TI BLE Stack API Documentation  2.03.07
linkdb.h
1 /******************************************************************************
2 
3  @file linkdb.h
4 
5  @brief This file contains the linkDB interface.
6 
7  Group: WCS, BTS
8  $Target Device: DEVICES $
9 
10  ******************************************************************************
11  $License: TISD 2009 $
12  ******************************************************************************
13  $Release Name: PACKAGE NAME $
14  $Release Date: PACKAGE RELEASE DATE $
15  *****************************************************************************/
16 
17 #ifndef LINKDB_H
18 #define LINKDB_H
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 /*********************************************************************
26  * INCLUDES
27  */
28 
29 /*********************************************************************
30  * MACROS
31  */
32 
33 /*********************************************************************
34  * CONSTANTS
35  */
36 
37 // Special case connection handles
38 #define INVALID_CONNHANDLE 0xFFFF // Invalid connection handle, used for no connection handle
39 #define LOOPBACK_CONNHANDLE 0xFFFE // Loopback connection handle, used to loopback a message
40 
41 // Link state flags
42 #define LINK_NOT_CONNECTED 0x00 // Link isn't connected
43 #define LINK_CONNECTED 0x01 // Link is connected
44 #define LINK_AUTHENTICATED 0x02 // Link is authenticated
45 #define LINK_BOUND 0x04 // Link is bonded
46 #define LINK_ENCRYPTED 0x10 // Link is encrypted
47 #define LINK_SECURE_CONNECTIONS 0x20 // Link uses Secure Connections
48 #define LINK_IN_UPDATE 0x40 // Link is in update procedure
49 
50 // Link Database Status callback changeTypes
51 #define LINKDB_STATUS_UPDATE_NEW 0 // New connection created
52 #define LINKDB_STATUS_UPDATE_REMOVED 1 // Connection was removed
53 #define LINKDB_STATUS_UPDATE_STATEFLAGS 2 // Connection state flag changed
54 
55 // Link Authentication Errors
56 #define LINKDB_ERR_INSUFFICIENT_AUTHEN 0x05 // Link isn't even encrypted
57 #define LINBDB_ERR_INSUFFICIENT_KEYSIZE 0x0c // Link is encrypted but the key size is too small
58 #define LINKDB_ERR_INSUFFICIENT_ENCRYPTION 0x0f // Link is encrypted but it's not authenticated
59 
60 /*********************************************************************
61  * TYPEDEFS
62  */
63 
64 typedef struct
65 {
66  uint8 srk[KEYLEN]; // Signature Resolving Key
67  uint32 signCounter; // Sign Counter
68 } linkSec_t;
69 
70 typedef struct
71 {
72  uint8 ltk[KEYLEN]; // Long Term Key
73  uint16 div; // Diversifier
74  uint8 rand[B_RANDOM_NUM_SIZE]; // random number
75  uint8 keySize; // LTK Key Size
76 } encParams_t;
77 
78 typedef struct
79 {
80  uint8 taskID; // Application that controls the link
81  uint16 connectionHandle; // Controller connection handle
82  uint8 stateFlags; // LINK_CONNECTED, LINK_AUTHENTICATED...
83  uint8 addrType; // Address type of connected device
84  uint8 addr[B_ADDR_LEN]; // Other Device's address
85  uint8 addrPriv[B_ADDR_LEN]; // Other Device's Private address
86  uint8 connRole; // Connection formed as Master or Slave
87  uint16 connInterval; // The connection's interval (n * 1.23 ms)
88  uint16 MTU; // The connection's MTU size
89  linkSec_t sec; // Connection Security related items
90  encParams_t *pEncParams; // pointer to LTK, ediv, rand. if needed.
91 } linkDBItem_t;
92 
93 typedef struct
94 {
95  uint8 stateFlags; // LINK_CONNECTED, LINK_AUTHENTICATED...
96  uint8 addrType; // Address type of connected device
97  uint8 addr[B_ADDR_LEN]; // Other Device's address
98  uint8 addrPriv[B_ADDR_LEN]; // Other Device's Private address
99  uint8 connRole; // Connection formed as Master or Slave
100  uint16 connInterval; // The connection's interval (n * 1.23 ms)
101  uint16 MTU; // The connection's MTU size
102 } linkDBInfo_t;
103 
104 // function pointer used to register for a status callback
105 typedef void (*pfnLinkDBCB_t)( uint16 connectionHandle, uint8 changeType );
106 
107 // function pointer used to perform specialized link database searches
108 typedef void (*pfnPerformFuncCB_t)( linkDBItem_t *pLinkItem );
109 
110 /*********************************************************************
111  * GLOBAL VARIABLES
112  */
113 
114 extern uint8 linkDBNumConns;
115 
116 /*********************************************************************
117  * PUBLIC FUNCTIONS
118  */
119  /*
120  * linkDB_Init - Initialize the Link Database.
121  */
122  extern void linkDB_Init( void );
123 
124  /*
125  * linkDB_Register - Register with this function to receive a callback when
126  * status changes on a connection.
127  */
128  extern uint8 linkDB_Register( pfnLinkDBCB_t pFunc );
129 
130  /*
131  * linkDB_Add - Adds a record to the link database.
132  */
133  extern uint8 linkDB_Add( uint8 taskID, uint16 connectionHandle,
134  uint8 stateFlags, uint8 addrType, uint8 *pAddr,
135  uint8 *pAddrPriv, uint8 connRole, uint16 connInterval,
136  uint16 MTU );
137 
138  /*
139  * linkDB_Remove - Removes a record from the link database.
140  */
141  extern uint8 linkDB_Remove( uint16 connectionHandle );
142 
143  /*
144  * linkDB_Update - This function is used to update the stateFlags of
145  * a link record.
146  */
147  extern uint8 linkDB_Update( uint16 connectionHandle, uint8 newState,
148  uint8 add );
149 
150  /*
151  * linkDB_NumActive - returns the number of active connections.
152  */
153  extern uint8 linkDB_NumActive( void );
154 
155  /*
156  * linkDB_NumConns - returns the maximum number of connections supported.
157  */
158  extern uint8 linkDB_NumConns( void );
159 
160  /*
161  * linkDB_UpdateMTU - This function is used to update the MTU size of
162  * a link record.
163  */
164  extern uint8 linkDB_UpdateMTU( uint16 connectionHandle, uint16 newMtu );
165 
166  /*
167  * linkDB_MTU - This function is used to get the MTU size of
168  * a link.
169  */
170  extern uint16 linkDB_MTU( uint16 connectionHandle );
171 
172  /*
173  * linkDB_GetInfo - Copies link information for the given connection handle
174  *
175  */
176  extern uint8 linkDB_GetInfo( uint16 connectionHandle, linkDBInfo_t * pInfo );
177 
178  /*
179  * linkDB_Find - Find link database item (link information)
180  *
181  * returns a pointer to the link item, NULL if not found
182  */
183  extern linkDBItem_t *linkDB_Find( uint16 connectionHandle );
184 
185  /*
186  * linkDB_FindFirst - Find the first link that matches the taskID.
187  *
188  * returns a pointer to the link item, NULL if not found
189  */
190  extern linkDBItem_t *linkDB_FindFirst( uint8 taskID );
191 
192  /*
193  * linkDB_State - Check to see if a physical link is in a specific state.
194  *
195  * returns TRUE is the link is in state. FALSE, otherwise.
196  */
197  extern uint8 linkDB_State( uint16 connectionHandle, uint8 state );
198 
199  /*
200  * linkDB_Authen - Check to see if the physical link is encrypted and authenticated.
201  * returns SUCCESS if the link is authenticated or
202  * bleNotConnected - connection handle is invalid,
203  * LINKDB_ERR_INSUFFICIENT_AUTHEN - link is not encrypted,
204  * LINBDB_ERR_INSUFFICIENT_KEYSIZE - key size encrypted is not large enough,
205  * LINKDB_ERR_INSUFFICIENT_ENCRYPTION - link is encrypted, but not authenticated
206  */
207  extern uint8 linkDB_Authen( uint16 connectionHandle, uint8 keySize,
208  uint8 mitmRequired );
209 
210  /*
211  * linkDB_Role - Get the role of a physical link.
212  *
213  * returns GAP_PROFILE_CENTRAL, GAP_PROFILE_PERIPHERAL or 0 (unknown).
214  */
215  extern uint8 linkDB_Role( uint16 connectionHandle );
216 
217  /*
218  * linkDB_PerformFunc - Perform a function of each connection in the link database.
219  */
220  extern void linkDB_PerformFunc( pfnPerformFuncCB_t cb );
221 
222  /*
223  * linkDB_SecurityModeSCOnly - Set a device into Secure Connection Only Mode.
224  * state is set to TRUE for Secure Connections Only Mode.
225  * state is set to FALSE to disable Secure Connections Only Mode.
226  */
227  extern void linkDB_SecurityModeSCOnly( uint8 state );
228 
229 /*********************************************************************
230  * LINK STATE MACROS
231  * Developer note: Call from Application only. Do not call from Stack,
232  * not supported for ROM patching!
233  */
234 
235  /*
236  * linkDB_Up - Check to see if a physical link is up (connected).
237  * Use like: uint8 linkDB_Up( uint16 connectionHandle );
238  * connectionHandle - controller link connection handle.
239  * returns TRUE if the link is up. FALSE, otherwise.
240  */
241  #define linkDB_Up( connectionHandle ) linkDB_State( (connectionHandle), LINK_CONNECTED )
242 
243  /*
244  * linkDB_Encrypted - Check to see if the physical link is encrypted.
245  * Use like: linkDB_Encrypted( uint16 connectionHandle );
246  * connectionHandle - controller link connection handle.
247  * returns TRUE if the link is encrypted. FALSE, otherwise.
248  */
249  #define linkDB_Encrypted( connectionHandle ) linkDB_State( (connectionHandle), LINK_ENCRYPTED )
250 
251  /*
252  * linkDB_Authenticated - Check to see if the physical link is authenticated.
253  * Use like: linkDB_Authenticated( uint16 connectionHandle );
254  * connectionHandle - controller link connection handle.
255  * returns TRUE if the link is authenticated. FALSE, otherwise.
256  */
257  #define linkDB_Authenticated( connectionHandle ) linkDB_State( (connectionHandle), LINK_AUTHENTICATED )
258 
259  /*
260  * linkDB_Bonded - Check to see if the physical link is bonded.
261  * Use like: linkDB_Bonded( uint16 connectionHandle );
262  * connectionHandle - controller link connection handle.
263  * returns TRUE if the link is bonded. FALSE, otherwise.
264  */
265  #define linkDB_Bonded( connectionHandle ) linkDB_State( (connectionHandle), LINK_BOUND )
266 
267 /*********************************************************************
268 *********************************************************************/
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 
274 #endif /* LINKDB_H */
Definition: linkdb.h:93
#define B_ADDR_LEN
Default Public and Random Address Length.
Definition: bcomdef.h:114
Definition: linkdb.h:64
#define KEYLEN
Default key length.
Definition: bcomdef.h:117
Definition: linkdb.h:70
Definition: linkdb.h:78
#define B_RANDOM_NUM_SIZE
BLE Random Number Size.
Definition: bcomdef.h:132