Commit 70c46425 authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Refactor connection request handling

The conditions for accepting an incoming connections are already
non-trivial and will become more so once a white list is added. This
patch breaks up the checks for when to reject the request by creating a
helper function for it.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent dee58c1e
...@@ -2121,10 +2121,21 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2121,10 +2121,21 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_conn_check_pending(hdev); hci_conn_check_pending(hdev);
} }
static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr)
{
struct hci_cp_reject_conn_req cp;
bacpy(&cp.bdaddr, bdaddr);
cp.reason = HCI_ERROR_REJ_BAD_ADDR;
hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
}
static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
{ {
struct hci_ev_conn_request *ev = (void *) skb->data; struct hci_ev_conn_request *ev = (void *) skb->data;
int mask = hdev->link_mode; int mask = hdev->link_mode;
struct inquiry_entry *ie;
struct hci_conn *conn;
__u8 flags = 0; __u8 flags = 0;
BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr, BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr,
...@@ -2133,12 +2144,18 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2133,12 +2144,18 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type, mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type,
&flags); &flags);
if ((mask & HCI_LM_ACCEPT) && if (!(mask & HCI_LM_ACCEPT)) {
!hci_bdaddr_list_lookup(&hdev->blacklist, &ev->bdaddr, hci_reject_conn(hdev, &ev->bdaddr);
return;
}
if (!hci_bdaddr_list_lookup(&hdev->blacklist, &ev->bdaddr,
BDADDR_BREDR)) { BDADDR_BREDR)) {
hci_reject_conn(hdev, &ev->bdaddr);
return;
}
/* Connection accepted */ /* Connection accepted */
struct inquiry_entry *ie;
struct hci_conn *conn;
hci_dev_lock(hdev); hci_dev_lock(hdev);
...@@ -2173,8 +2190,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2173,8 +2190,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
else else
cp.role = 0x01; /* Remain slave */ cp.role = 0x01; /* Remain slave */
hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
&cp);
} else if (!(flags & HCI_PROTO_DEFER)) { } else if (!(flags & HCI_PROTO_DEFER)) {
struct hci_cp_accept_sync_conn_req cp; struct hci_cp_accept_sync_conn_req cp;
conn->state = BT_CONNECT; conn->state = BT_CONNECT;
...@@ -2188,20 +2204,12 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2188,20 +2204,12 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
cp.content_format = cpu_to_le16(hdev->voice_setting); cp.content_format = cpu_to_le16(hdev->voice_setting);
cp.retrans_effort = 0xff; cp.retrans_effort = 0xff;
hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp),
sizeof(cp), &cp); &cp);
} else { } else {
conn->state = BT_CONNECT2; conn->state = BT_CONNECT2;
hci_proto_connect_cfm(conn, 0); hci_proto_connect_cfm(conn, 0);
} }
} else {
/* Connection rejected */
struct hci_cp_reject_conn_req cp;
bacpy(&cp.bdaddr, &ev->bdaddr);
cp.reason = HCI_ERROR_REJ_BAD_ADDR;
hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
}
} }
static u8 hci_to_mgmt_reason(u8 err) static u8 hci_to_mgmt_reason(u8 err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment