revised RFAC process

This commit is contained in:
Yunhorn 2023-11-08 17:51:55 +08:00
parent 8520de3835
commit b8b4e6a144
2 changed files with 21 additions and 28 deletions

View File

@ -34,7 +34,6 @@ hmac_result_t hmac_result;
uint32_t sts_hmac_verify(void)
{
uint8_t i=0;
uint8_t uid[8]="";
uint32_t ret=0;
hmac_result.ac_pass = 60;
@ -42,22 +41,17 @@ uint32_t sts_hmac_verify(void)
GetUniqueId(uid);
ret = sts_hmac_sha1((const uint8_t *) mKey, sizeof(mKey), (const uint8_t*)(uid+4), 4, &hmac_result);
/*
for (i=0;i<sizeof(Computed_Tag_SHA1); i++) {
APP_LOG(TS_OFF,VLEVEL_M,"0x%02x ", hmac_result.hmac_tag[i]);
}
*/
ret = memcmp(hmac_result.hmac_tag, (void *)sts_ac_code, sizeof(sts_ac_code));
if (ret !=0)
{
hmac_result.ac_pass =0U;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nHMAC Verify Error \r\n");
} else
{
ret =0;
hmac_result.ac_pass = 1U;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nHMAC Verify Success\r\n");
}
hmac_result.ac_pass = (ret == 0x0)?1U:0U;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nHMAC Verify Success = %u \r\n", hmac_result.ac_pass);
return ret;
}

View File

@ -1910,7 +1910,7 @@ void OnStoreSTSCFGContextRequest(void)
/* USER CODE BEGIN OnStoreContextRequest_1 */
uint8_t i=0,j=0,nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0};
#if (defined(YUNHORN_STS_O5_ENABLED) || defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R5_ENABLED))
#if (defined(YUNHORN_STS_O5_ENABLED) || defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R4_ENABLED) || defined(YUNHORN_STS_R5_ENABLED))
sts_cfg_nvm.length = STS_NVM_CFG_SIZE;
nvm_store_value[i++] = sts_cfg_nvm.mtmcode1;
nvm_store_value[i++] = sts_cfg_nvm.mtmcode2;
@ -1975,12 +1975,12 @@ void STS_REBOOT_CONFIG_Init(void)
UTIL_MEM_cpy_8(nvm_stored_value, (void *)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE);
/* USER CODE BEGIN OnRestoreContextRequest_Last */
#if defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R5_ENABLED)
#if defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R4_ENABLED) || defined(YUNHORN_STS_R5_ENABLED)
if ((nvm_stored_value[NVM_MTM1] != sts_mtmcode1) || (nvm_stored_value[NVM_MTM2] != sts_mtmcode2) || (nvm_stored_value[NVM_VER] != sts_version))
{
APP_LOG(TS_OFF, VLEVEL_H, "\r\nInitial Boot with Empty Config, Flash with default config....\r\n");
OnStoreSTSCFGContextRequest();
UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE);
//UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE);
HAL_Delay(1000);
} else
{
@ -2030,15 +2030,6 @@ void OnRestoreSTSCFGContextProcess(void)
periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit
TxPeriodicity= periodicity*1000; // to ms
if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0))
{
OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
} else
{ // ensure it's not in production yet
OnTxPeriodicityChanged(TxPeriodicity); // in msec unit
}
uint32_t samplingperiodicity = (sts_cfg_nvm.sampling); //Heart-beat or Sampling interval
if ((char)sts_cfg_nvm.s_unit =='M') {
samplingperiodicity *= 60;
@ -2048,16 +2039,24 @@ void OnRestoreSTSCFGContextProcess(void)
samplingperiodicity *= 1;
}
//Heart-beat or Sampling interval
samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit
HeartBeatPeriodicity = samplingperiodicity*1000;
if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0))
{ // ensure it's not in production yet
OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
} else
{
OnTxPeriodicityChanged(TxPeriodicity); // in msec unit
//Heart-beat or Sampling interval
samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit
HeartBeatPeriodicity = samplingperiodicity*1000;
#if defined(YUNHORN_STS_O6_ENABLED) ||defined(YUNHORN_STS_O5_ENABLED)
OnYunhornSTSSamplingPeriodicityChanged(HeartBeatPeriodicity); // in m-sec unit
#endif
#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)
#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R4_ENABLED)
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
#endif
}
sts_work_mode = sts_cfg_nvm.work_mode;
sts_service_mask = sts_cfg_nvm.sts_service_mask;