Bluetooth: use inclusive language to describe CPB
[linux-2.6-block.git] / net / bluetooth / hci_event.c
index ea06b010ccad76659ee3ff4892add9f2e54ab3c1..7c948244922878c98165bd3e8250207f4f3d3691 100644 (file)
@@ -2069,7 +2069,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;
@@ -3256,7 +3256,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 +3268,23 @@ unlock:
        hci_dev_unlock(hdev);
 }
 
+static inline void handle_cmd_cnt_and_timer(struct hci_dev *hdev,
+                                           u16 opcode, u8 ncmd)
+{
+       if (opcode != HCI_OP_NOP)
+               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,
@@ -3630,11 +3647,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, *opcode, ev->ncmd);
 
        hci_req_cmd_complete(hdev, *opcode, *status, req_complete,
                             req_complete_skb);
@@ -3735,11 +3748,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, *opcode, 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 +4339,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;
@@ -4404,12 +4413,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;
@@ -5187,6 +5196,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;
@@ -5204,7 +5230,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
        }
 
        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;
@@ -5441,7 +5467,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 +5498,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