Explorar o código

Implement SendMsg command

zhangbo %!s(int64=5) %!d(string=hai) anos
pai
achega
10ea29030e

+ 1 - 1
app/bmc/Api.c

@@ -638,7 +638,7 @@ int getSensorHistory(uint8_t sensorNum, uint8_t *phistoryBuf)
 	
 	if(i >= SENSOR_NUMBERS)
 	{
-		printf("---> can't find sensorNum!\n");
+		printf("Warning: Can't find sensorNum!\n");
 		return -1;
 	}
 }

+ 2 - 2
app/bmc/Session.h

@@ -116,8 +116,8 @@ typedef struct
     uint8_t			UserId;
     uint8_t			SessionHandle;
 //     uint8_t			ChallengeString[CHALLENGE_STR_LEN];
-//     LANRMCPPkt_T	LANRMCPPkt;
-//     int			hSocket;
+    LANRMCPPkt_T	LANRMCPPkt;
+    int			hSocket;
 //     BOOL			SerialModemMode;
     uint32_t 			Time;
 // #if (IPMI20_SUPPORT == 1)

BIN=BIN
app/bmc/bmc_app


+ 40 - 19
app/bmc/ipmb/IPMBIfc.c

@@ -164,31 +164,39 @@ void *IPMBIfcTask(void *Param)
 	{		
 		while(GetMsg(fd_IpmbIfcQ, &RcvMsgPkt, WAIT_INFINITE) != 0);
 		
+        // printf("======== IPMB Get message ========\n");
+        // printf("gFd_LanIfcQ %d, gFd_LanResQ %d, gFd_MsgHndlrIfc %d\n", 
+        //         gFd_LanIfcQ,gFd_LanResQ,gFd_MsgHndlrIfc);
 		switch(RcvMsgPkt.Param)
 		{
 			case PARAM_REQUEST:
+                //printf("---> IPMBIfcTask/PARAM_REQUEST\n");
 				ProcessIPMBReq (&RcvMsgPkt);
 				break;
 			case PARAM_BRIDGE:
-                printf("---> BRIDGING_REQUEST, channel: %d\n", RcvMsgPkt.Channel);
-                int i;
-                for(i=0;i<RcvMsgPkt.Size;i++)
-                    printf("%#x ", RcvMsgPkt.Data[i]);
-                printf("\n");
+                //printf("---> IPMBIfcTask/PARAM_BRIDGE, channel: %d\n", RcvMsgPkt.Channel);
+                
                 /* Send the response */
                 if(RcvMsgPkt.Channel == PRIMARY_IPMB_CHANNEL)
                 {
                     RetVal = stm32_i2c_master_write(gFd_Primary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size-1);
+                    //printf("PriTx: ");
                 }
                 else if(RcvMsgPkt.Channel == SECONDARY_IPMB_CHANNEL)
                 {
                     RetVal = stm32_i2c_master_write(gFd_Secondary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size-1);
+                    //printf("SecTx: ");
                 }
                 else
                 {
                     printf("IPMBIfc.c: IPMB channel error. %#x\r\n", RcvMsgPkt.Channel);
                 }
 
+                // int i;
+                // for(i=0;i<RcvMsgPkt.Size;i++)
+                //     printf("%#x ", RcvMsgPkt.Data[i]);
+                // printf("\n");
+
                 if (RetVal < 0)
                 {
                     printf ("IPMBIfc.c : Unable to send a IPMI Bridge Message\n");
@@ -240,6 +248,19 @@ ProcessIPMBReq ( MsgPkt_T* pReq)
     else
     	pReq->SrcQ 			= gFd_SecondaryIpmbResQ;
 	
+    if(0 == ValidateMsgHdr(pReq))
+    {
+        /* Post the message to message handler Task */
+        if (0 != PostMsg (gFd_MsgHndlrIfc, pReq))
+        {
+            printf("IPMB post message to MsgHndlrTask fail!\n");;
+        }
+    }
+    else
+    {
+         //printf("Bridge response to Originator\n");
+         return;
+    }
     /* Post the message to message handler Task */
     PostMsg (gFd_MsgHndlrIfc, pReq);
        
@@ -277,24 +298,24 @@ ProcessIPMBReq ( MsgPkt_T* pReq)
         pthread_mutex_lock(&primary_mutex);
 		RetVal = stm32_i2c_master_write(gFd_Primary, ResPkt.Data[0], &ResPkt.Data[1], ResPkt.Size-1);
         pthread_mutex_unlock(&primary_mutex);
-        printf("PriTx: ");
+        //printf("PriTx: ");
 	}
 	else if(pReq->Channel == SECONDARY_IPMB_CHANNEL)
 	{
         pthread_mutex_lock(&secondary_mutex);
 		RetVal = stm32_i2c_master_write(gFd_Secondary, ResPkt.Data[0], &ResPkt.Data[1], ResPkt.Size-1);
         pthread_mutex_unlock(&secondary_mutex);
-        printf("SecTx: ");
+        //printf("SecTx: ");
 	}
 	else
 	{
 		printf("IPMBIfc.c: IPMB channel error. %#x\r\n", pReq->Channel);
 	}
 
-    int i;
-    for(i=0;i<ResPkt.Size;i++)
-        printf("%#x ", ResPkt.Data[i]);
-    printf("\n");
+    // int i;
+    // for(i=0;i<ResPkt.Size;i++)
+    //     printf("%#x ", ResPkt.Data[i]);
+    // printf("\n");
 	
     if (0 != RetVal)
     {
@@ -435,15 +456,15 @@ static void* RecvIPMBPkt (void *Param)
             IPMBReqPkt.Param    = PARAM_REQUEST;
             IPMBReqPkt.Size     = retval + 1;       /* +1 to include BMC Slave address */
 
-            int cnt;
-            if(0 == ipmbSelect)
-                printf("\nPriRx: ");
-            else
-                printf("\nSecRx: ");
+            // int cnt;
+            // if(0 == ipmbSelect)
+            //     printf("\nPriRx: ");
+            // else
+            //     printf("\nSecRx: ");
 
-            for(cnt=0;cnt < IPMBReqPkt.Size; cnt++)
-                printf("%#x ", IPMBReqPkt.Data[cnt]);
-            printf("\n");
+            // for(cnt=0;cnt < IPMBReqPkt.Size; cnt++)
+            //     printf("%#x ", IPMBReqPkt.Data[cnt]);
+            // printf("\n");
 
             /* Post the IPMB Request message to IPMBIfc Queue */
             if(ipmbSelect == 0)

+ 76 - 79
app/bmc/lan/LANIfc.c

@@ -472,7 +472,7 @@ void *RecvLANPkt(void *pArg)
                 /* Post the request packet to LAN Interface Queue */
 				if (0 != PostMsg (gFd_LanIfcQ, &MsgPkt))
 				{
-					printf ("LANIfc.c : Error posting message to LANIfc Q\n");
+					printf ("Warning: LANIfc.c Error posting message to LANIfc Q\n");
 				}               
             }       
             else
@@ -516,7 +516,7 @@ int SendLANPkt (MsgPkt_T *pRes )
 		ret = sendto (pRes->Socket, pRes->Data, pRes->Size, 0, (struct sockaddr*)&Dest, sizeof (Dest));
 		if (ret == -1)
 		{
-			printf ("LANIfc.c : Error sending response packets to LAN, %s\n",strerror(errno));
+			printf ("Warning: LANIfc.c Error sending response packets to LAN, %s\n",strerror(errno));
 		}
 		// else
 		// {
@@ -544,28 +544,28 @@ ProcessLANReq (  MsgPkt_T* pReq )
 	/* Copy the request to response */
 	Res = *pReq;
 
-	// /* Save the LAN header inofmation */
-	// pSessionHdr  = (SessionHdr_T*) (((RMCPHdr_T*)pReq->Data) + 1);
-	// pSessionHdr2 = (SessionHdr2_T*)(((RMCPHdr_T*)pReq->Data) + 1);
-	// if (RMCP_PLUS_FORMAT == pSessionHdr->AuthType)
-	// {
-	// 	SessionID = pSessionHdr2->SessionID;
-	// 	pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
-	// }
-	// else
-	// {
-	// 	SessionID = pSessionHdr->SessionID;
-	// 	pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID );
-	// }
-	// if (NULL != pSessionInfo)
-	// {
-	// 	pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort = Res.UDPPort;
-	// 	pSessionInfo->hSocket                   = Res.Socket;
-	// 	SocktIndex=GetSocketInfoIndex(pSessionInfo->hSocket );
+	/* Save the LAN header inofmation */
+	pSessionHdr  = (SessionHdr_T*) (((RMCPHdr_T*)pReq->Data) + 1);
+	pSessionHdr2 = (SessionHdr2_T*)(((RMCPHdr_T*)pReq->Data) + 1);
+	if (RMCP_PLUS_FORMAT == pSessionHdr->AuthType)
+	{
+		SessionID = pSessionHdr2->SessionID;
+		pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
+	}
+	else
+	{
+		SessionID = pSessionHdr->SessionID;
+		pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID );
+	}
+	if (NULL != pSessionInfo)
+	{
+		pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort = Res.UDPPort;
+		pSessionInfo->hSocket                   = Res.Socket;
+		//SocktIndex=GetSocketInfoIndex(pSessionInfo->hSocket );
 		
-	// 	memcpy (pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, Res.IPAddr, sizeof (struct in_addr));
-	// 	memcpy (&pSessionInfo->LANRMCPPkt.RMCPHdr, Res.Data, sizeof (RMCPHdr_T));
-	// }
+		memcpy (pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, Res.IPAddr, sizeof (struct in_addr));
+		memcpy (&pSessionInfo->LANRMCPPkt.RMCPHdr, Res.Data, sizeof (RMCPHdr_T));
+	}
 
 	/* Process the RMCP Request */
 	Res.Size = ProcessRMCPReq ((RMCPHdr_T*)pReq->Data, (RMCPHdr_T*)Res.Data);
@@ -573,7 +573,7 @@ ProcessLANReq (  MsgPkt_T* pReq )
 	/* ResLen is 0, don't send the packet */
 	if (0 == Res.Size )
 	{
-        printf ("LANIfc.c : LAN request packet dropped, not processed\n");
+        printf ("Note: LANIfc.c LAN request packet dropped, not processed\n");
 	 	return;
 	}
 
@@ -589,25 +589,25 @@ ProcessLANReq (  MsgPkt_T* pReq )
 static void
 ProcessBridgeMsg (  MsgPkt_T* pReq )
 {
-// 	MsgPkt_T        ResPkt;
-// 	uint16_t          PayLoadLen   = 0;
-// 	uint8_t           PayLoadType  = 0;
-// 	//SessionInfo_T   *pSessionInfo = getSessionInfo (SESSION_HANDLE_INFO, pReq->Data);
+	MsgPkt_T        ResPkt;
+	uint16_t          PayLoadLen   = 0;
+	uint8_t           PayLoadType  = 0;
+	SessionInfo_T   *pSessionInfo = getSessionInfo (SESSION_HANDLE_INFO, pReq->Data);
 
- 	printf ("LANIfc: Bridge Request\n");
+ 	//printf ("LANIfc: Bridge Request\n");
 
-// 	if (NULL == pSessionInfo)
-// 	{
-// 		printf ("LANIfc: ProcessBridgeMsg - No Session with the LAN\n");
-// 		return;
-// 	}
+	if (NULL == pSessionInfo)
+	{
+		printf ("Warning: LANIfc ProcessBridgeMsg - No Session with the LAN\n");
+		return;
+	}
 
-// 	/* Copy Lan RMCP headers from Session Record */
-// 	ResPkt.UDPPort  = pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort;
-// 	ResPkt.Socket   = pSessionInfo->hSocket;
+	/* Copy Lan RMCP headers from Session Record */
+	ResPkt.UDPPort  = pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort;
+	ResPkt.Socket   = pSessionInfo->hSocket;
 	
-// 	memcpy (ResPkt.IPAddr, pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, sizeof (struct in_addr));
-// 	memcpy (ResPkt.Data, &pSessionInfo->LANRMCPPkt.RMCPHdr, sizeof (RMCPHdr_T));
+	memcpy (ResPkt.IPAddr, pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, sizeof (struct in_addr));
+	memcpy (ResPkt.Data, &pSessionInfo->LANRMCPPkt.RMCPHdr, sizeof (RMCPHdr_T));
 
 // #if IPMI20_SUPPORT == 1
 // 	if (RMCP_PLUS_FORMAT == pSessionInfo->AuthType)
@@ -622,50 +622,47 @@ ProcessBridgeMsg (  MsgPkt_T* pReq )
 // 	}
 // 	else
 // #endif /*IPMI20_SUPPORT == 1*/
-// 	{
-// 		/* Fill Session Header */
-// 		  SessionHdr_T* pSessionHdr = (  SessionHdr_T*)(&ResPkt.Data [sizeof(RMCPHdr_T)]);
-// 		  uint8_t*        pPayLoad    = (  uint8_t*)(pSessionHdr + 1);
-
-	// 	pSessionHdr->AuthType       = pSessionInfo->AuthType;
-	// 	pSessionHdr->SessionSeqNum  = pSessionInfo->OutboundSeq++;
-	// 	pSessionHdr->SessionID      = pSessionInfo->SessionID;
-
-	// 	/* If AuthType is not 0 - Compute AuthCode */
-	// 	if (0 != pSessionInfo->AuthType)
-	// 	{
-	// 		IPMI_DBG_PRINT ("Compute Authcode\n");
-	// 		PayLoadLen = AUTH_CODE_LEN;
-	// 		pPayLoad [PayLoadLen++] = pReq->Size - 1;
-	// 		_fmemcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
-	// 		PayLoadLen += pReq->Size;
-	// 		PayLoadLen--;
-	// 		PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
-	// 		ComputeAuthCode (pSessionInfo->Password, pSessionHdr,
-	// 						 (  IPMIMsgHdr_T*) &pPayLoad [AUTH_CODE_LEN+1],
-	// 						 pPayLoad, MULTI_SESSION_CHANNEL);
-	// 	}
-	// 	else
-	// 	{
-	// 	   pPayLoad [PayLoadLen++] = pReq->Size - 1;
-	// 		/*  Fill the ipmi message */
-	// 	   _fmemcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
-	// 	   PayLoadLen += pReq->Size;
-	// 	   PayLoadLen--;
-	// 	   PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
-	// 	}
+	{
+		/* Fill Session Header */
+		  SessionHdr_T* pSessionHdr = (  SessionHdr_T*)(&ResPkt.Data [sizeof(RMCPHdr_T)]);
+		  uint8_t*        pPayLoad    = (  uint8_t*)(pSessionHdr + 1);
 
-	// }
+		pSessionHdr->AuthType       = pSessionInfo->AuthType;
+		pSessionHdr->SessionSeqNum  = pSessionInfo->OutboundSeq++;
+		pSessionHdr->SessionID      = pSessionInfo->SessionID;
+
+		/* If AuthType is not 0 - Compute AuthCode */
+		if (0 != pSessionInfo->AuthType)
+		{
+			PayLoadLen = AUTH_CODE_LEN;
+			pPayLoad [PayLoadLen++] = pReq->Size - 1;
+			memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
+			PayLoadLen += pReq->Size;
+			PayLoadLen--;
+			PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
+			ComputeAuthCode (pSessionInfo->Password, pSessionHdr,
+							 (  IPMIMsgHdr_T*) &pPayLoad [AUTH_CODE_LEN+1],
+							 pPayLoad, MULTI_SESSION_CHANNEL);
+		}
+		else
+		{
+		   pPayLoad [PayLoadLen++] = pReq->Size - 1;
+			/*  Fill the ipmi message */
+		   memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
+		   PayLoadLen += pReq->Size;
+		   PayLoadLen--;
+		   PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
+		}
 
-	// OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+	}
 
-	// ResPkt.Size = PayLoadLen;
+	ResPkt.Size = PayLoadLen;
 
-	// if(pSessionInfo->Activated)
-	// {
-	// 	/* Sent the response packet */
-	// 	SendLANPkt (&ResPkt,BMCInst);
-	// }
+	if(pSessionInfo->Activated)
+	{
+		/* Sent the response packet */
+		SendLANPkt (&ResPkt);
+	}
 
 	return;
 }

+ 9 - 2
app/bmc/lan/RMCP.c

@@ -481,7 +481,7 @@ int ProcIPMIReq (  SessionInfo_T*  pSessionInfo, uint8_t Payload, MsgPkt_T *pReq
 	
 	if (PAYLOAD_IPMI_MSG == Payload)
 	{
-		//printf("Post to MsgHndlr from %d\n", gFd_LanResQ);
+//		printf("\n\n===> Post to MsgHndlr\n");
 		PostMsg (gFd_MsgHndlrIfc, pReq);
 	}
    
@@ -490,9 +490,16 @@ int ProcIPMIReq (  SessionInfo_T*  pSessionInfo, uint8_t Payload, MsgPkt_T *pReq
 	if ( GetMsg (gFd_LanResQ, pRes, DEFAULT_TIMEOUT) != 0)
 	{
 		//FillIPMIResFailure (pReq, pRes);
-		printf("---> RMCP get message error!\n");
+		printf("Warning: RMCP get message error!\n");
 	}
 
+//	printf("===> gFd_LanResQ Recv: ");
+	// int i;
+	// for(i=0;i<pRes->Size;i++)
+	// 	printf("%#x ", pRes->Data[i]);
+	// printf("\n");
+
+
 	if (PARAM_NO_RESPONSE == pRes->Param)
 	{
 		printf ("RMCP.c : No response from message handler\n");

+ 14 - 14
app/bmc/main.c

@@ -185,20 +185,20 @@ void main(void)
         printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
     }
 
-	// /* Create IPMB interface */
-	// uint8_t primaryIpmbSelect = 0;	//primary
-	// gThreadIndex++;
-	// if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
- //  {
- //      printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
- //  }
-
- //  uint8_t secondaryIpmbSelect = 1;	//secondary
- //  gThreadIndex++;
- //  if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
- //  {
- //      printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
- //  }
+	/* Create IPMB interface */
+	uint8_t primaryIpmbSelect = 0;	//primary
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
+  {
+      printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
+  }
+
+  uint8_t secondaryIpmbSelect = 1;	//secondary
+  gThreadIndex++;
+  if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
+  {
+      printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
+  }
 
     /* Create PendActionTask */
 	gThreadIndex++;

+ 42 - 18
app/bmc/msghndlr/App/AppDevice/AppDevice.c

@@ -879,7 +879,7 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
        return  sizeof (*pRes);
     }
 
-#if 1
+#if 0
 	int z;
 	printf("m_MsgPkt: ");
    	for(z = 0; z < m_MsgPkt.Size;z++)
@@ -887,16 +887,16 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
    	printf("\n");
 #endif
 
-    printf("curchannel: %d, Channel: %d\n", *curchannel, Channel);
+    //printf("curchannel: %d, Channel: %d\n", *curchannel, Channel);
 
     if((Channel == PRIMARY_IPMB_CHANNEL) && g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 1)
     {
-     printf ("SendMsg: To Primary IPMB Interface\n");
+     //printf ("SendMsg: To Primary IPMB Interface\n");
      m_MsgPkt.SrcQ 	= gFd_PrimaryIpmbIfcQ;
     }
     else if(( Channel == SECONDARY_IPMB_CHANNEL) && (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 1))
     {
-     printf ("SendMsg: To Secondary IPMB Interface\n");
+     //printf ("SendMsg: To Secondary IPMB Interface\n");
      m_MsgPkt.SrcQ = gFd_SecondaryIpmbIfcQ;
     }
     else
@@ -908,15 +908,29 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
 
     if (1 == Tracking)
     {       
+        ResLen = 0;
+        //printf("---> Tracking, curchannel %d, ", *curchannel);
        /* Tracking is not required if originator is System ifc */
        if (SYS_IFC_CHANNEL == (*curchannel & 0xF))
        {
            *pRes = CC_INV_DATA_FIELD;
            return sizeof (*pRes);
        }
-       
-       PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
 
+      pSessionInfo = getSessionInfo (SESSION_ID_INFO,  CurSesID);
+      //printf("SendMEssage/CurSesID %#x, SessionHandle %#x\n", *CurSesID, pSessionInfo->SessionHandle);
+      if (NULL != pSessionInfo)
+      {
+          g_BMCInfo.SessionHandle = pSessionInfo->SessionHandle;
+      }
+      else
+      {
+          *pRes = CC_UNSPECIFIED_ERR;
+          return sizeof(*pRes);
+      }
+ 
+       PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
+       //printf("PBTbl %d, g_BMCInfo.SendMsgSeqNum %d, ", PBTbl, g_BMCInfo.SendMsgSeqNum);
        /* Store in the table for response tracking */
        while(TRUE)
        {
@@ -929,11 +943,12 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
                
                if (1 != Offset)
                {
+                  //TODO:这个貌似没用到?
                    m_PendingBridgedResTbl[PBTbl][SeqNum].DstSessionHandle = pReq[Offset]; /* Session handle */
                }
 
-               m_PendingBridgedResTbl[PBTbl][SeqNum].SrcSessionHandle = SrcSessionHndl;
-
+               m_PendingBridgedResTbl[PBTbl][SeqNum].SrcSessionHandle = pSessionInfo->SessionHandle;//  SrcSessionHndl;
+               
                memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pIPMIMsgHdr, sizeof (IPMIMsgHdr_T));
 
                /* Format the IPMI Msg Hdr */
@@ -957,6 +972,7 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
                if((*curchannel & 0xF) == LAN_RMCP_CHANNEL)
                {                 
                    m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = gFd_LanIfcQ;
+                   
                }                  
                else
                {
@@ -970,7 +986,11 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
                    }                       
                }
                m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
-               printf( "SendMessage:  Bridged message added index = %d.\n", SeqNum);
+               m_PendingBridgedResTbl[PBTbl][SeqNum].SeqNum = SeqNum;
+               m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 0;
+               //printf( "SendMessage SeqNum %d, ", SeqNum);
+              //memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
+
 
                break;
            }
@@ -978,7 +998,7 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
            {
                SeqNum = (SeqNum + 1) & 0x3F;
 
-               if (SeqNum == g_BMCInfo.SendMsgSeqNum)
+               if (SeqNum == g_BMCInfo.SendMsgSeqNum)   //转了一圈,没有空闲的SeqNum可用。
                {
                    /* If not been added to the Pending Bridge table, an error should be reported back.
                    If not, for internal channel, the thread calling it may end up waiting! */
@@ -988,18 +1008,23 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
             }
        }
     }
+    else
+    {
+      pSendMsgRes->CompletionCode = 0xff;
+      return 1;
+    }
 
-    printf ("SendMsgCmd:Posting to interface ");
-    int y;
-    for(y=0;y<m_MsgPkt.Size;y++)
-    		printf("%#x ", m_MsgPkt.Data[y]);
-    	printf("\n");
+    // printf ("SendMsgCmd:Posting to interface ");
+    // int y;
+    // for(y=0;y<m_MsgPkt.Size;y++)
+    // 		printf("%#x ", m_MsgPkt.Data[y]);
+    // 	printf("\n");
 
     m_MsgPkt.Cmd = PAYLOAD_IPMI_MSG;
     /* Post the message to interface */
     if (0 != PostMsg (m_MsgPkt.SrcQ, &m_MsgPkt))
     {
-       printf ("SendMsg: Failed to post message to interface queue\n");
+       printf ("Warning: SendMsg Failed to post message to interface queue\n");
     }
 
     pSendMsgRes->CompletionCode = CC_NORMAL;
@@ -1258,6 +1283,7 @@ ActivateSession ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
     pSessInfo->SessionHandle = g_BMCInfo.SessionHandle;
 
 
+
     pAcvtSesRes->CompletionCode = CC_NORMAL;
     pAcvtSesRes->AuthType = (pSessInfo->AuthType & 0x0F);
     pAcvtSesRes->SessionID = pSessInfo->SessionID;
@@ -2639,8 +2665,6 @@ SetUserPassword ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
 
         				strcpy(pUserInfo->UserPassword, pSetUserPswdReq->Password);
         				FlushUserInfoTbl();
-                printf("---> SET_PASSWORD, username: %s, password: %s, get: %s\n", \
-                  pUserInfo->UserName, pUserInfo->UserPassword, pSetUserPswdReq->Password);
             }
             else
             {

+ 4 - 3
app/bmc/msghndlr/MsgHndlr.h

@@ -136,15 +136,16 @@ typedef struct
 {
     uint8_t               Used;
     uint8_t               TimeOut;
-    uint8_t               SeqNum;
-    uint8_t               ChannelNum;
+    uint8_t               SeqNum;           //转发到IPMB总线上的序号,也是PendingTbl的索引。
+    uint8_t               ChannelNum;       //记录下发SendMessage命令的通道,Lan
     uint8_t               DstSessionHandle;
     uint8_t               SrcSessionHandle;
     uint32_t              SrcSessionID;
-    int                   DestQ;
+    int                   DestQ;            //记录下发SendMessage命令的接收队列,LanIfcQ
     uint8_t               OriginSrc;
     IPMIMsgHdr_T        ReqMsgHdr;
     ResMsgHdr_T         ResMsgHdr;
+    uint8_t             ResDataOk;          //jimbo add, 响应数据准备好了标志。
 }    PendingBridgedResTbl_T;
 
 /*------------------------------

+ 160 - 48
app/bmc/msghndlr/MsgHndlrTask.c

@@ -145,9 +145,18 @@ void *MsgHndlrTask( void *pArg )
 		pthread_setspecific(g_tls.CurSessionType,&reqMsgPkt.SessionType);
 		pthread_setspecific(g_tls.OwnerLUN,&reqMsgPkt.NetFnLUN);
 
+		SwapIPMIMsgHdr ((IPMIMsgHdr_T*)reqMsgPkt.Data, (IPMIMsgHdr_T*)resMsgPkt.Data);
 		ProcessIPMIReq(&reqMsgPkt, &resMsgPkt);
+
+		/* Skip current request if no response from Command Handler */
+		if ( (sizeof(IPMIMsgHdr_T) == resMsgPkt.Size) && (NORMAL_RESPONSE == resMsgPkt.Param) )
+		{
+			continue;
+		}
 		//update checksum2
-		resMsgPkt.Data[resMsgPkt.Size-1]	=	CalculateCheckSum2(resMsgPkt.Data, resMsgPkt.Size-1);
+		resMsgPkt.Data[resMsgPkt.Size]	=	CalculateCheckSum2(resMsgPkt.Data, resMsgPkt.Size);
+		resMsgPkt.Size++;
+
 		if(g_BMCInfo.IpmiConfig.UDSIfcSupport == 0x01 && (reqMsgPkt.SrcQ == gFdUdsRes))
 		{
 			if (resMsgPkt.Size == sizeof(IPMIUDSMsg_T) && (NORMAL_RESPONSE == resMsgPkt.Param) )
@@ -168,7 +177,8 @@ void *MsgHndlrTask( void *pArg )
 			
 			resMsgPkt.SessionID = reqMsgPkt.SessionID;
 		}
-		// printf("Mtx: ");
+		// int i;
+		// printf("===> Mtx to %d: ", resMsgPkt.SrcQ);
 		// for(i=0;i<resMsgPkt.Size;i++)
 		// 	printf("%#x ", resMsgPkt.Data[i]);
 		// printf("\n");
@@ -179,6 +189,87 @@ void *MsgHndlrTask( void *pArg )
 	}
 }
 
+
+/**
+*@fn ValidateMsgHdr
+*@brief Validates the Message header and keeps track of the messages that has been bridged
+*@param pReq Request packet of the command to be executed
+*@return Returns -1 in case of the response to the bridged message
+*            Returns 0 otherwise
+*/
+int
+ValidateMsgHdr (MsgPkt_T* pReq)
+{
+	int  j;
+	uint8_t PBTbl = PRIMARY_PB_TBL;
+	IPMIMsgHdr_T*	pIPMIMsgReq = (IPMIMsgHdr_T*)&pReq->Data;
+	ChannelInfo_T*  pChannelInfo;
+	uint8_t SeqNum = NET_FN(pIPMIMsgReq->RqSeqLUN);
+	int Queuefd = 0;
+
+	/* Check for the request message LUN */
+	switch (pReq->NetFnLUN & 0x03)
+	{
+		case BMC_LUN_00:
+			if (0 == (pReq->NetFnLUN & 0x04))
+			{
+				return 0;	//IPMB做从
+			}
+
+			PBTbl = ( (pReq->Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL );
+			
+			
+			if ( (TRUE 		== m_PendingBridgedResTbl[PBTbl][SeqNum].Used) &&
+				 (NET_FN(pIPMIMsgReq->NetFnLUN)  == NET_FN((m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.NetFnLUN + 0x04)))  &&
+				 (pIPMIMsgReq->Cmd               == m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.Cmd)  &&
+				 (pIPMIMsgReq->ReqAddr           == m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.ResAddr))
+			{        
+
+				 /* Change the requester's address, sequence number and LUN */
+				 pIPMIMsgReq->ResAddr  = m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.ReqAddr;
+				 pIPMIMsgReq->RqSeqLUN = m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.RqSeqLUN;
+
+				 /* Calculate the Second CheckSum */
+				 pReq->Data[ pReq->Size - 1 ] = CalculateCheckSum2( pReq->Data, pReq->Size - 1 );
+				 pReq->Data[2] = (~(pReq->Data[0] + pReq->Data[1])) +1; //2's complement checksum
+
+				 pReq->Param = BRIDGING_REQUEST;
+
+				 
+				 if (m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ == gFd_LanIfcQ)
+				 {			
+					  for (j=pReq->Size - 1; j>=0; j--)
+					  {
+						   pReq->Data[j+1] = pReq->Data[j];
+					  }
+					  pReq->Data[0] = m_PendingBridgedResTbl[PBTbl][SeqNum].SrcSessionHandle;
+					  pReq->Size++;
+					  pReq->Cmd = PAYLOAD_IPMI_MSG;
+					  Queuefd = gFd_LanIfcQ;
+				 }
+				 else
+				 {
+					//TODO:其它接口转发
+				 	printf("Invalid interface!\n");
+				 }
+						
+				 /* Post the data to Destination Interface queue */
+				 //printf("===> ValidateMsgHdr post message to %d\n", Queuefd);
+				 PostMsg (Queuefd, pReq);
+
+				 m_PendingBridgedResTbl[PBTbl][SeqNum].Used = FALSE;
+				 m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 0;
+			}
+			return -1;
+		case BMC_LUN_01:
+		case BMC_LUN_10:
+		case BMC_LUN_11:
+			//TODO:
+		default:
+			return -1;
+	}
+}
+
 /**
 *@fn ProcessIPMIReq
 *@brief Processes the requested IPMI command
@@ -283,48 +374,48 @@ ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes)
 		}
 	}
 	
-	pRes->Size 	= 	pCmdHndlrMap->CmdHndlr (&pReq->Data [HdrOffset], pReq->Size, &pRes->Data [HdrOffset]) + HdrOffset + 1;
+	pRes->Size 	= 	pCmdHndlrMap->CmdHndlr (&pReq->Data [HdrOffset], pReq->Size, &pRes->Data [HdrOffset]) + HdrOffset;
 		
-	// //send message command
-	// if( (CMD_SEND_MSG == pReq->Cmd) && (NETFN_APP == pReq->NetFnLUN >> 2))
-	// {
-	// 	printf("log 4\n");
-	// 	int Offset = 0;
-	// 	uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
-	// 	if ((0 == pRes->Size) &&
-	// 		((g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 0x01  && PRIMARY_IPMB_CHANNEL == pRes->Channel) || 
-	// 		 (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 0x01 && SECONDARY_IPMB_CHANNEL == pRes->Channel)) )
-	// 	{
-	// 		pRes->Param = PARAM_NO_RESPONSE;
-	// 		Offset = HdrOffset + 2;
-	// 	}
-	// 	else if (HdrOffset == pRes->Size)
-	// 	{
-	// 		Offset = HdrOffset + 1;
-	// 	}
-
-	//     PBTbl = ( ((pReq->Data[sizeof (IPMIMsgHdr_T)] & 0x0F) == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL );
-	// 	while(TRUE)
-	// 	{ 
-	// 		if ( (TRUE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used) &&
-	// 			(0 == memcmp (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, &pReq->Data[Offset], sizeof (IPMIMsgHdr_T))) )
-	// 		{
-	// 			printf("---> log 4.1\n");
-	// 			 memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
-	// 			 break;    
-	// 		}
-	// 		else
-	// 		{
-	// 			SeqNum = (SeqNum - 1) & 0x3F;
-	// 			if(SeqNum == g_BMCInfo.SendMsgSeqNum)
-	// 			{
-	// 				break; 
-	// 			}
-	// 		}
-	// 	}
-	// }
-
-//	printf("log 5\n");
+	//prepare response data for send message command
+	if( (CMD_SEND_MSG == pReq->Cmd) && (NETFN_APP == pReq->NetFnLUN >> 2))
+	{
+		//printf("log 4, size %d, Channel %d\n",pRes->Size, pRes->Channel);
+		int Offset = 0;
+		uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
+		if ((0 == pRes->Size) &&
+			((g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 0x01  && PRIMARY_IPMB_CHANNEL == pRes->Channel) || 
+			 (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 0x01 && SECONDARY_IPMB_CHANNEL == pRes->Channel)) )
+		{
+			pRes->Param = PARAM_NO_RESPONSE;
+			Offset = HdrOffset + 2;
+		}
+		else if (HdrOffset == pRes->Size)
+		{
+			Offset = HdrOffset + 1;
+		}
+
+	    PBTbl = ( ((pReq->Data[sizeof (IPMIMsgHdr_T)] & 0x0F) == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL );
+		
+		int i;
+		while(TRUE)
+		{ 
+			if ( (TRUE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used) 
+				&& (0 == memcmp (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, &pReq->Data[Offset], sizeof (IPMIMsgHdr_T))) )
+			{				
+				 memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
+				 m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 1;
+				 break;    
+			}
+			else
+			{
+				SeqNum = (SeqNum - 1) & 0x3F;
+				if(SeqNum == g_BMCInfo.SendMsgSeqNum)
+				{
+					break; 
+				}
+			}
+		}
+	}
 	
 	return;
 }
@@ -478,18 +569,34 @@ void RespondSendMessage ( MsgPkt_T* pReq, uint8_t Status)
 	MsgPkt_T   ResPkt;
 	IPMIMsgHdr_T*  pIPMIResHdr = ( IPMIMsgHdr_T*)ResPkt.Data;
 	IPMIMsgHdr_T*  pIPMIReqHdr = ( IPMIMsgHdr_T*)pReq->Data;
-	uint8_t SeqNum = NET_FN(pIPMIReqHdr->RqSeqLUN);
+	uint8_t SeqNum = NET_FN(pIPMIReqHdr->RqSeqLUN);		//IPMB的sequence
 	int QueueFd;
 	
+	// printf("---> RespondSendMessage Status = %d\n");
+	// printf("Req: SeqNum %d, NetFn %#x, Cmd %#x, ResAddr %#x\n", SeqNum, NET_FN(pIPMIReqHdr->NetFnLUN), pIPMIReqHdr->Cmd, pIPMIReqHdr->ResAddr );
+	// printf("Tbl: SeqNum %d, NetFn %#x, Cmd %#x, ResAddr %#x\n",m_PendingBridgedResTbl[PBTbl][SeqNum].SeqNum,
+	// 	NET_FN(m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.NetFnLUN ),
+	// 	m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.Cmd,m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.ResAddr);
   /* Check for pending responses */
 	PBTbl = ( (pReq->Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL );
-	if ( (TRUE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used) &&
-		 (NET_FN(pIPMIReqHdr->RqSeqLUN)  == SeqNum) &&
+	if ( (TRUE 		== m_PendingBridgedResTbl[PBTbl][SeqNum].Used) &&
 		 (NET_FN(pIPMIReqHdr->NetFnLUN)  == NET_FN(m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.NetFnLUN )) &&
 		 (pIPMIReqHdr->Cmd               == m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.Cmd) &&
 		 (pIPMIReqHdr->ResAddr           == m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.ResAddr)  )
 	{
-		
+		// printf("---> RespondSendMessage/ m_PendingBridgedResTbl: PBTbl: %d, SeqNum %d\n", PBTbl, SeqNum);
+		// int i;
+		// for(i=0;i<6;i++)
+		// 	printf("%#x ", ((uint8_t*)&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr.IPMIMsgHdr)[i]);
+		// printf("\n");
+		uint32_t tcnt = 0;
+		while(m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk == 0)
+		{
+			usleep(1);
+			tcnt++;
+			if(tcnt > 100000)	break;	//100ms
+		}
+
 		memcpy (pIPMIResHdr, &m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
 		 
 			
@@ -553,11 +660,16 @@ void RespondSendMessage ( MsgPkt_T* pReq, uint8_t Status)
 		 if (STATUS_OK != Status)
 		 {
 			 m_PendingBridgedResTbl[PBTbl][SeqNum].Used = FALSE;
+			 m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 0;
 		 }
 		 
 		 /* Post the data to Destination Interface queue */
+		 //int i;
+		 // printf("===> RespondSendMessage post to %d: ", QueueFd);
+		 // for(i=0;i<ResPkt.Size;i++)
+		 // 	printf("%#x ", ResPkt.Data[i]);
+		 // printf("\n");
 		 PostMsg (QueueFd, &ResPkt);
-
 	}
 }
 

+ 2 - 2
app/bmc/msghndlr/cmdselect.c

@@ -908,13 +908,13 @@ int IsCommandEnabled(uint8_t NetFn,uint8_t* GroupExtnCode,uint8_t Cmd)
 	{
 		if(GetCommanEnabledStatus((NETFNTable_T*)&Netfntbl[i],Cmd) < 0)
 		{
-			printf("---> invalid command\n");
+			printf("Warning: invalid command\n");
 			return -1;
 		}
 	}
 	else
 	{
-		printf("---> not find netfn\n");
+		printf("Warning: not find netfn\n");
 		return -1;
 	}
 

+ 17 - 2
app/goahead-3.6.5/src/libipmi/src/sensor_helpers.c

@@ -1042,7 +1042,7 @@ unsigned char sdr_convert_sensor_value_to_raw(FullSensorRec_T	*sdr_record, doubl
     int tmp = 0;
     unsigned char retVal;
     
-    #define tos(val, bits)    ((val & ((1<<((bits)-1)))) ? (-((val) & (1<<((bits)-1))) | (val)) : (val))
+    #define tos(value, bits)    ((value & ((1<<((bits)-1)))) ? (-((value) & (1<<((bits)-1))) | (value)) : (value))
     m = tos((((unsigned short int) sdr_record->M_Tolerance << 2 & 0x300) | sdr_record->M), 10);
     b = tos((((unsigned short int) sdr_record->B_Accuracy << 2 & 0x300) | sdr_record->B), 10);
     k1 = tos(sdr_record->R_B_Exp & 0x0f, 4);
@@ -1067,12 +1067,27 @@ unsigned char sdr_convert_sensor_value_to_raw(FullSensorRec_T	*sdr_record, doubl
     //     return (unsigned char) result;
 
     if(result > 0)
+    {
         result += 0.5;
+    }
     else
+    {
         result += -0.5;
+    }
     tmp = (int)result;
+    printf("---> result: %f, tmp = %d,", result, tmp);
+
+    if (((sdr_record->Units1 & 0xC0) == 0x80) || ((sdr_record->Units1 & 0xC0) == 0x40))    //signed
+    {
+        if(tmp > 127)   tmp = 127;
+        if(tmp < -128)   tmp = -128;
+    }
+    else
+    {
+        if(tmp > 255)   tmp = 255;
+    }
     retVal = (unsigned char)tmp;
-    printf("---> result: %f, tmp = %d, retVal = %#x\n", result, tmp, retVal);
+    printf(" retVal = %#x\n", retVal);
     return  retVal;
 }
 

+ 4 - 4
local/rc

@@ -11,7 +11,7 @@ ifconfig lo 127.0.0.1
 ################### install module #####################
 #insmod /usr/bin/test_module.ko
 insmod /usr/bin/gpio.ko 
-#insmod /usr/bin/i2c.ko
+insmod /usr/bin/i2c.ko
 #insmod /usr/bin/fmc.ko
 insmod /usr/bin/platform.ko
 #insmod /usr/bin/adc.ko
@@ -21,9 +21,9 @@ insmod /usr/bin/platform.ko
 #################### create node ########################
 #mknod /dev/test_module c 99 0
 mknod /dev/platform c 100 0
-#mknod /dev/i2c1 c 101 0
-#mknod /dev/i2c2 c 101 1
-#mknod /dev/i2c3 c 101 2
+mknod /dev/i2c1 c 101 0
+mknod /dev/i2c2 c 101 1
+mknod /dev/i2c3 c 101 2
 #mknod /dev/fmc_cpld c 102 0
 mknod /dev/gpio c 103 0 
 #mknod /dev/adc1 c 105 0