| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*********************************************************************
 | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * 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> | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  *     Copyright (c) 1997, 1999 Dag Brattli, All Rights Reserved. | 
					
						
							|  |  |  |  *     Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com> | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  |  * | 
					
						
							|  |  |  |  *     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 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  *     the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2007-10-19 23:21:04 +02:00
										 |  |  |  *     Neither Dag Brattli nor University of Tromsø admit liability nor | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  |  *     provide warranty for any of this software. This material is | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  *     provided "AS-IS" and at no charge. | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  ********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/ctype.h>
 | 
					
						
							|  |  |  | #include <linux/sysctl.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <net/irda/irda.h>		/* irda_debug */
 | 
					
						
							| 
									
										
										
										
											2008-01-22 18:27:53 -08:00
										 |  |  | #include <net/irda/irlmp.h>
 | 
					
						
							|  |  |  | #include <net/irda/timer.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #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; | 
					
						
							| 
									
										
										
										
											2011-09-16 09:09:50 +00:00
										 |  |  | extern unsigned int sysctl_min_tx_turn_time; | 
					
						
							|  |  |  | extern unsigned int sysctl_max_tx_data_size; | 
					
						
							|  |  |  | extern unsigned int sysctl_max_tx_window; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | extern int  sysctl_max_noreply_time; | 
					
						
							|  |  |  | extern int  sysctl_warn_noreply_time; | 
					
						
							|  |  |  | extern int  sysctl_lap_keepalive_time; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-22 18:27:53 -08:00
										 |  |  | extern struct irlmp_cb *irlmp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* 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 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 15:57:19 -07:00
										 |  |  | static int do_devname(ctl_table *table, int write, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		      void __user *buffer, size_t *lenp, loff_t *ppos) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 15:57:19 -07:00
										 |  |  | 	ret = proc_dostring(table, write, buffer, lenp, ppos); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-22 18:27:53 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 15:57:19 -07:00
										 |  |  | static int do_discovery(ctl_table *table, int write, | 
					
						
							| 
									
										
										
										
											2008-01-22 18:27:53 -08:00
										 |  |  |                     void __user *buffer, size_t *lenp, loff_t *ppos) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |        int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 15:57:19 -07:00
										 |  |  |        ret = proc_dointvec(table, write, buffer, lenp, ppos); | 
					
						
							| 
									
										
										
										
											2008-01-22 18:27:53 -08:00
										 |  |  |        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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* One file */ | 
					
						
							|  |  |  | static ctl_table irda_table[] = { | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "discovery", | 
					
						
							|  |  |  | 		.data		= &sysctl_discovery, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= do_discovery, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "devname", | 
					
						
							|  |  |  | 		.data		= sysctl_devname, | 
					
						
							|  |  |  | 		.maxlen		= 65, | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= do_devname, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	}, | 
					
						
							|  |  |  | #ifdef CONFIG_IRDA_DEBUG
 | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.procname	= "debug", | 
					
						
							|  |  |  | 		.data		= &irda_debug, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	}, | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef CONFIG_IRDA_FAST_RR
 | 
					
						
							| 
									
										
										
										
											2007-02-09 23:24:53 +09:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.procname	= "fast_poll_increase", | 
					
						
							|  |  |  | 		.data		= &sysctl_fast_poll_increase, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	}, | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "discovery_slots", | 
					
						
							|  |  |  | 		.data		= &sysctl_discovery_slots, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_discovery_slots, | 
					
						
							|  |  |  | 		.extra2		= &max_discovery_slots | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "discovery_timeout", | 
					
						
							|  |  |  | 		.data		= &sysctl_discovery_timeout, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "slot_timeout", | 
					
						
							|  |  |  | 		.data		= &sysctl_slot_timeout, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_slot_timeout, | 
					
						
							|  |  |  | 		.extra2		= &max_slot_timeout | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "max_baud_rate", | 
					
						
							|  |  |  | 		.data		= &sysctl_max_baud_rate, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_max_baud_rate, | 
					
						
							|  |  |  | 		.extra2		= &max_max_baud_rate | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "min_tx_turn_time", | 
					
						
							|  |  |  | 		.data		= &sysctl_min_tx_turn_time, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_min_tx_turn_time, | 
					
						
							|  |  |  | 		.extra2		= &max_min_tx_turn_time | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "max_tx_data_size", | 
					
						
							|  |  |  | 		.data		= &sysctl_max_tx_data_size, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_max_tx_data_size, | 
					
						
							|  |  |  | 		.extra2		= &max_max_tx_data_size | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "max_tx_window", | 
					
						
							|  |  |  | 		.data		= &sysctl_max_tx_window, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_max_tx_window, | 
					
						
							|  |  |  | 		.extra2		= &max_max_tx_window | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "max_noreply_time", | 
					
						
							|  |  |  | 		.data		= &sysctl_max_noreply_time, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_max_noreply_time, | 
					
						
							|  |  |  | 		.extra2		= &max_max_noreply_time | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "warn_noreply_time", | 
					
						
							|  |  |  | 		.data		= &sysctl_warn_noreply_time, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_warn_noreply_time, | 
					
						
							|  |  |  | 		.extra2		= &max_warn_noreply_time | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		.procname	= "lap_keepalive_time", | 
					
						
							|  |  |  | 		.data		= &sysctl_lap_keepalive_time, | 
					
						
							|  |  |  | 		.maxlen		= sizeof(int), | 
					
						
							|  |  |  | 		.mode		= 0644, | 
					
						
							| 
									
										
										
										
											2008-11-03 18:21:05 -08:00
										 |  |  | 		.proc_handler	= proc_dointvec_minmax, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		.extra1		= &min_lap_keepalive_time, | 
					
						
							|  |  |  | 		.extra2		= &max_lap_keepalive_time | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2009-11-05 13:32:03 -08:00
										 |  |  | 	{ } | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ctl_table_header *irda_table_header; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Function irda_sysctl_register (void) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    Register our sysctl interface | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | int __init irda_sysctl_register(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:44:49 +00:00
										 |  |  | 	irda_table_header = register_net_sysctl(&init_net, "net/irda", irda_table); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (!irda_table_header) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Function irda_sysctl_unregister (void) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    Unregister our sysctl interface | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2007-07-18 02:16:30 -07:00
										 |  |  | void irda_sysctl_unregister(void) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:24:33 +00:00
										 |  |  | 	unregister_net_sysctl_table(irda_table_header); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |