err variable was set but never read.
---
android/main.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/android/main.c b/android/main.c
index 50b5901..18dc9f7 100644
--- a/android/main.c
+++ b/android/main.c
@@ -239,12 +239,12 @@ static GIOChannel *connect_hal(GIOFunc connect_cb)
struct sockaddr_un addr;
GIOCondition cond;
GIOChannel *io;
- int err, sk;
+ int sk;
sk = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
if (sk < 0) {
- err = errno;
- error("Failed to create socket: %d (%s)", err, strerror(err));
+ error("Failed to create socket: %d (%s)", errno,
+ strerror(errno));
return NULL;
}
@@ -258,9 +258,7 @@ static GIOChannel *connect_hal(GIOFunc connect_cb)
memcpy(addr.sun_path, BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH));
- err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
- if (err < 0) {
- err = -errno;
+ if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
error("Failed to connect HAL socket: %d (%s)", errno,
strerror(errno));
g_io_channel_unref(io);
--
1.8.4.1
Hi,
On Fri, Oct 25, 2013 at 12:36 PM, Andrei Emeltchenko
<[email protected]> wrote:
> Hi Szymon,
>
> On Fri, Oct 25, 2013 at 10:56:09AM +0200, Szymon Janc wrote:
>> This allows HAL to start bonding.
>> ---
>> android/hal-bluetooth.c | 8 +++++---
>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
>> index b81f8dd..6f7ef45 100644
>> --- a/android/hal-bluetooth.c
>> +++ b/android/hal-bluetooth.c
>> @@ -275,15 +275,17 @@ static int cancel_discovery(void)
>>
>> static int create_bond(const bt_bdaddr_t *bd_addr)
>> {
>> + struct hal_cmd_create_bond cmd;
>> +
>> DBG("");
>>
>> if (!interface_ready())
>> return BT_STATUS_NOT_READY;
>>
>> - if (!bd_addr)
>> - return BT_STATUS_PARM_INVALID;
>
> I think we can leave check here
If we are sure it will never be NULL then yes we can remove, otherwise leave it.
--
Luiz Augusto von Dentz
Hi Szymon,
On Fri, Oct 25, 2013 at 10:56:09AM +0200, Szymon Janc wrote:
> This allows HAL to start bonding.
> ---
> android/hal-bluetooth.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> index b81f8dd..6f7ef45 100644
> --- a/android/hal-bluetooth.c
> +++ b/android/hal-bluetooth.c
> @@ -275,15 +275,17 @@ static int cancel_discovery(void)
>
> static int create_bond(const bt_bdaddr_t *bd_addr)
> {
> + struct hal_cmd_create_bond cmd;
> +
> DBG("");
>
> if (!interface_ready())
> return BT_STATUS_NOT_READY;
>
> - if (!bd_addr)
> - return BT_STATUS_PARM_INVALID;
I think we can leave check here
Best regards
Andrei Emeltchenko
> + memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
>
> - return BT_STATUS_UNSUPPORTED;
> + return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND,
> + sizeof(cmd), &cmd, 0, NULL, NULL);
> }
>
> static int cancel_bond(const bt_bdaddr_t *bd_addr)
> --
> 1.8.4.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
This allows HAL to remove bonding.
---
android/hal-bluetooth.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index ebaa877..ca443a6 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -305,12 +305,17 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr)
static int remove_bond(const bt_bdaddr_t *bd_addr)
{
+ struct hal_cmd_remove_bond cmd;
+
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- return BT_STATUS_UNSUPPORTED;
+ memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_REMOVE_BOND,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
}
static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
--
1.8.4.1
This is used in HAL callbacks to indicate success.
---
android/hal-msg.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index f6c9e22..089f1d6 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -49,6 +49,7 @@ struct hal_hdr {
/* Core Service */
+#define HAL_ERROR_SUCCESS 0x00
#define HAL_ERROR_FAILED 0x01
#define HAL_ERROR_NOT_READY 0x02
#define HAL_ERROR_NOMEM 0x03
--
1.8.4.1
Support for HAL_BT_PROP_BDADDR property only.
---
android/adapter.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 5837e99..e6791e7 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -322,6 +322,49 @@ static bool set_mode(uint16_t opcode, uint8_t mode)
return false;
}
+static void send_adapter_name(void)
+{
+ struct hal_ev_adapter_props_changed *ev;
+ int len;
+
+ len = sizeof(*ev) + sizeof(struct hal_property) + sizeof(bdaddr_t);
+
+ ev = g_malloc(len);
+
+ ev->num_props = 1;
+ ev->status = HAL_ERROR_SUCCESS;
+
+ ev->props[0].type = HAL_BT_PROP_BDADDR;
+ ev->props[0].len = sizeof(bdaddr_t);
+ baswap((bdaddr_t *) ev->props[0].val, &adapter->bdaddr);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+ g_free(ev);
+}
+
+static bool get_property(void *buf, uint16_t len)
+{
+ struct hal_cmd_get_adapter_prop *cmd = buf;
+
+ switch (cmd->type) {
+ case HAL_BT_PROP_BDADDR:
+ send_adapter_name();
+ return true;
+ case HAL_BT_PROP_BDNAME:
+ case HAL_BT_PROP_UUIDS:
+ case HAL_BT_PROP_CLASS_OF_DEVICE:
+ case HAL_BT_PROP_TYPE_OF_DEVICE:
+ case HAL_BT_PROP_SERVICE_RECORD:
+ case HAL_BT_PROP_ADP_SCAN_MODE:
+ case HAL_BT_PROP_ADP_BONDED_DEVICES:
+ case HAL_BT_PROP_ADP_DISC_TIMEOUT:
+ default:
+ return false;
+ }
+}
+
void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
uint16_t len)
{
@@ -352,6 +395,13 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
return;
}
break;
+ case HAL_OP_GET_ADAPTER_PROP:
+ if (get_property(buf, len)) {
+ ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
+ -1);
+ return;
+ }
+ break;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
break;
--
1.8.4.1
---
android/hal-msg.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 7689f38..f6c9e22 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -169,6 +169,11 @@ struct hal_cmd_pin_reply {
uint8_t pin_code[16];
} __attribute__((packed));
+#define HAL_BT_SSP_VARIANT_CONFIRM 0x00
+#define HAL_BT_SSP_VARIANT_ENTRY 0x01
+#define HAL_BT_SSP_VARIANT_CONSENT 0x02
+#define HAL_BT_SSP_VARIANT_NOTIF 0x03
+
#define HAL_OP_SSP_REPLY 0x11
struct hal_cmd_ssp_reply {
uint8_t bdaddr[6];
--
1.8.4.1
---
android/hal-bluetooth.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index eb400ee..9c7fbea 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -35,6 +35,37 @@ static void handle_adapter_state_changed(void *buf)
bt_hal_cbacks->adapter_state_changed_cb(ev->state);
}
+static void handle_adapter_props_changed(void *buf, uint16_t len)
+{
+ struct hal_ev_adapter_props_changed *ev = buf;
+ bt_property_t props[ev->num_props];
+ struct hal_property *hal_prop;
+ void *p;
+ int i;
+
+ if (!bt_hal_cbacks->adapter_properties_cb)
+ return;
+
+ hal_prop = ev->props;
+ p = ev->props;
+
+ for (i = 0; i < ev->num_props; i++) {
+ if (p + sizeof(*hal_prop) + hal_prop->len > buf + len) {
+ error("invalid adapter properties event, aborting");
+ exit(EXIT_FAILURE);
+ }
+
+ props[i].type = hal_prop->type;
+ props[i].len = hal_prop->len;
+ props[i].val = hal_prop->val;
+
+ p += sizeof(*hal_prop) + hal_prop->len;
+ hal_prop = p;
+ }
+
+ bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
+}
+
/* will be called from notification thread context */
void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
{
@@ -45,6 +76,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_ADAPTER_STATE_CHANGED:
handle_adapter_state_changed(buf);
break;
+ case HAL_EV_ADAPTER_PROPS_CHANGED:
+ handle_adapter_props_changed(buf, len);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.4.1
This allows HAL to reply to SSP request.
---
android/hal-bluetooth.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6835db3..eb400ee 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -340,15 +340,21 @@ static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
uint8_t accept, uint32_t passkey)
{
+ struct hal_cmd_ssp_reply cmd;
+
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
+ memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+ /* type match IPC type */
+ cmd.ssp_variant = variant;
+ cmd.accept = accept;
+ cmd.passkey = passkey;
- return BT_STATUS_UNSUPPORTED;
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SSP_REPLY,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
}
static const void *get_profile_interface(const char *profile_id)
--
1.8.4.1
This allows HAL to reply to PIN code request.
---
android/hal-bluetooth.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index ca443a6..6835db3 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -321,12 +321,20 @@ static int remove_bond(const bt_bdaddr_t *bd_addr)
static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
uint8_t pin_len, bt_pin_code_t *pin_code)
{
+ struct hal_cmd_pin_reply cmd;
+
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- return BT_STATUS_UNSUPPORTED;
+ memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+ cmd.accept = accept;
+ cmd.pin_len = pin_len;
+ memcpy(cmd.pin_code, pin_code, sizeof(cmd.pin_code));
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_PIN_REPLY,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
}
static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
--
1.8.4.1
This allows HAL to cancel pending bonding.
---
android/hal-bluetooth.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6f7ef45..ebaa877 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -290,12 +290,17 @@ static int create_bond(const bt_bdaddr_t *bd_addr)
static int cancel_bond(const bt_bdaddr_t *bd_addr)
{
+ struct hal_cmd_cancel_bond cmd;
+
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- return BT_STATUS_UNSUPPORTED;
+ memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_BOND,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
}
static int remove_bond(const bt_bdaddr_t *bd_addr)
--
1.8.4.1
Those are used to specify SSP association model.
---
android/hal-ipc-api.txt | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index a5437c1..0c2fd25 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -281,6 +281,11 @@ Commands and responses:
Passkey (4 octets)
Response parameters: <none>
+ Valid SSP variant values: 0x00 = Passkey Confirmation
+ 0x01 = Passkey Entry
+ 0x02 = Consent (for Just Works)
+ 0x03 = Passkey Notification
+
In case of an error, the error response will be returned.
Opcode 0x12 - DUT Mode Configure command/response
--
1.8.4.1
This allows HAL to get all adapter properties.
---
android/hal-bluetooth.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index a71de83..b81f8dd 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -138,7 +138,8 @@ static int get_adapter_properties(void)
if (!interface_ready())
return BT_STATUS_NOT_READY;
- return BT_STATUS_UNSUPPORTED;
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
+ 0, NULL, 0, NULL, NULL);
}
static int get_adapter_property(bt_property_type_t type)
--
1.8.4.1
This allows HAL to set adapter property.
---
android/hal-bluetooth.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6e28c91..aae6078 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -153,15 +153,30 @@ static int get_adapter_property(bt_property_type_t type)
static int set_adapter_property(const bt_property_t *property)
{
+ char buf[sizeof(struct hal_cmd_set_adapter_prop) + property->len];
+ struct hal_cmd_set_adapter_prop *cmd = (void *) buf;
+
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- if (property == NULL)
+ switch (property->type) {
+ case BT_PROPERTY_BDNAME:
+ case BT_PROPERTY_ADAPTER_SCAN_MODE:
+ case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
+ break;
+ default:
return BT_STATUS_PARM_INVALID;
+ }
- return BT_STATUS_UNSUPPORTED;
+ /* type match IPC type */
+ cmd->type = property->type;
+ cmd->len = property->len;
+ memcpy(cmd->val, property->val, property->len);
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP,
+ sizeof(buf), cmd, 0, NULL, NULL);
}
static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
--
1.8.4.1
This allows HAL to get adapter property.
---
android/hal-bluetooth.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index aae6078..a71de83 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -143,12 +143,33 @@ static int get_adapter_properties(void)
static int get_adapter_property(bt_property_type_t type)
{
+ struct hal_cmd_get_adapter_prop cmd;
+
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- return BT_STATUS_UNSUPPORTED;
+ switch (type) {
+ case BT_PROPERTY_BDNAME:
+ case BT_PROPERTY_BDADDR:
+ case BT_PROPERTY_UUIDS:
+ case BT_PROPERTY_CLASS_OF_DEVICE:
+ case BT_PROPERTY_TYPE_OF_DEVICE:
+ case BT_PROPERTY_SERVICE_RECORD:
+ case BT_PROPERTY_ADAPTER_SCAN_MODE:
+ case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
+ case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
+ break;
+ default:
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ /* type match IPC type */
+ cmd.type = type;
+
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
}
static int set_adapter_property(const bt_property_t *property)
--
1.8.4.1
This allows HAL to start bonding.
---
android/hal-bluetooth.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index b81f8dd..6f7ef45 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -275,15 +275,17 @@ static int cancel_discovery(void)
static int create_bond(const bt_bdaddr_t *bd_addr)
{
+ struct hal_cmd_create_bond cmd;
+
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
+ memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
- return BT_STATUS_UNSUPPORTED;
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND,
+ sizeof(cmd), &cmd, 0, NULL, NULL);
}
static int cancel_bond(const bt_bdaddr_t *bd_addr)
--
1.8.4.1
HAL_BT_PROP_ADP_* are specific to adapter. HAL_BT_PROP_REM_* are
specific to remote device. Rest is common.
---
android/hal-msg.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 854e9b8..7689f38 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -91,6 +91,20 @@ struct hal_cmd_get_adapter_prop {
uint8_t type;
} __attribute__((packed));
+#define HAL_BT_PROP_BDNAME 0x01
+#define HAL_BT_PROP_BDADDR 0x02
+#define HAL_BT_PROP_UUIDS 0x03
+#define HAL_BT_PROP_CLASS_OF_DEVICE 0x04
+#define HAL_BT_PROP_TYPE_OF_DEVICE 0x05
+#define HAL_BT_PROP_SERVICE_RECORD 0x06
+#define HAL_BT_PROP_ADP_SCAN_MODE 0x07
+#define HAL_BT_PROP_ADP_BONDED_DEVICES 0x08
+#define HAL_BT_PROP_ADP_DISC_TIMEOUT 0x09
+#define HAL_BT_PROP_REM_FRIENDLY_NAME 0x0a
+#define HAL_BT_PROP_REM_RSSI 0x0b
+#define HAL_BT_PROP_REM_VERSION_INFO 0x0c
+#define HAL_BT_PROP_REM_DEV_TIMESTAMP 0xFF
+
#define HAL_OP_SET_ADAPTER_PROP 0x05
struct hal_cmd_set_adapter_prop {
uint8_t type;
--
1.8.4.1