Index: kernel/wctdm.c
===================================================================
--- kernel/wctdm.c	(revision 4618)
+++ kernel/wctdm.c	(working copy)
@@ -228,6 +228,8 @@
 		        int lastpol;
 		        int polarity;
 		        int polaritydebounce;
+			int readcid;
+			unsigned int cidtimer;
 		} fxo;
 		struct fxs {
 			int oldrxhook;
@@ -291,6 +293,7 @@
 static int fxorxgain = 0;
 static int fxstxgain = 0;
 static int fxsrxgain = 0;
+static int dtmf = 0;
 
 static int wctdm_init_proslic(struct wctdm *wc, int card, int fast , int manual, int sane);
 
@@ -383,6 +386,31 @@
 	}
 }
 #endif
+
+static inline void wctdm_dtmfcheck_fakepolarity(struct wctdm *wc, int card, int x) 
+{
+	int sample;
+    /* only look for sound on the line if dtmf flag is on, it is an fxo card and line is onhook */ 
+	if (!dtmf || !(wc->cardflag & (1 << card)) || !(wc->modtype[card] == MOD_TYPE_FXO) || wc->mod[card].fxo.offhook ) 
+        return;
+
+    /* don't look for noise if we're already processing it, or there is a ringing tone */
+	if(!wc->mod[card].fxo.readcid && !wc->mod[card].fxo.wasringing  &&
+		wc->intcount > wc->mod[card].fxo.cidtimer + 400 ) {
+		sample = ZT_XLAW(wc->chans[card].readchunk[x], (&(wc->chans[card])));
+		if (sample > 2000 || sample < -2000) {
+			wc->mod[card].fxo.readcid = 1;
+			wc->mod[card].fxo.cidtimer = wc->intcount;
+			if (debug) printk("DTMF CLIP on %i\n",card+1);
+			zt_qevent_lock(&wc->chans[card], ZT_EVENT_POLARITY);
+		}
+	} else if(wc->mod[card].fxo.readcid && wc->intcount > wc->mod[card].fxo.cidtimer + 2000) {
+        /* reset flags if it's been a while */
+		wc->mod[card].fxo.cidtimer = wc->intcount;
+		wc->mod[card].fxo.readcid = 0;
+	}
+}
+ 
 static inline void wctdm_receiveprep(struct wctdm *wc, unsigned char ints)
 {
 	volatile unsigned int *readchunk;
@@ -397,21 +425,29 @@
 #ifdef __BIG_ENDIAN
 		if (wc->cardflag & (1 << 3))
 			wc->chans[3].readchunk[x] = (readchunk[x]) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 3, x);
 		if (wc->cardflag & (1 << 2))
 			wc->chans[2].readchunk[x] = (readchunk[x] >> 8) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 2, x);
 		if (wc->cardflag & (1 << 1))
 			wc->chans[1].readchunk[x] = (readchunk[x] >> 16) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 1, x);
 		if (wc->cardflag & (1 << 0))
 			wc->chans[0].readchunk[x] = (readchunk[x] >> 24) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 0, x);
 #else
 		if (wc->cardflag & (1 << 3))
 			wc->chans[3].readchunk[x] = (readchunk[x] >> 24) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 3, x);
 		if (wc->cardflag & (1 << 2))
 			wc->chans[2].readchunk[x] = (readchunk[x] >> 16) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 2, x);
 		if (wc->cardflag & (1 << 1))
 			wc->chans[1].readchunk[x] = (readchunk[x] >> 8) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 1, x);
 		if (wc->cardflag & (1 << 0))
 			wc->chans[0].readchunk[x] = (readchunk[x]) & 0xff;
+		wctdm_dtmfcheck_fakepolarity(wc, 0, x);
 #endif
 	}
 #ifdef AUDIO_RINGCHECK
@@ -778,6 +814,8 @@
 				    (fxo->battery == BATTERY_PRESENT)) {
 					if (!fxo->wasringing) {
 						fxo->wasringing = 1;
+						fxo->readcid = 0;
+						fxo->cidtimer = wc->intcount;
 						if (debug)
 							printk("RING on %d/%d!\n", wc->span.spanno, card + 1);
 						zt_hooksig(&wc->chans[card], ZT_RXSIG_RING);
@@ -787,6 +825,8 @@
 				} else if (!res) {
 					if ((fxo->ringdebounce == 0) && fxo->wasringing) {
 						fxo->wasringing = 0;
+ 						fxo->readcid = 0;
+ 						fxo->cidtimer = wc->intcount;
 						if (debug)
 							printk("NO RING on %d/%d!\n", wc->span.spanno, card + 1);
 						zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
@@ -803,6 +843,8 @@
 				if (fxo->ringdebounce >= ZT_CHUNKSIZE * ringdebounce) {
 					if (!fxo->wasringing) {
 						fxo->wasringing = 1;
+						fxo->readcid = 0;
+						fxo->cidtimer = wc->intcount;
 						zt_hooksig(&wc->chans[card], ZT_RXSIG_RING);
 						if (debug)
 							printk("RING on %d/%d!\n", wc->span.spanno, card + 1);
@@ -814,6 +856,8 @@
 				if (fxo->ringdebounce <= 0) {
 					if (fxo->wasringing) {
 						fxo->wasringing = 0;
+						fxo->readcid = 0;
+						fxo->cidtimer = wc->intcount;
 						zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
 						if (debug)
 							printk("NO RING on %d/%d!\n", wc->span.spanno, card + 1);
@@ -2523,6 +2567,7 @@
 module_param(fxorxgain, int, 0600);
 module_param(fxstxgain, int, 0600);
 module_param(fxsrxgain, int, 0600);
+module_param(dtmf, int, 0600);
 #else
 MODULE_PARM(debug, "i");
 MODULE_PARM(loopcurrent, "i");
Index: kernel/wctdm24xxp/wctdm24xxp.h
===================================================================
--- kernel/wctdm24xxp/wctdm24xxp.h	(revision 4618)
+++ kernel/wctdm24xxp/wctdm24xxp.h	(working copy)
@@ -233,6 +233,8 @@
 			int lastpol;
 			int polarity;
 			int polaritydebounce;
+			int readcid;
+			unsigned int cidtimer;
 			int neonmwi_state;
 			int neonmwi_last_voltage;
 			unsigned int neonmwi_debounce;
Index: kernel/wctdm24xxp/base.c
===================================================================
--- kernel/wctdm24xxp/base.c	(revision 4618)
+++ kernel/wctdm24xxp/base.c	(working copy)
@@ -228,6 +228,7 @@
 /* See vpmnlptype = 4 for more info */
 static int vpmnlpmaxsupp = 0;
 #endif
+static int dtmf = 0;
 
 static int wctdm_init_proslic(struct wctdm *wc, int card, int fast , int manual, int sane);
 
@@ -856,6 +857,30 @@
 #endif
 }
 
+static inline void wctdm_dtmfcheck_fakepolarity(struct wctdm *wc, int card, int x) 
+{
+	int sample;
+    /* only look for sound on the line if dtmf flag is on, it is an fxo card and line is onhook */ 
+	if (!dtmf || !(wc->cardflag & (1 << card)) || !(wc->modtype[card] == MOD_TYPE_FXO) || wc->mods[card].fxo.offhook ) 
+        return;
+
+    /* don't look for noise if we're already processing it, or there is a ringing tone */
+	if (!wc->mods[card].fxo.readcid && !wc->mods[card].fxo.wasringing  &&
+		 wc->intcount > wc->mods[card].fxo.cidtimer + 400 ) {
+		sample = ZT_XLAW(wc->chans[card].readchunk[x], (&(wc->chans[card])));
+		if (sample > 2000 || sample < -2000) {
+			wc->mods[card].fxo.readcid = 1;
+			wc->mods[card].fxo.cidtimer = wc->intcount;
+			if (debug) printk("DTMF CLIP on %i\n",card+1);
+			zt_qevent_lock(&wc->chans[card], ZT_EVENT_POLARITY);
+		}
+	} else if (wc->mods[card].fxo.readcid && wc->intcount > wc->mods[card].fxo.cidtimer + 2000) {
+        /* reset flags if it's been a while */
+		wc->mods[card].fxo.cidtimer = wc->intcount;
+		wc->mods[card].fxo.readcid = 0;
+	}
+}
+ 
 static inline void wctdm_receiveprep(struct wctdm *wc, unsigned char *readchunk)
 {
 	int x,y;
@@ -879,6 +904,7 @@
 				}
 			}	
 			cmd_decifer(wc, readchunk, y);
+			wctdm_dtmfcheck_fakepolarity(wc,y,x);
 		}
 #ifdef VPM_SUPPORT
 		if (wc->vpm) {
@@ -1200,6 +1226,8 @@
 					fxo->ringdebounce = ringdebounce / 16;
 				} else if (--fxo->ringdebounce == 0) {
 					fxo->wasringing = 0;
+					fxo->readcid = 0;
+					fxo->cidtimer = wc->intcount;
 					if (debug)
 						printk("FW NO RING on %d/%d!\n", wc->span.spanno, card + 1);
 					zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
@@ -1223,6 +1251,8 @@
 				if (fxo->ringdebounce <= 0) {
 					if (fxo->wasringing) {
 						fxo->wasringing = 0;
+						fxo->readcid = 0;
+						fxo->cidtimer = wc->intcount;
 						zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
 						if (debug)
 							printk("NO RING on %d/%d!\n", wc->span.spanno, card + 1);
@@ -4105,6 +4135,7 @@
 module_param(fxsrxgain, int, 0600);
 module_param(ringdebounce, int, 0600);
 module_param(fwringdetect, int, 0600);
+module_param(dtmf, int, 0600);
 module_param(latency, int, 0600);
 module_param(neonmwi_monitor, int, 0600);
 module_param(neonmwi_level, int, 0600);
