irsysctl.c 7.8 KB

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