Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Copyright (c) 1997, 1999 Dag Brattli, All Rights Reserved. |
| 13 | * Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * the License, or (at your option) any later version. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 19 | * |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 20 | * Neither Dag Brattli nor University of Tromsø admit liability nor |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 21 | * provide warranty for any of this software. This material is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * provided "AS-IS" and at no charge. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 23 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | ********************************************************************/ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Ross Burton | 91cde6f | 2008-01-22 18:27:53 -0800 | [diff] [blame] | 32 | #include <net/irda/irlmp.h> |
| 33 | #include <net/irda/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <net/irda/irias_object.h> |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | extern int sysctl_discovery; |
| 37 | extern int sysctl_discovery_slots; |
| 38 | extern int sysctl_discovery_timeout; |
| 39 | extern int sysctl_slot_timeout; |
| 40 | extern int sysctl_fast_poll_increase; |
| 41 | extern char sysctl_devname[]; |
| 42 | extern int sysctl_max_baud_rate; |
Andi Kleen | 9566042 | 2011-09-16 09:09:50 +0000 | [diff] [blame] | 43 | extern unsigned int sysctl_min_tx_turn_time; |
| 44 | extern unsigned int sysctl_max_tx_data_size; |
| 45 | extern unsigned int sysctl_max_tx_window; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | extern int sysctl_max_noreply_time; |
| 47 | extern int sysctl_warn_noreply_time; |
| 48 | extern int sysctl_lap_keepalive_time; |
| 49 | |
Ross Burton | 91cde6f | 2008-01-22 18:27:53 -0800 | [diff] [blame] | 50 | extern struct irlmp_cb *irlmp; |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* this is needed for the proc_dointvec_minmax - Jean II */ |
| 53 | static int max_discovery_slots = 16; /* ??? */ |
| 54 | static 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) */ |
| 57 | static int max_slot_timeout = 160; |
| 58 | static int min_slot_timeout = 20; |
| 59 | static int max_max_baud_rate = 16000000; /* See qos.c - IrLAP spec */ |
| 60 | static int min_max_baud_rate = 2400; |
| 61 | static int max_min_tx_turn_time = 10000; /* See qos.c - IrLAP spec */ |
| 62 | static int min_min_tx_turn_time; |
| 63 | static int max_max_tx_data_size = 2048; /* See qos.c - IrLAP spec */ |
| 64 | static int min_max_tx_data_size = 64; |
| 65 | static int max_max_tx_window = 7; /* See qos.c - IrLAP spec */ |
| 66 | static int min_max_tx_window = 1; |
| 67 | static int max_max_noreply_time = 40; /* See qos.c - IrLAP spec */ |
| 68 | static int min_max_noreply_time = 3; |
| 69 | static int max_warn_noreply_time = 3; /* 3s == standard */ |
| 70 | static int min_warn_noreply_time = 1; /* 1s == min WD_TIMER */ |
| 71 | static int max_lap_keepalive_time = 10000; /* 10s */ |
| 72 | static 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 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 76 | static int do_devname(ctl_table *table, int write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 78 | { |
| 79 | int ret; |
| 80 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 81 | ret = proc_dostring(table, write, buffer, lenp, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Burton | 91cde6f | 2008-01-22 18:27:53 -0800 | [diff] [blame] | 92 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 93 | static int do_discovery(ctl_table *table, int write, |
Ross Burton | 91cde6f | 2008-01-22 18:27:53 -0800 | [diff] [blame] | 94 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 95 | { |
| 96 | int ret; |
| 97 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 98 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
Ross Burton | 91cde6f | 2008-01-22 18:27:53 -0800 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* One file */ |
| 114 | static ctl_table irda_table[] = { |
| 115 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | .procname = "discovery", |
| 117 | .data = &sysctl_discovery, |
| 118 | .maxlen = sizeof(int), |
| 119 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 120 | .proc_handler = do_discovery, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | }, |
| 122 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | .procname = "devname", |
| 124 | .data = sysctl_devname, |
| 125 | .maxlen = 65, |
| 126 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 127 | .proc_handler = do_devname, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | }, |
| 129 | #ifdef CONFIG_IRDA_DEBUG |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 130 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | .procname = "debug", |
| 132 | .data = &irda_debug, |
| 133 | .maxlen = sizeof(int), |
| 134 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 135 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }, |
| 137 | #endif |
| 138 | #ifdef CONFIG_IRDA_FAST_RR |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 139 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | .procname = "fast_poll_increase", |
| 141 | .data = &sysctl_fast_poll_increase, |
| 142 | .maxlen = sizeof(int), |
| 143 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 144 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | }, |
| 146 | #endif |
| 147 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | .procname = "discovery_slots", |
| 149 | .data = &sysctl_discovery_slots, |
| 150 | .maxlen = sizeof(int), |
| 151 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 152 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | .extra1 = &min_discovery_slots, |
| 154 | .extra2 = &max_discovery_slots |
| 155 | }, |
| 156 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | .procname = "discovery_timeout", |
| 158 | .data = &sysctl_discovery_timeout, |
| 159 | .maxlen = sizeof(int), |
| 160 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 161 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | }, |
| 163 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | .procname = "slot_timeout", |
| 165 | .data = &sysctl_slot_timeout, |
| 166 | .maxlen = sizeof(int), |
| 167 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 168 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | .extra1 = &min_slot_timeout, |
| 170 | .extra2 = &max_slot_timeout |
| 171 | }, |
| 172 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | .procname = "max_baud_rate", |
| 174 | .data = &sysctl_max_baud_rate, |
| 175 | .maxlen = sizeof(int), |
| 176 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 177 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | .extra1 = &min_max_baud_rate, |
| 179 | .extra2 = &max_max_baud_rate |
| 180 | }, |
| 181 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | .procname = "min_tx_turn_time", |
| 183 | .data = &sysctl_min_tx_turn_time, |
| 184 | .maxlen = sizeof(int), |
| 185 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 186 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | .extra1 = &min_min_tx_turn_time, |
| 188 | .extra2 = &max_min_tx_turn_time |
| 189 | }, |
| 190 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | .procname = "max_tx_data_size", |
| 192 | .data = &sysctl_max_tx_data_size, |
| 193 | .maxlen = sizeof(int), |
| 194 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 195 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | .extra1 = &min_max_tx_data_size, |
| 197 | .extra2 = &max_max_tx_data_size |
| 198 | }, |
| 199 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | .procname = "max_tx_window", |
| 201 | .data = &sysctl_max_tx_window, |
| 202 | .maxlen = sizeof(int), |
| 203 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 204 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | .extra1 = &min_max_tx_window, |
| 206 | .extra2 = &max_max_tx_window |
| 207 | }, |
| 208 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | .procname = "max_noreply_time", |
| 210 | .data = &sysctl_max_noreply_time, |
| 211 | .maxlen = sizeof(int), |
| 212 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 213 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | .extra1 = &min_max_noreply_time, |
| 215 | .extra2 = &max_max_noreply_time |
| 216 | }, |
| 217 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | .procname = "warn_noreply_time", |
| 219 | .data = &sysctl_warn_noreply_time, |
| 220 | .maxlen = sizeof(int), |
| 221 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 222 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | .extra1 = &min_warn_noreply_time, |
| 224 | .extra2 = &max_warn_noreply_time |
| 225 | }, |
| 226 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | .procname = "lap_keepalive_time", |
| 228 | .data = &sysctl_lap_keepalive_time, |
| 229 | .maxlen = sizeof(int), |
| 230 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 231 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | .extra1 = &min_lap_keepalive_time, |
| 233 | .extra2 = &max_lap_keepalive_time |
| 234 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 235 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | }; |
| 237 | |
Pavel Emelyanov | b5ccd79 | 2008-01-09 00:30:05 -0800 | [diff] [blame] | 238 | static struct ctl_path irda_path[] = { |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 239 | { .procname = "net", }, |
| 240 | { .procname = "irda", }, |
Pavel Emelyanov | b5ccd79 | 2008-01-09 00:30:05 -0800 | [diff] [blame] | 241 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | static struct ctl_table_header *irda_table_header; |
| 245 | |
| 246 | /* |
| 247 | * Function irda_sysctl_register (void) |
| 248 | * |
| 249 | * Register our sysctl interface |
| 250 | * |
| 251 | */ |
| 252 | int __init irda_sysctl_register(void) |
| 253 | { |
Pavel Emelyanov | b5ccd79 | 2008-01-09 00:30:05 -0800 | [diff] [blame] | 254 | irda_table_header = register_sysctl_paths(irda_path, irda_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | if (!irda_table_header) |
| 256 | return -ENOMEM; |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Function irda_sysctl_unregister (void) |
| 263 | * |
| 264 | * Unregister our sysctl interface |
| 265 | * |
| 266 | */ |
Samuel Ortiz | 75a69ac | 2007-07-18 02:16:30 -0700 | [diff] [blame] | 267 | void irda_sysctl_unregister(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
| 269 | unregister_sysctl_table(irda_table_header); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | |