aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-10-26 15:33:47 -0400
committerMarcel Holtmann <marcel@holtmann.org>2014-12-03 10:51:20 -0500
commit81328d5cca7e1cff6296a63a3c1b671d09ddb3ee (patch)
tree92656f21f12461a8ca4f101e82b3a3c2ebb83651 /net/bluetooth
parent903b71c78d56af56a5f4d53a8dbef8032d1949bf (diff)
Bluetooth: Unify remote OOB data functions
There's no need to duplicate code for the 192 vs 192+256 variants of the OOB data functions. This is also helpful to pave the way to support LE SC OOB data where only 256 bit data is provided. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/hci_core.c46
-rw-r--r--net/bluetooth/mgmt.c9
2 files changed, 20 insertions, 35 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 581e13e9dc32..967fbfe80f1f 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3517,7 +3517,8 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev)
3517} 3517}
3518 3518
3519int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 3519int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3520 u8 *hash, u8 *rand) 3520 u8 *hash192, u8 *rand192,
3521 u8 *hash256, u8 *rand256)
3521{ 3522{
3522 struct oob_data *data; 3523 struct oob_data *data;
3523 3524
@@ -3531,38 +3532,21 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3531 list_add(&data->list, &hdev->remote_oob_data); 3532 list_add(&data->list, &hdev->remote_oob_data);
3532 } 3533 }
3533 3534
3534 memcpy(data->hash192, hash, sizeof(data->hash192)); 3535 if (hash192 && rand192) {
3535 memcpy(data->rand192, rand, sizeof(data->rand192)); 3536 memcpy(data->hash192, hash192, sizeof(data->hash192));
3536 3537 memcpy(data->rand192, rand192, sizeof(data->rand192));
3537 memset(data->hash256, 0, sizeof(data->hash256)); 3538 } else {
3538 memset(data->rand256, 0, sizeof(data->rand256)); 3539 memset(data->hash192, 0, sizeof(data->hash192));
3539 3540 memset(data->rand192, 0, sizeof(data->rand192));
3540 BT_DBG("%s for %pMR", hdev->name, bdaddr);
3541
3542 return 0;
3543}
3544
3545int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3546 u8 *hash192, u8 *rand192,
3547 u8 *hash256, u8 *rand256)
3548{
3549 struct oob_data *data;
3550
3551 data = hci_find_remote_oob_data(hdev, bdaddr);
3552 if (!data) {
3553 data = kmalloc(sizeof(*data), GFP_KERNEL);
3554 if (!data)
3555 return -ENOMEM;
3556
3557 bacpy(&data->bdaddr, bdaddr);
3558 list_add(&data->list, &hdev->remote_oob_data);
3559 } 3541 }
3560 3542
3561 memcpy(data->hash192, hash192, sizeof(data->hash192)); 3543 if (hash256 && rand256) {
3562 memcpy(data->rand192, rand192, sizeof(data->rand192)); 3544 memcpy(data->hash256, hash256, sizeof(data->hash256));
3563 3545 memcpy(data->rand256, rand256, sizeof(data->rand256));
3564 memcpy(data->hash256, hash256, sizeof(data->hash256)); 3546 } else {
3565 memcpy(data->rand256, rand256, sizeof(data->rand256)); 3547 memset(data->hash256, 0, sizeof(data->hash256));
3548 memset(data->rand256, 0, sizeof(data->rand256));
3549 }
3566 3550
3567 BT_DBG("%s for %pMR", hdev->name, bdaddr); 3551 BT_DBG("%s for %pMR", hdev->name, bdaddr);
3568 3552
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 6e8165364b7f..0d92ba99ca93 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3599,7 +3599,8 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
3599 } 3599 }
3600 3600
3601 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, 3601 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr,
3602 cp->hash, cp->rand); 3602 cp->hash, cp->rand,
3603 NULL, NULL);
3603 if (err < 0) 3604 if (err < 0)
3604 status = MGMT_STATUS_FAILED; 3605 status = MGMT_STATUS_FAILED;
3605 else 3606 else
@@ -3619,9 +3620,9 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
3619 goto unlock; 3620 goto unlock;
3620 } 3621 }
3621 3622
3622 err = hci_add_remote_oob_ext_data(hdev, &cp->addr.bdaddr, 3623 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr,
3623 cp->hash192, cp->rand192, 3624 cp->hash192, cp->rand192,
3624 cp->hash256, cp->rand256); 3625 cp->hash256, cp->rand256);
3625 if (err < 0) 3626 if (err < 0)
3626 status = MGMT_STATUS_FAILED; 3627 status = MGMT_STATUS_FAILED;
3627 else 3628 else