Add support for disconnect management command

This commit is contained in:
Johan Hedberg 2011-01-21 10:05:24 +02:00
parent 8865beb9a3
commit cc8588d684
3 changed files with 66 additions and 1 deletions

View File

@ -182,6 +182,16 @@ Remove Key Command
Return Paramters: Controller_Index (2 Octets)
Disconnect Command
==================
Command Code: 0x000F
Command Parameters: Controller_Index (2 Octets)
Address (6 Octets)
Return Paramters: Controller_Index (2 Octets)
Address (6 Octets)
Read Tracing Buffer Size Command
================================

View File

@ -129,6 +129,16 @@ struct mgmt_cp_remove_key {
uint8_t disconnect;
} __packed;
#define MGMT_OP_DISCONNECT 0x000F
struct mgmt_cp_disconnect {
uint16_t index;
bdaddr_t bdaddr;
} __packed;
struct mgmt_rp_disconnect {
uint16_t index;
bdaddr_t bdaddr;
} __packed;
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
uint16_t opcode;

View File

@ -765,6 +765,34 @@ static void set_pairable_complete(int sk, void *buf, size_t len)
btd_adapter_pairable_changed(adapter, info->pairable);
}
static void disconnect_complete(int sk, void *buf, size_t len)
{
struct mgmt_rp_disconnect *rp = buf;
struct controller_info *info;
uint16_t index;
char addr[18];
if (len < sizeof(*rp)) {
error("Too small disconnect complete event");
return;
}
index = btohs(bt_get_unaligned(&rp->index));
ba2str(&rp->bdaddr, addr);
DBG("hci%d %s disconnected", index, addr);
if (index > max_index) {
error("Unexpected index %u in disconnect complete", index);
return;
}
info = &controllers[index];
btd_event_disconn_complete(&info->bdaddr, &rp->bdaddr);
}
static void mgmt_cmd_complete(int sk, void *buf, size_t len)
{
struct mgmt_ev_cmd_complete *ev = buf;
@ -819,6 +847,10 @@ static void mgmt_cmd_complete(int sk, void *buf, size_t len)
case MGMT_OP_REMOVE_KEY:
DBG("remove_key complete");
break;
case MGMT_OP_DISCONNECT:
DBG("disconnect complete");
disconnect_complete(sk, ev->data, len - sizeof(*ev));
break;
default:
error("Unknown command complete for opcode %u", opcode);
break;
@ -1175,12 +1207,25 @@ static int mgmt_read_local_features(int index, uint8_t *features)
static int mgmt_disconnect(int index, bdaddr_t *bdaddr)
{
char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_disconnect)];
struct mgmt_hdr *hdr = (void *) buf;
struct mgmt_cp_disconnect *cp = (void *) &buf[sizeof(*hdr)];
char addr[18];
ba2str(bdaddr, addr);
DBG("index %d %s", index, addr);
return -ENOSYS;
memset(buf, 0, sizeof(buf));
hdr->opcode = htobs(MGMT_OP_DISCONNECT);
hdr->len = htobs(sizeof(*cp));
cp->index = htobs(index);
bacpy(&cp->bdaddr, bdaddr);
if (write(mgmt_sock, buf, sizeof(buf)) < 0)
error("write: %s (%d)", strerror(errno), errno);
return 0;
}
static int mgmt_remove_bonding(int index, bdaddr_t *bdaddr)