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) { /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; /* OpenHPI plugin sometimes has bad RPT Tag DataLength here. */ // rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; 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,rptentry.ResourceTag.Data); 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, rptentry.ResourceTag.Data); } /*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); }
int main(int argc, char **argv) { int prodrecindx=0; int asset_len=0; int c; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiEirIdT eirid; printf("%s ver %s\n",argv[0],progver); while ( (c = getopt( argc, argv,"a:xz?")) != EOF ) switch(c) { case 'z': fxdebug = 1; /* fall thru to include next setting */ case 'x': fdebug = 1; break; case 'a': fasset = 1; if (optarg) { asset_tag = (char *)strdup(optarg); asset_len = strlen(optarg); } /* printf( "String Length = %d\n", asset_len); printf( "String Length = %d\n", strlen(optarg)); */ break; default: printf("Usage: %s [-x] [-a asset_tag]\n", progname); printf(" -a Sets the asset tag\n"); printf(" -x Display debug messages\n"); printf(" -z Display extra debug messages\n"); exit(1); } inv = (SaHpiInventoryDataT *)(void *)&inbuff[0]; rv = saHpiInitialize(&hpiVer); if (rv != SA_OK) { printf("saHpiInitialize error %d\n",rv); exit(-1); } rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL); if (rv != SA_OK) { printf("saHpiSessionOpen error %d\n",rv); exit(-1); } rv = saHpiResourcesDiscover(sessionid); if (fxdebug) printf("saHpiResourcesDiscover rv = %d\n",rv); rv = saHpiRptInfoGet(sessionid,&rptinfo); if (fxdebug) printf("saHpiRptInfoGet rv = %d\n",rv); if (fdebug) printf("RptInfo: UpdateCount = %x, UpdateTime = %lx\n", rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); /* 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: rv = %d\n",rv); if (rv == SA_OK) { /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; resourceid = rptentry.ResourceId; if (fdebug) printf("rptentry[%d] resourceid=%d\n", entryid,resourceid); printf("Resource Tag: %s\n", rptentry.ResourceTag.Data); while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) { rv = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr); if (fxdebug) printf("saHpiRdrGet[%d] rv = %d\n",entryid,rv); if (rv == SA_OK) { if (rdr.RdrType == SAHPI_INVENTORY_RDR) { /*type 3 includes inventory records*/ eirid = rdr.RdrTypeUnion.InventoryRec.EirId; rdr.IdString.Data[rdr.IdString.DataLength] = 0; if (fdebug) printf( "RDR[%d]: type=%d num=%d %s\n", rdr.RecordId, rdr.RdrType, eirid, rdr.IdString.Data); buffersize = sizeof(inbuff); if (fdebug) printf("BufferSize=%d InvenDataRecSize=%zd\n", buffersize, sizeof(inbuff)); if ( IsTagBmc(rdr.IdString.Data, rdr.IdString.DataLength) ) { rv = saHpiEntityInventoryDataRead( sessionid, resourceid, eirid, buffersize, inv, &actualsize); if (fxdebug) printf( "saHpiEntityInventoryDataRead[%d] rv = %d\n", eirid, rv); if (fdebug) printf("ActualSize=%d\n", actualsize); if (rv == SA_OK) { /* Walk thru the list of inventory data */ for (i=0; inv->DataRecords[i] != NULL; i++) { if (inv->Validity == SAHPI_INVENT_DATA_VALID) { if (fdebug) printf( "Index = %d type=%x len=%d\n", i, inv->DataRecords[i]->RecordType, inv->DataRecords[i]->DataLength); switch (inv->DataRecords[i]->RecordType) { case SAHPI_INVENT_RECTYPE_INTERNAL_USE: if (fdebug) printf( "Internal Use\n"); break; case SAHPI_INVENT_RECTYPE_PRODUCT_INFO: if (fdebug) printf( "Product Info\n"); prodrecindx = i; prtprodtinfo(); break; case SAHPI_INVENT_RECTYPE_CHASSIS_INFO: if (fdebug) printf( "Chassis Info\n"); prtchassinfo(); break; case SAHPI_INVENT_RECTYPE_BOARD_INFO: if (fdebug) printf( "Board Info\n"); prtboardinfo(); break; case SAHPI_INVENT_RECTYPE_OEM: if (fdebug) printf( "OEM Record\n"); break; default: printf(" Invalid Invent Rec Type =%x\n", inv->DataRecords[i]->RecordType); break; } } } if (IsTagBmc(rdr.IdString.Data,rdr.IdString.DataLength) && (fasset == 1)) { SaHpiTextBufferT aTag; if (fdebug) printf( "Inventory = %s\n", rdr.IdString.Data); /* prodrecindx contains index for Prod Rec Type */ dataptr = (SaHpiInventGeneralDataT *) &inv->DataRecords[prodrecindx]->RecordData.ProductInfo; dataptr->AssetTag = &aTag; strptr=dataptr->AssetTag; strptr->DataType = SAHPI_TL_TYPE_LANGUAGE; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)asset_len; strncpy( (char *)strptr->Data, (char *)asset_tag,asset_len); strptr->Data[asset_len] = 0; printf( "Writing new asset tag: %s\n",(char *)strptr->Data); rv = saHpiEntityInventoryDataWrite( sessionid, resourceid, eirid, inv); printf("Return Write Status = %d\n", rv); if (rv == SA_OK) { printf ("Good write - re-reading!\n"); rv = saHpiEntityInventoryDataRead( sessionid, resourceid, eirid, buffersize, inv, &actualsize); if (fxdebug) printf( "saHpiEntityInventoryDataRead[%d] rv = %d\n", eirid, rv); if (fdebug) printf("ActualSize=%d\n", actualsize); if (rv == SA_OK) { /* Walk thru the list of inventory data */ for (i=0; inv->DataRecords[i] != NULL; i++) { if (inv->Validity == SAHPI_INVENT_DATA_VALID) { if (fdebug) printf( "Index = %d type=%x len=%d\n", i, inv->DataRecords[i]->RecordType, inv->DataRecords[i]->DataLength); switch (inv->DataRecords[i]->RecordType) { case SAHPI_INVENT_RECTYPE_INTERNAL_USE: if (fdebug) printf( "Internal Use\n"); break; case SAHPI_INVENT_RECTYPE_PRODUCT_INFO: if (fdebug) printf( "Product Info\n"); prtprodtinfo(); break; case SAHPI_INVENT_RECTYPE_CHASSIS_INFO: if (fdebug) printf( "Chassis Info\n"); prtchassinfo(); break; case SAHPI_INVENT_RECTYPE_BOARD_INFO: if (fdebug) printf( "Board Info\n"); prtboardinfo(); break; case SAHPI_INVENT_RECTYPE_OEM: if (fdebug) printf( "OEM Record\n"); break; default: printf(" Invalid Invent Rec Type =%x\n", inv->DataRecords[i]->RecordType); break; } } } } /*re-walk the inventory record list */ } /* Good write - re-read */ } /* check asset tag flag */ } else { printf("Returned HPI Error: rv=%d\n", rv); } } } /* Inventory Data Records - Type 3 */ entryid = nextentryid; } } rptentryid = nextrptentryid; } } rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); exit(0); }