Convert files to UTF-8 and some cleanups
[safe/jmp/linux-2.6] / net / irda / irsysctl.c
1 /*********************************************************************
2  *
3  * Filename:      irsysctl.c
4  * Version:       1.0
5  * Description:   Sysctl interface for IrDA
6  * Status:        Experimental.
7  * Author:        Dag Brattli <dagb@cs.uit.no>
8  * Created at:    Sun May 24 22:12:06 1998
9  * Modified at:   Fri Jun  4 02:50:15 1999
10  * Modified by:   Dag Brattli <dagb@cs.uit.no>
11  *
12  *     Copyright (c) 1997, 1999 Dag Brattli, All Rights Reserved.
13  *     Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
14  *
15  *     This program is free software; you can redistribute it and/or
16  *     modify it under the terms of the GNU General Public License as
17  *     published by the Free Software Foundation; either version 2 of
18  *     the License, or (at your option) any later version.
19  *
20  *     Neither Dag Brattli nor University of Tromsø admit liability nor
21  *     provide warranty for any of this software. This material is
22  *     provided "AS-IS" and at no charge.
23  *
24  ********************************************************************/
25
26 #include <linux/mm.h>
27 #include <linux/ctype.h>
28 #include <linux/sysctl.h>
29 #include <linux/init.h>
30
31 #include <net/irda/irda.h>              /* irda_debug */
32 #include <net/irda/irias_object.h>
33
34 extern int  sysctl_discovery;
35 extern int  sysctl_discovery_slots;
36 extern int  sysctl_discovery_timeout;
37 extern int  sysctl_slot_timeout;
38 extern int  sysctl_fast_poll_increase;
39 extern char sysctl_devname[];
40 extern int  sysctl_max_baud_rate;
41 extern int  sysctl_min_tx_turn_time;
42 extern int  sysctl_max_tx_data_size;
43 extern int  sysctl_max_tx_window;
44 extern int  sysctl_max_noreply_time;
45 extern int  sysctl_warn_noreply_time;
46 extern int  sysctl_lap_keepalive_time;
47
48 /* this is needed for the proc_dointvec_minmax - Jean II */
49 static int max_discovery_slots = 16;            /* ??? */
50 static int min_discovery_slots = 1;
51 /* IrLAP 6.13.2 says 25ms to 10+70ms - allow higher since some devices
52  * seems to require it. (from Dag's comment) */
53 static int max_slot_timeout = 160;
54 static int min_slot_timeout = 20;
55 static int max_max_baud_rate = 16000000;        /* See qos.c - IrLAP spec */
56 static int min_max_baud_rate = 2400;
57 static int max_min_tx_turn_time = 10000;        /* See qos.c - IrLAP spec */
58 static int min_min_tx_turn_time;
59 static int max_max_tx_data_size = 2048;         /* See qos.c - IrLAP spec */
60 static int min_max_tx_data_size = 64;
61 static int max_max_tx_window = 7;               /* See qos.c - IrLAP spec */
62 static int min_max_tx_window = 1;
63 static int max_max_noreply_time = 40;           /* See qos.c - IrLAP spec */
64 static int min_max_noreply_time = 3;
65 static int max_warn_noreply_time = 3;           /* 3s == standard */
66 static int min_warn_noreply_time = 1;           /* 1s == min WD_TIMER */
67 static int max_lap_keepalive_time = 10000;      /* 10s */
68 static int min_lap_keepalive_time = 100;        /* 100us */
69 /* For other sysctl, I've no idea of the range. Maybe Dag could help
70  * us on that - Jean II */
71
72 static int do_devname(ctl_table *table, int write, struct file *filp,
73                       void __user *buffer, size_t *lenp, loff_t *ppos)
74 {
75         int ret;
76
77         ret = proc_dostring(table, write, filp, buffer, lenp, ppos);
78         if (ret == 0 && write) {
79                 struct ias_value *val;
80
81                 val = irias_new_string_value(sysctl_devname);
82                 if (val)
83                         irias_object_change_attribute("Device", "DeviceName", val);
84         }
85         return ret;
86 }
87
88 /* One file */
89 static ctl_table irda_table[] = {
90         {
91                 .ctl_name       = NET_IRDA_DISCOVERY,
92                 .procname       = "discovery",
93                 .data           = &sysctl_discovery,
94                 .maxlen         = sizeof(int),
95                 .mode           = 0644,
96                 .proc_handler   = &proc_dointvec
97         },
98         {
99                 .ctl_name       = NET_IRDA_DEVNAME,
100                 .procname       = "devname",
101                 .data           = sysctl_devname,
102                 .maxlen         = 65,
103                 .mode           = 0644,
104                 .proc_handler   = &do_devname,
105                 .strategy       = &sysctl_string
106         },
107 #ifdef CONFIG_IRDA_DEBUG
108         {
109                 .ctl_name       = NET_IRDA_DEBUG,
110                 .procname       = "debug",
111                 .data           = &irda_debug,
112                 .maxlen         = sizeof(int),
113                 .mode           = 0644,
114                 .proc_handler   = &proc_dointvec
115         },
116 #endif
117 #ifdef CONFIG_IRDA_FAST_RR
118         {
119                 .ctl_name       = NET_IRDA_FAST_POLL,
120                 .procname       = "fast_poll_increase",
121                 .data           = &sysctl_fast_poll_increase,
122                 .maxlen         = sizeof(int),
123                 .mode           = 0644,
124                 .proc_handler   = &proc_dointvec
125         },
126 #endif
127         {
128                 .ctl_name       = NET_IRDA_DISCOVERY_SLOTS,
129                 .procname       = "discovery_slots",
130                 .data           = &sysctl_discovery_slots,
131                 .maxlen         = sizeof(int),
132                 .mode           = 0644,
133                 .proc_handler   = &proc_dointvec_minmax,
134                 .strategy       = &sysctl_intvec,
135                 .extra1         = &min_discovery_slots,
136                 .extra2         = &max_discovery_slots
137         },
138         {
139                 .ctl_name       = NET_IRDA_DISCOVERY_TIMEOUT,
140                 .procname       = "discovery_timeout",
141                 .data           = &sysctl_discovery_timeout,
142                 .maxlen         = sizeof(int),
143                 .mode           = 0644,
144                 .proc_handler   = &proc_dointvec
145         },
146         {
147                 .ctl_name       = NET_IRDA_SLOT_TIMEOUT,
148                 .procname       = "slot_timeout",
149                 .data           = &sysctl_slot_timeout,
150                 .maxlen         = sizeof(int),
151                 .mode           = 0644,
152                 .proc_handler   = &proc_dointvec_minmax,
153                 .strategy       = &sysctl_intvec,
154                 .extra1         = &min_slot_timeout,
155                 .extra2         = &max_slot_timeout
156         },
157         {
158                 .ctl_name       = NET_IRDA_MAX_BAUD_RATE,
159                 .procname       = "max_baud_rate",
160                 .data           = &sysctl_max_baud_rate,
161                 .maxlen         = sizeof(int),
162                 .mode           = 0644,
163                 .proc_handler   = &proc_dointvec_minmax,
164                 .strategy       = &sysctl_intvec,
165                 .extra1         = &min_max_baud_rate,
166                 .extra2         = &max_max_baud_rate
167         },
168         {
169                 .ctl_name       = NET_IRDA_MIN_TX_TURN_TIME,
170                 .procname       = "min_tx_turn_time",
171                 .data           = &sysctl_min_tx_turn_time,
172                 .maxlen         = sizeof(int),
173                 .mode           = 0644,
174                 .proc_handler   = &proc_dointvec_minmax,
175                 .strategy       = &sysctl_intvec,
176                 .extra1         = &min_min_tx_turn_time,
177                 .extra2         = &max_min_tx_turn_time
178         },
179         {
180                 .ctl_name       = NET_IRDA_MAX_TX_DATA_SIZE,
181                 .procname       = "max_tx_data_size",
182                 .data           = &sysctl_max_tx_data_size,
183                 .maxlen         = sizeof(int),
184                 .mode           = 0644,
185                 .proc_handler   = &proc_dointvec_minmax,
186                 .strategy       = &sysctl_intvec,
187                 .extra1         = &min_max_tx_data_size,
188                 .extra2         = &max_max_tx_data_size
189         },
190         {
191                 .ctl_name       = NET_IRDA_MAX_TX_WINDOW,
192                 .procname       = "max_tx_window",
193                 .data           = &sysctl_max_tx_window,
194                 .maxlen         = sizeof(int),
195                 .mode           = 0644,
196                 .proc_handler   = &proc_dointvec_minmax,
197                 .strategy       = &sysctl_intvec,
198                 .extra1         = &min_max_tx_window,
199                 .extra2         = &max_max_tx_window
200         },
201         {
202                 .ctl_name       = NET_IRDA_MAX_NOREPLY_TIME,
203                 .procname       = "max_noreply_time",
204                 .data           = &sysctl_max_noreply_time,
205                 .maxlen         = sizeof(int),
206                 .mode           = 0644,
207                 .proc_handler   = &proc_dointvec_minmax,
208                 .strategy       = &sysctl_intvec,
209                 .extra1         = &min_max_noreply_time,
210                 .extra2         = &max_max_noreply_time
211         },
212         {
213                 .ctl_name       = NET_IRDA_WARN_NOREPLY_TIME,
214                 .procname       = "warn_noreply_time",
215                 .data           = &sysctl_warn_noreply_time,
216                 .maxlen         = sizeof(int),
217                 .mode           = 0644,
218                 .proc_handler   = &proc_dointvec_minmax,
219                 .strategy       = &sysctl_intvec,
220                 .extra1         = &min_warn_noreply_time,
221                 .extra2         = &max_warn_noreply_time
222         },
223         {
224                 .ctl_name       = NET_IRDA_LAP_KEEPALIVE_TIME,
225                 .procname       = "lap_keepalive_time",
226                 .data           = &sysctl_lap_keepalive_time,
227                 .maxlen         = sizeof(int),
228                 .mode           = 0644,
229                 .proc_handler   = &proc_dointvec_minmax,
230                 .strategy       = &sysctl_intvec,
231                 .extra1         = &min_lap_keepalive_time,
232                 .extra2         = &max_lap_keepalive_time
233         },
234         { .ctl_name = 0 }
235 };
236
237 /* One directory */
238 static ctl_table irda_net_table[] = {
239         {
240                 .ctl_name       = NET_IRDA,
241                 .procname       = "irda",
242                 .maxlen         = 0,
243                 .mode           = 0555,
244                 .child          = irda_table
245         },
246         { .ctl_name = 0 }
247 };
248
249 /* The parent directory */
250 static ctl_table irda_root_table[] = {
251         {
252                 .ctl_name       = CTL_NET,
253                 .procname       = "net",
254                 .maxlen         = 0,
255                 .mode           = 0555,
256                 .child          = irda_net_table
257         },
258         { .ctl_name = 0 }
259 };
260
261 static struct ctl_table_header *irda_table_header;
262
263 /*
264  * Function irda_sysctl_register (void)
265  *
266  *    Register our sysctl interface
267  *
268  */
269 int __init irda_sysctl_register(void)
270 {
271         irda_table_header = register_sysctl_table(irda_root_table);
272         if (!irda_table_header)
273                 return -ENOMEM;
274
275         return 0;
276 }
277
278 /*
279  * Function irda_sysctl_unregister (void)
280  *
281  *    Unregister our sysctl interface
282  *
283  */
284 void irda_sysctl_unregister(void)
285 {
286         unregister_sysctl_table(irda_table_header);
287 }
288
289
290