networking: introduce and use skb_put_data()
[linux-block.git] / net / bluetooth / hci_core.c
index 7655b4005dfbfaecfae8c5d6d0956cb117ee7262..d860e3cc23cf151583e5d455edce572328e2168f 100644 (file)
@@ -548,6 +548,7 @@ static void hci_set_event_mask_page_2(struct hci_request *req)
 {
        struct hci_dev *hdev = req->hdev;
        u8 events[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+       bool changed = false;
 
        /* If Connectionless Slave Broadcast master role is supported
         * enable all necessary events for it.
@@ -557,6 +558,7 @@ static void hci_set_event_mask_page_2(struct hci_request *req)
                events[1] |= 0x80;      /* Synchronization Train Complete */
                events[2] |= 0x10;      /* Slave Page Response Timeout */
                events[2] |= 0x20;      /* CSB Channel Map Change */
+               changed = true;
        }
 
        /* If Connectionless Slave Broadcast slave role is supported
@@ -567,13 +569,24 @@ static void hci_set_event_mask_page_2(struct hci_request *req)
                events[2] |= 0x02;      /* CSB Receive */
                events[2] |= 0x04;      /* CSB Timeout */
                events[2] |= 0x08;      /* Truncated Page Complete */
+               changed = true;
        }
 
        /* Enable Authenticated Payload Timeout Expired event if supported */
-       if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING)
+       if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) {
                events[2] |= 0x80;
+               changed = true;
+       }
 
-       hci_req_add(req, HCI_OP_SET_EVENT_MASK_PAGE_2, sizeof(events), events);
+       /* Some Broadcom based controllers indicate support for Set Event
+        * Mask Page 2 command, but then actually do not support it. Since
+        * the default value is all bits set to zero, the command is only
+        * required if the event mask has to be changed. In case no change
+        * to the event mask is needed, skip this command.
+        */
+       if (changed)
+               hci_req_add(req, HCI_OP_SET_EVENT_MASK_PAGE_2,
+                           sizeof(events), events);
 }
 
 static int hci_init3_req(struct hci_request *req, unsigned long opt)
@@ -3253,7 +3266,7 @@ int hci_reset_dev(struct hci_dev *hdev)
                return -ENOMEM;
 
        hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
-       memcpy(skb_put(skb, 3), hw_err, 3);
+       skb_put_data(skb, hw_err, 3);
 
        /* Send Hardware Error to upper stack */
        return hci_recv_frame(hdev, skb);