소스 검색

1.增加加密解密算法函数
2.利用Fota进行保护板刷写测试

CHENJIE-PC\QiXiang_CHENJIE 4 년 전
부모
커밋
1483a27040
4개의 변경된 파일46개의 추가작업 그리고 7개의 파일을 삭제
  1. 3 1
      inc/Fota.h
  2. 4 4
      inc/TcpTask.h
  3. 3 2
      src/Fota.c
  4. 36 0
      src/UartTask.c

+ 3 - 1
inc/Fota.h

@@ -7,7 +7,9 @@
  * 
  ****************************************************************************/
 #include "bsp_custom.h"
-
+#define FLASH_BMS_FOTA_START_ADDR         0x2E6000
+#define FLASH_BMS_FOTA_LEN               0x204800  //200k
+#define FLASH_BMS_FOTA_END_ADDR         0x318000
 typedef struct _Fota_Type
 {
     bool Fota_update_error ;

+ 4 - 4
inc/TcpTask.h

@@ -22,10 +22,10 @@ extern UINT32 TcpService;
 // #define QX_TCP_IPADRRES				"47.97.127.222"
 // #define QX_TCP_PORT					8712
 /*---------------测试IP地址-----------------------------------*/
-#define QX_TCP_IPADRRES				"39.103.177.126"
-#define QX_TCP_PORT					8712
-// #define QX_TCP_IPADRRES				"120.26.68.165"
-// #define QX_TCP_PORT					14319
+// #define QX_TCP_IPADRRES				"39.103.177.126"
+// #define QX_TCP_PORT					8712
+#define QX_TCP_IPADRRES				"120.26.68.165"
+#define QX_TCP_PORT					14319
 /*---------------测试IP地址END-----------------------------------*/
 #define BATT_SN_LEN             17
 #define TCP_START_SYM1			0x23

+ 3 - 2
src/Fota.c

@@ -23,7 +23,8 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
     UINT8 Fota_Answer[43];
     UINT8 Fota_Cmd;
     INT8 ret;
-    Fota_S.Fota_Flash_Addres = FLASH_FOTA_REGION_START;
+    //Fota_S.Fota_Flash_Addres = FLASH_FOTA_REGION_START;
+    Fota_S.Fota_Flash_Addres = FLASH_BMS_FOTA_START_ADDR;
     if(*(DataPtr+30)==0x01)
     {
         Fota_Cmd = *(DataPtr+31);
@@ -44,7 +45,7 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
                 memcpy(&Fota_Answer[24],(DataPtr+24),18);
                 Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
                 tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300  0x78000
+                BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300  0x78000
                 break;
             }
             case 0x02:

+ 36 - 0
src/UartTask.c

@@ -431,4 +431,40 @@ BOOL BattHeaterSwitch(UINT8* heaterSwitch)
                 }
         }
         return isNeedtoSwitch;
+}
+
+UINT8  decryptionAlgorithm (UINT16 cipherText)
+{
+        UINT16 plainText = 1;        
+        UINT16 publicKeyD = 43;
+        UINT16 publicKeyN = 10961;
+        cipherText = cipherText % publicKeyN;
+        while(publicKeyD >0)
+        {
+                if(publicKeyD % 2 ==1)
+                {                        
+                        plainText = plainText * cipherText % publicKeyN;
+                }
+                publicKeyD = publicKeyD/2;                
+                cipherText = (cipherText * cipherText) % publicKeyN;
+        }
+        return (UINT8)plainText;
+}
+
+UINT16  encryptionAlgorithm (UINT8 plainText)
+{
+        UINT16 cipherText = 1;        
+        UINT16 privateKeyE = 37507;
+        UINT16 privateKeyN = 10961;
+        plainText = plainText % privateKeyN;
+        while(privateKeyE >0)
+        {
+                if(privateKeyE % 2 ==1)
+                {                        
+                        cipherText = cipherText * plainText % privateKeyN;
+                }
+                privateKeyE = privateKeyE/2;                
+                cipherText = (plainText * plainText) % privateKeyN;
+        }
+        return cipherText;
 }