diff options
| author | Johan Hedberg <johan.hedberg@intel.com> | 2014-10-26 15:33:47 -0400 |
|---|---|---|
| committer | Marcel Holtmann <marcel@holtmann.org> | 2014-12-03 10:51:20 -0500 |
| commit | 81328d5cca7e1cff6296a63a3c1b671d09ddb3ee (patch) | |
| tree | 92656f21f12461a8ca4f101e82b3a3c2ebb83651 | |
| parent | 903b71c78d56af56a5f4d53a8dbef8032d1949bf (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>
| -rw-r--r-- | include/net/bluetooth/hci_core.h | 6 | ||||
| -rw-r--r-- | net/bluetooth/hci_core.c | 46 | ||||
| -rw-r--r-- | net/bluetooth/mgmt.c | 9 |
3 files changed, 22 insertions, 39 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index f39e65096b1f..3e89ece75039 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h | |||
| @@ -944,10 +944,8 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev); | |||
| 944 | struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, | 944 | struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, |
| 945 | bdaddr_t *bdaddr); | 945 | bdaddr_t *bdaddr); |
| 946 | int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, | 946 | int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 947 | u8 *hash, u8 *rand); | 947 | u8 *hash192, u8 *rand192, |
| 948 | int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, | 948 | u8 *hash256, u8 *rand256); |
| 949 | u8 *hash192, u8 *rand192, | ||
| 950 | u8 *hash256, u8 *rand256); | ||
| 951 | int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); | 949 | int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); |
| 952 | 950 | ||
| 953 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); | 951 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); |
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 | ||
| 3519 | int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, | 3519 | int 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 | |||
| 3545 | int 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 |
