[asterisk-commits] rmudgett: branch group/issue14068 r209588 - /team/group/issue14068/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 30 11:56:07 CDT 2009


Author: rmudgett
Date: Thu Jul 30 11:56:04 2009
New Revision: 209588

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=209588
Log:
Revert all chan_dahdi COLP changes to reimplement in sig_pri (chan_dahdi.c is now trunk -r203304)

Modified:
    team/group/issue14068/channels/chan_dahdi.c

Modified: team/group/issue14068/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/issue14068/channels/chan_dahdi.c?view=diff&rev=209588&r1=209587&r2=209588
==============================================================================
--- team/group/issue14068/channels/chan_dahdi.c (original)
+++ team/group/issue14068/channels/chan_dahdi.c Thu Jul 30 11:56:04 2009
@@ -65,7 +65,7 @@
 #include "sig_analog.h"
 
 #ifdef HAVE_PRI
-#include <libpri.h>
+#include "sig_pri.h"
 #endif
 
 #ifdef HAVE_SS7
@@ -346,57 +346,19 @@
 #define	SIG_SF_FEATDMF	(0x0400000 | DAHDI_SIG_SF)
 #define	SIG_SF_FEATB	(0x0800000 | DAHDI_SIG_SF)
 #define SIG_EM_E1	DAHDI_SIG_EM_E1
-#define SIG_GR303FXOKS	(0x0100000 | DAHDI_SIG_FXOKS)
-#define SIG_GR303FXSKS	(0x0100000 | DAHDI_SIG_FXSKS)
 
 #ifdef LOTS_OF_SPANS
 #define NUM_SPANS	DAHDI_MAX_SPANS
 #else
 #define NUM_SPANS 		32
 #endif
-#define NUM_DCHANS		4	/*!< No more than 4 d-channels */
-#define MAX_CHANNELS	672		/*!< No more than a DS3 per trunk group */
 
 #define CHAN_PSEUDO	-2
-
-#define DCHAN_PROVISIONED (1 << 0)
-#define DCHAN_NOTINALARM  (1 << 1)
-#define DCHAN_UP          (1 << 2)
-
-#define DCHAN_AVAILABLE	(DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
-
-/* Overlap dialing option types */
-#define DAHDI_OVERLAPDIAL_NONE 0
-#define DAHDI_OVERLAPDIAL_OUTGOING 1
-#define DAHDI_OVERLAPDIAL_INCOMING 2
-#define DAHDI_OVERLAPDIAL_BOTH (DAHDI_OVERLAPDIAL_INCOMING|DAHDI_OVERLAPDIAL_OUTGOING)
 
 #define CALLPROGRESS_PROGRESS		1
 #define CALLPROGRESS_FAX_OUTGOING	2
 #define CALLPROGRESS_FAX_INCOMING	4
 #define CALLPROGRESS_FAX		(CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
-
-#ifdef HAVE_PRI_SERVICE_MESSAGES
-/*! \brief Persistent Service State */
-#define SRVST_DBKEY "service-state"
-/*! \brief The out-of-service SERVICE state */
-#define SRVST_TYPE_OOS "O"
-/*! \brief SRVST_INITIALIZED is used to indicate a channel being out-of-service 
- *  The SRVST_INITIALIZED is mostly used maintain backwards compatibility but also may
- *  mean that the channel has not yet received a RESTART message.  If a channel is
- *  out-of-service with this reason a RESTART message will result in the channel
- *  being put into service. */
-#define SRVST_INITIALIZED 0
-/*! \brief SRVST_NEAREND is used to indicate that the near end was put out-of-service */
-#define SRVST_NEAREND  (1 << 0)
-/*! \brief SRVST_FAREND is used to indicate that the far end was taken out-of-service */
-#define SRVST_FAREND   (1 << 1)
-/*! \brief SRVST_BOTH is used to indicate that both sides of the channel are out-of-service */
-#define SRVST_BOTH (SRVST_NEAREND | SRVST_FAREND)
-
-/*! \brief The AstDB family */
-static const char dahdi_db[] = "dahdi/registry";
-#endif
 
 static char defaultcic[64] = "";
 static char defaultozz[64] = "";
@@ -419,7 +381,6 @@
 static int mwilevel = 512;
 
 #ifdef HAVE_PRI
-static struct ast_channel inuse;
 #ifdef PRI_GETSET_TIMERS
 static int pritimers[PRI_MAX_TIMERS];
 #endif
@@ -608,67 +569,12 @@
 
 #ifdef HAVE_PRI
 
-#define PVT_TO_CHANNEL(p) (((p)->prioffset) | ((p)->logicalspan << 8) | (p->pri->mastertrunkgroup ? 0x10000 : 0))
-#define PRI_CHANNEL(p) ((p) & 0xff)
-#define PRI_SPAN(p) (((p) >> 8) & 0xff)
-#define PRI_EXPLICIT(p) (((p) >> 16) & 0x01)
-
 struct dahdi_pri {
-	pthread_t master;						/*!< Thread of master */
-	ast_mutex_t lock;						/*!< Mutex */
-	char idleext[AST_MAX_EXTENSION];				/*!< Where to idle extra calls */
-	char idlecontext[AST_MAX_CONTEXT];				/*!< What context to use for idle */
-	char idledial[AST_MAX_EXTENSION];				/*!< What to dial before dumping */
-	int minunused;							/*!< Min # of channels to keep empty */
-	int minidle;							/*!< Min # of "idling" calls to keep active */
-	int nodetype;							/*!< Node type */
-	int switchtype;							/*!< Type of switch to emulate */
-	int nsf;							/*!< Network-Specific Facilities */
-	int dialplan;							/*!< Dialing plan */
-	int localdialplan;						/*!< Local dialing plan */
-	char internationalprefix[10];					/*!< country access code ('00' for european dialplans) */
-	char nationalprefix[10];					/*!< area access code ('0' for european dialplans) */
-	char localprefix[20];						/*!< area access code + area code ('0'+area code for european dialplans) */
-	char privateprefix[20];						/*!< for private dialplans */
-	char unknownprefix[20];						/*!< for unknown dialplans */
 	int dchannels[NUM_DCHANS];					/*!< What channel are the dchannels on */
-	int trunkgroup;							/*!< What our trunkgroup is */
 	int mastertrunkgroup;						/*!< What trunk group is our master */
 	int prilogicalspan;						/*!< Logical span number within trunk group */
-	int numchans;							/*!< Num of channels we represent */
-	int overlapdial;						/*!< In overlap dialing mode */
-	int qsigchannelmapping;						/*!< QSIG channel mapping type */
-	int discardremoteholdretrieval;					/*!< shall remote hold or remote retrieval notifications be discarded? */
-	int facilityenable;						/*!< Enable facility IEs */
-	struct pri *dchans[NUM_DCHANS];					/*!< Actual d-channels */
-	int dchanavail[NUM_DCHANS];					/*!< Whether each channel is available */
-	struct pri *pri;						/*!< Currently active D-channel */
-	/*! \brief TRUE if to dump PRI event info (Tested but never set) */
-	int debug;
-	int fds[NUM_DCHANS];						/*!< FD's for d-channels */
-	/*! \brief Value set but not used */
-	int offset;
-	/*! \brief Span number put into user output messages */
-	int span;
-	/*! \brief TRUE if span is being reset/restarted */
-	int resetting;
-	/*! \brief Current position during a reset (-1 if not started) */
-	int resetpos;
-#ifdef HAVE_PRI_SERVICE_MESSAGES
-	unsigned int enable_service_message_support:1;	/*!< enable SERVICE message support */
-#endif
-#ifdef HAVE_PRI_INBANDDISCONNECT
-	unsigned int inbanddisconnect:1;				/*!< Should we support inband audio after receiving DISCONNECT? */
-#endif
-	time_t lastreset;						/*!< time when unused channels were last reset */
-	long resetinterval;						/*!< Interval (in seconds) for resetting unused channels */
-	/*! \brief ISDN signalling type (SIG_PRI, SIG_BRI, SIG_BRI_PTMP, etc...) */
-	int sig;
-	struct dahdi_pvt *pvts[MAX_CHANNELS];				/*!< Member channel pvt structs */
-	struct dahdi_pvt *crvs;						/*!< Member CRV structs */
-	struct dahdi_pvt *crvend;						/*!< Pointer to end of CRV structs */
+	struct sig_pri_pri pri;
 };
-
 
 static struct dahdi_pri pris[NUM_SPANS];
 
@@ -677,11 +583,6 @@
 #else
 #define DEFAULT_PRI_DEBUG 0
 #endif
-
-static inline void pri_rel(struct dahdi_pri *pri)
-{
-	ast_mutex_unlock(&pri->lock);
-}
 
 #else
 /*! Shut up the compiler */
@@ -1028,6 +929,11 @@
 	 * \note Applies to SS7 channels.
 	 */
 	unsigned int remotelyblocked:1;
+#if defined(HAVE_PRI)
+	struct sig_pri_pri *pri;
+	int prioffset;
+	int logicalspan;
+#endif
 #if defined(HAVE_PRI) || defined(HAVE_SS7)
 	/*!
 	 * \brief XXX BOOLEAN Purpose???
@@ -1224,7 +1130,6 @@
 	struct timeval flashtime;			/*!< Last flash-hook time */
 	/*! \brief Opaque DSP configuration structure. */
 	struct ast_dsp *dsp;
-	//int cref;					/*!< Call reference number (Not used) */
 	/*! \brief DAHDI dial operation command struct for ioctl() call. */
 	struct dahdi_dialoperation dop;
 	int whichwink;					/*!< SIG_FEATDMF_TA Which wink are we on? */
@@ -1272,20 +1177,6 @@
 	 * \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
 	 */
 	int sendcalleridafter;
-#ifdef HAVE_PRI
-	/*! \brief DAHDI PRI control parameters */
-	struct dahdi_pri *pri;
-	/*! \brief XXX Purpose??? */
-	struct dahdi_pvt *bearer;
-	/*! \brief XXX Purpose??? */
-	struct dahdi_pvt *realcall;
-	/*! \brief Opaque libpri call control structure */
-	q931_call *call;
-	/*! \brief Channel number in span. */
-	int prioffset;
-	/*! \brief Logical span number within trunk group */
-	int logicalspan;
-#endif
 	/*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
 	int polarity;
 	/*! \brief DSP feature flags: DSP_FEATURE_xxx */
@@ -1384,7 +1275,7 @@
 	 */
 	struct dahdi_chan_conf conf = {
 #ifdef HAVE_PRI
-		.pri = {
+		.pri.pri = {
 			.nsf = PRI_NSF_NONE,
 			.switchtype = PRI_SWITCH_NI2,
 			.dialplan = PRI_UNKNOWN + 1,
@@ -1535,11 +1426,7 @@
 	.func_channel_write = dahdi_func_write,
 };
 
-#ifdef HAVE_PRI
-#define GET_CHANNEL(p) ((p)->bearer ? (p)->bearer->channel : p->channel)
-#else
 #define GET_CHANNEL(p) ((p)->channel)
-#endif
 
 static enum analog_sigtype dahdisig_to_analogsig(int sig)
 {
@@ -1847,7 +1734,7 @@
 	return dahdi_wink(p, index);
 }
 
-static void wakeup_sub(struct dahdi_pvt *p, int a, struct dahdi_pri *pri);
+static void wakeup_sub(struct dahdi_pvt *p, int a);
 
 static int reset_conf(struct dahdi_pvt *p);
 
@@ -2082,21 +1969,65 @@
 	p->subs[da].owner = ast_a;
 	p->subs[db].owner = ast_b;
 
-	wakeup_sub(p, a, NULL);
-	wakeup_sub(p, b, NULL);
+	wakeup_sub(p, a);
+	wakeup_sub(p, b);
 
 	return;
 }
 
 static struct ast_channel *dahdi_new(struct dahdi_pvt *, int, int, int, int, int);
 
-static struct ast_channel * my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub)
+static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub)
 {
 	struct dahdi_pvt *p = pvt;
 	int dsub = analogsub_to_dahdisub(sub);
 
 	return dahdi_new(p, state, startpbx, dsub, 0, 0);
 }
+
+#if defined(HAVE_PRI) || defined(HAVE_SS7)
+static int dahdi_setlaw(int dfd, int law)
+{
+	int res;
+	res = ioctl(dfd, DAHDI_SETLAW, &law);
+	if (res)
+		return res;
+	return 0;
+}
+#endif
+
+#ifdef HAVE_PRI
+static struct ast_channel *my_new_pri_ast_channel(void *pvt, int state, int startpbx, enum sig_pri_law law, int transfercapability, char *exten)
+{
+	struct dahdi_pvt *p = pvt;
+	int audio;
+	int newlaw = -1;
+
+	/* Set to audio mode at this point */
+	audio = 1;
+	if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1)
+		ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n", p->channel, audio, strerror(errno));
+
+	if (law != SIG_PRI_DEFLAW) {
+		dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
+	}
+
+	ast_copy_string(p->exten, exten, sizeof(p->exten));
+
+	switch (law) {
+		case SIG_PRI_DEFLAW:
+			newlaw = 0;
+			break;
+		case SIG_PRI_ALAW:
+			newlaw = DAHDI_LAW_ALAW;
+			break;
+		case SIG_PRI_ULAW:
+			newlaw = DAHDI_LAW_MULAW;
+			break;
+	}
+	return dahdi_new(p, state, startpbx, SUB_REAL, newlaw, transfercapability);
+}
+#endif
 
 static int unalloc_sub(struct dahdi_pvt *p, int x);
 
@@ -2333,6 +2264,92 @@
 	return ioctl(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_HOOK, &x);
 }
 
+#ifdef HAVE_PRI
+static void my_pri_fixup_chans(void *old_chan, void *new_chan)
+{
+	struct dahdi_pvt *old = old_chan;
+	struct dahdi_pvt *new = new_chan;
+	struct sig_pri_chan *pchan = new->sig_pvt;
+	struct sig_pri_pri *pri = pchan->pri;
+
+	new->owner = old->owner;
+	old->owner = NULL;
+	if (new->owner) {
+		char newname[AST_CHANNEL_NAME];
+		snprintf(newname, sizeof(newname), "DAHDI/%d:%d-%d", pri->trunkgroup, new->channel, 1);
+		ast_change_name(new->owner, newname);
+
+		new->owner->tech_pvt = new;
+		new->owner->fds[0] = new->subs[SUB_REAL].dfd;
+		new->subs[SUB_REAL].owner = old->subs[SUB_REAL].owner;
+		old->subs[SUB_REAL].owner = NULL;
+	}
+	/* Copy any DSP that may be present */
+	new->dsp = old->dsp;
+	new->dsp_features = old->dsp_features;
+	old->dsp = NULL;
+	old->dsp_features = 0;
+}
+
+static int sig_pri_tone_to_dahditone(enum analog_tone tone)
+{
+	switch (tone) {
+	case SIG_PRI_TONE_RINGTONE:
+		return DAHDI_TONE_RINGTONE;
+	case SIG_PRI_TONE_STUTTER:
+		return DAHDI_TONE_STUTTER;
+	case SIG_PRI_TONE_CONGESTION:
+		return DAHDI_TONE_CONGESTION;
+	case SIG_PRI_TONE_DIALTONE:
+		return DAHDI_TONE_DIALTONE;
+	case SIG_PRI_TONE_DIALRECALL:
+		return DAHDI_TONE_DIALRECALL;
+	case SIG_PRI_TONE_INFO:
+		return DAHDI_TONE_INFO;
+	case SIG_PRI_TONE_BUSY:
+		return DAHDI_TONE_BUSY;
+	default:
+		return -1;
+	}
+}
+
+static const char *event2str(int event);
+
+static void my_handle_dchan_exception(struct sig_pri_pri *pri, int index)
+{
+	int x, res;
+
+	res = ioctl(pri->fds[index], DAHDI_GETEVENT, &x);
+	if (x) {
+		ast_log(LOG_NOTICE, "PRI got event: %s (%d) on D-channel of span %d\n", event2str(x), x, pri->span);
+	}
+	/* Keep track of alarm state */	
+	if (x == DAHDI_EVENT_ALARM) {
+		pri_event_alarm(pri, index, 0);
+	} else if (x == DAHDI_EVENT_NOALARM) {
+		pri_event_noalarm(pri, index, 0);
+	}
+}
+
+static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone)
+{
+	struct dahdi_pvt *p = pvt;
+
+	return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone));
+}
+
+static struct sig_pri_callback dahdi_pri_callbacks =
+{
+	.handle_dchan_exception = my_handle_dchan_exception,
+	.play_tone = my_pri_play_tone,
+	.set_echocanceller = my_set_echocanceller,
+	.lock_private = my_lock_private,
+	.unlock_private = my_unlock_private,
+	.new_ast_channel = my_new_pri_ast_channel,
+	.fixup_chans = my_pri_fixup_chans,
+};
+#endif /* HAVE_PRI */
+
 /*!
  * \brief Send MWI state change
  *
@@ -2403,7 +2420,6 @@
 }
 
 
-static const char *event2str(int event);
 
 static struct analog_callback dahdi_analog_callbacks =
 {
@@ -2448,24 +2464,6 @@
 
 static struct dahdi_pvt *round_robin[32];
 
-#if defined(HAVE_PRI)
-static inline int pri_grab(struct dahdi_pvt *pvt, struct dahdi_pri *pri)
-{
-	int res;
-	/* Grab the lock first */
-	do {
-		res = ast_mutex_trylock(&pri->lock);
-		if (res) {
-			DEADLOCK_AVOIDANCE(&pvt->lock);
-		}
-	} while (res);
-	/* Then break the poll */
-	if (pri->master != AST_PTHREADT_NULL)
-		pthread_kill(pri->master, SIGURG);
-	return 0;
-}
-#endif	/* defined(HAVE_PRI) */
-
 #if defined(HAVE_SS7)
 static inline void ss7_rel(struct dahdi_ss7 *ss7)
 {
@@ -2538,12 +2536,8 @@
 	return res;
 }
 
-static void wakeup_sub(struct dahdi_pvt *p, int a, struct dahdi_pri *pri)
-{
-#ifdef HAVE_PRI
-	if (pri)
-		ast_mutex_unlock(&pri->lock);
-#endif
+static void wakeup_sub(struct dahdi_pvt *p, int a)
+{
 	for (;;) {
 		if (p->subs[a].owner) {
 			if (ast_channel_trylock(p->subs[a].owner)) {
@@ -2556,36 +2550,18 @@
 		} else
 			break;
 	}
-#ifdef HAVE_PRI
-	if (pri)
-		ast_mutex_lock(&pri->lock);
-#endif
 }
 
 static void dahdi_queue_frame(struct dahdi_pvt *p, struct ast_frame *f, void *data)
 {
-#ifdef HAVE_PRI
-	struct dahdi_pri *pri = (struct dahdi_pri*) data;
-#endif
 #ifdef HAVE_SS7
 	struct dahdi_ss7 *ss7 = (struct dahdi_ss7*) data;
-#endif
-	/* We must unlock the PRI to avoid the possibility of a deadlock */
-#if defined(HAVE_PRI) || defined(HAVE_SS7)
+
 	if (data) {
 		switch (p->sig) {
-#ifdef HAVE_PRI
-		case SIG_BRI:
-		case SIG_BRI_PTMP:
-		case SIG_PRI:
-			ast_mutex_unlock(&pri->lock);
-			break;
-#endif
-#ifdef HAVE_SS7
 		case SIG_SS7:
 			ast_mutex_unlock(&ss7->lock);
 			break;
-#endif
 		default:
 			break;
 		}
@@ -2603,21 +2579,12 @@
 		} else
 			break;
 	}
-#if defined(HAVE_PRI) || defined(HAVE_SS7)
+#if defined(HAVE_SS7)
 	if (data) {
 		switch (p->sig) {
-#ifdef HAVE_PRI
-		case SIG_BRI:
-		case SIG_BRI_PTMP:
-		case SIG_PRI:
-			ast_mutex_lock(&pri->lock);
-			break;
-#endif
-#ifdef HAVE_SS7
 		case SIG_SS7:
 			ast_mutex_lock(&ss7->lock);
 			break;
-#endif
 		default:
 			break;
 		}
@@ -3107,8 +3074,8 @@
 		ast_channel_set_fd(p->subs[a].owner, 0, p->subs[a].dfd);
 	if (p->subs[b].owner)
 		ast_channel_set_fd(p->subs[b].owner, 0, p->subs[b].dfd);
-	wakeup_sub(p, a, NULL);
-	wakeup_sub(p, b, NULL);
+	wakeup_sub(p, a);
+	wakeup_sub(p, b);
 }
 
 static int dahdi_open(char *fn)
@@ -3173,8 +3140,8 @@
 #if defined(HAVE_PRI)
 static void dahdi_close_pri_fd(struct dahdi_pri *pri, int fd_num)
 {
-	dahdi_close(pri->fds[fd_num]);
-	pri->fds[fd_num] = -1;
+	dahdi_close(pri->pri.fds[fd_num]);
+	pri->pri.fds[fd_num] = -1;
 }
 #endif	/* defined(HAVE_PRI) */
 
@@ -3271,6 +3238,7 @@
 	struct dahdi_pvt *pvt;
 	int idx;
 	int dtmf = -1;
+	int res;
 
 	pvt = chan->tech_pvt;
 
@@ -3282,29 +3250,16 @@
 		goto out;
 
 #ifdef HAVE_PRI
-	if (((pvt->sig == SIG_PRI) || (pvt->sig == SIG_BRI) || (pvt->sig == SIG_BRI_PTMP))
-			&& (chan->_state == AST_STATE_DIALING) && !pvt->proceeding) {
-		if (pvt->setup_ack) {
-			if (!pri_grab(pvt, pvt->pri)) {
-				pri_information(pvt->pri->pri, pvt->call, digit);
-				pri_rel(pvt->pri);
-			} else
-				ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", pvt->span);
-		} else if (strlen(pvt->dialdest) < sizeof(pvt->dialdest) - 1) {
-			int res;
-			ast_debug(1, "Queueing digit '%c' since setup_ack not yet received\n", digit);
-			res = strlen(pvt->dialdest);
-			pvt->dialdest[res++] = digit;
-			pvt->dialdest[res] = '\0';
-		}
-		goto out;
+	if (pvt->sig == SIG_PRI || pvt->sig == SIG_BRI || pvt->sig == SIG_BRI_PTMP) {
+		res = sig_pri_digit_begin(pvt->sig_pvt, chan, digit);
+		if (!res)
+			goto out;
 	}
 #endif
 	if ((dtmf = digit_to_dtmfindex(digit)) == -1)
 		goto out;
 
 	if (pvt->pulse || ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SENDTONE, &dtmf)) {
-		int res;
 		struct dahdi_dialoperation zo = {
 			.op = DAHDI_DIAL_OP_APPEND,
 		};
@@ -3418,16 +3373,6 @@
 	sprintf(buf, "Event %d", event); /* safe */
 	return buf;
 }
-
-#ifdef HAVE_PRI
-static char *dialplan2str(int dialplan)
-{
-	if (dialplan == -1 || dialplan == -2) {
-		return("Dynamically set dialplan in ISDN");
-	}
-	return (pri_plan2str(dialplan));
-}
-#endif
 
 static char *dahdi_sig2str(int sig)
 {
@@ -3485,10 +3430,6 @@
 		return "SF (Tone) with Feature Group D (MF)";
 	case SIG_SF_FEATB:
 		return "SF (Tone) with Feature Group B (MF)";
-	case SIG_GR303FXOKS:
-		return "GR-303 with FXOKS";
-	case SIG_GR303FXSKS:
-		return "GR-303 with FXSKS";
 	case 0:
 		return "Pseudo";
 	default:
@@ -4116,299 +4057,14 @@
 }
 #endif	/* defined(HAVE_SS7) */
 
-#if defined(HAVE_PRI)
-static enum AST_REDIRECTING_REASON pri_to_ast_reason(int pri_reason)
-{
-	enum AST_REDIRECTING_REASON ast_reason;
-
-	switch (pri_reason) {
-	case PRI_REDIR_FORWARD_ON_BUSY:
-		ast_reason = AST_REDIRECTING_REASON_USER_BUSY;
-		break;
-	case PRI_REDIR_FORWARD_ON_NO_REPLY:
-		ast_reason = AST_REDIRECTING_REASON_NO_ANSWER;
-		break;
-	case PRI_REDIR_DEFLECTION:
-		ast_reason = AST_REDIRECTING_REASON_DEFLECTION;
-		break;
-	case PRI_REDIR_UNCONDITIONAL:
-		ast_reason = AST_REDIRECTING_REASON_UNCONDITIONAL;
-		break;
-	case PRI_REDIR_UNKNOWN:
-	default:
-		ast_reason = AST_REDIRECTING_REASON_UNKNOWN;
-		break;
-	}
-
-	return ast_reason;
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-static int ast_to_pri_reason(enum AST_REDIRECTING_REASON ast_reason)
-{
-	int pri_reason;
-
-	switch (ast_reason) {
-	case AST_REDIRECTING_REASON_USER_BUSY:
-		pri_reason = PRI_REDIR_FORWARD_ON_BUSY;
-		break;
-	case AST_REDIRECTING_REASON_NO_ANSWER:
-		pri_reason = PRI_REDIR_FORWARD_ON_NO_REPLY;
-		break;
-	case AST_REDIRECTING_REASON_UNCONDITIONAL:
-		pri_reason = PRI_REDIR_UNCONDITIONAL;
-		break;
-	case AST_REDIRECTING_REASON_DEFLECTION:
-		pri_reason = PRI_REDIR_DEFLECTION;
-		break;
-	case AST_REDIRECTING_REASON_UNKNOWN:
-	default:
-		pri_reason = PRI_REDIR_UNKNOWN;
-		break;
-	}
-
-	return pri_reason;
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-static int pri_to_ast_presentation(int pri_presentation)
-{
-	int ast_presentation;
-
-	switch (pri_presentation) {
-	case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
-		ast_presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
-		break;
-	case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
-		ast_presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
-		break;
-	case PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
-		ast_presentation = AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN;
-		break;
-	case PRES_ALLOWED_NETWORK_NUMBER:
-		ast_presentation = AST_PRES_ALLOWED_NETWORK_NUMBER;
-		break;
-	case PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
-		ast_presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
-		break;
-	case PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
-		ast_presentation = AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN;
-		break;
-	case PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
-		ast_presentation = AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN;
-		break;
-	case PRES_PROHIB_NETWORK_NUMBER:
-		ast_presentation = AST_PRES_PROHIB_NETWORK_NUMBER;
-		break;
-	case PRES_NUMBER_NOT_AVAILABLE:
-		ast_presentation = AST_PRES_NUMBER_NOT_AVAILABLE;
-		break;
-	default:
-		ast_presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
-		break;
-	}
-
-	return ast_presentation;
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-static int ast_to_pri_presentation(int ast_presentation)
-{
-	int pri_presentation;
-
-	switch (ast_presentation) {
-	case AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
-		pri_presentation = PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
-		break;
-	case AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
-		pri_presentation = PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
-		break;
-	case AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
-		pri_presentation = PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN;
-		break;
-	case AST_PRES_ALLOWED_NETWORK_NUMBER:
-		pri_presentation = PRES_ALLOWED_NETWORK_NUMBER;
-		break;
-	case AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
-		pri_presentation = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
-		break;
-	case AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
-		pri_presentation = PRES_PROHIB_USER_NUMBER_PASSED_SCREEN;
-		break;
-	case AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
-		pri_presentation = PRES_PROHIB_USER_NUMBER_FAILED_SCREEN;
-		break;
-	case AST_PRES_PROHIB_NETWORK_NUMBER:
-		pri_presentation = PRES_PROHIB_NETWORK_NUMBER;
-		break;
-	case AST_PRES_NUMBER_NOT_AVAILABLE:
-		pri_presentation = PRES_NUMBER_NOT_AVAILABLE;
-		break;
-	default:
-		pri_presentation = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
-		break;
-	}
-
-	return pri_presentation;
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-/*!
- * \internal
- * \brief Determine the overall presentation value for the given party.
- * \since 1.6.3
- *
- * \param id Party to determine the overall presentation value.
- *
- * \return Overall presentation value for the given party converted to ast values.
- */
-static int overall_ast_presentation(const struct pri_party_id *id)
-{
-	int number_priority;
-	int number_value;
-	int number_screening;
-	int name_priority;
-	int name_value;
-
-	/* Determine name presentation priority. */
-	if (!id->name.valid) {
-		name_value = PRI_PRES_UNAVAILABLE;
-		name_priority = 3;
-	} else {
-		name_value = id->name.presentation & PRI_PRES_RESTRICTION;
-		switch (name_value) {
-		case PRI_PRES_RESTRICTED:
-			name_priority = 0;
-			break;
-		case PRI_PRES_ALLOWED:
-			name_priority = 1;
-			break;
-		case PRI_PRES_UNAVAILABLE:
-			name_priority = 2;
-			break;
-		default:
-			name_value = PRI_PRES_UNAVAILABLE;
-			name_priority = 3;
-			break;
-		}
-	}
-
-	/* Determine number presentation priority. */
-	if (!id->number.valid) {
-		number_screening = PRI_PRES_USER_NUMBER_UNSCREENED;
-		number_value = PRI_PRES_UNAVAILABLE;
-		number_priority = 3;
-	} else {
-		number_screening = id->number.presentation & PRI_PRES_NUMBER_TYPE;
-		number_value = id->number.presentation & PRI_PRES_RESTRICTION;
-		switch (number_value) {
-		case PRI_PRES_RESTRICTED:
-			number_priority = 0;
-			break;
-		case PRI_PRES_ALLOWED:
-			number_priority = 1;
-			break;
-		case PRI_PRES_UNAVAILABLE:
-			number_priority = 2;
-			break;
-		default:
-			number_screening = PRI_PRES_USER_NUMBER_UNSCREENED;
-			number_value = PRI_PRES_UNAVAILABLE;
-			number_priority = 3;
-			break;
-		}
-	}
-
-	/* Select the wining presentation value. */
-	if (name_priority < number_priority) {
-		number_value = name_value;
-	}
-
-	return pri_to_ast_presentation(number_value | number_screening);
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-/*!
- * \internal
- * \brief Fill in the PRI party id from the given asterisk party id.
- * \since 1.6.3
- *
- * \param pri_id PRI party id structure.
- * \param ast_id Asterisk party id structure.
- *
- * \return Nothing
- *
- * \note Assumes that pri_id has been previously memset to zero.
- */
-static void dahdi_pri_party_id_from_ast(struct pri_party_id *pri_id, const struct ast_party_id *ast_id)
-{
-	int presentation;
-
-	presentation = ast_to_pri_presentation(ast_id->number_presentation);
-	if (!ast_strlen_zero(ast_id->name)) {
-		pri_id->name.valid = 1;
-		pri_id->name.presentation = presentation;
-		pri_id->name.char_set = PRI_CHAR_SET_ISO8859_1;
-		ast_copy_string(pri_id->name.str, ast_id->name, sizeof(pri_id->name.str));
-	}
-	if (!ast_strlen_zero(ast_id->number)) {
-		pri_id->number.valid = 1;
-		pri_id->number.presentation = presentation;
-		pri_id->number.plan = ast_id->number_type;
-		ast_copy_string(pri_id->number.str, ast_id->number, sizeof(pri_id->number.str));
-	}
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-/*!
- * \internal
- * \brief Update the PRI redirecting information for the current call.
- * \since 1.6.3
- *
- * \param ast Asterisk channel
- *
- * \return Nothing
- *
- * \note Assumes that the PRI lock is already obtained.
- */
-static void dahdi_pri_redirecting_update(struct ast_channel *ast)
-{
-	struct dahdi_pvt *pvt;
-	struct pri_party_redirecting pri_redirecting;
-	struct ast_party_redirecting ast_redirecting;
-
-	/* Gather asterisk redirecting data */
-	ast_redirecting = ast->redirecting;
-	ast_redirecting.from.number = ast->cid.cid_rdnis;
-
-/*! \todo XXX Original called data can be put in a channel data store that is inherited. */
-
-	memset(&pri_redirecting, 0, sizeof(pri_redirecting));
-	dahdi_pri_party_id_from_ast(&pri_redirecting.from, &ast_redirecting.from);
-	dahdi_pri_party_id_from_ast(&pri_redirecting.to, &ast_redirecting.to);
-	pri_redirecting.count = ast_redirecting.count;
-	pri_redirecting.reason = ast_to_pri_reason(ast_redirecting.reason);
-
-	pvt = ast->tech_pvt;
-	pri_redirecting_update(pvt->pri->pri, pvt->call, &pri_redirecting);
-}
-#endif	/* defined(HAVE_PRI) */
-
 static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout)
 {
 	struct dahdi_pvt *p = ast->tech_pvt;
-	int x, res, idx,mysig;
-	char *c, *n, *l;
-#ifdef HAVE_PRI
-	char *s = NULL;
+	int x, res, mysig;
+	char dest[256]; /* must be same length as p->dialdest */
+#ifdef HAVE_SS7
+	char *c, *l;
 #endif
-	char dest[256]; /* must be same length as p->dialdest */
 	ast_mutex_lock(&p->lock);
 	ast_copy_string(dest, rdest, sizeof(dest));
 	ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
@@ -4438,6 +4094,20 @@
 	p->outgoing = 1;
 
 	set_actual_gain(p->subs[SUB_REAL].dfd, 0, p->rxgain, p->txgain, p->law);
+	
+#ifdef HAVE_PRI
+	if (p->sig == SIG_PRI || p->sig == SIG_BRI || p->sig == SIG_BRI_PTMP) {
+		struct dahdi_params ps;
+		memset(&ps, 0, sizeof(ps));
+		if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps)) {
+			ast_log(LOG_ERROR, "Could not get params\n");
+		}
+		res = sig_pri_call(p->sig_pvt, ast, rdest, timeout, (ps.curlaw == DAHDI_LAW_MULAW) ? PRI_LAYER_1_ULAW : PRI_LAYER_1_ALAW);
+		ast_mutex_unlock(&p->lock);
+		return res;
+	}
+#endif
+
 	/* Set the ring cadence */
 	mysig = p->sig;
 	if (p->outsigmod > -1)
@@ -4460,7 +4130,7 @@
 		}
 		break;
 	}
-	
+
 	/* If this is analog signalling we can exit here */
 	if (analog_lib_handles(p->sig, p->radio, p->oprmode)) {
 		p->callwaitrings = 0;
@@ -4469,234 +4139,15 @@
 		return res;
 	}
 
+	mysig = p->sig;
+	if (p->outsigmod > -1)
+		mysig = p->outsigmod;
+
 	switch (mysig) {
-	case SIG_FXOLS:
-	case SIG_FXOGS:
-	case SIG_FXOKS:
-		if (p->owner == ast) {
-			/* Normal ring, on hook */
-
-			/* Don't send audio while on hook, until the call is answered */
-			p->dialing = 1;
-			if (p->use_callerid) {
-				/* Generate the Caller-ID spill if desired */
-				if (p->cidspill) {
-					ast_log(LOG_WARNING, "cidspill already exists??\n");
-					ast_free(p->cidspill);
-				}
-				p->callwaitcas = 0;
-				if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
-					p->cidlen = ast_callerid_generate(p->cidspill, ast->connected.id.name, ast->connected.id.number, AST_LAW(p));
-					p->cidpos = 0;
-					send_callerid(p);
-				}
-			}
-			/* nick at dccinc.com 4/3/03 mods to allow for deferred dialing */
-			c = strchr(dest, '/');
-			if (c)
-				c++;
-			if (c && (strlen(c) < p->stripmsd)) {
-				ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
-				c = NULL;
-			}
-			if (c) {
-				p->dop.op = DAHDI_DIAL_OP_REPLACE;
-				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
-				ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
-			} else {
-				p->dop.dialstr[0] = '\0';
-			}
-			x = DAHDI_RING;
-			if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x) && (errno != EINPROGRESS)) {
-				ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
-				ast_mutex_unlock(&p->lock);
-				return -1;
-			}
-			p->dialing = 1;
-		} else {
-			/* Call waiting call */
-			p->callwaitrings = 0;
-			if (ast->connected.id.number)
-				ast_copy_string(p->callwait_num, ast->connected.id.number, sizeof(p->callwait_num));
-			else
-				p->callwait_num[0] = '\0';
-			if (ast->connected.id.name)
-				ast_copy_string(p->callwait_name, ast->connected.id.name, sizeof(p->callwait_name));
-			else
-				p->callwait_name[0] = '\0';
-			/* Call waiting tone instead */
-			if (dahdi_callwait(ast)) {
-				ast_mutex_unlock(&p->lock);
-				return -1;
-			}
-			/* Make ring-back */
-			if (tone_zone_play_tone(p->subs[SUB_CALLWAIT].dfd, DAHDI_TONE_RINGTONE))
-				ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast->name);
-		}
-		n = ast->connected.id.name;
-		l = ast->connected.id.number;
-		if (l)
-			ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
-		else
-			p->lastcid_num[0] = '\0';
-		if (n)
-			ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
-		else
-			p->lastcid_name[0] = '\0';
-		ast_setstate(ast, AST_STATE_RINGING);
-		idx = dahdi_get_index(ast, p, 0);
-		if (idx > -1) {
-			p->subs[idx].needringing = 1;
-		}
-		break;
-	case SIG_FXSLS:
-	case SIG_FXSGS:
-	case SIG_FXSKS:
-	case SIG_EMWINK:
-	case SIG_EM:
-	case SIG_EM_E1:
-	case SIG_FEATD:
-	case SIG_FEATDMF:
-	case SIG_E911:
-	case SIG_FGC_CAMA:
-	case SIG_FGC_CAMAMF:
-	case SIG_FEATB:
-	case SIG_SFWINK:
-	case SIG_SF:
-	case SIG_SF_FEATD:
-	case SIG_SF_FEATDMF:
-	case SIG_FEATDMF_TA:
-	case SIG_SF_FEATB:
-		c = strchr(dest, '/');
-		if (c)
-			c++;
-		else
-			c = "";
-		if (strlen(c) < p->stripmsd) {
-			ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
-			ast_mutex_unlock(&p->lock);
-			return -1;
-		}
-#ifdef HAVE_PRI
-		/* Start the trunk, if not GR-303 */
-		if (!p->pri) {
-#endif
-			x = DAHDI_START;
-			res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
-			if (res < 0) {
-				if (errno != EINPROGRESS) {
-					ast_log(LOG_WARNING, "Unable to start channel: %s\n", strerror(errno));
-					ast_mutex_unlock(&p->lock);
-					return -1;
-				}
-			}
-#ifdef HAVE_PRI
-		}
-#endif
-		ast_debug(1, "Dialing '%s'\n", c);
-		p->dop.op = DAHDI_DIAL_OP_REPLACE;
-
-		c += p->stripmsd;
-
-		switch (mysig) {
-		case SIG_FEATD:
-			l = ast->connected.id.number;
-			if (l)
-				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
-			else
-				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
-			break;
-		case SIG_FEATDMF:
-			l = ast->connected.id.number;
-			if (l)
-				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
-			else
-				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
-			break;
-		case SIG_FEATDMF_TA:
-		{
-			const char *cic, *ozz;
-
-			/* If you have to go through a Tandem Access point you need to use this */
-			ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
-			if (!ozz)
-				ozz = defaultozz;
-			cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
-			if (!cic)
-				cic = defaultcic;
-			if (!ozz || !cic) {
-				ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
-				ast_mutex_unlock(&p->lock);
-				return -1;
-			}
-			snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
-			snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
-			p->whichwink = 0;
-		}
-			break;
-		case SIG_E911:
-			ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
-			break;
-		case SIG_FGC_CAMA:
-			snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
-			break;
-		case SIG_FGC_CAMAMF:
-		case SIG_FEATB:
-			snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
-			break;
-		default:
-			if (p->pulse)
-				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
-			else
-				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
-			break;
-		}
-
-		if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
-			memset(p->echorest, 'w', sizeof(p->echorest) - 1);
-			strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
-			p->echorest[sizeof(p->echorest) - 1] = '\0';
-			p->echobreak = 1;
-			p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
-		} else
-			p->echobreak = 0;
-
-		/* waitfordialtone ? */
-#ifdef HAVE_PRI
-		if (!p->pri) {
-#endif
-			if( p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp ) {
-				ast_log(LOG_DEBUG, "Defer dialling for %dms or dialtone\n", p->waitfordialtone);
-				gettimeofday(&p->waitingfordt,NULL);
-				ast_setstate(ast, AST_STATE_OFFHOOK);
-				break;
-			}
-#ifdef HAVE_PRI
-		}
-#endif
-		if (!res) {
-			if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop)) {
-				int saveerr = errno;
-
-				x = DAHDI_ONHOOK;
-				ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
-				ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(saveerr));
-				ast_mutex_unlock(&p->lock);
-				return -1;
-			}
-		} else
-			ast_debug(1, "Deferring dialing...\n");
-
-		p->dialing = 1;
-		if (ast_strlen_zero(c))
-			p->dialednone = 1;
-		ast_setstate(ast, AST_STATE_DIALING);
-		break;
 	case 0:
 		/* Special pseudo -- automatically up*/
 		ast_setstate(ast, AST_STATE_UP);
 		break;
-	case SIG_PRI:
 	case SIG_BRI:
 	case SIG_BRI_PTMP:
 	case SIG_SS7:
@@ -4710,8 +4161,7 @@
 		ast_mutex_unlock(&p->lock);
 		return -1;
 	}
-
-#if defined(HAVE_SS7)
+#ifdef HAVE_SS7
 	if (p->ss7) {
 		char ss7_called_nai;
 		int called_nai_strip;
@@ -4848,8 +4298,7 @@
 		ast_setstate(ast, AST_STATE_DIALING);
 		ss7_rel(p->ss7);
 	}
-#endif	/* defined(HAVE_SS7) */
-
+#endif /* HAVE_SS7 */
 #ifdef HAVE_OPENR2
 	if (p->mfcr2) {
 		openr2_calling_party_category_t chancat;
@@ -4884,269 +4333,6 @@
 		ast_setstate(ast, AST_STATE_DIALING);
 	}
 #endif /* HAVE_OPENR2 */
-
-#if defined(HAVE_PRI)
-	if (p->pri) {
-		struct pri_sr *sr;
-#ifdef SUPPORT_USERUSER
-		const char *useruser;
-#endif
-		int pridialplan;
-		int dp_strip;
-		int prilocaldialplan;
-		int ldp_strip;
-		int exclusive;
-
-		c = strchr(dest, '/');
-		if (c) {
-			c++;
-		} else {
-			c = "";
-		}
-
-		l = NULL;
-		n = NULL;
-		if (!p->hidecallerid) {
-			l = ast->connected.id.number;
-			if (!p->hidecalleridname) {
-				n = ast->connected.id.name;
-			}
-		}
-
-		if (strlen(c) < p->stripmsd) {
-			ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
-			ast_mutex_unlock(&p->lock);
-			return -1;
-		}
-		if (mysig != SIG_FXSKS) {
-			p->dop.op = DAHDI_DIAL_OP_REPLACE;
-			s = strchr(c + p->stripmsd, 'w');
-			if (s) {
-				if (strlen(s) > 1)
-					snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%s", s);
-				else
-					p->dop.dialstr[0] = '\0';
-				*s = '\0';
-			} else {
-				p->dop.dialstr[0] = '\0';
-			}
-		}
-		if (pri_grab(p, p->pri)) {
-			ast_log(LOG_WARNING, "Failed to grab PRI!\n");
-			ast_mutex_unlock(&p->lock);
-			return -1;
-		}
-		if (!(p->call = pri_new_call(p->pri->pri))) {
-			ast_log(LOG_WARNING, "Unable to create call on channel %d\n", p->channel);
-			pri_rel(p->pri);
-			ast_mutex_unlock(&p->lock);
-			return -1;
-		}
-		if (!(sr = pri_sr_new())) {
-			ast_log(LOG_WARNING, "Failed to allocate setup request channel %d\n", p->channel);
-			pri_rel(p->pri);
-			ast_mutex_unlock(&p->lock);
-		}
-		if (p->bearer || (mysig == SIG_FXSKS)) {
-			if (p->bearer) {
-				ast_debug(1, "Oooh, I have a bearer on %d (%d:%d)\n", PVT_TO_CHANNEL(p->bearer), p->bearer->logicalspan, p->bearer->channel);
-				p->bearer->call = p->call;
-			} else
-				ast_debug(1, "I'm being setup with no bearer right now...\n");
-
-			pri_set_crv(p->pri->pri, p->call, p->channel, 0);
-		}
-		p->digital = IS_DIGITAL(ast->transfercapability);
-		/* Add support for exclusive override */
-		if (p->priexclusive)
-			exclusive = 1;
-		else {
-		/* otherwise, traditional behavior */
-			if (p->pri->nodetype == PRI_NETWORK)
-				exclusive = 0;
-			else
-				exclusive = 1;
-		}
-
-		pri_sr_set_channel(sr, p->bearer ? PVT_TO_CHANNEL(p->bearer) : PVT_TO_CHANNEL(p), exclusive, 1);
-		pri_sr_set_bearer(sr, p->digital ? PRI_TRANS_CAP_DIGITAL : ast->transfercapability,
-			(p->digital ? -1 :
-				((p->law == DAHDI_LAW_ALAW) ? PRI_LAYER_1_ALAW : PRI_LAYER_1_ULAW)));
-		if (p->pri->facilityenable)
-			pri_facility_enable(p->pri->pri);
-
-		ast_verb(3, "Requested transfer capability: 0x%.2x - %s\n", ast->transfercapability, ast_transfercapability2str(ast->transfercapability));
-
-		dp_strip = 0;
- 		pridialplan = p->pri->dialplan - 1;
-		if (pridialplan == -2 || pridialplan == -3) { /* compute dynamically */
- 			if (strncmp(c + p->stripmsd, p->pri->internationalprefix, strlen(p->pri->internationalprefix)) == 0) {
-				if (pridialplan == -2) {
- 					dp_strip = strlen(p->pri->internationalprefix);
-				}
- 				pridialplan = PRI_INTERNATIONAL_ISDN;
- 			} else if (strncmp(c + p->stripmsd, p->pri->nationalprefix, strlen(p->pri->nationalprefix)) == 0) {
-				if (pridialplan == -2) {
- 					dp_strip = strlen(p->pri->nationalprefix);
-				}
- 				pridialplan = PRI_NATIONAL_ISDN;
- 			} else {
-				pridialplan = PRI_LOCAL_ISDN;
- 			}
- 		}
-		while (c[p->stripmsd] > '9' && c[p->stripmsd] != '*' && c[p->stripmsd] != '#') {
-			switch (c[p->stripmsd]) {
-			case 'U':
-				pridialplan = (PRI_TON_UNKNOWN << 4) | (pridialplan & 0xf);
-				break;
-			case 'I':
-				pridialplan = (PRI_TON_INTERNATIONAL << 4) | (pridialplan & 0xf);
-				break;
-			case 'N':
-				pridialplan = (PRI_TON_NATIONAL << 4) | (pridialplan & 0xf);
-				break;
-			case 'L':
-				pridialplan = (PRI_TON_NET_SPECIFIC << 4) | (pridialplan & 0xf);
-				break;
-			case 'S':
-				pridialplan = (PRI_TON_SUBSCRIBER << 4) | (pridialplan & 0xf);
-				break;
-			case 'V':
-				pridialplan = (PRI_TON_ABBREVIATED << 4) | (pridialplan & 0xf);
-				break;
-			case 'R':
-				pridialplan = (PRI_TON_RESERVED << 4) | (pridialplan & 0xf);
-				break;
-			case 'u':
-				pridialplan = PRI_NPI_UNKNOWN | (pridialplan & 0xf0);
-				break;
-			case 'e':
-				pridialplan = PRI_NPI_E163_E164 | (pridialplan & 0xf0);
-				break;
-			case 'x':
-				pridialplan = PRI_NPI_X121 | (pridialplan & 0xf0);
-				break;
-			case 'f':
-				pridialplan = PRI_NPI_F69 | (pridialplan & 0xf0);
-				break;
-			case 'n':
-				pridialplan = PRI_NPI_NATIONAL | (pridialplan & 0xf0);
-				break;
-			case 'p':
-				pridialplan = PRI_NPI_PRIVATE | (pridialplan & 0xf0);
-				break;
-			case 'r':
-				pridialplan = PRI_NPI_RESERVED | (pridialplan & 0xf0);
-				break;
-			default:
-				if (isalpha(c[p->stripmsd])) {
-					ast_log(LOG_WARNING, "Unrecognized pridialplan %s modifier: %c\n",
-						c[p->stripmsd] > 'Z' ? "NPI" : "TON", c[p->stripmsd]);
-				}
-				break;
-			}
-			c++;
-		}
- 		pri_sr_set_called(sr, c + p->stripmsd + dp_strip, pridialplan, s ? 1 : 0);
-
-		ldp_strip = 0;
-		prilocaldialplan = p->pri->localdialplan - 1;
-		if ((l != NULL) && (prilocaldialplan == -2 || prilocaldialplan == -3)) { /* compute dynamically */

[... 4460 lines stripped ...]



More information about the asterisk-commits mailing list