* Re: Intel 7260 bluetooth malfunction when it is connected to EHCI bus
From: Marcel Holtmann @ 2013-10-30 19:44 UTC (permalink / raw)
To: Hui Wang
Cc: Tedd An, Johan Hedberg, xiong.y.zhang, Gustavo F. Padovan,
linux-bluetooth@vger.kernel.org development
In-Reply-To: <52707428.9070908@canonical.com>
Hi Hui,
>>> The problem is:
>>> On the machine which has Intel 7260 BT module, i use it to connect a bluetooth headset,
>>> it can successfully scan and connect to the headset, when i play sound to the bt headset,
>>> the problem comes, if the bt module is connected to the XHCI, it can work very well.
>>>
>>> u@u-Lenovo-B4400:~$ lsusb -t
>>> 1-7:1.0: No such file or directory
>>> /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
>>> /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/14p, 480M
>>> |__ Port 6: Dev 8, If 0, Class=HID, Driver=usbhid, 1.5M
>>> |__ Port 7: Dev 2, If 0, Class=vend., Driver=, 12M
>>> |__ Port 11: Dev 3, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
>>> |__ Port 11: Dev 3, If 1, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
>>>
>>> But if the bt module is connected to the EHCI, it always fails to play sound.
>>>
>>> u@u-Lenovo-B4400:~$ lsusb -t
>>> /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
>>> /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/14p, 480M
>>> /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/3p, 480M
>>> |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/8p, 480M
>>> /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/3p, 480M
>>> |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M
>>> |__ Port 5: Dev 3, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
>>> |__ Port 5: Dev 3, If 1, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
>>> |__ Port 6: Dev 4, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
>>> |__ Port 6: Dev 4, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
>> can you paste /sys/kernel/debug/usb/devices here.
>>
>> If the uvcvideo driver is also using ISOC URBs, we might have just exhausted the bandwidth of the USB bus here or these two devices just do not play nice with each other.
>>
>> Try to unload the uvcvideo driver and try it again.
> Thanks for your reply, follow your instruction, i totally disabled the camera from the BIOS, then the usb tree like this,
> u@u-Lenovo-B4400:~$ lsusb -t
> 1-1.3:1.0: No such file or directory
> /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
> /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/14p, 480M
> /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
> |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/8p, 480M
> /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
> |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M
> |__ Port 2: Dev 3, If 0, Class=HID, Driver=usbhid, 1.5M
> |__ Port 3: Dev 4, If 0, Class=vend., Driver=, 12M
> |__ Port 5: Dev 5, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
> |__ Port 5: Dev 5, If 1, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
> u@u-Lenovo-B4400:~$ uname -a
> Linux u-Lenovo-B4400 3.12.0-031200rc6-generic #201310191635 SMP Sat Oct 19 20:36:43 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
>
> I re-did the test, the result is same as before, after the headset is connected and i play audio, no sound is heard from the headset.
> And hciconfig output shows still no SCO packets received by BT driver.
> u@u-Lenovo-B4400:~$ hciconfig
> hci0: Type: BR/EDR Bus: USB
> BD Address: 00:15:00:CC:2D:D2 ACL MTU: 1021:5 SCO MTU: 96:5
> UP RUNNING PSCAN
> RX bytes:5853 acl:61 sco:0 events:298 errors:0
> TX bytes:19212 acl:68 sco:1 commands:179 errors:0
this is strange. The only reason I can think of is that you do not have the firmware installed and or it is not loaded correctly. Does dmesg give any indication that something failed here.
Since this is a 3.12 kernel it should have native support for Intel specific setup routing. Any chance you can run btmon -w <file> before plugging the device into the bus. Maybe something goes wrong with the setup routine on EHCI.
Regards
Marcel
^ permalink raw reply
* RE: l2cap sockets not properly multiplexed on ARM
From: Tim Tisdall @ 2013-10-30 20:45 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Alexander Holler, linux-bluetooth@vger.kernel.org
In-Reply-To: <4A213FF7-48BA-4906-8868-7C3A227EF954@holtmann.org>
> Can you have a look at Documentation/dynamic-debug-howto.txt and enable t=
he debug section for the bluetooth.ko kernel module. I wonder if we see som=
ething fishy in there.=0A=
=0A=
That document looks rather long and confusing... what exactly do I need to=
type to get the debugging statements working for bluetooth.ko?=0A=
=0A=
>Do you have the chance to run bluetooth-next tree for testing purposes? I =
rather debug this against the latest tree. I have no ARM platform lying aro=
und. So you have to be my test subject ;)=0A=
=0A=
My understanding is that the latest versions of the bluetooth code require =
kernel versions past 3.4, is this correct? Most of the devices I have only=
have the 3.0 kernel available because they're intended to run Android. Or=
is it possible to run it with the 3.4 kernel? In either case, where can I=
find the bluetooth-next tree?=0A=
^ permalink raw reply
* Re: l2cap sockets not properly multiplexed on ARM
From: Marcel Holtmann @ 2013-10-30 20:57 UTC (permalink / raw)
To: Tim Tisdall; +Cc: Alexander Holler, linux-bluetooth@vger.kernel.org
In-Reply-To: <D9B9EB3A112B8F489DFFA00A6D5C0FE203241A33@AD-BR-EX-2.adroot.flemingc.local>
Hi Tim,
>> Can you have a look at Documentation/dynamic-debug-howto.txt and enable the debug section for the bluetooth.ko kernel module. I wonder if we see something fishy in there.
>
> That document looks rather long and confusing... what exactly do I need to type to get the debugging statements working for bluetooth.ko?
This how you enable it based on file name:
echo -n "file l2cap_core.c +pfl" > /sys/kernel/debug/dynamic_debug/control
echo -n "file l2cap_sock.c +pfl" > /sys/kernel/debug/dynamic_debug/control
Or enabling for the whole module like this:
echo -n “module bluetooth +pfl" > /sys/kernel/debug/dynamic_debug/control
>> Do you have the chance to run bluetooth-next tree for testing purposes? I rather debug this against the latest tree. I have no ARM platform lying around. So you have to be my test subject ;)
>
> My understanding is that the latest versions of the bluetooth code require kernel versions past 3.4, is this correct? Most of the devices I have only have the 3.0 kernel available because they're intended to run Android. Or is it possible to run it with the 3.4 kernel? In either case, where can I find the bluetooth-next tree?
You can always run older userspace on newer kernel. At least that is what is suppose to work. So newer kernel should expose the same interface. Unless we are talking like 5 years old userspace. Then we might be in trouble. However running a bluetooth-next instead of 3.0 or 3.4 is certainly possible.
You find the latest kernel code here:
git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git
We need to find the spot where we for some reason send the SKB to the wrong socket. And that only for ARM as it seems. Seriously, this is a strange behavior.
Btw. sending on the socket works just fine? Meaning btmon shows it going out with the correct ACL handle to the right remote LE device?
Regards
Marcel
^ permalink raw reply
* [RFC 0/5] Disconnect complete refactoring
From: Andre Guedes @ 2013-10-30 22:01 UTC (permalink / raw)
To: linux-bluetooth
Hi all,
This patch set does some code refactoring in disconnect complete event handler
and related functions from Mgmt layer.
This refactoring used to be one patch from LE auto connection patch set, but
since Marcel asked me to do more changes, I put all these refactoring patches
in its own patch set.
Regards,
Andre Guedes (5):
Bluetooth: Check address in mgmt_disconnect_failed()
Bluetooth: Add an extra check in mgmt_device_disconnected()
Bluetooth: Remove link type check in hci_disconn_complete_evt()
Bluetooth: Remove unneeded check in hci_disconn_complete_evt()
Bluetooth: Refactor hci_disconn_complete_evt
net/bluetooth/hci_event.c | 61 ++++++++++++++++++++++-------------------------
net/bluetooth/mgmt.c | 15 +++++++++++-
2 files changed, 43 insertions(+), 33 deletions(-)
--
1.8.4
^ permalink raw reply
* [RFC 1/5] Bluetooth: Check address in mgmt_disconnect_failed()
From: Andre Guedes @ 2013-10-30 22:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383170504-16602-1-git-send-email-andre.guedes@openbossa.org>
Check the address and address type in mgmt_disconnect_failed() otherwise
we may wrongly fail the MGMT_OP_DISCONNECT command.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/mgmt.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 22cf547..6a74aa7 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4613,6 +4613,8 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
u8 link_type, u8 addr_type, u8 status)
{
+ u8 bdaddr_type = link_to_bdaddr(link_type, addr_type);
+ struct mgmt_cp_disconnect *cp;
struct mgmt_rp_disconnect rp;
struct pending_cmd *cmd;
@@ -4623,8 +4625,16 @@ void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
if (!cmd)
return;
+ cp = cmd->param;
+
+ if (bacmp(bdaddr, &cp->addr.bdaddr))
+ return;
+
+ if (cp->addr.type != bdaddr_type)
+ return;
+
bacpy(&rp.addr.bdaddr, bdaddr);
- rp.addr.type = link_to_bdaddr(link_type, addr_type);
+ rp.addr.type = bdaddr_type;
cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT,
mgmt_status(status), &rp, sizeof(rp));
--
1.8.4
^ permalink raw reply related
* [RFC 2/5] Bluetooth: Add an extra check in mgmt_device_disconnected()
From: Andre Guedes @ 2013-10-30 22:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383170504-16602-1-git-send-email-andre.guedes@openbossa.org>
This patch adds an extra check in mgmt_device_disconnected() so we only
send the "Device Disconnected" event if it is ACL_LINK or LE_LINK link
type.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/mgmt.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 6a74aa7..a03ca3c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4595,6 +4595,9 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
struct mgmt_ev_device_disconnected ev;
struct sock *sk = NULL;
+ if (link_type != ACL_LINK && link_type != LE_LINK)
+ return;
+
mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk);
bacpy(&ev.addr.bdaddr, bdaddr);
--
1.8.4
^ permalink raw reply related
* [RFC 3/5] Bluetooth: Remove link type check in hci_disconn_complete_evt()
From: Andre Guedes @ 2013-10-30 22:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383170504-16602-1-git-send-email-andre.guedes@openbossa.org>
We can safely remove the link type check from hci_disconn_complete_
evt() since this check in not required for mgmt_disconnect_failed()
and mgmt_device_disconnected() does it internally.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 5935f74..4673cfb 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1795,8 +1795,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (ev->status == 0)
conn->state = BT_CLOSED;
- if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags) &&
- (conn->type == ACL_LINK || conn->type == LE_LINK)) {
+ if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
if (ev->status) {
mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
conn->dst_type, ev->status);
--
1.8.4
^ permalink raw reply related
* [RFC 4/5] Bluetooth: Remove unneeded check in hci_disconn_complete_evt()
From: Andre Guedes @ 2013-10-30 22:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383170504-16602-1-git-send-email-andre.guedes@openbossa.org>
According to b644ba336 (patch that introduced HCI_CONN_MGMT_CONNECTED
flag), the HCI_CONN_MGMT_CONNECTED flag tracks when mgmt has been
notified about the connection.
That being said, there is no point in checking this flag in hci_
disconn_complete_evt() since neither mgmt_disconnect_failed() nor
mgmt_device_disconnected() depend on it. Below follows more details:
* mgmt_disconnect_failed() removes pending MGMT_OP_DISCONNECT
commands, it doesn't matter if that connection was notified or not.
* mgmt_device_disconnected() sends the mgmt event only if the link
type is ACL_LINK or LE_LINK. For those connection type, the flag is
always set.
So this patch removes the HCI_CONN_MGMT_CONNECTED check.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 4673cfb..9225a9c 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1795,16 +1795,14 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (ev->status == 0)
conn->state = BT_CLOSED;
- if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
- if (ev->status) {
- mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
- conn->dst_type, ev->status);
- } else {
- u8 reason = hci_to_mgmt_reason(ev->reason);
+ if (ev->status) {
+ mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
+ conn->dst_type, ev->status);
+ } else {
+ u8 reason = hci_to_mgmt_reason(ev->reason);
- mgmt_device_disconnected(hdev, &conn->dst, conn->type,
- conn->dst_type, reason);
- }
+ mgmt_device_disconnected(hdev, &conn->dst, conn->type,
+ conn->dst_type, reason);
}
if (ev->status == 0) {
--
1.8.4
^ permalink raw reply related
* [RFC 5/5] Bluetooth: Refactor hci_disconn_complete_evt
From: Andre Guedes @ 2013-10-30 22:01 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383170504-16602-1-git-send-email-andre.guedes@openbossa.org>
hci_disconn_complete_evt() logic is more complicated than what it
should be, making it hard to follow and add new features.
So this patch does some code refactoring by handling the error cases
in the beginning of the function and by moving the main flow into the
first level of function scope. No change is done in the event handling
logic itself.
Besides organizing this messy code, this patch makes easier to add
code for handling LE auto connection (which will be added in a further
patch).
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 56 +++++++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 9225a9c..981d858 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1782,7 +1782,9 @@ static u8 hci_to_mgmt_reason(u8 err)
static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
{
struct hci_ev_disconn_complete *ev = (void *) skb->data;
+ u8 reason = hci_to_mgmt_reason(ev->reason);
struct hci_conn *conn;
+ u8 type;
BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
@@ -1792,40 +1794,38 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (!conn)
goto unlock;
- if (ev->status == 0)
- conn->state = BT_CLOSED;
-
if (ev->status) {
mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
- conn->dst_type, ev->status);
- } else {
- u8 reason = hci_to_mgmt_reason(ev->reason);
-
- mgmt_device_disconnected(hdev, &conn->dst, conn->type,
- conn->dst_type, reason);
+ conn->dst_type, ev->status);
+ goto unlock;
}
- if (ev->status == 0) {
- u8 type = conn->type;
+ conn->state = BT_CLOSED;
- if (type == ACL_LINK && conn->flush_key)
- hci_remove_link_key(hdev, &conn->dst);
- hci_proto_disconn_cfm(conn, ev->reason);
- hci_conn_del(conn);
+ mgmt_device_disconnected(hdev, &conn->dst, conn->type,
+ conn->dst_type, reason);
- /* Re-enable advertising if necessary, since it might
- * have been disabled by the connection. From the
- * HCI_LE_Set_Advertise_Enable command description in
- * the core specification (v4.0):
- * "The Controller shall continue advertising until the Host
- * issues an LE_Set_Advertise_Enable command with
- * Advertising_Enable set to 0x00 (Advertising is disabled)
- * or until a connection is created or until the Advertising
- * is timed out due to Directed Advertising."
- */
- if (type == LE_LINK)
- mgmt_reenable_advertising(hdev);
- }
+
+ if (conn->type == ACL_LINK && conn->flush_key)
+ hci_remove_link_key(hdev, &conn->dst);
+
+ type = conn->type;
+
+ hci_proto_disconn_cfm(conn, ev->reason);
+ hci_conn_del(conn);
+
+ /* Re-enable advertising if necessary, since it might
+ * have been disabled by the connection. From the
+ * HCI_LE_Set_Advertise_Enable command description in
+ * the core specification (v4.0):
+ * "The Controller shall continue advertising until the Host
+ * issues an LE_Set_Advertise_Enable command with
+ * Advertising_Enable set to 0x00 (Advertising is disabled)
+ * or until a connection is created or until the Advertising
+ * is timed out due to Directed Advertising."
+ */
+ if (type == LE_LINK)
+ mgmt_reenable_advertising(hdev);
unlock:
hci_dev_unlock(hdev);
--
1.8.4
^ permalink raw reply related
* Re: l2cap sockets not properly multiplexed on ARM
From: Alexander Holler @ 2013-10-30 23:06 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Tim Tisdall, linux-bluetooth@vger.kernel.org
In-Reply-To: <4A213FF7-48BA-4906-8868-7C3A227EF954@holtmann.org>
Am 30.10.2013 20:40, schrieb Marcel Holtmann:
...
>> So it's perfectly clear: This all works fine on an x86 machine, but is an issue on ARM
...
> Do you have the chance to run bluetooth-next tree for testing purposes?
As Anderson Lizardo already mentioned, maybe first verify that the x86
kernel 3.4 doesn't have the same problem and that it's really a problem
of the ARM kernel. Up to now he didn't say what kernel version he uses
on x86.
Regards.
Alexander Holler
^ permalink raw reply
* [PATCH 00/14] android: Initial support for pairing
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Hi,
Following patches add support for pairing with remote device. Currently
link keys are not yet stored on fs.
This was tested for ssp and legacy pairing with haltest on PC only.
Still need to test those on Android. Some debugs logs from that code
could probably be also improved.
Comments are welcome.
BR
Szymon Janc
Szymon Janc (14):
android: Add missing bonding state definitions to IPC specification
android: Add missing bond state definition to IPC header
android: Add support for handling new link key mgmt event
android: Make load_link_keys function load keys
android: Set default IO capability on daemon start
android: Add support for handling create bond command
android: Add support for handling cancel bond command
android: Add support for handling remove bond command
android: Add support for sending pin code request
android: Add initial support for sending SSP request event
android: Add support for entry variant in SSP request event
android: Add support for notify variant in SSP request event
android: Add support for handling pin reply command
android: Add support for handling SSP reply command
android/adapter.c | 468 +++++++++++++++++++++++++++++++++++++++++++++++-
android/hal-ipc-api.txt | 4 +
android/hal-msg.h | 4 +
3 files changed, 467 insertions(+), 9 deletions(-)
--
1.8.4.rc3
^ permalink raw reply
* [PATCH 01/14] android: Add missing bonding state definitions to IPC specification
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-ipc-api.txt | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index e7af8a3..a5d1980 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -370,6 +370,10 @@ Notifications:
Remote address (6 octets)
Bond state (1 octet)
+ Valid bond state values: 0x00 = None
+ 0x01 = Bonding
+ 0x02 = Bonded
+
Opcode 0x89 - ACL State Changed notification
Notification parameters: Status (1 octect)
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 02/14] android: Add missing bond state definition to IPC header
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-msg.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index d2a0e2a..b0ee73c 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -372,6 +372,10 @@ struct hal_ev_ssp_request {
uint32_t passkey;
} __attribute__((packed));
+#define HAL_BOND_STATE_NONE 0
+#define HAL_BOND_STATE_BONDING 1
+#define HAL_BOND_STATE_BONDED 2
+
#define HAL_EV_BOND_STATE_CHANGED 0x88
struct hal_ev_bond_state_changed {
uint8_t status;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 03/14] android: Add support for handling new link key mgmt event
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
When link key is emitted by kernel bond state change notification is
send to HAL. Storing link key is not yet implemented.
---
android/adapter.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 15b65e5..4b4905b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -195,6 +195,60 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
/* TODO: Gatt attrib set*/
}
+static void store_link_key(const bdaddr_t *dst, const uint8_t *key,
+ uint8_t type, uint8_t pin_length)
+{
+ /* TODO store link key */
+
+}
+
+static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
+ uint8_t state)
+{
+ struct hal_ev_bond_state_changed ev;
+
+ ev.status = status;
+ ev.state = state;
+ bdaddr2android(addr, ev.bdaddr);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_BOND_STATE_CHANGED, sizeof(ev), &ev, -1);
+}
+
+static void new_link_key_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_ev_new_link_key *ev = param;
+ const struct mgmt_addr_info *addr = &ev->key.addr;
+ char dst[18];
+
+ if (length < sizeof(*ev)) {
+ error("Too small new link key event");
+ return;
+ }
+
+ ba2str(&addr->bdaddr, dst);
+
+ DBG("new key for %s type %u pin_len %u",
+ dst, ev->key.type, ev->key.pin_len);
+
+ if (ev->key.pin_len > 16) {
+ error("Invalid PIN length (%u) in new_key event",
+ ev->key.pin_len);
+ return;
+ }
+
+ if (ev->store_hint) {
+ const struct mgmt_link_key_info *key = &ev->key;
+
+ store_link_key(&addr->bdaddr, key->val, key->type,
+ key->pin_len);
+ }
+
+ send_bond_state_change(&addr->bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_BONDED);
+}
+
static void register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -207,6 +261,9 @@ static void register_mgmt_handlers(void)
mgmt_register(adapter->mgmt, MGMT_EV_LOCAL_NAME_CHANGED,
adapter->index, mgmt_local_name_changed_event,
NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_NEW_LINK_KEY, adapter->index,
+ new_link_key_callback, NULL, NULL);
}
static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 04/14] android: Make load_link_keys function load keys
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
GSlist passed is expected to hold mgmt_link_key_info structures.
---
android/adapter.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 4b4905b..d55a070 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -290,22 +290,37 @@ failed:
static void load_link_keys(GSList *keys)
{
struct mgmt_cp_load_link_keys *cp;
- size_t key_len = g_slist_length(keys);
struct mgmt_link_key_info *key;
- size_t len;
+ size_t key_count, cp_size;
+ unsigned int id;
- DBG("");
+ key_count = g_slist_length(keys);
+
+ DBG("keys %zu ", key_count);
+
+ cp_size = sizeof(*cp) + (key_count * sizeof(*key));
+
+ cp = g_malloc0(cp_size);
- len = sizeof(*cp) + key_len * sizeof(*key);
- cp = g_malloc0(len);
+ /*
+ * Even if the list of stored keys is empty, it is important to
+ * load an empty list into the kernel. That way it is ensured
+ * that no old keys from a previous daemon are present.
+ */
+ cp->key_count = htobs(key_count);
- cp->debug_keys = 0;
- cp->key_count = htobs(key_len);
+ for (key = cp->keys; keys != NULL; keys = g_slist_next(keys), key++)
+ memcpy(key, keys->data, sizeof(*key));
- mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, adapter->index, len,
- cp, load_link_keys_complete, NULL, NULL);
+ id = mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, adapter->index,
+ cp_size, cp, load_link_keys_complete, NULL, NULL);
g_free(cp);
+
+ if (id == 0) {
+ error("Failed to load link keys");
+ adapter->ready(-EIO);
+ }
}
static void set_mode_complete(uint8_t status, uint16_t length,
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 05/14] android: Set default IO capability on daemon start
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
There is no HAL function for setting IO capabilities so this is
hardcoded to DisplayYesNo as Android devices usually have screen
and input.
---
android/adapter.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index d55a070..d730dde 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -34,6 +34,9 @@
#include "utils.h"
#include "adapter.h"
+/* Default to DisplayYesNo */
+#define DEFAULT_IO_CAPABILITY 0x01
+
static GIOChannel *notification_io = NULL;
struct bt_adapter {
@@ -358,6 +361,19 @@ static bool set_mode(uint16_t opcode, uint8_t mode)
return false;
}
+static void set_io_capability(void)
+{
+ struct mgmt_cp_set_io_capability cp;
+
+ memset(&cp, 0, sizeof(cp));
+ cp.io_capability = DEFAULT_IO_CAPABILITY;
+
+ if (mgmt_send(adapter->mgmt, MGMT_OP_SET_IO_CAPABILITY,
+ adapter->index, sizeof(cp), &cp,
+ NULL, NULL, NULL) == 0)
+ error("Failed to set IO capability");
+}
+
static void read_info_complete(uint8_t status, uint16_t length, const void *param,
void *user_data)
{
@@ -399,6 +415,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
load_link_keys(NULL);
+ set_io_capability();
set_mode(MGMT_OP_SET_PAIRABLE, 0x01);
return;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 06/14] android: Add support for handling create bond command
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index d730dde..8c5482b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -568,6 +568,64 @@ static uint8_t set_property(void *buf, uint16_t len)
}
}
+static uint8_t status_mgmt2hal(uint8_t mgmt)
+{
+ switch (mgmt) {
+ case MGMT_STATUS_SUCCESS:
+ return HAL_STATUS_SUCCESS;
+ case MGMT_STATUS_NO_RESOURCES:
+ return HAL_STATUS_NOMEM;
+ case MGMT_STATUS_BUSY:
+ return HAL_STATUS_BUSY;
+ case MGMT_STATUS_NOT_SUPPORTED:
+ return HAL_STATUS_UNSUPPORTED;
+ case MGMT_STATUS_INVALID_PARAMS:
+ return HAL_STATUS_INVALID;
+ case MGMT_STATUS_AUTH_FAILED:
+ return HAL_STATUS_AUTH_FAILURE;
+ case MGMT_STATUS_NOT_CONNECTED:
+ return HAL_STATUS_REMOTE_DEVICE_DOWN;
+ default:
+ return HAL_STATUS_FAILED;
+ }
+}
+
+static void pair_device_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_pair_device *rp = param;
+
+ DBG("status %u", status);
+
+ /* On success bond state change will be send when new link key event
+ * is received */
+ if (status == MGMT_STATUS_SUCCESS)
+ return;
+
+ send_bond_state_change(&rp->addr.bdaddr, status_mgmt2hal(status),
+ HAL_BOND_STATE_NONE);
+}
+
+static bool create_bond(void *buf, uint16_t len)
+{
+ struct hal_cmd_create_bond *cmd = buf;
+ struct mgmt_cp_pair_device cp;
+
+ cp.io_cap = DEFAULT_IO_CAPABILITY;
+ cp.addr.type = BDADDR_BREDR;
+ android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
+
+ if (mgmt_send(adapter->mgmt, MGMT_OP_PAIR_DEVICE, adapter->index,
+ sizeof(cp), &cp, pair_device_complete, NULL,
+ NULL) == 0)
+ return false;
+
+ send_bond_state_change(&cp.addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_BONDING);
+
+ return true;
+}
+
void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
uint16_t len)
{
@@ -605,6 +663,11 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
goto error;
break;
+ case HAL_OP_CREATE_BOND:
+ if (!create_bond(buf, len))
+ goto error;
+
+ break;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
goto error;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 07/14] android: Add support for handling cancel bond command
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 8c5482b..0f174a6 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -626,6 +626,19 @@ static bool create_bond(void *buf, uint16_t len)
return true;
}
+static bool cancel_bond(void *buf, uint16_t len)
+{
+ struct hal_cmd_cancel_bond *cmd = buf;
+ struct mgmt_addr_info cp;
+
+ cp.type = BDADDR_BREDR;
+ android2bdaddr(cmd->bdaddr, &cp.bdaddr);
+
+ return mgmt_reply(adapter->mgmt, MGMT_OP_CANCEL_PAIR_DEVICE,
+ adapter->index, sizeof(cp), &cp, NULL, NULL,
+ NULL) > 0;
+}
+
void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
uint16_t len)
{
@@ -668,6 +681,11 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
goto error;
break;
+ case HAL_OP_CANCEL_BOND:
+ if (!cancel_bond(buf, len))
+ goto error;
+
+ break;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
goto error;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 08/14] android: Add support for handling remove bond command
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 0f174a6..0a91149 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -639,6 +639,26 @@ static bool cancel_bond(void *buf, uint16_t len)
NULL) > 0;
}
+static bool remove_bond(void *buf, uint16_t len)
+{
+ struct hal_cmd_remove_bond *cmd = buf;
+ struct mgmt_cp_unpair_device cp;
+
+ cp.disconnect = 1;
+ cp.addr.type = BDADDR_BREDR;
+ android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
+
+ if (mgmt_send(adapter->mgmt, MGMT_OP_UNPAIR_DEVICE,
+ adapter->index, sizeof(cp), &cp,
+ NULL, NULL, NULL) == 0)
+ return false;
+
+ send_bond_state_change(&cp.addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_NONE);
+
+ return true;
+}
+
void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
uint16_t len)
{
@@ -686,6 +706,11 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
goto error;
break;
+ case HAL_OP_REMOVE_BOND:
+ if (!remove_bond(buf, len))
+ goto error;
+
+ break;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
goto error;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 09/14] android: Add support for sending pin code request
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 0a91149..0c5ae8b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -252,6 +252,30 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
HAL_BOND_STATE_BONDED);
}
+static void pin_code_request_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_ev_pin_code_request *ev = param;
+ struct hal_ev_pin_request hal_ev;
+ char dst[18];
+
+ if (length < sizeof(*ev)) {
+ error("Too small PIN code request event");
+ return;
+ }
+
+ ba2str(&ev->addr.bdaddr, dst);
+
+ DBG("%s type %u secure %u", dst, ev->addr.type, ev->secure);
+
+ /* TODO name and CoD of remote devices should probably be cached */
+ memset(&hal_ev, 0, sizeof(hal_ev));
+ bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH, HAL_EV_PIN_REQUEST,
+ sizeof(hal_ev), &hal_ev, -1);
+}
+
static void register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -267,6 +291,9 @@ static void register_mgmt_handlers(void)
mgmt_register(adapter->mgmt, MGMT_EV_NEW_LINK_KEY, adapter->index,
new_link_key_callback, NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_PIN_CODE_REQUEST, adapter->index,
+ pin_code_request_callback, NULL, NULL);
}
static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 10/14] android: Add initial support for sending SSP request event
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
Only consent and confirm variants are supported in this patch.
---
android/adapter.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 0c5ae8b..b99c860 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -276,6 +276,42 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
sizeof(hal_ev), &hal_ev, -1);
}
+static void send_ssp_request(const bdaddr_t *addr, uint8_t variant,
+ uint32_t passkey)
+{
+ struct hal_ev_ssp_request ev;
+
+ /* TODO name and CoD of remote devices should probably be cached */
+ memset(&ev, 0, sizeof(ev));
+ bdaddr2android(addr, ev.bdaddr);
+ ev.pairing_variant = variant;
+ ev.passkey = passkey;
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH, HAL_EV_SSP_REQUEST,
+ sizeof(ev), &ev, -1);
+}
+
+static void user_confirm_request_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_ev_user_confirm_request *ev = param;
+ char dst[18];
+
+ if (length < sizeof(*ev)) {
+ error("Too small user confirm request event");
+ return;
+ }
+
+ ba2str(&ev->addr.bdaddr, dst);
+ DBG("%s confirm_hint %u", dst, ev->confirm_hint);
+
+ if (ev->confirm_hint)
+ send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_CONSENT, 0);
+ else
+ send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_CONFIRM,
+ ev->value);
+}
+
static void register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -294,6 +330,10 @@ static void register_mgmt_handlers(void)
mgmt_register(adapter->mgmt, MGMT_EV_PIN_CODE_REQUEST, adapter->index,
pin_code_request_callback, NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_USER_CONFIRM_REQUEST,
+ adapter->index, user_confirm_request_callback,
+ NULL, NULL);
}
static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 11/14] android: Add support for entry variant in SSP request event
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index b99c860..1be0fb3 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -312,6 +312,23 @@ static void user_confirm_request_callback(uint16_t index, uint16_t length,
ev->value);
}
+static void user_passkey_request_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_ev_user_passkey_request *ev = param;
+ char dst[18];
+
+ if (length < sizeof(*ev)) {
+ error("Too small passkey request event");
+ return;
+ }
+
+ ba2str(&ev->addr.bdaddr, dst);
+ DBG("%s", dst);
+
+ send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_ENTRY, 0);
+}
+
static void register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -334,6 +351,10 @@ static void register_mgmt_handlers(void)
mgmt_register(adapter->mgmt, MGMT_EV_USER_CONFIRM_REQUEST,
adapter->index, user_confirm_request_callback,
NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_USER_PASSKEY_REQUEST,
+ adapter->index, user_passkey_request_callback,
+ NULL, NULL);
}
static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 12/14] android: Add support for notify variant in SSP request event
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 1be0fb3..00766eb 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -329,6 +329,26 @@ static void user_passkey_request_callback(uint16_t index, uint16_t length,
send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_ENTRY, 0);
}
+static void user_passkey_notify_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_ev_passkey_notify *ev = param;
+ char dst[18];
+
+ if (length < sizeof(*ev)) {
+ error("Too small passkey notify event");
+ return;
+ }
+
+ ba2str(&ev->addr.bdaddr, dst);
+ DBG("%s entered %u", dst, ev->entered);
+
+ /* HAL seems to not support entered characters */
+ if (!ev->entered)
+ send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_NOTIF,
+ ev->passkey);
+}
+
static void register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -355,6 +375,10 @@ static void register_mgmt_handlers(void)
mgmt_register(adapter->mgmt, MGMT_EV_USER_PASSKEY_REQUEST,
adapter->index, user_passkey_request_callback,
NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_PASSKEY_NOTIFY, adapter->index,
+ user_passkey_notify_callback, NULL, NULL);
+
}
static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 13/14] android: Add support for handling pin reply command
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 00766eb..a6382dd 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -771,6 +771,49 @@ static bool remove_bond(void *buf, uint16_t len)
return true;
}
+static uint8_t pin_reply(void *buf, uint16_t len)
+{
+ struct hal_cmd_pin_reply *cmd = buf;
+ bdaddr_t bdaddr;
+ char addr[18];
+
+ android2bdaddr(cmd->bdaddr, &bdaddr);
+ ba2str(&bdaddr, addr);
+
+ DBG("%s accept %u pin_len %u", addr, cmd->accept, cmd->pin_len);
+
+ if (!cmd->accept && cmd->pin_len)
+ return HAL_STATUS_INVALID;
+
+ if (cmd->accept) {
+ struct mgmt_cp_pin_code_reply rp;
+
+ memset(&rp, 0, sizeof(rp));
+
+ bacpy(&rp.addr.bdaddr, &bdaddr);
+ rp.addr.type = BDADDR_BREDR;
+ rp.pin_len = cmd->pin_len;
+ memcpy(rp.pin_code, cmd->pin_code, rp.pin_len);
+
+ if (mgmt_reply(adapter->mgmt, MGMT_OP_PIN_CODE_REPLY,
+ adapter->index, sizeof(rp), &rp,
+ NULL, NULL, NULL) == 0)
+ return HAL_STATUS_FAILED;
+ } else {
+ struct mgmt_cp_pin_code_neg_reply rp;
+
+ bacpy(&rp.addr.bdaddr, &bdaddr);
+ rp.addr.type = BDADDR_BREDR;
+
+ if (mgmt_reply(adapter->mgmt, MGMT_OP_PIN_CODE_NEG_REPLY,
+ adapter->index, sizeof(rp), &rp,
+ NULL, NULL, NULL) == 0)
+ return HAL_STATUS_FAILED;
+ }
+
+ return HAL_STATUS_SUCCESS;
+}
+
void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
uint16_t len)
{
@@ -823,6 +866,12 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
goto error;
break;
+ case HAL_OP_PIN_REPLY:
+ status = pin_reply(buf, len);
+ if (status != HAL_STATUS_SUCCESS)
+ goto error;
+
+ break;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
goto error;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 14/14] android: Add support for handling SSP reply command
From: Szymon Janc @ 2013-10-31 2:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383188154-22905-1-git-send-email-szymon.janc@tieto.com>
---
android/adapter.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index a6382dd..9e12879 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -814,6 +814,94 @@ static uint8_t pin_reply(void *buf, uint16_t len)
return HAL_STATUS_SUCCESS;
}
+static uint8_t user_confirm_reply(const bdaddr_t *bdaddr, bool accept)
+{
+ struct mgmt_addr_info cp;
+ uint16_t opcode;
+
+ if (accept)
+ opcode = MGMT_OP_USER_CONFIRM_REPLY;
+ else
+ opcode = MGMT_OP_USER_CONFIRM_NEG_REPLY;
+
+ bacpy(&cp.bdaddr, bdaddr);
+ cp.type = BDADDR_BREDR;
+
+ if (mgmt_reply(adapter->mgmt, opcode, adapter->index, sizeof(cp), &cp,
+ NULL, NULL, NULL) > 0)
+ return HAL_STATUS_SUCCESS;
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t user_passkey_reply(const bdaddr_t *bdaddr, bool accept,
+ uint32_t passkey)
+{
+ unsigned int id;
+
+ if (accept) {
+ struct mgmt_cp_user_passkey_reply cp;
+
+ memset(&cp, 0, sizeof(cp));
+ bacpy(&cp.addr.bdaddr, bdaddr);
+ cp.addr.type = BDADDR_BREDR;
+ cp.passkey = htobl(passkey);
+
+ id = mgmt_reply(adapter->mgmt, MGMT_OP_USER_PASSKEY_REPLY,
+ adapter->index, sizeof(cp), &cp,
+ NULL, NULL, NULL);
+ } else {
+ struct mgmt_cp_user_passkey_neg_reply cp;
+
+ memset(&cp, 0, sizeof(cp));
+ bacpy(&cp.addr.bdaddr, bdaddr);
+ cp.addr.type = BDADDR_BREDR;
+
+ id = mgmt_reply(adapter->mgmt, MGMT_OP_USER_PASSKEY_NEG_REPLY,
+ adapter->index, sizeof(cp), &cp,
+ NULL, NULL, NULL);
+ }
+
+ if (id == 0)
+ return HAL_STATUS_FAILED;
+
+ return HAL_STATUS_SUCCESS;
+}
+
+static uint8_t ssp_reply(void *buf, uint16_t len)
+{
+ struct hal_cmd_ssp_reply *cmd = buf;
+ uint8_t status;
+ bdaddr_t bdaddr;
+ char addr[18];
+
+ /* TODO should parameters sanity be verified here? */
+
+ android2bdaddr(cmd->bdaddr, &bdaddr);
+ ba2str(&bdaddr, addr);
+
+ DBG("%s variant %u accept %u", addr, cmd->ssp_variant, cmd->accept);
+
+ switch (cmd->ssp_variant) {
+ case HAL_SSP_VARIANT_CONFIRM:
+ case HAL_SSP_VARIANT_CONSENT:
+ status = user_confirm_reply(&bdaddr, cmd->accept);
+ break;
+ case HAL_SSP_VARIANT_ENTRY:
+ status = user_passkey_reply(&bdaddr, cmd->accept,
+ cmd->passkey);
+ break;
+ case HAL_SSP_VARIANT_NOTIF:
+ status = HAL_STATUS_SUCCESS;
+ break;
+ default:
+ status = HAL_STATUS_INVALID;
+ break;
+ }
+
+ return status;
+}
+
void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
uint16_t len)
{
@@ -872,6 +960,12 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
goto error;
break;
+ case HAL_OP_SSP_REPLY:
+ status = ssp_reply(buf, len);
+ if (status != HAL_STATUS_SUCCESS)
+ goto error;
+
+ break;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
goto error;
--
1.8.4.rc3
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox