* [PATCH v3 5/9] android/bluetooth: Make property handling function return HAL status
From: Szymon Janc @ 2013-12-02 12:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385986848-8023-1-git-send-email-szymon.janc@tieto.com>
This makes funtions follow have similar style and makes properties
dispatch function much simpler.
---
android/bluetooth.c | 85 +++++++++++++++++++----------------------------------
1 file changed, 30 insertions(+), 55 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index eb8dbc5..a39e7bf 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1133,7 +1133,7 @@ static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128)
ntoh128(&uuid128.value.uuid128, u128);
}
-static bool get_uuids(void)
+static uint8_t get_uuids(void)
{
struct hal_ev_adapter_props_changed *ev;
GSList *list = adapter.uuids;
@@ -1169,7 +1169,7 @@ static bool get_uuids(void)
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
sizeof(buf), ev);
- return true;
+ return HAL_STATUS_SUCCESS;
}
static void remove_uuid_complete(uint8_t status, uint16_t length,
@@ -1691,7 +1691,7 @@ static bool set_discoverable(uint8_t mode, uint16_t timeout)
return false;
}
-static void get_address(void)
+static uint8_t get_address(void)
{
uint8_t buf[BASELEN_PROP_CHANGED + sizeof(bdaddr_t)];
struct hal_ev_adapter_props_changed *ev = (void *) buf;
@@ -1705,65 +1705,67 @@ static void get_address(void)
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
sizeof(buf), buf);
+
+ return HAL_STATUS_SUCCESS;
}
-static bool get_name(void)
+static uint8_t get_name(void)
{
if (!adapter.name)
- return false;
+ return HAL_STATUS_FAILED;
adapter_name_changed((uint8_t *) adapter.name);
- return true;
+ return HAL_STATUS_SUCCESS;
}
-static bool get_class(void)
+static uint8_t get_class(void)
{
DBG("");
adapter_class_changed();
- return true;
+ return HAL_STATUS_SUCCESS;
}
-static bool get_type(void)
+static uint8_t get_type(void)
{
DBG("Not implemented");
/* TODO: Add implementation */
- return false;
+ return HAL_STATUS_FAILED;
}
-static bool get_service(void)
+static uint8_t get_service(void)
{
DBG("Not implemented");
/* TODO: Add implementation */
- return false;
+ return HAL_STATUS_FAILED;
}
-static bool get_scan_mode(void)
+static uint8_t get_scan_mode(void)
{
DBG("");
scan_mode_changed();
- return true;
+ return HAL_STATUS_SUCCESS;
}
-static bool get_devices(void)
+static uint8_t get_devices(void)
{
DBG("Not implemented");
/* TODO: Add implementation */
- return false;
+ return HAL_STATUS_FAILED;
}
-static bool get_discoverable_timeout(void)
+static uint8_t get_discoverable_timeout(void)
{
struct hal_ev_adapter_props_changed *ev;
uint8_t buf[BASELEN_PROP_CHANGED + sizeof(uint32_t)];
@@ -1782,7 +1784,7 @@ static bool get_discoverable_timeout(void)
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
sizeof(buf), ev);
- return true;
+ return HAL_STATUS_SUCCESS;
}
static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
@@ -1792,64 +1794,37 @@ static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
switch (cmd->type) {
case HAL_PROP_ADAPTER_ADDR:
- get_address();
+ status = get_address();
break;
case HAL_PROP_ADAPTER_NAME:
- if (!get_name()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_name();
break;
case HAL_PROP_ADAPTER_UUIDS:
- if (!get_uuids()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_uuids();
break;
case HAL_PROP_ADAPTER_CLASS:
- if (!get_class()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_class();
break;
case HAL_PROP_ADAPTER_TYPE:
- if (!get_type()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_type();
break;
case HAL_PROP_ADAPTER_SERVICE_REC:
- if (!get_service()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_service();
break;
case HAL_PROP_ADAPTER_SCAN_MODE:
- if (!get_scan_mode()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_scan_mode();
break;
case HAL_PROP_ADAPTER_BONDED_DEVICES:
- if (!get_devices()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_devices();
break;
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- if (!get_discoverable_timeout()) {
- status = HAL_STATUS_FAILED;
- goto failed;
- }
+ status = get_discoverable_timeout();
break;
default:
status = HAL_STATUS_FAILED;
- goto failed;
+ break;
}
- status = HAL_STATUS_SUCCESS;
-
-failed:
ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP, status);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH v3 4/9] android/bluetooth: Use generic IPC msg handling for commands
From: Szymon Janc @ 2013-12-02 12:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385986848-8023-1-git-send-email-szymon.janc@tieto.com>
Handlers are registered on service register and unregistered on
unregister.
---
android/bluetooth.c | 464 ++++++++++++++++++++++++++++++++++++----------------
1 file changed, 321 insertions(+), 143 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 8a1d444..eb8dbc5 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1361,7 +1361,7 @@ static void set_adapter_name_complete(uint8_t status, uint16_t length,
adapter_set_name(rp->name);
}
-static uint8_t set_adapter_name(uint8_t *name, uint16_t len)
+static uint8_t set_adapter_name(const uint8_t *name, uint16_t len)
{
struct mgmt_cp_set_local_name cp;
@@ -1378,8 +1378,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)
+static uint8_t set_discoverable_timeout(const void *buf, uint16_t len)
{
+ const uint32_t *timeout = buf;
+
+ if (len != sizeof(*timeout)) {
+ error("Invalid set disc timeout size (%u bytes), terminating",
+ len);
+ raise(SIGTERM);
+ return HAL_STATUS_FAILED;
+ }
+
/* Android handles discoverable timeout in Settings app.
* There is no need to use kernel feature for that.
* Just need to store this value here */
@@ -1776,33 +1785,72 @@ static bool get_discoverable_timeout(void)
return true;
}
-static bool get_property(void *buf, uint16_t len)
+static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_get_adapter_prop *cmd = buf;
+ const struct hal_cmd_get_adapter_prop *cmd = buf;
+ uint8_t status;
switch (cmd->type) {
case HAL_PROP_ADAPTER_ADDR:
get_address();
- return true;
+ break;
case HAL_PROP_ADAPTER_NAME:
- return get_name();
+ if (!get_name()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
case HAL_PROP_ADAPTER_UUIDS:
- return get_uuids();
+ if (!get_uuids()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
case HAL_PROP_ADAPTER_CLASS:
- return get_class();
+ if (!get_class()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
case HAL_PROP_ADAPTER_TYPE:
- return get_type();
+ if (!get_type()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
case HAL_PROP_ADAPTER_SERVICE_REC:
- return get_service();
+ if (!get_service()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
case HAL_PROP_ADAPTER_SCAN_MODE:
- return get_scan_mode();
+ if (!get_scan_mode()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
case HAL_PROP_ADAPTER_BONDED_DEVICES:
- return get_devices();
+ if (!get_devices()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- return get_discoverable_timeout();
+ if (!get_discoverable_timeout()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+ break;
default:
- return false;
+ status = HAL_STATUS_FAILED;
+ goto failed;
}
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP, status);
}
static void get_properties(void)
@@ -1858,11 +1906,18 @@ static bool stop_discovery(void)
return false;
}
-static uint8_t set_scan_mode(void *buf, uint16_t len)
+static uint8_t set_scan_mode(const void *buf, uint16_t len)
{
- uint8_t *mode = buf;
+ const uint8_t *mode = buf;
bool conn, disc, cur_conn, cur_disc;
+ if (len != sizeof(*mode)) {
+ error("Invalid set scan mode size (%u bytes), terminating",
+ len);
+ raise(SIGTERM);
+ return HAL_STATUS_FAILED;
+ }
+
cur_conn = adapter.current_settings & MGMT_SETTING_CONNECTABLE;
cur_disc = adapter.current_settings & MGMT_SETTING_DISCOVERABLE;
@@ -1914,21 +1969,35 @@ done:
return HAL_STATUS_DONE;
}
-static uint8_t set_property(void *buf, uint16_t len)
+static void handle_set_adapter_prop_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_set_adapter_prop *cmd = buf;
+ const struct hal_cmd_set_adapter_prop *cmd = buf;
+ uint8_t status;
+
+ if (len != sizeof(*cmd) + cmd->len) {
+ error("Invalid set adapter prop cmd (0x%x), terminating",
+ cmd->type);
+ raise(SIGTERM);
+ return;
+ }
switch (cmd->type) {
case HAL_PROP_ADAPTER_SCAN_MODE:
- return set_scan_mode(cmd->val, cmd->len);
+ status = set_scan_mode(cmd->val, cmd->len);
+ break;
case HAL_PROP_ADAPTER_NAME:
- return set_adapter_name(cmd->val, cmd->len);
+ status = set_adapter_name(cmd->val, cmd->len);
+ break;
case HAL_PROP_ADAPTER_DISC_TIMEOUT:
- return set_discoverable_timeout(cmd->val);
+ status = set_discoverable_timeout(cmd->val, cmd->len);
+ break;
default:
DBG("Unhandled property type 0x%x", cmd->type);
- return HAL_STATUS_FAILED;
+ status = HAL_STATUS_FAILED;
+ break;
}
+
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP, status);
}
static void pair_device_complete(uint8_t status, uint16_t length,
@@ -1947,9 +2016,10 @@ 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 void handle_create_bond_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_create_bond *cmd = buf;
+ const struct hal_cmd_create_bond *cmd = buf;
+ uint8_t status;
struct mgmt_cp_pair_device cp;
cp.io_cap = DEFAULT_IO_CAPABILITY;
@@ -1957,25 +2027,36 @@ static bool create_bond(void *buf, uint16_t len)
android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
if (mgmt_send(mgmt_if, MGMT_OP_PAIR_DEVICE, adapter.index, sizeof(cp),
- &cp, pair_device_complete, NULL, NULL) == 0)
- return false;
+ &cp, pair_device_complete, NULL, NULL) == 0) {
+ status = HAL_STATUS_FAILED;
+ goto fail;
+ }
+
+ status = HAL_STATUS_SUCCESS;
set_device_bond_state(&cp.addr.bdaddr, HAL_STATUS_SUCCESS,
HAL_BOND_STATE_BONDING);
- return true;
+fail:
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND, status);
}
-static bool cancel_bond(void *buf, uint16_t len)
+static void handle_cancel_bond_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_cancel_bond *cmd = buf;
+ const struct hal_cmd_cancel_bond *cmd = buf;
struct mgmt_addr_info cp;
+ uint8_t status;
cp.type = BDADDR_BREDR;
android2bdaddr(cmd->bdaddr, &cp.bdaddr);
- return mgmt_reply(mgmt_if, MGMT_OP_CANCEL_PAIR_DEVICE, adapter.index,
- sizeof(cp), &cp, NULL, NULL, NULL) > 0;
+ if (mgmt_reply(mgmt_if, MGMT_OP_CANCEL_PAIR_DEVICE, adapter.index,
+ sizeof(cp), &cp, NULL, NULL, NULL) > 0)
+ status = HAL_STATUS_SUCCESS;
+ else
+ status = HAL_STATUS_FAILED;
+
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_BOND, status);
}
static void unpair_device_complete(uint8_t status, uint16_t length,
@@ -1992,23 +2073,30 @@ 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 void handle_remove_bond_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_remove_bond *cmd = buf;
+ const struct hal_cmd_remove_bond *cmd = buf;
struct mgmt_cp_unpair_device cp;
+ uint8_t status;
cp.disconnect = 1;
cp.addr.type = BDADDR_BREDR;
android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
- return mgmt_send(mgmt_if, MGMT_OP_UNPAIR_DEVICE, adapter.index,
+ if (mgmt_send(mgmt_if, MGMT_OP_UNPAIR_DEVICE, adapter.index,
sizeof(cp), &cp, unpair_device_complete,
- NULL, NULL) > 0;
+ NULL, NULL) > 0)
+ status = HAL_STATUS_SUCCESS;
+ else
+ status = HAL_STATUS_FAILED;
+
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_REMOVE_BOND, status);
}
-static uint8_t pin_reply(void *buf, uint16_t len)
+static void handle_pin_reply_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_pin_reply *cmd = buf;
+ const struct hal_cmd_pin_reply *cmd = buf;
+ uint8_t status;
bdaddr_t bdaddr;
char addr[18];
@@ -2017,8 +2105,10 @@ static uint8_t pin_reply(void *buf, uint16_t len)
DBG("%s accept %u pin_len %u", addr, cmd->accept, cmd->pin_len);
- if (!cmd->accept && cmd->pin_len)
- return HAL_STATUS_INVALID;
+ if (!cmd->accept && cmd->pin_len) {
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
if (cmd->accept) {
struct mgmt_cp_pin_code_reply rp;
@@ -2031,8 +2121,10 @@ static uint8_t pin_reply(void *buf, uint16_t len)
memcpy(rp.pin_code, cmd->pin_code, rp.pin_len);
if (mgmt_reply(mgmt_if, MGMT_OP_PIN_CODE_REPLY, adapter.index,
- sizeof(rp), &rp, NULL, NULL, NULL) == 0)
- return HAL_STATUS_FAILED;
+ sizeof(rp), &rp, NULL, NULL, NULL) == 0) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
} else {
struct mgmt_cp_pin_code_neg_reply rp;
@@ -2041,11 +2133,15 @@ static uint8_t pin_reply(void *buf, uint16_t len)
if (mgmt_reply(mgmt_if, MGMT_OP_PIN_CODE_NEG_REPLY,
adapter.index, sizeof(rp), &rp,
- NULL, NULL, NULL) == 0)
- return HAL_STATUS_FAILED;
+ NULL, NULL, NULL) == 0) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
}
- return HAL_STATUS_SUCCESS;
+ status = HAL_STATUS_SUCCESS;
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_PIN_REPLY, status);
}
static uint8_t user_confirm_reply(const bdaddr_t *bdaddr, bool accept)
@@ -2102,11 +2198,11 @@ 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 void handle_ssp_reply_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_ssp_reply *cmd = buf;
- uint8_t status;
+ const struct hal_cmd_ssp_reply *cmd = buf;
bdaddr_t bdaddr;
+ uint8_t status;
char addr[18];
/* TODO should parameters sanity be verified here? */
@@ -2133,144 +2229,226 @@ static uint8_t ssp_reply(void *buf, uint16_t len)
break;
}
- return status;
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SSP_REPLY, status);
}
-static uint8_t get_remote_services(void *buf, uint16_t len)
+static void handle_get_remote_services_cmd(const void *buf, uint16_t len)
{
- struct hal_cmd_get_remote_services *cmd = buf;
+ const struct hal_cmd_get_remote_services *cmd = buf;
+ uint8_t status;
bdaddr_t addr;
android2bdaddr(&cmd->bdaddr, &addr);
- return browse_remote_sdp(&addr);
+ status = browse_remote_sdp(&addr);
+
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_SERVICES,
+ status);
}
-void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
+static void handle_enable_cmd(const void *buf, uint16_t len)
{
- uint8_t status = HAL_STATUS_FAILED;
+ uint8_t status;
- switch (opcode) {
- case HAL_OP_ENABLE:
- /* Framework expects all properties to be emitted while
- * enabling adapter */
- get_properties();
+ /* Framework expects all properties to be emitted while
+ * enabling adapter */
+ get_properties();
- if (adapter.current_settings & MGMT_SETTING_POWERED) {
- status = HAL_STATUS_DONE;
- goto error;
- }
+ if (adapter.current_settings & MGMT_SETTING_POWERED) {
+ status = HAL_STATUS_DONE;
+ goto failed;
+ }
- if (!set_mode(MGMT_OP_SET_POWERED, 0x01))
- goto error;
+ if (!set_mode(MGMT_OP_SET_POWERED, 0x01)) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
- break;
- case HAL_OP_DISABLE:
- if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
- status = HAL_STATUS_DONE;
- goto error;
- }
+ status = HAL_STATUS_SUCCESS;
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_ENABLE, status);
+}
- if (!set_mode(MGMT_OP_SET_POWERED, 0x00))
- goto error;
+static void handle_disable_cmd(const void *buf, uint16_t len)
+{
+ uint8_t status;
- break;
- case HAL_OP_GET_ADAPTER_PROPS:
- get_properties();
+ if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
+ status = HAL_STATUS_DONE;
+ goto failed;
+ }
- break;
- case HAL_OP_GET_ADAPTER_PROP:
- if (!get_property(buf, len))
- goto error;
+ if (!set_mode(MGMT_OP_SET_POWERED, 0x00)) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
- break;
- case HAL_OP_SET_ADAPTER_PROP:
- status = set_property(buf, len);
- if (status != HAL_STATUS_SUCCESS && status != HAL_STATUS_DONE)
- goto error;
+ status = HAL_STATUS_SUCCESS;
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DISABLE, status);
+}
- break;
- case HAL_OP_CREATE_BOND:
- if (!create_bond(buf, len))
- goto error;
+static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
+{
+ get_properties();
- break;
- case HAL_OP_CANCEL_BOND:
- if (!cancel_bond(buf, len))
- goto error;
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
+ HAL_STATUS_SUCCESS);
+}
- break;
- case HAL_OP_REMOVE_BOND:
- if (!remove_bond(buf, len))
- goto error;
+static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
+{
+ /* TODO */
- break;
- case HAL_OP_PIN_REPLY:
- status = pin_reply(buf, len);
- if (status != HAL_STATUS_SUCCESS)
- goto error;
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_DEVICE_PROPS,
+ HAL_STATUS_FAILED);
+}
- break;
- case HAL_OP_SSP_REPLY:
- status = ssp_reply(buf, len);
- if (status != HAL_STATUS_SUCCESS)
- goto error;
- break;
- case HAL_OP_START_DISCOVERY:
- if (adapter.discovering) {
- status = HAL_STATUS_DONE;
- goto error;
- }
+static void handle_get_remote_device_prop_cmd(const void *buf, uint16_t len)
+{
+ /* TODO */
- if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
- status = HAL_STATUS_NOT_READY;
- goto error;
- }
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_DEVICE_PROP,
+ 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;
- if (!start_discovery())
- goto error;
+ if (len != sizeof(*cmd) + cmd->len) {
+ error("Invalid set remote device prop cmd (0x%x), terminating",
+ cmd->type);
+ raise(SIGTERM);
+ return;
+ }
+ /* TODO */
+
+ switch (cmd->type) {
+ default:
+ DBG("Unhandled property type 0x%x", cmd->type);
+ status = HAL_STATUS_FAILED;
break;
- case HAL_OP_CANCEL_DISCOVERY:
- if (!adapter.discovering) {
- status = HAL_STATUS_DONE;
- goto error;
- }
+ }
- if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
- status = HAL_STATUS_NOT_READY;
- goto error;
- }
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_REMOTE_DEVICE_PROP,
+ status);
+}
- if (!stop_discovery())
- goto error;
+static void handle_get_remote_service_rec_cmd(const void *buf, uint16_t len)
+{
+ /* TODO */
- break;
- case HAL_OP_GET_REMOTE_SERVICES:
- status = get_remote_services(buf, len);
- if (status != HAL_STATUS_SUCCESS)
- goto error;
- break;
- default:
- DBG("Unhandled command, opcode 0x%x", opcode);
- goto error;
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_SERVICE_REC,
+ HAL_STATUS_FAILED);
+}
+
+static void handle_start_discovery_cmd(const void *buf, uint16_t len)
+{
+ uint8_t status;
+
+ if (adapter.discovering) {
+ status = HAL_STATUS_DONE;
+ goto failed;
}
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, opcode, HAL_STATUS_SUCCESS);
- return;
+ if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
+ status = HAL_STATUS_NOT_READY;
+ goto failed;
+ }
-error:
- error("Error handling command 0x%02x status %u", opcode, status);
+ if (!start_discovery()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, opcode, status);
+ status = HAL_STATUS_SUCCESS;
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_START_DISCOVERY, status);
}
+static void handle_cancel_discovery_cmd(const void *buf, uint16_t len)
+{
+ uint8_t status;
+
+ if (!adapter.discovering) {
+ status = HAL_STATUS_DONE;
+ goto failed;
+ }
+
+ if (!(adapter.current_settings & MGMT_SETTING_POWERED)) {
+ status = HAL_STATUS_NOT_READY;
+ goto failed;
+ }
+
+ if (!stop_discovery()) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_DISCOVERY, status);
+}
+
+static const struct ipc_handler cmd_handlers[] = {
+ /* HAL_OP_ENABLE */
+ { handle_enable_cmd, false, 0 },
+ /* HAL_OP_DISABLE */
+ { handle_disable_cmd, false, 0 },
+ /* HAL_OP_GET_ADAPTER_PROPS */
+ { handle_get_adapter_props_cmd, false, 0 },
+ /* HAL_OP_GET_ADAPTER_PROP */
+ { handle_get_adapter_prop_cmd, false,
+ sizeof(struct hal_cmd_get_adapter_prop) },
+ /* HAL_OP_SET_ADAPTER_PROP */
+ { handle_set_adapter_prop_cmd, true,
+ sizeof(struct hal_cmd_set_adapter_prop) },
+ /* HAL_OP_GET_REMOTE_DEVICE_PROPS */
+ { handle_get_remote_device_props_cmd, false,
+ sizeof(struct hal_cmd_get_remote_device_props) },
+ /* HAL_OP_GET_REMOTE_DEVICE_PROP */
+ { handle_get_remote_device_prop_cmd, false,
+ sizeof(struct hal_cmd_get_remote_device_prop) },
+ /* HAL_OP_SET_REMOTE_DEVICE_PROP */
+ { handle_set_remote_device_prop_cmd, true,
+ sizeof(struct hal_cmd_set_remote_device_prop) },
+ /* HAL_OP_GET_REMOTE_SERVICE_REC */
+ { handle_get_remote_service_rec_cmd, false,
+ sizeof(struct hal_cmd_get_remote_service_rec) },
+ /* HAL_OP_GET_REMOTE_SERVICES */
+ { handle_get_remote_services_cmd, false,
+ sizeof(struct hal_cmd_get_remote_services) },
+ /* HAL_OP_START_DISCOVERY */
+ { handle_start_discovery_cmd, false, 0 },
+ /* HAL_OP_CANCEL_DISCOVERY */
+ { handle_cancel_discovery_cmd, false, 0 },
+ /* HAL_OP_CREATE_BOND */
+ { handle_create_bond_cmd, false, sizeof(struct hal_cmd_create_bond) },
+ /* HAL_OP_REMOVE_BOND */
+ { handle_remove_bond_cmd, false, sizeof(struct hal_cmd_remove_bond) },
+ /* HAL_OP_CANCEL_BOND */
+ {handle_cancel_bond_cmd, false, sizeof(struct hal_cmd_cancel_bond) },
+ /* HAL_OP_PIN_REPLY */
+ { handle_pin_reply_cmd, false, sizeof(struct hal_cmd_pin_reply) },
+ /* HAL_OP_SSP_REPLY */
+ { handle_ssp_reply_cmd, false, sizeof(struct hal_cmd_ssp_reply) },
+};
+
void bt_bluetooth_register(void)
{
DBG("");
+
+ ipc_register(HAL_SERVICE_ID_BLUETOOTH, cmd_handlers,
+ sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
}
void bt_bluetooth_unregister(void)
{
DBG("");
+
+ ipc_unregister(HAL_SERVICE_ID_CORE);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH v3 3/9] android/main: Use common exit path in core service functions
From: Szymon Janc @ 2013-12-02 12:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385986848-8023-1-git-send-email-szymon.janc@tieto.com>
This makes functions exit path simpler.
---
android/main.c | 40 +++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)
diff --git a/android/main.c b/android/main.c
index 0816ec7..c0f8901 100644
--- a/android/main.c
+++ b/android/main.c
@@ -77,9 +77,12 @@ static bool services[HAL_SERVICE_ID_MAX + 1] = { false };
static void service_register(const void *buf, uint16_t len)
{
const struct hal_cmd_register_module *m = buf;
+ uint8_t status;
- if (m->service_id > HAL_SERVICE_ID_MAX || services[m->service_id])
+ if (m->service_id > HAL_SERVICE_ID_MAX || services[m->service_id]) {
+ status = HAL_STATUS_FAILED;
goto failed;
+ }
switch (m->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
@@ -91,43 +94,51 @@ static void service_register(const void *buf, uint16_t len)
break;
case HAL_SERVICE_ID_HIDHOST:
- if (!bt_hid_register(&adapter_bdaddr))
+ if (!bt_hid_register(&adapter_bdaddr)) {
+ status = HAL_STATUS_FAILED;
goto failed;
+ }
break;
case HAL_SERVICE_ID_A2DP:
- if (!bt_a2dp_register(&adapter_bdaddr))
+ if (!bt_a2dp_register(&adapter_bdaddr)) {
+ status = HAL_STATUS_FAILED;
goto failed;
+ }
break;
case HAL_SERVICE_ID_PAN:
- if (!bt_pan_register(&adapter_bdaddr))
+ if (!bt_pan_register(&adapter_bdaddr)) {
+ status = HAL_STATUS_FAILED;
goto failed;
+ }
break;
default:
DBG("service %u not supported", m->service_id);
+ status = HAL_STATUS_FAILED;
goto failed;
}
services[m->service_id] = true;
- ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
- HAL_STATUS_SUCCESS);
+ status = HAL_STATUS_SUCCESS;
info("Service ID=%u registered", m->service_id);
- return;
+
failed:
- ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE, status);
}
static void service_unregister(const void *buf, uint16_t len)
{
const struct hal_cmd_unregister_module *m = buf;
+ uint8_t status;
- if (m->service_id > HAL_SERVICE_ID_MAX || !services[m->service_id])
+ if (m->service_id > HAL_SERVICE_ID_MAX || !services[m->service_id]) {
+ status = HAL_STATUS_FAILED;
goto failed;
+ }
switch (m->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
@@ -149,19 +160,18 @@ static void service_unregister(const void *buf, uint16_t len)
/* This would indicate bug in HAL, as unregister should not be
* called in init failed */
DBG("service %u not supported", m->service_id);
+ status = HAL_STATUS_FAILED;
goto failed;
}
services[m->service_id] = false;
- ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE,
- HAL_STATUS_SUCCESS);
+ status = HAL_STATUS_SUCCESS;
info("Service ID=%u unregistered", m->service_id);
- return;
+
failed:
- ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE, status);
}
static const struct ipc_handler cmd_handlers[] = {
--
1.8.3.2
^ permalink raw reply related
* [PATCH v3 2/9] android/main: Use generic IPC message handling for core service
From: Szymon Janc @ 2013-12-02 12:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385986848-8023-1-git-send-email-szymon.janc@tieto.com>
Handlers are registered on daemon start and unregistered on shutdown.
---
android/main.c | 83 +++++++++++-----------------------------------------------
1 file changed, 16 insertions(+), 67 deletions(-)
diff --git a/android/main.c b/android/main.c
index eedca58..0816ec7 100644
--- a/android/main.c
+++ b/android/main.c
@@ -74,9 +74,9 @@ 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(const void *buf, uint16_t len)
{
- struct hal_cmd_register_module *m = buf;
+ const struct hal_cmd_register_module *m = buf;
if (m->service_id > HAL_SERVICE_ID_MAX || services[m->service_id])
goto failed;
@@ -122,9 +122,9 @@ failed:
HAL_STATUS_FAILED);
}
-static void service_unregister(void *buf, uint16_t len)
+static void service_unregister(const void *buf, uint16_t len)
{
- struct hal_cmd_unregister_module *m = buf;
+ const struct hal_cmd_unregister_module *m = buf;
if (m->service_id > HAL_SERVICE_ID_MAX || !services[m->service_id])
goto failed;
@@ -164,20 +164,12 @@ failed:
HAL_STATUS_FAILED);
}
-static void handle_service_core(uint8_t opcode, void *buf, uint16_t len)
-{
- switch (opcode) {
- case HAL_OP_REGISTER_MODULE:
- service_register(buf, len);
- break;
- case HAL_OP_UNREGISTER_MODULE:
- service_unregister(buf, len);
- break;
- default:
- ipc_send_rsp(HAL_SERVICE_ID_CORE, opcode, HAL_STATUS_FAILED);
- break;
- }
-}
+static const struct ipc_handler cmd_handlers[] = {
+ /* HAL_OP_REGISTER_MODULE */
+ { service_register, false, sizeof(struct hal_cmd_register_module) },
+ /* HAL_OP_UNREGISTER_MODULE */
+ { service_unregister, false, sizeof(struct hal_cmd_unregister_module) },
+};
static void bluetooth_stopped(void)
{
@@ -211,7 +203,6 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
char buf[BLUEZ_HAL_MTU];
- struct hal_hdr *msg = (void *) buf;
ssize_t ret;
int fd;
@@ -229,51 +220,7 @@ 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);
- goto fail;
- }
-
- DBG("service_id %u opcode %u len %u", msg->service_id, msg->opcode,
- msg->len);
-
- if (msg->service_id > HAL_SERVICE_ID_MAX ||
- !services[msg->service_id]) {
- error("HAL command for unregistered service %u, terminating",
- msg->service_id);
- goto fail;
- }
-
- switch (msg->service_id) {
- case HAL_SERVICE_ID_CORE:
- handle_service_core(msg->opcode, msg->payload, msg->len);
- break;
- case HAL_SERVICE_ID_BLUETOOTH:
- bt_bluetooth_handle_cmd(fd, msg->opcode, msg->payload,
- msg->len);
- break;
- case HAL_SERVICE_ID_HIDHOST:
- bt_hid_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
- break;
- case HAL_SERVICE_ID_SOCK:
- bt_sock_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
- break;
- case HAL_SERVICE_ID_A2DP:
- bt_a2dp_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
- break;
- case HAL_SERVICE_ID_PAN:
- bt_pan_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
- break;
- default:
- ipc_send_rsp(msg->service_id, msg->opcode, HAL_STATUS_FAILED);
- break;
- }
-
+ ipc_handle_msg(buf, ret);
return TRUE;
fail:
@@ -568,9 +515,6 @@ int main(int argc, char *argv[])
GError *err = NULL;
guint signal;
- /* Core Service (ID=0) should always be considered registered */
- services[0] = true;
-
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, options, NULL);
@@ -622,6 +566,9 @@ int main(int argc, char *argv[])
/* Use params: mtu = 0, flags = 0 */
start_sdp_server(0, 0);
+ ipc_register(HAL_SERVICE_ID_CORE, cmd_handlers,
+ sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
+
DBG("Entering main loop");
event_loop = g_main_loop_new(NULL, FALSE);
@@ -640,6 +587,8 @@ int main(int argc, char *argv[])
bt_bluetooth_cleanup();
g_main_loop_unref(event_loop);
+ ipc_unregister(HAL_SERVICE_ID_CORE);
+
info("Exit");
__btd_log_cleanup();
--
1.8.3.2
^ permalink raw reply related
* [PATCH v3 1/9] android: Add initial code for IPC message handlers
From: Szymon Janc @ 2013-12-02 12:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385986848-8023-1-git-send-email-szymon.janc@tieto.com>
This will allow to register and unregister handlers for IPC messages
Basic sanity check will be done in common code. Commands with variable
length will be verified against minimum size only.
---
android/ipc.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
android/ipc.h | 10 ++++++++
2 files changed, 88 insertions(+)
diff --git a/android/ipc.c b/android/ipc.c
index 64b0db5..56f328b 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -30,12 +30,20 @@
#include <stdint.h>
#include <string.h>
#include <signal.h>
+#include <stdbool.h>
#include <sys/socket.h>
#include "hal-msg.h"
#include "ipc.h"
#include "log.h"
+struct service_handler {
+ const struct ipc_handler *handler;
+ uint8_t size;
+};
+
+static struct service_handler services[HAL_SERVICE_ID_MAX + 1];
+
static int cmd_sk = -1;
static int notif_sk = -1;
@@ -124,3 +132,73 @@ void ipc_send_notif(uint8_t service_id, uint8_t opcode, uint16_t len,
ipc_send(notif_sk, service_id, opcode, len, param, -1);
}
+
+void ipc_register(uint8_t service, const struct ipc_handler *handlers,
+ uint8_t size)
+{
+ services[service].handler = handlers;
+ services[service].size = size;
+}
+
+void ipc_unregister(uint8_t service)
+{
+ services[service].handler = NULL;
+ services[service].size = 0;
+}
+
+void ipc_handle_msg(const void *buf, ssize_t len)
+{
+ const struct hal_hdr *msg = buf;
+ const struct ipc_handler *handler;
+
+ if (len < (ssize_t) sizeof(*msg)) {
+ error("IPC: message too small (%zd bytes), terminating", len);
+ raise(SIGTERM);
+ return;
+ }
+
+ if (len != (ssize_t) (sizeof(*msg) + msg->len)) {
+ error("IPC: message malformed (%zd bytes), terminating", len);
+ raise(SIGTERM);
+ return;
+ }
+
+ /* if service is valid */
+ if (msg->service_id > HAL_SERVICE_ID_MAX) {
+ error("IPC: unknown service (0x%x), terminating",
+ msg->service_id);
+ raise(SIGTERM);
+ return;
+ }
+
+ /* if service is registered */
+ if (!services[msg->service_id].handler) {
+ error("IPC: unregistered service (0x%x), terminating",
+ msg->service_id);
+ raise(SIGTERM);
+ return;
+ }
+
+ /* if opcode is valid */
+ if (msg->opcode == HAL_OP_STATUS ||
+ msg->opcode > services[msg->service_id].size) {
+ error("IPC: invalid opcode 0x%x for service 0x%x, terminating",
+ msg->opcode, msg->service_id);
+ raise(SIGTERM);
+ return;
+ }
+
+ /* opcode is table offset + 1 */
+ handler = &services[msg->service_id].handler[msg->opcode - 1];
+
+ /* if payload size is valid */
+ if ((handler->var_len && handler->data_len > msg->len) ||
+ (!handler->var_len && handler->data_len != msg->len)) {
+ error("IPC: size invalid opcode 0x%x service 0x%x, terminating",
+ msg->service_id, msg->opcode);
+ raise(SIGTERM);
+ return;
+ }
+
+ handler->handler(msg->payload, msg->len);
+}
diff --git a/android/ipc.h b/android/ipc.h
index f66c9e0..9d0c5e1 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -21,6 +21,11 @@
*
*/
+struct ipc_handler {
+ void (*handler) (const void *buf, uint16_t len);
+ bool var_len;
+ size_t data_len;
+};
void ipc_init(int command_sk, int notification_sk);
void ipc_cleanup(void);
@@ -29,3 +34,8 @@ void ipc_send_rsp_full(uint8_t service_id, uint8_t opcode, uint16_t len,
void *param, int fd);
void ipc_send_notif(uint8_t service_id, uint8_t opcode, uint16_t len,
void *param);
+void ipc_register(uint8_t service, const struct ipc_handler *handlers,
+ uint8_t size);
+void ipc_unregister(uint8_t service);
+
+void ipc_handle_msg(const void *buf, ssize_t len);
--
1.8.3.2
^ permalink raw reply related
* [PATCH v3 0/9] android: IPC improvements - daemon part
From: Szymon Janc @ 2013-12-02 12:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
v3:
- rebased againt latest pan changes
v2:
- rebased against latest IPC helpers improvements
- more compact command handlers table format
- error handling path in command handlers improved according to Johan comments
- randmon small fixes
- patches not directly related to refactor removed from serie, will
be send after this is merged
v1:
This serie implements IPC message handling iprovments in daemon similar
to what is already done in HAL part.
Szymon Janc (9):
android: Add initial code for IPC message handlers
android/main: Use generic IPC message handling for core service
android/main: Use common exit path in core service functions
android/bluetooth: Use generic IPC msg handling for commands
android/bluetooth: Make property handling function return HAL status
android/hidhost: Use generic IPC message handling for commands
android/pan: Use generic IPC message handling for commands
android/a2dp: Use generic IPC message handling for commands
android/socket: Use generic IPC message handling for commands
android/a2dp.c | 69 ++++----
android/a2dp.h | 2 -
android/bluetooth.c | 477 ++++++++++++++++++++++++++++++++++------------------
android/hidhost.c | 309 ++++++++++++++++++++--------------
android/hidhost.h | 2 -
android/ipc.c | 78 +++++++++
android/ipc.h | 10 ++
android/main.c | 123 +++++---------
android/pan.c | 87 +++++-----
android/pan.h | 2 -
android/socket.c | 102 ++++++-----
11 files changed, 754 insertions(+), 507 deletions(-)
--
1.8.3.2
^ permalink raw reply
* Re: [PATCH 0/2] Bluetooth: A couple of SMP fixes
From: Marcel Holtmann @ 2013-12-02 11:23 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1385974144-8836-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> Here are a couple of small tweaks to the SMP code that I've found while
> browsing through and testing it (with the user space smp-tester).
>
> Johan
>
> Johan Hedberg (2):
> Bluetooth: Remove useless smp_rand function
> Bluetooth: Remove dead code from SMP encryption function
>
> net/bluetooth/smp.c | 24 +++---------------------
> 1 file changed, 3 insertions(+), 21 deletions(-)
both patches have been applied to bluetooth-next.
Regards
Marcel
^ permalink raw reply
* [PATCH 2/2] Bluetooth: Remove dead code from SMP encryption function
From: johan.hedberg @ 2013-12-02 8:49 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385974144-8836-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
The AES cipher is used in ECB mode by SMP and therefore doesn't use an
IV (crypto_blkcipher_ivsize returns 0) so the code trying to set the IV
was never getting called. Simply remove this code to avoid anyone from
thinking it actually makes some difference.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/smp.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 3bcb765b6a92..e61e74a1aabb 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -53,8 +53,7 @@ static int smp_e(struct crypto_blkcipher *tfm, const u8 *k, u8 *r)
{
struct blkcipher_desc desc;
struct scatterlist sg;
- int err, iv_len;
- unsigned char iv[128];
+ int err;
if (tfm == NULL) {
BT_ERR("tfm %p", tfm);
@@ -72,12 +71,6 @@ static int smp_e(struct crypto_blkcipher *tfm, const u8 *k, u8 *r)
sg_init_one(&sg, r, 16);
- iv_len = crypto_blkcipher_ivsize(tfm);
- if (iv_len) {
- memset(&iv, 0xff, iv_len);
- crypto_blkcipher_set_iv(tfm, iv, iv_len);
- }
-
err = crypto_blkcipher_encrypt(&desc, &sg, &sg, 16);
if (err)
BT_ERR("Encrypt data error %d", err);
--
1.8.4.2
^ permalink raw reply related
* [PATCH 1/2] Bluetooth: Remove useless smp_rand function
From: johan.hedberg @ 2013-12-02 8:49 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385974144-8836-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This function was always just making a single get_random_bytes() call
and always returning the value 0. It's simpler to just call
get_random_bytes() directly where needed.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/smp.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index f99352d1aa43..3bcb765b6a92 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -143,13 +143,6 @@ static int smp_s1(struct crypto_blkcipher *tfm, u8 k[16], u8 r1[16],
return err;
}
-static int smp_rand(u8 *buf)
-{
- get_random_bytes(buf, 16);
-
- return 0;
-}
-
static struct sk_buff *smp_build_cmd(struct l2cap_conn *conn, u8 code,
u16 dlen, void *data)
{
@@ -606,9 +599,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
if (check_enc_key_size(conn, key_size))
return SMP_ENC_KEY_SIZE;
- ret = smp_rand(smp->prnd);
- if (ret)
- return SMP_UNSPECIFIED;
+ get_random_bytes(smp->prnd, sizeof(smp->prnd));
smp->prsp[0] = SMP_CMD_PAIRING_RSP;
memcpy(&smp->prsp[1], &rsp, sizeof(rsp));
@@ -644,9 +635,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
if (check_enc_key_size(conn, key_size))
return SMP_ENC_KEY_SIZE;
- ret = smp_rand(smp->prnd);
- if (ret)
- return SMP_UNSPECIFIED;
+ get_random_bytes(smp->prnd, sizeof(smp->prnd));
smp->prsp[0] = SMP_CMD_PAIRING_RSP;
memcpy(&smp->prsp[1], rsp, sizeof(*rsp));
--
1.8.4.2
^ permalink raw reply related
* [PATCH 0/2] Bluetooth: A couple of SMP fixes
From: johan.hedberg @ 2013-12-02 8:49 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
Hi,
Here are a couple of small tweaks to the SMP code that I've found while
browsing through and testing it (with the user space smp-tester).
Johan
Johan Hedberg (2):
Bluetooth: Remove useless smp_rand function
Bluetooth: Remove dead code from SMP encryption function
net/bluetooth/smp.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
--
1.8.4.2
^ permalink raw reply
* Re: have to re-pair mouse every few hours
From: Brian J. Murrell @ 2013-12-01 22:44 UTC (permalink / raw)
To: Bastien Nocera; +Cc: linux-bluetooth
In-Reply-To: <1385937507.5405.5.camel@nuvo>
[-- Attachment #1: Type: text/plain, Size: 629 bytes --]
On Sun, 2013-12-01 at 23:38 +0100, Bastien Nocera wrote:
>
> You could try with a LiveCD.
I don't think a LiveCD would be a useful enough work environment for me
to use long enough to see the problem occur. It has happened within
minutes once or twice but typically it can take several hours. This
afternoon has actually been quite good a quite a few hours.
I don't know that there is enough useful stuff for me to do (without a
whole ton of configuring self preferences) in a livecd environment for
me to keep using it for hours. Probably upgrading to F20 is the most
productive way to see.
Cheers,
b.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply
* Re: have to re-pair mouse every few hours
From: Bastien Nocera @ 2013-12-01 22:38 UTC (permalink / raw)
To: Brian J. Murrell; +Cc: linux-bluetooth
In-Reply-To: <1385937375.12122.118.camel@pc.interlinx.bc.ca>
On Sun, 2013-12-01 at 17:36 -0500, Brian J. Murrell wrote:
> On Sun, 2013-12-01 at 23:28 +0100, Bastien Nocera wrote:
> > Hey Brian,
>
> Hi Bastien,
>
> > Upstream developers don't work on BlueZ 4.x anymore. Any chance for you
> > to test using Fedora 20?
>
> Hrm. Scheduling an upgrade, complete with back-out path here is bit of
> work. I will see what I can do. But for F19 I guess I am just stuck
> with this frustrating behavior? :-(
You could try with a LiveCD.
> > It uses BlueZ 5.x which has a lot of fixes and
> > architectural changes compared to 4.x.
>
> Interesting to know.
>
> Cheers,
> b.
>
^ permalink raw reply
* Re: have to re-pair mouse every few hours
From: Brian J. Murrell @ 2013-12-01 22:36 UTC (permalink / raw)
To: Bastien Nocera; +Cc: linux-bluetooth
In-Reply-To: <1385936884.5405.3.camel@nuvo>
[-- Attachment #1: Type: text/plain, Size: 512 bytes --]
On Sun, 2013-12-01 at 23:28 +0100, Bastien Nocera wrote:
> Hey Brian,
Hi Bastien,
> Upstream developers don't work on BlueZ 4.x anymore. Any chance for you
> to test using Fedora 20?
Hrm. Scheduling an upgrade, complete with back-out path here is bit of
work. I will see what I can do. But for F19 I guess I am just stuck
with this frustrating behavior? :-(
> It uses BlueZ 5.x which has a lot of fixes and
> architectural changes compared to 4.x.
Interesting to know.
Cheers,
b.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply
* Re: have to re-pair mouse every few hours
From: Bastien Nocera @ 2013-12-01 22:28 UTC (permalink / raw)
To: Brian J. Murrell; +Cc: linux-bluetooth
In-Reply-To: <1385843856.12122.5.camel@pc.interlinx.bc.ca>
Hey Brian,
On Sat, 2013-11-30 at 15:37 -0500, Brian J. Murrell wrote:
> Hi,
>
> I'm using a Microsoft Sculpt Touch Mouse on a Fedora 19 machine
> (kernel-3.11.9-200.fc19.x86_64 and bluez-4.101-9.fc19.x86_64) with a:
>
> Bus 002 Device 019: ID 0a5c:2148 Broadcom Corp. BCM92046DG-CL1ROM Bluetooth 2.1 Adapter
>
> bluetooth adapter. This exact same configuration worked for months just
> fine with a Logitech bluetooth mouse. But sadly that mouse was crap
> (second one to fail within the warranty period of one of them) so
> replaced it with this MS one.
>
> The problem with this MS mouse is that it just goes AWOL and needs to be
> delete and re-paired with the machine every few hours. Typically it's
> after I have gotten up from the computer and have come back to it. But
> I have also had it just happen while using it.
>
> When this happens, the messages log reports messages such as:
>
> Nov 30 12:42:03 pc kernel: [2500032.028982] Bluetooth: Unexpected continuation frame (len 0)
> Nov 30 12:42:03 pc kernel: [2500032.115027] Bluetooth: Unexpected continuation frame (len 0)
>
> Any ideas what the problem might be here?
Upstream developers don't work on BlueZ 4.x anymore. Any chance for you
to test using Fedora 20? It uses BlueZ 5.x which has a lot of fixes and
architectural changes compared to 4.x.
Cheers
^ permalink raw reply
* Add empty udev rule to disable hid2hci by default
From: Alexander Holler @ 2013-12-01 17:26 UTC (permalink / raw)
To: linux-bluetooth
Hello.
Almost every distribution gets it wrong and enables hid2hci by default
(besides Fedora where I already intervened twice).
This is a real problem, because it disables Bluetooth keyboards and/or
mice which aren't paired with bluez, thus many Live-CDs and default
installs aren't usable when only a Bluetooth keyboard is connect.
An easy solution to disable that behaviour would be to install an empty
rule in /etc/udev/rules.d named the same as the one in
/lib/udev/rules.d. It could just contain a comment like
# Delete this file in order to activate hid2hci.
#
# You might need to pair your Bluetooth keyboard and/or mouse
# in order to still use it when hid2hci is enabled.
This (empty) rule would then be used by udev instead of the one in
/lib/udev/rules.d and thus would be an easy to use configuration switch.
I would appreciate it, if the default bluez install would install such
an empty rule too, if configure was called with --enable-hid2hci.
I think otherwise that problem will never go away. It's really
unbelievable how many distributions got this wrong and thus how many
Live-CDs and default installations are unusable when only a Bluetooth
keyboard is used with a hid-aware Bluetooth dongle.
Regards,
Alexander Holler
^ permalink raw reply
* [PATCH 4/4] sixaxis: Add support for setting LEDs when connected over USB
From: Szymon Janc @ 2013-12-01 13:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385905316-21800-1-git-send-email-szymon.janc@gmail.com>
This allows to setup LEDs when device is connected over USB, not
Bluetooth. This coverts two scenarios:
- user plugged PS3 controller and pressed PS3 button before unplugging,
in that case LEDs are set
- user plugged already BT connected PS3 controller to USB, this results
in new /dev/input/jsX device being create but controller is still
transmitting over BT and old jsX device exists. In that case don't
set LEDs as they are already set.
This is not directly related to Bluetooth itself but change is really
small and provides much better and consistent user experience.
---
plugins/sixaxis.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index b8fe287..45fa170 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -181,7 +181,7 @@ static gboolean setup_leds(GIOChannel *channel, GIOCondition cond,
return FALSE;
}
-static void setup_device(int fd, int index, struct btd_adapter *adapter)
+static bool setup_device(int fd, int index, struct btd_adapter *adapter)
{
char device_addr[18], master_addr[18], adapter_addr[18];
bdaddr_t device_bdaddr, master_bdaddr;
@@ -189,22 +189,23 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
struct btd_device *device;
if (get_device_bdaddr(fd, &device_bdaddr) < 0)
- return;
+ return false;
if (get_master_bdaddr(fd, &master_bdaddr) < 0)
- return;
+ return false;
/* This can happen if controller was plugged while already connected
- * eg. to charge up battery */
+ * eg. to charge up battery.
+ * Don't set LEDs in that case, hence return false */
device = btd_adapter_find_device(adapter, &device_bdaddr);
if (device && btd_device_is_connected(device))
- return;
+ return false;
adapter_bdaddr = btd_adapter_get_address(adapter);
if (bacmp(adapter_bdaddr, &master_bdaddr)) {
if (set_master_bdaddr(fd, adapter_bdaddr) < 0)
- return;
+ return false;
}
ba2str(&device_bdaddr, device_addr);
@@ -218,7 +219,7 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
if (g_slist_find_custom(btd_device_get_uuids(device), HID_UUID,
(GCompareFunc)strcasecmp)) {
DBG("device %s already known, skipping", device_addr);
- return;
+ return true;
}
info("sixaxis: setting up new device");
@@ -228,6 +229,8 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
devices[index].pid, devices[index].version);
btd_device_set_temporary(device, FALSE);
btd_device_set_trusted(device, TRUE);
+
+ return true;
}
static int get_js_number(struct udev_device *udevice)
@@ -346,8 +349,10 @@ static void device_added(struct udev_device *udevice)
switch (bus) {
case BUS_USB:
- setup_device(fd, index, adapter);
- break;
+ if (!setup_device(fd, index, adapter))
+ break;
+
+ /* fall through */
case BUS_BLUETOOTH:
/* wait for events before setting leds */
g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
--
1.8.5
^ permalink raw reply related
* [PATCH 3/4] sixaxis: Skip controller setup if already connected over Bluetooth
From: Szymon Janc @ 2013-12-01 13:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385905316-21800-1-git-send-email-szymon.janc@gmail.com>
If controller is already connected over Bluetooth but was then
plugged-in via USB (eg. to charge battery) there is no need to do
any setup.
---
plugins/sixaxis.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index c3ca267..b8fe287 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -194,6 +194,12 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
if (get_master_bdaddr(fd, &master_bdaddr) < 0)
return;
+ /* This can happen if controller was plugged while already connected
+ * eg. to charge up battery */
+ device = btd_adapter_find_device(adapter, &device_bdaddr);
+ if (device && btd_device_is_connected(device))
+ return;
+
adapter_bdaddr = btd_adapter_get_address(adapter);
if (bacmp(adapter_bdaddr, &master_bdaddr)) {
--
1.8.5
^ permalink raw reply related
* [PATCH 2/4] Rename device_is_connected to btd_device_is_connected
From: Szymon Janc @ 2013-12-01 13:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385905316-21800-1-git-send-email-szymon.janc@gmail.com>
Allow this symbol to be exported and usable from external plugins.
---
profiles/input/device.c | 4 ++--
src/adapter.c | 6 +++---
src/device.c | 6 +++---
src/device.h | 2 +-
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 0c2089b..521aca8 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -667,7 +667,7 @@ static gboolean input_device_auto_reconnect(gpointer user_data)
/* Stop the recurrent reconnection attempts if the device is reconnected
* or is marked for removal. */
if (device_is_temporary(idev->device) ||
- device_is_connected(idev->device))
+ btd_device_is_connected(idev->device))
return FALSE;
/* Only attempt an auto-reconnect for at most 3 minutes (6 * 30s). */
@@ -713,7 +713,7 @@ static void input_device_enter_reconnect_mode(struct input_device *idev)
/* If the device is temporary we are not required to reconnect with the
* device. This is likely the case of a removing device. */
if (device_is_temporary(idev->device) ||
- device_is_connected(idev->device))
+ btd_device_is_connected(idev->device))
return;
if (idev->reconnect_timer > 0)
diff --git a/src/adapter.c b/src/adapter.c
index 55a41db..41f7bd6 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2158,7 +2158,7 @@ static DBusMessage *remove_device(DBusConnection *conn,
btd_device_set_temporary(device, TRUE);
- if (!device_is_connected(device)) {
+ if (!btd_device_is_connected(device)) {
adapter_remove_device(adapter, device);
return dbus_message_new_method_return(msg);
}
@@ -4195,7 +4195,7 @@ connect_le:
* connect_list stop passive scanning so that a connection
* attempt to it can be made
*/
- if (device_is_le(dev) && !device_is_connected(dev) &&
+ if (device_is_le(dev) && !btd_device_is_connected(dev) &&
g_slist_find(adapter->connect_list, dev)) {
adapter->connect_le = dev;
stop_passive_scanning(adapter);
@@ -5865,7 +5865,7 @@ static void unpaired_callback(uint16_t index, uint16_t length,
btd_device_set_temporary(device, TRUE);
- if (device_is_connected(device))
+ if (btd_device_is_connected(device))
device_request_disconnect(device, NULL);
else
adapter_remove_device(adapter, device);
diff --git a/src/device.c b/src/device.c
index 847ffad..5380c1a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1355,7 +1355,7 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,
if (device_is_le(dev)) {
int err;
- if (device_is_connected(dev))
+ if (btd_device_is_connected(dev))
return dbus_message_new_method_return(msg);
btd_device_set_temporary(dev, FALSE);
@@ -1645,7 +1645,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
* channel first and only then start pairing (there's code for
* this in the ATT connect callback)
*/
- if (device_is_le(device) && !device_is_connected(device))
+ if (device_is_le(device) && !btd_device_is_connected(device))
err = device_connect_le(device);
else
err = adapter_create_bonding(adapter, &device->bdaddr,
@@ -1791,7 +1791,7 @@ static const GDBusPropertyTable device_properties[] = {
{ }
};
-gboolean device_is_connected(struct btd_device *device)
+gboolean btd_device_is_connected(struct btd_device *device)
{
return device->connected;
}
diff --git a/src/device.h b/src/device.h
index c3fea4a..3a33cb2 100644
--- a/src/device.h
+++ b/src/device.h
@@ -74,7 +74,7 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted);
void device_set_bonded(struct btd_device *device, gboolean bonded);
void device_set_legacy(struct btd_device *device, bool legacy);
void device_set_rssi(struct btd_device *device, int8_t rssi);
-gboolean device_is_connected(struct btd_device *device);
+gboolean btd_device_is_connected(struct btd_device *device);
bool device_is_retrying(struct btd_device *device);
void device_bonding_complete(struct btd_device *device, uint8_t status);
gboolean device_is_bonding(struct btd_device *device, const char *sender);
--
1.8.5
^ permalink raw reply related
* [PATCH 1/4] sixaxis: Add support for setting PS3 controller LEDs
From: Szymon Janc @ 2013-12-01 13:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385905316-21800-1-git-send-email-szymon.janc@gmail.com>
This will set controller LEDs according to joystick device number
when controller is connected over Bluetooth. If joystick number is too
big (> 7) or falied to be read, set it to 0 to switch off all LEDs.
This will allow to disable LEDs blinking after connection.
Waiting for events is not really needed when connected over Bluetooth
but this is in preparation for supporting LEDs setup over USB.
---
plugins/sixaxis.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 139 insertions(+), 2 deletions(-)
diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index 070b463..c3ca267 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/hidraw.h>
#include <linux/input.h>
@@ -124,6 +125,62 @@ static int set_master_bdaddr(int fd, const bdaddr_t *bdaddr)
return ret;
}
+static gboolean setup_leds(GIOChannel *channel, GIOCondition cond,
+ gpointer user_data)
+{
+ /*
+ * the total time the led is active (0xff means forever)
+ * | duty_length: cycle time in deciseconds (0 - "blink very fast")
+ * | | ??? (Maybe a phase shift or duty_length multiplier?)
+ * | | | % of duty_length led is off (0xff means 100%)
+ * | | | | % of duty_length led is on (0xff means 100%)
+ * | | | | |
+ * 0xff, 0x27, 0x10, 0x00, 0x32,
+ */
+ uint8_t leds_report[] = {
+ 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, /* rumble values TBD */
+ 0x00, 0x00, 0x00, 0x00, 0x00, /* LED_1=0x02, LED_2=0x04 ... */
+ 0xff, 0x27, 0x10, 0x00, 0x32, /* LED_4 */
+ 0xff, 0x27, 0x10, 0x00, 0x32, /* LED_3 */
+ 0xff, 0x27, 0x10, 0x00, 0x32, /* LED_2 */
+ 0xff, 0x27, 0x10, 0x00, 0x32, /* LED_1 */
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+ int number = GPOINTER_TO_INT(user_data);
+ int ret;
+ int fd;
+
+ if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
+ return FALSE;
+
+ DBG("number %d", number);
+
+ /* TODO we could support up to 10 (1 + 2 + 3 + 4) */
+ if (number > 7)
+ return FALSE;
+
+ if (number > 4) {
+ leds_report[10] |= 0x10;
+ number -= 4;
+ }
+
+ leds_report[10] |= 0x01 << number;
+
+ fd = g_io_channel_unix_get_fd(channel);
+
+ ret = write(fd, leds_report, sizeof(leds_report));
+ if (ret == sizeof(leds_report))
+ return FALSE;
+
+ if (ret < 0)
+ error("sixaxis: failed to set LEDS (%s)", strerror(errno));
+ else
+ error("sixaxis: failed to set LEDS (%d bytes written)", ret);
+
+ return FALSE;
+}
+
static void setup_device(int fd, int index, struct btd_adapter *adapter)
{
char device_addr[18], master_addr[18], adapter_addr[18];
@@ -167,6 +224,69 @@ static void setup_device(int fd, int index, struct btd_adapter *adapter)
btd_device_set_trusted(device, TRUE);
}
+static int get_js_number(struct udev_device *udevice)
+{
+ struct udev_list_entry *devices, *dev_list_entry;
+ struct udev_enumerate *enumerate;
+ struct udev_device *hid_parent;
+ const char *hidraw_node;
+ const char *hid_phys;
+ int number = 0;
+
+ hid_parent = udev_device_get_parent_with_subsystem_devtype(udevice,
+ "hid", NULL);
+
+ hid_phys = udev_device_get_property_value(hid_parent, "HID_PHYS");
+ hidraw_node = udev_device_get_devnode(udevice);
+ if (!hid_phys || !hidraw_node)
+ return 0;
+
+ enumerate = udev_enumerate_new(udev_device_get_udev(udevice));
+ udev_enumerate_add_match_sysname(enumerate, "js*");
+ udev_enumerate_scan_devices(enumerate);
+ devices = udev_enumerate_get_list_entry(enumerate);
+
+ udev_list_entry_foreach(dev_list_entry, devices) {
+ struct udev_device *input_parent;
+ struct udev_device *js_dev;
+ const char *input_phys;
+ const char *devname;
+
+ devname = udev_list_entry_get_name(dev_list_entry);
+ js_dev = udev_device_new_from_syspath(
+ udev_device_get_udev(udevice),
+ devname);
+
+ input_parent = udev_device_get_parent_with_subsystem_devtype(
+ js_dev, "input", NULL);
+ if (!input_parent)
+ goto next;
+
+ /* check if this is the joystick relative to the hidraw device
+ * above */
+ input_phys = udev_device_get_sysattr_value(input_parent,
+ "phys");
+ if (!input_phys)
+ goto next;
+
+ if (!strcmp(input_phys, hid_phys)) {
+ number = atoi(udev_device_get_sysnum(js_dev));
+
+ /* joystick numbers start from 0, leds from 1 */
+ number++;
+
+ udev_device_unref(js_dev);
+ break;
+ }
+next:
+ udev_device_unref(js_dev);
+ }
+
+ udev_enumerate_unref(enumerate);
+
+ return number;
+}
+
static int get_supported_device(struct udev_device *udevice, uint16_t *bus)
{
struct udev_device *hid_parent;
@@ -195,6 +315,7 @@ static int get_supported_device(struct udev_device *udevice, uint16_t *bus)
static void device_added(struct udev_device *udevice)
{
struct btd_adapter *adapter;
+ GIOChannel *io;
uint16_t bus;
int index;
int fd;
@@ -215,10 +336,26 @@ static void device_added(struct udev_device *udevice)
if (fd < 0)
return;
- if (bus == BUS_USB)
+ io = g_io_channel_unix_new(fd);
+
+ switch (bus) {
+ case BUS_USB:
setup_device(fd, index, adapter);
+ break;
+ case BUS_BLUETOOTH:
+ /* wait for events before setting leds */
+ g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ setup_leds,
+ GINT_TO_POINTER(get_js_number(udevice)));
+
+ break;
+ default:
+ DBG("uknown bus type (%u)", bus);
+ break;
+ }
- close(fd);
+ g_io_channel_set_close_on_unref(io, TRUE);
+ g_io_channel_unref(io);
}
static gboolean monitor_watch(GIOChannel *source, GIOCondition condition,
--
1.8.5
^ permalink raw reply related
* [PATCH 0/4] more sixaxis goodies
From: Szymon Janc @ 2013-12-01 13:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Hi,
This adds support for setting PS3 controller LEDs both over Bluetooth
and USB. More details in commits messages.
One thing I noticed is that setting LEDs over Bluetooth fails on kernel
3.10+ (write always returns 0). Could this be related to HIDP related
work that was merged in 3.10?
Comments and testing are welcome.
--
BR
Szymon Janc
Szymon Janc (4):
sixaxis: Add support for setting PS3 controller LEDs
Rename device_is_connected to btd_device_is_connected
sixaxis: Skip controller setup if already connected over Bluetooth
sixaxis: Add support for setting LEDs when connected over USB
plugins/sixaxis.c | 164 +++++++++++++++++++++++++++++++++++++++++++++---
profiles/input/device.c | 4 +-
src/adapter.c | 6 +-
src/device.c | 6 +-
src/device.h | 2 +-
5 files changed, 165 insertions(+), 17 deletions(-)
--
1.8.5
^ permalink raw reply
* have to re-pair mouse every few hours
From: Brian J. Murrell @ 2013-11-30 20:37 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 1066 bytes --]
Hi,
I'm using a Microsoft Sculpt Touch Mouse on a Fedora 19 machine
(kernel-3.11.9-200.fc19.x86_64 and bluez-4.101-9.fc19.x86_64) with a:
Bus 002 Device 019: ID 0a5c:2148 Broadcom Corp. BCM92046DG-CL1ROM Bluetooth 2.1 Adapter
bluetooth adapter. This exact same configuration worked for months just
fine with a Logitech bluetooth mouse. But sadly that mouse was crap
(second one to fail within the warranty period of one of them) so
replaced it with this MS one.
The problem with this MS mouse is that it just goes AWOL and needs to be
delete and re-paired with the machine every few hours. Typically it's
after I have gotten up from the computer and have come back to it. But
I have also had it just happen while using it.
When this happens, the messages log reports messages such as:
Nov 30 12:42:03 pc kernel: [2500032.028982] Bluetooth: Unexpected continuation frame (len 0)
Nov 30 12:42:03 pc kernel: [2500032.115027] Bluetooth: Unexpected continuation frame (len 0)
Any ideas what the problem might be here?
Cheers,
b.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply
* Re: [PATCH_v5 0/6] Refactor bnep code and implement pan methods
From: Luiz Augusto von Dentz @ 2013-11-29 15:16 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1385734845-9725-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Fri, Nov 29, 2013 at 4:20 PM, Ravi kumar Veeramally
<ravikumar.veeramally@linux.intel.com> wrote:
> v5: Renamed strcut network_peer to pan_device as per Luiz comments.
>
> v4: Fixed Luiz comments (discussed in irc). Merge patch 1 and 2.
> Pass fd in bnep_connect instead of GIOChannel.
>
> v3: Fixed Anderson and Luiz comments and solved rebased conflicts.
>
> v2: Refactored profiles/network/common.* as per Johan's comments
> (renaming common.c|h to bnep.c|h and moving bnep related code to
> bnep.c ro reduce redundancy in profiles/netowrk/connection.c and
> android/pan.c)
>
> v1: This patch set supports PANU role with a minor fix in android. Added
> CAP_NET_RAW capability for bnep services. Creates bnep connection and
> up the inreface on connect call and free the device on disconnect call.
> Interface name(bnepX) will be notified on control state cb. Android
> environment will create IP address with dhcp calls.
>
> Ravi kumar Veeramally (6):
> profiles/network: Refactor bnep connection setup functionality
> profiles/network: Rename common.c|h to bnep.c|h
> android/pan: Implement pan connect method in daemon
> android/pan: Implement pan disconnect method in daemon
> android/pan: Implement the get local role method in daemon
> android: Add reasons for adding capabilites to process
>
> Makefile.plugins | 2 +-
> android/Android.mk | 2 +
> android/Makefile.am | 3 +-
> android/main.c | 3 +
> android/pan.c | 253 ++++++++++++++++++++++++++++++++--
> profiles/network/{common.c => bnep.c} | 197 +++++++++++++++++++++++++-
> profiles/network/{common.h => bnep.h} | 5 +
> profiles/network/connection.c | 174 ++---------------------
> profiles/network/manager.c | 2 +-
> profiles/network/server.c | 5 +-
> 10 files changed, 468 insertions(+), 178 deletions(-)
> rename profiles/network/{common.c => bnep.c} (58%)
> rename profiles/network/{common.h => bnep.h} (87%)
>
> --
> 1.8.3.2
Applied, please have a look as I renamed a few other things and I
found that we were sending uninitialized data while testing.
--
Luiz Augusto von Dentz
^ permalink raw reply
* [PATCH_v5 6/6] android: Add reasons for adding capabilites to process
From: Ravi kumar Veeramally @ 2013-11-29 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1385734845-9725-1-git-send-email-ravikumar.veeramally@linux.intel.com>
CAP_NET_ADMIN: Allow use of MGMT interface
CAP_NET_BIND_SERVICE: Allow use of privileged PSM
CAP_NET_RAW: Allow use of bnep ioctl calls
---
android/main.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/android/main.c b/android/main.c
index 3a14af5..eedca58 100644
--- a/android/main.c
+++ b/android/main.c
@@ -534,6 +534,9 @@ static bool set_capabilities(void)
header.version = _LINUX_CAPABILITY_VERSION;
header.pid = 0;
+ /* CAP_NET_ADMIN: Allow use of MGMT interface
+ * CAP_NET_BIND_SERVICE: Allow use of privileged PSM
+ * CAP_NET_RAW: Allow use of bnep ioctl calls */
cap.effective = cap.permitted =
CAP_TO_MASK(CAP_NET_RAW) |
CAP_TO_MASK(CAP_NET_ADMIN) |
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v5 5/6] android/pan: Implement the get local role method in daemon
From: Ravi kumar Veeramally @ 2013-11-29 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1385734845-9725-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Returns local role of the device (NONE, PANU or NAP).
---
android/pan.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/android/pan.c b/android/pan.c
index 7093e4c..9ff14f3 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -278,9 +278,15 @@ static uint8_t bt_pan_enable(struct hal_cmd_pan_enable *cmd, uint16_t len)
static uint8_t bt_pan_get_role(void *cmd, uint16_t len)
{
- DBG("Not Implemented");
+ struct hal_rsp_pan_get_role rsp;
- return HAL_STATUS_FAILED;
+ DBG("");
+
+ rsp.local_role = local_role;
+ ipc_send_rsp_full(HAL_SERVICE_ID_PAN, HAL_OP_PAN_GET_ROLE, sizeof(rsp),
+ &rsp, -1);
+
+ return HAL_STATUS_SUCCESS;
}
void bt_pan_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v5 4/6] android/pan: Implement pan disconnect method in daemon
From: Ravi kumar Veeramally @ 2013-11-29 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1385734845-9725-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Disconnect ongoing PANU role connection betweek devices, free
the device and notify the connection state.
---
android/pan.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/android/pan.c b/android/pan.c
index 031dfff..7093e4c 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -238,9 +238,35 @@ static uint8_t bt_pan_connect(struct hal_cmd_pan_connect *cmd, uint16_t len)
static uint8_t bt_pan_disconnect(struct hal_cmd_pan_disconnect *cmd,
uint16_t len)
{
- DBG("Not Implemented");
+ struct pan_device *dev;
+ GSList *l;
+ bdaddr_t dst;
- return HAL_STATUS_FAILED;
+ DBG("");
+
+ if (len < sizeof(*cmd))
+ return HAL_STATUS_INVALID;
+
+ android2bdaddr(&cmd->bdaddr, &dst);
+
+ l = g_slist_find_custom(peers, &dst, peer_cmp);
+ if (!l)
+ return HAL_STATUS_FAILED;
+
+ dev = l->data;
+
+ if (dev->watch) {
+ g_source_remove(dev->watch);
+ dev->watch = 0;
+ }
+
+ bnep_if_down(dev->dev);
+ bnep_kill_connection(&dst);
+
+ bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
+ pan_device_free(dev);
+
+ return HAL_STATUS_SUCCESS;
}
static uint8_t bt_pan_enable(struct hal_cmd_pan_enable *cmd, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox