Commit graph

922 commits

Author SHA1 Message Date
Johan Hedberg 50a25dcfd3 Bluetooth: Add BT_WARN convenience logging macro
Some logs indicate potentially problematic situations but are not
necessarily errors. Since we do want to log these regardless of the
debug setting it's better to have a separate BT_WARN macro for them.

Change-Id: Iad13fc4b58329113458c97b02855033836618f5b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 041c84c3e6 Bluetooth: Introduce dummy data type
We're already sending 'dummy' buffers to wake up the connection
fibers. The problem is that if we provide a real buffer type it may
have unintended consequences. E.g. with BT_ACL_OUT when bt_buf_put()
is called it may trigger an invalid HCI_Host_Num_Completed_Packets
command.

This patch creates a new BT_DUMMY buffer type to avoid this scenario.
The new type is an alias for BT_CMD since the pool where these buffers
come from is not quota-controlled and synced up with the controller.

Change-Id: I42ac235811dc242345853f7858c10bfc43e4f07d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 586d76b12a Bluetooth: Add support for reporting completed ACL buffers
Every time we put a BT_ACL_IN buffer back to the pool we should report
this to the controller so it knows it can send us more data. This
patch makes the necessary modifications to the bt_buf_put() function
to trigger the HCI command.

The Host Number of Completed Packets command is special in that it
doesn't need to obey the reported ncmd value and also doesn't generate
any command status/complete events. Because of this we need an
exception for it in the bt_hci_cmd_send() function.

Change-Id: If65f28078fd0d81af853447e95bc53822fea75b7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 39a6c7df9b Bluetooth: Enable controller to host flow control in HCI init
To start supporting controller to host flow control we need to tell
the controller our supported packet count & MTU and send the enabling
HCI command. This patch does the necessary addition to the HCI init
procedure.

Change-Id: I51a66f8cc3a85782a5085f9aae0f4aeb59decad3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 25af03265c Bluetooth: Add ACL user data to bt_buf
To track which ACL handle each buffer belongs to (needed for host flow
control) add the necessary information into a new ACL-specific struct.

Change-Id: Ie6cc7c32a70b43a4ff5954bb9dca34e4f62da292
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 5626788eb7 Bluetooth: Refactor buffer HCI user data
To accommodate for ACL user data move the HCI command/event data into
its own struct and put it inside a union in bt_buf.

Change-Id: I680500b15709d14b1e9f70ced88664d607a6568c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg b6804df02e Bluetooth: Split buffers into separate pools
In order to do proper flow control of ACL data to/from the controller
we need to have precise management of the available buffers. Mixing
with the events/commands buffers would make this impossible. This
patch splits the buffer pools into three separate ones:

	1. HCI commands/events
	2. Incoming ACL data
	3. Outgoing ACL data

The total number of available buffers is also increased to match
what's the smallest number supported by current controllers (to avoid
the stack from becoming a bottle neck).

Change-Id: I7e131d61c83a4dda554068d7917c5ee09f2f837d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg d829fe9755 Bluetooth: Consolidate bt_buf_get* functions
We may soon want to have a _wait() variant of bt_buf_get, so to avoid
the number of 'get' function growing too large consolidate the
existing get() and get_reserve() functions into a single one. The new
consolidated function also takes the type as input parameter so that
we know this from the very start and thereby plan for the split into
multiple buffer pools.

Change-Id: Ia09448565349def2be9bc08d9510fedd029480b4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 4e65d0aac2 Bluetooth: Split ACL buffers into two distinct types
We'll soon want to have dedicated pools for outgoing and incoming ACL
data. To know from which pool to get and put the buffers each buffer
should contain enough information to distinguish the two types. This
patch splits the old BT_ACL type into two new BT_ACL_IN & BT_ACL_OUT
types.

Change-Id: I7d3c05c26d2a70f80fb1229e245aa21673ec378b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 550cdd9717 Bluetooth: Add dependency includes to hci.h
The hci.h header file depends on the integer type definitions from
stdint.h and the PACK_STRUCT macro from toolchain.h. This patch adds
those so that users of hci.h don't need to be concerned of this
detail.

Change-Id: Ib1856cdec75a3bab1b86bc832cdec6ad0461db6d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 429240d376 Bluetooth: Move buffer handling into a dedicated file
The buffer handling code is quite large and will continue to grow. As
it's not strictly HCI core material it's better to just manage it in a
separate file. This patch moves the code to include/bluetooth/buf.h
and net/bluetooth/buf.c.

Change-Id: Ie1ff79ac2cfa132359ce9f7674ff812d34b228aa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 58c5689531 Bluetooth: Add skeleton for handling disconnect complete events
This patch adds a simple event handler for the LE Disconnection
Complete HCI event. An extra thing the handler needs to do is to
re-enable advertising if necessary, since it will have been implicitly
disabled by the controller upon a connection event.

Change-Id: Ie6f2eecb8c1d7de16fea24c8fd1533545f41baa5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg 391260d03c Bluetooth: Add skeleton for handling LE conn complete event
This patch adds a basic event handler for the LE Connection Complete
HCI event.

Change-Id: Iea099fe1b8c87fcd00d13e8793ebce8ced7adec6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg 3739760dc2 Bluetooth: Add skeleton for handling LE meta event
All LE related HCI events come wrapped in a LE Meta 'super' event.
This patch adds a basic event handler for it.

Change-Id: I4a037d4af080c3ba0f982586065c0c49b6cf7640
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg f64e3c08b2 Bluetooth: Add semaphore for counting controller-side ACL buffers
We shouldn't be sending more ACL packets to the controller than it
is capable of accepting. This patch adds a semaphore to track the
number of available controller-side ACL buffers.

Change-Id: Ib280afa06aade68eee03e44e33624eebb700dad5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg a6fbfe4bc1 Bluetooth: Add simple advertising enabling API
This patch adds a simple API for enabling advertising and specifying
the friendly name in the advertising data. The API is probably not a
final one but fulfills the initial need to create apps that are able
to act in the LE peripheral role.

Change-Id: I3ff7e72ece377d872ef1b0e4ad44aeb293cc13e5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg 7bfbe7abf2 Bluetooth: Add basic advertising definitions
To manage LE advertising we need basic HCI definitions for the
commands and events involved. This patch adds those to the hci.h
header file.

Change-Id: Ic6cf17369ad09d97ca5c098f25ba786d265d0bfd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg d210d306d7 Bluetooth: Add full HCI initialization routine
This patch adds a full HCI initialization routine to retrieve all
relevant information from the controller.

We also need to introduce a new blocking bt_hci_cmd_send_sync() API
since some commands are conditional to the results of others. The API
is implemented with the help of a semaphore that's part of the
command's bt_buf struct. We wait on the semaphore and get it back once
the command has completed (with the help of the hci_cmd_done
function).

The patch also adds variables for storing various controller specific
parameters which will be needed later during the operation of the
stack. These variables are part of 'struct bt_dev' and get updated
through the respective command complete handlers.

A new bt_hci_reset() API is added which allows an application to reset
the controller state at any time by re-running the HCI init procedure.

Change-Id: I5b1a38e910d79ad5fe806467bc51388eedc9c8f9
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg 23a0df8b9b Bluetooth: Add HCI driver API
This patch adds a basic HCI driver registration API along with a fiber
to process data from the driver. A FIFO is used for receiving data
from the driver and waking up the respective fiber. To open and set up
the HCI transport for operation there's an open() callback passed to
the HCI core. This function will be called as soon as an application
initializes Bluetooth functionality through bt_init().

Change-Id: I780cca517a0dfc714f1ca35527e1c61e307345a0
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg 64b117a9b1 Bluetooth: Add support for HCI data buffers
In order to manage incoming and outgoing HCI data (events, commands &
ACL data packets) we need to have some way of storing this into
buffers. This patch implements a 'pool' of buffers with the help of
the nano_fifo API. The pool is initially populated with all available
buffers. After this code can on demand request buffers from the pool
with the help of bt_buf_get() and return buffers back into the pool
with bt_buf_put().

Since we don't always know the execution context from where the API is
operated on, this patch also adds convenience fifo_get/fifo_put
wrappers that look up the exact context before calling the correct
nano_fifo API.

Change-Id: Ie7f6d450de865273171e21a000d5a14274d27d32
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg 63e9480399 Bluetooth: Add basic HCI definitions
For performing a basic HCI initialization procedure we need
definitions for the related HCI commands and events. This patch adds
these into separate hci.h header file. More content will be added to
this file as corresponding functionality gets added to other areas of
the stack.

Change-Id: Ida7555cb0a3d30b8a44324cb14699eba8a1bcdee
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg ac63429177 Bluetooth: Add skeleton for HCI core
To introduce the Bluetooth stack to the tree we need some additions to
the configuration options, as well as the very basic header files. The
patch also adds a skeleton for a bt_init() function that applications
will need to call to initialize Bluetooth functionality.

Change-Id: Ideb24dfea584b71f514e05eb47654b659776133e
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00