Commit graph

2878 commits

Author SHA1 Message Date
Vinayak Chettimada 966fbbcd04 Bluetooth: Controller: Run all enqueued mayfly before disable
Controller asserted in preparation of a role event due to
the previous (same or another) role event preparation being
not complete.

Mayfly callee was disabled in the previous event due to the
preparation time being short and previous start running
(higher natural priority) before all previous preparation
mayfly completed. The previous start disabled mayfly to
avoid Radio ISR latencies.

The current role event that asserted, preempted the
previous role (observer role with continuous scanning
window) which runs until preemption to maximise the Radio
h/w use (observer scanning until next interval). The
previous preparation mayfly is still disabled when the
current role preparation tries to use same mayfly instance
which should be free for a new enqueue.

This commit updates mayfly implementation so that mayfly
callee is disabled only after all enqueued mayfly instances
are run to completion.

Jira: ZEP-1839

Change-id: I3e0d31422db8e47b819189110b11ebd07dd09a7c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Johan Hedberg 0ed68c7680 Bluetooth: Relax minimum advertising interval for 5.0 controllers
The 100ms limit is only valid for controllers before version 5.0. For
a 5.0 controller the minimum is 20ms (0x00a0) which is already checked
for later in the valid_adv_param() function.

Change-Id: I0566a38ff855800d2e46e1d2c0a5c7bc9bc610cd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi ff3e6e333f Bluetooth: controller: Report 5.0 compliant controller
Since there are no mandatory features in 5.0 when compared to a 4.2
compliant controller, report 5.0 as the current specification
implemented by the controller, to allow for features such as short
advertising intervals (< 100ms) which are already supported.

Change-Id: I1b138a86290a0422760a5e265cdd7b72d68f0048
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Johan Hedberg f253f4e14c Bluetooth: Add support for Bluetooth 5.0 version specifier
Add support for detecting version 5.0, i.e. 0x09.

Change-Id: Ia2da513b65c420142fe97a4fa173bfa8045e9d75
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas f7a4d112ae Bluetooth: SDP: Server: Filter records based on requested uuids
Filters the service records by going through all the records and
removes the one which does not have the uuid. So finally, only
the records which has all the uuids in the service search pattern
will be present in matching recs.

Change-Id: I1daa7c1b645efae2af66962999cc4c541891eff7
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz 480cdbd6d3 Bluetooth: GATT: Add bt_gatt_get_mtu API
bt_gatt_get_mtu can be useful when GATT is used to transport another
protocol on top.

Change-Id: I328ef49138ccc4ce642b0019d08060f6022d5aa7
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas e3705b2f60 Bluetooth: SDP: Server: Handle Service Search request
Handles the service search request from peer, parses the service
search pattern (which is a data elem seq of uuids to be searched)
and populate the uuids.

This also populates the registered records which will be filtered
based on the uuids in the pattern (which will be done in the subsequent
patch).

Change-Id: I9a232a7cfdd159325214ed13e98cc20be39a2e3b
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Jaganath Kanakkassery 85b2a7e056 Bluetooth: SDP: Server: Introduce private define for max services
This is mainly done to avoid VLAs for looking up the service to handle
service search requests so that we can make sure that RX stack size
is sufficient for the defined no of services.

Change-Id: Ia99072615d9094a35bd7605ed2901e8018c0ecb2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Arun Jagadish d0c78ce6d4 Bluetooth: AVDTP: Rename of variables
Renaming the params in bt_avdtp_req.

Change-Id: Ibc84931d0fa1d3af0a017f25a9893e51fb06bd1b
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Arun Jagadish 7f27599aba Bluetooth: AVDTP: Fix discover param struct
Changed bt_avdtp_req variable from pointer to variable

Change-Id: Ie1270b7da4f6130e89259c6b5c999407d56b33d8
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz a05cea3a22 Bluetooth: GATT: Use __ASSERT for invalid parameters
Instead of returning -EINVAL at runtime assert in case of invalid
parameters.

Change-Id: I40505f06a4c12445bfb1f1846ace1b592b6bc342
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas c25df73c5a Bluetooth: SDP: Server: Refactor data element structure header
Separate out data element structure header into type and size fields

Change-Id: I869ee1ea82db1f6d669bb905055135b7d63f3fa2
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas 690d455b78 Bluetooth: SDP: Server: Set security level to NONE
Change-Id: I67e18ba3060d0cbe703be9cd0b31e72e2b18d429
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas 6699f5a52f Bluetooth: SDP: Server: Fix MTU setting after l2cap connection
L2CAP TX and RX MTUs will be exchanged during configuration req/rsp.
It should not be modified after connection.

Change-Id: I1e291c9e093561f349bcdcbb75cd7ff22b4163a5
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi 3141dcf3b4 Bluetooth: controller: Introduce debug pins Kconfig option
A new Kconfig debug option now controls the usage of pin toggling to
debug the BLE controller.

Change-Id: I24c5c13ca71e3395e10f14e27ad4bca9f2e94687
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Carles Cufi 34e0c4b253 Bluetooth: controller: Set debug pins with macros
Use macros to identify the different debug pins used to monitor the
runtime behavior of the controller, for easier identification of the
lines.

Change-Id: Ia76d6298985b1d367b7ad193d8261f5403446371
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Piyush Itankar edb32b74d1 Bluetooth: A2DP: Stream End Point Registration
Added an API to allow addition of stream end points by the application.

Change-Id: I91b95fc5dc3b9b2950e8d55b5846e460e55f2453
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada c78601481d Bluetooth: Controller: Fix LE Ping PDU dispatch
It was observed that due to possible CRC errors, one
connection interval was not sufficient by the peer to
respond to LE Ping PDU which caused the Controller to
generate the Authenticated Payload Timeout event to host.

This fix advanced the dispatch of LE Ping PDU by 6
connection intervals that the peer would listen to before
the 30s timeout.

Change-id: I6c292c623047a05b4e771e70093d87228db62cce
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada 16ef73423e Bluetooth: Controller: Use direct ISR for Radio IRQ only
The new hard real-time (direct) interrupt support is used
only for Radio IRQ. Only Radio ISR has hard real-time
requirement of completing its execution inside the tIFS of
150us.

This commit reverts back RTC0 and SWI4 ISR to using the
normal IRQ_CONNECT.

Observed on nRF51, Radio ISR (open text, notifications):
Latencies: min. of 5us and max. of 10us.
CPU utilized: min. of 44us and max. of 77us.

Observed on nRF51, Radio ISR (LESC, fast encrypted,
notifications):
Latencies: min. of 5us and max. of 10us.
CPU utilized: min. of 39us and max. of 112us.

Jira: ZEP-1038

Change-id: Id3d09df7bdbdfea090f21f6f58aaded8c5f1e10d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Arun Jagadish 4efe5eb5b1 Bluetooth: AVDTP: Add AVDTP Receive Function
Added AVDTP Receive function, to recieve L2CAP Data.
Handlers added to parse AVDTP Signal ID

Change-Id: Iedfc4b6883d6cf27615d90a0d37ed10869e47ff3
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi 727987276e Bluetooth: controller: Use direct ISRs
The new hard real-time (direct) interrupt support in the kernel allows
ISRs to be run directly with no significant latency overhead.

Use this new mechanism to improve the latency of the 3 critical
interrupts in the controller: radio, RTC0 and SWI4.

Jira: ZEP-1038

Change-Id: Ief9dacbea4c4c2e8a1c77893a0d6175a91819ffb
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Szymon Janc 767cd577dc Bluetooth: GATT: Fix subscriptions removal
This fix not removing subscription if it was first element on the list.
In that case prev was NULL resulting in passing garbage node to
sys_slist_remove.

Change-Id: I9452af08409692f9a331afd514fbac8cc727d289
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc 8637c23e41 Bluetooth: GATT: Remove not needed variable
prev is not used.

Change-Id: I735be33a3a763fcdee316fdf6cacfaa26e216210
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc da9f9cc3f7 Bluetooth: Fix connection object leak
When canceling outgoing connection initial reference was not dropped.

btshell> connect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_set_state: (0x0011a1ac) disconnected -> connect-scan
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 3
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
Connection pending
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
btshell>
btshell> disconnect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 3
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_set_state: (0x0011a1ac) connect-scan -> disconnected
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
btshell>
btshell> connect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
Connection failed
btshell>

Change-Id: I0c38bbed8d1712d07a579275355e7dcd8d6b0b38
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc 48b9c97b8f Bluetooth: SMP: Fix passkey entry for legacy pairing
This fix legacy pairing with passkey entry model when passkey
is fisr entered on local side. Replying with error in that case
is bogus as we should just wait for remote confirm.

Change-Id: I75480802928fd29d21617aa9250f90df647eb9a2
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz b4b395845a Bluetooth: GATT: Fix compilation error
List container changes apparently were merged in the wrong order causing
leaving it with a compilation error.

Change-Id: Ib9d9502ddb39330c262e495a33592d0340713d83
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 20:54:34 +02:00
Anas Nashif 8c7aa9aa85 Merge "Merge bluetooth branch into master" 2017-02-10 16:37:56 +00:00
Luiz Augusto von Dentz a8ed185615 Bluetooth: Convert FOR_EACH macro instances to use CONTAINER
Change-Id: I02c31842db5df10dda3e15bff370d2e459cc909d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 16:16:15 +00:00
Arun Jagadish 40f91b7105 Bluetooth: AVDTP: Moving structures to headerfile
Moving AVDTP structure - bt_avdtp_req,to header file.

Change-Id: I6e3bbc9e5b45ae7009cc5d94ae50a08b0490f4fa
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-10 10:37:05 +00:00
Johan Hedberg 6c995a5053 Bluetooth: Fix missing connection cleanup in some scenarios
If the TX thread is not in k_poll() when conn->state gets set to
DISCONNECTED and a dummy buffer is pushed to conn->tx_queue the
bt_conn_prepare_events() function would have failed to add the
connection to the poll list for cleanup. To ensure the cleanup always
happens introduce a new flag that indicates that a cleanup must
happen. The extra benefit of the flag is that we no-longer need a
dummy buffer, but can simply use the conn_change signal to wake up the
TX thread.

Change-Id: I369584d305261ab3666b931c786daff9d131d228
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-10 10:09:10 +02:00
Szymon Janc fb3317b7a1 Bluetooth: Fix not clearing signaled flag for conn_change signal
From k_poll_signal_init() documentation:
The poll signal contains a 'signaled' field that, when set by
k_poll_signal(), stays set until the user sets it back to 0. It thus
has to be reset by the user before being passed again to k_poll() or
k_poll() will consider it being signaled, and will return immediately.

Change-Id: I55daac92dd6293ac653fd7fa0f907b0b7fd99d65
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-10 06:18:05 +00:00
Luiz Augusto von Dentz 92e8d91332 Bluetooth: GATT: Fix not updating previous node
When iterating to the subscriptions to be removed the code has to keep
a reference to the previous node but it case the subscription matches but
doesn't need to be removed it doesn't update the prev node which may
corrupt the list in case the next node end up being removed.

Change-Id: Ic5448f01bf78d293f93b9a7078a0147385ea1d23
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 08:16:41 +02:00
Arun Jagadish 93e28c75fe Bluetooth: AVDTP: Add AVDTP Discover Function Definition
Implementation of Send AVDTP_DISCOVER functionality

< ACL Data TX: Handle 256 flags 0x00 dlen 6
      Channel: 64 len 2 [PSM 25 mode 0] {chan 0}
      AVDTP: Discover (0x01) Command (0x00) type 0x00 label 0 nosp 0

Change-Id: Ieb6d1e5379d8933d57f3b1399f091378ce3c0756
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-08 11:02:09 +00:00
Jonathan Gelie 048a15bcc8 Bluetooth: GATT: fixing unsubscription
If subcription was found within the subscription list,
we have check if remains identical subscription
from the next node.
Otherwise none unsubscription is realized.

Change-Id: I38132d7c80575801885b8057902f3d4666b08aea
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-08 11:00:06 +00:00
Johan Hedberg ce2d74a58a Bluetooth: Fix incorrect checks for command buffer user data
If the buffer given to hci_cmd_done() is not from the command buffer
then using the cmd(buf) macro is not valid. Simply bail out from
hci_cmd_done() if this is an event that didn't have a matching command
buffer.

Change-Id: Id8357a23a307f4ef3a9214a4e1f7d853a18cb907
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-08 11:59:50 +02:00
Johan Hedberg 5b80603dbd Bluetooth: Controller: Use LL_ASSERT instead of BT_ASSERT
The controller code should not use BT_ASSERT directly.

Change-Id: If0b7d8e21d2ab4569a564bd03e36e4eb9204c595
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-07 12:29:58 +00:00
Szymon Janc afab7e1c01 Bluetooth: L2CAP: Make l2cap_br_send_conn_rsp return void
This function cannot fail.

Change-Id: I6b3393e0cfe1c334536e26c2715d5aff44c6dfd8
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:46 +00:00
Szymon Janc 7ee83b6c62 Bluetooth: SDP: Make bt_sdp_create_pdu static
It is not used outside of sdp.c and has no declaration.

Change-Id: I420a6b98d1b46fedffa29d042267b9c606d04c46
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:35 +00:00
Szymon Janc 22ada7b063 Bluetooth: L2CAP: Remove dead code
l2cap_create_le_sig_pdu always returns valid pointer.

Change-Id: I1510dc9ae387b426d7280f213e9d22b9a6a8418a
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:24 +00:00
Szymon Janc 69a52d82c9 Bluetooth: Remove some dead code
bt_l2cap_create_pdu always returns valid pointer.

Change-Id: Id525d19c096407150a7370396ed557290fbc35c5
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:13 +00:00
Szymon Janc 295e8e575c Bluetooth: Use assert when getting net buf with K_FOREVER
net_buf_alloc called with K_FOREVER should always return valid pointer.
Returning NULL indicated kernel bug.

Change-Id: I6c317de2d98723d0c1a0618e91490a2128f69f06
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:01 +00:00
Sathish Narasimman 54eedffd58 Bluetooth: HFP HF: Remove unused variable 'buf'
'buf' variable of type struct net_buf was one of the arguments for
finish callback in response to each AT command sent. 'buf' variable
not used in that function. So removed 'buf' variables from the argument
list.

Change-Id: I7d6aa6082f524012ae13a04426915076130ddf69
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 18:19:31 +00:00
Jonathan Gelie a42e4f694f Bluetooth: GATT: set subscribe value to zero for unsubscription
Subscribe value is set to zero before calling notify callback,
to distinguish a subscription failure from an unsubscription
on disconnection (when flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE is set).

Change-Id: Ia91220492d82041b2c385bf88a15180387e7a483
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:44:01 +00:00
Sathish Narasimman ccecfaac6a Bluetooth: HFP HF: Disconnect rfcomm on SLC error
If found error during service level connection disconnect rfcomm.

Change-Id: Ida425375975b8d60ab1024d07a8ffe7745ae0b54
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 17:43:21 +00:00
Jonathan Gelie b3ac77becd Bluetooth: GATT: introduce volatile subscription flag
Some application protocol required non-persistente subscription
across connection even in bonded case.
Flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE specify if subscription
must be remove during disonnection.

Change-Id: I1bc2bbbb4bc86f58905e44a7eb267ca0871f2fdb
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:43:18 +00:00
Sathish Narasimman 8fe69090e5 Bluetooth: HFP HF: Indicate disconnect to application
Invoke disconnected application callback when rfcomm is disconnected.

Change-Id: Icdefa8ee0b8f061f7db75a73e7f7ed4044817c5a
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 13:01:07 +00:00
Luiz Augusto von Dentz 31016448b4 Bluetooth: GATT: Fix not removing subscriptions safely
The subscriptions callback may free or reuse the subscription so all
instances that where this could happen need to safely fetch the next
element which is why this changes switch to use sys_list_t as it has
SYS_SLIST_FOR_EACH_NODE_SAFE.

Change-Id: I37d51f27116ea0c057b560924a9416676477597b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-06 11:18:57 +00:00
Sathish Narasimman 7fe2a96fc2 Bluetooth: HFP HF: Enable extended AG Error Result Code
Send standard AT+CMEE command used to enable the use of result
code +CME ERROR.

< ACL Data TX: Handle 256 flags 0x00 dlen 18           [hci0] 23.101226
      Channel: 67 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x40
        41 54 2b 43 4d 45 45 3d 31 0d 40                 AT+CMEE=1.@
> ACL Data RX: Handle 256 flags 0x02 dlen 15           [hci0] 23.127140
      Channel: 64 len 11 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 6
         FCS: 0x86
         Credits: 1
        0d 0a 4f 4b 0d 0a 86                             ..OK...

Change-Id: I246c25252440c9c973e1f90156dab44c48f02c3a
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 10:32:24 +00:00
Sathish Narasimman ece5865b2e Bluetooth: HFP HF: Service level connection completed
Once the service level connection is done call the connected
callback.

Change-Id: I7541e221d4c03c939682ec70f1d9c093f87ceb09
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 09:36:54 +00:00
Johan Hedberg dc70415dc4 Bluetooth: Merge HCI command and connection TX threads
We can go further with taking advantage of k_poll and merge the
connection TX thread together with the HCI command thread, thereby
saving even more memory.

Change-Id: I1792056fd4621d62c7cd05929094033acca45c74
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 1fb0351f9a Bluetooth: Merge bt_conn TX threads into a single one with k_poll
Now that the k_poll API is available we can use it to have single
connection TX thread instead of multiple ones, which helps reduce the
per-connection memory overhead by a substantial amount.

Change-Id: Icb5d4da87cf0d660bba8da43186d1e76f41c825a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Arun Jagadish aa16b02bb5 Bluetooth: AVDTP: Remove buffer pool
Removing the module specific buffer pool. If future, use common acl_tx_pool.

Change-Id: Ie1452f981ef43642715be395315845cc2d9bb285
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 192db7179c Bluetooth: conn: Use delayed work for LE connection timeout
Detaching the timeout from the tx_thread lets us prepare for merging
all TX threads into a single one with the help of k_poll(). There's no
need to define a new delayed work object since the existing connection
parameter update object and connection timeout will never need to run
in parallel. Additionally, but some CONFIG_BLUETOOTH_CENTRAL guards to
void pulling in unnecessary code when Central role is not enabled.

Change-Id: Ia1f222aa052edcecd484a924f2d9a63a3b8fd11f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 50678b03cb Bluetooth: Reuse HCI command buffers for the command response
Reduce the pressure on the common RX buffer pool by reusing HCI
command buffers also for the Command Status or Command Complete
response to them. This also implies removing the existing Kconfig
variable for the command buffer sizes since the size is also dependent
on maximum Command Complete event sizes. Instead, reuse the RX buffer
size also for HCI Command buffers.

Change-Id: I006b287d64a0c9ca40de741aa9a424a49a927385
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 6c0e9720e2 Bluetooth: Controller: Redesign response buffer allocation for commands
With an upcoming patch the HCI command buffers will be reused for the
Command Complete/Status HCI events. The controller HCI code needs some
refactoring to postpone the event buffer allocation so that the
parsing state of the HCI command buffer isn't touched.

Change-Id: I1f614fb9f02ed1886ca84198fbc8c64abc29e44f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 743379c21f Bluetooth: Kconfig: Merge headroom reserve variables into a single one
A subsequent patch will start reusing HCI command buffers for
receiving the response, so the distinction of received vs sent data
headroom would just make the code unnecessarily complex. Instead, just
merge these two variable into a single one.

Change-Id: I31d846331939f1a2270df7ed0c75112825e16493
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg be139268b3 Bluetooth: Add convenience macros for common header sizes
The C pre-processor doesn't allow using sizeof() in comparisons such
as "#if FOO < sizeof(bar)". To make it possible to use such
comparisons where the sizes of headers are involved, introduce helper
macros for the headers instead of always having to hard-code magic
numbers into the code.

Change-Id: Iaf654cb4aaa49e83360901f5b01225ba4b952854
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 800ed72293 Bluetooth: Fix buffer leak when HCI driver send() fails
If the driver send() fails we need to free up bt_dev.sent_cmd.

Change-Id: I41b6293dfe09f1d94d7f85663ddbebed40cf6e90
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa 178482fdb1 Bluetooth: SDP: Add API to get SupportedFeature attribute
Adds API to allow user get SupportedFeatures attribute ID.

Jira: ZEP-1112

Change-Id: I91a1bf548d99c5c7cc75682aed19e89390350533
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa a7e4eaafaa Bluetooth: SDP: Add API to get ProfileDescriptorList attribute
Adds API enabling retrieve remote profile version.

Jira: ZEP-1112

Change-Id: I9b1a9a15848d5c485ec3dd2b405a6d51ce9b020e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa 15520c5ce9 Bluetooth: SDP: Get ProtocolDescriptorList attribute internals
Adds API to get available specific information included in protocols UUID
tree during parsing Protocol Descriptor List attribute. Usually it's to
be remote Server Channel/PSM number operating on applicable protocol.
There're a few helper functions added to be able parse and retrieve such
information from raw record data.

Jira: ZEP-1112

Change-Id: I736a780b95ba54821d36e6011b739f5ff37cd64f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg e5305f1ab5 Bluetooth: Fix using correct variable type for interrupt mask
The irq_lock() API returnes unsigned int.

Change-Id: I12d2e980dca621d44ac9776e2961f504cb747c94
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 54e34f4431 Bluetooth: Fix checking for invalid public address
Both all-zeroes and all-ones addresses are invalid. Fix the check for
this so that we fall back to a static random identity address when
needed.

Change-Id: I17cf903e0f3ed321311d86d09bed19343c2c801a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Jaganath Kanakkassery 43a5810793 Bluetooth: RFCOMM: Use common tx pool for control packets
This will reduce memory consumption by 23 bytes per session.

Change-Id: I1831b59881eaefb68f93c30e298b8f97d63c7428
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-02-05 22:39:25 +02:00
Jaganath Kanakkassery c5bb728d66 Bluetooth: RFCOMM: Fix session timer during acl disc
Session idle timer should not be started in dlc destroy if
session is already disconnected (which can happen in scenarios
like acl disconnection where in dlc is detached from session and
destroy will be called from tx thread) otherwise timer function will
get invoked for a disconnected session.

This patch moves starting of idle timer from dlc destroy to
the point dlc disconnect is recieved from remote since idle
timer is to handle only that scenario.

Change-Id: I94501515a182ff0e2348ba4e2df63100f2f52209
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-02-05 22:39:25 +02:00
Carles Cufi 2093c1ccf0 Bluetooth: hci_core: Use nRF5x FICR address
The nRF5x come preprogrammed from manufacturing with either a public or
random static BLE address in the FICR register. Use the random static
one when present instead of generating one during Bluetooth
initialization.

Change-id: Ic733cb926e0414e56d6f8be65b033692e914b72a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-02-05 22:39:25 +02:00
Johan Hedberg f23acadffe Bluetooth: Fix trivial coding style issue
Change-Id: I8a50fb6fe46d7a7deb6538f6a23bf5e58db2d52d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Kumar Gala edcb6ceb12 Bluetooth: hci_raw: Make bt_buf_get_rx args consistent
The hci_raw version of bt_buf_get_rx was expecting an int for timeout.
Let us int32_t instead so we match both the hci_core version and the
type that net_buf_alloc expects.

This addresses a possible build issue if/when int32_t differs from our
default (ie, newlib).

Change-Id: I69374c48da8f2b96fa2bd418ff505fbaacda11f0
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-28 08:43:41 +02:00
Johan Hedberg 4153b6ca1f Bluetooth: Kconfig: Make device name variable generic
Change BREDR_NAME to DEVICE_NAME so it can also be used as the LE
device name.

Change-Id: I9ef55d9dff098372d47d9d5754ad7a7163a65bc0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-28 08:43:41 +02:00
Piyush Itankar 4a014f3e81 Bluetooth: A2DP: Stream End Point Structure
Added structure definition for stream end points
and the a2dp stream.

Change-Id: I6d0cc08611f5179397bea6200eb9244d7c1cc8d6
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-28 08:43:41 +02:00
Sathish Narasimman 730b4f89d2 Bluetooth: HFP HF: Handle +CIEV reponse
The +CIEV reponse received from the AG is handle and value is
updated to the application.

> ACL Data RX: Handle 256 flags 0x02 dlen 22         [hci0] 114.667753
      Channel: 64 len 18 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 14
         FCS: 0x9a
        0d 0a 2b 43 49 45 56 3a 20 32 2c 30 0d 0a 9a     ..+CIEV: 2,0...

Change-Id: I771cdb422d201293d356151fa33ec485083b2356
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-28 08:43:41 +02:00
Arun Jagadish 1806804ad8 Bluetooth: AVDTP: Add AVDTP Discover API Prototype
Added AVDTP Discover Request API Prototype.

Change-Id: I661331634b64099e352efe12cacc9af5d4c7ce16
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-28 08:43:41 +02:00
Luiz Augusto von Dentz 278bd910d5 Bluetooth: L2CAP: Only set state for dynamic channels
Fixed channels don't really use channels state as they don't need
connection setup.

Change-Id: Ie8b1327db0269a45e9ccb6049f8dda87aa445fb5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-28 08:43:41 +02:00
Piyush Itankar 42a175f300 Bluetooth: A2DP: Adds accept state callback handlers
Adds state callback handler to allocate memory to AVDTP on an incoming
connection. Also, abstracts searching of free session as a function call.

Change-Id: Idee6b7a0507b0b75c0007717e351ca12de0cb5be
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-28 08:43:41 +02:00
Jaganath Kanakkassery 91f9c9cf1c Bluetooth: RFCOMM: Implement MSC Flow Control
This is mainly for backward compatibility with 1.0b devices and for
spec compliance. CFC is mandatory post 1.0b spec where in MSC FC
shall not be used.

FC bit in MSC is used to manage the flow control. If FC is 1 then
the device is unable to accept frames.

Implementation is done by reusing "tx_credit" as a binary semaphore
wherein it will be blocked if MSC is recieved with FC bit 1 and
unblocked if FC bit is 0. Once tx thread is scheduled then semaphore
should be always available until all the buf in queue is sent.

Change-Id: I91181668ec0f46ff0b02905dd97e4503fc1fa7a7
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-28 08:43:41 +02:00
Jaganath Kanakkassery 17ea79e733 Bluetooth: RFCOMM: Fix v24_signal in MSC response
v24_signal in MSC response should be the copy of it received
in the command.

Change-Id: I9723ba182bf5911025c7a57220cd70687ca785f3
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-28 08:43:41 +02:00
Sathish Narasimman d903b53e6b Bluetooth: AT: HFP HF: Handle unsolicited reponse
This implemnts the feature to handle the unsolicited response
received from the AG. In the hfp_hf.c file the unsolicited_cb function
process it.

Change-Id: I3ca6c8d4a1522d02f7160e2fe4ae1598cd93ce7e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-28 08:43:41 +02:00
Kumar Gala 8d4c1787bf Bluetooth: Controller: Use CMSIS NVIC APIs directly
Convert driver to use the CMSIS NVIC APIs rather than the internal
ones so we can remove them in the future.

Change-Id: Ib9fe696e8d5e55f60865d3fd958a035135ce517a
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-23 15:15:55 -06:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Johan Hedberg 1f35d47204 Bluetooth: Don't select TinyCrypt RNG for combined builds
For combined builds with Controller+Host the Controller's HW RNG is
used instead of TinyCrypts PRNG.

Change-Id: I4dbe85e547c057cf57ae0934b10866f2bb9f610d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 17:03:44 +00:00
Luiz Augusto von Dentz bfc0c35387 Bluetooth: L2CAP: Fix always using RX_BUF_COUNT as initial credits
In case the channel provides its own MTU and allocator it should be
able to store as much data as set in the MTU, based on that the code
can give enough credits to fill the entire channel MTU.

Change-Id: I291cf1bb643f200bde191914e814f681f4f65c3e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-18 17:03:34 +00:00
Lee Jones e74a91ce5a Bluetooth: Kconfig: Specify stack size for Bluetooth SPI
This value was found using trial and error.

Change-Id: I8dc3ea0759244bd28b97542f67a037f074d7b871
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2017-01-18 12:24:52 +00:00
Arun Jagadish d5b5af07be Bluetooth: AVDTP: Added params to AVDTP Request structure
Added pointer to store the callback function
from the application in the Request structure.

Added userdata param, to be used to fill AVDTP resp.

Change-Id: I8f3289545fdbbd91e4ed7f9983f4f4331d9b59a6
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-18 12:10:37 +00:00
Luiz Augusto von Dentz 514c9fa55f Bluetooth: L2CAP: Make sure state is correctly updated
This makes l2cap_chan_add updates the state to CONNECT so it doesn't
have to be done manually for both incoming and outgoing code paths.

Change-Id: I7331e49c675c83c6c1b184eeecc49c75c446a1ff
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-18 11:58:24 +00:00
Johan Hedberg 6cc35a751e Bluetooth: SMP: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I330769204914286bb98583dd89a3d849d4fcc128
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 11:57:23 +00:00
Johan Hedberg eb085514e3 Bluetooth: L2CAP: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I77d2e53f7aa7f2832513f235a63ad2cf14e73cb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:33:12 +00:00
Johan Hedberg fcc1fada58 Bluetooth: conn: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I78a3ccc6fcb84b431198f1a6c46aa6d50e9e9cd1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:23:36 +00:00
Johan Hedberg f036dd9ae8 Bluetooth: hci_core: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I4da93076a27a33b15a9b9119cfe5a1ff68acba0b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:21:08 +00:00
Johan Hedberg 645f867444 Bluetooth: Take advantage of IS_ENABLED macro for BT_DBG
The new IS_ENABLED macro allows exposing conditionally enabled code
always to the compiler, even though it may not ultimately end up being
built. This is in particular useful for letting the compiler catch any
logging format string errors. Introduce a new BT_DBG_ENABLED macro
that c-files need to define before including <bluetooth/log.h> in
order to choose whether BT_DBG() logs are enabled or not.

When no Bluetooth logs are enabled the patch also modifies the log
macros to have the format strings checked with the help of the
__printf_like annotation and empty static inline functions.

Change-Id: Ie6bc8e10727b5b306f3ed0f94089a07a22583d9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 08:28:06 +02:00
Johan Hedberg 1adc58fd79 Bluetooth: Introduce a new connection parameter request callback
Introduce a new callback to bt_conn_cb that allows the application to
decide whether the accept or reject an incoming connection parameter
request. If the request is accepted the callback allows the
application to also adjust the values to what it thinks are more
appropriate.

The Zephyr Bluetooth API allows multiple registered connection
callbacks, so in principle there may be multiple le_param_req()
callbacks. It's recommended for an app to just use one (for clarity),
but if there are multiple the app is responsible for managing
potentially different requirements. In the case of multiple callbacks
each callback will receive the modified parameters in case a previous
callback modified them.

Jira: ZEP-1474

Change-Id: I098db5791aac521f1edfa9fefdf847db0a27e3a5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 68732ef9d5 Bluetooth: L2CAP: Remove RECV_RESERVE from BT_L2CAP_RX_MTU
The BT_L2CAP_RX_MTU is counted starting with the BLUETOOTH_RX_BUF_LEN
variable, which doesn't include the BLUETOOTH_HCI_RECV_RESERVE
contribution (this would only be valid if we started subtracting from
BT_BUF_RX_SIZE).

Change-Id: I1ab3eaf8907946c56c2a9fe16b2074f3a3027a0f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 6f114e0a62 Bluetooth: Remove ACL details from BT_BUF_RX_SIZE
BT_BUF_RX_SIZE is used for the RX buffer pool which is used for both
ACL data and HCI events. It should therefore not contain any
ACL-specific details. This patch removes the ACL header size from the
macro and instead makes taking it into account the responsibility to
the Kconfig option. Since buffer sizes are anyway rounded up to the
nearest multiple of 4 the default goes up from 70 to 76.

Change-Id: I41274d9131e7529d41c16bd66de95637fb150a29
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Luiz Augusto von Dentz 27fb0aab10 Bluetooth: L2CAP: Fix using CONFIG_BLUETOOTH_RX_BUF_LEN as MTU
CONFIG_BLUETOOTH_RX_BUF_LEN shall not be used as RX MTU since it doesn't
account for ACL and L2CAP headers.

Change-Id: Ic3ebb4bd13d86a39174840f0ab625b66e863018a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-17 08:44:21 +02:00
Jaganath Kanakkassery 461591728f Bluetooth: RFCOMM: Implement Aggregate Flow Control
This is mainly for backward compatibility with 1.0b devices and for
ICS & spec compliance. CFC is mandatory post 1.0b spec where in
Aggregate FC shall not be used.

Aggregate FC is managed using FCOFF and FCON messages. This is for
the entire session which means that all the dlcs in that session
will be affected.

Implementation is done using binary semaphore wherein it will be
blocked when FCOFF is recieved and unblocked in FCON.
Once tx thread is scheduled then semaphore should be always available
until all the buf in queue is sent.

Change-Id: Ibfd2c4d033cef64c238ead83474f9e171572de1e
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-17 08:44:21 +02:00
Carles Cufi 93d7512215 bluetooth: hci_core: Fix conn params validity check
Bluetooth Core Specification v5.0, Vol 2, Part E, 7.8.12:

"The Supervision_Timeout parameter defines the link supervision timeout
for the connection. The Supervision_Timeout in milliseconds shall be larger
than (1 + Conn_Latency) * Conn_Interval_Max * 2, where Conn_Interval_Max is
given in milliseconds."

Let's remember that:
conn_interval is given in units N * 1.25 ms
sup_timeout is given in units N * 10 ms

sup_timeout_ms > (1 + latency) * (conn_interval_ms * 2)
yields:
sup_timeout_n * 10 > (1 + latency) * (conn_interval_n * 1.25 * 2)
yields:
sup_timeout_n * 10 > (1 + latency) * (conn_interval_n * 2.5)
yields:
sup_timeout_n * 4 > (1 + latency) * (conn_interval_n)

Change-id: I30ac1d375a1baaa3e61f4c29b1165110599e1f7c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-17 08:44:21 +02:00
Johan Hedberg e564de0deb Bluetooth: Prefer struct bt_le_conn_param over individual values
This reduces stack pressure a little bit, and also paves the way for
introducing an application callback for accepting an incoming
connection parameter update request.

Change-Id: Ib02c14e27cbe34f85d663f36abd0597683ae1dc1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg a54292afc9 Bluetooth: GATT: Fix missing connection address comparison
When receiving notifications we should be properly matching against
the remote address of subscribed peers.

Change-Id: Ibcba1101aac418fd02f9068667f84e8294aade07
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 1dccc36428 Bluetooth: Remove unused bt_hci_driver_unregister() API
There are no users of this API and no (currently) envisioned use cases
for it. Remove it for now - it can always be brought back later if
there's a need for it.

Change-Id: I6530e096e3671c844a3f7dea8856147ffc716d71
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Sathish Narasimman 10bb3bbba5 Bluetooth: AT: Rename enum at_cmd_type elements
Rename the elements of 'enum at_cmd_type' in order to follow the
name spacing. Which should have prefix of 'AT_' for each elements.
This patch also involves the renaming, corresponding handler
function of 'enum at_cmd_type' with prefix 'at_' i.e 'cmd_start' as
'at_cmd_start'.

Change-Id: I722a25954163c06e131b94042c6a18e1e3458f6e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 815e15e3b2 Bluetooth: Controller: Rename hci_le_rand to bt_rand
Rename hci_le_rand to bt_rand and make its parameter types compatible.
This also includes updating rand_get() to use size_t instead of
uint32_t & uint8_t.

Change-Id: I4d434dfbbaf339b1bc7b451d358d07a291dd0375
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 4cd92c90c9 Bluetooth: Use the controller bt_rand() whenever possible
The controller bt_rand() ties into the hardware which uses less memory
and is more power-efficient than using the TinyCrypt PRNG.

Change-Id: I7570d18f3e84dae3d5c2d3322b5d37cd3e8f3b6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 767c92e176 Bluetooth: Consolidate most outgoing ACL TX buffers into a single pool
Having TX buffers split into numerous pools has the downside of
increased memory consumption. This patch takes the initial step to
consolidate these pools into a single one, saving about 248 bytes of
RAM for a basic configuration.

Change-Id: I449ba18b44a9a6af68e9a2c44f19a9286eb88b14
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Arkadiusz Lichwa 4880e717b1 Bluetooth: ATT: Fix redundant sys_slist call
Uses sys_slist_get function to get node and automatically, if valid,
remove one from the list.

Change-Id: I4cee6fbb064bf9644efdb7e6771e702b1f08678a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-17 08:44:21 +02:00
Arkadiusz Lichwa 53fde44046 Bluetooth: UUID: Fix format specifier in 128-UUID
Fixes not supported now format specifier.

Change-Id: Ia01ea3fd18acfeed6f4a3899334911dac1b76643
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 696b89da0f Bluetooth: Fix potential race condition in bt_pub_key_gen()
It's possible for the Public Key to be available by the time that the
bt_hci_cmd_send_sync() returns, so we need to make sure the flags have
the right values no matter what.

Change-Id: I053093b6611af360f52b14ddca50d409388f9475
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 14:48:01 +02:00
Arun Jagadish 231050a966 Bluetooth: AVDTP:Add Accept Incoming connection cb
Added Accept Incoming connection callbacks for the A2DP layer

Change-Id: I8aee32a97916ed9fc9c4050151e7395e288c404c
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-05 11:33:24 +00:00
Jaganath Kanakkassery c37b59b3bb Bluetooth: RFCOMM: Implement timer in session
As per the spec, the station which disconnects the last dlc
should disconnect session also. In case if remote does not
do it we need to disconnect otherwise rfcomm will be connected
without any dlc. So this starts an idle timer to handle the
above scenario.

This also starts a disconnect timer to handle in case remote
does not respond to session disconnect request.

Change-Id: I3b45aa5bf4c35fd81dc10974f2b0b6d4cfe4ea7d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 09:36:08 +00:00
Sathish Narasimman b5891d1ddf Bluetooth: HFP HF: Rename cind_status_handle_values
Rename cind_status_handle_values to ag_inidcator_handle_values.
Because the same function will be reused internally for +CIEV
Callbacks.

Change-Id: I875064de17700d72ea89dbbe0f5cb6554c813a5e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Sathish Narasimman 4b323cd72e Bluetooth: AT: Reset AT and CMD state
Reset AT and COMMAND state to process unsolicited response received
after processing result recieved for AT command sent to AG.

Change-Id: Id2a5827ce5b098336291696157027699479478cf
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Sathish Narasimman 166a8f762a Bluetooth: HFP HF: SLC Enable indicator status report
End of service level connection(call waiting or 3-way calling bit
and HF Indicators bit not set at present). AT+CMER is sent to
enable indicators status reporting in the AG side.

< ACL Data TX: Handle 256 flags 0x00 dlen 24                  [hci0] 102.898017
      Channel: 68 len 20 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 16
         FCS: 0x40
        41 54 2b 43 4d 45 52 3d 33 2c 30 2c 30 2c 31 0d  AT+CMER=3,0,0,1.
        40                                               @
> ACL Data RX: Handle 256 flags 0x02 dlen 15                  [hci0] 102.942198
      Channel: 64 len 11 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 6
         FCS: 0x86
         Credits: 1
        0d 0a 4f 4b 0d 0a 86                             ..OK...

Change-Id: I1630bf40f0f84e6e037b405854eb0c1c4ea691c4
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Szymon Janc 46a7989a5d Bluetooth: hci_ecc: Verify LE Generate DHKey command parameters
Reply with Invalid Parameters Command Status if incomplete command
was received.

 HCI Command: LE Generate DHKey (0x08|0x0026) plen 60
        invalid packet size
        f6 0f 79 a0 3c 4f 3e 90 40 66 6b 1d 93 64 af ed  ..y.<O>.@fk..d..
        03 ec b4 5f 29 cf 6d 26 42 02 61 b9 29 9a bf 0b  ..._).m&B.a.)...
        5e da 86 8b 3a ef aa e8 13 3d 87 de a7 dc 36 57  ^...:....=....6W
        25 89 56 43 e8 2a 73 56 62 60 fa 81              %.VC.*sVb`..
> HCI Event: Command Status (0x0f) plen 4
      LE Generate DHKey (0x08|0x0026) ncmd 1
        Status: Invalid HCI Command Parameters (0x12)

Change-Id: I9c4e798096023f0807e8d353ac3318e3d13dc6f7
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-01-05 08:49:17 +02:00
Piyush Itankar 4b5e19d21c Bluetooth: A2DP: Removes confirmation callback registration
Confirmation callbacks needed not be registered with AVDTP
during A2DP initialization

Change-Id: I2cdf8c5a283775e49fa6e7e9404024e26d05a767
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-05 08:49:17 +02:00
Jaganath Kanakkassery 665937a19f Bluetooth: RFCOMM: Implement timer in dlc
This basically implements timer for connection and disconnection.

Conn timer will be started when dlc is initialized and stopped
when it is connected. Authentication if any, will be also included
in this timer.

Disc timer will be started during disconnect initiation.

Change-Id: Ia4b74e478fefa42db21aef528e623a24c72ddf7f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:17 +02:00
Jaganath Kanakkassery 3b397076ab Bluetooth: RFCOMM: Rearrange fns to avoid forward declaration
Moves rfcomm_send_disc() and rfcomm_session_disconnect() to call it
while doing timer implementation.

Change-Id: I5805d31fb45181193385f055716c8518d68cc4a1
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:17 +02:00
Arkadiusz Lichwa b11f30a246 Bluetooth: SDP: Update 'no records found' code comment
Adds more descriptive comment to the code responsible for handling no
resolved UUID case.

Jira: ZEP-1112

Change-Id: I1af07949e19246d51bab9df05504a90f5fb22bb2
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:17 +02:00
Arkadiusz Lichwa 7ec0c37ec3 Bluetooth: SDP: Add UUID reference to user callback
User may want to know when getting called user UUID callback handler
on what UUID the result data was retrieved from server.

Jira: ZEP-1112

Change-Id: Iabb2dbdf0f3cfdb24244e052f094c7549164b199
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:17 +02:00
Vinayak Chettimada 2d064eef89 Bluetooth: Controller: revert to event callback inside radio ISR
In order that host can continue a connection event by
enqueuing packets, the number of completed packets event
needs to be generated as soon it arrives on air. Hence, the
Controller now calls the radio_event_callback on every radio
Rx complete ISR.

The callback executes at the Radio ISR priority, take care
to only do as little as necessary in the callback, say, just
a semaphore give to wake up the hci_driver's thread.

Change-id: If48afd0f1390d450bc1e7ec66f1c9fd45208d9a4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:17 +02:00
Carles Cufi e979d656cc bluetooth: controller: Split events into normal and priority
For the host to be able to block on the recv_thread while waiting for a
number of completed packets HCI event, those are pulled from the radio
in a new, higher priority thread that also schedules the execution of
the lower priority event/ACL data recv_thread.

Change-id: I9d356bd297d0504cb16a032fb5fe5530693546e2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:17 +02:00
Luiz Augusto von Dentz ae6d92a4ef Bluetooth: ATT: Fix using k_fifo API with net_buf
net_buf shall not be used with k_fifo since net_buf_unref will assume
unused bytes in the beginning are actually fragments causing it to
unref them as well.

Jira: ZEP-1489

Change-Id: I5ce420de73b245dc20eb15ea4d8d0b6ba346e513
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg d64f47d956 Bluetooth: Create separate bt_recv_prio() API
Since callers of bt_recv() have so far anyway been required to know in
which context to call it (based on e.g. bt_hci_evt_is_prio) it's
cleaner to have two separate APIs: bt_recv and bt_recv_prio.

Change-Id: Icd0d9aed9c51ffd2def31432c4ffcc16a9f13ccd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 1094f00253 Bluetooth: Reduce the minimum RX buf count to 2
The recent redesign of the H:4 HCI driver means that the smallest
safest RX buffer count goes down to 2. Default is left at 3 however to
get a bit better performance.

Change-Id: I879c7bd3a769f973dfb9bd179d196ab91f9d2abe
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 2f191012c2 Bluetooth: Controller: Deprioritize adv report buffer allocation
Advertising reports are the only HCI events which we can drop if we
are low on buffers. Allocate them therefore with K_NO_WAIT rather than
K_FOREVER.

Change-Id: I0b7c92647f9be54b8746da837037725f8161a452
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 88b620550c Bluetooth: Controller: Switch to controller-side RX thread
Since the controller already uses a thread for receiving data it makes
sense to enable the BLUETOOTH_RECV_IS_RX_THREAD option.

Change-Id: I927b20c1a0afaea8d000df28cc220a69ae817d59
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 533d544d95 Bluetooth: Remove unused prio pool and buffer helpers
These are no longer used by anything.

Change-Id: Ic01467b4fbaae0af29ff5dc537f2e19744170a41
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg d79bdd74e9 Bluetooth: Controller: Use bt_buf_get_rx for buffer allocation
The controller uses K_FOREVER for the allocations so there's no
benefit in trying to use specialized pools (which exist to try to
guarantee availability of buffers for critical data).

Change-Id: I130f2c44a2f28af1284290e6a0b17dcba438862f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 38eef90d01 Bluetooth: hci_ecc: Delay event buffer allocation
Allocate the event buffers after the ECDH operations rather than
before them. This way we don't hold on to the buffer for potentially
multiple seconds while the buffer could be used for other things.

Change-Id: I0fcc34ec4bea2265b7df3c1de3587c2a850c974e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 8f766efc2f Bluetooth: Use bt_buf_get_rx in hci_ecc.c
There's no need to use the type-specific helpers since those anyway
map to the same pool.

Change-Id: I74750f545c989bb921abca58166fe591ed325856
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 53b1503ac8 Bluetooth: Kconfig: Fine tune options for RECV_IS_RX_THREAD
Give more sensible values when RECV_IS_RX_THREAD is configured.

Change-Id: I40b5bd88213d224cc29f63fccef6cecee5868f77
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 0174200cd0 Bluetooth: Add bt_buf_get_rx() helper API
The separate ACL & event pools will soon be removed, and it's already
now convenient to have a generic API when the exact type of the
incoming packet is not yet known.

Change-Id: I84cb65d17ea69ebeaeb21532fbf76689e4fb59a0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg bc8564bddc Bluetooth: Remove support for host flow control
The controller doesn't support this feature and the only driver that
was needing it (h4.c) will be converted not to rely on it in the next
patch.

Change-Id: Ia514b79b6d05aa128768c2355353b7797e8b8977
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 0a3a108762 Bluetooth: Introduce support for HCI driver-side RX thread
Add support for using the context bt_recv() is called in as the RX
thread, rather than having a separate host-side RX thread.

Change-Id: I256bfe5dece5272c816f2292e58747553189963d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg ea0dcd7587 Bluetooth: Refactor bt_recv() logic
Refactor the bt_recv() logic to make it easier to insert #ifdefs to
remove the RX queue and thread when the context calling bt_recv()
itself is sufficient enough.

Change-Id: Ie8c5a4dfe9533a4464a2e4909c94d3e1b185b55b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 57de98daf6 Bluetooth: Kconfig: Introduce BLUETOOTH_COMBINED_RX_BUF option
If the controller doesn't need ACL host flow control it may want to
optimize and use a single pool for incoming data.

Change-Id: Iec2a69bd2d7a127c7329d0423ab5ce6b73cb9904
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 6f429a38d8 Bluetooth: Kconfig Remove HOST_BUFFERS option
This option has not been used so far and will only contribute
unnecessary complexity in subsequent patches that introduce a concept
of combined RX buffers.

Change-Id: I53e0ce5155eebc352b84ba41b30ecb9d9958699f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 5d3d13f4a4 Bluetooth: SDP: Send resolved UUID data to user
After getting whole UUID response for SSA PDU request the user can be
informed about discovery results. Result data feeding the user is
splitted to logical record chunks if more than one record was found.
Every such portion represent unparsed SDP record prestripped from record
length. Each response record data passed to user starts from first raw
attributes data and the record response buffer's length tells exactly
about each record length. User UUID callback handler's return result
can drive delivery (dis)continuation of every such portion to the user.

Jira: ZEP-1112

Change-Id: Icec518ca7bab3c8dfef4a966d98e9d9004894bcc
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery 51e71ea0fd Bluetooth: RFCOMM: Increase dlc stack size to 256
This analyzes the dlc stack using stack_analyze() which is coming
as 188 with BLUETOOTH_DEBUG_LOG off.

dlc stack (real size 320):     unused 68       usage 188 / 256 (73 %)

So increase the stack size to 256.

Change-Id: Ie5d5f267f4f618747551f0bfd0e05ffb47e0bb91
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 164aa00f0f Bluetooth: SDP: Check room needed against user allocated
When getting very first SSA PDU response for given UUID we can extract
from it the counter telling us how much data will be delivered by server
to collect all complete response for given UUID. Let's use that
information to check if the room allocated by app is big enough for
collecting resolved data.

Jira: ZEP-1112

Change-Id: I91515da668d89e05755d64e427dee0936bf20323
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 7eacb0477c Bluetooth: HFP HF: SLC query indicators present value
Service level connection sending AT+CIND? and parse the response
to get the present value of the available indicators.
This patch also providing callback interface to application for
the indicators value received.

Also added doxygen comment for connected and disconnected callback.

< ACL Data TX: Handle 256 flags 0x00 dlen 17                   [hci0] 25.251358
      Channel: 67 len 13 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 9
         FCS: 0x40
        41 54 2b 43 49 4e 44 3f 0d 40                    AT+CIND?.@
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 25.262012
        Num handles: 1
        Handle: 256
        Count: 1
> ACL Data RX: Handle 256 flags 0x02 dlen 33                   [hci0] 25.293028
      Channel: 64 len 29 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 24
         FCS: 0x86
         Credits: 1
        0d 0a 2b 43 49 4e 44 3a 20 30 2c 30 2c 31 2c 33  ..+CIND: 0,0,1,3
        2c 30 2c 33 2c 30 0d 0a 86                       ,0,3,0...
> ACL Data RX: Handle 256 flags 0x02 dlen 14                   [hci0] 25.295006
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I7b2a89487e2d481391c51201e32b3287808f82dc
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 7782ccbd76 Bluetooth: AT: Change API name skip_whitespace to skip_space
skip_whitespace() API name is changed to skip_space(). Where the
skip_space function is to skip only SPACE(ASCII Dec: 32).

Change-Id: Ib28ffa45295912505bc27a986803ed0ae2b0002c
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 128ef4dd99 Bluetooth: HFP HF: SLC Connection send/parse CIND
Part of service level connection initilization. Sending AT+CIND=?
and parsing its response.

< ACL Data TX: Handle 256 flags 0x00 dlen 18                   [hci0] 20.888273
      Channel: 76 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x40
        41 54 2b 43 49 4e 44 3d 3f 0d 40                 AT+CIND=?.@
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 20.914998
        Num handles: 1
        Handle: 256
        Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 20.916863
        Num handles: 1
        Handle: 256
        Count: 1
> ACL Data RX: Handle 256 flags 0x02 dlen 142                  [hci0] 20.945835
      Channel: 64 len 138 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 1024
         FCS: 0x86
         Credits: 1
        0d 0a 2b 43 49 4e 44 3a 20 28 22 63 61 6c 6c 22  ..+CIND: ("call"
        2c 28 30 2c 31 29 29 2c 28 22 63 61 6c 6c 73 65  ,(0,1)),("callse
        74 75 70 22 2c 28 30 2d 33 29 29 2c 28 22 73 65  tup",(0-3)),("se
        72 76 69 63 65 22 2c 28 30 2d 31 29 29 2c 28 22  rvice",(0-1)),("
        73 69 67 6e 61 6c 22 2c 28 30 2d 35 29 29 2c 28  signal",(0-5)),(
        22 72 6f 61 6d 22 2c 28 30 2c 31 29 29 2c 28 22  "roam",(0,1)),("
        62 61 74 74 63 68 67 22 2c 28 30 2d 35 29 29 2c  battchg",(0-5)),
        28 22 63 61 6c 6c 68 65 6c 64 22 2c 28 30 2d 32  ("callheld",(0-2
        29 29 0d 0a 86                                   ))...
> ACL Data RX: Handle 256 flags 0x02 dlen 14                   [hci0] 20.947764
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I33126a19641b889f1749b642cbc5e63984d85b6d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 39e7350a13 Bluetooth: AT: Rename API's which uses term 'stream'
Rename the API's with 'list' which uses the term 'stream'.
For example 'at_open_stream' is renamed to 'at_open_list' and
the same applies for other API's which uses 'stream' in it.

Change-Id: I62bed70de3d85cd4890b10e04eba27ae2de1907c
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada a69cdca529 Bluetooth: Controller: Remove advertiser struct use in observer
Change-id: I2c332047d80167cb5823f5af605cb5edbcb5e9fe
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 0565945a5c Bluetooth: Controller: fix DLE conditional compilations
Fix missing conditional compilation of Data Length Update
feature.

Change-id: I93aa1da2145a33095c220c863ed1457bb27a7aec
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Johan Hedberg 34cff06a72 Bluetooth: hci_ecc: Fix incorrect private_key size
The private_key parameter to generate_keys is supposed to be 32 bytes
in size, i.e. an array of 8 uint32_t variables.

Change-Id: Ia891fd68bfd8662983b898084e5a8524b7a9b8e2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa c97220c1d6 Bluetooth: SDP: Allocate user delivered memory for resolved data
Adds driven by user params buffer location to be populated by UUID
resolved data. Corresponding handlers responsible for connected and
disconnected states of L2CAP transport channel used by SDP PSM traffic
automatically allocates and unrefs such memory. Data receiving handler
performs buffer fill up.

Jira: ZEP-1112

Change-Id: I8aa97e6e69344dca0f241a4e9097acac75e14a7c
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 3304cbc41b Bluetooth: SDP: Validate SSA response PDU
Adds two extra checks against invalid length of attribute payload
frame.

Jira: ZEP-1112

Change-Id: I089442a5b9631471f9f394860681f1483e021c43
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 7c6063c4ec Bluetooth: SDP: Enable resolve all user delivered UUIDs
Iterates all UUID params list delivered by user. When iteration finish
release SDP client L2CAP transport channel.

Jira: ZEP-1112

Change-Id: I0602e32a5296a05719ad1385b4aff537350b3e7d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada d5d473b0f8 Bluetooth: Controller: replace work with mayfly
This commit introduces a very light-weight and lock-less
scheduling of the Controller's deferred function calls
called the Mayfly.

Earlier work implementation used in the Controller had an
O(n) to schedule a function in a linked list that used IRQ
lock during modification of the linked list in the
Controller's ISR executions.

Mayfly is a compile time configurable matrix of queues
where an execution context-safe queue exists between two
execution context, one being the caller and the second
being the callee. Callee(s) are run in a software interrupt
but can also be run in an OS thread.

There are minor clean ups too in this commit related to
folder structure.

Change-id: I5ff44dcee6679d2f5ce9e8437d98d6c868782f3d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 8bd73aeba7 Bluetooth: Controller: add memq_peek interface
Change-id: I276eddd5e347a5930cff3158ee9aaec0cc7a1585
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 85cfff0d92 Bluetooth: Controller: Kconfig fast encryption setup feature
Enable connection encryption setup in 3 connection
intervals. Peripheral will respond to Encryption Request
with Encryption Response in the same connection interval,
and also, will respond with Start Encryption Response PDU in
the 3rd connection interval, hence completing encryption
setup in 3 connection intervals. Encrypted data would be
transmitted as fast as in 3rd connection interval from the
connection establishment. Maximum CPU time in Radio ISR will
increase if this feature is selected.

Change-id: I16f2863fc2aaed624826505739519d4de1ac44c5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 404e7662e0 Bluetooth: Controller: Kconfig Tx buffer size
Add Kconfig configuration to select Tx buffer size, this
value will be returned in the HCI LE Read Buffer Size
command response.
This configuration will allow lower Tx RAM usage when
larger PDU sizes are desired in Rx direction only.

Change-Id: I5106a448d78a0754c4b0f6fa61fd5dcacd87a67c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 27353bb655 Bluetooth: Controller: Kconfig connection RSSI measurement
Add Kconfig configuration and conditional compilation of
RSSI measurement during a connection.

Change-id: I5a2f23f76a7cbbd9569d53d31899a472bf39d3ee
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 08fcc44b8a Bluetooth: Controller: Kconfig Data Length Update feature
Add Kconfig configuration to conditionally enable Data
Length Update procedure support in the Controller.
This will save CPU time, flash and RAM, if this feature is
not desired.

Change-id: I4515c0c7cf9aeb333a289397ae3c9bac04a08e4e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 4fb2947b61 Bluetooth: Controller: fix LE Ping conditional compilations
Add additional conditional compilation of code not needed
when LE Ping is disabled in Kconfig.

Change-id: Idab40b1371488e06a6f2009fb553f7655b7b86f3
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa d333b3892b Bluetooth: SDP: Handle SSA PDU response
Adds initial handling of SDP Service Search Attribute response PDU.
Currently attributes data are not collected. Main focus was done on
proper handling PDU continuation state to be able receive whole
requested SDP record(s) if found for given UUID.

< ACL Data TX: Handle 74 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 1 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 1 len 59
        Attribute bytes: 48
        Continuation state: 8
        cd 91 5a 58 30 00 00 00                          ..ZX0...
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 2 len 23
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 8
        cd 91 5a 58 30 00 00 00                          ..ZX0...
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 2 len 59
        Attribute bytes: 48
        Continuation state: 8
        cd 91 5a 58 60 00 00 00                          ..ZX`...
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 3 len 23
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 8
        cd 91 5a 58 60 00 00 00                          ..ZX`...
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 19
      Channel: 64 len 15 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 3 len 10
        Attribute bytes: 7
        Continuation state: 0
        Combined attribute bytes: 103
          Attribute list: [len 99] {position 0}
            Attribute: Service Record Handle (0x0000) [len 2]
              0x00010001
            Attribute: Service Class ID List (0x0001) [len 2]
              UUID (3) with 2 bytes [0 extra bits] len 3
                OBEX Object Push (0x1105)
            Attribute: Protocol Descriptor List (0x0004) [len 2]
              Sequence (6) with 3 bytes [8 extra bits] len 5
                UUID (3) with 2 bytes [0 extra bits] len 3
                  L2CAP (0x0100)
              Sequence (6) with 5 bytes [8 extra bits] len 7
                UUID (3) with 2 bytes [0 extra bits] len 3
                  RFCOMM (0x0003)
                Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                  0x09
              Sequence (6) with 3 bytes [8 extra bits] len 5
                UUID (3) with 2 bytes [0 extra bits] len 3
                  OBEX (0x0008)
            Attribute: Browse Group List (0x0005) [len 2]
              UUID (3) with 2 bytes [0 extra bits] len 3
                Public Browse Root (0x1002)
            Attribute: Bluetooth Profile Descriptor List (0x0009) [len 2]
              Sequence (6) with 6 bytes [8 extra bits] len 8
                UUID (3) with 2 bytes [0 extra bits] len 3
                  OBEX Object Push (0x1105)
                Unsigned Integer (1) with 2 bytes [0 extra bits] len 3
                  0x0100
            Attribute: Unknown (0x0100) [len 2]
              OBEX Object Push [len 16]
            Attribute: Unknown (0x0303) [len 2]
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x01
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x02
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x03
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x04
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x05
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x06
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0xff

Jira: ZEP-1112

Change-Id: Ie282782fba6ef06c6826b3e624f83c8f4c94ebbe
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Carles Cufi 4b7cdd499f bluetooth: Tune stack sizes after measuring with hci_uart
The following readings were obtained after running the peripheral and
central_hr apps in qemu combined with the controller (hci_uart) on nRF51
and nRF52:

Main Stack 380
Idle Stack: 68
ISR stack: 532
Controller RX Stack: 388
HCI TX Stack: 516

The numbers set in this change provide a safety margin from the ones
measured empirically.

Change-id: Ice7ad7f081502e0ea1accf856a7937c0bf0783b2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa ce61122cdf Bluetooth: SDP: Introduce ContinuationState of PDU
Adds initial handling of PDU Continuation State. It has crutial role
to interact with SDP server when receiving partial SDP PDU responses.

< ACL Data TX: Handle 77 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Request (0x06) tid 3 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
> ACL Data RX: Handle 77 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Response (0x07) tid 3 len 59
        Attribute bytes: 48
        Continuation state: 8
        8d 55 59 58 30 00 00 00                          .UYX0...

Jira: ZEP-1112

Change-Id: I53ea9ae64c3f2685c9a12be3683dfc3a95aa8bf9
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery 5f3ce62eed Bluetooth: Fix reserve param of bt_l2cap_create_pdu()
reserve parameter of bt_l2cap_create_pdu() is incorrectly passed
as timeout.

Change-Id: Ieed293f52c2e98f16f1e43c498140178703236db
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Carles Cufi 80f000ab43 Bluetooth: Rename SEND_STACK to TX_STACK_SIZE
For consistency with RX_STACK_SIZE and the rest of stack sizes, rename
to use the normal naming scheme.

Change-id: Ib8d484482466fa8d629e6329e07b927abdd6f598
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 714718a33d Bluetooth: SDP: Validate Transaction ID of PDU
Adds check on receiving side whether current SDP PDU response matches
correcponding SDP PDU request.

Jira: ZEP-1112

Change-Id: Ide8da54fe38f12d3bcb1e7d056050c038b7ec065
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada b37e285c03 Bluetooth: Controller: Kconfig LE Ping feature
Add Kconfig configuration to conditionally enable LE Ping
feature in the Controller.
This will save CPU time, flash and RAM, if this feature is
not desired.

Change-id: I5fbbdbe8f45ac01c9b0d7b11e002a0d1db4d272e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 7fc2a8a4e2 Bluetooth: SDP: Implement ServiceSearchAttribute request PDU
Initial implementation one of basic UUID resolving request PDU based on
Service Search Attribute PDU specification [Core 4.2 Vol 3 Part B 4.7.1]
The request applies approach to query using single only UUID pattern
and getting all attributes for given UUID. The initial PDU transaction
is requested on PSM SDP L2CAP channel connected state.

> ACL Data RX: Handle 77 flags 0x02 dlen 18
      L2CAP: Configure Response (0x05) ident 12 len 10
        Source CID: 64
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 64
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
< ACL Data TX: Handle 77 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Request (0x06) tid 3 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
> ACL Data RX: Handle 77 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Response (0x07) tid 3 len 59
        Attribute bytes: 48
        Continuation state: 8
        8d 55 59 58 30 00 00 00                          .UYX0...

Jira: ZEP-1112

Change-Id: I0ed1d989a5abe030f1c70d4d1f104d488eafb2b3
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Louis Caron 9055f57850 Bluetooth: fix write cmd handling
The data pointer and length was not updated before invoking the
write_rsp function therefore providing pointer to the handle.

Change-Id: I5c27ab7a793979dffb8f1f2c68def027c45f2376
Signed-off-by: Louis Caron <louis.caron@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg fce1938a24 Bluetooth: Fix another incorrect memcpy call
This should also have been net_buf_add_mem(). Otherwise the buffer
gets corrupted.

Change-Id: I4687584777f446d398182c3e8c2cde5946987da4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 1921b53484 Bluetooth: Controller: refactor ISR to reduce critical path code
Move code that can be executed after radio tx/rx packet ptr
has been assigned in the radio h/w.

Change-id: I9c5a34ee6bb74c1265d7871bcdf93894e3e7b190
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada a591205045 Bluetooth: Controller: Kconfig radio ISR profiling
Add Kconfig configuration and conditional compilation of
radio ISR profiling.

Change-id: Ia80d6bc54810156be99b2e6a25327c30d0714697
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 73236dbaa5 Bluetooth: Controller: BT_INFO the ISR profiling event
Change-id: Ic2e01f698c13d76fc462349fe67f1694639888cb
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada ecb649c2a1 Bluetooth: Controller: add radio ISR profiling event
Added code to profile radio ISR execution time and generate
an event, which can be used to populate a vendor HCI event.

This event and associated code is disabled, subsequent
patch will add kconfig to enable it.

Change-id: Ic3fa3e0f4e36829a22a25ffee039949eaae561a7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 6996619399 Bluetooth: Controller: use BT_WARN to display unknown rsp
Use BT_WARN instead of BT_ASSERT to display unknown rsp in
HCI layer.

Change-id: I63c792468d9c4768f69df73395ee026a03521704
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada ced33653fa Bluetooth: Controller: internally handle unknown rsp for LE Ping
Peer controllers not supporting LE Ping feature will
respond with unknown response PDU, handle it internally in
the controller rather than exposing it to HCI layer.

Discovered that controller was passing the unknown rsp PDU
to HCI layer when LE Ping was send to Nexus 5.

Unknown response for slave feature request was forwarded to
HCI layer, during that implementation unknown rsp for LE
ping too was getting forwarded to HCI layer.

Change-id: I4396c482e5546d78239cf41d88728de996e48d7d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery 41984c7577 Bluetooth: RFCOMM: Handle non supported message types
If peer sends any non supported message then it has to be
responded with NSC (Non Supported Command) response.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: Unknown CMD (0x33)
           Length: 8
        01 22 34 55 67 88 9a bb 70

< ACL Data TX: Handle 256 flags 0x00 dlen 11
      Channel: 64 len 7 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 3
         FCS: 0xaa
         MCC Message type: Non Supported Command RSP (0x04)
           Length: 1
           cr 1, mcc_cmd_type 33

Change-Id: I7be3b64a9cf437276c10868d52e0b9c555018df0
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery fb07eb9022 Bluetooth: RFCOMM: Respond to Test command
Test command is to test the connection between two stations.
The pattern recieved should be sent back in the response.

> ACL Data RX: Handle 256 flags 0x02 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x70
         MCC Message type: Test Command CMD (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

< ACL Data TX: Handle 256 flags 0x00 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0xaa
         MCC Message type: Test Command RSP (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

Change-Id: I16beb4cf857cc8bbc049514dbf840d84e13c8fb5
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 14472d757d Bluetooth: Fix incorrect call to memcpy()
This call was supposed to be net_buf_add_mem().

Change-Id: I5e4a718474905c433533fd1c1d7e8e0b7ff35739
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 63f71adc5f Bluetooth: Take advantage of new net_buf_add_mem() API
This helps simplify code that was previously combining net_buf_add()
with memcpy().

Change-Id: If44cf9cd651aba5e544e36567869f147468663eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 4de2bad817 Bluetooth: SDP: Check SDP error when receiving PDU response
Stops handle data if server responds with SDP Error PDU

Jira: ZEP-1112

Change-Id: Iaddb740f71fa86384753ab32956fc69b89faeea0
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa d460181eb0 Bluetooth: SDP: Start receiving response data on SDP PSM
Adds handler responsible for receiving SDP data on SDP client request.
For now simple validation are done on SDP response header data.

Jira: ZEP-1112

Change-Id: Ic6009030db34e26dfdbd57fa1b0a22f6e27b6a11
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Szymon Janc fa8a27fc03 Bluetooth: L2CAP: Fix possible endless loop
cid is uint16_t and L2CAP_BR_CID_DYN_END is 0xffff so doing
"cid < L2CAP_BR_CID_DYN_END" comparisong is always true resulting
in for loop not being terminated as expected. Check against cid
overflow instead. Code comment is also added for clarity.

Change-Id: I15d6d838ed8b731824e602d089d765614c96c6c1
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa fe7d3392cd Bluetooth: SDP: Check params validness
Validates user driven bt_sdp_discover_params data.

Jira: ZEP-1112

Change-Id: I7d560f80df80708906d91e541385ddf804bfdeb6
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa b04f3a2b17 Bluetooth: SDP: Reset context on disconnection
Resets SDP client session data on related L2CAP transport channel
disconnection state. Leave the channel itself reset to L2CAP layer.

Jira: ZEP-1112

Change-Id: I4d8a8f10908f5e599ba6506470b98508869cb21b
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa 6d89dd897e Bluetooth: SDP: Queue user UUID to be resolved
Makes possible to append user UUID to context to be able later iterate
it on subsequent resolving process.

Jira: ZEP-1112

Change-Id: I193ff1cee199045c9686dc4ca200adf19db377e4
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa 4aca00220b Bluetooth: SDP: Refactor bt_sdp_discover API
Renames and refactors helper get_client_session to sdp_client_get_session
to follow existing naming convention and adds second helper creating
new SDP client session. Then simplifies using them the API implementation.

Jira: ZEP-1112

Change-Id: I6b919f521e6665a7117fa06208b3fa2ae5f77fda
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery c7346c4c93 Bluetooth: RFCOMM: Respond to RPN command
Peer sends Remote Port Negotiation command to set port
communication settings. Currently we accept all the settings
sent by remote.

If there is only one value byte in the request then current
port settings has to be returned for which we returns the
default settings defined in ETSI.

Note that RPN may be sent even before a dlc is opened.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: Remote Port Negotiation Command CMD (0x24)
           Length: 8
           dlci 10
           br 3 db 2 sb 0 p 0 pt 0 xi 0 xo 0
           rtri 0 rtro 0 rtci 0 rtco 0 xon 17 xoff 19
           pm 0x3f7f

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0xaa
         MCC Message type: Remote Port Negotiation Command RSP (0x24)
           Length: 8
           dlci 10
           br 3 db 2 sb 0 p 0 pt 0 xi 0 xo 0
           rtri 0 rtro 0 rtci 0 rtco 0 xon 17 xoff 19
           pm 0x3f7f

Change-Id: I73b7d8577e7e2bc3e436f4db86a91e12db440f1f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery 61f34fd966 Bluetooth: RFCOMM: Pass session instead of dlc in make_uih_msg()
rfcomm_make_uih_msg() only needs session to get the role while creating
msg. This is mainly done since some commands like Test and RPN may come
even before dlc is created.

Change-Id: Ifd5a2ceaf17c20db3f00604cd2b4f1759155123e
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Szymon Janc ba2adb70b2 Bluetooth: L2CAP: Fix use of uninitializer pointer
l2cap_br_conn_req_reply expects valid bt_l2cap_chan pointer but this
is achieved only on accept() callback. Use l2cap_br_send_conn_rsp
instead for rejecting cases where no channel was accepted. This also
makes success path being 'primary' function path ie erros all always
handled inside if() statements.

Jira: ZEP-1405

Change-Id: I890b4fcf029afce65eba4f2ebae0b1094feb007f
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2016-12-24 08:42:15 +02:00
Johan Hedberg f3c632bf44 Bluetooth: Add timeout to event & ACL buffer allocation functions
Not all users are in an ISR context where we can't block, so give the
callers the freedom to choose if they want to block or not.

Jira: ZEP-1481

Change-Id: I19bd7e2df94c4eeb60886a17a78f872bd7bea887
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa 3cbce90936 Bluetooth: SDP: Attempt reuse existing SDP client session
Adds validation check when 'sdp discovery' API is to be called
by client, to reuse existing connection if valid or initiate new one
if posssible to set SDP L2CAP link to remote.

Change-Id: I47ce33cb5e95cf2616f9b23712641b912ce40f37
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish 71fdc901e3 Bluetooth: AVDTP: Add AVDTP_Timer & Handler
Added AVDTP_TIMER = 6secs for tracking sent
Singalling Request.
Timeout handler function added.

Change-Id: I76ddcdcfba2b5e9317f66f9815e0d9d3f4cc87e7
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish 129a844d63 Bluetooth: AVDTP: Add AVDTP Pending Request
Added a Pending Request structure, this will keep
a track of the last sent AVDTP Singnalling Message.
This will be used to verify the response from the remote device
Memory will be allocated by the application.

Change-Id: Ic31df154b52ce9013e5039ab195a9651d1811a7a
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa f2c44466a4 Bluetooth: SDP: Add connected and disconnected handlers
Adds for now stubs of handlers responsible for taking a connected and
disconnected state of SDP L2CAP channel.

Change-Id: I21b76b755168fb63f6cade5f6b0c0bab93d0a01f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa b71e34da81 Bluetooth: SDP: Initial implementation of bt_sdp_discover API
Adds basic functionality to be able to trigger establishing outgoing
L2CAP channel to remote using as PSM SDP channel. The number of such
outgoing connections is limited by configured pool of connections.

Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>

Change-Id: Ie5428e5b1b5f5c57f473ee0adfd4621cd9fe6e3e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Sathish Narasimman 9abbc61e4a Bluetooth: AT: Command parsing for range of values
This patch contains API's which is used to parse range of values
eg. (0,3). This patch also parses the string, reads, process and
move the buffer accordingly.

Change-Id: I8dba5b7d630f65b87967c101557c5c7ffd297dd1
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-12-24 08:42:15 +02:00
Szymon Janc bddf039736 Bluetooth: Make BR/EDR discovery be limited only by time
If more inquiry results were received during discovery than fits in
storage results with lowest RSSI will be skipped. This is to improve
API usefulness in busy environments where results with low RSSI (likely
more far away than high RSSI) could consume provided result space,

Change-Id: I1e9ca901b693f608d58575916809e8bd8bfe710f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-24 08:42:15 +02:00
Sathish Narasimman 77446839ad Bluetooth: AT: Improve API() to work with buffer increment
at_get_number which converts the string into number now operates on
at_client to get the string buffer. This patch also improves API()
skip_whitespace to be operated on at_client. Also the the API's
get_cmd_value, get_response_string are updated to work with buf
increment.

Also in this patch the return type of the function str_has_prefix
is changed from 'int' to 'bool'.

Change-Id: Ia626e0d13212b84413cce0444349975f4abe1cf6
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-12-24 08:42:15 +02:00
Carles Cufi 167eac7df3 Bluetooth: controller: Move call to k_sem_give() out of the ISR
The execution time of k_sem_give() increased slightly recently, and
since it was being called from the radio ISR this had an impact in the
deadlines not being met.
This change moves the actual call to k_sem_give() to a lower-priority
job and thus out of the ISR to avoid its execution time affecting the
ISR's timing.

Change-id: I76c82df895c6daaffef52786b0c900ee15acb0aa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery 0b1e6fb231 Bluetooth: RFCOMM: Respond to RLS command
If remote sends RLS command then it should be responded with the
value received.

> ACL Data RX: Handle 256 flags 0x02 dlen 12
      Channel: 64 len 8 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 4
         FCS: 0x70
         MCC Message type: Remote Line Status CMD (0x14)
           Length: 2
           dlci 10 error: 5

< ACL Data TX: Handle 256 flags 0x00 dlen 12
      Channel: 64 len 8 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 4
         FCS: 0xaa
         MCC Message type: Remote Line Status RSP (0x14)
           Length: 2
           dlci 10 error: 5

Change-Id: Ib70e02aede2088bca748d1eb68bee9b1bc47a65d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery e03f2e249e Bluetooth: RFCOMM: Remove unneeded NULL checks
rfcomm_make_uih_msg() does not return NULL anymore.

Change-Id: I8f49b85df8924af1e0d382e699e655a1ffe70662
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Johan Hedberg 2b410afac1 Bluetooth: Fix priority event buffer availability when ECC is used
The ECC emulation synthesizes its own HCI events so we may need up to
two available priority buffers at any point in time.

Change-Id: I88b37c7e9e9f64483d80cde9243470a7f0477321
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish a535880505 Bluetooth: AVDTP: Fix Coding style
Fix modifies the comment section.

Change-Id: Ie105a12f613a1c179aa01eb39298df2ee51c2da3
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Carles Cufi fc479e03e0 Bluetooth: controller: Use SERIES config instead of NRF52
In preparation for the new Nordic MDK and nRF52840 IC support we switch
to using the SERIES config instead of the old "NRF52" macro that will be
deprecated in the new MDK.

JIRA: ZEP-1418

Change-Id: I563f025c9db9b7497116c5af23814d95c720f836
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-20 09:14:47 -06:00
Johan Hedberg 1c9da665c3 Bluetooth: Remove unnecessary runtime kernel object initialization
There are static initializer macros available for most kernel objects
which we should use whenever possible.

Change-Id: I496f4d05d26801eddd21fae53bdd4fcdc3246fe3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Szymon Janc 83874836ac Bluetooth: SMP: Add support for CT2 auth bit
This allows to use H7 function for key derivation if both sides declare
support for it.

< ACL Data TX: Handle 77 flags 0x00 dlen 11
      SMP: Pairing Request (0x01) len 6
        IO capability: NoInputNoOutput (0x03)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: Bonding, No MITM, SC, No Keypresses,
                                    CT2 (0x29)
        Max encryption key size: 16
        Initiator key distribution: EncKey IdKey Sign LinkKey (0x0f)
        Responder key distribution: EncKey IdKey Sign LinkKey (0x0f)
> ACL Data RX: Handle 77 flags 0x02 dlen 11
      SMP: Pairing Response (0x02) len 6
        IO capability: NoInputNoOutput (0x03)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: Bonding, No MITM, SC, No Keypresses,
                                    CT2 (0x29)
        Max encryption key size: 16
        Initiator key distribution: IdKey Sign LinkKey (0x0e)
        Responder key distribution: IdKey Sign LinkKey (0x0e)

Jira: ZEP-1431

Change-Id: I74ecfdd38a69bada0927907a0ef9ed6d59212e47
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Szymon Janc a2d8cee2cf Bluetooth: SMP: Add H7 crypto implementation and unit tests
This adds H7 function implementation and test based on sample data
from Core Specification 5.0 Vol 3. Part H. Appendix D.8.

Jira: ZEP-1431

Change-Id: I49d44ee7a352d1092f6379829d747c7e0ec5e83c
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Vinayak Chettimada f0bd2805bc Bluetooth: Controller: tune the xtal and hard realtime radio start offsets
Reduce the time limit for active clock startup and increase
the CPU usage time limit before hard real-time radio
transmit/receive.

Due to isr_wrapper overhead in ARM architectures, more time
was used before hard real-time radio transmission or
reception which was detected by controller implementation
and the controller aborted the radio transactions.

This commit permits more CPU utilization by the controller
before hard real-time radio transactions start.

Change-Id: Id976add80c70cabc753c43dfac6f6603588458d9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-12-16 10:27:48 +02:00
Vinayak Chettimada 6de7a808af Bluetooth: Controller: ctrl pdu processing based on available CPU time
On CPUs like nRF51 which run at 16MHz, certain BLE control
procedure PDU processing take more CPU time than permitted
inside tIFS (150us). Current implementation of Data Length
Update procedure does not span over multiple connection
interval (unlike Encryption Setup, which is another control
procedure processing that would consume more CPU time)
hence taking more CPU time inside tIFS on nRF51.

During the radio ISR, the active clock and packet timer are
active and it is used to profile the CPU time taken which
is used to decide on whether there is sufficient time in
the current radio event to process the control packet.

This commit also fixes a potential bug that would cause
disconnection due to MIC failure on encrypted connections
that performed Data Length Update. Controller used to NACK
the request/response PDU if it was not in a state to resize
the receive buffers but did not reset the CCM counter. This
is now fixed by the change done to NACK control PDU based
on available CPU time in radio ISR.

Change-id: Id58322ad76a0dbc284738cdd9a7c0437c9e8c423
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery c776791ed0 Bluetooth: RFCOMM: Rename tmp with next
"next" is more relevant since its used to save next pointer

Change-Id: Ic0a8d543944681ba4291c5aa06125f565ab6115c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery 3ec7df34c1 Bluetooth: RFCOMM: Handle DM from peer
Outgoing connection request would be rejected by peer because
of various reasons like server channel not registered etc.
This handles that by destroying the dlc and informing the same
to user.

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: DLC Parameter Negotiation CMD (0x20)
           Length: 8
           dlci 4 frame_type 0 credit_flow 15 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 5

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect Mode (DM) (0x0f)
         Address: 0x13 cr 1 dlci 0x04
         Control: 0x1f poll/final 1
         Length: 0
         FCS: 0xbc

Change-Id: I98288db045001bb73ecfd54e7677d88b2bda9c13
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery a95de4360c Bluetooth: RFCOMM: Disconnect session after last dlc disconnection
As per the spec the station which disconnects last dlc should initiate
session disconnection and then l2cap disconnection.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0xfd

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0xb6

Change-Id: I2d1d7d284995529d5d1522e0ca6082097db19bc2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg bc8ec12977 Bluetooth: Remove unnecessary NULL check
Change-Id: I6ec661cdd64c3c22d85f84c6246e4dcd5db71815
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg 758e220cdc Bluetooth: Remove inline declaration from bt_le_conn_params_valid
The function is not particularly small, and is used from several
places, so remove the inline declaration. This also prepares the way
for the possibility of having an application callback for letting the
application choose whether it's fine with the proposed parameters, and
thereby influence the response we send to the remote device.

Change-Id: I5848b179318b6fb6ee37fcbd479a919204f559f1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Szymon Janc 8d759fcec4 Bluetooth: SMP: Fix key_id length in smp_h6_test
key_id is 4 bytes value.

Change-Id: I2550f3c2b5ab328562fa4375d215b04d2fc76e6f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Arun Jagadish 7f6a059a36 Bluetooth: AVDTP: Add AV-Stream data structure
AV-Stream Data structure added to AVDTP structure.

Change-Id: Icb6ae80e84b49e8a800c99e7f004b43a0fa6c043
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg 6ca9390e4d Bluetooth: Kconfig: Fix logging dependency on printk
Now that all logging methods use printk as a backend the respective
Kconfig options should declare the right dependencies.

Change-Id: I65c759db0ec7ba6333b76d8d20aea0e374fd4947
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg d659bb020e net: buf: Remove redundant user_data_size from buffers
Since the user data size is now stored in the pool there's very little
value in storing it as well per-buffer.

Change-Id: I17a99123b232423c52a2179b4eccd813728d51b1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:17 +02:00
Johan Hedberg 71c7c01819 net: buf: Remove the need for net_buf_pool_init()
In order to keep the initialization process light-weight, remove
net_buf_pool_init() and instead perform the initialization of the pool
and buffers in a "lazy" manner. This means storing more information
in the pool, and removing any 'const' members from net_buf. Since
there are no more const members in net_buf the buffer array can be
declared with __noinit, which further reduces initialization overhead.

Change-Id: Ia126af101c2727c130651b697dcba99d159a1c76
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:02 +02:00
Johan Hedberg 45bc46d42e net: buf: Introduce net_buf_destroy() wrapper
This is only for use with custom destroy callbacks, so that the
application gets isolated away from the details of how exactly the
buffers are managed. This opens up the possibility of switching away
from k_fifo to potentially better solutions, such as k_lifo.

Change-Id: I0d8322fdec3500d8ae060ae471b9448aeaa4572a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 08:45:05 +02:00
Johan Hedberg c3e08c8fea net: buf: Redesigned pool & buffer allocation API
Until now it has been necessary to separately define a k_fifo and
an array of buffers when creating net_buf pools. This has been a bit
of an inconvenience as well as blurred the line of what exactly
constitutes the "pool".

This patch removes the NET_BUF_POOL() macro and replaces it with a
NET_BUF_POOL_DEFINE() macro that internally expands into the buffer
array and new net_buf_pool struct with a given name:

	NET_BUF_POOL_DEFINE(pool_name, ...);

Having a dedicated context struct for the pool has the added benefit
that we can start moving there net_buf members that have the same
value for all buffers from the same pool. The first such member that
gets moved is the destroy callback, thus shrinking net_buf by four
bytes. Another potential candidate is the user_data_size, however
right not that's left out since it would just leave 2 bytes of padding
in net_buf (i.e. not influence its size). Another common value is
buf->size, however that one is also used by net_buf_simple and can
therefore not be moved.

This patch also splits getting buffers from a FIFO and allocating a
new buffer from a pool into two separate APIs: net_buf_get and
net_buf_alloc, thus simplifying the APIs and their usage. There is no
separate 'reserve_head' parameter anymore when allocating, rather the
user is expected to call net_buf_reserve() afterwards if something
else than 0 headroom is desired.

Change-Id: Id91b1e5c2be2deb1274dde47f5edebfe29af383a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-13 21:41:53 +00:00
Johan Hedberg 3fcb9c4ec2 Bluetooth: Use _vprintk() instead of _prf()
The Bluetooth thread stack sizes are optimized based on the assumption
that printk is used for logging and not printf. Using _prf() (the
printf backend) risks overflowing the stack, so use the recently
exposed _vprintk instead.

Change-Id: Ibcbe0af2994c83114d12aa27a8bc29c77bb8c4c8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-11 04:26:06 +00:00
Arkadiusz Lichwa 24b03e75f3 Bluetooth: Remove not needed header in uuid.c file
Now printk family from <misc/printk.h> already included should handle
BT_DBG() like expansion.

Change-Id: I5e03f786530e4bbbdb94a13a4cd77db580268c11
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 19:34:59 +01:00
Arkadiusz Lichwa c4fa607499 Bluetooth: Fix format specifier in UUID DBG helpers
Replace precision formatter (.) in printk with padding flag like %04x
since for now precision is not handled properly in printk family.

Change-Id: Ib63198e407ef584c5650d6452518b1767047630f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 19:33:56 +01:00
Johan Hedberg 26056c8318 Bluetooth: Fix left-over printf usage
These should have been converted to using printk instead.

Change-Id: I62323704dad4fc51cc14ee4734acb6b325dcda14
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 12:26:02 +00:00
Jaganath Kanakkassery 4349141935 Bluetooth: RFCOMM: Implement Disconnect API
This will be used by the user to disconnect or cancel connect dlc.
This also defines an internal close function which will take
appropriate action based on the dlc state.

In case of user initiated disconnection if some pending packets are
there in queue then it has to be sent before sending DISC packet.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x2b cr 1 dlci 0x0a
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0x6d

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x29 cr 0 dlci 0x0a
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x26

Change-Id: Ie4fa3bd8f6b279fee6fb56ddce198d82c5047849
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-09 06:52:56 +00:00
Arkadiusz Lichwa 5c0a502e9f Bluetooth: L2CAP: Fix uninitialized pointer
When PSM server doesn't have BR/EDR L2CAP resources to assign and handle
incoming request properly, local channel pointer may stay uninitialized.
This fixes such scenario. The fix refactors main connection request
reply handler to additional helper which can be used to send response
unconditionally for situation when local channel is not allocated
to setup L2CAP link between.

Jira: ZEP-1405

Change-Id: I5caedd63a59ad0d1704ac87fa51616a0770320bf
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg f53388dbb9 Bluetooth: L2CAP: Fix format specifier for hex uint16_t
Instead of %4.4x we need to use %04x which printk supports.

Change-Id: I0564be5531bb266b328f77231f5d00f43eabe1ed
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz 4a0c9e86f6 Bluetooth: GATT: Update CCC addresses
If connection destination address has been changed update the addresses
stored by the time it disconnects since in case of RPA it is no longer
mapping to the same device after it has been disconnected.

Change-Id: I0ce966928f605a885125179eaa7b9093989825ab
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz 624a170e8d Bluetooth: GATT: Fix using bt_addr_le_cmp with destination address
The connection destination address may change if the identity address
is resolved.

Change-Id: Id6f7b6494c24ff118043ba5f4ff54e254376eddf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz ae213a2ea8 Bluetooth: Fix bt_conn_lookup*
bt_conn_lookup shall work both with identity address or initial
destination address as bt_conn may change the destination address with
the identity address.

Change-Id: Ibdd19ec453c3307eb6db188196b7e57a2260b526
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg a4b6b2417d Bluetooth: Switch from printf to printk functions
There's now snprintk available that's more light-weight on the stack
than snprintf.

Change-Id: I6b3e4409703ca92fe6b8f4146ff47c490ab826cb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg 5ac059b6b9 Bluetooth: Extend advertising parameters with optional own address
Applications may want finer control of the NRPA used for
non-connectable beacons, and provide it up-front rather than letting
the stack generate one.

Change-Id: I84d459372cc85ed09a8f9cde16dbb9b98dec2a43
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg d883fcf814 Bluetooth: Make LE random address helpers public
Expose helpers in hci.h for setting and getting the LE random address
type.

Change-Id: I7c6437051f0b2d1f5f79e19b2616bb643ae6300b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Arun Jagadish ede69e5d19 Bluetooth: AVDTP: Fix Coding style
Fix modifies the comment section.

Change-Id: Iafd6cfe7a2f85acd867d096515e1b803882875c2
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg 9aafa973df Bluetooth: Fix incorrect logging format specifiers
Fix compilation issues that show up if SYS_LOG is mapped to printk
instead of printf. Unlike printf, printk is annotated so that the
compiler catches incorrect format specifiers passed to it.

Change-Id: I4d6f635a0ed61de698727028ea8767dc0ef28bb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:59 +00:00
Johan Hedberg 299216b2f0 Bluetooth: Controller: Make use of min() convenience macro
Instead of having custom logic for determining the minimum of two
values, use the existing min() helper from misc/util.h.

Change-Id: I9809883d4a31126329373f293897dd49eb91e9ad
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery e36d58e593 Bluetooth: RFCOMM: Remove send DM from drop()
rfcomm_dlc_drop() can be used from many places to unlink dlc
from session and destroy it. So it is better to send DM
explicitly from relevant places.

Change-Id: I9b6a31ce5bb65b90510aa483539d4a201ba12b60
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-03 17:09:38 +00:00
Vinayak Chettimada f0186d716d Bluetooth: Controller: Fix DLE to check supported rx length
When the Controller is configured to support less than 251
as the supported maximum data length, missing check caused
the Controller to incorrectly re-initialize its rx buffers
causing assert during the DLE procedure. This commit fixes
the procedure to correctly use the supported maximum length
if the peer requests a transmit length that exceeds the
supported receive length.

Change-id: I6ad7196e3db44b303ddf2ec06e0ae579bf2eb774
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Szymon Janc d1187302e0 Bluetooth: Make bt_send stack requirements a Kconfig option
This allows to fine tune TX stacks size depending on selected HCI
driver. If needed it can be used to tune for monitor too or other
logging mechanism used.

Change-Id: Ib501921da0b786e151083760d85ec58fe3c08b60
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc b00e747ddf Bluetooth: L2CAP: Fix set but not used variables
If debugs are disabled scid and dcid variables were never read.
This also fix mixed values of scid and dcid in le_disconn_req.

Change-Id: I3b435dd0640c5c65ab5fe68e33dd25e3c9e0026e
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc efec1aa79d Bluetooth: Fix missing prototype config
subsys/bluetooth/host/hci_ecc.c: At top level:
subsys/bluetooth/host/hci_ecc.c:277:6: warning: no previous prototype
      for 'bt_hci_ecc_init' [-Wmissing-prototypes]
 void bt_hci_ecc_init(void)
      ^
  CC      subsys/bluetooth/host/conn.o

Change-Id: I920d8b6b66c82be932c579461310505c6d402c08
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Johan Hedberg cb84ad1ad6 Bluetooth: Fix coding style issues in LE address helper functions
Even one-line branches should have {}, and the last two return
statements can be simplified into a single one.

Change-Id: I0f65aeaba867240255eae8e1c461386700444ae6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-03 17:09:38 +00:00
Szymon Janc 70417f1fce Bluetooth: Simplify ncmd handling
With k_sem API it is possible to specify maximum sempahore value
so we no longer need to track semaphore count.

Change-Id: I86744ba63bd3207051ca3466d4f81b816d24f5ad
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc a081e0a57f Bluetooth: GATT: Fix primary service discovery response
Applications expect service end handle as attribute value in userdata
on discovery response callback.

Jira: ZEP-1354

Change-Id: I664da4a7e054a531ad1c2c8cbc74367cb679ff03
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery dd94c3b3eb Bluetooth: RFCOMM: Handle security for outgoing DLCs
Security needs to be elevated based on dlc required sec_level
before creating dlc. If L2CAP connection is not created then
setting dlc required sec_level to chan would do the job.

Change-Id: I21debd3559c9ccfb79011160d676932bc2a54604
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-03 17:09:38 +00:00
Carles Cufi d42987acf4 Bluetooth: Controller: Fix local LE supported features bitmap
Correct the local LE supported features bitmap to actually "or"
together all the bits that correspond to the set of features that
are implemented at this time.

Change-Id: I0c62ec566c775514250fcf062aeef6c9656719e3
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Arun Jagadish 6f3c4bf425 Bluetooth: AVDTP: SEP Definition
Added
SEP structure
SEP Registration function

Change-Id: Ib8c4a1753c85390009c154a50a1a1a2f2794e8a2
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-03 17:09:38 +00:00
Luiz Augusto von Dentz 30838af5e9 Bluetooth: L2CAP: Fix possibly reading past the end of buffer
If the original buffer cannot be reused, either by no having enough
space for user data or if is fragmented, it can in fact be smaller than
both the segment buffer and MPS.

Change-Id: I59a537aff59c5d56b2883e9bd51f3a1a3932d348
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-03 17:09:38 +00:00
Luiz Augusto von Dentz 37b0e0ab2e Bluetooth: L2CAP: Fix segmentation
The segments need to be limited by the minimun of the segment buffer
tailroom and tx MPS not the original buf length.

Change-Id: I580a3bb61aa190ac0cdd3717bc06fd6e6e668304
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-03 17:09:38 +00:00
Carles Cufi 3b1baa88ef Bluetooth: Controller: Implement ECC commands
Implement the 2 HCI commands that provide ECC public key
and shared secret generation:

- LE Read Local P-256 Public Key
- LE Generate DHKey

Jira: ZEP-1246

Change-Id: I79388bfdb9f2e28b9377b4bb6ee2caca25f33f3e
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery 8166de77db Bluetooth: RFCOMM: Initiate DLC
This patch initiate a DLC when user calls connect. It first does
Parameter negotiation and then establish connection to the
dlci derived from channel given by user.

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: DLC Parameter Negotiation CMD (0x20)
           Length: 8
           dlci 3 frame_type 0 credit_flow 15 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 4

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0xaa
         MCC Message type: DLC Parameter Negotiation RSP (0x20)
           Length: 8
           dlci 3 frame_type 0 credit_flow 14 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 7

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Set Async Balance Mode (SABM) (0x2f)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x3f poll/final 1
         Length: 0
         FCS: 0x59

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x92

Change-Id: I62a19f624fc4bb89eb9a109a5352fa763c1241d2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-18 17:27:01 +05:30
Jaganath Kanakkassery d9eb0fb2a0 Bluetooth: RFCOMM: Refactor rfcomm_handle_pn()
Handle the scenarios like ignoring a response in non existing dlc,
correctly handle if received a command with invalid mtu etc.

Change-Id: Ib0bce9134bac3a0dead03798f859af54873a70c1
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-18 17:27:01 +05:30
Luiz Augusto von Dentz 1bbb31e201 Bluetooth: L2CAP: Fix regression with move to k_sem API
k_sem_take return differ from nano_sem_take since it return 0 for
successful case instead of 1.

Change-Id: Ia39cd624d56dbc1c8e7f3558244bebf765da191d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 8217bb1ef6 Bluetooth: Kconfig: Remove deprecated dependency on NANO_TIMEOUT
This is no longer needed after switch to unified kernel.

Change-Id: Ie1f8dadb3f2e43ae6ccfbfaf1f754196f3237471
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 6cda540a4e Bluetooth: Kconfig: Remove deprecated dependency for ECC support
After switch to unified kernel this is no longer needed.

Change-Id: If9877d3fa038dd873011fb780c7e767e150647ae
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Luiz Augusto von Dentz 58a2b3df7c Bluetooth: GATT: Fix using out of scope variable
This fixes defect found by coverity: 152027 Pointer to local outside
scope.

Change-Id: I50f196a04363ffa6e6654b71a9a1d89034580413
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Carles Cufi c969e757bc Bluetooth: Controller: Implement missing DLE commands
Implement the 3 missing HCI commands required to support
Data Length Extensions:

- LE Read Suggested Default Data Length
- LE Write Suggested Default Data Length
- LE Read Maximum Data Length

Note: Only octets are actually used at this time, not time.

Jira: ZEP-1246

Change-Id: Id76d8fedb5ecaf0001c8429cf22f9a3e2c910a44
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada e9b818e763 Bluetooth: Controller: Fix suspicious use of sizeof
Fix Coverity, sizeof not portable, defect; by explicitly
using sizeof(void *).

suspicious_sizeof:
Passing argument mem_head of type void ** and argument 4U
/* sizeof (mem_head) */ to function memcpy is suspicious.
In this case, sizeof (void **) is equal to sizeof
(void *), but this is not a portable assumption.

Change-id: I4b4776466e16020876500feba0141985b8581017
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 26f6b71a8e Bluetooth: Controller: Fix incorrect irq priority check
External interrupts are indexed from value 16, wherein
0 to 15 are ARM cortex M exceptions. Fixed code in
_irq_is_priority_equal to fetch correct external
interrupt line ISR priority.

Change-id: I9cfd411480e78dfc9635e72d14df9d667a9d8400
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 27b1a24993 Bluetooth: Controller: Remove unused util functions
Change-id: I7b691d082d080239c35b63221e3c6c7aa93ed58e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 94a425429c Bluetooth: Controller: Fix incorrect auto variable init
Coverity analysis discovered NULL pointer being
dereferenced when passing a auto variable. The variable is
now correctly assigned with address of a valid default
value variable. As per design, the dereferencing will not
happen as the master role does not use the passed parameter
only slave role uses it to prepare the connection parameter
request PDU.

Change-id: I3f8519b23a83cb8c50c7fba81810eff7737ff74a
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 7b1c042b02 Bluetooth: Controller: Fix observer filter_policy field size
Coverity analysis discovered that observer filter policy
field was 1 bit, whereas valid range for extended scanner
filter policy feature implemented in controller is 0 to 3.
Increase the bit field size from 1 to 2.

Change-Id: Id4b2e354961dfb3b45f72fa4e0ab18de7425bbb5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Szymon Janc a2ee111aa0 Bluetooth: Fix address type use for passive scanning
This fix using incorrect address type for passive scanning with
privacy enabled. Controller was not reporting directed advertising
to RPA address due to public type being used for passive scan.

This was affecting TC_CONN_GCEP_BV_01_C, TC_CONN_ACEP_BV_01_C and
TC_CONN_DCEP_BV_01_C qualification test cases.

Jira: ZEP-1200

Change-Id: Icc316441fcac1a72d75f9ade27a99030efc846b9
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Luiz Augusto von Dentz c0edc551b5 Bluetooth: GATT: Fix using att_ prefix
This might create confusions when debugging as usually the prefix is
associated with the file or layer.

Change-Id: Ibf45578c1f54a4bec896acd6042589c815216e1f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 243668dbc4 Bluetooth: Kconfig: Fix BR/EDR dependencies
BR/EDR code should have minimal impact on LE code so to keep it simple
just require peripheral and central to be enabled when selecting BR/EDR
support.

Fix following Kconfig warning:

warning: (NETWORKING_WITH_BT && BLUETOOTH_BREDR) selects
    BLUETOOTH_L2CAP_DYNAMIC_CHANNEL which has unmet direct dependencies
    (BLUETOOTH && BLUETOOTH_HCI && BLUETOOTH_HCI_HOST && BLUETOOTH_CONN
    && BLUETOOTH_SMP)

Change-Id: I7f7cb8794def0df6daaa4abfe4596df460f1a2b2
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 9dde3e02fd Bluetooth: Fix use of deprecated PRIMARY init level
Fix following warning:

  CC      subsys/bluetooth/host/monitor.o
In file included from zephyr/include/drivers/loapic.h:58:0,
                 from zephyr/include/drivers/ioapic.h:22,
                 from zephyr/include/drivers/sysapic.h:20,
                 from zephyr/include/arch/x86/irq_controller.h:33,
                 from zephyr/include/arch/x86/arch.h:28,
                 from zephyr/include/arch/cpu.h:23,
                 from zephyr/include/kernel.h:2458,
                 from zephyr/include/zephyr.h:20,
                 from zephyr/subsys/bluetooth/host/monitor.c:24:
zephyr/subsys/bluetooth/host/monitor.c: In function
    '_deprecation_check_sys_init_bt_monitor_init0':
zephyr/include/device.h:130:16: warning: '_INIT_LEVEL_PRIMARY' is
    deprecated [-Wdeprecated-declarations]
  static struct device_config _CONCAT(__config_, dev_name) __used \
                ^
zephyr/include/device.h:245:2: note: in expansion of macro
    'DEVICE_AND_API_INIT'
  DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, \
  ^
zephyr/include/init.h:69:2: note: in expansion of macro 'DEVICE_INIT'
  DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio)
  ^
zephyr/subsys/bluetooth/host/monitor.c:193:1: note: in expansion of
    macro 'SYS_INIT'
 SYS_INIT(bt_monitor_init, PRIMARY, MONITOR_INIT_PRIORITY);
 ^
zephyr/include/device.h:48:31: note: declared here
 static __deprecated const int _INIT_LEVEL_PRIMARY = 1;

Change-Id: Ie903e3a075f6614b26018be5769be3651f0963be
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 11770b8bf4 Bluetooth: Controller: Fix HCI Reset Command implementation
Added implementation for HCI Reset Command. Implementation
gracefully disables any running advertiser, observer, and/
or connection roles, and it resets controller context members.
The HCI Reset Command is implemented in such a way that
driver instances shared with other sub-systems and
application is not disturbed and instance/references used
by Bluetooth Controller are gracefully returned back.

Jira: ZEP-1282

Change-id: Ifb9ae6807736b5ec2d9f346cf2a590322056bcee
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Mariusz Skmara 2305196461 Bluetooth: Fix not sending L2CAP Connection Parameters Update Request
This fixes issue that L2CAP Connection Parameters Update Request was
not sent. There was check that used LE features of host controller
to determine if L2CAP procedure or LL shall be used. It was failing
with 4.2 controller. The check shall test if remote supports
LL Connection Parameters Request Procedure. If it's not supported,
then L2CAP Connection Parameters Update Procedure will be used.

Closes ZEP-1220

1/4   L2CAP   TC_LE_CPU_BV_01_C      PASS
2/4   GAP     TC_CONN_CPUP_BV_01_C   PASS
3/4   GAP     TC_CONN_CPUP_BV_02_C   PASS
4/4   GAP     TC_CONN_CPUP_BV_03_C   PASS

Change-Id: I61ad544d9568ca6306a845e05c1a2e28d1693ab4
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-11-18 07:47:50 +02:00
Johan Hedberg 2469bd6f87 Bluetooth: Use convenience macros for timeout durations
Using the K_* macros makes it easier to read what exactly the various
timeouts are.

Change-Id: Ia405d3760b8e600af7e33a7221ef6ec717708973
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-18 07:47:50 +02:00
Johan Hedberg 1e20e8dc04 Bluetooth: Fix left-over usage of TICKS_NONE and TICKS_UNLIMITED
Switch left-over usage of TICKS_NONE and TICKS_UNLIMITED to the new
unified kernel counterparts K_NO_WAIT and K_FOREVER.

Change-Id: I2f2a16360e816f9f8791eb216deb3c70b8cc87df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 19:27:34 +02:00
Vinayak Chettimada 4812b2d40e Bluetooth: Controller: Fix device whitelist feature
During the initial integration of controller to Zephyr OS,
radio hardware access was abstracted out into hal/radio.c
file. Bug introduced in hal/radio.c has been fixed so that
whitelist feature works again.

Change-id: Ie5faf80b1a008ef326613548a5a28a4ba52e7ef7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-11 16:40:59 +00:00
Johan Hedberg c245b96249 Bluetooth: Kconfig: Fix order of default entries
The conditional defaults must come last in order to be properly
processed.

Change-Id: Id7a152ca1a1584935029e212d0dd8f37494d1cf4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 12:09:46 +00:00
Vinayak Chettimada 5629197b17 Bluetooth: Controller: Add HCI_LE_Remove_Device_From_White_List
Add implementation in HCI and Controller to support
HCI_LE_Remove_Device_From_White_List, as it is listed as
mandatory under BT Spec. v4.2, Part E, Section 3.19 LE
Controller Requirements.

Change-id: Icef88dffc85746f3cc7adb7fb692ae5578274ed2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-11 11:56:47 +00:00
Johan Hedberg a14680f7c0 Bluetooth: hci_ecc: Convert to new thread API
Convert from a private task to the thread API, also add stack usage
analysis and tune-down the stack size to avoid wasting memory:

On x86:
ecc stack (real size 1280):	unused 80	usage 1136 / 1216 (93 %)

On arm:
ecc stack (real size 1280):	unused 52	usage 1128 / 1180 (95 %)

Change-Id: Iba84a5a9cb5257c1456663adf4952c5c18650f97
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:52:02 +02:00
Johan Hedberg 81975637dc Bluetooth: Rename left-over mentions of "fiber" to "thread"
Rename left-over mentions in code comments of "fiber" to "thread".

Change-Id: I1af1baf99652434e90eb491c10238b94d26d341d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:06:05 +02:00
Johan Hedberg 916ed6cdd2 Bluetooth: Controller: Stop using deprecated APIs
Switch from fiber_start() to k_thread_spawn() and from NANOKERNEL to
POST_KERNEL init level.

Change-Id: I34fb11cbe20216c8646ebacb07be304a67e3cd0a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:04:02 +02:00
Johan Hedberg 8b92cb2d78 Bluetooth: RFCOMM: Switch to using k_thread_spawn()
Use k_thread_spawn() instead of the deprecated fiber_start() API.

Change-Id: I42e798ef3a4276863659c8d97c85224a652be1fd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:55:27 +02:00
Johan Hedberg 500010d369 Bluetooth: Remove need for fiber offload
The bt_recv() function had protections for being called from a
preemptible task context, however nothing was protecting preemption by
ISR. A fairly simple fix is to protect the couple of critical regions
that can be reached from bt_recv() with the help of irq_lock().

Change-Id: Ifc29fd31205eb5425e1b7c862347d9420688df4e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg 918a8e6bac Bluetooth: Use k_thread_spawn() instead of deprecated nano_fiber_start()
Switch to using the unified kernel k_thread_spawn() API instead of
nano_fiber_start().

Change-Id: I325cf467ae2a52c6aec8fc166397c323929e3013
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg b0f0742b6e Bluetooth: Use k_yield() instead of deprecated fiber_yield()
Use the unified kernel API k_yield() instead of fiber_yield().

Change-Id: I8f52031f52f7ac8783033a51751dc22decdfa59a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg 80e04e4fd1 Bluetooth: Use k_uptime_get() instead of deprecated sys_tick_get_32()
Switch to using k_uptime_get() instead of the deprecated
sys_tick_get_32() API.

Change-Id: I737ef0153eff9d283bae840ff5177f8132396e1b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:38:24 +00:00
Szymon Janc 2b16287286 Bluetooth: Use proper timeout defines for net_buf_get_timeout
Use defines from k_fifo intead of legacy API.

Change-Id: Ib8cf0d88240ef145da550b8cf83d2580e7140521
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 06:00:28 +00:00
Szymon Janc 577fe910ae Bluetooth: Remove not needed nano_work.h includes
Those are lefovers from nano_delayed_work usage.

Change-Id: I3f17c7b89b1fa946495e160732457500e2f74f25
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz 203897d04e Bluetooth: HCI: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in HCI layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: I953a82a6aa613bb1072a8ad4b01e0f94e5cd64bd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz 5aef8dd1ad Bluetooth: conn: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in bt_conn layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: Ia8f34b475051515fd74000cce745ad226aa18aa5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz b96efa9efd Bluetooth: SMP: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in SMP layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: Ida58ff0f609dc2a8fd415692bc2cec91eb56a294
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz ec57d7cdb2 Bluetooth: ATT: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in ATT layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeouts values changes.

Change-Id: I14d8438c1537febcb7768ef2934042ce38682739
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz b3cece0af1 Bluetooth: L2CAP: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in L2CAP layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeouts values changes.

Change-Id: I1e3bd7857248865e34a313dd42862af5f4e3805b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Szymon Janc 47eaaf9f96 Bluetooth: Use unified k_fifo API for FIFOs
Change-Id: I6ddc24575e4bf3c3040945a2bdb62f153b15cdb3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg 3062516a1a Bluetooth: Controller: Improve default RX/TX buffer counts
Currently the ideal buffer counts for a controller-only build are 6 RX
buffers and 7 TX buffers: ATT_MTU of 158 bytes can be sent in one
connection interval of 6 tx/rx -es wherein connection interval is
7.5ms

Change-Id: I64b4620c5e8e7db8d7ed72fa1db82e266e121f27
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Szymon Janc 27cbd586cb Bluetooth: ATT: Fix non-ASCII characters in code comments
Change-Id: Ief28ffbab1f1751344184b35e40f32e1fc1d6ac9
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Jaganath Kanakkassery 00457636f8 Bluetooth: RFCOMM: Initiate session connection
This patch introduces the Connect API which initiates session
connection first. If session is already there with the peer
then it has to reuse it and initiate DLC (which will be done
in the subsequent patch) since there can be only one session
per device.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Set Async Balance Mode (SABM) (0x2f)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x3f poll/final 1
         Length: 0
         FCS: 0x1c

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0xd7

Change-Id: I9828e0f3b3ea43bb17df95f0536e15df86f1b4be
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg e4c5c96a16 Bluetooth: Fine-tune default incoming ACL buffer count
In some SMP + GATT scenarios it's possible we get up to 6 incoming ACL
packets. To handle these efficiently, and more importantly, to not
have to drop data if the controller lacks host flow control (as is the
case currently with Zephyr-based controllers), increase the default
from 5 to 6.

For a controller-build it makes sense to just match up with the
controller-side configured RX buffers.

Change-Id: Id44fa724597b88a51f9085dac009e8d84a439bfc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg b64e0d4c51 Bluetooth: Kconfig: Remove redundant 'default n' declarations
All boolean options default to 'n' without the need to explicitly
state this. It's only the cases where we want 'default y' where we
need to state this.

Change-Id: I47dbda62462ea437a2423b8508ea2cc640a22e41
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg c583a9f43b Bluetooth: Kconfig: Restructure for a more logical hierarchy
Restructure the Bluetooth options more logically.

- Both host and controller are now behind the same high level
  CONFIG_BLUETOOTH.

- Selecting controller support disables other HCI driver selection, so
  the controller isn't in the same list as HCI drivers any more.

- Under the top-level there's a "Custom stack" option, which when
  enabled opens up the option of choosing CONFIG_NBLE.

There are various other cleanups and simplifications in this patch as
well, since splitting these up would have been fairly tricky while
making sure all test cases still build.

Change-Id: I5bb715cb9d20201cb8b72fbd149c8a09a4b2d7d2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg 1c40b964a0 Bluetooth: Dump the content of unhandled events as hex
This should be particularly useful with the recently added controller
assert functionality that causes vendor events with debug information.

Change-Id: Ied0df2ff414e08c11a73cca0afba4dc04b0b8625
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Carles Cufi f7d313b154 Bluetooth: Controller: Add ASSERT info dump on HCI builds
When building Zephyr in the controller-only configuration,
assertions that happen in the Link Layer code are not visible
to the Host which is running on another HCI and connected via
UART or USB to it. This patch allows the Controller code
to output the assertion line number when in such a configuration,
allowing the Host to view the event to help debugging.

The event format used is temporary and will be replaced by a
standardized Vendor Specific specification to come at a later
time.

Change-Id: I013ca6783a3fdedc47b171132919dd4798c66285
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-11 07:59:15 +02:00
Johan Hedberg 50f03a8de5 Bluetooth: Controller: Kconfig: Clean up style issues
The right convention for help text is tab + 2 spaces.

Change-Id: I2722a8b33f5f74be110dc43fbcecc12841f0db84
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz 629ab2da6b Bluetooth: ATT: Fix not forwarding error properly
When retrying the request due to a security error that can fail but since
the original buffer was freed in the process the code can no longer verify
if the opcode matches thus it always fails BT_ATT_ERR_UNLIKELY instead of
using the response error, so this not longer cares about the opcode and
just use the response error always.

JIRA: ZEP-1195

Change-Id: I1149b993b97733ab5bb00f347e4f973647e0fdd4
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz bc3af66a01 Bluetooth: L2CAP: Add helper function to create LE signalling PDUs
This consolidate code around LE signalling header handling which has been
duplicated in many places.

Change-Id: I0c2cd48c155b751e1bbbd26070965d075cdc2cc5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:43:43 +00:00
Carles Cufi 6ccfa64b5c Bluetooth: Controller: Handle LL_UNKNOWN_RSP PDU for remote features
When a peer controller does not recognize one of the LL control
PDUs received, it will issue an LL_UNKNOWN_RSP PDU to let the
peer know that it does not recognize the request.
The controller now handles this incoming PDU and completes the
procedure by issuing the appropriate HCI event in the case of
an LL_FEATURE_REQ and _RSP pair.

Jira: ZEP-1220

Change-Id: I7c04a346441f04deee41198daa6309c11ae1b571
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-09 08:57:52 +02:00
Johan Hedberg 195e1b89b1 Bluetooth: Fix usage of C++ reserved word
'private' is a C++ reserved word and will lead to compilation errors:

  C++     ble.o
In file included from ble.cpp:7:0:
 include/bluetooth/bluetooth.h:284:10: error: expected unqualified-id before 'private'
  uint8_t private[4];

Change-Id: I36aef5a84af4fc66e1c810bd0c56e5ab5f803294
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Sathish Narasimman c719bfb689 Bluetooth: HFP HF: SLC connection-Send/Parse BRSF
Service Level Connection(SLC) Initialization part. Sending AT+BRSF
and parsing its response.

< ACL Data TX: Handle 256 flags 0x00 dlen 20
      Channel: 75 len 16 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 12
         FCS: 0x40
        41 54 2b 42 52 53 46 3d 31 34 38 0d 40           AT+BRSF=20.

.
> ACL Data RX: Handle 256 flags 0x02 dlen 23
      Channel: 64 len 19 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 14
         FCS: 0x86
         Credits: 4
        0d 0a 2b 42 52 53 46 3a 20 38 37 31 0d 0a 86     ..+BRSF: 871.
> ACL Data RX: Handle 256 flags 0x02 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I51581928d479ea4229b32a07cbea86c1f6fe09c8
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-09 08:57:52 +02:00
Sathish Narasimman b0d34d83c5 Bluetooth: AT handling error condition
In function at_get_number check for the value if gets computed.
If not return error. Also change the end state handling.

Change-Id: I193b04fa2880dfb44e7727b30b67c1ec2e051cc7
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-09 08:57:52 +02:00
Johan Hedberg 8ed846285e Bluetooth: Implement bt_storage_clear()
Add an implementation for the bt_storage_clear() API.

Jira: ZEP-181

Change-Id: Iae01c571c161317ea0cc44513d108301c7b5a069
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Johan Hedberg 77a8516dd2 Bluetooth: storage: Add basic support for internal storage
Add basic implementation of an internal storage handler that uses the
local file system. The root directory for all Bluetooth related data
is /bt. Each remote device has its own subdirectory and each key its
own file. This helps keep the implementation very simple, but does
come with the meta-data overhead for each file.

As an example, the value of a key 0x0001 for a device with a static
random address cc:11:22:33:44:55 would be stored in the following
file: /bt/cc11223344551/0001. Local values such as the identity
address are stored directly under /bt with a file name that matches
the key the same way as remote-device files.

For full functionality the implementation requires a file system that
can support file/directory names of up to 13 characters in length. If
the file system supports less than that (as is the case with FAT12)
then only local values can be stored (in /bt/abcd). Local values
include the identity address as well as the local IRK.

Jira: ZEP-181

Change-Id: I7dc696af6353a154cb00dcd01a5f4ac3d7127e6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc e18e3ed60a Bluetooth: Controller: Use unified k_sem API for semaphore
Change-Id: I02b4e5f4d0a2995cfae1b9a2edcbdf01d6ec631a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8f800a8bfe Bluetooth: Use unified k_sem API for semaphores
Change-Id: I0099c837cc8ad67b8f927b2debd771acfe626eea
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8944c25c90 Bluetooth: Controller: Include zephyr.h instead of nanokernel.h
zephyr.h includes required kernel header depending on selected
configuration.

Change-Id: Ib72c4038637c303ee32e433706355299ae1b9a13
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz 3808ad0a96 Bluetooth: L2CAP: Limit segments to TX MPS
le_data buffers are no longer limited to the minimun of 23 bytes, instead
it uses CONFIG_BLUETOOTH_L2CAP_IN_MTU which means it can be bigger than
the MPS thus causing invalid data to be sent:

> ACL Data RX: Handle 64 flags 0x02 dlen 18
      LE L2CAP: LE Connection Request (0x14) ident 1 len 10
        PSM: 128 (0x0080)
        Source CID: 64
        MTU: 672
        MPS: 23
        Credits: 65535
< ACL Data TX: Handle 64 flags 0x00 dlen 18
      LE L2CAP: LE Connection Response (0x15) ident 1 len 10
        Destination CID: 64
        MTU: 230
        MPS: 65
        Credits: 4
        Result: Connection successful (0x0000)
< ACL Data TX: Handle 64 flags 0x00 dlen 27
< ACL Data TX: Handle 64 flags 0x01 dlen 2
      Channel: 64 len 25 [PSM 128 mode 0] {chan 0}
        3c 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff  <...............
        ff ff ff ff ff ff ff ff ff

JIRA: ZEP-1219

Change-Id: Id67f1faac8766c66aa24c7421d44112434666a10
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 3317227437 Bluetooth: Remove workaround for Mynewt firmware bug
This is not needed for Zephyr controller build and should already
be fixed in Mynewt.

Change-Id: I39e81dc3e9b5fd5a3f5f823465527248625caf26
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Arun Jagadish 227b1d4643 Bluetooth: AVDTP: Set Profile Security Level to Medium
Setting AVDTP Profile Security to Medium

Change-Id: I93aa367ac5bfe4e8bfe08f25d0e7e9d65b891350
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz 4f39b4ceb1 Bluetooth: L2CAP: Fix regression causing credits not to be restored
Patch 8c118f8673 causes the wrong semaphore
to checked so receiving credits are never restored which caused the
channel to get stuck after all the credits are consumed.

JIRA: ZEP-1199

Change-Id: I9cd5474b3bcaafcb19d15613939ce30d07befe0a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Vinayak Chettimada fb032efa90 Bluetooth: Controller: Use configured clock source
Remove hardcoded use of crystal as 32KHz clock source and
20 ppm accuracy; and use the values from config for sleep
clock source and sleep clock accuracy value in Bluetooth
Controller.

Change-id: I1c0d53ecf8ad158153d5186a6680b5eb03d1641b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-07 12:04:03 +00:00
Benjamin Walsh 8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

Moving the system workqueue to its own code module allows removing the
NANO_WORKQUEUE and SYSTEM_WORKQUEUE kconfig options, and compiling the
common workqueue code and system workqueue all the time. They are only
linked in the final image if a reference to them exist, same as the
other kernel modules.

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00:00
Johan Hedberg f26007d212 Bluetooth: Print full controller info upon init
Provide more detailed information about the controller address and
version upon init when debug is enabled.

Change-Id: I5fe9c7c91f95928cb3cc64b801137bb1466e4115
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:06:31 +02:00
Vinayak Chettimada d62426030c Bluetooth: Controller: Fix re-encryption procedure
During implementation of alternate encryption procedure
usable in nRF51, commited in
c41d3edda8, re-encryption
procedure was broken. This commit fixes the issue, and
now re-encryption should work on both nRF51 and nRF52.

Change-id: Ia41200f42b1d46e1f3f35ff44b582d4ffcc5f4fa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-04 22:06:31 +02:00
Mariusz Skamra 748c00b31e Bluetooth: GATT: Pass data buffer as NULL if length is 0
So that application could check data pointer to see if any
data have been received and if read operation is complete.

Change-Id: I36c3ff81baefbc535374d937e5297938445eafa6
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 1b7c219f8a Bluetooth: L2CAP: Make use of bt_l2cap_chan_set_state on BR/EDR
This makes use of the same code used by LE to print the state transitions.

Change-Id: I90a04f3c3f426fde1e0987acb572f7371c483c1c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 5fecf98c8e Bluetooth: L2CAP: Log state transitions
This adds a common function to log state transitions including the caller
function and line in case something goes wrong:

[bt] [DBG] bt_l2cap_chan_disconnect: (0x0011b14c) chan 0x001199c0 scid 0x0040 dcid 0x0040
[bt] [DBG] bt_l2cap_chan_set_state_debug: (0x0011b14c) chan 0x001199c0 psm 0x0080 connect -> disconnect
[bt] [WRN] bt_l2cap_chan_set_state_debug: bt_l2cap_chan_disconnect()1562: invalid transition

Change-Id: I246a9004a04d93a38b8c7f7633705f6c191698b2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 349230321f Bluetooth: L2CAP: Fix not updating CoC channel state
Channel state shall be updated properly otherwise it may cause unexpected
errors.

Change-Id: Ifd54d6bd3c5b44a40c315fd8a2946b30168aa65f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery 88038d1782 Bluetooth: RFCOMM: Define macro for PF bit
This defines and clarifies PF bit macro for both UIH and
non UIH packets.

Change-Id: Ide7736c0fc8607708824766adbfccf1bd7bc48e9
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery 70f1df22a4 Bluetooth: RFCOMM: Set sec_level to LOW during L2CAP register
Security will be elevated based on the DLC required level
during connection.

Change-Id: I0b63885582f34a5689f7bc8081c1f9f011b2325f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Sathish Narasimman 56392e5c2e Bluetooth: Fix initialization of variable
Initialize the variable to zero before computing.

Change-Id: Iccdf77a085667728dbb68779f001c8d940a7a89d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 807bd5fec8 Bluetooth: L2CAP: Handle LE connection response security errors
If there are security errors bump the security of the connection and
retry:

7C:7A:91:18:82:5F (public)> l2cap-connect 0x0080
[bt] [DBG] bt_l2cap_chan_connect: (0x0011ae8c) conn 0x0011b940 chan 0x00119700 psm 0x0080
[bt] [DBG] l2cap_chan_tx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] l2cap_chan_rx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] bt_l2cap_chan_add: (0x0011ae8c) conn 0x0011b940 chan 0x00119700
L2CAP connection pending
7C:7A:91:18:82:5F (public)> [bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 2 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0000 mtu 0 mps 0 credits 0 result 0x0005
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 7
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 7
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 65
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 65
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
Security changed: 7C:7A:91:18:82:5F (public) level 2
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 3 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0040 mtu 672 mps 230 credits 10 result 0x0000
Channel 0x00119700 connected

Change-Id: I2402fd86cc6bdf41a537053325e0a1973c23377a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Luiz Augusto von Dentz d1ae81eddd Bluetooth: L2CAP: Make CoC depend on SMP
This is necessary in order to properly handle security errors which are
part of the testing specification thus can influence qualification.

Change-Id: If444e753be9196f3d5bb36cea00e332a33aa249f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery 5d40ea1d15 Bluetooth: RFCOMM: Introduce helper to initialize dlc
This is to avoid code duplication while implementing outgoing
connection.

Change-Id: I52f882b7be9180f29def59c8ac3ef0a4798b719d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery e3c258e286 Bluetooth: RFCOMM: Introduce helper to get session
This is to avoid code duplication while implementing outgoing
connection.

This also moves setting initiator flag while allocating, than
doing it when SABM is received.

Change-Id: I8e811c995bf0eaa0bd24715e2e96d8a578a79c5d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery 2eba256fd2 Bluetooth: RFCOMM: Define enum and macros for role and CR
This replaces initiator flag of session and dlc to enum which has
two values INITIATOR and ACCEPTOR.

Also this defines macros for CRs in header. Basically there are
three types fo CRs. Frame header CR has different meaning for
UIH and non UIH packets. Also this renames the existing msg hdr
CR to make it consistent.

These changes are basically done to make it more readable

Change-Id: Ic15e93465b0afbd19d8805f27d7a43f34ef38689
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery f6f4acbced Bluetooth: RFCOMM: Remove extra tab
Change-Id: I2edafa32711cbac933d719a1ea0736e955bbb12c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 26d39cd107 Bluetooth: Move controller code to subsys/bluetooth
Move controller code from drivers/controller to
subsys/bluetooth/controller.

Change-Id: I73f675188485aa3267507bad7647796e593a3da0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 6bc645962a Bluetooth: Move Bluetooth host stack to subsys
Move the Bluetooth host stack from net/bluetooth to
subsys/bluetooth/host. This is preparation for having both host and
controller under the same root, i.e. subsys/bluetooth/.

Change-Id: I3bc796f7e331fca0c485f3890d62b9c03e027b96
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00