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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 3 09:48:17 CDT 2009


Author: jpeeler
Date: Wed Jun  3 09:48:04 2009
New Revision: 198885

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=198885
Log:
Look away people, this is not ready for prime time. It's just too much work not to commit.

Modified:
    team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_pri.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_pri.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=198885&r1=198884&r2=198885
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c Wed Jun  3 09:48:04 2009
@@ -63,10 +63,7 @@
 #include <dahdi/user.h>
 #include <dahdi/tonezone.h>
 #include "sig_analog.h"
-
-#ifdef HAVE_PRI
-#include <libpri.h>
-#endif
+#include "sig_pri.h"
 
 #ifdef HAVE_SS7
 #include <libss7.h>
@@ -346,6 +343,7 @@
 #define	SIG_SF_FEATDMF	(0x0400000 | DAHDI_SIG_SF)
 #define	SIG_SF_FEATB	(0x0800000 | DAHDI_SIG_SF)
 #define SIG_EM_E1	DAHDI_SIG_EM_E1
+/* jpeeler */
 #define SIG_GR303FXOKS	(0x0100000 | DAHDI_SIG_FXOKS)
 #define SIG_GR303FXSKS	(0x0100000 | DAHDI_SIG_FXSKS)
 
@@ -354,16 +352,8 @@
 #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
@@ -419,7 +409,6 @@
 static int mwilevel = 512;
 
 #ifdef HAVE_PRI
-static struct ast_channel inuse;
 #ifdef PRI_GETSET_TIMERS
 static int pritimers[PRI_MAX_TIMERS];
 #endif
@@ -605,67 +594,13 @@
 
 #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];
 
@@ -674,11 +609,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 */
@@ -1025,6 +955,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???
@@ -1269,20 +1204,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 */
@@ -1381,7 +1302,7 @@
 	 */
 	struct dahdi_chan_conf conf = {
 #ifdef HAVE_PRI
-		.pri = {
+		.pri.pri = {
 			.nsf = PRI_NSF_NONE,
 			.switchtype = PRI_SWITCH_NI2,
 			.dialplan = PRI_UNKNOWN + 1,
@@ -1527,11 +1448,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)
 {
@@ -1839,7 +1756,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);
 
@@ -2074,20 +1991,60 @@
 	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);
+}
+
+static int dahdi_setlaw(int dfd, int law)
+{
+	int res;
+	res = ioctl(dfd, DAHDI_SETLAW, &law);
+	if (res)
+		return res;
+	return 0;
+}
+
+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);
 }
 
 static int unalloc_sub(struct dahdi_pvt *p, int x);
@@ -2325,6 +2282,94 @@
 	return ioctl(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_HOOK, &x);
 }
 
+static void my_pri_fixup_chans(void *old_chan, void *new_chan)
+{
+	struct dahdi_pvt *old = old_chan;
+	struct dahdi_pvt *new = new_chan;
+
+	new->owner = old->owner;
+	old->owner = NULL;
+	if (new->owner) {
+#ifdef XXX
+		ast_string_field_build(new->owner, name, "%s/%d:%d-%d", dahdi_chan_name, pri->trunkgroup, new->channel, 1);
+#else
+		ast_string_field_build(new->owner, name, "%s/%d-%d", dahdi_chan_name, new->channel, 1);
+#endif
+		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);
+
+#ifdef HAVE_PRI
+static char *dialplan2str(int dialplan);
+#endif
+
+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_sig_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_sig_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,
+/* jpeeler queue_control ? */
+};
+
 /*!
  * \brief Send MWI state change
  *
@@ -2395,7 +2440,6 @@
 }
 
 
-static const char *event2str(int event);
 
 static struct analog_callback dahdi_analog_callbacks =
 {
@@ -2440,24 +2484,6 @@
 
 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)
 {
@@ -2530,12 +2556,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)) {
@@ -2548,36 +2570,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;
 		}
@@ -2595,21 +2599,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;
 		}
@@ -3099,8 +3094,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)
@@ -3165,8 +3160,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) */
 
@@ -3263,6 +3258,7 @@
 	struct dahdi_pvt *pvt;
 	int idx;
 	int dtmf = -1;
+	int res;
 
 	pvt = chan->tech_pvt;
 
@@ -3274,22 +3270,10 @@
 		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)
@@ -3410,16 +3394,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)
 {
@@ -3477,10 +3451,12 @@
 		return "SF (Tone) with Feature Group D (MF)";
 	case SIG_SF_FEATB:
 		return "SF (Tone) with Feature Group B (MF)";
+	/* jpeeler
 	case SIG_GR303FXOKS:
 		return "GR-303 with FXOKS";
 	case SIG_GR303FXSKS:
 		return "GR-303 with FXSKS";
+	*/
 	case 0:
 		return "Pseudo";
 	default:
@@ -4111,11 +4087,7 @@
 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;
-#endif
+	int x, res, mysig;
 	char dest[256]; /* must be same length as p->dialdest */
 	ast_mutex_lock(&p->lock);
 	ast_copy_string(dest, rdest, sizeof(dest));
@@ -4147,6 +4119,16 @@
 
 	set_actual_gain(p->subs[SUB_REAL].dfd, 0, p->rxgain, p->txgain, p->law);
 
+	if (p->sig == SIG_PRI) {
+		struct dahdi_params 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;
+	}
+
 	/* If this is analog signalling we can exit here */
 	if (analog_lib_handles(p->sig, p->radio, p->oprmode)) {
 		p->callwaitrings = 0;
@@ -4160,244 +4142,10 @@
 		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);
-				}
-			}
-			/* Choose proper cadence */
-			if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
-				if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
-					ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
-				p->cidrings = cidrings[p->distinctivering - 1];
-			} else {
-				if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
-					ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
-				p->cidrings = p->sendcalleridafter;
-			}
-
-			/* 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:
@@ -4583,282 +4331,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;
 }
@@ -4979,9 +4451,10 @@
 	ast_mutex_unlock(&iflock);
 }
 
-#if defined(HAVE_PRI)
+#if 0
 static char *dahdi_send_keypad_facility_app = "DAHDISendKeypadFacility";
 
+/* jpeeler, should be moved */
 static int dahdi_send_keypad_facility_exec(struct ast_channel *chan, const char *data)
 {
 	/* Data will be our digit string */
@@ -5031,6 +4504,7 @@
 {
 	/* Data will be our digit string */
 	struct dahdi_pvt *p;
+	struct sig_pri_chan *pchan;
 	char *parse;
 	int res = -1;
 	AST_DECLARE_APP_ARGS(args,
@@ -5045,6 +4519,7 @@
 	}
 
 	p = (struct dahdi_pvt *)chan->tech_pvt;
+	pchan = (struct sig_pri_chan *) p->sig_pvt;
 
 	if (!p) {
 		ast_log(LOG_DEBUG, "Unable to find technology private\n");
@@ -5071,17 +4546,18 @@
 
 	ast_mutex_lock(&p->lock);
 
-	if (!p->pri || !p->call) {
+	if (!p->pri || !pchan->call) {
 		ast_log(LOG_DEBUG, "Unable to find pri or call on channel!\n");
 		ast_mutex_unlock(&p->lock);
 		return -1;
 	}
 
+	/* jpeeler, come back...
 	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);
+				res = pri_callrerouting_facility(p->pri->pri, pchan->call, args.destination, args.original, args.reason);
 			}
 			pri_rel(p->pri);
 		} else {
@@ -5091,103 +4567,13 @@
 		}
 		break;
 	}
+*/
 
 	ast_mutex_unlock(&p->lock);
 
 	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;
-	crv->call = bearer->call;
-	crv->pri = pri;
-	return 0;
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-static char *pri_order(int level)
-{
-	switch (level) {
-	case 0:
-		return "Primary";
-	case 1:
-		return "Secondary";
-	case 2:
-		return "Tertiary";
-	case 3:
-		return "Quaternary";
-	default:
-		return "<Unknown>";
-	}
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-/* Returns fd of the active dchan */
-static int pri_active_dchan_fd(struct dahdi_pri *pri)
-{
-	int x = -1;
-
-	for (x = 0; x < NUM_DCHANS; x++) {
-		if ((pri->dchans[x] == pri->pri))
-			break;
-	}
-
-	return pri->fds[x];
-}
-#endif	/* defined(HAVE_PRI) */
-
-#if defined(HAVE_PRI)
-static int pri_find_dchan(struct dahdi_pri *pri)
-{
-	int oldslot = -1;
-	struct pri *old;
-	int newslot = -1;
-	int x;
-	old = pri->pri;
-	for (x = 0; x < NUM_DCHANS; x++) {
-		if ((pri->dchanavail[x] == DCHAN_AVAILABLE) && (newslot < 0))
-			newslot = x;
-		if (pri->dchans[x] == old) {
-			oldslot = x;
-		}
-	}
-	if (newslot < 0) {
-		newslot = 0;
-		/* This is annoying to see on non persistent layer 2 connections.  Let's not complain in that case */
-		if (pri->sig != SIG_BRI_PTMP) {
-			ast_log(LOG_WARNING, "No D-channels available!  Using Primary channel %d as D-channel anyway!\n",
-				pri->dchannels[newslot]);
-		}
-	}
-	if (old && (oldslot != newslot))
-		ast_log(LOG_NOTICE, "Switching from from d-channel %d to channel %d!\n",
-			pri->dchannels[oldslot], pri->dchannels[newslot]);
-	pri->pri = pri->dchans[newslot];
-	return 0;
-}
 #endif	/* defined(HAVE_PRI) */
 
 #if defined(HAVE_OPENR2)
@@ -5335,7 +4721,7 @@
 
 static int dahdi_hangup(struct ast_channel *ast)
 {
-	int res;
+	int res = 0;
 	int idx,x, law;
 	/*static int restore_gains(struct dahdi_pvt *p);*/
 	struct dahdi_pvt *p = ast->tech_pvt;
@@ -5381,7 +4767,29 @@
 
 	idx = dahdi_get_index(ast, p, 1);
 
-	if ((p->sig == SIG_PRI) || (p->sig == SIG_SS7) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) {
+	if (p->sig == SIG_PRI) {
+		x = 1;
+		ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
+		dahdi_confmute(p, 0);
+		restore_gains(p);
+		if (p->dsp) {
+			ast_dsp_free(p->dsp);
+			p->dsp = NULL;
+		}
+		dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
+		law = DAHDI_LAW_DEFAULT;
+		res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
+		if (p->sig)
+			dahdi_disable_ec(p);
+		update_conf(p);
+		reset_conf(p);
+		sig_pri_hangup(p->sig_pvt, ast);
+		p->subs[SUB_REAL].owner = NULL;
+		p->owner = NULL;
+		goto hangup_out;
+	}
+
+	if ((p->sig == SIG_SS7) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) {
 		x = 1;
 		ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
 	}
@@ -5548,8 +4956,6 @@
 			p->bufferoverrideinuse = 0;
 		}
 
-		law = DAHDI_LAW_DEFAULT;
-		res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
 		if (res < 0)
 			ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
 		/* Perform low level hangup if no owner left */
@@ -5591,59 +4997,6 @@
 				openr2_chan_disconnect_call(p->r2chan, r2cause);
 			}
 			dahdi_r2_update_monitor_count(p->mfcr2, 1);
-		}
-#endif
-#ifdef HAVE_PRI
-		if (p->pri) {
-#ifdef SUPPORT_USERUSER
-			const char *useruser = pbx_builtin_getvar_helper(ast,"USERUSERINFO");
-#endif
-
-			/* Make sure we have a call (or REALLY have a call in the case of a PRI) */
-			if (p->call && (!p->bearer || (p->bearer->call == p->call))) {
-				if (!pri_grab(p, p->pri)) {
-					if (p->alreadyhungup) {
-						ast_debug(1, "Already hungup...  Calling hangup once, and clearing call\n");
-
-#ifdef SUPPORT_USERUSER
-						pri_call_set_useruser(p->call, useruser);
-#endif
-
-						pri_hangup(p->pri->pri, p->call, -1);
-						p->call = NULL;
-						if (p->bearer)
-							p->bearer->call = NULL;
-					} else {
-						const char *cause = pbx_builtin_getvar_helper(ast,"PRI_CAUSE");
-						int icause = ast->hangupcause ? ast->hangupcause : -1;
-						ast_debug(1, "Not yet hungup...  Calling hangup once with icause, and clearing call\n");
-
-#ifdef SUPPORT_USERUSER
-						pri_call_set_useruser(p->call, useruser);
-#endif
-
-						p->alreadyhungup = 1;
-						if (p->bearer)
-							p->bearer->alreadyhungup = 1;
-						if (cause) {
-							if (atoi(cause))
-								icause = atoi(cause);
-						}
-						pri_hangup(p->pri->pri, p->call, icause);
-					}
-					if (res < 0)
-						ast_log(LOG_WARNING, "pri_disconnect failed\n");
-					pri_rel(p->pri);
-				} else {

[... 4700 lines stripped ...]



More information about the svn-commits mailing list