Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/kernel.h> |
| 15 | |
| 16 | #include "isdn_divert.h" |
| 17 | |
| 18 | MODULE_DESCRIPTION("ISDN4Linux: Call diversion support"); |
| 19 | MODULE_AUTHOR("Werner Cornelius"); |
| 20 | MODULE_LICENSE("GPL"); |
| 21 | |
| 22 | /****************************************/ |
| 23 | /* structure containing interface to hl */ |
| 24 | /****************************************/ |
Tilman Schmidt | 03f1828 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 25 | isdn_divert_if divert_if = { |
| 26 | DIVERT_IF_MAGIC, /* magic value */ |
| 27 | DIVERT_CMD_REG, /* register cmd */ |
| 28 | ll_callback, /* callback routine from ll */ |
| 29 | NULL, /* command still not specified */ |
| 30 | NULL, /* drv_to_name */ |
| 31 | NULL, /* name_to_drv */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 32 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /*************************/ |
| 35 | /* Module interface code */ |
| 36 | /* no cmd line parms */ |
| 37 | /*************************/ |
| 38 | static int __init divert_init(void) |
Tilman Schmidt | 03f1828 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 39 | { |
| 40 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Tilman Schmidt | 03f1828 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 42 | if (divert_dev_init()) { |
| 43 | printk(KERN_WARNING "dss1_divert: cannot install device, not loaded\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 44 | return (-EIO); |
| 45 | } |
Tilman Schmidt | 03f1828 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 46 | if ((i = DIVERT_REG_NAME(&divert_if)) != DIVERT_NO_ERR) { |
| 47 | divert_dev_deinit(); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 48 | printk(KERN_WARNING "dss1_divert: error %d registering module, not loaded\n", i); |
| 49 | return (-EIO); |
| 50 | } |
| 51 | printk(KERN_INFO "dss1_divert module successfully installed\n"); |
| 52 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /**********************/ |
| 56 | /* Module deinit code */ |
| 57 | /**********************/ |
| 58 | static void __exit divert_exit(void) |
| 59 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 60 | unsigned long flags; |
| 61 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 63 | spin_lock_irqsave(&divert_lock, flags); |
| 64 | divert_if.cmd = DIVERT_CMD_REL; /* release */ |
Tilman Schmidt | 03f1828 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 65 | if ((i = DIVERT_REG_NAME(&divert_if)) != DIVERT_NO_ERR) { |
| 66 | printk(KERN_WARNING "dss1_divert: error %d releasing module\n", i); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 67 | spin_unlock_irqrestore(&divert_lock, flags); |
| 68 | return; |
| 69 | } |
Tilman Schmidt | 03f1828 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 70 | if (divert_dev_deinit()) { |
| 71 | printk(KERN_WARNING "dss1_divert: device busy, remove cancelled\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 72 | spin_unlock_irqrestore(&divert_lock, flags); |
| 73 | return; |
| 74 | } |
| 75 | spin_unlock_irqrestore(&divert_lock, flags); |
| 76 | deleterule(-1); /* delete all rules and free mem */ |
| 77 | deleteprocs(); |
| 78 | printk(KERN_INFO "dss1_divert module successfully removed \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | module_init(divert_init); |
| 82 | module_exit(divert_exit); |