irsysctl.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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/irlmp.h>
  31. #include <net/irda/timer.h>
  32. #include <net/irda/irias_object.h>
  33. extern int sysctl_discovery;
  34. extern int sysctl_discovery_slots;
  35. extern int sysctl_discovery_timeout;
  36. extern int sysctl_slot_timeout;
  37. extern int sysctl_fast_poll_increase;
  38. extern char sysctl_devname[];
  39. extern int sysctl_max_baud_rate;
  40. extern unsigned int sysctl_min_tx_turn_time;
  41. extern unsigned int sysctl_max_tx_data_size;
  42. extern unsigned int sysctl_max_tx_window;
  43. extern int sysctl_max_noreply_time;
  44. extern int sysctl_warn_noreply_time;
  45. extern int sysctl_lap_keepalive_time;
  46. extern struct irlmp_cb *irlmp;
  47. /* this is needed for the proc_dointvec_minmax - Jean II */
  48. static int max_discovery_slots = 16; /* ??? */
  49. static int min_discovery_slots = 1;
  50. /* IrLAP 6.13.2 says 25ms to 10+70ms - allow higher since some devices
  51. * seems to require it. (from Dag's comment) */
  52. static int max_slot_timeout = 160;
  53. static int min_slot_timeout = 20;
  54. static int max_max_baud_rate = 16000000; /* See qos.c - IrLAP spec */
  55. static int min_max_baud_rate = 2400;
  56. static int max_min_tx_turn_time = 10000; /* See qos.c - IrLAP spec */
  57. static int min_min_tx_turn_time;
  58. static int max_max_tx_data_size = 2048; /* See qos.c - IrLAP spec */
  59. static int min_max_tx_data_size = 64;
  60. static int max_max_tx_window = 7; /* See qos.c - IrLAP spec */
  61. static int min_max_tx_window = 1;
  62. static int max_max_noreply_time = 40; /* See qos.c - IrLAP spec */
  63. static int min_max_noreply_time = 3;
  64. static int max_warn_noreply_time = 3; /* 3s == standard */
  65. static int min_warn_noreply_time = 1; /* 1s == min WD_TIMER */
  66. static int max_lap_keepalive_time = 10000; /* 10s */
  67. static int min_lap_keepalive_time = 100; /* 100us */
  68. /* For other sysctl, I've no idea of the range. Maybe Dag could help
  69. * us on that - Jean II */
  70. static int do_devname(struct ctl_table *table, int write,
  71. void __user *buffer, size_t *lenp, loff_t *ppos)
  72. {
  73. int ret;
  74. ret = proc_dostring(table, write, buffer, lenp, ppos);
  75. if (ret == 0 && write) {
  76. struct ias_value *val;
  77. val = irias_new_string_value(sysctl_devname);
  78. if (val)
  79. irias_object_change_attribute("Device", "DeviceName", val);
  80. }
  81. return ret;
  82. }
  83. static int do_discovery(struct ctl_table *table, int write,
  84. void __user *buffer, size_t *lenp, loff_t *ppos)
  85. {
  86. int ret;
  87. ret = proc_dointvec(table, write, buffer, lenp, ppos);
  88. if (ret)
  89. return ret;
  90. if (irlmp == NULL)
  91. return -ENODEV;
  92. if (sysctl_discovery)
  93. irlmp_start_discovery_timer(irlmp, sysctl_discovery_timeout*HZ);
  94. else
  95. del_timer_sync(&irlmp->discovery_timer);
  96. return ret;
  97. }
  98. /* One file */
  99. static struct ctl_table irda_table[] = {
  100. {
  101. .procname = "discovery",
  102. .data = &sysctl_discovery,
  103. .maxlen = sizeof(int),
  104. .mode = 0644,
  105. .proc_handler = do_discovery,
  106. },
  107. {
  108. .procname = "devname",
  109. .data = sysctl_devname,
  110. .maxlen = 65,
  111. .mode = 0644,
  112. .proc_handler = do_devname,
  113. },
  114. #ifdef CONFIG_IRDA_FAST_RR
  115. {
  116. .procname = "fast_poll_increase",
  117. .data = &sysctl_fast_poll_increase,
  118. .maxlen = sizeof(int),
  119. .mode = 0644,
  120. .proc_handler = proc_dointvec
  121. },
  122. #endif
  123. {
  124. .procname = "discovery_slots",
  125. .data = &sysctl_discovery_slots,
  126. .maxlen = sizeof(int),
  127. .mode = 0644,
  128. .proc_handler = proc_dointvec_minmax,
  129. .extra1 = &min_discovery_slots,
  130. .extra2 = &max_discovery_slots
  131. },
  132. {
  133. .procname = "discovery_timeout",
  134. .data = &sysctl_discovery_timeout,
  135. .maxlen = sizeof(int),
  136. .mode = 0644,
  137. .proc_handler = proc_dointvec
  138. },
  139. {
  140. .procname = "slot_timeout",
  141. .data = &sysctl_slot_timeout,
  142. .maxlen = sizeof(int),
  143. .mode = 0644,
  144. .proc_handler = proc_dointvec_minmax,
  145. .extra1 = &min_slot_timeout,
  146. .extra2 = &max_slot_timeout
  147. },
  148. {
  149. .procname = "max_baud_rate",
  150. .data = &sysctl_max_baud_rate,
  151. .maxlen = sizeof(int),
  152. .mode = 0644,
  153. .proc_handler = proc_dointvec_minmax,
  154. .extra1 = &min_max_baud_rate,
  155. .extra2 = &max_max_baud_rate
  156. },
  157. {
  158. .procname = "min_tx_turn_time",
  159. .data = &sysctl_min_tx_turn_time,
  160. .maxlen = sizeof(int),
  161. .mode = 0644,
  162. .proc_handler = proc_dointvec_minmax,
  163. .extra1 = &min_min_tx_turn_time,
  164. .extra2 = &max_min_tx_turn_time
  165. },
  166. {
  167. .procname = "max_tx_data_size",
  168. .data = &sysctl_max_tx_data_size,
  169. .maxlen = sizeof(int),
  170. .mode = 0644,
  171. .proc_handler = proc_dointvec_minmax,
  172. .extra1 = &min_max_tx_data_size,
  173. .extra2 = &max_max_tx_data_size
  174. },
  175. {
  176. .procname = "max_tx_window",
  177. .data = &sysctl_max_tx_window,
  178. .maxlen = sizeof(int),
  179. .mode = 0644,
  180. .proc_handler = proc_dointvec_minmax,
  181. .extra1 = &min_max_tx_window,
  182. .extra2 = &max_max_tx_window
  183. },
  184. {
  185. .procname = "max_noreply_time",
  186. .data = &sysctl_max_noreply_time,
  187. .maxlen = sizeof(int),
  188. .mode = 0644,
  189. .proc_handler = proc_dointvec_minmax,
  190. .extra1 = &min_max_noreply_time,
  191. .extra2 = &max_max_noreply_time
  192. },
  193. {
  194. .procname = "warn_noreply_time",
  195. .data = &sysctl_warn_noreply_time,
  196. .maxlen = sizeof(int),
  197. .mode = 0644,
  198. .proc_handler = proc_dointvec_minmax,
  199. .extra1 = &min_warn_noreply_time,
  200. .extra2 = &max_warn_noreply_time
  201. },
  202. {
  203. .procname = "lap_keepalive_time",
  204. .data = &sysctl_lap_keepalive_time,
  205. .maxlen = sizeof(int),
  206. .mode = 0644,
  207. .proc_handler = proc_dointvec_minmax,
  208. .extra1 = &min_lap_keepalive_time,
  209. .extra2 = &max_lap_keepalive_time
  210. },
  211. { }
  212. };
  213. static struct ctl_table_header *irda_table_header;
  214. /*
  215. * Function irda_sysctl_register (void)
  216. *
  217. * Register our sysctl interface
  218. *
  219. */
  220. int __init irda_sysctl_register(void)
  221. {
  222. irda_table_header = register_net_sysctl(&init_net, "net/irda", irda_table);
  223. if (!irda_table_header)
  224. return -ENOMEM;
  225. return 0;
  226. }
  227. /*
  228. * Function irda_sysctl_unregister (void)
  229. *
  230. * Unregister our sysctl interface
  231. *
  232. */
  233. void irda_sysctl_unregister(void)
  234. {
  235. unregister_net_sysctl_table(irda_table_header);
  236. }