Exemplo n.º 1
0
int Test_Resource(SaHpiSessionIdT sessionId,
		  SaHpiRptEntryT report, callback2_t func)
{
	SaErrorT status;
	int retval = SAF_TEST_NOTSUPPORT;
	SaHpiIdrInfoT IdrInfo;

	if (hasInventoryCapability(&report)) {

		//
		// Call saHpiIdrInfoGet() passing in an invalid IdrId
		//
		status = saHpiIdrInfoGet(sessionId,
					 report.ResourceId,
					 INVALID_INVENTORY_ID, &IdrInfo);

		if (status == SA_ERR_HPI_NOT_PRESENT) {
			retval = SAF_TEST_PASS;
		} else {
			retval = SAF_TEST_FAIL;
			e_print(saHpiIdrInfoGet, SA_ERR_HPI_NOT_PRESENT,
				status);
		}
	}

	return retval;
}
Exemplo n.º 2
0
static 
SaErrorT list_inv(SaHpiSessionIdT sessionid,
			SaHpiRptEntryT *rptptr,	
			SaHpiRdrT *rdrptr, 
			SaHpiResourceIdT l_resourceid)
{
 	SaErrorT  rvInvent = SA_OK;
	SaHpiIdrInfoT	idrInfo;
	SaHpiIdrIdT	idrid;
	SaHpiTextBufferT working;		
	oh_init_textbuffer(&working);																		


	if (rdrptr->RdrType == SAHPI_INVENTORY_RDR) {
		idrid = rdrptr->RdrTypeUnion.InventoryRec.IdrId;
		rvInvent = saHpiIdrInfoGet(
					sessionid,
					l_resourceid,
					idrid,
					&idrInfo);		

		if (rvInvent !=SA_OK) {
			printf("saHpiIdrInfoGet: ResourceId %d IdrId %d, error %s\n",
					l_resourceid, idrid, oh_lookup_error(rvInvent));
		} else {
			oh_print_idrinfo(&idrInfo, 4);
			walkInventory(sessionid, l_resourceid, &idrInfo);
		}
	}
	return(rvInvent);

}
Exemplo n.º 3
0
int processInventoryRdr(SaHpiSessionIdT sessionId,
			SaHpiResourceIdT resourceId,
			SaHpiRdrT * rdr, SaHpiInventoryRecT * inventoryRec)
{
	SaErrorT status;
	int retval = SAF_TEST_UNKNOWN;
	SaHpiIdrInfoT IdrInfo;

	// Check to see if this is a read-only IDR
	status = saHpiIdrInfoGet(sessionId, resourceId,
				 inventoryRec->IdrId, &IdrInfo);

	if (status != SA_OK) {
		retval = SAF_TEST_UNRESOLVED;
		e_print(saHpiIdrInfoGet, SA_OK, status);
	} else if (IdrInfo.ReadOnly) {
		retval = SAF_TEST_NOTSUPPORT;
	} else {

		status = saHpiIdrAreaDelete(sessionId,
					    resourceId,
					    inventoryRec->IdrId,
					    SAHPI_FIRST_ENTRY);

		if (status == SA_ERR_HPI_INVALID_PARAMS) {
			retval = SAF_TEST_PASS;
		} else {
			retval = SAF_TEST_FAIL;
			e_print(saHpiIdrAreaDelete, SA_ERR_HPI_INVALID_PARAMS,
				status);
		}
	}

	return retval;
}
Exemplo n.º 4
0
int processInventoryRdr(SaHpiSessionIdT sessionId,
			SaHpiResourceIdT resourceId,
			SaHpiRdrT * rdr, SaHpiInventoryRecT * inventoryRec)
{
	SaErrorT status;
	int retval;
	SaHpiEntryIdT AreaId, NextAreaId;
	SaHpiIdrAreaHeaderT Header;
	SaHpiIdrInfoT Info;

	status = saHpiIdrInfoGet(sessionId, resourceId,
				 inventoryRec->IdrId, &Info);

	if (status != SA_OK) {
		retval = SAF_TEST_UNRESOLVED;
		e_print(saHpiIdrInfoGet, SA_OK, status);
	} else if (Info.ReadOnly) {
		retval = SAF_TEST_NOTSUPPORT;
	} else {

		retval = SAF_TEST_NOTSUPPORT;

		NextAreaId = SAHPI_FIRST_ENTRY;
		while ((retval == SAF_TEST_NOTSUPPORT) &&
		       (NextAreaId != SAHPI_LAST_ENTRY)) {

			AreaId = NextAreaId;
			status = saHpiIdrAreaHeaderGet(sessionId,
						       resourceId,
						       inventoryRec->IdrId,
						       SAHPI_IDR_AREATYPE_UNSPECIFIED,
						       AreaId,
						       &NextAreaId, &Header);

			if (status == SA_ERR_HPI_NOT_PRESENT) {
				// do nothing
			} else if (status != SA_OK) {

				retval = SAF_TEST_UNRESOLVED;
				e_print(saHpiIdrAreaHeaderGet, SA_OK, status);

			} else if (!Header.ReadOnly) {

				retval = TestField(sessionId, resourceId,
						   inventoryRec->IdrId, AreaId);
			}
		}
	}

	return retval;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
        int number_resources=0;
        SaErrorT rv;
        SaHpiSessionIdT sessionid;
        SaHpiResourceIdT resourceid;
        SaHpiIdrIdT IdrId = SAHPI_DEFAULT_INVENTORY_ID;
        SaHpiIdrInfoT IdrInfo;
        SaHpiResourceIdT resourceid_list[RESOURCE_CAP_LENGTH] = {0};
        SaHpiCapabilitiesT capability = SAHPI_CAPABILITY_INVENTORY_DATA;

        printf("saHpiIdrInfoGet: Test for hpi IDR info get function\n");

        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
        if (rv != SA_OK) {
                printf("saHpiSessionOpen failed with error: %s\n",
                       oh_lookup_error(rv));
                return rv;
        }

        /* Discover the resources with IDR capability */
        printf("\nListing the resource with IDR capability \n");
        rv = discover_resources(sessionid, capability, resourceid_list,
                                &number_resources);
        if (rv != SA_OK) {
                exit(-1);
        }

        printf("\nPlease enter the resource id whose idr area header "
               "is required: ");
        scanf("%d", &resourceid);

        rv = saHpiIdrInfoGet(sessionid, resourceid, IdrId,&IdrInfo);
        if (rv != SA_OK) {
                printf("saHpiIdrInfoGet failed with error: %s\n",
                       oh_lookup_error(rv));
                printf("Test case - FAIL\n");
        }
        else {
                oh_print_idrinfo(&IdrInfo,6);
                printf("Test case - PASS\n");
        }

        rv = saHpiSessionClose(sessionid);
        return 0;
}
Exemplo n.º 6
0
static
SaErrorT show_inv(SaHpiSessionIdT sessionid,
                  SaHpiRptEntryT *rptptr,
                  SaHpiRdrT *rdrptr,
                  SaHpiResourceIdT l_resourceid)
{
    SaErrorT  rvInvent = SA_OK;
    SaHpiIdrInfoT	idrInfo;
    SaHpiIdrIdT	idrid;
    char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
    oh_big_textbuffer buffer;
    rvInvent = oh_init_bigtext(&buffer);


    if (rdrptr->RdrType == SAHPI_INVENTORY_RDR) {
        idrid = rdrptr->RdrTypeUnion.InventoryRec.IdrId;
        rvInvent = saHpiIdrInfoGet(
                       sessionid,
                       l_resourceid,
                       idrid,
                       &idrInfo);

        if (rvInvent !=SA_OK) {
            snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Inventory: ResourceId %u IdrId %u, error %s\n",
                     l_resourceid, idrid, oh_lookup_error(rvInvent));
            oh_append_bigtext(&buffer, str);
            show_rdr(&buffer);
        } else {

            snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Inventory Num: %u, ", rdrptr->RdrTypeUnion.InventoryRec.IdrId);
            oh_append_bigtext(&buffer, str);
            snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Num Areas: %u, ", idrInfo.NumAreas);
            oh_append_bigtext(&buffer, str);
            if ( rdrptr->IdString.DataType == SAHPI_TL_TYPE_TEXT ) {
                oh_append_bigtext(&buffer, "Tag: ");
                snprintf(str,  rdrptr->IdString.DataLength+1, "%s", rdrptr->IdString.Data);
                oh_append_bigtext(&buffer, str);
                oh_append_bigtext(&buffer, "\n");
            }
            show_rdr(&buffer);
        }
    }
    return(rvInvent);

}
Exemplo n.º 7
0
int processInventoryRdr(SaHpiSessionIdT sessionId,
			SaHpiResourceIdT resourceId,
			SaHpiRdrT * rdr, SaHpiInventoryRecT * inventoryRec)
{
	SaErrorT status;
	int retval = SAF_TEST_UNKNOWN;
	SaHpiEntryIdT AreaId;
	SaHpiIdrInfoT IdrInfo;
	SaHpiIdrIdT IdrId = inventoryRec->IdrId;

	// Check to see if this is a read-only IDR

	status = saHpiIdrInfoGet(sessionId, resourceId, IdrId, &IdrInfo);
	if (status != SA_OK) {
		retval = SAF_TEST_UNRESOLVED;
		e_print(saHpiIdrInfoGet, SA_OK, status);
	} else if (IdrInfo.ReadOnly) {
		retval = SAF_TEST_NOTSUPPORT;
	} else {
		status = saHpiIdrAreaAdd(sessionId, resourceId, IdrId,
					 SAHPI_IDR_AREATYPE_PRODUCT_INFO,
					 &AreaId);

		if (status == SA_ERR_HPI_INVALID_DATA) {
			retval = SAF_TEST_NOTSUPPORT;
		} else if (status != SA_OK) {
			retval = SAF_TEST_FAIL;
			e_print(saHpiIdrAreaAdd, SA_OK, status);
		} else {
			retval = run_test(sessionId, resourceId, IdrId,
					  SAHPI_IDR_AREATYPE_PRODUCT_INFO,
					  AreaId);

			status = saHpiIdrAreaDelete(sessionId, resourceId,
						    IdrId, AreaId);
			if (status != SA_OK) {
				e_print(saHpiIdrAreaDelete, SA_OK, status);
			}
		}
	}

	return retval;
}
Exemplo n.º 8
0
void cHpiSubProviderIdr::GetInfo( std::deque<HpiInfo>& info ) const
{
    info.clear();

    SaErrorT rv;

    SaHpiRdrT rdr;
    rv = saHpiRdrGetByInstrumentId( m_ctx.session_id,
                                    m_ctx.resource_id,
                                    SAHPI_INVENTORY_RDR,
                                    m_ctx.instrument_id,
                                    &rdr );
    if ( rv != SA_OK ) {
        Line( info, L"saHpiRdrGetByInstrumentId failed", rv, I32_SaError );
        return;
    }

    Line( info, L"Resource Id", m_ctx.resource_id, UI32_SaHpiResourceId );
    Line( info, L"Entity", rdr.Entity );
    Line( info, L"IsFru", rdr.IsFru, UI8_SaHpiBool );

    const SaHpiInventoryRecT& ir = rdr.RdrTypeUnion.InventoryRec;

    Line( info, L"Idr Id", ir.IdrId, UI32_SaHpiIdrId );
    Line( info, L"Persistent", ir.Persistent, UI8_SaHpiBool );
    Line( info, L"OEM", ir.Oem );
    Line( info, L"IdString", rdr.IdString );

    SaHpiIdrInfoT idr_info;
    rv = saHpiIdrInfoGet( m_ctx.session_id,
                          m_ctx.resource_id,
                          m_ctx.instrument_id,
                          &idr_info );
    if ( rv != SA_OK ) {
        Line( info, L"saHpiIdrInfoGet failed", rv, I32_SaError );
        return;
    }
    Line( info, L"Update Count", idr_info.UpdateCount );
    Line( info, L"Read Only", idr_info.ReadOnly, UI8_SaHpiBool );
    Line( info, L"Number of Areas", idr_info.NumAreas );
}
Exemplo n.º 9
0
int processInventoryRdr(SaHpiSessionIdT sessionId,
			SaHpiResourceIdT resourceId,
			SaHpiRdrT * rdr, SaHpiInventoryRecT * inventoryRec)
{
	SaErrorT status;
	int retval = SAF_TEST_UNKNOWN;
	SaHpiEntryIdT AreaId;
	SaHpiIdrInfoT IdrInfo;

	// Check to see if this is a read-only IDR
	status = saHpiIdrInfoGet(sessionId, resourceId,
				 inventoryRec->IdrId, &IdrInfo);

	if (status != SA_OK) {
		retval = SAF_TEST_UNRESOLVED;
		e_print(saHpiIdrInfoGet, SA_OK, status);
	} else if (IdrInfo.ReadOnly) {
		retval = SAF_TEST_NOTSUPPORT;
	} else {

		// Call saHpiIdrAreaAdd() on an IDR with the Unspecified area type.

		status = saHpiIdrAreaAdd(sessionId,
					 resourceId,
					 inventoryRec->IdrId,
					 SAHPI_IDR_AREATYPE_UNSPECIFIED,
					 &AreaId);

		if (status == SA_ERR_HPI_INVALID_DATA) {
			retval = SAF_TEST_PASS;
		} else {
			retval = SAF_TEST_FAIL;
			e_print(saHpiIdrAreaAdd, SA_ERR_HPI_INVALID_DATA,
				status);
		}
	}

	return retval;
}
Exemplo n.º 10
0
int processInventoryRdr(SaHpiSessionIdT sessionId,
			SaHpiResourceIdT resourceId,
			SaHpiRdrT * rdr, SaHpiInventoryRecT * inventoryRec)
{
	SaErrorT status;
	int retval = SAF_TEST_UNKNOWN;
	SaHpiEntryIdT AreaId;
	SaHpiIdrInfoT IdrInfo;

	// Check to see if this is a read-only IDR
	status = saHpiIdrInfoGet(sessionId, resourceId,
				 inventoryRec->IdrId, &IdrInfo);

	if (status != SA_OK) {
		retval = SAF_TEST_UNRESOLVED;
		e_print(saHpiIdrInfoGet, SA_OK, status);
	} else if (IdrInfo.ReadOnly) {
		retval = SAF_TEST_NOTSUPPORT;
	} else {

		// Call saHpiIdrAreaAdd() passing in an invalid ResourceId

		status = saHpiIdrAreaAdd(sessionId,
					 INVALID_RESOURCE_ID,
					 inventoryRec->IdrId,
					 SAHPI_IDR_AREATYPE_PRODUCT_INFO,
					 &AreaId);

		if (status == SA_ERR_HPI_INVALID_RESOURCE) {
			retval = SAF_TEST_PASS;
		} else {
			retval = SAF_TEST_FAIL;
			e_print(saHpiIdrAreaAdd, SA_ERR_HPI_INVALID_RESOURCE,
				status);
		}
	}

	return retval;
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
0
SaErrorT show_inventory(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid,
			SaHpiIdrIdT IdrId, hpi_ui_print_cb_t proc)
{
	SaHpiIdrInfoT		info;
	SaErrorT		rv;
	SaHpiEntryIdT		entryid, nextentryid;
	SaHpiEntryIdT		fentryid, nextfentryid;
	SaHpiIdrAreaHeaderT	hdr;
	SaHpiIdrFieldT		field;
	char			buf[SHOW_BUF_SZ];
	char			*str;
	int			num;

	rv = saHpiIdrInfoGet(sessionid, resourceid, IdrId, &info);
	if (rv != SA_OK) {
		snprintf(buf, SHOW_BUF_SZ, "ERROR!!! saHpiIdrInfoGet: %s\n",
			oh_lookup_error(rv));
		proc(buf);
		return(-1);
	};
	num = info.NumAreas;
	snprintf(buf, SHOW_BUF_SZ,
		"Inventory: %d   Update count: %d   Read only: %d   Areas: %d\n",
		info.IdrId, info.UpdateCount, info.ReadOnly, num);
	if (proc(buf) != 0) return(SA_OK);
	entryid = SAHPI_FIRST_ENTRY;
	while ((entryid != SAHPI_LAST_ENTRY) && (num > 0)) {
		rv = saHpiIdrAreaHeaderGet(sessionid, resourceid, IdrId,
			SAHPI_IDR_AREATYPE_UNSPECIFIED, entryid,
			&nextentryid, &hdr);
		if (rv != SA_OK) {
			proc("ERROR!!! saHpiIdrAreaHeaderGet\n");
			return(-1);
		};
		str = oh_lookup_idrareatype(hdr.Type);
		if (str == NULL) str = "Unknown";
		snprintf(buf, SHOW_BUF_SZ,
			"    Area: %d   Type: %s   Read Only: %d   Fields: %d\n",
			hdr.AreaId, str, hdr.ReadOnly, hdr.NumFields);
		if (proc(buf) != 0) return(SA_OK);
		fentryid = SAHPI_FIRST_ENTRY;
		entryid = nextentryid;
		while ((fentryid != SAHPI_LAST_ENTRY) && (hdr.NumFields > 0)) {
			rv = saHpiIdrFieldGet(sessionid, resourceid, IdrId, hdr.AreaId,
				SAHPI_IDR_FIELDTYPE_UNSPECIFIED, fentryid,
				&nextfentryid, &field);
			if (rv != SA_OK) {
				proc("ERROR!!! saHpiIdrFieldGet\n");
				return(-1);
			};
			str = oh_lookup_idrfieldtype(field.Type);
			if (str == NULL) str = "Unknown";
			snprintf(buf, SHOW_BUF_SZ,
				"        Field: %d  Type: %s Read Only: %d (",
				field.FieldId, str, field.ReadOnly);
			if (proc(buf) != 0) return(SA_OK);
			if (print_text_buffer(NULL, &(field.Field), NULL, proc) != 0)
				return(SA_OK);
			if (proc(")\n") != 0) return(SA_OK);
			fentryid = nextfentryid;
		}
	};
	return(SA_OK);
}
Exemplo n.º 13
0
int main(int argc, char **argv)
{

    /* ************************
     * Local variables
     * ***********************/
    int testfail = 0;
    SaErrorT          err;
    SaErrorT expected_err;
    SaHpiRptEntryT rptentry;
    SaHpiRdrT	rdr;
    SaHpiResourceIdT  id = 0;
    SaHpiSessionIdT   sessionid;
    SaHpiIdrIdT       idrId = 0;
    SaHpiIdrInfoT	  info;
    SaHpiEntryIdT entryid;
    SaHpiEntryIdT nextentryid;
    SaHpiBoolT foundControl;

    /* *************************************
     * Find a resource with inventory capability
     * ************************************* */
    err = tsetup(&sessionid);
    if (err != SA_OK) {
        printf("Error! Can not open session for test environment\n");
        printf("       File=%s, Line=%d\n", __FILE__, __LINE__);
        return -1;
    }

    err = tfind_resource(&sessionid, SAHPI_CAPABILITY_INVENTORY_DATA, SAHPI_FIRST_ENTRY, &rptentry, SAHPI_TRUE);
    if (err != SA_OK) {
        printf("Can not find an Inventory resource for test environment\n");
        printf("       File=%s, Line=%d\n", __FILE__, __LINE__);
        err = tcleanup(&sessionid);
        return SA_OK;
    }
    id = rptentry.ResourceId;

    /**************************
     * Test: find an Inventory RDR
     **************************/
    entryid = SAHPI_FIRST_ENTRY;
    foundControl = SAHPI_FALSE;
    do {
        err = saHpiRdrGet(sessionid,id,entryid,&nextentryid, &rdr);
        if (err == SA_OK)
        {
            if (rdr.RdrType == SAHPI_INVENTORY_RDR)
            {
                foundControl = SAHPI_TRUE;
                break;

            }
            entryid = nextentryid;
        }
    } while ((err == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;

    if (!foundControl) {
        dbg("Did not find desired resource for test\n");
        return(SA_OK);
    } else {
        idrId = rdr.RdrTypeUnion.InventoryRec.IdrId;
    }

    /**************************
     * Test : Invalid handle
     **************************/
    expected_err = SA_ERR_HPI_INVALID_PARAMS;
    err = snmp_bc_get_idr_info(NULL , id, idrId, &info);
    checkstatus(err, expected_err, testfail);

    /**************************
     * Test : Invalid info pointer
     * expected_err = SA_ERR_HPI_INVALID_PARAMS;
     **************************/
    err = saHpiIdrInfoGet(sessionid, id, idrId, NULL);
    checkstatus(err, expected_err, testfail);

    /**************************&*
     * Cleanup after all tests
     ***************************/
    err = tcleanup(&sessionid);
    return testfail;

}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
static ret_code_t sa_show_inv(SaHpiResourceIdT resourceid)
{
	SaErrorT		rv = SA_OK, rva, rvf;
	SaHpiEntryIdT		rdrentryid;
	SaHpiEntryIdT		nextrdrentryid;
	SaHpiRdrT		rdr;
	SaHpiIdrIdT		idrid;
	SaHpiIdrInfoT		idrInfo;
	SaHpiEntryIdT		areaId;
	SaHpiEntryIdT		nextareaId;
	SaHpiIdrAreaTypeT	areaType;
	int			numAreas;
	SaHpiEntryIdT		fieldId;
	SaHpiEntryIdT		nextFieldId;
	SaHpiIdrFieldTypeT	fieldType;
	SaHpiIdrFieldT		thisField;
	SaHpiIdrAreaHeaderT	areaHeader;

	rdrentryid = SAHPI_FIRST_ENTRY;
	while (rdrentryid != SAHPI_LAST_ENTRY) {
		rv = saHpiRdrGet(Domain->sessionId, resourceid, rdrentryid,
			&nextrdrentryid, &rdr);
		if (rv != SA_OK) {
			printf("saHpiRdrGet error %s\n", oh_lookup_error(rv));
			return HPI_SHELL_CMD_ERROR;
		}

		if (rdr.RdrType != SAHPI_INVENTORY_RDR) {
			rdrentryid = nextrdrentryid;
			continue;
		};
		
		idrid = rdr.RdrTypeUnion.InventoryRec.IdrId;
		rv = saHpiIdrInfoGet(Domain->sessionId, resourceid, idrid, &idrInfo);
		if (rv != SA_OK) {
			printf("saHpiIdrInfoGet error %s\n", oh_lookup_error(rv));
			return HPI_SHELL_CMD_ERROR;
		}
		
		numAreas = idrInfo.NumAreas;
		areaType = SAHPI_IDR_AREATYPE_UNSPECIFIED;
		areaId = SAHPI_FIRST_ENTRY; 
		while (areaId != SAHPI_LAST_ENTRY) {
			rva = saHpiIdrAreaHeaderGet(Domain->sessionId, resourceid,
				idrInfo.IdrId, areaType, areaId, &nextareaId,
				&areaHeader);
			if (rva != SA_OK) {
				printf("saHpiIdrAreaHeaderGet error %s\n",
					oh_lookup_error(rva));
				break;
			}
			show_inv_area_header(&areaHeader, 2, ui_print);

			fieldType = SAHPI_IDR_FIELDTYPE_UNSPECIFIED;
			fieldId = SAHPI_FIRST_ENTRY;
			while (fieldId != SAHPI_LAST_ENTRY) {
				rvf = saHpiIdrFieldGet(Domain->sessionId, resourceid,
						idrInfo.IdrId, areaHeader.AreaId, 
						fieldType, fieldId, &nextFieldId,
						&thisField);
				if (rvf != SA_OK) {
					printf("saHpiIdrFieldGet error %s\n",
						oh_lookup_error(rvf));
					break;
				}
				show_inv_field(&thisField, 4, ui_print);
				fieldId = nextFieldId;
			}
			areaId = nextareaId;
		}
		rdrentryid = nextrdrentryid;
	}
	return HPI_SHELL_OK;
}
Exemplo n.º 16
0
/* 
 * Function prototypes
**/
int
main(int argc, char **argv)
{
	int asset_len=0;
	int c;
	SaErrorT rv = SA_OK,
		 rvRdrGet = SA_OK,
		 rvRptGet = SA_OK, 
		 rvInvent = SA_OK;
	SaHpiSessionIdT sessionid;
	SaHpiRptEntryT rptentry;
	SaHpiEntryIdT rptentryid;
	SaHpiEntryIdT nextrptentryid;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiResourceIdT resourceid;
	SaHpiRdrT rdr;
	SaHpiIdrInfoT	idrInfo;
	SaHpiIdrIdT	idrid;

	int inv_discovered = 0;
		
	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);
				}
				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);
		}
	}
	
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
	if (rv != SA_OK) {
		printf("saHpiSessionOpen error %s\n",oh_lookup_error(rv));
		exit(-1);
	}

	do {
		rv = saHpiDiscover(sessionid);
		if (fxdebug) printf("saHpiDiscover rv = %s\n",oh_lookup_error(rv));
		if (rv != SA_OK) {
			printf("saHpiDiscover error %s\n",oh_lookup_error(rv));
			// continue anyway exit(-1);
		}

		/* walk the RPT list */
		rptentryid = SAHPI_FIRST_ENTRY;
		do {
			rvRptGet = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
			if (rvRptGet != SA_OK) printf("RptEntryGet error %s\n",oh_lookup_error(rvRptGet));

			if (rvRptGet == SA_OK 
                    		&& (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_RDR)
                    		&& (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA))
			{
				/* walk the RDR list for this RPT entry */
				entryid = SAHPI_FIRST_ENTRY;			
				resourceid = rptentry.ResourceId;

				if (fdebug) printf("rptentry[%d] resourceid=%d\n", entryid,resourceid);

				 do {
					rvRdrGet = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr);
					if (fxdebug) printf("saHpiRdrGet[%d] rv = %s\n",entryid,oh_lookup_error(rvRdrGet));

					if (rvRdrGet == SA_OK)
					{
						if (rdr.RdrType == SAHPI_INVENTORY_RDR)
						{
                                                	inv_discovered = 1;
														
							idrid = rdr.RdrTypeUnion.InventoryRec.IdrId;
							rvInvent = saHpiIdrInfoGet(
										sessionid,
										resourceid,
										idrid,
										&idrInfo);		

							if (rvInvent !=SA_OK) {
								printf("saHpiIdrInfoGet IdrId %d,  error %s\n", idrid, oh_lookup_error(rvInvent));
							} else {
								printf("\nIdr for %s, ResourceId: %d\n",
									 rptentry.ResourceTag.Data,resourceid);
								oh_print_idrinfo(&idrInfo, 4);
								walkInventory(sessionid, resourceid, &idrInfo);
							}
													} 
					}
					entryid = nextentryid;
				} while ((rvRdrGet == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;
			}
			rptentryid = nextrptentryid;
		} while ((rvRptGet == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY));


	/* 
	   Because INVENTORY RDR will be added after some time, 
	   we need to monitor RptInfo here; IMPI plugin.
	
	   Try again if none was found this pass 
	*/        
	} while (!inv_discovered);
	rv = saHpiSessionClose(sessionid);
	/* rv = saHpiFinalize();	*/
	
	exit(0);
}
Exemplo n.º 17
0
SaErrorT list_inv(SaHpiSessionIdT sessionid,SaHpiResourceIdT resourceid)
{
	SaErrorT rv       = SA_OK,
	         rvRdrGet = SA_OK,
 		 rvRptGet = SA_OK, 
 		 rvInvent = SA_OK;
	SaHpiRptEntryT rptentry;
	SaHpiEntryIdT rptentryid;
	SaHpiEntryIdT nextrptentryid;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiRdrT rdr;
	SaHpiIdrInfoT	idrInfo;
	SaHpiIdrIdT	idrid;
	SaHpiResourceIdT l_resourceid;
	SaHpiTextBufferT working;
		
	oh_init_textbuffer(&working);																		
																
	/* walk the RPT list */
	rptentryid = SAHPI_FIRST_ENTRY;
	do {
		
		if (fdebug) printf("saHpiRptEntryGet\n");
		rvRptGet = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
		if ((rvRptGet != SA_OK) || fdebug) 
		       	printf("RptEntryGet returns %s\n",oh_lookup_error(rvRptGet));
			if (rvRptGet == SA_OK 
                   		&& (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_RDR) 
				&& ((resourceid == 0xFF) || (resourceid == rptentry.ResourceId)))
			{
				l_resourceid = rptentry.ResourceId;
				if (resourceid != 0xFF) 
					 nextrptentryid = SAHPI_LAST_ENTRY;

				/* walk the RDR list for this RPT entry */
				entryid = SAHPI_FIRST_ENTRY;			

				if (fdebug) printf("rptentry[%d] resourceid=%d\n", entryid,resourceid);

				do {
					rvRdrGet = saHpiRdrGet(sessionid,l_resourceid, entryid,&nextentryid, &rdr);
					if (fdebug) printf("saHpiRdrGet[%d] rv = %s\n",entryid,oh_lookup_error(rvRdrGet));

					if (rvRdrGet == SA_OK)
					{
						if (rdr.RdrType == SAHPI_INVENTORY_RDR)
						{
														
							idrid = rdr.RdrTypeUnion.InventoryRec.IdrId;
							rvInvent = saHpiIdrInfoGet(
										sessionid,
										l_resourceid,
										idrid,
										&idrInfo);		

							if (rvInvent !=SA_OK) {
								printf("saHpiIdrInfoGet: ResourceId %d IdrId %d, error %s\n",
									l_resourceid, idrid, oh_lookup_error(rvInvent));
							} else {
								snprintf(working.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH,
								 	"\nIdr for %s, ResourceId: %d\n",
									 rptentry.ResourceTag.Data,l_resourceid);
								oh_print_text(&working);
								oh_print_idrinfo(&idrInfo, 4);
								walkInventory(sessionid, l_resourceid, &idrInfo);
							}
													} 
					}
					entryid = nextentryid;
				} while ((rvRdrGet == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;
			}
			rptentryid = nextrptentryid;
		} while ((rvRptGet == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY));

	return(rv);
}