All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup
@ 2012-03-28 10:03 Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 2/7] Set DeviceID when registering adapter not when sdp server is starting Szymon Janc
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Szymon Janc @ 2012-03-28 10:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

Instead of parsing config DeviceID string on sdp server startup, parse
it in main while reading config file. This allow to store logical DID
values in main_opts (instead of raw config string) and make use of them
in bluetoothd code.
---
 src/hcid.h         |    6 +++++-
 src/main.c         |   20 +++++++++++++++++---
 src/sdpd-server.c  |   19 ++++---------------
 src/sdpd-service.c |   20 +++++++++++---------
 src/sdpd.h         |    5 ++---
 5 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/src/hcid.h b/src/hcid.h
index df2829a..2c1cbff 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -42,7 +42,11 @@ struct main_opts {
 
 	uint8_t		mode;
 	uint8_t		discov_interval;
-	char		deviceid[15]; /* FIXME: */
+
+	uint16_t	did_source;
+	uint16_t	did_vendor;
+	uint16_t	did_product;
+	uint16_t	did_version;
 };
 
 enum {
diff --git a/src/main.c b/src/main.c
index f01e070..4e0cb5a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -87,6 +87,21 @@ static GKeyFile *load_config(const char *file)
 	return keyfile;
 }
 
+static void parse_did(const char *did)
+{
+	int result;
+	uint16_t vendor, product, version = 0x0000; /* version is optional */
+
+	result = sscanf(did, "%4hx:%4hx:%4hx", &vendor, &product, &version);
+	if (result == EOF || result < 2)
+		return;
+
+	main_opts.did_source = 0x0002;
+	main_opts.did_vendor = vendor;
+	main_opts.did_product = product;
+	main_opts.did_version = version;
+}
+
 static void parse_config(GKeyFile *config)
 {
 	GError *err = NULL;
@@ -192,8 +207,7 @@ static void parse_config(GKeyFile *config)
 		g_clear_error(&err);
 	} else {
 		DBG("deviceid=%s", str);
-		strncpy(main_opts.deviceid, str,
-					sizeof(main_opts.deviceid) - 1);
+		parse_did(str);
 		g_free(str);
 	}
 
@@ -516,7 +530,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	start_sdp_server(mtu, main_opts.deviceid, SDP_SERVER_COMPAT);
+	start_sdp_server(mtu, SDP_SERVER_COMPAT);
 
 	/* Loading plugins has to be done after D-Bus has been setup since
 	 * the plugins might wanna expose some paths on the bus. However the
diff --git a/src/sdpd-server.c b/src/sdpd-server.c
index a92ae2c..1d9509e 100644
--- a/src/sdpd-server.c
+++ b/src/sdpd-server.c
@@ -45,6 +45,7 @@
 
 #include <glib.h>
 
+#include "hcid.h"
 #include "log.h"
 #include "sdpd.h"
 
@@ -227,7 +228,7 @@ static gboolean io_accept_event(GIOChannel *chan, GIOCondition cond, gpointer da
 	return TRUE;
 }
 
-int start_sdp_server(uint16_t mtu, const char *did, uint32_t flags)
+int start_sdp_server(uint16_t mtu, uint32_t flags)
 {
 	int compat = flags & SDP_SERVER_COMPAT;
 	int master = flags & SDP_SERVER_MASTER;
@@ -240,20 +241,8 @@ int start_sdp_server(uint16_t mtu, const char *did, uint32_t flags)
 		return -1;
 	}
 
-	if (did && strlen(did) > 0) {
-		const char *ptr = did;
-		uint16_t vid = 0x0000, pid = 0x0000, ver = 0x0000;
-
-		vid = (uint16_t) strtol(ptr, NULL, 16);
-		ptr = strchr(ptr, ':');
-		if (ptr) {
-			pid = (uint16_t) strtol(ptr + 1, NULL, 16);
-			ptr = strchr(ptr + 1, ':');
-			if (ptr)
-				ver = (uint16_t) strtol(ptr + 1, NULL, 16);
-			register_device_id(vid, pid, ver);
-		}
-	}
+	if (main_opts.did_source > 0)
+		register_device_id();
 
 	io = g_io_channel_unix_new(l2cap_sock);
 	g_io_channel_set_close_on_unref(io, TRUE);
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index de11562..eb4b74c 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -44,6 +44,7 @@
 #include <glib.h>
 #include <dbus/dbus.h>
 
+#include "hcid.h"
 #include "sdpd.h"
 #include "log.h"
 #include "adapter.h"
@@ -172,10 +173,9 @@ void register_server_service(void)
 	update_db_timestamp();
 }
 
-void register_device_id(const uint16_t vendor, const uint16_t product,
-						const uint16_t version)
+void register_device_id(void)
 {
-	const uint16_t spec = 0x0102, source = 0x0002;
+	const uint16_t spec = 0x0102;
 	const uint8_t primary = 1;
 	sdp_list_t *class_list, *group_list, *profile_list;
 	uuid_t class_uuid, group_uuid;
@@ -184,9 +184,11 @@ void register_device_id(const uint16_t vendor, const uint16_t product,
 	sdp_profile_desc_t profile;
 	sdp_record_t *record = sdp_record_alloc();
 
-	info("Adding device id record for %04x:%04x", vendor, product);
+	info("Adding device id record for %04x:%04x:%04x", main_opts.did_vendor,
+				main_opts.did_product, main_opts.did_version);
 
-	btd_manager_set_did(vendor, product, version);
+	btd_manager_set_did(main_opts.did_vendor, main_opts.did_product,
+							main_opts.did_version);
 
 	record->handle = sdp_next_handle();
 
@@ -213,19 +215,19 @@ void register_device_id(const uint16_t vendor, const uint16_t product,
 	spec_data = sdp_data_alloc(SDP_UINT16, &spec);
 	sdp_attr_add(record, 0x0200, spec_data);
 
-	vendor_data = sdp_data_alloc(SDP_UINT16, &vendor);
+	vendor_data = sdp_data_alloc(SDP_UINT16, &main_opts.did_vendor);
 	sdp_attr_add(record, 0x0201, vendor_data);
 
-	product_data = sdp_data_alloc(SDP_UINT16, &product);
+	product_data = sdp_data_alloc(SDP_UINT16, &main_opts.did_product);
 	sdp_attr_add(record, 0x0202, product_data);
 
-	version_data = sdp_data_alloc(SDP_UINT16, &version);
+	version_data = sdp_data_alloc(SDP_UINT16, &main_opts.did_version);
 	sdp_attr_add(record, 0x0203, version_data);
 
 	primary_data = sdp_data_alloc(SDP_BOOL, &primary);
 	sdp_attr_add(record, 0x0204, primary_data);
 
-	source_data = sdp_data_alloc(SDP_UINT16, &source);
+	source_data = sdp_data_alloc(SDP_UINT16, &main_opts.did_source);
 	sdp_attr_add(record, 0x0205, source_data);
 
 	update_db_timestamp();
diff --git a/src/sdpd.h b/src/sdpd.h
index 9f5415f..83d2b03 100644
--- a/src/sdpd.h
+++ b/src/sdpd.h
@@ -53,8 +53,7 @@ int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp);
 
 void register_public_browse_group(void);
 void register_server_service(void);
-void register_device_id(const uint16_t vendor, const uint16_t product,
-						const uint16_t version);
+void register_device_id(void);
 
 int record_sort(const void *r1, const void *r2);
 void sdp_svcdb_reset(void);
@@ -74,7 +73,7 @@ uint32_t sdp_get_time(void);
 #define SDP_SERVER_COMPAT (1 << 0)
 #define SDP_SERVER_MASTER (1 << 1)
 
-int start_sdp_server(uint16_t mtu, const char *did, uint32_t flags);
+int start_sdp_server(uint16_t mtu, uint32_t flags);
 void stop_sdp_server(void);
 
 int add_record_to_server(const bdaddr_t *src, sdp_record_t *rec);
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 2/7] Set DeviceID when registering adapter not when sdp server is starting
  2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
@ 2012-03-28 10:03 ` Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 3/7] Add support for setting VID source in DeviceID from config file Szymon Janc
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Szymon Janc @ 2012-03-28 10:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

Adapter ops are registered after sdp server is started. Thus no
adapters were registered yet when setting DID on sdp startup and DID
was never set.
---
 src/manager.c      |   15 ++++-----------
 src/manager.h      |    1 -
 src/sdpd-service.c |    3 ---
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index 8c49457..3afc581 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -413,6 +413,10 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
 	if (default_adapter_id < 0)
 		manager_set_default_adapter(id);
 
+	if (main_opts.did_source)
+		btd_adapter_set_did(adapter, main_opts.did_vendor,
+				main_opts.did_product, main_opts.did_version);
+
 	DBG("Adapter %s registered", path);
 
 	return btd_adapter_ref(adapter);
@@ -435,14 +439,3 @@ int btd_manager_unregister_adapter(int id)
 
 	return 0;
 }
-
-void btd_manager_set_did(uint16_t vendor, uint16_t product, uint16_t version)
-{
-	GSList *l;
-
-	for (l = adapters; l != NULL; l = g_slist_next(l)) {
-		struct btd_adapter *adapter = l->data;
-
-		btd_adapter_set_did(adapter, vendor, product, version);
-	}
-}
diff --git a/src/manager.h b/src/manager.h
index 0056909..264cd25 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -41,4 +41,3 @@ GSList *manager_get_adapters(void);
 struct btd_adapter *btd_manager_register_adapter(int id, gboolean up);
 int btd_manager_unregister_adapter(int id);
 void manager_add_adapter(const char *path);
-void btd_manager_set_did(uint16_t vendor, uint16_t product, uint16_t version);
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index eb4b74c..ef00760 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -187,9 +187,6 @@ void register_device_id(void)
 	info("Adding device id record for %04x:%04x:%04x", main_opts.did_vendor,
 				main_opts.did_product, main_opts.did_version);
 
-	btd_manager_set_did(main_opts.did_vendor, main_opts.did_product,
-							main_opts.did_version);
-
 	record->handle = sdp_next_handle();
 
 	sdp_record_add(BDADDR_ANY, record);
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 3/7] Add support for setting VID source in DeviceID from config file
  2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 2/7] Set DeviceID when registering adapter not when sdp server is starting Szymon Janc
@ 2012-03-28 10:03 ` Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 4/7] mgmtops: Add support for setting Device ID Szymon Janc
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Szymon Janc @ 2012-03-28 10:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

This allows to set if VID source is Bluetooth SIG or USB. Assigner is
provided as string {bluetooth,usb} and fallback to usb if none is set
in config.
---
 plugins/hciops.c   |    7 +++++--
 plugins/mgmtops.c  |    6 +++---
 src/adapter.c      |    6 ++++--
 src/adapter.h      |    5 +++--
 src/eir.c          |    7 +++----
 src/eir.h          |    2 +-
 src/main.c         |   19 +++++++++++++++++--
 src/main.conf      |    8 +++++---
 src/manager.c      |    4 +++-
 src/sdpd-service.c |    3 ++-
 10 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 4f287f0..6b4a82c 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -147,6 +147,7 @@ static struct dev_info {
 
 	struct hci_version ver;
 
+	uint16_t did_source;
 	uint16_t did_vendor;
 	uint16_t did_product;
 	uint16_t did_version;
@@ -672,7 +673,8 @@ static void update_ext_inquiry_response(int index)
 	memset(&cp, 0, sizeof(cp));
 
 	eir_create(dev->name, dev->tx_power, dev->did_vendor, dev->did_product,
-					dev->did_version, dev->uuids, cp.data);
+			dev->did_version, dev->did_source, dev->uuids,
+			cp.data);
 
 	if (memcmp(cp.data, dev->eir, sizeof(cp.data)) == 0)
 		return;
@@ -886,13 +888,14 @@ fail:
 }
 
 static int hciops_set_did(int index, uint16_t vendor, uint16_t product,
-							uint16_t version)
+					uint16_t version, uint16_t source)
 {
 	struct dev_info *dev = &devs[index];
 
 	dev->did_vendor = vendor;
 	dev->did_product = product;
 	dev->did_version = version;
+	dev->did_source = source;
 
 	return 0;
 }
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 4aa38fe..c24757c 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -2116,10 +2116,10 @@ static int mgmt_encrypt_link(int index, bdaddr_t *dst, bt_hci_result_t cb,
 }
 
 static int mgmt_set_did(int index, uint16_t vendor, uint16_t product,
-							uint16_t version)
+					uint16_t version, uint16_t source)
 {
-	DBG("index %d vendor %u product %u version %u",
-					index, vendor, product, version);
+	DBG("index %d vendor %u product %u version %u source %u",
+				index, vendor, product, version, source);
 	return -ENOSYS;
 }
 
diff --git a/src/adapter.c b/src/adapter.c
index 7a2214a..0b4f9ba 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3476,9 +3476,11 @@ int btd_adapter_encrypt_link(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 }
 
 int btd_adapter_set_did(struct btd_adapter *adapter, uint16_t vendor,
-					uint16_t product, uint16_t version)
+					uint16_t product, uint16_t version,
+					uint16_t source)
 {
-	return adapter_ops->set_did(adapter->dev_id, vendor, product, version);
+	return adapter_ops->set_did(adapter->dev_id, vendor, product, version,
+								source);
 }
 
 int adapter_create_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/adapter.h b/src/adapter.h
index ceebb97..c47d180 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -212,7 +212,7 @@ struct btd_adapter_ops {
 	int (*encrypt_link) (int index, bdaddr_t *bdaddr, bt_hci_result_t cb,
 							gpointer user_data);
 	int (*set_did) (int index, uint16_t vendor, uint16_t product,
-							uint16_t version);
+					uint16_t version, uint16_t source);
 	int (*add_uuid) (int index, uuid_t *uuid, uint8_t svc_hint);
 	int (*remove_uuid) (int index, uuid_t *uuid);
 	int (*disable_cod_cache) (int index);
@@ -274,7 +274,8 @@ int btd_adapter_encrypt_link(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				bt_hci_result_t cb, gpointer user_data);
 
 int btd_adapter_set_did(struct btd_adapter *adapter, uint16_t vendor,
-					uint16_t product, uint16_t version);
+					uint16_t product, uint16_t version,
+					uint16_t source);
 
 int adapter_create_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				uint8_t addr_type, uint8_t io_cap);
diff --git a/src/eir.c b/src/eir.c
index 419f444..800dafa 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -232,7 +232,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
-			GSList *uuids, uint8_t *data)
+			uint16_t did_source, GSList *uuids, uint8_t *data)
 {
 	GSList *l;
 	uint8_t *ptr = data;
@@ -269,11 +269,10 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	}
 
 	if (did_vendor != 0x0000) {
-		uint16_t source = 0x0002;
 		*ptr++ = 9;
 		*ptr++ = EIR_DEVICE_ID;
-		*ptr++ = (source & 0x00ff);
-		*ptr++ = (source & 0xff00) >> 8;
+		*ptr++ = (did_source & 0x00ff);
+		*ptr++ = (did_source & 0xff00) >> 8;
 		*ptr++ = (did_vendor & 0x00ff);
 		*ptr++ = (did_vendor & 0xff00) >> 8;
 		*ptr++ = (did_product & 0x00ff);
diff --git a/src/eir.h b/src/eir.h
index 13311ef..c040e49 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -52,7 +52,7 @@ void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
-			GSList *uuids, uint8_t *data);
+			uint16_t did_source, GSList *uuids, uint8_t *data);
 
 gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type);
 
diff --git a/src/main.c b/src/main.c
index 4e0cb5a..8763bf9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -90,13 +90,28 @@ static GKeyFile *load_config(const char *file)
 static void parse_did(const char *did)
 {
 	int result;
-	uint16_t vendor, product, version = 0x0000; /* version is optional */
+	uint16_t vendor, product, version , source;
+
+	/* version and source are optional */
+	version = 0x0000;
+	source = 0x0002;
+
+	result = sscanf(did, "bluetooth:%4hx:%4hx:%4hx", &vendor, &product, &version);
+	if (result != EOF && result >= 2) {
+		source = 0x0001;
+		goto done;
+	}
+
+	result = sscanf(did, "usb:%4hx:%4hx:%4hx", &vendor, &product, &version);
+	if (result != EOF && result >= 2)
+		goto done;
 
 	result = sscanf(did, "%4hx:%4hx:%4hx", &vendor, &product, &version);
 	if (result == EOF || result < 2)
 		return;
 
-	main_opts.did_source = 0x0002;
+done:
+	main_opts.did_source = source;
 	main_opts.did_vendor = vendor;
 	main_opts.did_product = product;
 	main_opts.did_version = version;
diff --git a/src/main.conf b/src/main.conf
index 469c077..3419d07 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -43,9 +43,11 @@ InitiallyPowered = true
 # Remember the previously stored Powered state when initializing adapters
 RememberPowered = true
 
-# Use vendor, product and version information for DID profile support.
-# The values are separated by ":" and VID, PID and version.
-#DeviceID = 1234:5678:abcd
+# Use vendor id source (assigner), vendor, product and version information for
+# DID profile support. The values are separated by ":" and assigner, VID, PID
+# and version.
+# Possible vendor id source values: bluetooth, usb (defaults to usb)
+#DeviceID = bluetooth:1234:5678:abcd
 
 # Do reverse service discovery for previously unknown devices that connect to
 # us. This option is really only needed for qualification since the BITE tester
diff --git a/src/manager.c b/src/manager.c
index 3afc581..6244516 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -415,7 +415,9 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
 
 	if (main_opts.did_source)
 		btd_adapter_set_did(adapter, main_opts.did_vendor,
-				main_opts.did_product, main_opts.did_version);
+						main_opts.did_product,
+						main_opts.did_version,
+						main_opts.did_source);
 
 	DBG("Adapter %s registered", path);
 
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index ef00760..a6ed90e 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -184,7 +184,8 @@ void register_device_id(void)
 	sdp_profile_desc_t profile;
 	sdp_record_t *record = sdp_record_alloc();
 
-	info("Adding device id record for %04x:%04x:%04x", main_opts.did_vendor,
+	info("Adding device id record for %04x:%04x:%04x:%04x",
+				main_opts.did_source, main_opts.did_vendor,
 				main_opts.did_product, main_opts.did_version);
 
 	record->handle = sdp_next_handle();
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 4/7] mgmtops: Add support for setting Device ID
  2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 2/7] Set DeviceID when registering adapter not when sdp server is starting Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 3/7] Add support for setting VID source in DeviceID from config file Szymon Janc
@ 2012-03-28 10:03 ` Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 5/7] btmgmt: " Szymon Janc
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Szymon Janc @ 2012-03-28 10:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

---
 lib/mgmt.h        |    9 +++++++++
 plugins/mgmtops.c |   27 ++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index f3bc6da..c9b0f1a 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -311,6 +311,14 @@ struct mgmt_cp_unblock_device {
 	struct mgmt_addr_info addr;
 } __packed;
 
+#define MGMT_OP_SET_DEVICE_ID		0x0028
+struct mgmt_cp_set_device_id {
+	uint16_t source;
+	uint16_t vendor;
+	uint16_t product;
+	uint16_t version;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	uint16_t opcode;
@@ -475,6 +483,7 @@ static const char *mgmt_op[] = {
 	"Confirm Name",
 	"Block Device",
 	"Unblock Device",
+	"Set Device ID",
 };
 
 static const char *mgmt_ev[] = {
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index c24757c..c08117f 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1426,6 +1426,9 @@ static void mgmt_cmd_complete(int sk, uint16_t index, void *buf, size_t len)
 	case MGMT_OP_STOP_DISCOVERY:
 		DBG("stop_discovery complete");
 		break;
+	case MGMT_OP_SET_DEVICE_ID:
+		DBG("set_did complete");
+		break;
 	default:
 		error("Unknown command complete for opcode %u", opcode);
 		break;
@@ -2118,9 +2121,27 @@ static int mgmt_encrypt_link(int index, bdaddr_t *dst, bt_hci_result_t cb,
 static int mgmt_set_did(int index, uint16_t vendor, uint16_t product,
 					uint16_t version, uint16_t source)
 {
-	DBG("index %d vendor %u product %u version %u source %u",
-				index, vendor, product, version, source);
-	return -ENOSYS;
+	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_set_device_id)];
+	struct mgmt_hdr *hdr = (void *) buf;
+	struct mgmt_cp_set_device_id *cp = (void *) &buf[sizeof(*hdr)];
+
+	DBG("index %d source %x vendor %x product %x version %x",
+				index, source, vendor, product, version);
+
+	memset(buf, 0, sizeof(buf));
+	hdr->opcode = htobs(MGMT_OP_SET_DEVICE_ID);
+	hdr->len = htobs(sizeof(*cp));
+	hdr->index = htobs(index);
+
+	cp->source = htobs(source);
+	cp->vendor = htobs(vendor);
+	cp->product = htobs(product);
+	cp->version = htobs(version);
+
+	if (write(mgmt_sock, buf, sizeof(buf)) < 0)
+		return -errno;
+
+	return 0;
 }
 
 static int mgmt_disable_cod_cache(int index)
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 5/7] btmgmt: Add support for setting Device ID
  2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
                   ` (2 preceding siblings ...)
  2012-03-28 10:03 ` [PATCH V4 4/7] mgmtops: Add support for setting Device ID Szymon Janc
@ 2012-03-28 10:03 ` Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 6/7] Bump Device ID service version to 1.3 Szymon Janc
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Szymon Janc @ 2012-03-28 10:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

---
 mgmt/main.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/mgmt/main.c b/mgmt/main.c
index 4f10e08..90d43e3 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
@@ -1730,6 +1730,70 @@ static void cmd_clr_uuids(int mgmt_sk, uint16_t index, int argc, char **argv)
 	cmd_remove_uuid(mgmt_sk, index, 2, rm_argv);
 }
 
+static void did_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
+				void *rsp, uint16_t len, void *user_data)
+{
+	if (status != 0) {
+		fprintf(stderr, "Set Device ID failed with status 0x%02x (%s)\n",
+						status, mgmt_errstr(status));
+		exit(EXIT_FAILURE);
+	}
+
+	printf("Device ID succesfully set\n");
+
+	exit(EXIT_SUCCESS);
+}
+
+static void did_usage(void)
+{
+	printf("Usage: btmgmt did <source>:<vendor>:<product>:<version>\n");
+	printf("       possible source values: bluetooth, usb\n");
+}
+
+static void cmd_did(int mgmt_sk, uint16_t index, int argc, char **argv)
+{
+	struct mgmt_cp_set_device_id cp;
+	uint16_t vendor, product, version , source;
+	int result;
+
+	if (argc < 2) {
+		did_usage();
+		exit(EXIT_FAILURE);
+	}
+
+	result = sscanf(argv[1], "bluetooth:%4hx:%4hx:%4hx", &vendor, &product,
+								&version);
+	if (result == 3) {
+		source = 0x0001;
+		goto done;
+	}
+
+	result = sscanf(argv[1], "usb:%4hx:%4hx:%4hx", &vendor, &product,
+								&version);
+	if (result == 3) {
+		source = 0x0002;
+		goto done;
+	}
+
+	did_usage();
+	exit(EXIT_FAILURE);
+
+done:
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	cp.source = htobs(source);
+	cp.vendor = htobs(vendor);
+	cp.product = htobs(product);
+	cp.version = htobs(version);
+
+	if (mgmt_send_cmd(mgmt_sk, MGMT_OP_SET_DEVICE_ID, index,
+				&cp, sizeof(cp), did_rsp, NULL) < 0) {
+		fprintf(stderr, "Unable to send set_dev_class cmd\n");
+		exit(EXIT_FAILURE);
+	}
+}
+
 static struct {
 	char *cmd;
 	void (*func)(int mgmt_sk, uint16_t index, int argc, char **argv);
@@ -1760,6 +1824,7 @@ static struct {
 	{ "add-uuid",	cmd_add_uuid,	"Add UUID"			},
 	{ "rm-uuid",	cmd_add_uuid,	"Remove UUID"			},
 	{ "clr-uuids",	cmd_clr_uuids,	"Clear UUIDs",			},
+	{ "did",	cmd_did,	"Set Device ID",		},
 	{ NULL, NULL, 0 }
 };
 
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 6/7] Bump Device ID service version to 1.3
  2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
                   ` (3 preceding siblings ...)
  2012-03-28 10:03 ` [PATCH V4 5/7] btmgmt: " Szymon Janc
@ 2012-03-28 10:03 ` Szymon Janc
  2012-03-28 10:03 ` [PATCH V4 7/7] Move common code to sdp to avoid duplication Szymon Janc
  2012-03-28 10:18 ` [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Johan Hedberg
  6 siblings, 0 replies; 8+ messages in thread
From: Szymon Janc @ 2012-03-28 10:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

Device ID information in EIR are specified in DID 1.3 and this is
supported by BlueZ.
---
 src/sdpd-service.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index a6ed90e..c33e1da 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -175,7 +175,7 @@ void register_server_service(void)
 
 void register_device_id(void)
 {
-	const uint16_t spec = 0x0102;
+	const uint16_t spec = 0x0103;
 	const uint8_t primary = 1;
 	sdp_list_t *class_list, *group_list, *profile_list;
 	uuid_t class_uuid, group_uuid;
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V4 7/7] Move common code to sdp to avoid duplication
  2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
                   ` (4 preceding siblings ...)
  2012-03-28 10:03 ` [PATCH V4 6/7] Bump Device ID service version to 1.3 Szymon Janc
@ 2012-03-28 10:03 ` Szymon Janc
  2012-03-28 10:18 ` [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Johan Hedberg
  6 siblings, 0 replies; 8+ messages in thread
From: Szymon Janc @ 2012-03-28 10:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

LanguageBaseAttributeIDList is set from few places and each time static
function was copied and used for that. Move this funtion to sdp code
and use that instead of copying code.
---
 compat/sdp.c     |   16 +---------------
 lib/sdp.c        |   13 +++++++++++++
 lib/sdp_lib.h    |    2 ++
 network/server.c |   16 +---------------
 serial/proxy.c   |   16 +---------------
 tools/sdptool.c  |   20 +++-----------------
 6 files changed, 21 insertions(+), 62 deletions(-)

diff --git a/compat/sdp.c b/compat/sdp.c
index f384844..9ad8333 100644
--- a/compat/sdp.c
+++ b/compat/sdp.c
@@ -47,20 +47,6 @@
 static sdp_record_t *record = NULL;
 static sdp_session_t *session = NULL;
 
-static void add_lang_attr(sdp_record_t *r)
-{
-	sdp_lang_attr_t base_lang;
-	sdp_list_t *langs = 0;
-
-	/* UTF-8 MIBenum (http://www.iana.org/assignments/character-sets) */
-	base_lang.code_ISO639 = (0x65 << 8) | 0x6e;
-	base_lang.encoding = 106;
-	base_lang.base_offset = SDP_PRIMARY_LANG_BASE;
-	langs = sdp_list_append(0, &base_lang);
-	sdp_set_lang_attr(r, langs);
-	sdp_list_free(langs, 0);
-}
-
 static void epox_endian_quirk(unsigned char *data, int size)
 {
 	/* USAGE_PAGE (Keyboard)	05 07
@@ -448,7 +434,7 @@ int bnep_sdp_register(bdaddr_t *device, uint16_t role)
 	aproto = sdp_list_append(NULL, apseq);
 	sdp_set_access_protos(record, aproto);
 
-	add_lang_attr(record);
+	sdp_add_lang_attr(record);
 
 	sdp_list_free(proto[0], NULL);
 	sdp_list_free(proto[1], NULL);
diff --git a/lib/sdp.c b/lib/sdp.c
index 97c0a08..e12bace 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -4794,3 +4794,16 @@ fail:
 	return -1;
 }
 
+void sdp_add_lang_attr(sdp_record_t *rec)
+{
+	sdp_lang_attr_t base_lang;
+	sdp_list_t *langs;
+
+	base_lang.code_ISO639 = (0x65 << 8) | 0x6e;
+	base_lang.encoding = 106;
+	base_lang.base_offset = SDP_PRIMARY_LANG_BASE;
+
+	langs = sdp_list_append(0, &base_lang);
+	sdp_set_lang_attr(rec, langs);
+	sdp_list_free(langs, NULL);
+}
diff --git a/lib/sdp_lib.h b/lib/sdp_lib.h
index 433e9ef..6e1eb91 100644
--- a/lib/sdp_lib.h
+++ b/lib/sdp_lib.h
@@ -624,6 +624,8 @@ void sdp_pattern_add_uuidseq(sdp_record_t *rec, sdp_list_t *seq);
 
 int sdp_send_req_w4_rsp(sdp_session_t *session, uint8_t *req, uint8_t *rsp, uint32_t reqsize, uint32_t *rspsize);
 
+void sdp_add_lang_attr(sdp_record_t *rec);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/network/server.c b/network/server.c
index 67d81e3..987cfca 100644
--- a/network/server.c
+++ b/network/server.c
@@ -110,20 +110,6 @@ static struct network_server *find_server(GSList *list, uint16_t id)
 	return NULL;
 }
 
-static void add_lang_attr(sdp_record_t *r)
-{
-	sdp_lang_attr_t base_lang;
-	sdp_list_t *langs = 0;
-
-	/* UTF-8 MIBenum (http://www.iana.org/assignments/character-sets) */
-	base_lang.code_ISO639 = (0x65 << 8) | 0x6e;
-	base_lang.encoding = 106;
-	base_lang.base_offset = SDP_PRIMARY_LANG_BASE;
-	langs = sdp_list_append(0, &base_lang);
-	sdp_set_lang_attr(r, langs);
-	sdp_list_free(langs, 0);
-}
-
 static sdp_record_t *server_record_new(const char *name, uint16_t id)
 {
 	sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto;
@@ -232,7 +218,7 @@ static sdp_record_t *server_record_new(const char *name, uint16_t id)
 	aproto = sdp_list_append(NULL, apseq);
 	sdp_set_access_protos(record, aproto);
 
-	add_lang_attr(record);
+	sdp_add_lang_attr(record);
 
 	sdp_attr_add_new(record, SDP_ATTR_SECURITY_DESC,
 				SDP_UINT16, &security_desc);
diff --git a/serial/proxy.c b/serial/proxy.c
index 736f690..ea5c29f 100644
--- a/serial/proxy.c
+++ b/serial/proxy.c
@@ -130,20 +130,6 @@ static void proxy_free(struct serial_proxy *prx)
 	g_free(prx);
 }
 
-static void add_lang_attr(sdp_record_t *r)
-{
-	sdp_lang_attr_t base_lang;
-	sdp_list_t *langs = 0;
-
-	/* UTF-8 MIBenum (http://www.iana.org/assignments/character-sets) */
-	base_lang.code_ISO639 = (0x65 << 8) | 0x6e;
-	base_lang.encoding = 106;
-	base_lang.base_offset = SDP_PRIMARY_LANG_BASE;
-	langs = sdp_list_append(0, &base_lang);
-	sdp_set_lang_attr(r, langs);
-	sdp_list_free(langs, 0);
-}
-
 static sdp_record_t *proxy_record_new(const char *uuid128, uint8_t channel)
 {
 	sdp_list_t *apseq, *aproto, *profiles, *proto[2], *root, *svclass_id;
@@ -186,7 +172,7 @@ static sdp_record_t *proxy_record_new(const char *uuid128, uint8_t channel)
 	aproto = sdp_list_append(NULL, apseq);
 	sdp_set_access_protos(record, aproto);
 
-	add_lang_attr(record);
+	sdp_add_lang_attr(record);
 
 	sdp_set_info_attr(record, "Serial Proxy", NULL, "Serial Proxy");
 
diff --git a/tools/sdptool.c b/tools/sdptool.c
index 1a89245..db9ac0d 100644
--- a/tools/sdptool.c
+++ b/tools/sdptool.c
@@ -1148,20 +1148,6 @@ typedef struct {
 	uint8_t network;
 } svc_info_t;
 
-static void add_lang_attr(sdp_record_t *r)
-{
-	sdp_lang_attr_t base_lang;
-	sdp_list_t *langs = 0;
-
-	/* UTF-8 MIBenum (http://www.iana.org/assignments/character-sets) */
-	base_lang.code_ISO639 = (0x65 << 8) | 0x6e;
-	base_lang.encoding = 106;
-	base_lang.base_offset = SDP_PRIMARY_LANG_BASE;
-	langs = sdp_list_append(0, &base_lang);
-	sdp_set_lang_attr(r, langs);
-	sdp_list_free(langs, 0);
-}
-
 static int add_sp(sdp_session_t *session, svc_info_t *si)
 {
 	sdp_list_t *svclass_id, *apseq, *proto[2], *profiles, *root, *aproto;
@@ -1203,7 +1189,7 @@ static int add_sp(sdp_session_t *session, svc_info_t *si)
 	aproto = sdp_list_append(0, apseq);
 	sdp_set_access_protos(&record, aproto);
 
-	add_lang_attr(&record);
+	sdp_add_lang_attr(&record);
 
 	sdp_set_info_attr(&record, "Serial Port", "BlueZ", "COM Port");
 
@@ -2312,7 +2298,7 @@ static int add_hid_keyb(sdp_session_t *session, svc_info_t *si)
 	root = sdp_list_append(0, &root_uuid);
 	sdp_set_browse_groups(&record, root);
 
-	add_lang_attr(&record);
+	sdp_add_lang_attr(&record);
 
 	sdp_uuid16_create(&hidkb_uuid, HID_SVCLASS_ID);
 	svclass_id = sdp_list_append(0, &hidkb_uuid);
@@ -2490,7 +2476,7 @@ static int add_hid_wiimote(sdp_session_t *session, svc_info_t *si)
 	aproto = sdp_list_append(0, apseq);
 	sdp_set_add_access_protos(&record, aproto);
 
-	add_lang_attr(&record);
+	sdp_add_lang_attr(&record);
 
 	sdp_set_info_attr(&record, "Nintendo RVL-CNT-01",
 					"Nintendo", "Nintendo RVL-CNT-01");
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup
  2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
                   ` (5 preceding siblings ...)
  2012-03-28 10:03 ` [PATCH V4 7/7] Move common code to sdp to avoid duplication Szymon Janc
@ 2012-03-28 10:18 ` Johan Hedberg
  6 siblings, 0 replies; 8+ messages in thread
From: Johan Hedberg @ 2012-03-28 10:18 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth, kanak.gupta

Hi Szymon,

On Wed, Mar 28, 2012, Szymon Janc wrote:
> Instead of parsing config DeviceID string on sdp server startup, parse
> it in main while reading config file. This allow to store logical DID
> values in main_opts (instead of raw config string) and make use of them
> in bluetoothd code.
> ---
>  src/hcid.h         |    6 +++++-
>  src/main.c         |   20 +++++++++++++++++---
>  src/sdpd-server.c  |   19 ++++---------------
>  src/sdpd-service.c |   20 +++++++++++---------
>  src/sdpd.h         |    5 ++---
>  5 files changed, 39 insertions(+), 31 deletions(-)

All seven patches have been applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-03-28 10:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-28 10:03 [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Szymon Janc
2012-03-28 10:03 ` [PATCH V4 2/7] Set DeviceID when registering adapter not when sdp server is starting Szymon Janc
2012-03-28 10:03 ` [PATCH V4 3/7] Add support for setting VID source in DeviceID from config file Szymon Janc
2012-03-28 10:03 ` [PATCH V4 4/7] mgmtops: Add support for setting Device ID Szymon Janc
2012-03-28 10:03 ` [PATCH V4 5/7] btmgmt: " Szymon Janc
2012-03-28 10:03 ` [PATCH V4 6/7] Bump Device ID service version to 1.3 Szymon Janc
2012-03-28 10:03 ` [PATCH V4 7/7] Move common code to sdp to avoid duplication Szymon Janc
2012-03-28 10:18 ` [PATCH V4 1/7] Parse config DeviceID string on bluetoothd startup Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.