62#define POLARITY_IDLE 0
64#define MIN_MS_SINCE_FLASH ( (2000) )
107#define ISTRUNK(p) ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || \
108 (p->sig == ANALOG_SIG_FXSGS))
219#define gen_analog_field_callback(type, callback_name, def_value) \
220 static type analog_get_##callback_name(struct analog_pvt *p) \
222 if (!analog_callbacks.get_##callback_name) { \
225 return analog_callbacks.get_##callback_name(p->chan_pvt); \
232#undef gen_analog_field_callback
236 if (!strcasecmp(
value,
"ring")) {
238 }
else if (!strcasecmp(
value,
"polarity")) {
240 }
else if (!strcasecmp(
value,
"polarity_in")) {
242 }
else if (!strcasecmp(
value,
"dtmf")) {
257 return "Polarity_In";
270 res =
"ANALOG_EVENT_ONHOOK";
273 res =
"ANALOG_EVENT_RINGOFFHOOK";
276 res =
"ANALOG_EVENT_WINKFLASH";
279 res =
"ANALOG_EVENT_ALARM";
282 res =
"ANALOG_EVENT_NOALARM";
285 res =
"ANALOG_EVENT_DIALCOMPLETE";
288 res =
"ANALOG_EVENT_HOOKCOMPLETE";
291 res =
"ANALOG_EVENT_PULSE_START";
294 res =
"ANALOG_EVENT_POLARITY";
297 res =
"ANALOG_EVENT_RINGBEGIN";
300 res =
"ANALOG_EVENT_EC_DISABLED";
303 res =
"ANALOG_EVENT_RINGERON";
306 res =
"ANALOG_EVENT_RINGEROFF";
309 res =
"ANALOG_EVENT_REMOVED";
312 res =
"ANALOG_EVENT_NEONMWI_ACTIVE";
315 res =
"ANALOG_EVENT_NEONMWI_INACTIVE";
317#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
319 res =
"ANALOG_EVENT_TX_CED_DETECTED";
322 res =
"ANALOG_EVENT_RX_CED_DETECTED";
325 res =
"ANALOG_EVENT_EC_NLP_DISABLED";
328 res =
"ANALOG_EVENT_EC_NLP_ENABLED";
332 res =
"ANALOG_EVENT_PULSEDIGIT";
335 res =
"ANALOG_EVENT_DTMFDOWN";
338 res =
"ANALOG_EVENT_DTMFUP";
341 res =
"UNKNOWN/OTHER";
393 ast_debug(1,
"Sending callerid. CID_NAME: '%s' CID_NUM: '%s'\n",
407#define analog_get_index(ast, p, nullok) _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__)
421 "Unable to get index for '%s' on channel %d (%s(), line %lu)\n",
448 p->
owner = new_owner;
720 ast_verb(3,
"TRANSFERRING %s to %s\n",
749 for (
x = 0;
x < 3;
x++) {
762 ast_debug(1,
"Updated conferencing on %d, with %d conference users\n", p->
channel, needconf);
819#ifdef DAHDI_CHECK_HOOKSTATE
826 }
else if (offhook) {
996 ast_debug(1,
"CALLING CID_NAME: %s CID_NUM:: %s\n",
1025 if (p->
owner == ast) {
1033 c = strchr(dest,
'/');
1048 ast_debug(1,
"FXO: setup deferred dialstring: %s\n",
c);
1097 const char *qual_var;
1146 ast_debug(1,
"Ignore possible polarity reversal on line seizure\n");
1165 c = strchr(dest,
'/');
1177 if (
errno != EINPROGRESS) {
1205 const char *cic =
"", *ozz =
"";
1219 ast_log(
LOG_WARNING,
"Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1304 ast_debug(1,
"Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
1315 ast_debug(1,
"Normal call hung up with both three way call and a call waiting call in place?\n");
1318 ast_debug(1,
"We were flipped over to the callwait, moving back and not owning.\n");
1325 ast_debug(1,
"We were in the threeway and have a callwait still. Ditching the threeway.\n");
1331 ast_debug(1,
"Call was complete, setting owner to former third call\n");
1336 ast_debug(1,
"Call was incomplete, setting owner to NULL\n");
1365 ast_debug(1,
"Call was complete, setting owner to former third call\n");
1370 ast_debug(1,
"Call was incomplete, setting owner to NULL\n");
1536 ast_debug(1,
"Finally swapping real and threeway\n");
1597 ast_debug(1,
"%s DTMF digit: 0x%02X '%c' on %s\n",
1614 *dest = &p->
subs[idx].
f;
1618 ast_debug(1,
"Got some DTMF, but it's for the CAS\n");
1629 *dest = &p->
subs[idx].
f;
1649 if (strchr(term,
c)) {
1713#define ANALOG_NEED_MFDETECT(p) (((p)->sig == ANALOG_SIG_FEATDMF) || ((p)->sig == ANALOG_SIG_FEATDMF_TA) || ((p)->sig == ANALOG_SIG_E911) || ((p)->sig == ANALOG_SIG_FGC_CAMA) || ((p)->sig == ANALOG_SIG_FGC_CAMAMF) || ((p)->sig == ANALOG_SIG_FEATB))
1717 int extlen = strlen(exten);
1721 if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) {
1725 if (exten[0] ==
'*' && extlen < 3) {
1761 const char *pickupexten;
1792 ast_log(
LOG_ERROR,
"Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
1795 pickupexten =
ast_strdupa(pickup_cfg->pickupexten);
1830 memset(dtmfbuf, 0,
sizeof(dtmfbuf));
1875 && (strlen(dtmfbuf) != 14)) {
1923 dtmfbuf[
len] =
'\0';
1926 timeout = analog_get_matchdigit_timeout(p);
1928 timeout = analog_get_interdigit_timeout(p);
1932 ast_debug(1,
"waitfordigit returned < 0...\n");
1936 dtmfbuf[
len++] = res;
1937 dtmfbuf[
len] =
'\0';
1949 }
else if (res < 0) {
1950 ast_debug(1,
"Got hung up before digits finished\n");
1973 ast_debug(1,
"cnoffset: %d\n", cnoffset);
1982 ast_debug(1,
"Sent wink to signal ANI start\n");
1994 if ((res > 0) || (strlen(anibuf) >= 2)) {
1995 char anistart[2] =
"X";
1997 if (strchr(
"#ABC", anibuf[strlen(anibuf) - 1])) {
1998 anistart[0] = anibuf[strlen(anibuf) - 1];
1999 anibuf[strlen(anibuf) - 1] = 0;
2005 caller->
ani2 = atoi(f);
2007 anibuf[cnoffset] = 0;
2023 if (exten[0] ==
'*') {
2028 s1 =
strsep(&stringp,
"*");
2029 s2 =
strsep(&stringp,
"*");
2045 if (exten[0] ==
'*') {
2052 s1 =
strsep(&stringp,
"#");
2053 s2 =
strsep(&stringp,
"#");
2070 caller->
ani2 = atoi(s1);
2076 if (exten[0] ==
'*') {
2081 s1 =
strsep(&stringp,
"#");
2082 s2 =
strsep(&stringp,
"#");
2083 if (s2 && (*(s2 + 1) ==
'0')) {
2094 ast_log(
LOG_WARNING,
"A KP was expected to start signaling for Feature Group C CAMA-MF, but we got something else. Received: %s on channel %d\n", exten, p->
channel);
2098 if (exten[0] ==
'*') {
2103 s1 =
strsep(&stringp,
"#");
2106 ast_log(
LOG_WARNING,
"A KP was expected to start signaling for Feature Group B, but we got something else. Received: %s on channel %d\n", exten, p->
channel);
2170 timeout = analog_get_firstdigit_timeout(p);
2178 int is_exten_parking = 0;
2189 ast_debug(1,
"waitfordigit returned < 0...\n");
2194 ast_debug(1,
"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2219 memset(exten, 0,
sizeof(exten));
2252 timeout = analog_get_matchdigit_timeout(p);
2254 }
else if (res == 0) {
2255 ast_debug(1,
"not enough digits (and no ambiguous match)...\n");
2257 ast_debug(1,
"Nothing dialed at three-way dial tone, timed out to silent hold\n");
2264 }
else if (p->
callwaiting && !strcmp(exten,
"*70")) {
2274 memset(exten, 0,
sizeof(exten));
2275 timeout = analog_get_firstdigit_timeout(p);
2277 }
else if (!strcmp(exten, pickupexten)) {
2293 ast_debug(1,
"No call pickup possible...\n");
2307 }
else if (!p->
hidecallerid && !strcmp(exten,
"*67")) {
2319 memset(exten, 0,
sizeof(exten));
2320 timeout = analog_get_firstdigit_timeout(p);
2321 }
else if (p->
callreturn && !strcmp(exten,
"*69")) {
2330 }
else if (!strcmp(exten,
"*78")) {
2335 memset(exten, 0,
sizeof(exten));
2337 }
else if (!strcmp(exten,
"*79")) {
2342 memset(exten, 0,
sizeof(exten));
2347 memset(exten, 0,
sizeof(exten));
2350 ast_verb(3,
"Cancelling call forwarding on channel %d\n", p->
channel);
2354 memset(exten, 0,
sizeof(exten));
2367 if (bridge_channel) {
2391 memset(exten, 0,
sizeof(exten));
2406 memset(exten, 0,
sizeof(exten));
2407 timeout = analog_get_firstdigit_timeout(p);
2408 }
else if (!strcmp(exten,
"*0")) {
2415 if (pbridge &&
ISTRUNK(pbridge)) {
2421 "Unable to flash-hook bridged trunk from channel %s: %s\n",
2443 ast_debug(1,
"Can't match %s from '%s' in context %s\n", exten,
2450 timeout = analog_get_interdigit_timeout(p);
2463 if (smdi_msg !=
NULL) {
2466 if (smdi_msg->
type ==
'B')
2468 else if (smdi_msg->
type ==
'N')
2520 "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2549 ast_debug(1,
"CID got string '%s'\n", dtmfbuf);
2565 int timeout = 10000;
2570 struct timeval off_start;
2580 "CallerID returned with error on channel '%s'\n",
2620 "CID timed out waiting for ring. Exiting simple switch\n");
2647 "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2657 int timeout = 10000;
2661 int ring_data_idx = 0;
2672 "CallerID returned with error on channel '%s'\n",
2688 "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2701 ring_data[ring_data_idx] = p->
ringt;
2783 int data_size =
sizeof(*cause_code);
2784 char *subclass =
NULL;
2807 p->
subs[idx].
f.
src =
"dahdi_handle_event";
2809 f = &p->
subs[idx].
f;
2824 ast_debug(1,
"Dropping pulse digit '%c' because pulse dialing disabled on channel %d\n", res & 0xff, p->
channel);
2830 ast_debug(1,
"DTMF Down '%c'\n", res & 0xff);
2846 data_size += strlen(subclass);
2848 memset(cause_code, 0, data_size);
2851 snprintf(cause_code->
code, data_size -
sizeof(*cause_code) + 1,
"ANALOG %s", subclass);
2859 ast_verb(3,
"Channel %d echo canceller disabled due to CED detection\n", p->
channel);
2862#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2864 ast_verb(3,
"Channel %d detected a CED tone towards the network.\n", p->
channel);
2867 ast_verb(3,
"Channel %d detected a CED tone from the network.\n", p->
channel);
2870 ast_verb(3,
"Channel %d echo canceller disabled its NLP.\n", p->
channel);
2873 ast_verb(3,
"Channel %d echo canceller enabled its NLP.\n", p->
channel);
2910 ast_debug(1,
"Done dialing, but waiting for progress detection before doing more...\n");
2944 ast_debug(2,
"Letting this call hang up normally, since it's not the only call\n");
2956 ast_debug(2,
"Called Subscriber Held does not apply: not an incoming call\n");
2995 ast_verb(3,
"Channel %d still has (callwait) call, ringing phone\n", p->
channel);
3007 unsigned int mssinceflash;
3016 if (p->
owner != ast) {
3024 ast_debug(1,
"Last flash was %u ms ago\n", mssinceflash);
3028 ast_debug(1,
"Looks like a bounced flash, hanging up both calls on %d\n", p->
channel);
3115 return &p->
subs[idx].
f;
3160 return &p->
subs[idx].
f;
3167 return &p->
subs[idx].
f;
3287 ast_debug(1,
"Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3361 ast_debug(1,
"Flash when call not up or ringing\n");
3384 "Cannot allocate new call structure on channel %d\n",
3441 ast_debug(1,
"Got flash with three way call up, dropping last call on %d\n", p->
channel);
3459 ast_verb(3,
"Building conference call with %s and %s\n",
3513 ast_log(
LOG_WARNING,
"Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3578 ast_debug(1,
"Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->
channel);
3608 ast_debug(1,
"Ignore Answer on polarity switch, channel %d\n", p->
channel);
3621 ast_debug(1,
"Ignore Hangup on polarity switch, channel %d\n", p->
channel);
3665 ast_debug(1,
"Polarity Reversal event occured - DEBUG 2: channel %d, state %u, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %" PRIi64
"\n", p->
channel,
ast_channel_state(ast), p->
polarity, p->
answeronpolarityswitch, p->
hanguponpolarityswitch, p->
polarityonanswerdelay,
ast_tvdiff_ms(
ast_tvnow(), p->
polaritydelaytv) );
3668 ast_debug(1,
"Dunno what to do with event %d on channel %d\n", res, p->
channel);
3670 return &p->
subs[idx].
f;
3693 p->
subs[idx].
f.
src =
"dahdi_exception";
3707 ast_debug(1,
"Restoring owner of channel %d on event %d\n", p->
channel, res);
3768 f = &p->
subs[idx].
f;
3773 if (ast != p->
owner) {
3775 f = &p->
subs[idx].
f;
3801 ast_debug(1,
"channel (%d) - signaling (%d) - event (%s)\n",
3814 ast_log(
LOG_WARNING,
"Can't start PBX immediately, must wait for Caller ID / distinctive ring\n");
3821 ast_debug(1,
"Disabling ring timeout (previously %d) to begin handling immediately\n", i->
ringt_base);
3845 if (res && (
errno == EBUSY)) {
3879 ast_log(
LOG_WARNING,
"Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->
channel);