diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2011-01-21 04:40:11 +0200 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2011-01-21 05:02:19 +0200 |
commit | 1522d6568002afa27ee7a3280b3166f7ecb02f06 (patch) | |
tree | 12e1a8f9da42f59e0078de6113228e5031e024c2 | |
parent | 80caa32b6f0c0a774c8334295ee71b658acff630 (diff) | |
download | bluez-1522d6568002afa27ee7a3280b3166f7ecb02f06.tar.gz |
Use an unsigned integer for representing the PIN length
The value 0 is not allowed by the HCI spec so it can be used to denote
"not applicable" or "unknown". Also, the management interface will use
an unsigned integer for the PIN length so mirroring that in the core
daemon code makes sense. This patch also takes care of handling
previously stored -1 values and converts them to 0 whenever they are
detected.
-rw-r--r-- | plugins/hciops.c | 7 | ||||
-rw-r--r-- | src/adapter.c | 6 | ||||
-rw-r--r-- | src/adapter.h | 2 | ||||
-rw-r--r-- | src/event.c | 2 | ||||
-rw-r--r-- | src/event.h | 2 | ||||
-rw-r--r-- | src/storage.c | 2 |
6 files changed, 13 insertions, 8 deletions
diff --git a/plugins/hciops.c b/plugins/hciops.c index 1efbbd2a0..5f3b48ba9 100644 --- a/plugins/hciops.c +++ b/plugins/hciops.c @@ -100,7 +100,7 @@ static struct dev_info { gboolean debug_keys; GSList *keys; - int pin_length; + uint8_t pin_length; GSList *uuids; } *devs = NULL; @@ -117,7 +117,6 @@ static void init_dev_info(int index, int sk, gboolean registered) memset(dev, 0, sizeof(*dev)); dev->sk = sk; - dev->pin_length = -1; dev->cache_enable = TRUE; dev->registered = registered; } @@ -749,7 +748,7 @@ static void link_key_notify(int index, void *ptr) err = btd_event_link_key_notify(&dev->bdaddr, dba, evt->link_key, evt->key_type, dev->pin_length, old_key_type); - dev->pin_length = -1; + dev->pin_length = 0; if (err == 0) { dev->keys = g_slist_append(dev->keys, key_info); @@ -2066,7 +2065,7 @@ static void start_hci_dev(int index) io_security_event, GINT_TO_POINTER(index), NULL); dev->io = chan; - dev->pin_length = -1; + dev->pin_length = 0; } diff --git a/src/adapter.c b/src/adapter.c index ab4791c66..3f1288448 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -1975,6 +1975,7 @@ static struct link_key_info *get_key_info(const char *addr, const char *value) { struct link_key_info *info; char tmp[3]; + long int l; int i; if (strlen(value) < 36) { @@ -1997,7 +1998,10 @@ static struct link_key_info *get_key_info(const char *addr, const char *value) info->type = (uint8_t) strtol(tmp, NULL, 10); memcpy(tmp, value + 35, 2); - info->pin_len = strtol(tmp, NULL, 10); + l = strtol(tmp, NULL, 10); + if (l < 0) + l = 0; + info->pin_len = l; return info; } diff --git a/src/adapter.h b/src/adapter.h index b66be9a89..839656921 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -69,7 +69,7 @@ struct link_key_info { bdaddr_t bdaddr; unsigned char key[16]; uint8_t type; - int pin_len; + uint8_t pin_len; }; struct remote_dev_info { diff --git a/src/event.c b/src/event.c index 5d0bf6d0e..00b9ad7ea 100644 --- a/src/event.c +++ b/src/event.c @@ -695,7 +695,7 @@ proceed: int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t *key, uint8_t key_type, - int pin_length, uint8_t old_key_type) + uint8_t pin_length, uint8_t old_key_type) { struct btd_device *device; struct btd_adapter *adapter; diff --git a/src/event.h b/src/event.h index 66dd279c8..941902a90 100644 --- a/src/event.h +++ b/src/event.h @@ -45,4 +45,4 @@ int btd_event_user_passkey(bdaddr_t *sba, bdaddr_t *dba); int btd_event_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey); int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t *key, uint8_t key_type, - int pin_length, uint8_t old_key_type); + uint8_t pin_length, uint8_t old_key_type); diff --git a/src/storage.c b/src/storage.c index 1c6ced48c..35e1ba294 100644 --- a/src/storage.c +++ b/src/storage.c @@ -676,6 +676,8 @@ int read_pin_length(bdaddr_t *local, bdaddr_t *peer) } len = atoi(str + 35); + if (len < 0) + len = 0; free(str); |