* [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names
@ 2013-12-10 15:06 Szymon Janc
2013-12-10 15:06 ` [PATCH v2 2/8] android/bluetooth: Use single list for device caching Szymon Janc
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This match adapter properties handling functions with properties names.
Will make code easier to understand and avoid clashes with remote
device properties functions.
---
android/bluetooth.c | 72 ++++++++++++++++++++++++++---------------------------
1 file changed, 36 insertions(+), 36 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index a3145cb..f8df473 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1128,7 +1128,7 @@ static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128)
ntoh128(&uuid128.value.uuid128, u128);
}
-static uint8_t get_uuids(void)
+static uint8_t get_adapter_uuids(void)
{
struct hal_ev_adapter_props_changed *ev;
GSList *list = adapter.uuids;
@@ -1178,7 +1178,7 @@ static void remove_uuid_complete(uint8_t status, uint16_t length,
mgmt_dev_class_changed_event(adapter.index, length, param, NULL);
- get_uuids();
+ get_adapter_uuids();
}
static void remove_uuid(uint16_t uuid)
@@ -1204,7 +1204,7 @@ static void add_uuid_complete(uint8_t status, uint16_t length,
mgmt_dev_class_changed_event(adapter.index, length, param, NULL);
- get_uuids();
+ get_adapter_uuids();
}
static void add_uuid(uint8_t svc_hint, uint16_t uuid)
@@ -1373,7 +1373,7 @@ static uint8_t set_adapter_name(const uint8_t *name, uint16_t len)
return HAL_STATUS_FAILED;
}
-static uint8_t set_discoverable_timeout(const void *buf, uint16_t len)
+static uint8_t set_adapter_discoverable_timeout(const void *buf, uint16_t len)
{
const uint32_t *timeout = buf;
@@ -1686,7 +1686,7 @@ static bool set_discoverable(uint8_t mode, uint16_t timeout)
return false;
}
-static uint8_t get_address(void)
+static uint8_t get_adapter_address(void)
{
uint8_t buf[BASELEN_PROP_CHANGED + sizeof(bdaddr_t)];
struct hal_ev_adapter_props_changed *ev = (void *) buf;
@@ -1704,7 +1704,7 @@ static uint8_t get_address(void)
return HAL_STATUS_SUCCESS;
}
-static uint8_t get_name(void)
+static uint8_t get_adapter_name(void)
{
if (!adapter.name)
return HAL_STATUS_FAILED;
@@ -1715,7 +1715,7 @@ static uint8_t get_name(void)
}
-static uint8_t get_class(void)
+static uint8_t get_adapter_class(void)
{
DBG("");
@@ -1724,7 +1724,7 @@ static uint8_t get_class(void)
return HAL_STATUS_SUCCESS;
}
-static uint8_t get_type(void)
+static uint8_t get_adapter_type(void)
{
DBG("Not implemented");
@@ -1733,7 +1733,7 @@ static uint8_t get_type(void)
return HAL_STATUS_FAILED;
}
-static uint8_t get_service(void)
+static uint8_t get_adapter_service_rec(void)
{
DBG("Not implemented");
@@ -1742,7 +1742,7 @@ static uint8_t get_service(void)
return HAL_STATUS_FAILED;
}
-static uint8_t get_scan_mode(void)
+static uint8_t get_adapter_scan_mode(void)
{
DBG("");
@@ -1751,7 +1751,7 @@ static uint8_t get_scan_mode(void)
return HAL_STATUS_SUCCESS;
}
-static uint8_t get_devices(void)
+static uint8_t get_adapter_bonded_devices(void)
{
DBG("Not implemented");
@@ -1760,7 +1760,7 @@ static uint8_t get_devices(void)
return HAL_STATUS_FAILED;
}
-static uint8_t get_discoverable_timeout(void)
+static uint8_t get_adapter_discoverable_timeout(void)
{
struct hal_ev_adapter_props_changed *ev;
uint8_t buf[BASELEN_PROP_CHANGED + sizeof(uint32_t)];
@@ -1789,31 +1789,31 @@ static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
switch (cmd->type) {
case HAL_PROP_ADAPTER_ADDR:
- status = get_address();
+ status = get_adapter_address();
break;
case HAL_PROP_ADAPTER_NAME:
- status = get_name();
+ status = get_adapter_name();
break;
case HAL_PROP_ADAPTER_UUIDS:
- status = get_uuids();
+ status = get_adapter_uuids();
break;
case HAL_PROP_ADAPTER_CLASS:
- status = get_class();
+ status = get_adapter_class();
break;
case HAL_PROP_ADAPTER_TYPE:
- status = get_type();
+ status = get_adapter_type();
break;
case HAL_PROP_ADAPTER_SERVICE_REC:
- status = get_service();
+ status = get_adapter_service_rec();
break;
case HAL_PROP_ADAPTER_SCAN_MODE:
- status = get_scan_mode();
+ status = get_adapter_scan_mode();
break;
case HAL_PROP_ADAPTER_BONDED_DEVICES:
- status = get_devices();
+ status = get_adapter_bonded_devices();
break;
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- status = get_discoverable_timeout();
+ status = get_adapter_discoverable_timeout();
break;
default:
status = HAL_STATUS_FAILED;
@@ -1823,17 +1823,17 @@ static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP, status);
}
-static void get_properties(void)
+static void get_adapter_properties(void)
{
- get_address();
- get_name();
- get_uuids();
- get_class();
- get_type();
- get_service();
- get_scan_mode();
- get_devices();
- get_discoverable_timeout();
+ get_adapter_address();
+ get_adapter_name();
+ get_adapter_uuids();
+ get_adapter_class();
+ get_adapter_type();
+ get_adapter_service_rec();
+ get_adapter_scan_mode();
+ get_adapter_bonded_devices();
+ get_adapter_discoverable_timeout();
}
static bool start_discovery(void)
@@ -1876,7 +1876,7 @@ static bool stop_discovery(void)
return false;
}
-static uint8_t set_scan_mode(const void *buf, uint16_t len)
+static uint8_t set_adapter_scan_mode(const void *buf, uint16_t len)
{
const uint8_t *mode = buf;
bool conn, disc, cur_conn, cur_disc;
@@ -1953,13 +1953,13 @@ static void handle_set_adapter_prop_cmd(const void *buf, uint16_t len)
switch (cmd->type) {
case HAL_PROP_ADAPTER_SCAN_MODE:
- status = set_scan_mode(cmd->val, cmd->len);
+ status = set_adapter_scan_mode(cmd->val, cmd->len);
break;
case HAL_PROP_ADAPTER_NAME:
status = set_adapter_name(cmd->val, cmd->len);
break;
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- status = set_discoverable_timeout(cmd->val, cmd->len);
+ status = set_adapter_discoverable_timeout(cmd->val, cmd->len);
break;
default:
DBG("Unhandled property type 0x%x", cmd->type);
@@ -2222,7 +2222,7 @@ static void handle_enable_cmd(const void *buf, uint16_t len)
/* Framework expects all properties to be emitted while
* enabling adapter */
- get_properties();
+ get_adapter_properties();
if (adapter.current_settings & MGMT_SETTING_POWERED) {
status = HAL_STATUS_DONE;
@@ -2260,7 +2260,7 @@ failed:
static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
{
- get_properties();
+ get_adapter_properties();
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
HAL_STATUS_SUCCESS);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/8] android/bluetooth: Use single list for device caching
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
@ 2013-12-10 15:06 ` Szymon Janc
2013-12-10 15:06 ` [PATCH v2 3/8] android/bluetooth: Fix coding style issue in set_device_bond_state Szymon Janc
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This makes code much simpler and easier to follow. It is also
a preparation for supporting remote device properties getting, setting
and storing.
---
android/bluetooth.c | 160 ++++++++++++++++++++++------------------------------
1 file changed, 67 insertions(+), 93 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index f8df473..17c8e7a 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -111,9 +111,59 @@ static const uint16_t uuid_list[] = {
0
};
-static GSList *found_devices = NULL;
static GSList *devices = NULL;
+static int bdaddr_cmp(gconstpointer a, gconstpointer b)
+{
+ const bdaddr_t *bda = a;
+ const bdaddr_t *bdb = b;
+
+ return bacmp(bdb, bda);
+}
+
+static struct device *find_device(const bdaddr_t *bdaddr)
+{
+ GSList *l;
+
+ l = g_slist_find_custom(devices, bdaddr, bdaddr_cmp);
+ if (l)
+ return l->data;
+
+ return NULL;
+}
+
+static struct device *create_device(const bdaddr_t *bdaddr)
+{
+ struct device *dev;
+ char addr[18];
+
+ ba2str(bdaddr, addr);
+ DBG("%s", addr);
+
+ dev = g_new0(struct device, 1);
+
+ bacpy(&dev->bdaddr, bdaddr);
+ dev->bond_state = HAL_BOND_STATE_NONE;
+
+ /* use address for name, will be change if one is present
+ * eg. in EIR or set by set_property. */
+ dev->name = g_strdup(addr);
+ devices = g_slist_prepend(devices, dev);
+
+ return dev;
+}
+
+static struct device *get_device(const bdaddr_t *bdaddr)
+{
+ struct device *dev;
+
+ dev = find_device(bdaddr);
+ if (dev)
+ return dev;
+
+ return create_device(bdaddr);
+}
+
static void adapter_name_changed(const uint8_t *name)
{
struct hal_ev_adapter_props_changed *ev;
@@ -308,14 +358,6 @@ static void store_link_key(const bdaddr_t *dst, const uint8_t *key,
}
-static int bdaddr_cmp(gconstpointer a, gconstpointer b)
-{
- const bdaddr_t *bda = a;
- const bdaddr_t *bdb = b;
-
- return bacmp(bdb, bda);
-}
-
static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
uint8_t state)
{
@@ -329,46 +371,12 @@ static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
sizeof(ev), &ev);
}
-static void cache_device_name(const bdaddr_t *addr, const char *name)
-{
- struct device *dev = NULL;
- GSList *l;
-
- l = g_slist_find_custom(devices, addr, bdaddr_cmp);
- if (l)
- dev = l->data;
-
- if (!dev) {
- dev = g_new0(struct device, 1);
- bacpy(&dev->bdaddr, addr);
- dev->bond_state = HAL_BOND_STATE_NONE;
- devices = g_slist_prepend(devices, dev);
- }
-
- if (!g_strcmp0(dev->name, name))
- return;
-
- g_free(dev->name);
- dev->name = g_strdup(name);
- /*TODO: Do some real caching here */
-}
-
static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
int state) {
- struct device *dev = NULL;
- GSList *l;
-
- l = g_slist_find_custom(devices, addr, bdaddr_cmp);
- if (l)
- dev = l->data;
+ struct device *dev;
- if (!dev) {
- dev = g_new0(struct device, 1);
- bacpy(&dev->bdaddr, addr);
- dev->bond_state = HAL_BOND_STATE_NONE;
- devices = g_slist_prepend(devices, dev);
- }
+ dev = get_device(addr);
if (dev->bond_state != state) {
dev->bond_state = state;
@@ -566,42 +574,23 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
browse_remote_sdp(&addr->bdaddr);
}
-static const char *get_device_name(const bdaddr_t *addr)
-{
- GSList *l;
-
- l = g_slist_find_custom(devices, addr, bdaddr_cmp);
- if (l) {
- struct device *dev = l->data;
- return dev->name;
- }
-
- return NULL;
-}
-
static void send_remote_device_name_prop(const bdaddr_t *bdaddr)
{
struct hal_ev_remote_device_props *ev;
- const char *name;
+ struct device *dev;
size_t ev_len;
- char dst[18];
- /* Use cached name or bdaddr string */
- name = get_device_name(bdaddr);
- if (!name) {
- ba2str(bdaddr, dst);
- name = dst;
- }
+ dev = get_device(bdaddr);
- ev_len = BASELEN_REMOTE_DEV_PROP + strlen(name);
+ ev_len = BASELEN_REMOTE_DEV_PROP + strlen(dev->name);
ev = g_malloc0(ev_len);
ev->status = HAL_STATUS_SUCCESS;
bdaddr2android(bdaddr, ev->bdaddr);
ev->num_props = 1;
ev->props[0].type = HAL_PROP_DEVICE_NAME;
- ev->props[0].len = strlen(name);
- memcpy(&ev->props[0].val, name, strlen(name));
+ ev->props[0].len = strlen(dev->name);
+ memcpy(&ev->props[0].val, dev->name, strlen(dev->name));
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_REMOTE_DEVICE_PROPS,
ev_len, ev);
@@ -749,14 +738,10 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
DBG("new discovering state %u", ev->discovering);
- if (adapter.discovering) {
+ if (adapter.discovering)
cp.state = HAL_DISCOVERY_STATE_STARTED;
- } else {
- g_slist_free_full(found_devices, g_free);
- found_devices = NULL;
-
+ else
cp.state = HAL_DISCOVERY_STATE_STOPPED;
- }
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH,
HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp);
@@ -793,8 +778,8 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
const uint8_t *data, uint8_t data_len)
{
uint8_t buf[BLUEZ_HAL_MTU];
- bool new_dev = false;
struct eir_data eir;
+ struct device *dev;
uint8_t *num_prop;
uint8_t opcode;
int size = 0;
@@ -804,25 +789,13 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
eir_parse(&eir, data, data_len);
- if (!g_slist_find_custom(found_devices, bdaddr, bdaddr_cmp)) {
- bdaddr_t *new_bdaddr;
- char addr[18];
-
- new_bdaddr = g_new0(bdaddr_t, 1);
- bacpy(new_bdaddr, bdaddr);
-
- found_devices = g_slist_prepend(found_devices, new_bdaddr);
-
- ba2str(new_bdaddr, addr);
- DBG("New device found: %s", addr);
-
- new_dev = true;
- }
-
- if (new_dev) {
+ dev = find_device(bdaddr);
+ if (!dev) {
struct hal_ev_device_found *ev = (void *) buf;
bdaddr_t android_bdaddr;
+ dev = create_device(bdaddr);
+
size += sizeof(*ev);
num_prop = &ev->num_props;
@@ -858,7 +831,8 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
}
if (eir.name) {
- cache_device_name(bdaddr, eir.name);
+ g_free(dev->name);
+ dev->name = g_strdup(eir.name);
size += fill_hal_prop(buf + size, HAL_PROP_DEVICE_NAME,
strlen(eir.name), eir.name);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/8] android/bluetooth: Fix coding style issue in set_device_bond_state
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
2013-12-10 15:06 ` [PATCH v2 2/8] android/bluetooth: Use single list for device caching Szymon Janc
@ 2013-12-10 15:06 ` Szymon Janc
2013-12-10 15:06 ` [PATCH v2 4/8] android/bluetooth: Refactor send_remote_device_name_prop Szymon Janc
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/bluetooth.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 17c8e7a..5494dcb 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -372,7 +372,8 @@ static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
}
static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
- int state) {
+ int state)
+{
struct device *dev;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/8] android/bluetooth: Refactor send_remote_device_name_prop
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
2013-12-10 15:06 ` [PATCH v2 2/8] android/bluetooth: Use single list for device caching Szymon Janc
2013-12-10 15:06 ` [PATCH v2 3/8] android/bluetooth: Fix coding style issue in set_device_bond_state Szymon Janc
@ 2013-12-10 15:06 ` Szymon Janc
2013-12-10 15:06 ` [PATCH v2 5/8] android/bluetooth: Add stubs for get device properties command Szymon Janc
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Rename send_remote_device_name_prop to get_device_name and make it
accept struct device as parameter. Also return HAL status code.
This will allow to use this function also in get device property
command handler.
---
android/bluetooth.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 5494dcb..326f6d2 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -575,19 +575,16 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
browse_remote_sdp(&addr->bdaddr);
}
-static void send_remote_device_name_prop(const bdaddr_t *bdaddr)
+static uint8_t get_device_name(struct device *dev)
{
struct hal_ev_remote_device_props *ev;
- struct device *dev;
size_t ev_len;
- dev = get_device(bdaddr);
-
ev_len = BASELEN_REMOTE_DEV_PROP + strlen(dev->name);
ev = g_malloc0(ev_len);
ev->status = HAL_STATUS_SUCCESS;
- bdaddr2android(bdaddr, ev->bdaddr);
+ bdaddr2android(&dev->bdaddr, ev->bdaddr);
ev->num_props = 1;
ev->props[0].type = HAL_PROP_DEVICE_NAME;
ev->props[0].len = strlen(dev->name);
@@ -597,6 +594,8 @@ static void send_remote_device_name_prop(const bdaddr_t *bdaddr)
ev_len, ev);
g_free(ev);
+
+ return HAL_STATUS_SUCCESS;
}
static void pin_code_request_callback(uint16_t index, uint16_t length,
@@ -615,7 +614,7 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
/* Workaround for Android Bluetooth.apk issue: send remote
* device property */
- send_remote_device_name_prop(&ev->addr.bdaddr);
+ get_device_name(get_device(&ev->addr.bdaddr));
set_device_bond_state(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
HAL_BOND_STATE_BONDING);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/8] android/bluetooth: Add stubs for get device properties command
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
` (2 preceding siblings ...)
2013-12-10 15:06 ` [PATCH v2 4/8] android/bluetooth: Refactor send_remote_device_name_prop Szymon Janc
@ 2013-12-10 15:06 ` Szymon Janc
2013-12-10 15:06 ` [PATCH v2 6/8] android/bluetooth: Add stubs for set device property command Szymon Janc
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This adds per property stubs.
---
android/bluetooth.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 119 insertions(+), 2 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 326f6d2..f46238a 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2240,6 +2240,78 @@ static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
HAL_STATUS_SUCCESS);
}
+static uint8_t get_device_uuids(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_class(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_type(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_service_rec(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_friendly_name(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_rssi(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_version_info(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t get_device_timestamp(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
{
/* TODO */
@@ -2250,10 +2322,55 @@ static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
static void handle_get_remote_device_prop_cmd(const void *buf, uint16_t len)
{
- /* TODO */
+ const struct hal_cmd_get_remote_device_prop *cmd = buf;
+ uint8_t status;
+ bdaddr_t addr;
+ GSList *l;
+ android2bdaddr(cmd->bdaddr, &addr);
+
+ l = g_slist_find_custom(devices, &addr, bdaddr_cmp);
+ if (!l) {
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
+
+ switch (cmd->type) {
+ case HAL_PROP_DEVICE_NAME:
+ status = get_device_name(l->data);
+ break;
+ case HAL_PROP_DEVICE_UUIDS:
+ status = get_device_uuids(l->data);
+ break;
+ case HAL_PROP_DEVICE_CLASS:
+ status = get_device_class(l->data);
+ break;
+ case HAL_PROP_DEVICE_TYPE:
+ status = get_device_type(l->data);
+ break;
+ case HAL_PROP_DEVICE_SERVICE_REC:
+ status = get_device_service_rec(l->data);
+ break;
+ case HAL_PROP_DEVICE_FRIENDLY_NAME:
+ status = get_device_friendly_name(l->data);
+ break;
+ case HAL_PROP_DEVICE_RSSI:
+ status = get_device_rssi(l->data);
+ break;
+ case HAL_PROP_DEVICE_VERSION_INFO:
+ status = get_device_version_info(l->data);
+ break;
+ case HAL_PROP_DEVICE_TIMESTAMP:
+ status = get_device_timestamp(l->data);
+ break;
+ default:
+ status = HAL_STATUS_FAILED;
+ break;
+ }
+
+failed:
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_DEVICE_PROP,
- HAL_STATUS_FAILED);
+ status);
}
static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/8] android/bluetooth: Add stubs for set device property command
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
` (3 preceding siblings ...)
2013-12-10 15:06 ` [PATCH v2 5/8] android/bluetooth: Add stubs for get device properties command Szymon Janc
@ 2013-12-10 15:06 ` Szymon Janc
2013-12-10 15:06 ` [PATCH v2 7/8] android/bluetooth: Add send_device_property helper function Szymon Janc
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This adds per property stubs.
---
android/bluetooth.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index f46238a..483396c 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -2373,10 +2373,30 @@ failed:
status);
}
+static uint8_t set_device_friendly_name(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
+static uint8_t set_device_version_info(struct device *dev)
+{
+ DBG("Not implemented");
+
+ /* TODO */
+
+ return HAL_STATUS_FAILED;
+}
+
static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
{
const struct hal_cmd_set_remote_device_prop *cmd = buf;
uint8_t status;
+ bdaddr_t addr;
+ GSList *l;
if (len != sizeof(*cmd) + cmd->len) {
error("Invalid set remote device prop cmd (0x%x), terminating",
@@ -2385,15 +2405,27 @@ static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
return;
}
- /* TODO */
+ android2bdaddr(cmd->bdaddr, &addr);
+
+ l = g_slist_find_custom(devices, &addr, bdaddr_cmp);
+ if (!l) {
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
switch (cmd->type) {
+ case HAL_PROP_DEVICE_FRIENDLY_NAME:
+ status = set_device_friendly_name(l->data);
+ break;
+ case HAL_PROP_DEVICE_VERSION_INFO:
+ status = set_device_version_info(l->data);
+ break;
default:
- DBG("Unhandled property type 0x%x", cmd->type);
status = HAL_STATUS_FAILED;
break;
}
+failed:
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_REMOTE_DEVICE_PROP,
status);
}
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 7/8] android/bluetooth: Add send_device_property helper function
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
` (4 preceding siblings ...)
2013-12-10 15:06 ` [PATCH v2 6/8] android/bluetooth: Add stubs for set device property command Szymon Janc
@ 2013-12-10 15:06 ` Szymon Janc
2013-12-10 15:06 ` [PATCH v2 8/8] android/bluetooth: Add send_adapter_property " Szymon Janc
2013-12-10 15:29 ` [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Johan Hedberg
7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Remote device property notification will be send from multiple places
so it make sense to have helper for that. This will be especially
usefull for 'simple' properties.
---
android/bluetooth.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 483396c..b1d2c71 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -574,26 +574,27 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
browse_remote_sdp(&addr->bdaddr);
}
-
-static uint8_t get_device_name(struct device *dev)
+static void send_device_property(const bdaddr_t *bdaddr, uint8_t type,
+ uint16_t len, const void *val)
{
- struct hal_ev_remote_device_props *ev;
- size_t ev_len;
-
- ev_len = BASELEN_REMOTE_DEV_PROP + strlen(dev->name);
- ev = g_malloc0(ev_len);
+ uint8_t buf[BASELEN_REMOTE_DEV_PROP + len];
+ struct hal_ev_remote_device_props *ev = (void *) buf;
ev->status = HAL_STATUS_SUCCESS;
- bdaddr2android(&dev->bdaddr, ev->bdaddr);
+ bdaddr2android(bdaddr, ev->bdaddr);
ev->num_props = 1;
- ev->props[0].type = HAL_PROP_DEVICE_NAME;
- ev->props[0].len = strlen(dev->name);
- memcpy(&ev->props[0].val, dev->name, strlen(dev->name));
+ ev->props[0].type = type;
+ ev->props[0].len = len;
+ memcpy(ev->props[0].val, val, len);
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_REMOTE_DEVICE_PROPS,
- ev_len, ev);
+ sizeof(buf), buf);
+}
- g_free(ev);
+static uint8_t get_device_name(struct device *dev)
+{
+ send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_NAME,
+ strlen(dev->name), dev->name);
return HAL_STATUS_SUCCESS;
}
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 8/8] android/bluetooth: Add send_adapter_property helper function
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
` (5 preceding siblings ...)
2013-12-10 15:06 ` [PATCH v2 7/8] android/bluetooth: Add send_device_property helper function Szymon Janc
@ 2013-12-10 15:06 ` Szymon Janc
2013-12-10 15:29 ` [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Johan Hedberg
7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2013-12-10 15:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Adapter property notification are send from multiple places so it make
sense to have helper for that. This is especially usefull for 'simple'
properties.
---
android/bluetooth.c | 88 +++++++++++++++--------------------------------------
1 file changed, 25 insertions(+), 63 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index b1d2c71..e456f3c 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -164,24 +164,26 @@ static struct device *get_device(const bdaddr_t *bdaddr)
return create_device(bdaddr);
}
-static void adapter_name_changed(const uint8_t *name)
+static void send_adapter_property(uint8_t type, uint16_t len, const void *val)
{
- struct hal_ev_adapter_props_changed *ev;
- size_t len = strlen((const char *) name);
uint8_t buf[BASELEN_PROP_CHANGED + len];
+ struct hal_ev_adapter_props_changed *ev = (void *) buf;
- memset(buf, 0, sizeof(buf));
- ev = (void *) buf;
-
- ev->num_props = 1;
ev->status = HAL_STATUS_SUCCESS;
- ev->props[0].type = HAL_PROP_ADAPTER_NAME;
- /* Android expects value without NULL terminator */
+ ev->num_props = 1;
+ ev->props[0].type = type;
ev->props[0].len = len;
- memcpy(ev->props->val, name, len);
+ memcpy(ev->props[0].val, val, len);
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), ev);
+ sizeof(buf), buf);
+}
+
+static void adapter_name_changed(const uint8_t *name)
+{
+ /* Android expects string value without NULL terminator */
+ send_adapter_property(HAL_PROP_ADAPTER_NAME,
+ strlen((const char *) name), name);
}
static void adapter_set_name(const uint8_t *name)
@@ -243,39 +245,19 @@ static uint8_t settings2scan_mode(void)
static void scan_mode_changed(void)
{
- uint8_t buf[BASELEN_PROP_CHANGED + 1];
- struct hal_ev_adapter_props_changed *ev = (void *) buf;
- uint8_t *mode;
-
- ev->num_props = 1;
- ev->status = HAL_STATUS_SUCCESS;
-
- ev->props[0].type = HAL_PROP_ADAPTER_SCAN_MODE;
- ev->props[0].len = 1;
+ uint8_t mode;
- mode = ev->props[0].val;
- *mode = settings2scan_mode();
+ mode = settings2scan_mode();
- DBG("mode %u", *mode);
+ DBG("mode %u", mode);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), buf);
+ send_adapter_property(HAL_PROP_ADAPTER_SCAN_MODE, sizeof(mode), &mode);
}
static void adapter_class_changed(void)
{
- uint8_t buf[BASELEN_PROP_CHANGED + sizeof(uint32_t)];
- struct hal_ev_adapter_props_changed *ev = (void *) buf;
-
- 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_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), buf);
+ send_adapter_property(HAL_PROP_ADAPTER_CLASS, sizeof(adapter.dev_class),
+ &adapter.dev_class);
}
static void settings_changed(uint32_t settings)
@@ -1663,18 +1645,11 @@ static bool set_discoverable(uint8_t mode, uint16_t timeout)
static uint8_t get_adapter_address(void)
{
- uint8_t buf[BASELEN_PROP_CHANGED + sizeof(bdaddr_t)];
- struct hal_ev_adapter_props_changed *ev = (void *) buf;
-
- ev->num_props = 1;
- ev->status = HAL_STATUS_SUCCESS;
+ uint8_t buf[6];
- ev->props[0].type = HAL_PROP_ADAPTER_ADDR;
- ev->props[0].len = sizeof(bdaddr_t);
- bdaddr2android(&adapter.bdaddr, ev->props[0].val);
+ bdaddr2android(&adapter.bdaddr, buf);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), buf);
+ send_adapter_property(HAL_PROP_ADAPTER_ADDR, sizeof(buf), buf);
return HAL_STATUS_SUCCESS;
}
@@ -1737,22 +1712,9 @@ static uint8_t get_adapter_bonded_devices(void)
static uint8_t get_adapter_discoverable_timeout(void)
{
- struct hal_ev_adapter_props_changed *ev;
- uint8_t buf[BASELEN_PROP_CHANGED + sizeof(uint32_t)];
-
- memset(buf, 0, sizeof(buf));
- ev = (void *) buf;
-
- 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_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), ev);
+ send_adapter_property(HAL_PROP_ADAPTER_DISC_TIMEOUT,
+ sizeof(adapter.discoverable_timeout),
+ &adapter.discoverable_timeout);
return HAL_STATUS_SUCCESS;
}
--
1.8.3.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
` (6 preceding siblings ...)
2013-12-10 15:06 ` [PATCH v2 8/8] android/bluetooth: Add send_adapter_property " Szymon Janc
@ 2013-12-10 15:29 ` Johan Hedberg
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hedberg @ 2013-12-10 15:29 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Tue, Dec 10, 2013, Szymon Janc wrote:
> This match adapter properties handling functions with properties names.
> Will make code easier to understand and avoid clashes with remote
> device properties functions.
> ---
> android/bluetooth.c | 72 ++++++++++++++++++++++++++---------------------------
> 1 file changed, 36 insertions(+), 36 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-12-10 15:29 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-10 15:06 [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Szymon Janc
2013-12-10 15:06 ` [PATCH v2 2/8] android/bluetooth: Use single list for device caching Szymon Janc
2013-12-10 15:06 ` [PATCH v2 3/8] android/bluetooth: Fix coding style issue in set_device_bond_state Szymon Janc
2013-12-10 15:06 ` [PATCH v2 4/8] android/bluetooth: Refactor send_remote_device_name_prop Szymon Janc
2013-12-10 15:06 ` [PATCH v2 5/8] android/bluetooth: Add stubs for get device properties command Szymon Janc
2013-12-10 15:06 ` [PATCH v2 6/8] android/bluetooth: Add stubs for set device property command Szymon Janc
2013-12-10 15:06 ` [PATCH v2 7/8] android/bluetooth: Add send_device_property helper function Szymon Janc
2013-12-10 15:06 ` [PATCH v2 8/8] android/bluetooth: Add send_adapter_property " Szymon Janc
2013-12-10 15:29 ` [PATCH v2 1/8] android/bluetooth: Rename functions to match adapter properties names Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).