[asterisk-commits] russell: branch group/newcdr r203478 - in /team/group/newcdr: ./ channels/ co...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 25 17:47:19 CDT 2009


Author: russell
Date: Thu Jun 25 17:47:15 2009
New Revision: 203478

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=203478
Log:
sync with trunk, update for sig_analog and sig_pri stuff

Added:
    team/group/newcdr/channels/sig_pri.c
      - copied, changed from r203444, trunk/channels/sig_pri.c
    team/group/newcdr/channels/sig_pri.h
      - copied, changed from r203444, trunk/channels/sig_pri.h
Modified:
    team/group/newcdr/   (props changed)
    team/group/newcdr/channels/Makefile
    team/group/newcdr/channels/chan_dahdi.c
    team/group/newcdr/channels/sig_analog.c
    team/group/newcdr/channels/sig_analog.h
    team/group/newcdr/configs/chan_dahdi.conf.sample
    team/group/newcdr/main/ast_expr2.c
    team/group/newcdr/main/ast_expr2.fl
    team/group/newcdr/main/cli.c
    team/group/newcdr/main/features.c

Propchange: team/group/newcdr/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/group/newcdr/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Jun 25 17:47:15 2009
@@ -1,1 +1,1 @@
-/trunk:1-203254
+/trunk:1-203477

Modified: team/group/newcdr/channels/Makefile
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/channels/Makefile?view=diff&rev=203478&r1=203477&r2=203478
==============================================================================
--- team/group/newcdr/channels/Makefile (original)
+++ team/group/newcdr/channels/Makefile Thu Jun 25 17:47:15 2009
@@ -69,7 +69,7 @@
 	rm -f h323/Makefile
 
 $(if $(filter chan_iax2,$(EMBEDDED_MODS)),modules.link,chan_iax2.so): iax2-parser.o iax2-provision.o
-$(if $(filter chan_dahdi,$(EMBEDDED_MODS)),modules.link,chan_dahdi.so): sig_analog.o
+$(if $(filter chan_dahdi,$(EMBEDDED_MODS)),modules.link,chan_dahdi.so): sig_analog.o sig_pri.o
 
 ifneq ($(filter chan_h323,$(EMBEDDED_MODS)),)
 modules.link: h323/libchanh323.a

Modified: team/group/newcdr/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/channels/chan_dahdi.c?view=diff&rev=203478&r1=203477&r2=203478
==============================================================================
--- team/group/newcdr/channels/chan_dahdi.c (original)
+++ team/group/newcdr/channels/chan_dahdi.c Thu Jun 25 17:47:15 2009
@@ -65,7 +65,7 @@
 #include "sig_analog.h"
 
 #ifdef HAVE_PRI
-#include <libpri.h>
+#include "sig_pri.h"
 #endif
 
 #ifdef HAVE_SS7
@@ -347,57 +347,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] = "";
@@ -420,7 +382,6 @@
 static int mwilevel = 512;
 
 #ifdef HAVE_PRI
-static struct ast_channel inuse;
 #ifdef PRI_GETSET_TIMERS
 static int pritimers[PRI_MAX_TIMERS];
 #endif
@@ -609,67 +570,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];
 
@@ -678,11 +584,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 */
@@ -1029,6 +930,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???
@@ -1152,7 +1058,7 @@
 	 * \note The "setvar" strings read in from chan_dahdi.conf
 	 */
 	struct ast_variable *vars;
-	int channel;					/*!< Channel Number or CRV */
+	int channel;					/*!< Channel Number */
 	int span;					/*!< Span number */
 	time_t guardtime;				/*!< Must wait this much time before using for new call */
 	int cid_signalling;				/*!< CID signalling type bell202 or v23 */
@@ -1225,7 +1131,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? */
@@ -1273,20 +1178,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 */
@@ -1385,7 +1276,7 @@
 	 */
 	struct dahdi_chan_conf conf = {
 #ifdef HAVE_PRI
-		.pri = {
+		.pri.pri = {
 			.nsf = PRI_NSF_NONE,
 			.switchtype = PRI_SWITCH_NI2,
 			.dialplan = PRI_UNKNOWN + 1,
@@ -1536,11 +1427,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)
 {
@@ -1848,7 +1735,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);
 
@@ -2083,21 +1970,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, const char *);
 
-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, const struct ast_channel *requestor)
 {
 	struct dahdi_pvt *p = pvt;
 	int dsub = analogsub_to_dahdisub(sub);
 
-	return dahdi_new(p, state, startpbx, dsub, 0, 0, 0);
-}
+	return dahdi_new(p, state, startpbx, dsub, 0, 0, requestor ? requestor->linkedid : "");
+}
+
+#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, const struct ast_channel *requestor)
+{
+	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, requestor ? requestor->linkedid : "");
+}
+#endif
 
 static int unalloc_sub(struct dahdi_pvt *p, int x);
 
@@ -2334,6 +2265,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
  *
@@ -2404,7 +2421,6 @@
 }
 
 
-static const char *event2str(int event);
 
 static struct analog_callback dahdi_analog_callbacks =
 {
@@ -2449,24 +2465,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)
 {
@@ -2539,12 +2537,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)) {
@@ -2557,36 +2551,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;
 		}
@@ -2604,21 +2580,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:
@@ -4119,12 +4060,11 @@
 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));
@@ -4154,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)
@@ -4176,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;
@@ -4186,235 +4140,10 @@
 	}
 
 	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:
 	case SIG_MFCR2:
 		/* We'll get it in a moment -- but use dialdest to store pre-setup_ack digits */
@@ -4598,282 +4327,6 @@
 		ast_setstate(ast, AST_STATE_DIALING);
 	}
 #endif /* HAVE_OPENR2 */
-#ifdef 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;
-		const char *rr_str;
-		int redirect_reason;
-
-		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 */
-			if (strncmp(l, p->pri->internationalprefix, strlen(p->pri->internationalprefix)) == 0) {
-				if (prilocaldialplan == -2) {
-					ldp_strip = strlen(p->pri->internationalprefix);
-				}
-				prilocaldialplan = PRI_INTERNATIONAL_ISDN;
-			} else if (strncmp(l, p->pri->nationalprefix, strlen(p->pri->nationalprefix)) == 0) {
-				if (prilocaldialplan == -2) {
-					ldp_strip = strlen(p->pri->nationalprefix);
-				}
-				prilocaldialplan = PRI_NATIONAL_ISDN;
-			} else {
-				prilocaldialplan = PRI_LOCAL_ISDN;
-			}
-		}
-		if (l != NULL) {
-			while (*l > '9' && *l != '*' && *l != '#') {
-				switch (*l) {
-				case 'U':
-					prilocaldialplan = (PRI_TON_UNKNOWN << 4) | (prilocaldialplan & 0xf);
-					break;
-				case 'I':
-					prilocaldialplan = (PRI_TON_INTERNATIONAL << 4) | (prilocaldialplan & 0xf);
-					break;
-				case 'N':
-					prilocaldialplan = (PRI_TON_NATIONAL << 4) | (prilocaldialplan & 0xf);
-					break;
-				case 'L':
-					prilocaldialplan = (PRI_TON_NET_SPECIFIC << 4) | (prilocaldialplan & 0xf);
-					break;
-				case 'S':
-					prilocaldialplan = (PRI_TON_SUBSCRIBER << 4) | (prilocaldialplan & 0xf);
-					break;
-				case 'V':
-					prilocaldialplan = (PRI_TON_ABBREVIATED << 4) | (prilocaldialplan & 0xf);
-					break;
-				case 'R':
-					prilocaldialplan = (PRI_TON_RESERVED << 4) | (prilocaldialplan & 0xf);
-					break;
-				case 'u':
-					prilocaldialplan = PRI_NPI_UNKNOWN | (prilocaldialplan & 0xf0);
-					break;
-				case 'e':
-					prilocaldialplan = PRI_NPI_E163_E164 | (prilocaldialplan & 0xf0);
-					break;
-				case 'x':
-					prilocaldialplan = PRI_NPI_X121 | (prilocaldialplan & 0xf0);
-					break;
-				case 'f':
-					prilocaldialplan = PRI_NPI_F69 | (prilocaldialplan & 0xf0);
-					break;
-				case 'n':
-					prilocaldialplan = PRI_NPI_NATIONAL | (prilocaldialplan & 0xf0);
-					break;
-				case 'p':
-					prilocaldialplan = PRI_NPI_PRIVATE | (prilocaldialplan & 0xf0);
-					break;
-				case 'r':
-					prilocaldialplan = PRI_NPI_RESERVED | (prilocaldialplan & 0xf0);
-					break;
-				default:
-					if (isalpha(*l)) {
-						ast_log(LOG_WARNING,
-							"Unrecognized prilocaldialplan %s modifier: %c\n",
-							*l > 'Z' ? "NPI" : "TON", *l);
-					}
-					break;
-				}
-				l++;
-			}
-		}
-		pri_sr_set_caller(sr, l ? (l + ldp_strip) : NULL, n, prilocaldialplan,
-			p->use_callingpres ? ast->connected.id.number_presentation : (l ? PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN : PRES_NUMBER_NOT_AVAILABLE));
-		if ((rr_str = pbx_builtin_getvar_helper(ast, "PRIREDIRECTREASON"))) {
-			if (!strcasecmp(rr_str, "UNKNOWN"))
-				redirect_reason = 0;
-			else if (!strcasecmp(rr_str, "BUSY"))
-				redirect_reason = 1;
-			else if (!strcasecmp(rr_str, "NO_REPLY"))
-				redirect_reason = 2;
-			else if (!strcasecmp(rr_str, "UNCONDITIONAL"))
-				redirect_reason = 15;
-			else
-				redirect_reason = PRI_REDIR_UNCONDITIONAL;
-		} else
-			redirect_reason = PRI_REDIR_UNCONDITIONAL;
-		pri_sr_set_redirecting(sr, ast->cid.cid_rdnis, p->pri->localdialplan - 1, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, redirect_reason);
-
-#ifdef SUPPORT_USERUSER
-		/* User-user info */
-		useruser = pbx_builtin_getvar_helper(p->owner, "USERUSERINFO");
-		if (useruser)
-			pri_sr_set_useruser(sr, useruser);
-#endif
-
-		if (pri_setup(p->pri->pri, p->call, sr)) {
- 			ast_log(LOG_WARNING, "Unable to setup call to %s (using %s)\n",
- 				c + p->stripmsd + dp_strip, dialplan2str(p->pri->dialplan));
-			pri_rel(p->pri);
-			ast_mutex_unlock(&p->lock);
-			pri_sr_free(sr);
-			return -1;
-		}
-		pri_sr_free(sr);
-		ast_setstate(ast, AST_STATE_DIALING);
-		pri_rel(p->pri);
-	}
-#endif
 	ast_mutex_unlock(&p->lock);
 	return 0;
 }
@@ -4997,11 +4450,10 @@
 #if defined(HAVE_PRI)
 static char *dahdi_send_keypad_facility_app = "DAHDISendKeypadFacility";
 
-static int dahdi_send_keypad_facility_exec(struct ast_channel *chan, const char *data)
+static int dahdi_send_keypad_facility_exec(struct ast_channel *chan, const char *digits)
 {
 	/* Data will be our digit string */
 	struct dahdi_pvt *p;
-	const char *digits = data;
 
 	if (ast_strlen_zero(digits)) {
 		ast_debug(1, "No digit string sent to application!\n");
@@ -5015,24 +4467,7 @@
 		return -1;
 	}
 
-	ast_mutex_lock(&p->lock);
-
-	if (!p->pri || !p->call) {
-		ast_debug(1, "Unable to find pri or call on channel!\n");
-		ast_mutex_unlock(&p->lock);
-		return -1;
-	}
-
-	if (!pri_grab(p, p->pri)) {
-		pri_keypad_facility(p->pri->pri, p->call, digits);
-		pri_rel(p->pri);
-	} else {
-		ast_debug(1, "Unable to grab pri to send keypad facility!\n");
-		ast_mutex_unlock(&p->lock);
-		return -1;
-	}
-
-	ast_mutex_unlock(&p->lock);
+	pri_send_keypad_facility_exec(p->sig_pvt, digits);
 
 	return 0;
 }
@@ -5084,125 +4519,11 @@
 		args.reason = NULL;
 	}
 
-	ast_mutex_lock(&p->lock);
-
-	if (!p->pri || !p->call) {
-		ast_log(LOG_DEBUG, "Unable to find pri or call on channel!\n");
-		ast_mutex_unlock(&p->lock);
-		return -1;
-	}
-
-	switch (p->sig) {
-	case SIG_PRI:
-		if (!pri_grab(p, p->pri)) {
-			if (chan->_state == AST_STATE_RING) {
-				res = pri_callrerouting_facility(p->pri->pri, p->call, args.destination, args.original, args.reason);
-			}
-			pri_rel(p->pri);
-		} else {
-			ast_log(LOG_DEBUG, "Unable to grab pri to send callrerouting facility on span %d!\n", p->span);
-			ast_mutex_unlock(&p->lock);
-			return -1;
-		}
-		break;
-	}
-
-	ast_mutex_unlock(&p->lock);
+	pri_send_callrerouting_facility_exec(p->sig_pvt, chan->_state, args.destination, args.original, args.reason);
 
 	return res;
 }
 #endif	/* defined(HAVE_PRI_PROG_W_CAUSE) */
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-static int pri_is_up(struct dahdi_pri *pri)
-{
-	int x;
-	for (x = 0; x < NUM_DCHANS; x++) {
-		if (pri->dchanavail[x] == DCHAN_AVAILABLE)
-			return 1;
-	}
-	return 0;
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-static int pri_assign_bearer(struct dahdi_pvt *crv, struct dahdi_pri *pri, struct dahdi_pvt *bearer)
-{
-	bearer->owner = &inuse;
-	bearer->realcall = crv;
-	crv->subs[SUB_REAL].dfd = bearer->subs[SUB_REAL].dfd;
-	if (crv->subs[SUB_REAL].owner)
-		ast_channel_set_fd(crv->subs[SUB_REAL].owner, 0, crv->subs[SUB_REAL].dfd);
-	crv->bearer = bearer;

[... 4480 lines stripped ...]



More information about the asterisk-commits mailing list