* Re: [PATCH] Adding paired-devices cmd to the bluetoothctl
From: Johan Hedberg @ 2013-11-25 12:56 UTC (permalink / raw)
To: Sebastian; +Cc: linux-bluetooth, Sebastian Chlad
In-Reply-To: <1384978912-27461-1-git-send-email-sebastian.chlad@tieto.com>
Hi Sebastian,
On Wed, Nov 20, 2013, Sebastian wrote:
> From: Sebastian Chlad <sebastian.chlad@tieto.com>
>
> Paired-devices command lists only paired devices
> ---
> client/main.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
Applied (after a couple of minor tweaks). Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] bluetoothctl: Fix handling of (G_IO_IN | G_IO_HUP) input case
From: Johan Hedberg @ 2013-11-25 12:53 UTC (permalink / raw)
To: philip; +Cc: linux-bluetooth
In-Reply-To: <1385124462.18208.12.camel@philip-work-laptop.cbg.collabora.co.uk>
Hi Philip,
On Fri, Nov 22, 2013, Philip Withnall wrote:
> If running bluetoothctl as a subprocess from another process, and piping
> input to it, it’s possible for the stdin pipe to be closed by the parent
> process while there’s still data pending in its buffer. This results in
> input handler callbacks with condition (G_IO_IN | G_IO_HUP). All of the
> pending input should be handled before closing bluetoothctl.
> ---
> client/main.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] android/bluetooth: Fix memory leak
From: Johan Hedberg @ 2013-11-25 12:52 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1385130072-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Fri, Nov 22, 2013, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ---
> android/bluetooth.c | 1 +
> 1 file changed, 1 insertion(+)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH 1/4] android/pics: Add PTS PICS for PAN
From: Johan Hedberg @ 2013-11-25 12:51 UTC (permalink / raw)
To: Jakub Tyszkowski; +Cc: linux-bluetooth
In-Reply-To: <1385117261-25270-1-git-send-email-jakub.tyszkowski@tieto.com>
Hi Jakub,
On Fri, Nov 22, 2013, Jakub Tyszkowski wrote:
> PTS PICS for PAN, targeting Android 4.4.
>
> ---
> android/pics-pan.txt | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 146 insertions(+)
> create mode 100644 android/pics-pan.txt
All four patches have been applied, though I merged the Makefile.am
changes to the two main patches that add the txt files.
Johan
^ permalink raw reply
* Re: [PATCH] android/hal-bluetooth: Use static memory for enum convertion
From: Johan Hedberg @ 2013-11-25 12:47 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1385379120-10142-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Mon, Nov 25, 2013, Szymon Janc wrote:
> There is no need to use dynamic allocation for enum properties
> convertion. Each property type can be present only once in properties
> callback so using static allocation is safe. This also remove need
> for cleanup properties after HAL callback is called making code
> simpler.
> ---
> android/hal-bluetooth.c | 109 ++++++++++++++++--------------------------------
> 1 file changed, 37 insertions(+), 72 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] fixup add missing break (sjanc review)
From: Andrei Emeltchenko @ 2013-11-25 12:41 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385132551-20775-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
On Fri, Nov 22, 2013 at 05:02:31PM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com
this one merged to patch 1
Best regards
Andrei Emeltchenko
>
> ---
> android/socket.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/android/socket.c b/android/socket.c
> index 70e2307..7b9e41b 100644
> --- a/android/socket.c
> +++ b/android/socket.c
> @@ -852,6 +852,9 @@ static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
> sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free,
> NULL);
> sdp_list_free(protos, NULL);
> +
> + if (chan)
> + break;
> }
>
> if (chan <= 0) {
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* [PATCH] android/hal-bluetooth: Use static memory for enum convertion
From: Szymon Janc @ 2013-11-25 11:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
There is no need to use dynamic allocation for enum properties
convertion. Each property type can be present only once in properties
callback so using static allocation is safe. This also remove need
for cleanup properties after HAL callback is called making code
simpler.
---
android/hal-bluetooth.c | 109 ++++++++++++++++--------------------------------
1 file changed, 37 insertions(+), 72 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6b821dd..a879583 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -29,10 +29,10 @@
static const bt_callbacks_t *bt_hal_cbacks = NULL;
#define create_enum_prop(prop, hal_prop, type) do { \
- type *pe = malloc(sizeof(type)); \
- prop.val = pe; \
- prop.len = sizeof(*pe); \
- *pe = *((uint8_t *) (hal_prop->val)); \
+ static type e; \
+ prop.val = &e; \
+ prop.len = sizeof(e); \
+ e = *((uint8_t *) (hal_prop->val)); \
} while (0)
static void handle_adapter_state_changed(void *buf, uint16_t len)
@@ -45,13 +45,20 @@ static void handle_adapter_state_changed(void *buf, uint16_t len)
bt_hal_cbacks->adapter_state_changed_cb(ev->state);
}
-static void adapter_props_to_hal(bt_property_t *send_props, void *buf,
- uint8_t num_props)
+static void adapter_props_to_hal(bt_property_t *send_props,
+ struct hal_property *prop,
+ uint8_t num_props, uint16_t len)
{
- struct hal_property *prop = buf;
+ void *buf = prop;
uint8_t i;
for (i = 0; i < num_props; i++) {
+ if (sizeof(*prop) + prop->len > len) {
+ error("invalid adapter properties(%zu > %u), aborting",
+ sizeof(*prop) + prop->len, len);
+ exit(EXIT_FAILURE);
+ }
+
send_props[i].type = prop->type;
switch (prop->type) {
@@ -72,34 +79,32 @@ static void adapter_props_to_hal(bt_property_t *send_props, void *buf,
DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
+ len -= sizeof(*prop) + prop->len;
buf += sizeof(*prop) + prop->len;
prop = buf;
}
-}
-static void adapter_hal_props_cleanup(bt_property_t *props, uint8_t num)
-{
- uint8_t i;
+ if (!len)
+ return;
- for (i = 0; i < num; i++) {
- switch (props[i].type) {
- case HAL_PROP_ADAPTER_TYPE:
- case HAL_PROP_ADAPTER_SCAN_MODE:
- free(props[i].val);
- break;
- default:
- break;
- }
- }
+ error("invalid adapter properties (%u bytes left), aborting", len);
+ exit(EXIT_FAILURE);
}
-static void device_props_to_hal(bt_property_t *send_props, void *buf,
- uint8_t num_props)
+static void device_props_to_hal(bt_property_t *send_props,
+ struct hal_property *prop, uint8_t num_props,
+ uint16_t len)
{
- struct hal_property *prop = buf;
+ void *buf = prop;
uint8_t i;
for (i = 0; i < num_props; i++) {
+ if (sizeof(*prop) + prop->len > len) {
+ error("invalid device properties (%zu > %u), aborting",
+ sizeof(*prop) + prop->len, len);
+ exit(EXIT_FAILURE);
+ }
+
send_props[i].type = prop->type;
switch (prop->type) {
@@ -115,48 +120,17 @@ static void device_props_to_hal(bt_property_t *send_props, void *buf,
break;
}
+ len -= sizeof(*prop) + prop->len;
buf += sizeof(*prop) + prop->len;
prop = buf;
DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
}
-}
-
-
-static void device_hal_props_cleanup(bt_property_t *props, uint8_t num)
-{
- uint8_t i;
-
- for (i = 0; i < num; i++) {
- switch (props[i].type) {
- case HAL_PROP_DEVICE_TYPE:
- free(props[i].val);
- break;
- default:
- break;
- }
- }
-}
-
-static void check_props(int num, const struct hal_property *prop, uint16_t len)
-{
- int i;
-
- for (i = 0; i < num; i++) {
- if (sizeof(*prop) + prop->len > len) {
- error("invalid properties (%zu > %u), aborting",
- sizeof(*prop) + prop->len, len);
- exit(EXIT_FAILURE);
- }
-
- len -= sizeof(*prop) + prop->len;
- prop = ((void *) prop) + sizeof(*prop) + prop->len;
- }
if (!len)
return;
- error("invalid properties length (%u bytes left), aborting", len);
+ error("invalid device properties (%u bytes left), aborting", len);
exit(EXIT_FAILURE);
}
@@ -167,16 +141,13 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
DBG("");
- check_props(ev->num_props, ev->props, len - sizeof(*ev));
-
if (!bt_hal_cbacks->adapter_properties_cb)
return;
- adapter_props_to_hal(props, ev->props, ev->num_props);
+ len -= sizeof(*ev);
+ adapter_props_to_hal(props, ev->props, ev->num_props, len);
bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
-
- adapter_hal_props_cleanup(props, ev->num_props);
}
static void handle_bond_state_change(void *buf, uint16_t len)
@@ -253,16 +224,13 @@ static void handle_device_found(void *buf, uint16_t len)
DBG("");
- check_props(ev->num_props, ev->props, len - sizeof(*ev));
-
if (!bt_hal_cbacks->device_found_cb)
return;
- device_props_to_hal(props, ev->props, ev->num_props);
+ len -= sizeof(*ev);
+ device_props_to_hal(props, ev->props, ev->num_props, len);
bt_hal_cbacks->device_found_cb(ev->num_props, props);
-
- device_hal_props_cleanup(props, ev->num_props);
}
static void handle_device_state_changed(void *buf, uint16_t len)
@@ -272,18 +240,15 @@ static void handle_device_state_changed(void *buf, uint16_t len)
DBG("");
- check_props(ev->num_props, ev->props, len - sizeof(*ev));
-
if (!bt_hal_cbacks->remote_device_properties_cb)
return;
- device_props_to_hal(props, ev->props, ev->num_props);
+ len -= sizeof(*ev);
+ device_props_to_hal(props, ev->props, ev->num_props, len);
bt_hal_cbacks->remote_device_properties_cb(ev->status,
(bt_bdaddr_t *)ev->bdaddr,
ev->num_props, props);
-
- device_hal_props_cleanup(props, ev->num_props);
}
static void handle_acl_state_changed(void *buf, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 7/7] android/socket: Check create_rfsock returns valid structure
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385378577-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/socket.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 45f9b91..bbc29dc 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -644,6 +644,12 @@ static void accept_cb(GIOChannel *io, GError *err, gpointer user_data)
sock_acc = g_io_channel_unix_get_fd(io);
rfsock_acc = create_rfsock(sock_acc, &hal_fd);
+ if (!rfsock_acc) {
+ g_io_channel_shutdown(io, TRUE, NULL);
+ g_io_channel_unref(io);
+ return;
+ }
+
connections = g_list_append(connections, rfsock_acc);
DBG("rfsock: fd %d real_sock %d chan %u sock %d",
@@ -904,8 +910,11 @@ static int handle_connect(void *buf)
DBG("");
- android2bdaddr(cmd->bdaddr, &dst);
rfsock = create_rfsock(-1, &hal_fd);
+ if (!rfsock)
+ return -1;
+
+ android2bdaddr(cmd->bdaddr, &dst);
bacpy(&rfsock->dst, &dst);
memset(&uuid, 0, sizeof(uuid));
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 6/7] android/socket: Handle Android events for server socket
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385378577-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Add watch for tracking events from Android framework for server socket.
---
android/socket.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 93ace07..45f9b91 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -593,6 +593,24 @@ static bool sock_send_accept(struct rfcomm_sock *rfsock, bdaddr_t *bdaddr,
return true;
}
+static gboolean sock_server_stack_event_cb(GIOChannel *io, GIOCondition cond,
+ gpointer data)
+{
+ struct rfcomm_sock *rfsock = data;
+
+ DBG("");
+
+ if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+ error("Socket error: sock %d cond %d",
+ g_io_channel_unix_get_fd(io), cond);
+ cleanup_rfsock(rfsock);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void accept_cb(GIOChannel *io, GError *err, gpointer user_data)
{
struct rfcomm_sock *rfsock = user_data;
@@ -662,7 +680,8 @@ static int handle_listen(void *buf)
struct profile_info *profile;
struct rfcomm_sock *rfsock;
BtIOSecLevel sec_level;
- GIOChannel *io;
+ GIOChannel *io, *io_stack;
+ GIOCondition cond;
GError *err = NULL;
int hal_fd;
int chan;
@@ -705,6 +724,12 @@ static int handle_listen(void *buf)
rfsock->srv_io = io;
+ /* Handle events from Android */
+ cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
+ io_stack = g_io_channel_unix_new(rfsock->fd);
+ g_io_add_watch(io_stack, cond, sock_server_stack_event_cb, rfsock);
+ g_io_channel_unref(io_stack);
+
DBG("real_sock %d fd %d hal_fd %d", rfsock->real_sock, rfsock->fd,
hal_fd);
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 5/7] android/socket: Keep server iochannel reference
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385378577-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
server io channel reference will be stored in rfsock structure
and might be deleted when Android end closes connection or when
HAL makes cleanup() call.
---
android/socket.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 24503c5..93ace07 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -70,6 +70,8 @@ struct rfcomm_sock {
guint rfcomm_watch;
guint stack_watch;
+ GIOChannel *srv_io;
+
bdaddr_t dst;
uint32_t service_handle;
@@ -121,6 +123,11 @@ static void cleanup_rfsock(struct rfcomm_sock *rfsock)
if (rfsock->service_handle)
bt_adapter_remove_record(rfsock->service_handle);
+ if (rfsock->srv_io) {
+ g_io_channel_shutdown(rfsock->srv_io, TRUE, NULL);
+ g_io_channel_unref(rfsock->srv_io);
+ }
+
g_free(rfsock);
}
@@ -696,9 +703,7 @@ static int handle_listen(void *buf)
rfsock->real_sock = g_io_channel_unix_get_fd(io);
servers = g_list_append(servers, rfsock);
- /* TODO: Add server watch */
- g_io_channel_set_close_on_unref(io, TRUE);
- g_io_channel_unref(io);
+ rfsock->srv_io = io;
DBG("real_sock %d fd %d hal_fd %d", rfsock->real_sock, rfsock->fd,
hal_fd);
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 4/7] android/socket: Use security level for connect
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385378577-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Use low security level for connections without profile and default
sec_level for others. rfsock now has pointer to profile info for
outcoming connections.
---
android/socket.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 399590e..24503c5 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -60,6 +60,8 @@ GList *servers = NULL;
/* Simple list of RFCOMM connected sockets */
GList *connections = NULL;
+struct profile_info;
+
struct rfcomm_sock {
int fd; /* descriptor for communication with Java framework */
int real_sock; /* real RFCOMM socket */
@@ -70,6 +72,8 @@ struct rfcomm_sock {
bdaddr_t dst;
uint32_t service_handle;
+
+ struct profile_info *profile;
};
static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
@@ -785,6 +789,7 @@ fail:
static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
{
struct rfcomm_sock *rfsock = data;
+ BtIOSecLevel sec_level = BT_IO_SEC_LOW;
GError *gerr = NULL;
sdp_list_t *list;
GIOChannel *io;
@@ -828,11 +833,14 @@ static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
DBG("Got RFCOMM channel %d", chan);
+ if (rfsock->profile)
+ sec_level = rfsock->profile->sec_level;
+
io = bt_io_connect(connect_cb, rfsock, NULL, &gerr,
BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
BT_IO_OPT_DEST_BDADDR, &rfsock->dst,
BT_IO_OPT_CHANNEL, chan,
- BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
BT_IO_OPT_INVALID);
if (!io) {
error("Failed connect: %s", gerr->message);
@@ -874,6 +882,8 @@ static int handle_connect(void *buf)
uuid.type = SDP_UUID128;
memcpy(&uuid.value.uuid128, cmd->uuid, sizeof(uint128_t));
+ rfsock->profile = get_profile_by_uuid(cmd->uuid);
+
if (bt_search_service(&adapter_addr, &dst, &uuid, sdp_search_cb, rfsock,
NULL) < 0) {
error("Failed to search SDP records");
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 3/7] android/socket: Add error printing possible close() failure
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385378577-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/socket.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 0885fa2..399590e 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -96,10 +96,15 @@ static void cleanup_rfsock(struct rfcomm_sock *rfsock)
DBG("rfsock: %p fd %d real_sock %d chan %u",
rfsock, rfsock->fd, rfsock->real_sock, rfsock->channel);
- if (rfsock->fd > 0)
- close(rfsock->fd);
- if (rfsock->real_sock > 0)
- close(rfsock->real_sock);
+ if (rfsock->fd >= 0)
+ if (close(rfsock->fd) < 0)
+ error("close() fd %d failed: %s", rfsock->fd,
+ strerror(errno));
+
+ if (rfsock->real_sock >= 0)
+ if (close(rfsock->real_sock) < 0)
+ error("close() fd %d: failed: %s", rfsock->real_sock,
+ strerror(errno));
if (rfsock->rfcomm_watch > 0)
if (!g_source_remove(rfsock->rfcomm_watch))
@@ -890,7 +895,10 @@ void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
break;
ipc_send(sk, HAL_SERVICE_ID_SOCK, opcode, 0, NULL, fd);
- close(fd);
+
+ if (close(fd) < 0)
+ error("close() fd %d failed: %s", fd, strerror(errno));
+
return;
case HAL_OP_SOCK_CONNECT:
fd = handle_connect(buf);
@@ -898,7 +906,10 @@ void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
break;
ipc_send(sk, HAL_SERVICE_ID_SOCK, opcode, 0, NULL, fd);
- close(fd);
+
+ if (close(fd) < 0)
+ error("close() fd %d failed: %s", fd, strerror(errno));
+
return;
default:
DBG("Unhandled command, opcode 0x%x", opcode);
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 2/7] android/socket: Use default sec_level for listen
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385378577-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Set default security level low for OPP and SPP and medium for PBAP and MAS.
Default security level would be low for listening without profile.
---
android/socket.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 63587ee..0885fa2 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -344,6 +344,7 @@ static struct profile_info {
},
.channel = PBAP_DEFAULT_CHANNEL,
.svc_hint = SVC_HINT_OBEX,
+ .sec_level = BT_IO_SEC_MEDIUM,
.create_record = create_pbap_record
}, {
.uuid = {
@@ -352,13 +353,17 @@ static struct profile_info {
},
.channel = OPP_DEFAULT_CHANNEL,
.svc_hint = SVC_HINT_OBEX,
+ .sec_level = BT_IO_SEC_LOW,
.create_record = create_opp_record
}, {
.uuid = {
0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
},
- .channel = MAS_DEFAULT_CHANNEL
+ .channel = MAS_DEFAULT_CHANNEL,
+ .svc_hint = 0,
+ .sec_level = BT_IO_SEC_MEDIUM,
+ .create_record = NULL
}, {
.uuid = {
0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
@@ -366,6 +371,7 @@ static struct profile_info {
},
.channel = SPP_DEFAULT_CHANNEL,
.svc_hint = 0,
+ .sec_level = BT_IO_SEC_LOW,
.create_record = create_spp_record
},
};
@@ -639,6 +645,7 @@ static int handle_listen(void *buf)
struct hal_cmd_sock_listen *cmd = buf;
struct profile_info *profile;
struct rfcomm_sock *rfsock;
+ BtIOSecLevel sec_level;
GIOChannel *io;
GError *err = NULL;
int hal_fd;
@@ -650,10 +657,14 @@ static int handle_listen(void *buf)
if (!profile) {
if (!cmd->channel)
return -1;
- else
+ else {
chan = cmd->channel;
- } else
+ sec_level = BT_IO_SEC_LOW;
+ }
+ } else {
chan = profile->channel;
+ sec_level = profile->sec_level;
+ }
DBG("rfcomm channel %d svc_name %s", chan, cmd->name);
@@ -664,6 +675,7 @@ static int handle_listen(void *buf)
io = bt_io_listen(accept_cb, NULL, rfsock, NULL, &err,
BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
BT_IO_OPT_CHANNEL, chan,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
BT_IO_OPT_INVALID);
if (!io) {
error("Failed listen: %s", err->message);
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 1/7] android/socket: Check that create_record function exist
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385378577-20503-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/socket.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 22472b9..63587ee 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -688,7 +688,7 @@ static int handle_listen(void *buf)
return -1;
}
- if (profile)
+ if (profile && profile->create_record)
rfsock->service_handle = sdp_service_register(profile,
cmd->name);
--
1.8.3.2
^ permalink raw reply related
* [RFCv2 0/7] Socket HAL part2
From: Andrei Emeltchenko @ 2013-11-25 11:22 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
These are fixes and some missing functionality for Socket HAL.
Andrei Emeltchenko (7):
android/socket: Check that create_record function exist
android/socket: Use default sec_level for listen
android/socket: Add error printing possible close() failure
android/socket: Use security level for connect
android/socket: Keep server iochannel reference
android/socket: Handle Android events for server socket
android/socket: Check create_rfsock returns valid structure
android/socket.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 88 insertions(+), 16 deletions(-)
--
1.8.3.2
^ permalink raw reply
* [PATCH] android/bluetooth: Fix possible NULL dereference
From: Andrei Emeltchenko @ 2013-11-25 9:47 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Since sdp_record_find() may return NULL check this value.
---
android/bluetooth.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index aa684bd..ad8af0d 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1332,6 +1332,7 @@ static void set_device_id(void)
struct mgmt_cp_set_device_id cp;
uint8_t major, minor;
uint16_t version;
+ sdp_record_t *rec;
if (sscanf(VERSION, "%hhu.%hhu", &major, &minor) != 2)
return;
@@ -1351,7 +1352,9 @@ static void set_device_id(void)
register_device_id(DEVICE_ID_SOURCE, DEVICE_ID_VENDOR,
DEVICE_ID_PRODUCT, version);
- bt_adapter_add_record(sdp_record_find(0x10000), 0x00);
+ rec = sdp_record_find(0x10000);
+ if (rec)
+ bt_adapter_add_record(rec, 0x00);
}
static void set_adapter_name_complete(uint8_t status, uint16_t length,
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 15/15] android/hal-utils: Fix possible NULL pointer dereference
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/hal-utils.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/android/hal-utils.c b/android/hal-utils.c
index 4f44d98..e3c0c60 100644
--- a/android/hal-utils.c
+++ b/android/hal-utils.c
@@ -33,6 +33,9 @@ const char *bt_uuid_t2str(const uint8_t *uuid, char *buf)
unsigned int i;
int is_bt;
+ if (!uuid)
+ return strcpy(buf, "NULL");
+
is_bt = !memcmp(&uuid[4], &BT_BASE_UUID[4], HAL_UUID_LEN - 4);
for (i = 0; i < HAL_UUID_LEN; i++) {
@@ -167,6 +170,9 @@ const char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
{
const uint8_t *p = bd_addr->address;
+ if (!bd_addr)
+ return strcpy(buf, "NULL");
+
snprintf(buf, MAX_ADDR_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 14/15] android/socket: Refactor socket send_fd function
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Make code cleaner and initialize local cmsg buffer to zeroes.
---
android/socket.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 5f89f2c..22472b9 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -394,7 +394,7 @@ static int bt_sock_send_fd(int sock_fd, const void *buf, int len, int send_fd)
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iv;
- char msgbuf[CMSG_SPACE(1)];
+ char cmsgbuf[CMSG_SPACE(sizeof(int))];
DBG("len %d sock_fd %d send_fd %d", len, sock_fd, send_fd);
@@ -402,13 +402,16 @@ static int bt_sock_send_fd(int sock_fd, const void *buf, int len, int send_fd)
return -1;
memset(&msg, 0, sizeof(msg));
+ memset(cmsgbuf, 0, sizeof(cmsgbuf));
+
+ msg.msg_control = cmsgbuf;
+ msg.msg_controllen = sizeof(cmsgbuf);
- msg.msg_control = msgbuf;
- msg.msg_controllen = sizeof(msgbuf);
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(send_fd));
+
memcpy(CMSG_DATA(cmsg), &send_fd, sizeof(send_fd));
iv.iov_base = (unsigned char *) buf;
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 13/15] android/hal-sock: Print bdaddr on connect
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/hal-sock.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/android/hal-sock.c b/android/hal-sock.c
index bd88ad8..e02a49a 100644
--- a/android/hal-sock.c
+++ b/android/hal-sock.c
@@ -82,8 +82,8 @@ static bt_status_t sock_connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
return BT_STATUS_PARM_INVALID;
}
- DBG("uuid %s chan %d sock %p type %d flags 0x%02x",
- btuuid2str(uuid), chan, sock, type, flags);
+ DBG("bdaddr %s uuid %s chan %d sock %p type %d flags 0x%02x",
+ bdaddr2str(bdaddr), btuuid2str(uuid), chan, sock, type, flags);
if (type != BTSOCK_RFCOMM) {
error("Socket type %u not supported", type);
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 12/15] android/socket: Support listen() with supplied chan number
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
No profile is assigned in this case. There is a possibility to use
Serial Port Profile.
---
android/socket.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index ca5ea2f..5f89f2c 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -644,10 +644,13 @@ static int handle_listen(void *buf)
DBG("");
profile = get_profile_by_uuid(cmd->uuid);
- if (!profile)
- return -1;
-
- chan = profile->channel;
+ if (!profile) {
+ if (!cmd->channel)
+ return -1;
+ else
+ chan = cmd->channel;
+ } else
+ chan = profile->channel;
DBG("rfcomm channel %d svc_name %s", chan, cmd->name);
@@ -682,7 +685,9 @@ static int handle_listen(void *buf)
return -1;
}
- rfsock->service_handle = sdp_service_register(profile, cmd->name);
+ if (profile)
+ rfsock->service_handle = sdp_service_register(profile,
+ cmd->name);
return hal_fd;
}
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 11/15] android/socket: Add SPP SDP record
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/socket.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 72 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 619d5e9..ca5ea2f 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -261,6 +261,75 @@ static sdp_record_t *create_pbap_record(uint8_t chan, const char *svc_name)
return record;
}
+static sdp_record_t *create_spp_record(uint8_t chan, const char *svc_name)
+{
+ const char *service_name = "Serial Port";
+ sdp_list_t *svclass_id, *apseq, *profiles, *root;
+ uuid_t root_uuid, sp_uuid, l2cap, rfcomm;
+ sdp_profile_desc_t profile;
+ sdp_list_t *aproto, *proto[2];
+ sdp_data_t *channel;
+ sdp_record_t *record;
+
+ record = sdp_record_alloc();
+ if (!record)
+ return NULL;
+
+ record->handle = sdp_next_handle();
+
+ sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
+ root = sdp_list_append(NULL, &root_uuid);
+ sdp_set_browse_groups(record, root);
+
+ sdp_uuid16_create(&sp_uuid, SERIAL_PORT_SVCLASS_ID);
+ svclass_id = sdp_list_append(NULL, &sp_uuid);
+ sdp_set_service_classes(record, svclass_id);
+
+ sdp_uuid16_create(&profile.uuid, SERIAL_PORT_PROFILE_ID);
+ profile.version = 0x0100;
+ profiles = sdp_list_append(NULL, &profile);
+ sdp_set_profile_descs(record, profiles);
+
+ sdp_uuid16_create(&l2cap, L2CAP_UUID);
+ proto[0] = sdp_list_append(NULL, &l2cap);
+ apseq = sdp_list_append(NULL, proto[0]);
+
+ sdp_uuid16_create(&rfcomm, RFCOMM_UUID);
+ proto[1] = sdp_list_append(NULL, &rfcomm);
+ channel = sdp_data_alloc(SDP_UINT8, &chan);
+ proto[1] = sdp_list_append(proto[1], channel);
+ apseq = sdp_list_append(apseq, proto[1]);
+
+ aproto = sdp_list_append(NULL, apseq);
+ sdp_set_access_protos(record, aproto);
+
+ sdp_add_lang_attr(record);
+
+ if (svc_name)
+ service_name = svc_name;
+
+ sdp_set_info_attr(record, service_name, "BlueZ", "COM Port");
+
+ sdp_set_url_attr(record, "http://www.bluez.org/",
+ "http://www.bluez.org/", "http://www.bluez.org/");
+
+ sdp_set_service_id(record, sp_uuid);
+ sdp_set_service_ttl(record, 0xffff);
+ sdp_set_service_avail(record, 0xff);
+ sdp_set_record_state(record, 0x00001234);
+
+ sdp_data_free(channel);
+ sdp_list_free(proto[0], NULL);
+ sdp_list_free(proto[1], NULL);
+ sdp_list_free(apseq, NULL);
+ sdp_list_free(aproto, NULL);
+ sdp_list_free(root, NULL);
+ sdp_list_free(svclass_id, NULL);
+ sdp_list_free(profiles, NULL);
+
+ return record;
+}
+
static struct profile_info {
uint8_t uuid[16];
uint8_t channel;
@@ -295,7 +364,9 @@ static struct profile_info {
0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
},
- .channel = SPP_DEFAULT_CHANNEL
+ .channel = SPP_DEFAULT_CHANNEL,
+ .svc_hint = 0,
+ .create_record = create_spp_record
},
};
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 10/15] android/socket: Add PBAP SDP record
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This adds SDP service record like shown below:
Service Name: OBEX Phonebook Access Server
Service RecHandle: 0x10002
Service Class ID List:
"Phonebook Access - PSE" (0x112f)
Protocol Descriptor List:
"RFCOMM" (0x0003)
Channel: 15
"OBEX" (0x0008)
Profile Descriptor List:
"Phonebook Access" (0x1130)
Version: 0x0100
---
android/socket.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 73 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 94add6f..619d5e9 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -191,6 +191,76 @@ static sdp_record_t *create_opp_record(uint8_t chan, const char *svc_name)
return record;
}
+static sdp_record_t *create_pbap_record(uint8_t chan, const char *svc_name)
+{
+ const char *service_name = "OBEX Phonebook Access Server";
+ sdp_list_t *svclass_id, *pfseq, *apseq, *root;
+ uuid_t root_uuid, pbap_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid;
+ sdp_profile_desc_t profile[1];
+ sdp_list_t *aproto, *proto[3];
+ sdp_data_t *channel;
+ uint8_t formats[] = { 0x01 };
+ uint8_t dtd = SDP_UINT8;
+ sdp_data_t *sflist;
+ sdp_record_t *record;
+
+ record = sdp_record_alloc();
+ if (!record)
+ return NULL;
+
+ record->handle = sdp_next_handle();
+
+ sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
+ root = sdp_list_append(NULL, &root_uuid);
+ sdp_set_browse_groups(record, root);
+
+ sdp_uuid16_create(&pbap_uuid, PBAP_PSE_SVCLASS_ID);
+ svclass_id = sdp_list_append(NULL, &pbap_uuid);
+ sdp_set_service_classes(record, svclass_id);
+
+ sdp_uuid16_create(&profile[0].uuid, PBAP_PROFILE_ID);
+ profile[0].version = 0x0100;
+ pfseq = sdp_list_append(NULL, profile);
+ sdp_set_profile_descs(record, pfseq);
+
+ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
+ proto[0] = sdp_list_append(NULL, &l2cap_uuid);
+ apseq = sdp_list_append(NULL, proto[0]);
+
+ sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
+ proto[1] = sdp_list_append(NULL, &rfcomm_uuid);
+ channel = sdp_data_alloc(SDP_UINT8, &chan);
+ proto[1] = sdp_list_append(proto[1], channel);
+ apseq = sdp_list_append(apseq, proto[1]);
+
+ sdp_uuid16_create(&obex_uuid, OBEX_UUID);
+ proto[2] = sdp_list_append(NULL, &obex_uuid);
+ apseq = sdp_list_append(apseq, proto[2]);
+
+ aproto = sdp_list_append(NULL, apseq);
+ sdp_set_access_protos(record, aproto);
+
+ sflist = sdp_data_alloc(dtd, formats);
+ sdp_attr_add(record, SDP_ATTR_SUPPORTED_REPOSITORIES, sflist);
+
+ if (svc_name)
+ service_name = svc_name;
+
+ sdp_set_info_attr(record, service_name, NULL, NULL);
+
+ sdp_data_free(channel);
+ sdp_list_free(proto[0], NULL);
+ sdp_list_free(proto[1], NULL);
+ sdp_list_free(proto[2], NULL);
+ sdp_list_free(apseq, NULL);
+ sdp_list_free(pfseq, NULL);
+ sdp_list_free(aproto, NULL);
+ sdp_list_free(root, NULL);
+ sdp_list_free(svclass_id, NULL);
+
+ return record;
+}
+
static struct profile_info {
uint8_t uuid[16];
uint8_t channel;
@@ -203,7 +273,9 @@ static struct profile_info {
0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
},
- .channel = PBAP_DEFAULT_CHANNEL
+ .channel = PBAP_DEFAULT_CHANNEL,
+ .svc_hint = SVC_HINT_OBEX,
+ .create_record = create_pbap_record
}, {
.uuid = {
0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 09/15] android/socket: Add SPP uuid to profile table
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/socket.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 5f2af48..94add6f 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -45,6 +45,7 @@
#include "utils.h"
#include "socket.h"
+#define SPP_DEFAULT_CHANNEL 3
#define OPP_DEFAULT_CHANNEL 9
#define PBAP_DEFAULT_CHANNEL 15
#define MAS_DEFAULT_CHANNEL 16
@@ -217,7 +218,13 @@ static struct profile_info {
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
},
.channel = MAS_DEFAULT_CHANNEL
- }
+ }, {
+ .uuid = {
+ 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
+ },
+ .channel = SPP_DEFAULT_CHANNEL
+ },
};
static uint32_t sdp_service_register(struct profile_info *profile,
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 08/15] android/socket: Add MAS uuid to profile table
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/socket.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/android/socket.c b/android/socket.c
index a15268d..5f2af48 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -47,6 +47,7 @@
#define OPP_DEFAULT_CHANNEL 9
#define PBAP_DEFAULT_CHANNEL 15
+#define MAS_DEFAULT_CHANNEL 16
#define SVC_HINT_OBEX 0x10
@@ -210,6 +211,12 @@ static struct profile_info {
.channel = OPP_DEFAULT_CHANNEL,
.svc_hint = SVC_HINT_OBEX,
.create_record = create_opp_record
+ }, {
+ .uuid = {
+ 0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
+ },
+ .channel = MAS_DEFAULT_CHANNEL
}
};
--
1.8.3.2
^ permalink raw reply related
* [PATCHv8 07/15] android/socket: Add OPP SDP record
From: Andrei Emeltchenko @ 2013-11-25 9:44 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385372698-16212-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This adds SDP record for OPP shown below:
Service Name: OBEX Object Push
Service RecHandle: 0x10002
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"RFCOMM" (0x0003)
Channel: 9
"OBEX" (0x0008)
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100
---
android/socket.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 81 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index 71dcf4a..a15268d 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -48,6 +48,8 @@
#define OPP_DEFAULT_CHANNEL 9
#define PBAP_DEFAULT_CHANNEL 15
+#define SVC_HINT_OBEX 0x10
+
static bdaddr_t adapter_addr;
/* Simple list of RFCOMM server sockets */
@@ -111,6 +113,82 @@ static void cleanup_rfsock(struct rfcomm_sock *rfsock)
g_free(rfsock);
}
+static sdp_record_t *create_opp_record(uint8_t chan, const char *svc_name)
+{
+ const char *service_name = "OBEX Object Push";
+ sdp_list_t *svclass_id, *pfseq, *apseq, *root;
+ uuid_t root_uuid, opush_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid;
+ sdp_profile_desc_t profile[1];
+ sdp_list_t *aproto, *proto[3];
+ uint8_t formats[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
+ void *dtds[sizeof(formats)], *values[sizeof(formats)];
+ unsigned int i;
+ uint8_t dtd = SDP_UINT8;
+ sdp_data_t *sflist;
+ sdp_data_t *channel;
+ sdp_record_t *record;
+
+ record = sdp_record_alloc();
+ if (!record)
+ return NULL;
+
+ record->handle = sdp_next_handle();
+
+ sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
+ root = sdp_list_append(NULL, &root_uuid);
+ sdp_set_browse_groups(record, root);
+
+ sdp_uuid16_create(&opush_uuid, OBEX_OBJPUSH_SVCLASS_ID);
+ svclass_id = sdp_list_append(NULL, &opush_uuid);
+ sdp_set_service_classes(record, svclass_id);
+
+ sdp_uuid16_create(&profile[0].uuid, OBEX_OBJPUSH_PROFILE_ID);
+ profile[0].version = 0x0100;
+ pfseq = sdp_list_append(NULL, profile);
+ sdp_set_profile_descs(record, pfseq);
+
+ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
+ proto[0] = sdp_list_append(NULL, &l2cap_uuid);
+ apseq = sdp_list_append(NULL, proto[0]);
+
+ sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
+ proto[1] = sdp_list_append(NULL, &rfcomm_uuid);
+ channel = sdp_data_alloc(SDP_UINT8, &chan);
+ proto[1] = sdp_list_append(proto[1], channel);
+ apseq = sdp_list_append(apseq, proto[1]);
+
+ sdp_uuid16_create(&obex_uuid, OBEX_UUID);
+ proto[2] = sdp_list_append(NULL, &obex_uuid);
+ apseq = sdp_list_append(apseq, proto[2]);
+
+ aproto = sdp_list_append(NULL, apseq);
+ sdp_set_access_protos(record, aproto);
+
+ for (i = 0; i < sizeof(formats); i++) {
+ dtds[i] = &dtd;
+ values[i] = &formats[i];
+ }
+ sflist = sdp_seq_alloc(dtds, values, sizeof(formats));
+ sdp_attr_add(record, SDP_ATTR_SUPPORTED_FORMATS_LIST, sflist);
+
+ if (svc_name)
+ service_name = svc_name;
+
+ sdp_set_info_attr(record, service_name, NULL, NULL);
+
+ sdp_data_free(channel);
+ sdp_list_free(proto[0], NULL);
+ sdp_list_free(proto[1], NULL);
+ sdp_list_free(proto[2], NULL);
+ sdp_list_free(apseq, NULL);
+ sdp_list_free(pfseq, NULL);
+ sdp_list_free(aproto, NULL);
+ sdp_list_free(root, NULL);
+ sdp_list_free(svclass_id, NULL);
+
+ return record;
+}
+
static struct profile_info {
uint8_t uuid[16];
uint8_t channel;
@@ -129,7 +207,9 @@ static struct profile_info {
0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
},
- .channel = OPP_DEFAULT_CHANNEL
+ .channel = OPP_DEFAULT_CHANNEL,
+ .svc_hint = SVC_HINT_OBEX,
+ .create_record = create_opp_record
}
};
--
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