blob: 57f8817c3979029a38a680d1ea65d948766d2ef9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*********************************************************************
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09002 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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>
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Copyright (c) 1997, 1999 Dag Brattli, All Rights Reserved.
13 * Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090014 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * the License, or (at your option) any later version.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090019 *
Jan Engelhardt96de0e22007-10-19 23:21:04 +020020 * Neither Dag Brattli nor University of Tromsø admit liability nor
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090021 * provide warranty for any of this software. This material is
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * provided "AS-IS" and at no charge.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090023 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 ********************************************************************/
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#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 */
Ross Burton91cde6f2008-01-22 18:27:53 -080032#include <net/irda/irlmp.h>
33#include <net/irda/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <net/irda/irias_object.h>
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036extern int sysctl_discovery;
37extern int sysctl_discovery_slots;
38extern int sysctl_discovery_timeout;
39extern int sysctl_slot_timeout;
40extern int sysctl_fast_poll_increase;
41extern char sysctl_devname[];
42extern int sysctl_max_baud_rate;
43extern int sysctl_min_tx_turn_time;
44extern int sysctl_max_tx_data_size;
45extern int sysctl_max_tx_window;
46extern int sysctl_max_noreply_time;
47extern int sysctl_warn_noreply_time;
48extern int sysctl_lap_keepalive_time;
49
Ross Burton91cde6f2008-01-22 18:27:53 -080050extern struct irlmp_cb *irlmp;
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* this is needed for the proc_dointvec_minmax - Jean II */
53static int max_discovery_slots = 16; /* ??? */
54static int min_discovery_slots = 1;
55/* IrLAP 6.13.2 says 25ms to 10+70ms - allow higher since some devices
56 * seems to require it. (from Dag's comment) */
57static int max_slot_timeout = 160;
58static int min_slot_timeout = 20;
59static int max_max_baud_rate = 16000000; /* See qos.c - IrLAP spec */
60static int min_max_baud_rate = 2400;
61static int max_min_tx_turn_time = 10000; /* See qos.c - IrLAP spec */
62static int min_min_tx_turn_time;
63static int max_max_tx_data_size = 2048; /* See qos.c - IrLAP spec */
64static int min_max_tx_data_size = 64;
65static int max_max_tx_window = 7; /* See qos.c - IrLAP spec */
66static int min_max_tx_window = 1;
67static int max_max_noreply_time = 40; /* See qos.c - IrLAP spec */
68static int min_max_noreply_time = 3;
69static int max_warn_noreply_time = 3; /* 3s == standard */
70static int min_warn_noreply_time = 1; /* 1s == min WD_TIMER */
71static int max_lap_keepalive_time = 10000; /* 10s */
72static int min_lap_keepalive_time = 100; /* 100us */
73/* For other sysctl, I've no idea of the range. Maybe Dag could help
74 * us on that - Jean II */
75
76static int do_devname(ctl_table *table, int write, struct file *filp,
77 void __user *buffer, size_t *lenp, loff_t *ppos)
78{
79 int ret;
80
81 ret = proc_dostring(table, write, filp, buffer, lenp, ppos);
82 if (ret == 0 && write) {
83 struct ias_value *val;
84
85 val = irias_new_string_value(sysctl_devname);
86 if (val)
87 irias_object_change_attribute("Device", "DeviceName", val);
88 }
89 return ret;
90}
91
Ross Burton91cde6f2008-01-22 18:27:53 -080092
93static int do_discovery(ctl_table *table, int write, struct file *filp,
94 void __user *buffer, size_t *lenp, loff_t *ppos)
95{
96 int ret;
97
98 ret = proc_dointvec(table, write, filp, buffer, lenp, ppos);
99 if (ret)
100 return ret;
101
102 if (irlmp == NULL)
103 return -ENODEV;
104
105 if (sysctl_discovery)
106 irlmp_start_discovery_timer(irlmp, sysctl_discovery_timeout*HZ);
107 else
108 del_timer_sync(&irlmp->discovery_timer);
109
110 return ret;
111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* One file */
114static ctl_table irda_table[] = {
115 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700116 .ctl_name = NET_IRDA_DISCOVERY,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .procname = "discovery",
118 .data = &sysctl_discovery,
119 .maxlen = sizeof(int),
120 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800121 .proc_handler = do_discovery,
122 .strategy = sysctl_intvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 },
124 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700125 .ctl_name = NET_IRDA_DEVNAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .procname = "devname",
127 .data = sysctl_devname,
128 .maxlen = 65,
129 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800130 .proc_handler = do_devname,
131 .strategy = sysctl_string
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 },
133#ifdef CONFIG_IRDA_DEBUG
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900134 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700135 .ctl_name = NET_IRDA_DEBUG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .procname = "debug",
137 .data = &irda_debug,
138 .maxlen = sizeof(int),
139 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800140 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 },
142#endif
143#ifdef CONFIG_IRDA_FAST_RR
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900144 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700145 .ctl_name = NET_IRDA_FAST_POLL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 .procname = "fast_poll_increase",
147 .data = &sysctl_fast_poll_increase,
148 .maxlen = sizeof(int),
149 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800150 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 },
152#endif
153 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700154 .ctl_name = NET_IRDA_DISCOVERY_SLOTS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 .procname = "discovery_slots",
156 .data = &sysctl_discovery_slots,
157 .maxlen = sizeof(int),
158 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800159 .proc_handler = proc_dointvec_minmax,
160 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 .extra1 = &min_discovery_slots,
162 .extra2 = &max_discovery_slots
163 },
164 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700165 .ctl_name = NET_IRDA_DISCOVERY_TIMEOUT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 .procname = "discovery_timeout",
167 .data = &sysctl_discovery_timeout,
168 .maxlen = sizeof(int),
169 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800170 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 },
172 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700173 .ctl_name = NET_IRDA_SLOT_TIMEOUT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 .procname = "slot_timeout",
175 .data = &sysctl_slot_timeout,
176 .maxlen = sizeof(int),
177 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800178 .proc_handler = proc_dointvec_minmax,
179 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 .extra1 = &min_slot_timeout,
181 .extra2 = &max_slot_timeout
182 },
183 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700184 .ctl_name = NET_IRDA_MAX_BAUD_RATE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 .procname = "max_baud_rate",
186 .data = &sysctl_max_baud_rate,
187 .maxlen = sizeof(int),
188 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800189 .proc_handler = proc_dointvec_minmax,
190 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 .extra1 = &min_max_baud_rate,
192 .extra2 = &max_max_baud_rate
193 },
194 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700195 .ctl_name = NET_IRDA_MIN_TX_TURN_TIME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 .procname = "min_tx_turn_time",
197 .data = &sysctl_min_tx_turn_time,
198 .maxlen = sizeof(int),
199 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800200 .proc_handler = proc_dointvec_minmax,
201 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .extra1 = &min_min_tx_turn_time,
203 .extra2 = &max_min_tx_turn_time
204 },
205 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700206 .ctl_name = NET_IRDA_MAX_TX_DATA_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 .procname = "max_tx_data_size",
208 .data = &sysctl_max_tx_data_size,
209 .maxlen = sizeof(int),
210 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800211 .proc_handler = proc_dointvec_minmax,
212 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 .extra1 = &min_max_tx_data_size,
214 .extra2 = &max_max_tx_data_size
215 },
216 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700217 .ctl_name = NET_IRDA_MAX_TX_WINDOW,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 .procname = "max_tx_window",
219 .data = &sysctl_max_tx_window,
220 .maxlen = sizeof(int),
221 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800222 .proc_handler = proc_dointvec_minmax,
223 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .extra1 = &min_max_tx_window,
225 .extra2 = &max_max_tx_window
226 },
227 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700228 .ctl_name = NET_IRDA_MAX_NOREPLY_TIME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .procname = "max_noreply_time",
230 .data = &sysctl_max_noreply_time,
231 .maxlen = sizeof(int),
232 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800233 .proc_handler = proc_dointvec_minmax,
234 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .extra1 = &min_max_noreply_time,
236 .extra2 = &max_max_noreply_time
237 },
238 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700239 .ctl_name = NET_IRDA_WARN_NOREPLY_TIME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .procname = "warn_noreply_time",
241 .data = &sysctl_warn_noreply_time,
242 .maxlen = sizeof(int),
243 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800244 .proc_handler = proc_dointvec_minmax,
245 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .extra1 = &min_warn_noreply_time,
247 .extra2 = &max_warn_noreply_time
248 },
249 {
Eric W. Biedermanf429cd32007-10-18 03:05:33 -0700250 .ctl_name = NET_IRDA_LAP_KEEPALIVE_TIME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 .procname = "lap_keepalive_time",
252 .data = &sysctl_lap_keepalive_time,
253 .maxlen = sizeof(int),
254 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800255 .proc_handler = proc_dointvec_minmax,
256 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 .extra1 = &min_lap_keepalive_time,
258 .extra2 = &max_lap_keepalive_time
259 },
260 { .ctl_name = 0 }
261};
262
Pavel Emelyanovb5ccd792008-01-09 00:30:05 -0800263static struct ctl_path irda_path[] = {
264 { .procname = "net", .ctl_name = CTL_NET, },
265 { .procname = "irda", .ctl_name = NET_IRDA, },
266 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267};
268
269static struct ctl_table_header *irda_table_header;
270
271/*
272 * Function irda_sysctl_register (void)
273 *
274 * Register our sysctl interface
275 *
276 */
277int __init irda_sysctl_register(void)
278{
Pavel Emelyanovb5ccd792008-01-09 00:30:05 -0800279 irda_table_header = register_sysctl_paths(irda_path, irda_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (!irda_table_header)
281 return -ENOMEM;
282
283 return 0;
284}
285
286/*
287 * Function irda_sysctl_unregister (void)
288 *
289 * Unregister our sysctl interface
290 *
291 */
Samuel Ortiz75a69ac2007-07-18 02:16:30 -0700292void irda_sysctl_unregister(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
294 unregister_sysctl_table(irda_table_header);
295}
296
297
298