1 #ifndef GATTM_TASK_H_ 2 #define GATTM_TASK_H_ 3 4 /** 5 **************************************************************************************** 6 * @addtogroup GATTMTASK Task 7 * @ingroup GATTM 8 * @brief Handles ALL GATT block operations not related to a connection. 9 * 10 * The GATTMTASK is responsible for managing internal attribute database and state of 11 * GATT controller which manage GATT block operations related to a connection. 12 * 13 * Messages may originate from @ref ATTM "ATTM", @ref GAP "GAP" and Application. 14 * 15 * @{ 16 **************************************************************************************** 17 */ 18 /* 19 * INCLUDE FILES 20 **************************************************************************************** 21 */ 22 #include "rwip_task.h" // Task definitions 23 #include "att.h" 24 25 /* 26 * DEFINES 27 **************************************************************************************** 28 */ 29 30 31 /// GATT Task messages 32 enum gattm_msg_id 33 { 34 /* Database Management */ 35 /// Add service in database request 36 GATTM_ADD_SVC_REQ = TASK_FIRST_MSG(TASK_ID_GATTM), 37 /// Add service in database response 38 GATTM_ADD_SVC_RSP, 39 40 /* Service management */ 41 /// Get permission settings of service request 42 GATTM_SVC_GET_PERMISSION_REQ, 43 /// Get permission settings of service response 44 GATTM_SVC_GET_PERMISSION_RSP, 45 /// Set permission settings of service request 46 GATTM_SVC_SET_PERMISSION_REQ, 47 /// Set permission settings of service response 48 GATTM_SVC_SET_PERMISSION_RSP, 49 50 /* Attribute Manipulation */ 51 /// Get permission settings of attribute request 52 GATTM_ATT_GET_PERMISSION_REQ, 53 /// Get permission settings of attribute response 54 GATTM_ATT_GET_PERMISSION_RSP, 55 /// Set permission settings of attribute request 56 GATTM_ATT_SET_PERMISSION_REQ, 57 /// Set permission settings of attribute response 58 GATTM_ATT_SET_PERMISSION_RSP, 59 60 /// Get attribute value request 61 GATTM_ATT_GET_VALUE_REQ, 62 /// Get attribute value response 63 GATTM_ATT_GET_VALUE_RSP, 64 /// Set attribute value request 65 GATTM_ATT_SET_VALUE_REQ, 66 /// Set attribute value response 67 GATTM_ATT_SET_VALUE_RSP, 68 69 /* Debug messages */ 70 /// DEBUG ONLY: Destroy Attribute database request 71 GATTM_DESTROY_DB_REQ, 72 /// DEBUG ONLY: Destroy Attribute database response 73 GATTM_DESTROY_DB_RSP, 74 /// DEBUG ONLY: Retrieve list of services request 75 GATTM_SVC_GET_LIST_REQ, 76 /// DEBUG ONLY: Retrieve list of services response 77 GATTM_SVC_GET_LIST_RSP, 78 /// DEBUG ONLY: Retrieve information of attribute request 79 GATTM_ATT_GET_INFO_REQ, 80 /// DEBUG ONLY: Retrieve information of attribute response 81 GATTM_ATT_GET_INFO_RSP, 82 }; 83 84 85 /** 86 * Attribute Description 87 */ 88 struct gattm_att_desc 89 { 90 /** Attribute UUID (LSB First) */ 91 uint8_t uuid[ATT_UUID_128_LEN]; 92 93 /** 94 * Attribute Permission (@see attm_perm_mask) 95 */ 96 uint16_t perm; 97 98 99 /** 100 * Maximum length of the attribute 101 * 102 * Note: 103 * For Included Services and Characteristic Declarations, this field contains targeted 104 * handle. 105 * 106 * For Characteristic Extended Properties, this field contains 2 byte value 107 * 108 * Not used Client Characteristic Configuration and Server Characteristic Configuration, 109 * this field is not used. 110 */ 111 uint16_t max_len; 112 113 /** 114 * Attribute Extended permissions 115 * 116 * Extended Value permission bit field 117 * 118 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 119 * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 120 * | RI |UUID_LEN |EKS | Reserved | 121 * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 122 * 123 * Bit [0-11] : Reserved 124 * Bit [12] : Encryption key Size must be 16 bytes 125 * Bit [13-14]: UUID Length (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU) 126 * Bit [15] : Trigger Read Indication (0 = Value present in Database, 1 = Value not present in Database) 127 */ 128 uint16_t ext_perm; 129 }; 130 131 /** 132 * Service description 133 */ 134 struct gattm_svc_desc 135 { 136 /// Attribute Start Handle (0 = dynamically allocated) 137 uint16_t start_hdl; 138 /// Task identifier that manages service 139 uint16_t task_id; 140 141 /** 142 * 7 6 5 4 3 2 1 0 143 * +----+----+----+----+----+----+----+----+ 144 * |SEC |UUID_LEN |DIS | AUTH |EKS | MI | 145 * +----+----+----+----+----+----+----+----+ 146 * 147 * Bit [0] : Task that manage service is multi-instantiated (Connection index is conveyed) 148 * Bit [1] : Encryption key Size must be 16 bytes 149 * Bit [2-3]: Service Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = Secure Connect) 150 * Bit [4] : Disable the service 151 * Bit [5-6]: UUID Length (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU) 152 * Bit [7] : Secondary Service (0 = Primary Service, 1 = Secondary Service) 153 */ 154 uint8_t perm; 155 156 /// Number of attributes 157 uint8_t nb_att; 158 159 /** Service UUID */ 160 uint8_t uuid[ATT_UUID_128_LEN]; 161 /** 162 * List of attribute description present in service. 163 */ 164 struct gattm_att_desc atts[__ARRAY_EMPTY]; 165 }; 166 167 168 /// Add service in database request 169 struct gattm_add_svc_req 170 { 171 /// service description 172 struct gattm_svc_desc svc_desc; 173 }; 174 175 /// Add service in database response 176 struct gattm_add_svc_rsp 177 { 178 /// Start handle of allocated service in attribute database 179 uint16_t start_hdl; 180 /// Return status of service allocation in attribute database. 181 uint8_t status; 182 }; 183 184 /* Service management */ 185 /// Get permission settings of service request 186 struct gattm_svc_get_permission_req 187 { 188 /// Service start attribute handle 189 uint16_t start_hdl; 190 }; 191 192 /// Get permission settings of service response 193 struct gattm_svc_get_permission_rsp 194 { 195 /// Service start attribute handle 196 uint16_t start_hdl; 197 /// service permission 198 uint8_t perm; 199 /// Return status 200 uint8_t status; 201 }; 202 203 /// Set permission settings of service request 204 struct gattm_svc_set_permission_req 205 { 206 /// Service start attribute handle 207 uint16_t start_hdl; 208 /// service permission 209 uint8_t perm; 210 }; 211 212 /// Set permission settings of service response 213 struct gattm_svc_set_permission_rsp 214 { 215 /// Service start attribute handle 216 uint16_t start_hdl; 217 /// Return status 218 uint8_t status; 219 }; 220 221 222 /* Attribute management */ 223 /// Get permission settings of attribute request 224 struct gattm_att_get_permission_req 225 { 226 /// Handle of the attribute 227 uint16_t handle; 228 }; 229 230 /// Get permission settings of attribute response 231 struct gattm_att_get_permission_rsp 232 { 233 /// Handle of the attribute 234 uint16_t handle; 235 /// Attribute permission 236 uint16_t perm; 237 /// Extended Attribute permission 238 uint16_t ext_perm; 239 /// Return status 240 uint8_t status; 241 }; 242 243 /// Set permission settings of attribute request 244 struct gattm_att_set_permission_req 245 { 246 /// Handle of the attribute 247 uint16_t handle; 248 /// Attribute permission 249 uint16_t perm; 250 /// Extended Attribute permission 251 uint16_t ext_perm; 252 }; 253 254 /// Set permission settings of attribute response 255 struct gattm_att_set_permission_rsp 256 { 257 /// Handle of the attribute 258 uint16_t handle; 259 /// Return status 260 uint8_t status; 261 }; 262 263 264 /// Get attribute value request 265 struct gattm_att_get_value_req 266 { 267 /// Handle of the attribute 268 uint16_t handle; 269 }; 270 271 /// Get attribute value response 272 struct gattm_att_get_value_rsp 273 { 274 /// Handle of the attribute 275 uint16_t handle; 276 /// Attribute value length 277 uint16_t length; 278 /// Return status 279 uint8_t status; 280 /// Attribute value 281 uint8_t value[__ARRAY_EMPTY]; 282 }; 283 284 /// Set attribute value request 285 struct gattm_att_set_value_req 286 { 287 /// Handle of the attribute 288 uint16_t handle; 289 /// Attribute value length 290 uint16_t length; 291 /// Attribute value 292 uint8_t value[__ARRAY_EMPTY]; 293 }; 294 295 /// Set attribute value response 296 struct gattm_att_set_value_rsp 297 { 298 /// Handle of the attribute 299 uint16_t handle; 300 /// Return status 301 uint8_t status; 302 }; 303 304 /// DEBUG ONLY: Destroy Attribute database request 305 struct gattm_destroy_db_req 306 { 307 /// New Gap Start Handle 308 uint16_t gap_hdl; 309 /// New Gatt Start Handle 310 uint16_t gatt_hdl; 311 }; 312 313 /// DEBUG ONLY: Destroy Attribute database Response 314 struct gattm_destroy_db_rsp 315 { 316 /// Return status 317 uint8_t status; 318 }; 319 320 321 /// Service information 322 struct gattm_svc_info 323 { 324 /// Service start handle 325 uint16_t start_hdl; 326 /// Service end handle 327 uint16_t end_hdl; 328 /// Service task_id 329 uint16_t task_id; 330 /// Service permission 331 uint8_t perm; 332 }; 333 334 /// DEBUG ONLY: Retrieve list of services response 335 struct gattm_svc_get_list_rsp 336 { 337 /// Return status 338 uint8_t status; 339 /// Number of services 340 uint8_t nb_svc; 341 /// Array of information about services 342 struct gattm_svc_info svc[__ARRAY_EMPTY]; 343 }; 344 345 /// DEBUG ONLY: Retrieve information of attribute request 346 struct gattm_att_get_info_req 347 { 348 /// Attribute Handle 349 uint16_t handle; 350 }; 351 352 /// DEBUG ONLY: Retrieve information of attribute response 353 struct gattm_att_get_info_rsp 354 { 355 /// Return status 356 uint8_t status; 357 /// UUID Length 358 uint8_t uuid_len; 359 /// Attribute Handle 360 uint16_t handle; 361 /// Attribute Permissions 362 uint16_t perm; 363 /// Extended Attribute permission 364 uint16_t ext_perm; 365 /// UUID value 366 uint8_t uuid[ATT_UUID_128_LEN]; 367 }; 368 369 /* 370 * FUNCTION DECLARATIONS 371 **************************************************************************************** 372 */ 373 374 /// @} GATTMTASK 375 #endif // GATTM_TASK_H_ 376