From 6271215e3d077ceb0dad63ac60d09ccd51cadc07 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 27 Feb 2015 10:20:33 +0200 Subject: [PATCH] mgmt: Update code to match updated New CSRK specification The 'master' parameter was renamed to 'type' and now has two new possible values. --- android/bluetooth.c | 6 ++++-- lib/mgmt.h | 2 +- monitor/control.c | 23 +++++++++++++++++++++-- src/adapter.c | 14 +++++++------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/android/bluetooth.c b/android/bluetooth.c index 45cac5f38..dbb68d430 100644 --- a/android/bluetooth.c +++ b/android/bluetooth.c @@ -2354,19 +2354,21 @@ static void new_csrk_callback(uint16_t index, uint16_t length, if (!dev) return; - switch (ev->key.master) { + switch (ev->key.type) { case 0x00: + case 0x02: memcpy(dev->local_csrk, ev->key.val, 16); dev->local_sign_cnt = 0; dev->valid_local_csrk = true; break; case 0x01: + case 0x03: memcpy(dev->remote_csrk, ev->key.val, 16); dev->remote_sign_cnt = 0; dev->valid_remote_csrk = true; break; default: - error("Unknown CSRK key type 02%02x", ev->key.master); + error("Unknown CSRK key type 02%02x", ev->key.type); return; } diff --git a/lib/mgmt.h b/lib/mgmt.h index 59f1f7285..7e1ef7b2e 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -602,7 +602,7 @@ struct mgmt_ev_new_irk { struct mgmt_csrk_info { struct mgmt_addr_info addr; - uint8_t master; + uint8_t type; uint8_t val[16]; } __packed; diff --git a/monitor/control.c b/monitor/control.c index c6ed03c71..f40debbc8 100644 --- a/monitor/control.c +++ b/monitor/control.c @@ -599,6 +599,7 @@ static void mgmt_new_irk(uint16_t len, const void *buf) static void mgmt_new_csrk(uint16_t len, const void *buf) { const struct mgmt_ev_new_csrk *ev = buf; + const char *type; char addr[18]; if (len < sizeof(*ev)) { @@ -608,8 +609,26 @@ static void mgmt_new_csrk(uint16_t len, const void *buf) ba2str(&ev->key.addr.bdaddr, addr); - printf("@ New CSRK: %s (%d) %s\n", addr, ev->key.addr.type, - ev->key.master ? "Master" : "Slave"); + switch (ev->key.type) { + case 0x00: + type = "Local Unauthenticated"; + break; + case 0x01: + type = "Remote Unauthenticated"; + break; + case 0x02: + type = "Local Authenticated"; + break; + case 0x03: + type = "Remote Authenticated"; + break; + default: + type = ""; + break; + } + + printf("@ New CSRK: %s (%d) %s (%u)\n", addr, ev->key.addr.type, + type, ev->key.type); buf += sizeof(*ev); len -= sizeof(*ev); diff --git a/src/adapter.c b/src/adapter.c index 32faa261d..43501cbf4 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -6156,7 +6156,7 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length, static void store_csrk(const bdaddr_t *local, const bdaddr_t *peer, uint8_t bdaddr_type, const unsigned char *key, - uint32_t counter, uint8_t master) + uint32_t counter, uint8_t type) { const char *group; char adapter_addr[18]; @@ -6168,12 +6168,12 @@ static void store_csrk(const bdaddr_t *local, const bdaddr_t *peer, char *str; int i; - if (master == 0x00) + if (type == 0x00 || type == 0x02) group = "LocalSignatureKey"; - else if (master == 0x01) + else if (type == 0x01 || type == 0x03) group = "RemoteSignatureKey"; else { - warn("Unsupported CSRK type %u", master); + warn("Unsupported CSRK type %u", type); return; } @@ -6219,8 +6219,8 @@ static void new_csrk_callback(uint16_t index, uint16_t length, ba2str(&addr->bdaddr, dst); - DBG("hci%u new CSRK for %s master %u", adapter->dev_id, dst, - ev->key.master); + DBG("hci%u new CSRK for %s type %u", adapter->dev_id, dst, + ev->key.type); device = btd_adapter_get_device(adapter, &addr->bdaddr, addr->type); if (!device) { @@ -6232,7 +6232,7 @@ static void new_csrk_callback(uint16_t index, uint16_t length, return; store_csrk(bdaddr, &key->addr.bdaddr, key->addr.type, key->val, 0, - key->master); + key->type); if (device_is_temporary(device)) btd_device_set_temporary(device, FALSE); -- 2.47.3