Commit Graph

53 Commits

Author SHA1 Message Date
Johan Hedberg 939544b75d Bluetooth: Move logging helpers to a dedicated header file
To make it clearer that these helpers are intended only for
Bluetooth-subsystem internal code, move them to a separate file.

Change-Id: Iea64780f5c61c1c96e12c9df378676bc49498fe4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Luiz Augusto von Dentz 801c09757e Bluetooth: Add support for ATT Read Multiple
This adds parsing for ATT Read Multiple Request and Response:

> ACL Data RX: Handle 3585 flags 0x02 dlen 11
      ATT: Read Multiple Request (0x0e) len 6
        Handle: 0x0001
        Handle: 0x0002
        Handle: 0x0003
< ACL Data TX: Handle 3585 flags 0x00 dlen 27
      ATT: Read Multiple Response (0x0f) len 22
        00 18 02 03 00 00 2a 54 65 73 74 20 70 65 72 69  ......*Test peri
        70 68 65 72 61 6c                                pheral

Change-Id: I08efe2b73342423634c156f95baa2bba84bd50a9
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 651e9a4b2e Bluetooth: Rename conn.h to conn_internal.h
We'll have a public conn.h header file soon, so to avoid confusion
rename the existing conn.h to conn_internal.h.

Change-Id: I5e5c89ec184a0a2de63e244b034c55a3d97af9dc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Szymon Janc b47d14a273 Bluetooth: Fix NULL pointer dereference in flush_cb
conn was never set in struct flush_data passed to flush_cb.

Change-Id: I2a16479bf7660a96f705d1194245da02ee6eeff5
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 14ff92cea0 Bluetooth: Handle ATT execute write request
This introduce a new callback called flush to bt_gatt_attr to indicate
when and attribute can cache data, the data is automatically flushed if
regular write request happens and in case of prepare write it checks if
flush is supported otherwise return an error, then upon receiving an
execute write it perform flush over the entire database and respond
with result:

< ACL Data TX: Handle 42 flags 0x00 dlen 6
      ATT: Execute Write Request (0x18) len 1
        Flags: Immediately write all pending values (0x01)
> ACL Data RX: Handle 42 flags 0x02 dlen 5
      ATT: Execute Write Response (0x19) len 0

Change-Id: I2c47f962858b8a741bf40509a648fe2cd6755691
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 186b133028 Bluetooth: Handle ATT prepare write command
Call attribute write callback taking into account the offset and
generate proper responses:

> ACL Data TX: Handle 42 flags 0x00 dlen 69
      ATT: Prepare Write Request (0x16) len 64
        Handle: 0x0021
        Offset: 0x0000
          Data: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
< ACL Data RX: Handle 42 flags 0x01 dlen 15
      ATT: Prepare Write Response (0x17) len 64
        Handle: 0x0021
        Offset: 0x0000
          Data: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> ACL Data TX: Handle 42 flags 0x00 dlen 23
      ATT: Prepare Write Request (0x16) len 18
        Handle: 0x0021
        Offset: 0x003c
          Data: 0000000000000000000000000000
< ACL Data RX: Handle 42 flags 0x02 dlen 23
      ATT: Prepare Write Response (0x17) len 18
        Handle: 0x0021
        Offset: 0x003c
          Data: 0000000000000000000000000000

Change-Id: I4e5d8e8c92fdbf624d1588345878f0b678472401
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 875d519948 Bluetooth: Handle ATT signed write command
Call attribute write callback taking into account the signature length
so only the actual data is used.

Note: It still don't support validating the signature because that depend
on storing CRSK key.

Change-Id: I93973e2997f57e5715080ef56ad85e0eaf11d0fe
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 679dd4c1a9 Bluetooth: Convert ATT parser to use opcode table
This reduces the amount of code necessary to check minimum size and
to generate error responses.

Note that not every response can be generate using this method since in
some cases the handle must be set to indicate what attribute has failed.

Change-Id: I0dde7461d97e451407935d5ec3cbfedf6542d5e6
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 0000a2d790 Bluetooth: Add check fo connection encrypt flag in ATT
This checks if connection encrypt flag is set if attribute requires
encryption and in case the connection is already encrypted return
success.

Change-Id: I8af4e9786b63a21f478b3aa9f6df448d7f5760c5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz 8f6edeebb8 Bluetooth: Handle attribute read/write errors
Respond with an error if attribute read/write return an error.

Change-Id: I9c2f98ac4b73bca5d3714339a47290ca9ae2391b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz 58791718e1 Bluetooth: Check GATT attribute permissions
This checks attribute permission returning an error in case they don't
match.

Change-Id: I56a85ad594cb1ac535b03cdbceb43af84dc6604f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz 1d734fd60f Bluetooth: Fix not passing proper peer address to attribute read
Invalid peer address was being passed since the conn pointer was not
initialized properly.

Change-Id: Ib64584f1eb8bc534389bd4fa057c58dd00ffbd6d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:17 -05:00
Luiz Augusto von Dentz c6ce7792a7 Bluetooth: Add Bluetooth remote address to attribute callbacks
To implement CCC properly it is required to know the remote address since
it is per client, futhermore bt_gatt_notify requires an address where to
send the notification.

Change-Id: I9d9fdf72d668831bed76e2aef06816af3620f4b8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:17 -05:00
Luiz Augusto von Dentz 96ac8de38f Bluetooth: Add implementation of ATT Write Response
Write attributes matching handle generating a proper response if
necessary:

< ACL Data TX: Handle 3585 flags 0x00 dlen 5
      ATT: Write Response (0x13) len 0

Change-Id: I7c230501e042a1a759baa2653944bef830b51779
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:17 -05:00
Peter Mitsis 6059e0e2e1 Apply __stack tag to align bluetooth defined fiber stacks
Bluetooth fibers must have their stacks properly aligned.

Change-Id: Id46b376abb46400c563050b4c8393ab3983ff045
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:14:13 -05:00
Luiz Augusto von Dentz fc1392d7aa Bluetooth: Add implementation of ATT Find Information Response
Read attributes matching handle range generating a proper response:

< ACL Data TX: Handle 3585 flags 0x00 dlen 10
      ATT: Find Information Response (0x05) len 5
        Format: UUID-16 (0x01)
        Handle: 0x0011
        UUID: Client Characteristic Configuration (0x2902)

Change-Id: I16a5abbcca67d522bd2282d3bf727770d1fa4006
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz 32c50333b3 Bluetooth: Add implementation of ATT Read and Read Blob Response
Read attribute and generate a proper responses:

< ACL Data TX: Handle 3585 flags 0x00 dlen 6
      ATT: Read Response (0x0b) len 1
        Value: 01

< ACL Data TX: Handle 3585 flags 0x00 dlen 20
      ATT: Read Blob Response (0x0d) len 15
        54 65 73 74 20 50 65 72 69 70 68 65 72 61 6c     Test Peripheral

Change-Id: I5a644fd29ae46fdecdc32c6558591ce7a8d2d42c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz e6ef8df212 Bluetooth: Add implementation of ATT Find by Type Value Response
Read attributes matching value and handle range generating a proper
response:

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Find By Type Value Response (0x07) len 4
        Handle range: 0x0001-0x0005

Change-Id: I8001afa2b22e804bef3778d0509d17b01a8d597c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz 9a09a5d329 Bluetooth: Add implementation of ATT Read by Type Response
Read attributes matching UUID and handle range generating a proper
response:

< ACL Data TX: Handle 3585 flags 0x00 dlen 20
      ATT: Read By Type Response (0x09) len 15
        Attribute data length: 7
        Attribute data list: 2 entries
        Handle: 0x0002
        Value: 020300002a
        Handle: 0x0004
        Value: 020500012a

Change-Id: Iaf4b0c963765a7769a17144a4d394dce8555c2d3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz 7c14248061 Bluetooth: Add implementation of ATT Read by Group Type Request
Read attributes matching UUID and handle range generating a proper
response:

< ACL Data TX: Handle 3585 flags 0x00 dlen 24
      ATT: Read By Group Type Response (0x11) len 19
        Attribute data length: 6
        Attribute group list: 3 entries
        Handle range: 0x0001-0x0005
        UUID: Generic Access Profile (0x1800)
        Handle range: 0x0006-0x000d
        UUID: Heart Rate (0x180d)
        Handle range: 0x000e-0x0011
        UUID: Battery Service (0x180f)

Change-Id: I1ef2d5b1b0237fc0f89221239686777169cc8883
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz 2506aa93b3 Bluetooth: Make use of bt_uuid_cmp to compare UUIDs
This replace the old code that could only compare 16 bits UUID with
bt_uuid_cmp which can expand to 128 bits if types don't match.

Change-Id: I84219d451d8c95baf6f7e42b92629cb106428ccf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz de52b09a3f Bluetooth: Add GATT skeleton
This adds initial API and definitions to create a database.

Change-Id: I69d5b3f5fd2f04cc309c2f76a84581673aa54e7b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz 6d564a9648 Bluetooth: Handle ATT Exchange MTU request
This properly init the MTU to default upon new connection and properly
store the new value in case of Exchange MTU request.

Change-Id: I561f5b1756fd8833244cdd2a986e561c16fc8471
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Johan Hedberg 764dd444e5 Bluetooth: Fix coding style (missing braces)
Change-Id: If96f4ce601499345e8e29143a03742594cac35af
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Luiz Augusto von Dentz 7f6a66c04e Bluetooth: Move UUID code to its own file
UUID defines, etc, will be needed by multiple files including GATT.

Change-Id: I855d3934242f54a8b5bf31652a4f8b9dfb63ef06
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 5c9421ff32 Bluetooth: Move SMP & ATT contexts to protocol specific files
Now that we have the connected/disconnected callbacks available for
L2CAP channels we can use these to associate the bt_conn with a
respective protocol-specific context.

Change-Id: I7c4d9a54f73ae7029a73372a1b0c93d473b28881
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 0b099acb4c Bluetooth: Add registration mechanism for L2CAP channels
We'll either way need various callbacks as well as get rid of the
channel-specific contexts in conn.h, so add a dynamic way of
registering fixed channels. The LE signaling channel is handled in the
same way as any other channel.

Change-Id: I5f8c1af3c8e3d107212becf507a5a6485838e081
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 44e67698a6 Bluetooth: Move L2CAP header encoding to sending stage
Encoding the L2CAP header when allocating the buffer means that we
must know the final size up-front. This is not always possible, so
move the header encoding to bt_l2cap_send() and only have the
bt_l2cap_create_pdu() function reserve enough headroom without
actually encoding anything.

Change-Id: Ic1c3b6b72c265cd0db4e835790fa915e0acd9388
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 90b27c478d Bluetooth: Remove unnecessary bt_buf_add type casts
Now that bt_buf_add() returns 'void *' there's no need to explicitly
type cast its return value anymore.

Change-Id: I6d5c9d323dc08cb5a2b928977c1bbf3d741e5d8e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz dd52c0109f Bluetooth: Make use of bt_buf_pull_le16
Remove the memcpy code and instead use bt_buf_pull_le16 for unaligned
access and byte order conversion.

Change-Id: I0216042566e27d6a513b302ae1ea78b49f2f1c31
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz 009899116d Bluetooth: Fix missing braces in ATT code
Change-Id: Icc241250a357efb06614d841cc37de77dddece2e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz 09f8409bfe Bluetooth: Fix using wrong PDU in handlers
Both Write Command and Signed Write command should use their respective
packed struct.

Change-Id: Id786d1e0ee0327f662c68fa1d2f3d3bf19a237fc
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz f436fc835e Bluetooth: Warn unkown ATT PDUs
The code should always warn about unkown PDUs since it could be causing
unexpected behavior or that something is missing.

Change-Id: Idc608ca221c5ff6e440f90fa24c2cd6a3e6437fc
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Johan Hedberg 3beca82c90 Bluetooth: Add debug config options for all current sub-modules
We want to be able to do fine-grained enabling of debug logs for the
various Bluetooth sub-modules. They all default to 'n' so an app
writer would need to go and enable the specific ones that they're
interested in.

Change-Id: I17105adf133d441dfc811bdd66a00be015813679
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz ed7b333385 Bluetooth: Add ATT Execute Write Request skeleton
This adds the defines for Execute Write PDUs along with initial code to
parse them.

Change-Id: Ifa8229b9f3bf0a60d9abe553263b32397d1ba881
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz 0fe5fa9fcf Bluetooth: Add ATT Prepare Write Request skeleton
This adds the defines for Prepare Write PDUs along with initial code to
parse them.

Change-Id: Ia7210dbe4662afbebe742b5b1a7b8f08999adf2a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz d3acf5f16a Bluetooth: Add ATT Signed Write Command skeleton
This adds the defines for Signed Write Command along with initial code
to parse it.

Change-Id: I2071163c8468a6580d9a9305095187a140c80a43
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz 75f56d9e07 Bluetooth: Add ATT Write Command skeleton
This adds the defines for Write Command along with initial code to parse
it.

Change-Id: Ifabcfa8efb54b5135a540718fb60d9a656cd088c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz 9e8c1d1326 Bluetooth: Add ATT Write Request skeleton
This adds the defines for Write PDUs along with initial code to parse
them.

Change-Id: I69d2002b3e6da80037c058f42f543a0ab4765958
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz 75aab47603 Bluetooth: Add ATT Read by Group Type Request skeleton
This adds the defines for Read by Group Type PDUs along with initial
code to parse them:

> ACL Data RX: Handle 3585 flags 0x02 dlen 11
      ATT: Read By Group Type Request (0x10) len 6
        Handle range: 0x0001-0xffff
        Attribute group type: Primary Service (0x2800)
< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Read By Group Type Request (0x10)
        Handle: 0x0001
        Error: Attribute Not Found (0x0a)

Change-Id: Iebc84e7a9c405fa58b7984602d2d27f79d6033a7
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz f00308f0eb Bluetooth: Add ATT Read Mutiple Request skeleton
This adds the defines for Read Multiple PDUs along with initial code to
parse them.

Change-Id: I34f597881e3bdb9325ffbf2bda42b7ae6710c3ae
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz eedc01d6d5 Bluetooth: Add ATT Read Blob Request skeleton
This adds the defines for Read Blob PDUs along with initial code to
parse them.

Change-Id: I5a2a2e2e32bf44d98ce928b3d57ad7f05059a927
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz dfdd657b37 Bluetooth: Add ATT Read Request skeleton
This adds the defines for Read PDUs along with initial code to parse
them.

Change-Id: I3ec54a0bf2394b54bd8b08957533f0826bf4a23a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz 0d853d64c2 Bluetooth: Add ATT Read by Type Request skeleton
This adds the defines for Read by Type Value PDUs along with initial
code to parse them:

> ACL Data RX: Handle 3585 flags 0x02 dlen 11
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0001-0xffff
        Attribute type: Characteristic (0x2803)
< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0001
        Error: Attribute Not Found (0x0a)

Change-Id: I0b4371b8decebf33710a949552a11c80c544b5f8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:58 -05:00
Luiz Augusto von Dentz d51985e4ce Bluetooth: Add ATT Find Information by Type Value Request skeleton
This adds the defines for Find Information by Type Value PDUs along
with initial code to parse them.

Change-Id: I9eaf2df390ca6f78530df7f1ae606b588d1fcb2e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:57 -05:00
Luiz Augusto von Dentz b6d35d8281 Bluetooth: Add ATT Find Information Request skeleton
This adds the defines for Find Information PDUs along with initial code
to parse them.

Change-Id: If34533cca4a1a554ca3f119c7639a1167dae0ff2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:57 -05:00
Andrei Emeltchenko 2ea4e83446 Bluetooth: Fix ATT code printing
Fix bug printing ATT code in bt_att_recv()

Change-Id: I21fe9cb1272428e618412e98b09e8d786132eef6
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:13:57 -05:00
Luiz Augusto von Dentz 028edd59ba Bluetooth: Add code to handle BT_ATT_OP_MTU_REQ
Add code to respond to BT_ATT_OP_MTU_REQ with BT_ATT_OP_MTU_RSP
selecting the MTU based on the amount of room bt_buf has:

< ACL Data RX: Handle 39 flags 0x02 dlen 7
      ATT: Exchange MTU Response (0x03) len 2
        Server RX MTU: 65

Change-Id: I47b8179fcee0d6adff5761abc37cfcb1ed636d65
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:56 -05:00
Luiz Augusto von Dentz 7cbb4e6f4b Bluetooth: Add bt_att_create_pdu
Add bt_att_create_pdu which works similarly to bt_l2cap_create_pdu
eliminating some duplicated when generating ATT PDUs.

Change-Id: I30b89effbae887f4032ba1d1e380a763c3556869
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:56 -05:00
Luiz Augusto von Dentz 4202d9a7bf Bluetooth: Fix missing parentesis to sizeof
Change-Id: I31e7b8fb3e463371950b538a51676baa77b671ba
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:56 -05:00