Set up Bluez part
retrieve latest bluez code, configure it with enable-attrib, and compile it
# git clone git://git.kernel.org/pub/scm/bluetooth/bluez.git
# cd bluez
# autoreconf -vifs
# ./configure --prefix=/usr --mandir=/usr/share/man \
--sysconfdir=/etc --localstatedir=/var --libexecdir=/lib --enable-attrib
# make && sudo make install
modify main.conf, enable LE and attribute-server
diff --git a/src/main.conf b/src/main.conf
index c03f135..121ee9b 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -58,9 +58,9 @@ DebugKeys = false
# Enable Low Energy support if the dongle supports. Default is false.
# Enable/Disable interleave discovery and attribute server over LE.
-EnableLE = false
+EnableLE = true
# Enable the GATT Attribute Server. Default is false, because it is only
# useful for testing. Attribute server is not enabled over LE if EnableLE
# is false.
-AttributeServer = false
+AttributeServer = true
start bluetooth daemon in foreground with debug information
# sudo /usr/sbin/bluetoothd -n -d
Play with gatttool
Since we configured Bluez with enable-attrib, we will start an attribute-server from running bluetooth daemon. It would add some attribute records for GATT service, and it's created from attrib/example.c file. Also, we will add a GAP service like below.
erin@sundays:~/project/bluez$ sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service Name: Generic Attribute Profile
Service Provider: BlueZ
Service RecHandle: 0x10000
Service Class ID List:
"Generic Attribute" (0x1801)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 31
"ATT" (0x1801)
uint16: 0x1
uint16: 0xffff
Profile Descriptor List:
"Generic Attribute" (0x1801)
Version: 0x0100
Below GATT features are from BT 4.0 core spec Volume 3 Part G.

Primary Service Discovery
This procedure is used by a client to discover primary services on a server. Once the primary services are discovered, additional information about the primary services can be accessed using other procedures, including characteristic discovery and relationship discovery to find other related primary and secondary services.
a. Discover all primary services ==> "Read By Group Type Request"
b. Discover primary service by service UUID ==> "Find By Type Value Request"


gatt_discover_primary(attrib, opt_start, opt_end, opt_uuid, primary_by_uuid_cb, attrib);
erin@sundays:~$ sudo gatttool -b 78:DD:08:A3:A7:52 --primary --psm=31 --mtu=48
attr handle = 0x0001, end grp handle = 0x0006, attr value (UUID) = 1800
attr handle = 0x0010, end grp handle = 0x0012, attr value (UUID) = 1801
attr handle = 0x0100, end grp handle = 0x0111, attr value (UUID) = a002
attr handle = 0x0200, end grp handle = 0x0214, attr value (UUID) = a004
attr handle = 0x0680, end grp handle = 0x0685, attr value (UUID) = 4f0ac096-35d4-4911-9631-dea8dc74eefe
erin@autumn:~/project/bluez$ gatttool -b 78:DD:08:A3:A7:52 --primary --uuid=1801
Starting handle: 0010 Ending handle: 0012
erin@autumn:~/project/bluez$ gatttool -b 78:DD:08:A3:A7:52 --primary --uuid=1800
Starting handle: 0001 Ending handle: 0006
Characteristic Discovery
This procedure is used by a client to discover service characteristics on a server. Once the characteristics are discovered additional information about the characteristics can be discovered or accessed using other procedures.
a. Discover all characteristics of a Service ==> "Read By Type Request"
b. Discover characteristics by UUID ==> "Read By Type Request"


gatt_discover_char(attrib, opt_start, opt_end, char_discovered_cb, char_data);
gatt_read_char_by_uuid(attrib, start, end, &uuid, func, user_data);
erin@sundays:~$ sudo gatttool -b 78:DD:08:A3:A7:52 --characteristics --psm=31 --mtu=48
handle = 0x0004, char properties = 0x02, char value handle = 0x0006, uuid = 2a00
handle = 0x0011, char properties = 0x02, char value handle = 0x0012, uuid = a001
handle = 0x0106, char properties = 0x02, char value handle = 0x0110, uuid = a003
handle = 0x0203, char properties = 0x02, char value handle = 0x0204, uuid = a006
handle = 0x0210, char properties = 0x02, char value handle = 0x0212, uuid = a009
handle = 0x0501, char properties = 0x02, char value handle = 0x0502, uuid = a00c
handle = 0x0503, char properties = 0x02, char value handle = 0x0504, uuid = a00d
handle = 0x0506, char properties = 0x02, char value handle = 0x0507, uuid = a00c
handle = 0x0508, char properties = 0x02, char value handle = 0x0509, uuid = a00d
handle = 0x0560, char properties = 0x02, char value handle = 0x0568, uuid = a00f
handle = 0x0682, char properties = 0x02, char value handle = 0x0683, uuid = 8088f218-902c-450b-b6c4-62891e8c25e9
erin@autumn:~/project/bluez$ gatttool -b 78:DD:08:A3:A7:52 --characteristics --start=0x0001 --end=0x0100
handle = 0x0004, char properties = 0x02, char value handle = 0x0006, uuid = 2a00
handle = 0x0011, char properties = 0x02, char value handle = 0x0012, uuid = a001
Characteristic Descriptor Discovery
This procedure is used by a client to discover characteristic descriptors of a characteristic. Once the characteristic descriptors are discovered additional information about the characteristic descriptors can be accessed using other procedures.
a. Discover All Characteristic Descriptors ==> "Find Information Request"

gatt_find_info(attrib, opt_start, opt_end, char_desc_cb, NULL);
erin@sundays:~$ sudo gatttool -b 78:DD:08:A3:A7:52 --char-desc --psm=31
handle = 0x0001, uuid = 2800
handle = 0x0004, uuid = 2803
handle = 0x0006, uuid = 2a00
handle = 0x0010, uuid = 2800
handle = 0x0011, uuid = 2803
erin@autumn:~/project/bluez$ gatttool -b 78:DD:08:A3:A7:52 --char-desc --start=0x0001 --end=0x0010
handle = 0x0001, uuid = 2800
handle = 0x0004, uuid = 2803
handle = 0x0006, uuid = 2a00
handle = 0x0010, uuid = 2800
erin@autumn:~/project/bluez$ gatttool -b 78:DD:08:A3:A7:52 --char-desc --start=0x0001 --end=0x0005
handle = 0x0001, uuid = 2800
handle = 0x0004, uuid = 2803
Characteristic Value Read
This procedure is used to read a Characteristic Value from a server.
a. Read characteristic value
b. Read using characteristic UUID
c. Read long characteristic values (not implement)
d. Read multiple characteristic values (not implement)




gatt_read_char(attrib, opt_handle, char_read_cb, attrib);
==> g_attrib_send(attrib, ATT_OP_READ_REQ, pdu, plen, func, user_data, NULL);
gatt_read_char_by_uuid(attrib, opt_start, opt_end, opt_uuid, char_read_by_uuid_cb, char_data);
==> g_attrib_send(attrib, ATT_OP_READ_BY_TYPE_REQ, pdu, plen, func, user_data, NULL);
erin@sundays:~$ sudo gatttool -b 78:DD:08:A3:A7:52 --char-read --uuid=2800
handle: 0x0001 value: 00 18
handle: 0x0010 value: 01 18
handle: 0x0100 value: 02 a0
handle: 0x0200 value: 04 a0
handle: 0x0680 value: 4f 0a c0 96 35 d4 49 11 96 31 de a8 dc 74 ee fe
erin@sundays:~$ sudo gatttool -b 78:DD:08:A3:A7:52 --char-read --handle=0x0001
Characteristic value/descriptor: 00 18
erin@autumn:~/project/bluez$ gatttool -b 78:DD:08:A3:A7:52 --char-read --uuid=a00d
handle: 0x0504 value: 32 33 37 34 39 35 2d 33 32 38 32 2d 41
handle: 0x0509 value: 31 31 32 36 37 2d 32 33 32 37 41 30 30 32 33 39
Characteristic value write
This procedure is used to write a Characteristic Value to a server.
a. Write without response
b. Signed write without response (not check yet)
c. Write characteristic value
d. Write long charcharacteristic values (not check yet)
e. Reliable writes (not check yet)


erin@sundays:~$ gatttool -b 78:DD:08:A3:A7:52 --char-write --psm=31 --mtu=48 --handle=0x0001 --value=0x0011
erin@sundays:~$ gatttool -b 78:DD:08:A3:A7:52 --char-read --psm=31 --mtu=48 --handle=0x0001
Characteristic value/descriptor: 00 00 11
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.