提交 81328d5c 编写于 作者: J Johan Hedberg 提交者: Marcel Holtmann

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: NJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
上级 903b71c7
...@@ -944,10 +944,8 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev); ...@@ -944,10 +944,8 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev);
struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
bdaddr_t *bdaddr); bdaddr_t *bdaddr);
int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
u8 *hash, u8 *rand); u8 *hash192, u8 *rand192,
int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash256, u8 *rand256);
u8 *hash192, u8 *rand192,
u8 *hash256, u8 *rand256);
int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
......
...@@ -3517,7 +3517,8 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev) ...@@ -3517,7 +3517,8 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev)
} }
int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
u8 *hash, u8 *rand) u8 *hash192, u8 *rand192,
u8 *hash256, u8 *rand256)
{ {
struct oob_data *data; struct oob_data *data;
...@@ -3531,38 +3532,21 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, ...@@ -3531,38 +3532,21 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
list_add(&data->list, &hdev->remote_oob_data); list_add(&data->list, &hdev->remote_oob_data);
} }
memcpy(data->hash192, hash, sizeof(data->hash192)); if (hash192 && rand192) {
memcpy(data->rand192, rand, sizeof(data->rand192)); memcpy(data->hash192, hash192, sizeof(data->hash192));
memcpy(data->rand192, rand192, sizeof(data->rand192));
memset(data->hash256, 0, sizeof(data->hash256)); } else {
memset(data->rand256, 0, sizeof(data->rand256)); memset(data->hash192, 0, sizeof(data->hash192));
memset(data->rand192, 0, sizeof(data->rand192));
BT_DBG("%s for %pMR", hdev->name, bdaddr);
return 0;
}
int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
u8 *hash192, u8 *rand192,
u8 *hash256, u8 *rand256)
{
struct oob_data *data;
data = hci_find_remote_oob_data(hdev, bdaddr);
if (!data) {
data = kmalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
bacpy(&data->bdaddr, bdaddr);
list_add(&data->list, &hdev->remote_oob_data);
} }
memcpy(data->hash192, hash192, sizeof(data->hash192)); if (hash256 && rand256) {
memcpy(data->rand192, rand192, sizeof(data->rand192)); memcpy(data->hash256, hash256, sizeof(data->hash256));
memcpy(data->rand256, rand256, sizeof(data->rand256));
memcpy(data->hash256, hash256, sizeof(data->hash256)); } else {
memcpy(data->rand256, rand256, sizeof(data->rand256)); memset(data->hash256, 0, sizeof(data->hash256));
memset(data->rand256, 0, sizeof(data->rand256));
}
BT_DBG("%s for %pMR", hdev->name, bdaddr); BT_DBG("%s for %pMR", hdev->name, bdaddr);
......
...@@ -3599,7 +3599,8 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, ...@@ -3599,7 +3599,8 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
} }
err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr,
cp->hash, cp->rand); cp->hash, cp->rand,
NULL, NULL);
if (err < 0) if (err < 0)
status = MGMT_STATUS_FAILED; status = MGMT_STATUS_FAILED;
else else
...@@ -3619,9 +3620,9 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, ...@@ -3619,9 +3620,9 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
goto unlock; goto unlock;
} }
err = hci_add_remote_oob_ext_data(hdev, &cp->addr.bdaddr, err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr,
cp->hash192, cp->rand192, cp->hash192, cp->rand192,
cp->hash256, cp->rand256); cp->hash256, cp->rand256);
if (err < 0) if (err < 0)
status = MGMT_STATUS_FAILED; status = MGMT_STATUS_FAILED;
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册