* [PATCH 1/5] Add length argument to hci pincode reply
@ 2011-05-05 19:17 David Herrmann
2011-05-05 19:17 ` [PATCH 2/5] Make adapter API accept binary pincodes David Herrmann
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
This adds a new "length" argument to the hci pincode reply to allow
sending binary pins including \0 characters.
---
plugins/hciops.c | 10 +++++-----
plugins/mgmtops.c | 9 ++++-----
src/adapter.c | 3 ++-
src/adapter.h | 3 ++-
4 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 2c49e35..b125699 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -3415,7 +3415,8 @@ static int hciops_remove_bonding(int index, bdaddr_t *bdaddr)
return 0;
}
-static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
+static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin,
+ size_t pin_len)
{
struct dev_info *dev = &devs[index];
char addr[18];
@@ -3426,14 +3427,13 @@ static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
if (pin) {
pin_code_reply_cp pr;
- size_t len = strlen(pin);
- dev->pin_length = len;
+ dev->pin_length = pin_len;
memset(&pr, 0, sizeof(pr));
bacpy(&pr.bdaddr, bdaddr);
- memcpy(pr.pin_code, pin, len);
- pr.pin_len = len;
+ memcpy(pr.pin_code, pin, pin_len);
+ pr.pin_len = pin_len;
err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
OCF_PIN_CODE_REPLY,
PIN_CODE_REPLY_CP_SIZE, &pr);
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 9e1cfac..ce0ec2d 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -494,7 +494,8 @@ static void mgmt_connect_failed(int sk, uint16_t index, void *buf, size_t len)
btd_event_bonding_complete(&info->bdaddr, &ev->bdaddr, ev->status);
}
-static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
+static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin,
+ size_t pin_len)
{
char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_pin_code_reply)];
struct mgmt_hdr *hdr = (void *) buf;
@@ -502,7 +503,7 @@ static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
char addr[18];
ba2str(bdaddr, addr);
- DBG("index %d addr %s pin %s", index, addr, pin ? pin : "<none>");
+ DBG("index %d addr %s pinlen %lu", index, addr, pin_len);
memset(buf, 0, sizeof(buf));
@@ -519,9 +520,7 @@ static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
buf_len = sizeof(*hdr) + sizeof(*cp);
} else {
struct mgmt_cp_pin_code_reply *cp;
- size_t pin_len;
- pin_len = strlen(pin);
if (pin_len > 16)
return -EINVAL;
@@ -569,7 +568,7 @@ static void mgmt_pin_code_request(int sk, uint16_t index, void *buf, size_t len)
err = btd_event_request_pin(&info->bdaddr, &ev->bdaddr);
if (err < 0) {
error("btd_event_request_pin: %s", strerror(-err));
- mgmt_pincode_reply(index, &ev->bdaddr, NULL);
+ mgmt_pincode_reply(index, &ev->bdaddr, NULL, 0);
}
}
diff --git a/src/adapter.c b/src/adapter.c
index f068335..b7016c4 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3545,7 +3545,8 @@ int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr)
int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
const char *pin)
{
- return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin);
+ return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin,
+ pin ? strlen(pin) : 0);
}
int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/adapter.h b/src/adapter.h
index 9406b9b..e08068c 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -201,7 +201,8 @@ struct btd_adapter_ops {
int (*read_local_features) (int index, uint8_t *features);
int (*disconnect) (int index, bdaddr_t *bdaddr);
int (*remove_bonding) (int index, bdaddr_t *bdaddr);
- int (*pincode_reply) (int index, bdaddr_t *bdaddr, const char *pin);
+ int (*pincode_reply) (int index, bdaddr_t *bdaddr, const char *pin,
+ size_t pin_len);
int (*confirm_reply) (int index, bdaddr_t *bdaddr, gboolean success);
int (*passkey_reply) (int index, bdaddr_t *bdaddr, uint32_t passkey);
int (*enable_le) (int index);
--
1.7.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/5] Make adapter API accept binary pincodes
2011-05-05 19:17 [PATCH 1/5] Add length argument to hci pincode reply David Herrmann
@ 2011-05-05 19:17 ` David Herrmann
2011-05-05 19:17 ` [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings David Herrmann
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
Add pin-length argument to adapter API to allow passing binary pins
containing \0 characters to the hci handler.
---
src/adapter.c | 4 ++--
src/adapter.h | 2 +-
src/event.c | 7 ++++---
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index b7016c4..67644b8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3543,10 +3543,10 @@ int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr)
}
int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
- const char *pin)
+ const char *pin, size_t pin_len)
{
return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin,
- pin ? strlen(pin) : 0);
+ pin_len);
}
int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/adapter.h b/src/adapter.h
index e08068c..322a33b 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -254,7 +254,7 @@ int btd_adapter_disconnect_device(struct btd_adapter *adapter,
int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr);
int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
- const char *pin);
+ const char *pin, size_t pin_len);
int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
gboolean success);
int btd_adapter_passkey_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/event.c b/src/event.c
index d5bf967..c238392 100644
--- a/src/event.c
+++ b/src/event.c
@@ -111,13 +111,14 @@ static void pincode_cb(struct agent *agent, DBusError *derr,
device_get_address(device, &dba);
if (derr) {
- err = btd_adapter_pincode_reply(adapter, &dba, NULL);
+ err = btd_adapter_pincode_reply(adapter, &dba, NULL, 0);
if (err < 0)
goto fail;
return;
}
- err = btd_adapter_pincode_reply(adapter, &dba, pincode);
+ err = btd_adapter_pincode_reply(adapter, &dba, pincode,
+ pincode ? strlen(pincode) : 0);
if (err < 0)
goto fail;
@@ -140,7 +141,7 @@ int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba)
memset(pin, 0, sizeof(pin));
pinlen = read_pin_code(sba, dba, pin);
if (pinlen > 0) {
- btd_adapter_pincode_reply(adapter, dba, pin);
+ btd_adapter_pincode_reply(adapter, dba, pin, pinlen);
return 0;
}
--
1.7.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings
2011-05-05 19:17 [PATCH 1/5] Add length argument to hci pincode reply David Herrmann
2011-05-05 19:17 ` [PATCH 2/5] Make adapter API accept binary pincodes David Herrmann
@ 2011-05-05 19:17 ` David Herrmann
2011-05-05 19:17 ` [PATCH 4/5] Remove 16 byte limit for PIN codes returned by agents David Herrmann
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
If a pin code is retrieved from an agent and the first character is
a dollar sign '$', then the pin is decoded as following:
- The first character (dollar sign) is stripped from the pin
- The rest is parsed as hexadecimal numbers, where each two characters
will be converted into a one byte integer. If an odd number of
characters follows, then the last character is stripped. Empty
pins are valid. Parser is case insensitive.
Pins not starting with '$' are parsed as usual.
For instance:
pin: $0A3e005067
is decoded into a 5 byte pin:
decoded: 0x0a 0x3e 0x00 0x50 0x67
---
src/event.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/src/event.c b/src/event.c
index c238392..b0318de 100644
--- a/src/event.c
+++ b/src/event.c
@@ -101,12 +101,53 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
*
*****************************************************************/
+static uint8_t hex2dec(uint8_t c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ else if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ else if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ else
+ return 0;
+}
+
+static size_t decode_hex(const char *pin, char *out)
+{
+ size_t i;
+
+ for (i = 0; i < 16 && pin[i * 2] && pin[i * 2 + 1]; i++)
+ out[i] = hex2dec(pin[i * 2]) * 16 + hex2dec(pin[i * 2 + 1]);
+
+ return i;
+}
+
+static size_t decode_pin(const char *pin, char *out)
+{
+ size_t len;
+
+ if (!pin)
+ return 0;
+
+ if (pin[0] == '$') {
+ len = decode_hex(&pin[1], out);
+ } else {
+ len = strnlen(pin, 16);
+ memcpy(out, pin, len);
+ }
+
+ return len;
+}
+
static void pincode_cb(struct agent *agent, DBusError *derr,
const char *pincode, struct btd_device *device)
{
struct btd_adapter *adapter = device_get_adapter(device);
bdaddr_t dba;
int err;
+ size_t len;
+ char rawpin[16];
device_get_address(device, &dba);
@@ -117,8 +158,8 @@ static void pincode_cb(struct agent *agent, DBusError *derr,
return;
}
- err = btd_adapter_pincode_reply(adapter, &dba, pincode,
- pincode ? strlen(pincode) : 0);
+ len = decode_pin(pincode, rawpin);
+ err = btd_adapter_pincode_reply(adapter, &dba, rawpin, len);
if (err < 0)
goto fail;
--
1.7.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 4/5] Remove 16 byte limit for PIN codes returned by agents
2011-05-05 19:17 [PATCH 1/5] Add length argument to hci pincode reply David Herrmann
2011-05-05 19:17 ` [PATCH 2/5] Make adapter API accept binary pincodes David Herrmann
2011-05-05 19:17 ` [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings David Herrmann
@ 2011-05-05 19:17 ` David Herrmann
2011-05-05 19:17 ` [PATCH 5/5] Document new "hex-encoded pins" feature David Herrmann
2011-05-14 23:18 ` [PATCH 1/5] Add length argument to hci pincode reply Johan Hedberg
4 siblings, 0 replies; 7+ messages in thread
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
Agents can now return PIN codes longer than 16 characters. The
pin parser automatically truncates all PINs to 16 characters, but
allows hexadecimal PINs to be longer than 16 characters because
each two hexdecimal encoded bytes are parsed into one output byte.
---
src/agent.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/agent.c b/src/agent.c
index f87f253..40495bf 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -403,7 +403,7 @@ static void pincode_reply(DBusPendingCall *call, void *user_data)
len = strlen(pin);
dbus_error_init(&err);
- if (len > 16 || len < 1) {
+ if (len < 1) {
error("Invalid PIN length (%zu) from agent", len);
dbus_set_error_const(&err, "org.bluez.Error.InvalidArgs",
"Invalid passkey length");
--
1.7.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 5/5] Document new "hex-encoded pins" feature
2011-05-05 19:17 [PATCH 1/5] Add length argument to hci pincode reply David Herrmann
` (2 preceding siblings ...)
2011-05-05 19:17 ` [PATCH 4/5] Remove 16 byte limit for PIN codes returned by agents David Herrmann
@ 2011-05-05 19:17 ` David Herrmann
2011-05-14 23:18 ` [PATCH 1/5] Add length argument to hci pincode reply Johan Hedberg
4 siblings, 0 replies; 7+ messages in thread
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
---
doc/agent-api.txt | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/doc/agent-api.txt b/doc/agent-api.txt
index d8d35c0..0c84e1c 100644
--- a/doc/agent-api.txt
+++ b/doc/agent-api.txt
@@ -26,7 +26,13 @@ Methods void Release()
needs to get the passkey for an authentication.
The return value should be a string of 1-16 characters
- length. The string can be alphanumeric.
+ length. Longer strings are truncated to 16 characters.
+ The string can be alphanumeric.
+
+ Strings starting with '$' are parsed as hex-encoded
+ pins. That is, each two following hex characters form
+ a single byte of the resulting pin. The parser is
+ case-insensitive.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
--
1.7.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 1/5] Add length argument to hci pincode reply
2011-05-05 19:17 [PATCH 1/5] Add length argument to hci pincode reply David Herrmann
` (3 preceding siblings ...)
2011-05-05 19:17 ` [PATCH 5/5] Document new "hex-encoded pins" feature David Herrmann
@ 2011-05-14 23:18 ` Johan Hedberg
4 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2011-05-14 23:18 UTC (permalink / raw)
To: David Herrmann; +Cc: linux-bluetooth, hadess, padovan
Hi David,
On Thu, May 05, 2011, David Herrmann wrote:
> This adds a new "length" argument to the hci pincode reply to allow
> sending binary pins including \0 characters.
> ---
> plugins/hciops.c | 10 +++++-----
> plugins/mgmtops.c | 9 ++++-----
> src/adapter.c | 3 ++-
> src/adapter.h | 3 ++-
> 4 files changed, 13 insertions(+), 12 deletions(-)
All patches in this set have been pushed upstream. Thanks.
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings
@ 2011-05-05 19:42 David Herrmann
0 siblings, 0 replies; 7+ messages in thread
From: David Herrmann @ 2011-05-05 19:42 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, padovan, David Herrmann
If a pin code is retrieved from an agent and the first character is
a dollar sign '$', then the pin is decoded as following:
- The first character (dollar sign) is stripped from the pin
- The rest is parsed as hexadecimal numbers, where each two characters
will be converted into a one byte integer. If an odd number of
characters follows, then the last character is stripped. Empty
pins are valid. Parser is case insensitive.
Pins not starting with '$' are parsed as usual.
For instance:
pin: $0A3e005067
is decoded into a 5 byte pin:
decoded: 0x0a 0x3e 0x00 0x50 0x67
---
src/event.c | 33 +++++++++++++++++++++++++++++++--
1 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/event.c b/src/event.c
index c238392..147a29b 100644
--- a/src/event.c
+++ b/src/event.c
@@ -101,12 +101,41 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
*
*****************************************************************/
+static size_t decode_hex(const char *pin, char *out)
+{
+ size_t i;
+
+ for (i = 0; i < 16 && pin[i * 2] && pin[i * 2 + 1]; i++)
+ sscanf(&pin[i * 2], "%02hhX", &out[i]);
+
+ return i;
+}
+
+static size_t decode_pin(const char *pin, char *out)
+{
+ size_t len;
+
+ if (!pin)
+ return 0;
+
+ if (pin[0] == '$') {
+ len = decode_hex(&pin[1], out);
+ } else {
+ len = strnlen(pin, 16);
+ memcpy(out, pin, len);
+ }
+
+ return len;
+}
+
static void pincode_cb(struct agent *agent, DBusError *derr,
const char *pincode, struct btd_device *device)
{
struct btd_adapter *adapter = device_get_adapter(device);
bdaddr_t dba;
int err;
+ size_t len;
+ char rawpin[16];
device_get_address(device, &dba);
@@ -117,8 +146,8 @@ static void pincode_cb(struct agent *agent, DBusError *derr,
return;
}
- err = btd_adapter_pincode_reply(adapter, &dba, pincode,
- pincode ? strlen(pincode) : 0);
+ len = decode_pin(pincode, rawpin);
+ err = btd_adapter_pincode_reply(adapter, &dba, rawpin, len);
if (err < 0)
goto fail;
--
1.7.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-05-14 23:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-05 19:17 [PATCH 1/5] Add length argument to hci pincode reply David Herrmann
2011-05-05 19:17 ` [PATCH 2/5] Make adapter API accept binary pincodes David Herrmann
2011-05-05 19:17 ` [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings David Herrmann
2011-05-05 19:17 ` [PATCH 4/5] Remove 16 byte limit for PIN codes returned by agents David Herrmann
2011-05-05 19:17 ` [PATCH 5/5] Document new "hex-encoded pins" feature David Herrmann
2011-05-14 23:18 ` [PATCH 1/5] Add length argument to hci pincode reply Johan Hedberg
-- strict thread matches above, loose matches on Subject: below --
2011-05-05 19:42 [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings David Herrmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox