| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "asterisk.h" |
| 31 |
|
| 32 |
#include <errno.h> |
| 33 |
#include <ctype.h> |
| 34 |
|
| 35 |
#include "asterisk/utils.h" |
| 36 |
#include "asterisk/options.h" |
| 37 |
#include "asterisk/pickup.h" |
| 38 |
#include "asterisk/pbx.h" |
| 39 |
#include "asterisk/file.h" |
| 40 |
#include "asterisk/callerid.h" |
| 41 |
#include "asterisk/say.h" |
| 42 |
#include "asterisk/manager.h" |
| 43 |
#include "asterisk/astdb.h" |
| 44 |
#include "asterisk/features.h" |
| 45 |
#include "asterisk/causes.h" |
| 46 |
#include "asterisk/features_config.h" |
| 47 |
#include "asterisk/bridge.h" |
| 48 |
#include "asterisk/parking.h" |
| 49 |
|
| 50 |
#include "sig_analog.h" |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 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] = ""; |
| 67 |
|
| 68 |
static const struct { |
| 69 |
enum analog_sigtype sigtype; |
| 70 |
const char *name; |
| 71 |
} sigtypes[] = { |
| 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" }, |
| 93 |
}; |
| 94 |
|
| 95 |
static const struct { |
| 96 |
unsigned int cid_type; |
| 97 |
const char *name; |
| 98 |
} cidtypes[] = { |
| 99 |
{ CID_SIG_BELL, "bell" }, |
| 100 |
{ CID_SIG_V23, "v23" }, |
| 101 |
{ CID_SIG_V23_JP, "v23_jp" }, |
| 102 |
{ CID_SIG_DTMF, "dtmf" }, |
| 103 |
|
| 104 |
|
| 105 |
}; |
| 106 |
|
| 107 |
#define ISTRUNK(p) ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || \ |
| 108 |
(p->sig == ANALOG_SIG_FXSGS)) |
| 109 |
|
| 110 |
enum analog_sigtype analog_str_to_sigtype(const char *name) |
| 111 |
{ |
| 112 |
int i; |
| 113 |
|
| 114 |
for (i = 0; i < ARRAY_LEN(sigtypes); i++) { |
| 115 |
if (!strcasecmp(sigtypes[i].name, name)) { |
| 116 |
return sigtypes[i].sigtype; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
return 0; |
| 121 |
} |
| 122 |
|
| 123 |
const char *analog_sigtype_to_str(enum analog_sigtype sigtype) |
| 124 |
{ |
| 125 |
int i; |
| 126 |
|
| 127 |
for (i = 0; i < ARRAY_LEN(sigtypes); i++) { |
| 128 |
if (sigtype == sigtypes[i].sigtype) { |
| 129 |
return sigtypes[i].name; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
return "Unknown"; |
| 134 |
} |
| 135 |
|
| 136 |
unsigned int analog_str_to_cidtype(const char *name) |
| 137 |
{ |
| 138 |
int i; |
| 139 |
|
| 140 |
for (i = 0; i < ARRAY_LEN(cidtypes); i++) { |
| 141 |
if (!strcasecmp(cidtypes[i].name, name)) { |
| 142 |
return cidtypes[i].cid_type; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
return 0; |
| 147 |
} |
| 148 |
|
| 149 |
const char *analog_cidtype_to_str(unsigned int cid_type) |
| 150 |
{ |
| 151 |
int i; |
| 152 |
|
| 153 |
for (i = 0; i < ARRAY_LEN(cidtypes); i++) { |
| 154 |
if (cid_type == cidtypes[i].cid_type) { |
| 155 |
return cidtypes[i].name; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
return "Unknown"; |
| 160 |
} |
| 161 |
|
| 162 |
static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling) |
| 163 |
{ |
| 164 |
if (analog_callbacks.start_cid_detect) { |
| 165 |
return analog_callbacks.start_cid_detect(p->chan_pvt, cid_signalling); |
| 166 |
} |
| 167 |
return -1; |
| 168 |
} |
| 169 |
|
| 170 |
static int analog_stop_cid_detect(struct analog_pvt *p) |
| 171 |
{ |
| 172 |
if (analog_callbacks.stop_cid_detect) { |
| 173 |
return analog_callbacks.stop_cid_detect(p->chan_pvt); |
| 174 |
} |
| 175 |
return -1; |
| 176 |
} |
| 177 |
|
| 178 |
static int analog_get_callerid(struct analog_pvt *p, char *name, char *number, enum analog_event *ev, size_t timeout) |
| 179 |
{ |
| 180 |
if (analog_callbacks.get_callerid) { |
| 181 |
return analog_callbacks.get_callerid(p->chan_pvt, name, number, ev, timeout); |
| 182 |
} |
| 183 |
return -1; |
| 184 |
} |
| 185 |
|
| 186 |
static const char *analog_get_orig_dialstring(struct analog_pvt *p) |
| 187 |
{ |
| 188 |
if (analog_callbacks.get_orig_dialstring) { |
| 189 |
return analog_callbacks.get_orig_dialstring(p->chan_pvt); |
| 190 |
} |
| 191 |
return ""; |
| 192 |
} |
| 193 |
|
| 194 |
static int analog_get_event(struct analog_pvt *p) |
| 195 |
{ |
| 196 |
if (analog_callbacks.get_event) { |
| 197 |
return analog_callbacks.get_event(p->chan_pvt); |
| 198 |
} |
| 199 |
return -1; |
| 200 |
} |
| 201 |
|
| 202 |
static int analog_wait_event(struct analog_pvt *p) |
| 203 |
{ |
| 204 |
if (analog_callbacks.wait_event) { |
| 205 |
return analog_callbacks.wait_event(p->chan_pvt); |
| 206 |
} |
| 207 |
return -1; |
| 208 |
} |
| 209 |
|
| 210 |
static int analog_have_progressdetect(struct analog_pvt *p) |
| 211 |
{ |
| 212 |
if (analog_callbacks.have_progressdetect) { |
| 213 |
return analog_callbacks.have_progressdetect(p->chan_pvt); |
| 214 |
} |
| 215 |
|
| 216 |
return 0; |
| 217 |
} |
| 218 |
|
| 219 |
#define gen_analog_field_callback(type, callback_name, def_value) \ |
| 220 |
static type analog_get_##callback_name(struct analog_pvt *p) \ |
| 221 |
{ \ |
| 222 |
if (!analog_callbacks.get_##callback_name) { \ |
| 223 |
return def_value; \ |
| 224 |
} \ |
| 225 |
return analog_callbacks.get_##callback_name(p->chan_pvt); \ |
| 226 |
} |
| 227 |
|
| 228 |
gen_analog_field_callback(int, firstdigit_timeout, ANALOG_FIRST_DIGIT_TIMEOUT); |
| 229 |
gen_analog_field_callback(int, interdigit_timeout, ANALOG_INTER_DIGIT_TIMEOUT); |
| 230 |
gen_analog_field_callback(int, matchdigit_timeout, ANALOG_MATCH_DIGIT_TIMEOUT); |
| 231 |
|
| 232 |
#undef gen_analog_field_callback |
| 233 |
|
| 234 |
enum analog_cid_start analog_str_to_cidstart(const char *value) |
| 235 |
{ |
| 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; |
| 244 |
} |
| 245 |
|
| 246 |
return 0; |
| 247 |
} |
| 248 |
|
| 249 |
const char *analog_cidstart_to_str(enum analog_cid_start cid_start) |
| 250 |
{ |
| 251 |
switch (cid_start) { |
| 252 |
case ANALOG_CID_START_RING: |
| 253 |
return "Ring"; |
| 254 |
case ANALOG_CID_START_POLARITY: |
| 255 |
return "Polarity"; |
| 256 |
case ANALOG_CID_START_POLARITY_IN: |
| 257 |
return "Polarity_In"; |
| 258 |
case ANALOG_CID_START_DTMF_NOALERT: |
| 259 |
return "DTMF"; |
| 260 |
} |
| 261 |
|
| 262 |
return "Unknown"; |
| 263 |
} |
| 264 |
|
| 265 |
static char *analog_event2str(enum analog_event event) |
| 266 |
{ |
| 267 |
char *res; |
| 268 |
switch (event) { |
| 269 |
case ANALOG_EVENT_ONHOOK: |
| 270 |
res = "ANALOG_EVENT_ONHOOK"; |
| 271 |
break; |
| 272 |
case ANALOG_EVENT_RINGOFFHOOK: |
| 273 |
res = "ANALOG_EVENT_RINGOFFHOOK"; |
| 274 |
break; |
| 275 |
case ANALOG_EVENT_WINKFLASH: |
| 276 |
res = "ANALOG_EVENT_WINKFLASH"; |
| 277 |
break; |
| 278 |
case ANALOG_EVENT_ALARM: |
| 279 |
res = "ANALOG_EVENT_ALARM"; |
| 280 |
break; |
| 281 |
case ANALOG_EVENT_NOALARM: |
| 282 |
res = "ANALOG_EVENT_NOALARM"; |
| 283 |
break; |
| 284 |
case ANALOG_EVENT_DIALCOMPLETE: |
| 285 |
res = "ANALOG_EVENT_DIALCOMPLETE"; |
| 286 |
break; |
| 287 |
case ANALOG_EVENT_HOOKCOMPLETE: |
| 288 |
res = "ANALOG_EVENT_HOOKCOMPLETE"; |
| 289 |
break; |
| 290 |
case ANALOG_EVENT_PULSE_START: |
| 291 |
res = "ANALOG_EVENT_PULSE_START"; |
| 292 |
break; |
| 293 |
case ANALOG_EVENT_POLARITY: |
| 294 |
res = "ANALOG_EVENT_POLARITY"; |
| 295 |
break; |
| 296 |
case ANALOG_EVENT_RINGBEGIN: |
| 297 |
res = "ANALOG_EVENT_RINGBEGIN"; |
| 298 |
break; |
| 299 |
case ANALOG_EVENT_EC_DISABLED: |
| 300 |
res = "ANALOG_EVENT_EC_DISABLED"; |
| 301 |
break; |
| 302 |
case ANALOG_EVENT_RINGERON: |
| 303 |
res = "ANALOG_EVENT_RINGERON"; |
| 304 |
break; |
| 305 |
case ANALOG_EVENT_RINGEROFF: |
| 306 |
res = "ANALOG_EVENT_RINGEROFF"; |
| 307 |
break; |
| 308 |
case ANALOG_EVENT_REMOVED: |
| 309 |
res = "ANALOG_EVENT_REMOVED"; |
| 310 |
break; |
| 311 |
case ANALOG_EVENT_NEONMWI_ACTIVE: |
| 312 |
res = "ANALOG_EVENT_NEONMWI_ACTIVE"; |
| 313 |
break; |
| 314 |
case ANALOG_EVENT_NEONMWI_INACTIVE: |
| 315 |
res = "ANALOG_EVENT_NEONMWI_INACTIVE"; |
| 316 |
break; |
| 317 |
#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE |
| 318 |
case ANALOG_EVENT_TX_CED_DETECTED: |
| 319 |
res = "ANALOG_EVENT_TX_CED_DETECTED"; |
| 320 |
break; |
| 321 |
case ANALOG_EVENT_RX_CED_DETECTED: |
| 322 |
res = "ANALOG_EVENT_RX_CED_DETECTED"; |
| 323 |
break; |
| 324 |
case ANALOG_EVENT_EC_NLP_DISABLED: |
| 325 |
res = "ANALOG_EVENT_EC_NLP_DISABLED"; |
| 326 |
break; |
| 327 |
case ANALOG_EVENT_EC_NLP_ENABLED: |
| 328 |
res = "ANALOG_EVENT_EC_NLP_ENABLED"; |
| 329 |
break; |
| 330 |
#endif |
| 331 |
case ANALOG_EVENT_PULSEDIGIT: |
| 332 |
res = "ANALOG_EVENT_PULSEDIGIT"; |
| 333 |
break; |
| 334 |
case ANALOG_EVENT_DTMFDOWN: |
| 335 |
res = "ANALOG_EVENT_DTMFDOWN"; |
| 336 |
break; |
| 337 |
case ANALOG_EVENT_DTMFUP: |
| 338 |
res = "ANALOG_EVENT_DTMFUP"; |
| 339 |
break; |
| 340 |
default: |
| 341 |
res = "UNKNOWN/OTHER"; |
| 342 |
break; |
| 343 |
} |
| 344 |
|
| 345 |
return res; |
| 346 |
} |
| 347 |
|
| 348 |
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b) |
| 349 |
{ |
| 350 |
int tinthreeway; |
| 351 |
struct ast_channel *towner; |
| 352 |
|
| 353 |
ast_debug(1, "Swapping %u and %u\n", a, b); |
| 354 |
|
| 355 |
towner = p->subs[a].owner; |
| 356 |
p->subs[a].owner = p->subs[b].owner; |
| 357 |
p->subs[b].owner = towner; |
| 358 |
|
| 359 |
tinthreeway = p->subs[a].inthreeway; |
| 360 |
p->subs[a].inthreeway = p->subs[b].inthreeway; |
| 361 |
p->subs[b].inthreeway = tinthreeway; |
| 362 |
|
| 363 |
if (analog_callbacks.swap_subs) { |
| 364 |
analog_callbacks.swap_subs(p->chan_pvt, a, p->subs[a].owner, b, p->subs[b].owner); |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x) |
| 369 |
{ |
| 370 |
if (analog_callbacks.allocate_sub) { |
| 371 |
int res; |
| 372 |
res = analog_callbacks.allocate_sub(p->chan_pvt, x); |
| 373 |
if (!res) { |
| 374 |
p->subs[x].allocd = 1; |
| 375 |
} |
| 376 |
return res; |
| 377 |
} |
| 378 |
return 0; |
| 379 |
} |
| 380 |
|
| 381 |
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x) |
| 382 |
{ |
| 383 |
p->subs[x].allocd = 0; |
| 384 |
p->subs[x].owner = NULL; |
| 385 |
if (analog_callbacks.unallocate_sub) { |
| 386 |
return analog_callbacks.unallocate_sub(p->chan_pvt, x); |
| 387 |
} |
| 388 |
return 0; |
| 389 |
} |
| 390 |
|
| 391 |
static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller) |
| 392 |
{ |
| 393 |
|
| 394 |
if (!p->use_callerid) { |
| 395 |
ast_debug(1, "Caller ID is disabled for channel %d, skipping spill\n", p->channel); |
| 396 |
return 0; |
| 397 |
} |
| 398 |
|
| 399 |
ast_debug(1, "Sending callerid. CID_NAME: '%s' CID_NUM: '%s'\n", |
| 400 |
caller->id.name.str, |
| 401 |
caller->id.number.str); |
| 402 |
|
| 403 |
if (cwcid) { |
| 404 |
p->callwaitcas = 0; |
| 405 |
} |
| 406 |
|
| 407 |
if (analog_callbacks.send_callerid) { |
| 408 |
return analog_callbacks.send_callerid(p->chan_pvt, cwcid, caller); |
| 409 |
} |
| 410 |
return 0; |
| 411 |
} |
| 412 |
|
| 413 |
#define analog_get_index(ast, p, nullok) _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__) |
| 414 |
static int _analog_get_index(struct ast_channel *ast, struct analog_pvt *p, int nullok, const char *fname, unsigned long line) |
| 415 |
{ |
| 416 |
int res; |
| 417 |
if (p->subs[ANALOG_SUB_REAL].owner == ast) { |
| 418 |
res = ANALOG_SUB_REAL; |
| 419 |
} else if (p->subs[ANALOG_SUB_CALLWAIT].owner == ast) { |
| 420 |
res = ANALOG_SUB_CALLWAIT; |
| 421 |
} else if (p->subs[ANALOG_SUB_THREEWAY].owner == ast) { |
| 422 |
res = ANALOG_SUB_THREEWAY; |
| 423 |
} else { |
| 424 |
res = -1; |
| 425 |
if (!nullok) { |
| 426 |
ast_log(LOG_WARNING, |
| 427 |
"Unable to get index for '%s' on channel %d (%s(), line %lu)\n", |
| 428 |
ast ? ast_channel_name(ast) : "", p->channel, fname, line); |
| 429 |
} |
| 430 |
} |
| 431 |
return res; |
| 432 |
} |
| 433 |
|
| 434 |
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p) |
| 435 |
{ |
| 436 |
if (analog_callbacks.dsp_reset_and_flush_digits) { |
| 437 |
return analog_callbacks.dsp_reset_and_flush_digits(p->chan_pvt); |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
return 0; |
| 442 |
} |
| 443 |
|
| 444 |
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone) |
| 445 |
{ |
| 446 |
if (analog_callbacks.play_tone) { |
| 447 |
return analog_callbacks.play_tone(p->chan_pvt, sub, tone); |
| 448 |
} |
| 449 |
return -1; |
| 450 |
} |
| 451 |
|
| 452 |
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner) |
| 453 |
{ |
| 454 |
p->owner = new_owner; |
| 455 |
if (analog_callbacks.set_new_owner) { |
| 456 |
analog_callbacks.set_new_owner(p->chan_pvt, new_owner); |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
static struct ast_channel * analog_new_ast_channel(struct analog_pvt *p, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor) |
| 461 |
{ |
| 462 |
struct ast_channel *c; |
| 463 |
|
| 464 |
if (!analog_callbacks.new_ast_channel) { |
| 465 |
return NULL; |
| 466 |
} |
| 467 |
|
| 468 |
c = analog_callbacks.new_ast_channel(p->chan_pvt, state, startpbx, sub, requestor); |
| 469 |
if (c) { |
| 470 |
ast_channel_call_forward_set(c, p->call_forward); |
| 471 |
} |
| 472 |
p->subs[sub].owner = c; |
| 473 |
if (!p->owner) { |
| 474 |
analog_set_new_owner(p, c); |
| 475 |
} |
| 476 |
return c; |
| 477 |
} |
| 478 |
|
| 479 |
static int analog_set_echocanceller(struct analog_pvt *p, int enable) |
| 480 |
{ |
| 481 |
if (analog_callbacks.set_echocanceller) { |
| 482 |
return analog_callbacks.set_echocanceller(p->chan_pvt, enable); |
| 483 |
} |
| 484 |
return -1; |
| 485 |
} |
| 486 |
|
| 487 |
static int analog_train_echocanceller(struct analog_pvt *p) |
| 488 |
{ |
| 489 |
if (analog_callbacks.train_echocanceller) { |
| 490 |
return analog_callbacks.train_echocanceller(p->chan_pvt); |
| 491 |
} |
| 492 |
return -1; |
| 493 |
} |
| 494 |
|
| 495 |
static int analog_is_off_hook(struct analog_pvt *p) |
| 496 |
{ |
| 497 |
if (analog_callbacks.is_off_hook) { |
| 498 |
return analog_callbacks.is_off_hook(p->chan_pvt); |
| 499 |
} |
| 500 |
return -1; |
| 501 |
} |
| 502 |
|
| 503 |
static int analog_ring(struct analog_pvt *p) |
| 504 |
{ |
| 505 |
if (analog_callbacks.ring) { |
| 506 |
return analog_callbacks.ring(p->chan_pvt); |
| 507 |
} |
| 508 |
return -1; |
| 509 |
} |
| 510 |
|
| 511 |
static int analog_flash(struct analog_pvt *p) |
| 512 |
{ |
| 513 |
if (analog_callbacks.flash) { |
| 514 |
return analog_callbacks.flash(p->chan_pvt); |
| 515 |
} |
| 516 |
return -1; |
| 517 |
} |
| 518 |
|
| 519 |
static int analog_start(struct analog_pvt *p) |
| 520 |
{ |
| 521 |
if (analog_callbacks.start) { |
| 522 |
return analog_callbacks.start(p->chan_pvt); |
| 523 |
} |
| 524 |
return -1; |
| 525 |
} |
| 526 |
|
| 527 |
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop) |
| 528 |
{ |
| 529 |
if (analog_callbacks.dial_digits) { |
| 530 |
return analog_callbacks.dial_digits(p->chan_pvt, sub, dop); |
| 531 |
} |
| 532 |
return -1; |
| 533 |
} |
| 534 |
|
| 535 |
static int analog_on_hook(struct analog_pvt *p) |
| 536 |
{ |
| 537 |
if (analog_callbacks.on_hook) { |
| 538 |
return analog_callbacks.on_hook(p->chan_pvt); |
| 539 |
} |
| 540 |
return -1; |
| 541 |
} |
| 542 |
|
| 543 |
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing) |
| 544 |
{ |
| 545 |
p->outgoing = is_outgoing; |
| 546 |
if (analog_callbacks.set_outgoing) { |
| 547 |
analog_callbacks.set_outgoing(p->chan_pvt, is_outgoing); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
static int analog_check_for_conference(struct analog_pvt *p) |
| 552 |
{ |
| 553 |
if (analog_callbacks.check_for_conference) { |
| 554 |
return analog_callbacks.check_for_conference(p->chan_pvt); |
| 555 |
} |
| 556 |
return -1; |
| 557 |
} |
| 558 |
|
| 559 |
static void analog_all_subchannels_hungup(struct analog_pvt *p) |
| 560 |
{ |
| 561 |
if (analog_callbacks.all_subchannels_hungup) { |
| 562 |
analog_callbacks.all_subchannels_hungup(p->chan_pvt); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
static void analog_unlock_private(struct analog_pvt *p) |
| 567 |
{ |
| 568 |
if (analog_callbacks.unlock_private) { |
| 569 |
analog_callbacks.unlock_private(p->chan_pvt); |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
static void analog_lock_private(struct analog_pvt *p) |
| 574 |
{ |
| 575 |
if (analog_callbacks.lock_private) { |
| 576 |
analog_callbacks.lock_private(p->chan_pvt); |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
static void analog_deadlock_avoidance_private(struct analog_pvt *p) |
| 581 |
{ |
| 582 |
if (analog_callbacks.deadlock_avoidance_private) { |
| 583 |
analog_callbacks.deadlock_avoidance_private(p->chan_pvt); |
| 584 |
} else { |
| 585 |
|
| 586 |
analog_unlock_private(p); |
| 587 |
usleep(1); |
| 588 |
analog_lock_private(p); |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx) |
| 606 |
{ |
| 607 |
for (;;) { |
| 608 |
if (!pvt->subs[sub_idx].owner) { |
| 609 |
|
| 610 |
break; |
| 611 |
} |
| 612 |
if (!ast_channel_trylock(pvt->subs[sub_idx].owner)) { |
| 613 |
|
| 614 |
break; |
| 615 |
} |
| 616 |
|
| 617 |
analog_deadlock_avoidance_private(pvt); |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
static int analog_off_hook(struct analog_pvt *p) |
| 622 |
{ |
| 623 |
if (analog_callbacks.off_hook) { |
| 624 |
return analog_callbacks.off_hook(p->chan_pvt); |
| 625 |
} |
| 626 |
return -1; |
| 627 |
} |
| 628 |
|
| 629 |
static void analog_set_needringing(struct analog_pvt *p, int value) |
| 630 |
{ |
| 631 |
if (analog_callbacks.set_needringing) { |
| 632 |
analog_callbacks.set_needringing(p->chan_pvt, value); |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
#if 0 |
| 637 |
static void analog_set_polarity(struct analog_pvt *p, int value) |
| 638 |
{ |
| 639 |
if (analog_callbacks.set_polarity) { |
| 640 |
analog_callbacks.set_polarity(p->chan_pvt, value); |
| 641 |
} |
| 642 |
} |
| 643 |
#endif |
| 644 |
|
| 645 |
static void analog_start_polarityswitch(struct analog_pvt *p) |
| 646 |
{ |
| 647 |
if (analog_callbacks.start_polarityswitch) { |
| 648 |
analog_callbacks.start_polarityswitch(p->chan_pvt); |
| 649 |
} |
| 650 |
} |
| 651 |
static void analog_answer_polarityswitch(struct analog_pvt *p) |
| 652 |
{ |
| 653 |
if (analog_callbacks.answer_polarityswitch) { |
| 654 |
analog_callbacks.answer_polarityswitch(p->chan_pvt); |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
static void analog_hangup_polarityswitch(struct analog_pvt *p) |
| 659 |
{ |
| 660 |
if (analog_callbacks.hangup_polarityswitch) { |
| 661 |
analog_callbacks.hangup_polarityswitch(p->chan_pvt); |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode) |
| 666 |
{ |
| 667 |
if (analog_callbacks.dsp_set_digitmode) { |
| 668 |
return analog_callbacks.dsp_set_digitmode(p->chan_pvt, mode); |
| 669 |
} |
| 670 |
return -1; |
| 671 |
} |
| 672 |
|
| 673 |
static void analog_cb_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest) |
| 674 |
{ |
| 675 |
if (analog_callbacks.handle_dtmf) { |
| 676 |
analog_callbacks.handle_dtmf(p->chan_pvt, ast, analog_index, dest); |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
static int analog_wink(struct analog_pvt *p, enum analog_sub index) |
| 681 |
{ |
| 682 |
if (analog_callbacks.wink) { |
| 683 |
return analog_callbacks.wink(p->chan_pvt, index); |
| 684 |
} |
| 685 |
return -1; |
| 686 |
} |
| 687 |
|
| 688 |
static int analog_has_voicemail(struct analog_pvt *p) |
| 689 |
{ |
| 690 |
if (analog_callbacks.has_voicemail) { |
| 691 |
return analog_callbacks.has_voicemail(p->chan_pvt); |
| 692 |
} |
| 693 |
return -1; |
| 694 |
} |
| 695 |
|
| 696 |
static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index) |
| 697 |
{ |
| 698 |
if (analog_callbacks.is_dialing) { |
| 699 |
return analog_callbacks.is_dialing(p->chan_pvt, index); |
| 700 |
} |
| 701 |
return -1; |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
static int analog_attempt_transfer(struct analog_pvt *p) |
| 717 |
{ |
| 718 |
struct ast_channel *owner_real; |
| 719 |
struct ast_channel *owner_3way; |
| 720 |
enum ast_transfer_result xfer_res; |
| 721 |
int res = 0; |
| 722 |
|
| 723 |
owner_real = ast_channel_ref(p->subs[ANALOG_SUB_REAL].owner); |
| 724 |
owner_3way = ast_channel_ref(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 725 |
|
| 726 |
ast_verb(3, "TRANSFERRING %s to %s\n", |
| 727 |
ast_channel_name(owner_3way), ast_channel_name(owner_real)); |
| 728 |
|
| 729 |
ast_channel_unlock(owner_real); |
| 730 |
ast_channel_unlock(owner_3way); |
| 731 |
analog_unlock_private(p); |
| 732 |
|
| 733 |
xfer_res = ast_bridge_transfer_attended(owner_3way, owner_real); |
| 734 |
if (xfer_res != AST_BRIDGE_TRANSFER_SUCCESS) { |
| 735 |
ast_softhangup(owner_3way, AST_SOFTHANGUP_DEV); |
| 736 |
res = -1; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
ast_channel_lock(owner_real); |
| 741 |
analog_lock_private(p); |
| 742 |
|
| 743 |
ast_channel_unref(owner_real); |
| 744 |
ast_channel_unref(owner_3way); |
| 745 |
|
| 746 |
return res; |
| 747 |
} |
| 748 |
|
| 749 |
static int analog_update_conf(struct analog_pvt *p) |
| 750 |
{ |
| 751 |
int x; |
| 752 |
int needconf = 0; |
| 753 |
|
| 754 |
|
| 755 |
for (x = 0; x < 3; x++) { |
| 756 |
|
| 757 |
if ((p->subs[x].allocd) && p->subs[x].inthreeway) { |
| 758 |
if (analog_callbacks.conf_add) { |
| 759 |
analog_callbacks.conf_add(p->chan_pvt, x); |
| 760 |
} |
| 761 |
needconf++; |
| 762 |
} else { |
| 763 |
if (analog_callbacks.conf_del) { |
| 764 |
analog_callbacks.conf_del(p->chan_pvt, x); |
| 765 |
} |
| 766 |
} |
| 767 |
} |
| 768 |
ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf); |
| 769 |
|
| 770 |
if (analog_callbacks.complete_conference_update) { |
| 771 |
analog_callbacks.complete_conference_update(p->chan_pvt, needconf); |
| 772 |
} |
| 773 |
return 0; |
| 774 |
} |
| 775 |
|
| 776 |
struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor) |
| 777 |
{ |
| 778 |
struct ast_channel *ast; |
| 779 |
|
| 780 |
ast_debug(1, "%s %d\n", __FUNCTION__, p->channel); |
| 781 |
*callwait = (p->owner != NULL); |
| 782 |
|
| 783 |
if (p->owner) { |
| 784 |
if (analog_alloc_sub(p, ANALOG_SUB_CALLWAIT)) { |
| 785 |
ast_log(LOG_ERROR, "Unable to alloc subchannel\n"); |
| 786 |
return NULL; |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
analog_set_outgoing(p, 1); |
| 791 |
ast = analog_new_ast_channel(p, AST_STATE_RESERVED, 0, |
| 792 |
p->owner ? ANALOG_SUB_CALLWAIT : ANALOG_SUB_REAL, requestor); |
| 793 |
if (!ast) { |
| 794 |
analog_set_outgoing(p, 0); |
| 795 |
} |
| 796 |
return ast; |
| 797 |
} |
| 798 |
|
| 799 |
int analog_available(struct analog_pvt *p) |
| 800 |
{ |
| 801 |
int offhook; |
| 802 |
|
| 803 |
ast_debug(1, "%s %d\n", __FUNCTION__, p->channel); |
| 804 |
|
| 805 |
|
| 806 |
if (p->dnd) { |
| 807 |
return 0; |
| 808 |
} |
| 809 |
|
| 810 |
if (p->guardtime && (time(NULL) < p->guardtime)) { |
| 811 |
return 0; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
if (p->cshactive) { |
| 816 |
return 0; |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
if (!p->owner) { |
| 821 |
offhook = analog_is_off_hook(p); |
| 822 |
|
| 823 |
|
| 824 |
if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) { |
| 825 |
#ifdef DAHDI_CHECK_HOOKSTATE |
| 826 |
if (offhook) { |
| 827 |
return 1; |
| 828 |
} |
| 829 |
return 0; |
| 830 |
#endif |
| 831 |
|
| 832 |
} else if (offhook) { |
| 833 |
ast_debug(1, "Channel %d off hook, can't use\n", p->channel); |
| 834 |
|
| 835 |
return 0; |
| 836 |
} |
| 837 |
return 1; |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) { |
| 842 |
return 0; |
| 843 |
} |
| 844 |
|
| 845 |
if (!p->callwaiting) { |
| 846 |
|
| 847 |
return 0; |
| 848 |
} |
| 849 |
|
| 850 |
if (p->subs[ANALOG_SUB_CALLWAIT].allocd) { |
| 851 |
|
| 852 |
return 0; |
| 853 |
} |
| 854 |
|
| 855 |
if ((ast_channel_state(p->owner) != AST_STATE_UP) && |
| 856 |
((ast_channel_state(p->owner) != AST_STATE_RINGING) || p->outgoing)) { |
| 857 |
|
| 858 |
return 0; |
| 859 |
} |
| 860 |
if ((p->subs[ANALOG_SUB_THREEWAY].owner) && (!p->subs[ANALOG_SUB_THREEWAY].inthreeway)) { |
| 861 |
|
| 862 |
return 0; |
| 863 |
} |
| 864 |
|
| 865 |
return 1; |
| 866 |
} |
| 867 |
|
| 868 |
static int analog_stop_callwait(struct analog_pvt *p) |
| 869 |
{ |
| 870 |
p->callwaitcas = 0; |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
p->dialmode = p->permdialmode; |
| 880 |
|
| 881 |
if (analog_callbacks.stop_callwait) { |
| 882 |
return analog_callbacks.stop_callwait(p->chan_pvt); |
| 883 |
} |
| 884 |
return 0; |
| 885 |
} |
| 886 |
|
| 887 |
static int analog_callwait(struct analog_pvt *p) |
| 888 |
{ |
| 889 |
p->callwaitcas = p->callwaitingcallerid; |
| 890 |
if (analog_callbacks.callwait) { |
| 891 |
return analog_callbacks.callwait(p->chan_pvt); |
| 892 |
} |
| 893 |
return 0; |
| 894 |
} |
| 895 |
|
| 896 |
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable) |
| 897 |
{ |
| 898 |
p->callwaiting = callwaiting_enable; |
| 899 |
if (analog_callbacks.set_callwaiting) { |
| 900 |
analog_callbacks.set_callwaiting(p->chan_pvt, callwaiting_enable); |
| 901 |
} |
| 902 |
} |
| 903 |
|
| 904 |
static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan) |
| 905 |
{ |
| 906 |
if (analog_callbacks.set_cadence) { |
| 907 |
analog_callbacks.set_cadence(p->chan_pvt, &p->cidrings, chan); |
| 908 |
} |
| 909 |
} |
| 910 |
|
| 911 |
static void analog_set_dialing(struct analog_pvt *p, int is_dialing) |
| 912 |
{ |
| 913 |
p->dialing = is_dialing; |
| 914 |
if (analog_callbacks.set_dialing) { |
| 915 |
analog_callbacks.set_dialing(p->chan_pvt, is_dialing); |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
static void analog_set_alarm(struct analog_pvt *p, int in_alarm) |
| 920 |
{ |
| 921 |
p->inalarm = in_alarm; |
| 922 |
if (analog_callbacks.set_alarm) { |
| 923 |
analog_callbacks.set_alarm(p->chan_pvt, in_alarm); |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt) |
| 928 |
{ |
| 929 |
p->ringt = ringt; |
| 930 |
if (analog_callbacks.set_ringtimeout) { |
| 931 |
analog_callbacks.set_ringtimeout(p->chan_pvt, ringt); |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast) |
| 936 |
{ |
| 937 |
if (analog_callbacks.set_waitingfordt) { |
| 938 |
analog_callbacks.set_waitingfordt(p->chan_pvt, ast); |
| 939 |
} |
| 940 |
} |
| 941 |
|
| 942 |
static int analog_check_waitingfordt(struct analog_pvt *p) |
| 943 |
{ |
| 944 |
if (analog_callbacks.check_waitingfordt) { |
| 945 |
return analog_callbacks.check_waitingfordt(p->chan_pvt); |
| 946 |
} |
| 947 |
|
| 948 |
return 0; |
| 949 |
} |
| 950 |
|
| 951 |
static void analog_set_confirmanswer(struct analog_pvt *p, int flag) |
| 952 |
{ |
| 953 |
if (analog_callbacks.set_confirmanswer) { |
| 954 |
analog_callbacks.set_confirmanswer(p->chan_pvt, flag); |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
static int analog_check_confirmanswer(struct analog_pvt *p) |
| 959 |
{ |
| 960 |
if (analog_callbacks.check_confirmanswer) { |
| 961 |
return analog_callbacks.check_confirmanswer(p->chan_pvt); |
| 962 |
} |
| 963 |
|
| 964 |
return 0; |
| 965 |
} |
| 966 |
|
| 967 |
static void analog_cancel_cidspill(struct analog_pvt *p) |
| 968 |
{ |
| 969 |
if (analog_callbacks.cancel_cidspill) { |
| 970 |
analog_callbacks.cancel_cidspill(p->chan_pvt); |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
static int analog_confmute(struct analog_pvt *p, int mute) |
| 975 |
{ |
| 976 |
if (analog_callbacks.confmute) { |
| 977 |
return analog_callbacks.confmute(p->chan_pvt, mute); |
| 978 |
} |
| 979 |
return 0; |
| 980 |
} |
| 981 |
|
| 982 |
static void analog_set_pulsedial(struct analog_pvt *p, int flag) |
| 983 |
{ |
| 984 |
if (analog_callbacks.set_pulsedial) { |
| 985 |
analog_callbacks.set_pulsedial(p->chan_pvt, flag); |
| 986 |
} |
| 987 |
} |
| 988 |
|
| 989 |
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode) |
| 990 |
{ |
| 991 |
if (analog_callbacks.set_linear_mode) { |
| 992 |
|
| 993 |
return analog_callbacks.set_linear_mode(p->chan_pvt, sub, linear_mode); |
| 994 |
} |
| 995 |
return -1; |
| 996 |
} |
| 997 |
|
| 998 |
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway) |
| 999 |
{ |
| 1000 |
p->subs[sub].inthreeway = inthreeway; |
| 1001 |
if (analog_callbacks.set_inthreeway) { |
| 1002 |
analog_callbacks.set_inthreeway(p->chan_pvt, sub, inthreeway); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout) |
| 1007 |
{ |
| 1008 |
int res, idx, mysig; |
| 1009 |
char *c, *n, *l; |
| 1010 |
char dest[256]; |
| 1011 |
|
| 1012 |
ast_debug(1, "CALLING CID_NAME: %s CID_NUM:: %s\n", |
| 1013 |
S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, ""), |
| 1014 |
S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, "")); |
| 1015 |
|
| 1016 |
ast_copy_string(dest, rdest, sizeof(dest)); |
| 1017 |
ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest)); |
| 1018 |
|
| 1019 |
if ((ast_channel_state(ast) == AST_STATE_BUSY)) { |
| 1020 |
ast_queue_control(p->subs[ANALOG_SUB_REAL].owner, AST_CONTROL_BUSY); |
| 1021 |
return 0; |
| 1022 |
} |
| 1023 |
|
| 1024 |
if ((ast_channel_state(ast) != AST_STATE_DOWN) && (ast_channel_state(ast) != AST_STATE_RESERVED)) { |
| 1025 |
ast_log(LOG_WARNING, "analog_call called on %s, neither down nor reserved\n", ast_channel_name(ast)); |
| 1026 |
return -1; |
| 1027 |
} |
| 1028 |
|
| 1029 |
p->dialednone = 0; |
| 1030 |
analog_set_outgoing(p, 1); |
| 1031 |
|
| 1032 |
mysig = p->sig; |
| 1033 |
if (p->outsigmod > -1) { |
| 1034 |
mysig = p->outsigmod; |
| 1035 |
} |
| 1036 |
|
| 1037 |
switch (mysig) { |
| 1038 |
case ANALOG_SIG_FXOLS: |
| 1039 |
case ANALOG_SIG_FXOGS: |
| 1040 |
case ANALOG_SIG_FXOKS: |
| 1041 |
if (p->owner == ast) { |
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
analog_set_dialing(p, 1); |
| 1046 |
analog_set_cadence(p, ast); |
| 1047 |
|
| 1048 |
|
| 1049 |
c = strchr(dest, '/'); |
| 1050 |
if (c) { |
| 1051 |
c++; |
| 1052 |
} |
| 1053 |
if (c && (strlen(c) < p->stripmsd)) { |
| 1054 |
ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd); |
| 1055 |
c = NULL; |
| 1056 |
} |
| 1057 |
if (c && (strlen(c) > sizeof(p->dop.dialstr) - 3 )) { |
| 1058 |
ast_log(LOG_WARNING, "Number '%s' is longer than %d bytes\n", c, (int)sizeof(p->dop.dialstr) - 2); |
| 1059 |
c = NULL; |
| 1060 |
} |
| 1061 |
if (c) { |
| 1062 |
p->dop.op = ANALOG_DIAL_OP_REPLACE; |
| 1063 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c); |
| 1064 |
ast_debug(1, "FXO: setup deferred dialstring: %s\n", c); |
| 1065 |
} else { |
| 1066 |
p->dop.dialstr[0] = '\0'; |
| 1067 |
} |
| 1068 |
|
| 1069 |
if (analog_ring(p)) { |
| 1070 |
ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno)); |
| 1071 |
return -1; |
| 1072 |
} |
| 1073 |
analog_set_dialing(p, 1); |
| 1074 |
} else { |
| 1075 |
|
| 1076 |
if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) { |
| 1077 |
ast_copy_string(p->callwait_num, ast_channel_connected(ast)->id.number.str, sizeof(p->callwait_num)); |
| 1078 |
} else { |
| 1079 |
p->callwait_num[0] = '\0'; |
| 1080 |
} |
| 1081 |
if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) { |
| 1082 |
ast_copy_string(p->callwait_name, ast_channel_connected(ast)->id.name.str, sizeof(p->callwait_name)); |
| 1083 |
} else { |
| 1084 |
p->callwait_name[0] = '\0'; |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
if (analog_callwait(p)) { |
| 1089 |
return -1; |
| 1090 |
} |
| 1091 |
|
| 1092 |
if (analog_play_tone(p, ANALOG_SUB_CALLWAIT, ANALOG_TONE_RINGTONE)) { |
| 1093 |
ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast_channel_name(ast)); |
| 1094 |
} |
| 1095 |
|
| 1096 |
} |
| 1097 |
|
| 1098 |
|
| 1099 |
n = ast_channel_connected(ast)->id.name.valid ? ast_channel_connected(ast)->id.name.str : NULL; |
| 1100 |
l = ast_channel_connected(ast)->id.number.valid ? ast_channel_connected(ast)->id.number.str : NULL; |
| 1101 |
if (l) { |
| 1102 |
ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num)); |
| 1103 |
} else { |
| 1104 |
p->lastcid_num[0] = '\0'; |
| 1105 |
} |
| 1106 |
if (n) { |
| 1107 |
ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name)); |
| 1108 |
} else { |
| 1109 |
p->lastcid_name[0] = '\0'; |
| 1110 |
} |
| 1111 |
|
| 1112 |
if (p->use_callerid) { |
| 1113 |
const char *qual_var; |
| 1114 |
|
| 1115 |
|
| 1116 |
p->caller.id.name.str = p->lastcid_name; |
| 1117 |
p->caller.id.number.str = p->lastcid_num; |
| 1118 |
p->caller.id.name.valid = ast_channel_connected(ast)->id.name.valid; |
| 1119 |
p->caller.id.number.valid = ast_channel_connected(ast)->id.number.valid; |
| 1120 |
p->caller.id.name.presentation = ast_channel_connected(ast)->id.name.presentation; |
| 1121 |
p->caller.id.number.presentation = ast_channel_connected(ast)->id.number.presentation; |
| 1122 |
|
| 1123 |
|
| 1124 |
p->redirecting_reason = ast_channel_redirecting(ast)->from.number.valid ? ast_channel_redirecting(ast)->reason.code : -1; |
| 1125 |
|
| 1126 |
|
| 1127 |
ast_channel_lock(ast); |
| 1128 |
|
| 1129 |
qual_var = pbx_builtin_getvar_helper(ast, "CALL_QUALIFIER"); |
| 1130 |
p->call_qualifier = ast_true(qual_var) ? 1 : 0; |
| 1131 |
ast_channel_unlock(ast); |
| 1132 |
} |
| 1133 |
|
| 1134 |
ast_setstate(ast, AST_STATE_RINGING); |
| 1135 |
idx = analog_get_index(ast, p, 0); |
| 1136 |
if (idx > -1) { |
| 1137 |
struct ast_cc_config_params *cc_params; |
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
cc_params = ast_channel_get_cc_config_params(p->subs[idx].owner); |
| 1143 |
if (cc_params) { |
| 1144 |
switch (ast_get_cc_monitor_policy(cc_params)) { |
| 1145 |
case AST_CC_MONITOR_NEVER: |
| 1146 |
break; |
| 1147 |
case AST_CC_MONITOR_NATIVE: |
| 1148 |
case AST_CC_MONITOR_ALWAYS: |
| 1149 |
case AST_CC_MONITOR_GENERIC: |
| 1150 |
ast_queue_cc_frame(p->subs[idx].owner, AST_CC_GENERIC_MONITOR_TYPE, |
| 1151 |
analog_get_orig_dialstring(p), AST_CC_CCNR, NULL); |
| 1152 |
break; |
| 1153 |
} |
| 1154 |
} |
| 1155 |
ast_queue_control(p->subs[idx].owner, AST_CONTROL_RINGING); |
| 1156 |
} |
| 1157 |
break; |
| 1158 |
case ANALOG_SIG_FXSLS: |
| 1159 |
case ANALOG_SIG_FXSGS: |
| 1160 |
case ANALOG_SIG_FXSKS: |
| 1161 |
if (p->answeronpolarityswitch || p->hanguponpolarityswitch) { |
| 1162 |
ast_debug(1, "Ignore possible polarity reversal on line seizure\n"); |
| 1163 |
p->polaritydelaytv = ast_tvnow(); |
| 1164 |
} |
| 1165 |
|
| 1166 |
case ANALOG_SIG_EMWINK: |
| 1167 |
case ANALOG_SIG_EM: |
| 1168 |
case ANALOG_SIG_EM_E1: |
| 1169 |
case ANALOG_SIG_FEATD: |
| 1170 |
case ANALOG_SIG_FEATDMF: |
| 1171 |
case ANALOG_SIG_E911: |
| 1172 |
case ANALOG_SIG_FGC_CAMA: |
| 1173 |
case ANALOG_SIG_FGC_CAMAMF: |
| 1174 |
case ANALOG_SIG_FEATB: |
| 1175 |
case ANALOG_SIG_SFWINK: |
| 1176 |
case ANALOG_SIG_SF: |
| 1177 |
case ANALOG_SIG_SF_FEATD: |
| 1178 |
case ANALOG_SIG_SF_FEATDMF: |
| 1179 |
case ANALOG_SIG_FEATDMF_TA: |
| 1180 |
case ANALOG_SIG_SF_FEATB: |
| 1181 |
c = strchr(dest, '/'); |
| 1182 |
if (c) { |
| 1183 |
c++; |
| 1184 |
} else { |
| 1185 |
c = ""; |
| 1186 |
} |
| 1187 |
if (strlen(c) < p->stripmsd) { |
| 1188 |
ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd); |
| 1189 |
return -1; |
| 1190 |
} |
| 1191 |
res = analog_start(p); |
| 1192 |
if (res < 0) { |
| 1193 |
if (errno != EINPROGRESS) { |
| 1194 |
return -1; |
| 1195 |
} |
| 1196 |
} |
| 1197 |
ast_debug(1, "Dialing '%s'\n", c); |
| 1198 |
p->dop.op = ANALOG_DIAL_OP_REPLACE; |
| 1199 |
|
| 1200 |
c += p->stripmsd; |
| 1201 |
|
| 1202 |
switch (mysig) { |
| 1203 |
case ANALOG_SIG_FEATD: |
| 1204 |
l = ast_channel_connected(ast)->id.number.valid ? ast_channel_connected(ast)->id.number.str : NULL; |
| 1205 |
if (l) { |
| 1206 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c); |
| 1207 |
} else { |
| 1208 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c); |
| 1209 |
} |
| 1210 |
break; |
| 1211 |
case ANALOG_SIG_FEATDMF: |
| 1212 |
l = ast_channel_connected(ast)->id.number.valid ? ast_channel_connected(ast)->id.number.str : NULL; |
| 1213 |
if (l) { |
| 1214 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c); |
| 1215 |
} else { |
| 1216 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c); |
| 1217 |
} |
| 1218 |
break; |
| 1219 |
case ANALOG_SIG_FEATDMF_TA: |
| 1220 |
{ |
| 1221 |
const char *cic = "", *ozz = ""; |
| 1222 |
|
| 1223 |
|
| 1224 |
#ifndef STANDALONE |
| 1225 |
ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ"); |
| 1226 |
if (!ozz) { |
| 1227 |
ozz = analog_defaultozz; |
| 1228 |
} |
| 1229 |
cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC"); |
| 1230 |
if (!cic) { |
| 1231 |
cic = analog_defaultcic; |
| 1232 |
} |
| 1233 |
#endif |
| 1234 |
if (!ozz || !cic) { |
| 1235 |
ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n"); |
| 1236 |
return -1; |
| 1237 |
} |
| 1238 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic); |
| 1239 |
snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c); |
| 1240 |
p->whichwink = 0; |
| 1241 |
} |
| 1242 |
break; |
| 1243 |
case ANALOG_SIG_E911: |
| 1244 |
ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr)); |
| 1245 |
break; |
| 1246 |
case ANALOG_SIG_FGC_CAMA: |
| 1247 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c); |
| 1248 |
break; |
| 1249 |
case ANALOG_SIG_FGC_CAMAMF: |
| 1250 |
case ANALOG_SIG_FEATB: |
| 1251 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c); |
| 1252 |
break; |
| 1253 |
default: |
| 1254 |
if (p->pulse) { |
| 1255 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c); |
| 1256 |
} else { |
| 1257 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c); |
| 1258 |
} |
| 1259 |
break; |
| 1260 |
} |
| 1261 |
|
| 1262 |
if (p->echotraining && (strlen(p->dop.dialstr) > 4)) { |
| 1263 |
memset(p->echorest, 'w', sizeof(p->echorest) - 1); |
| 1264 |
strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2); |
| 1265 |
p->echorest[sizeof(p->echorest) - 1] = '\0'; |
| 1266 |
p->echobreak = 1; |
| 1267 |
p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0'; |
| 1268 |
} else { |
| 1269 |
p->echobreak = 0; |
| 1270 |
} |
| 1271 |
analog_set_waitingfordt(p, ast); |
| 1272 |
if (!res) { |
| 1273 |
if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) { |
| 1274 |
analog_on_hook(p); |
| 1275 |
return -1; |
| 1276 |
} |
| 1277 |
} else { |
| 1278 |
ast_debug(1, "Deferring dialing...\n"); |
| 1279 |
} |
| 1280 |
analog_set_dialing(p, 1); |
| 1281 |
if (ast_strlen_zero(c)) { |
| 1282 |
p->dialednone = 1; |
| 1283 |
} |
| 1284 |
ast_setstate(ast, AST_STATE_DIALING); |
| 1285 |
break; |
| 1286 |
default: |
| 1287 |
ast_debug(1, "not yet implemented\n"); |
| 1288 |
return -1; |
| 1289 |
} |
| 1290 |
return 0; |
| 1291 |
} |
| 1292 |
|
| 1293 |
int analog_hangup(struct analog_pvt *p, struct ast_channel *ast) |
| 1294 |
{ |
| 1295 |
int res; |
| 1296 |
int idx, x; |
| 1297 |
|
| 1298 |
ast_debug(1, "%s %d\n", __FUNCTION__, p->channel); |
| 1299 |
if (!ast_channel_tech_pvt(ast)) { |
| 1300 |
ast_log(LOG_WARNING, "Asked to hangup channel not connected\n"); |
| 1301 |
return 0; |
| 1302 |
} |
| 1303 |
|
| 1304 |
idx = analog_get_index(ast, p, 1); |
| 1305 |
|
| 1306 |
x = 0; |
| 1307 |
if (p->origcid_num) { |
| 1308 |
ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num)); |
| 1309 |
ast_free(p->origcid_num); |
| 1310 |
p->origcid_num = NULL; |
| 1311 |
} |
| 1312 |
if (p->origcid_name) { |
| 1313 |
ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name)); |
| 1314 |
ast_free(p->origcid_name); |
| 1315 |
p->origcid_name = NULL; |
| 1316 |
} |
| 1317 |
|
| 1318 |
analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF); |
| 1319 |
|
| 1320 |
ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n", |
| 1321 |
p->channel, idx, p->subs[ANALOG_SUB_REAL].allocd, p->subs[ANALOG_SUB_CALLWAIT].allocd, p->subs[ANALOG_SUB_THREEWAY].allocd); |
| 1322 |
if (idx > -1) { |
| 1323 |
|
| 1324 |
p->cshactive = 0; |
| 1325 |
p->subs[idx].owner = NULL; |
| 1326 |
p->polarity = POLARITY_IDLE; |
| 1327 |
analog_set_linear_mode(p, idx, 0); |
| 1328 |
switch (idx) { |
| 1329 |
case ANALOG_SUB_REAL: |
| 1330 |
if (p->subs[ANALOG_SUB_CALLWAIT].allocd && p->subs[ANALOG_SUB_THREEWAY].allocd) { |
| 1331 |
ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n"); |
| 1332 |
if (p->subs[ANALOG_SUB_CALLWAIT].inthreeway) { |
| 1333 |
|
| 1334 |
ast_debug(1, "We were flipped over to the callwait, moving back and not owning.\n"); |
| 1335 |
|
| 1336 |
analog_swap_subs(p, ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL); |
| 1337 |
analog_unalloc_sub(p, ANALOG_SUB_CALLWAIT); |
| 1338 |
analog_set_new_owner(p, NULL); |
| 1339 |
} else { |
| 1340 |
|
| 1341 |
ast_debug(1, "We were in the threeway and have a callwait still. Ditching the threeway.\n"); |
| 1342 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 1343 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 1344 |
if (p->subs[ANALOG_SUB_REAL].inthreeway) { |
| 1345 |
|
| 1346 |
|
| 1347 |
ast_debug(1, "Call was complete, setting owner to former third call\n"); |
| 1348 |
analog_set_inthreeway(p, ANALOG_SUB_REAL, 0); |
| 1349 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 1350 |
} else { |
| 1351 |
|
| 1352 |
ast_debug(1, "Call was incomplete, setting owner to NULL\n"); |
| 1353 |
analog_set_new_owner(p, NULL); |
| 1354 |
} |
| 1355 |
} |
| 1356 |
} else if (p->subs[ANALOG_SUB_CALLWAIT].allocd) { |
| 1357 |
|
| 1358 |
analog_lock_sub_owner(p, ANALOG_SUB_CALLWAIT); |
| 1359 |
if (!p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 1360 |
|
| 1361 |
analog_set_new_owner(p, NULL); |
| 1362 |
break; |
| 1363 |
} |
| 1364 |
|
| 1365 |
|
| 1366 |
analog_swap_subs(p, ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL); |
| 1367 |
analog_unalloc_sub(p, ANALOG_SUB_CALLWAIT); |
| 1368 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 1369 |
if (ast_channel_state(p->owner) != AST_STATE_UP) { |
| 1370 |
ast_queue_control(p->subs[ANALOG_SUB_REAL].owner, AST_CONTROL_ANSWER); |
| 1371 |
} |
| 1372 |
ast_queue_unhold(p->subs[ANALOG_SUB_REAL].owner); |
| 1373 |
|
| 1374 |
ast_channel_unlock(p->subs[ANALOG_SUB_REAL].owner); |
| 1375 |
} else if (p->subs[ANALOG_SUB_THREEWAY].allocd) { |
| 1376 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 1377 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 1378 |
if (p->subs[ANALOG_SUB_REAL].inthreeway) { |
| 1379 |
|
| 1380 |
|
| 1381 |
ast_debug(1, "Call was complete, setting owner to former third call\n"); |
| 1382 |
analog_set_inthreeway(p, ANALOG_SUB_REAL, 0); |
| 1383 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 1384 |
} else { |
| 1385 |
|
| 1386 |
ast_debug(1, "Call was incomplete, setting owner to NULL\n"); |
| 1387 |
analog_set_new_owner(p, NULL); |
| 1388 |
} |
| 1389 |
} |
| 1390 |
break; |
| 1391 |
case ANALOG_SUB_CALLWAIT: |
| 1392 |
|
| 1393 |
if (p->subs[ANALOG_SUB_CALLWAIT].inthreeway) { |
| 1394 |
|
| 1395 |
analog_lock_sub_owner(p, ANALOG_SUB_THREEWAY); |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
if (p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 1400 |
ast_queue_hold(p->subs[ANALOG_SUB_THREEWAY].owner, p->mohsuggest); |
| 1401 |
} |
| 1402 |
analog_set_inthreeway(p, ANALOG_SUB_THREEWAY, 0); |
| 1403 |
|
| 1404 |
analog_swap_subs(p, ANALOG_SUB_CALLWAIT, ANALOG_SUB_THREEWAY); |
| 1405 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 1406 |
if (p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 1407 |
|
| 1408 |
ast_channel_unlock(p->subs[ANALOG_SUB_CALLWAIT].owner); |
| 1409 |
} |
| 1410 |
} else { |
| 1411 |
analog_unalloc_sub(p, ANALOG_SUB_CALLWAIT); |
| 1412 |
} |
| 1413 |
break; |
| 1414 |
case ANALOG_SUB_THREEWAY: |
| 1415 |
|
| 1416 |
analog_lock_sub_owner(p, ANALOG_SUB_CALLWAIT); |
| 1417 |
if (p->subs[ANALOG_SUB_CALLWAIT].inthreeway) { |
| 1418 |
|
| 1419 |
|
| 1420 |
analog_set_inthreeway(p, ANALOG_SUB_CALLWAIT, 0); |
| 1421 |
if (p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 1422 |
ast_queue_hold(p->subs[ANALOG_SUB_CALLWAIT].owner, p->mohsuggest); |
| 1423 |
} |
| 1424 |
} |
| 1425 |
if (p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 1426 |
ast_channel_unlock(p->subs[ANALOG_SUB_CALLWAIT].owner); |
| 1427 |
} |
| 1428 |
analog_set_inthreeway(p, ANALOG_SUB_REAL, 0); |
| 1429 |
|
| 1430 |
|
| 1431 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 1432 |
break; |
| 1433 |
default: |
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
ast_log(LOG_ERROR, "Index found but not any type of call?\n"); |
| 1439 |
break; |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
if (!p->subs[ANALOG_SUB_REAL].owner && !p->subs[ANALOG_SUB_CALLWAIT].owner && !p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 1444 |
analog_set_new_owner(p, NULL); |
| 1445 |
analog_set_ringtimeout(p, 0); |
| 1446 |
analog_set_confirmanswer(p, 0); |
| 1447 |
analog_set_pulsedial(p, 0); |
| 1448 |
analog_set_outgoing(p, 0); |
| 1449 |
p->onhooktime = time(NULL); |
| 1450 |
p->cidrings = 1; |
| 1451 |
|
| 1452 |
|
| 1453 |
res = analog_on_hook(p); |
| 1454 |
if (res < 0) { |
| 1455 |
ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast_channel_name(ast)); |
| 1456 |
} |
| 1457 |
switch (p->sig) { |
| 1458 |
case ANALOG_SIG_FXOGS: |
| 1459 |
case ANALOG_SIG_FXOLS: |
| 1460 |
case ANALOG_SIG_FXOKS: |
| 1461 |
|
| 1462 |
if (analog_is_off_hook(p)) { |
| 1463 |
analog_hangup_polarityswitch(p); |
| 1464 |
analog_play_tone(p, ANALOG_SUB_REAL, ANALOG_TONE_CONGESTION); |
| 1465 |
} else { |
| 1466 |
analog_play_tone(p, ANALOG_SUB_REAL, -1); |
| 1467 |
} |
| 1468 |
break; |
| 1469 |
case ANALOG_SIG_FXSGS: |
| 1470 |
case ANALOG_SIG_FXSLS: |
| 1471 |
case ANALOG_SIG_FXSKS: |
| 1472 |
|
| 1473 |
|
| 1474 |
if (ast_channel_state(ast) != AST_STATE_RESERVED) { |
| 1475 |
time(&p->guardtime); |
| 1476 |
p->guardtime += 2; |
| 1477 |
} |
| 1478 |
break; |
| 1479 |
default: |
| 1480 |
analog_play_tone(p, ANALOG_SUB_REAL, -1); |
| 1481 |
break; |
| 1482 |
} |
| 1483 |
|
| 1484 |
analog_set_echocanceller(p, 0); |
| 1485 |
|
| 1486 |
x = 0; |
| 1487 |
ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0); |
| 1488 |
ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0); |
| 1489 |
p->callwaitcas = 0; |
| 1490 |
analog_set_callwaiting(p, p->permcallwaiting); |
| 1491 |
|
| 1492 |
|
| 1493 |
p->hidecallerid = p->permhidecallerid; |
| 1494 |
analog_set_dialing(p, 0); |
| 1495 |
analog_update_conf(p); |
| 1496 |
analog_all_subchannels_hungup(p); |
| 1497 |
} |
| 1498 |
|
| 1499 |
analog_stop_callwait(p); |
| 1500 |
|
| 1501 |
ast_verb(3, "Hanging up on '%s'\n", ast_channel_name(ast)); |
| 1502 |
|
| 1503 |
return 0; |
| 1504 |
} |
| 1505 |
|
| 1506 |
int analog_answer(struct analog_pvt *p, struct ast_channel *ast) |
| 1507 |
{ |
| 1508 |
int res = 0; |
| 1509 |
int idx; |
| 1510 |
int oldstate = ast_channel_state(ast); |
| 1511 |
|
| 1512 |
ast_debug(1, "%s %d\n", __FUNCTION__, p->channel); |
| 1513 |
ast_setstate(ast, AST_STATE_UP); |
| 1514 |
idx = analog_get_index(ast, p, 1); |
| 1515 |
if (idx < 0) { |
| 1516 |
idx = ANALOG_SUB_REAL; |
| 1517 |
} |
| 1518 |
switch (p->sig) { |
| 1519 |
case ANALOG_SIG_FXSLS: |
| 1520 |
case ANALOG_SIG_FXSGS: |
| 1521 |
case ANALOG_SIG_FXSKS: |
| 1522 |
analog_set_ringtimeout(p, 0); |
| 1523 |
|
| 1524 |
case ANALOG_SIG_EM: |
| 1525 |
case ANALOG_SIG_EM_E1: |
| 1526 |
case ANALOG_SIG_EMWINK: |
| 1527 |
case ANALOG_SIG_FEATD: |
| 1528 |
case ANALOG_SIG_FEATDMF: |
| 1529 |
case ANALOG_SIG_FEATDMF_TA: |
| 1530 |
case ANALOG_SIG_E911: |
| 1531 |
case ANALOG_SIG_FGC_CAMA: |
| 1532 |
case ANALOG_SIG_FGC_CAMAMF: |
| 1533 |
case ANALOG_SIG_FEATB: |
| 1534 |
case ANALOG_SIG_SF: |
| 1535 |
case ANALOG_SIG_SFWINK: |
| 1536 |
case ANALOG_SIG_SF_FEATD: |
| 1537 |
case ANALOG_SIG_SF_FEATDMF: |
| 1538 |
case ANALOG_SIG_SF_FEATB: |
| 1539 |
case ANALOG_SIG_FXOLS: |
| 1540 |
case ANALOG_SIG_FXOGS: |
| 1541 |
case ANALOG_SIG_FXOKS: |
| 1542 |
|
| 1543 |
ast_debug(1, "Took %s off hook\n", ast_channel_name(ast)); |
| 1544 |
if (p->hanguponpolarityswitch) { |
| 1545 |
gettimeofday(&p->polaritydelaytv, NULL); |
| 1546 |
} |
| 1547 |
res = analog_off_hook(p); |
| 1548 |
analog_play_tone(p, idx, -1); |
| 1549 |
analog_set_dialing(p, 0); |
| 1550 |
if ((idx == ANALOG_SUB_REAL) && p->subs[ANALOG_SUB_THREEWAY].inthreeway) { |
| 1551 |
if (oldstate == AST_STATE_RINGING) { |
| 1552 |
ast_debug(1, "Finally swapping real and threeway\n"); |
| 1553 |
analog_play_tone(p, ANALOG_SUB_THREEWAY, -1); |
| 1554 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 1555 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 1556 |
} |
| 1557 |
} |
| 1558 |
|
| 1559 |
switch (p->sig) { |
| 1560 |
case ANALOG_SIG_FXSLS: |
| 1561 |
case ANALOG_SIG_FXSKS: |
| 1562 |
case ANALOG_SIG_FXSGS: |
| 1563 |
analog_set_echocanceller(p, 1); |
| 1564 |
analog_train_echocanceller(p); |
| 1565 |
break; |
| 1566 |
case ANALOG_SIG_FXOLS: |
| 1567 |
case ANALOG_SIG_FXOKS: |
| 1568 |
case ANALOG_SIG_FXOGS: |
| 1569 |
analog_answer_polarityswitch(p); |
| 1570 |
break; |
| 1571 |
default: |
| 1572 |
break; |
| 1573 |
} |
| 1574 |
break; |
| 1575 |
default: |
| 1576 |
ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel); |
| 1577 |
res = -1; |
| 1578 |
break; |
| 1579 |
} |
| 1580 |
ast_setstate(ast, AST_STATE_UP); |
| 1581 |
return res; |
| 1582 |
} |
| 1583 |
|
| 1584 |
static int analog_handles_digit(struct ast_frame *f) |
| 1585 |
{ |
| 1586 |
char subclass = toupper(f->subclass.integer); |
| 1587 |
|
| 1588 |
switch (subclass) { |
| 1589 |
case '1': |
| 1590 |
case '2': |
| 1591 |
case '3': |
| 1592 |
case '4': |
| 1593 |
case '5': |
| 1594 |
case '6': |
| 1595 |
case '7': |
| 1596 |
case '9': |
| 1597 |
case 'A': |
| 1598 |
case 'B': |
| 1599 |
case 'C': |
| 1600 |
case 'D': |
| 1601 |
case 'E': |
| 1602 |
case 'F': |
| 1603 |
return 1; |
| 1604 |
default: |
| 1605 |
return 0; |
| 1606 |
} |
| 1607 |
} |
| 1608 |
|
| 1609 |
enum callwaiting_deluxe_option { |
| 1610 |
CWD_CONFERENCE = '3', |
| 1611 |
CWD_HOLD = '6', |
| 1612 |
CWD_DROP = '7', |
| 1613 |
CWD_ANNOUNCEMENT = '8', |
| 1614 |
CWD_FORWARD = '9', |
| 1615 |
}; |
| 1616 |
|
| 1617 |
static const char *callwaiting_deluxe_optname(int option) |
| 1618 |
{ |
| 1619 |
switch (option) { |
| 1620 |
case CWD_CONFERENCE: |
| 1621 |
return "CONFERENCE"; |
| 1622 |
case CWD_HOLD: |
| 1623 |
return "HOLD"; |
| 1624 |
case CWD_DROP: |
| 1625 |
return "DROP"; |
| 1626 |
case CWD_ANNOUNCEMENT: |
| 1627 |
return "ANNOUNCEMENT"; |
| 1628 |
case CWD_FORWARD: |
| 1629 |
return "FORWARD"; |
| 1630 |
default: |
| 1631 |
return "DEFAULT"; |
| 1632 |
} |
| 1633 |
} |
| 1634 |
|
| 1635 |
int analog_callwaiting_deluxe(struct analog_pvt *p, int option) |
| 1636 |
{ |
| 1637 |
const char *announce_var; |
| 1638 |
char announcement[PATH_MAX]; |
| 1639 |
|
| 1640 |
ast_debug(1, "Handling Call Waiting on channel %d with option %c: treatment %s\n", p->channel, option, callwaiting_deluxe_optname(option)); |
| 1641 |
|
| 1642 |
if (!p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 1643 |
|
| 1644 |
ast_debug(1, "Call waiting call disappeared before it could be handled?\n"); |
| 1645 |
return -1; |
| 1646 |
} |
| 1647 |
|
| 1648 |
analog_lock_sub_owner(p, ANALOG_SUB_CALLWAIT); |
| 1649 |
if (!p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 1650 |
ast_log(LOG_WARNING, "Whoa, the call-waiting call disappeared.\n"); |
| 1651 |
return -1; |
| 1652 |
} |
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
switch (option) { |
| 1659 |
case CWD_CONFERENCE: |
| 1660 |
|
| 1661 |
|
| 1662 |
if (p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 1663 |
ast_channel_unlock(p->subs[ANALOG_SUB_CALLWAIT].owner); |
| 1664 |
ast_log(LOG_ERROR, "Already have a 3-way call on channel %d, can't conference!\n", p->channel); |
| 1665 |
return -1; |
| 1666 |
} |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
analog_alloc_sub(p, ANALOG_SUB_THREEWAY); |
| 1671 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_CALLWAIT); |
| 1672 |
analog_unalloc_sub(p, ANALOG_SUB_CALLWAIT); |
| 1673 |
|
| 1674 |
ast_verb(3, "Building conference call with %s and %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner), ast_channel_name(p->subs[ANALOG_SUB_REAL].owner)); |
| 1675 |
analog_set_inthreeway(p, ANALOG_SUB_THREEWAY, 1); |
| 1676 |
analog_set_inthreeway(p, ANALOG_SUB_REAL, 1); |
| 1677 |
|
| 1678 |
if (ast_channel_state(p->subs[ANALOG_SUB_THREEWAY].owner) == AST_STATE_RINGING) { |
| 1679 |
ast_setstate(p->subs[ANALOG_SUB_THREEWAY].owner, AST_STATE_UP); |
| 1680 |
ast_queue_control(p->subs[ANALOG_SUB_THREEWAY].owner, AST_CONTROL_ANSWER); |
| 1681 |
|
| 1682 |
ast_queue_hold(p->subs[ANALOG_SUB_THREEWAY].owner, p->mohsuggest); |
| 1683 |
ast_queue_unhold(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 1684 |
} |
| 1685 |
analog_stop_callwait(p); |
| 1686 |
|
| 1687 |
ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 1688 |
break; |
| 1689 |
case CWD_HOLD: |
| 1690 |
case CWD_ANNOUNCEMENT: |
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
announce_var = pbx_builtin_getvar_helper(p->subs[ANALOG_SUB_CALLWAIT].owner, "CALLWAITDELUXEANNOUNCEMENT"); |
| 1705 |
ast_copy_string(announcement, S_OR(announce_var, "one-moment-please"), sizeof(announcement)); |
| 1706 |
ast_debug(2, "Call Waiting Deluxe announcement for %s: %s\n", ast_channel_name(p->subs[ANALOG_SUB_CALLWAIT].owner), announcement); |
| 1707 |
ast_channel_unlock(p->subs[ANALOG_SUB_CALLWAIT].owner); |
| 1708 |
|
| 1709 |
ast_queue_control_data(p->subs[ANALOG_SUB_CALLWAIT].owner, AST_CONTROL_PLAYBACK_BEGIN, announcement, strlen(announcement) + 1); |
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
break; |
| 1716 |
case CWD_FORWARD: |
| 1717 |
|
| 1718 |
analog_stop_callwait(p); |
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
ast_channel_call_forward_set(p->subs[ANALOG_SUB_CALLWAIT].owner, "f"); |
| 1724 |
ast_channel_unlock(p->subs[ANALOG_SUB_CALLWAIT].owner); |
| 1725 |
|
| 1726 |
break; |
| 1727 |
case CWD_DROP: |
| 1728 |
|
| 1729 |
default: |
| 1730 |
|
| 1731 |
analog_swap_subs(p, ANALOG_SUB_REAL, ANALOG_SUB_CALLWAIT); |
| 1732 |
analog_play_tone(p, ANALOG_SUB_REAL, -1); |
| 1733 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 1734 |
ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner)); |
| 1735 |
if (ast_channel_state(p->subs[ANALOG_SUB_REAL].owner) == AST_STATE_RINGING) { |
| 1736 |
ast_setstate(p->subs[ANALOG_SUB_REAL].owner, AST_STATE_UP); |
| 1737 |
ast_queue_control(p->subs[ANALOG_SUB_REAL].owner, AST_CONTROL_ANSWER); |
| 1738 |
} |
| 1739 |
analog_stop_callwait(p); |
| 1740 |
|
| 1741 |
if (option == CWD_DROP) { |
| 1742 |
|
| 1743 |
ast_queue_hangup(p->subs[ANALOG_SUB_CALLWAIT].owner); |
| 1744 |
ast_verb(3, "Dropping original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner)); |
| 1745 |
} else { |
| 1746 |
|
| 1747 |
if (!p->subs[ANALOG_SUB_CALLWAIT].inthreeway) { |
| 1748 |
ast_queue_hold(p->subs[ANALOG_SUB_CALLWAIT].owner, p->mohsuggest); |
| 1749 |
} |
| 1750 |
ast_verb(3, "Holding original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner)); |
| 1751 |
} |
| 1752 |
|
| 1753 |
|
| 1754 |
ast_queue_hold(p->subs[ANALOG_SUB_REAL].owner, p->mohsuggest); |
| 1755 |
ast_queue_unhold(p->subs[ANALOG_SUB_REAL].owner); |
| 1756 |
|
| 1757 |
|
| 1758 |
ast_channel_unlock(p->subs[ANALOG_SUB_REAL].owner); |
| 1759 |
} |
| 1760 |
analog_update_conf(p); |
| 1761 |
return 0; |
| 1762 |
} |
| 1763 |
|
| 1764 |
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest) |
| 1765 |
{ |
| 1766 |
struct ast_frame *f = *dest; |
| 1767 |
|
| 1768 |
ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n", |
| 1769 |
f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End", |
| 1770 |
(unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast)); |
| 1771 |
|
| 1772 |
if (analog_check_confirmanswer(p)) { |
| 1773 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 1774 |
ast_debug(1, "Confirm answer on %s!\n", ast_channel_name(ast)); |
| 1775 |
|
| 1776 |
|
| 1777 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 1778 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 1779 |
|
| 1780 |
analog_set_confirmanswer(p, 0); |
| 1781 |
} else { |
| 1782 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 1783 |
p->subs[idx].f.subclass.integer = 0; |
| 1784 |
} |
| 1785 |
*dest = &p->subs[idx].f; |
| 1786 |
} else if (p->callwaitcas) { |
| 1787 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 1788 |
if ((f->subclass.integer == 'A') || (f->subclass.integer == 'D')) { |
| 1789 |
ast_debug(1, "Got some DTMF, but it's for the CAS\n"); |
| 1790 |
p->caller.id.name.str = p->callwait_name; |
| 1791 |
p->caller.id.number.str = p->callwait_num; |
| 1792 |
analog_send_callerid(p, 1, &p->caller); |
| 1793 |
} |
| 1794 |
if (analog_handles_digit(f)) { |
| 1795 |
p->callwaitcas = 0; |
| 1796 |
} |
| 1797 |
} |
| 1798 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 1799 |
p->subs[idx].f.subclass.integer = 0; |
| 1800 |
*dest = &p->subs[idx].f; |
| 1801 |
} else if (p->callwaitingdeluxepending) { |
| 1802 |
if (f->frametype == AST_FRAME_DTMF_END) { |
| 1803 |
unsigned int mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime); |
| 1804 |
p->callwaitingdeluxepending = 0; |
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
if (mssinceflash > 990) { |
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
ast_debug(1, "It's been %u ms since the last flash, this is not a Call Waiting Deluxe DTMF\n", mssinceflash); |
| 1824 |
analog_cb_handle_dtmf(p, ast, idx, dest); |
| 1825 |
return; |
| 1826 |
} |
| 1827 |
|
| 1828 |
switch (f->subclass.integer) { |
| 1829 |
case CWD_CONFERENCE: |
| 1830 |
case CWD_HOLD: |
| 1831 |
case CWD_DROP: |
| 1832 |
case CWD_ANNOUNCEMENT: |
| 1833 |
case CWD_FORWARD: |
| 1834 |
ast_debug(1, "Got some DTMF, but it's for Call Waiting Deluxe: %c\n", f->subclass.integer); |
| 1835 |
analog_callwaiting_deluxe(p, f->subclass.integer); |
| 1836 |
break; |
| 1837 |
default: |
| 1838 |
ast_log(LOG_WARNING, "Invalid Call Waiting Deluxe option (%c), using default\n", f->subclass.integer); |
| 1839 |
analog_callwaiting_deluxe(p, 0); |
| 1840 |
} |
| 1841 |
} |
| 1842 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 1843 |
p->subs[idx].f.subclass.integer = 0; |
| 1844 |
*dest = &p->subs[idx].f; |
| 1845 |
} else { |
| 1846 |
analog_cb_handle_dtmf(p, ast, idx, dest); |
| 1847 |
} |
| 1848 |
} |
| 1849 |
|
| 1850 |
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms) |
| 1851 |
{ |
| 1852 |
char c; |
| 1853 |
|
| 1854 |
*str = 0; |
| 1855 |
for (;;) { |
| 1856 |
|
| 1857 |
c = ast_waitfordigit(chan, ms); |
| 1858 |
|
| 1859 |
if (c < 1) { |
| 1860 |
return c; |
| 1861 |
} |
| 1862 |
*str++ = c; |
| 1863 |
*str = 0; |
| 1864 |
if (strchr(term, c)) { |
| 1865 |
return 1; |
| 1866 |
} |
| 1867 |
} |
| 1868 |
} |
| 1869 |
|
| 1870 |
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent) |
| 1871 |
{ |
| 1872 |
if (analog_callbacks.handle_notify_message) { |
| 1873 |
analog_callbacks.handle_notify_message(chan, p->chan_pvt, cid_flags, neon_mwievent); |
| 1874 |
return 0; |
| 1875 |
} |
| 1876 |
return -1; |
| 1877 |
} |
| 1878 |
|
| 1879 |
static void analog_increase_ss_count(void) |
| 1880 |
{ |
| 1881 |
if (analog_callbacks.increase_ss_count) { |
| 1882 |
analog_callbacks.increase_ss_count(); |
| 1883 |
} |
| 1884 |
} |
| 1885 |
|
| 1886 |
static void analog_decrease_ss_count(void) |
| 1887 |
{ |
| 1888 |
if (analog_callbacks.decrease_ss_count) { |
| 1889 |
analog_callbacks.decrease_ss_count(); |
| 1890 |
} |
| 1891 |
} |
| 1892 |
|
| 1893 |
static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata) |
| 1894 |
{ |
| 1895 |
if (!p->usedistinctiveringdetection) { |
| 1896 |
return 0; |
| 1897 |
} |
| 1898 |
if (analog_callbacks.distinctive_ring) { |
| 1899 |
return analog_callbacks.distinctive_ring(chan, p->chan_pvt, idx, ringdata); |
| 1900 |
} |
| 1901 |
return -1; |
| 1902 |
|
| 1903 |
} |
| 1904 |
|
| 1905 |
static void analog_get_and_handle_alarms(struct analog_pvt *p) |
| 1906 |
{ |
| 1907 |
if (analog_callbacks.get_and_handle_alarms) { |
| 1908 |
analog_callbacks.get_and_handle_alarms(p->chan_pvt); |
| 1909 |
} |
| 1910 |
} |
| 1911 |
|
| 1912 |
static void *analog_get_bridged_channel(struct ast_channel *chan) |
| 1913 |
{ |
| 1914 |
if (analog_callbacks.get_sigpvt_bridged_channel) { |
| 1915 |
return analog_callbacks.get_sigpvt_bridged_channel(chan); |
| 1916 |
} |
| 1917 |
return NULL; |
| 1918 |
} |
| 1919 |
|
| 1920 |
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub) |
| 1921 |
{ |
| 1922 |
if (analog_callbacks.get_sub_fd) { |
| 1923 |
return analog_callbacks.get_sub_fd(p->chan_pvt, sub); |
| 1924 |
} |
| 1925 |
return -1; |
| 1926 |
} |
| 1927 |
|
| 1928 |
#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)) |
| 1929 |
|
| 1930 |
static int analog_canmatch_featurecode(const char *pickupexten, const char *exten) |
| 1931 |
{ |
| 1932 |
int extlen = strlen(exten); |
| 1933 |
if (!extlen) { |
| 1934 |
return 1; |
| 1935 |
} |
| 1936 |
if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) { |
| 1937 |
return 1; |
| 1938 |
} |
| 1939 |
if (exten[0] == '#' && extlen < 2) { |
| 1940 |
return 1; |
| 1941 |
} |
| 1942 |
|
| 1943 |
if (exten[0] == '*' && extlen < 3) { |
| 1944 |
if (extlen == 1) { |
| 1945 |
return 1; |
| 1946 |
} |
| 1947 |
|
| 1948 |
switch (exten[1]) { |
| 1949 |
case '6': |
| 1950 |
case '7': |
| 1951 |
case '8': |
| 1952 |
return 1; |
| 1953 |
} |
| 1954 |
} |
| 1955 |
return 0; |
| 1956 |
} |
| 1957 |
|
| 1958 |
static void *__analog_ss_thread(void *data) |
| 1959 |
{ |
| 1960 |
struct analog_pvt *p = data; |
| 1961 |
struct ast_channel *chan = p->ss_astchan; |
| 1962 |
char exten[AST_MAX_EXTENSION] = ""; |
| 1963 |
char exten2[AST_MAX_EXTENSION] = ""; |
| 1964 |
char dtmfcid[300]; |
| 1965 |
char dtmfbuf[300]; |
| 1966 |
char namebuf[ANALOG_MAX_CID]; |
| 1967 |
char numbuf[ANALOG_MAX_CID]; |
| 1968 |
char *name = NULL, *number = NULL; |
| 1969 |
int flags = 0; |
| 1970 |
struct ast_smdi_md_message *smdi_msg = NULL; |
| 1971 |
int timeout; |
| 1972 |
int getforward = 0; |
| 1973 |
char *s1, *s2; |
| 1974 |
int len = 0; |
| 1975 |
int res; |
| 1976 |
int idx; |
| 1977 |
ast_callid callid; |
| 1978 |
RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup); |
| 1979 |
const char *pickupexten; |
| 1980 |
|
| 1981 |
analog_increase_ss_count(); |
| 1982 |
|
| 1983 |
ast_debug(1, "%s %d\n", __FUNCTION__, p->channel); |
| 1984 |
|
| 1985 |
ast_assert(chan != NULL); |
| 1986 |
|
| 1987 |
if ((callid = ast_channel_callid(chan))) { |
| 1988 |
ast_callid_threadassoc_add(callid); |
| 1989 |
} |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
if (!ast_channel_tech_pvt(chan)) { |
| 1995 |
ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan)); |
| 1996 |
ast_hangup(chan); |
| 1997 |
goto quit; |
| 1998 |
} |
| 1999 |
|
| 2000 |
ast_verb(3, "Starting simple switch on '%s'\n", ast_channel_name(chan)); |
| 2001 |
idx = analog_get_index(chan, p, 0); |
| 2002 |
if (idx < 0) { |
| 2003 |
ast_hangup(chan); |
| 2004 |
goto quit; |
| 2005 |
} |
| 2006 |
|
| 2007 |
ast_channel_lock(chan); |
| 2008 |
pickup_cfg = ast_get_chan_features_pickup_config(chan); |
| 2009 |
if (!pickup_cfg) { |
| 2010 |
ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n"); |
| 2011 |
pickupexten = ""; |
| 2012 |
} else { |
| 2013 |
pickupexten = ast_strdupa(pickup_cfg->pickupexten); |
| 2014 |
} |
| 2015 |
ast_channel_unlock(chan); |
| 2016 |
|
| 2017 |
analog_dsp_reset_and_flush_digits(p); |
| 2018 |
switch (p->sig) { |
| 2019 |
case ANALOG_SIG_FEATD: |
| 2020 |
case ANALOG_SIG_FEATDMF: |
| 2021 |
case ANALOG_SIG_FEATDMF_TA: |
| 2022 |
case ANALOG_SIG_E911: |
| 2023 |
case ANALOG_SIG_FGC_CAMAMF: |
| 2024 |
case ANALOG_SIG_FEATB: |
| 2025 |
case ANALOG_SIG_EMWINK: |
| 2026 |
case ANALOG_SIG_SF_FEATD: |
| 2027 |
case ANALOG_SIG_SF_FEATDMF: |
| 2028 |
case ANALOG_SIG_SF_FEATB: |
| 2029 |
case ANALOG_SIG_SFWINK: |
| 2030 |
if (analog_wink(p, idx)) |
| 2031 |
goto quit; |
| 2032 |
|
| 2033 |
case ANALOG_SIG_EM: |
| 2034 |
case ANALOG_SIG_EM_E1: |
| 2035 |
case ANALOG_SIG_SF: |
| 2036 |
case ANALOG_SIG_FGC_CAMA: |
| 2037 |
res = analog_play_tone(p, idx, -1); |
| 2038 |
|
| 2039 |
analog_dsp_reset_and_flush_digits(p); |
| 2040 |
|
| 2041 |
|
| 2042 |
if (ANALOG_NEED_MFDETECT(p)) { |
| 2043 |
analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_MF); |
| 2044 |
} else { |
| 2045 |
analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF); |
| 2046 |
} |
| 2047 |
|
| 2048 |
memset(dtmfbuf, 0, sizeof(dtmfbuf)); |
| 2049 |
|
| 2050 |
if (!p->immediate) { |
| 2051 |
|
| 2052 |
res = ast_waitfordigit(chan, 5000); |
| 2053 |
} else { |
| 2054 |
res = 0; |
| 2055 |
} |
| 2056 |
if (res > 0) { |
| 2057 |
|
| 2058 |
dtmfbuf[0] = res; |
| 2059 |
switch (p->sig) { |
| 2060 |
case ANALOG_SIG_FEATD: |
| 2061 |
case ANALOG_SIG_SF_FEATD: |
| 2062 |
res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000); |
| 2063 |
if (res > 0) { |
| 2064 |
res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000); |
| 2065 |
} |
| 2066 |
if (res < 1) { |
| 2067 |
analog_dsp_reset_and_flush_digits(p); |
| 2068 |
} |
| 2069 |
break; |
| 2070 |
case ANALOG_SIG_FEATDMF_TA: |
| 2071 |
res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000); |
| 2072 |
if (res < 1) { |
| 2073 |
analog_dsp_reset_and_flush_digits(p); |
| 2074 |
} |
| 2075 |
if (analog_wink(p, idx)) { |
| 2076 |
goto quit; |
| 2077 |
} |
| 2078 |
dtmfbuf[0] = 0; |
| 2079 |
|
| 2080 |
res = ast_waitfordigit(chan, 5000); |
| 2081 |
if (res <= 0) { |
| 2082 |
break; |
| 2083 |
} |
| 2084 |
dtmfbuf[0] = res; |
| 2085 |
|
| 2086 |
case ANALOG_SIG_FEATDMF: |
| 2087 |
case ANALOG_SIG_E911: |
| 2088 |
case ANALOG_SIG_FGC_CAMAMF: |
| 2089 |
case ANALOG_SIG_SF_FEATDMF: |
| 2090 |
res = analog_my_getsigstr(chan, dtmfbuf + 1, "#ABC", 3000); |
| 2091 |
|
| 2092 |
if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0') |
| 2093 |
&& (strlen(dtmfbuf) != 14)) { |
| 2094 |
if (analog_wink(p, idx)) { |
| 2095 |
goto quit; |
| 2096 |
} |
| 2097 |
dtmfbuf[0] = 0; |
| 2098 |
|
| 2099 |
res = ast_waitfordigit(chan, 5000); |
| 2100 |
if (res <= 0) { |
| 2101 |
break; |
| 2102 |
} |
| 2103 |
dtmfbuf[0] = res; |
| 2104 |
res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000); |
| 2105 |
} |
| 2106 |
if (res > 0) { |
| 2107 |
|
| 2108 |
if (p->sig == ANALOG_SIG_E911) { |
| 2109 |
analog_off_hook(p); |
| 2110 |
} |
| 2111 |
if (p->sig != ANALOG_SIG_FGC_CAMAMF) { |
| 2112 |
|
| 2113 |
|
| 2114 |
res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000); |
| 2115 |
} |
| 2116 |
} |
| 2117 |
if (res < 1) { |
| 2118 |
analog_dsp_reset_and_flush_digits(p); |
| 2119 |
} |
| 2120 |
break; |
| 2121 |
case ANALOG_SIG_FEATB: |
| 2122 |
case ANALOG_SIG_SF_FEATB: |
| 2123 |
res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000); |
| 2124 |
if (res < 1) { |
| 2125 |
analog_dsp_reset_and_flush_digits(p); |
| 2126 |
} |
| 2127 |
break; |
| 2128 |
case ANALOG_SIG_EMWINK: |
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
if (res == '*') { |
| 2134 |
res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000); |
| 2135 |
if (res > 0) { |
| 2136 |
res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000); |
| 2137 |
} |
| 2138 |
if (res < 1) { |
| 2139 |
analog_dsp_reset_and_flush_digits(p); |
| 2140 |
} |
| 2141 |
break; |
| 2142 |
} |
| 2143 |
default: |
| 2144 |
|
| 2145 |
len = 1; |
| 2146 |
dtmfbuf[len] = '\0'; |
| 2147 |
while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) { |
| 2148 |
if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) { |
| 2149 |
timeout = analog_get_matchdigit_timeout(p); |
| 2150 |
} else { |
| 2151 |
timeout = analog_get_interdigit_timeout(p); |
| 2152 |
} |
| 2153 |
res = ast_waitfordigit(chan, timeout); |
| 2154 |
if (res < 0) { |
| 2155 |
ast_debug(1, "waitfordigit returned < 0...\n"); |
| 2156 |
ast_hangup(chan); |
| 2157 |
goto quit; |
| 2158 |
} else if (res) { |
| 2159 |
dtmfbuf[len++] = res; |
| 2160 |
dtmfbuf[len] = '\0'; |
| 2161 |
} else { |
| 2162 |
break; |
| 2163 |
} |
| 2164 |
} |
| 2165 |
break; |
| 2166 |
} |
| 2167 |
} |
| 2168 |
if (res == -1) { |
| 2169 |
ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno)); |
| 2170 |
ast_hangup(chan); |
| 2171 |
goto quit; |
| 2172 |
} else if (res < 0) { |
| 2173 |
ast_debug(1, "Got hung up before digits finished\n"); |
| 2174 |
ast_hangup(chan); |
| 2175 |
goto quit; |
| 2176 |
} |
| 2177 |
|
| 2178 |
if (p->sig == ANALOG_SIG_FGC_CAMA || p->sig == ANALOG_SIG_FGC_CAMAMF) { |
| 2179 |
|
| 2180 |
|
| 2181 |
char anibuf[100]; |
| 2182 |
struct ast_party_caller *caller; |
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
int cnoffset = p->ani_info_digits + 1; |
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
if (ast_safe_sleep(chan,p->ani_wink_time) == -1) { |
| 2200 |
ast_hangup(chan); |
| 2201 |
goto quit; |
| 2202 |
} |
| 2203 |
analog_off_hook(p); |
| 2204 |
ast_debug(1, "Went off-hook to signal ANI start\n"); |
| 2205 |
analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_MF); |
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
res = analog_my_getsigstr(chan, anibuf, "#ABC", p->ani_timeout); |
| 2210 |
|
| 2211 |
|
| 2212 |
pbx_builtin_setvar_helper(chan, "ANIBUF", anibuf); |
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
if ((res > 0) || (strlen(anibuf) >= 2)) { |
| 2217 |
char anistart[2] = "X"; |
| 2218 |
char f[101] = {0}; |
| 2219 |
if (strchr("#ABC", anibuf[strlen(anibuf) - 1])) { |
| 2220 |
anistart[0] = anibuf[strlen(anibuf) - 1]; |
| 2221 |
anibuf[strlen(anibuf) - 1] = 0; |
| 2222 |
} |
| 2223 |
ast_set_callerid(chan, anibuf + cnoffset, NULL, anibuf + cnoffset); |
| 2224 |
|
| 2225 |
caller = ast_channel_caller(chan); |
| 2226 |
strncpy(f, &(anibuf[1]), MIN((int)(p->ani_info_digits), sizeof(f)-1)); |
| 2227 |
caller->ani2 = atoi(f); |
| 2228 |
|
| 2229 |
anibuf[cnoffset] = 0; |
| 2230 |
|
| 2231 |
|
| 2232 |
pbx_builtin_setvar_helper(chan, "ANISTART", anistart); |
| 2233 |
|
| 2234 |
pbx_builtin_setvar_helper(chan, "ANI2", anibuf + 1); |
| 2235 |
} |
| 2236 |
analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF); |
| 2237 |
} |
| 2238 |
|
| 2239 |
ast_copy_string(exten, dtmfbuf, sizeof(exten)); |
| 2240 |
if (ast_strlen_zero(exten)) { |
| 2241 |
ast_copy_string(exten, "s", sizeof(exten)); |
| 2242 |
} |
| 2243 |
if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) { |
| 2244 |
|
| 2245 |
if (exten[0] == '*') { |
| 2246 |
char *stringp=NULL; |
| 2247 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 2248 |
|
| 2249 |
stringp=exten2 +1; |
| 2250 |
s1 = strsep(&stringp, "*"); |
| 2251 |
s2 = strsep(&stringp, "*"); |
| 2252 |
if (s2) { |
| 2253 |
if (!ast_strlen_zero(p->cid_num)) { |
| 2254 |
ast_set_callerid(chan, p->cid_num, NULL, p->cid_num); |
| 2255 |
} else { |
| 2256 |
ast_set_callerid(chan, s1, NULL, s1); |
| 2257 |
} |
| 2258 |
ast_copy_string(exten, s2, sizeof(exten)); |
| 2259 |
} else { |
| 2260 |
ast_copy_string(exten, s1, sizeof(exten)); |
| 2261 |
} |
| 2262 |
} else if (p->sig == ANALOG_SIG_FEATD) { |
| 2263 |
ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel); |
| 2264 |
} |
| 2265 |
} |
| 2266 |
if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) { |
| 2267 |
if (exten[0] == '*') { |
| 2268 |
char *stringp=NULL; |
| 2269 |
struct ast_party_caller *caller; |
| 2270 |
|
| 2271 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 2272 |
|
| 2273 |
stringp=exten2 +1; |
| 2274 |
s1 = strsep(&stringp, "#"); |
| 2275 |
s2 = strsep(&stringp, "#"); |
| 2276 |
if (s2) { |
| 2277 |
if (!ast_strlen_zero(p->cid_num)) { |
| 2278 |
ast_set_callerid(chan, p->cid_num, NULL, p->cid_num); |
| 2279 |
} else { |
| 2280 |
if (*(s1 + 2)) { |
| 2281 |
ast_set_callerid(chan, s1 + 2, NULL, s1 + 2); |
| 2282 |
} |
| 2283 |
} |
| 2284 |
ast_copy_string(exten, s2 + 1, sizeof(exten)); |
| 2285 |
} else { |
| 2286 |
ast_copy_string(exten, s1 + 2, sizeof(exten)); |
| 2287 |
} |
| 2288 |
|
| 2289 |
|
| 2290 |
caller = ast_channel_caller(chan); |
| 2291 |
s1[2] = '\0'; |
| 2292 |
caller->ani2 = atoi(s1); |
| 2293 |
} else { |
| 2294 |
ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel); |
| 2295 |
} |
| 2296 |
} |
| 2297 |
if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) { |
| 2298 |
if (exten[0] == '*') { |
| 2299 |
char *stringp=NULL; |
| 2300 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 2301 |
|
| 2302 |
stringp=exten2 +1; |
| 2303 |
s1 = strsep(&stringp, "#ABC"); |
| 2304 |
s2 = strsep(&stringp, "#ABC"); |
| 2305 |
if (s2 && (*(s2 + 1) == '0')) { |
| 2306 |
if (*(s2 + 2)) { |
| 2307 |
ast_set_callerid(chan, s2 + 2, NULL, s2 + 2); |
| 2308 |
} |
| 2309 |
} |
| 2310 |
if (s1) { |
| 2311 |
ast_copy_string(exten, s1, sizeof(exten)); |
| 2312 |
} else { |
| 2313 |
ast_copy_string(exten, "911", sizeof(exten)); |
| 2314 |
} |
| 2315 |
} else { |
| 2316 |
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); |
| 2317 |
} |
| 2318 |
} |
| 2319 |
if (p->sig == ANALOG_SIG_FEATB) { |
| 2320 |
if (exten[0] == '*') { |
| 2321 |
char *stringp=NULL; |
| 2322 |
ast_copy_string(exten2, exten, sizeof(exten2)); |
| 2323 |
|
| 2324 |
stringp=exten2 +1; |
| 2325 |
s1 = strsep(&stringp, "#"); |
| 2326 |
ast_copy_string(exten, exten2 + 1, sizeof(exten)); |
| 2327 |
} else { |
| 2328 |
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); |
| 2329 |
} |
| 2330 |
} |
| 2331 |
if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) { |
| 2332 |
analog_wink(p, idx); |
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
if (ast_safe_sleep(chan, 100)) { |
| 2339 |
ast_hangup(chan); |
| 2340 |
goto quit; |
| 2341 |
} |
| 2342 |
} |
| 2343 |
analog_set_echocanceller(p, 1); |
| 2344 |
|
| 2345 |
analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF); |
| 2346 |
|
| 2347 |
if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, |
| 2348 |
ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)) { |
| 2349 |
ast_channel_exten_set(chan, exten); |
| 2350 |
analog_dsp_reset_and_flush_digits(p); |
| 2351 |
res = ast_pbx_run(chan); |
| 2352 |
if (res) { |
| 2353 |
ast_log(LOG_WARNING, "PBX exited non-zero\n"); |
| 2354 |
res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 2355 |
} |
| 2356 |
goto quit; |
| 2357 |
} else { |
| 2358 |
ast_verb(3, "Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan)); |
| 2359 |
sleep(2); |
| 2360 |
res = analog_play_tone(p, idx, ANALOG_TONE_INFO); |
| 2361 |
if (res < 0) { |
| 2362 |
ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel); |
| 2363 |
} else { |
| 2364 |
sleep(1); |
| 2365 |
} |
| 2366 |
res = ast_streamfile(chan, "ss-noservice", ast_channel_language(chan)); |
| 2367 |
if (res >= 0) { |
| 2368 |
ast_waitstream(chan, ""); |
| 2369 |
} |
| 2370 |
res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 2371 |
ast_hangup(chan); |
| 2372 |
goto quit; |
| 2373 |
} |
| 2374 |
break; |
| 2375 |
case ANALOG_SIG_FXOLS: |
| 2376 |
case ANALOG_SIG_FXOGS: |
| 2377 |
case ANALOG_SIG_FXOKS: |
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
p->hidecallerid = p->permhidecallerid; |
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
p->dialmode = p->permdialmode; |
| 2413 |
|
| 2414 |
|
| 2415 |
timeout = analog_get_firstdigit_timeout(p); |
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
if (!p->threewaysilenthold && p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 2420 |
timeout = INT_MAX; |
| 2421 |
} |
| 2422 |
while (len < AST_MAX_EXTENSION-1) { |
| 2423 |
int is_exten_parking = 0; |
| 2424 |
int is_lastnumredial = 0; |
| 2425 |
int is_endofdialing = 0; |
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
if (p->immediate) { |
| 2430 |
res = 's'; |
| 2431 |
} else { |
| 2432 |
res = ast_waitfordigit(chan, timeout); |
| 2433 |
} |
| 2434 |
timeout = 0; |
| 2435 |
if (res < 0) { |
| 2436 |
ast_debug(1, "waitfordigit returned < 0...\n"); |
| 2437 |
res = analog_play_tone(p, idx, -1); |
| 2438 |
ast_hangup(chan); |
| 2439 |
goto quit; |
| 2440 |
} else if (res) { |
| 2441 |
ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout); |
| 2442 |
exten[len++] = res; |
| 2443 |
exten[len] = '\0'; |
| 2444 |
if (len > 1 && res == '#' && !ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) { |
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
exten[--len] = '\0'; |
| 2450 |
if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) { |
| 2451 |
|
| 2452 |
|
| 2453 |
ast_debug(1, "Interpreting '#' as end of dialing\n"); |
| 2454 |
is_endofdialing = 1; |
| 2455 |
} else { |
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
exten[len++] = res; |
| 2460 |
exten[len ] = '\0'; |
| 2461 |
} |
| 2462 |
} |
| 2463 |
} |
| 2464 |
if (!ast_ignore_pattern(ast_channel_context(chan), exten)) { |
| 2465 |
analog_play_tone(p, idx, -1); |
| 2466 |
} else { |
| 2467 |
analog_play_tone(p, idx, ANALOG_TONE_DIALTONE); |
| 2468 |
} |
| 2469 |
if (ast_parking_provider_registered()) { |
| 2470 |
is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten); |
| 2471 |
} |
| 2472 |
if (p->lastnumredial && !strcmp(exten, "##") && !ast_exists_extension(chan, ast_channel_context(chan), "##", 1, p->cid_num)) { |
| 2473 |
|
| 2474 |
if (!ast_strlen_zero(p->lastexten)) { |
| 2475 |
ast_verb(4, "Redialing last number dialed on channel %d\n", p->channel); |
| 2476 |
analog_lock_private(p); |
| 2477 |
ast_copy_string(exten, p->lastexten, sizeof(exten)); |
| 2478 |
analog_unlock_private(p); |
| 2479 |
|
| 2480 |
|
| 2481 |
is_lastnumredial = 1; |
| 2482 |
} else { |
| 2483 |
ast_verb(3, "Last Number Redial not possible on channel %d (no saved number)\n", p->channel); |
| 2484 |
res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 2485 |
analog_wait_event(p); |
| 2486 |
ast_hangup(chan); |
| 2487 |
goto quit; |
| 2488 |
} |
| 2489 |
} |
| 2490 |
if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) { |
| 2491 |
if (!res || is_lastnumredial || is_endofdialing || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) { |
| 2492 |
if (getforward) { |
| 2493 |
|
| 2494 |
analog_lock_private(p); |
| 2495 |
ast_copy_string(p->call_forward, exten, sizeof(p->call_forward)); |
| 2496 |
analog_unlock_private(p); |
| 2497 |
ast_verb(3, "Setting call forward to '%s' on channel %d\n", exten, p->channel); |
| 2498 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2499 |
if (res) { |
| 2500 |
break; |
| 2501 |
} |
| 2502 |
usleep(500000); |
| 2503 |
res = analog_play_tone(p, idx, -1); |
| 2504 |
sleep(1); |
| 2505 |
memset(exten, 0, sizeof(exten)); |
| 2506 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALTONE); |
| 2507 |
len = 0; |
| 2508 |
getforward = 0; |
| 2509 |
} else { |
| 2510 |
res = analog_play_tone(p, idx, -1); |
| 2511 |
ast_channel_lock(chan); |
| 2512 |
ast_channel_exten_set(chan, exten); |
| 2513 |
|
| 2514 |
|
| 2515 |
if (!p->immediate) { |
| 2516 |
ast_copy_string(p->lastexten, exten, sizeof(p->lastexten)); |
| 2517 |
} |
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
if (p->hidecallerid) { |
| 2523 |
ast_channel_caller(chan)->id.number.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; |
| 2524 |
ast_channel_caller(chan)->id.name.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; |
| 2525 |
} else { |
| 2526 |
ast_channel_caller(chan)->id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; |
| 2527 |
ast_channel_caller(chan)->id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; |
| 2528 |
} |
| 2529 |
|
| 2530 |
ast_setstate(chan, AST_STATE_RING); |
| 2531 |
ast_channel_unlock(chan); |
| 2532 |
analog_set_echocanceller(p, 1); |
| 2533 |
res = ast_pbx_run(chan); |
| 2534 |
if (res) { |
| 2535 |
ast_log(LOG_WARNING, "PBX exited non-zero\n"); |
| 2536 |
res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 2537 |
} |
| 2538 |
goto quit; |
| 2539 |
} |
| 2540 |
} else { |
| 2541 |
|
| 2542 |
|
| 2543 |
timeout = analog_get_matchdigit_timeout(p); |
| 2544 |
} |
| 2545 |
} else if (res == 0) { |
| 2546 |
ast_debug(1, "not enough digits (and no ambiguous match)...\n"); |
| 2547 |
if (p->threewaysilenthold) { |
| 2548 |
ast_debug(1, "Nothing dialed at three-way dial tone, timed out to silent hold\n"); |
| 2549 |
} else { |
| 2550 |
res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 2551 |
} |
| 2552 |
analog_wait_event(p); |
| 2553 |
ast_hangup(chan); |
| 2554 |
goto quit; |
| 2555 |
} else if (p->callwaiting && !strcmp(exten, "*70")) { |
| 2556 |
ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan)); |
| 2557 |
|
| 2558 |
analog_set_callwaiting(p, 0); |
| 2559 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2560 |
if (res) { |
| 2561 |
ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", |
| 2562 |
ast_channel_name(chan), strerror(errno)); |
| 2563 |
} |
| 2564 |
len = 0; |
| 2565 |
memset(exten, 0, sizeof(exten)); |
| 2566 |
timeout = analog_get_firstdigit_timeout(p); |
| 2567 |
|
| 2568 |
} else if (!strcmp(exten, pickupexten)) { |
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
if (idx == ANALOG_SUB_REAL) { |
| 2574 |
|
| 2575 |
if (p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 2576 |
|
| 2577 |
|
| 2578 |
analog_alloc_sub(p, ANALOG_SUB_CALLWAIT); |
| 2579 |
analog_swap_subs(p, ANALOG_SUB_CALLWAIT, ANALOG_SUB_THREEWAY); |
| 2580 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 2581 |
} |
| 2582 |
analog_set_echocanceller(p, 1); |
| 2583 |
if (ast_pickup_call(chan)) { |
| 2584 |
ast_debug(1, "No call pickup possible...\n"); |
| 2585 |
res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 2586 |
analog_wait_event(p); |
| 2587 |
} |
| 2588 |
ast_hangup(chan); |
| 2589 |
goto quit; |
| 2590 |
} else { |
| 2591 |
ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n"); |
| 2592 |
ast_hangup(chan); |
| 2593 |
goto quit; |
| 2594 |
} |
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
} else if (!p->hidecallerid && !strcmp(exten, "*67")) { |
| 2599 |
ast_verb(3, "Blocking Caller*ID on %s\n", ast_channel_name(chan)); |
| 2600 |
|
| 2601 |
p->hidecallerid = 1; |
| 2602 |
ast_channel_caller(chan)->id.number.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; |
| 2603 |
ast_channel_caller(chan)->id.name.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; |
| 2604 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2605 |
if (res) { |
| 2606 |
ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", |
| 2607 |
ast_channel_name(chan), strerror(errno)); |
| 2608 |
} |
| 2609 |
len = 0; |
| 2610 |
memset(exten, 0, sizeof(exten)); |
| 2611 |
timeout = analog_get_firstdigit_timeout(p); |
| 2612 |
} else if (p->callreturn && !strcmp(exten, "*69")) { |
| 2613 |
res = 0; |
| 2614 |
if (!ast_strlen_zero(p->lastcid_num)) { |
| 2615 |
res = ast_say_digit_str(chan, p->lastcid_num, "", ast_channel_language(chan)); |
| 2616 |
} |
| 2617 |
if (!res) { |
| 2618 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2619 |
} |
| 2620 |
break; |
| 2621 |
} else if (!strcmp(exten, "*78")) { |
| 2622 |
|
| 2623 |
analog_dnd(p, 1); |
| 2624 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2625 |
getforward = 0; |
| 2626 |
memset(exten, 0, sizeof(exten)); |
| 2627 |
len = 0; |
| 2628 |
} else if (!strcmp(exten, "*79")) { |
| 2629 |
|
| 2630 |
analog_dnd(p, 0); |
| 2631 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2632 |
getforward = 0; |
| 2633 |
memset(exten, 0, sizeof(exten)); |
| 2634 |
len = 0; |
| 2635 |
} else if (p->cancallforward && !strcmp(exten, "*72")) { |
| 2636 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2637 |
getforward = 1; |
| 2638 |
memset(exten, 0, sizeof(exten)); |
| 2639 |
len = 0; |
| 2640 |
} else if (p->cancallforward && !strcmp(exten, "*73")) { |
| 2641 |
ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel); |
| 2642 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2643 |
memset(p->call_forward, 0, sizeof(p->call_forward)); |
| 2644 |
getforward = 0; |
| 2645 |
memset(exten, 0, sizeof(exten)); |
| 2646 |
len = 0; |
| 2647 |
} else if ((p->transfer || p->canpark) && is_exten_parking |
| 2648 |
&& p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 2649 |
struct ast_bridge_channel *bridge_channel; |
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
ast_channel_lock(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 2656 |
bridge_channel = ast_channel_get_bridge_channel(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 2657 |
ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 2658 |
if (bridge_channel) { |
| 2659 |
if (!ast_parking_blind_transfer_park(bridge_channel, ast_channel_context(chan), exten, NULL, NULL)) { |
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
analog_lock_private(p); |
| 2665 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_THREEWAY].owner); |
| 2666 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 2667 |
analog_unlock_private(p); |
| 2668 |
|
| 2669 |
ast_verb(3, "%s: Parked call\n", ast_channel_name(chan)); |
| 2670 |
ast_hangup(chan); |
| 2671 |
ao2_ref(bridge_channel, -1); |
| 2672 |
goto quit; |
| 2673 |
} |
| 2674 |
ao2_ref(bridge_channel, -1); |
| 2675 |
} |
| 2676 |
break; |
| 2677 |
} else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) { |
| 2678 |
ast_verb(3, "Blacklisting number %s\n", p->lastcid_num); |
| 2679 |
res = ast_db_put("blacklist", p->lastcid_num, "1"); |
| 2680 |
if (!res) { |
| 2681 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2682 |
memset(exten, 0, sizeof(exten)); |
| 2683 |
len = 0; |
| 2684 |
} |
| 2685 |
} else if (p->hidecallerid && !strcmp(exten, "*82")) { |
| 2686 |
ast_verb(3, "Allowing Caller*ID on %s\n", ast_channel_name(chan)); |
| 2687 |
|
| 2688 |
p->hidecallerid = 0; |
| 2689 |
ast_channel_caller(chan)->id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; |
| 2690 |
ast_channel_caller(chan)->id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; |
| 2691 |
res = analog_play_tone(p, idx, ANALOG_TONE_DIALRECALL); |
| 2692 |
if (res) { |
| 2693 |
ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", |
| 2694 |
ast_channel_name(chan), strerror(errno)); |
| 2695 |
} |
| 2696 |
len = 0; |
| 2697 |
memset(exten, 0, sizeof(exten)); |
| 2698 |
timeout = analog_get_firstdigit_timeout(p); |
| 2699 |
} else if (!strcmp(exten, "*0")) { |
| 2700 |
struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner; |
| 2701 |
struct analog_pvt *pbridge = NULL; |
| 2702 |
|
| 2703 |
if (nbridge) { |
| 2704 |
pbridge = analog_get_bridged_channel(nbridge); |
| 2705 |
} |
| 2706 |
if (pbridge && ISTRUNK(pbridge)) { |
| 2707 |
|
| 2708 |
p->dop.dialstr[0] = '\0'; |
| 2709 |
|
| 2710 |
if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) { |
| 2711 |
ast_log(LOG_WARNING, |
| 2712 |
"Unable to flash-hook bridged trunk from channel %s: %s\n", |
| 2713 |
ast_channel_name(nbridge), strerror(errno)); |
| 2714 |
} |
| 2715 |
analog_swap_subs(p, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY); |
| 2716 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 2717 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 2718 |
ast_queue_unhold(p->subs[ANALOG_SUB_REAL].owner); |
| 2719 |
ast_hangup(chan); |
| 2720 |
goto quit; |
| 2721 |
} else { |
| 2722 |
analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 2723 |
analog_wait_event(p); |
| 2724 |
analog_play_tone(p, idx, -1); |
| 2725 |
analog_swap_subs(p, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY); |
| 2726 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 2727 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 2728 |
ast_hangup(chan); |
| 2729 |
goto quit; |
| 2730 |
} |
| 2731 |
} else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1, |
| 2732 |
ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL) |
| 2733 |
&& !analog_canmatch_featurecode(pickupexten, exten)) { |
| 2734 |
ast_debug(1, "Can't match %s from '%s' in context %s\n", exten, |
| 2735 |
ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str |
| 2736 |
? ast_channel_caller(chan)->id.number.str : "<Unknown Caller>", |
| 2737 |
ast_channel_context(chan)); |
| 2738 |
break; |
| 2739 |
} |
| 2740 |
if (!timeout) { |
| 2741 |
timeout = analog_get_interdigit_timeout(p); |
| 2742 |
} |
| 2743 |
if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) { |
| 2744 |
analog_play_tone(p, idx, -1); |
| 2745 |
} |
| 2746 |
} |
| 2747 |
break; |
| 2748 |
case ANALOG_SIG_FXSLS: |
| 2749 |
case ANALOG_SIG_FXSGS: |
| 2750 |
case ANALOG_SIG_FXSKS: |
| 2751 |
|
| 2752 |
if (p->use_smdi && p->smdi_iface) { |
| 2753 |
smdi_msg = ast_smdi_md_message_wait(p->smdi_iface, ANALOG_SMDI_MD_WAIT_TIMEOUT); |
| 2754 |
if (smdi_msg != NULL) { |
| 2755 |
ast_channel_exten_set(chan, smdi_msg->fwd_st); |
| 2756 |
|
| 2757 |
if (smdi_msg->type == 'B') |
| 2758 |
pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b"); |
| 2759 |
else if (smdi_msg->type == 'N') |
| 2760 |
pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u"); |
| 2761 |
|
| 2762 |
ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan)); |
| 2763 |
} else { |
| 2764 |
ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n"); |
| 2765 |
} |
| 2766 |
} |
| 2767 |
|
| 2768 |
if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) { |
| 2769 |
number = smdi_msg->calling_st; |
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
} else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING |
| 2775 |
&& (p->cid_start == ANALOG_CID_START_POLARITY |
| 2776 |
|| p->cid_start == ANALOG_CID_START_POLARITY_IN |
| 2777 |
|| p->cid_start == ANALOG_CID_START_DTMF_NOALERT))) { |
| 2778 |
|
| 2779 |
if (p->cid_signalling == CID_SIG_DTMF) { |
| 2780 |
int k = 0; |
| 2781 |
int oldlinearity; |
| 2782 |
int timeout_ms; |
| 2783 |
int ms; |
| 2784 |
struct timeval start = ast_tvnow(); |
| 2785 |
ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan)); |
| 2786 |
|
| 2787 |
oldlinearity = analog_set_linear_mode(p, idx, 0); |
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
ast_channel_lock(chan); |
| 2796 |
ast_set_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY); |
| 2797 |
ast_channel_unlock(chan); |
| 2798 |
timeout_ms = 4000; |
| 2799 |
for (;;) { |
| 2800 |
struct ast_frame *f; |
| 2801 |
|
| 2802 |
ms = ast_remaining_ms(start, timeout_ms); |
| 2803 |
res = ast_waitfor(chan, ms); |
| 2804 |
if (res <= 0) { |
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
ast_log(LOG_WARNING, |
| 2811 |
"DTMFCID timed out waiting for ring. Exiting simple switch\n"); |
| 2812 |
ast_hangup(chan); |
| 2813 |
goto quit; |
| 2814 |
} |
| 2815 |
f = ast_read(chan); |
| 2816 |
if (!f) { |
| 2817 |
break; |
| 2818 |
} |
| 2819 |
if (f->frametype == AST_FRAME_DTMF) { |
| 2820 |
if (k < ARRAY_LEN(dtmfbuf) - 1) { |
| 2821 |
dtmfbuf[k++] = f->subclass.integer; |
| 2822 |
} |
| 2823 |
ast_debug(1, "CID got digit '%c'\n", f->subclass.integer); |
| 2824 |
start = ast_tvnow(); |
| 2825 |
} |
| 2826 |
ast_frfree(f); |
| 2827 |
if (ast_channel_state(chan) == AST_STATE_RING || |
| 2828 |
ast_channel_state(chan) == AST_STATE_RINGING) { |
| 2829 |
break; |
| 2830 |
} |
| 2831 |
} |
| 2832 |
ast_channel_lock(chan); |
| 2833 |
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY); |
| 2834 |
ast_channel_unlock(chan); |
| 2835 |
dtmfbuf[k] = '\0'; |
| 2836 |
|
| 2837 |
analog_set_linear_mode(p, idx, oldlinearity); |
| 2838 |
|
| 2839 |
|
| 2840 |
ast_debug(1, "CID got string '%s'\n", dtmfbuf); |
| 2841 |
callerid_get_dtmf(dtmfbuf, dtmfcid, &flags); |
| 2842 |
ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags); |
| 2843 |
|
| 2844 |
if (!ast_strlen_zero(dtmfcid)) { |
| 2845 |
number = dtmfcid; |
| 2846 |
} else { |
| 2847 |
number = NULL; |
| 2848 |
} |
| 2849 |
|
| 2850 |
|
| 2851 |
} else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) { |
| 2852 |
namebuf[0] = 0; |
| 2853 |
numbuf[0] = 0; |
| 2854 |
|
| 2855 |
if (!analog_start_cid_detect(p, p->cid_signalling)) { |
| 2856 |
int timeout = 10000; |
| 2857 |
struct timeval start = ast_tvnow(); |
| 2858 |
enum analog_event ev; |
| 2859 |
int off_ms; |
| 2860 |
int ms; |
| 2861 |
struct timeval off_start; |
| 2862 |
|
| 2863 |
if (!p->usedistinctiveringdetection) { |
| 2864 |
|
| 2865 |
analog_set_ringtimeout(p, 0); |
| 2866 |
} |
| 2867 |
while ((ms = ast_remaining_ms(start, timeout))) { |
| 2868 |
res = analog_get_callerid(p, namebuf, numbuf, &ev, ms); |
| 2869 |
if (res < 0) { |
| 2870 |
ast_log(LOG_WARNING, |
| 2871 |
"CallerID returned with error on channel '%s'\n", |
| 2872 |
ast_channel_name(chan)); |
| 2873 |
break; |
| 2874 |
} |
| 2875 |
if (res == 0) { |
| 2876 |
break; |
| 2877 |
} |
| 2878 |
if (res != 1) { |
| 2879 |
continue; |
| 2880 |
} |
| 2881 |
if (ev == ANALOG_EVENT_NOALARM) { |
| 2882 |
analog_set_alarm(p, 0); |
| 2883 |
} |
| 2884 |
if (p->cid_signalling == CID_SIG_V23_JP) { |
| 2885 |
if (ev == ANALOG_EVENT_RINGBEGIN) { |
| 2886 |
analog_off_hook(p); |
| 2887 |
usleep(1); |
| 2888 |
} |
| 2889 |
} else { |
| 2890 |
break; |
| 2891 |
} |
| 2892 |
} |
| 2893 |
|
| 2894 |
name = namebuf; |
| 2895 |
number = numbuf; |
| 2896 |
|
| 2897 |
if (p->cid_signalling == CID_SIG_V23_JP) { |
| 2898 |
analog_on_hook(p); |
| 2899 |
usleep(1); |
| 2900 |
} |
| 2901 |
|
| 2902 |
|
| 2903 |
off_start = ast_tvnow(); |
| 2904 |
off_ms = 4000; |
| 2905 |
while ((ms = ast_remaining_ms(off_start, off_ms))) { |
| 2906 |
struct ast_frame *f; |
| 2907 |
|
| 2908 |
res = ast_waitfor(chan, ms); |
| 2909 |
if (res <= 0) { |
| 2910 |
ast_log(LOG_WARNING, |
| 2911 |
"CID timed out waiting for ring. Exiting simple switch\n"); |
| 2912 |
analog_stop_cid_detect(p); |
| 2913 |
ast_hangup(chan); |
| 2914 |
goto quit; |
| 2915 |
} |
| 2916 |
if (!(f = ast_read(chan))) { |
| 2917 |
ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n"); |
| 2918 |
analog_stop_cid_detect(p); |
| 2919 |
ast_hangup(chan); |
| 2920 |
goto quit; |
| 2921 |
} |
| 2922 |
ast_frfree(f); |
| 2923 |
if (ast_channel_state(chan) == AST_STATE_RING || |
| 2924 |
ast_channel_state(chan) == AST_STATE_RINGING) |
| 2925 |
break; |
| 2926 |
} |
| 2927 |
|
| 2928 |
res = analog_distinctive_ring(chan, p, idx, NULL); |
| 2929 |
analog_stop_cid_detect(p); |
| 2930 |
if (res) { |
| 2931 |
goto quit; |
| 2932 |
} |
| 2933 |
} else { |
| 2934 |
ast_log(LOG_WARNING, "Unable to get caller ID space\n"); |
| 2935 |
} |
| 2936 |
} else { |
| 2937 |
ast_log(LOG_WARNING, |
| 2938 |
"Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n", |
| 2939 |
ast_channel_name(chan)); |
| 2940 |
ast_hangup(chan); |
| 2941 |
goto quit; |
| 2942 |
} |
| 2943 |
} else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) { |
| 2944 |
namebuf[0] = 0; |
| 2945 |
numbuf[0] = 0; |
| 2946 |
|
| 2947 |
if (!analog_start_cid_detect(p, p->cid_signalling)) { |
| 2948 |
int timeout = 10000; |
| 2949 |
struct timeval start = ast_tvnow(); |
| 2950 |
enum analog_event ev; |
| 2951 |
int ring_data[RING_PATTERNS] = { 0 }; |
| 2952 |
int ring_data_idx = 0; |
| 2953 |
int ms; |
| 2954 |
|
| 2955 |
if (!p->usedistinctiveringdetection) { |
| 2956 |
|
| 2957 |
analog_set_ringtimeout(p, 0); |
| 2958 |
} |
| 2959 |
while ((ms = ast_remaining_ms(start, timeout))) { |
| 2960 |
res = analog_get_callerid(p, namebuf, numbuf, &ev, ms); |
| 2961 |
if (res < 0) { |
| 2962 |
ast_log(LOG_WARNING, |
| 2963 |
"CallerID returned with error on channel '%s'\n", |
| 2964 |
ast_channel_name(chan)); |
| 2965 |
break; |
| 2966 |
} |
| 2967 |
if (res == 0) { |
| 2968 |
break; |
| 2969 |
} |
| 2970 |
if (res != 1) { |
| 2971 |
continue; |
| 2972 |
} |
| 2973 |
if (ev == ANALOG_EVENT_NOALARM) { |
| 2974 |
analog_set_alarm(p, 0); |
| 2975 |
} else if (ev == ANALOG_EVENT_POLARITY |
| 2976 |
&& p->hanguponpolarityswitch |
| 2977 |
&& p->polarity == POLARITY_REV) { |
| 2978 |
ast_debug(1, |
| 2979 |
"Hanging up due to polarity reversal on channel %d while detecting callerid\n", |
| 2980 |
p->channel); |
| 2981 |
p->polarity = POLARITY_IDLE; |
| 2982 |
analog_stop_cid_detect(p); |
| 2983 |
ast_hangup(chan); |
| 2984 |
goto quit; |
| 2985 |
} else if (ev == ANALOG_EVENT_RINGOFFHOOK |
| 2986 |
&& p->usedistinctiveringdetection |
| 2987 |
&& ring_data_idx < RING_PATTERNS) { |
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
ring_data[ring_data_idx] = p->ringt; |
| 2993 |
++ring_data_idx; |
| 2994 |
} |
| 2995 |
} |
| 2996 |
|
| 2997 |
name = namebuf; |
| 2998 |
number = numbuf; |
| 2999 |
|
| 3000 |
res = analog_distinctive_ring(chan, p, idx, ring_data); |
| 3001 |
analog_stop_cid_detect(p); |
| 3002 |
if (res) { |
| 3003 |
goto quit; |
| 3004 |
} |
| 3005 |
} else { |
| 3006 |
ast_log(LOG_WARNING, "Unable to get caller ID space\n"); |
| 3007 |
} |
| 3008 |
} |
| 3009 |
|
| 3010 |
if (number) { |
| 3011 |
ast_shrink_phone_number(number); |
| 3012 |
} |
| 3013 |
ast_set_callerid(chan, number, name, number); |
| 3014 |
|
| 3015 |
analog_handle_notify_message(chan, p, flags, -1); |
| 3016 |
|
| 3017 |
ast_channel_lock(chan); |
| 3018 |
ast_setstate(chan, AST_STATE_RING); |
| 3019 |
ast_channel_rings_set(chan, 1); |
| 3020 |
ast_channel_unlock(chan); |
| 3021 |
analog_set_ringtimeout(p, p->ringt_base); |
| 3022 |
res = ast_pbx_run(chan); |
| 3023 |
if (res) { |
| 3024 |
ast_hangup(chan); |
| 3025 |
ast_log(LOG_WARNING, "PBX exited non-zero\n"); |
| 3026 |
} |
| 3027 |
goto quit; |
| 3028 |
default: |
| 3029 |
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); |
| 3030 |
break; |
| 3031 |
} |
| 3032 |
res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); |
| 3033 |
if (res < 0) { |
| 3034 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel); |
| 3035 |
} |
| 3036 |
ast_hangup(chan); |
| 3037 |
quit: |
| 3038 |
ao2_cleanup(smdi_msg); |
| 3039 |
analog_decrease_ss_count(); |
| 3040 |
return NULL; |
| 3041 |
} |
| 3042 |
|
| 3043 |
int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *chan) |
| 3044 |
{ |
| 3045 |
pthread_t threadid; |
| 3046 |
|
| 3047 |
p->ss_astchan = chan; |
| 3048 |
return ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p); |
| 3049 |
} |
| 3050 |
|
| 3051 |
static void analog_publish_channel_alarm_clear(int channel) |
| 3052 |
{ |
| 3053 |
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); |
| 3054 |
|
| 3055 |
ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel); |
| 3056 |
body = ast_json_pack("{s: i}", "Channel", channel); |
| 3057 |
if (!body) { |
| 3058 |
return; |
| 3059 |
} |
| 3060 |
|
| 3061 |
ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body); |
| 3062 |
} |
| 3063 |
|
| 3064 |
static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast) |
| 3065 |
{ |
| 3066 |
int res, x; |
| 3067 |
int mysig; |
| 3068 |
int idx; |
| 3069 |
char *c; |
| 3070 |
pthread_t threadid; |
| 3071 |
struct ast_channel *chan; |
| 3072 |
struct ast_frame *f; |
| 3073 |
struct ast_control_pvt_cause_code *cause_code = NULL; |
| 3074 |
int data_size = sizeof(*cause_code); |
| 3075 |
char *subclass = NULL; |
| 3076 |
|
| 3077 |
ast_debug(1, "%s %d\n", __FUNCTION__, p->channel); |
| 3078 |
|
| 3079 |
idx = analog_get_index(ast, p, 0); |
| 3080 |
if (idx < 0) { |
| 3081 |
return &ast_null_frame; |
| 3082 |
} |
| 3083 |
if (idx != ANALOG_SUB_REAL) { |
| 3084 |
ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n"); |
| 3085 |
} |
| 3086 |
|
| 3087 |
mysig = p->sig; |
| 3088 |
if (p->outsigmod > -1) { |
| 3089 |
mysig = p->outsigmod; |
| 3090 |
} |
| 3091 |
|
| 3092 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 3093 |
p->subs[idx].f.subclass.integer = 0; |
| 3094 |
p->subs[idx].f.datalen = 0; |
| 3095 |
p->subs[idx].f.samples = 0; |
| 3096 |
p->subs[idx].f.mallocd = 0; |
| 3097 |
p->subs[idx].f.offset = 0; |
| 3098 |
p->subs[idx].f.src = "dahdi_handle_event"; |
| 3099 |
p->subs[idx].f.data.ptr = NULL; |
| 3100 |
f = &p->subs[idx].f; |
| 3101 |
|
| 3102 |
res = analog_get_event(p); |
| 3103 |
|
| 3104 |
ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx); |
| 3105 |
|
| 3106 |
if (res & (ANALOG_EVENT_PULSEDIGIT | ANALOG_EVENT_DTMFUP)) { |
| 3107 |
analog_set_pulsedial(p, (res & ANALOG_EVENT_PULSEDIGIT) ? 1 : 0); |
| 3108 |
ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff); |
| 3109 |
analog_confmute(p, 0); |
| 3110 |
if (p->dialmode == ANALOG_DIALMODE_BOTH || p->dialmode == ANALOG_DIALMODE_PULSE) { |
| 3111 |
p->subs[idx].f.frametype = AST_FRAME_DTMF_END; |
| 3112 |
p->subs[idx].f.subclass.integer = res & 0xff; |
| 3113 |
analog_handle_dtmf(p, ast, idx, &f); |
| 3114 |
} else { |
| 3115 |
ast_debug(1, "Dropping pulse digit '%c' because pulse dialing disabled on channel %d\n", res & 0xff, p->channel); |
| 3116 |
} |
| 3117 |
return f; |
| 3118 |
} |
| 3119 |
|
| 3120 |
if (res & ANALOG_EVENT_DTMFDOWN) { |
| 3121 |
ast_debug(1, "DTMF Down '%c'\n", res & 0xff); |
| 3122 |
|
| 3123 |
analog_confmute(p, 1); |
| 3124 |
p->subs[idx].f.frametype = AST_FRAME_DTMF_BEGIN; |
| 3125 |
p->subs[idx].f.subclass.integer = res & 0xff; |
| 3126 |
analog_handle_dtmf(p, ast, idx, &f); |
| 3127 |
return f; |
| 3128 |
} |
| 3129 |
|
| 3130 |
switch (res) { |
| 3131 |
case ANALOG_EVENT_ALARM: |
| 3132 |
case ANALOG_EVENT_POLARITY: |
| 3133 |
case ANALOG_EVENT_ONHOOK: |
| 3134 |
|
| 3135 |
data_size += 7; |
| 3136 |
subclass = analog_event2str(res); |
| 3137 |
data_size += strlen(subclass); |
| 3138 |
cause_code = ast_alloca(data_size); |
| 3139 |
memset(cause_code, 0, data_size); |
| 3140 |
cause_code->ast_cause = AST_CAUSE_NORMAL_CLEARING; |
| 3141 |
ast_copy_string(cause_code->chan_name, ast_channel_name(ast), AST_CHANNEL_NAME); |
| 3142 |
snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass); |
| 3143 |
break; |
| 3144 |
default: |
| 3145 |
break; |
| 3146 |
} |
| 3147 |
|
| 3148 |
switch (res) { |
| 3149 |
case ANALOG_EVENT_EC_DISABLED: |
| 3150 |
ast_verb(3, "Channel %d echo canceller disabled due to CED detection\n", p->channel); |
| 3151 |
analog_set_echocanceller(p, 0); |
| 3152 |
break; |
| 3153 |
#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE |
| 3154 |
case ANALOG_EVENT_TX_CED_DETECTED: |
| 3155 |
ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel); |
| 3156 |
break; |
| 3157 |
case ANALOG_EVENT_RX_CED_DETECTED: |
| 3158 |
ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel); |
| 3159 |
break; |
| 3160 |
case ANALOG_EVENT_EC_NLP_DISABLED: |
| 3161 |
ast_verb(3, "Channel %d echo canceller disabled its NLP.\n", p->channel); |
| 3162 |
break; |
| 3163 |
case ANALOG_EVENT_EC_NLP_ENABLED: |
| 3164 |
ast_verb(3, "Channel %d echo canceller enabled its NLP.\n", p->channel); |
| 3165 |
break; |
| 3166 |
#endif |
| 3167 |
case ANALOG_EVENT_PULSE_START: |
| 3168 |
|
| 3169 |
if (!ast_channel_pbx(ast)) |
| 3170 |
analog_play_tone(p, ANALOG_SUB_REAL, -1); |
| 3171 |
break; |
| 3172 |
case ANALOG_EVENT_DIALCOMPLETE: |
| 3173 |
if (p->inalarm) { |
| 3174 |
break; |
| 3175 |
} |
| 3176 |
x = analog_is_dialing(p, idx); |
| 3177 |
if (!x) { |
| 3178 |
analog_set_echocanceller(p, 1); |
| 3179 |
if (p->echobreak) { |
| 3180 |
analog_train_echocanceller(p); |
| 3181 |
ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr)); |
| 3182 |
p->dop.op = ANALOG_DIAL_OP_REPLACE; |
| 3183 |
analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop); |
| 3184 |
p->echobreak = 0; |
| 3185 |
} else { |
| 3186 |
analog_set_dialing(p, 0); |
| 3187 |
if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) { |
| 3188 |
|
| 3189 |
if (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK) { |
| 3190 |
ast_setstate(ast, AST_STATE_UP); |
| 3191 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 3192 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 3193 |
break; |
| 3194 |
} else { |
| 3195 |
|
| 3196 |
ast_setstate(ast,AST_STATE_DIALING_OFFHOOK); |
| 3197 |
} |
| 3198 |
} |
| 3199 |
if (ast_channel_state(ast) == AST_STATE_DIALING) { |
| 3200 |
if (analog_have_progressdetect(p)) { |
| 3201 |
ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n"); |
| 3202 |
} else if (analog_check_confirmanswer(p) || (!p->dialednone |
| 3203 |
&& ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1) |
| 3204 |
|| (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD) |
| 3205 |
|| (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF) |
| 3206 |
|| (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) |
| 3207 |
|| (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB) |
| 3208 |
|| (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK) |
| 3209 |
|| (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF) |
| 3210 |
|| (mysig == ANALOG_SIG_SF_FEATB)))) { |
| 3211 |
ast_setstate(ast, AST_STATE_RINGING); |
| 3212 |
} else if (!p->answeronpolarityswitch) { |
| 3213 |
ast_setstate(ast, AST_STATE_UP); |
| 3214 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 3215 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 3216 |
|
| 3217 |
p->polarity = POLARITY_REV; |
| 3218 |
} else { |
| 3219 |
|
| 3220 |
p->polarity = POLARITY_IDLE; |
| 3221 |
} |
| 3222 |
} |
| 3223 |
} |
| 3224 |
} |
| 3225 |
break; |
| 3226 |
case ANALOG_EVENT_ALARM: |
| 3227 |
analog_set_alarm(p, 1); |
| 3228 |
analog_get_and_handle_alarms(p); |
| 3229 |
cause_code->ast_cause = AST_CAUSE_NETWORK_OUT_OF_ORDER; |
| 3230 |
case ANALOG_EVENT_ONHOOK: |
| 3231 |
if (p->calledsubscriberheld && (p->sig == ANALOG_SIG_FXOLS || p->sig == ANALOG_SIG_FXOGS || p->sig == ANALOG_SIG_FXOKS) && idx == ANALOG_SUB_REAL) { |
| 3232 |
ast_debug(4, "Channel state on %s is %d\n", ast_channel_name(ast), ast_channel_state(ast)); |
| 3233 |
|
| 3234 |
if (p->subs[ANALOG_SUB_CALLWAIT].owner || p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 3235 |
ast_debug(2, "Letting this call hang up normally, since it's not the only call\n"); |
| 3236 |
} else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || ast_channel_state(ast) != AST_STATE_UP) { |
| 3237 |
ast_debug(2, "Called Subscriber Held does not apply: channel state is %d\n", ast_channel_state(ast)); |
| 3238 |
} else if (p->owner && p->subs[ANALOG_SUB_REAL].owner && ast_strlen_zero(ast_channel_appl(p->subs[ANALOG_SUB_REAL].owner))) { |
| 3239 |
|
| 3240 |
|
| 3241 |
ast_debug(1, "Skipping Called Subscriber Held; channel has no application\n"); |
| 3242 |
} else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || strcmp(ast_channel_appl(p->subs[ANALOG_SUB_REAL].owner), "AppDial")) { |
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
ast_debug(2, "Called Subscriber Held does not apply: not an incoming call\n"); |
| 3252 |
} else if (analog_is_off_hook(p)) { |
| 3253 |
ast_log(LOG_WARNING, "Got ONHOOK but channel %d is off hook?\n", p->channel); |
| 3254 |
} else { |
| 3255 |
ast_verb(3, "Holding incoming call %s for channel %d\n", ast_channel_name(ast), p->channel); |
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
p->cshactive = 1; |
| 3260 |
break; |
| 3261 |
} |
| 3262 |
} |
| 3263 |
p->callwaitingdeluxepending = 0; |
| 3264 |
ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size); |
| 3265 |
ast_channel_hangupcause_hash_set(ast, cause_code, data_size); |
| 3266 |
switch (p->sig) { |
| 3267 |
case ANALOG_SIG_FXOLS: |
| 3268 |
case ANALOG_SIG_FXOGS: |
| 3269 |
case ANALOG_SIG_FXOKS: |
| 3270 |
analog_start_polarityswitch(p); |
| 3271 |
p->fxsoffhookstate = 0; |
| 3272 |
p->onhooktime = time(NULL); |
| 3273 |
p->msgstate = -1; |
| 3274 |
|
| 3275 |
if (idx == ANALOG_SUB_REAL) { |
| 3276 |
|
| 3277 |
if (p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 3278 |
|
| 3279 |
analog_lock_sub_owner(p, ANALOG_SUB_CALLWAIT); |
| 3280 |
if (!p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
analog_set_echocanceller(p, 0); |
| 3286 |
return NULL; |
| 3287 |
} |
| 3288 |
|
| 3289 |
|
| 3290 |
analog_swap_subs(p, ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL); |
| 3291 |
ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel); |
| 3292 |
analog_unalloc_sub(p, ANALOG_SUB_CALLWAIT); |
| 3293 |
analog_stop_callwait(p); |
| 3294 |
analog_set_new_owner(p, NULL); |
| 3295 |
|
| 3296 |
if (ast_channel_state(p->subs[ANALOG_SUB_REAL].owner) != AST_STATE_UP) { |
| 3297 |
analog_set_dialing(p, 1); |
| 3298 |
} |
| 3299 |
|
| 3300 |
ast_channel_unlock(p->subs[ANALOG_SUB_REAL].owner); |
| 3301 |
analog_ring(p); |
| 3302 |
} else if (p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 3303 |
unsigned int mssinceflash; |
| 3304 |
|
| 3305 |
|
| 3306 |
analog_lock_sub_owner(p, ANALOG_SUB_THREEWAY); |
| 3307 |
if (!p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 3308 |
ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n"); |
| 3309 |
|
| 3310 |
return NULL; |
| 3311 |
} |
| 3312 |
if (p->owner != ast) { |
| 3313 |
ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 3314 |
ast_log(LOG_WARNING, "This isn't good...\n"); |
| 3315 |
|
| 3316 |
return NULL; |
| 3317 |
} |
| 3318 |
|
| 3319 |
mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime); |
| 3320 |
ast_debug(1, "Last flash was %u ms ago\n", mssinceflash); |
| 3321 |
if (mssinceflash < MIN_MS_SINCE_FLASH) { |
| 3322 |
|
| 3323 |
|
| 3324 |
ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel); |
| 3325 |
ast_queue_hangup_with_cause(p->subs[ANALOG_SUB_THREEWAY].owner, AST_CAUSE_NO_ANSWER); |
| 3326 |
ast_softhangup_nolock(p->subs[ANALOG_SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 3327 |
ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 3328 |
} else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) { |
| 3329 |
if (p->transfer) { |
| 3330 |
|
| 3331 |
analog_set_inthreeway(p, ANALOG_SUB_REAL, 0); |
| 3332 |
analog_set_inthreeway(p, ANALOG_SUB_THREEWAY, 0); |
| 3333 |
|
| 3334 |
|
| 3335 |
if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) { |
| 3336 |
|
| 3337 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 3338 |
|
| 3339 |
ast_channel_unlock(p->subs[ANALOG_SUB_REAL].owner); |
| 3340 |
analog_set_new_owner(p, NULL); |
| 3341 |
|
| 3342 |
analog_ring(p); |
| 3343 |
} else if (!analog_attempt_transfer(p)) { |
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
break; |
| 3350 |
} |
| 3351 |
} else { |
| 3352 |
ast_softhangup_nolock(p->subs[ANALOG_SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 3353 |
ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); |
| 3354 |
} |
| 3355 |
} else { |
| 3356 |
|
| 3357 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 3358 |
|
| 3359 |
ast_channel_unlock(p->subs[ANALOG_SUB_REAL].owner); |
| 3360 |
analog_set_new_owner(p, NULL); |
| 3361 |
|
| 3362 |
analog_ring(p); |
| 3363 |
} |
| 3364 |
} |
| 3365 |
} else { |
| 3366 |
ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx); |
| 3367 |
} |
| 3368 |
|
| 3369 |
default: |
| 3370 |
analog_set_echocanceller(p, 0); |
| 3371 |
return NULL; |
| 3372 |
} |
| 3373 |
break; |
| 3374 |
case ANALOG_EVENT_RINGOFFHOOK: |
| 3375 |
if (p->inalarm) { |
| 3376 |
break; |
| 3377 |
} |
| 3378 |
|
| 3379 |
|
| 3380 |
if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) { |
| 3381 |
c = strchr(p->dialdest, '/'); |
| 3382 |
if (c) { |
| 3383 |
c++; |
| 3384 |
} else { |
| 3385 |
c = p->dialdest; |
| 3386 |
} |
| 3387 |
|
| 3388 |
if (*c) { |
| 3389 |
int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c); |
| 3390 |
if (numchars >= sizeof(p->dop.dialstr)) { |
| 3391 |
ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c); |
| 3392 |
} |
| 3393 |
} else { |
| 3394 |
ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr)); |
| 3395 |
} |
| 3396 |
|
| 3397 |
if (strlen(p->dop.dialstr) > 4) { |
| 3398 |
memset(p->echorest, 'w', sizeof(p->echorest) - 1); |
| 3399 |
strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2); |
| 3400 |
p->echorest[sizeof(p->echorest) - 1] = '\0'; |
| 3401 |
p->echobreak = 1; |
| 3402 |
p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0'; |
| 3403 |
} else { |
| 3404 |
p->echobreak = 0; |
| 3405 |
} |
| 3406 |
if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) { |
| 3407 |
analog_on_hook(p); |
| 3408 |
return NULL; |
| 3409 |
} |
| 3410 |
analog_set_dialing(p, 1); |
| 3411 |
return &p->subs[idx].f; |
| 3412 |
} |
| 3413 |
switch (p->sig) { |
| 3414 |
case ANALOG_SIG_FXOLS: |
| 3415 |
case ANALOG_SIG_FXOGS: |
| 3416 |
case ANALOG_SIG_FXOKS: |
| 3417 |
p->fxsoffhookstate = 1; |
| 3418 |
switch (ast_channel_state(ast)) { |
| 3419 |
case AST_STATE_RINGING: |
| 3420 |
analog_set_echocanceller(p, 1); |
| 3421 |
analog_train_echocanceller(p); |
| 3422 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 3423 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 3424 |
|
| 3425 |
analog_set_needringing(p, 0); |
| 3426 |
analog_off_hook(p); |
| 3427 |
ast_debug(1, "channel %d answered\n", p->channel); |
| 3428 |
|
| 3429 |
|
| 3430 |
analog_cancel_cidspill(p); |
| 3431 |
|
| 3432 |
analog_set_dialing(p, 0); |
| 3433 |
p->callwaitcas = 0; |
| 3434 |
if (analog_check_confirmanswer(p)) { |
| 3435 |
|
| 3436 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 3437 |
p->subs[idx].f.subclass.integer = 0; |
| 3438 |
} else if (!ast_strlen_zero(p->dop.dialstr)) { |
| 3439 |
|
| 3440 |
res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop); |
| 3441 |
if (res) { |
| 3442 |
p->dop.dialstr[0] = '\0'; |
| 3443 |
return NULL; |
| 3444 |
} else { |
| 3445 |
ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr); |
| 3446 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 3447 |
p->subs[idx].f.subclass.integer = 0; |
| 3448 |
analog_set_dialing(p, 1); |
| 3449 |
} |
| 3450 |
p->dop.dialstr[0] = '\0'; |
| 3451 |
ast_setstate(ast, AST_STATE_DIALING); |
| 3452 |
} else { |
| 3453 |
ast_setstate(ast, AST_STATE_UP); |
| 3454 |
analog_answer_polarityswitch(p); |
| 3455 |
} |
| 3456 |
return &p->subs[idx].f; |
| 3457 |
case AST_STATE_DOWN: |
| 3458 |
ast_setstate(ast, AST_STATE_RING); |
| 3459 |
ast_channel_rings_set(ast, 1); |
| 3460 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 3461 |
p->subs[idx].f.subclass.integer = AST_CONTROL_OFFHOOK; |
| 3462 |
ast_debug(1, "channel %d picked up\n", p->channel); |
| 3463 |
return &p->subs[idx].f; |
| 3464 |
case AST_STATE_UP: |
| 3465 |
|
| 3466 |
analog_off_hook(p); |
| 3467 |
|
| 3468 |
ast_queue_unhold(p->owner); |
| 3469 |
break; |
| 3470 |
case AST_STATE_RESERVED: |
| 3471 |
|
| 3472 |
if (analog_has_voicemail(p)) { |
| 3473 |
res = analog_play_tone(p, ANALOG_SUB_REAL, ANALOG_TONE_STUTTER); |
| 3474 |
} else { |
| 3475 |
res = analog_play_tone(p, ANALOG_SUB_REAL, ANALOG_TONE_DIALTONE); |
| 3476 |
} |
| 3477 |
break; |
| 3478 |
default: |
| 3479 |
ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast)); |
| 3480 |
} |
| 3481 |
break; |
| 3482 |
case ANALOG_SIG_FXSLS: |
| 3483 |
case ANALOG_SIG_FXSGS: |
| 3484 |
case ANALOG_SIG_FXSKS: |
| 3485 |
if (ast_channel_state(ast) == AST_STATE_RING) { |
| 3486 |
analog_set_ringtimeout(p, p->ringt_base); |
| 3487 |
} |
| 3488 |
|
| 3489 |
|
| 3490 |
case ANALOG_SIG_EM: |
| 3491 |
case ANALOG_SIG_EM_E1: |
| 3492 |
case ANALOG_SIG_EMWINK: |
| 3493 |
case ANALOG_SIG_FEATD: |
| 3494 |
case ANALOG_SIG_FEATDMF: |
| 3495 |
case ANALOG_SIG_FEATDMF_TA: |
| 3496 |
case ANALOG_SIG_E911: |
| 3497 |
case ANALOG_SIG_FGC_CAMA: |
| 3498 |
case ANALOG_SIG_FGC_CAMAMF: |
| 3499 |
case ANALOG_SIG_FEATB: |
| 3500 |
case ANALOG_SIG_SF: |
| 3501 |
case ANALOG_SIG_SFWINK: |
| 3502 |
case ANALOG_SIG_SF_FEATD: |
| 3503 |
case ANALOG_SIG_SF_FEATDMF: |
| 3504 |
case ANALOG_SIG_SF_FEATB: |
| 3505 |
switch (ast_channel_state(ast)) { |
| 3506 |
case AST_STATE_PRERING: |
| 3507 |
ast_setstate(ast, AST_STATE_RING); |
| 3508 |
|
| 3509 |
case AST_STATE_DOWN: |
| 3510 |
case AST_STATE_RING: |
| 3511 |
ast_debug(1, "Ring detected\n"); |
| 3512 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 3513 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RING; |
| 3514 |
break; |
| 3515 |
case AST_STATE_RINGING: |
| 3516 |
case AST_STATE_DIALING: |
| 3517 |
if (p->outgoing) { |
| 3518 |
ast_debug(1, "Line answered\n"); |
| 3519 |
if (analog_check_confirmanswer(p)) { |
| 3520 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 3521 |
p->subs[idx].f.subclass.integer = 0; |
| 3522 |
} else { |
| 3523 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 3524 |
p->subs[idx].f.subclass.integer = AST_CONTROL_ANSWER; |
| 3525 |
ast_setstate(ast, AST_STATE_UP); |
| 3526 |
} |
| 3527 |
break; |
| 3528 |
} |
| 3529 |
|
| 3530 |
default: |
| 3531 |
ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel); |
| 3532 |
break; |
| 3533 |
} |
| 3534 |
break; |
| 3535 |
default: |
| 3536 |
ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig); |
| 3537 |
break; |
| 3538 |
} |
| 3539 |
break; |
| 3540 |
case ANALOG_EVENT_RINGBEGIN: |
| 3541 |
switch (p->sig) { |
| 3542 |
case ANALOG_SIG_FXSLS: |
| 3543 |
case ANALOG_SIG_FXSGS: |
| 3544 |
case ANALOG_SIG_FXSKS: |
| 3545 |
if (ast_channel_state(ast) == AST_STATE_RING) { |
| 3546 |
analog_set_ringtimeout(p, p->ringt_base); |
| 3547 |
} |
| 3548 |
break; |
| 3549 |
default: |
| 3550 |
break; |
| 3551 |
} |
| 3552 |
break; |
| 3553 |
case ANALOG_EVENT_RINGEROFF: |
| 3554 |
if (p->inalarm) break; |
| 3555 |
ast_channel_rings_set(ast, ast_channel_rings(ast) + 1); |
| 3556 |
if (ast_channel_rings(ast) == p->cidrings) { |
| 3557 |
analog_send_callerid(p, 0, &p->caller); |
| 3558 |
} |
| 3559 |
|
| 3560 |
if (ast_channel_rings(ast) > p->cidrings) { |
| 3561 |
analog_cancel_cidspill(p); |
| 3562 |
p->callwaitcas = 0; |
| 3563 |
} |
| 3564 |
p->subs[idx].f.frametype = AST_FRAME_CONTROL; |
| 3565 |
p->subs[idx].f.subclass.integer = AST_CONTROL_RINGING; |
| 3566 |
break; |
| 3567 |
case ANALOG_EVENT_RINGERON: |
| 3568 |
break; |
| 3569 |
case ANALOG_EVENT_NOALARM: |
| 3570 |
analog_set_alarm(p, 0); |
| 3571 |
analog_publish_channel_alarm_clear(p->channel); |
| 3572 |
break; |
| 3573 |
case ANALOG_EVENT_WINKFLASH: |
| 3574 |
if (p->inalarm) { |
| 3575 |
break; |
| 3576 |
} |
| 3577 |
|
| 3578 |
gettimeofday(&p->flashtime, NULL); |
| 3579 |
p->callwaitingdeluxepending = 0; |
| 3580 |
switch (mysig) { |
| 3581 |
case ANALOG_SIG_FXOLS: |
| 3582 |
case ANALOG_SIG_FXOGS: |
| 3583 |
case ANALOG_SIG_FXOKS: |
| 3584 |
ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n", |
| 3585 |
idx, analog_get_sub_fd(p, ANALOG_SUB_REAL), analog_get_sub_fd(p, ANALOG_SUB_CALLWAIT), analog_get_sub_fd(p, ANALOG_SUB_THREEWAY)); |
| 3586 |
|
| 3587 |
|
| 3588 |
analog_cancel_cidspill(p); |
| 3589 |
p->callwaitcas = 0; |
| 3590 |
|
| 3591 |
if (idx != ANALOG_SUB_REAL) { |
| 3592 |
ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel); |
| 3593 |
goto winkflashdone; |
| 3594 |
} |
| 3595 |
|
| 3596 |
if (p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 3597 |
|
| 3598 |
analog_lock_sub_owner(p, ANALOG_SUB_CALLWAIT); |
| 3599 |
if (!p->subs[ANALOG_SUB_CALLWAIT].owner) { |
| 3600 |
|
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n"); |
| 3605 |
goto winkflashdone; |
| 3606 |
} |
| 3607 |
|
| 3608 |
|
| 3609 |
|
| 3610 |
if (ast_channel_state(p->subs[ANALOG_SUB_CALLWAIT].owner) == AST_STATE_RINGING) { |
| 3611 |
if (p->callwaitingdeluxe) { |
| 3612 |
|
| 3613 |
|
| 3614 |
|
| 3615 |
ast_channel_unlock(p->subs[ANALOG_SUB_CALLWAIT].owner); |
| 3616 |
p->callwaitingdeluxepending = 1; |
| 3617 |
ast_debug(1, "Deferring call waiting manipulation, waiting for Call Waiting Deluxe option from user\n"); |
| 3618 |
goto winkflashdone; |
| 3619 |
} |
| 3620 |
} |
| 3621 |
|
| 3622 |
|
| 3623 |
analog_swap_subs(p, ANALOG_SUB_REAL, ANALOG_SUB_CALLWAIT); |
| 3624 |
analog_play_tone(p, ANALOG_SUB_REAL, -1); |
| 3625 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 3626 |
ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner)); |
| 3627 |
if (ast_channel_state(p->subs[ANALOG_SUB_REAL].owner) == AST_STATE_RINGING) { |
| 3628 |
ast_setstate(p->subs[ANALOG_SUB_REAL].owner, AST_STATE_UP); |
| 3629 |
ast_queue_control(p->subs[ANALOG_SUB_REAL].owner, AST_CONTROL_ANSWER); |
| 3630 |
} |
| 3631 |
analog_stop_callwait(p); |
| 3632 |
|
| 3633 |
|
| 3634 |
if (!p->subs[ANALOG_SUB_CALLWAIT].inthreeway) { |
| 3635 |
ast_queue_hold(p->subs[ANALOG_SUB_CALLWAIT].owner, p->mohsuggest); |
| 3636 |
} |
| 3637 |
ast_queue_hold(p->subs[ANALOG_SUB_REAL].owner, p->mohsuggest); |
| 3638 |
ast_queue_unhold(p->subs[ANALOG_SUB_REAL].owner); |
| 3639 |
|
| 3640 |
|
| 3641 |
ast_channel_unlock(p->subs[ANALOG_SUB_REAL].owner); |
| 3642 |
} else if (!p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 3643 |
if (!p->threewaycalling) { |
| 3644 |
|
| 3645 |
ast_queue_control(p->subs[ANALOG_SUB_REAL].owner, AST_CONTROL_FLASH); |
| 3646 |
goto winkflashdone; |
| 3647 |
} else if (!analog_check_for_conference(p)) { |
| 3648 |
ast_callid callid = 0; |
| 3649 |
int callid_created; |
| 3650 |
char cid_num[256]; |
| 3651 |
char cid_name[256]; |
| 3652 |
|
| 3653 |
cid_num[0] = '\0'; |
| 3654 |
cid_name[0] = '\0'; |
| 3655 |
if (p->dahditrcallerid && p->owner) { |
| 3656 |
if (ast_channel_caller(p->owner)->id.number.valid |
| 3657 |
&& ast_channel_caller(p->owner)->id.number.str) { |
| 3658 |
ast_copy_string(cid_num, ast_channel_caller(p->owner)->id.number.str, |
| 3659 |
sizeof(cid_num)); |
| 3660 |
} |
| 3661 |
if (ast_channel_caller(p->owner)->id.name.valid |
| 3662 |
&& ast_channel_caller(p->owner)->id.name.str) { |
| 3663 |
ast_copy_string(cid_name, ast_channel_caller(p->owner)->id.name.str, |
| 3664 |
sizeof(cid_name)); |
| 3665 |
} |
| 3666 |
} |
| 3667 |
|
| 3668 |
|
| 3669 |
if (!((ast_channel_pbx(ast)) || |
| 3670 |
(ast_channel_state(ast) == AST_STATE_UP) || |
| 3671 |
(ast_channel_state(ast) == AST_STATE_RING))) { |
| 3672 |
ast_debug(1, "Flash when call not up or ringing\n"); |
| 3673 |
goto winkflashdone; |
| 3674 |
} |
| 3675 |
if (analog_alloc_sub(p, ANALOG_SUB_THREEWAY)) { |
| 3676 |
ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n"); |
| 3677 |
goto winkflashdone; |
| 3678 |
} |
| 3679 |
|
| 3680 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 3681 |
|
| 3682 |
|
| 3683 |
|
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
analog_unlock_private(p); |
| 3689 |
ast_channel_unlock(ast); |
| 3690 |
chan = analog_new_ast_channel(p, AST_STATE_RESERVED, 0, ANALOG_SUB_THREEWAY, NULL); |
| 3691 |
ast_channel_lock(ast); |
| 3692 |
analog_lock_private(p); |
| 3693 |
if (!chan) { |
| 3694 |
ast_log(LOG_WARNING, |
| 3695 |
"Cannot allocate new call structure on channel %d\n", |
| 3696 |
p->channel); |
| 3697 |
analog_unalloc_sub(p, ANALOG_SUB_THREEWAY); |
| 3698 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 3699 |
goto winkflashdone; |
| 3700 |
} |
| 3701 |
if (p->dahditrcallerid) { |
| 3702 |
if (!p->origcid_num) { |
| 3703 |
p->origcid_num = ast_strdup(p->cid_num); |
| 3704 |
} |
| 3705 |
if (!p->origcid_name) { |
| 3706 |
p->origcid_name = ast_strdup(p->cid_name); |
| 3707 |
} |
| 3708 |
ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num)); |
| 3709 |
ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name)); |
| 3710 |
} |
| 3711 |
|
| 3712 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 3713 |
|
| 3714 |
analog_set_echocanceller(p, 0); |
| 3715 |
res = analog_play_tone(p, ANALOG_SUB_REAL, ANALOG_TONE_DIALRECALL); |
| 3716 |
if (res) { |
| 3717 |
ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel); |
| 3718 |
} |
| 3719 |
analog_set_new_owner(p, chan); |
| 3720 |
p->ss_astchan = chan; |
| 3721 |
if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p)) { |
| 3722 |
ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel); |
| 3723 |
res = analog_play_tone(p, ANALOG_SUB_REAL, ANALOG_TONE_CONGESTION); |
| 3724 |
analog_set_echocanceller(p, 1); |
| 3725 |
ast_hangup(chan); |
| 3726 |
} else { |
| 3727 |
ast_verb(3, "Started three way call on channel %d\n", p->channel); |
| 3728 |
|
| 3729 |
|
| 3730 |
ast_queue_hold(p->subs[ANALOG_SUB_THREEWAY].owner, p->mohsuggest); |
| 3731 |
} |
| 3732 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 3733 |
} |
| 3734 |
} else { |
| 3735 |
|
| 3736 |
enum analog_sub orig_3way_sub; |
| 3737 |
|
| 3738 |
|
| 3739 |
analog_lock_sub_owner(p, ANALOG_SUB_THREEWAY); |
| 3740 |
if (!p->subs[ANALOG_SUB_THREEWAY].owner) { |
| 3741 |
|
| 3742 |
|
| 3743 |
|
| 3744 |
|
| 3745 |
ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n"); |
| 3746 |
goto winkflashdone; |
| 3747 |
} |
| 3748 |
orig_3way_sub = ANALOG_SUB_THREEWAY; |
| 3749 |
|
| 3750 |
if (p->subs[ANALOG_SUB_THREEWAY].inthreeway) { |
| 3751 |
|
| 3752 |
ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel); |
| 3753 |
|
| 3754 |
if ((ast_channel_state(p->subs[ANALOG_SUB_REAL].owner) != AST_STATE_UP) && |
| 3755 |
(ast_channel_state(p->subs[ANALOG_SUB_THREEWAY].owner) == AST_STATE_UP)) { |
| 3756 |
|
| 3757 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 3758 |
orig_3way_sub = ANALOG_SUB_REAL; |
| 3759 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 3760 |
} |
| 3761 |
|
| 3762 |
ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner)); |
| 3763 |
ast_softhangup_nolock(p->subs[ANALOG_SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 3764 |
analog_set_inthreeway(p, ANALOG_SUB_REAL, 0); |
| 3765 |
analog_set_inthreeway(p, ANALOG_SUB_THREEWAY, 0); |
| 3766 |
} else { |
| 3767 |
|
| 3768 |
if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) && |
| 3769 |
(p->transfertobusy || (ast_channel_state(ast) != AST_STATE_BUSY))) { |
| 3770 |
ast_verb(3, "Building conference call with %s and %s\n", |
| 3771 |
ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner), |
| 3772 |
ast_channel_name(p->subs[ANALOG_SUB_REAL].owner)); |
| 3773 |
|
| 3774 |
analog_set_inthreeway(p, ANALOG_SUB_THREEWAY, 1); |
| 3775 |
analog_set_inthreeway(p, ANALOG_SUB_REAL, 1); |
| 3776 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 3777 |
orig_3way_sub = ANALOG_SUB_REAL; |
| 3778 |
ast_queue_unhold(p->subs[orig_3way_sub].owner); |
| 3779 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 3780 |
} else { |
| 3781 |
ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner)); |
| 3782 |
analog_swap_subs(p, ANALOG_SUB_THREEWAY, ANALOG_SUB_REAL); |
| 3783 |
orig_3way_sub = ANALOG_SUB_REAL; |
| 3784 |
ast_softhangup_nolock(p->subs[ANALOG_SUB_THREEWAY].owner, AST_SOFTHANGUP_DEV); |
| 3785 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 3786 |
ast_queue_unhold(p->subs[ANALOG_SUB_REAL].owner); |
| 3787 |
analog_set_echocanceller(p, 1); |
| 3788 |
} |
| 3789 |
} |
| 3790 |
ast_channel_unlock(p->subs[orig_3way_sub].owner); |
| 3791 |
} |
| 3792 |
winkflashdone: |
| 3793 |
analog_update_conf(p); |
| 3794 |
break; |
| 3795 |
case ANALOG_SIG_EM: |
| 3796 |
case ANALOG_SIG_EM_E1: |
| 3797 |
case ANALOG_SIG_FEATD: |
| 3798 |
case ANALOG_SIG_SF: |
| 3799 |
case ANALOG_SIG_SFWINK: |
| 3800 |
case ANALOG_SIG_SF_FEATD: |
| 3801 |
case ANALOG_SIG_FXSLS: |
| 3802 |
case ANALOG_SIG_FXSGS: |
| 3803 |
if (p->dialing) { |
| 3804 |
ast_debug(1, "Ignoring wink on channel %d\n", p->channel); |
| 3805 |
} else { |
| 3806 |
ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel); |
| 3807 |
} |
| 3808 |
break; |
| 3809 |
case ANALOG_SIG_FEATDMF_TA: |
| 3810 |
switch (p->whichwink) { |
| 3811 |
case 0: |
| 3812 |
ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2, |
| 3813 |
S_COR(ast_channel_caller(p->owner)->ani.number.valid, |
| 3814 |
ast_channel_caller(p->owner)->ani.number.str, "")); |
| 3815 |
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#", |
| 3816 |
ast_channel_caller(p->owner)->ani2, |
| 3817 |
S_COR(ast_channel_caller(p->owner)->ani.number.valid, |
| 3818 |
ast_channel_caller(p->owner)->ani.number.str, "")); |
| 3819 |
break; |
| 3820 |
case 1: |
| 3821 |
ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr)); |
| 3822 |
break; |
| 3823 |
case 2: |
| 3824 |
ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n"); |
| 3825 |
return NULL; |
| 3826 |
} |
| 3827 |
p->whichwink++; |
| 3828 |
|
| 3829 |
case ANALOG_SIG_FEATDMF: |
| 3830 |
case ANALOG_SIG_E911: |
| 3831 |
case ANALOG_SIG_FGC_CAMAMF: |
| 3832 |
case ANALOG_SIG_FGC_CAMA: |
| 3833 |
case ANALOG_SIG_FEATB: |
| 3834 |
case ANALOG_SIG_SF_FEATDMF: |
| 3835 |
case ANALOG_SIG_SF_FEATB: |
| 3836 |
case ANALOG_SIG_EMWINK: |
| 3837 |
|
| 3838 |
if (!ast_strlen_zero(p->dop.dialstr)) { |
| 3839 |
res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop); |
| 3840 |
if (res) { |
| 3841 |
p->dop.dialstr[0] = '\0'; |
| 3842 |
return NULL; |
| 3843 |
} else { |
| 3844 |
ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr); |
| 3845 |
} |
| 3846 |
} |
| 3847 |
p->dop.dialstr[0] = '\0'; |
| 3848 |
break; |
| 3849 |
default: |
| 3850 |
ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig); |
| 3851 |
} |
| 3852 |
break; |
| 3853 |
case ANALOG_EVENT_HOOKCOMPLETE: |
| 3854 |
if (p->inalarm) break; |
| 3855 |
if (analog_check_waitingfordt(p)) { |
| 3856 |
break; |
| 3857 |
} |
| 3858 |
switch (mysig) { |
| 3859 |
case ANALOG_SIG_FXSLS: |
| 3860 |
case ANALOG_SIG_FXSGS: |
| 3861 |
case ANALOG_SIG_FXSKS: |
| 3862 |
case ANALOG_SIG_EM: |
| 3863 |
case ANALOG_SIG_EM_E1: |
| 3864 |
case ANALOG_SIG_EMWINK: |
| 3865 |
case ANALOG_SIG_FEATD: |
| 3866 |
case ANALOG_SIG_SF: |
| 3867 |
case ANALOG_SIG_SFWINK: |
| 3868 |
case ANALOG_SIG_SF_FEATD: |
| 3869 |
if (!ast_strlen_zero(p->dop.dialstr)) { |
| 3870 |
res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop); |
| 3871 |
if (res) { |
| 3872 |
p->dop.dialstr[0] = '\0'; |
| 3873 |
return NULL; |
| 3874 |
} else { |
| 3875 |
ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr); |
| 3876 |
} |
| 3877 |
} |
| 3878 |
p->dop.dialstr[0] = '\0'; |
| 3879 |
p->dop.op = ANALOG_DIAL_OP_REPLACE; |
| 3880 |
break; |
| 3881 |
case ANALOG_SIG_FEATDMF: |
| 3882 |
case ANALOG_SIG_FEATDMF_TA: |
| 3883 |
case ANALOG_SIG_E911: |
| 3884 |
case ANALOG_SIG_FGC_CAMA: |
| 3885 |
case ANALOG_SIG_FGC_CAMAMF: |
| 3886 |
case ANALOG_SIG_FEATB: |
| 3887 |
case ANALOG_SIG_SF_FEATDMF: |
| 3888 |
case ANALOG_SIG_SF_FEATB: |
| 3889 |
ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel); |
| 3890 |
break; |
| 3891 |
default: |
| 3892 |
break; |
| 3893 |
} |
| 3894 |
break; |
| 3895 |
case ANALOG_EVENT_POLARITY: |
| 3896 |
|
| 3897 |
|
| 3898 |
|
| 3899 |
|
| 3900 |
|
| 3901 |
|
| 3902 |
|
| 3903 |
|
| 3904 |
|
| 3905 |
if (p->polarityonanswerdelay > 0) { |
| 3906 |
|
| 3907 |
if (ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) > p->polarityonanswerdelay) { |
| 3908 |
switch (ast_channel_state(ast)) { |
| 3909 |
case AST_STATE_DIALING: |
| 3910 |
case AST_STATE_RINGING: |
| 3911 |
if (p->answeronpolarityswitch) { |
| 3912 |
ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel); |
| 3913 |
ast_setstate(p->owner, AST_STATE_UP); |
| 3914 |
p->polarity = POLARITY_REV; |
| 3915 |
if (p->hanguponpolarityswitch) { |
| 3916 |
p->polaritydelaytv = ast_tvnow(); |
| 3917 |
} |
| 3918 |
} else { |
| 3919 |
ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel); |
| 3920 |
} |
| 3921 |
break; |
| 3922 |
|
| 3923 |
case AST_STATE_UP: |
| 3924 |
case AST_STATE_RING: |
| 3925 |
if (p->hanguponpolarityswitch) { |
| 3926 |
ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel); |
| 3927 |
ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size); |
| 3928 |
ast_channel_hangupcause_hash_set(ast, cause_code, data_size); |
| 3929 |
ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT); |
| 3930 |
p->polarity = POLARITY_IDLE; |
| 3931 |
} else { |
| 3932 |
ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel); |
| 3933 |
} |
| 3934 |
break; |
| 3935 |
|
| 3936 |
case AST_STATE_DOWN: |
| 3937 |
case AST_STATE_RESERVED: |
| 3938 |
case AST_STATE_OFFHOOK: |
| 3939 |
case AST_STATE_BUSY: |
| 3940 |
case AST_STATE_DIALING_OFFHOOK: |
| 3941 |
case AST_STATE_PRERING: |
| 3942 |
default: |
| 3943 |
if (p->answeronpolarityswitch || p->hanguponpolarityswitch) { |
| 3944 |
ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast_channel_state(ast)); |
| 3945 |
} |
| 3946 |
break; |
| 3947 |
} |
| 3948 |
|
| 3949 |
} else { |
| 3950 |
|
| 3951 |
switch (ast_channel_state(ast)) { |
| 3952 |
case AST_STATE_DIALING: |
| 3953 |
case AST_STATE_RINGING: |
| 3954 |
if (p->answeronpolarityswitch) { |
| 3955 |
ast_debug(1, "Polarity switch detected but NOT answering (too close to OffHook event) on channel %d, state %u\n", p->channel, ast_channel_state(ast)); |
| 3956 |
} |
| 3957 |
break; |
| 3958 |
|
| 3959 |
case AST_STATE_UP: |
| 3960 |
case AST_STATE_RING: |
| 3961 |
if (p->hanguponpolarityswitch) { |
| 3962 |
ast_debug(1, "Polarity switch detected but NOT hanging up (too close to Answer event) on channel %d, state %u\n", p->channel, ast_channel_state(ast)); |
| 3963 |
} |
| 3964 |
break; |
| 3965 |
|
| 3966 |
default: |
| 3967 |
if (p->answeronpolarityswitch || p->hanguponpolarityswitch) { |
| 3968 |
ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast_channel_state(ast)); |
| 3969 |
} |
| 3970 |
break; |
| 3971 |
} |
| 3972 |
} |
| 3973 |
} |
| 3974 |
|
| 3975 |
|
| 3976 |
ast_debug(1, "Polarity Reversal event occurred - 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) ); |
| 3977 |
break; |
| 3978 |
default: |
| 3979 |
ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel); |
| 3980 |
} |
| 3981 |
return &p->subs[idx].f; |
| 3982 |
} |
| 3983 |
|
| 3984 |
struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast) |
| 3985 |
{ |
| 3986 |
int res; |
| 3987 |
int idx; |
| 3988 |
struct ast_frame *f; |
| 3989 |
|
| 3990 |
ast_debug(1, "%s %d\n", __FUNCTION__, p->channel); |
| 3991 |
|
| 3992 |
idx = analog_get_index(ast, p, 1); |
| 3993 |
if (idx < 0) { |
| 3994 |
idx = ANALOG_SUB_REAL; |
| 3995 |
} |
| 3996 |
|
| 3997 |
p->subs[idx].f.frametype = AST_FRAME_NULL; |
| 3998 |
p->subs[idx].f.datalen = 0; |
| 3999 |
p->subs[idx].f.samples = 0; |
| 4000 |
p->subs[idx].f.mallocd = 0; |
| 4001 |
p->subs[idx].f.offset = 0; |
| 4002 |
p->subs[idx].f.subclass.integer = 0; |
| 4003 |
p->subs[idx].f.delivery = ast_tv(0,0); |
| 4004 |
p->subs[idx].f.src = "dahdi_exception"; |
| 4005 |
p->subs[idx].f.data.ptr = NULL; |
| 4006 |
|
| 4007 |
if (!p->owner) { |
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
res = analog_get_event(p); |
| 4014 |
|
| 4015 |
|
| 4016 |
if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) && |
| 4017 |
(res != ANALOG_EVENT_HOOKCOMPLETE)) { |
| 4018 |
ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res); |
| 4019 |
analog_set_new_owner(p, p->subs[ANALOG_SUB_REAL].owner); |
| 4020 |
if (p->owner && ast != p->owner) { |
| 4021 |
|
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n", |
| 4026 |
analog_event2str(res), ast_channel_name(ast), ast_channel_name(p->owner)); |
| 4027 |
} |
| 4028 |
if (p->owner) { |
| 4029 |
ast_queue_unhold(p->owner); |
| 4030 |
} |
| 4031 |
} |
| 4032 |
switch (res) { |
| 4033 |
case ANALOG_EVENT_ONHOOK: |
| 4034 |
analog_set_echocanceller(p, 0); |
| 4035 |
if (p->owner) { |
| 4036 |
ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner)); |
| 4037 |
analog_ring(p); |
| 4038 |
analog_stop_callwait(p); |
| 4039 |
} else { |
| 4040 |
ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n", |
| 4041 |
analog_event2str(res)); |
| 4042 |
} |
| 4043 |
analog_update_conf(p); |
| 4044 |
break; |
| 4045 |
case ANALOG_EVENT_RINGOFFHOOK: |
| 4046 |
analog_set_echocanceller(p, 1); |
| 4047 |
analog_off_hook(p); |
| 4048 |
if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) { |
| 4049 |
ast_queue_control(p->owner, AST_CONTROL_ANSWER); |
| 4050 |
analog_set_dialing(p, 0); |
| 4051 |
} |
| 4052 |
break; |
| 4053 |
case ANALOG_EVENT_HOOKCOMPLETE: |
| 4054 |
case ANALOG_EVENT_RINGERON: |
| 4055 |
case ANALOG_EVENT_RINGEROFF: |
| 4056 |
|
| 4057 |
break; |
| 4058 |
case ANALOG_EVENT_WINKFLASH: |
| 4059 |
gettimeofday(&p->flashtime, NULL); |
| 4060 |
if (p->owner) { |
| 4061 |
ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner)); |
| 4062 |
if (ast_channel_state(p->owner) != AST_STATE_UP) { |
| 4063 |
|
| 4064 |
ast_queue_control(p->owner, AST_CONTROL_ANSWER); |
| 4065 |
ast_setstate(p->owner, AST_STATE_UP); |
| 4066 |
} |
| 4067 |
analog_stop_callwait(p); |
| 4068 |
ast_queue_unhold(p->owner); |
| 4069 |
} else { |
| 4070 |
ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n", |
| 4071 |
analog_event2str(res)); |
| 4072 |
} |
| 4073 |
analog_update_conf(p); |
| 4074 |
break; |
| 4075 |
default: |
| 4076 |
ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res)); |
| 4077 |
break; |
| 4078 |
} |
| 4079 |
f = &p->subs[idx].f; |
| 4080 |
return f; |
| 4081 |
} |
| 4082 |
ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel); |
| 4083 |
|
| 4084 |
if (ast != p->owner) { |
| 4085 |
ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner)); |
| 4086 |
f = &p->subs[idx].f; |
| 4087 |
return f; |
| 4088 |
} |
| 4089 |
|
| 4090 |
f = __analog_handle_event(p, ast); |
| 4091 |
if (!f) { |
| 4092 |
const char *name = ast_strdupa(ast_channel_name(ast)); |
| 4093 |
|
| 4094 |
|
| 4095 |
analog_unlock_private(p); |
| 4096 |
ast_channel_unlock(ast); |
| 4097 |
ast_set_hangupsource(ast, name, 0); |
| 4098 |
ast_channel_lock(ast); |
| 4099 |
analog_lock_private(p); |
| 4100 |
} |
| 4101 |
return f; |
| 4102 |
} |
| 4103 |
|
| 4104 |
void *analog_handle_init_event(struct analog_pvt *i, int event) |
| 4105 |
{ |
| 4106 |
int res; |
| 4107 |
pthread_t threadid; |
| 4108 |
struct ast_channel *chan; |
| 4109 |
ast_callid callid = 0; |
| 4110 |
int callid_created; |
| 4111 |
|
| 4112 |
ast_debug(1, "channel (%d) - signaling (%d) - event (%s)\n", |
| 4113 |
i->channel, i->sig, analog_event2str(event)); |
| 4114 |
|
| 4115 |
|
| 4116 |
switch (event) { |
| 4117 |
case ANALOG_EVENT_WINKFLASH: |
| 4118 |
case ANALOG_EVENT_RINGBEGIN: |
| 4119 |
switch (i->sig) { |
| 4120 |
case ANALOG_SIG_FXSLS: |
| 4121 |
case ANALOG_SIG_FXSGS: |
| 4122 |
case ANALOG_SIG_FXSKS: |
| 4123 |
if (i->immediate) { |
| 4124 |
if (i->use_callerid || i->usedistinctiveringdetection) { |
| 4125 |
ast_log(LOG_WARNING, "Can't start PBX immediately, must wait for Caller ID / distinctive ring\n"); |
| 4126 |
} else { |
| 4127 |
|
| 4128 |
|
| 4129 |
|
| 4130 |
|
| 4131 |
|
| 4132 |
ast_debug(1, "Disabling ring timeout (previously %d) to begin handling immediately\n", i->ringt_base); |
| 4133 |
analog_set_ringtimeout(i, 0); |
| 4134 |
} |
| 4135 |
} |
| 4136 |
break; |
| 4137 |
default: |
| 4138 |
break; |
| 4139 |
} |
| 4140 |
|
| 4141 |
if (!(ISTRUNK(i) && i->immediate && !i->use_callerid && !i->usedistinctiveringdetection)) { |
| 4142 |
break; |
| 4143 |
} |
| 4144 |
case ANALOG_EVENT_RINGOFFHOOK: |
| 4145 |
if (i->inalarm) { |
| 4146 |
break; |
| 4147 |
} |
| 4148 |
|
| 4149 |
switch (i->sig) { |
| 4150 |
case ANALOG_SIG_FXOLS: |
| 4151 |
case ANALOG_SIG_FXOGS: |
| 4152 |
case ANALOG_SIG_FXOKS: |
| 4153 |
res = analog_off_hook(i); |
| 4154 |
i->fxsoffhookstate = 1; |
| 4155 |
i->cshactive = 0; |
| 4156 |
i->callwaitingdeluxepending = 0; |
| 4157 |
if (res && (errno == EBUSY)) { |
| 4158 |
break; |
| 4159 |
} |
| 4160 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 4161 |
|
| 4162 |
|
| 4163 |
analog_cancel_cidspill(i); |
| 4164 |
|
| 4165 |
if (i->immediate) { |
| 4166 |
analog_set_echocanceller(i, 1); |
| 4167 |
|
| 4168 |
if (i->immediatering) { |
| 4169 |
|
| 4170 |
res = analog_play_tone(i, ANALOG_SUB_REAL, ANALOG_TONE_RINGTONE); |
| 4171 |
} |
| 4172 |
chan = analog_new_ast_channel(i, AST_STATE_RING, 1, ANALOG_SUB_REAL, NULL); |
| 4173 |
if (!chan) { |
| 4174 |
ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel); |
| 4175 |
res = analog_play_tone(i, ANALOG_SUB_REAL, ANALOG_TONE_CONGESTION); |
| 4176 |
if (res < 0) { |
| 4177 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 4178 |
} |
| 4179 |
} |
| 4180 |
} else { |
| 4181 |
|
| 4182 |
chan = analog_new_ast_channel(i, AST_STATE_RESERVED, 0, ANALOG_SUB_REAL, NULL); |
| 4183 |
i->ss_astchan = chan; |
| 4184 |
if (chan) { |
| 4185 |
if (analog_has_voicemail(i)) { |
| 4186 |
res = analog_play_tone(i, ANALOG_SUB_REAL, ANALOG_TONE_STUTTER); |
| 4187 |
} else { |
| 4188 |
res = analog_play_tone(i, ANALOG_SUB_REAL, ANALOG_TONE_DIALTONE); |
| 4189 |
} |
| 4190 |
if (res < 0) |
| 4191 |
ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel); |
| 4192 |
|
| 4193 |
if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) { |
| 4194 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 4195 |
res = analog_play_tone(i, ANALOG_SUB_REAL, ANALOG_TONE_CONGESTION); |
| 4196 |
if (res < 0) { |
| 4197 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 4198 |
} |
| 4199 |
ast_hangup(chan); |
| 4200 |
} |
| 4201 |
} else |
| 4202 |
ast_log(LOG_WARNING, "Unable to create channel\n"); |
| 4203 |
} |
| 4204 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 4205 |
break; |
| 4206 |
case ANALOG_SIG_FXSLS: |
| 4207 |
case ANALOG_SIG_FXSGS: |
| 4208 |
case ANALOG_SIG_FXSKS: |
| 4209 |
analog_set_ringtimeout(i, i->ringt_base); |
| 4210 |
|
| 4211 |
case ANALOG_SIG_EMWINK: |
| 4212 |
case ANALOG_SIG_FEATD: |
| 4213 |
case ANALOG_SIG_FEATDMF: |
| 4214 |
case ANALOG_SIG_FEATDMF_TA: |
| 4215 |
case ANALOG_SIG_E911: |
| 4216 |
case ANALOG_SIG_FGC_CAMA: |
| 4217 |
case ANALOG_SIG_FGC_CAMAMF: |
| 4218 |
case ANALOG_SIG_FEATB: |
| 4219 |
case ANALOG_SIG_EM: |
| 4220 |
case ANALOG_SIG_EM_E1: |
| 4221 |
case ANALOG_SIG_SFWINK: |
| 4222 |
case ANALOG_SIG_SF_FEATD: |
| 4223 |
case ANALOG_SIG_SF_FEATDMF: |
| 4224 |
case ANALOG_SIG_SF_FEATB: |
| 4225 |
case ANALOG_SIG_SF: |
| 4226 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 4227 |
|
| 4228 |
if (i->cid_start == ANALOG_CID_START_POLARITY_IN || i->cid_start == ANALOG_CID_START_DTMF_NOALERT) { |
| 4229 |
chan = analog_new_ast_channel(i, AST_STATE_PRERING, 0, ANALOG_SUB_REAL, NULL); |
| 4230 |
} else { |
| 4231 |
chan = analog_new_ast_channel(i, AST_STATE_RING, 0, ANALOG_SUB_REAL, NULL); |
| 4232 |
} |
| 4233 |
i->ss_astchan = chan; |
| 4234 |
if (!chan) { |
| 4235 |
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel); |
| 4236 |
} else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) { |
| 4237 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 4238 |
res = analog_play_tone(i, ANALOG_SUB_REAL, ANALOG_TONE_CONGESTION); |
| 4239 |
if (res < 0) { |
| 4240 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 4241 |
} |
| 4242 |
ast_hangup(chan); |
| 4243 |
} |
| 4244 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 4245 |
break; |
| 4246 |
default: |
| 4247 |
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); |
| 4248 |
res = analog_play_tone(i, ANALOG_SUB_REAL, ANALOG_TONE_CONGESTION); |
| 4249 |
if (res < 0) { |
| 4250 |
ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 4251 |
} |
| 4252 |
return NULL; |
| 4253 |
} |
| 4254 |
break; |
| 4255 |
case ANALOG_EVENT_NOALARM: |
| 4256 |
analog_set_alarm(i, 0); |
| 4257 |
analog_publish_channel_alarm_clear(i->channel); |
| 4258 |
break; |
| 4259 |
case ANALOG_EVENT_ALARM: |
| 4260 |
analog_set_alarm(i, 1); |
| 4261 |
analog_get_and_handle_alarms(i); |
| 4262 |
|
| 4263 |
case ANALOG_EVENT_ONHOOK: |
| 4264 |
|
| 4265 |
switch (i->sig) { |
| 4266 |
case ANALOG_SIG_FXOLS: |
| 4267 |
case ANALOG_SIG_FXOGS: |
| 4268 |
i->fxsoffhookstate = 0; |
| 4269 |
analog_start_polarityswitch(i); |
| 4270 |
|
| 4271 |
case ANALOG_SIG_FEATD: |
| 4272 |
case ANALOG_SIG_FEATDMF: |
| 4273 |
case ANALOG_SIG_FEATDMF_TA: |
| 4274 |
case ANALOG_SIG_E911: |
| 4275 |
case ANALOG_SIG_FGC_CAMA: |
| 4276 |
case ANALOG_SIG_FGC_CAMAMF: |
| 4277 |
case ANALOG_SIG_FEATB: |
| 4278 |
case ANALOG_SIG_EM: |
| 4279 |
case ANALOG_SIG_EM_E1: |
| 4280 |
case ANALOG_SIG_EMWINK: |
| 4281 |
case ANALOG_SIG_SF_FEATD: |
| 4282 |
case ANALOG_SIG_SF_FEATDMF: |
| 4283 |
case ANALOG_SIG_SF_FEATB: |
| 4284 |
case ANALOG_SIG_SF: |
| 4285 |
case ANALOG_SIG_SFWINK: |
| 4286 |
case ANALOG_SIG_FXSLS: |
| 4287 |
case ANALOG_SIG_FXSGS: |
| 4288 |
case ANALOG_SIG_FXSKS: |
| 4289 |
analog_set_echocanceller(i, 0); |
| 4290 |
res = analog_play_tone(i, ANALOG_SUB_REAL, -1); |
| 4291 |
analog_on_hook(i); |
| 4292 |
break; |
| 4293 |
case ANALOG_SIG_FXOKS: |
| 4294 |
i->fxsoffhookstate = 0; |
| 4295 |
analog_start_polarityswitch(i); |
| 4296 |
analog_set_echocanceller(i, 0); |
| 4297 |
|
| 4298 |
#ifdef ZHONE_HACK |
| 4299 |
analog_off_hook(i); |
| 4300 |
usleep(1); |
| 4301 |
#endif |
| 4302 |
res = analog_play_tone(i, ANALOG_SUB_REAL, -1); |
| 4303 |
analog_on_hook(i); |
| 4304 |
break; |
| 4305 |
default: |
| 4306 |
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); |
| 4307 |
res = analog_play_tone(i, ANALOG_SUB_REAL, -1); |
| 4308 |
return NULL; |
| 4309 |
} |
| 4310 |
break; |
| 4311 |
case ANALOG_EVENT_POLARITY: |
| 4312 |
switch (i->sig) { |
| 4313 |
case ANALOG_SIG_FXSLS: |
| 4314 |
case ANALOG_SIG_FXSKS: |
| 4315 |
case ANALOG_SIG_FXSGS: |
| 4316 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 4317 |
|
| 4318 |
|
| 4319 |
|
| 4320 |
|
| 4321 |
if (i->hanguponpolarityswitch) { |
| 4322 |
i->polarity = POLARITY_REV; |
| 4323 |
} |
| 4324 |
if (i->cid_start == ANALOG_CID_START_POLARITY || i->cid_start == ANALOG_CID_START_POLARITY_IN) { |
| 4325 |
i->polarity = POLARITY_REV; |
| 4326 |
ast_verb(2, "Starting post polarity CID detection on channel %d\n", |
| 4327 |
i->channel); |
| 4328 |
chan = analog_new_ast_channel(i, AST_STATE_PRERING, 0, ANALOG_SUB_REAL, NULL); |
| 4329 |
i->ss_astchan = chan; |
| 4330 |
if (!chan) { |
| 4331 |
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel); |
| 4332 |
} else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) { |
| 4333 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 4334 |
ast_hangup(chan); |
| 4335 |
} |
| 4336 |
} |
| 4337 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 4338 |
break; |
| 4339 |
default: |
| 4340 |
ast_log(LOG_WARNING, |
| 4341 |
"handle_init_event detected polarity reversal on non-FXO (ANALOG_SIG_FXS) interface %d\n", |
| 4342 |
i->channel); |
| 4343 |
break; |
| 4344 |
} |
| 4345 |
break; |
| 4346 |
case ANALOG_EVENT_DTMFCID: |
| 4347 |
switch (i->sig) { |
| 4348 |
case ANALOG_SIG_FXSLS: |
| 4349 |
case ANALOG_SIG_FXSKS: |
| 4350 |
case ANALOG_SIG_FXSGS: |
| 4351 |
callid_created = ast_callid_threadstorage_auto(&callid); |
| 4352 |
if (i->cid_start == ANALOG_CID_START_DTMF_NOALERT) { |
| 4353 |
ast_verb(2, "Starting DTMF CID detection on channel %d\n", |
| 4354 |
i->channel); |
| 4355 |
chan = analog_new_ast_channel(i, AST_STATE_PRERING, 0, ANALOG_SUB_REAL, NULL); |
| 4356 |
i->ss_astchan = chan; |
| 4357 |
if (!chan) { |
| 4358 |
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel); |
| 4359 |
} else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) { |
| 4360 |
ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel); |
| 4361 |
ast_hangup(chan); |
| 4362 |
} |
| 4363 |
} |
| 4364 |
ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 4365 |
break; |
| 4366 |
default: |
| 4367 |
ast_log(LOG_WARNING, |
| 4368 |
"handle_init_event detected dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) interface %d\n", |
| 4369 |
i->channel); |
| 4370 |
break; |
| 4371 |
} |
| 4372 |
break; |
| 4373 |
case ANALOG_EVENT_REMOVED: |
| 4374 |
ast_log(LOG_NOTICE, "Got ANALOG_EVENT_REMOVED. Destroying channel %d\n", |
| 4375 |
i->channel); |
| 4376 |
return i->chan_pvt; |
| 4377 |
case ANALOG_EVENT_NEONMWI_ACTIVE: |
| 4378 |
analog_handle_notify_message(NULL, i, -1, ANALOG_EVENT_NEONMWI_ACTIVE); |
| 4379 |
break; |
| 4380 |
case ANALOG_EVENT_NEONMWI_INACTIVE: |
| 4381 |
analog_handle_notify_message(NULL, i, -1, ANALOG_EVENT_NEONMWI_INACTIVE); |
| 4382 |
break; |
| 4383 |
} |
| 4384 |
return NULL; |
| 4385 |
} |
| 4386 |
|
| 4387 |
|
| 4388 |
struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data) |
| 4389 |
{ |
| 4390 |
struct analog_pvt *p; |
| 4391 |
|
| 4392 |
p = ast_calloc(1, sizeof(*p)); |
| 4393 |
if (!p) { |
| 4394 |
return p; |
| 4395 |
} |
| 4396 |
|
| 4397 |
p->outsigmod = ANALOG_SIG_NONE; |
| 4398 |
p->sig = signallingtype; |
| 4399 |
p->chan_pvt = private_data; |
| 4400 |
|
| 4401 |
|
| 4402 |
p->cid_start = ANALOG_CID_START_RING; |
| 4403 |
p->cid_signalling = CID_SIG_BELL; |
| 4404 |
|
| 4405 |
p->subs[ANALOG_SUB_REAL].allocd = 1; |
| 4406 |
|
| 4407 |
return p; |
| 4408 |
} |
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
void analog_delete(struct analog_pvt *doomed) |
| 4417 |
{ |
| 4418 |
ast_free(doomed); |
| 4419 |
} |
| 4420 |
|
| 4421 |
int analog_config_complete(struct analog_pvt *p) |
| 4422 |
{ |
| 4423 |
|
| 4424 |
if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) { |
| 4425 |
p->permcallwaiting = 0; |
| 4426 |
} |
| 4427 |
|
| 4428 |
analog_set_callwaiting(p, p->permcallwaiting); |
| 4429 |
|
| 4430 |
return 0; |
| 4431 |
} |
| 4432 |
|
| 4433 |
void analog_free(struct analog_pvt *p) |
| 4434 |
{ |
| 4435 |
ast_free(p); |
| 4436 |
} |
| 4437 |
|
| 4438 |
|
| 4439 |
int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp) |
| 4440 |
{ |
| 4441 |
struct analog_pvt *new_pvt = newp; |
| 4442 |
int x; |
| 4443 |
ast_debug(1, "New owner for channel %d is %s\n", new_pvt->channel, ast_channel_name(newchan)); |
| 4444 |
if (new_pvt->owner == oldchan) { |
| 4445 |
analog_set_new_owner(new_pvt, newchan); |
| 4446 |
} |
| 4447 |
for (x = 0; x < 3; x++) { |
| 4448 |
if (new_pvt->subs[x].owner == oldchan) { |
| 4449 |
new_pvt->subs[x].owner = newchan; |
| 4450 |
} |
| 4451 |
} |
| 4452 |
|
| 4453 |
analog_update_conf(new_pvt); |
| 4454 |
return 0; |
| 4455 |
} |
| 4456 |
|
| 4457 |
static void analog_publish_dnd_state(int channel, const char *status) |
| 4458 |
{ |
| 4459 |
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); |
| 4460 |
RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free); |
| 4461 |
if (!dahdichan) { |
| 4462 |
return; |
| 4463 |
} |
| 4464 |
|
| 4465 |
ast_str_set(&dahdichan, 0, "DAHDI/%d", channel); |
| 4466 |
|
| 4467 |
body = ast_json_pack("{s: s, s: s}", |
| 4468 |
"Channel", ast_str_buffer(dahdichan), |
| 4469 |
"Status", status); |
| 4470 |
if (!body) { |
| 4471 |
return; |
| 4472 |
} |
| 4473 |
|
| 4474 |
ast_manager_publish_event("DNDState", EVENT_FLAG_SYSTEM, body); |
| 4475 |
} |
| 4476 |
|
| 4477 |
int analog_dnd(struct analog_pvt *p, int flag) |
| 4478 |
{ |
| 4479 |
if (flag == -1) { |
| 4480 |
return p->dnd; |
| 4481 |
} |
| 4482 |
|
| 4483 |
p->dnd = flag; |
| 4484 |
|
| 4485 |
ast_verb(3, "%s DND on channel %d\n", |
| 4486 |
flag ? "Enabled" : "Disabled", |
| 4487 |
p->channel); |
| 4488 |
analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled"); |
| 4489 |
|
| 4490 |
return 0; |
| 4491 |
} |