This section introduces the GATT server's database including terms and acronyms, supported features, details on how to use this driver, GATT server's function groups, enums, structures and functions.
More...
This section introduces the GATT server's database including terms and acronyms, supported features, details on how to use this driver, GATT server's function groups, enums, structures and functions.
GATT server's database is divided into three levels, from the top to the bottom, the server, the services and the records. A server can have more than one service. A service can have more than one record with a type of bt_gatts_service_rec_t.
Terms and Acronyms
| Terms | Details |
| GATTS | GATT Server, is the device that accepts incoming commands and requests from the GATT client. |
| ACL | Asynchronous Connectionless Link. For more information, please refer to B. A. Forouzan, Data Communications and Networking, Fourth Edition. Wireless LANs, Chapter 14, p. 439, McGraw-Hill Professional, 2007. |
| MTU | Maximum Transmission Unit, specifies the maximum size of a packet to send. |
How to use this module
GATTS is composed of bt_gatts_service_rec_t.
In this example, a server is created with two services bt_if_gap_service and bt_if_gatt_service.
- bt_if_gap_service has 4 records.
- bt_if_gatt_service has 5 records.
| server | service | handle | record |
| bt_if_gatt_server | bt_if_gap_service | 0x0001 | bt_if_gap_primary_service |
| | 0x0002 | bt_if_gap_included_manufacturer_service |
| | 0x0003 | bt_if_gap_char4_dev_name |
| | 0x0004 | bt_if_gap_dev_name |
| bt_if_gatt_service | 0x0011 | bt_if_gatt_primary_service |
| | 0x0012 | bt_if_gatt_char4_service_changed |
| | 0x0013 | bt_if_gatt_service_changed |
| | 0x0014 | bt_if_gatt_client_config |
| | 0x0015 | bt_if_gatt_server_config |
Sample code
- Step 1. Create a GAP service with the bt_if_gap_service and related records.
- Each record is placed in an array of bt_if_gap_service_rec.
- The value of the starting_handle is assigned to the first record, bt_if_gap_primary_service.
- The value of the ending_handle is assigned to the last record, bt_if_gap_dev_name.
- The handles of the records between the first and the last are arranged sequentially.
- (ending_handle - starting_handle + 1) should be equal to the number of records.
- required_encryption_key_size specifies the encryption key size required by this service. If the record's permission was set with BT_GATTS_REC_PERM_READABLE_ENCRYPTION or BT_GATTS_REC_PERM_WRITABLE_ENCRYPTION, GATTS will check if the channel is encrypted and the encryption key size is greater than or equal to required_encryption_key_size.
};
.ending_handle = 0x0004,
.required_encryption_key_size = 7,
.records = bt_if_gap_service_rec
};
- Step 2. Create a GATT service with the bt_if_gatt_service and related records.
0x2, 0x0001050F);
bt_if_gatt_client_config_callback);
bt_if_gatt_server_config_callback);
};
.ending_handle = 0x0015,
.required_encryption_key_size = 9,
.records = bt_if_gatt_service_rec
};
- Step 3. Create a bt_if_gatt_server and collect all services.
- The server provides all services to GATTS using bt_get_gatt_server().
&bt_if_gap_service,
&bt_if_gatt_service_ro,
NULL
};
|
| | Define |
| | This section defines the macros for the GATTS.
|
| |
| | Struct |
| | This section defines the basic data structures for the GATTS.
|
| |
Bt_atts_rec_perm_t is a member of bt_gatts_service_rec_t.
It is used to store the record's read or write security permission.
| typedef 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 value.
If GATTS calls with BT_GATTS_CALLBACK_READ and with the size of 0, it is a request to query the length of the attribute value.
- Parameters
-
- Returns
-
This user defined API, invoked by the GATTS process, should be implemented by the application.
It is used to ask user whether to give authorization for specified attribute handle.
- Parameters
-
| [in] | req | is the GATT authorization request to be checked by the application. |
- Returns
- If application accepts peer access to this attribute, the returned value is BT_STATUS_SUCCESS; otherwise the returned value is BT_STATUS_UNSUPPORTED.
This user defined API, invoked by the GATTS process, should be implemented by the application.
It is used to execute the write request and check whether the execution is successful.
- Parameters
-
| [in] | req | is the request to the GATTS to execute the write request. |
- Returns
- If the write request was executed successfully, the returned value is BT_STATUS_SUCCESS; otherwise the returned value is BT_ATT_ERRCODE_XXXX.
This function sets the maximum MTU supported by the application.
This value will be used in GATTS MTU exchange response and GATTC MTU exchange request or other BT_STATUS_XXX.
- Parameters
-
| [in] | max_mtu | is the maximum MTU size in the range from 23 to 512 bytes. |
- Returns
- If the value is accepted, the returned value is BT_STATUS_SUCCESS; otherwise the returned value is BT_STATUS_FAIL.
This function is a callback API called by the GATTS to get the application's GATTS database.
- Returns
- The application's GATTS database or null, if application does not provide GATTS database.
UUID for GATT characteristic.
| const bt_uuid_t BT_GATT_UUID_CHARC_AGGREGATE_FORMAT |
UUID for GATT characteristic aggregate format.
| const bt_uuid_t BT_GATT_UUID_CHARC_EXTENDED_PROPERTIES |
UUID for GATT characteristic extended properties.
UUID for GATT characteristic presentation format.
| const bt_uuid_t BT_GATT_UUID_CHARC_USER_DESCRIPTION |
UUID for GATT characteristic user description.
| const bt_uuid_t BT_GATT_UUID_CLIENT_CHARC_CONFIG |
UUID for GATT client characteristic configuration.
| const bt_uuid_t BT_GATT_UUID_INCLUDED_SERVICE |
UUID for GATT included service.
UUID for GATT primary service.
| const bt_uuid_t BT_GATT_UUID_SECONDARY_SERVICE |
UUID for GATT secondary primary service.
| const bt_uuid_t BT_GATT_UUID_SERVER_CHARC_CONFIG |
UUID for GATT server characteristic configuration.