120 #include "bt_system.h" 121 #include "bt_platform.h" 133 #define BT_GATTC_EXCHANGE_MTU (BT_MODULE_GATT | 0x00010000) 134 #define BT_GATTC_DISCOVER_PRIMARY_SERVICE (BT_MODULE_GATT | 0x00020000) 135 #define BT_GATTC_DISCOVER_PRIMARY_SERVICE_BY_UUID (BT_MODULE_GATT | 0x00030000) 136 #define BT_GATTC_FIND_INCLUDED_SERVICES (BT_MODULE_GATT | 0x00040000) 137 #define BT_GATTC_DISCOVER_CHARC (BT_MODULE_GATT | 0x00050000) 138 #define BT_GATTC_DISCOVER_CHARC_DESCRIPTOR (BT_MODULE_GATT | 0x00060000) 139 #define BT_GATTC_READ_CHARC (BT_MODULE_GATT | 0x00070000) 140 #define BT_GATTC_READ_LONG_CHARC (BT_MODULE_GATT | 0x00080000) 141 #define BT_GATTC_READ_USING_CHARC_UUID (BT_MODULE_GATT | 0x00090000) 142 #define BT_GATTC_READ_MULTI_CHARC_VALUES (BT_MODULE_GATT | 0x000A0000) 143 #define BT_GATTC_WRITE_CHARC (BT_MODULE_GATT | 0x000D0000) 144 #define BT_GATTC_WRITE_LONG_CHARC (BT_MODULE_GATT | 0x000E0000) 145 #define BT_GATTC_RELIABLE_WRITE_CHARC (BT_MODULE_GATT | 0x000F0000) 146 #define BT_GATTC_CHARC_VALUE_NOTIFICATION (BT_MODULE_GATT | 0x00110000) 147 #define BT_GATTC_CHARC_VALUE_INDICATION (BT_MODULE_GATT | 0x00120000) 148 #define BT_GATTC_CHARC_VALUE_CONFIRMATION (BT_MODULE_GATT | 0x00130000) 162 typedef bt_att_exchange_mtu_req_t bt_gattc_exchange_mtu_req_t; 170 uint16_t starting_handle;
171 uint16_t ending_handle;
180 uint16_t attribute_value_length;
195 uint16_t starting_handle;
196 uint16_t ending_handle;
225 uint16_t handle_length;
234 uint16_t attribute_value_length;
243 uint16_t attribute_value_length;
252 uint16_t attribute_value_length;
266 uint16_t attribute_value_length;
286 uint16_t server_rx_mtu;
373 uint16_t attribute_value_length;
423 #define BT_GATTC_NEW_EXCHANGE_MTU_REQ(name, mtu) \ 424 static bt_gattc_exchange_mtu_req_t name; \ 425 name.opcode = BT_ATT_OPCODE_EXCHANGE_MTU_REQUEST; \ 426 name.client_rx_mtu = mtu; \ 432 #define BT_GATTC_NEW_DISCOVER_PRIMARY_SERVICE_REQ(name) \ 433 static const bt_gattc_discover_primary_service_req_t name = { \ 434 .opcode = BT_ATT_OPCODE_READ_BY_GROUP_TYPE_REQUEST, \ 435 .starting_handle = 0x0001, \ 436 .ending_handle = 0xFFFF, \ 437 .type16 = BT_GATT_UUID16_PRIMARY_SERVICE \ 445 #define BT_GATTC_NEW_DISCOVER_PRIMARY_SERVICE_BY_UUID16_REQ(name, uuid16) \ 446 static bt_gattc_discover_primary_service_by_uuid_req_t name; \ 447 static uint8_t name##buf[9]; \ 448 name.attribute_value_length = 2; \ 449 name.att_req = (bt_att_find_by_type_value_req_t *)(name##buf); \ 450 name.att_req->opcode = BT_ATT_OPCODE_FIND_BY_TYPE_VALUE_REQUEST; \ 451 name.att_req->starting_handle = 0x0001; \ 452 name.att_req->ending_handle = 0xFFFF; \ 453 name.att_req->uuid = BT_GATT_UUID16_PRIMARY_SERVICE; \ 454 memcpy(&(name.att_req->attribute_value), &uuid16, 2); 461 #define BT_GATTC_NEW_DISCOVER_PRIMARY_SERVICE_BY_UUID128_REQ(name, uuid128) \ 462 static bt_gattc_discover_primary_service_by_uuid_req_t name; \ 463 static uint8_t name##buf[30]; \ 464 name.attribute_value_length = 16; \ 465 name.att_req = (bt_att_find_by_type_value_req_t *)(name##buf); \ 466 name.att_req->opcode = BT_ATT_OPCODE_FIND_BY_TYPE_VALUE_REQUEST; \ 467 name.att_req->starting_handle = 0x0001; \ 468 name.att_req->ending_handle = 0xFFFF; \ 469 name.att_req->uuid = BT_GATT_UUID16_PRIMARY_SERVICE; \ 470 memcpy(&(name.att_req->attribute_value), &uuid128, 16); 478 #define BT_GATTC_NEW_FIND_INCLUDED_SERVICE_REQ(name, start_handle, end_handle) \ 479 static bt_gattc_find_included_services_req_t name; \ 480 name.opcode = BT_ATT_OPCODE_READ_BY_TYPE_REQUEST; \ 481 name.type16 = BT_GATT_UUID16_INCLUDE; \ 482 name.starting_handle = start_handle; \ 483 name.ending_handle = end_handle; 491 #define BT_GATTC_NEW_DISCOVER_CHARC_REQ(name, start_handle, end_handle) \ 492 static bt_gattc_discover_charc_req_t name; \ 493 name.opcode = BT_ATT_OPCODE_READ_BY_TYPE_REQUEST; \ 494 name.starting_handle = start_handle; \ 495 name.ending_handle = end_handle; \ 496 uint16_t name##uuid_16 = BT_GATT_UUID16_CHARC; \ 497 bt_uuid_load(&(name.type), (void *)&(name##uuid_16), 2); 507 #define BT_GATTC_NEW_DISCOVER_CHARC_BY_UUID_REQ(name, start_handle, end_handle, uuid, len) \ 508 static bt_gattc_discover_charc_req_t name; \ 509 name.opcode = BT_ATT_OPCODE_READ_BY_TYPE_REQUEST; \ 510 name.starting_handle = start_handle; \ 511 name.ending_handle = end_handle; \ 512 bt_uuid_load(&(name.type), (void *)uuid, len); 520 #define BT_GATTC_NEW_DISCOVER_CHARC_DESCRIPTOR_REQ(name, start_handle, end_handle) \ 521 static bt_gattc_discover_charc_descriptor_req_t name; \ 522 name.opcode = BT_ATT_OPCODE_FIND_INFORMATION_REQUEST; \ 523 name.starting_handle = start_handle; \ 524 name.ending_handle = end_handle; 531 #define BT_GATTC_NEW_READ_CHARC_REQ(name, attr_handle) \ 532 static bt_gattc_read_charc_req_t name; \ 533 name.opcode = BT_ATT_OPCODE_READ_REQUEST; \ 534 name.attribute_handle = attr_handle; 542 #define BT_GATTC_NEW_READ_LONG_CHARC_REQ(name, attr_handle, offset) \ 543 static bt_gattc_read_long_charc_value_req_t name; \ 544 name.opcode = BT_ATT_OPCODE_READ_BLOB_REQUEST; \ 545 name.attribute_handle = attr_handle; \ 546 name.value_offset = offset; 556 #define BT_GATTC_NEW_READ_USING_CHARC_UUID_REQ(name, start_handle, end_handle, uuid, len) \ 557 static bt_gattc_read_using_charc_uuid_req_t name; \ 558 name.opcode = BT_ATT_OPCODE_READ_BY_TYPE_REQUEST; \ 559 name.starting_handle = start_handle; \ 560 name.ending_handle = end_handle; \ 561 bt_uuid_load(&name.type, (void *)uuid, len); 572 #define BT_GATTC_NEW_WRITE_WITHOUT_RSP_REQ(name, buffer, type, attribute_handle, attribute_value, attribute_len) \ 573 static bt_gattc_write_without_rsp_req_t name; \ 574 name.attribute_value_length = attribute_len; \ 575 name.att_req = (bt_att_write_command_t *)(buffer); \ 576 name.att_req->opcode = (type == 0 ? BT_ATT_OPCODE_WRITE_COMMAND : BT_ATT_OPCODE_SIGNED_WRITE_COMMAND); \ 577 name.att_req->attribute_handle = attribute_handle; \ 578 memcpy(name.att_req->attribute_value, attribute_value, attribute_len); 588 #define BT_GATTC_NEW_WRITE_CHARC_REQ(name, buffer, attribute_handle, attribute_value, attribute_len) \ 589 static bt_gattc_write_charc_req_t name; \ 590 name.attribute_value_length = attribute_len; \ 591 name.att_req = (bt_att_write_req_t *)(buffer); \ 592 name.att_req->opcode = BT_ATT_OPCODE_WRITE_REQUEST; \ 593 name.att_req->attribute_handle = attribute_handle; \ 594 memcpy(name.att_req->attribute_value, attribute_value, attribute_len); 604 #define BT_GATTC_NEW_PREPARE_WRITE_REQ(name, attr_handle, offset, value, value_len) \ 605 static bt_gattc_prepare_write_charc_req_t name; \ 606 static bt_att_prepare_write_req_t name##att_req; \ 607 (name##att_req).opcode = BT_ATT_OPCODE_PREPARE_WRITE_REQUEST; \ 608 (name##att_req).attribute_handle = attr_handle; \ 609 (name##att_req).value_offset = offset; \ 610 (name##att_req).part_attribute_value = value; \ 611 name.attribute_value_length = value_len; \ 612 name.att_req = &(name##att_req); 619 #define BT_GATTC_NEW_EXECUTE_WRITE_REQ(name, flag) \ 620 static bt_gattc_execute_write_req_t name; \ 621 name.opcode = BT_ATT_OPCODE_EXECUTE_WRITE_REQUEST; \ 684 const bt_gattc_find_included_services_req_t *req);
709 const bt_gattc_discover_charc_descriptor_req_t *req);
722 const bt_gattc_read_charc_req_t *req);
735 const bt_gattc_read_long_charc_value_req_t *req);
748 const bt_gattc_read_using_charc_uuid_req_t *req);
820 const bt_gattc_execute_write_req_t *req);
ATT write request structure.
Definition: bt_att.h:297
ATT find by type value request structure.
Definition: bt_att.h:196
Discover Primary Service request.
Definition: bt_gattc.h:173
ATT handle value notification structure.
Definition: bt_att.h:355
bt_status_t bt_gattc_read_using_charc_uuid(bt_handle_t connection_handle, const bt_gattc_read_using_charc_uuid_req_t *req)
This function reads the characteristics of the GATT Server by UUID.
bt_gattc_discover_primary_service_req_t bt_gattc_find_included_services_req_t
Find Included Service request.
Definition: bt_gattc.h:187
ATT read multiple response structure.
Definition: bt_att.h:277
ATT write response structure.
Definition: bt_att.h:302
This structure defines the data type of the callback parameter for the event (BT_GATTC_WRITE_CHARC) w...
Definition: bt_gattc.h:366
bt_att_execute_write_req_t bt_gattc_execute_write_req_t
Execute Write request.
Definition: bt_gattc.h:259
This structure defines the data type of the callback parameter for the event (BT_GATTC_READ_CHARC or ...
Definition: bt_gattc.h:327
ATT read response structure.
Definition: bt_att.h:244
Discover Primary Service By UUID request.
Definition: bt_gattc.h:182
uint16_t bt_handle_t
Define the connection handle type.
Definition: bt_type.h:85
ATT execute write request structure.
Definition: bt_att.h:340
ATT exchange MTU request structure.
Definition: bt_att.h:155
This structure defines the data type of the callback parameter for the event (BT_GATTC_READ_MULTI_CHA...
Definition: bt_gattc.h:347
Read blob response.
Definition: bt_gattc.h:337
uint32_t bt_gattc_get_mtu(bt_handle_t connection_handle)
This function gets the MTU of this connection.
Write Long Characteristic Value or Write Long Characteristic Descriptors request. ...
Definition: bt_gattc.h:254
This structure defines the data type of the callback parameter for the event (BT_GATTC_WRITE_LONG_CHA...
Definition: bt_gattc.h:386
ATT prepare write response structure.
Definition: bt_att.h:331
ATT error response structure.
Definition: bt_att.h:146
bt_att_find_info_req_t bt_gattc_discover_charc_descriptor_req_t
Discover All Characteristic Descriptors request.
Definition: bt_gattc.h:203
Write Without Response or Signed Write Without Response request.
Definition: bt_gattc.h:236
ATT read blob request structure.
Definition: bt_att.h:254
ATT find information response structure.
Definition: bt_att.h:184
Error response.
Definition: bt_gattc.h:278
ATT read by type request structure.
Definition: bt_att.h:216
bt_status_t bt_gattc_discover_primary_service_by_uuid(bt_handle_t connection_handle, const bt_gattc_discover_primary_service_by_uuid_req_t *req)
This function discovers the primary service of the GATT Server by the UUID.
ATT find information request structure.
Definition: bt_att.h:174
bt_att_handle_value_confirmation_t bt_gattc_handle_value_confirmation_t
Handle value confirmation.
Definition: bt_gattc.h:406
ATT read request structure.
Definition: bt_att.h:235
Read Multiple Characteristic Values request.
Definition: bt_gattc.h:227
This structure defines the data type of the callback parameter for the event (BT_GATTC_FIND_INCLUDED_...
Definition: bt_gattc.h:317
Discover All Characteristics of a Service or Discover Characteristics by UUID request.
Definition: bt_gattc.h:198
bt_att_read_blob_req_t bt_gattc_read_long_charc_value_req_t
Read Long Characteristic Values or Read Long Characteristic Descriptors request.
Definition: bt_gattc.h:213
bt_status_t bt_gattc_read_long_charc(bt_handle_t connection_handle, const bt_gattc_read_long_charc_value_req_t *req)
This function reads a long characteristic value or a descriptor of the GATT Server.
Write Characteristic Value or Write Characteristic Descriptors request.
Definition: bt_gattc.h:245
This structure defines the data type of the callback parameter for the event (BT_GATTC_DISCOVER_PRIMA...
Definition: bt_gattc.h:307
bt_status_t bt_gattc_find_included_services(bt_handle_t connection_handle, const bt_gattc_find_included_services_req_t *req)
This function finds the included service on the GATT Server.
Prepare write response.
Definition: bt_gattc.h:376
bt_att_read_req_t bt_gattc_read_charc_req_t
Read Characteristic Value or Read Characteristic Descriptors request.
Definition: bt_gattc.h:208
bt_status_t bt_gattc_discover_primary_service(bt_handle_t connection_handle, const bt_gattc_discover_primary_service_req_t *req)
This function discovers the primary service of the GATT Server.
bt_uuid union.
Definition: bt_uuid.h:124
ATT find by type value response structure.
Definition: bt_att.h:205
int32_t bt_status_t
Define the status type, returned from the APIs, and defined as BT_STATUS_XXX.
Definition: bt_type.h:173
This structure defines the data type of the callback parameter for the event (BT_GATTC_EXCHANGE_MTU) ...
Definition: bt_gattc.h:287
bt_status_t bt_gattc_discover_charc(bt_handle_t connection_handle, const bt_gattc_discover_charc_req_t *req)
This function discovers all characteristics or a specific characteristic by UUID of the GATT Server...
ATT read multiple request structure.
Definition: bt_att.h:268
bt_status_t bt_gattc_send_execute_write_req(bt_handle_t connection_handle, const bt_gattc_execute_write_req_t *req)
This function sends an execute write request to the GATT Server.
This structure defines the data type of the callback parameter for the event (BT_GATTC_DISCOVER_CHARC...
Definition: bt_gattc.h:297
bt_att_read_by_type_req_t bt_gattc_read_using_charc_uuid_req_t
Read Using Characteristic UUID request.
Definition: bt_gattc.h:218
bt_gatt_handle_value_notification_t bt_gatt_handle_value_indication_t
This structure defines the data type of the callback parameter for the event (BT_GATTC_CHARC_VALUE_IN...
Definition: bt_gattc.h:401
This structure defines the data type of the callback parameter for the event (BT_GATTC_CHARC_VALUE_NO...
Definition: bt_gattc.h:396
bt_status_t bt_gattc_read_charc(bt_handle_t connection_handle, const bt_gattc_read_charc_req_t *req)
This function reads the value or the descriptor of a characteristic of the GATT Server.
bt_status_t bt_gattc_write_charc(bt_handle_t connection_handle, const bt_gattc_write_charc_req_t *req)
This function writes values or descriptors of a characteristic on the GATT Server.
bt_status_t bt_gattc_exchange_mtu(bt_handle_t connection_handle, const bt_gattc_exchange_mtu_req_t *req)
This function sends an exchange MTU request to the GATT Server.
bt_status_t bt_gattc_prepare_write_charc(bt_handle_t connection_handle, uint8_t is_reliable, uint16_t offset, const bt_gattc_prepare_write_charc_req_t *req)
This function prepares to write characteristic values to the GATT Server.
ATT read by type response structure.
Definition: bt_att.h:226
bt_status_t bt_gattc_write_without_rsp(bt_handle_t connection_handle, uint8_t is_signed, const bt_gattc_write_without_rsp_req_t *req)
This function writes characteristic values without a response from the GATT Server.
ATT prepare write request structure.
Definition: bt_att.h:320
Notification or Indication.
Definition: bt_gattc.h:268
bt_status_t bt_gattc_read_multi_charc_values(bt_handle_t connection_handle, const bt_gattc_read_multi_charc_values_req_t *req)
This function reads multiple characteristic values from the GATT Server.
This structure defines the data type of the callback parameter for the event (BT_GATTC_DISCOVER_PRIMA...
Definition: bt_gattc.h:357
bt_status_t bt_gattc_discover_charc_descriptor(bt_handle_t connection_handle, const bt_gattc_discover_charc_descriptor_req_t *req)
This function discovers characteristic descriptors.