35 #ifndef __BT_GATTS_H__ 36 #define __BT_GATTS_H__ 167 #define BT_GATTS_REC_PERM_READ_SHIFT(mask) ((mask)<<4) 168 #define BT_GATTS_REC_PERM_WRITE_SHIFT(mask) ((mask)<<0) 169 #define BT_GATTS_REC_PERM_READ_MASK 0xf0 170 #define BT_GATTS_REC_PERM_READABLE 0x80 171 #define BT_GATTS_REC_PERM_READABLE_ENCRYPTION (BT_GATTS_REC_PERM_READABLE | (BT_GATTS_REC_PERM_READ_SHIFT(BT_GAP_LE_SECURITY_ENCRYPTION_MASK))) 172 #define BT_GATTS_REC_PERM_READABLE_AUTHENTICATION (BT_GATTS_REC_PERM_READABLE | (BT_GATTS_REC_PERM_READ_SHIFT(BT_GAP_LE_SECURITY_AUTHENTICATION_MASK))) 173 #define BT_GATTS_REC_PERM_READABLE_AUTHORIZATION (BT_GATTS_REC_PERM_READABLE | (BT_GATTS_REC_PERM_READ_SHIFT(BT_GAP_LE_SECURITY_AUTHORIZATION_MASK))) 174 #define BT_GATTS_IS_READABLE(perm) (((perm) & BT_GATTS_REC_PERM_READ_MASK)> 0) 175 #define BT_GATTS_REC_PERM_WRITE_MASK 0x0f 176 #define BT_GATTS_REC_PERM_WRITABLE 0x08 177 #define BT_GATTS_REC_PERM_WRITABLE_ENCRYPTION (BT_GATTS_REC_PERM_WRITABLE | (BT_GATTS_REC_PERM_WRITE_SHIFT(BT_GAP_LE_SECURITY_ENCRYPTION_MASK))) 178 #define BT_GATTS_REC_PERM_WRITABLE_AUTHENTICATION (BT_GATTS_REC_PERM_WRITABLE | (BT_GATTS_REC_PERM_WRITE_SHIFT(BT_GAP_LE_SECURITY_AUTHENTICATION_MASK))) 179 #define BT_GATTS_REC_PERM_WRITABLE_AUTHORIZATION (BT_GATTS_REC_PERM_WRITABLE | (BT_GATTS_REC_PERM_WRITE_SHIFT(BT_GAP_LE_SECURITY_AUTHORIZATION_MASK))) 180 #define BT_GATTS_IS_WRITABLE(perm) (((perm) & BT_GATTS_REC_PERM_WRITE_MASK)> 0) 184 #define BT_GATTS_CALLBACK_READ 0 185 #define BT_GATTS_CALLBACK_WRITE 1 186 #define BT_GATTS_CALLBACK_PREPARE_WRITE 2 188 #define BT_GATTS_CALLBACK_EXECUTE_WRITE_CANCEL 3 189 #define BT_GATTS_CALLBACK_EXECUTE_WRITE_WRITE 4 193 #define BT_GATTS_EXECUTE_WRITE_RLT_SET(handle, status) (((handle)<<8)|(status)) 194 #define BT_GATTS_EXECUTE_WRITE_RLT_GET_HANDLE(s) (((s)>>8)&0xFFFF) 195 #define BT_GATTS_EXECUTE_WRITE_RLT_GET_STATUS(s) ((s)&0xFF) 199 typedef uint8_t bt_atts_rec_perm_t; 266 uint16_t attribute_handle;
267 uint16_t connection_handle;
275 uint16_t service_handle;
276 uint16_t end_group_handle;
308 uint8_t value_uint_8;
309 uint16_t value_uint_16;
310 uint32_t value_uint_32;
312 int16_t value_int_16;
313 int32_t value_int_32;
327 uint16_t description;
464 uint16_t handle_list[8];
481 #define BT_GATTS_NEW_PRIMARY_SERVICE_16(name, uuid16_value) \ 482 static const bt_gatts_primary_service_16_t name = { \ 483 .rec_hdr.uuid_ptr = &BT_GATT_UUID_PRIMARY_SERVICE, \ 484 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 485 .rec_hdr.value_len = 2, \ 486 .uuid16 = uuid16_value \ 494 #define BT_GATTS_NEW_PRIMARY_SERVICE_128(name, uuid128_value) \ 495 static const bt_gatts_primary_service_128_t name = { \ 496 .rec_hdr.uuid_ptr = &BT_GATT_UUID_PRIMARY_SERVICE, \ 497 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 498 .rec_hdr.value_len = 16, \ 499 .uuid128 = uuid128_value \ 507 #define BT_GATTS_NEW_SECONDARY_SERVICE_16(name, uuid16_value) \ 508 static const bt_gatts_secondary_service_16_t name = { \ 509 .rec_hdr.uuid_ptr = &BT_GATT_UUID_SECONDARY_SERVICE, \ 510 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 511 .rec_hdr.value_len = 2, \ 512 .uuid16 = uuid16_value \ 520 #define BT_GATTS_NEW_SECONDARY_SERVICE_128(name, uuid128_value) \ 521 static const bt_gatts_secondary_service_128_t name = { \ 522 .rec_hdr.uuid_ptr = &BT_GATT_UUID_SECONDARY_SERVICE, \ 523 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 524 .rec_hdr.value_len = 16, \ 525 .uuid128 = uuid128_value \ 535 #define BT_GATTS_NEW_INCLUDED_SERVICE_16(name, s_handle, e_handle, uuid) \ 536 static const bt_gatts_included_service_t name = { \ 537 .rec_hdr.uuid_ptr = &BT_GATT_UUID_INCLUDED_SERVICE, \ 538 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 539 .rec_hdr.value_len = 6, \ 540 .value.service_handle = s_handle, \ 541 .value.end_group_handle = e_handle, \ 542 .value.uuid16 = uuid \ 551 #define BT_GATTS_NEW_INCLUDED_SERVICE_128(name, s_handle, e_handle) \ 552 static const bt_gatts_included_service_t name = { \ 553 .rec_hdr.uuid_ptr = &BT_GATT_UUID_INCLUDED_SERVICE, \ 554 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 555 .rec_hdr.value_len = 4, \ 556 .value.service_handle = s_handle, \ 557 .value.end_group_handle = e_handle, \ 558 .value.uuid16 =0x0000 \ 568 #define BT_GATTS_NEW_CHARC_16(name, prop, _handle, uuid) \ 569 static const bt_gatts_characteristic_16_t name = { \ 570 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC, \ 571 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 572 .rec_hdr.value_len = 5, \ 573 .value.properties = prop, \ 574 .value.handle = _handle, \ 575 .value.uuid16 = uuid \ 585 #define BT_GATTS_NEW_CHARC_16_WRITABLE(name, prop, _handle, uuid) \ 586 static bt_gatts_characteristic_16_t name = { \ 587 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC, \ 588 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 589 .rec_hdr.value_len = 5, \ 590 .value.properties = prop, \ 591 .value.handle = _handle, \ 592 .value.uuid16 = uuid \ 602 #define BT_GATTS_NEW_CHARC_128(name, prop, _handle, uuid) \ 603 static const bt_gatts_characteristic_128_t name = { \ 604 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC, \ 605 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 606 .rec_hdr.value_len = 19, \ 607 .value.properties = prop, \ 608 .value.handle = _handle, \ 609 .value.uuid128 = uuid \ 619 #define BT_GATTS_NEW_CHARC_VALUE_UINT8(name, uuid, _perm, _value) \ 620 static const bt_gatts_characteristic_t name = { \ 621 .rec_hdr.uuid_ptr = &uuid, \ 622 .rec_hdr.perm = _perm, \ 623 .rec_hdr.value_len = 1, \ 624 .value.value_uint_8 = _value \ 634 #define BT_GATTS_NEW_CHARC_VALUE_UINT8_WRITABLE(name, uuid, _perm, _value) \ 635 static bt_gatts_characteristic_t name = { \ 636 .rec_hdr.uuid_ptr = &uuid, \ 637 .rec_hdr.perm = _perm, \ 638 .rec_hdr.value_len = 1, \ 639 .value.value_uint_8 = _value \ 649 #define BT_GATTS_NEW_CHARC_VALUE_UINT16(name, uuid, _perm, _value) \ 650 static const bt_gatts_characteristic_t name = { \ 651 .rec_hdr.uuid_ptr = &uuid, \ 652 .rec_hdr.perm = _perm, \ 653 .rec_hdr.value_len = 2, \ 654 .value.value_uint_16 = _value \ 664 #define BT_GATTS_NEW_CHARC_VALUE_UINT32(name, uuid, _perm, _value) \ 665 static const bt_gatts_characteristic_t name = { \ 666 .rec_hdr.uuid_ptr = &uuid, \ 667 .rec_hdr.perm = _perm, \ 668 .rec_hdr.value_len = 4, \ 669 .value.value_uint_32 = _value \ 679 #define BT_GATTS_NEW_CHARC_VALUE_UINT32_WRITABLE(name, uuid, _perm, _value) \ 680 static bt_gatts_characteristic_t name = { \ 681 .rec_hdr.uuid_ptr = &uuid, \ 682 .rec_hdr.perm = _perm, \ 683 .rec_hdr.value_len = 4, \ 684 .value.value_uint_32 = _value \ 694 #define BT_GATTS_NEW_CHARC_VALUE_INT8(name, uuid, _perm, _value) \ 695 static const bt_gatts_characteristic_t name = { \ 696 .rec_hdr.uuid_ptr = &uuid, \ 697 .rec_hdr.perm = _perm, \ 698 .rec_hdr.value_len = 1, \ 699 .value.value_int_8 = _value \ 709 #define BT_GATTS_NEW_CHARC_VALUE_INT16(name, uuid, _perm, _value) \ 710 static const bt_gatts_characteristic_t name = { \ 711 .rec_hdr.uuid_ptr = &uuid, \ 712 .rec_hdr.perm = _perm, \ 713 .rec_hdr.value_len = 2, \ 714 .value.value_int_16 = _value \ 724 #define BT_GATTS_NEW_CHARC_VALUE_INT32(name, uuid, _perm, _value) \ 725 static const bt_gatts_characteristic_t name = { \ 726 .rec_hdr.uuid_ptr = &uuid, \ 727 .rec_hdr.perm = _perm, \ 728 .rec_hdr.value_len = 4, \ 729 .value.value_int_32 = _value \ 739 #define BT_GATTS_NEW_CHARC_VALUE_CALLBACK(name, uuid, _perm, call) \ 740 static const bt_gatts_characteristic_t name = { \ 741 .rec_hdr.uuid_ptr = &uuid, \ 742 .rec_hdr.perm = _perm, \ 743 .rec_hdr.value_len = 0, \ 744 .value.callback = call \ 754 #define BT_GATTS_NEW_CHARC_VALUE_CALLBACK_WRITABLE(name, uuid, _perm, call) \ 755 static bt_gatts_characteristic_t name = { \ 756 .rec_hdr.uuid_ptr = &uuid, \ 757 .rec_hdr.perm = _perm, \ 758 .rec_hdr.value_len = 0, \ 759 .value.callback = call \ 771 #define BT_GATTS_NEW_CHARC_VALUE_STR16(name, uuid, _perm, val_len, val_name) \ 772 static const bt_gatts_characteristic_str16_t name = { \ 773 .rec_hdr.uuid_ptr = &uuid, \ 774 .rec_hdr.perm = _perm, \ 775 .rec_hdr.value_len = val_len, \ 786 #define BT_GATTS_NEW_CHARC_VALUE_HALFW8_WRITABLE(name, uuid, _perm, val_len,...) \ 787 static bt_gatts_characteristic_halfw8_t name = { \ 788 .rec_hdr.uuid_ptr = &uuid, \ 789 .rec_hdr.perm = _perm, \ 790 .rec_hdr.value_len = val_len, \ 791 .halfw = {__VA_ARGS__} \ 799 #define BT_GATTS_NEW_CHARC_EXTENDED_PROPERTIES(name, ext_prop) \ 800 static const bt_gatts_characteristic_extended_properties_t name = { \ 801 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC_EXTENDED_PROPERTIES, \ 802 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 803 .rec_hdr.value_len = 2, \ 804 .extended_properties = ext_prop \ 815 #define BT_GATTS_NEW_CHARC_USER_DESCRIPTION_STR16(name, _perm, val_len, val_name) \ 816 static const bt_gatts_characteristic_user_description_str16_t name = { \ 817 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC_USER_DESCRIPTION, \ 818 .rec_hdr.perm = _perm, \ 819 .rec_hdr.value_len = val_len, \ 829 #define BT_GATTS_NEW_CHARC_USER_DESCRIPTION(name, _perm, _callback) \ 830 static const bt_gatts_characteristic_user_description_t name = { \ 831 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC_USER_DESCRIPTION, \ 832 .rec_hdr.perm = _perm, \ 833 .rec_hdr.value_len = 0, \ 834 .callback = _callback \ 843 #define BT_GATTS_NEW_CLIENT_CHARC_CONFIG(name, _perm, _callback) \ 844 static const bt_gatts_client_characteristic_config_t name = { \ 845 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CLIENT_CHARC_CONFIG, \ 846 .rec_hdr.perm = _perm, \ 847 .rec_hdr.value_len = 0, \ 848 .callback = _callback \ 857 #define BT_GATTS_NEW_SERVER_CHARC_CONFIG(name, _perm, _callback) \ 858 static const bt_gatts_server_characteristic_config_t name = { \ 859 .rec_hdr.uuid_ptr = &BT_GATT_UUID_SERVER_CHARC_CONFIG, \ 860 .rec_hdr.perm = _perm, \ 861 .rec_hdr.value_len = 0, \ 862 .callback = _callback \ 874 #define BT_GATTS_NEW_CHARC_FORMAT(name, _format, _exponent, _unit, _name_space, _description) \ 875 static const bt_gatts_characteristic_format_t name = { \ 876 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC_FORMAT, \ 877 .rec_hdr.perm = BT_GATTS_REC_PERM_READABLE, \ 878 .rec_hdr.value_len = 7, \ 879 .value.format = _format, \ 880 .value.exponent = _exponent, \ 881 .value.unit = _unit, \ 882 .value.name_space = _name_space, \ 883 .value.description = _description \ 893 #define BT_GATTS_NEW_CHARC_AGGREGATE_FORMAT_H8(name, _perm, val_len,...) \ 894 static const bt_gatts_characteristic_aggregate_format_t name = { \ 895 .rec_hdr.uuid_ptr = &BT_GATT_UUID_CHARC_AGGREGATE_FORMAT, \ 896 .rec_hdr.perm = _perm, \ 897 .rec_hdr.value_len = val_len, \ 898 .handle_list = {__VA_ARGS__} \ 16-bit primary service structure of the GATTS.
Definition: bt_gatts.h:333
const bt_uuid_t BT_GATT_UUID_INCLUDED_SERVICE
UUID for GATT included service.
uint16_t handle
The connection handle.
Definition: bt_gatts.h:256
uint16_t extended_properties
The extended properties of the characteristic descriptor.
Definition: bt_gatts.h:418
Characteristic structure of the GATTS.
Definition: bt_gatts.h:388
const bt_uuid_t * uuid_ptr
A pointer to the UUID of attribute type.
Definition: bt_gatts.h:236
bt_gatts_characteristic_value_t value
The value of the characteristic.
Definition: bt_gatts.h:391
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:440
const bt_gatts_service_t ** bt_get_gatt_server(void)
This function is a callback API called by the GATTS to get the application's GATTS database...
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:381
uint16_t uuid16
The 16-bit primary service UUID.
Definition: bt_gatts.h:336
128-bit primary service structure of the GATTS.
Definition: bt_gatts.h:347
uint16_t bt_handle_t
Define the connection handle type.
Definition: bt_type.h:85
const bt_uuid_t BT_GATT_UUID_CHARC_FORMAT
UUID for GATT characteristic presentation format.
Record structure of the GATTS.
Definition: bt_gatts.h:235
Client characteristic configuration descriptor structure of the GATTS.
Definition: bt_gatts.h:438
Characteristic extended properties descriptor structure of the GATTS.
Definition: bt_gatts.h:415
const bt_uuid_t BT_GATT_UUID_CHARC
UUID for GATT characteristic.
bt_atts_rec_perm_t perm
The read or write permission and security requirement of the attribute, BT_GATTS_REC_PERM_READABLE, BT_GATTS_REC_PERM_WRITABLE.
Definition: bt_gatts.h:237
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:417
bt_status_t bt_gatts_send_charc_value_notification_indication(bt_handle_t connection_handle, bt_gattc_charc_value_notification_indication_t *req)
This function sends a characteristic value notification or indication.
uint8_t bt_atts_rec_perm_t
Bt_atts_rec_perm_t is a member of bt_gatts_service_rec_t.
Definition: bt_gatts.h:199
const bt_uuid_t BT_GATT_UUID_PRIMARY_SERVICE
UUID for GATT primary service.
Request the GATTS to do the execute write.
Definition: bt_gatts.h:255
Characteristic UUID16 value structure of the GATTS.
Definition: bt_gatts.h:288
const bt_uuid_t BT_GATT_UUID_CHARC_AGGREGATE_FORMAT
UUID for GATT characteristic aggregate format.
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:363
bt_uuid_t uuid128
The 128-bit primary service UUID.
Definition: bt_gatts.h:350
uint8_t value_len
The length of the attribute value.
Definition: bt_gatts.h:238
bt_gatts_characteristic_uuid16_value_t value
The value of the characteristic.
Definition: bt_gatts.h:373
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:390
uint16_t ending_handle
The service's ending handle.
Definition: bt_gatts.h:247
Included service structure of the GATTS.
Definition: bt_gatts.h:361
const bt_uuid_t BT_GATT_UUID_CHARC_USER_DESCRIPTION
UUID for GATT characteristic user description.
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:408
bt_gatts_included_service_value_t value
The value of the included service.
Definition: bt_gatts.h:364
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:399
Characteristic value structure of the GATTS.
Definition: bt_gatts.h:316
bt_gatts_rec_callback_t callback
When the rec_hdr.value_len is 0, the callback should handle the read and write request.
Definition: bt_gatts.h:427
bt_uuid union.
Definition: bt_uuid.h:124
int32_t bt_status_t
Define the status type, returned from the APIs, and defined as BT_STATUS_XXX.
Definition: bt_type.h:173
bt_gatts_characteristic_str16_t bt_gatts_characteristic_user_description_str16_t
Characteristic user description str16 descriptor structure of the GATTS.
Definition: bt_gatts.h:433
uint8_t flag
The flag indicating whether to execute write operation.
Definition: bt_gatts.h:257
Included service value structure of the GATTS.
Definition: bt_gatts.h:278
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:426
Characteristic user description descriptor structure of the GATTS.
Definition: bt_gatts.h:424
uint8_t required_encryption_key_size
The required encryption key size.
Definition: bt_gatts.h:248
bt_gatts_characteristic_uuid128_value_t value
The value of the characteristic.
Definition: bt_gatts.h:382
Characteristic UUID128 value structure of the GATTS.
Definition: bt_gatts.h:298
16-bit UUID characteristic structure of the GATTS.
Definition: bt_gatts.h:370
uint16_t starting_handle
The service's starting handle.
Definition: bt_gatts.h:246
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:372
const bt_uuid_t BT_GATT_UUID_SECONDARY_SERVICE
UUID for GATT secondary primary service.
const bt_uuid_t BT_GATT_UUID_CLIENT_CHARC_CONFIG
UUID for GATT client characteristic configuration.
bt_gatts_client_characteristic_config_t bt_gatts_server_characteristic_config_t
Server characteristic configuration descriptor structure of the GATTS.
Definition: bt_gatts.h:447
bt_status_t bt_gatts_set_max_mtu(uint16_t max_mtu)
This function sets the maximum MTU supported by the application.
utf-16 characteristic structure of the GATTS.
Definition: bt_gatts.h:397
const bt_uuid_t BT_GATT_UUID_CHARC_EXTENDED_PROPERTIES
UUID for GATT characteristic extended properties.
128-bit UUID characteristic structure of the GATTS.
Definition: bt_gatts.h:379
bt_status_t bt_gatts_get_authorization_check_result(bt_gatts_authorization_check_req_t *req)
This user defined API, invoked by the GATTS process, should be implemented by the application...
bt_gatts_rec_callback_t callback
If the rec_hdr.value_len is 0, the callback should handle the read and write request.
Definition: bt_gatts.h:441
bt_gatts_primary_service_128_t bt_gatts_secondary_service_128_t
128-bit secondary service structure of the GATTS.
Definition: bt_gatts.h:356
bt_status_t bt_gatts_get_execute_write_result(bt_gatts_execute_write_req_t *req)
This user defined API, invoked by the GATTS process, should be implemented by the application...
Notification or Indication.
Definition: bt_gattc.h:268
uint32_t(* bt_gatts_rec_callback_t)(const uint8_t rw, uint16_t handle, void *data, uint16_t size, uint16_t offset)
This function is the record's callback called by the GATTS to read or write the record's attribute va...
Definition: bt_gatts.h:226
const bt_uuid_t BT_GATT_UUID_SERVER_CHARC_CONFIG
UUID for GATT server characteristic configuration.
const bt_gatts_service_rec_t ** records
A pointer to the records in the service.
Definition: bt_gatts.h:249
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:349
Service structure of the GATTS.
Definition: bt_gatts.h:245
bt_gatts_service_rec_t rec_hdr
The record, which is the basic element of a service or characteristic.
Definition: bt_gatts.h:335
Half word characteristic structure of the GATTS.
Definition: bt_gatts.h:406
Request the GATTS to do an authorization check.
Definition: bt_gatts.h:268
bt_gatts_primary_service_16_t bt_gatts_secondary_service_16_t
16-bit secondary service structure of the GATTS.
Definition: bt_gatts.h:342