| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <linux/kernel.h> |
| 30 |
#include <linux/slab.h> |
| 31 |
#include <linux/errno.h> |
| 32 |
#include <linux/module.h> |
| 33 |
#include <linux/init.h> |
| 34 |
#include <linux/ctype.h> |
| 35 |
#include <linux/moduleparam.h> |
| 36 |
|
| 37 |
#include <dahdi/kernel.h> |
| 38 |
|
| 39 |
static int debug; |
| 40 |
|
| 41 |
static int echo_can_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, |
| 42 |
struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec); |
| 43 |
static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec); |
| 44 |
static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size); |
| 45 |
static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val); |
| 46 |
static const char *name = "JPAH"; |
| 47 |
static const char *ec_name(const struct dahdi_chan *chan) { return name; } |
| 48 |
|
| 49 |
static const struct dahdi_echocan_factory my_factory = { |
| 50 |
.get_name = ec_name, |
| 51 |
.owner = THIS_MODULE, |
| 52 |
.echocan_create = echo_can_create, |
| 53 |
}; |
| 54 |
|
| 55 |
static const struct dahdi_echocan_ops my_ops = { |
| 56 |
.echocan_free = echo_can_free, |
| 57 |
.echocan_process = echo_can_process, |
| 58 |
.echocan_traintap = echo_can_traintap, |
| 59 |
}; |
| 60 |
|
| 61 |
struct ec_pvt { |
| 62 |
struct dahdi_echocan_state dahdi; |
| 63 |
int blah; |
| 64 |
}; |
| 65 |
|
| 66 |
#define dahdi_to_pvt(a) container_of(a, struct ec_pvt, dahdi) |
| 67 |
|
| 68 |
static int echo_can_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, |
| 69 |
struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec) |
| 70 |
{ |
| 71 |
struct ec_pvt *pvt; |
| 72 |
|
| 73 |
if (ecp->param_count > 0) { |
| 74 |
printk(KERN_WARNING "JPAH does not support parameters; failing request\n"); |
| 75 |
return -EINVAL; |
| 76 |
} |
| 77 |
|
| 78 |
pvt = kzalloc(sizeof(*pvt), GFP_KERNEL); |
| 79 |
if (!pvt) |
| 80 |
return -ENOMEM; |
| 81 |
|
| 82 |
pvt->dahdi.ops = &my_ops; |
| 83 |
|
| 84 |
*ec = &pvt->dahdi; |
| 85 |
return 0; |
| 86 |
} |
| 87 |
|
| 88 |
static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec) |
| 89 |
{ |
| 90 |
struct ec_pvt *pvt = dahdi_to_pvt(ec); |
| 91 |
|
| 92 |
kfree(pvt); |
| 93 |
} |
| 94 |
|
| 95 |
static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size) |
| 96 |
{ |
| 97 |
struct ec_pvt *pvt = dahdi_to_pvt(ec); |
| 98 |
u32 x; |
| 99 |
|
| 100 |
for (x = 0; x < size; x++) { |
| 101 |
if (pvt->blah < 2) { |
| 102 |
pvt->blah++; |
| 103 |
|
| 104 |
*isig++ = 0; |
| 105 |
} else { |
| 106 |
pvt->blah = 0; |
| 107 |
|
| 108 |
isig++; |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val) |
| 114 |
{ |
| 115 |
return 0; |
| 116 |
} |
| 117 |
|
| 118 |
static int __init mod_init(void) |
| 119 |
{ |
| 120 |
if (dahdi_register_echocan_factory(&my_factory)) { |
| 121 |
module_printk(KERN_ERR, "could not register with DAHDI core\n"); |
| 122 |
|
| 123 |
return -EPERM; |
| 124 |
} |
| 125 |
|
| 126 |
module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n", |
| 127 |
my_factory.get_name(NULL)); |
| 128 |
|
| 129 |
return 0; |
| 130 |
} |
| 131 |
|
| 132 |
static void __exit mod_exit(void) |
| 133 |
{ |
| 134 |
dahdi_unregister_echocan_factory(&my_factory); |
| 135 |
} |
| 136 |
|
| 137 |
module_param(debug, int, S_IRUGO | S_IWUSR); |
| 138 |
|
| 139 |
MODULE_DESCRIPTION("DAHDI Jason Parker Audio Hoser"); |
| 140 |
MODULE_AUTHOR("Jason Parker <[email protected]>"); |
| 141 |
MODULE_LICENSE("GPL v2"); |
| 142 |
|
| 143 |
module_init(mod_init); |
| 144 |
module_exit(mod_exit); |