Bluetooth: MGMT start discovery LE-Only support
[linux-2.6-block.git] / net / bluetooth / mgmt.c
index bc8e59dda78e2bf72f81c3eeacea748d5cbd78ae..8c9de58779c71dbfda551c6ba73f32f78b503c59 100644 (file)
 #define MGMT_VERSION   0
 #define MGMT_REVISION  1
 
+/*
+ * These LE scan and inquiry parameters were chosen according to LE General
+ * Discovery Procedure specification.
+ */
+#define LE_SCAN_TYPE                   0x01
+#define LE_SCAN_WIN                    0x12
+#define LE_SCAN_INT                    0x12
+#define LE_SCAN_TIMEOUT_LE_ONLY                10240   /* TGAP(gen_disc_scan_min) */
+
 #define INQUIRY_LEN_BREDR 0x08 /* TGAP(100) */
 
 #define SERVICE_CACHE_TIMEOUT (5 * 1000)
@@ -226,10 +235,10 @@ static int read_index_list(struct sock *sk)
 
        i = 0;
        list_for_each_entry(d, &hci_dev_list, list) {
-               if (test_and_clear_bit(HCI_AUTO_OFF, &d->flags))
+               if (test_and_clear_bit(HCI_AUTO_OFF, &d->dev_flags))
                        cancel_delayed_work(&d->power_off);
 
-               if (test_bit(HCI_SETUP, &d->flags))
+               if (test_bit(HCI_SETUP, &d->dev_flags))
                        continue;
 
                put_unaligned_le16(d->id, &rp->index[i++]);
@@ -285,7 +294,7 @@ static u32 get_current_settings(struct hci_dev *hdev)
        if (test_bit(HCI_ISCAN, &hdev->flags))
                settings |= MGMT_SETTING_DISCOVERABLE;
 
-       if (test_bit(HCI_PAIRABLE, &hdev->flags))
+       if (test_bit(HCI_PAIRABLE, &hdev->dev_flags))
                settings |= MGMT_SETTING_PAIRABLE;
 
        if (!(hdev->features[4] & LMP_NO_BREDR))
@@ -297,24 +306,12 @@ static u32 get_current_settings(struct hci_dev *hdev)
        if (test_bit(HCI_AUTH, &hdev->flags))
                settings |= MGMT_SETTING_LINK_SECURITY;
 
-       if (hdev->ssp_mode > 0)
+       if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags))
                settings |= MGMT_SETTING_SSP;
 
        return settings;
 }
 
-#define EIR_FLAGS              0x01 /* flags */
-#define EIR_UUID16_SOME                0x02 /* 16-bit UUID, more available */
-#define EIR_UUID16_ALL         0x03 /* 16-bit UUID, all listed */
-#define EIR_UUID32_SOME                0x04 /* 32-bit UUID, more available */
-#define EIR_UUID32_ALL         0x05 /* 32-bit UUID, all listed */
-#define EIR_UUID128_SOME       0x06 /* 128-bit UUID, more available */
-#define EIR_UUID128_ALL                0x07 /* 128-bit UUID, all listed */
-#define EIR_NAME_SHORT         0x08 /* shortened local name */
-#define EIR_NAME_COMPLETE      0x09 /* complete local name */
-#define EIR_TX_POWER           0x0A /* transmit power level */
-#define EIR_DEVICE_ID          0x10 /* device ID */
-
 #define PNP_INFO_SVCLASS_ID            0x1200
 
 static u8 bluetooth_base_uuid[] = {
@@ -428,10 +425,10 @@ static int update_eir(struct hci_dev *hdev)
        if (!(hdev->features[6] & LMP_EXT_INQ))
                return 0;
 
-       if (hdev->ssp_mode == 0)
+       if (!test_bit(HCI_SSP_ENABLED, &hdev->dev_flags))
                return 0;
 
-       if (test_bit(HCI_SERVICE_CACHE, &hdev->flags))
+       if (test_bit(HCI_SERVICE_CACHE, &hdev->dev_flags))
                return 0;
 
        memset(&cp, 0, sizeof(cp));
@@ -463,7 +460,7 @@ static int update_class(struct hci_dev *hdev)
 
        BT_DBG("%s", hdev->name);
 
-       if (test_bit(HCI_SERVICE_CACHE, &hdev->flags))
+       if (test_bit(HCI_SERVICE_CACHE, &hdev->dev_flags))
                return 0;
 
        cod[0] = hdev->minor_class;
@@ -481,7 +478,7 @@ static void service_cache_off(struct work_struct *work)
        struct hci_dev *hdev = container_of(work, struct hci_dev,
                                                        service_cache.work);
 
-       if (!test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->flags))
+       if (!test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->dev_flags))
                return;
 
        hci_dev_lock(hdev);
@@ -494,10 +491,10 @@ static void service_cache_off(struct work_struct *work)
 
 static void mgmt_init_hdev(struct hci_dev *hdev)
 {
-       if (!test_and_set_bit(HCI_MGMT, &hdev->flags))
+       if (!test_and_set_bit(HCI_MGMT, &hdev->dev_flags))
                INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off);
 
-       if (!test_and_set_bit(HCI_SERVICE_CACHE, &hdev->flags))
+       if (!test_and_set_bit(HCI_SERVICE_CACHE, &hdev->dev_flags))
                schedule_delayed_work(&hdev->service_cache,
                                msecs_to_jiffies(SERVICE_CACHE_TIMEOUT));
 }
@@ -514,7 +511,7 @@ static int read_controller_info(struct sock *sk, u16 index)
                return cmd_status(sk, index, MGMT_OP_READ_INFO,
                                                MGMT_STATUS_INVALID_PARAMS);
 
-       if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
+       if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags))
                cancel_delayed_work_sync(&hdev->power_off);
 
        hci_dev_lock(hdev);
@@ -623,15 +620,13 @@ static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev)
        return cmd_complete(sk, hdev->id, opcode, &settings, sizeof(settings));
 }
 
-static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len)
+static int set_powered(struct sock *sk, u16 index, void *data, u16 len)
 {
-       struct mgmt_mode *cp;
+       struct mgmt_mode *cp = data;
        struct hci_dev *hdev;
        struct pending_cmd *cmd;
        int err, up;
 
-       cp = (void *) data;
-
        BT_DBG("request for hci%u", index);
 
        if (len != sizeof(*cp))
@@ -676,17 +671,14 @@ failed:
        return err;
 }
 
-static int set_discoverable(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
 {
-       struct mgmt_cp_set_discoverable *cp;
+       struct mgmt_cp_set_discoverable *cp = data;
        struct hci_dev *hdev;
        struct pending_cmd *cmd;
        u8 scan;
        int err;
 
-       cp = (void *) data;
-
        BT_DBG("request for hci%u", index);
 
        if (len != sizeof(*cp))
@@ -746,17 +738,14 @@ failed:
        return err;
 }
 
-static int set_connectable(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
 {
-       struct mgmt_mode *cp;
+       struct mgmt_mode *cp = data;
        struct hci_dev *hdev;
        struct pending_cmd *cmd;
        u8 scan;
        int err;
 
-       cp = (void *) data;
-
        BT_DBG("request for hci%u", index);
 
        if (len != sizeof(*cp))
@@ -839,16 +828,13 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data,
        return 0;
 }
 
-static int set_pairable(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int set_pairable(struct sock *sk, u16 index, void *data, u16 len)
 {
-       struct mgmt_mode *cp;
+       struct mgmt_mode *cp = data;
        struct hci_dev *hdev;
        __le32 ev;
        int err;
 
-       cp = (void *) data;
-
        BT_DBG("request for hci%u", index);
 
        if (len != sizeof(*cp))
@@ -863,9 +849,9 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data,
        hci_dev_lock(hdev);
 
        if (cp->val)
-               set_bit(HCI_PAIRABLE, &hdev->flags);
+               set_bit(HCI_PAIRABLE, &hdev->dev_flags);
        else
-               clear_bit(HCI_PAIRABLE, &hdev->flags);
+               clear_bit(HCI_PAIRABLE, &hdev->dev_flags);
 
        err = send_settings_rsp(sk, MGMT_OP_SET_PAIRABLE, hdev);
        if (err < 0)
@@ -882,15 +868,13 @@ failed:
        return err;
 }
 
-static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
+static int add_uuid(struct sock *sk, u16 index, void *data, u16 len)
 {
-       struct mgmt_cp_add_uuid *cp;
+       struct mgmt_cp_add_uuid *cp = data;
        struct hci_dev *hdev;
        struct bt_uuid *uuid;
        int err;
 
-       cp = (void *) data;
-
        BT_DBG("request for hci%u", index);
 
        if (len != sizeof(*cp))
@@ -932,16 +916,14 @@ failed:
        return err;
 }
 
-static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
+static int remove_uuid(struct sock *sk, u16 index, void *data, u16 len)
 {
+       struct mgmt_cp_remove_uuid *cp = data;
        struct list_head *p, *n;
-       struct mgmt_cp_remove_uuid *cp;
        struct hci_dev *hdev;
        u8 bt_uuid_any[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        int err, found;
 
-       cp = (void *) data;
-
        BT_DBG("request for hci%u", index);
 
        if (len != sizeof(*cp))
@@ -995,15 +977,12 @@ unlock:
        return err;
 }
 
-static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int set_dev_class(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_set_dev_class *cp;
+       struct mgmt_cp_set_dev_class *cp = data;
        int err;
 
-       cp = (void *) data;
-
        BT_DBG("request for hci%u", index);
 
        if (len != sizeof(*cp))
@@ -1020,7 +999,7 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
        hdev->major_class = cp->major;
        hdev->minor_class = cp->minor;
 
-       if (test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->flags)) {
+       if (test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->dev_flags)) {
                hci_dev_unlock(hdev);
                cancel_delayed_work_sync(&hdev->service_cache);
                hci_dev_lock(hdev);
@@ -1038,16 +1017,13 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
        return err;
 }
 
-static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
-                                                               u16 len)
+static int load_link_keys(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_load_link_keys *cp;
+       struct mgmt_cp_load_link_keys *cp = data;
        u16 key_count, expected_len;
        int i;
 
-       cp = (void *) data;
-
        if (len < sizeof(*cp))
                return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS,
                                                MGMT_STATUS_INVALID_PARAMS);
@@ -1075,12 +1051,12 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
 
        hci_link_keys_clear(hdev);
 
-       set_bit(HCI_LINK_KEYS, &hdev->flags);
+       set_bit(HCI_LINK_KEYS, &hdev->dev_flags);
 
        if (cp->debug_keys)
-               set_bit(HCI_DEBUG_KEYS, &hdev->flags);
+               set_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
        else
-               clear_bit(HCI_DEBUG_KEYS, &hdev->flags);
+               clear_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
 
        for (i = 0; i < key_count; i++) {
                struct mgmt_link_key_info *key = &cp->keys[i];
@@ -1097,19 +1073,16 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
        return 0;
 }
 
-static int remove_keys(struct sock *sk, u16 index, unsigned char *data,
-                                                               u16 len)
+static int remove_keys(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_remove_keys *cp;
+       struct mgmt_cp_remove_keys *cp = data;
        struct mgmt_rp_remove_keys rp;
        struct hci_cp_disconnect dc;
        struct pending_cmd *cmd;
        struct hci_conn *conn;
        int err;
 
-       cp = (void *) data;
-
        if (len != sizeof(*cp))
                return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS,
                                                MGMT_STATUS_INVALID_PARAMS);
@@ -1125,6 +1098,12 @@ static int remove_keys(struct sock *sk, u16 index, unsigned char *data,
        bacpy(&rp.bdaddr, &cp->bdaddr);
        rp.status = MGMT_STATUS_FAILED;
 
+       err = hci_remove_ltk(hdev, &cp->bdaddr);
+       if (err < 0) {
+               err = cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, -err);
+               goto unlock;
+       }
+
        err = hci_remove_link_key(hdev, &cp->bdaddr);
        if (err < 0) {
                rp.status = MGMT_STATUS_NOT_PAIRED;
@@ -1166,10 +1145,10 @@ unlock:
        return err;
 }
 
-static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
+static int disconnect(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_disconnect *cp;
+       struct mgmt_cp_disconnect *cp = data;
        struct hci_cp_disconnect dc;
        struct pending_cmd *cmd;
        struct hci_conn *conn;
@@ -1177,8 +1156,6 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
 
        BT_DBG("");
 
-       cp = (void *) data;
-
        if (len != sizeof(*cp))
                return cmd_status(sk, index, MGMT_OP_DISCONNECT,
                                                MGMT_STATUS_INVALID_PARAMS);
@@ -1256,7 +1233,6 @@ static int get_connections(struct sock *sk, u16 index)
        struct mgmt_rp_get_connections *rp;
        struct hci_dev *hdev;
        struct hci_conn *c;
-       struct list_head *p;
        size_t rp_len;
        u16 count;
        int i, err;
@@ -1271,8 +1247,9 @@ static int get_connections(struct sock *sk, u16 index)
        hci_dev_lock(hdev);
 
        count = 0;
-       list_for_each(p, &hdev->conn_hash.list) {
-               count++;
+       list_for_each_entry(c, &hdev->conn_hash.list, list) {
+               if (test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags))
+                       count++;
        }
 
        rp_len = sizeof(*rp) + (count * sizeof(struct mgmt_addr_info));
@@ -1286,6 +1263,8 @@ static int get_connections(struct sock *sk, u16 index)
 
        i = 0;
        list_for_each_entry(c, &hdev->conn_hash.list, list) {
+               if (!test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags))
+                       continue;
                bacpy(&rp->addr[i].bdaddr, &c->dst);
                rp->addr[i].type = link_to_mgmt(c->type, c->dst_type);
                if (rp->addr[i].type == MGMT_ADDR_INVALID)
@@ -1324,12 +1303,11 @@ static int send_pin_code_neg_reply(struct sock *sk, u16 index,
        return err;
 }
 
-static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int pin_code_reply(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
        struct hci_conn *conn;
-       struct mgmt_cp_pin_code_reply *cp;
+       struct mgmt_cp_pin_code_reply *cp = data;
        struct mgmt_cp_pin_code_neg_reply ncp;
        struct hci_cp_pin_code_reply reply;
        struct pending_cmd *cmd;
@@ -1337,8 +1315,6 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
 
        BT_DBG("");
 
-       cp = (void *) data;
-
        if (len != sizeof(*cp))
                return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
                                                MGMT_STATUS_INVALID_PARAMS);
@@ -1376,7 +1352,8 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
                goto failed;
        }
 
-       cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len);
+       cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data,
+                                                                       len);
        if (!cmd) {
                err = -ENOMEM;
                goto failed;
@@ -1397,17 +1374,14 @@ failed:
        return err;
 }
 
-static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int pin_code_neg_reply(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_pin_code_neg_reply *cp;
+       struct mgmt_cp_pin_code_neg_reply *cp = data;
        int err;
 
        BT_DBG("");
 
-       cp = (void *) data;
-
        if (len != sizeof(*cp))
                return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
                                                MGMT_STATUS_INVALID_PARAMS);
@@ -1434,16 +1408,13 @@ failed:
        return err;
 }
 
-static int set_io_capability(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int set_io_capability(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_set_io_capability *cp;
+       struct mgmt_cp_set_io_capability *cp = data;
 
        BT_DBG("");
 
-       cp = (void *) data;
-
        if (len != sizeof(*cp))
                return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY,
                                                MGMT_STATUS_INVALID_PARAMS);
@@ -1518,10 +1489,10 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status)
                pairing_complete(cmd, status);
 }
 
-static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
+static int pair_device(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_pair_device *cp;
+       struct mgmt_cp_pair_device *cp = data;
        struct mgmt_rp_pair_device rp;
        struct pending_cmd *cmd;
        u8 sec_level, auth_type;
@@ -1530,8 +1501,6 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
 
        BT_DBG("");
 
-       cp = (void *) data;
-
        if (len != sizeof(*cp))
                return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE,
                                                MGMT_STATUS_INVALID_PARAMS);
@@ -1604,6 +1573,54 @@ unlock:
        return err;
 }
 
+static int cancel_pair_device(struct sock *sk, u16 index,
+                                               unsigned char *data, u16 len)
+{
+       struct mgmt_addr_info *addr = (void *) data;
+       struct hci_dev *hdev;
+       struct pending_cmd *cmd;
+       struct hci_conn *conn;
+       int err;
+
+       BT_DBG("");
+
+       if (len != sizeof(*addr))
+               return cmd_status(sk, index, MGMT_OP_CANCEL_PAIR_DEVICE,
+                                               MGMT_STATUS_INVALID_PARAMS);
+
+       hdev = hci_dev_get(index);
+       if (!hdev)
+               return cmd_status(sk, index, MGMT_OP_CANCEL_PAIR_DEVICE,
+                                               MGMT_STATUS_INVALID_PARAMS);
+
+       hci_dev_lock(hdev);
+
+       cmd = mgmt_pending_find(MGMT_OP_PAIR_DEVICE, hdev);
+       if (!cmd) {
+               err = cmd_status(sk, index, MGMT_OP_CANCEL_PAIR_DEVICE,
+                                               MGMT_STATUS_INVALID_PARAMS);
+               goto unlock;
+       }
+
+       conn = cmd->user_data;
+
+       if (bacmp(&addr->bdaddr, &conn->dst) != 0) {
+               err = cmd_status(sk, index, MGMT_OP_CANCEL_PAIR_DEVICE,
+                                               MGMT_STATUS_INVALID_PARAMS);
+               goto unlock;
+       }
+
+       pairing_complete(cmd, MGMT_STATUS_CANCELLED);
+
+       err = cmd_complete(sk, index, MGMT_OP_CANCEL_PAIR_DEVICE, addr,
+                                                               sizeof(*addr));
+unlock:
+       hci_dev_unlock(hdev);
+       hci_dev_put(hdev);
+
+       return err;
+}
+
 static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr,
                                        u16 mgmt_op, u16 hci_op, __le32 passkey)
 {
@@ -1683,7 +1700,7 @@ done:
 
 static int user_confirm_reply(struct sock *sk, u16 index, void *data, u16 len)
 {
-       struct mgmt_cp_user_confirm_reply *cp = (void *) data;
+       struct mgmt_cp_user_confirm_reply *cp = data;
 
        BT_DBG("");
 
@@ -1714,7 +1731,7 @@ static int user_confirm_neg_reply(struct sock *sk, u16 index, void *data,
 
 static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len)
 {
-       struct mgmt_cp_user_passkey_reply *cp = (void *) data;
+       struct mgmt_cp_user_passkey_reply *cp = data;
 
        BT_DBG("");
 
@@ -1730,7 +1747,7 @@ static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len)
 static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data,
                                                                        u16 len)
 {
-       struct mgmt_cp_user_passkey_neg_reply *cp = (void *) data;
+       struct mgmt_cp_user_passkey_neg_reply *cp = data;
 
        BT_DBG("");
 
@@ -1743,10 +1760,10 @@ static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data,
                        HCI_OP_USER_PASSKEY_NEG_REPLY, 0);
 }
 
-static int set_local_name(struct sock *sk, u16 index, unsigned char *data,
+static int set_local_name(struct sock *sk, u16 index, void *data,
                                                                u16 len)
 {
-       struct mgmt_cp_set_local_name *mgmt_cp = (void *) data;
+       struct mgmt_cp_set_local_name *mgmt_cp = data;
        struct hci_cp_write_local_name hci_cp;
        struct hci_dev *hdev;
        struct pending_cmd *cmd;
@@ -1765,7 +1782,8 @@ static int set_local_name(struct sock *sk, u16 index, unsigned char *data,
 
        hci_dev_lock(hdev);
 
-       cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len);
+       cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data,
+                                                                       len);
        if (!cmd) {
                err = -ENOMEM;
                goto failed;
@@ -1834,11 +1852,11 @@ unlock:
        return err;
 }
 
-static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data,
-                                                                       u16 len)
+static int add_remote_oob_data(struct sock *sk, u16 index, void *data,
+                                                               u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_add_remote_oob_data *cp = (void *) data;
+       struct mgmt_cp_add_remote_oob_data *cp = data;
        int err;
 
        BT_DBG("hci%u ", index);
@@ -1870,10 +1888,10 @@ static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data,
 }
 
 static int remove_remote_oob_data(struct sock *sk, u16 index,
-                                               unsigned char *data, u16 len)
+                                               void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_remove_remote_oob_data *cp = (void *) data;
+       struct mgmt_cp_remove_remote_oob_data *cp = data;
        int err;
 
        BT_DBG("hci%u ", index);
@@ -1904,9 +1922,10 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
 }
 
 static int start_discovery(struct sock *sk, u16 index,
-                                               unsigned char *data, u16 len)
+                                               void *data, u16 len)
 {
-       struct mgmt_cp_start_discovery *cp = (void *) data;
+       struct mgmt_cp_start_discovery *cp = data;
+       unsigned long discov_type = cp->type;
        struct pending_cmd *cmd;
        struct hci_dev *hdev;
        int err;
@@ -1930,15 +1949,31 @@ static int start_discovery(struct sock *sk, u16 index,
                goto failed;
        }
 
+       if (hdev->discovery.state != DISCOVERY_STOPPED) {
+               err = cmd_status(sk, index, MGMT_OP_START_DISCOVERY,
+                                               MGMT_STATUS_BUSY);
+               goto failed;
+       }
+
        cmd = mgmt_pending_add(sk, MGMT_OP_START_DISCOVERY, hdev, NULL, 0);
        if (!cmd) {
                err = -ENOMEM;
                goto failed;
        }
 
-       err = hci_do_inquiry(hdev, INQUIRY_LEN_BREDR);
+       if (test_bit(MGMT_ADDR_BREDR, &discov_type))
+               err = hci_do_inquiry(hdev, INQUIRY_LEN_BREDR);
+       else if (test_bit(MGMT_ADDR_LE_PUBLIC, &discov_type) &&
+                               test_bit(MGMT_ADDR_LE_RANDOM, &discov_type))
+               err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT,
+                                       LE_SCAN_WIN, LE_SCAN_TIMEOUT_LE_ONLY);
+       else
+               err = -EINVAL;
+
        if (err < 0)
                mgmt_pending_remove(cmd);
+       else
+               hci_discovery_set_state(hdev, DISCOVERY_STARTING);
 
 failed:
        hci_dev_unlock(hdev);
@@ -1951,6 +1986,8 @@ static int stop_discovery(struct sock *sk, u16 index)
 {
        struct hci_dev *hdev;
        struct pending_cmd *cmd;
+       struct hci_cp_remote_name_req_cancel cp;
+       struct inquiry_entry *e;
        int err;
 
        BT_DBG("hci%u", index);
@@ -1962,28 +1999,103 @@ static int stop_discovery(struct sock *sk, u16 index)
 
        hci_dev_lock(hdev);
 
+       if (!hci_discovery_active(hdev)) {
+               err = cmd_status(sk, index, MGMT_OP_STOP_DISCOVERY,
+                                               MGMT_STATUS_REJECTED);
+               goto unlock;
+       }
+
        cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, NULL, 0);
        if (!cmd) {
                err = -ENOMEM;
-               goto failed;
+               goto unlock;
        }
 
-       err = hci_cancel_inquiry(hdev);
+       if (hdev->discovery.state == DISCOVERY_INQUIRY) {
+               err = hci_cancel_inquiry(hdev);
+               if (err < 0)
+                       mgmt_pending_remove(cmd);
+               else
+                       hci_discovery_set_state(hdev, DISCOVERY_STOPPING);
+               goto unlock;
+       }
+
+       e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_PENDING);
+       if (!e) {
+               mgmt_pending_remove(cmd);
+               err = cmd_complete(sk, index, MGMT_OP_STOP_DISCOVERY, NULL, 0);
+               hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+               goto unlock;
+       }
+
+       bacpy(&cp.bdaddr, &e->data.bdaddr);
+       err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL,
+                                                       sizeof(cp), &cp);
        if (err < 0)
                mgmt_pending_remove(cmd);
+       else
+               hci_discovery_set_state(hdev, DISCOVERY_STOPPING);
 
-failed:
+unlock:
        hci_dev_unlock(hdev);
        hci_dev_put(hdev);
 
        return err;
 }
 
-static int block_device(struct sock *sk, u16 index, unsigned char *data,
-                                                               u16 len)
+static int confirm_name(struct sock *sk, u16 index, void *data, u16 len)
+{
+       struct mgmt_cp_confirm_name *cp = data;
+       struct inquiry_entry *e;
+       struct hci_dev *hdev;
+       int err;
+
+       BT_DBG("hci%u", index);
+
+       if (len != sizeof(*cp))
+               return cmd_status(sk, index, MGMT_OP_CONFIRM_NAME,
+                               MGMT_STATUS_INVALID_PARAMS);
+
+       hdev = hci_dev_get(index);
+       if (!hdev)
+               return cmd_status(sk, index, MGMT_OP_CONFIRM_NAME,
+                               MGMT_STATUS_INVALID_PARAMS);
+
+       hci_dev_lock(hdev);
+
+       if (!hci_discovery_active(hdev)) {
+               err = cmd_status(sk, index, MGMT_OP_CONFIRM_NAME,
+                                                       MGMT_STATUS_FAILED);
+               goto failed;
+       }
+
+       e = hci_inquiry_cache_lookup_unknown(hdev, &cp->bdaddr);
+       if (!e) {
+               err = cmd_status (sk, index, MGMT_OP_CONFIRM_NAME,
+                               MGMT_STATUS_INVALID_PARAMS);
+               goto failed;
+       }
+
+       if (cp->name_known) {
+               e->name_state = NAME_KNOWN;
+               list_del(&e->list);
+       } else {
+               e->name_state = NAME_NEEDED;
+               hci_inquiry_cache_update_resolve(hdev, e);
+       }
+
+       err = 0;
+
+failed:
+       hci_dev_unlock(hdev);
+
+       return err;
+}
+
+static int block_device(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_block_device *cp = (void *) data;
+       struct mgmt_cp_block_device *cp = data;
        int err;
 
        BT_DBG("hci%u", index);
@@ -2013,11 +2125,10 @@ static int block_device(struct sock *sk, u16 index, unsigned char *data,
        return err;
 }
 
-static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
-                                                               u16 len)
+static int unblock_device(struct sock *sk, u16 index, void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_cp_unblock_device *cp = (void *) data;
+       struct mgmt_cp_unblock_device *cp = data;
        int err;
 
        BT_DBG("hci%u", index);
@@ -2049,10 +2160,10 @@ static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
 }
 
 static int set_fast_connectable(struct sock *sk, u16 index,
-                                       unsigned char *data, u16 len)
+                                       void *data, u16 len)
 {
        struct hci_dev *hdev;
-       struct mgmt_mode *cp = (void *) data;
+       struct mgmt_mode *cp = data;
        struct hci_cp_write_page_scan_activity acp;
        u8 type;
        int err;
@@ -2104,9 +2215,64 @@ done:
        return err;
 }
 
+static int load_long_term_keys(struct sock *sk, u16 index,
+                                       void *cp_data, u16 len)
+{
+       struct hci_dev *hdev;
+       struct mgmt_cp_load_long_term_keys *cp = cp_data;
+       u16 key_count, expected_len;
+       int i;
+
+       if (len < sizeof(*cp))
+               return cmd_status(sk, index, MGMT_OP_LOAD_LONG_TERM_KEYS,
+                                                               EINVAL);
+
+       key_count = get_unaligned_le16(&cp->key_count);
+
+       expected_len = sizeof(*cp) + key_count *
+                                       sizeof(struct mgmt_ltk_info);
+       if (expected_len != len) {
+               BT_ERR("load_keys: expected %u bytes, got %u bytes",
+                                                       len, expected_len);
+               return cmd_status(sk, index, MGMT_OP_LOAD_LONG_TERM_KEYS,
+                                                               EINVAL);
+       }
+
+       hdev = hci_dev_get(index);
+       if (!hdev)
+               return cmd_status(sk, index, MGMT_OP_LOAD_LONG_TERM_KEYS,
+                                                               ENODEV);
+
+       BT_DBG("hci%u key_count %u", index, key_count);
+
+       hci_dev_lock(hdev);
+
+       hci_smp_ltks_clear(hdev);
+
+       for (i = 0; i < key_count; i++) {
+               struct mgmt_ltk_info *key = &cp->keys[i];
+               u8 type;
+
+               if (key->master)
+                       type = HCI_SMP_LTK;
+               else
+                       type = HCI_SMP_LTK_SLAVE;
+
+               hci_add_ltk(hdev, &key->addr.bdaddr, key->addr.type,
+                                       type, 0, key->authenticated, key->val,
+                                       key->enc_size, key->ediv, key->rand);
+       }
+
+       hci_dev_unlock(hdev);
+       hci_dev_put(hdev);
+
+       return 0;
+}
+
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 {
-       unsigned char *buf;
+       void *buf;
+       u8 *cp;
        struct mgmt_hdr *hdr;
        u16 opcode, index, len;
        int err;
@@ -2125,7 +2291,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
                goto done;
        }
 
-       hdr = (struct mgmt_hdr *) buf;
+       hdr = buf;
        opcode = get_unaligned_le16(&hdr->opcode);
        index = get_unaligned_le16(&hdr->index);
        len = get_unaligned_le16(&hdr->len);
@@ -2135,6 +2301,8 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
                goto done;
        }
 
+       cp = buf + sizeof(*hdr);
+
        switch (opcode) {
        case MGMT_OP_READ_VERSION:
                err = read_version(sk);
@@ -2146,92 +2314,97 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
                err = read_controller_info(sk, index);
                break;
        case MGMT_OP_SET_POWERED:
-               err = set_powered(sk, index, buf + sizeof(*hdr), len);
+               err = set_powered(sk, index, cp, len);
                break;
        case MGMT_OP_SET_DISCOVERABLE:
-               err = set_discoverable(sk, index, buf + sizeof(*hdr), len);
+               err = set_discoverable(sk, index, cp, len);
                break;
        case MGMT_OP_SET_CONNECTABLE:
-               err = set_connectable(sk, index, buf + sizeof(*hdr), len);
+               err = set_connectable(sk, index, cp, len);
                break;
        case MGMT_OP_SET_FAST_CONNECTABLE:
-               err = set_fast_connectable(sk, index, buf + sizeof(*hdr),
-                                                               len);
+               err = set_fast_connectable(sk, index, cp, len);
                break;
        case MGMT_OP_SET_PAIRABLE:
-               err = set_pairable(sk, index, buf + sizeof(*hdr), len);
+               err = set_pairable(sk, index, cp, len);
                break;
        case MGMT_OP_ADD_UUID:
-               err = add_uuid(sk, index, buf + sizeof(*hdr), len);
+               err = add_uuid(sk, index, cp, len);
                break;
        case MGMT_OP_REMOVE_UUID:
-               err = remove_uuid(sk, index, buf + sizeof(*hdr), len);
+               err = remove_uuid(sk, index, cp, len);
                break;
        case MGMT_OP_SET_DEV_CLASS:
-               err = set_dev_class(sk, index, buf + sizeof(*hdr), len);
+               err = set_dev_class(sk, index, cp, len);
                break;
        case MGMT_OP_LOAD_LINK_KEYS:
-               err = load_link_keys(sk, index, buf + sizeof(*hdr), len);
+               err = load_link_keys(sk, index, cp, len);
                break;
        case MGMT_OP_REMOVE_KEYS:
-               err = remove_keys(sk, index, buf + sizeof(*hdr), len);
+               err = remove_keys(sk, index, cp, len);
                break;
        case MGMT_OP_DISCONNECT:
-               err = disconnect(sk, index, buf + sizeof(*hdr), len);
+               err = disconnect(sk, index, cp, len);
                break;
        case MGMT_OP_GET_CONNECTIONS:
                err = get_connections(sk, index);
                break;
        case MGMT_OP_PIN_CODE_REPLY:
-               err = pin_code_reply(sk, index, buf + sizeof(*hdr), len);
+               err = pin_code_reply(sk, index, cp, len);
                break;
        case MGMT_OP_PIN_CODE_NEG_REPLY:
-               err = pin_code_neg_reply(sk, index, buf + sizeof(*hdr), len);
+               err = pin_code_neg_reply(sk, index, cp, len);
                break;
        case MGMT_OP_SET_IO_CAPABILITY:
-               err = set_io_capability(sk, index, buf + sizeof(*hdr), len);
+               err = set_io_capability(sk, index, cp, len);
                break;
        case MGMT_OP_PAIR_DEVICE:
-               err = pair_device(sk, index, buf + sizeof(*hdr), len);
+               err = pair_device(sk, index, cp, len);
+               break;
+       case MGMT_OP_CANCEL_PAIR_DEVICE:
+               err = cancel_pair_device(sk, index, buf + sizeof(*hdr), len);
                break;
        case MGMT_OP_USER_CONFIRM_REPLY:
-               err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len);
+               err = user_confirm_reply(sk, index, cp, len);
                break;
        case MGMT_OP_USER_CONFIRM_NEG_REPLY:
-               err = user_confirm_neg_reply(sk, index, buf + sizeof(*hdr),
-                                                                       len);
+               err = user_confirm_neg_reply(sk, index, cp, len);
                break;
        case MGMT_OP_USER_PASSKEY_REPLY:
-               err = user_passkey_reply(sk, index, buf + sizeof(*hdr), len);
+               err = user_passkey_reply(sk, index, cp, len);
                break;
        case MGMT_OP_USER_PASSKEY_NEG_REPLY:
-               err = user_passkey_neg_reply(sk, index, buf + sizeof(*hdr),
-                                                                       len);
+               err = user_passkey_neg_reply(sk, index, cp, len);
                break;
        case MGMT_OP_SET_LOCAL_NAME:
-               err = set_local_name(sk, index, buf + sizeof(*hdr), len);
+               err = set_local_name(sk, index, cp, len);
                break;
        case MGMT_OP_READ_LOCAL_OOB_DATA:
                err = read_local_oob_data(sk, index);
                break;
        case MGMT_OP_ADD_REMOTE_OOB_DATA:
-               err = add_remote_oob_data(sk, index, buf + sizeof(*hdr), len);
+               err = add_remote_oob_data(sk, index, cp, len);
                break;
        case MGMT_OP_REMOVE_REMOTE_OOB_DATA:
-               err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr),
-                                                                       len);
+               err = remove_remote_oob_data(sk, index, cp, len);
                break;
        case MGMT_OP_START_DISCOVERY:
-               err = start_discovery(sk, index, buf + sizeof(*hdr), len);
+               err = start_discovery(sk, index, cp, len);
                break;
        case MGMT_OP_STOP_DISCOVERY:
                err = stop_discovery(sk, index);
                break;
+       case MGMT_OP_CONFIRM_NAME:
+               err = confirm_name(sk, index, cp, len);
+               break;
        case MGMT_OP_BLOCK_DEVICE:
-               err = block_device(sk, index, buf + sizeof(*hdr), len);
+               err = block_device(sk, index, cp, len);
                break;
        case MGMT_OP_UNBLOCK_DEVICE:
-               err = unblock_device(sk, index, buf + sizeof(*hdr), len);
+               err = unblock_device(sk, index, cp, len);
+               break;
+       case MGMT_OP_LOAD_LONG_TERM_KEYS:
+               err = load_long_term_keys(sk, index, cp, len);
                break;
        default:
                BT_DBG("Unknown op %u", opcode);
@@ -2386,15 +2559,52 @@ int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
        return mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL);
 }
 
-int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
-                                                               u8 addr_type)
+int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent)
 {
-       struct mgmt_addr_info ev;
+       struct mgmt_ev_new_long_term_key ev;
 
-       bacpy(&ev.bdaddr, bdaddr);
-       ev.type = link_to_mgmt(link_type, addr_type);
+       memset(&ev, 0, sizeof(ev));
+
+       ev.store_hint = persistent;
+       bacpy(&ev.key.addr.bdaddr, &key->bdaddr);
+       ev.key.addr.type = key->bdaddr_type;
+       ev.key.authenticated = key->authenticated;
+       ev.key.enc_size = key->enc_size;
+       ev.key.ediv = key->ediv;
+
+       if (key->type == HCI_SMP_LTK)
+               ev.key.master = 1;
 
-       return mgmt_event(MGMT_EV_CONNECTED, hdev, &ev, sizeof(ev), NULL);
+       memcpy(ev.key.rand, key->rand, sizeof(key->rand));
+       memcpy(ev.key.val, key->val, sizeof(key->val));
+
+       return mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev,
+                                               &ev, sizeof(ev), NULL);
+}
+
+int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
+                                       u8 addr_type, u8 *name, u8 name_len,
+                                       u8 *dev_class)
+{
+       char buf[512];
+       struct mgmt_ev_device_connected *ev = (void *) buf;
+       u16 eir_len = 0;
+
+       bacpy(&ev->addr.bdaddr, bdaddr);
+       ev->addr.type = link_to_mgmt(link_type, addr_type);
+
+       if (name_len > 0)
+               eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE,
+                                                               name, name_len);
+
+       if (dev_class && memcmp(dev_class, "\0\0\0", 3) != 0)
+               eir_len = eir_append_data(&ev->eir[eir_len], eir_len,
+                                       EIR_CLASS_OF_DEV, dev_class, 3);
+
+       put_unaligned_le16(eir_len, &ev->eir_len);
+
+       return mgmt_event(MGMT_EV_DEVICE_CONNECTED, hdev, buf,
+                                               sizeof(*ev) + eir_len, NULL);
 }
 
 static void disconnect_rsp(struct pending_cmd *cmd, void *data)
@@ -2431,8 +2641,8 @@ static void remove_keys_rsp(struct pending_cmd *cmd, void *data)
        mgmt_pending_remove(cmd);
 }
 
-int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
-                                                               u8 addr_type)
+int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
+                                               u8 link_type, u8 addr_type)
 {
        struct mgmt_addr_info ev;
        struct sock *sk = NULL;
@@ -2443,7 +2653,8 @@ int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
        bacpy(&ev.bdaddr, bdaddr);
        ev.type = link_to_mgmt(link_type, addr_type);
 
-       err = mgmt_event(MGMT_EV_DISCONNECTED, hdev, &ev, sizeof(ev), sk);
+       err = mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev),
+                                                                       sk);
 
        if (sk)
                sock_put(sk);
@@ -2701,35 +2912,59 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
 }
 
 int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
-                               u8 addr_type, u8 *dev_class, s8 rssi, u8 *eir)
+                               u8 addr_type, u8 *dev_class, s8 rssi,
+                               u8 cfm_name, u8 *eir, u16 eir_len)
 {
-       struct mgmt_ev_device_found ev;
+       char buf[512];
+       struct mgmt_ev_device_found *ev = (void *) buf;
+       size_t ev_size;
 
-       memset(&ev, 0, sizeof(ev));
+       /* Leave 5 bytes for a potential CoD field */
+       if (sizeof(*ev) + eir_len + 5 > sizeof(buf))
+               return -EINVAL;
 
-       bacpy(&ev.addr.bdaddr, bdaddr);
-       ev.addr.type = link_to_mgmt(link_type, addr_type);
-       ev.rssi = rssi;
+       memset(buf, 0, sizeof(buf));
 
-       if (eir)
-               memcpy(ev.eir, eir, sizeof(ev.eir));
+       bacpy(&ev->addr.bdaddr, bdaddr);
+       ev->addr.type = link_to_mgmt(link_type, addr_type);
+       ev->rssi = rssi;
+       ev->confirm_name = cfm_name;
 
-       if (dev_class)
-               memcpy(ev.dev_class, dev_class, sizeof(ev.dev_class));
+       if (eir_len > 0)
+               memcpy(ev->eir, eir, eir_len);
 
-       return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, &ev, sizeof(ev), NULL);
+       if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV))
+               eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV,
+                                                               dev_class, 3);
+
+       put_unaligned_le16(eir_len, &ev->eir_len);
+
+       ev_size = sizeof(*ev) + eir_len;
+
+       return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL);
 }
 
-int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *name)
+int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
+                               u8 addr_type, s8 rssi, u8 *name, u8 name_len)
 {
-       struct mgmt_ev_remote_name ev;
+       struct mgmt_ev_device_found *ev;
+       char buf[sizeof(*ev) + HCI_MAX_NAME_LENGTH + 2];
+       u16 eir_len;
 
-       memset(&ev, 0, sizeof(ev));
+       ev = (struct mgmt_ev_device_found *) buf;
 
-       bacpy(&ev.bdaddr, bdaddr);
-       memcpy(ev.name, name, HCI_MAX_NAME_LENGTH);
+       memset(buf, 0, sizeof(buf));
+
+       bacpy(&ev->addr.bdaddr, bdaddr);
+       ev->addr.type = link_to_mgmt(link_type, addr_type);
+       ev->rssi = rssi;
 
-       return mgmt_event(MGMT_EV_REMOTE_NAME, hdev, &ev, sizeof(ev), NULL);
+       eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, name,
+                                                               name_len);
+
+       put_unaligned_le16(eir_len, &ev->eir_len);
+
+       return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, &ev, sizeof(ev), NULL);
 }
 
 int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status)