aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-12-05 06:36:03 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-12-05 06:46:09 -0500
commit7776d1d8051469e61c8784076921ee16c1093ba1 (patch)
tree953bc69e7b40bae0f5785d3720333f6e2d0e31f1 /net/bluetooth/mgmt.c
parentf5818c2241247c0a5f967e41e952682b10db6fd6 (diff)
Bluetooth: Use cmd_complete callback for authentication mgmt commands
This patch converts the user confirmation & PIN code mgmt commands to take advantage of the new cmd_complete callback for pending mgmt commands. The patch also adds a new generic addr_cmd_complete() helper function to be used with commands that send a mgmt_addr_info response based on a mgmt_addr_info in the beginning of the command parameters. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 81b2886f64b8..0fc3d6914ef0 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1492,6 +1492,12 @@ static void generic_cmd_complete(struct pending_cmd *cmd, u8 status)
1492 cmd->param_len); 1492 cmd->param_len);
1493} 1493}
1494 1494
1495static void addr_cmd_complete(struct pending_cmd *cmd, u8 status)
1496{
1497 cmd_complete(cmd->sk, cmd->index, cmd->opcode, status, cmd->param,
1498 sizeof(struct mgmt_addr_info));
1499}
1500
1495static u8 mgmt_bredr_support(struct hci_dev *hdev) 1501static u8 mgmt_bredr_support(struct hci_dev *hdev)
1496{ 1502{
1497 if (!lmp_bredr_capable(hdev)) 1503 if (!lmp_bredr_capable(hdev))
@@ -3032,6 +3038,8 @@ static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data,
3032 goto failed; 3038 goto failed;
3033 } 3039 }
3034 3040
3041 cmd->cmd_complete = addr_cmd_complete;
3042
3035 bacpy(&reply.bdaddr, &cp->addr.bdaddr); 3043 bacpy(&reply.bdaddr, &cp->addr.bdaddr);
3036 reply.pin_len = cp->pin_len; 3044 reply.pin_len = cp->pin_len;
3037 memcpy(reply.pin_code, cp->pin_code, sizeof(reply.pin_code)); 3045 memcpy(reply.pin_code, cp->pin_code, sizeof(reply.pin_code));
@@ -3363,6 +3371,8 @@ static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
3363 goto done; 3371 goto done;
3364 } 3372 }
3365 3373
3374 cmd->cmd_complete = addr_cmd_complete;
3375
3366 /* Continue with pairing via HCI */ 3376 /* Continue with pairing via HCI */
3367 if (hci_op == HCI_OP_USER_PASSKEY_REPLY) { 3377 if (hci_op == HCI_OP_USER_PASSKEY_REPLY) {
3368 struct hci_cp_user_passkey_reply cp; 3378 struct hci_cp_user_passkey_reply cp;
@@ -6544,18 +6554,12 @@ void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
6544 u8 status) 6554 u8 status)
6545{ 6555{
6546 struct pending_cmd *cmd; 6556 struct pending_cmd *cmd;
6547 struct mgmt_rp_pin_code_reply rp;
6548 6557
6549 cmd = mgmt_pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); 6558 cmd = mgmt_pending_find(MGMT_OP_PIN_CODE_REPLY, hdev);
6550 if (!cmd) 6559 if (!cmd)
6551 return; 6560 return;
6552 6561
6553 bacpy(&rp.addr.bdaddr, bdaddr); 6562 cmd->cmd_complete(cmd, mgmt_status(status));
6554 rp.addr.type = BDADDR_BREDR;
6555
6556 cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_REPLY,
6557 mgmt_status(status), &rp, sizeof(rp));
6558
6559 mgmt_pending_remove(cmd); 6563 mgmt_pending_remove(cmd);
6560} 6564}
6561 6565
@@ -6563,18 +6567,12 @@ void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
6563 u8 status) 6567 u8 status)
6564{ 6568{
6565 struct pending_cmd *cmd; 6569 struct pending_cmd *cmd;
6566 struct mgmt_rp_pin_code_reply rp;
6567 6570
6568 cmd = mgmt_pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); 6571 cmd = mgmt_pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev);
6569 if (!cmd) 6572 if (!cmd)
6570 return; 6573 return;
6571 6574
6572 bacpy(&rp.addr.bdaddr, bdaddr); 6575 cmd->cmd_complete(cmd, mgmt_status(status));
6573 rp.addr.type = BDADDR_BREDR;
6574
6575 cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY,
6576 mgmt_status(status), &rp, sizeof(rp));
6577
6578 mgmt_pending_remove(cmd); 6576 mgmt_pending_remove(cmd);
6579} 6577}
6580 6578
@@ -6614,21 +6612,15 @@ static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
6614 u8 opcode) 6612 u8 opcode)
6615{ 6613{
6616 struct pending_cmd *cmd; 6614 struct pending_cmd *cmd;
6617 struct mgmt_rp_user_confirm_reply rp;
6618 int err;
6619 6615
6620 cmd = mgmt_pending_find(opcode, hdev); 6616 cmd = mgmt_pending_find(opcode, hdev);
6621 if (!cmd) 6617 if (!cmd)
6622 return -ENOENT; 6618 return -ENOENT;
6623 6619
6624 bacpy(&rp.addr.bdaddr, bdaddr); 6620 cmd->cmd_complete(cmd, mgmt_status(status));
6625 rp.addr.type = link_to_bdaddr(link_type, addr_type);
6626 err = cmd_complete(cmd->sk, hdev->id, opcode, mgmt_status(status),
6627 &rp, sizeof(rp));
6628
6629 mgmt_pending_remove(cmd); 6621 mgmt_pending_remove(cmd);
6630 6622
6631 return err; 6623 return 0;
6632} 6624}
6633 6625
6634int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 6626int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,