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