TI BLE5-Stack API Documentation  1.01.12.00
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  */
49 #define DISPLAY_ONLY 0x00
50 #define DISPLAY_YES_NO 0x01
51 #define KEYBOARD_ONLY 0x02
52 #define NO_INPUT_NO_OUTPUT 0x03
53 #define KEYBOARD_DISPLAY 0x04
54 
56 #define SM_AUTH_MITM_MASK(a) (((a) & 0x04) >> 2)
57 
58 
62 #define SM_PASSKEY_TYPE_INPUT 0x01
63 #define SM_PASSKEY_TYPE_DISPLAY 0x02
64 
71 #define SM_AUTH_REQ_NO_BONDING 0x00
72 #define SM_AUTH_REQ_BONDING 0x01
73 
75 #define PASSKEY_LEN 6
76 
77 #define SM_AUTH_STATE_AUTHENTICATED 0x04
78 #define SM_AUTH_STATE_BONDING 0x01
79 #define SM_AUTH_STATE_SECURECONNECTION 0x08
80 
81 #define SM_ECC_KEY_LEN 32
82 
83 /* SM private/public key regeneration policy */
84 #define SM_ECC_KEYS_NOT_AVAILABLE 0xFF
85 #define SM_ECC_KEYS_REGNENERATE_NEVER 0xFF
86 #define SM_ECC_KEYS_REGENERATE_ALWAYS 0x00
87 
88 
92 #define SM_ECC_KEYS_EVENT 0x00
93 #define SM_DH_KEY_EVENT 0x01
94  // end of GAPBondMgr_Constants
97 
98 /*-------------------------------------------------------------------
99  * General TYPEDEFS
100  */
101 
106 typedef struct
107 {
109  uint8 newKey[KEYLEN];
111 
115 typedef struct
116 {
118  uint8 opcode;
119 } smEventHdr_t;
120 
125 typedef struct
126 {
128  uint8 opcode;
129  uint8 privateKey[SM_ECC_KEY_LEN];
130  uint8 publicKeyX[SM_ECC_KEY_LEN];
131  uint8 publicKeyY[SM_ECC_KEY_LEN];
133 
138 typedef struct
139 {
141  uint8 opcode;
142  uint8 dhKey[SM_ECC_KEY_LEN];
143 } smDhKeyEvt_t;
144 
148 typedef struct
149 {
150  unsigned int sEncKey:1;
151  unsigned int sIdKey:1;
152  unsigned int sSign:1;
153  unsigned int sLinkKey:1;
154  unsigned int sReserved:4;
155  unsigned int mEncKey:1;
156  unsigned int mIdKey:1;
157  unsigned int mSign:1;
158  unsigned int mLinkKey:1;
159  unsigned int mReserved:4;
160 } keyDist_t;
161 
165 typedef struct
166 {
167  uint8 isUsed;
168  uint8 sK[SM_ECC_KEY_LEN];
169  uint8 pK_x[SM_ECC_KEY_LEN];
170  uint8 pK_y[SM_ECC_KEY_LEN];
171 } smEccKeys_t;
172 
176 typedef struct
177 {
178  uint8 ioCaps;
179  uint8 oobAvailable;
180  uint8 oob[KEYLEN];
181  uint8 oobConfirm[KEYLEN];
183  uint8 localOob[KEYLEN];
184  uint8 isSCOnlyMode;
186  uint8 authReq;
190 
194 typedef struct
195 {
196  uint8 ltk[KEYLEN];
197  uint16 div;
198  uint8 rand[B_RANDOM_NUM_SIZE];
199  uint8 keySize;
201 
205 typedef struct
206 {
207  uint8 irk[KEYLEN];
208  uint8 addrType;
209  uint8 bd_addr[B_ADDR_LEN];
211 
215 typedef struct
216 {
217  uint8 srk[KEYLEN];
218  uint32 signCounter;
220 
224 typedef struct
225 {
226  unsigned int bonding:2;
227  unsigned int mitm:1;
228  unsigned int sc:1;
229  unsigned int kp:1;
230  unsigned int ct2:1;
231  unsigned int reserved:2;
232 } authReq_t;
233 
237 typedef void (*smCB_t)
238 (
239 uint8 *secretKey,
240 uint8 *publicKeyX,
241 uint8 *publicKeyY
242 );
243 
244 /*-------------------------------------------------------------------
245  * GLOBAL VARIABLES
246  */
247 
248 /*-------------------------------------------------------------------
249  * FUNCTIONS - APPLICATION API - Functions the application may call
250  */
251 
258 extern void SM_RegisterTask( uint8 taskID );
259 
268 extern bStatus_t SM_GetEccKeys( void );
269 
283 extern bStatus_t SM_GetDHKey( uint8 *secretKey, uint8 *publicKeyX,
284  uint8 *publicKeyY );
285 
299 extern bStatus_t SM_GetScConfirmOob( uint8 *publicKey, uint8 *oob, uint8 *pOut );
300 
301 /*-------------------------------------------------------------------
302  * FUNCTIONS - MASTER API - Only use these in a master device
303  */
304 
312 extern bStatus_t SM_InitiatorInit( void );
313 
332 extern bStatus_t SM_StartPairing( uint8 initiator,
333  uint8 taskID,
334  uint16 connectionHandle,
335  smLinkSecurityReq_t *pSecReqs );
336 
351 extern bStatus_t SM_StartEncryption( uint16 connHandle, uint8 *pLTK,
352  uint16 div, uint8 *pRandNum,
353  uint8 keyLen );
354 
355 
356 /*-------------------------------------------------------------------
357  * FUNCTIONS - SLAVE API - Only use these in a slave device
358  */
359 
367 extern bStatus_t SM_ResponderInit( void );
368 
369 /*-------------------------------------------------------------------
370  * FUNCTIONS - GENERAL API - both master and slave
371  */
372 
383 extern bStatus_t SM_NewRandKey( uint8 taskID );
384 
397 extern bStatus_t SM_Encrypt( uint8 *pKey, uint8 *pPlainText, uint8 *pResult );
398 
411 extern bStatus_t SM_GenerateAuthenSig( uint8 *pData, uint16 len,
412  uint8 *pAuthenSig, uint16 connHandle );
413 
429 extern bStatus_t SM_VerifyAuthenSig( uint16 connHandle,
430  uint8 authentication,
431  uint8 *pData,
432  uint16 len,
433  uint8 *pAuthenSig );
434 
445 extern bStatus_t SM_PasskeyUpdate( uint8 *pPasskey, uint16 connectionHandle );
446 
447 
453 extern void SM_SetECCRegenerationCount(uint8 count);
454 
456 
457 /*-------------------------------------------------------------------
458  * TASK API - These functions must only be called by OSAL.
459  */
460 
468  extern void SM_Init( uint8 task_id );
469 
480  extern uint16 SM_ProcessEvent( uint8 task_id, uint16 events );
481 
494  extern void SM_p256KeyCB( hciEvt_BLEReadP256PublicKeyComplete_t *pK,
495  uint8 *privateKey );
496 
509  extern void SM_dhKeyCB( hciEvt_BLEGenDHKeyComplete_t *pDhKey );
510 
512 
513 /*-------------------------------------------------------------------
514 -------------------------------------------------------------------*/
515 
516 #ifdef __cplusplus
517 }
518 #endif
519 
520 #endif /* SM_H */
uint8 opcode
SM_DH_KEY_EVENT.
Definition: sm.h:141
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...
Definition: sm.h:165
void SM_RegisterTask(uint8 taskID)
Register Task with the Security Manager to receive ECC keys or a ECDH shared secret.
Definition: sm.h:194
#define B_RANDOM_NUM_SIZE
BLE Random Number Size.
Definition: bcomdef.h:140
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:125
Definition: sm.h:115
uint8 addrType
Address type for BD_ADDR.
Definition: sm.h:208
bStatus_t SM_GenerateAuthenSig(uint8 *pData, uint16 len, uint8 *pAuthenSig, uint16 connHandle)
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:81
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:106
Definition: sm.h:148
uint8 keySize
LTK Key Size (7-16 bytes)
Definition: sm.h:199
Definition: sm.h:205
osal_event_hdr_t hdr
SM_MSG_EVENT and status.
Definition: sm.h:127
LE Generate DHKey Complete Event.
Definition: hci.h:1077
uint8 opcode
op code
Definition: sm.h:118
uint8 isUsed
FALSE if not used. USE_PKEYS if public keys only. USE_ALL_KEYS if public and private keys...
Definition: sm.h:167
Type definitions and macros for BLE stack.
uint8 opcode
SM_ECC_KEYS_EVENT.
Definition: sm.h:128
Definition: sm.h:215
uint32_t len
Image length in bytes.
Definition: oad_image_header.h:529
OSAL Event Header.
Definition: osal.h:92
uint16 div
LTK Diversifier.
Definition: sm.h:197
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:138
void(* smCB_t)(uint8 *secretKey, uint8 *publicKeyX, uint8 *publicKeyY)
Definition: sm.h:238
osal_event_hdr_t hdr
SM_MSG_EVENT and status.
Definition: sm.h:140
#define B_ADDR_LEN
Default Public and Random Address Length.
Definition: bcomdef.h:115
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:249
osal_event_hdr_t hdr
osal event header
Definition: sm.h:117
uint32 signCounter
Sign Counter.
Definition: sm.h:218
LE Read P256 Public Key Complete Event.
Definition: hci.h:1068
Definition: sm.h:224
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:118
osal_event_hdr_t hdr
SM_NEW_RAND_KEY_EVENT and status.
Definition: sm.h:108
bStatus_t SM_Encrypt(uint8 *pKey, uint8 *pPlainText, uint8 *pResult)
Encrypt the plain text data with the key..
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale