Commit graph

98463 commits

Author SHA1 Message Date
Johan Hedberg 7ce57dd762 Bluetooth: SMP: Implement key generation function s1()
The s1() crypto function is used to generate keys for SMP Legacy
Pairing.

Change-Id: I839cb8210d8babe64551f8d958c97d0addd459b4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 5190c37967 Bluetooth: Make max supported connection count configurable
Add a kernel config option to specify how many simultaneous
connections can be supported.

Change-Id: I963aacb7cece3436ecd5049683a19a350224a156
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 63552b1485 Bluetooth: Add error logs for bt_init() failures
These may help debug early initialization issues.

Change-Id: I18a8043b2da46ec50f03fedfce46e48d9b41b373
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 6e20c3b838 Bluetooth: Move all logs behind CONFIG_BLUETOOTH_DEBUG
The BLUETOOTH_DEBUG config option bumps the stack sizes to cope with
printf requirements. Since all the logs use printf now they should
only be available with the bigger stack sizes to avoid surprises.
There are still basically two levels of log enabling where
BLUETOOTH_DEBUG enables the ERR/WARN/INFO everywhere and the
BLUETOOTH_DEBUG_* enables BT_DBG for a specific subset of the stack.

Change-Id: Ie8d64e47f44485efde32b40cd5bb34389c8e39da
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Andrei Emeltchenko fa77083bf4 Bluetooth: Fix printf specifier for debug
printf() '%x' expects type 'unsigned int' for 'x', but parameter has
pointer type.

Change-Id: Id2d365a32b2e3e711359bd56741370d8167db868
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko 9b9e9e66c5 Bluetooth: trivial: Fix coding style
Change-Id: Ie0bdad384ea353733bb37acd5422269cc49ea08b
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -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 e104fa5928 Bluetooth: Fix accounting for driver header in ACL MTU
When we notify the controller of our ACL MTU we should subtract from
the buffer size not just the ACL header but also the headroom reserved
by the driver.

Change-Id: Id05b1becab3682425f9b591217ac29659a13a6d0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 80824d459e Bluetooth: Fix coding style (too long lines)
Change-Id: I6573eee755d26290626e1a44a5f56fe56b92c55c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 60cf3146f7 Bluetooth: Fix minor typo in debug log
Change-Id: I0478e22b69d7a0ed5f5c642aa651cd58810aa035
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 7f9aeeb2e8 Bluetooth: Add debug logs to connection data path
Add debug logs to the rx/tx fibers so issues relating to them can be
more easily debugged.

Change-Id: Ie02d3e760772a3e47ff495c47d83b23744202941
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 24a0e0eeb5 Bluetooth: Improve debug logs for HCI core data paths
Add debug logs to the HCI core data handling to catch potential
issues.

Change-Id: I39bd3aeec9ed7b64156a9e2e899a153c0d484f38
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg d6600e075f Bluetooth: Include context ID in debug logs
Including the context ID in debug logs can help track down various
issues, e.g. stack corruption.

Change-Id: I3cd70edd5bfd1d726f6d35e7331afb313cf3cacb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 8930a13b60 Bluetooth: Prefer printf over printk
The printf API has a much richer support for various format
specifiers. Switch the Bluetooth logging macros to use printf instead
of printk and make sure STDOUT_CONSOLE gets selected when
BLUETOOTH_DEBUG is selected (so printf actually works).

Change-Id: I9a9818d51a677c6c79a35fef6daca7979f61c78d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg c533552497 Bluetooth: Increase fiber stack sizes when debug is enabled
The debug logs may cause a considerable overhead to stack utilization
(especially with printf). Increasing the fiber stack sizes when debug
is enabled decreases the chance of stack overflow.

Change-Id: I26e96c6516e0c1210e787cc5491fd5d59cbc75db
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko 3933278948 Bluetooth: Add ARM configuration for shell app
Change-Id: Ifa5bd8c82e4accd3778b45d7bb1af71b058c77e7
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Arkadiusz Lichwa 022d67096d Bluetooth: Initialize LE ACL MTU to proper value
Fix stack initialization.
When LE read buffer size returns 0 length LE buffers and controller
supports LE & BR/EDR functionality then ask controller about max ACL data
length it can accepts using BR/EDR read buffer size.
It should return value that can initialize LE MTU if that one still has 0.

Change-Id: Ib0bce89d47de5549d629a4ce771325e640443378
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko 87139e5e87 Bluetooth: Add peripheral app quick test to bt_regression
Build peripheral app for targets: pentium4 and ti_lm3s6965

Change-Id: Id98c94217ad39e1716b8f8bc6031b8814bae06f3
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko b428ef6d65 Bluetooth: Add ARM configuration to peripheral app
Change-Id: I23428811de2d825c75a3938354b1079550ba3911
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz 18af2d839b Bluetooth: Make local variable static in peripheral sample
Change-Id: I6ce9a8ccab3461c8e7bbd15b2b129c01c5bdaa9e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg a60a4aba2e Bluetooth: Fix includes for sample apps
Update the includes in the sample apps to match what their actual
dependencies are.

Change-Id: I6fdfa4ba0cda563433d51f0ec35fef8f2ee0fa40
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 5071a46ac8 Bluetooth: SMP: Add full Pairing Confirm & Random handling
Add tracking of the confirmation values, remote random value and the
temporary key value. This also involves implementing the SMP e()
function with the help of the HCI_LE_Encrypt command.

Change-Id: I4cdad917e9689bbe16cd908941d0335c1c33f870
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 1e5efb9fb7 Bluetooth: SMP: Store original pairing req/rsp values
These values are needed later in the SMP pairing procedure as inputs
to various crypto functions.

Change-Id: I68334ed6d32625c4e7e0668300844af09018e126
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 38a7d345ae Bluetooth: SMP: Fix minor coding style issues
Add missing braces to a couple of one-line branches.

Change-Id: Ie4d703eede3cc03b823bd0a0764a5b999f317322
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg a648bbe9a1 Bluetooth: SMP: Add local random number generation support
The SMP procedures require us to establish a local random number. Use
the HCI_LE_Rand command to generate the necessary 16 bytes (the
command needs to be called twice since it only returns 8 bytes at a
time). Store this number in the SMP context.

To help debugging with various crypto related values add a local h()
helper function for printk/BT_DBG to do hexadecimal conversion.

Change-Id: Id3e8793a77ac635023b3cc3a94e8679170455870
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 653378d031 Bluetooth: Track remote address for connections
We'll need to know the remote address for connections e.g. when
performing SMP based pairing.

Change-Id: I7e398a75c2418ec534b3cac15ab72f76586c2e9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 4dae513d4b Bluetooth: Add contexts for SMP & ATT specific data
All fixed channels will need per-connection contexts. Right now in
addition to the L2CAP (LE) signaling channel the other two fixed ones
are ATT and SMP.

Change-Id: I56dda6b903ef703e453438e03a99c704aa77899a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 19deebbecf Bluetooth: Move L2CAP context into dedicated struct
In preparation for having per-fixed channel contexts move the L2CAP
signaling channel specific data into a dedicated struct.

Change-Id: Iaacb5e1c7408be67740434f31ef56f94706ad327
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Szymon Janc 62267639ac Bluetooth: Fix not waiting for all commands to complete on init
For LE-only controller init procedure should wait for last HCI command
(Set Controller To Host Flow Control) to complete before returning.

Change-Id: Ic01e0cbaebf19d61560faab2ae01205c2eb22b77
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 46372d712c Bluetooth: Fix missing bt_buf_pull when parsing adv report
The code would only have worked for reports with num_reports being
equal to 1. Any event with multiple reports would have been
incorrectly parsed because of a missing bt_buf_pull() for the initial
one-byte num_reports value.

Change-Id: I0ac92edb792d559fb8ff84e40a4b4766f46afe58
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 19707e8257 Bluetooth: Use 'void *' also for bt_buf_pull/push return value
To make the bt_buf APIs consistent with the recent bt_but_add changes
and more user friendly, change the pull() and push() return values
also to 'void *'.

Change-Id: I25242635c87882db99152735c22316d4de00d363
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
Johan Hedberg d6a03600b2 Bluetooth: Change bt_buf_add return type to 'void *'
Almost all callers of bt_buf_add end up having to do explicit type
casts of the return value since 'uint8_t *' rarely fits what's needed.
Changing the return type to 'void *' removes this extra type casting
need and makes the API friendlier to its users.

Change-Id: I6a79605006153b6d09f0d662a051cb599af68c37
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 d1b61254f3 Bluetooth: Add bt_buf_pull_le16 helper
bt_buf_pull_le16 convert the initial 16 bits to little endian.

Change-Id: I6f6e9d63fc19b0579d9f445e15e975929fc63ba9
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
Tomasz Bursztyka 0b4413d607 uart: Removing driver specific informations from the generic API
IRQ and registers are hardware and driver specific information and as
such should no be exposed through the generic API.

Change-Id: I33e6d7ec7bd9fb82a4e343d99b7a5c17886d1470
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka ea4c3d1c0f bluetooth: UART based driver no longer needs to set regs and irq
Now that UART drivers are configured internally when it comes to
hardware specific information such as IRQ and registers (or mmaped
registers), bluetooth UART driver no longer needs to do it by itself. It
only requires to select the port it wants to use.

Change-Id: I5a30500f4b6f4155292609d0ed4a758f91930817
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 088e0a980f arm: Refactor how UART is configured
UART is configured statically into the driver directly and not anymore
in the board's system.c. Thus limiting the information to be scattered
into 2 files instead of 3. Then in future, it will also be possible to
remove driver specific informations from the generic UART API structure.

Change-Id: I001f2a6834df9a41ab395a80e4e39b347d545db3
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 4eb6aab3ad x86: Refactor how UART is configured
Now for x86 platforms, UART is configured statically or dynamically into
the driver and not anymore in the board's system.c. Thus limiting the
information to be scattered into 2 files instead of 3. Then in future,
it will also be possible to remove driver specific informations from the
generic UART API structure.

Change-Id: I7b7fa37f10f88316a4d375c99de3bbacf152a3e3
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 68a58ca587 kconf: Add an option to select PCI on x86 architecture
By default it is set to 'n'. This will be useful to enable the PCI layer
code if required. On quark boark, it is selected by default as UART
driver needs it currently.

Change-Id: I7aa38e73c431c66ebbd8092aff0a14d5fb9268d5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 1cc9c3901e k20uart: Apply a tiny syntax change
Remove camel case style on baseAddr, changing it into base.

Change-Id: Iea1e2d204a38912f4157cc6776a88640e29a04f6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 724282d27d k20uart: Let's use 'port' everywhere as it is more readable
Using "which" is somehow awkward to use when 'port', on the contrary, is
blatantly more readable.

Change-Id: I355c6e09d7c27b4b07ab6cd10b772a632855516b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 1eac566143 ns16550: Let's use 'port' everywhere as it is more readable
Using "which" is somehow awkward to use when 'port', on the contrary, is
blatantly more readable.

Change-Id: Id4d3786a192a650ca042024521b94e557a3ec7e8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 0a7c8ea578 uart: Follow the same parameter naming everywhere
Just a tiny change s/which/port.

Change-Id: I69be83f9805d71f5ec0ad68b146816d2a4fe221a
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka e5c8de83a0 quark: Remove MAX_PCI_DEVS Kconf entry
It is useless as PCI scanning is now storing anything.

Change-Id: I6e3b1e328e2f440ac57a2142cab138e4a222f4fc
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka d3a4177d92 pci: Provide a simpler yet powerful PCI enumeration API
This fixes many issues around PCI enumeration from old API:
- a static internal table was fed with scanning results, thus eating
  memory, and worse: due to the limit of its size, scanning for new
  classes was impossible unless growing statically the size of this
  table --> more memory eaten! Not to mention PCI enumeration is done
  once at boot time for driver initialization and that's all, so this
  table is hanging around for nothing afterwards.
- one needs first to scan a class, then maybe he will be able to find
  his device via pci_dev_find. Where all could be done at once.
- pci_dev_find was not trustworthy due again to the internal table. Now
  if the device is not found, one will know it really went through all
  the possbilities.
- still let the possibility for hard-coded BARs value on driver side
  (thus no PCI scan required). However this is greatly advised not to do
  so as BARs might change over a firmware/BIOS update.

Comparison:

old pci_dev_scan: could only filter out via class mask.
new pci_dev_scan: can filter out via a class, a vendor and device ID
(it could easily do the same for Function and BAR index as these are
usually fixed and informed through datasheet)

old pci_dev_scan: was limited in its findings by the size of the
internal result table.
new pci_dev_scan: can proceed through all the buses and devices every
time (there are optimizations to avoid useless work of course)

old results did not tell about the function or BAR index.
new one tells, and the structure has not bloated.

old internal code: was storing a big table of results
new internal code: is only storing a small lookup structure and an
array of Bus:Dev pairs for each PCI class for optimizations purpose.
(though, if needed, we could disable this through some #ifdef)

Usage:

- Have a local struct dev_info
- Fill it with what you want to look for, currently: only class and
  vendor_id/device_id. Function and BAR index could be added if needed.
- Call pci_bus_scan_init(): this will reset the internal lookup
  structure.
- Call pci_dev_scan(<a pointer to your dev_info>): at first call, the
  internal lookup structure will pick up the informations from dev_info
  and will try to find out what has been requested. It will return 1 on
  success, or 0. On 1, your dev_info structure will be updated with the
  found informations. If more devices can be found against the same
  lookup informations, just call again pci_dev_scan(<a pointer to your
  dev_info>) as long as it returns 1. When 0 is hit, it will mean you
  found all.

Change-Id: Ibc2a16c4485ee3fed7ef4946af0ece032ae406e4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Tomasz Bursztyka 1425fd8449 pci: Apply code style changes
- always add {} on any sub-statements
- proper indentation
- 80 chars limit

Change-Id: I869239bf2e309a6e73fb180cf29acf66c019489a
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-05 20:14:01 -05:00
Johan Hedberg 15bf447614 kconf: Fix build with gcc 5.1.1
Building zconf.hash.c fails with gcc 5.1.1 from Fedora 22:

In file included from zconf.tab.c:159:0:
zconf.hash.c:233:55: error: ‘kconf_id_strings_contents’ is static but used in inline function ‘kconf_id_lookup’ which is not static [-Werror]
zconf.hash.c:226:23: error: ‘kconf_id_hash’ is static but used in inline function ‘kconf_id_lookup’ which is not static [-Werror]
    register int key = kconf_id_hash (str, len);
                       ^
zconf.hash.c:177:26: error: ‘wordlist’ is static but declared in inline function ‘kconf_id_lookup’ which is not static [-Werror]
   static struct kconf_id wordlist[] =
                          ^
Import the necessary change from the latest Linux source tree.

Change-Id: Ib6297b5cc3da161bd99c2e92c366206e6c08b4e5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:01 -05:00