Example #1
0
int
closeSaHpiSession ()
{

  DEBUGMSGTL ((AGENT, "--- closeSaHpiSession: Entry. "));
  if (session_avail == AGENT_TRUE)
    {
      err = saHpiUnsubscribe (session_id);
      if (SA_OK != err)
	{
	  snmp_log (LOG_ERR, "saHpiUnsubscirbe error: %s.\n",
		    get_error_string (err));
	  return AGENT_ERR_SESSION_CLOSE;
	}
      err = saHpiFinalize ();
      if (SA_OK != err)
	{
	  snmp_log (LOG_ERR, "saHpiFinalize error: %s\n",
		    get_error_string (err));
	  return AGENT_ERR_SESSION_CLOSE;
	}
      session_avail = AGENT_FALSE;
    }
  DEBUGMSGTL ((AGENT, "--- closeSaHpiSession: Exit. "));

  return AGENT_ERR_NOERROR;
}
Example #2
0
int close_session()
{
	SaErrorT rv;

	pthread_kill(ge_thread, SIGKILL);
	
	rv = saHpiSessionClose(sessionid);
	if (rv != SA_OK) {
                printf("saHpiSessionClose error %d\n", rv);
                return -1;
        }
	rv = saHpiFinalize();
	 if (rv != SA_OK) {
                printf("saHpiFinalize error %d\n", rv);
                return -1;
        }
	return 0;
}
Example #3
0
void
cOpenHpiDaemon::Finalize()
{  
  while( m_num_connections )
       CloseConnection( 0 );

  if ( m_pollfd )
       delete [] m_pollfd;

  if ( m_main_socket )
     {
       ServerConnectionMainClose(  m_main_socket );
       m_main_socket = 0;
     }

  saHpiUnsubscribe( m_session );
  saHpiSessionClose( m_session );
  saHpiFinalize();
}
Example #4
0
/**
 * main: main program loop
 *
 *
 *
 * Return value: int 0
 **/
int main(int arc, const char *argv[])
{
        SaErrorT 		err;
        SaHpiVersionT		version;
        SaHpiSessionIdT 	session_id;
        SaHpiRptEntryT		entry;
        //SaHpiSelInfoT		Info;
        
	
	/* First step in HPI and openhpi */
        err = saHpiInitialize(&version);
        if (SA_OK != err) {
                error("saHpiInitialize", err);
                exit(-1);
        }
        
	/* Every domain requires a new session */
	/* This example is for one domain, one session */
        err = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID, &session_id, NULL);
        if (SA_OK != err) {
                error("saHpiSessionOpen", err);
                return err;
        }
        
        err = discover_domain(SAHPI_DEFAULT_DOMAIN_ID, session_id, entry);
        if (SA_OK != err) {
                warn("an error was encountered, results may be incomplete");
        }

        saHpiSessionClose(session_id);

        err = saHpiFinalize();
        if (SA_OK != err) {
                error("saHpiFinalize", err);
                exit(-1);

	}
	return 0;
}
Example #5
0
int main(int argc, char *argv[])
{
	SaErrorT err;
	SaHpiVersionT version;

	err = saHpiInitialize(&version);
	if (SA_OK != err) {
		error("saHpiInitialize", err);
		exit(-1);
	}
	
	err = discover_domain(SAHPI_DEFAULT_DOMAIN_ID);
	if (SA_OK != err) {
		warn("an error was encountered, results may be incomplete");
	}

	err = saHpiFinalize();
	if (SA_OK != err) {
		error("saHpiFinalize", err);
		exit(-1);
	}
	return 0;
}
Example #6
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);
}
Example #7
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;
}
Example #8
0
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);
}
Example #9
0
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);
}
Example #10
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);
}
Example #11
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;
}
Example #12
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);
}
Example #13
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);
}
Example #14
0
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);
}
Example #15
0
bool
cOpenHpiDaemon::Initialize()
{
  if ( m_daemon )
     {
       DbgInit( "become a daemon.\n" );

       pid_t pid = fork();

       if ( pid < 0 )
	  {
	    fprintf( stderr, "cannot fork: %s !\n",
		     strerror( errno ) );
	    return false;
	  }

       // parent process
       if ( pid != 0 )
	    exit( 0 );

       // become the session leader
       setsid();

       // second fork to become a real daemon
       pid = fork();

       if ( pid < 0 )
	  {
	    fprintf( stderr, "cannot fork: %s !\n",
		     strerror( errno ) );
	    return false;
	  }

       // parent process
       if ( pid != 0 )
	    exit( 0 );

       chdir( "/" );

       umask( 0 );
     }

  // use config file given by the command line
  if ( m_config )
       setenv( "OPENHPI_CONF", m_config, 1 );

  // initialize openhpi
  DbgInit( "initialize openhpi.\n" );
  SaErrorT rv = saHpiInitialize( &m_version );

  if ( rv != SA_OK )
     {
       fprintf( stderr, "cannot initialize openhpi: %s !\n",
		decode_error( rv ) );
       return false;
     }

  // create a session
  rv = saHpiSessionOpen( SAHPI_DEFAULT_DOMAIN_ID, &m_session, 0 );

  if ( rv != SA_OK )
     {
       fprintf( stderr, "cannot create session: %s !\n", 
		decode_error( rv ) );

       saHpiFinalize();
       return false;
     }

  // subscribe
  rv = saHpiSubscribe( m_session, SAHPI_TRUE );

  if ( rv != SA_OK )
     {
       fprintf( stderr, "cannot subscribe: %s !\n", 
		decode_error( rv ) );

       saHpiSessionClose( m_session );
       saHpiFinalize();
       return false;
     }

  // open daemon socket
  DbgInit( "create daemon connection port %d.\n", m_daemon_port );

  m_main_socket = ServerConnectionMainOpen( m_daemon_port );

  if ( !m_main_socket )
     {
       fprintf( stderr, "cannot create daemon socket: %d, %s !\n",
                errno, strerror( errno ) );

       saHpiUnsubscribe( m_session );
       saHpiSessionClose( m_session );
       saHpiFinalize();
       return false;
     }

  if ( m_interactive )
       DbgInit( "interactive\n" );

  DbgInit( "daemon is up.\n" );

  return true;
}
Example #16
0
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;
}
Example #17
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);
}
Example #18
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);
}
Example #19
0
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);
}