1 /**
2  ****************************************************************************************
3  *
4  * @file gapc.h
5  *
6  * @brief Generic Access Profile Controller Header.
7  *
8  * Copyright (C) RivieraWaves 2009-2016
9  *
10  ****************************************************************************************
11  */
12 
13 
14 #ifndef _GAPC_H_
15 #define _GAPC_H_
16 
17 /**
18  ****************************************************************************************
19  * @addtogroup GAPC Generic Access Profile Controller
20  * @ingroup GAP
21  * @brief  Generic Access Profile Controller.
22  *
23  * The GAP Controller module is responsible for providing an API to the application in
24  * to perform GAP action related to a BLE connection (pairing, update parameters,
25  * disconnect ...). GAP controller is multi-instantiated, one task instance per BLE
26  * connection.
27  *
28  * @{
29  ****************************************************************************************
30  */
31 
32 
33 /*
34  * INCLUDE FILES
35  ****************************************************************************************
36  */
37 #include "rwip_config.h"
38 
39 #if (BLE_GAPC)
40 
41 #include "ke_task.h"
42 #include "gap.h"
43 #include "smpc.h"
44 
45 
46 
47 /*
48  * DEFINES
49  ****************************************************************************************
50  */
51 
52 
53 /// Operation type
54 enum gapc_op_type
55 {
56     /// Operation used to manage Link (update params, get peer info)
57     GAPC_OP_LINK_INFO    = 0x00,
58 
59     /// Operation used to manage SMP
60     GAPC_OP_SMP          = 0x01,
61 
62     /// Operation used to manage connection update
63     GAPC_OP_LINK_UPD     = 0x02,
64 
65     /// Max number of operations
66     GAPC_OP_MAX
67 };
68 
69 /// Link security status. This status represents the authentication/authorization/bonding levels of the connection
70 enum gapc_lk_sec_req
71 {
72     /// Link is bonded
73     GAPC_LK_BONDED,
74     /// Link is Encrypted
75     GAPC_LK_ENCRYPTED,
76     /// Link LTK Exchanged during pairing
77     GAPC_LK_LTK_PRESENT,
78 };
79 
80 /*
81  * TYPE DEFINITIONS
82  ****************************************************************************************
83  */
84 
85 /// GAP controller environment variable structure.
86 struct gapc_env_tag
87 {
88     /// Request operation Kernel message
89     void* operation[GAPC_OP_MAX];
90     /// Task id requested disconnection
91     ke_task_id_t disc_requester;
92 
93 
94     /* Connection parameters to keep */
95 
96     /// Security Management Protocol environment variables
97     struct smpc_env smpc;
98 
99     /// connection handle
100     uint16_t conhdl;
101 
102     /// Configuration fields (@see enum gapc_fields)
103     uint8_t fields;
104 
105     // BD Address used for the link that should be kept
106     struct gap_bdaddr src[SMPC_INFO_MAX];
107 
108     /// Relevant information of peer LE features 8-byte array
109     uint8_t features;
110 };
111 
112 
113 
114 /*
115  * MACROS
116  ****************************************************************************************
117  */
118 
119 /*
120  * FUNCTION DECLARATIONS
121  ****************************************************************************************
122  */
123 
124 /**
125  ****************************************************************************************
126  * @brief Retrieve connection index from connection handle.
127  *
128  * @param[in] conhdl Connection handle
129  *
130  * @return Return found connection index, GAP_INVALID_CONIDX if not found.
131  ****************************************************************************************
132  */
133 uint8_t gapc_get_conidx(uint16_t conhdl);
134 
135 /**
136  ****************************************************************************************
137  * @brief Retrieve connection handle from connection index.
138  *
139  * @param[in] conidx Connection index
140  *
141  * @return Return found connection handle, GAP_INVALID_CONHDL if not found.
142  ****************************************************************************************
143  */
144 uint16_t gapc_get_conhdl(uint8_t conidx);
145 
146 /**
147  ****************************************************************************************
148  * @brief Retrieve connection role from connection index.
149  *
150  * @param[in] conidx Connection index
151  *
152  * @return Return found connection role
153  ****************************************************************************************
154  */
155 uint8_t gapc_get_role(uint8_t conidx);
156 
157 /**
158  ****************************************************************************************
159  * @brief Retrieve connection address information on current link.
160  *
161  * @param[in] conidx Connection index
162  * @param[in] src    Connection information source
163  *
164  * @return Return found connection address
165  ****************************************************************************************
166  */
167 struct gap_bdaddr* gapc_get_bdaddr(uint8_t conidx, uint8_t src);
168 
169 
170 /**
171  ****************************************************************************************
172  * @brief Check if current link support security requirements.
173  *
174  * @param[in] conidx  Connection index
175  * @param[in] sec_req Link security requirement to test
176  *
177  * @return True if link requirement is supported, False else.
178  ****************************************************************************************
179  */
180 bool gapc_is_sec_set(uint8_t conidx, uint8_t sec_req);
181 
182 /**
183  ****************************************************************************************
184  * @brief Retrieve Link Security level
185  *
186  * @param[in] conidx  Connection index
187  *
188  * @return Link Security level.
189  ****************************************************************************************
190  */
191 uint8_t gapc_lk_sec_lvl_get(uint8_t conidx);
192 
193 /**
194  ****************************************************************************************
195  * @brief Retrieve the encryption key size of the connection
196  *
197  * @param[in] conidx Connection index
198  *
199  * @return encryption key size (size is 7 - 16 byte range)
200  *
201  ****************************************************************************************
202  */
203 uint8_t gapc_enc_keysize_get(uint8_t conidx);
204 
205 /**
206  ****************************************************************************************
207  * @brief Get Service Change Client Configuration
208  *
209  * @param[in] conidx Connection index
210  *
211  * @return Service Change Client Configuration
212  ****************************************************************************************
213  */
214 bool gapc_svc_chg_ccc_get(uint8_t conidx);
215 
216 /**
217  ****************************************************************************************
218  * @brief Set Service Change Client Configuration
219  *
220  * @param[in] conidx Connection index
221  * @param[in] enable True if CCC is enabled, False else
222  *
223  ****************************************************************************************
224  */
225 void gapc_svc_chg_ccc_set(uint8_t conidx, bool enable);
226 
227 
228 #endif // (BLE_GAPC)
229 /// @} GAPC
230 
231 #endif /* _GAPC_H_ */
232