Commit 354fe804 authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Convert L2CAP security callback to use hci_cb

There's no reason to have the custom hci_proto_auth/encrypt_cfm helpers
when the hci_cb list works equally well. This patch adds L2CAP to the
hci_cb list and makes l2cap_security_cfm a private function of
l2cap_core.c.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent fba7ecf0
...@@ -506,7 +506,6 @@ int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); ...@@ -506,7 +506,6 @@ int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
void l2cap_connect_cfm(struct hci_conn *hcon, u8 status); void l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
int l2cap_disconn_ind(struct hci_conn *hcon); int l2cap_disconn_ind(struct hci_conn *hcon);
void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason); void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags); int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
...@@ -1107,35 +1106,6 @@ static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason) ...@@ -1107,35 +1106,6 @@ static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
conn->disconn_cfm_cb(conn, reason); conn->disconn_cfm_cb(conn, reason);
} }
static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
{
__u8 encrypt;
if (conn->type != ACL_LINK && conn->type != LE_LINK)
return;
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
return;
encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
l2cap_security_cfm(conn, status, encrypt);
if (conn->security_cfm_cb)
conn->security_cfm_cb(conn, status);
}
static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
__u8 encrypt)
{
if (conn->type != ACL_LINK && conn->type != LE_LINK)
return;
l2cap_security_cfm(conn, status, encrypt);
if (conn->security_cfm_cb)
conn->security_cfm_cb(conn, status);
}
/* ----- HCI callbacks ----- */ /* ----- HCI callbacks ----- */
struct hci_cb { struct hci_cb {
struct list_head list; struct list_head list;
...@@ -1153,8 +1123,6 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) ...@@ -1153,8 +1123,6 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
struct hci_cb *cb; struct hci_cb *cb;
__u8 encrypt; __u8 encrypt;
hci_proto_auth_cfm(conn, status);
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
return; return;
...@@ -1166,6 +1134,9 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) ...@@ -1166,6 +1134,9 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
cb->security_cfm(conn, status, encrypt); cb->security_cfm(conn, status, encrypt);
} }
mutex_unlock(&hci_cb_list_lock); mutex_unlock(&hci_cb_list_lock);
if (conn->security_cfm_cb)
conn->security_cfm_cb(conn, status);
} }
static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
...@@ -1179,14 +1150,15 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, ...@@ -1179,14 +1150,15 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
if (conn->pending_sec_level > conn->sec_level) if (conn->pending_sec_level > conn->sec_level)
conn->sec_level = conn->pending_sec_level; conn->sec_level = conn->pending_sec_level;
hci_proto_encrypt_cfm(conn, status, encrypt);
mutex_lock(&hci_cb_list_lock); mutex_lock(&hci_cb_list_lock);
list_for_each_entry(cb, &hci_cb_list, list) { list_for_each_entry(cb, &hci_cb_list, list) {
if (cb->security_cfm) if (cb->security_cfm)
cb->security_cfm(conn, status, encrypt); cb->security_cfm(conn, status, encrypt);
} }
mutex_unlock(&hci_cb_list_lock); mutex_unlock(&hci_cb_list_lock);
if (conn->security_cfm_cb)
conn->security_cfm_cb(conn, status);
} }
static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
......
...@@ -7345,13 +7345,13 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt) ...@@ -7345,13 +7345,13 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt)
} }
} }
int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
{ {
struct l2cap_conn *conn = hcon->l2cap_data; struct l2cap_conn *conn = hcon->l2cap_data;
struct l2cap_chan *chan; struct l2cap_chan *chan;
if (!conn) if (!conn)
return 0; return;
BT_DBG("conn %p status 0x%2.2x encrypt %u", conn, status, encrypt); BT_DBG("conn %p status 0x%2.2x encrypt %u", conn, status, encrypt);
...@@ -7434,8 +7434,6 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) ...@@ -7434,8 +7434,6 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
} }
mutex_unlock(&conn->chan_lock); mutex_unlock(&conn->chan_lock);
return 0;
} }
int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
...@@ -7543,6 +7541,11 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) ...@@ -7543,6 +7541,11 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
return 0; return 0;
} }
static struct hci_cb l2cap_cb = {
.name = "L2CAP",
.security_cfm = l2cap_security_cfm,
};
static int l2cap_debugfs_show(struct seq_file *f, void *p) static int l2cap_debugfs_show(struct seq_file *f, void *p)
{ {
struct l2cap_chan *c; struct l2cap_chan *c;
...@@ -7584,6 +7587,8 @@ int __init l2cap_init(void) ...@@ -7584,6 +7587,8 @@ int __init l2cap_init(void)
if (err < 0) if (err < 0)
return err; return err;
hci_register_cb(&l2cap_cb);
if (IS_ERR_OR_NULL(bt_debugfs)) if (IS_ERR_OR_NULL(bt_debugfs))
return 0; return 0;
...@@ -7601,6 +7606,7 @@ int __init l2cap_init(void) ...@@ -7601,6 +7606,7 @@ int __init l2cap_init(void)
void l2cap_exit(void) void l2cap_exit(void)
{ {
debugfs_remove(l2cap_debugfs); debugfs_remove(l2cap_debugfs);
hci_unregister_cb(&l2cap_cb);
l2cap_cleanup_sockets(); l2cap_cleanup_sockets();
} }
......
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