3838#include <linux/interrupt.h>
3939#include <linux/socket.h>
4040#include <linux/skbuff.h>
41- #include <linux/proc_fs.h>
42- #include <linux/seq_file.h>
4341#include <linux/list.h>
42+ #include <linux/device.h>
4443#include <net/sock.h>
4544
4645#include <asm/system.h>
5655#define BT_DBG (D ...)
5756#endif
5857
59- #define VERSION "2.7 "
58+ #define VERSION "2.8 "
6059
6160static struct proto_ops l2cap_sock_ops ;
6261
@@ -2137,94 +2136,29 @@ static int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 fl
21372136 return 0 ;
21382137}
21392138
2140- /* ---- Proc fs support ---- */
2141- #ifdef CONFIG_PROC_FS
2142- static void * l2cap_seq_start (struct seq_file * seq , loff_t * pos )
2139+ static ssize_t l2cap_sysfs_show (struct class * dev , char * buf )
21432140{
21442141 struct sock * sk ;
21452142 struct hlist_node * node ;
2146- loff_t l = * pos ;
2143+ char * str = buf ;
21472144
21482145 read_lock_bh (& l2cap_sk_list .lock );
21492146
2150- sk_for_each (sk , node , & l2cap_sk_list .head )
2151- if (!l -- )
2152- goto found ;
2153- sk = NULL ;
2154- found :
2155- return sk ;
2156- }
2147+ sk_for_each (sk , node , & l2cap_sk_list .head ) {
2148+ struct l2cap_pinfo * pi = l2cap_pi (sk );
21572149
2158- static void * l2cap_seq_next ( struct seq_file * seq , void * e , loff_t * pos )
2159- {
2160- ( * pos ) ++ ;
2161- return sk_next ( e );
2162- }
2150+ str += sprintf ( str , "%s %s %d %d 0x%4.4x 0x%4.4x %d %d 0x%x\n" ,
2151+ batostr ( & bt_sk ( sk ) -> src ), batostr ( & bt_sk ( sk ) -> dst ),
2152+ sk -> sk_state , pi -> psm , pi -> scid , pi -> dcid , pi -> imtu ,
2153+ pi -> omtu , pi -> link_mode );
2154+ }
21632155
2164- static void l2cap_seq_stop (struct seq_file * seq , void * e )
2165- {
21662156 read_unlock_bh (& l2cap_sk_list .lock );
2167- }
21682157
2169- static int l2cap_seq_show (struct seq_file * seq , void * e )
2170- {
2171- struct sock * sk = e ;
2172- struct l2cap_pinfo * pi = l2cap_pi (sk );
2173-
2174- seq_printf (seq , "%s %s %d %d 0x%4.4x 0x%4.4x %d %d 0x%x\n" ,
2175- batostr (& bt_sk (sk )-> src ), batostr (& bt_sk (sk )-> dst ),
2176- sk -> sk_state , pi -> psm , pi -> scid , pi -> dcid , pi -> imtu ,
2177- pi -> omtu , pi -> link_mode );
2178- return 0 ;
2158+ return (str - buf );
21792159}
21802160
2181- static struct seq_operations l2cap_seq_ops = {
2182- .start = l2cap_seq_start ,
2183- .next = l2cap_seq_next ,
2184- .stop = l2cap_seq_stop ,
2185- .show = l2cap_seq_show
2186- };
2187-
2188- static int l2cap_seq_open (struct inode * inode , struct file * file )
2189- {
2190- return seq_open (file , & l2cap_seq_ops );
2191- }
2192-
2193- static struct file_operations l2cap_seq_fops = {
2194- .owner = THIS_MODULE ,
2195- .open = l2cap_seq_open ,
2196- .read = seq_read ,
2197- .llseek = seq_lseek ,
2198- .release = seq_release ,
2199- };
2200-
2201- static int __init l2cap_proc_init (void )
2202- {
2203- struct proc_dir_entry * p = create_proc_entry ("l2cap" , S_IRUGO , proc_bt );
2204- if (!p )
2205- return - ENOMEM ;
2206- p -> owner = THIS_MODULE ;
2207- p -> proc_fops = & l2cap_seq_fops ;
2208- return 0 ;
2209- }
2210-
2211- static void __exit l2cap_proc_cleanup (void )
2212- {
2213- remove_proc_entry ("l2cap" , proc_bt );
2214- }
2215-
2216- #else /* CONFIG_PROC_FS */
2217-
2218- static int __init l2cap_proc_init (void )
2219- {
2220- return 0 ;
2221- }
2222-
2223- static void __exit l2cap_proc_cleanup (void )
2224- {
2225- return ;
2226- }
2227- #endif /* CONFIG_PROC_FS */
2161+ static CLASS_ATTR (l2cap , S_IRUGO , l2cap_sysfs_show , NULL) ;
22282162
22292163static struct proto_ops l2cap_sock_ops = {
22302164 .family = PF_BLUETOOTH ,
@@ -2266,7 +2200,7 @@ static struct hci_proto l2cap_hci_proto = {
22662200static int __init l2cap_init (void )
22672201{
22682202 int err ;
2269-
2203+
22702204 err = proto_register (& l2cap_proto , 0 );
22712205 if (err < 0 )
22722206 return err ;
@@ -2284,7 +2218,7 @@ static int __init l2cap_init(void)
22842218 goto error ;
22852219 }
22862220
2287- l2cap_proc_init ( );
2221+ class_create_file ( & bt_class , & class_attr_l2cap );
22882222
22892223 BT_INFO ("L2CAP ver %s" , VERSION );
22902224 BT_INFO ("L2CAP socket layer initialized" );
@@ -2298,7 +2232,7 @@ static int __init l2cap_init(void)
22982232
22992233static void __exit l2cap_exit (void )
23002234{
2301- l2cap_proc_cleanup ( );
2235+ class_remove_file ( & bt_class , & class_attr_l2cap );
23022236
23032237 if (bt_sock_unregister (BTPROTO_L2CAP ) < 0 )
23042238 BT_ERR ("L2CAP socket unregistration failed" );
0 commit comments