|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
|
|
|
///-------------------------------------------------------------------------
|
|
|
|
/// @file bsp_drv.c
|
|
|
|
/// @brief bsp @ driver config
|
|
|
|
///-------------------------------------------------------------------------
|
|
|
|
/// @version 1.0
|
|
|
|
/// @author CC
|
|
|
|
/// @date 20180331
|
|
|
|
/// @note cc_AS_stc02
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "task_encrypt.h"
|
|
|
|
#include "../bsp/bsp_config.h"
|
|
|
|
#include "../msp/uart0.h"
|
|
|
|
#include "../msp/eeprom.h"
|
|
|
|
#include "../bsp/chipid.h"
|
|
|
|
|
|
|
|
struct ts_eeprom_enc eep_enc;
|
|
|
|
struct mcu_encrypt_info enc_info;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief: eeprom的D_EEP_ENC_IN_SECTOR、D_EEP_ENC_IN_BLOCK中提前存放了加密信息: enc_key, enc_val(enc_key+chipid计算所得)
|
|
|
|
* @param: void
|
|
|
|
* @return: 1 is ok , 0 is failed
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int L3_mcu_id_ok(void)
|
|
|
|
{
|
|
|
|
U8 i = 0;
|
|
|
|
|
|
|
|
//1. 获取eeprom中存储的enc信息
|
|
|
|
if(L1_eep_read_block(D_EEP_ENC_IN_SECTOR, D_EEP_ENC_IN_BLOCK, D_EEP_SECTOR_BLOCK_SIZE, (U8*)&eep_enc,NULL) == 1)
|
|
|
|
{
|
|
|
|
//L0_uart0_sendstr("e2p read enc failed");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//L0_uart0_sendstr("e2p read enc success");
|
|
|
|
|
|
|
|
//2.获取MCU_ID
|
|
|
|
L0_id_get_rom(enc_info.mcu_id);
|
|
|
|
//L0_uart0_sendArray(enc_info.mcu_id,MCU_ID_LEN);
|
|
|
|
|
|
|
|
//3.根据mcu_id和enc_key计算enc_val
|
|
|
|
//enc_key = ((U32)eep_enc.enc_key[0] << 24) | (eep_enc.enc_key[1] << 16) | (eep_enc.enc_key[2] << 8) |(eep_enc.enc_key[3] << 0);
|
|
|
|
Lc_encrypt_id1((U8*)enc_info.mcu_enc_id, (U8*)enc_info.mcu_id, eep_enc.enc_key, MCU_ID_LEN);
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
//4.判断enc_val是否一致
|
|
|
|
for(i=0;i<MCU_ID_KEY_LEN;i++)
|
|
|
|
{
|
|
|
|
if(enc_info.mcu_enc_id[i] != eep_enc.enc_val[i])
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void L3_encrypt_handler(void)
|
|
|
|
{
|
|
|
|
#if(D_CODE_ENCRYPTION_TYPE == TYPE_ENCRYPTION_ENABLE)
|
|
|
|
if(L3_mcu_id_ok())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
L0_uart0_sendstr("X");
|
|
|
|
D_sys_delay_msec(1000);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|