Index: callerid.c
===================================================================
RCS file: /usr/cvsroot/asterisk/callerid.c,v
retrieving revision 1.19
diff -u -r1.19 callerid.c
--- callerid.c	23 Jul 2004 00:27:26 -0000	1.19
+++ callerid.c	1 Sep 2004 00:49:50 -0000
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <math.h>
+#include <ctype.h>
 #include <asterisk/ulaw.h>
 #include <asterisk/alaw.h>
 #include <asterisk/frame.h>
@@ -107,7 +108,7 @@
 	casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
 }
 
-struct callerid_state *callerid_new(void)
+struct callerid_state *callerid_new(int cid_signalling)
 {
 	struct callerid_state *cid;
 	cid = malloc(sizeof(struct callerid_state));
@@ -119,8 +120,13 @@
 		cid->fskd.nstop = 1;	/* 1 stop bit */
 		cid->fskd.paridad = 0;	/* No parity */
 		cid->fskd.bw=1;			/* Filter 800 Hz */
-		cid->fskd.f_mark_idx =  2;	/* 1200 Hz */
-		cid->fskd.f_space_idx = 3;	/* 2200 Hz */
+		if (cid_signalling == 2) { /* v23 signalling */
+			cid->fskd.f_mark_idx =  4;	/* 1300 Hz */
+			cid->fskd.f_space_idx = 5;	/* 2100 Hz */
+		} else { /* Bell 202 signalling as default */ 
+			cid->fskd.f_mark_idx =  2;	/* 1200 Hz */
+			cid->fskd.f_space_idx = 3;	/* 2200 Hz */
+		}
 		cid->fskd.pcola = 0;		/* No clue */
 		cid->fskd.cont = 0;			/* Digital PLL reset */
 		cid->fskd.x0 = 0.0;
@@ -147,6 +153,67 @@
 		*number = cid->number;
 }
 
+void callerid_get_dtmf(char *cidstring, char *number, int *flags)
+{
+	int i;
+	int code;
+
+	/* "Clear" the number-buffer. */
+	number[0] = 0;
+
+	if (strlen(cidstring) < 2) {
+		ast_log(LOG_DEBUG, "No cid detected\n");
+		*flags = CID_UNKNOWN_NUMBER;
+		return;
+	}
+	
+	/* Detect protocol and special types */
+	if (cidstring[0] == 'B') {
+		/* Handle special codes */
+		code = atoi(&cidstring[1]);
+		if (code == 0)
+			*flags = CID_UNKNOWN_NUMBER;
+		else if (code == 10) 
+			*flags = CID_PRIVATE_NUMBER;
+		else
+			ast_log(LOG_DEBUG, "Unknown DTMF code %d\n", code);
+	} else if (cidstring[0] == 'D' && cidstring[2] == '#') {
+		/* .DK special code */
+		if (cidstring[1] == '1')
+			*flags = CID_PRIVATE_NUMBER;
+		if (cidstring[1] == '2' || cidstring[1] == '3')
+			*flags = CID_UNKNOWN_NUMBER;
+	} else if (cidstring[0] == 'D' || cidstring[0] == 'A') {
+		/* "Standard" callerid */
+		for (i = 1; i < strlen(cidstring); i++ ) {
+			if (cidstring[i] == 'C' || cidstring[i] == '#')
+				break;
+			if (isdigit(cidstring[i]))
+				number[i-1] = cidstring[i];
+			else
+				ast_log(LOG_DEBUG, "Unknown CID digit '%c'\n",
+					cidstring[i]);
+		}
+		number[i-1] = 0;
+	} else if (isdigit(cidstring[0])) {
+		/* It begins with a digit, so we parse it as a number and hope
+		 * for the best */
+		ast_log(LOG_WARNING, "Couldn't detect start-character. CID "
+			"parsing might be unreliable\n");
+		for (i = 0; i < strlen(cidstring); i++) {
+			if (isdigit(cidstring[i]))
+                                number[i] = cidstring[i];
+			else
+				break;
+		}
+		number[i] = 0;
+	} else {
+		ast_log(LOG_DEBUG, "Unknown CID protocol, start digit '%c'\n", 
+			cidstring[0]);
+		*flags = CID_UNKNOWN_NUMBER;
+	}
+}
+
 int ast_gen_cas(unsigned char *outbuf, int sendsas, int len, int codec)
 {
 	int pos = 0;
@@ -275,6 +342,8 @@
 							memcpy(cid->name, cid->rawdata + x + 1, res);
 							cid->name[res] = '\0';
 							break;
+						case 17: /* UK: Call type, 1=Voice Call, 2=Ringback when free, 129=Message waiting  */
+						case 19: /* UK: Network message system status (Number of messages waiting) */
 						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	1 Sep 2004 00:49:50 -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	1 Sep 2004 00:49:50 -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.328
diff -u -r1.328 chan_zap.c
--- channels/chan_zap.c	31 Aug 2004 13:47:23 -0000	1.328
+++ channels/chan_zap.c	1 Sep 2004 00:50:01 -0000
@@ -156,6 +156,8 @@
 static int usedistinctiveringdetection = 0;
 
 static int use_callerid = 1;
+static int cid_signalling = 1;
+static int cid_start = 1;
 static int zaptrcallerid = 0;
 static int cur_signalling = -1;
 
@@ -464,6 +466,8 @@
 	time_t guardtime;			/* Must wait this much time before using for new call */
 	int dialednone;
 	int use_callerid;			/* Whether or not to use caller id on this channel */
+	int cid_signalling;			/* CID signalling type bell202 or v23 */
+	int cid_start;				/* CID start indicator, polarity or ring */
 	int hidecallerid;
 	int callreturn;
 	int permhidecallerid;		/* Whether to hide our outgoing caller ID or not */
@@ -865,7 +869,10 @@
 		"Ringer Off",
 		"Hook Transition Complete",
 		"Bits Changed",
-		"Pulse Start"
+	        "Pulse Start",
+		"Timer Expired",
+		"Timer Ping",
+	        "Polarity Reversal"
 };
 
 static struct {
@@ -894,7 +901,7 @@
 static char *event2str(int event)
 {
         static char buf[256];
-        if ((event < 15) && (event > -1))
+        if ((event < 18) && (event > -1))
                 return events[event];
         sprintf(buf, "Event %d", event); /* safe */
         return buf;
@@ -3332,6 +3339,8 @@
 			case SIG_SF_FEATD:
 			case SIG_SF_FEATDMF:
 			case SIG_SF_FEATB:
+				if (ast->_state == AST_STATE_PRERING)
+					ast_setstate(ast, AST_STATE_RING);
 				if ((ast->_state == AST_STATE_DOWN) || (ast->_state == AST_STATE_RING)) {
 					if (option_debug)
 						ast_log(LOG_DEBUG, "Ring detected\n");
@@ -4495,6 +4504,7 @@
 	char exten2[AST_MAX_EXTENSION]="";
 	unsigned char buf[256];
 	char cid[256];
+	char dtmfcid[300];
 	char dtmfbuf[300];
 	struct callerid_state *cs;
 	char *name=NULL, *number=NULL;
@@ -5033,8 +5043,218 @@
 			}
 		}
 #endif
-		if (p->use_callerid) {
-			cs = callerid_new();
+		/* If we want caller id, we're in a prering state due to a polarity reversal
+		 * and we're set to use a polarity reversal to trigger the start of caller id,
+		 * grab the caller id and wait for ringing to start... */
+		if (p->use_callerid && (chan->_state == AST_STATE_PRERING && p->cid_start == CID_START_POLARITY)) {
+			/* If set to use DTMF CID signalling, listen for DTMF */
+			if (p->cid_signalling == CID_SIG_DTMF) {
+				int i = 0;
+				ast_log(LOG_DEBUG, "Receiving DTMF cid on "
+					"channel %s\n", chan->name);
+				zt_setlinear(p->subs[index].zfd, 0);
+				res = 2000;
+				for (;;) {
+					struct ast_frame *f;
+					res = ast_waitfor(chan, res);
+					if (res <= 0) {
+						ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
+							"Exiting simple switch\n");
+						ast_hangup(chan);
+						return NULL;
+					} 
+					f = ast_read(chan);
+					if (f->frametype == AST_FRAME_DTMF) {
+						dtmfbuf[i++] = f->subclass;
+						ast_log(LOG_DEBUG, "CID got digit '%c'\n", f->subclass);
+						res = 2000;
+					}
+					ast_frfree(f);
+					if (chan->_state == AST_STATE_RING ||
+					    chan->_state == AST_STATE_RINGING) 
+						break; /* Got ring */
+				}
+				dtmfbuf[i] = 0;
+				zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
+				/* Got cid and ring. */
+				ast_log(LOG_DEBUG, "CID got string '%s'\n", dtmfbuf);
+				callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
+				ast_log(LOG_DEBUG, "CID is '%s', flags %d\n", 
+					dtmfcid, flags);
+				/* If first byte is NULL, we have no cid */
+				if (dtmfcid[0]) 
+					number = dtmfcid;
+				else
+					number = 0;
+			/* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
+			} else if (p->cid_signalling == CID_SIG_V23) {
+				cs = callerid_new(cid_signalling);
+				if (cs) {
+#if 1
+					bump_gains(p);
+#endif				
+					/* Take out of linear mode for Caller*ID processing */
+					zt_setlinear(p->subs[index].zfd, 0);
+					
+					/* First we wait and listen for the Caller*ID */
+					for(;;) {	
+						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);
+							ast_hangup(chan);
+							return NULL;
+						}
+						if (i & ZT_IOMUX_SIGEVENT) {
+							res = zt_get_event(p->subs[index].zfd);
+							ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
+							res = 0;
+						} else if (i & ZT_IOMUX_READ) {
+							res = read(p->subs[index].zfd, buf, sizeof(buf));
+							if (res < 0) {
+								if (errno != ELAST) {
+									ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
+									callerid_free(cs);
+									ast_hangup(chan);
+									return NULL;
+								}
+								break;
+							}
+							res = callerid_feed(cs, buf, res, AST_LAW(p));
+							if (res < 0) {
+								ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno));
+								break;
+							} else if (res)
+								break;
+						}
+					}
+					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 (res < 0) {
+						ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name);
+					}
+
+					/* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */ 
+					res = 2000;
+					for (;;) {
+						struct ast_frame *f;
+						res = ast_waitfor(chan, res);
+						if (res <= 0) {
+							ast_log(LOG_WARNING, "CID timed out waiting for ring. "
+								"Exiting simple switch\n");
+							ast_hangup(chan);
+							return NULL;
+						} 
+						f = ast_read(chan);
+						ast_frfree(f);
+						if (chan->_state == AST_STATE_RING ||
+						    chan->_state == AST_STATE_RINGING) 
+							break; /* Got ring */
+					}
+	
+					/* We must have a ring by now, so, if configured, lets try to listen for
+					 * distinctive ringing */ 
+					if (p->usedistinctiveringdetection == 1) {
+						len = 0;
+						distMatches = 0;
+						/* Clear the current ring data array so we dont have old data in it. */
+						for (receivedRingT=0; receivedRingT < 3; receivedRingT++) {
+							curRingData[receivedRingT] = 0;
+						}
+						receivedRingT = 0;
+						counter = 0;
+						counter1 = 0;
+						/* Check to see if context is what it should be, if not set to be. */
+						if (strcmp(p->context,p->defcontext) != 0) {
+							strncpy(p->context, p->defcontext, sizeof(p->context)-1);
+							strncpy(chan->context,p->defcontext,sizeof(chan->context)-1);
+						}
+		
+						for(;;) {	
+							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);
+								ast_hangup(chan);
+								return NULL;
+							}
+							if (i & ZT_IOMUX_SIGEVENT) {
+								res = zt_get_event(p->subs[index].zfd);
+								ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
+								res = 0;
+								/* Let us detect distinctive ring */
+		
+								curRingData[receivedRingT] = p->ringt;
+		
+								if (p->ringt < RINGT/2)
+									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) {
+								res = read(p->subs[index].zfd, buf, sizeof(buf));
+								if (res < 0) {
+									if (errno != ELAST) {
+										ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
+										callerid_free(cs);
+										ast_hangup(chan);
+										return NULL;
+									}
+									break;
+								}
+								if (p->ringt) 
+									p->ringt--;
+								if (p->ringt == 1) {
+									res = -1;
+									break;
+								}
+							}
+						}
+						if(option_verbose > 2)
+							/* this only shows up if you have n of the dring patterns filled in */
+							ast_verbose( VERBOSE_PREFIX_3 "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
+	
+						for (counter=0; counter < 3; counter++) {
+							/* Check to see if the rings we received match any of the ones in zapata.conf for this
+							channel */
+							distMatches = 0;
+							for (counter1=0; counter1 < 3; counter1++) {
+								if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1]+10) && curRingData[counter1] >=
+								(p->drings.ringnum[counter].ring[counter1]-10)) {
+									distMatches++;
+								}
+							}
+							if (distMatches == 3) {
+								/* The ring matches, set the context to whatever is for distinctive ring.. */
+								strncpy(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context)-1);
+								strncpy(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context)-1);
+								if(option_verbose > 2)
+									ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
+								break;
+							}
+						}
+					}
+					/* Restore linear mode (if appropriate) for Caller*ID processing */
+					zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
+#if 1
+					restore_gains(p);
+#endif				
+				} else
+					ast_log(LOG_WARNING, "Unable to get caller ID space\n");			
+			} else {
+				ast_log(LOG_WARNING, "Channel %s in prering "
+					"state, but I have nothing to do. "
+					"Terminating simple switch, should be "
+					"restarted by the actual ring.\n", 
+					chan->name);
+				ast_hangup(chan);
+				return NULL;
+			}
+		} else if (p->use_callerid && p->cid_start == CID_START_RING) {
+			/* FSK Bell202 callerID */
+			cs = callerid_new(cid_signalling);
 			if (cs) {
 #if 1
 				bump_gains(p);
@@ -5394,6 +5614,26 @@
 			return -1;
 		}
 		break;
+	case ZT_EVENT_POLARITY:
+		switch(i->sig) {
+		case SIG_FXSLS:
+		case SIG_FXSKS:
+		case SIG_FXSGS:
+			if (i->cid_start == CID_START_POLARITY) {
+				ast_verbose(VERBOSE_PREFIX_2 "Starting post polarity "
+					    "CID detection on channel %d\n",
+					    i->channel);
+				chan = zt_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, 0);
+				if (chan && ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
+					ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
+				}
+			}
+			break;
+		default:
+			ast_log(LOG_WARNING, "handle_init_event detected "
+				"polarity reversal on non-FXO (SIG_FXS) "
+				"interface %d\n", i->channel);
+		}
 	}
 	return 0;
 }
@@ -6142,6 +6382,8 @@
 		tmp->channel = channel;
 		tmp->stripmsd = stripmsd;
 		tmp->use_callerid = use_callerid;
+		tmp->cid_signalling = cid_signalling;
+		tmp->cid_start = cid_start;
 		tmp->zaptrcallerid = zaptrcallerid;
 		tmp->restrictcid = restrictcid;
 		tmp->use_callingpres = use_callingpres;
@@ -8817,6 +9059,22 @@
 			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);
+		} else if (!strcasecmp(v->name, "cidsignalling")) {
+			if (!strcasecmp(v->value, "bell"))
+				cid_signalling = CID_SIG_BELL;
+			else if (!strcasecmp(v->value, "v23"))
+				cid_signalling = CID_SIG_V23;
+			else if (!strcasecmp(v->value, "dtmf"))
+				cid_signalling = CID_SIG_DTMF;
+			else if (ast_true(v->value))
+				cid_signalling = CID_SIG_BELL;
+		} else if (!strcasecmp(v->name, "cidstart")) {
+			if (!strcasecmp(v->value, "ring"))
+				cid_start = CID_START_RING;
+			else if (!strcasecmp(v->value, "polarity"))
+				cid_start = CID_START_POLARITY;
+			else if (ast_true(v->value))
+				cid_start = CID_START_RING;
 		} else if (!strcasecmp(v->name, "threewaycalling")) {
 			threewaycalling = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "cancallforward")) {
@@ -9344,6 +9602,8 @@
 	language[0] = '\0'; 
 	musicclass[0] = '\0';
 	use_callerid = 1;
+	cid_signalling = 1;
+	cid_start = 1;
 	cur_signalling = -1;
 	cur_group = 0;
 	cur_callergroup = 0;
@@ -9481,8 +9741,24 @@
 		} else if (!strcasecmp(v->name, "dring3")) {
 			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);
+ 		} else if (!strcasecmp(v->name, "usecallerid")) {
+ 			use_callerid = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "cidsignalling")) {
+			if (!strcasecmp(v->value, "bell")) 
+				cid_signalling = CID_SIG_BELL;
+			else if (!strcasecmp(v->value, "v23")) 
+				cid_signalling = CID_SIG_V23;
+			else if (!strcasecmp(v->value, "dtmf"))
+				cid_signalling = CID_SIG_DTMF;
+			else if (ast_true(v->value)) 
+				cid_signalling = CID_SIG_BELL;
+		} else if (!strcasecmp(v->name, "cidstart")) {
+			if (!strcasecmp(v->value, "ring"))
+				cid_start = CID_START_RING;
+			else if (!strcasecmp(v->value, "polarity"))
+				cid_start = CID_START_POLARITY;
+			else if (ast_true(v->value))
+				cid_start = CID_START_RING;
 		} else if (!strcasecmp(v->name, "threewaycalling")) {
 			threewaycalling = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "transfer")) {
Index: configs/zapata.conf.sample
===================================================================
RCS file: /usr/cvsroot/asterisk/configs/zapata.conf.sample,v
retrieving revision 1.29
diff -u -r1.29 zapata.conf.sample
--- configs/zapata.conf.sample	31 Aug 2004 13:47:23 -0000	1.29
+++ configs/zapata.conf.sample	1 Sep 2004 00:50:01 -0000
@@ -150,6 +150,16 @@
 ;
 usecallerid=yes
 ;
+; Type of caller ID signalling in use
+; bell = bell202 as used in US, v23 = v23 as used in the UK, dtmf = DTMF as used in Denmark, Sweden and Netherlands
+;
+cidsignalling=bell
+;
+; What signals the start of caller ID
+; ring = a ring signals the start, polarity = polarity reversal signals the start
+;
+cidstart=ring
+;
 ; Whether or not to hide outgoing caller ID (Override with *67 or *82)
 ;
 hidecallerid=no
Index: include/asterisk/callerid.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/callerid.h,v
retrieving revision 1.6
diff -u -r1.6 callerid.h
--- include/asterisk/callerid.h	7 Aug 2004 15:51:11 -0000	1.6
+++ include/asterisk/callerid.h	1 Sep 2004 00:50:02 -0000
@@ -24,6 +24,14 @@
 #define CID_UNKNOWN_NAME		(1 << 2)
 #define CID_UNKNOWN_NUMBER		(1 << 3)
 
+#define CID_SIG_BELL	1
+#define CID_SIG_V23	2
+#define CID_SIG_DTMF	3
+
+#define CID_START_RING	1
+#define CID_START_POLARITY 2
+
+
 #define AST_LIN2X(a) ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))
 #define AST_XLAW(a) ((codec == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a)))
 
@@ -51,10 +59,12 @@
 
 //! Create a callerID state machine
 /*!
+ * \param cid_signalling Type of signalling in use
+ *
  * This function returns a malloc'd instance of the callerid_state data structure.
  * Returns a pointer to a malloc'd callerid_state structure, or NULL on error.
  */
-extern struct callerid_state *callerid_new(void);
+extern struct callerid_state *callerid_new(int cid_signalling);
 
 //! Read samples into the state machine.
 /*!
@@ -83,6 +93,15 @@
  * Returns nothing.
  */
 void callerid_get(struct callerid_state *cid, char **number, char **name, int *flags);
+
+//! Get and parse DTMF-based callerid 
+/*!
+ * \param cidstring The actual transmitted string.
+ * \param number The cid number is returned here.
+ * \param flags The cid flags are returned here.
+ * This function parses DTMF callerid.
+ */
+void callerid_get_dtmf(char *cidstring, char *number, int *flags);
 
 //! Free a callerID state
 /*!
Index: include/asterisk/channel.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/channel.h,v
retrieving revision 1.54
diff -u -r1.54 channel.h
--- include/asterisk/channel.h	6 Aug 2004 14:43:25 -0000	1.54
+++ include/asterisk/channel.h	1 Sep 2004 00:50:03 -0000
@@ -338,6 +338,8 @@
 #define AST_STATE_BUSY  	7		
 /*! Digits (or equivalent) have been dialed while offhook */
 #define AST_STATE_DIALING_OFFHOOK	8
+/*! Channel has detected an incoming call and is waiting for ring */
+#define AST_STATE_PRERING       9
 
 /* Bits 16-32 of state are reserved for flags */
 /*! Do not transmit voice data */
