/* * Main */ int main(int argc, char **argv) { SaHpiBoolT printusage = FALSE; int c; oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"vx?")) != EOF ) { switch(c) { case 'x': fdebug = 1; break; case 'v': fverbose = 1; break; default: printusage = TRUE; break; } } if (printusage == TRUE) { printf("\n\tUsage: %s [-option]\n\n", argv[0]); printf("\t (No Option) Display domains known to baselib \n"); printf("\t -v Display in verbose mode including " "domain info for directly related domains\n"); printf("\t -x Display debug messages\n"); printf("\n\n\n\n"); exit(1); } show_domains(); exit(0); }
/* * Main */ int main(int argc, char **argv) { SaErrorT rv = SA_OK; SaHpiSessionIdT sessionid; GOptionContext *context; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Display system topology\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION //TODO: Feature 880127? - OHC_VERBOSE_OPTION )) { // no verbose mode implemented g_option_context_free (context); return 1; } g_option_context_free (context); if (f_rpt || f_sensor || f_inv || f_ctrl || f_rdr || f_wdog) f_listall = TRUE; if (f_resourceid != 0) f_allres = FALSE; rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return rv; /* * Resource discovery */ if (copt.debug) DBG("saHpiDiscover"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { CRIT("saHpiDiscover returns %s",oh_lookup_error(rv)); return rv; } printf("Discovery done\n"); list_resources(sessionid, (SaHpiResourceIdT) f_resourceid); rv = saHpiSessionClose(sessionid); return 0; }
int main(int argc, char **argv) { int c, i; SaErrorT rv; char buf[READ_BUF_SIZE]; char *S; oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"x?")) != EOF ) switch(c) { case 'x': fdebug = 1; break; default: printf("Usage: %s [-x]\n", argv[0]); printf(" -x Display debug messages\n"); return(1); } rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL); if (rv != SA_OK) { printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv)); return(-1); } rv = saHpiDiscover(sessionid); if (fdebug) printf("saHpiDiscover: %s\n", oh_lookup_error(rv)); rv = saHpiSubscribe(sessionid); if (rv != SA_OK) { printf( "saHpiSubscribe error %d\n",rv); return(-1); } /* make the RPT list */ get_rpts(); /* get rdrs for the RPT list */ for (i = 0; i < nrpts; i++) get_rdrs(Rpts + i); help(); for (;;) { printf("==> "); S = fgets(buf, READ_BUF_SIZE, stdin); if (parse_command(S) < 0) break; }; rv = saHpiSessionClose(sessionid); return(0); }
int main(int argc, char **argv) { SaErrorT rv = SA_OK; oHpiHandlerIdT handlerid = 0; SaHpiResourceIdT resid = 0; SaHpiBoolT printusage = FALSE; int i=1; enum cmdT {eUndefined, eHandlerCreate, eHandlerDestroy, eHandlerInfo, eHandlerGetNext, eHandlerFind, eHandlerRetry, eHandlerList} cmd=eUndefined; oh_prog_version(argv[0], OH_SVN_REV); while (i<argc && !printusage && cmd!=eHandlerCreate) { if (strcmp(argv[i],"-D")==0) { if (++i<argc) domainid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"-x")==0) fdebug=1; else if (strcmp(argv[i],"create")==0) { cmd=eHandlerCreate; // exechandlercreate will do the remaining reading of // parameters itself rv = exechandlercreate (argc, argv, ++i); if (rv == SA_OK) exit (0); if (rv != SA_ERR_HPI_INVALID_PARAMS) exit (1); printusage = TRUE; } else if (strcmp(argv[i],"destroy")==0) { cmd=eHandlerDestroy; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"info")==0) { cmd=eHandlerInfo; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"getnext")==0) { cmd=eHandlerGetNext; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"find")==0) { cmd=eHandlerFind; if (++i<argc) resid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"retry")==0) { cmd=eHandlerRetry; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"list")==0) { cmd=eHandlerList; if (++i<argc) printusage = TRUE; } else printusage = TRUE; i++; } if (cmd == eHandlerCreate) { rv = exechandlercreate (argc, argv, i); if (rv == SA_OK) exit (0); if (rv == SA_ERR_HPI_INVALID_PARAMS) printusage = TRUE; else exit (1); } if (printusage == TRUE || cmd == eUndefined) { printf("\n"); printf("Usage: %s [-D domain] [-x] command [specific arguments]\n\n", argv[0]); printf(" -D nn Select domain id nn (not supported yet by oh-functions)\n"); printf(" -x Display debug messages\n"); printf("\n"); printf(" ohhander [-D domain] [-x] list\n"); printf(" List the handlers loaded in specified domain\n\n"); printf(" ohhander [-D domain] [-x] info <handler-id>\n"); printf(" Display info about handler <handler-id> \n\n"); printf(" ohhander [-D domain] [-x] destroy <handler-id>\n"); printf(" Unload handler <handler-id> and delete its config \n\n"); printf(" ohhander [-D domain] [-x] getnext <handler-id>\n"); printf(" Find next valid handler id from <handler-id> \n\n"); printf(" ohhander [-D domain] [-x] find <resource-id>\n"); printf(" Find the right handler for a resource id \n\n"); printf(" ohhander [-D domain] [-x] retry <handler-id>\n"); printf(" Retry loading of handler <handler-id> \n\n"); printf(" ohhander [-D domain] [-x] create plugin <name> <params>\n"); printf(" Create handler with the specified parameters.\n"); printf(" Pairs of strings in commandline like in openhpi.conf.\n"); printf(" Keyword plugin to select type of handler.\n"); printf(" Entity root and other complex strings must be \n"); printf(" enclosed in \".\n"); printf(" example:\n"); printf(" ohhandler create plugin libsimulator " "entity_root \"{SYSTEM_CHASSIS,1}\" name sim\n"); printf("\n\n"); exit(1); } if (fdebug) { if (domainid==SAHPI_UNSPECIFIED_DOMAIN_ID) printf("saHpiSessionOpen\n"); else printf("saHpiSessionOpen to domain %u\n",domainid); } rv = saHpiSessionOpen(domainid,&sessionid,NULL); if (rv != SA_OK) { printf("saHpiSessionOpen returns %d (%s)\n", rv, oh_lookup_error(rv)); exit(-1); } if (fdebug) printf("saHpiSessionOpen returns with SessionId %u\n", sessionid); switch (cmd){ case eHandlerCreate: break; //already done case eHandlerDestroy: rv = exechandlerdestroy ( handlerid ); break; case eHandlerInfo: rv = exechandlerinfo ( handlerid ); break; case eHandlerGetNext: rv = exechandlergetnext ( handlerid ); break; case eHandlerFind: rv = exechandlerfind ( resid ); break; case eHandlerRetry: rv = exechandlerretry ( handlerid ); break; case eHandlerList: rv = exechandlerlist ( ); break; case eUndefined: break; //already done } if (fdebug) { printf("Internal processing returns %d (%s)\n", rv, oh_lookup_error(rv)); printf("Calling saHpiSessionClose for session %u\n",sessionid); } rv = saHpiSessionClose(sessionid); if (fdebug) { printf("saHpiSessionClose returns %d (%s)\n", rv, oh_lookup_error(rv)); } exit(0); }
int main(int argc, char **argv) { SaErrorT rv,rv_rdr; SaHpiSessionIdT sessionid; SaHpiDomainInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiIdrInfoT idrInfo; SaHpiIdrIdT idrid; int invfound = 0; int nloops = 0; GOptionContext *context; atag.tlen = 0; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Shows resources' inventory records\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION )) { //TODO: Feature 880127? g_option_context_free (context); return 1; } g_option_context_free (context); if (fatag) { atag.tag = (char *)strdup(fatag); atag.tlen = strlen(fatag); g_free(fatag); } /* compile error */ // inv = (SaHpiIdrAreaHeaderT *)&inbuff[0]; inv = (SaHpiIdrAreaHeaderT *)(void *)&inbuff[0]; rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return rv; rv = saHpiDomainInfoGet(sessionid,&rptinfo); if (copt.debug) DBG("saHpiDomainInfoGet rv = %d",rv); // if (copt.debug) DBG("RptInfo: UpdateCount = %x, UpdateTime = %lx", // rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); while (!invfound && (nloops < 7)) { /* * The OpenHPI ipmi plugin has a bug whereby the FRU RDR is added * much later, and always requires a rediscovery. (bug #1095256) * This should not apply to other well-behaved plugins. */ nloops++; if (copt.debug) DBG("Starting Discovery, pass %u ...",nloops); rv = saHpiDiscover(sessionid); if (copt.debug) DBG("saHpiDiscover rv = %d",rv); if (rv != SA_OK) { CRIT("saHpiDiscover error %d",rv); break; } /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("RptEntryGet: rid=%u rv = %d\n",rptentryid,rv); if (rv == SA_OK) { /* obtain resource tag */ char tagstr[MAX_STRSIZE]; fixstr(&rptentry.ResourceTag,tagstr); /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; resourceid = rptentry.ResourceId; if (copt.debug) DBG("rptentry[%u] resourceid=%d", rptentryid,resourceid); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA) { printf("Resource[%u] Tag: %s \thas inventory capability\n", rptentryid,tagstr); rv_rdr = SA_OK; while ((rv_rdr == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) { rv_rdr = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr); if (copt.debug) DBG("saHpiRdrGet[%u] rv = %d",entryid,rv_rdr); if (rv_rdr == SA_OK) { if (copt.debug) DBG("Rdr[%u] type = %u tag = %s",entryid, rdr.RdrType,rdr.IdString.Data); if (rdr.RdrType == SAHPI_INVENTORY_RDR) { invfound = 1; /*type 3 includes inventory records*/ rdr.IdString.Data[rdr.IdString.DataLength] = 0; idrid = rdr.RdrTypeUnion.InventoryRec.IdrId; buffersize = sizeof(inbuff); if (copt.debug) { DBG("Rdr[%x] is inventory, IdrId=%x",rdr.RecordId,idrid); DBG("Inv BufferSize=%u", buffersize); } if ( IsTagBmc((char *)rdr.IdString.Data, rdr.IdString.DataLength) ) { /* Get all of the inventory data areas and fields */ memset(inv,0,buffersize); rv_rdr = saHpiIdrInfoGet(sessionid, resourceid, idrid, &idrInfo); if (rv_rdr != SA_OK) { printf("IDR Info error: rv_rdr = %d\n",rv_rdr); } else { /* idrInfo is ok */ if (copt.debug) DBG("IDR Info: ok "); print_epath(&rptentry.ResourceEntity, 1); printf("RDR[%x]: Inventory, IdrId=%x %s\n",rdr.RecordId, idrid,rdr.IdString.Data); print_idrinfo(&idrInfo,4); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (copt.debug) DBG("walkInventory rv_rdr = %d",rv_rdr); } if (!ent_writable(&rptentry.ResourceEntity,&idrInfo)) foundasset = 0; if ((atag.tlen > 0) && (foundasset == 1)) { SaHpiIdrFieldT atagField; atagField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG; atagField.ReadOnly = SAHPI_FALSE; atagField.AreaId = atag.areaid; atagField.FieldId = atag.fieldid; strptr=&(atagField.Field); strptr->DataType = SAHPI_TL_TYPE_TEXT; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)atag.tlen; strncpy((char *)strptr->Data, atag.tag, atag.tlen); strptr->Data[atag.tlen] = 0; printf( "Writing new asset tag: %s\n",strptr->Data); rv_rdr = saHpiIdrFieldSet(sessionid, resourceid, atag.idrid, &atagField); printf("Return Write Status = %d\n", rv_rdr); if (rv_rdr == SA_OK) { printf ("Good write - re-reading!\n"); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (copt.debug) DBG("walkInventory rv_rdr = %d",rv_rdr); } /* Good write - re-read */ } /*endif foundasset*/ } /*endif RDR tag ok*/ } /* Inventory Data Records - Type 3 */ else if (copt.debug) DBG("rdr type = %u", rdr.RdrType); } /*endif RdrGet ok*/ entryid = nextentryid; } /*end while rdr*/ } /*endif rpt invent capab*/ else if (copt.debug) DBG("Resource[%u] Tag: %s", rptentryid,tagstr); } /*endif rpt ok*/ rptentryid = nextrptentryid; } /*end rpt loop */ if (copt.debug) DBG("loop %u inventory found = %d",nloops,invfound); } /*end while no inv */ rv = saHpiSessionClose(sessionid); return 0; }
int main(int argc, char **argv) { SaHpiInt32T ComputerNumber = 0; //0..n-1 SaHpiInt32T SelectedSystem = 0; //0..n-1 SaHpiPowerStateT Action = 255; //set it out of range to stand for status; COMPUTER_DATA *ComputerPtr; SaHpiBoolT BladeSelected = FALSE; SaHpiBoolT MultipleBlades = FALSE; SaHpiBoolT ActionSelected = FALSE; GSList* Computer; GSList* ComputerListHead; SaHpiSessionIdT SessionId; SaErrorT Status; SaHpiEntryIdT RptEntry = SAHPI_FIRST_ENTRY; SaHpiEntryIdT RptNextEntry; SaHpiRptEntryT Report; SaHpiInt32T Index, EntityElement; SaHpiPowerStateT PowerState; char PowerStateString[3][7]= {"off\0","on\0","cycled\0"}; GOptionContext *context; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Exercise HPI Power Management APIs\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION //TODO: Feature 880127 - OHC_VERBOSE_OPTION )) { // no verbose mode implemented g_option_context_free (context); return 1; } g_option_context_free (context); if (f_down) { Action = SAHPI_POWER_OFF; ActionSelected = TRUE; } if (f_up) { Action = SAHPI_POWER_ON; ActionSelected = TRUE; } if (f_reset) { Action = SAHPI_POWER_CYCLE; ActionSelected = TRUE; } if (f_unattended) { BladeSelected = TRUE; ActionSelected = TRUE; } if (f_blade > 0) { BladeSelected = TRUE; SelectedSystem = f_blade - 1; //Normalizing to 0...n-1 if ((SelectedSystem > MAX_MANAGED_SYSTEMS) || (SelectedSystem < 0)) { CRIT("hpipower: blade number out of range"); return 1; //When we exit here, there is nothing to clean up } } /* Initialize the first of a list of computers */ HPI_POWER_DEBUG_PRINT("Initializing the List Structure for the computers"); Computer = g_slist_alloc(); ComputerListHead = Computer; HPI_POWER_DEBUG_PRINT("Allocating space for the information on each computer"); ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA)); Computer->data = (gpointer)ComputerPtr; /* Initialize HPI domain and session */ HPI_POWER_DEBUG_PRINT("Initalizing HPI Session"); Status = ohc_session_open_by_option ( &copt, &SessionId); if (Status == SA_OK) { /* Find all of the individual systems */ // regenerate the Resource Presence Table(RPT) HPI_POWER_DEBUG_PRINT("Hpi Discovery"); Status = saHpiDiscover(SessionId); } else { CRIT("Initalizing HPI Session FAILED, code %s", oh_lookup_error(Status)); return -1; } HPI_POWER_DEBUG_PRINT("Walking through all of the Report Tables"); while ((Status == SA_OK) && (RptEntry != SAHPI_LAST_ENTRY)) { HPI_POWER_DEBUG_PRINT1("@"); 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_PRINT1("."); if (Report.ResourceCapabilities & SAHPI_CAPABILITY_POWER) { char tagbuf[SAHPI_MAX_TEXT_BUFFER_LENGTH + 1]; HPI_POWER_DEBUG_PRINT1("#"); // 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 HpiTextBuffer2CString( &Report.ResourceTag, tagbuf ); snprintf(ComputerPtr->NameStr, sizeof(ComputerPtr->NameStr), "%s %d", tagbuf, (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("Generating Listing of options to choose from:"); /* 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("Printing out a listing of all the blades"); for (Index = 0; Index < ComputerNumber; Index++) { HPI_POWER_DEBUG_PRINT1("$"); // 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_PRINT1("%%"); 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: "); if (scanf("%d",&Index) == 0) { printf("Incorrect number\n"); } Index--; //normalize to 0..n-1 printf("\n"); } BladeSelected = TRUE; SelectedSystem = Index; } HPI_POWER_DEBUG_PRINT("Generating Listing of Actions to choose from"); /* 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: "); if (scanf("%d", &Index) == 0) { Index = -1; } switch (Index) { case 0: Action = SAHPI_POWER_OFF; break; case 1: Action = SAHPI_POWER_ON; break; case 2: Action = SAHPI_POWER_CYCLE; break; default: Action = 255; //Out of Range for "Status" break; } } /* execute the command */ if (Status == SA_OK) { HPI_POWER_DEBUG_PRINT("Executing the command"); // obtain the information for this computer ComputerPtr = g_slist_nth_data(ComputerListHead, SelectedSystem); if (ComputerPtr == NULL) { printf("Error: Selected system %d was not found.\n", SelectedSystem); return -1; } if (Action <= SAHPI_POWER_CYCLE) { HPI_POWER_DEBUG_PRINT("Setting a New Power State"); // 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", argv[0], ComputerPtr->NameStr, PowerStateString[Action]); } } else // Report Power status for the system { HPI_POWER_DEBUG_PRINT("Getting the Power Status\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("Clean up"); /* clean up */ saHpiSessionClose(SessionId); //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("Reporting Bad Status"); CRIT("Error: %s", oh_lookup_error(Status)); } return(Status); }
/* * Main */ int main(int argc, char **argv) { SaErrorT rv = SA_OK; SaHpiDomainIdT domainid = SAHPI_UNSPECIFIED_DOMAIN_ID; SaHpiSessionIdT sessionid; SaHpiResourceIdT resourceid = 0; SaHpiBoolT printusage = FALSE; int c; oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"rsicwadfD:n:x?")) != EOF ) { switch(c) { case 'D': if (optarg) { domainid = atoi(optarg); } else printusage = TRUE; break; case 'r': f_rpt = 1; break; case 's': f_sensor = 1; break; case 'i': f_inv = 1; break; case 'c': f_ctrl = 1; break; case 'w': f_wdog = 1; break; case 'a': f_ann = 1; break; case 'f': f_fumi = 1; break; case 'd': f_dimi = 1; break; case 'n': if (optarg) { resourceid = atoi(optarg); f_allres = 0; } else printusage = TRUE; break; case 'x': fdebug = 1; break; default: printusage = TRUE; break; } } if (printusage == TRUE) { printf("\n\tUsage: %s [-option]\n\n", argv[0]); printf("\t (No Option) Display system topology via default domain: rpt & rdr headers\n"); printf("\t -D nn Select domain id nn\n"); printf("\t -r Display only rpts\n"); printf("\t -s Display only sensors\n"); printf("\t -c Display only controls\n"); printf("\t -w Display only watchdogs\n"); printf("\t -i Display only inventories\n"); printf("\t -a Display only annunciators\n"); printf("\t -f Display only fumis\n"); printf("\t -d Display only dimis\n"); printf("\t -n nn Display only resource nn and its topology\n"); printf("\t -x Display debug messages\n"); printf("\n\n\n\n"); exit(1); } if (argc == 1) f_overview = 1; memset (previous_system, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH); if (fdebug) { if (domainid==SAHPI_UNSPECIFIED_DOMAIN_ID) printf("saHpiSessionOpen\n"); else printf("saHpiSessionOpen to domain %u\n",domainid); } rv = saHpiSessionOpen(domainid,&sessionid,NULL); if (rv != SA_OK) { printf("saHpiSessionOpen returns %s\n",oh_lookup_error(rv)); exit(-1); } if (fdebug) printf("saHpiSessionOpen returns with SessionId %u\n", sessionid); /* * Resource discovery */ if (fdebug) printf("saHpiDiscover\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover returns %s\n",oh_lookup_error(rv)); exit(-1); } if (fdebug) printf("Discovery done\n"); list_resources(sessionid, resourceid); rv = saHpiSessionClose(sessionid); exit(0); }
int main(int argc, char **argv) { SaHpiInt32T ComputerNumber; //0..n-1 SaHpiInt32T SelectedSystem; //0..n-1 SaHpiPowerStateT Action; COMPUTER_DATA *ComputerPtr; SaHpiBoolT BladeSelected; SaHpiBoolT MultipleBlades; SaHpiBoolT ActionSelected; SaHpiBoolT PrintUsage; SaHpiBoolT DebugPrints; GSList* Computer; GSList* ComputerListHead; int option; SaHpiDomainIdT domainid = SAHPI_UNSPECIFIED_DOMAIN_ID; SaHpiSessionIdT SessionId; SaErrorT Status, Clean_Up_Status; SaHpiEntryIdT RptEntry, RptNextEntry; SaHpiRptEntryT Report; SaHpiInt32T Index, EntityElement; SaHpiPowerStateT PowerState; char PowerStateString[3][7]={"off\0","on\0","cycled\0"}; /* // Print out the Program name and Version */ oh_prog_version(argv[0], OH_SVN_REV); /* 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, "D:dpruxb:"); if ((option == EOF) || (PrintUsage == TRUE)) { break; //break out of the while loop } switch (option) { case 'D': if (optarg) domainid = atoi(optarg); else { printf("hpipower: option requires an argument -- D"); PrintUsage = TRUE; } break; case 'd': Action = SAHPI_POWER_OFF; ActionSelected = TRUE; break; case 'p': Action = SAHPI_POWER_ON; ActionSelected = TRUE; break; case 'r': Action = SAHPI_POWER_CYCLE; ActionSelected = TRUE; break; case 'u': BladeSelected = TRUE; ActionSelected = TRUE; break; case 'x': DebugPrints = TRUE; break; case 'b': if (*optarg == 0) { printf("hpipower: option requires an argument -- b"); 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(argv[0]); exit(1); //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.1 Initalizing HPI Session\n"); Status = saHpiSessionOpen(domainid, &SessionId, NULL); if (Status == SA_OK) { if (domainid!=SAHPI_UNSPECIFIED_DOMAIN_ID) printf("Session opened to HPI domain %u\n",domainid); /* Find all of the individual systems */ // regenerate the Resource Presence Table(RPT) HPI_POWER_DEBUG_PRINT("2.2 Hpi Discovery\n"); Status = saHpiDiscover(SessionId); } else { printf("2.1 Initalizing HPI Session FAILED, code %s\n", oh_lookup_error(Status)); return -1; } 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.ResourceCapabilities & SAHPI_CAPABILITY_POWER) { char tagbuf[SAHPI_MAX_TEXT_BUFFER_LENGTH + 1]; 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 HpiTextBuffer2CString( &Report.ResourceTag, tagbuf ); snprintf(ComputerPtr->NameStr, sizeof(ComputerPtr->NameStr), "%s %d", tagbuf, (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: "); if (scanf("%d",&Index) == 0) { printf("Incorrect number\n"); } 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: "); if (scanf("%d", &Index) == 0) { Index = -1; } switch (Index) { case 0: Action = SAHPI_POWER_OFF; break; case 1: Action = SAHPI_POWER_ON; break; case 2: Action = SAHPI_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 (ComputerPtr == NULL) { printf("Error: Selected system %d was not found.\n", SelectedSystem); return -1; } if (Action <= SAHPI_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", argv[0], 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); //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"); printf("Program %s returns with Error = %s\n", argv[0], oh_lookup_error(Status)); } return(Status); }
int main(int argc, char **argv) { SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiWatchdogNumT wdnum; SaHpiWatchdogT wdt; GOptionContext *context; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Read and Enables the watchdog timer.\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION //TODO: Feature 880127 - OHC_VERBOSE_OPTION )) { // no verbose mode implemented g_option_context_free (context); return 1; } g_option_context_free (context); if (ftimeout == 0) ftimeout = 120; else fenable = TRUE; rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return rv; rv = saHpiDiscover(sessionid); if (copt.debug) DBG("saHpiDiscover rv = %s",oh_lookup_error(rv)); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (copt.debug) DBG("saHpiDomainInfoGet rv = %s",oh_lookup_error(rv)); printf("DomainInfo: UpdateCount = %x, UpdateTime = %lx\n", domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("RptEntryGet: rv = %s\n",oh_lookup_error(rv)); if (rv == SA_OK) { /* handle WDT for this RPT entry */ resourceid = rptentry.ResourceId; rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; if (copt.debug) printf("rptentry[%u] resourceid=%u capab=%x tag: %s\n", rptentryid, resourceid, rptentry.ResourceCapabilities, rptentry.ResourceTag.Data); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG) { printf("%s has watchdog capability\n",rptentry.ResourceTag.Data); wdnum = SAHPI_DEFAULT_WATCHDOG_NUM; rv = saHpiWatchdogTimerGet(sessionid,resourceid,wdnum,&wdt); if (copt.debug) DBG("saHpiWatchdogTimerGet rv = %s",oh_lookup_error(rv)); if (rv != 0) { printf("saHpiWatchdogTimerGet error = %s\n",oh_lookup_error(rv)); rv = 0; rptentryid = nextrptentryid; continue; } 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 = SAHPI_WTU_NONE; /* 1=FRB2 2=POST 3=OSLoad 4=SMS_OS 5=OEM */ wdt.TimerAction = SAHPI_WA_NO_ACTION; /* 0=none 1=reset 2=powerdown 3=powercycle */ wdt.PretimerInterrupt = SAHPI_WPI_NONE; /* 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 (copt.debug) DBG("saHpiWatchdogTimerSet rv = %s",oh_lookup_error(rv)); if (rv == 0) show_wdt(wdnum,&wdt); } else if (fenable) { printf("Enabling watchdog timer ...\n"); /* hard reset action, no pretimeout, clear SMS/OS when done */ /* use ftimeout for timeout */ wdt.TimerUse = SAHPI_WTU_SMS_OS; /* 1=FRB2 2=POST 3=OSLoad 4=SMS_OS 5=OEM */ wdt.TimerAction = SAHPI_WA_RESET; /* 0=none 1=reset 2=powerdown 3=powercycle */ wdt.PretimerInterrupt = SAHPI_WPI_NMI; /* 0=none 1=SMI 2=NMI 3=message */ wdt.PreTimeoutInterval = (ftimeout / 2) * 1000; /*msec*/ wdt.InitialCount = ftimeout * 1000; /*msec*/ wdt.PresentCount = ftimeout * 1000; /*msec*/ rv = saHpiWatchdogTimerSet(sessionid,resourceid,wdnum,&wdt); if (copt.debug) DBG("saHpiWatchdogTimerSet rv = %s",oh_lookup_error(rv)); if (rv == 0) show_wdt(wdnum,&wdt); } if (freset && !fdisable) { printf("Resetting watchdog timer ...\n"); rv = saHpiWatchdogTimerReset(sessionid,resourceid,wdnum); if (copt.debug) DBG("saHpiWatchdogTimerReset rv = %s",oh_lookup_error(rv)); } } /*watchdog capability*/ rptentryid = nextrptentryid; /* get next RPT (usu only one anyway) */ } /*endif RPT ok*/ } /*end while loop*/ rv = saHpiSessionClose(sessionid); return 0; }
int main(int argc, char **argv) { int c, test_fail = 0, wait = 0; char *timeout_str= (char *)NULL; int do_discover_after_subscribe = 0; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiEventLogInfoT info; SaHpiRdrT rdr; SaHpiTimeoutT timeout; SaHpiEventT event; memset(&rptentry, 0, sizeof(rptentry)); oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"t:xd?")) != EOF ) { switch(c) { case 't': timeout_str = optarg; break; case 'd': do_discover_after_subscribe = 1; break; case 'x': fdebug = 1; break; default: Usage(argv); exit(1); } } if (timeout_str != (char *)NULL) { if ((strcmp(timeout_str, "SAHPI_TIMEOUT_BLOCK") == 0) || (strcmp(timeout_str, "BLOCK") == 0)) { timeout = SAHPI_TIMEOUT_BLOCK; } else { wait = atoi(timeout_str); timeout = (SaHpiTimeoutT)(wait * HPI_NSEC_PER_SEC); } } else timeout = (SaHpiTimeoutT) SAHPI_TIMEOUT_IMMEDIATE; printf("************** timeout:[%lld] ****************\n", timeout); rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL); if (rv != SA_OK) { if (rv == SA_ERR_HPI_ERROR) printf("saHpiSessionOpen: error %d, SpiLibd not running\n", rv); else printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv)); exit(-1); } if (!do_discover_after_subscribe) { if (fdebug) printf("saHpiDiscover\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover: %s\n", oh_lookup_error(rv)); exit(-1); } } if (fdebug) printf( "Subscribe to events\n"); rv = saHpiSubscribe( sessionid ); if (rv != SA_OK) { printf("saHpiSubscribe: %s\n", oh_lookup_error(rv)); exit(-1); } if (do_discover_after_subscribe) { if (fdebug) printf("saHpiDiscover after saHpiSubscribe\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover after saHpiSubscribe: %s\n", oh_lookup_error(rv)); exit(-1); } } rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv)); printf("DomainInfo: UpdateCount = %d, UpdateTime = %lx\n", domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { printf("**********************************************\n"); rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (fdebug) printf("saHpiRptEntryGet %s\n", oh_lookup_error(rv)); if (rv == SA_OK) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); if ( (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { /* Using EventLogInfo to build up event queue - for now */ rv = saHpiEventLogInfoGet(sessionid, resourceid, &info); if (fdebug) printf("saHpiEventLogInfoGet %s\n", oh_lookup_error(rv)); if (rv == SA_OK) oh_print_eventloginfo(&info, 4); } else { if (fdebug) printf("RPT doesn't have SEL\n"); } rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] tag: %s\n", resourceid, rptentry.ResourceTag.Data); rptentryid = nextrptentryid; } printf("**********************************************\n"); } printf( "Go and get the event\n"); while (1) { rdr.RdrType = SAHPI_NO_RECORD; rptentry.ResourceId = 0; rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry, NULL); if (rv != SA_OK) { if (rv != SA_ERR_HPI_TIMEOUT) { printf("ERROR during EventGet : %s\n", oh_lookup_error(rv)); test_fail = 1; } else { if (timeout == SAHPI_TIMEOUT_BLOCK) { printf("ERROR: Timeout while infinite wait\n"); test_fail = 1; } else if (timeout != SAHPI_TIMEOUT_IMMEDIATE) { printf("ERROR: Time, %d seconds, expired waiting" " for event\n", wait); test_fail = 1; } } break; } else { if (rdr.RdrType != SAHPI_NO_RECORD) oh_print_event(&event, &rdr.Entity, 4); else if (rptentry.ResourceId != 0) oh_print_event(&event, &rptentry.ResourceEntity, 4); else { rptentryid = event.Source; rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if(rv == SA_OK) oh_print_event(&event, &rptentry.ResourceEntity, 4); else { printf("Wrong resource Id <%d> detected", event.Source); oh_print_event(&event, NULL, 4); } } } } if (test_fail == 0) printf(" Test PASS.\n"); else printf(" Test FAILED.\n"); /* Unsubscribe to future events */ if (fdebug) printf( "Unsubscribe\n"); rv = saHpiUnsubscribe( sessionid ); rv = saHpiSessionClose(sessionid); return(0); }
int main(int argc, char **argv) { int month, day, year; int day_array[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; struct tm new_tm_time; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiTimeT oldtime; SaHpiTimeT newtime; SaHpiTimeT readbacktime; SaHpiTextBufferT buffer; GOptionContext *context; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Exercises Event Log clock APIs.\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION // not applicable - OHC_VERBOSE_OPTION )) { // no verbose mode g_option_context_free (context); EXIT1; } g_option_context_free (context); if ( !findate || !fintime) { CRIT("Please enter date and time to be set, or try --help."); EXIT1; } if (findate) { if (copt.debug) printf("New date to be set: %s\n",findate); if (sscanf(findate,"%2d/%2d/%4d", &month, &day, &year) != 3) { CRIT("%s: Invalid date", argv[0]); EXIT1; } /* check month, day and year for correctness */ if ((month < 1) || (month > 12)) { CRIT("%s: Month out of range: (%d)", argv[0], month); EXIT1; }; if (year < 1900) { CRIT("%s: Year out of range: (%d)", argv[0], year); EXIT1; }; month--; if (month == 1) { /* if the given year is a leap year */ if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) day_array[1] = 29; }; if ((day < 1) || (day > day_array[month])) { CRIT("%s: Day out of range: (%d)", argv[0], day); EXIT1; }; new_tm_time.tm_mon = month; new_tm_time.tm_mday = day; new_tm_time.tm_year = year - 1900; } if (fintime) { if (copt.debug) DBG("New time to be set: %s",fintime); if (sscanf(fintime,"%2d:%2d:%2d", &new_tm_time.tm_hour, &new_tm_time.tm_min, &new_tm_time.tm_sec) != 3) { CRIT("%s: Invalid time", argv[0]); EXIT1; } /* check hours, minutes and seconds for correctness */ if ((new_tm_time.tm_hour < 0) || (new_tm_time.tm_hour > 24)) { CRIT("%s: Hours out of range: (%d)", argv[0], new_tm_time.tm_hour); EXIT1; }; if ((new_tm_time.tm_min < 0) || (new_tm_time.tm_min > 60)) { CRIT("%s: Minutes out of range: (%d)", argv[0], new_tm_time.tm_min); EXIT1; }; if ((new_tm_time.tm_sec < 0) || (new_tm_time.tm_sec > 60)) { CRIT("%s: Seconds out of range: (%d)", argv[0], new_tm_time.tm_sec); EXIT1; } } if (copt.debug) DBG("Values passed to mktime():\n\tmon %d\n\tday %d\n\tyear %d\n\tHH %d\n\tMM %d\n\tSS %d", new_tm_time.tm_mon, new_tm_time.tm_mday, new_tm_time.tm_year, new_tm_time.tm_hour, new_tm_time.tm_min, new_tm_time.tm_sec); newtime = (SaHpiTimeT) mktime(&new_tm_time) * 1000000000; if (copt.debug) DBG("New date and time in SaHpiTimeT %" PRId64 "\n", (int64_t)newtime); rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) EXIT1; if (copt.debug) DBG("saHpiDiscover"); rv = saHpiDiscover(sessionid); if (copt.debug) DBG("saHpiDiscover %s", oh_lookup_error(rv)); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (copt.debug) DBG("saHpiDomainInfoGet %s", oh_lookup_error(rv)); printf("DomainInfo: RptUpdateCount = %u, RptUpdateTimestamp = %lx\n", domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (copt.debug) DBG("saHpiRptEntryGet %s", oh_lookup_error(rv)); if ((rv == SA_OK) && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { resourceid = rptentry.ResourceId; if (copt.debug) DBG("RPT %x capabilities = %x", resourceid, rptentry.ResourceCapabilities); rv = saHpiEventLogTimeGet(sessionid, resourceid, &oldtime); oh_decode_time(oldtime, &buffer); printf ("\nCurrent event log time on HPI target: %s\n", buffer.Data); printf ("Setting new event log time on HPI target ...\n"); rv = saHpiEventLogTimeSet(sessionid, resourceid, newtime); if (rv != SA_OK) { CRIT("saHpiEventLogTimeSet returned %s", oh_lookup_error(rv)); } rv = saHpiEventLogTimeGet(sessionid, resourceid, &readbacktime); oh_decode_time(readbacktime, &buffer); printf ("Read-Back-Check event log time: %s\n", buffer.Data); } // entryid = SAHPI_OLDEST_ENTRY; rptentryid = nextrptentryid; } rv = saHpiSessionClose(sessionid); g_free(findate); g_free(fintime); return(0); }
/* * Main */ int main(int argc, char **argv) { SaErrorT rv = SA_OK; SaHpiSessionIdT sessionid; SaHpiResourceIdT resourceid = 0; SaHpiDomainIdT domainid = SAHPI_UNSPECIFIED_DOMAIN_ID; SaHpiBoolT printusage = FALSE; int c; oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"D:acdirswon:x?")) != EOF ) { switch(c) { case 'D': if (optarg) { domainid = atoi(optarg); } else printusage = TRUE; break; case 'a': f_listall = 1; break; case 'c': f_ctrl = 1; break; case 'd': f_rdr = 1; break; case 'i': f_inv = 1; break; case 'r': f_rpt = 1; break; case 's': f_sensor = 1; break; case 'w': f_wdog = 1; break; case 'o': f_overview = 1; break; case 'n': if (optarg) { resourceid = atoi(optarg); f_allres = 0; } else printusage = TRUE; break; case 'x': fdebug = 1; break; default: printusage = TRUE; break; } } if (printusage == TRUE) { printf("\n\tUsage: %s [-option]\n\n", argv[0]); printf("\t (No Option) Display all rpts and rdrs via default domain\n"); printf("\t -D nn Select domain id nn\n"); printf("\t -a Display all rpts and rdrs\n"); printf("\t -c Display only controls\n"); printf("\t -d Display rdr records\n"); printf("\t -i Display only inventories\n"); printf("\t -o Display system overview: rpt & rdr headers\n"); printf("\t -r Display only rpts\n"); printf("\t -s Display only sensors\n"); printf("\t -w Display only watchdog\n"); printf("\t -n nn Select particular resource id to display\n"); printf("\t (Used with [-cdirs] options)\n"); printf("\t -x Display debug messages\n"); printf("\n\n\n\n"); exit(1); } if (f_rpt+f_sensor+f_inv+f_ctrl+f_rdr+f_wdog == 0) f_listall = 1; if (fdebug) { if (domainid==SAHPI_UNSPECIFIED_DOMAIN_ID) printf("saHpiSessionOpen\n"); else printf("saHpiSessionOpen to domain %u\n",domainid); } rv = saHpiSessionOpen(domainid,&sessionid,NULL); if (rv != SA_OK) { printf("saHpiSessionOpen returns %s\n",oh_lookup_error(rv)); exit(-1); } if (fdebug) printf("saHpiSessionOpen returns with SessionId %u\n", sessionid); /* * Resource discovery */ if (fdebug) printf("saHpiDiscover\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover returns %s\n",oh_lookup_error(rv)); exit(-1); } printf("Discovery done\n"); list_resources(sessionid, resourceid); rv = saHpiSessionClose(sessionid); exit(0); }
/* * Main */ int main(int argc, char **argv) { SaErrorT rv = SA_OK; oHpiGlobalParamTypeT paramtype = OHPI_CONF; char setparam[OH_MAX_TEXT_BUFFER_LENGTH]; SaHpiBoolT printusage = FALSE; int i=1; enum cmdT {eUndefined, eGlobalParamGet, eGlobalParamSet} cmd=eUndefined; oh_prog_version(argv[0], OH_SVN_REV); while (i<argc && !printusage) { if (strcmp(argv[i],"-D")==0) { if (++i<argc) domainid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"-x")==0) fdebug=1; else if (strcmp(argv[i],"get")==0) { cmd=eGlobalParamGet; } else if (strcmp(argv[i],"set")==0) { cmd=eGlobalParamSet; if (++i<argc) { if (strcmp(argv[i],"OPENHPI_ON_EP")==0) paramtype=OHPI_ON_EP; else if (strcmp(argv[i],"OPENHPI_LOG_ON_SEV")==0) paramtype=OHPI_LOG_ON_SEV; else if (strcmp(argv[i],"OPENHPI_EVT_QUEUE_LIMIT")==0) paramtype=OHPI_EVT_QUEUE_LIMIT; else if (strcmp(argv[i],"OPENHPI_DEL_SIZE_LIMIT")==0) paramtype=OHPI_DEL_SIZE_LIMIT; else if (strcmp(argv[i],"OPENHPI_DEL_SAVE")==0) paramtype=OHPI_DEL_SAVE; else if (strcmp(argv[i],"OPENHPI_DAT_SIZE_LIMIT")==0) paramtype=OHPI_DAT_SIZE_LIMIT; else if (strcmp(argv[i],"OPENHPI_DAT_USER_LIMIT")==0) paramtype=OHPI_DAT_USER_LIMIT; else if (strcmp(argv[i],"OPENHPI_DAT_SAVE")==0) paramtype=OHPI_DAT_SAVE; else if (strcmp(argv[i],"OPENHPI_PATH")==0) paramtype=OHPI_PATH; else if (strcmp(argv[i],"OPENHPI_VARPATH")==0) paramtype=OHPI_VARPATH; else if (strcmp(argv[i],"OPENHPI_CONF")==0) paramtype=OHPI_CONF; else printusage = TRUE; } else printusage = TRUE; if (++i<argc) strcpy(setparam, argv[i]); else if (i>=argc) printusage = TRUE; } else printusage = TRUE; i++; } if (printusage == TRUE || cmd == eUndefined) { printf("\n"); printf("Usage: %s [-D domain] [-x] command [specific arguments]\n\n", argv[0]); printf(" -D nn Select domain id nn (not supported yet by oh-functions)\n"); printf(" -x Display debug messages\n"); printf("\n"); printf(" Command get: display info about all global parameters\n"); printf(" no specific arguments\n"); printf(" Command set:\n"); printf(" one of the daemon's global parameters:\n"); printf(" (without the OPENHPI prefix)\n"); printf(" ON_EP, LOG_ON_SEV, EVT_QUEUE_LIMIT, \n"); printf(" DEL_SIZE_LIMIT, DEL_SAVE\n"); printf(" DAT_SIZE_LIMIT, DAT_USER_LIMIT, DAT_SAVE\n"); printf(" PATH, VARPATH, CONF\n"); printf(" and the desired new value. Example:\n"); printf(" ohparam set DEL_SIZE_LIMIT 20000\n"); printf("\n\n"); exit(1); } if (fdebug) { if (domainid==SAHPI_UNSPECIFIED_DOMAIN_ID) printf("saHpiSessionOpen\n"); else printf("saHpiSessionOpen to domain %u\n",domainid); } rv = saHpiSessionOpen(domainid,&sessionid,NULL); if (rv != SA_OK) { printf("saHpiSessionOpen returns %d (%s)\n", rv, oh_lookup_error(rv)); exit(-1); } if (fdebug) printf("saHpiSessionOpen returns with SessionId %u\n", sessionid); switch (cmd){ case eGlobalParamGet: rv = execglobalparamget ( ); break; case eGlobalParamSet: rv = execglobalparamset ( paramtype, setparam ); break; default: printf("\n\nSorry, this function is not implemented yet\n\n"); rv = SA_ERR_HPI_INVALID_PARAMS; } if (rv == SA_OK) { rv = saHpiSessionClose(sessionid); exit(0); } printf("Param set failed with returncode %d (%s)\n", rv, oh_lookup_error(rv)); exit(-1); }
int main(int argc, char **argv) { SaErrorT rv = SA_OK; oHpiHandlerIdT handlerid = 0; SaHpiResourceIdT resid = 0; SaHpiBoolT printusage = FALSE; int i=1; GOptionContext *context; enum cmdT {eUndefined, eHandlerCreate, eHandlerDestroy, eHandlerInfo, eHandlerGetNext, eHandlerFind, eHandlerRetry, eHandlerList} cmd=eUndefined; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="command [specific arguments] - " "Control openhpi plugin instances (handlers).\n " OH_SVN_REV "\n\n" OHHANDLER_HELP ; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION // not applicable - OHC_VERBOSE_OPTION )) { // no verbose mode printusage = TRUE; } g_option_context_free (context); /* Parse ohparam specific commands */ while (i<argc && !printusage && cmd!=eHandlerCreate) { if (strcmp(argv[i],"create")==0) { cmd=eHandlerCreate; // exechandlercreate will do the remaining reading of // parameters itself rv = exechandlercreate (argc, argv, ++i); if (rv == SA_OK) return 0; if (rv != SA_ERR_HPI_INVALID_PARAMS) return 1; printusage = TRUE; } else if (strcmp(argv[i],"destroy")==0) { cmd=eHandlerDestroy; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"info")==0) { cmd=eHandlerInfo; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"getnext")==0) { cmd=eHandlerGetNext; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"find")==0) { cmd=eHandlerFind; if (++i<argc) resid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"retry")==0) { cmd=eHandlerRetry; if (++i<argc) handlerid = atoi(argv[i]); else printusage = TRUE; } else if (strcmp(argv[i],"list")==0) { cmd=eHandlerList; if (++i<argc) printusage = TRUE; } else printusage = TRUE; i++; } if (cmd == eHandlerCreate) { rv = exechandlercreate (argc, argv, i); if (rv == SA_OK) return 0; if (rv == SA_ERR_HPI_INVALID_PARAMS) printusage = TRUE; else return 1; } if (printusage == TRUE || cmd == eUndefined) { printf("\n"); printf("Usage: %s [Option...] command [specific arguments]\n\n", argv[0]); printf(OHHANDLER_HELP"\n"); printf(" Options: \n"); printf(" -h, --help Show help options \n"); printf(" -D, --domain=nn Select domain id nn \n"); printf(" -X, --debug Display debug messages \n"); printf(" -N, --host=\"host<:port>\" Open session to the domain served by the daemon \n"); printf(" at the specified URL (host:port) \n"); printf(" This option overrides the OPENHPI_DAEMON_HOST and \n"); printf(" OPENHPI_DAEMON_PORT environment variables. \n"); printf(" -C, --cfgfile=\"file\" Use passed file as client configuration file \n"); printf(" This option overrides the OPENHPICLIENT_CONF \n"); printf(" environment variable. \n\n"); return 1; } rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return rv; switch (cmd){ case eHandlerCreate: break; //already done case eHandlerDestroy: rv = exechandlerdestroy ( handlerid ); break; case eHandlerInfo: rv = exechandlerinfo ( handlerid ); break; case eHandlerGetNext: rv = exechandlergetnext ( handlerid ); break; case eHandlerFind: rv = exechandlerfind ( resid ); break; case eHandlerRetry: rv = exechandlerretry ( handlerid ); break; case eHandlerList: rv = exechandlerlist ( ); break; case eUndefined: break; //already done } if (copt.debug) { DBG("Internal processing returns %s", oh_lookup_error(rv)); DBG("Calling saHpiSessionClose for session %u",sessionid); } rv = saHpiSessionClose(sessionid); if (copt.debug) { DBG("saHpiSessionClose returns %s", oh_lookup_error(rv)); } return 0; }
int main(int argc, char **argv) { int c, month, day, year; char i_newdate[20]; char i_newtime[20]; int day_array[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; struct tm new_tm_time; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiEventLogEntryIdT entryid; SaHpiTimeT oldtime; SaHpiTimeT newtime; SaHpiTimeT readbacktime; SaHpiTextBufferT buffer; oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"d:t:x")) != EOF ) { switch(c) { case 'd': findate = 1; strcpy(i_newdate, optarg); break; case 't': fintime = 1; strcpy(i_newtime, optarg); break; case 'x': fdebug = 1; break; default: usage(argv); exit(1); } } if ( !findate || !fintime) { usage(argv); exit(1); } if (findate) { if (fdebug) printf("New date to be set: %s\n",i_newdate); if (sscanf(i_newdate,"%2d/%2d/%4d", &month, &day, &year) < 8) { printf("%s: Invalid date\n", argv[0]); } /* check month, day and year for correctness */ if ((month < 1) || (month > 12)) { printf("%s: Month out of range: (%d)\n", argv[0], month); usage(argv); exit(1); }; if (year < 1900) { printf("%s: Year out of range: (%d)\n", argv[0], year); usage(argv); exit(1); }; month--; if (month == 1) { /* if the given year is a leap year */ if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) day_array[1] = 29; }; if ((day < 1) || (day > day_array[month])) { printf("%s: Day out of range: (%d)\n", argv[0], day); usage(argv); exit(1); }; new_tm_time.tm_mon = month; new_tm_time.tm_mday = day; new_tm_time.tm_year = year - 1900; } if (fintime) { if (fdebug) printf("New time to be set: %s\n",i_newtime); if (sscanf(i_newtime,"%2d:%2d:%2d", &new_tm_time.tm_hour, &new_tm_time.tm_min, &new_tm_time.tm_sec) < 6) { printf("%s: Invalid time\n", argv[0]); } /* check hours, minutes and seconds for correctness */ if ((new_tm_time.tm_hour < 0) || (new_tm_time.tm_hour > 24)) { printf("%s: Hours out of range: (%d)\n", argv[0], new_tm_time.tm_hour); usage(argv); exit(1); }; if ((new_tm_time.tm_min < 0) || (new_tm_time.tm_min > 60)) { printf("%s: Minutes out of range: (%d)\n", argv[0], new_tm_time.tm_min); usage(argv); exit(1); }; if ((new_tm_time.tm_sec < 0) || (new_tm_time.tm_sec > 60)) { printf("%s: Seconds out of range: (%d)\n", argv[0], new_tm_time.tm_sec); usage(argv); exit(1); } } if (fdebug) printf("Values passed to mktime():\n\tmon %d\n\tday %d\n\tyear %d\n\tHH %d\n\tMM %d\n\tSS %d\n", new_tm_time.tm_mon, new_tm_time.tm_mday, new_tm_time.tm_year, new_tm_time.tm_hour, new_tm_time.tm_min, new_tm_time.tm_sec); newtime = (SaHpiTimeT) mktime(&new_tm_time) * 1000000000; if (fdebug) printf("New date and time in SaHpiTimeT %lli\n", (long long int)newtime); rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid,NULL); if (rv != SA_OK) { if (rv == SA_ERR_HPI_ERROR) printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv); else printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv)); exit(-1); } rv = saHpiDiscover(sessionid); if (fdebug) printf("saHpiDiscover %s\n", oh_lookup_error(rv)); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv)); printf("DomainInfo: RptUpdateCount = %d, RptUpdateTimestamp = %lx\n", domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (fdebug) printf("saHpiRptEntryGet %s\n", oh_lookup_error(rv)); if ((rv == SA_OK) && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); rv = saHpiEventLogTimeGet(sessionid, resourceid, &oldtime); oh_decode_time(oldtime, &buffer); printf ("\nCurrent event log time on HPI target: %s\n", buffer.Data); printf ("Setting new event log time on HPI target ...\n"); rv = saHpiEventLogTimeSet(sessionid, resourceid, newtime); if (rv != SA_OK) { printf("saHpiEventLogTimeSet %s\n", oh_lookup_error(rv)); } rv = saHpiEventLogTimeGet(sessionid, resourceid, &readbacktime); oh_decode_time(readbacktime, &buffer); printf ("Read-Back-Check event log time: %s\n", buffer.Data); } entryid = SAHPI_OLDEST_ENTRY; rptentryid = nextrptentryid; } rv = saHpiSessionClose(sessionid); return(0); }
int main(int argc, char **argv) { int c; SaErrorT rv,rv_rdr; SaHpiSessionIdT sessionid; SaHpiDomainInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiIdrInfoT idrInfo; SaHpiIdrIdT idrid; int invfound = 0; int nloops = 0; oh_prog_version(argv[0], OH_SVN_REV); atag.tlen = 0; while ( (c = getopt( argc, argv,"a:vxz?")) != EOF ) switch(c) { case 'z': fzdebug = 1; /* fall thru to include next setting */ case 'x': fdebug = 1; break; case 'v': fverbose = 1; break; case 'a': fasset = 1; if (optarg) { atag.tag = (char *)strdup(optarg); atag.tlen = strlen(optarg); } break; default: printf("Usage: %s [-x] [-a asset_tag]\n", argv[0]); printf(" -a Sets the asset tag\n"); printf(" -x Display debug messages\n"); printf(" -z Display extra debug messages\n"); exit(1); } /* compile error */ // inv = (SaHpiIdrAreaHeaderT *)&inbuff[0]; inv = (SaHpiIdrAreaHeaderT *)(void *)&inbuff[0]; rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL); if (fdebug) printf("saHpiSessionOpen rv = %d sessionid = %x\n",rv,sessionid); if (rv != SA_OK) { printf("saHpiSessionOpen error %d\n",rv); exit(-1); } rv = saHpiDomainInfoGet(sessionid,&rptinfo); if (fdebug) printf("saHpiDomainInfoGet rv = %d\n",rv); // if (fdebug) printf("RptInfo: UpdateCount = %x, UpdateTime = %lx\n", // rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); while (!invfound && (nloops < 7)) { /* * The OpenHPI ipmi plugin has a bug whereby the FRU RDR is added * much later, and always requires a rediscovery. (bug #1095256) * This should not apply to other well-behaved plugins. */ nloops++; if (fdebug) printf("Starting Discovery, pass %d ...\n",nloops); rv = saHpiDiscover(sessionid); if (fdebug) printf("saHpiDiscover rv = %d\n",rv); if (rv != SA_OK) { printf("saHpiDiscover error %d\n",rv); break; } /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("RptEntryGet: rid=%d rv = %d\n",rptentryid,rv); if (rv == SA_OK) { /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; /* OpenHPI plugin sometimes has bad RPT Tag DataLength here. */ // rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; resourceid = rptentry.ResourceId; if (fdebug) printf("rptentry[%d] resourceid=%d\n", rptentryid,resourceid); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA) { printf("Resource[%d] Tag: %s \thas inventory capability\n", rptentryid,rptentry.ResourceTag.Data); rv_rdr = SA_OK; while ((rv_rdr == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) { rv_rdr = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr); if (fdebug) printf("saHpiRdrGet[%x] rv = %d\n",entryid,rv_rdr); if (rv_rdr == SA_OK) { if (fdebug) printf("Rdr[%x] type = %d tag = %s\n",entryid, rdr.RdrType,rdr.IdString.Data); if (rdr.RdrType == SAHPI_INVENTORY_RDR) { invfound = 1; /*type 3 includes inventory records*/ rdr.IdString.Data[rdr.IdString.DataLength] = 0; idrid = rdr.RdrTypeUnion.InventoryRec.IdrId; buffersize = sizeof(inbuff); if (fdebug) { printf("Rdr[%x] is inventory, IdrId=%x\n",rdr.RecordId,idrid); printf("Inv BufferSize=%d\n", buffersize); } if ( IsTagBmc((char *)rdr.IdString.Data, rdr.IdString.DataLength) ) { /* Get all of the inventory data areas and fields */ memset(inv,0,buffersize); rv_rdr = saHpiIdrInfoGet(sessionid, resourceid, idrid, &idrInfo); if (rv_rdr != SA_OK) { printf("IDR Info error: rv_rdr = %d\n",rv_rdr); } else { /* idrInfo is ok */ if (fdebug) printf("IDR Info: ok \n"); print_epath(&rptentry.ResourceEntity, 1); printf("RDR[%x]: Inventory, IdrId=%x %s\n",rdr.RecordId, idrid,rdr.IdString.Data); print_idrinfo(&idrInfo,4); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr); } if (!ent_writable(&rptentry.ResourceEntity,&idrInfo)) foundasset = 0; if ((fasset == 1) && (foundasset == 1)) { SaHpiIdrFieldT atagField; atagField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG; atagField.ReadOnly = SAHPI_FALSE; atagField.AreaId = atag.areaid; atagField.FieldId = atag.fieldid; strptr=&(atagField.Field); strptr->DataType = SAHPI_TL_TYPE_TEXT; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)atag.tlen; strncpy((char *)strptr->Data, atag.tag, atag.tlen); strptr->Data[atag.tlen] = 0; printf( "Writing new asset tag: %s\n",strptr->Data); rv_rdr = saHpiIdrFieldSet(sessionid, resourceid, atag.idrid, &atagField); printf("Return Write Status = %d\n", rv_rdr); if (rv_rdr == SA_OK) { printf ("Good write - re-reading!\n"); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr); } /* Good write - re-read */ } /*endif fasset*/ } /*endif RDR tag ok*/ } /* Inventory Data Records - Type 3 */ else if (fdebug) printf("rdr type = %d\n", rdr.RdrType); } /*endif RdrGet ok*/ entryid = nextentryid; } /*end while rdr*/ } /*endif rpt invent capab*/ else if (fdebug) printf("Resource[%d] Tag: %s\n", rptentryid, rptentry.ResourceTag.Data); } /*endif rpt ok*/ rptentryid = nextrptentryid; } /*end rpt loop */ if (fdebug) printf("loop %d inventory found = %d\n",nloops,invfound); } /*end while no inv */ rv = saHpiSessionClose(sessionid); exit(0); }
/* * Main */ int main(int argc, char **argv) { SaErrorT rv = SA_OK; oHpiGlobalParamTypeT paramtype = OHPI_CONF; char setparam[OH_PATH_PARAM_MAX_LENGTH]; SaHpiBoolT printusage = FALSE; int i=1; GOptionContext *context; enum cmdT {eUndefined, eGlobalParamGet, eGlobalParamSet} cmd=eUndefined; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="command [specific arguments] - " "Control openhpi configuration parameters.\n " OH_SVN_REV "\n\n" OHPARAM_HELP ; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION // not applicable - OHC_VERBOSE_OPTION )) { // no verbose mode printusage = TRUE; } g_option_context_free (context); /* Parse ohparam specific commands */ while (i<argc && !printusage) { if (strcmp(argv[i],"get")==0) { cmd=eGlobalParamGet; } else if (strcmp(argv[i],"set")==0) { cmd=eGlobalParamSet; if (++i<argc) { if (strcmp(argv[i],"OPENHPI_ON_EP")==0) paramtype=OHPI_ON_EP; else if (strcmp(argv[i],"OPENHPI_LOG_ON_SEV")==0) paramtype=OHPI_LOG_ON_SEV; else if (strcmp(argv[i],"OPENHPI_EVT_QUEUE_LIMIT")==0) paramtype=OHPI_EVT_QUEUE_LIMIT; else if (strcmp(argv[i],"OPENHPI_DEL_SIZE_LIMIT")==0) paramtype=OHPI_DEL_SIZE_LIMIT; else if (strcmp(argv[i],"OPENHPI_DEL_SAVE")==0) paramtype=OHPI_DEL_SAVE; else if (strcmp(argv[i],"OPENHPI_DAT_SIZE_LIMIT")==0) paramtype=OHPI_DAT_SIZE_LIMIT; else if (strcmp(argv[i],"OPENHPI_DAT_USER_LIMIT")==0) paramtype=OHPI_DAT_USER_LIMIT; else if (strcmp(argv[i],"OPENHPI_DAT_SAVE")==0) paramtype=OHPI_DAT_SAVE; else if (strcmp(argv[i],"OPENHPI_PATH")==0) paramtype=OHPI_PATH; else if (strcmp(argv[i],"OPENHPI_VARPATH")==0) paramtype=OHPI_VARPATH; else if (strcmp(argv[i],"OPENHPI_CONF")==0) paramtype=OHPI_CONF; else printusage = TRUE; } else printusage = TRUE; if (++i<argc) strcpy(setparam, argv[i]); else if (i>=argc) printusage = TRUE; } else printusage = TRUE; i++; } if (printusage == TRUE || cmd == eUndefined) { printf("\n"); printf("Usage: %s [Option...] command [specific arguments]\n\n", argv[0]); printf(OHPARAM_HELP"\n"); printf(" Options: \n"); printf(" -h, --help Show help options \n"); printf(" -D, --domain=nn Select domain id nn \n"); printf(" -X, --debug Display debug messages \n"); printf(" -N, --host=\"host<:port>\" Open session to the domain served by the daemon \n"); printf(" at the specified URL (host:port) \n"); printf(" This option overrides the OPENHPI_DAEMON_HOST and \n"); printf(" OPENHPI_DAEMON_PORT environment variables. \n"); printf(" -C, --cfgfile=\"file\" Use passed file as client configuration file \n"); printf(" This option overrides the OPENHPICLIENT_CONf \n"); printf(" environment variable. \n\n"); return 1; } rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return -1; switch (cmd){ case eGlobalParamGet: rv = execglobalparamget ( ); break; case eGlobalParamSet: rv = execglobalparamset ( paramtype, setparam ); break; default: printf("\n\nSorry, this function is not implemented yet\n\n"); rv = SA_ERR_HPI_INVALID_PARAMS; } if (rv == SA_OK) { rv = saHpiSessionClose(sessionid); return 0; } printf("Param set failed with returncode %s\n", oh_lookup_error(rv)); return rv; }