aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/cmtp
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /net/bluetooth/cmtp
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'net/bluetooth/cmtp')
-rw-r--r--net/bluetooth/cmtp/Kconfig2
-rw-r--r--net/bluetooth/cmtp/capi.c2
-rw-r--r--net/bluetooth/cmtp/core.c25
-rw-r--r--net/bluetooth/cmtp/sock.c36
4 files changed, 24 insertions, 41 deletions
diff --git a/net/bluetooth/cmtp/Kconfig b/net/bluetooth/cmtp/Kconfig
index 94cbf42ce15..d6b0382f6f3 100644
--- a/net/bluetooth/cmtp/Kconfig
+++ b/net/bluetooth/cmtp/Kconfig
@@ -1,6 +1,6 @@
1config BT_CMTP 1config BT_CMTP
2 tristate "CMTP protocol support" 2 tristate "CMTP protocol support"
3 depends on BT && ISDN_CAPI 3 depends on BT && BT_L2CAP && ISDN_CAPI
4 help 4 help
5 CMTP (CAPI Message Transport Protocol) is a transport layer 5 CMTP (CAPI Message Transport Protocol) is a transport layer
6 for CAPI messages. CMTP is required for the Bluetooth Common 6 for CAPI messages. CMTP is required for the Bluetooth Common
diff --git a/net/bluetooth/cmtp/capi.c b/net/bluetooth/cmtp/capi.c
index a4a9d4b6816..50f0d135eb8 100644
--- a/net/bluetooth/cmtp/capi.c
+++ b/net/bluetooth/cmtp/capi.c
@@ -20,7 +20,7 @@
20 SOFTWARE IS DISCLAIMED. 20 SOFTWARE IS DISCLAIMED.
21*/ 21*/
22 22
23#include <linux/export.h> 23#include <linux/module.h>
24#include <linux/proc_fs.h> 24#include <linux/proc_fs.h>
25#include <linux/seq_file.h> 25#include <linux/seq_file.h>
26#include <linux/types.h> 26#include <linux/types.h>
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index e0a6ebf2baa..521baa4fe83 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -53,24 +53,28 @@ static LIST_HEAD(cmtp_session_list);
53static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr) 53static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr)
54{ 54{
55 struct cmtp_session *session; 55 struct cmtp_session *session;
56 struct list_head *p;
56 57
57 BT_DBG(""); 58 BT_DBG("");
58 59
59 list_for_each_entry(session, &cmtp_session_list, list) 60 list_for_each(p, &cmtp_session_list) {
61 session = list_entry(p, struct cmtp_session, list);
60 if (!bacmp(bdaddr, &session->bdaddr)) 62 if (!bacmp(bdaddr, &session->bdaddr))
61 return session; 63 return session;
62 64 }
63 return NULL; 65 return NULL;
64} 66}
65 67
66static void __cmtp_link_session(struct cmtp_session *session) 68static void __cmtp_link_session(struct cmtp_session *session)
67{ 69{
70 __module_get(THIS_MODULE);
68 list_add(&session->list, &cmtp_session_list); 71 list_add(&session->list, &cmtp_session_list);
69} 72}
70 73
71static void __cmtp_unlink_session(struct cmtp_session *session) 74static void __cmtp_unlink_session(struct cmtp_session *session)
72{ 75{
73 list_del(&session->list); 76 list_del(&session->list);
77 module_put(THIS_MODULE);
74} 78}
75 79
76static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci) 80static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci)
@@ -298,10 +302,7 @@ static int cmtp_session(void *arg)
298 302
299 while ((skb = skb_dequeue(&sk->sk_receive_queue))) { 303 while ((skb = skb_dequeue(&sk->sk_receive_queue))) {
300 skb_orphan(skb); 304 skb_orphan(skb);
301 if (!skb_linearize(skb)) 305 cmtp_recv_frame(session, skb);
302 cmtp_recv_frame(session, skb);
303 else
304 kfree_skb(skb);
305 } 306 }
306 307
307 cmtp_process_transmit(session); 308 cmtp_process_transmit(session);
@@ -323,7 +324,6 @@ static int cmtp_session(void *arg)
323 up_write(&cmtp_session_sem); 324 up_write(&cmtp_session_sem);
324 325
325 kfree(session); 326 kfree(session);
326 module_put_and_exit(0);
327 return 0; 327 return 0;
328} 328}
329 329
@@ -353,7 +353,7 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
353 353
354 BT_DBG("mtu %d", session->mtu); 354 BT_DBG("mtu %d", session->mtu);
355 355
356 sprintf(session->name, "%pMR", &bt_sk(sock->sk)->dst); 356 sprintf(session->name, "%s", batostr(&bt_sk(sock->sk)->dst));
357 357
358 session->sock = sock; 358 session->sock = sock;
359 session->state = BT_CONFIG; 359 session->state = BT_CONFIG;
@@ -373,11 +373,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
373 373
374 __cmtp_link_session(session); 374 __cmtp_link_session(session);
375 375
376 __module_get(THIS_MODULE);
377 session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d", 376 session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d",
378 session->num); 377 session->num);
379 if (IS_ERR(session->task)) { 378 if (IS_ERR(session->task)) {
380 module_put(THIS_MODULE);
381 err = PTR_ERR(session->task); 379 err = PTR_ERR(session->task);
382 goto unlink; 380 goto unlink;
383 } 381 }
@@ -430,16 +428,19 @@ int cmtp_del_connection(struct cmtp_conndel_req *req)
430 428
431int cmtp_get_connlist(struct cmtp_connlist_req *req) 429int cmtp_get_connlist(struct cmtp_connlist_req *req)
432{ 430{
433 struct cmtp_session *session; 431 struct list_head *p;
434 int err = 0, n = 0; 432 int err = 0, n = 0;
435 433
436 BT_DBG(""); 434 BT_DBG("");
437 435
438 down_read(&cmtp_session_sem); 436 down_read(&cmtp_session_sem);
439 437
440 list_for_each_entry(session, &cmtp_session_list, list) { 438 list_for_each(p, &cmtp_session_list) {
439 struct cmtp_session *session;
441 struct cmtp_conninfo ci; 440 struct cmtp_conninfo ci;
442 441
442 session = list_entry(p, struct cmtp_session, list);
443
443 __cmtp_copy_session(session, &ci); 444 __cmtp_copy_session(session, &ci);
444 445
445 if (copy_to_user(req->ci, &ci, sizeof(ci))) { 446 if (copy_to_user(req->ci, &ci, sizeof(ci))) {
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 1c57482112b..3f2dd5c25ae 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -20,7 +20,7 @@
20 SOFTWARE IS DISCLAIMED. 20 SOFTWARE IS DISCLAIMED.
21*/ 21*/
22 22
23#include <linux/export.h> 23#include <linux/module.h>
24 24
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/capability.h> 26#include <linux/capability.h>
@@ -39,13 +39,10 @@
39 39
40#include <linux/isdn/capilli.h> 40#include <linux/isdn/capilli.h>
41 41
42#include <asm/system.h>
42 43
43#include "cmtp.h" 44#include "cmtp.h"
44 45
45static struct bt_sock_list cmtp_sk_list = {
46 .lock = __RW_LOCK_UNLOCKED(cmtp_sk_list.lock)
47};
48
49static int cmtp_sock_release(struct socket *sock) 46static int cmtp_sock_release(struct socket *sock)
50{ 47{
51 struct sock *sk = sock->sk; 48 struct sock *sk = sock->sk;
@@ -55,8 +52,6 @@ static int cmtp_sock_release(struct socket *sock)
55 if (!sk) 52 if (!sk)
56 return 0; 53 return 0;
57 54
58 bt_sock_unlink(&cmtp_sk_list, sk);
59
60 sock_orphan(sk); 55 sock_orphan(sk);
61 sock_put(sk); 56 sock_put(sk);
62 57
@@ -78,7 +73,7 @@ static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
78 switch (cmd) { 73 switch (cmd) {
79 case CMTPCONNADD: 74 case CMTPCONNADD:
80 if (!capable(CAP_NET_ADMIN)) 75 if (!capable(CAP_NET_ADMIN))
81 return -EPERM; 76 return -EACCES;
82 77
83 if (copy_from_user(&ca, argp, sizeof(ca))) 78 if (copy_from_user(&ca, argp, sizeof(ca)))
84 return -EFAULT; 79 return -EFAULT;
@@ -103,7 +98,7 @@ static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
103 98
104 case CMTPCONNDEL: 99 case CMTPCONNDEL:
105 if (!capable(CAP_NET_ADMIN)) 100 if (!capable(CAP_NET_ADMIN))
106 return -EPERM; 101 return -EACCES;
107 102
108 if (copy_from_user(&cd, argp, sizeof(cd))) 103 if (copy_from_user(&cd, argp, sizeof(cd)))
109 return -EFAULT; 104 return -EFAULT;
@@ -142,10 +137,10 @@ static int cmtp_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigne
142{ 137{
143 if (cmd == CMTPGETCONNLIST) { 138 if (cmd == CMTPGETCONNLIST) {
144 struct cmtp_connlist_req cl; 139 struct cmtp_connlist_req cl;
145 u32 uci; 140 uint32_t uci;
146 int err; 141 int err;
147 142
148 if (get_user(cl.cnum, (u32 __user *) arg) || 143 if (get_user(cl.cnum, (uint32_t __user *) arg) ||
149 get_user(uci, (u32 __user *) (arg + 4))) 144 get_user(uci, (u32 __user *) (arg + 4)))
150 return -EFAULT; 145 return -EFAULT;
151 146
@@ -156,7 +151,7 @@ static int cmtp_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigne
156 151
157 err = cmtp_get_connlist(&cl); 152 err = cmtp_get_connlist(&cl);
158 153
159 if (!err && put_user(cl.cnum, (u32 __user *) arg)) 154 if (!err && put_user(cl.cnum, (uint32_t __user *) arg))
160 err = -EFAULT; 155 err = -EFAULT;
161 156
162 return err; 157 return err;
@@ -220,8 +215,6 @@ static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol,
220 sk->sk_protocol = protocol; 215 sk->sk_protocol = protocol;
221 sk->sk_state = BT_OPEN; 216 sk->sk_state = BT_OPEN;
222 217
223 bt_sock_link(&cmtp_sk_list, sk);
224
225 return 0; 218 return 0;
226} 219}
227 220
@@ -240,30 +233,19 @@ int cmtp_init_sockets(void)
240 return err; 233 return err;
241 234
242 err = bt_sock_register(BTPROTO_CMTP, &cmtp_sock_family_ops); 235 err = bt_sock_register(BTPROTO_CMTP, &cmtp_sock_family_ops);
243 if (err < 0) { 236 if (err < 0)
244 BT_ERR("Can't register CMTP socket");
245 goto error;
246 }
247
248 err = bt_procfs_init(THIS_MODULE, &init_net, "cmtp", &cmtp_sk_list, NULL);
249 if (err < 0) {
250 BT_ERR("Failed to create CMTP proc file");
251 bt_sock_unregister(BTPROTO_HIDP);
252 goto error; 237 goto error;
253 }
254
255 BT_INFO("CMTP socket layer initialized");
256 238
257 return 0; 239 return 0;
258 240
259error: 241error:
242 BT_ERR("Can't register CMTP socket");
260 proto_unregister(&cmtp_proto); 243 proto_unregister(&cmtp_proto);
261 return err; 244 return err;
262} 245}
263 246
264void cmtp_cleanup_sockets(void) 247void cmtp_cleanup_sockets(void)
265{ 248{
266 bt_procfs_cleanup(&init_net, "cmtp");
267 if (bt_sock_unregister(BTPROTO_CMTP) < 0) 249 if (bt_sock_unregister(BTPROTO_CMTP) < 0)
268 BT_ERR("Can't unregister CMTP socket"); 250 BT_ERR("Can't unregister CMTP socket");
269 251