int open_session() { SaErrorT rv; SaHpiVersionT hpiVer; rv = saHpiInitialize(&hpiVer); if (rv != SA_OK) { printf("saHpiInitialize error %d\n", rv); return -1; } rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID, &sessionid, NULL); if (rv != SA_OK) { printf("saHpiSessionOpen error %d\n", rv); return -1; } rv = saHpiResourcesDiscover(sessionid); if (rv != SA_OK) printf("saHpiResourcesDiscover rv = %d\n", rv); printf("Initial discovery done\n"); printf("\tEnter a command or \"help\" for list of commands\n"); pthread_create(&ge_thread, NULL, get_event, NULL); return 0; }
int getSaHpiSession (SaHpiSessionIdT * out) { SaHpiVersionT version; DEBUGMSGTL ((AGENT, "--- getSaHpiSession: Entry. ")); if (session_avail == AGENT_FALSE) { err = saHpiInitialize (&version); if (SA_OK != err) { snmp_log (LOG_ERR, "saHpiInitialize error: %s\n", get_error_string (err)); return AGENT_ERR_INIT; } err = saHpiSessionOpen (SAHPI_DEFAULT_DOMAIN_ID, &session_id, NULL); if (SA_OK != err) { snmp_log (LOG_ERR, "saHpiSessionOpen error: %s\n", get_error_string (err)); return AGENT_ERR_SESSION_OPEN; } err = saHpiSubscribe (session_id, SAHPI_FALSE); if (SA_OK != err) { snmp_log (LOG_ERR, "saHpiSubscribe failed. error: %s\n", get_error_string (err)); return AGENT_ERR_SUBSCRIBE; } session_avail = AGENT_TRUE; //Subscribe to the Events } rediscover_count--; if (rediscover_count <= 0) { // Re-set the rediscover_count; DEBUGMSGTL ((AGENT, "Calling 'saHpiResourceDiscover()'.\n")); rediscover_count = REDISCOVER_COUNT_MAX; err = saHpiResourcesDiscover (session_id); if (SA_OK != err) { snmp_log (LOG_ERR, "saHpiResourcesDiscover error: %s\n", get_error_string (err)); return AGENT_ERR_DISCOVER; } } if (out) *out = session_id; DEBUGMSGTL ((AGENT, "--- getSaHpiSession: Exit\n")); return AGENT_ERR_NOERROR; }
void *sahpi_discover_thread(void *sessionid) { int rv; struct timeval to; while (thread == 1) { rv = saHpiResourcesDiscover((SaHpiSessionIdT) sessionid); if (rv != SA_OK) printf("discovery failed\n"); to.tv_sec = 3; /*check everything 3 seconds */ to.tv_usec = 0; select(0, 0, NULL, NULL, &to); } pthread_exit("Thread exit\n"); }
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 { 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); if (entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR) list_rdr(session_id, entry.ResourceId); 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) { 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); }
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); }
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 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; }
void cHpiResourceRoot::discoverResources() { SaErrorT err = saHpiResourcesDiscover( theApp->m_session_id ); if ( err != SA_OK ) { theApp->LogError( "saHpiResourcesDiscover: ", err ); return; } unmark(); SaHpiEntryIdT next = SAHPI_FIRST_ENTRY; do { SaHpiEntryIdT current = next; SaHpiRptEntryT entry; err = saHpiRptEntryGet( theApp->m_session_id, current, &next, &entry ); if ( err != SA_OK ) { if ( current != SAHPI_FIRST_ENTRY ) { theApp->LogError( "saHpiRptEntryGet: ", err ); return; } theApp->Log( "Empty RPT !\n" ); break; } // create entity path cHpiItem *parent = createEntityPath( entry.ResourceEntity ); SaHpiEntityT *e = &entry.ResourceEntity.Entry[0]; QString name = QString( "%1 %2" ) .arg( hpiEntityType2String( e->EntityType ) ) .arg( e->EntityInstance ); // create rpt entry cHpiItem *item = parent->findChild( name ); if ( !item ) item = new cHpiResourceRptItem( parent, name, *e, entry ); item->mark(); parent = item; // create rdr if ( entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR ) { SaHpiEntryIdT next_rdr = SAHPI_FIRST_ENTRY; while ( next_rdr != SAHPI_LAST_ENTRY ) { SaHpiEntryIdT current_rdr = next_rdr; SaHpiRdrT rdr; err = saHpiRdrGet( theApp->m_session_id, entry.ResourceId, current_rdr, &next_rdr, &rdr ); if ( err != SA_OK ) { if ( current_rdr == SAHPI_FIRST_ENTRY ) theApp->Log( "empty RDR table !\n" ); else theApp->LogError( "saHpiRdrGet: ", err ); break; } parent = createEntityPath( rdr.Entity, 0 ); char str[257]; memcpy( str, rdr.IdString.Data, 256 ); str[rdr.IdString.DataLength] = 0; name = QString( "%1 %2" ) .arg( str ) .arg( rdr.RecordId ); item = parent->findChild( name ); if ( !item ) { if ( rdr.RdrType == SAHPI_INVENTORY_RDR ) { cHpiResourceRdrInventory *inv = new cHpiResourceRdrInventory( parent, name, rdr ); item = inv; SaHpiInventoryDataT *d = (SaHpiInventoryDataT *)inv->m_inventory; err = saHpiEntityInventoryDataRead( theApp->m_session_id, entry.ResourceId, rdr.RdrTypeUnion.InventoryRec.EirId, dMaxInventorySize, d, &inv->m_size ); if ( err ) theApp->LogError( "saHpiEntityInventoryDataRead: ", err ); else if ( d->Validity != SAHPI_INVENT_DATA_VALID ) theApp->Log( "saHpiEntityInventoryDataRead: data not valid" ); else { for( int i = 0; d->DataRecords[i]; i++ ) { SaHpiInventDataRecordT *r = d->DataRecords[i]; cHpiItem *iv = 0; switch( r->RecordType ) { case SAHPI_INVENT_RECTYPE_INTERNAL_USE: iv = new cHpiResourceInventoryInternalUse( item, "InternalUse", &r->RecordData.InternalUse ); break; case SAHPI_INVENT_RECTYPE_CHASSIS_INFO: iv = new cHpiResourceInventoryChassis( item, "Chassis", &r->RecordData.ChassisInfo ); break; case SAHPI_INVENT_RECTYPE_BOARD_INFO: iv = new cHpiResourceInventoryBoard( item, "Board", &r->RecordData.BoardInfo ); break; case SAHPI_INVENT_RECTYPE_PRODUCT_INFO: iv = new cHpiResourceInventoryProduct( item, "Product", &r->RecordData.ProductInfo ); break; case SAHPI_INVENT_RECTYPE_OEM: iv = new cHpiResourceInventoryOem( item, "Oem", &r->RecordData.OemData ); break; } iv->mark(); } } } else item = new cHpiResourceRdr( parent, name, rdr ); } else item->markDown(); item->mark(); } } } while( next != SAHPI_LAST_ENTRY ); deleteUnmark(); }
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) { SaErrorT err; SaHpiRdrT rdr; SaHpiRptEntryT rpt; 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; } /* 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; } } err = saHpiEventLogClear(sessionid, SAHPI_DEFAULT_DOMAIN_ID); if (err != SA_OK) { printf("Error! saHpiEventLogClear: line=%d; err=%d\n", __LINE__, err); return -1; } /************************************************************ * 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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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 rsa_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, SAHPI_DEFAULT_DOMAIN_ID, 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, SAHPI_DEFAULT_DOMAIN_ID); 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; }
int main(int argc, char **argv) { SaHpiInt32T ComputerNumber; //0..n-1 SaHpiInt32T SelectedSystem; //0..n-1 SaHpiHsPowerStateT Action; COMPUTER_DATA *ComputerPtr; SaHpiBoolT BladeSelected; SaHpiBoolT MultipleBlades; SaHpiBoolT ActionSelected; SaHpiBoolT PrintUsage; SaHpiBoolT DebugPrints; GSList* Computer; GSList* ComputerListHead; int option; SaHpiSessionIdT SessionId; SaErrorT Status, Clean_Up_Status; SaHpiEntryIdT RptEntry, RptNextEntry; SaHpiRptEntryT Report; SaHpiInt32T Index, EntityElement; SaHpiHsPowerStateT PowerState; char PowerStateString[3][7]={"off\0","on\0","cycled\0"}; SaHpiVersionT HpiVersion; /* // Print out the Program name and Version */ PROGRAM_HEADER; /* Set Program Defaults */ ComputerNumber = 0; SelectedSystem = 0; Action = 255; //set it out of range to stand for status BladeSelected = FALSE; MultipleBlades = FALSE; ActionSelected = FALSE; PrintUsage = FALSE; DebugPrints = FALSE; RptEntry = SAHPI_FIRST_ENTRY; /* Parse out option instructions */ while (1) { option = getopt(argc, argv, "dpruxb:"); if ((option == EOF) || (PrintUsage == TRUE)) { break; //break out of the while loop } switch (option) { case 'd': Action = SAHPI_HS_POWER_OFF; ActionSelected = TRUE; break; case 'p': Action = SAHPI_HS_POWER_ON; ActionSelected = TRUE; break; case 'r': Action = SAHPI_HS_POWER_CYCLE; ActionSelected = TRUE; break; case 'u': BladeSelected = TRUE; ActionSelected = TRUE; break; case 'x': DebugPrints = TRUE; break; case 'b': if (*optarg == 0) { PrintUsage = TRUE; break; //no argument } SelectedSystem = atoi(optarg) - 1; //Normalizing to 0...n-1 if ((SelectedSystem > MAX_MANAGED_SYSTEMS) || (SelectedSystem < 0)) { //Argument is out of Range PrintUsage = TRUE; } BladeSelected = TRUE; break; default: PrintUsage = TRUE; break; } //end of switch statement } //end of argument parsing while loop if (PrintUsage == TRUE) { UsageMessage(PrgName); /*BUG: what is the exit code for bad argument?*/ exit(0); //When we exit here, there is nothing to clean up } /* Initialize the first of a list of computers */ HPI_POWER_DEBUG_PRINT("1.0 Initializing the List Structure for the computers\n"); Computer = g_slist_alloc(); ComputerListHead = Computer; HPI_POWER_DEBUG_PRINT("1.1 Allocating space for the information on each computer\n"); ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA)); Computer->data = (gpointer)ComputerPtr; /* Initialize HPI domain and session */ HPI_POWER_DEBUG_PRINT("2.0 Initalizing HPI\n"); Status = saHpiInitialize(&HpiVersion); if (Status == SA_OK) { HPI_POWER_DEBUG_PRINT("2.1 Initalizing HPI Session\n"); Status = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID, &SessionId, NULL); } if (Status == SA_OK) { /* Find all of the individual systems */ // regenerate the Resource Presence Table(RPT) HPI_POWER_DEBUG_PRINT("2.2 Hpi Discovery\n"); Status = saHpiResourcesDiscover(SessionId); } HPI_POWER_DEBUG_PRINT("3.0 Walking through all of the Report Tables\n"); while ((Status == SA_OK) && (RptEntry != SAHPI_LAST_ENTRY)) { HPI_POWER_DEBUG_PRINT("@"); Status = saHpiRptEntryGet(SessionId, RptEntry, &RptNextEntry, &Report); RptEntry = RptNextEntry; // Blades will have the first Element of the Entity Path set to SBC_BLADE EntityElement = 0; HPI_POWER_DEBUG_PRINT("."); if (Report.ResourceEntity.Entry[EntityElement].EntityType == SAHPI_ENT_SBC_BLADE) { HPI_POWER_DEBUG_PRINT("#"); // We have found a Blade ComputerPtr->ResID = Report.ResourceId; /* enumerate this list as created */ ComputerPtr->number = ComputerNumber; ComputerNumber++; ComputerPtr->Instance = Report.ResourceEntity.Entry[EntityElement].EntityLocation; // find a Name string for this blade sprintf(ComputerPtr->NameStr, "%s %d", (char*)Report.ResourceTag.Data, (int) ComputerPtr->Instance); // Create a new allocation for another system ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA)); // Add another member to the list Computer = g_slist_append(Computer,(gpointer)ComputerPtr); // set a flag that we are working with blades MultipleBlades = TRUE; } } HPI_POWER_DEBUG_PRINT("\n4.0 Generating Listing of options to choose from:\n"); /* If parsed option does not select blade and more than one is found */ if ((MultipleBlades == TRUE) && (BladeSelected == FALSE) && (Status == SA_OK)) { HPI_POWER_DEBUG_PRINT("4.1 Printing out a listing of all the blades\n"); for (Index = 0; Index < ComputerNumber; Index++) { HPI_POWER_DEBUG_PRINT("$"); // obtain the information for this computer ComputerPtr = g_slist_nth_data(ComputerListHead, Index); if (ComputerPtr == NULL) { printf("Call returned a NULL\n"); break; } // retrieve the power status for this computer HPI_POWER_DEBUG_PRINT("%%"); PowerState = 0; Status = saHpiResourcePowerStateGet(SessionId, ComputerPtr->ResID, &PowerState); if (Status != SA_OK) { printf("%s does not support PowerStateGet", ComputerPtr->NameStr); } /* Print out all of the systems */ printf("%2d) %20s - %s \n\r", (Index + 1), ComputerPtr->NameStr, PowerStateString[PowerState]); } /* Prompt user to select one */ while ((Index >= ComputerNumber) || (Index < 0)) { printf("\nEnter the number for the desired blade: "); scanf("%d",&Index); Index--; //normalize to 0..n-1 printf("\n"); } BladeSelected = TRUE; SelectedSystem = Index; } HPI_POWER_DEBUG_PRINT("4.2 Generating Listing of Actions to choose from\n"); /* If action is not selected */ if ((ActionSelected == FALSE) && (Status == SA_OK)) { /* prompt user to select an action */ printf("\nSelect Action: 0 - Off; 1 - On; 2 - Reset; 3 - Status \n\r"); printf("Enter a number 0 to 3: "); scanf("%d", &Index); switch (Index) { case 0: Action = SAHPI_HS_POWER_OFF; break; case 1: Action = SAHPI_HS_POWER_ON; break; case 2: Action = SAHPI_HS_POWER_CYCLE; break; default: Action = 255; //Out of Range for "Status" break; } } /* execute the command */ if (Status == SA_OK) { HPI_POWER_DEBUG_PRINT("5.0 Executing the command\n\r"); // obtain the information for this computer ComputerPtr = g_slist_nth_data(ComputerListHead, SelectedSystem); if (Action <= SAHPI_HS_POWER_CYCLE) { HPI_POWER_DEBUG_PRINT("5.1 Setting a New Power State\n\r"); // Set the new power status for this computer Status = saHpiResourcePowerStateSet(SessionId, ComputerPtr->ResID, Action); /* return status */ if (Status == SA_OK) { printf("\n%s -- %20s has been successfully powered %s\n", PrgName, ComputerPtr->NameStr, PowerStateString[Action]); } } else // Report Power status for the system { HPI_POWER_DEBUG_PRINT("5.2 Getting the Power Status\n\r"); // retrieve the power status for this computer PowerState = 0; Status = saHpiResourcePowerStateGet(SessionId, ComputerPtr->ResID, &PowerState); if (Status != SA_OK) { printf("%s does not support PowerStateGet", ComputerPtr->NameStr); } /* Print out Status for this system */ printf("%2d) %20s - %s \n\r", (ComputerPtr->number + 1), ComputerPtr->NameStr, PowerStateString[PowerState]); } } HPI_POWER_DEBUG_PRINT("6.0 Clean up"); /* clean up */ Clean_Up_Status = saHpiSessionClose(SessionId); Clean_Up_Status = saHpiFinalize(); //Free all of the Allocations for the Computer data Computer = ComputerListHead; while (Computer != NULL) { free(Computer->data); Computer = g_slist_next(Computer); } //Free the whole List g_slist_free(ComputerListHead); /* return status code and exit */ if (Status != SA_OK) { HPI_POWER_DEBUG_PRINT("7.0 Reporting Bad Status"); AppHpiPrintError(Status, PrgName); } return(Status); }
int main(int argc, char **argv) { int prodrecindx=0; int asset_len=0; int c; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiEirIdT eirid; printf("%s ver %s\n",argv[0],progver); while ( (c = getopt( argc, argv,"a:xz?")) != EOF ) switch(c) { case 'z': fxdebug = 1; /* fall thru to include next setting */ case 'x': fdebug = 1; break; case 'a': fasset = 1; if (optarg) { asset_tag = (char *)strdup(optarg); asset_len = strlen(optarg); } /* printf( "String Length = %d\n", asset_len); printf( "String Length = %d\n", strlen(optarg)); */ break; default: printf("Usage: %s [-x] [-a asset_tag]\n", progname); printf(" -a Sets the asset tag\n"); printf(" -x Display debug messages\n"); printf(" -z Display extra debug messages\n"); exit(1); } inv = (SaHpiInventoryDataT *)(void *)&inbuff[0]; 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 = %x, 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) printf("RptEntryGet: rv = %d\n",rv); 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_INVENTORY_RDR) { /*type 3 includes inventory records*/ eirid = rdr.RdrTypeUnion.InventoryRec.EirId; rdr.IdString.Data[rdr.IdString.DataLength] = 0; if (fdebug) printf( "RDR[%d]: type=%d num=%d %s\n", rdr.RecordId, rdr.RdrType, eirid, rdr.IdString.Data); buffersize = sizeof(inbuff); if (fdebug) printf("BufferSize=%d InvenDataRecSize=%zd\n", buffersize, sizeof(inbuff)); if ( IsTagBmc(rdr.IdString.Data, rdr.IdString.DataLength) ) { rv = saHpiEntityInventoryDataRead( sessionid, resourceid, eirid, buffersize, inv, &actualsize); if (fxdebug) printf( "saHpiEntityInventoryDataRead[%d] rv = %d\n", eirid, rv); if (fdebug) printf("ActualSize=%d\n", actualsize); if (rv == SA_OK) { /* Walk thru the list of inventory data */ for (i=0; inv->DataRecords[i] != NULL; i++) { if (inv->Validity == SAHPI_INVENT_DATA_VALID) { if (fdebug) printf( "Index = %d type=%x len=%d\n", i, inv->DataRecords[i]->RecordType, inv->DataRecords[i]->DataLength); switch (inv->DataRecords[i]->RecordType) { case SAHPI_INVENT_RECTYPE_INTERNAL_USE: if (fdebug) printf( "Internal Use\n"); break; case SAHPI_INVENT_RECTYPE_PRODUCT_INFO: if (fdebug) printf( "Product Info\n"); prodrecindx = i; prtprodtinfo(); break; case SAHPI_INVENT_RECTYPE_CHASSIS_INFO: if (fdebug) printf( "Chassis Info\n"); prtchassinfo(); break; case SAHPI_INVENT_RECTYPE_BOARD_INFO: if (fdebug) printf( "Board Info\n"); prtboardinfo(); break; case SAHPI_INVENT_RECTYPE_OEM: if (fdebug) printf( "OEM Record\n"); break; default: printf(" Invalid Invent Rec Type =%x\n", inv->DataRecords[i]->RecordType); break; } } } if (IsTagBmc(rdr.IdString.Data,rdr.IdString.DataLength) && (fasset == 1)) { SaHpiTextBufferT aTag; if (fdebug) printf( "Inventory = %s\n", rdr.IdString.Data); /* prodrecindx contains index for Prod Rec Type */ dataptr = (SaHpiInventGeneralDataT *) &inv->DataRecords[prodrecindx]->RecordData.ProductInfo; dataptr->AssetTag = &aTag; strptr=dataptr->AssetTag; strptr->DataType = SAHPI_TL_TYPE_LANGUAGE; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)asset_len; strncpy( (char *)strptr->Data, (char *)asset_tag,asset_len); strptr->Data[asset_len] = 0; printf( "Writing new asset tag: %s\n",(char *)strptr->Data); rv = saHpiEntityInventoryDataWrite( sessionid, resourceid, eirid, inv); printf("Return Write Status = %d\n", rv); if (rv == SA_OK) { printf ("Good write - re-reading!\n"); rv = saHpiEntityInventoryDataRead( sessionid, resourceid, eirid, buffersize, inv, &actualsize); if (fxdebug) printf( "saHpiEntityInventoryDataRead[%d] rv = %d\n", eirid, rv); if (fdebug) printf("ActualSize=%d\n", actualsize); if (rv == SA_OK) { /* Walk thru the list of inventory data */ for (i=0; inv->DataRecords[i] != NULL; i++) { if (inv->Validity == SAHPI_INVENT_DATA_VALID) { if (fdebug) printf( "Index = %d type=%x len=%d\n", i, inv->DataRecords[i]->RecordType, inv->DataRecords[i]->DataLength); switch (inv->DataRecords[i]->RecordType) { case SAHPI_INVENT_RECTYPE_INTERNAL_USE: if (fdebug) printf( "Internal Use\n"); break; case SAHPI_INVENT_RECTYPE_PRODUCT_INFO: if (fdebug) printf( "Product Info\n"); prtprodtinfo(); break; case SAHPI_INVENT_RECTYPE_CHASSIS_INFO: if (fdebug) printf( "Chassis Info\n"); prtchassinfo(); break; case SAHPI_INVENT_RECTYPE_BOARD_INFO: if (fdebug) printf( "Board Info\n"); prtboardinfo(); break; case SAHPI_INVENT_RECTYPE_OEM: if (fdebug) printf( "OEM Record\n"); break; default: printf(" Invalid Invent Rec Type =%x\n", inv->DataRecords[i]->RecordType); break; } } } } /*re-walk the inventory record list */ } /* Good write - re-read */ } /* check asset tag flag */ } else { printf("Returned HPI Error: rv=%d\n", rv); } } } /* Inventory Data Records - Type 3 */ entryid = nextentryid; } } rptentryid = nextrptentryid; } } rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); exit(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; }
SaErrorT discover_domain(SaHpiDomainIdT domain_id) { SaErrorT err; SaHpiSessionIdT session_id; SaHpiRptInfoT rpt_info_before; SaHpiRptInfoT rpt_info_after; SaHpiEntryIdT current; SaHpiEntryIdT next = SAHPI_FIRST_ENTRY; SaHpiRptEntryT entry; if (next == SAHPI_LAST_ENTRY) return SA_OK; /* every domain requires a new session */ err = saHpiSessionOpen(domain_id, &session_id, NULL); if (SA_OK != err) { error("saHpiSessionOpen", err); return err; } /* force regeneration of the RPT */ err = saHpiResourcesDiscover(session_id); if (SA_OK != err) { error("saHpiResourcesDiscover", err); return err; } /* 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; } do { int i; current = next; err = saHpiRptEntryGet(session_id, current, &next, &entry); if (SA_OK != err) { error("saHpiRptEntryGet", err); return err; } printf("%s\n", (char *)entry.ResourceTag.Data); printf("Entry ID: %x\n", (int) entry.EntryId); printf("Resource ID: %x\n", (int) entry.ResourceId); printf("Domain ID: %x\n", (int) entry.DomainId); printf("Revision: %c\n", entry.ResourceInfo.ResourceRev); printf("Version: %c\n", entry.ResourceInfo.SpecificVer); printf("Severity: %s\n",severity2str(entry.ResourceSeverity)); printf("Entity Path:\n"); for ( i=0; i<SAHPI_MAX_ENTITY_PATH; i++ ) { SaHpiEntityT tmp = entry.ResourceEntity.Entry[i]; if (tmp.EntityType <= SAHPI_ENT_UNSPECIFIED) break; printf("\t{%s, %i}\n", type2string(tmp.EntityType), tmp.EntityInstance); } display_entity_capabilities(entry.ResourceCapabilities); printf("\n"); /* 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; } } while (next != SAHPI_LAST_ENTRY); /* get a copy of update counter to see if we missed anything */ err = saHpiRptInfoGet(session_id, &rpt_info_after); if (SA_OK != err) { error("saHpiRptInfoGet", err); return err; } if (rpt_info_after.UpdateCount != rpt_info_before.UpdateCount) { err = SA_ERR_HPI_ERROR; error("RPT table changed while obtaining resource info", err); return err; } return SA_OK; }
cOpenHpiDaemon::tResult cOpenHpiDaemon::HandleMsg( cConnection *c, const cMessageHeader &header, const void *data, cMessageHeader &rh, void *&rd ) { cHpiMarshal *hm = HpiMarshalFind( header.m_id ); // check for function and data length if ( !hm || hm->m_request_len < header.m_len ) { //MessageHeaderInit( &rh, eMhError, header.m_seq, 0, 0 ); //rd = 0; fprintf( stderr, "wrong message length: id %d !\n", header.m_id ); return eResultError; } assert( hm->m_reply_len ); // init reply header MessageHeaderInit( &rh, eMhReply, header.m_seq, header.m_id, hm->m_reply_len ); // alloc reply buffer rd = calloc( 1, hm->m_reply_len ); SaErrorT ret; switch( header.m_id ) { case eFsaHpiSessionOpen: { SaHpiDomainIdT domain_id; SaHpiSessionIdT session_id = 0; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, (void *)&domain_id ); ret = saHpiSessionOpen( domain_id, &session_id, 0 ); DbgFunc( "saHpiSessionOpen( %x, %x ) = %d\n", domain_id, session_id, ret ); if ( ret == SA_OK ) c->AddSession( session_id ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &session_id ); } break; case eFsaHpiSessionClose: { SaHpiSessionIdT session_id; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id ); ret = saHpiSessionClose( session_id ); DbgFunc( "saHpiSessionClose( %x ) = %d\n", session_id, ret ); if ( ret == SA_OK ) c->RemSession( session_id ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiResourcesDiscover: { SaHpiSessionIdT session_id; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id ); ret = saHpiResourcesDiscover( session_id ); DbgFunc( "saHpiResourcesDiscover( %x ) = %d\n", session_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiRptInfoGet: { SaHpiSessionIdT session_id; SaHpiRptInfoT rpt_info; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id ); ret = saHpiRptInfoGet( session_id, &rpt_info ); DbgFunc( "saHpiRptInfoGet( %x ) = %d\n", session_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &rpt_info ); } break; case eFsaHpiRptEntryGet: { SaHpiSessionIdT session_id; SaHpiEntryIdT entry_id; SaHpiEntryIdT next_entry_id; SaHpiRptEntryT rpt_entry; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &entry_id ); ret = saHpiRptEntryGet( session_id, entry_id, &next_entry_id, &rpt_entry ); DbgFunc( "saHpiRptEntryGet( %x, %x, %x ) = %d\n", session_id, entry_id, next_entry_id, ret ); rh.m_len = HpiMarshalReply2( hm, rd, &ret, &next_entry_id, &rpt_entry ); } break; case eFsaHpiRptEntryGetByResourceId: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiRptEntryT rpt_entry; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiRptEntryGetByResourceId( session_id, resource_id, &rpt_entry ); DbgFunc( "saHpiRptEntryGetByResourceId( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &rpt_entry ); } break; case eFsaHpiResourceSeveritySet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSeverityT severity; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &severity ); ret = saHpiResourceSeveritySet( session_id, resource_id, severity ); DbgFunc( "saHpiResourceSeveritySet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiResourceTagSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiTextBufferT resource_tag; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &resource_tag ); ret = saHpiResourceTagSet( session_id, resource_id, &resource_tag ); DbgFunc( "saHpiResourceTagSet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiResourceIdGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id = 0; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id ); ret = saHpiResourceIdGet( session_id, &resource_id ); DbgFunc( "saHpiResourceIdGet( %x ) = %d, %x\n", session_id, ret, resource_id ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &resource_id ); } break; case eFsaHpiEntitySchemaGet: { SaHpiSessionIdT session_id; SaHpiUint32T schema_id = 0; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id ); ret = saHpiEntitySchemaGet( session_id, &schema_id ); DbgFunc( "saHpiEntitySchemaGet( %x ) = %d, %x\n", session_id, ret, schema_id ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &schema_id ); } break; case eFsaHpiEventLogInfoGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSelInfoT info; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiEventLogInfoGet( session_id, resource_id, &info ); DbgFunc( "saHpiEventLogInfoGet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &info ); } break; case eFsaHpiEventLogEntryGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSelEntryIdT entry_id; SaHpiSelEntryIdT prev_entry_id = 0; SaHpiSelEntryIdT next_entry_id = 0; SaHpiSelEntryT event_log_entry; SaHpiRdrT rdr; SaHpiRptEntryT rpt_entry; memset( &rdr, 0, sizeof( SaHpiRdrT ) ); memset( &rpt_entry, 0, sizeof( SaHpiRptEntryT ) ); HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &entry_id ); ret = saHpiEventLogEntryGet( session_id, resource_id, entry_id, &prev_entry_id, &next_entry_id, &event_log_entry, &rdr, &rpt_entry ); DbgFunc( "saHpiEventLogEntryGet( %x, %x, %x ) = %d\n", session_id, resource_id, entry_id, ret ); rh.m_len = HpiMarshalReply5( hm, rd, &ret, &prev_entry_id, &next_entry_id, &event_log_entry, &rdr, &rpt_entry ); } break; case eFsaHpiEventLogEntryAdd: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSelEntryT evt_entry; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &evt_entry ); ret = saHpiEventLogEntryAdd( session_id, resource_id, &evt_entry ); DbgFunc( "saHpiEventLogEntryAdd( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiEventLogEntryDelete: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSelEntryIdT entry_id; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &entry_id ); ret = saHpiEventLogEntryDelete( session_id, resource_id, entry_id ); DbgFunc( "saHpiEventLogEntryDelete( %x, %x, %x ) = %d\n", session_id, resource_id, entry_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiEventLogClear: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiEventLogClear( session_id, resource_id ); DbgFunc( "saHpiEventLogClear( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiEventLogTimeGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiTimeT ti; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiEventLogTimeGet( session_id, resource_id, &ti ); DbgFunc( "saHpiEventLogTimeGet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &ti ); } break; case eFsaHpiEventLogTimeSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiTimeT ti; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id , &ti ); ret = saHpiEventLogTimeSet( session_id, resource_id, ti ); DbgFunc( "saHpiEventLogTimeSet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiEventLogStateGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiBoolT enable; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiEventLogStateGet( session_id, resource_id, &enable ); DbgFunc( "saHpiEventLogStateGet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &enable ); } break; case eFsaHpiEventLogStateSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiBoolT enable; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &enable ); ret = saHpiEventLogStateSet( session_id, resource_id, enable ); DbgFunc( "saHpiEventLogStateSet( %x, %x, %s ) = %d\n", session_id, resource_id, enable ? "true" : "false", ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiSubscribe: { SaHpiSessionIdT session_id; SaHpiBoolT provide_active_alarms; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &provide_active_alarms ); ret = saHpiSubscribe( session_id, provide_active_alarms ); DbgFunc( "saHpiSubscribe( %x, %s ) = %d\n", session_id, provide_active_alarms ? "true" : "false", ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiUnsubscribe: { SaHpiSessionIdT session_id; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id ); ret = saHpiUnsubscribe( session_id ); DbgFunc( "saHpiUnsubscribe( %x ) = %d\n", session_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiEventGet: { SaHpiSessionIdT session_id; SaHpiTimeoutT timeout; SaHpiEventT event; SaHpiRdrT rdr; SaHpiRptEntryT rpt_entry; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &timeout ); if ( timeout == 0 ) { ret = saHpiEventGet( session_id, timeout, &event, &rdr, &rpt_entry ); DbgFunc( "saHpiEventGet( %x ) = %d\n", session_id, ret ); rh.m_len = HpiMarshalReply3( hm, rd, &ret, &event, &rdr, &rpt_entry ); } else { cSession *s = c->FindSession( session_id ); if ( s && !s->IsEventGet() ) { s->EventGet( true ); SaHpiTimeT end; gettimeofday1( &end ); if ( timeout == SAHPI_TIMEOUT_BLOCK ) end += (SaHpiTimeT)10000*1000000000; //set a long time else end += timeout; s->Timeout() = end; s->Seq() = header.m_seq; DbgEvent( "saHpiEventGet( %x ): add to event listener.\n", s->SessionId() ); return eResultOk; } // error ret = SA_ERR_HPI_BUSY; rh.m_len = HpiMarshalReply3( hm, rd, &ret, &event, &rdr, &rpt_entry ); } } break; case eFsaHpiRdrGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiEntryIdT entry_id; SaHpiEntryIdT next_entry_id; SaHpiRdrT rdr; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &entry_id ); ret = saHpiRdrGet( session_id, resource_id, entry_id, &next_entry_id, &rdr ); DbgFunc( "saHpiRdrGet( %x, %x, %x ) = %d\n", session_id, resource_id, entry_id, ret ); rh.m_len = HpiMarshalReply2( hm, rd, &ret, &next_entry_id, &rdr ); } break; case eFsaHpiSensorReadingGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSensorNumT sensor_num; SaHpiSensorReadingT reading; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &sensor_num ); ret = saHpiSensorReadingGet( session_id, resource_id, sensor_num, &reading ); DbgFunc( "saHpiSensorReadingGet( %x, %x, %x ) = %d\n", session_id, resource_id, sensor_num, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &reading ); } break; case eFsaHpiSensorReadingConvert: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSensorNumT sensor_num; SaHpiSensorReadingT reading_input; SaHpiSensorReadingT converted_reading; HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &sensor_num, &reading_input ); ret = saHpiSensorReadingConvert( session_id, resource_id, sensor_num, &reading_input, &converted_reading ); DbgFunc( "saHpiSensorReadingConvert( %x, %x, %x ) = %d\n", session_id, resource_id, sensor_num, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &converted_reading ); } break; case eFsaHpiSensorThresholdsGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSensorNumT sensor_num; SaHpiSensorThresholdsT sensor_thresholds; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &sensor_num ); ret = saHpiSensorThresholdsGet( session_id, resource_id, sensor_num, &sensor_thresholds); DbgFunc( "saHpiSensorThresholdsGet( %x, %x, %x ) = %d\n", session_id, resource_id, sensor_num, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &sensor_thresholds ); } break; case eFsaHpiSensorThresholdsSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSensorNumT sensor_num; SaHpiSensorThresholdsT sensor_thresholds; HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &sensor_num, &sensor_thresholds ); ret = saHpiSensorThresholdsSet( session_id, resource_id, sensor_num, &sensor_thresholds ); DbgFunc( "saHpiSensorThresholdsSet( %x, %x, %x ) = %d\n", session_id, resource_id, sensor_num, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiSensorTypeGet: { SaHpiResourceIdT resource_id; SaHpiSessionIdT session_id; SaHpiSensorNumT sensor_num; SaHpiSensorTypeT type; SaHpiEventCategoryT category; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &sensor_num ); ret = saHpiSensorTypeGet( session_id, resource_id, sensor_num, &type, &category ); DbgFunc( "saHpiSensorTypeGet( %x, %x, %x ) = %d\n", session_id, resource_id, sensor_num, ret ); rh.m_len = HpiMarshalReply2( hm, rd, &ret, &type, &category ); } break; case eFsaHpiSensorEventEnablesGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSensorNumT sensor_num; SaHpiSensorEvtEnablesT enables; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &sensor_num ); ret = saHpiSensorEventEnablesGet( session_id, resource_id, sensor_num, &enables ); DbgFunc( "saHpiSensorEventEnablesGet( %x, %x, %x ) = %d\n", session_id, resource_id, sensor_num, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &enables ); } break; case eFsaHpiSensorEventEnablesSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiSensorNumT sensor_num; SaHpiSensorEvtEnablesT enables; HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &sensor_num, &enables ); ret = saHpiSensorEventEnablesSet( session_id, resource_id, sensor_num, &enables ); DbgFunc( "saHpiSensorEventEnablesSet( %x, %x, %x ) = %d\n", session_id, resource_id, sensor_num, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiControlTypeGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiCtrlNumT ctrl_num; SaHpiCtrlTypeT type; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &ctrl_num ); ret = saHpiControlTypeGet( session_id, resource_id, ctrl_num, &type ); DbgFunc( "saHpiControlTypeGet( %x, %x, %x ) = %d\n", session_id, resource_id, ctrl_num, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &type ); } break; case eFsaHpiControlStateGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiCtrlNumT ctrl_num; SaHpiCtrlStateT ctrl_state; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &ctrl_num ); ret = saHpiControlStateGet( session_id, resource_id, ctrl_num, &ctrl_state ); DbgFunc( "saHpiControlStateGet( %x, %x, %x ) = %d\n", session_id, resource_id, ctrl_num, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &ctrl_state ); } break; case eFsaHpiControlStateSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiCtrlNumT ctrl_num; SaHpiCtrlStateT ctrl_state; HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &ctrl_num, &ctrl_state ); ret = saHpiControlStateSet( session_id, resource_id, ctrl_num, &ctrl_state ); DbgFunc( "saHpiControlStateSet( %x, %x, %x ) = %d\n", session_id, resource_id, ctrl_num, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiEntityInventoryDataRead: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiEirIdT eir_id; SaHpiUint32T buffer_size; unsigned char *buffer = 0; SaHpiUint32T actual_size; HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &eir_id, &buffer_size ); if ( buffer_size ) buffer = new unsigned char [buffer_size]; ret = saHpiEntityInventoryDataRead( session_id, resource_id, eir_id, buffer_size, (SaHpiInventoryDataT *)(void *)buffer, &actual_size ); DbgFunc( "saHpintityInventoryDataRead( %x, %x, %x, %d ) = %d\n", session_id, resource_id, eir_id, buffer_size, ret ); const cMarshalType *reply[4]; reply[0] = &SaErrorType; // SA_OK reply[1] = &SaHpiUint32Type; // actual size const void *params[3]; params[0] = &ret; params[1] = &actual_size; if ( ret != SA_OK || buffer == 0 ) reply[2] = 0; else { reply[2] = &SaHpiInventoryDataType, // inventory data reply[3] = 0; params[2] = buffer; } rh.m_len = MarshalArray( reply, params, rd ); if ( buffer ) delete [] buffer; } break; case eFsaHpiEntityInventoryDataWrite: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiEirIdT eir_id; unsigned char buffer[10240]; HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &eir_id, buffer ); ret = saHpiEntityInventoryDataWrite( session_id, resource_id, eir_id, (SaHpiInventoryDataT *)(void *)buffer ); DbgFunc( "saHpintityInventoryDataWrite( %x, %x, %x ) = %d\n", session_id, resource_id, eir_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiWatchdogTimerGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiWatchdogNumT watchdog_num; SaHpiWatchdogT watchdog; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &watchdog_num ); ret = saHpiWatchdogTimerGet( session_id, resource_id, watchdog_num, &watchdog ); DbgFunc( "saHpiWatchdogTimerGet( %x, %x, %x ) = %d\n", session_id, resource_id, watchdog_num, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &watchdog ); } break; case eFsaHpiWatchdogTimerSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiWatchdogNumT watchdog_num; SaHpiWatchdogT watchdog; HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &watchdog_num, &watchdog ); ret = saHpiWatchdogTimerSet( session_id, resource_id, watchdog_num, &watchdog ); DbgFunc( "saHpiWatchdogTimerSet( %x, %x, %x ) = %d\n", session_id, resource_id, watchdog_num, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiWatchdogTimerReset: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiWatchdogNumT watchdog_num; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &watchdog_num ); ret = saHpiWatchdogTimerReset( session_id, resource_id, watchdog_num ); DbgFunc( "eFsaHpiWatchdogTimerReset( %x, %x, %x ) = %d\n", session_id, resource_id, watchdog_num, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiHotSwapControlRequest: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiHotSwapControlRequest( session_id, resource_id ); DbgFunc( "saHpiHotSwapControlRequest( %x, %x ) = %d\n", session_id, resource_id , ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiResourceActiveSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiResourceActiveSet( session_id, resource_id ); DbgFunc( "saHpiResourceActiveSet( %x, %x ) = %d\n", session_id, resource_id , ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiResourceInactiveSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiResourceInactiveSet( session_id, resource_id ); DbgFunc( "saHpiResourceInactiveSet( %x, %x ) = %d\n", session_id, resource_id , ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiAutoInsertTimeoutGet: { SaHpiSessionIdT session_id; SaHpiTimeoutT timeout; HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id ); ret = saHpiAutoInsertTimeoutGet( session_id, &timeout ); DbgFunc( "saHpiAutoInsertTimeoutGet( %x ) = %d\n", session_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &timeout ); } break; case eFsaHpiAutoInsertTimeoutSet: { SaHpiSessionIdT session_id; SaHpiTimeoutT timeout; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &timeout ); ret = saHpiAutoInsertTimeoutSet( session_id, timeout ); DbgFunc( "saHpiAutoInsertTimeoutSet( %x ) = %d\n", session_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiAutoExtractTimeoutGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiTimeoutT timeout; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiAutoExtractTimeoutGet( session_id, resource_id, &timeout ); DbgFunc( "saHpiAutoExtractTimeoutGet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &timeout ); } break; case eFsaHpiAutoExtractTimeoutSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiTimeoutT timeout; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &timeout ); ret = saHpiAutoExtractTimeoutSet( session_id, resource_id, timeout ); DbgFunc( "saHpiAutoExtractTimeoutSet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiHotSwapStateGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiHsStateT state; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiHotSwapStateGet( session_id, resource_id, &state ); DbgFunc( "saHpiHotSwapStateGet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &state ); } break; case eFsaHpiHotSwapActionRequest: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiHsActionT action; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &action ); ret = saHpiHotSwapActionRequest( session_id, resource_id, action ); DbgFunc( "saHpiHotSwapActionRequest( %x, %x ) = %d\n", session_id, resource_id , ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiResourcePowerStateGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiHsPowerStateT state; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiResourcePowerStateGet( session_id, resource_id, &state ); DbgFunc( "saHpiResourcePowerStateGet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &state ); } break; case eFsaHpiResourcePowerStateSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiHsPowerStateT state; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &state ); ret = saHpiResourcePowerStateSet( session_id, resource_id, state ); DbgFunc( "(saHpiResourcePowerStateSet %x, %x ) = %d\n", session_id, resource_id , ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiHotSwapIndicatorStateGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiHsIndicatorStateT state; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiHotSwapIndicatorStateGet( session_id, resource_id, &state ); DbgFunc( "saHpiHotSwapIndicatorStateGet( %x, %x ) = %d\n", session_id, resource_id , ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &state ); } break; case eFsaHpiHotSwapIndicatorStateSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiHsIndicatorStateT state; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &state ); ret = saHpiHotSwapIndicatorStateSet( session_id, resource_id, state ); DbgFunc( "saHpiHotSwapIndicatorStateSet( %x, %x ) = %d\n", session_id, resource_id , ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiParmControl: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiParmActionT action; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &action ); ret = saHpiParmControl( session_id, resource_id, action ); DbgFunc( "saHpiParmControl( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; case eFsaHpiResourceResetStateGet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiResetActionT reset_action; HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id ); ret = saHpiResourceResetStateGet( session_id, resource_id, &reset_action ); DbgFunc( "saHpiResourceResetStateGet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply1( hm, rd, &ret, &reset_action ); } break; case eFsaHpiResourceResetStateSet: { SaHpiSessionIdT session_id; SaHpiResourceIdT resource_id; SaHpiResetActionT reset_action; HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data, &session_id, &resource_id, &reset_action ); ret = saHpiResourceResetStateSet( session_id, resource_id, reset_action ); DbgFunc( "saHpiResourceResetStateSet( %x, %x ) = %d\n", session_id, resource_id, ret ); rh.m_len = HpiMarshalReply0( hm, rd, &ret ); } break; default: assert( 0 ); break; } assert( rh.m_len <= hm->m_reply_len ); return eResultReply; }
int main( int argc, char *argv[] ) { int c; int help = 0; SaErrorT rv; while( (c = getopt( argc, argv,"hs:") ) != -1 ) switch( c ) { case 'h': help = 1; break; case 's': fan_speed = atoi( optarg ); break; default: fprintf( stderr, "unknown option %s !\n", argv[optind] ); help = 1; } if ( help ) return usage(); SaHpiVersionT hpiVer; rv = saHpiInitialize( &hpiVer ); if ( rv != SA_OK ) { fprintf( stderr, "saHpiInitialize: %s\n",decode_error( rv ) ); return 1; } SaHpiSessionIdT sessionid; rv = saHpiSessionOpen( SAHPI_DEFAULT_DOMAIN_ID, &sessionid, 0 ); if ( rv != SA_OK ) { printf( "saHpiSessionOpen: %s\n", decode_error( rv ) ); return 1; } rv = saHpiResourcesDiscover( sessionid ); if ( rv != SA_OK ) { printf( "saHpiResourcesDiscover: %s\n", decode_error( rv ) ); return 1; } int rc = discover_domain( sessionid ); rv = saHpiSessionClose( sessionid ); if ( rv != SA_OK ) printf( "saHpiSessionClose: %s\n", decode_error( rv ) ); rv = saHpiFinalize(); if ( rv != SA_OK ) printf( "saHpiFinalize: %s\n", decode_error( rv ) ); return rc; }
int main(int argc, char **argv) { char c; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiSelEntryIdT entryid; SaHpiSelEntryIdT nextentryid; SaHpiSelEntryIdT preventryid; SaHpiSelInfoT info; SaHpiSelEntryT sel; SaHpiRdrT rdr; printf("%s: version %s\n",argv[0],progver); while ( (c = getopt( argc, argv,"cx?")) != EOF ) switch(c) { case 'c': fclear = 1; break; case 'x': fdebug = 1; break; default: printf("Usage %s [-cx]\n",argv[0]); printf("where -c clears the event log\n"); printf(" -x displays 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 required re-doing discovery as a workaround. */ #endif /* walk the RPT list */ rptentryid = SAHPI_OLDEST_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) == 0) continue; /* no SEL here, try next RPT */ if (fclear) { rv = saHpiEventLogClear(sessionid,resourceid); if (rv == SA_OK) printf("EventLog successfully cleared\n"); else printf("EventLog clear, error = %d\n",rv); break; } rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] tag: %s\n", resourceid,rptentry.ResourceTag.Data); rv = saHpiEventLogInfoGet(sessionid,resourceid,&info); if (fdebug) printf("saHpiEventLogInfoGet %s\n",decode_error(rv)); if (rv == SA_OK) { /* This data isn't reliable yet with Spi beta2 implementation */ /* Use the entryid instead to calculate log size below. */ printf("EventLog entries=%d, size=%d, enabled=%d\n", info.Entries,info.Size,info.Enabled); } entryid = SAHPI_OLDEST_ENTRY; while ((rv == SA_OK) && (entryid != SAHPI_NO_MORE_ENTRIES)) { rv = saHpiEventLogEntryGet(sessionid,resourceid,entryid, &preventryid,&nextentryid,&sel,&rdr,NULL); if (fdebug) printf("saHpiEventLogEntryGet %s\n", decode_error(rv)); if (rv == SA_OK) { ShowSel(&sel, &rdr, &rptentry); preventryid = entryid; entryid = nextentryid; } } if (preventryid >= 0xff80) { int free; /* * This test could be more generic if the log info fields above * were accurate. IPMI SEL logs have a fixed size of 0x10000 * bytes. New log records are thrown away when it gets full. * (OLDEST = 0, NO_MORE = fffffffe , so these are ok.) */ free = (0x10000 - 20) - preventryid; printf("WARNING: Log free space is very low (%d bytes)\n" " Clear log with hpisel -c\n",free); } rptentryid = nextrptentryid; } } rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); exit(0); return(0); }
int main(int argc, char **argv) { int c; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiSelEntryIdT entryid; SaHpiSelEntryIdT nextentryid; SaHpiSelEntryIdT preventryid; SaHpiSelInfoT info; SaHpiSelEntryT sel; SaHpiRdrT rdr; int free = 50; printf("%s: version %s\n",argv[0],progver); while ( (c = getopt( argc, argv,"cx?")) != EOF ) switch(c) { case 'c': fclear = 1; break; case 'x': fdebug = 1; break; default: printf("Usage %s [-cx]\n",argv[0]); printf("where -c clears the event log\n"); printf(" -x displays 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); /* 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 %d 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); /* initialize structure */ info.Entries = 0; info.Size = 0; info.Enabled = 0; rv = saHpiEventLogInfoGet(sessionid,resourceid,&info); if (fdebug) printf("saHpiEventLogInfoGet %s\n",decode_error(rv)); if (rv == SA_OK) { char date[30]; printf("EventLog entries=%d, size=%d, enabled=%d\n", info.Entries,info.Size,info.Enabled); free = info.Size - info.Entries; saftime2str(info.UpdateTimestamp,date,30); printf("UpdateTime = %s, ", date); saftime2str(info.CurrentTime,date,30); printf("CurrentTime = %s\n", date); printf("Overflow = %d\n", info.OverflowFlag); printf("DeleteEntrySupported = %d\n", info.DeleteEntrySupported); } if (fclear) { rv = saHpiEventLogClear(sessionid,resourceid); if (rv == SA_OK) printf("EventLog successfully cleared\n"); else printf("EventLog clear, error = %d, %s\n",rv, decode_error(rv)); break; } if (info.Entries != 0){ entryid = SAHPI_OLDEST_ENTRY; while ((rv == SA_OK) && (entryid != SAHPI_NO_MORE_ENTRIES)) { rv = saHpiEventLogEntryGet(sessionid,resourceid, entryid,&preventryid,&nextentryid, &sel,&rdr,NULL); if (fdebug) printf("saHpiEventLogEntryGet %s\n", decode_error(rv)); if (rv == SA_OK) { ShowSel(&sel, &rdr, &rptentry); preventryid = entryid; entryid = nextentryid; } } } else printf("SEL is empty\n"); if (free < 6) { printf("WARNING: Log free space is very low (%d records)\n",free); printf("\tClear log with hpisel -c\n"); } rptentryid = nextrptentryid; } } printf("done.\n"); rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); // exit(0); return(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); }
int main(int argc, char **argv) { int c; SaErrorT rv; SaHpiVersionT hpiVer; SaHpiSessionIdT sessionid; SaHpiRptInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiWatchdogNumT wdnum; SaHpiWatchdogT wdt; int t = 0; char freset = 0; char fenable = 0; char fdisable = 0; printf("%s ver %s\n", argv[0],progver); while ( (c = getopt( argc, argv,"dert:x?")) != EOF ) switch(c) { case 'r': /* reset wdt */ freset = 1; break; case 'e': /* disable wdt */ fenable = 1; break; case 'd': /* disable wdt */ fdisable = 1; break; case 't': /* timeout (enable implied) */ t = atoi(optarg); fenable = 1; break; case 'x': fdebug = 1; break; /* debug messages */ default: printf("Usage: %s [-derx -t sec]\n", argv[0]); printf(" where -e enables the watchdog timer\n"); printf(" -d disables the watchdog timer\n"); printf(" -r resets the watchdog timer\n"); printf(" -t N sets timeout to N seconds\n"); printf(" -x show eXtra debug messages\n"); exit(1); } if (t == 0) t = 120; 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) { if (rv == SA_ERR_HPI_ERROR) printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv); else printf("saHpiSessionOpen error %d\n",rv); exit(-1); } rv = saHpiResourcesDiscover(sessionid); if (fdebug) printf("saHpiResourcesDiscover rv = %d\n",rv); rv = saHpiRptInfoGet(sessionid,&rptinfo); if (fdebug) printf("saHpiRptInfoGet rv = %d\n",rv); printf("RptInfo: UpdateCount = %x, 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) printf("RptEntryGet: rv = %d\n",rv); if (rv == SA_OK) { /* handle WDT for this RPT entry */ resourceid = rptentry.ResourceId; rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] resourceid=%d tag: %s\n", rptentryid, resourceid, rptentry.ResourceTag.Data); /* * The definition for SAHPI_DEFAULT_WATCHDOG_NUM is broken, * so we are assigning wdnum to 0x00 which is what SaHpi.h * attempted to set the default as. */ wdnum = (SaHpiWatchdogNumT)0x00; rv = saHpiWatchdogTimerGet(sessionid,resourceid,wdnum,&wdt); if (fdebug) printf("saHpiWatchdogTimerGet rv = %d\n",rv); show_wdt(wdnum,&wdt); if (fdisable) { printf("Disabling watchdog timer ...\n"); /* clear FRB2, timeout back to 120 sec */ /* TODO: add setting wdt values here */ wdt.TimerUse = 1; /* 1=FRB2 2=POST 3=OSLoad 4=SMS_OS 5=OEM */ wdt.TimerAction = 0; /* 0=none 1=reset 2=powerdown 3=powercycle */ wdt.PretimerInterrupt = 0; /* 0=none 1=SMI 2=NMI 3=message */ wdt.PreTimeoutInterval = 60000; /*msec*/ wdt.InitialCount = 120000; /*msec*/ wdt.PresentCount = 120000; /*msec*/ rv = saHpiWatchdogTimerSet(sessionid,resourceid,wdnum,&wdt); if (fdebug) printf("saHpiWatchdogTimerSet rv = %d\n",rv); show_wdt(wdnum,&wdt); } else if (fenable) { printf("Enabling watchdog timer ...\n"); /* hard reset action, no pretimeout, clear SMS/OS when done */ /* use t for timeout */ /* TODO: add setting wdt values here */ wdt.TimerUse = 4; /* 1=FRB2 2=POST 3=OSLoad 4=SMS_OS 5=OEM */ wdt.TimerAction = 1; /* 0=none 1=reset 2=powerdown 3=powercycle */ wdt.PretimerInterrupt = 2; /* 0=none 1=SMI 2=NMI 3=message */ wdt.PreTimeoutInterval = (t / 2) * 1000; /*msec*/ wdt.InitialCount = t * 1000; /*msec*/ wdt.PresentCount = t * 1000; /*msec*/ rv = saHpiWatchdogTimerSet(sessionid,resourceid,wdnum,&wdt); if (fdebug) printf("saHpiWatchdogTimerSet rv = %d\n",rv); show_wdt(wdnum,&wdt); } if (freset && !fdisable) { printf("Resetting watchdog timer ...\n"); rv = saHpiWatchdogTimerReset(sessionid,resourceid,wdnum); if (fdebug) printf("saHpiWatchdogTimerReset rv = %d\n",rv); } rptentryid = nextrptentryid; /* get next RPT (usu only one anyway) */ } /*endif RPT ok*/ } /*end while loop*/ rv = saHpiSessionClose(sessionid); rv = saHpiFinalize(); exit(0); return(0); }