[asterisk-commits] jpeeler: branch jpeeler/asterisk-sigwork-trunk r204653 - /team/jpeeler/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 1 14:34:02 CDT 2009


Author: jpeeler
Date: Wed Jul  1 14:33:58 2009
New Revision: 204653

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=204653
Log:
first pass (incomplete) at sigifying distinctive ring detection

Modified:
    team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h

Modified: team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c?view=diff&rev=204653&r1=204652&r2=204653
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c Wed Jul  1 14:33:58 2009
@@ -1611,6 +1611,119 @@
 	return 1;
 }
 
+static const char *event2str(int event);
+static int restore_gains(struct dahdi_pvt *p);
+
+static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int checkaftercid)
+{
+	unsigned char buf[256];
+	int distMatches;
+	int curRingData[3];
+	int receivedRingT;
+	int counter1;
+	int counter;
+	int i;
+	int res;
+
+	struct dahdi_pvt *p = pvt;
+
+	/* We must have a ring by now, so, if configured, lets try to listen for
+	 * distinctive ringing */
+	if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
+		/* Clear the current ring data array so we dont have old data in it. */
+		for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++)
+			curRingData[receivedRingT] = 0;
+		receivedRingT = 0;
+		if (checkaftercid && distinctiveringaftercid)
+			ast_verb(3, "Detecting post-CID distinctive ring\n");
+		/* Check to see if context is what it should be, if not set to be. */
+		else if (strcmp(p->context,p->defcontext) != 0) {
+			ast_copy_string(p->context, p->defcontext, sizeof(p->context));
+			ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
+		}
+
+		for (;;) {
+			i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
+			if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
+				ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
+				ast_hangup(chan);
+				return 1;
+			}
+			if (i & DAHDI_IOMUX_SIGEVENT) {
+				res = dahdi_get_event(p->subs[idx].dfd);
+				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 < p->ringt_base/2)
+					break;
+				/* Increment the ringT counter so we can match it against
+				   values in chan_dahdi.conf for distinctive ring */
+				if (++receivedRingT == ARRAY_LEN(curRingData))
+					break;
+			} else if (i & DAHDI_IOMUX_READ) {
+				res = read(p->subs[idx].dfd, buf, sizeof(buf));
+				if (res < 0) {
+					if (errno != ELAST) {
+						ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
+						ast_hangup(chan);
+						return 1;
+					}
+					break;
+				}
+				if (p->ringt)
+					p->ringt--;
+				if (p->ringt == 1) {
+					res = -1;
+					break;
+				}
+			}
+		}
+	}
+	if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
+		/* this only shows up if you have n of the dring patterns filled in */
+		ast_verb(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 chan_dahdi.conf for this channel */
+			distMatches = 0;
+			/* this only shows up if you have n of the dring patterns filled in */
+			ast_verb(3, "Checking %d,%d,%d\n",
+					p->drings.ringnum[counter].ring[0],
+					p->drings.ringnum[counter].ring[1],
+					p->drings.ringnum[counter].ring[2]);
+			for (counter1 = 0; counter1 < 3; counter1++) {
+				ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
+				if (p->drings.ringnum[counter].ring[counter1] == -1) {
+					ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
+					curRingData[counter1]);
+					distMatches++;
+				} else if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
+										curRingData[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
+					ast_verb(3, "Ring pattern matched in range: %d to %d\n",
+					(p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
+					(p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
+					distMatches++;
+				}
+			}
+
+			if (distMatches == 3) {
+				/* The ring matches, set the context to whatever is for distinctive ring.. */
+				ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
+				ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
+				ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
+				break;
+			}
+		}
+	}
+	/* Restore linear mode (if appropriate) for Caller*ID processing */
+	dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
+	restore_gains(p);
+
+	return 0;
+}
+
 static int send_callerid(struct dahdi_pvt *p);
 
 static int my_stop_callwait(void *pvt)
@@ -2317,8 +2430,6 @@
 	}
 }
 
-static const char *event2str(int event);
-
 static void my_handle_dchan_exception(struct sig_pri_pri *pri, int index)
 {
 	int x, res;
@@ -2464,6 +2575,7 @@
 	.handle_notify_message = my_handle_notify_message,
 	.increase_ss_count = my_increase_ss_count,
 	.decrease_ss_count = my_decrease_ss_count,
+	.distinctive_ring = my_distinctive_ring,
 };
 
 static struct dahdi_pvt *round_robin[32];
@@ -3050,8 +3162,6 @@
 };
 
 #endif /* HAVE_OPENR2 */
-
-static int restore_gains(struct dahdi_pvt *p);
 
 static void swap_subs(struct dahdi_pvt *p, int a, int b)
 {
@@ -8723,7 +8833,7 @@
 						distMatches = 0;
 						/* Clear the current ring data array so we dont have old data in it. */
 						for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++)
-							curRingData[receivedRingT] = 0;
+						curRingData[receivedRingT] = 0;
 						receivedRingT = 0;
 						counter = 0;
 						counter1 = 0;
@@ -10849,6 +10959,7 @@
 				analog_p->stripmsd = conf->chan.stripmsd;
 				analog_p->cid_start = ANALOG_CID_START_RING;
 				tmp->callwaitingcallerid = analog_p->callwaitingcallerid = 1;
+				analog_p->usedistinctiveringdetection = conf->chan.usedistinctiveringdetection;
 	
 				ast_copy_string(analog_p->mohsuggest, conf->chan.mohsuggest, sizeof(analog_p->mohsuggest));
 				ast_copy_string(analog_p->cid_num, conf->chan.cid_num, sizeof(analog_p->cid_num));

Modified: team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c?view=diff&rev=204653&r1=204652&r2=204653
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c Wed Jul  1 14:33:58 2009
@@ -1254,6 +1254,14 @@
 		return -1;
 }
 
+static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int checkaftercid)
+{
+	if (p->calls->distinctive_ring) {
+		return p->calls->distinctive_ring(chan, p->chan_pvt, idx, checkaftercid);
+	} else
+		return -1;
+
+}
 #define ANALOG_NEED_MFDETECT(p) (((p)->sig == ANALOG_SIG_FEATDMF) || ((p)->sig == ANALOG_SIG_FEATDMF_TA) || ((p)->sig == ANALOG_SIG_E911) || ((p)->sig == ANALOG_SIG_FGC_CAMA) || ((p)->sig == ANALOG_SIG_FGC_CAMAMF) || ((p)->sig == ANALOG_SIG_FEATB))
 
 /* Note by jpeeler: This function has a rather large section of code ifdefed
@@ -2042,106 +2050,12 @@
 
 				analog_stop_cid_detect(p);
 
-#if 0
-			/* XXX */
-			if (strcmp(p->context,p->defcontext) != 0) {
-				ast_copy_string(p->context, p->defcontext, sizeof(p->context));
-				ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
-			}
-
-			analog_get_callerid(p, name, number);
-			/* FSK Bell202 callerID */
-			cs = callerid_new(p->cid_signalling);
-			if (cs) {
-#if 1
-				bump_gains(p);
-#endif				
-				samples = 0;
-				len = 0;
-				distMatches = 0;
-				/* Clear the current ring data array so we dont have old data in it. */
-				for (receivedRingT = 0; receivedRingT < (sizeof(curRingData) / sizeof(curRingData[0])); 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. */
-
-				/* Take out of linear mode for Caller*ID processing */
-				dahdi_setlinear(p->subs[index].dfd, 0);
-				for (;;) {	
-					i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
-					if ((res = ioctl(p->subs[index].dfd, DAHDI_IOMUX, &i)))	{
-						ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
-						callerid_free(cs);
-						ast_hangup(chan);
-						goto quit;
-					}
-					if (i & DAHDI_IOMUX_SIGEVENT) {
-						res = dahdi_get_event(p->subs[index].dfd);
-						ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
-						/* If we get a PR event, they hung up while processing calerid */
-						if ( res == ANALOG_EVENT_POLARITY && p->hanguponpolarityswitch && p->polarity == POLARITY_REV) {
-							ast_debug(1, "Hanging up due to polarity reversal on channel %d while detecting callerid\n", p->channel);
-							p->polarity = POLARITY_IDLE;
-							callerid_free(cs);
-							ast_hangup(chan);
-							goto quit;
-						}
-						res = 0;
-						/* Let us detect callerid when the telco uses distinctive ring */
-
-						curRingData[receivedRingT] = p->ringt;
-
-						if (p->ringt < p->ringt_base/2)
-							break;
-						/* Increment the ringT counter so we can match it against
-						   values in chan_dahdi.conf for distinctive ring */
-						if (++receivedRingT == (sizeof(curRingData) / sizeof(curRingData[0])))
-							break;
-					} else if (i & DAHDI_IOMUX_READ) {
-						res = read(p->subs[index].dfd, 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);
-								goto quit;
-							}
-							break;
-						}
-						if (p->ringt) 
-							p->ringt--;
-						if (p->ringt == 1) {
-							res = -1;
-							break;
-						}
-						samples += res;
-						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;
-						else if (samples > (8000 * 10))
-							break;
-					}
-				}
-				if (res == 1) {
-					callerid_get(cs, &name, &number, &flags);
-					ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
-				}
-				/* Restore linear mode (if appropriate) for Caller*ID processing */
-				dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
-#if 1
-				restore_gains(p);
-#endif				
+				if (analog_distinctive_ring(chan, p, index, 1))
+					goto quit;
+
 				if (res < 0) {
 					ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name);
 				}
-			} else
-				ast_log(LOG_WARNING, "Unable to get caller ID space\n");
-#endif
 			} else
 				ast_log(LOG_WARNING, "Unable to get caller ID space\n");
 		}
@@ -2159,9 +2073,7 @@
 
 		ast_setstate(chan, AST_STATE_RING);
 		chan->rings = 1;
-#if 0
 		p->ringt = p->ringt_base;
-#endif
 		res = ast_pbx_run(chan);
 		if (res) {
 			ast_hangup(chan);

Modified: team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h?view=diff&rev=204653&r1=204652&r2=204653
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h Wed Jul  1 14:33:58 2009
@@ -185,6 +185,8 @@
 	/* callbacks for increasing and decreasing ss_thread_count, will handle locking and condition signal */
 	void (* const increase_ss_count)(void);
 	void (* const decrease_ss_count)(void);
+
+	int (* const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int checkaftercid);
 };
 
 
@@ -228,9 +230,15 @@
 	unsigned int transfer:1;
 	unsigned int transfertobusy:1;			/*!< allow flash-transfers to busy channels */
 	unsigned int use_callerid:1;			/*!< Whether or not to use caller id on this channel */
+	/*!
+     * \brief TRUE if distinctive rings are to be detected.
+     * \note For FXO lines
+     * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
+     */
+	unsigned int usedistinctiveringdetection:1;
 
 	/* Not used for anything but log messages.  Could be just the TCID */
-	int channel;					/*!< Channel Number or CRV */
+	int channel;					/*!< Channel Number */
 	enum analog_sigtype outsigmod;
 	int echotraining;
 	int cid_signalling;				/*!< Asterisk callerid type we're using */
@@ -282,10 +290,8 @@
 
 	int callwaitcas;
 
-#if 0
 	int ringt;
 	int ringt_base;
-#endif
 };
 
 struct analog_pvt * analog_new(enum analog_sigtype signallingtype, struct analog_callback *c, void *private_data);




More information about the asterisk-commits mailing list