Bluetooth: Use hci_update_random_address() for initiating LE scan
authorJohan Hedberg <johan.hedberg@intel.com>
Sun, 23 Feb 2014 17:42:24 +0000 (19:42 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 23 Feb 2014 20:24:26 +0000 (12:24 -0800)
When we start LE scanning we need to update the local random address if
necessary. This patch updates the code to use hci_update_random_address()
for setting the own_address_type scan parameter and updating the local
random address if necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/mgmt.c

index 8df287ba9ba3866af4d76e63f5d99d1ce60c2f07..e369c871c7025db7c8b9f30a783914a21c499335 100644 (file)
@@ -3294,7 +3294,7 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
        struct hci_request req;
        /* General inquiry access code (GIAC) */
        u8 lap[3] = { 0x33, 0x8b, 0x9e };
-       u8 status;
+       u8 status, own_addr_type;
        int err;
 
        BT_DBG("%s", hdev->name);
@@ -3387,10 +3387,19 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
                }
 
                memset(&param_cp, 0, sizeof(param_cp));
+
+               err = hci_update_random_address(&req, &own_addr_type);
+               if (err < 0) {
+                       err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
+                                        MGMT_STATUS_FAILED);
+                       mgmt_pending_remove(cmd);
+                       goto failed;
+               }
+
                param_cp.type = LE_SCAN_ACTIVE;
                param_cp.interval = cpu_to_le16(DISCOV_LE_SCAN_INT);
                param_cp.window = cpu_to_le16(DISCOV_LE_SCAN_WIN);
-               param_cp.own_address_type = hdev->own_addr_type;
+               param_cp.own_address_type = own_addr_type;
                hci_req_add(&req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
                            &param_cp);