46 #include "asterisk/features_config.h"
62 #define POLARITY_IDLE 0
63 #define POLARITY_REV 1
64 #define MIN_MS_SINCE_FLASH ( (2000) )
65 static char analog_defaultcic[64] =
"";
66 static char analog_defaultozz[64] =
"";
69 enum analog_sigtype sigtype;
72 { ANALOG_SIG_FXOLS,
"fxo_ls" },
73 { ANALOG_SIG_FXOKS,
"fxo_ks" },
74 { ANALOG_SIG_FXOGS,
"fxo_gs" },
75 { ANALOG_SIG_FXSLS,
"fxs_ls" },
76 { ANALOG_SIG_FXSKS,
"fxs_ks" },
77 { ANALOG_SIG_FXSGS,
"fxs_gs" },
78 { ANALOG_SIG_EMWINK,
"em_w" },
79 { ANALOG_SIG_EM,
"em" },
80 { ANALOG_SIG_EM_E1,
"em_e1" },
81 { ANALOG_SIG_FEATD,
"featd" },
82 { ANALOG_SIG_FEATDMF,
"featdmf" },
83 { ANALOG_SIG_FEATDMF_TA,
"featdmf_ta" },
84 { ANALOG_SIG_FEATB,
"featb" },
85 { ANALOG_SIG_FGC_CAMA,
"fgccama" },
86 { ANALOG_SIG_FGC_CAMAMF,
"fgccamamf" },
87 { ANALOG_SIG_SF,
"sf" },
88 { ANALOG_SIG_SFWINK,
"sf_w" },
89 { ANALOG_SIG_SF_FEATD,
"sf_featd" },
90 { ANALOG_SIG_SF_FEATDMF,
"sf_featdmf" },
91 { ANALOG_SIG_SF_FEATB,
"sf_featb" },
92 { ANALOG_SIG_E911,
"e911" },
96 unsigned int cid_type;
99 { CID_SIG_BELL,
"bell" },
100 { CID_SIG_V23,
"v23" },
101 { CID_SIG_V23_JP,
"v23_jp" },
102 { CID_SIG_DTMF,
"dtmf" },
107 #define ISTRUNK(p) ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || \
108 (p->sig == ANALOG_SIG_FXSGS))
110 enum analog_sigtype analog_str_to_sigtype(
const char *name)
114 for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
115 if (!strcasecmp(sigtypes[i].name, name)) {
116 return sigtypes[i].sigtype;
123 const char *analog_sigtype_to_str(
enum analog_sigtype sigtype)
127 for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
128 if (sigtype == sigtypes[i].sigtype) {
129 return sigtypes[i].name;
136 unsigned int analog_str_to_cidtype(
const char *name)
140 for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
141 if (!strcasecmp(cidtypes[i].name, name)) {
142 return cidtypes[i].cid_type;
149 const char *analog_cidtype_to_str(
unsigned int cid_type)
153 for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
154 if (cid_type == cidtypes[i].cid_type) {
155 return cidtypes[i].name;
162 static int analog_start_cid_detect(
struct analog_pvt *p,
int cid_signalling)
170 static int analog_stop_cid_detect(
struct analog_pvt *p)
178 static int analog_get_callerid(
struct analog_pvt *p,
char *name,
char *
number,
enum analog_event *ev,
size_t timeout)
181 return analog_callbacks.get_callerid(p->chan_pvt, name, number, ev, timeout);
186 static const char *analog_get_orig_dialstring(
struct analog_pvt *p)
194 static int analog_get_event(
struct analog_pvt *p)
202 static int analog_wait_event(
struct analog_pvt *p)
210 static int analog_have_progressdetect(
struct analog_pvt *p)
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
234 enum analog_cid_start analog_str_to_cidstart(
const char *value)
236 if (!strcasecmp(value,
"ring")) {
237 return ANALOG_CID_START_RING;
238 }
else if (!strcasecmp(value,
"polarity")) {
239 return ANALOG_CID_START_POLARITY;
240 }
else if (!strcasecmp(value,
"polarity_in")) {
241 return ANALOG_CID_START_POLARITY_IN;
242 }
else if (!strcasecmp(value,
"dtmf")) {
243 return ANALOG_CID_START_DTMF_NOALERT;
249 const char *analog_cidstart_to_str(
enum analog_cid_start cid_start)
252 case ANALOG_CID_START_RING:
254 case ANALOG_CID_START_POLARITY:
256 case ANALOG_CID_START_POLARITY_IN:
257 return "Polarity_In";
258 case ANALOG_CID_START_DTMF_NOALERT:
265 static char *analog_event2str(
enum analog_event
event)
269 case ANALOG_EVENT_ONHOOK:
270 res =
"ANALOG_EVENT_ONHOOK";
272 case ANALOG_EVENT_RINGOFFHOOK:
273 res =
"ANALOG_EVENT_RINGOFFHOOK";
275 case ANALOG_EVENT_WINKFLASH:
276 res =
"ANALOG_EVENT_WINKFLASH";
278 case ANALOG_EVENT_ALARM:
279 res =
"ANALOG_EVENT_ALARM";
281 case ANALOG_EVENT_NOALARM:
282 res =
"ANALOG_EVENT_NOALARM";
284 case ANALOG_EVENT_DIALCOMPLETE:
285 res =
"ANALOG_EVENT_DIALCOMPLETE";
287 case ANALOG_EVENT_HOOKCOMPLETE:
288 res =
"ANALOG_EVENT_HOOKCOMPLETE";
290 case ANALOG_EVENT_PULSE_START:
291 res =
"ANALOG_EVENT_PULSE_START";
293 case ANALOG_EVENT_POLARITY:
294 res =
"ANALOG_EVENT_POLARITY";
296 case ANALOG_EVENT_RINGBEGIN:
297 res =
"ANALOG_EVENT_RINGBEGIN";
299 case ANALOG_EVENT_EC_DISABLED:
300 res =
"ANALOG_EVENT_EC_DISABLED";
302 case ANALOG_EVENT_RINGERON:
303 res =
"ANALOG_EVENT_RINGERON";
305 case ANALOG_EVENT_RINGEROFF:
306 res =
"ANALOG_EVENT_RINGEROFF";
308 case ANALOG_EVENT_REMOVED:
309 res =
"ANALOG_EVENT_REMOVED";
311 case ANALOG_EVENT_NEONMWI_ACTIVE:
312 res =
"ANALOG_EVENT_NEONMWI_ACTIVE";
314 case ANALOG_EVENT_NEONMWI_INACTIVE:
315 res =
"ANALOG_EVENT_NEONMWI_INACTIVE";
317 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
318 case ANALOG_EVENT_TX_CED_DETECTED:
319 res =
"ANALOG_EVENT_TX_CED_DETECTED";
321 case ANALOG_EVENT_RX_CED_DETECTED:
322 res =
"ANALOG_EVENT_RX_CED_DETECTED";
324 case ANALOG_EVENT_EC_NLP_DISABLED:
325 res =
"ANALOG_EVENT_EC_NLP_DISABLED";
327 case ANALOG_EVENT_EC_NLP_ENABLED:
328 res =
"ANALOG_EVENT_EC_NLP_ENABLED";
331 case ANALOG_EVENT_PULSEDIGIT:
332 res =
"ANALOG_EVENT_PULSEDIGIT";
334 case ANALOG_EVENT_DTMFDOWN:
335 res =
"ANALOG_EVENT_DTMFDOWN";
337 case ANALOG_EVENT_DTMFUP:
338 res =
"ANALOG_EVENT_DTMFUP";
341 res =
"UNKNOWN/OTHER";
353 ast_debug(1,
"Swapping %u and %u\n", a, b);
355 towner = p->
subs[a].owner;
356 p->
subs[a].owner = p->
subs[b].owner;
357 p->
subs[b].owner = towner;
359 tinthreeway = p->
subs[a].inthreeway;
360 p->
subs[a].inthreeway = p->
subs[b].inthreeway;
361 p->
subs[b].inthreeway = tinthreeway;
374 p->
subs[x].allocd = 1;
383 p->
subs[x].allocd = 0;
384 p->
subs[x].owner = NULL;
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__)
408 static int _analog_get_index(
struct ast_channel *ast,
struct analog_pvt *p,
int nullok,
const char *fname,
unsigned long line)
421 "Unable to get index for '%s' on channel %d (%s(), line %lu)\n",
422 ast ? ast_channel_name(ast) :
"", p->
channel, fname, line);
428 static int analog_dsp_reset_and_flush_digits(
struct analog_pvt *p)
448 p->
owner = new_owner;
462 c =
analog_callbacks.new_ast_channel(p->chan_pvt, state, startpbx, sub, requestor);
464 ast_channel_call_forward_set(c, p->call_forward);
466 p->
subs[sub].owner = c;
468 analog_set_new_owner(p, c);
473 static int analog_set_echocanceller(
struct analog_pvt *p,
int enable)
481 static int analog_train_echocanceller(
struct analog_pvt *p)
489 static int analog_is_off_hook(
struct analog_pvt *p)
529 static int analog_on_hook(
struct analog_pvt *p)
537 static void analog_set_outgoing(
struct analog_pvt *p,
int is_outgoing)
539 p->outgoing = is_outgoing;
545 static int analog_check_for_conference(
struct analog_pvt *p)
553 static void analog_all_subchannels_hungup(
struct analog_pvt *p)
560 static void analog_unlock_private(
struct analog_pvt *p)
567 static void analog_lock_private(
struct analog_pvt *p)
574 static void analog_deadlock_avoidance_private(
struct analog_pvt *p)
580 analog_unlock_private(p);
582 analog_lock_private(p);
602 if (!pvt->
subs[sub_idx].owner) {
606 if (!ast_channel_trylock(pvt->
subs[sub_idx].owner)) {
611 analog_deadlock_avoidance_private(pvt);
615 static int analog_off_hook(
struct analog_pvt *p)
623 static void analog_set_needringing(
struct analog_pvt *p,
int value)
631 static void analog_set_polarity(
struct analog_pvt *p,
int value)
639 static void analog_start_polarityswitch(
struct analog_pvt *p)
645 static void analog_answer_polarityswitch(
struct analog_pvt *p)
652 static void analog_hangup_polarityswitch(
struct analog_pvt *p)
659 static int analog_dsp_set_digitmode(
struct analog_pvt *p,
enum analog_dsp_digitmode mode)
682 static int analog_has_voicemail(
struct analog_pvt *p)
710 static int analog_attempt_transfer(
struct analog_pvt *p)
720 ast_verb(3,
"TRANSFERRING %s to %s\n",
721 ast_channel_name(owner_3way), ast_channel_name(owner_real));
723 ast_channel_unlock(owner_real);
724 ast_channel_unlock(owner_3way);
725 analog_unlock_private(p);
734 ast_channel_lock(owner_real);
735 analog_lock_private(p);
743 static int analog_update_conf(
struct analog_pvt *p)
749 for (x = 0; x < 3; x++) {
751 if ((p->
subs[x].allocd) && p->
subs[x].inthreeway) {
762 ast_debug(1,
"Updated conferencing on %d, with %d conference users\n", p->
channel, needconf);
775 *callwait = (p->
owner != NULL);
779 ast_log(LOG_ERROR,
"Unable to alloc subchannel\n");
784 analog_set_outgoing(p, 1);
788 analog_set_outgoing(p, 0);
815 offhook = analog_is_off_hook(p);
818 if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) {
819 #ifdef DAHDI_CHECK_HOOKSTATE
826 }
else if (offhook) {
835 if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
862 static int analog_stop_callwait(
struct analog_pvt *p)
871 static int analog_callwait(
struct analog_pvt *p)
880 static void analog_set_callwaiting(
struct analog_pvt *p,
int callwaiting_enable)
895 static void analog_set_dialing(
struct analog_pvt *p,
int is_dialing)
903 static void analog_set_alarm(
struct analog_pvt *p,
int in_alarm)
905 p->inalarm = in_alarm;
911 static void analog_set_ringtimeout(
struct analog_pvt *p,
int ringt)
926 static int analog_check_waitingfordt(
struct analog_pvt *p)
935 static void analog_set_confirmanswer(
struct analog_pvt *p,
int flag)
942 static int analog_check_confirmanswer(
struct analog_pvt *p)
951 static void analog_cancel_cidspill(
struct analog_pvt *p)
958 static int analog_confmute(
struct analog_pvt *p,
int mute)
966 static void analog_set_pulsedial(
struct analog_pvt *p,
int flag)
984 p->
subs[sub].inthreeway = inthreeway;
996 ast_debug(1,
"CALLING CID_NAME: %s CID_NUM:: %s\n",
997 S_COR(ast_channel_connected(ast)->
id.name.valid, ast_channel_connected(ast)->
id.name.str,
""),
998 S_COR(ast_channel_connected(ast)->
id.number.valid, ast_channel_connected(ast)->
id.number.str,
""));
1009 ast_log(LOG_WARNING,
"analog_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
1014 analog_set_outgoing(p, 1);
1017 if (p->outsigmod > -1) {
1018 mysig = p->outsigmod;
1022 case ANALOG_SIG_FXOLS:
1023 case ANALOG_SIG_FXOGS:
1024 case ANALOG_SIG_FXOKS:
1025 if (p->
owner == ast) {
1029 analog_set_dialing(p, 1);
1030 analog_set_cadence(p, ast);
1033 c = strchr(dest,
'/');
1037 if (c && (strlen(c) < p->stripmsd)) {
1038 ast_log(LOG_WARNING,
"Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1041 if (c && (strlen(c) >
sizeof(p->dop.dialstr) - 3 )) {
1042 ast_log(LOG_WARNING,
"Number '%s' is longer than %d bytes\n", c, (
int)
sizeof(p->dop.dialstr) - 2);
1046 p->dop.op = ANALOG_DIAL_OP_REPLACE;
1047 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"Tw%s", c);
1048 ast_debug(1,
"FXO: setup deferred dialstring: %s\n", c);
1050 p->dop.dialstr[0] =
'\0';
1053 if (analog_ring(p)) {
1054 ast_log(LOG_WARNING,
"Unable to ring phone: %s\n", strerror(errno));
1057 analog_set_dialing(p, 1);
1060 if (ast_channel_connected(ast)->
id.number.valid && ast_channel_connected(ast)->
id.number.str) {
1061 ast_copy_string(p->callwait_num, ast_channel_connected(ast)->
id.number.str,
sizeof(p->callwait_num));
1063 p->callwait_num[0] =
'\0';
1065 if (ast_channel_connected(ast)->
id.name.valid && ast_channel_connected(ast)->
id.name.str) {
1066 ast_copy_string(p->callwait_name, ast_channel_connected(ast)->
id.name.str,
sizeof(p->callwait_name));
1068 p->callwait_name[0] =
'\0';
1072 if (analog_callwait(p)) {
1077 ast_log(LOG_WARNING,
"Unable to generate call-wait ring-back on channel %s\n", ast_channel_name(ast));
1083 n = ast_channel_connected(ast)->
id.
name.
valid ? ast_channel_connected(ast)->
id.
name.
str : NULL;
1088 p->lastcid_num[0] =
'\0';
1093 p->lastcid_name[0] =
'\0';
1097 const char *qual_var;
1100 p->caller.
id.
name.
str = p->lastcid_name;
1111 ast_channel_lock(ast);
1115 ast_channel_unlock(ast);
1119 idx = analog_get_index(ast, p, 0);
1131 case AST_CC_MONITOR_NATIVE:
1135 analog_get_orig_dialstring(p), AST_CC_CCNR, NULL);
1142 case ANALOG_SIG_FXSLS:
1143 case ANALOG_SIG_FXSGS:
1144 case ANALOG_SIG_FXSKS:
1145 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
1146 ast_debug(1,
"Ignore possible polarity reversal on line seizure\n");
1150 case ANALOG_SIG_EMWINK:
1152 case ANALOG_SIG_EM_E1:
1153 case ANALOG_SIG_FEATD:
1154 case ANALOG_SIG_FEATDMF:
1155 case ANALOG_SIG_E911:
1156 case ANALOG_SIG_FGC_CAMA:
1157 case ANALOG_SIG_FGC_CAMAMF:
1158 case ANALOG_SIG_FEATB:
1159 case ANALOG_SIG_SFWINK:
1161 case ANALOG_SIG_SF_FEATD:
1162 case ANALOG_SIG_SF_FEATDMF:
1163 case ANALOG_SIG_FEATDMF_TA:
1164 case ANALOG_SIG_SF_FEATB:
1165 c = strchr(dest,
'/');
1171 if (strlen(c) < p->stripmsd) {
1172 ast_log(LOG_WARNING,
"Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1175 res = analog_start(p);
1177 if (errno != EINPROGRESS) {
1182 p->dop.op = ANALOG_DIAL_OP_REPLACE;
1187 case ANALOG_SIG_FEATD:
1190 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"T*%s*%s*", l, c);
1192 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"T**%s*", c);
1195 case ANALOG_SIG_FEATDMF:
1198 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"M*00%s#*%s#", l, c);
1200 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"M*02#*%s#", c);
1203 case ANALOG_SIG_FEATDMF_TA:
1205 const char *cic =
"", *ozz =
"";
1211 ozz = analog_defaultozz;
1215 cic = analog_defaultcic;
1219 ast_log(LOG_WARNING,
"Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1222 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"M*%s%s#", ozz, cic);
1223 snprintf(p->finaldial,
sizeof(p->finaldial),
"M*%s#", c);
1227 case ANALOG_SIG_E911:
1230 case ANALOG_SIG_FGC_CAMA:
1231 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"P%s", c);
1233 case ANALOG_SIG_FGC_CAMAMF:
1234 case ANALOG_SIG_FEATB:
1235 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"M*%s#", c);
1239 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"P%sw", c);
1241 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"T%sw", c);
1246 if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
1247 memset(p->echorest,
'w',
sizeof(p->echorest) - 1);
1248 strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
1249 p->echorest[
sizeof(p->echorest) - 1] =
'\0';
1251 p->dop.dialstr[strlen(p->dop.dialstr)-2] =
'\0';
1255 analog_set_waitingfordt(p, ast);
1264 analog_set_dialing(p, 1);
1265 if (ast_strlen_zero(c)) {
1283 if (!ast_channel_tech_pvt(ast)) {
1284 ast_log(LOG_WARNING,
"Asked to hangup channel not connected\n");
1288 idx = analog_get_index(ast, p, 1);
1302 analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF);
1304 ast_debug(1,
"Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
1309 p->
subs[idx].owner = NULL;
1311 analog_set_linear_mode(p, idx, 0);
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");
1322 analog_set_new_owner(p, NULL);
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");
1337 analog_set_new_owner(p, NULL);
1345 analog_set_new_owner(p, NULL);
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");
1371 analog_set_new_owner(p, NULL);
1422 ast_log(LOG_ERROR,
"Index found but not any type of call?\n");
1428 analog_set_new_owner(p, NULL);
1429 analog_set_ringtimeout(p, 0);
1430 analog_set_confirmanswer(p, 0);
1431 analog_set_pulsedial(p, 0);
1432 analog_set_outgoing(p, 0);
1433 p->onhooktime = time(NULL);
1437 res = analog_on_hook(p);
1439 ast_log(LOG_WARNING,
"Unable to hangup line %s\n", ast_channel_name(ast));
1442 case ANALOG_SIG_FXOGS:
1443 case ANALOG_SIG_FXOLS:
1444 case ANALOG_SIG_FXOKS:
1446 if (analog_is_off_hook(p)) {
1447 analog_hangup_polarityswitch(p);
1453 case ANALOG_SIG_FXSGS:
1454 case ANALOG_SIG_FXSLS:
1455 case ANALOG_SIG_FXSKS:
1468 analog_set_echocanceller(p, 0);
1478 analog_set_dialing(p, 0);
1479 analog_update_conf(p);
1480 analog_all_subchannels_hungup(p);
1483 analog_stop_callwait(p);
1485 ast_verb(3,
"Hanging up on '%s'\n", ast_channel_name(ast));
1498 idx = analog_get_index(ast, p, 1);
1503 case ANALOG_SIG_FXSLS:
1504 case ANALOG_SIG_FXSGS:
1505 case ANALOG_SIG_FXSKS:
1506 analog_set_ringtimeout(p, 0);
1509 case ANALOG_SIG_EM_E1:
1510 case ANALOG_SIG_EMWINK:
1511 case ANALOG_SIG_FEATD:
1512 case ANALOG_SIG_FEATDMF:
1513 case ANALOG_SIG_FEATDMF_TA:
1514 case ANALOG_SIG_E911:
1515 case ANALOG_SIG_FGC_CAMA:
1516 case ANALOG_SIG_FGC_CAMAMF:
1517 case ANALOG_SIG_FEATB:
1519 case ANALOG_SIG_SFWINK:
1520 case ANALOG_SIG_SF_FEATD:
1521 case ANALOG_SIG_SF_FEATDMF:
1522 case ANALOG_SIG_SF_FEATB:
1523 case ANALOG_SIG_FXOLS:
1524 case ANALOG_SIG_FXOGS:
1525 case ANALOG_SIG_FXOKS:
1527 ast_debug(1,
"Took %s off hook\n", ast_channel_name(ast));
1528 if (p->hanguponpolarityswitch) {
1529 gettimeofday(&p->polaritydelaytv, NULL);
1531 res = analog_off_hook(p);
1532 analog_play_tone(p, idx, -1);
1533 analog_set_dialing(p, 0);
1536 ast_debug(1,
"Finally swapping real and threeway\n");
1544 case ANALOG_SIG_FXSLS:
1545 case ANALOG_SIG_FXSKS:
1546 case ANALOG_SIG_FXSGS:
1547 analog_set_echocanceller(p, 1);
1548 analog_train_echocanceller(p);
1550 case ANALOG_SIG_FXOLS:
1551 case ANALOG_SIG_FXOKS:
1552 case ANALOG_SIG_FXOGS:
1553 analog_answer_polarityswitch(p);
1560 ast_log(LOG_WARNING,
"Don't know how to answer signalling %d (channel %d)\n", p->sig, p->
channel);
1568 static int analog_handles_digit(
struct ast_frame *f)
1597 ast_debug(1,
"%s DTMF digit: 0x%02X '%c' on %s\n",
1601 if (analog_check_confirmanswer(p)) {
1603 ast_debug(1,
"Confirm answer on %s!\n", ast_channel_name(ast));
1609 analog_set_confirmanswer(p, 0);
1614 *dest = &p->
subs[idx].
f;
1618 ast_debug(1,
"Got some DTMF, but it's for the CAS\n");
1619 p->caller.
id.
name.
str = p->callwait_name;
1621 analog_send_callerid(p, 1, &p->caller);
1623 if (analog_handles_digit(f)) {
1629 *dest = &p->
subs[idx].
f;
1631 analog_cb_handle_dtmf(p, ast, idx, dest);
1635 static int analog_my_getsigstr(
struct ast_channel *chan,
char *str,
const char *term,
int ms)
1649 if (strchr(term, c)) {
1655 static int analog_handle_notify_message(
struct ast_channel *chan,
struct analog_pvt *p,
int cid_flags,
int neon_mwievent)
1658 analog_callbacks.handle_notify_message(chan, p->chan_pvt, cid_flags, neon_mwievent);
1664 static void analog_increase_ss_count(
void)
1671 static void analog_decrease_ss_count(
void)
1678 static int analog_distinctive_ring(
struct ast_channel *chan,
struct analog_pvt *p,
int idx,
int *ringdata)
1680 if (!p->usedistinctiveringdetection) {
1684 return analog_callbacks.distinctive_ring(chan, p->chan_pvt, idx, ringdata);
1690 static void analog_get_and_handle_alarms(
struct analog_pvt *p)
1697 static void *analog_get_bridged_channel(
struct ast_channel *chan)
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))
1715 static int analog_canmatch_featurecode(
const char *pickupexten,
const char *exten)
1717 int extlen = strlen(exten);
1721 if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) {
1725 if (exten[0] ==
'*' && extlen < 3) {
1740 static void *__analog_ss_thread(
void *
data)
1748 char namebuf[ANALOG_MAX_CID];
1749 char numbuf[ANALOG_MAX_CID];
1750 char *name = NULL, *number = NULL;
1761 const char *pickupexten;
1763 analog_increase_ss_count();
1767 ast_assert(chan != NULL);
1769 if ((callid = ast_channel_callid(chan))) {
1776 if (!ast_channel_tech_pvt(chan)) {
1777 ast_log(LOG_WARNING,
"Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan));
1782 ast_verb(3,
"Starting simple switch on '%s'\n", ast_channel_name(chan));
1783 idx = analog_get_index(chan, p, 0);
1789 ast_channel_lock(chan);
1790 pickup_cfg = ast_get_chan_features_pickup_config(chan);
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);
1797 ast_channel_unlock(chan);
1799 analog_dsp_reset_and_flush_digits(p);
1801 case ANALOG_SIG_FEATD:
1802 case ANALOG_SIG_FEATDMF:
1803 case ANALOG_SIG_FEATDMF_TA:
1804 case ANALOG_SIG_E911:
1805 case ANALOG_SIG_FGC_CAMAMF:
1806 case ANALOG_SIG_FEATB:
1807 case ANALOG_SIG_EMWINK:
1808 case ANALOG_SIG_SF_FEATD:
1809 case ANALOG_SIG_SF_FEATDMF:
1810 case ANALOG_SIG_SF_FEATB:
1811 case ANALOG_SIG_SFWINK:
1812 if (analog_wink(p, idx))
1816 case ANALOG_SIG_EM_E1:
1818 case ANALOG_SIG_FGC_CAMA:
1819 res = analog_play_tone(p, idx, -1);
1821 analog_dsp_reset_and_flush_digits(p);
1824 if (ANALOG_NEED_MFDETECT(p)) {
1825 analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_MF);
1827 analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF);
1830 memset(dtmfbuf, 0,
sizeof(dtmfbuf));
1832 if (!p->immediate) {
1842 case ANALOG_SIG_FEATD:
1843 case ANALOG_SIG_SF_FEATD:
1844 res = analog_my_getsigstr(chan, dtmfbuf + 1,
"*", 3000);
1846 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf),
"*", 3000);
1849 analog_dsp_reset_and_flush_digits(p);
1852 case ANALOG_SIG_FEATDMF_TA:
1853 res = analog_my_getsigstr(chan, dtmfbuf + 1,
"#", 3000);
1855 analog_dsp_reset_and_flush_digits(p);
1857 if (analog_wink(p, idx)) {
1868 case ANALOG_SIG_FEATDMF:
1869 case ANALOG_SIG_E911:
1870 case ANALOG_SIG_FGC_CAMAMF:
1871 case ANALOG_SIG_SF_FEATDMF:
1872 res = analog_my_getsigstr(chan, dtmfbuf + 1,
"#", 3000);
1874 if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] !=
'0')
1875 && (strlen(dtmfbuf) != 14)) {
1876 if (analog_wink(p, idx)) {
1886 res = analog_my_getsigstr(chan, dtmfbuf + 1,
"#", 3000);
1890 if (p->sig == ANALOG_SIG_E911) {
1895 analog_dsp_reset_and_flush_digits(p);
1898 case ANALOG_SIG_FEATB:
1899 case ANALOG_SIG_SF_FEATB:
1900 res = analog_my_getsigstr(chan, dtmfbuf + 1,
"#", 3000);
1902 analog_dsp_reset_and_flush_digits(p);
1905 case ANALOG_SIG_EMWINK:
1911 res = analog_my_getsigstr(chan, dtmfbuf + 1,
"*", 3000);
1913 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf),
"*", 3000);
1916 analog_dsp_reset_and_flush_digits(p);
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';
1946 ast_log(LOG_WARNING,
"getdtmf on channel %d: %s\n", p->
channel, strerror(errno));
1949 }
else if (res < 0) {
1950 ast_debug(1,
"Got hung up before digits finished\n");
1955 if (p->sig == ANALOG_SIG_FGC_CAMA || p->sig == ANALOG_SIG_FGC_CAMAMF) {
1972 int cnoffset = p->ani_info_digits + 1;
1973 ast_debug(1,
"cnoffset: %d\n", cnoffset);
1982 ast_debug(1,
"Sent wink to signal ANI start\n");
1983 analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_MF);
1987 res = analog_my_getsigstr(chan, anibuf,
"#ABC", p->ani_timeout);
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;
2003 caller = ast_channel_caller(chan);
2004 strncpy(f, &(anibuf[1]), MIN((
int)(p->ani_info_digits),
sizeof(f)-1));
2005 caller->
ani2 = atoi(f);
2007 anibuf[cnoffset] = 0;
2014 analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF);
2018 if (ast_strlen_zero(exten)) {
2021 if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) {
2023 if (exten[0] ==
'*') {
2028 s1 = strsep(&stringp,
"*");
2029 s2 = strsep(&stringp,
"*");
2031 if (!ast_strlen_zero(p->cid_num)) {
2040 }
else if (p->sig == ANALOG_SIG_FEATD) {
2041 ast_log(LOG_WARNING,
"Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->
channel);
2044 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2045 if (exten[0] ==
'*') {
2052 s1 = strsep(&stringp,
"#");
2053 s2 = strsep(&stringp,
"#");
2055 if (!ast_strlen_zero(p->cid_num)) {
2068 caller = ast_channel_caller(chan);
2070 caller->
ani2 = atoi(s1);
2072 ast_log(LOG_WARNING,
"Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->
channel);
2075 if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) {
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);
2097 if (p->sig == ANALOG_SIG_FEATB) {
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);
2109 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2110 analog_wink(p, idx);
2121 analog_set_echocanceller(p, 1);
2123 analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF);
2126 ast_channel_caller(chan)->
id.number.valid ? ast_channel_caller(chan)->
id.number.str : NULL)) {
2127 ast_channel_exten_set(chan, exten);
2128 analog_dsp_reset_and_flush_digits(p);
2131 ast_log(LOG_WARNING,
"PBX exited non-zero\n");
2132 res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION);
2136 ast_verb(3,
"Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan));
2138 res = analog_play_tone(p, idx, ANALOG_TONE_INFO);
2140 ast_log(LOG_WARNING,
"Unable to start special tone on %d\n", p->
channel);
2144 res =
ast_streamfile(chan,
"ss-noservice", ast_channel_language(chan));
2148 res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION);
2153 case ANALOG_SIG_FXOLS:
2154 case ANALOG_SIG_FXOGS:
2155 case ANALOG_SIG_FXOKS:
2170 timeout = analog_get_firstdigit_timeout(p);
2178 int is_exten_parking = 0;
2189 ast_debug(1,
"waitfordigit returned < 0...\n");
2190 res = analog_play_tone(p, idx, -1);
2194 ast_debug(1,
"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2199 analog_play_tone(p, idx, -1);
2201 analog_play_tone(p, idx, ANALOG_TONE_DIALTONE);
2206 if (
ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) {
2211 ast_verb(3,
"Setting call forward to '%s' on channel %d\n", p->call_forward, p->
channel);
2212 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2217 res = analog_play_tone(p, idx, -1);
2219 memset(exten, 0,
sizeof(exten));
2220 res = analog_play_tone(p, idx, ANALOG_TONE_DIALTONE);
2224 res = analog_play_tone(p, idx, -1);
2225 ast_channel_lock(chan);
2226 ast_channel_exten_set(chan, exten);
2231 if (p->hidecallerid) {
2233 ast_channel_caller(chan)->
id.
name.
presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
2236 ast_channel_caller(chan)->
id.
name.
presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
2240 ast_channel_unlock(chan);
2241 analog_set_echocanceller(p, 1);
2244 ast_log(LOG_WARNING,
"PBX exited non-zero\n");
2245 res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION);
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");
2259 res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION);
2261 analog_wait_event(p);
2264 }
else if (p->
callwaiting && !strcmp(exten,
"*70")) {
2265 ast_verb(3,
"Disabling call waiting on %s\n", ast_channel_name(chan));
2267 analog_set_callwaiting(p, 0);
2268 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2270 ast_log(LOG_WARNING,
"Unable to do dial recall on channel %s: %s\n",
2271 ast_channel_name(chan), strerror(errno));
2274 memset(exten, 0,
sizeof(exten));
2275 timeout = analog_get_firstdigit_timeout(p);
2277 }
else if (!strcmp(exten, pickupexten)) {
2291 analog_set_echocanceller(p, 1);
2293 ast_debug(1,
"No call pickup possible...\n");
2294 res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION);
2295 analog_wait_event(p);
2300 ast_log(LOG_WARNING,
"Huh? Got *8# on call not on real\n");
2307 }
else if (!p->hidecallerid && !strcmp(exten,
"*67")) {
2308 ast_verb(3,
"Blocking Caller*ID on %s\n", ast_channel_name(chan));
2310 p->hidecallerid = 1;
2312 ast_channel_caller(chan)->
id.
name.
presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
2313 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2315 ast_log(LOG_WARNING,
"Unable to do dial recall on channel %s: %s\n",
2316 ast_channel_name(chan), strerror(errno));
2319 memset(exten, 0,
sizeof(exten));
2320 timeout = analog_get_firstdigit_timeout(p);
2321 }
else if (p->callreturn && !strcmp(exten,
"*69")) {
2323 if (!ast_strlen_zero(p->lastcid_num)) {
2327 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2330 }
else if (!strcmp(exten,
"*78")) {
2333 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2335 memset(exten, 0,
sizeof(exten));
2337 }
else if (!strcmp(exten,
"*79")) {
2340 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2342 memset(exten, 0,
sizeof(exten));
2344 }
else if (p->cancallforward && !strcmp(exten,
"*72")) {
2345 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2347 memset(exten, 0,
sizeof(exten));
2349 }
else if (p->cancallforward && !strcmp(exten,
"*73")) {
2350 ast_verb(3,
"Cancelling call forwarding on channel %d\n", p->
channel);
2351 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2352 memset(p->call_forward, 0,
sizeof(p->call_forward));
2354 memset(exten, 0,
sizeof(exten));
2356 }
else if ((p->transfer || p->canpark) && is_exten_parking
2367 if (bridge_channel) {
2373 analog_lock_private(p);
2376 analog_unlock_private(p);
2378 ast_verb(3,
"%s: Parked call\n", ast_channel_name(chan));
2386 }
else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten,
"*60")) {
2387 ast_verb(3,
"Blacklisting number %s\n", p->lastcid_num);
2388 res =
ast_db_put(
"blacklist", p->lastcid_num,
"1");
2390 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2391 memset(exten, 0,
sizeof(exten));
2394 }
else if (p->hidecallerid && !strcmp(exten,
"*82")) {
2395 ast_verb(3,
"Allowing Caller*ID on %s\n", ast_channel_name(chan));
2397 p->hidecallerid = 0;
2399 ast_channel_caller(chan)->
id.
name.
presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
2400 res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL);
2402 ast_log(LOG_WARNING,
"Unable to do dial recall on channel %s: %s\n",
2403 ast_channel_name(chan), strerror(errno));
2406 memset(exten, 0,
sizeof(exten));
2407 timeout = analog_get_firstdigit_timeout(p);
2408 }
else if (!strcmp(exten,
"*0")) {
2413 pbridge = analog_get_bridged_channel(nbridge);
2415 if (pbridge && ISTRUNK(pbridge)) {
2417 p->dop.dialstr[0] =
'\0';
2419 if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2420 ast_log(LOG_WARNING,
2421 "Unable to flash-hook bridged trunk from channel %s: %s\n",
2422 ast_channel_name(nbridge), strerror(errno));
2431 analog_play_tone(p, idx, ANALOG_TONE_CONGESTION);
2432 analog_wait_event(p);
2433 analog_play_tone(p, idx, -1);
2441 ast_channel_caller(chan)->
id.number.valid ? ast_channel_caller(chan)->
id.number.str : NULL)
2442 && !analog_canmatch_featurecode(pickupexten, exten)) {
2443 ast_debug(1,
"Can't match %s from '%s' in context %s\n", exten,
2444 ast_channel_caller(chan)->
id.number.valid && ast_channel_caller(chan)->
id.number.str
2445 ? ast_channel_caller(chan)->
id.number.str :
"<Unknown Caller>",
2446 ast_channel_context(chan));
2450 timeout = analog_get_interdigit_timeout(p);
2453 analog_play_tone(p, idx, -1);
2457 case ANALOG_SIG_FXSLS:
2458 case ANALOG_SIG_FXSGS:
2459 case ANALOG_SIG_FXSKS:
2463 if (smdi_msg != NULL) {
2464 ast_channel_exten_set(chan, smdi_msg->fwd_st);
2466 if (smdi_msg->type ==
'B')
2468 else if (smdi_msg->type ==
'N')
2471 ast_debug(1,
"Received SMDI message on %s\n", ast_channel_name(chan));
2473 ast_log(LOG_WARNING,
"SMDI enabled but no SMDI message present\n");
2478 number = smdi_msg->calling_st;
2484 && (p->cid_start == ANALOG_CID_START_POLARITY
2485 || p->cid_start == ANALOG_CID_START_POLARITY_IN
2486 || p->cid_start == ANALOG_CID_START_DTMF_NOALERT))) {
2494 ast_debug(1,
"Receiving DTMF cid on channel %s\n", ast_channel_name(chan));
2496 oldlinearity = analog_set_linear_mode(p, idx, 0);
2504 ast_channel_lock(chan);
2506 ast_channel_unlock(chan);
2519 ast_log(LOG_WARNING,
2520 "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2529 if (k < ARRAY_LEN(dtmfbuf) - 1) {
2541 ast_channel_lock(chan);
2543 ast_channel_unlock(chan);
2546 analog_set_linear_mode(p, idx, oldlinearity);
2549 ast_debug(1,
"CID got string '%s'\n", dtmfbuf);
2551 ast_debug(1,
"CID is '%s', flags %d\n", dtmfcid, flags);
2553 if (!ast_strlen_zero(dtmfcid)) {
2565 int timeout = 10000;
2567 enum analog_event ev;
2570 struct timeval off_start;
2572 if (!p->usedistinctiveringdetection) {
2574 analog_set_ringtimeout(p, 0);
2577 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2579 ast_log(LOG_WARNING,
2580 "CallerID returned with error on channel '%s'\n",
2581 ast_channel_name(chan));
2590 if (ev == ANALOG_EVENT_NOALARM) {
2591 analog_set_alarm(p, 0);
2594 if (ev == ANALOG_EVENT_RINGBEGIN) {
2619 ast_log(LOG_WARNING,
2620 "CID timed out waiting for ring. Exiting simple switch\n");
2621 analog_stop_cid_detect(p);
2626 ast_log(LOG_WARNING,
"Hangup received waiting for ring. Exiting simple switch\n");
2627 analog_stop_cid_detect(p);
2637 res = analog_distinctive_ring(chan, p, idx, NULL);
2638 analog_stop_cid_detect(p);
2643 ast_log(LOG_WARNING,
"Unable to get caller ID space\n");
2646 ast_log(LOG_WARNING,
2647 "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2648 ast_channel_name(chan));
2652 }
else if (p->
use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2657 int timeout = 10000;
2659 enum analog_event ev;
2660 int ring_data[RING_PATTERNS] = { 0 };
2661 int ring_data_idx = 0;
2664 if (!p->usedistinctiveringdetection) {
2666 analog_set_ringtimeout(p, 0);
2669 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2671 ast_log(LOG_WARNING,
2672 "CallerID returned with error on channel '%s'\n",
2673 ast_channel_name(chan));
2682 if (ev == ANALOG_EVENT_NOALARM) {
2683 analog_set_alarm(p, 0);
2684 }
else if (ev == ANALOG_EVENT_POLARITY
2685 && p->hanguponpolarityswitch
2686 && p->polarity == POLARITY_REV) {
2688 "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2691 analog_stop_cid_detect(p);
2694 }
else if (ev == ANALOG_EVENT_RINGOFFHOOK
2695 && p->usedistinctiveringdetection
2696 && ring_data_idx < RING_PATTERNS) {
2701 ring_data[ring_data_idx] = p->ringt;
2709 res = analog_distinctive_ring(chan, p, idx, ring_data);
2710 analog_stop_cid_detect(p);
2715 ast_log(LOG_WARNING,
"Unable to get caller ID space\n");
2724 analog_handle_notify_message(chan, p, flags, -1);
2726 ast_channel_lock(chan);
2728 ast_channel_rings_set(chan, 1);
2729 ast_channel_unlock(chan);
2730 analog_set_ringtimeout(p, p->ringt_base);
2734 ast_log(LOG_WARNING,
"PBX exited non-zero\n");
2738 ast_log(LOG_WARNING,
"Don't know how to handle simple switch with signalling %s on channel %d\n", analog_sigtype_to_str(p->sig), p->
channel);
2741 res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION);
2743 ast_log(LOG_WARNING,
"Unable to play congestion tone on channel %d\n", p->
channel);
2747 ao2_cleanup(smdi_msg);
2748 analog_decrease_ss_count();
2756 p->ss_astchan = chan;
2757 return ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p);
2760 static void analog_publish_channel_alarm_clear(
int channel)
2764 ast_log(LOG_NOTICE,
"Alarm cleared on channel %d\n", channel);
2783 int data_size =
sizeof(*cause_code);
2784 char *subclass = NULL;
2788 idx = analog_get_index(ast, p, 0);
2793 ast_log(LOG_ERROR,
"We got an event on a non real sub. Fix it!\n");
2797 if (p->outsigmod > -1) {
2798 mysig = p->outsigmod;
2807 p->
subs[idx].
f.
src =
"dahdi_handle_event";
2809 f = &p->
subs[idx].
f;
2811 res = analog_get_event(p);
2813 ast_debug(1,
"Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->
channel, idx);
2815 if (res & (ANALOG_EVENT_PULSEDIGIT | ANALOG_EVENT_DTMFUP)) {
2816 analog_set_pulsedial(p, (res & ANALOG_EVENT_PULSEDIGIT) ? 1 : 0);
2817 ast_debug(1,
"Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ?
"pulse ":
"", res & 0xff);
2818 analog_confmute(p, 0);
2819 if (p->
dialmode == ANALOG_DIALMODE_BOTH || p->
dialmode == ANALOG_DIALMODE_PULSE) {
2822 analog_handle_dtmf(p, ast, idx, &f);
2824 ast_debug(1,
"Dropping pulse digit '%c' because pulse dialing disabled on channel %d\n", res & 0xff, p->
channel);
2829 if (res & ANALOG_EVENT_DTMFDOWN) {
2830 ast_debug(1,
"DTMF Down '%c'\n", res & 0xff);
2832 analog_confmute(p, 1);
2835 analog_handle_dtmf(p, ast, idx, &f);
2840 case ANALOG_EVENT_ALARM:
2841 case ANALOG_EVENT_POLARITY:
2842 case ANALOG_EVENT_ONHOOK:
2845 subclass = analog_event2str(res);
2846 data_size += strlen(subclass);
2848 memset(cause_code, 0, data_size);
2849 cause_code->
ast_cause = AST_CAUSE_NORMAL_CLEARING;
2851 snprintf(cause_code->
code, data_size -
sizeof(*cause_code) + 1,
"ANALOG %s", subclass);
2858 case ANALOG_EVENT_EC_DISABLED:
2859 ast_verb(3,
"Channel %d echo canceller disabled due to CED detection\n", p->
channel);
2860 analog_set_echocanceller(p, 0);
2862 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2863 case ANALOG_EVENT_TX_CED_DETECTED:
2864 ast_verb(3,
"Channel %d detected a CED tone towards the network.\n", p->
channel);
2866 case ANALOG_EVENT_RX_CED_DETECTED:
2867 ast_verb(3,
"Channel %d detected a CED tone from the network.\n", p->
channel);
2869 case ANALOG_EVENT_EC_NLP_DISABLED:
2870 ast_verb(3,
"Channel %d echo canceller disabled its NLP.\n", p->
channel);
2872 case ANALOG_EVENT_EC_NLP_ENABLED:
2873 ast_verb(3,
"Channel %d echo canceller enabled its NLP.\n", p->
channel);
2876 case ANALOG_EVENT_PULSE_START:
2878 if (!ast_channel_pbx(ast))
2881 case ANALOG_EVENT_DIALCOMPLETE:
2885 x = analog_is_dialing(p, idx);
2887 analog_set_echocanceller(p, 1);
2889 analog_train_echocanceller(p);
2891 p->dop.op = ANALOG_DIAL_OP_REPLACE;
2895 analog_set_dialing(p, 0);
2896 if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
2909 if (analog_have_progressdetect(p)) {
2910 ast_debug(1,
"Done dialing, but waiting for progress detection before doing more...\n");
2911 }
else if (analog_check_confirmanswer(p) || (!p->dialednone
2912 && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
2913 || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
2914 || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
2915 || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
2916 || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
2917 || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
2918 || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
2919 || (mysig == ANALOG_SIG_SF_FEATB)))) {
2921 }
else if (!p->answeronpolarityswitch) {
2926 p->polarity = POLARITY_REV;
2935 case ANALOG_EVENT_ALARM:
2936 analog_set_alarm(p, 1);
2937 analog_get_and_handle_alarms(p);
2938 cause_code->
ast_cause = AST_CAUSE_NETWORK_OUT_OF_ORDER;
2939 case ANALOG_EVENT_ONHOOK:
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");
2957 }
else if (analog_is_off_hook(p)) {
2958 ast_log(LOG_WARNING,
"Got ONHOOK but channel %d is off hook?\n", p->
channel);
2960 ast_verb(3,
"Holding incoming call %s for channel %d\n", ast_channel_name(ast), p->
channel);
2971 case ANALOG_SIG_FXOLS:
2972 case ANALOG_SIG_FXOGS:
2973 case ANALOG_SIG_FXOKS:
2974 analog_start_polarityswitch(p);
2975 p->fxsoffhookstate = 0;
2976 p->onhooktime = time(NULL);
2989 analog_set_echocanceller(p, 0);
2995 ast_verb(3,
"Channel %d still has (callwait) call, ringing phone\n", p->
channel);
2997 analog_stop_callwait(p);
2998 analog_set_new_owner(p, NULL);
3001 analog_set_dialing(p, 1);
3007 unsigned int mssinceflash;
3012 ast_log(LOG_NOTICE,
"Whoa, threeway disappeared kinda randomly.\n");
3016 if (p->
owner != ast) {
3018 ast_log(LOG_WARNING,
"This isn't good...\n");
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);
3044 analog_set_new_owner(p, NULL);
3047 }
else if (!analog_attempt_transfer(p)) {
3064 analog_set_new_owner(p, NULL);
3070 ast_log(LOG_WARNING,
"Got a hangup and my index is %u?\n", idx);
3074 analog_set_echocanceller(p, 0);
3078 case ANALOG_EVENT_RINGOFFHOOK:
3085 c = strchr(p->dialdest,
'/');
3093 int numchars = snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"M*0%s#", c);
3094 if (numchars >=
sizeof(p->dop.dialstr)) {
3095 ast_log(LOG_WARNING,
"Dial string '%s' truncated\n", c);
3101 if (strlen(p->dop.dialstr) > 4) {
3102 memset(p->echorest,
'w',
sizeof(p->echorest) - 1);
3103 strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
3104 p->echorest[
sizeof(p->echorest) - 1] =
'\0';
3106 p->dop.dialstr[strlen(p->dop.dialstr)-2] =
'\0';
3114 analog_set_dialing(p, 1);
3115 return &p->
subs[idx].
f;
3118 case ANALOG_SIG_FXOLS:
3119 case ANALOG_SIG_FXOGS:
3120 case ANALOG_SIG_FXOKS:
3121 p->fxsoffhookstate = 1;
3124 analog_set_echocanceller(p, 1);
3125 analog_train_echocanceller(p);
3129 analog_set_needringing(p, 0);
3134 analog_cancel_cidspill(p);
3136 analog_set_dialing(p, 0);
3138 if (analog_check_confirmanswer(p)) {
3142 }
else if (!ast_strlen_zero(p->dop.dialstr)) {
3146 p->dop.dialstr[0] =
'\0';
3149 ast_debug(1,
"Sent FXO deferred digit string: %s\n", p->dop.dialstr);
3152 analog_set_dialing(p, 1);
3154 p->dop.dialstr[0] =
'\0';
3158 analog_answer_polarityswitch(p);
3160 return &p->
subs[idx].
f;
3163 ast_channel_rings_set(ast, 1);
3167 return &p->
subs[idx].
f;
3176 if (analog_has_voicemail(p)) {
3183 ast_log(LOG_WARNING,
"FXO phone off hook in weird state %u??\n",
ast_channel_state(ast));
3186 case ANALOG_SIG_FXSLS:
3187 case ANALOG_SIG_FXSGS:
3188 case ANALOG_SIG_FXSKS:
3190 analog_set_ringtimeout(p, p->ringt_base);
3195 case ANALOG_SIG_EM_E1:
3196 case ANALOG_SIG_EMWINK:
3197 case ANALOG_SIG_FEATD:
3198 case ANALOG_SIG_FEATDMF:
3199 case ANALOG_SIG_FEATDMF_TA:
3200 case ANALOG_SIG_E911:
3201 case ANALOG_SIG_FGC_CAMA:
3202 case ANALOG_SIG_FGC_CAMAMF:
3203 case ANALOG_SIG_FEATB:
3205 case ANALOG_SIG_SFWINK:
3206 case ANALOG_SIG_SF_FEATD:
3207 case ANALOG_SIG_SF_FEATDMF:
3208 case ANALOG_SIG_SF_FEATB:
3223 if (analog_check_confirmanswer(p)) {
3240 ast_log(LOG_WARNING,
"Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3244 case ANALOG_EVENT_RINGBEGIN:
3246 case ANALOG_SIG_FXSLS:
3247 case ANALOG_SIG_FXSGS:
3248 case ANALOG_SIG_FXSKS:
3250 analog_set_ringtimeout(p, p->ringt_base);
3257 case ANALOG_EVENT_RINGEROFF:
3258 if (p->inalarm)
break;
3259 ast_channel_rings_set(ast, ast_channel_rings(ast) + 1);
3260 if (ast_channel_rings(ast) == p->
cidrings) {
3261 analog_send_callerid(p, 0, &p->caller);
3264 if (ast_channel_rings(ast) > p->
cidrings) {
3265 analog_cancel_cidspill(p);
3271 case ANALOG_EVENT_RINGERON:
3273 case ANALOG_EVENT_NOALARM:
3274 analog_set_alarm(p, 0);
3275 analog_publish_channel_alarm_clear(p->
channel);
3277 case ANALOG_EVENT_WINKFLASH:
3284 case ANALOG_SIG_FXOLS:
3285 case ANALOG_SIG_FXOGS:
3286 case ANALOG_SIG_FXOKS:
3287 ast_debug(1,
"Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3291 analog_cancel_cidspill(p);
3295 ast_log(LOG_WARNING,
"Got flash hook with index %u on channel %d?!?\n", idx, p->
channel);
3307 ast_log(LOG_NOTICE,
"Whoa, the call-waiting call disappeared.\n");
3315 ast_debug(1,
"Making %s the new owner\n", ast_channel_name(p->
owner));
3320 analog_stop_callwait(p);
3332 if (!p->threewaycalling) {
3336 }
else if (!analog_check_for_conference(p)) {
3337 ast_callid callid = 0;
3358 if (!((ast_channel_pbx(ast)) ||
3361 ast_debug(1,
"Flash when call not up or ringing\n");
3365 ast_log(LOG_WARNING,
"Unable to allocate three-way subchannel\n");
3377 analog_unlock_private(p);
3378 ast_channel_unlock(ast);
3380 ast_channel_lock(ast);
3381 analog_lock_private(p);
3383 ast_log(LOG_WARNING,
3384 "Cannot allocate new call structure on channel %d\n",
3403 analog_set_echocanceller(p, 0);
3406 ast_log(LOG_WARNING,
"Unable to start dial recall tone on channel %d\n", p->
channel);
3408 analog_set_new_owner(p, chan);
3409 p->ss_astchan = chan;
3410 if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p)) {
3411 ast_log(LOG_WARNING,
"Unable to start simple switch on channel %d\n", p->
channel);
3413 analog_set_echocanceller(p, 1);
3416 ast_verb(3,
"Started three way call on channel %d\n", p->
channel);
3434 ast_log(LOG_NOTICE,
"Whoa, the 3-way call disappeared.\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",
3476 analog_set_echocanceller(p, 1);
3479 ast_channel_unlock(p->
subs[orig_3way_sub].owner);
3482 analog_update_conf(p);
3485 case ANALOG_SIG_EM_E1:
3486 case ANALOG_SIG_FEATD:
3488 case ANALOG_SIG_SFWINK:
3489 case ANALOG_SIG_SF_FEATD:
3490 case ANALOG_SIG_FXSLS:
3491 case ANALOG_SIG_FXSGS:
3498 case ANALOG_SIG_FEATDMF_TA:
3501 ast_debug(1,
"ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->
owner)->
ani2,
3504 snprintf(p->dop.dialstr,
sizeof(p->dop.dialstr),
"M*%d%s#",
3510 ast_copy_string(p->dop.dialstr, p->finaldial,
sizeof(p->dop.dialstr));
3513 ast_log(LOG_WARNING,
"Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3518 case ANALOG_SIG_FEATDMF:
3519 case ANALOG_SIG_E911:
3520 case ANALOG_SIG_FGC_CAMAMF:
3521 case ANALOG_SIG_FGC_CAMA:
3522 case ANALOG_SIG_FEATB:
3523 case ANALOG_SIG_SF_FEATDMF:
3524 case ANALOG_SIG_SF_FEATB:
3525 case ANALOG_SIG_EMWINK:
3527 if (!ast_strlen_zero(p->dop.dialstr)) {
3530 p->dop.dialstr[0] =
'\0';
3533 ast_debug(1,
"Sent deferred digit string on channel %d: %s\n", p->
channel, p->dop.dialstr);
3536 p->dop.dialstr[0] =
'\0';
3539 ast_log(LOG_WARNING,
"Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3542 case ANALOG_EVENT_HOOKCOMPLETE:
3543 if (p->inalarm)
break;
3544 if (analog_check_waitingfordt(p)) {
3548 case ANALOG_SIG_FXSLS:
3549 case ANALOG_SIG_FXSGS:
3550 case ANALOG_SIG_FXSKS:
3552 case ANALOG_SIG_EM_E1:
3553 case ANALOG_SIG_EMWINK:
3554 case ANALOG_SIG_FEATD:
3556 case ANALOG_SIG_SFWINK:
3557 case ANALOG_SIG_SF_FEATD:
3558 if (!ast_strlen_zero(p->dop.dialstr)) {
3561 p->dop.dialstr[0] =
'\0';
3564 ast_debug(1,
"Sent deferred digit string on channel %d: %s\n", p->
channel, p->dop.dialstr);
3567 p->dop.dialstr[0] =
'\0';
3568 p->dop.op = ANALOG_DIAL_OP_REPLACE;
3570 case ANALOG_SIG_FEATDMF:
3571 case ANALOG_SIG_FEATDMF_TA:
3572 case ANALOG_SIG_E911:
3573 case ANALOG_SIG_FGC_CAMA:
3574 case ANALOG_SIG_FGC_CAMAMF:
3575 case ANALOG_SIG_FEATB:
3576 case ANALOG_SIG_SF_FEATDMF:
3577 case ANALOG_SIG_SF_FEATB:
3578 ast_debug(1,
"Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->
channel);
3584 case ANALOG_EVENT_POLARITY:
3594 if (p->polarityonanswerdelay > 0) {
3600 if (p->answeronpolarityswitch) {
3603 p->polarity = POLARITY_REV;
3604 if (p->hanguponpolarityswitch) {
3608 ast_debug(1,
"Ignore Answer on polarity switch, channel %d\n", p->
channel);
3614 if (p->hanguponpolarityswitch) {
3621 ast_debug(1,
"Ignore Hangup on polarity switch, channel %d\n", p->
channel);
3632 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
3643 if (p->answeronpolarityswitch) {
3650 if (p->hanguponpolarityswitch) {
3656 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
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;
3681 idx = analog_get_index(ast, p, 1);
3693 p->
subs[idx].
f.
src =
"dahdi_exception";
3702 res = analog_get_event(p);
3705 if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
3706 (res != ANALOG_EVENT_HOOKCOMPLETE)) {
3707 ast_debug(1,
"Restoring owner of channel %d on event %d\n", p->
channel, res);
3714 ast_log(LOG_WARNING,
"Event %s on %s is not restored owner %s\n",
3715 analog_event2str(res), ast_channel_name(ast), ast_channel_name(p->
owner));
3722 case ANALOG_EVENT_ONHOOK:
3723 analog_set_echocanceller(p, 0);
3725 ast_verb(3,
"Channel %s still has call, ringing phone\n", ast_channel_name(p->
owner));
3727 analog_stop_callwait(p);
3729 ast_log(LOG_WARNING,
"Absorbed %s, but nobody is left!?!?\n",
3730 analog_event2str(res));
3732 analog_update_conf(p);
3734 case ANALOG_EVENT_RINGOFFHOOK:
3735 analog_set_echocanceller(p, 1);
3739 analog_set_dialing(p, 0);
3742 case ANALOG_EVENT_HOOKCOMPLETE:
3743 case ANALOG_EVENT_RINGERON:
3744 case ANALOG_EVENT_RINGEROFF:
3747 case ANALOG_EVENT_WINKFLASH:
3750 ast_verb(3,
"Channel %d flashed to other channel %s\n", p->
channel, ast_channel_name(p->
owner));
3756 analog_stop_callwait(p);
3759 ast_log(LOG_WARNING,
"Absorbed %s, but nobody is left!?!?\n",
3760 analog_event2str(res));
3762 analog_update_conf(p);
3765 ast_log(LOG_WARNING,
"Don't know how to absorb event %s\n", analog_event2str(res));
3768 f = &p->
subs[idx].
f;
3771 ast_debug(1,
"Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->
channel);
3773 if (ast != p->
owner) {
3774 ast_log(LOG_WARNING,
"We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->
owner));
3775 f = &p->
subs[idx].
f;
3781 const char *name =
ast_strdupa(ast_channel_name(ast));
3784 analog_unlock_private(p);
3785 ast_channel_unlock(ast);
3787 ast_channel_lock(ast);
3788 analog_lock_private(p);
3793 void *analog_handle_init_event(
struct analog_pvt *i,
int event)
3798 ast_callid callid = 0;
3801 ast_debug(1,
"channel (%d) - signaling (%d) - event (%s)\n",
3802 i->
channel, i->sig, analog_event2str(event));
3806 case ANALOG_EVENT_WINKFLASH:
3807 case ANALOG_EVENT_RINGBEGIN:
3809 case ANALOG_SIG_FXSLS:
3810 case ANALOG_SIG_FXSGS:
3811 case ANALOG_SIG_FXSKS:
3813 if (i->
use_callerid || i->usedistinctiveringdetection) {
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);
3822 analog_set_ringtimeout(i, 0);
3830 if (!(ISTRUNK(i) && i->immediate && !i->
use_callerid && !i->usedistinctiveringdetection)) {
3833 case ANALOG_EVENT_RINGOFFHOOK:
3839 case ANALOG_SIG_FXOLS:
3840 case ANALOG_SIG_FXOGS:
3841 case ANALOG_SIG_FXOKS:
3842 res = analog_off_hook(i);
3843 i->fxsoffhookstate = 1;
3845 if (res && (errno == EBUSY)) {
3851 analog_cancel_cidspill(i);
3854 analog_set_echocanceller(i, 1);
3862 ast_log(LOG_WARNING,
"Unable to start PBX on channel %d\n", i->
channel);
3865 ast_log(LOG_WARNING,
"Unable to play congestion tone on channel %d\n", i->
channel);
3871 i->ss_astchan = chan;
3873 if (analog_has_voicemail(i)) {
3879 ast_log(LOG_WARNING,
"Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->
channel);
3881 if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3882 ast_log(LOG_WARNING,
"Unable to start simple switch thread on channel %d\n", i->
channel);
3885 ast_log(LOG_WARNING,
"Unable to play congestion tone on channel %d\n", i->
channel);
3890 ast_log(LOG_WARNING,
"Unable to create channel\n");
3894 case ANALOG_SIG_FXSLS:
3895 case ANALOG_SIG_FXSGS:
3896 case ANALOG_SIG_FXSKS:
3897 analog_set_ringtimeout(i, i->ringt_base);
3899 case ANALOG_SIG_EMWINK:
3900 case ANALOG_SIG_FEATD:
3901 case ANALOG_SIG_FEATDMF:
3902 case ANALOG_SIG_FEATDMF_TA:
3903 case ANALOG_SIG_E911:
3904 case ANALOG_SIG_FGC_CAMA:
3905 case ANALOG_SIG_FGC_CAMAMF:
3906 case ANALOG_SIG_FEATB:
3908 case ANALOG_SIG_EM_E1:
3909 case ANALOG_SIG_SFWINK:
3910 case ANALOG_SIG_SF_FEATD:
3911 case ANALOG_SIG_SF_FEATDMF:
3912 case ANALOG_SIG_SF_FEATB:
3916 if (i->cid_start == ANALOG_CID_START_POLARITY_IN || i->cid_start == ANALOG_CID_START_DTMF_NOALERT) {
3921 i->ss_astchan = chan;
3923 ast_log(LOG_WARNING,
"Cannot allocate new structure on channel %d\n", i->
channel);
3924 }
else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3925 ast_log(LOG_WARNING,
"Unable to start simple switch thread on channel %d\n", i->
channel);
3928 ast_log(LOG_WARNING,
"Unable to play congestion tone on channel %d\n", i->
channel);
3935 ast_log(LOG_WARNING,
"Don't know how to handle ring/answer with signalling %s on channel %d\n", analog_sigtype_to_str(i->sig), i->
channel);
3938 ast_log(LOG_WARNING,
"Unable to play congestion tone on channel %d\n", i->
channel);
3943 case ANALOG_EVENT_NOALARM:
3944 analog_set_alarm(i, 0);
3945 analog_publish_channel_alarm_clear(i->
channel);
3947 case ANALOG_EVENT_ALARM:
3948 analog_set_alarm(i, 1);
3949 analog_get_and_handle_alarms(i);
3951 case ANALOG_EVENT_ONHOOK:
3954 case ANALOG_SIG_FXOLS:
3955 case ANALOG_SIG_FXOGS:
3956 i->fxsoffhookstate = 0;
3957 analog_start_polarityswitch(i);
3959 case ANALOG_SIG_FEATD:
3960 case ANALOG_SIG_FEATDMF:
3961 case ANALOG_SIG_FEATDMF_TA:
3962 case ANALOG_SIG_E911:
3963 case ANALOG_SIG_FGC_CAMA:
3964 case ANALOG_SIG_FGC_CAMAMF:
3965 case ANALOG_SIG_FEATB:
3967 case ANALOG_SIG_EM_E1:
3968 case ANALOG_SIG_EMWINK:
3969 case ANALOG_SIG_SF_FEATD:
3970 case ANALOG_SIG_SF_FEATDMF:
3971 case ANALOG_SIG_SF_FEATB:
3973 case ANALOG_SIG_SFWINK:
3974 case ANALOG_SIG_FXSLS:
3975 case ANALOG_SIG_FXSGS:
3976 case ANALOG_SIG_FXSKS:
3977 analog_set_echocanceller(i, 0);
3981 case ANALOG_SIG_FXOKS:
3982 i->fxsoffhookstate = 0;
3983 analog_start_polarityswitch(i);
3984 analog_set_echocanceller(i, 0);
3994 ast_log(LOG_WARNING,
"Don't know how to handle on hook with signalling %s on channel %d\n", analog_sigtype_to_str(i->sig), i->
channel);
3999 case ANALOG_EVENT_POLARITY:
4001 case ANALOG_SIG_FXSLS:
4002 case ANALOG_SIG_FXSKS:
4003 case ANALOG_SIG_FXSGS:
4009 if (i->hanguponpolarityswitch) {
4010 i->polarity = POLARITY_REV;
4012 if (i->cid_start == ANALOG_CID_START_POLARITY || i->cid_start == ANALOG_CID_START_POLARITY_IN) {
4013 i->polarity = POLARITY_REV;
4014 ast_verb(2,
"Starting post polarity CID detection on channel %d\n",
4017 i->ss_astchan = chan;
4019 ast_log(LOG_WARNING,
"Cannot allocate new structure on channel %d\n", i->
channel);
4020 }
else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4021 ast_log(LOG_WARNING,
"Unable to start simple switch thread on channel %d\n", i->
channel);
4028 ast_log(LOG_WARNING,
4029 "handle_init_event detected polarity reversal on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4034 case ANALOG_EVENT_DTMFCID:
4036 case ANALOG_SIG_FXSLS:
4037 case ANALOG_SIG_FXSKS:
4038 case ANALOG_SIG_FXSGS:
4040 if (i->cid_start == ANALOG_CID_START_DTMF_NOALERT) {
4041 ast_verb(2,
"Starting DTMF CID detection on channel %d\n",
4044 i->ss_astchan = chan;
4046 ast_log(LOG_WARNING,
"Cannot allocate new structure on channel %d\n", i->
channel);
4047 }
else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4048 ast_log(LOG_WARNING,
"Unable to start simple switch thread on channel %d\n", i->
channel);
4055 ast_log(LOG_WARNING,
4056 "handle_init_event detected dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4061 case ANALOG_EVENT_REMOVED:
4062 ast_log(LOG_NOTICE,
"Got ANALOG_EVENT_REMOVED. Destroying channel %d\n",
4065 case ANALOG_EVENT_NEONMWI_ACTIVE:
4066 analog_handle_notify_message(NULL, i, -1, ANALOG_EVENT_NEONMWI_ACTIVE);
4068 case ANALOG_EVENT_NEONMWI_INACTIVE:
4069 analog_handle_notify_message(NULL, i, -1, ANALOG_EVENT_NEONMWI_INACTIVE);
4076 struct analog_pvt *analog_new(
enum analog_sigtype signallingtype,
void *private_data)
4085 p->outsigmod = ANALOG_SIG_NONE;
4086 p->sig = signallingtype;
4087 p->chan_pvt = private_data;
4090 p->cid_start = ANALOG_CID_START_RING;
4109 int analog_config_complete(
struct analog_pvt *p)
4112 if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
4131 ast_debug(1,
"New owner for channel %d is %s\n", new_pvt->
channel, ast_channel_name(newchan));
4132 if (new_pvt->
owner == oldchan) {
4133 analog_set_new_owner(new_pvt, newchan);
4135 for (x = 0; x < 3; x++) {
4136 if (new_pvt->
subs[x].owner == oldchan) {
4137 new_pvt->
subs[x].owner = newchan;
4141 analog_update_conf(new_pvt);
4145 static void analog_publish_dnd_state(
int channel,
const char *status)
4165 int analog_dnd(
struct analog_pvt *p,
int flag)
4173 ast_verb(3,
"%s DND on channel %d\n",
4174 flag ?
"Enabled" :
"Disabled",
4176 analog_publish_dnd_state(p->
channel, flag ?
"enabled" :
"disabled");
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
enum analog_dialmode dialmode
int presentation
Q.931 encoded presentation-indicator encoded field.
int(*const on_hook)(void *pvt)
Set channel on hook.
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch) ...
unsigned int use_callerid
Main Channel structure associated with a channel.
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
char * str
Subscriber phone number (Malloced)
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
void(*const start_polarityswitch)(void *pvt)
Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch.
Asterisk main include file. File version handling, generic pbx functions.
enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee, struct ast_channel *to_transfer_target)
Attended transfer.
char chan_name[AST_CHANNEL_NAME]
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
struct ast_party_caller caller
Channel Caller ID information.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
struct ast_party_id id
Connected party ID.
#define ast_channel_unref(c)
Decrease channel reference count.
static struct ast_frame * __analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_party_name name
Subscriber name.
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
void(*const hangup_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
says digits of a string
struct analog_callback analog_callbacks
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
ast_channel_state
ast_channel states
char * str
Subscriber name (Malloced)
#define ANALOG_MATCH_DIGIT_TIMEOUT
Default time (ms) to wait, in case of ambiguous match.
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
int ast_parking_blind_transfer_park(struct ast_bridge_channel *parker, const char *context, const char *exten, transfer_channel_cb parked_channel_cb, struct transfer_channel_data *parked_channel_data)
Perform a blind transfer to a parking extension.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
unsigned int transfertobusy
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
#define ast_strdup(str)
A wrapper for strdup()
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_queue_cc_frame(struct ast_channel *chan, const char *const monitor_type, const char *const dialstring, enum ast_cc_service_type service, void *private_data)
Queue an AST_CONTROL_CC frame.
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
int code
enum AST_REDIRECTING_REASON value for redirection
struct ast_smdi_md_message * ast_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
Get the next SMDI message from the queue.
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
struct ast_cc_config_params * ast_channel_get_cc_config_params(struct ast_channel *chan)
Get the CCSS parameters from a channel.
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
void(*const set_polarity)(void *pvt, int value)
Set FXS line polarity to 0=IDLE NZ=REVERSED.
enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
Get the cc_monitor_policy.
struct ast_channel * owner
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
struct ast_party_id id
Caller party ID.
struct ast_party_id ani
Automatic Number Identification (ANI)
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it's bridge.
#define ast_strdupa(s)
duplicate a string in memory from the stack
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created)
Use in conjunction with ast_callid_threadstorage_auto. Cleans up the references and if the callid was...
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define AST_MAX_EXTENSION
Caller Party information.
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
unsigned int immediatering
void(*const swap_subs)(void *pvt, enum analog_sub a, struct ast_channel *new_a_owner, enum analog_sub b, struct ast_channel *new_b_owner)
#define ast_debug(level,...)
Log a DEBUG message.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
An SMDI message desk message.
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Core PBX routines and definitions.
#define AST_CC_GENERIC_MONITOR_TYPE
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Support for dynamic strings.
int ast_parking_is_exten_park(const char *context, const char *exten)
Determine if the context/exten is a "parking" extension.
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
int ani2
Automatic Number Identification 2 (Info Digits)
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
int(*const off_hook)(void *pvt)
Set channel off hook.
int ast_parking_provider_registered(void)
Check whether a parking provider is registered.
union ast_frame::@224 data
#define ast_calloc(num, len)
A wrapper for calloc()
unsigned int dahditrcallerid
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
unsigned int permhidecallerid
struct ast_party_redirecting_reason reason
Reason for the redirection.
struct ast_bridge_channel * ast_channel_get_bridge_channel(struct ast_channel *chan)
Get a reference to the channel's bridge pointer.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
struct ast_frame ast_null_frame
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
int ast_callid_threadstorage_auto(ast_callid *callid)
Checks thread storage for a callid and stores a reference if it exists. If not, then a new one will b...
#define ANALOG_FIRST_DIGIT_TIMEOUT
Default time (ms) to detect first digit.
Structure that contains information regarding a channel in a bridge.
#define ast_channel_ref(c)
Increase channel reference count.
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
unsigned int callwaitingcallerid
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
unsigned int call_qualifier
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame with payload.
Interface header for analog signaling module.
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
#define MIN_MS_SINCE_FLASH
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
#define ANALOG_INTER_DIGIT_TIMEOUT
Default time (ms) to detect following digits.
Abstract JSON element (object, array, string, int, ...).
Options provided by main asterisk program.
unsigned int threewaysilenthold
#define AST_OPTION_TONE_VERIFY
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
enum ast_frame_type frametype
unsigned char valid
TRUE if the name information is valid/present.
Call Parking and Pickup API Includes code and algorithms from the Zapata library. ...
struct analog_subchannel subs[3]
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s...
Say numbers and dates (maybe words one day too)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Persistent data storage (akin to *doze registry)
unsigned char valid
TRUE if the number information is valid/present.
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel. ...
unsigned int calledsubscriberheld
unsigned int permcallwaiting
void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj)
Publish an event to AMI.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Configuration relating to call pickup.
struct ast_party_number number
Subscriber phone number.