1 /** 2 **************************************************************************************** 3 * 4 * @file gapm.h 5 * 6 * @brief Generic Access Profile Manager Header. 7 * 8 * Copyright (C) RivieraWaves 2009-2016 9 * 10 **************************************************************************************** 11 */ 12 13 14 #ifndef _GAPM_H_ 15 #define _GAPM_H_ 16 17 /** 18 **************************************************************************************** 19 * @addtogroup GAPM Generic Access Profile Manager 20 * @ingroup GAP 21 * @brief Generic Access Profile Manager. 22 * 23 * The GAP Manager module is responsible for providing an API to the application in order 24 * to manage all non connected stuff such as configuring device to go in desired mode 25 * (discoverable, connectable, etc.) and perform required actions (scanning, connection, 26 * etc.). GAP Manager is also responsible of managing GAP Controller state according to 27 * corresponding BLE connection states. 28 * 29 * @{ 30 **************************************************************************************** 31 */ 32 33 34 /* 35 * INCLUDE FILES 36 **************************************************************************************** 37 */ 38 #include "rwip_config.h" 39 #include "ke_task.h" 40 #include "gap.h" 41 42 /* 43 * DEFINES 44 **************************************************************************************** 45 */ 46 /// Bit checking 47 #define GAPM_ISBITSET(flag, mask) (((flag)&(mask)) == mask) 48 49 50 51 52 53 /* 54 * FUNCTION DECLARATIONS 55 **************************************************************************************** 56 */ 57 58 /** 59 **************************************************************************************** 60 * @brief Initialize Generic Access Profile Manager Module. 61 * 62 * @param[in] reset true if it's requested by a reset; false if it's boot initialization 63 * 64 **************************************************************************************** 65 */ 66 void gapm_init(bool reset); 67 68 69 /** 70 **************************************************************************************** 71 * @brief Retrieve Task Identifier from Task number 72 * (automatically update index of task in returned task id) 73 * 74 * @param task Task number 75 * @return Task Identifier 76 **************************************************************************************** 77 */ 78 ke_task_id_t gapm_get_id_from_task(ke_msg_id_t task); 79 80 /** 81 **************************************************************************************** 82 * @brief Retrieve Task Number from Task Identifier 83 * (automatically update index of task in returned task id) 84 * 85 * @param id Task Identifier 86 * @return Task Number 87 **************************************************************************************** 88 */ 89 ke_task_id_t gapm_get_task_from_id(ke_msg_id_t id); 90 91 92 93 #if (BLE_GAPC) 94 /** 95 **************************************************************************************** 96 * @brief Created link connection parameters (from bond data) has been set, connection 97 * ready to be used. 98 * 99 * @param[in] conidx Connection Index 100 * 101 **************************************************************************************** 102 */ 103 void gapm_con_enable(uint8_t conidx); 104 105 106 /** 107 **************************************************************************************** 108 * @brief A link has been disconnected, clean-up host stack for this connection. 109 * 110 * @param[in] conidx Connection Index 111 * @param[in] conhdl Connection Handle 112 * @param[in] reason Reason of the disconnection 113 * 114 **************************************************************************************** 115 */ 116 void gapm_con_cleanup(uint8_t conidx, uint16_t conhdl, uint8_t reason); 117 118 #endif // (BLE_GAPC) 119 120 121 /** 122 **************************************************************************************** 123 * @brief Retrieve device identity key. 124 * 125 * @return Device Identity Key 126 **************************************************************************************** 127 */ 128 struct gap_sec_key* gapm_get_irk(void); 129 130 131 /** 132 **************************************************************************************** 133 * @brief Retrieve local public address. 134 * 135 * @return Return local public address 136 **************************************************************************************** 137 */ 138 bd_addr_t* gapm_get_bdaddr(void); 139 140 141 142 #ifdef BLE_AUDIO_AM0_TASK 143 /** 144 **************************************************************************************** 145 * @brief Return if LE Audio Mode 0 is supported or not 146 * 147 * @return True if supported, False else 148 **************************************************************************************** 149 */ 150 bool gapm_is_audio_am0_sup(void); 151 #endif // BLE_AUDIO_AM0_TASK 152 153 154 #if (BLE_EMB_PRESENT && HCI_TL_SUPPORT) 155 /** 156 **************************************************************************************** 157 * @brief Retrieve if host is embedded or not 158 * 159 * @return True if embedded host is enabled, false else. 160 **************************************************************************************** 161 */ 162 bool gapm_is_embedded_host(void); 163 164 /** 165 **************************************************************************************** 166 * @brief Set if host is embedded or not 167 * 168 * @param[in] enable True to enable embedded host, false else. 169 **************************************************************************************** 170 */ 171 void gapm_set_embedded_host(bool enable); 172 #endif // (BLE_EMB_PRESENT && HCI_TL_SUPPORT) 173 174 175 176 /** 177 **************************************************************************************** 178 * @brief Retrieve the device address type (@see enum gapm_addr_type) 179 * 180 * @return address type 181 **************************************************************************************** 182 */ 183 uint8_t gapm_get_address_type(void); 184 185 186 #if (BLE_ATTS) 187 188 /** 189 **************************************************************************************** 190 * @brief Get if preferred connection parameters present in GAP ATT database 191 * 192 * @return True if referred connection parameters present in GAP ATT database, False else 193 **************************************************************************************** 194 */ 195 bool gapm_is_pref_con_param_pres(void); 196 197 /** 198 **************************************************************************************** 199 * @brief retrieve gap attribute handle from attribute index. 200 * 201 * @param[in] att_idx Attribute index 202 * 203 * @return Attribute handle 204 **************************************************************************************** 205 */ 206 uint16_t gapm_get_att_handle(uint8_t att_idx); 207 208 #endif // (BLE_ATTS) 209 210 #if (SECURE_CONNECTIONS) 211 /** 212 **************************************************************************************** 213 * @brief Returns the local Public Key 214 * 215 * @return pointer to the local Public Key 216 **************************************************************************************** 217 */ 218 public_key_t* gapm_get_local_public_key(void); 219 #endif // (SECURE_CONNECTIONS) 220 221 /** 222 **************************************************************************************** 223 * @brief Retrieve if Legacy pairing is supported on local device 224 * 225 * @return True if legacy pairing is supported 226 **************************************************************************************** 227 */ 228 bool gapm_is_legacy_pairing_supp(void); 229 230 231 /** 232 **************************************************************************************** 233 * @brief Retrieve if Secure Connection pairing is supported on local device 234 * 235 * @return True if Secure Connection pairing is supported 236 **************************************************************************************** 237 */ 238 bool gapm_is_sec_con_pairing_supp(void); 239 240 241 #if (BLE_LECB) 242 /** 243 **************************************************************************************** 244 * @brief Check if LECB connection can be registered (established) 245 * 246 * @param[in] le_psm LE Protocol/Service Multiplexer 247 * @param[in] conidx Connection index for app_task computation 248 * @param[out] app_task Destination application/profile task 249 * @param[out] sec_lvl Security level requirements 250 * 251 * 252 * @return GAP_ERR_NOT_FOUND if LE_PSM not register, GAP_ERR_NO_ERROR else 253 **************************************************************************************** 254 */ 255 uint8_t gapm_le_psm_get_info(uint16_t le_psm, uint8_t conidx, ke_task_id_t *app_task, uint8_t *sec_lvl); 256 257 258 /** 259 **************************************************************************************** 260 * @brief Check if LECB connection can be registered (established) 261 * 262 * @param[in] le_psm LE Protocol/Service Multiplexer 263 * @param[in] peer_con_init Info to know if connection is initiated by peer device 264 * 265 * @return L2C_ERR_NO_RES_AVAIL if all LECB link are established, GAP_ERR_NO_ERROR else 266 **************************************************************************************** 267 */ 268 uint8_t gapm_lecb_register(uint16_t le_psm, bool peer_con_init); 269 270 271 /** 272 **************************************************************************************** 273 * @brief Unregister an existing LECB connection 274 * 275 * @param[in] le_psm LE Protocol/Service Multiplexer 276 * @param[in] peer_con_init Info to know if connection is initiated by peer device 277 * 278 * @return GAP_ERR_NO_ERROR 279 **************************************************************************************** 280 */ 281 uint8_t gapm_lecb_unregister(uint16_t le_psm, bool peer_con_init); 282 283 #endif // (BLE_LECB) 284 285 /** 286 **************************************************************************************** 287 * @brief Return the maximal MTU value 288 * 289 * @param[out] Maximal MTU value 290 **************************************************************************************** 291 */ 292 uint16_t gapm_get_max_mtu(void); 293 void gapm_set_max_mtu(uint16_t mtu); 294 295 /** 296 **************************************************************************************** 297 * @brief Return the maximal MPS value 298 * 299 * @param[out] Maximal MPS value 300 **************************************************************************************** 301 */ 302 uint16_t gapm_get_max_mps(void); 303 304 305 306 /** 307 **************************************************************************************** 308 * @brief Check If Service changed feature is enabled or not 309 * 310 * @return true if enabled, false else. 311 * 312 **************************************************************************************** 313 */ 314 bool gapm_svc_chg_en(void); 315 316 #if (BLE_DEBUG) 317 /** 318 **************************************************************************************** 319 * @brief Check If Debug mode feature is enabled or not 320 * 321 * @return true if enabled, false else. 322 * 323 **************************************************************************************** 324 */ 325 bool gapm_dbg_mode_en(void); 326 327 /** 328 **************************************************************************************** 329 * @brief Force the GAP service start handle 330 **************************************************************************************** 331 */ 332 void gapm_set_svc_start_hdl(uint16_t start_hdl); 333 #endif // (BLE_DEBUG) 334 335 /** 336 **************************************************************************************** 337 * Retrieve if current connection index is used for a discovery purpose such as 338 * Name discovery 339 * 340 * @param conidx Index of the specific connection 341 * 342 * @return true if connection has a discovery purpose, False else 343 **************************************************************************************** 344 */ 345 bool gapm_is_disc_connection(uint8_t conidx); 346 347 /// @} GAPM 348 349 #endif /* _GAPM_H_ */ 350