[dahdi-commits] kpfleming: branch linux/kpfleming/modular_ec r4392 - /linux/team/kpfleming/mo...

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Wed Jun 18 11:28:40 CDT 2008


Author: kpfleming
Date: Wed Jun 18 11:16:37 2008
New Revision: 4392

URL: http://svn.digium.com/view/dahdi?view=rev&rev=4392
Log:
echocan modules can now register and unregister, and the DAHDI_GETVERSION ioctl will now return the list of all registered echo cancelers

Modified:
    linux/team/kpfleming/modular_ec/drivers/dahdi/dahdi-base.c

Modified: linux/team/kpfleming/modular_ec/drivers/dahdi/dahdi-base.c
URL: http://svn.digium.com/view/dahdi/linux/team/kpfleming/modular_ec/drivers/dahdi/dahdi-base.c?view=diff&rev=4392&r1=4391&r2=4392
==============================================================================
--- linux/team/kpfleming/modular_ec/drivers/dahdi/dahdi-base.c (original)
+++ linux/team/kpfleming/modular_ec/drivers/dahdi/dahdi-base.c Wed Jun 18 11:16:37 2008
@@ -47,6 +47,7 @@
 #include <linux/ctype.h>
 #include <linux/kmod.h>
 #include <linux/moduleparam.h>
+#include <linux/list.h>
 
 #ifdef CONFIG_DAHDI_NET
 #include <linux/netdevice.h>
@@ -349,19 +350,65 @@
 #include "jpah.h"
 #endif
 
+#ifdef DEFINE_RWLOCK
+static DEFINE_RWLOCK(echocan_list_lock);
+#else
+static rwlock_t echocan_list_lock = RW_LOCK_UNLOCKED;
+#endif
+
+LIST_HEAD(echocan_list);
+
 struct echocan {
 	const struct dahdi_echocan *ec;
 	struct module *owner;
-	struct echocan *next;
+	struct list_head list;
 };
 
 int dahdi_register_echocan(const struct dahdi_echocan *ec, struct module *owner)
 {
-	return -1;
+	struct echocan *cur;
+
+	write_lock(&echocan_list_lock);
+
+	/* make sure it isn't already registered */
+	list_for_each_entry(cur, &echocan_list, list) {
+		if (cur->ec == ec) {
+			write_unlock(&echocan_list_lock);
+			return -EPERM;
+		}
+	}
+
+	if (!(cur = kmalloc(sizeof(*cur), GFP_KERNEL))) {
+			write_unlock(&echocan_list_lock);
+		return -ENOMEM;
+	}
+
+	memset(cur, 0, sizeof(*cur));
+
+	cur->ec = ec;
+	cur->owner = owner;
+
+	list_add_tail(&echocan_list, &cur->list);
+
+	write_unlock(&echocan_list_lock);
+
+	return 0;
 }
 
 void dahdi_unregister_echocan(const struct dahdi_echocan *ec)
 {
+	struct echocan *cur, *next;
+
+	write_lock(&echocan_list_lock);
+
+	list_for_each_entry_safe(cur, next, &echocan_list, list) {
+		if (cur->ec == ec) {
+			list_del(&cur->list);
+			break;
+		}
+	}
+
+	write_unlock(&echocan_list_lock);
 }
 
 static inline void rotate_sums(void)
@@ -3782,10 +3829,27 @@
 	case DAHDI_GETVERSION:
 	{
 		struct dahdi_versioninfo vi;
+		struct echocan *cur;
+		size_t space = sizeof(vi.echo_canceller) - 1;
 
 		memset(&vi, 0, sizeof(vi));
 		dahdi_copy_string(vi.version, DAHDI_VERSION, sizeof(vi.version));
-		echo_can_identify(vi.echo_canceller, sizeof(vi.echo_canceller) - 1);
+		read_lock(&echocan_list_lock);
+		list_for_each_entry(cur, &echocan_list, list) {
+			strncat(vi.echo_canceller, cur->ec->name, space);
+			space -= strlen(cur->ec->name);
+			if (space < 1) {
+				break;
+			}
+			if (cur->list.next && (cur->list.next != &echocan_list)) {
+				strncat(vi.echo_canceller, ", ", space);
+				space -= 2;
+				if (space < 1) {
+					break;
+				}
+			}
+		}
+		read_unlock(&echocan_list_lock);
 		if (copy_to_user((struct dahdi_versioninfo *) data, &vi, sizeof(vi)))
 			return -EFAULT;
 		break;
@@ -7469,7 +7533,6 @@
 
 	printk(KERN_INFO "DAHDI Telephony Interface Registered on major %d\n", DAHDI_MAJOR);
 	printk(KERN_INFO "DAHDI Version: %s\n", DAHDI_VERSION);
-	echo_can_init();
 	dahdi_conv_init();
 	fasthdlc_precalc();
 	rotate_sums();




More information about the dahdi-commits mailing list