static void list_rpt(SaHpiSessionIdT sessionid) { SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; int rv; rptentryid = SAHPI_FIRST_ENTRY; rv = SA_OK; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) { printf("Error getting RPT entry: rv = %d\n", rv); } printf("Resource Id: %d\n", rptentry.ResourceId); printf("Resource Tag: %s\n", (char *)rptentry.ResourceTag.Data); rptentryid = nextrptentryid; } }
SaErrorT list_all(SaHpiSessionIdT sessionid) { SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaErrorT rv = SA_OK; rptentryid = SAHPI_FIRST_ENTRY; do { if (fdebug) printf("saHpiRptEntryGet\n"); rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid,&rptentry); if (rv != SA_OK) { printf("Error getting RPT entry: rv = %s\n", oh_lookup_error(rv)); return (rv); } else { oh_print_rptentry(&rptentry, 2); list_rdr(sessionid, rptentry.ResourceId); list_inv(sessionid, rptentry.ResourceId); list_sens(sessionid, rptentry.ResourceId); list_ctrl(sessionid, rptentry.ResourceId); list_wdog(sessionid, rptentry.ResourceId); } rptentryid = nextrptentryid; } while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)); return(rv); }
SaErrorT list_rpt(SaHpiSessionIdT sessionid,SaHpiResourceIdT resourceid) { SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaErrorT rv = SA_OK; rptentryid = SAHPI_FIRST_ENTRY; do { if (fdebug) printf("saHpiRptEntryGet\n"); rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid,&rptentry); if (rv != SA_OK) { printf("Error getting RPT entry: rv = %s\n", oh_lookup_error(rv)); return (rv); } else { if (resourceid == 255) oh_print_rptentry(&rptentry, 2); else { if (resourceid == rptentry.ResourceId) { oh_print_rptentry(&rptentry, 2); nextrptentryid = SAHPI_LAST_ENTRY; } } } rptentryid = nextrptentryid; } while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)); return(rv); }
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); }
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); }
static void* get_event(void *unused) { SaHpiEventT event; SaErrorT rv; SaHpiRptEntryT rptentry; SaHpiRdrT rdr; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; rv = saHpiSubscribe(Domain->sessionId); if (rv != SA_OK) { printf("OpenHPI>Fail to Subscribe event\n"); return (void *)0; } while(1) { for(;;) { rdr.RdrType = SAHPI_NO_RECORD; rptentry.ResourceId = 0; memset(&event, 0xF, sizeof(event)); rv = saHpiEventGet(Domain->sessionId, SAHPI_TIMEOUT_BLOCK, &event, NULL, NULL, NULL); if (rv != SA_OK ) { printf("saHpiEventGet failed with error <%d>", rv); break; } if (prt_flag == 1) { if (show_event_short) show_short_event(&event, ui_print); else if (rdr.RdrType != SAHPI_NO_RECORD) oh_print_event(&event, &rdr.Entity, 4); else if (rptentry.ResourceId != 0) oh_print_event(&event, &rptentry.ResourceEntity, 4); else { rptentryid = event.Source; rv = saHpiRptEntryGet(Domain->sessionId, rptentryid, &nextrptentryid, &rptentry); if(rv == SA_OK) oh_print_event(&event, &rptentry.ResourceEntity, 4); else { printf("saHpiRptEntryGet failed for resource Id <%d> with error <%d>", event.Source, rv); printf("Wrong resource Id <%d> detected", event.Source); oh_print_event(&event, NULL, 4); } } } }/*the loop for retrieving event*/ sleep(1); } return (void *)1; }
static SaHpiResourceIdT get_resid(SaHpiSessionIdT sid, SaHpiEntryIdT srchid) { SaHpiRptEntryT res; SaHpiEntryIdT rptid = SAHPI_FIRST_ENTRY; while(saHpiRptEntryGet(sid, rptid, &rptid, &res) == SA_OK) { if (srchid == res.ResourceEntity.Entry[0].EntityType) { return res.ResourceId; } } return 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; }
/* * This function opens the HPI session, discovers the resources which matches * the requested capability and sends the list of resource ids and resource * names. * * If the none of the resources matches to requested capability, * then SA_ERR_HPI_NOT_PRESENT error will be return. * On sucess SA_OK will be return. */ SaErrorT discover_resources(SaHpiSessionIdT sessionid, SaHpiCapabilitiesT capability, SaHpiResourceIdT *resourceid_list, int *number_resources) { int count=0; SaErrorT rv; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover failed with error: %s\n", oh_lookup_error(rv)); return rv; } rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) { printf("RptEntryGet failed with error: %s\n", oh_lookup_error(rv)); return rv; } if (rptentry.ResourceCapabilities & capability) { resourceid_list[count] = rptentry.ResourceId; printf("\tResource-id = %d, Resource Name = %s\n", rptentry.ResourceId, rptentry.ResourceTag.Data); if (strcmp(rptentry.ResourceTag.Data, "Power Subsystem") == 0) powerSubsystemResId = rptentry.ResourceId; count++; } rptentryid = nextrptentryid; } if (count == 0) return SA_ERR_HPI_NOT_PRESENT; *number_resources = count; return SA_OK; }
int main(int argc, char **argv) { SaHpiSessionIdT sid = 0; SaHpiRptEntryT res; SaHpiEntryIdT id = SAHPI_FIRST_ENTRY; 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"); } /* loop over all resources, ensure that ResourceTag and * ManufacturerId have been set */ while(saHpiRptEntryGet(sid,id,&id,&res) == SA_OK) { runtest(); if(!res.ResourceTag.DataLength) { failed("Resource Tag has zero length"); } runtest(); if(!res.ResourceInfo.ManufacturerId) { failed("Resource has no Manufacturer Id"); } /* there should be an inner loop here for Rdrs */ } printf("I hit here\n"); dbg("Ran %d tests", testnum); /* if there is any failures, the test fails */ if(failcount) { return -1; } return(0); }
static void get_rpts(void) { SaHpiEntryIdT rptentryid, nextrptentryid; SaErrorT rv; SaHpiRptEntryT rptentry; int n; rptentryid = SAHPI_FIRST_ENTRY; while (rptentryid != SAHPI_LAST_ENTRY) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) break; n = nrpts; Rpts = (Rpt_t *)resize_array(Rpts, sizeof(Rpt_t), &nrpts, 1); rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; Rpts[n].Rpt = rptentry; rptentryid = nextrptentryid; } }
SaErrorT sensor_list(SaHpiSessionIdT sessionid, hpi_ui_print_cb_t proc) { SaErrorT rv = SA_OK; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while (rptentryid != SAHPI_LAST_ENTRY) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) break; rv = show_sensor_list(sessionid, rptentry.ResourceId, proc); if (rv == -1) return(-1); rptentryid = nextrptentryid; }; return(rv); }
int Test_Resource(SaHpiSessionIdT session) { SaErrorT status; int retval = SAF_TEST_UNKNOWN; SaHpiEntryIdT RptNextEntry; SaHpiRptEntryT Report; // // Obtain a ResourceId // status = saHpiRptEntryGet(session, SAHPI_FIRST_ENTRY, &RptNextEntry, &Report); if (status != SA_OK) { if (status == SA_ERR_HPI_NOT_PRESENT) { retval = SAF_TEST_NOTSUPPORT; } else { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } } else { // // Call saHpiResourceSeveritySet while passing in an invalid // session id // status = saHpiResourceSeveritySet(INVALID_SESSION_ID, Report.ResourceId, SAHPI_OK); if (status == SA_ERR_HPI_INVALID_SESSION) retval = SAF_TEST_PASS; else { e_print(saHpiResourceSeveritySet, SA_ERR_HPI_INVALID_SESSION, status); retval = SAF_TEST_FAIL; } } return (retval); }
int set_resource_tag(SaHpiSessionIdT sessionid) { SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiTextBufferT new_resource_tag; SaHpiTextBufferT old_resource_tag; int rv; SaHpiResourceIdT resource_id; char id_buf[SAHPI_MAX_TEXT_BUFFER_LENGTH], *res_id; char tag_buf[SAHPI_MAX_TEXT_BUFFER_LENGTH], *res_tag; rptentryid = SAHPI_FIRST_ENTRY; rv = SA_OK; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) { printf("Error getting RPT entry: rv = %d\n", rv); return (-1); } printf("Resource Id: %d\n", rptentry.ResourceId); printf("Resource Tag: %s\n", (char *)rptentry.ResourceTag.Data); rptentryid = nextrptentryid; } res_id = NULL; res_tag = NULL; printf("\nResource Id to change: "); res_id = fgets(id_buf, 255, stdin); if ((res_id = strchr(id_buf, '\n')) != NULL) *res_id = '\0'; resource_id = (SaHpiResourceIdT) atoi(id_buf); printf("New Resource Tag: "); res_tag = fgets(tag_buf, SAHPI_MAX_TEXT_BUFFER_LENGTH, stdin); if ((res_tag = strchr(tag_buf, '\n')) != NULL) *res_tag = '\0'; rv = saHpiRptEntryGetByResourceId(sessionid, resource_id, &rptentry); if (rv != SA_OK) { printf("Erro getting RPT entry for resource: %d\n", resource_id); return (-1); } if (rptentry.ResourceEntity.Entry[0].EntityType == SAHPI_ENT_SYS_MGMNT_MODULE) { printf("On some systems, changing the Tag is no allowed\n"); printf("for System Management Modules\n"); printf("Failed to change tag for resource: %d\n", resource_id); return(1); } old_resource_tag = rptentry.ResourceTag; new_resource_tag.DataType = SAHPI_TL_TYPE_ASCII6; new_resource_tag.Language = SAHPI_LANG_ENGLISH; new_resource_tag.DataLength = strlen(tag_buf); memcpy(new_resource_tag.Data, tag_buf, strlen(tag_buf) + 1); rv = saHpiResourceTagSet(sessionid, resource_id, &new_resource_tag); if (rv != SA_OK) { printf("Erro setting custom tag for resource: %d\n", resource_id); return -1; } memset(&rptentry, 0, 0); rv = saHpiRptEntryGetByResourceId(sessionid, resource_id, &rptentry); if (rv != SA_OK) { printf("Erro getting RPT entry for resource: %d\n", resource_id); return (-1); } else { printf("Old resource Tag was: %s, new Tag: %s\n", (char *)old_resource_tag.Data, (char *)rptentry.ResourceTag.Data); } return 0; }
int main(int argc, char **argv) { int c; SaErrorT rv; SaErrorT rvx; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; char input[255], *p; pthread_t discover_thread; void *thread_done; int valid = 0; printf("%s ver %s\n", argv[0], progver); while ((c = getopt(argc, argv, "x?")) != EOF) { switch (c) { case 'x': debug = 1; break; default: printf("Usage: %s [-x]\n", progname); printf(" -x Display 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 (debug) printf("saHpiResourcesDiscover rv = %d\n", rv); restart: rv = saHpiRptInfoGet(sessionid, &rptinfo); if (debug) printf("saHpiRptInfoGet rv = %d\n", rv); printf("RptInfo: UpdateCount = %d, UpdateTime = %lx\n", rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; rvx = SA_OK; while ((rvx == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rvx != SA_OK) printf("RptEntryGet: rv = %d\n", rv); if (rvx == SA_OK && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_RDR) && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA)) { resourceid = rptentry.ResourceId; list_inv(sessionid, resourceid); } rptentryid = nextrptentryid; } printf("Initial discovery done\n"); printf("\tEnter a command or \"help\" for list of commands\n"); printf("Command> "); rv = pthread_create(&discover_thread, NULL, sahpi_discover_thread, (void *)sessionid); if (rv) printf("Error creating event thread\n"); while (!valid) { fflush(stdout); p = fgets(input, 255, stdin); if ((p = strchr(input, '\n')) != NULL) *p = '\0'; if (!strcmp(input, "list_all_inv")) { goto restart; } if (!strcmp(input, "list_inv")) { list_rpt(sessionid); printf("Enter resource id:"); p = fgets(input, 255, stdin); if ((p = strchr(input, '\n')) != NULL) *p = '\0'; list_inv(sessionid, (SaHpiResourceIdT) atoi(input)); } if (!strcmp(input, "set_tag")) { rv = set_resource_tag(sessionid); if (rv) printf("Error setting tag\n"); } if (!strcmp(input, "list_rpt")) { list_rpt(sessionid); } if (!strcmp(input, "help")) { usage(); } if (!strcmp(input, "quit")) { valid = 1; thread = 0; rv = pthread_join(discover_thread, &thread_done); if (rv) printf("Error joining thread\n"); printf("Discovery %s\n", (char *)thread_done); break; } else { printf("Type command (help for list) or \"quit\" to exit\n"); printf("Command> "); } } rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); exit(0); }
SaErrorT populate_saHpiEventLog (SaHpiSessionIdT sessionid) { SaErrorT rv; SaHpiEntryIdT rpt_entry_id; SaHpiEventLogEntryIdT event_entry_id; SaHpiEventLogEntryIdT pre_event_entry_id; SaHpiEventLogEntryT event_log_entry; SaHpiRptEntryT rpt_entry; SaHpiRptEntryT event_rpt_entry; SaHpiRdrT event_rdr_entry; oid evt_log_oid[EVENT_LOG_INDEX_NR]; netsnmp_index evt_log_index; saHpiEventLogTable_context *evt_log_context; DR_XREF *dr_entry; SaHpiDomainIdResourceIdArrayT dr_pair; oid child_oid[MAX_OID_LEN]; size_t child_oid_len; printf( "populate_saHpiEventLog\n"); printf(" ***************************************\n"); printf(" ***************************************\n"); printf(" EVENT LOG TABLES \n"); rpt_entry_id = SAHPI_FIRST_ENTRY; do { rv = saHpiRptEntryGet(sessionid, rpt_entry_id, &rpt_entry_id, &rpt_entry); if (rv != SA_OK) { DEBUGMSGTL ((AGENT, "populate_saHpiEventLog, saHpiRptEntryGet Failed: rv = %d\n",rv)); rv = AGENT_ERR_INTERNAL_ERROR; break; } printf("ResourceId [%d]\n", rpt_entry.ResourceId); event_entry_id = SAHPI_OLDEST_ENTRY; do { rv = saHpiEventLogEntryGet (sessionid, rpt_entry.ResourceId, event_entry_id, &pre_event_entry_id, &event_entry_id, &event_log_entry, &event_rdr_entry, &event_rpt_entry); printf(" Entry ID [%d]\n", event_entry_id); printf(" EventType [%d]\n", event_log_entry.Event.EventType); printf(" rv [%d]\n", rv); if (rv == SA_ERR_HPI_CAPABILITY) { printf ("populate_saHpiEventLog, saHpiEventLogEntryGet() == SA_ERR_HPI_CAPABILITY\n"); DEBUGMSGTL ((AGENT, "populate_saHpiEventLog, saHpiEventLogEntryGet() == SA_ERR_HPI_CAPABILITY\n")); rv = AGENT_ERR_NOERROR; break; } else if (rv == SA_ERR_HPI_NOT_PRESENT) { printf ("populate_saHpiEventLog, saHpiEventLogEntryGet() == SA_ERR_HPI_NOT_PRESENT\n"); DEBUGMSGTL ((AGENT, "populatesaHpiResourcesDiscover_saHpiEventLog, saHpiEventLogEntryGet() == SA_ERR_HPI_NOT_PRESENT\n")); rv = AGENT_ERR_NOERROR; break; } else if (rv != SA_OK) { printf ("populate_saHpiEventLog Failed: rv = %d\n",rv); DEBUGMSGTL ((AGENT, "populate_saHpiEventLog Failed: rv = %d\n",rv)); rv = AGENT_ERR_INTERNAL_ERROR; break; } switch (event_log_entry.Event.EventType) { case SAHPI_ET_RESOURCE: printf("SAHPI_ET_RESOURCE: rv [%d]\n", rv); printf(" Event Type: [%s]\n", oh_lookup_resourceeventtype(event_log_entry.Event.EventDataUnion.ResourceEvent.ResourceEventType)); printf(" Resource: [%d]\n", event_log_entry.Event.Source); printf(" Severity: [%s]\n\n",oh_lookup_severity(event_log_entry.Event.Severity)); populate_saHpiResourceEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); break; case SAHPI_ET_SENSOR: printf("SAHPI_ET_SENSOR: rv [%d]\n", rv); printf(" Sensor Type: [%s]\n\n", oh_lookup_sensortype(event_log_entry.Event.EventDataUnion.SensorEvent.SensorType)); populate_saHpiSensorEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len, &event_rdr_entry); break; case SAHPI_ET_SENSOR_ENABLE_CHANGE: printf("SAHPI_ET_SENSOR_ENABLE_CHANGE: rv [%d]\n\n", rv); populate_saHpiSensorEnableChangeEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); break; case SAHPI_ET_HOTSWAP: printf("SAHPI_ET_HOTSWAP: rv [%d]\n\n", rv); populate_saHpiHotSwapEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); break; case SAHPI_ET_WATCHDOG: printf("SAHPI_ET_WATCHDOG: rv [%d]\n\n", rv); populate_saHpiWatchdogEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); break; case SAHPI_ET_HPI_SW: printf("SAHPI_ET_HPI_SW: rv [%d]\n\n", rv); populate_saHpiSoftwareEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); break; case SAHPI_ET_OEM: printf("SAHPI_ET_OEM: rv [%d]\n\n", rv); populate_saHpiOemEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); break; case SAHPI_ET_USER: printf("SAHPI_ET_USER: rv [%d]\n\n", rv); populate_saHpiUserEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); break; default: printf("********* unknown event type *********\n"); break; } /* BUILD oid for new row */ /* assign the number of indices */ evt_log_index.len = EVENT_LOG_INDEX_NR; /** Index saHpiDomainId is external */ evt_log_oid[0] = get_domain_id(sessionid); /** Index saHpiResourceId is external */ evt_log_oid[1] = rpt_entry.ResourceId; /** Index saHpiEventLogIndex is internal */ dr_pair.domainId_resourceId_arry[0] = get_domain_id(sessionid); dr_pair.domainId_resourceId_arry[1] = rpt_entry.ResourceId; dr_entry = domain_resource_pair_get(&dr_pair, &dr_table); if (dr_entry == NULL) { DEBUGMSGTL ((AGENT, "ERROR: populate_saHpEventLogTable() domain_resource_pair_get returned NULL\n")); return AGENT_ERR_INTERNAL_ERROR; } evt_log_oid[2] = dr_entry->entry_id++; /* assign the indices to the index */ evt_log_index.oids = (oid *) & evt_log_oid; /* See if it exists. */ evt_log_context = NULL; evt_log_context = CONTAINER_FIND (cb.container, &evt_log_index); if (!evt_log_context) { // New entry. Add it evt_log_context = saHpiEventLogTable_create_row ( &evt_log_index); } if (!evt_log_context) { snmp_log (LOG_ERR, "Not enough memory for a EventLog row!"); rv = AGENT_ERR_INTERNAL_ERROR; break; } /** SaHpiEntryId = ASN_UNSIGNED */ evt_log_context->saHpiEventLogIndex = evt_log_oid[2]; /** INTEGER = ASN_INTEGER */ evt_log_context->saHpiEventLogType = event_log_entry.Event.EventType; /** SaHpiTime = ASN_COUNTER64 */ evt_log_context->saHpiEventLogAddedTimestamp = event_log_entry.Timestamp; /** RowPointer = ASN_OBJECT_ID */ evt_log_context->saHpiEventLogRowPointer_len = child_oid_len * sizeof (oid); memcpy (evt_log_context->saHpiEventLogRowPointer, child_oid, evt_log_context->saHpiEventLogRowPointer_len); CONTAINER_INSERT (cb.container, evt_log_context); } while (event_entry_id != SAHPI_NO_MORE_ENTRIES); } while (rpt_entry_id != SAHPI_LAST_ENTRY); /******************************************************/ /* now get the Domain Event Log Info for this session */ /* this is accomplished by using */ /* in saHpiEventLogInfoGet() */ /* SAHPI_UNSPECIFIED_RESOURCE_ID */ /******************************************************/ rv = saHpiEventLogEntryGet (sessionid, SAHPI_UNSPECIFIED_RESOURCE_ID, event_entry_id, &pre_event_entry_id, &event_entry_id, &event_log_entry, &event_rdr_entry, &event_rpt_entry); if (rv == SA_ERR_HPI_NOT_PRESENT) { DEBUGMSGTL ((AGENT, "Domain Event Log Empty\n")); return AGENT_ERR_NOERROR; } if (rv != SA_OK) { DEBUGMSGTL ((AGENT, "getting Domain Event Log Failed: rv = %d\n",rv)); return AGENT_ERR_INTERNAL_ERROR; } printf("SAHPI_ET_DOMAIN: rv [%d]\n\n", rv); populate_saHpiDomainEventLogTable(sessionid, &event_log_entry, child_oid, &child_oid_len); /* BUILD oid for new row */ /* assign the number of indices */ evt_log_index.len = EVENT_LOG_INDEX_NR; /** Index saHpiDomainId is external */ evt_log_oid[0] = get_domain_id(sessionid); /** Index saHpiResourceId is external */ evt_log_oid[1] = SAHPI_UNSPECIFIED_RESOURCE_ID; /** Index saHpiEventLogIndex is internal */ dr_pair.domainId_resourceId_arry[0] = get_domain_id(sessionid); dr_pair.domainId_resourceId_arry[1] = rpt_entry.ResourceId; dr_entry = domain_resource_pair_get(&dr_pair, &dr_table); if (dr_entry == NULL) { DEBUGMSGTL ((AGENT, "ERROR: populate_saHpEventLogTable() domain_resource_pair_get returned NULL\n")); return AGENT_ERR_INTERNAL_ERROR; } evt_log_oid[2] = dr_entry->entry_id++; /* assign the indices to the index */ evt_log_index.oids = (oid *) & evt_log_oid; /* See if it exists. */ evt_log_context = NULL; evt_log_context = CONTAINER_FIND (cb.container, &evt_log_index); if (!evt_log_context) { // New entry. Add it evt_log_context = saHpiEventLogTable_create_row ( &evt_log_index); } if (!evt_log_context) { snmp_log (LOG_ERR, "Not enough memory for a EventLog row!"); rv = AGENT_ERR_INTERNAL_ERROR; } /** SaHpiEntryId = ASN_UNSIGNED */ evt_log_context->saHpiEventLogIndex = evt_log_oid[2]; /** INTEGER = ASN_INTEGER */ evt_log_context->saHpiEventLogType = event_log_entry.Event.EventType; /** SaHpiTime = ASN_COUNTER64 */ evt_log_context->saHpiEventLogAddedTimestamp = event_log_entry.Timestamp; /** RowPointer = ASN_OBJECT_ID */ evt_log_context->saHpiEventLogRowPointer_len = child_oid_len * sizeof (oid); memcpy (evt_log_context->saHpiEventLogRowPointer, child_oid, evt_log_context->saHpiEventLogRowPointer_len); CONTAINER_INSERT (cb.container, evt_log_context); return rv; }
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); }
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); }
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); }
/********************************************************** * Main Function * takes no arguments * * returns: SAF_TEST_PASS when successfull * SAF_TEST_FAIL when an unexpected error occurs *************************************************************/ int main(int argc, char **argv) { SaHpiSessionIdT session, new_session; SaErrorT status; SaHpiDomainInfoT domain_info; SaHpiEntryIdT entry_id, next_entry_id, entry_id_domain2; SaHpiDrtEntryT domain_table_entry; int retval = SAF_TEST_UNKNOWN; SaHpiTextBufferT new_tag, old_tag, old_tag_domain2; SaHpiEntityPathT old_entity_path; SaHpiRptEntryT Report; SaHpiBoolT old_session_open = SAHPI_FALSE; SaHpiBoolT new_session_open = SAHPI_FALSE; SaHpiBoolT found_res = SAHPI_FALSE; SaHpiResourceIdT res_id_domain1; // // Open the session // status = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &session, NULL); if (status != SA_OK) { e_print(saHpiSessionOpen, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { // // Discover Resources // old_session_open = SAHPI_TRUE; // // Get the DRT info // status = saHpiDomainInfoGet(session, &domain_info); if (status != SA_OK) { //Unable to discover e_print(saHpiDomainInfoGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { if (!domain_info.IsPeer) retval = SAF_TEST_NOTSUPPORT; else { status = saHpiDrtEntryGet(session, SAHPI_FIRST_ENTRY, &next_entry_id, &domain_table_entry); if (status != SA_OK) { e_print(saHpiDrtEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } } } } //Get the information of another domain if (retval == SAF_TEST_UNKNOWN) { status = saHpiSessionOpen(domain_table_entry.DomainId, &new_session, NULL); if (status != SA_OK) { e_print(saHpiSessionOpen, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { // // Discover Resources // new_session_open = SAHPI_TRUE; } } //update the resource tag in the first domain if (retval == SAF_TEST_UNKNOWN) { status = saHpiRptEntryGet(session, SAHPI_FIRST_ENTRY, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { old_entity_path = Report.ResourceEntity; old_tag.DataType = Report.ResourceTag.DataType; old_tag.Language = Report.ResourceTag.Language; old_tag.DataLength = Report.ResourceTag.DataLength; memcpy(old_tag.Data, Report.ResourceTag.Data, sizeof(Report.ResourceTag.Data)); res_id_domain1 = Report.ResourceId; //find the exist tag for resource in the 2nd domain while (next_entry_id != SAHPI_LAST_ENTRY) { entry_id = next_entry_id; status = saHpiRptEntryGet(new_session, entry_id, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; break; } else { if (is_entitypath_equal (&Report.ResourceEntity, &old_entity_path)) { found_res = SAHPI_TRUE; entry_id_domain2 = Report.EntryId; old_tag_domain2.DataType = Report.ResourceTag.DataType; old_tag_domain2.Language = Report.ResourceTag.Language; old_tag_domain2.DataLength = Report.ResourceTag. DataLength; memcpy(old_tag_domain2.Data, Report.ResourceTag.Data, sizeof(Report. ResourceTag. Data)); break; } } } if (!found_res) retval = SAF_TEST_FAIL; if (retval == SAF_TEST_UNKNOWN) { memset(&new_tag, 0, sizeof(new_tag)); new_tag.DataType = SAHPI_TL_TYPE_BINARY; new_tag.Language = SAHPI_LANG_ENGLISH; new_tag.DataLength = sizeof(TEST_STR); memcpy(new_tag.Data, TEST_STR, new_tag.DataLength); status = saHpiResourceTagSet(session, res_id_domain1, &new_tag); if (status != SA_OK) { e_print(saHpiResourceTagSet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } } } } //find the resource in the second domain and check whether the resource tag has been changed if (retval == SAF_TEST_UNKNOWN) { status = saHpiRptEntryGet(new_session, entry_id_domain2, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { if (!tag_cmp(&Report.ResourceTag, &old_tag_domain2)) retval = SAF_TEST_PASS; else { m_print ("The resource tag for the resource in the second domain "); m_print ("is different than the resource tag for the resource "); m_print ("in the first domain. They should have been the same!"); retval = SAF_TEST_FAIL; } } } // // Close all the session // if (old_session_open) { status = saHpiSessionClose(session); if (status != SA_OK) { m_print("The old session failed to close properly!"); e_print(saHpiSessionClose, SA_OK, status); } } if (new_session_open) { status = saHpiSessionClose(new_session); if (status != SA_OK) { m_print("The new session failed to close properly!"); e_print(saHpiSessionClose, SA_OK, status); } } return retval; }
int main(int argc, char **argv) { int c, month, day, year; char i_newdate[20]; char i_newtime[20]; int day_array[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; struct tm new_tm_time; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiEventLogEntryIdT entryid; SaHpiTimeT oldtime; SaHpiTimeT newtime; SaHpiTimeT readbacktime; SaHpiTextBufferT buffer; oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"d:t:x")) != EOF ) { switch(c) { case 'd': findate = 1; strcpy(i_newdate, optarg); break; case 't': fintime = 1; strcpy(i_newtime, optarg); break; case 'x': fdebug = 1; break; default: usage(argv); exit(1); } } if ( !findate || !fintime) { usage(argv); exit(1); } if (findate) { if (fdebug) printf("New date to be set: %s\n",i_newdate); if (sscanf(i_newdate,"%2d/%2d/%4d", &month, &day, &year) < 8) { printf("%s: Invalid date\n", argv[0]); } /* check month, day and year for correctness */ if ((month < 1) || (month > 12)) { printf("%s: Month out of range: (%d)\n", argv[0], month); usage(argv); exit(1); }; if (year < 1900) { printf("%s: Year out of range: (%d)\n", argv[0], year); usage(argv); exit(1); }; month--; if (month == 1) { /* if the given year is a leap year */ if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) day_array[1] = 29; }; if ((day < 1) || (day > day_array[month])) { printf("%s: Day out of range: (%d)\n", argv[0], day); usage(argv); exit(1); }; new_tm_time.tm_mon = month; new_tm_time.tm_mday = day; new_tm_time.tm_year = year - 1900; } if (fintime) { if (fdebug) printf("New time to be set: %s\n",i_newtime); if (sscanf(i_newtime,"%2d:%2d:%2d", &new_tm_time.tm_hour, &new_tm_time.tm_min, &new_tm_time.tm_sec) < 6) { printf("%s: Invalid time\n", argv[0]); } /* check hours, minutes and seconds for correctness */ if ((new_tm_time.tm_hour < 0) || (new_tm_time.tm_hour > 24)) { printf("%s: Hours out of range: (%d)\n", argv[0], new_tm_time.tm_hour); usage(argv); exit(1); }; if ((new_tm_time.tm_min < 0) || (new_tm_time.tm_min > 60)) { printf("%s: Minutes out of range: (%d)\n", argv[0], new_tm_time.tm_min); usage(argv); exit(1); }; if ((new_tm_time.tm_sec < 0) || (new_tm_time.tm_sec > 60)) { printf("%s: Seconds out of range: (%d)\n", argv[0], new_tm_time.tm_sec); usage(argv); exit(1); } } if (fdebug) printf("Values passed to mktime():\n\tmon %d\n\tday %d\n\tyear %d\n\tHH %d\n\tMM %d\n\tSS %d\n", new_tm_time.tm_mon, new_tm_time.tm_mday, new_tm_time.tm_year, new_tm_time.tm_hour, new_tm_time.tm_min, new_tm_time.tm_sec); newtime = (SaHpiTimeT) mktime(&new_tm_time) * 1000000000; if (fdebug) printf("New date and time in SaHpiTimeT %lli\n", (long long int)newtime); rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_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", oh_lookup_error(rv)); exit(-1); } rv = saHpiDiscover(sessionid); if (fdebug) printf("saHpiDiscover %s\n", oh_lookup_error(rv)); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv)); printf("DomainInfo: RptUpdateCount = %d, RptUpdateTimestamp = %lx\n", domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp); /* 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", oh_lookup_error(rv)); if ((rv == SA_OK) && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); rv = saHpiEventLogTimeGet(sessionid, resourceid, &oldtime); oh_decode_time(oldtime, &buffer); printf ("\nCurrent event log time on HPI target: %s\n", buffer.Data); printf ("Setting new event log time on HPI target ...\n"); rv = saHpiEventLogTimeSet(sessionid, resourceid, newtime); if (rv != SA_OK) { printf("saHpiEventLogTimeSet %s\n", oh_lookup_error(rv)); } rv = saHpiEventLogTimeGet(sessionid, resourceid, &readbacktime); oh_decode_time(readbacktime, &buffer); printf ("Read-Back-Check event log time: %s\n", buffer.Data); } entryid = SAHPI_OLDEST_ENTRY; rptentryid = nextrptentryid; } rv = saHpiSessionClose(sessionid); return(0); }
int main(int argc, char **argv) { int c, wait = 0; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiSelInfoT info; SaHpiRdrT rdr; SaHpiTimeoutT timeout; SaHpiEventT event; printf("%s: version %s\n",argv[0],progver); while ( (c = getopt( argc, argv,"t:x?")) != EOF ) switch(c) { case 't': ftimer = 1; wait = atoi(optarg); break; case 'x': fdebug = 1; break; default: printf("Usage %s [-tx]\n",argv[0]); printf(" -t <value>:wait <value> seconds for event\n"); printf(" -x :displays eXtra debug messages\n"); exit(1); } if (ftimer) timeout = (SaHpiInt64T)(wait * HPI_NSEC_PER_SEC); else timeout = (SaHpiInt64T) SAHPI_TIMEOUT_IMMEDIATE; 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); printf( "Subscribe to events\n"); rv = saHpiSubscribe( sessionid, (SaHpiBoolT)0 ); if (rv != SA_OK) return rv; /* 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) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); if (!(rptentry.ResourceCapabilities & SAHPI_CAPABILITY_SEL)) { if (fdebug) printf("RPT doesn't have SEL\n"); rptentryid = nextrptentryid; continue; /* no SEL here, try next RPT */ } rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] tag: %s\n", resourceid,rptentry.ResourceTag.Data); /* Using EventLogInfo to build up event queue - for now */ rv = saHpiEventLogInfoGet(sessionid,resourceid,&info); if (fdebug) printf("saHpiEventLogInfoGet %s\n",decode_error(rv)); if (rv == SA_OK) { break; } rptentryid = nextrptentryid; } } printf( "Go and get the event\n"); while (1) { rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry ); if (rv != SA_OK) { if (rv != SA_ERR_HPI_TIMEOUT) { printf( "Error during EventGet - Test FAILED\n"); break; } else { printf( "\n\n****** Time, %d seconds, expired waiting for event.\n", wait); break; } } else { print_event(&event); } } /* Unsubscribe to future events */ printf( "Unsubscribe\n"); rv = saHpiUnsubscribe( sessionid ); rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); exit(0); return(0); }
int show_rpt_list(Domain_t *domain, int as, SaHpiResourceIdT rptid, int addedfields, hpi_ui_print_cb_t proc) /* as : SHOW_ALL_RPT - show all rpt entry only * SHOW_ALL_RDR - show all rdr for all rpt * SHOW_RPT_RDR - show all rdr for rptid * addedfields : SHORT_LSRES - traditional resource list * STATE_LSRES - show resource status * PATH_LSRES - show entity path * return: list size */ { SaHpiRptEntryT rpt_entry; SaHpiEntryIdT rptentryid, nextrptentryid; int ind = 0, show_path; char buf[SHOW_BUF_SZ]; SaErrorT rv; SaHpiCapabilitiesT cap; SaHpiHsCapabilitiesT hscap; SaHpiHsStateT state; rpt_outbuf_t *rpt_out = NULL, *tmp; int res_num = 0, n_rpt = 0, max_rpt = 0; if (as != SHOW_ALL_RPT) show_path = 0; else show_path = addedfields & PATH_LSRES; rptentryid = SAHPI_FIRST_ENTRY; while (rptentryid != SAHPI_LAST_ENTRY) { rv = saHpiRptEntryGet(domain->sessionId, rptentryid, &nextrptentryid, &rpt_entry); if (rv != SA_OK) break; if ((as == SHOW_RPT_RDR) && (rpt_entry.ResourceId != rptid)) { rptentryid = nextrptentryid; continue; }; res_num++; snprintf(buf, SHOW_BUF_SZ, "(%3.3d):", rpt_entry.ResourceId); get_text_buffer_text(NULL, &(rpt_entry.ResourceTag), ":", buf + strlen(buf)); strcat(buf, "{"); cap = rpt_entry.ResourceCapabilities; if (cap & SAHPI_CAPABILITY_SENSOR) strcat(buf, "S|"); if (cap & SAHPI_CAPABILITY_RDR) strcat(buf, "RDR|"); if (cap & SAHPI_CAPABILITY_EVENT_LOG) strcat(buf, "ELOG|"); if (cap & SAHPI_CAPABILITY_INVENTORY_DATA) strcat(buf, "INV|"); if (cap & SAHPI_CAPABILITY_RESET) strcat(buf, "RST|"); if (cap & SAHPI_CAPABILITY_POWER) strcat(buf, "PWR|"); if (cap & SAHPI_CAPABILITY_ANNUNCIATOR) strcat(buf, "AN|"); if (cap & SAHPI_CAPABILITY_FRU) strcat(buf, "FRU|"); if (cap & SAHPI_CAPABILITY_CONTROL) strcat(buf, "CNT|"); if (cap & SAHPI_CAPABILITY_WATCHDOG) strcat(buf, "WTD|"); if (cap & SAHPI_CAPABILITY_MANAGED_HOTSWAP) strcat(buf, "HS|"); if (cap & SAHPI_CAPABILITY_CONFIGURATION) strcat(buf, "CF |"); if (cap & SAHPI_CAPABILITY_AGGREGATE_STATUS) strcat(buf, "AG|"); if (cap & SAHPI_CAPABILITY_EVT_DEASSERTS) strcat(buf, "DS|"); if (cap & SAHPI_CAPABILITY_RESOURCE) strcat(buf, "RES|"); ind = strlen(buf); if (buf[ind - 1] == '|') buf[ind - 1] = 0; strcat(buf, "}"); if (addedfields & STATE_LSRES) { rv = saHpiHotSwapStateGet(domain->sessionId, rpt_entry.ResourceId, &state); hscap = rpt_entry.HotSwapCapabilities; if ((rv == SA_OK) || (hscap != 0)) { strcat(buf, " HS={"); if (rv == SA_OK) strcat(buf, oh_lookup_hsstate(state)); if (hscap & SAHPI_HS_CAPABILITY_AUTOEXTRACT_READ_ONLY) strcat(buf, " RO|"); if (hscap & SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED) strcat(buf, " IND|"); ind = strlen(buf); if (buf[ind - 1] == '|') buf[ind - 1] = 0; strcat(buf, "}"); } }; if (show_path) { if (n_rpt >= max_rpt) { max_rpt += 10; tmp = (rpt_outbuf_t *)malloc(sizeof(rpt_outbuf_t) * max_rpt); memset(tmp, 0, sizeof(rpt_outbuf_t) * max_rpt); if (n_rpt > 0) { memcpy(tmp, rpt_out, sizeof(rpt_outbuf_t) * n_rpt); free(rpt_out); }; rpt_out = tmp; }; tmp = rpt_out + n_rpt; tmp->len_buf = strlen(buf); if (tmp->len_buf > 0) { strcpy(tmp->outbuf, buf); tmp->path = rpt_entry.ResourceEntity; n_rpt++; } } else { strcat(buf, "\n"); if (proc(buf) != HPI_UI_OK) return(res_num); if (as == SHOW_ALL_RDR) show_rdr_list(domain, rpt_entry.ResourceId, SAHPI_NO_RECORD, proc); }; rptentryid = nextrptentryid; }; if (show_path) { print_rpt_paths(rpt_out, n_rpt, proc); free(rpt_out); }; return(res_num); }
int main(int argc, char **argv) { int c, test_fail = 0, wait = 0; char *timeout_str= (char *)NULL; int do_discover_after_subscribe = 0; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiEventLogInfoT info; SaHpiRdrT rdr; SaHpiTimeoutT timeout; SaHpiEventT event; memset(&rptentry, 0, sizeof(rptentry)); printf("%s: version %s\n", argv[0], progver); while ( (c = getopt( argc, argv,"t:xd?")) != EOF ) { switch(c) { case 't': timeout_str = optarg; break; case 'd': do_discover_after_subscribe = 1; break; case 'x': fdebug = 1; break; default: Usage(argv); exit(1); } } if (timeout_str != (char *)NULL) { if ((strcmp(timeout_str, "SAHPI_TIMEOUT_BLOCK") == 0) || (strcmp(timeout_str, "BLOCK") == 0)) { timeout = SAHPI_TIMEOUT_BLOCK; } else { wait = atoi(timeout_str); timeout = (SaHpiTimeoutT)(wait * HPI_NSEC_PER_SEC); } } else timeout = (SaHpiTimeoutT) SAHPI_TIMEOUT_IMMEDIATE; printf("************** timeout:[%lld] ****************\n", timeout); rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_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", oh_lookup_error(rv)); exit(-1); } if (fdebug) printf("saHpiDiscover\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover: %s\n", oh_lookup_error(rv)); exit(-1); } if (fdebug) printf( "Subscribe to events\n"); rv = saHpiSubscribe( sessionid ); if (rv != SA_OK) { printf("saHpiSubscribe: %s\n", oh_lookup_error(rv)); exit(-1); } if (do_discover_after_subscribe) { if (fdebug) printf("saHpiDiscover after saHpiSubscribe\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover after saHpiSubscribe: %s\n", oh_lookup_error(rv)); exit(-1); } } rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv)); printf("DomainInfo: UpdateCount = %d, UpdateTime = %lx\n", domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { printf("**********************************************\n"); rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (fdebug) printf("saHpiRptEntryGet %s\n", oh_lookup_error(rv)); if (rv == SA_OK) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); if ( (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { /* Using EventLogInfo to build up event queue - for now */ rv = saHpiEventLogInfoGet(sessionid, resourceid, &info); if (fdebug) printf("saHpiEventLogInfoGet %s\n", oh_lookup_error(rv)); if (rv == SA_OK) oh_print_eventloginfo(&info, 4); } else { if (fdebug) printf("RPT doesn't have SEL\n"); } rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] tag: %s\n", resourceid, rptentry.ResourceTag.Data); rptentryid = nextrptentryid; } printf("**********************************************\n"); } printf( "Go and get the event\n"); while (1) { rdr.RdrType = SAHPI_NO_RECORD; rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry, NULL); if (rv != SA_OK) { if (rv != SA_ERR_HPI_TIMEOUT) { printf("ERROR during EventGet : %s\n", oh_lookup_error(rv)); test_fail = 1; } else { if (timeout == SAHPI_TIMEOUT_BLOCK) { printf("ERROR: Timeout while infinite wait\n"); test_fail = 1; } else if (timeout != SAHPI_TIMEOUT_IMMEDIATE) { printf("ERROR: Time, %d seconds, expired waiting" " for event\n", wait); test_fail = 1; } } break; } else { oh_print_event(&event, 4); } } if (test_fail == 0) printf(" Test PASS.\n"); else printf(" Test FAILED.\n"); /* Unsubscribe to future events */ if (fdebug) printf( "Unsubscribe\n"); rv = saHpiUnsubscribe( sessionid ); rv = saHpiSessionClose(sessionid); return(0); }
SaErrorT discover_domain(SaHpiDomainIdT domain_id, SaHpiSessionIdT session_id, SaHpiRptEntryT entry) { SaErrorT err; SaHpiRptInfoT rpt_info_before; SaHpiRptInfoT rpt_info_after; SaHpiEntryIdT current; SaHpiEntryIdT next; err = saHpiResourcesDiscover(session_id); if (SA_OK != err) { error("saHpiResourcesDiscover", err); return err; } warn("list_resources: discover done"); /* grab copy of the update counter before traversing RPT */ err = saHpiRptInfoGet(session_id, &rpt_info_before); if (SA_OK != err) { error("saHpiRptInfoGet", err); return err; } warn("Scanning RPT..."); next = SAHPI_FIRST_ENTRY; do { char tmp_epath[128]; current = next; err = saHpiRptEntryGet(session_id, current, &next, &entry); if (SA_OK != err) { if (current != SAHPI_FIRST_ENTRY) { error("saHpiRptEntryGet", err); return err; } else { warn("Empty RPT\n"); break; } } printf("***Records:\n"); printf("%s\n", (char *)entry.ResourceTag.Data); printf("Entry ID: %d\n", (int) entry.EntryId); printf("Resource ID: %d\n", (int) entry.ResourceId); printf("Domain ID: %d\n", (int) entry.DomainId); printf("Revision: %c\n", entry.ResourceInfo.ResourceRev); printf("Version: %c\n", entry.ResourceInfo.SpecificVer); printf("Device Support: %d\n", entry.ResourceInfo.DeviceSupport); printf("Manufacturer ID: %d\n", (int) entry.ResourceInfo.ManufacturerId); printf("Product ID: %d\n", (int) entry.ResourceInfo.ProductId); printf("Firmware Major, Minor, Aux: %d %d %d\n", entry.ResourceInfo.FirmwareMajorRev, entry.ResourceInfo.FirmwareMinorRev, entry.ResourceInfo.AuxFirmwareRev); printf("Severity: %s\n",severity2str(entry.ResourceSeverity)); rpt_cap2str(entry.ResourceCapabilities); printf("Entity Path:\n"); entitypath2string(&entry.ResourceEntity, tmp_epath, sizeof(tmp_epath)); printf("\t%s\n", tmp_epath); printf("\tResourceTag: "); display_textbuffer(entry.ResourceTag); if (entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR) list_rdr(session_id, entry.ResourceId); if (entry.ResourceCapabilities & SAHPI_CAPABILITY_SEL) list_sel(session_id, entry.ResourceId); #if 0 /* if the resource is also a domain, then * traverse its RPT */ if (entry.ResourceCapabilities & SAHPI_CAPABILITY_DOMAIN) { err = discover_domain(entry.DomainId); if (SA_OK != err) return err; } #endif printf("\tEntryId: %d\n", next); } while (next != SAHPI_LAST_ENTRY); printf("SAHPI_LAST_ENTRY\n"); /* wait for update in RPT */ while (1) { err = saHpiRptInfoGet(session_id, &rpt_info_after); if (SA_OK != err) { error("saHpiRptInfoGet", err); return err; } if (rpt_info_before.UpdateCount != rpt_info_after.UpdateCount) { rpt_info_before = rpt_info_after; } else break; }; return SA_OK; }
int main(int argc, char **argv) { SaErrorT err; SaHpiRdrT rdr; SaHpiEntryIdT rptid, next_rptid; SaHpiRptEntryT rpt; SaHpiResourceIdT chassis_rid=0; SaHpiSelEntryT logentry; SaHpiSelEntryIdT prev_logid, next_logid; SaHpiSessionIdT sessionid; SaHpiVersionT hpiVer; char *hash_key, *logstr; SnmpMibInfoT *hash_value; /* Setup Infra-structure */ err = saHpiInitialize(&hpiVer); if (err != SA_OK) { printf("Error! saHpiInitialize: err=%d\n", err); return -1; } err = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID, &sessionid, NULL); if (err != SA_OK) { printf("Error! saHpiSessionOpen: err=%d\n", err); return -1; } err = saHpiResourcesDiscover(sessionid); if (err != SA_OK) { printf("Error! saHpiResourcesDiscover: err=%d\n", err); return -1; } /* Find first SEL capable Resource - assume its the chassis */ rptid = SAHPI_FIRST_ENTRY; while ((err == SA_OK) && (rptid != SAHPI_LAST_ENTRY)) { err = saHpiRptEntryGet(sessionid, rptid, &next_rptid, &rpt); if (err != SA_OK) { printf("Error! saHpiRptEntryGet: err=%d\n", err); return -1; } if ((rpt.ResourceCapabilities & SAHPI_CAPABILITY_SEL)) { chassis_rid = rpt.ResourceId; break; } else { rptid = next_rptid; continue; } } if (chassis_rid == 0) { printf("Error! saHpiRptEntryGet couldn't find SEL RID\n"); return -1; } /* If test OID not already in sim hash table; create it */ if (!g_hash_table_lookup_extended(sim_hash, ERROR_LOG_MSG_OID, (gpointer)&hash_key, (gpointer)&hash_value)) { hash_key = g_strdup(ERROR_LOG_MSG_OID); if (!hash_key) { printf("Error: Cannot allocate memory for oid key=%s\n", ERROR_LOG_MSG_OID); return -1; } hash_value = g_malloc0(sizeof(SnmpMibInfoT)); if (!hash_value) { printf("Cannot allocate memory for hash value for oid=%s", ERROR_LOG_MSG_OID); return -1; } } printf("Calling Clear\n"); err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } printf("Calling EntryGet\n"); /************************************************************ * TestCase - Mapped Chassis Event (EN_CUTOFF_HI_FAULT_3_35V) * Event recovered in next testcase ************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:System shutoff due to +3.3v over voltage. Read value 3.5 Threshold value 3.4"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((logentry.Event.Source == chassis_rid) && (logentry.Event.EventType == SAHPI_ET_SENSOR) && (logentry.Event.Severity == SAHPI_CRITICAL) && (logentry.Event.EventDataUnion.SensorEvent.SensorType == SAHPI_VOLTAGE) && (logentry.Event.EventDataUnion.SensorEvent.Assertion == SAHPI_TRUE) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_CRIT) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MINOR) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState == SAHPI_ES_UNSPECIFIED) && (logentry.Event.EventDataUnion.SensorEvent.TriggerReading.Interpreted.Value.SensorFloat32 == (float)3.5) && (logentry.Event.EventDataUnion.SensorEvent.TriggerThreshold.Interpreted.Value.SensorFloat32 == (float)3.4))) { printf("Error! TestCase - Mapped Chassis Event (EN_CUTOFF_HI_FAULT_3_35V)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************************************* * TestCase - Chassis Recovery Event (EN_CUTOFF_HI_FAULT_3_35V) * Recover event in previous testcase *************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:Recovery System shutoff due to +3.3v over voltage. Read value 3.5 Threshold value 3.4"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((logentry.Event.Source == chassis_rid) && (logentry.Event.EventType == SAHPI_ET_SENSOR) && (logentry.Event.Severity == SAHPI_CRITICAL) && (logentry.Event.EventDataUnion.SensorEvent.SensorType == SAHPI_VOLTAGE) && (logentry.Event.EventDataUnion.SensorEvent.Assertion == SAHPI_FALSE) && (!(logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_CRIT)) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MINOR) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState & SAHPI_ES_UPPER_CRIT) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState & SAHPI_ES_UPPER_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState & SAHPI_ES_UPPER_MINOR) && (logentry.Event.EventDataUnion.SensorEvent.TriggerReading.Interpreted.Value.SensorFloat32 == (float)3.5) && (logentry.Event.EventDataUnion.SensorEvent.TriggerThreshold.Interpreted.Value.SensorFloat32 == (float)3.4))) { printf("Error! TestCase - Chassis Recovery Event (EN_CUTOFF_HI_FAULT_3_35V)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************************************* * TestCase - Chassis Duplicate Event ( EN_PFA_HI_FAULT_3_35V) * Previous state check depends on previous testcase! *************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:System over recommended voltage on +3.3v. Read value 3.5 Threshold value 3.4"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((logentry.Event.Source == chassis_rid) && (logentry.Event.EventType == SAHPI_ET_SENSOR) && (logentry.Event.Severity == SAHPI_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.SensorType == SAHPI_VOLTAGE) && (logentry.Event.EventDataUnion.SensorEvent.Assertion == SAHPI_TRUE) && (!(logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_CRIT)) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MINOR) && (!(logentry.Event.EventDataUnion.SensorEvent.PreviousState & SAHPI_ES_UPPER_CRIT)) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState & SAHPI_ES_UPPER_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState & SAHPI_ES_UPPER_MINOR) && (logentry.Event.EventDataUnion.SensorEvent.TriggerReading.Interpreted.Value.SensorFloat32 == (float)3.5) && (logentry.Event.EventDataUnion.SensorEvent.TriggerThreshold.Interpreted.Value.SensorFloat32 == (float)3.4))) { printf("Error! TestCase - Chassis Duplicate Event ( EN_PFA_HI_FAULT_3_35V)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************************************* * TestCase - Blade Duplicate Event ( EN_PFA_HI_FAULT_3_35V) * Same as previous testcase only for the blade not chassis *************************************************************/ logstr = "Severity:INFO Source:BLADE_10 Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:System over recommended voltage on +3.3v. Read value 3.5 Threshold value 3.4"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((!(logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_SENSOR) && (logentry.Event.Severity == SAHPI_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.SensorType == SAHPI_VOLTAGE) && (logentry.Event.EventDataUnion.SensorEvent.Assertion == SAHPI_TRUE) && (!(logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_CRIT)) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MINOR) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState == SAHPI_ES_UNSPECIFIED) && (logentry.Event.EventDataUnion.SensorEvent.TriggerReading.Interpreted.Value.SensorFloat32 == (float)3.5) && (logentry.Event.EventDataUnion.SensorEvent.TriggerThreshold.Interpreted.Value.SensorFloat32 == (float)3.4))) { printf("Error! TestCase - Blade Duplicate Event ( EN_PFA_HI_FAULT_3_35V)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************************************* * TestCase - Non-mapped Event (Severity=INFO) *************************************************************/ logstr = "Severity:INFO Source:BLADE_01 Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:Bogus message not in string to event table"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((!(logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_OEM) && (logentry.Event.Severity == SAHPI_INFORMATIONAL))) { printf("Error! TestCase - Non-mapped Event (Severity=INFO)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /* Better to test a mapped login event - don't have one yet */ /************************************************************* * TestCase - Non-mapped Login Event (Severity=WARN) *************************************************************/ logstr = "Severity:WARN Source:SWITCH_4 Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:Bogus login message Login ID:\'\'myid\' @ someaddress\'"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((!(logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_OEM) && (logentry.Event.Severity == SAHPI_MINOR))) { printf("Error! TestCase - Non-mapped Login Event (Severity=WARN)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************************************ * TestCase - Daughter Card Event (EN_PFA_HI_OVER_TEMP_DASD1) ************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:BSE Option over recommended temperature."; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((!(logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_SENSOR) && (logentry.Event.Severity == SAHPI_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.SensorType == SAHPI_TEMPERATURE) && (logentry.Event.EventDataUnion.SensorEvent.Assertion == SAHPI_TRUE) && (!(logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_CRIT)) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MAJOR) && (logentry.Event.EventDataUnion.SensorEvent.EventState & SAHPI_ES_UPPER_MINOR) && (logentry.Event.EventDataUnion.SensorEvent.PreviousState == SAHPI_ES_UNSPECIFIED) && (logentry.Event.EventDataUnion.SensorEvent.TriggerReading.Interpreted.Value.SensorFloat32 == (float)0) && (logentry.Event.EventDataUnion.SensorEvent.TriggerThreshold.Interpreted.Value.SensorFloat32 == (float)0))) { printf("Error! TestCase - Daughter Card Event (EN_PFA_HI_OVER_TEMP_DASD1)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************************************* * TestCase - Hot-swap switch installed (EN_SWITCH_3_INSTALLED) *************************************************************/ logstr = "Severity:INFO Source:SWITCH_3 Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:I/O module 3 was installed."; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((!(logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_HOTSWAP) && (logentry.Event.Severity == SAHPI_INFORMATIONAL) && (logentry.Event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_ACTIVE_HEALTHY) && (logentry.Event.EventDataUnion.HotSwapEvent.PreviousHotSwapState == SAHPI_HS_STATE_ACTIVE_HEALTHY))) { printf("Error! TestCase - Hot-swap switch installed (EN_SWITCH_3_INSTALLED)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /**************************************************************** * TestCase - Hot-swap Media Tray removal (EN_MEDIA_TRAY_REMOVED) * This event is recovered in the next testcase ****************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:The media tray was removed."; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((!(logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_HOTSWAP) && (logentry.Event.Severity == SAHPI_INFORMATIONAL) && (logentry.Event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_NOT_PRESENT) && (logentry.Event.EventDataUnion.HotSwapEvent.PreviousHotSwapState == SAHPI_HS_STATE_ACTIVE_HEALTHY))) { printf("Error! TestCase - Hot-swap Media Tray removal (EN_MEDIA_TRAY_REMOVED)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /**************************************************************** * TestCase - Hot-swap Media Tray recovery (EN_MEDIA_TRAY_REMOVED) * Recovery of previous event ****************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:Recovery The media tray was removed."; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!((!(logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_HOTSWAP) && (logentry.Event.Severity == SAHPI_INFORMATIONAL) && (logentry.Event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_ACTIVE_HEALTHY) && (logentry.Event.EventDataUnion.HotSwapEvent.PreviousHotSwapState == SAHPI_HS_STATE_NOT_PRESENT))) { printf("Error! TestCase - Hot-swap Media Tray recovery (EN_MEDIA_TRAY_REMOVED)\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************ * Drive some error paths in the code ************************************/ /****************************************************************** * TestCase - Bogus threshold strings ******************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:System shutoff due to +3.3v over voltage. Bogus Read value 3.5 Bogus Threshold value 3.4"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!(((logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_OEM) && (logentry.Event.Severity == SAHPI_INFORMATIONAL))) { printf("Error! TestCase - Bogus threshold strings\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /****************************************************************** * TestCase - Recovery string not first character of text string * (blank is first character). Should not treat as a recovery event ******************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text: Recovery System shutoff due to +3.3v over voltage. Read value 3.5 Threshold value 3.4"; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!(((logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_OEM) && (logentry.Event.Severity == SAHPI_INFORMATIONAL))) { printf("Error! TestCase - Recovery string not first character of text string\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /****************************************************************** * TestCase - In string table but not mapped * Uses special defined Test event in bc_str2event.c ******************************************************************/ logstr = "Severity:INFO Source:SERVPROC Name:WMN315702424 Date:10/11/03 Time:09:09:46 Text:Bogus Test Event."; memset(&logentry, 0 , sizeof(SaHpiSelEntryT)); strcpy(hash_value->value.string, logstr); g_hash_table_insert(sim_hash, hash_key, hash_value); err = saHpiEventLogEntryGet(sessionid, chassis_rid, SAHPI_NEWEST_ENTRY, &prev_logid, &next_logid, &logentry, &rdr, &rpt); if (err != SA_OK) { printf("Error! saHpiEventLogEntryGet: line=%d; err=%d\n", __LINE__, err); return -1; } /* Check expected values */ if (!(((logentry.Event.Source == chassis_rid)) && (logentry.Event.EventType == SAHPI_ET_OEM) && (logentry.Event.Severity == SAHPI_INFORMATIONAL))) { printf("Error! TestCase - In string table but not mapped\n"); print_event(&(logentry.Event)); return -1; } err = saHpiEventLogClear(sessionid, chassis_rid); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /****************** * End of testcases ******************/ err = saHpiSessionClose(sessionid); if (err != SA_OK) { printf("Error! saHpiSessionClose: err=%d\n", err); return -1; } err = saHpiFinalize(); if (err != SA_OK) { printf("Error! saHpiFinalize: err=%d\n", err); return -1; } return 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); }
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); }
SaErrorT show_event_log(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid, int show_short, hpi_ui_print_cb_t proc) { SaErrorT rv = SA_OK; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEventLogInfoT info; SaHpiEventLogEntryIdT entryid; SaHpiEventLogEntryIdT nextentryid; SaHpiEventLogEntryIdT preventryid; SaHpiEventLogEntryT sel; SaHpiRdrT rdr; char buf[1024]; char date[30], date1[30]; rptentryid = SAHPI_FIRST_ENTRY; while (rptentryid != SAHPI_LAST_ENTRY) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) { snprintf(buf, 1024, "ERROR: saHpiRptEntryGet error = %s\n", oh_lookup_error(rv)); proc(buf); return rv; }; if (rptentry.ResourceId == resourceid) { if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG) break; else { proc("ERROR: The designated resource hasn't SEL.\n"); return rv; } }; rptentryid = nextrptentryid; } if (rptentryid == SAHPI_LAST_ENTRY) { snprintf(buf, 1024, "ERROR: no resource for resourceId = %d\n", resourceid); proc(buf); return rv; } rv = saHpiEventLogInfoGet(sessionid, resourceid, &info); if (rv != SA_OK) { snprintf(buf, 1024, "ERROR: saHpiEventLogInfoGet error = %s\n", oh_lookup_error(rv)); proc(buf); return -1; } snprintf(buf, 1024, "EventLog: entries = %d, size = %d, enabled = %d\n", info.Entries, info.Size, info.Enabled); proc(buf); time2str(info.UpdateTimestamp, date, 30); time2str(info.CurrentTime, date1, 30); snprintf(buf, 1024, "UpdateTime = %s CurrentTime = %s Overflow = %d\n", date, date1, info.OverflowFlag); proc(buf); if (info.Entries != 0){ entryid = SAHPI_OLDEST_ENTRY; while (entryid != SAHPI_NO_MORE_ENTRIES) { rv = saHpiEventLogEntryGet(sessionid, resourceid, entryid, &preventryid, &nextentryid, &sel, &rdr, NULL); if (rv != SA_OK) { snprintf(buf, 1024, "ERROR: saHpiEventLogEntryGet error = %s\n", oh_lookup_error(rv)); proc(buf); return -1; }; if (show_short) show_short_event(&(sel.Event)); else oh_print_eventlogentry(&sel, 1); preventryid = entryid; entryid = nextentryid; } } else { snprintf(buf, 1024, "SEL is empty\n"); proc(buf); }; return SA_OK; }
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; }