TI BLE-Stack for Bluetooth 4.2 API Documentation  3.01.00.07
sm.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Group: WCS, BTS
4  $Target Device: DEVICES $
5 
6  ******************************************************************************
7  $License: TISD 2009 $
8  ******************************************************************************
9  $Release Name: PACKAGE NAME $
10  $Release Date: PACKAGE RELEASE DATE $
11  *****************************************************************************/
12 
18 #ifndef SM_H
19 #define SM_H
20 
21 #ifdef __cplusplus
22 extern "C"
23 {
24 #endif
25 
26 /*-------------------------------------------------------------------
27  * INCLUDES
28  */
29 #include "bcomdef.h"
30 #include "osal.h"
31 
32 #include "hci.h"
33 
34 /*-------------------------------------------------------------------
35  * MACROS
36  */
37 
38 /*-------------------------------------------------------------------
39  * CONSTANTS
40  */
48 #define DISPLAY_ONLY 0x00
49 #define DISPLAY_YES_NO 0x01
50 #define KEYBOARD_ONLY 0x02
51 #define NO_INPUT_NO_OUTPUT 0x03
52 #define KEYBOARD_DISPLAY 0x04
53 
55 #define SM_AUTH_MITM_MASK(a) (((a) & 0x04) >> 2)
56 
57 
60 #define SM_PASSKEY_TYPE_INPUT 0x01
61 #define SM_PASSKEY_TYPE_DISPLAY 0x02
62 
68 #define SM_AUTH_REQ_NO_BONDING 0x00
69 #define SM_AUTH_REQ_BONDING 0x01
70 
72 #define PASSKEY_LEN 6
73 
74 #define SM_AUTH_STATE_AUTHENTICATED 0x04
75 #define SM_AUTH_STATE_BONDING 0x01
76 #define SM_AUTH_STATE_SECURECONNECTION 0x08
77 
78 #define SM_ECC_KEY_LEN 32
79 
80 /* SM private/public key regeneration policy */
81 #define SM_ECC_KEYS_NOT_AVAILABLE 0xFF
82 #define SM_ECC_KEYS_REGNENERATE_NEVER 0xFF
83 #define SM_ECC_KEYS_REGENERATE_ALWAYS 0x00
84 
85 
88 #define SM_ECC_KEYS_EVENT 0x00
89 #define SM_DH_KEY_EVENT 0x01
90  // end of GAPBondMgr_Constants
93 
94 /*-------------------------------------------------------------------
95  * General TYPEDEFS
96  */
97 
102 typedef struct
103 {
105  uint8 newKey[KEYLEN];
107 
111 typedef struct
112 {
114  uint8 opcode;
115 } smEventHdr_t;
116 
121 typedef struct
122 {
124  uint8 opcode;
125  uint8 privateKey[SM_ECC_KEY_LEN];
126  uint8 publicKeyX[SM_ECC_KEY_LEN];
127  uint8 publicKeyY[SM_ECC_KEY_LEN];
129 
134 typedef struct
135 {
137  uint8 opcode;
138  uint8 dhKey[SM_ECC_KEY_LEN];
139 } smDhKeyEvt_t;
140 
144 typedef struct
145 {
146  unsigned int sEncKey:1;
147  unsigned int sIdKey:1;
148  unsigned int sSign:1;
149  unsigned int sLinkKey:1;
150  unsigned int sReserved:4;
151  unsigned int mEncKey:1;
152  unsigned int mIdKey:1;
153  unsigned int mSign:1;
154  unsigned int mLinkKey:1;
155  unsigned int mReserved:4;
156 } keyDist_t;
157 
161 typedef struct
162 {
163  uint8 isUsed;
164  uint8 sK[SM_ECC_KEY_LEN];
165  uint8 pK_x[SM_ECC_KEY_LEN];
166  uint8 pK_y[SM_ECC_KEY_LEN];
167 } smEccKeys_t;
168 
172 typedef struct
173 {
174  uint8 ioCaps;
175  uint8 oobAvailable;
176  uint8 oob[KEYLEN];
177  uint8 oobConfirm[KEYLEN];
179  uint8 localOob[KEYLEN];
180  uint8 isSCOnlyMode;
182  uint8 authReq;
186 
190 typedef struct
191 {
192  uint8 ltk[KEYLEN];
193  uint16 div;
194  uint8 rand[B_RANDOM_NUM_SIZE];
195  uint8 keySize;
197 
201 typedef struct
202 {
203  uint8 irk[KEYLEN];
204  uint8 addrType;
205  uint8 bd_addr[B_ADDR_LEN];
207 
211 typedef struct
212 {
213  uint8 srk[KEYLEN];
214  uint32 signCounter;
216 
220 typedef struct
221 {
222  unsigned int bonding:2;
223  unsigned int mitm:1;
224  unsigned int sc:1;
225  unsigned int kp:1;
226  unsigned int reserved:3;
227 } authReq_t;
228 
232 typedef void (*smCB_t)
233 (
234 uint8 *secretKey,
235 uint8 *publicKeyX,
236 uint8 *publicKeyY
237 );
238 
239 /*-------------------------------------------------------------------
240  * GLOBAL VARIABLES
241  */
242 
243 /*-------------------------------------------------------------------
244  * FUNCTIONS - APPLICATION API - Functions the application may call
245  */
246 
253 extern void SM_RegisterTask( uint8 taskID );
254 
263 extern bStatus_t SM_GetEccKeys( void );
264 
278 extern bStatus_t SM_GetDHKey( uint8 *secretKey, uint8 *publicKeyX,
279  uint8 *publicKeyY );
280 
294 extern bStatus_t SM_GetScConfirmOob( uint8 *publicKey, uint8 *oob, uint8 *pOut );
295 
296 /*-------------------------------------------------------------------
297  * FUNCTIONS - MASTER API - Only use these in a master device
298  */
299 
307 extern bStatus_t SM_InitiatorInit( void );
308 
327 extern bStatus_t SM_StartPairing( uint8 initiator,
328  uint8 taskID,
329  uint16 connectionHandle,
330  smLinkSecurityReq_t *pSecReqs );
331 
346 extern bStatus_t SM_StartEncryption( uint16 connHandle, uint8 *pLTK,
347  uint16 div, uint8 *pRandNum,
348  uint8 keyLen );
349 
350 
351 /*-------------------------------------------------------------------
352  * FUNCTIONS - SLAVE API - Only use these in a slave device
353  */
354 
362 extern bStatus_t SM_ResponderInit( void );
363 
364 /*-------------------------------------------------------------------
365  * FUNCTIONS - GENERAL API - both master and slave
366  */
367 
378 extern bStatus_t SM_NewRandKey( uint8 taskID );
379 
380 #if !defined (BLE_V42_FEATURES) || !(BLE_V42_FEATURES & PRIVACY_1_2_CFG)
381 
390 extern bStatus_t SM_CalcRandomAddr( uint8 *pIRK, uint8 *pNewAddr );
391 
402 extern bStatus_t SM_ResolveRandomAddrs( uint8 *pIRK, uint8 *pAddr );
403 #endif // ! BLE_V42_FEATURES | ! PRIVACY_1_2_CFG
404 
417 extern bStatus_t SM_Encrypt( uint8 *pKey, uint8 *pPlainText, uint8 *pResult );
418 
430 extern bStatus_t SM_GenerateAuthenSig( uint8 *pData, uint16 len,
431  uint8 *pAuthenSig );
432 
448 extern bStatus_t SM_VerifyAuthenSig( uint16 connHandle,
449  uint8 authentication,
450  uint8 *pData,
451  uint16 len,
452  uint8 *pAuthenSig );
453 
464 extern bStatus_t SM_PasskeyUpdate( uint8 *pPasskey, uint16 connectionHandle );
465 
466 
472 extern void SM_SetECCRegenerationCount(uint8 count);
473 
475 
476 /*-------------------------------------------------------------------
477  * TASK API - These functions must only be called by OSAL.
478  */
479 
487  extern void SM_Init( uint8 task_id );
488 
499  extern uint16 SM_ProcessEvent( uint8 task_id, uint16 events );
500 
513  extern void SM_p256KeyCB( hciEvt_BLEReadP256PublicKeyComplete_t *pK,
514  uint8 *privateKey );
515 
528  extern void SM_dhKeyCB( hciEvt_BLEGenDHKeyComplete_t *pDhKey );
529 
531 
532 /*-------------------------------------------------------------------
533 -------------------------------------------------------------------*/
534 
535 #ifdef __cplusplus
536 }
537 #endif
538 
539 #endif /* SM_H */
uint8 opcode
SM_DH_KEY_EVENT.
Definition: sm.h:137
bStatus_t SM_PasskeyUpdate(uint8 *pPasskey, uint16 connectionHandle)
Update the passkey for the pairing process.
This API allows the software components in the Z-Stack to be written independently of the specifics o...
bStatus_t SM_ResolveRandomAddrs(uint8 *pIRK, uint8 *pAddr)
Resolve a Private Resolvable Address.
Definition: sm.h:161
void SM_RegisterTask(uint8 taskID)
Register Task with the Security Manager to receive ECC keys or a ECDH shared secret.
Definition: sm.h:190
#define B_RANDOM_NUM_SIZE
BLE Random Number Size.
Definition: bcomdef.h:130
bStatus_t SM_StartPairing(uint8 initiator, uint8 taskID, uint16 connectionHandle, smLinkSecurityReq_t *pSecReqs)
Start the pairing process.
bStatus_t SM_GetScConfirmOob(uint8 *publicKey, uint8 *oob, uint8 *pOut)
Generate a confirm value for OOB data.
bStatus_t SM_NewRandKey(uint8 taskID)
Generate a key with a random value.
Definition: sm.h:121
Definition: sm.h:111
uint8 addrType
Address type for BD_ADDR.
Definition: sm.h:204
void SM_SetECCRegenerationCount(uint8 count)
Update the regeneration count for ECC key re-usage.
#define SM_ECC_KEY_LEN
ECC Key length in bytes.
Definition: sm.h:78
bStatus_t SM_ResponderInit(void)
Initialize SM Responder on a slave device.
bStatus_t SM_GetEccKeys(void)
Get ECC private and public keys. Keys are returned through the callback registered in SM_RegisterCb...
Definition: sm.h:102
Definition: sm.h:144
uint8 keySize
LTK Key Size (7-16 bytes)
Definition: sm.h:195
Definition: sm.h:201
osal_event_hdr_t hdr
SM_MSG_EVENT and status.
Definition: sm.h:123
LE Generate DHKey Complete Event.
Definition: hci.h:1150
uint8 opcode
op code
Definition: sm.h:114
uint8 isUsed
FALSE if not used. USE_PKEYS if public keys only. USE_ALL_KEYS if public and private keys...
Definition: sm.h:163
Type definitions and macros for BLE stack.
uint8 opcode
SM_ECC_KEYS_EVENT.
Definition: sm.h:124
Definition: sm.h:211
OSAL Event Header.
Definition: osal.h:92
uint16 div
LTK Diversifier.
Definition: sm.h:193
bStatus_t SM_CalcRandomAddr(uint8 *pIRK, uint8 *pNewAddr)
Calculate a new Private Resolvable address.
HCI layer interface.
bStatus_t SM_GetDHKey(uint8 *secretKey, uint8 *publicKeyX, uint8 *publicKeyY)
Request a Diffie-Hellman key from the ECC engine. Key is returned through the callback registered in ...
Definition: sm.h:134
void(* smCB_t)(uint8 *secretKey, uint8 *publicKeyX, uint8 *publicKeyY)
Definition: sm.h:233
osal_event_hdr_t hdr
SM_MSG_EVENT and status.
Definition: sm.h:136
#define B_ADDR_LEN
Default Public and Random Address Length.
Definition: bcomdef.h:112
bStatus_t SM_StartEncryption(uint16 connHandle, uint8 *pLTK, uint16 div, uint8 *pRandNum, uint8 keyLen)
Send Start Encrypt through HCI.
bStatus_t SM_InitiatorInit(void)
Initialize SM Initiator on a master device.
Status_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:227
osal_event_hdr_t hdr
osal event header
Definition: sm.h:113
bStatus_t SM_GenerateAuthenSig(uint8 *pData, uint16 len, uint8 *pAuthenSig)
Generate an outgoing Authentication Signature.
uint32 signCounter
Sign Counter.
Definition: sm.h:214
LE Read P256 Public Key Complete Event.
Definition: hci.h:1141
Definition: sm.h:220
bStatus_t SM_VerifyAuthenSig(uint16 connHandle, uint8 authentication, uint8 *pData, uint16 len, uint8 *pAuthenSig)
Verify an Authentication Signature.
#define KEYLEN
Default key length.
Definition: bcomdef.h:115
osal_event_hdr_t hdr
SM_NEW_RAND_KEY_EVENT and status.
Definition: sm.h:104
bStatus_t SM_Encrypt(uint8 *pKey, uint8 *pPlainText, uint8 *pResult)
Encrypt the plain text data with the key..
Copyright 2017, Texas Instruments Incorporated