divert_init.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* $Id divert_init.c,v 1.5.6.2 2001/01/24 22:18:17 kai Exp $
  2. *
  3. * Module init for DSS1 diversion services for i4l.
  4. *
  5. * Copyright 1999 by Werner Cornelius (werner@isdn4linux.de)
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include "isdn_divert.h"
  15. MODULE_DESCRIPTION("ISDN4Linux: Call diversion support");
  16. MODULE_AUTHOR("Werner Cornelius");
  17. MODULE_LICENSE("GPL");
  18. /****************************************/
  19. /* structure containing interface to hl */
  20. /****************************************/
  21. isdn_divert_if divert_if = {
  22. DIVERT_IF_MAGIC, /* magic value */
  23. DIVERT_CMD_REG, /* register cmd */
  24. ll_callback, /* callback routine from ll */
  25. NULL, /* command still not specified */
  26. NULL, /* drv_to_name */
  27. NULL, /* name_to_drv */
  28. };
  29. /*************************/
  30. /* Module interface code */
  31. /* no cmd line parms */
  32. /*************************/
  33. static int __init divert_init(void)
  34. {
  35. int i;
  36. if (divert_dev_init()) {
  37. printk(KERN_WARNING "dss1_divert: cannot install device, not loaded\n");
  38. return (-EIO);
  39. }
  40. if ((i = DIVERT_REG_NAME(&divert_if)) != DIVERT_NO_ERR) {
  41. divert_dev_deinit();
  42. printk(KERN_WARNING "dss1_divert: error %d registering module, not loaded\n", i);
  43. return (-EIO);
  44. }
  45. printk(KERN_INFO "dss1_divert module successfully installed\n");
  46. return (0);
  47. }
  48. /**********************/
  49. /* Module deinit code */
  50. /**********************/
  51. static void __exit divert_exit(void)
  52. {
  53. unsigned long flags;
  54. int i;
  55. spin_lock_irqsave(&divert_lock, flags);
  56. divert_if.cmd = DIVERT_CMD_REL; /* release */
  57. if ((i = DIVERT_REG_NAME(&divert_if)) != DIVERT_NO_ERR) {
  58. printk(KERN_WARNING "dss1_divert: error %d releasing module\n", i);
  59. spin_unlock_irqrestore(&divert_lock, flags);
  60. return;
  61. }
  62. if (divert_dev_deinit()) {
  63. printk(KERN_WARNING "dss1_divert: device busy, remove cancelled\n");
  64. spin_unlock_irqrestore(&divert_lock, flags);
  65. return;
  66. }
  67. spin_unlock_irqrestore(&divert_lock, flags);
  68. deleterule(-1); /* delete all rules and free mem */
  69. deleteprocs();
  70. printk(KERN_INFO "dss1_divert module successfully removed \n");
  71. }
  72. module_init(divert_init);
  73. module_exit(divert_exit);