diff --git a/apps/app_test.c b/apps/app_test.c
index 98f9373e1504021e2c3484a5492884ba23548152..90af93c7791e2a88a845b18c3d512cfff25ca50b 100755
--- a/apps/app_test.c
+++ b/apps/app_test.c
@@ -27,7 +27,7 @@
 #include "../astconf.h"
 
 
-static char *tdesc = "Make sure asterisk doesn't save CDR for a certain call";
+static char *tdesc = "Interface Test Application";
 
 static char *tests_descrip = "TestServer(): Perform test server function and write call report"
 							 "Results stored in /var/log/asterisk/testreports/<testid>.txt";
diff --git a/callerid.c b/callerid.c
index f616cae80b2c64d27b734f80f0e00f189b7142f0..348c8440439e268693b1037debcba2193f4f1e30 100755
--- a/callerid.c
+++ b/callerid.c
@@ -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 @@ void callerid_init(void)
 	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 @@ struct callerid_state *callerid_new(void)
 		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 @@ void callerid_get(struct callerid_state *cid, char **name, char **number, int *f
 		*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;
@@ -277,6 +344,8 @@ int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, int
 							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:
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index e2d5a81f1be7e3e3d94d94898a76564de4d4d985..f15530f97acbd58ce086373f36977972b444d2d4 100755
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -163,6 +163,8 @@ static char progzone[10]= "";
 static int usedistinctiveringdetection = 0;
 
 static int use_callerid = 1;
+static int cid_signalling = CID_SIG_BELL;
+static int cid_start = CID_START_RING;
 static int zaptrcallerid = 0;
 static int cur_signalling = -1;
 
@@ -473,6 +475,8 @@ static struct zt_pvt {
 	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 */
@@ -900,7 +904,10 @@ static char *events[] = {
 		"Ringer Off",
 		"Hook Transition Complete",
 		"Bits Changed",
-		"Pulse Start"
+	        "Pulse Start",
+		"Timer Expired",
+		"Timer Ping",
+	        "Polarity Reversal"
 };
 
 static struct {
@@ -929,7 +936,7 @@ static char *alarm2str(int alarm)
 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;
@@ -3373,6 +3380,8 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
 			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");
@@ -4540,6 +4549,7 @@ static void *ss_thread(void *data)
 	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;
@@ -5083,8 +5093,219 @@ static void *ss_thread(void *data)
 			}
 		}
 #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;
+				cs = NULL;
+				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);
@@ -5444,6 +5665,26 @@ static int handle_init_event(struct zt_pvt *i, int event)
 			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;
 }
@@ -6193,6 +6434,8 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
 		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;
@@ -8891,6 +9134,22 @@ static int setup_zap(void)
 			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")) {
@@ -9420,6 +9679,8 @@ static int reload_zt(void)
 	language[0] = '\0'; 
 	musicclass[0] = '\0';
 	use_callerid = 1;
+	cid_signalling = CID_SIG_BELL;
+	cid_start = CID_START_RING;
 	cur_signalling = -1;
 	cur_group = 0;
 	cur_callergroup = 0;
@@ -9557,8 +9818,24 @@ static int reload_zt(void)
 		} 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")) {
diff --git a/coef_in.h b/coef_in.h
index b095501b6e8fa8f82d92889ff0c7cf08ccc144a6..9aba022f637f9645d7ae97f9a4cff8d36868dac9 100755
--- a/coef_in.h
+++ b/coef_in.h
@@ -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,
  },  }, 
diff --git a/configs/zapata.conf.sample b/configs/zapata.conf.sample
index 28343a9d5e4a1e16af2e647e4335d49de02c0a63..c692a27b8671dd6c1a794954de65c1793ca367b8 100755
--- a/configs/zapata.conf.sample
+++ b/configs/zapata.conf.sample
@@ -150,6 +150,16 @@ rxwink=300		; Atlas seems to use long (250ms) winks
 ;
 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
diff --git a/fskmodem.c b/fskmodem.c
index 6d45bde7e70b0d4cf97a57e5cecf974b2176a1df..f89e40a844cf1f6192e3db541055b4672b087b69 100755
--- a/fskmodem.c
+++ b/fskmodem.c
@@ -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
diff --git a/include/asterisk/callerid.h b/include/asterisk/callerid.h
index 486c8100a91d021a3743019c7ebde8cee7c7e9e7..19a6eeb9da8c06b8c00da1391ce43f6c8a57d55a 100755
--- a/include/asterisk/callerid.h
+++ b/include/asterisk/callerid.h
@@ -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 @@ extern int callerid_generate(unsigned char *buf, char *number, char *name, int f
 
 //! 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.
 /*!
@@ -84,6 +94,15 @@ extern int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int sa
  */
 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
 /*!
  * \param cid This is the callerid_state state machine to free
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 5eb25dabb7fef50f93467d02b16445e2f451be80..75627cda74b78b5fa7ffd9b7cf0ceff06c600224 100755
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -3,9 +3,9 @@
  *
  * General Asterisk channel definitions.
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
  *
- * Mark Spencer <markster@linux-support.net>
+ * Mark Spencer <markster@digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -338,6 +338,8 @@ struct outgoing_helper {
 #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 */