* Re: [PATCHv2 4/6] android: Add supported uuids when adapter is initialized
From: Marcel Holtmann @ 2013-11-06 8:41 UTC (permalink / raw)
To: Johan Hedberg; +Cc: Marcin Kraglak, linux-bluetooth@vger.kernel.org development
In-Reply-To: <20131106080254.GA15573@x220.p-661hnu-f1>
Hi Johan,
>> It will set class of device with proper service hints.
>> We set it statically because we want to keep code simple.
>>
>> ---
>> android/adapter.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 59 insertions(+)
>
> I've applied patches 1-3, but am a bit confused about this one.
>
>> diff --git a/android/adapter.c b/android/adapter.c
>> index 0f24cac..70b9265 100644
>> --- a/android/adapter.c
>> +++ b/android/adapter.c
>> @@ -52,6 +52,29 @@ static GIOChannel *notification_io = NULL;
>> /* This list contains addresses which are asked for records */
>> static GSList *browse_reqs;
>>
>> +/*
>> + * This is an array of supported uuids and service hints. We add them via mgmt
>> + * interface when adapter is initialized. Uuids are in reverse orded.
>> + */
>> +static const struct mgmt_cp_add_uuid supported_services[] = {
>> + /* OBEX_OPP_UUID */
>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>> + 0x00, 0x10, 0x00, 0x00, 0x05, 0x11, 0x00, 0x00 },
>> + .svc_hint = 0x10 },
>> + /* HFP_AG_UUID */
>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>> + 0x00, 0x10, 0x00, 0x00, 0x1f, 0x11, 0x00, 0x00 },
>> + .svc_hint = 0x40 },
>> + /* ADVANCED_AUDIO_UUID */
>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>> + 0x00, 0x10, 0x00, 0x00, 0x0d, 0x11, 0x00, 0x00 },
>> + .svc_hint = 0x08 },
>> + /* PANU_UUID */
>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>> + 0x00, 0x10, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00 },
>> + .svc_hint = 0x02 }
>> +};
>
> I seem to remember the discussion around this drifting back to doing the
> registration dynamically. Do I remember wrong? Wasn't it so that at
> least some UUIDs (such as PAN) with a bluedroid based system only appear
> when you actually enable support for the profile in the UI?
looking at a Nexus 4, the SDP database seems static. The PAN record is always present.
I think dynamic is on the level do we compile in support for the PAN HAL module or not. So the record and UUID list should come from the PAN module. So it is kinda dynamic in that sense, but ultimately static.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 1/2] android/debug: Export print uuid function
From: Marcel Holtmann @ 2013-11-06 8:42 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <20131106083144.GD18874@aemeltch-MOBL1>
Hi Andrei,
>>> The function will be reused in socket HAL.
>>> ---
>>> android/client/textconv.c | 2 +-
>>> android/client/textconv.h | 1 +
>>> 2 files changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/android/client/textconv.c b/android/client/textconv.c
>>> index 9a2f7e6..e6f327f 100644
>>> --- a/android/client/textconv.c
>>> +++ b/android/client/textconv.c
>>> @@ -237,7 +237,7 @@ char *bdaddr2str(const bt_bdaddr_t *bd_addr)
>>> return bt_bdaddr_t2str(bd_addr, bdaddr_tls_buffer);
>>> }
>>>
>>> -static char *btuuid2str(const bt_uuid_t *uuid)
>>> +char *btuuid2str(const bt_uuid_t *uuid)
>>> {
>>> static char buf[MAX_UUID_STR_LEN];
>>>
>>> diff --git a/android/client/textconv.h b/android/client/textconv.h
>>> index 1c848ef..7520b04 100644
>>> --- a/android/client/textconv.h
>>> +++ b/android/client/textconv.h
>>> @@ -109,6 +109,7 @@ void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
>>>
>>> char *btproperty2str(const bt_property_t *property);
>>> char *bdaddr2str(const bt_bdaddr_t *bd_addr);
>>> +char *btuuid2str(const bt_uuid_t *uuid);
>>
>> this is totally backwards then. The HAL should not depend on client code.
>>
>
> So shall the function be moved to utils.c inside android or even better
> src/shared?
keep it inside android/ directory.
Regards
Marcel
^ permalink raw reply
* [PATCH] Bluetooth: Remove unnecessary 'send' parameter from smp_failure()
From: johan.hedberg @ 2013-11-06 9:24 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
The send parameter has only been used for determining whether to send a
Pairing Failed PDU or not. However, the function can equally well use
the already existing reason parameter to make this choice and send the
PDU whenever a non-zero value was passed.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/smp.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 4b07acb8293c..f99352d1aa43 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -257,11 +257,11 @@ static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size)
return 0;
}
-static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send)
+static void smp_failure(struct l2cap_conn *conn, u8 reason)
{
struct hci_conn *hcon = conn->hcon;
- if (send)
+ if (reason)
smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason),
&reason);
@@ -406,7 +406,7 @@ static void confirm_work(struct work_struct *work)
return;
error:
- smp_failure(conn, reason, 1);
+ smp_failure(conn, reason);
}
static void random_work(struct work_struct *work)
@@ -490,7 +490,7 @@ static void random_work(struct work_struct *work)
return;
error:
- smp_failure(conn, reason, 1);
+ smp_failure(conn, reason);
}
static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
@@ -555,10 +555,10 @@ int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey)
break;
case MGMT_OP_USER_PASSKEY_NEG_REPLY:
case MGMT_OP_USER_CONFIRM_NEG_REPLY:
- smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED, 1);
+ smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED);
return 0;
default:
- smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED, 1);
+ smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED);
return -EOPNOTSUPP;
}
@@ -895,7 +895,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
break;
case SMP_CMD_PAIRING_FAIL:
- smp_failure(conn, skb->data[0], 0);
+ smp_failure(conn, 0);
reason = 0;
err = -EPERM;
break;
@@ -941,7 +941,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
done:
if (reason)
- smp_failure(conn, reason, 1);
+ smp_failure(conn, reason);
kfree_skb(skb);
return err;
--
1.8.3.1
^ permalink raw reply related
* [PATCHv3] android: Implement class of device property callback
From: Marcin Kraglak @ 2013-11-06 10:59 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
This will send adapter property with class of device
to notification socket.
---
android/adapter.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 0f24cac..cf5edcd 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -189,6 +189,28 @@ static void scan_mode_changed(void)
g_free(ev);
}
+static void adapter_class_changed(void)
+{
+ struct hal_ev_adapter_props_changed *ev;
+ int len;
+
+ len = sizeof(*ev) + sizeof(struct hal_property) + sizeof(uint32_t);
+
+ ev = g_malloc(len);
+
+ ev->num_props = 1;
+ ev->status = HAL_STATUS_SUCCESS;
+
+ ev->props[0].type = HAL_PROP_ADAPTER_CLASS;
+ ev->props[0].len = sizeof(uint32_t);
+ memcpy(ev->props->val, &adapter->dev_class, sizeof(uint32_t));
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+ g_free(ev);
+}
+
static void settings_changed(uint32_t settings)
{
uint32_t changed_mask;
@@ -257,7 +279,7 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
adapter->dev_class = dev_class;
- /* TODO: Inform prop change: Class */
+ adapter_class_changed();
/* TODO: Gatt attrib set*/
}
@@ -1219,11 +1241,11 @@ static bool get_uuids(void)
static bool get_class(void)
{
- DBG("Not implemented");
+ DBG("");
- /* TODO: Add implementation */
+ adapter_class_changed();
- return false;
+ return true;
}
static bool get_type(void)
--
1.8.4.1
^ permalink raw reply related
* Re: [PATCHv2 4/6] android: Add supported uuids when adapter is initialized
From: Marcin Kraglak @ 2013-11-06 11:08 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Johan Hedberg, linux-bluetooth@vger.kernel.org development
In-Reply-To: <FC8AC89E-747D-4005-9816-9A00734DC2B0@holtmann.org>
Hi Johan, Marcel
On 6 November 2013 09:41, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Johan,
>
>>> It will set class of device with proper service hints.
>>> We set it statically because we want to keep code simple.
>>>
>>> ---
>>> android/adapter.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>> 1 file changed, 59 insertions(+)
>>
>> I've applied patches 1-3, but am a bit confused about this one.
>>
>>> diff --git a/android/adapter.c b/android/adapter.c
>>> index 0f24cac..70b9265 100644
>>> --- a/android/adapter.c
>>> +++ b/android/adapter.c
>>> @@ -52,6 +52,29 @@ static GIOChannel *notification_io = NULL;
>>> /* This list contains addresses which are asked for records */
>>> static GSList *browse_reqs;
>>>
>>> +/*
>>> + * This is an array of supported uuids and service hints. We add them via mgmt
>>> + * interface when adapter is initialized. Uuids are in reverse orded.
>>> + */
>>> +static const struct mgmt_cp_add_uuid supported_services[] = {
>>> + /* OBEX_OPP_UUID */
>>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>>> + 0x00, 0x10, 0x00, 0x00, 0x05, 0x11, 0x00, 0x00 },
>>> + .svc_hint = 0x10 },
>>> + /* HFP_AG_UUID */
>>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>>> + 0x00, 0x10, 0x00, 0x00, 0x1f, 0x11, 0x00, 0x00 },
>>> + .svc_hint = 0x40 },
>>> + /* ADVANCED_AUDIO_UUID */
>>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>>> + 0x00, 0x10, 0x00, 0x00, 0x0d, 0x11, 0x00, 0x00 },
>>> + .svc_hint = 0x08 },
>>> + /* PANU_UUID */
>>> + { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
>>> + 0x00, 0x10, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00 },
>>> + .svc_hint = 0x02 }
>>> +};
>>
>> I seem to remember the discussion around this drifting back to doing the
>> registration dynamically. Do I remember wrong? Wasn't it so that at
>> least some UUIDs (such as PAN) with a bluedroid based system only appear
>> when you actually enable support for the profile in the UI?
>
> looking at a Nexus 4, the SDP database seems static. The PAN record is always present.
>
> I think dynamic is on the level do we compile in support for the PAN HAL module or not. So the record and UUID list should come from the PAN module. So it is kinda dynamic in that sense, but ultimately static.
>
> Regards
>
> Marcel
>
Could it look like this:
we will hold that static array off uuids and svc hints and additional
profile_id.
Each profile will call generic method like
adapter_register_profile(profile_id) (just example), and it will add
sdp record to sdp server & uuid to mgmt interface. Profiles
implemented out of stack (I mean opp, pbab etc) will have static sdp
record and uuid which will be added once adapter is initialized. What
is your opinion?
Regards
Marcin
^ permalink raw reply
* Re: [PATCHv3] android: Implement class of device property callback
From: Johan Hedberg @ 2013-11-06 11:32 UTC (permalink / raw)
To: Marcin Kraglak; +Cc: linux-bluetooth
In-Reply-To: <1383735562-21777-1-git-send-email-marcin.kraglak@tieto.com>
Hi Marcin,
On Wed, Nov 06, 2013, Marcin Kraglak wrote:
> This will send adapter property with class of device
> to notification socket.
> ---
> android/adapter.c | 30 ++++++++++++++++++++++++++----
> 1 file changed, 26 insertions(+), 4 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* [PATCH 0/6] Add missing hid ipc doc and hal headers
From: Ravi kumar Veeramally @ 2013-11-06 11:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
This patch adds missing hid ipc documentation, hal headers,
renaming and virtual unplug notification in hid HAL.
Unsupported methods are virtual unplug and send data in daemon.
Ravi kumar Veeramally (6):
android/hid: Add missing hid send data parameters in ipc document
android/hid: Add missing parameters in send data struct in HAL headers
android/hid: Fill send data structure variables in hal-hidhost
android/hid: Rename virtual unplug define and struct
android/hid: Add hid event virtual unplug structure to HAL msg headers
android/hid: Handle virtual unplug notification in hid hal
android/hal-hidhost.c | 18 ++++++++++++++++--
android/hal-ipc-api.txt | 4 +++-
android/hal-msg.h | 14 +++++++++++---
android/hid.c | 5 +++--
4 files changed, 33 insertions(+), 8 deletions(-)
--
1.8.1.2
^ permalink raw reply
* [PATCH 1/6] android/hid: Add missing hid send data parameters in ipc document
From: Ravi kumar Veeramally @ 2013-11-06 11:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383738528-14550-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-ipc-api.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index c39cb0d..da4eaaa 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -566,7 +566,9 @@ Commands and responses:
Opcode 0x09 - Send Data command/response
Command parameters: Remote address (6 octets)
- ...
+ Report length (2 octets)
+ Report data (670 octets)
+
Response parameters: <none>
In case of an error, the error response will be returned.
--
1.8.1.2
^ permalink raw reply related
* [PATCH 2/6] android/hid: Add missing parameters in send data struct in HAL headers
From: Ravi kumar Veeramally @ 2013-11-06 11:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383738528-14550-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-msg.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index f0cc800..eb145a5 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -298,7 +298,9 @@ struct hal_cmd_hid_set_report {
#define HAL_OP_HID_SEND_DATA 0x09
struct hal_cmd_hid_send_data {
- uint8_t bdaddr[6];
+ uint8_t bdaddr[6];
+ uint16_t len;
+ uint8_t data[670];
} __attribute__((packed));
#define HAL_OP_AV_CONNECT 0x01
--
1.8.1.2
^ permalink raw reply related
* [PATCH 3/6] android/hid: Fill send data structure variables in hal-hidhost
From: Ravi kumar Veeramally @ 2013-11-06 11:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383738528-14550-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-hidhost.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index f1a2223..22a5d15 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -330,6 +330,8 @@ static bt_status_t hh_send_data(bt_bdaddr_t *bd_addr, char *data)
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+ cmd.len = strlen(data);
+ memcpy(cmd.data, data, cmd.len);
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HID_SEND_DATA,
sizeof(cmd), &cmd, 0, NULL, NULL);
--
1.8.1.2
^ permalink raw reply related
* [PATCH 4/6] android/hid: Rename virtual unplug define and struct
From: Ravi kumar Veeramally @ 2013-11-06 11:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383738528-14550-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Renaming virtual unplug define and strcut name from VP to more
meaning full.
---
android/hal-hidhost.c | 4 ++--
android/hal-msg.h | 4 ++--
android/hid.c | 5 +++--
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 22a5d15..b24e74e 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -140,7 +140,7 @@ static bt_status_t hh_disconnect(bt_bdaddr_t *bd_addr)
static bt_status_t hh_virtual_unplug(bt_bdaddr_t *bd_addr)
{
- struct hal_cmd_hid_vp cmd;
+ struct hal_cmd_hid_virtual_unplug cmd;
DBG("");
@@ -152,7 +152,7 @@ static bt_status_t hh_virtual_unplug(bt_bdaddr_t *bd_addr)
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
- return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HID_VP,
+ return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HID_VIRTUAL_UNPLUG,
sizeof(cmd), &cmd, 0, NULL, NULL);
}
diff --git a/android/hal-msg.h b/android/hal-msg.h
index eb145a5..59e4f78 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -242,8 +242,8 @@ struct hal_cmd_hid_disconnect {
uint8_t bdaddr[6];
} __attribute__((packed));
-#define HAL_OP_HID_VP 0x03
-struct hal_cmd_hid_vp {
+#define HAL_OP_HID_VIRTUAL_UNPLUG 0x03
+struct hal_cmd_hid_virtual_unplug {
uint8_t bdaddr[6];
} __attribute__((packed));
diff --git a/android/hid.c b/android/hid.c
index c38c4c1..77dc81d 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -740,7 +740,8 @@ static uint8_t bt_hid_disconnect(struct hal_cmd_hid_disconnect *cmd,
return HAL_STATUS_SUCCESS;
}
-static uint8_t bt_hid_virtual_unplug(struct hal_cmd_hid_vp *cmd, uint16_t len)
+static uint8_t bt_hid_virtual_unplug(struct hal_cmd_hid_virtual_unplug *cmd,
+ uint16_t len)
{
DBG("Not Implemented");
@@ -938,7 +939,7 @@ void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
case HAL_OP_HID_DISCONNECT:
status = bt_hid_disconnect(buf, len);
break;
- case HAL_OP_HID_VP:
+ case HAL_OP_HID_VIRTUAL_UNPLUG:
status = bt_hid_virtual_unplug(buf, len);
break;
case HAL_OP_HID_SET_INFO:
--
1.8.1.2
^ permalink raw reply related
* [PATCH 5/6] android/hid: Add hid event virtual unplug structure to HAL msg headers
From: Ravi kumar Veeramally @ 2013-11-06 11:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383738528-14550-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-msg.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 59e4f78..740f2ab 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -477,6 +477,12 @@ struct hal_ev_hid_get_report {
uint8_t data[0];
} __attribute__((packed));
+#define HAL_EV_HID_VIRTUAL_UNPLUG 0x86
+struct hal_ev_hid_virtual_unplug {
+ uint8_t bdaddr[6];
+ uint8_t status;
+} __attribute__((packed));
+
#define HAL_EV_AV_CONNECTION_STATE 0x81
struct hal_ev_av_connection_state {
uint8_t state;
--
1.8.1.2
^ permalink raw reply related
* [PATCH 6/6] android/hid: Handle virtual unplug notification in hid hal
From: Ravi kumar Veeramally @ 2013-11-06 11:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383738528-14550-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-hidhost.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index b24e74e..74a7fe7 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -77,6 +77,15 @@ static void handle_get_report(void *buf)
ev->status, ev->data, ev->len);
}
+static void handle_virtual_unplug(void *buf)
+{
+ struct hal_ev_hid_virtual_unplug *ev = buf;
+
+ if (bt_hh_cbacks->virtual_unplug_cb)
+ bt_hh_cbacks->virtual_unplug_cb((bt_bdaddr_t *) ev->bdaddr,
+ ev->status);
+}
+
/* will be called from notification thread context */
void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
{
@@ -96,6 +105,9 @@ void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_HID_GET_REPORT:
handle_get_report(buf);
break;
+ case HAL_EV_HID_VIRTUAL_UNPLUG:
+ handle_virtual_unplug(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.1.2
^ permalink raw reply related
* Re: [PATCH] Bluetooth: Remove unnecessary 'send' parameter from smp_failure()
From: Anderson Lizardo @ 2013-11-06 13:31 UTC (permalink / raw)
To: Johan Hedberg; +Cc: BlueZ development
In-Reply-To: <1383729897-28492-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
On Wed, Nov 6, 2013 at 5:24 AM, <johan.hedberg@gmail.com> wrote:
> @@ -895,7 +895,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
> break;
>
> case SMP_CMD_PAIRING_FAIL:
> - smp_failure(conn, skb->data[0], 0);
> + smp_failure(conn, 0);
I think you meant "smp_failure(conn, skb->data[0]);" here.
> reason = 0;
> err = -EPERM;
> break;
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH] Bluetooth: Remove unnecessary 'send' parameter from smp_failure()
From: Anderson Lizardo @ 2013-11-06 13:32 UTC (permalink / raw)
To: Johan Hedberg; +Cc: BlueZ development
In-Reply-To: <CAJdJm_MGVDvH4h71PgD6YWavOBm=xpgnh1nMtFNtEpL7gEQQcw@mail.gmail.com>
Hi again,
On Wed, Nov 6, 2013 at 9:31 AM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> Hi Johan,
>
> On Wed, Nov 6, 2013 at 5:24 AM, <johan.hedberg@gmail.com> wrote:
>
>> @@ -895,7 +895,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
>> break;
>>
>> case SMP_CMD_PAIRING_FAIL:
>> - smp_failure(conn, skb->data[0], 0);
>> + smp_failure(conn, 0);
>
> I think you meant "smp_failure(conn, skb->data[0]);" here.
My bad, I see now that the purpose is to not send an error in this case.
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH] Bluetooth: Remove unnecessary 'send' parameter from smp_failure()
From: Johan Hedberg @ 2013-11-06 13:44 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: BlueZ development
In-Reply-To: <CAJdJm_Mj4AUHka3y5T1T=GEAATbuzwgsB20dLSMEzpdzi56jbA@mail.gmail.com>
Hi Lizardo,
On Wed, Nov 06, 2013, Anderson Lizardo wrote:
> On Wed, Nov 6, 2013 at 9:31 AM, Anderson Lizardo
> <anderson.lizardo@openbossa.org> wrote:
> > Hi Johan,
> >
> > On Wed, Nov 6, 2013 at 5:24 AM, <johan.hedberg@gmail.com> wrote:
> >
> >> @@ -895,7 +895,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
> >> break;
> >>
> >> case SMP_CMD_PAIRING_FAIL:
> >> - smp_failure(conn, skb->data[0], 0);
> >> + smp_failure(conn, 0);
> >
> > I think you meant "smp_failure(conn, skb->data[0]);" here.
>
> My bad, I see now that the purpose is to not send an error in this case.
Exactly. Which is why the original code was misleading in that you might
have thought it actually did something with skb->data[0].
Johan
^ permalink raw reply
* [PATCH 1/3] android/hal-sock: Check socket type in connect
From: Andrei Emeltchenko @ 2013-11-06 14:03 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Only RFCOMM sockets are supported in Android.
---
android/hal-sock.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/android/hal-sock.c b/android/hal-sock.c
index 131877a..cd85f1f 100644
--- a/android/hal-sock.c
+++ b/android/hal-sock.c
@@ -83,6 +83,11 @@ static bt_status_t sock_connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
DBG("uuid %p chan %d sock %p type %d", uuid, chan, sock, type);
+ if (type != BTSOCK_RFCOMM) {
+ error("Socket type %u not supported", type);
+ return BT_STATUS_UNSUPPORTED;
+ }
+
cmd.flags = flags;
cmd.type = type;
cmd.channel = chan;
--
1.7.10.4
^ permalink raw reply related
* [PATCH 2/3] android/daemon: Move include mgmt.h to adapter.h
From: Andrei Emeltchenko @ 2013-11-06 14:03 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383746614-15077-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Without including src/shared/mgmt.h adapter.h cannot be included.
This force some profiles which do not use mgmt interface to include
src/shared/mgmt.h like hid.c and socket.c
---
android/adapter.c | 1 -
android/adapter.h | 1 +
android/hid.c | 1 -
android/main.c | 1 -
4 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index cf5edcd..db70b46 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -32,7 +32,6 @@
#include "lib/bluetooth.h"
#include "lib/sdp.h"
#include "lib/mgmt.h"
-#include "src/shared/mgmt.h"
#include "src/glib-helper.h"
#include "src/eir.h"
#include "lib/sdp.h"
diff --git a/android/adapter.h b/android/adapter.h
index 2afc67a..eca77ae 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -27,6 +27,7 @@
#include <glib.h>
#include "lib/bluetooth.h"
+#include "src/shared/mgmt.h"
typedef void (*bt_adapter_ready)(int err);
diff --git a/android/hid.c b/android/hid.c
index c38c4c1..2ef2733 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -38,7 +38,6 @@
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
#include "lib/uuid.h"
-#include "src/shared/mgmt.h"
#include "src/sdp-client.h"
#include "src/glib-helper.h"
#include "profiles/input/uhid_copy.h"
diff --git a/android/main.c b/android/main.c
index 75004cf..80d7c24 100644
--- a/android/main.c
+++ b/android/main.c
@@ -46,7 +46,6 @@
#include "lib/bluetooth.h"
#include "lib/mgmt.h"
-#include "src/shared/mgmt.h"
#include "adapter.h"
#include "socket.h"
--
1.7.10.4
^ permalink raw reply related
* [PATCH 3/3] android/hal: Rename hal_op_sock_listen to hal_cmd_sock_listen
From: Andrei Emeltchenko @ 2013-11-06 14:03 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383746614-15077-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This makes structures consistent with the rest of the code.
---
android/hal-msg.h | 4 ++--
android/hal-sock.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index f0cc800..a5e5c76 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -215,7 +215,7 @@ struct hal_cmd_le_test_mode {
/* Bluetooth Socket HAL api */
#define HAL_OP_SOCK_LISTEN 0x01
-struct hal_op_sock_listen {
+struct hal_cmd_sock_listen {
uint8_t type;
uint8_t name[256];
uint8_t uuid[16];
@@ -224,7 +224,7 @@ struct hal_op_sock_listen {
} __attribute__((packed));
#define HAL_OP_SOCK_CONNECT 0x02
-struct hal_op_sock_connect {
+struct hal_cmd_sock_connect {
uint8_t bdaddr[6];
uint8_t type;
uint8_t uuid[16];
diff --git a/android/hal-sock.c b/android/hal-sock.c
index cd85f1f..32c7939 100644
--- a/android/hal-sock.c
+++ b/android/hal-sock.c
@@ -29,7 +29,7 @@ static bt_status_t sock_listen_rfcomm(const char *service_name,
const uint8_t *uuid, int chan,
int *sock, int flags)
{
- struct hal_op_sock_listen cmd;
+ struct hal_cmd_sock_listen cmd;
DBG("");
@@ -73,7 +73,7 @@ static bt_status_t sock_connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
const uint8_t *uuid, int chan,
int *sock, int flags)
{
- struct hal_op_sock_connect cmd;
+ struct hal_cmd_sock_connect cmd;
if ((!uuid && chan <= 0) || !bdaddr || !sock) {
error("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 1/2] android: Create debug utils helpers
From: Andrei Emeltchenko @ 2013-11-06 14:07 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <903E7C5D-33E0-4EDB-BD6D-02B183278514@holtmann.org>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Create debug-utils helpers which helps to decode packets Android
sends through HAL interface.
---
android/Android.mk | 2 ++
android/Makefile.am | 3 ++-
android/client/if-gatt.c | 1 +
android/client/textconv.c | 42 ++------------------------------
android/client/textconv.h | 2 --
android/debug-utils.c | 58 +++++++++++++++++++++++++++++++++++++++++++++
android/debug-utils.h | 26 ++++++++++++++++++++
7 files changed, 91 insertions(+), 43 deletions(-)
create mode 100644 android/debug-utils.c
create mode 100644 android/debug-utils.h
diff --git a/android/Android.mk b/android/Android.mk
index d76dfaf..0a8bd6c 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -88,6 +88,7 @@ LOCAL_SRC_FILES := \
hal-pan.c \
hal-av.c \
client/textconv.c \
+ debug-utils.c \
LOCAL_C_INCLUDES += \
$(call include-path-for, system-core) \
@@ -125,6 +126,7 @@ LOCAL_SRC_FILES := \
client/if-hh.c \
client/if-pan.c \
client/if-sock.c \
+ debug-utils.c \
ANDROID_4_3_OR_ABOVE := $(shell echo 0 | awk -v v=$(PLATFORM_SDK_VERSION) 'END {print (v > 17) ? 1 : 0}')
diff --git a/android/Makefile.am b/android/Makefile.am
index 3c51390..e29da08 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -68,7 +68,8 @@ android_haltest_SOURCES = android/client/haltest.c \
android/client/if-hh.c \
android/client/if-pan.c \
android/client/if-sock.c \
- android/client/hwmodule.c
+ android/client/hwmodule.c \
+ android/debug-utils.h android/debug-utils.c
android_haltest_LDADD = android/libhal-internal.la
diff --git a/android/client/if-gatt.c b/android/client/if-gatt.c
index b2b20cb..eb049c1 100644
--- a/android/client/if-gatt.c
+++ b/android/client/if-gatt.c
@@ -17,6 +17,7 @@
#include <hardware/bluetooth.h>
+#include "../debug-utils.h"
#include "if-main.h"
const btgatt_interface_t *if_gatt = NULL;
diff --git a/android/client/textconv.c b/android/client/textconv.c
index 4def3da..07924ac 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -19,6 +19,8 @@
#include <stdio.h>
#include <hardware/bluetooth.h>
+#include "../debug-utils.h"
+
#include "textconv.h"
/*
@@ -154,39 +156,6 @@ void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr)
&p[0], &p[1], &p[2], &p[3], &p[4], &p[5]);
}
-static const char BT_BASE_UUID[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb
-};
-
-/*
- * converts uuid to string
- * buf should be at least 39 bytes
- *
- * returns string representation of uuid
- */
-char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf)
-{
- int shift = 0;
- int i;
- int is_bt;
-
- is_bt = !memcmp(&uuid->uu[4], &BT_BASE_UUID[4], sizeof(bt_uuid_t) - 4);
-
- for (i = 0; i < (int) sizeof(bt_uuid_t); i++) {
- if (i == 4 && is_bt)
- break;
-
- if (i == 4 || i == 6 || i == 8 || i == 10) {
- buf[i * 2 + shift] = '-';
- shift++;
- }
- sprintf(buf + i * 2 + shift, "%02x", uuid->uu[i]);
- }
-
- return buf;
-}
-
/* converts string to uuid */
void str2bt_uuid_t(const char *str, bt_uuid_t *uuid)
{
@@ -234,13 +203,6 @@ char *bdaddr2str(const bt_bdaddr_t *bd_addr)
return bt_bdaddr_t2str(bd_addr, buf);
}
-static char *btuuid2str(const bt_uuid_t *uuid)
-{
- static char buf[MAX_UUID_STR_LEN];
-
- return bt_uuid_t2str(uuid, buf);
-}
-
char *btproperty2str(const bt_property_t *property)
{
static char buf[4096];
diff --git a/android/client/textconv.h b/android/client/textconv.h
index 1c848ef..837eb4e 100644
--- a/android/client/textconv.h
+++ b/android/client/textconv.h
@@ -103,8 +103,6 @@ static struct int2str __##type##2str[] = {
char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf);
void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr);
-#define MAX_UUID_STR_LEN 37
-char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf);
void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
char *btproperty2str(const bt_property_t *property);
diff --git a/android/debug-utils.c b/android/debug-utils.c
new file mode 100644
index 0000000..07bfb27
--- /dev/null
+++ b/android/debug-utils.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <hardware/bluetooth.h>
+
+#include "debug-utils.h"
+
+/*
+ * converts uuid to string
+ * buf should be at least 39 bytes
+ *
+ * returns string representation of uuid
+ */
+char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf)
+{
+ int shift = 0;
+ int i;
+ int is_bt;
+
+ is_bt = !memcmp(&uuid->uu[4], &BT_BASE_UUID[4], sizeof(bt_uuid_t) - 4);
+
+ for (i = 0; i < (int) sizeof(bt_uuid_t); i++) {
+ if (i == 4 && is_bt)
+ break;
+
+ if (i == 4 || i == 6 || i == 8 || i == 10) {
+ buf[i * 2 + shift] = '-';
+ shift++;
+ }
+ sprintf(buf + i * 2 + shift, "%02x", uuid->uu[i]);
+ }
+
+ return buf;
+}
+
+char *btuuid2str(const bt_uuid_t *uuid)
+{
+ static char buf[MAX_UUID_STR_LEN];
+
+ return bt_uuid_t2str(uuid, buf);
+}
diff --git a/android/debug-utils.h b/android/debug-utils.h
new file mode 100644
index 0000000..d40b430
--- /dev/null
+++ b/android/debug-utils.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define MAX_UUID_STR_LEN 37
+
+static const char BT_BASE_UUID[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb
+};
+
+char *btuuid2str(const bt_uuid_t *uuid);
+char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf);
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 2/2] android/hal: Add UUID debug print in socket HAL
From: Andrei Emeltchenko @ 2013-11-06 14:07 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383746829-15167-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/hal-sock.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/android/hal-sock.c b/android/hal-sock.c
index 32c7939..750cf5b 100644
--- a/android/hal-sock.c
+++ b/android/hal-sock.c
@@ -25,6 +25,8 @@
#include "hal-msg.h"
#include "hal.h"
+#include "debug-utils.h"
+
static bt_status_t sock_listen_rfcomm(const char *service_name,
const uint8_t *uuid, int chan,
int *sock, int flags)
@@ -49,13 +51,14 @@ static bt_status_t sock_listen(btsock_type_t type, const char *service_name,
int *sock, int flags)
{
if ((!uuid && chan <= 0) || !sock) {
- error("%s: invalid params: uuid %p, chan %d, sock %p",
- __func__, uuid, chan, sock);
+ error("Invalid params: uuid %s, chan %d, sock %p",
+ btuuid2str((bt_uuid_t *) uuid), chan, sock);
return BT_STATUS_PARM_INVALID;
}
- DBG("uuid %p chan %d sock %p type %d service_name %s",
- uuid, chan, sock, type, service_name);
+ DBG("uuid %s chan %d sock %p type %d service_name %s",
+ btuuid2str((bt_uuid_t *) uuid), chan,
+ sock, type, service_name);
switch (type) {
case BTSOCK_RFCOMM:
@@ -76,12 +79,13 @@ static bt_status_t sock_connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
struct hal_cmd_sock_connect cmd;
if ((!uuid && chan <= 0) || !bdaddr || !sock) {
- error("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
- bdaddr, uuid, chan, sock);
+ error("Invalid params: bd_addr %p, uuid %s, chan %d, sock %p",
+ bdaddr, btuuid2str((bt_uuid_t *) uuid), chan, sock);
return BT_STATUS_PARM_INVALID;
}
- DBG("uuid %p chan %d sock %p type %d", uuid, chan, sock, type);
+ DBG("uuid %s chan %d sock %p type %d", btuuid2str((bt_uuid_t *) uuid),
+ chan, sock, type);
if (type != BTSOCK_RFCOMM) {
error("Socket type %u not supported", type);
--
1.7.10.4
^ permalink raw reply related
* [RFC 00/14] IPC sanity checks
From: Szymon Janc @ 2013-11-06 14:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Hi,
Following patches are implementing verification of correctness of messages
received over android IPC. The idea for keeping those checks in single
place is that messages passed are quite similar in structure and can
be group into 4 categories. This will also limit possible exit points both
in daemon and HAL as IPC error should trigger disconnection and shutdown.
Another benefit would be that every new command/event implemented will first
needs to have check implemented limiting possible problems with missing
message verification.
Checks are ensuring that message format is correct and don't verify content
of message (which is for command/event handler). Only service id and opcode
sanity is check in common place.
Some addition ideas for future:
- if exit due to IPC would return specific code, there could be 'unit' or
stress tests that would verify IPC behaviour with valid and invalid data
- we could have sort of assert when sending data over ipc to quickly detect
problems in new code
- provide hexdump function for dumping offending ipc message for easier
debugging
Comments are welcome.
Szymon Janc (14):
android: Add HAL IPC commands sanity check
android: Use IPC command sanity checks
android: Add HAL IPC message response sanity checks
android/hal: Use IPC command responses sanity checks
android: Add HAL IPC events sanity check
android/hal: Use IPC notifications sanity checks
android: Remove not needed HAL_MINIMUM_EVENT define
android: Remove not needed buf len from Core service functions
android: Remove not needed buf len from Bluetooth service functions
android: Remove not needed buf len from Hidhost service functions
android: Remove not needed buf len from Socket service functions
android/hal: Remove not neede buf len from bluetooth HAL
android/hal: Remove not neede buf len from hidhost HAL
android/hal: Remove not neede buf len from av HAL
android/Android.mk | 2 +
android/Makefile.am | 6 +-
android/adapter.c | 35 +++---
android/adapter.h | 3 +-
android/hal-av.c | 2 +-
android/hal-bluetooth.c | 35 ++----
android/hal-hidhost.c | 2 +-
android/hal-ipc.c | 32 ++---
android/hal-msg-check.c | 327 ++++++++++++++++++++++++++++++++++++++++++++++++
android/hal-msg.h | 9 +-
android/hal.h | 6 +-
android/hid.c | 62 +++------
android/hid.h | 2 +-
android/ipc.c | 1 +
android/main.c | 30 ++---
android/socket.c | 3 +-
android/socket.h | 3 +-
17 files changed, 416 insertions(+), 144 deletions(-)
create mode 100644 android/hal-msg-check.c
--
1.8.4.2
^ permalink raw reply
* [RFC 01/14] android: Add HAL IPC commands sanity check
From: Szymon Janc @ 2013-11-06 14:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383746970-25906-1-git-send-email-szymon.janc@tieto.com>
This allows to check if command received by daemon is properly
formatted. Only common header values sanity is checked. Parameters
values needs to be verified by appropriate command handlers.
This implements core, bluetooth, sock and hidhost services checks.
---
android/Android.mk | 2 +
android/Makefile.am | 6 +-
android/hal-msg-check.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++++
android/hal-msg.h | 3 +
android/ipc.c | 1 +
5 files changed, 173 insertions(+), 2 deletions(-)
create mode 100644 android/hal-msg-check.c
diff --git a/android/Android.mk b/android/Android.mk
index d76dfaf..c756aaa 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -27,6 +27,7 @@ LOCAL_SRC_FILES := \
ipc.c ipc.h \
a2dp.c \
pan.c \
+ hal-msg-check.c \
../src/log.c \
../src/shared/mgmt.c \
../src/shared/util.c \
@@ -88,6 +89,7 @@ LOCAL_SRC_FILES := \
hal-pan.c \
hal-av.c \
client/textconv.c \
+ hal-msg-check.c \
LOCAL_C_INCLUDES += \
$(call include-path-for, system-core) \
diff --git a/android/Makefile.am b/android/Makefile.am
index 3c51390..b7a7437 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -23,7 +23,8 @@ android_bluetoothd_SOURCES = android/main.c \
android/socket.h android/socket.c \
android/pan.h android/pan.c \
btio/btio.h btio/btio.c \
- src/sdp-client.h src/sdp-client.c
+ src/sdp-client.h src/sdp-client.c \
+ android/hal-msg-check.c
android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
@@ -49,7 +50,8 @@ android_libhal_internal_la_SOURCES = android/hal.h android/hal-bluetooth.c \
android/hardware/hardware.h \
android/cutils/properties.h \
android/hal-log.h \
- android/hal-ipc.h android/hal-ipc.c
+ android/hal-ipc.h android/hal-ipc.c \
+ android/hal-msg-check.c
android_libhal_internal_la_CPPFLAGS = -I$(srcdir)/android
diff --git a/android/hal-msg-check.c b/android/hal-msg-check.c
new file mode 100644
index 0000000..208d8a5
--- /dev/null
+++ b/android/hal-msg-check.c
@@ -0,0 +1,163 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "hal-msg.h"
+
+#define check_no_p(opcode) \
+ case opcode: \
+ return len == 0;
+
+#define check_fix_p(opcode, msg) \
+ case opcode: \
+ return len == sizeof(struct msg);
+
+#define check_var_p(opcode, msg, mp_len_name) \
+ case opcode: \
+ { \
+ const struct msg *mp = (const struct msg *) payload; \
+ return len == (sizeof(*mp) + mp->mp_len_name); \
+ }
+
+#define check_props_p(opcode, msg) \
+ case opcode: \
+ { \
+ const struct msg *mp = (const struct msg *) payload; \
+ const struct hal_property *hp = mp->props; \
+ const void *p = mp->props; \
+ int i; \
+ for (i = 0; i < mp->num_props; i++) { \
+ if ((void *) (p + sizeof(*hp) + hp->len) > \
+ (void *) (payload + len)) \
+ return false; \
+ p += sizeof(*hp) + hp->len; \
+ hp = p; \
+ } \
+ return p == payload + len; \
+ }
+
+static bool check_cmd_core(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_OP_REGISTER_MODULE, hal_cmd_register_module);
+ check_fix_p(HAL_OP_UNREGISTER_MODULE, hal_cmd_unregister_module);
+ default:
+ return false;
+ }
+}
+
+static bool check_cmd_bluetooth(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_no_p(HAL_OP_ENABLE);
+ check_no_p(HAL_OP_DISABLE);
+ check_no_p(HAL_OP_GET_ADAPTER_PROPS);
+ check_fix_p(HAL_OP_GET_ADAPTER_PROP, hal_cmd_get_adapter_prop);
+ check_var_p(HAL_OP_SET_ADAPTER_PROP, hal_cmd_set_adapter_prop, len);
+ check_fix_p(HAL_OP_GET_REMOTE_DEVICE_PROPS,
+ hal_cmd_get_remote_device_props);
+ check_fix_p(HAL_OP_GET_REMOTE_DEVICE_PROP,
+ hal_cmd_get_remote_device_prop);
+ check_var_p(HAL_OP_SET_REMOTE_DEVICE_PROP,
+ hal_cmd_set_remote_device_prop, len);
+ check_fix_p(HAL_OP_GET_REMOTE_SERVICE_REC,
+ hal_cmd_get_remote_service_rec);
+ check_fix_p(HAL_OP_GET_REMOTE_SERVICES, hal_cmd_get_remote_services);
+ check_no_p(HAL_OP_START_DISCOVERY);
+ check_no_p(HAL_OP_CANCEL_DISCOVERY);
+ check_fix_p(HAL_OP_CREATE_BOND, hal_cmd_create_bond);
+ check_fix_p(HAL_OP_REMOVE_BOND, hal_cmd_remove_bond);
+ check_fix_p(HAL_OP_CANCEL_BOND, hal_cmd_cancel_bond)
+ check_fix_p(HAL_OP_PIN_REPLY, hal_cmd_pin_reply);
+ check_fix_p(HAL_OP_SSP_REPLY, hal_cmd_ssp_reply)
+ check_fix_p(HAL_OP_DUT_MODE_CONF, hal_cmd_dut_mode_conf);
+ check_var_p(HAL_OP_DUT_MODE_SEND, hal_cmd_dut_mode_send, len);
+ check_var_p(HAL_OP_LE_TEST_MODE, hal_cmd_le_test_mode, len);
+ default:
+ return false;
+ }
+}
+
+static bool check_cmd_sock(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_OP_SOCK_LISTEN, hal_op_sock_listen);
+ check_fix_p(HAL_OP_SOCK_CONNECT, hal_op_sock_connect);
+ default:
+ return false;
+ }
+}
+
+static bool check_cmd_hidhost(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_OP_HID_CONNECT, hal_cmd_hid_connect);
+ check_fix_p(HAL_OP_HID_DISCONNECT, hal_cmd_hid_disconnect);
+ check_fix_p(HAL_OP_HID_VP, hal_cmd_hid_vp);
+ check_var_p(HAL_OP_HID_SET_INFO, hal_cmd_hid_set_info, descr_len);
+ check_fix_p(HAL_OP_HID_GET_PROTOCOL, hal_cmd_hid_get_protocol);
+ check_fix_p(HAL_OP_HID_SET_PROTOCOL, hal_cmd_hid_set_protocol);
+ check_fix_p(HAL_OP_HID_GET_REPORT, hal_cmd_hid_get_report);
+ check_fix_p(HAL_OP_HID_SET_REPORT, hal_cmd_hid_set_report);
+ check_fix_p(HAL_OP_HID_SEND_DATA, hal_cmd_hid_send_data);
+ default:
+ return false;
+ }
+}
+
+bool hal_cmd_check(const struct hal_hdr *msg, const void *payload, ssize_t len)
+{
+ if (len < (ssize_t) sizeof(*msg))
+ return false;
+
+ if (len != (ssize_t) (sizeof(*msg) + msg->len))
+ return false;
+
+ switch (msg->service_id) {
+ case HAL_SERVICE_ID_CORE:
+ return check_cmd_core(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_BLUETOOTH:
+ return check_cmd_bluetooth(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_SOCK:
+ return check_cmd_sock(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_HIDHOST:
+ return check_cmd_hidhost(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_PAN:
+ case HAL_SERVICE_ID_HANDSFREE:
+ case HAL_SERVICE_ID_A2DP:
+ case HAL_SERVICE_ID_HEALTH:
+ case HAL_SERVICE_ID_AVRCP:
+ case HAL_SERVICE_ID_GATT:
+ /*TODO implement */
+ return false;
+ default:
+ return false;
+ }
+}
diff --git a/android/hal-msg.h b/android/hal-msg.h
index f0cc800..e7587bf 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -486,3 +486,6 @@ struct hal_ev_av_audio_state {
uint8_t state;
uint8_t bdaddr[6];
} __attribute__((packed));
+
+bool hal_cmd_check(const struct hal_hdr *msg, const void *payload,
+ ssize_t len);
diff --git a/android/ipc.c b/android/ipc.c
index e672bf8..57aa56d 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -28,6 +28,7 @@
#include <stddef.h>
#include <errno.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <signal.h>
#include <sys/socket.h>
--
1.8.4.2
^ permalink raw reply related
* [RFC 02/14] android: Use IPC command sanity checks
From: Szymon Janc @ 2013-11-06 14:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383746970-25906-1-git-send-email-szymon.janc@tieto.com>
Make deamon checks received IPC commands for correctness.
---
android/main.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/android/main.c b/android/main.c
index 75004cf..85ea270 100644
--- a/android/main.c
+++ b/android/main.c
@@ -236,13 +236,8 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
goto fail;
}
- if (ret < (ssize_t) sizeof(*msg)) {
- error("HAL command too small, terminating (%zd)", ret);
- goto fail;
- }
-
- if (ret != (ssize_t) (sizeof(*msg) + msg->len)) {
- error("Malformed HAL command (%zd bytes), terminating", ret);
+ if (!hal_cmd_check(msg, msg->payload, ret)) {
+ error("IPC protocol error, terminating");
goto fail;
}
--
1.8.4.2
^ permalink raw reply related
* [RFC 03/14] android: Add HAL IPC message response sanity checks
From: Szymon Janc @ 2013-11-06 14:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383746970-25906-1-git-send-email-szymon.janc@tieto.com>
This implements core, bluetooth, sock and hidhost services checks.
---
android/hal-msg-check.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++
android/hal-msg.h | 2 +
2 files changed, 103 insertions(+)
diff --git a/android/hal-msg-check.c b/android/hal-msg-check.c
index 208d8a5..0c719ac 100644
--- a/android/hal-msg-check.c
+++ b/android/hal-msg-check.c
@@ -161,3 +161,104 @@ bool hal_cmd_check(const struct hal_hdr *msg, const void *payload, ssize_t len)
return false;
}
}
+
+static bool check_rsp_core(uint8_t opcode, const void *payload, uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_OP_STATUS, hal_status);
+ check_no_p(HAL_OP_REGISTER_MODULE);
+ check_no_p(HAL_OP_UNREGISTER_MODULE);
+ default:
+ return false;
+ }
+}
+
+static bool check_rsp_bluetooth(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_OP_STATUS, hal_status);
+ check_no_p(HAL_OP_ENABLE);
+ check_no_p(HAL_OP_DISABLE);
+ check_no_p(HAL_OP_GET_ADAPTER_PROPS);
+ check_no_p(HAL_OP_GET_ADAPTER_PROP);
+ check_no_p(HAL_OP_SET_ADAPTER_PROP);
+ check_no_p(HAL_OP_GET_REMOTE_DEVICE_PROPS);
+ check_no_p(HAL_OP_GET_REMOTE_DEVICE_PROP);
+ check_no_p(HAL_OP_SET_REMOTE_DEVICE_PROP);
+ check_no_p(HAL_OP_GET_REMOTE_SERVICE_REC);
+ check_no_p(HAL_OP_GET_REMOTE_SERVICES);
+ check_no_p(HAL_OP_START_DISCOVERY);
+ check_no_p(HAL_OP_CANCEL_DISCOVERY);
+ check_no_p(HAL_OP_CREATE_BOND);
+ check_no_p(HAL_OP_REMOVE_BOND);
+ check_no_p(HAL_OP_CANCEL_BOND)
+ check_no_p(HAL_OP_PIN_REPLY);
+ check_no_p(HAL_OP_SSP_REPLY)
+ check_no_p(HAL_OP_DUT_MODE_CONF);
+ check_no_p(HAL_OP_DUT_MODE_SEND);
+ check_no_p(HAL_OP_LE_TEST_MODE);
+ default:
+ return false;
+ }
+}
+
+static bool check_rsp_sock(uint8_t opcode, const void *payload, uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_OP_STATUS, hal_status);
+ check_no_p(HAL_OP_SOCK_LISTEN);
+ check_no_p(HAL_OP_SOCK_CONNECT);
+ default:
+ return false;
+ }
+}
+
+static bool check_rsp_hidhost(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_OP_STATUS, hal_status);
+ check_no_p(HAL_OP_HID_CONNECT);
+ check_no_p(HAL_OP_HID_DISCONNECT);
+ check_no_p(HAL_OP_HID_VP);
+ check_no_p(HAL_OP_HID_SET_INFO);
+ check_no_p(HAL_OP_HID_GET_PROTOCOL);
+ check_no_p(HAL_OP_HID_SET_PROTOCOL);
+ check_no_p(HAL_OP_HID_GET_REPORT);
+ check_no_p(HAL_OP_HID_SET_REPORT);
+ check_no_p(HAL_OP_HID_SEND_DATA);
+ default:
+ return false;
+ }
+}
+
+bool hal_rsp_check(const struct hal_hdr *msg, const void *payload,
+ ssize_t len)
+{
+ if (len < (ssize_t) sizeof(*msg))
+ return false;
+
+ if (len != (ssize_t) (sizeof(*msg) + msg->len))
+ return false;
+
+ switch (msg->service_id) {
+ case HAL_SERVICE_ID_CORE:
+ return check_rsp_core(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_BLUETOOTH:
+ return check_rsp_bluetooth(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_SOCK:
+ return check_rsp_sock(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_HIDHOST:
+ return check_rsp_hidhost(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_PAN:
+ case HAL_SERVICE_ID_HANDSFREE:
+ case HAL_SERVICE_ID_A2DP:
+ case HAL_SERVICE_ID_HEALTH:
+ case HAL_SERVICE_ID_AVRCP:
+ case HAL_SERVICE_ID_GATT:
+ return true;
+ default:
+ return false;
+ }
+}
diff --git a/android/hal-msg.h b/android/hal-msg.h
index e7587bf..2d67ccf 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -489,3 +489,5 @@ struct hal_ev_av_audio_state {
bool hal_cmd_check(const struct hal_hdr *msg, const void *payload,
ssize_t len);
+bool hal_rsp_check(const struct hal_hdr *msg, const void *payload,
+ ssize_t len);
--
1.8.4.2
^ 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