zhangbo 5 jaren geleden
bovenliggende
commit
34257f20be

+ 8 - 2
app/bmc/Api.c

@@ -137,16 +137,20 @@ int PlatformInit(void)
 int InitTimerTaskTbl(void)
 {
 	printf("InitTimerTaskTbl...\n");
-	g_BMCInfo.TimerTaskTblSize = 9;
-    memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl,sizeof(m_TimerTaskTbl));
+	g_BMCInfo.TimerTaskTblSize = 2;
+    memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl, sizeof(TimerTaskTbl_T)*g_BMCInfo.TimerTaskTblSize);
 }
 
 int Init_SessionTbl(void)
 {
 	printf("Init_SessionTbl...\n");
+	g_BMCInfo.SessionHandle 					=	0;
+	g_BMCInfo.UDSSessionHandle 					=	0;
+
 	g_BMCInfo.IpmiConfig.MaxSession				= 	10;
 	g_BMCInfo.IpmiConfig.SessionTimeOut			= 	10;	//10s
 	g_BMCInfo.IpmiConfig.SendMsgTimeout			=	10;	//10s
+	
 	/*Allocating Memory to hold session Table informations */
     g_BMCInfo.SessionTblInfo.SessionTbl = (SessionInfo_T *) malloc(sizeof(SessionInfo_T)*( g_BMCInfo.IpmiConfig.MaxSession + 1));
     if(g_BMCInfo.SessionTblInfo.SessionTbl == NULL)
@@ -154,6 +158,7 @@ int Init_SessionTbl(void)
         printf("Error in allocating memory for SessionTbl \n");
         return 1;
     }
+    g_BMCInfo.SessionTblInfo.Count = 0;
     /*Initialize the Session Table memory */
     memset(g_BMCInfo.SessionTblInfo.SessionTbl,0,sizeof(SessionInfo_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
 
@@ -164,6 +169,7 @@ int Init_SessionTbl(void)
         printf("Error in allocating memory for SessionTbl \n");
         return 1;
     }
+    g_BMCInfo.UDSSessionTblInfo.SessionCount = 0;
     /*Initialize the UDS Session Table memory */
     memset(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl,0,sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
 }

+ 3 - 1
app/bmc/BmcType.h

@@ -111,8 +111,10 @@ typedef struct
 	uint8_t				DeviceGUID[16];
 //	OEM_FLAGS_T			OemFlags;
 	
-	SessionInfo_T		LanSession;
+//	SessionInfo_T		LanSession;
+	uint8_t 			SessionHandle;
 	SessionTblInfo_T 	SessionTblInfo;
+	uint8_t 			UDSSessionHandle;
 	UDSSessionTblInfo_T UDSSessionTblInfo;
 	uint8_t			 	TimerTaskTblSize;
 	TimerTaskTbl_T    	TimerTaskTbl[20];

+ 14 - 43
app/bmc/Session.c

@@ -98,7 +98,7 @@ void SessionTimerTask (void)
 //   char solsessionfile[MAXFILESIZE] = {0};
    struct stat fp;
 
-   printf("-> SessionTimerTask\n");
+//   printf("-> SessionTimerTask\n");
    for (Index=0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
    {
        if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
@@ -121,41 +121,13 @@ void SessionTimerTask (void)
        //         }
        //     }
        // }
-       
-       // if(pBMCInfo->IpmiConfig.SOLIfcSupport == 1)
-       // {
-       //     if(pSessionTblInfo->SessionTbl[Index].SessPyldInfo [PAYLOAD_SOL].Type == PAYLOAD_SOL)
-       //     {
-       //         if (pBMCInfo->IpmiConfig.SOLSessionTimeOut == 0 ) // Never Time Out 
-       //         {
-       //             continue;
-       //         }
-               
-       //         if(pSessionTblInfo->SessionTbl[Index].TimeOutValue == 0)
-       //         {
-       //             sprintf(solsessionfile,"%s%d",SOL_SESSION_FILE,BMCInst);
-               
-       //             if(stat(solsessionfile,&fp) == 0)
-       //             {
-       //                 unlink(solsessionfile);
-       //             }
-       //         }
-       //     }
-       // }
 
-    //   if(GetLinkStatus(pSessionTblInfo->SessionTbl[Index].Channel,BMCInst) !=0)
-    //   {
-           if (pSessionTblInfo->SessionTbl[Index].TimeOutValue > 0)
-           {
-               pSessionTblInfo->SessionTbl[Index].TimeOutValue--;
-               continue;
-           }
-       // }
-       // else
-       // {
-       //     pSessionTblInfo->SessionTbl[Index].Linkstat = TRUE;
-       //     continue;
-       // }
+      if (pSessionTblInfo->SessionTbl[Index].TimeOutValue > 0)
+      {
+         pSessionTblInfo->SessionTbl[Index].TimeOutValue--;
+         continue;
+      }
+       
 
        printf ("\nSessionTimerTask: Session Time Out Occured\n");
        printf ("SessionID = 0x%lX  Num of Sessions = %X\n", pSessionTblInfo->SessionTbl[Index].SessionID,
@@ -815,8 +787,8 @@ void DeleteSession( SessionInfo_T*	pSessionInfo)
            pSessionTblInfo->Count--;
            pSessionTblInfo->SessionTbl[Index].Time=0xFFFFFFFF;
 
-           printf("DeleteSession: SessionID = %lX	Num Session %X\t%x\n",
-           pSessionInfo->SessionID, pSessionTblInfo->Count,Index);
+           //printf("DeleteSession: SessionID = %lX	Num Session %X\t%x\n",
+           //pSessionInfo->SessionID, pSessionTblInfo->Count,Index);
            return;
        }
    }
@@ -985,7 +957,7 @@ void UDSSessionTimerTask (void)
    uint8_t Index=0;
    UDSSessionTblInfo_T *pUDSSessionTblInfo = &g_BMCInfo.UDSSessionTblInfo;
 
-   printf("-> UDSSessionTimerTask\n");
+//   printf("-> UDSSessionTimerTask\n");
    for(Index=0;Index<g_BMCInfo.IpmiConfig.MaxSession;Index++)
   {
        if(FALSE == pUDSSessionTblInfo->UDSSessionTbl[Index].Activated)
@@ -994,15 +966,14 @@ void UDSSessionTimerTask (void)
            continue;
        }
 
-       if((pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue <= g_BMCInfo.IpmiConfig.SessionTimeOut) && (pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue != 0))
+       if(pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue > 0)
        {
           /* Reduce the Session Timeout Value if the session is not used */
            pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue--;
+           continue;
        }
-       else if(pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue <= 0)
-       {
-           DeleteUDSSession(&pUDSSessionTblInfo->UDSSessionTbl[Index]);
-       }
+       
+      DeleteUDSSession(&pUDSSessionTblInfo->UDSSessionTbl[Index]);
   }
 }
 

+ 1 - 1
app/bmc/Session.h

@@ -134,7 +134,7 @@ typedef struct
 // #endif
 //     uint32_t                   InitialInboundSeq;
 //     uint32_t                   InboundTrac[SIXTEEN_COUNT_WINDOW_LEN];
-//     uint16_t                   InboundRecv;
+    uint16_t                   InboundRecv;
     uint8_t 			IsLoopBack;
     uint8_t       Linkstat;
     uint8_t 			EventFlag;

+ 1 - 5
app/bmc/SysTimer/TimerTask.c

@@ -38,7 +38,7 @@ void *TimerTask( void *pvParameters )
 			g_BMCInfo.TotalBootValidMinutes++;
 		}
 
-		//ProcessTimerReq();
+		ProcessTimerReq();
 
 		sleep(1);
 	}
@@ -53,10 +53,6 @@ void *TimerTask( void *pvParameters )
 static void ProcessTimerReq (void)
 {
 	int i;
-	// if(g_corefeatures.delayed_lan_restart_support)
-	// {
-	// 	ElapsedTime++;
-	// }
 	for (i = 0; i < g_BMCInfo.TimerTaskTblSize; i++)
 	{
 		if (0 == (g_BMCInfo.CurTimerTick % g_BMCInfo.TimerTaskTbl [i].NumSecs))

BIN
app/bmc/bmc_app


+ 8 - 3
app/bmc/ipmb/IPMBIfc.c

@@ -158,14 +158,19 @@ void *IPMBIfcTask(void *Param)
 				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");
                 /* Send the response */
                 if(RcvMsgPkt.Channel == PRIMARY_IPMB_CHANNEL)
                 {
-                    RetVal = stm32_i2c_master_write(gFd_Primary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size);
+                    RetVal = stm32_i2c_master_write(gFd_Primary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size-1);
                 }
                 else if(RcvMsgPkt.Channel == SECONDARY_IPMB_CHANNEL)
                 {
-                    RetVal = stm32_i2c_master_write(gFd_Secondary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size);
+                    RetVal = stm32_i2c_master_write(gFd_Secondary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size-1);
                 }
                 else
                 {
@@ -181,7 +186,7 @@ void *IPMBIfcTask(void *Param)
                 {
                     RespondSendMessage (&RcvMsgPkt, STATUS_OK);
                 }
-                printf("---> IPMBIfcTask/BRIDGING_REQUEST\n");
+                
                 break;
             default:
 				printf("Unknow message param %#x\r\n", RcvMsgPkt.Param);

+ 1 - 1
app/bmc/lan/RMCP.c

@@ -375,7 +375,7 @@ ProcessRMCPReq( RMCPHdr_T* pRMCPReq,  RMCPHdr_T* pRMCPRes)
 		SessionID             = pReqSessionHdr->SessionID;
 
 		/* Get Session Information */
-		pSessionInfo = &g_BMCInfo.LanSession;
+		pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
 	
 		if (0 == pReqSessionHdr->AuthType)
 		{

+ 13 - 13
app/bmc/main.c

@@ -96,19 +96,19 @@ 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 Update FPGA thread */
 

+ 153 - 148
app/bmc/msghndlr/App/AppDevice/AppDevice.c

@@ -952,9 +952,8 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
       }
 
 #if 1
-   	printf("SendMsg: ReqLen = %d, size = %ld\n",ReqLen,m_MsgPkt.Size);
 	int z;
-	printf("m_MsgPkt: \n");
+	printf("m_MsgPkt: ");
    	for(z = 0; z < m_MsgPkt.Size;z++)
    		printf("%02x ", m_MsgPkt.Data[z]);
    	printf("\n");
@@ -981,103 +980,41 @@ SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
        // }
 
    		printf("curchannel: %d, Channel: %d\n", *curchannel, Channel);
-   		if(g_BMCInfo.IpmiConfig.LANIfcSupport == 1)
-       	{
-           /* To Check the Wheather  LAN Channel */
-           //if (IsLANChannel(*curchannel & 0xF, BMCInst))
-       		if(*curchannel&0xf == LAN_RMCP_CHANNEL)	//jimbo
-           {
-                SessionInfo_T* pSessionInfo = getSessionInfo (SESSION_ID_INFO,CurSesID);
-
-               if (NULL != pSessionInfo)
-               {
-                   SrcSessionHndl = pSessionInfo->SessionHandle;
-               }
-
-               printf ("SendMsg: To LAN Interface for reference\n");
-               // Offset++; : causes bridging issues
-               strcpy ((char *)m_MsgPkt.SrcQ, LAN_IFC_Q);
-           }
-       }
-
-       if((Channel == PRIMARY_IPMB_CHANNEL) && g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 1)
-       {
-           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 SMLink IPMB Interface\n");
-           m_MsgPkt.SrcQ = gFd_SecondaryIpmbIfcQ;
-       }
-       // else if ((pBMCInfo->SERIALch != CH_NOT_USED && Channel == pBMCInfo->SERIALch) && pBMCInfo->IpmiConfig.SerialIfcSupport == 1)
-       // {
-       //     TDBG ("SendMsg: To Serial Interface\n");
-       //     Offset++;
-       //     strcpy ((char *)m_MsgPkt.SrcQ, SERIAL_IFC_Q);
-       // }
-       // else if ((pBMCInfo->ICMBCh != CH_NOT_USED && Channel == pBMCInfo->ICMBCh) && pBMCInfo->IpmiConfig.ICMBIfcSupport == 1)
-       // {
-       //     TDBG ("SendMsg: To ICMB Interface\n");
-       //     strcpy ((char *)m_MsgPkt.SrcQ, ICMB_IFC_Q);
-       // }
-       // else if(pBMCInfo->SYSCh != CH_NOT_USED && Channel == pBMCInfo->SYSCh)
-       // {
-       //     TDBG ("SendMsg: To System Interface\n");
-       //     /*
-       //      * According to IPMI Spec v2.0.
-       //      * It is recommended to send CC_DEST_UNAVAILABLE
-       //      * completion code, if the channel is disabled for
-       //      * receiving messages.
-       //      * */
-       //      OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
-       //     pChannelInfo = getChannelInfo(Channel,BMCInst);
-       //     if(NULL == pChannelInfo)
-       //     {
-       //         *pRes = CC_INV_DATA_FIELD;
-       //         OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
-       //         OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
-       //         return  sizeof (*pRes);
-       //     }
-       //     if (0x0 == pChannelInfo->ReceiveMsgQ)
-       //     {
-       //         printf ("The Channel(0x%x) has been Disabled "
-       //                     "for Receive message\n", Channel);
-       //         *pRes = CC_DEST_UNAVAILABLE;
-       //         OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
-       //         OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
-       //         return sizeof (*pRes);
-       //     }
-       //     OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
-       //     strcpy ((char *)m_MsgPkt.SrcQ, &g_RcvMsgQ[*kcsifcnum][0]);
-       //     m_MsgPkt.Param = SrcSessionHndl;
-       // }
-       else
-       {
-           printf ("SendMsg: Invalid Channel\n");
-           *pRes = CC_DEST_UNAVAILABLE;
-           return sizeof (*pRes);
-       }
-
-       // if( (TRUE == pBMCInfo->NMConfig.NMSupport) && (pBMCInfo->NMConfig.NMDevSlaveAddress == pIPMIMsgHdr->ResAddr) &&
-       //     (Channel == (NM_PRIMARY_IPMB_BUS == pBMCInfo->NMConfig.NM_IPMBBus) ? pBMCInfo->PrimaryIPMBCh : pBMCInfo->SecondaryIPMBCh) )
-       // {
-       //     if( (pBMCInfo->RMCPLAN1Ch == *curchannel) ||
-       //         (pBMCInfo->RMCPLAN2Ch == *curchannel) ||
-       //         (pBMCInfo->RMCPLAN3Ch == *curchannel) ||
-       //         (pBMCInfo->RMCPLAN4Ch == *curchannel) ||
-       //         (pBMCInfo->SERIALch   == *curchannel) )
-       //     {
-       //         OS_THREAD_TLS_GET(g_tls.CurPrivLevel,curprivlevel);
-       //         if(PRIV_ADMIN != *curprivlevel)
-       //         {
-       //             TDBG("Insufficient Privilege\n");
-       //             *pRes = CC_INSUFFIENT_PRIVILEGE;
-       //             OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
-       //             return sizeof(*pRes);
-       //         }
-       //     }
-       // }
+   		// if(g_BMCInfo.IpmiConfig.LANIfcSupport == 1)
+     //  {
+     //       /* To Check the Wheather  LAN Channel */
+     //       //if (IsLANChannel(*curchannel & 0xF, BMCInst))
+     //   		if(*curchannel&0xf == LAN_RMCP_CHANNEL)	//jimbo
+     //      {
+     //          SessionInfo_T* pSessionInfo = getSessionInfo (SESSION_ID_INFO,CurSesID);
+
+     //          if (NULL != pSessionInfo)
+     //          {
+     //              SrcSessionHndl = pSessionInfo->SessionHandle;
+     //          }
+
+     //           printf ("SendMsg: To LAN Interface for reference\n");
+     //           // Offset++; : causes bridging issues
+     //           m_MsgPkt.SrcQ = gFd_LanIfcQ;
+     //      }
+     //  }
+
+      if((Channel == PRIMARY_IPMB_CHANNEL) && g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 1)
+      {
+         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 SMLink IPMB Interface\n");
+         m_MsgPkt.SrcQ = gFd_SecondaryIpmbIfcQ;
+      }
+      else
+      {
+         printf ("SendMsg: Invalid Channel\n");
+         *pRes = CC_DEST_UNAVAILABLE;
+         return sizeof (*pRes);
+      }
    
        if (1 == Tracking)
        {
@@ -1376,16 +1313,13 @@ GetSessionChallenge ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
 {
 	GetSesChallengeReq_T* pGetSesChalReq = ( GetSesChallengeReq_T*)pReq;
 	GetSesChallengeRes_T* pGetSesChalRes = ( GetSesChallengeRes_T*)pRes;
-    uint8_t                 Index;
-    uint8_t                 ChallengeString[CHALLENGE_STR_LEN];
+  uint8_t                 Index;
+  uint8_t                 ChallengeString[CHALLENGE_STR_LEN];
 	UserInfo_T			*pUserInfo;
-	
-    // // Check for Reserved bits
-    // if((pGetSesChalReq->AuthType == AUTHTYPE_RESERVED) || (pGetSesChalReq->AuthType > AUTHTYPE_OEM_PROPRIETARY))
-    // {
-    //     pGetSesChalRes->CompletionCode = CC_INV_DATA_FIELD;
-    //     return sizeof (*pRes);
-    // }
+  uint32_t                TempSessId;
+  SessionInfo_T         SessionInfo;
+  uint8_t         *curchannel;
+  uint32_t        TempRandom;
 
 	if(pGetSesChalReq->UserName[0] == 0)
 	{
@@ -1400,28 +1334,49 @@ GetSessionChallenge ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
 		pGetSesChalRes->CompletionCode = 0x81;
         return sizeof (*pRes);
 	}
-	
-	// if((pUserInfo->ID != USER_ID) || (pUserInfo->UserStatus == FALSE))
-	// {
-	// 	pGetSesChalRes->CompletionCode = 0x81;
- //        return sizeof (*pRes);
-	// }
+
+  curchannel = pthread_getspecific(g_tls.CurChannel);   
+
+  do
+  {
+      /*generate 32 bit temp session Id*/
+      TempSessId = stm32_generate_random32bit();
+  } while ((NULL != getSessionInfo (SESSION_ID_INFO, &TempSessId)) || (0 == TempSessId));
+
+  SessionInfo.UserId       = (uint8_t)pUserInfo->UserId;
+  /*Activated in ActivateSession Command*/
+  SessionInfo.Activated    = FALSE;
+  SessionInfo.AuthType     = pGetSesChalReq->AuthType;
+  SessionInfo.Channel      = *curchannel & 0xF;
+  SessionInfo.SessionID    = TempSessId;
+	SessionInfo.TimeOutValue = g_BMCInfo.IpmiConfig.SessionTimeOut; 
+
+  if(GetNumOfUsedSessions() >= g_BMCInfo.IpmiConfig.MaxSession)
+  {
+      CleanSession();
+  }
+  /* Add Session information in Table */
+  AddSession (&SessionInfo);
+
+
 	g_BMCInfo.pUserInfo = pUserInfo;
 	
-	g_BMCInfo.LanSession.AuthType	=	pGetSesChalReq->AuthType;
-	g_BMCInfo.LanSession.SessionID = 0x1234;//trng_get_true_random_data();
-	
 	pGetSesChalRes->CompletionCode = CC_NORMAL;
-    pGetSesChalRes->TempSessionID  = g_BMCInfo.LanSession.SessionID;
+  pGetSesChalRes->TempSessionID  = TempSessId;
 
 	/* generate Randam Challenge String */
-    for(Index=0;Index < CHALLENGE_STR_LEN;Index++)
-    {
-        ChallengeString[Index] = 0x56;//trng_get_true_random_data()&0xff;
-    }
-    memcpy(pGetSesChalRes->ChallengeString, ChallengeString, CHALLENGE_STR_LEN);
-
-    return sizeof (GetSesChallengeRes_T);
+  for(Index=0;Index < CHALLENGE_STR_LEN;Index+=4)
+  {
+      TempRandom = stm32_generate_random32bit();
+      printf("TempRandom: %#lx\n", TempRandom);
+      ChallengeString[Index] = TempRandom&0xff;
+      ChallengeString[Index+1] = TempRandom>>8;
+      ChallengeString[Index+2] = TempRandom>>16;
+      ChallengeString[Index+3] = TempRandom>>24;
+  }
+  memcpy(pGetSesChalRes->ChallengeString, ChallengeString, CHALLENGE_STR_LEN);
+
+  return sizeof (GetSesChallengeRes_T);
 }
 
 /*---------------------------------------
@@ -1433,34 +1388,46 @@ ActivateSession ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
 	//TODO: dummy data
 	ActivateSesReq_T*   pAcvtSesReq = ( ActivateSesReq_T*)pReq;
 	ActivateSesRes_T*   pAcvtSesRes = ( ActivateSesRes_T*)pRes;
-      
+  uint32_t *CurSesID,*curchannel;
+  SessionInfo_T*      pSessInfo;
+
+    /* Initial Outbound Sequence Number cannot be null */  
+    if (pAcvtSesReq->OutboundSeq == 0)  
+    {  
+        pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_SEQ_OUT_OF_RANGE;  
+        return sizeof(*pRes);  
+    }
 
-    // /* Initial Outbound Sequence Number cannot be null */  
-    // if (pAcvtSesReq->OutboundSeq == 0)  
-    // {  
-    //     pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_SEQ_OUT_OF_RANGE;  
-    //     return sizeof(*pRes);  
-    // }
-   
-    // // Check for Reserved bitss
-    // if((pAcvtSesReq->AuthType == AUTHTYPE_RESERVED) || (pAcvtSesReq->AuthType > AUTHTYPE_OEM_PROPRIETARY))
-    // {
-    //     pAcvtSesRes->CompletionCode = CC_INV_DATA_FIELD;
-    //     return sizeof (*pRes);
-    // }
+    CurSesID = pthread_getspecific(g_tls.CurSessionID);  
+    curchannel = pthread_getspecific(g_tls.CurChannel);  
+    
+    pSessInfo = getSessionInfo (SESSION_ID_INFO, CurSesID);
+    if(pSessInfo == NULL)
+    {
+        pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_INVALID_SESSION_ID;
+        return sizeof (*pRes);
+    }
+
+    pSessInfo->Activated    = TRUE;
+    pSessInfo->Channel      = (*curchannel & 0xF);
+    /* set the Max Privilege allowed for the Session*/
+    pSessInfo->MaxPrivilege = pAcvtSesReq->Privilege;
+    /* set the Out bound sequensce Number */
+    pSessInfo->OutboundSeq  = (pAcvtSesReq->OutboundSeq);
+
+    g_BMCInfo.SessionHandle += 1;
+    pSessInfo->SessionHandle = g_BMCInfo.SessionHandle;
 
-    // if ((pAcvtSesReq->Privilege == PRIV_LEVEL_RESERVED) || (pAcvtSesReq->Privilege > PRIV_LEVEL_PROPRIETARY))
-    // {
-    //    pAcvtSesRes->CompletionCode = CC_INV_DATA_FIELD;/* Privilege is Reserved */
-    //    return sizeof (*pRes);
-    // }
 
     pAcvtSesRes->CompletionCode = CC_NORMAL;
-    pAcvtSesRes->AuthType = g_BMCInfo.LanSession.AuthType;
-    pAcvtSesRes->SessionID = g_BMCInfo.LanSession.SessionID;
-    pAcvtSesRes->InboundSeq = 0x78;//trng_get_true_random_data();
+    pAcvtSesRes->AuthType = (pSessInfo->AuthType & 0x0F);
+    pAcvtSesRes->SessionID = pSessInfo->SessionID;
+    pAcvtSesRes->InboundSeq = stm32_generate_random32bit();
     pAcvtSesRes->Privilege = 0x04;
 
+    pSessInfo->InboundRecv = 0xFF;
+    pSessInfo->InboundSeq = (pAcvtSesRes->InboundSeq -1);
+
     return sizeof (ActivateSesRes_T);
 }
 
@@ -1505,7 +1472,45 @@ SetSessionPrivLevel ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
 int
 CloseSession ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
 {
-	//TODO: dymmy data
+    CloseSesReq_T*  pCloseSesReq = (CloseSesReq_T*)pReq;
+	  SessionInfo_T*  pSessInfo;
+    uint32_t          SessionID;
+
+    *pRes = CC_REQ_INV_LEN;
+
+    if ((4 != ReqLen) && (5 != ReqLen))
+    {
+        return sizeof (*pRes);
+    }
+
+    if (0 == pCloseSesReq->SessionID)
+    {
+        if (5 != ReqLen)
+        {
+            return sizeof (*pRes);
+        }
+        SessionID = (uint32_t)pCloseSesReq->SessionHandle;
+        *pRes = CC_CLOSE_INVALID_SESSION_ID_HANDLE;
+        pSessInfo = getSessionInfo (SESSION_HANDLE_INFO, &SessionID);
+    }
+    else
+    {
+        if (4 != ReqLen)
+        {
+            return sizeof (*pRes);
+        }
+        SessionID = pCloseSesReq->SessionID;
+        *pRes = CC_CLOSE_INVALID_SESSION_ID;
+        pSessInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
+    }
+
+    if ((NULL == pSessInfo) || (0 == pSessInfo->Activated))
+    {
+        return sizeof (*pRes);
+    }
+
+    /* The SessionInfo is deleted form session table  from interface */
+    DeleteSession(pSessInfo);
     *pRes = CC_NORMAL;
     return sizeof (*pRes);
 }

+ 4 - 4
app/bmc/msghndlr/MsgHndlrTask.c

@@ -64,8 +64,8 @@ TimerTaskTbl_T    m_TimerTaskTbl [20] =
 //	{ 1,    PETAckTimerTask },
 //	{ 1,    PEFStartDlyTimerTask },
 	{ 1,    SessionTimerTask },
-	{ 1,    PendingBridgeResTimerTask },
-	{ 1,    PendingSeqNoTimerTask },
+//	{ 1,    PendingBridgeResTimerTask },
+//	{ 1,    PendingSeqNoTimerTask },
 //	{ 1,    FlashTimerTask },
 
 //	#if FRB_SUPPORT == 1
@@ -294,7 +294,7 @@ ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes)
 	//send message command
 	if( (CMD_SEND_MSG == pReq->Cmd) && (NETFN_APP == pReq->NetFnLUN >> 2))
 	{
-		//printf("log 4\n");
+		printf("log 4\n");
 		int Offset = 0;
 		uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
 		if ((0 == pRes->Size) &&
@@ -329,7 +329,7 @@ ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes)
 		}
 	}
 
-	//printf("log 5\n");
+//	printf("log 5\n");
 	
 	return;
 }

+ 4 - 1
app/bmc/readme.txt

@@ -12,4 +12,7 @@
 	g_BMCInfo.UserInfoTbl[0]: UserId = 1
 	g_BMCInfo.UserInfoTbl[1]: UserId = 2
 	g_BMCInfo.UserInfoTbl[2]: UserId = 3
-	...
+	...
+
+4. SessionTblInfo
+	所有的当前会话信息均保存在SessionTblInfo里,Init_SessionTbl用来初始化结构体。

+ 1 - 1
app/driver/Platform/.platform.mod.o.cmd

@@ -1,4 +1,4 @@
-cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.o := arm-uclinuxeabi-gcc -Wp,-MD,/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/.platform.mod.o.d  -nostdinc -isystem /gd32f450_prj/linux-cortexm-1.14.2/tools/arm-2010q1/bin/../lib/gcc/arm-uclinuxeabi/4.4.1/include -I/gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include -Iinclude  -include include/generated/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-stm32/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -marm -mabi=aapcs-linux -mno-thumb-interwork -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -mcpu=cortex-m3 -Wa,-mcpu=cortex-m3 -msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/common_include  -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(platform.mod)"  -D"KBUILD_MODNAME=KBUILD_STR(platform)"  -DMODULE -mlong-calls -fno-optimize-sibling-calls -c -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.c
+cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.o := arm-uclinuxeabi-gcc -Wp,-MD,/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/.platform.mod.o.d  -nostdinc -isystem /gd32f450_prj/linux-cortexm-1.14.2/tools/arm-2010q1/bin/../lib/gcc/arm-uclinuxeabi/4.4.1/include -I/gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include -Iinclude  -include include/generated/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-stm32/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -marm -mabi=aapcs-linux -mno-thumb-interwork -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -mcpu=cortex-m3 -Wa,-mcpu=cortex-m3 -msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/Legacy -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/common_include  -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(platform.mod)"  -D"KBUILD_MODNAME=KBUILD_STR(platform)"  -DMODULE -mlong-calls -fno-optimize-sibling-calls -c -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.c
 
 deps_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.o := \
   /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.mod.c \

+ 1 - 1
app/driver/Platform/.platform.o.cmd

@@ -1 +1 @@
-cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.o := arm-uclinuxeabi-ld -EL    -r -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/system_stm32f4xx.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o 
+cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.o := arm-uclinuxeabi-ld -EL    -r -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/system_stm32f4xx.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o 

+ 5 - 1
app/driver/Platform/.platform_main.o.cmd

@@ -1,4 +1,4 @@
-cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o := arm-uclinuxeabi-gcc -Wp,-MD,/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/.platform_main.o.d  -nostdinc -isystem /gd32f450_prj/linux-cortexm-1.14.2/tools/arm-2010q1/bin/../lib/gcc/arm-uclinuxeabi/4.4.1/include -I/gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include -Iinclude  -include include/generated/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-stm32/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -marm -mabi=aapcs-linux -mno-thumb-interwork -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -mcpu=cortex-m3 -Wa,-mcpu=cortex-m3 -msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/common_include  -DMODULE -mlong-calls -fno-optimize-sibling-calls -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(platform_main)"  -D"KBUILD_MODNAME=KBUILD_STR(platform)"  -c -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.c
+cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o := arm-uclinuxeabi-gcc -Wp,-MD,/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/.platform_main.o.d  -nostdinc -isystem /gd32f450_prj/linux-cortexm-1.14.2/tools/arm-2010q1/bin/../lib/gcc/arm-uclinuxeabi/4.4.1/include -I/gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include -Iinclude  -include include/generated/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-stm32/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -marm -mabi=aapcs-linux -mno-thumb-interwork -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -mcpu=cortex-m3 -Wa,-mcpu=cortex-m3 -msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/Legacy -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/common_include  -DMODULE -mlong-calls -fno-optimize-sibling-calls -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(platform_main)"  -D"KBUILD_MODNAME=KBUILD_STR(platform)"  -c -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.c
 
 deps_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o := \
   /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.c \
@@ -506,6 +506,10 @@ deps_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platfo
   /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h \
   /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/driver.h \
   /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/stm32f429xx.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rng.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h \
+    $(wildcard include/config/disable.h) \
+    $(wildcard include/config/enable.h) \
 
 /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o: $(deps_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o)
 

+ 1 - 1
app/driver/Platform/.tmp_versions/platform.mod

@@ -1,2 +1,2 @@
 /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform.ko
-/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/system_stm32f4xx.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o
+/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/system_stm32f4xx.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o

+ 3 - 0
app/driver/Platform/Makefile

@@ -4,6 +4,8 @@ KERNELDIR	:= $(INSTALL_ROOT)/linux
 platform-objs += ../STM32F4xx_HAL_Driver/system_stm32f4xx.o
 platform-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o
 platform-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.o
+platform-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.o
+platform-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o
 
 platform-objs += platform_main.o
 
@@ -13,6 +15,7 @@ APPDIR := $(INSTALL_ROOT)/projects/gd32450i-eval/app
 
 EXTRA_CFLAGS += -I$(APPDIR)/driver/STM32F4xx_HAL_Driver
 EXTRA_CFLAGS += -I$(APPDIR)/driver/STM32F4xx_HAL_Driver/Inc
+EXTRA_CFLAGS += -I$(APPDIR)/driver/STM32F4xx_HAL_Driver/Inc/Legacy
 EXTRA_CFLAGS += -I$(APPDIR)/driver
 EXTRA_CFLAGS += -I$(APPDIR)/common_include
 

BIN
app/driver/Platform/platform.ko


+ 18 - 8
app/driver/Platform/platform_main.c

@@ -17,6 +17,8 @@
 #include "stm32f4xx.h"
 #include "stm32f4xx_hal_cortex.h"
 #include "driver.h"
+#include "stm32f4xx_hal_rng.h"
+#include "stm32_hal_legacy.h"
 
 static int major = MAJOR_PLATFORM;
 static int minor = 0;
@@ -26,10 +28,7 @@ static int count = 1;
 #define DEVNAME "Platform_GD32F450I"
 struct device *dev = NULL;
 
-typedef struct {
-	uint32_t	priority_group;
-} platform_arg_t;
-
+RNG_HandleTypeDef hrng;
 
 static int platform_open(struct inode *inode, struct file *filep);
 static int platform_close(struct inode *inode, struct file *filep);
@@ -51,13 +50,15 @@ static struct file_operations platform_ops =
 
 static int platform_open(struct inode *inode, struct file *filep)
 {
-	printk("---> platform open\n");
+	//printk("---> platform open\n");
+	
 	return 0;
 }
 
 static int platform_close(struct inode *inode, struct file *filep)
 {
-	printk("---> platform close\n");
+	//printk("---> platform close\n");
+	
 	return 0;
 }
 
@@ -101,6 +102,11 @@ static int platform_ioctl(struct inode *indoe, struct file *filep, unsigned int
 	case RESET_MCU:
 		NVIC_SystemReset();
 		break;
+	case GET_32BIT_RANDOM:
+		HAL_RNG_GenerateRandomNumber(&hrng, &platform_arg.random_32bit);
+		if(copy_to_user((void*)arg, &platform_arg, sizeof(platform_arg_t)))
+			return -EFAULT;
+		break;
 	default:
 		printk(KERN_ERR"Invalid cmd\n");
 		break;
@@ -120,12 +126,16 @@ static int platform_ioctl(struct inode *indoe, struct file *filep, unsigned int
 extern uint32_t SystemCoreClock;
 void platform_hw_init(void)
 {
+	HAL_StatusTypeDef retVal;
 	/* Set Interrupt Group Priority */
 	HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
 
 	SystemCoreClockUpdate();
-		
-	//printk("STM32F429 SystemCoreClock: %d\n", SystemCoreClock);
+	
+	__RNG_CLK_ENABLE();
+	//Init random generator
+	hrng.Instance = RNG;
+	retVal = HAL_RNG_Init(&hrng);	
 }
 
 static int __init platform_init(void)

+ 68 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_rng.o.cmd

@@ -0,0 +1,68 @@
+cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o := arm-uclinuxeabi-gcc -Wp,-MD,/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_rng.o.d  -nostdinc -isystem /gd32f450_prj/linux-cortexm-1.14.2/tools/arm-2010q1/bin/../lib/gcc/arm-uclinuxeabi/4.4.1/include -I/gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include -Iinclude  -include include/generated/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-stm32/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -marm -mabi=aapcs-linux -mno-thumb-interwork -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -mcpu=cortex-m3 -Wa,-mcpu=cortex-m3 -msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/Legacy -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver -I/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/common_include  -DMODULE -mlong-calls -fno-optimize-sibling-calls -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(stm32f4xx_hal_rng)"  -D"KBUILD_MODNAME=KBUILD_STR(platform)"  -c -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c
+
+deps_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o := \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h \
+  include/linux/types.h \
+    $(wildcard include/config/uid16.h) \
+    $(wildcard include/config/lbdaf.h) \
+    $(wildcard include/config/phys/addr/t/64bit.h) \
+    $(wildcard include/config/64bit.h) \
+  /gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include/asm/types.h \
+  include/asm-generic/int-ll64.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include/asm/bitsperlong.h \
+  include/asm-generic/bitsperlong.h \
+  include/linux/posix_types.h \
+  include/linux/stddef.h \
+  include/linux/compiler.h \
+    $(wildcard include/config/trace/branch/profiling.h) \
+    $(wildcard include/config/profile/all/branches.h) \
+    $(wildcard include/config/enable/must/check.h) \
+    $(wildcard include/config/enable/warn/deprecated.h) \
+  include/linux/compiler-gcc.h \
+    $(wildcard include/config/arch/supports/optimized/inlining.h) \
+    $(wildcard include/config/optimize/inlining.h) \
+  include/linux/compiler-gcc4.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/linux/arch/arm/include/asm/posix_types.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/stm32f4xx.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/stm32f429xx.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/core_cm4.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/system_stm32f4xx.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_conf.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/common_include/com_gpio.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dac.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dac_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_sram.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_fmc.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_nor.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_nand.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pccard.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rng.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rtc.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rtc_ex.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_usart.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_wwdg.h \
+  /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_qspi.h \
+
+/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o: $(deps_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o)
+
+$(deps_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.o):

+ 6 - 0
app/driver/driver.h

@@ -58,6 +58,7 @@
 #define SET_PRIORITY_GROUP 				GENERATE_CMD(IOCTL_MAGIC, MAJOR_PLATFORM, 0)
 #define GET_PRIORITY_GROUP 				GENERATE_CMD(IOCTL_MAGIC, MAJOR_PLATFORM, 1)
 #define RESET_MCU 						GENERATE_CMD(IOCTL_MAGIC, MAJOR_PLATFORM, 2)
+#define GET_32BIT_RANDOM 				GENERATE_CMD(IOCTL_MAGIC, MAJOR_PLATFORM, 3)
 
 typedef struct {
 	uint32_t address;
@@ -101,4 +102,9 @@ typedef struct {
 	uint16_t value[10];
 } adc_arg_t;
 
+typedef struct {
+	uint32_t	priority_group;
+	uint32_t 	random_32bit;
+} platform_arg_t;
+
 #endif /* __DRIVER_H__ */

+ 5 - 5
app/hal_api/hal_i2c_interface.c

@@ -74,11 +74,11 @@ int stm32_i2c_slave_recv(int fd, uint8_t *pBuf)
 	}
 	memcpy(pBuf, i2c_arg.buf, i2c_arg.Size);
 
-	int i;
-	printf("i2c recv: ");
-	for(i=0;i<i2c_arg.Size;i++)
-		printf("%#x ", pBuf[i]);
-	printf("\n");
+	// int i;
+	// printf("i2c recv: ");
+	// for(i=0;i<i2c_arg.Size;i++)
+	// 	printf("%#x ", pBuf[i]);
+	// printf("\n");
 	return i2c_arg.Size;
 }
 

+ 1 - 0
app/hal_api/hal_interface_api.h

@@ -41,5 +41,6 @@ int stm32_adc_get_value(uint8_t channel, uint16_t *value);
 /* UART Interface */
 /* Platform Interface */
 int stm32_reset_mcu(void);
+uint32_t stm32_generate_random32bit(void);
 
 #endif /* __HAL_INTERFACE_API_H__ */

+ 22 - 0
app/hal_api/hal_platform_interface.c

@@ -29,4 +29,26 @@ int stm32_reset_mcu(void)
 	close(fd);
 
 	return ret;
+}
+
+uint32_t stm32_generate_random32bit(void)
+{
+	int fd;
+	int ret;
+	platform_arg_t args;
+	
+	fd = open(DEV_NAME, O_RDWR);
+	if(fd == -1)
+	{
+		printf("Open %s failed!\n", DEV_NAME);
+	}
+
+	ret = ioctl(fd, GET_32BIT_RANDOM, &args);
+	if(ret == -1)
+	{
+		printf("Get random failed!\n");
+	}
+	close(fd);
+
+	return args.random_32bit;
 }

BIN
app/test_app/test_app


+ 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
@@ -20,9 +20,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