Upgrade 3CX to v18 and get it hosted free!

chan_ss7 HWDTMF patch

Author image
diff -u -r chan_ss7-1.1/l4isup.c chan_ss7-1.1-hwdtmf/l4isup.c
--- chan_ss7-1.1/l4isup.c	2008-12-05 13:50:47.000000000 +0100
+++ chan_ss7-1.1-hwdtmf/l4isup.c	2009-05-21 23:34:59.000000000 +0200
@@ -58,6 +58,12 @@
 #include "asterisk/alaw.h"
 #include "asterisk/ulaw.h"
 
+#ifndef DAHDI_TONEDETECT
+/* Work around older code with no tone detect */
+#define DAHDI_EVENT_DTMFDOWN 0
+#define DAHDI_EVENT_DTMFUP 0
+#endif
+
 #ifdef DAHDI
 #include <dahdi/user.h>
 #else
@@ -69,6 +75,12 @@
 #define DAHDI_LAW_MULAW ZT_LAW_MULAW
 #define DAHDI_SETGAINS ZT_SETGAINS
 #define dahdi_gains zt_gains
+#define DAHDI_TONEDETECT ZT_TONEDETECT
+#define DAHDI_TONEDETECT_ON ZT_TONEDETECT_ON
+#define DAHDI_TONEDETECT_MUTE ZT_TONEDETECT_MUTE
+#define DAHDI_EVENT_DTMFDOWN ZT_EVENT_DTMFDOWN 
+#define DAHDI_EVENT_DTMFDUP ZT_EVENT_DTMFUP 
+
 #endif
 
 #include "astversion.h"
@@ -169,6 +181,8 @@
   int law;
   char context[AST_MAX_CONTEXT];
   char language[MAX_LANGUAGE];
+  unsigned int hardwaredtmf:1;
+
 };
 
 /*   Locking order (deadlock avoidance): global lock, chan->lock, pvt->lock
@@ -2164,6 +2178,22 @@
 static void ss7_handle_event(struct ss7_chan *pvt, int event) {
   int res, doing_dtmf;
 
+       if(event & DAHDI_EVENT_DTMFDOWN ) {
+			pvt->frame.frametype = AST_FRAME_DTMF_BEGIN;
+			pvt->frame.sub & 0xff;
+			return ;
+       
+       }
+       
+       if(event &  DAHDI_EVENT_DTMFUP ) {
+		pvt->frame.frametype = AST_FRAME_DTMF_END;
+		pvt->frame.sub & 0xff;
+		return;
+		
+       }
+
+
+
   switch(event) {
   case DAHDI_EVENT_DIALCOMPLETE:
     /* Chech if still doing DTMF sending. If not, set flag to start
@@ -2305,7 +2335,13 @@
 #endif
   pvt->frame.datalen = sofar;
   pvt->frame.samples = sofar;
-  processed_frame = ast_dsp_process(chan, pvt->dsp, &pvt->frame);
+
+   if(pvt->dsp){
+	  	processed_frame = ast_dsp_process(chan, pvt->dsp, &pvt->frame);
+   } else {
+		/*Incase of HWDTF */
+		processed_frame = &pvt->frame;
+	}
 
   ast_mutex_unlock(&pvt->lock);
 
@@ -4463,6 +4499,7 @@
   int cic = link->first_cic + channel;
   char* lang = link->linkset->language;
   char* ctxt = link->linkset->context;
+  int features,x;
   struct ss7_chan *pvt;
 
   pvt = malloc(sizeof(*pvt));
@@ -4473,6 +4510,7 @@
   init_pvt(pvt, cic);
   pvt->link = link;
   pvt->equipped = 1;
+  features=0;
   if(ctxt != NULL) {
     ast_copy_string(pvt->context, ctxt, sizeof(pvt->context));
   }
@@ -4486,14 +4524,28 @@
   pvt->zaptel_fd = openchannel(link, channel);
   if (pvt->zaptel_fd < 0)
     return pvt->zaptel_fd < 0;
-  pvt->dsp = ast_dsp_new();
-  if(pvt->dsp == NULL) {
-    ast_log(LOG_WARNING, "Failed to allocate DSP for CIC=%d.\n", pvt->cic);
-    return -1;
-  }
-  ast_dsp_set_features(pvt->dsp, DSP_FEATURE_DTMF_DETECT);
-  ast_dsp_digitmode(pvt->dsp, DSP_DIGITMODE_DTMF | (link->relaxdtmf ? DSP_DIGITMODE_RELAXDTMF : 0));
+#ifdef DAHDI_TONEDETECT
+	x = DAHDI_TONEDETECT_ON | DAHDI_TONEDETECT_MUTE;
+	if (ioctl(pvt->zaptel_fd, DAHDI_TONEDETECT, &x)) {
+#endif		
+		pvt->hardwaredtmf = 0;
+		features |= DSP_FEATURE_DTMF_DETECT;
+#ifdef DAHDI_TONEDETECT
+	} else if (0) {
+		pvt->hardwaredtmf = 1;
+		features |= DSP_FEATURE_DTMF_DETECT;
+	}
+#endif
 
+  if(features){
+	pvt->dsp = ast_dsp_new();
+	if(pvt->dsp == NULL) {
+		ast_log(LOG_WARNING, "Failed to allocate DSP for CIC=%d.\n", pvt->cic);
+		return -1;
+	}
+	ast_dsp_set_features(pvt->dsp, DSP_FEATURE_DTMF_DETECT);
+	ast_dsp_digitmode(pvt->dsp, DSP_DIGITMODE_DTMF | (link->relaxdtmf ? DSP_DIGITMODE_RELAXDTMF : 0));
+  }
   /* Set gain - Channel must be in audiomode when setting gain */
   set_audiomode(pvt->zaptel_fd);
   set_gain(pvt, link->rxgain, link->txgain);


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.
Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.