TI BLE5-Stack API Documentation  1.00.01.04
linkdb.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 
21 #ifndef LINKDB_H
22 #define LINKDB_H
23 
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
29 /*********************************************************************
30  * INCLUDES
31  */
32 
33 /*********************************************************************
34  * MACROS
35  */
36 
37 /*********************************************************************
38  * CONSTANTS
39  */
40 
44 // Special case connection handles
45 #define INVALID_CONNHANDLE 0xFFFF
46 #define LOOPBACK_CONNHANDLE 0xFFFE
47 
48 
51 // Link state flags
52 #define LINK_NOT_CONNECTED 0x00
53 #define LINK_CONNECTED 0x01
54 #define LINK_AUTHENTICATED 0x02
55 #define LINK_BOUND 0x04
56 #define LINK_ENCRYPTED 0x10
57 #define LINK_SECURE_CONNECTIONS 0x20
58 #define LINK_IN_UPDATE 0x40
59 #define LINK_PAIR_TIMEOUT 0x80
60 
62 // Link Database Status callback changeTypes
63 #define LINKDB_STATUS_UPDATE_NEW 0
64 #define LINKDB_STATUS_UPDATE_REMOVED 1
65 #define LINKDB_STATUS_UPDATE_STATEFLAGS 2
66 
67 // Link Authentication Errors
68 #define LINKDB_ERR_INSUFFICIENT_AUTHEN 0x05
69 #define LINBDB_ERR_INSUFFICIENT_KEYSIZE 0x0c
70 #define LINKDB_ERR_INSUFFICIENT_ENCRYPTION 0x0f
71 
73 // Secure Connection Only Mode Encryption Key Size
74 #define SCOM_ENCRYPT_KEY_SIZE 16
75 
76 /*********************************************************************
77  * TYPEDEFS
78  */
79 
86 typedef struct
87 {
88  uint8 srk[KEYLEN];
89  uint32 signCounter;
90 } linkSec_t;
91 
95 typedef struct
96 {
97  uint8 ltk[KEYLEN];
98  uint16 div;
99  uint8 rand[B_RANDOM_NUM_SIZE];
100  uint8 keySize;
101 } encParams_t;
102 
106 typedef struct
107 {
108  uint8 taskID;
110  uint8 stateFlags;
111  uint8 addrType;
112  uint8 addr[B_ADDR_LEN];
113  uint8 addrPriv[B_ADDR_LEN];
114  uint8 connRole;
115  uint16 connInterval;
116  uint16 MTU;
119 } linkDBItem_t;
120 
124 typedef struct
125 {
126  uint8 stateFlags;
127  uint8 addrType;
128  uint8 addr[B_ADDR_LEN];
129  uint8 addrPriv[B_ADDR_LEN];
130  uint8 connRole;
131  uint16 connInterval;
132  uint16 MTU;
133 } linkDBInfo_t;
139 typedef void (*pfnLinkDBCB_t)( uint16 connectionHandle, uint8 changeType );
141 
143 typedef void (*pfnPerformFuncCB_t)( linkDBItem_t *pLinkItem );
146 /*********************************************************************
147  * GLOBAL VARIABLES
148  */
149 
151 
152 extern uint8 linkDBNumConns;
153 
155 
156 /*********************************************************************
157  * PUBLIC FUNCTIONS
158  */
159 
163  extern void linkDB_Init( void );
164  extern uint8 linkDB_Register( pfnLinkDBCB_t pFunc );
178 
198  extern uint8 linkDB_Add( uint8 taskID, uint16 connectionHandle,
199  uint8 stateFlags, uint8 addrType, uint8 *pAddr,
200  uint8 *pAddrPriv, uint8 connRole, uint16 connInterval,
201  uint16 MTU );
202 
212  extern uint8 linkDB_Remove( uint16 connectionHandle );
213 
226  extern uint8 linkDB_Update( uint16 connectionHandle, uint8 newState,
227  uint8 add );
228 
229 
236  extern uint8 linkDB_NumActive( void );
237 
244  extern uint8 linkDB_NumConns( void );
245 
255  extern uint8 linkDB_UpdateMTU( uint16 connectionHandle, uint16 newMtu );
256 
264  extern uint16 linkDB_MTU( uint16 connectionHandle );
265 
277  extern uint8 linkDB_GetInfo( uint16 connectionHandle, linkDBInfo_t * pInfo );
278 
290  extern linkDBItem_t *linkDB_Find( uint16 connectionHandle );
291 
300  extern linkDBItem_t *linkDB_FindFirst( uint8 taskID );
301 
311  extern uint8 linkDB_State( uint16 connectionHandle, uint8 state );
312 
326  extern uint8 linkDB_Authen( uint16 connectionHandle, uint8 keySize,
327  uint8 mitmRequired );
328 
337  extern uint8 linkDB_Role( uint16 connectionHandle );
338 
344  extern void linkDB_PerformFunc( pfnPerformFuncCB_t cb );
345 
352  extern void linkDB_SecurityModeSCOnly( uint8 state );
353 
354 /*********************************************************************
355  * LINK STATE MACROS
356  * Developer note: Call from Application only. Do not call from Stack,
357  * not supported for ROM patching!
358  */
359 
368  #define linkDB_Up( connectionHandle ) linkDB_State( (connectionHandle), LINK_CONNECTED )
369 
378  #define linkDB_Encrypted( connectionHandle ) linkDB_State( (connectionHandle), LINK_ENCRYPTED )
379 
388  #define linkDB_Authenticated( connectionHandle ) linkDB_State( (connectionHandle), LINK_AUTHENTICATED )
389 
398  #define linkDB_Bonded( connectionHandle ) linkDB_State( (connectionHandle), LINK_BOUND )
399 
400 /*********************************************************************
401 *********************************************************************/
402 
403 #ifdef __cplusplus
404 }
405 #endif
406 
407 #endif /* LINKDB_H */
408 
#define B_RANDOM_NUM_SIZE
BLE Random Number Size.
Definition: bcomdef.h:130
Encryption Params.
Definition: linkdb.h:95
#define B_ADDR_LEN
Default Public and Random Address Length.
Definition: bcomdef.h:112
uint16 div
Diversifier.
Definition: linkdb.h:98
#define KEYLEN
Default key length.
Definition: bcomdef.h:115
uint8 keySize
LTK Key Size.
Definition: linkdb.h:100
Copyright 2017, Texas Instruments Incorporated