Topic

FAQ
Login Register
BLE Single Connection SDK - pairing PINCODE
Dec 18, 2023 04:39

/

A

/A

After a long while I had to go back from ZigBee to BLE SDK and found some issues that haven t changed for a couple of years.

How to set default pincode for pairing in BLE Single Connection SDK?

In (very) old version of the SDK I could use the following:
if (event == GAP_EVT_SMP_TK_DISPALY) { // PK_Resp_Dsply_Init_Input
uint32_t * p = (uint32_t *)&smp_param_own.paring_tk[0];
memset(p, 0, sizeof(smp_param_own.paring_tk));
p[0] = pinCode;
}

Note this method can still be used in BLE ZigBee concurrent SDK!

In BLE Multiconnection SDK I can use function:
blc_smp_setDefaultPinCode(PIN_CODE);


Why are Single and Multiconnection SDKs different? Wouldn t it make more sense to have the same functions?



5 replies
TL_Soyo Dec 18, 2023 14:14
0
/A

Hi, 

  It is same need you input pincode in GAP_EVT_SMP_TK_DISPALY event,please search GAP_EVT_SMP_TK_DISPALY in BLE handbook.

wes58 [Author] Dec 19, 2023 04:31
0
/A

Hi Soyo,

No, it is not the same. The code doesn't compile because in smp.h there is no structure smp_param_own_t defined!


I remembered that I raised this issue in 2021. I looked through my posts and I found this.

Response from WeiSun:

For security, the definition of smp_param_own has been packaged into precompiled libraries in the latest SDK (v3.4.2.0).
You can use the function 'blc_smp_setTK_by_PasskeyEntry (u32 pinCodeInput)' in smp.h to set your own pin.


My response:
I found out that this function can only be used in GAP_EVT_SMP_TK_REQUEST_PASSKEY
It didn't work in GAP_EVT_SMP_TK_DISPALY, you could only use smp_param_own.paring_tk in old Single Connection SDK


And then WeiSun:
Yes, you are right. The function blc_smp_setTK_by_PasskeyEntry() can only be used in GAP_EVT_SMP_TK_REQUEST_PASSKEY, It didn't work in GAP_EVT_SMP_TK_DISPALY.
If you want to use smp_param_own.paring_tk in lastest Single Connection SDK, you can set it as extern variable to access and redeclare the associated struct.
In the future, the BLE team will consider improving these Settings.


Obviously, 2 years later BLE team didn't do it!

- ZigBee BLE concurrent SDK have it

- BLE multiconnection SDK has function blc_smp_setDefaultPinCode(PIN_CODE);

- BLE singleconnection SDK has nothing unless you add it to smp.h as advised by WeiSun in 2021.

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; r

sp = 0x02;

u8 ioCapablity;

u8 oobDataFlag;

smp_authReq_t authReq;

u8 maxEncrySize;

smp_keyDistribution_t initKeyDistribution;

smp_keyDistribution_t rspKeyDistribution;

}smp_paring_req_rsp_t;


/* * smp parameter about own device. * */

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 _attribute_aligned_(4) smp_param_own_t smp_param_own;


The code compiles but I haven't checked it yet if it works.



TL_Soyo Dec 20, 2023 09:43
0
/A

Hi,

  The default pin code you can set in GAP_EVT_SMP_TK_DISPALY.

  please refer to http://wiki.telink-semi.cn/doc/an/AN-21112300-E_Telink%20B85m%20BLE%20Single%20Connection%20SDK%20Developer%20Handbook.pdf page 172.

wes58 [Author] Dec 20, 2023 12:37
0
/A

Hi Soyo,

I read the Handbook 2 years ago and read it again now.

On Page 172 there is a code:

The user can also manually set a user-specified pincode code such as “123456” without using the 6-digit pincode code generated by underlying layer randomly.

case GAP_EVT_SMP_TK_DISPALY:

{

char pc[7];

#if 1 //Set pincode manually

u32 pinCode = 123456;

memset(smp_param_own.paring_tk, 0, 16);

memcpy(smp_param_own.paring_tk, &pinCode, 4);

#else//Using the pincode generated by bottom layer randomly

u32 pinCode = *(u32*)para;

#endif

}

break;

As I wrote before this code work in the very old SDK but now now.

Here is the result of compilation:

../vendor/b85m_ble_sample/app.c:356:22: error: smp_param_own undeclared (first use in this function)


The code is using smp_param_own which has been removed from smp.h. Read WeiSun response in the second post.

So the user can not manually set a user-specified pincode code such as “123456” without using the 6-digit
pincode code generated by underlying layer randomly - as it says on page 172.

As I wrote above - Zigbee BLE concurrent SDK still has smp_param_own in smp.h, but BLE multiconnection SDK has a function blc_smp_setDefaultPinCode(PIN_CODE); to set default pincode.

So why singleconnection SDK is not the same?

As I said in the previous post, When I add the structure definition in smp.h from the old sdk, the code compiles. I have just tested it and it works.


So this code should be in the smp.h in the SDK!





TL_Soyo Dec 20, 2023 13:54
0
/A

I confirmed with WeiSun that the major version update in the next month will fix this issue, and the SDK has not had a major update in the past two years, so it has not been fixed yet.