summaryrefslogtreecommitdiff
path: root/android/socket.c
diff options
context:
space:
mode:
authorSzymon Janc <szymon.janc@gmail.com>2014-01-04 21:16:14 +0100
committerJohan Hedberg <johan.hedberg@intel.com>2014-01-06 21:26:21 +0200
commit26381ed7d895f3bf4d704039df1a4d29b06ca5b2 (patch)
tree239fcc425b1fea317bad9bb92d07245ddbeeebd8 /android/socket.c
parent74c65573ce78a347015753fbc405fc84e915ac21 (diff)
downloadbluez-26381ed7d895f3bf4d704039df1a4d29b06ca5b2.tar.gz
android/socket: Move logic from HAL to daemon in connect
This reduce logic in HAL to bare minimum e.g. no modifications in library will be needed to add different socket type support. Both bdaddr2str and btuuid2str handle NULL pointers so it is safe to print debug unconditionally.
Diffstat (limited to 'android/socket.c')
-rw-r--r--android/socket.c81
1 files changed, 57 insertions, 24 deletions
diff --git a/android/socket.c b/android/socket.c
index 98862cb5e..69b39eed6 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -975,7 +975,7 @@ fail:
cleanup_rfsock(rfsock);
}
-static bool do_connect(struct rfcomm_sock *rfsock, int chan)
+static bool do_rfcomm_connect(struct rfcomm_sock *rfsock, int chan)
{
BtIOSecLevel sec_level = BT_IO_SEC_MEDIUM;
GIOChannel *io;
@@ -1056,58 +1056,91 @@ static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
DBG("Got RFCOMM channel %d", chan);
- if (do_connect(rfsock, chan))
+ if (do_rfcomm_connect(rfsock, chan))
return;
fail:
cleanup_rfsock(rfsock);
}
-static void handle_connect(const void *buf, uint16_t len)
+static uint8_t connect_rfcomm(const bdaddr_t *addr, int chan,
+ const uint8_t *uuid, uint8_t flags, int *hal_fd)
{
- const struct hal_cmd_sock_connect *cmd = buf;
struct rfcomm_sock *rfsock;
- uuid_t uuid;
- int hal_fd = -1;
+ uuid_t uu;
- DBG("");
+ if ((!memcmp(uuid, zero_uuid, sizeof(zero_uuid)) && chan <= 0) ||
+ !bacmp(addr, BDADDR_ANY)) {
+ error("Invalid rfcomm connect params");
+ return HAL_STATUS_INVALID;
+ }
- rfsock = create_rfsock(-1, &hal_fd);
+ rfsock = create_rfsock(-1, hal_fd);
if (!rfsock)
- goto failed;
+ return HAL_STATUS_FAILED;
- android2bdaddr(cmd->bdaddr, &rfsock->dst);
+ bacpy(&rfsock->dst, addr);
- if (!memcmp(cmd->uuid, zero_uuid, sizeof(zero_uuid))) {
- if (!do_connect(rfsock, cmd->channel))
+ if (!memcmp(uuid, zero_uuid, sizeof(zero_uuid))) {
+ if (!do_rfcomm_connect(rfsock, chan))
goto failed;
} else {
- memset(&uuid, 0, sizeof(uuid));
- uuid.type = SDP_UUID128;
- memcpy(&uuid.value.uuid128, cmd->uuid, sizeof(uint128_t));
+ memset(&uu, 0, sizeof(uu));
+ uu.type = SDP_UUID128;
+ memcpy(&uu.value.uuid128, uuid, sizeof(uint128_t));
- rfsock->profile = get_profile_by_uuid(cmd->uuid);
+ rfsock->profile = get_profile_by_uuid(uuid);
- if (bt_search_service(&adapter_addr, &rfsock->dst, &uuid,
+ if (bt_search_service(&adapter_addr, &rfsock->dst, &uu,
sdp_search_cb, rfsock, NULL) < 0) {
error("Failed to search SDP records");
goto failed;
}
}
+ return HAL_STATUS_SUCCESS;
+
+failed:
+ cleanup_rfsock(rfsock);
+ close(*hal_fd);
+ return HAL_STATUS_FAILED;
+}
+
+static void handle_connect(const void *buf, uint16_t len)
+{
+ const struct hal_cmd_sock_connect *cmd = buf;
+ bdaddr_t bdaddr;
+ uint8_t status;
+ int hal_fd;
+
+ DBG("");
+
+ android2bdaddr(cmd->bdaddr, &bdaddr);
+
+ switch (cmd->type) {
+ case HAL_SOCK_RFCOMM:
+ status = connect_rfcomm(&bdaddr, cmd->channel, cmd->uuid,
+ cmd->flags, &hal_fd);
+ break;
+ case HAL_SOCK_SCO:
+ case HAL_SOCK_L2CAP:
+ status = HAL_STATUS_UNSUPPORTED;
+ break;
+ default:
+ status = HAL_STATUS_INVALID;
+ break;
+ }
+
+ if (status != HAL_STATUS_SUCCESS)
+ goto failed;
+
ipc_send_rsp_full(HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_CONNECT, 0, NULL,
hal_fd);
close(hal_fd);
return;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_CONNECT,
- HAL_STATUS_FAILED);
-
- if (rfsock)
- cleanup_rfsock(rfsock);
+ ipc_send_rsp(HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_CONNECT, status);
- if (hal_fd >= 0)
- close(hal_fd);
}
static const struct ipc_handler cmd_handlers[] = {