From 0573fc7cb121fdb771908551d2051ef7ec031478 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 10 Nov 2011 23:22:32 +0200 Subject: [PATCH] mgmt: Add address type to mgmt_pair_device This is important especially in the future when dual-mode devices can be connected to over LE. It's also important if/when we decide to move the advertisement cache into user-space. --- doc/mgmt-api.txt | 7 +++++++ lib/mgmt.h | 4 ++-- mgmt/main.c | 15 ++++++++++----- plugins/mgmtops.c | 7 ++++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt index 7dfae60ed..6c2e44124 100644 --- a/doc/mgmt-api.txt +++ b/doc/mgmt-api.txt @@ -259,10 +259,17 @@ Pair Device Command Command Code: 0x0014 Controller Index: Command Parameters: Address (6 Octets) + Address_Type (1 Octet) IO_Capability (1 Octet) Return Parameters: Address (6 Octets) + Address_Type (1 Octet) Status (1 Octet) + Possible values for the Address_Type parameter: + 0 BR/EDR + 1 LE Public + 2 LE Random + User Confirmation Reply Command =============================== diff --git a/lib/mgmt.h b/lib/mgmt.h index 9eb6d2d02..396081516 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -178,11 +178,11 @@ struct mgmt_cp_set_io_capability { #define MGMT_OP_PAIR_DEVICE 0x0014 struct mgmt_cp_pair_device { - bdaddr_t bdaddr; + struct mgmt_addr_info addr; uint8_t io_cap; } __packed; struct mgmt_rp_pair_device { - bdaddr_t bdaddr; + struct mgmt_addr_info addr; uint8_t status; } __packed; diff --git a/mgmt/main.c b/mgmt/main.c index e9b0ee1e0..573cfb322 100644 --- a/mgmt/main.c +++ b/mgmt/main.c @@ -1166,7 +1166,7 @@ static void pair_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status, exit(EXIT_FAILURE); } - ba2str(&rp->bdaddr, addr); + ba2str(&rp->addr.bdaddr, addr); if (rp->status != 0) { fprintf(stderr, "Pairing with %s failed with status %u\n", @@ -1181,12 +1181,13 @@ static void pair_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status, static void pair_usage(void) { - printf("Usage: btmgmt pair [-c cap] \n"); + printf("Usage: btmgmt pair [-c cap] [-t type] \n"); } static struct option pair_options[] = { { "help", 0, 0, 'h' }, { "capability", 1, 0, 'c' }, + { "type", 1, 0, 't' }, { 0, 0, 0, 0 } }; @@ -1194,15 +1195,18 @@ static void cmd_pair(int mgmt_sk, uint16_t index, int argc, char **argv) { struct mgmt_cp_pair_device cp; uint8_t cap = 0x01; + uint8_t type = MGMT_ADDR_BREDR; int opt; - while ((opt = getopt_long(argc, argv, "+c:h", pair_options, + while ((opt = getopt_long(argc, argv, "+c:t:h", pair_options, NULL)) != -1) { switch (opt) { case 'c': cap = strtol(optarg, NULL, 0); break; - + case 't': + type = strtol(optarg, NULL, 0); + break; case 'h': default: pair_usage(); @@ -1223,7 +1227,8 @@ static void cmd_pair(int mgmt_sk, uint16_t index, int argc, char **argv) index = 0; memset(&cp, 0, sizeof(cp)); - str2ba(argv[0], &cp.bdaddr); + str2ba(argv[0], &cp.addr.bdaddr); + cp.addr.type = type; cp.io_cap = cap; if (mgmt_send_cmd(mgmt_sk, MGMT_OP_PAIR_DEVICE, index, &cp, sizeof(cp), diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c index 160bbd43c..b9e9ad634 100644 --- a/plugins/mgmtops.c +++ b/plugins/mgmtops.c @@ -1010,7 +1010,7 @@ static void pair_device_complete(int sk, uint16_t index, void *buf, size_t len) return; } - ba2str(&rp->bdaddr, addr); + ba2str(&rp->addr.bdaddr, addr); DBG("hci%d %s pairing complete status %u", index, addr, rp->status); @@ -1021,7 +1021,8 @@ static void pair_device_complete(int sk, uint16_t index, void *buf, size_t len) info = &controllers[index]; - btd_event_bonding_complete(&info->bdaddr, &rp->bdaddr, rp->status); + btd_event_bonding_complete(&info->bdaddr, &rp->addr.bdaddr, + rp->status); } static void get_connections_complete(int sk, uint16_t index, void *buf, @@ -2045,7 +2046,7 @@ static int mgmt_create_bonding(int index, bdaddr_t *bdaddr, uint8_t io_cap) hdr->len = htobs(sizeof(*cp)); hdr->index = htobs(index); - bacpy(&cp->bdaddr, bdaddr); + bacpy(&cp->addr.bdaddr, bdaddr); cp->io_cap = io_cap; if (write(mgmt_sock, &buf, sizeof(buf)) < 0) -- 2.47.3