Procházet zdrojové kódy

remote_control ipmc ok

zhangbo před 3 roky
rodič
revize
9ec59f4ef0

+ 2 - 66
app/goahead-3.6.5/src/libipmi/inc/libipmi_ChassisDevice.h

@@ -32,71 +32,7 @@ extern "C" {
 
 
 uint16_t  IPMICMD_ChassisControl( IPMI20_UDS_SESSION_T *pUDSSession, int timeout, char cmd);
-
-
-// /**
-//    \breif	Higher level function for PowerOff Host.
-//    @param	pUDSSession		[in]Session handle
-//    @param	timeout			[in]timeout value in seconds.
-
-//    @retval Returns LIBIPMI_STATUS_SUCCESS on success and error codes on failure
-// */
-//   uint16_t LIBIPMI_HL_PowerOff( IPMI20_UDS_SESSION_T *pUDSSession/*in*/, int timeout/*in*/);
-
-
-
-// /**
-//    \breif	Higher level function for PowerUP Host
-//    @param	pUDSSession		[in]Session handle
-//    @param	timeout			[in]timeout value in seconds.
-
-//    @retval Returns LIBIPMI_STATUS_SUCCESS on success and error codes on failure
-// */
-//   uint16_t LIBIPMI_HL_PowerUp( IPMI20_UDS_SESSION_T *pUDSSession/*in*/, int timeout/*in*/);
-
-
-
-// /**
-//    \breif	Higher level function for PowerCycle host.
-//    @param	pUDSSession		[in]Session handle
-//    @param	timeout			[in]timeout value in seconds.
-
-//    @retval Returns LIBIPMI_STATUS_SUCCESS on success and error codes on failure
-// */
-//   uint16_t LIBIPMI_HL_PowerCycle( IPMI20_UDS_SESSION_T *pUDSSession, int timeout );
-
-
-
-// /**
-//    \breif	Higher level function for HardReset
-//    @param	pUDSSession		[in]Session handle
-//    @param	timeout			[in]timeout value in seconds.
-
-//    @retval Returns LIBIPMI_STATUS_SUCCESS on success and error codes on failure
-// */
-//   uint16_t LIBIPMI_HL_HardReset( IPMI20_UDS_SESSION_T *pUDSSession, int timeout );
-    
-
-// /**
-//    \breif	Higher level function for DiagInt
-//    @param	pUDSSession		[in]Session handle
-//    @param	timeout			[in]timeout value in seconds.
-
-//    @retval Returns LIBIPMI_STATUS_SUCCESS on success and error codes on failure
-// */
-//   uint16_t LIBIPMI_HL_DiagInt( IPMI20_UDS_SESSION_T *pUDSSession, int timeout );
-    
-
-// /**
-//    \breif	Higher level function for SoftOff
-//    @param	pUDSSession		[in]Session handle
-//    @param	timeout			[in]timeout value in seconds.
-
-//    @retval Returns LIBIPMI_STATUS_SUCCESS on success and error codes on failure
-// */
-//   uint16_t LIBIPMI_HL_SoftOff( IPMI20_UDS_SESSION_T *pUDSSession, int timeout );
-    
-
+uint16_t IPMC_ChassisControl( IPMI20_UDS_SESSION_T *pUDSSession, uint8_t IpmbAddr, int timeout, char cmd);
 
 typedef enum tag_CHASSIS_ID_STATE
 {
@@ -123,7 +59,7 @@ typedef struct tag_chassis_status_T
  * @return  Returns LIBIPMI_STATUS_SUCCESS on success and error codes on failure
  */
   uint16_t	LIBIPMI_HL_GetChassisStatus( IPMI20_UDS_SESSION_T *pUDSSession, int timeout,  chassis_status_T *status);
-
+uint16_t	IPMC_GetChassisStatus( IPMI20_UDS_SESSION_T *pUDSSession, uint8_t IpmbAddr, int timeout, chassis_status_T *status);
 /*---------------------Chassis Idnetify defines ---------------------*/
 #define CHASSIS_ID_INTERVAL_TURN_OFF		0
 #define CHASSIS_ID_INTERVAL_SPEC_DEFAULT   	15

+ 101 - 97
app/goahead-3.6.5/src/libipmi/src/libipmi_Chassis.c

@@ -24,6 +24,7 @@
 #include "libipmi_session.h"
 #include "libipmi_errorcodes.h"
 #include "libipmi_ChassisDevice.h"
+#include "com_IPMI_App.h"
 
 #include "string.h"
 
@@ -55,6 +56,38 @@ uint16_t IPMICMD_ChassisControl( IPMI20_UDS_SESSION_T *pUDSSession, int timeout,
     return wRet;
 }
 
+uint16_t IPMC_ChassisControl( IPMI20_UDS_SESSION_T *pUDSSession, uint8_t IpmbAddr, int timeout, char cmd)
+{
+	uint16_t 	wRet = 0;
+	uint8_t 	Req[10] = {0};
+	uint8_t		Res[10];
+	uint16_t 	strLen, remainLen;
+	uint32_t	dwResLen;
+	
+	//get title
+	Req[0] = 0x40;	//Track | channel 0
+	Req[1] = IpmbAddr;
+	Req[2] = NETFNLUN_IPMI_CHASSIS;
+	Req[3] = 0x100 - (Req[1] + Req[2])&0xff;	//checksum1
+	Req[4] = 0x20;
+	Req[5] = 0x10;
+	Req[6] = CMD_CHASSIS_CONTROL;	
+	Req[7] = cmd;
+	Req[8] = 0x100 - (Req[4] + Req[5] + Req[6] + Req[7])&0xff;
+
+	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession, 
+											DEFAULT_NET_FN_LUN, CMD_SEND_MSG,
+											Req, 9,
+											Res, &dwResLen,
+											timeout);
+	if((wRet != 0) || (Res[6] != 0))
+	{
+		printf("IPMC_ChassisControl faile\n" );
+		return -1;
+	}
+
+    return 0;
+}
 
 uint16_t IPMICMD_GetSystemBootOptions(IPMI20_UDS_SESSION_T *pUDSSession, GetBootOptionsReq_T* pReqGetBootOptions,
 							 GetBootOptionsRes_T* pResGetBootOptions,int reslen,int timeout)
@@ -155,101 +188,15 @@ uint16_t IPMICMD_ChassisIdentify(IPMI20_UDS_SESSION_T *pUDSSession,int timeout,C
 }
 
 
-// uint16_t LIBIPMI_HL_PowerOff( IPMI20_UDS_SESSION_T *pUDSSession, int timeout )
-// {
-//     uint16_t	wRet;
-
-//     wRet = IPMICMD_ChassisControl( pUDSSession, timeout, CHASSIS_POWEROFF);
-
-//     if (wRet == LIBIPMI_E_SUCCESS){
-// 	TDBG("Succefully executed powerOFF  command.\n");
-//     }else
-// 	TDBG("Error: PowerOFF Command Failed.\n");
-	
-//     return wRet;
-// }
-
-// uint16_t LIBIPMI_HL_PowerUp( IPMI20_UDS_SESSION_T *pUDSSession, int timeout )
-// {
-//     uint16_t	wRet;
-
-//     wRet = IPMICMD_ChassisControl( pUDSSession, timeout, CHASSIS_POWERUP);
-
-//     if (wRet == LIBIPMI_E_SUCCESS){
-// 	TDBG("Succefully executed powerUP the command.\n");
-//     }else
-// 	TDBG("Error: PowerUp Command Failed.\n");
-	
-//     return wRet;
-// }
-
-// uint16_t LIBIPMI_HL_PowerCycle( IPMI20_UDS_SESSION_T *pUDSSession, int timeout )
-// {
-//     uint16_t	wRet;
-
-//     wRet = IPMICMD_ChassisControl( pUDSSession, timeout, CHASSIS_POWERCYCLE);
-
-//     if (wRet == LIBIPMI_E_SUCCESS){
-// 	TDBG("Succefully executed powerCycle the command.\n");
-//     }else
-// 	TDBG("Error: PowerCycle Command Failed.\n");
-	
-//     return wRet;
-// }
-
-// uint16_t LIBIPMI_HL_HardReset( IPMI20_UDS_SESSION_T *pUDSSession, int timeout )
-// {	//TODO: jimbo control rst1~10 pin
-//     uint16_t	wRet;
-
-//     wRet = IPMICMD_ChassisControl( pUDSSession, timeout, CHASSIS_HARDRESET);
-
-//     if (wRet == LIBIPMI_E_SUCCESS){
-// 	TDBG("Succefully executed HardReset the command.\n");
-//     }else
-// 	TDBG("Error: HardReset Command Failed.\n");
-	
-//     return wRet;
-// }
-
-// uint16_t LIBIPMI_HL_DiagInt( IPMI20_UDS_SESSION_T *pUDSSession, int timeout )
-// {
-//     uint16_t	wRet;
-
-//     wRet = IPMICMD_ChassisControl( pUDSSession, timeout, CHASSIS_DIAGINT);
-
-//     if (wRet == LIBIPMI_E_SUCCESS){
-// 	TDBG("Succefully executed DiagInt command.\n");
-//     }else
-// 	TDBG("Error: DiagInt Command Failed.\n");
-	
-//     return wRet;
-// }
-
-// uint16_t LIBIPMI_HL_SoftOff( IPMI20_UDS_SESSION_T *pUDSSession, int timeout )
-// {
-//     uint16_t	wRet;
-
-//     wRet = IPMICMD_ChassisControl( pUDSSession, timeout, CHASSIS_SOFTOFF);
-
-//     if (wRet == LIBIPMI_E_SUCCESS){
-// 	TDBG("Succefully executed SoftOff command.\n");
-//     }else
-// 	TDBG("Error: SoftOff Command Failed.\n");
-	
-//     return wRet;
-// }
 
 uint16_t	LIBIPMI_HL_GetChassisStatus( IPMI20_UDS_SESSION_T *pUDSSession, int timeout, chassis_status_T *status)
 {
-
     uint32_t		dwResLen;
     uint16_t		wRet;
     uint8_t		ChassisStatusReq;
     GetChassisStatusRes_T ChassisStatusRes;
     uint8_t		powerState = -1;
 
-    dwResLen = sizeof(GetChassisStatusRes_T);
-    
     wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
 					    NETFNLUN_IPMI_CHASSIS, CMD_GET_CHASSIS_STATUS,
 					    (uint8_t *)&ChassisStatusReq, 0 ,
@@ -257,27 +204,21 @@ uint16_t	LIBIPMI_HL_GetChassisStatus( IPMI20_UDS_SESSION_T *pUDSSession, int tim
 					    timeout);
     
     powerState = ChassisStatusRes.ChassisPowerState.PowerState ;
-    
-//    TINFO("PowerState is %d \n", powerState);
-    
     status->power_state = powerState & 0x01;
-
     status->last_power_event = ChassisStatusRes.ChassisPowerState.LastPowerEvent;
-
-
     if(ChassisStatusRes.ChassisPowerState.MiscChassisState & CHASSIS_IDENTITY_STATE_INFO_SUPPORTED)
     {
-	status->chassis_indetify_supported = 1;
+		status->chassis_indetify_supported = 1;
     }
     else
     {
-	status->chassis_indetify_supported = 0;
+		status->chassis_indetify_supported = 0;
     }
 
 
     if(ChassisStatusRes.ChassisPowerState.MiscChassisState & CHASSIS_IDENTITY_INDEFINITE_ON)
     {
-	status->chassis_identify_state = CHASSIS_ID_INDEFINITE_ON;
+		status->chassis_identify_state = CHASSIS_ID_INDEFINITE_ON;
     }
     else if(ChassisStatusRes.ChassisPowerState.MiscChassisState & CHASSIS_IDENTITY_TIMED_ON)
     {
@@ -285,12 +226,75 @@ uint16_t	LIBIPMI_HL_GetChassisStatus( IPMI20_UDS_SESSION_T *pUDSSession, int tim
     }
     else
     {
-	status->chassis_identify_state = CHASSIS_ID_OFF;
+		status->chassis_identify_state = CHASSIS_ID_OFF;
     }
     
-    return wRet;
+    return 0;
 }
 
+uint16_t	IPMC_GetChassisStatus( IPMI20_UDS_SESSION_T *pUDSSession, uint8_t IpmbAddr, int timeout, chassis_status_T *status)
+{
+
+	uint16_t 	wRet = 0;
+	uint8_t 	Req[10] = {0};
+	uint8_t		Res[10];
+	uint16_t 	strLen, remainLen;
+	uint32_t	dwResLen;
+	GetChassisStatusRes_T *pChassisStatusRes;
+	uint8_t		powerState = -1;
+	
+
+	//get title
+	Req[0] = 0x40;	//Track | channel 0
+	Req[1] = IpmbAddr;
+	Req[2] = NETFNLUN_IPMI_CHASSIS;
+	Req[3] = 0x100 - (Req[1] + Req[2])&0xff;	//checksum1
+	Req[4] = 0x20;
+	Req[5] = 0x10;
+	Req[6] = CMD_GET_CHASSIS_STATUS;	
+	Req[7] = 0x100 - (Req[4] + Req[5] + Req[6])&0xff;
+
+	//dwResLen = sizeof(GetDevIDRes_T);
+	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession, 
+											DEFAULT_NET_FN_LUN, CMD_SEND_MSG,
+											Req, 8,
+											Res, &dwResLen,
+											timeout);
+    if((wRet != 0) || (Res[6] != 0))
+	{
+		printf("---> IPMC_GetChassisStatus error\n");
+		return -1;
+	}
+    
+    pChassisStatusRes = (GetChassisStatusRes_T *)&Res[6];
+    powerState = pChassisStatusRes->ChassisPowerState.PowerState ;
+    status->power_state = powerState & 0x01;
+    status->last_power_event = pChassisStatusRes->ChassisPowerState.LastPowerEvent;
+    if(pChassisStatusRes->ChassisPowerState.MiscChassisState & CHASSIS_IDENTITY_STATE_INFO_SUPPORTED)
+    {
+		status->chassis_indetify_supported = 1;
+    }
+    else
+    {
+		status->chassis_indetify_supported = 0;
+    }
+
+
+    if(pChassisStatusRes->ChassisPowerState.MiscChassisState & CHASSIS_IDENTITY_INDEFINITE_ON)
+    {
+		status->chassis_identify_state = CHASSIS_ID_INDEFINITE_ON;
+    }
+    else if(pChassisStatusRes->ChassisPowerState.MiscChassisState & CHASSIS_IDENTITY_TIMED_ON)
+    {
+        status->chassis_identify_state = CHASSIS_ID_TIMED_ON;
+    }
+    else
+    {
+		status->chassis_identify_state = CHASSIS_ID_OFF;
+    }
+    
+    return 0;
+}
 
 //will turn chassis identify on or off
 //BlinkTime - Set to TURN_OFF for turning off indefinitely

+ 44 - 30
app/goahead-3.6.5/src/web_interface/src/remote_control.c

@@ -27,8 +27,12 @@ void chassisPwrCtrl(Webs *wp){
 	char cmd = -1;
 	char *pwrAction = NULL;
 	int ret;
+    uint8_t target_addr;
+    uint16_t wRet;
 	pwrAction = websGetVar(wp, "pwrAction", NULL);
 
+    //wp->index = 1;
+
 	if(strcmp(pwrAction, "on") == 0)
 		cmd = 1;
 	else if(strcmp(pwrAction, "off") == 0)
@@ -42,9 +46,9 @@ void chassisPwrCtrl(Webs *wp){
 	else if(strcmp(pwrAction, "soft") == 0)
 		cmd = 5;
 
-	printf("Get pwrAction: %s, cmd: %d\n", pwrAction, cmd);
+//	printf("Get pwrAction: %s, cmd: %d\n", pwrAction, cmd);
 
-	char *pStr;
+	
     cJSON * root =  cJSON_CreateObject();
     cJSON * data =  cJSON_CreateObject();
     cJSON_AddItemToObject(root, "data", data);//根节点下添加
@@ -56,10 +60,22 @@ void chassisPwrCtrl(Webs *wp){
 	{
 		//Create session
 	    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
-	    IPMICMD_ChassisControl( &UDSSession, DEFAULT_TIMEOUT, cmd);
+        target_addr = gIPMBAddr[wp->index];
+        if(target_addr == 0x20)
+        {
+	       wRet = IPMICMD_ChassisControl( &UDSSession, DEFAULT_TIMEOUT, cmd);
+        }
+        else
+        {
+            wRet = IPMC_ChassisControl( &UDSSession, target_addr, DEFAULT_TIMEOUT, cmd);
+        }
 	    //Close session
 	    LIBIPMI_CloseSession(&UDSSession );
-	    cJSON_AddStringToObject(data, "status", "success");
+
+        if(wRet != 0)
+            cJSON_AddStringToObject(data, "status", "fail");
+        else    
+	       cJSON_AddStringToObject(data, "status", "success");
 	}
 	else
 	{
@@ -67,22 +83,16 @@ void chassisPwrCtrl(Webs *wp){
 		cJSON_AddStringToObject(data, "status", "fail");
 	}
 
+    char *pStr;
     pStr = cJSON_PrintUnformatted(root);
-
-//    printf("---> cJSON Str: %d\n%s\n", strlen(pStr), pStr);
     websSetStatus(wp, 200);
     websWriteHeaders(wp, -1, 0);
     websWriteEndHeaders(wp);
-    ret = websWrite(wp, "%s", pStr);
-    if(ret < 0)
-    	printf("websWrite error\n");
-    
-    ret = websFlush(wp, 1);	//wait for all data to be written to the socket 
-  	printf("websFlush ret = %d\n", ret);
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);	
     websDone(wp);
+    printf("---> cJSON Str: %d\n%s\n", strlen(pStr), pStr);
 
-    // if(pwrAction)
-    // 	wfree(pwrAction);
     if(pStr)
         wfree(pStr);
     if(root)
@@ -95,15 +105,26 @@ void getChassisStatus(Webs *wp)
 {
 	chassis_status_T chassisSta;
 	IPMI20_UDS_SESSION_T    UDSSession;
-	int ret;
+    uint8_t target_addr;
+    uint16_t wRet;
+
+    //wp->index = 1;
 
 	//Create session
     LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
-    LIBIPMI_HL_GetChassisStatus(&UDSSession, DEFAULT_TIMEOUT, &chassisSta);
+    target_addr = gIPMBAddr[wp->index];
+    if(target_addr == 0x20)
+    {
+        wRet = LIBIPMI_HL_GetChassisStatus(&UDSSession, DEFAULT_TIMEOUT, &chassisSta);
+    }
+    else
+    {
+        wRet = IPMC_GetChassisStatus(&UDSSession, target_addr, DEFAULT_TIMEOUT, &chassisSta);
+    }
     //Close session
     LIBIPMI_CloseSession(&UDSSession );
 
-    char *pStr;
+    
     cJSON * root =  cJSON_CreateObject();
     cJSON * data =  cJSON_CreateObject();
     cJSON_AddItemToObject(root, "data", data);//根节点下添加
@@ -118,22 +139,15 @@ void getChassisStatus(Webs *wp)
     	cJSON_AddStringToObject(data, "powerStatus", "on" );	
     }
 
-    pStr = cJSON_PrintUnformatted(root);
-
-//    printf("---> cJSON Str: %d \n%s\n", strlen(pStr), pStr);
+    char *pStr;
+    pStr = cJSON_PrintUnformatted(root); 
     websSetStatus(wp, 200);
-    websWriteHeaders(wp, -1, 0);	//Set length to -1 if unknown and transfer-chunk-encoding will be employed.
+    websWriteHeaders(wp, -1, 0);
     websWriteEndHeaders(wp);
-
-    ret = websWrite(wp, "%s", pStr);
-    if(ret < 0)
-    	printf("websWrite error\n");
-    
-    ret = websFlush(wp, 1);	//wait for all data to be written to the socket 
-    if(ret != 1)
-    	printf("websFlush error, ret = %d\n", ret);
-    
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);	
     websDone(wp);
+    printf("---> cJSON Str: %d \n%s\n", strlen(pStr), pStr);
 
     if(pStr)
         wfree(pStr);