]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
issue 7877: chan_zap module reload does not use default/initialized values on subsequ...
authorDwayne M. Hubbard <dwayne.hubbard@gmail.com>
Thu, 18 Jan 2007 23:47:10 +0000 (23:47 +0000)
committerDwayne M. Hubbard <dwayne.hubbard@gmail.com>
Thu, 18 Jan 2007 23:47:10 +0000 (23:47 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@51271 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_zap.c

index c671e659664aaeb51f8e7ba3f02195d587a03a8e..e8a88579156c9ec87d9dbba8fd499f72d2dd163a 100644 (file)
@@ -195,112 +195,17 @@ static const char config[] = "zapata.conf";
 
 #define DCHAN_AVAILABLE        (DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
 
-static char context[AST_MAX_CONTEXT] = "default";
-static char cid_num[256] = "";
-static char cid_name[256] = "";
 static char defaultcic[64] = "";
 static char defaultozz[64] = "";
 
 static char language[MAX_LANGUAGE] = "";
-static char musicclass[MAX_MUSICCLASS] = "";
 static char progzone[10]= "";
 
 static int usedistinctiveringdetection = 0;
 
-static int transfertobusy = 1;
-
-static int use_callerid = 1;
-static int cid_signalling = CID_SIG_BELL;
-static int cid_start = CID_START_RING;
-static int zaptrcallerid = 0;
-static int cur_signalling = -1;
-
-static ast_group_t cur_group = 0;
-static ast_group_t cur_callergroup = 0;
-static ast_group_t cur_pickupgroup = 0;
-static int relaxdtmf = 0;
-
-static int immediate = 0;
-
-static int stripmsd = 0;
-
-static int callwaiting = 0;
-
-static int callwaitingcallerid = 0;
-
-static int hidecallerid = 0;
-
-static int restrictcid = 0;
-
-static int use_callingpres = 0;
-
-static int callreturn = 0;
-
-static int threewaycalling = 0;
-
-static int transfer = 0;
-
-static int canpark = 0;
-
-static int cancallforward = 0;
-
-static float rxgain = 0.0;
-
-static float txgain = 0.0;
-
-static int tonezone = -1;
-
-static int echocancel;
-
-static int echotraining;
-
-static int pulse;
-
-static int echocanbridged = 0;
-
-static int busydetect = 0;
-
-static int busycount = 3;
-static int busy_tonelength = 0;
-static int busy_quietlength = 0;
-
-static int callprogress = 0;
-
-static char accountcode[AST_MAX_ACCOUNT_CODE] = "";
-
-static char mailbox[AST_MAX_EXTENSION];
-
-static int amaflags = 0;
-
-static int adsi = 0;
-
 static int numbufs = 4;
 
-static int cur_prewink = -1;
-static int cur_preflash = -1;
-static int cur_wink = -1;
-static int cur_flash = -1;
-static int cur_start = -1;
-static int cur_rxwink = -1;
-static int cur_rxflash = -1;
-static int cur_debounce = -1;
-static int cur_priexclusive = 0;
-
-static int priindication_oob = 0;
-
 #ifdef ZAPATA_PRI
-static int minunused = 2;
-static int minidle = 0;
-static char idleext[AST_MAX_EXTENSION];
-static char idledial[AST_MAX_EXTENSION];
-static int overlapdial = 0;
-static int facilityenable = 0;
-static char internationalprefix[10] = "";
-static char nationalprefix[10] = "";
-static char localprefix[20] = "";
-static char privateprefix[20] = "";
-static char unknownprefix[20] = "";
-static long resetinterval = 3600;      /*!< How often (in seconds) to reset unused channels. Default 1 hour. */
 static struct ast_channel inuse = { "GR-303InUse" };
 #ifdef PRI_GETSET_TIMERS
 static int pritimers[PRI_MAX_TIMERS];
@@ -331,18 +236,6 @@ static int ifcount = 0;
 AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
 #endif
 
-/*! \brief Whether we answer on a Polarity Switch event */
-static int answeronpolarityswitch = 0;
-
-/*! \brief Whether we hang up on a Polarity Switch event */
-static int hanguponpolarityswitch = 0;
-
-/*! \brief How long (ms) to ignore Polarity Switch events after we answer a call */
-static int polarityonanswerdelay = 600;
-
-/*! \brief When to send the CallerID signals (rings) */
-static int sendcalleridafter = DEFAULT_CIDRINGS;
-
 /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
    when it's doing something critical. */
 AST_MUTEX_DEFINE_STATIC(monlock);
@@ -520,6 +413,264 @@ struct zt_subchannel {
 
 #define MAX_SLAVES     4
 
+/*! \brief The PRI part of the channel configuration.
+ * Separated as it is is applied to the span rather than to the channel.
+ */
+struct zt_pri_conf {
+#ifdef ZAPATA_PRI
+       int minunused;
+       int minidle;
+       char idleext[AST_MAX_EXTENSION];
+       char idledial[AST_MAX_EXTENSION];
+       int overlapdial;
+       int facilityenable;
+       char internationalprefix[10];
+       char nationalprefix[10];
+       char localprefix[20];
+       char privateprefix[20];
+       char unknownprefix[20];
+       long resetinterval;
+#endif
+};
+
+/*! \brief Channel configuration from zapata.conf .
+ * This struct is used for parsing the [channels] section of zapata.conf.
+ * Generally there is a field here for every possible configuration item.
+ *
+ * The state of fields is saved along the parsing and whenever a 'channel'
+ * statement is reached, the current zt_chan_conf is used to configure the 
+ * channel (struct zt_pvt)
+ *
+ * @seealso zt_chan_init for the default values.
+ */
+struct zt_chan_conf {
+       struct zt_pri_conf pri;
+       char context[AST_MAX_CONTEXT];
+       char cid_num[AST_MAX_EXTENSION];
+       char cid_name[AST_MAX_EXTENSION];
+       char musicclass[MAX_MUSICCLASS];
+       int transfertobusy;
+
+       int cid_signalling;
+       int cid_start;
+       int zaptrcallerid;
+       int use_callerid;
+       int signalling;
+       int outsignalling;
+       ast_group_t group;
+       ast_group_t callergroup;
+       ast_group_t pickupgroup;
+
+       int relaxdtmf;
+
+       int immediate; 
+
+       int stripmsd;
+
+       int callwaiting;
+
+       int callwaitingcallerid;
+
+       int hidecallerid;
+
+       int restrictcid;
+
+       int use_callingpres;
+
+       int callreturn;
+
+       int threewaycalling;
+
+       int transfer;
+
+       int canpark;
+
+       int cancallforward;
+
+       float rxgain;
+
+       float txgain;
+
+       int tonezone;
+
+       int echocancel;
+
+       int echotraining;
+
+       int pulse;
+
+       int echocanbridged;
+
+       int busydetect;
+
+       int busycount;
+       int busy_tonelength;
+       int busy_quietlength;
+
+       int callprogress;
+
+       char accountcode[AST_MAX_ACCOUNT_CODE];
+
+       char mailbox[AST_MAX_EXTENSION];
+
+       int amaflags;
+
+       int adsi;
+
+       int numbufs;
+
+       int prewink;
+       int preflash;
+       int wink;
+       int flash;
+       int start;
+       int rxwink;
+       int rxflash;
+       int debounce;
+       int priexclusive;
+
+       int answeronpolarityswitch;
+       int hanguponpolarityswitch;
+       int polarityonanswerdelay;
+       int sendcalleridafter;
+
+       int priindication_oob;
+       int radio;
+};
+
+/** returns a new zt_chan_conf with default values (by-value) */
+struct zt_chan_conf zt_chan_conf_default(void) {
+       struct zt_chan_conf chan_conf = {
+               .pri = {
+#ifdef ZAPATA_PRI
+                       .minunused = 2,
+                       .minidle = 0,
+                       .idleext = "",
+                       .idledial = "",
+                       .overlapdial = 0,
+                       .facilityenable = 0,
+                       .internationalprefix = "",
+                       .nationalprefix = "",
+                       .localprefix = "",
+                       .privateprefix = "",
+                       .unknownprefix = "",
+                       /*!< How often (in seconds) to reset unused channels. Default 1 hour. */
+                       .resetinterval = 3600,  
+#endif
+               },
+               .context = "default",
+               .cid_num = "",
+               .cid_name = "",
+               .musicclass = "",
+               .transfertobusy = 1,
+
+               .cid_signalling = CID_SIG_BELL,
+               .cid_start = CID_START_RING,
+               .zaptrcallerid = 0,
+               .use_callerid = 1,
+               .signalling = -1,
+               .group = 0,
+               .callergroup = 0,
+               .pickupgroup = 0,
+
+               .relaxdtmf = 0,
+               .immediate = 0,
+
+               .stripmsd = 0,
+
+               .callwaiting = 0,
+
+               .callwaitingcallerid = 0,
+
+               .hidecallerid = 0,
+
+               .restrictcid = 0,
+
+               .use_callingpres = 0,
+
+               .callreturn = 0,
+
+               .threewaycalling = 0,
+
+               .transfer = 0,
+
+               .canpark = 0,
+
+               .cancallforward = 0,
+
+               .rxgain = 0.0,
+
+               .txgain = 0.0,
+
+               .tonezone = -1,
+
+               /*! \brief Boolean: true to use echo cancelling. Default: True. */
+               .echocancel = 1,
+
+               /*! \brief Integer: Echo training time. True implies 400. */
+               .echotraining = 0,
+
+               /*! \brief Boolean: Use pulse dialing. Default: false. Right? */
+               .pulse = 0,
+               
+               /*! \brief Boolean: true to use echo cancelling even between zaptel 
+                * channels. Default: false. */
+               .echocanbridged = 0,
+
+               /*! \brief Boolean: hangup calls by detecting a busy tone. 
+                * Default: false. */
+               .busydetect = 0,
+
+               .busycount = 3,
+               .busy_tonelength = 0,
+               .busy_quietlength = 0,
+
+               .callprogress = 0,
+
+               .accountcode = "",
+
+               /*! \brief String. Voicemail box in which to check mail for 
+                * the channel (mailbox[@context]). Default: none. */
+               .mailbox = "",
+               .amaflags = 0,
+
+               .adsi = 0,
+               .numbufs = 4,
+
+               .prewink = -1,
+               .preflash = -1,
+               .wink = -1,
+               .flash = -1,
+               .start = -1,
+               .rxwink = -1,
+               .rxflash = -1,
+               .debounce = -1,
+               .priexclusive = 0,
+
+               /*! \brief Whether we answer on a Polarity Switch event */
+               .answeronpolarityswitch = 0,
+
+               /*! \brief Whether we hang up on a Polarity Switch event */
+               .hanguponpolarityswitch = 0,
+
+               /*! \brief How long (ms) to ignore Polarity Switch events after we answer a call */
+               .polarityonanswerdelay = 600,
+
+               /*! \brief When to send the CallerID signals (rings) */
+               .sendcalleridafter = DEFAULT_CIDRINGS,
+
+               .priindication_oob = 0,
+
+               /* Add fields above this comment. "radio" will be 
+                * kept as the one without the comma. for the moment, 
+                * until we add all fields.
+                */
+               .radio = 0
+       };
+
+       return chan_conf;
+}
+
 static struct zt_pvt {
        ast_mutex_t lock;
        struct ast_channel *owner;                      /*!< Our current active owner (if applicable) */
@@ -6808,7 +6959,7 @@ static int pri_create_spanmap(int span, int trunkgroup, int logicalspan)
 
 #endif
 
-static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_pri *pri, int reloading)
+static struct zt_pvt *mkintf(int channel, struct zt_chan_conf chan_conf, struct zt_pri *pri, int reloading)
 {
        /* Make a zt_pvt structure for this interface (or CRV if "pri" is specified) */
        struct zt_pvt *tmp = NULL, *tmp2,  *prev = NULL;
@@ -6888,8 +7039,8 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                                        destroy_zt_pvt(&tmp);
                                        return NULL;
                                }
-                               if (p.sigtype != (signalling & 0x3ffff)) {
-                                       ast_log(LOG_ERROR, "Signalling requested on channel %d is %s but line is in %s signalling\n", channel, sig2str(signalling), sig2str(p.sigtype));
+                               if (p.sigtype != (chan_conf.signalling & 0x3ffff)) {
+                                       ast_log(LOG_ERROR, "Signalling requested on channel %d is %s but line is in %s signalling\n", channel, sig2str(chan_conf.signalling), sig2str(p.sigtype));
                                        destroy_zt_pvt(&tmp);
                                        return tmp;
                                }
@@ -6898,20 +7049,20 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                                span = p.spanno - 1;
                        } else {
                                if (channel == CHAN_PSEUDO)
-                                       signalling = 0;
-                               else if ((signalling != SIG_FXOKS) && (signalling != SIG_FXSKS)) {
+                                       chan_conf.signalling = 0;
+                               else if ((chan_conf.signalling != SIG_FXOKS) && (chan_conf.signalling != SIG_FXSKS)) {
                                        ast_log(LOG_ERROR, "CRV's must use FXO/FXS Kewl Start (fxo_ks/fxs_ks) signalling only.\n");
                                        return NULL;
                                }
                        }
 #ifdef ZAPATA_PRI
-                       if ((signalling == SIG_PRI) || (signalling == SIG_GR303FXOKS) || (signalling == SIG_GR303FXSKS)) {
+                       if ((chan_conf.signalling == SIG_PRI) || (chan_conf.signalling == SIG_GR303FXOKS) || (chan_conf.signalling == SIG_GR303FXSKS)) {
                                int offset;
                                int myswitchtype;
                                int matchesdchan;
                                int x,y;
                                offset = 0;
-                               if ((signalling == SIG_PRI) && ioctl(tmp->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &offset)) {
+                               if ((chan_conf.signalling == SIG_PRI) && ioctl(tmp->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &offset)) {
                                        ast_log(LOG_ERROR, "Unable to set clear mode on clear channel %d of span %d: %s\n", channel, p.spanno, strerror(errno));
                                        destroy_zt_pvt(&tmp);
                                        return NULL;
@@ -6935,7 +7086,7 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                                                destroy_zt_pvt(&tmp);
                                                return NULL;
                                        }
-                                       if (signalling == SIG_PRI)
+                                       if (chan_conf.signalling == SIG_PRI)
                                                myswitchtype = switchtype;
                                        else
                                                myswitchtype = PRI_SWITCH_GR303_TMC;
@@ -6966,23 +7117,23 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                                                        destroy_zt_pvt(&tmp);
                                                        return NULL;
                                                }
-                                               if (!ast_strlen_zero(pris[span].idledial) && strcmp(pris[span].idledial, idledial)) {
-                                                       ast_log(LOG_ERROR, "Span %d already has idledial '%s'.\n", span + 1, idledial);
+                                               if (!ast_strlen_zero(pris[span].idledial) && strcmp(pris[span].idledial, chan_conf.pri.idledial)) {
+                                                       ast_log(LOG_ERROR, "Span %d already has idledial '%s'.\n", span + 1, chan_conf.pri.idledial);
                                                        destroy_zt_pvt(&tmp);
                                                        return NULL;
                                                }
-                                               if (!ast_strlen_zero(pris[span].idleext) && strcmp(pris[span].idleext, idleext)) {
-                                                       ast_log(LOG_ERROR, "Span %d already has idleext '%s'.\n", span + 1, idleext);
+                                               if (!ast_strlen_zero(pris[span].idleext) && strcmp(pris[span].idleext, chan_conf.pri.idleext)) {
+                                                       ast_log(LOG_ERROR, "Span %d already has idleext '%s'.\n", span + 1, chan_conf.pri.idleext);
                                                        destroy_zt_pvt(&tmp);
                                                        return NULL;
                                                }
-                                               if (pris[span].minunused && (pris[span].minunused != minunused)) {
-                                                       ast_log(LOG_ERROR, "Span %d already has minunused of %d.\n", span + 1, minunused);
+                                               if (pris[span].minunused && (pris[span].minunused != chan_conf.pri.minunused)) {
+                                                       ast_log(LOG_ERROR, "Span %d already has minunused of %d.\n", span + 1, chan_conf.pri.minunused);
                                                        destroy_zt_pvt(&tmp);
                                                        return NULL;
                                                }
-                                               if (pris[span].minidle && (pris[span].minidle != minidle)) {
-                                                       ast_log(LOG_ERROR, "Span %d already has minidle of %d.\n", span + 1, minidle);
+                                               if (pris[span].minidle && (pris[span].minidle != chan_conf.pri.minidle)) {
+                                                       ast_log(LOG_ERROR, "Span %d already has minidle of %d.\n", span + 1, chan_conf.pri.minidle);
                                                        destroy_zt_pvt(&tmp);
                                                        return NULL;
                                                }
@@ -6998,18 +7149,18 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                                                pris[span].dialplan = dialplan;
                                                pris[span].localdialplan = localdialplan;
                                                pris[span].pvts[pris[span].numchans++] = tmp;
-                                               pris[span].minunused = minunused;
-                                               pris[span].minidle = minidle;
-                                               pris[span].overlapdial = overlapdial;
-                                               pris[span].facilityenable = facilityenable;
-                                               ast_copy_string(pris[span].idledial, idledial, sizeof(pris[span].idledial));
-                                               ast_copy_string(pris[span].idleext, idleext, sizeof(pris[span].idleext));
-                                               ast_copy_string(pris[span].internationalprefix, internationalprefix, sizeof(pris[span].internationalprefix));
-                                               ast_copy_string(pris[span].nationalprefix, nationalprefix, sizeof(pris[span].nationalprefix));
-                                               ast_copy_string(pris[span].localprefix, localprefix, sizeof(pris[span].localprefix));
-                                               ast_copy_string(pris[span].privateprefix, privateprefix, sizeof(pris[span].privateprefix));
-                                               ast_copy_string(pris[span].unknownprefix, unknownprefix, sizeof(pris[span].unknownprefix));
-                                               pris[span].resetinterval = resetinterval;
+                                               pris[span].minunused = chan_conf.pri.minunused;
+                                               pris[span].minidle = chan_conf.pri.minidle;
+                                               pris[span].overlapdial = chan_conf.pri.overlapdial;
+                                               pris[span].facilityenable = chan_conf.pri.facilityenable;
+                                               ast_copy_string(pris[span].idledial, chan_conf.pri.idledial, sizeof(pris[span].idledial));
+                                               ast_copy_string(pris[span].idleext, chan_conf.pri.idleext, sizeof(pris[span].idleext));
+                                               ast_copy_string(pris[span].internationalprefix, chan_conf.pri.internationalprefix, sizeof(pris[span].internationalprefix));
+                                               ast_copy_string(pris[span].nationalprefix, chan_conf.pri.nationalprefix, sizeof(pris[span].nationalprefix));
+                                               ast_copy_string(pris[span].localprefix, chan_conf.pri.localprefix, sizeof(pris[span].localprefix));
+                                               ast_copy_string(pris[span].privateprefix, chan_conf.pri.privateprefix, sizeof(pris[span].privateprefix));
+                                               ast_copy_string(pris[span].unknownprefix, chan_conf.pri.unknownprefix, sizeof(pris[span].unknownprefix));
+                                               pris[span].resetinterval = chan_conf.pri.resetinterval;
                                                
                                                tmp->pri = &pris[span];
                                                tmp->prioffset = offset;
@@ -7025,7 +7176,7 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                        }
 #endif
 #ifdef ZAPATA_R2
-                       if (signalling == SIG_R2) {
+                       if (chan_conf.signalling == SIG_R2) {
                                if (r2prot < 0) {
                                        ast_log(LOG_WARNING, "R2 Country not specified for channel %d -- Assuming China\n", tmp->channel);
                                        tmp->r2prot = MFCR2_PROT_CHINA;
@@ -7045,23 +7196,23 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                        }
 #endif
                } else {
-                       signalling = tmp->sig;
-                       radio = tmp->radio;
+                       chan_conf.signalling = tmp->sig;
+                       chan_conf.radio = tmp->radio;
                        memset(&p, 0, sizeof(p));
                        if (tmp->subs[SUB_REAL].zfd > -1)
                                res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &p);
                }
                /* Adjust starttime on loopstart and kewlstart trunks to reasonable values */
-               if ((signalling == SIG_FXSKS) || (signalling == SIG_FXSLS) ||
-                   (signalling == SIG_EM) || (signalling == SIG_EM_E1) ||  (signalling == SIG_EMWINK) ||
-                       (signalling == SIG_FEATD) || (signalling == SIG_FEATDMF) || (signalling == SIG_FEATDMF_TA) ||
-                         (signalling == SIG_FEATB) || (signalling == SIG_E911) ||
-                   (signalling == SIG_SF) || (signalling == SIG_SFWINK) ||
-                       (signalling == SIG_SF_FEATD) || (signalling == SIG_SF_FEATDMF) ||
-                         (signalling == SIG_SF_FEATB)) {
+               if ((chan_conf.signalling == SIG_FXSKS) || (chan_conf.signalling == SIG_FXSLS) ||
+                   (chan_conf.signalling == SIG_EM) || (chan_conf.signalling == SIG_EM_E1) ||  (chan_conf.signalling == SIG_EMWINK) ||
+                       (chan_conf.signalling == SIG_FEATD) || (chan_conf.signalling == SIG_FEATDMF) || (chan_conf.signalling == SIG_FEATDMF_TA) ||
+                         (chan_conf.signalling == SIG_FEATB) || (chan_conf.signalling == SIG_E911) ||
+                   (chan_conf.signalling == SIG_SF) || (chan_conf.signalling == SIG_SFWINK) ||
+                       (chan_conf.signalling == SIG_SF_FEATD) || (chan_conf.signalling == SIG_SF_FEATDMF) ||
+                         (chan_conf.signalling == SIG_SF_FEATB)) {
                        p.starttime = 250;
                }
-               if (radio) {
+               if (chan_conf.radio) {
                        /* XXX Waiting to hear back from Jim if these should be adjustable XXX */
                        p.channo = channel;
                        p.rxwinktime = 1;
@@ -7069,25 +7220,25 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                        p.starttime = 1;
                        p.debouncetime = 5;
                }
-               if (!radio) {
+               if (!chan_conf.radio) {
                        p.channo = channel;
                        /* Override timing settings based on config file */
-                       if (cur_prewink >= 0)
-                               p.prewinktime = cur_prewink;
-                       if (cur_preflash >= 0)
-                               p.preflashtime = cur_preflash;
-                       if (cur_wink >= 0)
-                               p.winktime = cur_wink;
-                       if (cur_flash >= 0)
-                               p.flashtime = cur_flash;
-                       if (cur_start >= 0)
-                               p.starttime = cur_start;
-                       if (cur_rxwink >= 0)
-                               p.rxwinktime = cur_rxwink;
-                       if (cur_rxflash >= 0)
-                               p.rxflashtime = cur_rxflash;
-                       if (cur_debounce >= 0)
-                               p.debouncetime = cur_debounce;
+                       if (chan_conf.prewink >= 0)
+                               p.prewinktime = chan_conf.prewink;
+                       if (chan_conf.preflash >= 0)
+                               p.preflashtime = chan_conf.preflash;
+                       if (chan_conf.wink >= 0)
+                               p.winktime = chan_conf.wink;
+                       if (chan_conf.flash >= 0)
+                               p.flashtime = chan_conf.flash;
+                       if (chan_conf.start >= 0)
+                               p.starttime = chan_conf.start;
+                       if (chan_conf.rxwink >= 0)
+                               p.rxwinktime = chan_conf.rxwink;
+                       if (chan_conf.rxflash >= 0)
+                               p.rxflashtime = chan_conf.rxflash;
+                       if (chan_conf.debounce >= 0)
+                               p.debouncetime = chan_conf.debounce;
                }
                
                /* dont set parms on a pseudo-channel (or CRV) */
@@ -7116,48 +7267,48 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                                ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d\n", channel);
                }
 #endif
-               tmp->immediate = immediate;
-               tmp->transfertobusy = transfertobusy;
-               tmp->sig = signalling;
-               tmp->radio = radio;
+               tmp->immediate = chan_conf.immediate;
+               tmp->transfertobusy = chan_conf.transfertobusy;
+               tmp->sig = chan_conf.signalling;
+               tmp->radio = chan_conf.radio;
                tmp->ringt_base = ringt_base;
                tmp->firstradio = 0;
-               if ((signalling == SIG_FXOKS) || (signalling == SIG_FXOLS) || (signalling == SIG_FXOGS))
-                       tmp->permcallwaiting = callwaiting;
+               if ((chan_conf.signalling == SIG_FXOKS) || (chan_conf.signalling == SIG_FXOLS) || (chan_conf.signalling == SIG_FXOGS))
+                       tmp->permcallwaiting = chan_conf.callwaiting;
                else
                        tmp->permcallwaiting = 0;
                /* Flag to destroy the channel must be cleared on new mkif.  Part of changes for reload to work */
                tmp->destroy = 0;
                tmp->drings = drings;
                tmp->usedistinctiveringdetection = usedistinctiveringdetection;
-               tmp->callwaitingcallerid = callwaitingcallerid;
-               tmp->threewaycalling = threewaycalling;
-               tmp->adsi = adsi;
-               tmp->permhidecallerid = hidecallerid;
-               tmp->callreturn = callreturn;
-               tmp->echocancel = echocancel;
-               tmp->echotraining = echotraining;
-               tmp->pulse = pulse;
-               tmp->echocanbridged = echocanbridged;
-               tmp->busydetect = busydetect;
-               tmp->busycount = busycount;
-               tmp->busy_tonelength = busy_tonelength;
-               tmp->busy_quietlength = busy_quietlength;
-               tmp->callprogress = callprogress;
-               tmp->cancallforward = cancallforward;
-               tmp->dtmfrelax = relaxdtmf;
+               tmp->callwaitingcallerid = chan_conf.callwaitingcallerid;
+               tmp->threewaycalling = chan_conf.threewaycalling;
+               tmp->adsi = chan_conf.adsi;
+               tmp->permhidecallerid = chan_conf.hidecallerid;
+               tmp->callreturn = chan_conf.callreturn;
+               tmp->echocancel = chan_conf.echocancel;
+               tmp->echotraining = chan_conf.echotraining;
+               tmp->pulse = chan_conf.pulse;
+               tmp->echocanbridged = chan_conf.echocanbridged;
+               tmp->busydetect = chan_conf.busydetect;
+               tmp->busycount = chan_conf.busycount;
+               tmp->busy_tonelength = chan_conf.busy_tonelength;
+               tmp->busy_quietlength = chan_conf.busy_quietlength;
+               tmp->callprogress = chan_conf.callprogress;
+               tmp->cancallforward = chan_conf.cancallforward;
+               tmp->dtmfrelax = chan_conf.relaxdtmf;
                tmp->callwaiting = tmp->permcallwaiting;
                tmp->hidecallerid = tmp->permhidecallerid;
                tmp->channel = channel;
-               tmp->stripmsd = stripmsd;
-               tmp->use_callerid = use_callerid;
-               tmp->cid_signalling = cid_signalling;
-               tmp->cid_start = cid_start;
-               tmp->zaptrcallerid = zaptrcallerid;
-               tmp->restrictcid = restrictcid;
-               tmp->use_callingpres = use_callingpres;
-               tmp->priindication_oob = priindication_oob;
-               tmp->priexclusive = cur_priexclusive;
+               tmp->stripmsd = chan_conf.stripmsd;
+               tmp->use_callerid = chan_conf.use_callerid;
+               tmp->cid_signalling = chan_conf.cid_signalling;
+               tmp->cid_start = chan_conf.cid_start;
+               tmp->zaptrcallerid = chan_conf.zaptrcallerid;
+               tmp->restrictcid = chan_conf.restrictcid;
+               tmp->use_callingpres = chan_conf.use_callingpres;
+               tmp->priindication_oob = chan_conf.priindication_oob;
+               tmp->priexclusive = chan_conf.priexclusive;
                if (tmp->usedistinctiveringdetection) {
                        if (!tmp->use_callerid) {
                                ast_log(LOG_NOTICE, "Distinctive Ring detect requires 'usecallerid' be on\n");
@@ -7165,29 +7316,29 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                        }
                }
 
-               ast_copy_string(tmp->accountcode, accountcode, sizeof(tmp->accountcode));
-               tmp->amaflags = amaflags;
+               ast_copy_string(tmp->accountcode, chan_conf.accountcode, sizeof(tmp->accountcode));
+               tmp->amaflags = chan_conf.amaflags;
                if (!here) {
                        tmp->confno = -1;
                        tmp->propconfno = -1;
                }
-               tmp->canpark = canpark;
-               tmp->transfer = transfer;
-               ast_copy_string(tmp->defcontext,context,sizeof(tmp->defcontext));
+               tmp->canpark = chan_conf.canpark;
+               tmp->transfer = chan_conf.transfer;
+               ast_copy_string(tmp->defcontext,chan_conf.context,sizeof(tmp->defcontext));
                ast_copy_string(tmp->language, language, sizeof(tmp->language));
-               ast_copy_string(tmp->musicclass, musicclass, sizeof(tmp->musicclass));
-               ast_copy_string(tmp->context, context, sizeof(tmp->context));
-               ast_copy_string(tmp->cid_num, cid_num, sizeof(tmp->cid_num));
+               ast_copy_string(tmp->musicclass, chan_conf.musicclass, sizeof(tmp->musicclass));
+               ast_copy_string(tmp->context, chan_conf.context, sizeof(tmp->context));
+               ast_copy_string(tmp->cid_num, chan_conf.cid_num, sizeof(tmp->cid_num));
                tmp->cid_ton = 0;
-               ast_copy_string(tmp->cid_name, cid_name, sizeof(tmp->cid_name));
-               ast_copy_string(tmp->mailbox, mailbox, sizeof(tmp->mailbox));
+               ast_copy_string(tmp->cid_name, chan_conf.cid_name, sizeof(tmp->cid_name));
+               ast_copy_string(tmp->mailbox, chan_conf.mailbox, sizeof(tmp->mailbox));
                tmp->msgstate = -1;
-               tmp->group = cur_group;
-               tmp->callgroup=cur_callergroup;
-               tmp->pickupgroup=cur_pickupgroup;
-               tmp->rxgain = rxgain;
-               tmp->txgain = txgain;
-               tmp->tonezone = tonezone;
+               tmp->group = chan_conf.group;
+               tmp->callgroup=chan_conf.callergroup;
+               tmp->pickupgroup=chan_conf.pickupgroup;
+               tmp->rxgain = chan_conf.rxgain;
+               tmp->txgain = chan_conf.txgain;
+               tmp->tonezone = chan_conf.tonezone;
                tmp->onhooktime = time(NULL);
                if (tmp->subs[SUB_REAL].zfd > -1) {
                        set_actual_gain(tmp->subs[SUB_REAL].zfd, 0, tmp->rxgain, tmp->txgain, tmp->law);
@@ -7195,7 +7346,7 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                                ast_dsp_digitmode(tmp->dsp, DSP_DIGITMODE_DTMF | tmp->dtmfrelax);
                        update_conf(tmp);
                        if (!here) {
-                               if ((signalling != SIG_PRI) && (signalling != SIG_R2))
+                               if ((chan_conf.signalling != SIG_PRI) && (chan_conf.signalling != SIG_R2))
                                        /* Hang it up to be sure it's good */
                                        zt_set_hook(tmp->subs[SUB_REAL].zfd, ZT_ONHOOK);
                        }
@@ -7216,10 +7367,10 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p
                        if (si.alarms) tmp->inalarm = 1;
                }
 
-               tmp->polarityonanswerdelay = polarityonanswerdelay;
-               tmp->answeronpolarityswitch = answeronpolarityswitch;
-               tmp->hanguponpolarityswitch = hanguponpolarityswitch;
-               tmp->sendcalleridafter = sendcalleridafter;
+               tmp->polarityonanswerdelay = chan_conf.polarityonanswerdelay;
+               tmp->answeronpolarityswitch = chan_conf.answeronpolarityswitch;
+               tmp->hanguponpolarityswitch = chan_conf.hanguponpolarityswitch;
+               tmp->sendcalleridafter = chan_conf.sendcalleridafter;
 
        }
        if (tmp && !here) {
@@ -10131,7 +10282,7 @@ static int setup_zap(int reload)
        int start, finish,x;
        int y;
        int found_pseudo = 0;
-       int cur_radio = 0;
+       struct zt_chan_conf chan_conf = zt_chan_conf_default();
 #ifdef ZAPATA_PRI
        int spanno;
        int i;
@@ -10224,7 +10375,7 @@ static int setup_zap(int reload)
 #endif                 
                                        ) {
                        if (reload == 0) {
-                               if (cur_signalling < 0) {
+                               if (chan_conf.signalling < 0) {
                                        ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n");
                                        ast_config_destroy(cfg);
                                        ast_mutex_unlock(&iflock);
@@ -10287,9 +10438,9 @@ static int setup_zap(int reload)
                                }
                                for (x=start;x<=finish;x++) {
 #ifdef ZAPATA_PRI
-                                       tmp = mkintf(x, cur_signalling, cur_radio, pri, reload);
+                                       tmp = mkintf(x, chan_conf, pri, reload);
 #else                                  
-                                       tmp = mkintf(x, cur_signalling, cur_radio, NULL, reload);
+                                       tmp = mkintf(x, chan_conf, NULL, reload);
 #endif                                 
 
                                        if (tmp) {
@@ -10332,278 +10483,272 @@ static int setup_zap(int reload)
                        ringc = v->value;
                        sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]);
                } else if (!strcasecmp(v->name, "usecallerid")) {
-                       use_callerid = ast_true(v->value);
+                       chan_conf.use_callerid = ast_true(v->value);
                } else if (!strcasecmp(v->name, "cidsignalling")) {
                        if (!strcasecmp(v->value, "bell"))
-                               cid_signalling = CID_SIG_BELL;
+                               chan_conf.cid_signalling = CID_SIG_BELL;
                        else if (!strcasecmp(v->value, "v23"))
-                               cid_signalling = CID_SIG_V23;
+                               chan_conf.cid_signalling = CID_SIG_V23;
                        else if (!strcasecmp(v->value, "dtmf"))
-                               cid_signalling = CID_SIG_DTMF;
+                               chan_conf.cid_signalling = CID_SIG_DTMF;
                        else if (ast_true(v->value))
-                               cid_signalling = CID_SIG_BELL;
+                               chan_conf.cid_signalling = CID_SIG_BELL;
                } else if (!strcasecmp(v->name, "cidstart")) {
                        if (!strcasecmp(v->value, "ring"))
-                               cid_start = CID_START_RING;
+                               chan_conf.cid_start = CID_START_RING;
                        else if (!strcasecmp(v->value, "polarity"))
-                               cid_start = CID_START_POLARITY;
+                               chan_conf.cid_start = CID_START_POLARITY;
                        else if (ast_true(v->value))
-                               cid_start = CID_START_RING;
+                               chan_conf.cid_start = CID_START_RING;
                } else if (!strcasecmp(v->name, "threewaycalling")) {
-                       threewaycalling = ast_true(v->value);
+                       chan_conf.threewaycalling = ast_true(v->value);
                } else if (!strcasecmp(v->name, "cancallforward")) {
-                       cancallforward = ast_true(v->value);
+                       chan_conf.cancallforward = ast_true(v->value);
                } else if (!strcasecmp(v->name, "relaxdtmf")) {
                        if (ast_true(v->value)) 
-                               relaxdtmf = DSP_DIGITMODE_RELAXDTMF;
+                               chan_conf.relaxdtmf = DSP_DIGITMODE_RELAXDTMF;
                        else
-                               relaxdtmf = 0;
+                               chan_conf.relaxdtmf = 0;
                } else if (!strcasecmp(v->name, "mailbox")) {
-                       ast_copy_string(mailbox, v->value, sizeof(mailbox));
+                       ast_copy_string(chan_conf.mailbox, v->value, sizeof(chan_conf.mailbox));
                } else if (!strcasecmp(v->name, "adsi")) {
-                       adsi = ast_true(v->value);
+                       chan_conf.adsi = ast_true(v->value);
                } else if (!strcasecmp(v->name, "transfer")) {
-                       transfer = ast_true(v->value);
+                       chan_conf.transfer = ast_true(v->value);
                } else if (!strcasecmp(v->name, "canpark")) {
-                       canpark = ast_true(v->value);
+                       chan_conf.canpark = ast_true(v->value);
                } else if (!strcasecmp(v->name, "echocancelwhenbridged")) {
-                       echocanbridged = ast_true(v->value);
+                       chan_conf.echocanbridged = ast_true(v->value);
                } else if (!strcasecmp(v->name, "busydetect")) {
-                       busydetect = ast_true(v->value);
+                       chan_conf.busydetect = ast_true(v->value);
                } else if (!strcasecmp(v->name, "busycount")) {
-                       busycount = atoi(v->value);
+                       chan_conf.busycount = atoi(v->value);
                } else if (!strcasecmp(v->name, "busypattern")) {
-                       if (sscanf(v->value, "%d,%d", &busy_tonelength, &busy_quietlength) != 2) {
+                       if (sscanf(v->value, "%d,%d", &chan_conf.busy_tonelength, &chan_conf.busy_quietlength) != 2) {
                                ast_log(LOG_ERROR, "busypattern= expects busypattern=tonelength,quietlength\n");
                        }
                } else if (!strcasecmp(v->name, "callprogress")) {
                        if (ast_true(v->value))
-                               callprogress |= 1;
+                               chan_conf.callprogress |= 1;
                        else
-                               callprogress &= ~1;
+                               chan_conf.callprogress &= ~1;
                } else if (!strcasecmp(v->name, "faxdetect")) {
                        if (!strcasecmp(v->value, "incoming")) {
-                               callprogress |= 4;
-                               callprogress &= ~2;
+                               chan_conf.callprogress |= 4;
+                               chan_conf.callprogress &= ~2;
                        } else if (!strcasecmp(v->value, "outgoing")) {
-                               callprogress &= ~4;
-                               callprogress |= 2;
+                               chan_conf.callprogress &= ~4;
+                               chan_conf.callprogress |= 2;
                        } else if (!strcasecmp(v->value, "both") || ast_true(v->value))
-                               callprogress |= 6;
+                               chan_conf.callprogress |= 6;
                        else
-                               callprogress &= ~6;
+                               chan_conf.callprogress &= ~6;
                } else if (!strcasecmp(v->name, "echocancel")) {
                        if (!ast_strlen_zero(v->value)) {
                                y = atoi(v->value);
                        } else
                                y = 0;
                        if ((y == 32) || (y == 64) || (y == 128) || (y == 256) || (y == 512) || (y == 1024))
-                               echocancel = y;
+                               chan_conf.echocancel = y;
                        else {
-                               echocancel = ast_true(v->value);
-                               if (echocancel)
-                                       echocancel=128;
+                               chan_conf.echocancel = ast_true(v->value);
+                               if (chan_conf.echocancel)
+                                       chan_conf.echocancel=128;
                        }
                } else if (!strcasecmp(v->name, "echotraining")) {
                        if (sscanf(v->value, "%d", &y) == 1) {
                                if ((y < 10) || (y > 4000)) {
                                        ast_log(LOG_WARNING, "Echo training time must be within the range of 10 to 2000 ms at line %d\n", v->lineno);                                   
                                } else {
-                                       echotraining = y;
+                                       chan_conf.echotraining = y;
                                }
                        } else if (ast_true(v->value)) {
-                               echotraining = 400;
+                               chan_conf.echotraining = 400;
                        } else
-                               echotraining = 0;
+                               chan_conf.echotraining = 0;
                } else if (!strcasecmp(v->name, "hidecallerid")) {
-                       hidecallerid = ast_true(v->value);
+                       chan_conf.hidecallerid = ast_true(v->value);
                } else if (!strcasecmp(v->name, "pulsedial")) {
-                       pulse = ast_true(v->value);
+                       chan_conf.pulse = ast_true(v->value);
                } else if (!strcasecmp(v->name, "callreturn")) {
-                       callreturn = ast_true(v->value);
+                       chan_conf.callreturn = ast_true(v->value);
                } else if (!strcasecmp(v->name, "callwaiting")) {
-                       callwaiting = ast_true(v->value);
+                       chan_conf.callwaiting = ast_true(v->value);
                } else if (!strcasecmp(v->name, "callwaitingcallerid")) {
-                       callwaitingcallerid = ast_true(v->value);
+                       chan_conf.callwaitingcallerid = ast_true(v->value);
                } else if (!strcasecmp(v->name, "context")) {
-                       ast_copy_string(context, v->value, sizeof(context));
+                       ast_copy_string(chan_conf.context, v->value, sizeof(chan_conf.context));
                } else if (!strcasecmp(v->name, "language")) {
                        ast_copy_string(language, v->value, sizeof(language));
                } else if (!strcasecmp(v->name, "progzone")) {
                        ast_copy_string(progzone, v->value, sizeof(progzone));
                } else if (!strcasecmp(v->name, "musiconhold")) {
-                       ast_copy_string(musicclass, v->value, sizeof(musicclass));
+                       ast_copy_string(chan_conf.musicclass, v->value, sizeof(chan_conf.musicclass));
                } else if (!strcasecmp(v->name, "stripmsd")) {
-                       stripmsd = atoi(v->value);
+                       chan_conf.stripmsd = atoi(v->value);
                } else if (!strcasecmp(v->name, "jitterbuffers")) {
                        numbufs = atoi(v->value);
                } else if (!strcasecmp(v->name, "group")) {
-                       cur_group = ast_get_group(v->value);
+                       chan_conf.group = ast_get_group(v->value);
                } else if (!strcasecmp(v->name, "callgroup")) {
-                       if (!strcasecmp(v->value, "none"))
-                               cur_callergroup = 0;
-                       else
-                               cur_callergroup = ast_get_group(v->value);
+                       chan_conf.callergroup = ast_get_group(v->value);
                } else if (!strcasecmp(v->name, "pickupgroup")) {
-                       if (!strcasecmp(v->value, "none"))
-                               cur_pickupgroup = 0;
-                       else
-                               cur_pickupgroup = ast_get_group(v->value);
+                       chan_conf.pickupgroup = ast_get_group(v->value);
                } else if (!strcasecmp(v->name, "immediate")) {
-                       immediate = ast_true(v->value);
+                       chan_conf.immediate = ast_true(v->value);
                } else if (!strcasecmp(v->name, "transfertobusy")) {
-                       transfertobusy = ast_true(v->value);
+                       chan_conf.transfertobusy = ast_true(v->value);
                } else if (!strcasecmp(v->name, "rxgain")) {
-                       if (sscanf(v->value, "%f", &rxgain) != 1) {
+                       if (sscanf(v->value, "%f", &chan_conf.rxgain) != 1) {
                                ast_log(LOG_WARNING, "Invalid rxgain: %s\n", v->value);
                        }
                } else if (!strcasecmp(v->name, "txgain")) {
-                       if (sscanf(v->value, "%f", &txgain) != 1) {
+                       if (sscanf(v->value, "%f", &chan_conf.txgain) != 1) {
                                ast_log(LOG_WARNING, "Invalid txgain: %s\n", v->value);
                        }
                } else if (!strcasecmp(v->name, "tonezone")) {
-                       if (sscanf(v->value, "%d", &tonezone) != 1) {
+                       if (sscanf(v->value, "%d", &chan_conf.tonezone) != 1) {
                                ast_log(LOG_WARNING, "Invalid tonezone: %s\n", v->value);
                        }
                } else if (!strcasecmp(v->name, "callerid")) {
                        if (!strcasecmp(v->value, "asreceived")) {
-                               cid_num[0] = '\0';
-                               cid_name[0] = '\0';
+                               chan_conf.cid_num[0] = '\0';
+                               chan_conf.cid_name[0] = '\0';
                        } else {
-                               ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
+                               ast_callerid_split(v->value, chan_conf.cid_name, sizeof(chan_conf.cid_name), chan_conf.cid_num, sizeof(chan_conf.cid_num));
                        }
                } else if (!strcasecmp(v->name, "useincomingcalleridonzaptransfer")) {
-                       zaptrcallerid = ast_true(v->value);
+                       chan_conf.zaptrcallerid = ast_true(v->value);
                } else if (!strcasecmp(v->name, "restrictcid")) {
-                       restrictcid = ast_true(v->value);
+                       chan_conf.restrictcid = ast_true(v->value);
                } else if (!strcasecmp(v->name, "usecallingpres")) {
-                       use_callingpres = ast_true(v->value);
+                       chan_conf.use_callingpres = ast_true(v->value);
                } else if (!strcasecmp(v->name, "accountcode")) {
-                       ast_copy_string(accountcode, v->value, sizeof(accountcode));
+                       ast_copy_string(chan_conf.accountcode, v->value, sizeof(chan_conf.accountcode));
                } else if (!strcasecmp(v->name, "amaflags")) {
                        y = ast_cdr_amaflags2int(v->value);
                        if (y < 0) 
                                ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
                        else
-                               amaflags = y;
+                               chan_conf.amaflags = y;
                } else if(!reload){ 
                         if (!strcasecmp(v->name, "signalling")) {
                                if (!strcasecmp(v->value, "em")) {
-                                       cur_signalling = SIG_EM;
+                                       chan_conf.signalling = SIG_EM;
                                } else if (!strcasecmp(v->value, "em_e1")) {
-                                       cur_signalling = SIG_EM_E1;
+                                       chan_conf.signalling = SIG_EM_E1;
                                } else if (!strcasecmp(v->value, "em_w")) {
-                                       cur_signalling = SIG_EMWINK;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_EMWINK;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "fxs_ls")) {
-                                       cur_signalling = SIG_FXSLS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FXSLS;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "fxs_gs")) {
-                                       cur_signalling = SIG_FXSGS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FXSGS;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "fxs_ks")) {
-                                       cur_signalling = SIG_FXSKS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FXSKS;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "fxo_ls")) {
-                                       cur_signalling = SIG_FXOLS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FXOLS;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "fxo_gs")) {
-                                       cur_signalling = SIG_FXOGS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FXOGS;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "fxo_ks")) {
-                                       cur_signalling = SIG_FXOKS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FXOKS;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "fxs_rx")) {
-                                       cur_signalling = SIG_FXSKS;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_FXSKS;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "fxo_rx")) {
-                                       cur_signalling = SIG_FXOLS;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_FXOLS;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "fxs_tx")) {
-                                       cur_signalling = SIG_FXSLS;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_FXSLS;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "fxo_tx")) {
-                                       cur_signalling = SIG_FXOGS;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_FXOGS;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "em_rx")) {
-                                       cur_signalling = SIG_EM;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_EM;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "em_tx")) {
-                                       cur_signalling = SIG_EM;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_EM;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "em_rxtx")) {
-                                       cur_signalling = SIG_EM;
-                                       cur_radio = 2;
+                                       chan_conf.signalling = SIG_EM;
+                                       chan_conf.radio = 2;
                                } else if (!strcasecmp(v->value, "em_txrx")) {
-                                       cur_signalling = SIG_EM;
-                                       cur_radio = 2;
+                                       chan_conf.signalling = SIG_EM;
+                                       chan_conf.radio = 2;
                                } else if (!strcasecmp(v->value, "sf")) {
-                                       cur_signalling = SIG_SF;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_SF;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "sf_w")) {
-                                       cur_signalling = SIG_SFWINK;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_SFWINK;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "sf_featd")) {
-                                       cur_signalling = SIG_FEATD;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FEATD;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "sf_featdmf")) {
-                                       cur_signalling = SIG_FEATDMF;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FEATDMF;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "sf_featb")) {
-                                       cur_signalling = SIG_SF_FEATB;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_SF_FEATB;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "sf")) {
-                                       cur_signalling = SIG_SF;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_SF;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "sf_rx")) {
-                                       cur_signalling = SIG_SF;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_SF;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "sf_tx")) {
-                                       cur_signalling = SIG_SF;
-                                       cur_radio = 1;
+                                       chan_conf.signalling = SIG_SF;
+                                       chan_conf.radio = 1;
                                } else if (!strcasecmp(v->value, "sf_rxtx")) {
-                                       cur_signalling = SIG_SF;
-                                       cur_radio = 2;
+                                       chan_conf.signalling = SIG_SF;
+                                       chan_conf.radio = 2;
                                } else if (!strcasecmp(v->value, "sf_txrx")) {
-                                       cur_signalling = SIG_SF;
-                                       cur_radio = 2;
+                                       chan_conf.signalling = SIG_SF;
+                                       chan_conf.radio = 2;
                                } else if (!strcasecmp(v->value, "featd")) {
-                                       cur_signalling = SIG_FEATD;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FEATD;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "featdmf")) {
-                                       cur_signalling = SIG_FEATDMF;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FEATDMF;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "featdmf_ta")) {
-                                       cur_signalling = SIG_FEATDMF_TA;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FEATDMF_TA;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "e911")) {
-                                       cur_signalling = SIG_E911;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_E911;
+                                       chan_conf.radio = 0;
                                } else if (!strcasecmp(v->value, "featb")) {
-                                       cur_signalling = SIG_FEATB;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_FEATB;
+                                       chan_conf.radio = 0;
 #ifdef ZAPATA_PRI
                                } else if (!strcasecmp(v->value, "pri_net")) {
-                                       cur_radio = 0;
-                                       cur_signalling = SIG_PRI;
+                                       chan_conf.radio = 0;
+                                       chan_conf.signalling = SIG_PRI;
                                        pritype = PRI_NETWORK;
                                } else if (!strcasecmp(v->value, "pri_cpe")) {
-                                       cur_signalling = SIG_PRI;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_PRI;
+                                       chan_conf.radio = 0;
                                        pritype = PRI_CPE;
                                } else if (!strcasecmp(v->value, "gr303fxoks_net")) {
-                                       cur_signalling = SIG_GR303FXOKS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_GR303FXOKS;
+                                       chan_conf.radio = 0;
                                        pritype = PRI_NETWORK;
                                } else if (!strcasecmp(v->value, "gr303fxsks_cpe")) {
-                                       cur_signalling = SIG_GR303FXSKS;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_GR303FXSKS;
+                                       chan_conf.radio = 0;
                                        pritype = PRI_CPE;
 #endif
 #ifdef ZAPATA_R2
                                } else if (!strcasecmp(v->value, "r2")) {
-                                       cur_signalling = SIG_R2;
-                                       cur_radio = 0;
+                                       chan_conf.signalling = SIG_R2;
+                                       chan_conf.radio = 0;
 #endif                 
                                } else {
                                        ast_log(LOG_ERROR, "Unknown signalling method '%s'\n", v->value);
@@ -10684,42 +10829,42 @@ static int setup_zap(int reload)
                                }
                        } else if (!strcasecmp(v->name, "priindication")) {
                                if (!strcasecmp(v->value, "outofband"))
-                                       priindication_oob = 1;
+                                       chan_conf.priindication_oob = 1;
                                else if (!strcasecmp(v->value, "inband"))
-                                       priindication_oob = 0;
+                                       chan_conf.priindication_oob = 0;
                                else
                                        ast_log(LOG_WARNING, "'%s' is not a valid pri indication value, should be 'inband' or 'outofband' at line %d\n",
                                                v->value, v->lineno);
                        } else if (!strcasecmp(v->name, "priexclusive")) {
-                               cur_priexclusive = ast_true(v->value);
+                               chan_conf.priexclusive = ast_true(v->value);
                        } else if (!strcasecmp(v->name, "internationalprefix")) {
-                               ast_copy_string(internationalprefix, v->value, sizeof(internationalprefix));
+                               ast_copy_string(chan_conf.pri.internationalprefix, v->value, sizeof(chan_conf.pri.internationalprefix));
                        } else if (!strcasecmp(v->name, "nationalprefix")) {
-                               ast_copy_string(nationalprefix, v->value, sizeof(nationalprefix));
+                               ast_copy_string(chan_conf.pri.nationalprefix, v->value, sizeof(chan_conf.pri.nationalprefix));
                        } else if (!strcasecmp(v->name, "localprefix")) {
-                               ast_copy_string(localprefix, v->value, sizeof(localprefix));
+                               ast_copy_string(chan_conf.pri.localprefix, v->value, sizeof(chan_conf.pri.localprefix));
                        } else if (!strcasecmp(v->name, "privateprefix")) {
-                               ast_copy_string(privateprefix, v->value, sizeof(privateprefix));
+                               ast_copy_string(chan_conf.pri.privateprefix, v->value, sizeof(chan_conf.pri.privateprefix));
                        } else if (!strcasecmp(v->name, "unknownprefix")) {
-                               ast_copy_string(unknownprefix, v->value, sizeof(unknownprefix));
+                               ast_copy_string(chan_conf.pri.unknownprefix, v->value, sizeof(chan_conf.pri.unknownprefix));
                        } else if (!strcasecmp(v->name, "resetinterval")) {
                                if (!strcasecmp(v->value, "never"))
-                                       resetinterval = -1;
+                                       chan_conf.pri.resetinterval = -1;
                                else if( atoi(v->value) >= 60 )
-                                       resetinterval = atoi(v->value);
+                                       chan_conf.pri.resetinterval = atoi(v->value);
                                else
                                        ast_log(LOG_WARNING, "'%s' is not a valid reset interval, should be >= 60 seconds or 'never' at line %d\n",
                                                v->value, v->lineno);
                        } else if (!strcasecmp(v->name, "minunused")) {
-                               minunused = atoi(v->value);
+                               chan_conf.pri.minunused = atoi(v->value);
                        } else if (!strcasecmp(v->name, "minidle")) {
-                               minidle = atoi(v->value); 
+                               chan_conf.pri.minidle = atoi(v->value); 
                        } else if (!strcasecmp(v->name, "idleext")) {
-                               ast_copy_string(idleext, v->value, sizeof(idleext));
+                               ast_copy_string(chan_conf.pri.idleext, v->value, sizeof(chan_conf.pri.idleext));
                        } else if (!strcasecmp(v->name, "idledial")) {
-                               ast_copy_string(idledial, v->value, sizeof(idledial));
+                               ast_copy_string(chan_conf.pri.idledial, v->value, sizeof(chan_conf.pri.idledial));
                        } else if (!strcasecmp(v->name, "overlapdial")) {
-                               overlapdial = ast_true(v->value);
+                               chan_conf.pri.overlapdial = ast_true(v->value);
                        } else if (!strcasecmp(v->name, "pritimer")) {
 #ifdef PRI_GETSET_TIMERS
                                char *timerc;
@@ -10740,7 +10885,7 @@ static int setup_zap(int reload)
                                        ast_log(LOG_WARNING, "'%s' is not a valid ISDN timer configuration string\n", v->value);
 
                        } else if (!strcasecmp(v->name, "facilityenable")) {
-                               facilityenable = ast_true(v->value);
+                               chan_conf.pri.facilityenable = ast_true(v->value);
 #endif /* PRI_GETSET_TIMERS */
 #endif /* ZAPATA_PRI */
                        } else if (!strcasecmp(v->name, "cadence")) {
@@ -10827,21 +10972,21 @@ static int setup_zap(int reload)
                        } else if (!strcasecmp(v->name, "ringtimeout")) {
                                ringt_base = (atoi(v->value) * 8) / READ_SIZE;
                        } else if (!strcasecmp(v->name, "prewink")) {
-                               cur_prewink = atoi(v->value);
+                               chan_conf.prewink = atoi(v->value);
                        } else if (!strcasecmp(v->name, "preflash")) {
-                               cur_preflash = atoi(v->value);
+                               chan_conf.preflash = atoi(v->value);
                        } else if (!strcasecmp(v->name, "wink")) {
-                               cur_wink = atoi(v->value);
+                               chan_conf.wink = atoi(v->value);
                        } else if (!strcasecmp(v->name, "flash")) {
-                               cur_flash = atoi(v->value);
+                               chan_conf.flash = atoi(v->value);
                        } else if (!strcasecmp(v->name, "start")) {
-                               cur_start = atoi(v->value);
+                               chan_conf.start = atoi(v->value);
                        } else if (!strcasecmp(v->name, "rxwink")) {
-                               cur_rxwink = atoi(v->value);
+                               chan_conf.rxwink = atoi(v->value);
                        } else if (!strcasecmp(v->name, "rxflash")) {
-                               cur_rxflash = atoi(v->value);
+                               chan_conf.rxflash = atoi(v->value);
                        } else if (!strcasecmp(v->name, "debounce")) {
-                               cur_debounce = atoi(v->value);
+                               chan_conf.debounce = atoi(v->value);
                        } else if (!strcasecmp(v->name, "toneduration")) {
                                int toneduration;
                                int ctlfd;
@@ -10865,13 +11010,13 @@ static int setup_zap(int reload)
                                }
                                close(ctlfd);
                        } else if (!strcasecmp(v->name, "polarityonanswerdelay")) {
-                               polarityonanswerdelay = atoi(v->value);
+                               chan_conf.polarityonanswerdelay = atoi(v->value);
                        } else if (!strcasecmp(v->name, "answeronpolarityswitch")) {
-                               answeronpolarityswitch = ast_true(v->value);
+                               chan_conf.answeronpolarityswitch = ast_true(v->value);
                        } else if (!strcasecmp(v->name, "hanguponpolarityswitch")) {
-                               hanguponpolarityswitch = ast_true(v->value);
+                               chan_conf.hanguponpolarityswitch = ast_true(v->value);
                        } else if (!strcasecmp(v->name, "sendcalleridafter")) {
-                               sendcalleridafter = atoi(v->value);
+                               chan_conf.sendcalleridafter = atoi(v->value);
                        } else if (!strcasecmp(v->name, "defaultcic")) {
                                ast_copy_string(defaultcic, v->value, sizeof(defaultcic));
                        } else if (!strcasecmp(v->name, "defaultozz")) {
@@ -10885,11 +11030,11 @@ static int setup_zap(int reload)
        
                /* Make sure pseudo isn't a member of any groups if
                   we're automatically making it. */    
-               cur_group = 0;
-               cur_callergroup = 0;
-               cur_pickupgroup = 0;
+               chan_conf.group = 0;
+               chan_conf.callergroup = 0;
+               chan_conf.pickupgroup = 0;
        
-               tmp = mkintf(CHAN_PSEUDO, cur_signalling, cur_radio, NULL, reload);
+               tmp = mkintf(CHAN_PSEUDO, chan_conf, NULL, reload);
 
                if (tmp) {
                        if (option_verbose > 2)