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 <depend>isdnnet</depend>
62 <depend>misdn</depend>
63 <depend>suppserv</depend>
64 <support_level>extended</support_level>
69 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
72 #include <sys/socket.h>
74 #include <arpa/inet.h>
76 #include <sys/ioctl.h>
79 #include <semaphore.h>
83 #include "asterisk/channel.h"
84 #include "asterisk/config.h"
85 #include "asterisk/module.h"
86 #include "asterisk/pbx.h"
87 #include "asterisk/io.h"
88 #include "asterisk/frame.h"
89 #include "asterisk/translate.h"
90 #include "asterisk/cli.h"
91 #include "asterisk/musiconhold.h"
92 #include "asterisk/dsp.h"
93 #include "asterisk/file.h"
94 #include "asterisk/callerid.h"
95 #include "asterisk/indications.h"
96 #include "asterisk/app.h"
97 #include "asterisk/features.h"
98 #include "asterisk/term.h"
99 #include "asterisk/sched.h"
100 #include "asterisk/stringfields.h"
101 #include "asterisk/abstract_jb.h"
102 #include "asterisk/causes.h"
103 #include "asterisk/format.h"
104 #include "asterisk/format_cap.h"
106 #include "chan_misdn_config.h"
107 #include "isdn_lib.h"
109 static char global_tracefile[BUFFERSIZE + 1];
111 static int g_config_initialized = 0;
125 /*! \brief allocates the jb-structure and initialize the elements */
126 struct misdn_jb *misdn_jb_init(int size, int upper_threshold);
128 /*! \brief frees the data and destroys the given jitterbuffer struct */
129 void misdn_jb_destroy(struct misdn_jb *jb);
131 /*! \brief fills the jitterbuffer with len data returns < 0 if there was an
132 error (buffer overrun). */
133 int misdn_jb_fill(struct misdn_jb *jb, const char *data, int len);
135 /*! \brief gets len bytes out of the jitterbuffer if available, else only the
136 available data is returned and the return value indicates the number
138 int misdn_jb_empty(struct misdn_jb *jb, char *data, int len);
140 static char *complete_ch(struct ast_cli_args *a);
141 static char *complete_debug_port(struct ast_cli_args *a);
142 static char *complete_show_config(struct ast_cli_args *a);
144 /* BEGIN: chan_misdn.h */
146 #if defined(AST_MISDN_ENHANCEMENTS)
148 * This timeout duration is to clean up any call completion records that
149 * are forgotten about by the switch.
151 #define MISDN_CC_RECORD_AGE_MAX (6UL * 60 * 60) /* seconds */
153 #define MISDN_CC_REQUEST_WAIT_MAX 5 /* seconds */
156 * \brief Caller that initialized call completion services
159 * This data is the payload for a datastore that is put on the channel that
160 * initializes call completion services. This datastore is set to be inherited
161 * by the outbound mISDN channel. When one of these channels hangs up, the
162 * channel pointer will be set to NULL. That way, we can ensure that we do not
163 * touch this channel after it gets destroyed.
165 struct misdn_cc_caller {
166 /*! \brief The channel that initialized call completion services */
167 struct ast_channel *chan;
170 struct misdn_cc_notify {
171 /*! \brief Dialplan: Notify extension priority */
174 /*! \brief Dialplan: Notify extension context */
175 char context[AST_MAX_CONTEXT];
177 /*! \brief Dialplan: Notify extension number (User-A) */
178 char exten[AST_MAX_EXTENSION];
181 /*! \brief mISDN call completion record */
182 struct misdn_cc_record {
183 /*! \brief Call completion record linked list */
184 AST_LIST_ENTRY(misdn_cc_record) list;
186 /*! \brief Time the record was created. */
189 /*! \brief MISDN_CC_RECORD_ID value */
193 * \brief Logical Layer 1 port associated with this
194 * call completion record
198 /*! \brief TRUE if point-to-point mode (CCBS-T/CCNR-T mode) */
201 /*! \brief Mode specific parameters */
203 /*! \brief point-to-point specific parameters. */
206 * \brief Call-completion signaling link.
207 * NULL if signaling link not established.
209 struct misdn_bchannel *bc;
212 * \brief TRUE if we requested the request retention option
215 int requested_retention;
218 * \brief TRUE if the request retention option is enabled.
220 int retention_enabled;
223 /*! \brief point-to-multi-point specific parameters. */
225 /*! \brief CallLinkageID (valid when port determined) */
228 /*! \breif CCBSReference (valid when activated is TRUE) */
231 /*! \brief globalRecall(0), specificRecall(1) */
236 /*! \brief TRUE if call completion activated */
239 /*! \brief Outstanding message ID (valid when outstanding_message) */
242 /*! \brief TRUE if waiting for a response from a message (invoke_id is valid) */
243 int outstanding_message;
245 /*! \brief TRUE if activation has been requested */
246 int activation_requested;
249 * \brief TRUE if User-A is free
250 * \note PTMP - Used to answer CCBSStatusRequest.
251 * PTP - Determines how to respond to CCBS_T_RemoteUserFree.
255 /*! \brief Error code received from last outstanding message. */
256 enum FacErrorCode error_code;
258 /*! \brief Reject code received from last outstanding message. */
259 enum FacRejectCode reject_code;
262 * \brief Saved struct misdn_bchannel call information when
263 * attempted to call User-B
266 /*! \brief User-A caller id information */
267 struct misdn_party_id caller;
269 /*! \brief User-B number information */
270 struct misdn_party_dialing dialed;
272 /*! \brief The BC, HLC (optional) and LLC (optional) contents from the SETUP message. */
273 struct Q931_Bc_Hlc_Llc setup_bc_hlc_llc;
275 /*! \brief SETUP message bearer capability field code value */
278 /*! \brief TRUE if call made in digital HDLC mode */
282 /*! \brief Dialplan location to indicate User-B free and User-A is free */
283 struct misdn_cc_notify remote_user_free;
285 /*! \brief Dialplan location to indicate User-B free and User-A is busy */
286 struct misdn_cc_notify b_free;
289 /*! \brief mISDN call completion record database */
290 static AST_LIST_HEAD_STATIC(misdn_cc_records_db, misdn_cc_record);
291 /*! \brief Next call completion record ID to use */
292 static __u16 misdn_cc_record_id;
293 /*! \brief Next invoke ID to use */
294 static __s16 misdn_invoke_id;
296 static const char misdn_no_response_from_network[] = "No response from network";
297 static const char misdn_cc_record_not_found[] = "Call completion record not found";
299 /* mISDN channel variable names */
300 #define MISDN_CC_RECORD_ID "MISDN_CC_RECORD_ID"
301 #define MISDN_CC_STATUS "MISDN_CC_STATUS"
302 #define MISDN_ERROR_MSG "MISDN_ERROR_MSG"
303 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
305 static ast_mutex_t release_lock;
307 enum misdn_chan_state {
308 MISDN_NOTHING = 0, /*!< at beginning */
309 MISDN_WAITING4DIGS, /*!< when waiting for info */
310 MISDN_EXTCANTMATCH, /*!< when asterisk couldn't match our ext */
311 MISDN_INCOMING_SETUP, /*!< for incoming setup */
312 MISDN_DIALING, /*!< when pbx_start */
313 MISDN_PROGRESS, /*!< we have progress */
314 MISDN_PROCEEDING, /*!< we have progress */
315 MISDN_CALLING, /*!< when misdn_call is called */
316 MISDN_CALLING_ACKNOWLEDGE, /*!< when we get SETUP_ACK */
317 MISDN_ALERTING, /*!< when Alerting */
318 MISDN_BUSY, /*!< when BUSY */
319 MISDN_CONNECTED, /*!< when connected */
320 MISDN_DISCONNECTED, /*!< when connected */
321 MISDN_CLEANING, /*!< when hangup from * but we were connected before */
324 /*! Asterisk created the channel (outgoing call) */
326 /*! mISDN created the channel (incoming call) */
329 enum misdn_hold_state {
330 MISDN_HOLD_IDLE, /*!< HOLD not active */
331 MISDN_HOLD_ACTIVE, /*!< Call is held */
332 MISDN_HOLD_TRANSFER, /*!< Held call is being transferred */
333 MISDN_HOLD_DISCONNECT, /*!< Held call is being disconnected */
337 * \brief Call HOLD state.
339 enum misdn_hold_state state;
341 * \brief Logical port the channel call record is HELD on
342 * because the B channel is no longer associated.
347 * \brief Original B channel number the HELD call was using.
348 * \note Used only for debug display messages.
353 #define chan_list_ref(obj, debug) (ao2_t_ref((obj), +1, (debug)), (obj))
354 #define chan_list_unref(obj, debug) (ao2_t_ref((obj), -1, (debug)), NULL)
357 * \brief Channel call record structure
361 * \brief The "allowed_bearers" string read in from /etc/asterisk/misdn.conf
363 char allowed_bearers[BUFFERSIZE + 1];
366 * \brief State of the channel
368 enum misdn_chan_state state;
371 * \brief TRUE if a hangup needs to be queued
372 * \note This is a debug flag only used to catch calls to hangup_chan() that are already hungup.
374 int need_queue_hangup;
377 * \brief TRUE if a channel can be hung up by calling asterisk directly when done.
382 * \brief TRUE if we could send an AST_CONTROL_BUSY if needed.
387 * \brief Who originally created this channel. ORG_AST or ORG_MISDN
392 * \brief TRUE of we are not to respond immediately to a SETUP message. Check the dialplan first.
393 * \note The "noautorespond_on_setup" boolean read in from /etc/asterisk/misdn.conf
395 int noautorespond_on_setup;
397 int norxtone; /*!< Boolean assigned values but the value is not used. */
400 * \brief TRUE if we are not to generate tones (Playtones)
405 * \brief TRUE if echo canceller is enabled. Value is toggled.
410 * \brief TRUE if you want to send Tone Indications to an incoming
411 * ISDN channel on a TE Port.
412 * \note The "incoming_early_audio" boolean read in from /etc/asterisk/misdn.conf
414 int incoming_early_audio;
417 * \brief TRUE if DTMF digits are to be passed inband only.
418 * \note It is settable by the misdn_set_opt() application.
423 * \brief Pipe file descriptor handles array.
424 * Read from pipe[0], write to pipe[1]
429 * \brief Read buffer for inbound audio from pipe[0]
431 char ast_rd_buf[4096];
434 * \brief Inbound audio frame returned by misdn_read().
436 struct ast_frame frame;
439 * \brief Fax detection option. (0:no 1:yes 2:yes+nojump)
440 * \note The "faxdetect" option string read in from /etc/asterisk/misdn.conf
441 * \note It is settable by the misdn_set_opt() application.
446 * \brief Number of seconds to detect a Fax machine when detection enabled.
447 * \note 0 disables the timeout.
448 * \note The "faxdetect_timeout" value read in from /etc/asterisk/misdn.conf
450 int faxdetect_timeout;
453 * \brief Starting time of fax detection with timeout when nonzero.
455 struct timeval faxdetect_tv;
458 * \brief TRUE if a fax has been detected.
463 * \brief TRUE if we will use the Asterisk DSP to detect DTMF/Fax
464 * \note The "astdtmf" boolean read in from /etc/asterisk/misdn.conf
469 * \brief Jitterbuffer length
470 * \note The "jitterbuffer" value read in from /etc/asterisk/misdn.conf
475 * \brief Jitterbuffer upper threshold
476 * \note The "jitterbuffer_upper_threshold" value read in from /etc/asterisk/misdn.conf
478 int jb_upper_threshold;
481 * \brief Allocated jitterbuffer controller
482 * \note misdn_jb_init() creates the jitterbuffer.
483 * \note Must use misdn_jb_destroy() to clean up.
488 * \brief Allocated DSP controller
489 * \note ast_dsp_new() creates the DSP controller.
490 * \note Must use ast_dsp_free() to clean up.
495 * \brief Associated Asterisk channel structure.
497 struct ast_channel * ast;
500 * \brief Associated B channel structure.
502 struct misdn_bchannel *bc;
504 #if defined(AST_MISDN_ENHANCEMENTS)
506 * \brief Peer channel for which call completion was initialized.
508 struct misdn_cc_caller *peer;
510 /*! \brief Associated call completion record ID (-1 if not associated) */
512 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
515 * \brief HELD channel call information
517 struct hold_info hold;
520 * \brief From associated B channel: Layer 3 process ID
521 * \note Used to find the HELD channel call record when retrieving a call.
526 * \brief From associated B channel: B Channel mISDN driver layer ID from mISDN_get_layerid()
527 * \note Used only for debug display messages.
532 * \brief Incoming call dialplan context identifier.
533 * \note The "context" string read in from /etc/asterisk/misdn.conf
535 char context[AST_MAX_CONTEXT];
538 * \brief The configured music-on-hold class to use for this call.
539 * \note The "musicclass" string read in from /etc/asterisk/misdn.conf
541 char mohinterpret[MAX_MUSICCLASS];
544 * \brief Number of outgoing audio frames dropped since last debug gripe message.
546 int dropped_frame_cnt;
549 * \brief TRUE if we must do the ringback tones.
550 * \note The "far_alerting" boolean read in from /etc/asterisk/misdn.conf
555 * \brief TRUE if NT should disconnect an overlap dialing call when a timeout occurs.
556 * \note The "nttimeout" boolean read in from /etc/asterisk/misdn.conf
561 * \brief Tone zone sound used for dialtone generation.
562 * \note Used as a boolean. Non-NULL to prod generation if enabled.
564 struct ast_tone_zone_sound *ts;
567 * \brief Enables overlap dialing for the set amount of seconds. (0 = Disabled)
568 * \note The "overlapdial" value read in from /etc/asterisk/misdn.conf
573 * \brief Overlap dialing timeout Task ID. -1 if not running.
575 int overlap_dial_task;
578 * \brief overlap_tv access lock.
580 ast_mutex_t overlap_tv_lock;
583 * \brief Overlap timer start time. Timer restarted for every digit received.
585 struct timeval overlap_tv;
588 * \brief Next channel call record in the list.
590 struct chan_list *next;
597 void export_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
598 void import_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
599 static struct ast_frame *process_ast_dsp(struct chan_list *tmp, struct ast_frame *frame);
605 struct robin_list *next;
606 struct robin_list *prev;
608 static struct robin_list *robin = NULL;
611 static void free_robin_list(void)
613 struct robin_list *r;
614 struct robin_list *next;
616 for (r = robin, robin = NULL; r; r = next) {
623 static struct robin_list *get_robin_position(char *group)
625 struct robin_list *new;
626 struct robin_list *iter = robin;
627 for (; iter; iter = iter->next) {
628 if (!strcasecmp(iter->group, group)) {
632 new = ast_calloc(1, sizeof(*new));
636 new->group = ast_strdup(group);
651 /*! \brief the main schedule context for stuff like l1 watcher, overlap dial, ... */
652 static struct ast_sched_context *misdn_tasks = NULL;
653 static pthread_t misdn_tasks_thread;
655 static int *misdn_ports;
657 static void chan_misdn_log(int level, int port, char *tmpl, ...)
658 __attribute__((format(printf, 3, 4)));
660 static struct ast_channel *misdn_new(struct chan_list *cl, int state, char *exten, char *callerid, struct ast_format_cap *cap, const char *linkedid, int port, int c);
661 static void send_digit_to_chan(struct chan_list *cl, char digit);
663 static int pbx_start_chan(struct chan_list *ch);
665 #define MISDN_ASTERISK_TECH_PVT(ast) ast_channel_tech_pvt(ast)
666 #define MISDN_ASTERISK_TECH_PVT_SET(ast, value) ast_channel_tech_pvt_set(ast, value)
668 #include "asterisk/strings.h"
670 /* #define MISDN_DEBUG 1 */
672 static const char misdn_type[] = "mISDN";
674 static int tracing = 0;
676 /*! \brief Only alaw and mulaw is allowed for now */
677 static struct ast_format prefformat; /* AST_FORMAT_SLINEAR ; AST_FORMAT_ULAW | */
679 static int *misdn_debug;
680 static int *misdn_debug_only;
681 static int max_ports;
683 static int *misdn_in_calls;
684 static int *misdn_out_calls;
687 * \brief Global channel call record list head.
689 static struct chan_list *cl_te=NULL;
690 static ast_mutex_t cl_te_lock;
692 static enum event_response_e
693 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data);
695 static int send_cause2ast(struct ast_channel *ast, struct misdn_bchannel *bc, struct chan_list *ch);
697 static void cl_queue_chan(struct chan_list *chan);
699 static int dialtone_indicate(struct chan_list *cl);
700 static void hanguptone_indicate(struct chan_list *cl);
701 static int stop_indicate(struct chan_list *cl);
703 static int start_bc_tones(struct chan_list *cl);
704 static int stop_bc_tones(struct chan_list *cl);
705 static void release_chan_early(struct chan_list *ch);
706 static void release_chan(struct chan_list *ch, struct misdn_bchannel *bc);
708 #if defined(AST_MISDN_ENHANCEMENTS)
709 static const char misdn_command_name[] = "misdn_command";
710 static int misdn_command_exec(struct ast_channel *chan, const char *data);
711 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
712 static int misdn_check_l2l1(struct ast_channel *chan, const char *data);
713 static int misdn_set_opt_exec(struct ast_channel *chan, const char *data);
714 static int misdn_facility_exec(struct ast_channel *chan, const char *data);
716 int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len);
718 void debug_numtype(int port, int numtype, char *type);
720 int add_out_calls(int port);
721 int add_in_calls(int port);
725 static int update_pipeline_config(struct misdn_bchannel *bc);
727 static int update_ec_config(struct misdn_bchannel *bc);
732 /*************** Helpers *****************/
734 static int misdn_chan_is_valid(struct chan_list *ch)
736 struct chan_list *list;
738 ast_mutex_lock(&cl_te_lock);
739 for (list = cl_te; list; list = list->next) {
741 ast_mutex_unlock(&cl_te_lock);
745 ast_mutex_unlock(&cl_te_lock);
750 /*! Returns a reference to the found chan_list. */
751 static struct chan_list *get_chan_by_ast(struct ast_channel *ast)
753 struct chan_list *tmp;
755 ast_mutex_lock(&cl_te_lock);
756 for (tmp = cl_te; tmp; tmp = tmp->next) {
757 if (tmp->ast == ast) {
758 chan_list_ref(tmp, "Found chan_list by ast");
759 ast_mutex_unlock(&cl_te_lock);
763 ast_mutex_unlock(&cl_te_lock);
768 /*! Returns a reference to the found chan_list. */
769 static struct chan_list *get_chan_by_ast_name(const char *name)
771 struct chan_list *tmp;
773 ast_mutex_lock(&cl_te_lock);
774 for (tmp = cl_te; tmp; tmp = tmp->next) {
775 if (tmp->ast && strcmp(ast_channel_name(tmp->ast), name) == 0) {
776 chan_list_ref(tmp, "Found chan_list by ast name");
777 ast_mutex_unlock(&cl_te_lock);
781 ast_mutex_unlock(&cl_te_lock);
786 #if defined(AST_MISDN_ENHANCEMENTS)
789 * \brief Destroy the misdn_cc_ds_info datastore payload
791 * \param[in] data the datastore payload, a reference to an misdn_cc_caller
794 * Since the payload is a reference to an astobj2 object, we just decrement its
795 * reference count. Before doing so, we NULL out the channel pointer inside of
796 * the misdn_cc_caller instance. This function will be called in one of two
797 * cases. In both cases, we no longer need the channel pointer:
799 * - The original channel that initialized call completion services, the same
800 * channel that is stored here, has been destroyed early. This could happen
801 * if it transferred the mISDN channel, for example.
803 * - The mISDN channel that had this datastore inherited on to it is now being
804 * destroyed. If this is the case, then the call completion events have
805 * already occurred and the appropriate channel variables have already been
806 * set on the original channel that requested call completion services.
810 static void misdn_cc_ds_destroy(void *data)
812 struct misdn_cc_caller *cc_caller = data;
815 cc_caller->chan = NULL;
816 ao2_unlock(cc_caller);
818 ao2_ref(cc_caller, -1);
820 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
822 #if defined(AST_MISDN_ENHANCEMENTS)
825 * \brief Duplicate the misdn_cc_ds_info datastore payload
827 * \param[in] data the datastore payload, a reference to an misdn_cc_caller
830 * All we need to do is bump the reference count and return the same instance.
832 * \return A reference to an instance of a misdn_cc_caller
834 static void *misdn_cc_ds_duplicate(void *data)
836 struct misdn_cc_caller *cc_caller = data;
838 ao2_ref(cc_caller, +1);
842 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
844 #if defined(AST_MISDN_ENHANCEMENTS)
845 static const struct ast_datastore_info misdn_cc_ds_info = {
847 .destroy = misdn_cc_ds_destroy,
848 .duplicate = misdn_cc_ds_duplicate,
850 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
852 #if defined(AST_MISDN_ENHANCEMENTS)
855 * \brief Set a channel var on the peer channel for call completion services
857 * \param[in] peer The peer that initialized call completion services
858 * \param[in] var The variable name to set
859 * \param[in] value The variable value to set
861 * This function may be called from outside of the channel thread. It handles
862 * the fact that the peer channel may be hung up and destroyed at any time.
866 static void misdn_cc_set_peer_var(struct misdn_cc_caller *peer, const char *var,
871 /*! \todo XXX This nastiness can go away once ast_channel is ref counted! */
872 while (peer->chan && ast_channel_trylock(peer->chan)) {
879 pbx_builtin_setvar_helper(peer->chan, var, value);
880 ast_channel_unlock(peer->chan);
885 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
887 #if defined(AST_MISDN_ENHANCEMENTS)
890 * \brief Get a reference to the CC caller if it exists
892 static struct misdn_cc_caller *misdn_cc_caller_get(struct ast_channel *chan)
894 struct ast_datastore *datastore;
895 struct misdn_cc_caller *cc_caller;
897 ast_channel_lock(chan);
899 if (!(datastore = ast_channel_datastore_find(chan, &misdn_cc_ds_info, NULL))) {
900 ast_channel_unlock(chan);
904 ao2_ref(datastore->data, +1);
905 cc_caller = datastore->data;
907 ast_channel_unlock(chan);
911 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
913 #if defined(AST_MISDN_ENHANCEMENTS)
916 * \brief Find the call completion record given the record id.
920 * \retval pointer to found call completion record
921 * \retval NULL if not found
923 * \note Assumes the misdn_cc_records_db lock is already obtained.
925 static struct misdn_cc_record *misdn_cc_find_by_id(long record_id)
927 struct misdn_cc_record *current;
929 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
930 if (current->record_id == record_id) {
931 /* Found the record */
938 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
940 #if defined(AST_MISDN_ENHANCEMENTS)
943 * \brief Find the call completion record given the port and call linkage id.
945 * \param port Logical port number
946 * \param linkage_id Call linkage ID number from switch.
948 * \retval pointer to found call completion record
949 * \retval NULL if not found
951 * \note Assumes the misdn_cc_records_db lock is already obtained.
953 static struct misdn_cc_record *misdn_cc_find_by_linkage(int port, int linkage_id)
955 struct misdn_cc_record *current;
957 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
958 if (current->port == port
960 && current->mode.ptmp.linkage_id == linkage_id) {
961 /* Found the record */
968 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
970 #if defined(AST_MISDN_ENHANCEMENTS)
973 * \brief Find the call completion record given the port and outstanding invocation id.
975 * \param port Logical port number
976 * \param invoke_id Outstanding message invocation ID number.
978 * \retval pointer to found call completion record
979 * \retval NULL if not found
981 * \note Assumes the misdn_cc_records_db lock is already obtained.
983 static struct misdn_cc_record *misdn_cc_find_by_invoke(int port, int invoke_id)
985 struct misdn_cc_record *current;
987 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
988 if (current->outstanding_message
989 && current->invoke_id == invoke_id
990 && current->port == port) {
991 /* Found the record */
998 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1000 #if defined(AST_MISDN_ENHANCEMENTS)
1003 * \brief Find the call completion record given the port and CCBS reference id.
1005 * \param port Logical port number
1006 * \param reference_id CCBS reference ID number from switch.
1008 * \retval pointer to found call completion record
1009 * \retval NULL if not found
1011 * \note Assumes the misdn_cc_records_db lock is already obtained.
1013 static struct misdn_cc_record *misdn_cc_find_by_reference(int port, int reference_id)
1015 struct misdn_cc_record *current;
1017 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
1018 if (current->activated
1019 && current->port == port
1021 && current->mode.ptmp.reference_id == reference_id) {
1022 /* Found the record */
1029 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1031 #if defined(AST_MISDN_ENHANCEMENTS)
1034 * \brief Find the call completion record given the B channel pointer
1036 * \param bc B channel control structure pointer.
1038 * \retval pointer to found call completion record
1039 * \retval NULL if not found
1041 * \note Assumes the misdn_cc_records_db lock is already obtained.
1043 static struct misdn_cc_record *misdn_cc_find_by_bc(const struct misdn_bchannel *bc)
1045 struct misdn_cc_record *current;
1048 AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
1050 && current->mode.ptp.bc == bc) {
1051 /* Found the record */
1061 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1063 #if defined(AST_MISDN_ENHANCEMENTS)
1066 * \brief Delete the given call completion record
1068 * \param doomed Call completion record to destroy
1072 * \note Assumes the misdn_cc_records_db lock is already obtained.
1074 static void misdn_cc_delete(struct misdn_cc_record *doomed)
1076 struct misdn_cc_record *current;
1078 AST_LIST_TRAVERSE_SAFE_BEGIN(&misdn_cc_records_db, current, list) {
1079 if (current == doomed) {
1080 AST_LIST_REMOVE_CURRENT(list);
1085 AST_LIST_TRAVERSE_SAFE_END;
1087 /* The doomed node is not in the call completion database */
1089 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1091 #if defined(AST_MISDN_ENHANCEMENTS)
1094 * \brief Delete all old call completion records
1098 * \note Assumes the misdn_cc_records_db lock is already obtained.
1100 static void misdn_cc_remove_old(void)
1102 struct misdn_cc_record *current;
1106 AST_LIST_TRAVERSE_SAFE_BEGIN(&misdn_cc_records_db, current, list) {
1107 if (MISDN_CC_RECORD_AGE_MAX < now - current->time_created) {
1108 if (current->ptp && current->mode.ptp.bc) {
1109 /* Close the old call-completion signaling link */
1110 current->mode.ptp.bc->fac_out.Function = Fac_None;
1111 current->mode.ptp.bc->out_cause = AST_CAUSE_NORMAL_CLEARING;
1112 misdn_lib_send_event(current->mode.ptp.bc, EVENT_RELEASE_COMPLETE);
1115 /* Remove the old call completion record */
1116 AST_LIST_REMOVE_CURRENT(list);
1120 AST_LIST_TRAVERSE_SAFE_END;
1122 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1124 #if defined(AST_MISDN_ENHANCEMENTS)
1127 * \brief Allocate the next record id.
1129 * \retval New record id on success.
1130 * \retval -1 on error.
1132 * \note Assumes the misdn_cc_records_db lock is already obtained.
1134 static long misdn_cc_record_id_new(void)
1139 record_id = ++misdn_cc_record_id;
1140 first_id = record_id;
1141 while (misdn_cc_find_by_id(record_id)) {
1142 record_id = ++misdn_cc_record_id;
1143 if (record_id == first_id) {
1145 * We have a resource leak.
1146 * We should never need to allocate 64k records.
1148 chan_misdn_log(0, 0, " --> ERROR Too many call completion records!\n");
1156 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1158 #if defined(AST_MISDN_ENHANCEMENTS)
1161 * \brief Create a new call completion record
1163 * \retval pointer to new call completion record
1164 * \retval NULL if failed
1166 * \note Assumes the misdn_cc_records_db lock is already obtained.
1168 static struct misdn_cc_record *misdn_cc_new(void)
1170 struct misdn_cc_record *cc_record;
1173 misdn_cc_remove_old();
1175 cc_record = ast_calloc(1, sizeof(*cc_record));
1177 record_id = misdn_cc_record_id_new();
1178 if (record_id < 0) {
1179 ast_free(cc_record);
1183 /* Initialize the new record */
1184 cc_record->record_id = record_id;
1185 cc_record->port = -1;/* Invalid port so it will never be found this way */
1186 cc_record->invoke_id = ++misdn_invoke_id;
1187 cc_record->party_a_free = 1;/* Default User-A as free */
1188 cc_record->error_code = FacError_None;
1189 cc_record->reject_code = FacReject_None;
1190 cc_record->time_created = time(NULL);
1192 /* Insert the new record into the database */
1193 AST_LIST_INSERT_HEAD(&misdn_cc_records_db, cc_record, list);
1197 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1199 #if defined(AST_MISDN_ENHANCEMENTS)
1202 * \brief Destroy the call completion record database
1206 static void misdn_cc_destroy(void)
1208 struct misdn_cc_record *current;
1210 while ((current = AST_LIST_REMOVE_HEAD(&misdn_cc_records_db, list))) {
1211 /* Do a misdn_cc_delete(current) inline */
1215 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1217 #if defined(AST_MISDN_ENHANCEMENTS)
1220 * \brief Initialize the call completion record database
1224 static void misdn_cc_init(void)
1226 misdn_cc_record_id = 0;
1228 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1230 #if defined(AST_MISDN_ENHANCEMENTS)
1233 * \brief Check the status of an outstanding invocation request.
1235 * \param data Points to an integer containing the call completion record id.
1237 * \retval 0 if got a response.
1238 * \retval -1 if no response yet.
1240 static int misdn_cc_response_check(void *data)
1243 struct misdn_cc_record *cc_record;
1245 AST_LIST_LOCK(&misdn_cc_records_db);
1246 cc_record = misdn_cc_find_by_id(*(long *) data);
1248 if (cc_record->outstanding_message) {
1254 /* No record so there is no response to check. */
1257 AST_LIST_UNLOCK(&misdn_cc_records_db);
1259 return not_responded;
1261 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1263 #if defined(AST_MISDN_ENHANCEMENTS)
1266 * \brief Wait for a response from the switch for an outstanding
1267 * invocation request.
1269 * \param chan Asterisk channel to operate upon.
1270 * \param wait_seconds Number of seconds to wait
1271 * \param record_id Call completion record ID.
1275 static void misdn_cc_response_wait(struct ast_channel *chan, int wait_seconds, long record_id)
1279 for (count = 2 * MISDN_CC_REQUEST_WAIT_MAX; count--;) {
1280 /* Sleep in 500 ms increments */
1281 if (ast_safe_sleep_conditional(chan, 500, misdn_cc_response_check, &record_id) != 0) {
1282 /* We got hung up or our response came in. */
1287 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1289 #if defined(AST_MISDN_ENHANCEMENTS)
1292 * \brief Convert the mISDN reject code to a string
1294 * \param code mISDN reject code.
1296 * \return The mISDN reject code as a string
1298 static const char *misdn_to_str_reject_code(enum FacRejectCode code)
1300 static const struct {
1301 enum FacRejectCode code;
1305 { FacReject_None, "No reject occurred" },
1306 { FacReject_Unknown, "Unknown reject code" },
1308 { FacReject_Gen_UnrecognizedComponent, "General: Unrecognized Component" },
1309 { FacReject_Gen_MistypedComponent, "General: Mistyped Component" },
1310 { FacReject_Gen_BadlyStructuredComponent, "General: Badly Structured Component" },
1312 { FacReject_Inv_DuplicateInvocation, "Invoke: Duplicate Invocation" },
1313 { FacReject_Inv_UnrecognizedOperation, "Invoke: Unrecognized Operation" },
1314 { FacReject_Inv_MistypedArgument, "Invoke: Mistyped Argument" },
1315 { FacReject_Inv_ResourceLimitation, "Invoke: Resource Limitation" },
1316 { FacReject_Inv_InitiatorReleasing, "Invoke: Initiator Releasing" },
1317 { FacReject_Inv_UnrecognizedLinkedID, "Invoke: Unrecognized Linked ID" },
1318 { FacReject_Inv_LinkedResponseUnexpected, "Invoke: Linked Response Unexpected" },
1319 { FacReject_Inv_UnexpectedChildOperation, "Invoke: Unexpected Child Operation" },
1321 { FacReject_Res_UnrecognizedInvocation, "Result: Unrecognized Invocation" },
1322 { FacReject_Res_ResultResponseUnexpected, "Result: Result Response Unexpected" },
1323 { FacReject_Res_MistypedResult, "Result: Mistyped Result" },
1325 { FacReject_Err_UnrecognizedInvocation, "Error: Unrecognized Invocation" },
1326 { FacReject_Err_ErrorResponseUnexpected, "Error: Error Response Unexpected" },
1327 { FacReject_Err_UnrecognizedError, "Error: Unrecognized Error" },
1328 { FacReject_Err_UnexpectedError, "Error: Unexpected Error" },
1329 { FacReject_Err_MistypedParameter, "Error: Mistyped Parameter" },
1335 for (index = 0; index < ARRAY_LEN(arr); ++index) {
1336 if (arr[index].code == code) {
1337 return arr[index].name;
1343 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1345 #if defined(AST_MISDN_ENHANCEMENTS)
1348 * \brief Convert the mISDN error code to a string
1350 * \param code mISDN error code.
1352 * \return The mISDN error code as a string
1354 static const char *misdn_to_str_error_code(enum FacErrorCode code)
1356 static const struct {
1357 enum FacErrorCode code;
1361 { FacError_None, "No error occurred" },
1362 { FacError_Unknown, "Unknown OID error code" },
1364 { FacError_Gen_NotSubscribed, "General: Not Subscribed" },
1365 { FacError_Gen_NotAvailable, "General: Not Available" },
1366 { FacError_Gen_NotImplemented, "General: Not Implemented" },
1367 { FacError_Gen_InvalidServedUserNr, "General: Invalid Served User Number" },
1368 { FacError_Gen_InvalidCallState, "General: Invalid Call State" },
1369 { FacError_Gen_BasicServiceNotProvided, "General: Basic Service Not Provided" },
1370 { FacError_Gen_NotIncomingCall, "General: Not Incoming Call" },
1371 { FacError_Gen_SupplementaryServiceInteractionNotAllowed,"General: Supplementary Service Interaction Not Allowed" },
1372 { FacError_Gen_ResourceUnavailable, "General: Resource Unavailable" },
1374 { FacError_Div_InvalidDivertedToNr, "Diversion: Invalid Diverted To Number" },
1375 { FacError_Div_SpecialServiceNr, "Diversion: Special Service Number" },
1376 { FacError_Div_DiversionToServedUserNr, "Diversion: Diversion To Served User Number" },
1377 { FacError_Div_IncomingCallAccepted, "Diversion: Incoming Call Accepted" },
1378 { FacError_Div_NumberOfDiversionsExceeded, "Diversion: Number Of Diversions Exceeded" },
1379 { FacError_Div_NotActivated, "Diversion: Not Activated" },
1380 { FacError_Div_RequestAlreadyAccepted, "Diversion: Request Already Accepted" },
1382 { FacError_AOC_NoChargingInfoAvailable, "AOC: No Charging Info Available" },
1384 { FacError_CCBS_InvalidCallLinkageID, "CCBS: Invalid Call Linkage ID" },
1385 { FacError_CCBS_InvalidCCBSReference, "CCBS: Invalid CCBS Reference" },
1386 { FacError_CCBS_LongTermDenial, "CCBS: Long Term Denial" },
1387 { FacError_CCBS_ShortTermDenial, "CCBS: Short Term Denial" },
1388 { FacError_CCBS_IsAlreadyActivated, "CCBS: Is Already Activated" },
1389 { FacError_CCBS_AlreadyAccepted, "CCBS: Already Accepted" },
1390 { FacError_CCBS_OutgoingCCBSQueueFull, "CCBS: Outgoing CCBS Queue Full" },
1391 { FacError_CCBS_CallFailureReasonNotBusy, "CCBS: Call Failure Reason Not Busy" },
1392 { FacError_CCBS_NotReadyForCall, "CCBS: Not Ready For Call" },
1394 { FacError_CCBS_T_LongTermDenial, "CCBS-T: Long Term Denial" },
1395 { FacError_CCBS_T_ShortTermDenial, "CCBS-T: Short Term Denial" },
1397 { FacError_ECT_LinkIdNotAssignedByNetwork, "ECT: Link ID Not Assigned By Network" },
1403 for (index = 0; index < ARRAY_LEN(arr); ++index) {
1404 if (arr[index].code == code) {
1405 return arr[index].name;
1411 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1413 #if defined(AST_MISDN_ENHANCEMENTS)
1416 * \brief Convert mISDN redirecting reason to diversion reason.
1418 * \param reason mISDN redirecting reason code.
1420 * \return Supported diversion reason code.
1422 static unsigned misdn_to_diversion_reason(enum mISDN_REDIRECTING_REASON reason)
1424 unsigned diversion_reason;
1427 case mISDN_REDIRECTING_REASON_CALL_FWD:
1428 diversion_reason = 1;/* cfu */
1430 case mISDN_REDIRECTING_REASON_CALL_FWD_BUSY:
1431 diversion_reason = 2;/* cfb */
1433 case mISDN_REDIRECTING_REASON_NO_REPLY:
1434 diversion_reason = 3;/* cfnr */
1437 diversion_reason = 0;/* unknown */
1441 return diversion_reason;
1443 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1445 #if defined(AST_MISDN_ENHANCEMENTS)
1448 * \brief Convert diversion reason to mISDN redirecting reason
1450 * \param diversion_reason Diversion reason to convert
1452 * \return Supported redirecting reason code.
1454 static enum mISDN_REDIRECTING_REASON diversion_reason_to_misdn(unsigned diversion_reason)
1456 enum mISDN_REDIRECTING_REASON reason;
1458 switch (diversion_reason) {
1460 reason = mISDN_REDIRECTING_REASON_CALL_FWD;
1463 reason = mISDN_REDIRECTING_REASON_CALL_FWD_BUSY;
1466 reason = mISDN_REDIRECTING_REASON_NO_REPLY;
1469 reason = mISDN_REDIRECTING_REASON_UNKNOWN;
1475 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1477 #if defined(AST_MISDN_ENHANCEMENTS)
1480 * \brief Convert the mISDN presentation to PresentedNumberUnscreened type
1482 * \param presentation mISDN presentation to convert
1483 * \param number_present TRUE if the number is present
1485 * \return PresentedNumberUnscreened type
1487 static unsigned misdn_to_PresentedNumberUnscreened_type(int presentation, int number_present)
1491 switch (presentation) {
1492 case 0:/* allowed */
1493 if (number_present) {
1494 type = 0;/* presentationAllowedNumber */
1496 type = 2;/* numberNotAvailableDueToInterworking */
1499 case 1:/* restricted */
1500 if (number_present) {
1501 type = 3;/* presentationRestrictedNumber */
1503 type = 1;/* presentationRestricted */
1507 type = 2;/* numberNotAvailableDueToInterworking */
1513 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1515 #if defined(AST_MISDN_ENHANCEMENTS)
1518 * \brief Convert the PresentedNumberUnscreened type to mISDN presentation
1520 * \param type PresentedNumberUnscreened type
1522 * \return mISDN presentation
1524 static int PresentedNumberUnscreened_to_misdn_pres(unsigned type)
1530 case 0:/* presentationAllowedNumber */
1531 presentation = 0;/* allowed */
1534 case 1:/* presentationRestricted */
1535 case 3:/* presentationRestrictedNumber */
1536 presentation = 1;/* restricted */
1539 case 2:/* numberNotAvailableDueToInterworking */
1540 presentation = 2;/* unavailable */
1544 return presentation;
1546 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1548 #if defined(AST_MISDN_ENHANCEMENTS)
1551 * \brief Convert the mISDN numbering plan to PartyNumber numbering plan
1553 * \param number_plan mISDN numbering plan
1555 * \return PartyNumber numbering plan
1557 static unsigned misdn_to_PartyNumber_plan(enum mISDN_NUMBER_PLAN number_plan)
1559 unsigned party_plan;
1561 switch (number_plan) {
1563 case NUMPLAN_UNKNOWN:
1564 party_plan = 0;/* unknown */
1568 party_plan = 1;/* public */
1572 party_plan = 3;/* data */
1576 party_plan = 4;/* telex */
1579 case NUMPLAN_NATIONAL:
1580 party_plan = 8;/* nationalStandard */
1583 case NUMPLAN_PRIVATE:
1584 party_plan = 5;/* private */
1590 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1592 #if defined(AST_MISDN_ENHANCEMENTS)
1595 * \brief Convert PartyNumber numbering plan to mISDN numbering plan
1597 * \param party_plan PartyNumber numbering plan
1599 * \return mISDN numbering plan
1601 static enum mISDN_NUMBER_PLAN PartyNumber_to_misdn_plan(unsigned party_plan)
1603 enum mISDN_NUMBER_PLAN number_plan;
1605 switch (party_plan) {
1607 case 0:/* unknown */
1608 number_plan = NUMPLAN_UNKNOWN;
1611 number_plan = NUMPLAN_ISDN;
1614 number_plan = NUMPLAN_DATA;
1617 number_plan = NUMPLAN_TELEX;
1619 case 8:/* nationalStandard */
1620 number_plan = NUMPLAN_NATIONAL;
1622 case 5:/* private */
1623 number_plan = NUMPLAN_PRIVATE;
1629 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1631 #if defined(AST_MISDN_ENHANCEMENTS)
1634 * \brief Convert mISDN type-of-number to PartyNumber public type-of-number
1636 * \param ton mISDN type-of-number
1638 * \return PartyNumber public type-of-number
1640 static unsigned misdn_to_PartyNumber_ton_public(enum mISDN_NUMBER_TYPE ton)
1646 case NUMTYPE_UNKNOWN:
1647 party_ton = 0;/* unknown */
1650 case NUMTYPE_INTERNATIONAL:
1651 party_ton = 1;/* internationalNumber */
1654 case NUMTYPE_NATIONAL:
1655 party_ton = 2;/* nationalNumber */
1658 case NUMTYPE_NETWORK_SPECIFIC:
1659 party_ton = 3;/* networkSpecificNumber */
1662 case NUMTYPE_SUBSCRIBER:
1663 party_ton = 4;/* subscriberNumber */
1666 case NUMTYPE_ABBREVIATED:
1667 party_ton = 6;/* abbreviatedNumber */
1673 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1675 #if defined(AST_MISDN_ENHANCEMENTS)
1678 * \brief Convert the PartyNumber public type-of-number to mISDN type-of-number
1680 * \param party_ton PartyNumber public type-of-number
1682 * \return mISDN type-of-number
1684 static enum mISDN_NUMBER_TYPE PartyNumber_to_misdn_ton_public(unsigned party_ton)
1686 enum mISDN_NUMBER_TYPE ton;
1688 switch (party_ton) {
1690 case 0:/* unknown */
1691 ton = NUMTYPE_UNKNOWN;
1694 case 1:/* internationalNumber */
1695 ton = NUMTYPE_INTERNATIONAL;
1698 case 2:/* nationalNumber */
1699 ton = NUMTYPE_NATIONAL;
1702 case 3:/* networkSpecificNumber */
1703 ton = NUMTYPE_NETWORK_SPECIFIC;
1706 case 4:/* subscriberNumber */
1707 ton = NUMTYPE_SUBSCRIBER;
1710 case 6:/* abbreviatedNumber */
1711 ton = NUMTYPE_ABBREVIATED;
1717 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1719 #if defined(AST_MISDN_ENHANCEMENTS)
1722 * \brief Convert mISDN type-of-number to PartyNumber private type-of-number
1724 * \param ton mISDN type-of-number
1726 * \return PartyNumber private type-of-number
1728 static unsigned misdn_to_PartyNumber_ton_private(enum mISDN_NUMBER_TYPE ton)
1734 case NUMTYPE_UNKNOWN:
1735 party_ton = 0;/* unknown */
1738 case NUMTYPE_INTERNATIONAL:
1739 party_ton = 1;/* level2RegionalNumber */
1742 case NUMTYPE_NATIONAL:
1743 party_ton = 2;/* level1RegionalNumber */
1746 case NUMTYPE_NETWORK_SPECIFIC:
1747 party_ton = 3;/* pTNSpecificNumber */
1750 case NUMTYPE_SUBSCRIBER:
1751 party_ton = 4;/* localNumber */
1754 case NUMTYPE_ABBREVIATED:
1755 party_ton = 6;/* abbreviatedNumber */
1761 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1763 #if defined(AST_MISDN_ENHANCEMENTS)
1766 * \brief Convert the PartyNumber private type-of-number to mISDN type-of-number
1768 * \param party_ton PartyNumber private type-of-number
1770 * \return mISDN type-of-number
1772 static enum mISDN_NUMBER_TYPE PartyNumber_to_misdn_ton_private(unsigned party_ton)
1774 enum mISDN_NUMBER_TYPE ton;
1776 switch (party_ton) {
1778 case 0:/* unknown */
1779 ton = NUMTYPE_UNKNOWN;
1782 case 1:/* level2RegionalNumber */
1783 ton = NUMTYPE_INTERNATIONAL;
1786 case 2:/* level1RegionalNumber */
1787 ton = NUMTYPE_NATIONAL;
1790 case 3:/* pTNSpecificNumber */
1791 ton = NUMTYPE_NETWORK_SPECIFIC;
1794 case 4:/* localNumber */
1795 ton = NUMTYPE_SUBSCRIBER;
1798 case 6:/* abbreviatedNumber */
1799 ton = NUMTYPE_ABBREVIATED;
1805 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1809 * \brief Convert the mISDN type of number code to a string
1811 * \param number_type mISDN type of number code.
1813 * \return The mISDN type of number code as a string
1815 static const char *misdn_to_str_ton(enum mISDN_NUMBER_TYPE number_type)
1819 switch (number_type) {
1821 case NUMTYPE_UNKNOWN:
1825 case NUMTYPE_INTERNATIONAL:
1826 str = "International";
1829 case NUMTYPE_NATIONAL:
1833 case NUMTYPE_NETWORK_SPECIFIC:
1834 str = "Network Specific";
1837 case NUMTYPE_SUBSCRIBER:
1841 case NUMTYPE_ABBREVIATED:
1842 str = "Abbreviated";
1851 * \brief Convert the mISDN type of number code to Asterisk type of number code
1853 * \param number_type mISDN type of number code.
1855 * \return Asterisk type of number code
1857 static int misdn_to_ast_ton(enum mISDN_NUMBER_TYPE number_type)
1859 int ast_number_type;
1861 switch (number_type) {
1863 case NUMTYPE_UNKNOWN:
1864 ast_number_type = NUMTYPE_UNKNOWN << 4;
1867 case NUMTYPE_INTERNATIONAL:
1868 ast_number_type = NUMTYPE_INTERNATIONAL << 4;
1871 case NUMTYPE_NATIONAL:
1872 ast_number_type = NUMTYPE_NATIONAL << 4;
1875 case NUMTYPE_NETWORK_SPECIFIC:
1876 ast_number_type = NUMTYPE_NETWORK_SPECIFIC << 4;
1879 case NUMTYPE_SUBSCRIBER:
1880 ast_number_type = NUMTYPE_SUBSCRIBER << 4;
1883 case NUMTYPE_ABBREVIATED:
1884 ast_number_type = NUMTYPE_ABBREVIATED << 4;
1888 return ast_number_type;
1893 * \brief Convert the Asterisk type of number code to mISDN type of number code
1895 * \param ast_number_type Asterisk type of number code.
1897 * \return mISDN type of number code
1899 static enum mISDN_NUMBER_TYPE ast_to_misdn_ton(unsigned ast_number_type)
1901 enum mISDN_NUMBER_TYPE number_type;
1903 switch ((ast_number_type >> 4) & 0x07) {
1905 case NUMTYPE_UNKNOWN:
1906 number_type = NUMTYPE_UNKNOWN;
1909 case NUMTYPE_INTERNATIONAL:
1910 number_type = NUMTYPE_INTERNATIONAL;
1913 case NUMTYPE_NATIONAL:
1914 number_type = NUMTYPE_NATIONAL;
1917 case NUMTYPE_NETWORK_SPECIFIC:
1918 number_type = NUMTYPE_NETWORK_SPECIFIC;
1921 case NUMTYPE_SUBSCRIBER:
1922 number_type = NUMTYPE_SUBSCRIBER;
1925 case NUMTYPE_ABBREVIATED:
1926 number_type = NUMTYPE_ABBREVIATED;
1935 * \brief Convert the mISDN numbering plan code to a string
1937 * \param number_plan mISDN numbering plan code.
1939 * \return The mISDN numbering plan code as a string
1941 static const char *misdn_to_str_plan(enum mISDN_NUMBER_PLAN number_plan)
1945 switch (number_plan) {
1947 case NUMPLAN_UNKNOWN:
1963 case NUMPLAN_NATIONAL:
1967 case NUMPLAN_PRIVATE:
1977 * \brief Convert the mISDN numbering plan code to Asterisk numbering plan code
1979 * \param number_plan mISDN numbering plan code.
1981 * \return Asterisk numbering plan code
1983 static int misdn_to_ast_plan(enum mISDN_NUMBER_PLAN number_plan)
1985 int ast_number_plan;
1987 switch (number_plan) {
1989 case NUMPLAN_UNKNOWN:
1990 ast_number_plan = NUMPLAN_UNKNOWN;
1994 ast_number_plan = NUMPLAN_ISDN;
1998 ast_number_plan = NUMPLAN_DATA;
2002 ast_number_plan = NUMPLAN_TELEX;
2005 case NUMPLAN_NATIONAL:
2006 ast_number_plan = NUMPLAN_NATIONAL;
2009 case NUMPLAN_PRIVATE:
2010 ast_number_plan = NUMPLAN_PRIVATE;
2014 return ast_number_plan;
2019 * \brief Convert the Asterisk numbering plan code to mISDN numbering plan code
2021 * \param ast_number_plan Asterisk numbering plan code.
2023 * \return mISDN numbering plan code
2025 static enum mISDN_NUMBER_PLAN ast_to_misdn_plan(unsigned ast_number_plan)
2027 enum mISDN_NUMBER_PLAN number_plan;
2029 switch (ast_number_plan & 0x0F) {
2031 case NUMPLAN_UNKNOWN:
2032 number_plan = NUMPLAN_UNKNOWN;
2036 number_plan = NUMPLAN_ISDN;
2040 number_plan = NUMPLAN_DATA;
2044 number_plan = NUMPLAN_TELEX;
2047 case NUMPLAN_NATIONAL:
2048 number_plan = NUMPLAN_NATIONAL;
2051 case NUMPLAN_PRIVATE:
2052 number_plan = NUMPLAN_PRIVATE;
2061 * \brief Convert the mISDN presentation code to a string
2063 * \param presentation mISDN number presentation restriction code.
2065 * \return The mISDN presentation code as a string
2067 static const char *misdn_to_str_pres(int presentation)
2071 switch (presentation) {
2081 str = "Unavailable";
2094 * \brief Convert the mISDN presentation code to Asterisk presentation code
2096 * \param presentation mISDN number presentation restriction code.
2098 * \return Asterisk presentation code
2100 static int misdn_to_ast_pres(int presentation)
2102 switch (presentation) {
2105 presentation = AST_PRES_ALLOWED;
2109 presentation = AST_PRES_RESTRICTED;
2113 presentation = AST_PRES_UNAVAILABLE;
2117 return presentation;
2122 * \brief Convert the Asterisk presentation code to mISDN presentation code
2124 * \param presentation Asterisk number presentation restriction code.
2126 * \return mISDN presentation code
2128 static int ast_to_misdn_pres(int presentation)
2130 switch (presentation & AST_PRES_RESTRICTION) {
2132 case AST_PRES_ALLOWED:
2136 case AST_PRES_RESTRICTED:
2140 case AST_PRES_UNAVAILABLE:
2145 return presentation;
2150 * \brief Convert the mISDN screening code to a string
2152 * \param screening mISDN number screening code.
2154 * \return The mISDN screening code as a string
2156 static const char *misdn_to_str_screen(int screening)
2160 switch (screening) {
2166 str = "Passed Screen";
2170 str = "Failed Screen";
2174 str = "Network Number";
2187 * \brief Convert the mISDN screening code to Asterisk screening code
2189 * \param screening mISDN number screening code.
2191 * \return Asterisk screening code
2193 static int misdn_to_ast_screen(int screening)
2195 switch (screening) {
2198 screening = AST_PRES_USER_NUMBER_UNSCREENED;
2202 screening = AST_PRES_USER_NUMBER_PASSED_SCREEN;
2206 screening = AST_PRES_USER_NUMBER_FAILED_SCREEN;
2210 screening = AST_PRES_NETWORK_NUMBER;
2219 * \brief Convert the Asterisk screening code to mISDN screening code
2221 * \param screening Asterisk number screening code.
2223 * \return mISDN screening code
2225 static int ast_to_misdn_screen(int screening)
2227 switch (screening & AST_PRES_NUMBER_TYPE) {
2229 case AST_PRES_USER_NUMBER_UNSCREENED:
2233 case AST_PRES_USER_NUMBER_PASSED_SCREEN:
2237 case AST_PRES_USER_NUMBER_FAILED_SCREEN:
2241 case AST_PRES_NETWORK_NUMBER:
2251 * \brief Convert Asterisk redirecting reason to mISDN redirecting reason code.
2253 * \param ast Asterisk redirecting reason code.
2255 * \return mISDN reason code
2257 static enum mISDN_REDIRECTING_REASON ast_to_misdn_reason(const enum AST_REDIRECTING_REASON ast)
2261 static const struct misdn_reasons {
2262 enum AST_REDIRECTING_REASON ast;
2263 enum mISDN_REDIRECTING_REASON q931;
2264 } misdn_reason_table[] = {
2266 { AST_REDIRECTING_REASON_UNKNOWN, mISDN_REDIRECTING_REASON_UNKNOWN },
2267 { AST_REDIRECTING_REASON_USER_BUSY, mISDN_REDIRECTING_REASON_CALL_FWD_BUSY },
2268 { AST_REDIRECTING_REASON_NO_ANSWER, mISDN_REDIRECTING_REASON_NO_REPLY },
2269 { AST_REDIRECTING_REASON_UNAVAILABLE, mISDN_REDIRECTING_REASON_NO_REPLY },
2270 { AST_REDIRECTING_REASON_UNCONDITIONAL, mISDN_REDIRECTING_REASON_CALL_FWD },
2271 { AST_REDIRECTING_REASON_TIME_OF_DAY, mISDN_REDIRECTING_REASON_UNKNOWN },
2272 { AST_REDIRECTING_REASON_DO_NOT_DISTURB, mISDN_REDIRECTING_REASON_UNKNOWN },
2273 { AST_REDIRECTING_REASON_DEFLECTION, mISDN_REDIRECTING_REASON_DEFLECTION },
2274 { AST_REDIRECTING_REASON_FOLLOW_ME, mISDN_REDIRECTING_REASON_UNKNOWN },
2275 { AST_REDIRECTING_REASON_OUT_OF_ORDER, mISDN_REDIRECTING_REASON_OUT_OF_ORDER },
2276 { AST_REDIRECTING_REASON_AWAY, mISDN_REDIRECTING_REASON_UNKNOWN },
2277 { AST_REDIRECTING_REASON_CALL_FWD_DTE, mISDN_REDIRECTING_REASON_CALL_FWD_DTE }
2281 for (index = 0; index < ARRAY_LEN(misdn_reason_table); ++index) {
2282 if (misdn_reason_table[index].ast == ast) {
2283 return misdn_reason_table[index].q931;
2286 return mISDN_REDIRECTING_REASON_UNKNOWN;
2291 * \brief Convert the mISDN redirecting reason to Asterisk redirecting reason code
2293 * \param q931 mISDN redirecting reason code.
2295 * \return Asterisk redirecting reason code
2297 static enum AST_REDIRECTING_REASON misdn_to_ast_reason(const enum mISDN_REDIRECTING_REASON q931)
2299 enum AST_REDIRECTING_REASON ast;
2303 case mISDN_REDIRECTING_REASON_UNKNOWN:
2304 ast = AST_REDIRECTING_REASON_UNKNOWN;
2307 case mISDN_REDIRECTING_REASON_CALL_FWD_BUSY:
2308 ast = AST_REDIRECTING_REASON_USER_BUSY;
2311 case mISDN_REDIRECTING_REASON_NO_REPLY:
2312 ast = AST_REDIRECTING_REASON_NO_ANSWER;
2315 case mISDN_REDIRECTING_REASON_DEFLECTION:
2316 ast = AST_REDIRECTING_REASON_DEFLECTION;
2319 case mISDN_REDIRECTING_REASON_OUT_OF_ORDER:
2320 ast = AST_REDIRECTING_REASON_OUT_OF_ORDER;
2323 case mISDN_REDIRECTING_REASON_CALL_FWD_DTE:
2324 ast = AST_REDIRECTING_REASON_CALL_FWD_DTE;
2327 case mISDN_REDIRECTING_REASON_CALL_FWD:
2328 ast = AST_REDIRECTING_REASON_UNCONDITIONAL;
2337 struct allowed_bearers {
2338 char *name; /*!< Bearer capability name string used in /etc/misdn.conf allowed_bearers */
2339 char *display; /*!< Bearer capability displayable name */
2340 int cap; /*!< SETUP message bearer capability field code value */
2341 int deprecated; /*!< TRUE if this entry is deprecated. (Misspelled or bad name to use) */
2345 static const struct allowed_bearers allowed_bearers_array[] = {
2346 /* Name, Displayable Name Bearer Capability, Deprecated */
2347 { "speech", "Speech", INFO_CAPABILITY_SPEECH, 0 },
2348 { "3_1khz", "3.1KHz Audio", INFO_CAPABILITY_AUDIO_3_1K, 0 },
2349 { "digital_unrestricted", "Unrestricted Digital", INFO_CAPABILITY_DIGITAL_UNRESTRICTED, 0 },
2350 { "digital_restricted", "Restricted Digital", INFO_CAPABILITY_DIGITAL_RESTRICTED, 0 },
2351 { "digital_restriced", "Restricted Digital", INFO_CAPABILITY_DIGITAL_RESTRICTED, 1 }, /* Allow misspelling for backwards compatibility */
2352 { "video", "Video", INFO_CAPABILITY_VIDEO, 0 }
2356 static const char *bearer2str(int cap)
2360 for (index = 0; index < ARRAY_LEN(allowed_bearers_array); ++index) {
2361 if (allowed_bearers_array[index].cap == cap) {
2362 return allowed_bearers_array[index].display;
2366 return "Unknown Bearer";
2369 #if defined(AST_MISDN_ENHANCEMENTS)
2372 * \brief Fill in facility PartyNumber information
2374 * \param party PartyNumber structure to fill in.
2375 * \param id Information to put in PartyNumber structure.
2379 static void misdn_PartyNumber_fill(struct FacPartyNumber *party, const struct misdn_party_id *id)
2381 ast_copy_string((char *) party->Number, id->number, sizeof(party->Number));
2382 party->LengthOfNumber = strlen((char *) party->Number);
2383 party->Type = misdn_to_PartyNumber_plan(id->number_plan);
2384 switch (party->Type) {
2386 party->TypeOfNumber = misdn_to_PartyNumber_ton_public(id->number_type);
2388 case 5:/* private */
2389 party->TypeOfNumber = misdn_to_PartyNumber_ton_private(id->number_type);
2392 party->TypeOfNumber = 0;/* Don't care */
2396 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2398 #if defined(AST_MISDN_ENHANCEMENTS)
2401 * \brief Extract the information from PartyNumber
2403 * \param id Where to put extracted PartyNumber information
2404 * \param party PartyNumber information to extract
2408 static void misdn_PartyNumber_extract(struct misdn_party_id *id, const struct FacPartyNumber *party)
2410 if (party->LengthOfNumber) {
2411 ast_copy_string(id->number, (char *) party->Number, sizeof(id->number));
2412 id->number_plan = PartyNumber_to_misdn_plan(party->Type);
2413 switch (party->Type) {
2415 id->number_type = PartyNumber_to_misdn_ton_public(party->TypeOfNumber);
2417 case 5:/* private */
2418 id->number_type = PartyNumber_to_misdn_ton_private(party->TypeOfNumber);
2421 id->number_type = NUMTYPE_UNKNOWN;
2425 /* Number not present */
2426 id->number_type = NUMTYPE_UNKNOWN;
2427 id->number_plan = NUMPLAN_ISDN;
2431 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2433 #if defined(AST_MISDN_ENHANCEMENTS)
2436 * \brief Fill in facility Address information
2438 * \param Address Address structure to fill in.
2439 * \param id Information to put in Address structure.
2443 static void misdn_Address_fill(struct FacAddress *Address, const struct misdn_party_id *id)
2445 misdn_PartyNumber_fill(&Address->Party, id);
2447 /* Subaddresses are not supported yet */
2448 Address->Subaddress.Length = 0;
2450 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2452 #if defined(AST_MISDN_ENHANCEMENTS)
2455 * \brief Fill in facility PresentedNumberUnscreened information
2457 * \param presented PresentedNumberUnscreened structure to fill in.
2458 * \param id Information to put in PresentedNumberUnscreened structure.
2462 static void misdn_PresentedNumberUnscreened_fill(struct FacPresentedNumberUnscreened *presented, const struct misdn_party_id *id)
2464 presented->Type = misdn_to_PresentedNumberUnscreened_type(id->presentation, id->number[0] ? 1 : 0);
2465 misdn_PartyNumber_fill(&presented->Unscreened, id);
2467 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2469 #if defined(AST_MISDN_ENHANCEMENTS)
2472 * \brief Extract the information from PartyNumber
2474 * \param id Where to put extracted PresentedNumberUnscreened information
2475 * \param presented PresentedNumberUnscreened information to extract
2479 static void misdn_PresentedNumberUnscreened_extract(struct misdn_party_id *id, const struct FacPresentedNumberUnscreened *presented)
2481 id->presentation = PresentedNumberUnscreened_to_misdn_pres(presented->Type);
2482 id->screening = 0;/* unscreened */
2483 switch (presented->Type) {
2484 case 0:/* presentationAllowedNumber */
2485 case 3:/* presentationRestrictedNumber */
2486 misdn_PartyNumber_extract(id, &presented->Unscreened);
2488 case 1:/* presentationRestricted */
2489 case 2:/* numberNotAvailableDueToInterworking */
2491 /* Number not present (And uninitialized so do not even look at it!) */
2492 id->number_type = NUMTYPE_UNKNOWN;
2493 id->number_plan = NUMPLAN_ISDN;
2498 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2500 #if defined(AST_MISDN_ENHANCEMENTS)
2501 static const char Level_Spacing[] = " ";/* Work for up to 10 levels */
2502 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2504 #if defined(AST_MISDN_ENHANCEMENTS)
2505 static void print_facility_PartyNumber(unsigned Level, const struct FacPartyNumber *Party, const struct misdn_bchannel *bc)
2507 if (Party->LengthOfNumber) {
2508 const char *Spacing;
2510 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2511 chan_misdn_log(1, bc->port, " -->%s PartyNumber: Type:%d\n",
2512 Spacing, Party->Type);
2513 switch (Party->Type) {
2514 case 0: /* Unknown PartyNumber */
2515 chan_misdn_log(1, bc->port, " -->%s Unknown: %s\n",
2516 Spacing, Party->Number);
2518 case 1: /* Public PartyNumber */
2519 chan_misdn_log(1, bc->port, " -->%s Public TON:%d %s\n",
2520 Spacing, Party->TypeOfNumber, Party->Number);
2522 case 2: /* NSAP encoded PartyNumber */
2523 chan_misdn_log(1, bc->port, " -->%s NSAP: %s\n",
2524 Spacing, Party->Number);
2526 case 3: /* Data PartyNumber (Not used) */
2527 chan_misdn_log(1, bc->port, " -->%s Data: %s\n",
2528 Spacing, Party->Number);
2530 case 4: /* Telex PartyNumber (Not used) */
2531 chan_misdn_log(1, bc->port, " -->%s Telex: %s\n",
2532 Spacing, Party->Number);
2534 case 5: /* Private PartyNumber */
2535 chan_misdn_log(1, bc->port, " -->%s Private TON:%d %s\n",
2536 Spacing, Party->TypeOfNumber, Party->Number);
2538 case 8: /* National Standard PartyNumber (Not used) */
2539 chan_misdn_log(1, bc->port, " -->%s National: %s\n",
2540 Spacing, Party->Number);
2547 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2549 #if defined(AST_MISDN_ENHANCEMENTS)
2550 static void print_facility_Subaddress(unsigned Level, const struct FacPartySubaddress *Subaddress, const struct misdn_bchannel *bc)
2552 if (Subaddress->Length) {
2553 const char *Spacing;
2555 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2556 chan_misdn_log(1, bc->port, " -->%s Subaddress: Type:%d\n",
2557 Spacing, Subaddress->Type);
2558 switch (Subaddress->Type) {
2559 case 0: /* UserSpecified */
2560 if (Subaddress->u.UserSpecified.OddCountPresent) {
2561 chan_misdn_log(1, bc->port, " -->%s User BCD OddCount:%d NumOctets:%d\n",
2562 Spacing, Subaddress->u.UserSpecified.OddCount, Subaddress->Length);
2564 chan_misdn_log(1, bc->port, " -->%s User: %s\n",
2565 Spacing, Subaddress->u.UserSpecified.Information);
2569 chan_misdn_log(1, bc->port, " -->%s NSAP: %s\n",
2570 Spacing, Subaddress->u.Nsap);
2577 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2579 #if defined(AST_MISDN_ENHANCEMENTS)
2580 static void print_facility_Address(unsigned Level, const struct FacAddress *Address, const struct misdn_bchannel *bc)
2582 print_facility_PartyNumber(Level, &Address->Party, bc);
2583 print_facility_Subaddress(Level, &Address->Subaddress, bc);
2585 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2587 #if defined(AST_MISDN_ENHANCEMENTS)
2588 static void print_facility_PresentedNumberUnscreened(unsigned Level, const struct FacPresentedNumberUnscreened *Presented, const struct misdn_bchannel *bc)
2590 const char *Spacing;
2592 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2593 chan_misdn_log(1, bc->port, " -->%s Unscreened Type:%d\n", Spacing, Presented->Type);
2594 switch (Presented->Type) {
2595 case 0: /* presentationAllowedNumber */
2596 chan_misdn_log(1, bc->port, " -->%s Allowed:\n", Spacing);
2597 print_facility_PartyNumber(Level + 2, &Presented->Unscreened, bc);
2599 case 1: /* presentationRestricted */
2600 chan_misdn_log(1, bc->port, " -->%s Restricted\n", Spacing);
2602 case 2: /* numberNotAvailableDueToInterworking */
2603 chan_misdn_log(1, bc->port, " -->%s Not Available\n", Spacing);
2605 case 3: /* presentationRestrictedNumber */
2606 chan_misdn_log(1, bc->port, " -->%s Restricted:\n", Spacing);
2607 print_facility_PartyNumber(Level + 2, &Presented->Unscreened, bc);
2613 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2615 #if defined(AST_MISDN_ENHANCEMENTS)
2616 static void print_facility_AddressScreened(unsigned Level, const struct FacAddressScreened *Address, const struct misdn_bchannel *bc)
2618 const char *Spacing;
2620 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2621 chan_misdn_log(1, bc->port, " -->%s ScreeningIndicator:%d\n", Spacing, Address->ScreeningIndicator);
2622 print_facility_PartyNumber(Level, &Address->Party, bc);
2623 print_facility_Subaddress(Level, &Address->Subaddress, bc);
2625 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2627 #if defined(AST_MISDN_ENHANCEMENTS)
2628 static void print_facility_PresentedAddressScreened(unsigned Level, const struct FacPresentedAddressScreened *Presented, const struct misdn_bchannel *bc)
2630 const char *Spacing;
2632 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2633 chan_misdn_log(1, bc->port, " -->%s Screened Type:%d\n", Spacing, Presented->Type);
2634 switch (Presented->Type) {
2635 case 0: /* presentationAllowedAddress */
2636 chan_misdn_log(1, bc->port, " -->%s Allowed:\n", Spacing);
2637 print_facility_AddressScreened(Level + 2, &Presented->Address, bc);
2639 case 1: /* presentationRestricted */
2640 chan_misdn_log(1, bc->port, " -->%s Restricted\n", Spacing);
2642 case 2: /* numberNotAvailableDueToInterworking */
2643 chan_misdn_log(1, bc->port, " -->%s Not Available\n", Spacing);
2645 case 3: /* presentationRestrictedAddress */
2646 chan_misdn_log(1, bc->port, " -->%s Restricted:\n", Spacing);
2647 print_facility_AddressScreened(Level + 2, &Presented->Address, bc);
2653 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2655 #if defined(AST_MISDN_ENHANCEMENTS)
2656 static void print_facility_Q931_Bc_Hlc_Llc(unsigned Level, const struct Q931_Bc_Hlc_Llc *Q931ie, const struct misdn_bchannel *bc)
2658 const char *Spacing;
2660 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2661 chan_misdn_log(1, bc->port, " -->%s Q931ie:\n", Spacing);
2662 if (Q931ie->Bc.Length) {
2663 chan_misdn_log(1, bc->port, " -->%s Bc Len:%d\n", Spacing, Q931ie->Bc.Length);
2665 if (Q931ie->Hlc.Length) {
2666 chan_misdn_log(1, bc->port, " -->%s Hlc Len:%d\n", Spacing, Q931ie->Hlc.Length);
2668 if (Q931ie->Llc.Length) {
2669 chan_misdn_log(1, bc->port, " -->%s Llc Len:%d\n", Spacing, Q931ie->Llc.Length);
2672 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2674 #if defined(AST_MISDN_ENHANCEMENTS)
2675 static void print_facility_Q931_Bc_Hlc_Llc_Uu(unsigned Level, const struct Q931_Bc_Hlc_Llc_Uu *Q931ie, const struct misdn_bchannel *bc)
2677 const char *Spacing;
2679 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2680 chan_misdn_log(1, bc->port, " -->%s Q931ie:\n", Spacing);
2681 if (Q931ie->Bc.Length) {
2682 chan_misdn_log(1, bc->port, " -->%s Bc Len:%d\n", Spacing, Q931ie->Bc.Length);
2684 if (Q931ie->Hlc.Length) {
2685 chan_misdn_log(1, bc->port, " -->%s Hlc Len:%d\n", Spacing, Q931ie->Hlc.Length);
2687 if (Q931ie->Llc.Length) {
2688 chan_misdn_log(1, bc->port, " -->%s Llc Len:%d\n", Spacing, Q931ie->Llc.Length);
2690 if (Q931ie->UserInfo.Length) {
2691 chan_misdn_log(1, bc->port, " -->%s UserInfo Len:%d\n", Spacing, Q931ie->UserInfo.Length);
2694 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2696 #if defined(AST_MISDN_ENHANCEMENTS)
2697 static void print_facility_CallInformation(unsigned Level, const struct FacCallInformation *CallInfo, const struct misdn_bchannel *bc)
2699 const char *Spacing;
2701 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2702 chan_misdn_log(1, bc->port, " -->%s CCBSReference:%d\n",
2703 Spacing, CallInfo->CCBSReference);
2704 chan_misdn_log(1, bc->port, " -->%s AddressOfB:\n", Spacing);
2705 print_facility_Address(Level + 1, &CallInfo->AddressOfB, bc);
2706 print_facility_Q931_Bc_Hlc_Llc(Level, &CallInfo->Q931ie, bc);
2707 if (CallInfo->SubaddressOfA.Length) {
2708 chan_misdn_log(1, bc->port, " -->%s SubaddressOfA:\n", Spacing);
2709 print_facility_Subaddress(Level + 1, &CallInfo->SubaddressOfA, bc);
2712 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2714 #if defined(AST_MISDN_ENHANCEMENTS)
2715 static void print_facility_ServedUserNr(unsigned Level, const struct FacPartyNumber *Party, const struct misdn_bchannel *bc)
2717 const char *Spacing;
2719 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2720 if (Party->LengthOfNumber) {
2721 print_facility_PartyNumber(Level, Party, bc);
2723 chan_misdn_log(1, bc->port, " -->%s All Numbers\n", Spacing);
2726 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2728 #if defined(AST_MISDN_ENHANCEMENTS)
2729 static void print_facility_IntResult(unsigned Level, const struct FacForwardingRecord *ForwardingRecord, const struct misdn_bchannel *bc)
2731 const char *Spacing;
2733 Spacing = &Level_Spacing[sizeof(Level_Spacing) - 1 - Level];
2734 chan_misdn_log(1, bc->port, " -->%s Procedure:%d BasicService:%d\n",
2736 ForwardingRecord->Procedure,
2737 ForwardingRecord->BasicService);
2738 chan_misdn_log(1, bc->port, " -->%s ForwardedTo:\n", Spacing);
2739 print_facility_Address(Level + 1, &ForwardingRecord->ForwardedTo, bc);
2740 chan_misdn_log(1, bc->port, " -->%s ServedUserNr:\n", Spacing);
2741 print_facility_ServedUserNr(Level + 1, &ForwardingRecord->ServedUser, bc);
2743 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2745 static void print_facility(const struct FacParm *fac, const struct misdn_bchannel *bc)
2747 #if defined(AST_MISDN_ENHANCEMENTS)
2749 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2751 switch (fac->Function) {
2752 #if defined(AST_MISDN_ENHANCEMENTS)
2753 case Fac_ActivationDiversion:
2754 chan_misdn_log(1, bc->port, " --> ActivationDiversion: InvokeID:%d\n",
2755 fac->u.ActivationDiversion.InvokeID);
2756 switch (fac->u.ActivationDiversion.ComponentType) {
2757 case FacComponent_Invoke:
2758 chan_misdn_log(1, bc->port, " --> Invoke: Procedure:%d BasicService:%d\n",
2759 fac->u.ActivationDiversion.Component.Invoke.Procedure,
2760 fac->u.ActivationDiversion.Component.Invoke.BasicService);
2761 chan_misdn_log(1, bc->port, " --> ForwardedTo:\n");
2762 print_facility_Address(3, &fac->u.ActivationDiversion.Component.Invoke.ForwardedTo, bc);
2763 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2764 print_facility_ServedUserNr(3, &fac->u.ActivationDiversion.Component.Invoke.ServedUser, bc);
2766 case FacComponent_Result:
2767 chan_misdn_log(1, bc->port, " --> Result\n");
2773 case Fac_DeactivationDiversion:
2774 chan_misdn_log(1, bc->port, " --> DeactivationDiversion: InvokeID:%d\n",
2775 fac->u.DeactivationDiversion.InvokeID);
2776 switch (fac->u.DeactivationDiversion.ComponentType) {
2777 case FacComponent_Invoke:
2778 chan_misdn_log(1, bc->port, " --> Invoke: Procedure:%d BasicService:%d\n",
2779 fac->u.DeactivationDiversion.Component.Invoke.Procedure,
2780 fac->u.DeactivationDiversion.Component.Invoke.BasicService);
2781 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2782 print_facility_ServedUserNr(3, &fac->u.DeactivationDiversion.Component.Invoke.ServedUser, bc);
2784 case FacComponent_Result:
2785 chan_misdn_log(1, bc->port, " --> Result\n");
2791 case Fac_ActivationStatusNotificationDiv:
2792 chan_misdn_log(1, bc->port, " --> ActivationStatusNotificationDiv: InvokeID:%d Procedure:%d BasicService:%d\n",
2793 fac->u.ActivationStatusNotificationDiv.InvokeID,
2794 fac->u.ActivationStatusNotificationDiv.Procedure,
2795 fac->u.ActivationStatusNotificationDiv.BasicService);
2796 chan_misdn_log(1, bc->port, " --> ForwardedTo:\n");
2797 print_facility_Address(2, &fac->u.ActivationStatusNotificationDiv.ForwardedTo, bc);
2798 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2799 print_facility_ServedUserNr(2, &fac->u.ActivationStatusNotificationDiv.ServedUser, bc);
2801 case Fac_DeactivationStatusNotificationDiv:
2802 chan_misdn_log(1, bc->port, " --> DeactivationStatusNotificationDiv: InvokeID:%d Procedure:%d BasicService:%d\n",
2803 fac->u.DeactivationStatusNotificationDiv.InvokeID,
2804 fac->u.DeactivationStatusNotificationDiv.Procedure,
2805 fac->u.DeactivationStatusNotificationDiv.BasicService);
2806 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2807 print_facility_ServedUserNr(2, &fac->u.DeactivationStatusNotificationDiv.ServedUser, bc);
2809 case Fac_InterrogationDiversion:
2810 chan_misdn_log(1, bc->port, " --> InterrogationDiversion: InvokeID:%d\n",
2811 fac->u.InterrogationDiversion.InvokeID);
2812 switch (fac->u.InterrogationDiversion.ComponentType) {
2813 case FacComponent_Invoke:
2814 chan_misdn_log(1, bc->port, " --> Invoke: Procedure:%d BasicService:%d\n",
2815 fac->u.InterrogationDiversion.Component.Invoke.Procedure,
2816 fac->u.InterrogationDiversion.Component.Invoke.BasicService);
2817 chan_misdn_log(1, bc->port, " --> ServedUserNr:\n");
2818 print_facility_ServedUserNr(3, &fac->u.InterrogationDiversion.Component.Invoke.ServedUser, bc);
2820 case FacComponent_Result:
2821 chan_misdn_log(1, bc->port, " --> Result:\n");
2822 if (fac->u.InterrogationDiversion.Component.Result.NumRecords) {
2823 for (Index = 0; Index < fac->u.InterrogationDiversion.Component.Result.NumRecords; ++Index) {
2824 chan_misdn_log(1, bc->port, " --> IntResult[%d]:\n", Index);
2825 print_facility_IntResult(3, &fac->u.InterrogationDiversion.Component.Result.List[Index], bc);
2833 case Fac_DiversionInformation:
2834 chan_misdn_log(1, bc->port, " --> DiversionInformation: InvokeID:%d Reason:%d BasicService:%d\n",
2835 fac->u.DiversionInformation.InvokeID,
2836 fac->u.DiversionInformation.DiversionReason,
2837 fac->u.DiversionInformation.BasicService);
2838 if (fac->u.DiversionInformation.ServedUserSubaddress.Length) {
2839 chan_misdn_log(1, bc->port, " --> ServedUserSubaddress:\n");
2840 print_facility_Subaddress(2, &fac->u.DiversionInformation.ServedUserSubaddress, bc);
2842 if (fac->u.DiversionInformation.CallingAddressPresent) {
2843 chan_misdn_log(1, bc->port, " --> CallingAddress:\n");
2844 print_facility_PresentedAddressScreened(2, &fac->u.DiversionInformation.CallingAddress, bc);
2846 if (fac->u.DiversionInformation.OriginalCalledPresent) {
2847 chan_misdn_log(1, bc->port, " --> OriginalCalledNr:\n");
2848 print_facility_PresentedNumberUnscreened(2, &fac->u.DiversionInformation.OriginalCalled, bc);
2850 if (fac->u.DiversionInformation.LastDivertingPresent) {
2851 chan_misdn_log(1, bc->port, " --> LastDivertingNr:\n");
2852 print_facility_PresentedNumberUnscreened(2, &fac->u.DiversionInformation.LastDiverting, bc);
2854 if (fac->u.DiversionInformation.LastDivertingReasonPresent) {
2855 chan_misdn_log(1, bc->port, " --> LastDivertingReason:%d\n", fac->u.DiversionInformation.LastDivertingReason);
2857 if (fac->u.DiversionInformation.UserInfo.Length) {
2858 chan_misdn_log(1, bc->port, " --> UserInfo Length:%d\n", fac->u.DiversionInformation.UserInfo.Length);
2861 case Fac_CallDeflection:
2862 chan_misdn_log(1, bc->port, " --> CallDeflection: InvokeID:%d\n",
2863 fac->u.CallDeflection.InvokeID);
2864 switch (fac->u.CallDeflection.ComponentType) {
2865 case FacComponent_Invoke:
2866 chan_misdn_log(1, bc->port, " --> Invoke:\n");
2867 if (fac->u.CallDeflection.Component.Invoke.PresentationAllowedToDivertedToUserPresent) {
2868 chan_misdn_log(1, bc->port, " --> PresentationAllowed:%d\n",
2869 fac->u.CallDeflection.Component.Invoke.PresentationAllowedToDivertedToUser);
2871 chan_misdn_log(1, bc->port, " --> DeflectionAddress:\n");
2872 print_facility_Address(3, &fac->u.CallDeflection.Component.Invoke.Deflection, bc);
2874 case FacComponent_Result:
2875 chan_misdn_log(1, bc->port, " --> Result\n");
2881 case Fac_CallRerouteing:
2882 chan_misdn_log(1, bc->port, " --> CallRerouteing: InvokeID:%d\n",
2883 fac->u.CallRerouteing.InvokeID);
2884 switch (fac->u.CallRerouteing.ComponentType) {
2885 case FacComponent_Invoke:
2886 chan_misdn_log(1, bc->port, " --> Invoke: Reason:%d Counter:%d\n",
2887 fac->u.CallRerouteing.Component.Invoke.ReroutingReason,
2888 fac->u.CallRerouteing.Component.Invoke.ReroutingCounter);
2889 chan_misdn_log(1, bc->port, " --> CalledAddress:\n");
2890 print_facility_Address(3, &fac->u.CallRerouteing.Component.Invoke.CalledAddress, bc);
2891 print_facility_Q931_Bc_Hlc_Llc_Uu(2, &fac->u.CallRerouteing.Component.Invoke.Q931ie, bc);
2892 chan_misdn_log(1, bc->port, " --> LastReroutingNr:\n");
2893 print_facility_PresentedNumberUnscreened(3, &fac->u.CallRerouteing.Component.Invoke.LastRerouting, bc);
2894 chan_misdn_log(1, bc->port, " --> SubscriptionOption:%d\n",
2895 fac->u.CallRerouteing.Component.Invoke.SubscriptionOption);
2896 if (fac->u.CallRerouteing.Component.Invoke.CallingPartySubaddress.Length) {
2897 chan_misdn_log(1, bc->port, " --> CallingParty:\n");
2898 print_facility_Subaddress(3, &fac->u.CallRerouteing.Component.Invoke.CallingPartySubaddress, bc);
2901 case FacComponent_Result:
2902 chan_misdn_log(1, bc->port, " --> Result\n");
2908 case Fac_InterrogateServedUserNumbers:
2909 chan_misdn_log(1, bc->port, " --> InterrogateServedUserNumbers: InvokeID:%d\n",
2910 fac->u.InterrogateServedUserNumbers.InvokeID);
2911 switch (fac->u.InterrogateServedUserNumbers.ComponentType) {
2912 case FacComponent_Invoke:
2913 chan_misdn_log(1, bc->port, " --> Invoke\n");
2915 case FacComponent_Result:
2916 chan_misdn_log(1, bc->port, " --> Result:\n");
2917 if (fac->u.InterrogateServedUserNumbers.Component.Result.NumRecords) {
2918 for (Index = 0; Index < fac->u.InterrogateServedUserNumbers.Component.Result.NumRecords; ++Index) {
2919 chan_misdn_log(1, bc->port, " --> ServedUserNr[%d]:\n", Index);
2920 print_facility_PartyNumber(3, &fac->u.InterrogateServedUserNumbers.Component.Result.List[Index], bc);
2928 case Fac_DivertingLegInformation1:
2929 chan_misdn_log(1, bc->port, " --> DivertingLegInformation1: InvokeID:%d Reason:%d SubscriptionOption:%d\n",
2930 fac->u.DivertingLegInformation1.InvokeID,
2931 fac->u.DivertingLegInformation1.DiversionReason,
2932 fac->u.DivertingLegInformation1.SubscriptionOption);
2933 if (fac->u.DivertingLegInformation1.DivertedToPresent) {
2934 chan_misdn_log(1, bc->port, " --> DivertedToNr:\n");
2935 print_facility_PresentedNumberUnscreened(2, &fac->u.DivertingLegInformation1.DivertedTo, bc);
2938 case Fac_DivertingLegInformation2:
2939 chan_misdn_log(1, bc->port, " --> DivertingLegInformation2: InvokeID:%d Reason:%d Count:%d\n",
2940 fac->u.DivertingLegInformation2.InvokeID,
2941 fac->u.DivertingLegInformation2.DiversionReason,
2942 fac->u.DivertingLegInformation2.DiversionCounter);
2943 if (fac->u.DivertingLegInformation2.DivertingPresent) {
2944 chan_misdn_log(1, bc->port, " --> DivertingNr:\n");
2945 print_facility_PresentedNumberUnscreened(2, &fac->u.DivertingLegInformation2.Diverting, bc);
2947 if (fac->u.DivertingLegInformation2.OriginalCalledPresent) {
2948 chan_misdn_log(1, bc->port, " --> OriginalCalledNr:\n");
2949 print_facility_PresentedNumberUnscreened(2, &fac->u.DivertingLegInformation2.OriginalCalled, bc);
2952 case Fac_DivertingLegInformation3:
2953 chan_misdn_log(1, bc->port, " --> DivertingLegInformation3: InvokeID:%d PresentationAllowed:%d\n",
2954 fac->u.DivertingLegInformation3.InvokeID,
2955 fac->u.DivertingLegInformation3.PresentationAllowedIndicator);
2958 #else /* !defined(AST_MISDN_ENHANCEMENTS) */
2961 chan_misdn_log(1, bc->port, " --> calldeflect to: %s, presentable: %s\n", fac->u.CDeflection.DeflectedToNumber,
2962 fac->u.CDeflection.PresentationAllowed ? "yes" : "no");
2964 #endif /* !defined(AST_MISDN_ENHANCEMENTS) */
2965 case Fac_AOCDCurrency:
2966 if (fac->u.AOCDcur.chargeNotAvailable) {
2967 chan_misdn_log(1, bc->port, " --> AOCD currency: charge not available\n");
2968 } else if (fac->u.AOCDcur.freeOfCharge) {
2969 chan_misdn_log(1, bc->port, " --> AOCD currency: free of charge\n");
2970 } else if (fac->u.AOCDchu.billingId >= 0) {
2971 chan_misdn_log(1, bc->port, " --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s billingId:%d\n",
2972 fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
2973 (fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDcur.billingId);
2975 chan_misdn_log(1, bc->port, " --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s\n",
2976 fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
2977 (fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total");
2980 case Fac_AOCDChargingUnit:
2981 if (fac->u.AOCDchu.chargeNotAvailable) {
2982 chan_misdn_log(1, bc->port, " --> AOCD charging unit: charge not available\n");
2983 } else if (fac->u.AOCDchu.freeOfCharge) {
2984 chan_misdn_log(1, bc->port, " --> AOCD charging unit: free of charge\n");
2985 } else if (fac->u.AOCDchu.billingId >= 0) {
2986 chan_misdn_log(1, bc->port, " --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s billingId:%d\n",
2987 fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDchu.billingId);
2989 chan_misdn_log(1, bc->port, " --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s\n",
2990 fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total");
2993 #if defined(AST_MISDN_ENHANCEMENTS)
2995 chan_misdn_log(1, bc->port, " --> ERROR: InvokeID:%d, Code:0x%02x\n",
2996 fac->u.ERROR.invokeId, fac->u.ERROR.errorValue);
2999 chan_misdn_log(1, bc->port, " --> RESULT: InvokeID:%d\n",
3000 fac->u.RESULT.InvokeID);
3003 if (fac->u.REJECT.InvokeIDPresent) {
3004 chan_misdn_log(1, bc->port, " --> REJECT: InvokeID:%d, Code:0x%02x\n",
3005 fac->u.REJECT.InvokeID, fac->u.REJECT.Code);
3007 chan_misdn_log(1, bc->port, " --> REJECT: Code:0x%02x\n",
3008 fac->u.REJECT.Code);
3011 case Fac_EctExecute:
3012 chan_misdn_log(1, bc->port, " --> EctExecute: InvokeID:%d\n",
3013 fac->u.EctExecute.InvokeID);
3015 case Fac_ExplicitEctExecute:
3016 chan_misdn_log(1, bc->port, " --> ExplicitEctExecute: InvokeID:%d LinkID:%d\n",
3017 fac->u.ExplicitEctExecute.InvokeID,
3018 fac->u.ExplicitEctExecute.LinkID);
3020 case Fac_RequestSubaddress:
3021 chan_misdn_log(1, bc->port, " --> RequestSubaddress: InvokeID:%d\n",
3022 fac->u.RequestSubaddress.InvokeID);
3024 case Fac_SubaddressTransfer:
3025 chan_misdn_log(1, bc->port, " --> SubaddressTransfer: InvokeID:%d\n",
3026 fac->u.SubaddressTransfer.InvokeID);
3027 print_facility_Subaddress(1, &fac->u.SubaddressTransfer.Subaddress, bc);
3029 case Fac_EctLinkIdRequest:
3030 chan_misdn_log(1, bc->port, " --> EctLinkIdRequest: InvokeID:%d\n",
3031 fac->u.EctLinkIdRequest.InvokeID);
3032 switch (fac->u.EctLinkIdRequest.ComponentType) {
3033 case FacComponent_Invoke:
3034 chan_misdn_log(1, bc->port, " --> Invoke\n");
3036 case FacComponent_Result:
3037 chan_misdn_log(1, bc->port, " --> Result: LinkID:%d\n",
3038 fac->u.EctLinkIdRequest.Component.Result.LinkID);
3045 chan_misdn_log(1, bc->port, " --> EctInform: InvokeID:%d Status:%d\n",
3046 fac->u.EctInform.InvokeID,
3047 fac->u.EctInform.Status);
3048 if (fac->u.EctInform.RedirectionPresent) {
3049 chan_misdn_log(1, bc->port, " --> Redirection Number\n");
3050 print_facility_PresentedNumberUnscreened(2, &fac->u.EctInform.Redirection, bc);
3053 case Fac_EctLoopTest:
3054 chan_misdn_log(1, bc->port, " --> EctLoopTest: InvokeID:%d\n",
3055 fac->u.EctLoopTest.InvokeID);
3056 switch (fac->u.EctLoopTest.ComponentType) {
3057 case FacComponent_Invoke:
3058 chan_misdn_log(1, bc->port, " --> Invoke: CallTransferID:%d\n",
3059 fac->u.EctLoopTest.Component.Invoke.CallTransferID);
3061 case FacComponent_Result:
3062 chan_misdn_log(1, bc->port, " --> Result: LoopResult:%d\n",
3063 fac->u.EctLoopTest.Component.Result.LoopResult);
3069 case Fac_StatusRequest:
3070 chan_misdn_log(1, bc->port, " --> StatusRequest: InvokeID:%d\n",
3071 fac->u.StatusRequest.InvokeID);
3072 switch (fac->u.StatusRequest.ComponentType) {
3073 case FacComponent_Invoke:
3074 chan_misdn_log(1, bc->port, " --> Invoke: Compatibility:%d\n",
3075 fac->u.StatusRequest.Component.Invoke.CompatibilityMode);
3077 case FacComponent_Result:
3078 chan_misdn_log(1, bc->port, " --> Result: Status:%d\n",
3079 fac->u.StatusRequest.Component.Result.Status);
3085 case Fac_CallInfoRetain:
3086 chan_misdn_log(1, bc->port, " --> CallInfoRetain: InvokeID:%d, LinkageID:%d\n",
3087 fac->u.CallInfoRetain.InvokeID, fac->u.CallInfoRetain.CallLinkageID);
3089 case Fac_CCBSDeactivate:
3090 chan_misdn_log(1, bc->port, " --> CCBSDeactivate: InvokeID:%d\n",
3091 fac->u.CCBSDeactivate.InvokeID);
3092 switch (fac->u.CCBSDeactivate.ComponentType) {
3093 case FacComponent_Invoke:
3094 chan_misdn_log(1, bc->port, " --> Invoke: CCBSReference:%d\n",
3095 fac->u.CCBSDeactivate.Component.Invoke.CCBSReference);
3097 case FacComponent_Result:
3098 chan_misdn_log(1, bc->port, " --> Result\n");
3105 chan_misdn_log(1, bc->port, " --> CCBSErase: InvokeID:%d, CCBSReference:%d RecallMode:%d, Reason:%d\n",
3106 fac->u.CCBSErase.InvokeID, fac->u.CCBSErase.CCBSReference,
3107 fac->u.CCBSErase.RecallMode, fac->u.CCBSErase.Reason);
3108 chan_misdn_log(1, bc->port, " --> AddressOfB\n");
3109 print_facility_Address(2, &fac->u.CCBSErase.AddressOfB, bc);
3110 print_facility_Q931_Bc_Hlc_Llc(1, &fac->u.CCBSErase.Q931ie, bc);
3112 case Fac_CCBSRemoteUserFree:
3113 chan_misdn_log(1, bc->port, " --> CCBSRemoteUserFree: InvokeID:%d, CCBSReference:%d RecallMode:%d\n",
3114 fac->u.CCBSRemoteUserFree.InvokeID, fac->u.CCBSRemoteUserFree.CCBSReference,
3115 fac->u.CCBSRemoteUserFree.RecallMode);
3116 chan_misdn_log(1, bc->port, " --> AddressOfB\n");
3117 print_facility_Address(2, &fac->u.CCBSRemoteUserFree.AddressOfB, bc);
3118 print_facility_Q931_Bc_Hlc_Llc(1, &fac->u.CCBSRemoteUserFree.Q931ie, bc);
3121 chan_misdn_log(1, bc->port, " --> CCBSCall: InvokeID:%d, CCBSReference:%d\n",
3122 fac->u.CCBSCall.InvokeID, fac->u.CCBSCall.CCBSReference);
3124 case Fac_CCBSStatusRequest:
3125 chan_misdn_log(1, bc->port, " --> CCBSStatusRequest: InvokeID:%d\n",
3126 fac->u.CCBSStatusRequest.InvokeID);
3127 switch (fac->u.CCBSStatusRequest.ComponentType) {
3128 case FacComponent_Invoke:
3129 chan_misdn_log(1, bc->port, " --> Invoke: CCBSReference:%d RecallMode:%d\n",
3130 fac->u.CCBSStatusRequest.Component.Invoke.CCBSReference,
3131 fac->u.CCBSStatusRequest.Component.Invoke.RecallMode);
3132 print_facility_Q931_Bc_Hlc_Llc(2, &fac->u.CCBSStatusRequest.Component.Invoke.Q931ie, bc);
3134 case FacComponent_Result:
3135 chan_misdn_log(1, bc->port, " --> Result: Free:%d\n",
3136 fac->u.CCBSStatusRequest.Component.Result.Free);
3143 chan_misdn_log(1, bc->port, " --> CCBSBFree: InvokeID:%d, CCBSReference:%d RecallMode:%d\n",
3144 fac->u.CCBSBFree.InvokeID, fac->u.CCBSBFree.CCBSReference,
3145 fac->u.CCBSBFree.RecallMode);
3146 chan_misdn_log(1, bc->port, " --> AddressOfB\n");
3147 print_facility_Address(2, &fac->u.CCBSBFree.AddressOfB, bc);
3148 print_facility_Q931_Bc_Hlc_Llc(1, &fac->u.CCBSBFree.Q931ie, bc);
3150 case Fac_EraseCallLinkageID:
3151 chan_misdn_log(1, bc->port, " --> EraseCallLinkageID: InvokeID:%d, LinkageID:%d\n",
3152 fac->u.EraseCallLinkageID.InvokeID, fac->u.EraseCallLinkageID.CallLinkageID);
3154 case Fac_CCBSStopAlerting:
3155 chan_misdn_log(1, bc->port, " --> CCBSStopAlerting: InvokeID:%d, CCBSReference:%d\n",
3156 fac->u.CCBSStopAlerting.InvokeID, fac->u.CCBSStopAlerting.CCBSReference);
3158 case Fac_CCBSRequest:
3159 chan_misdn_log(1, bc->port, " --> CCBSRequest: InvokeID:%d\n",
3160 fac->u.CCBSRequest.InvokeID);
3161 switch (fac->u.CCBSRequest.ComponentType) {
3162 case FacComponent_Invoke:
3163 chan_misdn_log(1, bc->port, " --> Invoke: LinkageID:%d\n",
3164 fac->u.CCBSRequest.Component.Invoke.CallLinkageID);
3166 case FacComponent_Result:
3167 chan_misdn_log(1, bc->port, " --> Result: CCBSReference:%d RecallMode:%d\n",
3168 fac->u.CCBSRequest.Component.Result.CCBSReference,
3169 fac->u.CCBSRequest.Component.Result.RecallMode);
3175 case Fac_CCBSInterrogate:
3176 chan_misdn_log(1, bc->port, " --> CCBSInterrogate: InvokeID:%d\n",
3177 fac->u.CCBSInterrogate.InvokeID);
3178 switch (fac->u.CCBSInterrogate.ComponentType) {
3179 case FacComponent_Invoke:
3180 chan_misdn_log(1, bc->port, " --> Invoke\n");
3181 if (fac->u.CCBSInterrogate.Component.Invoke.CCBSReferencePresent) {
3182 chan_misdn_log(1, bc->port, " --> CCBSReference:%d\n",
3183 fac->u.CCBSInterrogate.Component.Invoke.CCBSReference);
3185 if (fac->u.CCBSInterrogate.Component.Invoke.AParty.LengthOfNumber) {
3186 chan_misdn_log(1, bc->port, " --> AParty\n");
3187 print_facility_PartyNumber(3, &fac->u.CCBSInterrogate.Component.Invoke.AParty, bc);
3190 case FacComponent_Result:
3191 chan_misdn_log(1, bc->port, " --> Result: RecallMode:%d\n",
3192 fac->u.CCBSInterrogate.Component.Result.RecallMode);
3193 if (fac->u.CCBSInterrogate.Component.Result.NumRecords) {
3194 for (Index = 0; Index < fac->u.CCBSInterrogate.Component.Result.NumRecords; ++Index) {
3195 chan_misdn_log(1, bc->port, " --> CallDetails[%d]:\n", Index);
3196 print_facility_CallInformation(3, &fac->u.CCBSInterrogate.Component.Result.CallDetails[Index], bc);
3204 case Fac_CCNRRequest:
3205 chan_misdn_log(1, bc->port, " --> CCNRRequest: InvokeID:%d\n",
3206 fac->u.CCNRRequest.InvokeID);
3207 switch (fac->u.CCNRRequest.ComponentType) {
3208 case FacComponent_Invoke:
3209 chan_misdn_log(1, bc->port, " --> Invoke: LinkageID:%d\n",
3210 fac->u.CCNRRequest.Component.Invoke.CallLinkageID);
3212 case FacComponent_Result:
3213 chan_misdn_log(1, bc->port, " --> Result: CCBSReference:%d RecallMode:%d\n",
3214 fac->u.CCNRRequest.Component.Result.CCBSReference,
3215 fac->u.CCNRRequest.Component.Result.RecallMode);
3221 case Fac_CCNRInterrogate:
3222 chan_misdn_log(1, bc->port, " --> CCNRInterrogate: InvokeID:%d\n",
3223 fac->u.CCNRInterrogate.InvokeID);
3224 switch (fac->u.CCNRInterrogate.ComponentType) {
3225 case FacComponent_Invoke:
3226 chan_misdn_log(1, bc->port, " --> Invoke\n");
3227 if (fac->u.CCNRInterrogate.Component.Invoke.CCBSReferencePresent) {
3228 chan_misdn_log(1, bc->port, " --> CCBSReference:%d\n",
3229 fac->u.CCNRInterrogate.Component.Invoke.CCBSReference);
3231 if (fac->u.CCNRInterrogate.Component.Invoke.AParty.LengthOfNumber) {
3232 chan_misdn_log(1, bc->port, " --> AParty\n");
3233 print_facility_PartyNumber(3, &fac->u.CCNRInterrogate.Component.Invoke.AParty, bc);
3236 case FacComponent_Result:
3237 chan_misdn_log(1, bc->port, " --> Result: RecallMode:%d\n",
3238 fac->u.CCNRInterrogate.Component.Result.RecallMode);
3239 if (fac->u.CCNRInterrogate.Component.Result.NumRecords) {
3240 for (Index = 0; Index < fac->u.CCNRInterrogate.Component.Result.NumRecords; ++Index) {
3241 chan_misdn_log(1, bc->port, " --> CallDetails[%d]:\n", Index);
3242 print_facility_CallInformation(3, &fac->u.CCNRInterrogate.Component.Result.CallDetails[Index], bc);
3250 case Fac_CCBS_T_Call:
3251 chan_misdn_log(1, bc->port, " --> CCBS_T_Call: InvokeID:%d\n",
3252 fac->u.CCBS_T_Call.InvokeID);
3254 case Fac_CCBS_T_Suspend:
3255 chan_misdn_log(1, bc->port, " --> CCBS_T_Suspend: InvokeID:%d\n",
3256 fac->u.CCBS_T_Suspend.InvokeID);
3258 case Fac_CCBS_T_Resume:
3259 chan_misdn_log(1, bc->port, " --> CCBS_T_Resume: InvokeID:%d\n",
3260 fac->u.CCBS_T_Resume.InvokeID);
3262 case Fac_CCBS_T_RemoteUserFree:
3263 chan_misdn_log(1, bc->port, " --> CCBS_T_RemoteUserFree: InvokeID:%d\n",
3264 fac->u.CCBS_T_RemoteUserFree.InvokeID);
3266 case Fac_CCBS_T_Available:
3267 chan_misdn_log(1, bc->port, " --> CCBS_T_Available: InvokeID:%d\n",
3268 fac->u.CCBS_T_Available.InvokeID);
3270 case Fac_CCBS_T_Request:
3271 chan_misdn_log(1, bc->port, " --> CCBS_T_Request: InvokeID:%d\n",
3272 fac->u.CCBS_T_Request.InvokeID);
3273 switch (fac->u.CCBS_T_Request.ComponentType) {
3274 case FacComponent_Invoke:
3275 chan_misdn_log(1, bc->port, " --> Invoke\n");
3276 chan_misdn_log(1, bc->port, " --> DestinationAddress:\n");
3277 print_facility_Address(3, &fac->u.CCBS_T_Request.Component.Invoke.Destination, bc);
3278 print_facility_Q931_Bc_Hlc_Llc(2, &fac->u.CCBS_T_Request.Component.Invoke.Q931ie, bc);
3279 if (fac->u.CCBS_T_Request.Component.Invoke.RetentionSupported) {
3280 chan_misdn_log(1, bc->port, " --> RetentionSupported:1\n");
3282 if (fac->u.CCBS_T_Request.Component.Invoke.PresentationAllowedIndicatorPresent) {
3283 chan_misdn_log(1, bc->port, " --> PresentationAllowed:%d\n",
3284 fac->u.CCBS_T_Request.Component.Invoke.PresentationAllowedIndicator);
3286 if (fac->u.CCBS_T_Request.Component.Invoke.Originating.Party.LengthOfNumber) {
3287 chan_misdn_log(1, bc->port, " --> OriginatingAddress:\n");
3288 print_facility_Address(3, &fac->u.CCBS_T_Request.Component.Invoke.Originating, bc);
3291 case FacComponent_Result:
3292 chan_misdn_log(1, bc->port, " --> Result: RetentionSupported:%d\n",
3293 fac->u.CCBS_T_Request.Component.Result.RetentionSupported);
3299 case Fac_CCNR_T_Request:
3300 chan_misdn_log(1, bc->port, " --> CCNR_T_Request: InvokeID:%d\n",
3301 fac->u.CCNR_T_Request.InvokeID);
3302 switch (fac->u.CCNR_T_Request.ComponentType) {
3303 case FacComponent_Invoke:
3304 chan_misdn_log(1, bc->port, " --> Invoke\n");
3305 chan_misdn_log(1, bc->port, " --> DestinationAddress:\n");
3306 print_facility_Address(3, &fac->u.CCNR_T_Request.Component.Invoke.Destination, bc);
3307 print_facility_Q931_Bc_Hlc_Llc(2, &fac->u.CCNR_T_Request.Component.Invoke.Q931ie, bc);
3308 if (fac->u.CCNR_T_Request.Component.Invoke.RetentionSupported) {
3309 chan_misdn_log(1, bc->port, " --> RetentionSupported:1\n");
3311 if (fac->u.CCNR_T_Request.Component.Invoke.PresentationAllowedIndicatorPresent) {
3312 chan_misdn_log(1, bc->port, " --> PresentationAllowed:%d\n",
3313 fac->u.CCNR_T_Request.Component.Invoke.PresentationAllowedIndicator);
3315 if (fac->u.CCNR_T_Request.Component.Invoke.Originating.Party.LengthOfNumber) {
3316 chan_misdn_log(1, bc->port, " --> OriginatingAddress:\n");
3317 print_facility_Address(3, &fac->u.CCNR_T_Request.Component.Invoke.Originating, bc);
3320 case FacComponent_Result:
3321 chan_misdn_log(1, bc->port, " --> Result: RetentionSupported:%d\n",
3322 fac->u.CCNR_T_Request.Component.Result.RetentionSupported);
3328 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
3330 /* No facility so print nothing */
3333 chan_misdn_log(1, bc->port, " --> unknown facility\n");
3338 static void print_bearer(struct misdn_bchannel *bc)
3340 chan_misdn_log(2, bc->port, " --> Bearer: %s\n", bearer2str(bc->capability));
3343 case INFO_CODEC_ALAW:
3344 chan_misdn_log(2, bc->port, " --> Codec: Alaw\n");
3346 case INFO_CODEC_ULAW:
3347 chan_misdn_log(2, bc->port, " --> Codec: Ulaw\n");
3354 * \brief Prefix a string to another string in place.
3356 * \param str_prefix String to prefix to the main string.
3357 * \param str_main String to get the prefix added to it.
3358 * \param size Buffer size of the main string (Includes null terminator).
3360 * \note The str_main buffer size must be greater than one.
3364 static void misdn_prefix_string(const char *str_prefix, char *str_main, size_t size)
3371 len_prefix = strlen(str_prefix);
3373 /* There is no prefix to prepend. */
3376 len_main = strlen(str_main);
3377 len_total = len_prefix + len_main;
3378 if (size <= len_total) {
3379 /* We need to truncate since the buffer is too small. */
3380 len_over = len_total + 1 - size;
3381 if (len_over <= len_main) {
3382 len_main -= len_over;
3384 len_over -= len_main;
3386 len_prefix -= len_over;
3390 memmove(str_main + len_prefix, str_main, len_main);
3392 memcpy(str_main, str_prefix, len_prefix);
3393 str_main[len_prefix + len_main] = '\0';
3398 * \brief Add a configured prefix to the given number.
3400 * \param port Logical port number
3401 * \param number_type Type-of-number passed in.
3402 * \param number Given number string to add prefix
3403 * \param size Buffer size number string occupies.
3407 static void misdn_add_number_prefix(int port, enum mISDN_NUMBER_TYPE number_type, char *number, size_t size)
3409 enum misdn_cfg_elements type_prefix;
3410 char num_prefix[MISDN_MAX_NUMBER_LEN];
3412 /* Get prefix string. */
3413 switch (number_type) {
3414 case NUMTYPE_UNKNOWN:
3415 type_prefix = MISDN_CFG_TON_PREFIX_UNKNOWN;
3417 case NUMTYPE_INTERNATIONAL:
3418 type_prefix = MISDN_CFG_TON_PREFIX_INTERNATIONAL;
3420 case NUMTYPE_NATIONAL:
3421 type_prefix = MISDN_CFG_TON_PREFIX_NATIONAL;
3423 case NUMTYPE_NETWORK_SPECIFIC:
3424 type_prefix = MISDN_CFG_TON_PREFIX_NETWORK_SPECIFIC;
3426 case NUMTYPE_SUBSCRIBER:
3427 type_prefix = MISDN_CFG_TON_PREFIX_SUBSCRIBER;
3429 case NUMTYPE_ABBREVIATED:
3430 type_prefix = MISDN_CFG_TON_PREFIX_ABBREVIATED;
3433 /* Type-of-number does not have a prefix that can be added. */
3436 misdn_cfg_get(port, type_prefix, num_prefix, sizeof(num_prefix));
3438 misdn_prefix_string(num_prefix, number, size);
3441 static void export_aoc_vars(int originator, struct ast_channel *ast, struct misdn_bchannel *bc)
3445 if (!bc->AOCD_need_export || !ast) {
3449 if (originator == ORG_AST) {
3450 ast = ast_bridged_channel(ast);
3456 switch (bc->AOCDtype) {
3457 case Fac_AOCDCurrency:
3458 pbx_builtin_setvar_helper(ast, "AOCD_Type", "currency");
3459 if (bc->AOCD.currency.chargeNotAvailable) {
3460 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
3462 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
3463 if (bc->AOCD.currency.freeOfCharge) {
3464 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
3466 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
3467 if (snprintf(buf, sizeof(buf), "%d %s", bc->AOCD.currency.currencyAmount * bc->AOCD.currency.multiplier, bc->AOCD.currency.currency) < sizeof(buf)) {
3468 pbx_builtin_setvar_helper(ast, "AOCD_Amount", buf);
3469 if (bc->AOCD.currency.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.currency.billingId) < sizeof(buf)) {
3470 pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
3476 case Fac_AOCDChargingUnit:
3477 pbx_builtin_setvar_helper(ast, "AOCD_Type", "charging_unit");
3478 if (bc->AOCD.chargingUnit.chargeNotAvailable) {
3479 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
3481 pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
3482 if (bc->AOCD.chargingUnit.freeOfCharge) {
3483 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
3485 pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
3486 if (snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.recordedUnits) < sizeof(buf)) {
3487 pbx_builtin_setvar_helper(ast, "AOCD_RecordedUnits", buf);
3488 if (bc->AOCD.chargingUnit.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.billingId) < sizeof(buf)) {
3489 pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
3499 bc->AOCD_need_export = 0;
3502 /*************** Helpers END *************/
3504 static void sighandler(int sig)
3508 static void *misdn_tasks_thread_func(void *data)
3511 struct sigaction sa;
3513 sa.sa_handler = sighandler;
3514 sa.sa_flags = SA_NODEFER;
3515 sigemptyset(&sa.sa_mask);
3516 sigaddset(&sa.sa_mask, SIGUSR1);
3517 sigaction(SIGUSR1, &sa, NULL);
3519 sem_post((sem_t *)data);
3522 wait = ast_sched_wait(misdn_tasks);
3526 if (poll(NULL, 0, wait) < 0) {
3527 chan_misdn_log(4, 0, "Waking up misdn_tasks thread\n");
3529 ast_sched_runq(misdn_tasks);
3534 static void misdn_tasks_init(void)
3539 if (sem_init(&blocker, 0, 0)) {
3540 perror("chan_misdn: Failed to initialize semaphore!");
3544 chan_misdn_log(4, 0, "Starting misdn_tasks thread\n");
3546 misdn_tasks = ast_sched_context_create();
3547 pthread_create(&misdn_tasks_thread, NULL, misdn_tasks_thread_func, &blocker);
3549 while (sem_wait(&blocker) && --i) {
3551 sem_destroy(&blocker);
3554 static void misdn_tasks_destroy(void)
3557 chan_misdn_log(4, 0, "Killing misdn_tasks thread\n");
3558 if (pthread_cancel(misdn_tasks_thread) == 0) {
3559 cb_log(4, 0, "Joining misdn_tasks thread\n");
3560 pthread_join(misdn_tasks_thread, NULL);
3562 ast_sched_context_destroy(misdn_tasks);
3566 static inline void misdn_tasks_wakeup(void)
3568 pthread_kill(misdn_tasks_thread, SIGUSR1);
3571 static inline int _misdn_tasks_add_variable(int timeout, ast_sched_cb callback, const void *data, int variable)
3578 task_id = ast_sched_add_variable(misdn_tasks, timeout, callback, data, variable);
3579 misdn_tasks_wakeup();
3584 static int misdn_tasks_add(int timeout, ast_sched_cb callback, const void *data)
3586 return _misdn_tasks_add_variable(timeout, callback, data, 0);
3589 static int misdn_tasks_add_variable(int timeout, ast_sched_cb callback, const void *data)
3591 return _misdn_tasks_add_variable(timeout, callback, data, 1);
3594 static void misdn_tasks_remove(int task_id)
3596 AST_SCHED_DEL(misdn_tasks, task_id);
3599 static int misdn_l1_task(const void *vdata)
3601 const int *data = vdata;
3603 misdn_lib_isdn_l1watcher(*data);
3604 chan_misdn_log(5, *data, "L1watcher timeout\n");
3608 static int misdn_overlap_dial_task(const void *data)
3610 struct timeval tv_end, tv_now;
3612 struct chan_list *ch = (struct chan_list *) data;
3615 chan_misdn_log(4, ch->bc->port, "overlap dial task, chan_state: %d\n", ch->state);
3617 if (ch->state != MISDN_WAITING4DIGS) {
3618 ch->overlap_dial_task = -1;
3622 ast_mutex_lock(&ch->overlap_tv_lock);
3623 tv_end = ch->overlap_tv;
3624 ast_mutex_unlock(&ch->overlap_tv_lock);
3626 tv_end.tv_sec += ch->overlap_dial;
3627 tv_now = ast_tvnow();
3629 diff = ast_tvdiff_ms(tv_end, tv_now);
3634 /* if we are 100ms near the timeout, we are satisfied.. */
3637 if (ast_strlen_zero(ch->bc->dialed.number)) {
3639 ast_channel_exten_set(ch->ast, dad);
3641 dad = ch->bc->dialed.number;
3644 if (ast_exists_extension(ch->ast, ch->context, dad, 1, ch->bc->caller.number)) {
3645 ch->state = MISDN_DIALING;
3646 if (pbx_start_chan(ch) < 0) {
3647 chan_misdn_log(-1, ch->bc->port, "ast_pbx_start returned < 0 in misdn_overlap_dial_task\n");
3648 goto misdn_overlap_dial_task_disconnect;
3651 misdn_overlap_dial_task_disconnect:
3652 hanguptone_indicate(ch);
3653 ch->bc->out_cause = AST_CAUSE_UNALLOCATED;
3654 ch->state = MISDN_CLEANING;
3655 misdn_lib_send_event(ch->bc, EVENT_DISCONNECT);
3657 ch->overlap_dial_task = -1;
3661 static void send_digit_to_chan(struct chan_list *cl, char digit)
3663 static const char * const dtmf_tones[] = {
3665 "!941+1336/100,!0/100", /* 0 */
3666 "!697+1209/100,!0/100", /* 1 */
3667 "!697+1336/100,!0/100", /* 2 */
3668 "!697+1477/100,!0/100", /* 3 */
3669 "!770+1209/100,!0/100", /* 4 */
3670 "!770+1336/100,!0/100", /* 5 */
3671 "!770+1477/100,!0/100", /* 6 */
3672 "!852+1209/100,!0/100", /* 7 */
3673 "!852+1336/100,!0/100", /* 8 */
3674 "!852+1477/100,!0/100", /* 9 */
3675 "!697+1633/100,!0/100", /* A */
3676 "!770+1633/100,!0/100", /* B */
3677 "!852+1633/100,!0/100", /* C */
3678 "!941+1633/100,!0/100", /* D */
3679 "!941+1209/100,!0/100", /* * */
3680 "!941+1477/100,!0/100", /* # */
3683 struct ast_channel *chan = cl->ast;
3685 if (digit >= '0' && digit <='9') {
3686 ast_playtones_start(chan, 0, dtmf_tones[digit - '0'], 0);
3687 } else if (digit >= 'A' && digit <= 'D') {
3688 ast_playtones_start(chan, 0, dtmf_tones[digit - 'A' + 10], 0);
3689 } else if (digit == '*') {
3690 ast_playtones_start(chan, 0, dtmf_tones[14], 0);
3691 } else if (digit == '#') {
3692 ast_playtones_start(chan, 0, dtmf_tones[15], 0);
3695 ast_debug(1, "Unable to handle DTMF tone '%c' for '%s'\n", digit, ast_channel_name(chan));
3699 /*** CLI HANDLING ***/
3700 static char *handle_cli_misdn_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3706 e->command = "misdn set debug [on|off]";
3708 "Usage: misdn set debug {on|off|<level>} [only] | [port <port> [only]]\n"
3709 " Set the debug level of the mISDN channel.\n";
3712 return complete_debug_port(a);
3715 if (a->argc < 4 || a->argc > 7) {
3716 return CLI_SHOWUSAGE;
3719 if (!strcasecmp(a->argv[3], "on")) {
3721 } else if (!strcasecmp(a->argv[3], "off")) {
3723 } else if (isdigit(a->argv[3][0])) {
3724 level = atoi(a->argv[3]);
3726 return CLI_SHOWUSAGE;
3736 if (strncasecmp(a->argv[4], "only", strlen(a->argv[4]))) {
3737 return CLI_SHOWUSAGE;
3743 for (i = 0; i <= max_ports; i++) {
3744 misdn_debug[i] = level;
3745 misdn_debug_only[i] = only;
3747 ast_cli(a->fd, "changing debug level for all ports to %d%s\n", misdn_debug[0], only ? " (only)" : "");
3754 if (strncasecmp(a->argv[4], "port", strlen(a->argv[4])))
3755 return CLI_SHOWUSAGE;
3756 port = atoi(a->argv[5]);
3757 if (port <= 0 || port > max_ports) {
3758 switch (max_ports) {
3760 ast_cli(a->fd, "port number not valid! no ports available so you won't get lucky with any number here...\n");
3763 ast_cli(a->fd, "port number not valid! only port 1 is available.\n");
3766 ast_cli(a->fd, "port number not valid! only ports 1 to %d are available.\n", max_ports);
3771 if (strncasecmp(a->argv[6], "only", strlen(a->argv[6]))) {
3772 return CLI_SHOWUSAGE;