mgmt: Add support for connected/disconnected events

This commit is contained in:
Johan Hedberg 2011-01-21 07:03:02 +02:00
parent bda6bb0079
commit 48908574c4
3 changed files with 82 additions and 0 deletions

View File

@ -310,3 +310,17 @@ Event Parameters Controller_Index (2 Octets)
PIN_Length (1 Octet)
}
Old_Key_Type (1 Octet)
Device Connected Event
======================
Event Code 0x000B
Event Parameters Controller_Index (2 Octets)
Address (6 Octets)
Device Disconnected Event
=========================
Event Code 0x000C
Event Parameters Controller_Index (2 Octets)
Address (6 Octets)

View File

@ -171,3 +171,15 @@ struct mgmt_ev_new_key {
struct mgmt_key_info key;
uint8_t old_key_type;
} __packed;
#define MGMT_EV_DEVICE_CONNECTED 0x000B
struct mgmt_ev_device_connected {
uint16_t index;
bdaddr_t bdaddr;
} __packed;
#define MGMT_EV_DEVICE_DISCONNECTED 0x000C
struct mgmt_ev_device_disconnected {
uint16_t index;
bdaddr_t bdaddr;
} __packed;

View File

@ -427,6 +427,56 @@ static void mgmt_new_key(int sk, void *buf, size_t len)
ev->key.pin_len, ev->old_key_type);
}
static void mgmt_device_connected(int sk, void *buf, size_t len)
{
struct mgmt_ev_device_connected *ev = buf;
struct controller_info *info;
uint16_t index;
char addr[18];
if (len < sizeof(*ev)) {
error("Too small device_connected event");
return;
}
index = btohs(bt_get_unaligned(&ev->index));
ba2str(&ev->bdaddr, addr);
DBG("hci%u device %s connected", index, addr);
if (index > max_index) {
error("Unexpected index %u in device_connected event", index);
return;
}
info = &controllers[index];
}
static void mgmt_device_disconnected(int sk, void *buf, size_t len)
{
struct mgmt_ev_device_disconnected *ev = buf;
struct controller_info *info;
uint16_t index;
char addr[18];
if (len < sizeof(*ev)) {
error("Too small device_disconnected event");
return;
}
index = btohs(bt_get_unaligned(&ev->index));
ba2str(&ev->bdaddr, addr);
DBG("hci%u device %s disconnected", index, addr);
if (index > max_index) {
error("Unexpected index %u in device_disconnected event", index);
return;
}
info = &controllers[index];
}
static void uuid_to_uuid128(uuid_t *uuid128, const uuid_t *uuid)
{
if (uuid->type == SDP_UUID16)
@ -878,6 +928,12 @@ static gboolean mgmt_event(GIOChannel *io, GIOCondition cond, gpointer user_data
case MGMT_EV_NEW_KEY:
mgmt_new_key(sk, buf + MGMT_HDR_SIZE, len);
break;
case MGMT_EV_DEVICE_CONNECTED:
mgmt_device_connected(sk, buf + MGMT_HDR_SIZE, len);
break;
case MGMT_EV_DEVICE_DISCONNECTED:
mgmt_device_disconnected(sk, buf + MGMT_HDR_SIZE, len);
break;
default:
error("Unknown Management opcode %u", opcode);
break;