Esempio n. 1
0
int TestField(SaHpiSessionIdT sessionId,
	      SaHpiResourceIdT resourceId,
	      SaHpiIdrIdT IdrId, SaHpiEntryIdT AreaId)
{
	SaErrorT status;
	int retval;
	int response;
	SaHpiIdrFieldT Field;

	response = getField(sessionId, resourceId, IdrId, AreaId, &Field);
	if (response == SAF_TEST_NOTSUPPORT) {
		retval = SAF_TEST_NOTSUPPORT;
	} else if (response == SAF_TEST_FAIL) {
		e_trace();
		retval = SAF_TEST_UNRESOLVED;
	} else {

		Field.ReadOnly = SAHPI_FALSE;
		status = saHpiIdrFieldSet(sessionId,
					  resourceId,
					  INVALID_INVENTORY_ID, &Field);

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

	return retval;
}
Esempio n. 2
0
static int set_inventory_field(SaHpiSessionIdT sessionId, SaHpiResourceIdT rptid, SaHpiIdrIdT rdrnum)
{
	SaErrorT	rv;
	SaHpiIdrFieldT	field;
	char		buf[256];
	int		res, i;

	memset(&field, 0, sizeof(SaHpiIdrFieldT));
	i = get_int_param("Area Id: ", &res);
	if (i != 1) {
		printf("Error!!! Invalid Area Id\n");
		return(-1);
	};
	field.AreaId = res;

	i = get_int_param("Field Id: ", &res);
	if (i != 1) {
		printf("Error!!! Invalid Field Id\n");
		return(-1);
	};
	field.FieldId = res;

	i = get_string_param("Field type(chass,time,manuf,prodname,prodver,"
		"snum,pnum,file,tag,custom): ", buf, 9);
	if (i == 0) {
		for (i = 0; Field_types[i].name != (char *)NULL; i++)
			if (strcmp(Field_types[i].name, buf) == 0) break;
		if (Field_types[i].name == (char *)NULL) {
			printf("Error!!! Unknown Field type: %s\n", buf);
			return(-1);
		};
		field.Type = Field_types[i].val;
	};
	i = set_text_buffer(&(field.Field));
	if (i != 0) {
		printf("Invalid text\n");
		return(HPI_SHELL_CMD_ERROR);
	};
	rv = saHpiIdrFieldSet(sessionId, rptid, rdrnum, &field);
	if (rv != SA_OK) {
		printf("ERROR!!! saHpiIdrFieldSet: %s\n", oh_lookup_error(rv));
		return(rv);
	};
	return(SA_OK);
}
Esempio n. 3
0
static ret_code_t set_inventory_field(SaHpiSessionIdT sessionId,
	SaHpiResourceIdT rptid, SaHpiIdrIdT rdrnum)
{
	SaErrorT	rv;
	SaHpiIdrFieldT	field, read_field;
	SaHpiEntryIdT	next;
	int		res, i;

	memset(&field, 0, sizeof(SaHpiIdrFieldT));
	i = get_int_param("Area Id: ", &res);
	if (i != 1) {
		printf("Error!!! Invalid Area Id\n");
		return(HPI_SHELL_PARM_ERROR);
	};
	field.AreaId = res;

	i = get_int_param("Field Id: ", &res);
	if (i != 1) {
		printf("Error!!! Invalid Field Id\n");
		return(HPI_SHELL_PARM_ERROR);
	};
	field.FieldId = res;
	
	rv = saHpiIdrFieldGet(sessionId, rptid, rdrnum, field.AreaId,
		SAHPI_IDR_FIELDTYPE_UNSPECIFIED, field.FieldId, &next, &read_field);
	if (rv != SA_OK) {
		printf("ERROR!!! saHpiIdrFieldGet: %s\n", oh_lookup_error(rv));
		return(HPI_SHELL_CMD_ERROR);
	};
	field.Type = read_field.Type;

	i = set_text_buffer(&(field.Field));
	if (i != 0) {
		printf("Invalid text\n");
		return(HPI_SHELL_PARM_ERROR);
	};
	rv = saHpiIdrFieldSet(sessionId, rptid, rdrnum, &field);
	if (rv != SA_OK) {
		printf("ERROR!!! saHpiIdrFieldSet: %s\n", oh_lookup_error(rv));
		return(HPI_SHELL_CMD_ERROR);
	};
	return(HPI_SHELL_OK);
}
Esempio n. 4
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);
}
Esempio n. 5
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;
}
Esempio n. 6
0
int TestField(SaHpiSessionIdT sessionId,
	      SaHpiResourceIdT resourceId,
	      SaHpiIdrIdT IdrId, SaHpiEntryIdT AreaId)
{
	SaErrorT status;
	int retval;
	SaHpiIdrFieldT Field;
	SaHpiEntryIdT NextFieldId;

	status = addCustomField(sessionId, resourceId, IdrId, AreaId, &Field);
	if (status == SA_ERR_HPI_INVALID_DATA) {
		retval = SAF_TEST_NOTSUPPORT;
	} else if (status == SA_ERR_HPI_OUT_OF_SPACE) {
		retval = SAF_TEST_NOTSUPPORT;
	} else if (status != SA_OK) {
		retval = SAF_TEST_UNRESOLVED;
		e_print(saHpiIdrFieldAdd, SA_OK, status);
	} else {

		// Set a new value in the field. 

		Field.Field.Data[0] = 's';
		status = saHpiIdrFieldSet(sessionId, resourceId, IdrId, &Field);

		if (status == SA_ERR_HPI_INVALID_DATA) {

			retval = SAF_TEST_NOTSUPPORT;

		} else if (status != SA_OK) {

			retval = SAF_TEST_FAIL;
			e_print(saHpiIdrFieldSet, SA_OK, status);

		} else {

			status = saHpiIdrFieldGet(sessionId,
						  resourceId,
						  IdrId, AreaId,
						  SAHPI_IDR_FIELDTYPE_CUSTOM,
						  Field.FieldId,
						  &NextFieldId, &Field);

			if (status != SA_OK) {
				retval = SAF_TEST_UNRESOLVED;
				e_print(saHpiIdrFieldGet, SA_OK, status);
			} else if (Field.Field.Data[0] == 's') {
				retval = SAF_TEST_PASS;
			} else {
				retval = SAF_TEST_FAIL;
			}
		}

		// Clean up
		status = saHpiIdrFieldDelete(sessionId, resourceId,
					     IdrId, AreaId, Field.FieldId);

		if (status != SA_OK) {
			e_print(saHpiIdrFieldDelete, SA_OK, status);
		}
	}

	return retval;
}