RISC-V: Correctly print supported extensions
[platform/kernel/linux-starfive.git] / net / bluetooth / hci_event.c
index 016b299..0bca035 100644 (file)
@@ -40,6 +40,8 @@
 #define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \
                 "\x00\x00\x00\x00\x00\x00\x00\x00"
 
+#define secs_to_jiffies(_secs) msecs_to_jiffies((_secs) * 1000)
+
 /* Handle HCI Event packets */
 
 static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb,
@@ -236,7 +238,7 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 
        hdev->ssp_debug_mode = 0;
 
-       hci_bdaddr_list_clear(&hdev->le_white_list);
+       hci_bdaddr_list_clear(&hdev->le_accept_list);
        hci_bdaddr_list_clear(&hdev->le_resolv_list);
 }
 
@@ -1171,6 +1173,12 @@ static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb)
 
        bacpy(&hdev->random_addr, sent);
 
+       if (!bacmp(&hdev->rpa, sent)) {
+               hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED);
+               queue_delayed_work(hdev->workqueue, &hdev->rpa_expired,
+                                  secs_to_jiffies(hdev->rpa_timeout));
+       }
+
        hci_dev_unlock(hdev);
 }
 
@@ -1201,24 +1209,30 @@ static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev,
 {
        __u8 status = *((__u8 *) skb->data);
        struct hci_cp_le_set_adv_set_rand_addr *cp;
-       struct adv_info *adv_instance;
+       struct adv_info *adv;
 
        if (status)
                return;
 
        cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR);
-       if (!cp)
+       /* Update only in case the adv instance since handle 0x00 shall be using
+        * HCI_OP_LE_SET_RANDOM_ADDR since that allows both extended and
+        * non-extended adverting.
+        */
+       if (!cp || !cp->handle)
                return;
 
        hci_dev_lock(hdev);
 
-       if (!cp->handle) {
-               /* Store in hdev for instance 0 (Set adv and Directed advs) */
-               bacpy(&hdev->random_addr, &cp->bdaddr);
-       } else {
-               adv_instance = hci_find_adv_instance(hdev, cp->handle);
-               if (adv_instance)
-                       bacpy(&adv_instance->random_addr, &cp->bdaddr);
+       adv = hci_find_adv_instance(hdev, cp->handle);
+       if (adv) {
+               bacpy(&adv->random_addr, &cp->bdaddr);
+               if (!bacmp(&hdev->rpa, &cp->bdaddr)) {
+                       adv->rpa_expired = false;
+                       queue_delayed_work(hdev->workqueue,
+                                          &adv->rpa_expired_cb,
+                                          secs_to_jiffies(hdev->rpa_timeout));
+               }
        }
 
        hci_dev_unlock(hdev);
@@ -1277,7 +1291,9 @@ static void hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev,
                                         struct sk_buff *skb)
 {
        struct hci_cp_le_set_ext_adv_enable *cp;
+       struct hci_cp_ext_adv_set *set;
        __u8 status = *((__u8 *) skb->data);
+       struct adv_info *adv = NULL, *n;
 
        BT_DBG("%s status 0x%2.2x", hdev->name, status);
 
@@ -1288,22 +1304,48 @@ static void hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev,
        if (!cp)
                return;
 
+       set = (void *)cp->data;
+
        hci_dev_lock(hdev);
 
+       if (cp->num_of_sets)
+               adv = hci_find_adv_instance(hdev, set->handle);
+
        if (cp->enable) {
                struct hci_conn *conn;
 
                hci_dev_set_flag(hdev, HCI_LE_ADV);
 
+               if (adv)
+                       adv->enabled = true;
+
                conn = hci_lookup_le_connect(hdev);
                if (conn)
                        queue_delayed_work(hdev->workqueue,
                                           &conn->le_conn_timeout,
                                           conn->conn_timeout);
        } else {
+               if (adv) {
+                       adv->enabled = false;
+                       /* If just one instance was disabled check if there are
+                        * any other instance enabled before clearing HCI_LE_ADV
+                        */
+                       list_for_each_entry_safe(adv, n, &hdev->adv_instances,
+                                                list) {
+                               if (adv->enabled)
+                                       goto unlock;
+                       }
+               } else {
+                       /* All instances shall be considered disabled */
+                       list_for_each_entry_safe(adv, n, &hdev->adv_instances,
+                                                list)
+                               adv->enabled = false;
+               }
+
                hci_dev_clear_flag(hdev, HCI_LE_ADV);
        }
 
+unlock:
        hci_dev_unlock(hdev);
 }
 
@@ -1492,21 +1534,21 @@ static void hci_cc_le_read_num_adv_sets(struct hci_dev *hdev,
        hdev->le_num_of_adv_sets = rp->num_of_sets;
 }
 
-static void hci_cc_le_read_white_list_size(struct hci_dev *hdev,
-                                          struct sk_buff *skb)
+static void hci_cc_le_read_accept_list_size(struct hci_dev *hdev,
+                                           struct sk_buff *skb)
 {
-       struct hci_rp_le_read_white_list_size *rp = (void *) skb->data;
+       struct hci_rp_le_read_accept_list_size *rp = (void *)skb->data;
 
        BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size);
 
        if (rp->status)
                return;
 
-       hdev->le_white_list_size = rp->size;
+       hdev->le_accept_list_size = rp->size;
 }
 
-static void hci_cc_le_clear_white_list(struct hci_dev *hdev,
-                                      struct sk_buff *skb)
+static void hci_cc_le_clear_accept_list(struct hci_dev *hdev,
+                                       struct sk_buff *skb)
 {
        __u8 status = *((__u8 *) skb->data);
 
@@ -1515,13 +1557,13 @@ static void hci_cc_le_clear_white_list(struct hci_dev *hdev,
        if (status)
                return;
 
-       hci_bdaddr_list_clear(&hdev->le_white_list);
+       hci_bdaddr_list_clear(&hdev->le_accept_list);
 }
 
-static void hci_cc_le_add_to_white_list(struct hci_dev *hdev,
-                                       struct sk_buff *skb)
+static void hci_cc_le_add_to_accept_list(struct hci_dev *hdev,
+                                        struct sk_buff *skb)
 {
-       struct hci_cp_le_add_to_white_list *sent;
+       struct hci_cp_le_add_to_accept_list *sent;
        __u8 status = *((__u8 *) skb->data);
 
        BT_DBG("%s status 0x%2.2x", hdev->name, status);
@@ -1529,18 +1571,18 @@ static void hci_cc_le_add_to_white_list(struct hci_dev *hdev,
        if (status)
                return;
 
-       sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_WHITE_LIST);
+       sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST);
        if (!sent)
                return;
 
-       hci_bdaddr_list_add(&hdev->le_white_list, &sent->bdaddr,
-                          sent->bdaddr_type);
+       hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr,
+                           sent->bdaddr_type);
 }
 
-static void hci_cc_le_del_from_white_list(struct hci_dev *hdev,
-                                         struct sk_buff *skb)
+static void hci_cc_le_del_from_accept_list(struct hci_dev *hdev,
+                                          struct sk_buff *skb)
 {
-       struct hci_cp_le_del_from_white_list *sent;
+       struct hci_cp_le_del_from_accept_list *sent;
        __u8 status = *((__u8 *) skb->data);
 
        BT_DBG("%s status 0x%2.2x", hdev->name, status);
@@ -1548,11 +1590,11 @@ static void hci_cc_le_del_from_white_list(struct hci_dev *hdev,
        if (status)
                return;
 
-       sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_WHITE_LIST);
+       sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST);
        if (!sent)
                return;
 
-       hci_bdaddr_list_del(&hdev->le_white_list, &sent->bdaddr,
+       hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr,
                            sent->bdaddr_type);
 }
 
@@ -2069,7 +2111,7 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
        if (conn &&
            (conn->state == BT_CONFIG || conn->state == BT_CONNECTED) &&
            !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
-               mgmt_device_connected(hdev, conn, 0, name, name_len);
+               mgmt_device_connected(hdev, conn, name, name_len);
 
        if (discov->state == DISCOVERY_STOPPED)
                return;
@@ -2306,19 +2348,20 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
 
        conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
        if (conn) {
-               u8 type = conn->type;
-
                mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
                                       conn->dst_type, status);
 
+               if (conn->type == LE_LINK) {
+                       hdev->cur_adv_instance = conn->adv_instance;
+                       hci_req_reenable_advertising(hdev);
+               }
+
                /* If the disconnection failed for any reason, the upper layer
                 * does not retry to disconnect in current implementation.
                 * Hence, we need to do some basic cleanup here and re-enable
                 * advertising if necessary.
                 */
                hci_conn_del(conn);
-               if (type == LE_LINK)
-                       hci_req_reenable_advertising(hdev);
        }
 
        hci_dev_unlock(hdev);
@@ -2367,7 +2410,7 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr,
        /* We don't want the connection attempt to stick around
         * indefinitely since LE doesn't have a page timeout concept
         * like BR/EDR. Set a timer for any connection that doesn't use
-        * the white list for connecting.
+        * the accept list for connecting.
         */
        if (filter_policy == HCI_LE_USE_PEER_ADDR)
                queue_delayed_work(conn->hdev->workqueue,
@@ -2623,7 +2666,7 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
                 * only used during suspend.
                 */
                if (ev->link_type == ACL_LINK &&
-                   hci_bdaddr_list_lookup_with_flags(&hdev->whitelist,
+                   hci_bdaddr_list_lookup_with_flags(&hdev->accept_list,
                                                      &ev->bdaddr,
                                                      BDADDR_BREDR)) {
                        conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr,
@@ -2745,19 +2788,19 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
                return;
        }
 
-       if (hci_bdaddr_list_lookup(&hdev->blacklist, &ev->bdaddr,
+       if (hci_bdaddr_list_lookup(&hdev->reject_list, &ev->bdaddr,
                                   BDADDR_BREDR)) {
                hci_reject_conn(hdev, &ev->bdaddr);
                return;
        }
 
-       /* Require HCI_CONNECTABLE or a whitelist entry to accept the
+       /* Require HCI_CONNECTABLE or an accept list entry to accept the
         * connection. These features are only touched through mgmt so
         * only do the checks if HCI_MGMT is set.
         */
        if (hci_dev_test_flag(hdev, HCI_MGMT) &&
            !hci_dev_test_flag(hdev, HCI_CONNECTABLE) &&
-           !hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, &ev->bdaddr,
+           !hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, &ev->bdaddr,
                                               BDADDR_BREDR)) {
                hci_reject_conn(hdev, &ev->bdaddr);
                return;
@@ -2795,9 +2838,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
                bacpy(&cp.bdaddr, &ev->bdaddr);
 
                if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
-                       cp.role = 0x00; /* Become master */
+                       cp.role = 0x00; /* Become central */
                else
-                       cp.role = 0x01; /* Remain slave */
+                       cp.role = 0x01; /* Remain peripheral */
 
                hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
        } else if (!(flags & HCI_PROTO_DEFER)) {
@@ -2844,7 +2887,6 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
        struct hci_conn_params *params;
        struct hci_conn *conn;
        bool mgmt_connected;
-       u8 type;
 
        BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
 
@@ -2899,10 +2941,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
                }
        }
 
-       type = conn->type;
-
        hci_disconn_cfm(conn, ev->reason);
-       hci_conn_del(conn);
 
        /* The suspend notifier is waiting for all devices to disconnect so
         * clear the bit from pending tasks and inform the wait queue.
@@ -2922,8 +2961,12 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
         * or until a connection is created or until the Advertising
         * is timed out due to Directed Advertising."
         */
-       if (type == LE_LINK)
+       if (conn->type == LE_LINK) {
+               hdev->cur_adv_instance = conn->adv_instance;
                hci_req_reenable_advertising(hdev);
+       }
+
+       hci_conn_del(conn);
 
 unlock:
        hci_dev_unlock(hdev);
@@ -3256,7 +3299,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev,
                cp.pscan_rep_mode = 0x02;
                hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
        } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
-               mgmt_device_connected(hdev, conn, 0, NULL, 0);
+               mgmt_device_connected(hdev, conn, NULL, 0);
 
        if (!hci_outgoing_auth_needed(hdev, conn)) {
                conn->state = BT_CONNECTED;
@@ -3268,6 +3311,21 @@ unlock:
        hci_dev_unlock(hdev);
 }
 
+static inline void handle_cmd_cnt_and_timer(struct hci_dev *hdev, u8 ncmd)
+{
+       cancel_delayed_work(&hdev->cmd_timer);
+
+       if (!test_bit(HCI_RESET, &hdev->flags)) {
+               if (ncmd) {
+                       cancel_delayed_work(&hdev->ncmd_timer);
+                       atomic_set(&hdev->cmd_cnt, 1);
+               } else {
+                       schedule_delayed_work(&hdev->ncmd_timer,
+                                             HCI_NCMD_TIMEOUT);
+               }
+       }
+}
+
 static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
                                 u16 *opcode, u8 *status,
                                 hci_req_complete_t *req_complete,
@@ -3521,20 +3579,20 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
                hci_cc_le_set_scan_enable(hdev, skb);
                break;
 
-       case HCI_OP_LE_READ_WHITE_LIST_SIZE:
-               hci_cc_le_read_white_list_size(hdev, skb);
+       case HCI_OP_LE_READ_ACCEPT_LIST_SIZE:
+               hci_cc_le_read_accept_list_size(hdev, skb);
                break;
 
-       case HCI_OP_LE_CLEAR_WHITE_LIST:
-               hci_cc_le_clear_white_list(hdev, skb);
+       case HCI_OP_LE_CLEAR_ACCEPT_LIST:
+               hci_cc_le_clear_accept_list(hdev, skb);
                break;
 
-       case HCI_OP_LE_ADD_TO_WHITE_LIST:
-               hci_cc_le_add_to_white_list(hdev, skb);
+       case HCI_OP_LE_ADD_TO_ACCEPT_LIST:
+               hci_cc_le_add_to_accept_list(hdev, skb);
                break;
 
-       case HCI_OP_LE_DEL_FROM_WHITE_LIST:
-               hci_cc_le_del_from_white_list(hdev, skb);
+       case HCI_OP_LE_DEL_FROM_ACCEPT_LIST:
+               hci_cc_le_del_from_accept_list(hdev, skb);
                break;
 
        case HCI_OP_LE_READ_SUPPORTED_STATES:
@@ -3630,11 +3688,7 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
                break;
        }
 
-       if (*opcode != HCI_OP_NOP)
-               cancel_delayed_work(&hdev->cmd_timer);
-
-       if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags))
-               atomic_set(&hdev->cmd_cnt, 1);
+       handle_cmd_cnt_and_timer(hdev, ev->ncmd);
 
        hci_req_cmd_complete(hdev, *opcode, *status, req_complete,
                             req_complete_skb);
@@ -3735,11 +3789,7 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb,
                break;
        }
 
-       if (*opcode != HCI_OP_NOP)
-               cancel_delayed_work(&hdev->cmd_timer);
-
-       if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags))
-               atomic_set(&hdev->cmd_cnt, 1);
+       handle_cmd_cnt_and_timer(hdev, ev->ncmd);
 
        /* Indicate request completion if the command failed. Also, if
         * we're not waiting for a special event and we get a success
@@ -4330,7 +4380,7 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev,
                cp.pscan_rep_mode = 0x02;
                hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
        } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
-               mgmt_device_connected(hdev, conn, 0, NULL, 0);
+               mgmt_device_connected(hdev, conn, NULL, 0);
 
        if (!hci_outgoing_auth_needed(hdev, conn)) {
                conn->state = BT_CONNECTED;
@@ -4373,6 +4423,21 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
 
        switch (ev->status) {
        case 0x00:
+               /* The synchronous connection complete event should only be
+                * sent once per new connection. Receiving a successful
+                * complete event when the connection status is already
+                * BT_CONNECTED means that the device is misbehaving and sent
+                * multiple complete event packets for the same new connection.
+                *
+                * Registering the device more than once can corrupt kernel
+                * memory, hence upon detecting this invalid event, we report
+                * an error and ignore the packet.
+                */
+               if (conn->state == BT_CONNECTED) {
+                       bt_dev_err(hdev, "Ignoring connect complete event for existing connection");
+                       goto unlock;
+               }
+
                conn->handle = __le16_to_cpu(ev->handle);
                conn->state  = BT_CONNECTED;
                conn->type   = ev->link_type;
@@ -4404,12 +4469,12 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
 
        bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode);
 
-       switch (conn->setting & SCO_AIRMODE_MASK) {
-       case SCO_AIRMODE_CVSD:
+       switch (ev->air_mode) {
+       case 0x02:
                if (hdev->notify)
                        hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD);
                break;
-       case SCO_AIRMODE_TRANSP:
+       case 0x03:
                if (hdev->notify)
                        hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_TRANSP);
                break;
@@ -5095,9 +5160,64 @@ static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev,
 }
 #endif
 
+static void le_conn_update_addr(struct hci_conn *conn, bdaddr_t *bdaddr,
+                               u8 bdaddr_type, bdaddr_t *local_rpa)
+{
+       if (conn->out) {
+               conn->dst_type = bdaddr_type;
+               conn->resp_addr_type = bdaddr_type;
+               bacpy(&conn->resp_addr, bdaddr);
+
+               /* Check if the controller has set a Local RPA then it must be
+                * used instead or hdev->rpa.
+                */
+               if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) {
+                       conn->init_addr_type = ADDR_LE_DEV_RANDOM;
+                       bacpy(&conn->init_addr, local_rpa);
+               } else if (hci_dev_test_flag(conn->hdev, HCI_PRIVACY)) {
+                       conn->init_addr_type = ADDR_LE_DEV_RANDOM;
+                       bacpy(&conn->init_addr, &conn->hdev->rpa);
+               } else {
+                       hci_copy_identity_address(conn->hdev, &conn->init_addr,
+                                                 &conn->init_addr_type);
+               }
+       } else {
+               conn->resp_addr_type = conn->hdev->adv_addr_type;
+               /* Check if the controller has set a Local RPA then it must be
+                * used instead or hdev->rpa.
+                */
+               if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) {
+                       conn->resp_addr_type = ADDR_LE_DEV_RANDOM;
+                       bacpy(&conn->resp_addr, local_rpa);
+               } else if (conn->hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) {
+                       /* In case of ext adv, resp_addr will be updated in
+                        * Adv Terminated event.
+                        */
+                       if (!ext_adv_capable(conn->hdev))
+                               bacpy(&conn->resp_addr,
+                                     &conn->hdev->random_addr);
+               } else {
+                       bacpy(&conn->resp_addr, &conn->hdev->bdaddr);
+               }
+
+               conn->init_addr_type = bdaddr_type;
+               bacpy(&conn->init_addr, bdaddr);
+
+               /* For incoming connections, set the default minimum
+                * and maximum connection interval. They will be used
+                * to check if the parameters are in range and if not
+                * trigger the connection update procedure.
+                */
+               conn->le_conn_min_interval = conn->hdev->le_conn_min_interval;
+               conn->le_conn_max_interval = conn->hdev->le_conn_max_interval;
+       }
+}
+
 static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
-                       bdaddr_t *bdaddr, u8 bdaddr_type, u8 role, u16 handle,
-                       u16 interval, u16 latency, u16 supervision_timeout)
+                                bdaddr_t *bdaddr, u8 bdaddr_type,
+                                bdaddr_t *local_rpa, u8 role, u16 handle,
+                                u16 interval, u16 latency,
+                                u16 supervision_timeout)
 {
        struct hci_conn_params *params;
        struct hci_conn *conn;
@@ -5122,8 +5242,8 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
                conn->dst_type = bdaddr_type;
 
                /* If we didn't have a hci_conn object previously
-                * but we're in master role this must be something
-                * initiated using a white list. Since white list based
+                * but we're in central role this must be something
+                * initiated using an accept list. Since accept list based
                 * connections are not "first class citizens" we don't
                 * have full tracking of them. Therefore, we go ahead
                 * with a "best effort" approach of determining the
@@ -5145,32 +5265,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
                cancel_delayed_work(&conn->le_conn_timeout);
        }
 
-       if (!conn->out) {
-               /* Set the responder (our side) address type based on
-                * the advertising address type.
-                */
-               conn->resp_addr_type = hdev->adv_addr_type;
-               if (hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) {
-                       /* In case of ext adv, resp_addr will be updated in
-                        * Adv Terminated event.
-                        */
-                       if (!ext_adv_capable(hdev))
-                               bacpy(&conn->resp_addr, &hdev->random_addr);
-               } else {
-                       bacpy(&conn->resp_addr, &hdev->bdaddr);
-               }
-
-               conn->init_addr_type = bdaddr_type;
-               bacpy(&conn->init_addr, bdaddr);
-
-               /* For incoming connections, set the default minimum
-                * and maximum connection interval. They will be used
-                * to check if the parameters are in range and if not
-                * trigger the connection update procedure.
-                */
-               conn->le_conn_min_interval = hdev->le_conn_min_interval;
-               conn->le_conn_max_interval = hdev->le_conn_max_interval;
-       }
+       le_conn_update_addr(conn, bdaddr, bdaddr_type, local_rpa);
 
        /* Lookup the identity address from the stored connection
         * address and address type.
@@ -5187,6 +5282,23 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
                conn->dst_type = irk->addr_type;
        }
 
+       /* When using controller based address resolution, then the new
+        * address types 0x02 and 0x03 are used. These types need to be
+        * converted back into either public address or random address type
+        */
+       if (use_ll_privacy(hdev) &&
+           hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
+           hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) {
+               switch (conn->dst_type) {
+               case ADDR_LE_DEV_PUBLIC_RESOLVED:
+                       conn->dst_type = ADDR_LE_DEV_PUBLIC;
+                       break;
+               case ADDR_LE_DEV_RANDOM_RESOLVED:
+                       conn->dst_type = ADDR_LE_DEV_RANDOM;
+                       break;
+               }
+       }
+
        if (status) {
                hci_le_conn_failed(conn, status);
                goto unlock;
@@ -5198,18 +5310,25 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
                addr_type = BDADDR_LE_RANDOM;
 
        /* Drop the connection if the device is blocked */
-       if (hci_bdaddr_list_lookup(&hdev->blacklist, &conn->dst, addr_type)) {
+       if (hci_bdaddr_list_lookup(&hdev->reject_list, &conn->dst, addr_type)) {
                hci_conn_drop(conn);
                goto unlock;
        }
 
        if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
-               mgmt_device_connected(hdev, conn, 0, NULL, 0);
+               mgmt_device_connected(hdev, conn, NULL, 0);
 
        conn->sec_level = BT_SECURITY_LOW;
        conn->handle = handle;
        conn->state = BT_CONFIG;
 
+       /* Store current advertising instance as connection advertising instance
+        * when sotfware rotation is in use so it can be re-enabled when
+        * disconnected.
+        */
+       if (!ext_adv_capable(hdev))
+               conn->adv_instance = hdev->cur_adv_instance;
+
        conn->le_conn_interval = interval;
        conn->le_conn_latency = latency;
        conn->le_supv_timeout = supervision_timeout;
@@ -5217,17 +5336,17 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
        hci_debugfs_create_conn(conn);
        hci_conn_add_sysfs(conn);
 
-       /* The remote features procedure is defined for master
+       /* The remote features procedure is defined for central
         * role only. So only in case of an initiated connection
         * request the remote features.
         *
-        * If the local controller supports slave-initiated features
-        * exchange, then requesting the remote features in slave
+        * If the local controller supports peripheral-initiated features
+        * exchange, then requesting the remote features in peripheral
         * role is possible. Otherwise just transition into the
         * connected state without requesting the remote features.
         */
        if (conn->out ||
-           (hdev->le_features[0] & HCI_LE_SLAVE_FEATURES)) {
+           (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) {
                struct hci_cp_le_read_remote_features cp;
 
                cp.handle = __cpu_to_le16(conn->handle);
@@ -5264,7 +5383,7 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
        BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
 
        le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
-                            ev->role, le16_to_cpu(ev->handle),
+                            NULL, ev->role, le16_to_cpu(ev->handle),
                             le16_to_cpu(ev->interval),
                             le16_to_cpu(ev->latency),
                             le16_to_cpu(ev->supervision_timeout));
@@ -5278,7 +5397,7 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
        BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
 
        le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
-                            ev->role, le16_to_cpu(ev->handle),
+                            &ev->local_rpa, ev->role, le16_to_cpu(ev->handle),
                             le16_to_cpu(ev->interval),
                             le16_to_cpu(ev->latency),
                             le16_to_cpu(ev->supervision_timeout));
@@ -5293,17 +5412,35 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
        struct hci_evt_le_ext_adv_set_term *ev = (void *) skb->data;
        struct hci_conn *conn;
+       struct adv_info *adv;
 
        BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
 
-       if (ev->status)
+       adv = hci_find_adv_instance(hdev, ev->handle);
+
+       if (ev->status) {
+               if (!adv)
+                       return;
+
+               /* Remove advertising as it has been terminated */
+               hci_remove_adv_instance(hdev, ev->handle);
+               mgmt_advertising_removed(NULL, hdev, ev->handle);
+
                return;
+       }
+
+       if (adv)
+               adv->enabled = false;
 
        conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle));
        if (conn) {
-               struct adv_info *adv_instance;
+               /* Store handle in the connection so the correct advertising
+                * instance can be re-enabled when disconnected.
+                */
+               conn->adv_instance = ev->handle;
 
-               if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM)
+               if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM ||
+                   bacmp(&conn->resp_addr, BDADDR_ANY))
                        return;
 
                if (!ev->handle) {
@@ -5311,9 +5448,8 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb)
                        return;
                }
 
-               adv_instance = hci_find_adv_instance(hdev, ev->handle);
-               if (adv_instance)
-                       bacpy(&conn->resp_addr, &adv_instance->random_addr);
+               if (adv)
+                       bacpy(&conn->resp_addr, &adv->random_addr);
        }
 }
 
@@ -5354,13 +5490,13 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
                return NULL;
 
        /* Ignore if the device is blocked */
-       if (hci_bdaddr_list_lookup(&hdev->blacklist, addr, addr_type))
+       if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type))
                return NULL;
 
        /* Most controller will fail if we try to create new connections
-        * while we have an existing one in slave role.
+        * while we have an existing one in peripheral role.
         */
-       if (hdev->conn_hash.le_num_slave > 0 &&
+       if (hdev->conn_hash.le_num_peripheral > 0 &&
            (!test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) ||
             !(hdev->le_states[3] & 0x10)))
                return NULL;
@@ -5378,7 +5514,7 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
                case HCI_AUTO_CONN_DIRECT:
                        /* Only devices advertising with ADV_DIRECT_IND are
                         * triggering a connection attempt. This is allowing
-                        * incoming connections from slave devices.
+                        * incoming connections from peripheral devices.
                         */
                        if (adv_type != LE_ADV_DIRECT_IND)
                                return NULL;
@@ -5386,8 +5522,8 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
                case HCI_AUTO_CONN_ALWAYS:
                        /* Devices advertising with ADV_IND or ADV_DIRECT_IND
                         * are triggering a connection attempt. This means
-                        * that incoming connections from slave device are
-                        * accepted and also outgoing connections to slave
+                        * that incoming connections from peripheral device are
+                        * accepted and also outgoing connections to peripheral
                         * devices are established when found.
                         */
                        break;
@@ -5441,7 +5577,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
        struct hci_conn *conn;
        bool match;
        u32 flags;
-       u8 *ptr, real_len;
+       u8 *ptr;
 
        switch (type) {
        case LE_ADV_IND:
@@ -5472,14 +5608,10 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
                        break;
        }
 
-       real_len = ptr - data;
-
-       /* Adjust for actual length */
-       if (len != real_len) {
-               bt_dev_err_ratelimited(hdev, "advertising data len corrected %u -> %u",
-                                      len, real_len);
-               len = real_len;
-       }
+       /* Adjust for actual length. This handles the case when remote
+        * device is advertising with incorrect data length.
+        */
+       len = ptr - data;
 
        /* If the direct address is present, then this report is from
         * a LE Direct Advertising Report event. In that case it is
@@ -5752,7 +5884,7 @@ static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev,
                if (conn->state == BT_CONFIG) {
                        __u8 status;
 
-                       /* If the local controller supports slave-initiated
+                       /* If the local controller supports peripheral-initiated
                         * features exchange, but the remote controller does
                         * not, then it is possible that the error code 0x1a
                         * for unsupported remote feature gets returned.
@@ -5761,8 +5893,8 @@ static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev,
                         * transition into connected state and mark it as
                         * successful.
                         */
-                       if ((hdev->le_features[0] & HCI_LE_SLAVE_FEATURES) &&
-                           !conn->out && ev->status == 0x1a)
+                       if (!conn->out && ev->status == 0x1a &&
+                           (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES))
                                status = 0x00;
                        else
                                status = ev->status;
@@ -6032,7 +6164,7 @@ static bool hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode,
                return true;
        }
 
-       /* Check if request ended in Command Status - no way to retreive
+       /* Check if request ended in Command Status - no way to retrieve
         * any extra parameters in this case.
         */
        if (hdr->evt == HCI_EV_CMD_STATUS)