SaErrorT snmp_bc_set_power_state(void *hnd, SaHpiResourceIdT id, SaHpiHsPowerStateT state) { gchar *oid; int rtn_code = SA_OK; struct snmp_value set_value; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; SaHpiRptEntryT *res = oh_get_resource_by_id(handle->rptcache, id); if(res == NULL) { return SA_ERR_HPI_NOT_PRESENT; } struct BC_ResourceInfo *s = (struct BC_ResourceInfo *)oh_get_resource_data(handle->rptcache, id); if(s == NULL) { return -1; } if(s->mib.OidPowerOnOff == NULL) { return SA_ERR_HPI_INVALID_CMD; } oid = snmp_derive_objid(res->ResourceEntity, s->mib.OidPowerOnOff); if(oid == NULL) { dbg("NULL SNMP OID returned for %s\n",s->mib.OidPowerOnOff); return -1; } set_value.type = ASN_INTEGER; switch (state) { case SAHPI_HS_POWER_OFF: set_value.integer = 0; if((snmp_set(custom_handle->ss, oid, set_value) != 0)) { dbg("SNMP could not set %s; Type=%d.\n",s->mib.OidPowerOnOff,set_value.type); rtn_code = SA_ERR_HPI_NO_RESPONSE; } break; case SAHPI_HS_POWER_ON: set_value.integer = 1; if((snmp_set(custom_handle->ss, oid, set_value) != 0)) { dbg("SNMP could not set %s; Type=%d.\n",s->mib.OidPowerOnOff,set_value.type); rtn_code = SA_ERR_HPI_NO_RESPONSE; } break; case SAHPI_HS_POWER_CYCLE: { SaHpiResetActionT act = SAHPI_COLD_RESET; rtn_code=snmp_bc_set_reset_state(hnd, id, act); } break; default: dbg("Invalid Power Action Type - %d\n", state); rtn_code = SA_ERR_HPI_INVALID_PARAMS; } g_free(oid); return rtn_code; }
/** * snmp_bc_clear_sel: * @hnd: Pointer to handler's data. * @id: Resource ID that owns the Event Log. * * Clears the system event log. * * Return values: * SA_OK - normal case. * SA_ERR_HPI_INVALID_PARAMS - @hnd is NULL. **/ SaErrorT snmp_bc_clear_sel(void *hnd, SaHpiResourceIdT id) { struct snmp_value set_value; struct oh_handler_state *handle = hnd; struct snmp_bc_hnd *custom_handle = handle->data; SaErrorT err; if (!hnd) { dbg("Invalid parameters."); return(SA_ERR_HPI_INVALID_PARAMS); } err = oh_el_clear(handle->elcache); if (err) { dbg("Cannot clear system Event Log. Error=%s.", oh_lookup_error(err)); return(err); } set_value.type = ASN_INTEGER; set_value.str_len = 1; set_value.integer = (long) clearEventLogExecute; err = snmp_set(custom_handle->ss, SNMP_BC_CLEAR_SEL_OID, set_value); if (err) { dbg("SNMP set failed. Error=%s.", oh_lookup_error(err)); return(err); } return(SA_OK); }
/** * Wrapper to set the given tuner frequency */ void snmp_set_freq(struct snmp_sessions *ss, size_t rx, const char *frequency) { char oid[40]; if (!get_freq_tuner_oid(rx, oid)) { fprintf(stderr, "SNMP: Could not get OID to tune frequency!\n"); return; } if (!snmp_set(ss->write, oid, 'u', frequency)) { fprintf(stderr, "SNMP: Set frequency failed!\n"); } }
/** * Wrapper to set the given profile as active */ void snmp_set_active_profile(struct snmp_sessions *ss, size_t rx, unsigned char profile) { char oid[40]; if (!get_profile_activate_oid(rx, profile, oid)) { fprintf(stderr, "SNMP: Could not get profile OID\n"); return; } if (!snmp_set(ss->write, oid, 'i', "0")) { fprintf(stderr, "SNMP: Set active profile failed!\n"); } }
SaErrorT snmp_rsa_set_reset_state(void *hnd, SaHpiResourceIdT id, SaHpiResetActionT act) { gchar *oid; struct snmp_value set_value; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_rsa_hnd *custom_handle = (struct snmp_rsa_hnd *)handle->data; SaHpiRptEntryT *res = oh_get_resource_by_id(handle->rptcache, id); if(res == NULL) { return SA_ERR_HPI_NOT_PRESENT; } struct RSA_ResourceInfo *s = (struct RSA_ResourceInfo *)oh_get_resource_data(handle->rptcache, id); if(s == NULL) { return -1; } if(s->mib.OidReset == NULL) { return SA_ERR_HPI_INVALID_CMD; } switch (act) { case SAHPI_RESET_ASSERT: /* RESET_ASSERT = RESET_DEASSERT Action */ case SAHPI_RESET_DEASSERT: return SA_ERR_HPI_INVALID_CMD; case SAHPI_COLD_RESET: /* COLD = WARM Reset Action */ case SAHPI_WARM_RESET: oid = snmp_derive_objid(res->ResourceEntity, s->mib.OidReset); if(oid == NULL) { dbg("NULL SNMP OID returned for %s\n",s->mib.OidReset); return -1; } set_value.type = ASN_INTEGER; set_value.str_len = 1; set_value.integer = 1; if((snmp_set(custom_handle->ss, oid, set_value) != 0)) { dbg("SNMP could not set %s; Type=%d.\n",s->mib.OidReset,set_value.type); g_free(oid); return SA_ERR_HPI_NO_RESPONSE; } g_free(oid); break; default: dbg("Invalid Reset Action Type - %d\n", act); return SA_ERR_HPI_INVALID_PARAMS; } return SA_OK; }
/** * Wrapper to set the active RX */ void snmp_set_active_rx(struct snmp_sessions *ss, size_t rx) { char oid[40]; char rx_str[2]; strncpy(oid, SNMP_RX_MGMT, 40); if (rx == RX1) { strncpy(rx_str, "1", 2); } else if (rx == RX2) { strncpy(rx_str, "2", 2); } else { fprintf(stderr, "SNMP: Bad RX given!\n"); return; } if (!snmp_set(ss->write, oid, 'i', rx_str)) { fprintf(stderr, "SNMP: Set active RX failed!\n"); } }
int set_bc_sp_time(struct snmp_session *ss, struct tm *time) { struct snmp_value set_value; int returncode = 0; set_value.type = ASN_OCTET_STR; strftime(set_value.string, sizeof(set_value.string), "%m/%d/%Y,%H:%M:%S", time); set_value.str_len = 19; if (snmp_set(ss,BC_DATETIME_OID,set_value) == 0) { returncode = 0; } else { dbg("snmp_set is NOT successful\n"); returncode = -1; } return returncode; }
/** * snmp_bc_snmp_set: * @custom_handle: Plugin's data pointer. * @objid: SNMP OID. * @value: SNMP value to set. * * Plugin wrapper for SNMP set call. If SNMP command times out, * this function returns an SA_ERR_HPI_BUSY until a max number * of retries occurs - then it returns SA_ERR_HPI_NO_RESPONSE. * BladeCenter hardware often takes several SNMP attempts before * it responses. User applications should continue to retry on * BUSY and only fail on NO_RESPONSE. * * Return values: * SA_OK - Normal case. **/ SaErrorT snmp_bc_snmp_set(struct snmp_bc_hnd *custom_handle, char *objid, struct snmp_value value) { SaErrorT err; /* struct snmp_session *ss = custom_handle->ss; */ err = snmp_set(custom_handle->sessp, objid, value); if (err == SA_ERR_HPI_TIMEOUT) { if (custom_handle->handler_retries == SNMP_BC_MAX_SNMP_RETRY_ATTEMPTED) { custom_handle->handler_retries = 0; err = SA_ERR_HPI_NO_RESPONSE; } else { custom_handle->handler_retries++; err = SA_ERR_HPI_BUSY; } } else { custom_handle->handler_retries = 0; } return(err); }
SaErrorT snmp_bc_set_control_state(void *hnd, SaHpiResourceIdT id, SaHpiCtrlNumT num, SaHpiCtrlStateT *state) { gchar *oid; int value; struct snmp_value set_value; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, id, SAHPI_CTRL_RDR, num); if(rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } struct BC_ControlInfo *s = (struct BC_ControlInfo *)oh_get_rdr_data(handle->rptcache, id, rdr->RecordId); if(s == NULL) { return -1; } if (rdr->RdrTypeUnion.CtrlRec.Ignore == SAHPI_TRUE) { return SA_ERR_HPI_INVALID_CMD; } if(state->Type != rdr->RdrTypeUnion.CtrlRec.Type) { dbg("Control %s type %d cannot be changed\n",s->mib.oid,state->Type); return SA_ERR_HPI_INVALID_PARAMS; } switch (state->Type) { case SAHPI_CTRL_TYPE_DIGITAL: /* More icky dependencies on SaHpiStateDigitalT enum */ switch (state->StateUnion.Digital) { case SAHPI_CTRL_STATE_OFF: value = s->mib.digitalmap[SAHPI_CTRL_STATE_OFF]; break; case SAHPI_CTRL_STATE_ON: value = s->mib.digitalmap[SAHPI_CTRL_STATE_ON]; break; case SAHPI_CTRL_STATE_PULSE_OFF: value = s->mib.digitalmap[SAHPI_CTRL_STATE_PULSE_OFF]; break; case SAHPI_CTRL_STATE_PULSE_ON: value = s->mib.digitalmap[SAHPI_CTRL_STATE_PULSE_ON]; break; case SAHPI_CTRL_STATE_AUTO: value = s->mib.digitalmap[ELEMENTS_IN_SaHpiStateDigitalT - 1]; break; default: dbg("Spec Change: MAX_SaHpiStateDigitalT incorrect?\n"); return -1; } if(value < 0) { dbg("Control state %d not allowed to be set\n",state->StateUnion.Digital); return SA_ERR_HPI_INVALID_CMD; } 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; } set_value.type = ASN_INTEGER; set_value.str_len = 1; set_value.integer = value; if((snmp_set(custom_handle->ss, oid, set_value) != 0)) { dbg("SNMP could not set %s; Type=%d.\n",s->mib.oid,set_value.type); g_free(oid); return SA_ERR_HPI_NO_RESPONSE; } g_free(oid); break; case SAHPI_CTRL_TYPE_DISCRETE: 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; } set_value.type = ASN_INTEGER; set_value.str_len = 1; set_value.integer = state->StateUnion.Discrete; if((snmp_set(custom_handle->ss, oid, set_value) != 0)) { dbg("SNMP could not set %s; Type=%d.\n",s->mib.oid,set_value.type); g_free(oid); return SA_ERR_HPI_NO_RESPONSE; } g_free(oid); break; case SAHPI_CTRL_TYPE_ANALOG: dbg("Analog controls not supported\n"); return SA_ERR_HPI_INVALID_CMD; case SAHPI_CTRL_TYPE_STREAM: dbg("Stream controls not supported\n"); return SA_ERR_HPI_INVALID_CMD; case SAHPI_CTRL_TYPE_TEXT: dbg("Text controls not supported\n"); return SA_ERR_HPI_INVALID_CMD; case SAHPI_CTRL_TYPE_OEM: dbg("Oem controls not supported\n"); return SA_ERR_HPI_INVALID_CMD; default: dbg("Request has invalid control state=%d\n", state->Type); return SA_ERR_HPI_INVALID_PARAMS; } return SA_OK; }