diff options
author | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-02-03 23:56:13 -0500 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-02-07 22:43:31 -0500 |
commit | 4e34c50bfe5ba87da1622cc7c6ed10712da255ad (patch) | |
tree | 1efef8e2e5f664c144bfcd4eee2f54863c43a152 /net/bluetooth | |
parent | 99f4808db0c052f3c92a689ec2841618bf2ce14a (diff) |
Bluetooth: move l2cap_sock_connect() to l2cap_sock.c
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 87 | ||||
-rw-r--r-- | net/bluetooth/l2cap_sock.c | 85 |
2 files changed, 86 insertions, 86 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 8e015d971267..97327457b52d 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -848,7 +848,7 @@ static void l2cap_sock_close(struct sock *sk) | |||
848 | l2cap_sock_kill(sk); | 848 | l2cap_sock_kill(sk); |
849 | } | 849 | } |
850 | 850 | ||
851 | static int l2cap_do_connect(struct sock *sk) | 851 | int l2cap_do_connect(struct sock *sk) |
852 | { | 852 | { |
853 | bdaddr_t *src = &bt_sk(sk)->src; | 853 | bdaddr_t *src = &bt_sk(sk)->src; |
854 | bdaddr_t *dst = &bt_sk(sk)->dst; | 854 | bdaddr_t *dst = &bt_sk(sk)->dst; |
@@ -908,91 +908,6 @@ done: | |||
908 | return err; | 908 | return err; |
909 | } | 909 | } |
910 | 910 | ||
911 | int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags) | ||
912 | { | ||
913 | struct sock *sk = sock->sk; | ||
914 | struct sockaddr_l2 la; | ||
915 | int len, err = 0; | ||
916 | |||
917 | BT_DBG("sk %p", sk); | ||
918 | |||
919 | if (!addr || alen < sizeof(addr->sa_family) || | ||
920 | addr->sa_family != AF_BLUETOOTH) | ||
921 | return -EINVAL; | ||
922 | |||
923 | memset(&la, 0, sizeof(la)); | ||
924 | len = min_t(unsigned int, sizeof(la), alen); | ||
925 | memcpy(&la, addr, len); | ||
926 | |||
927 | if (la.l2_cid) | ||
928 | return -EINVAL; | ||
929 | |||
930 | lock_sock(sk); | ||
931 | |||
932 | if ((sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) | ||
933 | && !la.l2_psm) { | ||
934 | err = -EINVAL; | ||
935 | goto done; | ||
936 | } | ||
937 | |||
938 | switch (l2cap_pi(sk)->mode) { | ||
939 | case L2CAP_MODE_BASIC: | ||
940 | break; | ||
941 | case L2CAP_MODE_ERTM: | ||
942 | case L2CAP_MODE_STREAMING: | ||
943 | if (!disable_ertm) | ||
944 | break; | ||
945 | /* fall through */ | ||
946 | default: | ||
947 | err = -ENOTSUPP; | ||
948 | goto done; | ||
949 | } | ||
950 | |||
951 | switch (sk->sk_state) { | ||
952 | case BT_CONNECT: | ||
953 | case BT_CONNECT2: | ||
954 | case BT_CONFIG: | ||
955 | /* Already connecting */ | ||
956 | goto wait; | ||
957 | |||
958 | case BT_CONNECTED: | ||
959 | /* Already connected */ | ||
960 | err = -EISCONN; | ||
961 | goto done; | ||
962 | |||
963 | case BT_OPEN: | ||
964 | case BT_BOUND: | ||
965 | /* Can connect */ | ||
966 | break; | ||
967 | |||
968 | default: | ||
969 | err = -EBADFD; | ||
970 | goto done; | ||
971 | } | ||
972 | |||
973 | /* PSM must be odd and lsb of upper byte must be 0 */ | ||
974 | if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 && | ||
975 | sk->sk_type != SOCK_RAW) { | ||
976 | err = -EINVAL; | ||
977 | goto done; | ||
978 | } | ||
979 | |||
980 | /* Set destination address and psm */ | ||
981 | bacpy(&bt_sk(sk)->dst, &la.l2_bdaddr); | ||
982 | l2cap_pi(sk)->psm = la.l2_psm; | ||
983 | |||
984 | err = l2cap_do_connect(sk); | ||
985 | if (err) | ||
986 | goto done; | ||
987 | |||
988 | wait: | ||
989 | err = bt_sock_wait_state(sk, BT_CONNECTED, | ||
990 | sock_sndtimeo(sk, flags & O_NONBLOCK)); | ||
991 | done: | ||
992 | release_sock(sk); | ||
993 | return err; | ||
994 | } | ||
995 | |||
996 | static int __l2cap_wait_ack(struct sock *sk) | 911 | static int __l2cap_wait_ack(struct sock *sk) |
997 | { | 912 | { |
998 | DECLARE_WAITQUEUE(wait, current); | 913 | DECLARE_WAITQUEUE(wait, current); |
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index b7d5ae9c6bdf..e2f14f1783f6 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c | |||
@@ -139,6 +139,91 @@ done: | |||
139 | return err; | 139 | return err; |
140 | } | 140 | } |
141 | 141 | ||
142 | static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags) | ||
143 | { | ||
144 | struct sock *sk = sock->sk; | ||
145 | struct sockaddr_l2 la; | ||
146 | int len, err = 0; | ||
147 | |||
148 | BT_DBG("sk %p", sk); | ||
149 | |||
150 | if (!addr || alen < sizeof(addr->sa_family) || | ||
151 | addr->sa_family != AF_BLUETOOTH) | ||
152 | return -EINVAL; | ||
153 | |||
154 | memset(&la, 0, sizeof(la)); | ||
155 | len = min_t(unsigned int, sizeof(la), alen); | ||
156 | memcpy(&la, addr, len); | ||
157 | |||
158 | if (la.l2_cid) | ||
159 | return -EINVAL; | ||
160 | |||
161 | lock_sock(sk); | ||
162 | |||
163 | if ((sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) | ||
164 | && !la.l2_psm) { | ||
165 | err = -EINVAL; | ||
166 | goto done; | ||
167 | } | ||
168 | |||
169 | switch (l2cap_pi(sk)->mode) { | ||
170 | case L2CAP_MODE_BASIC: | ||
171 | break; | ||
172 | case L2CAP_MODE_ERTM: | ||
173 | case L2CAP_MODE_STREAMING: | ||
174 | if (!disable_ertm) | ||
175 | break; | ||
176 | /* fall through */ | ||
177 | default: | ||
178 | err = -ENOTSUPP; | ||
179 | goto done; | ||
180 | } | ||
181 | |||
182 | switch (sk->sk_state) { | ||
183 | case BT_CONNECT: | ||
184 | case BT_CONNECT2: | ||
185 | case BT_CONFIG: | ||
186 | /* Already connecting */ | ||
187 | goto wait; | ||
188 | |||
189 | case BT_CONNECTED: | ||
190 | /* Already connected */ | ||
191 | err = -EISCONN; | ||
192 | goto done; | ||
193 | |||
194 | case BT_OPEN: | ||
195 | case BT_BOUND: | ||
196 | /* Can connect */ | ||
197 | break; | ||
198 | |||
199 | default: | ||
200 | err = -EBADFD; | ||
201 | goto done; | ||
202 | } | ||
203 | |||
204 | /* PSM must be odd and lsb of upper byte must be 0 */ | ||
205 | if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 && | ||
206 | sk->sk_type != SOCK_RAW) { | ||
207 | err = -EINVAL; | ||
208 | goto done; | ||
209 | } | ||
210 | |||
211 | /* Set destination address and psm */ | ||
212 | bacpy(&bt_sk(sk)->dst, &la.l2_bdaddr); | ||
213 | l2cap_pi(sk)->psm = la.l2_psm; | ||
214 | |||
215 | err = l2cap_do_connect(sk); | ||
216 | if (err) | ||
217 | goto done; | ||
218 | |||
219 | wait: | ||
220 | err = bt_sock_wait_state(sk, BT_CONNECTED, | ||
221 | sock_sndtimeo(sk, flags & O_NONBLOCK)); | ||
222 | done: | ||
223 | release_sock(sk); | ||
224 | return err; | ||
225 | } | ||
226 | |||
142 | static int l2cap_sock_listen(struct socket *sock, int backlog) | 227 | static int l2cap_sock_listen(struct socket *sock, int backlog) |
143 | { | 228 | { |
144 | struct sock *sk = sock->sk; | 229 | struct sock *sk = sock->sk; |