Skip to content

Commit 94a86df

Browse files
holtmannJohan Hedberg
authored andcommitted
Bluetooth: Store RFCOMM address information in its own socket structure
The address information of RFCOMM sockets should be stored in its own socket structure. Trying to generalize them is not helpful since different transports have different address types. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent eea9636 commit 94a86df

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

include/net/bluetooth/rfcomm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ struct rfcomm_conninfo {
300300

301301
struct rfcomm_pinfo {
302302
struct bt_sock bt;
303+
bdaddr_t src;
304+
bdaddr_t dst;
303305
struct rfcomm_dlc *dlc;
304306
u8 channel;
305307
u8 sec_level;

net/bluetooth/rfcomm/sock.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static void rfcomm_sk_state_change(struct rfcomm_dlc *d, int err)
8787
parent->sk_data_ready(parent, 0);
8888
} else {
8989
if (d->state == BT_CONNECTED)
90-
rfcomm_session_getaddr(d->session, &bt_sk(sk)->src, NULL);
90+
rfcomm_session_getaddr(d->session,
91+
&rfcomm_pi(sk)->src, NULL);
9192
sk->sk_state_change(sk);
9293
}
9394

@@ -110,7 +111,7 @@ static struct sock *__rfcomm_get_sock_by_addr(u8 channel, bdaddr_t *src)
110111

111112
sk_for_each(sk, &rfcomm_sk_list.head) {
112113
if (rfcomm_pi(sk)->channel == channel &&
113-
!bacmp(&bt_sk(sk)->src, src))
114+
!bacmp(&rfcomm_pi(sk)->src, src))
114115
break;
115116
}
116117

@@ -132,11 +133,11 @@ static struct sock *rfcomm_get_sock_by_channel(int state, u8 channel, bdaddr_t *
132133

133134
if (rfcomm_pi(sk)->channel == channel) {
134135
/* Exact match. */
135-
if (!bacmp(&bt_sk(sk)->src, src))
136+
if (!bacmp(&rfcomm_pi(sk)->src, src))
136137
break;
137138

138139
/* Closest match */
139-
if (!bacmp(&bt_sk(sk)->src, BDADDR_ANY))
140+
if (!bacmp(&rfcomm_pi(sk)->src, BDADDR_ANY))
140141
sk1 = sk;
141142
}
142143
}
@@ -355,7 +356,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
355356
err = -EADDRINUSE;
356357
} else {
357358
/* Save source address */
358-
bacpy(&bt_sk(sk)->src, &sa->rc_bdaddr);
359+
bacpy(&rfcomm_pi(sk)->src, &sa->rc_bdaddr);
359360
rfcomm_pi(sk)->channel = sa->rc_channel;
360361
sk->sk_state = BT_BOUND;
361362
}
@@ -393,13 +394,14 @@ static int rfcomm_sock_connect(struct socket *sock, struct sockaddr *addr, int a
393394
}
394395

395396
sk->sk_state = BT_CONNECT;
396-
bacpy(&bt_sk(sk)->dst, &sa->rc_bdaddr);
397+
bacpy(&rfcomm_pi(sk)->dst, &sa->rc_bdaddr);
397398
rfcomm_pi(sk)->channel = sa->rc_channel;
398399

399400
d->sec_level = rfcomm_pi(sk)->sec_level;
400401
d->role_switch = rfcomm_pi(sk)->role_switch;
401402

402-
err = rfcomm_dlc_open(d, &bt_sk(sk)->src, &sa->rc_bdaddr, sa->rc_channel);
403+
err = rfcomm_dlc_open(d, &rfcomm_pi(sk)->src, &sa->rc_bdaddr,
404+
sa->rc_channel);
403405
if (!err)
404406
err = bt_sock_wait_state(sk, BT_CONNECTED,
405407
sock_sndtimeo(sk, flags & O_NONBLOCK));
@@ -429,7 +431,7 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
429431
}
430432

431433
if (!rfcomm_pi(sk)->channel) {
432-
bdaddr_t *src = &bt_sk(sk)->src;
434+
bdaddr_t *src = &rfcomm_pi(sk)->src;
433435
u8 channel;
434436

435437
err = -EINVAL;
@@ -530,9 +532,9 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
530532
sa->rc_family = AF_BLUETOOTH;
531533
sa->rc_channel = rfcomm_pi(sk)->channel;
532534
if (peer)
533-
bacpy(&sa->rc_bdaddr, &bt_sk(sk)->dst);
535+
bacpy(&sa->rc_bdaddr, &rfcomm_pi(sk)->dst);
534536
else
535-
bacpy(&sa->rc_bdaddr, &bt_sk(sk)->src);
537+
bacpy(&sa->rc_bdaddr, &rfcomm_pi(sk)->src);
536538

537539
*len = sizeof(struct sockaddr_rc);
538540
return 0;
@@ -951,8 +953,8 @@ int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc *
951953
bt_sock_reclassify_lock(sk, BTPROTO_RFCOMM);
952954

953955
rfcomm_sock_init(sk, parent);
954-
bacpy(&bt_sk(sk)->src, &src);
955-
bacpy(&bt_sk(sk)->dst, &dst);
956+
bacpy(&rfcomm_pi(sk)->src, &src);
957+
bacpy(&rfcomm_pi(sk)->dst, &dst);
956958
rfcomm_pi(sk)->channel = channel;
957959

958960
sk->sk_state = BT_CONFIG;
@@ -979,7 +981,7 @@ static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
979981

980982
sk_for_each(sk, &rfcomm_sk_list.head) {
981983
seq_printf(f, "%pMR %pMR %d %d\n",
982-
&bt_sk(sk)->src, &bt_sk(sk)->dst,
984+
&rfcomm_pi(sk)->src, &rfcomm_pi(sk)->dst,
983985
sk->sk_state, rfcomm_pi(sk)->channel);
984986
}
985987

0 commit comments

Comments
 (0)