static void prtprodtinfo(void) { int j; dataptr = (SaHpiInventGeneralDataT *)&inv->DataRecords[i]->RecordData.ProductInfo; strptr=dataptr->Manufacturer; fixstr((SaHpiTextBufferT *)strptr); printf( "Product Manufacturer: %s\n", outbuff); strptr=dataptr->ProductName; fixstr((SaHpiTextBufferT *)strptr); printf( "Product Name : %s\n", outbuff); strptr=dataptr->ProductVersion; fixstr((SaHpiTextBufferT *)strptr); printf( "Product Version : %s\n", outbuff); strptr=dataptr->ModelNumber; fixstr((SaHpiTextBufferT *)strptr); printf( "Product Model Number: %s\n", outbuff); strptr=dataptr->SerialNumber; fixstr((SaHpiTextBufferT *)strptr); printf( "Product Serial # : %s\n", outbuff); strptr=dataptr->PartNumber; fixstr((SaHpiTextBufferT *)strptr); printf( "Product Part Number : %s\n", outbuff); strptr=dataptr->FileId; fixstr((SaHpiTextBufferT *)strptr); printf( "Product FRU File ID : %s\n", outbuff); strptr=dataptr->AssetTag; fixstr((SaHpiTextBufferT *)strptr); printf( "Product Asset Tag : %s\n", outbuff); for (j = 0; j < 10; j++) { int ii; if (dataptr->CustomField[j] != NULL) { if ((dataptr->CustomField[j]->DataType == 0) && (dataptr->CustomField[j]->DataLength == 16)) { /*binary GUID*/ printf( "IPMI SystemGUID : "); for (ii=0; ii< dataptr->CustomField[j]->DataLength; ii++) printf("%02x", dataptr->CustomField[j]->Data[ii]); printf("\n"); } else { /* other text field */ dataptr->CustomField[j]->Data[ dataptr->CustomField[j]->DataLength] = 0; printf( "Product OEM Field : %s\n", dataptr->CustomField[j]->Data); } } else /* NULL pointer */ break; } /*end for*/ }
static void prtchassinfo(void) { chasstype = (SaHpiInventChassisTypeT) inv->DataRecords[i]->RecordData. ChassisInfo.Type; for (k = 0; k < NCT; k++) { if ((unsigned int)k == chasstype) printf("\tChassis Type : %s\n", chasstypes[k]); } dataptr = (SaHpiInventGeneralDataT *) & inv->DataRecords[i]->RecordData. ChassisInfo.GeneralData; strptr = dataptr->Manufacturer; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis Manufacturer: %s\n", outbuff); strptr = dataptr->ProductName; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis Name : %s\n", outbuff); strptr = dataptr->ProductVersion; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis Version : %s\n", outbuff); strptr = dataptr->ModelNumber; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis Model Number: %s\n", outbuff); strptr = dataptr->SerialNumber; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis Serial # : %s\n", outbuff); strptr = dataptr->PartNumber; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis Part Number : %s\n", outbuff); strptr = dataptr->FileId; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis FRU File ID : %s\n", outbuff); strptr = dataptr->AssetTag; fixstr((SaHpiTextBufferT *) strptr); printf("\tChassis Asset Tag : %s\n", outbuff); if (dataptr->CustomField[0] != 0) { if (dataptr->CustomField[0]->DataLength != 0) strncpy((char *)outbuff, (char *)dataptr->CustomField[0]->Data, dataptr->CustomField[0]->DataLength); outbuff[dataptr->CustomField[0]->DataLength] = 0; printf("\tChassis OEM Field : %s\n", outbuff); } }
static void prtboardinfo(void) { dataptr = (SaHpiInventGeneralDataT *) & inv->DataRecords[i]->RecordData. BoardInfo; strptr = dataptr->Manufacturer; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard Manufacturer : %s\n", outbuff); strptr = dataptr->ProductName; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard Product Name : %s\n", outbuff); strptr = dataptr->ModelNumber; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard Model Number : %s\n", outbuff); strptr = dataptr->PartNumber; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard Part Number : %s\n", outbuff); strptr = dataptr->ProductVersion; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard Version : %s\n", outbuff); strptr = dataptr->SerialNumber; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard Serial # : %s\n", outbuff); strptr = dataptr->FileId; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard FRU File ID : %s\n", outbuff); strptr = dataptr->AssetTag; fixstr((SaHpiTextBufferT *) strptr); printf("\tBoard Asset Tag : %s\n", outbuff); for (j = 0; j < 10 && dataptr->CustomField[j]; j++) { if (dataptr->CustomField[j]->DataLength != 0) { strncpy((char *)outbuff,(char *)dataptr->CustomField[j]->Data, dataptr->CustomField[j]->DataLength); outbuff[dataptr->CustomField[j]->DataLength] = 0; printf("\tBoard OEM Field : %s\n", outbuff); } } }
static void print_idrfield(SaHpiIdrFieldT *field, int len) { SaHpiTextBufferT *strptr; char fieldstr[MAX_STRSIZE]; int i; #ifdef OPENHPI_USED if (fverbose) { oh_print_idrfield(field, len); } else #endif { for (i = 0; i < NFIELDTYP; i++) { if (map_fieldtype[i].type == field->Type) break; } if (i == NFIELDTYP) i--; strptr = &(field->Field); fixstr(strptr,fieldstr); /*stringify if needed*/ printf(" FieldId[%d] %s : %s\n", field->FieldId,map_fieldtype[i].str ,fieldstr); } }
int main(int argc, char **argv) { SaErrorT rv,rv_rdr; SaHpiSessionIdT sessionid; SaHpiDomainInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiIdrInfoT idrInfo; SaHpiIdrIdT idrid; int invfound = 0; int nloops = 0; GOptionContext *context; atag.tlen = 0; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Shows resources' inventory records\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION )) { //TODO: Feature 880127? g_option_context_free (context); return 1; } g_option_context_free (context); if (fatag) { atag.tag = (char *)strdup(fatag); atag.tlen = strlen(fatag); g_free(fatag); } /* compile error */ // inv = (SaHpiIdrAreaHeaderT *)&inbuff[0]; inv = (SaHpiIdrAreaHeaderT *)(void *)&inbuff[0]; rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return rv; rv = saHpiDomainInfoGet(sessionid,&rptinfo); if (copt.debug) DBG("saHpiDomainInfoGet rv = %d",rv); // if (copt.debug) DBG("RptInfo: UpdateCount = %x, UpdateTime = %lx", // rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); while (!invfound && (nloops < 7)) { /* * The OpenHPI ipmi plugin has a bug whereby the FRU RDR is added * much later, and always requires a rediscovery. (bug #1095256) * This should not apply to other well-behaved plugins. */ nloops++; if (copt.debug) DBG("Starting Discovery, pass %u ...",nloops); rv = saHpiDiscover(sessionid); if (copt.debug) DBG("saHpiDiscover rv = %d",rv); if (rv != SA_OK) { CRIT("saHpiDiscover error %d",rv); break; } /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("RptEntryGet: rid=%u rv = %d\n",rptentryid,rv); if (rv == SA_OK) { /* obtain resource tag */ char tagstr[MAX_STRSIZE]; fixstr(&rptentry.ResourceTag,tagstr); /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; resourceid = rptentry.ResourceId; if (copt.debug) DBG("rptentry[%u] resourceid=%d", rptentryid,resourceid); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA) { printf("Resource[%u] Tag: %s \thas inventory capability\n", rptentryid,tagstr); rv_rdr = SA_OK; while ((rv_rdr == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) { rv_rdr = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr); if (copt.debug) DBG("saHpiRdrGet[%u] rv = %d",entryid,rv_rdr); if (rv_rdr == SA_OK) { if (copt.debug) DBG("Rdr[%u] type = %u tag = %s",entryid, rdr.RdrType,rdr.IdString.Data); if (rdr.RdrType == SAHPI_INVENTORY_RDR) { invfound = 1; /*type 3 includes inventory records*/ rdr.IdString.Data[rdr.IdString.DataLength] = 0; idrid = rdr.RdrTypeUnion.InventoryRec.IdrId; buffersize = sizeof(inbuff); if (copt.debug) { DBG("Rdr[%x] is inventory, IdrId=%x",rdr.RecordId,idrid); DBG("Inv BufferSize=%u", buffersize); } if ( IsTagBmc((char *)rdr.IdString.Data, rdr.IdString.DataLength) ) { /* Get all of the inventory data areas and fields */ memset(inv,0,buffersize); rv_rdr = saHpiIdrInfoGet(sessionid, resourceid, idrid, &idrInfo); if (rv_rdr != SA_OK) { printf("IDR Info error: rv_rdr = %d\n",rv_rdr); } else { /* idrInfo is ok */ if (copt.debug) DBG("IDR Info: ok "); print_epath(&rptentry.ResourceEntity, 1); printf("RDR[%x]: Inventory, IdrId=%x %s\n",rdr.RecordId, idrid,rdr.IdString.Data); print_idrinfo(&idrInfo,4); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (copt.debug) DBG("walkInventory rv_rdr = %d",rv_rdr); } if (!ent_writable(&rptentry.ResourceEntity,&idrInfo)) foundasset = 0; if ((atag.tlen > 0) && (foundasset == 1)) { SaHpiIdrFieldT atagField; atagField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG; atagField.ReadOnly = SAHPI_FALSE; atagField.AreaId = atag.areaid; atagField.FieldId = atag.fieldid; strptr=&(atagField.Field); strptr->DataType = SAHPI_TL_TYPE_TEXT; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)atag.tlen; strncpy((char *)strptr->Data, atag.tag, atag.tlen); strptr->Data[atag.tlen] = 0; printf( "Writing new asset tag: %s\n",strptr->Data); rv_rdr = saHpiIdrFieldSet(sessionid, resourceid, atag.idrid, &atagField); printf("Return Write Status = %d\n", rv_rdr); if (rv_rdr == SA_OK) { printf ("Good write - re-reading!\n"); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (copt.debug) DBG("walkInventory rv_rdr = %d",rv_rdr); } /* Good write - re-read */ } /*endif foundasset*/ } /*endif RDR tag ok*/ } /* Inventory Data Records - Type 3 */ else if (copt.debug) DBG("rdr type = %u", rdr.RdrType); } /*endif RdrGet ok*/ entryid = nextentryid; } /*end while rdr*/ } /*endif rpt invent capab*/ else if (copt.debug) DBG("Resource[%u] Tag: %s", rptentryid,tagstr); } /*endif rpt ok*/ rptentryid = nextrptentryid; } /*end rpt loop */ if (copt.debug) DBG("loop %u inventory found = %d",nloops,invfound); } /*end while no inv */ rv = saHpiSessionClose(sessionid); return 0; }
int main(int argc, char **argv) { int c; SaErrorT rv,rv_rdr; SaHpiSessionIdT sessionid; SaHpiDomainInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiIdrInfoT idrInfo; SaHpiIdrIdT idrid; int invfound = 0; int nloops = 0; oh_prog_version(argv[0], OH_SVN_REV); atag.tlen = 0; while ( (c = getopt( argc, argv,"a:vxz?")) != EOF ) switch(c) { case 'z': fzdebug = 1; /* fall thru to include next setting */ case 'x': fdebug = 1; break; case 'v': fverbose = 1; break; case 'a': fasset = 1; if (optarg) { atag.tag = (char *)strdup(optarg); atag.tlen = strlen(optarg); } break; default: printf("Usage: %s [-x] [-a asset_tag]\n", argv[0]); printf(" -a Sets the asset tag\n"); printf(" -x Display debug messages\n"); printf(" -z Display extra debug messages\n"); exit(1); } /* compile error */ // inv = (SaHpiIdrAreaHeaderT *)&inbuff[0]; inv = (SaHpiIdrAreaHeaderT *)(void *)&inbuff[0]; rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL); if (fdebug) printf("saHpiSessionOpen rv = %d sessionid = %x\n",rv,sessionid); if (rv != SA_OK) { printf("saHpiSessionOpen error %d\n",rv); exit(-1); } rv = saHpiDomainInfoGet(sessionid,&rptinfo); if (fdebug) printf("saHpiDomainInfoGet rv = %d\n",rv); // if (fdebug) printf("RptInfo: UpdateCount = %x, UpdateTime = %lx\n", // rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); while (!invfound && (nloops < 7)) { /* * The OpenHPI ipmi plugin has a bug whereby the FRU RDR is added * much later, and always requires a rediscovery. (bug #1095256) * This should not apply to other well-behaved plugins. */ nloops++; if (fdebug) printf("Starting Discovery, pass %d ...\n",nloops); rv = saHpiDiscover(sessionid); if (fdebug) printf("saHpiDiscover rv = %d\n",rv); if (rv != SA_OK) { printf("saHpiDiscover error %d\n",rv); break; } /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("RptEntryGet: rid=%d rv = %d\n",rptentryid,rv); if (rv == SA_OK) { /* obtain resource tag */ char tagstr[MAX_STRSIZE]; fixstr(&rptentry.ResourceTag,tagstr); /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; resourceid = rptentry.ResourceId; if (fdebug) printf("rptentry[%d] resourceid=%d\n", rptentryid,resourceid); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA) { printf("Resource[%d] Tag: %s \thas inventory capability\n", rptentryid,tagstr); rv_rdr = SA_OK; while ((rv_rdr == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) { rv_rdr = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr); if (fdebug) printf("saHpiRdrGet[%x] rv = %d\n",entryid,rv_rdr); if (rv_rdr == SA_OK) { if (fdebug) printf("Rdr[%x] type = %d tag = %s\n",entryid, rdr.RdrType,rdr.IdString.Data); if (rdr.RdrType == SAHPI_INVENTORY_RDR) { invfound = 1; /*type 3 includes inventory records*/ rdr.IdString.Data[rdr.IdString.DataLength] = 0; idrid = rdr.RdrTypeUnion.InventoryRec.IdrId; buffersize = sizeof(inbuff); if (fdebug) { printf("Rdr[%x] is inventory, IdrId=%x\n",rdr.RecordId,idrid); printf("Inv BufferSize=%d\n", buffersize); } if ( IsTagBmc((char *)rdr.IdString.Data, rdr.IdString.DataLength) ) { /* Get all of the inventory data areas and fields */ memset(inv,0,buffersize); rv_rdr = saHpiIdrInfoGet(sessionid, resourceid, idrid, &idrInfo); if (rv_rdr != SA_OK) { printf("IDR Info error: rv_rdr = %d\n",rv_rdr); } else { /* idrInfo is ok */ if (fdebug) printf("IDR Info: ok \n"); print_epath(&rptentry.ResourceEntity, 1); printf("RDR[%x]: Inventory, IdrId=%x %s\n",rdr.RecordId, idrid,rdr.IdString.Data); print_idrinfo(&idrInfo,4); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr); } if (!ent_writable(&rptentry.ResourceEntity,&idrInfo)) foundasset = 0; if ((fasset == 1) && (foundasset == 1)) { SaHpiIdrFieldT atagField; atagField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG; atagField.ReadOnly = SAHPI_FALSE; atagField.AreaId = atag.areaid; atagField.FieldId = atag.fieldid; strptr=&(atagField.Field); strptr->DataType = SAHPI_TL_TYPE_TEXT; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)atag.tlen; strncpy((char *)strptr->Data, atag.tag, atag.tlen); strptr->Data[atag.tlen] = 0; printf( "Writing new asset tag: %s\n",strptr->Data); rv_rdr = saHpiIdrFieldSet(sessionid, resourceid, atag.idrid, &atagField); printf("Return Write Status = %d\n", rv_rdr); if (rv_rdr == SA_OK) { printf ("Good write - re-reading!\n"); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr); } /* Good write - re-read */ } /*endif fasset*/ } /*endif RDR tag ok*/ } /* Inventory Data Records - Type 3 */ else if (fdebug) printf("rdr type = %d\n", rdr.RdrType); } /*endif RdrGet ok*/ entryid = nextentryid; } /*end while rdr*/ } /*endif rpt invent capab*/ else if (fdebug) printf("Resource[%d] Tag: %s\n", rptentryid,tagstr); } /*endif rpt ok*/ rptentryid = nextrptentryid; } /*end rpt loop */ if (fdebug) printf("loop %d inventory found = %d\n",nloops,invfound); } /*end while no inv */ rv = saHpiSessionClose(sessionid); exit(0); }
/* ###################################################################### # command no, optional argument, where to store value # returns 0 on success */ int ask(int cmd,char *s,double *rvp,int o,int r,int cached,char *msg) { char buf[256]; fd_set rfd,wfd,xfd; struct timeval tv; int n; char *t; static double a,b; if(sock<0) { sprintf(mesg,"Socket not open"); return(1); } /* socket not open */ if(!cached || msg) { /* prepare the message */ if(s) { for(t=s;*t;t++){ if(*t==',') { *t='&'; } } /* remove commas */ snprintf(buf,sizeof(buf),"%s&%d&%s%s\n",pass,cmd,s, (compatmode?"&":"")); } else { snprintf(buf,sizeof(buf),"%s&%d&\n",pass,cmd); } n = write(sock,buf,strlen(buf)); if( n != strlen(buf) ) { sprintf(mesg,"Unable to write to socket."); return 1; /* write error */ } if(debugmode) { printf("Sent: %s",buf);fflush(NULL); } FD_ZERO(&rfd); FD_ZERO(&wfd); FD_ZERO(&xfd); FD_SET(sock,&rfd); tv.tv_usec = 0; tv.tv_sec = timeout; n = select(sock+1,&rfd,&wfd,&xfd,&tv); if(!n) { sprintf(mesg,"Timeout on read."); if(debugmode) { printf("Timed out (%d).\n",timeout);fflush(NULL); } return( 1 ); /* timeout */ } if( n < 0 ) { sprintf(mesg,"Error on select."); if(debugmode) { printf("Select error.\n");fflush(NULL); } return( 1 ); } if(debugmode) { printf("Reading data...\n");fflush(NULL); } n = read( sock,buf,sizeof(buf) ); buf[n]='\0'; if(debugmode) { printf("Read [%s]\n",buf);fflush(NULL); } if(!n) { sprintf(mesg,"No data received from host"); return( 1 ); /* nothing received */ } if(msg) { strncpy(msg,buf,sizeof(buf)); return 0; } fixstr(buf); /* commas and decimal points */ /* now, we may have 2 values here */ t = strchr(buf,'&'); if(t) { *t='\0'; t++; b = atof(t); } a = atof(buf); if(!t) { b = a; } } /* cached */ if(rvp) { if( r ) { if(a>b) { if(a>0) { *rvp = b/a*100.0; } } else { if(b>0) { *rvp = a/b*100.0; } } } else if( o ) { *rvp = b; } else { *rvp = a; } if(debugmode) { printf("Processed %f,%f: Returning %f\n",a,b,*rvp);fflush(NULL); } } return(0); }
int main(int argc, char* argv[]) { if (argc != 2) { printf("BGI Text Exprot by Fuyin\n"); printf("usage: %s <input_file>\n", argv[0]); return -1; } std::string in_filename = argv[1]; FILE* fin = fopen(in_filename.c_str(), "rb"); if (!fin) { printf("fopen failed!\n"); return -1; } fseek(fin, 0, SEEK_END); dword fsize = ftell(fin); fseek(fin, 0, SEEK_SET); byte *buffer = new byte[fsize]; fread(buffer, fsize, 1, fin); fclose(fin); byte *p = buffer; const int magic_size = 0x1C; if (strncmp((char*)p, "BurikoCompiledScriptVer1.00\x00", magic_size)) { printf("format not match!\n"); return -1; } p += magic_size; dword header_size = *(dword*)p; p += header_size; //忽略文件末尾的少于4个的字节 dword find_count = (fsize - magic_size - header_size) / 4; dword baseoffset = magic_size + header_size; //用于避免导出空文本 dword *dummy; dword first_offset = baseoffset + find_and_getoffset((dword*)p, find_count, 0x00000003, dummy); find_count = (first_offset - magic_size - header_size) / 4; std::string out_filename = in_filename + ".txt"; FILE* fout = fopen(out_filename.c_str(), "wb"); fwrite("\xFF\xFE", 2, 1, fout); dword *opt_block = (dword*)p; dword text_offset = 0; dword *next_opt; while (true) { text_offset = baseoffset + find_and_getoffset(opt_block, find_count, 0x00000003, next_opt); if (next_opt == NULL) break; if (text_offset == 0) break; opt_block = next_opt; if (text_offset < fsize && text_offset > first_offset) { char *str = dumpstr(buffer, text_offset); fixstr(str); printstr(fout, str); } } fclose(fout); delete[]buffer; return 0; }