sig_ss7.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. #define LINKSET_FLAG_INITIALHWBLO (1 << 1)
  57. #define LINKSET_FLAG_USEECHOCONTROL (1 << 2)
  58. #define LINKSET_FLAG_DEFAULTECHOCONTROL (1 << 3)
  59. #define LINKSET_FLAG_AUTOACM (1 << 4)
  60. #define SS7_BLOCKED_MAINTENANCE (1 << 0)
  61. #define SS7_BLOCKED_HARDWARE (1 << 1)
  62. enum sig_ss7_tone {
  63. SIG_SS7_TONE_RINGTONE = 0,
  64. SIG_SS7_TONE_STUTTER,
  65. SIG_SS7_TONE_CONGESTION,
  66. SIG_SS7_TONE_DIALTONE,
  67. SIG_SS7_TONE_DIALRECALL,
  68. SIG_SS7_TONE_INFO,
  69. SIG_SS7_TONE_BUSY,
  70. };
  71. enum sig_ss7_law {
  72. SIG_SS7_DEFLAW = 0,
  73. SIG_SS7_ULAW,
  74. SIG_SS7_ALAW
  75. };
  76. enum sig_ss7_redirect_idication {
  77. SS7_INDICATION_NO_REDIRECTION = 0,
  78. SS7_INDICATION_REROUTED_PRES_ALLOWED,
  79. SS7_INDICATION_REROUTED_INFO_RESTRICTED,
  80. SS7_INDICATION_DIVERTED_PRES_ALLOWED,
  81. SS7_INDICATION_DIVERTED_INFO_RESTRICTED,
  82. SS7_INDICATION_REROUTED_PRES_RESTRICTED,
  83. SS7_INDICATION_DIVERTED_PRES_RESTRICTED,
  84. SS7_INDICATION_SPARE
  85. };
  86. enum sig_ss7_redirect_reason {
  87. SS7_REDIRECTING_REASON_UNKNOWN = 0,
  88. SS7_REDIRECTING_REASON_USER_BUSY,
  89. SS7_REDIRECTING_REASON_NO_ANSWER,
  90. SS7_REDIRECTING_REASON_UNCONDITIONAL,
  91. SS7_REDIRECTING_REASON_DEFLECTION_DURING_ALERTING,
  92. SS7_REDIRECTING_REASON_DEFLECTION_IMMEDIATE_RESPONSE,
  93. SS7_REDIRECTING_REASON_UNAVAILABLE
  94. };
  95. /*! Call establishment life cycle level for simple comparisons. */
  96. enum sig_ss7_call_level {
  97. /*! Call does not exist. */
  98. SIG_SS7_CALL_LEVEL_IDLE,
  99. /*!
  100. * Call is allocated to the channel.
  101. * We have not sent or responded to IAM yet.
  102. */
  103. SIG_SS7_CALL_LEVEL_ALLOCATED,
  104. /*!
  105. * Call is performing continuity check after receiving IAM.
  106. * We are waiting for COT to proceed further.
  107. */
  108. SIG_SS7_CALL_LEVEL_CONTINUITY,
  109. /*!
  110. * Call is present.
  111. * We have not seen a response or sent further call progress to an IAM yet.
  112. */
  113. SIG_SS7_CALL_LEVEL_SETUP,
  114. /*!
  115. * Call routing is happening.
  116. * We have sent or received ACM.
  117. */
  118. SIG_SS7_CALL_LEVEL_PROCEEDING,
  119. /*!
  120. * Called party is being alerted of the call.
  121. * We have sent or received CPG(ALERTING)/ACM(ALERTING).
  122. */
  123. SIG_SS7_CALL_LEVEL_ALERTING,
  124. /*!
  125. * Call is connected/answered.
  126. * We have sent or received CON/ANM.
  127. */
  128. SIG_SS7_CALL_LEVEL_CONNECT,
  129. };
  130. struct sig_ss7_linkset;
  131. struct sig_ss7_callback {
  132. /* Unlock the private in the signaling private structure. */
  133. void (* const unlock_private)(void *pvt);
  134. /* Lock the private in the signaling private structure. */
  135. void (* const lock_private)(void *pvt);
  136. /* Do deadlock avoidance for the private signaling structure lock. */
  137. void (* const deadlock_avoidance_private)(void *pvt);
  138. int (* const set_echocanceller)(void *pvt, int enable);
  139. void (* const set_loopback)(void *pvt, int enable);
  140. struct ast_channel * (* const new_ast_channel)(void *pvt, int state,
  141. enum sig_ss7_law law, char *exten, const struct ast_assigned_ids *assignedids,
  142. const struct ast_channel *requestor);
  143. int (* const play_tone)(void *pvt, enum sig_ss7_tone tone);
  144. void (* const handle_link_exception)(struct sig_ss7_linkset *linkset, int which);
  145. void (* const set_alarm)(void *pvt, int in_alarm);
  146. void (* const set_dialing)(void *pvt, int is_dialing);
  147. void (* const set_digital)(void *pvt, int is_digital);
  148. void (* const set_outgoing)(void *pvt, int is_outgoing);
  149. void (* const set_inservice)(void *pvt, int is_inservice);
  150. void (* const set_locallyblocked)(void *pvt, int is_blocked);
  151. void (* const set_remotelyblocked)(void *pvt, int is_blocked);
  152. void (* const set_callerid)(void *pvt, const struct ast_party_caller *caller);
  153. void (* const set_dnid)(void *pvt, const char *dnid);
  154. void (* const queue_control)(void *pvt, int subclass);
  155. void (* const open_media)(void *pvt);
  156. struct sig_ss7_linkset *(* const find_linkset)(struct ss7 *ss7);
  157. };
  158. /*! Global sig_ss7 callbacks to the upper layer. */
  159. extern struct sig_ss7_callback sig_ss7_callbacks;
  160. struct sig_ss7_chan {
  161. void *chan_pvt; /*!< Private structure of the user of this module. */
  162. struct sig_ss7_linkset *ss7;
  163. struct ast_channel *owner;
  164. /*! \brief Opaque libss7 call control structure */
  165. struct isup_call *ss7call;
  166. /*! Call establishment life cycle level for simple comparisons. */
  167. enum sig_ss7_call_level call_level;
  168. int channel; /*!< Channel Number */
  169. int cic; /*!< CIC associated with channel */
  170. unsigned int dpc; /*!< CIC's DPC */
  171. /* Options to be set by user */
  172. /*!
  173. * \brief Number of most significant digits/characters to strip from the dialed number.
  174. * \note Feature is deprecated. Use dialplan logic.
  175. */
  176. int stripmsd;
  177. /*!
  178. * \brief TRUE if the outgoing caller ID is blocked/hidden.
  179. */
  180. unsigned int hidecallerid:1;
  181. /*! \brief TRUE if caller ID is used on this channel. */
  182. unsigned int use_callerid:1;
  183. /*!
  184. * \brief TRUE if we will use the calling presentation setting
  185. * from the Asterisk channel for outgoing calls.
  186. */
  187. unsigned int use_callingpres:1;
  188. unsigned int immediate:1; /*!< Answer before getting digits? */
  189. /*!
  190. * \brief Bitmask for the channel being locally blocked.
  191. * \note 1 maintenance blocked, 2 blocked in hardware.
  192. * \note Set by user and link.
  193. */
  194. unsigned int locallyblocked:2;
  195. /*!
  196. * \brief Bitmask for the channel being remotely blocked.
  197. * \note 1 maintenance blocked, 2 blocked in hardware.
  198. * \note Set by user and link.
  199. */
  200. unsigned int remotelyblocked:2;
  201. char context[AST_MAX_CONTEXT];
  202. char mohinterpret[MAX_MUSICCLASS];
  203. /* Options to be checked by user */
  204. int cid_ani2; /*!< Automatic Number Identification number (Alternate PRI caller ID number) */
  205. int cid_ton; /*!< Type Of Number (TON) */
  206. int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
  207. char cid_num[AST_MAX_EXTENSION];
  208. char cid_subaddr[AST_MAX_EXTENSION];/*!< XXX SS7 may not support. */
  209. char cid_name[AST_MAX_EXTENSION];
  210. char cid_ani[AST_MAX_EXTENSION];
  211. char exten[AST_MAX_EXTENSION];
  212. /* Options to be checked by user that are stuffed into channel variables. */
  213. char charge_number[50];
  214. char gen_add_number[50];
  215. char gen_dig_number[50];
  216. char orig_called_num[50];
  217. int orig_called_presentation;
  218. char redirecting_num[50];
  219. int redirecting_presentation;
  220. unsigned char redirect_counter;
  221. unsigned char redirect_info;
  222. unsigned char redirect_info_ind;
  223. unsigned char redirect_info_orig_reas;
  224. unsigned char redirect_info_counter;
  225. unsigned char redirect_info_reas;
  226. char generic_name[50];
  227. unsigned char gen_add_num_plan;
  228. unsigned char gen_add_nai;
  229. unsigned char gen_add_pres_ind;
  230. unsigned char gen_add_type;
  231. unsigned char gen_dig_type;
  232. unsigned char gen_dig_scheme;
  233. char jip_number[50];
  234. #if 0
  235. unsigned char lspi_type;
  236. unsigned char lspi_scheme;
  237. unsigned char lspi_context;
  238. #endif
  239. char lspi_ident[50];
  240. unsigned int call_ref_ident;
  241. unsigned int call_ref_pc;
  242. unsigned char calling_party_cat;
  243. unsigned int do_hangup; /* What we have to do to clear the call */
  244. unsigned int echocontrol_ind;
  245. /*
  246. * Channel status bits.
  247. */
  248. /*! \brief TRUE if channel is associated with a link that is down. */
  249. unsigned int inalarm:1;
  250. /*! \brief TRUE if channel is in service. */
  251. unsigned int inservice:1;
  252. /*! \brief TRUE if this channel is being used for an outgoing call. */
  253. unsigned int outgoing:1;
  254. /*! \brief TRUE if the channel has completed collecting digits. */
  255. unsigned int called_complete:1;
  256. /*! \brief TRUE if the call has seen inband-information progress through the network. */
  257. unsigned int progress:1;
  258. /*! \brief XXX BOOLEAN Purpose??? */
  259. unsigned int rlt:1;
  260. /*! \brief TRUE if this channel is in loopback. */
  261. unsigned int loopedback:1;
  262. /*
  263. * Closed User Group fields Q.735.1
  264. */
  265. /*! \brief Network Identify Code as per Q.763 3.15.a */
  266. char cug_interlock_ni[5];
  267. /*! \brief Binari Code to uniquely identify a CUG inside the network. */
  268. unsigned short cug_interlock_code;
  269. /*!
  270. * \brief Indication of the call being a CUG call and its permissions.
  271. * \note 0 or 1 - non-CUG call
  272. * \note 2 - CUG call, outgoing access alowed
  273. * \note 3 - CUG call, outgoing access not alowed
  274. */
  275. unsigned char cug_indicator;
  276. };
  277. struct sig_ss7_linkset {
  278. pthread_t master; /*!< Thread of master */
  279. ast_mutex_t lock; /*!< libss7 access lock */
  280. struct ss7 *ss7;
  281. struct sig_ss7_chan *pvts[SIG_SS7_MAX_CHANNELS];/*!< Member channel pvt structs */
  282. int fds[SIG_SS7_NUM_DCHANS];
  283. int numsigchans;
  284. int linkstate[SIG_SS7_NUM_DCHANS];
  285. int numchans;
  286. int span; /*!< span number put into user output messages */
  287. int debug; /*!< set to true if to dump SS7 event info */
  288. enum {
  289. LINKSET_STATE_DOWN = 0,
  290. LINKSET_STATE_UP
  291. } state;
  292. /* Options to be set by user */
  293. int flags; /*!< Linkset flags (LINKSET_FLAG_EXPLICITACM) */
  294. int type; /*!< SS7 type ITU/ANSI. Used for companding selection. */
  295. char called_nai; /*!< Called Nature of Address Indicator */
  296. char calling_nai; /*!< Calling Nature of Address Indicator */
  297. char internationalprefix[10]; /*!< country access code ('00' for european dialplans) */
  298. char nationalprefix[10]; /*!< area access code ('0' for european dialplans) */
  299. char subscriberprefix[20]; /*!< area access code + area code ('0'+area code for european dialplans) */
  300. char unknownprefix[20]; /*!< for unknown dialplans */
  301. char networkroutedprefix[20];
  302. };
  303. void sig_ss7_set_alarm(struct sig_ss7_chan *p, int in_alarm);
  304. void *ss7_linkset(void *data);
  305. void sig_ss7_link_alarm(struct sig_ss7_linkset *linkset, int which);
  306. void sig_ss7_link_noalarm(struct sig_ss7_linkset *linkset, int which);
  307. 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);
  308. int sig_ss7_reset_cic(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc);
  309. int sig_ss7_reset_group(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc, int range);
  310. int sig_ss7_cic_blocking(struct sig_ss7_linkset *linkset, int do_block, int cic);
  311. int sig_ss7_group_blocking(struct sig_ss7_linkset *linkset, int do_block, int startcic, int endcic, unsigned char state[], int type);
  312. int sig_ss7_available(struct sig_ss7_chan *p);
  313. int sig_ss7_call(struct sig_ss7_chan *p, struct ast_channel *ast, const char *rdest);
  314. int sig_ss7_hangup(struct sig_ss7_chan *p, struct ast_channel *ast);
  315. int sig_ss7_answer(struct sig_ss7_chan *p, struct ast_channel *ast);
  316. int sig_ss7_find_cic(struct sig_ss7_linkset *linkset, int cic, unsigned int dpc);
  317. int sig_ss7_find_cic_range(struct sig_ss7_linkset *linkset, int startcic, int endcic, unsigned int dpc);
  318. void sig_ss7_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_ss7_chan *pchan);
  319. int sig_ss7_indicate(struct sig_ss7_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen);
  320. struct ast_channel *sig_ss7_request(struct sig_ss7_chan *p, enum sig_ss7_law law,
  321. const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor,
  322. int transfercapability);
  323. void sig_ss7_chan_delete(struct sig_ss7_chan *doomed);
  324. struct sig_ss7_chan *sig_ss7_chan_new(void *pvt_data, struct sig_ss7_linkset *ss7);
  325. void sig_ss7_init_linkset(struct sig_ss7_linkset *ss7);
  326. void sig_ss7_free_isup_call(struct sig_ss7_linkset *linkset, int channel);
  327. void sig_ss7_cli_show_channels_header(int fd);
  328. void sig_ss7_cli_show_channels(int fd, struct sig_ss7_linkset *linkset);
  329. int sig_ss7_cb_hangup(struct ss7 *ss7, int cic, unsigned int dpc, int cause, int do_hangup);
  330. void sig_ss7_cb_call_null(struct ss7 *ss7, struct isup_call *c, int lock);
  331. void sig_ss7_cb_notinservice(struct ss7 *ss7, int cic, unsigned int dpc);
  332. /* ------------------------------------------------------------------- */
  333. #ifdef __cplusplus
  334. }
  335. #endif
  336. #endif /* _ASTERISK_SIG_SS7_H */
  337. /* ------------------------------------------------------------------- */
  338. /* end sig_ss7.h */