Hi Team,
I am working on a code wherein the device is in scanning mode for a particular duration, then encrypts the data received and advertises the data ecrypted. I am using the hardware encryption for the encryption purpose. The problem I am facing is that the encryption is not getting done when my device is in scanning mode. The callback handler gapm_use_enc_block_ind_handler is not getting invoked.
谢谢 ,
队怀士队
Device:

Hi Wisilica,
DA14580不会导出API以使用硬件加密块。您可能需要软件加密。
您使用了哪个API和预期的GAPM_USE_ENC_BLOCK_IND_HANDLER?
Hi ,
在设备退出扫描(观察者)模式后调用时,硬件加密工作。当设备处于广播模式时,它还运行。
这是我们使用的代码片段:
void aes_encrypt_hw(uint8_t * data,uint8_t *键)
{
struct gapm_use_enc_block_cmd *cmd = KE_MSG_ALLOC(GAPM_USE_ENC_BLOCK_CMD, TASK_GAPM, TASK_APP, gapm_use_enc_block_cmd);
uint8_t rev_key [16];
uint8_t rev_data [16];
cmd->操作= gapm_use_enc_block;
for(i=0;i<16;++i)
{
rev_key [i] = *(键+(15-i));
rev_data[i] = *(data+(15-i));
}
memcpy(cmd->操作数_1,rev_key,16);
memcpy(cmd->操作数_2,rev_data,16);
ke_msg_send(cmd);
}
Now, once encryption is completed, we get a callback to the handler ,
static int gapm_use_enc_block_ind_handler(ke_msg_id_t msgid,
struct gapm_use_enc_block_ind * param,
ke_task_id_t dest_id,
ke_task_id_t src_id)在app_gap_process_handler中定义,如下所示:
static const struct ke_msg_handler app_gap_process_handlers[]=
{
{gapm_device_ready_ind,(ke_msg_func_t)gapm_device_ready_ind_handler},
{gapm_cmp_evt,(ke_msg_func_t)gapm_cmp_evt_handler},
{gapc_cmp_evt,(ke_msg_func_t)gapc_cmp_evt_handler},
{gapc_connection_req_ind,(ke_msg_func_t)gapc_connection_req_ind_handler},
{gapc_disconnect_ind,(ke_msg_func_t)gapc_disconnect_ind_handler},
{app_module_init_cmp_evt,(ke_msg_func_t)app_module_init_cmp_evt_handler},
{GAPM_ADV_REPORT_IND, (ke_msg_func_t)gapm_adv_report_ind_handler},
{gapm_use_enc_block_ind,(ke_msg_func_t)gapm_use_enc_block_ind_handler},
#if(ble_app_sec)
{gapc_security_ind,(ke_msg_func_t)gapc_security_ind_handler},
#万一
};
We are able to get the proper encrypted result using DA14580 chip in all cases except when the device is in SCAN mode.
Thanks,
Wisilica.
嗨wisillica,
我试着在扫描模式中,你已经提到我ve invoked the encryption function when an advertising indication occured and i could always get the callback in the catch rest function, so please try to catch the GAPM_USE_ENC_BLOCK_IND in that function instead of the app_gap_process_handlers[] array.
谢谢mt_dialog.
Hi ,
在DA14580数据表中,芯片支持硬件加密(屏幕截图附带的屏幕截图)。因此,如果在DA14580芯片中使用硬件AES加密,请建议在长时间使用硬件AES加密。
Thanks,
Wisilica.
Hi wisilica,
Yes the chip has an AES-128 bit encryption Processor, i am not aware of any issues, are you experiencing something particular in your application ? Its about the Scan and the encryption indication, have you tried what i ve mentioned above ?
谢谢mt_dialog.
你好,
Yes, I tried to include the callback handler of encryption in the the catch rest function as you mentioned above,but I was not able to get callback to this function as a result of hardware encryption complete. The hardware encryption is called during the scanning phase of the device.
Thanks,
Wisilica.
Hi wisilica,
从SDK 5.0.4的模板中,我执行了以下修改以测试您提到的内容,并且我可以验证加密消息始终返回从广告指示回调的命令时返回指示。
void encrypt_data(void)
{
UINT8_T键[16] = {15,14,11,12,11,10,9,8,7,6,5,4,3,2,1,0};
uint8_t plaintext [16] = {0xff,0xee,0xDD,0xCC,0xBB,0xAA,0x99,0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11,0x00};
struct gapm_use_enc_block_cmd *cmd = KE_MSG_ALLOC(GAPM_USE_ENC_BLOCK_CMD, TASK_GAPM, TASK_APP, gapm_use_enc_block_cmd);
cmd->操作= gapm_use_enc_block;
memcpy(cmd->操作数_1,键,16);
Memcpy(CMD-> Operand_2,明文,16);
ke_msg_send(cmd);
}
void user_on_adv_report_ind(struct gapm_adv_report_ind const * param)
{
arch_set_pxact_gpio();
arch_printf("Connect with %02x %02x %02x %02x %02x %02x \n\r",
param->report.adv_addr.addr[5],
param->report.adv_addr.addr[4],
param-> eport.adddr.addr [3],
param-> eport.adddr.addr [2],
param->report.adv_addr.addr[1],
param-> report.adddr.addr [0]);
encrypt_data();
}
void user_catch_rest_hndl(ke_msg_id_t const msgid,
void const * param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
开关(msgs)
{
CASE GAPM_USE_ENC_BLOCK_IND:
{
uint8_t encryted_data [16];
Memset(EncryTed_data,0,sizeof(encryted_data));
struct gapm_use_enc_block_ind const * msg_param =(结构gapm_use_enc_block_ind const *)(param);
memcpy(encryted_data,msg_param->结果,sizeof(encryted_data));
arch_printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n\r",
EncryTed_data [0],
EncryTed_data [1],
encryted_data[2],
encryted_data[3],
EncryTed_data [4],
EncryTed_data [5],
encryted_data[6],
EncryTed_data [7],
Encryted_data [8],
EncryTed_data [9],
EncryTed_data [10],
EncryTed_data [11],
EncryTed_data [12],
encryted_data[13],
encryted_data[14],
EncryTed_data [15]
);
}break;
If there is an advertising indication that printed the bd address and called the encrypt_data() function and the encryption indication has not occured it would be easy to spot on the terminal log, which is something that i dont see on my setup. Even if two advertising indications come in a very short noticed the message will get in the queue and two encryption responses will be printed. So can you please try what i ve mention.
谢谢mt_dialog.