[zaptel-commits] file: trunk r1374 - in /trunk: zaptel.c zaptel.h

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Wed Aug 30 18:41:31 MST 2006


Author: file
Date: Wed Aug 30 20:41:30 2006
New Revision: 1374

URL: http://svn.digium.com/view/zaptel?rev=1374&view=rev
Log:
Merge in Zaptel VLDTMF support. This does currently have the bug where dialtone briefly returns after a digit is being played, but that will be fixed shortly.

Modified:
    trunk/zaptel.c
    trunk/zaptel.h

Modified: trunk/zaptel.c
URL: http://svn.digium.com/view/zaptel/trunk/zaptel.c?rev=1374&r1=1373&r2=1374&view=diff
==============================================================================
--- trunk/zaptel.c (original)
+++ trunk/zaptel.c Wed Aug 30 20:41:30 2006
@@ -337,6 +337,9 @@
 #define DIGIT_MODE_PULSE	2
 
 #include "digits.h"
+
+static struct zt_tone *dtmf_tones_continuous = NULL;
+static struct zt_tone *mfv1_tones_continuous = NULL;
 
 static int zt_chan_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data, int unit);
 
@@ -1104,28 +1107,44 @@
 static int start_tone(struct zt_chan *chan, int tone)
 {
 	int res = -EINVAL;
+
 	/* Stop the current tone, no matter what */
 	chan->tonep = 0;
 	chan->curtone = NULL;
 	chan->pdialcount = 0;
 	chan->txdialbuf[0] = '\0';
-	chan->dialing =  0;
-	if ((tone >= ZT_TONE_MAX) || (tone < -1)) 
-		return -EINVAL;
-	/* Just wanted to stop the tone anyway */
-	if (tone < 0)
-		return 0;
-	if (chan->curzone) {
-		/* Have a tone zone */
-		if (chan->curzone->tones[tone]) {
-			chan->curtone = chan->curzone->tones[tone];
-			res = 0;
-		} else	/* Indicate that zone is loaded but no such tone exists */
-			res = -ENOSYS;
-	} else	/* Note that no tone zone exists at the moment */
-		res = -ENODATA;
+	chan->dialing = 0;
+
+	if (tone == -1) {
+		/* Just stop the current tone */
+		res = 0;
+	} else if ((tone >= 0 && tone <= ZT_TONE_MAX)) {
+		if (chan->curzone) {
+			/* Have a tone zone */
+			if (chan->curzone->tones[tone]) {
+				chan->curtone = chan->curzone->tones[tone];
+				res = 0;
+			} else	/* Indicate that zone is loaded but no such tone exists */
+				res = -ENOSYS;
+		} else	/* Note that no tone zone exists at the moment */
+			res = -ENODATA;
+	} else if (tone >= ZT_TONE_DTMF_BASE && tone <= ZT_TONE_DTMF_MAX) {
+		/* ZT_SENDTONE should never be used on a channel configured for pulse dialing */
+		chan->dialing = 1;
+		res = 0;
+		if (chan->digitmode == DIGIT_MODE_DTMF)
+			chan->curtone = dtmf_tones_continuous + (tone - ZT_TONE_DTMF_BASE);
+		else if (chan->digitmode == DIGIT_MODE_MFV1 && tone != ZT_TONE_DTMF_MAX) /* No 'D' */
+			chan->curtone = mfv1_tones_continuous + (tone - ZT_TONE_DTMF_BASE);
+		else {
+			chan->dialing = 0;
+			res = -EINVAL;
+		}
+	}
+
 	if (chan->curtone)
 		zt_init_tone_state(&chan->ts, chan->curtone);
+	
 	return res;
 }
 
@@ -6894,6 +6913,7 @@
 
 static int __init zt_init(void) {
 	int res = 0;
+	int i = 0;
 
 #ifdef CONFIG_PROC_FS
 	proc_entries[0] = proc_mkdir("zaptel", NULL);
@@ -6926,6 +6946,26 @@
 		return res;
 	}
 #endif /* CONFIG_DEVFS_FS */
+
+	if (!(dtmf_tones_continuous = kmalloc(sizeof(dtmf_tones), GFP_KERNEL))) {
+		printk(KERN_ERR "Zaptel: THERE IS A CRISIS IN THE BATCAVE!"
+			" Unable to allocate memory for continuous DTMF tones list!\n");
+		return -ENOMEM;
+	}
+
+	if (!(mfv1_tones_continuous = kmalloc(sizeof(mfv1_tones), GFP_KERNEL))) {
+		printk(KERN_ERR "Zaptel: THERE IS A CRISIS IN THE BATCAVE!"
+			" Unable to allocate memory for continuous MFV1 tones list!\n");
+		return -ENOMEM;
+	}
+
+	memcpy(dtmf_tones_continuous, dtmf_tones, sizeof(dtmf_tones));
+	for (i = 0; i < (sizeof(dtmf_tones) / sizeof(dtmf_tones[0])); i++)
+		dtmf_tones_continuous[i].next = dtmf_tones_continuous + i;
+
+	memcpy(mfv1_tones_continuous, mfv1_tones, sizeof(mfv1_tones));
+	for (i = 0; i < (sizeof(mfv1_tones) / sizeof(mfv1_tones[0])); i++)
+		mfv1_tones_continuous[i].next = mfv1_tones_continuous + i;
 
 	printk(KERN_INFO "Zapata Telephony Interface Registered on major %d\n", ZT_MAJOR);
 	printk(KERN_INFO "Zaptel Version: %s Echo Canceller: %s\n", ZAPTEL_VERSION,
@@ -6949,9 +6989,21 @@
 #endif
 
 	printk(KERN_INFO "Zapata Telephony Interface Unloaded\n");
-	for (x=0;x<ZT_TONE_ZONE_MAX;x++)
+	for (x = 0; x < ZT_TONE_ZONE_MAX; x++) {
 		if (tone_zones[x])
 			kfree(tone_zones[x]);
+	}
+
+	if (dtmf_tones_continuous) {
+		kfree(dtmf_tones_continuous);
+		dtmf_tones_continuous = NULL;
+	}
+
+	if (mfv1_tones_continuous) {
+		kfree(mfv1_tones_continuous);
+		mfv1_tones_continuous = NULL;
+	}
+
 #ifdef CONFIG_DEVFS_FS
 	devfs_unregister(timer);
 	devfs_unregister(transcode);

Modified: trunk/zaptel.h
URL: http://svn.digium.com/view/zaptel/trunk/zaptel.h?rev=1374&r1=1373&r2=1374&view=diff
==============================================================================
--- trunk/zaptel.h (original)
+++ trunk/zaptel.h Wed Aug 30 20:41:30 2006
@@ -673,6 +673,32 @@
 #define ZT_TONE_CUST2		9
 #define ZT_TONE_STUTTER		10
 #define ZT_TONE_MAX		16
+
+#define ZT_TONE_DTMF_BASE	64
+
+/*
+ * These must be in the same order as the dtmf_tones array in tones.h 
+ */
+enum {
+	ZT_TONE_DTMF_0 = ZT_TONE_DTMF_BASE,
+	ZT_TONE_DTMF_1,
+	ZT_TONE_DTMF_2,
+	ZT_TONE_DTMF_3,
+	ZT_TONE_DTMF_4,
+	ZT_TONE_DTMF_5,
+	ZT_TONE_DTMF_6,
+	ZT_TONE_DTMF_7,
+	ZT_TONE_DTMF_8,
+	ZT_TONE_DTMF_9,
+	ZT_TONE_DTMF_s,
+	ZT_TONE_DTMF_p,
+	ZT_TONE_DTMF_A,
+	ZT_TONE_DTMF_B,
+	ZT_TONE_DTMF_C,
+	ZT_TONE_DTMF_D
+};
+
+#define ZT_TONE_DTMF_MAX ZT_TONE_DTMF_D
 
 #define ZT_MAX_CADENCE		16
 



More information about the zaptel-commits mailing list