2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2004 - 2006, Christian Richter
6 * Christian Richter <crich@beronet.com>
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.
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.
23 * \brief the chan_misdn channel driver for Asterisk
25 * \author Christian Richter <crich@beronet.com>
27 * MISDN http://www.misdn.org/
29 * \ingroup channel_drivers
32 /*! \li \ref chan_misdn.c uses the configuration file \ref misdn.conf
33 * \addtogroup configuration_file
36 /*! \page misdn.conf misdn.conf
37 * \verbinclude misdn.conf.sample
42 * To use the CCBS/CCNR supplementary service feature and other
43 * supplementary services using FACILITY messages requires a
44 * modified version of mISDN.
47 * The latest modified mISDN v1.1.x based version is available at:
48 * http://svn.digium.com/svn/thirdparty/mISDN/trunk
49 * http://svn.digium.com/svn/thirdparty/mISDNuser/trunk
52 * Taged versions of the modified mISDN code are available under:
53 * http://svn.digium.com/svn/thirdparty/mISDN/tags
54 * http://svn.digium.com/svn/thirdparty/mISDNuser/tags
57 /* Define to enable cli commands to generate canned CCBS messages. */
58 // #define CCBS_TEST_MESSAGES 1
61 * XXX The mISDN channel driver needs its native bridge code
62 * converted to the new bridge technology scheme. The
63 * chan_dahdi native bridge code can be used as an example. It
64 * is unlikely that this will ever get done. Support for this
65 * channel driver is dwindling because the supported version of
66 * mISDN does not support newer kernels.
68 * Without native bridge support, the following config file
69 * parameters have no effect: bridging.
71 * The existing native bridge code is marked with the
72 * mISDN_NATIVE_BRIDGING conditional.
76 <depend>isdnnet</depend>
77 <depend>misdn</depend>
78 <depend>suppserv</depend>
79 <support_level>deprecated</support_level>
80 <replacement>chan_dahdi</replacement>
86 #include <sys/socket.h>
88 #include <arpa/inet.h>
90 #include <sys/ioctl.h>
93 #include <semaphore.h>
97 #include "asterisk/channel.h"
98 #include "asterisk/config.h"
99 #include "asterisk/module.h"
100 #include "asterisk/pbx.h"
101 #include "asterisk/io.h"
102 #include "asterisk/frame.h"
103 #include "asterisk/translate.h"
104 #include "asterisk/cli.h"
105 #include "asterisk/musiconhold.h"
106 #include "asterisk/dsp.h"
107 #include "asterisk/file.h"
108 #include "asterisk/callerid.h"
109 #include "asterisk/indications.h"
110 #include "asterisk/app.h"
111 #include "asterisk/features.h"
112 #include "asterisk/term.h"
113 #include "asterisk/sched.h"
114 #include "asterisk/stringfields.h"
115 #include "asterisk/abstract_jb.h"
116 #include "asterisk/causes.h"
117 #include "asterisk/format.h"
118 #include "asterisk/format_cap.h"
119 #include "asterisk/features_config.h"
120 #include "asterisk/bridge.h"
121 #include "asterisk/pickup.h"
122 #include "asterisk/format_cache.h"
124 #include "chan_misdn_config.h"
125 #include "isdn_lib.h"
127 static char global_tracefile[BUFFERSIZE + 1];
129 static int g_config_initialized = 0;
143 /*! \brief allocates the jb-structure and initialize the elements */
144 struct misdn_jb *misdn_jb_init(int size, int upper_threshold);
146 /*! \brief frees the data and destroys the given jitterbuffer struct */
147 void misdn_jb_destroy(struct misdn_jb *jb);
149 /*! \brief fills the jitterbuffer with len data returns < 0 if there was an
150 error (buffer overrun). */
151 int misdn_jb_fill(struct misdn_jb *jb, const char *data, int len);
153 /*! \brief gets len bytes out of the jitterbuffer if available, else only the
154 available data is returned and the return value indicates the number
156 int misdn_jb_empty(struct misdn_jb *jb, char *data, int len);
158 static char *complete_ch(struct ast_cli_args *a);
159 static char *complete_debug_port(struct ast_cli_args *a);
160 static char *complete_show_config(struct ast_cli_args *a);
162 /* BEGIN: chan_misdn.h */
164 #if defined(AST_MISDN_ENHANCEMENTS)
166 * This timeout duration is to clean up any call completion records that
167 * are forgotten about by the switch.
169 #define MISDN_CC_RECORD_AGE_MAX (6UL * 60 * 60) /* seconds */
171 #define MISDN_CC_REQUEST_WAIT_MAX 5 /* seconds */
174 * \brief Caller that initialized call completion services
177 * This data is the payload for a datastore that is put on the channel that
178 * initializes call completion services. This datastore is set to be inherited
179 * by the outbound mISDN channel. When one of these channels hangs up, the
180 * channel pointer will be set to NULL. That way, we can ensure that we do not
181 * touch this channel after it gets destroyed.
183 struct misdn_cc_caller {
184 /*! \brief The channel that initialized call completion services */
185 struct ast_channel *chan;
188 struct misdn_cc_notify {
189 /*! \brief Dialplan: Notify extension priority */
192 /*! \brief Dialplan: Notify extension context */
193 char context[AST_MAX_CONTEXT];
195 /*! \brief Dialplan: Notify extension number (User-A) */
196 char exten[AST_MAX_EXTENSION];
199 /*! \brief mISDN call completion record */
200 struct misdn_cc_record {
201 /*! \brief Call completion record linked list */
202 AST_LIST_ENTRY(misdn_cc_record) list;
204 /*! \brief Time the record was created. */
207 /*! \brief MISDN_CC_RECORD_ID value */
211 * \brief Logical Layer 1 port associated with this
212 * call completion record
216 /*! \brief TRUE if point-to-point mode (CCBS-T/CCNR-T mode) */
219 /*! \brief Mode specific parameters */
221 /*! \brief point-to-point specific parameters. */
224 * \brief Call-completion signaling link.
225 * NULL if signaling link not established.
227 struct misdn_bchannel *bc;
230 * \brief TRUE if we requested the request retention option
233 int requested_retention;
236 * \brief TRUE if the request retention option is enabled.
238 int retention_enabled;
241 /*! \brief point-to-multi-point specific parameters. */
243 /*! \brief CallLinkageID (valid when port determined) */
246 /*! \breif CCBSReference (valid when activated is TRUE) */
249 /*! \brief globalRecall(0), specificRecall(1) */
254 /*! \brief TRUE if call completion activated */
257 /*! \brief Outstanding message ID (valid when outstanding_message) */
260 /*! \brief TRUE if waiting for a response from a message (invoke_id is valid) */
261 int outstanding_message;
263 /*! \brief TRUE if activation has been requested */
264 int activation_requested;
267 * \brief TRUE if User-A is free
268 * \note PTMP - Used to answer CCBSStatusRequest.
269 * PTP - Determines how to respond to CCBS_T_RemoteUserFree.
273 /*! \brief Error code received from last outstanding message. */
274 enum FacErrorCode error_code;
276 /*! \brief Reject code received from last outstanding message. */
277 enum FacRejectCode reject_code;
280 * \brief Saved struct misdn_bchannel call information when
281 * attempted to call User-B
284 /*! \brief User-A caller id information */
285 struct misdn_party_id caller;
287 /*! \brief User-B number information */
288 struct misdn_party_dialing dialed;
290 /*! \brief The BC, HLC (optional) and LLC (optional) contents from the SETUP message. */
291 struct Q931_Bc_Hlc_Llc setup_bc_hlc_llc;
293 /*! \brief SETUP message bearer capability field code value */
296 /*! \brief TRUE if call made in digital HDLC mode */
300 /*! \brief Dialplan location to indicate User-B free and User-A is free */
301 struct misdn_cc_notify remote_user_free;
303 /*! \brief Dialplan location to indicate User-B free and User-A is busy */
304 struct misdn_cc_notify b_free;
307 /*! \brief mISDN call completion record database */
308 static AST_LIST_HEAD_STATIC(misdn_cc_records_db, misdn_cc_record);
309 /*! \brief Next call completion record ID to use */
310 static __u16 misdn_cc_record_id;
311 /*! \brief Next invoke ID to use */
312 static __s16 misdn_invoke_id;
314 static const char misdn_no_response_from_network[] = "No response from network";
315 static const char misdn_cc_record_not_found[] = "Call completion record not found";
317 /* mISDN channel variable names */
318 #define MISDN_CC_RECORD_ID "MISDN_CC_RECORD_ID"
319 #define MISDN_CC_STATUS "MISDN_CC_STATUS"
320 #define MISDN_ERROR_MSG "MISDN_ERROR_MSG"
321 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
323 static ast_mutex_t release_lock;
325 enum misdn_chan_state {
326 MISDN_NOTHING = 0, /*!< at beginning */
327 MISDN_WAITING4DIGS, /*!< when waiting for info */
328 MISDN_EXTCANTMATCH, /*!< when asterisk couldn't match our ext */
329 MISDN_INCOMING_SETUP, /*!< for incoming setup */
330 MISDN_DIALING, /*!< when pbx_start */
331 MISDN_PROGRESS, /*!< we have progress */
332 MISDN_PROCEEDING, /*!< we have progress */
333 MISDN_CALLING, /*!< when misdn_call is called */
334 MISDN_CALLING_ACKNOWLEDGE, /*!< when we get SETUP_ACK */
335 MISDN_ALERTING, /*!< when Alerting */
336 MISDN_BUSY, /*!< when BUSY */
337 MISDN_CONNECTED, /*!< when connected */
338 MISDN_DISCONNECTED, /*!< when connected */
339 MISDN_CLEANING, /*!< when hangup from * but we were connected before */
342 /*! Asterisk created the channel (outgoing call) */
344 /*! mISDN created the channel (incoming call) */
347 enum misdn_hold_state {
348 MISDN_HOLD_IDLE, /*!< HOLD not active */
349 MISDN_HOLD_ACTIVE, /*!< Call is held */
350 MISDN_HOLD_TRANSFER, /*!< Held call is being transferred */
351 MISDN_HOLD_DISCONNECT, /*!< Held call is being disconnected */
355 * \brief Call HOLD state.
357 enum misdn_hold_state state;
359 * \brief Logical port the channel call record is HELD on
360 * because the B channel is no longer associated.
365 * \brief Original B channel number the HELD call was using.
366 * \note Used only for debug display messages.
371 #define chan_list_ref(obj, debug) ao2_t_ref((obj), +1, (debug))
372 #define chan_list_unref(obj, debug) ao2_t_ref((obj), -1, (debug))
375 * \brief Channel call record structure
379 * \brief The "allowed_bearers" string read in from /etc/asterisk/misdn.conf
381 char allowed_bearers[BUFFERSIZE + 1];
384 * \brief State of the channel
386 enum misdn_chan_state state;
389 * \brief TRUE if a hangup needs to be queued
390 * \note This is a debug flag only used to catch calls to hangup_chan() that are already hungup.
392 int need_queue_hangup;
395 * \brief TRUE if a channel can be hung up by calling asterisk directly when done.
400 * \brief TRUE if we could send an AST_CONTROL_BUSY if needed.
405 * \brief Who originally created this channel. ORG_AST or ORG_MISDN
410 * \brief TRUE of we are not to respond immediately to a SETUP message. Check the dialplan first.
411 * \note The "noautorespond_on_setup" boolean read in from /etc/asterisk/misdn.conf
413 int noautorespond_on_setup;
415 int norxtone; /*!< Boolean assigned values but the value is not used. */
418 * \brief TRUE if we are not to generate tones (Playtones)
423 * \brief TRUE if echo canceller is enabled. Value is toggled.
428 * \brief TRUE if you want to send Tone Indications to an incoming
429 * ISDN channel on a TE Port.
430 * \note The "incoming_early_audio" boolean read in from /etc/asterisk/misdn.conf
432 int incoming_early_audio;
435 * \brief TRUE if DTMF digits are to be passed inband only.
436 * \note It is settable by the misdn_set_opt() application.
441 * \brief Pipe file descriptor handles array.
442 * Read from pipe[0], write to pipe[1]
447 * \brief Read buffer for inbound audio from pipe[0]
449 char ast_rd_buf[4096];
452 * \brief Inbound audio frame returned by misdn_read().
454 struct ast_frame frame;
457 * \brief Fax detection option. (0:no 1:yes 2:yes+nojump)
458 * \note The "faxdetect" option string read in from /etc/asterisk/misdn.conf
459 * \note It is settable by the misdn_set_opt() application.
464 * \brief Number of seconds to detect a Fax machine when detection enabled.
465 * \note 0 disables the timeout.
466 * \note The "faxdetect_timeout" value read in from /etc/asterisk/misdn.conf
468 int faxdetect_timeout;
471 * \brief Starting time of fax detection with timeout when nonzero.
473 struct timeval faxdetect_tv;
476 * \brief TRUE if a fax has been detected.
481 * \brief TRUE if we will use the Asterisk DSP to detect DTMF/Fax
482 * \note The "astdtmf" boolean read in from /etc/asterisk/misdn.conf
487 * \brief Jitterbuffer length
488 * \note The "jitterbuffer" value read in from /etc/asterisk/misdn.conf
493 * \brief Jitterbuffer upper threshold
494 * \note The "jitterbuffer_upper_threshold" value read in from /etc/asterisk/misdn.conf
496 int jb_upper_threshold;
499 * \brief Allocated jitterbuffer controller
500 * \note misdn_jb_init() creates the jitterbuffer.
501 * \note Must use misdn_jb_destroy() to clean up.
506 * \brief Allocated DSP controller
507 * \note ast_dsp_new() creates the DSP controller.
508 * \note Must use ast_dsp_free() to clean up.
513 * \brief Associated Asterisk channel structure.
515 struct ast_channel * ast;
518 * \brief Associated B channel structure.
520 struct misdn_bchannel *bc;
522 #if defined(AST_MISDN_ENHANCEMENTS)
524 * \brief Peer channel for which call completion was initialized.
526 struct misdn_cc_caller *peer;
528 /*! \brief Associated call completion record ID (-1 if not associated) */
530 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
533 * \brief HELD channel call information
535 struct hold_info hold;
538 * \brief From associated B channel: Layer 3 process ID
539 * \note Used to find the HELD channel call record when retrieving a call.
544 * \brief From associated B channel: B Channel mISDN driver layer ID from mISDN_get_layerid()
545 * \note Used only for debug display messages.
550 * \brief Incoming call dialplan context identifier.
551 * \note The "context" string read in from /etc/asterisk/misdn.conf
553 char context[AST_MAX_CONTEXT];
556 * \brief The configured music-on-hold class to use for this call.
557 * \note The "musicclass" string read in from /etc/asterisk/misdn.conf
559 char mohinterpret[MAX_MUSICCLASS];
562 * \brief Number of outgoing audio frames dropped since last debug gripe message.
564 int dropped_frame_cnt;
567 * \brief TRUE if we must do the ringback tones.
568 * \note The "far_alerting" boolean read in from /etc/asterisk/misdn.conf
573 * \brief TRUE if NT should disconnect an overlap dialing call when a timeout occurs.
574 * \note The "nttimeout" boolean read in from /etc/asterisk/misdn.conf
579 * \brief Tone zone sound used for dialtone generation.
580 * \note Used as a boolean. Non-NULL to prod generation if enabled.
582 struct ast_tone_zone_sound *ts;
585 * \brief Enables overlap dialing for the set amount of seconds. (0 = Disabled)
586 * \note The "overlapdial" value read in from /etc/asterisk/misdn.conf
591 * \brief Overlap dialing timeout Task ID. -1 if not running.
593 int overlap_dial_task;
596 * \brief overlap_tv access lock.
598 ast_mutex_t overlap_tv_lock;
601 * \brief Overlap timer start time. Timer restarted for every digit received.
603 struct timeval overlap_tv;
606 * \brief Next channel call record in the list.
608 struct chan_list *next;
615 void export_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
616 void import_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
617 static struct ast_frame *process_ast_dsp(struct chan_list *tmp, struct ast_frame *frame);
623 struct robin_list *next;
624 struct robin_list *prev;
626 static struct robin_list *robin = NULL;
629 static void free_robin_list(void)
631 struct robin_list *r;
632 struct robin_list *next;
634 for (r = robin, robin = NULL; r; r = next) {
641 static struct robin_list *get_robin_position(char *group)
643 struct robin_list *new;
644 struct robin_list *iter = robin;
645 for (; iter; iter = iter->next) {
646 if (!strcasecmp(iter->group, group)) {
650 new = ast_calloc(1, sizeof(*new));
654 new->group = ast_strdup(group);
669 /*! \brief the main schedule context for stuff like l1 watcher, overlap dial, ... */
670 static struct ast_sched_context *misdn_tasks = NULL;
671 static pthread_t misdn_tasks_thread;
673 static int *misdn_ports;
675 static void chan_misdn_log(int level, int port, char *tmpl, ...)
676 __attribute__((format(printf, 3, 4)));
678 static struct ast_channel *misdn_new(struct chan_list *cl, int state, char *exten, char *callerid, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, int port, int c);
679 static void send_digit_to_chan(struct chan_list *cl, char digit);
681 static int pbx_start_chan(struct chan_list *ch);
683 #define MISDN_ASTERISK_TECH_PVT(ast) ast_channel_tech_pvt(ast)
684 #define MISDN_ASTERISK_TECH_PVT_SET(ast, value) ast_channel_tech_pvt_set(ast, value)
686 #include "asterisk/strings.h"
688 /* #define MISDN_DEBUG 1 */
690 static const char misdn_type[] = "mISDN";
692 static int tracing = 0;
694 static int *misdn_debug;
695 static int *misdn_debug_only;
696 static int max_ports;
698 static int *misdn_in_calls;
699 static int *misdn_out_calls;
702 * \brief Global channel call record list head.
704 static struct chan_list *cl_te=NULL;
705 static ast_mutex_t cl_te_lock;
707 static enum event_response_e
708 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data);
710 static int send_cause2ast(struct ast_channel *ast, struct misdn_bchannel *bc, struct chan_list *ch);
712 static void cl_queue_chan(struct chan_list *chan);
714 static int dialtone_indicate(struct chan_list *cl);
715 static void hanguptone_indicate(struct chan_list *cl);
716 static int stop_indicate(struct chan_list *cl);
718 static int start_bc_tones(struct chan_list *cl);
719 static int stop_bc_tones(struct chan_list *cl);
720 static void release_chan_early(struct chan_list *ch);
721 static void release_chan(struct chan_list *ch, struct misdn_bchannel *bc);
723 #if defined(AST_MISDN_ENHANCEMENTS)
724 static const char misdn_command_name[] = "misdn_command";
725 static int misdn_command_exec(struct ast_channel *chan, const char *data);
726 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
727 static int misdn_check_l2l1(struct ast_channel *chan, const char *data);
728 static int misdn_set_opt_exec(struct ast_channel *chan, const char *data);
729 static int misdn_facility_exec(struct ast_channel *chan, const char *data);
731 int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len);
733 void debug_numtype(int port, int numtype, char *type);
735 int add_out_calls(int port);
736 int add_in_calls(int port);
740 static int update_pipeline_config(struct misdn_bchannel *bc);
742 static int update_ec_config(struct misdn_bchannel *bc);
747 /*************** Helpers *****************/
749 static int misdn_chan_is_valid(struct chan_list *ch)
751 struct chan_list *list;
753 ast_mutex_lock(&cl_te_lock);
754 for (list = cl_te; list; list = list->next) {
756 ast_mutex_unlock(&cl_te_lock);
760 ast_mutex_unlock(&cl_te_lock);
765 #if defined(mISDN_NATIVE_BRIDGING)
766 /*! Returns a reference to the found chan_list. */
767 static struct chan_list *get_chan_by_ast(struct ast_channel *ast)
769 struct chan_list *tmp;
771 ast_mutex_lock(&cl_te_lock);
772 for (tmp = cl_te; tmp; tmp = tmp->next) {
773 if (tmp->ast == ast) {
774 chan_list_ref(tmp, "Found chan_list by ast");
775 ast_mutex_unlock(&cl_te_lock);
779 ast_mutex_unlock(&cl_te_lock);
783 #endif /* defined(mISDN_NATIVE_BRIDGING) */
785 /*! Returns a reference to the found chan_list. */
786 static struct chan_list *get_chan_by_ast_name(const char *name)
788 struct chan_list *tmp;
790 ast_mutex_lock(&cl_te_lock);
791 for (tmp = cl_te; tmp; tmp = tmp->next) {
792 if (tmp->ast && strcmp(ast_channel_name(tmp->ast), name) == 0) {
793 chan_list_ref(tmp, "Found chan_list by ast name");
794 ast_mutex_unlock(&cl_te_lock);
798 ast_mutex_unlock(&cl_te_lock);
803 #if defined(AST_MISDN_ENHANCEMENTS)
806 * \brief Destroy the misdn_cc_ds_info datastore payload
808 * \param[in] data the datastore payload, a reference to an misdn_cc_caller
811 * Since the payload is a reference to an astobj2 object, we just decrement its
812 * reference count. Before doing so, we NULL out the channel pointer inside of
813 * the misdn_cc_caller instance. This function will be called in one of two
814 * cases. In both cases, we no longer need the channel pointer:
816 * - The original channel that initialized call completion services, the same
817 * channel that is stored here, has been destroyed early. This could happen
818 * if it transferred the mISDN channel, for example.
820 * - The mISDN channel that had this datastore inherited on to it is now being
821 * destroyed. If this is the case, then the call completion events have
822 * already occurred and the appropriate channel variables have already been
823 * set on the original channel that requested call completion services.
827 static void misdn_cc_ds_destroy(void *data)
829 struct misdn_cc_caller *cc_caller = data;
832 cc_caller->chan = NULL;
833 ao2_unlock(cc_caller);
835 ao2_ref(cc_caller, -1);
837 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
839 #if defined(AST_MISDN_ENHANCEMENTS)
842 * \brief Duplicate the misdn_cc_ds_info datastore payload
844 * \param[in] data the datastore payload, a reference to an misdn_cc_caller
847 * All we need to do is bump the reference count and return the same instance.
849 * \return A reference to an instance of a misdn_cc_caller
851 static void *misdn_cc_ds_duplicate(void *data)
853 struct misdn_cc_caller *cc_caller = data;
855 ao2_ref(cc_caller, +1);
859 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
861 #if defined(AST_MISDN_ENHANCEMENTS)
862 static const struct ast_datastore_info misdn_cc_ds_info = {
864 .destroy = misdn_cc_ds_destroy,
865 .duplicate = misdn_cc_ds_duplicate,
867 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
869 #if defined(AST_MISDN_ENHANCEMENTS)
872 * \brief Set a channel var on the peer channel for call completion services
874 * \param[in] peer The peer that initialized call completion services
875 * \param[in] var The variable name to set
876 * \param[in] value The variable value to set
878 * This function may be called from outside of the channel thread. It handles
879 * the fact that the peer channel may be hung up and destroyed at any time.
883 static void misdn_cc_set_peer_var(struct misdn_cc_caller *peer, const char *var,
888 /*! \todo XXX This nastiness can go away once ast_channel is ref counted! */
889 while (peer->chan && ast_channel_trylock(peer->chan)) {
896 pbx_builtin_setvar_helper(peer->chan, var, value);
897 ast_channel_unlock(peer->chan);
902 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
904 #if defined(AST_MISDN_ENHANCEMENTS)
907 * \brief Get a reference to the CC caller if it exists
909 static struct misdn_cc_caller *misdn_cc_caller_get(struct ast_channel *chan)
911 struct ast_datastore *datastore;
912 struct misdn_cc_caller *cc_caller;
914 ast_channel_lock(chan);
916 if (!(datastore = ast_channel_datastore_find(chan, &misdn_cc_ds_info, NULL))) {
917 ast_channel_unlock(chan);
921 ao2_ref(datastore->data, +1);
922 cc_caller = datastore->data;
924 ast_channel_unlock(chan);
928 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
930 #if defined(AST_MISDN_ENHANCEMENTS)
933 * \brief Find the call completion record given the record id.
937 * \retval pointer to found call completion record
938 * \retval NULL if not found
940 * \note Assumes the misdn_cc_records_db lock is already obtained.
942 static struct misdn_cc_record *misdn_cc_find_by_id(long record_id)
944 struct misdn_cc_record *current;
946 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
947 if (current->record_id == record_id) {
948 /* Found the record */
955 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
957 #if defined(AST_MISDN_ENHANCEMENTS)
960 * \brief Find the call completion record given the port and call linkage id.
962 * \param port Logical port number
963 * \param linkage_id Call linkage ID number from switch.
965 * \retval pointer to found call completion record
966 * \retval NULL if not found
968 * \note Assumes the misdn_cc_records_db lock is already obtained.
970 static struct misdn_cc_record *misdn_cc_find_by_linkage(int port, int linkage_id)
972 struct misdn_cc_record *current;
974 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
975 if (current->port == port
977 && current->mode.ptmp.linkage_id == linkage_id) {
978 /* Found the record */
985 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
987 #if defined(AST_MISDN_ENHANCEMENTS)
990 * \brief Find the call completion record given the port and outstanding invocation id.
992 * \param port Logical port number
993 * \param invoke_id Outstanding message invocation ID number.
995 * \retval pointer to found call completion record
996 * \retval NULL if not found
998 * \note Assumes the misdn_cc_records_db lock is already obtained.
1000 static struct misdn_cc_record *misdn_cc_find_by_invoke(int port, int invoke_id)
1002 struct misdn_cc_record *current;
1004 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
1005 if (current->outstanding_message
1006 && current->invoke_id == invoke_id
1007 && current->port == port) {
1008 /* Found the record */
1015 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1017 #if defined(AST_MISDN_ENHANCEMENTS)
1020 * \brief Find the call completion record given the port and CCBS reference id.
1022 * \param port Logical port number
1023 * \param reference_id CCBS reference ID number from switch.
1025 * \retval pointer to found call completion record
1026 * \retval NULL if not found
1028 * \note Assumes the misdn_cc_records_db lock is already obtained.
1030 static struct misdn_cc_record *misdn_cc_find_by_reference(int port, int reference_id)
1032 struct misdn_cc_record *current;
1034 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
1035 if (current->activated
1036 && current->port == port
1038 && current->mode.ptmp.reference_id == reference_id) {
1039 /* Found the record */
1046 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1048 #if defined(AST_MISDN_ENHANCEMENTS)
1051 * \brief Find the call completion record given the B channel pointer
1053 * \param bc B channel control structure pointer.
1055 * \retval pointer to found call completion record
1056 * \retval NULL if not found
1058 * \note Assumes the misdn_cc_records_db lock is already obtained.
1060 static struct misdn_cc_record *misdn_cc_find_by_bc(const struct misdn_bchannel *bc)
1062 struct misdn_cc_record *current;
1065 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
1067 && current->mode.ptp.bc == bc) {
1068 /* Found the record */
1078 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1080 #if defined(AST_MISDN_ENHANCEMENTS)
1083 * \brief Delete the given call completion record
1085 * \param doomed Call completion record to destroy
1089 * \note Assumes the misdn_cc_records_db lock is already obtained.
1091 static void misdn_cc_delete(struct misdn_cc_record *doomed)
1093 struct misdn_cc_record *current;
1095 AST_LIST_TRAVERSE_SAFE_BEGIN(&misdn_cc_records_db, current, list) {
1096 if (current == doomed) {
1097 AST_LIST_REMOVE_CURRENT(list);
1102 AST_LIST_TRAVERSE_SAFE_END;
1104 /* The doomed node is not in the call completion database */
1106 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1108 #if defined(AST_MISDN_ENHANCEMENTS)
1111 * \brief Delete all old call completion records
1115 * \note Assumes the misdn_cc_records_db lock is already obtained.
1117 static void misdn_cc_remove_old(void)
1119 struct misdn_cc_record *current;
1123 AST_LIST_TRAVERSE_SAFE_BEGIN(&misdn_cc_records_db, current, list) {
1124 if (MISDN_CC_RECORD_AGE_MAX < now - current->time_created) {
1125 if (current->ptp && current->mode.ptp.bc) {
1126 /* Close the old call-completion signaling link */
1127 current->mode.ptp.bc->fac_out.Function = Fac_None;
1128 current->mode.ptp.bc->out_cause = AST_CAUSE_NORMAL_CLEARING;
1129 misdn_lib_send_event(current->mode.ptp.bc, EVENT_RELEASE_COMPLETE);
1132 /* Remove the old call completion record */
1133 AST_LIST_REMOVE_CURRENT(list);
1137 AST_LIST_TRAVERSE_SAFE_END;
1139 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1141 #if defined(AST_MISDN_ENHANCEMENTS)
1144 * \brief Allocate the next record id.
1146 * \retval New record id on success.
1147 * \retval -1 on error.
1149 * \note Assumes the misdn_cc_records_db lock is already obtained.
1151 static long misdn_cc_record_id_new(void)
1156 record_id = ++misdn_cc_record_id;
1157 first_id = record_id;
1158 while (misdn_cc_find_by_id(record_id)) {
1159 record_id = ++misdn_cc_record_id;
1160 if (record_id == first_id) {
1162 * We have a resource leak.
1163 * We should never need to allocate 64k records.
1165 chan_misdn_log(0, 0, " --> ERROR Too many call completion records!\n");
1173 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1175 #if defined(AST_MISDN_ENHANCEMENTS)
1178 * \brief Create a new call completion record
1180 * \retval pointer to new call completion record
1181 * \retval NULL if failed
1183 * \note Assumes the misdn_cc_records_db lock is already obtained.
1185 static struct misdn_cc_record *misdn_cc_new(void)
1187 struct misdn_cc_record *cc_record;
1190 misdn_cc_remove_old();
1192 cc_record = ast_calloc(1, sizeof(*cc_record));
1194 record_id = misdn_cc_record_id_new();
1195 if (record_id < 0) {
1196 ast_free(cc_record);
1200 /* Initialize the new record */
1201 cc_record->record_id = record_id;
1202 cc_record->port = -1;/* Invalid port so it will never be found this way */
1203 cc_record->invoke_id = ++misdn_invoke_id;
1204 cc_record->party_a_free = 1;/* Default User-A as free */
1205 cc_record->error_code = FacError_None;
1206 cc_record->reject_code = FacReject_None;
1207 cc_record->time_created = time(NULL);
1209 /* Insert the new record into the database */
1210 AST_LIST_INSERT_HEAD(&misdn_cc_records_db, cc_record, list);
1214 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1216 #if defined(AST_MISDN_ENHANCEMENTS)
1219 * \brief Destroy the call completion record database
1223 static void misdn_cc_destroy(void)
1225 struct misdn_cc_record *current;
1227 while ((current = AST_LIST_REMOVE_HEAD(&misdn_cc_records_db, list))) {
1228 /* Do a misdn_cc_delete(current) inline */
1232 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1234 #if defined(AST_MISDN_ENHANCEMENTS)
1237 * \brief Initialize the call completion record database
1241 static void misdn_cc_init(void)
1243 misdn_cc_record_id = 0;
1245 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1247 #if defined(AST_MISDN_ENHANCEMENTS)
1250 * \brief Check the status of an outstanding invocation request.
1252 * \param data Points to an integer containing the call completion record id.
1254 * \retval 0 if got a response.
1255 * \retval -1 if no response yet.
1257 static int misdn_cc_response_check(void *data)
1260 struct misdn_cc_record *cc_record;
1262 AST_LIST_LOCK(&misdn_cc_records_db);
1263 cc_record = misdn_cc_find_by_id(*(long *) data);
1265 if (cc_record->outstanding_message) {
1271 /* No record so there is no response to check. */
1274 AST_LIST_UNLOCK(&misdn_cc_records_db);
1276 return not_responded;
1278 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1280 #if defined(AST_MISDN_ENHANCEMENTS)
1283 * \brief Wait for a response from the switch for an outstanding
1284 * invocation request.
1286 * \param chan Asterisk channel to operate upon.
1287 * \param wait_seconds Number of seconds to wait
1288 * \param record_id Call completion record ID.
1292 static void misdn_cc_response_wait(struct ast_channel *chan, int wait_seconds, long record_id)
1296 for (count = 2 * MISDN_CC_REQUEST_WAIT_MAX; count--;) {
1297 /* Sleep in 500 ms increments */
1298 if (ast_safe_sleep_conditional(chan, 500, misdn_cc_response_check, &record_id) != 0) {
1299 /* We got hung up or our response came in. */
1304 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1306 #if defined(AST_MISDN_ENHANCEMENTS)
1309 * \brief Convert the mISDN reject code to a string
1311 * \param code mISDN reject code.
1313 * \return The mISDN reject code as a string
1315 static const char *misdn_to_str_reject_code(enum FacRejectCode code)
1317 static const struct {
1318 enum FacRejectCode code;
1322 { FacReject_None, "No reject occurred" },
1323 { FacReject_Unknown, "Unknown reject code" },
1325 { FacReject_Gen_UnrecognizedComponent, "General: Unrecognized Component" },
1326 { FacReject_Gen_MistypedComponent, "General: Mistyped Component" },
1327 { FacReject_Gen_BadlyStructuredComponent, "General: Badly Structured Component" },
1329 { FacReject_Inv_DuplicateInvocation, "Invoke: Duplicate Invocation" },
1330 { FacReject_Inv_UnrecognizedOperation, "Invoke: Unrecognized Operation" },
1331 { FacReject_Inv_MistypedArgument, "Invoke: Mistyped Argument" },
1332 { FacReject_Inv_ResourceLimitation, "Invoke: Resource Limitation" },
1333 { FacReject_Inv_InitiatorReleasing, "Invoke: Initiator Releasing" },
1334 { FacReject_Inv_UnrecognizedLinkedID, "Invoke: Unrecognized Linked ID" },
1335 { FacReject_Inv_LinkedResponseUnexpected, "Invoke: Linked Response Unexpected" },
1336 { FacReject_Inv_UnexpectedChildOperation, "Invoke: Unexpected Child Operation" },
1338 { FacReject_Res_UnrecognizedInvocation, "Result: Unrecognized Invocation" },
1339 { FacReject_Res_ResultResponseUnexpected, "Result: Result Response Unexpected" },
1340 { FacReject_Res_MistypedResult, "Result: Mistyped Result" },
1342 { FacReject_Err_UnrecognizedInvocation, "Error: Unrecognized Invocation" },
1343 { FacReject_Err_ErrorResponseUnexpected, "Error: Error Response Unexpected" },
1344 { FacReject_Err_UnrecognizedError, "Error: Unrecognized Error" },
1345 { FacReject_Err_UnexpectedError, "Error: Unexpected Error" },
1346 { FacReject_Err_MistypedParameter, "Error: Mistyped Parameter" },
1352 for (index = 0; index < ARRAY_LEN(arr); ++index) {
1353 if (arr[index].code == code) {
1354 return arr[index].name;
1360 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1362 #if defined(AST_MISDN_ENHANCEMENTS)
1365 * \brief Convert the mISDN error code to a string
1367 * \param code mISDN error code.
1369 * \return The mISDN error code as a string
1371 static const char *misdn_to_str_error_code(enum FacErrorCode code)
1373 static const struct {
1374 enum FacErrorCode code;
1378 { FacError_None, "No error occurred" },
1379 { FacError_Unknown, "Unknown OID error code" },
1381 { FacError_Gen_NotSubscribed, "General: Not Subscribed" },
1382 { FacError_Gen_NotAvailable, "General: Not Available" },
1383 { FacError_Gen_NotImplemented, "General: Not Implemented" },
1384 { FacError_Gen_InvalidServedUserNr, "General: Invalid Served User Number" },
1385 { FacError_Gen_InvalidCallState, "General: Invalid Call State" },
1386 { FacError_Gen_BasicServiceNotProvided, "General: Basic Service Not Provided" },
1387 { FacError_Gen_NotIncomingCall, "General: Not Incoming Call" },
1388 { FacError_Gen_SupplementaryServiceInteractionNotAllowed,"General: Supplementary Service Interaction Not Allowed" },
1389 { FacError_Gen_ResourceUnavailable, "General: Resource Unavailable" },
1391 { FacError_Div_InvalidDivertedToNr, "Diversion: Invalid Diverted To Number" },
1392 { FacError_Div_SpecialServiceNr, "Diversion: Special Service Number" },
1393 { FacError_Div_DiversionToServedUserNr, "Diversion: Diversion To Served User Number" },
1394 { FacError_Div_IncomingCallAccepted, "Diversion: Incoming Call Accepted" },
1395 { FacError_Div_NumberOfDiversionsExceeded, "Diversion: Number Of Diversions Exceeded" },
1396 { FacError_Div_NotActivated, "Diversion: Not Activated" },
1397 { FacError_Div_RequestAlreadyAccepted, "Diversion: Request Already Accepted" },
1399 { FacError_AOC_NoChargingInfoAvailable, "AOC: No Charging Info Available" },
1401 { FacError_CCBS_InvalidCallLinkageID, "CCBS: Invalid Call Linkage ID" },
1402 { FacError_CCBS_InvalidCCBSReference, "CCBS: Invalid CCBS Reference" },
1403 { FacError_CCBS_LongTermDenial, "CCBS: Long Term Denial" },
1404 { FacError_CCBS_ShortTermDenial, "CCBS: Short Term Denial" },
1405 { FacError_CCBS_IsAlreadyActivated, "CCBS: Is Already Activated" },
1406 { FacError_CCBS_AlreadyAccepted, "CCBS: Already Accepted" },
1407 { FacError_CCBS_OutgoingCCBSQueueFull, "CCBS: Outgoing CCBS Queue Full" },
1408 { FacError_CCBS_CallFailureReasonNotBusy, "CCBS: Call Failure Reason Not Busy" },
1409 { FacError_CCBS_NotReadyForCall, "CCBS: Not Ready For Call" },
1411 { FacError_CCBS_T_LongTermDenial, "CCBS-T: Long Term Denial" },
1412 { FacError_CCBS_T_ShortTermDenial, "CCBS-T: Short Term Denial" },
1414 { FacError_ECT_LinkIdNotAssignedByNetwork, "ECT: Link ID Not Assigned By Network" },
1420 for (index = 0; index < ARRAY_LEN(arr); ++index) {
1421 if (arr[index].code == code) {
1422 return arr[index].name;
1428 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1430 #if defined(AST_MISDN_ENHANCEMENTS)
1433 * \brief Convert mISDN redirecting reason to diversion reason.
1435 * \param reason mISDN redirecting reason code.
1437 * \return Supported diversion reason code.
1439 static unsigned misdn_to_diversion_reason(enum mISDN_REDIRECTING_REASON reason)
1441 unsigned diversion_reason;
1444 case mISDN_REDIRECTING_REASON_CALL_FWD:
1445 diversion_reason = 1;/* cfu */
1447 case mISDN_REDIRECTING_REASON_CALL_FWD_BUSY:
1448 diversion_reason = 2;/* cfb */
1450 case mISDN_REDIRECTING_REASON_NO_REPLY:
1451 diversion_reason = 3;/* cfnr */
1454 diversion_reason = 0;/* unknown */
1458 return diversion_reason;
1460 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1462 #if defined(AST_MISDN_ENHANCEMENTS)
1465 * \brief Convert diversion reason to mISDN redirecting reason
1467 * \param diversion_reason Diversion reason to convert
1469 * \return Supported redirecting reason code.
1471 static enum mISDN_REDIRECTING_REASON diversion_reason_to_misdn(unsigned diversion_reason)
1473 enum mISDN_REDIRECTING_REASON reason;
1475 switch (diversion_reason) {
1477 reason = mISDN_REDIRECTING_REASON_CALL_FWD;
1480 reason = mISDN_REDIRECTING_REASON_CALL_FWD_BUSY;
1483 reason = mISDN_REDIRECTING_REASON_NO_REPLY;
1486 reason = mISDN_REDIRECTING_REASON_UNKNOWN;
1492 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1494 #if defined(AST_MISDN_ENHANCEMENTS)
1497 * \brief Convert the mISDN presentation to PresentedNumberUnscreened type
1499 * \param presentation mISDN presentation to convert
1500 * \param number_present TRUE if the number is present
1502 * \return PresentedNumberUnscreened type
1504 static unsigned misdn_to_PresentedNumberUnscreened_type(int presentation, int number_present)
1508 switch (presentation) {
1509 case 0:/* allowed */
1510 if (number_present) {
1511 type = 0;/* presentationAllowedNumber */
1513 type = 2;/* numberNotAvailableDueToInterworking */
1516 case 1:/* restricted */
1517 if (number_present) {
1518 type = 3;/* presentationRestrictedNumber */
1520 type = 1;/* presentationRestricted */
1524 type = 2;/* numberNotAvailableDueToInterworking */
1530 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1532 #if defined(AST_MISDN_ENHANCEMENTS)
1535 * \brief Convert the PresentedNumberUnscreened type to mISDN presentation
1537 * \param type PresentedNumberUnscreened type
1539 * \return mISDN presentation
1541 static int PresentedNumberUnscreened_to_misdn_pres(unsigned type)
1547 case 0:/* presentationAllowedNumber */
1548 presentation = 0;/* allowed */
1551 case 1:/* presentationRestricted */
1552 case 3:/* presentationRestrictedNumber */
1553 presentation = 1;/* restricted */
1556 case 2:/* numberNotAvailableDueToInterworking */
1557 presentation = 2;/* unavailable */
1561 return presentation;
1563 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1565 #if defined(AST_MISDN_ENHANCEMENTS)
1568 * \brief Convert the mISDN numbering plan to PartyNumber numbering plan
1570 * \param number_plan mISDN numbering plan
1572 * \return PartyNumber numbering plan
1574 static unsigned misdn_to_PartyNumber_plan(enum mISDN_NUMBER_PLAN number_plan)
1576 unsigned party_plan;
1578 switch (number_plan) {
1580 case NUMPLAN_UNKNOWN:
1581 party_plan = 0;/* unknown */
1585 party_plan = 1;/* public */
1589 party_plan = 3;/* data */
1593 party_plan = 4;/* telex */
1596 case NUMPLAN_NATIONAL:
1597 party_plan = 8;/* nationalStandard */
1600 case NUMPLAN_PRIVATE:
1601 party_plan = 5;/* private */
1607 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1609 #if defined(AST_MISDN_ENHANCEMENTS)
1612 * \brief Convert PartyNumber numbering plan to mISDN numbering plan
1614 * \param party_plan PartyNumber numbering plan
1616 * \return mISDN numbering plan
1618 static enum mISDN_NUMBER_PLAN PartyNumber_to_misdn_plan(unsigned party_plan)
1620 enum mISDN_NUMBER_PLAN number_plan;
1622 switch (party_plan) {
1624 case 0:/* unknown */
1625 number_plan = NUMPLAN_UNKNOWN;
1628 number_plan = NUMPLAN_ISDN;
1631 number_plan = NUMPLAN_DATA;
1634 number_plan = NUMPLAN_TELEX;
1636 case 8:/* nationalStandard */
1637 number_plan = NUMPLAN_NATIONAL;
1639 case 5:/* private */
1640 number_plan = NUMPLAN_PRIVATE;
1646 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1648 #if defined(AST_MISDN_ENHANCEMENTS)
1651 * \brief Convert mISDN type-of-number to PartyNumber public type-of-number
1653 * \param ton mISDN type-of-number
1655 * \return PartyNumber public type-of-number
1657 static unsigned misdn_to_PartyNumber_ton_public(enum mISDN_NUMBER_TYPE ton)
1663 case NUMTYPE_UNKNOWN:
1664 party_ton = 0;/* unknown */
1667 case NUMTYPE_INTERNATIONAL:
1668 party_ton = 1;/* internationalNumber */
1671 case NUMTYPE_NATIONAL:
1672 party_ton = 2;/* nationalNumber */
1675 case NUMTYPE_NETWORK_SPECIFIC:
1676 party_ton = 3;/* networkSpecificNumber */
1679 case NUMTYPE_SUBSCRIBER:
1680 party_ton = 4;/* subscriberNumber */
1683 case NUMTYPE_ABBREVIATED:
1684 party_ton = 6;/* abbreviatedNumber */
1690 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1692 #if defined(AST_MISDN_ENHANCEMENTS)
1695 * \brief Convert the PartyNumber public type-of-number to mISDN type-of-number
1697 * \param party_ton PartyNumber public type-of-number
1699 * \return mISDN type-of-number
1701 static enum mISDN_NUMBER_TYPE PartyNumber_to_misdn_ton_public(unsigned party_ton)
1703 enum mISDN_NUMBER_TYPE ton;
1705 switch (party_ton) {
1707 case 0:/* unknown */
1708 ton = NUMTYPE_UNKNOWN;
1711 case 1:/* internationalNumber */
1712 ton = NUMTYPE_INTERNATIONAL;
1715 case 2:/* nationalNumber */
1716 ton = NUMTYPE_NATIONAL;
1719 case 3:/* networkSpecificNumber */
1720 ton = NUMTYPE_NETWORK_SPECIFIC;
1723 case 4:/* subscriberNumber */
1724 ton = NUMTYPE_SUBSCRIBER;
1727 case 6:/* abbreviatedNumber */
1728 ton = NUMTYPE_ABBREVIATED;
1734 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1736 #if defined(AST_MISDN_ENHANCEMENTS)
1739 * \brief Convert mISDN type-of-number to PartyNumber private type-of-number
1741 * \param ton mISDN type-of-number
1743 * \return PartyNumber private type-of-number
1745 static unsigned misdn_to_PartyNumber_ton_private(enum mISDN_NUMBER_TYPE ton)
1751 case NUMTYPE_UNKNOWN:
1752 party_ton = 0;/* unknown */
1755 case NUMTYPE_INTERNATIONAL:
1756 party_ton = 1;/* level2RegionalNumber */
1759 case NUMTYPE_NATIONAL:
1760 party_ton = 2;/* level1RegionalNumber */
1763 case NUMTYPE_NETWORK_SPECIFIC:
1764 party_ton = 3;/* pTNSpecificNumber */
1767 case NUMTYPE_SUBSCRIBER:
1768 party_ton = 4;/* localNumber */
1771 case NUMTYPE_ABBREVIATED:
1772 party_ton = 6;/* abbreviatedNumber */
1778 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1780 #if defined(AST_MISDN_ENHANCEMENTS)
1783 * \brief Convert the PartyNumber private type-of-number to mISDN type-of-number
1785 * \param party_ton PartyNumber private type-of-number
1787 * \return mISDN type-of-number
1789 static enum mISDN_NUMBER_TYPE PartyNumber_to_misdn_ton_private(unsigned party_ton)
1791 enum mISDN_NUMBER_TYPE ton;
1793 switch (party_ton) {
1795 case 0:/* unknown */
1796 ton = NUMTYPE_UNKNOWN;
1799 case 1:/* level2RegionalNumber */
1800 ton = NUMTYPE_INTERNATIONAL;
1803 case 2:/* level1RegionalNumber */
1804 ton = NUMTYPE_NATIONAL;
1807 case 3:/* pTNSpecificNumber */
1808 ton = NUMTYPE_NETWORK_SPECIFIC;
1811 case 4:/* localNumber */
1812 ton = NUMTYPE_SUBSCRIBER;
1815 case 6:/* abbreviatedNumber */
1816 ton = NUMTYPE_ABBREVIATED;
1822 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1826 * \brief Convert the mISDN type of number code to a string
1828 * \param number_type mISDN type of number code.
1830 * \return The mISDN type of number code as a string
1832 static const char *misdn_to_str_ton(enum mISDN_NUMBER_TYPE number_type)
1836 switch (number_type) {
1838 case NUMTYPE_UNKNOWN:
1842 case NUMTYPE_INTERNATIONAL:
1843 str = "International";
1846 case NUMTYPE_NATIONAL:
1850 case NUMTYPE_NETWORK_SPECIFIC:
1851 str = "Network Specific";
1854 case NUMTYPE_SUBSCRIBER:
1858 case NUMTYPE_ABBREVIATED:
1859 str = "Abbreviated";
1868 * \brief Convert the mISDN type of number code to Asterisk type of number code
1870 * \param number_type mISDN type of number code.
1872 * \return Asterisk type of number code
1874 static int misdn_to_ast_ton(enum mISDN_NUMBER_TYPE number_type)
1876 int ast_number_type;
1878 switch (number_type) {
1880 case NUMTYPE_UNKNOWN:
1881 ast_number_type = NUMTYPE_UNKNOWN << 4;
1884 case NUMTYPE_INTERNATIONAL:
1885 ast_number_type = NUMTYPE_INTERNATIONAL << 4;
1888 case NUMTYPE_NATIONAL:
1889 ast_number_type = NUMTYPE_NATIONAL << 4;
1892 case NUMTYPE_NETWORK_SPECIFIC:
1893 ast_number_type = NUMTYPE_NETWORK_SPECIFIC << 4;
1896 case NUMTYPE_SUBSCRIBER:
1897 ast_number_type = NUMTYPE_SUBSCRIBER << 4;
1900 case NUMTYPE_ABBREVIATED:
1901 ast_number_type = NUMTYPE_ABBREVIATED << 4;
1905 return ast_number_type;
1910 * \brief Convert the Asterisk type of number code to mISDN type of number code
1912 * \param ast_number_type Asterisk type of number code.
1914 * \return mISDN type of number code
1916 static enum mISDN_NUMBER_TYPE ast_to_misdn_ton(unsigned ast_number_type)
1918 enum mISDN_NUMBER_TYPE number_type;
1920 switch ((ast_number_type >> 4) & 0x07) {
1922 case NUMTYPE_UNKNOWN:
1923 number_type = NUMTYPE_UNKNOWN;
1926 case NUMTYPE_INTERNATIONAL:
1927 number_type = NUMTYPE_INTERNATIONAL;
1930 case NUMTYPE_NATIONAL:
1931 number_type = NUMTYPE_NATIONAL;
1934 case NUMTYPE_NETWORK_SPECIFIC:
1935 number_type = NUMTYPE_NETWORK_SPECIFIC;
1938 case NUMTYPE_SUBSCRIBER:
1939 number_type = NUMTYPE_SUBSCRIBER;
1942 case NUMTYPE_ABBREVIATED:
1943 number_type = NUMTYPE_ABBREVIATED;
1952 * \brief Convert the mISDN numbering plan code to a string
1954 * \param number_plan mISDN numbering plan code.
1956 * \return The mISDN numbering plan code as a string
1958 static const char *misdn_to_str_plan(enum mISDN_NUMBER_PLAN number_plan)
1962 switch (number_plan) {
1964 case NUMPLAN_UNKNOWN:
1980 case NUMPLAN_NATIONAL:
1984 case NUMPLAN_PRIVATE:
1994 * \brief Convert the mISDN numbering plan code to Asterisk numbering plan code
1996 * \param number_plan mISDN numbering plan code.
1998 * \return Asterisk numbering plan code
2000 static int misdn_to_ast_plan(enum mISDN_NUMBER_PLAN number_plan)
2002 int ast_number_plan;
2004 switch (number_plan) {
2006 case NUMPLAN_UNKNOWN:
2007 ast_number_plan = NUMPLAN_UNKNOWN;
2011 ast_number_plan = NUMPLAN_ISDN;
2015 ast_number_plan = NUMPLAN_DATA;
2019 ast_number_plan = NUMPLAN_TELEX;
2022 case NUMPLAN_NATIONAL:
2023 ast_number_plan = NUMPLAN_NATIONAL;
2026 case NUMPLAN_PRIVATE:
2027 ast_number_plan = NUMPLAN_PRIVATE;
2031 return ast_number_plan;
2036 * \brief Convert the Asterisk numbering plan code to mISDN numbering plan code
2038 * \param ast_number_plan Asterisk numbering plan code.
2040 * \return mISDN numbering plan code
2042 static enum mISDN_NUMBER_PLAN ast_to_misdn_plan(unsigned ast_number_plan)
2044 enum mISDN_NUMBER_PLAN number_plan;
2046 switch (ast_number_plan & 0x0F) {
2048 case NUMPLAN_UNKNOWN:
2049 number_plan = NUMPLAN_UNKNOWN;
2053 number_plan = NUMPLAN_ISDN;
2057 number_plan = NUMPLAN_DATA;
2061 number_plan = NUMPLAN_TELEX;
2064 case NUMPLAN_NATIONAL:
2065 number_plan = NUMPLAN_NATIONAL;
2068 case NUMPLAN_PRIVATE:
2069 number_plan = NUMPLAN_PRIVATE;
2078 * \brief Convert the mISDN presentation code to a string
2080 * \param presentation mISDN number presentation restriction code.
2082 * \return The mISDN presentation code as a string
2084 static const char *misdn_to_str_pres(int presentation)
2088 switch (presentation) {
2098 str = "Unavailable";
2111 * \brief Convert the mISDN presentation code to Asterisk presentation code
2113 * \param presentation mISDN number presentation restriction code.
2115 * \return Asterisk presentation code
2117 static int misdn_to_ast_pres(int presentation)
2119 switch (presentation) {
2122 presentation = AST_PRES_ALLOWED;
2126 presentation = AST_PRES_RESTRICTED;
2130 presentation = AST_PRES_UNAVAILABLE;
2134 return presentation;
2139 * \brief Convert the Asterisk presentation code to mISDN presentation code
2141 * \param presentation Asterisk number presentation restriction code.
2143 * \return mISDN presentation code
2145 static int ast_to_misdn_pres(int presentation)
2147 switch (presentation & AST_PRES_RESTRICTION) {
2149 case AST_PRES_ALLOWED:
2153 case AST_PRES_RESTRICTED:
2157 case AST_PRES_UNAVAILABLE:
2162 return presentation;
2167 * \brief Convert the mISDN screening code to a string
2169 * \param screening mISDN number screening code.
2171 * \return The mISDN screening code as a string
2173 static const char *misdn_to_str_screen(int screening)
2177 switch (screening) {
2183 str = "Passed Screen";
2187 str = "Failed Screen";
2191 str = "Network Number";
2204 * \brief Convert the mISDN screening code to Asterisk screening code
2206 * \param screening mISDN number screening code.
2208 * \return Asterisk screening code
2210 static int misdn_to_ast_screen(int screening)
2212 switch (screening) {
2215 screening = AST_PRES_USER_NUMBER_UNSCREENED;
2219 screening = AST_PRES_USER_NUMBER_PASSED_SCREEN;
2223 screening = AST_PRES_USER_NUMBER_FAILED_SCREEN;
2227 screening = AST_PRES_NETWORK_NUMBER;
2236 * \brief Convert the Asterisk screening code to mISDN screening code
2238 * \param screening Asterisk number screening code.
2240 * \return mISDN screening code
2242 static int ast_to_misdn_screen(int screening)
2244 switch (screening & AST_PRES_NUMBER_TYPE) {
2246 case AST_PRES_USER_NUMBER_UNSCREENED:
2250 case AST_PRES_USER_NUMBER_PASSED_SCREEN:
2254 case AST_PRES_USER_NUMBER_FAILED_SCREEN:
2258 case AST_PRES_NETWORK_NUMBER:
2268 * \brief Convert Asterisk redirecting reason to mISDN redirecting reason code.
2270 * \param ast Asterisk redirecting reason code.
2272 * \return mISDN reason code
2274 static enum mISDN_REDIRECTING_REASON ast_to_misdn_reason(const enum AST_REDIRECTING_REASON ast)
2278 static const struct misdn_reasons {
2279 enum AST_REDIRECTING_REASON ast;
2280 enum mISDN_REDIRECTING_REASON q931;
2281 } misdn_reason_table[] = {
2283 { AST_REDIRECTING_REASON_UNKNOWN, mISDN_REDIRECTING_REASON_UNKNOWN },
2284 { AST_REDIRECTING_REASON_USER_BUSY, mISDN_REDIRECTING_REASON_CALL_FWD_BUSY },
2285 { AST_REDIRECTING_REASON_NO_ANSWER, mISDN_REDIRECTING_REASON_NO_REPLY },
2286 { AST_REDIRECTING_REASON_UNAVAILABLE, mISDN_REDIRECTING_REASON_NO_REPLY },
2287 { AST_REDIRECTING_REASON_UNCONDITIONAL, mISDN_REDIRECTING_REASON_CALL_FWD },
2288 { AST_REDIRECTING_REASON_TIME_OF_DAY, mISDN_REDIRECTING_REASON_UNKNOWN },
2289 { AST_REDIRECTING_REASON_DO_NOT_DISTURB, mISDN_REDIRECTING_REASON_UNKNOWN },
2290 { AST_REDIRECTING_REASON_DEFLECTION, mISDN_REDIRECTING_REASON_DEFLECTION },
2291 { AST_REDIRECTING_REASON_FOLLOW_ME, mISDN_REDIRECTING_REASON_UNKNOWN },
2292 { AST_REDIRECTING_REASON_OUT_OF_ORDER, mISDN_REDIRECTING_REASON_OUT_OF_ORDER },
2293 { AST_REDIRECTING_REASON_AWAY, mISDN_REDIRECTING_REASON_UNKNOWN },
2294 { AST_REDIRECTING_REASON_CALL_FWD_DTE, mISDN_REDIRECTING_REASON_CALL_FWD_DTE }
2298 for (index = 0; index < ARRAY_LEN(misdn_reason_table); ++index) {
2299 if (misdn_reason_table[index].ast == ast) {
2300 return misdn_reason_table[index].q931;
2303 return mISDN_REDIRECTING_REASON_UNKNOWN;
2308 * \brief Convert the mISDN redirecting reason to Asterisk redirecting reason code
2310 * \param q931 mISDN redirecting reason code.
2312 * \return Asterisk redirecting reason code
2314 static enum AST_REDIRECTING_REASON misdn_to_ast_reason(const enum mISDN_REDIRECTING_REASON q931)
2316 enum AST_REDIRECTING_REASON ast;
2320 case mISDN_REDIRECTING_REASON_UNKNOWN:
2321 ast = AST_REDIRECTING_REASON_UNKNOWN;
2324 case mISDN_REDIRECTING_REASON_CALL_FWD_BUSY:
2325 ast = AST_REDIRECTING_REASON_USER_BUSY;
2328 case mISDN_REDIRECTING_REASON_NO_REPLY:
2329 ast = AST_REDIRECTING_REASON_NO_ANSWER;
2332 case mISDN_REDIRECTING_REASON_DEFLECTION:
2333 ast = AST_REDIRECTING_REASON_DEFLECTION;
2336 case mISDN_REDIRECTING_REASON_OUT_OF_ORDER:
2337 ast = AST_REDIRECTING_REASON_OUT_OF_ORDER;
2340 case mISDN_REDIRECTING_REASON_CALL_FWD_DTE:
2341 ast = AST_REDIRECTING_REASON_CALL_FWD_DTE;
2344 case mISDN_REDIRECTING_REASON_CALL_FWD:
2345 ast = AST_REDIRECTING_REASON_UNCONDITIONAL;
2354 struct allowed_bearers {
2355 char *name; /*!< Bearer capability name string used in /etc/misdn.conf allowed_bearers */
2356 char *display; /*!< Bearer capability displayable name */
2357 int cap; /*!< SETUP message bearer capability field code value */
2358 int deprecated; /*!< TRUE if this entry is deprecated. (Misspelled or bad name to use) */
2362 static const struct allowed_bearers allowed_bearers_array[] = {
2363 /* Name, Displayable Name Bearer Capability, Deprecated */
2364 { "speech", "Speech", INFO_CAPABILITY_SPEECH, 0 },
2365 { "3_1khz", "3.1KHz Audio", INFO_CAPABILITY_AUDIO_3_1K, 0 },
2366 { "digital_unrestricted", "Unrestricted Digital", INFO_CAPABILITY_DIGITAL_UNRESTRICTED, 0 },
2367 { "digital_restricted", "Restricted Digital", INFO_CAPABILITY_DIGITAL_RESTRICTED, 0 },
2368 { "digital_restriced", "Restricted Digital", INFO_CAPABILITY_DIGITAL_RESTRICTED, 1 }, /* Allow misspelling for backwards compatibility */
2369 { "video", "Video", INFO_CAPABILITY_VIDEO, 0 }
2373 static const char *bearer2str(int cap)
2377 for (index = 0; index < ARRAY_LEN(allowed_bearers_array); ++index) {
2378 if (allowed_bearers_array[index].cap == cap) {
2379 return allowed_bearers_array[index].display;
2383 return "Unknown Bearer";
2386 #if defined(AST_MISDN_ENHANCEMENTS)
2389 * \brief Fill in facility PartyNumber information
2391 * \param party PartyNumber structure to fill in.
2392 * \param id Information to put in PartyNumber structure.
2396 static void misdn_PartyNumber_fill(struct FacPartyNumber *party, const struct misdn_party_id *id)
2398 ast_copy_string((char *) party->Number, id->number, sizeof(party->Number));
2399 party->LengthOfNumber = strlen((char *) party->Number);
2400 party->Type = misdn_to_PartyNumber_plan(id->number_plan);
2401 switch (party->Type) {
2403 party->TypeOfNumber = misdn_to_PartyNumber_ton_public(id->number_type);
2405 case 5:/* private */
2406 party->TypeOfNumber = misdn_to_PartyNumber_ton_private(id->number_type);
2409 party->TypeOfNumber = 0;/* Don't care */
2413 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2415 #if defined(AST_MISDN_ENHANCEMENTS)
2418 * \brief Extract the information from PartyNumber
2420 * \param id Where to put extracted PartyNumber information
2421 * \param party PartyNumber information to extract
2425 static void misdn_PartyNumber_extract(struct misdn_party_id *id, const struct FacPartyNumber *party)
2427 if (party->LengthOfNumber) {
2428 ast_copy_string(id->number, (char *) party->Number, sizeof(id->number));
2429 id->number_plan = PartyNumber_to_misdn_plan(party->Type);
2430 switch (party->Type) {
2432 id->number_type = PartyNumber_to_misdn_ton_public(party->TypeOfNumber);
2434 case 5:/* private */
2435 id->number_type = PartyNumber_to_misdn_ton_private(party->TypeOfNumber);
2438 id->number_type = NUMTYPE_UNKNOWN;
2442 /* Number not present */
2443 id->number_type = NUMTYPE_UNKNOWN;
2444 id->number_plan = NUMPLAN_ISDN;
2448 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2450 #if defined(AST_MISDN_ENHANCEMENTS)
2453 * \brief Fill in facility Address information
2455 * \param Address Address structure to fill in.
2456 * \param id Information to put in Address structure.
2460 static void misdn_Address_fill(struct FacAddress *Address, const struct misdn_party_id *id)
2462 misdn_PartyNumber_fill(&Address->Party, id);
2464 /* Subaddresses are not supported yet */
2465 Address->Subaddress.Length = 0;
2467 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2469 #if defined(AST_MISDN_ENHANCEMENTS)
2472 * \brief Fill in facility PresentedNumberUnscreened information
2474 * \param presented PresentedNumberUnscreened structure to fill in.
2475 * \param id Information to put in PresentedNumberUnscreened structure.
2479 static void misdn_PresentedNumberUnscreened_fill(struct FacPresentedNumberUnscreened *presented, const struct misdn_party_id *id)
2481 presented->Type = misdn_to_PresentedNumberUnscreened_type(id->presentation, id->number[0] ? 1 : 0);
2482 misdn_PartyNumber_fill(&presented->Unscreened, id);
2484 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2486 #if defined(AST_MISDN_ENHANCEMENTS)
2489 * \brief Extract the information from PartyNumber
2491 * \param id Where to put extracted PresentedNumberUnscreened information
2492 * \param presented PresentedNumberUnscreened information to extract
2496 static void misdn_PresentedNumberUnscreened_extract(struct misdn_party_id *id, const struct FacPresentedNumberUnscreened *presented)
2498 id->presentation = PresentedNumberUnscreened_to_misdn_pres(presented->Type);
2499 id->screening = 0;/* unscreened */
2500 switch (presented->Type) {
2501 case 0:/* presentationAllowedNumber */
2502 case 3:/* presentationRestrictedNumber */
2503 misdn_PartyNumber_extract(id, &presented->Unscreened);
2505 case 1:/* presentationRestricted */
2506 case 2:/* numberNotAvailableDueToInterworking */
2508 /* Number not present (And uninitialized so do not even look at it!) */
2509 id->number_type = NUMTYPE_UNKNOWN;
2510 id->number_plan = NUMPLAN_ISDN;
2515 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2517 #if defined(AST_MISDN_ENHANCEMENTS)
2518 static const char Level_Spacing[] = " ";/* Work for up to 10 levels */
2519 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2521 #if defined(AST_MISDN_ENHANCEMENTS)
2522 static void print_facility_PartyNumber(unsigned Level, const struct FacPartyNumber *Party, const struct misdn_bchannel *bc)
2524 if (Party->LengthOfNumber) {
2525 const char *Spacing;
2527 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2528 chan_misdn_log(1, bc->port, " -->%s PartyNumber: Type:%d\n",
2529 Spacing, Party->Type);
2530 switch (Party->Type) {
2531 case 0: /* Unknown PartyNumber */
2532 chan_misdn_log(1, bc->port, " -->%s Unknown: %s\n",
2533 Spacing, Party->Number);
2535 case 1: /* Public PartyNumber */
2536 chan_misdn_log(1, bc->port, " -->%s Public TON:%d %s\n",
2537 Spacing, Party->TypeOfNumber, Party->Number);
2539 case 2: /* NSAP encoded PartyNumber */
2540 chan_misdn_log(1, bc->port, " -->%s NSAP: %s\n",
2541 Spacing, Party->Number);
2543 case 3: /* Data PartyNumber (Not used) */
2544 chan_misdn_log(1, bc->port, " -->%s Data: %s\n",
2545 Spacing, Party->Number);
2547 case 4: /* Telex PartyNumber (Not used) */
2548 chan_misdn_log(1, bc->port, " -->%s Telex: %s\n",
2549 Spacing, Party->Number);
2551 case 5: /* Private PartyNumber */
2552 chan_misdn_log(1, bc->port, " -->%s Private TON:%d %s\n",
2553 Spacing, Party->TypeOfNumber, Party->Number);
2555 case 8: /* National Standard PartyNumber (Not used) */
2556 chan_misdn_log(1, bc->port, " -->%s National: %s\n",
2557 Spacing, Party->Number);
2564 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2566 #if defined(AST_MISDN_ENHANCEMENTS)
2567 static void print_facility_Subaddress(unsigned Level, const struct FacPartySubaddress *Subaddress, const struct misdn_bchannel *bc)
2569 if (Subaddress->Length) {
2570 const char *Spacing;
2572 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2573 chan_misdn_log(1, bc->port, " -->%s Subaddress: Type:%d\n",
2574 Spacing, Subaddress->Type);
2575 switch (Subaddress->Type) {
2576 case 0: /* UserSpecified */
2577 if (Subaddress->u.UserSpecified.OddCountPresent) {
2578 chan_misdn_log(1, bc->port, " -->%s User BCD OddCount:%d NumOctets:%d\n",
2579 Spacing, Subaddress->u.UserSpecified.OddCount, Subaddress->Length);
2581 chan_misdn_log(1, bc->port, " -->%s User: %s\n",
2582 Spacing, Subaddress->u.UserSpecified.Information);
2586 chan_misdn_log(1, bc->port, " -->%s NSAP: %s\n",
2587 Spacing, Subaddress->u.Nsap);
2594 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2596 #if defined(AST_MISDN_ENHANCEMENTS)
2597 static void print_facility_Address(unsigned Level, const struct FacAddress *Address, const struct misdn_bchannel *bc)
2599 print_facility_PartyNumber(Level, &Address->Party, bc);
2600 print_facility_Subaddress(Level, &Address->Subaddress, bc);
2602 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2604 #if defined(AST_MISDN_ENHANCEMENTS)
2605 static void print_facility_PresentedNumberUnscreened(unsigned Level, const struct FacPresentedNumberUnscreened *Presented, const struct misdn_bchannel *bc)
2607 const char *Spacing;
2609 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2610 chan_misdn_log(1, bc->port, " -->%s Unscreened Type:%d\n", Spacing, Presented->Type);
2611 switch (Presented->Type) {
2612 case 0: /* presentationAllowedNumber */
2613 chan_misdn_log(1, bc->port, " -->%s Allowed:\n", Spacing);
2614 print_facility_PartyNumber(Level + 2, &Presented->Unscreened, bc);
2616 case 1: /* presentationRestricted */
2617 chan_misdn_log(1, bc->port, " -->%s Restricted\n", Spacing);
2619 case 2: /* numberNotAvailableDueToInterworking */
2620 chan_misdn_log(1, bc->port, " -->%s Not Available\n", Spacing);
2622 case 3: /* presentationRestrictedNumber */
2623 chan_misdn_log(1, bc->port, " -->%s Restricted:\n", Spacing);
2624 print_facility_PartyNumber(Level + 2, &Presented->Unscreened, bc);
2630 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2632 #if defined(AST_MISDN_ENHANCEMENTS)
2633 static void print_facility_AddressScreened(unsigned Level, const struct FacAddressScreened *Address, const struct misdn_bchannel *bc)
2635 const char *Spacing;
2637 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2638 chan_misdn_log(1, bc->port, " -->%s ScreeningIndicator:%d\n", Spacing, Address->ScreeningIndicator);
2639 print_facility_PartyNumber(Level, &Address->Party, bc);
2640 print_facility_Subaddress(Level, &Address->Subaddress, bc);
2642 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2644 #if defined(AST_MISDN_ENHANCEMENTS)
2645 static void print_facility_PresentedAddressScreened(unsigned Level, const struct FacPresentedAddressScreened *Presented, const struct misdn_bchannel *bc)
2647 const char *Spacing;
2649 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2650 chan_misdn_log(1, bc->port, " -->%s Screened Type:%d\n", Spacing, Presented->Type);
2651 switch (Presented->Type) {
2652 case 0: /* presentationAllowedAddress */
2653 chan_misdn_log(1, bc->port, " -->%s Allowed:\n", Spacing);
2654 print_facility_AddressScreened(Level + 2, &Presented->Address, bc);
2656 case 1: /* presentationRestricted */
2657 chan_misdn_log(1, bc->port, " -->%s Restricted\n", Spacing);
2659 case 2: /* numberNotAvailableDueToInterworking */
2660 chan_misdn_log(1, bc->port, " -->%s Not Available\n", Spacing);
2662 case 3: /* presentationRestrictedAddress */
2663 chan_misdn_log(1, bc->port, " -->%s Restricted:\n", Spacing);
2664 print_facility_AddressScreened(Level + 2, &Presented->Address, bc);
2670 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2672 #if defined(AST_MISDN_ENHANCEMENTS)
2673 static void print_facility_Q931_Bc_Hlc_Llc(unsigned Level, const struct Q931_Bc_Hlc_Llc *Q931ie, const struct misdn_bchannel *bc)
2675 const char *Spacing;
2677 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2678 chan_misdn_log(1, bc->port, " -->%s Q931ie:\n", Spacing);
2679 if (Q931ie->Bc.Length) {
2680 chan_misdn_log(1, bc->port, " -->%s Bc Len:%d\n", Spacing, Q931ie->Bc.Length);
2682 if (Q931ie->Hlc.Length) {
2683 chan_misdn_log(1, bc->port, " -->%s Hlc Len:%d\n", Spacing, Q931ie->Hlc.Length);
2685 if (Q931ie->Llc.Length) {
2686 chan_misdn_log(1, bc->port, " -->%s Llc Len:%d\n", Spacing, Q931ie->Llc.Length);
2689 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2691 #if defined(AST_MISDN_ENHANCEMENTS)
2692 static void print_facility_Q931_Bc_Hlc_Llc_Uu(unsigned Level, const struct Q931_Bc_Hlc_Llc_Uu *Q931ie, const struct misdn_bchannel *bc)
2694 const char *Spacing;
2696 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2697 chan_misdn_log(1, bc->port, " -->%s Q931ie:\n", Spacing);
2698 if (Q931ie->Bc.Length) {
2699 chan_misdn_log(1, bc->port, " -->%s Bc Len:%d\n", Spacing, Q931ie->Bc.Length);
2701 if (Q931ie->Hlc.Length) {
2702 chan_misdn_log(1, bc->port, " -->%s Hlc Len:%d\n", Spacing, Q931ie->Hlc.Length);
2704 if (Q931ie->Llc.Length) {
2705 chan_misdn_log(1, bc->port, " -->%s Llc Len:%d\n", Spacing, Q931ie->Llc.Length);
2707 if (Q931ie->UserInfo.Length) {
2708 chan_misdn_log(1, bc->port, " -->%s UserInfo Len:%d\n", Spacing, Q931ie->UserInfo.Length);
2711 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2713 #if defined(AST_MISDN_ENHANCEMENTS)
2714 static void print_facility_CallInformation(unsigned Level, const struct FacCallInformation *CallInfo, const struct misdn_bchannel *bc)
2716 const char *Spacing;
2718 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2719 chan_misdn_log(1, bc->port, " -->%s CCBSReference:%d\n",
2720 Spacing, CallInfo->CCBSReference);
2721 chan_misdn_log(1, bc->port, " -->%s AddressOfB:\n", Spacing);
2722 print_facility_Address(Level + 1, &CallInfo->AddressOfB, bc);
2723 print_facility_Q931_Bc_Hlc_Llc(Level, &CallInfo->Q931ie, bc);
2724 if (CallInfo->SubaddressOfA.Length) {
2725 chan_misdn_log(1, bc->port, " -->%s SubaddressOfA:\n", Spacing);
2726 print_facility_Subaddress(Level + 1, &CallInfo->SubaddressOfA, bc);
2729 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2731 #if defined(AST_MISDN_ENHANCEMENTS)
2732 static void print_facility_ServedUserNr(unsigned Level, const struct FacPartyNumber *Party, const struct misdn_bchannel *bc)
2734 const char *Spacing;
2736 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2737 if (Party->LengthOfNumber) {
2738 print_facility_PartyNumber(Level, Party, bc);
2740 chan_misdn_log(1, bc->port, " -->%s All Numbers\n", Spacing);
2743 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2745 #if defined(AST_MISDN_ENHANCEMENTS)
2746 static void print_facility_IntResult(unsigned Level, const struct FacForwardingRecord *ForwardingRecord, const struct misdn_bchannel *bc)
2748 const char *Spacing;
2750 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2751 chan_misdn_log(1, bc->port, " -->%s Procedure:%d BasicService:%d\n",
2753 ForwardingRecord->Procedure,
2754 ForwardingRecord->BasicService);
2755 chan_misdn_log(1, bc->port, " -->%s ForwardedTo:\n", Spacing);
2756 print_facility_Address(Level + 1, &ForwardingRecord->ForwardedTo, bc);
2757 chan_misdn_log(1, bc->port, " -->%s ServedUserNr:\n", Spacing);
2758 print_facility_ServedUserNr(Level + 1, &ForwardingRecord->ServedUser, bc);
2760 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2762 static void print_facility(const struct FacParm *fac, const struct misdn_bchannel *bc)
2764 #if defined(AST_MISDN_ENHANCEMENTS)
2766 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2768 switch (fac->Function) {
2769 #if defined(AST_MISDN_ENHANCEMENTS)
2770 case Fac_ActivationDiversion:
2771 chan_misdn_log(1, bc->port, " --> ActivationDiversion: InvokeID:%d\n",
2772 fac->u.ActivationDiversion.InvokeID);
2773 switch (fac->u.ActivationDiversion.ComponentType) {
2774 case FacComponent_Invoke:
2775 chan_misdn_log(1, bc->port, " --> Invoke: Procedure:%d BasicService:%d\n",
2776 fac->u.ActivationDiversion.Component.Invoke.Procedure,
2777 fac->u.ActivationDiversion.Component.Invoke.BasicService);
2778 chan_misdn_log(1, bc->port, " --> ForwardedTo:\n");
2779 print_facility_Address(3, &fac->u.ActivationDiversion.Component.Invoke.ForwardedTo, bc);
2780 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2781 print_facility_ServedUserNr(3, &fac->u.ActivationDiversion.Component.Invoke.ServedUser, bc);
2783 case FacComponent_Result:
2784 chan_misdn_log(1, bc->port, " --> Result\n");
2790 case Fac_DeactivationDiversion:
2791 chan_misdn_log(1, bc->port, " --> DeactivationDiversion: InvokeID:%d\n",
2792 fac->u.DeactivationDiversion.InvokeID);
2793 switch (fac->u.DeactivationDiversion.ComponentType) {
2794 case FacComponent_Invoke:
2795 chan_misdn_log(1, bc->port, " --> Invoke: Procedure:%d BasicService:%d\n",
2796 fac->u.DeactivationDiversion.Component.Invoke.Procedure,
2797 fac->u.DeactivationDiversion.Component.Invoke.BasicService);
2798 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2799 print_facility_ServedUserNr(3, &fac->u.DeactivationDiversion.Component.Invoke.ServedUser, bc);
2801 case FacComponent_Result:
2802 chan_misdn_log(1, bc->port, " --> Result\n");
2808 case Fac_ActivationStatusNotificationDiv:
2809 chan_misdn_log(1, bc->port, " --> ActivationStatusNotificationDiv: InvokeID:%d Procedure:%d BasicService:%d\n",
2810 fac->u.ActivationStatusNotificationDiv.InvokeID,
2811 fac->u.ActivationStatusNotificationDiv.Procedure,
2812 fac->u.ActivationStatusNotificationDiv.BasicService);
2813 chan_misdn_log(1, bc->port, " --> ForwardedTo:\n");
2814 print_facility_Address(2, &fac->u.ActivationStatusNotificationDiv.ForwardedTo, bc);
2815 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2816 print_facility_ServedUserNr(2, &fac->u.ActivationStatusNotificationDiv.ServedUser, bc);
2818 case Fac_DeactivationStatusNotificationDiv:
2819 chan_misdn_log(1, bc->port, " --> DeactivationStatusNotificationDiv: InvokeID:%d Procedure:%d BasicService:%d\n",
2820 fac->u.DeactivationStatusNotificationDiv.InvokeID,
2821 fac->u.DeactivationStatusNotificationDiv.Procedure,
2822 fac->u.DeactivationStatusNotificationDiv.BasicService);
2823 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2824 print_facility_ServedUserNr(2, &fac->u.DeactivationStatusNotificationDiv.ServedUser, bc);
2826 case Fac_InterrogationDiversion:
2827 chan_misdn_log(1, bc->port, " --> InterrogationDiversion: InvokeID:%d\n",
2828 fac->u.InterrogationDiversion.InvokeID);
2829 switch (fac->u.InterrogationDiversion.ComponentType) {
2830 case FacComponent_Invoke:
2831 chan_misdn_log(1, bc->port, " --> Invoke: Procedure:%d BasicService:%d\n",
2832 fac->u.InterrogationDiversion.Component.Invoke.Procedure,
2833 fac->u.InterrogationDiversion.Component.Invoke.BasicService);
2834 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2835 print_facility_ServedUserNr(3, &fac->u.InterrogationDiversion.Component.Invoke.ServedUser, bc);
2837 case FacComponent_Result:
2838 chan_misdn_log(1, bc->port, " --> Result:\n");
2839 if (fac->u.InterrogationDiversion.Component.Result.NumRecords) {
2840 for (Index = 0; Index < fac->u.InterrogationDiversion.Component.Result.NumRecords; ++Index) {
2841 chan_misdn_log(1, bc->port, " --> IntResult[%d]:\n", Index);
2842 print_facility_IntResult(3, &fac->u.InterrogationDiversion.Component.Result.List[Index], bc);
2850 case Fac_DiversionInformation:
2851 chan_misdn_log(1, bc->port, " --> DiversionInformation: InvokeID:%d Reason:%d BasicService:%d\n",
2852 fac->u.DiversionInformation.InvokeID,
2853 fac->u.DiversionInformation.DiversionReason,
2854 fac->u.DiversionInformation.BasicService);
2855 if (fac->u.DiversionInformation.ServedUserSubaddress.Length) {
2856 chan_misdn_log(1, bc->port, " --> ServedUserSubaddress:\n");
2857 print_facility_Subaddress(2, &fac->u.DiversionInformation.ServedUserSubaddress, bc);
2859 if (fac->u.DiversionInformation.CallingAddressPresent) {
2860 chan_misdn_log(1, bc->port, " --> CallingAddress:\n");
2861 print_facility_PresentedAddressScreened(2, &fac->u.DiversionInformation.CallingAddress, bc);
2863 if (fac->u.DiversionInformation.OriginalCalledPresent) {
2864 chan_misdn_log(1, bc->port, " --> OriginalCalledNr:\n");
2865 print_facility_PresentedNumberUnscreened(2, &fac->u.DiversionInformation.OriginalCalled, bc);
2867 if (fac->u.DiversionInformation.LastDivertingPresent) {
2868 chan_misdn_log(1, bc->port, " --> LastDivertingNr:\n");
2869 print_facility_PresentedNumberUnscreened(2, &fac->u.DiversionInformation.LastDiverting, bc);
2871 if (fac->u.DiversionInformation.LastDivertingReasonPresent) {
2872 chan_misdn_log(1, bc->port, " --> LastDivertingReason:%d\n", fac->u.DiversionInformation.LastDivertingReason);
2874 if (fac->u.DiversionInformation.UserInfo.Length) {
2875 chan_misdn_log(1, bc->port, " --> UserInfo Length:%d\n", fac->u.DiversionInformation.UserInfo.Length);
2878 case Fac_CallDeflection:
2879 chan_misdn_log(1, bc->port, " --> CallDeflection: InvokeID:%d\n",
2880 fac->u.CallDeflection.InvokeID);
2881 switch (fac->u.CallDeflection.ComponentType) {
2882 case FacComponent_Invoke:
2883 chan_misdn_log(1, bc->port, " --> Invoke:\n");
2884 if (fac->u.CallDeflection.Component.Invoke.PresentationAllowedToDivertedToUserPresent) {
2885 chan_misdn_log(1, bc->port, " --> PresentationAllowed:%d\n",
2886 fac->u.CallDeflection.Component.Invoke.PresentationAllowedToDivertedToUser);
2888 chan_misdn_log(1, bc->port, " --> DeflectionAddress:\n");
2889 print_facility_Address(3, &fac->u.CallDeflection.Component.Invoke.Deflection, bc);
2891 case FacComponent_Result:
2892 chan_misdn_log(1, bc->port, " --> Result\n");
2898 case Fac_CallRerouteing:
2899 chan_misdn_log(1, bc->port, " --> CallRerouteing: InvokeID:%d\n",
2900 fac->u.CallRerouteing.InvokeID);
2901 switch (fac->u.CallRerouteing.ComponentType) {
2902 case FacComponent_Invoke:
2903 chan_misdn_log(1, bc->port, " --> Invoke: Reason:%d Counter:%d\n",
2904 fac->u.CallRerouteing.Component.Invoke.ReroutingReason,
2905 fac->u.CallRerouteing.Component.Invoke.ReroutingCounter);
2906 chan_misdn_log(1, bc->port, " --> CalledAddress:\n");
2907 print_facility_Address(3, &fac->u.CallRerouteing.Component.Invoke.CalledAddress, bc);
2908 print_facility_Q931_Bc_Hlc_Llc_Uu(2, &fac->u.CallRerouteing.Component.Invoke.Q931ie, bc);
2909 chan_misdn_log(1, bc->port, " --> LastReroutingNr:\n");
2910 print_facility_PresentedNumberUnscreened(3, &fac->u.CallRerouteing.Component.Invoke.LastRerouting, bc);
2911 chan_misdn_log(1, bc->port, " --> SubscriptionOption:%d\n",
2912 fac->u.CallRerouteing.Component.Invoke.SubscriptionOption);
2913 if (fac->u.CallRerouteing.Component.Invoke.CallingPartySubaddress.Length) {
2914 chan_misdn_log(1, bc->port, " --> CallingParty:\n");
2915 print_facility_Subaddress(3, &fac->u.CallRerouteing.Component.Invoke.CallingPartySubaddress, bc);
2918 case FacComponent_Result:
2919 chan_misdn_log(1, bc->port, " --> Result\n");
2925 case Fac_InterrogateServedUserNumbers:
2926 chan_misdn_log(1, bc->port, " --> InterrogateServedUserNumbers: InvokeID:%d\n",
2927 fac->u.InterrogateServedUserNumbers.InvokeID);
2928 switch (fac->u.InterrogateServedUserNumbers.ComponentType) {
2929 case FacComponent_Invoke:
2930 chan_misdn_log(1, bc->port, " --> Invoke\n");
2932 case FacComponent_Result:
2933 chan_misdn_log(1, bc->port, " --> Result:\n");
2934 if (fac->u.InterrogateServedUserNumbers.Component.Result.NumRecords) {
2935 for (Index = 0; Index < fac->u.InterrogateServedUserNumbers.Component.Result.NumRecords; ++Index) {
2936 chan_misdn_log(1, bc->port, " --> ServedUserNr[%d]:\n", Index);
2937 print_facility_PartyNumber(3, &fac->u.InterrogateServedUserNumbers.Component.Result.List[Index], bc);
2945 case Fac_DivertingLegInformation1:
2946 chan_misdn_log(1, bc->port, " --> DivertingLegInformation1: InvokeID:%d Reason:%d SubscriptionOption:%d\n",
2947 fac->u.DivertingLegInformation1.InvokeID,
2948 fac->u.DivertingLegInformation1.DiversionReason,
2949 fac->u.DivertingLegInformation1.SubscriptionOption);
2950 if (fac->u.DivertingLegInformation1.DivertedToPresent) {
2951 chan_misdn_log(1, bc->port, " --> DivertedToNr:\n");
2952 print_facility_PresentedNumberUnscreened(2, &fac->u.DivertingLegInformation1.DivertedTo, bc);
2955 case Fac_DivertingLegInformation2:
2956 chan_misdn_log(1, bc->port, " --> DivertingLegInformation2: InvokeID:%d Reason:%d Count:%d\n",
2957 fac->u.DivertingLegInformation2.InvokeID,
2958 fac->u.DivertingLegInformation2.DiversionReason,
2959 fac->u.DivertingLegInformation2.DiversionCounter);
2960 if (fac->u.DivertingLegInformation2.DivertingPresent) {
2961 chan_misdn_log(1, bc->port, " --> DivertingNr:\n");
2962 print_facility_PresentedNumberUnscreened(2, &fac->u.DivertingLegInformation2.Diverting, bc);
2964 if (fac->u.DivertingLegInformation2.OriginalCalledPresent) {
2965 chan_misdn_log(1, bc->port, " --> OriginalCalledNr:\n");
2966 print_facility_PresentedNumberUnscreened(2, &fac->u.DivertingLegInformation2.OriginalCalled, bc);
2969 case Fac_DivertingLegInformation3:
2970 chan_misdn_log(1, bc->port, " --> DivertingLegInformation3: InvokeID:%d PresentationAllowed:%d\n",
2971 fac->u.DivertingLegInformation3.InvokeID,
2972 fac->u.DivertingLegInformation3.PresentationAllowedIndicator);
2975 #else /* !defined(AST_MISDN_ENHANCEMENTS) */
2978 chan_misdn_log(1, bc->port, " --> calldeflect to: %s, presentable: %s\n", fac->u.CDeflection.DeflectedToNumber,
2979 fac->u.CDeflection.PresentationAllowed ? "yes" : "no");
2981 #endif /* !defined(AST_MISDN_ENHANCEMENTS) */
2982 case Fac_AOCDCurrency:
2983 if (fac->u.AOCDcur.chargeNotAvailable) {
2984 chan_misdn_log(1, bc->port, " --> AOCD currency: charge not available\n");
2985 } else if (fac->u.AOCDcur.freeOfCharge) {
2986 chan_misdn_log(1, bc->port, " --> AOCD currency: free of charge\n");
2987 } else if (fac->u.AOCDchu.billingId >= 0) {
2988 chan_misdn_log(1, bc->port, " --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s billingId:%d\n",
2989 fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
2990 (fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDcur.billingId);
2992 chan_misdn_log(1, bc->port, " --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s\n",
2993 fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
2994 (fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total");
2997 case Fac_AOCDChargingUnit:
2998 if (fac->u.AOCDchu.chargeNotAvailable) {
2999 chan_misdn_log(1, bc->port, " --> AOCD charging unit: charge not available\n");
3000 } else if (fac->u.AOCDchu.freeOfCharge) {
3001 chan_misdn_log(1, bc->port, " --> AOCD charging unit: free of charge\n");
3002 } else if (fac->u.AOCDchu.billingId >= 0) {
3003 chan_misdn_log(1, bc->port, " --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s billingId:%d\n",
3004 fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDchu.billingId);
3006 chan_misdn_log(1, bc->port, " --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s\n",
3007 fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total");
3010 #if defined(AST_MISDN_ENHANCEMENTS)
3012 chan_misdn_log(1, bc->port, " --> ERROR: InvokeID:%d, Code:0x%02x\n",
3013 fac->u.ERROR.invokeId, fac->u.ERROR.errorValue);
3016 chan_misdn_log(1, bc->port, " --> RESULT: InvokeID:%d\n",
3017 fac->u.RESULT.InvokeID);
3020 if (fac->u.REJECT.InvokeIDPresent) {
3021 chan_misdn_log(1, bc->port, " --> REJECT: InvokeID:%d, Code:0x%02x\n",
3022 fac->u.REJECT.InvokeID, fac->u.REJECT.Code);
3024 chan_misdn_log(1, bc->port, " --> REJECT: Code:0x%02x\n",
3025 fac->u.REJECT.Code);
3028 case Fac_EctExecute:
3029 chan_misdn_log(1, bc->port, " --> EctExecute: InvokeID:%d\n",
3030 fac->u.EctExecute.InvokeID);
3032 case Fac_ExplicitEctExecute:
3033 chan_misdn_log(1, bc->port, " --> ExplicitEctExecute: InvokeID:%d LinkID:%d\n",
3034 fac->u.ExplicitEctExecute.InvokeID,
3035 fac->u.ExplicitEctExecute.LinkID);
3037 case Fac_RequestSubaddress:
3038 chan_misdn_log(1, bc->port, " --> RequestSubaddress: InvokeID:%d\n",
3039 fac->u.RequestSubaddress.InvokeID);
3041 case Fac_SubaddressTransfer:
3042 chan_misdn_log(1, bc->port, " --> SubaddressTransfer: InvokeID:%d\n",
3043 fac->u.SubaddressTransfer.InvokeID);
3044 print_facility_Subaddress(1, &fac->u.SubaddressTransfer.Subaddress, bc);
3046 case Fac_EctLinkIdRequest:
3047 chan_misdn_log(1, bc->port, " --> EctLinkIdRequest: InvokeID:%d\n",
3048 fac->u.EctLinkIdRequest.InvokeID);
3049 switch (fac->u.EctLinkIdRequest.ComponentType) {
3050 case FacComponent_Invoke:
3051 chan_misdn_log(1, bc->port, " --> Invoke\n");
3053 case FacComponent_Result:
3054 chan_misdn_log(1, bc->port, " --> Result: LinkID:%d\n",
3055 fac->u.EctLinkIdRequest.Component.Result.LinkID);
3062 chan_misdn_log(1, bc->port, " --> EctInform: InvokeID:%d Status:%d\n",
3063 fac->u.EctInform.InvokeID,
3064 fac->u.EctInform.Status);
3065 if (fac->u.EctInform.RedirectionPresent) {
3066 chan_misdn_log(1, bc->port, " --> Redirection Number\n");
3067 print_facility_PresentedNumberUnscreened(2, &fac->u.EctInform.Redirection, bc);
3070 case Fac_EctLoopTest:
3071 chan_misdn_log(1, bc->port, " --> EctLoopTest: InvokeID:%d\n",
3072 fac->u.EctLoopTest.InvokeID);
3073 switch (fac->u.EctLoopTest.ComponentType) {
3074 case FacComponent_Invoke:
3075 chan_misdn_log(1, bc->port, " --> Invoke: CallTransferID:%d\n",
3076 fac->u.EctLoopTest.Component.Invoke.CallTransferID);
3078 case FacComponent_Result:
3079 chan_misdn_log(1, bc->port, " --> Result: LoopResult:%d\n",
3080 fac->u.EctLoopTest.Component.Result.LoopResult);
3086 case Fac_StatusRequest:
3087 chan_misdn_log(1, bc->port, " --> StatusRequest: InvokeID:%d\n",
3088 fac->u.StatusRequest.InvokeID);
3089 switch (fac->u.StatusRequest.ComponentType) {
3090 case FacComponent_Invoke:
3091 chan_misdn_log(1, bc->port, " --> Invoke: Compatibility:%d\n",
3092 fac->u.StatusRequest.Component.Invoke.CompatibilityMode);
3094 case FacComponent_Result:
3095 chan_misdn_log(1, bc->port, " --> Result: Status:%d\n",
3096 fac->u.StatusRequest.Component.Result.Status);
3102 case Fac_CallInfoRetain:
3103 chan_misdn_log(1, bc->port, " --> CallInfoRetain: InvokeID:%d, LinkageID:%d\n",
3104 fac->u.CallInfoRetain.InvokeID, fac->u.CallInfoRetain.CallLinkageID);
3106 case Fac_CCBSDeactivate:
3107 chan_misdn_log(1, bc->port, " --> CCBSDeactivate: InvokeID:%d\n",
3108 fac->u.CCBSDeactivate.InvokeID);
3109 switch (fac->u.CCBSDeactivate.ComponentType) {
3110 case FacComponent_Invoke:
3111 chan_misdn_log(1, bc->port, " --> Invoke: CCBSReference:%d\n",
3112 fac->u.CCBSDeactivate.Component.Invoke.CCBSReference);
3114 case FacComponent_Result:
3115 chan_misdn_log(1, bc->port, " --> Result\n");
3122 chan_misdn_log(1, bc->port, " --> CCBSErase: InvokeID:%d, CCBSReference:%d RecallMode:%d, Reason:%d\n",
3123 fac->u.CCBSErase.InvokeID, fac->u.CCBSErase.CCBSReference,
3124 fac->u.CCBSErase.RecallMode, fac->u.CCBSErase.Reason);
3125 chan_misdn_log(1, bc->port, " --> AddressOfB\n");
3126 print_facility_Address(2, &fac->u.CCBSErase.AddressOfB, bc);
3127 print_facility_Q931_Bc_Hlc_Llc(1, &fac->u.CCBSErase.Q931ie, bc);
3129 case Fac_CCBSRemoteUserFree:
3130 chan_misdn_log(1, bc->port, " --> CCBSRemoteUserFree: InvokeID:%d, CCBSReference:%d RecallMode:%d\n",
3131 fac->u.CCBSRemoteUserFree.InvokeID, fac->u.CCBSRemoteUserFree.CCBSReference,
3132 fac->u.CCBSRemoteUserFree.RecallMode);
3133 chan_misdn_log(1, bc->port, " --> AddressOfB\n");
3134 print_facility_Address(2, &fac->u.CCBSRemoteUserFree.AddressOfB, bc);
3135 print_facility_Q931_Bc_Hlc_Llc(1, &fac->u.CCBSRemoteUserFree.Q931ie, bc);
3138 chan_misdn_log(1, bc->port, " --> CCBSCall: InvokeID:%d, CCBSReference:%d\n",
3139 fac->u.CCBSCall.InvokeID, fac->u.CCBSCall.CCBSReference);
3141 case Fac_CCBSStatusRequest:
3142 chan_misdn_log(1, bc->port, " --> CCBSStatusRequest: InvokeID:%d\n",
3143 fac->u.CCBSStatusRequest.InvokeID);
3144 switch (fac->u.CCBSStatusRequest.ComponentType) {
3145 case FacComponent_Invoke:
3146 chan_misdn_log(1, bc->port, " --> Invoke: CCBSReference:%d RecallMode:%d\n",
3147 fac->u.CCBSStatusRequest.Component.Invoke.CCBSReference,
3148 fac->u.CCBSStatusRequest.Component.Invoke.RecallMode);
3149 print_facility_Q931_Bc_Hlc_Llc(2, &fac->u.CCBSStatusRequest.Component.Invoke.Q931ie, bc);
3151 case FacComponent_Result:
3152 chan_misdn_log(1, bc->port, " --> Result: Free:%d\n",
3153 fac->u.CCBSStatusRequest.Component.Result.Free);
3160 chan_misdn_log(1, bc->port, " --> CCBSBFree: InvokeID:%d, CCBSReference:%d RecallMode:%d\n",
3161 fac->u.CCBSBFree.InvokeID, fac->u.CCBSBFree.CCBSReference,
3162 fac->u.CCBSBFree.RecallMode);
3163 chan_misdn_log(1, bc->port, " --> AddressOfB\n");
3164 print_facility_Address(2, &fac->u.CCBSBFree.AddressOfB, bc);
3165 print_facility_Q931_Bc_Hlc_Llc(1, &fac->u.CCBSBFree.Q931ie, bc);
3167 case Fac_EraseCallLinkageID:
3168 chan_misdn_log(1, bc->port, " --> EraseCallLinkageID: InvokeID:%d, LinkageID:%d\n",
3169 fac->u.EraseCallLinkageID.InvokeID, fac->u.EraseCallLinkageID.CallLinkageID);
3171 case Fac_CCBSStopAlerting:
3172 chan_misdn_log(1, bc->port, " --> CCBSStopAlerting: InvokeID:%d, CCBSReference:%d\n",
3173 fac->u.CCBSStopAlerting.InvokeID, fac->u.CCBSStopAlerting.CCBSReference);
3175 case Fac_CCBSRequest:
3176 chan_misdn_log(1, bc->port, " --> CCBSRequest: InvokeID:%d\n",
3177 fac->u.CCBSRequest.InvokeID);
3178 switch (fac->u.CCBSRequest.ComponentType) {
3179 case FacComponent_Invoke:
3180 chan_misdn_log(1, bc->port, " --> Invoke: LinkageID:%d\n",
3181 fac->u.CCBSRequest.Component.Invoke.CallLinkageID);
3183 case FacComponent_Result:
3184 chan_misdn_log(1, bc->port, " --> Result: CCBSReference:%d RecallMode:%d\n",
3185 fac->u.CCBSRequest.Component.Result.CCBSReference,
3186 fac->u.CCBSRequest.Component.Result.RecallMode);
3192 case Fac_CCBSInterrogate:
3193 chan_misdn_log(1, bc->port, " --> CCBSInterrogate: InvokeID:%d\n",
3194 fac->u.CCBSInterrogate.InvokeID);
3195 switch (fac->u.CCBSInterrogate.ComponentType) {
3196 case FacComponent_Invoke:
3197 chan_misdn_log(1, bc->port, " --> Invoke\n");
3198 if (fac->u.CCBSInterrogate.Component.Invoke.CCBSReferencePresent) {
3199 chan_misdn_log(1, bc->port, " --> CCBSReference:%d\n",
3200 fac->u.CCBSInterrogate.Component.Invoke.CCBSReference);
3202 if (fac->u.CCBSInterrogate.Component.Invoke.AParty.LengthOfNumber) {
3203 chan_misdn_log(1, bc->port, " --> AParty\n");
3204 print_facility_PartyNumber(3, &fac->u.CCBSInterrogate.Component.Invoke.AParty, bc);
3207 case FacComponent_Result:
3208 chan_misdn_log(1, bc->port, " --> Result: RecallMode:%d\n",
3209 fac->u.CCBSInterrogate.Component.Result.RecallMode);
3210 if (fac->u.CCBSInterrogate.Component.Result.NumRecords) {
3211 for (Index = 0; Index < fac->u.CCBSInterrogate.Component.Result.NumRecords; ++Index) {
3212 chan_misdn_log(1, bc->port, " --> CallDetails[%d]:\n", Index);
3213 print_facility_CallInformation(3, &fac->u.CCBSInterrogate.Component.Result.CallDetails[Index], bc);
3221 case Fac_CCNRRequest:
3222 chan_misdn_log(1, bc->port, " --> CCNRRequest: InvokeID:%d\n",
3223 fac->u.CCNRRequest.InvokeID);
3224 switch (fac->u.CCNRRequest.ComponentType) {
3225 case FacComponent_Invoke:
3226 chan_misdn_log(1, bc->port, " --> Invoke: LinkageID:%d\n",
3227 fac->u.CCNRRequest.Component.Invoke.CallLinkageID);
3229 case FacComponent_Result:
3230 chan_misdn_log(1, bc->port, " --> Result: CCBSReference:%d RecallMode:%d\n",
3231 fac->u.CCNRRequest.Component.Result.CCBSReference,
3232 fac->u.CCNRRequest.Component.Result.RecallMode);
3238 case Fac_CCNRInterrogate:
3239 chan_misdn_log(1, bc->port, " --> CCNRInterrogate: InvokeID:%d\n",
3240 fac->u.CCNRInterrogate.InvokeID);
3241 switch (fac->u.CCNRInterrogate.ComponentType) {
3242 case FacComponent_Invoke:
3243 chan_misdn_log(1, bc->port, " --> Invoke\n");
3244 if (fac->u.CCNRInterrogate.Component.Invoke.CCBSReferencePresent) {
3245 chan_misdn_log(1, bc->port, " --> CCBSReference:%d\n",
3246 fac->u.CCNRInterrogate.Component.Invoke.CCBSReference);
3248 if (fac->u.CCNRInterrogate.Component.Invoke.AParty.LengthOfNumber) {
3249 chan_misdn_log(1, bc->port, " --> AParty\n");
3250 print_facility_PartyNumber(3, &fac->u.CCNRInterrogate.Component.Invoke.AParty, bc);
3253 case FacComponent_Result:
3254 chan_misdn_log(1, bc->port, " --> Result: RecallMode:%d\n",
3255 fac->u.CCNRInterrogate.Component.Result.RecallMode);
3256 if (fac->u.CCNRInterrogate.Component.Result.NumRecords) {
3257 for (Index = 0; Index < fac->u.CCNRInterrogate.Component.Result.NumRecords; ++Index) {
3258 chan_misdn_log(1, bc->port, " --> CallDetails[%d]:\n", Index);
3259 print_facility_CallInformation(3, &fac->u.CCNRInterrogate.Component.Result.CallDetails[Index], bc);
3267 case Fac_CCBS_T_Call:
3268 chan_misdn_log(1, bc->port, " --> CCBS_T_Call: InvokeID:%d\n",
3269 fac->u.CCBS_T_Call.InvokeID);
3271 case Fac_CCBS_T_Suspend:
3272 chan_misdn_log(1, bc->port, " --> CCBS_T_Suspend: InvokeID:%d\n",
3273 fac->u.CCBS_T_Suspend.InvokeID);
3275 case Fac_CCBS_T_Resume:
3276 chan_misdn_log(1, bc->port, " --> CCBS_T_Resume: InvokeID:%d\n",
3277 fac->u.CCBS_T_Resume.InvokeID);
3279 case Fac_CCBS_T_RemoteUserFree:
3280 chan_misdn_log(1, bc->port, " --> CCBS_T_RemoteUserFree: InvokeID:%d\n",
3281 fac->u.CCBS_T_RemoteUserFree.InvokeID);
3283 case Fac_CCBS_T_Available:
3284 chan_misdn_log(1, bc->port, " --> CCBS_T_Available: InvokeID:%d\n",