762
762
/*! \brief TRUE if dynamic faxbuffers are configured for use, default is OFF */
763
763
unsigned int usefaxbuffers:1;
764
764
/*! \brief TRUE while dynamic faxbuffers are in use */
765
unsigned int faxbuffersinuse:1;
765
unsigned int bufferoverrideinuse:1;
766
766
/*! \brief TRUE if over a radio and dahdi_read() has been called. */
767
767
unsigned int firstradio:1;
1396
1396
static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
1397
1397
static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
1398
1398
static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
1399
static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
1399
1400
static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event);
1401
1402
static const struct ast_channel_tech dahdi_tech = {
5016
5018
case AST_OPTION_ECHOCAN:
5017
5019
cp = (char *) data;
5019
ast_debug(1, "Enabling echo cancelation on %s\n", chan->name);
5021
ast_debug(1, "Enabling echo cancellation on %s\n", chan->name);
5020
5022
dahdi_enable_ec(p);
5022
ast_debug(1, "Disabling echo cancelation on %s\n", chan->name);
5024
ast_debug(1, "Disabling echo cancellation on %s\n", chan->name);
5023
5025
dahdi_disable_ec(p);
5043
5046
ast_mutex_unlock(&p->lock);
5045
5048
ast_copy_string(buf, "", len);
5056
static int parse_buffers_policy(const char *parse, int *num_buffers, int *policy)
5059
char policy_str[21] = "";
5061
if (((res = sscanf(parse, "%d,%20s", num_buffers, policy_str)) != 2) &&
5062
((res = sscanf(parse, "%d|%20s", num_buffers, policy_str)) != 2)) {
5063
ast_log(LOG_WARNING, "Parsing buffer string '%s' failed.\n", parse);
5066
if (*num_buffers < 0) {
5067
ast_log(LOG_WARNING, "Invalid buffer count given '%d'.\n", *num_buffers);
5070
if (!strcasecmp(policy_str, "full")) {
5071
*policy = DAHDI_POLICY_WHEN_FULL;
5072
} else if (!strcasecmp(policy_str, "immediate")) {
5073
*policy = DAHDI_POLICY_IMMEDIATE;
5074
#ifdef DAHDI_POLICY_HALF_FULL
5075
} else if (!strcasecmp(policy_str, "half")) {
5076
*policy = DAHDI_POLICY_HALF_FULL;
5079
ast_log(LOG_WARNING, "Invalid policy name given '%s'.\n", policy_str);
5086
static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value)
5088
struct dahdi_pvt *p = chan->tech_pvt;
5091
if (!strcasecmp(data, "buffers")) {
5092
int num_bufs, policy;
5094
if (!(parse_buffers_policy(value, &num_bufs, &policy))) {
5095
struct dahdi_bufferinfo bi = {
5096
.txbufpolicy = policy,
5097
.rxbufpolicy = policy,
5098
.bufsize = p->bufsize,
5099
.numbufs = num_bufs,
5103
if ((bpres = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
5104
ast_log(LOG_WARNING, "Channel '%d' unable to override buffer policy: %s\n", p->channel, strerror(errno));
5106
p->bufferoverrideinuse = 1;
5051
5118
static void dahdi_unlink(struct dahdi_pvt *slave, struct dahdi_pvt *master, int needlock)
5396
5462
#ifdef PRI_2BCT
5399
if (p0->transfer && p1->transfer
5401
&& !triedtopribridge) {
5402
pri_channel_bridge(q931c0, q931c1);
5463
if (!triedtopribridge) {
5403
5464
triedtopribridge = 1;
5465
if (p0->pri && p0->pri == p1->pri && p0->transfer && p1->transfer) {
5466
ast_mutex_lock(&p0->pri->lock);
5467
if (p0->call && p1->call) {
5468
pri_channel_bridge(p0->call, p1->call);
5470
ast_mutex_unlock(&p0->pri->lock);
5642
5710
/* Fax tone -- Handle and return NULL */
5643
5711
if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
5644
5712
/* If faxbuffers are configured, use them for the fax transmission */
5645
if (p->usefaxbuffers && !p->faxbuffersinuse) {
5713
if (p->usefaxbuffers && !p->bufferoverrideinuse) {
5646
5714
struct dahdi_bufferinfo bi = {
5647
5715
.txbufpolicy = p->faxbuf_policy,
5648
5716
.bufsize = p->bufsize,
8381
8449
if (p->cid_signalling == CID_SIG_DTMF) {
8384
ast_debug(1, "Receiving DTMF cid on "
8385
"channel %s\n", chan->name);
8452
ast_debug(1, "Receiving DTMF cid on channel %s\n", chan->name);
8386
8453
dahdi_setlinear(p->subs[idx].dfd, 0);
8455
* We are the only party interested in the Rx stream since
8456
* we have not answered yet. We don't need or even want DTMF
8457
* emulation. The DTMF digits can come so fast that emulation
8458
* can drop some of them.
8460
ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
8461
res = 4000;/* This is a typical OFF time between rings. */
8389
8463
struct ast_frame *f;
8390
8464
res = ast_waitfor(chan, res);
8391
8465
if (res <= 0) {
8467
* We do not need to restore the dahdi_setlinear()
8468
* or AST_FLAG_END_DTMF_ONLY flag settings since we
8469
* are hanging up the channel.
8392
8471
ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
8393
8472
"Exiting simple switch\n");
8394
8473
ast_hangup(chan);
8400
8479
if (f->frametype == AST_FRAME_DTMF) {
8401
dtmfbuf[k++] = f->subclass;
8480
if (k < ARRAY_LEN(dtmfbuf) - 1) {
8481
dtmfbuf[k++] = f->subclass;
8402
8483
ast_debug(1, "CID got digit '%c'\n", f->subclass);
8484
res = 4000;/* This is a typical OFF time between rings. */
8406
8487
if (chan->_state == AST_STATE_RING ||
8407
8488
chan->_state == AST_STATE_RINGING)
8408
8489
break; /* Got ring */
8491
ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
8410
8492
dtmfbuf[k] = '\0';
8411
8493
dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
8412
8494
/* Got cid and ring. */
8413
8495
ast_debug(1, "CID got string '%s'\n", dtmfbuf);
8414
8496
callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
8415
ast_debug(1, "CID is '%s', flags %d\n",
8497
ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
8417
8498
/* If first byte is NULL, we have no cid */
8418
8499
if (!ast_strlen_zero(dtmfcid))
8419
8500
number = dtmfcid;
8474
8555
res = callerid_feed(cs, buf, res, AST_LAW(p));
8478
ast_log(LOG_WARNING, "CallerID feed failed on channel '%s'\n", chan->name);
8559
* The previous diagnostic message output likely
8560
* explains why it failed.
8562
ast_log(LOG_WARNING,
8563
"Failed to decode CallerID on channel '%s'\n",
8480
8566
} else if (res)
8491
8577
if (p->cid_signalling == CID_SIG_V23_JP) {
8492
8578
res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_ONHOOK);
8497
/* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
8582
/* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
8583
res = 4000;/* This is a typical OFF time between rings. */
8502
8585
struct ast_frame *f;
8503
8586
res = ast_waitfor(chan, res);
8740
8823
samples += res;
8741
8824
res = callerid_feed(cs, buf, res, AST_LAW(p));
8743
ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno));
8827
* The previous diagnostic message output likely
8828
* explains why it failed.
8830
ast_log(LOG_WARNING,
8831
"Failed to decode CallerID on channel '%s'\n",
8745
8834
} else if (res)
9017
9106
samples += res;
9018
9107
if (!spill_done) {
9019
9108
if ((spill_result = callerid_feed(cs, mtd->buf, res, AST_LAW(mtd->pvt))) < 0) {
9020
ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno));
9110
* The previous diagnostic message output likely
9111
* explains why it failed.
9113
ast_log(LOG_WARNING, "Failed to decode CallerID\n");
9022
9115
} else if (spill_result) {
9023
9116
spill_done = 1;
16147
16241
ast_log(LOG_DEBUG, "Channel '%s' configured.\n", v->value);
16148
16242
} else if (!strcasecmp(v->name, "buffers")) {
16150
char policy[21] = "";
16152
res = sscanf(v->value, "%30d,%20s", &confp->chan.buf_no, policy);
16154
ast_log(LOG_WARNING, "Parsing buffers option data failed, using defaults.\n");
16155
confp->chan.buf_no = numbufs;
16158
if (confp->chan.buf_no < 0)
16159
confp->chan.buf_no = numbufs;
16160
if (!strcasecmp(policy, "full")) {
16161
confp->chan.buf_policy = DAHDI_POLICY_WHEN_FULL;
16162
} else if (!strcasecmp(policy, "immediate")) {
16243
if (parse_buffers_policy(v->value, &confp->chan.buf_no, &confp->chan.buf_policy)) {
16244
ast_log(LOG_WARNING, "Using default buffer policy.\n");
16245
confp->chan.buf_no = numbufs;
16163
16246
confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE;
16164
#ifdef HAVE_DAHDI_HALF_FULL
16165
} else if (!strcasecmp(policy, "half_full")) {
16166
confp->chan.buf_policy = DAHDI_POLICY_HALF_FULL;
16169
ast_log(LOG_WARNING, "Invalid policy name given (%s).\n", policy);
16171
16248
} else if (!strcasecmp(v->name, "faxbuffers")) {
16173
char policy[21] = "";
16175
res = sscanf(v->value, "%30d,%20s", &confp->chan.faxbuf_no, policy);
16177
ast_log(LOG_WARNING, "Parsing faxbuffers option data failed, using defaults.\n");
16178
confp->chan.faxbuf_no = numbufs;
16181
confp->chan.usefaxbuffers = 1;
16182
if (confp->chan.faxbuf_no < 0)
16183
confp->chan.faxbuf_no = numbufs;
16184
if (!strcasecmp(policy, "full")) {
16185
confp->chan.faxbuf_policy = DAHDI_POLICY_WHEN_FULL;
16186
} else if (!strcasecmp(policy, "immediate")) {
16187
confp->chan.faxbuf_policy = DAHDI_POLICY_IMMEDIATE;
16189
ast_log(LOG_WARNING, "Invalid policy name given (%s).\n", policy);
16190
confp->chan.usefaxbuffers = 0;
16192
} else if (!strcasecmp(v->name, "dahdichan")) {
16249
if (!parse_buffers_policy(v->value, &confp->chan.faxbuf_no, &confp->chan.faxbuf_policy)) {
16250
confp->chan.usefaxbuffers = 1;
16252
} else if (!strcasecmp(v->name, "dahdichan")) {
16193
16253
ast_copy_string(dahdichan, v->value, sizeof(dahdichan));
16194
16254
} else if (!strcasecmp(v->name, "usedistinctiveringdetection")) {
16195
16255
usedistinctiveringdetection = ast_true(v->value);