* [PATCHv3 2/2] android/hal: Add UUID debug print in socket HAL
From: Andrei Emeltchenko @ 2013-11-06 15:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383750643-1139-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..1d198ac 100644
--- a/android/hal-sock.c
+++ b/android/hal-sock.c
@@ -25,6 +25,8 @@
#include "hal-msg.h"
#include "hal.h"
+#include "hal-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
* [PATCHv3 1/2] android: Create debug hal-utils helpers
From: Andrei Emeltchenko @ 2013-11-06 15:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <903E7C5D-33E0-4EDB-BD6D-02B183278514@holtmann.org>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Create hal-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/hal-utils.c | 58 +++++++++++++++++++++++++++++++++++++++++++++
android/hal-utils.h | 26 ++++++++++++++++++++
7 files changed, 91 insertions(+), 43 deletions(-)
create mode 100644 android/hal-utils.c
create mode 100644 android/hal-utils.h
diff --git a/android/Android.mk b/android/Android.mk
index d76dfaf..32bb591 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 \
+ hal-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 \
+ hal-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 8619641..e4adf6c 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/hal-utils.h android/hal-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..bb53952 100644
--- a/android/client/if-gatt.c
+++ b/android/client/if-gatt.c
@@ -17,6 +17,7 @@
#include <hardware/bluetooth.h>
+#include "../hal-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..469b2c3 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -19,6 +19,8 @@
#include <stdio.h>
#include <hardware/bluetooth.h>
+#include "../hal-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/hal-utils.c b/android/hal-utils.c
new file mode 100644
index 0000000..84cfad1
--- /dev/null
+++ b/android/hal-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 "hal-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/hal-utils.h b/android/hal-utils.h
new file mode 100644
index 0000000..d40b430
--- /dev/null
+++ b/android/hal-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
* [PATCH 2/2] android: Add set/get for discovery timeout
From: Lukasz Rymanowski @ 2013-11-06 15:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
In-Reply-To: <1383750530-18815-1-git-send-email-lukasz.rymanowski@tieto.com>
Android handles discoverable timeout in Settings app, however still
expects BT stack to maintain this value so we should do it as well.
Otherwise we will get some unexpected behaviour.
For now we keep discovery_timeout only during runtime, but we need to move
it to some local storage once we will have it.
Note: That since Android Settings up handles timer there is no reason to
use discovery timer we have in kernel.
---
android/adapter.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 1d462c8..d97f34b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -47,6 +47,8 @@
/* Default to DisplayYesNo */
#define DEFAULT_IO_CAPABILITY 0x01
+/* Default discoverable timeout 120sec as in Android */
+#define DEFAULT_DISCOVERABLE_TIMEOUT 120
static GIOChannel *notification_io = NULL;
/* This list contains addresses which are asked for records */
@@ -67,6 +69,7 @@ struct bt_adapter {
uint32_t current_settings;
bool discovering;
+ uint32_t discoverable_timeout;
};
struct browse_req {
@@ -1101,6 +1104,17 @@ static uint8_t set_adapter_name(uint8_t *name, uint16_t len)
return HAL_STATUS_FAILED;
}
+static uint8_t set_discoverable_timeout(uint8_t *timeout)
+{
+ /* Android handles discoverable timeout in Settings app.
+ * There is no need to use kernel feature for that.
+ * Just need to store this value here */
+
+ /* TODO: This should be in some storage */
+ memcpy(&adapter->discoverable_timeout, timeout, sizeof(uint32_t));
+
+ return HAL_STATUS_SUCCESS;
+}
static void read_info_complete(uint8_t status, uint16_t length, const void *param,
void *user_data)
{
@@ -1169,6 +1183,8 @@ void bt_adapter_init(uint16_t index, struct mgmt *mgmt, bt_adapter_ready cb)
adapter->index = index;
adapter->discovering = false;
adapter->ready = cb;
+ /* TODO: Read it from some storage */
+ adapter->discoverable_timeout = DEFAULT_DISCOVERABLE_TIMEOUT;
if (mgmt_send(mgmt, MGMT_OP_READ_INFO, index, 0, NULL,
read_info_complete, NULL, NULL) > 0)
@@ -1286,11 +1302,26 @@ static bool get_devices(void)
static bool get_discoverable_timeout(void)
{
- DBG("Not implemented");
+ struct hal_ev_adapter_props_changed *ev;
+ int len;
- /* TODO: Add implementation */
+ len = sizeof(*ev) + sizeof(struct hal_property) + sizeof(uint32_t);
- return false;
+ ev = g_malloc(len);
+
+ ev->num_props = 1;
+ ev->status = HAL_STATUS_SUCCESS;
+
+ ev->props[0].type = HAL_PROP_ADAPTER_DISC_TIMEOUT;
+ ev->props[0].len = sizeof(uint32_t);
+ memcpy(&ev->props[0].val, &adapter->discoverable_timeout, sizeof(uint32_t));
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+ g_free(ev);
+
+ return true;
}
static bool get_property(void *buf, uint16_t len)
@@ -1441,6 +1472,7 @@ static uint8_t set_property(void *buf, uint16_t len)
case HAL_PROP_ADAPTER_NAME:
return set_adapter_name(cmd->val, cmd->len);
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
+ return set_discoverable_timeout(cmd->val);
default:
DBG("Unhandled property type 0x%x", cmd->type);
return HAL_STATUS_FAILED;
--
1.8.4
^ permalink raw reply related
* [PATCH 1/2] android: Change name for get_disc_timeout
From: Lukasz Rymanowski @ 2013-11-06 15:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
Change name to get_discoverable_timeout. Previous name could be
confusing with disconnection timeout.
---
android/adapter.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index cf5edcd..1d462c8 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1284,7 +1284,7 @@ static bool get_devices(void)
return false;
}
-static bool get_disc_timeout(void)
+static bool get_discoverable_timeout(void)
{
DBG("Not implemented");
@@ -1316,7 +1316,7 @@ static bool get_property(void *buf, uint16_t len)
case HAL_PROP_ADAPTER_BONDED_DEVICES:
return get_devices();
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- return get_disc_timeout();
+ return get_discoverable_timeout();
default:
return false;
}
@@ -1332,7 +1332,7 @@ static void get_properties(void)
get_service();
get_scan_mode();
get_devices();
- get_disc_timeout();
+ get_discoverable_timeout();
}
static bool start_discovery(void)
--
1.8.4
^ permalink raw reply related
* [RFC 14/14] android/hal: Remove not neede buf len from av HAL
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>
Message correctness is verified upon reception and handling functions
can simply make assumption that data in buffer is correct.
---
android/hal-av.c | 2 +-
android/hal-ipc.c | 2 +-
android/hal.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/android/hal-av.c b/android/hal-av.c
index 9e1b3df..3da79c4 100644
--- a/android/hal-av.c
+++ b/android/hal-av.c
@@ -49,7 +49,7 @@ static void handle_audio_state(void *buf)
}
/* will be called from notification thread context */
-void bt_notify_av(uint16_t opcode, void *buf, uint16_t len)
+void bt_notify_av(uint16_t opcode, void *buf)
{
if (!interface_ready())
return;
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 173229a..2de7c2f 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -53,7 +53,7 @@ static void notification_dispatch(struct hal_hdr *msg, int fd)
bt_notify_hh(msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_A2DP:
- bt_notify_av(msg->opcode, msg->payload, msg->len);
+ bt_notify_av(msg->opcode, msg->payload);
break;
default:
DBG("Unhandled notification service=%d opcode=0x%x",
diff --git a/android/hal.h b/android/hal.h
index 9f1ecec..bcd0861 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -30,4 +30,4 @@ void bt_notify_adapter(uint16_t opcode, void *buf);
void bt_thread_associate(void);
void bt_thread_disassociate(void);
void bt_notify_hh(uint16_t opcode, void *buf);
-void bt_notify_av(uint16_t opcode, void *buf, uint16_t len);
+void bt_notify_av(uint16_t opcode, void *buf);
--
1.8.4.2
^ permalink raw reply related
* [RFC 13/14] android/hal: Remove not neede buf len from hidhost HAL
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>
Message correctness is verified upon reception and handling functions
can simply make assumption that data in buffer is correct.
---
android/hal-hidhost.c | 2 +-
android/hal-ipc.c | 2 +-
android/hal.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index f1a2223..a96e122 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -78,7 +78,7 @@ static void handle_get_report(void *buf)
}
/* will be called from notification thread context */
-void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
+void bt_notify_hh(uint16_t opcode, void *buf)
{
if (!interface_ready())
return;
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 7ca9fe4..173229a 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -50,7 +50,7 @@ static void notification_dispatch(struct hal_hdr *msg, int fd)
bt_notify_adapter(msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_HIDHOST:
- bt_notify_hh(msg->opcode, msg->payload, msg->len);
+ bt_notify_hh(msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_A2DP:
bt_notify_av(msg->opcode, msg->payload, msg->len);
diff --git a/android/hal.h b/android/hal.h
index c10a27c..9f1ecec 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -29,5 +29,5 @@ btav_interface_t *bt_get_av_interface(void);
void bt_notify_adapter(uint16_t opcode, void *buf);
void bt_thread_associate(void);
void bt_thread_disassociate(void);
-void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len);
+void bt_notify_hh(uint16_t opcode, void *buf);
void bt_notify_av(uint16_t opcode, void *buf, uint16_t len);
--
1.8.4.2
^ permalink raw reply related
* [RFC 12/14] android/hal: Remove not neede buf len from bluetooth HAL
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>
Message correctness is verified upon reception and handling functions
can simply make assumption that data in buffer is correct.
---
android/hal-bluetooth.c | 35 ++++++++++++-----------------------
android/hal-ipc.c | 2 +-
android/hal.h | 2 +-
3 files changed, 14 insertions(+), 25 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 88c7b99..67e6eea 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -48,17 +48,11 @@ static void handle_adapter_state_changed(void *buf)
static void adapter_props_to_hal(bt_property_t *send_props,
struct hal_property *hal_prop,
- uint8_t num_props, void *buff_end)
+ uint8_t num_props)
{
- void *p = hal_prop;
uint8_t i;
for (i = 0; i < num_props; i++) {
- if (p + sizeof(*hal_prop) + hal_prop->len > buff_end) {
- error("invalid adapter properties event, aborting");
- exit(EXIT_FAILURE);
- }
-
send_props[i].type = hal_prop->type;
switch (hal_prop->type) {
@@ -99,17 +93,12 @@ static void adapter_hal_props_cleanup(bt_property_t *props, uint8_t num)
static void device_props_to_hal(bt_property_t *send_props,
struct hal_property *hal_prop,
- uint8_t num_props, void *buff_end)
+ uint8_t num_props)
{
void *p = hal_prop;
uint8_t i;
for (i = 0; i < num_props; i++) {
- if (p + sizeof(*hal_prop) + hal_prop->len > buff_end) {
- error("invalid adapter properties event, aborting");
- exit(EXIT_FAILURE);
- }
-
send_props[i].type = hal_prop->type;
switch (hal_prop->type) {
@@ -148,7 +137,7 @@ static void device_hal_props_cleanup(bt_property_t *props, uint8_t num)
}
}
-static void handle_adapter_props_changed(void *buf, uint16_t len)
+static void handle_adapter_props_changed(void *buf)
{
struct hal_ev_adapter_props_changed *ev = buf;
bt_property_t props[ev->num_props];
@@ -158,7 +147,7 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
if (!bt_hal_cbacks->adapter_properties_cb)
return;
- adapter_props_to_hal(props, ev->props, ev->num_props, buf + len);
+ adapter_props_to_hal(props, ev->props, ev->num_props);
bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
@@ -232,7 +221,7 @@ static void handle_discovery_state_changed(void *buf)
bt_hal_cbacks->discovery_state_changed_cb(ev->state);
}
-static void handle_device_found(void *buf, uint16_t len)
+static void handle_device_found(void *buf)
{
struct hal_ev_device_found *ev = buf;
bt_property_t props[ev->num_props];
@@ -242,14 +231,14 @@ static void handle_device_found(void *buf, uint16_t len)
if (!bt_hal_cbacks->device_found_cb)
return;
- device_props_to_hal(props, ev->props, ev->num_props, buf + len);
+ device_props_to_hal(props, ev->props, ev->num_props);
bt_hal_cbacks->device_found_cb(ev->num_props, props);
device_hal_props_cleanup(props, ev->num_props);
}
-static void handle_device_state_changed(void *buf, uint16_t len)
+static void handle_device_state_changed(void *buf)
{
struct hal_ev_remote_device_props *ev = buf;
bt_property_t props[ev->num_props];
@@ -259,7 +248,7 @@ static void handle_device_state_changed(void *buf, uint16_t len)
if (!bt_hal_cbacks->remote_device_properties_cb)
return;
- device_props_to_hal(props, ev->props, ev->num_props, buf + len);
+ device_props_to_hal(props, ev->props, ev->num_props);
bt_hal_cbacks->remote_device_properties_cb(ev->status,
(bt_bdaddr_t *)ev->bdaddr,
@@ -281,7 +270,7 @@ static void handle_acl_state_changed(void *buf)
}
/* will be called from notification thread context */
-void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
+void bt_notify_adapter(uint16_t opcode, void *buf)
{
if (!interface_ready())
return;
@@ -293,16 +282,16 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
handle_adapter_state_changed(buf);
break;
case HAL_EV_ADAPTER_PROPS_CHANGED:
- handle_adapter_props_changed(buf, len);
+ handle_adapter_props_changed(buf);
break;
case HAL_EV_DISCOVERY_STATE_CHANGED:
handle_discovery_state_changed(buf);
break;
case HAL_EV_DEVICE_FOUND:
- handle_device_found(buf, len);
+ handle_device_found(buf);
break;
case HAL_EV_REMOTE_DEVICE_PROPS:
- handle_device_state_changed(buf, len);
+ handle_device_state_changed(buf);
break;
case HAL_EV_BOND_STATE_CHANGED:
handle_bond_state_change(buf);
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 13392c2..7ca9fe4 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -47,7 +47,7 @@ static void notification_dispatch(struct hal_hdr *msg, int fd)
{
switch (msg->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
- bt_notify_adapter(msg->opcode, msg->payload, msg->len);
+ bt_notify_adapter(msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_HIDHOST:
bt_notify_hh(msg->opcode, msg->payload, msg->len);
diff --git a/android/hal.h b/android/hal.h
index 5d6a93e..c10a27c 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -26,7 +26,7 @@ bthh_interface_t *bt_get_hidhost_interface(void);
btpan_interface_t *bt_get_pan_interface(void);
btav_interface_t *bt_get_av_interface(void);
-void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len);
+void bt_notify_adapter(uint16_t opcode, void *buf);
void bt_thread_associate(void);
void bt_thread_disassociate(void);
void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len);
--
1.8.4.2
^ permalink raw reply related
* [RFC 11/14] android: Remove not needed buf len from Socket service functions
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>
Message correctness is verified upon reception and handling functions
can simply make assumption that data in buffer is correct.
---
android/main.c | 3 +--
android/socket.c | 3 +--
android/socket.h | 3 +--
3 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/android/main.c b/android/main.c
index 08bba4e..9cc3e1d 100644
--- a/android/main.c
+++ b/android/main.c
@@ -255,8 +255,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
bt_hid_handle_cmd(hal_cmd_io, msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_SOCK:
- bt_sock_handle_cmd(hal_cmd_io, msg->opcode, msg->payload,
- msg->len);
+ bt_sock_handle_cmd(hal_cmd_io, msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_A2DP:
bt_a2dp_handle_cmd(hal_cmd_io, msg->opcode, msg->payload,
diff --git a/android/socket.c b/android/socket.c
index e32be46..b9c556f 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -50,8 +50,7 @@ static int handle_connect(void *buf)
return -1;
}
-void bt_sock_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
- uint16_t len)
+void bt_sock_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf)
{
int fd;
diff --git a/android/socket.h b/android/socket.h
index 2b3b940..69cfc58 100644
--- a/android/socket.h
+++ b/android/socket.h
@@ -21,8 +21,7 @@
*
*/
-void bt_sock_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
- uint16_t len);
+void bt_sock_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf);
bool bt_socket_register(GIOChannel *io, const bdaddr_t *addr);
void bt_socket_unregister(void);
--
1.8.4.2
^ permalink raw reply related
* [RFC 10/14] android: Remove not needed buf len from Hidhost service functions
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>
Message correctness is verified upon reception and handling functions
can simply make assumption that data in buffer is correct.
---
android/hid.c | 62 ++++++++++++++++++----------------------------------------
android/hid.h | 2 +-
android/main.c | 3 +--
3 files changed, 21 insertions(+), 46 deletions(-)
diff --git a/android/hid.c b/android/hid.c
index c38c4c1..968dc29 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -667,7 +667,7 @@ fail:
hid_device_free(dev);
}
-static uint8_t bt_hid_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
+static uint8_t bt_hid_connect(struct hal_cmd_hid_connect *cmd)
{
struct hid_device *dev;
char addr[18];
@@ -678,9 +678,6 @@ static uint8_t bt_hid_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
@@ -708,8 +705,7 @@ static uint8_t bt_hid_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
return HAL_STATUS_SUCCESS;
}
-static uint8_t bt_hid_disconnect(struct hal_cmd_hid_disconnect *cmd,
- uint16_t len)
+static uint8_t bt_hid_disconnect(struct hal_cmd_hid_disconnect *cmd)
{
struct hid_device *dev;
GSList *l;
@@ -717,9 +713,6 @@ static uint8_t bt_hid_disconnect(struct hal_cmd_hid_disconnect *cmd,
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
@@ -740,22 +733,21 @@ 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_vp *cmd)
{
DBG("Not Implemented");
return HAL_STATUS_FAILED;
}
-static uint8_t bt_hid_info(struct hal_cmd_hid_set_info *cmd, uint16_t len)
+static uint8_t bt_hid_info(struct hal_cmd_hid_set_info *cmd)
{
DBG("Not Implemented");
return HAL_STATUS_FAILED;
}
-static uint8_t bt_hid_get_protocol(struct hal_cmd_hid_get_protocol *cmd,
- uint16_t len)
+static uint8_t bt_hid_get_protocol(struct hal_cmd_hid_get_protocol *cmd)
{
struct hid_device *dev;
GSList *l;
@@ -765,9 +757,6 @@ static uint8_t bt_hid_get_protocol(struct hal_cmd_hid_get_protocol *cmd,
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
@@ -791,8 +780,7 @@ static uint8_t bt_hid_get_protocol(struct hal_cmd_hid_get_protocol *cmd,
return HAL_STATUS_SUCCESS;
}
-static uint8_t bt_hid_set_protocol(struct hal_cmd_hid_set_protocol *cmd,
- uint16_t len)
+static uint8_t bt_hid_set_protocol(struct hal_cmd_hid_set_protocol *cmd)
{
struct hid_device *dev;
GSList *l;
@@ -802,9 +790,6 @@ static uint8_t bt_hid_set_protocol(struct hal_cmd_hid_set_protocol *cmd,
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
@@ -828,8 +813,7 @@ static uint8_t bt_hid_set_protocol(struct hal_cmd_hid_set_protocol *cmd,
return HAL_STATUS_SUCCESS;
}
-static uint8_t bt_hid_get_report(struct hal_cmd_hid_get_report *cmd,
- uint16_t len)
+static uint8_t bt_hid_get_report(struct hal_cmd_hid_get_report *cmd)
{
struct hid_device *dev;
GSList *l;
@@ -840,9 +824,6 @@ static uint8_t bt_hid_get_report(struct hal_cmd_hid_get_report *cmd,
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
@@ -876,8 +857,7 @@ static uint8_t bt_hid_get_report(struct hal_cmd_hid_get_report *cmd,
return HAL_STATUS_SUCCESS;
}
-static uint8_t bt_hid_set_report(struct hal_cmd_hid_set_report *cmd,
- uint16_t len)
+static uint8_t bt_hid_set_report(struct hal_cmd_hid_set_report *cmd)
{
struct hid_device *dev;
GSList *l;
@@ -888,9 +868,6 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hid_set_report *cmd,
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
@@ -919,45 +896,44 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hid_set_report *cmd,
return HAL_STATUS_SUCCESS;
}
-static uint8_t bt_hid_send_data(struct hal_cmd_hid_send_data *cmd,
- uint16_t len)
+static uint8_t bt_hid_send_data(struct hal_cmd_hid_send_data *cmd)
{
DBG("Not Implemented");
return HAL_STATUS_FAILED;
}
-void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
+void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf)
{
uint8_t status = HAL_STATUS_FAILED;
switch (opcode) {
case HAL_OP_HID_CONNECT:
- status = bt_hid_connect(buf, len);
+ status = bt_hid_connect(buf);
break;
case HAL_OP_HID_DISCONNECT:
- status = bt_hid_disconnect(buf, len);
+ status = bt_hid_disconnect(buf);
break;
case HAL_OP_HID_VP:
- status = bt_hid_virtual_unplug(buf, len);
+ status = bt_hid_virtual_unplug(buf);
break;
case HAL_OP_HID_SET_INFO:
- status = bt_hid_info(buf, len);
+ status = bt_hid_info(buf);
break;
case HAL_OP_HID_GET_PROTOCOL:
- status = bt_hid_get_protocol(buf, len);
+ status = bt_hid_get_protocol(buf);
break;
case HAL_OP_HID_SET_PROTOCOL:
- status = bt_hid_set_protocol(buf, len);
+ status = bt_hid_set_protocol(buf);
break;
case HAL_OP_HID_GET_REPORT:
- status = bt_hid_get_report(buf, len);
+ status = bt_hid_get_report(buf);
break;
case HAL_OP_HID_SET_REPORT:
- status = bt_hid_set_report(buf, len);
+ status = bt_hid_set_report(buf);
break;
case HAL_OP_HID_SEND_DATA:
- status = bt_hid_send_data(buf, len);
+ status = bt_hid_send_data(buf);
break;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
diff --git a/android/hid.h b/android/hid.h
index 674b35a..b92f4f1 100644
--- a/android/hid.h
+++ b/android/hid.h
@@ -21,7 +21,7 @@
*
*/
-void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len);
+void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf);
bool bt_hid_register(GIOChannel *io, const bdaddr_t *addr);
void bt_hid_unregister(void);
diff --git a/android/main.c b/android/main.c
index d309068..08bba4e 100644
--- a/android/main.c
+++ b/android/main.c
@@ -252,8 +252,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
bt_adapter_handle_cmd(hal_cmd_io, msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_HIDHOST:
- bt_hid_handle_cmd(hal_cmd_io, msg->opcode, msg->payload,
- msg->len);
+ bt_hid_handle_cmd(hal_cmd_io, msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_SOCK:
bt_sock_handle_cmd(hal_cmd_io, msg->opcode, msg->payload,
--
1.8.4.2
^ permalink raw reply related
* [RFC 09/14] android: Remove not needed buf len from Bluetooth service functions
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>
Message correctness is verified upon reception and handling functions
can simply make assumption that data in buffer is correct.
---
android/adapter.c | 35 +++++++++++++++++------------------
android/adapter.h | 3 +--
android/main.c | 3 +--
3 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index cf5edcd..5b099fe 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1293,7 +1293,7 @@ static bool get_disc_timeout(void)
return false;
}
-static bool get_property(void *buf, uint16_t len)
+static bool get_property(void *buf)
{
struct hal_cmd_get_adapter_prop *cmd = buf;
@@ -1431,7 +1431,7 @@ done:
return HAL_STATUS_DONE;
}
-static uint8_t set_property(void *buf, uint16_t len)
+static uint8_t set_property(void *buf)
{
struct hal_cmd_set_adapter_prop *cmd = buf;
@@ -1485,7 +1485,7 @@ static void pair_device_complete(uint8_t status, uint16_t length,
HAL_BOND_STATE_NONE);
}
-static bool create_bond(void *buf, uint16_t len)
+static bool create_bond(void *buf)
{
struct hal_cmd_create_bond *cmd = buf;
struct mgmt_cp_pair_device cp;
@@ -1505,7 +1505,7 @@ static bool create_bond(void *buf, uint16_t len)
return true;
}
-static bool cancel_bond(void *buf, uint16_t len)
+static bool cancel_bond(void *buf)
{
struct hal_cmd_cancel_bond *cmd = buf;
struct mgmt_addr_info cp;
@@ -1532,7 +1532,7 @@ static void unpair_device_complete(uint8_t status, uint16_t length,
HAL_BOND_STATE_NONE);
}
-static bool remove_bond(void *buf, uint16_t len)
+static bool remove_bond(void *buf)
{
struct hal_cmd_remove_bond *cmd = buf;
struct mgmt_cp_unpair_device cp;
@@ -1546,7 +1546,7 @@ static bool remove_bond(void *buf, uint16_t len)
unpair_device_complete, NULL, NULL) > 0;
}
-static uint8_t pin_reply(void *buf, uint16_t len)
+static uint8_t pin_reply(void *buf)
{
struct hal_cmd_pin_reply *cmd = buf;
bdaddr_t bdaddr;
@@ -1643,7 +1643,7 @@ static uint8_t user_passkey_reply(const bdaddr_t *bdaddr, bool accept,
return HAL_STATUS_SUCCESS;
}
-static uint8_t ssp_reply(void *buf, uint16_t len)
+static uint8_t ssp_reply(void *buf)
{
struct hal_cmd_ssp_reply *cmd = buf;
uint8_t status;
@@ -1677,7 +1677,7 @@ static uint8_t ssp_reply(void *buf, uint16_t len)
return status;
}
-static uint8_t get_remote_services(void *buf, uint16_t len)
+static uint8_t get_remote_services(void *buf)
{
struct hal_cmd_get_remote_services *cmd = buf;
bdaddr_t addr;
@@ -1687,8 +1687,7 @@ static uint8_t get_remote_services(void *buf, uint16_t len)
return browse_remote_sdp(&addr);
}
-void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
- uint16_t len)
+void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf)
{
uint8_t status = HAL_STATUS_FAILED;
@@ -1722,39 +1721,39 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
break;
case HAL_OP_GET_ADAPTER_PROP:
- if (!get_property(buf, len))
+ if (!get_property(buf))
goto error;
break;
case HAL_OP_SET_ADAPTER_PROP:
- status = set_property(buf, len);
+ status = set_property(buf);
if (status != HAL_STATUS_SUCCESS && status != HAL_STATUS_DONE)
goto error;
break;
case HAL_OP_CREATE_BOND:
- if (!create_bond(buf, len))
+ if (!create_bond(buf))
goto error;
break;
case HAL_OP_CANCEL_BOND:
- if (!cancel_bond(buf, len))
+ if (!cancel_bond(buf))
goto error;
break;
case HAL_OP_REMOVE_BOND:
- if (!remove_bond(buf, len))
+ if (!remove_bond(buf))
goto error;
break;
case HAL_OP_PIN_REPLY:
- status = pin_reply(buf, len);
+ status = pin_reply(buf);
if (status != HAL_STATUS_SUCCESS)
goto error;
break;
case HAL_OP_SSP_REPLY:
- status = ssp_reply(buf, len);
+ status = ssp_reply(buf);
if (status != HAL_STATUS_SUCCESS)
goto error;
break;
@@ -1789,7 +1788,7 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
break;
case HAL_OP_GET_REMOTE_SERVICES:
- status = get_remote_services(buf, len);
+ status = get_remote_services(buf);
if (status != HAL_STATUS_SUCCESS)
goto error;
break;
diff --git a/android/adapter.h b/android/adapter.h
index 2afc67a..d304575 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -33,8 +33,7 @@ typedef void (*bt_adapter_ready)(int err);
void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
bt_adapter_ready cb);
-void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
- uint16_t len);
+void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf);
const bdaddr_t *bt_adapter_get_address(void);
diff --git a/android/main.c b/android/main.c
index d7e77a2..d309068 100644
--- a/android/main.c
+++ b/android/main.c
@@ -249,8 +249,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
handle_service_core(msg->opcode, buf + sizeof(*msg));
break;
case HAL_SERVICE_ID_BLUETOOTH:
- bt_adapter_handle_cmd(hal_cmd_io, msg->opcode, msg->payload,
- msg->len);
+ bt_adapter_handle_cmd(hal_cmd_io, msg->opcode, msg->payload);
break;
case HAL_SERVICE_ID_HIDHOST:
bt_hid_handle_cmd(hal_cmd_io, msg->opcode, msg->payload,
--
1.8.4.2
^ permalink raw reply related
* [RFC 08/14] android: Remove not needed buf len from Core service functions
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>
Message correctness is verified upon reception and handling functions
can simply make assumption that data in buffer is correct.
---
android/main.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/android/main.c b/android/main.c
index 85ea270..d7e77a2 100644
--- a/android/main.c
+++ b/android/main.c
@@ -76,7 +76,7 @@ static GIOChannel *hal_notif_io = NULL;
static bool services[HAL_SERVICE_ID_MAX + 1] = { false };
-static void service_register(void *buf, uint16_t len)
+static void service_register(void *buf)
{
struct hal_cmd_register_module *m = buf;
const bdaddr_t *adapter_bdaddr = bt_adapter_get_address();
@@ -126,7 +126,7 @@ failed:
ipc_send_rsp(hal_cmd_io, HAL_SERVICE_ID_CORE, HAL_STATUS_FAILED);
}
-static void service_unregister(void *buf, uint16_t len)
+static void service_unregister(void *buf)
{
struct hal_cmd_unregister_module *m = buf;
@@ -167,14 +167,14 @@ failed:
ipc_send_rsp(hal_cmd_io, HAL_SERVICE_ID_CORE, HAL_STATUS_FAILED);
}
-static void handle_service_core(uint8_t opcode, void *buf, uint16_t len)
+static void handle_service_core(uint8_t opcode, void *buf)
{
switch (opcode) {
case HAL_OP_REGISTER_MODULE:
- service_register(buf, len);
+ service_register(buf);
break;
case HAL_OP_UNREGISTER_MODULE:
- service_unregister(buf, len);
+ service_unregister(buf);
break;
default:
ipc_send_rsp(hal_cmd_io, HAL_SERVICE_ID_CORE,
@@ -246,7 +246,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
switch (msg->service_id) {
case HAL_SERVICE_ID_CORE:
- handle_service_core(msg->opcode, buf + sizeof(*msg), msg->len);
+ handle_service_core(msg->opcode, buf + sizeof(*msg));
break;
case HAL_SERVICE_ID_BLUETOOTH:
bt_adapter_handle_cmd(hal_cmd_io, msg->opcode, msg->payload,
--
1.8.4.2
^ permalink raw reply related
* [RFC 07/14] android: Remove not needed HAL_MINIMUM_EVENT define
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 is no longer needed as correct events ID are verified by
hal_notif_check function.
---
android/hal-msg.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 9f36c61..0d7137a 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -32,8 +32,6 @@ struct hal_hdr {
uint8_t payload[0];
} __attribute__((packed));
-#define HAL_MINIMUM_EVENT 0x81
-
#define HAL_SERVICE_ID_CORE 0
#define HAL_SERVICE_ID_BLUETOOTH 1
#define HAL_SERVICE_ID_SOCK 2
--
1.8.4.2
^ permalink raw reply related
* [RFC 06/14] android/hal: Use IPC notifications 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 HAL library checks received IPC notifications for correctness.
---
android/hal-ipc.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 293be87..13392c2 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -105,21 +105,8 @@ static void *notification_handler(void *data)
exit(EXIT_FAILURE);
}
- if (ret < (ssize_t) sizeof(*ev)) {
- error("Too small notification (%zd bytes), aborting",
- ret);
- exit(EXIT_FAILURE);
- }
-
- if (ev->opcode < HAL_MINIMUM_EVENT) {
- error("Invalid notification (0x%x), aborting",
- ev->opcode);
- exit(EXIT_FAILURE);
- }
-
- if (ret != (ssize_t) (sizeof(*ev) + ev->len)) {
- error("Malformed notification(%zd bytes), aborting",
- ret);
+ if (!hal_notif_check(ev, ev->payload, ret)) {
+ error("IPC protocol error in notification, aborting");
exit(EXIT_FAILURE);
}
--
1.8.4.2
^ permalink raw reply related
* [RFC 05/14] android: Add HAL IPC events 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 implements core, bluetooth, sock and hidhost services checks.
---
android/hal-msg-check.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
android/hal-msg.h | 2 ++
2 files changed, 65 insertions(+)
diff --git a/android/hal-msg-check.c b/android/hal-msg-check.c
index 0c719ac..8fe1a4f 100644
--- a/android/hal-msg-check.c
+++ b/android/hal-msg-check.c
@@ -262,3 +262,66 @@ bool hal_rsp_check(const struct hal_hdr *msg, const void *payload,
return false;
}
}
+
+static bool check_notif_bluetooth(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_EV_ADAPTER_STATE_CHANGED,
+ hal_ev_adapter_state_changed);
+ check_props_p(HAL_EV_ADAPTER_PROPS_CHANGED,
+ hal_ev_adapter_props_changed);
+ check_props_p(HAL_EV_REMOTE_DEVICE_PROPS, hal_ev_remote_device_props);
+ check_props_p(HAL_EV_DEVICE_FOUND, hal_ev_device_found);
+ check_fix_p(HAL_EV_DISCOVERY_STATE_CHANGED,
+ hal_ev_discovery_state_changed);
+ check_fix_p(HAL_EV_PIN_REQUEST, hal_ev_pin_request);
+ check_fix_p(HAL_EV_SSP_REQUEST, hal_ev_ssp_request);
+ check_fix_p(HAL_EV_BOND_STATE_CHANGED, hal_ev_bond_state_changed);
+ check_fix_p(HAL_EV_ACL_STATE_CHANGED, hal_ev_acl_state_changed);
+ check_var_p(HAL_EV_DUT_MODE_RECEIVE, hal_ev_dut_mode_receive, len);
+ check_fix_p(HAL_EV_LE_TEST_MODE, hal_ev_le_test_mode);
+ default:
+ return false;
+ }
+}
+
+static bool check_notif_hidhost(uint8_t opcode, const void *payload,
+ uint16_t len)
+{
+ switch (opcode) {
+ check_fix_p(HAL_EV_HID_CONN_STATE, hal_ev_hid_conn_state);
+ check_fix_p(HAL_EV_HID_INFO, hal_ev_hid_info);
+ default:
+ return false;
+ }
+}
+
+bool hal_notif_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_BLUETOOTH:
+ return check_notif_bluetooth(msg->opcode, payload, msg->len);
+ case HAL_SERVICE_ID_HIDHOST:
+ return check_notif_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;
+ case HAL_SERVICE_ID_CORE:
+ case HAL_SERVICE_ID_SOCK:
+ default:
+ return false;
+ }
+}
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 2d67ccf..9f36c61 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -491,3 +491,5 @@ 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);
+bool hal_notif_check(const struct hal_hdr *msg, const void *payload,
+ ssize_t len);
--
1.8.4.2
^ permalink raw reply related
* [RFC 04/14] android/hal: Use IPC command responses 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 HAL library checks received IPC responses for correctness.
---
android/hal-ipc.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 14be69b..293be87 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -340,8 +340,8 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
pthread_mutex_unlock(&cmd_sk_mutex);
- if (ret < (ssize_t) sizeof(cmd)) {
- error("Too small response received(%zd bytes), aborting", ret);
+ if (!hal_rsp_check(&cmd, &rsp, ret)) {
+ error("IPC protocol error in command response, aborting");
exit(EXIT_FAILURE);
}
@@ -351,11 +351,6 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
exit(EXIT_FAILURE);
}
- if (ret != (ssize_t) (sizeof(cmd) + cmd.len)) {
- error("Malformed response received(%zd bytes), aborting", ret);
- exit(EXIT_FAILURE);
- }
-
if (cmd.opcode != opcode && cmd.opcode != HAL_OP_STATUS) {
error("Invalid opcode received (%u vs %u), aborting",
cmd.opcode, opcode);
--
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
* [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 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 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
* [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
* [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
* [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
* [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 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
* 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
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