* [PATCH] android: Fix pan service registration
From: Szymon Janc @ 2013-11-08 9:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
From: Marcin Kraglak <marcin.kraglak@tieto.com>
A2dp service was registered instead of pan.
---
android/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/main.c b/android/main.c
index 057c2f7..93870d0 100644
--- a/android/main.c
+++ b/android/main.c
@@ -107,7 +107,7 @@ static void service_register(void *buf, uint16_t len)
break;
case HAL_SERVICE_ID_PAN:
- if (!bt_a2dp_register(sk, adapter_bdaddr))
+ if (!bt_pan_register(sk, adapter_bdaddr))
goto failed;
break;
--
1.8.4.2
^ permalink raw reply related
* [PATCH_v3 0/5] Fixed and implemented set report and send data ifaces
From: Ravi kumar Veeramally @ 2013-11-08 10:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
v3: Fixed issues as per Johan's and Jerzy' comments and suggestions
Implemented hex2bin as a static funtion and split the patches.
v2: Fixed issues as per Johan's comments and suggestions.
This patch adds missing hid ipc documentation, hal headers,
renaming and virtual unplug notification in hid HAL.
Set report and send data interfaces are receiving data in ascii format
but it should be in hex format. Provided utility for this and fixed
set report data preparation. Implemented virtual unplug and send data
methods in daemon.
v1: This patch adds missing hid ipc documentation, hal headers,
renaming and virtual unplug notification in hid HAL.
send RFC for ascii2hex utility.
Unsupported methods are virtual unplug and send data in daemon.
Ravi kumar Veeramally (5):
android/hid: Fix set seport ipc cmd preparation
android/hid: Fix set report data format in daemon
android/hid: Fill send data command struct in hal-hidhost
android/hid: Add send data implemention in daemon
android/hid: Add virtual unplug implemention in daemon
android/hal-hidhost.c | 47 +++++++++++++++++-------
android/hal-msg.h | 2 +-
android/hidhost.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 127 insertions(+), 21 deletions(-)
--
1.8.3.2
^ permalink raw reply
* [PATCH_v3 1/5] android/hid: Fix set seport ipc cmd preparation
From: Ravi kumar Veeramally @ 2013-11-08 10:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383906271-23554-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Now report data is not fixed array. Allocate proper memory
and send ipc cmd.
---
android/hal-hidhost.c | 29 ++++++++++++++++++++---------
android/hal-msg.h | 2 +-
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 34f9f77..ce3dcd7 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
+#include <stdlib.h>
#include "hal-log.h"
#include "hal.h"
@@ -297,7 +298,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
bthh_report_type_t report_type,
char *report)
{
- struct hal_cmd_hidhost_set_report cmd;
+ struct hal_cmd_hidhost_set_report *cmd;
+ int cmd_len, status;
DBG("");
@@ -307,26 +309,35 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
if (!bd_addr || !report)
return BT_STATUS_PARM_INVALID;
- memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
- cmd.len = strlen(report);
- memcpy(cmd.data, report, cmd.len);
+ cmd_len = sizeof(*cmd) + sizeof(struct hal_cmd_hidhost_set_report)
+ + 1 + strlen(report);
+
+ cmd = malloc(cmd_len);
+ memset(cmd, 0, cmd_len);
+ memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
+ cmd->len = strlen(report);
+ memcpy(cmd->data, report, cmd->len);
switch (report_type) {
case BTHH_INPUT_REPORT:
- cmd.type = HAL_HIDHOST_INPUT_REPORT;
+ cmd->type = HAL_HIDHOST_INPUT_REPORT;
break;
case BTHH_OUTPUT_REPORT:
- cmd.type = HAL_HIDHOST_OUTPUT_REPORT;
+ cmd->type = HAL_HIDHOST_OUTPUT_REPORT;
break;
case BTHH_FEATURE_REPORT:
- cmd.type = HAL_HIDHOST_FEATURE_REPORT;
+ cmd->type = HAL_HIDHOST_FEATURE_REPORT;
break;
default:
+ free(cmd);
return BT_STATUS_PARM_INVALID;
}
- return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
- sizeof(cmd), &cmd, 0, NULL, NULL);
+ status = hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
+ cmd_len, cmd, 0, NULL, NULL);
+ free(cmd);
+
+ return status;
}
static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 851875e..7ba2e00 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -293,7 +293,7 @@ struct hal_cmd_hidhost_set_report {
uint8_t bdaddr[6];
uint8_t type;
uint16_t len;
- uint8_t data[670];
+ uint8_t data[0];
} __attribute__((packed));
#define HAL_OP_HIDHOST_SEND_DATA 0x09
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v3 2/5] android/hid: Fix set report data format in daemon
From: Ravi kumar Veeramally @ 2013-11-08 10:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383906271-23554-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Report data coming to HAL is in ascii format, HAL sends
data in hex to daemon, so convert to binary.
---
android/hidhost.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index c7b4114..9b4bb15 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -98,6 +98,14 @@ struct hid_device {
uint8_t last_hid_msg;
};
+static void hex2bin(const uint8_t *ascii, int ascii_len, uint8_t *hex)
+{
+ int i;
+
+ for (i = 0; i < ascii_len / 2; i++)
+ sscanf((char *) &ascii[i * 2], "%hhx", &hex[i]);
+}
+
static int device_cmp(gconstpointer s, gconstpointer user_data)
{
const struct hid_device *dev = s;
@@ -900,18 +908,20 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hidhost_set_report *cmd,
return HAL_STATUS_FAILED;
dev = l->data;
- req_size = 1 + cmd->len;
+ /* Report data coming to HAL is in ascii format, HAL sends
+ * data in hex to daemon, so convert to binary. */
+ req_size = 1 + (cmd->len / 2);
req = g_try_malloc0(req_size);
if (!req)
return HAL_STATUS_NOMEM;
req[0] = HID_MSG_SET_REPORT | cmd->type;
- memcpy(req + 1, cmd->data, req_size - 1);
+ hex2bin(cmd->data, cmd->len, (req + 1));
fd = g_io_channel_unix_get_fd(dev->ctrl_io);
if (write(fd, req, req_size) < 0) {
- error("error while querying device protocol");
+ error("error while sending report");
g_free(req);
return HAL_STATUS_FAILED;
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v3 3/5] android/hid: Fill send data command struct in hal-hidhost
From: Ravi kumar Veeramally @ 2013-11-08 10:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383906271-23554-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-hidhost.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index ce3dcd7..ec120ed 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -342,7 +342,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
{
- struct hal_cmd_hidhost_send_data cmd;
+ struct hal_cmd_hidhost_send_data *cmd;
+ int cmd_len, status;
DBG("");
@@ -352,10 +353,19 @@ static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
if (!bd_addr || !data)
return BT_STATUS_PARM_INVALID;
- memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+ cmd_len = sizeof(*cmd) + sizeof(struct hal_cmd_hidhost_send_data)
+ + 1 + strlen(data);
- return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
- sizeof(cmd), &cmd, 0, NULL, NULL);
+ cmd = malloc(cmd_len);
+ memset(cmd, 0, cmd_len);
+ memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
+ cmd->len = strlen(data);
+ memcpy(cmd->data, data, cmd->len);
+
+ status = hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
+ cmd_len, cmd, 0, NULL, NULL);
+ free(cmd);
+ return status;
}
static bt_status_t init(bthh_callbacks_t *callbacks)
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v3 4/5] android/hid: Add send data implemention in daemon
From: Ravi kumar Veeramally @ 2013-11-08 10:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383906271-23554-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Send data on interrupt channel on request from hid host.
---
android/hidhost.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index 9b4bb15..612dff4 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -934,9 +934,43 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hidhost_set_report *cmd,
static uint8_t bt_hid_send_data(struct hal_cmd_hidhost_send_data *cmd,
uint16_t len)
{
- DBG("Not Implemented");
+ struct hid_device *dev;
+ GSList *l;
+ bdaddr_t dst;
+ int fd;
+ uint8_t *req;
+ uint8_t req_size;
- return HAL_STATUS_FAILED;
+ DBG("");
+
+ if (len < sizeof(*cmd))
+ return HAL_STATUS_INVALID;
+
+ android2bdaddr(&cmd->bdaddr, &dst);
+
+ l = g_slist_find_custom(devices, &dst, device_cmp);
+ if (!l)
+ return HAL_STATUS_FAILED;
+
+ dev = l->data;
+ req_size = 1 + (cmd->len / 2);
+ req = g_try_malloc0(req_size);
+ if (!req)
+ return HAL_STATUS_NOMEM;
+
+ req[0] = HID_MSG_DATA | HID_DATA_TYPE_OUTPUT;
+ hex2bin(cmd->data, cmd->len, (req + 1));
+
+ fd = g_io_channel_unix_get_fd(dev->intr_io);
+
+ if (write(fd, req, req_size) < 0) {
+ error("error while sending data to device");
+ g_free(req);
+ return HAL_STATUS_FAILED;
+ }
+
+ g_free(req);
+ return HAL_STATUS_SUCCESS;
}
void bt_hid_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v3 5/5] android/hid: Add virtual unplug implemention in daemon
From: Ravi kumar Veeramally @ 2013-11-08 10:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383906271-23554-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Send virtual unplug command to hid device and disconnect and remove
hid device details.
---
android/hidhost.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index 612dff4..ac6a3b9 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -55,6 +55,7 @@
#define UHID_DEVICE_FILE "/dev/uhid"
/* HID message types */
+#define HID_MSG_CONTROL 0x10
#define HID_MSG_GET_REPORT 0x40
#define HID_MSG_SET_REPORT 0x50
#define HID_MSG_GET_PROTOCOL 0x60
@@ -73,6 +74,9 @@
/* HID GET REPORT Size Field */
#define HID_GET_REPORT_SIZE_FIELD 0x08
+/* HID Virtual Cable Unplug */
+#define HID_VIRTUAL_CABLE_UNPLUG 0x05
+
static int notification_sk = -1;
static GIOChannel *ctrl_io = NULL;
static GIOChannel *intr_io = NULL;
@@ -752,9 +756,46 @@ static uint8_t bt_hid_disconnect(struct hal_cmd_hidhost_disconnect *cmd,
static uint8_t bt_hid_virtual_unplug(struct hal_cmd_hidhost_vp *cmd,
uint16_t len)
{
- DBG("Not Implemented");
+ struct hid_device *dev;
+ GSList *l;
+ bdaddr_t dst;
+ uint8_t hdr;
+ int fd;
- return HAL_STATUS_FAILED;
+ DBG("");
+
+ if (len < sizeof(*cmd))
+ return HAL_STATUS_INVALID;
+
+ android2bdaddr(&cmd->bdaddr, &dst);
+
+ l = g_slist_find_custom(devices, &dst, device_cmp);
+ if (!l)
+ return HAL_STATUS_FAILED;
+
+ dev = l->data;
+ hdr = HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG;
+
+ if (!(dev->ctrl_io))
+ return HAL_STATUS_FAILED;
+
+ fd = g_io_channel_unix_get_fd(dev->ctrl_io);
+
+ if (write(fd, &hdr, sizeof(hdr)) < 0) {
+ error("error while virtual unplug command");
+ return HAL_STATUS_FAILED;
+ }
+
+ /* Wait either channels to HUP */
+ if (dev->intr_io)
+ g_io_channel_shutdown(dev->intr_io, TRUE, NULL);
+
+ if (dev->ctrl_io)
+ g_io_channel_shutdown(dev->ctrl_io, TRUE, NULL);
+
+ bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTING);
+
+ return HAL_STATUS_SUCCESS;
}
static uint8_t bt_hid_info(struct hal_cmd_hidhost_set_info *cmd, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH] android: Fix pan service registration
From: Johan Hedberg @ 2013-11-08 10:46 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth, Marcin Kraglak
In-Reply-To: <1383904308-15141-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon/Marcin,
On Fri, Nov 08, 2013, Szymon Janc wrote:
> From: Marcin Kraglak <marcin.kraglak@tieto.com>
>
> A2dp service was registered instead of pan.
> ---
> android/main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCHv4 2/3] android/debug: Convert uuid helper to use uint8_t buffer
From: Johan Hedberg @ 2013-11-08 10:49 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1383903349-17487-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Fri, Nov 08, 2013, Andrei Emeltchenko wrote:
> -char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf)
> +char *bt_uuid_t2str(const uint8_t *uuid, size_t len, char *buf)
I don't understand what you need the len parameter for. Won't you always
be passing 16 bytes to this function?
Johan
^ permalink raw reply
* Re: [PATCH_v3 2/5] android/hid: Fix set report data format in daemon
From: Johan Hedberg @ 2013-11-08 11:05 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383906271-23554-3-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Fri, Nov 08, 2013, Ravi kumar Veeramally wrote:
> Report data coming to HAL is in ascii format, HAL sends
> data in hex to daemon, so convert to binary.
> ---
> android/hidhost.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/android/hidhost.c b/android/hidhost.c
> index c7b4114..9b4bb15 100644
> --- a/android/hidhost.c
> +++ b/android/hidhost.c
> @@ -98,6 +98,14 @@ struct hid_device {
> uint8_t last_hid_msg;
> };
>
> +static void hex2bin(const uint8_t *ascii, int ascii_len, uint8_t *hex)
> +{
> + int i;
> +
> + for (i = 0; i < ascii_len / 2; i++)
> + sscanf((char *) &ascii[i * 2], "%hhx", &hex[i]);
> +}
You're still calling the input parameter ascii and the output parameter
hex. Also, I'm still fine if you just drop this function altogether and
do the conversion inline in the two places that you need it.
> if (write(fd, req, req_size) < 0) {
> - error("error while querying device protocol");
> + error("error while sending report");
If you're fixing this error, how about fixing it to properly print the
exact error in the same go, i.e. using strerror?
Johan
^ permalink raw reply
* Re: [PATCH_v3 1/5] android/hid: Fix set seport ipc cmd preparation
From: Johan Hedberg @ 2013-11-08 11:07 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383906271-23554-2-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Fri, Nov 08, 2013, Ravi kumar Veeramally wrote:
> Now report data is not fixed array. Allocate proper memory
> and send ipc cmd.
> ---
> android/hal-hidhost.c | 29 ++++++++++++++++++++---------
> android/hal-msg.h | 2 +-
> 2 files changed, 21 insertions(+), 10 deletions(-)
>
> diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
> index 34f9f77..ce3dcd7 100644
> --- a/android/hal-hidhost.c
> +++ b/android/hal-hidhost.c
> @@ -18,6 +18,7 @@
> #include <stdbool.h>
> #include <stddef.h>
> #include <string.h>
> +#include <stdlib.h>
>
> #include "hal-log.h"
> #include "hal.h"
> @@ -297,7 +298,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
> bthh_report_type_t report_type,
> char *report)
> {
> - struct hal_cmd_hidhost_set_report cmd;
> + struct hal_cmd_hidhost_set_report *cmd;
> + int cmd_len, status;
The return type of this function is bt_status_t, not int (even though
the two are in practice compatible).
Are you sure you don't want to keep using a stack variable? You could
potentially just define a buffer with the max mtu size and use that.
Johan
^ permalink raw reply
* Re: Intel 7260 bluetooth malfunction when it is connected to EHCI bus
From: Michal Labedzki @ 2013-11-08 11:17 UTC (permalink / raw)
To: Hui Wang
Cc: Stevie Trujillo, Marcel Holtmann, tedd.an,
linux-bluetooth@vger.kernel.org development
In-Reply-To: <527C41C5.8070209@canonical.com>
Hello,
Could you create a bug for Wireshark? (capture log are welcome)
https://bugs.wireshark.org/bugzilla/buglist.cgi?resolution=3D---&query_form=
at=3Dadvanced&list_id=3D11313
I check and that is right. There are two commands shares the same
code. "Setup Synchronous Connection" and "Accept Synchronous
Connection Request". But second one should be different. I can fix
that.
Also I recommend to try latest development Wireshark - it is generally stab=
le.
On 8 November 2013 02:43, Hui Wang <hui.wang@canonical.com> wrote:
> On 11/07/2013 06:07 PM, Stevie Trujillo wrote:
>>
>> On Thu, 07 Nov 2013 11:45:53 +0800
>> Hui Wang <hui.wang@canonical.com> wrote:
>>
>>> Do you know any tools can decode the log generated by usbmon?
>>
>> Hmm, I never actually used the usbmon program. I did "modprobe usbmon",
>> then Wireshark shows usbmon{1..4} (one for each bus) as an interface
>> like eth0 for ethernet. http://wiki.wireshark.org/CaptureSetup/USB
>>
>> If it's difficult to compare two captures in Wireshark (I don't know any
>> other method than visual inspection), tshark (Wireshark's "command-line
>> counter-part") is able to decode to stdout. Maybe one can run the diff
>> program on that. The output seems a bit terse however.
>>
>> Please be aware: in my Wireshark (1.10.2) one of the of the SCO setup
>> packets are decoded slightly wrong. It looks like Wireshark is missing
>> a BDADDR in the beginning, so all the other fields get shifted.
>>
>>
> Thanks for sharing this knowledge, i will have a try according to your
> instructions.
>
> Regards,
> Hui.
>
> --
> 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
--=20
Pozdrawiam / Best regards
---------------------------------------------------------------------------=
----------------------------------
Micha=C5=82 =C5=81ab=C4=99dzki, Software Engineer
Tieto Corporation
Product Development Services
http://www.tieto.com / http://www.tieto.pl
---
ASCII: Michal Labedzki
location: Swobodna 1 Street, 50-088 Wroc=C5=82aw, Poland
room: 5.01 (desk next to 5.08)
---
Please note: The information contained in this message may be legally
privileged and confidential and protected from disclosure. If the
reader of this message is not the intended recipient, you are hereby
notified that any unauthorised use, distribution or copying of this
communication is strictly prohibited. If you have received this
communication in error, please notify us immediately by replying to
the message and deleting it from your computer. Thank You.
---
Please consider the environment before printing this e-mail.
---
Tieto Poland sp=C3=B3=C5=82ka z ograniczon=C4=85 odpowiedzialno=C5=9Bci=C4=
=85 z siedzib=C4=85 w
Szczecinie, ul. Malczewskiego 26. Zarejestrowana w S=C4=85dzie Rejonowym
Szczecin-Centrum w Szczecinie, XIII Wydzia=C5=82 Gospodarczy Krajowego
Rejestru S=C4=85dowego pod numerem 0000124858. NIP: 8542085557. REGON:
812023656. Kapita=C5=82 zak=C5=82adowy: 4 271500 PLN
^ permalink raw reply
* Re: [PATCHv4 2/3] android/debug: Convert uuid helper to use uint8_t buffer
From: Andrei Emeltchenko @ 2013-11-08 11:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <20131108104953.GB28608@x220.p-661hnu-f1>
Hi Johan,
On Fri, Nov 08, 2013 at 12:49:53PM +0200, Johan Hedberg wrote:
> Hi Andrei,
>
> On Fri, Nov 08, 2013, Andrei Emeltchenko wrote:
> > -char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf)
> > +char *bt_uuid_t2str(const uint8_t *uuid, size_t len, char *buf)
>
> I don't understand what you need the len parameter for. Won't you always
> be passing 16 bytes to this function?
OK I'll remove len.
Best regards
Andrei Emeltchenko
^ permalink raw reply
* Re: [PATCH_v3 2/5] android/hid: Fix set report data format in daemon
From: Ravi Kumar Veeramally @ 2013-11-08 11:26 UTC (permalink / raw)
To: linux-bluetooth, Johan Hedberg
In-Reply-To: <20131108110528.GC28608@x220.p-661hnu-f1>
Hi Johan,
On 11/08/2013 01:05 PM, Johan Hedberg wrote:
> Hi Ravi,
>
> On Fri, Nov 08, 2013, Ravi kumar Veeramally wrote:
>> Report data coming to HAL is in ascii format, HAL sends
>> data in hex to daemon, so convert to binary.
>> ---
>> android/hidhost.c | 16 +++++++++++++---
>> 1 file changed, 13 insertions(+), 3 deletions(-)
>>
>> diff --git a/android/hidhost.c b/android/hidhost.c
>> index c7b4114..9b4bb15 100644
>> --- a/android/hidhost.c
>> +++ b/android/hidhost.c
>> @@ -98,6 +98,14 @@ struct hid_device {
>> uint8_t last_hid_msg;
>> };
>>
>> +static void hex2bin(const uint8_t *ascii, int ascii_len, uint8_t *hex)
>> +{
>> + int i;
>> +
>> + for (i = 0; i < ascii_len / 2; i++)
>> + sscanf((char *) &ascii[i * 2], "%hhx", &hex[i]);
>> +}
> You're still calling the input parameter ascii and the output parameter
> hex. Also, I'm still fine if you just drop this function altogether and
> do the conversion inline in the two places that you need it.
Ok.
>> if (write(fd, req, req_size) < 0) {
>> - error("error while querying device protocol");
>> + error("error while sending report");
> If you're fixing this error, how about fixing it to properly print the
> exact error in the same go, i.e. using strerror?
>
Ok, I will send this in another patch, have to fix other debugs also.
Thanks,
Ravi.
^ permalink raw reply
* Re: [PATCH_v3 1/5] android/hid: Fix set seport ipc cmd preparation
From: Ravi Kumar Veeramally @ 2013-11-08 11:28 UTC (permalink / raw)
To: linux-bluetooth, Johan Hedberg
In-Reply-To: <20131108110757.GD28608@x220.p-661hnu-f1>
Hi Johan,
On 11/08/2013 01:07 PM, Johan Hedberg wrote:
> Hi Ravi,
>
> On Fri, Nov 08, 2013, Ravi kumar Veeramally wrote:
>> Now report data is not fixed array. Allocate proper memory
>> and send ipc cmd.
>> ---
>> android/hal-hidhost.c | 29 ++++++++++++++++++++---------
>> android/hal-msg.h | 2 +-
>> 2 files changed, 21 insertions(+), 10 deletions(-)
>>
>> diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
>> index 34f9f77..ce3dcd7 100644
>> --- a/android/hal-hidhost.c
>> +++ b/android/hal-hidhost.c
>> @@ -18,6 +18,7 @@
>> #include <stdbool.h>
>> #include <stddef.h>
>> #include <string.h>
>> +#include <stdlib.h>
>>
>> #include "hal-log.h"
>> #include "hal.h"
>> @@ -297,7 +298,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
>> bthh_report_type_t report_type,
>> char *report)
>> {
>> - struct hal_cmd_hidhost_set_report cmd;
>> + struct hal_cmd_hidhost_set_report *cmd;
>> + int cmd_len, status;
> The return type of this function is bt_status_t, not int (even though
> the two are in practice compatible).
>
> Are you sure you don't want to keep using a stack variable? You could
> potentially just define a buffer with the max mtu size and use that.
>
> Johan
Ahh , I noticed your commit 49f051b6b62 removing
unnecessary allocations. I will fix that.
Thanks,
Ravi.
^ permalink raw reply
* [PATCH_v4 0/5] Fixed and implemented set report and send data ifaces
From: Ravi kumar Veeramally @ 2013-11-08 12:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
v4: Fixed changes as per Johan's comments. Conversion done inside
functions now. Removed unnecessary allocation in hal-hidhost
v3: Fixed issues as per Johan's and Jerzy' comments and suggestions
Implemented hex2bin as a static funtion and split the patches.
v2: Fixed issues as per Johan's comments and suggestions.
This patch adds missing hid ipc documentation, hal headers,
renaming and virtual unplug notification in hid HAL.
Set report and send data interfaces are receiving data in ascii format
but it should be in hex format. Provided utility for this and fixed
set report data preparation. Implemented virtual unplug and send data
methods in daemon.
v1: This patch adds missing hid ipc documentation, hal headers,
renaming and virtual unplug notification in hid HAL.
send RFC for ascii2hex utility.
Unsupported methods are virtual unplug and send data in daemon.
Ravi kumar Veeramally (5):
android/hid: Fix set seport ipc cmd preparation
android/hid: Fix set report data format in daemon
android/hid: Fill send data command struct in hal-hidhost
android/hid: Add send data implemention in daemon
android/hid: Add virtual unplug implemention in daemon
android/hal-hidhost.c | 29 ++++++++------
android/hal-msg.h | 2 +-
android/hidhost.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 116 insertions(+), 19 deletions(-)
--
1.8.3.2
^ permalink raw reply
* [PATCH_v4 1/5] android/hid: Fix set seport ipc cmd preparation
From: Ravi kumar Veeramally @ 2013-11-08 12:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383912531-1306-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-hidhost.c | 19 +++++++++++--------
android/hal-msg.h | 2 +-
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 94f7e01..a0df7ce 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
+#include <stdlib.h>
#include "hal-log.h"
#include "hal.h"
@@ -298,7 +299,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
bthh_report_type_t report_type,
char *report)
{
- struct hal_cmd_hidhost_set_report cmd;
+ uint8_t buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_hidhost_set_report *cmd = (void *) buf;
DBG("");
@@ -308,26 +310,27 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
if (!bd_addr || !report)
return BT_STATUS_PARM_INVALID;
- memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
- cmd.len = strlen(report);
- memcpy(cmd.data, report, cmd.len);
+ memset(cmd, 0, sizeof(buf));
+ memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
+ cmd->len = strlen(report);
+ memcpy(cmd->data, report, cmd->len);
switch (report_type) {
case BTHH_INPUT_REPORT:
- cmd.type = HAL_HIDHOST_INPUT_REPORT;
+ cmd->type = HAL_HIDHOST_INPUT_REPORT;
break;
case BTHH_OUTPUT_REPORT:
- cmd.type = HAL_HIDHOST_OUTPUT_REPORT;
+ cmd->type = HAL_HIDHOST_OUTPUT_REPORT;
break;
case BTHH_FEATURE_REPORT:
- cmd.type = HAL_HIDHOST_FEATURE_REPORT;
+ cmd->type = HAL_HIDHOST_FEATURE_REPORT;
break;
default:
return BT_STATUS_PARM_INVALID;
}
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
- sizeof(cmd), &cmd, 0, NULL, NULL);
+ sizeof(buf), buf, 0, NULL, NULL);
}
static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 4af86de..4c7d344 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -293,7 +293,7 @@ struct hal_cmd_hidhost_set_report {
uint8_t bdaddr[6];
uint8_t type;
uint16_t len;
- uint8_t data[670];
+ uint8_t data[0];
} __attribute__((packed));
#define HAL_OP_HIDHOST_SEND_DATA 0x09
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v4 2/5] android/hid: Fix set report data format in daemon
From: Ravi kumar Veeramally @ 2013-11-08 12:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383912531-1306-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Report data coming to HAL is in ascii format, HAL sends
data in hex to daemon, so convert to binary.
---
android/hidhost.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index 242fcbc..0e6bae0 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -884,7 +884,7 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hidhost_set_report *cmd,
struct hid_device *dev;
GSList *l;
bdaddr_t dst;
- int fd;
+ int i, fd;
uint8_t *req;
uint8_t req_size;
@@ -900,13 +900,20 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hidhost_set_report *cmd,
return HAL_STATUS_FAILED;
dev = l->data;
- req_size = 1 + cmd->len;
+
+ if (!(dev->ctrl_io))
+ return HAL_STATUS_FAILED;
+
+ req_size = 1 + (cmd->len / 2);
req = g_try_malloc0(req_size);
if (!req)
return HAL_STATUS_NOMEM;
req[0] = HID_MSG_SET_REPORT | cmd->type;
- memcpy(req + 1, cmd->data, req_size - 1);
+ /* Report data coming to HAL is in ascii format, HAL sends
+ * data in hex to daemon, so convert to binary. */
+ for (i = 0; i < (req_size - 1); i++)
+ sscanf((char *) &(cmd->data)[i * 2], "%hhx", &(req + 1)[i]);
fd = g_io_channel_unix_get_fd(dev->ctrl_io);
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v4 3/5] android/hid: Fill send data command struct in hal-hidhost
From: Ravi kumar Veeramally @ 2013-11-08 12:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383912531-1306-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-hidhost.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index a0df7ce..e4a15c0 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -335,7 +335,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
{
- struct hal_cmd_hidhost_send_data cmd;
+ uint8_t buf[BLUEZ_HAL_MTU];
+ struct hal_cmd_hidhost_send_data *cmd = (void *) buf;
DBG("");
@@ -345,10 +346,13 @@ static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
if (!bd_addr || !data)
return BT_STATUS_PARM_INVALID;
- memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+ memset(cmd, 0, sizeof(buf));
+ memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
+ cmd->len = strlen(data);
+ memcpy(cmd->data, data, cmd->len);
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
- sizeof(cmd), &cmd, 0, NULL, NULL);
+ sizeof(buf), buf, 0, NULL, NULL);
}
static bt_status_t init(bthh_callbacks_t *callbacks)
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v4 4/5] android/hid: Add send data implemention in daemon
From: Ravi kumar Veeramally @ 2013-11-08 12:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383912531-1306-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Send data on interrupt channel on request from hid host.
---
android/hidhost.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index 0e6bae0..250288c 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -931,9 +931,50 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hidhost_set_report *cmd,
static uint8_t bt_hid_send_data(struct hal_cmd_hidhost_send_data *cmd,
uint16_t len)
{
- DBG("Not Implemented");
+ struct hid_device *dev;
+ GSList *l;
+ bdaddr_t dst;
+ int i, fd;
+ uint8_t *req;
+ uint8_t req_size;
- return HAL_STATUS_FAILED;
+ DBG("");
+
+ if (len < sizeof(*cmd))
+ return HAL_STATUS_INVALID;
+
+ android2bdaddr(&cmd->bdaddr, &dst);
+
+ l = g_slist_find_custom(devices, &dst, device_cmp);
+ if (!l)
+ return HAL_STATUS_FAILED;
+
+ dev = l->data;
+
+ if (!(dev->intr_io))
+ return HAL_STATUS_FAILED;
+
+ req_size = 1 + (cmd->len / 2);
+ req = g_try_malloc0(req_size);
+ if (!req)
+ return HAL_STATUS_NOMEM;
+
+ req[0] = HID_MSG_DATA | HID_DATA_TYPE_OUTPUT;
+ /* Report data coming to HAL is in ascii format, HAL sends
+ * data in hex to daemon, so convert to binary. */
+ for (i = 0; i < (req_size - 1); i++)
+ sscanf((char *) &(cmd->data)[i * 2], "%hhx", &(req + 1)[i]);
+
+ fd = g_io_channel_unix_get_fd(dev->intr_io);
+
+ if (write(fd, req, req_size) < 0) {
+ error("error while sending data to device");
+ g_free(req);
+ return HAL_STATUS_FAILED;
+ }
+
+ g_free(req);
+ return HAL_STATUS_SUCCESS;
}
void bt_hid_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* [PATCH_v4 5/5] android/hid: Add virtual unplug implemention in daemon
From: Ravi kumar Veeramally @ 2013-11-08 12:08 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383912531-1306-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Send virtual unplug command to hid device and disconnect and remove
hid device details.
---
android/hidhost.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index 250288c..46f992e 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -55,6 +55,7 @@
#define UHID_DEVICE_FILE "/dev/uhid"
/* HID message types */
+#define HID_MSG_CONTROL 0x10
#define HID_MSG_GET_REPORT 0x40
#define HID_MSG_SET_REPORT 0x50
#define HID_MSG_GET_PROTOCOL 0x60
@@ -73,6 +74,9 @@
/* HID GET REPORT Size Field */
#define HID_GET_REPORT_SIZE_FIELD 0x08
+/* HID Virtual Cable Unplug */
+#define HID_VIRTUAL_CABLE_UNPLUG 0x05
+
static int notification_sk = -1;
static GIOChannel *ctrl_io = NULL;
static GIOChannel *intr_io = NULL;
@@ -744,9 +748,47 @@ static uint8_t bt_hid_disconnect(struct hal_cmd_hidhost_disconnect *cmd,
static uint8_t bt_hid_virtual_unplug(struct hal_cmd_hidhost_virtual_unplug *cmd,
uint16_t len)
{
- DBG("Not Implemented");
+ struct hid_device *dev;
+ GSList *l;
+ bdaddr_t dst;
+ uint8_t hdr;
+ int fd;
- return HAL_STATUS_FAILED;
+ DBG("");
+
+ if (len < sizeof(*cmd))
+ return HAL_STATUS_INVALID;
+
+ android2bdaddr(&cmd->bdaddr, &dst);
+
+ l = g_slist_find_custom(devices, &dst, device_cmp);
+ if (!l)
+ return HAL_STATUS_FAILED;
+
+ dev = l->data;
+
+ if (!(dev->ctrl_io))
+ return HAL_STATUS_FAILED;
+
+ hdr = HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG;
+
+ fd = g_io_channel_unix_get_fd(dev->ctrl_io);
+
+ if (write(fd, &hdr, sizeof(hdr)) < 0) {
+ error("error while virtual unplug command");
+ return HAL_STATUS_FAILED;
+ }
+
+ /* Wait either channels to HUP */
+ if (dev->intr_io)
+ g_io_channel_shutdown(dev->intr_io, TRUE, NULL);
+
+ if (dev->ctrl_io)
+ g_io_channel_shutdown(dev->ctrl_io, TRUE, NULL);
+
+ bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTING);
+
+ return HAL_STATUS_SUCCESS;
}
static uint8_t bt_hid_info(struct hal_cmd_hidhost_set_info *cmd, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH_v4 1/5] android/hid: Fix set seport ipc cmd preparation
From: Johan Hedberg @ 2013-11-08 12:15 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383912531-1306-2-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Fri, Nov 08, 2013, Ravi kumar Veeramally wrote:
> - memcpy(cmd.data, report, cmd.len);
> + memset(cmd, 0, sizeof(buf));
How about memset(buf, 0, sizeof(buf)) to make this perfectly clear. Btw,
why is the memset needed? I don't think the original code had it. Seems
like this is an independent bug fix?
> + cmd->len = strlen(report);
> + memcpy(cmd->data, report, cmd->len);
>
> switch (report_type) {
> case BTHH_INPUT_REPORT:
> - cmd.type = HAL_HIDHOST_INPUT_REPORT;
> + cmd->type = HAL_HIDHOST_INPUT_REPORT;
> break;
> case BTHH_OUTPUT_REPORT:
> - cmd.type = HAL_HIDHOST_OUTPUT_REPORT;
> + cmd->type = HAL_HIDHOST_OUTPUT_REPORT;
> break;
> case BTHH_FEATURE_REPORT:
> - cmd.type = HAL_HIDHOST_FEATURE_REPORT;
> + cmd->type = HAL_HIDHOST_FEATURE_REPORT;
> break;
> default:
> return BT_STATUS_PARM_INVALID;
> }
>
> return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
> - sizeof(cmd), &cmd, 0, NULL, NULL);
> + sizeof(buf), buf, 0, NULL, NULL);
This last call looks broken to me. Shouldn't you instead of sizeof(buf)
be sending sizeof(*cmd) + cmd->len?
Johan
^ permalink raw reply
* [PATCH 0/4] Add support for registering local SDP records
From: Szymon Janc @ 2013-11-08 12:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This adds support for manipulating local SDP database with
bt_adapter_add_record and bt_adapter_remove_record functions. Those should
be called when HAL service is registered or unregistered.
This also adds DeviceID record as at least 1 local UUID is needed by Android to
properly handle remote device profiles.
Last but not least: With this serie it is possible to connect HID device from
Android UI (Settings application). \O/
Comments are welcome.
BR
Szymon Janc
Marcin Kraglak (3):
android: Add and remove sdp records and uuids
android: Clear adapter uuids during initialization
android: Add support for getting UUIDs property
Szymon Janc (1):
android: Register DeviceID record when adapter is initialized
android/Android.mk | 1 +
android/adapter.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++++----
android/adapter.h | 4 ++
3 files changed, 180 insertions(+), 12 deletions(-)
--
1.8.4.2
^ permalink raw reply
* [PATCH 1/4] android: Add and remove sdp records and uuids
From: Szymon Janc @ 2013-11-08 12:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383913284-4032-1-git-send-email-szymon.janc@tieto.com>
From: Marcin Kraglak <marcin.kraglak@tieto.com>
This is api for adding and removing sdp records and uuids
via mgmt interface. Local profiles have to store handle to
own records to remove them in cleanup. Additionally list of
uuids is created in bt_adapter struct.
---
android/Android.mk | 1 +
android/adapter.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 4 +++
3 files changed, 106 insertions(+)
diff --git a/android/Android.mk b/android/Android.mk
index 51037a7..9f89dfd 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -39,6 +39,7 @@ LOCAL_SRC_FILES := \
../lib/sdp.c \
../lib/bluetooth.c \
../lib/hci.c \
+ ../lib/uuid.c \
../btio/btio.c \
../src/sdp-client.c \
diff --git a/android/adapter.c b/android/adapter.c
index 65b3170..60b2635 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -39,6 +39,7 @@
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
#include "lib/uuid.h"
+#include "src/sdpd.h"
#include "src/sdp-client.h"
#include "log.h"
#include "hal-msg.h"
@@ -74,6 +75,7 @@ struct bt_adapter {
bool discovering;
uint32_t discoverable_timeout;
+ GSList *uuids;
};
struct browse_req {
@@ -986,6 +988,105 @@ static void load_link_keys(GSList *keys)
}
}
+static void remove_uuid_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ if (status != MGMT_STATUS_SUCCESS) {
+ error("Failed to remove UUID: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+}
+
+static void remove_uuid(const uint8_t *uuid)
+{
+ struct mgmt_cp_remove_uuid cp;
+
+ memcpy(cp.uuid, uuid, sizeof(uint128_t));
+
+
+ mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_UUID,
+ adapter->index, sizeof(cp), &cp,
+ remove_uuid_complete, NULL, NULL);
+}
+
+static void add_uuid_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ if (status != MGMT_STATUS_SUCCESS) {
+ error("Failed to add UUID: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+}
+
+static void add_uuid(uint8_t svc_hint, const uint8_t *uuid)
+{
+ struct mgmt_cp_add_uuid cp;
+
+ memcpy(cp.uuid, uuid, sizeof(uint128_t));
+ cp.svc_hint = svc_hint;
+
+ mgmt_send(adapter->mgmt, MGMT_OP_ADD_UUID,
+ adapter->index, sizeof(cp), &cp,
+ add_uuid_complete, NULL, NULL);
+}
+
+static int uuid_cmp(gconstpointer a, gconstpointer b)
+{
+ const bt_uuid_t *uuid_a = a;
+ const bt_uuid_t *uuid_b = b;
+
+ return bt_uuid_cmp(uuid_a, uuid_b);
+}
+
+int bt_adapter_add_record(const char *uuid, sdp_record_t *rec,
+ uint8_t svc_hint)
+{
+ bt_uuid_t *new_uuid;
+
+ new_uuid = g_new0(bt_uuid_t, 1);
+ bt_string_to_uuid(new_uuid, uuid);
+ if (new_uuid->type != BT_UUID128) {
+ g_free(new_uuid);
+ return -1;
+ }
+
+ if (g_slist_find_custom(adapter->uuids, new_uuid, uuid_cmp)) {
+ DBG("UUID %s already added", uuid);
+ g_free(new_uuid);
+ return -1;
+ }
+
+ adapter->uuids = g_slist_prepend(adapter->uuids, new_uuid);
+ add_uuid(svc_hint, new_uuid->value.u128.data);
+
+ return add_record_to_server(&adapter->bdaddr, rec);
+}
+
+void bt_adapter_remove_record(const char *uuid, int handle)
+{
+ bt_uuid_t bt_uuid;
+ GSList *uuid_found;
+
+ bt_string_to_uuid(&bt_uuid, uuid);
+
+ uuid_found = g_slist_find_custom(adapter->uuids, &bt_uuid, uuid_cmp);
+
+ if (uuid_found) {
+ remove_uuid(bt_uuid.value.u128.data);
+ g_free(uuid_found->data);
+ adapter->uuids = g_slist_remove(adapter->uuids,
+ uuid_found->data);
+ }
+
+ remove_record_from_server(handle);
+}
+
static void set_mode_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
diff --git a/android/adapter.h b/android/adapter.h
index c62b859..0d93917 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -32,3 +32,7 @@ const bdaddr_t *bt_adapter_get_address(void);
bool bt_adapter_register(int sk);
void bt_adapter_unregister(void);
+
+int bt_adapter_add_record(const char *uuid, sdp_record_t *rec,
+ uint8_t svc_hint);
+void bt_adapter_remove_record(const char *uuid, int handle);
--
1.8.4.2
^ permalink raw reply related
* [PATCH 2/4] android: Clear adapter uuids during initialization
From: Szymon Janc @ 2013-11-08 12:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383913284-4032-1-git-send-email-szymon.janc@tieto.com>
From: Marcin Kraglak <marcin.kraglak@tieto.com>
Clear adapter uuids during init. We have to do it before
other profiles will be able to register sdp records and add
their uuids.
---
android/adapter.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 60b2635..8ea104b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1197,6 +1197,17 @@ static uint8_t set_discoverable_timeout(uint8_t *timeout)
return HAL_STATUS_SUCCESS;
}
+
+static void clear_uuids(void)
+{
+ struct mgmt_cp_remove_uuid cp;
+
+ memset(&cp, 0, sizeof(cp));
+
+ mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_UUID, adapter->index,
+ sizeof(cp), &cp, NULL, NULL, NULL);
+}
+
static void read_info_complete(uint8_t status, uint16_t length, const void *param,
void *user_data)
{
@@ -1237,6 +1248,8 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
/* TODO: Register all event notification handlers */
register_mgmt_handlers();
+ clear_uuids();
+
load_link_keys(NULL);
set_io_capability();
--
1.8.4.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