File: /usr/src/linux/net/bluetooth/l2cap_proc.c

1     /* 
2        BlueZ - Bluetooth protocol stack for Linux
3        Copyright (C) 2000-2001 Qualcomm Incorporated
4     
5        Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6     
7        This program is free software; you can redistribute it and/or modify
8        it under the terms of the GNU General Public License version 2 as
9        published by the Free Software Foundation;
10     
11        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12        OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14        IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15        CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 
16        WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
17        ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
18        OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19     
20        ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 
21        COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 
22        SOFTWARE IS DISCLAIMED.
23     */
24     
25     /*
26      * BlueZ L2CAP proc fs support.
27      *
28      * $Id: l2cap_proc.c,v 1.2 2001/06/02 01:40:09 maxk Exp $
29      */
30     
31     #include <linux/config.h>
32     #include <linux/module.h>
33     
34     #include <linux/types.h>
35     #include <linux/errno.h>
36     #include <linux/kernel.h>
37     #include <linux/major.h>
38     #include <linux/sched.h>
39     #include <linux/slab.h>
40     #include <linux/poll.h>
41     #include <linux/fcntl.h>
42     #include <linux/init.h>
43     #include <linux/skbuff.h>
44     #include <linux/interrupt.h>
45     #include <linux/socket.h>
46     #include <linux/skbuff.h>
47     #include <linux/proc_fs.h>
48     #include <linux/list.h>
49     #include <net/sock.h>
50     
51     #include <asm/system.h>
52     #include <asm/uaccess.h>
53     
54     #include <net/bluetooth/bluez.h>
55     #include <net/bluetooth/bluetooth.h>
56     #include <net/bluetooth/hci_core.h>
57     #include <net/bluetooth/l2cap_core.h>
58     
59     #ifndef L2CAP_DEBUG
60     #undef  DBG
61     #define DBG( A... )
62     #endif
63     
64     /* ----- PROC fs support ----- */
65     static int l2cap_conn_dump(char *buf, struct l2cap_iff *iff)
66     {
67     	struct list_head *p;
68     	char *ptr = buf;
69     
70     	list_for_each(p, &iff->conn_list) {
71     		struct l2cap_conn *c;
72     
73     		c = list_entry(p, struct l2cap_conn, list);
74     		ptr += sprintf(ptr, "    %p %d %p %p %s %s\n", 
75     				c, c->state, c->iff, c->hconn, batostr(&c->src), batostr(&c->dst));
76     	}
77     
78     	return ptr - buf;
79     }
80     
81     static int l2cap_iff_dump(char *buf)
82     {
83     	struct list_head *p;
84     	char *ptr = buf;
85     
86     	ptr += sprintf(ptr, "Interfaces:\n");
87     
88     	write_lock(&l2cap_rt_lock);
89     
90     	list_for_each(p, &l2cap_iff_list) {
91     		struct l2cap_iff *iff;
92     
93     		iff = list_entry(p, struct l2cap_iff, list);
94     
95     		ptr += sprintf(ptr, "  %s %p %p\n", iff->hdev->name, iff, iff->hdev);
96     		
97     		l2cap_iff_lock(iff);
98     		ptr += l2cap_conn_dump(ptr, iff);
99     		l2cap_iff_unlock(iff);
100     	}
101     
102     	write_unlock(&l2cap_rt_lock);
103     
104     	ptr += sprintf(ptr, "\n");
105     
106     	return ptr - buf;
107     }
108     
109     static int l2cap_sock_dump(char *buf, struct bluez_sock_list *list)
110     {
111     	struct l2cap_pinfo *pi;
112     	struct sock *sk;
113     	char *ptr = buf;
114     
115     	ptr += sprintf(ptr, "Sockets:\n");
116     
117     	write_lock(&list->lock);
118     
119     	for (sk = list->head; sk; sk = sk->next) {
120     		pi = l2cap_pi(sk);
121     		ptr += sprintf(ptr, "  %p %d %p %d %s %s 0x%4.4x 0x%4.4x %d %d\n", sk, sk->state, pi->conn, pi->psm,
122     		               batostr(&pi->src), batostr(&pi->dst), pi->scid, pi->dcid, pi->imtu, pi->omtu );
123     	}
124     
125     	write_unlock(&list->lock);
126     
127     	ptr += sprintf(ptr, "\n");
128     
129     	return ptr - buf;
130     }
131     
132     static int l2cap_read_proc(char *buf, char **start, off_t offset, int count, int *eof, void *priv)
133     {
134     	char *ptr = buf;
135     	int len;
136     
137     	DBG("count %d, offset %ld", count, offset);
138     
139     	ptr += l2cap_iff_dump(ptr);
140     	ptr += l2cap_sock_dump(ptr, &l2cap_sk_list);
141     	len  = ptr - buf;
142     
143     	if (len <= count + offset)
144     		*eof = 1;
145     
146     	*start = buf + offset;
147     	len -= offset;
148     
149     	if (len > count)
150     		len = count;
151     	if (len < 0)
152     		len = 0;
153     
154     	return len;
155     }
156     
157     void l2cap_register_proc(void)
158     {
159     	create_proc_read_entry("bluetooth/l2cap", 0, 0, l2cap_read_proc, NULL);
160     }
161     
162     void l2cap_unregister_proc(void)
163     {
164     	remove_proc_entry("bluetooth/l2cap", NULL);
165     }
166