linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hciconfig: Retrieve linkey from device info file
@ 2012-12-05 10:20 Frédéric Danis
  2012-12-05 10:33 ` Marcel Holtmann
  0 siblings, 1 reply; 7+ messages in thread
From: Frédéric Danis @ 2012-12-05 10:20 UTC (permalink / raw)
  To: linux-bluetooth

Skip 2 first bytes of Key entry as it begins with "0x"
---
 Makefile.tools    |    2 +-
 tools/hciconfig.c |   37 ++++++++++++++++++++++++++++---------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/Makefile.tools b/Makefile.tools
index 1cbd876..e820301 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -23,7 +23,7 @@ tools_hciattach_LDADD = lib/libbluetooth-private.la
 
 tools_hciconfig_SOURCES = tools/hciconfig.c tools/csr.h tools/csr.c \
 						src/textfile.h src/textfile.c
-tools_hciconfig_LDADD = lib/libbluetooth-private.la
+tools_hciconfig_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@
 
 tools_hcitool_SOURCES = tools/hcitool.c src/oui.h src/oui.c \
 						src/textfile.h src/textfile.c
diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 045e9a8..3700198 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -38,6 +38,8 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 
+#include <glib.h>
+
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
 #include <bluetooth/hci_lib.h>
@@ -1018,26 +1020,43 @@ static void cmd_voice(int ctl, int hdev, char *opt)
 static int get_link_key(const bdaddr_t *local, const bdaddr_t *peer,
 			uint8_t *key)
 {
-	char filename[PATH_MAX + 1], addr[18], tmp[3], *str;
+	char filename[PATH_MAX + 1];
+	char local_addr[18], peer_addr[18];
+	GKeyFile *key_file;
+	char tmp[3], *str;
 	int i;
+	int err = 0;
+
+	ba2str(local, local_addr);
+	ba2str(peer, peer_addr);
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", local_addr,
+			peer_addr);
+	filename[PATH_MAX] = '\0';
+	key_file = g_key_file_new();
 
-	ba2str(local, addr);
-	create_name(filename, PATH_MAX, STORAGEDIR, addr, "linkkeys");
+	if (!g_key_file_load_from_file(key_file, filename, 0, NULL)) {
+		err = -EIO;
+		goto failed;
+	}
 
-	ba2str(peer, addr);
-	str = textfile_get(filename, addr);
-	if (!str)
-		return -EIO;
+	str = g_key_file_get_string(key_file, "LinkKey", "Key", NULL);
+	if (!str) {
+		err = -EIO;
+		goto failed;
+	}
 
 	memset(tmp, 0, sizeof(tmp));
 	for (i = 0; i < 16; i++) {
-		memcpy(tmp, str + (i * 2), 2);
+		memcpy(tmp, str + 2 + (i * 2), 2);
 		key[i] = (uint8_t) strtol(tmp, NULL, 16);
 	}
 
 	free(str);
 
-	return 0;
+failed:
+	g_key_file_free(key_file);
+
+	return err;
 }
 
 static void cmd_putkey(int ctl, int hdev, char *opt)
-- 
1.7.9.5


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

* Re: [PATCH] hciconfig: Retrieve linkey from device info file
  2012-12-05 10:20 [PATCH] hciconfig: Retrieve linkey from device info file Frédéric Danis
@ 2012-12-05 10:33 ` Marcel Holtmann
  2012-12-05 11:02   ` [PATCH v2] hciconfig: Remove putkey command Frédéric Danis
  0 siblings, 1 reply; 7+ messages in thread
From: Marcel Holtmann @ 2012-12-05 10:33 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth

Hi Fred,

> Skip 2 first bytes of Key entry as it begins with "0x"
> ---
>  Makefile.tools    |    2 +-
>  tools/hciconfig.c |   37 ++++++++++++++++++++++++++++---------
>  2 files changed, 29 insertions(+), 10 deletions(-)

this is not worth it. I rather have the feature in hciconfig removed.

Regards

Marcel



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

* [PATCH v2] hciconfig: Remove putkey command
  2012-12-05 10:33 ` Marcel Holtmann
@ 2012-12-05 11:02   ` Frédéric Danis
  2012-12-05 11:06     ` Marcel Holtmann
  0 siblings, 1 reply; 7+ messages in thread
From: Frédéric Danis @ 2012-12-05 11:02 UTC (permalink / raw)
  To: linux-bluetooth

---
 tools/hciconfig.c |   64 -----------------------------------------------------
 1 file changed, 64 deletions(-)

diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 045e9a8..6b18c4f 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -1015,69 +1015,6 @@ static void cmd_voice(int ctl, int hdev, char *opt)
 	}
 }
 
-static int get_link_key(const bdaddr_t *local, const bdaddr_t *peer,
-			uint8_t *key)
-{
-	char filename[PATH_MAX + 1], addr[18], tmp[3], *str;
-	int i;
-
-	ba2str(local, addr);
-	create_name(filename, PATH_MAX, STORAGEDIR, addr, "linkkeys");
-
-	ba2str(peer, addr);
-	str = textfile_get(filename, addr);
-	if (!str)
-		return -EIO;
-
-	memset(tmp, 0, sizeof(tmp));
-	for (i = 0; i < 16; i++) {
-		memcpy(tmp, str + (i * 2), 2);
-		key[i] = (uint8_t) strtol(tmp, NULL, 16);
-	}
-
-	free(str);
-
-	return 0;
-}
-
-static void cmd_putkey(int ctl, int hdev, char *opt)
-{
-	struct hci_dev_info di;
-	bdaddr_t bdaddr;
-	uint8_t key[16];
-	int dd;
-
-	if (!opt)
-		return;
-
-	dd = hci_open_dev(hdev);
-	if (dd < 0) {
-		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",
-						hdev, strerror(errno), errno);
-		exit(1);
-	}
-
-	if (hci_devinfo(hdev, &di) < 0) {
-		fprintf(stderr, "Can't get device info for hci%d: %s (%d)\n",
-						hdev, strerror(errno), errno);
-		exit(1);
-	}
-
-	str2ba(opt, &bdaddr);
-	if (get_link_key(&di.bdaddr, &bdaddr, key) < 0) {
-		fprintf(stderr, "Can't find link key for %s on hci%d\n", opt, hdev);
-		exit(1);
-	}
-
-	if (hci_write_stored_link_key(dd, &bdaddr, key, 1000) < 0) {
-		fprintf(stderr, "Can't write stored link key on hci%d: %s (%d)\n",
-						hdev, strerror(errno), errno);
-		exit(1);
-	}
-
-	hci_close_dev(dd);
-}
-
 static void cmd_delkey(int ctl, int hdev, char *opt)
 {
 	bdaddr_t bdaddr;
@@ -1984,7 +1921,6 @@ static struct {
 	{ "sspmode",	cmd_ssp_mode,	"[mode]",	"Get/Set Simple Pairing Mode" },
 	{ "aclmtu",	cmd_aclmtu,	"<mtu:pkt>",	"Set ACL MTU and number of packets" },
 	{ "scomtu",	cmd_scomtu,	"<mtu:pkt>",	"Set SCO MTU and number of packets" },
-	{ "putkey",	cmd_putkey,	"<bdaddr>",	"Store link key on the device" },
 	{ "delkey",	cmd_delkey,	"<bdaddr>",	"Delete link key from the device" },
 	{ "oobdata",	cmd_oob_data,	0,		"Get local OOB data" },
 	{ "commands",	cmd_commands,	0,		"Display supported commands" },
-- 
1.7.9.5


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

* Re: [PATCH v2] hciconfig: Remove putkey command
  2012-12-05 11:02   ` [PATCH v2] hciconfig: Remove putkey command Frédéric Danis
@ 2012-12-05 11:06     ` Marcel Holtmann
  2012-12-05 11:26       ` Johan Hedberg
  2012-12-05 11:43       ` [PATCH v3] " Frédéric Danis
  0 siblings, 2 replies; 7+ messages in thread
From: Marcel Holtmann @ 2012-12-05 11:06 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth

Hi Fred,

>  tools/hciconfig.c |   64 -----------------------------------------------------
>  1 file changed, 64 deletions(-)

that command does have a manpage entry.

Regards

Marcel



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

* Re: [PATCH v2] hciconfig: Remove putkey command
  2012-12-05 11:06     ` Marcel Holtmann
@ 2012-12-05 11:26       ` Johan Hedberg
  2012-12-05 11:43       ` [PATCH v3] " Frédéric Danis
  1 sibling, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2012-12-05 11:26 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Frédéric Danis, linux-bluetooth

Hi,

On Wed, Dec 05, 2012, Marcel Holtmann wrote:
> >  tools/hciconfig.c |   64 -----------------------------------------------------
> >  1 file changed, 64 deletions(-)
> 
> that command does have a manpage entry.

And I'd appreciate an explanation in the commit message body for *why*
the command is removed. It's not like it's going to be obvious for
anybody looking at the commit history, at least not a more than a year
from now.

Johan

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

* [PATCH v3] hciconfig: Remove putkey command
  2012-12-05 11:06     ` Marcel Holtmann
  2012-12-05 11:26       ` Johan Hedberg
@ 2012-12-05 11:43       ` Frédéric Danis
  2012-12-05 15:25         ` Johan Hedberg
  1 sibling, 1 reply; 7+ messages in thread
From: Frédéric Danis @ 2012-12-05 11:43 UTC (permalink / raw)
  To: linux-bluetooth

With new storage architecture legacy storage "linkkeys"
file doesn't exist anymore.
---
 tools/hciconfig.8 |    5 -----
 tools/hciconfig.c |   64 -----------------------------------------------------
 2 files changed, 69 deletions(-)

diff --git a/tools/hciconfig.8 b/tools/hciconfig.8
index 6397427..897d820 100644
--- a/tools/hciconfig.8
+++ b/tools/hciconfig.8
@@ -212,11 +212,6 @@ bytes and SCO buffer size to
 .I pkt
 packets.
 .TP
-.BI putkey " <bdaddr>"
-This command stores the link key for
-.I bdaddr
-on the device.
-.TP
 .BI delkey " <bdaddr>"
 This command deletes the stored link key for
 .I bdaddr
diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 045e9a8..6b18c4f 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -1015,69 +1015,6 @@ static void cmd_voice(int ctl, int hdev, char *opt)
 	}
 }
 
-static int get_link_key(const bdaddr_t *local, const bdaddr_t *peer,
-			uint8_t *key)
-{
-	char filename[PATH_MAX + 1], addr[18], tmp[3], *str;
-	int i;
-
-	ba2str(local, addr);
-	create_name(filename, PATH_MAX, STORAGEDIR, addr, "linkkeys");
-
-	ba2str(peer, addr);
-	str = textfile_get(filename, addr);
-	if (!str)
-		return -EIO;
-
-	memset(tmp, 0, sizeof(tmp));
-	for (i = 0; i < 16; i++) {
-		memcpy(tmp, str + (i * 2), 2);
-		key[i] = (uint8_t) strtol(tmp, NULL, 16);
-	}
-
-	free(str);
-
-	return 0;
-}
-
-static void cmd_putkey(int ctl, int hdev, char *opt)
-{
-	struct hci_dev_info di;
-	bdaddr_t bdaddr;
-	uint8_t key[16];
-	int dd;
-
-	if (!opt)
-		return;
-
-	dd = hci_open_dev(hdev);
-	if (dd < 0) {
-		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",
-						hdev, strerror(errno), errno);
-		exit(1);
-	}
-
-	if (hci_devinfo(hdev, &di) < 0) {
-		fprintf(stderr, "Can't get device info for hci%d: %s (%d)\n",
-						hdev, strerror(errno), errno);
-		exit(1);
-	}
-
-	str2ba(opt, &bdaddr);
-	if (get_link_key(&di.bdaddr, &bdaddr, key) < 0) {
-		fprintf(stderr, "Can't find link key for %s on hci%d\n", opt, hdev);
-		exit(1);
-	}
-
-	if (hci_write_stored_link_key(dd, &bdaddr, key, 1000) < 0) {
-		fprintf(stderr, "Can't write stored link key on hci%d: %s (%d)\n",
-						hdev, strerror(errno), errno);
-		exit(1);
-	}
-
-	hci_close_dev(dd);
-}
-
 static void cmd_delkey(int ctl, int hdev, char *opt)
 {
 	bdaddr_t bdaddr;
@@ -1984,7 +1921,6 @@ static struct {
 	{ "sspmode",	cmd_ssp_mode,	"[mode]",	"Get/Set Simple Pairing Mode" },
 	{ "aclmtu",	cmd_aclmtu,	"<mtu:pkt>",	"Set ACL MTU and number of packets" },
 	{ "scomtu",	cmd_scomtu,	"<mtu:pkt>",	"Set SCO MTU and number of packets" },
-	{ "putkey",	cmd_putkey,	"<bdaddr>",	"Store link key on the device" },
 	{ "delkey",	cmd_delkey,	"<bdaddr>",	"Delete link key from the device" },
 	{ "oobdata",	cmd_oob_data,	0,		"Get local OOB data" },
 	{ "commands",	cmd_commands,	0,		"Display supported commands" },
-- 
1.7.9.5


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

* Re: [PATCH v3] hciconfig: Remove putkey command
  2012-12-05 11:43       ` [PATCH v3] " Frédéric Danis
@ 2012-12-05 15:25         ` Johan Hedberg
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2012-12-05 15:25 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth

Hi Frederic,

On Wed, Dec 05, 2012, Frédéric Danis wrote:
> With new storage architecture legacy storage "linkkeys"
> file doesn't exist anymore.
> ---
>  tools/hciconfig.8 |    5 -----
>  tools/hciconfig.c |   64 -----------------------------------------------------
>  2 files changed, 69 deletions(-)

Applied. Thanks.

Johan

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

end of thread, other threads:[~2012-12-05 15:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-05 10:20 [PATCH] hciconfig: Retrieve linkey from device info file Frédéric Danis
2012-12-05 10:33 ` Marcel Holtmann
2012-12-05 11:02   ` [PATCH v2] hciconfig: Remove putkey command Frédéric Danis
2012-12-05 11:06     ` Marcel Holtmann
2012-12-05 11:26       ` Johan Hedberg
2012-12-05 11:43       ` [PATCH v3] " Frédéric Danis
2012-12-05 15:25         ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).