中
A
feature_smp_security例程中已经实现配对时,在slave 端显⽰密钥,master 端输⼊密钥。不过每次配对的密钥都是随机生成的,如何修改为静态密钥??
你好,你可以按照如下方法设置静态密钥。
user_init里加这两句: blc_gap_registerHostEventHandler( app_host_event_callback ); blc_gap_setEventMask( GAP_EVT_MASK_SMP_TK_DISPALY ); 在app.c的user_init 前加这些代码:
typedef union { struct{ u8 bondingFlag : 2; u8 MITM : 1; u8 SC : 1; u8 keyPress: 1; u8 rsvd: 3; }; u8 authType; }smp_authReq_t; typedef union{ struct { u8 encKey : 1; u8 idKey : 1; u8 sign : 1; u8 linkKey : 4; }; u8 keyIni; }smp_keyDistribution_t; typedef struct{ u8 code; //req = 0x01; rsp = 0x02; u8 ioCapablity; u8 oobDataFlag; smp_authReq_t authReq; u8 maxEncrySize; smp_keyDistribution_t initKeyDistribution; smp_keyDistribution_t rspKeyDistribution; }smp_paring_req_rsp_t; typedef struct{ u8 paring_tk[16]; // in security connection to keep own random u8 own_ltk[16]; //used for generate ediv and random smp_paring_req_rsp_t paring_req; smp_paring_req_rsp_t paring_rsp; smp_authReq_t auth_req; u8 own_conn_type; //current connection peer own type u16 rsvd; u8 own_conn_addr[6]; u8 local_irk[16]; }smp_param_own_t; extern smp_param_own_t smp_param_own; int blc_smp_setTK (u32 pinCodeInput) { memset(smp_param_own.paring_tk, 0, 16); if(pinCodeInput <= 999999){ //0~999999 memcpy(smp_param_own.paring_tk, &pinCodeInput, 4); return 1; } return 0; }
int app_host_event_callback (u32 h, u8 *para, int n) { u8 event = h & 0xFF; switch(event) { case GAP_EVT_SMP_TK_DISPALY: { u32 pinCode = 123456; blc_smp_setTK(pinCode); } break; default: break; } return 0; }
你好,你可以按照如下方法设置静态密钥。
user_init里加这两句:
blc_gap_registerHostEventHandler( app_host_event_callback );
blc_gap_setEventMask( GAP_EVT_MASK_SMP_TK_DISPALY );
在app.c的user_init 前加这些代码:
typedef union {
struct{
u8 bondingFlag : 2;
u8 MITM : 1;
u8 SC : 1;
u8 keyPress: 1;
u8 rsvd: 3;
};
u8 authType;
}smp_authReq_t;
typedef union{
struct {
u8 encKey : 1;
u8 idKey : 1;
u8 sign : 1;
u8 linkKey : 4;
};
u8 keyIni;
}smp_keyDistribution_t;
typedef struct{
u8 code; //req = 0x01; rsp = 0x02;
u8 ioCapablity;
u8 oobDataFlag;
smp_authReq_t authReq;
u8 maxEncrySize;
smp_keyDistribution_t initKeyDistribution;
smp_keyDistribution_t rspKeyDistribution;
}smp_paring_req_rsp_t;
typedef struct{
u8 paring_tk[16]; // in security connection to keep own random
u8 own_ltk[16]; //used for generate ediv and random
smp_paring_req_rsp_t paring_req;
smp_paring_req_rsp_t paring_rsp;
smp_authReq_t auth_req;
u8 own_conn_type; //current connection peer own type
u16 rsvd;
u8 own_conn_addr[6];
u8 local_irk[16];
}smp_param_own_t;
extern smp_param_own_t smp_param_own;
int blc_smp_setTK (u32 pinCodeInput)
{
memset(smp_param_own.paring_tk, 0, 16);
if(pinCodeInput <= 999999){ //0~999999
memcpy(smp_param_own.paring_tk, &pinCodeInput, 4);
return 1;
}
return 0;
}
int app_host_event_callback (u32 h, u8 *para, int n)
{
u8 event = h & 0xFF;
switch(event)
{
case GAP_EVT_SMP_TK_DISPALY:
{
u32 pinCode = 123456;
blc_smp_setTK(pinCode);
}
break;
default:
break;
}
return 0;
}