BLE-Stack APIs  3.00.00
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linkdb.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @defgroup LinkDB LinkDB
34  * @brief This module implements the Link Database Module
35  * @{
36  * @file linkdb.h
37  * @brief LinkDB layer interface
38  */
39 
40 #ifndef LINKDB_H
41 #define LINKDB_H
42 
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 /*********************************************************************
49  * INCLUDES
50  */
51 
52 /*********************************************************************
53  * MACROS
54  */
55 
56 /*********************************************************************
57  * CONSTANTS
58  */
59 
63 // Special case connection handles
64 #define INVALID_CONNHANDLE 0xFFFF
65 #define LOOPBACK_CONNHANDLE 0xFFFE
66 
67 
70 // Link state flags
71 #define LINK_NOT_CONNECTED 0x00
72 #define LINK_CONNECTED 0x01
73 #define LINK_AUTHENTICATED 0x02
74 #define LINK_BOUND 0x04
75 #define LINK_ENCRYPTED 0x10
76 #define LINK_SECURE_CONNECTIONS 0x20
77 #define LINK_IN_UPDATE 0x40
78 
80 // Link Database Status callback changeTypes
81 #define LINKDB_STATUS_UPDATE_NEW 0
82 #define LINKDB_STATUS_UPDATE_REMOVED 1
83 #define LINKDB_STATUS_UPDATE_STATEFLAGS 2
84 
85 // Link Authentication Errors
86 #define LINKDB_ERR_INSUFFICIENT_AUTHEN 0x05
87 #define LINBDB_ERR_INSUFFICIENT_KEYSIZE 0x0c
88 #define LINKDB_ERR_INSUFFICIENT_ENCRYPTION 0x0f
89 
91 /*********************************************************************
92  * TYPEDEFS
93  */
94 
101 typedef struct
102 {
103  uint8 srk[KEYLEN]; // Signature Resolving Key
104  uint32 signCounter; // Sign Counter
105 } linkSec_t;
106 
110 typedef struct
111 {
112  uint8 ltk[KEYLEN]; // Long Term Key
113  uint16 div; // Diversifier
114  uint8 rand[B_RANDOM_NUM_SIZE]; // random number
115  uint8 keySize; // LTK Key Size
116 } encParams_t;
117 
121 typedef struct
122 {
123  uint8 taskID; // Application that controls the link
124  uint16 connectionHandle; // Controller connection handle
125  uint8 stateFlags; // LINK_CONNECTED, LINK_AUTHENTICATED...
126  uint8 addrType; // Address type of connected device
127  uint8 addr[B_ADDR_LEN]; // Other Device's address
128  uint8 addrPriv[B_ADDR_LEN]; // Other Device's Private address
129  uint8 connRole; // Connection formed as Master or Slave
130  uint16 connInterval; // The connection's interval (n * 1.23 ms)
131  uint16 MTU; // The connection's MTU size
132  linkSec_t sec; // Connection Security related items
133  encParams_t *pEncParams; // pointer to LTK, ediv, rand. if needed.
134 } linkDBItem_t;
135 
139 typedef struct
140 {
141  uint8 stateFlags; // LINK_CONNECTED, LINK_AUTHENTICATED...
142  uint8 addrType; // Address type of connected device
143  uint8 addr[B_ADDR_LEN]; // Other Device's address
144  uint8 addrPriv[B_ADDR_LEN]; // Other Device's Private address
145  uint8 connRole; // Connection formed as Master or Slave
146  uint16 connInterval; // The connection's interval (n * 1.23 ms)
147  uint16 MTU; // The connection's MTU size
148 } linkDBInfo_t;
154 typedef void (*pfnLinkDBCB_t)( uint16 connectionHandle, uint8 changeType );
156 
158 typedef void (*pfnPerformFuncCB_t)( linkDBItem_t *pLinkItem );
161 /*********************************************************************
162  * GLOBAL VARIABLES
163  */
164 
166 
167 extern uint8 linkDBNumConns;
168 
170 
171 /*********************************************************************
172  * PUBLIC FUNCTIONS
173  */
174 
178  extern void linkDB_Init( void );
179  extern uint8 linkDB_Register( pfnLinkDBCB_t pFunc );
193 
213  extern uint8 linkDB_Add( uint8 taskID, uint16 connectionHandle,
214  uint8 stateFlags, uint8 addrType, uint8 *pAddr,
215  uint8 *pAddrPriv, uint8 connRole, uint16 connInterval,
216  uint16 MTU );
217 
227  extern uint8 linkDB_Remove( uint16 connectionHandle );
228 
241  extern uint8 linkDB_Update( uint16 connectionHandle, uint8 newState,
242  uint8 add );
243 
244 
251  extern uint8 linkDB_NumActive( void );
252 
259  extern uint8 linkDB_NumConns( void );
260 
270  extern uint8 linkDB_UpdateMTU( uint16 connectionHandle, uint16 newMtu );
271 
272 /*
273  * @brief This function is used to get the MTU size of a link.
274  *
275  * @param connectionHandle - controller link connection handle.
276  *
277  * @return link MTU size
278  */
279  extern uint16 linkDB_MTU( uint16 connectionHandle );
280 
292  extern uint8 linkDB_GetInfo( uint16 connectionHandle, linkDBInfo_t * pInfo );
293 
305  extern linkDBItem_t *linkDB_Find( uint16 connectionHandle );
306 
315  extern linkDBItem_t *linkDB_FindFirst( uint8 taskID );
316 
326  extern uint8 linkDB_State( uint16 connectionHandle, uint8 state );
327 
341  extern uint8 linkDB_Authen( uint16 connectionHandle, uint8 keySize,
342  uint8 mitmRequired );
343 
352  extern uint8 linkDB_Role( uint16 connectionHandle );
353 
359  extern void linkDB_PerformFunc( pfnPerformFuncCB_t cb );
360 
367  extern void linkDB_SecurityModeSCOnly( uint8 state );
368 
369 /*********************************************************************
370  * LINK STATE MACROS
371  * Developer note: Call from Application only. Do not call from Stack,
372  * not supported for ROM patching!
373  */
374 
383  #define linkDB_Up( connectionHandle ) linkDB_State( (connectionHandle), LINK_CONNECTED )
384 
393  #define linkDB_Encrypted( connectionHandle ) linkDB_State( (connectionHandle), LINK_ENCRYPTED )
394 
403  #define linkDB_Authenticated( connectionHandle ) linkDB_State( (connectionHandle), LINK_AUTHENTICATED )
404 
413  #define linkDB_Bonded( connectionHandle ) linkDB_State( (connectionHandle), LINK_BOUND )
414 
415 /*********************************************************************
416 *********************************************************************/
417 
418 #ifdef __cplusplus
419 }
420 #endif
421 
422 #endif /* LINKDB_H */
423 
#define B_RANDOM_NUM_SIZE
BLE Random Number Size.
Definition: bcomdef.h:149
Encryption Params.
Definition: linkdb.h:110
#define B_ADDR_LEN
Default Public and Random Address Length.
Definition: bcomdef.h:131
#define KEYLEN
Default key length.
Definition: bcomdef.h:134
Copyright 2016, Texas Instruments Incorporated