Sat Apr 26 2014 22:01:42

Asterisk developer's documentation


sig_pri.h
Go to the documentation of this file.
00001 #ifndef _SIG_PRI_H
00002 #define _SIG_PRI_H
00003 /*
00004  * Asterisk -- An open source telephony toolkit.
00005  *
00006  * Copyright (C) 1999 - 2009, Digium, Inc.
00007  *
00008  * Mark Spencer <markster@digium.com>
00009  *
00010  * See http://www.asterisk.org for more information about
00011  * the Asterisk project. Please do not directly contact
00012  * any of the maintainers of this project for assistance;
00013  * the project provides a web site, mailing lists and IRC
00014  * channels for your use.
00015  *
00016  * This program is free software, distributed under the terms of
00017  * the GNU General Public License Version 2. See the LICENSE file
00018  * at the top of the source tree.
00019  */
00020 
00021 /*! \file
00022  *
00023  * \brief Interface header for PRI signaling module
00024  *
00025  * \author Matthew Fredrickson <creslin@digium.com>
00026  */
00027 
00028 #include "asterisk/channel.h"
00029 #include "asterisk/frame.h"
00030 #include "asterisk/event.h"
00031 #include "asterisk/ccss.h"
00032 #include <libpri.h>
00033 #include <dahdi/user.h>
00034 
00035 #if defined(HAVE_PRI_CCSS)
00036 /*! PRI debug message flags when normal PRI debugging is turned on at the command line. */
00037 #define SIG_PRI_DEBUG_NORMAL  \
00038    (PRI_DEBUG_APDU | PRI_DEBUG_Q931_STATE | PRI_DEBUG_Q921_STATE | PRI_DEBUG_CC)
00039 #else
00040 
00041 /*! PRI debug message flags when normal PRI debugging is turned on at the command line. */
00042 #define SIG_PRI_DEBUG_NORMAL  \
00043    (PRI_DEBUG_APDU | PRI_DEBUG_Q931_STATE | PRI_DEBUG_Q921_STATE)
00044 #endif   /* !defined(HAVE_PRI_CCSS) */
00045 
00046 #if 0
00047 /*! PRI debug message flags set on initial startup. */
00048 #define SIG_PRI_DEBUG_DEFAULT (SIG_PRI_DEBUG_NORMAL | PRI_DEBUG_Q931_DUMP)
00049 #else
00050 /*! PRI debug message flags set on initial startup. */
00051 #define SIG_PRI_DEBUG_DEFAULT 0
00052 #endif
00053 
00054 #define SIG_PRI_AOC_GRANT_S    (1 << 0)
00055 #define SIG_PRI_AOC_GRANT_D    (1 << 1)
00056 #define SIG_PRI_AOC_GRANT_E    (1 << 2)
00057 
00058 enum sig_pri_tone {
00059    SIG_PRI_TONE_RINGTONE = 0,
00060    SIG_PRI_TONE_STUTTER,
00061    SIG_PRI_TONE_CONGESTION,
00062    SIG_PRI_TONE_DIALTONE,
00063    SIG_PRI_TONE_DIALRECALL,
00064    SIG_PRI_TONE_INFO,
00065    SIG_PRI_TONE_BUSY,
00066 };
00067 
00068 enum sig_pri_law {
00069    SIG_PRI_DEFLAW = 0,
00070    SIG_PRI_ULAW,
00071    SIG_PRI_ALAW
00072 };
00073 
00074 enum sig_pri_moh_signaling {
00075    /*! Generate MOH to the remote party. */
00076    SIG_PRI_MOH_SIGNALING_MOH,
00077    /*! Send hold notification signaling to the remote party. */
00078    SIG_PRI_MOH_SIGNALING_NOTIFY,
00079 #if defined(HAVE_PRI_CALL_HOLD)
00080    /*! Use HOLD/RETRIEVE signaling to release the B channel while on hold. */
00081    SIG_PRI_MOH_SIGNALING_HOLD,
00082 #endif   /* defined(HAVE_PRI_CALL_HOLD) */
00083 };
00084 
00085 enum sig_pri_moh_state {
00086    /*! Bridged peer has not put us on hold. */
00087    SIG_PRI_MOH_STATE_IDLE,
00088    /*! Bridged peer has put us on hold and we were to notify the remote party. */
00089    SIG_PRI_MOH_STATE_NOTIFY,
00090    /*! Bridged peer has put us on hold and we were to play MOH or HOLD/RETRIEVE fallback. */
00091    SIG_PRI_MOH_STATE_MOH,
00092 #if defined(HAVE_PRI_CALL_HOLD)
00093    /*! Requesting to put channel on hold. */
00094    SIG_PRI_MOH_STATE_HOLD_REQ,
00095    /*! Trying to go on hold when bridged peer requested to unhold. */
00096    SIG_PRI_MOH_STATE_PEND_UNHOLD,
00097    /*! Channel is held. */
00098    SIG_PRI_MOH_STATE_HOLD,
00099    /*! Requesting to take channel out of hold. */
00100    SIG_PRI_MOH_STATE_RETRIEVE_REQ,
00101    /*! Trying to take channel out of hold when bridged peer requested to hold. */
00102    SIG_PRI_MOH_STATE_PEND_HOLD,
00103    /*! Failed to take the channel out of hold. No B channels were available? */
00104    SIG_PRI_MOH_STATE_RETRIEVE_FAIL,
00105 #endif   /* defined(HAVE_PRI_CALL_HOLD) */
00106 
00107    /*! Number of MOH states.  Must be last in enum. */
00108    SIG_PRI_MOH_STATE_NUM
00109 };
00110 
00111 enum sig_pri_moh_event {
00112    /*! Reset the MOH state machine. (Because of hangup.) */
00113    SIG_PRI_MOH_EVENT_RESET,
00114    /*! Bridged peer placed this channel on hold. */
00115    SIG_PRI_MOH_EVENT_HOLD,
00116    /*! Bridged peer took this channel off hold. */
00117    SIG_PRI_MOH_EVENT_UNHOLD,
00118 #if defined(HAVE_PRI_CALL_HOLD)
00119    /*! The hold request was successfully acknowledged. */
00120    SIG_PRI_MOH_EVENT_HOLD_ACK,
00121    /*! The hold request was rejected. */
00122    SIG_PRI_MOH_EVENT_HOLD_REJ,
00123    /*! The unhold request was successfully acknowledged. */
00124    SIG_PRI_MOH_EVENT_RETRIEVE_ACK,
00125    /*! The unhold request was rejected. */
00126    SIG_PRI_MOH_EVENT_RETRIEVE_REJ,
00127    /*! The remote party took this channel off hold. */
00128    SIG_PRI_MOH_EVENT_REMOTE_RETRIEVE_ACK,
00129 #endif   /* defined(HAVE_PRI_CALL_HOLD) */
00130 
00131    /*! Number of MOH events.  Must be last in enum. */
00132    SIG_PRI_MOH_EVENT_NUM
00133 };
00134 
00135 /*! Call establishment life cycle level for simple comparisons. */
00136 enum sig_pri_call_level {
00137    /*! Call does not exist. */
00138    SIG_PRI_CALL_LEVEL_IDLE,
00139    /*! Call is present but has no response yet. (SETUP) */
00140    SIG_PRI_CALL_LEVEL_SETUP,
00141    /*! Call is collecting digits for overlap dialing. (SETUP ACKNOWLEDGE) */
00142    SIG_PRI_CALL_LEVEL_OVERLAP,
00143    /*! Call routing is happening. (PROCEEDING) */
00144    SIG_PRI_CALL_LEVEL_PROCEEDING,
00145    /*! Called party is being alerted of the call. (ALERTING) */
00146    SIG_PRI_CALL_LEVEL_ALERTING,
00147    /*! Call is dialing 'w' deferred digits. (CONNECT) */
00148    SIG_PRI_CALL_LEVEL_DEFER_DIAL,
00149    /*! Call is connected/answered. (CONNECT) */
00150    SIG_PRI_CALL_LEVEL_CONNECT,
00151 };
00152 
00153 enum sig_pri_reset_state {
00154    /*! \brief The channel is not being RESTARTed. */
00155    SIG_PRI_RESET_IDLE,
00156    /*!
00157     * \brief The channel is being RESTARTed.
00158     * \note Waiting for a RESTART ACKNOWLEDGE from the peer.
00159     */
00160    SIG_PRI_RESET_ACTIVE,
00161    /*!
00162     * \brief Peer may not be sending the expected RESTART ACKNOWLEDGE.
00163     *
00164     * \details We have already received a SETUP on this channel.
00165     * If another SETUP comes in on this channel then the peer
00166     * considers this channel useable.  Assume that the peer is
00167     * never going to give us a RESTART ACKNOWLEDGE and assume that
00168     * we have received one.  This is not according to Q.931, but
00169     * some peers occasionally fail to send a RESTART ACKNOWLEDGE.
00170     */
00171    SIG_PRI_RESET_NO_ACK,
00172 };
00173 
00174 struct sig_pri_span;
00175 
00176 struct sig_pri_callback {
00177    /* Unlock the private in the signalling private structure.  This is used for three way calling madness. */
00178    void (* const unlock_private)(void *pvt);
00179    /* Lock the private in the signalling private structure.  ... */
00180    void (* const lock_private)(void *pvt);
00181    /* Do deadlock avoidance for the private signaling structure lock.  */
00182    void (* const deadlock_avoidance_private)(void *pvt);
00183    /* Function which is called back to handle any other DTMF events that are received.  Called by analog_handle_event.  Why is this
00184     * important to use, instead of just directly using events received before they are passed into the library?  Because sometimes,
00185     * (CWCID) the library absorbs DTMF events received. */
00186    //void (* const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest);
00187 
00188    //int (* const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop);
00189    int (* const play_tone)(void *pvt, enum sig_pri_tone tone);
00190 
00191    int (* const set_echocanceller)(void *pvt, int enable);
00192    int (* const train_echocanceller)(void *pvt);
00193    int (* const dsp_reset_and_flush_digits)(void *pvt);
00194 
00195    struct ast_channel * (* const new_ast_channel)(void *pvt, int state, enum sig_pri_law law, char *exten, const struct ast_channel *chan);
00196 
00197    void (* const fixup_chans)(void *old_chan, void *new_chan);
00198 
00199    /* Note: Called with PRI lock held */
00200    void (* const handle_dchan_exception)(struct sig_pri_span *pri, int index);
00201    void (* const set_alarm)(void *pvt, int in_alarm);
00202    void (* const set_dialing)(void *pvt, int is_dialing);
00203    void (* const set_digital)(void *pvt, int is_digital);
00204    void (* const set_outgoing)(void *pvt, int is_outgoing);
00205    void (* const set_callerid)(void *pvt, const struct ast_party_caller *caller);
00206    void (* const set_dnid)(void *pvt, const char *dnid);
00207    void (* const set_rdnis)(void *pvt, const char *rdnis);
00208    void (* const queue_control)(void *pvt, int subclass);
00209    int (* const new_nobch_intf)(struct sig_pri_span *pri);
00210    void (* const init_config)(void *pvt, struct sig_pri_span *pri);
00211    const char *(* const get_orig_dialstring)(void *pvt);
00212    void (* const make_cc_dialstring)(void *pvt, char *buf, size_t buf_size);
00213    void (* const update_span_devstate)(struct sig_pri_span *pri);
00214    void (* const dial_digits)(void *pvt, const char *dial_string);
00215 
00216    void (* const open_media)(void *pvt);
00217 
00218    /*!
00219     * \brief Post an AMI B channel association event.
00220     *
00221     * \param pvt Private structure of the user of this module.
00222     * \param chan Channel associated with the private pointer
00223     *
00224     * \return Nothing
00225     */
00226    void (* const ami_channel_event)(void *pvt, struct ast_channel *chan);
00227 
00228    /*! Reference the parent module. */
00229    void (*module_ref)(void);
00230    /*! Unreference the parent module. */
00231    void (*module_unref)(void);
00232 };
00233 
00234 /*! Global sig_pri callbacks to the upper layer. */
00235 extern struct sig_pri_callback sig_pri_callbacks;
00236 
00237 #define SIG_PRI_NUM_DCHANS    4     /*!< No more than 4 d-channels */
00238 #define SIG_PRI_MAX_CHANNELS  672      /*!< No more than a DS3 per trunk group */
00239 
00240 #define SIG_PRI      DAHDI_SIG_CLEAR
00241 #define SIG_BRI      (0x2000000 | DAHDI_SIG_CLEAR)
00242 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
00243 
00244 /* QSIG channel mapping option types */
00245 #define DAHDI_CHAN_MAPPING_PHYSICAL 0
00246 #define DAHDI_CHAN_MAPPING_LOGICAL  1
00247 
00248 /* Overlap dialing option types */
00249 #define DAHDI_OVERLAPDIAL_NONE 0
00250 #define DAHDI_OVERLAPDIAL_OUTGOING 1
00251 #define DAHDI_OVERLAPDIAL_INCOMING 2
00252 #define DAHDI_OVERLAPDIAL_BOTH (DAHDI_OVERLAPDIAL_INCOMING|DAHDI_OVERLAPDIAL_OUTGOING)
00253 
00254 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00255 /*! \brief Persistent Service State */
00256 #define SRVST_DBKEY "service-state"
00257 /*! \brief The out-of-service SERVICE state */
00258 #define SRVST_TYPE_OOS "O"
00259 /*! \brief SRVST_INITIALIZED is used to indicate a channel being out-of-service
00260  *  The SRVST_INITIALIZED is mostly used maintain backwards compatibility but also may
00261  *  mean that the channel has not yet received a RESTART message.  If a channel is
00262  *  out-of-service with this reason a RESTART message will result in the channel
00263  *  being put into service. */
00264 #define SRVST_INITIALIZED 0
00265 /*! \brief SRVST_NEAREND is used to indicate that the near end was put out-of-service */
00266 #define SRVST_NEAREND  (1 << 0)
00267 /*! \brief SRVST_FAREND is used to indicate that the far end was taken out-of-service */
00268 #define SRVST_FAREND   (1 << 1)
00269 /*! \brief SRVST_BOTH is used to indicate that both sides of the channel are out-of-service */
00270 #define SRVST_BOTH (SRVST_NEAREND | SRVST_FAREND)
00271 
00272 /*! \brief The AstDB family */
00273 static const char dahdi_db[] = "dahdi/registry";
00274 #endif   /* defined(HAVE_PRI_SERVICE_MESSAGES) */
00275 
00276 struct sig_pri_chan {
00277    /* Options to be set by user */
00278    unsigned int hidecallerid:1;
00279    unsigned int hidecalleridname:1;      /*!< Hide just the name not the number for legacy PBX use */
00280    unsigned int immediate:1;        /*!< Answer before getting digits? */
00281    unsigned int priexclusive:1;        /*!< Whether or not to override and use exculsive mode for channel selection */
00282    unsigned int priindication_oob:1;
00283    unsigned int use_callerid:1;        /*!< Whether or not to use caller id on this channel */
00284    unsigned int use_callingpres:1;        /*!< Whether to use the callingpres the calling switch sends */
00285    char context[AST_MAX_CONTEXT];
00286    char mohinterpret[MAX_MUSICCLASS];
00287    int stripmsd;
00288    int channel;               /*!< Channel Number or CRV */
00289 
00290    /* Options to be checked by user */
00291    int cid_ani2;                 /*!< Automatic Number Identification number (Alternate PRI caller ID number) */
00292    int cid_ton;               /*!< Type Of Number (TON) */
00293    int callingpres;           /*!< The value of calling presentation that we're going to use when placing a PRI call */
00294    char cid_num[AST_MAX_EXTENSION];
00295    char cid_subaddr[AST_MAX_EXTENSION];
00296    char cid_name[AST_MAX_EXTENSION];
00297    char cid_ani[AST_MAX_EXTENSION];
00298    /*! \brief User tag for party id's sent from this device driver. */
00299    char user_tag[AST_MAX_EXTENSION];
00300    char exten[AST_MAX_EXTENSION];
00301 
00302    /* Internal variables -- Don't touch */
00303    /* Probably will need DS0 number, DS1 number, and a few other things */
00304    char dialdest[256];           /* Queued up digits for overlap dialing.  They will be sent out as information messages when setup ACK is received */
00305 #if defined(HAVE_PRI_SETUP_KEYPAD)
00306    /*! \brief Keypad digits that came in with the SETUP message. */
00307    char keypad_digits[AST_MAX_EXTENSION];
00308 #endif   /* defined(HAVE_PRI_SETUP_KEYPAD) */
00309    /*! 'w' deferred dialing digits. */
00310    char deferred_digits[AST_MAX_EXTENSION];
00311    /*! Music class suggested with AST_CONTROL_HOLD. */
00312    char moh_suggested[MAX_MUSICCLASS];
00313    enum sig_pri_moh_state moh_state;
00314 
00315 #if defined(HAVE_PRI_AOC_EVENTS)
00316    struct pri_subcmd_aoc_e aoc_e;
00317    int aoc_s_request_invoke_id;     /*!< If an AOC-S request was present for the call, this is the invoke_id to use for the response */
00318    unsigned int aoc_s_request_invoke_id_valid:1; /*!< This is set when the AOC-S invoke id is present */
00319    unsigned int waiting_for_aoce:1; /*!< Delaying hangup for AOC-E msg. If this is set and AOC-E is received, continue with hangup before timeout period. */
00320    unsigned int holding_aoce:1;     /*!< received AOC-E msg from asterisk. holding for disconnect/release */
00321 #endif   /* defined(HAVE_PRI_AOC_EVENTS) */
00322    unsigned int inalarm:1;
00323    unsigned int alreadyhungup:1; /*!< TRUE if the call has already gone/hungup */
00324    unsigned int isidlecall:1;    /*!< TRUE if this is an idle call */
00325    unsigned int progress:1;      /*!< TRUE if the call has seen inband-information progress through the network */
00326 
00327    /*!
00328     * \brief TRUE when this channel is allocated.
00329     *
00330     * \details
00331     * Needed to hold an outgoing channel allocation before the
00332     * owner pointer is created.
00333     *
00334     * \note This is one of several items to check to see if a
00335     * channel is available for use.
00336     */
00337    unsigned int allocated:1;
00338    unsigned int outgoing:1;
00339    unsigned int digital:1;
00340    /*! \brief TRUE if this interface has no B channel.  (call hold and call waiting) */
00341    unsigned int no_b_channel:1;
00342 #if defined(HAVE_PRI_CALL_WAITING)
00343    /*! \brief TRUE if this is a call waiting call */
00344    unsigned int is_call_waiting:1;
00345 #endif   /* defined(HAVE_PRI_CALL_WAITING) */
00346 
00347    struct ast_channel *owner;
00348 
00349    struct sig_pri_span *pri;
00350    q931_call *call;           /*!< opaque libpri call control structure */
00351 
00352    /*! Call establishment life cycle level for simple comparisons. */
00353    enum sig_pri_call_level call_level;
00354    /*! \brief Channel reset/restart state. */
00355    enum sig_pri_reset_state resetting;
00356    int prioffset;             /*!< channel number in span */
00357    int logicalspan;           /*!< logical span number within trunk group */
00358    int mastertrunkgroup;         /*!< what trunk group is our master */
00359 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00360    /*! \brief Active SRVST_DBKEY out-of-service status value. */
00361    unsigned service_status;
00362 #endif   /* defined(HAVE_PRI_SERVICE_MESSAGES) */
00363 
00364    void *chan_pvt;               /*!< Private structure of the user of this module. */
00365 #if defined(HAVE_PRI_REVERSE_CHARGE)
00366    /*!
00367     * \brief Reverse charging indication
00368     * \details
00369     * -1 - No reverse charging,
00370     *  1 - Reverse charging,
00371     * 0,2-7 - Reserved for future use
00372     */
00373    int reverse_charging_indication;
00374 #endif
00375 };
00376 
00377 #if defined(HAVE_PRI_MWI)
00378 /*! Maximum number of mailboxes per span. */
00379 #define SIG_PRI_MAX_MWI_MAILBOXES         8
00380 /*! Typical maximum length of mwi voicemail controlling number */
00381 #define SIG_PRI_MAX_MWI_VM_NUMBER_LEN     10 /* digits in number */
00382 /*! Typical maximum length of mwi mailbox number */
00383 #define SIG_PRI_MAX_MWI_MBOX_NUMBER_LEN      10 /* digits in number */
00384 /*! Typical maximum length of mwi mailbox context */
00385 #define SIG_PRI_MAX_MWI_CONTEXT_LEN       10
00386 /*!
00387  * \brief Maximum mwi_vm_numbers string length.
00388  * \details
00389  * max_length = #mailboxes * (vm_number + ',')
00390  * The last ',' is a null terminator instead.
00391  */
00392 #define SIG_PRI_MAX_MWI_VM_NUMBER_STR  (SIG_PRI_MAX_MWI_MAILBOXES \
00393    * (SIG_PRI_MAX_MWI_VM_NUMBER_LEN + 1))
00394 /*!
00395  * \brief Maximum mwi_mailboxs string length.
00396  * \details
00397  * max_length = #mailboxes * (mbox_number + '@' + context + ',')
00398  * The last ',' is a null terminator instead.
00399  */
00400 #define SIG_PRI_MAX_MWI_MAILBOX_STR    (SIG_PRI_MAX_MWI_MAILBOXES \
00401    * (SIG_PRI_MAX_MWI_MBOX_NUMBER_LEN + 1 + SIG_PRI_MAX_MWI_CONTEXT_LEN + 1))
00402 
00403 struct sig_pri_mbox {
00404    /*!
00405     * \brief MWI mailbox event subscription.
00406     * \note NULL if mailbox not configured.
00407     */
00408    struct ast_event_sub *sub;
00409    /*! \brief Mailbox number */
00410    const char *number;
00411    /*! \brief Mailbox context. */
00412    const char *context;
00413    /*! \brief Voicemail controlling number. */
00414    const char *vm_number;
00415 };
00416 #endif   /* defined(HAVE_PRI_MWI) */
00417 
00418 enum sig_pri_colp_signaling {
00419    /*! Block all connected line updates. */
00420    SIG_PRI_COLP_BLOCK,
00421    /*! Only send connected line information with the CONNECT message. */
00422    SIG_PRI_COLP_CONNECT,
00423    /*! Allow all connected line updates. */
00424    SIG_PRI_COLP_UPDATE,
00425 };
00426 
00427 struct sig_pri_span {
00428    /* Should be set by user */
00429    struct ast_cc_config_params *cc_params;         /*!< CC config parameters for each new call. */
00430    int   pritimers[PRI_MAX_TIMERS];
00431    int overlapdial;                       /*!< In overlap dialing mode */
00432    int qsigchannelmapping;                   /*!< QSIG channel mapping type */
00433    int discardremoteholdretrieval;              /*!< shall remote hold or remote retrieval notifications be discarded? */
00434    int facilityenable;                       /*!< Enable facility IEs */
00435 #if defined(HAVE_PRI_L2_PERSISTENCE)
00436    /*! Layer 2 persistence option. */
00437    int l2_persistence;
00438 #endif   /* defined(HAVE_PRI_L2_PERSISTENCE) */
00439    int dchan_logical_span[SIG_PRI_NUM_DCHANS];     /*!< Logical offset the DCHAN sits in */
00440    int fds[SIG_PRI_NUM_DCHANS];              /*!< FD's for d-channels */
00441 
00442 #if defined(HAVE_PRI_AOC_EVENTS)
00443    int aoc_passthrough_flag;                 /*!< Represents what AOC messages (S,D,E) are allowed to pass-through */
00444    unsigned int aoce_delayhangup:1;          /*!< defines whether the aoce_delayhangup option is enabled or not */
00445 #endif   /* defined(HAVE_PRI_AOC_EVENTS) */
00446 
00447 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00448    unsigned int enable_service_message_support:1;  /*!< enable SERVICE message support */
00449 #endif   /* defined(HAVE_PRI_SERVICE_MESSAGES) */
00450 #ifdef HAVE_PRI_INBANDDISCONNECT
00451    unsigned int inbanddisconnect:1;          /*!< Should we support inband audio after receiving DISCONNECT? */
00452 #endif
00453 #if defined(HAVE_PRI_CALL_HOLD)
00454    /*! \brief TRUE if held calls are transferred on disconnect. */
00455    unsigned int hold_disconnect_transfer:1;
00456 #endif   /* defined(HAVE_PRI_CALL_HOLD) */
00457    /*!
00458     * \brief TRUE if call transfer is enabled for the span.
00459     * \note Support switch-side transfer (called 2BCT, RLT or other names)
00460     */
00461    unsigned int transfer:1;
00462 #if defined(HAVE_PRI_CALL_WAITING)
00463    /*! \brief TRUE if we will allow incoming ISDN call waiting calls. */
00464    unsigned int allow_call_waiting_calls:1;
00465 #endif   /* defined(HAVE_PRI_CALL_WAITING) */
00466    /*! TRUE if layer 1 alarm status is ignored */
00467    unsigned int layer1_ignored:1;
00468    /*!
00469     * TRUE if a new call's sig_pri_chan.user_tag[] has the MSN
00470     * appended to the initial_user_tag[].
00471     */
00472    unsigned int append_msn_to_user_tag:1;
00473    /*! TRUE if a PROCEEDING message needs to unsquelch the received audio. */
00474    unsigned int inband_on_proceeding:1;
00475 #if defined(HAVE_PRI_MCID)
00476    /*! \brief TRUE if allow sending MCID request on this span. */
00477    unsigned int mcid_send:1;
00478 #endif   /* defined(HAVE_PRI_MCID) */
00479 #if defined(HAVE_PRI_DATETIME_SEND)
00480    /*! \brief Configured date/time ie send policy option. */
00481    int datetime_send;
00482 #endif   /* defined(HAVE_PRI_DATETIME_SEND) */
00483    int dialplan;                    /*!< Dialing plan */
00484    int localdialplan;                  /*!< Local dialing plan */
00485    int cpndialplan;                 /*!< Connected party dialing plan */
00486    char internationalprefix[10];       /*!< country access code ('00' for european dialplans) */
00487    char nationalprefix[10];            /*!< area access code ('0' for european dialplans) */
00488    char localprefix[20];               /*!< area access code + area code ('0'+area code for european dialplans) */
00489    char privateprefix[20];             /*!< for private dialplans */
00490    char unknownprefix[20];             /*!< for unknown dialplans */
00491    enum sig_pri_moh_signaling moh_signaling;
00492    /*! Send connected line signaling to peer option. */
00493    enum sig_pri_colp_signaling colp_send;
00494    long resetinterval;                 /*!< Interval (in seconds) for resetting unused channels */
00495 #if defined(HAVE_PRI_DISPLAY_TEXT)
00496    unsigned long display_flags_send;      /*!< PRI_DISPLAY_OPTION_xxx flags for display text sending */
00497    unsigned long display_flags_receive;   /*!< PRI_DISPLAY_OPTION_xxx flags for display text receiving */
00498 #endif   /* defined(HAVE_PRI_DISPLAY_TEXT) */
00499 #if defined(HAVE_PRI_MWI)
00500    /*! \brief Active MWI mailboxes */
00501    struct sig_pri_mbox mbox[SIG_PRI_MAX_MWI_MAILBOXES];
00502    /*!
00503     * \brief Comma separated list of mailboxes to indicate MWI.
00504     * \note Empty if disabled.
00505     * \note Format: mailbox_number[@context]{,mailbox_number[@context]}
00506     * \note String is split apart when span is started.
00507     */
00508    char mwi_mailboxes[SIG_PRI_MAX_MWI_MAILBOX_STR];
00509    /*!
00510     * \brief Comma separated list of voicemail access controlling numbers for MWI.
00511     * \note Format: vm_number{,vm_number}
00512     * \note String is split apart when span is started.
00513     */
00514    char mwi_vm_numbers[SIG_PRI_MAX_MWI_VM_NUMBER_STR];
00515 #endif   /* defined(HAVE_PRI_MWI) */
00516    /*!
00517     * \brief Initial user tag for party id's sent from this device driver.
00518     * \note String set by config file.
00519     */
00520    char initial_user_tag[AST_MAX_EXTENSION];
00521    char msn_list[AST_MAX_EXTENSION];      /*!< Comma separated list of MSNs to handle.  Empty if disabled. */
00522    char idleext[AST_MAX_EXTENSION];    /*!< Where to idle extra calls */
00523    char idlecontext[AST_MAX_CONTEXT];     /*!< What context to use for idle */
00524    char idledial[AST_MAX_EXTENSION];      /*!< What to dial before dumping */
00525    int minunused;                   /*!< Min # of channels to keep empty */
00526    int minidle;                     /*!< Min # of "idling" calls to keep active */
00527    int nodetype;                    /*!< Node type */
00528    int switchtype;                     /*!< Type of switch to emulate */
00529    int nsf;                      /*!< Network-Specific Facilities */
00530    int trunkgroup;                     /*!< What our trunkgroup is */
00531 #if defined(HAVE_PRI_CCSS)
00532    int cc_ptmp_recall_mode;            /*!< CC PTMP recall mode. globalRecall(0), specificRecall(1) */
00533    int cc_qsig_signaling_link_req;        /*!< CC Q.SIG signaling link retention (Party A) release(0), retain(1), do-not-care(2) */
00534    int cc_qsig_signaling_link_rsp;        /*!< CC Q.SIG signaling link retention (Party B) release(0), retain(1) */
00535 #endif   /* defined(HAVE_PRI_CCSS) */
00536 #if defined(HAVE_PRI_CALL_WAITING)
00537    /*!
00538     * \brief Number of extra outgoing calls to allow on a span before
00539     * considering that span congested.
00540     */
00541    int max_call_waiting_calls;
00542    struct {
00543       int stripmsd;
00544       unsigned int hidecallerid:1;
00545       unsigned int hidecalleridname:1;      /*!< Hide just the name not the number for legacy PBX use */
00546       unsigned int immediate:1;        /*!< Answer before getting digits? */
00547       unsigned int priexclusive:1;        /*!< Whether or not to override and use exculsive mode for channel selection */
00548       unsigned int priindication_oob:1;
00549       unsigned int use_callerid:1;        /*!< Whether or not to use caller id on this channel */
00550       unsigned int use_callingpres:1;        /*!< Whether to use the callingpres the calling switch sends */
00551       char context[AST_MAX_CONTEXT];
00552       char mohinterpret[MAX_MUSICCLASS];
00553    } ch_cfg;
00554 
00555    /*!
00556     * \brief Number of outstanding call waiting calls.
00557     * \note Must be zero to allow new calls from asterisk to
00558     * immediately allocate a B channel.
00559     */
00560    int num_call_waiting_calls;
00561 #endif   /* defined(HAVE_PRI_CALL_WAITING) */
00562    int dchanavail[SIG_PRI_NUM_DCHANS];    /*!< Whether each channel is available */
00563    int debug;                       /*!< set to true if to dump PRI event info */
00564    int span;                        /*!< span number put into user output messages */
00565    int resetting;                   /*!< true if span is being reset/restarted */
00566    int resetpos;                    /*!< current position during a reset (-1 if not started) */
00567    int sig;                      /*!< ISDN signalling type (SIG_PRI, SIG_BRI, SIG_BRI_PTMP, etc...) */
00568    int new_chan_seq;                /*!< New struct ast_channel sequence number */
00569    /*! TRUE if we have already whined about no D channels available. */
00570    unsigned int no_d_channels:1;
00571 
00572    /* Everything after here is internally set */
00573    struct pri *dchans[SIG_PRI_NUM_DCHANS];      /*!< Actual d-channels */
00574    struct pri *pri;                    /*!< Currently active D-channel */
00575    /*!
00576     * List of private structures of the user of this module for no B channel
00577     * interfaces. (hold and call waiting interfaces)
00578     */
00579    void *no_b_chan_iflist;
00580    /*!
00581     * List of private structures of the user of this module for no B channel
00582     * interfaces. (hold and call waiting interfaces)
00583     */
00584    void *no_b_chan_end;
00585    int numchans;                       /*!< Num of channels we represent */
00586    struct sig_pri_chan *pvts[SIG_PRI_MAX_CHANNELS];/*!< Member channel pvt structs */
00587    pthread_t master;                   /*!< Thread of master */
00588    ast_mutex_t lock;                   /*!< libpri access Mutex */
00589    time_t lastreset;                   /*!< time when unused channels were last reset */
00590    /*!
00591     * \brief Congestion device state of the span.
00592     * \details
00593     * AST_DEVICE_NOT_INUSE - Span does not have all B channels in use.
00594     * AST_DEVICE_BUSY - All B channels are in use.
00595     * AST_DEVICE_UNAVAILABLE - Span is in alarm.
00596     * \note
00597     * Device name: \startverbatim DAHDI/I<span>/congestion. \endverbatim
00598     */
00599    int congestion_devstate;
00600 #if defined(THRESHOLD_DEVSTATE_PLACEHOLDER)
00601    /*! \todo An ISDN span threshold device state could be useful in determining how often a span utilization goes over a configurable threshold. */
00602    /*!
00603     * \brief User threshold device state of the span.
00604     * \details
00605     * AST_DEVICE_NOT_INUSE - There are no B channels in use.
00606     * AST_DEVICE_INUSE - The number of B channels in use is less than
00607     *    the configured threshold but not zero.
00608     * AST_DEVICE_BUSY - The number of B channels in use meets or exceeds
00609     *    the configured threshold.
00610     * AST_DEVICE_UNAVAILABLE - Span is in alarm.
00611     * \note
00612     * Device name:  DAHDI/I<span>/threshold
00613     */
00614    int threshold_devstate;
00615    /*!
00616     * \brief Number of B channels in use to consider the span in a busy state.
00617     * \note Setting the threshold to zero is interpreted as all B channels.
00618     */
00619    int user_busy_threshold;
00620 #endif   /* defined(THRESHOLD_DEVSTATE_PLACEHOLDER) */
00621 };
00622 
00623 void sig_pri_extract_called_num_subaddr(struct sig_pri_chan *p, const char *rdest, char *called, size_t called_buff_size);
00624 int sig_pri_call(struct sig_pri_chan *p, struct ast_channel *ast, const char *rdest, int timeout, int layer1);
00625 
00626 int sig_pri_hangup(struct sig_pri_chan *p, struct ast_channel *ast);
00627 
00628 int sig_pri_indicate(struct sig_pri_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen);
00629 
00630 int sig_pri_answer(struct sig_pri_chan *p, struct ast_channel *ast);
00631 
00632 int sig_pri_is_chan_available(struct sig_pri_chan *pvt);
00633 int sig_pri_available(struct sig_pri_chan **pvt, int is_specific_channel);
00634 
00635 void sig_pri_init_pri(struct sig_pri_span *pri);
00636 
00637 /* If return 0, it means this function was able to handle it (pre setup digits).  If non zero, the user of this
00638  * functions should handle it normally (generate inband DTMF) */
00639 int sig_pri_digit_begin(struct sig_pri_chan *pvt, struct ast_channel *ast, char digit);
00640 void sig_pri_dial_complete(struct sig_pri_chan *pvt, struct ast_channel *ast);
00641 
00642 void sig_pri_stop_pri(struct sig_pri_span *pri);
00643 int sig_pri_start_pri(struct sig_pri_span *pri);
00644 
00645 void sig_pri_set_alarm(struct sig_pri_chan *p, int in_alarm);
00646 void sig_pri_chan_alarm_notify(struct sig_pri_chan *p, int noalarm);
00647 
00648 int sig_pri_is_alarm_ignored(struct sig_pri_span *pri);
00649 void pri_event_alarm(struct sig_pri_span *pri, int index, int before_start_pri);
00650 void pri_event_noalarm(struct sig_pri_span *pri, int index, int before_start_pri);
00651 
00652 struct ast_channel *sig_pri_request(struct sig_pri_chan *p, enum sig_pri_law law, const struct ast_channel *requestor, int transfercapability);
00653 
00654 struct sig_pri_chan *sig_pri_chan_new(void *pvt_data, struct sig_pri_span *pri, int logicalspan, int channo, int trunkgroup);
00655 void sig_pri_chan_delete(struct sig_pri_chan *doomed);
00656 
00657 int pri_is_up(struct sig_pri_span *pri);
00658 
00659 struct mansession;
00660 int sig_pri_ami_show_spans(struct mansession *s, const char *show_cmd, struct sig_pri_span *pri, const int *dchannels, const char *action_id);
00661 
00662 void sig_pri_cli_show_channels_header(int fd);
00663 void sig_pri_cli_show_channels(int fd, struct sig_pri_span *pri);
00664 void sig_pri_cli_show_spans(int fd, int span, struct sig_pri_span *pri);
00665 
00666 void sig_pri_cli_show_span(int fd, int *dchannels, struct sig_pri_span *pri);
00667 
00668 int pri_send_keypad_facility_exec(struct sig_pri_chan *p, const char *digits);
00669 int pri_send_callrerouting_facility_exec(struct sig_pri_chan *p, enum ast_channel_state chanstate, const char *destination, const char *original, const char *reason);
00670 
00671 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00672 int pri_maintenance_bservice(struct pri *pri, struct sig_pri_chan *p, int changestatus);
00673 #endif   /* defined(HAVE_PRI_SERVICE_MESSAGES) */
00674 
00675 void sig_pri_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_pri_chan *pchan);
00676 #if defined(HAVE_PRI_DISPLAY_TEXT)
00677 void sig_pri_sendtext(struct sig_pri_chan *pchan, const char *text);
00678 #endif   /* defined(HAVE_PRI_DISPLAY_TEXT) */
00679 
00680 int sig_pri_cc_agent_init(struct ast_cc_agent *agent, struct sig_pri_chan *pvt_chan);
00681 int sig_pri_cc_agent_start_offer_timer(struct ast_cc_agent *agent);
00682 int sig_pri_cc_agent_stop_offer_timer(struct ast_cc_agent *agent);
00683 void sig_pri_cc_agent_req_rsp(struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason);
00684 int sig_pri_cc_agent_status_req(struct ast_cc_agent *agent);
00685 int sig_pri_cc_agent_stop_ringing(struct ast_cc_agent *agent);
00686 int sig_pri_cc_agent_party_b_free(struct ast_cc_agent *agent);
00687 int sig_pri_cc_agent_start_monitoring(struct ast_cc_agent *agent);
00688 int sig_pri_cc_agent_callee_available(struct ast_cc_agent *agent);
00689 void sig_pri_cc_agent_destructor(struct ast_cc_agent *agent);
00690 
00691 int sig_pri_cc_monitor_req_cc(struct ast_cc_monitor *monitor, int *available_timer_id);
00692 int sig_pri_cc_monitor_suspend(struct ast_cc_monitor *monitor);
00693 int sig_pri_cc_monitor_unsuspend(struct ast_cc_monitor *monitor);
00694 int sig_pri_cc_monitor_status_rsp(struct ast_cc_monitor *monitor, enum ast_device_state devstate);
00695 int sig_pri_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, int *sched_id);
00696 void sig_pri_cc_monitor_destructor(void *monitor_pvt);
00697 
00698 int sig_pri_load(const char *cc_type_name);
00699 void sig_pri_unload(void);
00700 
00701 #endif /* _SIG_PRI_H */