Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hpcc05!hpgva1!hpucph!john From: john@hpucph.dnk.hp.com (John Damm Srensen) Newsgroups: comp.sys.hp Subject: Re: read ID-MODULE series# Message-ID: <16200009@hpucph.dnk.hp.com> Date: 4 Feb 91 07:58:26 GMT References: <3104@unccvax.uncc.edu> Organization: Hewlett-Packard A/S , Denmark Lines: 108 Following small C program will give you the serial number in ASCII format. It will search the entire HIL loop for ID module(s) and report serial number(s) in plain ASCII. As far as I remember this program was once publiced in the HP9000 Communicator. john@ejna.dnk.hp.com Danish Response Center #include #include main() { int fd,status,i; unsigned char hildev[7][10]; unsigned char describe[16],serial_number[11]; long int sr_number; /*Open the device file for the first seven devices on the loop and look for any ID modeules */ strcpy(hildev[0],"/dev/hil1"); strcpy(hildev[1],"/dev/hil2"); strcpy(hildev[2],"/dev/hil3"); strcpy(hildev[3],"/dev/hil4"); strcpy(hildev[4],"/dev/hil5"); strcpy(hildev[5],"/dev/hil6"); strcpy(hildev[6],"/dev/hil7"); for (i=0;i<7;i++) { fd=open(hildev[i],0); /*This ioctl system call requests a describe record from the device. The describe record contains information describing the amount and type of data that can be returned by the device*/ status=ioctl(fd,HILID,&describe[0]); /*Is there an HP-HIL device out there and is it an ID Module? */ if ((status != -1) && (describe[0]==0x34)) { printf("\nID MODULE found at device %s \n",hildev[i]); get_serial_number(fd,&serial_number[0],&sr_number); printf("%s %ld\n",serial_number,sr_number); } } } get_serial_number(hil_fd,serial_number,sr_number) int hil_fd; char serial_number[]; long int *sr_number; { unsigned long int year_week, suffix; int status; union srnum { unsigned long int number; struct{ unsigned dummy :2; unsigned byte8 :6; unsigned byte7 :8; unsigned byte6 :8; unsigned byte5 :8; } r; } s; union hil_sc { unsigned char describe[9]; struct { unsigned format :4; unsigned undefined :4; unsigned byte2 :8; unsigned byte3 :8; unsigned bit17 :1; unsigned product_letter :7; unsigned sr_byte5 :8; unsigned sr_byte6 :8; unsigned sr_byte7 :8; unsigned res1 :2; unsigned sr_byte8 :6; unsigned res2 :1; unsigned country :7; } sc; } hilsc; /* Use Report Security Cdoe command to get ID Module information */ status= ioctl(hil_fd,HILSC,&hilsc.describe[0]); /* Put bits and bytes in proper order to make valid Serial Number */ s.r.byte5 = hilsc.sc.sr_byte5; s.r.byte6 = hilsc.sc.sr_byte6; s.r.byte7 = hilsc.sc.sr_byte7; s.r.byte8 = hilsc.sc.sr_byte8; /* Separate Year and Week code from the Serial # suffix */ year_week = s.number/100000; suffix = s.number - year_week*100000; /* Print out ID Module information into return string */ if(suffix <= 9) sprintf(serial_number,"%ld%c0000%ld",year_week,suffix); else if (suffix << 99) sprintf(serial_number,"%ld%c000%ld",year_week,hilsc.sc.country,suffix); else if (suffix << 999) sprintf(serial_number,"%ld%c00%ld",year_week,hilsc.sc.country,suffix); else if (suffix << 9999) sprintf(serial_number,"%ld%c0%ld",year_week,hilsc.sc.country,suffix); else sprintf(serial_number,"%ld%c%ld",year_week,suffix); /* Return long int value for what ever reason! */ *sr_number = s.number; }