divert_init.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/version.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include "isdn_divert.h"
  16. MODULE_DESCRIPTION("ISDN4Linux: Call diversion support");
  17. MODULE_AUTHOR("Werner Cornelius");
  18. MODULE_LICENSE("GPL");
  19. /****************************************/
  20. /* structure containing interface to hl */
  21. /****************************************/
  22. isdn_divert_if divert_if =
  23. { DIVERT_IF_MAGIC, /* magic value */
  24. DIVERT_CMD_REG, /* register cmd */
  25. ll_callback, /* callback routine from ll */
  26. NULL, /* command still not specified */
  27. NULL, /* drv_to_name */
  28. NULL, /* name_to_drv */
  29. };
  30. /*************************/
  31. /* Module interface code */
  32. /* no cmd line parms */
  33. /*************************/
  34. static int __init divert_init(void)
  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);