SaErrorT ohoi_set_control_state(void *hnd, SaHpiResourceIdT id, SaHpiCtrlNumT num, SaHpiCtrlModeT mode, SaHpiCtrlStateT *state) { struct oh_handler_state *handler = (struct oh_handler_state *)hnd; struct ohoi_control_info *ctrl_info; SaErrorT rv; SaHpiRdrT *rdr; rdr = oh_get_rdr_by_type(handler->rptcache, id, SAHPI_CTRL_RDR, num); if (!rdr) return SA_ERR_HPI_INVALID_RESOURCE; rv = ohoi_get_rdr_data(hnd, id, SAHPI_CTRL_RDR, num, (void *)&ctrl_info); if (rv != SA_OK) return rv; if (rdr->RdrTypeUnion.CtrlRec.DefaultMode.ReadOnly && rdr->RdrTypeUnion.CtrlRec.DefaultMode.Mode != mode) { dbg("Attempt to change mode of RO sensor mode"); return SA_ERR_HPI_READ_ONLY; } if (ctrl_info->ohoii.set_control_state == NULL) { return SA_ERR_HPI_UNSUPPORTED_API; } rv = ctrl_info->ohoii.set_control_state(handler, ctrl_info, rdr, mode, state); return rv; }
SaErrorT snmp_rsa_get_sensor_event_enables(void *hnd, SaHpiResourceIdT id, SaHpiSensorNumT num, SaHpiSensorEvtEnablesT *enables) { SaHpiSensorEvtEnablesT working; SaHpiRdrT *rdr = oh_get_rdr_by_type(((struct oh_handler_state *)hnd)->rptcache, id, SAHPI_SENSOR_RDR, num); if (rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } gpointer rsa_data = oh_get_rdr_data( ((struct oh_handler_state *)hnd)->rptcache, id, rdr->RecordId); if (rsa_data == NULL) { dbg("Sensor Data Pointer is NULL; RID=%x; SID=%d", id, num); return -1; } if (rdr->RdrTypeUnion.SensorRec.Ignore == SAHPI_TRUE) { return SA_ERR_HPI_INVALID_CMD; } if (rdr->RdrTypeUnion.SensorRec.EventCtrl == SAHPI_SEC_NO_EVENTS) { return SA_ERR_HPI_INVALID_CMD; } working = ((struct RSA_SensorInfo *)rsa_data)->sensor_evt_enablement; memcpy(enables, &working, sizeof(SaHpiSensorEvtEnablesT)); return SA_OK; }
SaErrorT sim_reset_watchdog(void *hnd, SaHpiResourceIdT rid, SaHpiWatchdogNumT num) { SaHpiRdrT *rdr; if (!hnd) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *state = (struct oh_handler_state *)hnd; /* Check if resource exists and has managed hotswap capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return SA_ERR_HPI_INVALID_RESOURCE; } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG)) { return SA_ERR_HPI_CAPABILITY; } rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_WATCHDOG_RDR, num); if (rdr == NULL) return SA_ERR_HPI_NOT_PRESENT; // since no timer is actually running we can just do nothing here return SA_OK; }
/** * main: Starts with an RPTable of 10 resources, adds 1 rdr * to first resource. Fetches rdr by its type and num and compares * with original. A failed comparison means the test failed, * otherwise the test passed. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); SaHpiEntryIdT record_id; SaHpiRdrT *tmprdr = NULL; guint i = 0; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, sensors, NULL,0)) return 1; record_id = get_rdr_uid(sensors[0].RdrType, sensors[0].RdrTypeUnion.SensorRec.Num); sensors[0].RecordId = record_id; tmprdr = oh_get_rdr_by_type(rptable, SAHPI_FIRST_ENTRY, sensors[0].RdrType, sensors[0].RdrTypeUnion.SensorRec.Num); if (!tmprdr || memcmp(sensors, tmprdr, sizeof(SaHpiRdrT))) return 1; return 0; }
static cIpmiFru * VerifyFruAndEnter( void *hnd, SaHpiResourceIdT rid, SaHpiEirIdT num, cIpmi *&ipmi ) { ipmi = VerifyIpmi( hnd ); if ( !ipmi ) { assert( 0 ); return 0; } ipmi->IfEnter(); SaHpiRdrT *rdr = oh_get_rdr_by_type( ipmi->GetHandler()->rptcache, rid, SAHPI_INVENTORY_RDR, num ); if ( !rdr ) { ipmi->IfLeave(); return 0; } cIpmiFru *fru = (cIpmiFru *)oh_get_rdr_data( ipmi->GetHandler()->rptcache, rid, rdr->RecordId ); assert( fru ); if ( !ipmi->VerifyFru( fru ) ) { ipmi->IfLeave(); return 0; } return fru; }
/** * snmp_bc_get_sensor_event_enable: * @hnd: Handler data pointer. * @rid: Resource ID. * @sid: Sensor ID. * @enable: Location to store sensor event enablement boolean. * * Retrieves a sensor's boolean event enablement status. * * Return values: * SA_OK - normal case. * SA_ERR_HPI_CAPABILITY - if resource doesn't have SAHPI_CAPABILITY_SENSOR. * SA_ERR_HPI_NOT_PRESENT - if sensor doesn't exist. **/ SaErrorT snmp_bc_get_sensor_event_enable(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, SaHpiBoolT *enable) { SaHpiRdrT *rdr; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct SensorInfo *sinfo; if (!enable) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exists and return enablement status */ rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("Cannot retrieve sensor data."); return(SA_ERR_HPI_INTERNAL_ERROR); } *enable = sinfo->events_enabled; return(SA_OK); }
static cIpmiSensor * VerifySensorAndEnter( void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT num, cIpmi *&ipmi ) { ipmi = VerifyIpmi( hnd ); if ( !ipmi ) { assert( 0 ); return 0; } ipmi->IfEnter(); SaHpiRdrT *rdr = oh_get_rdr_by_type( ipmi->GetHandler()->rptcache, rid, SAHPI_SENSOR_RDR, num ); if ( !rdr ) { ipmi->IfLeave(); return 0; } cIpmiSensor *sensor = (cIpmiSensor *)oh_get_rdr_data( ipmi->GetHandler()->rptcache, rid, rdr->RecordId ); assert( sensor ); if ( !ipmi->VerifySensor( sensor ) ) { ipmi->IfLeave(); return 0; } return sensor; }
SaErrorT ohoi_get_control_state(void *hnd, SaHpiResourceIdT id, SaHpiCtrlNumT num, SaHpiCtrlModeT *mode, SaHpiCtrlStateT *state) { struct oh_handler_state *handler = (struct oh_handler_state *)hnd; struct ohoi_handler *ipmi_handler = (struct ohoi_handler *)handler->data; struct ohoi_control_info info; SaErrorT rv; ipmi_control_id_t *ctrl; SaHpiRdrT * rdr; SaHpiUint8T val, mask, idx, i; SaHpiCtrlStateT localstate; SaHpiCtrlModeT localmode; rdr = oh_get_rdr_by_type(handler->rptcache, id, SAHPI_CTRL_RDR, num); if (!rdr) return SA_ERR_HPI_INVALID_RESOURCE; rv = ohoi_get_rdr_data(hnd, id, SAHPI_CTRL_RDR, num, (void *)&ctrl); if (rv!=SA_OK) return rv; if (state == NULL) { state = &localstate; } if (mode == NULL) { mode = &localmode; } memset(state, 0, sizeof(*state)); memset(mode, 0, sizeof(*mode)); info.done = 0; info.state = state; info.state->Type = SAHPI_CTRL_TYPE_OEM; rv = ipmi_control_pointer_cb(*ctrl, _get_control_state, &info); if (rv) { dbg("Unable to retrieve control state"); return SA_ERR_HPI_ERROR; } rv = ohoi_loop(&info.done, ipmi_handler); val = info.state->StateUnion.Oem.Body[0]; if ((rdr->RdrTypeUnion.CtrlRec.Type == SAHPI_CTRL_TYPE_DIGITAL) && (rdr->RdrTypeUnion.CtrlRec.OutputType == SAHPI_CTRL_LED) && (rdr->RdrTypeUnion.CtrlRec.Oem >= OEM_ALARM_BASE)) { oem_alarm_state = val; /* This is a front panel alarm LED. */ state->Type = SAHPI_CTRL_TYPE_DIGITAL; mask = 0x01; idx = rdr->RdrTypeUnion.CtrlRec.Oem - OEM_ALARM_BASE; /* bits 0 - 3 = Pwr, Crit, Maj, Min */ for (i = 0; i < idx; i++) mask = mask << 1; if ((val & mask) == 0) state->StateUnion.Digital = SAHPI_CTRL_STATE_ON; else state->StateUnion.Digital = SAHPI_CTRL_STATE_OFF; } return(rv); }
SaErrorT sim_add_idr_area(void *hnd, SaHpiResourceIdT rid, SaHpiIdrIdT IdrId, SaHpiIdrAreaTypeT AreaType, SaHpiEntryIdT *AreaId) { struct sim_inventory_info *info; if (!hnd || !AreaId) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *state = (struct oh_handler_state *)hnd; /* Check if resource exists and has inventory capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return SA_ERR_HPI_INVALID_RESOURCE; } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA)) { return SA_ERR_HPI_CAPABILITY; } /* Find inventory and its data - see if it accessable */ SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_INVENTORY_RDR, IdrId); if (rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } info = (struct sim_inventory_info *)oh_get_rdr_data(state->rptcache, rid, rdr->RecordId); if (info == NULL) { dbg("No inventory data. IdrId=%s", rdr->IdString.Data); return SA_ERR_HPI_NOT_PRESENT; } /* check to see if space is available for the new area */ if (info->idrinfo.NumAreas == SIM_INVENTORY_AREAS) { return SA_ERR_HPI_OUT_OF_SPACE; } else if (info->idrinfo.ReadOnly) { return SA_ERR_HPI_READ_ONLY; } /* add the area */ info->area[info->idrinfo.NumAreas].idrareahead.AreaId = info->nextareaid; info->area[info->idrinfo.NumAreas].idrareahead.Type = AreaType; info->area[info->idrinfo.NumAreas].idrareahead.ReadOnly = SAHPI_FALSE; info->area[info->idrinfo.NumAreas].idrareahead.NumFields = 0; /* increment our counters and set return info */ info->idrinfo.NumAreas++; *AreaId = info->nextareaid; info->nextareaid++; return SA_OK; }
SaErrorT ohoi_set_control_state(void *hnd, SaHpiResourceIdT id, SaHpiCtrlNumT num, SaHpiCtrlModeT mode, SaHpiCtrlStateT *state) { struct oh_handler_state *handler = (struct oh_handler_state *)hnd; struct ohoi_handler *ipmi_handler = (struct ohoi_handler *)handler->data; struct ohoi_control_info info; SaErrorT rv; ipmi_control_id_t *ctrl; SaHpiRdrT * rdr; SaHpiUint8T val, mask, idx, i; rdr = oh_get_rdr_by_type(handler->rptcache, id, SAHPI_CTRL_RDR, num); if (!rdr) return SA_ERR_HPI_INVALID_RESOURCE; rv = ohoi_get_rdr_data(hnd, id, SAHPI_CTRL_RDR, num, (void *)&ctrl); if (rv!=SA_OK) return rv; if ((rdr->RdrTypeUnion.CtrlRec.Type == SAHPI_CTRL_TYPE_DIGITAL) && (rdr->RdrTypeUnion.CtrlRec.OutputType == SAHPI_CTRL_LED) && (rdr->RdrTypeUnion.CtrlRec.Oem >= OEM_ALARM_BASE)) { /* This is a front panel alarm LED. */ val = oem_alarm_state; val |= 0xf0; /* h.o. nibble always write 1 */ mask = 0x01; idx = rdr->RdrTypeUnion.CtrlRec.Oem - OEM_ALARM_BASE; /* bits 0 - 3 = Pwr, Crit, Maj, Min */ for (i = 0; i < idx; i++) mask = mask << 1; if (state->StateUnion.Digital == SAHPI_CTRL_STATE_ON) val &= (0xff - mask); /*turn it on */ else /* turn it off */ val |= mask; state->Type = SAHPI_CTRL_TYPE_OEM; state->StateUnion.Oem.BodyLength = 1; state->StateUnion.Oem.Body[0] = val; } info.done = 0; info.state = state; if (info.state->Type != SAHPI_CTRL_TYPE_OEM) { dbg("IPMI only support OEM control"); return SA_ERR_HPI_INVALID_CMD; } rv = ipmi_control_pointer_cb(*ctrl, _set_control_state, &info); if (rv) { dbg("Unable to retrieve control state"); return SA_ERR_HPI_ERROR; } ohoi_loop(&info.done, ipmi_handler); return SA_OK; }
SaErrorT snmp_bc_get_sensor_oid_reading(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const char *raw_oid, SaHpiSensorReadingT *reading) { SaHpiSensorReadingT working; struct SensorInfo *sinfo; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; struct snmp_value get_value; SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Normalize and read sensor's raw SNMP OID */ if (snmp_bc_oid_snmp_get(custom_handle, &(rdr->Entity), raw_oid, &get_value, SAHPI_TRUE) != 0) { dbg("SNMP cannot read sensor OID=%s. Type=%d", raw_oid, get_value.type); return(SA_ERR_HPI_NO_RESPONSE); } /* Convert SNMP value to HPI reading value */ working.IsSupported = SAHPI_TRUE; if (get_value.type == ASN_INTEGER) { working.Type = SAHPI_SENSOR_READING_TYPE_INT64; working.Value.SensorInt64 = (SaHpiInt64T)get_value.integer; } else { SaHpiTextBufferT buffer; oh_init_textbuffer(&buffer); oh_append_textbuffer(&buffer, get_value.string); SaErrorT err = oh_encode_sensorreading(&buffer, rdr->RdrTypeUnion.SensorRec.DataFormat.ReadingType, &working); if (err) { dbg("Cannot convert sensor OID=%s value=%s. Error=%s", sinfo->mib.oid, buffer.Data, oh_lookup_error(err)); return(SA_ERR_HPI_INTERNAL_ERROR); } } memcpy(reading, &working, sizeof(SaHpiSensorReadingT)); return(SA_OK); }
int sim_util_get_rdr_by_sensornum(RPTable *table, SaHpiResourceIdT res_id, SaHpiSensorNumT num, SaHpiEntryIdT *eid) { SaHpiRdrT *rdr; rdr = oh_get_rdr_by_type(table, res_id, SAHPI_SENSOR_RDR, num); if (rdr == NULL) return -1; *eid = rdr->RecordId; return 0; }
SaErrorT sim_get_sensor_event_masks(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, SaHpiEventStateT *AssertEventMask, SaHpiEventStateT *DeassertEventMask) { struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct SensorInfo *sinfo; if (!hnd ) { err("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exists and return enablement status */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); if (!AssertEventMask && !DeassertEventMask) { return SA_OK; } sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { err("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_NOT_PRESENT); } if (AssertEventMask) *AssertEventMask = sinfo->assert_mask; if (DeassertEventMask) { if (rpt->ResourceCapabilities & SAHPI_CAPABILITY_EVT_DEASSERTS) { *DeassertEventMask = sinfo->assert_mask; } else { *DeassertEventMask = sinfo->deassert_mask; } } return(SA_OK); }
SaErrorT sim_get_sensor_reading(void *hnd, SaHpiResourceIdT id, SaHpiSensorNumT num, SaHpiSensorReadingT *data, SaHpiEventStateT *state) { struct SensorInfo *sinfo; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; if (!hnd) { err("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, id); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exist and is enabled */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, id, SAHPI_SENSOR_RDR, num); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, id, rdr->RecordId); if (sinfo == NULL) { err("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_NOT_PRESENT); } /*If sensor is enabled, get sensor reading*/ if (sinfo->sensor_enabled == SAHPI_FALSE) { return(SA_ERR_HPI_INVALID_REQUEST); } else { if (data) { *data = sinfo->reading; } if (state) { *state = sinfo->cur_state; } } return(SA_OK); }
SaErrorT sim_set_sensor_thresholds(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const SaHpiSensorThresholdsT *thres) { struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct SensorInfo *sinfo; if (!hnd || !thres) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exist and is enabled */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_NOT_PRESENT); } if (rdr->RdrTypeUnion.SensorRec.Category != SAHPI_EC_THRESHOLD || rdr->RdrTypeUnion.SensorRec.ThresholdDefn.IsAccessible == SAHPI_FALSE || rdr->RdrTypeUnion.SensorRec.ThresholdDefn.WriteThold == 0) { return(SA_ERR_HPI_INVALID_CMD); } if (sinfo->sensor_enabled == SAHPI_FALSE){ return(SA_ERR_HPI_INVALID_REQUEST); } else{ memcpy(&sinfo->thres, thres, sizeof(SaHpiSensorThresholdsT)); } return(SA_OK); }
/** * main: Starts with an RPTable of 10 resources, adds 5 rdr * to first resource. Fetches rdrs randomly by type and compares * with original. A failed comparison means the test failed, * otherwise the test passed. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); GSList *records = NULL; guint i = 0; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, rdrs + i, NULL,0)) return 1; else records = g_slist_append(records, rdrs + i); } for (; records; i--) { SaHpiRdrT *tmprdr = NULL, *randrdr = NULL; GSList *tmpnode = NULL; guint k = (guint) (((gfloat)i)*rand()/(RAND_MAX+1.0)); tmpnode = g_slist_nth(records, k); randrdr = (SaHpiRdrT *)tmpnode->data; randrdr->RecordId = get_rdr_uid(randrdr->RdrType, randrdr->RdrTypeUnion.SensorRec.Num); tmprdr = oh_get_rdr_by_type(rptable, SAHPI_FIRST_ENTRY, randrdr->RdrType, randrdr->RdrTypeUnion.SensorRec.Num); if (!tmprdr || memcmp(randrdr, tmprdr, sizeof(SaHpiRdrT))) return 1; else { records = g_slist_remove_link(records, tmpnode); g_slist_free_1(tmpnode); } } return 0; }
/** * main: Starts with an RPTable of 1 resource, adds 5 rdrs to first resource. * Fetches an rdr by type using a NULL table. * Success if the interface returns an error, otherwise there was a failure. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); guint i; if (oh_add_resource(rptable, rptentries, NULL, 1)) return 1; for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, rptentries[0].ResourceId, rdrs+i, NULL, 1)) return 1; } if (oh_get_rdr_by_type(NULL, rptentries[0].ResourceId, rdrs[0].RdrType, rdrs[0].RdrTypeUnion.SensorRec.Num)) return 1; return 0; }
SaErrorT snmp_rsa_set_sensor_event_enables(void *hnd, SaHpiResourceIdT id, SaHpiSensorNumT num, const SaHpiSensorEvtEnablesT *enables) { SaHpiRdrT *rdr = oh_get_rdr_by_type(((struct oh_handler_state *)hnd)->rptcache, id, SAHPI_SENSOR_RDR, num); if (rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } gpointer rsa_data = oh_get_rdr_data(((struct oh_handler_state *)hnd)->rptcache, id, rdr->RecordId); if (rsa_data == NULL) { dbg("Sensor Data Pointer is NULL; RID=%x; SID=%d", id, num); return -1; } if (rdr->RdrTypeUnion.SensorRec.Ignore == SAHPI_TRUE) { return SA_ERR_HPI_INVALID_CMD; } if (rdr->RdrTypeUnion.SensorRec.EventCtrl == SAHPI_SEC_NO_EVENTS) { return SA_ERR_HPI_INVALID_CMD; } if ((enables->SensorStatus & SAHPI_SENSTAT_SCAN_ENABLED) || (enables->SensorStatus & SAHPI_SENSTAT_BUSY)) { return SA_ERR_HPI_INVALID_CMD; } /* * Ignore the assertion/deassert event states in enables, since RSA does not * support enabling/disabling individual events - just the entire sensor */ if (!(enables->SensorStatus & SAHPI_SENSTAT_EVENTS_ENABLED)) { /* turn off events in RDR's data */ ((struct RSA_SensorInfo *)rsa_data)->sensor_evt_enablement.SensorStatus = ((struct RSA_SensorInfo *)rsa_data)->sensor_evt_enablement.SensorStatus & ~SAHPI_SENSTAT_EVENTS_ENABLED; } return SA_OK; }
SaErrorT sim_get_sensor_thresholds(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, SaHpiSensorThresholdsT *thres) { struct SensorInfo *sinfo; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; if (!hnd || !thres) { err("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } if (!rid) return SA_ERR_HPI_INVALID_RESOURCE; if (!sid) return SA_ERR_HPI_NOT_PRESENT; /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exist and is enabled */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { err("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_NOT_PRESENT); } /* If sensor is enabled, set thresholds */ if (sinfo->sensor_enabled == SAHPI_FALSE){ return(SA_ERR_HPI_INVALID_REQUEST); } else { *thres = sinfo->thres; } return(SA_OK); }
/** * snmp_bc_set_sensor_event_enable: * @hnd: Handler data pointer. * @rid: Resource ID. * @sid: Sensor ID. * @enable: Enable/disable sensor. * * Sets a sensor's boolean event enablement status. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_CAPABILITY - Resource doesn't have SAHPI_CAPABILITY_SENSOR. * SA_ERR_HPI_NOT_PRESENT - Sensor doesn't exist. **/ SaErrorT snmp_bc_set_sensor_event_enable(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const SaHpiBoolT enable) { struct oh_handler_state *handle = (struct oh_handler_state *)hnd; if (!hnd ) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exists and if it supports setting of sensor event enablement */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); if (rdr->RdrTypeUnion.SensorRec.EventCtrl == SAHPI_SEC_PER_EVENT || rdr->RdrTypeUnion.SensorRec.EventCtrl == SAHPI_SEC_READ_ONLY_MASKS) { dbg("BladeCenter/RSA do not support snmp_bc_set_sensor_event_enable\n"); struct SensorInfo *sinfo; sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (sinfo->events_enabled != enable) { /* Probably need to drive an OID, if hardware supported it */ sinfo->events_enabled = enable; /* FIXME:: Add SAHPI_ET_SENSOR_ENABLE_CHANGE event on IF event Q */ } } else { return(SA_ERR_HPI_READ_ONLY); } return(SA_OK); }
/** * snmp_bc_set_sensor_event_enable: * @hnd: Handler data pointer. * @rid: Resource ID. * @sid: Sensor ID. * @enable: Enable/disable sensor. * * Sets a sensor's boolean event enablement status. * * Return values: * SA_OK - normal case. * SA_ERR_HPI_CAPABILITY - if resource doesn't have SAHPI_CAPABILITY_SENSOR. * SA_ERR_HPI_NOT_PRESENT - if sensor doesn't exist. **/ SaErrorT snmp_bc_set_sensor_event_enable(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const SaHpiBoolT enable) { SaHpiRdrT *rdr; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exists and if it supports setting of sensor event enablement */ rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); if (rdr->RdrTypeUnion.SensorRec.EventCtrl == SAHPI_SEC_PER_EVENT || rdr->RdrTypeUnion.SensorRec.EventCtrl == SAHPI_SEC_READ_ONLY_MASKS) { #if 1 dbg("BladeCenter/RSA do not support snmp_bc_set_sensor_event_enable"); return(SA_ERR_HPI_INTERNAL_ERROR); #else /* Not tested */ struct SensorInfo *sinfo; sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("Cannot retrieve sensor data."); return(SA_ERR_HPI_INTERNAL_ERROR); } if (sinfo->events_enabled != enable) { sinfo->events_enabled = enable; /* FIXME:: Add SAHPI_ET_SENSOR_ENABLE_CHANGE event on IF event Q */ } #endif } else { return(SA_ERR_HPI_READ_ONLY); } return(SA_OK); }
SaErrorT sim_get_next_announce(void *hnd, SaHpiResourceIdT rid, SaHpiAnnunciatorNumT aid, SaHpiSeverityT sev, SaHpiBoolT unackonly, SaHpiAnnouncementT *announcement) { struct oh_handler_state *state = (struct oh_handler_state *)hnd; struct simAnnunciatorInfo *info; if (!hnd || !announcement || oh_lookup_severity(sev) == NULL) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } /* Check if resource exists and has annunciator capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return(SA_ERR_HPI_INVALID_RESOURCE); } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_ANNUNCIATOR)) { return(SA_ERR_HPI_CAPABILITY); } SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_ANNUNCIATOR_RDR, aid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); /* get our announcement info */ info = (struct simAnnunciatorInfo *)oh_get_rdr_data(state->rptcache, rid, rdr->RecordId); if (info == NULL) { dbg("No annunciator data."); return(SA_ERR_HPI_NOT_PRESENT); } /* perform function */ return oh_announcement_get_next(info->announs, sev, unackonly, announcement); }
SaErrorT ohoi_get_control_state(void *hnd, SaHpiResourceIdT id, SaHpiCtrlNumT num, SaHpiCtrlModeT *mode, SaHpiCtrlStateT *state) { struct oh_handler_state *handler = (struct oh_handler_state *)hnd; SaErrorT rv; struct ohoi_control_info *ctrl_info; SaHpiRdrT *rdr; rdr = oh_get_rdr_by_type(handler->rptcache, id, SAHPI_CTRL_RDR, num); if (!rdr) return SA_ERR_HPI_INVALID_RESOURCE; rv = ohoi_get_rdr_data(hnd, id, SAHPI_CTRL_RDR, num, (void *)&ctrl_info); if (rv!=SA_OK) return rv; if (ctrl_info->ohoii.get_control_state == NULL) { return SA_ERR_HPI_UNSUPPORTED_API; } return ctrl_info->ohoii.get_control_state(handler, ctrl_info, rdr, mode, state); }
SaErrorT sim_set_watchdog_info(void *hnd, SaHpiResourceIdT rid, SaHpiWatchdogNumT num, SaHpiWatchdogT *wdt) { struct simWatchdogInfo *info; if (!hnd) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *state = (struct oh_handler_state *)hnd; /* Check if resource exists and has managed hotswap capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return SA_ERR_HPI_INVALID_RESOURCE; } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG)) { return SA_ERR_HPI_CAPABILITY; } /* get our private info */ SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_WATCHDOG_RDR, num); if (rdr == NULL) return SA_ERR_HPI_NOT_PRESENT; info = (struct simWatchdogInfo *)oh_get_rdr_data(state->rptcache, rid, rdr->RecordId); if (info == NULL) { dbg("No watchdog data. Watchdog=%s", rdr->IdString.Data); return SA_ERR_HPI_NOT_PRESENT; } memcpy(&info->watchdog, wdt, sizeof(SaHpiWatchdogT)); return SA_OK; }
SaErrorT sim_set_annunc_mode(void *hnd, SaHpiResourceIdT rid, SaHpiAnnunciatorNumT aid, SaHpiAnnunciatorModeT mode) { struct oh_handler_state *state = (struct oh_handler_state *)hnd; struct simAnnunciatorInfo *info; if (!hnd || oh_lookup_annunciatormode(mode) == NULL) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } /* Check if resource exists and has annunciator capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return(SA_ERR_HPI_INVALID_RESOURCE); } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_ANNUNCIATOR)) { return(SA_ERR_HPI_CAPABILITY); } SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_ANNUNCIATOR_RDR, aid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); /* get our announcement info */ info = (struct simAnnunciatorInfo *)oh_get_rdr_data(state->rptcache, rid, rdr->RecordId); if (info == NULL) { dbg("No annunciator data."); return(SA_ERR_HPI_NOT_PRESENT); } info->mode = mode; return SA_OK; }
SaErrorT sim_get_idr_info(void *hnd, SaHpiResourceIdT rid, SaHpiIdrIdT IdrId, SaHpiIdrInfoT *IdrInfo) { struct sim_inventory_info *info; if (!hnd || !IdrInfo) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *state = (struct oh_handler_state *)hnd; /* Check if resource exists and has inventory capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return SA_ERR_HPI_INVALID_RESOURCE; } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA)) { return SA_ERR_HPI_CAPABILITY; } /* Find inventory and its data - see if it accessable */ SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_INVENTORY_RDR, IdrId); if (rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } info = (struct sim_inventory_info *)oh_get_rdr_data(state->rptcache, IdrId, rdr->RecordId); if (info == NULL) { dbg("No inventory data. IdrId=%s", rdr->IdString.Data); return SA_ERR_HPI_NOT_PRESENT; } /* return the data */ memcpy(IdrInfo, &info->idrinfo, sizeof(SaHpiIdrInfoT)); return SA_OK; }
SaErrorT sim_set_sensor_enable(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const SaHpiBoolT enable) { struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct SensorInfo *sinfo; if (!hnd || !rid || !sid || !enable) { err("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exist and is enabled */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { err("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_NOT_PRESENT); } /* set sensor flag */ sinfo->sensor_enabled = enable; return(SA_OK); }
SaErrorT snmp_rsa_get_sensor_data(void *hnd, SaHpiResourceIdT id, SaHpiSensorNumT num, SaHpiSensorReadingT *data) { gchar *oid; SaHpiSensorReadingT working; struct snmp_value get_value; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_rsa_hnd *custom_handle = (struct snmp_rsa_hnd *)handle->data; SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, id, SAHPI_SENSOR_RDR, num); if(rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } struct RSA_SensorInfo *s = (struct RSA_SensorInfo *)oh_get_rdr_data(handle->rptcache, id, rdr->RecordId); if(s == NULL) { return -1; } if (rdr->RdrTypeUnion.SensorRec.Ignore == SAHPI_TRUE) { return SA_ERR_HPI_INVALID_CMD; } memset(&working, 0, sizeof(SaHpiSensorReadingT)); /* Extract index from rdr id and get the snmp of the sensor */ if (s->mib.oid != NULL) { oid = snmp_derive_objid(rdr->Entity, s->mib.oid); if(oid == NULL) { dbg("NULL SNMP OID returned for %s\n",s->mib.oid); return -1; } /* Read the sensor value */ if(snmp_get(custom_handle->ss, oid, &get_value) != 0){ dbg("SNMP could not read sensor %s. Type = %d",oid,get_value.type); g_free(oid); return SA_ERR_HPI_NO_RESPONSE; } g_free(oid); /* Based on the sensor description, construct a reading to send up */ /* format the value into the reading for each type of reading format */ working.ValuesPresent = rdr->RdrTypeUnion.SensorRec.DataFormat.ReadingFormats; if(working.ValuesPresent & SAHPI_SRF_RAW) { if(get_value.type != ASN_INTEGER) { dbg("Sensor value type mismatches reading format."); return -1; } else { working.Raw = (SaHpiUint32T)get_value.integer; } } if(working.ValuesPresent & SAHPI_SRF_INTERPRETED) { if(get_value.type == ASN_INTEGER) { working.Interpreted.Type = SAHPI_SENSOR_INTERPRETED_TYPE_INT32; working.Interpreted.Value.SensorInt32 = get_value.integer; } else { SaHpiSensorInterpretedUnionT value; working.Interpreted.Type = rdr->RdrTypeUnion.SensorRec.DataFormat.Range.Max.Interpreted.Type; if(rdr->RdrTypeUnion.SensorRec.DataFormat.Range.Max.Interpreted.Type == SAHPI_SENSOR_INTERPRETED_TYPE_BUFFER) { strncpy(working.Interpreted.Value.SensorBuffer, get_value.string, SAHPI_SENSOR_BUFFER_LENGTH); } else { if(s->mib.convert_snmpstr >= 0) { if(get_interpreted_value(get_value.string,s->mib.convert_snmpstr,&value)) { dbg("Error: get_interpreted_value for %s, (%s)\n",s->mib.oid,get_value.string); return -1; } working.Interpreted.Value = value; } else { dbg("Sensor %s SNMP string value needs to be converted\n", s->mib.oid); return -1; } } } } } if (working.ValuesPresent & SAHPI_SRF_EVENT_STATE) { working.EventStatus.SensorStatus = s->sensor_evt_enablement.SensorStatus; /* Hardcoded hack for R/W LEDs */ if (working.ValuesPresent & SAHPI_SRF_RAW) { if (rdr->RdrTypeUnion.SensorRec.Category == SAHPI_EC_USAGE) { switch (working.Raw) { case 0: working.EventStatus.EventStatus = rdr->RdrTypeUnion.SensorRec.DataFormat.Range.Min.EventStatus.EventStatus; break; case 1: working.EventStatus.EventStatus = rdr->RdrTypeUnion.SensorRec.DataFormat.Range.Nominal.EventStatus.EventStatus; break; case 2: working.EventStatus.EventStatus = rdr->RdrTypeUnion.SensorRec.DataFormat.Range.Max.EventStatus.EventStatus; break; default: dbg("Unrecognized Raw values for LED=%s", rdr->IdString.Data); return -1; } } else { switch (working.Raw) { case 0: working.EventStatus.EventStatus = rdr->RdrTypeUnion.SensorRec.DataFormat.Range.Min.EventStatus.EventStatus; break; case 1: working.EventStatus.EventStatus = rdr->RdrTypeUnion.SensorRec.DataFormat.Range.Max.EventStatus.EventStatus; break; default: dbg("Unrecognized Raw values for LED=%s", rdr->IdString.Data); return -1; } } } else { /* Non-LED sensor - normal case */ working.EventStatus.EventStatus = s->cur_state; } } memcpy(data,&working,sizeof(SaHpiSensorReadingT)); return SA_OK; }
SaErrorT snmp_rsa_get_sensor_thresholds(void *hnd, SaHpiResourceIdT id, SaHpiSensorNumT num, SaHpiSensorThresholdsT *thres) { gchar *oid = NULL; int found_raw, found_interpreted; SaHpiSensorThresholdsT working; SaHpiSensorInterpretedUnionT value; struct snmp_value get_value; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_rsa_hnd *custom_handle = (struct snmp_rsa_hnd *)handle->data; SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, id, SAHPI_SENSOR_RDR, num); if(rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } struct RSA_SensorInfo *s = (struct RSA_SensorInfo *)oh_get_rdr_data(handle->rptcache, id, rdr->RecordId); if(s == NULL) { return -1; } if (rdr->RdrTypeUnion.SensorRec.Ignore == SAHPI_TRUE) { return SA_ERR_HPI_INVALID_CMD; } memset(&working, 0, sizeof(SaHpiSensorThresholdsT)); if(rdr->RdrTypeUnion.SensorRec.ThresholdDefn.IsThreshold == SAHPI_TRUE) { found_raw = found_interpreted = 0; if(rdr->RdrTypeUnion.SensorRec.ThresholdDefn.TholdCapabilities & SAHPI_STC_RAW) { get_raw_thresholds(SAHPI_STM_LOW_MINOR, OidLowMinor, LowMinor); get_raw_thresholds(SAHPI_STM_LOW_MAJOR, OidLowMajor, LowMajor); get_raw_thresholds(SAHPI_STM_LOW_CRIT, OidLowCrit, LowCritical); get_raw_thresholds(SAHPI_STM_UP_MINOR, OidUpMinor, UpMinor); get_raw_thresholds(SAHPI_STM_UP_MAJOR, OidUpMajor, UpMajor); get_raw_thresholds(SAHPI_STM_UP_CRIT, OidUpCrit, UpCritical); /* Ignore any PosThdHysteresis and NegThdHysteresis for RAW (going away in 1.1) */ } if(rdr->RdrTypeUnion.SensorRec.ThresholdDefn.TholdCapabilities & SAHPI_STC_INTERPRETED) { get_interpreted_thresholds(SAHPI_STM_LOW_MINOR, OidLowMinor, LowMinor); get_interpreted_thresholds(SAHPI_STM_LOW_MAJOR, OidLowMajor, LowMajor); get_interpreted_thresholds(SAHPI_STM_LOW_CRIT, OidLowCrit, LowCritical); get_interpreted_thresholds(SAHPI_STM_UP_MINOR, OidUpMinor, UpMinor); get_interpreted_thresholds(SAHPI_STM_UP_MAJOR, OidUpMajor, UpMajor); get_interpreted_thresholds(SAHPI_STM_UP_CRIT, OidUpCrit, UpCritical); get_interpreted_thresholds(SAHPI_STM_UP_HYSTERESIS, OidUpHysteresis, PosThdHysteresis); get_interpreted_thresholds(SAHPI_STM_LOW_HYSTERESIS, OidLowHysteresis, NegThdHysteresis); /* Hysteresis - RSA supports a reset value for some single threshold * sensors. So there may be a major threshold of 78 and a reset of 76. This * extremely ugly code, calculates the delta to report hysteresis. * If multiple thresholds are defined, the most severe one is used as the * basis for the delta calculation. Also we assume all values are float32 */ if ((found_interpreted & SAHPI_STM_UP_HYSTERESIS) && ((found_interpreted & SAHPI_STM_UP_CRIT) || (found_interpreted & SAHPI_STM_UP_MAJOR) || (found_interpreted & SAHPI_STM_UP_MINOR))) { if (found_interpreted & SAHPI_STM_UP_CRIT) { get_up_hysteresis_value(PosThdHysteresis, UpCritical); } else { if (found_interpreted & SAHPI_STM_UP_MAJOR) { get_up_hysteresis_value(PosThdHysteresis, UpMajor); } else { if (found_interpreted & SAHPI_STM_UP_MINOR) { get_up_hysteresis_value(PosThdHysteresis, UpMinor); } } } } else { dbg("Positive Hysteresis is defined but not any positive thresholds"); working.PosThdHysteresis.ValuesPresent = 0; } /* Negitive hysteresis */ if ((found_interpreted & SAHPI_STM_LOW_HYSTERESIS) && ((found_interpreted & SAHPI_STM_LOW_CRIT) || (found_interpreted & SAHPI_STM_LOW_MAJOR) || (found_interpreted & SAHPI_STM_LOW_MINOR))) { if (found_interpreted & SAHPI_STM_LOW_CRIT) { get_low_hysteresis_value(NegThdHysteresis, LowCritical); } else { if (found_interpreted & SAHPI_STM_LOW_MAJOR) { get_low_hysteresis_value(NegThdHysteresis, LowMajor); } else { if (found_interpreted & SAHPI_STM_LOW_MINOR) { get_low_hysteresis_value(NegThdHysteresis, LowMinor); } } } } else { dbg("Negitive Hysteresis is defined but not any negitive thresholds"); working.NegThdHysteresis.ValuesPresent = 0; } } if (found_raw || found_interpreted) { memcpy(thres,&working,sizeof(SaHpiSensorThresholdsT)); return SA_OK; } else { dbg("No threshold values found\n"); return -1; } } else { dbg("Thresholds requested, but sensor does not support them.\n"); return SA_ERR_HPI_INVALID_CMD; } }
int main(int argc, char **argv) { /* ************************ * Local variables * ***********************/ int testfail = 0; SaErrorT err; SaErrorT expected_err; SaHpiResourceIdT id; SaHpiSessionIdT sessionid; SaHpiSensorNumT dd_sid = 0; SaHpiEventStateT state; SaHpiSensorReadingT reading; /* ************************************* * Find a resource with Sensor type rdr * ************************************* */ struct oh_handler l_handler; struct oh_handler *h= &l_handler; SaHpiRptEntryT rptentry; SaHpiRdrT *rdrptr; err = tsetup(&sessionid); if (err != SA_OK) { printf("Error! bc_sensor, can not setup test environment\n"); return -1; } err = tfind_resource(&sessionid, (SaHpiCapabilitiesT) SAHPI_CAPABILITY_SENSOR, h, &rptentry); if (err != SA_OK) { printf("Error! bc_sensor, can not setup test environment\n"); err = tcleanup(&sessionid); return -1; } struct oh_handler_state *handle = (struct oh_handler_state *)h->hnd; id = rptentry.ResourceId; /************************** * Test 10 **************************/ dd_sid = 0; do { dd_sid++; rdrptr = oh_get_rdr_by_type(handle->rptcache, id, SAHPI_SENSOR_RDR, dd_sid); if (rdrptr != NULL) { if (rdrptr->RdrTypeUnion.SensorRec.DataFormat.IsSupported == SAHPI_FALSE) { break; } else rdrptr = NULL; } } while ((rdrptr == NULL) && (dd_sid < 128)); if (rdrptr == NULL) testfail = -1; /************************** * Test 11 **************************/ expected_err = SA_OK; err = snmp_bc_get_sensor_reading((void *)h->hnd, id, dd_sid, &reading, &state); checkstatus(&err, &expected_err, &testfail); /************************** * Test 12 **************************/ if (reading.IsSupported ) { printf("\t Reading Is Supported for sensor %d!\n\n", dd_sid); testfail = -1; } /*************************** * Cleanup after all tests ***************************/ err = tcleanup(&sessionid); return testfail; }