diff --git a/src/adapter.c b/src/adapter.c
index d3e5dd4..030a64b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
passkey);
}
+static void pair_device_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_pair_device *rp = param;
+ struct btd_adapter *adapter = user_data;
+
+ DBG("%s (0x%02x)", mgmt_errstr(status), status);
+
+ if (status != MGMT_STATUS_SUCCESS && length < sizeof(*rp)) {
+ error("Pair device failed: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Too small pair device response");
+ return;
+ }
+
+ adapter_bonding_complete(adapter, &rp->addr.bdaddr, rp->addr.type,
+ status);
+}
+
int adapter_create_bonding(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
uint8_t addr_type, uint8_t io_cap)
{
+ struct mgmt_cp_pair_device cp;
+ char addr[18];
+
suspend_discovery(adapter);
- return mgmt_create_bonding(adapter->dev_id, bdaddr, addr_type, io_cap);
+
+ ba2str(bdaddr, addr);
+ DBG("hci%u bdaddr %s type %d io_cap 0x%02x",
+ adapter->dev_id, addr, addr_type, io_cap);
+
+ memset(&cp, 0, sizeof(cp));
+ bacpy(&cp.addr.bdaddr, bdaddr);
+ cp.addr.type = addr_type;
+ cp.io_cap = io_cap;
+
+ if (mgmt_send(adapter->mgmt, MGMT_OP_PAIR_DEVICE,
+ adapter->dev_id, sizeof(cp), &cp,
+ pair_device_complete, adapter, NULL) > 0)
+ return 0;
+
+ error("Failed to pair %s for hci%u", addr, adapter->dev_id);
+
+ return -EIO;
}
int adapter_cancel_bonding(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
diff --git a/src/mgmt.c b/src/mgmt.c
index b0e0915..c71cea4 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
}
}
-static void pair_device_complete(uint16_t index, uint8_t status,
- void *buf, size_t len)
-{
- struct mgmt_rp_pair_device *rp = buf;
- char addr[18];
-
- if (len < sizeof(*rp)) {
- error("Too small pair_device complete event");
- return;
- }
-
- ba2str(&rp->addr.bdaddr, addr);
-
- DBG("hci%d %s pairing complete status %u", index, addr, status);
-
- bonding_complete(index, &rp->addr, status);
-}
-
static void mgmt_cmd_complete(uint16_t index, void *buf, size_t len)
{
struct mgmt_ev_cmd_complete *ev = buf;
DBG("set_io_capability complete");
break;
case MGMT_OP_PAIR_DEVICE:
- pair_device_complete(index, ev->status, ev->data, len);
+ DBG("pair_device complete");
break;
case MGMT_OP_USER_CONFIRM_REPLY:
DBG("user_confirm_reply complete");
}
}
-int mgmt_create_bonding(int index, const bdaddr_t *bdaddr, uint8_t addr_type,
- uint8_t io_cap)
-{
- char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_pair_device)];
- struct mgmt_hdr *hdr = (void *) buf;
- struct mgmt_cp_pair_device *cp = (void *) &buf[sizeof(*hdr)];
- char addr[18];
-
- ba2str(bdaddr, addr);
- DBG("hci%d bdaddr %s type %d io_cap 0x%02x",
- index, addr, addr_type, io_cap);
-
- memset(buf, 0, sizeof(buf));
- hdr->opcode = htobs(MGMT_OP_PAIR_DEVICE);
- hdr->len = htobs(sizeof(*cp));
- hdr->index = htobs(index);
-
- bacpy(&cp->addr.bdaddr, bdaddr);
- cp->addr.type = addr_type;
- cp->io_cap = io_cap;
-
- if (write(mgmt_sock, &buf, sizeof(buf)) < 0)
- return -errno;
-
- return 0;
-}
-
int mgmt_cancel_bonding(int index, const bdaddr_t *bdaddr, uint8_t addr_type)
{
char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_addr_info)];
diff --git a/src/mgmt.h b/src/mgmt.h
index 91ea085..86dd842 100644
--- a/src/mgmt.h
+++ b/src/mgmt.h
int mgmt_setup(void);
void mgmt_cleanup(void);
-int mgmt_create_bonding(int index, const bdaddr_t *bdaddr, uint8_t addr_type,
- uint8_t io_cap);
int mgmt_cancel_bonding(int index, const bdaddr_t *bdaddr, uint8_t addr_type);
int mgmt_pincode_reply(int index, const bdaddr_t *bdaddr, const char *pin,