diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2013-10-13 11:50:41 -0400 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2013-10-13 11:58:30 -0400 |
commit | 4f1654e08464abad06487e173661cb73721d27a7 (patch) | |
tree | 03906a24a3ad343060e5cec47f59513b3a4e6998 /net/bluetooth/l2cap_core.c | |
parent | 7eafc59e2f547fce3a31b3e2d03c14d57e9162b2 (diff) |
Bluetooth: Return the correct address type for L2CAP sockets
The L2CAP sockets can use BR/EDR public, LE public and LE random
addresses for various combinations of source and destination
devices. So make sure that getsockname(), getpeername() and
accept() return the correct address type.
For this the address type of the source and destination is stored
with the L2CAP channel information. The stored address type is
not the one specific for the HCI protocol. It is the address
type used for the L2CAP sockets and the management interface.
The underlying HCI connections store the HCI address type. If
needed, it gets converted to the socket address type.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net/bluetooth/l2cap_core.c')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index be3e0f8c6f8b..769c379b3eeb 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -59,6 +59,18 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err); | |||
59 | static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control, | 59 | static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control, |
60 | struct sk_buff_head *skbs, u8 event); | 60 | struct sk_buff_head *skbs, u8 event); |
61 | 61 | ||
62 | static inline __u8 bdaddr_type(struct hci_conn *hcon, __u8 type) | ||
63 | { | ||
64 | if (hcon->type == LE_LINK) { | ||
65 | if (type == ADDR_LE_DEV_PUBLIC) | ||
66 | return BDADDR_LE_PUBLIC; | ||
67 | else | ||
68 | return BDADDR_LE_RANDOM; | ||
69 | } | ||
70 | |||
71 | return BDADDR_BREDR; | ||
72 | } | ||
73 | |||
62 | /* ---- L2CAP channels ---- */ | 74 | /* ---- L2CAP channels ---- */ |
63 | 75 | ||
64 | static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, | 76 | static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, |
@@ -1398,6 +1410,8 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn) | |||
1398 | 1410 | ||
1399 | bacpy(&chan->src, &conn->hcon->src); | 1411 | bacpy(&chan->src, &conn->hcon->src); |
1400 | bacpy(&chan->dst, &conn->hcon->dst); | 1412 | bacpy(&chan->dst, &conn->hcon->dst); |
1413 | chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type); | ||
1414 | chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type); | ||
1401 | 1415 | ||
1402 | __l2cap_chan_add(conn, chan); | 1416 | __l2cap_chan_add(conn, chan); |
1403 | 1417 | ||
@@ -1818,6 +1832,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, | |||
1818 | 1832 | ||
1819 | /* Set destination address and psm */ | 1833 | /* Set destination address and psm */ |
1820 | bacpy(&chan->dst, dst); | 1834 | bacpy(&chan->dst, dst); |
1835 | chan->dst_type = dst_type; | ||
1821 | 1836 | ||
1822 | chan->psm = psm; | 1837 | chan->psm = psm; |
1823 | chan->dcid = cid; | 1838 | chan->dcid = cid; |
@@ -1851,6 +1866,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, | |||
1851 | 1866 | ||
1852 | /* Update source addr of the socket */ | 1867 | /* Update source addr of the socket */ |
1853 | bacpy(&chan->src, &hcon->src); | 1868 | bacpy(&chan->src, &hcon->src); |
1869 | chan->src_type = bdaddr_type(hcon, hcon->src_type); | ||
1854 | 1870 | ||
1855 | l2cap_chan_unlock(chan); | 1871 | l2cap_chan_unlock(chan); |
1856 | l2cap_chan_add(conn, chan); | 1872 | l2cap_chan_add(conn, chan); |
@@ -3791,6 +3807,8 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn, | |||
3791 | 3807 | ||
3792 | bacpy(&chan->src, &conn->hcon->src); | 3808 | bacpy(&chan->src, &conn->hcon->src); |
3793 | bacpy(&chan->dst, &conn->hcon->dst); | 3809 | bacpy(&chan->dst, &conn->hcon->dst); |
3810 | chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type); | ||
3811 | chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type); | ||
3794 | chan->psm = psm; | 3812 | chan->psm = psm; |
3795 | chan->dcid = scid; | 3813 | chan->dcid = scid; |
3796 | chan->local_amp_id = amp_id; | 3814 | chan->local_amp_id = amp_id; |