Esempio n. 1
0
Pr_ret_t show_sensor_list(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid,
		hpi_ui_print_cb_t proc)
{
	SaErrorT	rv = SA_OK;
	SaHpiEntryIdT	entryid;
	SaHpiEntryIdT	nextentryid;
	SaHpiRdrT	rdr;
	char		buf[SHOW_BUF_SZ];

	entryid = SAHPI_FIRST_ENTRY;
	while (entryid != SAHPI_LAST_ENTRY) {
		rv = saHpiRdrGet(sessionid, resourceid, entryid, &nextentryid, &rdr);
		if (rv != SA_OK)
			break;
		if (rdr.RdrType == SAHPI_SENSOR_RDR) {
			snprintf(buf, 256, "Resource Id: %d, Sensor Num: %d",
				resourceid, rdr.RdrTypeUnion.SensorRec.Num);
			if (proc(buf) != 0) return(HPI_UI_END);
			if (print_text_buffer_text(" Tag: ", &(rdr.IdString),
				NULL, proc) != 0)
				return(-1);
			if (proc("\n") != 0) return(HPI_UI_END);
		};
		entryid = nextentryid;
	};
	return(HPI_UI_OK);
}
Esempio n. 2
0
int Test_Resource(SaHpiSessionIdT session_id, SaHpiRptEntryT rpt_entry,
		  callback2_t func)
{
	SaHpiResourceIdT resource_id = rpt_entry.ResourceId;
	SaHpiEntryIdT next_rdr;
	SaErrorT val;
	SaHpiRdrT rdr;
	int ret = SAF_TEST_UNKNOWN;

	if (rpt_entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR) {
		val =
		    saHpiRdrGet(INVALID_SESSION_ID, resource_id,
				SAHPI_FIRST_ENTRY, &next_rdr, &rdr);

		if (val != SA_ERR_HPI_INVALID_SESSION) {
			e_print(saHpiRdrGet, SA_ERR_HPI_INVALID_SESSION, val);
			ret = SAF_TEST_FAIL;
		} else {
			ret = SAF_TEST_PASS_AND_EXIT;
		}
	} else
		ret = SAF_TEST_NOTSUPPORT;

	return ret;
}
Esempio n. 3
0
SaErrorT list_rdr(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid)
{
	SaErrorT rv       = SA_OK,
	         rvRdrGet = SA_OK,
 		 rvRptGet = SA_OK;

	SaHpiRptEntryT rptentry;
	SaHpiEntryIdT rptentryid;
	SaHpiEntryIdT nextrptentryid;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiRdrT rdr;
	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)
					{
						snprintf(working.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH,
							 "\nRdr for %s, ResourceId: %d\n",
							 rptentry.ResourceTag.Data,l_resourceid);
						oh_print_text(&working);

						oh_print_rdr(&rdr, 4);
					}
					entryid = nextentryid;
				} while ((rvRdrGet == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;
			}
			rptentryid = nextrptentryid;
		} while ((rvRptGet == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY));

	return(rv);
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	SaHpiSessionIdT sid = 0;
	SaHpiRptEntryT res;
	SaHpiRdrT rdr;
	SaHpiEntryIdT id = SAHPI_FIRST_ENTRY;
	SaHpiResourceIdT resid;
	int failcount = 0;
	int testnum = 0;
	SaErrorT rc = SA_OK;

        rc = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sid, NULL);
	if(rc != SA_OK) {
		failed("Failed to open session");
	}

	rc = saHpiDiscover(sid);
	if(rc != SA_OK) {
		failed("Failed to run discover");
	}
						
        rc = saHpiRptEntryGet(sid, id, &id, &res);
        runtest();
        if(rc != SA_OK) {
		dbg("Error %s",oh_lookup_error(rc));
		failed("Couldn't get the first rpt entry");
		/* we're toast, bail */
		goto end;
	}
	else{
		id = SAHPI_FIRST_ENTRY;
		resid = res.ResourceId;
		rc = saHpiRdrGet(sid, resid, id, &id, &rdr);
		if (oh_cmp_ep(&rdr.Entity,&res.ResourceEntity) != SAHPI_TRUE){
			dbg("Error %s", oh_lookup_error(rc));
			failed("Entity path of rdr did not match entity path of resource");
		}
		runtest();
		if(rc != SA_OK){
			dbg("Error %s", oh_lookup_error(rc));
			failed("Couldn't get the first rdr entry");
			goto end;
		}
	}
	
	dbg("Ran %d tests", testnum);
	/* if there is any failures, the test fails */
	end:
		if(failcount) {
			return -1;
		}

	return(0);
}
Esempio n. 5
0
SaErrorT find_rdr_by_num(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid,
                         SaHpiInstrumentIdT num, SaHpiRdrTypeT type, int as,
                         SaHpiRdrT *retrdr)
//as : 0 - get rdr by num
//     1 - get first rdr
{
    SaHpiRdrT		rdr;
    SaErrorT		rv;
    SaHpiEntryIdT		entryid;
    SaHpiEntryIdT		nextentryid;
    SaHpiInstrumentIdT	rdrnum;

    entryid = SAHPI_FIRST_ENTRY;
    while (entryid !=SAHPI_LAST_ENTRY) {
        rv = saHpiRdrGet(sessionid, resourceid, entryid, &nextentryid, &rdr);
        if (rv != SA_OK) return(-1);
        if ((type != SAHPI_NO_RECORD) && (rdr.RdrType != type))
            continue;
        switch (rdr.RdrType) {
        case SAHPI_CTRL_RDR:
            rdrnum = rdr.RdrTypeUnion.CtrlRec.Num;
            break;
        case SAHPI_SENSOR_RDR:
            rdrnum = rdr.RdrTypeUnion.SensorRec.Num;
            break;
        case SAHPI_INVENTORY_RDR:
            rdrnum = rdr.RdrTypeUnion.InventoryRec.IdrId;
            break;
        case SAHPI_WATCHDOG_RDR:
            rdrnum = rdr.RdrTypeUnion.WatchdogRec.WatchdogNum;
            break;
        case SAHPI_ANNUNCIATOR_RDR:
            rdrnum = rdr.RdrTypeUnion.AnnunciatorRec.AnnunciatorNum;
            break;
        case SAHPI_DIMI_RDR:
            rdrnum = rdr.RdrTypeUnion.DimiRec.DimiNum;
            break;
        case SAHPI_FUMI_RDR:
            rdrnum = rdr.RdrTypeUnion.FumiRec.Num;
            break;
        default:
            entryid = nextentryid;
            continue;
        };
        if ((rdrnum == num) || as) {
            *retrdr = rdr;
            return(SA_OK);
        };
        entryid = nextentryid;
    };
    return(-1);
}
Esempio n. 6
0
static int sa_list_sensor(void)
{
        SaErrorT rv = SA_OK;
        SaHpiEntryIdT rptentryid;
        SaHpiRptEntryT rptentry;
        SaHpiEntryIdT nextrptentryid;
        SaHpiEntryIdT entryid;
        SaHpiEntryIdT nextentryid;
        SaHpiResourceIdT resourceid;
        SaHpiRdrT rdr;
        SaHpiEntityPathT ep_target;
        char *ep_string = NULL;

        /* 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) {
                        /* Walk the RDR list for this RPT entry */

                        /* Filter by entity path if specified */
                        if (ep_string && !oh_cmp_ep(&ep_target,&(rptentry.ResourceEntity))) {
                                rptentryid = nextrptentryid;
                                continue;
                        }

                        entryid = SAHPI_FIRST_ENTRY;
                        resourceid = rptentry.ResourceId;
                        rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0;
                        while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
                        {
                                rv = saHpiRdrGet(sessionid,resourceid,
                                                 entryid,&nextentryid, &rdr);
                                if (rv == SA_OK) {
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR &&
                                                rdr.RdrTypeUnion.SensorRec.Ignore != TRUE) {
						printf("Resource Id: %d, Sensor Id: %d\n",
							resourceid, rdr.RdrTypeUnion.SensorRec.Num);
                                        } 

                                        entryid = nextentryid;
                                } else {
                                        rv = SA_OK;
                                        entryid = SAHPI_LAST_ENTRY;
                                }
                        }
                        rptentryid = nextrptentryid;
                }
        }
	return rv;
}
Esempio n. 7
0
static int
get_sensor_num(SaHpiSessionIdT ohsession, SaHpiResourceIdT ohresid)
{
	SaErrorT	ohrc = SA_OK;
	SaHpiEntryIdT	ohnextid;
	SaHpiRdrT	ohRDR;

	ohnextid = SAHPI_FIRST_ENTRY;
	do {
		ohrc = saHpiRdrGet(ohsession, ohresid, ohnextid
				, &ohnextid, &ohRDR);
		if (ohrc != SA_OK) {
			LOG(PIL_CRIT, "Unable to get RDR entry in %s (%d)"
			,	__FUNCTION__, ohrc);
		} else if (ohRDR.RdrType == SAHPI_SENSOR_RDR) {
			return ohRDR.RdrTypeUnion.SensorRec.Num;
		}
	} while (ohrc == SA_OK && ohnextid != SAHPI_LAST_ENTRY);

	return 0;
}
Esempio n. 8
0
static void get_rdrs(Rpt_t *Rpt)
{
	SaHpiRdrT		rdr;
	SaErrorT		rv;
	int			n;
	SaHpiEntryIdT		entryid;
	SaHpiEntryIdT		nextentryid;
	SaHpiResourceIdT	resourceid;

	entryid = SAHPI_FIRST_ENTRY;
	while (entryid !=SAHPI_LAST_ENTRY) {
		resourceid = Rpt->Rpt.ResourceId;
		rv = saHpiRdrGet(sessionid, resourceid, entryid, &nextentryid, &rdr);
		if (rv != SA_OK)
			break;
		n = Rpt->nrdrs;
		Rpt->rdrs = (Rdr_t *)resize_array(Rpt->rdrs, sizeof(Rdr_t), &(Rpt->nrdrs), 1);
		rdr.IdString.Data[rdr.IdString.DataLength] = 0;
		Rpt->rdrs[n].Rdr = rdr;
		entryid = nextentryid;
	}
}
Esempio n. 9
0
int testResource(SaHpiSessionIdT sessionId, SaHpiResourceIdT resourceId) {
     int retval = SAF_TEST_NOTSUPPORT;
     int response;
     SaErrorT error;
     SaHpiEntryIdT nextEntryId;
     SaHpiEntryIdT entryId;
     SaHpiRdrT rdr;
     SaHpiBoolT pass = SAHPI_FALSE;

     nextEntryId = SAHPI_FIRST_ENTRY;
     while (nextEntryId != SAHPI_LAST_ENTRY && retval == SAF_TEST_NOTSUPPORT) {
          entryId = nextEntryId;
          error = saHpiRdrGet(sessionId, resourceId, entryId, &nextEntryId, &rdr);
          if (error == SA_ERR_HPI_NOT_PRESENT) {
              break;
          } else if (error != SA_OK) {
              retval = SAF_TEST_UNRESOLVED;
              e_print(saHpiRdrGet, SA_OK, error);
          } else {
              response = canTest(sessionId, resourceId, &rdr);
              if (response != SAF_TEST_PASS) {
                   retval = response;
              } else {
                   response = testSensor(sessionId, resourceId, &rdr);
                   if (response == SAF_TEST_PASS) {
                       pass = SAHPI_TRUE;
                   } else {
                       retval = response;
                   }
              }
          }
     }

     if (retval == SAF_TEST_NOTSUPPORT && pass) {
         retval = SAF_TEST_PASS;
     }

     return retval;
}
Esempio n. 10
0
void list_rdr(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id)
{
        SaErrorT        err;
	SaHpiEntryIdT	current_rdr;
	SaHpiEntryIdT	next_rdr;
	SaHpiRdrT	rdr;

	printf("RDR Info:\n");
	next_rdr = SAHPI_FIRST_ENTRY;
	do {
		int i;
		current_rdr = next_rdr;
		err = saHpiRdrGet(session_id, resource_id, current_rdr, 
				&next_rdr, &rdr);
		if (SA_OK != err) {
			if (current_rdr == SAHPI_FIRST_ENTRY)
				printf("Empty RDR table\n");
			else
				error("saHpiRdrGet", err);
			return;			
		}
		
		printf("\tRecordId: %x\n", rdr.RecordId);
		printf("\tRdrType: %s\n", rdrtype2str(rdr.RdrType));
		printf("\tEntity: \n");
		for ( i=0; i<SAHPI_MAX_ENTITY_PATH; i++)
		{
			SaHpiEntityT tmp = rdr.Entity.Entry[i];
			if (tmp.EntityType <= SAHPI_ENT_UNSPECIFIED)
				break;
				printf("\t\t{%s, %i}\n", 
				type2string(tmp.EntityType),
				tmp.EntityInstance);
		}
		printf("\tIdString: ");
	       	display_id_string(rdr.IdString);
	}while(next_rdr != SAHPI_LAST_ENTRY);
}
Esempio n. 11
0
SaErrorT show_sensor_list(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid,
		hpi_ui_print_cb_t proc)
{
	SaErrorT	rv = SA_OK;
	SaHpiEntryIdT	entryid;
	SaHpiEntryIdT	nextentryid;
	SaHpiRdrT	rdr;
	char		buf[256];

	entryid = SAHPI_FIRST_ENTRY;
	while (entryid != SAHPI_LAST_ENTRY) {
		rv = saHpiRdrGet(sessionid, resourceid, entryid, &nextentryid, &rdr);
		if (rv != SA_OK)
			break;
		if (rdr.RdrType == SAHPI_SENSOR_RDR) {
			snprintf(buf, 256, "Resource Id: %d, Sensor Num: %d\n",
				resourceid, rdr.RdrTypeUnion.SensorRec.Num);
			if (proc(buf) != 0)
				return(-1);
		};
		entryid = nextentryid;
	};
	return(rv);
}
Esempio n. 12
0
int main(int argc, char **argv) 
{

	/* ************************
	 * Local variables
	 * ***********************/	 
	int testfail = 0;
	SaErrorT          err;
	SaErrorT expected_err;
        SaHpiRptEntryT rptentry;
	SaHpiResourceIdT  id;
        SaHpiSessionIdT sessionid;
	SaHpiRdrT	rdr;
	SaHpiCtrlNumT cid = 1;
	SaHpiCtrlModeT mode;
	SaHpiCtrlStateT state;
													   
	/* *************************************	 	 
	 * Find a resource with Control type rdr
	 * ************************************* */
	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_CONTROL, SAHPI_FIRST_ENTRY, &rptentry, SAHPI_TRUE);
	if (err != SA_OK) {
		printf("Can not find a control resource for test environment\n");
		printf("       File=%s, Line=%d\n", __FILE__, __LINE__);
		err = tcleanup(&sessionid);
		return SA_OK;
	}
	
	id = rptentry.ResourceId;
	/************************** 
	 * Test: find a control RDR
	 **************************/
	SaHpiEntryIdT entryid = SAHPI_FIRST_ENTRY;
	SaHpiEntryIdT nextentryid;
	SaHpiBoolT foundControl = SAHPI_FALSE;			
	do {
		err = saHpiRdrGet(sessionid,id,entryid,&nextentryid, &rdr);
		if (err == SA_OK)
		{
			if (rdr.RdrType == SAHPI_CTRL_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 {
		cid = rdr.RdrTypeUnion.CtrlRec.Num; 
	}	

	/************************** 
	 * Test 1: Invalid Handle    
	 *************************/
	struct oh_handler_state l_handle;
	memset(&l_handle, 0, sizeof(struct oh_handler_state));
	expected_err = SA_ERR_HPI_INVALID_PARAMS;
	err = snmp_bc_get_control_state(NULL, id, cid, &mode, &state);
	checkstatus(err, expected_err, testfail);
	
	/************************** 
	 * Test 2: Resource ID with no RPT
	 *************************/
	expected_err = SA_ERR_HPI_INVALID_RESOURCE;
	err = saHpiControlGet(sessionid, 5000, cid, &mode, &state);
	checkstatus(err, expected_err, testfail);
	
	/************************** 
	 * Test 3: Control ID with no RDR 
	 *************************/
	expected_err = SA_ERR_HPI_NOT_PRESENT;
	err = saHpiControlGet(sessionid, id, 5000, &mode, &state);
	checkstatus(err, expected_err, testfail);
	
	/************************** 
	 * Test 4: NULL mode and state    
	 *************************/
	expected_err = SA_OK;
	err = saHpiControlGet(sessionid, id, cid, NULL, NULL);
	checkstatus(err, expected_err, testfail);
	
	/************************** 
	 * Test: resource without SAHPI_CAPABILITY_CONTROL    
	 *************************/
	err = tfind_resource(&sessionid, SAHPI_CAPABILITY_CONTROL, SAHPI_FIRST_ENTRY, &rptentry, SAHPI_FALSE);
	if (err != SA_OK) {
		printf("Error! Can not find resources for test environment\n");
		printf("       File=%s, Line=%d\n", __FILE__, __LINE__);
		err = tcleanup(&sessionid);
		return SA_OK;
	}		
	expected_err = SA_ERR_HPI_CAPABILITY;
	err = saHpiControlGet(sessionid, rptentry.ResourceId, cid, &mode, &state);
	checkstatus(err, expected_err, testfail);
	/***************************
	 * Cleanup after all tests
	 ***************************/
	 err = tcleanup(&sessionid);
	 return testfail;

}
Esempio n. 13
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;
}
Esempio n. 14
0
int main(int argc, char **argv) 
{

	/* ************************
	 * Local variables
	 * ***********************/	 
	int testfail = 0;
	SaErrorT          err;
	SaErrorT expected_err;

	SaHpiResourceIdT  id;
        SaHpiSessionIdT sessionid;
        SaHpiRptEntryT    rptentry;
	SaHpiRdrT         rdr;
	SaHpiSensorNumT   dd_sid = 0;
	SaHpiEventStateT state;
	SaHpiSensorReadingT reading;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiBoolT foundSensor;			
													    
	/* *************************************	 	 
	 * Find a resource with Sensor type rdr
	 * ************************************* */
	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_SENSOR,SAHPI_FIRST_ENTRY, &rptentry, SAHPI_TRUE);
	if (err != SA_OK) {
		printf("Error! Can not find resources for test environment\n");
		printf("      File=%s, Line=%d\n", __FILE__, __LINE__);
		err = tcleanup(&sessionid);
		return -1;
	}

	id = rptentry.ResourceId;
	/************************** 
	 * Test: find a sensor with desired property
	 **************************/
	entryid = SAHPI_FIRST_ENTRY;
	foundSensor = SAHPI_FALSE;			
	do {
		err = saHpiRdrGet(sessionid,id,entryid,&nextentryid, &rdr);
		if (err == SA_OK)
		{
			if ((rdr.RdrType == SAHPI_SENSOR_RDR) &&
				(rdr.RdrTypeUnion.SensorRec.DataFormat.IsSupported == SAHPI_TRUE))
			{
				foundSensor = SAHPI_TRUE;
				break;
														
			}
			entryid = nextentryid;
		}
	} while ((err == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;

	if (!foundSensor) {
		err("Did not find desired resource for test\n");
		return(SA_OK);
	} else {
		dd_sid = rdr.RdrTypeUnion.SensorRec.Num; 
	}	

	/************************** 
	 * Test : Read sensor with NULL Reading area. State only 
	 **************************/
	expected_err = SA_OK;                   
	err = saHpiSensorReadingGet(sessionid, id, dd_sid, NULL, &state);
	checkstatus(err, expected_err, testfail);

	/************************** 
	 * Test:Read with NULL State area, Read Value only 
	 **************************/
	err = saHpiSensorReadingGet(sessionid, id, dd_sid, &reading, NULL);
	checkstatus(err, expected_err, testfail);

	/************************** 
	 * Test: Both Reading and State are NULL. ie checking for sensor existance
	 **************************/
	err = saHpiSensorReadingGet(sessionid, id, dd_sid, NULL, NULL);
	checkstatus(err, expected_err, testfail);
	
	/***************************
	 * Cleanup after all tests
	 ***************************/
	 err = tcleanup(&sessionid);
	 return testfail;

}
Esempio n. 15
0
int show_rdr_list(Domain_t *domain, SaHpiResourceIdT rptid, SaHpiRdrTypeT passed_type,
	hpi_ui_print_cb_t proc)
//  return: list size
{
	SaHpiRdrT		rdr;
	SaHpiEntryIdT		entryid;
	SaHpiEntryIdT		nextentryid;
	char			buf[SHOW_BUF_SZ];
	SaHpiRdrTypeT		type;
	char			ar[256];
	SaHpiSensorRecT		*sensor;
	SaHpiCtrlRecT		*ctrl;
	SaHpiInventoryRecT	*inv;
	SaHpiWatchdogRecT	*wdog;
	SaHpiAnnunciatorRecT	*ann;
	SaErrorT		ret;
	int			res_num = 0;

	entryid = SAHPI_FIRST_ENTRY;
	while (entryid !=SAHPI_LAST_ENTRY) {
		ret = saHpiRdrGet(domain->sessionId, rptid, entryid,
			&nextentryid, &rdr);
		if (ret != SA_OK)
			return(res_num);
		type = rdr.RdrType;
		if ((passed_type != SAHPI_NO_RECORD) && (type != passed_type)) {
			entryid = nextentryid;
			continue;
		};
		snprintf(buf, SHOW_BUF_SZ, "  (%d):%s NUM=", rdr.RecordId,
			oh_lookup_rdrtype(type));
		switch (type) {
			case SAHPI_SENSOR_RDR:
				sensor = &(rdr.RdrTypeUnion.SensorRec);
				snprintf(ar, 256, "%3.3d Ctrl=%d EvtCtrl=",
					sensor->Num, sensor->EnableCtrl);
				switch (sensor->EventCtrl) {
					case SAHPI_SEC_PER_EVENT:
						strcat(ar, "WR"); break;
					case SAHPI_SEC_READ_ONLY_MASKS:
						strcat(ar, "RM"); break;
					default:
						strcat(ar, "RO"); break;
				};
				break;
			case SAHPI_CTRL_RDR:
				ctrl = &(rdr.RdrTypeUnion.CtrlRec);
				snprintf(ar, 256, "%3.3d", ctrl->Num);
				break;
			case SAHPI_INVENTORY_RDR:
				inv = &(rdr.RdrTypeUnion.InventoryRec);
				snprintf(ar, 256, "%3.3d", inv->IdrId);
				break;
			case SAHPI_WATCHDOG_RDR:
				wdog = &(rdr.RdrTypeUnion.WatchdogRec);
				snprintf(ar, 256, "%3.3d", wdog->WatchdogNum);
				break;
			case SAHPI_ANNUNCIATOR_RDR:
				ann = &(rdr.RdrTypeUnion.AnnunciatorRec);
				snprintf(ar, 256, "%3.3d", ann->AnnunciatorNum);
				break;
			default:
				snprintf(ar, 256, "%c", '?');
		};
		strcat(buf, ar);
		res_num++;
		if (proc(buf) != HPI_UI_OK) return(res_num);
		if (print_text_buffer_text(" Tag=", &(rdr.IdString),
			"\n", proc) != HPI_UI_OK)
			return(res_num);
		entryid = nextentryid;
	};
	return(res_num);
}
Esempio n. 16
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;

}
Esempio n. 17
0
int main(int argc, char **argv) 
{

	/* ************************
	 * Local variables
	 * ***********************/	 
	int testfail = 0;
	SaErrorT          err;
	SaErrorT expected_err;
	SaHpiResourceIdT  id = 0;
        SaHpiSessionIdT sessionid;
	SaHpiRptEntryT rptentry;
	SaHpiRdrT	rdr;	 
	SaHpiSensorNumT sid = 0;
	SaHpiSensorThresholdsT thres;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiBoolT foundSensor;			

	/* *************************************	 	 
	 * Find a resource with Sensor type rdr
	 * ************************************* */		
	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_SENSOR,SAHPI_FIRST_ENTRY, &rptentry, SAHPI_TRUE);
	if (err != SA_OK) {
		printf("Error! Can not find resources for test environment\n");
		printf("      File=%s, Line=%d\n", __FILE__, __LINE__);
		err = tcleanup(&sessionid);
		return SA_OK;
	}

	id = rptentry.ResourceId;
	/************************** 
	 * Test: find a sensor with desired property
	 **************************/
	entryid = SAHPI_FIRST_ENTRY;
	foundSensor = SAHPI_FALSE;			
	do {
		err = saHpiRdrGet(sessionid,id,entryid,&nextentryid, &rdr);
		if (err == SA_OK)
		{
			if ((rdr.RdrType == SAHPI_SENSOR_RDR) &&
				(rdr.RdrTypeUnion.SensorRec.Category == SAHPI_EC_THRESHOLD) &&
				(rdr.RdrTypeUnion.SensorRec.ThresholdDefn.WriteThold == 0))
			{
				foundSensor = SAHPI_TRUE;
				break;
														
			}
			entryid = nextentryid;
		}
	} while ((err == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;

	if (!foundSensor) {
		dbg("Did not find desired resource for test\n");
		return(SA_OK);
	} else {
		sid = rdr.RdrTypeUnion.SensorRec.Num; 
	}	


        /************************** 
	 * Test: setting to a non-writeable sensor
         **************************/
        expected_err = SA_ERR_HPI_INVALID_CMD;
	err = saHpiSensorThresholdsSet(sessionid, id, sid, &thres);
        checkstatus(err, expected_err, testfail);
											
	/***************************
	 * Cleanup after all tests
	 ***************************/
	err = tcleanup(&sessionid);
	return testfail;

}
Esempio n. 18
0
int show_rdr_list(Domain_t *domain, SaHpiResourceIdT rptid, SaHpiRdrTypeT passed_type,
                  hpi_ui_print_cb_t proc)
//  return: list size
{
    SaHpiRdrT               rdr;
    SaHpiEntryIdT           entryid;
    SaHpiEntryIdT           nextentryid;
    char                    buf[SHOW_BUF_SZ];
    SaHpiRdrTypeT           type;
    char                    ar[256];
    SaHpiSensorRecT         *sensor;
    SaErrorT                ret;
    int                     res_num = 0;

    entryid = SAHPI_FIRST_ENTRY;
    while (entryid !=SAHPI_LAST_ENTRY) {
        memset(buf, 0, SHOW_BUF_SZ);
        memset(ar, 0, 256);
        ret = saHpiRdrGet(domain->sessionId, rptid, entryid,
                          &nextentryid, &rdr);
        if (ret != SA_OK)
            return(res_num);
        type = rdr.RdrType;
        if ((passed_type != SAHPI_NO_RECORD) && (type != passed_type)) {
            entryid = nextentryid;
            continue;
        };
        snprintf(buf, SHOW_BUF_SZ, "(%3.3d): %s ID=%u",
                 oh_get_rdr_num(rdr.RecordId),
                 oh_lookup_rdrtype(type), rdr.RecordId);
        switch (type) {
        case SAHPI_SENSOR_RDR:
            sensor = &(rdr.RdrTypeUnion.SensorRec);
            snprintf(ar, 256, ", Ctrl=%d, EvtCtrl=",
                     sensor->EnableCtrl);
            switch (sensor->EventCtrl) {
            case SAHPI_SEC_PER_EVENT:
                strcat(ar, "WR");
                break;
            case SAHPI_SEC_READ_ONLY_MASKS:
                strcat(ar, "RM");
                break;
            default:
                strcat(ar, "RO");
                break;
            };
            break;
        case SAHPI_CTRL_RDR:
            break;
        case SAHPI_INVENTORY_RDR:
            break;
        case SAHPI_WATCHDOG_RDR:
            break;
        case SAHPI_ANNUNCIATOR_RDR:
            break;
        case SAHPI_DIMI_RDR:
            break;
        case SAHPI_FUMI_RDR:
            break;
        default:
            snprintf(ar, 256, ", Unrecognized RDR Type");
        };
        strcat(buf, ar);
        res_num++;
        if (proc(buf) != HPI_UI_OK) return(res_num);
        if (print_text_buffer_text(", Tag=", &(rdr.IdString),
                                   "\n", proc) != HPI_UI_OK)
            return(res_num);
        entryid = nextentryid;
    };
    return(res_num);
}
Esempio n. 19
0
int main(int argc, char **argv) 
{

	/* ************************
	 * Local variables
	 * ***********************/	 
	int testfail = 0;
	SaErrorT          err;
	SaErrorT expected_err;
	SaHpiResourceIdT  id;
        SaHpiSessionIdT sessionid;
        SaHpiRptEntryT rptentry;
	SaHpiRdrT	rdr;	
	SaHpiCtrlNumT cid = 1;
	SaHpiCtrlModeT mode;
	SaHpiCtrlStateT state;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiBoolT foundControl;			
													   
	/* *************************************	 	 
	 * Find a resource with Control type rdr
	 * ************************************* */
	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_CONTROL, SAHPI_FIRST_ENTRY, &rptentry, SAHPI_TRUE);
	if (err != SA_OK) {
		printf("Can not find a control resource for test environment\n");
		printf("       File=%s, Line=%d\n", __FILE__, __LINE__);
		err = tcleanup(&sessionid);
		return SA_OK;
	}
	
	id = rptentry.ResourceId;
	/************************** 
	 * Test: find a control RDR
	 **************************/
	entryid = SAHPI_FIRST_ENTRY;
	foundControl = SAHPI_FALSE;			
	do {
		err = saHpiRdrGet(sessionid,id,entryid,&nextentryid, &rdr);
		if (err == SA_OK)
		{
			if (rdr.RdrType == SAHPI_CTRL_RDR) 
			{
				foundControl = SAHPI_TRUE;
				break;
														
			}
			entryid = nextentryid;
		}
	} while ((err == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;

	if (!foundControl) {
		err("Did not find desired resource for test\n");
		return(SA_OK);
	} else {
		cid = rdr.RdrTypeUnion.CtrlRec.Num; 
	}	

	/************************** 
	 * Test 1: Normal get    
	 *************************/
	expected_err = SA_OK;
	err = saHpiControlGet(sessionid, id, cid, &mode, &state);
	checkstatus(err, expected_err, testfail);
	
	/************************** 
	 * Test 2: Get with no mode
	 * expected_err = SA_OK;
	 *************************/
	err = saHpiControlGet(sessionid, id, cid, NULL, &state);
	checkstatus(err, expected_err, testfail);
	
	/************************** 
	 * Test 3: Get with no state 
	 * expected_err = SA_OK;
	 *************************/
	err = saHpiControlGet(sessionid, id, cid, &mode, NULL);
	checkstatus(err, expected_err, testfail);
	
	/***************************
	 * Cleanup after all tests
	 ***************************/
	 err = tcleanup(&sessionid);
	 return testfail;

}
Esempio n. 20
0
void list_rdr(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id)
{
        SaErrorT             	err;
        SaHpiEntryIdT        	current_rdr;
        SaHpiEntryIdT        	next_rdr;
        SaHpiRdrT            	rdr;

	SaHpiSensorReadingT	reading;
	SaHpiSensorTypeT	sensor_type;
	SaHpiSensorNumT		sensor_num;
	SaHpiEventCategoryT	category;
	SaHpiSensorThresholdsT	thres; 

	SaHpiCtrlNumT   	ctrl_num;
	SaHpiCtrlStateT 	state;
	SaHpiCtrlTypeT  	ctrl_type;

        SaHpiEirIdT             l_eirid;
        SaHpiInventoryDataT*    l_inventdata;
	const SaHpiUint32T	l_inventsize = 16384;
        SaHpiUint32T            l_actualsize;


        printf("RDR Info:\n");
        next_rdr = SAHPI_FIRST_ENTRY;
        do {
                char tmp_epath[128];
                current_rdr = next_rdr;
                err = saHpiRdrGet(session_id, resource_id, current_rdr, 
                                  &next_rdr, &rdr);
                if (SA_OK != err) {
                        if (current_rdr == SAHPI_FIRST_ENTRY)
                                printf("Empty RDR table\n");
                        else
                                error("saHpiRdrGet", err);
                        return;                        
                }
                
                printf("\tRecordId: %x\n", rdr.RecordId);
                printf("\tRdrType: %s\n", rdrtype2str(rdr.RdrType));
		
		if (rdr.RdrType == SAHPI_SENSOR_RDR)
		{			
			SaErrorT val;
			
			sensor_num = rdr.RdrTypeUnion.SensorRec.Num;
			
			val = saHpiSensorTypeGet(session_id, resource_id, 
						 sensor_num, &sensor_type, 
						 &category);
			
			printf("\tSensor num: %i\n\tType: %s\n", sensor_num, get_sensor_type(sensor_type)); 
			printf("\tCategory: %s\n", get_sensor_category(category)); 

			memset(&reading, 0, sizeof(SaHpiSensorReadingT));

			err = saHpiSensorReadingGet(session_id, resource_id, sensor_num, &reading);
			if (err != SA_OK) {
				printf("Error=%d reading sensor data {sensor, %d}\n", err, sensor_num);
				continue;
			}

			if (reading.ValuesPresent & SAHPI_SRF_RAW) {
				printf("\tValues Present: RAW\n");
				printf("\t\tRaw value: %d\n", reading.Raw);
			}

			if (reading.ValuesPresent & SAHPI_SRF_INTERPRETED) {
				printf("\tValues Present: Interpreted\n");
                                printf("\t\t");
				interpreted2str(reading.Interpreted);
			}

			if (reading.ValuesPresent & SAHPI_SRF_EVENT_STATE) {
				printf("\tValues Present: Event State\n");
			}

			if (rdr.RdrTypeUnion.SensorRec.ThresholdDefn.IsThreshold == SAHPI_TRUE) {
                                memset(&thres, 0, sizeof(SaHpiSensorThresholdsT));
				err = saHpiSensorThresholdsGet(session_id, resource_id, sensor_num, &thres);
				if (err != SA_OK) {
					printf("Error=%d reading sensor thresholds {sensor, %d}\n", err, sensor_num);
					continue;
				}
				
				if (thres.LowCritical.ValuesPresent) {
					printf("\t\tThreshold:  Low Critical Values\n");
					printreading(thres.LowCritical);
				}
				if (thres.LowMajor.ValuesPresent) {
					printf("\t\tThreshold:  Low Major Values\n");
					printreading(thres.LowMajor);
				}
				if (thres.LowMinor.ValuesPresent) {
					printf("\t\tThreshold:  Low Minor Values\n");
					printreading(thres.LowMinor);
				}
				if (thres.UpCritical.ValuesPresent) {
					printf("\t\tThreshold:  Up Critical Values\n");
					printreading(thres.UpCritical);
				}
				if (thres.UpMajor.ValuesPresent) {
					printf("\t\tThreshold:  Up Major Values\n");
					printreading(thres.UpMajor);
				}
				if (thres.UpMinor.ValuesPresent) {
					printf("\t\tThreshold:  Up Minor Values\n");
					printreading(thres.UpMinor);
				}
				if (thres.PosThdHysteresis.ValuesPresent) {
					printf("\t\tThreshold:  Pos Threshold Hysteresis Values\n");
					printreading(thres.PosThdHysteresis);
				}
				if (thres.NegThdHysteresis.ValuesPresent) {
					printf("\t\tThreshold:  Neg Threshold Hysteresis Values\n");
					printreading(thres.NegThdHysteresis);
				}
			}
		}
		
		if (rdr.RdrType == SAHPI_CTRL_RDR)
		{    
			ctrl_num = rdr.RdrTypeUnion.CtrlRec.Num;
			err = saHpiControlTypeGet(session_id, resource_id, ctrl_num, &ctrl_type);
			if (err != SA_OK) {
				printf("Error=%d reading control type {control, %d}\n", err, ctrl_num);
				continue;
			}
			printf("\tControl num: %i\n\tType: %s\n", ctrl_num, get_control_type(ctrl_type)); 
		
			err = saHpiControlStateGet(session_id, resource_id, ctrl_num, &state);
			if (err != SA_OK) {
				printf("Error=%d reading control state {control, %d}\n", err, ctrl_num);
				continue;
			}
			if (ctrl_type != state.Type) {
				printf("Control Type mismatch between saHpiControlTypeGet=%d and saHpiControlStateGet = %d\n", 
				       ctrl_type, state.Type);
			}

			switch (state.Type) {
				case SAHPI_CTRL_TYPE_DIGITAL:
					printf("\t\tControl Digital State: %s\n", 
					       ctrldigital2str(state.StateUnion.Digital));
					break;
				case SAHPI_CTRL_TYPE_DISCRETE:
					printf("\t\tControl Discrete State: %x\n", state.StateUnion.Discrete);
					break;
				case SAHPI_CTRL_TYPE_ANALOG:
					printf("\t\tControl Analog State: %x\n", state.StateUnion.Analog);
					break;
				case SAHPI_CTRL_TYPE_STREAM:
					printf("\t\tControl Stream Repeat: %d\n", state.StateUnion.Stream.Repeat);
					printf("\t\tControl Stream Data: ");
					display_oembuffer(state.StateUnion.Stream.StreamLength, state.StateUnion.Stream.Stream);
					break;
				case SAHPI_CTRL_TYPE_TEXT:
					printf("\t\tControl Text Line Num: %c\n", state.StateUnion.Text.Line);
					display_textbuffer(state.StateUnion.Text.Text);
					break;
				case SAHPI_CTRL_TYPE_OEM:
					printf("\t\tControl OEM Manufacturer: %d\n", state.StateUnion.Oem.MId);
					printf("\t\tControl OEM Data: ");
					display_oembuffer((SaHpiUint32T)state.StateUnion.Oem.BodyLength, 
						  state.StateUnion.Oem.Body);
					break;
				default:
					printf("\t\tInvalid control type (%d) from saHpiControlStateGet\n", 
					       state.Type);
			}
                }

                if (rdr.RdrType == SAHPI_INVENTORY_RDR)
                {
                        l_eirid = rdr.RdrTypeUnion.InventoryRec.EirId;

                        l_inventdata = (SaHpiInventoryDataT *)g_malloc(l_inventsize);
                        err = saHpiEntityInventoryDataRead(session_id, resource_id,
                                                            l_eirid, l_inventsize,
                                                            l_inventdata, &l_actualsize);

			if (err != SA_OK) {
				printf("Error=%d reading inventory type {EirId, %d}\n", err, l_eirid);
				continue;
			} else if (l_inventdata->Validity ==  SAHPI_INVENT_DATA_VALID) {
                        	printf("\tFound Inventory RDR with EirId: %x\n", l_eirid);
				printf("\tRDR l_inventsize = %d, actualsize = %d\n", l_inventsize, l_actualsize);
				switch (l_inventdata->DataRecords[0]->RecordType)
				{
					case SAHPI_INVENT_RECTYPE_INTERNAL_USE:
						printf( "Internal Use\n");
						break;
					case SAHPI_INVENT_RECTYPE_PRODUCT_INFO:
						printf( "Product Info\n");
						break;
					case SAHPI_INVENT_RECTYPE_CHASSIS_INFO:
						printf( "Chassis Info\n");
						break;
					case SAHPI_INVENT_RECTYPE_BOARD_INFO:
						printf( "Board Info\n");
						break;
					case SAHPI_INVENT_RECTYPE_OEM:
						printf( "OEM Record\n");
						break;
					default:
						printf(" Invalid Invent Rec Type =%x\n",
								l_inventdata->DataRecords[0]->RecordType);
						break;
				} 

			}

                        g_free(l_inventdata);
                }

                printf("\tEntity: \n");
                entitypath2string(&rdr.Entity, tmp_epath, sizeof(tmp_epath));
                printf("\t\t%s\n", tmp_epath);
                printf("\tIdString: ");
                display_textbuffer(rdr.IdString);
                printf("\n"); /* Produce blank line between rdrs. */
        }while(next_rdr != SAHPI_LAST_ENTRY);
}
Esempio n. 21
0
static
void list_inv(SaHpiSessionIdT sessionid, SaHpiResourceIdT res_id)
{
   SaHpiRptEntryT rptentry;
   SaHpiEntryIdT entryid;
   SaHpiEntryIdT nextentryid;
   SaHpiResourceIdT resourceid;
   SaHpiRdrT rdr;
   SaHpiEirIdT eirid;
   SaErrorT rv;
   int prodrecindx = 0;
  	
   rv = SA_OK;

   rv = saHpiRptEntryGetByResourceId(sessionid, res_id, &rptentry);

	if (rv == 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;

		printf("Resource Tag: %s\n", rptentry.ResourceTag.Data);

		while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) {
                        
		  	rv = saHpiRdrGet(sessionid, resourceid, entryid,
					 	&nextentryid, &rdr);

			if (rv == SA_OK) {
			  	if (rdr.RdrType == SAHPI_INVENTORY_RDR) {
				  	unsigned int invsize = 0;

					eirid = rdr.RdrTypeUnion.InventoryRec.EirId;
					rdr.IdString.Data[rdr.IdString.DataLength] = 0;

					actualsize = 0;
					
					rv = saHpiEntityInventoryDataRead(sessionid, resourceid, eirid, 0, NULL, &actualsize);

					invsize = actualsize;

					inv = (SaHpiInventoryDataT *)malloc(invsize);
					memset(inv, 0, invsize);

					rv = saHpiEntityInventoryDataRead(sessionid, resourceid, eirid, invsize, inv, &actualsize);

					if (rv == SA_OK) {
					  	/* Walk thru the list of inventory data */
					  	if (inv->Validity == SAHPI_INVENT_DATA_VALID) {
                                                        for (i = 0; inv->DataRecords[i] != NULL; i++) {
                                                                switch(inv->DataRecords[i]->RecordType) {
                                                                        case SAHPI_INVENT_RECTYPE_INTERNAL_USE:
                                                                                if (debug)
                                                                                        printf("Internal Use\n");
                                                                                break;
                                                                        case SAHPI_INVENT_RECTYPE_PRODUCT_INFO:
                                                                                if (debug)
                                                                                        printf("Product Info\n");
                                                                                prodrecindx = 0;
                                                                                prtprodtinfo();
                                                                                break;
                                                                        case SAHPI_INVENT_RECTYPE_CHASSIS_INFO:
                                                                                if (debug)
                                                                                        printf("Chassis Info\n");
                                                                                prtchassinfo();
                                                                                break; 
                                                                        case SAHPI_INVENT_RECTYPE_BOARD_INFO:
                                                                                if (debug)
                                                                                        printf("Board Info\n");
                                                                                prtboardinfo();
                                                                                break;
                                                                        case SAHPI_INVENT_RECTYPE_OEM:
										if (debug)
                                                                                        printf("OEM Record\n");
                                                                                break;
                                                                        default:
                                                                                printf(" Invalid Invent Rec Type =%x\n",
                                                                                       inv->DataRecords[i]->RecordType);
                                                                                break;
                                                                }
                                                        }
                                                }
					} else {
					  	printf(" InventoryDataRead returns HPI Error: rv=%d\n", rv);
                                        }

                                        free(inv);
                                }
                        }
                        
			entryid = nextentryid;
                }
        }
}
Esempio n. 22
0
static 
SaErrorT list_resources(SaHpiSessionIdT sessionid,SaHpiResourceIdT resourceid)
{
	SaErrorT rv       = SA_OK,
	         rvRdrGet = SA_OK,
 		 rvRptGet = SA_OK; 

	SaHpiRptEntryT rptentry;
	SaHpiEntryIdT rptentryid;
	SaHpiEntryIdT nextrptentryid;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiRdrT rdr;
	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));
		
		rv = list_rpt(&rptentry, resourceid);
						
		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 (f_listall || f_rdr || f_overview)
							list_rdr(sessionid, &rptentry, &rdr, l_resourceid);
					if (f_listall || f_inv)
							list_inv(sessionid, &rptentry, &rdr, l_resourceid); 
					if (f_listall || f_sensor)
							list_sens(sessionid, &rptentry, &rdr, l_resourceid); 
					if (f_listall || f_ctrl)
							list_ctrl(sessionid, &rptentry, &rdr, l_resourceid); 
					if (f_listall || f_wdog)
							list_wdog(sessionid, &rptentry, &rdr, l_resourceid); 
					if (f_listall || f_ann)
							list_ann(sessionid, &rptentry, &rdr, l_resourceid); 
												
				}
				entryid = nextentryid;
			} while ((rvRdrGet == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;
		}
		rptentryid = nextrptentryid;
	} while ((rvRptGet == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY));

	return(rv);
}
Esempio n. 23
0
int main(int argc, char **argv)
{
        char c;
        SaErrorT rv;
        SaHpiVersionT hpiVer;
        SaHpiSessionIdT sessionid;
        SaHpiRptInfoT rptinfo;
        SaHpiRptEntryT rptentry;
        SaHpiEntryIdT rptentryid;
        SaHpiEntryIdT nextrptentryid;
        SaHpiEntryIdT entryid;
        SaHpiEntryIdT nextentryid;
        SaHpiResourceIdT resourceid;
        SaHpiRdrT rdr;
        
        printf("%s: version %s\n",argv[0],progver); 
        
        while ( (c = getopt( argc, argv,"tx?")) != EOF )
                switch(c) {
                case 't': fshowthr = 1; break;
                case 'x': fdebug = 1; break;
                default:
                        printf("Usage %s [-t -x]\n",argv[0]);
                        printf("where -t = show Thresholds also\n");
                        printf("      -x = show eXtra debug messages\n");
                        exit(1);
                }
        rv = saHpiInitialize(&hpiVer);
        if (rv != SA_OK) {
                printf("saHpiInitialize: %s\n",decode_error(rv));
                exit(-1);
        }
        rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL);
        if (rv != SA_OK) {
                if (rv == SA_ERR_HPI_ERROR) 
                        printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv);
                else
                        printf("saHpiSessionOpen: %s\n",decode_error(rv));
                exit(-1);
        }
        
        rv = saHpiResourcesDiscover(sessionid);
        if (fdebug) printf("saHpiResourcesDiscover %s\n",decode_error(rv));
        rv = saHpiRptInfoGet(sessionid,&rptinfo);
        if (fdebug) printf("saHpiRptInfoGet %s\n",decode_error(rv));
        printf("RptInfo: UpdateCount = %d, UpdateTime = %lx\n",
               rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
        
#ifdef BUGGY
        /* ARC: Bug here in OpenHPI requires re-doing discovery (workaround). */
        { 
                int updcnt;
                int i = 0;
                updcnt = rptinfo.UpdateCount;
                while (rptinfo.UpdateCount == updcnt) {
                        rv = saHpiResourcesDiscover(sessionid);
                        if (fdebug) printf("saHpiResourcesDiscover %s\n",decode_error(rv));
                        rv = saHpiRptInfoGet(sessionid,&rptinfo);
                        if (fdebug) printf("saHpiRptInfoGet %s\n",decode_error(rv));
                        printf("RptInfo/%d: UpdateCount = %d, UpdateTime = %lx\n",
                               ++i,rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
                }
        }  /*end openhpi bug workaround*/
#endif
        
        /* walk the RPT list */
        rptentryid = SAHPI_FIRST_ENTRY;
        while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
        {
                rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
                if (fdebug) printf("saHpiRptEntryGet %s\n",decode_error(rv));
                if (rv == SA_OK) {
                        /* walk the RDR list for this RPT entry */
                        entryid = SAHPI_FIRST_ENTRY;
                        resourceid = rptentry.ResourceId;
                        rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; 
                        printf("rptentry[%d] resourceid=%d tag: %s\n",
                               entryid,resourceid, rptentry.ResourceTag.Data);
                        while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
                        {
                                rv = saHpiRdrGet(sessionid,resourceid,
                                                 entryid,&nextentryid, &rdr);
                                if (fdebug) printf("saHpiRdrGet[%d] rv = %d\n",entryid,rv);
                                if (rv == SA_OK) {
                                        char *eol;
                                        rdr.IdString.Data[rdr.IdString.DataLength] = 0;
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR) eol = "    \t";
                                        else eol = "\n";
                                        printf("RDR[%02d]: %s %s %s",rdr.RecordId,
                                               rtypes[rdr.RdrType],rdr.IdString.Data,eol);
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR) {
                                                ShowSensor(sessionid,resourceid,
                                                           &rdr.RdrTypeUnion.SensorRec);
                                        } 
                                        entryid = nextentryid;
                                } else {
                                        rv = SA_OK;
                                        entryid = SAHPI_LAST_ENTRY;
                                }
                        }
                        rptentryid = nextrptentryid;
                }
        }
        
        rv = saHpiSessionClose(sessionid);
        rv = saHpiFinalize();
        
        exit(0);
        return(0);
}
Esempio n. 24
0
/*
 * void populate_saHpiRdrTable(void)
 */
int populate_saHpiRdrTable(SaHpiSessionIdT sessionid, 
			   SaHpiRptEntryT * rpt_entry,
			   oid * resource_oid, 
			   size_t resource_oid_len)
{
	/* 
	 * From   oid * resource_oid, size_t resource_oid_len
	 *       INDEX   { saHpiDomainId, 
	 *		saHpiResourceEntryId,
	 *       	saHpiResourceIsHistorical 
	 *		} 
	 *
	 */

 	SaErrorT 		rv;   

	SaHpiEntryIdT    	rdr_entry_id;
	SaHpiRdrT		rdr_entry;
	oh_big_textbuffer	bigbuf;
		
	oid 			rdr_oid[RDR_INDEX_NR];
	netsnmp_index 		rdr_index;;
	saHpiRdrTable_context	*rdr_context;

	oid column[2];
	int column_len = 2;
	oid full_oid[MAX_OID_LEN];
	size_t full_oid_len;
	oid child_oid[MAX_OID_LEN];
	size_t child_oid_len;
	netsnmp_index resource_index;

	DEBUGMSGTL ((AGENT, "populate_saHpiRdrTable, called\n"));
	
	rdr_entry_id = SAHPI_FIRST_ENTRY;
	do {
		rv =  saHpiRdrGet(sessionid, 
				  rpt_entry->ResourceId, 
				  rdr_entry_id, 
				  &rdr_entry_id, 
				  &rdr_entry);
	
		if (rv != SA_OK) {
			DEBUGMSGTL ((AGENT, "saHpiRdrGet Failed: rv = %d\n",rv));
			rv =  AGENT_ERR_INTERNAL_ERROR;
			break;
		}

		/* From MIB table index 
		 * INDEX { 
		 *	saHpiDomainId, 
		 *	saHpiResourceId, 
		 *      saHpiResourceIsHistorical,
		 *	saHpiRdrEntryId
		 * }
		 */
		rdr_index.len = RDR_INDEX_NR;
		rdr_oid[0] = resource_oid[0];
		rdr_oid[1] = rpt_entry->ResourceId;
		rdr_oid[2] = MIB_FALSE;
		rdr_oid[3] = rdr_entry.RecordId;
		rdr_index.oids = (oid *) &rdr_oid;
		
		/* See if it exists. */
		rdr_context = NULL;
		rdr_context = CONTAINER_FIND(cb.container, &rdr_index);
			
		if (!rdr_context) { 
			// New entry. Add it
			rdr_context = 
				saHpiRdrTable_create_row(&rdr_index);
		}
		if (!rdr_context) {
			snmp_log (LOG_ERR, "Not enough memory for a Rdr row!");
			rv = AGENT_ERR_INTERNAL_ERROR;
			break;
		} 

		/*
		 * Build the full oid for THIS rdr, then pass it to
		 * the appropriate populate() for its RowPointer. Then accept 
		 * its full oidto use in this rdr's RowPointer.
		 */
		column[0] = 1;
		column[1] = COLUMN_SAHPIRDRENTRYID;
		memset(full_oid, 0, sizeof(full_oid_len));
		build_full_oid (saHpiRdrTable_oid, saHpiRdrTable_oid_len,
				column, column_len,
				&rdr_index,
				full_oid, MAX_OID_LEN, &full_oid_len);
		/*
		 * make sure we don't pickup previous rdr type's oid  
		 * this shall be the oid of the corresponding rdr type's 
		 * table
		 */
		memset(&child_oid, 0, sizeof(child_oid));
		child_oid_len = 0;

		/*
		 * call the _populate() fpr the corresponding 'type'
		 * specific table.
		 */
		switch (rdr_entry.RdrType) {
		case SAHPI_NO_RECORD:
			DEBUGMSGTL((AGENT, "SAHPI_NO_RECORD: ERROR STATE\n"));
			break;

		case SAHPI_CTRL_RDR:
			DEBUGMSGTL ((AGENT,
				     "SAHPI_CTRL_RDR; RPT: %d, RDR: %d, CtrlRec.Num: %d\n",
				      rpt_entry->ResourceId,
				      rdr_entry.RecordId,
				      rdr_entry.RdrTypeUnion.CtrlRec.Num));
			switch (rdr_entry.RdrTypeUnion.CtrlRec.Type) {
			case SAHPI_CTRL_TYPE_DIGITAL:
				rv = populate_ctrl_digital(sessionid,
							   &rdr_entry,
							   rpt_entry,
							   full_oid, full_oid_len,
							   child_oid, &child_oid_len);
				DEBUGMSGTL((AGENT,
					    "populate_ctrl_digital rv: %s\n",
					    oh_lookup_error(rv)));
 				break;
			case SAHPI_CTRL_TYPE_DISCRETE:
				rv = populate_ctrl_discrete(sessionid,
							    &rdr_entry,
							    rpt_entry,
							    full_oid, full_oid_len,
							    child_oid, &child_oid_len);
				DEBUGMSGTL((AGENT,
					    "populate_ctrl_discrete rv: %s\n",
					    oh_lookup_error(rv)));            
				break;
			case SAHPI_CTRL_TYPE_ANALOG:
				rv = populate_ctrl_analog(sessionid,
							  &rdr_entry,
							  rpt_entry,
							  full_oid, full_oid_len,
							  child_oid, &child_oid_len);
				DEBUGMSGTL((AGENT,
					    "populate_ctrl_analog rv: %s\n",
					    oh_lookup_error(rv))); 
				break;
			case SAHPI_CTRL_TYPE_STREAM:
				rv = populate_ctrl_stream(sessionid,
							  &rdr_entry,
							  rpt_entry,
							  full_oid, full_oid_len,
							  child_oid, &child_oid_len);
				DEBUGMSGTL((AGENT,
					    "populate_ctrl_stream rv: %s\n",
					    oh_lookup_error(rv))); 
				break;
			case SAHPI_CTRL_TYPE_TEXT:
				rv = populate_ctrl_text(sessionid,
							&rdr_entry,
							rpt_entry,
							full_oid, full_oid_len,
							child_oid, &child_oid_len);
				DEBUGMSGTL((AGENT,
					    "populate_ctrl_text rv: %s\n",
					    oh_lookup_error(rv))); 
				break;
			case SAHPI_CTRL_TYPE_OEM:
				rv = populate_ctrl_oem(sessionid,
						       &rdr_entry,
						       rpt_entry,
						       full_oid, full_oid_len,
						       child_oid, &child_oid_len);
				DEBUGMSGTL((AGENT,
					    "populate_ctrl_oem rv: %s\n",
					    oh_lookup_error(rv)));
				break;
			default:
				DEBUGMSGTL ((AGENT, 
		                "SAHPI_CTRL_RDR UNKNOWN TYPE: Not implemented\n"));
				break;
			}
			break;

		case SAHPI_SENSOR_RDR:
			DEBUGMSGTL ((AGENT,
				     "SAHPI_CTRL_RDR; RPT: %d, RDR: %d, CtrlRec.Num: %d\n",
				      rpt_entry->ResourceId,
				      rdr_entry.RecordId,
				      rdr_entry.RdrTypeUnion.CtrlRec.Num));

			/* saHpiSensorTable */
			rv = populate_sensor (sessionid,
					      &rdr_entry,
					      rpt_entry,
					      full_oid, full_oid_len,
					      child_oid, &child_oid_len);
			DEBUGMSGTL((AGENT, 
		        "Called populate_sensor(); rc: %d\n",rv));

			/* saHpiCurrentSensorStateTable */
			rv = populate_current_sensor_state (sessionid,
							    &rdr_entry,
							    rpt_entry,
							    full_oid, full_oid_len);
			DEBUGMSGTL((AGENT, 
		       "Called populate_current_sensor_state(); rc: %d\n", rv));

			break;

		case SAHPI_INVENTORY_RDR:
			DEBUGMSGTL ((AGENT,
				      "Calling populate_inventory; RPT: %d, RDR: %d, InventoryRec.IdrId: %d\n",
				      rpt_entry->ResourceId,
				      rdr_entry.RecordId,
				      rdr_entry.RdrTypeUnion.InventoryRec.IdrId));
			rv = populate_inventory (sessionid,
                                                 &rdr_entry,
                                                 rpt_entry,
                                                 full_oid, full_oid_len,
                                                 child_oid, &child_oid_len);
			DEBUGMSGTL ((AGENT,
				     "Called populate_inventory(); rc: %d\n",
				     rv));
			break;

		case SAHPI_WATCHDOG_RDR:
			DEBUGMSGTL ((AGENT,
				      "Calling populate_watchdog; RPT: %d, RDR: %d, CtrlRec.Num: %d\n",
				      rpt_entry->ResourceId,
				      rdr_entry.RecordId,
				      rdr_entry.RdrTypeUnion.WatchdogRec.WatchdogNum));
			rv = populate_watchdog (sessionid,
					        &rdr_entry,
					        rpt_entry,
					        full_oid, full_oid_len,
					        child_oid, &child_oid_len);
			DEBUGMSGTL ((AGENT,
				     "Called populate_watchdog(); rc: %d\n",
				     rv));
			break;

		case SAHPI_ANNUNCIATOR_RDR:
			DEBUGMSGTL ((AGENT,
				      "SAHPI_ANNUNCIATOR_RDR; RPT: %d, RDR: %d, CtrlRec.Num: %d\n",
				      rpt_entry->ResourceId,
				      rdr_entry.RecordId,
				      rdr_entry.RdrTypeUnion.AnnunciatorRec.AnnunciatorNum));
			rv = populate_annunciator (sessionid,
                                                   &rdr_entry,
                                                   rpt_entry,
                                                   full_oid, full_oid_len,
                                                   child_oid, &child_oid_len);
			DEBUGMSGTL ((AGENT,
				     "Called populate_annunciator(); rc: %d\n",
				     rv));

			break;

		default:
			DEBUGMSGTL((AGENT, "RdrType,default: Not Implemented\n"));
			break;
		}


		/** COUNTER = ASN_COUNTER */
		rdr_context->saHpiRdrEntryId = rdr_entry.RecordId;
	
		/** COUNTER = ASN_COUNTER */
                rdr_context->saHpiRdrNextEntryId = rdr_entry_id;
	
		/** INTEGER = ASN_INTEGER */
		rdr_context->saHpiRdrType = rdr_entry.RdrType + 1;
	
		/** SaHpiEntityPath = ASN_OCTET_STR */
		/** SaHpiEntityPath = ASN_OCTET_STR */
		memset(rdr_context->saHpiRdrEntityPath,
		       0, sizeof(oh_big_textbuffer));
		
		memset(&bigbuf, 0, sizeof(oh_big_textbuffer));        
		
		rv = oh_decode_entitypath(&rdr_entry.Entity, &bigbuf);
		
		if (rv != SA_OK) {
			DEBUGMSGTL ((AGENT, 
			"ERROR: RDR, oh_decode_entitypath() rv = %d\n",rv));
			rv =  AGENT_ERR_INTERNAL_ERROR;
			saHpiRdrTable_delete_row(rdr_context);
			break;
		}       
			 
		memcpy(rdr_context->saHpiRdrEntityPath,
		       bigbuf.Data, bigbuf.DataLength );
		
		
		if ((bigbuf.Data[bigbuf.DataLength - 1] == 0x00) && 
			(bigbuf.DataType == SAHPI_TL_TYPE_TEXT))         		
			rdr_context->saHpiRdrEntityPath_len = 
				bigbuf.DataLength - 1;
		else
			rdr_context->saHpiRdrEntityPath_len = 
				bigbuf.DataLength;
	
		/** TruthValue = ASN_INTEGER */
		rdr_context->saHpiRdrIsFru = 
			(rdr_entry.IsFru == SAHPI_TRUE) ? MIB_TRUE : MIB_FALSE;
	
		/** RowPointer = ASN_OBJECT_ID */ 
		memset(rdr_context->saHpiRdrRowPointer, 
		       0, sizeof(rdr_context->saHpiRdrRowPointer));

		rdr_context->saHpiRdrRowPointer_len = 
			child_oid_len * sizeof(oid);

		memcpy(rdr_context->saHpiRdrRowPointer, 
		       child_oid, 
		       rdr_context->saHpiRdrRowPointer_len);

	
		/** RowPointer = ASN_OBJECT_ID */
		column[0] = 1;
		column[1] = COLUMN_SAHPIRESOURCEID;
		resource_index.len = resource_oid_len;
		resource_index.oids = resource_oid;
		memset(full_oid, 0, sizeof(full_oid_len));

		build_full_oid (saHpiResourceTable_oid, saHpiResourceTable_oid_len,
				column, column_len,
				&resource_index,
				full_oid, MAX_OID_LEN, &full_oid_len);

		rdr_context->saHpiRdrRPT_len = full_oid_len * sizeof (oid);
		memcpy (rdr_context->saHpiRdrRPT, 
			full_oid, 
			rdr_context->saHpiRdrRPT_len);

		/** SaHpiTextType = ASN_INTEGER */
		rdr_context->saHpiRdrTextType = 
			rdr_entry.IdString.DataType + 1;
	
		/** SaHpiTextLanguage = ASN_INTEGER */
		rdr_context->saHpiRdrTextLanguage = 
			rdr_entry.IdString.Language + 1;
	
		/** OCTETSTR = ASN_OCTET_STR */
		memset(rdr_context->saHpiRdrIdString, 
		       0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
		memcpy(rdr_context->saHpiRdrIdString, 
		       rdr_entry.IdString.Data, 
		       rdr_entry.IdString.DataLength);        		
        		
		if ((rdr_entry.IdString.Data[rdr_entry.IdString.DataLength - 1] == 0x00) 
			&& (rdr_entry.IdString.DataType == SAHPI_TL_TYPE_TEXT))         		
			rdr_context->saHpiRdrIdString_len = 
				rdr_entry.IdString.DataLength - 1;
		else
			rdr_context->saHpiRdrIdString_len = 
				rdr_entry.IdString.DataLength;  

		CONTAINER_INSERT (cb.container, rdr_context);
	
	} while (rdr_entry_id !=  SAHPI_LAST_ENTRY );
	
	rdr_entry_count = CONTAINER_SIZE (cb.container);
	
	DEBUGMSGTL ((AGENT, "resource_entry_count = %d\n", rdr_entry_count));
		
	return rv;

}
Esempio n. 25
0
int main(int argc, char **argv) 
{

	/* ************************
	 * Local variables
	 * ***********************/	 
	int testfail = 0;
	SaErrorT          err;
	SaErrorT expected_err;
	SaHpiRptEntryT rptentry;
	SaHpiRdrT      rdr;		
	SaHpiResourceIdT  id;
        SaHpiSessionIdT sessionid;
	SaHpiEntryIdT entryid;
	SaHpiEntryIdT nextentryid;
	SaHpiBoolT foundSensor;			
	SaHpiSensorNumT sid = 0;
	SaHpiBoolT enable = SAHPI_FALSE;

	/* *************************************	 	 
	 * Find a resource with Sensor type rdr
	 * ************************************* */		
	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_SENSOR,SAHPI_FIRST_ENTRY, &rptentry, SAHPI_TRUE);
	if (err != SA_OK) {
		printf("Error! Can not find resources for test environment\n");
		printf("      File=%s, Line=%d\n", __FILE__, __LINE__);
		err = tcleanup(&sessionid);
		return SA_OK;
	}

	id = rptentry.ResourceId;
	/************************** 
	 * Test: find a sensor with desired property
	 **************************/
	entryid = SAHPI_FIRST_ENTRY;
	foundSensor = SAHPI_FALSE;			
	do {
		err = saHpiRdrGet(sessionid,id,entryid,&nextentryid, &rdr);
		if (err == SA_OK)
		{
			if ((rdr.RdrType == SAHPI_SENSOR_RDR) &&
				(rdr.RdrTypeUnion.SensorRec.DataFormat.IsSupported == SAHPI_FALSE))
			{
				foundSensor = SAHPI_TRUE;
				break;
														
			}
			entryid = nextentryid;
		}
	} while ((err == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ;

	if (!foundSensor) {
		dbg("Did not find desired resource for test\n");
		return(SA_OK);
	} else {
		sid = rdr.RdrTypeUnion.SensorRec.Num; 
	}	

	/************************** 
	 * Test: enable event for nonsupported capability
	 **************************/
	expected_err = SA_ERR_HPI_READ_ONLY;                   
	err = saHpiSensorEventEnableSet(sessionid, id, sid, enable);
	checkstatus(err, expected_err, testfail);

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

}
Esempio n. 26
0
void
cHpiResourceRoot::discoverResources()
{
  SaErrorT err = saHpiResourcesDiscover( theApp->m_session_id );

  if ( err != SA_OK )
     {
       theApp->LogError( "saHpiResourcesDiscover: ", err );
       return;
     }

  unmark();

  SaHpiEntryIdT next = SAHPI_FIRST_ENTRY;

  do
     {
       SaHpiEntryIdT current = next;
       SaHpiRptEntryT entry;

       err = saHpiRptEntryGet( theApp->m_session_id, current, &next, &entry );

       if ( err != SA_OK )
          {
            if ( current != SAHPI_FIRST_ENTRY )
               {
                 theApp->LogError( "saHpiRptEntryGet: ", err );
                 return;
               }

            theApp->Log( "Empty RPT !\n" );

            break;
          }

       // create entity path
       cHpiItem *parent = createEntityPath( entry.ResourceEntity );

       SaHpiEntityT *e = &entry.ResourceEntity.Entry[0];

       QString name = QString( "%1 %2" )
         .arg( hpiEntityType2String( e->EntityType ) )
         .arg( e->EntityInstance );

       // create rpt entry
       cHpiItem *item = parent->findChild( name );

       if ( !item )
            item = new cHpiResourceRptItem( parent, name, *e, entry );

       item->mark();

       parent = item;

       // create rdr
       if ( entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR )
          {
            SaHpiEntryIdT next_rdr = SAHPI_FIRST_ENTRY;

            while ( next_rdr != SAHPI_LAST_ENTRY )
               {
                 SaHpiEntryIdT current_rdr = next_rdr;
                 SaHpiRdrT rdr;

                 err = saHpiRdrGet( theApp->m_session_id, 
                                    entry.ResourceId,
                                    current_rdr,
                                    &next_rdr, &rdr );

                 if ( err != SA_OK )
                    {
                      if ( current_rdr == SAHPI_FIRST_ENTRY )
                           theApp->Log( "empty RDR table !\n" );
                      else
                           theApp->LogError( "saHpiRdrGet: ", err );

                      break;
                    }

                 parent = createEntityPath( rdr.Entity, 0 );

		 char str[257];
		 memcpy( str, rdr.IdString.Data, 256 );
		 str[rdr.IdString.DataLength] = 0;

                 name = QString( "%1 %2" )
                   .arg( str )
                   .arg( rdr.RecordId );

                 item = parent->findChild( name );

                 if ( !item )
                    {
                      if ( rdr.RdrType == SAHPI_INVENTORY_RDR )
                         {
                           cHpiResourceRdrInventory *inv = new cHpiResourceRdrInventory( parent, name, rdr );
                           item = inv;

                           SaHpiInventoryDataT *d = (SaHpiInventoryDataT *)inv->m_inventory;

                           err = saHpiEntityInventoryDataRead( theApp->m_session_id, entry.ResourceId,
                                                               rdr.RdrTypeUnion.InventoryRec.EirId,
                                                               dMaxInventorySize, d,
                                                               &inv->m_size );

                           if ( err )
                                theApp->LogError( "saHpiEntityInventoryDataRead: ", err );
                           else if ( d->Validity != SAHPI_INVENT_DATA_VALID )
                                theApp->Log( "saHpiEntityInventoryDataRead: data not valid" );
                           else
                              {
                                for( int i = 0; d->DataRecords[i]; i++ )
                                   {
                                     SaHpiInventDataRecordT *r = d->DataRecords[i];
				     cHpiItem *iv = 0;

                                     switch( r->RecordType )
                                        {
                                          case SAHPI_INVENT_RECTYPE_INTERNAL_USE:
                                               iv = new cHpiResourceInventoryInternalUse( item, "InternalUse", &r->RecordData.InternalUse );
                                               break;

                                          case SAHPI_INVENT_RECTYPE_CHASSIS_INFO:
                                               iv = new cHpiResourceInventoryChassis( item, "Chassis", &r->RecordData.ChassisInfo );
                                               break;

                                          case SAHPI_INVENT_RECTYPE_BOARD_INFO:
                                               iv = new cHpiResourceInventoryBoard( item, "Board", &r->RecordData.BoardInfo );
                                               break;

                                          case SAHPI_INVENT_RECTYPE_PRODUCT_INFO:
                                               iv = new cHpiResourceInventoryProduct( item, "Product", &r->RecordData.ProductInfo );
                                               break;

                                          case SAHPI_INVENT_RECTYPE_OEM:
                                               iv = new cHpiResourceInventoryOem( item, "Oem", &r->RecordData.OemData );
                                               break;
                                        }

				     iv->mark();
                                   }
                              }
                         }
                      else
                           item = new cHpiResourceRdr( parent, name, rdr );
                    }
		 else
		      item->markDown();

                 item->mark();
               }
          }
     }
  while( next != SAHPI_LAST_ENTRY );

  deleteUnmark();
}
Esempio n. 27
0
int
main(int argc, char **argv)
{
  int c;
  SaHpiVersionT hpiVer;
  SaHpiSessionIdT sessionid;
  SaHpiRptInfoT rptinfo;
  SaHpiRptEntryT rptentry;
  SaHpiEntryIdT rptentryid;
  SaHpiEntryIdT nextrptentryid;
  SaHpiEntryIdT entryid;
  SaHpiEntryIdT nextentryid;
  SaHpiResourceIdT resourceid;
  SaHpiRdrT rdr;

  printf("%s  ver %s\n", progname,progver);
  sensor_name = (char *)strdup(s_name);
  while ( (c = getopt( argc, argv,"ms:xz?")) != EOF )
  switch(c)
  {
    case 'z': fxdebug = 1; /* fall thru to include next setting */
    case 'x': fdebug = 1; break;
	      /*
    case 'l': slist = 1; break;
	      */
    case 'm': 
	      sensor_name = (char *)strdup(sm_name);
	      break;
    case 's':
	  fsensor = 1;
          if (optarg) {
	    sensor_name = (char *)strdup(optarg);
	  }
          break;
    default:
          printf("Usage: %s [-xm] [-s sensor_descriptor]\n", progname);
          printf("   -s  Sensor descriptor\n");
          printf("   -m  use Mullins sensor descriptor\n");
	  /*
          printf("   -l  Display entire sensor list\n");
	  */
          printf("   -x  Display debug messages\n");
          printf("   -z  Display extra debug messages\n");
          exit(1);
  }

  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 = %d, 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)
    {
      /* 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_SENSOR_RDR)
	  { 
	    /*type 2 includes sensor and control records*/
	    rdr.IdString.Data[rdr.IdString.DataLength] = 0;
	    if (strncmp(rdr.IdString.Data, sensor_name,
		rdr.IdString.DataLength) == 0)
	    {
	      printf( "%02d %s\t", rdr.RecordId, rdr.IdString.Data);
	      DoEvent( sessionid, resourceid, &rdr.RdrTypeUnion.SensorRec);
	      if (rv != SA_OK)
	        printf( "Returned Error from DoEvent: rv=%d\n", rv);
	    }
	  } 
	  if (rv != SA_OK)
	      printf( "Returned HPI Error: rv=%d\n", rv);
	  entryid = nextentryid;
        }
      }
      rptentryid = nextrptentryid;
    }
  }
  rv = saHpiSessionClose(sessionid);
  rv = saHpiFinalize();
  exit(0);
}
Esempio n. 28
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. 29
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. 30
0
int
main(int argc, char **argv)
{
        SaHpiVersionT    hpiVer;
        SaHpiSessionIdT  sessionid;
        SaHpiRptInfoT    rptinfo;
        SaHpiRptEntryT   rptentry;
        SaHpiEntryIdT    rptentryid;
        SaHpiEntryIdT    nextrptentryid;
        SaHpiEntryIdT    entryid;
        SaHpiEntryIdT    nextentryid;
        SaHpiResourceIdT resourceid;
        SaHpiRdrT        rdr;
        SaErrorT         rv;


        pname = argv[0];

        if (argc < 2) {
                usage();
                exit(-1);
        }

        sensor_name = argv[1];
        have_minor = 0;
        have_major = 0;

        if (argc >= 3) {
                have_minor = 1;
                minor_value = atof(argv[2]);
        }

        if (argc >=4) {
                have_major = 1;
                major_value = atof(argv[3]);
        }

        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);

        rv = saHpiRptInfoGet(sessionid,&rptinfo);

        rptentryid = SAHPI_FIRST_ENTRY;
        while (rptentryid != SAHPI_LAST_ENTRY) {
                rv = saHpiRptEntryGet(sessionid,rptentryid,
                                      &nextrptentryid,&rptentry);
                if (rv != SA_OK) {
                        printf("saHpiRptEntryGet(%s)Error: %d\n",
                               gettext(&rptentry.ResourceTag), rv);
                        break;
                }

                resourceid = rptentry.ResourceId;
                printf("Resource Id:%d Tag: %s\n", resourceid,
                        gettext(&rptentry.ResourceTag));

                entryid = SAHPI_FIRST_ENTRY;
                while (entryid != SAHPI_LAST_ENTRY) {
                        rv = saHpiRdrGet(sessionid, resourceid, entryid,
                                        &nextentryid, &rdr);
               	        if (rv != SA_OK) {
                            printf( "saHpiRdrGet(%s) Error: %d\n",
                                    gettext(&rptentry.ResourceTag), rv);
                            break;
                        }
                        dordr(sessionid, resourceid, &rdr);
	                entryid = nextentryid;
                }

                rptentryid = nextrptentryid;
         }
         rv = saHpiSessionClose(sessionid);
         rv = saHpiFinalize();
         exit(0);
}