irmod.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. /* Packet type handler.
  42. * Tell the kernel how IrDA packets should be handled.
  43. */
  44. static struct packet_type irda_packet_type __read_mostly = {
  45. .type = cpu_to_be16(ETH_P_IRDA),
  46. .func = irlap_driver_rcv, /* Packet type handler irlap_frame.c */
  47. };
  48. /*
  49. * Function irda_notify_init (notify)
  50. *
  51. * Used for initializing the notify structure
  52. *
  53. */
  54. void irda_notify_init(notify_t *notify)
  55. {
  56. notify->data_indication = NULL;
  57. notify->udata_indication = NULL;
  58. notify->connect_confirm = NULL;
  59. notify->connect_indication = NULL;
  60. notify->disconnect_indication = NULL;
  61. notify->flow_indication = NULL;
  62. notify->status_indication = NULL;
  63. notify->instance = NULL;
  64. strlcpy(notify->name, "Unknown", sizeof(notify->name));
  65. }
  66. EXPORT_SYMBOL(irda_notify_init);
  67. /*
  68. * Function irda_init (void)
  69. *
  70. * Protocol stack initialisation entry point.
  71. * Initialise the various components of the IrDA stack
  72. */
  73. static int __init irda_init(void)
  74. {
  75. int ret = 0;
  76. /* Lower layer of the stack */
  77. irlmp_init();
  78. irlap_init();
  79. /* Driver/dongle support */
  80. irda_device_init();
  81. /* Higher layers of the stack */
  82. iriap_init();
  83. irttp_init();
  84. ret = irsock_init();
  85. if (ret < 0)
  86. goto out_err_1;
  87. /* Add IrDA packet type (Start receiving packets) */
  88. dev_add_pack(&irda_packet_type);
  89. /* External APIs */
  90. #ifdef CONFIG_PROC_FS
  91. irda_proc_register();
  92. #endif
  93. #ifdef CONFIG_SYSCTL
  94. ret = irda_sysctl_register();
  95. if (ret < 0)
  96. goto out_err_2;
  97. #endif
  98. ret = irda_nl_register();
  99. if (ret < 0)
  100. goto out_err_3;
  101. return 0;
  102. out_err_3:
  103. #ifdef CONFIG_SYSCTL
  104. irda_sysctl_unregister();
  105. out_err_2:
  106. #endif
  107. #ifdef CONFIG_PROC_FS
  108. irda_proc_unregister();
  109. #endif
  110. /* Remove IrDA packet type (stop receiving packets) */
  111. dev_remove_pack(&irda_packet_type);
  112. /* Remove higher layers */
  113. irsock_cleanup();
  114. out_err_1:
  115. irttp_cleanup();
  116. iriap_cleanup();
  117. /* Remove lower layers */
  118. irda_device_cleanup();
  119. irlap_cleanup(); /* Must be done before irlmp_cleanup()! DB */
  120. /* Remove middle layer */
  121. irlmp_cleanup();
  122. return ret;
  123. }
  124. /*
  125. * Function irda_cleanup (void)
  126. *
  127. * Protocol stack cleanup/removal entry point.
  128. * Cleanup the various components of the IrDA stack
  129. */
  130. static void __exit irda_cleanup(void)
  131. {
  132. /* Remove External APIs */
  133. irda_nl_unregister();
  134. #ifdef CONFIG_SYSCTL
  135. irda_sysctl_unregister();
  136. #endif
  137. #ifdef CONFIG_PROC_FS
  138. irda_proc_unregister();
  139. #endif
  140. /* Remove IrDA packet type (stop receiving packets) */
  141. dev_remove_pack(&irda_packet_type);
  142. /* Remove higher layers */
  143. irsock_cleanup();
  144. irttp_cleanup();
  145. iriap_cleanup();
  146. /* Remove lower layers */
  147. irda_device_cleanup();
  148. irlap_cleanup(); /* Must be done before irlmp_cleanup()! DB */
  149. /* Remove middle layer */
  150. irlmp_cleanup();
  151. }
  152. /*
  153. * The IrDA stack must be initialised *before* drivers get initialised,
  154. * and *before* higher protocols (IrLAN/IrCOMM/IrNET) get initialised,
  155. * otherwise bad things will happen (hashbins will be NULL for example).
  156. * Those modules are at module_init()/device_initcall() level.
  157. *
  158. * On the other hand, it needs to be initialised *after* the basic
  159. * networking, the /proc/net filesystem and sysctl module. Those are
  160. * currently initialised in .../init/main.c (before initcalls).
  161. * Also, IrDA drivers needs to be initialised *after* the random number
  162. * generator (main stack and higher layer init don't need it anymore).
  163. *
  164. * Jean II
  165. */
  166. subsys_initcall(irda_init);
  167. module_exit(irda_cleanup);
  168. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no> & Jean Tourrilhes <jt@hpl.hp.com>");
  169. MODULE_DESCRIPTION("The Linux IrDA Protocol Stack");
  170. MODULE_LICENSE("GPL");
  171. MODULE_ALIAS_NETPROTO(PF_IRDA);