irsysctl.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*********************************************************************
  2. *
  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>
  11. *
  12. * Copyright (c) 1997, 1999 Dag Brattli, All Rights Reserved.
  13. * Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
  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
  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
  22. * provided "AS-IS" and at no charge.
  23. *
  24. ********************************************************************/
  25. #include <linux/config.h>
  26. #include <linux/mm.h>
  27. #include <linux/ctype.h>
  28. #include <linux/sysctl.h>
  29. #include <linux/init.h>
  30. #include <net/irda/irda.h> /* irda_debug */
  31. #include <net/irda/irias_object.h>
  32. #define NET_IRDA 412 /* Random number */
  33. enum { DISCOVERY=1, DEVNAME, DEBUG, FAST_POLL, DISCOVERY_SLOTS,
  34. DISCOVERY_TIMEOUT, SLOT_TIMEOUT, MAX_BAUD_RATE, MIN_TX_TURN_TIME,
  35. MAX_TX_DATA_SIZE, MAX_TX_WINDOW, MAX_NOREPLY_TIME, WARN_NOREPLY_TIME,
  36. LAP_KEEPALIVE_TIME };
  37. extern int sysctl_discovery;
  38. extern int sysctl_discovery_slots;
  39. extern int sysctl_discovery_timeout;
  40. extern int sysctl_slot_timeout;
  41. extern int sysctl_fast_poll_increase;
  42. extern char sysctl_devname[];
  43. extern int sysctl_max_baud_rate;
  44. extern int sysctl_min_tx_turn_time;
  45. extern int sysctl_max_tx_data_size;
  46. extern int sysctl_max_tx_window;
  47. extern int sysctl_max_noreply_time;
  48. extern int sysctl_warn_noreply_time;
  49. extern int sysctl_lap_keepalive_time;
  50. /* this is needed for the proc_dointvec_minmax - Jean II */
  51. static int max_discovery_slots = 16; /* ??? */
  52. static int min_discovery_slots = 1;
  53. /* IrLAP 6.13.2 says 25ms to 10+70ms - allow higher since some devices
  54. * seems to require it. (from Dag's comment) */
  55. static int max_slot_timeout = 160;
  56. static int min_slot_timeout = 20;
  57. static int max_max_baud_rate = 16000000; /* See qos.c - IrLAP spec */
  58. static int min_max_baud_rate = 2400;
  59. static int max_min_tx_turn_time = 10000; /* See qos.c - IrLAP spec */
  60. static int min_min_tx_turn_time;
  61. static int max_max_tx_data_size = 2048; /* See qos.c - IrLAP spec */
  62. static int min_max_tx_data_size = 64;
  63. static int max_max_tx_window = 7; /* See qos.c - IrLAP spec */
  64. static int min_max_tx_window = 1;
  65. static int max_max_noreply_time = 40; /* See qos.c - IrLAP spec */
  66. static int min_max_noreply_time = 3;
  67. static int max_warn_noreply_time = 3; /* 3s == standard */
  68. static int min_warn_noreply_time = 1; /* 1s == min WD_TIMER */
  69. static int max_lap_keepalive_time = 10000; /* 10s */
  70. static int min_lap_keepalive_time = 100; /* 100us */
  71. /* For other sysctl, I've no idea of the range. Maybe Dag could help
  72. * us on that - Jean II */
  73. static int do_devname(ctl_table *table, int write, struct file *filp,
  74. void __user *buffer, size_t *lenp, loff_t *ppos)
  75. {
  76. int ret;
  77. ret = proc_dostring(table, write, filp, buffer, lenp, ppos);
  78. if (ret == 0 && write) {
  79. struct ias_value *val;
  80. val = irias_new_string_value(sysctl_devname);
  81. if (val)
  82. irias_object_change_attribute("Device", "DeviceName", val);
  83. }
  84. return ret;
  85. }
  86. /* One file */
  87. static ctl_table irda_table[] = {
  88. {
  89. .ctl_name = DISCOVERY,
  90. .procname = "discovery",
  91. .data = &sysctl_discovery,
  92. .maxlen = sizeof(int),
  93. .mode = 0644,
  94. .proc_handler = &proc_dointvec
  95. },
  96. {
  97. .ctl_name = DEVNAME,
  98. .procname = "devname",
  99. .data = sysctl_devname,
  100. .maxlen = 65,
  101. .mode = 0644,
  102. .proc_handler = &do_devname,
  103. .strategy = &sysctl_string
  104. },
  105. #ifdef CONFIG_IRDA_DEBUG
  106. {
  107. .ctl_name = DEBUG,
  108. .procname = "debug",
  109. .data = &irda_debug,
  110. .maxlen = sizeof(int),
  111. .mode = 0644,
  112. .proc_handler = &proc_dointvec
  113. },
  114. #endif
  115. #ifdef CONFIG_IRDA_FAST_RR
  116. {
  117. .ctl_name = FAST_POLL,
  118. .procname = "fast_poll_increase",
  119. .data = &sysctl_fast_poll_increase,
  120. .maxlen = sizeof(int),
  121. .mode = 0644,
  122. .proc_handler = &proc_dointvec
  123. },
  124. #endif
  125. {
  126. .ctl_name = DISCOVERY_SLOTS,
  127. .procname = "discovery_slots",
  128. .data = &sysctl_discovery_slots,
  129. .maxlen = sizeof(int),
  130. .mode = 0644,
  131. .proc_handler = &proc_dointvec_minmax,
  132. .strategy = &sysctl_intvec,
  133. .extra1 = &min_discovery_slots,
  134. .extra2 = &max_discovery_slots
  135. },
  136. {
  137. .ctl_name = DISCOVERY_TIMEOUT,
  138. .procname = "discovery_timeout",
  139. .data = &sysctl_discovery_timeout,
  140. .maxlen = sizeof(int),
  141. .mode = 0644,
  142. .proc_handler = &proc_dointvec
  143. },
  144. {
  145. .ctl_name = SLOT_TIMEOUT,
  146. .procname = "slot_timeout",
  147. .data = &sysctl_slot_timeout,
  148. .maxlen = sizeof(int),
  149. .mode = 0644,
  150. .proc_handler = &proc_dointvec_minmax,
  151. .strategy = &sysctl_intvec,
  152. .extra1 = &min_slot_timeout,
  153. .extra2 = &max_slot_timeout
  154. },
  155. {
  156. .ctl_name = MAX_BAUD_RATE,
  157. .procname = "max_baud_rate",
  158. .data = &sysctl_max_baud_rate,
  159. .maxlen = sizeof(int),
  160. .mode = 0644,
  161. .proc_handler = &proc_dointvec_minmax,
  162. .strategy = &sysctl_intvec,
  163. .extra1 = &min_max_baud_rate,
  164. .extra2 = &max_max_baud_rate
  165. },
  166. {
  167. .ctl_name = MIN_TX_TURN_TIME,
  168. .procname = "min_tx_turn_time",
  169. .data = &sysctl_min_tx_turn_time,
  170. .maxlen = sizeof(int),
  171. .mode = 0644,
  172. .proc_handler = &proc_dointvec_minmax,
  173. .strategy = &sysctl_intvec,
  174. .extra1 = &min_min_tx_turn_time,
  175. .extra2 = &max_min_tx_turn_time
  176. },
  177. {
  178. .ctl_name = MAX_TX_DATA_SIZE,
  179. .procname = "max_tx_data_size",
  180. .data = &sysctl_max_tx_data_size,
  181. .maxlen = sizeof(int),
  182. .mode = 0644,
  183. .proc_handler = &proc_dointvec_minmax,
  184. .strategy = &sysctl_intvec,
  185. .extra1 = &min_max_tx_data_size,
  186. .extra2 = &max_max_tx_data_size
  187. },
  188. {
  189. .ctl_name = MAX_TX_WINDOW,
  190. .procname = "max_tx_window",
  191. .data = &sysctl_max_tx_window,
  192. .maxlen = sizeof(int),
  193. .mode = 0644,
  194. .proc_handler = &proc_dointvec_minmax,
  195. .strategy = &sysctl_intvec,
  196. .extra1 = &min_max_tx_window,
  197. .extra2 = &max_max_tx_window
  198. },
  199. {
  200. .ctl_name = MAX_NOREPLY_TIME,
  201. .procname = "max_noreply_time",
  202. .data = &sysctl_max_noreply_time,
  203. .maxlen = sizeof(int),
  204. .mode = 0644,
  205. .proc_handler = &proc_dointvec_minmax,
  206. .strategy = &sysctl_intvec,
  207. .extra1 = &min_max_noreply_time,
  208. .extra2 = &max_max_noreply_time
  209. },
  210. {
  211. .ctl_name = WARN_NOREPLY_TIME,
  212. .procname = "warn_noreply_time",
  213. .data = &sysctl_warn_noreply_time,
  214. .maxlen = sizeof(int),
  215. .mode = 0644,
  216. .proc_handler = &proc_dointvec_minmax,
  217. .strategy = &sysctl_intvec,
  218. .extra1 = &min_warn_noreply_time,
  219. .extra2 = &max_warn_noreply_time
  220. },
  221. {
  222. .ctl_name = LAP_KEEPALIVE_TIME,
  223. .procname = "lap_keepalive_time",
  224. .data = &sysctl_lap_keepalive_time,
  225. .maxlen = sizeof(int),
  226. .mode = 0644,
  227. .proc_handler = &proc_dointvec_minmax,
  228. .strategy = &sysctl_intvec,
  229. .extra1 = &min_lap_keepalive_time,
  230. .extra2 = &max_lap_keepalive_time
  231. },
  232. { .ctl_name = 0 }
  233. };
  234. /* One directory */
  235. static ctl_table irda_net_table[] = {
  236. {
  237. .ctl_name = NET_IRDA,
  238. .procname = "irda",
  239. .maxlen = 0,
  240. .mode = 0555,
  241. .child = irda_table
  242. },
  243. { .ctl_name = 0 }
  244. };
  245. /* The parent directory */
  246. static ctl_table irda_root_table[] = {
  247. {
  248. .ctl_name = CTL_NET,
  249. .procname = "net",
  250. .maxlen = 0,
  251. .mode = 0555,
  252. .child = irda_net_table
  253. },
  254. { .ctl_name = 0 }
  255. };
  256. static struct ctl_table_header *irda_table_header;
  257. /*
  258. * Function irda_sysctl_register (void)
  259. *
  260. * Register our sysctl interface
  261. *
  262. */
  263. int __init irda_sysctl_register(void)
  264. {
  265. irda_table_header = register_sysctl_table(irda_root_table, 0);
  266. if (!irda_table_header)
  267. return -ENOMEM;
  268. return 0;
  269. }
  270. /*
  271. * Function irda_sysctl_unregister (void)
  272. *
  273. * Unregister our sysctl interface
  274. *
  275. */
  276. void __exit irda_sysctl_unregister(void)
  277. {
  278. unregister_sysctl_table(irda_table_header);
  279. }