blob: d6a59651767a89ca8a2a485665c0040a7ff0c641 [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;
Andi Kleen95660422011-09-16 09:09:50 +000043extern unsigned int sysctl_min_tx_turn_time;
44extern unsigned int sysctl_max_tx_data_size;
45extern unsigned int sysctl_max_tx_window;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046extern 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
Joe Perchesfe2c6332013-06-11 23:04:25 -070076static int do_devname(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 void __user *buffer, size_t *lenp, loff_t *ppos)
78{
79 int ret;
80
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070081 ret = proc_dostring(table, write, buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 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
Joe Perchesfe2c6332013-06-11 23:04:25 -070093static int do_discovery(struct ctl_table *table, int write,
Ross Burton91cde6f2008-01-22 18:27:53 -080094 void __user *buffer, size_t *lenp, loff_t *ppos)
95{
96 int ret;
97
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070098 ret = proc_dointvec(table, write, buffer, lenp, ppos);
Ross Burton91cde6f2008-01-22 18:27:53 -080099 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 */
Joe Perchesfe2c6332013-06-11 23:04:25 -0700114static struct ctl_table irda_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .procname = "discovery",
117 .data = &sysctl_discovery,
118 .maxlen = sizeof(int),
119 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800120 .proc_handler = do_discovery,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 },
122 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .procname = "devname",
124 .data = sysctl_devname,
125 .maxlen = 65,
126 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800127 .proc_handler = do_devname,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 },
129#ifdef CONFIG_IRDA_DEBUG
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900130 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 .procname = "debug",
132 .data = &irda_debug,
133 .maxlen = sizeof(int),
134 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800135 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 },
137#endif
138#ifdef CONFIG_IRDA_FAST_RR
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900139 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 .procname = "fast_poll_increase",
141 .data = &sysctl_fast_poll_increase,
142 .maxlen = sizeof(int),
143 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800144 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 },
146#endif
147 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 .procname = "discovery_slots",
149 .data = &sysctl_discovery_slots,
150 .maxlen = sizeof(int),
151 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800152 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 .extra1 = &min_discovery_slots,
154 .extra2 = &max_discovery_slots
155 },
156 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 .procname = "discovery_timeout",
158 .data = &sysctl_discovery_timeout,
159 .maxlen = sizeof(int),
160 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800161 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 },
163 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 .procname = "slot_timeout",
165 .data = &sysctl_slot_timeout,
166 .maxlen = sizeof(int),
167 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800168 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 .extra1 = &min_slot_timeout,
170 .extra2 = &max_slot_timeout
171 },
172 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 .procname = "max_baud_rate",
174 .data = &sysctl_max_baud_rate,
175 .maxlen = sizeof(int),
176 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800177 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 .extra1 = &min_max_baud_rate,
179 .extra2 = &max_max_baud_rate
180 },
181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 .procname = "min_tx_turn_time",
183 .data = &sysctl_min_tx_turn_time,
184 .maxlen = sizeof(int),
185 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800186 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 .extra1 = &min_min_tx_turn_time,
188 .extra2 = &max_min_tx_turn_time
189 },
190 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 .procname = "max_tx_data_size",
192 .data = &sysctl_max_tx_data_size,
193 .maxlen = sizeof(int),
194 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800195 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 .extra1 = &min_max_tx_data_size,
197 .extra2 = &max_max_tx_data_size
198 },
199 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 .procname = "max_tx_window",
201 .data = &sysctl_max_tx_window,
202 .maxlen = sizeof(int),
203 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800204 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 .extra1 = &min_max_tx_window,
206 .extra2 = &max_max_tx_window
207 },
208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 .procname = "max_noreply_time",
210 .data = &sysctl_max_noreply_time,
211 .maxlen = sizeof(int),
212 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800213 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .extra1 = &min_max_noreply_time,
215 .extra2 = &max_max_noreply_time
216 },
217 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 .procname = "warn_noreply_time",
219 .data = &sysctl_warn_noreply_time,
220 .maxlen = sizeof(int),
221 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800222 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 .extra1 = &min_warn_noreply_time,
224 .extra2 = &max_warn_noreply_time
225 },
226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 .procname = "lap_keepalive_time",
228 .data = &sysctl_lap_keepalive_time,
229 .maxlen = sizeof(int),
230 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800231 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .extra1 = &min_lap_keepalive_time,
233 .extra2 = &max_lap_keepalive_time
234 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800235 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236};
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238static struct ctl_table_header *irda_table_header;
239
240/*
241 * Function irda_sysctl_register (void)
242 *
243 * Register our sysctl interface
244 *
245 */
246int __init irda_sysctl_register(void)
247{
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000248 irda_table_header = register_net_sysctl(&init_net, "net/irda", irda_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (!irda_table_header)
250 return -ENOMEM;
251
252 return 0;
253}
254
255/*
256 * Function irda_sysctl_unregister (void)
257 *
258 * Unregister our sysctl interface
259 *
260 */
Samuel Ortiz75a69ac2007-07-18 02:16:30 -0700261void irda_sysctl_unregister(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000263 unregister_net_sysctl_table(irda_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
266
267