[Asterisk-Users] Caller ID with BT CD50

Tony Hoyle tmh at nodomain.org
Fri May 28 05:10:52 MST 2004


Kevin Walsh wrote:

> Yes - it does break the distinctive ring detection, but that's easily
> sorted out.

Actually it's the first time I've ever heard of distinctive ring being 
available in the UK...  :)

> The "correct" way would be to move the "if (p->use_callerid == 2)"
> code within the existing "if (p->use_callerid)" block, with a couple
> more "if" conditionals here and there.  The quick way, however, is
> to apply the attached chan_zap.c hack over the top of Tony Hoyle's
> great work.

It needs an extra conditional - no need to add the extra delay before 
the phone starts ringing if there's no need to (I prefer my phone to 
start ringing immediately).

Try this patch.  It also enables distinctive ring detection even if 
usecallerid=no.  It's not well tested yet (well, at all actually since I 
don't have access to distinctive ring...)

Tony

-- 
All your code belongs to Santa

Tony Hoyle <tmh at nodomain.org>  Key ID: 104D/4F4B6917 2003-09-13
Fingerprint: 063C AFB4 3026 F724 0AA2  02B8 E547 470E 4F4B 6917
Phone(FWD): (0845 004 5566) 413300
-------------- next part --------------
? channels/chan_zap.cx
Index: callerid.c
===================================================================
RCS file: /usr/cvsroot/asterisk/callerid.c,v
retrieving revision 1.16
diff -u -r1.16 callerid.c
--- callerid.c	4 May 2004 06:42:06 -0000	1.16
+++ callerid.c	25 May 2004 20:04:27 -0000
@@ -134,6 +134,12 @@
 	return cid;
 }
 
+void callerid_set_v23(struct callerid_state *cid)
+{
+	cid->fskd.f_mark_idx  = 4;	/* 1300 Hz */
+	cid->fskd.f_space_idx = 5;	/* 2100 Hz */
+}
+
 void callerid_get(struct callerid_state *cid, char **name, char **number, int *flags)
 {
 	*flags = cid->flags;
@@ -255,7 +260,7 @@
 							break;
 						case 2: /* Number */
 						case 3: /* Number (for Zebble) */
-						case 4: /* Number */
+						case 4: /* Number (UK: Reason for number withheld) */
 							res = cid->rawdata[x];
 							if (res > 32) {
 								ast_log(LOG_NOTICE, "Truncating long caller ID number from %d bytes to 32\n", cid->rawdata[x]);
@@ -266,7 +271,7 @@
 							cid->number[res] = '\0';
 							break;
 						case 7: /* Name */
-						case 8: /* Name */
+						case 8: /* Name (UK: Reason for absence of name) */
 							res = cid->rawdata[x];
 							if (res > 32) {
 								ast_log(LOG_NOTICE, "Truncating long caller ID name from %d bytes to 32\n", cid->rawdata[x]);
@@ -275,6 +280,11 @@
 							memcpy(cid->name, cid->rawdata + x + 1, res);
 							cid->name[res] = '\0';
 							break;
+						case 17: /* Call type (UK) */
+							/* Currently defined: 1 = Voice call, 2 = Ringback when free, 129 = Message waiting */
+							break;
+						case 19: /* Network message system status (UK) */
+							break;
 						case 22: /* Something French */
 							break;
 						default:
Index: coef_in.h
===================================================================
RCS file: /usr/cvsroot/asterisk/coef_in.h,v
retrieving revision 1.1
diff -u -r1.1 coef_in.h
--- coef_in.h	20 Mar 2001 20:11:26 -0000	1.1
+++ coef_in.h	25 May 2004 16:55:41 -0000
@@ -6,4 +6,8 @@
  },  { 9.8539686961e-02,-5.6297236492e-02,4.2915323820e-01,-1.2609358633e+00,2.2399213250e+00,-2.9928879142e+00,2.5990173742e+00,0.0000000000e+00,
  },  },  {  { 1.8229206610e-04,-7.8997325866e-01,-7.7191410839e-01,-2.8075643964e+00,-1.6948618347e+00,-3.0367273700e+00,-9.0333559408e-01,0.0000000000e+00,
  },  { 9.8531161839e-02,-5.6297236492e-02,-1.1421579050e-01,-4.8122536483e-01,-4.0121072432e-01,-7.4834487567e-01,-6.9170822332e-01,0.0000000000e+00,
- },  }, 
+ },  },  {  { 1.8229206611e-04,-7.8997325866e-01, 2.5782298908e+00, -5.3629717478e+00, 6.5890882172e+00, -5.8012914776e+00, 3.0171839130e+00,  -0.0000000000e+00,
+ },  { 9.8534230718e-02,-5.6297236492e-02, 3.8148618075e-01, -1.0848760410e+00, 1.8441165168e+00, -2.4860666655e+00, 2.3103384142e+00,  -0.0000000000e+00,
+ },  },  {  { 1.8229206610e-04,-7.8997325866e-01, -3.8715051001e-01, -2.6192408538e+00, -8.3977994034e-01, -2.8329897913e+00, -4.5306444352e-01,  -0.0000000000e+00,
+ },  { 9.8531160936e-02,-5.6297236492e-02, -5.7284484199e-02, -4.3673866734e-01, -1.9564766257e-01, -6.2028156584e-01, -3.4692356122e-01,  -0.0000000000e+00,
+ },  },
Index: fskmodem.c
===================================================================
RCS file: /usr/cvsroot/asterisk/fskmodem.c,v
retrieving revision 1.2
diff -u -r1.2 fskmodem.c
--- fskmodem.c	10 Nov 2001 20:30:18 -0000	1.2
+++ fskmodem.c	25 May 2004 16:56:15 -0000
@@ -20,8 +20,8 @@
 
 #define NBW	2
 #define BWLIST	{75,800}
-#define	NF	4
-#define	FLIST {1400,1800,1200,2200}
+#define	NF	6
+#define	FLIST {1400,1800,1200,2200,1300,2100}
 
 #define STATE_SEARCH_STARTBIT	0
 #define STATE_SEARCH_STARTBIT2	1
Index: channels/chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.238
diff -u -r1.238 chan_zap.c
--- channels/chan_zap.c	28 May 2004 02:02:33 -0000	1.238
+++ channels/chan_zap.c	28 May 2004 11:59:52 -0000
@@ -734,6 +734,14 @@
 	return 0;
 }
 
+static int zt_get_history(int fd, void *buf, int buf_size)
+{
+	struct zt_history hist;
+	hist.buf=buf;
+	hist.len=buf_size;
+	return ioctl(fd, ZT_GET_HISTORY, &hist);
+}
+
 static int alloc_sub(struct zt_pvt *p, int x)
 {
 	ZT_BUFFERINFO bi;
@@ -4761,9 +4769,35 @@
 	case SIG_FXSLS:
 	case SIG_FXSGS:
 	case SIG_FXSKS:
-		if (p->use_callerid) {
-			cs = callerid_new();
-			if (cs) {
+		if(p->use_callerid == 2) { /* UK callerid is before the ring, so we already have the data */
+		  cs = callerid_new();
+		  if (cs) {
+		    unsigned char cidbuf[16384];
+		    res=0;
+
+		    /* UK caller ID is V23 not Bell202 */
+		    callerid_set_v23(cs);
+		    res = zt_get_history(p->subs[index].zfd,cidbuf,sizeof(cidbuf));
+		    if(res<0) {
+		    	ast_log(LOG_ERROR,"zt_get_history failed: %s\n", strerror(errno));
+		    } else {
+		    	res=callerid_feed(cs,cidbuf,sizeof(cidbuf),AST_LAW(p));
+		    	if (res < 0) {
+			    ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno));
+		    	}
+		    }
+	 	   
+		    if(res==1) {
+		        callerid_get(cs, &name, &number, &flags);
+		        if (option_debug)
+			    ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
+		        }
+ 		    }
+	     	}
+		if (usedistinctiveringdetection || p->use_callerid == 1) {
+			if(p->use_callerid == 1) cs = callerid_new();
+			else cs = NULL;
+			if(usedistinctiveringdetection || cs) {
 #if 1
 				bump_gains(p);
 #endif				
@@ -4788,7 +4822,7 @@
 					i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
 					if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i)))	{
 						ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
-						callerid_free(cs);
+						if(cs) callerid_free(cs);
 						ast_hangup(chan);
 						return NULL;
 					}
@@ -4804,7 +4838,7 @@
 							break;
 						++receivedRingT; /* Increment the ringT counter so we can match it against
 								values in zapata.conf for distinctive ring */
-					} else if (i & ZT_IOMUX_READ) {
+					} else if (i & ZT_IOMUX_READ && cs) {
 						res = read(p->subs[index].zfd, buf, sizeof(buf));
 						if (res < 0) {
 							if (errno != ELAST) {
@@ -4854,7 +4888,7 @@
 						}
 					}
 				}
-				if (res == 1) {
+				if (res == 1 && cs) {
 					callerid_get(cs, &name, &number, &flags);
 					if (option_debug)
 						ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
@@ -7677,7 +7711,9 @@
 			ringc = v->value;
 			sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]);
 		} else if (!strcasecmp(v->name, "usecallerid")) {
-			use_callerid = ast_true(v->value);
+			if(!ast_true(v->value)) use_callerid=0;
+		} else if (!strcasecmp(v->name, "ukcallerid")) {
+			if(ast_true(v->value)) use_callerid=2;
 		} else if (!strcasecmp(v->name, "threewaycalling")) {
 			threewaycalling = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "cancallforward")) {
@@ -8262,7 +8298,9 @@
 			ringc = v->value;
 			sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]);
 		} else if (!strcasecmp(v->name, "usecallerid")) {
-			use_callerid = ast_true(v->value);
+			if(!ast_true(v->value)) use_callerid=0;
+		} else if (!strcasecmp(v->name, "ukcallerid")) {
+			if(ast_true)v->value)) use_callerid=2;
 		} else if (!strcasecmp(v->name, "threewaycalling")) {
 			threewaycalling = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "transfer")) {
Index: include/asterisk/callerid.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/callerid.h,v
retrieving revision 1.5
diff -u -r1.5 callerid.h
--- include/asterisk/callerid.h	29 Nov 2002 16:43:28 -0000	1.5
+++ include/asterisk/callerid.h	25 May 2004 17:12:50 -0000
@@ -56,6 +56,14 @@
  */
 extern struct callerid_state *callerid_new(void);
 
+// Reset the callerid for UK (V23) signalling
+/*!
+ * \param cid Which state machine to act upon
+ *
+ * Reset the callerid structure for UK (V23) signalling
+ */
+extern void callerid_set_v23(struct callerid_state *cid);
+
 //! Read samples into the state machine.
 /*!
  * \param cid Which state machine to act upon


More information about the asterisk-users mailing list