Asterisk - The Open Source Telephony Project  18.5.0
sig_ss7.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2010 Digium, Inc.
5  *
6  * Richard Mudgett <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*!
20  * \file
21  * \brief SS7 signaling module.
22  *
23  * \author Matthew Fredrickson <[email protected]>
24  * \author Richard Mudgett <[email protected]>
25  *
26  * See Also:
27  * \arg \ref AstCREDITS
28  */
29 
30 /*** MODULEINFO
31  <support_level>core</support_level>
32  ***/
33 
34 #include "asterisk.h"
35 
36 #if defined(HAVE_SS7)
37 
38 #include <signal.h>
39 
40 #include "asterisk/pbx.h"
41 #include "asterisk/causes.h"
42 #include "asterisk/musiconhold.h"
43 #include "asterisk/cli.h"
44 #include "asterisk/callerid.h"
45 #include "asterisk/transcap.h"
47 
48 #include "sig_ss7.h"
49 #if !defined(LIBSS7_ABI_COMPATIBILITY)
50 #error "Upgrade your libss7"
51 #elif LIBSS7_ABI_COMPATIBILITY != 2
52 #error "Your installed libss7 is not compatible"
53 #endif
54 
55 /* ------------------------------------------------------------------- */
56 
57 static const char *sig_ss7_call_level2str(enum sig_ss7_call_level level)
58 {
59  switch (level) {
61  return "Idle";
63  return "Allocated";
65  return "Continuity";
67  return "Setup";
69  return "Proceeding";
71  return "Alerting";
73  return "Connect";
74  }
75  return "Unknown";
76 }
77 
78 static void sig_ss7_unlock_private(struct sig_ss7_chan *p)
79 {
82  }
83 }
84 
85 static void sig_ss7_lock_private(struct sig_ss7_chan *p)
86 {
89  }
90 }
91 
92 static void sig_ss7_deadlock_avoidance_private(struct sig_ss7_chan *p)
93 {
96  } else {
97  /* Fallback to the old way if callback not present. */
98  sig_ss7_unlock_private(p);
99  sched_yield();
100  sig_ss7_lock_private(p);
101  }
102 }
103 
104 void sig_ss7_set_alarm(struct sig_ss7_chan *p, int in_alarm)
105 {
106  p->inalarm = in_alarm;
108  sig_ss7_callbacks.set_alarm(p->chan_pvt, in_alarm);
109  }
110 }
111 
112 static void sig_ss7_set_dialing(struct sig_ss7_chan *p, int is_dialing)
113 {
115  sig_ss7_callbacks.set_dialing(p->chan_pvt, is_dialing);
116  }
117 }
118 
119 static void sig_ss7_set_digital(struct sig_ss7_chan *p, int is_digital)
120 {
122  sig_ss7_callbacks.set_digital(p->chan_pvt, is_digital);
123  }
124 }
125 
126 static void sig_ss7_set_outgoing(struct sig_ss7_chan *p, int is_outgoing)
127 {
128  p->outgoing = is_outgoing;
130  sig_ss7_callbacks.set_outgoing(p->chan_pvt, is_outgoing);
131  }
132 }
133 
134 static void sig_ss7_set_inservice(struct sig_ss7_chan *p, int is_inservice)
135 {
136  p->inservice = is_inservice;
138  sig_ss7_callbacks.set_inservice(p->chan_pvt, is_inservice);
139  }
140 }
141 
142 static void sig_ss7_set_locallyblocked(struct sig_ss7_chan *p, int is_blocked, int type)
143 {
144  if (is_blocked) {
145  p->locallyblocked |= type;
146  } else {
147  p->locallyblocked &= ~type;
148  }
149 
152  }
153 }
154 
155 static void sig_ss7_set_remotelyblocked(struct sig_ss7_chan *p, int is_blocked, int type)
156 {
157  if (is_blocked) {
158  p->remotelyblocked |= type;
159  } else {
160  p->remotelyblocked &= ~type;
161  }
162 
165  }
166 }
167 
168 /*!
169  * \internal
170  * \brief Open the SS7 channel media path.
171  * \since 1.8.12
172  *
173  * \param p Channel private control structure.
174  *
175  * \return Nothing
176  */
177 static void sig_ss7_open_media(struct sig_ss7_chan *p)
178 {
181  }
182 }
183 
184 /*!
185  * \internal
186  * \brief Set the caller id information in the parent module.
187  * \since 1.8
188  *
189  * \param p sig_ss7 channel structure.
190  *
191  * \return Nothing
192  */
193 static void sig_ss7_set_caller_id(struct sig_ss7_chan *p)
194 {
195  struct ast_party_caller caller;
196 
198  ast_party_caller_init(&caller);
199 
200  caller.id.name.str = p->cid_name;
201  caller.id.name.presentation = p->callingpres;
202  caller.id.name.valid = 1;
203 
204  caller.id.number.str = p->cid_num;
205  caller.id.number.plan = p->cid_ton;
206  caller.id.number.presentation = p->callingpres;
207  caller.id.number.valid = 1;
208 
209  if (!ast_strlen_zero(p->cid_subaddr)) {
210  caller.id.subaddress.valid = 1;
211  //caller.id.subaddress.type = 0;/* nsap */
212  //caller.id.subaddress.odd_even_indicator = 0;
213  caller.id.subaddress.str = p->cid_subaddr;
214  }
215 
216  caller.ani.number.str = p->cid_ani;
217  //caller.ani.number.plan = p->xxx;
218  //caller.ani.number.presentation = p->xxx;
219  caller.ani.number.valid = 1;
220 
221  caller.ani2 = p->cid_ani2;
223  }
224 }
225 
226 /*!
227  * \internal
228  * \brief Set the Dialed Number Identifier.
229  * \since 1.8
230  *
231  * \param p sig_ss7 channel structure.
232  * \param dnid Dialed Number Identifier string.
233  *
234  * \return Nothing
235  */
236 static void sig_ss7_set_dnid(struct sig_ss7_chan *p, const char *dnid)
237 {
240  }
241 }
242 
243 static int sig_ss7_play_tone(struct sig_ss7_chan *p, enum sig_ss7_tone tone)
244 {
245  int res;
246 
248  res = sig_ss7_callbacks.play_tone(p->chan_pvt, tone);
249  } else {
250  res = -1;
251  }
252  return res;
253 }
254 
255 static int sig_ss7_set_echocanceller(struct sig_ss7_chan *p, int enable)
256 {
258  return sig_ss7_callbacks.set_echocanceller(p->chan_pvt, enable);
259  }
260  return -1;
261 }
262 
263 static void sig_ss7_loopback(struct sig_ss7_chan *p, int enable)
264 {
265  if (p->loopedback != enable) {
266  p->loopedback = enable;
269  }
270  }
271 }
272 
273 static struct ast_channel *sig_ss7_new_ast_channel(struct sig_ss7_chan *p, int state,
274  int ulaw, int transfercapability, char *exten,
275  const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
276 {
277  struct ast_channel *ast;
278 
280  ast = sig_ss7_callbacks.new_ast_channel(p->chan_pvt, state, ulaw, exten,
281  assignedids, requestor);
282  } else {
283  return NULL;
284  }
285  if (!ast) {
286  return NULL;
287  }
288 
289  if (!p->owner) {
290  p->owner = ast;
291  }
292 
293  if (p->outgoing) {
294  p->do_hangup = SS7_HANGUP_FREE_CALL;
295  } else {
296  p->do_hangup = SS7_HANGUP_SEND_REL;
297  }
298 
299  ast_channel_transfercapability_set(ast, transfercapability);
300  pbx_builtin_setvar_helper(ast, "TRANSFERCAPABILITY",
301  ast_transfercapability2str(transfercapability));
302  if (transfercapability & AST_TRANS_CAP_DIGITAL) {
303  sig_ss7_set_digital(p, 1);
304  }
305 
306  return ast;
307 }
308 
309 static void sig_ss7_handle_link_exception(struct sig_ss7_linkset *linkset, int which)
310 {
313  }
314 }
315 
316 static struct sig_ss7_linkset *sig_ss7_find_linkset(struct ss7 *ss7)
317 {
319  return sig_ss7_callbacks.find_linkset(ss7);
320  }
321  return NULL;
322 }
323 
324 /*!
325  * \internal
326  * \brief Determine if a private channel structure is available.
327  *
328  * \param pvt Channel to determine if available.
329  *
330  * \return TRUE if the channel is available.
331  */
332 static int sig_ss7_is_chan_available(struct sig_ss7_chan *pvt)
333 {
334  if (pvt->inservice && !pvt->inalarm && !pvt->owner && !pvt->ss7call
336  && !pvt->locallyblocked && !pvt->remotelyblocked) {
337  return 1;
338  }
339  return 0;
340 }
341 
342 /*!
343  * \internal
344  * \brief Obtain the sig_ss7 owner channel lock if the owner exists.
345  * \since 1.8
346  *
347  * \param ss7 SS7 linkset control structure.
348  * \param chanpos Channel position in the span.
349  *
350  * \note Assumes the ss7->lock is already obtained.
351  * \note Assumes the sig_ss7_lock_private(ss7->pvts[chanpos]) is already obtained.
352  *
353  * \return Nothing
354  */
355 static void sig_ss7_lock_owner(struct sig_ss7_linkset *ss7, int chanpos)
356 {
357  for (;;) {
358  if (!ss7->pvts[chanpos]->owner) {
359  /* There is no owner lock to get. */
360  break;
361  }
362  if (!ast_channel_trylock(ss7->pvts[chanpos]->owner)) {
363  /* We got the lock */
364  break;
365  }
366 
367  /* Avoid deadlock */
368  sig_ss7_unlock_private(ss7->pvts[chanpos]);
369  DEADLOCK_AVOIDANCE(&ss7->lock);
370  sig_ss7_lock_private(ss7->pvts[chanpos]);
371  }
372 }
373 
374 /*!
375  * \internal
376  * \brief Queue the given frame onto the owner channel.
377  * \since 1.8
378  *
379  * \param ss7 SS7 linkset control structure.
380  * \param chanpos Channel position in the span.
381  * \param frame Frame to queue onto the owner channel.
382  *
383  * \note Assumes the ss7->lock is already obtained.
384  * \note Assumes the sig_ss7_lock_private(ss7->pvts[chanpos]) is already obtained.
385  *
386  * \return Nothing
387  */
388 static void sig_ss7_queue_frame(struct sig_ss7_linkset *ss7, int chanpos, struct ast_frame *frame)
389 {
390  sig_ss7_lock_owner(ss7, chanpos);
391  if (ss7->pvts[chanpos]->owner) {
392  ast_queue_frame(ss7->pvts[chanpos]->owner, frame);
393  ast_channel_unlock(ss7->pvts[chanpos]->owner);
394  }
395 }
396 
397 /*!
398  * \internal
399  * \brief Queue a control frame of the specified subclass onto the owner channel.
400  * \since 1.8
401  *
402  * \param ss7 SS7 linkset control structure.
403  * \param chanpos Channel position in the span.
404  * \param subclass Control frame subclass to queue onto the owner channel.
405  *
406  * \note Assumes the ss7->lock is already obtained.
407  * \note Assumes the sig_ss7_lock_private(ss7->pvts[chanpos]) is already obtained.
408  *
409  * \return Nothing
410  */
411 static void sig_ss7_queue_control(struct sig_ss7_linkset *ss7, int chanpos, int subclass)
412 {
413  struct ast_frame f = {AST_FRAME_CONTROL, };
414  struct sig_ss7_chan *p = ss7->pvts[chanpos];
415 
418  }
419 
420  f.subclass.integer = subclass;
421  sig_ss7_queue_frame(ss7, chanpos, &f);
422 }
423 
424 /*!
425  * \internal
426  * \brief Queue a PVT_CAUSE_CODE frame onto the owner channel.
427  * \since 11.0
428  *
429  * \param owner Owner channel of the pvt.
430  * \param cause String describing the cause to be placed into the frame.
431  *
432  * \note Assumes the linkset->lock is already obtained.
433  * \note Assumes the sig_ss7_lock_private(linkset->pvts[chanpos]) is already obtained.
434  * \note Assumes linkset->pvts[chanpos]->owner is non-NULL and its lock is already obtained.
435  *
436  * \return Nothing
437  */
438 static void ss7_queue_pvt_cause_data(struct ast_channel *owner, const char *cause, int ast_cause)
439 {
440  struct ast_control_pvt_cause_code *cause_code;
441  int datalen = sizeof(*cause_code) + strlen(cause);
442 
443  cause_code = ast_alloca(datalen);
444  memset(cause_code, 0, datalen);
445  cause_code->ast_cause = ast_cause;
447  ast_copy_string(cause_code->code, cause, datalen + 1 - sizeof(*cause_code));
448  ast_queue_control_data(owner, AST_CONTROL_PVT_CAUSE_CODE, cause_code, datalen);
449  ast_channel_hangupcause_hash_set(owner, cause_code, datalen);
450 }
451 
452 
453 /*!
454  * \brief Find the channel position by CIC/DPC.
455  *
456  * \param linkset SS7 linkset control structure.
457  * \param cic Circuit Identification Code
458  * \param dpc Destination Point Code
459  *
460  * \retval chanpos on success.
461  * \retval -1 on error.
462  */
463 int sig_ss7_find_cic(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc)
464 {
465  int i;
466  int winner = -1;
467  for (i = 0; i < linkset->numchans; i++) {
468  if (linkset->pvts[i] && (linkset->pvts[i]->dpc == dpc && linkset->pvts[i]->cic == cic)) {
469  winner = i;
470  break;
471  }
472  }
473  return winner;
474 }
475 
476 /*!
477  * \internal
478  * \brief Find the channel position by CIC/DPC and gripe if not found.
479  *
480  * \param linkset SS7 linkset control structure.
481  * \param cic Circuit Identification Code
482  * \param dpc Destination Point Code
483  * \param msg_name Message type name that failed.
484  *
485  * \retval chanpos on success.
486  * \retval -1 on error.
487  */
488 static int ss7_find_cic_gripe(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc, const char *msg_name)
489 {
490  int chanpos;
491 
492  chanpos = sig_ss7_find_cic(linkset, cic, dpc);
493  if (chanpos < 0) {
494  ast_log(LOG_WARNING, "Linkset %d: SS7 %s requested on unconfigured CIC/DPC %d/%d.\n",
495  linkset->span, msg_name, cic, dpc);
496  return -1;
497  }
498  return chanpos;
499 }
500 
501 static struct sig_ss7_chan *ss7_find_pvt(struct ss7 *ss7, int cic, unsigned int dpc)
502 {
503  int chanpos;
504  struct sig_ss7_linkset *winner;
505 
506  winner = sig_ss7_find_linkset(ss7);
507  if (winner && (chanpos = sig_ss7_find_cic(winner, cic, dpc)) > -1) {
508  return winner->pvts[chanpos];
509  }
510  return NULL;
511 }
512 
513 int sig_ss7_cb_hangup(struct ss7 *ss7, int cic, unsigned int dpc, int cause, int do_hangup)
514 {
515  struct sig_ss7_chan *p;
516  int res;
517 
518  if (!(p = ss7_find_pvt(ss7, cic, dpc))) {
519  return SS7_CIC_NOT_EXISTS;
520  }
521 
522  sig_ss7_lock_private(p);
523  if (p->owner) {
526  p->do_hangup = do_hangup;
527  res = SS7_CIC_USED;
528  } else {
529  res = SS7_CIC_IDLE;
530  }
531  sig_ss7_unlock_private(p);
532 
533  return res;
534 }
535 
536 void sig_ss7_cb_call_null(struct ss7 *ss7, struct isup_call *call, int lock)
537 {
538  int i;
539  struct sig_ss7_linkset *winner;
540 
541  winner = sig_ss7_find_linkset(ss7);
542  if (!winner) {
543  return;
544  }
545  for (i = 0; i < winner->numchans; i++) {
546  if (winner->pvts[i] && (winner->pvts[i]->ss7call == call)) {
547  if (lock) {
548  sig_ss7_lock_private(winner->pvts[i]);
549  }
550  winner->pvts[i]->ss7call = NULL;
551  if (winner->pvts[i]->owner) {
554  }
555  if (lock) {
556  sig_ss7_unlock_private(winner->pvts[i]);
557  }
558  ast_log(LOG_WARNING, "libss7 asked set ss7 call to NULL on CIC %d DPC %d\n", winner->pvts[i]->cic, winner->pvts[i]->dpc);
559  }
560  }
561 }
562 
563 void sig_ss7_cb_notinservice(struct ss7 *ss7, int cic, unsigned int dpc)
564 {
565  struct sig_ss7_chan *p;
566 
567  if (!(p = ss7_find_pvt(ss7, cic, dpc))) {
568  return;
569  }
570 
571  sig_ss7_lock_private(p);
572  sig_ss7_set_inservice(p, 0);
573  sig_ss7_unlock_private(p);
574 }
575 
576 /*!
577  * \internal
578  * \brief Check if CICs in a range belong to the linkset for a given DPC.
579  * \since 11.0
580  *
581  * \param linkset SS7 linkset control structure.
582  * \param startcic Circuit Identification Code to start from
583  * \param endcic Circuit Identification Code to search up-to
584  * \param dpc Destination Point Code
585  * \param state Array containing the status of the search
586  *
587  * \retval Nothing.
588  */
589 static void ss7_check_range(struct sig_ss7_linkset *linkset, int startcic, int endcic, unsigned int dpc, unsigned char *state)
590 {
591  int cic;
592 
593  for (cic = startcic; cic <= endcic; cic++) {
594  if (state[cic - startcic] && sig_ss7_find_cic(linkset, cic, dpc) == -1) {
595  state[cic - startcic] = 0;
596  }
597  }
598 }
599 
600 static int ss7_match_range(struct sig_ss7_chan *pvt, int startcic, int endcic, unsigned int dpc)
601 {
602  if (pvt && pvt->dpc == dpc && pvt->cic >= startcic && pvt->cic <= endcic) {
603  return 1;
604  }
605 
606  return 0;
607 }
608 
609 /*!
610  * \internal
611  * \brief Check if a range is defined for the given DPC.
612  * \since 11.0
613  *
614  * \param linkset SS7 linkset control structure.
615  * \param startcic Start CIC of the range to clear.
616  * \param endcic End CIC of the range to clear.
617  * \param dpc Destination Point Code.
618  *
619  * \note Assumes the linkset->lock is already obtained.
620  *
621  * \return TRUE if all CICs in the range are present
622  */
623 int sig_ss7_find_cic_range(struct sig_ss7_linkset *linkset, int startcic, int endcic, unsigned int dpc)
624 {
625  int i, found = 0;
626 
627  for (i = 0; i < linkset->numchans; i++) {
628  if (ss7_match_range(linkset->pvts[i], startcic, endcic, dpc)) {
629  found++;
630  }
631  }
632 
633  if (found == endcic - startcic + 1) {
634  return 1;
635  }
636 
637  return 0;
638 }
639 
640 static void ss7_handle_cqm(struct sig_ss7_linkset *linkset, ss7_event *e)
641 {
642  unsigned char status[32];
643  struct sig_ss7_chan *p = NULL;
644  int i;
645  int offset;
646  int chanpos;
647 
648  memset(status, 0, sizeof(status));
649  for (i = 0; i < linkset->numchans; i++) {
650  if (ss7_match_range(linkset->pvts[i], e->cqm.startcic, e->cqm.endcic, e->cqm.opc)) {
651  p = linkset->pvts[i];
652  sig_ss7_lock_private(p);
653  offset = p->cic - e->cqm.startcic;
654  status[offset] = 0;
655  if (p->locallyblocked) {
656  status[offset] |= (1 << 0) | (1 << 4);
657  }
658  if (p->remotelyblocked) {
659  status[offset] |= (1 << 1) | (1 << 5);
660  }
661  if (p->ss7call) {
662  if (p->outgoing) {
663  status[offset] |= (1 << 3);
664  } else {
665  status[offset] |= (1 << 2);
666  }
667  } else {
668  status[offset] |= 0x3 << 2;
669  }
670  sig_ss7_unlock_private(p);
671  }
672  }
673 
674  if (p) {
675  isup_cqr(linkset->ss7, e->cqm.startcic, e->cqm.endcic, e->cqm.opc, status);
676  } else {
677  ast_log(LOG_WARNING, "Could not find any equipped circuits within CQM CICs\n");
678  }
679 
680  chanpos = sig_ss7_find_cic(linkset, e->cqm.startcic, e->cqm.opc);
681  if (chanpos < 0) {
682  isup_free_call(linkset->ss7, e->cqm.call);
683  return;
684  }
685  p = linkset->pvts[chanpos];
686  sig_ss7_lock_private(p);
687  p->ss7call = e->cqm.call;
688  if (!p->owner) {
689  p->ss7call = isup_free_call_if_clear(linkset->ss7, e->cqm.call);
690  }
691  sig_ss7_unlock_private(p);
692 }
693 
694 static inline void ss7_hangup_cics(struct sig_ss7_linkset *linkset, int startcic, int endcic, unsigned int dpc)
695 {
696  int i;
697 
698  for (i = 0; i < linkset->numchans; i++) {
699  if (ss7_match_range(linkset->pvts[i], startcic, endcic, dpc)) {
700  sig_ss7_lock_private(linkset->pvts[i]);
701  sig_ss7_lock_owner(linkset, i);
702  if (linkset->pvts[i]->owner) {
704  ast_channel_unlock(linkset->pvts[i]->owner);
705  }
706  sig_ss7_unlock_private(linkset->pvts[i]);
707  }
708  }
709 }
710 
711 /*!
712  * \param linkset SS7 linkset control structure.
713  * \param startcic Start CIC of the range to clear.
714  * \param endcic End CIC of the range to clear.
715  * \param dpc Destination Point Code.
716  * \param state Affected CICs from the operation. NULL for all CICs in the range.
717  * \param block Operation to perform. TRUE to block.
718  * \param remotely Direction of the blocking. TRUE to block/unblock remotely.
719  * \param type Blocking type - hardware or maintenance.
720  *
721  * \note Assumes the linkset->lock is already obtained.
722  * \note Must be called without sig_ss7_lock_private() obtained.
723  *
724  * \return Nothing.
725  */
726 static inline void ss7_block_cics(struct sig_ss7_linkset *linkset, int startcic, int endcic, unsigned int dpc, unsigned char state[], int block, int remotely, int type)
727 {
728  int i;
729 
730  for (i = 0; i < linkset->numchans; i++) {
731  if (ss7_match_range(linkset->pvts[i], startcic, endcic, dpc)) {
732  sig_ss7_lock_private(linkset->pvts[i]);
733  if (state) {
734  if (state[linkset->pvts[i]->cic - startcic]) {
735 
736  if (remotely) {
737  sig_ss7_set_remotelyblocked(linkset->pvts[i], block, type);
738  } else {
739  sig_ss7_set_locallyblocked(linkset->pvts[i], block, type);
740  }
741 
742  sig_ss7_lock_owner(linkset, i);
743  if (linkset->pvts[i]->owner) {
744  if (ast_channel_state(linkset->pvts[i]->owner) == AST_STATE_DIALING
745  && linkset->pvts[i]->call_level < SIG_SS7_CALL_LEVEL_PROCEEDING) {
746  ast_channel_hangupcause_set(linkset->pvts[i]->owner, SS7_CAUSE_TRY_AGAIN);
747  }
748  ast_channel_unlock(linkset->pvts[i]->owner);
749  }
750  }
751  } else {
752  if (remotely) {
753  sig_ss7_set_remotelyblocked(linkset->pvts[i], block, type);
754  } else {
755  sig_ss7_set_locallyblocked(linkset->pvts[i], block, type);
756  }
757  }
758  sig_ss7_unlock_private(linkset->pvts[i]);
759  }
760  }
761 }
762 
763 /*!
764  * \param linkset SS7 linkset control structure.
765  * \param startcic Start CIC of the range to set in service.
766  * \param endcic End CIC of the range to set in service.
767  * \param dpc Destination Point Code.
768  *
769  * \note Must be called without sig_ss7_lock_private() obtained.
770  *
771  * \return Nothing.
772  */
773 static void ss7_inservice(struct sig_ss7_linkset *linkset, int startcic, int endcic, unsigned int dpc)
774 {
775  int i;
776 
777  for (i = 0; i < linkset->numchans; i++) {
778  if (ss7_match_range(linkset->pvts[i], startcic, endcic, dpc)) {
779  sig_ss7_lock_private(linkset->pvts[i]);
780  sig_ss7_set_inservice(linkset->pvts[i], 1);
781  sig_ss7_unlock_private(linkset->pvts[i]);
782  }
783  }
784 }
785 
786 static int ss7_find_alloc_call(struct sig_ss7_chan *p)
787 {
788  if (!p) {
789  return 0;
790  }
791 
792  if (!p->ss7call) {
793  p->ss7call = isup_new_call(p->ss7->ss7, p->cic, p->dpc, 0);
794  if (!p->ss7call) {
795  return 0;
796  }
797  }
798  return 1;
799 }
800 
801 /*
802  * XXX This routine is not tolerant of holes in the pvts[] array.
803  * XXX This routine assumes the cic's in the pvts[] array are sorted.
804  *
805  * Probably the easiest way to deal with the invalid assumptions
806  * is to have a local pvts[] array and sort it by dpc and cic.
807  * Then the existing algorithm could work.
808  */
809 static void ss7_reset_linkset(struct sig_ss7_linkset *linkset)
810 {
811  int i, startcic, endcic, dpc;
812  struct sig_ss7_chan *p;
813 
814  if (linkset->numchans <= 0) {
815  return;
816  }
817 
818  startcic = linkset->pvts[0]->cic;
819  p = linkset->pvts[0];
820  /* DB: CIC's DPC fix */
821  dpc = linkset->pvts[0]->dpc;
822 
823  for (i = 0; i < linkset->numchans; i++) {
824  if (linkset->pvts[i+1]
825  && linkset->pvts[i+1]->dpc == dpc
826  && linkset->pvts[i+1]->cic - linkset->pvts[i]->cic == 1
827  && linkset->pvts[i]->cic - startcic < (linkset->type == SS7_ANSI ? 24 : 31)) {
828  continue;
829  } else {
830  endcic = linkset->pvts[i]->cic;
831  ast_verb(1, "Resetting CICs %d to %d\n", startcic, endcic);
832 
833  sig_ss7_lock_private(p);
834  if (!ss7_find_alloc_call(p)) {
835  ast_log(LOG_ERROR, "Unable to allocate new ss7call\n");
836  } else if (!(endcic - startcic)) { /* GRS range can not be 0 - use RSC instead */
837  isup_rsc(linkset->ss7, p->ss7call);
838  } else {
839  isup_grs(linkset->ss7, p->ss7call, endcic);
840  }
841  sig_ss7_unlock_private(p);
842 
843  /* DB: CIC's DPC fix */
844  if (linkset->pvts[i+1]) {
845  startcic = linkset->pvts[i+1]->cic;
846  dpc = linkset->pvts[i+1]->dpc;
847  p = linkset->pvts[i+1];
848  }
849  }
850  }
851 }
852 
853 /*!
854  * \internal
855  * \brief Complete the RSC procedure started earlier
856  * \since 11.0
857  *
858  * \param p Signaling private structure pointer.
859  *
860  * \note Assumes the ss7->lock is already obtained.
861  * \note Assumes sig_ss7_lock_private(p) is already obtained.
862  *
863  * \return Nothing.
864  */
865 static void ss7_do_rsc(struct sig_ss7_chan *p)
866 {
867  if (!p || !p->ss7call) {
868  return;
869  }
870 
871  isup_rsc(p->ss7->ss7, p->ss7call);
872 
874  isup_blo(p->ss7->ss7, p->ss7call);
875  } else {
876  sig_ss7_set_locallyblocked(p, 0, SS7_BLOCKED_MAINTENANCE | SS7_BLOCKED_HARDWARE);
877  }
878 }
879 
880 /*!
881  * \internal
882  * \brief Start RSC procedure on a specific link
883  * \since 11.0
884  *
885  * \param ss7 SS7 linkset control structure.
886  * \param which Channel position in the span.
887  *
888  * \note Assumes the ss7->lock is already obtained.
889  * \note Assumes the sig_ss7_lock_private(ss7->pvts[chanpos]) is already obtained.
890  *
891  * \return TRUE on success
892  */
893 static int ss7_start_rsc(struct sig_ss7_linkset *linkset, int which)
894 {
895  if (!linkset->pvts[which]) {
896  return 0;
897  }
898 
899  if (!ss7_find_alloc_call(linkset->pvts[which])) {
900  return 0;
901  }
902 
903  sig_ss7_set_remotelyblocked(linkset->pvts[which], 0, SS7_BLOCKED_MAINTENANCE | SS7_BLOCKED_HARDWARE);
904  sig_ss7_set_inservice(linkset->pvts[which], 0);
905  sig_ss7_loopback(linkset->pvts[which], 0);
906 
907  sig_ss7_lock_owner(linkset, which);
908  if (linkset->pvts[which]->owner) {
911  ast_channel_unlock(linkset->pvts[which]->owner);
912  linkset->pvts[which]->do_hangup = SS7_HANGUP_SEND_RSC;
913  } else {
914  ss7_do_rsc(linkset->pvts[which]);
915  }
916 
917  return 1;
918 }
919 
920 /*!
921  * \internal
922  * \brief Determine if a private channel structure is available.
923  * \since 11.0
924  *
925  * \param linkset SS7 linkset control structure.
926  * \param startcic Start CIC of the range to clear.
927  * \param endcic End CIC of the range to clear.
928  * \param dpc Destination Point Code.
929  * \param do_hangup What we have to do to clear the call.
930  *
931  * \note Assumes the linkset->lock is already obtained.
932  * \note Must be called without sig_ss7_lock_private() obtained.
933  *
934  * \return Nothing.
935  */
936 static void ss7_clear_channels(struct sig_ss7_linkset *linkset, int startcic, int endcic, int dpc, int do_hangup)
937 {
938  int i;
939 
940  for (i = 0; i < linkset->numchans; i++) {
941  if (ss7_match_range(linkset->pvts[i], startcic, endcic, dpc)) {
942  sig_ss7_lock_private(linkset->pvts[i]);
943  sig_ss7_set_inservice(linkset->pvts[i], 0);
944  sig_ss7_lock_owner(linkset, i);
945  if (linkset->pvts[i]->owner) {
949  ast_channel_unlock(linkset->pvts[i]->owner);
950  linkset->pvts[i]->do_hangup = (linkset->pvts[i]->cic != startcic) ?
951  do_hangup : SS7_HANGUP_DO_NOTHING;
952  } else if (linkset->pvts[i] && linkset->pvts[i]->cic != startcic) {
953  isup_free_call(linkset->pvts[i]->ss7->ss7, linkset->pvts[i]->ss7call);
954  linkset->pvts[i]->ss7call = NULL;
955  }
956  sig_ss7_unlock_private(linkset->pvts[i]);
957  }
958  }
959 }
960 
961 /*!
962  * \internal
963  *
964  * \param p Signaling private structure pointer.
965  * \param linkset SS7 linkset control structure.
966  *
967  * \note Assumes the linkset->lock is already obtained.
968  * \note Assumes the sig_ss7_lock_private(ss7->pvts[chanpos]) is already obtained.
969  *
970  * \return Nothing.
971  */
972 static void ss7_start_call(struct sig_ss7_chan *p, struct sig_ss7_linkset *linkset)
973 {
974  struct ss7 *ss7 = linkset->ss7;
975  int law;
976  struct ast_channel *c;
977  char tmp[256];
978  char *strp;
979  ast_callid callid = 0;
980  int callid_created = ast_callid_threadstorage_auto(&callid);
981 
982  if (!(linkset->flags & LINKSET_FLAG_EXPLICITACM)) {
984  isup_acm(ss7, p->ss7call);
985  } else {
987  }
988 
989  /* Companding law is determined by SS7 signaling type. */
990  if (linkset->type == SS7_ITU) {
991  law = SIG_SS7_ALAW;
992  } else {
993  law = SIG_SS7_ULAW;
994  }
995 
996  isup_set_echocontrol(p->ss7call, (linkset->flags & LINKSET_FLAG_DEFAULTECHOCONTROL) ? 1 : 0);
997 
998  /*
999  * Release the SS7 lock while we create the channel so other
1000  * threads can send messages. We must also release the private
1001  * lock to prevent deadlock while creating the channel.
1002  */
1003  ast_mutex_unlock(&linkset->lock);
1004  sig_ss7_unlock_private(p);
1005  c = sig_ss7_new_ast_channel(p, AST_STATE_RING, law, 0, p->exten, NULL, NULL);
1006  if (!c) {
1007  ast_log(LOG_WARNING, "Unable to start PBX on CIC %d\n", p->cic);
1008  ast_mutex_lock(&linkset->lock);
1009  sig_ss7_lock_private(p);
1010  isup_rel(linkset->ss7, p->ss7call, AST_CAUSE_SWITCH_CONGESTION);
1012  ast_callid_threadstorage_auto_clean(callid, callid_created);
1013  return;
1014  }
1015 
1016  /* Hold the channel and private lock while we setup the channel. */
1017  ast_channel_lock(c);
1018  sig_ss7_lock_private(p);
1019 
1021 
1022  /*
1023  * It is reasonably safe to set the following
1024  * channel variables while the channel private
1025  * structure is locked. The PBX has not been
1026  * started yet and it is unlikely that any other task
1027  * will do anything with the channel we have just
1028  * created.
1029  *
1030  * We only reference these variables in the context of the ss7_linkset function
1031  * when receiving either and IAM or a COT message.
1032  */
1033  if (!ast_strlen_zero(p->charge_number)) {
1034  pbx_builtin_setvar_helper(c, "SS7_CHARGE_NUMBER", p->charge_number);
1035  /* Clear this after we set it */
1036  p->charge_number[0] = 0;
1037  }
1038  if (!ast_strlen_zero(p->gen_add_number)) {
1039  pbx_builtin_setvar_helper(c, "SS7_GENERIC_ADDRESS", p->gen_add_number);
1040  /* Clear this after we set it */
1041  p->gen_add_number[0] = 0;
1042  }
1043  if (!ast_strlen_zero(p->jip_number)) {
1044  pbx_builtin_setvar_helper(c, "SS7_JIP", p->jip_number);
1045  /* Clear this after we set it */
1046  p->jip_number[0] = 0;
1047  }
1048  if (!ast_strlen_zero(p->gen_dig_number)) {
1049  pbx_builtin_setvar_helper(c, "SS7_GENERIC_DIGITS", p->gen_dig_number);
1050  /* Clear this after we set it */
1051  p->gen_dig_number[0] = 0;
1052  }
1053 
1054  snprintf(tmp, sizeof(tmp), "%d", p->gen_dig_type);
1055  pbx_builtin_setvar_helper(c, "SS7_GENERIC_DIGTYPE", tmp);
1056  /* Clear this after we set it */
1057  p->gen_dig_type = 0;
1058 
1059  snprintf(tmp, sizeof(tmp), "%d", p->gen_dig_scheme);
1060  pbx_builtin_setvar_helper(c, "SS7_GENERIC_DIGSCHEME", tmp);
1061  /* Clear this after we set it */
1062  p->gen_dig_scheme = 0;
1063 
1064  if (!ast_strlen_zero(p->lspi_ident)) {
1065  pbx_builtin_setvar_helper(c, "SS7_LSPI_IDENT", p->lspi_ident);
1066  /* Clear this after we set it */
1067  p->lspi_ident[0] = 0;
1068  }
1069 
1070  snprintf(tmp, sizeof(tmp), "%d", p->call_ref_ident);
1071  pbx_builtin_setvar_helper(c, "SS7_CALLREF_IDENT", tmp);
1072  /* Clear this after we set it */
1073  p->call_ref_ident = 0;
1074 
1075  snprintf(tmp, sizeof(tmp), "%d", p->call_ref_pc);
1076  pbx_builtin_setvar_helper(c, "SS7_CALLREF_PC", tmp);
1077  /* Clear this after we set it */
1078  p->call_ref_pc = 0;
1079 
1080  snprintf(tmp, sizeof(tmp), "%d", p->calling_party_cat);
1081  pbx_builtin_setvar_helper(c, "SS7_CALLING_PARTY_CATEGORY", tmp);
1082  /* Clear this after we set it */
1083  p->calling_party_cat = 0;
1084 
1085  if (p->redirect_counter) {
1086  struct ast_party_redirecting redirecting;
1087 
1088  switch (p->redirect_info_ind) {
1089  case 0:
1090  strp = "NO_REDIRECTION";
1091  break;
1092  case 1:
1093  strp = "CALL_REROUTED_PRES_ALLOWED";
1094  break;
1095  case 2:
1096  strp = "CALL_REROUTED_INFO_RESTRICTED";
1097  break;
1098  case 3:
1099  strp = "CALL_DIVERTED_PRES_ALLOWED";
1100  break;
1101  case 4:
1102  strp = "CALL_DIVERTED_INFO_RESTRICTED";
1103  break;
1104  case 5:
1105  strp = "CALL_REROUTED_PRES_RESTRICTED";
1106  break;
1107  case 6:
1108  strp = "CALL_DIVERTED_PRES_RESTRICTED";
1109  break;
1110  case 7:
1111  strp = "SPARE";
1112  break;
1113  default:
1114  strp = "NO_REDIRECTION";
1115  break;
1116  }
1117  pbx_builtin_setvar_helper(c, "SS7_REDIRECT_INFO_IND", strp);
1118  /* Clear this after we set it */
1119  p->redirect_info_ind = 0;
1120 
1121  ast_party_redirecting_init(&redirecting);
1122 
1123  if (p->redirect_info_counter) {
1124  redirecting.count = p->redirect_info_counter;
1125  if (p->redirect_info_counter != p->redirect_counter) {
1127  redirecting.count = p->redirect_counter;
1128  }
1129  ast_log(LOG_WARNING, "Redirect counters differ: %u while info says %u - using %u\n",
1130  p->redirect_counter, p->redirect_info_counter, redirecting.count);
1131  }
1132  /* Clear this after we set it */
1133  p->redirect_info_counter = 0;
1134  p->redirect_counter = 0;
1135  }
1136 
1137  if (p->redirect_counter) {
1138  redirecting.count = p->redirect_counter;
1139  /* Clear this after we set it */
1140  p->redirect_counter = 0;
1141  }
1142 
1143  switch (p->redirect_info_orig_reas) {
1145  redirecting.orig_reason.code = AST_REDIRECTING_REASON_UNKNOWN;
1146  break;
1148  redirecting.orig_reason.code = AST_REDIRECTING_REASON_USER_BUSY;
1149  break;
1151  redirecting.orig_reason.code = AST_REDIRECTING_REASON_NO_ANSWER;
1152  break;
1154  redirecting.orig_reason.code = AST_REDIRECTING_REASON_UNCONDITIONAL;
1155  break;
1156  default:
1157  redirecting.orig_reason.code = AST_REDIRECTING_REASON_UNKNOWN;
1158  break;
1159  }
1160 
1161  switch (p->redirect_info_reas) {
1163  redirecting.reason.code = AST_REDIRECTING_REASON_UNKNOWN;
1164  break;
1166  redirecting.reason.code = AST_REDIRECTING_REASON_USER_BUSY;
1167  if (!p->redirect_info_orig_reas && redirecting.count == 1) {
1168  redirecting.orig_reason.code = AST_REDIRECTING_REASON_USER_BUSY;
1169  }
1170  break;
1172  redirecting.reason.code = AST_REDIRECTING_REASON_NO_ANSWER;
1173  if (!p->redirect_info_orig_reas && redirecting.count == 1) {
1174  redirecting.orig_reason.code = AST_REDIRECTING_REASON_NO_ANSWER;
1175  }
1176  break;
1178  redirecting.reason.code = AST_REDIRECTING_REASON_UNCONDITIONAL;
1179  if (!p->redirect_info_orig_reas && redirecting.count == 1) {
1180  redirecting.orig_reason.code = AST_REDIRECTING_REASON_UNCONDITIONAL;
1181  }
1182  break;
1185  redirecting.reason.code = AST_REDIRECTING_REASON_DEFLECTION;
1186  break;
1188  redirecting.reason.code = AST_REDIRECTING_REASON_UNAVAILABLE;
1189  break;
1190  default:
1191  redirecting.reason.code = AST_REDIRECTING_REASON_UNKNOWN;
1192  break;
1193  }
1194  /* Clear this after we set it */
1195  p->redirect_info_orig_reas = 0;
1196  p->redirect_info_reas = 0;
1197 
1198  if (!ast_strlen_zero(p->redirecting_num)) {
1199  redirecting.from.number.str = ast_strdup(p->redirecting_num);
1200  redirecting.from.number.presentation = p->redirecting_presentation;
1201  redirecting.from.number.valid = 1;
1202  /* Clear this after we set it */
1203  p->redirecting_num[0] = 0;
1204  }
1205 
1206  if (!ast_strlen_zero(p->generic_name)) {
1207  redirecting.from.name.str = ast_strdup(p->generic_name);
1208  redirecting.from.name.presentation = p->redirecting_presentation;
1209  redirecting.from.name.valid = 1;
1210  /* Clear this after we set it */
1211  p->generic_name[0] = 0;
1212  }
1213 
1214  if (!ast_strlen_zero(p->orig_called_num)) {
1215  redirecting.orig.number.str = ast_strdup(p->orig_called_num);
1216  redirecting.orig.number.presentation = p->orig_called_presentation;
1217  redirecting.orig.number.valid = 1;
1218  /* Clear this after we set it */
1219  p->orig_called_num[0] = 0;
1220  } else if (redirecting.count == 1) {
1221  ast_party_id_copy(&redirecting.orig, &redirecting.from);
1222  }
1223 
1224  ast_channel_update_redirecting(c, &redirecting, NULL);
1225  ast_party_redirecting_free(&redirecting);
1226  }
1227 
1228  if (p->cug_indicator != ISUP_CUG_NON) {
1229  sprintf(tmp, "%d", p->cug_interlock_code);
1230  pbx_builtin_setvar_helper(c, "SS7_CUG_INTERLOCK_CODE", tmp);
1231 
1232  switch (p->cug_indicator) {
1233  case ISUP_CUG_NON:
1234  strp = "NON_CUG";
1235  break;
1236  case ISUP_CUG_OUTGOING_ALLOWED:
1237  strp = "OUTGOING_ALLOWED";
1238  break;
1239  case ISUP_CUG_OUTGOING_NOT_ALLOWED:
1240  strp = "OUTGOING_NOT_ALLOWED";
1241  break;
1242  default:
1243  strp = "SPARE";
1244  break;
1245  }
1246  pbx_builtin_setvar_helper(c, "SS7_CUG_INDICATOR", strp);
1247 
1248  if (!ast_strlen_zero(p->cug_interlock_ni)) {
1249  pbx_builtin_setvar_helper(c, "SS7_CUG_INTERLOCK_NI", p->cug_interlock_ni);
1250  }
1251 
1252  p->cug_indicator = ISUP_CUG_NON;
1253  }
1254 
1256 
1257  sig_ss7_unlock_private(p);
1258  ast_channel_unlock(c);
1259 
1260  if (ast_pbx_start(c)) {
1261  ast_log(LOG_WARNING, "Unable to start PBX on %s (CIC %d)\n", ast_channel_name(c), p->cic);
1262  ast_hangup(c);
1263  } else {
1264  ast_verb(3, "Accepting call to '%s' on CIC %d\n", p->exten, p->cic);
1265  }
1266 
1267  /* Must return with linkset and private lock. */
1268  ast_mutex_lock(&linkset->lock);
1269  sig_ss7_lock_private(p);
1270  ast_callid_threadstorage_auto_clean(callid, callid_created);
1271 }
1272 
1273 static void ss7_apply_plan_to_number(char *buf, size_t size, const struct sig_ss7_linkset *ss7, const char *number, const unsigned nai)
1274 {
1275  if (ast_strlen_zero(number)) { /* make sure a number exists so prefix isn't placed on an empty string */
1276  if (size) {
1277  *buf = '\0';
1278  }
1279  return;
1280  }
1281  switch (nai) {
1282  case SS7_NAI_INTERNATIONAL:
1283  snprintf(buf, size, "%s%s", ss7->internationalprefix, number);
1284  break;
1285  case SS7_NAI_NATIONAL:
1286  snprintf(buf, size, "%s%s", ss7->nationalprefix, number);
1287  break;
1288  case SS7_NAI_SUBSCRIBER:
1289  snprintf(buf, size, "%s%s", ss7->subscriberprefix, number);
1290  break;
1291  case SS7_NAI_UNKNOWN:
1292  snprintf(buf, size, "%s%s", ss7->unknownprefix, number);
1293  break;
1294  case SS7_NAI_NETWORKROUTED:
1295  snprintf(buf, size, "%s%s", ss7->networkroutedprefix, number);
1296  break;
1297  default:
1298  snprintf(buf, size, "%s", number);
1299  break;
1300  }
1301 }
1302 
1303 static int ss7_pres_scr2cid_pres(char presentation_ind, char screening_ind)
1304 {
1305  return ((presentation_ind & 0x3) << 5) | (screening_ind & 0x3);
1306 }
1307 
1308 /*!
1309  * \internal
1310  * \brief Set callid threadstorage for the ss7_linkset thread to that of an existing channel
1311  *
1312  * \param linkset ss7 span control structure.
1313  * \param chanpos channel position in the span
1314  *
1315  * \note Assumes the ss7->lock is already obtained.
1316  * \note Assumes the sig_ss7_lock_private(ss7->pvts[chanpos]) is already obtained.
1317  *
1318  * \return The callid bound to the channel which has also been bound to threadstorage
1319  * if it exists. If this returns non-zero, the threadstorage should be unbound
1320  * before the while loop wraps in ss7_linkset.
1321  */
1322 static ast_callid func_ss7_linkset_callid(struct sig_ss7_linkset *linkset, int chanpos)
1323 {
1324  ast_callid callid = 0;
1325  sig_ss7_lock_owner(linkset, chanpos);
1326  if (linkset->pvts[chanpos]->owner) {
1327  callid = ast_channel_callid(linkset->pvts[chanpos]->owner);
1328  ast_channel_unlock(linkset->pvts[chanpos]->owner);
1329  if (callid) {
1331  }
1332  }
1333 
1334  return callid;
1335 }
1336 
1337 /*!
1338  * \internal
1339  * \brief Proceed with the call based on the extension matching status
1340  * is matching in the dialplan.
1341  * \since 11.0
1342  *
1343  * \param linkset ss7 span control structure.
1344  * \param p Signaling private structure pointer.
1345  * \param e Event causing the match.
1346  *
1347  * \note Assumes the linkset->lock is already obtained.
1348  * \note Assumes the sig_ss7_lock_private(ss7->pvts[chanpos]) is already obtained.
1349  *
1350  * \return Nothing.
1351  */
1352 static void ss7_match_extension(struct sig_ss7_linkset *linkset, struct sig_ss7_chan *p, ss7_event *e)
1353 {
1354  ast_verb(3, "SS7 exten: %s complete: %d\n", p->exten, p->called_complete);
1355 
1356  if (!p->called_complete
1357  && linkset->type == SS7_ITU /* ANSI does not support overlap dialing. */
1358  && ast_matchmore_extension(NULL, p->context, p->exten, 1, p->cid_num)
1359  && !isup_start_digittimeout(linkset->ss7, p->ss7call)) {
1360  /* Wait for more digits. */
1361  return;
1362  }
1363  if (ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num)) {
1364  /* DNID is complete */
1365  p->called_complete = 1;
1366  sig_ss7_set_dnid(p, p->exten);
1367 
1368  /* If COT successful start call! */
1369  if ((e->e == ISUP_EVENT_IAM)
1370  ? !(e->iam.cot_check_required || e->iam.cot_performed_on_previous_cic)
1371  : (!(e->sam.cot_check_required || e->sam.cot_performed_on_previous_cic) || e->sam.cot_check_passed)) {
1372  ss7_start_call(p, linkset);
1373  }
1374  return;
1375  }
1376 
1377  ast_debug(1, "Call on CIC for unconfigured extension %s\n", p->exten);
1378  isup_rel(linkset->ss7, (e->e == ISUP_EVENT_IAM) ? e->iam.call : e->sam.call, AST_CAUSE_UNALLOCATED);
1379 }
1380 
1381 /* This is a thread per linkset that handles all received events from libss7. */
1382 void *ss7_linkset(void *data)
1383 {
1384  int res, i;
1385  struct timeval *next = NULL, tv;
1386  struct sig_ss7_linkset *linkset = (struct sig_ss7_linkset *) data;
1387  struct ss7 *ss7 = linkset->ss7;
1388  ss7_event *e = NULL;
1389  struct sig_ss7_chan *p;
1390  struct pollfd pollers[SIG_SS7_NUM_DCHANS];
1391  unsigned char mb_state[255];
1392  int nextms;
1393 
1394 #define SS7_MAX_POLL 60000 /* Maximum poll time in ms. */
1395 
1396  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
1397 
1398  ss7_set_debug(ss7, SIG_SS7_DEBUG_DEFAULT);
1399  ast_mutex_lock(&linkset->lock);
1400  ss7_start(ss7);
1401  ast_mutex_unlock(&linkset->lock);
1402 
1403  for (;;) {
1404  ast_mutex_lock(&linkset->lock);
1405  if ((next = ss7_schedule_next(ss7))) {
1406  tv = ast_tvnow();
1407  tv.tv_sec = next->tv_sec - tv.tv_sec;
1408  tv.tv_usec = next->tv_usec - tv.tv_usec;
1409  if (tv.tv_usec < 0) {
1410  tv.tv_usec += 1000000;
1411  tv.tv_sec -= 1;
1412  }
1413  if (tv.tv_sec < 0) {
1414  tv.tv_sec = 0;
1415  tv.tv_usec = 0;
1416  }
1417  nextms = tv.tv_sec * 1000;
1418  nextms += tv.tv_usec / 1000;
1419  if (SS7_MAX_POLL < nextms) {
1420  nextms = SS7_MAX_POLL;
1421  }
1422  } else {
1423  nextms = SS7_MAX_POLL;
1424  }
1425 
1426  for (i = 0; i < linkset->numsigchans; i++) {
1427  pollers[i].fd = linkset->fds[i];
1428  pollers[i].events = ss7_pollflags(ss7, linkset->fds[i]);
1429  pollers[i].revents = 0;
1430  }
1431  ast_mutex_unlock(&linkset->lock);
1432 
1433  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
1434  pthread_testcancel();
1435  res = poll(pollers, linkset->numsigchans, nextms);
1436  pthread_testcancel();
1437  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
1438 
1439  ast_mutex_lock(&linkset->lock);
1440  if ((res < 0) && (errno != EINTR)) {
1441  ast_log(LOG_ERROR, "poll(%s)\n", strerror(errno));
1442  } else if (!res) {
1443  ss7_schedule_run(ss7);
1444  }
1445 
1446  for (i = 0; i < linkset->numsigchans; i++) {
1447  if (pollers[i].revents & POLLPRI) {
1448  sig_ss7_handle_link_exception(linkset, i);
1449  }
1450  if (pollers[i].revents & POLLIN) {
1451  res = ss7_read(ss7, pollers[i].fd);
1452  }
1453  if (pollers[i].revents & POLLOUT) {
1454  res = ss7_write(ss7, pollers[i].fd);
1455  if (res < 0) {
1456  ast_debug(1, "Error in write %s\n", strerror(errno));
1457  }
1458  }
1459  }
1460 
1461  while ((e = ss7_check_event(ss7))) {
1462  ast_callid callid = 0;
1463  int chanpos = -1;
1464  char cause_str[30];
1465 
1466  if (linkset->debug) {
1467  ast_verbose("Linkset %d: Processing event: %s\n",
1468  linkset->span, ss7_event2str(e->e));
1469  }
1470 
1471  switch (e->e) {
1472  case SS7_EVENT_UP:
1473  if (linkset->state != LINKSET_STATE_UP) {
1474  ast_verb(1, "--- SS7 Up ---\n");
1475  ss7_reset_linkset(linkset);
1476  }
1477  linkset->state = LINKSET_STATE_UP;
1478  break;
1479  case SS7_EVENT_DOWN:
1480  ast_verb(1, "--- SS7 Down ---\n");
1481  linkset->state = LINKSET_STATE_DOWN;
1482  for (i = 0; i < linkset->numchans; i++) {
1483  p = linkset->pvts[i];
1484  if (p) {
1485  sig_ss7_set_inservice(p, 0);
1486  if (linkset->flags & LINKSET_FLAG_INITIALHWBLO) {
1487  sig_ss7_set_remotelyblocked(p, 1, SS7_BLOCKED_HARDWARE);
1488  }
1489  }
1490  }
1491  break;
1492  case MTP2_LINK_UP:
1493  ast_verb(1, "MTP2 link up (SLC %d)\n", e->gen.data);
1494  break;
1495  case MTP2_LINK_DOWN:
1496  ast_log(LOG_WARNING, "MTP2 link down (SLC %d)\n", e->gen.data);
1497  break;
1498  case ISUP_EVENT_CPG:
1499  chanpos = ss7_find_cic_gripe(linkset, e->cpg.cic, e->cpg.opc, "CPG");
1500  if (chanpos < 0) {
1501  isup_free_call(ss7, e->cpg.call);
1502  break;
1503  }
1504  p = linkset->pvts[chanpos];
1505  sig_ss7_lock_private(p);
1506  callid = func_ss7_linkset_callid(linkset, chanpos);
1507 
1508  switch (e->cpg.event) {
1509  case CPG_EVENT_ALERTING:
1512  }
1513  sig_ss7_lock_owner(linkset, chanpos);
1514  if (p->owner) {
1516  if (!ast_strlen_zero(e->cpg.connected_num)) {
1517  struct ast_party_connected_line ast_connected;
1518  char connected_num[AST_MAX_EXTENSION];
1519 
1520  ast_party_connected_line_init(&ast_connected);
1521  ast_connected.id.number.presentation =
1522  ss7_pres_scr2cid_pres(e->cpg.connected_presentation_ind,
1523  e->cpg.connected_screening_ind);
1524  ss7_apply_plan_to_number(connected_num, sizeof(connected_num),
1525  linkset, e->cpg.connected_num, e->cpg.connected_nai);
1526  ast_connected.id.number.str = ast_strdup(connected_num);
1527  ast_connected.id.number.valid = 1;
1528  ast_channel_queue_connected_line_update(p->owner, &ast_connected, NULL);
1529  ast_party_connected_line_free(&ast_connected);
1530  }
1532  }
1533  sig_ss7_queue_control(linkset, chanpos, AST_CONTROL_RINGING);
1534  break;
1535  case CPG_EVENT_PROGRESS:
1536  case CPG_EVENT_INBANDINFO:
1537  {
1538  ast_debug(1, "Queuing frame PROGRESS on CIC %d\n", p->cic);
1539  sig_ss7_queue_control(linkset, chanpos, AST_CONTROL_PROGRESS);
1540  p->progress = 1;
1541  sig_ss7_set_dialing(p, 0);
1542  sig_ss7_open_media(p);
1543  }
1544  break;
1545  default:
1546  ast_debug(1, "Do not handle CPG with event type 0x%x\n", e->cpg.event);
1547  break;
1548  }
1549 
1550  sig_ss7_unlock_private(p);
1551  break;
1552  case ISUP_EVENT_RSC:
1553  ast_verb(1, "Resetting CIC %d\n", e->rsc.cic);
1554  chanpos = ss7_find_cic_gripe(linkset, e->rsc.cic, e->rsc.opc, "RSC");
1555  if (chanpos < 0) {
1556  isup_free_call(ss7, e->rsc.call);
1557  break;
1558  }
1559  p = linkset->pvts[chanpos];
1560  sig_ss7_lock_private(p);
1561  p->ss7call = e->rsc.call;
1562  callid = func_ss7_linkset_callid(linkset, chanpos);
1563  sig_ss7_set_inservice(p, 1);
1564  sig_ss7_set_remotelyblocked(p, 0, SS7_BLOCKED_MAINTENANCE | SS7_BLOCKED_HARDWARE);
1565 
1567  isup_blo(ss7, e->rsc.call);
1568  } else if (p->locallyblocked & SS7_BLOCKED_HARDWARE) {
1569  sig_ss7_set_locallyblocked(p, 0, SS7_BLOCKED_HARDWARE);
1570  }
1571 
1572  isup_set_call_dpc(e->rsc.call, p->dpc);
1573  sig_ss7_lock_owner(linkset, chanpos);
1574  if (p->owner) {
1575  p->do_hangup = SS7_HANGUP_SEND_RLC;
1576  if (!(e->rsc.got_sent_msg & ISUP_SENT_IAM)) {
1577  /* Q.784 6.2.3 */
1579  } else {
1580  ast_channel_hangupcause_set(p->owner, SS7_CAUSE_TRY_AGAIN);
1581  }
1582 
1583  ss7_queue_pvt_cause_data(p->owner, "SS7 ISUP_EVENT_RSC", AST_CAUSE_INTERWORKING);
1584 
1587  } else {
1588  isup_rlc(ss7, e->rsc.call);
1589  p->ss7call = isup_free_call_if_clear(ss7, e->rsc.call);
1590  }
1591  /* End the loopback if we have one */
1592  sig_ss7_loopback(p, 0);
1593 
1594  sig_ss7_unlock_private(p);
1595  break;
1596  case ISUP_EVENT_GRS:
1597  if (!sig_ss7_find_cic_range(linkset, e->grs.startcic, e->grs.endcic,
1598  e->grs.opc)) {
1599  ast_log(LOG_WARNING, "GRS on unconfigured range CIC %d - %d PC %d\n",
1600  e->grs.startcic, e->grs.endcic, e->grs.opc);
1601  chanpos = sig_ss7_find_cic(linkset, e->grs.startcic, e->grs.opc);
1602  if (chanpos < 0) {
1603  isup_free_call(ss7, e->grs.call);
1604  break;
1605  }
1606  p = linkset->pvts[chanpos];
1607  sig_ss7_lock_private(p);
1608  p->ss7call = isup_free_call_if_clear(ss7, e->grs.call);
1609  sig_ss7_unlock_private(p);
1610  break;
1611  }
1612 
1613  /* Leave startcic last to collect all cics mb_state */
1614  for (i = e->grs.endcic - e->grs.startcic; 0 <= i; --i) {
1615  /*
1616  * We are guaranteed to find chanpos because
1617  * sig_ss7_find_cic_range() includes it.
1618  */
1619  chanpos = sig_ss7_find_cic(linkset, e->grs.startcic + i, e->grs.opc);
1620  p = linkset->pvts[chanpos];
1621  sig_ss7_lock_private(p);
1622 
1624  mb_state[i] = 1;
1625  } else {
1626  mb_state[i] = 0;
1627  sig_ss7_set_locallyblocked(p, 0, SS7_BLOCKED_HARDWARE);
1628  }
1629 
1630  sig_ss7_set_remotelyblocked(p, 0, SS7_BLOCKED_MAINTENANCE | SS7_BLOCKED_HARDWARE);
1631 
1632  if (!i) {
1633  p->ss7call = e->grs.call;
1634  isup_gra(ss7, p->ss7call, e->grs.endcic, mb_state);
1635  }
1636 
1637  sig_ss7_lock_owner(linkset, chanpos);
1638  if (p->owner) {
1641  && linkset->pvts[i]->call_level < SIG_SS7_CALL_LEVEL_PROCEEDING) {
1642  ast_channel_hangupcause_set(p->owner, SS7_CAUSE_TRY_AGAIN);
1643  } else {
1645  }
1646  p->do_hangup = SS7_HANGUP_FREE_CALL;
1648  } else if (!i) {
1649  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
1650  } else if (p->ss7call) {
1651  /* clear any other session */
1652  isup_free_call(ss7, p->ss7call);
1653  p->ss7call = NULL;
1654  }
1655  sig_ss7_set_inservice(p, 1);
1656  sig_ss7_unlock_private(p);
1657  }
1658  break;
1659  case ISUP_EVENT_CQM:
1660  ast_debug(1, "Got Circuit group query message from CICs %d to %d\n",
1661  e->cqm.startcic, e->cqm.endcic);
1662  ss7_handle_cqm(linkset, e);
1663  break;
1664  case ISUP_EVENT_GRA:
1665  if (!sig_ss7_find_cic_range(linkset, e->gra.startcic,
1666  e->gra.endcic, e->gra.opc)) { /* Never will be true */
1667  ast_log(LOG_WARNING, "GRA on unconfigured range CIC %d - %d PC %d\n",
1668  e->gra.startcic, e->gra.endcic, e->gra.opc);
1669  isup_free_call(ss7, e->gra.call);
1670  break;
1671  }
1672  ast_verb(1, "Got reset acknowledgement from CIC %d to %d DPC: %d\n",
1673  e->gra.startcic, e->gra.endcic, e->gra.opc);
1674  ss7_block_cics(linkset, e->gra.startcic, e->gra.endcic, e->gra.opc,
1675  e->gra.status, 1, 1, SS7_BLOCKED_MAINTENANCE);
1676  ss7_inservice(linkset, e->gra.startcic, e->gra.endcic, e->gra.opc);
1677 
1678  chanpos = sig_ss7_find_cic(linkset, e->gra.startcic, e->gra.opc);
1679  if (chanpos < 0) {
1680  isup_free_call(ss7, e->gra.call);
1681  break;
1682  }
1683 
1684  p = linkset->pvts[chanpos];
1685  sig_ss7_lock_private(p);
1686 
1687  /* we may send a CBD with GRS! */
1688  p->ss7call = isup_free_call_if_clear(ss7, e->gra.call);
1689  sig_ss7_unlock_private(p);
1690  break;
1691  case ISUP_EVENT_SAM:
1692  chanpos = ss7_find_cic_gripe(linkset, e->sam.cic, e->sam.opc, "SAM");
1693  if (chanpos < 0) {
1694  isup_free_call(ss7, e->sam.call);
1695  break;
1696  }
1697  p = linkset->pvts[chanpos];
1698  sig_ss7_lock_private(p);
1699  sig_ss7_lock_owner(linkset, chanpos);
1700  if (p->owner) {
1701  ast_log(LOG_WARNING, "SAM on CIC %d PC %d already have call\n", e->sam.cic, e->sam.opc);
1703  sig_ss7_unlock_private(p);
1704  break;
1705  }
1706  p->called_complete = 0;
1707  if (!ast_strlen_zero(e->sam.called_party_num)) {
1708  char *st;
1709  strncat(p->exten, e->sam.called_party_num, sizeof(p->exten) - strlen(p->exten) - 1);
1710  st = strchr(p->exten, '#');
1711  if (st) {
1712  *st = '\0';
1713  p->called_complete = 1;
1714  }
1715  ss7_match_extension(linkset, p, e);
1716  }
1717  sig_ss7_unlock_private(p);
1718  break;
1719  case ISUP_EVENT_IAM:
1720  ast_debug(1, "Got IAM for CIC %d and called number %s, calling number %s\n", e->iam.cic, e->iam.called_party_num, e->iam.calling_party_num);
1721  chanpos = ss7_find_cic_gripe(linkset, e->iam.cic, e->iam.opc, "IAM");
1722  if (chanpos < 0) {
1723  isup_free_call(ss7, e->iam.call);
1724  break;
1725  }
1726  p = linkset->pvts[chanpos];
1727  sig_ss7_lock_private(p);
1728  /*
1729  * The channel should be idle and not have an owner at this point since we
1730  * are in the process of creating an owner for it.
1731  */
1733 
1734  if (p->remotelyblocked) {
1735  ast_log(LOG_NOTICE, "Got IAM on remotely blocked CIC %d DPC %d remove blocking\n", e->iam.cic, e->iam.opc);
1736  sig_ss7_set_remotelyblocked(p, 0, SS7_BLOCKED_MAINTENANCE | SS7_BLOCKED_HARDWARE);
1737  sig_ss7_set_inservice(p, 1);
1738  }
1739 
1740  if (!sig_ss7_is_chan_available(p)) {
1741  /* Circuit is likely blocked or in alarm. */
1742  isup_rel(ss7, e->iam.call, AST_CAUSE_NORMAL_CIRCUIT_CONGESTION);
1743  if (p->locallyblocked) {
1744  isup_clear_callflags(ss7, e->iam.call, ISUP_GOT_IAM);
1745  p->ss7call = isup_free_call_if_clear(ss7, e->iam.call);
1746  ast_log(LOG_WARNING, "Got IAM on locally blocked CIC %d DPC %d, ignore\n", e->iam.cic, e->iam.opc);
1747  }
1748  sig_ss7_unlock_private(p);
1749  break;
1750  }
1751 
1752  /* Mark channel as in use so no outgoing call will steal it. */
1754  p->ss7call = e->iam.call;
1755 
1756  isup_set_call_dpc(p->ss7call, p->dpc);
1757 
1758  if ((p->use_callerid) && (!ast_strlen_zero(e->iam.calling_party_num))) {
1759  ss7_apply_plan_to_number(p->cid_num, sizeof(p->cid_num), linkset, e->iam.calling_party_num, e->iam.calling_nai);
1760  p->callingpres = ss7_pres_scr2cid_pres(e->iam.presentation_ind, e->iam.screening_ind);
1761  } else {
1762  p->cid_num[0] = 0;
1763  if (e->iam.presentation_ind) {
1764  p->callingpres = ss7_pres_scr2cid_pres(e->iam.presentation_ind, e->iam.screening_ind);
1765  }
1766  }
1767 
1768  p->called_complete = 0;
1769  if (p->immediate) {
1770  p->exten[0] = 's';
1771  p->exten[1] = '\0';
1772  } else if (!ast_strlen_zero(e->iam.called_party_num)) {
1773  char *st;
1774  ss7_apply_plan_to_number(p->exten, sizeof(p->exten), linkset, e->iam.called_party_num, e->iam.called_nai);
1775  st = strchr(p->exten, '#');
1776  if (st) {
1777  *st = '\0';
1778  p->called_complete = 1;
1779  }
1780  } else {
1781  p->exten[0] = '\0';
1782  }
1783 
1784  p->cid_ani[0] = '\0';
1785  if ((p->use_callerid) && (!ast_strlen_zero(e->iam.generic_name))) {
1786  ast_copy_string(p->cid_name, e->iam.generic_name, sizeof(p->cid_name));
1787  } else {
1788  p->cid_name[0] = '\0';
1789  }
1790 
1791  p->cid_ani2 = e->iam.oli_ani2;
1792  p->cid_ton = 0;
1793  ast_copy_string(p->charge_number, e->iam.charge_number, sizeof(p->charge_number));
1794  ast_copy_string(p->gen_add_number, e->iam.gen_add_number, sizeof(p->gen_add_number));
1795  p->gen_add_type = e->iam.gen_add_type;
1796  p->gen_add_nai = e->iam.gen_add_nai;
1797  p->gen_add_pres_ind = e->iam.gen_add_pres_ind;
1798  p->gen_add_num_plan = e->iam.gen_add_num_plan;
1799  ast_copy_string(p->gen_dig_number, e->iam.gen_dig_number, sizeof(p->gen_dig_number));
1800  p->gen_dig_type = e->iam.gen_dig_type;
1801  p->gen_dig_scheme = e->iam.gen_dig_scheme;
1802  ast_copy_string(p->jip_number, e->iam.jip_number, sizeof(p->jip_number));
1803  if (!ast_strlen_zero(e->iam.orig_called_num)) {
1804  ss7_apply_plan_to_number(p->orig_called_num, sizeof(p->orig_called_num), linkset, e->iam.orig_called_num, e->iam.orig_called_nai);
1805  p->orig_called_presentation = ss7_pres_scr2cid_pres(e->iam.orig_called_pres_ind, e->iam.orig_called_screening_ind);
1806  }
1807  if (!ast_strlen_zero(e->iam.redirecting_num)) {
1808  ss7_apply_plan_to_number(p->redirecting_num, sizeof(p->redirecting_num), linkset, e->iam.redirecting_num, e->iam.redirecting_num_nai);
1809  p->redirecting_presentation = ss7_pres_scr2cid_pres(e->iam.redirecting_num_presentation_ind, e->iam.redirecting_num_screening_ind);
1810  }
1811  ast_copy_string(p->generic_name, e->iam.generic_name, sizeof(p->generic_name));
1812  p->calling_party_cat = e->iam.calling_party_cat;
1813  p->redirect_counter = e->iam.redirect_counter;
1814  p->redirect_info = e->iam.redirect_info;
1815  p->redirect_info_ind = e->iam.redirect_info_ind;
1816  p->redirect_info_orig_reas = e->iam.redirect_info_orig_reas;
1817  p->redirect_info_counter = e->iam.redirect_info_counter;
1818  if (p->redirect_info_counter && !p->redirect_counter) {
1820  }
1821  p->redirect_info_reas = e->iam.redirect_info_reas;
1822  p->cug_indicator = e->iam.cug_indicator;
1823  p->cug_interlock_code = e->iam.cug_interlock_code;
1824  ast_copy_string(p->cug_interlock_ni, e->iam.cug_interlock_ni, sizeof(p->cug_interlock_ni));
1825 
1826  if (e->iam.cot_check_required) {
1827  sig_ss7_loopback(p, 1);
1828  }
1829 
1830  p->echocontrol_ind = e->iam.echocontrol_ind;
1831  sig_ss7_set_caller_id(p);
1832  ss7_match_extension(linkset, p, e);
1833  sig_ss7_unlock_private(p);
1834 
1835  if (e->iam.cot_performed_on_previous_cic) {
1836  chanpos = sig_ss7_find_cic(linkset, (e->iam.cic - 1), e->iam.opc);
1837  if (chanpos < 0) {
1838  /* some stupid switch do this */
1839  ast_verb(1, "COT request on previous nonexistent CIC %d in IAM PC %d\n", (e->iam.cic - 1), e->iam.opc);
1840  break;
1841  }
1842  ast_verb(1, "COT request on previous CIC %d in IAM PC %d\n", (e->iam.cic - 1), e->iam.opc);
1843  p = linkset->pvts[chanpos];
1844  sig_ss7_lock_private(p);
1845  if (sig_ss7_is_chan_available(p)) {
1846  sig_ss7_set_inservice(p, 0); /* to prevent to use this circuit */
1847  sig_ss7_loopback(p, 1);
1848  } /* If already have a call don't loop */
1849  sig_ss7_unlock_private(p);
1850  }
1851  break;
1852  case ISUP_EVENT_DIGITTIMEOUT:
1853  chanpos = ss7_find_cic_gripe(linkset, e->digittimeout.cic, e->digittimeout.opc, "DIGITTIMEOUT");
1854  if (chanpos < 0) {
1855  isup_free_call(ss7, e->digittimeout.call);
1856  break;
1857  }
1858  p = linkset->pvts[chanpos];
1859  sig_ss7_lock_private(p);
1860  ast_debug(1, "Digittimeout on CIC: %d PC: %d\n", e->digittimeout.cic, e->digittimeout.opc);
1861  if (ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num)) {
1862  /* DNID is complete */
1863  p->called_complete = 1;
1864  sig_ss7_set_dnid(p, p->exten);
1865 
1866  /* If COT successful start call! */
1867  if (!(e->digittimeout.cot_check_required || e->digittimeout.cot_performed_on_previous_cic) || e->digittimeout.cot_check_passed) {
1868  ss7_start_call(p, linkset);
1869  }
1870  } else {
1871  ast_debug(1, "Call on CIC for unconfigured extension %s\n", p->exten);
1872  isup_rel(linkset->ss7, e->digittimeout.call, AST_CAUSE_UNALLOCATED);
1873  }
1874  sig_ss7_unlock_private(p);
1875  break;
1876  case ISUP_EVENT_COT:
1877  if (e->cot.cot_performed_on_previous_cic) {
1878  chanpos = sig_ss7_find_cic(linkset, (e->cot.cic - 1), e->cot.opc);
1879  /* some stupid switches do this!!! */
1880  if (-1 < chanpos) {
1881  p = linkset->pvts[chanpos];
1882  sig_ss7_lock_private(p);
1883  sig_ss7_set_inservice(p, 1);
1884  sig_ss7_loopback(p, 0);
1885  sig_ss7_unlock_private(p);;
1886  ast_verb(1, "Loop turned off on CIC: %d PC: %d\n", (e->cot.cic - 1), e->cot.opc);
1887  }
1888  }
1889 
1890  chanpos = ss7_find_cic_gripe(linkset, e->cot.cic, e->cot.opc, "COT");
1891  if (chanpos < 0) {
1892  isup_free_call(ss7, e->cot.call);
1893  break;
1894  }
1895  p = linkset->pvts[chanpos];
1896 
1897  sig_ss7_lock_private(p);
1898  p->ss7call = e->cot.call;
1899 
1900  if (p->loopedback) {
1901  sig_ss7_loopback(p, 0);
1902  ast_verb(1, "Loop turned off on CIC: %d PC: %d\n", e->cot.cic, e->cot.opc);
1903  }
1904 
1905  /* Don't start call if we didn't get IAM or COT failed! */
1906  if ((e->cot.got_sent_msg & ISUP_GOT_IAM) && e->cot.passed && p->called_complete) {
1907  ss7_start_call(p, linkset);
1908  }
1909 
1910  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
1911  sig_ss7_unlock_private(p);
1912  break;
1913  case ISUP_EVENT_CCR:
1914  ast_debug(1, "Got CCR request on CIC %d\n", e->ccr.cic);
1915  chanpos = ss7_find_cic_gripe(linkset, e->ccr.cic, e->ccr.opc, "CCR");
1916  if (chanpos < 0) {
1917  isup_free_call(ss7, e->ccr.call);
1918  break;
1919  }
1920 
1921  p = linkset->pvts[chanpos];
1922 
1923  sig_ss7_lock_private(p);
1924  p->ss7call = e->ccr.call;
1925  sig_ss7_loopback(p, 1);
1926  if (linkset->type == SS7_ANSI) {
1927  isup_lpa(linkset->ss7, e->ccr.cic, p->dpc);
1928  }
1929  sig_ss7_unlock_private(p);
1930  break;
1931  case ISUP_EVENT_CVT:
1932  ast_debug(1, "Got CVT request on CIC %d\n", e->cvt.cic);
1933  chanpos = ss7_find_cic_gripe(linkset, e->cvt.cic, e->cvt.opc, "CVT");
1934  if (chanpos < 0) {
1935  isup_free_call(ss7, e->cvt.call);
1936  break;
1937  }
1938 
1939  p = linkset->pvts[chanpos];
1940 
1941  sig_ss7_lock_private(p);
1942  p->ss7call = e->cvt.call;
1943  sig_ss7_loopback(p, 1);
1944  if (!p->owner) {
1945  p->ss7call = isup_free_call_if_clear(ss7, e->cvt.call);
1946  }
1947  isup_cvr(linkset->ss7, e->cvt.cic, p->dpc);
1948  sig_ss7_unlock_private(p);
1949  break;
1950  case ISUP_EVENT_REL:
1951  chanpos = ss7_find_cic_gripe(linkset, e->rel.cic, e->rel.opc, "REL");
1952  if (chanpos < 0) {
1953  isup_free_call(ss7, e->rel.call);
1954  break;
1955  }
1956  p = linkset->pvts[chanpos];
1957  sig_ss7_lock_private(p);
1958  p->ss7call = e->rel.call;
1959  callid = func_ss7_linkset_callid(linkset, chanpos);
1960  sig_ss7_lock_owner(linkset, chanpos);
1961  if (p->owner) {
1962  snprintf(cause_str, sizeof(cause_str), "SS7 ISUP_EVENT_REL (%d)", e->rel.cause);
1963  ss7_queue_pvt_cause_data(p->owner, cause_str, e->rel.cause);
1964 
1965  ast_channel_hangupcause_set(p->owner, e->rel.cause);
1967  p->do_hangup = SS7_HANGUP_SEND_RLC;
1969  } else {
1970  ast_verb(1, "REL on CIC %d DPC %d without owner!\n", p->cic, p->dpc);
1971  isup_rlc(ss7, p->ss7call);
1972  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
1973  }
1974 
1975  /* End the loopback if we have one */
1976  sig_ss7_loopback(p, 0);
1977 
1978  /* the rel is not complete here!!! */
1979  sig_ss7_unlock_private(p);
1980  break;
1981  case ISUP_EVENT_ACM:
1982  chanpos = ss7_find_cic_gripe(linkset, e->acm.cic, e->acm.opc, "ACM");
1983  if (chanpos < 0) {
1984  isup_free_call(ss7, e->acm.call);
1985  break;
1986  }
1987 
1988  p = linkset->pvts[chanpos];
1989 
1990  ast_debug(1, "Queueing frame from SS7_EVENT_ACM on CIC %d\n", p->cic);
1991 
1992  if (e->acm.call_ref_ident > 0) {
1993  p->rlt = 1; /* Setting it but not using it here*/
1994  }
1995 
1996  sig_ss7_lock_private(p);
1997  p->ss7call = e->acm.call;
1998  callid = func_ss7_linkset_callid(linkset, chanpos);
1999  sig_ss7_queue_control(linkset, chanpos, AST_CONTROL_PROCEEDING);
2002  }
2003  sig_ss7_set_dialing(p, 0);
2004  /* Send alerting if subscriber is free */
2005  if (e->acm.called_party_status_ind == 1) {
2008  }
2009  sig_ss7_lock_owner(linkset, chanpos);
2010  if (p->owner) {
2013  }
2014  sig_ss7_queue_control(linkset, chanpos, AST_CONTROL_RINGING);
2015  }
2016  p->echocontrol_ind = e->acm.echocontrol_ind;
2017  sig_ss7_unlock_private(p);
2018  break;
2019  case ISUP_EVENT_CGB:
2020  chanpos = ss7_find_cic_gripe(linkset, e->cgb.startcic, e->cgb.opc, "CGB");
2021  if (chanpos < 0) {
2022  isup_free_call(ss7, e->cgb.call);
2023  break;
2024  }
2025  p = linkset->pvts[chanpos];
2026  ss7_check_range(linkset, e->cgb.startcic, e->cgb.endcic,
2027  e->cgb.opc, e->cgb.status);
2028  ss7_block_cics(linkset, e->cgb.startcic, e->cgb.endcic,
2029  e->cgb.opc, e->cgb.status, 1, 1,
2030  (e->cgb.type) ? SS7_BLOCKED_HARDWARE : SS7_BLOCKED_MAINTENANCE);
2031 
2032  sig_ss7_lock_private(p);
2033  p->ss7call = e->cgb.call;
2034 
2035  isup_cgba(linkset->ss7, p->ss7call, e->cgb.endcic, e->cgb.status);
2036  if (!p->owner) {
2037  p->ss7call = isup_free_call_if_clear(ss7, e->cgb.call);
2038  }
2039  sig_ss7_unlock_private(p);
2040  break;
2041  case ISUP_EVENT_CGU:
2042  chanpos = ss7_find_cic_gripe(linkset, e->cgu.startcic, e->cgu.opc, "CGU");
2043  if (chanpos < 0) {
2044  isup_free_call(ss7, e->cgu.call);
2045  break;
2046  }
2047  p = linkset->pvts[chanpos];
2048  ss7_check_range(linkset, e->cgu.startcic, e->cgu.endcic,
2049  e->cgu.opc, e->cgu.status);
2050  ss7_block_cics(linkset, e->cgu.startcic, e->cgu.endcic,
2051  e->cgu.opc, e->cgu.status, 0, 1,
2053 
2054  sig_ss7_lock_private(p);
2055  p->ss7call = e->cgu.call;
2056 
2057  isup_cgua(linkset->ss7, p->ss7call, e->cgu.endcic, e->cgu.status);
2058  if (!p->owner) {
2059  p->ss7call = isup_free_call_if_clear(ss7, e->cgu.call);
2060  }
2061  sig_ss7_unlock_private(p);
2062  break;
2063  case ISUP_EVENT_UCIC:
2064  chanpos = ss7_find_cic_gripe(linkset, e->ucic.cic, e->ucic.opc, "UCIC");
2065  if (chanpos < 0) {
2066  isup_free_call(ss7, e->ucic.call);
2067  break;
2068  }
2069  p = linkset->pvts[chanpos];
2070  ast_debug(1, "Unequiped Circuit Id Code on CIC %d\n", e->ucic.cic);
2071  sig_ss7_lock_private(p);
2072  sig_ss7_lock_owner(linkset, chanpos);
2073  if (p->owner) {
2076  }
2077  sig_ss7_set_remotelyblocked(p, 1, SS7_BLOCKED_MAINTENANCE);
2078  sig_ss7_set_inservice(p, 0);
2079  p->ss7call = NULL;
2080  isup_free_call(ss7, e->ucic.call);
2081  sig_ss7_unlock_private(p);/* doesn't require a SS7 acknowledgement */
2082  break;
2083  case ISUP_EVENT_BLO:
2084  chanpos = ss7_find_cic_gripe(linkset, e->blo.cic, e->blo.opc, "BLO");
2085  if (chanpos < 0) {
2086  isup_free_call(ss7, e->blo.call);
2087  break;
2088  }
2089  p = linkset->pvts[chanpos];
2090  ast_debug(1, "Blocking CIC %d\n", e->blo.cic);
2091  sig_ss7_lock_private(p);
2092  p->ss7call = e->blo.call;
2093  sig_ss7_set_remotelyblocked(p, 1, SS7_BLOCKED_MAINTENANCE);
2094  isup_bla(linkset->ss7, e->blo.call);
2095  sig_ss7_lock_owner(linkset, chanpos);
2096  if (!p->owner) {
2097  p->ss7call = isup_free_call_if_clear(ss7, e->blo.call);
2098  } else {
2099  if (e->blo.got_sent_msg & ISUP_SENT_IAM) {
2100  /* Q.784 6.2.2 */
2101  ast_channel_hangupcause_set(p->owner, SS7_CAUSE_TRY_AGAIN);
2102  }
2104  }
2105  sig_ss7_unlock_private(p);
2106  break;
2107  case ISUP_EVENT_BLA:
2108  chanpos = ss7_find_cic_gripe(linkset, e->bla.cic, e->bla.opc, "BLA");
2109  if (chanpos < 0) {
2110  isup_free_call(ss7, e->bla.call);
2111  break;
2112  }
2113  ast_debug(1, "Locally blocking CIC %d\n", e->bla.cic);
2114  p = linkset->pvts[chanpos];
2115  sig_ss7_lock_private(p);
2116  p->ss7call = e->bla.call;
2117  sig_ss7_set_locallyblocked(p, 1, SS7_BLOCKED_MAINTENANCE);
2118  if (!p->owner) {
2119  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
2120  }
2121  sig_ss7_unlock_private(p);
2122  break;
2123  case ISUP_EVENT_UBL:
2124  chanpos = ss7_find_cic_gripe(linkset, e->ubl.cic, e->ubl.opc, "UBL");
2125  if (chanpos < 0) {
2126  isup_free_call(ss7, e->ubl.call);
2127  break;
2128  }
2129  p = linkset->pvts[chanpos];
2130  ast_debug(1, "Remotely unblocking CIC %d PC %d\n", e->ubl.cic, e->ubl.opc);
2131  sig_ss7_lock_private(p);
2132  p->ss7call = e->ubl.call;
2133  sig_ss7_set_remotelyblocked(p, 0, SS7_BLOCKED_MAINTENANCE);
2134  isup_uba(linkset->ss7, e->ubl.call);
2135  if (!p->owner) {
2136  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
2137  }
2138  sig_ss7_unlock_private(p);
2139  break;
2140  case ISUP_EVENT_UBA:
2141  chanpos = ss7_find_cic_gripe(linkset, e->uba.cic, e->uba.opc, "UBA");
2142  if (chanpos < 0) {
2143  isup_free_call(ss7, e->uba.call);
2144  break;
2145  }
2146  p = linkset->pvts[chanpos];
2147  ast_debug(1, "Locally unblocking CIC %d PC %d\n", e->uba.cic, e->uba.opc);
2148  sig_ss7_lock_private(p);
2149  p->ss7call = e->uba.call;
2150  sig_ss7_set_locallyblocked(p, 0, SS7_BLOCKED_MAINTENANCE);
2151  if (!p->owner) {
2152  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
2153  }
2154  sig_ss7_unlock_private(p);
2155  break;
2156  case ISUP_EVENT_CON:
2157  case ISUP_EVENT_ANM:
2158  if (e->e == ISUP_EVENT_CON) {
2159  chanpos = ss7_find_cic_gripe(linkset, e->con.cic, e->con.opc, "CON");
2160  if (chanpos < 0) {
2161  isup_free_call(ss7, e->con.call);
2162  break;
2163  }
2164  } else {
2165  chanpos = ss7_find_cic_gripe(linkset, e->anm.cic, e->anm.opc, "ANM");
2166  if (chanpos < 0) {
2167  isup_free_call(ss7, e->anm.call);
2168  break;
2169  }
2170  }
2171 
2172  p = linkset->pvts[chanpos];
2173  sig_ss7_lock_private(p);
2174  p->ss7call = (e->e == ISUP_EVENT_ANM) ? e->anm.call : e->con.call;
2175  callid = func_ss7_linkset_callid(linkset, chanpos);
2178  }
2179 
2180  if (!ast_strlen_zero((e->e == ISUP_EVENT_ANM)
2181  ? e->anm.connected_num : e->con.connected_num)) {
2182  sig_ss7_lock_owner(linkset, chanpos);
2183  if (p->owner) {
2184  struct ast_party_connected_line ast_connected;
2185  char connected_num[AST_MAX_EXTENSION];
2186 
2187  ast_party_connected_line_init(&ast_connected);
2188  if (e->e == ISUP_EVENT_ANM) {
2189  ast_connected.id.number.presentation = ss7_pres_scr2cid_pres(
2190  e->anm.connected_presentation_ind,
2191  e->anm.connected_screening_ind);
2192  ss7_apply_plan_to_number(connected_num, sizeof(connected_num),
2193  linkset, e->anm.connected_num, e->anm.connected_nai);
2194  ast_connected.id.number.str = ast_strdup(connected_num);
2195  } else {
2196  ast_connected.id.number.presentation = ss7_pres_scr2cid_pres(
2197  e->con.connected_presentation_ind,
2198  e->con.connected_screening_ind);
2199  ss7_apply_plan_to_number(connected_num, sizeof(connected_num),
2200  linkset, e->con.connected_num, e->con.connected_nai);
2201  ast_connected.id.number.str = ast_strdup(connected_num);
2202  }
2203  ast_connected.id.number.valid = 1;
2204  ast_connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
2205  ast_channel_queue_connected_line_update(p->owner, &ast_connected, NULL);
2206  ast_party_connected_line_free(&ast_connected);
2208  }
2209  }
2210 
2211  sig_ss7_queue_control(linkset, chanpos, AST_CONTROL_ANSWER);
2212  sig_ss7_set_dialing(p, 0);
2213  sig_ss7_open_media(p);
2214  if (((e->e == ISUP_EVENT_ANM) ? !e->anm.echocontrol_ind :
2215  !e->con.echocontrol_ind) || !(linkset->flags & LINKSET_FLAG_USEECHOCONTROL)) {
2216  sig_ss7_set_echocanceller(p, 1);
2217  }
2218  sig_ss7_unlock_private(p);
2219  break;
2220  case ISUP_EVENT_RLC:
2221  chanpos = ss7_find_cic_gripe(linkset, e->rlc.cic, e->rlc.opc, "RLC");
2222  if (chanpos < 0) {
2223  isup_free_call(ss7, e->rlc.call);
2224  break;
2225  }
2226 
2227  p = linkset->pvts[chanpos];
2228  sig_ss7_lock_private(p);
2229  p->ss7call = e->rlc.call;
2230  callid = func_ss7_linkset_callid(linkset, chanpos);
2231  if (e->rlc.got_sent_msg & (ISUP_SENT_RSC | ISUP_SENT_REL)) {
2232  sig_ss7_loopback(p, 0);
2233  if (e->rlc.got_sent_msg & ISUP_SENT_RSC) {
2234  sig_ss7_set_inservice(p, 1);
2235  }
2236  }
2237  sig_ss7_lock_owner(linkset, chanpos);
2238  if (!p->owner) {
2239  p->ss7call = isup_free_call_if_clear(ss7, e->rlc.call);
2241  } else {
2242  p->do_hangup = SS7_HANGUP_DO_NOTHING;
2245  }
2246  sig_ss7_unlock_private(p);
2247  break;
2248  case ISUP_EVENT_FAA:
2249  /*!
2250  * \todo The handling of the SS7 FAA message is not good and I
2251  * don't know enough to handle it correctly.
2252  */
2253  chanpos = ss7_find_cic_gripe(linkset, e->faa.cic, e->faa.opc, "FAA");
2254  if (chanpos < 0) {
2255  isup_free_call(ss7, e->faa.call);
2256  break;
2257  }
2258 
2259  /* XXX FAR and FAA used for something dealing with transfers? */
2260  p = linkset->pvts[chanpos];
2261  sig_ss7_lock_private(p);
2262  callid = func_ss7_linkset_callid(linkset, chanpos);
2263  ast_debug(1, "FAA received on CIC %d\n", e->faa.cic);
2264  p->ss7call = isup_free_call_if_clear(ss7, e->faa.call);
2265  sig_ss7_unlock_private(p);
2266  break;
2267  case ISUP_EVENT_CGBA:
2268  chanpos = ss7_find_cic_gripe(linkset, e->cgba.startcic, e->cgba.opc, "CGBA");
2269  if (chanpos < 0) { /* Never will be true */
2270  isup_free_call(ss7, e->cgba.call);
2271  break;
2272  }
2273 
2274  ss7_block_cics(linkset, e->cgba.startcic, e->cgba.endcic,
2275  e->cgba.opc, e->cgba.status, 1, 0,
2277 
2278  p = linkset->pvts[chanpos];
2279  sig_ss7_lock_private(p);
2280  p->ss7call = e->cgba.call;
2281 
2282  if (!p->owner) {
2283  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
2284  }
2285  sig_ss7_unlock_private(p);
2286  break;
2287  case ISUP_EVENT_CGUA:
2288  chanpos = ss7_find_cic_gripe(linkset, e->cgua.startcic, e->cgua.opc, "CGUA");
2289  if (chanpos < 0) { /* Never will be true */
2290  isup_free_call(ss7, e->cgua.call);
2291  break;
2292  }
2293 
2294  ss7_block_cics(linkset, e->cgua.startcic, e->cgua.endcic,
2295  e->cgua.opc, e->cgua.status, 0, 0,
2297 
2298  p = linkset->pvts[chanpos];
2299  sig_ss7_lock_private(p);
2300  p->ss7call = e->cgua.call;
2301 
2302  if (!p->owner) {
2303  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
2304  }
2305  sig_ss7_unlock_private(p);
2306  break;
2307  case ISUP_EVENT_SUS:
2308  chanpos = ss7_find_cic_gripe(linkset, e->sus.cic, e->sus.opc, "SUS");
2309  if (chanpos < 0) {
2310  isup_free_call(ss7, e->sus.call);
2311  break;
2312  }
2313 
2314  p = linkset->pvts[chanpos];
2315  sig_ss7_lock_private(p);
2316  p->ss7call = e->sus.call;
2317  if (!p->owner) {
2318  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
2319  }
2320  sig_ss7_unlock_private(p);
2321  break;
2322  case ISUP_EVENT_RES:
2323  chanpos = ss7_find_cic_gripe(linkset, e->res.cic, e->res.opc, "RES");
2324  if (chanpos < 0) {
2325  isup_free_call(ss7, e->res.call);
2326  break;
2327  }
2328 
2329  p = linkset->pvts[chanpos];
2330  sig_ss7_lock_private(p);
2331  p->ss7call = e->res.call;
2332  if (!p->owner) {
2333  p->ss7call = isup_free_call_if_clear(ss7, p->ss7call);
2334  }
2335  sig_ss7_unlock_private(p);
2336  break;
2337  default:
2338  ast_debug(1, "Unknown event %s\n", ss7_event2str(e->e));
2339  break;
2340  }
2341 
2342  /* Call ID stuff needs to be cleaned up here */
2343  if (callid) {
2345  }
2346  }
2347  ast_mutex_unlock(&linkset->lock);
2348  }
2349 
2350  return 0;
2351 }
2352 
2353 static void ss7_rel(struct sig_ss7_linkset *ss7)
2354 {
2355  /* Release the lock first */
2356  ast_mutex_unlock(&ss7->lock);
2357 
2358  /* Then break the poll to send our messages */
2359  if (ss7->master != AST_PTHREADT_NULL) {
2360  pthread_kill(ss7->master, SIGURG);
2361  }
2362 }
2363 
2364 static void ss7_grab(struct sig_ss7_chan *pvt, struct sig_ss7_linkset *ss7)
2365 {
2366  /* Grab the lock first */
2367  while (ast_mutex_trylock(&ss7->lock)) {
2368  /* Avoid deadlock */
2369  sig_ss7_deadlock_avoidance_private(pvt);
2370  }
2371 }
2372 
2373 /*!
2374  * \brief Reset a specific CIC.
2375  * \since 11.0
2376  *
2377  * \param linkset linkset control structure.
2378  * \param cic Circuit Identification Code
2379  * \param dpc Destination Point Code
2380  *
2381  * \return TRUE on success
2382  */
2383 int sig_ss7_reset_cic(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc)
2384 {
2385  int i;
2386 
2387  ast_mutex_lock(&linkset->lock);
2388  for (i = 0; i < linkset->numchans; i++) {
2389  if (linkset->pvts[i] && linkset->pvts[i]->cic == cic && linkset->pvts[i]->dpc == dpc) {
2390  int res;
2391 
2392  sig_ss7_lock_private(linkset->pvts[i]);
2393  sig_ss7_set_locallyblocked(linkset->pvts[i], 0, SS7_BLOCKED_MAINTENANCE | SS7_BLOCKED_HARDWARE);
2394  res = ss7_start_rsc(linkset, i);
2395  sig_ss7_unlock_private(linkset->pvts[i]);
2396  ss7_rel(linkset); /* Also breaks the poll to send our messages */
2397  return res;
2398  }
2399  }
2400  ss7_rel(linkset);
2401 
2402  return 0;
2403 }
2404 
2405 /*!
2406  * \brief Block or Unblock a specific CIC.
2407  * \since 11.0
2408  *
2409  * \param linkset linkset control structure.
2410  * \param do_block Action to perform. Block if TRUE.
2411  * \param which On which CIC to perform the operation.
2412  *
2413  * \return 0 on success
2414  */
2415 int sig_ss7_cic_blocking(struct sig_ss7_linkset *linkset, int do_block, int which)
2416 {
2417  ast_mutex_lock(&linkset->lock);
2418  sig_ss7_lock_private(linkset->pvts[which]);
2419  if (!ss7_find_alloc_call(linkset->pvts[which])) {
2420  sig_ss7_unlock_private(linkset->pvts[which]);
2421  ss7_rel(linkset);
2422  return -1;
2423  }
2424 
2425  if (do_block) {
2426  isup_blo(linkset->ss7, linkset->pvts[which]->ss7call);
2427  } else {
2428  isup_ubl(linkset->ss7, linkset->pvts[which]->ss7call);
2429  }
2430 
2431  sig_ss7_unlock_private(linkset->pvts[which]);
2432  ss7_rel(linkset); /* Also breaks the poll to send our messages */
2433 
2434  return 0;
2435 }
2436 
2437 /*!
2438  * \brief Block or Unblock a range of CICs.
2439  * \since 11.0
2440  *
2441  * \param linkset linkset control structure.
2442  * \param do_block Action to perform. Block if TRUE.
2443  * \param chanpos Channel position to start from.
2444  * \param endcic Circuit Identification Code of the end of the range.
2445  * \param state Array of CIC blocking status.
2446  * \param type Type of the blocking - maintenance or hardware
2447  *
2448  * \note Assumes the linkset->lock is already obtained.
2449  *
2450  * \return 0 on success
2451  */
2452 int sig_ss7_group_blocking(struct sig_ss7_linkset *linkset, int do_block, int chanpos, int endcic, unsigned char state[], int type)
2453 {
2454  sig_ss7_lock_private(linkset->pvts[chanpos]);
2455  if (!ss7_find_alloc_call(linkset->pvts[chanpos])) {
2456  sig_ss7_unlock_private(linkset->pvts[chanpos]);
2457  return -1;
2458  }
2459 
2460  if (do_block) {
2461  isup_cgb(linkset->ss7, linkset->pvts[chanpos]->ss7call, endcic, state, type);
2462  } else {
2463  isup_cgu(linkset->ss7, linkset->pvts[chanpos]->ss7call, endcic, state, type);
2464  }
2465 
2466  sig_ss7_unlock_private(linkset->pvts[chanpos]);
2467  return 0;
2468 }
2469 
2470 /*!
2471  * \brief Reset a group of CICs.
2472  * \since 11.0
2473  *
2474  * \param linkset linkset control structure.
2475  * \param cic Circuit Identification Code
2476  * \param dpc Destination Point Code
2477  * \param range Range of the CICs to reset
2478  *
2479  * \note Assumes the linkset->lock is already obtained.
2480  *
2481  * \return 0 on success
2482  */
2483 int sig_ss7_reset_group(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc, int range)
2484 {
2485  int i;
2486 
2487  for (i = 0; i < linkset->numchans; i++) {
2488  if (linkset->pvts[i] && linkset->pvts[i]->cic == cic && linkset->pvts[i]->dpc == dpc) {
2489  ss7_clear_channels(linkset, cic, cic + range, dpc, SS7_HANGUP_FREE_CALL);
2490  ss7_block_cics(linkset, cic, cic + range, dpc, NULL, 0, 1,
2492  ss7_block_cics(linkset, cic, cic + range, dpc, NULL, 0, 0,
2494 
2495  sig_ss7_lock_private(linkset->pvts[i]);
2496  if (!ss7_find_alloc_call(linkset->pvts[i])) {
2497  sig_ss7_unlock_private(linkset->pvts[i]);
2498  return -1;
2499  }
2500  isup_grs(linkset->ss7, linkset->pvts[i]->ss7call, linkset->pvts[i]->cic + range);
2501  sig_ss7_unlock_private(linkset->pvts[i]);
2502  break;
2503  }
2504  }
2505  return 0;
2506 }
2507 
2508 void sig_ss7_free_isup_call(struct sig_ss7_linkset *linkset, int channel)
2509 {
2510  sig_ss7_lock_private(linkset->pvts[channel]);
2511  if (linkset->pvts[channel]->ss7call) {
2512  isup_free_call(linkset->ss7, linkset->pvts[channel]->ss7call);
2513  linkset->pvts[channel]->ss7call = NULL;
2514  }
2515  sig_ss7_unlock_private(linkset->pvts[channel]);
2516 }
2517 
2518 static int ss7_parse_prefix(struct sig_ss7_chan *p, const char *number, char *nai)
2519 {
2520  int strip = 0;
2521 
2522  if (strncmp(number, p->ss7->internationalprefix, strlen(p->ss7->internationalprefix)) == 0) {
2523  strip = strlen(p->ss7->internationalprefix);
2524  *nai = SS7_NAI_INTERNATIONAL;
2525  } else if (strncmp(number, p->ss7->nationalprefix, strlen(p->ss7->nationalprefix)) == 0) {
2526  strip = strlen(p->ss7->nationalprefix);
2527  *nai = SS7_NAI_NATIONAL;
2528  } else if (strncmp(number, p->ss7->networkroutedprefix, strlen(p->ss7->networkroutedprefix)) == 0) {
2529  strip = strlen(p->ss7->networkroutedprefix);
2530  *nai = SS7_NAI_NETWORKROUTED;
2531  } else if (strncmp(number, p->ss7->unknownprefix, strlen(p->ss7->unknownprefix)) == 0) {
2532  strip = strlen(p->ss7->unknownprefix);
2533  *nai = SS7_NAI_UNKNOWN;
2534  } else if (strncmp(number, p->ss7->subscriberprefix, strlen(p->ss7->subscriberprefix)) == 0) {
2535  strip = strlen(p->ss7->subscriberprefix);
2536  *nai = SS7_NAI_SUBSCRIBER;
2537  } else {
2538  *nai = SS7_NAI_SUBSCRIBER;
2539  }
2540 
2541  return strip;
2542 }
2543 
2544 /*!
2545  * \brief Notify the SS7 layer that the link is in alarm.
2546  * \since 1.8
2547  *
2548  * \param linkset Controlling linkset for the channel.
2549  * \param which Link index of the signaling channel.
2550  *
2551  * \return Nothing
2552  */
2553 void sig_ss7_link_alarm(struct sig_ss7_linkset *linkset, int which)
2554 {
2555  linkset->linkstate[which] |= (LINKSTATE_DOWN | LINKSTATE_INALARM);
2556  linkset->linkstate[which] &= ~LINKSTATE_UP;
2557  ss7_link_alarm(linkset->ss7, linkset->fds[which]);
2558 }
2559 
2560 /*!
2561  * \brief Notify the SS7 layer that the link is no longer in alarm.
2562  * \since 1.8
2563  *
2564  * \param linkset Controlling linkset for the channel.
2565  * \param which Link index of the signaling channel.
2566  *
2567  * \return Nothing
2568  */
2569 void sig_ss7_link_noalarm(struct sig_ss7_linkset *linkset, int which)
2570 {
2571  linkset->linkstate[which] &= ~(LINKSTATE_INALARM | LINKSTATE_DOWN);
2572  linkset->linkstate[which] |= LINKSTATE_STARTING;
2573  ss7_link_noalarm(linkset->ss7, linkset->fds[which]);
2574 }
2575 
2576 /*!
2577  * \brief Setup and add a SS7 link channel.
2578  * \since 1.8
2579  *
2580  * \param linkset Controlling linkset for the channel.
2581  * \param which Link index of the signaling channel.
2582  * \param ss7type Switch type of the linkset
2583  * \param transport Signaling transport of channel.
2584  * \param inalarm Non-zero if the channel is in alarm.
2585  * \param networkindicator User configuration parameter.
2586  * \param pointcode User configuration parameter.
2587  * \param adjpointcode User configuration parameter.
2588  *
2589  * \retval 0 on success.
2590  * \retval -1 on error.
2591  */
2592 int sig_ss7_add_sigchan(struct sig_ss7_linkset *linkset, int which, int ss7type, int transport, int inalarm, int networkindicator, int pointcode, int adjpointcode, int cur_slc)
2593 {
2594  if (!linkset->ss7) {
2595  linkset->type = ss7type;
2596  linkset->ss7 = ss7_new(ss7type);
2597  if (!linkset->ss7) {
2598  ast_log(LOG_ERROR, "Can't create new SS7!\n");
2599  return -1;
2600  }
2601  }
2602 
2603  ss7_set_network_ind(linkset->ss7, networkindicator);
2604  ss7_set_pc(linkset->ss7, pointcode);
2605 
2606  if (ss7_add_link(linkset->ss7, transport, linkset->fds[which], cur_slc, adjpointcode)) {
2607  ast_log(LOG_WARNING, "Could not add SS7 link!\n");
2608  }
2609 
2610  if (inalarm) {
2611  linkset->linkstate[which] = LINKSTATE_DOWN | LINKSTATE_INALARM;
2612  ss7_link_alarm(linkset->ss7, linkset->fds[which]);
2613  } else {
2614  linkset->linkstate[which] = LINKSTATE_DOWN;
2615  ss7_link_noalarm(linkset->ss7, linkset->fds[which]);
2616  }
2617 
2618  return 0;
2619 }
2620 
2621 /*!
2622  * \brief Determine if the specified channel is available for an outgoing call.
2623  * \since 1.8
2624  *
2625  * \param p Signaling private structure pointer.
2626  *
2627  * \retval TRUE if the channel is available.
2628  */
2629 int sig_ss7_available(struct sig_ss7_chan *p)
2630 {
2631  int available;
2632 
2633  if (!p->ss7) {
2634  /* Something is wrong here. A SS7 channel without the ss7 pointer? */
2635  return 0;
2636  }
2637 
2638  /* Only have to deal with the linkset lock. */
2639  ast_mutex_lock(&p->ss7->lock);
2640  available = sig_ss7_is_chan_available(p);
2641  if (available) {
2642  p->ss7call = isup_new_call(p->ss7->ss7, p->cic, p->dpc, 1);
2643  if (!p->ss7call) {
2644  ast_log(LOG_ERROR, "Unable to allocate new SS7 call!\n");
2645  available = 0;
2646  } else {
2648  }
2649  }
2650  ast_mutex_unlock(&p->ss7->lock);
2651 
2652  return available;
2653 }
2654 
2655 static unsigned char cid_pres2ss7pres(int cid_pres)
2656 {
2657  return (cid_pres >> 5) & 0x03;
2658 }
2659 
2660 static unsigned char cid_pres2ss7screen(int cid_pres)
2661 {
2662  return cid_pres & 0x03;
2663 }
2664 
2665 static void ss7_connected_line_update(struct sig_ss7_chan *p, struct ast_party_connected_line *connected)
2666 {
2667  int connected_strip = 0;
2668  char connected_nai;
2669  unsigned char connected_pres;
2670  unsigned char connected_screen;
2671  const char *connected_num;
2672 
2673  if (!connected->id.number.valid) {
2674  return;
2675  }
2676 
2677  connected_num = S_OR(connected->id.number.str, "");
2678  if (p->ss7->called_nai == SS7_NAI_DYNAMIC) {
2679  connected_strip = ss7_parse_prefix(p, connected_num, &connected_nai);
2680  } else {
2681  connected_nai = p->ss7->called_nai;
2682  }
2683 
2684  connected_pres = cid_pres2ss7pres(connected->id.number.presentation);
2685  connected_screen = cid_pres2ss7screen(connected->id.number.presentation);
2686 
2687  isup_set_connected(p->ss7call, connected_num + connected_strip, connected_nai, connected_pres, connected_screen);
2688 }
2689 
2690 static unsigned char ss7_redirect_reason(struct sig_ss7_chan *p, struct ast_party_redirecting *redirecting, int orig)
2691 {
2692  int reason = (orig) ? redirecting->orig_reason.code : redirecting->reason.code;
2693 
2694  switch (reason) {
2701  }
2702 
2703  if (orig || reason == AST_REDIRECTING_REASON_UNKNOWN) {
2705  }
2706 
2707  if (reason == AST_REDIRECTING_REASON_UNAVAILABLE) {
2709  }
2710 
2711  if (reason == AST_REDIRECTING_REASON_DEFLECTION) {
2714  }
2716  }
2717 
2719 }
2720 
2721 static unsigned char ss7_redirect_info_ind(struct ast_channel *ast)
2722 {
2723  const char *redirect_info_ind;
2724  struct ast_party_redirecting *redirecting = ast_channel_redirecting(ast);
2725 
2726  redirect_info_ind = pbx_builtin_getvar_helper(ast, "SS7_REDIRECT_INFO_IND");
2727  if (!ast_strlen_zero(redirect_info_ind)) {
2728  if (!strcasecmp(redirect_info_ind, "CALL_REROUTED_PRES_ALLOWED")) {
2730  }
2731  if (!strcasecmp(redirect_info_ind, "CALL_REROUTED_INFO_RESTRICTED")) {
2733  }
2734  if (!strcasecmp(redirect_info_ind, "CALL_DIVERTED_PRES_ALLOWED")) {
2736  }
2737  if (!strcasecmp(redirect_info_ind, "CALL_DIVERTED_INFO_RESTRICTED")) {
2739  }
2740  if (!strcasecmp(redirect_info_ind, "CALL_REROUTED_PRES_RESTRICTED")) {
2742  }
2743  if (!strcasecmp(redirect_info_ind, "CALL_DIVERTED_PRES_RESTRICTED")) {
2745  }
2746  if (!strcasecmp(redirect_info_ind, "SPARE")) {
2747  return SS7_INDICATION_SPARE;
2748  }
2750  }
2751 
2752  if (redirecting->reason.code == AST_REDIRECTING_REASON_DEFLECTION) {
2753  if ((redirecting->to.number.presentation & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
2754  if ((redirecting->orig.number.presentation & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
2756  }
2758  }
2760  }
2761 
2762  if ((redirecting->to.number.presentation & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
2763  if ((redirecting->orig.number.presentation & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
2765  }
2767  }
2769 }
2770 
2771 static void ss7_redirecting_update(struct sig_ss7_chan *p, struct ast_channel *ast)
2772 {
2773  int num_nai_strip = 0;
2774  struct ast_party_redirecting *redirecting = ast_channel_redirecting(ast);
2775 
2776  if (!redirecting->count) {
2777  return;
2778  }
2779 
2780  isup_set_redirect_counter(p->ss7call, redirecting->count);
2781 
2782  if (redirecting->orig.number.valid) {
2783  char ss7_orig_called_nai = p->ss7->called_nai;
2784  const char *ss7_orig_called_num = S_OR(redirecting->orig.number.str, "");
2785 
2786  if (ss7_orig_called_nai == SS7_NAI_DYNAMIC) {
2787  num_nai_strip = ss7_parse_prefix(p, ss7_orig_called_num, &ss7_orig_called_nai);
2788  } else {
2789  num_nai_strip = 0;
2790  }
2791  isup_set_orig_called_num(p->ss7call, ss7_orig_called_num + num_nai_strip,
2792  ss7_orig_called_nai,
2793  cid_pres2ss7pres(redirecting->orig.number.presentation),
2794  cid_pres2ss7screen(redirecting->orig.number.presentation));
2795  }
2796 
2797  if (redirecting->from.number.valid) {
2798  char ss7_redirecting_num_nai = p->ss7->calling_nai;
2799  const char *redirecting_number = S_OR(redirecting->from.number.str, "");
2800 
2801  if (ss7_redirecting_num_nai == SS7_NAI_DYNAMIC) {
2802  num_nai_strip = ss7_parse_prefix(p, redirecting_number, &ss7_redirecting_num_nai);
2803  } else {
2804  num_nai_strip = 0;
2805  }
2806 
2807  isup_set_redirecting_number(p->ss7call, redirecting_number + num_nai_strip,
2808  ss7_redirecting_num_nai,
2809  cid_pres2ss7pres(redirecting->from.number.presentation),
2810  cid_pres2ss7screen(redirecting->from.number.presentation));
2811  }
2812 
2813  isup_set_redirection_info(p->ss7call, ss7_redirect_info_ind(ast),
2814  ss7_redirect_reason(p, ast_channel_redirecting(ast), 1),
2815  redirecting->count, ss7_redirect_reason(p, ast_channel_redirecting(ast), 0));
2816 }
2817 
2818 /*!
2819  * \brief Dial out using the specified SS7 channel.
2820  * \since 1.8
2821  *
2822  * \param p Signaling private structure pointer.
2823  * \param ast Asterisk channel structure pointer.
2824  * \param rdest Dialstring.
2825  *
2826  * \retval 0 on success.
2827  * \retval -1 on error.
2828  */
2829 int sig_ss7_call(struct sig_ss7_chan *p, struct ast_channel *ast, const char *rdest)
2830 {
2831  char ss7_called_nai;
2832  int called_nai_strip;
2833  char ss7_calling_nai;
2834  int calling_nai_strip;
2835  const char *col_req = NULL;
2836  const char *ss7_cug_indicator_str;
2837  const char *ss7_cug_interlock_ni;
2838  const char *ss7_cug_interlock_code;
2839  const char *ss7_interworking_indicator;
2840  const char *ss7_forward_indicator_pmbits;
2841  unsigned char ss7_cug_indicator;
2842  const char *charge_str = NULL;
2843  const char *gen_address = NULL;
2844  const char *gen_digits = NULL;
2845  const char *gen_dig_type = NULL;
2846  const char *gen_dig_scheme = NULL;
2847  const char *gen_name = NULL;
2848  const char *jip_digits = NULL;
2849  const char *lspi_ident = NULL;
2850  const char *rlt_flag = NULL;
2851  const char *call_ref_id = NULL;
2852  const char *call_ref_pc = NULL;
2853  const char *send_far = NULL;
2854  const char *tmr = NULL;
2855  char *c;
2856  char *l;
2857  char dest[256];
2858 
2859  ast_copy_string(dest, rdest, sizeof(dest));
2860 
2861  c = strchr(dest, '/');
2862  if (c) {
2863  c++;
2864  } else {
2865  c = "";
2866  }
2867  if (strlen(c) < p->stripmsd) {
2868  ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
2869  return -1;
2870  }
2871 
2872  if (!p->hidecallerid) {
2874  } else {
2875  l = NULL;
2876  }
2877 
2878  ss7_grab(p, p->ss7);
2879 
2881  /* Call collision before sending IAM. Abort call. */
2882  ss7_rel(p->ss7);
2883  return -1;
2884  }
2885 
2886  called_nai_strip = 0;
2887  ss7_called_nai = p->ss7->called_nai;
2888  if (ss7_called_nai == SS7_NAI_DYNAMIC) { /* compute dynamically */
2889  called_nai_strip = ss7_parse_prefix(p, c + p->stripmsd, &ss7_called_nai);
2890  }
2891  isup_set_called(p->ss7call, c + p->stripmsd + called_nai_strip, ss7_called_nai, p->ss7->ss7);
2892 
2893  calling_nai_strip = 0;
2894  ss7_calling_nai = p->ss7->calling_nai;
2895  if ((l != NULL) && (ss7_calling_nai == SS7_NAI_DYNAMIC)) { /* compute dynamically */
2896  calling_nai_strip = ss7_parse_prefix(p, l, &ss7_calling_nai);
2897  }
2898 
2899  isup_set_calling(p->ss7call, l ? (l + calling_nai_strip) : NULL, ss7_calling_nai,
2900  p->use_callingpres ? cid_pres2ss7pres(ast_channel_connected(ast)->id.number.presentation)
2901  : (l ? SS7_PRESENTATION_ALLOWED
2902  : (ast_channel_connected(ast)->id.number.presentation == AST_PRES_UNAVAILABLE
2903  ? SS7_PRESENTATION_ADDR_NOT_AVAILABLE : SS7_PRESENTATION_RESTRICTED)),
2904  p->use_callingpres ? cid_pres2ss7screen(ast_channel_connected(ast)->id.number.presentation) : SS7_SCREENING_USER_PROVIDED);
2905 
2906  isup_set_oli(p->ss7call, ast_channel_connected(ast)->ani2);
2907 
2908  /* Set the charge number if it is set */
2909  charge_str = pbx_builtin_getvar_helper(ast, "SS7_CHARGE_NUMBER");
2910  if (charge_str)
2911  isup_set_charge(p->ss7call, charge_str, SS7_ANI_CALLING_PARTY_SUB_NUMBER, 0x10);
2912 
2913  gen_address = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_ADDRESS");
2914  if (gen_address)
2915  isup_set_gen_address(p->ss7call, gen_address, p->gen_add_nai,p->gen_add_pres_ind, p->gen_add_num_plan,p->gen_add_type); /* need to add some types here for NAI,PRES,TYPE */
2916 
2917  gen_digits = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_DIGITS");
2918  gen_dig_type = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_DIGTYPE");
2919  gen_dig_scheme = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_DIGSCHEME");
2920  if (gen_digits)
2921  isup_set_gen_digits(p->ss7call, gen_digits, atoi(gen_dig_type), atoi(gen_dig_scheme));
2922 
2923  gen_name = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_NAME");
2924  if (gen_name)
2925  isup_set_generic_name(p->ss7call, gen_name, GEN_NAME_TYPE_CALLING_NAME, GEN_NAME_AVAIL_AVAILABLE, GEN_NAME_PRES_ALLOWED);
2926 
2927  jip_digits = pbx_builtin_getvar_helper(ast, "SS7_JIP");
2928  if (jip_digits)
2929  isup_set_jip_digits(p->ss7call, jip_digits);
2930 
2931  lspi_ident = pbx_builtin_getvar_helper(ast, "SS7_LSPI_IDENT");
2932  if (lspi_ident)
2933  isup_set_lspi(p->ss7call, lspi_ident, 0x18, 0x7, 0x00);
2934 
2935  rlt_flag = pbx_builtin_getvar_helper(ast, "SS7_RLT_ON");
2936  if ((rlt_flag) && ((strncmp("NO", rlt_flag, strlen(rlt_flag))) != 0 )) {
2937  isup_set_lspi(p->ss7call, rlt_flag, 0x18, 0x7, 0x00); /* Setting for Nortel DMS-250/500 */
2938  }
2939 
2940  call_ref_id = pbx_builtin_getvar_helper(ast, "SS7_CALLREF_IDENT");
2941  call_ref_pc = pbx_builtin_getvar_helper(ast, "SS7_CALLREF_PC");
2942  if (call_ref_id && call_ref_pc) {
2943  isup_set_callref(p->ss7call, atoi(call_ref_id),
2944  call_ref_pc ? atoi(call_ref_pc) : 0);
2945  }
2946 
2947  send_far = pbx_builtin_getvar_helper(ast, "SS7_SEND_FAR");
2948  if (send_far && strncmp("NO", send_far, strlen(send_far)) != 0) {
2949  isup_far(p->ss7->ss7, p->ss7call);
2950  }
2951 
2952  tmr = pbx_builtin_getvar_helper(ast, "SS7_TMR_NUM");
2953  if (tmr) {
2954  isup_set_tmr(p->ss7call, atoi(tmr));
2955  } else if ((tmr = pbx_builtin_getvar_helper(ast, "SS7_TMR")) && tmr[0] != '\0') {
2956  if (!strcasecmp(tmr, "SPEECH")) {
2957  isup_set_tmr(p->ss7call, SS7_TMR_SPEECH);
2958  } else if (!strcasecmp(tmr, "SPARE")) {
2959  isup_set_tmr(p->ss7call, SS7_TMR_SPARE);
2960  } else if (!strcasecmp(tmr, "3K1_AUDIO")) {
2961  isup_set_tmr(p->ss7call, SS7_TMR_3K1_AUDIO);
2962  } else if (!strcasecmp(tmr, "64K_UNRESTRICTED")) {
2963  isup_set_tmr(p->ss7call, SS7_TMR_64K_UNRESTRICTED);
2964  } else {
2965  isup_set_tmr(p->ss7call, SS7_TMR_N64K_OR_SPARE);
2966  }
2967  }
2968 
2969  col_req = pbx_builtin_getvar_helper(ast, "SS7_COL_REQUEST");
2970  if (ast_true(col_req)) {
2971  isup_set_col_req(p->ss7call);
2972  }
2973 
2974  ss7_cug_indicator_str = pbx_builtin_getvar_helper(ast, "SS7_CUG_INDICATOR");
2975  if (!ast_strlen_zero(ss7_cug_indicator_str)) {
2976  if (!strcasecmp(ss7_cug_indicator_str, "OUTGOING_ALLOWED")) {
2977  ss7_cug_indicator = ISUP_CUG_OUTGOING_ALLOWED;
2978  } else if (!strcasecmp(ss7_cug_indicator_str, "OUTGOING_NOT_ALLOWED")) {
2979  ss7_cug_indicator = ISUP_CUG_OUTGOING_NOT_ALLOWED;
2980  } else {
2981  ss7_cug_indicator = ISUP_CUG_NON;
2982  }
2983 
2984  if (ss7_cug_indicator != ISUP_CUG_NON) {
2985  ss7_cug_interlock_code = pbx_builtin_getvar_helper(ast, "SS7_CUG_INTERLOCK_CODE");
2986  ss7_cug_interlock_ni = pbx_builtin_getvar_helper(ast, "SS7_CUG_INTERLOCK_NI");
2987  if (ss7_cug_interlock_code && ss7_cug_interlock_ni && strlen(ss7_cug_interlock_ni) == 4) {
2988  isup_set_cug(p->ss7call, ss7_cug_indicator, ss7_cug_interlock_ni, atoi(ss7_cug_interlock_code));
2989  }
2990  }
2991  }
2992 
2993  ss7_redirecting_update(p, ast);
2994 
2995  isup_set_echocontrol(p->ss7call, (p->ss7->flags & LINKSET_FLAG_DEFAULTECHOCONTROL) ? 1 : 0);
2996  ss7_interworking_indicator = pbx_builtin_getvar_helper(ast, "SS7_INTERWORKING_INDICATOR");
2997  if (ss7_interworking_indicator) {
2998  isup_set_interworking_indicator(p->ss7call, ast_true(ss7_interworking_indicator));
2999  }
3000 
3001  ss7_forward_indicator_pmbits = pbx_builtin_getvar_helper(ast, "SS7_FORWARD_INDICATOR_PMBITS");
3002  if (ss7_forward_indicator_pmbits) {
3003  isup_set_forward_indicator_pmbits(p->ss7call, atoi(ss7_forward_indicator_pmbits));
3004  }
3005 
3007  p->do_hangup = SS7_HANGUP_SEND_REL;
3008  isup_iam(p->ss7->ss7, p->ss7call);
3009  sig_ss7_set_dialing(p, 1);
3011  ss7_rel(p->ss7);
3012  return 0;
3013 }
3014 
3015 /*!
3016  * \brief SS7 hangup channel.
3017  * \since 1.8
3018  *
3019  * \param p Signaling private structure pointer.
3020  * \param ast Asterisk channel structure pointer.
3021  *
3022  * \retval 0 on success.
3023  * \retval -1 on error.
3024  */
3025 int sig_ss7_hangup(struct sig_ss7_chan *p, struct ast_channel *ast)
3026 {
3027  if (!ast_channel_tech_pvt(ast)) {
3028  ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
3029  return 0;
3030  }
3031 
3032  p->owner = NULL;
3033  sig_ss7_set_dialing(p, 0);
3034  sig_ss7_set_outgoing(p, 0);
3035  p->progress = 0;
3036  p->rlt = 0;
3037  p->exten[0] = '\0';
3038  /* Perform low level hangup if no owner left */
3039  ss7_grab(p, p->ss7);
3041  if (p->ss7call) {
3042  switch (p->do_hangup) {
3043  case SS7_HANGUP_SEND_REL:
3044  {
3045  const char *cause = pbx_builtin_getvar_helper(ast,"SS7_CAUSE");
3046  int icause = ast_channel_hangupcause(ast) ? ast_channel_hangupcause(ast) : -1;
3047 
3048  if (cause) {
3049  if (atoi(cause)) {
3050  icause = atoi(cause);
3051  }
3052  }
3053  if (icause > 255) {
3054  icause = 16;
3055  }
3056 
3057  isup_rel(p->ss7->ss7, p->ss7call, icause);
3058  p->do_hangup = SS7_HANGUP_DO_NOTHING;
3059  }
3060  break;
3061  case SS7_HANGUP_SEND_RSC:
3062  ss7_do_rsc(p);
3063  p->do_hangup = SS7_HANGUP_DO_NOTHING;
3064  break;
3065  case SS7_HANGUP_SEND_RLC:
3066  isup_rlc(p->ss7->ss7, p->ss7call);
3067  p->do_hangup = SS7_HANGUP_DO_NOTHING;
3068  p->ss7call = isup_free_call_if_clear(p->ss7->ss7, p->ss7call);
3069  break;
3070  case SS7_HANGUP_FREE_CALL:
3071  p->do_hangup = SS7_HANGUP_DO_NOTHING;
3072  isup_free_call(p->ss7->ss7, p->ss7call);
3073  p->ss7call = NULL;
3074  break;
3075  case SS7_HANGUP_REEVENT_IAM:
3076  isup_event_iam(p->ss7->ss7, p->ss7call, p->dpc);
3077  p->do_hangup = SS7_HANGUP_SEND_REL;
3078  break;
3079  case SS7_HANGUP_DO_NOTHING:
3080  p->ss7call = isup_free_call_if_clear(p->ss7->ss7, p->ss7call);
3081  break;
3082  }
3083  }
3084  ss7_rel(p->ss7);
3085 
3086  return 0;
3087 }
3088 
3089 /*!
3090  * \brief SS7 answer channel.
3091  * \since 1.8
3092  *
3093  * \param p Signaling private structure pointer.
3094  * \param ast Asterisk channel structure pointer.
3095  *
3096  * \retval 0 on success.
3097  * \retval -1 on error.
3098  */
3099 int sig_ss7_answer(struct sig_ss7_chan *p, struct ast_channel *ast)
3100 {
3101  int res;
3102 
3103  ss7_grab(p, p->ss7);
3106  isup_acm(p->ss7->ss7, p->ss7call);
3107  }
3109  }
3110 
3111  res = isup_anm(p->ss7->ss7, p->ss7call);
3112  sig_ss7_open_media(p);
3113  ss7_rel(p->ss7);
3114  return res;
3115 }
3116 
3117 /*!
3118  * \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links.
3119  * \since 1.8
3120  *
3121  * \param oldchan Old channel pointer to replace.
3122  * \param newchan New channel pointer to set.
3123  * \param pchan Signaling private structure pointer.
3124  *
3125  * \return Nothing
3126  */
3127 void sig_ss7_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_ss7_chan *pchan)
3128 {
3129  if (pchan->owner == oldchan) {
3130  pchan->owner = newchan;
3131  }
3132 }
3133 
3134 /*!
3135  * \brief SS7 indication.
3136  * \since 1.8
3137  *
3138  * \param p Signaling private structure pointer.
3139  * \param chan Asterisk channel structure pointer.
3140  * \param condition AST control frame subtype.
3141  * \param data AST control frame payload contents.
3142  * \param datalen Length of payload contents.
3143  *
3144  * \retval 0 on success.
3145  * \retval -1 on error or indication condition not handled.
3146  */
3147 int sig_ss7_indicate(struct sig_ss7_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen)
3148 {
3149  int res = -1;
3150 
3151  switch (condition) {
3152  case AST_CONTROL_BUSY:
3156  res = 0;
3157  break;
3158  }
3159  res = sig_ss7_play_tone(p, SIG_SS7_TONE_BUSY);
3160  break;
3161  case AST_CONTROL_RINGING:
3162  ss7_grab(p, p->ss7);
3164  if ((isup_far(p->ss7->ss7, p->ss7call)) != -1) {
3165  p->rlt = 1;
3166  }
3167 
3169  isup_acm(p->ss7->ss7, p->ss7call);
3170  }
3171 
3172  /* No need to send CPG if call will be RELEASE */
3173  if (p->rlt != 1) {
3174  isup_cpg(p->ss7->ss7, p->ss7call, CPG_EVENT_ALERTING);
3175  }
3176 
3178  }
3179  ss7_rel(p->ss7);
3180 
3181  res = sig_ss7_play_tone(p, SIG_SS7_TONE_RINGTONE);
3182 
3185  }
3186  break;
3188  ast_debug(1,"Received AST_CONTROL_PROCEEDING on %s\n",ast_channel_name(chan));
3189  ss7_grab(p, p->ss7);
3190  /* This IF sends the FAR for an answered ALEG call */
3191  if (ast_channel_state(chan) == AST_STATE_UP && (p->rlt != 1)){
3192  if ((isup_far(p->ss7->ss7, p->ss7call)) != -1) {
3193  p->rlt = 1;
3194  }
3195  }
3196 
3199  isup_acm(p->ss7->ss7, p->ss7call);
3200  }
3201  ss7_rel(p->ss7);
3202  /* don't continue in ast_indicate */
3203  res = 0;
3204  break;
3205  case AST_CONTROL_PROGRESS:
3206  ast_debug(1,"Received AST_CONTROL_PROGRESS on %s\n",ast_channel_name(chan));
3207  ss7_grab(p, p->ss7);
3208  if (!p->progress && p->call_level < SIG_SS7_CALL_LEVEL_ALERTING && !p->outgoing) {
3209  p->progress = 1; /* No need to send inband-information progress again. */
3210  isup_cpg(p->ss7->ss7, p->ss7call, CPG_EVENT_INBANDINFO);
3211 
3212  /* enable echo canceler here on SS7 calls */
3213  if (!p->echocontrol_ind || !(p->ss7->flags & LINKSET_FLAG_USEECHOCONTROL)) {
3214  sig_ss7_set_echocanceller(p, 1);
3215  }
3216  }
3217  ss7_rel(p->ss7);
3218  /* don't continue in ast_indicate */
3219  res = 0;
3220  break;
3225  res = 0;
3226  break;
3227  }
3228  /* Wait for DTMF digits to complete the dialed number. */
3229  res = 0;
3230  break;
3235  res = 0;
3236  break;
3237  }
3238  res = sig_ss7_play_tone(p, SIG_SS7_TONE_CONGESTION);
3239  break;
3240  case AST_CONTROL_HOLD:
3241  ast_moh_start(chan, data, p->mohinterpret);
3242  break;
3243  case AST_CONTROL_UNHOLD:
3244  ast_moh_stop(chan);
3245  break;
3246  case AST_CONTROL_SRCUPDATE:
3247  res = 0;
3248  break;
3250  ss7_connected_line_update(p, ast_channel_connected(chan));
3251  res = 0;
3252  break;
3254  ss7_redirecting_update(p, chan);
3255  res = 0;
3256  break;
3257  case -1:
3258  res = sig_ss7_play_tone(p, -1);
3259  break;
3260  }
3261  return res;
3262 }
3263 
3264 /*!
3265  * \brief SS7 channel request.
3266  * \since 1.8
3267  *
3268  * \param p Signaling private structure pointer.
3269  * \param law Companding law preferred
3270  * \param requestor Asterisk channel requesting a channel to dial (Can be NULL)
3271  * \param transfercapability
3272  *
3273  * \retval ast_channel on success.
3274  * \retval NULL on error.
3275  */
3276 struct ast_channel *sig_ss7_request(struct sig_ss7_chan *p, enum sig_ss7_law law,
3277  const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor,
3278  int transfercapability)
3279 {
3280  struct ast_channel *ast;
3281 
3282  /* Companding law is determined by SS7 signaling type. */
3283  if (p->ss7->type == SS7_ITU) {
3284  law = SIG_SS7_ALAW;
3285  } else {
3286  law = SIG_SS7_ULAW;
3287  }
3288 
3289  sig_ss7_set_outgoing(p, 1);
3290  ast = sig_ss7_new_ast_channel(p, AST_STATE_RESERVED, law, transfercapability,
3291  p->exten, assignedids, requestor);
3292  if (!ast) {
3293  sig_ss7_set_outgoing(p, 0);
3294 
3295  /* Release the allocated channel. Only have to deal with the linkset lock. */
3296  ast_mutex_lock(&p->ss7->lock);
3298  isup_free_call(p->ss7->ss7, p->ss7call);
3299  ast_mutex_unlock(&p->ss7->lock);
3300  }
3301  return ast;
3302 }
3303 
3304 /*!
3305  * \brief Delete the sig_ss7 private channel structure.
3306  * \since 1.8
3307  *
3308  * \param doomed sig_ss7 private channel structure to delete.
3309  *
3310  * \return Nothing
3311  */
3312 void sig_ss7_chan_delete(struct sig_ss7_chan *doomed)
3313 {
3314  ast_free(doomed);
3315 }
3316 
3317 #define SIG_SS7_SC_HEADER "%-4s %4s %-4s %-3s %-3s %-10s %-4s %s\n"
3318 #define SIG_SS7_SC_LINE "%4d %4d %-4s %-3s %-3s %-10s %-4s %s"
3320 {
3321  ast_cli(fd, SIG_SS7_SC_HEADER, "link", "", "Chan", "Lcl", "Rem", "Call", "SS7", "Channel");
3322  ast_cli(fd, SIG_SS7_SC_HEADER, "set", "Chan", "Idle", "Blk", "Blk", "Level", "Call", "Name");
3323 }
3324 
3325 void sig_ss7_cli_show_channels(int fd, struct sig_ss7_linkset *linkset)
3326 {
3327  char line[256];
3328  int idx;
3329  struct sig_ss7_chan *pvt;
3330 
3331  ast_mutex_lock(&linkset->lock);
3332  for (idx = 0; idx < linkset->numchans; ++idx) {
3333  if (!linkset->pvts[idx]) {
3334  continue;
3335  }
3336  pvt = linkset->pvts[idx];
3337  sig_ss7_lock_private(pvt);
3338  sig_ss7_lock_owner(linkset, idx);
3339 
3340  snprintf(line, sizeof(line), SIG_SS7_SC_LINE,
3341  linkset->span,
3342  pvt->channel,
3343  sig_ss7_is_chan_available(pvt) ? "Yes" : "No",
3344  pvt->locallyblocked ? "Yes" : "No",
3345  pvt->remotelyblocked ? "Yes" : "No",
3346  sig_ss7_call_level2str(pvt->call_level),
3347  pvt->ss7call ? "Yes" : "No",
3348  pvt->owner ? ast_channel_name(pvt->owner) : "");
3349 
3350  if (pvt->owner) {
3351  ast_channel_unlock(pvt->owner);
3352  }
3353  sig_ss7_unlock_private(pvt);
3354 
3355  ast_mutex_unlock(&linkset->lock);
3356  ast_cli(fd, "%s\n", line);
3357  ast_mutex_lock(&linkset->lock);
3358  }
3359  ast_mutex_unlock(&linkset->lock);
3360 }
3361 
3362 /*!
3363  * \brief Create a new sig_ss7 private channel structure.
3364  * \since 1.8
3365  *
3366  * \param pvt_data Upper layer private data structure.
3367  * \param ss7 Controlling linkset for the channel.
3368  *
3369  * \retval sig_ss7_chan on success.
3370  * \retval NULL on error.
3371  */
3372 struct sig_ss7_chan *sig_ss7_chan_new(void *pvt_data, struct sig_ss7_linkset *ss7)
3373 {
3374  struct sig_ss7_chan *pvt;
3375 
3376  pvt = ast_calloc(1, sizeof(*pvt));
3377  if (!pvt) {
3378  return pvt;
3379  }
3380 
3381  pvt->chan_pvt = pvt_data;
3382  pvt->ss7 = ss7;
3383 
3384  return pvt;
3385 }
3386 
3387 /*!
3388  * \brief Initialize the SS7 linkset control.
3389  * \since 1.8
3390  *
3391  * \param ss7 SS7 linkset control structure.
3392  *
3393  * \return Nothing
3394  */
3395 void sig_ss7_init_linkset(struct sig_ss7_linkset *ss7)
3396 {
3397  int idx;
3398 
3399  memset(ss7, 0, sizeof(*ss7));
3400 
3401  ast_mutex_init(&ss7->lock);
3402 
3403  ss7->master = AST_PTHREADT_NULL;
3404  for (idx = 0; idx < ARRAY_LEN(ss7->fds); ++idx) {
3405  ss7->fds[idx] = -1;
3406  }
3407 }
3408 
3409 /* ------------------------------------------------------------------- */
3410 
3411 #endif /* defined(HAVE_SS7) */
3412 /* end sig_ss7.c */
unsigned char gen_add_pres_ind
Definition: sig_ss7.h:267
static const char type[]
Definition: chan_ooh323.c:109
struct ast_channel * sig_ss7_request(struct sig_ss7_chan *p, enum sig_ss7_law law, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, int transfercapability)
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2022
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch) ...
Definition: pbx.c:4199
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
Music on hold handling.
char calling_nai
Definition: sig_ss7.h:338
char * str
Subscriber phone number (Malloced)
Definition: channel.h:292
General Asterisk channel transcoding definitions.
int cid_ton
Definition: sig_ss7.h:242
unsigned int call_ref_pc
Definition: sig_ss7.h:279
enum sig_ss7_call_level call_level
Definition: sig_ss7.h:198
Asterisk main include file. File version handling, generic pbx functions.
int sig_ss7_available(struct sig_ss7_chan *p)
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char chan_name[AST_CHANNEL_NAME]
unsigned char gen_dig_type
Definition: sig_ss7.h:269
int sig_ss7_reset_cic(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc)
unsigned int outgoing
TRUE if this channel is being used for an outgoing call.
Definition: sig_ss7.h:292
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition: channel.h:296
void(*const lock_private)(void *pvt)
Definition: sig_ss7.h:157
static struct ast_codec ulaw
unsigned int dpc
Definition: sig_ss7.h:202
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
int(*const set_echocanceller)(void *pvt, int enable)
Definition: sig_ss7.h:161
int sig_ss7_indicate(struct sig_ss7_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen)
struct ast_party_id id
Connected party ID.
Definition: channel.h:459
void(*const set_alarm)(void *pvt, int in_alarm)
Definition: sig_ss7.h:170
unsigned char gen_add_num_plan
Definition: sig_ss7.h:265
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define AST_CAUSE_NORMAL_TEMPORARY_FAILURE
Definition: causes.h:121
#define AST_CAUSE_SWITCH_CONGESTION
Definition: causes.h:122
void sig_ss7_cli_show_channels(int fd, struct sig_ss7_linkset *linkset)
unsigned int hidecallerid
TRUE if the outgoing caller ID is blocked/hidden.
Definition: sig_ss7.h:213
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition: channel.h:528
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_CAUSE_UNALLOCATED
Definition: causes.h:97
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Indicate that the redirecting id has changed.
Definition: channel.c:10379
sig_ss7_call_level
Definition: sig_ss7.h:116
char unknownprefix[20]
Definition: sig_ss7.h:342
unsigned char cug_indicator
Indication of the call being a CUG call and its permissions.
Definition: sig_ss7.h:315
void(*const set_remotelyblocked)(void *pvt, int is_blocked)
Definition: sig_ss7.h:176
enum sig_ss7_linkset::@164 state
#define DEADLOCK_AVOIDANCE(lock)
Definition: lock.h:374
#define LOG_WARNING
Definition: logger.h:274
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:4712
char cug_interlock_ni[5]
Network Identify Code as per Q.763 3.15.a.
Definition: sig_ss7.h:306
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created)
Use in conjunction with ast_callid_threadstorage_auto. Cleans up the references and if the callid was...
Definition: logger.c:2042
unsigned char redirect_info_counter
Definition: sig_ss7.h:262
unsigned short cug_interlock_code
Binari Code to uniquely identify a CUG inside the network.
Definition: sig_ss7.h:308
int callingpres
Definition: sig_ss7.h:243
#define LINKSET_FLAG_INITIALHWBLO
Definition: sig_ss7.h:69
static int tmp()
Definition: bt_open.c:389
int channel
Definition: sig_ss7.h:200
#define LINKSET_FLAG_USEECHOCONTROL
Definition: sig_ss7.h:70
unsigned int loopedback
TRUE if this channel is in loopback.
Definition: sig_ss7.h:300
void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
Copy the source party id information to the destination party id.
Definition: channel.c:1765
struct sig_ss7_linkset * ss7
Definition: sig_ss7.h:191
char gen_add_number[50]
Definition: sig_ss7.h:252
void(*const set_locallyblocked)(void *pvt, int is_blocked)
Definition: sig_ss7.h:175
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:605
struct sig_ss7_callback sig_ss7_callbacks
Interface header for SS7 signaling module.
ast_channel_state
ast_channel states
Definition: channelstate.h:35
struct ast_channel *(*const new_ast_channel)(void *pvt, int state, enum sig_ss7_law law, char *exten, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
Definition: sig_ss7.h:164
unsigned int inalarm
TRUE if channel is associated with a link that is down.
Definition: sig_ss7.h:288
pthread_t master
Definition: sig_ss7.h:319
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
unsigned int ast_callid
Definition: logger.h:87
int redirecting_presentation
Definition: sig_ss7.h:257
#define ast_assert(a)
Definition: utils.h:695
#define ast_mutex_lock(a)
Definition: lock.h:187
struct sig_ss7_linkset *(*const find_linkset)(struct ss7 *ss7)
Definition: sig_ss7.h:183
static struct test_val c
Definition: muted.c:95
char redirecting_num[50]
Definition: sig_ss7.h:256
void ast_verbose(const char *fmt,...)
Definition: extconf.c:2207
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
static int call(void *data)
Definition: chan_pjsip.c:2358
void sig_ss7_cb_notinservice(struct ss7 *ss7, int cic, unsigned int dpc)
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition: channel.c:2072
unsigned char gen_dig_scheme
Definition: sig_ss7.h:270
void sig_ss7_free_isup_call(struct sig_ss7_linkset *linkset, int channel)
#define NULL
Definition: resample.c:96
char exten[AST_MAX_EXTENSION]
Definition: sig_ss7.h:248
#define AST_CAUSE_NORMAL_CIRCUIT_CONGESTION
Definition: causes.h:119
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int sig_ss7_cic_blocking(struct sig_ss7_linkset *linkset, int do_block, int cic)
#define AST_CAUSE_INVALID_NUMBER_FORMAT
Definition: causes.h:115
char lspi_ident[50]
Definition: sig_ss7.h:277
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7876
#define SS7_BLOCKED_HARDWARE
Definition: sig_ss7.h:75
int code
enum AST_REDIRECTING_REASON value for redirection
Definition: channel.h:511
#define SS7_NAI_DYNAMIC
Definition: sig_ss7.h:66
#define ast_verb(level,...)
Definition: logger.h:463
char cid_subaddr[AST_MAX_EXTENSION]
Definition: sig_ss7.h:245
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
Definition: logger.c:2003
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
char cid_name[AST_MAX_EXTENSION]
Definition: sig_ss7.h:246
int sig_ss7_reset_group(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc, int range)
unsigned char redirect_info_reas
Definition: sig_ss7.h:263
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_party_id orig
Who originally redirected the call (Sent to the party the call is redirected toward) ...
Definition: channel.h:525
void(*const set_digital)(void *pvt, int is_digital)
Definition: sig_ss7.h:172
unsigned int use_callingpres
TRUE if we will use the calling presentation setting from the Asterisk channel for outgoing calls...
Definition: sig_ss7.h:220
struct ss7 * ss7
Definition: sig_ss7.h:321
Number structure.
Definition: app_followme.c:154
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition: logger.c:1984
unsigned int remotelyblocked
Bitmask for the channel being remotely blocked.
Definition: sig_ss7.h:235
#define LINKSTATE_INALARM
Definition: sig_ss7.h:61
ast_mutex_t lock
Definition: sig_ss7.h:320
void(*const set_dnid)(void *pvt, const char *dnid)
Definition: sig_ss7.h:178
char context[AST_MAX_CONTEXT]
Definition: sig_ss7.h:237
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
unsigned char redirect_info_ind
Definition: sig_ss7.h:260
void(*const set_dialing)(void *pvt, int is_dialing)
Definition: sig_ss7.h:171
unsigned int use_callerid
TRUE if caller ID is used on this channel.
Definition: sig_ss7.h:215
unsigned int progress
TRUE if the call has seen inband-information progress through the network.
Definition: sig_ss7.h:296
void(*const set_outgoing)(void *pvt, int is_outgoing)
Definition: sig_ss7.h:173
#define LINKSTATE_STARTING
Definition: sig_ss7.h:62
void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Queue a connected line update frame on a channel.
Definition: channel.c:9202
int stripmsd
Number of most significant digits/characters to strip from the dialed number.
Definition: sig_ss7.h:209
unsigned char redirect_info
Definition: sig_ss7.h:259
#define ast_mutex_trylock(a)
Definition: lock.h:189
#define LINKSTATE_UP
Definition: sig_ss7.h:63
struct sig_ss7_chan * sig_ss7_chan_new(void *pvt_data, struct sig_ss7_linkset *ss7)
struct ast_party_redirecting_reason orig_reason
Reason for the redirection by the original party.
Definition: channel.h:546
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
#define AST_PTHREADT_NULL
Definition: lock.h:66
ast_mutex_t lock
Definition: app_meetme.c:1091
void sig_ss7_link_noalarm(struct sig_ss7_linkset *linkset, int which)
#define LINKSET_FLAG_EXPLICITACM
Definition: sig_ss7.h:68
#define AST_MAX_EXTENSION
Definition: channel.h:135
int sig_ss7_find_cic(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc)
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
void(*const open_media)(void *pvt)
Definition: sig_ss7.h:181
void sig_ss7_cli_show_channels_header(int fd)
Caller Party information.
Definition: channel.h:419
unsigned char redirect_info_orig_reas
Definition: sig_ss7.h:261
char generic_name[50]
Definition: sig_ss7.h:264
void sig_ss7_set_alarm(struct sig_ss7_chan *p, int in_alarm)
void * chan_pvt
Definition: sig_ss7.h:190
char mohinterpret[MAX_MUSICCLASS]
Definition: sig_ss7.h:238
unsigned int inservice
TRUE if channel is in service.
Definition: sig_ss7.h:290
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4179
char subscriberprefix[20]
Definition: sig_ss7.h:341
int cid_ani2
Definition: sig_ss7.h:241
Core PBX routines and definitions.
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1139
char charge_number[50]
Definition: sig_ss7.h:251
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
struct sig_ss7_chan * pvts[SIG_SS7_MAX_CHANNELS]
Definition: sig_ss7.h:322
#define LOG_ERROR
Definition: logger.h:285
int sig_ss7_call(struct sig_ss7_chan *p, struct ast_channel *ast, const char *rdest)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
int fds[SIG_SS7_NUM_DCHANS]
Definition: sig_ss7.h:323
char orig_called_num[50]
Definition: sig_ss7.h:254
void(*const set_loopback)(void *pvt, int enable)
Definition: sig_ss7.h:162
#define LINKSTATE_DOWN
Definition: sig_ss7.h:64
#define SIG_SS7_NUM_DCHANS
Definition: sig_ss7.h:56
int sig_ss7_find_cic_range(struct sig_ss7_linkset *linkset, int startcic, int endcic, unsigned int dpc)
int errno
Connected Line/Party information.
Definition: channel.h:457
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7866
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
Definition: channel.h:523
#define LOG_NOTICE
Definition: logger.h:263
unsigned int rlt
XXX BOOLEAN Purpose???
Definition: sig_ss7.h:298
sig_ss7_tone
Definition: sig_ss7.h:78
unsigned char gen_add_type
Definition: sig_ss7.h:268
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2463
int linkstate[SIG_SS7_NUM_DCHANS]
Definition: sig_ss7.h:325
void sig_ss7_init_linkset(struct sig_ss7_linkset *ss7)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
int sig_ss7_group_blocking(struct sig_ss7_linkset *linkset, int do_block, int startcic, int endcic, unsigned char state[], int type)
unsigned int call_ref_ident
Definition: sig_ss7.h:278
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define AST_CHANNEL_NAME
Definition: channel.h:172
int(*const play_tone)(void *pvt, enum sig_ss7_tone tone)
Definition: sig_ss7.h:167
char called_nai
Definition: sig_ss7.h:337
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
int orig_called_presentation
Definition: sig_ss7.h:255
#define SIG_SS7_DEBUG_DEFAULT
Definition: sig_ss7.h:51
char jip_number[50]
Definition: sig_ss7.h:271
#define AST_CAUSE_INTERWORKING
Definition: causes.h:145
struct ast_party_redirecting_reason reason
Reason for the redirection.
Definition: channel.h:543
void sig_ss7_link_alarm(struct sig_ss7_linkset *linkset, int which)
char cid_num[AST_MAX_EXTENSION]
Definition: sig_ss7.h:244
char networkroutedprefix[20]
Definition: sig_ss7.h:343
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
char nationalprefix[10]
Definition: sig_ss7.h:340
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
#define AST_PRES_RESTRICTION
Definition: callerid.h:323
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
Definition: chan_dahdi.c:13058
unsigned int locallyblocked
Bitmask for the channel being locally blocked.
Definition: sig_ss7.h:228
unsigned int immediate
Definition: sig_ss7.h:221
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition: channel.c:2179
void sig_ss7_chan_delete(struct sig_ss7_chan *doomed)
void(*const queue_control)(void *pvt, int subclass)
Definition: sig_ss7.h:180
int sig_ss7_hangup(struct sig_ss7_chan *p, struct ast_channel *ast)
int count
Number of times the call was redirected.
Definition: channel.h:549
Standard Command Line Interface.
int sig_ss7_add_sigchan(struct sig_ss7_linkset *linkset, int which, int ss7type, int transport, int inalarm, int networkindicator, int pointcode, int adjpointcode, int cur_slc)
int ast_channel_hangupcause(const struct ast_channel *chan)
struct ast_party_id to
Call is redirecting to a new party (Sent to the caller)
Definition: channel.h:531
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char gen_dig_number[50]
Definition: sig_ss7.h:253
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
void(*const set_inservice)(void *pvt, int is_inservice)
Definition: sig_ss7.h:174
const char * ast_channel_name(const struct ast_channel *chan)
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition: channel.c:2122
void(*const set_callerid)(void *pvt, const struct ast_party_caller *caller)
Definition: sig_ss7.h:177
#define AST_CAUSE_USER_BUSY
Definition: causes.h:106
int ast_callid_threadstorage_auto(ast_callid *callid)
Checks thread storage for a callid and stores a reference if it exists. If not, then a new one will b...
Definition: logger.c:2020
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7486
#define AST_PRES_ALLOWED
Definition: callerid.h:324
char * ast_transfercapability2str(int transfercapability) attribute_const
Gives the string form of a given transfer capability.
Definition: channel.c:678
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame with payload.
Definition: channel.c:1238
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
struct ast_channel * owner
Definition: sig_ss7.h:192
void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
char internationalprefix[10]
Definition: sig_ss7.h:339
unsigned int called_complete
TRUE if the channel has completed collecting digits.
Definition: sig_ss7.h:294
struct isup_call * ss7call
Opaque libss7 call control structure.
Definition: sig_ss7.h:195
void(*const deadlock_avoidance_private)(void *pvt)
Definition: sig_ss7.h:159
int sig_ss7_answer(struct sig_ss7_chan *p, struct ast_channel *ast)
char cid_ani[AST_MAX_EXTENSION]
Definition: sig_ss7.h:247
unsigned int do_hangup
Definition: sig_ss7.h:281
void(*const handle_link_exception)(struct sig_ss7_linkset *linkset, int which)
Definition: sig_ss7.h:169
#define AST_PRES_UNAVAILABLE
Definition: callerid.h:326
#define ast_mutex_init(pmutex)
Definition: lock.h:184
#define ast_channel_trylock(chan)
Definition: channel.h:2947
#define LINKSET_FLAG_DEFAULTECHOCONTROL
Definition: sig_ss7.h:71
void(*const unlock_private)(void *pvt)
Definition: sig_ss7.h:155
void sig_ss7_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_ss7_chan *pchan)
unsigned char gen_add_nai
Definition: sig_ss7.h:266
void ast_party_caller_init(struct ast_party_caller *init)
Initialize the given caller structure.
Definition: channel.c:1978
int sig_ss7_cb_hangup(struct ss7 *ss7, int cic, unsigned int dpc, int cause, int do_hangup)
char connected
Definition: eagi_proxy.c:82
#define SS7_BLOCKED_MAINTENANCE
Definition: sig_ss7.h:74
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:298
ast_callid ast_channel_callid(const struct ast_channel *chan)
sig_ss7_law
Definition: sig_ss7.h:88
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel. ...
Definition: channel.c:4391
unsigned int echocontrol_ind
Definition: sig_ss7.h:282
#define AST_CAUSE_CONGESTION
Definition: causes.h:152
void * ss7_linkset(void *data)
#define AST_TRANS_CAP_DIGITAL
Definition: transcap.h:35
#define LINKSET_FLAG_AUTOACM
Definition: sig_ss7.h:72
jack_status_t status
Definition: app_jack.c:146
unsigned char calling_party_cat
Definition: sig_ss7.h:280
unsigned char redirect_counter
Definition: sig_ss7.h:258
#define ast_mutex_unlock(a)
Definition: lock.h:188
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343
void sig_ss7_cb_call_null(struct ss7 *ss7, struct isup_call *c, int lock)