irmod.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*********************************************************************
  2. *
  3. * Filename: irmod.c
  4. * Version: 0.9
  5. * Description: IrDA stack main entry points
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Mon Dec 15 13:55:39 1997
  9. * Modified at: Wed Jan 5 15:12:41 2000
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1997, 1999-2000 Dag Brattli, All Rights Reserved.
  13. * Copyright (c) 2000-2004 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. /*
  26. * This file contains the main entry points of the IrDA stack.
  27. * They are in this file and not af_irda.c because some developpers
  28. * are using the IrDA stack without the socket API (compiling out
  29. * af_irda.c).
  30. * Jean II
  31. */
  32. #include <linux/module.h>
  33. #include <linux/moduleparam.h>
  34. #include <net/irda/irda.h>
  35. #include <net/irda/irmod.h> /* notify_t */
  36. #include <net/irda/irlap.h> /* irlap_init */
  37. #include <net/irda/irlmp.h> /* irlmp_init */
  38. #include <net/irda/iriap.h> /* iriap_init */
  39. #include <net/irda/irttp.h> /* irttp_init */
  40. #include <net/irda/irda_device.h> /* irda_device_init */
  41. /*
  42. * Module parameters
  43. */
  44. #ifdef CONFIG_IRDA_DEBUG
  45. unsigned int irda_debug = IRDA_DEBUG_LEVEL;
  46. module_param_named(debug, irda_debug, uint, 0);
  47. MODULE_PARM_DESC(debug, "IRDA debugging level");
  48. EXPORT_SYMBOL(irda_debug);
  49. #endif
  50. /* Packet type handler.
  51. * Tell the kernel how IrDA packets should be handled.
  52. */
  53. static struct packet_type irda_packet_type __read_mostly = {
  54. .type = cpu_to_be16(ETH_P_IRDA),
  55. .func = irlap_driver_rcv, /* Packet type handler irlap_frame.c */
  56. };
  57. /*
  58. * Function irda_notify_init (notify)
  59. *
  60. * Used for initializing the notify structure
  61. *
  62. */
  63. void irda_notify_init(notify_t *notify)
  64. {
  65. notify->data_indication = NULL;
  66. notify->udata_indication = NULL;
  67. notify->connect_confirm = NULL;
  68. notify->connect_indication = NULL;
  69. notify->disconnect_indication = NULL;
  70. notify->flow_indication = NULL;
  71. notify->status_indication = NULL;
  72. notify->instance = NULL;
  73. strlcpy(notify->name, "Unknown", sizeof(notify->name));
  74. }
  75. EXPORT_SYMBOL(irda_notify_init);
  76. /*
  77. * Function irda_init (void)
  78. *
  79. * Protocol stack initialisation entry point.
  80. * Initialise the various components of the IrDA stack
  81. */
  82. static int __init irda_init(void)
  83. {
  84. int ret = 0;
  85. IRDA_DEBUG(0, "%s()\n", __func__);
  86. /* Lower layer of the stack */
  87. irlmp_init();
  88. irlap_init();
  89. /* Driver/dongle support */
  90. irda_device_init();
  91. /* Higher layers of the stack */
  92. iriap_init();
  93. irttp_init();
  94. ret = irsock_init();
  95. if (ret < 0)
  96. goto out_err_1;
  97. /* Add IrDA packet type (Start receiving packets) */
  98. dev_add_pack(&irda_packet_type);
  99. /* External APIs */
  100. #ifdef CONFIG_PROC_FS
  101. irda_proc_register();
  102. #endif
  103. #ifdef CONFIG_SYSCTL
  104. ret = irda_sysctl_register();
  105. if (ret < 0)
  106. goto out_err_2;
  107. #endif
  108. ret = irda_nl_register();
  109. if (ret < 0)
  110. goto out_err_3;
  111. return 0;
  112. out_err_3:
  113. #ifdef CONFIG_SYSCTL
  114. irda_sysctl_unregister();
  115. out_err_2:
  116. #endif
  117. #ifdef CONFIG_PROC_FS
  118. irda_proc_unregister();
  119. #endif
  120. /* Remove IrDA packet type (stop receiving packets) */
  121. dev_remove_pack(&irda_packet_type);
  122. /* Remove higher layers */
  123. irsock_cleanup();
  124. out_err_1:
  125. irttp_cleanup();
  126. iriap_cleanup();
  127. /* Remove lower layers */
  128. irda_device_cleanup();
  129. irlap_cleanup(); /* Must be done before irlmp_cleanup()! DB */
  130. /* Remove middle layer */
  131. irlmp_cleanup();
  132. return ret;
  133. }
  134. /*
  135. * Function irda_cleanup (void)
  136. *
  137. * Protocol stack cleanup/removal entry point.
  138. * Cleanup the various components of the IrDA stack
  139. */
  140. static void __exit irda_cleanup(void)
  141. {
  142. /* Remove External APIs */
  143. irda_nl_unregister();
  144. #ifdef CONFIG_SYSCTL
  145. irda_sysctl_unregister();
  146. #endif
  147. #ifdef CONFIG_PROC_FS
  148. irda_proc_unregister();
  149. #endif
  150. /* Remove IrDA packet type (stop receiving packets) */
  151. dev_remove_pack(&irda_packet_type);
  152. /* Remove higher layers */
  153. irsock_cleanup();
  154. irttp_cleanup();
  155. iriap_cleanup();
  156. /* Remove lower layers */
  157. irda_device_cleanup();
  158. irlap_cleanup(); /* Must be done before irlmp_cleanup()! DB */
  159. /* Remove middle layer */
  160. irlmp_cleanup();
  161. }
  162. /*
  163. * The IrDA stack must be initialised *before* drivers get initialised,
  164. * and *before* higher protocols (IrLAN/IrCOMM/IrNET) get initialised,
  165. * otherwise bad things will happen (hashbins will be NULL for example).
  166. * Those modules are at module_init()/device_initcall() level.
  167. *
  168. * On the other hand, it needs to be initialised *after* the basic
  169. * networking, the /proc/net filesystem and sysctl module. Those are
  170. * currently initialised in .../init/main.c (before initcalls).
  171. * Also, IrDA drivers needs to be initialised *after* the random number
  172. * generator (main stack and higher layer init don't need it anymore).
  173. *
  174. * Jean II
  175. */
  176. subsys_initcall(irda_init);
  177. module_exit(irda_cleanup);
  178. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no> & Jean Tourrilhes <jt@hpl.hp.com>");
  179. MODULE_DESCRIPTION("The Linux IrDA Protocol Stack");
  180. MODULE_LICENSE("GPL");
  181. MODULE_ALIAS_NETPROTO(PF_IRDA);