+LEATTRIB Define Attributes for a Service
AT syntax: AT+LEATTRIB=<type>[,par1=<value1>[, .. ,parn=<valuen>]..]]
This command is used to define attributes for one or more services in the GATT server. The maximum number of services and characteristics depends on the used features. Every combination results in a different number of possible service and characteristic combinations. The maximum number of possible characteristics is limited to 20. This restriction results from the limited size of the internal definition array. If the space is completely used the command “AT+LEATTRIB=charval,…” returns “ERROR”.
The GAP and GATT services that each GATT server must expose are built-in services in the BlueMod+S and thus shall not be defined by the application!
The presence of parameters par1,..,parn depends on the value of <type>:
|
type |
par1 |
par2 |
par3 |
par4 (1) |
|
pserv
Mandatory |
uuid=<16/128bit UUID>
Mandatory
Coding: hexadecimal. |
|
|
|
|
char
Mandatory |
prop=<properties>
Mandatory
Coding: hexadecimal.
properties may have the bitmask values Read, Write Without Response, Write, Notify and Indicate set.
Note: internally the controller generates an additional Client Characteristic Configuration Descriptor (CCCD) attribute with permissions „readable and writable without authentication or authorization“ if bits Notify or Indicate are set.
|
|
|
|
|
charval
Mandatory |
uuid=<16/128bit UUID>
Mandatory
Coding: hexadecimal. |
perm=<permissions>
Mandatory
Coding: hexadecimal.
16-bit value that decodes the access permissions and authentication requirements. |
len=<length>
Mandatory
Coding: decimal.
Maximum supported length is 20 bytes. A length of 0 means a variable length of the characteristic (up to 20 bytes) |
val=<value>
Optional
Coding: hexadecimal.
Pre-defined characteristic value that will be loaded when the service set is activated. |
|
chardcccd
Optional
|
perm=<permissions>
Mandatory
Coding: hexadecimal.
This command is needed only if a CCCD shall be generated with permissions other than „readable and writable without authentication or authorization“. See note in type=char description.
CCCDs are required to be readable without authentication and required to be writable.
|
|
|
|
|
chardusrd
Optional
|
usrd=<user description>
Mandatory
Coding: UTF-8 string.
User description string.
Note: - Since Extended Properties (see type=char, parameter properties description) are not supported the remote peer may not write to this characteristic descriptor. - The number of characters is limited to 13. Internally the character sequence is terminated by a zero byte resulting in an ASCII-Z string. |
perm=<permissions>
Optional
Coding: hexadecimal.
16-bit value that decodes the access permissions and authentication requirements.
User Descriptions are required to be readable and required to be not writeable.
If this parameter is omitted the default readable without authentication or authorization applies. |
|
|
|
complete
Mandatory |
No parameter.
Used to signal that all attribute definitions have been sent to the controller.
|
|
|
|
(1) par4 supported since firmware version 2.000
The characteristic properties are coded as a hexadecimal bitmask as defined in Bluetooth Core Spec 4.0 Volume3 Part G Chapter 3.3.1.1 [4].
|
Value |
Properties |
|
02 |
Read |
|
04 |
Write without response |
|
08 |
Write |
|
10 |
Notify |
|
20 |
Indicate |
The values can be combined, for example read & notify result in 12.
The attribute permissions (parameter perm=<permissions>) are bit coded in a 16 bit hexadecimal value.
|
Bit |
Value |
Function |
|
0,1,2 |
0 1 2 3 4 |
Read not permitted Read permitted Read with authentication permitted Read with authentication and MITM protection permitted Read with authentication, LE Secure Connection and MITM protection permitted |
|
3 |
- |
Reserved |
|
4,5,6 |
0 1 2 3 4 |
Write not permitted Write permitted Write with authentication permitted Write with authentication and MITM protection permitted Write with authentication, LE Secure Connection and MITM protection permitted |
|
7..15 |
- |
Reserved |
Example: Value for read only is 0001.
The complete service/s is/are defined through repeated submissions of the AT+LEATTRIB command (see example below).
The AT+LEATTRIB commands must be submitted in a specific order:
Definition of first service:
AT+LEATTRIB=pserv, …
Definition of first characteristic of first service:
AT+LEATTRIB=char, …
… optional characteristic descriptors (AT+LEATTRIB=chardxxx) …
AT+LEATTRIB=charval, …
Definition of second characteristic of first service:
AT+LEATTRIB=char, …
… optional characteristic descriptors (AT+LEATTRIB=chardxxx) …
AT+LEATTRIB=charval, …
…
Definition of second service:
AT+LEATTRIB=pserv, …
Definition of first characteristic of second service:
AT+LEATTRIB=char, …
… optional characteristic descriptors (AT+LEATTRIB=chardxxx) …
AT+LEATTRIB=charval, …
…
…
Completion of service and characteristics definition:
AT+LEATTRIB=complete
Upon successful execution of the AT+LEATTRIB command with type=charval the device returns the data channel ID which is associated to the characteristic value.
Format: <CR><LF>0x<channel><CR><LF>
Data belonging to the characteristic value is exchanged with the AT+LESRVDATA command / LESRVDATA event.
Example:
The example below shows the Battery Service. Battery Service is a simple service which exposes the battery charging level as single characteristic value.
|
Command |
Response |
Description |
|
AT+LEATTRIB=pserv,uuid=180F
AT+LEATTRIB=char,prop=12 |
OK
OK |
Declares the properties of the battery level value |
|
AT+LEATTRIB=charval,uuid=2A19,perm=0001,len=1 |
0x20 OK |
Declares the battery level value
(one byte in the range 0,..,100). |
|
AT+LEATTRIB=complete |
OK |
Completes the service definition sequence |
+LESRVCCCDS Behavior of CCCD Value Store
AT syntax: AT+LESRVCCCDS=<value>
This command allows to define the behavior of the firmware regarding stored Client Characteristic Configuration Descriptor (CCCD) values.
|
Value |
Properties |
|
0 |
CCCD values set from bonded peer devices are not stored in non-volatile memory. After reconnect a peer device need to set the CCCD bits again to enable Notifications and Indications. |
|
1 |
CCCD values set from bonded peer devices are stored in non-volatile memory. After reconnect the GATT Server restores the security level that was required for setting the CCCD before sending Notifications and Indications. |