* [PATCH 1/2] android/bluetooth: Set default adapter name on first start
@ 2014-01-09 8:39 Szymon Janc
2014-01-09 8:39 ` [PATCH 2/2] android/bluetooth: Set major and minor class od device Szymon Janc
2014-01-09 9:32 ` [PATCH 1/2] android/bluetooth: Set default adapter name on first start Szymon Janc
0 siblings, 2 replies; 3+ messages in thread
From: Szymon Janc @ 2014-01-09 8:39 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
On first start always set name to default name. Adapter name is
updated on start only if current name is different.
---
android/bluetooth.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 9da988b..6aad9b5 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -50,6 +50,8 @@
#include "utils.h"
#include "bluetooth.h"
+#define DEFAULT_ADAPTER_NAME "BlueZ for Android"
+
#define DUT_MODE_FILE "/sys/kernel/debug/bluetooth/hci%u/dut_mode"
#define DEVICE_ID_SOURCE 0x0002 /* USB */
@@ -1734,15 +1736,17 @@ static void read_info_complete(uint8_t status, uint16_t length,
if (!bacmp(&adapter.bdaddr, BDADDR_ANY)) {
bacpy(&adapter.bdaddr, &rp->bdaddr);
- adapter.name = g_strdup((const char *) rp->name);
+ adapter.name = g_strdup(DEFAULT_ADAPTER_NAME);
store_adapter_config();
- set_adapter_name(rp->name, strlen((char *)rp->name));
} else if (bacmp(&adapter.bdaddr, &rp->bdaddr)) {
error("Bluetooth address mismatch");
err = -ENODEV;
goto failed;
}
+ if (g_strcmp0(adapter.name, (const char *) rp->name))
+ set_adapter_name((uint8_t *)adapter.name, strlen(adapter.name));
+
/* Store adapter information */
adapter.dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
(rp->dev_class[2] << 16);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] android/bluetooth: Set major and minor class od device
2014-01-09 8:39 [PATCH 1/2] android/bluetooth: Set default adapter name on first start Szymon Janc
@ 2014-01-09 8:39 ` Szymon Janc
2014-01-09 9:32 ` [PATCH 1/2] android/bluetooth: Set default adapter name on first start Szymon Janc
1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-01-09 8:39 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Currently this is hardcoded to Phone/Smartphone.
---
android/bluetooth.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 6aad9b5..a43eecb 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -58,6 +58,9 @@
#define DEVICE_ID_VENDOR 0x1d6b /* Linux Foundation */
#define DEVICE_ID_PRODUCT 0x0247 /* BlueZ for Android */
+#define ADAPTER_MAJOR_CLASS 0x02 /* Phone */
+#define ADAPTER_MINOR_CLASS 0x03 /* Smartphone */
+
/* Default to DisplayYesNo */
#define DEFAULT_IO_CAPABILITY 0x01
@@ -1703,6 +1706,26 @@ static void load_devices_info(bt_bluetooth_ready cb)
g_key_file_free(key_file);
}
+static void set_adapter_class(void)
+{
+ struct mgmt_cp_set_dev_class cp;
+
+ memset(&cp, 0, sizeof(cp));
+
+ /*
+ * kernel assign the major and minor numbers straight to dev_class[0]
+ * and dev_class[1] without considering the proper bit shifting.
+ */
+ cp.major = ADAPTER_MAJOR_CLASS & 0x1f;
+ cp.minor = ADAPTER_MINOR_CLASS << 2;
+
+ if (mgmt_send(mgmt_if, MGMT_OP_SET_DEV_CLASS, adapter.index,
+ sizeof(cp), &cp, NULL, NULL, NULL) > 0)
+ return;
+
+ error("Failed to set class of device");
+}
+
static void read_info_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
@@ -1747,6 +1770,8 @@ static void read_info_complete(uint8_t status, uint16_t length,
if (g_strcmp0(adapter.name, (const char *) rp->name))
set_adapter_name((uint8_t *)adapter.name, strlen(adapter.name));
+ set_adapter_class();
+
/* Store adapter information */
adapter.dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
(rp->dev_class[2] << 16);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] android/bluetooth: Set default adapter name on first start
2014-01-09 8:39 [PATCH 1/2] android/bluetooth: Set default adapter name on first start Szymon Janc
2014-01-09 8:39 ` [PATCH 2/2] android/bluetooth: Set major and minor class od device Szymon Janc
@ 2014-01-09 9:32 ` Szymon Janc
1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-01-09 9:32 UTC (permalink / raw)
To: linux-bluetooth
On Thursday 09 of January 2014 09:39:19 Szymon Janc wrote:
> On first start always set name to default name. Adapter name is
> updated on start only if current name is different.
> ---
> android/bluetooth.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 9da988b..6aad9b5 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -50,6 +50,8 @@
> #include "utils.h"
> #include "bluetooth.h"
>
> +#define DEFAULT_ADAPTER_NAME "BlueZ for Android"
> +
> #define DUT_MODE_FILE "/sys/kernel/debug/bluetooth/hci%u/dut_mode"
>
> #define DEVICE_ID_SOURCE 0x0002 /* USB */
> @@ -1734,15 +1736,17 @@ static void read_info_complete(uint8_t status, uint16_t length,
>
> if (!bacmp(&adapter.bdaddr, BDADDR_ANY)) {
> bacpy(&adapter.bdaddr, &rp->bdaddr);
> - adapter.name = g_strdup((const char *) rp->name);
> + adapter.name = g_strdup(DEFAULT_ADAPTER_NAME);
> store_adapter_config();
> - set_adapter_name(rp->name, strlen((char *)rp->name));
> } else if (bacmp(&adapter.bdaddr, &rp->bdaddr)) {
> error("Bluetooth address mismatch");
> err = -ENODEV;
> goto failed;
> }
>
> + if (g_strcmp0(adapter.name, (const char *) rp->name))
> + set_adapter_name((uint8_t *)adapter.name, strlen(adapter.name));
> +
> /* Store adapter information */
> adapter.dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
> (rp->dev_class[2] << 16);
>
Both patches are now pushed upstream.
--
Best regards,
Szymon Janc
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-09 9:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-09 8:39 [PATCH 1/2] android/bluetooth: Set default adapter name on first start Szymon Janc
2014-01-09 8:39 ` [PATCH 2/2] android/bluetooth: Set major and minor class od device Szymon Janc
2014-01-09 9:32 ` [PATCH 1/2] android/bluetooth: Set default adapter name on first start Szymon Janc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox