sig_ss7.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2010 Digium, Inc.
  5. *
  6. * Richard Mudgett <rmudgett@digium.com>
  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. * \file
  20. * \brief Interface header for SS7 signaling module.
  21. *
  22. * \author Matthew Fredrickson <creslin@digium.com>
  23. * \author Richard Mudgett <rmudgett@digium.com>
  24. *
  25. * See Also:
  26. * \arg \ref AstCREDITS
  27. */
  28. #ifndef _ASTERISK_SIG_SS7_H
  29. #define _ASTERISK_SIG_SS7_H
  30. #include "asterisk/channel.h"
  31. #include <libss7.h>
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /* ------------------------------------------------------------------- */
  36. /*! SS7 debug message flags when SS7 debugging is turned on at the command line. */
  37. #define SIG_SS7_DEBUG \
  38. (SS7_DEBUG_MTP2 | SS7_DEBUG_MTP3 | SS7_DEBUG_ISUP)
  39. #if 0
  40. /*! SS7 debug message flags set on initial startup. */
  41. #define SIG_SS7_DEBUG_DEFAULT SIG_SS7_DEBUG
  42. #else
  43. /*! SS7 debug message flags set on initial startup. */
  44. #define SIG_SS7_DEBUG_DEFAULT 0
  45. #endif
  46. /* ------------------------------------------------------------------- */
  47. #define SIG_SS7_NUM_DCHANS 4 /*!< No more than 4 d-channels */
  48. #define SIG_SS7_MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
  49. #define SIG_SS7 (0x1000000 | DAHDI_SIG_CLEAR)
  50. #define LINKSTATE_INALARM (1 << 0)
  51. #define LINKSTATE_STARTING (1 << 1)
  52. #define LINKSTATE_UP (1 << 2)
  53. #define LINKSTATE_DOWN (1 << 3)
  54. #define SS7_NAI_DYNAMIC -1
  55. #define LINKSET_FLAG_EXPLICITACM (1 << 0)
  56. enum sig_ss7_tone {
  57. SIG_SS7_TONE_RINGTONE = 0,
  58. SIG_SS7_TONE_STUTTER,
  59. SIG_SS7_TONE_CONGESTION,
  60. SIG_SS7_TONE_DIALTONE,
  61. SIG_SS7_TONE_DIALRECALL,
  62. SIG_SS7_TONE_INFO,
  63. SIG_SS7_TONE_BUSY,
  64. };
  65. enum sig_ss7_law {
  66. SIG_SS7_DEFLAW = 0,
  67. SIG_SS7_ULAW,
  68. SIG_SS7_ALAW
  69. };
  70. /*! Call establishment life cycle level for simple comparisons. */
  71. enum sig_ss7_call_level {
  72. /*! Call does not exist. */
  73. SIG_SS7_CALL_LEVEL_IDLE,
  74. /*!
  75. * Call is allocated to the channel.
  76. * We have not sent or responded to IAM yet.
  77. */
  78. SIG_SS7_CALL_LEVEL_ALLOCATED,
  79. /*!
  80. * Call is performing continuity check after receiving IAM.
  81. * We are waiting for COT to proceed further.
  82. */
  83. SIG_SS7_CALL_LEVEL_CONTINUITY,
  84. /*!
  85. * Call is present.
  86. * We have not seen a response or sent further call progress to an IAM yet.
  87. */
  88. SIG_SS7_CALL_LEVEL_SETUP,
  89. /*!
  90. * Call routing is happening.
  91. * We have sent or received ACM.
  92. */
  93. SIG_SS7_CALL_LEVEL_PROCEEDING,
  94. /*!
  95. * Called party is being alerted of the call.
  96. * We have sent or received CPG(ALERTING)/ACM(ALERTING).
  97. */
  98. SIG_SS7_CALL_LEVEL_ALERTING,
  99. /*!
  100. * Call is connected/answered.
  101. * We have sent or received CON/ANM.
  102. */
  103. SIG_SS7_CALL_LEVEL_CONNECT,
  104. /*! Call has collided with incoming call. */
  105. SIG_SS7_CALL_LEVEL_GLARE,
  106. };
  107. struct sig_ss7_linkset;
  108. struct sig_ss7_callback {
  109. /* Unlock the private in the signaling private structure. */
  110. void (* const unlock_private)(void *pvt);
  111. /* Lock the private in the signaling private structure. */
  112. void (* const lock_private)(void *pvt);
  113. /* Do deadlock avoidance for the private signaling structure lock. */
  114. void (* const deadlock_avoidance_private)(void *pvt);
  115. int (* const set_echocanceller)(void *pvt, int enable);
  116. void (* const set_loopback)(void *pvt, int enable);
  117. struct ast_channel * (* const new_ast_channel)(void *pvt, int state, enum sig_ss7_law law, char *exten, const struct ast_channel *requestor);
  118. int (* const play_tone)(void *pvt, enum sig_ss7_tone tone);
  119. void (* const handle_link_exception)(struct sig_ss7_linkset *linkset, int which);
  120. void (* const set_alarm)(void *pvt, int in_alarm);
  121. void (* const set_dialing)(void *pvt, int is_dialing);
  122. void (* const set_digital)(void *pvt, int is_digital);
  123. void (* const set_outgoing)(void *pvt, int is_outgoing);
  124. void (* const set_inservice)(void *pvt, int is_inservice);
  125. void (* const set_locallyblocked)(void *pvt, int is_blocked);
  126. void (* const set_remotelyblocked)(void *pvt, int is_blocked);
  127. void (* const set_callerid)(void *pvt, const struct ast_party_caller *caller);
  128. void (* const set_dnid)(void *pvt, const char *dnid);
  129. void (* const queue_control)(void *pvt, int subclass);
  130. void (* const open_media)(void *pvt);
  131. };
  132. struct sig_ss7_chan {
  133. struct sig_ss7_callback *calls;
  134. void *chan_pvt; /*!< Private structure of the user of this module. */
  135. struct sig_ss7_linkset *ss7;
  136. struct ast_channel *owner;
  137. /*! \brief Opaque libss7 call control structure */
  138. struct isup_call *ss7call;
  139. /*! Call establishment life cycle level for simple comparisons. */
  140. enum sig_ss7_call_level call_level;
  141. int channel; /*!< Channel Number */
  142. int cic; /*!< CIC associated with channel */
  143. unsigned int dpc; /*!< CIC's DPC */
  144. /* Options to be set by user */
  145. /*!
  146. * \brief Number of most significant digits/characters to strip from the dialed number.
  147. * \note Feature is deprecated. Use dialplan logic.
  148. */
  149. int stripmsd;
  150. /*!
  151. * \brief TRUE if the outgoing caller ID is blocked/hidden.
  152. */
  153. unsigned int hidecallerid:1;
  154. /*! \brief TRUE if caller ID is used on this channel. */
  155. unsigned int use_callerid:1;
  156. /*!
  157. * \brief TRUE if we will use the calling presentation setting
  158. * from the Asterisk channel for outgoing calls.
  159. */
  160. unsigned int use_callingpres:1;
  161. unsigned int immediate:1; /*!< Answer before getting digits? */
  162. /*! \brief TRUE if the channel is locally blocked. Set by user and link. */
  163. unsigned int locallyblocked:1;
  164. /*! \brief TRUE if the channel is remotely blocked. Set by user and link. */
  165. unsigned int remotelyblocked:1;
  166. char context[AST_MAX_CONTEXT];
  167. char mohinterpret[MAX_MUSICCLASS];
  168. /* Options to be checked by user */
  169. int cid_ani2; /*!< Automatic Number Identification number (Alternate PRI caller ID number) */
  170. int cid_ton; /*!< Type Of Number (TON) */
  171. int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
  172. char cid_num[AST_MAX_EXTENSION];
  173. char cid_subaddr[AST_MAX_EXTENSION];/*!< XXX SS7 may not support. */
  174. char cid_name[AST_MAX_EXTENSION];
  175. char cid_ani[AST_MAX_EXTENSION];
  176. char exten[AST_MAX_EXTENSION];
  177. /* Options to be checked by user that are stuffed into channel variables. */
  178. char charge_number[50];
  179. char gen_add_number[50];
  180. char gen_dig_number[50];
  181. char orig_called_num[50];
  182. char redirecting_num[50];
  183. char generic_name[50];
  184. unsigned char gen_add_num_plan;
  185. unsigned char gen_add_nai;
  186. unsigned char gen_add_pres_ind;
  187. unsigned char gen_add_type;
  188. unsigned char gen_dig_type;
  189. unsigned char gen_dig_scheme;
  190. char jip_number[50];
  191. #if 0
  192. unsigned char lspi_type;
  193. unsigned char lspi_scheme;
  194. unsigned char lspi_context;
  195. #endif
  196. char lspi_ident[50];
  197. unsigned int call_ref_ident;
  198. unsigned int call_ref_pc;
  199. unsigned char calling_party_cat;
  200. /*
  201. * Channel status bits.
  202. */
  203. /*! TRUE if channel is associated with a link that is down. */
  204. unsigned int inalarm:1;
  205. /*! TRUE if this channel is being used for an outgoing call. */
  206. unsigned int outgoing:1;
  207. /*! \brief TRUE if the call has seen inband-information progress through the network. */
  208. unsigned int progress:1;
  209. /*! \brief TRUE if the call has already gone/hungup */
  210. unsigned int alreadyhungup:1;
  211. /*! \brief XXX BOOLEAN Purpose??? */
  212. unsigned int rlt:1;
  213. /*! TRUE if this channel is in loopback. */
  214. unsigned int loopedback:1;
  215. };
  216. struct sig_ss7_linkset {
  217. pthread_t master; /*!< Thread of master */
  218. ast_mutex_t lock; /*!< libss7 access lock */
  219. struct sig_ss7_callback *calls;
  220. struct ss7 *ss7;
  221. struct sig_ss7_chan *pvts[SIG_SS7_MAX_CHANNELS];/*!< Member channel pvt structs */
  222. int fds[SIG_SS7_NUM_DCHANS];
  223. int numsigchans;
  224. int linkstate[SIG_SS7_NUM_DCHANS];
  225. int numchans;
  226. int span; /*!< span number put into user output messages */
  227. int debug; /*!< set to true if to dump SS7 event info */
  228. enum {
  229. LINKSET_STATE_DOWN = 0,
  230. LINKSET_STATE_UP
  231. } state;
  232. /* Options to be set by user */
  233. int flags; /*!< Linkset flags (LINKSET_FLAG_EXPLICITACM) */
  234. int type; /*!< SS7 type ITU/ANSI. Used for companding selection. */
  235. char called_nai; /*!< Called Nature of Address Indicator */
  236. char calling_nai; /*!< Calling Nature of Address Indicator */
  237. char internationalprefix[10]; /*!< country access code ('00' for european dialplans) */
  238. char nationalprefix[10]; /*!< area access code ('0' for european dialplans) */
  239. char subscriberprefix[20]; /*!< area access code + area code ('0'+area code for european dialplans) */
  240. char unknownprefix[20]; /*!< for unknown dialplans */
  241. };
  242. void sig_ss7_set_alarm(struct sig_ss7_chan *p, int in_alarm);
  243. void *ss7_linkset(void *data);
  244. void sig_ss7_link_alarm(struct sig_ss7_linkset *linkset, int which);
  245. void sig_ss7_link_noalarm(struct sig_ss7_linkset *linkset, int which);
  246. int sig_ss7_add_sigchan(struct sig_ss7_linkset *linkset, int which, int ss7type, int transport, int inalarm, int networkindicator, int pointcode, int adjpointcode);
  247. int sig_ss7_available(struct sig_ss7_chan *p);
  248. int sig_ss7_call(struct sig_ss7_chan *p, struct ast_channel *ast, char *rdest);
  249. int sig_ss7_hangup(struct sig_ss7_chan *p, struct ast_channel *ast);
  250. int sig_ss7_answer(struct sig_ss7_chan *p, struct ast_channel *ast);
  251. void sig_ss7_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_ss7_chan *pchan);
  252. int sig_ss7_indicate(struct sig_ss7_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen);
  253. struct ast_channel *sig_ss7_request(struct sig_ss7_chan *p, enum sig_ss7_law law, const struct ast_channel *requestor, int transfercapability);
  254. void sig_ss7_chan_delete(struct sig_ss7_chan *doomed);
  255. struct sig_ss7_chan *sig_ss7_chan_new(void *pvt_data, struct sig_ss7_callback *callback, struct sig_ss7_linkset *ss7);
  256. void sig_ss7_init_linkset(struct sig_ss7_linkset *ss7);
  257. void sig_ss7_cli_show_channels_header(int fd);
  258. void sig_ss7_cli_show_channels(int fd, struct sig_ss7_linkset *linkset);
  259. /* ------------------------------------------------------------------- */
  260. #ifdef __cplusplus
  261. }
  262. #endif
  263. #endif /* _ASTERISK_SIG_SS7_H */
  264. /* ------------------------------------------------------------------- */
  265. /* end sig_ss7.h */