irsysctl.c 8.1 KB
Newer Older
L
Linus Torvalds 已提交
1
/*********************************************************************
2
 *
L
Linus Torvalds 已提交
3 4 5 6 7 8 9 10
 * Filename:      irsysctl.c
 * Version:       1.0
 * Description:   Sysctl interface for IrDA
 * Status:        Experimental.
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Created at:    Sun May 24 22:12:06 1998
 * Modified at:   Fri Jun  4 02:50:15 1999
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
11
 *
L
Linus Torvalds 已提交
12 13
 *     Copyright (c) 1997, 1999 Dag Brattli, All Rights Reserved.
 *     Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
14 15 16 17
 *
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of
L
Linus Torvalds 已提交
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
L
Linus Torvalds 已提交
22
 *     provided "AS-IS" and at no charge.
23
 *
L
Linus Torvalds 已提交
24 25 26 27 28 29 30 31
 ********************************************************************/

#include <linux/mm.h>
#include <linux/ctype.h>
#include <linux/sysctl.h>
#include <linux/init.h>

#include <net/irda/irda.h>		/* irda_debug */
32 33
#include <net/irda/irlmp.h>
#include <net/irda/timer.h>
L
Linus Torvalds 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#include <net/irda/irias_object.h>

extern int  sysctl_discovery;
extern int  sysctl_discovery_slots;
extern int  sysctl_discovery_timeout;
extern int  sysctl_slot_timeout;
extern int  sysctl_fast_poll_increase;
extern char sysctl_devname[];
extern int  sysctl_max_baud_rate;
extern int  sysctl_min_tx_turn_time;
extern int  sysctl_max_tx_data_size;
extern int  sysctl_max_tx_window;
extern int  sysctl_max_noreply_time;
extern int  sysctl_warn_noreply_time;
extern int  sysctl_lap_keepalive_time;

50 51
extern struct irlmp_cb *irlmp;

L
Linus Torvalds 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
/* this is needed for the proc_dointvec_minmax - Jean II */
static int max_discovery_slots = 16;		/* ??? */
static int min_discovery_slots = 1;
/* IrLAP 6.13.2 says 25ms to 10+70ms - allow higher since some devices
 * seems to require it. (from Dag's comment) */
static int max_slot_timeout = 160;
static int min_slot_timeout = 20;
static int max_max_baud_rate = 16000000;	/* See qos.c - IrLAP spec */
static int min_max_baud_rate = 2400;
static int max_min_tx_turn_time = 10000;	/* See qos.c - IrLAP spec */
static int min_min_tx_turn_time;
static int max_max_tx_data_size = 2048;		/* See qos.c - IrLAP spec */
static int min_max_tx_data_size = 64;
static int max_max_tx_window = 7;		/* See qos.c - IrLAP spec */
static int min_max_tx_window = 1;
static int max_max_noreply_time = 40;		/* See qos.c - IrLAP spec */
static int min_max_noreply_time = 3;
static int max_warn_noreply_time = 3;		/* 3s == standard */
static int min_warn_noreply_time = 1;		/* 1s == min WD_TIMER */
static int max_lap_keepalive_time = 10000;	/* 10s */
static int min_lap_keepalive_time = 100;	/* 100us */
/* For other sysctl, I've no idea of the range. Maybe Dag could help
 * us on that - Jean II */

static int do_devname(ctl_table *table, int write, struct file *filp,
		      void __user *buffer, size_t *lenp, loff_t *ppos)
{
	int ret;

	ret = proc_dostring(table, write, filp, buffer, lenp, ppos);
	if (ret == 0 && write) {
		struct ias_value *val;

		val = irias_new_string_value(sysctl_devname);
		if (val)
			irias_object_change_attribute("Device", "DeviceName", val);
	}
	return ret;
}

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

static int do_discovery(ctl_table *table, int write, struct file *filp,
                    void __user *buffer, size_t *lenp, loff_t *ppos)
{
       int ret;

       ret = proc_dointvec(table, write, filp, buffer, lenp, ppos);
       if (ret)
	       return ret;

       if (irlmp == NULL)
	       return -ENODEV;

       if (sysctl_discovery)
	       irlmp_start_discovery_timer(irlmp, sysctl_discovery_timeout*HZ);
       else
	       del_timer_sync(&irlmp->discovery_timer);

       return ret;
}

L
Linus Torvalds 已提交
113 114 115
/* One file */
static ctl_table irda_table[] = {
	{
116
		.ctl_name	= NET_IRDA_DISCOVERY,
L
Linus Torvalds 已提交
117 118 119 120
		.procname	= "discovery",
		.data		= &sysctl_discovery,
		.maxlen		= sizeof(int),
		.mode		= 0644,
121 122
		.proc_handler	= &do_discovery,
		.strategy       = &sysctl_intvec
L
Linus Torvalds 已提交
123 124
	},
	{
125
		.ctl_name	= NET_IRDA_DEVNAME,
L
Linus Torvalds 已提交
126 127 128 129 130 131 132 133
		.procname	= "devname",
		.data		= sysctl_devname,
		.maxlen		= 65,
		.mode		= 0644,
		.proc_handler	= &do_devname,
		.strategy	= &sysctl_string
	},
#ifdef CONFIG_IRDA_DEBUG
134
	{
135
		.ctl_name	= NET_IRDA_DEBUG,
L
Linus Torvalds 已提交
136 137 138 139 140 141 142 143
		.procname	= "debug",
		.data		= &irda_debug,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec
	},
#endif
#ifdef CONFIG_IRDA_FAST_RR
144
	{
145
		.ctl_name	= NET_IRDA_FAST_POLL,
L
Linus Torvalds 已提交
146 147 148 149 150 151 152 153
		.procname	= "fast_poll_increase",
		.data		= &sysctl_fast_poll_increase,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec
	},
#endif
	{
154
		.ctl_name	= NET_IRDA_DISCOVERY_SLOTS,
L
Linus Torvalds 已提交
155 156 157 158 159 160 161 162 163 164
		.procname	= "discovery_slots",
		.data		= &sysctl_discovery_slots,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_discovery_slots,
		.extra2		= &max_discovery_slots
	},
	{
165
		.ctl_name	= NET_IRDA_DISCOVERY_TIMEOUT,
L
Linus Torvalds 已提交
166 167 168 169 170 171 172
		.procname	= "discovery_timeout",
		.data		= &sysctl_discovery_timeout,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec
	},
	{
173
		.ctl_name	= NET_IRDA_SLOT_TIMEOUT,
L
Linus Torvalds 已提交
174 175 176 177 178 179 180 181 182 183
		.procname	= "slot_timeout",
		.data		= &sysctl_slot_timeout,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_slot_timeout,
		.extra2		= &max_slot_timeout
	},
	{
184
		.ctl_name	= NET_IRDA_MAX_BAUD_RATE,
L
Linus Torvalds 已提交
185 186 187 188 189 190 191 192 193 194
		.procname	= "max_baud_rate",
		.data		= &sysctl_max_baud_rate,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_max_baud_rate,
		.extra2		= &max_max_baud_rate
	},
	{
195
		.ctl_name	= NET_IRDA_MIN_TX_TURN_TIME,
L
Linus Torvalds 已提交
196 197 198 199 200 201 202 203 204 205
		.procname	= "min_tx_turn_time",
		.data		= &sysctl_min_tx_turn_time,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_min_tx_turn_time,
		.extra2		= &max_min_tx_turn_time
	},
	{
206
		.ctl_name	= NET_IRDA_MAX_TX_DATA_SIZE,
L
Linus Torvalds 已提交
207 208 209 210 211 212 213 214 215 216
		.procname	= "max_tx_data_size",
		.data		= &sysctl_max_tx_data_size,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_max_tx_data_size,
		.extra2		= &max_max_tx_data_size
	},
	{
217
		.ctl_name	= NET_IRDA_MAX_TX_WINDOW,
L
Linus Torvalds 已提交
218 219 220 221 222 223 224 225 226 227
		.procname	= "max_tx_window",
		.data		= &sysctl_max_tx_window,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_max_tx_window,
		.extra2		= &max_max_tx_window
	},
	{
228
		.ctl_name	= NET_IRDA_MAX_NOREPLY_TIME,
L
Linus Torvalds 已提交
229 230 231 232 233 234 235 236 237 238
		.procname	= "max_noreply_time",
		.data		= &sysctl_max_noreply_time,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_max_noreply_time,
		.extra2		= &max_max_noreply_time
	},
	{
239
		.ctl_name	= NET_IRDA_WARN_NOREPLY_TIME,
L
Linus Torvalds 已提交
240 241 242 243 244 245 246 247 248 249
		.procname	= "warn_noreply_time",
		.data		= &sysctl_warn_noreply_time,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_warn_noreply_time,
		.extra2		= &max_warn_noreply_time
	},
	{
250
		.ctl_name	= NET_IRDA_LAP_KEEPALIVE_TIME,
L
Linus Torvalds 已提交
251 252 253 254 255 256 257 258 259 260 261 262
		.procname	= "lap_keepalive_time",
		.data		= &sysctl_lap_keepalive_time,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_lap_keepalive_time,
		.extra2		= &max_lap_keepalive_time
	},
	{ .ctl_name = 0 }
};

263 264 265 266
static struct ctl_path irda_path[] = {
	{ .procname = "net", .ctl_name = CTL_NET, },
	{ .procname = "irda", .ctl_name = NET_IRDA, },
	{ }
L
Linus Torvalds 已提交
267 268 269 270 271 272 273 274 275 276 277 278
};

static struct ctl_table_header *irda_table_header;

/*
 * Function irda_sysctl_register (void)
 *
 *    Register our sysctl interface
 *
 */
int __init irda_sysctl_register(void)
{
279
	irda_table_header = register_sysctl_paths(irda_path, irda_table);
L
Linus Torvalds 已提交
280 281 282 283 284 285 286 287 288 289 290 291
	if (!irda_table_header)
		return -ENOMEM;

	return 0;
}

/*
 * Function irda_sysctl_unregister (void)
 *
 *    Unregister our sysctl interface
 *
 */
S
Samuel Ortiz 已提交
292
void irda_sysctl_unregister(void)
L
Linus Torvalds 已提交
293 294 295 296 297 298
{
	unregister_sysctl_table(irda_table_header);
}