Wed Aug 11 01:07:03 2010

Asterisk developer's documentation


chan_dahdi.c File Reference

DAHDI for Pseudo TDM. More...

#include "asterisk.h"
#include <sys/signal.h>
#include <sys/ioctl.h>
#include <math.h>
#include <ctype.h>
#include <dahdi/user.h>
#include <dahdi/tonezone.h>
#include <libpri.h>
#include <libss7.h>
#include <openr2.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/file.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
#include "asterisk/adsi.h"
#include "asterisk/cli.h"
#include "asterisk/cdr.h"
#include "asterisk/features.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/tdd.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/astdb.h"
#include "asterisk/manager.h"
#include "asterisk/causes.h"
#include "asterisk/term.h"
#include "asterisk/utils.h"
#include "asterisk/transcap.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/smdi.h"
#include "asterisk/astobj.h"
#include "asterisk/event.h"
#include "asterisk/devicestate.h"
#include "asterisk/paths.h"

Include dependency graph for chan_dahdi.c:

Go to the source code of this file.

Data Structures

struct  dahdi_chan_conf
 Channel configuration from chan_dahdi.conf . This struct is used for parsing the [channels] section of chan_dahdi.conf. Generally there is a field here for every possible configuration item. More...
struct  dahdi_distRings
struct  dahdi_mfcr2
struct  dahdi_mfcr2_conf
struct  dahdi_pri
struct  dahdi_pvt
struct  dahdi_ss7
struct  dahdi_subchannel
struct  distRingData
struct  mwi_thread_data
struct  mwisend_info
struct  ringContextData

Defines

#define ASCII_BYTES_PER_CHAR   80
#define AST_LAW(p)   (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
#define CALLPROGRESS_FAX   (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
#define CALLPROGRESS_FAX_INCOMING   4
#define CALLPROGRESS_FAX_OUTGOING   2
#define CALLPROGRESS_PROGRESS   1
#define CALLWAITING_REPEAT_SAMPLES   ( (10000 * 8) / READ_SIZE)
#define CALLWAITING_SILENT_SAMPLES   ( (300 * 8) / READ_SIZE)
#define CANBUSYDETECT(p)   (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
#define CANPROGRESSDETECT(p)   (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
#define CHAN_PSEUDO   -2
#define CHAN_TAG   "Chan "
#define CHANNEL_PSEUDO   -12
#define CIDCW_EXPIRE_SAMPLES   ( (500 * 8) / READ_SIZE)
#define CONF_USER_REAL   (1 << 0)
#define CONF_USER_THIRDCALL   (1 << 1)
#define CONTEXT_TAG   "Context - "
#define DAHDI_CHAN_MAPPING_LOGICAL   1
#define DAHDI_CHAN_MAPPING_PHYSICAL   0
#define DAHDI_OVERLAPDIAL_BOTH   (DAHDI_OVERLAPDIAL_INCOMING|DAHDI_OVERLAPDIAL_OUTGOING)
#define DAHDI_OVERLAPDIAL_INCOMING   2
#define DAHDI_OVERLAPDIAL_NONE   0
#define DAHDI_OVERLAPDIAL_OUTGOING   1
#define DCHAN_AVAILABLE   (DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
#define DCHAN_NOTINALARM   (1 << 1)
#define DCHAN_PROVISIONED   (1 << 0)
#define DCHAN_UP   (1 << 2)
#define DEFAULT_CIDRINGS   1
 Typically, how many rings before we should send Caller*ID.
#define DEFAULT_PRI_DEBUG   0
#define DEFAULT_RINGT   ( (8000 * 8) / READ_SIZE)
#define END_SILENCE_LEN   400
#define FORMAT   "%-40.40s %-7.7s %-6d %-6d %-6d %-3.3s %-4.4s %-8.8s %s\n"
#define FORMAT   "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
#define FORMAT   "%4s %-7.7s %-7.7s %-8.8s %-9.9s %-16.16s %-8.8s %-8.8s\n"
#define FORMAT   "%4s %40s\n"
#define FORMAT2   "%-40.40s %-7.7s %-6.6s %-6.6s %-6.6s %-3.3s %-4.4s %-8.8s %s\n"
#define FORMAT2   "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
#define GET_CHANNEL(p)   ((p)->bearer ? (p)->bearer->channel : p->channel)
#define HANGUP   1
#define HEADER_LEN   ((HEADER_MS + TRAILER_MS) * 8)
#define HEADER_MS   50
#define ISTRUNK(p)
#define LINKSET_FLAG_EXPLICITACM   (1 << 0)
#define LINKSTATE_DOWN   (1 << 3)
#define LINKSTATE_INALARM   (1 << 0)
#define LINKSTATE_STARTING   (1 << 1)
#define LINKSTATE_UP   (1 << 2)
#define MASK_AVAIL   (1 << 0)
#define MASK_INUSE   (1 << 1)
#define MAX_CHANLIST_LEN   80
#define MAX_CHANNELS   672
#define MAX_SLAVES   4
#define MIN_MS_SINCE_FLASH   ( (2000) )
#define NEED_MFDETECT(p)   (((p)->sig == SIG_FEATDMF) || ((p)->sig == SIG_FEATDMF_TA) || ((p)->sig == SIG_E911) || ((p)->sig == SIG_FGC_CAMA) || ((p)->sig == SIG_FGC_CAMAMF) || ((p)->sig == SIG_FEATB))
 Signaling types that need to use MF detection should be placed in this macro.
#define NUM_CADENCE_MAX   25
#define NUM_DCHANS   4
#define NUM_SPANS   32
#define POLARITY_IDLE   0
#define POLARITY_REV   1
#define PRI_CHANNEL(p)   ((p) & 0xff)
#define PRI_EXPLICIT(p)   (((p) >> 16) & 0x01)
#define PRI_SPAN(p)   (((p) >> 8) & 0xff)
#define PROC_DAHDI_OPT_NOCHAN   (1 << 0)
#define PROC_DAHDI_OPT_NOWARN   (1 << 1)
#define PVT_TO_CHANNEL(p)   (((p)->prioffset) | ((p)->logicalspan << 8) | (p->pri->mastertrunkgroup ? 0x10000 : 0))
#define R2_LINK_CAPACITY   10
#define READ_SIZE   160
#define sig2str   dahdi_sig2str
#define SIG_BRI   (0x2000000 | DAHDI_SIG_CLEAR)
#define SIG_BRI_PTMP   (0X4000000 | DAHDI_SIG_CLEAR)
#define SIG_E911   (0x1000000 | DAHDI_SIG_EM)
#define SIG_EM   DAHDI_SIG_EM
#define SIG_EM_E1   DAHDI_SIG_EM_E1
#define SIG_EMWINK   (0x0100000 | DAHDI_SIG_EM)
#define SIG_FEATB   (0x0800000 | DAHDI_SIG_EM)
#define SIG_FEATD   (0x0200000 | DAHDI_SIG_EM)
#define SIG_FEATDMF   (0x0400000 | DAHDI_SIG_EM)
#define SIG_FEATDMF_TA   (0x2000000 | DAHDI_SIG_EM)
#define SIG_FGC_CAMA   (0x4000000 | DAHDI_SIG_EM)
#define SIG_FGC_CAMAMF   (0x8000000 | DAHDI_SIG_EM)
#define SIG_FXOGS   DAHDI_SIG_FXOGS
#define SIG_FXOKS   DAHDI_SIG_FXOKS
#define SIG_FXOLS   DAHDI_SIG_FXOLS
#define SIG_FXSGS   DAHDI_SIG_FXSGS
#define SIG_FXSKS   DAHDI_SIG_FXSKS
#define SIG_FXSLS   DAHDI_SIG_FXSLS
#define SIG_GR303FXOKS   (0x0100000 | DAHDI_SIG_FXOKS)
#define SIG_GR303FXSKS   (0x0100000 | DAHDI_SIG_FXSKS)
#define SIG_MFCR2   DAHDI_SIG_CAS
#define SIG_PRI   DAHDI_SIG_CLEAR
#define SIG_SF   DAHDI_SIG_SF
#define SIG_SF_FEATB   (0x0800000 | DAHDI_SIG_SF)
#define SIG_SF_FEATD   (0x0200000 | DAHDI_SIG_SF)
#define SIG_SF_FEATDMF   (0x0400000 | DAHDI_SIG_SF)
#define SIG_SFWINK   (0x0100000 | DAHDI_SIG_SF)
#define SIG_SS7   (0x1000000 | DAHDI_SIG_CLEAR)
#define SMDI_MD_WAIT_TIMEOUT   1500
#define SS7_NAI_DYNAMIC   -1
#define SUB_CALLWAIT   1
#define SUB_REAL   0
#define SUB_THREEWAY   2
#define TRAILER_MS   5
#define TRANSFER   0

Enumerations

enum  mwisend_states {
  MWI_SEND_NULL = 0, MWI_SEND_SA, MWI_SEND_SA_WAIT, MWI_SEND_PAUSE,
  MWI_SEND_SPILL, MWI_SEND_CLEANUP, MWI_SEND_DONE
}

Functions

static struct ast_frame * __dahdi_exception (struct ast_channel *ast)
static void __reg_module (void)
static int __unload_module (void)
static void __unreg_module (void)
static int action_dahdidialoffhook (struct mansession *s, const struct message *m)
static int action_dahdidndoff (struct mansession *s, const struct message *m)
static int action_dahdidndon (struct mansession *s, const struct message *m)
static int action_dahdirestart (struct mansession *s, const struct message *m)
static int action_dahdishowchannels (struct mansession *s, const struct message *m)
static int action_transfer (struct mansession *s, const struct message *m)
static int action_transferhangup (struct mansession *s, const struct message *m)
static char * alarm2str (int alm)
static int alloc_sub (struct dahdi_pvt *p, int x)
static void apply_plan_to_number (char *buf, size_t size, const struct dahdi_pri *pri, const char *number, const int plan)
static int attempt_transfer (struct dahdi_pvt *p)
static int available (struct dahdi_pvt *p, int channelmatch, ast_group_t groupmatch, int *busy, int *channelmatched, int *groupmatched)
static int build_channels (struct dahdi_chan_conf *conf, int iscrv, const char *value, int reload, int lineno, int *found_pseudo)
static void build_status (char *s, size_t len, int status, int active)
static int bump_gains (struct dahdi_pvt *p)
static int calc_energy (const unsigned char *buf, int len, int law)
static int check_for_conference (struct dahdi_pvt *p)
static unsigned char cid_pres2ss7pres (int cid_pres)
static unsigned char cid_pres2ss7screen (int cid_pres)
static char * complete_span_4 (const char *line, const char *word, int pos, int state)
static char * complete_span_helper (const char *line, const char *word, int pos, int state, int rpos)
static int conf_add (struct dahdi_pvt *p, struct dahdi_subchannel *c, int idx, int slavechannel)
static int conf_del (struct dahdi_pvt *p, struct dahdi_subchannel *c, int idx)
static int dahdi_accept_r2_call_exec (struct ast_channel *chan, void *data)
static int dahdi_answer (struct ast_channel *ast)
static
openr2_call_disconnect_cause_t 
dahdi_ast_cause_to_r2_cause (int cause)
static enum ast_bridge_result dahdi_bridge (struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
static int dahdi_call (struct ast_channel *ast, char *rdest, int timeout)
static int dahdi_callwait (struct ast_channel *ast)
static struct dahdi_chan_conf dahdi_chan_conf_default (void)
static void dahdi_close (int fd)
static void dahdi_close_pri_fd (struct dahdi_pri *pri, int fd_num)
static void dahdi_close_ss7_fd (struct dahdi_ss7 *ss7, int fd_num)
static void dahdi_close_sub (struct dahdi_pvt *chan_pvt, int sub_num)
static int dahdi_confmute (struct dahdi_pvt *p, int muted)
static char * dahdi_destroy_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int dahdi_destroy_channel_bynum (int channel)
static int dahdi_digit_begin (struct ast_channel *ast, char digit)
static int dahdi_digit_end (struct ast_channel *ast, char digit, unsigned int duration)
static void dahdi_disable_ec (struct dahdi_pvt *p)
static void dahdi_dnd (struct dahdi_pvt *dahdichan, int on)
 enable or disable the chan_dahdi Do-Not-Disturb mode for a DAHDI channel
static void dahdi_enable_ec (struct dahdi_pvt *p)
static struct ast_frame * dahdi_exception (struct ast_channel *ast)
static int dahdi_fake_event (struct dahdi_pvt *p, int mode)
static int dahdi_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
static int dahdi_func_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
static int dahdi_func_write (struct ast_channel *chan, const char *function, char *data, const char *value)
static int dahdi_get_event (int fd)
 Avoid the silly dahdi_getevent which ignores a bunch of events.
static int dahdi_get_index (struct ast_channel *ast, struct dahdi_pvt *p, int nullok)
static void dahdi_handle_dtmfup (struct ast_channel *ast, int idx, struct ast_frame **dest)
static struct ast_frame * dahdi_handle_event (struct ast_channel *ast)
static int dahdi_hangup (struct ast_channel *ast)
static int dahdi_indicate (struct ast_channel *chan, int condition, const void *data, size_t datalen)
static void dahdi_link (struct dahdi_pvt *slave, struct dahdi_pvt *master)
static void dahdi_loopback (struct dahdi_pvt *p, int enable)
static struct ast_channel * dahdi_new (struct dahdi_pvt *, int, int, int, int, int)
static int dahdi_open (char *fn)
static void dahdi_pri_error (struct pri *pri, char *s)
static void dahdi_pri_message (struct pri *pri, char *s)
static void dahdi_queue_frame (struct dahdi_pvt *p, struct ast_frame *f, void *data)
static int16_t dahdi_r2_alaw_to_linear (uint8_t sample)
static int dahdi_r2_answer (struct dahdi_pvt *p)
static int dahdi_r2_cause_to_ast_cause (openr2_call_disconnect_cause_t cause)
static void dahdi_r2_destroy_links (void)
static void dahdi_r2_disconnect_call (struct dahdi_pvt *p, openr2_call_disconnect_cause_t cause)
static
openr2_calling_party_category_t 
dahdi_r2_get_channel_category (struct ast_channel *c)
static struct dahdi_mfcr2 * dahdi_r2_get_link (void)
static uint8_t dahdi_r2_linear_to_alaw (int sample)
static void dahdi_r2_on_ani_digit_received (openr2_chan_t *r2chan, char digit)
static void dahdi_r2_on_billing_pulse_received (openr2_chan_t *r2chan)
static void dahdi_r2_on_call_accepted (openr2_chan_t *r2chan, openr2_call_mode_t mode)
static void dahdi_r2_on_call_answered (openr2_chan_t *r2chan)
static void dahdi_r2_on_call_disconnect (openr2_chan_t *r2chan, openr2_call_disconnect_cause_t cause)
static void dahdi_r2_on_call_end (openr2_chan_t *r2chan)
static void dahdi_r2_on_call_init (openr2_chan_t *r2chan)
static void dahdi_r2_on_call_offered (openr2_chan_t *r2chan, const char *ani, const char *dnis, openr2_calling_party_category_t category)
static void dahdi_r2_on_call_read (openr2_chan_t *r2chan, const unsigned char *buf, int buflen)
static void dahdi_r2_on_chan_log (openr2_chan_t *r2chan, openr2_log_level_t level, const char *fmt, va_list ap)
static void dahdi_r2_on_context_log (openr2_context_t *r2context, openr2_log_level_t level, const char *fmt, va_list ap)
static int dahdi_r2_on_dnis_digit_received (openr2_chan_t *r2chan, char digit)
static void dahdi_r2_on_hardware_alarm (openr2_chan_t *r2chan, int alarm)
static void dahdi_r2_on_line_blocked (openr2_chan_t *r2chan)
static void dahdi_r2_on_line_idle (openr2_chan_t *r2chan)
static void dahdi_r2_on_os_error (openr2_chan_t *r2chan, int errorcode)
static void dahdi_r2_on_protocol_error (openr2_chan_t *r2chan, openr2_protocol_error_t reason)
static int dahdi_r2_set_context (struct dahdi_mfcr2 *r2_link, const struct dahdi_chan_conf *conf)
static void dahdi_r2_write_log (openr2_log_level_t level, char *logmessage)
static struct ast_frame * dahdi_read (struct ast_channel *ast)
static struct ast_channel * dahdi_request (const char *type, int format, void *data, int *cause)
static int dahdi_restart (void)
static char * dahdi_restart_cmd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int dahdi_ring_phone (struct dahdi_pvt *p)
static int dahdi_send_keypad_facility_exec (struct ast_channel *chan, void *data)
static int dahdi_sendtext (struct ast_channel *c, const char *text)
static char * dahdi_set_dnd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int dahdi_set_hook (int fd, int hs)
static char * dahdi_set_hwgain (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * dahdi_set_swgain (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int dahdi_setlaw (int dfd, int law)
static int dahdi_setlinear (int dfd, int linear)
static int dahdi_setoption (struct ast_channel *chan, int option, void *data, int datalen)
static char * dahdi_show_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * dahdi_show_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * dahdi_show_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * dahdi_show_version (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * dahdi_sig2str (int sig)
static void dahdi_softhangup_all (void)
static void dahdi_ss7_error (struct ss7 *ss7, char *s)
static void dahdi_ss7_message (struct ss7 *ss7, char *s)
static void dahdi_train_ec (struct dahdi_pvt *p)
static void dahdi_unlink (struct dahdi_pvt *slave, struct dahdi_pvt *master, int needlock)
static int dahdi_wait_event (int fd)
 Avoid the silly dahdi_waitevent which ignores a bunch of events.
static int dahdi_wink (struct dahdi_pvt *p, int idx)
static int dahdi_write (struct ast_channel *ast, struct ast_frame *frame)
static void destroy_all_channels (void)
static int destroy_channel (struct dahdi_pvt *prev, struct dahdi_pvt *cur, int now)
static void destroy_dahdi_pvt (struct dahdi_pvt **pvt)
static char * dialplan2str (int dialplan)
static int digit_to_dtmfindex (char digit)
static void disable_dtmf_detect (struct dahdi_pvt *p)
static void * do_idle_thread (void *vchan)
static void * do_monitor (void *data)
static struct dahdi_pvt * duplicate_pseudo (struct dahdi_pvt *src)
static void enable_dtmf_detect (struct dahdi_pvt *p)
static char * event2str (int event)
static void fill_rxgain (struct dahdi_gains *g, float gain, int law)
static void fill_txgain (struct dahdi_gains *g, float gain, int law)
static struct dahdi_pvt * find_channel (int channel)
static int get_alarms (struct dahdi_pvt *p)
static void handle_alarms (struct dahdi_pvt *p, int alms)
static char * handle_dahdi_show_cadences (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct dahdi_pvt * handle_init_event (struct dahdi_pvt *i, int event)
static char * handle_mfcr2_call_files (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_mfcr2_set_blocked (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_mfcr2_set_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_mfcr2_set_idle (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_mfcr2_show_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_mfcr2_show_variants (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_mfcr2_version (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_pri_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_pri_set_debug_file (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_pri_show_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_pri_show_span (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_pri_show_spans (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_pri_version (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_ss7_block_cic (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_ss7_block_linkset (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_ss7_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_ss7_show_linkset (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_ss7_unblock_cic (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_ss7_unblock_linkset (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_ss7_version (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int has_voicemail (struct dahdi_pvt *p)
static int isourconf (struct dahdi_pvt *p, struct dahdi_subchannel *c)
static int isslavenative (struct dahdi_pvt *p, struct dahdi_pvt **out)
static int linkset_addsigchan (int sigchan)
static int load_module (void)
static void * mfcr2_monitor (void *data)
static struct dahdi_pvt * mkintf (int channel, const struct dahdi_chan_conf *conf, struct dahdi_pri *pri, int reloading)
static void mwi_event_cb (const struct ast_event *event, void *userdata)
static int mwi_send_init (struct dahdi_pvt *pvt)
static int mwi_send_process_buffer (struct dahdi_pvt *pvt, int num_read)
static int mwi_send_process_event (struct dahdi_pvt *pvt, int event)
static void * mwi_thread (void *data)
static int my_dahdi_write (struct dahdi_pvt *p, unsigned char *buf, int len, int idx, int linear)
static int my_getsigstr (struct ast_channel *chan, char *str, const char *term, int ms)
static void notify_message (char *mailbox_full, int thereornot)
 Send MWI state change.
static int parse_buffers_policy (const char *parse, int *num_buffers, int *policy)
static unsigned int parse_pointcode (const char *pcstring)
static int pri_active_dchan_fd (struct dahdi_pri *pri)
static int pri_assign_bearer (struct dahdi_pvt *crv, struct dahdi_pri *pri, struct dahdi_pvt *bearer)
static int pri_check_restart (struct dahdi_pri *pri)
static int pri_create_spanmap (int span, int trunkgroup, int logicalspan)
static int pri_create_trunkgroup (int trunkgroup, int *channels)
static void * pri_dchannel (void *vpri)
static struct dahdi_pvt * pri_find_crv (struct dahdi_pri *pri, int crv)
static int pri_find_dchan (struct dahdi_pri *pri)
static int pri_find_empty_chan (struct dahdi_pri *pri, int backwards)
static int pri_find_principle (struct dahdi_pri *pri, int channel)
static int pri_fixup_principle (struct dahdi_pri *pri, int principle, q931_call *c)
static int pri_grab (struct dahdi_pvt *pvt, struct dahdi_pri *pri)
static int pri_hangup_all (struct dahdi_pvt *p, struct dahdi_pri *pri)
static int pri_is_up (struct dahdi_pri *pri)
static char * pri_order (int level)
static void pri_rel (struct dahdi_pri *pri)
static int pri_resolve_span (int *span, int channel, int offset, struct dahdi_spaninfo *si)
static int process_dahdi (struct dahdi_chan_conf *confp, const char *cat, struct ast_variable *v, int reload, int options)
static void process_echocancel (struct dahdi_chan_conf *confp, const char *data, unsigned int line)
static char * redirectingreason2str (int redirectingreason)
static int reload (void)
static int reset_conf (struct dahdi_pvt *p)
static int restart_monitor (void)
static int restore_conference (struct dahdi_pvt *p)
static int restore_gains (struct dahdi_pvt *p)
static int save_conference (struct dahdi_pvt *p)
static int send_callerid (struct dahdi_pvt *p)
static int send_cwcidspill (struct dahdi_pvt *p)
static int set_actual_gain (int fd, int chan, float rxgain, float txgain, int law)
static int set_actual_rxgain (int fd, int chan, float gain, int law)
static int set_actual_txgain (int fd, int chan, float gain, int law)
static int setup_dahdi (int reload)
static int sigtype_to_signalling (int sigtype)
static void ss7_apply_plan_to_number (char *buf, size_t size, const struct dahdi_ss7 *ss7, const char *number, const unsigned nai)
static void ss7_block_cics (struct dahdi_ss7 *linkset, int startcic, int endcic, unsigned int dpc, unsigned char state[], int block)
static int ss7_find_cic (struct dahdi_ss7 *linkset, int cic, unsigned int dpc)
static int ss7_grab (struct dahdi_pvt *pvt, struct dahdi_ss7 *pri)
static void ss7_handle_cqm (struct dahdi_ss7 *linkset, int startcic, int endcic, unsigned int dpc)
static void ss7_hangup_cics (struct dahdi_ss7 *linkset, int startcic, int endcic, unsigned int dpc)
static void ss7_inservice (struct dahdi_ss7 *linkset, int startcic, int endcic, unsigned int dpc)
static void * ss7_linkset (void *data)
static int ss7_pres_scr2cid_pres (char presentation_ind, char screening_ind)
static void ss7_rel (struct dahdi_ss7 *ss7)
static void ss7_reset_linkset (struct dahdi_ss7 *linkset)
static struct dahdi_ss7 * ss7_resolve_linkset (int linkset)
static void ss7_start_call (struct dahdi_pvt *p, struct dahdi_ss7 *linkset)
static void * ss_thread (void *data)
static int start_pri (struct dahdi_pri *pri)
static void swap_subs (struct dahdi_pvt *p, int a, int b)
static int unalloc_sub (struct dahdi_pvt *p, int x)
static int unload_module (void)
static int update_conf (struct dahdi_pvt *p)
static void wakeup_sub (struct dahdi_pvt *p, int a, struct dahdi_pri *pri)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = tdesc , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, }
struct {
   int   alarm
   char *   name
} alarms []
static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}}
static struct ast_module_info * ast_module_info = &__mod_info
static struct dahdi_ring_cadence cadences [NUM_CADENCE_MAX]
static int cidrings [NUM_CADENCE_MAX]
 cidrings says in which pause to transmit the cid information, where the first pause is 1, the second pause is 2 and so on.
static const char config [] = "chan_dahdi.conf"
static int cur_adjpointcode = -1
static int cur_cicbeginswith = -1
static int cur_defaultdpc = -1
static int cur_linkset = -1
static int cur_networkindicator = -1
static int cur_pointcode = -1
static int cur_ss7type = -1
static const char * dahdi_accept_r2_call_app = "DAHDIAcceptR2Call"
static struct ast_cli_entry dahdi_cli []
static struct ast_cli_entry dahdi_mfcr2_cli []
static struct ast_cli_entry dahdi_pri_cli []
static openr2_event_interface_t dahdi_r2_event_iface
static
openr2_transcoder_interface_t 
dahdi_r2_transcode_iface
static char * dahdi_send_keypad_facility_app = "DAHDISendKeypadFacility"
static struct ast_cli_entry dahdi_ss7_cli []
static struct ast_channel_tech dahdi_tech
static struct ast_jb_conf default_jbconf
static char defaultcic [64] = ""
static char defaultozz [64] = ""
static int distinctiveringaftercid = 0
static char * events []
static int firstdigittimeout = 16000
 Wait up to 16 seconds for first digit (FXO logic).
static int gendigittimeout = 8000
 How long to wait for following digits (FXO logic).
static struct ast_jb_conf global_jbconf
static int ifcount = 0
static struct dahdi_pvt * ifend
static struct dahdi_pvt * iflist
static ast_mutex_t iflock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP )
 Protect the interface list (of dahdi_pvt's).
static struct ast_channel inuse
static const char * lbostr []
static struct dahdi_ss7 linksets [NUM_SPANS]
static int matchdigittimeout = 3000
 How long to wait for an extra digit, if there is an ambiguous match.
static pthread_t monitor_thread = AST_PTHREADT_NULL
 This is the thread for the monitor which checks for input on the channels which are not currently in use.
static ast_mutex_t monlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP )
 Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical.
static int mwilevel = 512
static char mwimonitornotify [PATH_MAX] = ""
static int num_cadence = 4
static int num_restart_pending = 0
static int numbufs = 4
static char parkinglot [AST_MAX_EXTENSION] = ""
static int pridebugfd = -1
static ast_mutex_t pridebugfdlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP )
static char pridebugfilename [1024] = ""
static struct dahdi_pri pris [NUM_SPANS]
static char progzone [10] = ""
static struct dahdi_mfcr2 ** r2links
static int r2links_count = 0
static ast_mutex_t restart_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP )
static int ringt_base = DEFAULT_RINGT
 Configured ring timeout base.
struct dahdi_pvt * round_robin [32]
static ast_cond_t ss_thread_complete
static int ss_thread_count = 0
static ast_mutex_t ss_thread_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP )
static char * subnames []
static const char tdesc []
static int usedistinctiveringdetection = 0
static int user_has_defined_cadences = 0


Detailed Description

DAHDI for Pseudo TDM.

Author:
Mark Spencer <markster@digium.com>
Connects to the DAHDI telephony library as well as libpri. Libpri is optional and needed only if you are going to use ISDN connections.

You need to install libraries before you attempt to compile and install the DAHDI channel.

See also
Todo:
Deprecate the "musiconhold" configuration option post 1.4

Definition in file chan_dahdi.c.


Define Documentation

#define ASCII_BYTES_PER_CHAR   80

Referenced by dahdi_sendtext().

#define AST_LAW ( p   )     (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)

#define CALLPROGRESS_FAX   (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)

Definition at line 294 of file chan_dahdi.c.

Referenced by dahdi_handle_dtmfup(), and process_dahdi().

#define CALLPROGRESS_FAX_INCOMING   4

Definition at line 293 of file chan_dahdi.c.

Referenced by dahdi_new(), and process_dahdi().

#define CALLPROGRESS_FAX_OUTGOING   2

Definition at line 292 of file chan_dahdi.c.

Referenced by dahdi_new(), and process_dahdi().

#define CALLPROGRESS_PROGRESS   1

Definition at line 291 of file chan_dahdi.c.

Referenced by dahdi_handle_event(), dahdi_new(), and process_dahdi().

#define CALLWAITING_REPEAT_SAMPLES   ( (10000 * 8) / READ_SIZE)

10,000 ms

Definition at line 403 of file chan_dahdi.c.

Referenced by dahdi_callwait().

#define CALLWAITING_SILENT_SAMPLES   ( (300 * 8) / READ_SIZE)

300 ms

Definition at line 402 of file chan_dahdi.c.

#define CANBUSYDETECT ( p   )     (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)

Definition at line 1502 of file chan_dahdi.c.

Referenced by dahdi_new().

#define CANPROGRESSDETECT ( p   )     (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)

Definition at line 1503 of file chan_dahdi.c.

Referenced by dahdi_call(), dahdi_handle_event(), and dahdi_new().

#define CHAN_PSEUDO   -2

#define CHAN_TAG   "Chan "

Referenced by dahdi_r2_on_chan_log().

#define CHANNEL_PSEUDO   -12

Definition at line 207 of file chan_dahdi.c.

#define CIDCW_EXPIRE_SAMPLES   ( (500 * 8) / READ_SIZE)

500 ms

Definition at line 404 of file chan_dahdi.c.

Referenced by send_callerid().

#define CONF_USER_REAL   (1 << 0)

Definition at line 625 of file chan_dahdi.c.

#define CONF_USER_THIRDCALL   (1 << 1)

Definition at line 626 of file chan_dahdi.c.

#define CONTEXT_TAG   "Context - "

Referenced by dahdi_r2_on_context_log().

#define DAHDI_CHAN_MAPPING_LOGICAL   1

Definition at line 339 of file chan_dahdi.c.

Referenced by process_dahdi(), and start_pri().

#define DAHDI_CHAN_MAPPING_PHYSICAL   0

Definition at line 338 of file chan_dahdi.c.

Referenced by dahdi_chan_conf_default(), and process_dahdi().

#define DAHDI_OVERLAPDIAL_BOTH   (DAHDI_OVERLAPDIAL_INCOMING|DAHDI_OVERLAPDIAL_OUTGOING)

Definition at line 289 of file chan_dahdi.c.

Referenced by process_dahdi(), and start_pri().

#define DAHDI_OVERLAPDIAL_INCOMING   2

#define DAHDI_OVERLAPDIAL_NONE   0

Definition at line 286 of file chan_dahdi.c.

Referenced by process_dahdi().

#define DAHDI_OVERLAPDIAL_OUTGOING   1

Definition at line 287 of file chan_dahdi.c.

Referenced by dahdi_read(), process_dahdi(), and start_pri().

#define DCHAN_AVAILABLE   (DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)

Definition at line 283 of file chan_dahdi.c.

Referenced by pri_find_dchan(), and pri_is_up().

#define DCHAN_NOTINALARM   (1 << 1)

Definition at line 280 of file chan_dahdi.c.

Referenced by build_status(), pri_dchannel(), and start_pri().

#define DCHAN_PROVISIONED   (1 << 0)

Definition at line 279 of file chan_dahdi.c.

Referenced by build_status(), pri_create_trunkgroup(), and pri_resolve_span().

#define DCHAN_UP   (1 << 2)

Definition at line 281 of file chan_dahdi.c.

Referenced by build_status(), and pri_dchannel().

#define DEFAULT_CIDRINGS   1

Typically, how many rings before we should send Caller*ID.

Note:
Define ZHONE_HACK to cause us to go off hook and then back on hook when the user hangs up to reset the state machine so ring works properly. This is used to be able to support kewlstart by putting the zhone in groundstart mode since their forward disconnect supervision is entirely broken even though their documentation says it isn't and their support is entirely unwilling to provide any assistance with their channel banks even though their web site says they support their products for life.

Define if you want to check the hook state for an FXO (FXS signalled) interface before dialing on it. Certain FXO interfaces always think they're out of service with this method however.

Definition at line 205 of file chan_dahdi.c.

Referenced by dahdi_chan_conf_default().

#define DEFAULT_PRI_DEBUG   0

Definition at line 566 of file chan_dahdi.c.

Referenced by start_pri().

#define DEFAULT_RINGT   ( (8000 * 8) / READ_SIZE)

8,000 ms

Definition at line 406 of file chan_dahdi.c.

#define END_SILENCE_LEN   400

Referenced by dahdi_sendtext().

#define FORMAT   "%-40.40s %-7.7s %-6d %-6d %-6d %-3.3s %-4.4s %-8.8s %s\n"

#define FORMAT   "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"

#define FORMAT   "%4s %-7.7s %-7.7s %-8.8s %-9.9s %-16.16s %-8.8s %-8.8s\n"

#define FORMAT   "%4s %40s\n"

#define FORMAT2   "%-40.40s %-7.7s %-6.6s %-6.6s %-6.6s %-3.3s %-4.4s %-8.8s %s\n"

#define FORMAT2   "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"

#define GET_CHANNEL ( p   )     ((p)->bearer ? (p)->bearer->channel : p->channel)

Definition at line 1425 of file chan_dahdi.c.

Referenced by update_conf().

#define HANGUP   1

Definition at line 15300 of file chan_dahdi.c.

Referenced by action_transferhangup(), and dahdi_fake_event().

#define HEADER_LEN   ((HEADER_MS + TRAILER_MS) * 8)

#define HEADER_MS   50

Referenced by dahdi_sendtext().

#define ISTRUNK ( p   ) 

Value:

((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
         (p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))

Definition at line 1499 of file chan_dahdi.c.

Referenced by dahdi_indicate(), and ss_thread().

#define LINKSET_FLAG_EXPLICITACM   (1 << 0)

Definition at line 425 of file chan_dahdi.c.

Referenced by process_dahdi(), and ss7_start_call().

#define LINKSTATE_DOWN   (1 << 3)

Definition at line 421 of file chan_dahdi.c.

Referenced by linkset_addsigchan(), and ss7_linkset().

#define LINKSTATE_INALARM   (1 << 0)

Definition at line 418 of file chan_dahdi.c.

Referenced by linkset_addsigchan(), and ss7_linkset().

#define LINKSTATE_STARTING   (1 << 1)

Definition at line 419 of file chan_dahdi.c.

Referenced by ss7_linkset().

#define LINKSTATE_UP   (1 << 2)

Definition at line 420 of file chan_dahdi.c.

Referenced by ss7_linkset().

#define MASK_AVAIL   (1 << 0)

Channel available for PRI use

Definition at line 399 of file chan_dahdi.c.

#define MASK_INUSE   (1 << 1)

Channel currently in use

Definition at line 400 of file chan_dahdi.c.

#define MAX_CHANLIST_LEN   80

The length of the parameters list of 'dahdichan'.

Todo:
Move definition of MAX_CHANLIST_LEN to a proper place.

Definition at line 16155 of file chan_dahdi.c.

Referenced by process_dahdi().

#define MAX_CHANNELS   672

No more than a DS3 per trunk group

Definition at line 275 of file chan_dahdi.c.

Referenced by mkintf().

#define MAX_SLAVES   4

#define MIN_MS_SINCE_FLASH   ( (2000) )

2000 ms

Definition at line 405 of file chan_dahdi.c.

Referenced by dahdi_handle_event().

#define NEED_MFDETECT ( p   )     (((p)->sig == SIG_FEATDMF) || ((p)->sig == SIG_FEATDMF_TA) || ((p)->sig == SIG_E911) || ((p)->sig == SIG_FGC_CAMA) || ((p)->sig == SIG_FGC_CAMAMF) || ((p)->sig == SIG_FEATB))

Signaling types that need to use MF detection should be placed in this macro.

Definition at line 213 of file chan_dahdi.c.

Referenced by dahdi_new(), and ss_thread().

#define NUM_CADENCE_MAX   25

Definition at line 1474 of file chan_dahdi.c.

Referenced by process_dahdi().

#define NUM_DCHANS   4

#define NUM_SPANS   32

#define POLARITY_IDLE   0

Definition at line 584 of file chan_dahdi.c.

Referenced by dahdi_handle_event(), dahdi_hangup(), ss_thread(), and unalloc_sub().

#define POLARITY_REV   1

Definition at line 585 of file chan_dahdi.c.

Referenced by dahdi_handle_event(), handle_init_event(), and ss_thread().

#define PRI_CHANNEL ( p   )     ((p) & 0xff)

Definition at line 503 of file chan_dahdi.c.

Referenced by pri_dchannel(), and pri_find_principle().

#define PRI_EXPLICIT ( p   )     (((p) >> 16) & 0x01)

Definition at line 505 of file chan_dahdi.c.

Referenced by pri_find_principle().

#define PRI_SPAN ( p   )     (((p) >> 8) & 0xff)

Definition at line 504 of file chan_dahdi.c.

Referenced by pri_dchannel(), and pri_find_principle().

#define PROC_DAHDI_OPT_NOCHAN   (1 << 0)

process_dahdi() - ignore keyword 'channel' and similar

Definition at line 16209 of file chan_dahdi.c.

Referenced by process_dahdi(), and setup_dahdi().

#define PROC_DAHDI_OPT_NOWARN   (1 << 1)

process_dahdi() - No warnings on non-existing cofiguration keywords

Definition at line 16211 of file chan_dahdi.c.

Referenced by process_dahdi(), and setup_dahdi().

#define PVT_TO_CHANNEL ( p   )     (((p)->prioffset) | ((p)->logicalspan << 8) | (p->pri->mastertrunkgroup ? 0x10000 : 0))

#define R2_LINK_CAPACITY   10

Definition at line 10007 of file chan_dahdi.c.

Referenced by dahdi_r2_get_link().

#define READ_SIZE   160

Chunk size to read -- we use 20ms chunks to make things happy.

Definition at line 397 of file chan_dahdi.c.

Referenced by dahdi_callwait(), dahdi_open(), dahdi_read(), dahdi_sendtext(), dahdi_setoption(), my_dahdi_write(), process_dahdi(), and send_cwcidspill().

#define sig2str   dahdi_sig2str

#define SIG_BRI   (0x2000000 | DAHDI_SIG_CLEAR)

#define SIG_BRI_PTMP   (0X4000000 | DAHDI_SIG_CLEAR)

#define SIG_E911   (0x1000000 | DAHDI_SIG_EM)

#define SIG_EM   DAHDI_SIG_EM

#define SIG_EM_E1   DAHDI_SIG_EM_E1

#define SIG_EMWINK   (0x0100000 | DAHDI_SIG_EM)

#define SIG_FEATB   (0x0800000 | DAHDI_SIG_EM)

#define SIG_FEATD   (0x0200000 | DAHDI_SIG_EM)

#define SIG_FEATDMF   (0x0400000 | DAHDI_SIG_EM)

#define SIG_FEATDMF_TA   (0x2000000 | DAHDI_SIG_EM)

#define SIG_FGC_CAMA   (0x4000000 | DAHDI_SIG_EM)

#define SIG_FGC_CAMAMF   (0x8000000 | DAHDI_SIG_EM)

#define SIG_FXOGS   DAHDI_SIG_FXOGS

#define SIG_FXOKS   DAHDI_SIG_FXOKS

#define SIG_FXOLS   DAHDI_SIG_FXOLS

#define SIG_FXSGS   DAHDI_SIG_FXSGS

#define SIG_FXSKS   DAHDI_SIG_FXSKS

#define SIG_FXSLS   DAHDI_SIG_FXSLS

#define SIG_GR303FXOKS   (0x0100000 | DAHDI_SIG_FXOKS)

Definition at line 266 of file chan_dahdi.c.

Referenced by dahdi_sig2str(), handle_init_event(), mkintf(), and process_dahdi().

#define SIG_GR303FXSKS   (0x0100000 | DAHDI_SIG_FXSKS)

Definition at line 267 of file chan_dahdi.c.

Referenced by dahdi_sig2str(), handle_init_event(), mkintf(), and process_dahdi().

#define SIG_MFCR2   DAHDI_SIG_CAS

#define SIG_PRI   DAHDI_SIG_CLEAR

#define SIG_SF   DAHDI_SIG_SF

#define SIG_SF_FEATB   (0x0800000 | DAHDI_SIG_SF)

#define SIG_SF_FEATD   (0x0200000 | DAHDI_SIG_SF)

#define SIG_SF_FEATDMF   (0x0400000 | DAHDI_SIG_SF)

#define SIG_SFWINK   (0x0100000 | DAHDI_SIG_SF)

#define SIG_SS7   (0x1000000 | DAHDI_SIG_CLEAR)

#define SMDI_MD_WAIT_TIMEOUT   1500

Definition at line 159 of file chan_dahdi.c.

Referenced by ss_thread().

#define SS7_NAI_DYNAMIC   -1

Definition at line 423 of file chan_dahdi.c.

Referenced by dahdi_call(), and process_dahdi().

#define SUB_CALLWAIT   1

#define SUB_REAL   0

#define SUB_THREEWAY   2

#define TRAILER_MS   5

Referenced by dahdi_sendtext().

#define TRANSFER   0


Enumeration Type Documentation

Enumerator:
MWI_SEND_NULL 
MWI_SEND_SA 
MWI_SEND_SA_WAIT 
MWI_SEND_PAUSE 
MWI_SEND_SPILL 
MWI_SEND_CLEANUP 
MWI_SEND_DONE 

Definition at line 633 of file chan_dahdi.c.

00633              {
00634    MWI_SEND_NULL = 0,
00635    MWI_SEND_SA,
00636    MWI_SEND_SA_WAIT,
00637    MWI_SEND_PAUSE,
00638    MWI_SEND_SPILL,
00639    MWI_SEND_CLEANUP,
00640    MWI_SEND_DONE,
00641 } mwisend_states;


Function Documentation

static struct ast_frame* __dahdi_exception ( struct ast_channel *  ast  )  [static, read]

Definition at line 6678 of file chan_dahdi.c.

References ast_channel::_state, ast_bridged_channel(), AST_CONTROL_UNHOLD, ast_debug, AST_FRAME_NULL, ast_log(), ast_queue_control(), ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, ast_tv(), ast_tvnow(), ast_verb, dahdi_pvt::callwaitingrepeat, dahdi_pvt::channel, dahdi_pvt::cidcwexpire, dahdi_disable_ec(), dahdi_enable_ec(), dahdi_get_event(), dahdi_get_index(), dahdi_handle_event(), dahdi_ring_phone(), dahdi_set_hook(), ast_frame::data, ast_frame::datalen, ast_frame::delivery, dahdi_subchannel::dfd, dahdi_pvt::dialing, event2str(), dahdi_subchannel::f, f, dahdi_pvt::fake_event, ast_channel::fds, dahdi_pvt::flashtime, ast_frame::frametype, LOG_WARNING, ast_frame::mallocd, ast_channel::name, dahdi_subchannel::needanswer, dahdi_subchannel::needunhold, ast_frame::offset, dahdi_pvt::oprmode, dahdi_subchannel::owner, dahdi_pvt::owner, ast_frame::ptr, dahdi_pvt::radio, ast_frame::samples, ast_frame::src, SUB_REAL, ast_frame::subclass, dahdi_pvt::subs, ast_channel::tech_pvt, and update_conf().

Referenced by dahdi_exception(), and dahdi_read().

06679 {
06680    struct dahdi_pvt *p = ast->tech_pvt;
06681    int res;
06682    int usedindex=-1;
06683    int idx;
06684    struct ast_frame *f;
06685 
06686 
06687    idx = dahdi_get_index(ast, p, 1);
06688 
06689    p->subs[idx].f.frametype = AST_FRAME_NULL;
06690    p->subs[idx].f.datalen = 0;
06691    p->subs[idx].f.samples = 0;
06692    p->subs[idx].f.mallocd = 0;
06693    p->subs[idx].f.offset = 0;
06694    p->subs[idx].f.subclass = 0;
06695    p->subs[idx].f.delivery = ast_tv(0,0);
06696    p->subs[idx].f.src = "dahdi_exception";
06697    p->subs[idx].f.data.ptr = NULL;
06698 
06699 
06700    if ((!p->owner) && (!(p->radio || (p->oprmode < 0)))) {
06701       /* If nobody owns us, absorb the event appropriately, otherwise
06702          we loop indefinitely.  This occurs when, during call waiting, the
06703          other end hangs up our channel so that it no longer exists, but we
06704          have neither FLASH'd nor ONHOOK'd to signify our desire to
06705          change to the other channel. */
06706       if (p->fake_event) {
06707          res = p->fake_event;
06708          p->fake_event = 0;
06709       } else
06710          res = dahdi_get_event(p->subs[SUB_REAL].dfd);
06711       /* Switch to real if there is one and this isn't something really silly... */
06712       if ((res != DAHDI_EVENT_RINGEROFF) && (res != DAHDI_EVENT_RINGERON) &&
06713          (res != DAHDI_EVENT_HOOKCOMPLETE)) {
06714          ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
06715          p->owner = p->subs[SUB_REAL].owner;
06716          if (p->owner && ast_bridged_channel(p->owner))
06717             ast_queue_control(p->owner, AST_CONTROL_UNHOLD);
06718          p->subs[SUB_REAL].needunhold = 1;
06719       }
06720       switch (res) {
06721       case DAHDI_EVENT_ONHOOK:
06722          dahdi_disable_ec(p);
06723          if (p->owner) {
06724             ast_verb(3, "Channel %s still has call, ringing phone\n", p->owner->name);
06725             dahdi_ring_phone(p);
06726             p->callwaitingrepeat = 0;
06727             p->cidcwexpire = 0;
06728          } else
06729             ast_log(LOG_WARNING, "Absorbed on hook, but nobody is left!?!?\n");
06730          update_conf(p);
06731          break;
06732       case DAHDI_EVENT_RINGOFFHOOK:
06733          dahdi_enable_ec(p);
06734          dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
06735          if (p->owner && (p->owner->_state == AST_STATE_RINGING)) {
06736             p->subs[SUB_REAL].needanswer = 1;
06737             p->dialing = 0;
06738          }
06739          break;
06740       case DAHDI_EVENT_HOOKCOMPLETE:
06741       case DAHDI_EVENT_RINGERON:
06742       case DAHDI_EVENT_RINGEROFF:
06743          /* Do nothing */
06744          break;
06745       case DAHDI_EVENT_WINKFLASH:
06746          p->flashtime = ast_tvnow();
06747          if (p->owner) {
06748             ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, p->owner->name);
06749             if (p->owner->_state != AST_STATE_UP) {
06750                /* Answer if necessary */
06751                usedindex = dahdi_get_index(p->owner, p, 0);
06752                if (usedindex > -1) {
06753                   p->subs[usedindex].needanswer = 1;
06754                }
06755                ast_setstate(p->owner, AST_STATE_UP);
06756             }
06757             p->callwaitingrepeat = 0;
06758             p->cidcwexpire = 0;
06759             if (ast_bridged_channel(p->owner))
06760                ast_queue_control(p->owner, AST_CONTROL_UNHOLD);
06761             p->subs[SUB_REAL].needunhold = 1;
06762          } else
06763             ast_log(LOG_WARNING, "Absorbed on hook, but nobody is left!?!?\n");
06764          update_conf(p);
06765          break;
06766       default:
06767          ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", event2str(res));
06768       }
06769       f = &p->subs[idx].f;
06770       return f;
06771    }
06772    if (!(p->radio || (p->oprmode < 0)))
06773       ast_debug(1, "Exception on %d, channel %d\n", ast->fds[0],p->channel);
06774    /* If it's not us, return NULL immediately */
06775    if (ast != p->owner) {
06776       ast_log(LOG_WARNING, "We're %s, not %s\n", ast->name, p->owner->name);
06777       f = &p->subs[idx].f;
06778       return f;
06779    }
06780    f = dahdi_handle_event(ast);
06781    return f;
06782 }

static void __reg_module ( void   )  [static]

Definition at line 17588 of file chan_dahdi.c.

static int __unload_module ( void   )  [static]

Definition at line 15966 of file chan_dahdi.c.

References ARRAY_LEN, ast_channel_unregister(), ast_cli_unregister_multiple(), ast_cond_destroy(), ast_manager_unregister(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_unregister_application(), dahdi_close_pri_fd(), dahdi_close_ss7_fd(), dahdi_r2_destroy_links(), destroy_all_channels(), iflist, iflock, linksets, master, monlock, dahdi_pvt::next, NUM_DCHANS, NUM_SPANS, dahdi_pvt::owner, and pris.

Referenced by load_module(), and unload_module().

15967 {
15968    struct dahdi_pvt *p;
15969 #if defined(HAVE_PRI) || defined(HAVE_SS7)
15970    int i, j;
15971 #endif
15972 
15973 #ifdef HAVE_PRI
15974    for (i = 0; i < NUM_SPANS; i++) {
15975       if (pris[i].master != AST_PTHREADT_NULL)
15976          pthread_cancel(pris[i].master);
15977    }
15978    ast_cli_unregister_multiple(dahdi_pri_cli, ARRAY_LEN(dahdi_pri_cli));
15979    ast_unregister_application(dahdi_send_keypad_facility_app);
15980 #ifdef HAVE_PRI_PROG_W_CAUSE
15981    ast_unregister_application(dahdi_send_callrerouting_facility_app);
15982 #endif
15983 #endif
15984 #if defined(HAVE_SS7)
15985    for (i = 0; i < NUM_SPANS; i++) {
15986       if (linksets[i].master != AST_PTHREADT_NULL)
15987          pthread_cancel(linksets[i].master);
15988       }
15989    ast_cli_unregister_multiple(dahdi_ss7_cli, ARRAY_LEN(dahdi_ss7_cli));
15990 #endif
15991 #if defined(HAVE_OPENR2)
15992    dahdi_r2_destroy_links();
15993    ast_cli_unregister_multiple(dahdi_mfcr2_cli, ARRAY_LEN(dahdi_mfcr2_cli));
15994    ast_unregister_application(dahdi_accept_r2_call_app);
15995 #endif
15996 
15997    ast_cli_unregister_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli));
15998    ast_manager_unregister( "DAHDIDialOffhook" );
15999    ast_manager_unregister( "DAHDIHangup" );
16000    ast_manager_unregister( "DAHDITransfer" );
16001    ast_manager_unregister( "DAHDIDNDoff" );
16002    ast_manager_unregister( "DAHDIDNDon" );
16003    ast_manager_unregister("DAHDIShowChannels");
16004    ast_manager_unregister("DAHDIRestart");
16005    ast_channel_unregister(&dahdi_tech);
16006    ast_mutex_lock(&iflock);
16007    /* Hangup all interfaces if they have an owner */
16008    p = iflist;
16009    while (p) {
16010       if (p->owner)
16011          ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
16012       p = p->next;
16013    }
16014    ast_mutex_unlock(&iflock);
16015    ast_mutex_lock(&monlock);
16016    if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
16017       pthread_cancel(monitor_thread);
16018       pthread_kill(monitor_thread, SIGURG);
16019       pthread_join(monitor_thread, NULL);
16020    }
16021    monitor_thread = AST_PTHREADT_STOP;
16022    ast_mutex_unlock(&monlock);
16023 
16024    destroy_all_channels();
16025 
16026 #if defined(HAVE_PRI)
16027    for (i = 0; i < NUM_SPANS; i++) {
16028       if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL))
16029          pthread_join(pris[i].master, NULL);
16030       for (j = 0; j < NUM_DCHANS; j++) {
16031          dahdi_close_pri_fd(&(pris[i]), j);
16032       }
16033    }
16034 #endif
16035 
16036 #if defined(HAVE_SS7)
16037    for (i = 0; i < NUM_SPANS; i++) {
16038       if (linksets[i].master && (linksets[i].master != AST_PTHREADT_NULL))
16039          pthread_join(linksets[i].master, NULL);
16040       for (j = 0; j < NUM_DCHANS; j++) {
16041          dahdi_close_ss7_fd(&(linksets[i]), j);
16042       }
16043    }
16044 #endif
16045    ast_cond_destroy(&ss_thread_complete);
16046    return 0;
16047 }

static void __unreg_module ( void   )  [static]

Definition at line 17588 of file chan_dahdi.c.

static int action_dahdidialoffhook ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 15406 of file chan_dahdi.c.

References AST_FRAME_DTMF, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), dahdi_pvt::channel, dahdi_queue_frame(), find_channel(), and dahdi_pvt::owner.

Referenced by load_module().

15407 {
15408    struct dahdi_pvt *p = NULL;
15409    const char *channel = astman_get_header(m, "DAHDIChannel");
15410    const char *number = astman_get_header(m, "Number");
15411    int i;
15412 
15413    if (ast_strlen_zero(channel)) {
15414       astman_send_error(s, m, "No channel specified");
15415       return 0;
15416    }
15417    if (ast_strlen_zero(number)) {
15418       astman_send_error(s, m, "No number specified");
15419       return 0;
15420    }
15421    p = find_channel(atoi(channel));
15422    if (!p) {
15423       astman_send_error(s, m, "No such channel");
15424       return 0;
15425    }
15426    if (!p->owner) {
15427       astman_send_error(s, m, "Channel does not have it's owner");
15428       return 0;
15429    }
15430    for (i = 0; i < strlen(number); i++) {
15431       struct ast_frame f = { AST_FRAME_DTMF, number[i] };
15432       dahdi_queue_frame(p, &f, NULL);
15433    }
15434    astman_send_ack(s, m, "DAHDIDialOffhook");
15435    return 0;
15436 }

static int action_dahdidndoff ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 15349 of file chan_dahdi.c.

References ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), dahdi_pvt::channel, dahdi_pvt::dnd, and find_channel().

Referenced by load_module().

15350 {
15351    struct dahdi_pvt *p = NULL;
15352    const char *channel = astman_get_header(m, "DAHDIChannel");
15353 
15354    if (ast_strlen_zero(channel)) {
15355       astman_send_error(s, m, "No channel specified");
15356       return 0;
15357    }
15358    p = find_channel(atoi(channel));
15359    if (!p) {
15360       astman_send_error(s, m, "No such channel");
15361       return 0;
15362    }
15363    p->dnd = 0;
15364    astman_send_ack(s, m, "DND Disabled");
15365    return 0;
15366 }

static int action_dahdidndon ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 15330 of file chan_dahdi.c.

References ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), dahdi_pvt::channel, dahdi_pvt::dnd, and find_channel().

Referenced by load_module().

15331 {
15332    struct dahdi_pvt *p = NULL;
15333    const char *channel = astman_get_header(m, "DAHDIChannel");
15334 
15335    if (ast_strlen_zero(channel)) {
15336       astman_send_error(s, m, "No channel specified");
15337       return 0;
15338    }
15339    p = find_channel(atoi(channel));
15340    if (!p) {
15341       astman_send_error(s, m, "No such channel");
15342       return 0;
15343    }
15344    p->dnd = 1;
15345    astman_send_ack(s, m, "DND Enabled");
15346    return 0;
15347 }

static int action_dahdirestart ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 14591 of file chan_dahdi.c.

References astman_send_ack(), astman_send_error(), and dahdi_restart().

Referenced by load_module().

14592 {
14593    if (dahdi_restart() != 0) {
14594       astman_send_error(s, m, "Failed rereading DAHDI configuration");
14595       return 1;
14596    }
14597    astman_send_ack(s, m, "DAHDIRestart: Success");
14598    return 0;
14599 }

static int action_dahdishowchannels ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 15438 of file chan_dahdi.c.

References ast_channel::accountcode, alarm2str(), ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), dahdi_pvt::channel, dahdi_pvt::context, dahdi_pvt::dnd, get_alarms(), iflist, iflock, ast_channel::name, dahdi_pvt::next, dahdi_pvt::owner, dahdi_pvt::sig, sig2str, and ast_channel::uniqueid.

Referenced by load_module().

15439 {
15440    struct dahdi_pvt *tmp = NULL;
15441    const char *id = astman_get_header(m, "ActionID");
15442    const char *dahdichannel = astman_get_header(m, "DAHDIChannel");
15443    char idText[256] = "";
15444    int channels = 0;
15445    int dahdichanquery = -1;
15446    if (!ast_strlen_zero(dahdichannel)) {
15447       dahdichanquery = atoi(dahdichannel);
15448    }
15449 
15450    astman_send_ack(s, m, "DAHDI channel status will follow");
15451    if (!ast_strlen_zero(id))
15452       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
15453 
15454    ast_mutex_lock(&iflock);
15455 
15456    tmp = iflist;
15457    while (tmp) {
15458       if (tmp->channel > 0) {
15459          int alm = get_alarms(tmp);
15460 
15461          /* If a specific channel is queried for, only deliver status for that channel */
15462          if (dahdichanquery > 0 && tmp->channel != dahdichanquery)
15463             continue;
15464 
15465          channels++;
15466          if (tmp->owner) {
15467             /* Add data if we have a current call */
15468             astman_append(s,
15469                "Event: DAHDIShowChannels\r\n"
15470                "DAHDIChannel: %d\r\n"
15471                "Channel: %s\r\n"
15472                "Uniqueid: %s\r\n"
15473                "AccountCode: %s\r\n"
15474                "Signalling: %s\r\n"
15475                "SignallingCode: %d\r\n"
15476                "Context: %s\r\n"
15477                "DND: %s\r\n"
15478                "Alarm: %s\r\n"
15479                "%s"
15480                "\r\n",
15481                tmp->channel,
15482                tmp->owner->name,
15483                tmp->owner->uniqueid,
15484                tmp->owner->accountcode,
15485                sig2str(tmp->sig),
15486                tmp->sig,
15487                tmp->context,
15488                tmp->dnd ? "Enabled" : "Disabled",
15489                alarm2str(alm), idText);
15490          } else {
15491             astman_append(s,
15492                "Event: DAHDIShowChannels\r\n"
15493                "DAHDIChannel: %d\r\n"
15494                "Signalling: %s\r\n"
15495                "SignallingCode: %d\r\n"
15496                "Context: %s\r\n"
15497                "DND: %s\r\n"
15498                "Alarm: %s\r\n"
15499                "%s"
15500                "\r\n",
15501                tmp->channel, sig2str(tmp->sig), tmp->sig,
15502                tmp->context,
15503                tmp->dnd ? "Enabled" : "Disabled",
15504                alarm2str(alm), idText);
15505          }
15506       }
15507 
15508       tmp = tmp->next;
15509    }
15510 
15511    ast_mutex_unlock(&iflock);
15512 
15513    astman_append(s,
15514       "Event: DAHDIShowChannelsComplete\r\n"
15515       "%s"
15516       "Items: %d\r\n"
15517       "\r\n",
15518       idText,
15519       channels);
15520    return 0;
15521 }

static int action_transfer ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 15368 of file chan_dahdi.c.

References ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), dahdi_pvt::channel, dahdi_fake_event(), find_channel(), and TRANSFER.

Referenced by load_module().

15369 {
15370    struct dahdi_pvt *p = NULL;
15371    const char *channel = astman_get_header(m, "DAHDIChannel");
15372 
15373    if (ast_strlen_zero(channel)) {
15374       astman_send_error(s, m, "No channel specified");
15375       return 0;
15376    }
15377    p = find_channel(atoi(channel));
15378    if (!p) {
15379       astman_send_error(s, m, "No such channel");
15380       return 0;
15381    }
15382    dahdi_fake_event(p,TRANSFER);
15383    astman_send_ack(s, m, "DAHDITransfer");
15384    return 0;
15385 }

static int action_transferhangup ( struct mansession *  s,
const struct message *  m 
) [static]

Definition at line 15387 of file chan_dahdi.c.

References ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), dahdi_pvt::channel, dahdi_fake_event(), find_channel(), and HANGUP.

Referenced by load_module().

15388 {
15389    struct dahdi_pvt *p = NULL;
15390    const char *channel = astman_get_header(m, "DAHDIChannel");
15391 
15392    if (ast_strlen_zero(channel)) {
15393       astman_send_error(s, m, "No channel specified");
15394       return 0;
15395    }
15396    p = find_channel(atoi(channel));
15397    if (!p) {
15398       astman_send_error(s, m, "No such channel");
15399       return 0;
15400    }
15401    dahdi_fake_event(p,HANGUP);
15402    astman_send_ack(s, m, "DAHDIHangup");
15403    return 0;
15404 }

static char* alarm2str ( int  alm  )  [static]

Definition at line 2381 of file chan_dahdi.c.

References alarm, alarms, and ARRAY_LEN.

Referenced by action_dahdishowchannels(), and handle_alarms().

02382 {
02383    int x;
02384    for (x = 0; x < ARRAY_LEN(alarms); x++) {
02385       if (alarms[x].alarm & alm)
02386          return alarms[x].name;
02387    }
02388    return alm ? "Unknown Alarm" : "No Alarm";
02389 }

static int alloc_sub ( struct dahdi_pvt *  p,
int  x 
) [static]

Definition at line 2177 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_pvt::buf_no, dahdi_pvt::buf_policy, dahdi_subchannel::chan, dahdi_pvt::channel, dahdi_close_sub(), dahdi_open(), dahdi_subchannel::dfd, errno, LOG_WARNING, and dahdi_pvt::subs.

Referenced by dahdi_handle_event(), dahdi_request(), and ss_thread().

02178 {
02179    struct dahdi_bufferinfo bi;
02180    int res;
02181    if (p->subs[x].dfd >= 0) {
02182       ast_log(LOG_WARNING, "%s subchannel of %d already in use\n", subnames[x], p->channel);
02183       return -1;
02184    }
02185 
02186    p->subs[x].dfd = dahdi_open("/dev/dahdi/pseudo");
02187    if (p->subs[x].dfd <= -1) {
02188       ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
02189       return -1;
02190    }
02191 
02192    res = ioctl(p->subs[x].dfd, DAHDI_GET_BUFINFO, &bi);
02193    if (!res) {
02194       bi.txbufpolicy = p->buf_policy;
02195       bi.rxbufpolicy = p->buf_policy;
02196       bi.numbufs = p->buf_no;
02197       res = ioctl(p->subs[x].dfd, DAHDI_SET_BUFINFO, &bi);
02198       if (res < 0) {
02199          ast_log(LOG_WARNING, "Unable to set buffer policy on channel %d: %s\n", x, strerror(errno));
02200       }
02201    } else
02202       ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d: %s\n", x, strerror(errno));
02203 
02204    if (ioctl(p->subs[x].dfd, DAHDI_CHANNO, &p->subs[x].chan) == 1) {
02205       ast_log(LOG_WARNING, "Unable to get channel number for pseudo channel on FD %d: %s\n", p->subs[x].dfd, strerror(errno));
02206       dahdi_close_sub(p, x);
02207       p->subs[x].dfd = -1;
02208       return -1;
02209    }
02210    ast_debug(1, "Allocated %s subchannel on FD %d channel %d\n", subnames[x], p->subs[x].dfd, p->subs[x].chan);
02211    return 0;
02212 }

static void apply_plan_to_number ( char *  buf,
size_t  size,
const struct dahdi_pri *  pri,
const char *  number,
const int  plan 
) [static]

Definition at line 12478 of file chan_dahdi.c.

References ast_strlen_zero(), dahdi_pri::dialplan, dahdi_pri::internationalprefix, dahdi_pri::localprefix, dahdi_pri::nationalprefix, dahdi_pri::privateprefix, and dahdi_pri::unknownprefix.

Referenced by pri_dchannel().

12479 {
12480    if (pri->dialplan == -2) { /* autodetect the TON but leave the number untouched */
12481       snprintf(buf, size, "%s", number);
12482       return;
12483    }
12484    if (ast_strlen_zero(number)) { /* make sure a number exists so prefix isn't placed on an empty string */
12485       if (size) {
12486          *buf = '\0';
12487       }
12488       return;
12489    }
12490    switch (plan) {
12491    case PRI_INTERNATIONAL_ISDN:     /* Q.931 dialplan == 0x11 international dialplan => prepend international prefix digits */
12492       snprintf(buf, size, "%s%s", pri->internationalprefix, number);
12493       break;
12494    case PRI_NATIONAL_ISDN:       /* Q.931 dialplan == 0x21 national dialplan => prepend national prefix digits */
12495       snprintf(buf, size, "%s%s", pri->nationalprefix, number);
12496       break;
12497    case PRI_LOCAL_ISDN:       /* Q.931 dialplan == 0x41 local dialplan => prepend local prefix digits */
12498       snprintf(buf, size, "%s%s", pri->localprefix, number);
12499       break;
12500    case PRI_PRIVATE:       /* Q.931 dialplan == 0x49 private dialplan => prepend private prefix digits */
12501       snprintf(buf, size, "%s%s", pri->privateprefix, number);
12502       break;
12503    case PRI_UNKNOWN:       /* Q.931 dialplan == 0x00 unknown dialplan => prepend unknown prefix digits */
12504       snprintf(buf, size, "%s%s", pri->unknownprefix, number);
12505       break;
12506    default:          /* other Q.931 dialplan => don't twiddle with callingnum */
12507       snprintf(buf, size, "%s", number);
12508       break;
12509    }
12510 }

static int attempt_transfer ( struct dahdi_pvt *  p  )  [static]

Definition at line 5578 of file chan_dahdi.c.

References ast_channel::_softhangup, ast_channel::_state, ast_bridged_channel(), ast_channel_masquerade(), ast_channel_unlock, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_debug, ast_indicate(), ast_log(), ast_queue_control(), AST_SOFTHANGUP_DEV, AST_STATE_RING, AST_STATE_RINGING, dahdi_subchannel::dfd, LOG_WARNING, ast_channel::name, dahdi_subchannel::owner, SUB_REAL, SUB_THREEWAY, dahdi_pvt::subs, swap_subs(), and unalloc_sub().

Referenced by dahdi_handle_event().

05579 {
05580    /* In order to transfer, we need at least one of the channels to
05581       actually be in a call bridge.  We can't conference two applications
05582       together (but then, why would we want to?) */
05583    if (ast_bridged_channel(p->subs[SUB_REAL].owner)) {
05584       /* The three-way person we're about to transfer to could still be in MOH, so
05585          stop if now if appropriate */
05586       if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner))
05587          ast_queue_control(p->subs[SUB_THREEWAY].owner, AST_CONTROL_UNHOLD);
05588       if (p->subs[SUB_REAL].owner->_state == AST_STATE_RINGING) {
05589          ast_indicate(ast_bridged_channel(p->subs[SUB_REAL].owner), AST_CONTROL_RINGING);
05590       }
05591       if (p->subs[SUB_THREEWAY].owner->_state == AST_STATE_RING) {
05592          tone_zone_play_tone(p->subs[SUB_THREEWAY].dfd, DAHDI_TONE_RINGTONE);
05593       }
05594        if (ast_channel_masquerade(p->subs[SUB_THREEWAY].owner, ast_bridged_channel(p->subs[SUB_REAL].owner))) {
05595          ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
05596                ast_bridged_channel(p->subs[SUB_REAL].owner)->name, p->subs[SUB_THREEWAY].owner->name);
05597          return -1;
05598       }
05599       /* Orphan the channel after releasing the lock */
05600       ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
05601       unalloc_sub(p, SUB_THREEWAY);
05602    } else if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
05603       ast_queue_control(p->subs[SUB_REAL].owner, AST_CONTROL_UNHOLD);
05604       if (p->subs[SUB_THREEWAY].owner->_state == AST_STATE_RINGING) {
05605          ast_indicate(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), AST_CONTROL_RINGING);
05606       }
05607       if (p->subs[SUB_REAL].owner->_state == AST_STATE_RING) {
05608          tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
05609       }
05610       if (ast_channel_masquerade(p->subs[SUB_REAL].owner, ast_bridged_channel(p->subs[SUB_THREEWAY].owner))) {
05611          ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
05612                ast_bridged_channel(p->subs[SUB_THREEWAY].owner)->name, p->subs[SUB_REAL].owner->name);
05613          return -1;
05614       }
05615       /* Three-way is now the REAL */
05616       swap_subs(p, SUB_THREEWAY, SUB_REAL);
05617       ast_channel_unlock(p->subs[SUB_REAL].owner);
05618       unalloc_sub(p, SUB_THREEWAY);
05619       /* Tell the caller not to hangup */
05620       return 1;
05621    } else {
05622       ast_debug(1, "Neither %s nor %s are in a bridge, nothing to transfer\n",
05623          p->subs[SUB_REAL].owner->name, p->subs[SUB_THREEWAY].owner->name);
05624       p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
05625       return -1;
05626    }
05627    return 0;
05628 }

static int available ( struct dahdi_pvt *  p,
int  channelmatch,
ast_group_t  groupmatch,
int *  busy,
int *  channelmatched,
int *  groupmatched 
) [inline, static]

Definition at line 10754 of file chan_dahdi.c.

References ast_channel::_state, ast_debug, ast_log(), AST_STATE_RINGING, AST_STATE_UP, dahdi_pvt::call, dahdi_pvt::callwaiting, dahdi_pvt::channel, dahdi_subchannel::dfd, dahdi_pvt::dnd, errno, dahdi_pvt::group, dahdi_pvt::guardtime, dahdi_subchannel::inthreeway, dahdi_pvt::locallyblocked, LOG_WARNING, dahdi_pvt::mfcr2, dahdi_pvt::mfcr2call, dahdi_pvt::oprmode, dahdi_pvt::outgoing, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::pri, dahdi_pvt::radio, dahdi_pvt::remotelyblocked, dahdi_pvt::resetting, dahdi_pvt::sig, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, dahdi_pvt::ss7, dahdi_pvt::ss7call, SUB_CALLWAIT, SUB_REAL, SUB_THREEWAY, and dahdi_pvt::subs.

Referenced by __ast_string_field_ptr_build_va(), and dahdi_request().

10755 {
10756    int res;
10757    struct dahdi_params par;
10758 
10759    /* First, check group matching */
10760    if (groupmatch) {
10761       if ((p->group & groupmatch) != groupmatch)
10762          return 0;
10763       *groupmatched = 1;
10764    }
10765    /* Check to see if we have a channel match */
10766    if (channelmatch != -1) {
10767       if (p->channel != channelmatch)
10768          return 0;
10769       *channelmatched = 1;
10770    }
10771    /* We're at least busy at this point */
10772    if (busy) {
10773       if ((p->sig == SIG_FXOKS) || (p->sig == SIG_FXOLS) || (p->sig == SIG_FXOGS))
10774          *busy = 1;
10775    }
10776    /* If do not disturb, definitely not */
10777    if (p->dnd)
10778       return 0;
10779    /* If guard time, definitely not */
10780    if (p->guardtime && (time(NULL) < p->guardtime))
10781       return 0;
10782 
10783    if (p->locallyblocked || p->remotelyblocked)
10784       return 0;
10785 
10786    /* If no owner definitely available */
10787    if (!p->owner) {
10788 #ifdef HAVE_PRI
10789       /* Trust PRI */
10790       if (p->pri) {
10791          if (p->resetting || p->call)
10792             return 0;
10793          else
10794             return 1;
10795       }
10796 #endif
10797 #ifdef HAVE_SS7
10798       /* Trust SS7 */
10799       if (p->ss7) {
10800          if (p->ss7call)
10801             return 0;
10802          else
10803             return 1;
10804       }
10805 #endif
10806 #ifdef HAVE_OPENR2
10807       /* Trust MFC/R2 */
10808       if (p->mfcr2) {
10809          if (p->mfcr2call)
10810             return 0;
10811          else
10812             return 1;
10813       }
10814 #endif
10815 
10816       /* Trust hook state */
10817       if (p->sig && !(p->radio || (p->oprmode < 0)))
10818       {
10819          /* Check hook state */
10820          if (p->subs[SUB_REAL].dfd > -1) {
10821             memset(&par, 0, sizeof(par));
10822             res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
10823          } else {
10824             /* Assume not off hook on CVRS */
10825             res = 0;
10826             par.rxisoffhook = 0;
10827          }
10828 
10829          if (res) {
10830             ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
10831          }
10832          else if ((p->sig != SIG_FXSKS) && (p->sig != SIG_FXSGS) && (p->sig != SIG_FXSLS)) {
10833             if (par.rxisoffhook) {
10834                ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
10835                /* Not available when the other end is off hook */
10836                return 0;
10837             }
10838          }
10839 #ifdef DAHDI_CHECK_HOOKSTATE
10840          } else { /* FXO channel case (SIG_FXS--) */
10841             /* Channel bank (using CAS), "onhook" does not necessarily means out of service, so return 1 */
10842             if (par.rxbits > -1)
10843                return 1;
10844             /* TDM FXO card, "onhook" means out of service (no battery on the line) */
10845             if (par.rxisoffhook)
10846                return 1;
10847             else
10848                return 0;
10849 #endif
10850       }
10851 
10852       return 1;
10853    }
10854 
10855    /* If it's not an FXO, forget about call wait */
10856    if ((p->sig != SIG_FXOKS) && (p->sig != SIG_FXOLS) && (p->sig != SIG_FXOGS))
10857       return 0;
10858 
10859    if (!p->callwaiting) {
10860       /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
10861       return 0;
10862    }
10863 
10864    if (p->subs[SUB_CALLWAIT].dfd > -1) {
10865       /* If there is already a call waiting call, then we can't take a second one */
10866       return 0;
10867    }
10868 
10869    if ((p->owner->_state != AST_STATE_UP) &&
10870       ((p->owner->_state != AST_STATE_RINGING) || p->outgoing)) {
10871       /* If the current call is not up, then don't allow the call */
10872       return 0;
10873    }
10874    if ((p->subs[SUB_THREEWAY].owner) && (!p->subs[SUB_THREEWAY].inthreeway)) {
10875       /* Can't take a call wait when the three way calling hasn't been merged yet. */
10876       return 0;
10877    }
10878    /* We're cool */
10879    return 1;
10880 }

static int build_channels ( struct dahdi_chan_conf *  conf,
int  iscrv,
const char *  value,
int  reload,
int  lineno,
int *  found_pseudo 
) [static]

Definition at line 16065 of file chan_dahdi.c.

References ast_log(), ast_strdupa, ast_verb, dahdi_chan_conf::chan, CHAN_PSEUDO, dahdi_chan_conf::is_sig_auto, LOG_ERROR, LOG_WARNING, mkintf(), NUM_SPANS, dahdi_pri::pri, pris, dahdi_pvt::sig, sig2str, strsep(), and dahdi_pri::trunkgroup.

Referenced by process_dahdi().

16066 {
16067    char *c, *chan;
16068    int x, start, finish;
16069    struct dahdi_pvt *tmp;
16070 #ifdef HAVE_PRI
16071    struct dahdi_pri *pri;
16072    int trunkgroup, y;
16073 #endif
16074 
16075    if ((reload == 0) && (conf->chan.sig < 0) && !conf->is_sig_auto) {
16076       ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n");
16077       return -1;
16078    }
16079 
16080    c = ast_strdupa(value);
16081 
16082 #ifdef HAVE_PRI
16083    pri = NULL;
16084    if (iscrv) {
16085       if (sscanf(c, "%30d:%n", &trunkgroup, &y) != 1) {
16086          ast_log(LOG_WARNING, "CRV must begin with trunkgroup followed by a colon at line %d.\n", lineno);
16087          return -1;
16088       }
16089       if (trunkgroup < 1) {
16090          ast_log(LOG_WARNING, "CRV trunk group must be a positive number at line %d.\n", lineno);
16091          return -1;
16092       }
16093       c += y;
16094       for (y = 0; y < NUM_SPANS; y++) {
16095          if (pris[y].trunkgroup == trunkgroup) {
16096             pri = pris + y;
16097             break;
16098          }
16099       }
16100       if (!pri) {
16101          ast_log(LOG_WARNING, "No such trunk group %d at CRV declaration at line %d.\n", trunkgroup, lineno);
16102          return -1;
16103       }
16104    }
16105 #endif
16106 
16107    while ((chan = strsep(&c, ","))) {
16108       if (sscanf(chan, "%30d-%30d", &start, &finish) == 2) {
16109          /* Range */
16110       } else if (sscanf(chan, "%30d", &start)) {
16111          /* Just one */
16112          finish = start;
16113       } else if (!strcasecmp(chan, "pseudo")) {
16114          finish = start = CHAN_PSEUDO;
16115          if (found_pseudo)
16116             *found_pseudo = 1;
16117       } else {
16118          ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'\n", value, chan);
16119          return -1;
16120       }
16121       if (finish < start) {
16122          ast_log(LOG_WARNING, "Sillyness: %d < %d\n", start, finish);
16123          x = finish;
16124          finish = start;
16125          start = x;
16126       }
16127 
16128       for (x = start; x <= finish; x++) {
16129 #ifdef HAVE_PRI
16130          tmp = mkintf(x, conf, pri, reload);
16131 #else
16132          tmp = mkintf(x, conf, NULL, reload);
16133 #endif
16134 
16135          if (tmp) {
16136 #ifdef HAVE_PRI
16137             if (pri)
16138                ast_verb(3, "%s CRV %d:%d, %s signalling\n", reload ? "Reconfigured" : "Registered", trunkgroup, x, sig2str(tmp->sig));
16139             else
16140 #endif
16141                ast_verb(3, "%s channel %d, %s signalling\n", reload ? "Reconfigured" : "Registered", x, sig2str(tmp->sig));
16142          } else {
16143             ast_log(LOG_ERROR, "Unable to %s channel '%s'\n",
16144                (reload == 1) ? "reconfigure" : "register", value);
16145             return -1;
16146          }
16147       }
16148    }
16149 
16150    return 0;
16151 }

static void build_status ( char *  s,
size_t  len,
int  status,
int  active 
) [static]

Definition at line 13886 of file chan_dahdi.c.

References DCHAN_NOTINALARM, DCHAN_PROVISIONED, and DCHAN_UP.

Referenced by handle_pri_show_span(), and handle_pri_show_spans().

13887 {
13888    if (!s || len < 1) {
13889       return;
13890    }
13891    s[0] = '\0';
13892    if (status & DCHAN_PROVISIONED)
13893       strncat(s, "Provisioned, ", len - strlen(s) - 1);
13894    if (!(status & DCHAN_NOTINALARM))
13895       strncat(s, "In Alarm, ", len - strlen(s) - 1);
13896    if (status & DCHAN_UP)
13897       strncat(s, "Up", len - strlen(s) - 1);
13898    else
13899       strncat(s, "Down", len - strlen(s) - 1);
13900    if (active)
13901       strncat(s, ", Active", len - strlen(s) - 1);
13902    else
13903       strncat(s, ", Standby", len - strlen(s) - 1);
13904    s[len - 1] = '\0';
13905 }

static int bump_gains ( struct dahdi_pvt *  p  )  [static]

Definition at line 2838 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::cid_rxgain, dahdi_subchannel::dfd, errno, dahdi_pvt::law, LOG_WARNING, dahdi_pvt::rxgain, set_actual_gain(), SUB_REAL, dahdi_pvt::subs, and dahdi_pvt::txgain.

Referenced by mwi_thread(), and ss_thread().

02839 {
02840    int res;
02841 
02842    /* Bump receive gain by value stored in cid_rxgain */
02843    res = set_actual_gain(p->subs[SUB_REAL].dfd, 0, p->rxgain + p->cid_rxgain, p->txgain, p->law);
02844    if (res) {
02845       ast_log(LOG_WARNING, "Unable to bump gain: %s\n", strerror(errno));
02846       return -1;
02847    }
02848 
02849    return 0;
02850 }

static int calc_energy ( const unsigned char *  buf,
int  len,
int  law 
) [static]

Definition at line 9011 of file chan_dahdi.c.

References AST_ALAW, AST_FORMAT_ULAW, and AST_MULAW.

Referenced by do_monitor(), and mwi_thread().

09012 {
09013    int x;
09014    int sum = 0;
09015 
09016    if (!len)
09017       return 0;
09018 
09019    for (x = 0; x < len; x++)
09020       sum += abs(law == AST_FORMAT_ULAW ? AST_MULAW(buf[x]) : AST_ALAW(buf[x]));
09021 
09022    return sum / len;
09023 }

static int check_for_conference ( struct dahdi_pvt *  p  )  [static]

Definition at line 5630 of file chan_dahdi.c.

References ast_log(), ast_verb, dahdi_pvt::channel, dahdi_pvt::confno, dahdi_subchannel::curconf, dahdi_subchannel::dfd, errno, LOG_WARNING, dahdi_pvt::master, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_handle_event().

05631 {
05632    struct dahdi_confinfo ci;
05633    /* Fine if we already have a master, etc */
05634    if (p->master || (p->confno > -1))
05635       return 0;
05636    memset(&ci, 0, sizeof(ci));
05637    if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_GETCONF, &ci)) {
05638       ast_log(LOG_WARNING, "Failed to get conference info on channel %d: %s\n", p->channel, strerror(errno));
05639       return 0;
05640    }
05641    /* If we have no master and don't have a confno, then
05642       if we're in a conference, it's probably a MeetMe room or
05643       some such, so don't let us 3-way out! */
05644    if ((p->subs[SUB_REAL].curconf.confno != ci.confno) || (p->subs[SUB_REAL].curconf.confmode != ci.confmode)) {
05645       ast_verb(3, "Avoiding 3-way call when in an external conference\n");
05646       return 1;
05647    }
05648    return 0;
05649 }

static unsigned char cid_pres2ss7pres ( int  cid_pres  )  [static]

Definition at line 3090 of file chan_dahdi.c.

Referenced by dahdi_call().

03091 {
03092     return (cid_pres >> 5) & 0x03;
03093 }

static unsigned char cid_pres2ss7screen ( int  cid_pres  )  [static]

Definition at line 3097 of file chan_dahdi.c.

Referenced by dahdi_call().

03098 {
03099    return cid_pres & 0x03;
03100 }

static char* complete_span_4 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 13778 of file chan_dahdi.c.

References complete_span_helper().

Referenced by handle_pri_debug(), and handle_pri_show_span().

13779 {
13780    return complete_span_helper(line,word,pos,state,3);
13781 }

static char* complete_span_helper ( const char *  line,
const char *  word,
int  pos,
int  state,
int  rpos 
) [static]

Definition at line 13757 of file chan_dahdi.c.

References asprintf, ast_log(), errno, LOG_WARNING, NUM_SPANS, and pris.

Referenced by complete_span_4().

13758 {
13759    int which, span;
13760    char *ret = NULL;
13761 
13762    if (pos != rpos)
13763       return ret;
13764 
13765    for (which = span = 0; span < NUM_SPANS; span++) {
13766       if (pris[span].pri && ++which > state) {
13767          if (asprintf(&ret, "%d", span + 1) < 0) { /* user indexes start from 1 */
13768             ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
13769          }
13770          break;
13771       }
13772    }
13773    return ret;
13774 }

static int conf_add ( struct dahdi_pvt *  p,
struct dahdi_subchannel *  c,
int  idx,
int  slavechannel 
) [static]

Definition at line 2480 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_pvt::confno, dahdi_subchannel::curconf, dahdi_subchannel::dfd, errno, and LOG_WARNING.

Referenced by update_conf().

02481 {
02482    /* If the conference already exists, and we're already in it
02483       don't bother doing anything */
02484    struct dahdi_confinfo zi;
02485 
02486    memset(&zi, 0, sizeof(zi));
02487    zi.chan = 0;
02488 
02489    if (slavechannel > 0) {
02490       /* If we have only one slave, do a digital mon */
02491       zi.confmode = DAHDI_CONF_DIGITALMON;
02492       zi.confno = slavechannel;
02493    } else {
02494       if (!idx) {
02495          /* Real-side and pseudo-side both participate in conference */
02496          zi.confmode = DAHDI_CONF_REALANDPSEUDO | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER |
02497             DAHDI_CONF_PSEUDO_TALKER | DAHDI_CONF_PSEUDO_LISTENER;
02498       } else
02499          zi.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
02500       zi.confno = p->confno;
02501    }
02502    if ((zi.confno == c->curconf.confno) && (zi.confmode == c->curconf.confmode))
02503       return 0;
02504    if (c->dfd < 0)
02505       return 0;
02506    if (ioctl(c->dfd, DAHDI_SETCONF, &zi)) {
02507       ast_log(LOG_WARNING, "Failed to add %d to conference %d/%d: %s\n", c->dfd, zi.confmode, zi.confno, strerror(errno));
02508       return -1;
02509    }
02510    if (slavechannel < 1) {
02511       p->confno = zi.confno;
02512    }
02513    memcpy(&c->curconf, &zi, sizeof(c->curconf));
02514    ast_debug(1, "Added %d to conference %d/%d\n", c->dfd, c->curconf.confmode, c->curconf.confno);
02515    return 0;
02516 }

static int conf_del ( struct dahdi_pvt *  p,
struct dahdi_subchannel *  c,
int  idx 
) [static]

Definition at line 2529 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_subchannel::curconf, dahdi_subchannel::dfd, errno, isourconf(), and LOG_WARNING.

Referenced by dahdi_unlink(), and update_conf().

02530 {
02531    struct dahdi_confinfo zi;
02532    if (/* Can't delete if there's no dfd */
02533       (c->dfd < 0) ||
02534       /* Don't delete from the conference if it's not our conference */
02535       !isourconf(p, c)
02536       /* Don't delete if we don't think it's conferenced at all (implied) */
02537       ) return 0;
02538    memset(&zi, 0, sizeof(zi));
02539    if (ioctl(c->dfd, DAHDI_SETCONF, &zi)) {
02540       ast_log(LOG_WARNING, "Failed to drop %d from conference %d/%d: %s\n", c->dfd, c->curconf.confmode, c->curconf.confno, strerror(errno));
02541       return -1;
02542    }
02543    ast_debug(1, "Removed %d from conference %d/%d\n", c->dfd, c->curconf.confmode, c->curconf.confno);
02544    memcpy(&c->curconf, &zi, sizeof(c->curconf));
02545    return 0;
02546 }

static int dahdi_accept_r2_call_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 4175 of file chan_dahdi.c.

References AST_APP_ARG, ast_check_hangup(), AST_CONTROL_HANGUP, AST_DECLARE_APP_ARGS, AST_FRAME_CONTROL, ast_frfree, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_read(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_true(), ast_waitfor(), f, ast_frame::frametype, dahdi_pvt::lock, LOG_DEBUG, LOG_WARNING, dahdi_pvt::mfcr2, dahdi_pvt::mfcr2_call_accepted, dahdi_pvt::mfcr2call, ast_channel::name, dahdi_pvt::r2chan, ast_frame::subclass, ast_channel::tech, and ast_channel::tech_pvt.

Referenced by load_module().

04176 {
04177    /* data is whether to accept with charge or no charge */
04178    openr2_call_mode_t accept_mode;
04179    int res, timeout, maxloops;
04180    struct ast_frame *f;
04181    struct dahdi_pvt *p;
04182    char *parse;
04183    AST_DECLARE_APP_ARGS(args,
04184          AST_APP_ARG(charge);
04185    );
04186 
04187    if (ast_strlen_zero(data)) {
04188       ast_log(LOG_DEBUG, "No data sent to application!\n");
04189       return -1;
04190    }
04191 
04192    if (chan->tech != &dahdi_tech) {
04193       ast_log(LOG_DEBUG, "Only DAHDI technology accepted!\n");
04194       return -1;
04195    }
04196 
04197    p = (struct dahdi_pvt *)chan->tech_pvt;
04198    if (!p) {
04199       ast_log(LOG_DEBUG, "Unable to find technology private!\n");
04200       return -1;
04201    }
04202 
04203    parse = ast_strdupa(data);
04204    AST_STANDARD_APP_ARGS(args, parse);
04205 
04206    if (ast_strlen_zero(args.charge)) {
04207       ast_log(LOG_WARNING, "DAHDIAcceptR2Call requires 'yes' or 'no' for the charge parameter\n");
04208       return -1;
04209    }
04210 
04211    ast_mutex_lock(&p->lock);
04212    if (!p->mfcr2 || !p->mfcr2call) {
04213       ast_mutex_unlock(&p->lock);
04214       ast_log(LOG_DEBUG, "Channel %s does not seems to be an R2 active channel!\n", chan->name);
04215       return -1;
04216    }
04217 
04218    if (p->mfcr2_call_accepted) {
04219       ast_mutex_unlock(&p->lock);
04220       ast_log(LOG_DEBUG, "MFC/R2 call already accepted on channel %s!\n", chan->name);
04221       return 0;
04222    }
04223    accept_mode = ast_true(args.charge) ? OR2_CALL_WITH_CHARGE : OR2_CALL_NO_CHARGE;
04224    if (openr2_chan_accept_call(p->r2chan, accept_mode)) {
04225       ast_mutex_unlock(&p->lock);
04226       ast_log(LOG_WARNING, "Failed to accept MFC/R2 call!\n");
04227       return -1;
04228    }
04229    ast_mutex_unlock(&p->lock);
04230 
04231    res = 0;
04232    timeout = 100;
04233    maxloops = 50; /* wait up to 5 seconds */
04234    /* we need to read() until the call is accepted */
04235    while (maxloops > 0) {
04236       maxloops--;
04237       if (ast_check_hangup(chan)) {
04238          break;
04239       }
04240       res = ast_waitfor(chan, timeout);
04241       if (res < 0) {
04242          ast_log(LOG_DEBUG, "ast_waitfor failed on channel %s, going out ...\n", chan->name);
04243          res = -1;
04244          break;
04245       }
04246       if (res == 0) {
04247          continue;
04248       }
04249       f = ast_read(chan);
04250       if (!f) {
04251          ast_log(LOG_DEBUG, "No frame read on channel %s, going out ...\n", chan->name);
04252          res = -1;
04253          break;
04254       }
04255       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) {
04256          ast_log(LOG_DEBUG, "Got HANGUP frame on channel %s, going out ...\n", chan->name);
04257          ast_frfree(f);
04258          res = -1;
04259          break;
04260       }
04261       ast_frfree(f);
04262       ast_mutex_lock(&p->lock);
04263       if (p->mfcr2_call_accepted) {
04264          ast_mutex_unlock(&p->lock);
04265          ast_log(LOG_DEBUG, "Accepted MFC/R2 call!\n");
04266          break;
04267       }
04268       ast_mutex_unlock(&p->lock);
04269    }
04270    if (res == -1) {
04271       ast_log(LOG_WARNING, "Failed to accept MFC/R2 call!\n");
04272    }
04273    return res;
04274 }

static int dahdi_answer ( struct ast_channel *  ast  )  [static]

Definition at line 4727 of file chan_dahdi.c.

References ast_channel::_state, ast_debug, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, ast_tvnow(), dahdi_pvt::call, dahdi_pvt::channel, dahdi_enable_ec(), dahdi_get_index(), dahdi_r2_answer(), dahdi_set_hook(), dahdi_train_ec(), dahdi_subchannel::dfd, dahdi_pvt::dialing, dahdi_pvt::digital, dahdi_pvt::hanguponpolarityswitch, dahdi_subchannel::inthreeway, dahdi_pvt::lock, LOG_DEBUG, LOG_WARNING, dahdi_pvt::mfcr2_answer_pending, dahdi_pvt::mfcr2_call_accepted, dahdi_pvt::mfcr2_charge_calls, ast_channel::name, dahdi_pvt::oprmode, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::polaritydelaytv, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), dahdi_pvt::proceeding, dahdi_pvt::r2chan, dahdi_pvt::radio, dahdi_pvt::ringt, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_MFCR2, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SF_FEATD, SIG_SF_FEATDMF, SIG_SFWINK, SIG_SS7, dahdi_pvt::span, dahdi_ss7::ss7, dahdi_pvt::ss7, ss7_grab(), ss7_rel(), dahdi_pvt::ss7call, SUB_REAL, SUB_THREEWAY, dahdi_pvt::subs, swap_subs(), and ast_channel::tech_pvt.

04728 {
04729    struct dahdi_pvt *p = ast->tech_pvt;
04730    int res = 0;
04731    int idx;
04732    int oldstate = ast->_state;
04733    ast_setstate(ast, AST_STATE_UP);
04734    ast_mutex_lock(&p->lock);
04735    idx = dahdi_get_index(ast, p, 0);
04736    if (idx < 0)
04737       idx = SUB_REAL;
04738    /* nothing to do if a radio channel */
04739    if ((p->radio || (p->oprmode < 0))) {
04740       ast_mutex_unlock(&p->lock);
04741       return 0;
04742    }
04743    switch (p->sig) {
04744    case SIG_FXSLS:
04745    case SIG_FXSGS:
04746    case SIG_FXSKS:
04747       p->ringt = 0;
04748       /* Fall through */
04749    case SIG_EM:
04750    case SIG_EM_E1:
04751    case SIG_EMWINK:
04752    case SIG_FEATD:
04753    case SIG_FEATDMF:
04754    case SIG_FEATDMF_TA:
04755    case SIG_E911:
04756    case SIG_FGC_CAMA:
04757    case SIG_FGC_CAMAMF:
04758    case SIG_FEATB:
04759    case SIG_SF:
04760    case SIG_SFWINK:
04761    case SIG_SF_FEATD:
04762    case SIG_SF_FEATDMF:
04763    case SIG_SF_FEATB:
04764    case SIG_FXOLS:
04765    case SIG_FXOGS:
04766    case SIG_FXOKS:
04767       /* Pick up the line */
04768       ast_debug(1, "Took %s off hook\n", ast->name);
04769       if (p->hanguponpolarityswitch) {
04770          p->polaritydelaytv = ast_tvnow();
04771       }
04772       res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
04773       tone_zone_play_tone(p->subs[idx].dfd, -1);
04774       p->dialing = 0;
04775       if ((idx == SUB_REAL) && p->subs[SUB_THREEWAY].inthreeway) {
04776          if (oldstate == AST_STATE_RINGING) {
04777             ast_debug(1, "Finally swapping real and threeway\n");
04778             tone_zone_play_tone(p->subs[SUB_THREEWAY].dfd, -1);
04779             swap_subs(p, SUB_THREEWAY, SUB_REAL);
04780             p->owner = p->subs[SUB_REAL].owner;
04781          }
04782       }
04783       if (p->sig & __DAHDI_SIG_FXS) {
04784          dahdi_enable_ec(p);
04785          dahdi_train_ec(p);
04786       }
04787       break;
04788 #ifdef HAVE_PRI
04789    case SIG_BRI:
04790    case SIG_BRI_PTMP:
04791    case SIG_PRI:
04792       /* Send a pri acknowledge */
04793       if (!pri_grab(p, p->pri)) {
04794          p->proceeding = 1;
04795          p->dialing = 0;
04796          res = pri_answer(p->pri->pri, p->call, 0, !p->digital);
04797          pri_rel(p->pri);
04798       } else {
04799          ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
04800          res = -1;
04801       }
04802       break;
04803 #endif
04804 #ifdef HAVE_SS7
04805    case SIG_SS7:
04806       if (!ss7_grab(p, p->ss7)) {
04807          p->proceeding = 1;
04808          res = isup_anm(p->ss7->ss7, p->ss7call);
04809          ss7_rel(p->ss7);
04810       } else {
04811          ast_log(LOG_WARNING, "Unable to grab SS7 on span %d\n", p->span);
04812          res = -1;
04813       }
04814       break;
04815 #endif
04816 #ifdef HAVE_OPENR2
04817    case SIG_MFCR2:
04818       if (!p->mfcr2_call_accepted) {
04819          /* The call was not accepted on offer nor the user, so it must be accepted now before answering,
04820             openr2_chan_answer_call will be called when the callback on_call_accepted is executed */
04821          p->mfcr2_answer_pending = 1;
04822          if (p->mfcr2_charge_calls) {
04823             ast_log(LOG_DEBUG, "Accepting MFC/R2 call with charge before answering on chan %d\n", p->channel);
04824             openr2_chan_accept_call(p->r2chan, OR2_CALL_WITH_CHARGE);
04825          } else {
04826             ast_log(LOG_DEBUG, "Accepting MFC/R2 call with no charge before answering on chan %d\n", p->channel);
04827             openr2_chan_accept_call(p->r2chan, OR2_CALL_NO_CHARGE);
04828          }
04829       } else {
04830          ast_log(LOG_DEBUG, "Answering MFC/R2 call on chan %d\n", p->channel);
04831          dahdi_r2_answer(p);
04832       }
04833       break;
04834 #endif
04835    case 0:
04836       ast_mutex_unlock(&p->lock);
04837       return 0;
04838    default:
04839       ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
04840       res = -1;
04841    }
04842    ast_mutex_unlock(&p->lock);
04843    return res;
04844 }

static openr2_call_disconnect_cause_t dahdi_ast_cause_to_r2_cause ( int  cause  )  [static]

Definition at line 4276 of file chan_dahdi.c.

References AST_CAUSE_CALL_REJECTED, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_INTERWORKING, AST_CAUSE_NETWORK_OUT_OF_ORDER, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_NORMAL_CIRCUIT_CONGESTION, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_UNALLOCATED, AST_CAUSE_USER_BUSY, ast_log(), and LOG_DEBUG.

Referenced by dahdi_hangup().

04277 {
04278    openr2_call_disconnect_cause_t r2cause = OR2_CAUSE_NORMAL_CLEARING;
04279    switch (cause) {
04280    case AST_CAUSE_USER_BUSY:
04281    case AST_CAUSE_CALL_REJECTED:
04282    case AST_CAUSE_INTERWORKING: /* I don't know wtf is this but is used sometimes when ekiga rejects a call */
04283       r2cause = OR2_CAUSE_BUSY_NUMBER;
04284       break;
04285 
04286    case AST_CAUSE_NORMAL_CIRCUIT_CONGESTION:
04287    case AST_CAUSE_SWITCH_CONGESTION:
04288       r2cause = OR2_CAUSE_NETWORK_CONGESTION;
04289       break;
04290 
04291    case AST_CAUSE_UNALLOCATED:
04292       r2cause = OR2_CAUSE_UNALLOCATED_NUMBER;
04293       break;
04294 
04295    case AST_CAUSE_NETWORK_OUT_OF_ORDER:
04296    case AST_CAUSE_DESTINATION_OUT_OF_ORDER:
04297       r2cause = OR2_CAUSE_OUT_OF_ORDER;
04298       break;
04299 
04300    case AST_CAUSE_NO_ANSWER:
04301    case AST_CAUSE_NO_USER_RESPONSE:
04302       r2cause = OR2_CAUSE_NO_ANSWER;
04303       break;
04304 
04305    default:
04306       r2cause = OR2_CAUSE_NORMAL_CLEARING;
04307       break;
04308    }
04309    ast_log(LOG_DEBUG, "ast cause %d resulted in openr2 cause %d/%s\n",
04310          cause, r2cause, openr2_proto_get_disconnect_string(r2cause));
04311    return r2cause;
04312 }

static enum ast_bridge_result dahdi_bridge ( struct ast_channel *  c0,
struct ast_channel *  c1,
int  flags,
struct ast_frame **  fo,
struct ast_channel **  rc,
int  timeoutms 
) [static]

Definition at line 5230 of file chan_dahdi.c.

References ast_channel::_state, AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree, ast_log(), ast_mutex_lock(), ast_mutex_trylock(), ast_mutex_unlock(), ast_read(), AST_STATE_RINGING, ast_verb, ast_waitfor_n(), ast_write(), dahdi_pvt::call, dahdi_pvt::channel, CHANNEL_DEADLOCK_AVOIDANCE, dahdi_disable_ec(), dahdi_enable_ec(), dahdi_get_index(), dahdi_link(), dahdi_unlink(), dahdi_subchannel::dfd, disable_dtmf_detect(), dahdi_pvt::echocanbridged, enable_dtmf_detect(), f, ast_channel::fds, ast_frame::frametype, dahdi_pvt::inconference, dahdi_subchannel::inthreeway, dahdi_pri::lock, dahdi_pvt::lock, LOG_NOTICE, LOG_WARNING, master, ast_channel::name, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::pri, dahdi_pvt::pulsedial, dahdi_pvt::sig, SUB_CALLWAIT, SUB_REAL, SUB_THREEWAY, dahdi_pvt::subs, ast_channel::tech_pvt, dahdi_pvt::transfer, and update_conf().

05231 {
05232    struct ast_channel *who;
05233    struct dahdi_pvt *p0, *p1, *op0, *op1;
05234    struct dahdi_pvt *master = NULL, *slave = NULL;
05235    struct ast_frame *f;
05236    int inconf = 0;
05237    int nothingok = 1;
05238    int ofd0, ofd1;
05239    int oi0, oi1, i0 = -1, i1 = -1, t0, t1;
05240    int os0 = -1, os1 = -1;
05241    int priority = 0;
05242    struct ast_channel *oc0, *oc1;
05243    enum ast_bridge_result res;
05244 
05245 #ifdef PRI_2BCT
05246    int triedtopribridge = 0;
05247 #endif
05248 
05249    /* For now, don't attempt to native bridge if either channel needs DTMF detection.
05250       There is code below to handle it properly until DTMF is actually seen,
05251       but due to currently unresolved issues it's ignored...
05252    */
05253 
05254    if (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))
05255       return AST_BRIDGE_FAILED_NOWARN;
05256 
05257    ast_channel_lock(c0);
05258    while (ast_channel_trylock(c1)) {
05259       CHANNEL_DEADLOCK_AVOIDANCE(c0);
05260    }
05261 
05262    p0 = c0->tech_pvt;
05263    p1 = c1->tech_pvt;
05264    /* cant do pseudo-channels here */
05265    if (!p0 || (!p0->sig) || !p1 || (!p1->sig)) {
05266       ast_channel_unlock(c0);
05267       ast_channel_unlock(c1);
05268       return AST_BRIDGE_FAILED_NOWARN;
05269    }
05270 
05271    oi0 = dahdi_get_index(c0, p0, 0);
05272    oi1 = dahdi_get_index(c1, p1, 0);
05273    if ((oi0 < 0) || (oi1 < 0)) {
05274       ast_channel_unlock(c0);
05275       ast_channel_unlock(c1);
05276       return AST_BRIDGE_FAILED;
05277    }
05278 
05279    op0 = p0 = c0->tech_pvt;
05280    op1 = p1 = c1->tech_pvt;
05281    ofd0 = c0->fds[0];
05282    ofd1 = c1->fds[0];
05283    oc0 = p0->owner;
05284    oc1 = p1->owner;
05285 
05286    if (ast_mutex_trylock(&p0->lock)) {
05287       /* Don't block, due to potential for deadlock */
05288       ast_channel_unlock(c0);
05289       ast_channel_unlock(c1);
05290       ast_log(LOG_NOTICE, "Avoiding deadlock...\n");
05291       return AST_BRIDGE_RETRY;
05292    }
05293    if (ast_mutex_trylock(&p1->lock)) {
05294       /* Don't block, due to potential for deadlock */
05295       ast_mutex_unlock(&p0->lock);
05296       ast_channel_unlock(c0);
05297       ast_channel_unlock(c1);
05298       ast_log(LOG_NOTICE, "Avoiding deadlock...\n");
05299       return AST_BRIDGE_RETRY;
05300    }
05301 
05302    if ((oi0 == SUB_REAL) && (oi1 == SUB_REAL)) {
05303       if (p0->owner && p1->owner) {
05304          /* If we don't have a call-wait in a 3-way, and we aren't in a 3-way, we can be master */
05305          if (!p0->subs[SUB_CALLWAIT].inthreeway && !p1->subs[SUB_REAL].inthreeway) {
05306             master = p0;
05307             slave = p1;
05308             inconf = 1;
05309          } else if (!p1->subs[SUB_CALLWAIT].inthreeway && !p0->subs[SUB_REAL].inthreeway) {
05310             master = p1;
05311             slave = p0;
05312             inconf = 1;
05313          } else {
05314             ast_log(LOG_WARNING, "Huh?  Both calls are callwaits or 3-ways?  That's clever...?\n");
05315             ast_log(LOG_WARNING, "p0: chan %d/%d/CW%d/3W%d, p1: chan %d/%d/CW%d/3W%d\n",
05316                p0->channel,
05317                oi0, (p0->subs[SUB_CALLWAIT].dfd > -1) ? 1 : 0,
05318                p0->subs[SUB_REAL].inthreeway, p0->channel,
05319                oi0, (p1->subs[SUB_CALLWAIT].dfd > -1) ? 1 : 0,
05320                p1->subs[SUB_REAL].inthreeway);
05321          }
05322          nothingok = 0;
05323       }
05324    } else if ((oi0 == SUB_REAL) && (oi1 == SUB_THREEWAY)) {
05325       if (p1->subs[SUB_THREEWAY].inthreeway) {
05326          master = p1;
05327          slave = p0;
05328          nothingok = 0;
05329       }
05330    } else if ((oi0 == SUB_THREEWAY) && (oi1 == SUB_REAL)) {
05331       if (p0->subs[SUB_THREEWAY].inthreeway) {
05332          master = p0;
05333          slave = p1;
05334          nothingok = 0;
05335       }
05336    } else if ((oi0 == SUB_REAL) && (oi1 == SUB_CALLWAIT)) {
05337       /* We have a real and a call wait.  If we're in a three way call, put us in it, otherwise,
05338          don't put us in anything */
05339       if (p1->subs[SUB_CALLWAIT].inthreeway) {
05340          master = p1;
05341          slave = p0;
05342          nothingok = 0;
05343       }
05344    } else if ((oi0 == SUB_CALLWAIT) && (oi1 == SUB_REAL)) {
05345       /* Same as previous */
05346       if (p0->subs[SUB_CALLWAIT].inthreeway) {
05347          master = p0;
05348          slave = p1;
05349          nothingok = 0;
05350       }
05351    }
05352    ast_debug(1, "master: %d, slave: %d, nothingok: %d\n",
05353       master ? master->channel : 0, slave ? slave->channel : 0, nothingok);
05354    if (master && slave) {
05355       /* Stop any tones, or play ringtone as appropriate.  If they're bridged
05356          in an active threeway call with a channel that is ringing, we should
05357          indicate ringing. */
05358       if ((oi1 == SUB_THREEWAY) &&
05359          p1->subs[SUB_THREEWAY].inthreeway &&
05360          p1->subs[SUB_REAL].owner &&
05361          p1->subs[SUB_REAL].inthreeway &&
05362          (p1->subs[SUB_REAL].owner->_state == AST_STATE_RINGING)) {
05363          ast_debug(1, "Playing ringback on %s since %s is in a ringing three-way\n", c0->name, c1->name);
05364          tone_zone_play_tone(p0->subs[oi0].dfd, DAHDI_TONE_RINGTONE);
05365          os1 = p1->subs[SUB_REAL].owner->_state;
05366       } else {
05367          ast_debug(1, "Stopping tones on %d/%d talking to %d/%d\n", p0->channel, oi0, p1->channel, oi1);
05368          tone_zone_play_tone(p0->subs[oi0].dfd, -1);
05369       }
05370       if ((oi0 == SUB_THREEWAY) &&
05371          p0->subs[SUB_THREEWAY].inthreeway &&
05372          p0->subs[SUB_REAL].owner &&
05373          p0->subs[SUB_REAL].inthreeway &&
05374          (p0->subs[SUB_REAL].owner->_state == AST_STATE_RINGING)) {
05375          ast_debug(1, "Playing ringback on %s since %s is in a ringing three-way\n", c1->name, c0->name);
05376          tone_zone_play_tone(p1->subs[oi1].dfd, DAHDI_TONE_RINGTONE);
05377          os0 = p0->subs[SUB_REAL].owner->_state;
05378       } else {
05379          ast_debug(1, "Stopping tones on %d/%d talking to %d/%d\n", p1->channel, oi1, p0->channel, oi0);
05380          tone_zone_play_tone(p1->subs[oi0].dfd, -1);
05381       }
05382       if ((oi0 == SUB_REAL) && (oi1 == SUB_REAL)) {
05383          if (!p0->echocanbridged || !p1->echocanbridged) {
05384             /* Disable echo cancellation if appropriate */
05385             dahdi_disable_ec(p0);
05386             dahdi_disable_ec(p1);
05387          }
05388       }
05389       dahdi_link(slave, master);
05390       master->inconference = inconf;
05391    } else if (!nothingok)
05392       ast_log(LOG_WARNING, "Can't link %d/%s with %d/%s\n", p0->channel, subnames[oi0], p1->channel, subnames[oi1]);
05393 
05394    update_conf(p0);
05395    update_conf(p1);
05396    t0 = p0->subs[SUB_REAL].inthreeway;
05397    t1 = p1->subs[SUB_REAL].inthreeway;
05398 
05399    ast_mutex_unlock(&p0->lock);
05400    ast_mutex_unlock(&p1->lock);
05401 
05402    ast_channel_unlock(c0);
05403    ast_channel_unlock(c1);
05404 
05405    /* Native bridge failed */
05406    if ((!master || !slave) && !nothingok) {
05407       dahdi_enable_ec(p0);
05408       dahdi_enable_ec(p1);
05409       return AST_BRIDGE_FAILED;
05410    }
05411 
05412    ast_verb(3, "Native bridging %s and %s\n", c0->name, c1->name);
05413 
05414    if (!(flags & AST_BRIDGE_DTMF_CHANNEL_0) && (oi0 == SUB_REAL))
05415       disable_dtmf_detect(op0);
05416 
05417    if (!(flags & AST_BRIDGE_DTMF_CHANNEL_1) && (oi1 == SUB_REAL))
05418       disable_dtmf_detect(op1);
05419 
05420    for (;;) {
05421       struct ast_channel *c0_priority[2] = {c0, c1};
05422       struct ast_channel *c1_priority[2] = {c1, c0};
05423 
05424       /* Here's our main loop...  Start by locking things, looking for private parts,
05425          and then balking if anything is wrong */
05426 
05427       ast_channel_lock(c0);
05428       while (ast_channel_trylock(c1)) {
05429          CHANNEL_DEADLOCK_AVOIDANCE(c0);
05430       }
05431 
05432       p0 = c0->tech_pvt;
05433       p1 = c1->tech_pvt;
05434 
05435       if (op0 == p0)
05436          i0 = dahdi_get_index(c0, p0, 1);
05437       if (op1 == p1)
05438          i1 = dahdi_get_index(c1, p1, 1);
05439 
05440       ast_channel_unlock(c0);
05441       ast_channel_unlock(c1);
05442 
05443       if (!timeoutms ||
05444          (op0 != p0) ||
05445          (op1 != p1) ||
05446          (ofd0 != c0->fds[0]) ||
05447          (ofd1 != c1->fds[0]) ||
05448          (p0->subs[SUB_REAL].owner && (os0 > -1) && (os0 != p0->subs[SUB_REAL].owner->_state)) ||
05449          (p1->subs[SUB_REAL].owner && (os1 > -1) && (os1 != p1->subs[SUB_REAL].owner->_state)) ||
05450          (oc0 != p0->owner) ||
05451          (oc1 != p1->owner) ||
05452          (t0 != p0->subs[SUB_REAL].inthreeway) ||
05453          (t1 != p1->subs[SUB_REAL].inthreeway) ||
05454          (oi0 != i0) ||
05455          (oi1 != i1)) {
05456          ast_debug(1, "Something changed out on %d/%d to %d/%d, returning -3 to restart\n",
05457             op0->channel, oi0, op1->channel, oi1);
05458          res = AST_BRIDGE_RETRY;
05459          goto return_from_bridge;
05460       }
05461 
05462 #ifdef PRI_2BCT
05463       if (!triedtopribridge) {
05464          triedtopribridge = 1;
05465          if (p0->pri && p0->pri == p1->pri && p0->transfer && p1->transfer) {
05466             ast_mutex_lock(&p0->pri->lock);
05467             if (p0->call && p1->call) {
05468                pri_channel_bridge(p0->call, p1->call);
05469             }
05470             ast_mutex_unlock(&p0->pri->lock);
05471          }
05472       }
05473 #endif
05474 
05475       who = ast_waitfor_n(priority ? c0_priority : c1_priority, 2, &timeoutms);
05476       if (!who) {
05477          ast_debug(1, "Ooh, empty read...\n");
05478          continue;
05479       }
05480       f = ast_read(who);
05481       if (!f || (f->frametype == AST_FRAME_CONTROL)) {
05482          *fo = f;
05483          *rc = who;
05484          res = AST_BRIDGE_COMPLETE;
05485          goto return_from_bridge;
05486       }
05487       if (f->frametype == AST_FRAME_DTMF) {
05488          if ((who == c0) && p0->pulsedial) {
05489             ast_write(c1, f);
05490          } else if ((who == c1) && p1->pulsedial) {
05491             ast_write(c0, f);
05492          } else {
05493             *fo = f;
05494             *rc = who;
05495             res = AST_BRIDGE_COMPLETE;
05496             goto return_from_bridge;
05497          }
05498       }
05499       ast_frfree(f);
05500 
05501       /* Swap who gets priority */
05502       priority = !priority;
05503    }
05504 
05505 return_from_bridge:
05506    if (op0 == p0)
05507       dahdi_enable_ec(p0);
05508 
05509    if (op1 == p1)
05510       dahdi_enable_ec(p1);
05511 
05512    if (!(flags & AST_BRIDGE_DTMF_CHANNEL_0) && (oi0 == SUB_REAL))
05513       enable_dtmf_detect(op0);
05514 
05515    if (!(flags & AST_BRIDGE_DTMF_CHANNEL_1) && (oi1 == SUB_REAL))
05516       enable_dtmf_detect(op1);
05517 
05518    dahdi_unlink(slave, master, 1);
05519 
05520    return res;
05521 }

static int dahdi_call ( struct ast_channel *  ast,
char *  rdest,
int  timeout 
) [static]

Definition at line 3103 of file chan_dahdi.c.

References ast_channel::_state, dahdi_pvt::answeronpolarityswitch, ast_callerid_generate(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_debug, ast_free, AST_LAW, ast_log(), ast_malloc, ast_mutex_lock(), ast_mutex_unlock(), ast_setstate(), AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_RESERVED, AST_STATE_RINGING, AST_STATE_UP, ast_strlen_zero(), ast_transfercapability2str(), ast_tvnow(), ast_verb, dahdi_pvt::bearer, dahdi_pvt::call, dahdi_pvt::call_ref_pc, dahdi_ss7::called_nai, dahdi_ss7::calling_nai, dahdi_pvt::callwait_name, dahdi_pvt::callwait_num, dahdi_pvt::callwaitcas, dahdi_pvt::callwaitrings, CANPROGRESSDETECT, dahdi_pvt::channel, dahdi_pvt::cic, ast_channel::cid, ast_callerid::cid_ani2, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, cid_pres2ss7pres(), cid_pres2ss7screen(), ast_callerid::cid_rdnis, dahdi_pvt::cidlen, dahdi_pvt::cidpos, dahdi_pvt::cidrings, dahdi_pvt::cidspill, dahdi_callwait(), dahdi_get_index(), dahdi_r2_get_channel_category(), dahdi_subchannel::dfd, dahdi_pvt::dialdest, dahdi_pvt::dialednone, dahdi_pvt::dialing, dahdi_pri::dialplan, dialplan2str(), dahdi_pvt::digital, dahdi_pvt::distinctivering, dahdi_pvt::dop, dahdi_pvt::dpc, dahdi_pvt::dsp, dahdi_pvt::echobreak, dahdi_pvt::echorest, dahdi_pvt::echotraining, errno, dahdi_pri::facilityenable, dahdi_pvt::finaldial, dahdi_pvt::gen_add_nai, dahdi_pvt::gen_add_num_plan, dahdi_pvt::gen_add_pres_ind, dahdi_pvt::gen_add_type, dahdi_pvt::gen_dig_scheme, dahdi_pvt::gen_dig_type, dahdi_pvt::hanguponpolarityswitch, dahdi_pvt::hidecallerid, dahdi_pvt::hidecalleridname, dahdi_pri::internationalprefix, dahdi_ss7::internationalprefix, IS_DIGITAL, dahdi_pvt::lastcid_name, dahdi_pvt::lastcid_num, dahdi_pvt::law, dahdi_pri::localdialplan, dahdi_pvt::lock, LOG_DEBUG, LOG_ERROR, LOG_WARNING, dahdi_pvt::logicalspan, dahdi_pvt::lspi_ident, MAX_CALLERID_SIZE, dahdi_pvt::mfcr2, ast_channel::name, dahdi_pri::nationalprefix, dahdi_ss7::nationalprefix, dahdi_subchannel::needbusy, dahdi_subchannel::needringing, dahdi_pri::nodetype, dahdi_pvt::oprmode, dahdi_pvt::outgoing, dahdi_pvt::outsigmod, dahdi_pvt::owner, pbx_builtin_getvar_helper(), dahdi_pvt::polaritydelaytv, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), PRI_TRANS_CAP_DIGITAL, dahdi_pvt::priexclusive, dahdi_pvt::pulse, PVT_TO_CHANNEL, dahdi_pvt::r2chan, dahdi_pvt::radio, dahdi_pvt::rxgain, s, send_callerid(), dahdi_pvt::sendcalleridafter, set_actual_gain(), dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_MFCR2, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SF_FEATD, SIG_SF_FEATDMF, SIG_SFWINK, SIG_SS7, dahdi_ss7::ss7, dahdi_pvt::ss7, ss7_grab(), SS7_NAI_DYNAMIC, ss7_rel(), dahdi_pvt::ss7call, dahdi_pvt::stripmsd, SUB_CALLWAIT, SUB_REAL, dahdi_pvt::subs, ast_channel::tech_pvt, ast_channel::transfercapability, dahdi_pvt::txgain, dahdi_pvt::use_callerid, dahdi_pvt::use_callingpres, dahdi_pvt::waitfordialtone, dahdi_pvt::waitingfordt, and dahdi_pvt::whichwink.

03104 {
03105    struct dahdi_pvt *p = ast->tech_pvt;
03106    int x, res, idx,mysig;
03107    char *c, *n, *l;
03108 #ifdef HAVE_PRI
03109    char *s = NULL;
03110 #endif
03111    char dest[256]; /* must be same length as p->dialdest */
03112    ast_mutex_lock(&p->lock);
03113    ast_copy_string(dest, rdest, sizeof(dest));
03114    ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
03115    if ((ast->_state == AST_STATE_BUSY)) {
03116       p->subs[SUB_REAL].needbusy = 1;
03117       ast_mutex_unlock(&p->lock);
03118       return 0;
03119    }
03120    if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
03121       ast_log(LOG_WARNING, "dahdi_call called on %s, neither down nor reserved\n", ast->name);
03122       ast_mutex_unlock(&p->lock);
03123       return -1;
03124    }
03125    p->waitingfordt.tv_sec = 0;
03126    p->dialednone = 0;
03127    if ((p->radio || (p->oprmode < 0)))  /* if a radio channel, up immediately */
03128    {
03129       /* Special pseudo -- automatically up */
03130       ast_setstate(ast, AST_STATE_UP);
03131       ast_mutex_unlock(&p->lock);
03132       return 0;
03133    }
03134    x = DAHDI_FLUSH_READ | DAHDI_FLUSH_WRITE;
03135    res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_FLUSH, &x);
03136    if (res)
03137       ast_log(LOG_WARNING, "Unable to flush input on channel %d: %s\n", p->channel, strerror(errno));
03138    p->outgoing = 1;
03139 
03140    if (IS_DIGITAL(ast->transfercapability)){
03141       set_actual_gain(p->subs[SUB_REAL].dfd, 0, 0, 0, p->law);
03142    } else {
03143       set_actual_gain(p->subs[SUB_REAL].dfd, 0, p->rxgain, p->txgain, p->law);
03144    }  
03145 
03146    mysig = p->sig;
03147    if (p->outsigmod > -1)
03148       mysig = p->outsigmod;
03149 
03150    switch (mysig) {
03151    case SIG_FXOLS:
03152    case SIG_FXOGS:
03153    case SIG_FXOKS:
03154       if (p->owner == ast) {
03155          /* Normal ring, on hook */
03156 
03157          /* Don't send audio while on hook, until the call is answered */
03158          p->dialing = 1;
03159          if (p->use_callerid) {
03160             /* Generate the Caller-ID spill if desired */
03161             if (p->cidspill) {
03162                ast_log(LOG_WARNING, "cidspill already exists??\n");
03163                ast_free(p->cidspill);
03164             }
03165             p->callwaitcas = 0;
03166             if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
03167                p->cidlen = ast_callerid_generate(p->cidspill, ast->cid.cid_name, ast->cid.cid_num, AST_LAW(p));
03168                p->cidpos = 0;
03169                send_callerid(p);
03170             }
03171          }
03172          /* Choose proper cadence */
03173          if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
03174             if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
03175                ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
03176             p->cidrings = cidrings[p->distinctivering - 1];
03177          } else {
03178             if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
03179                ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
03180             p->cidrings = p->sendcalleridafter;
03181          }
03182 
03183          /* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
03184          c = strchr(dest, '/');
03185          if (c)
03186             c++;
03187          if (c && (strlen(c) < p->stripmsd)) {
03188             ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
03189             c = NULL;
03190          }
03191          if (c) {
03192             p->dop.op = DAHDI_DIAL_OP_REPLACE;
03193             snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
03194             ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
03195          } else {
03196             p->dop.dialstr[0] = '\0';
03197          }
03198          x = DAHDI_RING;
03199          if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x) && (errno != EINPROGRESS)) {
03200             ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
03201             ast_mutex_unlock(&p->lock);
03202             return -1;
03203          }
03204          p->dialing = 1;
03205       } else {
03206          /* Call waiting call */
03207          p->callwaitrings = 0;
03208          if (ast->cid.cid_num)
03209             ast_copy_string(p->callwait_num, ast->cid.cid_num, sizeof(p->callwait_num));
03210          else
03211             p->callwait_num[0] = '\0';
03212          if (ast->cid.cid_name)
03213             ast_copy_string(p->callwait_name, ast->cid.cid_name, sizeof(p->callwait_name));
03214          else
03215             p->callwait_name[0] = '\0';
03216          /* Call waiting tone instead */
03217          if (dahdi_callwait(ast)) {
03218             ast_mutex_unlock(&p->lock);
03219             return -1;
03220          }
03221          /* Make ring-back */
03222          if (tone_zone_play_tone(p->subs[SUB_CALLWAIT].dfd, DAHDI_TONE_RINGTONE))
03223             ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast->name);
03224       }
03225       n = ast->cid.cid_name;
03226       l = ast->cid.cid_num;
03227       if (l)
03228          ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
03229       else
03230          p->lastcid_num[0] = '\0';
03231       if (n)
03232          ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
03233       else
03234          p->lastcid_name[0] = '\0';
03235       ast_setstate(ast, AST_STATE_RINGING);
03236       idx = dahdi_get_index(ast, p, 0);
03237       if (idx > -1) {
03238          p->subs[idx].needringing = 1;
03239       }
03240       break;
03241    case SIG_FXSLS:
03242    case SIG_FXSGS:
03243    case SIG_FXSKS:
03244       if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
03245          ast_debug(1, "Ignore possible polarity reversal on line seizure\n");
03246          p->polaritydelaytv = ast_tvnow();
03247       }
03248       /* fall through */
03249    case SIG_EMWINK:
03250    case SIG_EM:
03251    case SIG_EM_E1:
03252    case SIG_FEATD:
03253    case SIG_FEATDMF:
03254    case SIG_E911:
03255    case SIG_FGC_CAMA:
03256    case SIG_FGC_CAMAMF:
03257    case SIG_FEATB:
03258    case SIG_SFWINK:
03259    case SIG_SF:
03260    case SIG_SF_FEATD:
03261    case SIG_SF_FEATDMF:
03262    case SIG_FEATDMF_TA:
03263    case SIG_SF_FEATB:
03264       c = strchr(dest, '/');
03265       if (c)
03266          c++;
03267       else
03268          c = "";
03269       if (strlen(c) < p->stripmsd) {
03270          ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
03271          ast_mutex_unlock(&p->lock);
03272          return -1;
03273       }
03274 #ifdef HAVE_PRI
03275       /* Start the trunk, if not GR-303 */
03276       if (!p->pri) {
03277 #endif
03278          x = DAHDI_START;
03279          res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
03280          if (res < 0) {
03281             if (errno != EINPROGRESS) {
03282                ast_log(LOG_WARNING, "Unable to start channel: %s\n", strerror(errno));
03283                ast_mutex_unlock(&p->lock);
03284                return -1;
03285             }
03286          }
03287 #ifdef HAVE_PRI
03288       }
03289 #endif
03290       ast_debug(1, "Dialing '%s'\n", c);
03291       p->dop.op = DAHDI_DIAL_OP_REPLACE;
03292 
03293       c += p->stripmsd;
03294 
03295       switch (mysig) {
03296       case SIG_FEATD:
03297          l = ast->cid.cid_num;
03298          if (l)
03299             snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
03300          else
03301             snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
03302          break;
03303       case SIG_FEATDMF:
03304          l = ast->cid.cid_num;
03305          if (l)
03306             snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
03307          else
03308             snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
03309          break;
03310       case SIG_FEATDMF_TA:
03311       {
03312          const char *cic, *ozz;
03313 
03314          /* If you have to go through a Tandem Access point you need to use this */
03315          ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
03316          if (!ozz)
03317             ozz = defaultozz;
03318          cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
03319          if (!cic)
03320             cic = defaultcic;
03321          if (!ozz || !cic) {
03322             ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
03323             ast_mutex_unlock(&p->lock);
03324             return -1;
03325          }
03326          snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
03327          snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
03328          p->whichwink = 0;
03329       }
03330          break;
03331       case SIG_E911:
03332          ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
03333          break;
03334       case SIG_FGC_CAMA:
03335          snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
03336          break;
03337       case SIG_FGC_CAMAMF:
03338       case SIG_FEATB:
03339          snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
03340          break;
03341       default:
03342          if (p->pulse)
03343             snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
03344          else
03345             snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
03346          break;
03347       }
03348 
03349       if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
03350          memset(p->echorest, 'w', sizeof(p->echorest) - 1);
03351          strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
03352          p->echorest[sizeof(p->echorest) - 1] = '\0';
03353          p->echobreak = 1;
03354          p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
03355       } else
03356          p->echobreak = 0;
03357 
03358       /* waitfordialtone ? */
03359 #ifdef HAVE_PRI
03360       if (!p->pri) {
03361 #endif
03362          if( p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp ) {
03363             ast_log(LOG_DEBUG, "Defer dialling for %dms or dialtone\n", p->waitfordialtone);
03364             gettimeofday(&p->waitingfordt,NULL);
03365             ast_setstate(ast, AST_STATE_OFFHOOK);
03366             break;
03367          }
03368 #ifdef HAVE_PRI
03369       }
03370 #endif
03371       if (!res) {
03372          if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop)) {
03373             int saveerr = errno;
03374 
03375             x = DAHDI_ONHOOK;
03376             ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
03377             ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(saveerr));
03378             ast_mutex_unlock(&p->lock);
03379             return -1;
03380          }
03381       } else
03382          ast_debug(1, "Deferring dialing...\n");
03383 
03384       p->dialing = 1;
03385       if (ast_strlen_zero(c))
03386          p->dialednone = 1;
03387       ast_setstate(ast, AST_STATE_DIALING);
03388       break;
03389    case 0:
03390       /* Special pseudo -- automatically up*/
03391       ast_setstate(ast, AST_STATE_UP);
03392       break;
03393    case SIG_PRI:
03394    case SIG_BRI:
03395    case SIG_BRI_PTMP:
03396    case SIG_SS7:
03397    case SIG_MFCR2:
03398       /* We'll get it in a moment -- but use dialdest to store pre-setup_ack digits */
03399       p->dialdest[0] = '\0';
03400       p->dialing = 1;
03401       break;
03402    default:
03403       ast_debug(1, "not yet implemented\n");
03404       ast_mutex_unlock(&p->lock);
03405       return -1;
03406    }
03407 #ifdef HAVE_SS7
03408    if (p->ss7) {
03409       char ss7_called_nai;
03410       int called_nai_strip;
03411       char ss7_calling_nai;
03412       int calling_nai_strip;
03413       const char *charge_str = NULL;
03414       const char *gen_address = NULL;
03415       const char *gen_digits = NULL;
03416       const char *gen_dig_type = NULL;
03417       const char *gen_dig_scheme = NULL;
03418       const char *gen_name = NULL;
03419       const char *jip_digits = NULL;
03420       const char *lspi_ident = NULL;
03421       const char *rlt_flag = NULL;
03422       const char *call_ref_id = NULL;
03423       const char *call_ref_pc = NULL;
03424       const char *send_far = NULL;
03425 
03426       c = strchr(dest, '/');
03427       if (c) {
03428          c++;
03429       } else {
03430          c = "";
03431       }
03432       if (strlen(c) < p->stripmsd) {
03433          ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
03434          ast_mutex_unlock(&p->lock);
03435          return -1;
03436       }
03437 
03438       if (!p->hidecallerid) {
03439          l = ast->cid.cid_num;
03440       } else {
03441          l = NULL;
03442       }
03443 
03444       if (ss7_grab(p, p->ss7)) {
03445          ast_log(LOG_WARNING, "Failed to grab SS7!\n");
03446          ast_mutex_unlock(&p->lock);
03447          return -1;
03448       }
03449       p->digital = IS_DIGITAL(ast->transfercapability);
03450       p->ss7call = isup_new_call(p->ss7->ss7);
03451 
03452       if (!p->ss7call) {
03453          ss7_rel(p->ss7);
03454          ast_mutex_unlock(&p->lock);
03455          ast_log(LOG_ERROR, "Unable to allocate new SS7 call!\n");
03456          return -1;
03457       }
03458 
03459       called_nai_strip = 0;
03460       ss7_called_nai = p->ss7->called_nai;
03461       if (ss7_called_nai == SS7_NAI_DYNAMIC) { /* compute dynamically */
03462          if (strncmp(c + p->stripmsd, p->ss7->internationalprefix, strlen(p->ss7->internationalprefix)) == 0) {
03463             called_nai_strip = strlen(p->ss7->internationalprefix);
03464             ss7_called_nai = SS7_NAI_INTERNATIONAL;
03465          } else if (strncmp(c + p->stripmsd, p->ss7->nationalprefix, strlen(p->ss7->nationalprefix)) == 0) {
03466             called_nai_strip = strlen(p->ss7->nationalprefix);
03467             ss7_called_nai = SS7_NAI_NATIONAL;
03468          } else {
03469             ss7_called_nai = SS7_NAI_SUBSCRIBER;
03470          }
03471       }
03472       isup_set_called(p->ss7call, c + p->stripmsd + called_nai_strip, ss7_called_nai, p->ss7->ss7);
03473 
03474       calling_nai_strip = 0;
03475       ss7_calling_nai = p->ss7->calling_nai;
03476       if ((l != NULL) && (ss7_calling_nai == SS7_NAI_DYNAMIC)) { /* compute dynamically */
03477          if (strncmp(l, p->ss7->internationalprefix, strlen(p->ss7->internationalprefix)) == 0) {
03478             calling_nai_strip = strlen(p->ss7->internationalprefix);
03479             ss7_calling_nai = SS7_NAI_INTERNATIONAL;
03480          } else if (strncmp(l, p->ss7->nationalprefix, strlen(p->ss7->nationalprefix)) == 0) {
03481             calling_nai_strip = strlen(p->ss7->nationalprefix);
03482             ss7_calling_nai = SS7_NAI_NATIONAL;
03483          } else {
03484             ss7_calling_nai = SS7_NAI_SUBSCRIBER;
03485          }
03486       }
03487       isup_set_calling(p->ss7call, l ? (l + calling_nai_strip) : NULL, ss7_calling_nai,
03488          p->use_callingpres ? cid_pres2ss7pres(ast->cid.cid_pres) : (l ? SS7_PRESENTATION_ALLOWED : SS7_PRESENTATION_RESTRICTED),
03489          p->use_callingpres ? cid_pres2ss7screen(ast->cid.cid_pres) : SS7_SCREENING_USER_PROVIDED );
03490 
03491       isup_set_oli(p->ss7call, ast->cid.cid_ani2);
03492       isup_init_call(p->ss7->ss7, p->ss7call, p->cic, p->dpc);
03493 
03494       ast_channel_lock(ast);
03495       /* Set the charge number if it is set */
03496       charge_str = pbx_builtin_getvar_helper(ast, "SS7_CHARGE_NUMBER");
03497       if (charge_str)
03498          isup_set_charge(p->ss7call, charge_str, SS7_ANI_CALLING_PARTY_SUB_NUMBER, 0x10);
03499 
03500       gen_address = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_ADDRESS");
03501       if (gen_address)
03502          isup_set_gen_address(p->ss7call, gen_address, p->gen_add_nai,p->gen_add_pres_ind, p->gen_add_num_plan,p->gen_add_type); /* need to add some types here for NAI,PRES,TYPE */
03503 
03504       gen_digits = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_DIGITS");
03505       gen_dig_type = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_DIGTYPE");
03506       gen_dig_scheme = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_DIGSCHEME");
03507       if (gen_digits)
03508          isup_set_gen_digits(p->ss7call, gen_digits, atoi(gen_dig_type), atoi(gen_dig_scheme));
03509 
03510       gen_name = pbx_builtin_getvar_helper(ast, "SS7_GENERIC_NAME");
03511       if (gen_name)
03512          isup_set_generic_name(p->ss7call, gen_name, GEN_NAME_TYPE_CALLING_NAME, GEN_NAME_AVAIL_AVAILABLE, GEN_NAME_PRES_ALLOWED);
03513 
03514       jip_digits = pbx_builtin_getvar_helper(ast, "SS7_JIP");
03515       if (jip_digits)
03516          isup_set_jip_digits(p->ss7call, jip_digits);
03517 
03518       lspi_ident = pbx_builtin_getvar_helper(ast, "SS7_LSPI_IDENT");
03519       if (lspi_ident)
03520          isup_set_lspi(p->ss7call, lspi_ident, 0x18, 0x7, 0x00);
03521 
03522       rlt_flag = pbx_builtin_getvar_helper(ast, "SS7_RLT_ON");
03523       if ((rlt_flag) && ((strncmp("NO", rlt_flag, strlen(rlt_flag))) != 0 )) {
03524          isup_set_lspi(p->ss7call, rlt_flag, 0x18, 0x7, 0x00); /* Setting for Nortel DMS-250/500 */
03525       }
03526 
03527       call_ref_id = pbx_builtin_getvar_helper(ast, "SS7_CALLREF_IDENT");
03528       call_ref_pc = pbx_builtin_getvar_helper(ast, "SS7_CALLREF_PC");
03529       if (call_ref_id && call_ref_pc) {
03530          isup_set_callref(p->ss7call, atoi(call_ref_id),
03531                 call_ref_pc ? atoi(call_ref_pc) : 0);
03532       }
03533 
03534       send_far = pbx_builtin_getvar_helper(ast, "SS7_SEND_FAR");
03535       if ((send_far) && ((strncmp("NO", send_far, strlen(send_far))) != 0 ))
03536          (isup_far(p->ss7->ss7, p->ss7call));
03537 
03538       ast_channel_unlock(ast);
03539 
03540       isup_iam(p->ss7->ss7, p->ss7call);
03541       ast_setstate(ast, AST_STATE_DIALING);
03542       ss7_rel(p->ss7);
03543    }
03544 #endif /* HAVE_SS7 */
03545 #ifdef HAVE_OPENR2
03546    if (p->mfcr2) {
03547       openr2_calling_party_category_t chancat;
03548       int callres = 0;
03549       char *c, *l;
03550 
03551       c = strchr(dest, '/');
03552       if (c) {
03553          c++;
03554       } else {
03555          c = "";
03556       }
03557       if (!p->hidecallerid) {
03558          l = ast->cid.cid_num;
03559       } else {
03560          l = NULL;
03561       }
03562       if (strlen(c) < p->stripmsd) {
03563          ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
03564          ast_mutex_unlock(&p->lock);
03565          return -1;
03566       }
03567       p->dialing = 1;
03568       ast_channel_lock(ast);
03569       chancat = dahdi_r2_get_channel_category(ast);
03570       ast_channel_unlock(ast);
03571       callres = openr2_chan_make_call(p->r2chan, l, (c + p->stripmsd), chancat);
03572       if (-1 == callres) {
03573          ast_mutex_unlock(&p->lock);
03574          ast_log(LOG_ERROR, "unable to make new MFC/R2 call!\n");
03575          return -1;
03576       }
03577       ast_setstate(ast, AST_STATE_DIALING);
03578    }
03579 #endif /* HAVE_OPENR2 */
03580 #ifdef HAVE_PRI
03581    if (p->pri) {
03582       struct pri_sr *sr;
03583 #ifdef SUPPORT_USERUSER
03584       const char *useruser;
03585 #endif
03586       int pridialplan;
03587       int dp_strip;
03588       int prilocaldialplan;
03589       int ldp_strip;
03590       int exclusive;
03591       const char *rr_str;
03592       int redirect_reason;
03593 
03594       c = strchr(dest, '/');
03595       if (c) {
03596          c++;
03597       } else {
03598          c = "";
03599       }
03600 
03601       l = NULL;
03602       n = NULL;
03603       if (!p->hidecallerid) {
03604          l = ast->cid.cid_num;
03605          if (!p->hidecalleridname) {
03606             n = ast->cid.cid_name;
03607          }
03608       }
03609 
03610       if (strlen(c) < p->stripmsd) {
03611          ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
03612          ast_mutex_unlock(&p->lock);
03613          return -1;
03614       }
03615       if (mysig != SIG_FXSKS) {
03616          p->dop.op = DAHDI_DIAL_OP_REPLACE;
03617          s = strchr(c + p->stripmsd, 'w');
03618          if (s) {
03619             if (strlen(s) > 1)
03620                snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%s", s);
03621             else
03622                p->dop.dialstr[0] = '\0';
03623             *s = '\0';
03624          } else {
03625             p->dop.dialstr[0] = '\0';
03626          }
03627       }
03628       if (pri_grab(p, p->pri)) {
03629          ast_log(LOG_WARNING, "Failed to grab PRI!\n");
03630          ast_mutex_unlock(&p->lock);
03631          return -1;
03632       }
03633       if (!(p->call = pri_new_call(p->pri->pri))) {
03634          ast_log(LOG_WARNING, "Unable to create call on channel %d\n", p->channel);
03635          pri_rel(p->pri);
03636          ast_mutex_unlock(&p->lock);
03637          return -1;
03638       }
03639       if (!(sr = pri_sr_new())) {
03640          ast_log(LOG_WARNING, "Failed to allocate setup request channel %d\n", p->channel);
03641          pri_rel(p->pri);
03642          ast_mutex_unlock(&p->lock);
03643       }
03644       if (p->bearer || (mysig == SIG_FXSKS)) {
03645          if (p->bearer) {
03646             ast_debug(1, "Oooh, I have a bearer on %d (%d:%d)\n", PVT_TO_CHANNEL(p->bearer), p->bearer->logicalspan, p->bearer->channel);
03647             p->bearer->call = p->call;
03648          } else
03649             ast_debug(1, "I'm being setup with no bearer right now...\n");
03650 
03651          pri_set_crv(p->pri->pri, p->call, p->channel, 0);
03652       }
03653       p->digital = IS_DIGITAL(ast->transfercapability);
03654 
03655       /* Should the picked channel be used exclusively? */
03656       if (p->priexclusive || p->pri->nodetype == PRI_NETWORK) {
03657          exclusive = 1;
03658       } else {
03659          exclusive = 0;
03660       }
03661 
03662       pri_sr_set_channel(sr, p->bearer ? PVT_TO_CHANNEL(p->bearer) : PVT_TO_CHANNEL(p), exclusive, 1);
03663       pri_sr_set_bearer(sr, p->digital ? PRI_TRANS_CAP_DIGITAL : ast->transfercapability,
03664          (p->digital ? -1 :
03665             ((p->law == DAHDI_LAW_ALAW) ? PRI_LAYER_1_ALAW : PRI_LAYER_1_ULAW)));
03666       if (p->pri->facilityenable)
03667          pri_facility_enable(p->pri->pri);
03668 
03669       ast_verb(3, "Requested transfer capability: 0x%.2x - %s\n", ast->transfercapability, ast_transfercapability2str(ast->transfercapability));
03670 
03671       dp_strip = 0;
03672       pridialplan = p->pri->dialplan - 1;
03673       if (pridialplan == -2 || pridialplan == -3) { /* compute dynamically */
03674          if (strncmp(c + p->stripmsd, p->pri->internationalprefix, strlen(p->pri->internationalprefix)) == 0) {
03675             if (pridialplan == -2) {
03676                dp_strip = strlen(p->pri->internationalprefix);
03677             }
03678             pridialplan = PRI_INTERNATIONAL_ISDN;
03679          } else if (strncmp(c + p->stripmsd, p->pri->nationalprefix, strlen(p->pri->nationalprefix)) == 0) {
03680             if (pridialplan == -2) {
03681                dp_strip = strlen(p->pri->nationalprefix);
03682             }
03683             pridialplan = PRI_NATIONAL_ISDN;
03684          } else {
03685             pridialplan = PRI_LOCAL_ISDN;
03686          }
03687       }
03688       while (c[p->stripmsd] > '9' && c[p->stripmsd] != '*' && c[p->stripmsd] != '#') {
03689          switch (c[p->stripmsd]) {
03690          case 'U':
03691             pridialplan = (PRI_TON_UNKNOWN << 4) | (pridialplan & 0xf);
03692             break;
03693          case 'I':
03694             pridialplan = (PRI_TON_INTERNATIONAL << 4) | (pridialplan & 0xf);
03695             break;
03696          case 'N':
03697             pridialplan = (PRI_TON_NATIONAL << 4) | (pridialplan & 0xf);
03698             break;
03699          case 'L':
03700             pridialplan = (PRI_TON_NET_SPECIFIC << 4) | (pridialplan & 0xf);
03701             break;
03702          case 'S':
03703             pridialplan = (PRI_TON_SUBSCRIBER << 4) | (pridialplan & 0xf);
03704             break;
03705          case 'V':
03706             pridialplan = (PRI_TON_ABBREVIATED << 4) | (pridialplan & 0xf);
03707             break;
03708          case 'R':
03709             pridialplan = (PRI_TON_RESERVED << 4) | (pridialplan & 0xf);
03710             break;
03711          case 'u':
03712             pridialplan = PRI_NPI_UNKNOWN | (pridialplan & 0xf0);
03713             break;
03714          case 'e':
03715             pridialplan = PRI_NPI_E163_E164 | (pridialplan & 0xf0);
03716             break;
03717          case 'x':
03718             pridialplan = PRI_NPI_X121 | (pridialplan & 0xf0);
03719             break;
03720          case 'f':
03721             pridialplan = PRI_NPI_F69 | (pridialplan & 0xf0);
03722             break;
03723          case 'n':
03724             pridialplan = PRI_NPI_NATIONAL | (pridialplan & 0xf0);
03725             break;
03726          case 'p':
03727             pridialplan = PRI_NPI_PRIVATE | (pridialplan & 0xf0);
03728             break;
03729          case 'r':
03730             pridialplan = PRI_NPI_RESERVED | (pridialplan & 0xf0);
03731             break;
03732          default:
03733             if (isalpha(c[p->stripmsd])) {
03734                ast_log(LOG_WARNING, "Unrecognized pridialplan %s modifier: %c\n",
03735                   c[p->stripmsd] > 'Z' ? "NPI" : "TON", c[p->stripmsd]);
03736             }
03737             break;
03738          }
03739          c++;
03740       }
03741       pri_sr_set_called(sr, c + p->stripmsd + dp_strip, pridialplan, s ? 1 : 0);
03742 
03743       ldp_strip = 0;
03744       prilocaldialplan = p->pri->localdialplan - 1;
03745       if ((l != NULL) && (prilocaldialplan == -2 || prilocaldialplan == -3)) { /* compute dynamically */
03746          if (strncmp(l, p->pri->internationalprefix, strlen(p->pri->internationalprefix)) == 0) {
03747             if (prilocaldialplan == -2) {
03748                ldp_strip = strlen(p->pri->internationalprefix);
03749             }
03750             prilocaldialplan = PRI_INTERNATIONAL_ISDN;
03751          } else if (strncmp(l, p->pri->nationalprefix, strlen(p->pri->nationalprefix)) == 0) {
03752             if (prilocaldialplan == -2) {
03753                ldp_strip = strlen(p->pri->nationalprefix);
03754             }
03755             prilocaldialplan = PRI_NATIONAL_ISDN;
03756          } else {
03757             prilocaldialplan = PRI_LOCAL_ISDN;
03758          }
03759       }
03760       if (l != NULL) {
03761          while (*l > '9' && *l != '*' && *l != '#') {
03762             switch (*l) {
03763             case 'U':
03764                prilocaldialplan = (PRI_TON_UNKNOWN << 4) | (prilocaldialplan & 0xf);
03765                break;
03766             case 'I':
03767                prilocaldialplan = (PRI_TON_INTERNATIONAL << 4) | (prilocaldialplan & 0xf);
03768                break;
03769             case 'N':
03770                prilocaldialplan = (PRI_TON_NATIONAL << 4) | (prilocaldialplan & 0xf);
03771                break;
03772             case 'L':
03773                prilocaldialplan = (PRI_TON_NET_SPECIFIC << 4) | (prilocaldialplan & 0xf);
03774                break;
03775             case 'S':
03776                prilocaldialplan = (PRI_TON_SUBSCRIBER << 4) | (prilocaldialplan & 0xf);
03777                break;
03778             case 'V':
03779                prilocaldialplan = (PRI_TON_ABBREVIATED << 4) | (prilocaldialplan & 0xf);
03780                break;
03781             case 'R':
03782                prilocaldialplan = (PRI_TON_RESERVED << 4) | (prilocaldialplan & 0xf);
03783                break;
03784             case 'u':
03785                prilocaldialplan = PRI_NPI_UNKNOWN | (prilocaldialplan & 0xf0);
03786                break;
03787             case 'e':
03788                prilocaldialplan = PRI_NPI_E163_E164 | (prilocaldialplan & 0xf0);
03789                break;
03790             case 'x':
03791                prilocaldialplan = PRI_NPI_X121 | (prilocaldialplan & 0xf0);
03792                break;
03793             case 'f':
03794                prilocaldialplan = PRI_NPI_F69 | (prilocaldialplan & 0xf0);
03795                break;
03796             case 'n':
03797                prilocaldialplan = PRI_NPI_NATIONAL | (prilocaldialplan & 0xf0);
03798                break;
03799             case 'p':
03800                prilocaldialplan = PRI_NPI_PRIVATE | (prilocaldialplan & 0xf0);
03801                break;
03802             case 'r':
03803                prilocaldialplan = PRI_NPI_RESERVED | (prilocaldialplan & 0xf0);
03804                break;
03805             default:
03806                if (isalpha(*l)) {
03807                   ast_log(LOG_WARNING,
03808                      "Unrecognized prilocaldialplan %s modifier: %c\n",
03809                      *l > 'Z' ? "NPI" : "TON", *l);
03810                }
03811                break;
03812             }
03813             l++;
03814          }
03815       }
03816       pri_sr_set_caller(sr, l ? (l + ldp_strip) : NULL, n, prilocaldialplan,
03817          p->use_callingpres ? ast->cid.cid_pres : (l ? PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN : PRES_NUMBER_NOT_AVAILABLE));
03818       if ((rr_str = pbx_builtin_getvar_helper(ast, "PRIREDIRECTREASON"))) {
03819          if (!strcasecmp(rr_str, "UNKNOWN"))
03820             redirect_reason = 0;
03821          else if (!strcasecmp(rr_str, "BUSY"))
03822             redirect_reason = 1;
03823          else if (!strcasecmp(rr_str, "NO_REPLY") || !strcasecmp(rr_str, "NOANSWER"))
03824          /* the NOANSWER is to match diversion-reason from chan_sip, (which never reads PRIREDIRECTREASON) */
03825             redirect_reason = 2;
03826          else if (!strcasecmp(rr_str, "UNCONDITIONAL"))
03827             redirect_reason = 15;
03828          else
03829             redirect_reason = PRI_REDIR_UNCONDITIONAL;
03830       } else
03831          redirect_reason = PRI_REDIR_UNCONDITIONAL;
03832       pri_sr_set_redirecting(sr, ast->cid.cid_rdnis, p->pri->localdialplan - 1, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, redirect_reason);
03833 
03834 #ifdef SUPPORT_USERUSER
03835       /* User-user info */
03836       useruser = pbx_builtin_getvar_helper(p->owner, "USERUSERINFO");
03837       if (useruser)
03838          pri_sr_set_useruser(sr, useruser);
03839 #endif
03840 
03841       if (pri_setup(p->pri->pri, p->call, sr)) {
03842          ast_log(LOG_WARNING, "Unable to setup call to %s (using %s)\n",
03843             c + p->stripmsd + dp_strip, dialplan2str(p->pri->dialplan));
03844          pri_rel(p->pri);
03845          ast_mutex_unlock(&p->lock);
03846          pri_sr_free(sr);
03847          return -1;
03848       }
03849       pri_sr_free(sr);
03850       ast_setstate(ast, AST_STATE_DIALING);
03851       pri_rel(p->pri);
03852    }
03853 #endif
03854    ast_mutex_unlock(&p->lock);
03855    return 0;
03856 }

static int dahdi_callwait ( struct ast_channel *  ast  )  [static]

Definition at line 3061 of file chan_dahdi.c.

References ast_free, ast_gen_cas(), AST_LAW, ast_log(), ast_malloc, dahdi_pvt::callwaitcas, CALLWAITING_REPEAT_SAMPLES, dahdi_pvt::callwaitingcallerid, dahdi_pvt::callwaitingrepeat, dahdi_pvt::callwaitrings, dahdi_pvt::cidlen, dahdi_pvt::cidpos, dahdi_pvt::cidspill, LOG_WARNING, READ_SIZE, save_conference(), send_callerid(), and ast_channel::tech_pvt.

Referenced by dahdi_call(), and dahdi_read().

03062 {
03063    struct dahdi_pvt *p = ast->tech_pvt;
03064    p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
03065    if (p->cidspill) {
03066       ast_log(LOG_WARNING, "Spill already exists?!?\n");
03067       ast_free(p->cidspill);
03068    }
03069    if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
03070       return -1;
03071    save_conference(p);
03072    /* Silence */
03073    memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
03074    if (!p->callwaitrings && p->callwaitingcallerid) {
03075       ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
03076       p->callwaitcas = 1;
03077       p->cidlen = 2400 + 680 + READ_SIZE * 4;
03078    } else {
03079       ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
03080       p->callwaitcas = 0;
03081       p->cidlen = 2400 + READ_SIZE * 4;
03082    }
03083    p->cidpos = 0;
03084    send_callerid(p);
03085 
03086    return 0;
03087 }

static struct dahdi_chan_conf dahdi_chan_conf_default ( void   )  [static, read]

returns a new dahdi_chan_conf with default values (by-value)

Definition at line 1266 of file chan_dahdi.c.

References CID_SIG_BELL, CID_START_RING, DAHDI_CHAN_MAPPING_PHYSICAL, DEFAULT_CIDRINGS, dahdi_pri::nsf, and dahdi_chan_conf::pri.

Referenced by process_dahdi(), and setup_dahdi().

01267 {
01268    /* recall that if a field is not included here it is initialized
01269     * to 0 or equivalent
01270     */
01271    struct dahdi_chan_conf conf = {
01272 #ifdef HAVE_PRI
01273       .pri = {
01274          .nsf = PRI_NSF_NONE,
01275          .switchtype = PRI_SWITCH_NI2,
01276          .dialplan = PRI_UNKNOWN + 1,
01277          .localdialplan = PRI_NATIONAL_ISDN + 1,
01278          .nodetype = PRI_CPE,
01279          .qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
01280 
01281          .minunused = 2,
01282          .idleext = "",
01283          .idledial = "",
01284          .internationalprefix = "",
01285          .nationalprefix = "",
01286          .localprefix = "",
01287          .privateprefix = "",
01288          .unknownprefix = "",
01289          .resetinterval = -1,
01290       },
01291 #endif
01292 #ifdef HAVE_SS7
01293       .ss7 = {
01294          .called_nai = SS7_NAI_NATIONAL,
01295          .calling_nai = SS7_NAI_NATIONAL,
01296          .internationalprefix = "",
01297          .nationalprefix = "",
01298          .subscriberprefix = "",
01299          .unknownprefix = ""
01300       },
01301 #endif
01302 #ifdef HAVE_OPENR2
01303       .mfcr2 = {
01304          .variant = OR2_VAR_ITU,
01305          .mfback_timeout = -1,
01306          .metering_pulse_timeout = -1,
01307          .max_ani = 10,
01308          .max_dnis = 4,
01309          .get_ani_first = -1,
01310 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
01311          .skip_category_request = -1,
01312 #endif
01313          .call_files = 0,
01314          .allow_collect_calls = 0,
01315          .charge_calls = 1,
01316          .accept_on_offer = 1,
01317          .forced_release = 0,
01318          .double_answer = 0,
01319          .immediate_accept = -1,
01320          .logdir = "",
01321          .r2proto_file = "",
01322          .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
01323          .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
01324       },
01325 #endif
01326       .chan = {
01327          .context = "default",
01328          .cid_num = "",
01329          .cid_name = "",
01330          .mohinterpret = "default",
01331          .mohsuggest = "",
01332          .parkinglot = "",
01333          .transfertobusy = 1,
01334 
01335          .cid_signalling = CID_SIG_BELL,
01336          .cid_start = CID_START_RING,
01337          .dahditrcallerid = 0,
01338          .use_callerid = 1,
01339          .sig = -1,
01340          .outsigmod = -1,
01341 
01342          .cid_rxgain = +5.0,
01343 
01344          .tonezone = -1,
01345 
01346          .echocancel.head.tap_length = 1,
01347 
01348          .busycount = 3,
01349 
01350          .accountcode = "",
01351 
01352          .mailbox = "",
01353 
01354 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
01355          .mwisend_fsk = 1,
01356 #endif
01357          .polarityonanswerdelay = 600,
01358 
01359          .sendcalleridafter = DEFAULT_CIDRINGS,
01360 
01361          .buf_policy = DAHDI_POLICY_IMMEDIATE,
01362          .buf_no = numbufs,
01363          .usefaxbuffers = 0,
01364          .faxbuf_policy = DAHDI_POLICY_IMMEDIATE,
01365          .faxbuf_no = numbufs,
01366       },
01367       .timing = {
01368          .prewinktime = -1,
01369          .preflashtime = -1,
01370          .winktime = -1,
01371          .flashtime = -1,
01372          .starttime = -1,
01373          .rxwinktime = -1,
01374          .rxflashtime = -1,
01375          .debouncetime = -1
01376       },
01377       .is_sig_auto = 1,
01378       .smdi_port = "/dev/ttyS0",
01379    };
01380 
01381    return conf;
01382 }

static void dahdi_close ( int  fd  )  [static]

Definition at line 2139 of file chan_dahdi.c.

Referenced by dahdi_close_pri_fd(), dahdi_close_ss7_fd(), and dahdi_close_sub().

02140 {
02141    if (fd > 0)
02142       close(fd);
02143 }

static void dahdi_close_pri_fd ( struct dahdi_pri *  pri,
int  fd_num 
) [static]

Definition at line 2152 of file chan_dahdi.c.

References dahdi_close(), and dahdi_pri::fds.

Referenced by __unload_module(), dahdi_restart(), and start_pri().

02153 {
02154    dahdi_close(pri->fds[fd_num]);
02155    pri->fds[fd_num] = -1;
02156 }

static void dahdi_close_ss7_fd ( struct dahdi_ss7 *  ss7,
int  fd_num 
) [static]

Definition at line 2160 of file chan_dahdi.c.

References dahdi_close(), and dahdi_ss7::fds.

Referenced by __unload_module(), dahdi_restart(), and linkset_addsigchan().

02161 {
02162    dahdi_close(ss7->fds[fd_num]);
02163    ss7->fds[fd_num] = -1;
02164 }

static void dahdi_close_sub ( struct dahdi_pvt *  chan_pvt,
int  sub_num 
) [static]

Definition at line 2145 of file chan_dahdi.c.

References dahdi_close(), dahdi_subchannel::dfd, and dahdi_pvt::subs.

Referenced by alloc_sub(), destroy_dahdi_pvt(), pri_fixup_principle(), and unalloc_sub().

02146 {
02147    dahdi_close(chan_pvt->subs[sub_num].dfd);
02148    chan_pvt->subs[sub_num].dfd = -1;
02149 }

static int dahdi_confmute ( struct dahdi_pvt *  p,
int  muted 
) [inline, static]

Definition at line 2882 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::channel, dahdi_subchannel::dfd, errno, LOG_WARNING, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_PRI, SIG_SS7, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_handle_dtmfup(), dahdi_handle_event(), dahdi_hangup(), dahdi_new(), and dahdi_read().

02883 {
02884    int x, y, res;
02885    x = muted;
02886    if ((p->sig == SIG_PRI) || (p->sig == SIG_SS7) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) {
02887       y = 1;
02888       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &y);
02889       if (res)
02890          ast_log(LOG_WARNING, "Unable to set audio mode on %d: %s\n", p->channel, strerror(errno));
02891    }
02892    res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_CONFMUTE, &x);
02893    if (res < 0)
02894       ast_log(LOG_WARNING, "DAHDI confmute(%d) failed on channel %d: %s\n", muted, p->channel, strerror(errno));
02895    return res;
02896 }

static char* dahdi_destroy_channel ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14403 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_destroy_channel_bynum(), RESULT_SUCCESS, and ast_cli_entry::usage.

14404 {
14405    int channel;
14406    int ret;
14407    switch (cmd) {
14408    case CLI_INIT:
14409       e->command = "dahdi destroy channel";
14410       e->usage =
14411          "Usage: dahdi destroy channel <chan num>\n"
14412          "  DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.  Immediately removes a given channel, whether it is in use or not\n";
14413       return NULL;
14414    case CLI_GENERATE:
14415       return NULL;
14416    }
14417    if (a->argc != 4)
14418       return CLI_SHOWUSAGE;
14419 
14420    channel = atoi(a->argv[3]);
14421    ret = dahdi_destroy_channel_bynum(channel);
14422    return ( RESULT_SUCCESS == ret ) ? CLI_SUCCESS : CLI_FAILURE;
14423 }

static int dahdi_destroy_channel_bynum ( int  channel  )  [static]

Definition at line 9353 of file chan_dahdi.c.

References ast_module_unref(), dahdi_pvt::channel, destroy_channel(), dahdi_subchannel::dfd, iflist, dahdi_pvt::next, dahdi_pvt::prev, RESULT_FAILURE, RESULT_SUCCESS, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_destroy_channel(), and do_monitor().

09354 {
09355    struct dahdi_pvt *tmp = NULL;
09356    struct dahdi_pvt *prev = NULL;
09357 
09358    tmp = iflist;
09359    while (tmp) {
09360       if (tmp->channel == channel) {
09361          int x = DAHDI_FLASH;
09362          ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); /* important to create an event for dahdi_wait_event to register so that all ss_threads terminate */
09363          destroy_channel(prev, tmp, 1);
09364          ast_module_unref(ast_module_info->self);
09365          return RESULT_SUCCESS;
09366       }
09367       prev = tmp;
09368       tmp = tmp->next;
09369    }
09370    return RESULT_FAILURE;
09371 }

static int dahdi_digit_begin ( struct ast_channel *  ast,
char  digit 
) [static]

Definition at line 2247 of file chan_dahdi.c.

References ast_channel::_state, ast_debug, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_DIALING, dahdi_pvt::begindigit, dahdi_pvt::call, dahdi_get_index(), dahdi_subchannel::dfd, dahdi_pvt::dialdest, dahdi_pvt::dialing, digit_to_dtmfindex(), errno, dahdi_pvt::lock, LOG_WARNING, dahdi_pvt::owner, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), dahdi_pvt::proceeding, dahdi_pvt::pulse, dahdi_pvt::setup_ack, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_PRI, dahdi_pvt::span, SUB_REAL, dahdi_pvt::subs, and ast_channel::tech_pvt.

02248 {
02249    struct dahdi_pvt *pvt;
02250    int idx;
02251    int dtmf = -1;
02252 
02253    pvt = chan->tech_pvt;
02254 
02255    ast_mutex_lock(&pvt->lock);
02256 
02257    idx = dahdi_get_index(chan, pvt, 0);
02258 
02259    if ((idx != SUB_REAL) || !pvt->owner)
02260       goto out;
02261 
02262 #ifdef HAVE_PRI
02263    if (((pvt->sig == SIG_PRI) || (pvt->sig == SIG_BRI) || (pvt->sig == SIG_BRI_PTMP))
02264          && (chan->_state == AST_STATE_DIALING) && !pvt->proceeding) {
02265       if (pvt->setup_ack) {
02266          if (!pri_grab(pvt, pvt->pri)) {
02267             pri_information(pvt->pri->pri, pvt->call, digit);
02268             pri_rel(pvt->pri);
02269          } else
02270             ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", pvt->span);
02271       } else if (strlen(pvt->dialdest) < sizeof(pvt->dialdest) - 1) {
02272          int res;
02273          ast_debug(1, "Queueing digit '%c' since setup_ack not yet received\n", digit);
02274          res = strlen(pvt->dialdest);
02275          pvt->dialdest[res++] = digit;
02276          pvt->dialdest[res] = '\0';
02277       }
02278       goto out;
02279    }
02280 #endif
02281    if ((dtmf = digit_to_dtmfindex(digit)) == -1)
02282       goto out;
02283 
02284    if (pvt->pulse || ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SENDTONE, &dtmf)) {
02285       int res;
02286       struct dahdi_dialoperation zo = {
02287          .op = DAHDI_DIAL_OP_APPEND,
02288       };
02289 
02290       zo.dialstr[0] = 'T';
02291       zo.dialstr[1] = digit;
02292       zo.dialstr[2] = '\0';
02293       if ((res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_DIAL, &zo)))
02294          ast_log(LOG_WARNING, "Couldn't dial digit %c: %s\n", digit, strerror(errno));
02295       else
02296          pvt->dialing = 1;
02297    } else {
02298       ast_debug(1, "Started VLDTMF digit '%c'\n", digit);
02299       pvt->dialing = 1;
02300       pvt->begindigit = digit;
02301    }
02302 
02303 out:
02304    ast_mutex_unlock(&pvt->lock);
02305 
02306    return 0;
02307 }

static int dahdi_digit_end ( struct ast_channel *  ast,
char  digit,
unsigned int  duration 
) [static]

Definition at line 2309 of file chan_dahdi.c.

References ast_debug, ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::begindigit, dahdi_get_index(), dahdi_subchannel::dfd, dahdi_pvt::dialing, dahdi_pvt::lock, dahdi_pvt::owner, dahdi_pvt::pulse, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_PRI, SUB_REAL, dahdi_pvt::subs, and ast_channel::tech_pvt.

02310 {
02311    struct dahdi_pvt *pvt;
02312    int res = 0;
02313    int idx;
02314    int x;
02315 
02316    pvt = chan->tech_pvt;
02317 
02318    ast_mutex_lock(&pvt->lock);
02319 
02320    idx = dahdi_get_index(chan, pvt, 0);
02321 
02322    if ((idx != SUB_REAL) || !pvt->owner || pvt->pulse)
02323       goto out;
02324 
02325 #ifdef HAVE_PRI
02326    /* This means that the digit was already sent via PRI signalling */
02327    if (((pvt->sig == SIG_PRI) || (pvt->sig == SIG_BRI) || (pvt->sig == SIG_BRI_PTMP))
02328          && !pvt->begindigit)
02329       goto out;
02330 #endif
02331 
02332    if (pvt->begindigit) {
02333       x = -1;
02334       ast_debug(1, "Ending VLDTMF digit '%c'\n", digit);
02335       res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SENDTONE, &x);
02336       pvt->dialing = 0;
02337       pvt->begindigit = 0;
02338    }
02339 
02340 out:
02341    ast_mutex_unlock(&pvt->lock);
02342 
02343    return res;
02344 }

static void dahdi_disable_ec ( struct dahdi_pvt *  p  )  [static]

Definition at line 2711 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_pvt::channel, dahdi_subchannel::dfd, dahdi_pvt::echocanon, errno, LOG_WARNING, SUB_REAL, and dahdi_pvt::subs.

Referenced by __dahdi_exception(), dahdi_bridge(), dahdi_handle_event(), dahdi_hangup(), dahdi_setoption(), and handle_init_event().

02712 {
02713    int res;
02714 
02715    if (p->echocanon) {
02716       struct dahdi_echocanparams ecp = { .tap_length = 0 };
02717 
02718       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOCANCEL_PARAMS, &ecp);
02719 
02720       if (res)
02721          ast_log(LOG_WARNING, "Unable to disable echo cancellation on channel %d: %s\n", p->channel, strerror(errno));
02722       else
02723          ast_debug(1, "Disabled echo cancellation on channel %d\n", p->channel);
02724    }
02725 
02726    p->echocanon = 0;
02727 }

static void dahdi_dnd ( struct dahdi_pvt *  dahdichan,
int  on 
) [static]

enable or disable the chan_dahdi Do-Not-Disturb mode for a DAHDI channel

Parameters:
dahdichan "Physical" DAHDI channel (e.g: DAHDI/5)
on 1 to enable, 0 to disable
chan_dahdi has a DND (Do Not Disturb) mode for each dahdichan (physical DAHDI channel). Use this to enable or disable it.

Bug:
the use of the word "channel" for those dahdichans is really confusing.

Definition at line 7739 of file chan_dahdi.c.

References ast_verb, dahdi_pvt::channel, dahdi_pvt::dnd, EVENT_FLAG_SYSTEM, and manager_event.

Referenced by dahdi_set_dnd(), and ss_thread().

07740 {
07741    /* Do not disturb */
07742    dahdichan->dnd = on;
07743    ast_verb(3, "%s DND on channel %d\n",
07744          on? "Enabled" : "Disabled",
07745          dahdichan->channel);
07746    manager_event(EVENT_FLAG_SYSTEM, "DNDState",
07747          "Channel: DAHDI/%d\r\n"
07748          "Status: %s\r\n", dahdichan->channel,
07749          on? "enabled" : "disabled");
07750 }

static void dahdi_enable_ec ( struct dahdi_pvt *  p  )  [static]

Definition at line 2662 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_pvt::channel, dahdi_subchannel::dfd, dahdi_pvt::digital, dahdi_pvt::echocancel, dahdi_pvt::echocanon, errno, dahdi_pvt::head, LOG_WARNING, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_PRI, SIG_SS7, SUB_REAL, and dahdi_pvt::subs.

Referenced by __dahdi_exception(), dahdi_answer(), dahdi_bridge(), dahdi_handle_event(), dahdi_indicate(), dahdi_r2_on_call_accepted(), dahdi_setoption(), handle_init_event(), pri_dchannel(), ss7_linkset(), ss7_start_call(), and ss_thread().

02663 {
02664    int x;
02665    int res;
02666    if (!p)
02667       return;
02668    if (p->echocanon) {
02669       ast_debug(1, "Echo cancellation already on\n");
02670       return;
02671    }
02672    if (p->digital) {
02673       ast_debug(1, "Echo cancellation isn't required on digital connection\n");
02674       return;
02675    }
02676    if (p->echocancel.head.tap_length) {
02677       if ((p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP) || (p->sig == SIG_PRI) || (p->sig == SIG_SS7)) {
02678          x = 1;
02679          res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &x);
02680          if (res)
02681             ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n", p->channel, strerror(errno));
02682       }
02683       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOCANCEL_PARAMS, &p->echocancel);
02684       if (res) {
02685          ast_log(LOG_WARNING, "Unable to enable echo cancellation on channel %d (%s)\n", p->channel, strerror(errno));
02686       } else {
02687          p->echocanon = 1;
02688          ast_debug(1, "Enabled echo cancellation on channel %d\n", p->channel);
02689       }
02690    } else
02691       ast_debug(1, "No echo cancellation requested\n");
02692 }

static struct ast_frame * dahdi_exception ( struct ast_channel *  ast  )  [static, read]

Definition at line 6784 of file chan_dahdi.c.

References __dahdi_exception(), ast_mutex_lock(), ast_mutex_unlock(), f, dahdi_pvt::lock, and ast_channel::tech_pvt.

06785 {
06786    struct dahdi_pvt *p = ast->tech_pvt;
06787    struct ast_frame *f;
06788    ast_mutex_lock(&p->lock);
06789    f = __dahdi_exception(ast);
06790    ast_mutex_unlock(&p->lock);
06791    return f;
06792 }

static int dahdi_fake_event ( struct dahdi_pvt *  p,
int  mode 
) [static]

Definition at line 15302 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::fake_event, HANGUP, LOG_WARNING, ast_channel::name, dahdi_pvt::owner, and TRANSFER.

Referenced by action_transfer(), and action_transferhangup().

15303 {
15304    if (p) {
15305       switch (mode) {
15306          case TRANSFER:
15307             p->fake_event = DAHDI_EVENT_WINKFLASH;
15308             break;
15309          case HANGUP:
15310             p->fake_event = DAHDI_EVENT_ONHOOK;
15311             break;
15312          default:
15313             ast_log(LOG_WARNING, "I don't know how to handle transfer event with this: %d on channel %s\n",mode, p->owner->name);
15314       }
15315    }
15316    return 0;
15317 }

static int dahdi_fixup ( struct ast_channel *  oldchan,
struct ast_channel *  newchan 
) [static]

Definition at line 5523 of file chan_dahdi.c.

References ast_channel::_state, AST_CONTROL_RINGING, ast_debug, ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_RINGING, dahdi_pvt::channel, dahdi_indicate(), dahdi_unlink(), dahdi_pvt::lock, ast_channel::name, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::subs, ast_channel::tech_pvt, and update_conf().

05524 {
05525    struct dahdi_pvt *p = newchan->tech_pvt;
05526    int x;
05527    ast_mutex_lock(&p->lock);
05528    ast_debug(1, "New owner for channel %d is %s\n", p->channel, newchan->name);
05529    if (p->owner == oldchan) {
05530       p->owner = newchan;
05531    }
05532    for (x = 0; x < 3; x++)
05533       if (p->subs[x].owner == oldchan) {
05534          if (!x)
05535             dahdi_unlink(NULL, p, 0);
05536          p->subs[x].owner = newchan;
05537       }
05538    update_conf(p);
05539    ast_mutex_unlock(&p->lock);
05540    if (newchan->_state == AST_STATE_RINGING) {
05541       dahdi_indicate(newchan, AST_CONTROL_RINGING, NULL, 0);
05542    }
05543    return 0;
05544 }

static int dahdi_func_read ( struct ast_channel *  chan,
const char *  function,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 5034 of file chan_dahdi.c.

References ast_copy_string(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::lock, dahdi_pvt::rxgain, ast_channel::tech_pvt, and dahdi_pvt::txgain.

05035 {
05036    struct dahdi_pvt *p = chan->tech_pvt;
05037    int res = 0;
05038 
05039    if (!strcasecmp(data, "rxgain")) {
05040       ast_mutex_lock(&p->lock);
05041       snprintf(buf, len, "%f", p->rxgain);
05042       ast_mutex_unlock(&p->lock);
05043    } else if (!strcasecmp(data, "txgain")) {
05044       ast_mutex_lock(&p->lock);
05045       snprintf(buf, len, "%f", p->txgain);
05046       ast_mutex_unlock(&p->lock);
05047    } else {
05048       ast_copy_string(buf, "", len);
05049       res = -1;
05050    }
05051 
05052    return res;
05053 }

static int dahdi_func_write ( struct ast_channel *  chan,
const char *  function,
char *  data,
const char *  value 
) [static]

Definition at line 5086 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::bufferoverrideinuse, dahdi_pvt::bufsize, dahdi_pvt::channel, dahdi_subchannel::dfd, errno, LOG_WARNING, parse_buffers_policy(), SUB_REAL, dahdi_pvt::subs, and ast_channel::tech_pvt.

05087 {
05088    struct dahdi_pvt *p = chan->tech_pvt;
05089    int res = 0;
05090 
05091    if (!strcasecmp(data, "buffers")) {
05092       int num_bufs, policy;
05093 
05094       if (!(parse_buffers_policy(value, &num_bufs, &policy))) {
05095          struct dahdi_bufferinfo bi = {
05096             .txbufpolicy = policy,
05097             .rxbufpolicy = policy,
05098             .bufsize = p->bufsize,
05099             .numbufs = num_bufs,
05100          };
05101          int bpres;
05102 
05103          if ((bpres = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
05104             ast_log(LOG_WARNING, "Channel '%d' unable to override buffer policy: %s\n", p->channel, strerror(errno));
05105          } else {
05106             p->bufferoverrideinuse = 1;
05107          }
05108       } else {
05109          res = -1;
05110       }
05111    } else {
05112       res = -1;
05113    }
05114 
05115    return res;
05116 }

static int dahdi_get_event ( int  fd  )  [inline, static]

Avoid the silly dahdi_getevent which ignores a bunch of events.

Definition at line 376 of file chan_dahdi.c.

Referenced by __dahdi_exception(), dahdi_handle_event(), do_monitor(), mwi_thread(), and ss_thread().

00377 {
00378    int j;
00379    if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
00380       return -1;
00381    return j;
00382 }

static int dahdi_get_index ( struct ast_channel *  ast,
struct dahdi_pvt *  p,
int  nullok 
) [static]

Definition at line 1505 of file chan_dahdi.c.

References ast_log(), LOG_WARNING, dahdi_subchannel::owner, SUB_CALLWAIT, SUB_REAL, SUB_THREEWAY, and dahdi_pvt::subs.

Referenced by __dahdi_exception(), dahdi_answer(), dahdi_bridge(), dahdi_call(), dahdi_digit_begin(), dahdi_digit_end(), dahdi_handle_event(), dahdi_hangup(), dahdi_indicate(), dahdi_read(), dahdi_sendtext(), dahdi_setoption(), dahdi_write(), and ss_thread().

01506 {
01507    int res;
01508    if (p->subs[SUB_REAL].owner == ast)
01509       res = 0;
01510    else if (p->subs[SUB_CALLWAIT].owner == ast)
01511       res = 1;
01512    else if (p->subs[SUB_THREEWAY].owner == ast)
01513       res = 2;
01514    else {
01515       res = -1;
01516       if (!nullok)
01517          ast_log(LOG_WARNING, "Unable to get index, and nullok is not asserted\n");
01518    }
01519    return res;
01520 }

static void dahdi_handle_dtmfup ( struct ast_channel *  ast,
int  idx,
struct ast_frame **  dest 
) [static]

Definition at line 5683 of file chan_dahdi.c.

References ast_async_goto(), ast_channel_lock, ast_channel_unlock, AST_CONTROL_ANSWER, ast_debug, ast_exists_extension(), AST_FRAME_CONTROL, AST_FRAME_NULL, ast_free, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verb, dahdi_pvt::bufferoverrideinuse, dahdi_pvt::bufsize, dahdi_pvt::callprogress, CALLPROGRESS_FAX, dahdi_pvt::callwaitcas, ast_channel::cid, ast_callerid::cid_num, dahdi_pvt::cidspill, dahdi_pvt::confirmanswer, ast_channel::context, dahdi_confmute(), dahdi_subchannel::dfd, errno, ast_channel::exten, dahdi_subchannel::f, f, dahdi_pvt::faxbuf_no, dahdi_pvt::faxbuf_policy, dahdi_pvt::faxhandled, ast_frame::frametype, dahdi_pvt::lock, LOG_NOTICE, LOG_WARNING, ast_channel::macrocontext, ast_channel::name, pbx_builtin_setvar_helper(), S_OR, send_cwcidspill(), ast_frame::subclass, dahdi_pvt::subs, ast_channel::tech_pvt, and dahdi_pvt::usefaxbuffers.

Referenced by dahdi_handle_event(), and dahdi_read().

05684 {
05685    struct dahdi_pvt *p = ast->tech_pvt;
05686    struct ast_frame *f = *dest;
05687 
05688    ast_debug(1, "DTMF digit: %c on %s\n", f->subclass, ast->name);
05689 
05690    if (p->confirmanswer) {
05691       ast_debug(1, "Confirm answer on %s!\n", ast->name);
05692       /* Upon receiving a DTMF digit, consider this an answer confirmation instead
05693          of a DTMF digit */
05694       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
05695       p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
05696       *dest = &p->subs[idx].f;
05697       /* Reset confirmanswer so DTMF's will behave properly for the duration of the call */
05698       p->confirmanswer = 0;
05699    } else if (p->callwaitcas) {
05700       if ((f->subclass == 'A') || (f->subclass == 'D')) {
05701          ast_debug(1, "Got some DTMF, but it's for the CAS\n");
05702          if (p->cidspill)
05703             ast_free(p->cidspill);
05704          send_cwcidspill(p);
05705       }
05706       p->callwaitcas = 0;
05707       p->subs[idx].f.frametype = AST_FRAME_NULL;
05708       p->subs[idx].f.subclass = 0;
05709       *dest = &p->subs[idx].f;
05710    } else if (f->subclass == 'f') {
05711       /* Fax tone -- Handle and return NULL */
05712       if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
05713          /* If faxbuffers are configured, use them for the fax transmission */
05714          if (p->usefaxbuffers && !p->bufferoverrideinuse) {
05715             struct dahdi_bufferinfo bi = {
05716                .txbufpolicy = p->faxbuf_policy,
05717                .bufsize = p->bufsize,
05718                .numbufs = p->faxbuf_no
05719             };
05720             int res;
05721 
05722             if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
05723                ast_log(LOG_WARNING, "Channel '%s' unable to set faxbuffer policy, reason: %s\n", ast->name, strerror(errno));
05724             } else {
05725                p->bufferoverrideinuse = 1;
05726             }
05727          }
05728          p->faxhandled = 1;
05729          if (strcmp(ast->exten, "fax")) {
05730             const char *target_context = S_OR(ast->macrocontext, ast->context);
05731 
05732             /* We need to unlock 'ast' here because ast_exists_extension has the
05733              * potential to start autoservice on the channel. Such action is prone
05734              * to deadlock.
05735              */
05736             ast_mutex_unlock(&p->lock);
05737             ast_channel_unlock(ast);
05738             if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) {
05739                ast_channel_lock(ast);
05740                ast_mutex_lock(&p->lock);
05741                ast_verb(3, "Redirecting %s to fax extension\n", ast->name);
05742                /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
05743                pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
05744                if (ast_async_goto(ast, target_context, "fax", 1))
05745                   ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
05746             } else {
05747                ast_channel_lock(ast);
05748                ast_mutex_lock(&p->lock);
05749                ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
05750             }
05751          } else {
05752             ast_debug(1, "Already in a fax extension, not redirecting\n");
05753          }
05754       } else {
05755          ast_debug(1, "Fax already handled\n");
05756       }
05757       dahdi_confmute(p, 0);
05758       p->subs[idx].f.frametype = AST_FRAME_NULL;
05759       p->subs[idx].f.subclass = 0;
05760       *dest = &p->subs[idx].f;
05761    }
05762 }

static struct ast_frame* dahdi_handle_event ( struct ast_channel *  ast  )  [static, read]

< Digits (or equivalent) have been dialed

< Remote end is ringing

< Line is up

< Line is ringing

< Channel is down and available

< Channel is down, but reserved

< Channel is off hook

< Line is busy

< Digits (or equivalent) have been dialed while offhook

< Channel has detected an incoming call and is waiting for ring

< Digits (or equivalent) have been dialed

< Remote end is ringing

< Line is up

< Line is ringing

Definition at line 5775 of file chan_dahdi.c.

References ast_channel::_softhangup, ast_channel::_state, alloc_sub(), dahdi_pvt::answeronpolarityswitch, ast_bridged_channel(), AST_CAUSE_NO_ANSWER, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_NULL, ast_free, ast_hangup(), ast_log(), ast_pthread_create_detached, ast_queue_control(), ast_queue_control_data(), ast_queue_hangup_with_cause(), ast_setstate(), ast_softhangup(), AST_SOFTHANGUP_DEV, AST_SOFTHANGUP_EXPLICIT, AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DIALING_OFFHOOK, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_strdup, ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, attempt_transfer(), dahdi_pvt::bearer, dahdi_pvt::call, dahdi_pvt::callprogress, CALLPROGRESS_PROGRESS, dahdi_pvt::callwaitcas, dahdi_pvt::callwaitingrepeat, CANPROGRESSDETECT, ast_channel::cdr, dahdi_pvt::channel, CHANNEL_DEADLOCK_AVOIDANCE, check_for_conference(), ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_ani2, dahdi_pvt::cid_name, ast_callerid::cid_name, cid_name, dahdi_pvt::cid_num, ast_callerid::cid_num, cid_num, dahdi_pvt::cidcwexpire, dahdi_pvt::cidrings, dahdi_pvt::cidspill, dahdi_pvt::confirmanswer, dahdi_confmute(), dahdi_disable_ec(), dahdi_enable_ec(), dahdi_get_event(), dahdi_get_index(), dahdi_handle_dtmfup(), dahdi_new(), DAHDI_OVERLAPDIAL_INCOMING, dahdi_ring_phone(), dahdi_set_hook(), dahdi_train_ec(), dahdi_pvt::dahditrcallerid, ast_frame::data, ast_frame::datalen, dahdi_subchannel::dfd, dahdi_pvt::dialdest, dahdi_pvt::dialednone, dahdi_pvt::dialing, DLA_LOCK, DLA_UNLOCK, dahdi_pvt::dop, dahdi_pvt::dsp, dahdi_pvt::echobreak, dahdi_pvt::echocanon, dahdi_pvt::echorest, dahdi_pvt::echotraining, errno, event2str(), EVENT_FLAG_SYSTEM, dahdi_subchannel::f, f, dahdi_pvt::fake_event, dahdi_pvt::finaldial, dahdi_pvt::flashtime, ast_frame::frametype, dahdi_pvt::fxsoffhookstate, get_alarms(), handle_alarms(), dahdi_pvt::hanguponpolarityswitch, has_voicemail(), dahdi_pvt::inalarm, dahdi_subchannel::inthreeway, dahdi_pvt::lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, ast_frame::mallocd, manager_event, MIN_MS_SINCE_FLASH, dahdi_pvt::mohsuggest, dahdi_pvt::msgstate, ast_channel::name, dahdi_subchannel::needanswer, dahdi_subchannel::needflash, dahdi_subchannel::needhold, dahdi_subchannel::needringing, dahdi_subchannel::needunhold, ast_frame::offset, dahdi_pvt::onhooktime, dahdi_pvt::oprmode, dahdi_pvt::oprpeer, option_debug, dahdi_pvt::origcid_name, dahdi_pvt::origcid_num, dahdi_pvt::outgoing, dahdi_pvt::outsigmod, dahdi_pri::overlapdial, dahdi_subchannel::owner, dahdi_pvt::owner, ast_channel::pbx, dahdi_pvt::polarity, POLARITY_IDLE, POLARITY_REV, dahdi_pvt::polaritydelaytv, dahdi_pvt::polarityonanswerdelay, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), dahdi_pvt::proceeding, ast_frame::ptr, dahdi_pvt::pulsedial, dahdi_pvt::r2chan, dahdi_pvt::radio, restore_conference(), ast_channel::rings, dahdi_pvt::ringt, dahdi_pvt::ringt_base, S_OR, ast_frame::samples, save_conference(), dahdi_pvt::sig, sig2str, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_MFCR2, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SF_FEATD, SIG_SF_FEATDMF, SIG_SFWINK, SIG_SS7, ast_frame::src, ss_thread(), SUB_CALLWAIT, SUB_REAL, SUB_THREEWAY, ast_frame::subclass, dahdi_pvt::subs, swap_subs(), ast_channel::tech_pvt, dahdi_pvt::threewaycalling, dahdi_pvt::transfer, dahdi_pvt::transfertobusy, unalloc_sub(), update_conf(), dahdi_pvt::waitingfordt, and dahdi_pvt::whichwink.

Referenced by __dahdi_exception().

05776 {
05777    int res, x;
05778    int idx, mysig;
05779    char *c;
05780    struct dahdi_pvt *p = ast->tech_pvt;
05781    pthread_t threadid;
05782    struct ast_channel *chan;
05783    struct ast_frame *f;
05784 
05785    idx = dahdi_get_index(ast, p, 0);
05786    mysig = p->sig;
05787    if (p->outsigmod > -1)
05788       mysig = p->outsigmod;
05789    p->subs[idx].f.frametype = AST_FRAME_NULL;
05790    p->subs[idx].f.subclass = 0;
05791    p->subs[idx].f.datalen = 0;
05792    p->subs[idx].f.samples = 0;
05793    p->subs[idx].f.mallocd = 0;
05794    p->subs[idx].f.offset = 0;
05795    p->subs[idx].f.src = "dahdi_handle_event";
05796    p->subs[idx].f.data.ptr = NULL;
05797    f = &p->subs[idx].f;
05798 
05799    if (idx < 0)
05800       return &p->subs[idx].f;
05801    if (p->fake_event) {
05802       res = p->fake_event;
05803       p->fake_event = 0;
05804    } else
05805       res = dahdi_get_event(p->subs[idx].dfd);
05806 
05807    ast_debug(1, "Got event %s(%d) on channel %d (index %d)\n", event2str(res), res, p->channel, idx);
05808 
05809    if (res & (DAHDI_EVENT_PULSEDIGIT | DAHDI_EVENT_DTMFUP)) {
05810       p->pulsedial = (res & DAHDI_EVENT_PULSEDIGIT) ? 1 : 0;
05811       ast_debug(1, "Detected %sdigit '%c'\n", p->pulsedial ? "pulse ": "", res & 0xff);
05812 #ifdef HAVE_PRI
05813       if (!p->proceeding && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) && p->pri && (p->pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)) {
05814          /* absorb event */
05815       } else {
05816 #endif
05817          dahdi_confmute(p, 0);
05818          p->subs[idx].f.frametype = AST_FRAME_DTMF_END;
05819          p->subs[idx].f.subclass = res & 0xff;
05820 #ifdef HAVE_PRI
05821       }
05822 #endif
05823       dahdi_handle_dtmfup(ast, idx, &f);
05824       return f;
05825    }
05826 
05827    if (res & DAHDI_EVENT_DTMFDOWN) {
05828       ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
05829       /* Mute conference */
05830       dahdi_confmute(p, 1);
05831       p->subs[idx].f.frametype = AST_FRAME_DTMF_BEGIN;
05832       p->subs[idx].f.subclass = res & 0xff;
05833       return &p->subs[idx].f;
05834    }
05835 
05836    switch (res) {
05837       case DAHDI_EVENT_EC_DISABLED:
05838          ast_verb(3, "Channel %d echo canceler disabled due to CED detection\n", p->channel);
05839          p->echocanon = 0;
05840          break;
05841       case DAHDI_EVENT_BITSCHANGED:
05842 #ifdef HAVE_OPENR2
05843          if (p->sig != SIG_MFCR2) {
05844             ast_log(LOG_WARNING, "Received bits changed on %s signalling?\n", sig2str(p->sig));
05845          } else {
05846             ast_log(LOG_DEBUG, "bits changed in chan %d\n", p->channel);
05847             openr2_chan_handle_cas(p->r2chan);
05848          }
05849 #else
05850          ast_log(LOG_WARNING, "Received bits changed on %s signalling?\n", sig2str(p->sig));
05851 #endif
05852       case DAHDI_EVENT_PULSE_START:
05853          /* Stop tone if there's a pulse start and the PBX isn't started */
05854          if (!ast->pbx)
05855             tone_zone_play_tone(p->subs[idx].dfd, -1);
05856          break;
05857       case DAHDI_EVENT_DIALCOMPLETE:
05858 #ifdef HAVE_OPENR2
05859          if ((p->sig & SIG_MFCR2) && p->r2chan && ast->_state != AST_STATE_UP) {
05860             /* we don't need to do anything for this event for R2 signaling
05861                if the call is being setup */
05862             break;
05863          }
05864 #endif
05865          if (p->inalarm) break;
05866          if ((p->radio || (p->oprmode < 0))) break;
05867          if (ioctl(p->subs[idx].dfd,DAHDI_DIALING,&x) == -1) {
05868             ast_log(LOG_DEBUG, "DAHDI_DIALING ioctl failed on %s: %s\n",ast->name, strerror(errno));
05869             return NULL;
05870          }
05871          if (!x) { /* if not still dialing in driver */
05872             dahdi_enable_ec(p);
05873             if (p->echobreak) {
05874                dahdi_train_ec(p);
05875                ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
05876                p->dop.op = DAHDI_DIAL_OP_REPLACE;
05877                res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
05878                p->echobreak = 0;
05879             } else {
05880                p->dialing = 0;
05881                if ((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) {
05882                   /* if thru with dialing after offhook */
05883                   if (ast->_state == AST_STATE_DIALING_OFFHOOK) {
05884                      ast_setstate(ast, AST_STATE_UP);
05885                      p->subs[idx].f.frametype = AST_FRAME_CONTROL;
05886                      p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
05887                      break;
05888                   } else { /* if to state wait for offhook to dial rest */
05889                      /* we now wait for off hook */
05890                      ast_setstate(ast,AST_STATE_DIALING_OFFHOOK);
05891                   }
05892                }
05893                if (ast->_state == AST_STATE_DIALING) {
05894                   if ((p->callprogress & CALLPROGRESS_PROGRESS) && CANPROGRESSDETECT(p) && p->dsp && p->outgoing) {
05895                      ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
05896                   } else if (p->confirmanswer || (!p->dialednone
05897                      && ((mysig == SIG_EM) || (mysig == SIG_EM_E1)
05898                         || (mysig == SIG_EMWINK) || (mysig == SIG_FEATD)
05899                         || (mysig == SIG_FEATDMF_TA) || (mysig == SIG_FEATDMF)
05900                         || (mysig == SIG_E911) || (mysig == SIG_FGC_CAMA)
05901                         || (mysig == SIG_FGC_CAMAMF) || (mysig == SIG_FEATB)
05902                         || (mysig == SIG_SF) || (mysig == SIG_SFWINK)
05903                         || (mysig == SIG_SF_FEATD) || (mysig == SIG_SF_FEATDMF)
05904                         || (mysig == SIG_SF_FEATB)))) {
05905                      ast_setstate(ast, AST_STATE_RINGING);
05906                   } else if (!p->answeronpolarityswitch) {
05907                      ast_setstate(ast, AST_STATE_UP);
05908                      p->subs[idx].f.frametype = AST_FRAME_CONTROL;
05909                      p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
05910                      /* If aops=0 and hops=1, this is necessary */
05911                      p->polarity = POLARITY_REV;
05912                   } else {
05913                      /* Start clean, so we can catch the change to REV polarity when party answers */
05914                      p->polarity = POLARITY_IDLE;
05915                   }
05916                }
05917             }
05918          }
05919          break;
05920       case DAHDI_EVENT_ALARM:
05921 #ifdef HAVE_PRI
05922          if ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) {
05923             if (!p->pri || !p->pri->pri || (pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0)) {
05924                /* T309 is not enabled : hangup calls when alarm occurs */
05925                if (p->call) {
05926                   if (p->pri && p->pri->pri) {
05927                      if (!pri_grab(p, p->pri)) {
05928                         pri_hangup(p->pri->pri, p->call, -1);
05929                         pri_destroycall(p->pri->pri, p->call);
05930                         p->call = NULL;
05931                         pri_rel(p->pri);
05932                      } else
05933                         ast_log(LOG_WARNING, "Failed to grab PRI!\n");
05934                   } else
05935                      ast_log(LOG_WARNING, "The PRI Call has not been destroyed\n");
05936                }
05937                if (p->owner)
05938                   p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
05939             }
05940          }
05941          if (p->bearer)
05942             p->bearer->inalarm = 1;
05943          else
05944 #endif
05945          p->inalarm = 1;
05946          res = get_alarms(p);
05947          handle_alarms(p, res);
05948 #ifdef HAVE_PRI
05949          if (!p->pri || !p->pri->pri || pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0) {
05950             /* fall through intentionally */
05951          } else {
05952             break;
05953          }
05954 #endif
05955 #ifdef HAVE_SS7
05956          if (p->sig == SIG_SS7)
05957             break;
05958 #endif
05959 #ifdef HAVE_OPENR2
05960          if (p->sig == SIG_MFCR2)
05961             break;
05962 #endif
05963       case DAHDI_EVENT_ONHOOK:
05964          if (p->radio) {
05965             p->subs[idx].f.frametype = AST_FRAME_CONTROL;
05966             p->subs[idx].f.subclass = AST_CONTROL_RADIO_UNKEY;
05967             break;
05968          }
05969          if (p->oprmode < 0)
05970          {
05971             if (p->oprmode != -1) break;
05972             if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS))
05973             {
05974                /* Make sure it starts ringing */
05975                dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
05976                dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RING);
05977                save_conference(p->oprpeer);
05978                tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
05979             }
05980             break;
05981          }
05982          switch (p->sig) {
05983          case SIG_FXOLS:
05984          case SIG_FXOGS:
05985          case SIG_FXOKS:
05986             p->onhooktime = time(NULL);
05987             p->fxsoffhookstate = 0;
05988             p->msgstate = -1;
05989             /* Check for some special conditions regarding call waiting */
05990             if (idx == SUB_REAL) {
05991                /* The normal line was hung up */
05992                if (p->subs[SUB_CALLWAIT].owner) {
05993                   /* There's a call waiting call, so ring the phone, but make it unowned in the mean time */
05994                   swap_subs(p, SUB_CALLWAIT, SUB_REAL);
05995                   ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
05996                   unalloc_sub(p, SUB_CALLWAIT);
05997 #if 0
05998                   p->subs[idx].needanswer = 0;
05999                   p->subs[idx].needringing = 0;
06000 #endif
06001                   p->callwaitingrepeat = 0;
06002                   p->cidcwexpire = 0;
06003                   p->owner = NULL;
06004                   /* Don't start streaming audio yet if the incoming call isn't up yet */
06005                   if (p->subs[SUB_REAL].owner->_state != AST_STATE_UP)
06006                      p->dialing = 1;
06007                   dahdi_ring_phone(p);
06008                } else if (p->subs[SUB_THREEWAY].owner) {
06009                   unsigned int mssinceflash;
06010                   /* Here we have to retain the lock on both the main channel, the 3-way channel, and
06011                      the private structure -- not especially easy or clean */
06012                   while (p->subs[SUB_THREEWAY].owner && ast_channel_trylock(p->subs[SUB_THREEWAY].owner)) {
06013                      /* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
06014                      DLA_UNLOCK(&p->lock);
06015                      CHANNEL_DEADLOCK_AVOIDANCE(ast);
06016                      /* We can grab ast and p in that order, without worry.  We should make sure
06017                         nothing seriously bad has happened though like some sort of bizarre double
06018                         masquerade! */
06019                      DLA_LOCK(&p->lock);
06020                      if (p->owner != ast) {
06021                         ast_log(LOG_WARNING, "This isn't good...\n");
06022                         return NULL;
06023                      }
06024                   }
06025                   if (!p->subs[SUB_THREEWAY].owner) {
06026                      ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
06027                      return NULL;
06028                   }
06029                   mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
06030                   ast_debug(1, "Last flash was %d ms ago\n", mssinceflash);
06031                   if (mssinceflash < MIN_MS_SINCE_FLASH) {
06032                      /* It hasn't been long enough since the last flashook.  This is probably a bounce on
06033                         hanging up.  Hangup both channels now */
06034                      if (p->subs[SUB_THREEWAY].owner)
06035                         ast_queue_hangup_with_cause(p->subs[SUB_THREEWAY].owner, AST_CAUSE_NO_ANSWER);
06036                      p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
06037                      ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
06038                      ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
06039                   } else if ((ast->pbx) || (ast->_state == AST_STATE_UP)) {
06040                      if (p->transfer) {
06041                         /* In any case this isn't a threeway call anymore */
06042                         p->subs[SUB_REAL].inthreeway = 0;
06043                         p->subs[SUB_THREEWAY].inthreeway = 0;
06044                         /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
06045                         if (!p->transfertobusy && ast->_state == AST_STATE_BUSY) {
06046                            ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
06047                            /* Swap subs and dis-own channel */
06048                            swap_subs(p, SUB_THREEWAY, SUB_REAL);
06049                            p->owner = NULL;
06050                            /* Ring the phone */
06051                            dahdi_ring_phone(p);
06052                         } else {
06053                            if ((res = attempt_transfer(p)) < 0) {
06054                               p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
06055                               if (p->subs[SUB_THREEWAY].owner)
06056                                  ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
06057                            } else if (res) {
06058                               /* Don't actually hang up at this point */
06059                               if (p->subs[SUB_THREEWAY].owner)
06060                                  ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
06061                               break;
06062                            }
06063                         }
06064                      } else {
06065                         p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
06066                         if (p->subs[SUB_THREEWAY].owner)
06067                            ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
06068                      }
06069                   } else {
06070                      ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
06071                      /* Swap subs and dis-own channel */
06072                      swap_subs(p, SUB_THREEWAY, SUB_REAL);
06073                      p->owner = NULL;
06074                      /* Ring the phone */
06075                      dahdi_ring_phone(p);
06076                   }
06077                }
06078             } else {
06079                ast_log(LOG_WARNING, "Got a hangup and my index is %d?\n", idx);
06080             }
06081             /* Fall through */
06082          default:
06083             dahdi_disable_ec(p);
06084             return NULL;
06085          }
06086          break;
06087       case DAHDI_EVENT_RINGOFFHOOK:
06088          if (p->inalarm) break;
06089          if (p->oprmode < 0)
06090          {
06091             if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS))
06092             {
06093                /* Make sure it stops ringing */
06094                dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
06095                tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, -1);
06096                restore_conference(p->oprpeer);
06097             }
06098             break;
06099          }
06100          if (p->radio)
06101          {
06102             p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06103             p->subs[idx].f.subclass = AST_CONTROL_RADIO_KEY;
06104             break;
06105          }
06106          /* for E911, its supposed to wait for offhook then dial
06107             the second half of the dial string */
06108          if (((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) && (ast->_state == AST_STATE_DIALING_OFFHOOK)) {
06109             c = strchr(p->dialdest, '/');
06110             if (c)
06111                c++;
06112             else
06113                c = p->dialdest;
06114             if (*c) snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
06115             else ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
06116             if (strlen(p->dop.dialstr) > 4) {
06117                memset(p->echorest, 'w', sizeof(p->echorest) - 1);
06118                strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
06119                p->echorest[sizeof(p->echorest) - 1] = '\0';
06120                p->echobreak = 1;
06121                p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
06122             } else
06123                p->echobreak = 0;
06124             if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop)) {
06125                int saveerr = errno;
06126 
06127                x = DAHDI_ONHOOK;
06128                ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
06129                ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(saveerr));
06130                return NULL;
06131                }
06132             p->dialing = 1;
06133             return &p->subs[idx].f;
06134          }
06135          switch (p->sig) {
06136          case SIG_FXOLS:
06137          case SIG_FXOGS:
06138          case SIG_FXOKS:
06139             p->fxsoffhookstate = 1;
06140             switch (ast->_state) {
06141             case AST_STATE_RINGING:
06142                dahdi_enable_ec(p);
06143                dahdi_train_ec(p);
06144                p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06145                p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
06146                /* Make sure it stops ringing */
06147                p->subs[SUB_REAL].needringing = 0;
06148                dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK);
06149                ast_debug(1, "channel %d answered\n", p->channel);
06150                if (p->cidspill) {
06151                   /* Cancel any running CallerID spill */
06152                   ast_free(p->cidspill);
06153                   p->cidspill = NULL;
06154                }
06155                p->dialing = 0;
06156                p->callwaitcas = 0;
06157                if (p->confirmanswer) {
06158                   /* Ignore answer if "confirm answer" is enabled */
06159                   p->subs[idx].f.frametype = AST_FRAME_NULL;
06160                   p->subs[idx].f.subclass = 0;
06161                } else if (!ast_strlen_zero(p->dop.dialstr)) {
06162                   /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
06163                   res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
06164                   if (res < 0) {
06165                      ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", p->channel, strerror(errno));
06166                      p->dop.dialstr[0] = '\0';
06167                      return NULL;
06168                   } else {
06169                      ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
06170                      p->subs[idx].f.frametype = AST_FRAME_NULL;
06171                      p->subs[idx].f.subclass = 0;
06172                      p->dialing = 1;
06173                   }
06174                   p->dop.dialstr[0] = '\0';
06175                   ast_setstate(ast, AST_STATE_DIALING);
06176                } else
06177                   ast_setstate(ast, AST_STATE_UP);
06178                return &p->subs[idx].f;
06179             case AST_STATE_DOWN:
06180                ast_setstate(ast, AST_STATE_RING);
06181                ast->rings = 1;
06182                p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06183                p->subs[idx].f.subclass = AST_CONTROL_OFFHOOK;
06184                ast_debug(1, "channel %d picked up\n", p->channel);
06185                return &p->subs[idx].f;
06186             case AST_STATE_UP:
06187                /* Make sure it stops ringing */
06188                dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK);
06189                /* Okay -- probably call waiting*/
06190                if (ast_bridged_channel(p->owner))
06191                   ast_queue_control(p->owner, AST_CONTROL_UNHOLD);
06192                p->subs[idx].needunhold = 1;
06193                break;
06194             case AST_STATE_RESERVED:
06195                /* Start up dialtone */
06196                if (has_voicemail(p))
06197                   res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_STUTTER);
06198                else
06199                   res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_DIALTONE);
06200                break;
06201             default:
06202                ast_log(LOG_WARNING, "FXO phone off hook in weird state %d??\n", ast->_state);
06203             }
06204             break;
06205          case SIG_FXSLS:
06206          case SIG_FXSGS:
06207          case SIG_FXSKS:
06208             if (ast->_state == AST_STATE_RING) {
06209                p->ringt = p->ringt_base;
06210             }
06211 
06212             /* If we get a ring then we cannot be in
06213              * reversed polarity. So we reset to idle */
06214             ast_debug(1, "Setting IDLE polarity due "
06215                "to ring. Old polarity was %d\n",
06216                p->polarity);
06217             p->polarity = POLARITY_IDLE;
06218 
06219             /* Fall through */
06220          case SIG_EM:
06221          case SIG_EM_E1:
06222          case SIG_EMWINK:
06223          case SIG_FEATD:
06224          case SIG_FEATDMF:
06225          case SIG_FEATDMF_TA:
06226          case SIG_E911:
06227          case SIG_FGC_CAMA:
06228          case SIG_FGC_CAMAMF:
06229          case SIG_FEATB:
06230          case SIG_SF:
06231          case SIG_SFWINK:
06232          case SIG_SF_FEATD:
06233          case SIG_SF_FEATDMF:
06234          case SIG_SF_FEATB:
06235             if (ast->_state == AST_STATE_PRERING)
06236                ast_setstate(ast, AST_STATE_RING);
06237             if ((ast->_state == AST_STATE_DOWN) || (ast->_state == AST_STATE_RING)) {
06238                ast_debug(1, "Ring detected\n");
06239                p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06240                p->subs[idx].f.subclass = AST_CONTROL_RING;
06241             } else if (p->outgoing && ((ast->_state == AST_STATE_RINGING) || (ast->_state == AST_STATE_DIALING))) {
06242                ast_debug(1, "Line answered\n");
06243                if (p->confirmanswer) {
06244                   p->subs[idx].f.frametype = AST_FRAME_NULL;
06245                   p->subs[idx].f.subclass = 0;
06246                } else {
06247                   p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06248                   p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
06249                   ast_setstate(ast, AST_STATE_UP);
06250                }
06251             } else if (ast->_state != AST_STATE_RING)
06252                ast_log(LOG_WARNING, "Ring/Off-hook in strange state %d on channel %d\n", ast->_state, p->channel);
06253             break;
06254          default:
06255             ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
06256          }
06257          break;
06258       case DAHDI_EVENT_RINGBEGIN:
06259          switch (p->sig) {
06260          case SIG_FXSLS:
06261          case SIG_FXSGS:
06262          case SIG_FXSKS:
06263             if (ast->_state == AST_STATE_RING) {
06264                p->ringt = p->ringt_base;
06265             }
06266             break;
06267          }
06268          break;
06269       case DAHDI_EVENT_RINGEROFF:
06270          if (p->inalarm) break;
06271          if ((p->radio || (p->oprmode < 0))) break;
06272          ast->rings++;
06273          if ((ast->rings > p->cidrings) && (p->cidspill)) {
06274             ast_log(LOG_WARNING, "Didn't finish Caller-ID spill.  Cancelling.\n");
06275             ast_free(p->cidspill);
06276             p->cidspill = NULL;
06277             p->callwaitcas = 0;
06278          }
06279          p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06280          p->subs[idx].f.subclass = AST_CONTROL_RINGING;
06281          break;
06282       case DAHDI_EVENT_RINGERON:
06283          break;
06284       case DAHDI_EVENT_NOALARM:
06285          p->inalarm = 0;
06286 #ifdef HAVE_PRI
06287          /* Extremely unlikely but just in case */
06288          if (p->bearer)
06289             p->bearer->inalarm = 0;
06290 #endif
06291          ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", p->channel);
06292          manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
06293                         "Channel: %d\r\n", p->channel);
06294          break;
06295       case DAHDI_EVENT_WINKFLASH:
06296          if (p->inalarm) break;
06297          if (p->radio) break;
06298          if (p->oprmode < 0) break;
06299          if (p->oprmode > 1)
06300          {
06301             struct dahdi_params par;
06302 
06303             memset(&par, 0, sizeof(par));
06304             if (ioctl(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par) != -1)
06305             {
06306                if (!par.rxisoffhook)
06307                {
06308                   /* Make sure it stops ringing */
06309                   dahdi_set_hook(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
06310                   dahdi_set_hook(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_RING);
06311                   save_conference(p);
06312                   tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
06313                }
06314             }
06315             break;
06316          }
06317          /* Remember last time we got a flash-hook */
06318          p->flashtime = ast_tvnow();
06319          switch (mysig) {
06320          case SIG_FXOLS:
06321          case SIG_FXOGS:
06322          case SIG_FXOKS:
06323             ast_debug(1, "Winkflash, index: %d, normal: %d, callwait: %d, thirdcall: %d\n",
06324                idx, p->subs[SUB_REAL].dfd, p->subs[SUB_CALLWAIT].dfd, p->subs[SUB_THREEWAY].dfd);
06325             p->callwaitcas = 0;
06326 
06327             if (idx != SUB_REAL) {
06328                ast_log(LOG_WARNING, "Got flash hook with index %d on channel %d?!?\n", idx, p->channel);
06329                goto winkflashdone;
06330             }
06331 
06332             if (p->subs[SUB_CALLWAIT].owner) {
06333                /* Swap to call-wait */
06334                swap_subs(p, SUB_REAL, SUB_CALLWAIT);
06335                tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1);
06336                p->owner = p->subs[SUB_REAL].owner;
06337                ast_debug(1, "Making %s the new owner\n", p->owner->name);
06338                if (p->owner->_state == AST_STATE_RINGING) {
06339                   ast_setstate(p->owner, AST_STATE_UP);
06340                   p->subs[SUB_REAL].needanswer = 1;
06341                }
06342                p->callwaitingrepeat = 0;
06343                p->cidcwexpire = 0;
06344                /* Start music on hold if appropriate */
06345                if (!p->subs[SUB_CALLWAIT].inthreeway && ast_bridged_channel(p->subs[SUB_CALLWAIT].owner)) {
06346                   ast_queue_control_data(p->subs[SUB_CALLWAIT].owner, AST_CONTROL_HOLD,
06347                      S_OR(p->mohsuggest, NULL),
06348                      !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
06349                }
06350                p->subs[SUB_CALLWAIT].needhold = 1;
06351                if (ast_bridged_channel(p->subs[SUB_REAL].owner)) {
06352                   ast_queue_control_data(p->subs[SUB_REAL].owner, AST_CONTROL_HOLD,
06353                      S_OR(p->mohsuggest, NULL),
06354                      !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
06355                }
06356                p->subs[SUB_REAL].needunhold = 1;
06357             } else if (!p->subs[SUB_THREEWAY].owner) {
06358                if (!p->threewaycalling) {
06359                   /* Just send a flash if no 3-way calling */
06360                   p->subs[SUB_REAL].needflash = 1;
06361                   goto winkflashdone;
06362                } else if (!check_for_conference(p)) {
06363                   char cid_num[256];
06364                   char cid_name[256];
06365 
06366                   cid_num[0] = 0;
06367                   cid_name[0] = 0;
06368                   if (p->dahditrcallerid && p->owner) {
06369                      if (p->owner->cid.cid_num)
06370                         ast_copy_string(cid_num, p->owner->cid.cid_num, sizeof(cid_num));
06371                      if (p->owner->cid.cid_name)
06372                         ast_copy_string(cid_name, p->owner->cid.cid_name, sizeof(cid_name));
06373                   }
06374                   /* XXX This section needs much more error checking!!! XXX */
06375                   /* Start a 3-way call if feasible */
06376                   if (!((ast->pbx) ||
06377                      (ast->_state == AST_STATE_UP) ||
06378                      (ast->_state == AST_STATE_RING))) {
06379                      ast_debug(1, "Flash when call not up or ringing\n");
06380                      goto winkflashdone;
06381                   }
06382                   if (alloc_sub(p, SUB_THREEWAY)) {
06383                      ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
06384                      goto winkflashdone;
06385                   }
06386                   /* Make new channel */
06387                   chan = dahdi_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0);
06388                   if (p->dahditrcallerid) {
06389                      if (!p->origcid_num)
06390                         p->origcid_num = ast_strdup(p->cid_num);
06391                      if (!p->origcid_name)
06392                         p->origcid_name = ast_strdup(p->cid_name);
06393                      ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
06394                      ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
06395                   }
06396                   /* Swap things around between the three-way and real call */
06397                   swap_subs(p, SUB_THREEWAY, SUB_REAL);
06398                   /* Disable echo canceller for better dialing */
06399                   dahdi_disable_ec(p);
06400                   res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_DIALRECALL);
06401                   if (res)
06402                      ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
06403                   p->owner = chan;
06404                   if (!chan) {
06405                      ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel);
06406                   } else if (ast_pthread_create_detached(&threadid, NULL, ss_thread, chan)) {
06407                      ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
06408                      res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
06409                      dahdi_enable_ec(p);
06410                      ast_hangup(chan);
06411                   } else {
06412                      struct ast_channel *other = ast_bridged_channel(p->subs[SUB_THREEWAY].owner);
06413                      int way3bridge = 0, cdr3way = 0;
06414 
06415                      if (!other) {
06416                         other = ast_bridged_channel(p->subs[SUB_REAL].owner);
06417                      } else
06418                         way3bridge = 1;
06419 
06420                      if (p->subs[SUB_THREEWAY].owner->cdr)
06421                         cdr3way = 1;
06422 
06423                      ast_verb(3, "Started three way call on channel %d\n", p->channel);
06424 
06425                      /* Start music on hold if appropriate */
06426                      if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
06427                         ast_queue_control_data(p->subs[SUB_THREEWAY].owner, AST_CONTROL_HOLD,
06428                            S_OR(p->mohsuggest, NULL),
06429                            !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
06430                      }
06431                      p->subs[SUB_THREEWAY].needhold = 1;
06432                   }
06433                }
06434             } else {
06435                /* Already have a 3 way call */
06436                if (p->subs[SUB_THREEWAY].inthreeway) {
06437                   /* Call is already up, drop the last person */
06438                   ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
06439                   /* If the primary call isn't answered yet, use it */
06440                   if ((p->subs[SUB_REAL].owner->_state != AST_STATE_UP) && (p->subs[SUB_THREEWAY].owner->_state == AST_STATE_UP)) {
06441                      /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
06442                      swap_subs(p, SUB_THREEWAY, SUB_REAL);
06443                      p->owner = p->subs[SUB_REAL].owner;
06444                   }
06445                   /* Drop the last call and stop the conference */
06446                   ast_verb(3, "Dropping three-way call on %s\n", p->subs[SUB_THREEWAY].owner->name);
06447                   p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
06448                   p->subs[SUB_REAL].inthreeway = 0;
06449                   p->subs[SUB_THREEWAY].inthreeway = 0;
06450                } else {
06451                   /* Lets see what we're up to */
06452                   if (((ast->pbx) || (ast->_state == AST_STATE_UP)) &&
06453                      (p->transfertobusy || (ast->_state != AST_STATE_BUSY))) {
06454                      int otherindex = SUB_THREEWAY;
06455                      struct ast_channel *other = ast_bridged_channel(p->subs[SUB_THREEWAY].owner);
06456                      int way3bridge = 0, cdr3way = 0;
06457 
06458                      if (!other) {
06459                         other = ast_bridged_channel(p->subs[SUB_REAL].owner);
06460                      } else
06461                         way3bridge = 1;
06462 
06463                      if (p->subs[SUB_THREEWAY].owner->cdr)
06464                         cdr3way = 1;
06465 
06466                      ast_verb(3, "Building conference on call on %s and %s\n", p->subs[SUB_THREEWAY].owner->name, p->subs[SUB_REAL].owner->name);
06467                      /* Put them in the threeway, and flip */
06468                      p->subs[SUB_THREEWAY].inthreeway = 1;
06469                      p->subs[SUB_REAL].inthreeway = 1;
06470                      if (ast->_state == AST_STATE_UP) {
06471                         swap_subs(p, SUB_THREEWAY, SUB_REAL);
06472                         otherindex = SUB_REAL;
06473                      }
06474                      if (p->subs[otherindex].owner && ast_bridged_channel(p->subs[otherindex].owner))
06475                         ast_queue_control(p->subs[otherindex].owner, AST_CONTROL_UNHOLD);
06476                      p->subs[otherindex].needunhold = 1;
06477                      p->owner = p->subs[SUB_REAL].owner;
06478                      if (ast->_state == AST_STATE_RINGING) {
06479                         ast_debug(1, "Enabling ringtone on real and threeway\n");
06480                         res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
06481                         res = tone_zone_play_tone(p->subs[SUB_THREEWAY].dfd, DAHDI_TONE_RINGTONE);
06482                      }
06483                   } else {
06484                      ast_verb(3, "Dumping incomplete call on on %s\n", p->subs[SUB_THREEWAY].owner->name);
06485                      swap_subs(p, SUB_THREEWAY, SUB_REAL);
06486                      p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
06487                      p->owner = p->subs[SUB_REAL].owner;
06488                      if (p->subs[SUB_REAL].owner && ast_bridged_channel(p->subs[SUB_REAL].owner))
06489                         ast_queue_control(p->subs[SUB_REAL].owner, AST_CONTROL_UNHOLD);
06490                      p->subs[SUB_REAL].needunhold = 1;
06491                      dahdi_enable_ec(p);
06492                   }
06493                }
06494             }
06495 winkflashdone:
06496             update_conf(p);
06497             break;
06498          case SIG_EM:
06499          case SIG_EM_E1:
06500          case SIG_FEATD:
06501          case SIG_SF:
06502          case SIG_SFWINK:
06503          case SIG_SF_FEATD:
06504          case SIG_FXSLS:
06505          case SIG_FXSGS:
06506             if (option_debug) {
06507                if (p->dialing)
06508                   ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
06509                else
06510                   ast_debug(1, "Got wink in weird state %d on channel %d\n", ast->_state, p->channel);
06511             }
06512             break;
06513          case SIG_FEATDMF_TA:
06514             switch (p->whichwink) {
06515             case 0:
06516                ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", p->owner->cid.cid_ani2, p->owner->cid.cid_ani);
06517                snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#", p->owner->cid.cid_ani2, p->owner->cid.cid_ani);
06518                break;
06519             case 1:
06520                ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
06521                break;
06522             case 2:
06523                ast_log(LOG_WARNING, "Received unexpected wink on channel of type SIG_FEATDMF_TA\n");
06524                return NULL;
06525             }
06526             p->whichwink++;
06527             /* Fall through */
06528          case SIG_FEATDMF:
06529          case SIG_E911:
06530          case SIG_FGC_CAMAMF:
06531          case SIG_FGC_CAMA:
06532          case SIG_FEATB:
06533          case SIG_SF_FEATDMF:
06534          case SIG_SF_FEATB:
06535          case SIG_EMWINK:
06536             /* FGD MF and EMWINK *Must* wait for wink */
06537             if (!ast_strlen_zero(p->dop.dialstr)) {
06538                res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
06539                if (res < 0) {
06540                   ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", p->channel, strerror(errno));
06541                   p->dop.dialstr[0] = '\0';
06542                   return NULL;
06543                } else
06544                   ast_debug(1, "Sent deferred digit string: %s\n", p->dop.dialstr);
06545             }
06546             p->dop.dialstr[0] = '\0';
06547             break;
06548          default:
06549             ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
06550          }
06551          break;
06552       case DAHDI_EVENT_HOOKCOMPLETE:
06553          if (p->inalarm) break;
06554          if ((p->radio || (p->oprmode < 0))) break;
06555          if (p->waitingfordt.tv_sec) break;
06556          switch (mysig) {
06557          case SIG_FXSLS:  /* only interesting for FXS */
06558          case SIG_FXSGS:
06559          case SIG_FXSKS:
06560          case SIG_EM:
06561          case SIG_EM_E1:
06562          case SIG_EMWINK:
06563          case SIG_FEATD:
06564          case SIG_SF:
06565          case SIG_SFWINK:
06566          case SIG_SF_FEATD:
06567             if (!ast_strlen_zero(p->dop.dialstr)) {
06568                res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
06569                if (res < 0) {
06570                   ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", p->channel, strerror(errno));
06571                   p->dop.dialstr[0] = '\0';
06572                   return NULL;
06573                } else
06574                   ast_debug(1, "Sent deferred digit string: %s\n", p->dop.dialstr);
06575             }
06576             p->dop.dialstr[0] = '\0';
06577             p->dop.op = DAHDI_DIAL_OP_REPLACE;
06578             break;
06579          case SIG_FEATDMF:
06580          case SIG_FEATDMF_TA:
06581          case SIG_E911:
06582          case SIG_FGC_CAMA:
06583          case SIG_FGC_CAMAMF:
06584          case SIG_FEATB:
06585          case SIG_SF_FEATDMF:
06586          case SIG_SF_FEATB:
06587             ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
06588             break;
06589          default:
06590             break;
06591          }
06592          break;
06593       case DAHDI_EVENT_POLARITY:
06594          /*
06595           * If we get a Polarity Switch event, this could be
06596           * due to line seizure, remote end connect or remote end disconnect.
06597           *
06598           * Check to see if we should change the polarity state and
06599           * mark the channel as UP or if this is an indication
06600           * of remote end disconnect.
06601           */
06602 
06603          if (p->polarityonanswerdelay > 0) {
06604             /* check if event is not too soon after OffHook or Answer */
06605             if (ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) > p->polarityonanswerdelay) {
06606                switch (ast->_state) {
06607                case AST_STATE_DIALING:       /*!< Digits (or equivalent) have been dialed */
06608                case AST_STATE_RINGING:       /*!< Remote end is ringing */
06609                   if (p->answeronpolarityswitch) {
06610                      ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
06611                      ast_setstate(p->owner, AST_STATE_UP);
06612                      p->polarity = POLARITY_REV;
06613                      if (p->hanguponpolarityswitch) {
06614                         p->polaritydelaytv = ast_tvnow();
06615                      }
06616                   } else {
06617                      ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
06618                   }
06619                   break;
06620 
06621                case AST_STATE_UP:         /*!< Line is up */
06622                case AST_STATE_RING:       /*!< Line is ringing */
06623                   if (p->hanguponpolarityswitch) {
06624                      ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
06625                      ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
06626                      p->polarity = POLARITY_IDLE;
06627                   } else {
06628                      ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
06629                   }
06630                   break;
06631 
06632                case AST_STATE_DOWN:       /*!< Channel is down and available */
06633                case AST_STATE_RESERVED:      /*!< Channel is down, but reserved */
06634                case AST_STATE_OFFHOOK:       /*!< Channel is off hook */
06635                case AST_STATE_BUSY:       /*!< Line is busy */
06636                case AST_STATE_DIALING_OFFHOOK:     /*!< Digits (or equivalent) have been dialed while offhook */
06637                case AST_STATE_PRERING:       /*!< Channel has detected an incoming call and is waiting for ring */
06638                default:
06639                   if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
06640                      ast_debug(1, "Ignoring Polarity switch on channel %d, state %d\n", p->channel, ast->_state);
06641                   }
06642                }
06643 
06644             } else {
06645                /* event is too soon after OffHook or Answer */
06646                switch (ast->_state) {
06647                case AST_STATE_DIALING:       /*!< Digits (or equivalent) have been dialed */
06648                case AST_STATE_RINGING:       /*!< Remote end is ringing */
06649                   if (p->answeronpolarityswitch) {
06650                      ast_debug(1, "Polarity switch detected but NOT answering (too close to OffHook event) on channel %d, state %d\n", p->channel, ast->_state);
06651                   }
06652                   break;
06653 
06654                case AST_STATE_UP:         /*!< Line is up */
06655                case AST_STATE_RING:       /*!< Line is ringing */
06656                   if (p->hanguponpolarityswitch) {
06657                      ast_debug(1, "Polarity switch detected but NOT hanging up (too close to Answer event) on channel %d, state %d\n", p->channel, ast->_state);
06658                   }
06659                   break;
06660 
06661                default: 
06662                   if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
06663                      ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %d\n", p->channel, ast->_state);
06664                   }
06665                }
06666             }
06667          }
06668 
06669          /* Added more log_debug information below to provide a better indication of what is going on */
06670          ast_debug(1, "Polarity Reversal event occured - DEBUG 2: channel %d, state %d, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %d\n", p->channel, ast->_state, p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) );
06671          break;
06672       default:
06673          ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
06674    }
06675    return &p->subs[idx].f;
06676 }

static int dahdi_hangup ( struct ast_channel *  ast  )  [static]

Definition at line 4315 of file chan_dahdi.c.

References ast_channel::_state, dahdi_pvt::alerting, dahdi_pvt::alreadyhungup, ast_bridged_channel(), ast_channel_setoption(), AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, ast_dsp_free(), ast_dsp_set_digitmode(), ast_free, ast_log(), ast_module_unref(), ast_mutex_lock(), ast_mutex_unlock(), AST_OPTION_AUDIO_MODE, AST_OPTION_TDD, AST_OPTION_TONE_VERIFY, ast_queue_control(), ast_queue_control_data(), AST_STATE_RESERVED, AST_STATE_UP, ast_strlen_zero(), ast_verb, dahdi_pvt::bearer, dahdi_pvt::buf_no, dahdi_pvt::buf_policy, dahdi_pvt::bufferoverrideinuse, dahdi_pvt::bufsize, dahdi_pvt::call, dahdi_pvt::callwaitcas, dahdi_pvt::callwaiting, dahdi_pvt::callwaitingrepeat, cause, dahdi_pvt::channel, dahdi_pvt::cic, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::cidcwexpire, dahdi_pvt::cidrings, dahdi_pvt::cidspill, dahdi_pvt::confirmanswer, dahdi_ast_cause_to_r2_cause(), dahdi_confmute(), dahdi_disable_ec(), dahdi_get_index(), dahdi_r2_disconnect_call(), dahdi_set_hook(), dahdi_setlinear(), dahdi_pvt::destroy, destroy_channel(), dahdi_subchannel::dfd, dahdi_pvt::dialing, dahdi_pvt::didtdd, dahdi_pvt::digital, dahdi_pvt::distinctivering, dahdi_pvt::dsp, DSP_DIGITMODE_DTMF, dahdi_pvt::dtmfrelax, errno, dahdi_pvt::exten, dahdi_pvt::faxhandled, dahdi_pvt::fxsoffhookstate, dahdi_pvt::guardtime, ast_channel::hangupcause, dahdi_pvt::hidecallerid, iflist, iflock, dahdi_pvt::ignoredtmf, dahdi_subchannel::inthreeway, dahdi_pvt::law, dahdi_subchannel::linear, dahdi_pvt::lock, LOG_DEBUG, LOG_WARNING, dahdi_pvt::mfcr2, dahdi_pvt::mfcr2_forced_release, dahdi_pvt::mfcr2call, dahdi_pvt::mohsuggest, dahdi_pvt::muting, ast_channel::name, dahdi_subchannel::needanswer, dahdi_subchannel::needbusy, dahdi_subchannel::needcallerid, dahdi_subchannel::needcongestion, dahdi_subchannel::needflash, dahdi_subchannel::needringing, dahdi_pvt::next, dahdi_pvt::onhooktime, dahdi_pvt::oprmode, dahdi_pvt::origcid_name, dahdi_pvt::origcid_num, dahdi_pvt::outgoing, dahdi_pvt::owner, dahdi_subchannel::owner, pbx_builtin_getvar_helper(), dahdi_pvt::permcallwaiting, dahdi_pvt::permhidecallerid, dahdi_pvt::polarity, POLARITY_IDLE, dahdi_pvt::prev, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), dahdi_pvt::proceeding, dahdi_pvt::progress, dahdi_pvt::pulsedial, dahdi_pvt::r2chan, dahdi_pvt::radio, dahdi_pvt::rdnis, dahdi_pvt::realcall, reset_conf(), restart_monitor(), dahdi_pvt::restartpending, restore_gains(), dahdi_pvt::ringt, dahdi_pvt::rlt, S_OR, dahdi_pvt::setup_ack, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_MFCR2, SIG_PRI, SIG_SS7, dahdi_pvt::span, dahdi_ss7::ss7, dahdi_pvt::ss7, ss7_grab(), ss7_rel(), dahdi_pvt::ss7call, SUB_CALLWAIT, SUB_REAL, SUB_THREEWAY, dahdi_pvt::subs, swap_subs(), ast_channel::tech_pvt, unalloc_sub(), update_conf(), and dahdi_pvt::waitingfordt.

Referenced by pri_dchannel().

04316 {
04317    int res;
04318    int idx,x, law;
04319    /*static int restore_gains(struct dahdi_pvt *p);*/
04320    struct dahdi_pvt *p = ast->tech_pvt;
04321    struct dahdi_pvt *tmp = NULL;
04322    struct dahdi_pvt *prev = NULL;
04323    struct dahdi_params par;
04324 
04325    ast_debug(1, "dahdi_hangup(%s)\n", ast->name);
04326    if (!ast->tech_pvt) {
04327       ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
04328       return 0;
04329    }
04330 
04331    ast_mutex_lock(&p->lock);
04332 
04333    idx = dahdi_get_index(ast, p, 1);
04334 
04335    switch (p->sig) {
04336    case SIG_PRI:
04337    case SIG_BRI:
04338    case SIG_BRI_PTMP:
04339    case SIG_SS7:
04340       x = 1;
04341       ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
04342       /* Fall through */
04343    case SIG_MFCR2:
04344       p->cid_num[0] = '\0';
04345       p->cid_name[0] = '\0';
04346       break;
04347    default:
04348       break;
04349    }
04350 
04351    x = 0;
04352    dahdi_confmute(p, 0);
04353    p->muting = 0;
04354    restore_gains(p);
04355    if (p->origcid_num) {
04356       ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
04357       ast_free(p->origcid_num);
04358       p->origcid_num = NULL;
04359    }
04360    if (p->origcid_name) {
04361       ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
04362       ast_free(p->origcid_name);
04363       p->origcid_name = NULL;
04364    }
04365    if (p->dsp)
04366       ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
04367    p->exten[0] = '\0';
04368 
04369    ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
04370       p->channel, idx, p->subs[SUB_REAL].dfd, p->subs[SUB_CALLWAIT].dfd, p->subs[SUB_THREEWAY].dfd);
04371    p->ignoredtmf = 0;
04372 
04373    if (idx > -1) {
04374       /* Real channel, do some fixup */
04375       p->subs[idx].owner = NULL;
04376       p->subs[idx].needanswer = 0;
04377       p->subs[idx].needflash = 0;
04378       p->subs[idx].needringing = 0;
04379       p->subs[idx].needbusy = 0;
04380       p->subs[idx].needcongestion = 0;
04381       p->subs[idx].linear = 0;
04382       p->subs[idx].needcallerid = 0;
04383       p->polarity = POLARITY_IDLE;
04384       dahdi_setlinear(p->subs[idx].dfd, 0);
04385       if (idx == SUB_REAL) {
04386          if ((p->subs[SUB_CALLWAIT].dfd > -1) && (p->subs[SUB_THREEWAY].dfd > -1)) {
04387             ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n");
04388             if (p->subs[SUB_CALLWAIT].inthreeway) {
04389                /* We had flipped over to answer a callwait and now it's gone */
04390                ast_debug(1, "We were flipped over to the callwait, moving back and unowning.\n");
04391                /* Move to the call-wait, but un-own us until they flip back. */
04392                swap_subs(p, SUB_CALLWAIT, SUB_REAL);
04393                unalloc_sub(p, SUB_CALLWAIT);
04394                p->owner = NULL;
04395             } else {
04396                /* The three way hung up, but we still have a call wait */
04397                ast_debug(1, "We were in the threeway and have a callwait still.  Ditching the threeway.\n");
04398                swap_subs(p, SUB_THREEWAY, SUB_REAL);
04399                unalloc_sub(p, SUB_THREEWAY);
04400                if (p->subs[SUB_REAL].inthreeway) {
04401                   /* This was part of a three way call.  Immediately make way for
04402                      another call */
04403                   ast_debug(1, "Call was complete, setting owner to former third call\n");
04404                   p->owner = p->subs[SUB_REAL].owner;
04405                } else {
04406                   /* This call hasn't been completed yet...  Set owner to NULL */
04407                   ast_debug(1, "Call was incomplete, setting owner to NULL\n");
04408                   p->owner = NULL;
04409                }
04410                p->subs[SUB_REAL].inthreeway = 0;
04411             }
04412          } else if (p->subs[SUB_CALLWAIT].dfd > -1) {
04413             /* Move to the call-wait and switch back to them. */
04414             swap_subs(p, SUB_CALLWAIT, SUB_REAL);
04415             unalloc_sub(p, SUB_CALLWAIT);
04416             p->owner = p->subs[SUB_REAL].owner;
04417             if (p->owner->_state != AST_STATE_UP)
04418                p->subs[SUB_REAL].needanswer = 1;
04419             if (ast_bridged_channel(p->subs[SUB_REAL].owner))
04420                ast_queue_control(p->subs[SUB_REAL].owner, AST_CONTROL_UNHOLD);
04421          } else if (p->subs[SUB_THREEWAY].dfd > -1) {
04422             swap_subs(p, SUB_THREEWAY, SUB_REAL);
04423             unalloc_sub(p, SUB_THREEWAY);
04424             if (p->subs[SUB_REAL].inthreeway) {
04425                /* This was part of a three way call.  Immediately make way for
04426                   another call */
04427                ast_debug(1, "Call was complete, setting owner to former third call\n");
04428                p->owner = p->subs[SUB_REAL].owner;
04429             } else {
04430                /* This call hasn't been completed yet...  Set owner to NULL */
04431                ast_debug(1, "Call was incomplete, setting owner to NULL\n");
04432                p->owner = NULL;
04433             }
04434             p->subs[SUB_REAL].inthreeway = 0;
04435          }
04436       } else if (idx == SUB_CALLWAIT) {
04437          /* Ditch the holding callwait call, and immediately make it availabe */
04438          if (p->subs[SUB_CALLWAIT].inthreeway) {
04439             /* This is actually part of a three way, placed on hold.  Place the third part
04440                on music on hold now */
04441             if (p->subs[SUB_THREEWAY].owner && ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
04442                ast_queue_control_data(p->subs[SUB_THREEWAY].owner, AST_CONTROL_HOLD,
04443                   S_OR(p->mohsuggest, NULL),
04444                   !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
04445             }
04446             p->subs[SUB_THREEWAY].inthreeway = 0;
04447             /* Make it the call wait now */
04448             swap_subs(p, SUB_CALLWAIT, SUB_THREEWAY);
04449             unalloc_sub(p, SUB_THREEWAY);
04450          } else
04451             unalloc_sub(p, SUB_CALLWAIT);
04452       } else if (idx == SUB_THREEWAY) {
04453          if (p->subs[SUB_CALLWAIT].inthreeway) {
04454             /* The other party of the three way call is currently in a call-wait state.
04455                Start music on hold for them, and take the main guy out of the third call */
04456             if (p->subs[SUB_CALLWAIT].owner && ast_bridged_channel(p->subs[SUB_CALLWAIT].owner)) {
04457                ast_queue_control_data(p->subs[SUB_CALLWAIT].owner, AST_CONTROL_HOLD,
04458                   S_OR(p->mohsuggest, NULL),
04459                   !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
04460             }
04461             p->subs[SUB_CALLWAIT].inthreeway = 0;
04462          }
04463          p->subs[SUB_REAL].inthreeway = 0;
04464          /* If this was part of a three way call index, let us make
04465             another three way call */
04466          unalloc_sub(p, SUB_THREEWAY);
04467       } else {
04468          /* This wasn't any sort of call, but how are we an index? */
04469          ast_log(LOG_WARNING, "Index found but not any type of call?\n");
04470       }
04471    }
04472 
04473    if (!p->subs[SUB_REAL].owner && !p->subs[SUB_CALLWAIT].owner && !p->subs[SUB_THREEWAY].owner) {
04474       p->owner = NULL;
04475       p->ringt = 0;
04476       p->distinctivering = 0;
04477       p->confirmanswer = 0;
04478       p->cidrings = 1;
04479       p->outgoing = 0;
04480       p->digital = 0;
04481       p->faxhandled = 0;
04482       p->pulsedial = 0;
04483       p->onhooktime = time(NULL);
04484 #if defined(HAVE_PRI) || defined(HAVE_SS7)
04485       p->proceeding = 0;
04486       p->dialing = 0;
04487       p->progress = 0;
04488       p->alerting = 0;
04489       p->setup_ack = 0;
04490       p->rlt = 0;
04491 #endif
04492       if (p->dsp) {
04493          ast_dsp_free(p->dsp);
04494          p->dsp = NULL;
04495       }
04496 
04497       if (p->bufferoverrideinuse) {
04498          /* faxbuffers are in use, revert them */
04499          struct dahdi_bufferinfo bi = {
04500             .txbufpolicy = p->buf_policy,
04501             .rxbufpolicy = p->buf_policy,
04502             .bufsize = p->bufsize,
04503             .numbufs = p->buf_no
04504          };
04505          int bpres;
04506 
04507          if ((bpres = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
04508             ast_log(LOG_WARNING, "Channel '%s' unable to revert faxbuffer policy: %s\n", ast->name, strerror(errno));
04509          }
04510          p->bufferoverrideinuse = 0;
04511       }
04512 
04513       law = DAHDI_LAW_DEFAULT;
04514       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
04515       if (res < 0)
04516          ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
04517       /* Perform low level hangup if no owner left */
04518 #ifdef HAVE_SS7
04519       if (p->ss7) {
04520          if (p->ss7call) {
04521             if (!ss7_grab(p, p->ss7)) {
04522                if (!p->alreadyhungup) {
04523                   const char *cause = pbx_builtin_getvar_helper(ast,"SS7_CAUSE");
04524                   int icause = ast->hangupcause ? ast->hangupcause : -1;
04525 
04526                   if (cause) {
04527                      if (atoi(cause))
04528                         icause = atoi(cause);
04529                   }
04530                   isup_rel(p->ss7->ss7, p->ss7call, icause);
04531                   ss7_rel(p->ss7);
04532                   p->alreadyhungup = 1;
04533                } else
04534                   ast_log(LOG_WARNING, "Trying to hangup twice!\n");
04535             } else {
04536                ast_log(LOG_WARNING, "Unable to grab SS7 on CIC %d\n", p->cic);
04537                res = -1;
04538             }
04539          }
04540       }
04541 #endif
04542 #ifdef HAVE_OPENR2
04543       if (p->mfcr2 && p->mfcr2call && openr2_chan_get_direction(p->r2chan) != OR2_DIR_STOPPED) {
04544          ast_log(LOG_DEBUG, "disconnecting MFC/R2 call on chan %d\n", p->channel);
04545          /* If it's an incoming call, check the mfcr2_forced_release setting */
04546          if (openr2_chan_get_direction(p->r2chan) == OR2_DIR_BACKWARD && p->mfcr2_forced_release) {
04547             dahdi_r2_disconnect_call(p, OR2_CAUSE_FORCED_RELEASE);
04548          } else {
04549             const char *r2causestr = pbx_builtin_getvar_helper(ast, "MFCR2_CAUSE");
04550             int r2cause_user = r2causestr ? atoi(r2causestr) : 0;
04551             openr2_call_disconnect_cause_t r2cause = r2cause_user ? dahdi_ast_cause_to_r2_cause(r2cause_user)
04552                                                              : dahdi_ast_cause_to_r2_cause(ast->hangupcause);
04553             dahdi_r2_disconnect_call(p, r2cause);
04554          }
04555       } else if (p->mfcr2call) {
04556          ast_log(LOG_DEBUG, "Clearing call request on channel %d\n", p->channel);
04557          /* since ast_request() was called but not ast_call() we have not yet dialed
04558          and the openr2 stack will not call on_call_end callback, we need to unset
04559          the mfcr2call flag and bump the monitor count so the monitor thread can take
04560          care of this channel events from now on */
04561          p->mfcr2call = 0;
04562       }
04563 #endif
04564 #ifdef HAVE_PRI
04565       if (p->pri) {
04566 #ifdef SUPPORT_USERUSER
04567          const char *useruser = pbx_builtin_getvar_helper(ast,"USERUSERINFO");
04568 #endif
04569 
04570          /* Make sure we have a call (or REALLY have a call in the case of a PRI) */
04571          if (p->call && (!p->bearer || (p->bearer->call == p->call))) {
04572             if (!pri_grab(p, p->pri)) {
04573                if (p->alreadyhungup) {
04574                   ast_debug(1, "Already hungup...  Calling hangup once, and clearing call\n");
04575 
04576 #ifdef SUPPORT_USERUSER
04577                   pri_call_set_useruser(p->call, useruser);
04578 #endif
04579 
04580                   pri_hangup(p->pri->pri, p->call, -1);
04581                   p->call = NULL;
04582                   if (p->bearer)
04583                      p->bearer->call = NULL;
04584                } else {
04585                   const char *cause = pbx_builtin_getvar_helper(ast,"PRI_CAUSE");
04586                   int icause = ast->hangupcause ? ast->hangupcause : -1;
04587                   ast_debug(1, "Not yet hungup...  Calling hangup once with icause, and clearing call\n");
04588 
04589 #ifdef SUPPORT_USERUSER
04590                   pri_call_set_useruser(p->call, useruser);
04591 #endif
04592 
04593                   p->alreadyhungup = 1;
04594                   if (p->bearer)
04595                      p->bearer->alreadyhungup = 1;
04596                   if (cause) {
04597                      if (atoi(cause))
04598                         icause = atoi(cause);
04599                   }
04600                   pri_hangup(p->pri->pri, p->call, icause);
04601                }
04602                if (res < 0)
04603                   ast_log(LOG_WARNING, "pri_disconnect failed\n");
04604                pri_rel(p->pri);
04605             } else {
04606                ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
04607                res = -1;
04608             }
04609          } else {
04610             if (p->bearer)
04611                ast_debug(1, "Bearer call is %p, while ours is still %p\n", p->bearer->call, p->call);
04612             p->call = NULL;
04613             res = 0;
04614          }
04615       }
04616 #endif
04617       if (p->sig && ((p->sig != SIG_PRI) && (p->sig != SIG_SS7)
04618          && (p->sig != SIG_BRI)
04619          && (p->sig != SIG_BRI_PTMP))
04620          && (p->sig != SIG_MFCR2))
04621          res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_ONHOOK);
04622       if (res < 0) {
04623          ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast->name);
04624       }
04625       switch (p->sig) {
04626       case SIG_FXOGS:
04627       case SIG_FXOLS:
04628       case SIG_FXOKS:
04629          memset(&par, 0, sizeof(par));
04630          res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
04631          if (!res) {
04632 #if 0
04633             ast_debug(1, "Hanging up channel %d, offhook = %d\n", p->channel, par.rxisoffhook);
04634 #endif
04635             /* If they're off hook, try playing congestion */
04636             if ((par.rxisoffhook) && (!(p->radio || (p->oprmode < 0))))
04637                tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
04638             else
04639                tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1);
04640             p->fxsoffhookstate = par.rxisoffhook;
04641          }
04642          break;
04643       case SIG_FXSGS:
04644       case SIG_FXSLS:
04645       case SIG_FXSKS:
04646          /* Make sure we're not made available for at least two seconds assuming
04647             we were actually used for an inbound or outbound call. */
04648          if (ast->_state != AST_STATE_RESERVED) {
04649             time(&p->guardtime);
04650             p->guardtime += 2;
04651          }
04652          break;
04653       default:
04654          tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1);
04655       }
04656       if (p->cidspill)
04657          ast_free(p->cidspill);
04658       if (p->sig)
04659          dahdi_disable_ec(p);
04660       x = 0;
04661       ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
04662       ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
04663       p->didtdd = 0;
04664       p->cidspill = NULL;
04665       p->callwaitcas = 0;
04666       p->callwaiting = p->permcallwaiting;
04667       p->hidecallerid = p->permhidecallerid;
04668       p->waitingfordt.tv_sec = 0;
04669       p->dialing = 0;
04670       p->rdnis[0] = '\0';
04671       update_conf(p);
04672       reset_conf(p);
04673       /* Restore data mode */
04674       if ((p->sig == SIG_PRI) || (p->sig == SIG_SS7) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) {
04675          x = 0;
04676          ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
04677       }
04678 #ifdef HAVE_PRI
04679       if (p->bearer) {
04680          ast_debug(1, "Freeing up bearer channel %d\n", p->bearer->channel);
04681          /* Free up the bearer channel as well, and
04682             don't use its file descriptor anymore */
04683          update_conf(p->bearer);
04684          reset_conf(p->bearer);
04685          p->bearer->owner = NULL;
04686          p->bearer->realcall = NULL;
04687          p->bearer = NULL;
04688          p->subs[SUB_REAL].dfd = -1;
04689          p->pri = NULL;
04690       }
04691 #endif
04692       if (num_restart_pending == 0)
04693          restart_monitor();
04694    }
04695 
04696    p->callwaitingrepeat = 0;
04697    p->cidcwexpire = 0;
04698    p->oprmode = 0;
04699    ast->tech_pvt = NULL;
04700    ast_mutex_unlock(&p->lock);
04701    ast_module_unref(ast_module_info->self);
04702    ast_verb(3, "Hungup '%s'\n", ast->name);
04703 
04704    ast_mutex_lock(&iflock);
04705 
04706    if (p->restartpending) {
04707       num_restart_pending--;
04708    }
04709 
04710    tmp = iflist;
04711    prev = NULL;
04712    if (p->destroy) {
04713       while (tmp) {
04714          if (tmp == p) {
04715             destroy_channel(prev, tmp, 0);
04716             break;
04717          } else {
04718             prev = tmp;
04719             tmp = tmp->next;
04720          }
04721       }
04722    }
04723    ast_mutex_unlock(&iflock);
04724    return 0;
04725 }

static int dahdi_indicate ( struct ast_channel *  chan,
int  condition,
const void *  data,
size_t  datalen 
) [static]

Definition at line 7247 of file chan_dahdi.c.

References ast_channel::_softhangup, ast_channel::_state, dahdi_pvt::alerting, AST_CAUSE_CONGESTION, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_USER_BUSY, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, ast_debug, ast_log(), ast_moh_start(), ast_moh_stop(), ast_mutex_lock(), ast_mutex_unlock(), ast_setstate(), AST_SOFTHANGUP_DEV, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, dahdi_pvt::call, dahdi_enable_ec(), dahdi_get_index(), dahdi_set_hook(), dahdi_subchannel::dfd, dahdi_pvt::dialing, dahdi_pvt::digital, dahdi_pvt::dop, errno, ast_channel::hangupcause, ISTRUNK, dahdi_pvt::lock, LOG_WARNING, dahdi_pvt::mfcr2, dahdi_pvt::mfcr2_call_accepted, dahdi_pvt::mohinterpret, ast_channel::name, dahdi_pvt::outgoing, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), dahdi_pvt::priindication_oob, dahdi_pvt::prioffset, dahdi_pvt::proceeding, dahdi_pvt::progress, PVT_TO_CHANNEL, dahdi_pvt::radio, dahdi_pvt::rlt, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_PRI, SIG_SS7, dahdi_pvt::span, dahdi_ss7::ss7, dahdi_pvt::ss7, ss7_grab(), ss7_rel(), dahdi_pvt::ss7call, SUB_REAL, dahdi_pvt::subs, and ast_channel::tech_pvt.

Referenced by dahdi_fixup().

07248 {
07249    struct dahdi_pvt *p = chan->tech_pvt;
07250    int res=-1;
07251    int idx;
07252    int func = DAHDI_FLASH;
07253    ast_mutex_lock(&p->lock);
07254    idx = dahdi_get_index(chan, p, 0);
07255    ast_debug(1, "Requested indication %d on channel %s\n", condition, chan->name);
07256 #ifdef HAVE_OPENR2
07257    if (p->mfcr2 && !p->mfcr2_call_accepted) {
07258       ast_mutex_unlock(&p->lock);
07259       /* if this is an R2 call and the call is not yet accepted, we don't want the
07260          tone indications to mess up with the MF tones */
07261       return 0;
07262    }
07263 #endif
07264    if (idx == SUB_REAL) {
07265       switch (condition) {
07266       case AST_CONTROL_BUSY:
07267 #ifdef HAVE_PRI
07268          if (p->priindication_oob && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP))) {
07269             chan->hangupcause = AST_CAUSE_USER_BUSY;
07270             chan->_softhangup |= AST_SOFTHANGUP_DEV;
07271             res = 0;
07272          } else if (!p->progress &&
07273                ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP))
07274                && p->pri && !p->outgoing) {
07275             if (p->pri->pri) {
07276                if (!pri_grab(p, p->pri)) {
07277 #ifdef HAVE_PRI_PROG_W_CAUSE
07278                   pri_progress_with_cause(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1, PRI_CAUSE_USER_BUSY); /* cause = 17 */
07279 #else
07280                   pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1);
07281 #endif
07282                   pri_rel(p->pri);
07283                }
07284                else
07285                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07286             }
07287             p->progress = 1;
07288             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_BUSY);
07289          } else
07290 #endif
07291             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_BUSY);
07292          break;
07293       case AST_CONTROL_RINGING:
07294 #ifdef HAVE_PRI
07295          if ((!p->alerting) && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP))
07296                && p->pri && !p->outgoing && (chan->_state != AST_STATE_UP)) {
07297             if (p->pri->pri) {
07298                if (!pri_grab(p, p->pri)) {
07299                   pri_acknowledge(p->pri->pri,p->call, PVT_TO_CHANNEL(p), !p->digital);
07300                   pri_rel(p->pri);
07301                }
07302                else
07303                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07304             }
07305             p->alerting = 1;
07306          }
07307 
07308 #endif
07309 #ifdef HAVE_SS7
07310          if ((!p->alerting) && (p->sig == SIG_SS7) && p->ss7 && !p->outgoing && (chan->_state != AST_STATE_UP)) {
07311             if (p->ss7->ss7) {
07312                ss7_grab(p, p->ss7);
07313 
07314                if ((isup_far(p->ss7->ss7, p->ss7call)) != -1)
07315                   p->rlt = 1;
07316                if (p->rlt != 1) /* No need to send CPG if call will be RELEASE */
07317                   isup_cpg(p->ss7->ss7, p->ss7call, CPG_EVENT_ALERTING);
07318                p->alerting = 1;
07319                ss7_rel(p->ss7);
07320             }
07321          }
07322 #endif
07323 
07324          res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_RINGTONE);
07325 
07326          if (chan->_state != AST_STATE_UP) {
07327             if ((chan->_state != AST_STATE_RING) ||
07328                ((p->sig != SIG_FXSKS) &&
07329              (p->sig != SIG_FXSLS) &&
07330              (p->sig != SIG_FXSGS)))
07331             ast_setstate(chan, AST_STATE_RINGING);
07332          }
07333          break;
07334       case AST_CONTROL_PROCEEDING:
07335          ast_debug(1,"Received AST_CONTROL_PROCEEDING on %s\n",chan->name);
07336 #ifdef HAVE_PRI
07337          if (!p->proceeding && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP))
07338                && p->pri && !p->outgoing) {
07339             if (p->pri->pri) {
07340                if (!pri_grab(p, p->pri)) {
07341                   pri_proceeding(p->pri->pri,p->call, PVT_TO_CHANNEL(p), !p->digital);
07342                   pri_rel(p->pri);
07343                }
07344                else
07345                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07346             }
07347             p->proceeding = 1;
07348             p->dialing = 0;
07349          }
07350 #endif
07351 #ifdef HAVE_SS7
07352          /* This IF sends the FAR for an answered ALEG call */
07353          if (chan->_state == AST_STATE_UP && (p->rlt != 1) && (p->sig == SIG_SS7)){
07354             if ((isup_far(p->ss7->ss7, p->ss7call)) != -1)
07355                p->rlt = 1;
07356          }
07357 
07358          if (!p->proceeding && p->sig == SIG_SS7 && p->ss7 && !p->outgoing) {
07359             if (p->ss7->ss7) {
07360                ss7_grab(p, p->ss7);
07361                isup_acm(p->ss7->ss7, p->ss7call);
07362                p->proceeding = 1;
07363                ss7_rel(p->ss7);
07364 
07365             }
07366          }
07367 #endif
07368          /* don't continue in ast_indicate */
07369          res = 0;
07370          break;
07371       case AST_CONTROL_PROGRESS:
07372          ast_debug(1,"Received AST_CONTROL_PROGRESS on %s\n",chan->name);
07373 #ifdef HAVE_PRI
07374          p->digital = 0;   /* Digital-only calls isn't allows any inband progress messages */
07375          if (!p->progress && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP))
07376                && p->pri && !p->outgoing) {
07377             if (p->pri->pri) {
07378                if (!pri_grab(p, p->pri)) {
07379 #ifdef HAVE_PRI_PROG_W_CAUSE
07380                   pri_progress_with_cause(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1, -1);  /* no cause at all */
07381 #else
07382                   pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1);
07383 #endif
07384                   pri_rel(p->pri);
07385                }
07386                else
07387                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07388             }
07389             p->progress = 1;
07390          }
07391 #endif
07392 #ifdef HAVE_SS7
07393          if (!p->progress && p->sig==SIG_SS7 && p->ss7 && !p->outgoing) {
07394             if (p->ss7->ss7) {
07395                ss7_grab(p, p->ss7);
07396                isup_cpg(p->ss7->ss7, p->ss7call, CPG_EVENT_INBANDINFO);
07397                p->progress = 1;
07398                ss7_rel(p->ss7);
07399                /* enable echo canceler here on SS7 calls */
07400                dahdi_enable_ec(p);
07401 
07402             }
07403          }
07404 #endif
07405          /* don't continue in ast_indicate */
07406          res = 0;
07407          break;
07408       case AST_CONTROL_CONGESTION:
07409          chan->hangupcause = AST_CAUSE_CONGESTION;
07410 #ifdef HAVE_PRI
07411          if (p->priindication_oob && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP))) {
07412             chan->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
07413             chan->_softhangup |= AST_SOFTHANGUP_DEV;
07414             res = 0;
07415          } else if (!p->progress && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP))
07416                && p->pri && !p->outgoing) {
07417             if (p->pri) {
07418                if (!pri_grab(p, p->pri)) {
07419 #ifdef HAVE_PRI_PROG_W_CAUSE
07420                   pri_progress_with_cause(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1, PRI_CAUSE_SWITCH_CONGESTION); /* cause = 42 */
07421 #else
07422                   pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), 1);
07423 #endif
07424                   pri_rel(p->pri);
07425                } else
07426                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07427             }
07428             p->progress = 1;
07429             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
07430          } else
07431 #endif
07432             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
07433          break;
07434       case AST_CONTROL_HOLD:
07435 #ifdef HAVE_PRI
07436          if (p->pri && !strcasecmp(p->mohinterpret, "passthrough")) {
07437             if (!pri_grab(p, p->pri)) {
07438                res = pri_notify(p->pri->pri, p->call, p->prioffset, PRI_NOTIFY_REMOTE_HOLD);
07439                pri_rel(p->pri);
07440             } else
07441                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07442          } else
07443 #endif
07444             ast_moh_start(chan, data, p->mohinterpret);
07445          break;
07446       case AST_CONTROL_UNHOLD:
07447 #ifdef HAVE_PRI
07448          if (p->pri && !strcasecmp(p->mohinterpret, "passthrough")) {
07449             if (!pri_grab(p, p->pri)) {
07450                res = pri_notify(p->pri->pri, p->call, p->prioffset, PRI_NOTIFY_REMOTE_RETRIEVAL);
07451                pri_rel(p->pri);
07452             } else
07453                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07454          } else
07455 #endif
07456             ast_moh_stop(chan);
07457          break;
07458       case AST_CONTROL_RADIO_KEY:
07459          if (p->radio)
07460             res = dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK);
07461          res = 0;
07462          break;
07463       case AST_CONTROL_RADIO_UNKEY:
07464          if (p->radio)
07465             res = dahdi_set_hook(p->subs[idx].dfd, DAHDI_RINGOFF);
07466          res = 0;
07467          break;
07468       case AST_CONTROL_FLASH:
07469          /* flash hookswitch */
07470          if (ISTRUNK(p) && (p->sig != SIG_PRI)) {
07471             /* Clear out the dial buffer */
07472             p->dop.dialstr[0] = '\0';
07473             if ((ioctl(p->subs[SUB_REAL].dfd,DAHDI_HOOK,&func) == -1) && (errno != EINPROGRESS)) {
07474                ast_log(LOG_WARNING, "Unable to flash external trunk on channel %s: %s\n",
07475                   chan->name, strerror(errno));
07476             } else
07477                res = 0;
07478          } else
07479             res = 0;
07480          break;
07481       case AST_CONTROL_SRCUPDATE:
07482          res = 0;
07483          break;
07484       case -1:
07485          res = tone_zone_play_tone(p->subs[idx].dfd, -1);
07486          break;
07487       }
07488    } else
07489       res = 0;
07490    ast_mutex_unlock(&p->lock);
07491    return res;
07492 }

static void dahdi_link ( struct dahdi_pvt *  slave,
struct dahdi_pvt *  master 
) [static]

Definition at line 5174 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_pvt::channel, LOG_WARNING, dahdi_pvt::master, MAX_SLAVES, and dahdi_pvt::slaves.

Referenced by dahdi_bridge().

05174                                                                           {
05175    int x;
05176    if (!slave || !master) {
05177       ast_log(LOG_WARNING, "Tried to link to/from NULL??\n");
05178       return;
05179    }
05180    for (x = 0; x < MAX_SLAVES; x++) {
05181       if (!master->slaves[x]) {
05182          master->slaves[x] = slave;
05183          break;
05184       }
05185    }
05186    if (x >= MAX_SLAVES) {
05187       ast_log(LOG_WARNING, "Replacing slave %d with new slave, %d\n", master->slaves[MAX_SLAVES - 1]->channel, slave->channel);
05188       master->slaves[MAX_SLAVES - 1] = slave;
05189    }
05190    if (slave->master)
05191       ast_log(LOG_WARNING, "Replacing master %d with new master, %d\n", slave->master->channel, master->channel);
05192    slave->master = master;
05193 
05194    ast_debug(1, "Making %d slave to master %d at %d\n", slave->channel, master->channel, x);
05195 }

static void dahdi_loopback ( struct dahdi_pvt *  p,
int  enable 
) [static]

Definition at line 11337 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::channel, dahdi_subchannel::dfd, errno, LOG_WARNING, dahdi_pvt::loopedback, SUB_REAL, and dahdi_pvt::subs.

Referenced by ss7_linkset().

11338 {
11339    if (p->loopedback != enable) {
11340       if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_LOOPBACK, &enable)) {
11341          ast_log(LOG_WARNING, "Unable to set loopback on channel %d: %s\n", p->channel, strerror(errno));
11342          return;
11343       }
11344       p->loopedback = enable;
11345    }
11346 }

static struct ast_channel * dahdi_new ( struct dahdi_pvt *  i,
int  state,
int  startpbx,
int  idx,
int  law,
int  transfercapability 
) [static, read]

Definition at line 7494 of file chan_dahdi.c.

References accountcode, dahdi_pvt::accountcode, dahdi_pvt::adsi, ast_channel::adsicpe, dahdi_pvt::alreadyhungup, ast_channel::amaflags, dahdi_pvt::amaflags, AST_ADSI_UNAVAILABLE, ast_channel_alloc, ast_channel_set_fd(), ast_copy_string(), ast_debug, ast_devstate_changed_literal(), ast_dsp_new(), ast_dsp_set_busy_count(), ast_dsp_set_busy_pattern(), ast_dsp_set_call_progress_zone(), ast_dsp_set_digitmode(), ast_dsp_set_features(), AST_FORMAT_ALAW, AST_FORMAT_ULAW, ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_pbx_start(), ast_random(), ast_state_chan2dev(), AST_STATE_RING, ast_str_alloca, ast_str_buffer(), ast_str_set(), ast_strdup, ast_string_field_set, ast_strlen_zero(), AST_TRANS_CAP_DIGITAL, ast_transfercapability2str(), dahdi_pvt::bearer, dahdi_pvt::busy_quietlength, dahdi_pvt::busy_tonelength, dahdi_pvt::busycount, dahdi_pvt::busydetect, dahdi_pvt::call_forward, dahdi_pvt::callgroup, ast_channel::callgroup, dahdi_pvt::callingpres, dahdi_pvt::callprogress, CALLPROGRESS_FAX_INCOMING, CALLPROGRESS_FAX_OUTGOING, CALLPROGRESS_PROGRESS, CANBUSYDETECT, CANPROGRESSDETECT, CHAN_PSEUDO, dahdi_pvt::channel, ast_channel::cid, ast_callerid::cid_ani, dahdi_pvt::cid_ani, dahdi_pvt::cid_ani2, ast_callerid::cid_ani2, ast_callerid::cid_dnid, dahdi_pvt::cid_name, dahdi_pvt::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, dahdi_pvt::cid_ton, ast_callerid::cid_ton, ast_channel::context, dahdi_pvt::context, dahdi_confmute(), dahdi_setlinear(), dahdi_subchannel::dfd, dahdi_pvt::digital, dahdi_pvt::dnid, dahdi_pvt::dsp, DSP_DIGITMODE_DTMF, DSP_FEATURE_BUSY_DETECT, DSP_FEATURE_CALL_PROGRESS, DSP_FEATURE_DIGIT_DETECT, DSP_FEATURE_FAX_DETECT, DSP_FEATURE_WAITDIALTONE, dahdi_pvt::dsp_features, DSP_PROGRESS_TALK, dahdi_pvt::dtmfrelax, errno, ast_channel::exten, dahdi_pvt::exten, dahdi_pvt::fake_event, global_jbconf, dahdi_pvt::hardwaredtmf, dahdi_pvt::isidlecall, language, dahdi_pvt::language, dahdi_subchannel::linear, LOG_WARNING, dahdi_pvt::mfcr2_recvd_category, dahdi_pvt::mfcr2call, dahdi_pvt::muting, ast_variable::name, ast_channel::name, ast_channel::nativeformats, NEED_MFDETECT, ast_variable::next, dahdi_pvt::outgoing, dahdi_pvt::owner, dahdi_subchannel::owner, dahdi_pvt::parkinglot, pbx_builtin_setvar_helper(), dahdi_pvt::pickupgroup, ast_channel::pickupgroup, dahdi_pvt::pri, ast_channel::rawreadformat, ast_channel::rawwriteformat, dahdi_pvt::rdnis, ast_channel::readformat, ast_channel::rings, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSKS, SIG_PRI, SIG_SS7, SUB_REAL, dahdi_pvt::subs, ast_channel::tech, ast_channel::tech_pvt, ast_channel::transfercapability, dahdi_pri::trunkgroup, ast_variable::value, dahdi_pvt::vars, dahdi_pvt::waitfordialtone, and ast_channel::writeformat.

Referenced by dahdi_handle_event(), dahdi_r2_on_call_accepted(), dahdi_r2_on_call_offered(), dahdi_request(), handle_init_event(), mwi_thread(), pri_dchannel(), and ss7_start_call().

07495 {
07496    struct ast_channel *tmp;
07497    int deflaw;
07498    int res;
07499    int x,y;
07500    int features;
07501    struct ast_str *chan_name;
07502    struct ast_variable *v;
07503    struct dahdi_params ps;
07504    if (i->subs[idx].owner) {
07505       ast_log(LOG_WARNING, "Channel %d already has a %s call\n", i->channel,subnames[idx]);
07506       return NULL;
07507    }
07508    y = 1;
07509    chan_name = ast_str_alloca(32);
07510    do {
07511 #ifdef HAVE_PRI
07512       if (i->bearer || (i->pri && (i->sig == SIG_FXSKS)))
07513          ast_str_set(&chan_name, 0, "%d:%d-%d", i->pri->trunkgroup, i->channel, y);
07514       else
07515 #endif
07516       if (i->channel == CHAN_PSEUDO)
07517          ast_str_set(&chan_name, 0, "pseudo-%ld", ast_random());
07518       else
07519          ast_str_set(&chan_name, 0, "%d-%d", i->channel, y);
07520       for (x = 0; x < 3; x++) {
07521          if ((idx != x) && i->subs[x].owner && !strcasecmp(ast_str_buffer(chan_name), i->subs[x].owner->name + 6))
07522             break;
07523       }
07524       y++;
07525    } while (x < 3);
07526    tmp = ast_channel_alloc(0, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "DAHDI/%s", ast_str_buffer(chan_name));
07527    if (!tmp)
07528       return NULL;
07529    tmp->tech = &dahdi_tech;
07530    memset(&ps, 0, sizeof(ps));
07531    ps.channo = i->channel;
07532    res = ioctl(i->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps);
07533    if (res) {
07534       ast_log(LOG_WARNING, "Unable to get parameters, assuming MULAW: %s\n", strerror(errno));
07535       ps.curlaw = DAHDI_LAW_MULAW;
07536    }
07537    if (ps.curlaw == DAHDI_LAW_ALAW)
07538       deflaw = AST_FORMAT_ALAW;
07539    else
07540       deflaw = AST_FORMAT_ULAW;
07541    if (law) {
07542       if (law == DAHDI_LAW_ALAW)
07543          deflaw = AST_FORMAT_ALAW;
07544       else
07545          deflaw = AST_FORMAT_ULAW;
07546    }
07547    ast_channel_set_fd(tmp, 0, i->subs[idx].dfd);
07548    tmp->nativeformats = deflaw;
07549    /* Start out assuming ulaw since it's smaller :) */
07550    tmp->rawreadformat = deflaw;
07551    tmp->readformat = deflaw;
07552    tmp->rawwriteformat = deflaw;
07553    tmp->writeformat = deflaw;
07554    i->subs[idx].linear = 0;
07555    dahdi_setlinear(i->subs[idx].dfd, i->subs[idx].linear);
07556    features = 0;
07557    if (idx == SUB_REAL) {
07558       if (i->busydetect && CANBUSYDETECT(i))
07559          features |= DSP_FEATURE_BUSY_DETECT;
07560       if ((i->callprogress & CALLPROGRESS_PROGRESS) && CANPROGRESSDETECT(i))
07561          features |= DSP_FEATURE_CALL_PROGRESS;
07562       if ((i->waitfordialtone) && CANPROGRESSDETECT(i))
07563          features |= DSP_FEATURE_WAITDIALTONE;
07564       if ((!i->outgoing && (i->callprogress & CALLPROGRESS_FAX_INCOMING)) ||
07565          (i->outgoing && (i->callprogress & CALLPROGRESS_FAX_OUTGOING))) {
07566          features |= DSP_FEATURE_FAX_DETECT;
07567       }
07568       x = DAHDI_TONEDETECT_ON | DAHDI_TONEDETECT_MUTE;
07569       if (ioctl(i->subs[idx].dfd, DAHDI_TONEDETECT, &x)) {
07570          i->hardwaredtmf = 0;
07571          features |= DSP_FEATURE_DIGIT_DETECT;
07572       } else if (NEED_MFDETECT(i)) {
07573          i->hardwaredtmf = 1;
07574          features |= DSP_FEATURE_DIGIT_DETECT;
07575       }
07576    }
07577    if (features) {
07578       if (i->dsp) {
07579          ast_debug(1, "Already have a dsp on %s?\n", tmp->name);
07580       } else {
07581          if (i->channel != CHAN_PSEUDO)
07582             i->dsp = ast_dsp_new();
07583          else
07584             i->dsp = NULL;
07585          if (i->dsp) {
07586             i->dsp_features = features;
07587 #if defined(HAVE_PRI) || defined(HAVE_SS7)
07588             /* We cannot do progress detection until receives PROGRESS message */
07589             if (i->outgoing && ((i->sig == SIG_PRI) || (i->sig == SIG_BRI) || (i->sig == SIG_BRI_PTMP) || (i->sig == SIG_SS7))) {
07590                /* Remember requested DSP features, don't treat
07591                   talking as ANSWER */
07592                i->dsp_features = features & ~DSP_PROGRESS_TALK;
07593                features = 0;
07594             }
07595 #endif
07596             ast_dsp_set_features(i->dsp, features);
07597             ast_dsp_set_digitmode(i->dsp, DSP_DIGITMODE_DTMF | i->dtmfrelax);
07598             if (!ast_strlen_zero(progzone))
07599                ast_dsp_set_call_progress_zone(i->dsp, progzone);
07600             if (i->busydetect && CANBUSYDETECT(i)) {
07601                ast_dsp_set_busy_count(i->dsp, i->busycount);
07602                ast_dsp_set_busy_pattern(i->dsp, i->busy_tonelength, i->busy_quietlength);
07603             }
07604          }
07605       }
07606    }
07607 
07608    if (state == AST_STATE_RING)
07609       tmp->rings = 1;
07610    tmp->tech_pvt = i;
07611    if ((i->sig == SIG_FXOKS) || (i->sig == SIG_FXOGS) || (i->sig == SIG_FXOLS)) {
07612       /* Only FXO signalled stuff can be picked up */
07613       tmp->callgroup = i->callgroup;
07614       tmp->pickupgroup = i->pickupgroup;
07615    }
07616    if (!ast_strlen_zero(i->parkinglot))
07617       ast_string_field_set(tmp, parkinglot, i->parkinglot);
07618    if (!ast_strlen_zero(i->language))
07619       ast_string_field_set(tmp, language, i->language);
07620    if (!i->owner)
07621       i->owner = tmp;
07622    if (!ast_strlen_zero(i->accountcode))
07623       ast_string_field_set(tmp, accountcode, i->accountcode);
07624    if (i->amaflags)
07625       tmp->amaflags = i->amaflags;
07626    i->subs[idx].owner = tmp;
07627    ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
07628    ast_string_field_set(tmp, call_forward, i->call_forward);
07629    /* If we've been told "no ADSI" then enforce it */
07630    if (!i->adsi)
07631       tmp->adsicpe = AST_ADSI_UNAVAILABLE;
07632    if (!ast_strlen_zero(i->exten))
07633       ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
07634    if (!ast_strlen_zero(i->rdnis))
07635       tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
07636    if (!ast_strlen_zero(i->dnid))
07637       tmp->cid.cid_dnid = ast_strdup(i->dnid);
07638 
07639    /* Don't use ast_set_callerid() here because it will
07640     * generate a needless NewCallerID event */
07641 #ifdef PRI_ANI
07642    if (!ast_strlen_zero(i->cid_ani))
07643       tmp->cid.cid_ani = ast_strdup(i->cid_ani);
07644    else
07645       tmp->cid.cid_ani = ast_strdup(i->cid_num);
07646 #else
07647    tmp->cid.cid_ani = ast_strdup(i->cid_num);
07648 #endif
07649    tmp->cid.cid_pres = i->callingpres;
07650    tmp->cid.cid_ton = i->cid_ton;
07651    tmp->cid.cid_ani2 = i->cid_ani2;
07652 #if defined(HAVE_PRI) || defined(HAVE_SS7)
07653    tmp->transfercapability = transfercapability;
07654    pbx_builtin_setvar_helper(tmp, "TRANSFERCAPABILITY", ast_transfercapability2str(transfercapability));
07655    if (transfercapability & AST_TRANS_CAP_DIGITAL)
07656       i->digital = 1;
07657    /* Assume calls are not idle calls unless we're told differently */
07658    i->isidlecall = 0;
07659    i->alreadyhungup = 0;
07660 #endif
07661    /* clear the fake event in case we posted one before we had ast_channel */
07662    i->fake_event = 0;
07663    /* Assure there is no confmute on this channel */
07664    dahdi_confmute(i, 0);
07665    i->muting = 0;
07666    /* Configure the new channel jb */
07667    ast_jb_configure(tmp, &global_jbconf);
07668 
07669    ast_devstate_changed_literal(ast_state_chan2dev(state), tmp->name);
07670 
07671    for (v = i->vars ; v ; v = v->next)
07672       pbx_builtin_setvar_helper(tmp, v->name, v->value);
07673 
07674    if (startpbx) {
07675 #ifdef HAVE_OPENR2
07676       if (i->mfcr2call) {
07677          pbx_builtin_setvar_helper(tmp, "MFCR2_CATEGORY", openr2_proto_get_category_string(i->mfcr2_recvd_category));
07678       }
07679 #endif
07680       if (ast_pbx_start(tmp)) {
07681          ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
07682          ast_hangup(tmp);
07683          i->owner = NULL;
07684          return NULL;
07685       }
07686    }
07687 
07688    ast_module_ref(ast_module_info->self);
07689    return tmp;
07690 }

static int dahdi_open ( char *  fn  )  [static]

Definition at line 2092 of file chan_dahdi.c.

References ast_log(), chan, errno, LOG_WARNING, and READ_SIZE.

Referenced by alloc_sub(), duplicate_pseudo(), and mkintf().

02093 {
02094    int fd;
02095    int isnum;
02096    int chan = 0;
02097    int bs;
02098    int x;
02099    isnum = 1;
02100    for (x = 0; x < strlen(fn); x++) {
02101       if (!isdigit(fn[x])) {
02102          isnum = 0;
02103          break;
02104       }
02105    }
02106    if (isnum) {
02107       chan = atoi(fn);
02108       if (chan < 1) {
02109          ast_log(LOG_WARNING, "Invalid channel number '%s'\n", fn);
02110          return -1;
02111       }
02112       fn = "/dev/dahdi/channel";
02113    }
02114    fd = open(fn, O_RDWR | O_NONBLOCK);
02115    if (fd < 0) {
02116       ast_log(LOG_WARNING, "Unable to open '%s': %s\n", fn, strerror(errno));
02117       return -1;
02118    }
02119    if (chan) {
02120       if (ioctl(fd, DAHDI_SPECIFY, &chan)) {
02121          x = errno;
02122          close(fd);
02123          errno = x;
02124          ast_log(LOG_WARNING, "Unable to specify channel %d: %s\n", chan, strerror(errno));
02125          return -1;
02126       }
02127    }
02128    bs = READ_SIZE;
02129    if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs) == -1) {
02130       ast_log(LOG_WARNING, "Unable to set blocksize '%d': %s\n", bs,  strerror(errno));
02131       x = errno;
02132       close(fd);
02133       errno = x;
02134       return -1;
02135    }
02136    return fd;
02137 }

static void dahdi_pri_error ( struct pri *  pri,
char *  s 
) [static]

Definition at line 12372 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), errno, LOG_ERROR, LOG_WARNING, NUM_DCHANS, NUM_SPANS, pridebugfdlock, and pris.

Referenced by dahdi_restart(), and load_module().

12373 {
12374    int x, y;
12375    int dchan = -1, span = -1;
12376    int dchancount = 0;
12377 
12378    if (pri) {
12379       for (x = 0; x < NUM_SPANS; x++) {
12380          for (y = 0; y < NUM_DCHANS; y++) {
12381             if (pris[x].dchans[y])
12382                dchancount++;
12383 
12384             if (pris[x].dchans[y] == pri)
12385                dchan = y;
12386          }
12387          if (dchan >= 0) {
12388             span = x;
12389             break;
12390          }
12391          dchancount = 0;
12392       }
12393       if ((dchancount > 1) && (span > -1))
12394          ast_log(LOG_ERROR, "[Span %d D-Channel %d] PRI: %s", span, dchan, s);
12395       else
12396          ast_log(LOG_ERROR, "%s", s);
12397    } else
12398       ast_log(LOG_ERROR, "%s", s);
12399 
12400    ast_mutex_lock(&pridebugfdlock);
12401 
12402    if (pridebugfd >= 0) {
12403       if (write(pridebugfd, s, strlen(s)) < 0) {
12404          ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
12405       }
12406    }
12407 
12408    ast_mutex_unlock(&pridebugfdlock);
12409 }

static void dahdi_pri_message ( struct pri *  pri,
char *  s 
) [static]

Definition at line 12331 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose, errno, LOG_WARNING, NUM_DCHANS, NUM_SPANS, pridebugfdlock, and pris.

Referenced by dahdi_restart(), and load_module().

12332 {
12333    int x, y;
12334    int dchan = -1, span = -1;
12335    int dchancount = 0;
12336 
12337    if (pri) {
12338       for (x = 0; x < NUM_SPANS; x++) {
12339          for (y = 0; y < NUM_DCHANS; y++) {
12340             if (pris[x].dchans[y])
12341                dchancount++;
12342 
12343             if (pris[x].dchans[y] == pri)
12344                dchan = y;
12345          }
12346          if (dchan >= 0) {
12347             span = x;
12348             break;
12349          }
12350          dchancount = 0;
12351       }
12352       if (dchancount > 1 && (span > -1))
12353          ast_verbose("[Span %d D-Channel %d]%s", span, dchan, s);
12354       else
12355          ast_verbose("%s", s);
12356    } else
12357       ast_verbose("%s", s);
12358 
12359    ast_mutex_lock(&pridebugfdlock);
12360 
12361    if (pridebugfd >= 0) {
12362       if (write(pridebugfd, s, strlen(s)) < 0) {
12363          ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
12364       }
12365    }
12366 
12367    ast_mutex_unlock(&pridebugfdlock);
12368 }

static void dahdi_queue_frame ( struct dahdi_pvt *  p,
struct ast_frame *  f,
void *  data 
) [static]

Definition at line 1546 of file chan_dahdi.c.

References ast_channel_trylock, ast_channel_unlock, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), DEADLOCK_AVOIDANCE, dahdi_pvt::lock, dahdi_ss7::lock, dahdi_pri::lock, dahdi_pvt::owner, dahdi_pri::pri, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_PRI, SIG_SS7, and dahdi_ss7::ss7.

Referenced by action_dahdidialoffhook(), pri_dchannel(), and ss7_linkset().

01547 {
01548 #ifdef HAVE_PRI
01549    struct dahdi_pri *pri = (struct dahdi_pri*) data;
01550 #endif
01551 #ifdef HAVE_SS7
01552    struct dahdi_ss7 *ss7 = (struct dahdi_ss7*) data;
01553 #endif
01554    /* We must unlock the PRI to avoid the possibility of a deadlock */
01555 #if defined(HAVE_PRI) || defined(HAVE_SS7)
01556    if (data) {
01557       switch (p->sig) {
01558 #ifdef HAVE_PRI
01559       case SIG_BRI:
01560       case SIG_BRI_PTMP:
01561       case SIG_PRI:
01562          ast_mutex_unlock(&pri->lock);
01563          break;
01564 #endif
01565 #ifdef HAVE_SS7
01566       case SIG_SS7:
01567          ast_mutex_unlock(&ss7->lock);
01568          break;
01569 #endif
01570       default:
01571          break;
01572       }
01573    }
01574 #endif
01575    for (;;) {
01576       if (p->owner) {
01577          if (ast_channel_trylock(p->owner)) {
01578             DEADLOCK_AVOIDANCE(&p->lock);
01579          } else {
01580             ast_queue_frame(p->owner, f);
01581             ast_channel_unlock(p->owner);
01582             break;
01583          }
01584       } else
01585          break;
01586    }
01587 #if defined(HAVE_PRI) || defined(HAVE_SS7)
01588    if (data) {
01589       switch (p->sig) {
01590 #ifdef HAVE_PRI
01591       case SIG_BRI:
01592       case SIG_BRI_PTMP:
01593       case SIG_PRI:
01594          ast_mutex_lock(&pri->lock);
01595          break;
01596 #endif
01597 #ifdef HAVE_SS7
01598       case SIG_SS7:
01599          ast_mutex_lock(&ss7->lock);
01600          break;
01601 #endif
01602       default:
01603          break;
01604       }
01605    }
01606 #endif
01607 }

static int16_t dahdi_r2_alaw_to_linear ( uint8_t  sample  )  [inline, static]

Definition at line 2045 of file chan_dahdi.c.

References AST_ALAW.

02046 {
02047    return AST_ALAW(sample);
02048 }

static int dahdi_r2_answer ( struct dahdi_pvt *  p  )  [static]

Definition at line 1612 of file chan_dahdi.c.

References ast_true(), dahdi_pvt::owner, pbx_builtin_getvar_helper(), and dahdi_pvt::r2chan.

Referenced by dahdi_answer(), and dahdi_r2_on_call_accepted().

01613 {
01614    int res = 0;
01615    /* openr2 1.1.0 and older does not even define OR2_LIB_INTERFACE
01616    * and does not has support for openr2_chan_answer_call_with_mode
01617    *  */
01618 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
01619    const char *double_answer = pbx_builtin_getvar_helper(p->owner, "MFCR2_DOUBLE_ANSWER");
01620    int wants_double_answer = ast_true(double_answer) ? 1 : 0;
01621    if (!double_answer) {
01622       /* this still can result in double answer if the channel context
01623       * was configured that way */
01624       res = openr2_chan_answer_call(p->r2chan);
01625    } else if (wants_double_answer) {
01626       res = openr2_chan_answer_call_with_mode(p->r2chan, OR2_ANSWER_DOUBLE);
01627    } else {
01628       res = openr2_chan_answer_call_with_mode(p->r2chan, OR2_ANSWER_SIMPLE);
01629    }
01630 #else
01631    res = openr2_chan_answer_call(p->r2chan);
01632 #endif
01633    return res;
01634 }

static int dahdi_r2_cause_to_ast_cause ( openr2_call_disconnect_cause_t  cause  )  [static]

Definition at line 1855 of file chan_dahdi.c.

References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_NO_ANSWER, AST_CAUSE_NORMAL_CLEARING, AST_CAUSE_NOTDEFINED, and AST_CAUSE_UNREGISTERED.

Referenced by dahdi_r2_on_call_disconnect().

01856 {
01857    switch (cause) {
01858    case OR2_CAUSE_BUSY_NUMBER:
01859       return AST_CAUSE_BUSY;
01860    case OR2_CAUSE_NETWORK_CONGESTION:
01861       return AST_CAUSE_CONGESTION;
01862    case OR2_CAUSE_OUT_OF_ORDER:
01863       return AST_CAUSE_DESTINATION_OUT_OF_ORDER;
01864    case OR2_CAUSE_UNALLOCATED_NUMBER:
01865       return AST_CAUSE_UNREGISTERED;
01866    case OR2_CAUSE_NO_ANSWER:
01867       return AST_CAUSE_NO_ANSWER;
01868    case OR2_CAUSE_NORMAL_CLEARING:
01869       return AST_CAUSE_NORMAL_CLEARING;
01870    case OR2_CAUSE_UNSPECIFIED:
01871    default:
01872       return AST_CAUSE_NOTDEFINED;
01873    }
01874 }

static void dahdi_r2_destroy_links ( void   )  [static]

Definition at line 9988 of file chan_dahdi.c.

References ast_free, and AST_PTHREADT_NULL.

Referenced by __unload_module(), and dahdi_restart().

09989 {
09990    int i = 0;
09991    if (!r2links) {
09992       return;
09993    }
09994    for (; i < r2links_count; i++) {
09995       if (r2links[i]->r2master != AST_PTHREADT_NULL) {
09996          pthread_cancel(r2links[i]->r2master);
09997          pthread_join(r2links[i]->r2master, NULL);
09998          openr2_context_delete(r2links[i]->protocol_context);
09999       }
10000       ast_free(r2links[i]);
10001    }
10002    ast_free(r2links);
10003    r2links = NULL;
10004    r2links_count = 0;
10005 }

static void dahdi_r2_disconnect_call ( struct dahdi_pvt *  p,
openr2_call_disconnect_cause_t  cause 
) [static]

Definition at line 1723 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, dahdi_pvt::lock, LOG_NOTICE, dahdi_pvt::mfcr2call, and dahdi_pvt::r2chan.

Referenced by dahdi_hangup(), dahdi_r2_on_call_accepted(), dahdi_r2_on_call_disconnect(), and dahdi_r2_on_call_offered().

01724 {
01725    if (openr2_chan_disconnect_call(p->r2chan, cause)) {
01726       ast_log(LOG_NOTICE, "Bad! failed to disconnect call on channel %d with reason %s, hope for the best!\n",
01727          p->channel, openr2_proto_get_disconnect_string(cause));
01728       /* force the chan to idle and release the call flag now since we will not see a clean on_call_end */
01729       openr2_chan_set_idle(p->r2chan);
01730       ast_mutex_lock(&p->lock);
01731       p->mfcr2call = 0;
01732       ast_mutex_unlock(&p->lock);
01733    }
01734 }

static openr2_calling_party_category_t dahdi_r2_get_channel_category ( struct ast_channel *  c  )  [static]

Definition at line 1639 of file chan_dahdi.c.

References ast_debug, ast_log(), ast_strlen_zero(), LOG_WARNING, dahdi_pvt::mfcr2_category, ast_channel::name, pbx_builtin_getvar_helper(), and ast_channel::tech_pvt.

Referenced by dahdi_call().

01640 {
01641    openr2_calling_party_category_t cat;
01642    const char *catstr = pbx_builtin_getvar_helper(c, "MFCR2_CATEGORY");
01643    struct dahdi_pvt *p = c->tech_pvt;
01644    if (ast_strlen_zero(catstr)) {
01645       ast_debug(1, "No MFC/R2 category specified for chan %s, using default %s\n",
01646             c->name, openr2_proto_get_category_string(p->mfcr2_category));
01647       return p->mfcr2_category;
01648    }
01649    if ((cat = openr2_proto_get_category(catstr)) == OR2_CALLING_PARTY_CATEGORY_UNKNOWN) {
01650       ast_log(LOG_WARNING, "Invalid category specified '%s' for chan %s, using default %s\n",
01651             catstr, c->name, openr2_proto_get_category_string(p->mfcr2_category));
01652       return p->mfcr2_category;
01653    }
01654    ast_debug(1, "Using category %s\n", catstr);
01655    return cat;
01656 }

static struct dahdi_mfcr2* dahdi_r2_get_link ( void   )  [static, read]

Definition at line 10008 of file chan_dahdi.c.

References ast_calloc, ast_free, ast_log(), AST_PTHREADT_NULL, ast_realloc, LOG_DEBUG, LOG_ERROR, dahdi_mfcr2::monitored_count, R2_LINK_CAPACITY, and dahdi_mfcr2::r2master.

Referenced by mkintf().

10009 {
10010    struct dahdi_mfcr2 *new_r2link = NULL;
10011    struct dahdi_mfcr2 **new_r2links = NULL;
10012    /* this function is called just when starting up and no monitor threads have been launched,
10013       no need to lock monitored_count member */
10014    if (!r2links_count || (r2links[r2links_count - 1]->monitored_count == R2_LINK_CAPACITY)) {
10015       new_r2link = ast_calloc(1, sizeof(**r2links));
10016       if (!new_r2link) {
10017          ast_log(LOG_ERROR, "Cannot allocate R2 link!\n");
10018          return NULL;
10019       }
10020       new_r2links = ast_realloc(r2links, ((r2links_count + 1) * sizeof(*r2links)));
10021       if (!new_r2links) {
10022          ast_log(LOG_ERROR, "Cannot allocate R2 link!\n");
10023          ast_free(new_r2link);
10024          return NULL;
10025       }
10026       r2links = new_r2links;
10027       new_r2link->r2master = AST_PTHREADT_NULL;
10028       r2links[r2links_count] = new_r2link;
10029       r2links_count++;
10030       ast_log(LOG_DEBUG, "Created new R2 link!\n");
10031    }
10032    return r2links[r2links_count - 1];
10033 }

static uint8_t dahdi_r2_linear_to_alaw ( int  sample  )  [inline, static]

Definition at line 2050 of file chan_dahdi.c.

References AST_LIN2A.

02051 {
02052    return AST_LIN2A(sample);
02053 }

static void dahdi_r2_on_ani_digit_received ( openr2_chan_t *  r2chan,
char  digit 
) [static]

Definition at line 2009 of file chan_dahdi.c.

References dahdi_pvt::cid_name, dahdi_pvt::cid_num, and dahdi_pvt::mfcr2_ani_index.

02010 {
02011    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
02012    p->cid_num[p->mfcr2_ani_index] = digit;
02013    p->cid_name[p->mfcr2_ani_index] = digit;
02014    p->mfcr2_ani_index++;
02015    p->cid_num[p->mfcr2_ani_index] = 0;
02016    p->cid_name[p->mfcr2_ani_index] = 0;
02017 }

static void dahdi_r2_on_billing_pulse_received ( openr2_chan_t *  r2chan  )  [static]

Definition at line 2019 of file chan_dahdi.c.

References ast_verbose.

02020 {
02021    ast_verbose("MFC/R2 billing pulse received on channel %d\n", openr2_chan_get_number(r2chan));
02022 }

static void dahdi_r2_on_call_accepted ( openr2_chan_t *  r2chan,
openr2_call_mode_t  mode 
) [static]

Definition at line 1801 of file chan_dahdi.c.

References ast_log(), AST_STATE_RING, ast_verbose, dahdi_pvt::channel, dahdi_enable_ec(), dahdi_new(), dahdi_r2_answer(), dahdi_r2_disconnect_call(), dahdi_pvt::dialing, LOG_DEBUG, LOG_WARNING, dahdi_pvt::mfcr2_accept_on_offer, dahdi_pvt::mfcr2_answer_pending, dahdi_pvt::mfcr2_call_accepted, dahdi_subchannel::needringing, SUB_REAL, and dahdi_pvt::subs.

01802 {
01803    struct dahdi_pvt *p = NULL;
01804    struct ast_channel *c = NULL;
01805    p = openr2_chan_get_client_data(r2chan);
01806    dahdi_enable_ec(p);
01807    p->mfcr2_call_accepted = 1;
01808    /* if it's an incoming call ... */
01809    if (OR2_DIR_BACKWARD == openr2_chan_get_direction(r2chan)) {
01810       ast_verbose("MFC/R2 call has been accepted on backward channel %d\n", openr2_chan_get_number(r2chan));
01811       /* If accept on offer is not set, it means at this point the PBX thread is already
01812          launched (was launched in the 'on call offered' handler) and therefore this callback
01813          is being executed already in the PBX thread rather than the monitor thread, don't launch
01814          any other thread, just disable the openr2 reading and answer the call if needed */
01815       if (!p->mfcr2_accept_on_offer) {
01816          openr2_chan_disable_read(r2chan);
01817          if (p->mfcr2_answer_pending) {
01818             ast_log(LOG_DEBUG, "Answering MFC/R2 call after accepting it on chan %d\n", openr2_chan_get_number(r2chan));
01819             dahdi_r2_answer(p);
01820          }
01821          return;
01822       }
01823       c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, DAHDI_LAW_ALAW, 0);
01824       if (c) {
01825          /* chan_dahdi will take care of reading from now on in the PBX thread, tell the
01826             library to forget about it */
01827          openr2_chan_disable_read(r2chan);
01828          return;
01829       }
01830       ast_log(LOG_WARNING, "Unable to create PBX channel in DAHDI channel %d\n", p->channel);
01831       /* failed to create the channel, bail out and report it as an out of order line */
01832       dahdi_r2_disconnect_call(p, OR2_CAUSE_OUT_OF_ORDER);
01833       return;
01834    }
01835    /* this is an outgoing call, no need to launch the PBX thread, most likely we're in one already */
01836    ast_verbose("MFC/R2 call has been accepted on forward channel %d\n", p->channel);
01837    p->subs[SUB_REAL].needringing = 1;
01838    p->dialing = 0;
01839    /* chan_dahdi will take care of reading from now on in the PBX thread, tell the library to forget about it */
01840    openr2_chan_disable_read(r2chan);
01841 }

static void dahdi_r2_on_call_answered ( openr2_chan_t *  r2chan  )  [static]

Definition at line 1843 of file chan_dahdi.c.

References ast_verbose, dahdi_subchannel::needanswer, SUB_REAL, and dahdi_pvt::subs.

01844 {
01845    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01846    ast_verbose("MFC/R2 call has been answered on channel %d\n", openr2_chan_get_number(r2chan));
01847    p->subs[SUB_REAL].needanswer = 1;
01848 }

static void dahdi_r2_on_call_disconnect ( openr2_chan_t *  r2chan,
openr2_call_disconnect_cause_t  cause 
) [static]

Definition at line 1876 of file chan_dahdi.c.

References ast_channel::_softhangup, ast_channel::_state, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_hangup_with_cause(), AST_SOFTHANGUP_DEV, AST_STATE_UP, ast_verbose, dahdi_r2_cause_to_ast_cause(), dahdi_r2_disconnect_call(), dahdi_pvt::lock, dahdi_subchannel::needbusy, dahdi_subchannel::needcongestion, dahdi_pvt::owner, SUB_REAL, and dahdi_pvt::subs.

01877 {
01878    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01879    ast_verbose("MFC/R2 call disconnected on channel %d\n", openr2_chan_get_number(r2chan));
01880    ast_mutex_lock(&p->lock);
01881    if (!p->owner) {
01882       ast_mutex_unlock(&p->lock);
01883       /* no owner, therefore we can't use dahdi_hangup to disconnect, do it right now */
01884       dahdi_r2_disconnect_call(p, OR2_CAUSE_NORMAL_CLEARING);
01885       return;
01886    }
01887    /* when we have an owner we don't call dahdi_r2_disconnect_call here, that will
01888       be done in dahdi_hangup */
01889    if (p->owner->_state == AST_STATE_UP) {
01890       p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
01891       ast_mutex_unlock(&p->lock);
01892    } else if (openr2_chan_get_direction(r2chan) == OR2_DIR_FORWARD) {
01893       /* being the forward side we must report what happened to the call to whoever requested it */
01894       switch (cause) {
01895       case OR2_CAUSE_BUSY_NUMBER:
01896          p->subs[SUB_REAL].needbusy = 1;
01897          break;
01898       case OR2_CAUSE_NETWORK_CONGESTION:
01899       case OR2_CAUSE_OUT_OF_ORDER:
01900       case OR2_CAUSE_UNALLOCATED_NUMBER:
01901       case OR2_CAUSE_NO_ANSWER:
01902       case OR2_CAUSE_UNSPECIFIED:
01903       case OR2_CAUSE_NORMAL_CLEARING:
01904          p->subs[SUB_REAL].needcongestion = 1;
01905          break;
01906       default:
01907          p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
01908       }
01909       ast_mutex_unlock(&p->lock);
01910    } else {
01911       ast_mutex_unlock(&p->lock);
01912       /* being the backward side and not UP yet, we only need to request hangup */
01913       /* TODO: what about doing this same thing when were AST_STATE_UP? */
01914       ast_queue_hangup_with_cause(p->owner, dahdi_r2_cause_to_ast_cause(cause));
01915    }
01916 }

static void dahdi_r2_on_call_end ( openr2_chan_t *  r2chan  )  [static]

Definition at line 1791 of file chan_dahdi.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose, dahdi_pvt::channel, dahdi_pvt::lock, and dahdi_pvt::mfcr2call.

01792 {
01793    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01794    ast_verbose("MFC/R2 call end on channel %d\n", p->channel);
01795    ast_mutex_lock(&p->lock);
01796    p->mfcr2call = 0;
01797    ast_mutex_unlock(&p->lock);
01798 }

static void dahdi_r2_on_call_init ( openr2_chan_t *  r2chan  )  [static]

Definition at line 1658 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::exten, dahdi_pvt::lock, LOG_ERROR, dahdi_pvt::mfcr2_ani_index, dahdi_pvt::mfcr2_answer_pending, dahdi_pvt::mfcr2_call_accepted, dahdi_pvt::mfcr2_dnis_index, dahdi_pvt::mfcr2_dnis_matched, dahdi_pvt::mfcr2call, and dahdi_pvt::rdnis.

01659 {
01660    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01661    ast_mutex_lock(&p->lock);
01662    if (p->mfcr2call) {
01663       ast_mutex_unlock(&p->lock);
01664       /* TODO: This can happen when some other thread just finished dahdi_request requesting this very same
01665          interface but has not yet seized the line (dahdi_call), and the far end wins and seize the line,
01666          can we avoid this somehow?, at this point when dahdi_call send the seize, it is likely that since
01667          the other end will see our seize as a forced release and drop the call, we will see an invalid
01668          pattern that will be seen and treated as protocol error. */
01669       ast_log(LOG_ERROR, "Collision of calls on chan %d detected!.\n", openr2_chan_get_number(r2chan));
01670       return;
01671    }
01672    p->mfcr2call = 1;
01673    /* better safe than sorry ... */
01674    p->cid_name[0] = '\0';
01675    p->cid_num[0] = '\0';
01676    p->rdnis[0] = '\0';
01677    p->exten[0] = '\0';
01678    p->mfcr2_ani_index = '\0';
01679    p->mfcr2_dnis_index = '\0';
01680    p->mfcr2_dnis_matched = 0;
01681    p->mfcr2_answer_pending = 0;
01682    p->mfcr2_call_accepted = 0;
01683    ast_mutex_unlock(&p->lock);
01684    ast_verbose("New MFC/R2 call detected on chan %d.\n", openr2_chan_get_number(r2chan));
01685 }

static void dahdi_r2_on_call_offered ( openr2_chan_t *  r2chan,
const char *  ani,
const char *  dnis,
openr2_calling_party_category_t  category 
) [static]

Definition at line 1736 of file chan_dahdi.c.

References ast_exists_extension(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_RING, ast_verbose, dahdi_pvt::channel, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::context, dahdi_new(), dahdi_r2_disconnect_call(), dahdi_pvt::exten, dahdi_pvt::immediate, dahdi_pvt::lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, dahdi_pvt::mfcr2_accept_on_offer, dahdi_pvt::mfcr2_allow_collect_calls, dahdi_pvt::mfcr2_charge_calls, dahdi_pvt::mfcr2_recvd_category, SUB_REAL, and dahdi_pvt::use_callerid.

01737 {
01738    struct dahdi_pvt *p;
01739    struct ast_channel *c;
01740    ast_verbose("MFC/R2 call offered on chan %d. ANI = %s, DNIS = %s, Category = %s\n",
01741          openr2_chan_get_number(r2chan), ani ? ani : "(restricted)", dnis,
01742          openr2_proto_get_category_string(category));
01743    p = openr2_chan_get_client_data(r2chan);
01744    /* if collect calls are not allowed and this is a collect call, reject it! */
01745    if (!p->mfcr2_allow_collect_calls && category == OR2_CALLING_PARTY_CATEGORY_COLLECT_CALL) {
01746       ast_log(LOG_NOTICE, "Rejecting MFC/R2 collect call\n");
01747       dahdi_r2_disconnect_call(p, OR2_CAUSE_COLLECT_CALL_REJECTED);
01748       return;
01749    }
01750    ast_mutex_lock(&p->lock);
01751    p->mfcr2_recvd_category = category;
01752    /* if we're not supposed to use CID, clear whatever we have */
01753    if (!p->use_callerid) {
01754       ast_log(LOG_DEBUG, "No CID allowed in configuration, CID is being cleared!\n");
01755       p->cid_num[0] = 0;
01756       p->cid_name[0] = 0;
01757    }
01758    /* if we're supposed to answer immediately, clear DNIS and set 's' exten */
01759    if (p->immediate || !openr2_context_get_max_dnis(openr2_chan_get_context(r2chan))) {
01760       ast_log(LOG_DEBUG, "Setting exten => s because of immediate or 0 DNIS configured\n");
01761       p->exten[0] = 's';
01762       p->exten[1] = 0;
01763    }
01764    ast_mutex_unlock(&p->lock);
01765    if (!ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num)) {
01766       ast_log(LOG_NOTICE, "MFC/R2 call on channel %d requested non-existent extension '%s' in context '%s'. Rejecting call.\n",
01767             p->channel, p->exten, p->context);
01768       dahdi_r2_disconnect_call(p, OR2_CAUSE_UNALLOCATED_NUMBER);
01769       return;
01770    }
01771    if (!p->mfcr2_accept_on_offer) {
01772       /* The user wants us to start the PBX thread right away without accepting the call first */
01773       c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, DAHDI_LAW_ALAW, 0);
01774       if (c) {
01775          /* Done here, don't disable reading now since we still need to generate MF tones to accept
01776             the call or reject it and detect the tone off condition of the other end, all of this
01777             will be done in the PBX thread now */
01778          return;
01779       }
01780       ast_log(LOG_WARNING, "Unable to create PBX channel in DAHDI channel %d\n", p->channel);
01781       dahdi_r2_disconnect_call(p, OR2_CAUSE_OUT_OF_ORDER);
01782    } else if (p->mfcr2_charge_calls) {
01783       ast_log(LOG_DEBUG, "Accepting MFC/R2 call with charge on chan %d\n", p->channel);
01784       openr2_chan_accept_call(r2chan, OR2_CALL_WITH_CHARGE);
01785    } else {
01786       ast_log(LOG_DEBUG, "Accepting MFC/R2 call with no charge on chan %d\n", p->channel);
01787       openr2_chan_accept_call(r2chan, OR2_CALL_NO_CHARGE);
01788    }
01789 }

static void dahdi_r2_on_call_read ( openr2_chan_t *  r2chan,
const unsigned char *  buf,
int  buflen 
) [static]

Definition at line 1850 of file chan_dahdi.c.

01851 {
01852    /*ast_log(LOG_DEBUG, "Read data from dahdi channel %d\n", openr2_chan_get_number(r2chan));*/
01853 }

static void dahdi_r2_on_chan_log ( openr2_chan_t *  r2chan,
openr2_log_level_t  level,
const char *  fmt,
va_list  ap 
) [static]

Definition at line 1977 of file chan_dahdi.c.

References CHAN_TAG, and dahdi_r2_write_log().

Referenced by mkintf().

01978 {
01979 #define CHAN_TAG "Chan "
01980    char logmsg[256];
01981    char completemsg[sizeof(logmsg) + sizeof(CHAN_TAG) - 1];
01982    vsnprintf(logmsg, sizeof(logmsg), fmt, ap);
01983    snprintf(completemsg, sizeof(completemsg), CHAN_TAG "%d - %s", openr2_chan_get_number(r2chan), logmsg);
01984    dahdi_r2_write_log(level, completemsg);
01985 }

static void dahdi_r2_on_context_log ( openr2_context_t *  r2context,
openr2_log_level_t  level,
const char *  fmt,
va_list  ap 
) [static]

Definition at line 1964 of file chan_dahdi.c.

References CONTEXT_TAG, and dahdi_r2_write_log().

01965 {
01966 #define CONTEXT_TAG "Context - "
01967    char logmsg[256];
01968    char completemsg[sizeof(logmsg) + sizeof(CONTEXT_TAG) - 1];
01969    vsnprintf(logmsg, sizeof(logmsg), fmt, ap);
01970    snprintf(completemsg, sizeof(completemsg), CONTEXT_TAG "%s", logmsg);
01971    dahdi_r2_write_log(level, completemsg);
01972 #undef CONTEXT_TAG
01973 }

static int dahdi_r2_on_dnis_digit_received ( openr2_chan_t *  r2chan,
char  digit 
) [static]

Definition at line 1987 of file chan_dahdi.c.

References ast_exists_extension(), ast_matchmore_extension(), dahdi_pvt::cid_num, dahdi_pvt::context, dahdi_pvt::exten, dahdi_pvt::immediate, dahdi_pvt::mfcr2_dnis_index, dahdi_pvt::mfcr2_dnis_matched, and dahdi_pvt::rdnis.

01988 {
01989    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01990    /* if 'immediate' is set, let's stop requesting DNIS */
01991    if (p->immediate) {
01992       return 0;
01993    }
01994    p->exten[p->mfcr2_dnis_index] = digit;
01995    p->rdnis[p->mfcr2_dnis_index] = digit;
01996    p->mfcr2_dnis_index++;
01997    p->exten[p->mfcr2_dnis_index] = 0;
01998    p->rdnis[p->mfcr2_dnis_index] = 0;
01999    /* if the DNIS is a match and cannot match more, stop requesting DNIS */
02000    if ((p->mfcr2_dnis_matched ||
02001        (ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num) && (p->mfcr2_dnis_matched = 1))) &&
02002        !ast_matchmore_extension(NULL, p->context, p->exten, 1, p->cid_num)) {
02003       return 0;
02004    }
02005    /* otherwise keep going */
02006    return 1;
02007 }

static void dahdi_r2_on_hardware_alarm ( openr2_chan_t *  r2chan,
int  alarm 
) [static]

Definition at line 1689 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, EVENT_FLAG_SYSTEM, get_alarms(), handle_alarms(), dahdi_pvt::inalarm, dahdi_pvt::lock, LOG_NOTICE, and manager_event.

01690 {
01691    int res;
01692    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01693    ast_mutex_lock(&p->lock);
01694    p->inalarm = alarm ? 1 : 0;
01695    if (p->inalarm) {
01696       res = get_alarms(p);
01697       handle_alarms(p, res);
01698    } else {
01699       ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", p->channel);
01700       manager_event(EVENT_FLAG_SYSTEM, "AlarmClear", "Channel: %d\r\n", p->channel);
01701    }
01702    ast_mutex_unlock(&p->lock);
01703 }

static void dahdi_r2_on_line_blocked ( openr2_chan_t *  r2chan  )  [static]

Definition at line 1944 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::lock, LOG_NOTICE, and dahdi_pvt::remotelyblocked.

01945 {
01946    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01947    ast_mutex_lock(&p->lock);
01948    p->remotelyblocked = 1;
01949    ast_mutex_unlock(&p->lock);
01950    ast_log(LOG_NOTICE, "Far end blocked on chan %d\n", openr2_chan_get_number(r2chan));
01951 }

static void dahdi_r2_on_line_idle ( openr2_chan_t *  r2chan  )  [static]

Definition at line 1953 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::lock, LOG_NOTICE, and dahdi_pvt::remotelyblocked.

01954 {
01955    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01956    ast_mutex_lock(&p->lock);
01957    p->remotelyblocked = 0;
01958    ast_mutex_unlock(&p->lock);
01959    ast_log(LOG_NOTICE, "Far end unblocked on chan %d\n", openr2_chan_get_number(r2chan));
01960 }

static void dahdi_r2_on_os_error ( openr2_chan_t *  r2chan,
int  errorcode 
) [static]

Definition at line 1705 of file chan_dahdi.c.

References ast_log(), and LOG_ERROR.

01706 {
01707    ast_log(LOG_ERROR, "OS error on chan %d: %s\n", openr2_chan_get_number(r2chan), strerror(errorcode));
01708 }

static void dahdi_r2_on_protocol_error ( openr2_chan_t *  r2chan,
openr2_protocol_error_t  reason 
) [static]

Definition at line 1710 of file chan_dahdi.c.

References ast_channel::_softhangup, AST_CAUSE_PROTOCOL_ERROR, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_SOFTHANGUP_DEV, ast_channel::hangupcause, dahdi_pvt::lock, LOG_ERROR, dahdi_pvt::mfcr2call, and dahdi_pvt::owner.

01711 {
01712    struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
01713    ast_log(LOG_ERROR, "MFC/R2 protocol error on chan %d: %s\n", openr2_chan_get_number(r2chan), openr2_proto_get_error(reason));
01714    if (p->owner) {
01715       p->owner->hangupcause = AST_CAUSE_PROTOCOL_ERROR;
01716       p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
01717    }
01718    ast_mutex_lock(&p->lock);
01719    p->mfcr2call = 0;
01720    ast_mutex_unlock(&p->lock);
01721 }

static int dahdi_r2_set_context ( struct dahdi_mfcr2 *  r2_link,
const struct dahdi_chan_conf *  conf 
) [static]

Definition at line 10035 of file chan_dahdi.c.

References ast_config_AST_LOG_DIR, ast_log(), ast_strlen_zero(), dahdi_mfcr2_conf::double_answer, dahdi_mfcr2_conf::get_ani_first, dahdi_mfcr2_conf::immediate_accept, LOG_ERROR, dahdi_mfcr2_conf::logdir, dahdi_mfcr2_conf::loglevel, dahdi_mfcr2_conf::max_ani, dahdi_mfcr2_conf::max_dnis, dahdi_mfcr2_conf::metering_pulse_timeout, dahdi_mfcr2_conf::mfback_timeout, dahdi_chan_conf::mfcr2, dahdi_mfcr2::monitored_count, dahdi_mfcr2::protocol_context, dahdi_mfcr2_conf::r2proto_file, and dahdi_mfcr2_conf::variant.

Referenced by mkintf().

10036 {
10037    char tmplogdir[] = "/tmp";
10038    char logdir[OR2_MAX_PATH];
10039    int threshold = 0;
10040    int snres = 0;
10041    r2_link->protocol_context = openr2_context_new(NULL, &dahdi_r2_event_iface,
10042          &dahdi_r2_transcode_iface, conf->mfcr2.variant, conf->mfcr2.max_ani,
10043          conf->mfcr2.max_dnis);
10044    if (!r2_link->protocol_context) {
10045       return -1;
10046    }
10047    openr2_context_set_log_level(r2_link->protocol_context, conf->mfcr2.loglevel);
10048    openr2_context_set_ani_first(r2_link->protocol_context, conf->mfcr2.get_ani_first);
10049 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
10050    openr2_context_set_skip_category_request(r2_link->protocol_context, conf->mfcr2.skip_category_request);
10051 #endif
10052    openr2_context_set_mf_threshold(r2_link->protocol_context, threshold);
10053    openr2_context_set_mf_back_timeout(r2_link->protocol_context, conf->mfcr2.mfback_timeout);
10054    openr2_context_set_metering_pulse_timeout(r2_link->protocol_context, conf->mfcr2.metering_pulse_timeout);
10055    openr2_context_set_double_answer(r2_link->protocol_context, conf->mfcr2.double_answer);
10056    openr2_context_set_immediate_accept(r2_link->protocol_context, conf->mfcr2.immediate_accept);
10057    if (ast_strlen_zero(conf->mfcr2.logdir)) {
10058       if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) {
10059          ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir);
10060       }
10061    } else {
10062       snres = snprintf(logdir, sizeof(logdir), "%s/%s/%s", ast_config_AST_LOG_DIR, "mfcr2", conf->mfcr2.logdir);
10063       if (snres >= sizeof(logdir)) {
10064          ast_log(LOG_ERROR, "MFC/R2 logging directory truncated, using %s\n", tmplogdir);
10065          if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) {
10066             ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir);
10067          }
10068       } else {
10069          if (openr2_context_set_log_directory(r2_link->protocol_context, logdir)) {
10070             ast_log(LOG_ERROR, "Failed setting MFC/R2 log directory %s\n", logdir);
10071          }
10072       }
10073    }
10074    if (!ast_strlen_zero(conf->mfcr2.r2proto_file)) {
10075       if (openr2_context_configure_from_advanced_file(r2_link->protocol_context, conf->mfcr2.r2proto_file)) {
10076          ast_log(LOG_ERROR, "Failed to configure r2context from advanced configuration file %s\n", conf->mfcr2.r2proto_file);
10077       }
10078    }
10079    r2_link->monitored_count = 0;
10080    return 0;
10081 }

static void dahdi_r2_write_log ( openr2_log_level_t  level,
char *  logmessage 
) [static]

Definition at line 1918 of file chan_dahdi.c.

References ast_log(), ast_verbose, LOG_DEBUG, LOG_ERROR, and LOG_WARNING.

Referenced by dahdi_r2_on_chan_log(), and dahdi_r2_on_context_log().

01919 {
01920    switch (level) {
01921    case OR2_LOG_NOTICE:
01922       ast_verbose("%s", logmessage);
01923       break;
01924    case OR2_LOG_WARNING:
01925       ast_log(LOG_WARNING, "%s", logmessage);
01926       break;
01927    case OR2_LOG_ERROR:
01928       ast_log(LOG_ERROR, "%s", logmessage);
01929       break;
01930    case OR2_LOG_STACK_TRACE:
01931    case OR2_LOG_MF_TRACE:
01932    case OR2_LOG_CAS_TRACE:
01933    case OR2_LOG_DEBUG:
01934    case OR2_LOG_EX_DEBUG:
01935       ast_log(LOG_DEBUG, "%s", logmessage);
01936       break;
01937    default:
01938       ast_log(LOG_WARNING, "We should handle logging level %d here.\n", level);
01939       ast_log(LOG_DEBUG, "%s", logmessage);
01940       break;
01941    }
01942 }

static struct ast_frame * dahdi_read ( struct ast_channel *  ast  )  [static, read]

Definition at line 6794 of file chan_dahdi.c.

References __dahdi_exception(), ast_channel::_state, ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HOLD, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_debug, ast_dsp_get_tcount(), ast_dsp_get_tstate(), ast_dsp_process(), ast_dsp_set_features(), ast_dsp_was_muted(), AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_getformatname(), ast_log(), ast_mutex_trylock(), ast_mutex_unlock(), ast_null_frame, ast_set_callerid(), ast_set_flag, ast_setstate(), AST_STATE_DIALING, AST_STATE_RINGING, AST_STATE_UP, ast_strlen_zero(), ast_tv(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, dahdi_subchannel::buffer, dahdi_pvt::busydetect, dahdi_pvt::callprogress, dahdi_pvt::callwaitcas, dahdi_pvt::callwaitingrepeat, dahdi_pvt::callwaitrings, dahdi_pvt::channel, CHANNEL_DEADLOCK_AVOIDANCE, CHECK_BLOCKING, dahdi_pvt::cidcwexpire, dahdi_pvt::cidrings, dahdi_pvt::cidspill, dahdi_callwait(), dahdi_confmute(), dahdi_get_index(), dahdi_handle_dtmfup(), DAHDI_OVERLAPDIAL_INCOMING, DAHDI_OVERLAPDIAL_OUTGOING, dahdi_setlinear(), ast_frame::data, ast_frame::datalen, ast_frame::delivery, dahdi_subchannel::dfd, dahdi_pvt::dialing, dahdi_pvt::dop, dahdi_pvt::dsp, DSP_FEATURE_WAITDIALTONE, dahdi_pvt::dsp_features, DSP_TONE_STATE_DIALTONE, DSP_TONE_STATE_RINGING, errno, dahdi_subchannel::f, f, dahdi_pvt::fake_event, dahdi_pvt::firstradio, ast_frame::frametype, dahdi_pvt::ignoredtmf, dahdi_pvt::inalarm, dahdi_subchannel::inthreeway, dahdi_pvt::lastcid_name, dahdi_pvt::lastcid_num, dahdi_subchannel::linear, dahdi_pvt::lock, LOG_DEBUG, LOG_WARNING, ast_frame::mallocd, dahdi_pvt::mfcr2, dahdi_pvt::muting, ast_channel::name, dahdi_subchannel::needanswer, dahdi_subchannel::needbusy, dahdi_subchannel::needcallerid, dahdi_subchannel::needcongestion, dahdi_subchannel::needflash, dahdi_subchannel::needhold, dahdi_subchannel::needringing, dahdi_subchannel::needunhold, ast_frame::offset, dahdi_pvt::oprmode, dahdi_pvt::outgoing, dahdi_pri::overlapdial, dahdi_pvt::owner, dahdi_pvt::pri, dahdi_pvt::proceeding, ast_frame::ptr, dahdi_pvt::pulsedial, dahdi_pvt::r2chan, dahdi_pvt::radio, ast_channel::rawreadformat, READ_SIZE, restore_conference(), ast_channel::rings, dahdi_pvt::ringt, S_OR, ast_frame::samples, send_callerid(), dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_PRI, ast_frame::src, SUB_CALLWAIT, SUB_REAL, ast_frame::subclass, dahdi_pvt::subs, dahdi_pvt::tdd, tdd_feed(), ast_channel::tech_pvt, dahdi_pvt::waitfordialtone, and dahdi_pvt::waitingfordt.

06795 {
06796    struct dahdi_pvt *p = ast->tech_pvt;
06797    int res;
06798    int idx;
06799    void *readbuf;
06800    struct ast_frame *f;
06801 
06802    while (ast_mutex_trylock(&p->lock)) {
06803       CHANNEL_DEADLOCK_AVOIDANCE(ast);
06804    }
06805 
06806    idx = dahdi_get_index(ast, p, 0);
06807 
06808    /* Hang up if we don't really exist */
06809    if (idx < 0)   {
06810       ast_log(LOG_WARNING, "We don't exist?\n");
06811       ast_mutex_unlock(&p->lock);
06812       return NULL;
06813    }
06814 
06815    if ((p->radio || (p->oprmode < 0)) && p->inalarm) {
06816       ast_mutex_unlock(&p->lock);
06817       return NULL;
06818    }
06819 
06820    p->subs[idx].f.frametype = AST_FRAME_NULL;
06821    p->subs[idx].f.datalen = 0;
06822    p->subs[idx].f.samples = 0;
06823    p->subs[idx].f.mallocd = 0;
06824    p->subs[idx].f.offset = 0;
06825    p->subs[idx].f.subclass = 0;
06826    p->subs[idx].f.delivery = ast_tv(0,0);
06827    p->subs[idx].f.src = "dahdi_read";
06828    p->subs[idx].f.data.ptr = NULL;
06829 
06830    /* make sure it sends initial key state as first frame */
06831    if ((p->radio || (p->oprmode < 0)) && (!p->firstradio))
06832    {
06833       struct dahdi_params ps;
06834 
06835       memset(&ps, 0, sizeof(ps));
06836       ps.channo = p->channel;
06837       if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) {
06838          ast_mutex_unlock(&p->lock);
06839          return NULL;
06840       }
06841       p->firstradio = 1;
06842       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06843       if (ps.rxisoffhook)
06844       {
06845          p->subs[idx].f.subclass = AST_CONTROL_RADIO_KEY;
06846       }
06847       else
06848       {
06849          p->subs[idx].f.subclass = AST_CONTROL_RADIO_UNKEY;
06850       }
06851       ast_mutex_unlock(&p->lock);
06852       return &p->subs[idx].f;
06853    }
06854    if (p->ringt == 1) {
06855       ast_mutex_unlock(&p->lock);
06856       return NULL;
06857    }
06858    else if (p->ringt > 0)
06859       p->ringt--;
06860 
06861 #ifdef HAVE_OPENR2
06862    if (p->mfcr2) {
06863       openr2_chan_process_event(p->r2chan);
06864    }
06865 #endif
06866 
06867    if (p->subs[idx].needringing) {
06868       /* Send ringing frame if requested */
06869       p->subs[idx].needringing = 0;
06870       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06871       p->subs[idx].f.subclass = AST_CONTROL_RINGING;
06872       ast_setstate(ast, AST_STATE_RINGING);
06873       ast_mutex_unlock(&p->lock);
06874       return &p->subs[idx].f;
06875    }
06876 
06877    if (p->subs[idx].needbusy) {
06878       /* Send busy frame if requested */
06879       p->subs[idx].needbusy = 0;
06880       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06881       p->subs[idx].f.subclass = AST_CONTROL_BUSY;
06882       ast_mutex_unlock(&p->lock);
06883       return &p->subs[idx].f;
06884    }
06885 
06886    if (p->subs[idx].needcongestion) {
06887       /* Send congestion frame if requested */
06888       p->subs[idx].needcongestion = 0;
06889       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06890       p->subs[idx].f.subclass = AST_CONTROL_CONGESTION;
06891       ast_mutex_unlock(&p->lock);
06892       return &p->subs[idx].f;
06893    }
06894 
06895    if (p->subs[idx].needcallerid) {
06896       ast_set_callerid(ast, S_OR(p->lastcid_num, NULL),
06897                      S_OR(p->lastcid_name, NULL),
06898                      S_OR(p->lastcid_num, NULL)
06899                      );
06900       p->subs[idx].needcallerid = 0;
06901    }
06902 
06903    if (p->subs[idx].needanswer) {
06904       /* Send answer frame if requested */
06905       p->subs[idx].needanswer = 0;
06906       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06907       p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
06908       ast_mutex_unlock(&p->lock);
06909       return &p->subs[idx].f;
06910    }
06911 #ifdef HAVE_OPENR2
06912    if (p->mfcr2 && openr2_chan_get_read_enabled(p->r2chan)) {
06913       /* openr2 took care of reading and handling any event
06914         (needanswer, needbusy etc), if we continue we will read()
06915         twice, lets just return a null frame. This should only
06916         happen when openr2 is dialing out */
06917       ast_mutex_unlock(&p->lock);
06918       return &ast_null_frame;
06919    }
06920 #endif
06921 
06922    if (p->subs[idx].needflash) {
06923       /* Send answer frame if requested */
06924       p->subs[idx].needflash = 0;
06925       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06926       p->subs[idx].f.subclass = AST_CONTROL_FLASH;
06927       ast_mutex_unlock(&p->lock);
06928       return &p->subs[idx].f;
06929    }
06930 
06931    if (p->subs[idx].needhold) {
06932       /* Send answer frame if requested */
06933       p->subs[idx].needhold = 0;
06934       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06935       p->subs[idx].f.subclass = AST_CONTROL_HOLD;
06936       ast_mutex_unlock(&p->lock);
06937       ast_debug(1, "Sending hold on '%s'\n", ast->name);
06938       return &p->subs[idx].f;
06939    }
06940 
06941    if (p->subs[idx].needunhold) {
06942       /* Send answer frame if requested */
06943       p->subs[idx].needunhold = 0;
06944       p->subs[idx].f.frametype = AST_FRAME_CONTROL;
06945       p->subs[idx].f.subclass = AST_CONTROL_UNHOLD;
06946       ast_mutex_unlock(&p->lock);
06947       ast_debug(1, "Sending unhold on '%s'\n", ast->name);
06948       return &p->subs[idx].f;
06949    }
06950 
06951    if (ast->rawreadformat == AST_FORMAT_SLINEAR) {
06952       if (!p->subs[idx].linear) {
06953          p->subs[idx].linear = 1;
06954          res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
06955          if (res)
06956             ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to linear mode.\n", p->channel, idx);
06957       }
06958    } else if ((ast->rawreadformat == AST_FORMAT_ULAW) ||
06959       (ast->rawreadformat == AST_FORMAT_ALAW)) {
06960       if (p->subs[idx].linear) {
06961          p->subs[idx].linear = 0;
06962          res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
06963          if (res)
06964             ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to companded mode.\n", p->channel, idx);
06965       }
06966    } else {
06967       ast_log(LOG_WARNING, "Don't know how to read frames in format %s\n", ast_getformatname(ast->rawreadformat));
06968       ast_mutex_unlock(&p->lock);
06969       return NULL;
06970    }
06971    readbuf = ((unsigned char *)p->subs[idx].buffer) + AST_FRIENDLY_OFFSET;
06972    CHECK_BLOCKING(ast);
06973    res = read(p->subs[idx].dfd, readbuf, p->subs[idx].linear ? READ_SIZE * 2 : READ_SIZE);
06974    ast_clear_flag(ast, AST_FLAG_BLOCKING);
06975    /* Check for hangup */
06976    if (res < 0) {
06977       f = NULL;
06978       if (res == -1) {
06979          if (errno == EAGAIN) {
06980             /* Return "NULL" frame if there is nobody there */
06981             ast_mutex_unlock(&p->lock);
06982             return &p->subs[idx].f;
06983          } else if (errno == ELAST) {
06984             f = __dahdi_exception(ast);
06985          } else
06986             ast_log(LOG_WARNING, "dahdi_rec: %s\n", strerror(errno));
06987       }
06988       ast_mutex_unlock(&p->lock);
06989       return f;
06990    }
06991    if (res != (p->subs[idx].linear ? READ_SIZE * 2 : READ_SIZE)) {
06992       ast_debug(1, "Short read (%d/%d), must be an event...\n", res, p->subs[idx].linear ? READ_SIZE * 2 : READ_SIZE);
06993       f = __dahdi_exception(ast);
06994       ast_mutex_unlock(&p->lock);
06995       return f;
06996    }
06997    if (p->tdd) { /* if in TDD mode, see if we receive that */
06998       int c;
06999 
07000       c = tdd_feed(p->tdd,readbuf,READ_SIZE);
07001       if (c < 0) {
07002          ast_debug(1,"tdd_feed failed\n");
07003          ast_mutex_unlock(&p->lock);
07004          return NULL;
07005       }
07006       if (c) { /* if a char to return */
07007          p->subs[idx].f.subclass = 0;
07008          p->subs[idx].f.frametype = AST_FRAME_TEXT;
07009          p->subs[idx].f.mallocd = 0;
07010          p->subs[idx].f.offset = AST_FRIENDLY_OFFSET;
07011          p->subs[idx].f.data.ptr = p->subs[idx].buffer + AST_FRIENDLY_OFFSET;
07012          p->subs[idx].f.datalen = 1;
07013          *((char *) p->subs[idx].f.data.ptr) = c;
07014          ast_mutex_unlock(&p->lock);
07015          return &p->subs[idx].f;
07016       }
07017    }
07018    /* Ensure the CW timer decrements only on a single subchannel */
07019    if (p->callwaitingrepeat && dahdi_get_index(ast, p, 1) == SUB_REAL) {
07020       p->callwaitingrepeat--;
07021    }
07022    if (p->cidcwexpire)
07023       p->cidcwexpire--;
07024    /* Repeat callwaiting */
07025    if (p->callwaitingrepeat == 1) {
07026       p->callwaitrings++;
07027       dahdi_callwait(ast);
07028    }
07029    /* Expire CID/CW */
07030    if (p->cidcwexpire == 1) {
07031       ast_verb(3, "CPE does not support Call Waiting Caller*ID.\n");
07032       restore_conference(p);
07033    }
07034    if (p->subs[idx].linear) {
07035       p->subs[idx].f.datalen = READ_SIZE * 2;
07036    } else
07037       p->subs[idx].f.datalen = READ_SIZE;
07038 
07039    /* Handle CallerID Transmission */
07040    if ((p->owner == ast) && p->cidspill &&((ast->_state == AST_STATE_UP) || (ast->rings == p->cidrings))) {
07041       send_callerid(p);
07042    }
07043 
07044    p->subs[idx].f.frametype = AST_FRAME_VOICE;
07045    p->subs[idx].f.subclass = ast->rawreadformat;
07046    p->subs[idx].f.samples = READ_SIZE;
07047    p->subs[idx].f.mallocd = 0;
07048    p->subs[idx].f.offset = AST_FRIENDLY_OFFSET;
07049    p->subs[idx].f.data.ptr = p->subs[idx].buffer + AST_FRIENDLY_OFFSET / sizeof(p->subs[idx].buffer[0]);
07050 #if 0
07051    ast_debug(1, "Read %d of voice on %s\n", p->subs[idx].f.datalen, ast->name);
07052 #endif
07053    if (p->dialing || /* Transmitting something */
07054       (idx && (ast->_state != AST_STATE_UP)) || /* Three-way or callwait that isn't up */
07055       ((idx == SUB_CALLWAIT) && !p->subs[SUB_CALLWAIT].inthreeway) /* Inactive and non-confed call-wait */
07056       ) {
07057       /* Whoops, we're still dialing, or in a state where we shouldn't transmit....
07058          don't send anything */
07059       p->subs[idx].f.frametype = AST_FRAME_NULL;
07060       p->subs[idx].f.subclass = 0;
07061       p->subs[idx].f.samples = 0;
07062       p->subs[idx].f.mallocd = 0;
07063       p->subs[idx].f.offset = 0;
07064       p->subs[idx].f.data.ptr = NULL;
07065       p->subs[idx].f.datalen= 0;
07066    }
07067    if (p->dsp && (!p->ignoredtmf || p->callwaitcas || p->busydetect || p->callprogress || p->waitingfordt.tv_sec) && !idx) {
07068       /* Perform busy detection etc on the dahdi line */
07069       int mute;
07070 
07071       f = ast_dsp_process(ast, p->dsp, &p->subs[idx].f);
07072 
07073       /* Check if DSP code thinks we should be muting this frame and mute the conference if so */
07074       mute = ast_dsp_was_muted(p->dsp);
07075       if (p->muting != mute) {
07076          p->muting = mute;
07077          dahdi_confmute(p, mute);
07078       }
07079 
07080       if (f) {
07081          if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_BUSY)) {
07082             if ((ast->_state == AST_STATE_UP) && !p->outgoing) {
07083                /* Treat this as a "hangup" instead of a "busy" on the assumption that
07084                   a busy */
07085                f = NULL;
07086             }
07087          } else if (f->frametype == AST_FRAME_DTMF) {
07088 #ifdef HAVE_PRI
07089             if (!p->proceeding && ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) && p->pri &&
07090                ((!p->outgoing && (p->pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)) ||
07091                (p->outgoing && (p->pri->overlapdial & DAHDI_OVERLAPDIAL_OUTGOING)))) {
07092                /* Don't accept in-band DTMF when in overlap dial mode */
07093                f->frametype = AST_FRAME_NULL;
07094                f->subclass = 0;
07095             }
07096 #endif
07097             /* DSP clears us of being pulse */
07098             p->pulsedial = 0;
07099          } else if (p->waitingfordt.tv_sec) {
07100             if (ast_tvdiff_ms(ast_tvnow(), p->waitingfordt) >= p->waitfordialtone ) {
07101                p->waitingfordt.tv_sec = 0;
07102                ast_log(LOG_WARNING, "Never saw dialtone on channel %d\n", p->channel);
07103                f=NULL;
07104             } else if (f->frametype == AST_FRAME_VOICE) {
07105                f->frametype = AST_FRAME_NULL;
07106                f->subclass = 0;
07107                if ((ast_dsp_get_tstate(p->dsp) == DSP_TONE_STATE_DIALTONE || ast_dsp_get_tstate(p->dsp) == DSP_TONE_STATE_RINGING) && ast_dsp_get_tcount(p->dsp) > 9) {
07108                   p->waitingfordt.tv_sec = 0;
07109                   p->dsp_features &= ~DSP_FEATURE_WAITDIALTONE;
07110                   ast_dsp_set_features(p->dsp, p->dsp_features);
07111                   ast_log(LOG_DEBUG, "Got 10 samples of dialtone!\n");
07112                   if (!ast_strlen_zero(p->dop.dialstr)) { /* Dial deferred digits */
07113                      res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
07114                      if (res < 0) {
07115                         ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
07116                         p->dop.dialstr[0] = '\0';
07117                         ast_mutex_unlock(&p->lock);
07118                         return NULL;
07119                      } else {
07120                         ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", p->dop.dialstr);
07121                         p->dialing = 1;
07122                         p->dop.dialstr[0] = '\0';
07123                         p->dop.op = DAHDI_DIAL_OP_REPLACE;
07124                         ast_setstate(ast, AST_STATE_DIALING);
07125                      }
07126                   }
07127                }
07128             }
07129          }
07130       }
07131    } else
07132       f = &p->subs[idx].f;
07133 
07134    if (f && (f->frametype == AST_FRAME_DTMF))
07135       dahdi_handle_dtmfup(ast, idx, &f);
07136 
07137    /* If we have a fake_event, trigger exception to handle it */
07138    if (p->fake_event)
07139       ast_set_flag(ast, AST_FLAG_EXCEPTION);
07140 
07141    ast_mutex_unlock(&p->lock);
07142    return f;
07143 }

static struct ast_channel * dahdi_request ( const char *  type,
int  format,
void *  data,
int *  cause 
) [static, read]

Definition at line 10950 of file chan_dahdi.c.

References alloc_sub(), AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CDR_CALLWAIT, ast_debug, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_RESERVED, ast_strdupa, AST_TRANS_CAP_DIGITAL, ast_verbose, available(), dahdi_pvt::bearer, ast_channel::cdrflags, CHAN_PSEUDO, dahdi_pvt::channel, dahdi_pvt::confirmanswer, dahdi_pri::crvend, dahdi_pri::crvs, dahdi_new(), dahdi_subchannel::dfd, dahdi_pvt::digital, dahdi_pvt::distinctivering, duplicate_pseudo(), iflist, iflock, dahdi_pvt::inalarm, dahdi_pvt::lock, dahdi_pri::lock, lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, dahdi_pvt::mfcr2, dahdi_pvt::mfcr2call, ast_channel::name, dahdi_pvt::next, NUM_SPANS, dahdi_pvt::outgoing, dahdi_pvt::owner, dahdi_pvt::prev, dahdi_pvt::pri, dahdi_pri::pri, pri_assign_bearer(), pri_find_empty_chan(), pris, dahdi_pri::pvts, restart_monitor(), s, dahdi_pvt::sig, SIG_FXSKS, dahdi_pri::span, strsep(), SUB_CALLWAIT, SUB_REAL, dahdi_pvt::subs, and ast_channel::transfercapability.

Referenced by pri_dchannel().

10951 {
10952    ast_group_t groupmatch = 0;
10953    int channelmatch = -1;
10954    int roundrobin = 0;
10955    int callwait = 0;
10956    int busy = 0;
10957    struct dahdi_pvt *p;
10958    struct ast_channel *tmp = NULL;
10959    char *dest=NULL;
10960    int x;
10961    char *s;
10962    char opt=0;
10963    int res=0, y=0;
10964    int backwards = 0;
10965 #ifdef HAVE_PRI
10966    int crv;
10967    int bearer = -1;
10968    int trunkgroup;
10969    struct dahdi_pri *pri=NULL;
10970 #endif
10971    struct dahdi_pvt *exitpvt, *start, *end;
10972    ast_mutex_t *lock;
10973    int channelmatched = 0;
10974    int groupmatched = 0;
10975 
10976    /*
10977     * data is ---v
10978     * Dial(DAHDI/pseudo[/extension])
10979     * Dial(DAHDI/<channel#>[c|r<cadance#>|d][/extension])
10980     * Dial(DAHDI/<trunk_group#>:<crv#>[c|r<cadance#>|d][/extension])
10981     * Dial(DAHDI/(g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension])
10982     *
10983     * g - channel group allocation search forward
10984     * G - channel group allocation search backward
10985     * r - channel group allocation round robin search forward
10986     * R - channel group allocation round robin search backward
10987     *
10988     * c - Wait for DTMF digit to confirm answer
10989     * r<cadance#> - Set distintive ring cadance number
10990     * d - Force bearer capability for ISDN/SS7 call to digital.
10991     */
10992 
10993    /* Assume we're locking the iflock */
10994    lock = &iflock;
10995    start = iflist;
10996    end = ifend;
10997    if (data) {
10998       dest = ast_strdupa((char *)data);
10999    } else {
11000       ast_log(LOG_WARNING, "Channel requested with no data\n");
11001       return NULL;
11002    }
11003    if (toupper(dest[0]) == 'G' || toupper(dest[0])=='R') {
11004       /* Retrieve the group number */
11005       char *stringp;
11006 
11007       stringp = dest + 1;
11008       s = strsep(&stringp, "/");
11009       if ((res = sscanf(s, "%30d%1c%30d", &x, &opt, &y)) < 1) {
11010          ast_log(LOG_WARNING, "Unable to determine group for data %s\n", (char *)data);
11011          return NULL;
11012       }
11013       groupmatch = ((ast_group_t) 1 << x);
11014       if (toupper(dest[0]) == 'G') {
11015          if (dest[0] == 'G') {
11016             backwards = 1;
11017             p = ifend;
11018          } else
11019             p = iflist;
11020       } else {
11021          if (dest[0] == 'R') {
11022             backwards = 1;
11023             p = round_robin[x]?round_robin[x]->prev:ifend;
11024             if (!p)
11025                p = ifend;
11026          } else {
11027             p = round_robin[x]?round_robin[x]->next:iflist;
11028             if (!p)
11029                p = iflist;
11030          }
11031          roundrobin = 1;
11032       }
11033    } else {
11034       char *stringp;
11035 
11036       stringp = dest;
11037       s = strsep(&stringp, "/");
11038       p = iflist;
11039       if (!strcasecmp(s, "pseudo")) {
11040          /* Special case for pseudo */
11041          x = CHAN_PSEUDO;
11042          channelmatch = x;
11043       }
11044 #ifdef HAVE_PRI
11045       else if ((res = sscanf(s, "%30d:%30d%1c%30d", &trunkgroup, &crv, &opt, &y)) > 1) {
11046          if ((trunkgroup < 1) || (crv < 1)) {
11047             ast_log(LOG_WARNING, "Unable to determine trunk group and CRV for data %s\n", (char *)data);
11048             return NULL;
11049          }
11050          res--;
11051          for (x = 0; x < NUM_SPANS; x++) {
11052             if (pris[x].trunkgroup == trunkgroup) {
11053                pri = pris + x;
11054                lock = &pri->lock;
11055                start = pri->crvs;
11056                end = pri->crvend;
11057                break;
11058             }
11059          }
11060          if (!pri) {
11061             ast_log(LOG_WARNING, "Unable to find trunk group %d\n", trunkgroup);
11062             return NULL;
11063          }
11064          channelmatch = crv;
11065          p = pris[x].crvs;
11066       }
11067 #endif
11068       else if ((res = sscanf(s, "%30d%1c%30d", &x, &opt, &y)) < 1) {
11069          ast_log(LOG_WARNING, "Unable to determine channel for data %s\n", (char *)data);
11070          return NULL;
11071       } else {
11072          channelmatch = x;
11073       }
11074    }
11075    /* Search for an unowned channel */
11076    ast_mutex_lock(lock);
11077    exitpvt = p;
11078    while (p && !tmp) {
11079       if (roundrobin)
11080          round_robin[x] = p;
11081 #if 0
11082       ast_verbose("name = %s, %d, %d, %llu\n",p->owner ? p->owner->name : "<none>", p->channel, channelmatch, groupmatch);
11083 #endif
11084 
11085       if (p && available(p, channelmatch, groupmatch, &busy, &channelmatched, &groupmatched)) {
11086          ast_debug(1, "Using channel %d\n", p->channel);
11087          if (p->inalarm)
11088             goto next;
11089 
11090          callwait = (p->owner != NULL);
11091 #ifdef HAVE_PRI
11092          if (pri && (p->subs[SUB_REAL].dfd < 0)) {
11093             if (p->sig != SIG_FXSKS) {
11094                /* Gotta find an actual channel to use for this
11095                   CRV if this isn't a callwait */
11096                bearer = pri_find_empty_chan(pri, 0);
11097                if (bearer < 0) {
11098                   ast_log(LOG_NOTICE, "Out of bearer channels on span %d for call to CRV %d:%d\n", pri->span, trunkgroup, crv);
11099                   p = NULL;
11100                   break;
11101                }
11102                pri_assign_bearer(p, pri, pri->pvts[bearer]);
11103             } else {
11104                if (alloc_sub(p, 0)) {
11105                   ast_log(LOG_NOTICE, "Failed to allocate place holder pseudo channel!\n");
11106                   p = NULL;
11107                   break;
11108                } else
11109                   ast_debug(1, "Allocated placeholder pseudo channel\n");
11110 
11111                p->pri = pri;
11112             }
11113          }
11114 #endif
11115 #ifdef HAVE_OPENR2
11116          if (p->mfcr2) {
11117             ast_mutex_lock(&p->lock);
11118             if (p->mfcr2call) {
11119                ast_mutex_unlock(&p->lock);
11120                ast_log(LOG_DEBUG, "Yay!, someone just beat us in the race for channel %d.\n", p->channel);
11121                goto next;
11122             }
11123             p->mfcr2call = 1;
11124             ast_mutex_unlock(&p->lock);
11125          }
11126 #endif
11127          if (p->channel == CHAN_PSEUDO) {
11128             p = duplicate_pseudo(p);
11129             if (!p) {
11130                break;
11131             }
11132          }
11133          if (p->owner) {
11134             if (alloc_sub(p, SUB_CALLWAIT)) {
11135                p = NULL;
11136                break;
11137             }
11138          }
11139          p->outgoing = 1;
11140          tmp = dahdi_new(p, AST_STATE_RESERVED, 0, p->owner ? SUB_CALLWAIT : SUB_REAL, 0, 0);
11141          if (!tmp) {
11142             p->outgoing = 0;
11143          }
11144 #ifdef HAVE_PRI
11145          if (p->bearer) {
11146             /* Log owner to bearer channel, too */
11147             p->bearer->owner = tmp;
11148          }
11149 #endif
11150          /* Make special notes */
11151          if (res > 1) {
11152             if (opt == 'c') {
11153                /* Confirm answer */
11154                p->confirmanswer = 1;
11155             } else if (opt == 'r') {
11156                /* Distinctive ring */
11157                if (res < 3)
11158                   ast_log(LOG_WARNING, "Distinctive ring missing identifier in '%s'\n", (char *)data);
11159                else
11160                   p->distinctivering = y;
11161             } else if (opt == 'd') {
11162                /* If this is an ISDN call, make it digital */
11163                p->digital = 1;
11164                if (tmp)
11165                   tmp->transfercapability = AST_TRANS_CAP_DIGITAL;
11166             } else {
11167                ast_log(LOG_WARNING, "Unknown option '%c' in '%s'\n", opt, (char *)data);
11168             }
11169          }
11170          /* Note if the call is a call waiting call */
11171          if (tmp && callwait)
11172             tmp->cdrflags |= AST_CDR_CALLWAIT;
11173          break;
11174       }
11175 next:
11176       if (backwards) {
11177          p = p->prev;
11178          if (!p)
11179             p = end;
11180       } else {
11181          p = p->next;
11182          if (!p)
11183             p = start;
11184       }
11185       /* stop when you roll to the one that we started from */
11186       if (p == exitpvt)
11187          break;
11188    }
11189    ast_mutex_unlock(lock);
11190    restart_monitor();
11191    if (callwait)
11192       *cause = AST_CAUSE_BUSY;
11193    else if (!tmp) {
11194       if (channelmatched) {
11195          if (busy)
11196             *cause = AST_CAUSE_BUSY;
11197       } else if (groupmatched) {
11198          *cause = AST_CAUSE_CONGESTION;
11199       }
11200    }
11201 
11202    return tmp;
11203 }

static int dahdi_restart ( void   )  [static]

Definition at line 14454 of file chan_dahdi.c.

References ast_active_channels(), ast_cond_wait(), ast_debug, ast_log(), ast_mutex_init(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_verb, dahdi_close_pri_fd(), dahdi_close_ss7_fd(), dahdi_pri_error(), dahdi_pri_message(), dahdi_r2_destroy_links(), dahdi_softhangup_all(), dahdi_ss7_error(), dahdi_ss7_message(), destroy_all_channels(), dahdi_subchannel::dfd, iflist, linksets, lock, LOG_WARNING, dahdi_ss7::master, dahdi_pri::master, master, monlock, dahdi_pvt::next, NUM_DCHANS, NUM_SPANS, dahdi_pri::offset, dahdi_pvt::owner, pris, restart_lock, setup_dahdi(), ss_thread_lock, SUB_REAL, and dahdi_pvt::subs.

Referenced by action_dahdirestart(), and dahdi_restart_cmd().

14455 {
14456 #if defined(HAVE_PRI) || defined(HAVE_SS7)
14457    int i, j;
14458 #endif
14459    int cancel_code;
14460    struct dahdi_pvt *p;
14461 
14462    ast_mutex_lock(&restart_lock);
14463    ast_verb(1, "Destroying channels and reloading DAHDI configuration.\n");
14464    dahdi_softhangup_all();
14465    ast_verb(4, "Initial softhangup of all DAHDI channels complete.\n");
14466 #ifdef HAVE_OPENR2
14467    dahdi_r2_destroy_links();
14468 #endif
14469 
14470 #if defined(HAVE_PRI)
14471    for (i = 0; i < NUM_SPANS; i++) {
14472       if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL)) {
14473          cancel_code = pthread_cancel(pris[i].master);
14474          pthread_kill(pris[i].master, SIGURG);
14475          ast_debug(4, "Waiting to join thread of span %d with pid=%p, cancel_code=%d\n", i, (void *) pris[i].master, cancel_code);
14476          pthread_join(pris[i].master, NULL);
14477          ast_debug(4, "Joined thread of span %d\n", i);
14478       }
14479    }
14480 #endif
14481 
14482 #if defined(HAVE_SS7)
14483    for (i = 0; i < NUM_SPANS; i++) {
14484       if (linksets[i].master && (linksets[i].master != AST_PTHREADT_NULL)) {
14485          cancel_code = pthread_cancel(linksets[i].master);
14486          pthread_kill(linksets[i].master, SIGURG);
14487          ast_debug(4, "Waiting to join thread of span %d with pid=%p, cancel_code=%d\n", i, (void *) linksets[i].master, cancel_code);
14488          pthread_join(linksets[i].master, NULL);
14489          ast_debug(4, "Joined thread of span %d\n", i);
14490       }
14491    }
14492 #endif
14493 
14494    ast_mutex_lock(&monlock);
14495    if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
14496       cancel_code = pthread_cancel(monitor_thread);
14497       pthread_kill(monitor_thread, SIGURG);
14498       ast_debug(4, "Waiting to join monitor thread with pid=%p, cancel_code=%d\n", (void *) monitor_thread, cancel_code);
14499       pthread_join(monitor_thread, NULL);
14500       ast_debug(4, "Joined monitor thread\n");
14501    }
14502    monitor_thread = AST_PTHREADT_NULL; /* prepare to restart thread in setup_dahdi once channels are reconfigured */
14503 
14504    ast_mutex_lock(&ss_thread_lock);
14505    while (ss_thread_count > 0) { /* let ss_threads finish and run dahdi_hangup before dahvi_pvts are destroyed */
14506       int x = DAHDI_FLASH;
14507       ast_debug(3, "Waiting on %d ss_thread(s) to finish\n", ss_thread_count);
14508 
14509       for (p = iflist; p; p = p->next) {
14510          if (p->owner)
14511             ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); /* important to create an event for dahdi_wait_event to register so that all ss_threads terminate */
14512          }
14513          ast_cond_wait(&ss_thread_complete, &ss_thread_lock);
14514       }
14515 
14516    /* ensure any created channels before monitor threads were stopped are hungup */
14517    dahdi_softhangup_all();
14518    ast_verb(4, "Final softhangup of all DAHDI channels complete.\n");
14519    destroy_all_channels();
14520    ast_debug(1, "Channels destroyed. Now re-reading config. %d active channels remaining.\n", ast_active_channels());
14521 
14522    ast_mutex_unlock(&monlock);
14523 
14524 #ifdef HAVE_PRI
14525    for (i = 0; i < NUM_SPANS; i++) {
14526       for (j = 0; j < NUM_DCHANS; j++)
14527          dahdi_close_pri_fd(&(pris[i]), j);
14528    }
14529 
14530    memset(pris, 0, sizeof(pris));
14531    for (i = 0; i < NUM_SPANS; i++) {
14532       ast_mutex_init(&pris[i].lock);
14533       pris[i].offset = -1;
14534       pris[i].master = AST_PTHREADT_NULL;
14535       for (j = 0; j < NUM_DCHANS; j++)
14536          pris[i].fds[j] = -1;
14537       }
14538    pri_set_error(dahdi_pri_error);
14539    pri_set_message(dahdi_pri_message);
14540 #endif
14541 #ifdef HAVE_SS7
14542    for (i = 0; i < NUM_SPANS; i++) {
14543       for (j = 0; j < NUM_DCHANS; j++)
14544          dahdi_close_ss7_fd(&(linksets[i]), j);
14545    }
14546 
14547    memset(linksets, 0, sizeof(linksets));
14548    for (i = 0; i < NUM_SPANS; i++) {
14549       ast_mutex_init(&linksets[i].lock);
14550       linksets[i].master = AST_PTHREADT_NULL;
14551       for (j = 0; j < NUM_DCHANS; j++)
14552          linksets[i].fds[j] = -1;
14553    }
14554    ss7_set_error(dahdi_ss7_error);
14555    ss7_set_message(dahdi_ss7_message);
14556 #endif
14557 
14558    if (setup_dahdi(2) != 0) {
14559       ast_log(LOG_WARNING, "Reload channels from dahdi config failed!\n");
14560       ast_mutex_unlock(&ss_thread_lock);
14561       return 1;
14562    }
14563    ast_mutex_unlock(&ss_thread_lock);
14564    ast_mutex_unlock(&restart_lock);
14565    return 0;
14566 }

static char* dahdi_restart_cmd ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14568 of file chan_dahdi.c.

References ast_cli_args::argc, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_restart(), and ast_cli_entry::usage.

14569 {
14570    switch (cmd) {
14571    case CLI_INIT:
14572       e->command = "dahdi restart";
14573       e->usage =
14574          "Usage: dahdi restart\n"
14575          "  Restarts the DAHDI channels: destroys them all and then\n"
14576          "  re-reads them from chan_dahdi.conf.\n"
14577          "  Note that this will STOP any running CALL on DAHDI channels.\n"
14578          "";
14579       return NULL;
14580    case CLI_GENERATE:
14581       return NULL;
14582    }
14583    if (a->argc != 2)
14584       return CLI_SHOWUSAGE;
14585 
14586    if (dahdi_restart() != 0)
14587       return CLI_FAILURE;
14588    return CLI_SUCCESS;
14589 }

static int dahdi_ring_phone ( struct dahdi_pvt *  p  )  [static]

Definition at line 5546 of file chan_dahdi.c.

References ast_log(), dahdi_subchannel::dfd, errno, LOG_WARNING, SUB_REAL, and dahdi_pvt::subs.

Referenced by __dahdi_exception(), and dahdi_handle_event().

05547 {
05548    int x;
05549    int res;
05550    /* Make sure our transmit state is on hook */
05551    x = 0;
05552    x = DAHDI_ONHOOK;
05553    res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
05554    do {
05555       x = DAHDI_RING;
05556       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
05557       if (res) {
05558          switch (errno) {
05559          case EBUSY:
05560          case EINTR:
05561             /* Wait just in case */
05562             usleep(10000);
05563             continue;
05564          case EINPROGRESS:
05565             res = 0;
05566             break;
05567          default:
05568             ast_log(LOG_WARNING, "Couldn't ring the phone: %s\n", strerror(errno));
05569             res = 0;
05570          }
05571       }
05572    } while (res);
05573    return res;
05574 }

static int dahdi_send_keypad_facility_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 3964 of file chan_dahdi.c.

References ast_debug, ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), dahdi_pvt::call, dahdi_pvt::lock, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), and ast_channel::tech_pvt.

Referenced by load_module().

03965 {
03966    /* Data will be our digit string */
03967    struct dahdi_pvt *p;
03968    char *digits = (char *) data;
03969 
03970    if (ast_strlen_zero(digits)) {
03971       ast_debug(1, "No digit string sent to application!\n");
03972       return -1;
03973    }
03974 
03975    p = (struct dahdi_pvt *)chan->tech_pvt;
03976 
03977    if (!p) {
03978       ast_debug(1, "Unable to find technology private\n");
03979       return -1;
03980    }
03981 
03982    ast_mutex_lock(&p->lock);
03983 
03984    if (!p->pri || !p->call) {
03985       ast_debug(1, "Unable to find pri or call on channel!\n");
03986       ast_mutex_unlock(&p->lock);
03987       return -1;
03988    }
03989 
03990    if (!pri_grab(p, p->pri)) {
03991       pri_keypad_facility(p->pri->pri, p->call, digits);
03992       pri_rel(p->pri);
03993    } else {
03994       ast_debug(1, "Unable to grab pri to send keypad facility!\n");
03995       ast_mutex_unlock(&p->lock);
03996       return -1;
03997    }
03998 
03999    ast_mutex_unlock(&p->lock);
04000 
04001    return 0;
04002 }

static int dahdi_sendtext ( struct ast_channel *  c,
const char *  text 
) [static]

Definition at line 17468 of file chan_dahdi.c.

References ASCII_BYTES_PER_CHAR, ast_check_hangup(), ast_debug, ast_free, AST_LAW, ast_log(), ast_malloc, buf, dahdi_pvt::channel, dahdi_get_index(), dahdi_subchannel::dfd, END_SILENCE_LEN, errno, HEADER_LEN, HEADER_MS, len(), LOG_ERROR, LOG_WARNING, dahdi_pvt::mate, PUT_CLID, PUT_CLID_MARKMS, READ_SIZE, dahdi_pvt::subs, dahdi_pvt::tdd, TDD_BYTES_PER_CHAR, tdd_generate(), ast_channel::tech_pvt, and TRAILER_MS.

17469 {
17470 #define  END_SILENCE_LEN 400
17471 #define  HEADER_MS 50
17472 #define  TRAILER_MS 5
17473 #define  HEADER_LEN ((HEADER_MS + TRAILER_MS) * 8)
17474 #define  ASCII_BYTES_PER_CHAR 80
17475 
17476    unsigned char *buf,*mybuf;
17477    struct dahdi_pvt *p = c->tech_pvt;
17478    struct pollfd fds[1];
17479    int size,res,fd,len,x;
17480    int bytes=0;
17481    /* Initial carrier (imaginary) */
17482    float cr = 1.0;
17483    float ci = 0.0;
17484    float scont = 0.0;
17485    int idx;
17486 
17487    idx = dahdi_get_index(c, p, 0);
17488    if (idx < 0) {
17489       ast_log(LOG_WARNING, "Huh?  I don't exist?\n");
17490       return -1;
17491    }
17492    if (!text[0]) return(0); /* if nothing to send, dont */
17493    if ((!p->tdd) && (!p->mate)) return(0);  /* if not in TDD mode, just return */
17494    if (p->mate)
17495       buf = ast_malloc(((strlen(text) + 1) * ASCII_BYTES_PER_CHAR) + END_SILENCE_LEN + HEADER_LEN);
17496    else
17497       buf = ast_malloc(((strlen(text) + 1) * TDD_BYTES_PER_CHAR) + END_SILENCE_LEN);
17498    if (!buf)
17499       return -1;
17500    mybuf = buf;
17501    if (p->mate) {
17502       int codec = AST_LAW(p);
17503       for (x = 0; x < HEADER_MS; x++) {   /* 50 ms of Mark */
17504          PUT_CLID_MARKMS;
17505       }
17506       /* Put actual message */
17507       for (x = 0; text[x]; x++) {
17508          PUT_CLID(text[x]);
17509       }
17510       for (x = 0; x < TRAILER_MS; x++) {  /* 5 ms of Mark */
17511          PUT_CLID_MARKMS;
17512       }
17513       len = bytes;
17514       buf = mybuf;
17515    } else {
17516       len = tdd_generate(p->tdd, buf, text);
17517       if (len < 1) {
17518          ast_log(LOG_ERROR, "TDD generate (len %d) failed!!\n", (int)strlen(text));
17519          ast_free(mybuf);
17520          return -1;
17521       }
17522    }
17523    memset(buf + len, 0x7f, END_SILENCE_LEN);
17524    len += END_SILENCE_LEN;
17525    fd = p->subs[idx].dfd;
17526    while (len) {
17527       if (ast_check_hangup(c)) {
17528          ast_free(mybuf);
17529          return -1;
17530       }
17531       size = len;
17532       if (size > READ_SIZE)
17533          size = READ_SIZE;
17534       fds[0].fd = fd;
17535       fds[0].events = POLLOUT | POLLPRI;
17536       fds[0].revents = 0;
17537       res = poll(fds, 1, -1);
17538       if (!res) {
17539          ast_debug(1, "poll (for write) ret. 0 on channel %d\n", p->channel);
17540          continue;
17541       }
17542       /* if got exception */
17543       if (fds[0].revents & POLLPRI) {
17544          ast_free(mybuf);
17545          return -1;
17546       }
17547       if (!(fds[0].revents & POLLOUT)) {
17548          ast_debug(1, "write fd not ready on channel %d\n", p->channel);
17549          continue;
17550       }
17551       res = write(fd, buf, size);
17552       if (res != size) {
17553          if (res == -1) {
17554             ast_free(mybuf);
17555             return -1;
17556          }
17557          ast_debug(1, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel);
17558          break;
17559       }
17560       len -= size;
17561       buf += size;
17562    }
17563    ast_free(mybuf);
17564    return(0);
17565 }

static char* dahdi_set_dnd ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15229 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_false(), ast_mutex_lock(), ast_mutex_unlock(), ast_true(), dahdi_pvt::channel, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_dnd(), ast_cli_args::fd, iflist, iflock, dahdi_pvt::next, and ast_cli_entry::usage.

15230 {
15231    int channel;
15232    int on;
15233    struct dahdi_pvt *dahdi_chan = NULL;
15234 
15235    switch (cmd) {
15236    case CLI_INIT:
15237       e->command = "dahdi set dnd";
15238       e->usage =
15239          "Usage: dahdi set dnd <chan#> <on|off>\n"
15240          "  Sets/resets DND (Do Not Disturb) mode on a channel.\n"
15241          "  Changes take effect immediately.\n"
15242          "  <chan num> is the channel number\n"
15243          "  <on|off> Enable or disable DND mode?\n"
15244          ;
15245       return NULL;
15246    case CLI_GENERATE:
15247       return NULL;
15248    }
15249 
15250    if (a->argc != 5)
15251       return CLI_SHOWUSAGE;
15252 
15253    if ((channel = atoi(a->argv[3])) <= 0) {
15254       ast_cli(a->fd, "Expected channel number, got '%s'\n", a->argv[3]);
15255       return CLI_SHOWUSAGE;
15256    }
15257 
15258    if (ast_true(a->argv[4]))
15259       on = 1;
15260    else if (ast_false(a->argv[4]))
15261       on = 0;
15262    else {
15263       ast_cli(a->fd, "Expected 'on' or 'off', got '%s'\n", a->argv[4]);
15264       return CLI_SHOWUSAGE;
15265    }
15266 
15267    ast_mutex_lock(&iflock);
15268    for (dahdi_chan = iflist; dahdi_chan; dahdi_chan = dahdi_chan->next) {
15269       if (dahdi_chan->channel != channel)
15270          continue;
15271 
15272       /* Found the channel. Actually set it */
15273       dahdi_dnd(dahdi_chan, on);
15274       break;
15275    }
15276    ast_mutex_unlock(&iflock);
15277 
15278    if (!dahdi_chan) {
15279       ast_cli(a->fd, "Unable to find given channel %d\n", channel);
15280       return CLI_FAILURE;
15281    }
15282 
15283    return CLI_SUCCESS;
15284 }

static int dahdi_set_hook ( int  fd,
int  hs 
) [inline, static]

Definition at line 2865 of file chan_dahdi.c.

References ast_log(), errno, and LOG_WARNING.

Referenced by __dahdi_exception(), dahdi_answer(), dahdi_handle_event(), dahdi_hangup(), dahdi_indicate(), dahdi_wink(), handle_init_event(), mkintf(), mwi_send_process_buffer(), mwi_send_process_event(), and ss_thread().

02866 {
02867    int x, res;
02868 
02869    x = hs;
02870    res = ioctl(fd, DAHDI_HOOK, &x);
02871 
02872    if (res < 0) {
02873       if (errno == EINPROGRESS)
02874          return 0;
02875       ast_log(LOG_WARNING, "DAHDI hook failed returned %d (trying %d): %s\n", res, hs, strerror(errno));
02876       /* will expectedly fail if phone is off hook during operation, such as during a restart */
02877    }
02878 
02879    return res;
02880 }

static char* dahdi_set_hwgain ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15086 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_subchannel::dfd, errno, ast_cli_args::fd, iflist, iflock, dahdi_pvt::next, SUB_REAL, dahdi_pvt::subs, and ast_cli_entry::usage.

15087 {
15088    int channel;
15089    int gain;
15090    int tx;
15091    struct dahdi_hwgain hwgain;
15092    struct dahdi_pvt *tmp = NULL;
15093 
15094    switch (cmd) {
15095    case CLI_INIT:
15096       e->command = "dahdi set hwgain";
15097       e->usage =
15098          "Usage: dahdi set hwgain <rx|tx> <chan#> <gain>\n"
15099          "  Sets the hardware gain on a a given channel, overriding the\n"
15100          "   value provided at module loadtime, whether the channel is in\n"
15101          "   use or not.  Changes take effect immediately.\n"
15102          "   <rx|tx> which direction do you want to change (relative to our module)\n"
15103          "   <chan num> is the channel number relative to the device\n"
15104          "   <gain> is the gain in dB (e.g. -3.5 for -3.5dB)\n";
15105       return NULL;
15106    case CLI_GENERATE:
15107       return NULL;
15108    }
15109 
15110    if (a->argc != 6)
15111       return CLI_SHOWUSAGE;
15112 
15113    if (!strcasecmp("rx", a->argv[3]))
15114       tx = 0; /* rx */
15115    else if (!strcasecmp("tx", a->argv[3]))
15116       tx = 1; /* tx */
15117    else
15118       return CLI_SHOWUSAGE;
15119 
15120    channel = atoi(a->argv[4]);
15121    gain = atof(a->argv[5])*10.0;
15122 
15123    ast_mutex_lock(&iflock);
15124 
15125    for (tmp = iflist; tmp; tmp = tmp->next) {
15126 
15127       if (tmp->channel != channel)
15128          continue;
15129 
15130       if (tmp->subs[SUB_REAL].dfd == -1)
15131          break;
15132 
15133       hwgain.newgain = gain;
15134       hwgain.tx = tx;
15135       if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_SET_HWGAIN, &hwgain) < 0) {
15136          ast_cli(a->fd, "Unable to set the hardware gain for channel %d: %s\n", channel, strerror(errno));
15137          ast_mutex_unlock(&iflock);
15138          return CLI_FAILURE;
15139       }
15140       ast_cli(a->fd, "hardware %s gain set to %d (%.1f dB) on channel %d\n",
15141          tx ? "tx" : "rx", gain, (float)gain/10.0, channel);
15142       break;
15143    }
15144 
15145    ast_mutex_unlock(&iflock);
15146 
15147    if (tmp)
15148       return CLI_SUCCESS;
15149 
15150    ast_cli(a->fd, "Unable to find given channel %d\n", channel);
15151    return CLI_FAILURE;
15152 
15153 }

static char* dahdi_set_swgain ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15155 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_subchannel::dfd, ast_cli_args::fd, iflist, iflock, dahdi_pvt::law, lock, dahdi_pvt::next, set_actual_rxgain(), set_actual_txgain(), SUB_REAL, dahdi_pvt::subs, and ast_cli_entry::usage.

15156 {
15157    int channel;
15158    float gain;
15159    int tx;
15160    int res;
15161    ast_mutex_t *lock;
15162    struct dahdi_pvt *tmp = NULL;
15163 
15164    switch (cmd) {
15165    case CLI_INIT:
15166       e->command = "dahdi set swgain";
15167       e->usage =
15168          "Usage: dahdi set swgain <rx|tx> <chan#> <gain>\n"
15169          "  Sets the software gain on a a given channel, overriding the\n"
15170          "   value provided at module loadtime, whether the channel is in\n"
15171          "   use or not.  Changes take effect immediately.\n"
15172          "   <rx|tx> which direction do you want to change (relative to our module)\n"
15173          "   <chan num> is the channel number relative to the device\n"
15174          "   <gain> is the gain in dB (e.g. -3.5 for -3.5dB)\n";
15175       return NULL;
15176    case CLI_GENERATE:
15177       return NULL;
15178    }
15179 
15180    lock = &iflock;
15181 
15182    if (a->argc != 6)
15183       return CLI_SHOWUSAGE;
15184 
15185    if (!strcasecmp("rx", a->argv[3]))
15186       tx = 0; /* rx */
15187    else if (!strcasecmp("tx", a->argv[3]))
15188       tx = 1; /* tx */
15189    else
15190       return CLI_SHOWUSAGE;
15191 
15192    channel = atoi(a->argv[4]);
15193    gain = atof(a->argv[5]);
15194 
15195    ast_mutex_lock(lock);
15196    for (tmp = iflist; tmp; tmp = tmp->next) {
15197 
15198       if (tmp->channel != channel)
15199          continue;
15200 
15201       if (tmp->subs[SUB_REAL].dfd == -1)
15202          break;
15203 
15204       if (tx)
15205          res = set_actual_txgain(tmp->subs[SUB_REAL].dfd, channel, gain, tmp->law);
15206       else
15207          res = set_actual_rxgain(tmp->subs[SUB_REAL].dfd, channel, gain, tmp->law);
15208 
15209       if (res) {
15210          ast_cli(a->fd, "Unable to set the software gain for channel %d\n", channel);
15211          ast_mutex_unlock(lock);
15212          return CLI_FAILURE;
15213       }
15214 
15215       ast_cli(a->fd, "software %s gain set to %.1f on channel %d\n",
15216          tx ? "tx" : "rx", gain, channel);
15217       break;
15218    }
15219    ast_mutex_unlock(lock);
15220 
15221    if (tmp)
15222       return CLI_SUCCESS;
15223 
15224    ast_cli(a->fd, "Unable to find given channel %d\n", channel);
15225    return CLI_FAILURE;
15226 
15227 }

static int dahdi_setlaw ( int  dfd,
int  law 
) [static]

Definition at line 11206 of file chan_dahdi.c.

Referenced by pri_dchannel(), and ss7_start_call().

11207 {
11208    return ioctl(dfd, DAHDI_SETLAW, &law);
11209 }

static int dahdi_setlinear ( int  dfd,
int  linear 
) [static]

Definition at line 2167 of file chan_dahdi.c.

Referenced by dahdi_hangup(), dahdi_new(), dahdi_read(), dahdi_write(), send_callerid(), and ss_thread().

02168 {
02169    int res;
02170    res = ioctl(dfd, DAHDI_SETLINEAR, &linear);
02171    if (res)
02172       return res;
02173    return 0;
02174 }

static int dahdi_setoption ( struct ast_channel *  chan,
int  option,
void *  data,
int  datalen 
) [static]

Todo:
XXX This is an abuse of the stack!!

Definition at line 4846 of file chan_dahdi.c.

References ast_check_hangup(), ast_debug, ast_dsp_set_digitmode(), ast_log(), AST_OPTION_AUDIO_MODE, AST_OPTION_ECHOCAN, AST_OPTION_OPRMODE, AST_OPTION_RELAXDTMF, AST_OPTION_RXGAIN, AST_OPTION_TDD, AST_OPTION_TONE_VERIFY, AST_OPTION_TXGAIN, ast_tdd_gen_ecdisa(), buf, dahdi_pvt::channel, dahdi_disable_ec(), dahdi_enable_ec(), dahdi_get_index(), dahdi_subchannel::dfd, dahdi_pvt::didtdd, dahdi_pvt::dsp, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MUTECONF, DSP_DIGITMODE_MUTEMAX, DSP_DIGITMODE_RELAXDTMF, dahdi_pvt::dtmfrelax, errno, dahdi_pvt::law, len(), LOG_NOTICE, LOG_WARNING, dahdi_pvt::mate, oprmode::mode, ast_channel::name, dahdi_pvt::oprmode, dahdi_pvt::oprpeer, oprmode::peer, pp, READ_SIZE, dahdi_pvt::rxgain, set_actual_rxgain(), set_actual_txgain(), SUB_REAL, dahdi_pvt::subs, dahdi_pvt::tdd, tdd_free(), tdd_new(), ast_channel::tech, ast_channel::tech_pvt, dahdi_pvt::txgain, and ast_channel_tech::type.

04847 {
04848    char *cp;
04849    signed char *scp;
04850    int x;
04851    int idx;
04852    struct dahdi_pvt *p = chan->tech_pvt, *pp;
04853    struct oprmode *oprmode;
04854 
04855 
04856    /* all supported options require data */
04857    if (!data || (datalen < 1)) {
04858       errno = EINVAL;
04859       return -1;
04860    }
04861 
04862    switch (option) {
04863    case AST_OPTION_TXGAIN:
04864       scp = (signed char *) data;
04865       idx = dahdi_get_index(chan, p, 0);
04866       if (idx < 0) {
04867          ast_log(LOG_WARNING, "No index in TXGAIN?\n");
04868          return -1;
04869       }
04870       ast_debug(1, "Setting actual tx gain on %s to %f\n", chan->name, p->txgain + (float) *scp);
04871       return set_actual_txgain(p->subs[idx].dfd, 0, p->txgain + (float) *scp, p->law);
04872    case AST_OPTION_RXGAIN:
04873       scp = (signed char *) data;
04874       idx = dahdi_get_index(chan, p, 0);
04875       if (idx < 0) {
04876          ast_log(LOG_WARNING, "No index in RXGAIN?\n");
04877          return -1;
04878       }
04879       ast_debug(1, "Setting actual rx gain on %s to %f\n", chan->name, p->rxgain + (float) *scp);
04880       return set_actual_rxgain(p->subs[idx].dfd, 0, p->rxgain + (float) *scp, p->law);
04881    case AST_OPTION_TONE_VERIFY:
04882       if (!p->dsp)
04883          break;
04884       cp = (char *) data;
04885       switch (*cp) {
04886       case 1:
04887          ast_debug(1, "Set option TONE VERIFY, mode: MUTECONF(1) on %s\n",chan->name);
04888          ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MUTECONF | p->dtmfrelax);  /* set mute mode if desired */
04889          break;
04890       case 2:
04891          ast_debug(1, "Set option TONE VERIFY, mode: MUTECONF/MAX(2) on %s\n",chan->name);
04892          ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX | p->dtmfrelax);  /* set mute mode if desired */
04893          break;
04894       default:
04895          ast_debug(1, "Set option TONE VERIFY, mode: OFF(0) on %s\n",chan->name);
04896          ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);  /* set mute mode if desired */
04897          break;
04898       }
04899       break;
04900    case AST_OPTION_TDD:
04901       /* turn on or off TDD */
04902       cp = (char *) data;
04903       p->mate = 0;
04904       if (!*cp) { /* turn it off */
04905          ast_debug(1, "Set option TDD MODE, value: OFF(0) on %s\n",chan->name);
04906          if (p->tdd)
04907             tdd_free(p->tdd);
04908          p->tdd = 0;
04909          break;
04910       }
04911       ast_debug(1, "Set option TDD MODE, value: %s(%d) on %s\n",
04912          (*cp == 2) ? "MATE" : "ON", (int) *cp, chan->name);
04913       dahdi_disable_ec(p);
04914       /* otherwise, turn it on */
04915       if (!p->didtdd) { /* if havent done it yet */
04916          unsigned char mybuf[41000];/*! \todo XXX This is an abuse of the stack!! */
04917          unsigned char *buf;
04918          int size, res, fd, len;
04919          struct pollfd fds[1];
04920 
04921          buf = mybuf;
04922          memset(buf, 0x7f, sizeof(mybuf)); /* set to silence */
04923          ast_tdd_gen_ecdisa(buf + 16000, 16000);  /* put in tone */
04924          len = 40000;
04925          idx = dahdi_get_index(chan, p, 0);
04926          if (idx < 0) {
04927             ast_log(LOG_WARNING, "No index in TDD?\n");
04928             return -1;
04929          }
04930          fd = p->subs[idx].dfd;
04931          while (len) {
04932             if (ast_check_hangup(chan))
04933                return -1;
04934             size = len;
04935             if (size > READ_SIZE)
04936                size = READ_SIZE;
04937             fds[0].fd = fd;
04938             fds[0].events = POLLPRI | POLLOUT;
04939             fds[0].revents = 0;
04940             res = poll(fds, 1, -1);
04941             if (!res) {
04942                ast_debug(1, "poll (for write) ret. 0 on channel %d\n", p->channel);
04943                continue;
04944             }
04945             /* if got exception */
04946             if (fds[0].revents & POLLPRI)
04947                return -1;
04948             if (!(fds[0].revents & POLLOUT)) {
04949                ast_debug(1, "write fd not ready on channel %d\n", p->channel);
04950                continue;
04951             }
04952             res = write(fd, buf, size);
04953             if (res != size) {
04954                if (res == -1) return -1;
04955                ast_debug(1, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel);
04956                break;
04957             }
04958             len -= size;
04959             buf += size;
04960          }
04961          p->didtdd = 1; /* set to have done it now */
04962       }
04963       if (*cp == 2) { /* Mate mode */
04964          if (p->tdd)
04965             tdd_free(p->tdd);
04966          p->tdd = 0;
04967          p->mate = 1;
04968          break;
04969       }
04970       if (!p->tdd) { /* if we dont have one yet */
04971          p->tdd = tdd_new(); /* allocate one */
04972       }
04973       break;
04974    case AST_OPTION_RELAXDTMF:  /* Relax DTMF decoding (or not) */
04975       if (!p->dsp)
04976          break;
04977       cp = (char *) data;
04978       ast_debug(1, "Set option RELAX DTMF, value: %s(%d) on %s\n",
04979          *cp ? "ON" : "OFF", (int) *cp, chan->name);
04980       ast_dsp_set_digitmode(p->dsp, ((*cp) ? DSP_DIGITMODE_RELAXDTMF : DSP_DIGITMODE_DTMF) | p->dtmfrelax);
04981       break;
04982    case AST_OPTION_AUDIO_MODE:  /* Set AUDIO mode (or not) */
04983       cp = (char *) data;
04984       if (!*cp) {
04985          ast_debug(1, "Set option AUDIO MODE, value: OFF(0) on %s\n", chan->name);
04986          x = 0;
04987          dahdi_disable_ec(p);
04988       } else {
04989          ast_debug(1, "Set option AUDIO MODE, value: ON(1) on %s\n", chan->name);
04990          x = 1;
04991       }
04992       if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &x) == -1)
04993          ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n", p->channel, x, strerror(errno));
04994       break;
04995    case AST_OPTION_OPRMODE:  /* Operator services mode */
04996       oprmode = (struct oprmode *) data;
04997       /* We don't support operator mode across technologies */
04998       if (strcasecmp(chan->tech->type, oprmode->peer->tech->type)) {
04999          ast_log(LOG_NOTICE, "Operator mode not supported on %s to %s calls.\n",
05000                chan->tech->type, oprmode->peer->tech->type);
05001          errno = EINVAL;
05002          return -1;
05003       }
05004       pp = oprmode->peer->tech_pvt;
05005       p->oprmode = pp->oprmode = 0;
05006       /* setup peers */
05007       p->oprpeer = pp;
05008       pp->oprpeer = p;
05009       /* setup modes, if any */
05010       if (oprmode->mode)
05011       {
05012          pp->oprmode = oprmode->mode;
05013          p->oprmode = -oprmode->mode;
05014       }
05015       ast_debug(1, "Set Operator Services mode, value: %d on %s/%s\n",
05016          oprmode->mode, chan->name,oprmode->peer->name);
05017       break;
05018    case AST_OPTION_ECHOCAN:
05019       cp = (char *) data;
05020       if (*cp) {
05021          ast_debug(1, "Enabling echo cancelation on %s\n", chan->name);
05022          dahdi_enable_ec(p);
05023       } else {
05024          ast_debug(1, "Disabling echo cancelation on %s\n", chan->name);
05025          dahdi_disable_ec(p);
05026       }
05027       break;
05028    }
05029    errno = 0;
05030 
05031    return 0;
05032 }

static char* dahdi_show_channel ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14725 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::bearer, dahdi_pvt::busy_quietlength, dahdi_pvt::busy_tonelength, dahdi_pvt::busycount, dahdi_pvt::busydetect, dahdi_pvt::call, dahdi_pvt::callwaitcas, dahdi_pvt::channel, dahdi_pvt::cic, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::cid_ton, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_pvt::confno, dahdi_pvt::context, dahdi_pri::crvs, dahdi_pvt::destroy, dahdi_subchannel::dfd, dahdi_pvt::dialing, dahdi_pvt::dnd, dahdi_pvt::dsp, dahdi_pvt::dtmfrelax, dahdi_pvt::echocanbridged, dahdi_pvt::echocancel, dahdi_pvt::echocanon, errno, dahdi_pvt::exten, dahdi_pvt::faxhandled, ast_cli_args::fd, dahdi_pvt::head, iflist, iflock, dahdi_pvt::inalarm, dahdi_pvt::inconference, dahdi_subchannel::inthreeway, dahdi_pvt::law, dahdi_subchannel::linear, dahdi_pri::lock, lock, LOG_WARNING, dahdi_pvt::logicalspan, dahdi_pvt::mailbox, dahdi_pvt::master, MAX_SLAVES, dahdi_pvt::mfcr2, dahdi_pvt::mfcr2_accept_on_offer, dahdi_pvt::mfcr2_allow_collect_calls, dahdi_pvt::mfcr2_charge_calls, dahdi_pvt::mfcr2_forced_release, ast_channel::name, ast_variable::name, dahdi_pvt::next, ast_variable::next, NUM_SPANS, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::params, dahdi_pvt::pri, dahdi_pri::pri, pris, dahdi_pvt::propconfno, dahdi_pvt::pulsedial, dahdi_pvt::r2chan, dahdi_pvt::radio, dahdi_pvt::resetting, S_OR, dahdi_pvt::sig, sig2str, dahdi_pvt::slaves, dahdi_pvt::span, dahdi_pvt::ss7, SUB_CALLWAIT, SUB_REAL, SUB_THREEWAY, dahdi_pvt::subs, dahdi_pvt::tdd, ast_cli_entry::usage, ast_variable::value, dahdi_pvt::vars, and dahdi_pvt::waitfordialtone.

14726 {
14727    int channel;
14728    struct dahdi_pvt *tmp = NULL;
14729    struct dahdi_confinfo ci;
14730    struct dahdi_params ps;
14731    int x;
14732    ast_mutex_t *lock;
14733    struct dahdi_pvt *start;
14734 #ifdef HAVE_PRI
14735    char *c;
14736    int trunkgroup;
14737    struct dahdi_pri *pri=NULL;
14738 #endif
14739    switch (cmd) {
14740    case CLI_INIT:
14741       e->command = "dahdi show channel";
14742       e->usage =
14743          "Usage: dahdi show channel <chan num>\n"
14744          "  Detailed information about a given channel\n";
14745       return NULL;
14746    case CLI_GENERATE:
14747       return NULL;
14748    }
14749 
14750    lock = &iflock;
14751    start = iflist;
14752 
14753    if (a->argc != 4)
14754       return CLI_SHOWUSAGE;
14755 #ifdef HAVE_PRI
14756    if ((c = strchr(a->argv[3], ':'))) {
14757       if (sscanf(a->argv[3], "%30d:%30d", &trunkgroup, &channel) != 2)
14758          return CLI_SHOWUSAGE;
14759       if ((trunkgroup < 1) || (channel < 1))
14760          return CLI_SHOWUSAGE;
14761       for (x = 0; x < NUM_SPANS; x++) {
14762          if (pris[x].trunkgroup == trunkgroup) {
14763             pri = pris + x;
14764             break;
14765          }
14766       }
14767       if (pri) {
14768          start = pri->crvs;
14769          lock = &pri->lock;
14770       } else {
14771          ast_cli(a->fd, "No such trunk group %d\n", trunkgroup);
14772          return CLI_FAILURE;
14773       }
14774    } else
14775 #endif
14776       channel = atoi(a->argv[3]);
14777 
14778    ast_mutex_lock(lock);
14779    tmp = start;
14780    while (tmp) {
14781       if (tmp->channel == channel) {
14782 #ifdef HAVE_PRI
14783          if (pri)
14784             ast_cli(a->fd, "Trunk/CRV: %d/%d\n", trunkgroup, tmp->channel);
14785          else
14786 #endif
14787          ast_cli(a->fd, "Channel: %d\n", tmp->channel);
14788          ast_cli(a->fd, "File Descriptor: %d\n", tmp->subs[SUB_REAL].dfd);
14789          ast_cli(a->fd, "Span: %d\n", tmp->span);
14790          ast_cli(a->fd, "Extension: %s\n", tmp->exten);
14791          ast_cli(a->fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no");
14792          ast_cli(a->fd, "Context: %s\n", tmp->context);
14793          ast_cli(a->fd, "Caller ID: %s\n", tmp->cid_num);
14794          ast_cli(a->fd, "Calling TON: %d\n", tmp->cid_ton);
14795          ast_cli(a->fd, "Caller ID name: %s\n", tmp->cid_name);
14796          ast_cli(a->fd, "Mailbox: %s\n", S_OR(tmp->mailbox, "none"));
14797          if (tmp->vars) {
14798             struct ast_variable *v;
14799             ast_cli(a->fd, "Variables:\n");
14800             for (v = tmp->vars ; v ; v = v->next)
14801                ast_cli(a->fd, "       %s = %s\n", v->name, v->value);
14802          }
14803          ast_cli(a->fd, "Destroy: %d\n", tmp->destroy);
14804          ast_cli(a->fd, "InAlarm: %d\n", tmp->inalarm);
14805          ast_cli(a->fd, "Signalling Type: %s\n", sig2str(tmp->sig));
14806          ast_cli(a->fd, "Radio: %d\n", tmp->radio);
14807          ast_cli(a->fd, "Owner: %s\n", tmp->owner ? tmp->owner->name : "<None>");
14808          ast_cli(a->fd, "Real: %s%s%s\n", tmp->subs[SUB_REAL].owner ? tmp->subs[SUB_REAL].owner->name : "<None>", tmp->subs[SUB_REAL].inthreeway ? " (Confed)" : "", tmp->subs[SUB_REAL].linear ? " (Linear)" : "");
14809          ast_cli(a->fd, "Callwait: %s%s%s\n", tmp->subs[SUB_CALLWAIT].owner ? tmp->subs[SUB_CALLWAIT].owner->name : "<None>", tmp->subs[SUB_CALLWAIT].inthreeway ? " (Confed)" : "", tmp->subs[SUB_CALLWAIT].linear ? " (Linear)" : "");
14810          ast_cli(a->fd, "Threeway: %s%s%s\n", tmp->subs[SUB_THREEWAY].owner ? tmp->subs[SUB_THREEWAY].owner->name : "<None>", tmp->subs[SUB_THREEWAY].inthreeway ? " (Confed)" : "", tmp->subs[SUB_THREEWAY].linear ? " (Linear)" : "");
14811          ast_cli(a->fd, "Confno: %d\n", tmp->confno);
14812          ast_cli(a->fd, "Propagated Conference: %d\n", tmp->propconfno);
14813          ast_cli(a->fd, "Real in conference: %d\n", tmp->inconference);
14814          ast_cli(a->fd, "DSP: %s\n", tmp->dsp ? "yes" : "no");
14815          ast_cli(a->fd, "Busy Detection: %s\n", tmp->busydetect ? "yes" : "no");
14816          if (tmp->busydetect) {
14817 #if defined(BUSYDETECT_TONEONLY)
14818             ast_cli(a->fd, "    Busy Detector Helper: BUSYDETECT_TONEONLY\n");
14819 #elif defined(BUSYDETECT_COMPARE_TONE_AND_SILENCE)
14820             ast_cli(a->fd, "    Busy Detector Helper: BUSYDETECT_COMPARE_TONE_AND_SILENCE\n");
14821 #endif
14822 #ifdef BUSYDETECT_DEBUG
14823             ast_cli(a->fd, "    Busy Detector Debug: Enabled\n");
14824 #endif
14825             ast_cli(a->fd, "    Busy Count: %d\n", tmp->busycount);
14826             ast_cli(a->fd, "    Busy Pattern: %d,%d\n", tmp->busy_tonelength, tmp->busy_quietlength);
14827          }
14828          ast_cli(a->fd, "TDD: %s\n", tmp->tdd ? "yes" : "no");
14829          ast_cli(a->fd, "Relax DTMF: %s\n", tmp->dtmfrelax ? "yes" : "no");
14830          ast_cli(a->fd, "Dialing/CallwaitCAS: %d/%d\n", tmp->dialing, tmp->callwaitcas);
14831          ast_cli(a->fd, "Default law: %s\n", tmp->law == DAHDI_LAW_MULAW ? "ulaw" : tmp->law == DAHDI_LAW_ALAW ? "alaw" : "unknown");
14832          ast_cli(a->fd, "Fax Handled: %s\n", tmp->faxhandled ? "yes" : "no");
14833          ast_cli(a->fd, "Pulse phone: %s\n", tmp->pulsedial ? "yes" : "no");
14834          ast_cli(a->fd, "DND: %s\n", tmp->dnd ? "yes" : "no");
14835          ast_cli(a->fd, "Echo Cancellation:\n");
14836 
14837          if (tmp->echocancel.head.tap_length) {
14838             ast_cli(a->fd, "\t%d taps\n", tmp->echocancel.head.tap_length);
14839             for (x = 0; x < tmp->echocancel.head.param_count; x++) {
14840                ast_cli(a->fd, "\t\t%s: %ud\n", tmp->echocancel.params[x].name, tmp->echocancel.params[x].value);
14841             }
14842             ast_cli(a->fd, "\t%scurrently %s\n", tmp->echocanbridged ? "" : "(unless TDM bridged) ", tmp->echocanon ? "ON" : "OFF");
14843          } else {
14844             ast_cli(a->fd, "\tnone\n");
14845          }
14846          ast_cli(a->fd, "Wait for dialtone: %dms\n", tmp->waitfordialtone);
14847          if (tmp->master)
14848             ast_cli(a->fd, "Master Channel: %d\n", tmp->master->channel);
14849          for (x = 0; x < MAX_SLAVES; x++) {
14850             if (tmp->slaves[x])
14851                ast_cli(a->fd, "Slave Channel: %d\n", tmp->slaves[x]->channel);
14852          }
14853 #ifdef HAVE_OPENR2
14854          if (tmp->mfcr2) {
14855             char calldir[OR2_MAX_PATH];
14856             openr2_context_t *r2context = openr2_chan_get_context(tmp->r2chan);
14857             openr2_variant_t r2variant = openr2_context_get_variant(r2context);
14858             ast_cli(a->fd, "MFC/R2 MF State: %s\n", openr2_chan_get_mf_state_string(tmp->r2chan));
14859             ast_cli(a->fd, "MFC/R2 MF Group: %s\n", openr2_chan_get_mf_group_string(tmp->r2chan));
14860             ast_cli(a->fd, "MFC/R2 State: %s\n", openr2_chan_get_r2_state_string(tmp->r2chan));
14861             ast_cli(a->fd, "MFC/R2 Call State: %s\n", openr2_chan_get_call_state_string(tmp->r2chan));
14862             ast_cli(a->fd, "MFC/R2 Call Files Enabled: %s\n", openr2_chan_get_call_files_enabled(tmp->r2chan) ? "Yes" : "No");
14863             ast_cli(a->fd, "MFC/R2 Variant: %s\n", openr2_proto_get_variant_string(r2variant));
14864             ast_cli(a->fd, "MFC/R2 Max ANI: %d\n", openr2_context_get_max_ani(r2context));
14865             ast_cli(a->fd, "MFC/R2 Max DNIS: %d\n", openr2_context_get_max_dnis(r2context));
14866             ast_cli(a->fd, "MFC/R2 Get ANI First: %s\n", openr2_context_get_ani_first(r2context) ? "Yes" : "No");
14867 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
14868             ast_cli(a->fd, "MFC/R2 Skip Category Request: %s\n", openr2_context_get_skip_category_request(r2context) ? "Yes" : "No");
14869 #endif
14870             ast_cli(a->fd, "MFC/R2 Immediate Accept: %s\n", openr2_context_get_immediate_accept(r2context) ? "Yes" : "No");
14871             ast_cli(a->fd, "MFC/R2 Accept on Offer: %s\n", tmp->mfcr2_accept_on_offer ? "Yes" : "No");
14872             ast_cli(a->fd, "MFC/R2 Charge Calls: %s\n", tmp->mfcr2_charge_calls ? "Yes" : "No");
14873             ast_cli(a->fd, "MFC/R2 Allow Collect Calls: %s\n", tmp->mfcr2_allow_collect_calls ? "Yes" : "No");
14874             ast_cli(a->fd, "MFC/R2 Forced Release: %s\n", tmp->mfcr2_forced_release ? "Yes" : "No");
14875             ast_cli(a->fd, "MFC/R2 MF Back Timeout: %dms\n", openr2_context_get_mf_back_timeout(r2context));
14876             ast_cli(a->fd, "MFC/R2 R2 Metering Pulse Timeout: %dms\n", openr2_context_get_metering_pulse_timeout(r2context));
14877             ast_cli(a->fd, "MFC/R2 Rx CAS: %s\n", openr2_chan_get_rx_cas_string(tmp->r2chan));
14878             ast_cli(a->fd, "MFC/R2 Tx CAS: %s\n", openr2_chan_get_tx_cas_string(tmp->r2chan));
14879             ast_cli(a->fd, "MFC/R2 MF Tx Signal: %d\n", openr2_chan_get_tx_mf_signal(tmp->r2chan));
14880             ast_cli(a->fd, "MFC/R2 MF Rx Signal: %d\n", openr2_chan_get_rx_mf_signal(tmp->r2chan));
14881             ast_cli(a->fd, "MFC/R2 Call Files Directory: %s\n", openr2_context_get_log_directory(r2context, calldir, sizeof(calldir)));
14882          }
14883 #endif
14884 #ifdef HAVE_SS7
14885          if (tmp->ss7) {
14886             ast_cli(a->fd, "CIC: %d\n", tmp->cic);
14887          }
14888 #endif
14889 #ifdef HAVE_PRI
14890          if (tmp->pri) {
14891             ast_cli(a->fd, "PRI Flags: ");
14892             if (tmp->resetting)
14893                ast_cli(a->fd, "Resetting ");
14894             if (tmp->call)
14895                ast_cli(a->fd, "Call ");
14896             if (tmp->bearer)
14897                ast_cli(a->fd, "Bearer ");
14898             ast_cli(a->fd, "\n");
14899             if (tmp->logicalspan)
14900                ast_cli(a->fd, "PRI Logical Span: %d\n", tmp->logicalspan);
14901             else
14902                ast_cli(a->fd, "PRI Logical Span: Implicit\n");
14903          }
14904 #endif
14905          memset(&ci, 0, sizeof(ci));
14906          ps.channo = tmp->channel;
14907          if (tmp->subs[SUB_REAL].dfd > -1) {
14908             memset(&ci, 0, sizeof(ci));
14909             if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONF, &ci)) {
14910                ast_cli(a->fd, "Actual Confinfo: Num/%d, Mode/0x%04x\n", ci.confno, ci.confmode);
14911             }
14912             if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONFMUTE, &x)) {
14913                ast_cli(a->fd, "Actual Confmute: %s\n", x ? "Yes" : "No");
14914             }
14915             memset(&ps, 0, sizeof(ps));
14916             if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) {
14917                ast_log(LOG_WARNING, "Failed to get parameters on channel %d: %s\n", tmp->channel, strerror(errno));
14918             } else {
14919                ast_cli(a->fd, "Hookstate (FXS only): %s\n", ps.rxisoffhook ? "Offhook" : "Onhook");
14920             }
14921          }
14922          ast_mutex_unlock(lock);
14923          return CLI_SUCCESS;
14924       }
14925       tmp = tmp->next;
14926    }
14927 
14928    ast_cli(a->fd, "Unable to find given channel %d\n", channel);
14929    ast_mutex_unlock(lock);
14930    return CLI_FAILURE;
14931 }

static char* dahdi_show_channels ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14601 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_pvt::context, dahdi_pri::crvs, dahdi_pvt::exten, ast_cli_args::fd, FORMAT, FORMAT2, dahdi_pvt::group, iflist, iflock, dahdi_pvt::language, dahdi_pvt::locallyblocked, dahdi_pri::lock, lock, dahdi_pvt::mohinterpret, dahdi_pvt::next, NUM_SPANS, dahdi_pri::pri, pris, dahdi_pvt::remotelyblocked, and ast_cli_entry::usage.

14602 {
14603 #define FORMAT "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
14604 #define FORMAT2 "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
14605    unsigned int targetnum = 0;
14606    int filtertype = 0;
14607    struct dahdi_pvt *tmp = NULL;
14608    char tmps[20] = "";
14609    char statestr[20] = "";
14610    char blockstr[20] = "";
14611    ast_mutex_t *lock;
14612    struct dahdi_pvt *start;
14613 #ifdef HAVE_PRI
14614    int trunkgroup;
14615    struct dahdi_pri *pri = NULL;
14616    int x;
14617 #endif
14618    switch (cmd) {
14619    case CLI_INIT:
14620       e->command = "dahdi show channels [trunkgroup|group|context]";
14621       e->usage =
14622          "Usage: dahdi show channels [ trunkgroup <trunkgroup> | group <group> | context <context> ]\n"
14623          "  Shows a list of available channels with optional filtering\n"
14624          "  <group> must be a number between 0 and 63\n";
14625       return NULL;
14626    case CLI_GENERATE:
14627       return NULL;
14628    }
14629 
14630    lock = &iflock;
14631    start = iflist;
14632 
14633    /* syntax: dahdi show channels [ group <group> | context <context> | trunkgroup <trunkgroup> ] */
14634 
14635    if (!((a->argc == 3) || (a->argc == 5)))
14636       return CLI_SHOWUSAGE;
14637 
14638    if (a->argc == 5) {
14639 #ifdef HAVE_PRI
14640       if (!strcasecmp(a->argv[3], "trunkgroup")) {
14641          /* this option requires no special handling, so leave filtertype to zero */
14642          if ((trunkgroup = atoi(a->argv[4])) < 1)
14643             return CLI_SHOWUSAGE;
14644          for (x = 0; x < NUM_SPANS; x++) {
14645             if (pris[x].trunkgroup == trunkgroup) {
14646                pri = pris + x;
14647                break;
14648             }
14649          }
14650          if (pri) {
14651             start = pri->crvs;
14652             lock = &pri->lock;
14653          } else {
14654             ast_cli(a->fd, "No such trunk group %d\n", trunkgroup);
14655             return CLI_FAILURE;
14656          }
14657       } else
14658 #endif
14659       if (!strcasecmp(a->argv[3], "group")) {
14660          targetnum = atoi(a->argv[4]);
14661          if ((targetnum < 0) || (targetnum > 63))
14662             return CLI_SHOWUSAGE;
14663          targetnum = 1 << targetnum;
14664          filtertype = 1;
14665       } else if (!strcasecmp(a->argv[3], "context")) {
14666          filtertype = 2;
14667       }
14668    }
14669 
14670    ast_mutex_lock(lock);
14671 #ifdef HAVE_PRI
14672    ast_cli(a->fd, FORMAT2, pri ? "CRV" : "Chan", "Extension", "Context", "Language", "MOH Interpret", "Blocked", "State");
14673 #else
14674    ast_cli(a->fd, FORMAT2, "Chan", "Extension", "Context", "Language", "MOH Interpret", "Blocked", "State");
14675 #endif
14676 
14677    tmp = start;
14678    while (tmp) {
14679       if (filtertype) {
14680          switch(filtertype) {
14681          case 1: /* dahdi show channels group <group> */
14682             if (!(tmp->group & targetnum)) {
14683                tmp = tmp->next;
14684                continue;
14685             }
14686             break;
14687          case 2: /* dahdi show channels context <context> */
14688             if (strcasecmp(tmp->context, a->argv[4])) {
14689                tmp = tmp->next;
14690                continue;
14691             }
14692             break;
14693          default:
14694             ;
14695          }
14696       }
14697       if (tmp->channel > 0) {
14698          snprintf(tmps, sizeof(tmps), "%d", tmp->channel);
14699       } else
14700          ast_copy_string(tmps, "pseudo", sizeof(tmps));
14701 
14702       if (tmp->locallyblocked)
14703          blockstr[0] = 'L';
14704       else
14705          blockstr[0] = ' ';
14706 
14707       if (tmp->remotelyblocked)
14708          blockstr[1] = 'R';
14709       else
14710          blockstr[1] = ' ';
14711 
14712       blockstr[2] = '\0';
14713 
14714       snprintf(statestr, sizeof(statestr), "%s", "In Service");
14715 
14716       ast_cli(a->fd, FORMAT, tmps, tmp->exten, tmp->context, tmp->language, tmp->mohinterpret, blockstr, statestr);
14717       tmp = tmp->next;
14718    }
14719    ast_mutex_unlock(lock);
14720    return CLI_SUCCESS;
14721 #undef FORMAT
14722 #undef FORMAT2
14723 }

static char* dahdi_show_status ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14970 of file chan_dahdi.c.

References ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, errno, ast_cli_args::fd, FORMAT, FORMAT2, and ast_cli_entry::usage.

14971 {
14972    #define FORMAT "%-40.40s %-7.7s %-6d %-6d %-6d %-3.3s %-4.4s %-8.8s %s\n"
14973    #define FORMAT2 "%-40.40s %-7.7s %-6.6s %-6.6s %-6.6s %-3.3s %-4.4s %-8.8s %s\n"
14974    int span;
14975    int res;
14976    char alarmstr[50];
14977 
14978    int ctl;
14979    struct dahdi_spaninfo s;
14980 
14981    switch (cmd) {
14982    case CLI_INIT:
14983       e->command = "dahdi show status";
14984       e->usage =
14985          "Usage: dahdi show status\n"
14986          "       Shows a list of DAHDI cards with status\n";
14987       return NULL;
14988    case CLI_GENERATE:
14989       return NULL;
14990    }
14991    ctl = open("/dev/dahdi/ctl", O_RDWR);
14992    if (ctl < 0) {
14993       ast_cli(a->fd, "No DAHDI found. Unable to open /dev/dahdi/ctl: %s\n", strerror(errno));
14994       return CLI_FAILURE;
14995    }
14996    ast_cli(a->fd, FORMAT2, "Description", "Alarms", "IRQ", "bpviol", "CRC4", "Framing", "Coding", "Options", "LBO");
14997 
14998    for (span = 1; span < DAHDI_MAX_SPANS; ++span) {
14999       s.spanno = span;
15000       res = ioctl(ctl, DAHDI_SPANSTAT, &s);
15001       if (res) {
15002          continue;
15003       }
15004       alarmstr[0] = '\0';
15005       if (s.alarms > 0) {
15006          if (s.alarms & DAHDI_ALARM_BLUE)
15007             strcat(alarmstr, "BLU/");
15008          if (s.alarms & DAHDI_ALARM_YELLOW)
15009             strcat(alarmstr, "YEL/");
15010          if (s.alarms & DAHDI_ALARM_RED)
15011             strcat(alarmstr, "RED/");
15012          if (s.alarms & DAHDI_ALARM_LOOPBACK)
15013             strcat(alarmstr, "LB/");
15014          if (s.alarms & DAHDI_ALARM_RECOVER)
15015             strcat(alarmstr, "REC/");
15016          if (s.alarms & DAHDI_ALARM_NOTOPEN)
15017             strcat(alarmstr, "NOP/");
15018          if (!strlen(alarmstr))
15019             strcat(alarmstr, "UUU/");
15020          if (strlen(alarmstr)) {
15021             /* Strip trailing / */
15022             alarmstr[strlen(alarmstr) - 1] = '\0';
15023          }
15024       } else {
15025          if (s.numchans)
15026             strcpy(alarmstr, "OK");
15027          else
15028             strcpy(alarmstr, "UNCONFIGURED");
15029       }
15030 
15031       ast_cli(a->fd, FORMAT, s.desc, alarmstr, s.irqmisses, s.bpvcount, s.crc4count,
15032          s.lineconfig & DAHDI_CONFIG_D4 ? "D4" :
15033          s.lineconfig & DAHDI_CONFIG_ESF ? "ESF" :
15034          s.lineconfig & DAHDI_CONFIG_CCS ? "CCS" :
15035          "CAS",
15036          s.lineconfig & DAHDI_CONFIG_B8ZS ? "B8ZS" :
15037          s.lineconfig & DAHDI_CONFIG_HDB3 ? "HDB3" :
15038          s.lineconfig & DAHDI_CONFIG_AMI ? "AMI" :
15039          "Unk",
15040          s.lineconfig & DAHDI_CONFIG_CRC4 ?
15041             s.lineconfig & DAHDI_CONFIG_NOTOPEN ? "CRC4/YEL" : "CRC4" :
15042             s.lineconfig & DAHDI_CONFIG_NOTOPEN ? "YEL" : "",
15043          lbostr[s.lbo]
15044          );
15045    }
15046    close(ctl);
15047 
15048    return CLI_SUCCESS;
15049 #undef FORMAT
15050 #undef FORMAT2
15051 }

static char* dahdi_show_version ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15053 of file chan_dahdi.c.

References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, errno, ast_cli_args::fd, and ast_cli_entry::usage.

15054 {
15055    int pseudo_fd = -1;
15056    struct dahdi_versioninfo vi;
15057 
15058    switch (cmd) {
15059    case CLI_INIT:
15060       e->command = "dahdi show version";
15061       e->usage =
15062          "Usage: dahdi show version\n"
15063          "       Shows the DAHDI version in use\n";
15064       return NULL;
15065    case CLI_GENERATE:
15066       return NULL;
15067    }
15068    if ((pseudo_fd = open("/dev/dahdi/ctl", O_RDONLY)) < 0) {
15069       ast_cli(a->fd, "Failed to open control file to get version.\n");
15070       return CLI_SUCCESS;
15071    }
15072 
15073    strcpy(vi.version, "Unknown");
15074    strcpy(vi.echo_canceller, "Unknown");
15075 
15076    if (ioctl(pseudo_fd, DAHDI_GETVERSION, &vi))
15077       ast_cli(a->fd, "Failed to get DAHDI version: %s\n", strerror(errno));
15078    else
15079       ast_cli(a->fd, "DAHDI Version: %s Echo Canceller: %s\n", vi.version, vi.echo_canceller);
15080 
15081    close(pseudo_fd);
15082 
15083    return CLI_SUCCESS;
15084 }

static char* dahdi_sig2str ( int  sig  )  [static]

Definition at line 2410 of file chan_dahdi.c.

References buf, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_GR303FXOKS, SIG_GR303FXSKS, SIG_MFCR2, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SF_FEATD, SIG_SF_FEATDMF, SIG_SFWINK, and SIG_SS7.

02411 {
02412    static char buf[256];
02413    switch (sig) {
02414    case SIG_EM:
02415       return "E & M Immediate";
02416    case SIG_EMWINK:
02417       return "E & M Wink";
02418    case SIG_EM_E1:
02419       return "E & M E1";
02420    case SIG_FEATD:
02421       return "Feature Group D (DTMF)";
02422    case SIG_FEATDMF:
02423       return "Feature Group D (MF)";
02424    case SIG_FEATDMF_TA:
02425       return "Feature Groud D (MF) Tandem Access";
02426    case SIG_FEATB:
02427       return "Feature Group B (MF)";
02428    case SIG_E911:
02429       return "E911 (MF)";
02430    case SIG_FGC_CAMA:
02431       return "FGC/CAMA (Dialpulse)";
02432    case SIG_FGC_CAMAMF:
02433       return "FGC/CAMA (MF)";
02434    case SIG_FXSLS:
02435       return "FXS Loopstart";
02436    case SIG_FXSGS:
02437       return "FXS Groundstart";
02438    case SIG_FXSKS:
02439       return "FXS Kewlstart";
02440    case SIG_FXOLS:
02441       return "FXO Loopstart";
02442    case SIG_FXOGS:
02443       return "FXO Groundstart";
02444    case SIG_FXOKS:
02445       return "FXO Kewlstart";
02446    case SIG_PRI:
02447       return "ISDN PRI";
02448    case SIG_BRI:
02449       return "ISDN BRI Point to Point";
02450    case SIG_BRI_PTMP:
02451       return "ISDN BRI Point to MultiPoint";
02452    case SIG_SS7:
02453       return "SS7";
02454    case SIG_MFCR2:
02455       return "MFC/R2";
02456    case SIG_SF:
02457       return "SF (Tone) Immediate";
02458    case SIG_SFWINK:
02459       return "SF (Tone) Wink";
02460    case SIG_SF_FEATD:
02461       return "SF (Tone) with Feature Group D (DTMF)";
02462    case SIG_SF_FEATDMF:
02463       return "SF (Tone) with Feature Group D (MF)";
02464    case SIG_SF_FEATB:
02465       return "SF (Tone) with Feature Group B (MF)";
02466    case SIG_GR303FXOKS:
02467       return "GR-303 with FXOKS";
02468    case SIG_GR303FXSKS:
02469       return "GR-303 with FXSKS";
02470    case 0:
02471       return "Pseudo";
02472    default:
02473       snprintf(buf, sizeof(buf), "Unknown signalling %d", sig);
02474       return buf;
02475    }
02476 }

static void dahdi_softhangup_all ( void   )  [static]

Definition at line 14425 of file chan_dahdi.c.

References ast_channel_trylock, ast_channel_unlock, ast_mutex_lock(), ast_mutex_unlock(), AST_SOFTHANGUP_EXPLICIT, ast_softhangup_nolock(), ast_verbose, iflist, iflock, dahdi_pvt::lock, ast_channel::name, dahdi_pvt::next, option_debug, dahdi_pvt::owner, and dahdi_pvt::restartpending.

Referenced by dahdi_restart().

14426 {
14427    struct dahdi_pvt *p;
14428 retry:
14429    ast_mutex_lock(&iflock);
14430    for (p = iflist; p; p = p->next) {
14431       ast_mutex_lock(&p->lock);
14432       if (p->owner && !p->restartpending) {
14433          if (ast_channel_trylock(p->owner)) {
14434             if (option_debug > 2)
14435                ast_verbose("Avoiding deadlock\n");
14436             /* Avoid deadlock since you're not supposed to lock iflock or pvt before a channel */
14437             ast_mutex_unlock(&p->lock);
14438             ast_mutex_unlock(&iflock);
14439             goto retry;
14440          }
14441          if (option_debug > 2)
14442             ast_verbose("Softhanging up on %s\n", p->owner->name);
14443          ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_EXPLICIT);
14444          p->restartpending = 1;
14445          num_restart_pending++;
14446          ast_channel_unlock(p->owner);
14447       }
14448       ast_mutex_unlock(&p->lock);
14449    }
14450    ast_mutex_unlock(&iflock);
14451 }

static void dahdi_ss7_error ( struct ss7 *  ss7,
char *  s 
) [static]

Definition at line 12055 of file chan_dahdi.c.

References ast_log(), linksets, LOG_ERROR, and NUM_SPANS.

Referenced by dahdi_restart(), and load_module().

12056 {
12057 #if 0
12058    int i;
12059 
12060    for (i = 0; i < NUM_SPANS; i++)
12061       if (linksets[i].ss7 == ss7)
12062          break;
12063 
12064 #else
12065    ast_log(LOG_ERROR, "%s", s);
12066 #endif
12067 }

static void dahdi_ss7_message ( struct ss7 *  ss7,
char *  s 
) [static]

Definition at line 12038 of file chan_dahdi.c.

References ast_verbose, linksets, and NUM_SPANS.

Referenced by dahdi_restart(), and load_module().

12039 {
12040 #if 0
12041    int i;
12042 
12043    for (i = 0; i < NUM_SPANS; i++)
12044       if (linksets[i].ss7 == ss7)
12045          break;
12046 
12047    ast_verbose("[%d] %s", i+1, s);
12048 #else
12049    ast_verbose("%s", s);
12050 #endif
12051 }

static void dahdi_train_ec ( struct dahdi_pvt *  p  )  [static]

Definition at line 2694 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_pvt::channel, dahdi_subchannel::dfd, dahdi_pvt::echocanon, dahdi_pvt::echotraining, errno, LOG_WARNING, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_answer(), and dahdi_handle_event().

02695 {
02696    int x;
02697    int res;
02698 
02699    if (p && p->echocanon && p->echotraining) {
02700       x = p->echotraining;
02701       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_ECHOTRAIN, &x);
02702       if (res)
02703          ast_log(LOG_WARNING, "Unable to request echo training on channel %d: %s\n", p->channel, strerror(errno));
02704       else
02705          ast_debug(1, "Engaged echo training on channel %d\n", p->channel);
02706    } else {
02707       ast_debug(1, "No echo training requested\n");
02708    }
02709 }

static void dahdi_unlink ( struct dahdi_pvt *  slave,
struct dahdi_pvt *  master,
int  needlock 
) [static]

Definition at line 5118 of file chan_dahdi.c.

References ast_debug, ast_mutex_lock(), ast_mutex_trylock(), ast_mutex_unlock(), dahdi_pvt::channel, conf_del(), DEADLOCK_AVOIDANCE, dahdi_pvt::inconference, dahdi_pvt::lock, dahdi_pvt::master, MAX_SLAVES, dahdi_pvt::slaves, SUB_REAL, dahdi_pvt::subs, and update_conf().

Referenced by dahdi_bridge(), and dahdi_fixup().

05119 {
05120    /* Unlink a specific slave or all slaves/masters from a given master */
05121    int x;
05122    int hasslaves;
05123    if (!master)
05124       return;
05125    if (needlock) {
05126       ast_mutex_lock(&master->lock);
05127       if (slave) {
05128          while (ast_mutex_trylock(&slave->lock)) {
05129             DEADLOCK_AVOIDANCE(&master->lock);
05130          }
05131       }
05132    }
05133    hasslaves = 0;
05134    for (x = 0; x < MAX_SLAVES; x++) {
05135       if (master->slaves[x]) {
05136          if (!slave || (master->slaves[x] == slave)) {
05137             /* Take slave out of the conference */
05138             ast_debug(1, "Unlinking slave %d from %d\n", master->slaves[x]->channel, master->channel);
05139             conf_del(master, &master->slaves[x]->subs[SUB_REAL], SUB_REAL);
05140             conf_del(master->slaves[x], &master->subs[SUB_REAL], SUB_REAL);
05141             master->slaves[x]->master = NULL;
05142             master->slaves[x] = NULL;
05143          } else
05144             hasslaves = 1;
05145       }
05146       if (!hasslaves)
05147          master->inconference = 0;
05148    }
05149    if (!slave) {
05150       if (master->master) {
05151          /* Take master out of the conference */
05152          conf_del(master->master, &master->subs[SUB_REAL], SUB_REAL);
05153          conf_del(master, &master->master->subs[SUB_REAL], SUB_REAL);
05154          hasslaves = 0;
05155          for (x = 0; x < MAX_SLAVES; x++) {
05156             if (master->master->slaves[x] == master)
05157                master->master->slaves[x] = NULL;
05158             else if (master->master->slaves[x])
05159                hasslaves = 1;
05160          }
05161          if (!hasslaves)
05162             master->master->inconference = 0;
05163       }
05164       master->master = NULL;
05165    }
05166    update_conf(master);
05167    if (needlock) {
05168       if (slave)
05169          ast_mutex_unlock(&slave->lock);
05170       ast_mutex_unlock(&master->lock);
05171    }
05172 }

static int dahdi_wait_event ( int  fd  )  [inline, static]

Avoid the silly dahdi_waitevent which ignores a bunch of events.

Definition at line 385 of file chan_dahdi.c.

Referenced by ss_thread().

00386 {
00387    int i, j = 0;
00388    i = DAHDI_IOMUX_SIGEVENT;
00389    if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
00390       return -1;
00391    if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
00392       return -1;
00393    return j;
00394 }

static int dahdi_wink ( struct dahdi_pvt *  p,
int  idx 
) [static]

Definition at line 7712 of file chan_dahdi.c.

References dahdi_set_hook(), dahdi_subchannel::dfd, and dahdi_pvt::subs.

Referenced by ss_thread().

07713 {
07714    int j;
07715    dahdi_set_hook(p->subs[idx].dfd, DAHDI_WINK);
07716    for (;;)
07717    {
07718       /* set bits of interest */
07719       j = DAHDI_IOMUX_SIGEVENT;
07720       /* wait for some happening */
07721       if (ioctl(p->subs[idx].dfd,DAHDI_IOMUX,&j) == -1) return(-1);
07722       /* exit loop if we have it */
07723       if (j & DAHDI_IOMUX_SIGEVENT) break;
07724    }
07725    /* get the event info */
07726    if (ioctl(p->subs[idx].dfd,DAHDI_GETEVENT,&j) == -1) return(-1);
07727    return 0;
07728 }

static int dahdi_write ( struct ast_channel *  ast,
struct ast_frame *  frame 
) [static]

Definition at line 7167 of file chan_dahdi.c.

References ast_debug, AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, AST_FRAME_IMAGE, AST_FRAME_VOICE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::call, dahdi_pvt::channel, dahdi_pvt::cidspill, dahdi_get_index(), dahdi_setlinear(), ast_frame::data, ast_frame::datalen, dahdi_subchannel::dfd, dahdi_pvt::dialing, dahdi_pvt::digital, errno, ast_frame::frametype, dahdi_subchannel::linear, dahdi_pvt::lock, LOG_WARNING, my_dahdi_write(), ast_channel::name, dahdi_pvt::outgoing, dahdi_pvt::owner, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), dahdi_pvt::proceeding, ast_frame::ptr, PVT_TO_CHANNEL, dahdi_pvt::sig, SIG_PRI, dahdi_pvt::span, ast_frame::subclass, dahdi_pvt::subs, and ast_channel::tech_pvt.

07168 {
07169    struct dahdi_pvt *p = ast->tech_pvt;
07170    int res;
07171    int idx;
07172    idx = dahdi_get_index(ast, p, 0);
07173    if (idx < 0) {
07174       ast_log(LOG_WARNING, "%s doesn't really exist?\n", ast->name);
07175       return -1;
07176    }
07177 
07178 #if 0
07179 #ifdef HAVE_PRI
07180    ast_mutex_lock(&p->lock);
07181    if (!p->proceeding && p->sig==SIG_PRI && p->pri && !p->outgoing) {
07182       if (p->pri->pri) {
07183          if (!pri_grab(p, p->pri)) {
07184                pri_progress(p->pri->pri,p->call, PVT_TO_CHANNEL(p), !p->digital);
07185                pri_rel(p->pri);
07186          } else
07187                ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07188       }
07189       p->proceeding=1;
07190    }
07191    ast_mutex_unlock(&p->lock);
07192 #endif
07193 #endif
07194    /* Write a frame of (presumably voice) data */
07195    if (frame->frametype != AST_FRAME_VOICE) {
07196       if (frame->frametype != AST_FRAME_IMAGE)
07197          ast_log(LOG_WARNING, "Don't know what to do with frame type '%d'\n", frame->frametype);
07198       return 0;
07199    }
07200    if ((frame->subclass != AST_FORMAT_SLINEAR) &&
07201       (frame->subclass != AST_FORMAT_ULAW) &&
07202       (frame->subclass != AST_FORMAT_ALAW)) {
07203       ast_log(LOG_WARNING, "Cannot handle frames in %d format\n", frame->subclass);
07204       return -1;
07205    }
07206    if (p->dialing) {
07207       ast_debug(1, "Dropping frame since I'm still dialing on %s...\n",ast->name);
07208       return 0;
07209    }
07210    if (!p->owner) {
07211       ast_debug(1, "Dropping frame since there is no active owner on %s...\n",ast->name);
07212       return 0;
07213    }
07214    if (p->cidspill) {
07215       ast_debug(1, "Dropping frame since I've still got a callerid spill\n");
07216       return 0;
07217    }
07218    /* Return if it's not valid data */
07219    if (!frame->data.ptr || !frame->datalen)
07220       return 0;
07221 
07222    if (frame->subclass == AST_FORMAT_SLINEAR) {
07223       if (!p->subs[idx].linear) {
07224          p->subs[idx].linear = 1;
07225          res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
07226          if (res)
07227             ast_log(LOG_WARNING, "Unable to set linear mode on channel %d\n", p->channel);
07228       }
07229       res = my_dahdi_write(p, (unsigned char *)frame->data.ptr, frame->datalen, idx, 1);
07230    } else {
07231       /* x-law already */
07232       if (p->subs[idx].linear) {
07233          p->subs[idx].linear = 0;
07234          res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
07235          if (res)
07236             ast_log(LOG_WARNING, "Unable to set companded mode on channel %d\n", p->channel);
07237       }
07238       res = my_dahdi_write(p, (unsigned char *)frame->data.ptr, frame->datalen, idx, 0);
07239    }
07240    if (res < 0) {
07241       ast_log(LOG_WARNING, "write failed: %s\n", strerror(errno));
07242       return -1;
07243    }
07244    return 0;
07245 }

static void destroy_all_channels ( void   )  [static]

Definition at line 3931 of file chan_dahdi.c.

References ast_free, ast_mutex_lock(), ast_mutex_unlock(), ast_verbose, dahdi_pvt::channel, dahdi_pvt::cidspill, destroy_dahdi_pvt(), iflist, iflock, dahdi_pvt::next, option_verbose, and VERBOSE_PREFIX_2.

Referenced by __unload_module(), and dahdi_restart().

03932 {
03933    int x;
03934    struct dahdi_pvt *p, *pl;
03935 
03936    while (num_restart_pending) {
03937       usleep(1);
03938    }
03939 
03940    ast_mutex_lock(&iflock);
03941    /* Destroy all the interfaces and free their memory */
03942    p = iflist;
03943    while (p) {
03944       /* Free any callerid */
03945       if (p->cidspill)
03946          ast_free(p->cidspill);
03947       pl = p;
03948       p = p->next;
03949       x = pl->channel;
03950       /* Free associated memory */
03951       if (pl)
03952          destroy_dahdi_pvt(&pl);
03953       if (option_verbose > 2)
03954          ast_verbose(VERBOSE_PREFIX_2 "Unregistered channel %d\n", x);
03955    }
03956    iflist = NULL;
03957    ifcount = 0;
03958    ast_mutex_unlock(&iflock);
03959 }

static int destroy_channel ( struct dahdi_pvt *  prev,
struct dahdi_pvt *  cur,
int  now 
) [static]

Definition at line 3881 of file chan_dahdi.c.

References destroy_dahdi_pvt(), iflist, dahdi_pvt::next, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::prev, and dahdi_pvt::subs.

Referenced by dahdi_destroy_channel_bynum(), and dahdi_hangup().

03882 {
03883    int owned = 0;
03884    int i = 0;
03885 
03886    if (!now) {
03887       if (cur->owner) {
03888          owned = 1;
03889       }
03890 
03891       for (i = 0; i < 3; i++) {
03892          if (cur->subs[i].owner) {
03893             owned = 1;
03894          }
03895       }
03896       if (!owned) {
03897          if (prev) {
03898             prev->next = cur->next;
03899             if (prev->next)
03900                prev->next->prev = prev;
03901             else
03902                ifend = prev;
03903          } else {
03904             iflist = cur->next;
03905             if (iflist)
03906                iflist->prev = NULL;
03907             else
03908                ifend = NULL;
03909          }
03910          destroy_dahdi_pvt(&cur);
03911       }
03912    } else {
03913       if (prev) {
03914          prev->next = cur->next;
03915          if (prev->next)
03916             prev->next->prev = prev;
03917          else
03918             ifend = prev;
03919       } else {
03920          iflist = cur->next;
03921          if (iflist)
03922             iflist->prev = NULL;
03923          else
03924             ifend = NULL;
03925       }
03926       destroy_dahdi_pvt(&cur);
03927    }
03928    return 0;
03929 }

static void destroy_dahdi_pvt ( struct dahdi_pvt **  pvt  )  [static]

Definition at line 3858 of file chan_dahdi.c.

References ast_event_unsubscribe(), ast_mutex_destroy(), ast_smdi_interface_unref(), ast_variables_destroy(), dahdi_close_sub(), free, dahdi_pvt::lock, dahdi_pvt::mwi_event_sub, dahdi_pvt::next, dahdi_pvt::owner, dahdi_pvt::prev, dahdi_pvt::smdi_iface, SUB_REAL, ast_channel::tech_pvt, dahdi_pvt::use_smdi, and dahdi_pvt::vars.

Referenced by destroy_all_channels(), destroy_channel(), duplicate_pseudo(), and mkintf().

03859 {
03860    struct dahdi_pvt *p = *pvt;
03861    /* Remove channel from the list */
03862    if (p->prev)
03863       p->prev->next = p->next;
03864    if (p->next)
03865       p->next->prev = p->prev;
03866    if (p->use_smdi)
03867       ast_smdi_interface_unref(p->smdi_iface);
03868    if (p->mwi_event_sub)
03869       ast_event_unsubscribe(p->mwi_event_sub);
03870    if (p->vars) {
03871       ast_variables_destroy(p->vars);
03872    }
03873    ast_mutex_destroy(&p->lock);
03874    dahdi_close_sub(p, SUB_REAL);
03875    if (p->owner)
03876       p->owner->tech_pvt = NULL;
03877    free(p);
03878    *pvt = NULL;
03879 }

static char* dialplan2str ( int  dialplan  )  [static]

Definition at line 2401 of file chan_dahdi.c.

Referenced by dahdi_call(), and mkintf().

02402 {
02403    if (dialplan == -1 || dialplan == -2) {
02404       return("Dynamically set dialplan in ISDN");
02405    }
02406    return (pri_plan2str(dialplan));
02407 }

static int digit_to_dtmfindex ( char  digit  )  [static]

Definition at line 2231 of file chan_dahdi.c.

Referenced by dahdi_digit_begin().

02232 {
02233    if (isdigit(digit))
02234       return DAHDI_TONE_DTMF_BASE + (digit - '0');
02235    else if (digit >= 'A' && digit <= 'D')
02236       return DAHDI_TONE_DTMF_A + (digit - 'A');
02237    else if (digit >= 'a' && digit <= 'd')
02238       return DAHDI_TONE_DTMF_A + (digit - 'a');
02239    else if (digit == '*')
02240       return DAHDI_TONE_DTMF_s;
02241    else if (digit == '#')
02242       return DAHDI_TONE_DTMF_p;
02243    else
02244       return -1;
02245 }

static void disable_dtmf_detect ( struct dahdi_pvt *  p  )  [static]

Definition at line 5197 of file chan_dahdi.c.

References ast_dsp_set_features(), dahdi_subchannel::dfd, dahdi_pvt::dsp, DSP_FEATURE_DIGIT_DETECT, dahdi_pvt::dsp_features, dahdi_pvt::hardwaredtmf, dahdi_pvt::ignoredtmf, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_bridge().

05198 {
05199    int val;
05200 
05201    p->ignoredtmf = 1;
05202 
05203    val = 0;
05204    ioctl(p->subs[SUB_REAL].dfd, DAHDI_TONEDETECT, &val);
05205 
05206    if (!p->hardwaredtmf && p->dsp) {
05207       p->dsp_features &= ~DSP_FEATURE_DIGIT_DETECT;
05208       ast_dsp_set_features(p->dsp, p->dsp_features);
05209    }
05210 }

static void* do_idle_thread ( void *  vchan  )  [static]

Definition at line 12278 of file chan_dahdi.c.

References ast_call(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, ast_copy_string(), AST_FRAME_CONTROL, ast_frfree, ast_hangup(), ast_log(), ast_pbx_run(), ast_read(), ast_verb, ast_waitfor(), dahdi_pvt::channel, ast_channel::context, ast_channel::exten, f, ast_frame::frametype, dahdi_pri::idlecontext, dahdi_pri::idledial, dahdi_pri::idleext, LOG_WARNING, ast_channel::name, dahdi_pvt::pri, ast_channel::priority, ast_frame::subclass, and ast_channel::tech_pvt.

Referenced by pri_dchannel().

12279 {
12280    struct ast_channel *chan = vchan;
12281    struct dahdi_pvt *pvt = chan->tech_pvt;
12282    struct ast_frame *f;
12283    char ex[80];
12284    /* Wait up to 30 seconds for an answer */
12285    int newms, ms = 30000;
12286    ast_verb(3, "Initiating idle call on channel %s\n", chan->name);
12287    snprintf(ex, sizeof(ex), "%d/%s", pvt->channel, pvt->pri->idledial);
12288    if (ast_call(chan, ex, 0)) {
12289       ast_log(LOG_WARNING, "Idle dial failed on '%s' to '%s'\n", chan->name, ex);
12290       ast_hangup(chan);
12291       return NULL;
12292    }
12293    while ((newms = ast_waitfor(chan, ms)) > 0) {
12294       f = ast_read(chan);
12295       if (!f) {
12296          /* Got hangup */
12297          break;
12298       }
12299       if (f->frametype == AST_FRAME_CONTROL) {
12300          switch (f->subclass) {
12301          case AST_CONTROL_ANSWER:
12302             /* Launch the PBX */
12303             ast_copy_string(chan->exten, pvt->pri->idleext, sizeof(chan->exten));
12304             ast_copy_string(chan->context, pvt->pri->idlecontext, sizeof(chan->context));
12305             chan->priority = 1;
12306             ast_verb(4, "Idle channel '%s' answered, sending to %s@%s\n", chan->name, chan->exten, chan->context);
12307             ast_pbx_run(chan);
12308             /* It's already hungup, return immediately */
12309             return NULL;
12310          case AST_CONTROL_BUSY:
12311             ast_verb(4, "Idle channel '%s' busy, waiting...\n", chan->name);
12312             break;
12313          case AST_CONTROL_CONGESTION:
12314             ast_verb(4, "Idle channel '%s' congested, waiting...\n", chan->name);
12315             break;
12316          };
12317       }
12318       ast_frfree(f);
12319       ms = newms;
12320    }
12321    /* Hangup the channel since nothing happend */
12322    ast_hangup(chan);
12323    return NULL;
12324 }

static void* do_monitor ( void *  data  )  [static]

Definition at line 9600 of file chan_dahdi.c.

References ast_calloc, ast_debug, ast_fdisset(), ast_free, AST_LAW, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create_background, ast_strlen_zero(), mwi_thread_data::buf, buf, calc_energy(), dahdi_pvt::channel, dahdi_pvt::cidspill, dahdi_destroy_channel_bynum(), dahdi_get_event(), dahdi_subchannel::dfd, errno, event2str(), dahdi_pvt::fxsoffhookstate, handle_init_event(), has_voicemail(), iflist, iflock, last, mwi_thread_data::len, LOG_DEBUG, LOG_WARNING, dahdi_pvt::mailbox, dahdi_pvt::msgstate, mwi_send_init(), mwi_send_process_buffer(), mwi_send_process_event(), mwi_thread(), dahdi_pvt::mwimonitor_fsk, dahdi_pvt::mwimonitoractive, dahdi_pvt::mwisendactive, dahdi_pvt::next, dahdi_pvt::onhooktime, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::pri, mwi_thread_data::pvt, dahdi_pvt::radio, dahdi_pvt::sig, SIG_MFCR2, SUB_REAL, and dahdi_pvt::subs.

Referenced by restart_monitor().

09601 {
09602    int count, res, res2, spoint, pollres=0;
09603    struct dahdi_pvt *i;
09604    struct dahdi_pvt *last = NULL;
09605    struct dahdi_pvt *doomed;
09606    time_t thispass = 0, lastpass = 0;
09607    int found;
09608    char buf[1024];
09609    struct pollfd *pfds=NULL;
09610    int lastalloc = -1;
09611    /* This thread monitors all the frame relay interfaces which are not yet in use
09612       (and thus do not have a separate thread) indefinitely */
09613    /* From here on out, we die whenever asked */
09614 #if 0
09615    if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)) {
09616       ast_log(LOG_WARNING, "Unable to set cancel type to asynchronous\n");
09617       return NULL;
09618    }
09619    ast_debug(1, "Monitor starting...\n");
09620 #endif
09621    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
09622 
09623    for (;;) {
09624       /* Lock the interface list */
09625       ast_mutex_lock(&iflock);
09626       if (!pfds || (lastalloc != ifcount)) {
09627          if (pfds) {
09628             ast_free(pfds);
09629             pfds = NULL;
09630          }
09631          if (ifcount) {
09632             if (!(pfds = ast_calloc(1, ifcount * sizeof(*pfds)))) {
09633                ast_mutex_unlock(&iflock);
09634                return NULL;
09635             }
09636          }
09637          lastalloc = ifcount;
09638       }
09639       /* Build the stuff we're going to poll on, that is the socket of every
09640          dahdi_pvt that does not have an associated owner channel */
09641       count = 0;
09642       i = iflist;
09643       while (i) {
09644          if ((i->subs[SUB_REAL].dfd > -1) && i->sig && (!i->radio) && !(i->sig & SIG_MFCR2)) {
09645             if (!i->owner && !i->subs[SUB_REAL].owner && !i->mwimonitoractive ) {
09646                /* This needs to be watched, as it lacks an owner */
09647                pfds[count].fd = i->subs[SUB_REAL].dfd;
09648                pfds[count].events = POLLPRI;
09649                pfds[count].revents = 0;
09650                /* If we are monitoring for VMWI or sending CID, we need to
09651                   read from the channel as well */
09652                if (i->cidspill || i->mwisendactive || i->mwimonitor_fsk)
09653                   pfds[count].events |= POLLIN;
09654                count++;
09655             }
09656          }
09657          i = i->next;
09658       }
09659       /* Okay, now that we know what to do, release the interface lock */
09660       ast_mutex_unlock(&iflock);
09661 
09662       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
09663       pthread_testcancel();
09664       /* Wait at least a second for something to happen */
09665       res = poll(pfds, count, 1000);
09666       pthread_testcancel();
09667       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
09668 
09669       /* Okay, poll has finished.  Let's see what happened.  */
09670       if (res < 0) {
09671          if ((errno != EAGAIN) && (errno != EINTR))
09672             ast_log(LOG_WARNING, "poll return %d: %s\n", res, strerror(errno));
09673          continue;
09674       }
09675       /* Alright, lock the interface list again, and let's look and see what has
09676          happened */
09677       ast_mutex_lock(&iflock);
09678       found = 0;
09679       spoint = 0;
09680       lastpass = thispass;
09681       thispass = time(NULL);
09682       i = iflist;
09683       doomed = NULL;
09684       for (i = iflist;; i = i->next) {
09685          if (doomed) {
09686             int res;
09687             res = dahdi_destroy_channel_bynum(doomed->channel);
09688             if (!res) {
09689                ast_log(LOG_WARNING, "Couldn't find channel to destroy, hopefully another destroy operation just happened.\n");
09690             }
09691             doomed = NULL;
09692          }
09693          if (!i) {
09694             break;
09695          }
09696 
09697          if (thispass != lastpass) {
09698             if (!found && ((i == last) || ((i == iflist) && !last))) {
09699                last = i;
09700                if (last) {
09701                   /* Only allow MWI to be initiated on a quiescent fxs port */
09702                   if (!last->mwisendactive &&   last->sig & __DAHDI_SIG_FXO &&
09703                         !last->fxsoffhookstate && !last->owner &&
09704                         !ast_strlen_zero(last->mailbox) && (thispass - last->onhooktime > 3)) {
09705                      res = has_voicemail(last);
09706                      if (last->msgstate != res) {
09707                         /* Set driver resources for signalling VMWI */
09708                         res2 = ioctl(last->subs[SUB_REAL].dfd, DAHDI_VMWI, &res);
09709                         if (res2) {
09710                            /* TODO: This message will ALWAYS be generated on some cards; any way to restrict it to those cards where it is interesting? */
09711                            ast_debug(3, "Unable to control message waiting led on channel %d: %s\n", last->channel, strerror(errno));
09712                         }
09713                         /* If enabled for FSK spill then initiate it */
09714                         if (mwi_send_init(last)) {
09715                            ast_log(LOG_WARNING, "Unable to initiate mwi send sequence on channel %d\n", last->channel);
09716                         }
09717                         last->msgstate = res;
09718                         found ++;
09719                      }
09720                   }
09721                   last = last->next;
09722                }
09723             }
09724          }
09725          if ((i->subs[SUB_REAL].dfd > -1) && i->sig) {
09726             if (i->radio && !i->owner)
09727             {
09728                res = dahdi_get_event(i->subs[SUB_REAL].dfd);
09729                if (res)
09730                {
09731                   ast_debug(1, "Monitor doohicky got event %s on radio channel %d\n", event2str(res), i->channel);
09732                   /* Don't hold iflock while handling init events */
09733                   ast_mutex_unlock(&iflock);
09734                   doomed = handle_init_event(i, res);
09735                   ast_mutex_lock(&iflock);
09736                }
09737                continue;
09738             }
09739             pollres = ast_fdisset(pfds, i->subs[SUB_REAL].dfd, count, &spoint);
09740             if (pollres & POLLIN) {
09741                if (i->owner || i->subs[SUB_REAL].owner) {
09742 #ifdef HAVE_PRI
09743                   if (!i->pri)
09744 #endif
09745                      ast_log(LOG_WARNING, "Whoa....  I'm owned but found (%d) in read...\n", i->subs[SUB_REAL].dfd);
09746                   continue;
09747                }
09748                if (!i->mwimonitor_fsk && !i->mwisendactive) {
09749                   ast_log(LOG_WARNING, "Whoa....  I'm not looking for MWI or sending MWI but am reading (%d)...\n", i->subs[SUB_REAL].dfd);
09750                   continue;
09751                }
09752                res = read(i->subs[SUB_REAL].dfd, buf, sizeof(buf));
09753                if (res > 0) {
09754                   if (i->mwimonitor_fsk) {
09755                      if (calc_energy((unsigned char *) buf, res, AST_LAW(i)) > mwilevel) {
09756                         pthread_attr_t attr;
09757                         pthread_t threadid;
09758                         struct mwi_thread_data *mtd;
09759 
09760                         pthread_attr_init(&attr);
09761                         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
09762 
09763                         ast_log(LOG_DEBUG, "Maybe some MWI on port %d!\n", i->channel);
09764                         if ((mtd = ast_calloc(1, sizeof(*mtd)))) {
09765                            mtd->pvt = i;
09766                            memcpy(mtd->buf, buf, res);
09767                            mtd->len = res;
09768                            if (ast_pthread_create_background(&threadid, &attr, mwi_thread, mtd)) {
09769                               ast_log(LOG_WARNING, "Unable to start mwi thread on channel %d\n", i->channel);
09770                               ast_free(mtd);
09771                            }
09772                            i->mwimonitoractive = 1;
09773                         }
09774                      }
09775                   }
09776                   if (i->mwisendactive) {
09777                      mwi_send_process_buffer(i, res);
09778                   }
09779                } else {
09780                   ast_log(LOG_WARNING, "Read failed with %d: %s\n", res, strerror(errno));
09781                }
09782             }
09783             if (pollres & POLLPRI) {
09784                if (i->owner || i->subs[SUB_REAL].owner) {
09785 #ifdef HAVE_PRI
09786                   if (!i->pri)
09787 #endif
09788                      ast_log(LOG_WARNING, "Whoa....  I'm owned but found (%d)...\n", i->subs[SUB_REAL].dfd);
09789                   continue;
09790                }
09791                res = dahdi_get_event(i->subs[SUB_REAL].dfd);
09792                ast_debug(1, "Monitor doohicky got event %s on channel %d\n", event2str(res), i->channel);
09793                /* Don't hold iflock while handling init events */
09794                ast_mutex_unlock(&iflock);
09795                if (0 == i->mwisendactive || 0 == mwi_send_process_event(i, res)) {
09796                   doomed = handle_init_event(i, res);
09797                }
09798                ast_mutex_lock(&iflock);
09799             }
09800          }
09801       }
09802       ast_mutex_unlock(&iflock);
09803    }
09804    /* Never reached */
09805    return NULL;
09806 
09807 }

static struct dahdi_pvt* duplicate_pseudo ( struct dahdi_pvt *  src  )  [static, read]

Definition at line 10887 of file chan_dahdi.c.

References ast_log(), ast_malloc, ast_mutex_init(), dahdi_pvt::buf_no, dahdi_pvt::buf_policy, dahdi_open(), dahdi_pvt::destroy, destroy_dahdi_pvt(), dahdi_subchannel::dfd, errno, iflist, dahdi_pvt::lock, LOG_ERROR, LOG_WARNING, dahdi_pvt::next, dahdi_pvt::prev, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_request().

10888 {
10889    struct dahdi_pvt *p;
10890    struct dahdi_bufferinfo bi;
10891    int res;
10892 
10893    if ((p = ast_malloc(sizeof(*p)))) {
10894       memcpy(p, src, sizeof(struct dahdi_pvt));
10895       ast_mutex_init(&p->lock);
10896       p->subs[SUB_REAL].dfd = dahdi_open("/dev/dahdi/pseudo");
10897       if (p->subs[SUB_REAL].dfd < 0) {
10898          ast_log(LOG_ERROR, "Unable to dup channel: %s\n", strerror(errno));
10899          destroy_dahdi_pvt(&p);
10900          return NULL;
10901       }
10902       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_BUFINFO, &bi);
10903       if (!res) {
10904          bi.txbufpolicy = src->buf_policy;
10905          bi.rxbufpolicy = src->buf_policy;
10906          bi.numbufs = src->buf_no;
10907          res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi);
10908          if (res < 0) {
10909             ast_log(LOG_WARNING, "Unable to set buffer policy on dup channel: %s\n", strerror(errno));
10910          }
10911       } else
10912          ast_log(LOG_WARNING, "Unable to check buffer policy on dup channel: %s\n", strerror(errno));
10913    }
10914    p->destroy = 1;
10915    p->next = iflist;
10916    p->prev = NULL;
10917    iflist = p;
10918    if (iflist->next)
10919       iflist->next->prev = p;
10920    return p;
10921 }

static void enable_dtmf_detect ( struct dahdi_pvt *  p  )  [static]

Definition at line 5212 of file chan_dahdi.c.

References ast_dsp_set_features(), CHAN_PSEUDO, dahdi_pvt::channel, dahdi_subchannel::dfd, dahdi_pvt::dsp, DSP_FEATURE_DIGIT_DETECT, dahdi_pvt::dsp_features, dahdi_pvt::hardwaredtmf, dahdi_pvt::ignoredtmf, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_bridge().

05213 {
05214    int val;
05215 
05216    if (p->channel == CHAN_PSEUDO)
05217       return;
05218 
05219    p->ignoredtmf = 0;
05220 
05221    val = DAHDI_TONEDETECT_ON | DAHDI_TONEDETECT_MUTE;
05222    ioctl(p->subs[SUB_REAL].dfd, DAHDI_TONEDETECT, &val);
05223 
05224    if (!p->hardwaredtmf && p->dsp) {
05225       p->dsp_features |= DSP_FEATURE_DIGIT_DETECT;
05226       ast_dsp_set_features(p->dsp, p->dsp_features);
05227    }
05228 }

static char* event2str ( int  event  )  [static]

Definition at line 2391 of file chan_dahdi.c.

References ARRAY_LEN, and buf.

Referenced by __dahdi_exception(), dahdi_handle_event(), do_monitor(), mwi_thread(), pri_dchannel(), and ss_thread().

02392 {
02393    static char buf[256];
02394    if ((event < (ARRAY_LEN(events))) && (event > -1))
02395       return events[event];
02396    sprintf(buf, "Event %d", event); /* safe */
02397    return buf;
02398 }

static void fill_rxgain ( struct dahdi_gains *  g,
float  gain,
int  law 
) [static]

Definition at line 2763 of file chan_dahdi.c.

References ARRAY_LEN, AST_ALAW, AST_LIN2A, AST_LIN2MU, and AST_MULAW.

Referenced by set_actual_rxgain().

02764 {
02765    int j;
02766    int k;
02767    float linear_gain = pow(10.0, gain / 20.0);
02768 
02769    switch (law) {
02770    case DAHDI_LAW_ALAW:
02771       for (j = 0; j < ARRAY_LEN(g->rxgain); j++) {
02772          if (gain) {
02773             k = (int) (((float) AST_ALAW(j)) * linear_gain);
02774             if (k > 32767) k = 32767;
02775             if (k < -32767) k = -32767;
02776             g->rxgain[j] = AST_LIN2A(k);
02777          } else {
02778             g->rxgain[j] = j;
02779          }
02780       }
02781       break;
02782    case DAHDI_LAW_MULAW:
02783       for (j = 0; j < ARRAY_LEN(g->rxgain); j++) {
02784          if (gain) {
02785             k = (int) (((float) AST_MULAW(j)) * linear_gain);
02786             if (k > 32767) k = 32767;
02787             if (k < -32767) k = -32767;
02788             g->rxgain[j] = AST_LIN2MU(k);
02789          } else {
02790             g->rxgain[j] = j;
02791          }
02792       }
02793       break;
02794    }
02795 }

static void fill_txgain ( struct dahdi_gains *  g,
float  gain,
int  law 
) [static]

Definition at line 2729 of file chan_dahdi.c.

References ARRAY_LEN, AST_ALAW, AST_LIN2A, AST_LIN2MU, and AST_MULAW.

Referenced by set_actual_txgain().

02730 {
02731    int j;
02732    int k;
02733    float linear_gain = pow(10.0, gain / 20.0);
02734 
02735    switch (law) {
02736    case DAHDI_LAW_ALAW:
02737       for (j = 0; j < ARRAY_LEN(g->txgain); j++) {
02738          if (gain) {
02739             k = (int) (((float) AST_ALAW(j)) * linear_gain);
02740             if (k > 32767) k = 32767;
02741             if (k < -32767) k = -32767;
02742             g->txgain[j] = AST_LIN2A(k);
02743          } else {
02744             g->txgain[j] = j;
02745          }
02746       }
02747       break;
02748    case DAHDI_LAW_MULAW:
02749       for (j = 0; j < ARRAY_LEN(g->txgain); j++) {
02750          if (gain) {
02751             k = (int) (((float) AST_MULAW(j)) * linear_gain);
02752             if (k > 32767) k = 32767;
02753             if (k < -32767) k = -32767;
02754             g->txgain[j] = AST_LIN2MU(k);
02755          } else {
02756             g->txgain[j] = j;
02757          }
02758       }
02759       break;
02760    }
02761 }

static struct dahdi_pvt* find_channel ( int  channel  )  [static, read]

Definition at line 15318 of file chan_dahdi.c.

References dahdi_pvt::channel, iflist, and dahdi_pvt::next.

Referenced by action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_transfer(), and action_transferhangup().

15319 {
15320    struct dahdi_pvt *p = iflist;
15321    while (p) {
15322       if (p->channel == channel) {
15323          break;
15324       }
15325       p = p->next;
15326    }
15327    return p;
15328 }

static int get_alarms ( struct dahdi_pvt *  p  )  [static]

Checks channel for alarms

Parameters:
p a channel to check for alarms.
Returns:
the alarms on the span to which the channel belongs, or alarms on the channel if no span alarms.

Definition at line 5656 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::channel, dahdi_subchannel::dfd, errno, LOG_WARNING, dahdi_pvt::span, SUB_REAL, and dahdi_pvt::subs.

Referenced by action_dahdishowchannels(), dahdi_handle_event(), dahdi_r2_on_hardware_alarm(), handle_init_event(), mkintf(), and mwi_thread().

05657 {
05658    int res;
05659    struct dahdi_spaninfo zi;
05660    struct dahdi_params params;
05661 
05662    memset(&zi, 0, sizeof(zi));
05663    zi.spanno = p->span;
05664 
05665    if ((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SPANSTAT, &zi)) >= 0) {
05666       if (zi.alarms != DAHDI_ALARM_NONE)
05667          return zi.alarms;
05668    } else {
05669       ast_log(LOG_WARNING, "Unable to determine alarm on channel %d: %s\n", p->channel, strerror(errno));
05670       return 0;
05671    }
05672 
05673    /* No alarms on the span. Check for channel alarms. */
05674    memset(&params, 0, sizeof(params));
05675    if ((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &params)) >= 0)
05676       return params.chan_alarms;
05677 
05678    ast_log(LOG_WARNING, "Unable to determine alarm on channel %d\n", p->channel);
05679 
05680    return DAHDI_ALARM_NONE;
05681 }

static void handle_alarms ( struct dahdi_pvt *  p,
int  alms 
) [static]

Definition at line 5764 of file chan_dahdi.c.

References alarm2str(), ast_log(), dahdi_pvt::channel, EVENT_FLAG_SYSTEM, LOG_WARNING, and manager_event.

Referenced by dahdi_handle_event(), dahdi_r2_on_hardware_alarm(), handle_init_event(), mkintf(), and mwi_thread().

05765 {
05766    const char *alarm_str = alarm2str(alms);
05767 
05768    ast_log(LOG_WARNING, "Detected alarm on channel %d: %s\n", p->channel, alarm_str);
05769    manager_event(EVENT_FLAG_SYSTEM, "Alarm",
05770       "Alarm: %s\r\n"
05771       "Channel: %d\r\n",
05772       alarm_str, p->channel);
05773 }

static char* handle_dahdi_show_cadences ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14933 of file chan_dahdi.c.

References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, COLOR_BLACK, COLOR_GREEN, COLOR_MAGENTA, ast_cli_entry::command, ast_cli_args::fd, term_color(), and ast_cli_entry::usage.

14934 {
14935    int i, j;
14936    switch (cmd) {
14937    case CLI_INIT:
14938       e->command = "dahdi show cadences";
14939       e->usage =
14940          "Usage: dahdi show cadences\n"
14941          "       Shows all cadences currently defined\n";
14942       return NULL;
14943    case CLI_GENERATE:
14944       return NULL;
14945    }
14946    for (i = 0; i < num_cadence; i++) {
14947       char output[1024];
14948       char tmp[16], tmp2[64];
14949       snprintf(tmp, sizeof(tmp), "r%d: ", i + 1);
14950       term_color(output, tmp, COLOR_GREEN, COLOR_BLACK, sizeof(output));
14951 
14952       for (j = 0; j < 16; j++) {
14953          if (cadences[i].ringcadence[j] == 0)
14954             break;
14955          snprintf(tmp, sizeof(tmp), "%d", cadences[i].ringcadence[j]);
14956          if (cidrings[i] * 2 - 1 == j)
14957             term_color(tmp2, tmp, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp2) - 1);
14958          else
14959             term_color(tmp2, tmp, COLOR_GREEN, COLOR_BLACK, sizeof(tmp2) - 1);
14960          if (j != 0)
14961             strncat(output, ",", sizeof(output) - strlen(output) - 1);
14962          strncat(output, tmp2, sizeof(output) - strlen(output) - 1);
14963       }
14964       ast_cli(a->fd,"%s\n",output);
14965    }
14966    return CLI_SUCCESS;
14967 }

static struct dahdi_pvt * handle_init_event ( struct dahdi_pvt *  i,
int  event 
) [static, read]

Definition at line 9373 of file chan_dahdi.c.

References ast_free, ast_hangup(), ast_log(), ast_pthread_create_detached, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, ast_verb, dahdi_pvt::channel, dahdi_pvt::cid_start, CID_START_POLARITY, CID_START_POLARITY_IN, dahdi_pvt::cidspill, dahdi_disable_ec(), dahdi_enable_ec(), dahdi_new(), dahdi_set_hook(), dahdi_subchannel::dfd, errno, EVENT_FLAG_SYSTEM, dahdi_pvt::fxsoffhookstate, get_alarms(), handle_alarms(), dahdi_pvt::hanguponpolarityswitch, has_voicemail(), dahdi_pvt::immediate, dahdi_pvt::inalarm, LOG_NOTICE, LOG_WARNING, dahdi_pvt::mailbox, manager_event, dahdi_pvt::mwimonitor_neon, notify_message(), dahdi_pvt::polarity, POLARITY_REV, dahdi_pvt::radio, dahdi_pvt::ringt, dahdi_pvt::ringt_base, dahdi_pvt::sig, sig2str, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_GR303FXOKS, SIG_GR303FXSKS, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SF_FEATD, SIG_SF_FEATDMF, SIG_SFWINK, SIG_SS7, ss_thread(), SUB_REAL, and dahdi_pvt::subs.

Referenced by do_monitor().

09374 {
09375    int res;
09376    pthread_t threadid;
09377    struct ast_channel *chan;
09378 
09379    /* Handle an event on a given channel for the monitor thread. */
09380 
09381    switch (event) {
09382    case DAHDI_EVENT_NONE:
09383    case DAHDI_EVENT_BITSCHANGED:
09384       break;
09385    case DAHDI_EVENT_WINKFLASH:
09386    case DAHDI_EVENT_RINGOFFHOOK:
09387       if (i->inalarm) break;
09388       if (i->radio) break;
09389       /* Got a ring/answer.  What kind of channel are we? */
09390       switch (i->sig) {
09391       case SIG_FXOLS:
09392       case SIG_FXOGS:
09393       case SIG_FXOKS:
09394          res = dahdi_set_hook(i->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
09395          i->fxsoffhookstate = 1;
09396          if (res && (errno == EBUSY))
09397             break;
09398          if (i->cidspill) {
09399             /* Cancel VMWI spill */
09400             ast_free(i->cidspill);
09401             i->cidspill = NULL;
09402          }
09403          if (i->immediate) {
09404             dahdi_enable_ec(i);
09405             /* The channel is immediately up.  Start right away */
09406             res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
09407             chan = dahdi_new(i, AST_STATE_RING, 1, SUB_REAL, 0, 0);
09408             if (!chan) {
09409                ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
09410                res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
09411                if (res < 0)
09412                   ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
09413             }
09414          } else {
09415             /* Check for callerid, digits, etc */
09416             chan = dahdi_new(i, AST_STATE_RESERVED, 0, SUB_REAL, 0, 0);
09417             if (chan) {
09418                if (has_voicemail(i))
09419                   res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_STUTTER);
09420                else
09421                   res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_DIALTONE);
09422                if (res < 0)
09423                   ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel);
09424                if (ast_pthread_create_detached(&threadid, NULL, ss_thread, chan)) {
09425                   ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
09426                   res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
09427                   if (res < 0)
09428                      ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
09429                   ast_hangup(chan);
09430                }
09431             } else
09432                ast_log(LOG_WARNING, "Unable to create channel\n");
09433          }
09434          break;
09435       case SIG_FXSLS:
09436       case SIG_FXSGS:
09437       case SIG_FXSKS:
09438             i->ringt = i->ringt_base;
09439             /* Fall through */
09440       case SIG_EMWINK:
09441       case SIG_FEATD:
09442       case SIG_FEATDMF:
09443       case SIG_FEATDMF_TA:
09444       case SIG_E911:
09445       case SIG_FGC_CAMA:
09446       case SIG_FGC_CAMAMF:
09447       case SIG_FEATB:
09448       case SIG_EM:
09449       case SIG_EM_E1:
09450       case SIG_SFWINK:
09451       case SIG_SF_FEATD:
09452       case SIG_SF_FEATDMF:
09453       case SIG_SF_FEATB:
09454       case SIG_SF:
09455          /* Check for callerid, digits, etc */
09456          if (i->cid_start == CID_START_POLARITY_IN) {
09457             chan = dahdi_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, 0);
09458          } else {
09459             chan = dahdi_new(i, AST_STATE_RING, 0, SUB_REAL, 0, 0);
09460          }
09461 
09462          if (!chan) {
09463             ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
09464          } else if (ast_pthread_create_detached(&threadid, NULL, ss_thread, chan)) {
09465             ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
09466             res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
09467             if (res < 0) {
09468                ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
09469             }
09470             ast_hangup(chan);
09471          }
09472          break;
09473       default:
09474          ast_log(LOG_WARNING, "Don't know how to handle ring/answer with signalling %s on channel %d\n", sig2str(i->sig), i->channel);
09475          res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
09476          if (res < 0)
09477             ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
09478          return NULL;
09479       }
09480       break;
09481    case DAHDI_EVENT_NOALARM:
09482       i->inalarm = 0;
09483       ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", i->channel);
09484       manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
09485          "Channel: %d\r\n", i->channel);
09486       break;
09487    case DAHDI_EVENT_ALARM:
09488       i->inalarm = 1;
09489       res = get_alarms(i);
09490       handle_alarms(i, res);
09491       /* fall thru intentionally */
09492    case DAHDI_EVENT_ONHOOK:
09493       if (i->radio)
09494          break;
09495       /* Back on hook.  Hang up. */
09496       switch (i->sig) {
09497       case SIG_FXOLS:
09498       case SIG_FXOGS:
09499       case SIG_FEATD:
09500       case SIG_FEATDMF:
09501       case SIG_FEATDMF_TA:
09502       case SIG_E911:
09503       case SIG_FGC_CAMA:
09504       case SIG_FGC_CAMAMF:
09505       case SIG_FEATB:
09506       case SIG_EM:
09507       case SIG_EM_E1:
09508       case SIG_EMWINK:
09509       case SIG_SF_FEATD:
09510       case SIG_SF_FEATDMF:
09511       case SIG_SF_FEATB:
09512       case SIG_SF:
09513       case SIG_SFWINK:
09514       case SIG_FXSLS:
09515       case SIG_FXSGS:
09516       case SIG_FXSKS:
09517       case SIG_GR303FXSKS:
09518          dahdi_disable_ec(i);
09519          res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, -1);
09520          dahdi_set_hook(i->subs[SUB_REAL].dfd, DAHDI_ONHOOK);
09521          break;
09522       case SIG_GR303FXOKS:
09523       case SIG_FXOKS:
09524          dahdi_disable_ec(i);
09525          /* Diddle the battery for the zhone */
09526 #ifdef ZHONE_HACK
09527          dahdi_set_hook(i->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
09528          usleep(1);
09529 #endif
09530          res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, -1);
09531          dahdi_set_hook(i->subs[SUB_REAL].dfd, DAHDI_ONHOOK);
09532          break;
09533       case SIG_PRI:
09534       case SIG_SS7:
09535       case SIG_BRI:
09536       case SIG_BRI_PTMP:
09537          dahdi_disable_ec(i);
09538          res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, -1);
09539          break;
09540       default:
09541          ast_log(LOG_WARNING, "Don't know how to handle on hook with signalling %s on channel %d\n", sig2str(i->sig), i->channel);
09542          res = tone_zone_play_tone(i->subs[SUB_REAL].dfd, -1);
09543          return NULL;
09544       }
09545       if (i->sig & __DAHDI_SIG_FXO) {
09546          i->fxsoffhookstate = 0;
09547       }
09548       break;
09549    case DAHDI_EVENT_POLARITY:
09550       switch (i->sig) {
09551       case SIG_FXSLS:
09552       case SIG_FXSKS:
09553       case SIG_FXSGS:
09554          /* We have already got a PR before the channel was
09555             created, but it wasn't handled. We need polarity
09556             to be REV for remote hangup detection to work.
09557             At least in Spain */
09558          if (i->hanguponpolarityswitch)
09559             i->polarity = POLARITY_REV;
09560          if (i->cid_start == CID_START_POLARITY || i->cid_start == CID_START_POLARITY_IN) {
09561             i->polarity = POLARITY_REV;
09562             ast_verb(2, "Starting post polarity "
09563                "CID detection on channel %d\n",
09564                i->channel);
09565             chan = dahdi_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, 0);
09566             if (!chan) {
09567                ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
09568             } else if (ast_pthread_create_detached(&threadid, NULL, ss_thread, chan)) {
09569                ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
09570             }
09571          }
09572          break;
09573       default:
09574          ast_log(LOG_WARNING, "handle_init_event detected "
09575             "polarity reversal on non-FXO (SIG_FXS) "
09576             "interface %d\n", i->channel);
09577       }
09578       break;
09579    case DAHDI_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */
09580       ast_log(LOG_NOTICE,
09581             "Got DAHDI_EVENT_REMOVED. Destroying channel %d\n",
09582             i->channel);
09583       return i;
09584    case DAHDI_EVENT_NEONMWI_ACTIVE:
09585       if (i->mwimonitor_neon) {
09586          notify_message(i->mailbox, 1);
09587          ast_log(LOG_NOTICE, "NEON MWI set for channel %d, mailbox %s \n", i->channel, i->mailbox);
09588       }
09589       break;
09590    case DAHDI_EVENT_NEONMWI_INACTIVE:
09591       if (i->mwimonitor_neon) {
09592          notify_message(i->mailbox, 0);
09593          ast_log(LOG_NOTICE, "NEON MWI cleared for channel %d, mailbox %s\n", i->channel, i->mailbox);
09594       }
09595       break;
09596    }
09597    return NULL;
09598 }

static char* handle_mfcr2_call_files ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14255 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), ast_true(), dahdi_pvt::channel, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, iflist, iflock, dahdi_pvt::next, dahdi_pvt::r2chan, dahdi_pvt::sig, SIG_MFCR2, and ast_cli_entry::usage.

14256 {
14257    struct dahdi_pvt *p = NULL;
14258    int channo = 0;
14259    switch (cmd) {
14260    case CLI_INIT:
14261       e->command = "mfcr2 call files [on|off]";
14262       e->usage =
14263          "Usage: mfcr2 call files [on|off] <channel>\n"
14264          "       Enable call files creation on the specified channel.\n"
14265          "       If no channel is specified call files creation policy will be applied to all channels.\n";
14266       return NULL;
14267    case CLI_GENERATE:
14268       return NULL;
14269    }
14270    if (a->argc < 4) {
14271       return CLI_SHOWUSAGE;
14272    }
14273    channo = (a->argc == 5) ? atoi(a->argv[4]) : -1;
14274    ast_mutex_lock(&iflock);
14275    for (p = iflist; p; p = p->next) {
14276       if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
14277          continue;
14278       }
14279       if ((channo != -1) && (p->channel != channo )) {
14280          continue;
14281       }
14282       if (ast_true(a->argv[3])) {
14283          openr2_chan_enable_call_files(p->r2chan);
14284       } else {
14285          openr2_chan_disable_call_files(p->r2chan);
14286       }
14287       if (channo != -1) {
14288          if (ast_true(a->argv[3])) {
14289             ast_cli(a->fd, "MFC/R2 call files enabled for channel %d.\n", p->channel);
14290          } else {
14291             ast_cli(a->fd, "MFC/R2 call files disabled for channel %d.\n", p->channel);
14292          }
14293          break;
14294       }
14295    }
14296    if ((channo != -1) && !p) {
14297       ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
14298    }
14299    if (channo == -1) {
14300       if (ast_true(a->argv[3])) {
14301          ast_cli(a->fd, "MFC/R2 Call files enabled for all channels.\n");
14302       } else {
14303          ast_cli(a->fd, "MFC/R2 Call files disabled for all channels.\n");
14304       }
14305    }
14306    ast_mutex_unlock(&iflock);
14307    return CLI_SUCCESS;
14308 }

static char* handle_mfcr2_set_blocked ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14351 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, iflist, iflock, dahdi_pvt::locallyblocked, dahdi_pvt::lock, dahdi_pvt::next, dahdi_pvt::r2chan, dahdi_pvt::sig, SIG_MFCR2, and ast_cli_entry::usage.

14352 {
14353    struct dahdi_pvt *p = NULL;
14354    int channo = 0;
14355    switch (cmd) {
14356    case CLI_INIT:
14357       e->command = "mfcr2 set blocked";
14358       e->usage =
14359          "Usage: mfcr2 set blocked <channel>\n"
14360          "       DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.\n"
14361          "       Force the given channel into BLOCKED state.\n"
14362          "       If no channel is specified, all channels will be set to BLOCKED.\n";
14363       return NULL;
14364    case CLI_GENERATE:
14365       return NULL;
14366    }
14367    channo = (a->argc == 4) ? atoi(a->argv[3]) : -1;
14368    ast_mutex_lock(&iflock);
14369    for (p = iflist; p; p = p->next) {
14370       if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
14371          continue;
14372       }
14373       if ((channo != -1) && (p->channel != channo )) {
14374          continue;
14375       }
14376       openr2_chan_set_blocked(p->r2chan);
14377       ast_mutex_lock(&p->lock);
14378       p->locallyblocked = 1;
14379       ast_mutex_unlock(&p->lock);
14380       if (channo != -1) {
14381          break;
14382       }
14383    }
14384    if ((channo != -1) && !p) {
14385       ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
14386    }
14387    ast_mutex_unlock(&iflock);
14388    return CLI_SUCCESS;
14389 }

static char* handle_mfcr2_set_debug ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14190 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), ast_strdupa, dahdi_pvt::channel, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, iflist, iflock, dahdi_pvt::next, dahdi_pvt::r2chan, dahdi_pvt::sig, SIG_MFCR2, and ast_cli_entry::usage.

14191 {
14192    struct dahdi_pvt *p = NULL;
14193    int channo = 0;
14194    char *toklevel = NULL;
14195    char *saveptr = NULL;
14196    char *logval = NULL;
14197    openr2_log_level_t loglevel = OR2_LOG_NOTHING;
14198    openr2_log_level_t tmplevel = OR2_LOG_NOTHING;
14199    switch (cmd) {
14200    case CLI_INIT:
14201       e->command = "mfcr2 set debug";
14202       e->usage =
14203          "Usage: mfcr2 set debug <loglevel> <channel>\n"
14204          "       Set a new logging level for the specified channel.\n"
14205          "       If no channel is specified the logging level will be applied to all channels.\n";
14206       return NULL;
14207    case CLI_GENERATE:
14208       return NULL;
14209    }
14210    if (a->argc < 4) {
14211       return CLI_SHOWUSAGE;
14212    }
14213    channo = (a->argc == 5) ? atoi(a->argv[4]) : -1;
14214    logval = ast_strdupa(a->argv[3]);
14215    toklevel = strtok_r(logval, ",", &saveptr);
14216    if (-1 == (tmplevel = openr2_log_get_level(toklevel))) {
14217       ast_cli(a->fd, "Invalid MFC/R2 logging level '%s'.\n", a->argv[3]);
14218       return CLI_FAILURE;
14219    } else if (OR2_LOG_NOTHING == tmplevel) {
14220       loglevel = tmplevel;
14221    } else {
14222       loglevel |= tmplevel;
14223       while ((toklevel = strtok_r(NULL, ",", &saveptr))) {
14224          if (-1 == (tmplevel = openr2_log_get_level(toklevel))) {
14225             ast_cli(a->fd, "Ignoring invalid logging level: '%s'.\n", toklevel);
14226             continue;
14227          }
14228          loglevel |= tmplevel;
14229       }
14230    }
14231    ast_mutex_lock(&iflock);
14232    for (p = iflist; p; p = p->next) {
14233       if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
14234          continue;
14235       }
14236       if ((channo != -1) && (p->channel != channo )) {
14237          continue;
14238       }
14239       openr2_chan_set_log_level(p->r2chan, loglevel);
14240       if (channo != -1) {
14241          ast_cli(a->fd, "MFC/R2 debugging set to '%s' for channel %d.\n", a->argv[3], p->channel);
14242          break;
14243       }
14244    }
14245    if ((channo != -1) && !p) {
14246       ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
14247    }
14248    if (channo == -1) {
14249       ast_cli(a->fd, "MFC/R2 debugging set to '%s' for all channels.\n", a->argv[3]);
14250    }
14251    ast_mutex_unlock(&iflock);
14252    return CLI_SUCCESS;
14253 }

static char* handle_mfcr2_set_idle ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14310 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, iflist, iflock, dahdi_pvt::locallyblocked, dahdi_pvt::lock, dahdi_pvt::mfcr2call, dahdi_pvt::next, dahdi_pvt::r2chan, dahdi_pvt::sig, SIG_MFCR2, and ast_cli_entry::usage.

14311 {
14312    struct dahdi_pvt *p = NULL;
14313    int channo = 0;
14314    switch (cmd) {
14315    case CLI_INIT:
14316       e->command = "mfcr2 set idle";
14317       e->usage =
14318          "Usage: mfcr2 set idle <channel>\n"
14319          "       DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.\n"
14320          "       Force the given channel into IDLE state.\n"
14321          "       If no channel is specified, all channels will be set to IDLE.\n";
14322       return NULL;
14323    case CLI_GENERATE:
14324       return NULL;
14325    }
14326    channo = (a->argc == 4) ? atoi(a->argv[3]) : -1;
14327    ast_mutex_lock(&iflock);
14328    for (p = iflist; p; p = p->next) {
14329       if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
14330          continue;
14331       }
14332       if ((channo != -1) && (p->channel != channo )) {
14333          continue;
14334       }
14335       openr2_chan_set_idle(p->r2chan);
14336       ast_mutex_lock(&p->lock);
14337       p->locallyblocked = 0;
14338       p->mfcr2call = 0;
14339       ast_mutex_unlock(&p->lock);
14340       if (channo != -1) {
14341          break;
14342       }
14343    }
14344    if ((channo != -1) && !p) {
14345       ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
14346    }
14347    ast_mutex_unlock(&iflock);
14348    return CLI_SUCCESS;
14349 }

static char* handle_mfcr2_show_channels ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14115 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::channel, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dahdi_pvt::context, ast_cli_args::fd, FORMAT, dahdi_pvt::group, iflist, iflock, dahdi_pvt::next, dahdi_pvt::r2chan, dahdi_pvt::sig, SIG_MFCR2, and ast_cli_entry::usage.

14116 {
14117 #define FORMAT "%4s %-7.7s %-7.7s %-8.8s %-9.9s %-16.16s %-8.8s %-8.8s\n"
14118    int filtertype = 0;
14119    int targetnum = 0;
14120    char channo[5];
14121    char anino[5];
14122    char dnisno[5];
14123    struct dahdi_pvt *p;
14124    openr2_context_t *r2context;
14125    openr2_variant_t r2variant;
14126    switch (cmd) {
14127    case CLI_INIT:
14128       e->command = "mfcr2 show channels [group|context]";
14129       e->usage =
14130          "Usage: mfcr2 show channels [group <group> | context <context>]\n"
14131          "       Shows the DAHDI channels configured with MFC/R2 signaling.\n";
14132       return NULL;
14133    case CLI_GENERATE:
14134       return NULL;
14135    }
14136    if (!((a->argc == 3) || (a->argc == 5))) {
14137       return CLI_SHOWUSAGE;
14138    }
14139    if (a->argc == 5) {
14140       if (!strcasecmp(a->argv[3], "group")) {
14141          targetnum = atoi(a->argv[4]);
14142          if ((targetnum < 0) || (targetnum > 63))
14143             return CLI_SHOWUSAGE;
14144          targetnum = 1 << targetnum;
14145          filtertype = 1;
14146       } else if (!strcasecmp(a->argv[3], "context")) {
14147          filtertype = 2;
14148       } else {
14149          return CLI_SHOWUSAGE;
14150       }
14151    }
14152    ast_cli(a->fd, FORMAT, "Chan", "Variant", "Max ANI", "Max DNIS", "ANI First", "Immediate Accept", "Tx CAS", "Rx CAS");
14153    ast_mutex_lock(&iflock);
14154    p = iflist;
14155    for (p = iflist; p; p = p->next) {
14156       if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
14157          continue;
14158       }
14159       if (filtertype) {
14160          switch(filtertype) {
14161          case 1: /* mfcr2 show channels group <group> */
14162             if (p->group != targetnum) {
14163                continue;
14164             }
14165             break;
14166          case 2: /* mfcr2 show channels context <context> */
14167             if (strcasecmp(p->context, a->argv[4])) {
14168                continue;
14169             }
14170             break;
14171          default:
14172             ;
14173          }
14174       }
14175       r2context = openr2_chan_get_context(p->r2chan);
14176       r2variant = openr2_context_get_variant(r2context);
14177       snprintf(channo, sizeof(channo), "%d", p->channel);
14178       snprintf(anino, sizeof(anino), "%d", openr2_context_get_max_ani(r2context));
14179       snprintf(dnisno, sizeof(dnisno), "%d", openr2_context_get_max_dnis(r2context));
14180       ast_cli(a->fd, FORMAT, channo, openr2_proto_get_variant_string(r2variant),
14181             anino, dnisno, openr2_context_get_ani_first(r2context) ? "Yes" : "No",
14182             openr2_context_get_immediate_accept(r2context) ? "Yes" : "No",
14183             openr2_chan_get_tx_cas_string(p->r2chan), openr2_chan_get_rx_cas_string(p->r2chan));
14184    }
14185    ast_mutex_unlock(&iflock);
14186    return CLI_SUCCESS;
14187 #undef FORMAT
14188 }

static char* handle_mfcr2_show_variants ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14087 of file chan_dahdi.c.

References ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT, and ast_cli_entry::usage.

14088 {
14089 #define FORMAT "%4s %40s\n"
14090    int i = 0;
14091    int numvariants = 0;
14092    const openr2_variant_entry_t *variants;
14093    switch (cmd) {
14094    case CLI_INIT:
14095       e->command = "mfcr2 show variants";
14096       e->usage =
14097          "Usage: mfcr2 show variants\n"
14098          "       Shows the list of MFC/R2 variants supported.\n";
14099       return NULL;
14100    case CLI_GENERATE:
14101       return NULL;
14102    }
14103    if (!(variants = openr2_proto_get_variant_list(&numvariants))) {
14104       ast_cli(a->fd, "Failed to get list of variants.\n");
14105       return CLI_FAILURE;
14106    }
14107    ast_cli(a->fd, FORMAT, "Variant Code", "Country");
14108    for (i = 0; i < numvariants; i++) {
14109       ast_cli(a->fd, FORMAT, variants[i].name, variants[i].country);
14110    }
14111    return CLI_SUCCESS;
14112 #undef FORMAT
14113 }

static char* handle_mfcr2_version ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14071 of file chan_dahdi.c.

References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.

14072 {
14073    switch (cmd) {
14074    case CLI_INIT:
14075       e->command = "mfcr2 show version";
14076       e->usage =
14077          "Usage: mfcr2 show version\n"
14078          "       Shows the version of the OpenR2 library being used.\n";
14079       return NULL;
14080    case CLI_GENERATE:
14081       return NULL;
14082    }
14083    ast_cli(a->fd, "OpenR2 version: %s, revision: %s\n", openr2_get_version(), openr2_get_revision());
14084    return CLI_SUCCESS;
14085 }

static char* handle_pri_debug ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 13823 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_span_4(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, NUM_DCHANS, NUM_SPANS, ast_cli_args::pos, pridebugfdlock, pris, ast_cli_entry::usage, and ast_cli_args::word.

13824 {
13825    int span;
13826    int x;
13827    int level = 0;
13828    switch (cmd) {
13829    case CLI_INIT:
13830       e->command = "pri set debug {on|off|0|1|2} span";
13831       e->usage =
13832          "Usage: pri set debug {<level>|on|off} span <span>\n"
13833          "       Enables debugging on a given PRI span\n";
13834       return NULL;
13835    case CLI_GENERATE:
13836       return complete_span_4(a->line, a->word, a->pos, a->n);
13837    }
13838    if (a->argc < 6) {
13839       return CLI_SHOWUSAGE;
13840    }
13841 
13842    if (!strcasecmp(a->argv[3], "on")) {
13843       level = 1;
13844    } else if (!strcasecmp(a->argv[3], "off")) {
13845       level = 0;
13846    } else {
13847       level = atoi(a->argv[3]);
13848    }
13849    span = atoi(a->argv[5]);
13850    if ((span < 1) || (span > NUM_SPANS)) {
13851       ast_cli(a->fd, "Invalid span %s.  Should be a number %d to %d\n", a->argv[5], 1, NUM_SPANS);
13852       return CLI_SUCCESS;
13853    }
13854    if (!pris[span-1].pri) {
13855       ast_cli(a->fd, "No PRI running on span %d\n", span);
13856       return CLI_SUCCESS;
13857    }
13858    for (x = 0; x < NUM_DCHANS; x++) {
13859       if (pris[span-1].dchans[x]) {
13860          if (level == 1) {
13861             pri_set_debug(pris[span-1].dchans[x], PRI_DEBUG_APDU |
13862                PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE |
13863                PRI_DEBUG_Q921_STATE);
13864             ast_cli(a->fd, "Enabled debugging on span %d\n", span);
13865          } else if (level == 0) {
13866             pri_set_debug(pris[span-1].dchans[x], 0);
13867             //close the file if it's set
13868             ast_mutex_lock(&pridebugfdlock);
13869             close(pridebugfd);
13870             pridebugfd = -1;
13871             ast_cli(a->fd, "PRI debug output to file disabled\n");
13872             ast_mutex_unlock(&pridebugfdlock);
13873          } else {
13874             pri_set_debug(pris[span-1].dchans[x], PRI_DEBUG_APDU |
13875                PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE |
13876                PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_STATE);
13877             ast_cli(a->fd, "Enabled debugging on span %d\n", span);
13878          }
13879       }
13880    }
13881    return CLI_SUCCESS;
13882 }

static char* handle_pri_set_debug_file ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 13785 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), AST_FILE_MODE, ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, pridebugfdlock, and ast_cli_entry::usage.

13786 {
13787    int myfd;
13788    switch (cmd) {
13789    case CLI_INIT:
13790       e->command = "pri set debug file";
13791       e->usage = "Usage: pri set debug file [output-file]\n"
13792          "       Sends PRI debug output to the specified output file\n";
13793       return NULL;
13794    case CLI_GENERATE:
13795       return NULL;
13796    }
13797    if (a->argc < 5)
13798       return CLI_SHOWUSAGE;
13799 
13800    if (ast_strlen_zero(a->argv[4]))
13801       return CLI_SHOWUSAGE;
13802 
13803    myfd = open(a->argv[4], O_CREAT|O_WRONLY, AST_FILE_MODE);
13804    if (myfd < 0) {
13805       ast_cli(a->fd, "Unable to open '%s' for writing\n", a->argv[4]);
13806       return CLI_SUCCESS;
13807    }
13808 
13809    ast_mutex_lock(&pridebugfdlock);
13810 
13811    if (pridebugfd >= 0)
13812       close(pridebugfd);
13813 
13814    pridebugfd = myfd;
13815    ast_copy_string(pridebugfilename,a->argv[4],sizeof(pridebugfilename));
13816    ast_mutex_unlock(&pridebugfdlock);
13817    ast_cli(a->fd, "PRI debug output will be sent to '%s'\n", a->argv[4]);
13818    return CLI_SUCCESS;
13819 }

static char* handle_pri_show_debug ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 13996 of file chan_dahdi.c.

References ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, debug, ast_cli_args::fd, NUM_DCHANS, NUM_SPANS, pridebugfdlock, pris, and ast_cli_entry::usage.

13997 {
13998    int x;
13999    int span;
14000    int count=0;
14001    int debug=0;
14002 
14003    switch (cmd) {
14004    case CLI_INIT:
14005       e->command = "pri show debug";
14006       e->usage =
14007          "Usage: pri show debug\n"
14008          "  Show the debug state of pri spans\n";
14009       return NULL;
14010    case CLI_GENERATE:
14011       return NULL;
14012    }
14013 
14014    for (span = 0; span < NUM_SPANS; span++) {
14015       if (pris[span].pri) {
14016          for (x = 0; x < NUM_DCHANS; x++) {
14017             debug = 0;
14018             if (pris[span].dchans[x]) {
14019                debug = pri_get_debug(pris[span].dchans[x]);
14020                ast_cli(a->fd, "Span %d: Debug: %s\tIntense: %s\n", span+1, (debug&PRI_DEBUG_Q931_STATE)? "Yes" : "No" ,(debug&PRI_DEBUG_Q921_RAW)? "Yes" : "No" );
14021                count++;
14022             }
14023          }
14024       }
14025 
14026    }
14027    ast_mutex_lock(&pridebugfdlock);
14028    if (pridebugfd >= 0)
14029       ast_cli(a->fd, "Logging PRI debug to file %s\n", pridebugfilename);
14030    ast_mutex_unlock(&pridebugfdlock);
14031 
14032    if (!count)
14033       ast_cli(a->fd, "No debug set or no PRI running\n");
14034    return CLI_SUCCESS;
14035 }

static char* handle_pri_show_span ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 13944 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_free, build_status(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_span_4(), DAHDI_OVERLAPDIAL_INCOMING, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, NUM_DCHANS, NUM_SPANS, dahdi_pri::overlapdial, ast_cli_args::pos, pri_order(), pris, status, ast_cli_entry::usage, and ast_cli_args::word.

13945 {
13946    int span;
13947    int x;
13948    char status[256];
13949    switch (cmd) {
13950    case CLI_INIT:
13951       e->command = "pri show span";
13952       e->usage =
13953          "Usage: pri show span <span>\n"
13954          "       Displays PRI Information on a given PRI span\n";
13955       return NULL;
13956    case CLI_GENERATE:
13957       return complete_span_4(a->line, a->word, a->pos, a->n);
13958    }
13959 
13960    if (a->argc < 4)
13961       return CLI_SHOWUSAGE;
13962    span = atoi(a->argv[3]);
13963    if ((span < 1) || (span > NUM_SPANS)) {
13964       ast_cli(a->fd, "Invalid span '%s'.  Should be a number from %d to %d\n", a->argv[3], 1, NUM_SPANS);
13965       return CLI_SUCCESS;
13966    }
13967    if (!pris[span-1].pri) {
13968       ast_cli(a->fd, "No PRI running on span %d\n", span);
13969       return CLI_SUCCESS;
13970    }
13971    for (x = 0; x < NUM_DCHANS; x++) {
13972       if (pris[span-1].dchannels[x]) {
13973 #ifdef PRI_DUMP_INFO_STR
13974          char *info_str = NULL;
13975 #endif
13976          ast_cli(a->fd, "%s D-channel: %d\n", pri_order(x), pris[span-1].dchannels[x]);
13977          build_status(status, sizeof(status), pris[span-1].dchanavail[x], pris[span-1].dchans[x] == pris[span-1].pri);
13978          ast_cli(a->fd, "Status: %s\n", status);
13979 #ifdef PRI_DUMP_INFO_STR
13980          info_str = pri_dump_info_str(pris[span-1].pri);
13981          if (info_str) {
13982             ast_cli(a->fd, "%s", info_str);
13983             ast_free(info_str);
13984          }
13985 #else
13986          pri_dump_info(pris[span-1].pri);
13987 #endif
13988          ast_cli(a->fd, "Overlap Recv: %s\n\n", (pris[span-1].overlapdial & DAHDI_OVERLAPDIAL_INCOMING)?"Yes":"No");
13989       }
13990    }
13991    return CLI_SUCCESS;
13992 }

static char* handle_pri_show_spans ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 13909 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli(), build_status(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NUM_DCHANS, NUM_SPANS, pris, status, and ast_cli_entry::usage.

13910 {
13911    int span;
13912    int x;
13913    char status[256];
13914 
13915    switch (cmd) {
13916    case CLI_INIT:
13917       e->command = "pri show spans";
13918       e->usage =
13919          "Usage: pri show spans\n"
13920          "       Displays PRI Information\n";
13921       return NULL;
13922    case CLI_GENERATE:
13923       return NULL;
13924    }
13925 
13926    if (a->argc != 3)
13927       return CLI_SHOWUSAGE;
13928 
13929    for (span = 0; span < NUM_SPANS; span++) {
13930       if (pris[span].pri) {
13931          for (x = 0; x < NUM_DCHANS; x++) {
13932             if (pris[span].dchannels[x]) {
13933                build_status(status, sizeof(status), pris[span].dchanavail[x], pris[span].dchans[x] == pris[span].pri);
13934                ast_cli(a->fd, "PRI span %d/%d: %s\n", span + 1, x, status);
13935             }
13936          }
13937       }
13938    }
13939    return CLI_SUCCESS;
13940 }

static char* handle_pri_version ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 14039 of file chan_dahdi.c.

References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.

14040 {
14041    switch (cmd) {
14042    case CLI_INIT:
14043       e->command = "pri show version";
14044       e->usage =
14045          "Usage: pri show version\n"
14046          "Show libpri version information\n";
14047       return NULL;
14048    case CLI_GENERATE:
14049       return NULL;
14050    }
14051 
14052    ast_cli(a->fd, "libpri version: %s\n", pri_get_version());
14053 
14054    return CLI_SUCCESS;
14055 }

static char* handle_ss7_block_cic ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15686 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, linksets, dahdi_pvt::locallyblocked, lock, master, NUM_SPANS, dahdi_ss7::numchans, dahdi_ss7::pvts, pvts, and ast_cli_entry::usage.

15687 {
15688    int linkset, cic;
15689    int blocked = -1, i;
15690    switch (cmd) {
15691    case CLI_INIT:
15692       e->command = "ss7 block cic";
15693       e->usage =
15694          "Usage: ss7 block cic <linkset> <CIC>\n"
15695          "       Sends a remote blocking request for the given CIC on the specified linkset\n";
15696       return NULL;
15697    case CLI_GENERATE:
15698       return NULL;
15699    }
15700    if (a->argc == 5)
15701       linkset = atoi(a->argv[3]);
15702    else
15703       return CLI_SHOWUSAGE;
15704 
15705    if ((linkset < 1) || (linkset > NUM_SPANS)) {
15706       ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
15707       return CLI_SUCCESS;
15708    }
15709 
15710    if (!linksets[linkset-1].ss7) {
15711       ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
15712       return CLI_SUCCESS;
15713    }
15714 
15715    cic = atoi(a->argv[4]);
15716 
15717    if (cic < 1) {
15718       ast_cli(a->fd, "Invalid CIC specified!\n");
15719       return CLI_SUCCESS;
15720    }
15721 
15722    for (i = 0; i < linksets[linkset-1].numchans; i++) {
15723       if (linksets[linkset-1].pvts[i]->cic == cic) {
15724          blocked = linksets[linkset-1].pvts[i]->locallyblocked;
15725          if (!blocked) {
15726             ast_mutex_lock(&linksets[linkset-1].lock);
15727             isup_blo(linksets[linkset-1].ss7, cic, linksets[linkset-1].pvts[i]->dpc);
15728             ast_mutex_unlock(&linksets[linkset-1].lock);
15729          }
15730       }
15731    }
15732 
15733    if (blocked < 0) {
15734       ast_cli(a->fd, "Invalid CIC specified!\n");
15735       return CLI_SUCCESS;
15736    }
15737 
15738    if (!blocked)
15739       ast_cli(a->fd, "Sent blocking request for linkset %d on CIC %d\n", linkset, cic);
15740    else
15741       ast_cli(a->fd, "CIC %d already locally blocked\n", cic);
15742 
15743    /* Break poll on the linkset so it sends our messages */
15744    pthread_kill(linksets[linkset-1].master, SIGURG);
15745 
15746    return CLI_SUCCESS;
15747 }

static char* handle_ss7_block_linkset ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15751 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::cic, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, linksets, lock, master, NUM_SPANS, dahdi_ss7::numchans, pvts, dahdi_ss7::pvts, and ast_cli_entry::usage.

15752 {
15753    int linkset;
15754    int i;
15755    switch (cmd) {
15756    case CLI_INIT:
15757       e->command = "ss7 block linkset";
15758       e->usage =
15759          "Usage: ss7 block linkset <linkset number>\n"
15760          "       Sends a remote blocking request for all CICs on the given linkset\n";
15761       return NULL;
15762    case CLI_GENERATE:
15763       return NULL;
15764    }
15765    if (a->argc == 4)
15766       linkset = atoi(a->argv[3]);
15767    else
15768       return CLI_SHOWUSAGE;
15769 
15770    if ((linkset < 1) || (linkset > NUM_SPANS)) {
15771       ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
15772       return CLI_SUCCESS;
15773    }
15774 
15775    if (!linksets[linkset-1].ss7) {
15776       ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
15777       return CLI_SUCCESS;
15778    }
15779 
15780    for (i = 0; i < linksets[linkset-1].numchans; i++) {
15781       ast_cli(a->fd, "Sending remote blocking request on CIC %d\n", linksets[linkset-1].pvts[i]->cic);
15782       ast_mutex_lock(&linksets[linkset-1].lock);
15783       isup_blo(linksets[linkset-1].ss7, linksets[linkset-1].pvts[i]->cic, linksets[linkset-1].pvts[i]->dpc);
15784       ast_mutex_unlock(&linksets[linkset-1].lock);
15785    }
15786 
15787    /* Break poll on the linkset so it sends our messages */
15788    pthread_kill(linksets[linkset-1].master, SIGURG);
15789 
15790    return CLI_SUCCESS;
15791 }

static char* handle_ss7_debug ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15647 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, linksets, NUM_SPANS, and ast_cli_entry::usage.

15648 {
15649    int span;
15650    switch (cmd) {
15651    case CLI_INIT:
15652       e->command = "ss7 set debug {on|off} linkset";
15653       e->usage =
15654          "Usage: ss7 set debug {on|off} linkset <linkset>\n"
15655          "       Enables debugging on a given SS7 linkset\n";
15656       return NULL;
15657    case CLI_GENERATE:
15658       return NULL;
15659    }
15660    if (a->argc < 6)
15661       return CLI_SHOWUSAGE;
15662    span = atoi(a->argv[5]);
15663    if ((span < 1) || (span > NUM_SPANS)) {
15664       ast_cli(a->fd, "Invalid linkset %s.  Should be a number from %d to %d\n", a->argv[5], 1, NUM_SPANS);
15665       return CLI_SUCCESS;
15666    }
15667    if (!linksets[span-1].ss7) {
15668       ast_cli(a->fd, "No SS7 running on linkset %d\n", span);
15669       return CLI_SUCCESS;
15670    }
15671    if (linksets[span-1].ss7) {
15672       if (!strcasecmp(a->argv[3], "on")) {
15673          ss7_set_debug(linksets[span-1].ss7, SS7_DEBUG_MTP2 | SS7_DEBUG_MTP3 | SS7_DEBUG_ISUP);
15674          ast_cli(a->fd, "Enabled debugging on linkset %d\n", span);
15675       } else {
15676          ss7_set_debug(linksets[span-1].ss7, 0);
15677          ast_cli(a->fd, "Disabled debugging on linkset %d\n", span);
15678       }
15679    }
15680 
15681    return CLI_SUCCESS;
15682 }

static char* handle_ss7_show_linkset ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15899 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, dahdi_ss7::LINKSET_STATE_UP, linksets, NUM_SPANS, dahdi_ss7::ss7, dahdi_ss7::state, and ast_cli_entry::usage.

15900 {
15901    int linkset;
15902    struct dahdi_ss7 *ss7;
15903    switch (cmd) {
15904    case CLI_INIT:
15905       e->command = "ss7 show linkset";
15906       e->usage =
15907          "Usage: ss7 show linkset <span>\n"
15908          "       Shows the status of an SS7 linkset.\n";
15909       return NULL;
15910    case CLI_GENERATE:
15911       return NULL;
15912    }
15913 
15914    if (a->argc < 4)
15915       return CLI_SHOWUSAGE;
15916    linkset = atoi(a->argv[3]);
15917    if ((linkset < 1) || (linkset > NUM_SPANS)) {
15918       ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
15919       return CLI_SUCCESS;
15920    }
15921    if (!linksets[linkset-1].ss7) {
15922       ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
15923       return CLI_SUCCESS;
15924    }
15925    if (linksets[linkset-1].ss7)
15926       ss7 = &linksets[linkset-1];
15927 
15928    ast_cli(a->fd, "SS7 linkset %d status: %s\n", linkset, (ss7->state == LINKSET_STATE_UP) ? "Up" : "Down");
15929 
15930    return CLI_SUCCESS;
15931 }

static char* handle_ss7_unblock_cic ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15795 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, linksets, dahdi_pvt::locallyblocked, lock, master, NUM_SPANS, dahdi_ss7::numchans, dahdi_ss7::pvts, pvts, and ast_cli_entry::usage.

15796 {
15797    int linkset, cic;
15798    int i, blocked = -1;
15799    switch (cmd) {
15800    case CLI_INIT:
15801       e->command = "ss7 unblock cic";
15802       e->usage =
15803          "Usage: ss7 unblock cic <linkset> <CIC>\n"
15804          "       Sends a remote unblocking request for the given CIC on the specified linkset\n";
15805       return NULL;
15806    case CLI_GENERATE:
15807       return NULL;
15808    }
15809 
15810    if (a->argc == 5)
15811       linkset = atoi(a->argv[3]);
15812    else
15813       return CLI_SHOWUSAGE;
15814 
15815    if ((linkset < 1) || (linkset > NUM_SPANS)) {
15816       ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
15817       return CLI_SUCCESS;
15818    }
15819 
15820    if (!linksets[linkset-1].ss7) {
15821       ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
15822       return CLI_SUCCESS;
15823    }
15824 
15825    cic = atoi(a->argv[4]);
15826 
15827    if (cic < 1) {
15828       ast_cli(a->fd, "Invalid CIC specified!\n");
15829       return CLI_SUCCESS;
15830    }
15831 
15832    for (i = 0; i < linksets[linkset-1].numchans; i++) {
15833       if (linksets[linkset-1].pvts[i]->cic == cic) {
15834          blocked = linksets[linkset-1].pvts[i]->locallyblocked;
15835          if (blocked) {
15836             ast_mutex_lock(&linksets[linkset-1].lock);
15837             isup_ubl(linksets[linkset-1].ss7, cic, linksets[linkset-1].pvts[i]->dpc);
15838             ast_mutex_unlock(&linksets[linkset-1].lock);
15839          }
15840       }
15841    }
15842 
15843    if (blocked > 0)
15844       ast_cli(a->fd, "Sent unblocking request for linkset %d on CIC %d\n", linkset, cic);
15845 
15846    /* Break poll on the linkset so it sends our messages */
15847    pthread_kill(linksets[linkset-1].master, SIGURG);
15848 
15849    return CLI_SUCCESS;
15850 }

static char* handle_ss7_unblock_linkset ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15854 of file chan_dahdi.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), dahdi_pvt::cic, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, linksets, lock, master, NUM_SPANS, dahdi_ss7::numchans, pvts, dahdi_ss7::pvts, and ast_cli_entry::usage.

15855 {
15856    int linkset;
15857    int i;
15858    switch (cmd) {
15859    case CLI_INIT:
15860       e->command = "ss7 unblock linkset";
15861       e->usage =
15862          "Usage: ss7 unblock linkset <linkset number>\n"
15863          "       Sends a remote unblocking request for all CICs on the specified linkset\n";
15864       return NULL;
15865    case CLI_GENERATE:
15866       return NULL;
15867    }
15868 
15869    if (a->argc == 4)
15870       linkset = atoi(a->argv[3]);
15871    else
15872       return CLI_SHOWUSAGE;
15873 
15874    if ((linkset < 1) || (linkset > NUM_SPANS)) {
15875       ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
15876       return CLI_SUCCESS;
15877    }
15878 
15879    if (!linksets[linkset-1].ss7) {
15880       ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
15881       return CLI_SUCCESS;
15882    }
15883 
15884    for (i = 0; i < linksets[linkset-1].numchans; i++) {
15885       ast_cli(a->fd, "Sending remote unblock request on CIC %d\n", linksets[linkset-1].pvts[i]->cic);
15886       ast_mutex_lock(&linksets[linkset-1].lock);
15887       isup_ubl(linksets[linkset-1].ss7, linksets[linkset-1].pvts[i]->cic, linksets[linkset-1].pvts[i]->dpc);
15888       ast_mutex_unlock(&linksets[linkset-1].lock);
15889    }
15890 
15891    /* Break poll on the linkset so it sends our messages */
15892    pthread_kill(linksets[linkset-1].master, SIGURG);
15893 
15894    return CLI_SUCCESS;
15895 }

static char* handle_ss7_version ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 15935 of file chan_dahdi.c.

References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.

15936 {
15937    switch (cmd) {
15938    case CLI_INIT:
15939       e->command = "ss7 show version";
15940       e->usage =
15941          "Usage: ss7 show version\n"
15942          "  Show the libss7 version\n";
15943       return NULL;
15944    case CLI_GENERATE:
15945       return NULL;
15946    }
15947 
15948    ast_cli(a->fd, "libss7 version: %s\n", ss7_get_version());
15949 
15950    return CLI_SUCCESS;
15951 }

static int has_voicemail ( struct dahdi_pvt *  p  )  [static]

Definition at line 3003 of file chan_dahdi.c.

References ast_app_has_voicemail(), ast_event_destroy(), ast_event_get_cached(), ast_event_get_ie_uint(), AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_MWI, ast_strdupa, ast_strlen_zero(), context, dahdi_pvt::mailbox, mailbox, and strsep().

Referenced by dahdi_handle_event(), do_monitor(), handle_init_event(), and mwi_send_init().

03004 {
03005    int new_msgs;
03006    struct ast_event *event;
03007    char *mailbox, *context;
03008 
03009    mailbox = context = ast_strdupa(p->mailbox);
03010    strsep(&context, "@");
03011    if (ast_strlen_zero(context))
03012       context = "default";
03013 
03014    event = ast_event_get_cached(AST_EVENT_MWI,
03015       AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
03016       AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
03017       AST_EVENT_IE_END);
03018 
03019    if (event) {
03020       new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
03021       ast_event_destroy(event);
03022    } else
03023       new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
03024 
03025    return new_msgs;
03026 }

static int isourconf ( struct dahdi_pvt *  p,
struct dahdi_subchannel *  c 
) [static]

Definition at line 2518 of file chan_dahdi.c.

References dahdi_pvt::channel, dahdi_pvt::confno, and dahdi_subchannel::curconf.

Referenced by conf_del().

02519 {
02520    /* If they're listening to our channel, they're ours */
02521    if ((p->channel == c->curconf.confno) && (c->curconf.confmode == DAHDI_CONF_DIGITALMON))
02522       return 1;
02523    /* If they're a talker on our (allocated) conference, they're ours */
02524    if ((p->confno > 0) && (p->confno == c->curconf.confno) && (c->curconf.confmode & DAHDI_CONF_TALKER))
02525       return 1;
02526    return 0;
02527 }

static int isslavenative ( struct dahdi_pvt *  p,
struct dahdi_pvt **  out 
) [static]

Definition at line 2548 of file chan_dahdi.c.

References dahdi_subchannel::dfd, dahdi_subchannel::inthreeway, dahdi_pvt::law, MAX_SLAVES, dahdi_pvt::slaves, and dahdi_pvt::subs.

Referenced by update_conf().

02549 {
02550    int x;
02551    int useslavenative;
02552    struct dahdi_pvt *slave = NULL;
02553    /* Start out optimistic */
02554    useslavenative = 1;
02555    /* Update conference state in a stateless fashion */
02556    for (x = 0; x < 3; x++) {
02557       /* Any three-way calling makes slave native mode *definitely* out
02558          of the question */
02559       if ((p->subs[x].dfd > -1) && p->subs[x].inthreeway)
02560          useslavenative = 0;
02561    }
02562    /* If we don't have any 3-way calls, check to see if we have
02563       precisely one slave */
02564    if (useslavenative) {
02565       for (x = 0; x < MAX_SLAVES; x++) {
02566          if (p->slaves[x]) {
02567             if (slave) {
02568                /* Whoops already have a slave!  No
02569                   slave native and stop right away */
02570                slave = NULL;
02571                useslavenative = 0;
02572                break;
02573             } else {
02574                /* We have one slave so far */
02575                slave = p->slaves[x];
02576             }
02577          }
02578       }
02579    }
02580    /* If no slave, slave native definitely out */
02581    if (!slave)
02582       useslavenative = 0;
02583    else if (slave->law != p->law) {
02584       useslavenative = 0;
02585       slave = NULL;
02586    }
02587    if (out)
02588       *out = slave;
02589    return useslavenative;
02590 }

static int linkset_addsigchan ( int  sigchan  )  [static]

Definition at line 15524 of file chan_dahdi.c.

References ast_log(), dahdi_close_ss7_fd(), errno, LINKSTATE_DOWN, LINKSTATE_INALARM, LOG_ERROR, NUM_DCHANS, NUM_SPANS, and ss7_resolve_linkset().

Referenced by process_dahdi().

15525 {
15526    struct dahdi_ss7 *link;
15527    int res;
15528    int curfd;
15529    struct dahdi_params p;
15530    struct dahdi_bufferinfo bi;
15531    struct dahdi_spaninfo si;
15532 
15533 
15534    link = ss7_resolve_linkset(cur_linkset);
15535    if (!link) {
15536       ast_log(LOG_ERROR, "Invalid linkset number.  Must be between 1 and %d\n", NUM_SPANS + 1);
15537       return -1;
15538    }
15539 
15540    if (cur_ss7type < 0) {
15541       ast_log(LOG_ERROR, "Unspecified or invalid ss7type\n");
15542       return -1;
15543    }
15544 
15545    if (!link->ss7)
15546       link->ss7 = ss7_new(cur_ss7type);
15547 
15548    if (!link->ss7) {
15549       ast_log(LOG_ERROR, "Can't create new SS7!\n");
15550       return -1;
15551    }
15552 
15553    link->type = cur_ss7type;
15554 
15555    if (cur_pointcode < 0) {
15556       ast_log(LOG_ERROR, "Unspecified pointcode!\n");
15557       return -1;
15558    } else
15559       ss7_set_pc(link->ss7, cur_pointcode);
15560 
15561    if (sigchan < 0) {
15562       ast_log(LOG_ERROR, "Invalid sigchan!\n");
15563       return -1;
15564    } else {
15565       if (link->numsigchans >= NUM_DCHANS) {
15566          ast_log(LOG_ERROR, "Too many sigchans on linkset %d\n", cur_linkset);
15567          return -1;
15568       }
15569       curfd = link->numsigchans;
15570 
15571       link->fds[curfd] = open("/dev/dahdi/channel", O_RDWR, 0600);
15572       if ((link->fds[curfd] < 0) || (ioctl(link->fds[curfd],DAHDI_SPECIFY,&sigchan) == -1)) {
15573          ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan, strerror(errno));
15574          return -1;
15575       }
15576       memset(&p, 0, sizeof(p));
15577       res = ioctl(link->fds[curfd], DAHDI_GET_PARAMS, &p);
15578       if (res) {
15579          dahdi_close_ss7_fd(link, curfd);
15580          ast_log(LOG_ERROR, "Unable to get parameters for sigchan %d (%s)\n", sigchan, strerror(errno));
15581          return -1;
15582       }
15583       if ((p.sigtype != DAHDI_SIG_HDLCFCS) && (p.sigtype != DAHDI_SIG_HARDHDLC) && (p.sigtype != DAHDI_SIG_MTP2)) {
15584          dahdi_close_ss7_fd(link, curfd);
15585          ast_log(LOG_ERROR, "sigchan %d is not in HDLC/FCS mode.\n", sigchan);
15586          return -1;
15587       }
15588 
15589       memset(&bi, 0, sizeof(bi));
15590       bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
15591       bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
15592       bi.numbufs = 32;
15593       bi.bufsize = 512;
15594 
15595       if (ioctl(link->fds[curfd], DAHDI_SET_BUFINFO, &bi)) {
15596          ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", sigchan, strerror(errno));
15597          dahdi_close_ss7_fd(link, curfd);
15598          return -1;
15599       }
15600 
15601       if (p.sigtype == DAHDI_SIG_MTP2)
15602          ss7_add_link(link->ss7, SS7_TRANSPORT_DAHDIMTP2, link->fds[curfd]);
15603       else
15604          ss7_add_link(link->ss7, SS7_TRANSPORT_DAHDIDCHAN, link->fds[curfd]);
15605 
15606       link->numsigchans++;
15607 
15608       memset(&si, 0, sizeof(si));
15609       res = ioctl(link->fds[curfd], DAHDI_SPANSTAT, &si);
15610       if (res) {
15611          dahdi_close_ss7_fd(link, curfd);
15612          ast_log(LOG_ERROR, "Unable to get span state for sigchan %d (%s)\n", sigchan, strerror(errno));
15613       }
15614 
15615       if (!si.alarms) {
15616          link->linkstate[curfd] = LINKSTATE_DOWN;
15617          ss7_link_noalarm(link->ss7, link->fds[curfd]);
15618       } else {
15619          link->linkstate[curfd] = LINKSTATE_DOWN | LINKSTATE_INALARM;
15620          ss7_link_alarm(link->ss7, link->fds[curfd]);
15621       }
15622    }
15623 
15624    if (cur_adjpointcode < 0) {
15625       ast_log(LOG_ERROR, "Unspecified adjpointcode!\n");
15626       return -1;
15627    } else {
15628       ss7_set_adjpc(link->ss7, link->fds[curfd], cur_adjpointcode);
15629    }
15630 
15631    if (cur_defaultdpc < 0) {
15632       ast_log(LOG_ERROR, "Unspecified defaultdpc!\n");
15633       return -1;
15634    }
15635 
15636    if (cur_networkindicator < 0) {
15637       ast_log(LOG_ERROR, "Invalid networkindicator!\n");
15638       return -1;
15639    } else
15640       ss7_set_network_ind(link->ss7, cur_networkindicator);
15641 
15642    return 0;
15643 }

static int load_module ( void   )  [static]

Definition at line 17396 of file chan_dahdi.c.

References __unload_module(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdirestart(), action_dahdishowchannels(), action_transfer(), action_transferhangup(), ARRAY_LEN, ast_channel_register(), ast_cli_register_multiple(), ast_cond_init(), ast_log(), ast_manager_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, ast_mutex_init(), AST_PTHREADT_NULL, ast_register_application_xml, ast_string_field_init, ast_string_field_set, dahdi_accept_r2_call_exec(), dahdi_pri_error(), dahdi_pri_message(), dahdi_send_keypad_facility_exec(), dahdi_ss7_error(), dahdi_ss7_message(), inuse, linksets, lock, LOG_ERROR, dahdi_ss7::master, dahdi_pri::master, name, NUM_DCHANS, NUM_SPANS, dahdi_pri::offset, pris, and setup_dahdi().

17397 {
17398    int res;
17399 #if defined(HAVE_PRI) || defined(HAVE_SS7)
17400    int y, i;
17401 #endif
17402 
17403 #ifdef HAVE_PRI
17404    memset(pris, 0, sizeof(pris));
17405    for (y = 0; y < NUM_SPANS; y++) {
17406       ast_mutex_init(&pris[y].lock);
17407       pris[y].offset = -1;
17408       pris[y].master = AST_PTHREADT_NULL;
17409       for (i = 0; i < NUM_DCHANS; i++)
17410          pris[y].fds[i] = -1;
17411    }
17412    pri_set_error(dahdi_pri_error);
17413    pri_set_message(dahdi_pri_message);
17414    ast_register_application_xml(dahdi_send_keypad_facility_app, dahdi_send_keypad_facility_exec);
17415 #ifdef HAVE_PRI_PROG_W_CAUSE
17416    ast_register_application_xml(dahdi_send_callrerouting_facility_app, dahdi_send_callrerouting_facility_exec);
17417 #endif
17418 #endif
17419 #ifdef HAVE_SS7
17420    memset(linksets, 0, sizeof(linksets));
17421    for (y = 0; y < NUM_SPANS; y++) {
17422       ast_mutex_init(&linksets[y].lock);
17423       linksets[y].master = AST_PTHREADT_NULL;
17424       for (i = 0; i < NUM_DCHANS; i++)
17425          linksets[y].fds[i] = -1;
17426    }
17427    ss7_set_error(dahdi_ss7_error);
17428    ss7_set_message(dahdi_ss7_message);
17429 #endif /* HAVE_SS7 */
17430    res = setup_dahdi(0);
17431    /* Make sure we can register our DAHDI channel type */
17432    if (res)
17433       return AST_MODULE_LOAD_DECLINE;
17434    if (ast_channel_register(&dahdi_tech)) {
17435       ast_log(LOG_ERROR, "Unable to register channel class 'DAHDI'\n");
17436       __unload_module();
17437       return AST_MODULE_LOAD_FAILURE;
17438    }
17439 #ifdef HAVE_PRI
17440    ast_string_field_init(&inuse, 16);
17441    ast_string_field_set(&inuse, name, "GR-303InUse");
17442    ast_cli_register_multiple(dahdi_pri_cli, ARRAY_LEN(dahdi_pri_cli));
17443 #endif
17444 #ifdef HAVE_SS7
17445    ast_cli_register_multiple(dahdi_ss7_cli, ARRAY_LEN(dahdi_ss7_cli));
17446 #endif
17447 #ifdef HAVE_OPENR2
17448    ast_cli_register_multiple(dahdi_mfcr2_cli, sizeof(dahdi_mfcr2_cli)/sizeof(dahdi_mfcr2_cli[0]));
17449    ast_register_application_xml(dahdi_accept_r2_call_app, dahdi_accept_r2_call_exec);
17450 #endif
17451 
17452    ast_cli_register_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli));
17453 
17454    memset(round_robin, 0, sizeof(round_robin));
17455    ast_manager_register( "DAHDITransfer", 0, action_transfer, "Transfer DAHDI Channel" );
17456    ast_manager_register( "DAHDIHangup", 0, action_transferhangup, "Hangup DAHDI Channel" );
17457    ast_manager_register( "DAHDIDialOffhook", 0, action_dahdidialoffhook, "Dial over DAHDI channel while offhook" );
17458    ast_manager_register( "DAHDIDNDon", 0, action_dahdidndon, "Toggle DAHDI channel Do Not Disturb status ON" );
17459    ast_manager_register( "DAHDIDNDoff", 0, action_dahdidndoff, "Toggle DAHDI channel Do Not Disturb status OFF" );
17460    ast_manager_register("DAHDIShowChannels", 0, action_dahdishowchannels, "Show status DAHDI channels");
17461    ast_manager_register("DAHDIRestart", 0, action_dahdirestart, "Fully Restart DAHDI channels (terminates calls)");
17462 
17463    ast_cond_init(&ss_thread_complete, NULL);
17464 
17465    return res;
17466 }

static void* mfcr2_monitor ( void *  data  )  [static]

Definition at line 12071 of file chan_dahdi.c.

References ast_log(), errno, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, and SUB_REAL.

Referenced by setup_dahdi().

12072 {
12073    struct dahdi_mfcr2 *mfcr2 = data;
12074    /* we should be using pthread_key_create
12075       and allocate pollers dynamically.
12076       I think do_monitor() could be leaking, since it
12077       could be cancelled at any time and is not
12078       using thread keys, why?, */
12079    struct pollfd pollers[sizeof(mfcr2->pvts)];
12080    int res = 0;
12081    int i = 0;
12082    int oldstate = 0;
12083    int quit_loop = 0;
12084    int maxsleep = 20;
12085    int was_idle = 0;
12086    int pollsize = 0;
12087    /* now that we're ready to get calls, unblock our side and
12088       get current line state */
12089    for (i = 0; i < mfcr2->numchans; i++) {
12090       openr2_chan_set_idle(mfcr2->pvts[i]->r2chan);
12091       openr2_chan_handle_cas(mfcr2->pvts[i]->r2chan);
12092    }
12093    while (1) {
12094       /* we trust here that the mfcr2 channel list will not ever change once
12095          the module is loaded */
12096       pollsize = 0;
12097       for (i = 0; i < mfcr2->numchans; i++) {
12098          pollers[i].revents = 0;
12099          pollers[i].events = 0;
12100          if (mfcr2->pvts[i]->owner) {
12101             continue;
12102          }
12103          if (!mfcr2->pvts[i]->r2chan) {
12104             ast_log(LOG_DEBUG, "Wow, no r2chan on channel %d\n", mfcr2->pvts[i]->channel);
12105             quit_loop = 1;
12106             break;
12107          }
12108          openr2_chan_enable_read(mfcr2->pvts[i]->r2chan);
12109          pollers[i].events = POLLIN | POLLPRI;
12110          pollers[i].fd = mfcr2->pvts[i]->subs[SUB_REAL].dfd;
12111          pollsize++;
12112       }
12113       if (quit_loop) {
12114          break;
12115       }
12116       if (pollsize == 0) {
12117          if (!was_idle) {
12118             ast_log(LOG_DEBUG, "Monitor thread going idle since everybody has an owner\n");
12119             was_idle = 1;
12120          }
12121          poll(NULL, 0, maxsleep);
12122          continue;
12123       }
12124       was_idle = 0;
12125       /* probably poll() is a valid cancel point, lets just be on the safe side
12126          by calling pthread_testcancel */
12127       pthread_testcancel();
12128       res = poll(pollers, mfcr2->numchans, maxsleep);
12129       pthread_testcancel();
12130       if ((res < 0) && (errno != EINTR)) {
12131          ast_log(LOG_ERROR, "going out, poll failed: %s\n", strerror(errno));
12132          break;
12133       }
12134       /* do we want to allow to cancel while processing events? */
12135       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
12136       for (i = 0; i < mfcr2->numchans; i++) {
12137          if (pollers[i].revents & POLLPRI || pollers[i].revents & POLLIN) {
12138             openr2_chan_process_event(mfcr2->pvts[i]->r2chan);
12139          }
12140       }
12141       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
12142    }
12143    ast_log(LOG_NOTICE, "Quitting MFC/R2 monitor thread\n");
12144    return 0;
12145 }

static struct dahdi_pvt* mkintf ( int  channel,
const struct dahdi_chan_conf *  conf,
struct dahdi_pri *  pri,
int  reloading 
) [static, read]

Definition at line 10094 of file chan_dahdi.c.

References dahdi_mfcr2_conf::accept_on_offer, dahdi_pvt::accountcode, dahdi_pvt::adsi, dahdi_mfcr2_conf::allow_collect_calls, dahdi_pvt::amaflags, dahdi_pvt::answeronpolarityswitch, ast_calloc, ast_copy_string(), ast_dsp_set_digitmode(), AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_MWI, ast_event_subscribe(), ast_log(), ast_mutex_init(), ast_smdi_interface_find(), ast_strdupa, ast_strlen_zero(), ast_variable_new(), dahdi_pvt::buf_no, dahdi_pvt::buf_policy, dahdi_pvt::bufsize, dahdi_pvt::busy_quietlength, dahdi_pvt::busy_tonelength, dahdi_pvt::busycount, dahdi_pvt::busydetect, dahdi_pvt::call, dahdi_mfcr2_conf::call_files, dahdi_ss7::called_nai, dahdi_pvt::callgroup, dahdi_ss7::calling_nai, dahdi_pvt::callprogress, dahdi_pvt::callreturn, dahdi_pvt::callwaiting, dahdi_pvt::callwaitingcallerid, dahdi_pvt::cancallforward, dahdi_pvt::canpark, dahdi_mfcr2_conf::category, dahdi_chan_conf::chan, CHAN_PSEUDO, dahdi_pvt::channel, dahdi_mfcr2_conf::charge_calls, dahdi_pvt::cic, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::cid_rxgain, CID_SIG_SMDI, dahdi_pvt::cid_signalling, dahdi_pvt::cid_start, dahdi_pvt::cid_ton, dahdi_pvt::confno, context, dahdi_pvt::context, dahdi_pri::crvend, dahdi_pri::crvs, dahdi_open(), dahdi_r2_get_link(), dahdi_r2_on_chan_log(), dahdi_r2_set_context(), dahdi_set_hook(), dahdi_pvt::dahditrcallerid, dahdi_pvt::defcontext, dahdi_pvt::destroy, destroy_dahdi_pvt(), dahdi_subchannel::dfd, dahdi_pri::dialplan, dialplan2str(), dahdi_pri::discardremoteholdretrieval, dahdi_pvt::dpc, dahdi_pvt::drings, dahdi_pvt::dsp, DSP_DIGITMODE_DTMF, dahdi_pvt::dtmfrelax, dahdi_pvt::echocanbridged, dahdi_pvt::echocancel, dahdi_pvt::echotraining, errno, dahdi_pri::facilityenable, dahdi_pvt::faxbuf_no, dahdi_pvt::faxbuf_policy, ast_variable::file, dahdi_pvt::firstradio, dahdi_mfcr2_conf::forced_release, free, dahdi_pvt::fxsoffhookstate, get_alarms(), dahdi_pvt::group, handle_alarms(), dahdi_pvt::hanguponpolarityswitch, dahdi_pvt::head, dahdi_pvt::hidecallerid, dahdi_pvt::hidecalleridname, dahdi_pri::idledial, dahdi_pri::idleext, iflist, dahdi_pvt::immediate, dahdi_pvt::inalarm, dahdi_pri::inbanddisconnect, dahdi_pvt::inservice, dahdi_pri::internationalprefix, dahdi_ss7::internationalprefix, dahdi_chan_conf::is_sig_auto, dahdi_pvt::language, dahdi_pvt::law, dahdi_pri::localdialplan, dahdi_pvt::locallyblocked, dahdi_pri::localprefix, dahdi_pvt::lock, LOG_ERROR, LOG_NOTICE, LOG_WARNING, dahdi_pvt::logicalspan, dahdi_mfcr2_conf::loglevel, mailbox, dahdi_pvt::mailbox, MAX_CHANNELS, dahdi_chan_conf::mfcr2, dahdi_pvt::mfcr2, dahdi_pvt::mfcr2_accept_on_offer, dahdi_pvt::mfcr2_allow_collect_calls, dahdi_pvt::mfcr2_ani_index, dahdi_pvt::mfcr2_category, dahdi_pvt::mfcr2_charge_calls, dahdi_pvt::mfcr2_dnis_index, dahdi_pvt::mfcr2_forced_release, dahdi_pvt::mfcr2call, dahdi_pri::minidle, dahdi_pri::minunused, dahdi_pvt::mohinterpret, dahdi_pvt::mohsuggest, dahdi_mfcr2::monitored_count, dahdi_pvt::msgstate, mwi_event_cb(), dahdi_pvt::mwi_event_sub, dahdi_pvt::mwimonitor_fsk, dahdi_pvt::mwimonitor_neon, dahdi_pvt::mwimonitor_rpas, dahdi_pvt::mwisend_fsk, dahdi_pvt::mwisend_rpas, dahdi_pvt::mwisend_setting, ast_variable::name, dahdi_pri::nationalprefix, dahdi_ss7::nationalprefix, ast_variable::next, dahdi_pvt::next, dahdi_pri::nodetype, dahdi_pri::nsf, NUM_DCHANS, NUM_SPANS, dahdi_pri::numchans, dahdi_mfcr2::numchans, dahdi_ss7::numchans, dahdi_pvt::onhooktime, dahdi_pvt::outsigmod, dahdi_pri::overlapdial, dahdi_pvt::parkinglot, dahdi_pvt::permcallwaiting, dahdi_pvt::permhidecallerid, dahdi_pvt::pickupgroup, dahdi_pvt::polarityonanswerdelay, dahdi_pvt::prev, dahdi_pvt::pri, dahdi_chan_conf::pri, pri_is_up(), pri_resolve_span(), dahdi_pvt::priexclusive, dahdi_pvt::priindication_oob, dahdi_pri::prilogicalspan, dahdi_pvt::prioffset, pris, dahdi_pri::privateprefix, dahdi_pvt::propconfno, dahdi_mfcr2::protocol_context, dahdi_pvt::pulse, dahdi_pri::pvts, dahdi_mfcr2::pvts, dahdi_ss7::pvts, dahdi_pri::qsigchannelmapping, dahdi_pvt::r2chan, dahdi_pvt::radio, distRingData::range, dahdi_pvt::remotelyblocked, dahdi_pri::resetinterval, dahdi_pvt::restrictcid, dahdi_distRings::ringnum, dahdi_pvt::ringt_base, dahdi_pvt::rxgain, dahdi_pvt::sendcalleridafter, set_actual_gain(), dahdi_pri::sig, dahdi_pvt::sig, sig2str, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSKS, SIG_FXSLS, SIG_GR303FXOKS, SIG_GR303FXSKS, SIG_MFCR2, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SF_FEATD, SIG_SF_FEATDMF, SIG_SFWINK, SIG_SS7, sigtype_to_signalling(), dahdi_pvt::smdi_iface, dahdi_chan_conf::smdi_port, dahdi_pvt::span, dahdi_chan_conf::ss7, dahdi_pvt::ss7, dahdi_ss7::ss7, ss7_resolve_linkset(), dahdi_pvt::ss7call, dahdi_pvt::stripmsd, strsep(), SUB_REAL, dahdi_pvt::subs, dahdi_ss7::subscriberprefix, dahdi_pri::switchtype, dahdi_pvt::threewaycalling, dahdi_chan_conf::timing, dahdi_pvt::tonezone, dahdi_pvt::transfer, dahdi_pvt::transfertobusy, dahdi_pvt::txgain, dahdi_pri::unknownprefix, dahdi_ss7::unknownprefix, update_conf(), dahdi_pvt::use_callerid, dahdi_pvt::use_callingpres, dahdi_pvt::use_smdi, dahdi_pvt::usedistinctiveringdetection, dahdi_pvt::usefaxbuffers, ast_variable::value, dahdi_pvt::vars, and dahdi_pvt::waitfordialtone.

Referenced by build_channels(), and process_dahdi().

10095 {
10096    /* Make a dahdi_pvt structure for this interface (or CRV if "pri" is specified) */
10097    struct dahdi_pvt *tmp = NULL, *tmp2, *prev = NULL;
10098    char fn[80];
10099    struct dahdi_bufferinfo bi;
10100 
10101    int res;
10102    int span = 0;
10103    int here = 0;
10104    int x;
10105    struct dahdi_pvt **wlist;
10106    struct dahdi_pvt **wend;
10107    struct dahdi_params p;
10108 
10109    wlist = &iflist;
10110    wend = &ifend;
10111 
10112 #ifdef HAVE_PRI
10113    if (pri) {
10114       wlist = &pri->crvs;
10115       wend = &pri->crvend;
10116    }
10117 #endif
10118 
10119    tmp2 = *wlist;
10120    prev = NULL;
10121 
10122    while (tmp2) {
10123       if (!tmp2->destroy) {
10124          if (tmp2->channel == channel) {
10125             tmp = tmp2;
10126             here = 1;
10127             break;
10128          }
10129          if (tmp2->channel > channel) {
10130             break;
10131          }
10132       }
10133       prev = tmp2;
10134       tmp2 = tmp2->next;
10135    }
10136 
10137    if (!here && reloading != 1) {
10138       if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
10139          if (tmp)
10140             free(tmp);
10141          return NULL;
10142       }
10143       ast_mutex_init(&tmp->lock);
10144       ifcount++;
10145       for (x = 0; x < 3; x++)
10146          tmp->subs[x].dfd = -1;
10147       tmp->channel = channel;
10148       tmp->priindication_oob = conf->chan.priindication_oob;
10149    }
10150 
10151    if (tmp) {
10152       int chan_sig = conf->chan.sig;
10153       if (!here) {
10154          if ((channel != CHAN_PSEUDO) && !pri) {
10155             int count = 0;
10156             snprintf(fn, sizeof(fn), "%d", channel);
10157             /* Open non-blocking */
10158             tmp->subs[SUB_REAL].dfd = dahdi_open(fn);
10159             while (tmp->subs[SUB_REAL].dfd < 0 && reloading == 2 && count < 1000) { /* the kernel may not call dahdi_release fast enough for the open flagbit to be cleared in time */
10160                usleep(1);
10161                tmp->subs[SUB_REAL].dfd = dahdi_open(fn);
10162                count++;
10163             }
10164             /* Allocate a DAHDI structure */
10165             if (tmp->subs[SUB_REAL].dfd < 0) {
10166                ast_log(LOG_ERROR, "Unable to open channel %d: %s\nhere = %d, tmp->channel = %d, channel = %d\n", channel, strerror(errno), here, tmp->channel, channel);
10167                destroy_dahdi_pvt(&tmp);
10168                return NULL;
10169             }
10170             memset(&p, 0, sizeof(p));
10171             res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p);
10172             if (res < 0) {
10173                ast_log(LOG_ERROR, "Unable to get parameters: %s\n", strerror(errno));
10174                destroy_dahdi_pvt(&tmp);
10175                return NULL;
10176             }
10177             if (conf->is_sig_auto)
10178                chan_sig = sigtype_to_signalling(p.sigtype);
10179             if (p.sigtype != (chan_sig & 0x3ffff)) {
10180                ast_log(LOG_ERROR, "Signalling requested on channel %d is %s but line is in %s signalling\n", channel, sig2str(chan_sig), sig2str(p.sigtype));
10181                destroy_dahdi_pvt(&tmp);
10182                return NULL;
10183             }
10184             tmp->law = p.curlaw;
10185             tmp->span = p.spanno;
10186             span = p.spanno - 1;
10187          } else {
10188             if (channel == CHAN_PSEUDO)
10189                chan_sig = 0;
10190             else if ((chan_sig != SIG_FXOKS) && (chan_sig != SIG_FXSKS)) {
10191                ast_log(LOG_ERROR, "CRV's must use FXO/FXS Kewl Start (fxo_ks/fxs_ks) signalling only.\n");
10192                return NULL;
10193             }
10194          }
10195          tmp->outsigmod = conf->chan.outsigmod;
10196 
10197 #ifdef HAVE_SS7
10198          if (chan_sig == SIG_SS7) {
10199             struct dahdi_ss7 *ss7;
10200             int clear = 0;
10201             if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &clear)) {
10202                ast_log(LOG_ERROR, "Unable to set clear mode on clear channel %d of span %d: %s\n", channel, p.spanno, strerror(errno));
10203                destroy_dahdi_pvt(&tmp);
10204                return NULL;
10205             }
10206 
10207             ss7 = ss7_resolve_linkset(cur_linkset);
10208             if (!ss7) {
10209                ast_log(LOG_ERROR, "Unable to find linkset %d\n", cur_linkset);
10210                destroy_dahdi_pvt(&tmp);
10211                return NULL;
10212             }
10213             if (cur_cicbeginswith < 0) {
10214                ast_log(LOG_ERROR, "Need to set cicbeginswith for the channels!\n");
10215                destroy_dahdi_pvt(&tmp);
10216                return NULL;
10217             }
10218 
10219             tmp->cic = cur_cicbeginswith++;
10220 
10221             /* DB: Add CIC's DPC information */
10222             tmp->dpc = cur_defaultdpc;
10223 
10224             tmp->ss7 = ss7;
10225             tmp->ss7call = NULL;
10226             ss7->pvts[ss7->numchans++] = tmp;
10227 
10228             ast_copy_string(ss7->internationalprefix, conf->ss7.internationalprefix, sizeof(ss7->internationalprefix));
10229             ast_copy_string(ss7->nationalprefix, conf->ss7.nationalprefix, sizeof(ss7->nationalprefix));
10230             ast_copy_string(ss7->subscriberprefix, conf->ss7.subscriberprefix, sizeof(ss7->subscriberprefix));
10231             ast_copy_string(ss7->unknownprefix, conf->ss7.unknownprefix, sizeof(ss7->unknownprefix));
10232 
10233             ss7->called_nai = conf->ss7.called_nai;
10234             ss7->calling_nai = conf->ss7.calling_nai;
10235          }
10236 #endif
10237 #ifdef HAVE_OPENR2
10238          if (chan_sig == SIG_MFCR2 && reloading != 1) {
10239             struct dahdi_mfcr2 *r2_link;
10240             r2_link = dahdi_r2_get_link();
10241             if (!r2_link) {
10242                ast_log(LOG_WARNING, "Cannot get another R2 DAHDI context!\n");
10243                destroy_dahdi_pvt(&tmp);
10244                return NULL;
10245             }
10246             if (!r2_link->protocol_context && dahdi_r2_set_context(r2_link, conf)) {
10247                ast_log(LOG_ERROR, "Cannot create OpenR2 protocol context.\n");
10248                destroy_dahdi_pvt(&tmp);
10249                return NULL;
10250             }
10251             if (r2_link->numchans == (sizeof(r2_link->pvts)/sizeof(r2_link->pvts[0]))) {
10252                ast_log(LOG_ERROR, "Cannot add more channels to this link!\n");
10253                destroy_dahdi_pvt(&tmp);
10254                return NULL;
10255             }
10256             r2_link->pvts[r2_link->numchans++] = tmp;
10257             tmp->r2chan = openr2_chan_new_from_fd(r2_link->protocol_context,
10258                                         tmp->subs[SUB_REAL].dfd,
10259                                         NULL, NULL);
10260             if (!tmp->r2chan) {
10261                openr2_liberr_t err = openr2_context_get_last_error(r2_link->protocol_context);
10262                ast_log(LOG_ERROR, "Cannot create OpenR2 channel: %s\n", openr2_context_error_string(err));
10263                destroy_dahdi_pvt(&tmp);
10264                return NULL;
10265             }
10266             tmp->mfcr2 = r2_link;
10267             if (conf->mfcr2.call_files) {
10268                openr2_chan_enable_call_files(tmp->r2chan);
10269             }
10270             openr2_chan_set_client_data(tmp->r2chan, tmp);
10271             /* cast seems to be needed to get rid of the annoying warning regarding format attribute  */
10272             openr2_chan_set_logging_func(tmp->r2chan, (openr2_logging_func_t)dahdi_r2_on_chan_log);
10273             openr2_chan_set_log_level(tmp->r2chan, conf->mfcr2.loglevel);
10274             tmp->mfcr2_category = conf->mfcr2.category;
10275             tmp->mfcr2_charge_calls = conf->mfcr2.charge_calls;
10276             tmp->mfcr2_allow_collect_calls = conf->mfcr2.allow_collect_calls;
10277             tmp->mfcr2_forced_release = conf->mfcr2.forced_release;
10278             tmp->mfcr2_accept_on_offer = conf->mfcr2.accept_on_offer;
10279             tmp->mfcr2call = 0;
10280             tmp->mfcr2_dnis_index = 0;
10281             tmp->mfcr2_ani_index = 0;
10282             r2_link->monitored_count++;
10283          }
10284 #endif
10285 #ifdef HAVE_PRI
10286          if ((chan_sig == SIG_PRI) || (chan_sig == SIG_BRI) || (chan_sig == SIG_BRI_PTMP) || (chan_sig == SIG_GR303FXOKS) || (chan_sig == SIG_GR303FXSKS)) {
10287             int offset;
10288             int myswitchtype;
10289             int matchesdchan;
10290             int x,y;
10291             offset = 0;
10292             if (((chan_sig == SIG_PRI) || (chan_sig == SIG_BRI) || (chan_sig == SIG_BRI_PTMP))
10293                   && ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &offset)) {
10294                ast_log(LOG_ERROR, "Unable to set clear mode on clear channel %d of span %d: %s\n", channel, p.spanno, strerror(errno));
10295                destroy_dahdi_pvt(&tmp);
10296                return NULL;
10297             }
10298             if (span >= NUM_SPANS) {
10299                ast_log(LOG_ERROR, "Channel %d does not lie on a span I know of (%d)\n", channel, span);
10300                destroy_dahdi_pvt(&tmp);
10301                return NULL;
10302             } else {
10303                struct dahdi_spaninfo si;
10304                si.spanno = 0;
10305                if (ioctl(tmp->subs[SUB_REAL].dfd,DAHDI_SPANSTAT,&si) == -1) {
10306                   ast_log(LOG_ERROR, "Unable to get span status: %s\n", strerror(errno));
10307                   destroy_dahdi_pvt(&tmp);
10308                   return NULL;
10309                }
10310                /* Store the logical span first based upon the real span */
10311                tmp->logicalspan = pris[span].prilogicalspan;
10312                pri_resolve_span(&span, channel, (channel - p.chanpos), &si);
10313                if (span < 0) {
10314                   ast_log(LOG_WARNING, "Channel %d: Unable to find locate channel/trunk group!\n", channel);
10315                   destroy_dahdi_pvt(&tmp);
10316                   return NULL;
10317                }
10318                if ((chan_sig == SIG_PRI) ||
10319                      (chan_sig == SIG_BRI) ||
10320                      (chan_sig == SIG_BRI_PTMP))
10321                   myswitchtype = conf->pri.switchtype;
10322                else
10323                   myswitchtype = PRI_SWITCH_GR303_TMC;
10324                /* Make sure this isn't a d-channel */
10325                matchesdchan=0;
10326                for (x = 0; x < NUM_SPANS; x++) {
10327                   for (y = 0; y < NUM_DCHANS; y++) {
10328                      if (pris[x].dchannels[y] == tmp->channel) {
10329                         matchesdchan = 1;
10330                         break;
10331                      }
10332                   }
10333                }
10334                offset = p.chanpos;
10335                if (!matchesdchan) {
10336                   if (pris[span].nodetype && (pris[span].nodetype != conf->pri.nodetype)) {
10337                      ast_log(LOG_ERROR, "Span %d is already a %s node\n", span + 1, pri_node2str(pris[span].nodetype));
10338                      destroy_dahdi_pvt(&tmp);
10339                      return NULL;
10340                   }
10341                   if (pris[span].switchtype && (pris[span].switchtype != myswitchtype)) {
10342                      ast_log(LOG_ERROR, "Span %d is already a %s switch\n", span + 1, pri_switch2str(pris[span].switchtype));
10343                      destroy_dahdi_pvt(&tmp);
10344                      return NULL;
10345                   }
10346                   if ((pris[span].dialplan) && (pris[span].dialplan != conf->pri.dialplan)) {
10347                      ast_log(LOG_ERROR, "Span %d is already a %s dialing plan\n", span + 1, dialplan2str(pris[span].dialplan));
10348                      destroy_dahdi_pvt(&tmp);
10349                      return NULL;
10350                   }
10351                   if (!ast_strlen_zero(pris[span].idledial) && strcmp(pris[span].idledial, conf->pri.idledial)) {
10352                      ast_log(LOG_ERROR, "Span %d already has idledial '%s'.\n", span + 1, conf->pri.idledial);
10353                      destroy_dahdi_pvt(&tmp);
10354                      return NULL;
10355                   }
10356                   if (!ast_strlen_zero(pris[span].idleext) && strcmp(pris[span].idleext, conf->pri.idleext)) {
10357                      ast_log(LOG_ERROR, "Span %d already has idleext '%s'.\n", span + 1, conf->pri.idleext);
10358                      destroy_dahdi_pvt(&tmp);
10359                      return NULL;
10360                   }
10361                   if (pris[span].minunused && (pris[span].minunused != conf->pri.minunused)) {
10362                      ast_log(LOG_ERROR, "Span %d already has minunused of %d.\n", span + 1, conf->pri.minunused);
10363                      destroy_dahdi_pvt(&tmp);
10364                      return NULL;
10365                   }
10366                   if (pris[span].minidle && (pris[span].minidle != conf->pri.minidle)) {
10367                      ast_log(LOG_ERROR, "Span %d already has minidle of %d.\n", span + 1, conf->pri.minidle);
10368                      destroy_dahdi_pvt(&tmp);
10369                      return NULL;
10370                   }
10371                   if (pris[span].numchans >= MAX_CHANNELS) {
10372                      ast_log(LOG_ERROR, "Unable to add channel %d: Too many channels in trunk group %d!\n", channel,
10373                         pris[span].trunkgroup);
10374                      destroy_dahdi_pvt(&tmp);
10375                      return NULL;
10376                   }
10377 
10378                   pris[span].sig = chan_sig;
10379                   pris[span].nodetype = conf->pri.nodetype;
10380                   pris[span].switchtype = myswitchtype;
10381                   pris[span].nsf = conf->pri.nsf;
10382                   pris[span].dialplan = conf->pri.dialplan;
10383                   pris[span].localdialplan = conf->pri.localdialplan;
10384                   pris[span].pvts[pris[span].numchans++] = tmp;
10385                   pris[span].minunused = conf->pri.minunused;
10386                   pris[span].minidle = conf->pri.minidle;
10387                   pris[span].overlapdial = conf->pri.overlapdial;
10388                   pris[span].qsigchannelmapping = conf->pri.qsigchannelmapping;
10389                   pris[span].discardremoteholdretrieval = conf->pri.discardremoteholdretrieval;
10390 #ifdef HAVE_PRI_INBANDDISCONNECT
10391                   pris[span].inbanddisconnect = conf->pri.inbanddisconnect;
10392 #endif
10393                   pris[span].facilityenable = conf->pri.facilityenable;
10394                   ast_copy_string(pris[span].idledial, conf->pri.idledial, sizeof(pris[span].idledial));
10395                   ast_copy_string(pris[span].idleext, conf->pri.idleext, sizeof(pris[span].idleext));
10396                   ast_copy_string(pris[span].internationalprefix, conf->pri.internationalprefix, sizeof(pris[span].internationalprefix));
10397                   ast_copy_string(pris[span].nationalprefix, conf->pri.nationalprefix, sizeof(pris[span].nationalprefix));
10398                   ast_copy_string(pris[span].localprefix, conf->pri.localprefix, sizeof(pris[span].localprefix));
10399                   ast_copy_string(pris[span].privateprefix, conf->pri.privateprefix, sizeof(pris[span].privateprefix));
10400                   ast_copy_string(pris[span].unknownprefix, conf->pri.unknownprefix, sizeof(pris[span].unknownprefix));
10401                   pris[span].resetinterval = conf->pri.resetinterval;
10402 
10403                   tmp->pri = &pris[span];
10404                   tmp->prioffset = offset;
10405                   tmp->call = NULL;
10406 
10407                   tmp->priexclusive = conf->chan.priexclusive;
10408                } else {
10409                   ast_log(LOG_ERROR, "Channel %d is reserved for D-channel.\n", offset);
10410                   destroy_dahdi_pvt(&tmp);
10411                   return NULL;
10412                }
10413             }
10414          } else {
10415             tmp->prioffset = 0;
10416          }
10417 #endif
10418       } else {
10419          chan_sig = tmp->sig;
10420          if (tmp->subs[SUB_REAL].dfd > -1) {
10421             memset(&p, 0, sizeof(p));
10422             res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p);
10423          }
10424       }
10425       /* Adjust starttime on loopstart and kewlstart trunks to reasonable values */
10426       switch (chan_sig) {
10427       case SIG_FXSKS:
10428       case SIG_FXSLS:
10429       case SIG_EM:
10430       case SIG_EM_E1:
10431       case SIG_EMWINK:
10432       case SIG_FEATD:
10433       case SIG_FEATDMF:
10434       case SIG_FEATDMF_TA:
10435       case SIG_FEATB:
10436       case SIG_E911:
10437       case SIG_SF:
10438       case SIG_SFWINK:
10439       case SIG_FGC_CAMA:
10440       case SIG_FGC_CAMAMF:
10441       case SIG_SF_FEATD:
10442       case SIG_SF_FEATDMF:
10443       case SIG_SF_FEATB:
10444          p.starttime = 250;
10445          break;
10446       }
10447 
10448       if (tmp->radio) {
10449          /* XXX Waiting to hear back from Jim if these should be adjustable XXX */
10450          p.channo = channel;
10451          p.rxwinktime = 1;
10452          p.rxflashtime = 1;
10453          p.starttime = 1;
10454          p.debouncetime = 5;
10455       }
10456       if (!tmp->radio) {
10457          p.channo = channel;
10458          /* Override timing settings based on config file */
10459          if (conf->timing.prewinktime >= 0)
10460             p.prewinktime = conf->timing.prewinktime;
10461          if (conf->timing.preflashtime >= 0)
10462             p.preflashtime = conf->timing.preflashtime;
10463          if (conf->timing.winktime >= 0)
10464             p.winktime = conf->timing.winktime;
10465          if (conf->timing.flashtime >= 0)
10466             p.flashtime = conf->timing.flashtime;
10467          if (conf->timing.starttime >= 0)
10468             p.starttime = conf->timing.starttime;
10469          if (conf->timing.rxwinktime >= 0)
10470             p.rxwinktime = conf->timing.rxwinktime;
10471          if (conf->timing.rxflashtime >= 0)
10472             p.rxflashtime = conf->timing.rxflashtime;
10473          if (conf->timing.debouncetime >= 0)
10474             p.debouncetime = conf->timing.debouncetime;
10475       }
10476 
10477       /* dont set parms on a pseudo-channel (or CRV) */
10478       if (tmp->subs[SUB_REAL].dfd >= 0)
10479       {
10480          res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_SET_PARAMS, &p);
10481          if (res < 0) {
10482             ast_log(LOG_ERROR, "Unable to set parameters: %s\n", strerror(errno));
10483             destroy_dahdi_pvt(&tmp);
10484             return NULL;
10485          }
10486       }
10487 #if 1
10488       if (!here && (tmp->subs[SUB_REAL].dfd > -1)) {
10489          memset(&bi, 0, sizeof(bi));
10490          res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_BUFINFO, &bi);
10491          if (!res) {
10492             bi.txbufpolicy = conf->chan.buf_policy;
10493             bi.rxbufpolicy = conf->chan.buf_policy;
10494             bi.numbufs = conf->chan.buf_no;
10495             res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi);
10496             if (res < 0) {
10497                ast_log(LOG_WARNING, "Unable to set buffer policy on channel %d: %s\n", channel, strerror(errno));
10498             }
10499          } else {
10500             ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d: %s\n", channel, strerror(errno));
10501          }
10502          tmp->buf_policy = conf->chan.buf_policy;
10503          tmp->buf_no = conf->chan.buf_no;
10504          tmp->usefaxbuffers = conf->chan.usefaxbuffers;
10505          tmp->faxbuf_policy = conf->chan.faxbuf_policy;
10506          tmp->faxbuf_no = conf->chan.faxbuf_no;
10507          /* This is not as gnarly as it may first appear.  If the ioctl above failed, we'd be setting
10508           * tmp->bufsize to zero which would cause subsequent faxbuffer-related ioctl calls to fail.
10509           * The reason the ioctl call above failed should to be determined before worrying about the
10510           * faxbuffer-related ioctl calls */
10511          tmp->bufsize = bi.bufsize;
10512       }
10513 #endif
10514       tmp->immediate = conf->chan.immediate;
10515       tmp->transfertobusy = conf->chan.transfertobusy;
10516       if (chan_sig & __DAHDI_SIG_FXS) {
10517          tmp->mwimonitor_fsk = conf->chan.mwimonitor_fsk;
10518          tmp->mwimonitor_neon = conf->chan.mwimonitor_neon;
10519          tmp->mwimonitor_rpas = conf->chan.mwimonitor_rpas;
10520       }
10521       tmp->sig = chan_sig;
10522       tmp->ringt_base = ringt_base;
10523       tmp->firstradio = 0;
10524       if ((chan_sig == SIG_FXOKS) || (chan_sig == SIG_FXOLS) || (chan_sig == SIG_FXOGS))
10525          tmp->permcallwaiting = conf->chan.callwaiting;
10526       else
10527          tmp->permcallwaiting = 0;
10528       /* Flag to destroy the channel must be cleared on new mkif.  Part of changes for reload to work */
10529       tmp->destroy = 0;
10530       tmp->drings = conf->chan.drings;
10531 
10532       /* 10 is a nice default. */
10533       if (tmp->drings.ringnum[0].range == 0)
10534          tmp->drings.ringnum[0].range = 10;
10535       if (tmp->drings.ringnum[1].range == 0)
10536          tmp->drings.ringnum[1].range = 10;
10537       if (tmp->drings.ringnum[2].range == 0)
10538          tmp->drings.ringnum[2].range = 10;
10539 
10540       tmp->usedistinctiveringdetection = usedistinctiveringdetection;
10541       tmp->callwaitingcallerid = conf->chan.callwaitingcallerid;
10542       tmp->threewaycalling = conf->chan.threewaycalling;
10543       tmp->adsi = conf->chan.adsi;
10544       tmp->use_smdi = conf->chan.use_smdi;
10545       tmp->permhidecallerid = conf->chan.hidecallerid;
10546       tmp->hidecalleridname = conf->chan.hidecalleridname;
10547       tmp->callreturn = conf->chan.callreturn;
10548       tmp->echocancel = conf->chan.echocancel;
10549       tmp->echotraining = conf->chan.echotraining;
10550       tmp->pulse = conf->chan.pulse;
10551       if (tmp->echocancel.head.tap_length) {
10552          tmp->echocanbridged = conf->chan.echocanbridged;
10553       } else {
10554          if (conf->chan.echocanbridged)
10555             ast_log(LOG_NOTICE, "echocancelwhenbridged requires echocancel to be enabled; ignoring\n");
10556          tmp->echocanbridged = 0;
10557       }
10558       tmp->busydetect = conf->chan.busydetect;
10559       tmp->busycount = conf->chan.busycount;
10560       tmp->busy_tonelength = conf->chan.busy_tonelength;
10561       tmp->busy_quietlength = conf->chan.busy_quietlength;
10562       tmp->callprogress = conf->chan.callprogress;
10563       tmp->waitfordialtone = conf->chan.waitfordialtone;
10564       tmp->cancallforward = conf->chan.cancallforward;
10565       tmp->dtmfrelax = conf->chan.dtmfrelax;
10566       tmp->callwaiting = tmp->permcallwaiting;
10567       tmp->hidecallerid = tmp->permhidecallerid;
10568       tmp->channel = channel;
10569       tmp->stripmsd = conf->chan.stripmsd;
10570       tmp->use_callerid = conf->chan.use_callerid;
10571       tmp->cid_signalling = conf->chan.cid_signalling;
10572       tmp->cid_start = conf->chan.cid_start;
10573       tmp->dahditrcallerid = conf->chan.dahditrcallerid;
10574       tmp->restrictcid = conf->chan.restrictcid;
10575       tmp->use_callingpres = conf->chan.use_callingpres;
10576       if (tmp->usedistinctiveringdetection) {
10577          if (!tmp->use_callerid) {
10578             ast_log(LOG_NOTICE, "Distinctive Ring detect requires 'usecallerid' be on\n");
10579             tmp->use_callerid = 1;
10580          }
10581       }
10582 
10583       if (tmp->cid_signalling == CID_SIG_SMDI) {
10584          if (!tmp->use_smdi) {
10585             ast_log(LOG_WARNING, "SMDI callerid requires SMDI to be enabled, enabling...\n");
10586             tmp->use_smdi = 1;
10587          }
10588       }
10589       if (tmp->use_smdi) {
10590          tmp->smdi_iface = ast_smdi_interface_find(conf->smdi_port);
10591          if (!(tmp->smdi_iface)) {
10592             ast_log(LOG_ERROR, "Invalid SMDI port specfied, disabling SMDI support\n");
10593             tmp->use_smdi = 0;
10594          }
10595       }
10596 
10597       ast_copy_string(tmp->accountcode, conf->chan.accountcode, sizeof(tmp->accountcode));
10598       tmp->amaflags = conf->chan.amaflags;
10599       if (!here) {
10600          tmp->confno = -1;
10601          tmp->propconfno = -1;
10602       }
10603       tmp->canpark = conf->chan.canpark;
10604       tmp->transfer = conf->chan.transfer;
10605       ast_copy_string(tmp->defcontext,conf->chan.context,sizeof(tmp->defcontext));
10606       ast_copy_string(tmp->language, conf->chan.language, sizeof(tmp->language));
10607       ast_copy_string(tmp->mohinterpret, conf->chan.mohinterpret, sizeof(tmp->mohinterpret));
10608       ast_copy_string(tmp->mohsuggest, conf->chan.mohsuggest, sizeof(tmp->mohsuggest));
10609       ast_copy_string(tmp->context, conf->chan.context, sizeof(tmp->context));
10610       ast_copy_string(tmp->parkinglot, conf->chan.parkinglot, sizeof(tmp->parkinglot));
10611       tmp->cid_ton = 0;
10612       switch (tmp->sig) {
10613       case SIG_PRI:
10614       case SIG_BRI:
10615       case SIG_BRI_PTMP:
10616       case SIG_SS7:
10617       case SIG_MFCR2:
10618          tmp->cid_num[0] = '\0';
10619          tmp->cid_name[0] = '\0';
10620          break;
10621       default:
10622          ast_copy_string(tmp->cid_num, conf->chan.cid_num, sizeof(tmp->cid_num));
10623          ast_copy_string(tmp->cid_name, conf->chan.cid_name, sizeof(tmp->cid_name));
10624          break;
10625       }
10626       ast_copy_string(tmp->mailbox, conf->chan.mailbox, sizeof(tmp->mailbox));
10627       if (channel != CHAN_PSEUDO && !ast_strlen_zero(tmp->mailbox)) {
10628          char *mailbox, *context;
10629          mailbox = context = ast_strdupa(tmp->mailbox);
10630          strsep(&context, "@");
10631          if (ast_strlen_zero(context))
10632             context = "default";
10633          tmp->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
10634             AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
10635             AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
10636             AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
10637             AST_EVENT_IE_END);
10638       }
10639       tmp->msgstate = -1;
10640 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
10641       tmp->mwisend_setting = conf->chan.mwisend_setting;
10642       tmp->mwisend_fsk  = conf->chan.mwisend_fsk;
10643       tmp->mwisend_rpas = conf->chan.mwisend_rpas;
10644 #endif
10645       if (chan_sig & __DAHDI_SIG_FXO) {
10646          memset(&p, 0, sizeof(p));
10647          res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p);
10648          if (!res) {
10649             tmp->fxsoffhookstate = p.rxisoffhook;
10650          }
10651 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
10652          res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_VMWI_CONFIG, &tmp->mwisend_setting);
10653 #endif
10654       }
10655       tmp->onhooktime = time(NULL);
10656       tmp->group = conf->chan.group;
10657       tmp->callgroup = conf->chan.callgroup;
10658       tmp->pickupgroup= conf->chan.pickupgroup;
10659       if (conf->chan.vars) {
10660          struct ast_variable *v, *tmpvar;
10661                    for (v = conf->chan.vars ; v ; v = v->next) {
10662                          if ((tmpvar = ast_variable_new(v->name, v->value, v->file))) {
10663                                   tmpvar->next = tmp->vars;
10664                                    tmp->vars = tmpvar;
10665                            }
10666                   }
10667       }
10668       tmp->cid_rxgain = conf->chan.cid_rxgain;
10669       tmp->rxgain = conf->chan.rxgain;
10670       tmp->txgain = conf->chan.txgain;
10671       tmp->tonezone = conf->chan.tonezone;
10672       if (tmp->subs[SUB_REAL].dfd > -1) {
10673          set_actual_gain(tmp->subs[SUB_REAL].dfd, 0, tmp->rxgain, tmp->txgain, tmp->law);
10674          if (tmp->dsp)
10675             ast_dsp_set_digitmode(tmp->dsp, DSP_DIGITMODE_DTMF | tmp->dtmfrelax);
10676          update_conf(tmp);
10677          if (!here) {
10678             if ((chan_sig != SIG_BRI) && (chan_sig != SIG_BRI_PTMP) && (chan_sig != SIG_PRI)
10679                 && (chan_sig != SIG_SS7) && (chan_sig != SIG_MFCR2))
10680                /* Hang it up to be sure it's good */
10681                dahdi_set_hook(tmp->subs[SUB_REAL].dfd, DAHDI_ONHOOK);
10682          }
10683          ioctl(tmp->subs[SUB_REAL].dfd,DAHDI_SETTONEZONE,&tmp->tonezone);
10684 #ifdef HAVE_PRI
10685          /* the dchannel is down so put the channel in alarm */
10686          if (tmp->pri && !pri_is_up(tmp->pri))
10687             tmp->inalarm = 1;
10688 #endif
10689          if ((res = get_alarms(tmp)) != DAHDI_ALARM_NONE) {
10690             tmp->inalarm = 1;
10691             handle_alarms(tmp, res);
10692          }
10693       }
10694 
10695       tmp->polarityonanswerdelay = conf->chan.polarityonanswerdelay;
10696       tmp->answeronpolarityswitch = conf->chan.answeronpolarityswitch;
10697       tmp->hanguponpolarityswitch = conf->chan.hanguponpolarityswitch;
10698       tmp->sendcalleridafter = conf->chan.sendcalleridafter;
10699       if (!here) {
10700          tmp->locallyblocked = tmp->remotelyblocked = 0;
10701          if ((chan_sig == SIG_PRI) || (chan_sig == SIG_BRI) || (chan_sig == SIG_BRI_PTMP) || (chan_sig == SIG_SS7))
10702             tmp->inservice = 0;
10703          else /* We default to in service on protocols that don't have a reset */
10704             tmp->inservice = 1;
10705       }
10706    }
10707    if (tmp && !here) {
10708       /* nothing on the iflist */
10709       if (!*wlist) {
10710          *wlist = tmp;
10711          tmp->prev = NULL;
10712          tmp->next = NULL;
10713          *wend = tmp;
10714       } else {
10715          /* at least one member on the iflist */
10716          struct dahdi_pvt *working = *wlist;
10717 
10718          /* check if we maybe have to put it on the begining */
10719          if (working->channel > tmp->channel) {
10720             tmp->next = *wlist;
10721             tmp->prev = NULL;
10722             (*wlist)->prev = tmp;
10723             *wlist = tmp;
10724          } else {
10725          /* go through all the members and put the member in the right place */
10726             while (working) {
10727                /* in the middle */
10728                if (working->next) {
10729                   if (working->channel < tmp->channel && working->next->channel > tmp->channel) {
10730                      tmp->next = working->next;
10731                      tmp->prev = working;
10732                      working->next->prev = tmp;
10733                      working->next = tmp;
10734                      break;
10735                   }
10736                } else {
10737                /* the last */
10738                   if (working->channel < tmp->channel) {
10739                      working->next = tmp;
10740                      tmp->next = NULL;
10741                      tmp->prev = working;
10742                      *wend = tmp;
10743                      break;
10744                   }
10745                }
10746                working = working->next;
10747             }
10748          }
10749       }
10750    }
10751    return tmp;
10752 }

static void mwi_event_cb ( const struct ast_event *  event,
void *  userdata 
) [static]

Definition at line 367 of file chan_dahdi.c.

Referenced by mkintf().

00368 {
00369    /* This module does not handle MWI in an event-based manner.  However, it
00370     * subscribes to MWI for each mailbox that is configured so that the core
00371     * knows that we care about it.  Then, chan_dahdi will get the MWI from the
00372     * event cache instead of checking the mailbox directly. */
00373 }

static int mwi_send_init ( struct dahdi_pvt *  pvt  )  [static]

Definition at line 9167 of file chan_dahdi.c.

References ast_calloc, ast_free, AST_LAW, ast_log(), CID_MWI_TYPE_MDMF_FULL, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::cidlen, dahdi_pvt::cidpos, dahdi_pvt::cidspill, dahdi_subchannel::dfd, has_voicemail(), LOG_WARNING, MAX_CALLERID_SIZE, MWI_SEND_SA, MWI_SEND_SPILL, mwisend_info::mwisend_current, dahdi_pvt::mwisend_data, dahdi_pvt::mwisend_fsk, dahdi_pvt::mwisend_rpas, dahdi_pvt::mwisendactive, SUB_REAL, dahdi_pvt::subs, and vmwi_generate().

Referenced by do_monitor().

09168 {
09169    int x, res;
09170 
09171 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
09172    /* Determine how this spill is to be sent */
09173    if (pvt->mwisend_rpas) {
09174       pvt->mwisend_data.mwisend_current = MWI_SEND_SA;
09175       pvt->mwisendactive = 1;
09176    } else if (pvt->mwisend_fsk) {
09177       pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL;
09178       pvt->mwisendactive = 1;
09179    } else {
09180       pvt->mwisendactive = 0;
09181       return 0;
09182    }
09183 #else
09184    if (mwisend_rpas) {
09185       pvt->mwisend_data.mwisend_current = MWI_SEND_SA;
09186    } else {
09187       pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL;
09188    }
09189    pvt->mwisendactive = 1;
09190 #endif
09191 
09192    if (pvt->cidspill) {
09193       ast_log(LOG_WARNING, "cidspill already exists when trying to send FSK MWI\n");
09194       ast_free(pvt->cidspill);
09195       pvt->cidspill = NULL;
09196       pvt->cidpos = 0;
09197       pvt->cidlen = 0;
09198    }
09199    pvt->cidspill = ast_calloc(1, MAX_CALLERID_SIZE);
09200    if (!pvt->cidspill) {
09201       pvt->mwisendactive = 0;
09202       return -1;
09203    }
09204    x = DAHDI_FLUSH_BOTH;
09205    res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_FLUSH, &x);
09206    x = 3000;
09207    ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_ONHOOKTRANSFER, &x);
09208 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
09209    if (pvt->mwisend_fsk) {
09210 #endif
09211       pvt->cidlen = vmwi_generate(pvt->cidspill, has_voicemail(pvt), CID_MWI_TYPE_MDMF_FULL,
09212                         AST_LAW(pvt), pvt->cid_name, pvt->cid_num, 0);
09213       pvt->cidpos = 0;
09214 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
09215    }
09216 #endif
09217    return 0;
09218 }

static int mwi_send_process_buffer ( struct dahdi_pvt *  pvt,
int  num_read 
) [static]

Definition at line 9220 of file chan_dahdi.c.

References ast_free, ast_log(), dahdi_pvt::cidlen, dahdi_pvt::cidpos, dahdi_pvt::cidspill, dahdi_set_hook(), dahdi_subchannel::dfd, errno, LOG_WARNING, MWI_SEND_CLEANUP, MWI_SEND_DONE, MWI_SEND_PAUSE, MWI_SEND_SA, MWI_SEND_SA_WAIT, MWI_SEND_SPILL, mwisend_info::mwisend_current, dahdi_pvt::mwisend_data, dahdi_pvt::mwisend_fsk, dahdi_pvt::mwisendactive, mwisend_info::pause, quit, SUB_REAL, and dahdi_pvt::subs.

Referenced by do_monitor().

09221 {
09222    struct timeval    now;
09223    int         res;
09224 
09225    /* sanity check to catch if this had been interrupted previously
09226    *  i.e. state says there is more to do but there is no spill allocated
09227    */
09228    if (MWI_SEND_DONE != pvt->mwisend_data.mwisend_current && !pvt->cidspill) {
09229       pvt->mwisend_data.mwisend_current = MWI_SEND_DONE;
09230    } else if (MWI_SEND_DONE != pvt->mwisend_data.mwisend_current) {
09231       /* Normal processing -- Perform mwi send action */
09232       switch ( pvt->mwisend_data.mwisend_current) {
09233       case MWI_SEND_SA:
09234          /* Send the Ring Pulse Signal Alert */
09235          res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &AS_RP_cadence);
09236          if (res) {
09237             ast_log(LOG_WARNING, "Unable to set RP-AS ring cadence: %s\n", strerror(errno));
09238             goto quit;
09239          }
09240          res = dahdi_set_hook(pvt->subs[SUB_REAL].dfd, DAHDI_RING);
09241          pvt->mwisend_data.mwisend_current = MWI_SEND_SA_WAIT;
09242          break;
09243       case MWI_SEND_SA_WAIT:  /* do nothing until I get RINGEROFF event */
09244          break;
09245       case MWI_SEND_PAUSE:  /* Wait between alert and spill - min of 500 mS*/
09246 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
09247          if (pvt->mwisend_fsk) {
09248 #endif
09249             gettimeofday(&now, NULL);
09250             if ((int)(now.tv_sec - pvt->mwisend_data.pause.tv_sec) * 1000000 + (int)now.tv_usec - (int)pvt->mwisend_data.pause.tv_usec > 500000) {
09251                pvt->mwisend_data.mwisend_current = MWI_SEND_SPILL;
09252             }
09253 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
09254          } else { /* support for mwisendtype=nofsk */
09255             pvt->mwisend_data.mwisend_current = MWI_SEND_CLEANUP;
09256          }
09257 #endif
09258          break;
09259       case MWI_SEND_SPILL:
09260          /* We read some number of bytes.  Write an equal amount of data */
09261          if(0 < num_read) {
09262             if (num_read > pvt->cidlen - pvt->cidpos)
09263                num_read = pvt->cidlen - pvt->cidpos;
09264             res = write(pvt->subs[SUB_REAL].dfd, pvt->cidspill + pvt->cidpos, num_read);
09265             if (res > 0) {
09266                pvt->cidpos += res;
09267                if (pvt->cidpos >= pvt->cidlen) {
09268                   pvt->mwisend_data.mwisend_current = MWI_SEND_CLEANUP;
09269                }
09270             } else {
09271                ast_log(LOG_WARNING, "MWI FSK Send Write failed: %s\n", strerror(errno));
09272                goto quit;
09273             }
09274          }
09275          break;
09276       case MWI_SEND_CLEANUP:
09277          /* For now, do nothing */
09278          pvt->mwisend_data.mwisend_current = MWI_SEND_DONE;
09279          break;
09280       default:
09281          /* Should not get here, punt*/
09282          goto quit;
09283       }
09284    }
09285 
09286    if (MWI_SEND_DONE == pvt->mwisend_data.mwisend_current) {
09287       if (pvt->cidspill) {
09288          ast_free(pvt->cidspill);
09289          pvt->cidspill = NULL;
09290          pvt->cidpos = 0;
09291          pvt->cidlen = 0;
09292       }
09293       pvt->mwisendactive = 0;
09294    }
09295    return 0;
09296 quit:
09297    if (pvt->cidspill) {
09298       ast_free(pvt->cidspill);
09299       pvt->cidspill = NULL;
09300       pvt->cidpos = 0;
09301       pvt->cidlen = 0;
09302    }
09303    pvt->mwisendactive = 0;
09304    return -1;
09305 }

static int mwi_send_process_event ( struct dahdi_pvt *  pvt,
int  event 
) [static]

Definition at line 9307 of file chan_dahdi.c.

References ast_free, ast_log(), dahdi_pvt::cidlen, dahdi_pvt::cidpos, dahdi_pvt::cidspill, dahdi_set_hook(), dahdi_subchannel::dfd, errno, LOG_WARNING, MWI_SEND_DONE, MWI_SEND_PAUSE, MWI_SEND_SA_WAIT, mwisend_info::mwisend_current, dahdi_pvt::mwisend_data, dahdi_pvt::mwisendactive, mwisend_info::pause, SUB_REAL, and dahdi_pvt::subs.

Referenced by do_monitor().

09308 {
09309    int handled = 0;
09310 
09311    if (MWI_SEND_DONE != pvt->mwisend_data.mwisend_current) {
09312       switch (event) {
09313       case DAHDI_EVENT_RINGEROFF:
09314          if(pvt->mwisend_data.mwisend_current == MWI_SEND_SA_WAIT) {
09315             handled = 1;
09316 
09317             if (dahdi_set_hook(pvt->subs[SUB_REAL].dfd, DAHDI_RINGOFF) ) {
09318                ast_log(LOG_WARNING, "Unable to finsh RP-AS: %s mwi send aborted\n", strerror(errno));
09319                if(pvt->cidspill) {
09320                   ast_free(pvt->cidspill);
09321                   pvt->cidspill = NULL;
09322                }
09323                pvt->mwisend_data.mwisend_current = MWI_SEND_DONE;
09324                pvt->mwisendactive = 0;
09325             } else {
09326                pvt->mwisend_data.mwisend_current = MWI_SEND_PAUSE;
09327                gettimeofday(&pvt->mwisend_data.pause, NULL);
09328             }
09329          }
09330          break;
09331       /* Going off hook, I need to punt this spill */
09332       case DAHDI_EVENT_RINGOFFHOOK:
09333          if (pvt->cidspill) {
09334             ast_free(pvt->cidspill);
09335             pvt->cidspill = NULL;
09336             pvt->cidpos = 0;
09337             pvt->cidlen = 0;
09338          }
09339          pvt->mwisend_data.mwisend_current = MWI_SEND_DONE;
09340          pvt->mwisendactive = 0;
09341          break;
09342       case DAHDI_EVENT_RINGERON:
09343       case DAHDI_EVENT_HOOKCOMPLETE:
09344          break;
09345       default:
09346          break;
09347       }
09348    }
09349    return handled;
09350 }

static void* mwi_thread ( void *  data  )  [static]

Definition at line 9025 of file chan_dahdi.c.

References ast_free, ast_hangup(), AST_LAW, ast_log(), ast_pthread_create_detached, AST_STATE_RING, mwi_thread_data::buf, bump_gains(), calc_energy(), callerid_feed(), callerid_free(), callerid_get(), callerid_new(), dahdi_pvt::channel, CID_MSGWAITING, CID_NOMSGWAITING, dahdi_pvt::cid_signalling, dahdi_get_event(), dahdi_new(), dahdi_subchannel::dfd, errno, event2str(), EVENT_FLAG_SYSTEM, callerid_state::flags, get_alarms(), handle_alarms(), dahdi_pvt::inalarm, mwi_thread_data::len, LOG_NOTICE, LOG_WARNING, dahdi_pvt::mailbox, manager_event, dahdi_pvt::mwimonitoractive, name, notify_message(), mwi_thread_data::pvt, quit, restore_gains(), dahdi_pvt::ringt, dahdi_pvt::ringt_base, ss_thread(), SUB_REAL, and dahdi_pvt::subs.

Referenced by do_monitor().

09026 {
09027    struct mwi_thread_data *mtd = data;
09028    struct callerid_state *cs;
09029    pthread_t threadid;
09030    int samples = 0;
09031    char *name, *number;
09032    int flags;
09033    int i, res;
09034    unsigned int spill_done = 0;
09035    int spill_result = -1;
09036 
09037    if (!(cs = callerid_new(mtd->pvt->cid_signalling))) {
09038       mtd->pvt->mwimonitoractive = 0;
09039 
09040       return NULL;
09041    }
09042 
09043    callerid_feed(cs, mtd->buf, mtd->len, AST_LAW(mtd->pvt));
09044 
09045    bump_gains(mtd->pvt);
09046 
09047    for (;;) {
09048       i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
09049       if ((res = ioctl(mtd->pvt->subs[SUB_REAL].dfd, DAHDI_IOMUX, &i))) {
09050          ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
09051          goto quit;
09052       }
09053 
09054       if (i & DAHDI_IOMUX_SIGEVENT) {
09055          struct ast_channel *chan;
09056 
09057          /* If we get an event, screen out events that we do not act on.
09058           * Otherwise, cancel and go to the simple switch to let it deal with it.
09059           */
09060          res = dahdi_get_event(mtd->pvt->subs[SUB_REAL].dfd);
09061 
09062          switch (res) {
09063          case DAHDI_EVENT_NEONMWI_ACTIVE:
09064          case DAHDI_EVENT_NEONMWI_INACTIVE:
09065          case DAHDI_EVENT_NONE:
09066          case DAHDI_EVENT_BITSCHANGED:
09067             break;
09068          case DAHDI_EVENT_NOALARM:
09069             mtd->pvt->inalarm = 0;
09070             ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", mtd->pvt->channel);
09071             manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
09072                "Channel: %d\r\n", mtd->pvt->channel);
09073             break;
09074          case DAHDI_EVENT_ALARM:
09075             mtd->pvt->inalarm = 1;
09076             res = get_alarms(mtd->pvt);
09077             handle_alarms(mtd->pvt, res);
09078             break; /* What to do on channel alarm ???? -- fall thru intentionally?? */
09079          default:
09080             ast_log(LOG_NOTICE, "Got event %d (%s)...  Passing along to ss_thread\n", res, event2str(res));
09081             callerid_free(cs);
09082 
09083             restore_gains(mtd->pvt);
09084             mtd->pvt->ringt = mtd->pvt->ringt_base;
09085 
09086             if ((chan = dahdi_new(mtd->pvt, AST_STATE_RING, 0, SUB_REAL, 0, 0))) {
09087                if (ast_pthread_create_detached(&threadid, NULL, ss_thread, chan)) {
09088                   ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", mtd->pvt->channel);
09089                   res = tone_zone_play_tone(mtd->pvt->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
09090                   if (res < 0)
09091                      ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", mtd->pvt->channel);
09092                   ast_hangup(chan);
09093                   goto quit;
09094                }
09095                goto quit_no_clean;
09096 
09097             } else {
09098                ast_log(LOG_WARNING, "Could not create channel to handle call\n");
09099             }
09100          }
09101       } else if (i & DAHDI_IOMUX_READ) {
09102          if ((res = read(mtd->pvt->subs[SUB_REAL].dfd, mtd->buf, sizeof(mtd->buf))) < 0) {
09103             if (errno != ELAST) {
09104                ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
09105                goto quit;
09106             }
09107             break;
09108          }
09109          samples += res;
09110          if (!spill_done) {
09111             if ((spill_result = callerid_feed(cs, mtd->buf, res, AST_LAW(mtd->pvt))) < 0) {
09112                /*
09113                 * The previous diagnostic message output likely
09114                 * explains why it failed.
09115                 */
09116                ast_log(LOG_WARNING, "Failed to decode CallerID\n");
09117                break;
09118             } else if (spill_result) {
09119                spill_done = 1;
09120             }
09121          } else {
09122             /* keep reading data until the energy level drops below the threshold
09123                so we don't get another 'trigger' on the remaining carrier signal
09124             */
09125             if (calc_energy(mtd->buf, res, AST_LAW(mtd->pvt)) <= mwilevel)
09126                break;
09127          }
09128          if (samples > (8000 * 4)) /*Termination case - time to give up*/
09129             break;
09130       }
09131    }
09132 
09133    if (spill_result == 1) {
09134       callerid_get(cs, &name, &number, &flags);
09135       if (flags & CID_MSGWAITING) {
09136          ast_log(LOG_NOTICE, "mwi: Have Messages on channel %d\n", mtd->pvt->channel);
09137          notify_message(mtd->pvt->mailbox, 1);
09138       } else if (flags & CID_NOMSGWAITING) {
09139          ast_log(LOG_NOTICE, "mwi: No Messages on channel %d\n", mtd->pvt->channel);
09140          notify_message(mtd->pvt->mailbox, 0);
09141       } else {
09142          ast_log(LOG_NOTICE, "mwi: Status unknown on channel %d\n", mtd->pvt->channel);
09143       }
09144    }
09145 
09146 
09147 quit:
09148    callerid_free(cs);
09149 
09150    restore_gains(mtd->pvt);
09151 
09152 quit_no_clean:
09153    mtd->pvt->mwimonitoractive = 0;
09154 
09155    ast_free(mtd);
09156 
09157    return NULL;
09158 }

static int my_dahdi_write ( struct dahdi_pvt *  p,
unsigned char *  buf,
int  len,
int  idx,
int  linear 
) [static]

Definition at line 7145 of file chan_dahdi.c.

References ast_debug, dahdi_pvt::channel, dahdi_subchannel::dfd, errno, READ_SIZE, and dahdi_pvt::subs.

Referenced by dahdi_write().

07146 {
07147    int sent=0;
07148    int size;
07149    int res;
07150    int fd;
07151    fd = p->subs[idx].dfd;
07152    while (len) {
07153       size = len;
07154       if (size > (linear ? READ_SIZE * 2 : READ_SIZE))
07155          size = (linear ? READ_SIZE * 2 : READ_SIZE);
07156       res = write(fd, buf, size);
07157       if (res != size) {
07158          ast_debug(1, "Write returned %d (%s) on channel %d\n", res, strerror(errno), p->channel);
07159          return sent;
07160       }
07161       len -= size;
07162       buf += size;
07163    }
07164    return sent;
07165 }

static int my_getsigstr ( struct ast_channel *  chan,
char *  str,
const char *  term,
int  ms 
) [static]

Definition at line 7693 of file chan_dahdi.c.

References ast_waitfordigit().

Referenced by ss_thread().

07694 {
07695    char c;
07696 
07697    *str = 0; /* start with empty output buffer */
07698    for (;;)
07699    {
07700       /* Wait for the first digit (up to specified ms). */
07701       c = ast_waitfordigit(chan, ms);
07702       /* if timeout, hangup or error, return as such */
07703       if (c < 1)
07704          return c;
07705       *str++ = c;
07706       *str = 0;
07707       if (strchr(term, c))
07708          return 1;
07709    }
07710 }

static void notify_message ( char *  mailbox_full,
int  thereornot 
) [static]

Send MWI state change.

  • mailbox_full This is the mailbox associated with the FXO line that the MWI state has changed on.
  • thereornot This argument should simply be set to 1 or 0, to indicate whether there are messages waiting or not.
Returns:
nothing
This function does two things:

1) It generates an internal Asterisk event notifying any other module that cares about MWI that the state of a mailbox has changed.

2) It runs the script specified by the mwimonitornotify option to allow some custom handling of the state change.

Definition at line 2942 of file chan_dahdi.c.

References AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI, ast_event_new(), ast_event_queue_and_cache(), ast_safe_system(), ast_strdupa, ast_strlen_zero(), context, mailbox, s, and strsep().

Referenced by handle_init_event(), mwi_thread(), and ss_thread().

02943 {
02944    char s[sizeof(mwimonitornotify) + 80];
02945    struct ast_event *event;
02946    char *mailbox, *context;
02947 
02948    /* Strip off @default */
02949    context = mailbox = ast_strdupa(mailbox_full);
02950    strsep(&context, "@");
02951    if (ast_strlen_zero(context))
02952       context = "default";
02953 
02954    if (!(event = ast_event_new(AST_EVENT_MWI,
02955          AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
02956          AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
02957          AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, thereornot,
02958          AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, thereornot,
02959          AST_EVENT_IE_END))) {
02960       return;
02961    }
02962 
02963    ast_event_queue_and_cache(event);
02964 
02965    if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(mwimonitornotify)) {
02966       snprintf(s, sizeof(s), "%s %s %d", mwimonitornotify, mailbox, thereornot);
02967       ast_safe_system(s);
02968    }
02969 }

static int parse_buffers_policy ( const char *  parse,
int *  num_buffers,
int *  policy 
) [static]

Definition at line 5056 of file chan_dahdi.c.

References ast_log(), and LOG_WARNING.

Referenced by dahdi_func_write(), and process_dahdi().

05057 {
05058    int res;
05059    char policy_str[21] = "";
05060    
05061    if (((res = sscanf(parse, "%d,%20s", num_buffers, policy_str)) != 2) &&
05062       ((res = sscanf(parse, "%d|%20s", num_buffers, policy_str)) != 2)) {
05063       ast_log(LOG_WARNING, "Parsing buffer string '%s' failed.\n", parse);
05064       return 1;
05065    }
05066    if (*num_buffers < 0) {
05067       ast_log(LOG_WARNING, "Invalid buffer count given '%d'.\n", *num_buffers);
05068       return -1;
05069    }
05070    if (!strcasecmp(policy_str, "full")) {
05071       *policy = DAHDI_POLICY_WHEN_FULL;
05072    } else if (!strcasecmp(policy_str, "immediate")) {
05073       *policy = DAHDI_POLICY_IMMEDIATE;
05074 #ifdef DAHDI_POLICY_HALF_FULL
05075    } else if (!strcasecmp(policy_str, "half")) {
05076       *policy = DAHDI_POLICY_HALF_FULL;
05077 #endif
05078    } else {
05079       ast_log(LOG_WARNING, "Invalid policy name given '%s'.\n", policy_str);
05080       return -1;
05081    }
05082 
05083    return 0;
05084 }

static unsigned int parse_pointcode ( const char *  pcstring  )  [static]

Definition at line 9962 of file chan_dahdi.c.

Referenced by process_dahdi().

09963 {
09964    unsigned int code1, code2, code3;
09965    int numvals;
09966 
09967    numvals = sscanf(pcstring, "%30d-%30d-%30d", &code1, &code2, &code3);
09968    if (numvals == 1)
09969       return code1;
09970    if (numvals == 3)
09971       return (code1 << 16) | (code2 << 8) | code3;
09972 
09973    return 0;
09974 }

static int pri_active_dchan_fd ( struct dahdi_pri *  pri  )  [static]

Definition at line 4128 of file chan_dahdi.c.

References dahdi_pri::dchans, dahdi_pri::fds, NUM_DCHANS, and dahdi_pri::pri.

Referenced by pri_find_principle().

04129 {
04130    int x = -1;
04131 
04132    for (x = 0; x < NUM_DCHANS; x++) {
04133       if ((pri->dchans[x] == pri->pri))
04134          break;
04135    }
04136 
04137    return pri->fds[x];
04138 }

static int pri_assign_bearer ( struct dahdi_pvt *  crv,
struct dahdi_pri *  pri,
struct dahdi_pvt *  bearer 
) [static]

Definition at line 4094 of file chan_dahdi.c.

References ast_channel_set_fd(), dahdi_pvt::bearer, dahdi_pvt::call, dahdi_subchannel::dfd, inuse, dahdi_subchannel::owner, dahdi_pvt::owner, dahdi_pvt::pri, dahdi_pvt::realcall, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_request(), pri_dchannel(), and pri_fixup_principle().

04095 {
04096    bearer->owner = &inuse;
04097    bearer->realcall = crv;
04098    crv->subs[SUB_REAL].dfd = bearer->subs[SUB_REAL].dfd;
04099    if (crv->subs[SUB_REAL].owner)
04100       ast_channel_set_fd(crv->subs[SUB_REAL].owner, 0, crv->subs[SUB_REAL].dfd);
04101    crv->bearer = bearer;
04102    crv->call = bearer->call;
04103    crv->pri = pri;
04104    return 0;
04105 }

static int pri_check_restart ( struct dahdi_pri *  pri  )  [static]

Definition at line 12413 of file chan_dahdi.c.

References dahdi_pvt::call, dahdi_pri::lastreset, dahdi_pri::numchans, dahdi_pri::pri, PVT_TO_CHANNEL, dahdi_pri::pvts, dahdi_pri::resetpos, dahdi_pri::resetting, and dahdi_pvt::resetting.

Referenced by pri_dchannel().

12414 {
12415    do {
12416       pri->resetpos++;
12417    } while ((pri->resetpos < pri->numchans) &&
12418       (!pri->pvts[pri->resetpos] ||
12419       pri->pvts[pri->resetpos]->call ||
12420       pri->pvts[pri->resetpos]->resetting));
12421    if (pri->resetpos < pri->numchans) {
12422       /* Mark the channel as resetting and restart it */
12423       pri->pvts[pri->resetpos]->resetting = 1;
12424       pri_reset(pri->pri, PVT_TO_CHANNEL(pri->pvts[pri->resetpos]));
12425    } else {
12426       pri->resetting = 0;
12427       time(&pri->lastreset);
12428    }
12429    return 0;
12430 }

static int pri_create_spanmap ( int  span,
int  trunkgroup,
int  logicalspan 
) [static]

Definition at line 9949 of file chan_dahdi.c.

References ast_log(), LOG_WARNING, dahdi_pri::mastertrunkgroup, dahdi_pri::prilogicalspan, and pris.

Referenced by setup_dahdi().

09950 {
09951    if (pris[span].mastertrunkgroup) {
09952       ast_log(LOG_WARNING, "Span %d is already part of trunk group %d, cannot add to trunk group %d\n", span + 1, pris[span].mastertrunkgroup, trunkgroup);
09953       return -1;
09954    }
09955    pris[span].mastertrunkgroup = trunkgroup;
09956    pris[span].prilogicalspan = logicalspan;
09957    return 0;
09958 }

static int pri_create_trunkgroup ( int  trunkgroup,
int *  channels 
) [static]

Definition at line 9884 of file chan_dahdi.c.

References ast_log(), DCHAN_PROVISIONED, dahdi_pri::dchanavail, dahdi_pri::dchannels, errno, LOG_WARNING, NUM_DCHANS, NUM_SPANS, dahdi_pri::offset, pris, pvts, dahdi_pri::span, and dahdi_pri::trunkgroup.

Referenced by setup_dahdi().

09885 {
09886    struct dahdi_spaninfo si;
09887    struct dahdi_params p;
09888    int fd;
09889    int span;
09890    int ospan=0;
09891    int x,y;
09892    for (x = 0; x < NUM_SPANS; x++) {
09893       if (pris[x].trunkgroup == trunkgroup) {
09894          ast_log(LOG_WARNING, "Trunk group %d already exists on span %d, Primary d-channel %d\n", trunkgroup, x + 1, pris[x].dchannels[0]);
09895          return -1;
09896       }
09897    }
09898    for (y = 0; y < NUM_DCHANS; y++) {
09899       if (!channels[y])
09900          break;
09901       memset(&si, 0, sizeof(si));
09902       memset(&p, 0, sizeof(p));
09903       fd = open("/dev/dahdi/channel", O_RDWR);
09904       if (fd < 0) {
09905          ast_log(LOG_WARNING, "Failed to open channel: %s\n", strerror(errno));
09906          return -1;
09907       }
09908       x = channels[y];
09909       if (ioctl(fd, DAHDI_SPECIFY, &x)) {
09910          ast_log(LOG_WARNING, "Failed to specify channel %d: %s\n", channels[y], strerror(errno));
09911          close(fd);
09912          return -1;
09913       }
09914       if (ioctl(fd, DAHDI_GET_PARAMS, &p)) {
09915          ast_log(LOG_WARNING, "Failed to get channel parameters for channel %d: %s\n", channels[y], strerror(errno));
09916          return -1;
09917       }
09918       if (ioctl(fd, DAHDI_SPANSTAT, &si)) {
09919          ast_log(LOG_WARNING, "Failed go get span information on channel %d (span %d): %s\n", channels[y], p.spanno, strerror(errno));
09920          close(fd);
09921          return -1;
09922       }
09923       span = p.spanno - 1;
09924       if (pris[span].trunkgroup) {
09925          ast_log(LOG_WARNING, "Span %d is already provisioned for trunk group %d\n", span + 1, pris[span].trunkgroup);
09926          close(fd);
09927          return -1;
09928       }
09929       if (pris[span].pvts[0]) {
09930          ast_log(LOG_WARNING, "Span %d is already provisioned with channels (implicit PRI maybe?)\n", span + 1);
09931          close(fd);
09932          return -1;
09933       }
09934       if (!y) {
09935          pris[span].trunkgroup = trunkgroup;
09936          pris[span].offset = channels[y] - p.chanpos;
09937          ospan = span;
09938       }
09939       pris[ospan].dchannels[y] = channels[y];
09940       pris[ospan].dchanavail[y] |= DCHAN_PROVISIONED;
09941       pris[span].span = span + 1;
09942       close(fd);
09943    }
09944    return 0;
09945 }

static void* pri_dchannel ( void *  vpri  )  [static]

Definition at line 12514 of file chan_dahdi.c.

References ast_channel::_softhangup, ast_channel::_state, dahdi_pvt::alerting, dahdi_pvt::alreadyhungup, apply_plan_to_number(), ast_canmatch_extension(), AST_CAUSE_USER_BUSY, AST_CONTROL_BUSY, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, ast_dsp_set_features(), ast_exists_extension(), AST_FORMAT_ULAW, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_hangup(), ast_log(), ast_matchmore_extension(), ast_mutex_lock(), ast_mutex_unlock(), ast_pbx_start(), ast_pthread_create_background, ast_pthread_create_detached, ast_shrink_phone_number(), AST_SOFTHANGUP_DEV, AST_STATE_BUSY, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_UP, ast_strlen_zero(), ast_tv(), ast_tvcmp(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_verb, dahdi_pvt::bearer, dahdi_pvt::call, dahdi_pvt::callingpres, cause, dahdi_pvt::channel, dahdi_pvt::cid_ani, dahdi_pvt::cid_ani2, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::cid_ton, dahdi_pvt::confirmanswer, dahdi_pvt::context, dahdi_enable_ec(), dahdi_hangup(), dahdi_new(), DAHDI_OVERLAPDIAL_INCOMING, dahdi_queue_frame(), dahdi_request(), dahdi_setlaw(), DCHAN_NOTINALARM, DCHAN_UP, dahdi_pri::dchanavail, dahdi_pri::dchannels, dahdi_pri::dchans, dahdi_pri::debug, dahdi_subchannel::dfd, dahdi_pvt::dialdest, dahdi_pvt::dialing, dahdi_pri::discardremoteholdretrieval, dahdi_pvt::dnid, do_idle_thread(), dahdi_pvt::dop, dahdi_pvt::dsp, dahdi_pvt::dsp_features, DSP_PROGRESS_RINGING, errno, event2str(), EVENT_FLAG_SYSTEM, dahdi_pvt::exten, dahdi_pri::fds, ast_channel::hangupcause, dahdi_pri::idlecontext, dahdi_pri::idledial, dahdi_pri::idleext, dahdi_pvt::immediate, dahdi_pvt::inalarm, dahdi_pvt::inservice, inuse, dahdi_pvt::isidlecall, dahdi_pvt::lastcid_name, dahdi_pvt::lastcid_num, dahdi_pri::lastreset, dahdi_pvt::lock, dahdi_pri::lock, LOG_NOTICE, LOG_WARNING, dahdi_pvt::logicalspan, manager_event, dahdi_pri::minidle, dahdi_pri::minunused, ast_channel::name, dahdi_subchannel::needanswer, dahdi_subchannel::needbusy, dahdi_subchannel::needcallerid, dahdi_subchannel::needcongestion, dahdi_subchannel::needringing, dahdi_pri::numchans, dahdi_pri::overlapdial, dahdi_pvt::owner, pbx_builtin_setvar_helper(), dahdi_pvt::pri, dahdi_pri::pri, pri_assign_bearer(), PRI_CHANNEL, pri_check_restart(), pri_find_crv(), pri_find_dchan(), pri_find_empty_chan(), pri_find_principle(), pri_fixup_principle(), pri_hangup_all(), pri_is_up(), pri_order(), PRI_SPAN, dahdi_pvt::prioffset, dahdi_pvt::proceeding, dahdi_pvt::progress, PVT_TO_CHANNEL, dahdi_pri::pvts, dahdi_pvt::rdnis, dahdi_pvt::realcall, redirectingreason2str(), dahdi_pri::resetinterval, dahdi_pri::resetpos, dahdi_pvt::resetting, dahdi_pri::resetting, dahdi_pvt::rxgain, S_OR, set_actual_gain(), dahdi_pvt::setup_ack, dahdi_pvt::sig, dahdi_pri::sig, SIG_BRI_PTMP, SIG_FXSKS, dahdi_pri::span, ss_thread(), SUB_REAL, ast_frame::subclass, dahdi_pvt::subs, dahdi_pri::switchtype, dahdi_pri::trunkgroup, dahdi_pvt::txgain, and dahdi_pvt::use_callerid.

Referenced by start_pri().

12515 {
12516    struct dahdi_pri *pri = vpri;
12517    pri_event *e;
12518    struct pollfd fds[NUM_DCHANS];
12519    int res;
12520    int chanpos = 0;
12521    int x;
12522    int haveidles;
12523    int activeidles;
12524    int nextidle = -1;
12525    struct ast_channel *c;
12526    struct timeval tv, lowest, *next;
12527    struct timeval lastidle = ast_tvnow();
12528    int doidling=0;
12529    char *cc;
12530    char idlen[80];
12531    struct ast_channel *idle;
12532    pthread_t p;
12533    time_t t;
12534    int i, which=-1;
12535    int numdchans;
12536    int cause=0;
12537    struct dahdi_pvt *crv;
12538    pthread_t threadid;
12539    char ani2str[6];
12540    char plancallingnum[256];
12541    char plancallingani[256];
12542    char calledtonstr[10];
12543 
12544    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
12545 
12546    gettimeofday(&lastidle, NULL);
12547    if (!ast_strlen_zero(pri->idledial) && !ast_strlen_zero(pri->idleext)) {
12548       /* Need to do idle dialing, check to be sure though */
12549       cc = strchr(pri->idleext, '@');
12550       if (cc) {
12551          *cc = '\0';
12552          cc++;
12553          ast_copy_string(pri->idlecontext, cc, sizeof(pri->idlecontext));
12554 #if 0
12555          /* Extensions may not be loaded yet */
12556          if (!ast_exists_extension(NULL, pri->idlecontext, pri->idleext, 1, NULL))
12557             ast_log(LOG_WARNING, "Extension '%s @ %s' does not exist\n", pri->idleext, pri->idlecontext);
12558          else
12559 #endif
12560             doidling = 1;
12561       } else
12562          ast_log(LOG_WARNING, "Idle dial string '%s' lacks '@context'\n", pri->idleext);
12563    }
12564    for (;;) {
12565       for (i = 0; i < NUM_DCHANS; i++) {
12566          if (!pri->dchannels[i])
12567             break;
12568          fds[i].fd = pri->fds[i];
12569          fds[i].events = POLLIN | POLLPRI;
12570          fds[i].revents = 0;
12571       }
12572       numdchans = i;
12573       time(&t);
12574       ast_mutex_lock(&pri->lock);
12575       if ((pri->switchtype != PRI_SWITCH_GR303_TMC) && (pri->sig != SIG_BRI_PTMP) && (pri->resetinterval > 0)) {
12576          if (pri->resetting && pri_is_up(pri)) {
12577             if (pri->resetpos < 0)
12578                pri_check_restart(pri);
12579          } else {
12580             if (!pri->resetting  && (t - pri->lastreset) >= pri->resetinterval) {
12581                pri->resetting = 1;
12582                pri->resetpos = -1;
12583             }
12584          }
12585       }
12586       /* Look for any idle channels if appropriate */
12587       if (doidling && pri_is_up(pri)) {
12588          nextidle = -1;
12589          haveidles = 0;
12590          activeidles = 0;
12591          for (x = pri->numchans; x >= 0; x--) {
12592             if (pri->pvts[x] && !pri->pvts[x]->owner &&
12593                !pri->pvts[x]->call) {
12594                if (haveidles < pri->minunused) {
12595                   haveidles++;
12596                } else if (!pri->pvts[x]->resetting) {
12597                   nextidle = x;
12598                   break;
12599                }
12600             } else if (pri->pvts[x] && pri->pvts[x]->owner && pri->pvts[x]->isidlecall)
12601                activeidles++;
12602          }
12603          if (nextidle > -1) {
12604             if (ast_tvdiff_ms(ast_tvnow(), lastidle) > 1000) {
12605                /* Don't create a new idle call more than once per second */
12606                snprintf(idlen, sizeof(idlen), "%d/%s", pri->pvts[nextidle]->channel, pri->idledial);
12607                idle = dahdi_request("DAHDI", AST_FORMAT_ULAW, idlen, &cause);
12608                if (idle) {
12609                   pri->pvts[nextidle]->isidlecall = 1;
12610                   if (ast_pthread_create_background(&p, NULL, do_idle_thread, idle)) {
12611                      ast_log(LOG_WARNING, "Unable to start new thread for idle channel '%s'\n", idle->name);
12612                      dahdi_hangup(idle);
12613                   }
12614                } else
12615                   ast_log(LOG_WARNING, "Unable to request channel 'DAHDI/%s' for idle call\n", idlen);
12616                lastidle = ast_tvnow();
12617             }
12618          } else if ((haveidles < pri->minunused) &&
12619             (activeidles > pri->minidle)) {
12620             /* Mark something for hangup if there is something
12621                that can be hungup */
12622             for (x = pri->numchans; x >= 0; x--) {
12623                /* find a candidate channel */
12624                if (pri->pvts[x] && pri->pvts[x]->owner && pri->pvts[x]->isidlecall) {
12625                   pri->pvts[x]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
12626                   haveidles++;
12627                   /* Stop if we have enough idle channels or
12628                     can't spare any more active idle ones */
12629                   if ((haveidles >= pri->minunused) ||
12630                      (activeidles <= pri->minidle))
12631                      break;
12632                }
12633             }
12634          }
12635       }
12636       /* Start with reasonable max */
12637       lowest = ast_tv(60, 0);
12638       for (i = 0; i < NUM_DCHANS; i++) {
12639          /* Find lowest available d-channel */
12640          if (!pri->dchannels[i])
12641             break;
12642          if ((next = pri_schedule_next(pri->dchans[i]))) {
12643             /* We need relative time here */
12644             tv = ast_tvsub(*next, ast_tvnow());
12645             if (tv.tv_sec < 0) {
12646                tv = ast_tv(0,0);
12647             }
12648             if (doidling || pri->resetting) {
12649                if (tv.tv_sec > 1) {
12650                   tv = ast_tv(1, 0);
12651                }
12652             } else {
12653                if (tv.tv_sec > 60) {
12654                   tv = ast_tv(60, 0);
12655                }
12656             }
12657          } else if (doidling || pri->resetting) {
12658             /* Make sure we stop at least once per second if we're
12659                monitoring idle channels */
12660             tv = ast_tv(1,0);
12661          } else {
12662             /* Don't poll for more than 60 seconds */
12663             tv = ast_tv(60, 0);
12664          }
12665          if (!i || ast_tvcmp(tv, lowest) < 0) {
12666             lowest = tv;
12667          }
12668       }
12669       ast_mutex_unlock(&pri->lock);
12670 
12671       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
12672       pthread_testcancel();
12673       e = NULL;
12674       res = poll(fds, numdchans, lowest.tv_sec * 1000 + lowest.tv_usec / 1000);
12675       pthread_testcancel();
12676       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
12677 
12678       ast_mutex_lock(&pri->lock);
12679       if (!res) {
12680          for (which = 0; which < NUM_DCHANS; which++) {
12681             if (!pri->dchans[which])
12682                break;
12683             /* Just a timeout, run the scheduler */
12684             e = pri_schedule_run(pri->dchans[which]);
12685             if (e)
12686                break;
12687          }
12688       } else if (res > -1) {
12689          for (which = 0; which < NUM_DCHANS; which++) {
12690             if (!pri->dchans[which])
12691                break;
12692             if (fds[which].revents & POLLPRI) {
12693                /* Check for an event */
12694                x = 0;
12695                res = ioctl(pri->fds[which], DAHDI_GETEVENT, &x);
12696                if (x) {
12697                   ast_log(LOG_NOTICE, "PRI got event: %s (%d) on %s D-channel of span %d\n", event2str(x), x, pri_order(which), pri->span);
12698                   manager_event(EVENT_FLAG_SYSTEM, "PRIEvent",
12699                      "PRIEvent: %s\r\n"
12700                      "PRIEventCode: %d\r\n"
12701                      "D-channel: %s\r\n"
12702                      "Span: %d\r\n",
12703                      event2str(x),
12704                      x,
12705                      pri_order(which),
12706                      pri->span
12707                      );
12708                }
12709                /* Keep track of alarm state */
12710                if (x == DAHDI_EVENT_ALARM) {
12711                   pri->dchanavail[which] &= ~(DCHAN_NOTINALARM | DCHAN_UP);
12712                   pri_find_dchan(pri);
12713                } else if (x == DAHDI_EVENT_NOALARM) {
12714                   pri->dchanavail[which] |= DCHAN_NOTINALARM;
12715                   pri_restart(pri->dchans[which]);
12716                }
12717 
12718                ast_debug(1, "Got event %s (%d) on D-channel for span %d\n", event2str(x), x, pri->span);
12719             } else if (fds[which].revents & POLLIN) {
12720                e = pri_check_event(pri->dchans[which]);
12721             }
12722             if (e)
12723                break;
12724          }
12725       } else if (errno != EINTR)
12726          ast_log(LOG_WARNING, "pri_event returned error %d (%s)\n", errno, strerror(errno));
12727 
12728       if (e) {
12729          if (pri->debug)
12730             pri_dump_event(pri->dchans[which], e);
12731 
12732          if (e->e != PRI_EVENT_DCHAN_DOWN) {
12733             if (!(pri->dchanavail[which] & DCHAN_UP)) {
12734                ast_verb(2, "%s D-Channel on span %d up\n", pri_order(which), pri->span);
12735             }
12736             pri->dchanavail[which] |= DCHAN_UP;
12737          } else if (pri->sig != SIG_BRI_PTMP) {
12738             if (pri->dchanavail[which] & DCHAN_UP) {
12739                ast_verb(2, "%s D-Channel on span %d down\n", pri_order(which), pri->span);
12740             }
12741             pri->dchanavail[which] &= ~DCHAN_UP;
12742          }
12743 
12744          if ((e->e != PRI_EVENT_DCHAN_UP) && (e->e != PRI_EVENT_DCHAN_DOWN) && (pri->pri != pri->dchans[which]))
12745             /* Must be an NFAS group that has the secondary dchan active */
12746             pri->pri = pri->dchans[which];
12747 
12748          switch (e->e) {
12749          case PRI_EVENT_DCHAN_UP:
12750             if (!pri->pri) pri_find_dchan(pri);
12751 
12752             /* Note presense of D-channel */
12753             time(&pri->lastreset);
12754 
12755             /* Restart in 5 seconds */
12756             if (pri->resetinterval > -1) {
12757                pri->lastreset -= pri->resetinterval;
12758                pri->lastreset += 5;
12759             }
12760             pri->resetting = 0;
12761             /* Take the channels from inalarm condition */
12762             for (i = 0; i < pri->numchans; i++)
12763                if (pri->pvts[i]) {
12764                   pri->pvts[i]->inalarm = 0;
12765                }
12766             break;
12767          case PRI_EVENT_DCHAN_DOWN:
12768             pri_find_dchan(pri);
12769             if (!pri_is_up(pri)) {
12770                pri->resetting = 0;
12771                /* Hangup active channels and put them in alarm mode */
12772                for (i = 0; i < pri->numchans; i++) {
12773                   struct dahdi_pvt *p = pri->pvts[i];
12774                   if (p) {
12775                      if (!p->pri || !p->pri->pri || pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0) {
12776                         /* T309 is not enabled : hangup calls when alarm occurs */
12777                         if (p->call) {
12778                            if (p->pri && p->pri->pri) {
12779                               pri_hangup(p->pri->pri, p->call, -1);
12780                               pri_destroycall(p->pri->pri, p->call);
12781                               p->call = NULL;
12782                            } else
12783                               ast_log(LOG_WARNING, "The PRI Call have not been destroyed\n");
12784                         }
12785                         if (p->realcall) {
12786                            pri_hangup_all(p->realcall, pri);
12787                         } else if (p->owner)
12788                            p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
12789                      }
12790                      /* For PTMP connections with non persistent layer 2 we want
12791                       * to *not* declare inalarm unless there actually is an alarm */
12792                      if (p->sig != SIG_BRI_PTMP) {
12793                         p->inalarm = 1;
12794                      }
12795                   }
12796                }
12797             }
12798             break;
12799          case PRI_EVENT_RESTART:
12800             if (e->restart.channel > -1) {
12801                chanpos = pri_find_principle(pri, e->restart.channel);
12802                if (chanpos < 0)
12803                   ast_log(LOG_WARNING, "Restart requested on odd/unavailable channel number %d/%d on span %d\n",
12804                      PRI_SPAN(e->restart.channel), PRI_CHANNEL(e->restart.channel), pri->span);
12805                else {
12806                   ast_verb(3, "B-channel %d/%d restarted on span %d\n",
12807                         PRI_SPAN(e->restart.channel), PRI_CHANNEL(e->restart.channel), pri->span);
12808                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
12809                   if (pri->pvts[chanpos]->call) {
12810                      pri_destroycall(pri->pri, pri->pvts[chanpos]->call);
12811                      pri->pvts[chanpos]->call = NULL;
12812                   }
12813                   /* Force soft hangup if appropriate */
12814                   if (pri->pvts[chanpos]->realcall)
12815                      pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
12816                   else if (pri->pvts[chanpos]->owner)
12817                      pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
12818                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
12819                }
12820             } else {
12821                ast_verb(3, "Restart on requested on entire span %d\n", pri->span);
12822                for (x = 0; x < pri->numchans; x++)
12823                   if (pri->pvts[x]) {
12824                      ast_mutex_lock(&pri->pvts[x]->lock);
12825                      if (pri->pvts[x]->call) {
12826                         pri_destroycall(pri->pri, pri->pvts[x]->call);
12827                         pri->pvts[x]->call = NULL;
12828                      }
12829                      if (pri->pvts[x]->realcall)
12830                         pri_hangup_all(pri->pvts[x]->realcall, pri);
12831                      else if (pri->pvts[x]->owner)
12832                         pri->pvts[x]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
12833                      ast_mutex_unlock(&pri->pvts[x]->lock);
12834                   }
12835             }
12836             break;
12837          case PRI_EVENT_KEYPAD_DIGIT:
12838             chanpos = pri_find_principle(pri, e->digit.channel);
12839             if (chanpos < 0) {
12840                ast_log(LOG_WARNING, "KEYPAD_DIGITs received on unconfigured channel %d/%d span %d\n",
12841                   PRI_SPAN(e->digit.channel), PRI_CHANNEL(e->digit.channel), pri->span);
12842             } else {
12843                chanpos = pri_fixup_principle(pri, chanpos, e->digit.call);
12844                if (chanpos > -1) {
12845                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
12846                   /* queue DTMF frame if the PBX for this call was already started (we're forwarding KEYPAD_DIGITs further on */
12847                   if ((pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING) && pri->pvts[chanpos]->call==e->digit.call && pri->pvts[chanpos]->owner) {
12848                      /* how to do that */
12849                      int digitlen = strlen(e->digit.digits);
12850                      char digit;
12851                      int i;
12852                      for (i = 0; i < digitlen; i++) {
12853                         digit = e->digit.digits[i];
12854                         {
12855                            struct ast_frame f = { AST_FRAME_DTMF, digit, };
12856                            dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
12857                         }
12858                      }
12859                   }
12860                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
12861                }
12862             }
12863             break;
12864 
12865          case PRI_EVENT_INFO_RECEIVED:
12866             chanpos = pri_find_principle(pri, e->ring.channel);
12867             if (chanpos < 0) {
12868                ast_log(LOG_WARNING, "INFO received on unconfigured channel %d/%d span %d\n",
12869                   PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
12870             } else {
12871                chanpos = pri_fixup_principle(pri, chanpos, e->ring.call);
12872                if (chanpos > -1) {
12873                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
12874                   /* queue DTMF frame if the PBX for this call was already started (we're forwarding INFORMATION further on */
12875                   if ((pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING) && pri->pvts[chanpos]->call==e->ring.call && pri->pvts[chanpos]->owner) {
12876                      /* how to do that */
12877                      int digitlen = strlen(e->ring.callednum);
12878                      char digit;
12879                      int i;
12880                      for (i = 0; i < digitlen; i++) {
12881                         digit = e->ring.callednum[i];
12882                         {
12883                            struct ast_frame f = { AST_FRAME_DTMF, digit, };
12884                            dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
12885                         }
12886                      }
12887                   }
12888                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
12889                }
12890             }
12891             break;
12892          case PRI_EVENT_RING:
12893             crv = NULL;
12894             if (e->ring.channel == -1)
12895                chanpos = pri_find_empty_chan(pri, 1);
12896             else
12897                chanpos = pri_find_principle(pri, e->ring.channel);
12898             /* if no channel specified find one empty */
12899             if (chanpos < 0) {
12900                ast_log(LOG_WARNING, "Ring requested on unconfigured channel %d/%d span %d\n",
12901                   PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
12902             } else {
12903                ast_mutex_lock(&pri->pvts[chanpos]->lock);
12904                if (pri->pvts[chanpos]->owner) {
12905                   if (pri->pvts[chanpos]->call == e->ring.call) {
12906                      ast_log(LOG_WARNING, "Duplicate setup requested on channel %d/%d already in use on span %d\n",
12907                         PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
12908                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
12909                      break;
12910                   } else {
12911                      /* This is where we handle initial glare */
12912                      ast_debug(1, "Ring requested on channel %d/%d already in use or previously requested on span %d.  Attempting to renegotiate channel.\n",
12913                      PRI_SPAN(e->ring.channel), PRI_CHANNEL(e->ring.channel), pri->span);
12914                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
12915                      chanpos = -1;
12916                   }
12917                }
12918                if (chanpos > -1)
12919                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
12920             }
12921             if ((chanpos < 0) && (e->ring.flexible))
12922                chanpos = pri_find_empty_chan(pri, 1);
12923             if (chanpos > -1) {
12924                ast_mutex_lock(&pri->pvts[chanpos]->lock);
12925                if (pri->switchtype == PRI_SWITCH_GR303_TMC) {
12926                   /* Should be safe to lock CRV AFAIK while bearer is still locked */
12927                   crv = pri_find_crv(pri, pri_get_crv(pri->pri, e->ring.call, NULL));
12928                   if (crv)
12929                      ast_mutex_lock(&crv->lock);
12930                   if (!crv || crv->owner) {
12931                      pri->pvts[chanpos]->call = NULL;
12932                      if (crv) {
12933                         if (crv->owner)
12934                            crv->owner->_softhangup |= AST_SOFTHANGUP_DEV;
12935                         ast_log(LOG_WARNING, "Call received for busy CRV %d on span %d\n", pri_get_crv(pri->pri, e->ring.call, NULL), pri->span);
12936                      } else
12937                         ast_log(LOG_NOTICE, "Call received for unconfigured CRV %d on span %d\n", pri_get_crv(pri->pri, e->ring.call, NULL), pri->span);
12938                      pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_INVALID_CALL_REFERENCE);
12939                      if (crv)
12940                         ast_mutex_unlock(&crv->lock);
12941                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
12942                      break;
12943                   }
12944                }
12945                pri->pvts[chanpos]->call = e->ring.call;
12946                apply_plan_to_number(plancallingnum, sizeof(plancallingnum), pri, e->ring.callingnum, e->ring.callingplan);
12947                if (pri->pvts[chanpos]->use_callerid) {
12948                   ast_shrink_phone_number(plancallingnum);
12949                   ast_copy_string(pri->pvts[chanpos]->cid_num, plancallingnum, sizeof(pri->pvts[chanpos]->cid_num));
12950 #ifdef PRI_ANI
12951                   if (!ast_strlen_zero(e->ring.callingani)) {
12952                      apply_plan_to_number(plancallingani, sizeof(plancallingani), pri, e->ring.callingani, e->ring.callingplanani);
12953                      ast_shrink_phone_number(plancallingani);
12954                      ast_copy_string(pri->pvts[chanpos]->cid_ani, plancallingani, sizeof(pri->pvts[chanpos]->cid_ani));
12955                   } else {
12956                      pri->pvts[chanpos]->cid_ani[0] = '\0';
12957                   }
12958 #endif
12959                   ast_copy_string(pri->pvts[chanpos]->cid_name, e->ring.callingname, sizeof(pri->pvts[chanpos]->cid_name));
12960                   pri->pvts[chanpos]->cid_ton = e->ring.callingplan; /* this is the callingplan (TON/NPI), e->ring.callingplan>>4 would be the TON */
12961                } else {
12962                   pri->pvts[chanpos]->cid_num[0] = '\0';
12963                   pri->pvts[chanpos]->cid_ani[0] = '\0';
12964                   pri->pvts[chanpos]->cid_name[0] = '\0';
12965                   pri->pvts[chanpos]->cid_ton = 0;
12966                }
12967                apply_plan_to_number(pri->pvts[chanpos]->rdnis, sizeof(pri->pvts[chanpos]->rdnis), pri,
12968                   e->ring.redirectingnum, e->ring.callingplanrdnis);
12969                /* If immediate=yes go to s|1 */
12970                if (pri->pvts[chanpos]->immediate) {
12971                   ast_verb(3, "Going to extension s|1 because of immediate=yes\n");
12972                   pri->pvts[chanpos]->exten[0] = 's';
12973                   pri->pvts[chanpos]->exten[1] = '\0';
12974                }
12975                /* Get called number */
12976                else if (!ast_strlen_zero(e->ring.callednum)) {
12977                   ast_copy_string(pri->pvts[chanpos]->exten, e->ring.callednum, sizeof(pri->pvts[chanpos]->exten));
12978                   ast_copy_string(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid));
12979                } else if (pri->overlapdial)
12980                   pri->pvts[chanpos]->exten[0] = '\0';
12981                else {
12982                   /* Some PRI circuits are set up to send _no_ digits.  Handle them as 's'. */
12983                   pri->pvts[chanpos]->exten[0] = 's';
12984                   pri->pvts[chanpos]->exten[1] = '\0';
12985                }
12986                /* Set DNID on all incoming calls -- even immediate */
12987                if (!ast_strlen_zero(e->ring.callednum))
12988                   ast_copy_string(pri->pvts[chanpos]->dnid, e->ring.callednum, sizeof(pri->pvts[chanpos]->dnid));
12989                /* No number yet, but received "sending complete"? */
12990                if (e->ring.complete && (ast_strlen_zero(e->ring.callednum))) {
12991                   ast_verb(3, "Going to extension s|1 because of Complete received\n");
12992                   pri->pvts[chanpos]->exten[0] = 's';
12993                   pri->pvts[chanpos]->exten[1] = '\0';
12994                }
12995 
12996                /* Make sure extension exists (or in overlap dial mode, can exist) */
12997                if (((pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING) && ast_canmatch_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) ||
12998                   ast_exists_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) {
12999                   /* Setup law */
13000                   int law;
13001                   if (pri->switchtype != PRI_SWITCH_GR303_TMC) {
13002                      /* Set to audio mode at this point */
13003                      law = 1;
13004                      if (ioctl(pri->pvts[chanpos]->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &law) == -1)
13005                         ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n", pri->pvts[chanpos]->channel, law, strerror(errno));
13006                   }
13007                   if (e->ring.layer1 == PRI_LAYER_1_ALAW)
13008                      law = DAHDI_LAW_ALAW;
13009                   else
13010                      law = DAHDI_LAW_MULAW;
13011                   res = dahdi_setlaw(pri->pvts[chanpos]->subs[SUB_REAL].dfd, law);
13012                   if (res < 0)
13013                      ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pri->pvts[chanpos]->channel);
13014                   res = set_actual_gain(pri->pvts[chanpos]->subs[SUB_REAL].dfd, 0, pri->pvts[chanpos]->rxgain, pri->pvts[chanpos]->txgain, law);
13015                   if (res < 0)
13016                      ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pri->pvts[chanpos]->channel);
13017                   if (e->ring.complete || !(pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)) {
13018                      /* Just announce proceeding */
13019                      pri->pvts[chanpos]->proceeding = 1;
13020                      pri_proceeding(pri->pri, e->ring.call, PVT_TO_CHANNEL(pri->pvts[chanpos]), 0);
13021                   } else {
13022                      if (pri->switchtype != PRI_SWITCH_GR303_TMC)
13023                         pri_need_more_info(pri->pri, e->ring.call, PVT_TO_CHANNEL(pri->pvts[chanpos]), 1);
13024                      else
13025                         pri_answer(pri->pri, e->ring.call, PVT_TO_CHANNEL(pri->pvts[chanpos]), 1);
13026                   }
13027                   /* Get the use_callingpres state */
13028                   pri->pvts[chanpos]->callingpres = e->ring.callingpres;
13029 
13030                   /* Start PBX */
13031                   if (!e->ring.complete
13032                      && (pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING)
13033                      && ast_matchmore_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) {
13034                      /*
13035                       * Release the PRI lock while we create the channel
13036                       * so other threads can send D channel messages.
13037                       */
13038                      ast_mutex_unlock(&pri->lock);
13039                      if (crv) {
13040                         /* Set bearer and such */
13041                         pri_assign_bearer(crv, pri, pri->pvts[chanpos]);
13042                         c = dahdi_new(crv, AST_STATE_RESERVED, 0, SUB_REAL, law, e->ring.ctype);
13043                         pri->pvts[chanpos]->owner = &inuse;
13044                         ast_debug(1, "Started up crv %d:%d on bearer channel %d\n", pri->trunkgroup, crv->channel, crv->bearer->channel);
13045                      } else {
13046                         c = dahdi_new(pri->pvts[chanpos], AST_STATE_RESERVED, 0, SUB_REAL, law, e->ring.ctype);
13047                      }
13048                      ast_mutex_lock(&pri->lock);
13049                      if (c) {
13050                         if (!ast_strlen_zero(e->ring.callingsubaddr)) {
13051                            pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
13052                         }
13053                         if (e->ring.ani2 >= 0) {
13054                            snprintf(ani2str, sizeof(ani2str), "%d", e->ring.ani2);
13055                            pbx_builtin_setvar_helper(c, "ANI2", ani2str);
13056                            pri->pvts[chanpos]->cid_ani2 = e->ring.ani2;
13057                         }
13058 
13059 #ifdef SUPPORT_USERUSER
13060                         if (!ast_strlen_zero(e->ring.useruserinfo)) {
13061                            pbx_builtin_setvar_helper(c, "USERUSERINFO", e->ring.useruserinfo);
13062                         }
13063 #endif
13064 
13065                         snprintf(calledtonstr, sizeof(calledtonstr), "%d", e->ring.calledplan);
13066                         pbx_builtin_setvar_helper(c, "CALLEDTON", calledtonstr);
13067                         if (e->ring.redirectingreason >= 0)
13068                            pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason));
13069                      }
13070                      if (c && !ast_pthread_create_detached(&threadid, NULL, ss_thread, c)) {
13071                         ast_verb(3, "Accepting overlap call from '%s' to '%s' on channel %d/%d, span %d\n",
13072                            plancallingnum, S_OR(pri->pvts[chanpos]->exten, "<unspecified>"),
13073                            pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
13074                      } else {
13075                         ast_log(LOG_WARNING, "Unable to start PBX on channel %d/%d, span %d\n",
13076                            pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
13077                         if (c)
13078                            ast_hangup(c);
13079                         else {
13080                            pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_SWITCH_CONGESTION);
13081                            pri->pvts[chanpos]->call = NULL;
13082                         }
13083                      }
13084                   } else {
13085                      /*
13086                       * Release the PRI lock while we create the channel
13087                       * so other threads can send D channel messages.
13088                       */
13089                      ast_mutex_unlock(&pri->lock);
13090                      c = dahdi_new(pri->pvts[chanpos], AST_STATE_RING, 0, SUB_REAL, law, e->ring.ctype);
13091                      ast_mutex_lock(&pri->lock);
13092                      if (c) {
13093                         /*
13094                          * It is reasonably safe to set the following
13095                          * channel variables while the PRI and DAHDI private
13096                          * structures are locked.  The PBX has not been
13097                          * started yet and it is unlikely that any other task
13098                          * will do anything with the channel we have just
13099                          * created.
13100                          */
13101                         if (!ast_strlen_zero(e->ring.callingsubaddr)) {
13102                            pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
13103                         }
13104                         if (e->ring.ani2 >= 0) {
13105                            snprintf(ani2str, sizeof(ani2str), "%d", e->ring.ani2);
13106                            pbx_builtin_setvar_helper(c, "ANI2", ani2str);
13107                            pri->pvts[chanpos]->cid_ani2 = e->ring.ani2;
13108                         }
13109 
13110 #ifdef SUPPORT_USERUSER
13111                         if (!ast_strlen_zero(e->ring.useruserinfo)) {
13112                            pbx_builtin_setvar_helper(c, "USERUSERINFO", e->ring.useruserinfo);
13113                         }
13114 #endif
13115 
13116                         if (e->ring.redirectingreason >= 0)
13117                            pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason));
13118 
13119                         snprintf(calledtonstr, sizeof(calledtonstr), "%d", e->ring.calledplan);
13120                         pbx_builtin_setvar_helper(c, "CALLEDTON", calledtonstr);
13121                      }
13122                      if (c && !ast_pbx_start(c)) {
13123                         ast_verb(3, "Accepting call from '%s' to '%s' on channel %d/%d, span %d\n",
13124                            plancallingnum, pri->pvts[chanpos]->exten,
13125                            pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
13126 
13127                         dahdi_enable_ec(pri->pvts[chanpos]);
13128                      } else {
13129                         ast_log(LOG_WARNING, "Unable to start PBX on channel %d/%d, span %d\n",
13130                            pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
13131                         if (c) {
13132                            ast_hangup(c);
13133                         } else {
13134                            pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_SWITCH_CONGESTION);
13135                            pri->pvts[chanpos]->call = NULL;
13136                         }
13137                      }
13138                   }
13139                } else {
13140                   ast_verb(3, "Extension '%s' in context '%s' from '%s' does not exist.  Rejecting call on channel %d/%d, span %d\n",
13141                      pri->pvts[chanpos]->exten, pri->pvts[chanpos]->context, pri->pvts[chanpos]->cid_num, pri->pvts[chanpos]->logicalspan,
13142                      pri->pvts[chanpos]->prioffset, pri->span);
13143                   pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_UNALLOCATED);
13144                   pri->pvts[chanpos]->call = NULL;
13145                   pri->pvts[chanpos]->exten[0] = '\0';
13146                }
13147                if (crv)
13148                   ast_mutex_unlock(&crv->lock);
13149                ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13150             } else {
13151                if (e->ring.flexible)
13152                   pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION);
13153                else
13154                   pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_REQUESTED_CHAN_UNAVAIL);
13155             }
13156             break;
13157          case PRI_EVENT_RINGING:
13158             chanpos = pri_find_principle(pri, e->ringing.channel);
13159             if (chanpos < 0) {
13160                ast_log(LOG_WARNING, "Ringing requested on unconfigured channel %d/%d span %d\n",
13161                   PRI_SPAN(e->ringing.channel), PRI_CHANNEL(e->ringing.channel), pri->span);
13162             } else {
13163                chanpos = pri_fixup_principle(pri, chanpos, e->ringing.call);
13164                if (chanpos < 0) {
13165                   ast_log(LOG_WARNING, "Ringing requested on channel %d/%d not in use on span %d\n",
13166                      PRI_SPAN(e->ringing.channel), PRI_CHANNEL(e->ringing.channel), pri->span);
13167                } else {
13168                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13169                   if (ast_strlen_zero(pri->pvts[chanpos]->dop.dialstr)) {
13170                      dahdi_enable_ec(pri->pvts[chanpos]);
13171                      pri->pvts[chanpos]->subs[SUB_REAL].needringing = 1;
13172                      pri->pvts[chanpos]->alerting = 1;
13173                   } else
13174                      ast_debug(1, "Deferring ringing notification because of extra digits to dial...\n");
13175 
13176                   if (
13177 #ifdef PRI_PROGRESS_MASK
13178                      e->ringing.progressmask & PRI_PROG_INBAND_AVAILABLE
13179 #else
13180                      e->ringing.progress == 8
13181 #endif
13182                      ) {
13183                      /* Now we can do call progress detection */
13184                      if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
13185                         /* RINGING detection isn't required because we got ALERTING signal */
13186                         ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features & ~DSP_PROGRESS_RINGING);
13187                         pri->pvts[chanpos]->dsp_features = 0;
13188                      }
13189                   }
13190 
13191 #ifdef SUPPORT_USERUSER
13192                   if (!ast_strlen_zero(e->ringing.useruserinfo)) {
13193                      struct ast_channel *owner = pri->pvts[chanpos]->owner;
13194                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13195                      pbx_builtin_setvar_helper(owner, "USERUSERINFO", e->ringing.useruserinfo);
13196                      ast_mutex_lock(&pri->pvts[chanpos]->lock);
13197                   }
13198 #endif
13199 
13200                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13201                }
13202             }
13203             break;
13204          case PRI_EVENT_PROGRESS:
13205             /* Get chan value if e->e is not PRI_EVNT_RINGING */
13206             chanpos = pri_find_principle(pri, e->proceeding.channel);
13207             if (chanpos > -1) {
13208                if ((!pri->pvts[chanpos]->progress)
13209 #ifdef PRI_PROGRESS_MASK
13210                   || (e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE)
13211 #else
13212                   || (e->proceeding.progress == 8)
13213 #endif
13214                   ) {
13215                   struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, };
13216 
13217                   if (e->proceeding.cause > -1) {
13218                      ast_verb(3, "PROGRESS with cause code %d received\n", e->proceeding.cause);
13219 
13220                      /* Work around broken, out of spec USER_BUSY cause in a progress message */
13221                      if (e->proceeding.cause == AST_CAUSE_USER_BUSY) {
13222                         if (pri->pvts[chanpos]->owner) {
13223                            ast_verb(3, "PROGRESS with 'user busy' received, signalling AST_CONTROL_BUSY instead of AST_CONTROL_PROGRESS\n");
13224 
13225                            pri->pvts[chanpos]->owner->hangupcause = e->proceeding.cause;
13226                            f.subclass = AST_CONTROL_BUSY;
13227                         }
13228                      }
13229                   }
13230 
13231                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13232                   ast_debug(1, "Queuing frame from PRI_EVENT_PROGRESS on channel %d/%d span %d\n",
13233                      pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
13234                   dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
13235                   if (
13236 #ifdef PRI_PROGRESS_MASK
13237                      e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE
13238 #else
13239                      e->proceeding.progress == 8
13240 #endif
13241                      ) {
13242                      /* Now we can do call progress detection */
13243                      if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
13244                         ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
13245                         pri->pvts[chanpos]->dsp_features = 0;
13246                      }
13247                      /* Bring voice path up */
13248                      f.subclass = AST_CONTROL_PROGRESS;
13249                      dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
13250                   }
13251                   pri->pvts[chanpos]->progress = 1;
13252                   pri->pvts[chanpos]->dialing = 0;
13253                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13254                }
13255             }
13256             break;
13257          case PRI_EVENT_PROCEEDING:
13258             chanpos = pri_find_principle(pri, e->proceeding.channel);
13259             if (chanpos > -1) {
13260                if (!pri->pvts[chanpos]->proceeding) {
13261                   struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROCEEDING, };
13262 
13263                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13264                   ast_debug(1, "Queuing frame from PRI_EVENT_PROCEEDING on channel %d/%d span %d\n",
13265                      pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
13266                   dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
13267                   if (
13268 #ifdef PRI_PROGRESS_MASK
13269                      e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE
13270 #else
13271                      e->proceeding.progress == 8
13272 #endif
13273                      ) {
13274                      /* Now we can do call progress detection */
13275                      if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
13276                         ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
13277                         pri->pvts[chanpos]->dsp_features = 0;
13278                      }
13279                      /* Bring voice path up */
13280                      f.subclass = AST_CONTROL_PROGRESS;
13281                      dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
13282                   }
13283                   pri->pvts[chanpos]->proceeding = 1;
13284                   pri->pvts[chanpos]->dialing = 0;
13285                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13286                }
13287             }
13288             break;
13289          case PRI_EVENT_FACNAME:
13290             chanpos = pri_find_principle(pri, e->facname.channel);
13291             if (chanpos < 0) {
13292                ast_log(LOG_WARNING, "Facility Name requested on unconfigured channel %d/%d span %d\n",
13293                   PRI_SPAN(e->facname.channel), PRI_CHANNEL(e->facname.channel), pri->span);
13294             } else {
13295                chanpos = pri_fixup_principle(pri, chanpos, e->facname.call);
13296                if (chanpos < 0) {
13297                   ast_log(LOG_WARNING, "Facility Name requested on channel %d/%d not in use on span %d\n",
13298                      PRI_SPAN(e->facname.channel), PRI_CHANNEL(e->facname.channel), pri->span);
13299                } else {
13300                   /* Re-use *69 field for PRI */
13301                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13302                   ast_copy_string(pri->pvts[chanpos]->lastcid_num, e->facname.callingnum, sizeof(pri->pvts[chanpos]->lastcid_num));
13303                   ast_copy_string(pri->pvts[chanpos]->lastcid_name, e->facname.callingname, sizeof(pri->pvts[chanpos]->lastcid_name));
13304                   pri->pvts[chanpos]->subs[SUB_REAL].needcallerid =1;
13305                   dahdi_enable_ec(pri->pvts[chanpos]);
13306                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13307                }
13308             }
13309             break;
13310          case PRI_EVENT_ANSWER:
13311             chanpos = pri_find_principle(pri, e->answer.channel);
13312             if (chanpos < 0) {
13313                ast_log(LOG_WARNING, "Answer on unconfigured channel %d/%d span %d\n",
13314                   PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), pri->span);
13315             } else {
13316                chanpos = pri_fixup_principle(pri, chanpos, e->answer.call);
13317                if (chanpos < 0) {
13318                   ast_log(LOG_WARNING, "Answer requested on channel %d/%d not in use on span %d\n",
13319                      PRI_SPAN(e->answer.channel), PRI_CHANNEL(e->answer.channel), pri->span);
13320                } else {
13321                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13322                   /* Now we can do call progress detection */
13323 
13324                   /* We changed this so it turns on the DSP no matter what... progress or no progress.
13325                    * By this time, we need DTMF detection and other features that were previously disabled
13326                    * -- Matt F */
13327                   if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
13328                      ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
13329                      pri->pvts[chanpos]->dsp_features = 0;
13330                   }
13331                   if (pri->pvts[chanpos]->realcall && (pri->pvts[chanpos]->realcall->sig == SIG_FXSKS)) {
13332                      ast_debug(1, "Starting up GR-303 trunk now that we got CONNECT...\n");
13333                      x = DAHDI_START;
13334                      res = ioctl(pri->pvts[chanpos]->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
13335                      if (res < 0) {
13336                         if (errno != EINPROGRESS) {
13337                            ast_log(LOG_WARNING, "Unable to start channel: %s\n", strerror(errno));
13338                         }
13339                      }
13340                   } else if (!ast_strlen_zero(pri->pvts[chanpos]->dop.dialstr)) {
13341                      pri->pvts[chanpos]->dialing = 1;
13342                      /* Send any "w" waited stuff */
13343                      res = ioctl(pri->pvts[chanpos]->subs[SUB_REAL].dfd, DAHDI_DIAL, &pri->pvts[chanpos]->dop);
13344                      if (res < 0) {
13345                         ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", pri->pvts[chanpos]->channel, strerror(errno));
13346                         pri->pvts[chanpos]->dop.dialstr[0] = '\0';
13347                      } else
13348                         ast_debug(1, "Sent deferred digit string: %s\n", pri->pvts[chanpos]->dop.dialstr);
13349 
13350                      pri->pvts[chanpos]->dop.dialstr[0] = '\0';
13351                   } else if (pri->pvts[chanpos]->confirmanswer) {
13352                      ast_debug(1, "Waiting on answer confirmation on channel %d!\n", pri->pvts[chanpos]->channel);
13353                   } else {
13354                      pri->pvts[chanpos]->dialing = 0;
13355                      pri->pvts[chanpos]->subs[SUB_REAL].needanswer =1;
13356                      /* Enable echo cancellation if it's not on already */
13357                      dahdi_enable_ec(pri->pvts[chanpos]);
13358                   }
13359 
13360 #ifdef SUPPORT_USERUSER
13361                   if (!ast_strlen_zero(e->answer.useruserinfo)) {
13362                      struct ast_channel *owner = pri->pvts[chanpos]->owner;
13363                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13364                      pbx_builtin_setvar_helper(owner, "USERUSERINFO", e->answer.useruserinfo);
13365                      ast_mutex_lock(&pri->pvts[chanpos]->lock);
13366                   }
13367 #endif
13368 
13369                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13370                }
13371             }
13372             break;
13373          case PRI_EVENT_HANGUP:
13374             chanpos = pri_find_principle(pri, e->hangup.channel);
13375             if (chanpos < 0) {
13376                ast_log(LOG_WARNING, "Hangup requested on unconfigured channel %d/%d span %d\n",
13377                   PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13378             } else {
13379                chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
13380                if (chanpos > -1) {
13381                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13382                   if (!pri->pvts[chanpos]->alreadyhungup) {
13383                      /* we're calling here dahdi_hangup so once we get there we need to clear p->call after calling pri_hangup */
13384                      pri->pvts[chanpos]->alreadyhungup = 1;
13385                      if (pri->pvts[chanpos]->realcall)
13386                         pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
13387                      else if (pri->pvts[chanpos]->owner) {
13388                         /* Queue a BUSY instead of a hangup if our cause is appropriate */
13389                         pri->pvts[chanpos]->owner->hangupcause = e->hangup.cause;
13390                         switch (pri->pvts[chanpos]->owner->_state) {
13391                         case AST_STATE_BUSY:
13392                         case AST_STATE_UP:
13393                            pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
13394                            break;
13395                         default:
13396                            switch (e->hangup.cause) {
13397                            case PRI_CAUSE_USER_BUSY:
13398                               pri->pvts[chanpos]->subs[SUB_REAL].needbusy =1;
13399                               break;
13400                            case PRI_CAUSE_CALL_REJECTED:
13401                            case PRI_CAUSE_NETWORK_OUT_OF_ORDER:
13402                            case PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION:
13403                            case PRI_CAUSE_SWITCH_CONGESTION:
13404                            case PRI_CAUSE_DESTINATION_OUT_OF_ORDER:
13405                            case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
13406                               pri->pvts[chanpos]->subs[SUB_REAL].needcongestion =1;
13407                               break;
13408                            default:
13409                               pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
13410                            }
13411                            break;
13412                         }
13413                      }
13414                      ast_verb(3, "Channel %d/%d, span %d got hangup, cause %d\n",
13415                            pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span, e->hangup.cause);
13416                   } else {
13417                      pri_hangup(pri->pri, pri->pvts[chanpos]->call, e->hangup.cause);
13418                      pri->pvts[chanpos]->call = NULL;
13419                   }
13420                   if (e->hangup.cause == PRI_CAUSE_REQUESTED_CHAN_UNAVAIL) {
13421                      ast_verb(3, "Forcing restart of channel %d/%d on span %d since channel reported in use\n",
13422                            PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13423                      pri_reset(pri->pri, PVT_TO_CHANNEL(pri->pvts[chanpos]));
13424                      pri->pvts[chanpos]->resetting = 1;
13425                   }
13426                   if (e->hangup.aoc_units > -1)
13427                      ast_verb(3, "Channel %d/%d, span %d received AOC-E charging %d unit%s\n",
13428                            pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span, (int)e->hangup.aoc_units, (e->hangup.aoc_units == 1) ? "" : "s");
13429 
13430 #ifdef SUPPORT_USERUSER
13431                   if (pri->pvts[chanpos]->owner && !ast_strlen_zero(e->hangup.useruserinfo)) {
13432                      struct ast_channel *owner = pri->pvts[chanpos]->owner;
13433                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13434                      pbx_builtin_setvar_helper(owner, "USERUSERINFO", e->hangup.useruserinfo);
13435                      ast_mutex_lock(&pri->pvts[chanpos]->lock);
13436                   }
13437 #endif
13438 
13439                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13440                } else {
13441                   ast_log(LOG_WARNING, "Hangup on bad channel %d/%d on span %d\n",
13442                      PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13443                }
13444             }
13445             break;
13446 #ifndef PRI_EVENT_HANGUP_REQ
13447 #error please update libpri
13448 #endif
13449          case PRI_EVENT_HANGUP_REQ:
13450             chanpos = pri_find_principle(pri, e->hangup.channel);
13451             if (chanpos < 0) {
13452                ast_log(LOG_WARNING, "Hangup REQ requested on unconfigured channel %d/%d span %d\n",
13453                   PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13454             } else {
13455                chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
13456                if (chanpos > -1) {
13457                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13458                   if (pri->pvts[chanpos]->realcall)
13459                      pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
13460                   else if (pri->pvts[chanpos]->owner) {
13461                      pri->pvts[chanpos]->owner->hangupcause = e->hangup.cause;
13462                      switch (pri->pvts[chanpos]->owner->_state) {
13463                      case AST_STATE_BUSY:
13464                      case AST_STATE_UP:
13465                         pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
13466                         break;
13467                      default:
13468                         switch (e->hangup.cause) {
13469                         case PRI_CAUSE_USER_BUSY:
13470                            pri->pvts[chanpos]->subs[SUB_REAL].needbusy =1;
13471                            break;
13472                         case PRI_CAUSE_CALL_REJECTED:
13473                         case PRI_CAUSE_NETWORK_OUT_OF_ORDER:
13474                         case PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION:
13475                         case PRI_CAUSE_SWITCH_CONGESTION:
13476                         case PRI_CAUSE_DESTINATION_OUT_OF_ORDER:
13477                         case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
13478                            pri->pvts[chanpos]->subs[SUB_REAL].needcongestion =1;
13479                            break;
13480                         default:
13481                            pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
13482                            break;
13483                         }
13484                         break;
13485                      }
13486                      ast_verb(3, "Channel %d/%d, span %d got hangup request, cause %d\n", PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span, e->hangup.cause);
13487                      if (e->hangup.aoc_units > -1)
13488                         ast_verb(3, "Channel %d/%d, span %d received AOC-E charging %d unit%s\n",
13489                               pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span, (int)e->hangup.aoc_units, (e->hangup.aoc_units == 1) ? "" : "s");
13490                   } else {
13491                      pri_hangup(pri->pri, pri->pvts[chanpos]->call, e->hangup.cause);
13492                      pri->pvts[chanpos]->call = NULL;
13493                   }
13494                   if (e->hangup.cause == PRI_CAUSE_REQUESTED_CHAN_UNAVAIL) {
13495                      ast_verb(3, "Forcing restart of channel %d/%d span %d since channel reported in use\n",
13496                            PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13497                      pri_reset(pri->pri, PVT_TO_CHANNEL(pri->pvts[chanpos]));
13498                      pri->pvts[chanpos]->resetting = 1;
13499                   }
13500 
13501 #ifdef SUPPORT_USERUSER
13502                   if (!ast_strlen_zero(e->hangup.useruserinfo)) {
13503                      struct ast_channel *owner = pri->pvts[chanpos]->owner;
13504                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13505                      pbx_builtin_setvar_helper(owner, "USERUSERINFO", e->hangup.useruserinfo);
13506                      ast_mutex_lock(&pri->pvts[chanpos]->lock);
13507                   }
13508 #endif
13509 
13510                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13511                } else {
13512                   ast_log(LOG_WARNING, "Hangup REQ on bad channel %d/%d on span %d\n", PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13513                }
13514             }
13515             break;
13516          case PRI_EVENT_HANGUP_ACK:
13517             chanpos = pri_find_principle(pri, e->hangup.channel);
13518             if (chanpos < 0) {
13519                ast_log(LOG_WARNING, "Hangup ACK requested on unconfigured channel number %d/%d span %d\n",
13520                   PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13521             } else {
13522                chanpos = pri_fixup_principle(pri, chanpos, e->hangup.call);
13523                if (chanpos > -1) {
13524                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13525                   pri->pvts[chanpos]->call = NULL;
13526                   pri->pvts[chanpos]->resetting = 0;
13527                   if (pri->pvts[chanpos]->owner) {
13528                      ast_verb(3, "Channel %d/%d, span %d got hangup ACK\n", PRI_SPAN(e->hangup.channel), PRI_CHANNEL(e->hangup.channel), pri->span);
13529                   }
13530 
13531 #ifdef SUPPORT_USERUSER
13532                   if (!ast_strlen_zero(e->hangup.useruserinfo)) {
13533                      struct ast_channel *owner = pri->pvts[chanpos]->owner;
13534                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13535                      pbx_builtin_setvar_helper(owner, "USERUSERINFO", e->hangup.useruserinfo);
13536                      ast_mutex_lock(&pri->pvts[chanpos]->lock);
13537                   }
13538 #endif
13539 
13540                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13541                }
13542             }
13543             break;
13544          case PRI_EVENT_CONFIG_ERR:
13545             ast_log(LOG_WARNING, "PRI Error on span %d: %s\n", pri->trunkgroup, e->err.err);
13546             break;
13547          case PRI_EVENT_RESTART_ACK:
13548             chanpos = pri_find_principle(pri, e->restartack.channel);
13549             if (chanpos < 0) {
13550                /* Sometime switches (e.g. I421 / British Telecom) don't give us the
13551                   channel number, so we have to figure it out...  This must be why
13552                   everybody resets exactly a channel at a time. */
13553                for (x = 0; x < pri->numchans; x++) {
13554                   if (pri->pvts[x] && pri->pvts[x]->resetting) {
13555                      chanpos = x;
13556                      ast_mutex_lock(&pri->pvts[chanpos]->lock);
13557                      ast_debug(1, "Assuming restart ack is really for channel %d/%d span %d\n", pri->pvts[chanpos]->logicalspan,
13558                         pri->pvts[chanpos]->prioffset, pri->span);
13559                      if (pri->pvts[chanpos]->realcall)
13560                         pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
13561                      else if (pri->pvts[chanpos]->owner) {
13562                         ast_log(LOG_WARNING, "Got restart ack on channel %d/%d with owner on span %d\n", pri->pvts[chanpos]->logicalspan,
13563                            pri->pvts[chanpos]->prioffset, pri->span);
13564                         pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
13565                      }
13566                      pri->pvts[chanpos]->resetting = 0;
13567                      ast_verb(3, "B-channel %d/%d successfully restarted on span %d\n", pri->pvts[chanpos]->logicalspan,
13568                            pri->pvts[chanpos]->prioffset, pri->span);
13569                      ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13570                      if (pri->resetting)
13571                         pri_check_restart(pri);
13572                      break;
13573                   }
13574                }
13575                if (chanpos < 0) {
13576                   ast_log(LOG_WARNING, "Restart ACK requested on strange channel %d/%d span %d\n",
13577                      PRI_SPAN(e->restartack.channel), PRI_CHANNEL(e->restartack.channel), pri->span);
13578                }
13579             } else {
13580                if (pri->pvts[chanpos]) {
13581                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13582                   if (pri->pvts[chanpos]->realcall)
13583                      pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
13584                   else if (pri->pvts[chanpos]->owner) {
13585                      ast_log(LOG_WARNING, "Got restart ack on channel %d/%d span %d with owner\n",
13586                         PRI_SPAN(e->restartack.channel), PRI_CHANNEL(e->restartack.channel), pri->span);
13587                      pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
13588                   }
13589                   pri->pvts[chanpos]->resetting = 0;
13590                   pri->pvts[chanpos]->inservice = 1;
13591                   ast_verb(3, "B-channel %d/%d successfully restarted on span %d\n", pri->pvts[chanpos]->logicalspan,
13592                            pri->pvts[chanpos]->prioffset, pri->span);
13593                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13594                   if (pri->resetting)
13595                      pri_check_restart(pri);
13596                }
13597             }
13598             break;
13599          case PRI_EVENT_SETUP_ACK:
13600             chanpos = pri_find_principle(pri, e->setup_ack.channel);
13601             if (chanpos < 0) {
13602                ast_log(LOG_WARNING, "Received SETUP_ACKNOWLEDGE on unconfigured channel %d/%d span %d\n",
13603                   PRI_SPAN(e->setup_ack.channel), PRI_CHANNEL(e->setup_ack.channel), pri->span);
13604             } else {
13605                chanpos = pri_fixup_principle(pri, chanpos, e->setup_ack.call);
13606                if (chanpos > -1) {
13607                   ast_mutex_lock(&pri->pvts[chanpos]->lock);
13608                   pri->pvts[chanpos]->setup_ack = 1;
13609                   /* Send any queued digits */
13610                   for (x = 0;x < strlen(pri->pvts[chanpos]->dialdest); x++) {
13611                      ast_debug(1, "Sending pending digit '%c'\n", pri->pvts[chanpos]->dialdest[x]);
13612                      pri_information(pri->pri, pri->pvts[chanpos]->call,
13613                         pri->pvts[chanpos]->dialdest[x]);
13614                   }
13615                   ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13616                } else
13617                   ast_log(LOG_WARNING, "Unable to move channel %d!\n", e->setup_ack.channel);
13618             }
13619             break;
13620          case PRI_EVENT_NOTIFY:
13621             chanpos = pri_find_principle(pri, e->notify.channel);
13622             if (chanpos < 0) {
13623                ast_log(LOG_WARNING, "Received NOTIFY on unconfigured channel %d/%d span %d\n",
13624                   PRI_SPAN(e->notify.channel), PRI_CHANNEL(e->notify.channel), pri->span);
13625             } else if (!pri->discardremoteholdretrieval) {
13626                struct ast_frame f = { AST_FRAME_CONTROL, };
13627                ast_mutex_lock(&pri->pvts[chanpos]->lock);
13628                switch (e->notify.info) {
13629                case PRI_NOTIFY_REMOTE_HOLD:
13630                   f.subclass = AST_CONTROL_HOLD;
13631                   dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
13632                   break;
13633                case PRI_NOTIFY_REMOTE_RETRIEVAL:
13634                   f.subclass = AST_CONTROL_UNHOLD;
13635                   dahdi_queue_frame(pri->pvts[chanpos], &f, pri);
13636                   break;
13637                }
13638                ast_mutex_unlock(&pri->pvts[chanpos]->lock);
13639             }
13640             break;
13641          default:
13642             ast_debug(1, "Event: %d\n", e->e);
13643          }
13644       }
13645       ast_mutex_unlock(&pri->lock);
13646    }
13647    /* Never reached */
13648    return NULL;
13649 }

static struct dahdi_pvt* pri_find_crv ( struct dahdi_pri *  pri,
int  crv 
) [static, read]

Definition at line 12149 of file chan_dahdi.c.

References dahdi_pvt::channel, dahdi_pri::crvs, and dahdi_pvt::next.

Referenced by pri_dchannel().

12150 {
12151    struct dahdi_pvt *p;
12152    p = pri->crvs;
12153    while (p) {
12154       if (p->channel == crv)
12155          return p;
12156       p = p->next;
12157    }
12158    return NULL;
12159 }

static int pri_find_dchan ( struct dahdi_pri *  pri  )  [static]

Definition at line 4142 of file chan_dahdi.c.

References ast_log(), DCHAN_AVAILABLE, dahdi_pri::dchanavail, dahdi_pri::dchannels, dahdi_pri::dchans, LOG_NOTICE, LOG_WARNING, NUM_DCHANS, dahdi_pri::pri, dahdi_pri::sig, and SIG_BRI_PTMP.

Referenced by pri_dchannel().

04143 {
04144    int oldslot = -1;
04145    struct pri *old;
04146    int newslot = -1;
04147    int x;
04148    old = pri->pri;
04149    for (x = 0; x < NUM_DCHANS; x++) {
04150       if ((pri->dchanavail[x] == DCHAN_AVAILABLE) && (newslot < 0))
04151          newslot = x;
04152       if (pri->dchans[x] == old) {
04153          oldslot = x;
04154       }
04155    }
04156    if (newslot < 0) {
04157       newslot = 0;
04158       /* This is annoying to see on non persistent layer 2 connections.  Let's not complain in that case */
04159       if (pri->sig != SIG_BRI_PTMP) {
04160          ast_log(LOG_WARNING, "No D-channels available!  Using Primary channel %d as D-channel anyway!\n",
04161             pri->dchannels[newslot]);
04162       }
04163    }
04164    if (old && (oldslot != newslot))
04165       ast_log(LOG_NOTICE, "Switching from from d-channel %d to channel %d!\n",
04166          pri->dchannels[oldslot], pri->dchannels[newslot]);
04167    pri->pri = pri->dchans[newslot];
04168    return 0;
04169 }

static int pri_find_empty_chan ( struct dahdi_pri *  pri,
int  backwards 
) [static]

Definition at line 10924 of file chan_dahdi.c.

References ast_debug, dahdi_pvt::inalarm, dahdi_pvt::logicalspan, dahdi_pri::numchans, dahdi_pvt::owner, dahdi_pvt::prioffset, and dahdi_pri::pvts.

Referenced by dahdi_request(), and pri_dchannel().

10925 {
10926    int x;
10927    if (backwards)
10928       x = pri->numchans;
10929    else
10930       x = 0;
10931    for (;;) {
10932       if (backwards && (x < 0))
10933          break;
10934       if (!backwards && (x >= pri->numchans))
10935          break;
10936       if (pri->pvts[x] && !pri->pvts[x]->inalarm && !pri->pvts[x]->owner) {
10937          ast_debug(1, "Found empty available channel %d/%d\n",
10938             pri->pvts[x]->logicalspan, pri->pvts[x]->prioffset);
10939          return x;
10940       }
10941       if (backwards)
10942          x--;
10943       else
10944          x++;
10945    }
10946    return -1;
10947 }

static int pri_find_principle ( struct dahdi_pri *  pri,
int  channel 
) [static]

Definition at line 12163 of file chan_dahdi.c.

References dahdi_pvt::logicalspan, dahdi_pri::numchans, pri_active_dchan_fd(), PRI_CHANNEL, PRI_EXPLICIT, PRI_SPAN, dahdi_pri::prilogicalspan, dahdi_pvt::prioffset, pris, dahdi_pri::pvts, and dahdi_pvt::span.

Referenced by pri_dchannel().

12164 {
12165    int x;
12166    int span = PRI_SPAN(channel);
12167    int spanfd;
12168    struct dahdi_params param;
12169    int principle = -1;
12170    int explicit = PRI_EXPLICIT(channel);
12171    channel = PRI_CHANNEL(channel);
12172 
12173    if (!explicit) {
12174       spanfd = pri_active_dchan_fd(pri);
12175       memset(&param, 0, sizeof(param));
12176       if (ioctl(spanfd, DAHDI_GET_PARAMS, &param))
12177          return -1;
12178       span = pris[param.spanno - 1].prilogicalspan;
12179    }
12180 
12181    for (x = 0; x < pri->numchans; x++) {
12182       if (pri->pvts[x] && (pri->pvts[x]->prioffset == channel) && (pri->pvts[x]->logicalspan == span)) {
12183          principle = x;
12184          break;
12185       }
12186    }
12187 
12188    return principle;
12189 }

static int pri_fixup_principle ( struct dahdi_pri *  pri,
int  principle,
q931_call *  c 
) [static]

Definition at line 12193 of file chan_dahdi.c.

References ast_channel_set_fd(), ast_debug, ast_log(), ast_string_field_build, ast_verb, dahdi_pvt::bearer, dahdi_pvt::call, dahdi_pvt::channel, dahdi_pri::crvs, dahdi_close_sub(), LOG_WARNING, dahdi_pvt::logicalspan, name, dahdi_pvt::next, dahdi_pri::numchans, dahdi_pvt::owner, pri_assign_bearer(), dahdi_pvt::prioffset, dahdi_pri::pvts, SUB_REAL, dahdi_pri::trunkgroup, and wakeup_sub().

Referenced by pri_dchannel().

12194 {
12195    int x;
12196    struct dahdi_pvt *crv;
12197    if (!c) {
12198       if (principle < 0)
12199          return -1;
12200       return principle;
12201    }
12202    if ((principle > -1) &&
12203       (principle < pri->numchans) &&
12204       (pri->pvts[principle]) &&
12205       (pri->pvts[principle]->call == c))
12206       return principle;
12207    /* First, check for other bearers */
12208    for (x = 0; x < pri->numchans; x++) {
12209       if (!pri->pvts[x])
12210          continue;
12211       if (pri->pvts[x]->call == c) {
12212          /* Found our call */
12213          if (principle != x) {
12214             struct dahdi_pvt *new = pri->pvts[principle], *old = pri->pvts[x];
12215 
12216             ast_verb(3, "Moving call from channel %d to channel %d\n",
12217                 old->channel, new->channel);
12218             if (new->owner) {
12219                ast_log(LOG_WARNING, "Can't fix up channel from %d to %d because %d is already in use\n",
12220                   old->channel, new->channel, new->channel);
12221                return -1;
12222             }
12223             /* Fix it all up now */
12224             new->owner = old->owner;
12225             old->owner = NULL;
12226             if (new->owner) {
12227                ast_string_field_build(new->owner, name,
12228                   "DAHDI/%d:%d-%d", pri->trunkgroup,
12229                   new->channel, 1);
12230                new->owner->tech_pvt = new;
12231                ast_channel_set_fd(new->owner, 0, new->subs[SUB_REAL].dfd);
12232                new->subs[SUB_REAL].owner = old->subs[SUB_REAL].owner;
12233                old->subs[SUB_REAL].owner = NULL;
12234             } else
12235                ast_log(LOG_WARNING, "Whoa, there's no  owner, and we're having to fix up channel %d to channel %d\n", old->channel, new->channel);
12236             new->call = old->call;
12237             old->call = NULL;
12238 
12239             /* Copy any DSP that may be present */
12240             new->dsp = old->dsp;
12241             new->dsp_features = old->dsp_features;
12242             old->dsp = NULL;
12243             old->dsp_features = 0;
12244          }
12245          return principle;
12246       }
12247    }
12248    /* Now check for a CRV with no bearer */
12249    crv = pri->crvs;
12250    while (crv) {
12251       if (crv->call == c) {
12252          /* This is our match...  Perform some basic checks */
12253          if (crv->bearer)
12254             ast_log(LOG_WARNING, "Trying to fix up call which already has a bearer which isn't the one we think it is\n");
12255          else if (pri->pvts[principle]->owner)
12256             ast_log(LOG_WARNING, "Tring to fix up a call to a bearer which already has an owner!\n");
12257          else {
12258             /* Looks good.  Drop the pseudo channel now, clear up the assignment, and
12259                wakeup the potential sleeper */
12260             dahdi_close_sub(crv, SUB_REAL);
12261             pri->pvts[principle]->call = crv->call;
12262             pri_assign_bearer(crv, pri, pri->pvts[principle]);
12263             ast_debug(1, "Assigning bearer %d/%d to CRV %d:%d\n",
12264                pri->pvts[principle]->logicalspan, pri->pvts[principle]->prioffset,
12265                pri->trunkgroup, crv->channel);
12266             wakeup_sub(crv, SUB_REAL, pri);
12267          }
12268          return principle;
12269       }
12270       crv = crv->next;
12271    }
12272    ast_log(LOG_WARNING, "Call specified, but not found?\n");
12273    return -1;
12274 }

static int pri_grab ( struct dahdi_pvt *  pvt,
struct dahdi_pri *  pri 
) [inline, static]

Definition at line 1433 of file chan_dahdi.c.

References ast_mutex_trylock(), AST_PTHREADT_NULL, DEADLOCK_AVOIDANCE, dahdi_pvt::lock, dahdi_pri::lock, and dahdi_pri::master.

Referenced by dahdi_answer(), dahdi_call(), dahdi_digit_begin(), dahdi_handle_event(), dahdi_hangup(), dahdi_indicate(), dahdi_send_keypad_facility_exec(), dahdi_write(), and ss_thread().

01434 {
01435    int res;
01436    /* Grab the lock first */
01437    do {
01438       res = ast_mutex_trylock(&pri->lock);
01439       if (res) {
01440          DEADLOCK_AVOIDANCE(&pvt->lock);
01441       }
01442    } while (res);
01443    /* Then break the poll */
01444    if (pri->master != AST_PTHREADT_NULL)
01445       pthread_kill(pri->master, SIGURG);
01446    return 0;
01447 }

static int pri_hangup_all ( struct dahdi_pvt *  p,
struct dahdi_pri *  pri 
) [static]

Definition at line 12434 of file chan_dahdi.c.

References AST_CAUSE_PRE_EMPTED, ast_channel_trylock, ast_channel_unlock, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_hangup_with_cause(), DEADLOCK_AVOIDANCE, dahdi_pvt::lock, dahdi_pri::lock, dahdi_subchannel::owner, and dahdi_pvt::subs.

Referenced by pri_dchannel().

12435 {
12436    int x;
12437    int redo;
12438    ast_mutex_unlock(&pri->lock);
12439    ast_mutex_lock(&p->lock);
12440    do {
12441       redo = 0;
12442       for (x = 0; x < 3; x++) {
12443          while (p->subs[x].owner && ast_channel_trylock(p->subs[x].owner)) {
12444             redo++;
12445             DEADLOCK_AVOIDANCE(&p->lock);
12446          }
12447          if (p->subs[x].owner) {
12448             ast_queue_hangup_with_cause(p->subs[x].owner, AST_CAUSE_PRE_EMPTED);
12449             ast_channel_unlock(p->subs[x].owner);
12450          }
12451       }
12452    } while (redo);
12453    ast_mutex_unlock(&p->lock);
12454    ast_mutex_lock(&pri->lock);
12455    return 0;
12456 }

static int pri_is_up ( struct dahdi_pri *  pri  )  [static]

Definition at line 4082 of file chan_dahdi.c.

References DCHAN_AVAILABLE, dahdi_pri::dchanavail, and NUM_DCHANS.

Referenced by mkintf(), and pri_dchannel().

04083 {
04084    int x;
04085    for (x = 0; x < NUM_DCHANS; x++) {
04086       if (pri->dchanavail[x] == DCHAN_AVAILABLE)
04087          return 1;
04088    }
04089    return 0;
04090 }

static char* pri_order ( int  level  )  [static]

Definition at line 4109 of file chan_dahdi.c.

Referenced by handle_pri_show_span(), and pri_dchannel().

04110 {
04111    switch (level) {
04112    case 0:
04113       return "Primary";
04114    case 1:
04115       return "Secondary";
04116    case 2:
04117       return "Tertiary";
04118    case 3:
04119       return "Quaternary";
04120    default:
04121       return "<Unknown>";
04122    }
04123 }

static void pri_rel ( struct dahdi_pri *  pri  )  [inline, static]

static int pri_resolve_span ( int *  span,
int  channel,
int  offset,
struct dahdi_spaninfo *  si 
) [static]

Definition at line 9836 of file chan_dahdi.c.

References ast_log(), DCHAN_PROVISIONED, dahdi_pri::dchanavail, dahdi_pri::dchannels, LOG_WARNING, dahdi_pri::mastertrunkgroup, NUM_SPANS, dahdi_pri::offset, pris, and dahdi_pri::span.

Referenced by mkintf().

09837 {
09838    int x;
09839    int trunkgroup;
09840    /* Get appropriate trunk group if there is one */
09841    trunkgroup = pris[*span].mastertrunkgroup;
09842    if (trunkgroup) {
09843       /* Select a specific trunk group */
09844       for (x = 0; x < NUM_SPANS; x++) {
09845          if (pris[x].trunkgroup == trunkgroup) {
09846             *span = x;
09847             return 0;
09848          }
09849       }
09850       ast_log(LOG_WARNING, "Channel %d on span %d configured to use nonexistent trunk group %d\n", channel, *span, trunkgroup);
09851       *span = -1;
09852    } else {
09853       if (pris[*span].trunkgroup) {
09854          ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is trunk group %d (please use spanmap)\n", *span, pris[*span].trunkgroup);
09855          *span = -1;
09856       } else if (pris[*span].mastertrunkgroup) {
09857          ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is already part of trunk group %d\n", *span, pris[*span].mastertrunkgroup);
09858          *span = -1;
09859       } else {
09860          if (si->totalchans == 31) {
09861             /* E1 */
09862             pris[*span].dchannels[0] = 16 + offset;
09863          } else if (si->totalchans == 24) {
09864             /* T1 or J1 */
09865             pris[*span].dchannels[0] = 24 + offset;
09866          } else if (si->totalchans == 3) {
09867             /* BRI */
09868             pris[*span].dchannels[0] = 3 + offset;
09869          } else {
09870             ast_log(LOG_WARNING, "Unable to use span %d, since the D-channel cannot be located (unexpected span size of %d channels)\n", *span, si->totalchans);
09871             *span = -1;
09872             return 0;
09873          }
09874          pris[*span].dchanavail[0] |= DCHAN_PROVISIONED;
09875          pris[*span].offset = offset;
09876          pris[*span].span = *span + 1;
09877       }
09878    }
09879    return 0;
09880 }

static int process_dahdi ( struct dahdi_chan_conf *  confp,
const char *  cat,
struct ast_variable *  v,
int  reload,
int  options 
) [static]

Definition at line 16213 of file chan_dahdi.c.

References dahdi_mfcr2_conf::accept_on_offer, dahdi_pvt::accountcode, dahdi_pvt::adsi, dahdi_mfcr2_conf::allow_collect_calls, dahdi_pvt::amaflags, dahdi_pvt::answeronpolarityswitch, ast_callerid_split(), ast_cdr_amaflags2int(), ast_copy_string(), ast_get_group(), ast_jb_read_conf(), ast_log(), AST_MAX_EXTENSION, ast_strdupa, ast_strlen_zero(), ast_true(), ast_variable_new(), ast_verb, dahdi_pvt::buf_no, dahdi_pvt::buf_policy, build_channels(), dahdi_pvt::busy_quietlength, dahdi_pvt::busy_tonelength, dahdi_pvt::busycount, dahdi_pvt::busydetect, dahdi_mfcr2_conf::call_files, dahdi_ss7::called_nai, dahdi_pvt::callgroup, dahdi_ss7::calling_nai, dahdi_pvt::callprogress, CALLPROGRESS_FAX, CALLPROGRESS_FAX_INCOMING, CALLPROGRESS_FAX_OUTGOING, CALLPROGRESS_PROGRESS, dahdi_pvt::callreturn, dahdi_pvt::callwaiting, dahdi_pvt::callwaitingcallerid, dahdi_pvt::cancallforward, dahdi_pvt::canpark, dahdi_mfcr2_conf::category, dahdi_chan_conf::chan, CHAN_PSEUDO, dahdi_mfcr2_conf::charge_calls, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::cid_rxgain, CID_SIG_BELL, CID_SIG_DTMF, CID_SIG_SMDI, CID_SIG_V23, CID_SIG_V23_JP, dahdi_pvt::cid_signalling, dahdi_pvt::cid_start, CID_START_POLARITY, CID_START_POLARITY_IN, CID_START_RING, dahdi_pvt::context, ringContextData::contextData, dahdi_chan_conf_default(), DAHDI_CHAN_MAPPING_LOGICAL, DAHDI_CHAN_MAPPING_PHYSICAL, DAHDI_OVERLAPDIAL_BOTH, DAHDI_OVERLAPDIAL_INCOMING, DAHDI_OVERLAPDIAL_NONE, DAHDI_OVERLAPDIAL_OUTGOING, dahdi_pvt::dahditrcallerid, dahdi_pri::dialplan, dahdi_pri::discardremoteholdretrieval, dahdi_mfcr2_conf::double_answer, dahdi_pvt::drings, DSP_DIGITMODE_RELAXDTMF, dahdi_pvt::dtmfrelax, dahdi_pvt::echocanbridged, dahdi_pvt::echotraining, errno, dahdi_pri::facilityenable, dahdi_pvt::faxbuf_no, dahdi_pvt::faxbuf_policy, dahdi_ss7::flags, dahdi_mfcr2_conf::forced_release, dahdi_mfcr2_conf::get_ani_first, global_jbconf, dahdi_pvt::group, dahdi_pvt::hanguponpolarityswitch, HAVE_PRI, dahdi_pvt::hidecallerid, dahdi_pvt::hidecalleridname, dahdi_pri::idledial, dahdi_pri::idleext, dahdi_pvt::immediate, dahdi_mfcr2_conf::immediate_accept, dahdi_pri::inbanddisconnect, dahdi_ss7::internationalprefix, dahdi_pri::internationalprefix, dahdi_chan_conf::is_sig_auto, dahdi_pvt::language, ast_variable::lineno, linkset_addsigchan(), LINKSET_FLAG_EXPLICITACM, dahdi_pri::localdialplan, dahdi_pri::localprefix, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, dahdi_mfcr2_conf::logdir, dahdi_mfcr2_conf::loglevel, dahdi_pvt::mailbox, dahdi_mfcr2_conf::max_ani, MAX_CHANLIST_LEN, dahdi_mfcr2_conf::max_dnis, dahdi_mfcr2_conf::metering_pulse_timeout, dahdi_mfcr2_conf::mfback_timeout, dahdi_chan_conf::mfcr2, dahdi_pri::minidle, dahdi_pri::minunused, mkintf(), dahdi_pvt::mohinterpret, dahdi_pvt::mohsuggest, dahdi_pvt::mwimonitor_fsk, dahdi_pvt::mwimonitor_neon, dahdi_pvt::mwimonitor_rpas, dahdi_pvt::mwisend_fsk, dahdi_pvt::mwisend_rpas, dahdi_pvt::mwisend_setting, ast_variable::name, dahdi_ss7::nationalprefix, dahdi_pri::nationalprefix, ast_variable::next, dahdi_pri::nodetype, dahdi_pri::nsf, NUM_CADENCE_MAX, NUM_SPANS, dahdi_pvt::outsigmod, dahdi_pri::overlapdial, dahdi_pvt::parkinglot, parse_buffers_policy(), parse_pointcode(), dahdi_pvt::pickupgroup, dahdi_pvt::polarityonanswerdelay, dahdi_chan_conf::pri, dahdi_pvt::priexclusive, dahdi_pvt::priindication_oob, dahdi_pri::privateprefix, PROC_DAHDI_OPT_NOCHAN, PROC_DAHDI_OPT_NOWARN, process_echocancel(), dahdi_pvt::pulse, dahdi_pri::qsigchannelmapping, dahdi_mfcr2_conf::r2proto_file, dahdi_pvt::radio, distRingData::range, READ_SIZE, dahdi_pri::resetinterval, dahdi_pvt::restrictcid, distRingData::ring, dahdi_distRings::ringContext, dahdi_distRings::ringnum, dahdi_pvt::rxgain, dahdi_pvt::sendcalleridafter, dahdi_pvt::sig, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_GR303FXOKS, SIG_GR303FXSKS, SIG_MFCR2, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SFWINK, SIG_SS7, dahdi_chan_conf::smdi_port, dahdi_chan_conf::ss7, SS7_NAI_DYNAMIC, ss7_resolve_linkset(), strcasestr(), dahdi_pvt::stripmsd, strsep(), dahdi_ss7::subscriberprefix, dahdi_pri::switchtype, dahdi_pvt::threewaycalling, timer, dahdi_chan_conf::timing, dahdi_pvt::tonezone, dahdi_pvt::transfer, dahdi_pvt::transfertobusy, dahdi_pvt::txgain, dahdi_ss7::unknownprefix, dahdi_pri::unknownprefix, dahdi_pvt::use_callerid, dahdi_pvt::use_callingpres, dahdi_pvt::use_smdi, dahdi_pvt::usefaxbuffers, ast_variable::value, dahdi_mfcr2_conf::variant, dahdi_pvt::vars, and dahdi_pvt::waitfordialtone.

Referenced by setup_dahdi().

16214 {
16215    struct dahdi_pvt *tmp;
16216    int y;
16217    int found_pseudo = 0;
16218    char dahdichan[MAX_CHANLIST_LEN] = {};
16219 
16220    for (; v; v = v->next) {
16221       if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
16222          continue;
16223 
16224       /* must have parkinglot in confp before build_channels is called */
16225       if (!strcasecmp(v->name, "parkinglot")) {
16226          ast_copy_string(confp->chan.parkinglot, v->value, sizeof(confp->chan.parkinglot));
16227       }
16228 
16229       /* Create the interface list */
16230       if (!strcasecmp(v->name, "channel")
16231 #ifdef HAVE_PRI
16232          || !strcasecmp(v->name, "crv")
16233 #endif
16234          ) {
16235          int iscrv;
16236          if (options & PROC_DAHDI_OPT_NOCHAN) {
16237             ast_log(LOG_WARNING, "Channel '%s' ignored.\n", v->value);
16238             continue;
16239          }
16240          iscrv = !strcasecmp(v->name, "crv");
16241          if (build_channels(confp, iscrv, v->value, reload, v->lineno, &found_pseudo))
16242                return -1;
16243          ast_log(LOG_DEBUG, "Channel '%s' configured.\n", v->value);
16244       } else if (!strcasecmp(v->name, "buffers")) {
16245          if (parse_buffers_policy(v->value, &confp->chan.buf_no, &confp->chan.buf_policy)) {
16246             ast_log(LOG_WARNING, "Using default buffer policy.\n");
16247             confp->chan.buf_no = numbufs;
16248             confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE;
16249          }
16250       } else if (!strcasecmp(v->name, "faxbuffers")) {
16251          if (!parse_buffers_policy(v->value, &confp->chan.faxbuf_no, &confp->chan.faxbuf_policy)) {
16252             confp->chan.usefaxbuffers = 1;
16253          }
16254       } else if (!strcasecmp(v->name, "dahdichan")) {
16255          ast_copy_string(dahdichan, v->value, sizeof(dahdichan));
16256       } else if (!strcasecmp(v->name, "usedistinctiveringdetection")) {
16257          usedistinctiveringdetection = ast_true(v->value);
16258       } else if (!strcasecmp(v->name, "distinctiveringaftercid")) {
16259          distinctiveringaftercid = ast_true(v->value);
16260       } else if (!strcasecmp(v->name, "dring1context")) {
16261          ast_copy_string(confp->chan.drings.ringContext[0].contextData,v->value,sizeof(confp->chan.drings.ringContext[0].contextData));
16262       } else if (!strcasecmp(v->name, "dring2context")) {
16263          ast_copy_string(confp->chan.drings.ringContext[1].contextData,v->value,sizeof(confp->chan.drings.ringContext[1].contextData));
16264       } else if (!strcasecmp(v->name, "dring3context")) {
16265          ast_copy_string(confp->chan.drings.ringContext[2].contextData,v->value,sizeof(confp->chan.drings.ringContext[2].contextData));
16266       } else if (!strcasecmp(v->name, "dring1range")) {
16267          confp->chan.drings.ringnum[0].range = atoi(v->value);
16268       } else if (!strcasecmp(v->name, "dring2range")) {
16269          confp->chan.drings.ringnum[1].range = atoi(v->value);
16270       } else if (!strcasecmp(v->name, "dring3range")) {
16271          confp->chan.drings.ringnum[2].range = atoi(v->value);
16272       } else if (!strcasecmp(v->name, "dring1")) {
16273          sscanf(v->value, "%30d,%30d,%30d", &confp->chan.drings.ringnum[0].ring[0], &confp->chan.drings.ringnum[0].ring[1], &confp->chan.drings.ringnum[0].ring[2]);
16274       } else if (!strcasecmp(v->name, "dring2")) {
16275          sscanf(v->value, "%30d,%30d,%30d", &confp->chan.drings.ringnum[1].ring[0], &confp->chan.drings.ringnum[1].ring[1], &confp->chan.drings.ringnum[1].ring[2]);
16276       } else if (!strcasecmp(v->name, "dring3")) {
16277          sscanf(v->value, "%30d,%30d,%30d", &confp->chan.drings.ringnum[2].ring[0], &confp->chan.drings.ringnum[2].ring[1], &confp->chan.drings.ringnum[2].ring[2]);
16278       } else if (!strcasecmp(v->name, "usecallerid")) {
16279          confp->chan.use_callerid = ast_true(v->value);
16280       } else if (!strcasecmp(v->name, "cidsignalling")) {
16281          if (!strcasecmp(v->value, "bell"))
16282             confp->chan.cid_signalling = CID_SIG_BELL;
16283          else if (!strcasecmp(v->value, "v23"))
16284             confp->chan.cid_signalling = CID_SIG_V23;
16285          else if (!strcasecmp(v->value, "dtmf"))
16286             confp->chan.cid_signalling = CID_SIG_DTMF;
16287          else if (!strcasecmp(v->value, "smdi"))
16288             confp->chan.cid_signalling = CID_SIG_SMDI;
16289          else if (!strcasecmp(v->value, "v23_jp"))
16290             confp->chan.cid_signalling = CID_SIG_V23_JP;
16291          else if (ast_true(v->value))
16292             confp->chan.cid_signalling = CID_SIG_BELL;
16293       } else if (!strcasecmp(v->name, "cidstart")) {
16294          if (!strcasecmp(v->value, "ring"))
16295             confp->chan.cid_start = CID_START_RING;
16296          else if (!strcasecmp(v->value, "polarity_in"))
16297             confp->chan.cid_start = CID_START_POLARITY_IN;
16298          else if (!strcasecmp(v->value, "polarity"))
16299             confp->chan.cid_start = CID_START_POLARITY;
16300          else if (ast_true(v->value))
16301             confp->chan.cid_start = CID_START_RING;
16302       } else if (!strcasecmp(v->name, "threewaycalling")) {
16303          confp->chan.threewaycalling = ast_true(v->value);
16304       } else if (!strcasecmp(v->name, "cancallforward")) {
16305          confp->chan.cancallforward = ast_true(v->value);
16306       } else if (!strcasecmp(v->name, "relaxdtmf")) {
16307          if (ast_true(v->value))
16308             confp->chan.dtmfrelax = DSP_DIGITMODE_RELAXDTMF;
16309          else
16310             confp->chan.dtmfrelax = 0;
16311       } else if (!strcasecmp(v->name, "mailbox")) {
16312          ast_copy_string(confp->chan.mailbox, v->value, sizeof(confp->chan.mailbox));
16313       } else if (!strcasecmp(v->name, "hasvoicemail")) {
16314          if (ast_true(v->value) && ast_strlen_zero(confp->chan.mailbox)) {
16315             ast_copy_string(confp->chan.mailbox, cat, sizeof(confp->chan.mailbox));
16316          }
16317       } else if (!strcasecmp(v->name, "adsi")) {
16318          confp->chan.adsi = ast_true(v->value);
16319       } else if (!strcasecmp(v->name, "usesmdi")) {
16320          confp->chan.use_smdi = ast_true(v->value);
16321       } else if (!strcasecmp(v->name, "smdiport")) {
16322          ast_copy_string(confp->smdi_port, v->value, sizeof(confp->smdi_port));
16323       } else if (!strcasecmp(v->name, "transfer")) {
16324          confp->chan.transfer = ast_true(v->value);
16325       } else if (!strcasecmp(v->name, "canpark")) {
16326          confp->chan.canpark = ast_true(v->value);
16327       } else if (!strcasecmp(v->name, "echocancelwhenbridged")) {
16328          confp->chan.echocanbridged = ast_true(v->value);
16329       } else if (!strcasecmp(v->name, "busydetect")) {
16330          confp->chan.busydetect = ast_true(v->value);
16331       } else if (!strcasecmp(v->name, "busycount")) {
16332          confp->chan.busycount = atoi(v->value);
16333       } else if (!strcasecmp(v->name, "busypattern")) {
16334          if (sscanf(v->value, "%30d,%30d", &confp->chan.busy_tonelength, &confp->chan.busy_quietlength) != 2) {
16335             ast_log(LOG_ERROR, "busypattern= expects busypattern=tonelength,quietlength at line %d.\n", v->lineno);
16336          }
16337       } else if (!strcasecmp(v->name, "callprogress")) {
16338          confp->chan.callprogress &= ~CALLPROGRESS_PROGRESS;
16339          if (ast_true(v->value))
16340             confp->chan.callprogress |= CALLPROGRESS_PROGRESS;
16341       } else if (!strcasecmp(v->name, "waitfordialtone")) {
16342          confp->chan.waitfordialtone = atoi(v->value);
16343       } else if (!strcasecmp(v->name, "faxdetect")) {
16344          confp->chan.callprogress &= ~CALLPROGRESS_FAX;
16345          if (!strcasecmp(v->value, "incoming")) {
16346             confp->chan.callprogress |= CALLPROGRESS_FAX_INCOMING;
16347          } else if (!strcasecmp(v->value, "outgoing")) {
16348             confp->chan.callprogress |= CALLPROGRESS_FAX_OUTGOING;
16349          } else if (!strcasecmp(v->value, "both") || ast_true(v->value))
16350             confp->chan.callprogress |= CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING;
16351       } else if (!strcasecmp(v->name, "echocancel")) {
16352          process_echocancel(confp, v->value, v->lineno);
16353       } else if (!strcasecmp(v->name, "echotraining")) {
16354          if (sscanf(v->value, "%30d", &y) == 1) {
16355             if ((y < 10) || (y > 4000)) {
16356                ast_log(LOG_WARNING, "Echo training time must be within the range of 10 to 4000 ms at line %d.\n", v->lineno);
16357             } else {
16358                confp->chan.echotraining = y;
16359             }
16360          } else if (ast_true(v->value)) {
16361             confp->chan.echotraining = 400;
16362          } else
16363             confp->chan.echotraining = 0;
16364       } else if (!strcasecmp(v->name, "hidecallerid")) {
16365          confp->chan.hidecallerid = ast_true(v->value);
16366       } else if (!strcasecmp(v->name, "hidecalleridname")) {
16367          confp->chan.hidecalleridname = ast_true(v->value);
16368       } else if (!strcasecmp(v->name, "pulsedial")) {
16369          confp->chan.pulse = ast_true(v->value);
16370       } else if (!strcasecmp(v->name, "callreturn")) {
16371          confp->chan.callreturn = ast_true(v->value);
16372       } else if (!strcasecmp(v->name, "callwaiting")) {
16373          confp->chan.callwaiting = ast_true(v->value);
16374       } else if (!strcasecmp(v->name, "callwaitingcallerid")) {
16375          confp->chan.callwaitingcallerid = ast_true(v->value);
16376       } else if (!strcasecmp(v->name, "context")) {
16377          ast_copy_string(confp->chan.context, v->value, sizeof(confp->chan.context));
16378       } else if (!strcasecmp(v->name, "language")) {
16379          ast_copy_string(confp->chan.language, v->value, sizeof(confp->chan.language));
16380       } else if (!strcasecmp(v->name, "progzone")) {
16381          ast_copy_string(progzone, v->value, sizeof(progzone));
16382       } else if (!strcasecmp(v->name, "mohinterpret")
16383          ||!strcasecmp(v->name, "musiconhold") || !strcasecmp(v->name, "musicclass")) {
16384          ast_copy_string(confp->chan.mohinterpret, v->value, sizeof(confp->chan.mohinterpret));
16385       } else if (!strcasecmp(v->name, "mohsuggest")) {
16386          ast_copy_string(confp->chan.mohsuggest, v->value, sizeof(confp->chan.mohsuggest));
16387       } else if (!strcasecmp(v->name, "parkinglot")) {
16388          ast_copy_string(parkinglot, v->value, sizeof(parkinglot));
16389       } else if (!strcasecmp(v->name, "stripmsd")) {
16390          ast_log(LOG_NOTICE, "Configuration option \"%s\" has been deprecated. Please use dialplan instead\n", v->name);
16391          confp->chan.stripmsd = atoi(v->value);
16392       } else if (!strcasecmp(v->name, "jitterbuffers")) {
16393          numbufs = atoi(v->value);
16394       } else if (!strcasecmp(v->name, "group")) {
16395          confp->chan.group = ast_get_group(v->value);
16396       } else if (!strcasecmp(v->name, "callgroup")) {
16397          if (!strcasecmp(v->value, "none"))
16398             confp->chan.callgroup = 0;
16399          else
16400             confp->chan.callgroup = ast_get_group(v->value);
16401       } else if (!strcasecmp(v->name, "pickupgroup")) {
16402          if (!strcasecmp(v->value, "none"))
16403             confp->chan.pickupgroup = 0;
16404          else
16405             confp->chan.pickupgroup = ast_get_group(v->value);
16406       } else if (!strcasecmp(v->name, "setvar")) {
16407          char *varname = ast_strdupa(v->value), *varval = NULL;
16408          struct ast_variable *tmpvar;
16409          if (varname && (varval = strchr(varname, '='))) {
16410             *varval++ = '\0';
16411             if ((tmpvar = ast_variable_new(varname, varval, ""))) {
16412                tmpvar->next = confp->chan.vars;
16413                confp->chan.vars = tmpvar;
16414             }
16415          }
16416       } else if (!strcasecmp(v->name, "immediate")) {
16417          confp->chan.immediate = ast_true(v->value);
16418       } else if (!strcasecmp(v->name, "transfertobusy")) {
16419          confp->chan.transfertobusy = ast_true(v->value);
16420       } else if (!strcasecmp(v->name, "mwimonitor")) {
16421          confp->chan.mwimonitor_neon = 0;
16422          confp->chan.mwimonitor_fsk = 0;
16423          confp->chan.mwimonitor_rpas = 0;
16424          if (strcasestr(v->value, "fsk")) {
16425             confp->chan.mwimonitor_fsk = 1;
16426          }
16427          if (strcasestr(v->value, "rpas")) {
16428             confp->chan.mwimonitor_rpas = 1;
16429          }
16430          if (strcasestr(v->value, "neon")) {
16431             confp->chan.mwimonitor_neon = 1;
16432          }
16433          /* If set to true or yes, assume that simple fsk is desired */
16434          if (ast_true(v->value)) {
16435             confp->chan.mwimonitor_fsk = 1;
16436          }
16437       } else if (!strcasecmp(v->name, "cid_rxgain")) {
16438          if (sscanf(v->value, "%30f", &confp->chan.cid_rxgain) != 1) {
16439             ast_log(LOG_WARNING, "Invalid cid_rxgain: %s at line %d.\n", v->value, v->lineno);
16440          }
16441       } else if (!strcasecmp(v->name, "rxgain")) {
16442          if (sscanf(v->value, "%30f", &confp->chan.rxgain) != 1) {
16443             ast_log(LOG_WARNING, "Invalid rxgain: %s at line %d.\n", v->value, v->lineno);
16444          }
16445       } else if (!strcasecmp(v->name, "txgain")) {
16446          if (sscanf(v->value, "%30f", &confp->chan.txgain) != 1) {
16447             ast_log(LOG_WARNING, "Invalid txgain: %s at line %d.\n", v->value, v->lineno);
16448          }
16449       } else if (!strcasecmp(v->name, "tonezone")) {
16450          if (sscanf(v->value, "%30d", &confp->chan.tonezone) != 1) {
16451             ast_log(LOG_WARNING, "Invalid tonezone: %s at line %d.\n", v->value, v->lineno);
16452          }
16453       } else if (!strcasecmp(v->name, "callerid")) {
16454          if (!strcasecmp(v->value, "asreceived")) {
16455             confp->chan.cid_num[0] = '\0';
16456             confp->chan.cid_name[0] = '\0';
16457          } else {
16458             ast_callerid_split(v->value, confp->chan.cid_name, sizeof(confp->chan.cid_name), confp->chan.cid_num, sizeof(confp->chan.cid_num));
16459          }
16460       } else if (!strcasecmp(v->name, "fullname")) {
16461          ast_copy_string(confp->chan.cid_name, v->value, sizeof(confp->chan.cid_name));
16462       } else if (!strcasecmp(v->name, "cid_number")) {
16463          ast_copy_string(confp->chan.cid_num, v->value, sizeof(confp->chan.cid_num));
16464       } else if (!strcasecmp(v->name, "useincomingcalleridondahditransfer")) {
16465          confp->chan.dahditrcallerid = ast_true(v->value);
16466       } else if (!strcasecmp(v->name, "restrictcid")) {
16467          confp->chan.restrictcid = ast_true(v->value);
16468       } else if (!strcasecmp(v->name, "usecallingpres")) {
16469          confp->chan.use_callingpres = ast_true(v->value);
16470       } else if (!strcasecmp(v->name, "accountcode")) {
16471          ast_copy_string(confp->chan.accountcode, v->value, sizeof(confp->chan.accountcode));
16472       } else if (!strcasecmp(v->name, "amaflags")) {
16473          y = ast_cdr_amaflags2int(v->value);
16474          if (y < 0)
16475             ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d.\n", v->value, v->lineno);
16476          else
16477             confp->chan.amaflags = y;
16478       } else if (!strcasecmp(v->name, "polarityonanswerdelay")) {
16479          confp->chan.polarityonanswerdelay = atoi(v->value);
16480       } else if (!strcasecmp(v->name, "answeronpolarityswitch")) {
16481          confp->chan.answeronpolarityswitch = ast_true(v->value);
16482       } else if (!strcasecmp(v->name, "hanguponpolarityswitch")) {
16483          confp->chan.hanguponpolarityswitch = ast_true(v->value);
16484       } else if (!strcasecmp(v->name, "sendcalleridafter")) {
16485          confp->chan.sendcalleridafter = atoi(v->value);
16486       } else if (!strcasecmp(v->name, "mwimonitornotify")) {
16487          ast_copy_string(mwimonitornotify, v->value, sizeof(mwimonitornotify));
16488       } else if (!strcasecmp(v->name, "mwisendtype")) {
16489 #ifndef HAVE_DAHDI_LINEREVERSE_VMWI  /* backward compatibility for older dahdi VMWI implementation */
16490          if (!strcasecmp(v->value, "rpas")) { /* Ring Pulse Alert Signal */
16491             mwisend_rpas = 1;
16492          } else {
16493             mwisend_rpas = 0;
16494          }
16495 #else
16496          /* Default is fsk, to turn it off you must specify nofsk */
16497          memset(&confp->chan.mwisend_setting, 0, sizeof(confp->chan.mwisend_setting));
16498          if (strcasestr(v->value, "nofsk")) {      /* NoFSK */
16499             confp->chan.mwisend_fsk = 0;
16500          } else {             /* Default FSK */
16501             confp->chan.mwisend_fsk = 1;
16502          }
16503          if (strcasestr(v->value, "rpas")) {       /* Ring Pulse Alert Signal, normally followed by FSK */
16504             confp->chan.mwisend_rpas = 1;
16505          } else {
16506             confp->chan.mwisend_rpas = 0;
16507          }
16508          if (strcasestr(v->value, "lrev")) {       /* Line Reversal */
16509             confp->chan.mwisend_setting.vmwi_type |= DAHDI_VMWI_LREV;
16510          }
16511          if (strcasestr(v->value, "hvdc")) {       /* HV 90VDC */
16512             confp->chan.mwisend_setting.vmwi_type |= DAHDI_VMWI_HVDC;
16513          }
16514          if ( (strcasestr(v->value, "neon")) || (strcasestr(v->value, "hvac")) ){   /* 90V DC pulses */
16515             confp->chan.mwisend_setting.vmwi_type |= DAHDI_VMWI_HVAC;
16516          }
16517 #endif
16518       } else if (reload != 1) {
16519           if (!strcasecmp(v->name, "signalling") || !strcasecmp(v->name, "signaling")) {
16520             int orig_radio = confp->chan.radio;
16521             int orig_outsigmod = confp->chan.outsigmod;
16522             int orig_auto = confp->is_sig_auto;
16523 
16524             confp->chan.radio = 0;
16525             confp->chan.outsigmod = -1;
16526             confp->is_sig_auto = 0;
16527             if (!strcasecmp(v->value, "em")) {
16528                confp->chan.sig = SIG_EM;
16529             } else if (!strcasecmp(v->value, "em_e1")) {
16530                confp->chan.sig = SIG_EM_E1;
16531             } else if (!strcasecmp(v->value, "em_w")) {
16532                confp->chan.sig = SIG_EMWINK;
16533             } else if (!strcasecmp(v->value, "fxs_ls")) {
16534                confp->chan.sig = SIG_FXSLS;
16535             } else if (!strcasecmp(v->value, "fxs_gs")) {
16536                confp->chan.sig = SIG_FXSGS;
16537             } else if (!strcasecmp(v->value, "fxs_ks")) {
16538                confp->chan.sig = SIG_FXSKS;
16539             } else if (!strcasecmp(v->value, "fxo_ls")) {
16540                confp->chan.sig = SIG_FXOLS;
16541             } else if (!strcasecmp(v->value, "fxo_gs")) {
16542                confp->chan.sig = SIG_FXOGS;
16543             } else if (!strcasecmp(v->value, "fxo_ks")) {
16544                confp->chan.sig = SIG_FXOKS;
16545             } else if (!strcasecmp(v->value, "fxs_rx")) {
16546                confp->chan.sig = SIG_FXSKS;
16547                confp->chan.radio = 1;
16548             } else if (!strcasecmp(v->value, "fxo_rx")) {
16549                confp->chan.sig = SIG_FXOLS;
16550                confp->chan.radio = 1;
16551             } else if (!strcasecmp(v->value, "fxs_tx")) {
16552                confp->chan.sig = SIG_FXSLS;
16553                confp->chan.radio = 1;
16554             } else if (!strcasecmp(v->value, "fxo_tx")) {
16555                confp->chan.sig = SIG_FXOGS;
16556                confp->chan.radio = 1;
16557             } else if (!strcasecmp(v->value, "em_rx")) {
16558                confp->chan.sig = SIG_EM;
16559                confp->chan.radio = 1;
16560             } else if (!strcasecmp(v->value, "em_tx")) {
16561                confp->chan.sig = SIG_EM;
16562                confp->chan.radio = 1;
16563             } else if (!strcasecmp(v->value, "em_rxtx")) {
16564                confp->chan.sig = SIG_EM;
16565                confp->chan.radio = 2;
16566             } else if (!strcasecmp(v->value, "em_txrx")) {
16567                confp->chan.sig = SIG_EM;
16568                confp->chan.radio = 2;
16569             } else if (!strcasecmp(v->value, "sf")) {
16570                confp->chan.sig = SIG_SF;
16571             } else if (!strcasecmp(v->value, "sf_w")) {
16572                confp->chan.sig = SIG_SFWINK;
16573             } else if (!strcasecmp(v->value, "sf_featd")) {
16574                confp->chan.sig = SIG_FEATD;
16575             } else if (!strcasecmp(v->value, "sf_featdmf")) {
16576                confp->chan.sig = SIG_FEATDMF;
16577             } else if (!strcasecmp(v->value, "sf_featb")) {
16578                confp->chan.sig = SIG_SF_FEATB;
16579             } else if (!strcasecmp(v->value, "sf")) {
16580                confp->chan.sig = SIG_SF;
16581             } else if (!strcasecmp(v->value, "sf_rx")) {
16582                confp->chan.sig = SIG_SF;
16583                confp->chan.radio = 1;
16584             } else if (!strcasecmp(v->value, "sf_tx")) {
16585                confp->chan.sig = SIG_SF;
16586                confp->chan.radio = 1;
16587             } else if (!strcasecmp(v->value, "sf_rxtx")) {
16588                confp->chan.sig = SIG_SF;
16589                confp->chan.radio = 2;
16590             } else if (!strcasecmp(v->value, "sf_txrx")) {
16591                confp->chan.sig = SIG_SF;
16592                confp->chan.radio = 2;
16593             } else if (!strcasecmp(v->value, "featd")) {
16594                confp->chan.sig = SIG_FEATD;
16595             } else if (!strcasecmp(v->value, "featdmf")) {
16596                confp->chan.sig = SIG_FEATDMF;
16597             } else if (!strcasecmp(v->value, "featdmf_ta")) {
16598                confp->chan.sig = SIG_FEATDMF_TA;
16599             } else if (!strcasecmp(v->value, "e911")) {
16600                confp->chan.sig = SIG_E911;
16601             } else if (!strcasecmp(v->value, "fgccama")) {
16602                confp->chan.sig = SIG_FGC_CAMA;
16603             } else if (!strcasecmp(v->value, "fgccamamf")) {
16604                confp->chan.sig = SIG_FGC_CAMAMF;
16605             } else if (!strcasecmp(v->value, "featb")) {
16606                confp->chan.sig = SIG_FEATB;
16607 #ifdef HAVE_PRI
16608             } else if (!strcasecmp(v->value, "pri_net")) {
16609                confp->chan.sig = SIG_PRI;
16610                confp->pri.nodetype = PRI_NETWORK;
16611             } else if (!strcasecmp(v->value, "pri_cpe")) {
16612                confp->chan.sig = SIG_PRI;
16613                confp->pri.nodetype = PRI_CPE;
16614             } else if (!strcasecmp(v->value, "bri_cpe")) {
16615                confp->chan.sig = SIG_BRI;
16616                confp->pri.nodetype = PRI_CPE;
16617             } else if (!strcasecmp(v->value, "bri_net")) {
16618                confp->chan.sig = SIG_BRI;
16619                confp->pri.nodetype = PRI_NETWORK;
16620             } else if (!strcasecmp(v->value, "bri_cpe_ptmp")) {
16621                confp->chan.sig = SIG_BRI_PTMP;
16622                confp->pri.nodetype = PRI_CPE;
16623             } else if (!strcasecmp(v->value, "bri_net_ptmp")) {
16624                ast_log(LOG_WARNING, "How cool would it be if someone implemented this mode!  For now, sucks for you. (line %d)\n", v->lineno);
16625             } else if (!strcasecmp(v->value, "gr303fxoks_net")) {
16626                confp->chan.sig = SIG_GR303FXOKS;
16627                confp->pri.nodetype = PRI_NETWORK;
16628             } else if (!strcasecmp(v->value, "gr303fxsks_cpe")) {
16629                confp->chan.sig = SIG_GR303FXSKS;
16630                confp->pri.nodetype = PRI_CPE;
16631 #endif
16632 #ifdef HAVE_SS7
16633             } else if (!strcasecmp(v->value, "ss7")) {
16634                confp->chan.sig = SIG_SS7;
16635 #endif
16636 #ifdef HAVE_OPENR2
16637             } else if (!strcasecmp(v->value, "mfcr2")) {
16638                confp->chan.sig = SIG_MFCR2;
16639 #endif
16640             } else if (!strcasecmp(v->value, "auto")) {
16641                confp->is_sig_auto = 1;
16642             } else {
16643                confp->chan.outsigmod = orig_outsigmod;
16644                confp->chan.radio = orig_radio;
16645                confp->is_sig_auto = orig_auto;
16646                ast_log(LOG_ERROR, "Unknown signalling method '%s' at line %d.\n", v->value, v->lineno);
16647             }
16648           } else if (!strcasecmp(v->name, "outsignalling") || !strcasecmp(v->name, "outsignaling")) {
16649             if (!strcasecmp(v->value, "em")) {
16650                confp->chan.outsigmod = SIG_EM;
16651             } else if (!strcasecmp(v->value, "em_e1")) {
16652                confp->chan.outsigmod = SIG_EM_E1;
16653             } else if (!strcasecmp(v->value, "em_w")) {
16654                confp->chan.outsigmod = SIG_EMWINK;
16655             } else if (!strcasecmp(v->value, "sf")) {
16656                confp->chan.outsigmod = SIG_SF;
16657             } else if (!strcasecmp(v->value, "sf_w")) {
16658                confp->chan.outsigmod = SIG_SFWINK;
16659             } else if (!strcasecmp(v->value, "sf_featd")) {
16660                confp->chan.outsigmod = SIG_FEATD;
16661             } else if (!strcasecmp(v->value, "sf_featdmf")) {
16662                confp->chan.outsigmod = SIG_FEATDMF;
16663             } else if (!strcasecmp(v->value, "sf_featb")) {
16664                confp->chan.outsigmod = SIG_SF_FEATB;
16665             } else if (!strcasecmp(v->value, "sf")) {
16666                confp->chan.outsigmod = SIG_SF;
16667             } else if (!strcasecmp(v->value, "featd")) {
16668                confp->chan.outsigmod = SIG_FEATD;
16669             } else if (!strcasecmp(v->value, "featdmf")) {
16670                confp->chan.outsigmod = SIG_FEATDMF;
16671             } else if (!strcasecmp(v->value, "featdmf_ta")) {
16672                confp->chan.outsigmod = SIG_FEATDMF_TA;
16673             } else if (!strcasecmp(v->value, "e911")) {
16674                confp->chan.outsigmod = SIG_E911;
16675             } else if (!strcasecmp(v->value, "fgccama")) {
16676                confp->chan.outsigmod = SIG_FGC_CAMA;
16677             } else if (!strcasecmp(v->value, "fgccamamf")) {
16678                confp->chan.outsigmod = SIG_FGC_CAMAMF;
16679             } else if (!strcasecmp(v->value, "featb")) {
16680                confp->chan.outsigmod = SIG_FEATB;
16681             } else {
16682                ast_log(LOG_ERROR, "Unknown signalling method '%s' at line %d.\n", v->value, v->lineno);
16683             }
16684 #ifdef HAVE_PRI
16685          } else if (!strcasecmp(v->name, "pridialplan")) {
16686             if (!strcasecmp(v->value, "national")) {
16687                confp->pri.dialplan = PRI_NATIONAL_ISDN + 1;
16688             } else if (!strcasecmp(v->value, "unknown")) {
16689                confp->pri.dialplan = PRI_UNKNOWN + 1;
16690             } else if (!strcasecmp(v->value, "private")) {
16691                confp->pri.dialplan = PRI_PRIVATE + 1;
16692             } else if (!strcasecmp(v->value, "international")) {
16693                confp->pri.dialplan = PRI_INTERNATIONAL_ISDN + 1;
16694             } else if (!strcasecmp(v->value, "local")) {
16695                confp->pri.dialplan = PRI_LOCAL_ISDN + 1;
16696             } else if (!strcasecmp(v->value, "dynamic")) {
16697                confp->pri.dialplan = -1;
16698             } else if (!strcasecmp(v->value, "redundant")) {
16699                confp->pri.dialplan = -2;
16700             } else {
16701                ast_log(LOG_WARNING, "Unknown PRI dialplan '%s' at line %d.\n", v->value, v->lineno);
16702             }
16703          } else if (!strcasecmp(v->name, "prilocaldialplan")) {
16704             if (!strcasecmp(v->value, "national")) {
16705                confp->pri.localdialplan = PRI_NATIONAL_ISDN + 1;
16706             } else if (!strcasecmp(v->value, "unknown")) {
16707                confp->pri.localdialplan = PRI_UNKNOWN + 1;
16708             } else if (!strcasecmp(v->value, "private")) {
16709                confp->pri.localdialplan = PRI_PRIVATE + 1;
16710             } else if (!strcasecmp(v->value, "international")) {
16711                confp->pri.localdialplan = PRI_INTERNATIONAL_ISDN + 1;
16712             } else if (!strcasecmp(v->value, "local")) {
16713                confp->pri.localdialplan = PRI_LOCAL_ISDN + 1;
16714             } else if (!strcasecmp(v->value, "dynamic")) {
16715                confp->pri.localdialplan = -1;
16716             } else if (!strcasecmp(v->value, "redundant")) {
16717                confp->pri.localdialplan = -2;
16718             } else {
16719                ast_log(LOG_WARNING, "Unknown PRI localdialplan '%s' at line %d.\n", v->value, v->lineno);
16720             }
16721          } else if (!strcasecmp(v->name, "switchtype")) {
16722             if (!strcasecmp(v->value, "national"))
16723                confp->pri.switchtype = PRI_SWITCH_NI2;
16724             else if (!strcasecmp(v->value, "ni1"))
16725                confp->pri.switchtype = PRI_SWITCH_NI1;
16726             else if (!strcasecmp(v->value, "dms100"))
16727                confp->pri.switchtype = PRI_SWITCH_DMS100;
16728             else if (!strcasecmp(v->value, "4ess"))
16729                confp->pri.switchtype = PRI_SWITCH_ATT4ESS;
16730             else if (!strcasecmp(v->value, "5ess"))
16731                confp->pri.switchtype = PRI_SWITCH_LUCENT5E;
16732             else if (!strcasecmp(v->value, "euroisdn"))
16733                confp->pri.switchtype = PRI_SWITCH_EUROISDN_E1;
16734             else if (!strcasecmp(v->value, "qsig"))
16735                confp->pri.switchtype = PRI_SWITCH_QSIG;
16736             else {
16737                ast_log(LOG_ERROR, "Unknown switchtype '%s' at line %d.\n", v->value, v->lineno);
16738                return -1;
16739             }
16740          } else if (!strcasecmp(v->name, "nsf")) {
16741             if (!strcasecmp(v->value, "sdn"))
16742                confp->pri.nsf = PRI_NSF_SDN;
16743             else if (!strcasecmp(v->value, "megacom"))
16744                confp->pri.nsf = PRI_NSF_MEGACOM;
16745             else if (!strcasecmp(v->value, "tollfreemegacom"))
16746                confp->pri.nsf = PRI_NSF_TOLL_FREE_MEGACOM;
16747             else if (!strcasecmp(v->value, "accunet"))
16748                confp->pri.nsf = PRI_NSF_ACCUNET;
16749             else if (!strcasecmp(v->value, "none"))
16750                confp->pri.nsf = PRI_NSF_NONE;
16751             else {
16752                ast_log(LOG_WARNING, "Unknown network-specific facility '%s' at line %d.\n", v->value, v->lineno);
16753                confp->pri.nsf = PRI_NSF_NONE;
16754             }
16755          } else if (!strcasecmp(v->name, "priindication")) {
16756             if (!strcasecmp(v->value, "outofband"))
16757                confp->chan.priindication_oob = 1;
16758             else if (!strcasecmp(v->value, "inband"))
16759                confp->chan.priindication_oob = 0;
16760             else
16761                ast_log(LOG_WARNING, "'%s' is not a valid pri indication value, should be 'inband' or 'outofband' at line %d.\n",
16762                   v->value, v->lineno);
16763          } else if (!strcasecmp(v->name, "priexclusive")) {
16764             confp->chan.priexclusive = ast_true(v->value);
16765          } else if (!strcasecmp(v->name, "internationalprefix")) {
16766             ast_copy_string(confp->pri.internationalprefix, v->value, sizeof(confp->pri.internationalprefix));
16767          } else if (!strcasecmp(v->name, "nationalprefix")) {
16768             ast_copy_string(confp->pri.nationalprefix, v->value, sizeof(confp->pri.nationalprefix));
16769          } else if (!strcasecmp(v->name, "localprefix")) {
16770             ast_copy_string(confp->pri.localprefix, v->value, sizeof(confp->pri.localprefix));
16771          } else if (!strcasecmp(v->name, "privateprefix")) {
16772             ast_copy_string(confp->pri.privateprefix, v->value, sizeof(confp->pri.privateprefix));
16773          } else if (!strcasecmp(v->name, "unknownprefix")) {
16774             ast_copy_string(confp->pri.unknownprefix, v->value, sizeof(confp->pri.unknownprefix));
16775          } else if (!strcasecmp(v->name, "resetinterval")) {
16776             if (!strcasecmp(v->value, "never"))
16777                confp->pri.resetinterval = -1;
16778             else if (atoi(v->value) >= 60)
16779                confp->pri.resetinterval = atoi(v->value);
16780             else
16781                ast_log(LOG_WARNING, "'%s' is not a valid reset interval, should be >= 60 seconds or 'never' at line %d.\n",
16782                   v->value, v->lineno);
16783          } else if (!strcasecmp(v->name, "minunused")) {
16784             confp->pri.minunused = atoi(v->value);
16785          } else if (!strcasecmp(v->name, "minidle")) {
16786             confp->pri.minidle = atoi(v->value);
16787          } else if (!strcasecmp(v->name, "idleext")) {
16788             ast_copy_string(confp->pri.idleext, v->value, sizeof(confp->pri.idleext));
16789          } else if (!strcasecmp(v->name, "idledial")) {
16790             ast_copy_string(confp->pri.idledial, v->value, sizeof(confp->pri.idledial));
16791          } else if (!strcasecmp(v->name, "overlapdial")) {
16792             if (ast_true(v->value)) {
16793                confp->pri.overlapdial = DAHDI_OVERLAPDIAL_BOTH;
16794             } else if (!strcasecmp(v->value, "incoming")) {
16795                confp->pri.overlapdial = DAHDI_OVERLAPDIAL_INCOMING;
16796             } else if (!strcasecmp(v->value, "outgoing")) {
16797                confp->pri.overlapdial = DAHDI_OVERLAPDIAL_OUTGOING;
16798             } else if (!strcasecmp(v->value, "both") || ast_true(v->value)) {
16799                confp->pri.overlapdial = DAHDI_OVERLAPDIAL_BOTH;
16800             } else {
16801                confp->pri.overlapdial = DAHDI_OVERLAPDIAL_NONE;
16802             }
16803 #ifdef HAVE_PRI_PROG_W_CAUSE
16804          } else if (!strcasecmp(v->name, "qsigchannelmapping")) {
16805             if (!strcasecmp(v->value, "logical")) {
16806                confp->pri.qsigchannelmapping = DAHDI_CHAN_MAPPING_LOGICAL;
16807             } else if (!strcasecmp(v->value, "physical")) {
16808                confp->pri.qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL;
16809             } else {
16810                confp->pri.qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL;
16811             }
16812 #endif
16813          } else if (!strcasecmp(v->name, "discardremoteholdretrieval")) {
16814             confp->pri.discardremoteholdretrieval = ast_true(v->value);
16815 #ifdef HAVE_PRI_INBANDDISCONNECT
16816          } else if (!strcasecmp(v->name, "inbanddisconnect")) {
16817             confp->pri.inbanddisconnect = ast_true(v->value);
16818 #endif
16819          } else if (!strcasecmp(v->name, "pritimer")) {
16820 #ifdef PRI_GETSET_TIMERS
16821             char tmp[20];
16822             char *timerc;
16823             char *c;
16824             int timer;
16825             int timeridx;
16826 
16827             ast_copy_string(tmp, v->value, sizeof(tmp));
16828             c = tmp;
16829             timerc = strsep(&c, ",");
16830             if (!ast_strlen_zero(timerc) && !ast_strlen_zero(c)) {
16831                timeridx = pri_timer2idx(timerc);
16832                timer = atoi(c);
16833                if (timeridx < 0 || PRI_MAX_TIMERS <= timeridx) {
16834                   ast_log(LOG_WARNING,
16835                      "'%s' is not a valid ISDN timer at line %d.\n", timerc,
16836                      v->lineno);
16837                } else if (!timer) {
16838                   ast_log(LOG_WARNING,
16839                      "'%s' is not a valid value for ISDN timer '%s' at line %d.\n",
16840                      c, timerc, v->lineno);
16841                } else {
16842                   pritimers[timeridx] = timer;
16843                }
16844             } else {
16845                ast_log(LOG_WARNING,
16846                   "'%s' is not a valid ISDN timer configuration string at line %d.\n",
16847                   v->value, v->lineno);
16848             }
16849 
16850          } else if (!strcasecmp(v->name, "facilityenable")) {
16851             confp->pri.facilityenable = ast_true(v->value);
16852 #endif /* PRI_GETSET_TIMERS */
16853 #endif /* HAVE_PRI */
16854 #ifdef HAVE_SS7
16855          } else if (!strcasecmp(v->name, "ss7type")) {
16856             if (!strcasecmp(v->value, "itu")) {
16857                cur_ss7type = SS7_ITU;
16858             } else if (!strcasecmp(v->value, "ansi")) {
16859                cur_ss7type = SS7_ANSI;
16860             } else
16861                ast_log(LOG_WARNING, "'%s' is an unknown ss7 switch type at line %d.!\n", v->value, v->lineno);
16862          } else if (!strcasecmp(v->name, "linkset")) {
16863             cur_linkset = atoi(v->value);
16864          } else if (!strcasecmp(v->name, "pointcode")) {
16865             cur_pointcode = parse_pointcode(v->value);
16866          } else if (!strcasecmp(v->name, "adjpointcode")) {
16867             cur_adjpointcode = parse_pointcode(v->value);
16868          } else if (!strcasecmp(v->name, "defaultdpc")) {
16869             cur_defaultdpc = parse_pointcode(v->value);
16870          } else if (!strcasecmp(v->name, "cicbeginswith")) {
16871             cur_cicbeginswith = atoi(v->value);
16872          } else if (!strcasecmp(v->name, "networkindicator")) {
16873             if (!strcasecmp(v->value, "national"))
16874                cur_networkindicator = SS7_NI_NAT;
16875             else if (!strcasecmp(v->value, "national_spare"))
16876                cur_networkindicator = SS7_NI_NAT_SPARE;
16877             else if (!strcasecmp(v->value, "international"))
16878                cur_networkindicator = SS7_NI_INT;
16879             else if (!strcasecmp(v->value, "international_spare"))
16880                cur_networkindicator = SS7_NI_INT_SPARE;
16881             else
16882                cur_networkindicator = -1;
16883          } else if (!strcasecmp(v->name, "ss7_internationalprefix")) {
16884             ast_copy_string(confp->ss7.internationalprefix, v->value, sizeof(confp->ss7.internationalprefix));
16885          } else if (!strcasecmp(v->name, "ss7_nationalprefix")) {
16886             ast_copy_string(confp->ss7.nationalprefix, v->value, sizeof(confp->ss7.nationalprefix));
16887          } else if (!strcasecmp(v->name, "ss7_subscriberprefix")) {
16888             ast_copy_string(confp->ss7.subscriberprefix, v->value, sizeof(confp->ss7.subscriberprefix));
16889          } else if (!strcasecmp(v->name, "ss7_unknownprefix")) {
16890             ast_copy_string(confp->ss7.unknownprefix, v->value, sizeof(confp->ss7.unknownprefix));
16891          } else if (!strcasecmp(v->name, "ss7_called_nai")) {
16892             if (!strcasecmp(v->value, "national")) {
16893                confp->ss7.called_nai = SS7_NAI_NATIONAL;
16894             } else if (!strcasecmp(v->value, "international")) {
16895                confp->ss7.called_nai = SS7_NAI_INTERNATIONAL;
16896             } else if (!strcasecmp(v->value, "subscriber")) {
16897                confp->ss7.called_nai = SS7_NAI_SUBSCRIBER;
16898             } else if (!strcasecmp(v->value, "dynamic")) {
16899                confp->ss7.called_nai = SS7_NAI_DYNAMIC;
16900             } else {
16901                ast_log(LOG_WARNING, "Unknown SS7 called_nai '%s' at line %d.\n", v->value, v->lineno);
16902             }
16903          } else if (!strcasecmp(v->name, "ss7_calling_nai")) {
16904             if (!strcasecmp(v->value, "national")) {
16905                confp->ss7.calling_nai = SS7_NAI_NATIONAL;
16906             } else if (!strcasecmp(v->value, "international")) {
16907                confp->ss7.calling_nai = SS7_NAI_INTERNATIONAL;
16908             } else if (!strcasecmp(v->value, "subscriber")) {
16909                confp->ss7.calling_nai = SS7_NAI_SUBSCRIBER;
16910             } else if (!strcasecmp(v->value, "dynamic")) {
16911                confp->ss7.calling_nai = SS7_NAI_DYNAMIC;
16912             } else {
16913                ast_log(LOG_WARNING, "Unknown SS7 calling_nai '%s' at line %d.\n", v->value, v->lineno);
16914             }
16915          } else if (!strcasecmp(v->name, "sigchan")) {
16916             int sigchan, res;
16917             sigchan = atoi(v->value);
16918             res = linkset_addsigchan(sigchan);
16919             if (res < 0)
16920                return -1;
16921 
16922          } else if (!strcasecmp(v->name, "ss7_explicitacm")) {
16923             struct dahdi_ss7 *link;
16924             link = ss7_resolve_linkset(cur_linkset);
16925             if (!link) {
16926                ast_log(LOG_ERROR, "Invalid linkset number.  Must be between 1 and %d\n", NUM_SPANS + 1);
16927                return -1;
16928             }
16929             if (ast_true(v->value))
16930                link->flags |= LINKSET_FLAG_EXPLICITACM;
16931 #endif /* HAVE_SS7 */
16932 #ifdef HAVE_OPENR2
16933          } else if (!strcasecmp(v->name, "mfcr2_advanced_protocol_file")) {
16934             ast_copy_string(confp->mfcr2.r2proto_file, v->value, sizeof(confp->mfcr2.r2proto_file));
16935             ast_log(LOG_WARNING, "MFC/R2 Protocol file '%s' will be used, you only should use this if you *REALLY KNOW WHAT YOU ARE DOING*.\n", confp->mfcr2.r2proto_file);
16936          } else if (!strcasecmp(v->name, "mfcr2_logdir")) {
16937             ast_copy_string(confp->mfcr2.logdir, v->value, sizeof(confp->mfcr2.logdir));
16938          } else if (!strcasecmp(v->name, "mfcr2_variant")) {
16939             confp->mfcr2.variant = openr2_proto_get_variant(v->value);
16940             if (OR2_VAR_UNKNOWN == confp->mfcr2.variant) {
16941                ast_log(LOG_WARNING, "Unknown MFC/R2 variant '%s' at line %d, defaulting to ITU.\n", v->value, v->lineno);
16942                confp->mfcr2.variant = OR2_VAR_ITU;
16943             }
16944          } else if (!strcasecmp(v->name, "mfcr2_mfback_timeout")) {
16945             confp->mfcr2.mfback_timeout = atoi(v->value);
16946             if (!confp->mfcr2.mfback_timeout) {
16947                ast_log(LOG_WARNING, "MF timeout of 0? hum, I will protect you from your ignorance. Setting default.\n");
16948                confp->mfcr2.mfback_timeout = -1;
16949             } else if (confp->mfcr2.mfback_timeout > 0 && confp->mfcr2.mfback_timeout < 500) {
16950                ast_log(LOG_WARNING, "MF timeout less than 500ms is not recommended, you have been warned!\n");
16951             }
16952          } else if (!strcasecmp(v->name, "mfcr2_metering_pulse_timeout")) {
16953             confp->mfcr2.metering_pulse_timeout = atoi(v->value);
16954             if (confp->mfcr2.metering_pulse_timeout > 500) {
16955                ast_log(LOG_WARNING, "Metering pulse timeout greater than 500ms is not recommended, you have been warned!\n");
16956             }
16957          } else if (!strcasecmp(v->name, "mfcr2_get_ani_first")) {
16958             confp->mfcr2.get_ani_first = ast_true(v->value) ? 1 : 0;
16959          } else if (!strcasecmp(v->name, "mfcr2_double_answer")) {
16960             confp->mfcr2.double_answer = ast_true(v->value) ? 1 : 0;
16961          } else if (!strcasecmp(v->name, "mfcr2_charge_calls")) {
16962             confp->mfcr2.charge_calls = ast_true(v->value) ? 1 : 0;
16963          } else if (!strcasecmp(v->name, "mfcr2_accept_on_offer")) {
16964             confp->mfcr2.accept_on_offer = ast_true(v->value) ? 1 : 0;
16965          } else if (!strcasecmp(v->name, "mfcr2_allow_collect_calls")) {
16966             confp->mfcr2.allow_collect_calls = ast_true(v->value) ? 1 : 0;
16967          } else if (!strcasecmp(v->name, "mfcr2_forced_release")) {
16968             confp->mfcr2.forced_release = ast_true(v->value) ? 1 : 0;
16969          } else if (!strcasecmp(v->name, "mfcr2_immediate_accept")) {
16970             confp->mfcr2.immediate_accept = ast_true(v->value) ? 1 : 0;
16971 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
16972          } else if (!strcasecmp(v->name, "mfcr2_skip_category")) {
16973             confp->mfcr2.skip_category_request = ast_true(v->value) ? 1 : 0;
16974 #endif
16975          } else if (!strcasecmp(v->name, "mfcr2_call_files")) {
16976             confp->mfcr2.call_files = ast_true(v->value) ? 1 : 0;
16977          } else if (!strcasecmp(v->name, "mfcr2_max_ani")) {
16978             confp->mfcr2.max_ani = atoi(v->value);
16979             if (confp->mfcr2.max_ani >= AST_MAX_EXTENSION){
16980                confp->mfcr2.max_ani = AST_MAX_EXTENSION - 1;
16981             }
16982          } else if (!strcasecmp(v->name, "mfcr2_max_dnis")) {
16983             confp->mfcr2.max_dnis = atoi(v->value);
16984             if (confp->mfcr2.max_dnis >= AST_MAX_EXTENSION){
16985                confp->mfcr2.max_dnis = AST_MAX_EXTENSION - 1;
16986             }
16987          } else if (!strcasecmp(v->name, "mfcr2_category")) {
16988             confp->mfcr2.category = openr2_proto_get_category(v->value);
16989             if (OR2_CALLING_PARTY_CATEGORY_UNKNOWN == confp->mfcr2.category) {
16990                confp->mfcr2.category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER;
16991                ast_log(LOG_WARNING, "Invalid MFC/R2 caller category '%s' at line %d. Using national subscriber as default.\n",
16992                      v->value, v->lineno);
16993             }
16994          } else if (!strcasecmp(v->name, "mfcr2_logging")) {
16995             openr2_log_level_t tmplevel;
16996             char *clevel;
16997             char *logval = ast_strdupa(v->value);
16998             while (logval) {
16999                clevel = strsep(&logval,",");
17000                if (-1 == (tmplevel = openr2_log_get_level(clevel))) {
17001                   ast_log(LOG_WARNING, "Ignoring invalid logging level: '%s' at line %d.\n", clevel, v->lineno);
17002                   continue;
17003                }
17004                confp->mfcr2.loglevel |= tmplevel;
17005             }
17006 #endif /* HAVE_OPENR2 */
17007          } else if (!strcasecmp(v->name, "cadence")) {
17008             /* setup to scan our argument */
17009             int element_count, c[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
17010             int i;
17011             struct dahdi_ring_cadence new_cadence;
17012             int cid_location = -1;
17013             int firstcadencepos = 0;
17014             char original_args[80];
17015             int cadence_is_ok = 1;
17016 
17017             ast_copy_string(original_args, v->value, sizeof(original_args));
17018             /* 16 cadences allowed (8 pairs) */
17019             element_count = sscanf(v->value, "%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d,%30d", &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12], &c[13], &c[14], &c[15]);
17020 
17021             /* Cadence must be even (on/off) */
17022             if (element_count % 2 == 1) {
17023                ast_log(LOG_ERROR, "Must be a silence duration for each ring duration: %s at line %d.\n", original_args, v->lineno);
17024                cadence_is_ok = 0;
17025             }
17026 
17027             /* Ring cadences cannot be negative */
17028             for (i = 0; i < element_count; i++) {
17029                if (c[i] == 0) {
17030                   ast_log(LOG_ERROR, "Ring or silence duration cannot be zero: %s at line %d.\n", original_args, v->lineno);
17031                   cadence_is_ok = 0;
17032                   break;
17033                } else if (c[i] < 0) {
17034                   if (i % 2 == 1) {
17035                      /* Silence duration, negative possibly okay */
17036                      if (cid_location == -1) {
17037                         cid_location = i;
17038                         c[i] *= -1;
17039                      } else {
17040                         ast_log(LOG_ERROR, "CID location specified twice: %s at line %d.\n", original_args, v->lineno);
17041                         cadence_is_ok = 0;
17042                         break;
17043                      }
17044                   } else {
17045                      if (firstcadencepos == 0) {
17046                         firstcadencepos = i; /* only recorded to avoid duplicate specification */
17047                                  /* duration will be passed negative to the DAHDI driver */
17048                      } else {
17049                          ast_log(LOG_ERROR, "First cadence position specified twice: %s at line %d.\n", original_args, v->lineno);
17050                         cadence_is_ok = 0;
17051                         break;
17052                      }
17053                   }
17054                }
17055             }
17056 
17057             /* Substitute our scanned cadence */
17058             for (i = 0; i < 16; i++) {
17059                new_cadence.ringcadence[i] = c[i];
17060             }
17061 
17062             if (cadence_is_ok) {
17063                /* ---we scanned it without getting annoyed; now some sanity checks--- */
17064                if (element_count < 2) {
17065                   ast_log(LOG_ERROR, "Minimum cadence is ring,pause: %s at line %d.\n", original_args, v->lineno);
17066                } else {
17067                   if (cid_location == -1) {
17068                      /* user didn't say; default to first pause */
17069                      cid_location = 1;
17070                   } else {
17071                      /* convert element_index to cidrings value */
17072                      cid_location = (cid_location + 1) / 2;
17073                   }
17074                   /* ---we like their cadence; try to install it--- */
17075                   if (!user_has_defined_cadences++)
17076                      /* this is the first user-defined cadence; clear the default user cadences */
17077                      num_cadence = 0;
17078                   if ((num_cadence+1) >= NUM_CADENCE_MAX)
17079                      ast_log(LOG_ERROR, "Already %d cadences; can't add another: %s at line %d.\n", NUM_CADENCE_MAX, original_args, v->lineno);
17080                   else {
17081                      cadences[num_cadence] = new_cadence;
17082                      cidrings[num_cadence++] = cid_location;
17083                      ast_verb(3, "cadence 'r%d' added: %s\n",num_cadence,original_args);
17084                   }
17085                }
17086             }
17087          } else if (!strcasecmp(v->name, "ringtimeout")) {
17088             ringt_base = (atoi(v->value) * 8) / READ_SIZE;
17089          } else if (!strcasecmp(v->name, "prewink")) {
17090             confp->timing.prewinktime = atoi(v->value);
17091          } else if (!strcasecmp(v->name, "preflash")) {
17092             confp->timing.preflashtime = atoi(v->value);
17093          } else if (!strcasecmp(v->name, "wink")) {
17094             confp->timing.winktime = atoi(v->value);
17095          } else if (!strcasecmp(v->name, "flash")) {
17096             confp->timing.flashtime = atoi(v->value);
17097          } else if (!strcasecmp(v->name, "start")) {
17098             confp->timing.starttime = atoi(v->value);
17099          } else if (!strcasecmp(v->name, "rxwink")) {
17100             confp->timing.rxwinktime = atoi(v->value);
17101          } else if (!strcasecmp(v->name, "rxflash")) {
17102             confp->timing.rxflashtime = atoi(v->value);
17103          } else if (!strcasecmp(v->name, "debounce")) {
17104             confp->timing.debouncetime = atoi(v->value);
17105          } else if (!strcasecmp(v->name, "toneduration")) {
17106             int toneduration;
17107             int ctlfd;
17108             int res;
17109             struct dahdi_dialparams dps;
17110 
17111             ctlfd = open("/dev/dahdi/ctl", O_RDWR);
17112             if (ctlfd == -1) {
17113                ast_log(LOG_ERROR, "Unable to open /dev/dahdi/ctl to set toneduration at line %d.\n", v->lineno);
17114                return -1;
17115             }
17116 
17117             toneduration = atoi(v->value);
17118             if (toneduration > -1) {
17119                memset(&dps, 0, sizeof(dps));
17120 
17121                dps.dtmf_tonelen = dps.mfv1_tonelen = toneduration;
17122                res = ioctl(ctlfd, DAHDI_SET_DIALPARAMS, &dps);
17123                if (res < 0) {
17124                   ast_log(LOG_ERROR, "Invalid tone duration: %d ms at line %d: %s\n", toneduration, v->lineno, strerror(errno));
17125                   close(ctlfd);
17126                   return -1;
17127                }
17128             }
17129             close(ctlfd);
17130          } else if (!strcasecmp(v->name, "defaultcic")) {
17131             ast_copy_string(defaultcic, v->value, sizeof(defaultcic));
17132          } else if (!strcasecmp(v->name, "defaultozz")) {
17133             ast_copy_string(defaultozz, v->value, sizeof(defaultozz));
17134          } else if (!strcasecmp(v->name, "mwilevel")) {
17135             mwilevel = atoi(v->value);
17136          }
17137       } else if (!(options & PROC_DAHDI_OPT_NOWARN) )
17138          ast_log(LOG_WARNING, "Ignoring any changes to '%s' (on reload) at line %d.\n", v->name, v->lineno);
17139    }
17140    if (dahdichan[0]) {
17141       /* The user has set 'dahdichan' */
17142       /*< \todo pass proper line number instead of 0 */
17143       if (build_channels(confp, 0, dahdichan, reload, 0, &found_pseudo)) {
17144          return -1;
17145       }
17146    }
17147    /*< \todo why check for the pseudo in the per-channel section.
17148     * Any actual use for manual setup of the pseudo channel? */
17149    if (!found_pseudo && reload != 1) {
17150       /* use the default configuration for a channel, so
17151          that any settings from real configured channels
17152          don't "leak" into the pseudo channel config
17153       */
17154       struct dahdi_chan_conf conf = dahdi_chan_conf_default();
17155 
17156       tmp = mkintf(CHAN_PSEUDO, &conf, NULL, reload);
17157 
17158       if (tmp) {
17159          ast_verb(3, "Automatically generated pseudo channel\n");
17160       } else {
17161          ast_log(LOG_WARNING, "Unable to register pseudo channel!\n");
17162       }
17163    }
17164    return 0;
17165 }

static void process_echocancel ( struct dahdi_chan_conf *  confp,
const char *  data,
unsigned int  line 
) [static]

Definition at line 16157 of file chan_dahdi.c.

References ARRAY_LEN, ast_app_separate_args, ast_log(), ast_strdupa, ast_strlen_zero(), ast_true(), dahdi_chan_conf::chan, dahdi_pvt::echocancel, dahdi_pvt::head, LOG_WARNING, name, and dahdi_pvt::params.

Referenced by process_dahdi().

16158 {
16159    char *parse = ast_strdupa(data);
16160    char *params[DAHDI_MAX_ECHOCANPARAMS + 1];
16161    unsigned int param_count;
16162    unsigned int x;
16163 
16164    if (!(param_count = ast_app_separate_args(parse, ',', params, ARRAY_LEN(params))))
16165       return;
16166 
16167    memset(&confp->chan.echocancel, 0, sizeof(confp->chan.echocancel));
16168 
16169    /* first parameter is tap length, process it here */
16170 
16171    x = ast_strlen_zero(params[0]) ? 0 : atoi(params[0]);
16172 
16173    if ((x == 32) || (x == 64) || (x == 128) || (x == 256) || (x == 512) || (x == 1024))
16174       confp->chan.echocancel.head.tap_length = x;
16175    else if ((confp->chan.echocancel.head.tap_length = ast_true(params[0])))
16176       confp->chan.echocancel.head.tap_length = 128;
16177 
16178    /* now process any remaining parameters */
16179 
16180    for (x = 1; x < param_count; x++) {
16181       struct {
16182          char *name;
16183          char *value;
16184       } param;
16185 
16186       if (ast_app_separate_args(params[x], '=', (char **) &param, 2) < 1) {
16187          ast_log(LOG_WARNING, "Invalid echocancel parameter supplied at line %d: '%s'\n", line, params[x]);
16188          continue;
16189       }
16190 
16191       if (ast_strlen_zero(param.name) || (strlen(param.name) > sizeof(confp->chan.echocancel.params[0].name)-1)) {
16192          ast_log(LOG_WARNING, "Invalid echocancel parameter supplied at line %d: '%s'\n", line, param.name);
16193          continue;
16194       }
16195 
16196       strcpy(confp->chan.echocancel.params[confp->chan.echocancel.head.param_count].name, param.name);
16197 
16198       if (param.value) {
16199          if (sscanf(param.value, "%30d", &confp->chan.echocancel.params[confp->chan.echocancel.head.param_count].value) != 1) {
16200             ast_log(LOG_WARNING, "Invalid echocancel parameter value supplied at line %d: '%s'\n", line, param.value);
16201             continue;
16202          }
16203       }
16204       confp->chan.echocancel.head.param_count++;
16205    }
16206 }

static char* redirectingreason2str ( int  redirectingreason  )  [static]

Definition at line 12460 of file chan_dahdi.c.

Referenced by pri_dchannel().

12461 {
12462    switch (redirectingreason) {
12463    case 0:
12464       return "UNKNOWN";
12465    case 1:
12466       return "BUSY";
12467    case 2:
12468       return "NO_REPLY";
12469    case 0xF:
12470       return "UNCONDITIONAL";
12471    default:
12472       return "NOREDIRECT";
12473    }
12474 }

static int reload ( void   )  [static]

Definition at line 17568 of file chan_dahdi.c.

References ast_log(), LOG_WARNING, and setup_dahdi().

17569 {
17570    int res = 0;
17571 
17572    res = setup_dahdi(1);
17573    if (res) {
17574       ast_log(LOG_WARNING, "Reload of chan_dahdi.so is unsuccessful!\n");
17575       return -1;
17576    }
17577    return 0;
17578 }

static int reset_conf ( struct dahdi_pvt *  p  )  [static]

Definition at line 2592 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::channel, dahdi_pvt::confno, dahdi_subchannel::curconf, dahdi_subchannel::dfd, errno, LOG_WARNING, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_hangup().

02593 {
02594    p->confno = -1;
02595    memset(&p->subs[SUB_REAL].curconf, 0, sizeof(p->subs[SUB_REAL].curconf));
02596    if (p->subs[SUB_REAL].dfd > -1) {
02597       struct dahdi_confinfo zi;
02598 
02599       memset(&zi, 0, sizeof(zi));
02600       if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &zi))
02601          ast_log(LOG_WARNING, "Failed to reset conferencing on channel %d: %s\n", p->channel, strerror(errno));
02602    }
02603    return 0;
02604 }

static int restart_monitor ( void   )  [static]

Definition at line 9809 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create_background, AST_PTHREADT_NULL, AST_PTHREADT_STOP, do_monitor(), LOG_ERROR, LOG_WARNING, and monlock.

Referenced by dahdi_hangup(), dahdi_request(), and setup_dahdi().

09810 {
09811    /* If we're supposed to be stopped -- stay stopped */
09812    if (monitor_thread == AST_PTHREADT_STOP)
09813       return 0;
09814    ast_mutex_lock(&monlock);
09815    if (monitor_thread == pthread_self()) {
09816       ast_mutex_unlock(&monlock);
09817       ast_log(LOG_WARNING, "Cannot kill myself\n");
09818       return -1;
09819    }
09820    if (monitor_thread != AST_PTHREADT_NULL) {
09821       /* Wake up the thread */
09822       pthread_kill(monitor_thread, SIGURG);
09823    } else {
09824       /* Start a new monitor */
09825       if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
09826          ast_mutex_unlock(&monlock);
09827          ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
09828          return -1;
09829       }
09830    }
09831    ast_mutex_unlock(&monlock);
09832    return 0;
09833 }

static int restore_conference ( struct dahdi_pvt *  p  )  [static]

Definition at line 2971 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_subchannel::dfd, errno, LOG_WARNING, dahdi_pvt::saveconf, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_handle_event(), dahdi_read(), and send_callerid().

02972 {
02973    int res;
02974    if (p->saveconf.confmode) {
02975       res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &p->saveconf);
02976       p->saveconf.confmode = 0;
02977       if (res) {
02978          ast_log(LOG_WARNING, "Unable to restore conference info: %s\n", strerror(errno));
02979          return -1;
02980       }
02981    }
02982    ast_debug(1, "Restored conferencing\n");
02983    return 0;
02984 }

static int restore_gains ( struct dahdi_pvt *  p  )  [static]

Definition at line 2852 of file chan_dahdi.c.

References ast_log(), dahdi_subchannel::dfd, errno, dahdi_pvt::law, LOG_WARNING, dahdi_pvt::rxgain, set_actual_gain(), SUB_REAL, dahdi_pvt::subs, and dahdi_pvt::txgain.

Referenced by dahdi_hangup(), mwi_thread(), and ss_thread().

02853 {
02854    int res;
02855 
02856    res = set_actual_gain(p->subs[SUB_REAL].dfd, 0, p->rxgain, p->txgain, p->law);
02857    if (res) {
02858       ast_log(LOG_WARNING, "Unable to restore gains: %s\n", strerror(errno));
02859       return -1;
02860    }
02861 
02862    return 0;
02863 }

static int save_conference ( struct dahdi_pvt *  p  )  [static]

Definition at line 2898 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_subchannel::dfd, errno, LOG_WARNING, dahdi_pvt::saveconf, SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_callwait(), and dahdi_handle_event().

02899 {
02900    struct dahdi_confinfo c;
02901    int res;
02902    if (p->saveconf.confmode) {
02903       ast_log(LOG_WARNING, "Can't save conference -- already in use\n");
02904       return -1;
02905    }
02906    p->saveconf.chan = 0;
02907    res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GETCONF, &p->saveconf);
02908    if (res) {
02909       ast_log(LOG_WARNING, "Unable to get conference info: %s\n", strerror(errno));
02910       p->saveconf.confmode = 0;
02911       return -1;
02912    }
02913    memset(&c, 0, sizeof(c));
02914    c.confmode = DAHDI_CONF_NORMAL;
02915    res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &c);
02916    if (res) {
02917       ast_log(LOG_WARNING, "Unable to set conference info: %s\n", strerror(errno));
02918       return -1;
02919    }
02920    ast_debug(1, "Disabled conferencing\n");
02921    return 0;
02922 }

static int send_callerid ( struct dahdi_pvt *  p  )  [static]

Definition at line 3028 of file chan_dahdi.c.

References ast_free, ast_log(), dahdi_pvt::callwaitcas, CIDCW_EXPIRE_SAMPLES, dahdi_pvt::cidcwexpire, dahdi_pvt::cidlen, dahdi_pvt::cidpos, dahdi_pvt::cidspill, dahdi_setlinear(), dahdi_subchannel::dfd, errno, dahdi_subchannel::linear, LOG_WARNING, restore_conference(), SUB_REAL, and dahdi_pvt::subs.

Referenced by dahdi_call(), dahdi_callwait(), dahdi_read(), and send_cwcidspill().

03029 {
03030    /* Assumes spill in p->cidspill, p->cidlen in length and we're p->cidpos into it */
03031    int res;
03032    /* Take out of linear mode if necessary */
03033    if (p->subs[SUB_REAL].linear) {
03034       p->subs[SUB_REAL].linear = 0;
03035       dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
03036    }
03037    while (p->cidpos < p->cidlen) {
03038       res = write(p->subs[SUB_REAL].dfd, p->cidspill + p->cidpos, p->cidlen - p->cidpos);
03039       if (res < 0) {
03040          if (errno == EAGAIN)
03041             return 0;
03042          else {
03043             ast_log(LOG_WARNING, "write failed: %s\n", strerror(errno));
03044             return -1;
03045          }
03046       }
03047       if (!res)
03048          return 0;
03049       p->cidpos += res;
03050    }
03051    ast_free(p->cidspill);
03052    p->cidspill = NULL;
03053    if (p->callwaitcas) {
03054       /* Wait for CID/CW to expire */
03055       p->cidcwexpire = CIDCW_EXPIRE_SAMPLES;
03056    } else
03057       restore_conference(p);
03058    return 0;
03059 }

static int send_cwcidspill ( struct dahdi_pvt *  p  )  [static]

Definition at line 2988 of file chan_dahdi.c.

References ast_callerid_callwaiting_generate(), AST_LAW, ast_malloc, ast_verb, dahdi_pvt::callwait_name, dahdi_pvt::callwait_num, dahdi_pvt::callwaitcas, dahdi_pvt::cidcwexpire, dahdi_pvt::cidlen, dahdi_pvt::cidpos, dahdi_pvt::cidspill, MAX_CALLERID_SIZE, READ_SIZE, and send_callerid().

Referenced by dahdi_handle_dtmfup().

02989 {
02990    p->callwaitcas = 0;
02991    p->cidcwexpire = 0;
02992    if (!(p->cidspill = ast_malloc(MAX_CALLERID_SIZE)))
02993       return -1;
02994    p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, AST_LAW(p));
02995    /* Make sure we account for the end */
02996    p->cidlen += READ_SIZE * 4;
02997    p->cidpos = 0;
02998    send_callerid(p);
02999    ast_verb(3, "CPE supports Call Waiting Caller*ID.  Sending '%s/%s'\n", p->callwait_name, p->callwait_num);
03000    return 0;
03001 }

static int set_actual_gain ( int  fd,
int  chan,
float  rxgain,
float  txgain,
int  law 
) [static]

Definition at line 2833 of file chan_dahdi.c.

References set_actual_rxgain(), and set_actual_txgain().

Referenced by bump_gains(), dahdi_call(), mkintf(), pri_dchannel(), and restore_gains().

02834 {
02835    return set_actual_txgain(fd, chan, txgain, law) | set_actual_rxgain(fd, chan, rxgain, law);
02836 }

static int set_actual_rxgain ( int  fd,
int  chan,
float  gain,
int  law 
) [static]

Definition at line 2815 of file chan_dahdi.c.

References ast_debug, errno, and fill_rxgain().

Referenced by dahdi_set_swgain(), dahdi_setoption(), and set_actual_gain().

02816 {
02817    struct dahdi_gains g;
02818    int res;
02819 
02820    memset(&g, 0, sizeof(g));
02821    g.chan = chan;
02822    res = ioctl(fd, DAHDI_GETGAINS, &g);
02823    if (res) {
02824       ast_debug(1, "Failed to read gains: %s\n", strerror(errno));
02825       return res;
02826    }
02827 
02828    fill_rxgain(&g, gain, law);
02829 
02830    return ioctl(fd, DAHDI_SETGAINS, &g);
02831 }

static int set_actual_txgain ( int  fd,
int  chan,
float  gain,
int  law 
) [static]

Definition at line 2797 of file chan_dahdi.c.

References ast_debug, errno, and fill_txgain().

Referenced by dahdi_set_swgain(), dahdi_setoption(), and set_actual_gain().

02798 {
02799    struct dahdi_gains g;
02800    int res;
02801 
02802    memset(&g, 0, sizeof(g));
02803    g.chan = chan;
02804    res = ioctl(fd, DAHDI_GETGAINS, &g);
02805    if (res) {
02806       ast_debug(1, "Failed to read gains: %s\n", strerror(errno));
02807       return res;
02808    }
02809 
02810    fill_txgain(&g, gain, law);
02811 
02812    return ioctl(fd, DAHDI_SETGAINS, &g);
02813 }

static int setup_dahdi ( int  reload  )  [static]

Definition at line 17167 of file chan_dahdi.c.

References ast_category_browse(), ast_clear_flag, ast_config_destroy(), ast_config_load, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create, ast_strlen_zero(), ast_variable_browse(), ast_variable_retrieve(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, dahdi_chan_conf_default(), global_jbconf, iflock, ast_variable::lineno, linksets, LOG_ERROR, LOG_NOTICE, LOG_WARNING, master, mfcr2_monitor(), ast_variable::name, ast_variable::next, NUM_DCHANS, NUM_SPANS, pri_create_spanmap(), pri_create_trunkgroup(), pris, PROC_DAHDI_OPT_NOCHAN, PROC_DAHDI_OPT_NOWARN, process_dahdi(), pvts, restart_monitor(), ss7_linkset(), start_pri(), and ast_variable::value.

Referenced by dahdi_restart(), load_module(), and reload().

17168 {
17169    struct ast_config *cfg, *ucfg;
17170    struct ast_variable *v;
17171    struct dahdi_chan_conf base_conf = dahdi_chan_conf_default();
17172    struct dahdi_chan_conf conf;
17173    struct ast_flags config_flags = { reload == 1 ? CONFIG_FLAG_FILEUNCHANGED : 0 };
17174    const char *cat;
17175    int res;
17176 
17177 #ifdef HAVE_PRI
17178    char *c;
17179    int spanno;
17180    int i;
17181    int logicalspan;
17182    int trunkgroup;
17183    int dchannels[NUM_DCHANS];
17184 #endif
17185 
17186    cfg = ast_config_load(config, config_flags);
17187 
17188    /* Error if we have no config file */
17189    if (!cfg) {
17190       ast_log(LOG_ERROR, "Unable to load config %s\n", config);
17191       return 0;
17192    } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
17193       ucfg = ast_config_load("users.conf", config_flags);
17194       if (ucfg == CONFIG_STATUS_FILEUNCHANGED) {
17195          return 0;
17196       } else if (ucfg == CONFIG_STATUS_FILEINVALID) {
17197          ast_log(LOG_ERROR, "File users.conf cannot be parsed.  Aborting.\n");
17198          return 0;
17199       }
17200       ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
17201       if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
17202          ast_log(LOG_ERROR, "File %s cannot be parsed.  Aborting.\n", config);
17203          ast_config_destroy(ucfg);
17204          return 0;
17205       }
17206    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
17207       ast_log(LOG_ERROR, "File %s cannot be parsed.  Aborting.\n", config);
17208       return 0;
17209    } else {
17210       ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
17211       if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
17212          ast_log(LOG_ERROR, "File users.conf cannot be parsed.  Aborting.\n");
17213          ast_config_destroy(cfg);
17214          return 0;
17215       }
17216    }
17217 
17218    /* It's a little silly to lock it, but we mind as well just to be sure */
17219    ast_mutex_lock(&iflock);
17220 #ifdef HAVE_PRI
17221    if (reload != 1) {
17222       /* Process trunkgroups first */
17223       v = ast_variable_browse(cfg, "trunkgroups");
17224       while (v) {
17225          if (!strcasecmp(v->name, "trunkgroup")) {
17226             trunkgroup = atoi(v->value);
17227             if (trunkgroup > 0) {
17228                if ((c = strchr(v->value, ','))) {
17229                   i = 0;
17230                   memset(dchannels, 0, sizeof(dchannels));
17231                   while (c && (i < NUM_DCHANS)) {
17232                      dchannels[i] = atoi(c + 1);
17233                      if (dchannels[i] < 0) {
17234                         ast_log(LOG_WARNING, "D-channel for trunk group %d must be a postiive number at line %d of chan_dahdi.conf\n", trunkgroup, v->lineno);
17235                      } else
17236                         i++;
17237                      c = strchr(c + 1, ',');
17238                   }
17239                   if (i) {
17240                      if (pri_create_trunkgroup(trunkgroup, dchannels)) {
17241                         ast_log(LOG_WARNING, "Unable to create trunk group %d with Primary D-channel %d at line %d of chan_dahdi.conf\n", trunkgroup, dchannels[0], v->lineno);
17242                   } else
17243                         ast_verb(2, "Created trunk group %d with Primary D-channel %d and %d backup%s\n", trunkgroup, dchannels[0], i - 1, (i == 1) ? "" : "s");
17244                   } else
17245                      ast_log(LOG_WARNING, "Trunk group %d lacks any valid D-channels at line %d of chan_dahdi.conf\n", trunkgroup, v->lineno);
17246                } else
17247                   ast_log(LOG_WARNING, "Trunk group %d lacks a primary D-channel at line %d of chan_dahdi.conf\n", trunkgroup, v->lineno);
17248             } else
17249                ast_log(LOG_WARNING, "Trunk group identifier must be a positive integer at line %d of chan_dahdi.conf\n", v->lineno);
17250          } else if (!strcasecmp(v->name, "spanmap")) {
17251             spanno = atoi(v->value);
17252             if (spanno > 0) {
17253                if ((c = strchr(v->value, ','))) {
17254                   trunkgroup = atoi(c + 1);
17255                   if (trunkgroup > 0) {
17256                      if ((c = strchr(c + 1, ',')))
17257                         logicalspan = atoi(c + 1);
17258                      else
17259                         logicalspan = 0;
17260                      if (logicalspan >= 0) {
17261                         if (pri_create_spanmap(spanno - 1, trunkgroup, logicalspan)) {
17262                            ast_log(LOG_WARNING, "Failed to map span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan);
17263                      } else
17264                            ast_verb(2, "Mapped span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan);
17265                      } else
17266                         ast_log(LOG_WARNING, "Logical span must be a postive number, or '0' (for unspecified) at line %d of chan_dahdi.conf\n", v->lineno);
17267                   } else
17268                      ast_log(LOG_WARNING, "Trunk group must be a postive number at line %d of chan_dahdi.conf\n", v->lineno);
17269                } else
17270                   ast_log(LOG_WARNING, "Missing trunk group for span map at line %d of chan_dahdi.conf\n", v->lineno);
17271             } else
17272                ast_log(LOG_WARNING, "Span number must be a postive integer at line %d of chan_dahdi.conf\n", v->lineno);
17273          } else {
17274             ast_log(LOG_NOTICE, "Ignoring unknown keyword '%s' in trunkgroups\n", v->name);
17275          }
17276          v = v->next;
17277       }
17278    }
17279 #endif
17280 
17281    /* Copy the default jb config over global_jbconf */
17282    memcpy(&global_jbconf, &default_jbconf, sizeof(global_jbconf));
17283 
17284    mwimonitornotify[0] = '\0';
17285 
17286    v = ast_variable_browse(cfg, "channels");
17287    if ((res = process_dahdi(&base_conf, "", v, reload, 0))) {
17288       ast_mutex_unlock(&iflock);
17289       ast_config_destroy(cfg);
17290       if (ucfg) {
17291          ast_config_destroy(ucfg);
17292       }
17293       return res;
17294    }
17295 
17296    /* Now get configuration from all normal sections in chan_dahdi.conf: */
17297    for (cat = ast_category_browse(cfg, NULL); cat ; cat = ast_category_browse(cfg, cat)) {
17298       /* [channels] and [trunkgroups] are used. Let's also reserve
17299        * [globals] and [general] for future use
17300        */
17301       if (!strcasecmp(cat, "general") ||
17302          !strcasecmp(cat, "trunkgroups") ||
17303          !strcasecmp(cat, "globals") ||
17304          !strcasecmp(cat, "channels")) {
17305          continue;
17306       }
17307 
17308       memcpy(&conf, &base_conf, sizeof(conf));
17309 
17310       if ((res = process_dahdi(&conf, cat, ast_variable_browse(cfg, cat), reload, PROC_DAHDI_OPT_NOCHAN))) {
17311          ast_mutex_unlock(&iflock);
17312          ast_config_destroy(cfg);
17313          if (ucfg) {
17314             ast_config_destroy(ucfg);
17315          }
17316          return res;
17317       }
17318    }
17319 
17320    ast_config_destroy(cfg);
17321 
17322    if (ucfg) {
17323       const char *chans;
17324 
17325       process_dahdi(&base_conf, "", ast_variable_browse(ucfg, "general"), 1, 0);
17326 
17327       for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) {
17328          if (!strcasecmp(cat, "general")) {
17329             continue;
17330          }
17331 
17332          chans = ast_variable_retrieve(ucfg, cat, "dahdichan");
17333 
17334          if (ast_strlen_zero(chans)) {
17335             continue;
17336          }
17337 
17338          memcpy(&conf, &base_conf, sizeof(conf));
17339 
17340          if ((res = process_dahdi(&conf, cat, ast_variable_browse(ucfg, cat), reload, PROC_DAHDI_OPT_NOCHAN | PROC_DAHDI_OPT_NOWARN))) {
17341             ast_config_destroy(ucfg);
17342             ast_mutex_unlock(&iflock);
17343             return res;
17344          }
17345       }
17346       ast_config_destroy(ucfg);
17347    }
17348    ast_mutex_unlock(&iflock);
17349 
17350 #ifdef HAVE_PRI
17351    if (reload != 1) {
17352       int x;
17353       for (x = 0; x < NUM_SPANS; x++) {
17354          if (pris[x].pvts[0]) {
17355             if (start_pri(pris + x)) {
17356                ast_log(LOG_ERROR, "Unable to start D-channel on span %d\n", x + 1);
17357                return -1;
17358             } else
17359                ast_verb(2, "Starting D-Channel on span %d\n", x + 1);
17360          }
17361       }
17362    }
17363 #endif
17364 #ifdef HAVE_SS7
17365    if (reload != 1) {
17366       int x;
17367       for (x = 0; x < NUM_SPANS; x++) {
17368          if (linksets[x].ss7) {
17369             if (ast_pthread_create(&linksets[x].master, NULL, ss7_linkset, &linksets[x])) {
17370                ast_log(LOG_ERROR, "Unable to start SS7 linkset on span %d\n", x + 1);
17371                return -1;
17372             } else
17373                ast_verb(2, "Starting SS7 linkset on span %d\n", x + 1);
17374          }
17375       }
17376    }
17377 #endif
17378 #ifdef HAVE_OPENR2
17379    if (reload != 1) {
17380       int x;
17381       for (x = 0; x < r2links_count; x++) {
17382          if (ast_pthread_create(&r2links[x]->r2master, NULL, mfcr2_monitor, r2links[x])) {
17383             ast_log(LOG_ERROR, "Unable to start R2 monitor on channel group %d\n", x + 1);
17384             return -1;
17385          } else {
17386             ast_verb(2, "Starting R2 monitor on channel group %d\n", x + 1);
17387          }
17388       }
17389    }
17390 #endif
17391    /* And start the monitor for the first time */
17392    restart_monitor();
17393    return 0;
17394 }

static int sigtype_to_signalling ( int  sigtype  )  [static]

Definition at line 10089 of file chan_dahdi.c.

Referenced by mkintf().

10090 {
10091    return sigtype;
10092 }

static void ss7_apply_plan_to_number ( char *  buf,
size_t  size,
const struct dahdi_ss7 *  ss7,
const char *  number,
const unsigned  nai 
) [static]

Definition at line 11469 of file chan_dahdi.c.

References ast_strlen_zero(), dahdi_ss7::internationalprefix, dahdi_ss7::nationalprefix, dahdi_ss7::subscriberprefix, and dahdi_ss7::unknownprefix.

Referenced by ss7_linkset().

11470 {
11471    if (ast_strlen_zero(number)) { /* make sure a number exists so prefix isn't placed on an empty string */
11472       if (size) {
11473          *buf = '\0';
11474       }
11475       return;
11476    }
11477    switch (nai) {
11478    case SS7_NAI_INTERNATIONAL:
11479       snprintf(buf, size, "%s%s", ss7->internationalprefix, number);
11480       break;
11481    case SS7_NAI_NATIONAL:
11482       snprintf(buf, size, "%s%s", ss7->nationalprefix, number);
11483       break;
11484    case SS7_NAI_SUBSCRIBER:
11485       snprintf(buf, size, "%s%s", ss7->subscriberprefix, number);
11486       break;
11487    case SS7_NAI_UNKNOWN:
11488       snprintf(buf, size, "%s%s", ss7->unknownprefix, number);
11489       break;
11490    default:
11491       snprintf(buf, size, "%s", number);
11492       break;
11493    }
11494 }

static void ss7_block_cics ( struct dahdi_ss7 *  linkset,
int  startcic,
int  endcic,
unsigned int  dpc,
unsigned char  state[],
int  block 
) [inline, static]

Definition at line 11278 of file chan_dahdi.c.

References dahdi_pvt::cic, dahdi_pvt::dpc, dahdi_ss7::numchans, dahdi_ss7::pvts, and dahdi_pvt::remotelyblocked.

Referenced by ss7_linkset().

11279 {
11280    int i;
11281 
11282    for (i = 0; i < linkset->numchans; i++) {
11283       if (linkset->pvts[i] && (linkset->pvts[i]->dpc == dpc && ((linkset->pvts[i]->cic >= startcic) && (linkset->pvts[i]->cic <= endcic)))) {
11284          if (state) {
11285             if (state[i])
11286                linkset->pvts[i]->remotelyblocked = block;
11287          } else
11288             linkset->pvts[i]->remotelyblocked = block;
11289       }
11290    }
11291 }

static int ss7_find_cic ( struct dahdi_ss7 *  linkset,
int  cic,
unsigned int  dpc 
) [static]

Definition at line 11213 of file chan_dahdi.c.

References dahdi_pvt::cic, dahdi_pvt::dpc, dahdi_ss7::numchans, and dahdi_ss7::pvts.

Referenced by ss7_linkset().

11214 {
11215    int i;
11216    int winner = -1;
11217    for (i = 0; i < linkset->numchans; i++) {
11218       if (linkset->pvts[i] && (linkset->pvts[i]->dpc == dpc && linkset->pvts[i]->cic == cic)) {
11219          winner = i;
11220          break;
11221       }
11222    }
11223    return winner;
11224 }

static int ss7_grab ( struct dahdi_pvt *  pvt,
struct dahdi_ss7 *  pri 
) [inline, static]

Definition at line 1458 of file chan_dahdi.c.

References ast_mutex_trylock(), AST_PTHREADT_NULL, DEADLOCK_AVOIDANCE, dahdi_pvt::lock, dahdi_ss7::lock, and dahdi_ss7::master.

Referenced by dahdi_answer(), dahdi_call(), dahdi_hangup(), and dahdi_indicate().

01459 {
01460    int res;
01461    /* Grab the lock first */
01462    do {
01463       res = ast_mutex_trylock(&pri->lock);
01464       if (res) {
01465          DEADLOCK_AVOIDANCE(&pvt->lock);
01466       }
01467    } while (res);
01468    /* Then break the poll */
01469    if (pri->master != AST_PTHREADT_NULL)
01470       pthread_kill(pri->master, SIGURG);
01471    return 0;
01472 }

static void ss7_handle_cqm ( struct dahdi_ss7 *  linkset,
int  startcic,
int  endcic,
unsigned int  dpc 
) [static]

Definition at line 11228 of file chan_dahdi.c.

References ast_log(), dahdi_pvt::cic, dahdi_pvt::dpc, dahdi_pvt::locallyblocked, LOG_WARNING, dahdi_ss7::numchans, dahdi_pvt::outgoing, dahdi_ss7::pvts, dahdi_pvt::remotelyblocked, dahdi_ss7::ss7, dahdi_pvt::ss7call, and status.

Referenced by ss7_linkset().

11229 {
11230    unsigned char status[32];
11231    struct dahdi_pvt *p = NULL;
11232    int i, offset;
11233 
11234    for (i = 0; i < linkset->numchans; i++) {
11235       if (linkset->pvts[i] && (linkset->pvts[i]->dpc == dpc && ((linkset->pvts[i]->cic >= startcic) && (linkset->pvts[i]->cic <= endcic)))) {
11236          p = linkset->pvts[i];
11237          offset = p->cic - startcic;
11238          status[offset] = 0;
11239          if (p->locallyblocked)
11240             status[offset] |= (1 << 0) | (1 << 4);
11241          if (p->remotelyblocked)
11242             status[offset] |= (1 << 1) | (1 << 5);
11243          if (p->ss7call) {
11244             if (p->outgoing)
11245                status[offset] |= (1 << 3);
11246             else
11247                status[offset] |= (1 << 2);
11248          } else
11249             status[offset] |= 0x3 << 2;
11250       }
11251    }
11252 
11253    if (p)
11254       isup_cqr(linkset->ss7, startcic, endcic, dpc, status);
11255    else
11256       ast_log(LOG_WARNING, "Could not find any equipped circuits within CQM CICs\n");
11257 
11258 }

static void ss7_hangup_cics ( struct dahdi_ss7 *  linkset,
int  startcic,
int  endcic,
unsigned int  dpc 
) [inline, static]

Definition at line 11262 of file chan_dahdi.c.

References ast_channel::_softhangup, ast_mutex_lock(), ast_mutex_unlock(), AST_SOFTHANGUP_DEV, dahdi_pvt::cic, dahdi_pvt::dpc, dahdi_pvt::lock, dahdi_ss7::numchans, dahdi_pvt::owner, and dahdi_ss7::pvts.

Referenced by ss7_linkset().

11263 {
11264    int i;
11265 
11266    for (i = 0; i < linkset->numchans; i++) {
11267       if (linkset->pvts[i] && (linkset->pvts[i]->dpc == dpc && ((linkset->pvts[i]->cic >= startcic) && (linkset->pvts[i]->cic <= endcic)))) {
11268          ast_mutex_lock(&linkset->pvts[i]->lock);
11269          if (linkset->pvts[i]->owner)
11270             linkset->pvts[i]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
11271          ast_mutex_unlock(&linkset->pvts[i]->lock);
11272       }
11273    }
11274 }

static void ss7_inservice ( struct dahdi_ss7 *  linkset,
int  startcic,
int  endcic,
unsigned int  dpc 
) [static]

Definition at line 11295 of file chan_dahdi.c.

References dahdi_pvt::cic, dahdi_pvt::dpc, dahdi_pvt::inservice, dahdi_ss7::numchans, and dahdi_ss7::pvts.

Referenced by ss7_linkset().

11296 {
11297    int i;
11298 
11299    for (i = 0; i < linkset->numchans; i++) {
11300       if (linkset->pvts[i] && (linkset->pvts[i]->dpc == dpc && ((linkset->pvts[i]->cic >= startcic) && (linkset->pvts[i]->cic <= endcic))))
11301          linkset->pvts[i]->inservice = 1;
11302    }
11303 }

static void* ss7_linkset ( void *  data  )  [static]

Definition at line 11505 of file chan_dahdi.c.

References ast_channel::_softhangup, dahdi_pvt::alerting, dahdi_pvt::alreadyhungup, AST_CAUSE_UNALLOCATED, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, ast_copy_string(), ast_debug, ast_dsp_set_features(), ast_exists_extension(), AST_FRAME_CONTROL, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_SOFTHANGUP_DEV, ast_strlen_zero(), ast_tvnow(), ast_verbose, dahdi_ss7::called_nai, dahdi_ss7::calling_nai, dahdi_pvt::calling_party_cat, dahdi_pvt::callingpres, dahdi_pvt::charge_number, dahdi_pvt::cic, dahdi_pvt::cid_ani, dahdi_pvt::cid_ani2, dahdi_pvt::cid_name, dahdi_pvt::cid_num, dahdi_pvt::cid_ton, dahdi_pvt::context, dahdi_enable_ec(), dahdi_loopback(), dahdi_queue_frame(), dahdi_pvt::dialing, dahdi_pvt::dnid, dahdi_pvt::dpc, dahdi_pvt::dsp, dahdi_pvt::dsp_features, errno, dahdi_pvt::exten, dahdi_ss7::fds, dahdi_pvt::gen_add_nai, dahdi_pvt::gen_add_num_plan, dahdi_pvt::gen_add_number, dahdi_pvt::gen_add_pres_ind, dahdi_pvt::gen_add_type, dahdi_pvt::gen_dig_number, dahdi_pvt::gen_dig_scheme, dahdi_pvt::gen_dig_type, dahdi_pvt::generic_name, ast_channel::hangupcause, dahdi_pvt::immediate, dahdi_pvt::inalarm, dahdi_pvt::inservice, dahdi_pvt::jip_number, dahdi_ss7::linkstate, LINKSTATE_DOWN, LINKSTATE_INALARM, LINKSTATE_STARTING, LINKSTATE_UP, dahdi_pvt::locallyblocked, dahdi_pvt::lock, dahdi_ss7::lock, LOG_ERROR, LOG_NOTICE, LOG_WARNING, dahdi_pvt::loopedback, dahdi_subchannel::needanswer, dahdi_subchannel::needringing, dahdi_ss7::numchans, dahdi_ss7::numsigchans, dahdi_pvt::orig_called_num, dahdi_pvt::owner, dahdi_pvt::proceeding, dahdi_pvt::progress, dahdi_ss7::pvts, dahdi_pvt::redirecting_num, dahdi_pvt::remotelyblocked, dahdi_pvt::restartpending, dahdi_pvt::rlt, dahdi_ss7::ss7, ss7_apply_plan_to_number(), ss7_block_cics(), ss7_find_cic(), ss7_handle_cqm(), ss7_hangup_cics(), ss7_inservice(), ss7_pres_scr2cid_pres(), ss7_reset_linkset(), ss7_start_call(), dahdi_pvt::ss7call, dahdi_ss7::state, SUB_REAL, dahdi_pvt::subs, tv, and dahdi_pvt::use_callerid.

Referenced by setup_dahdi().

11506 {
11507    int res, i;
11508    struct timeval *next = NULL, tv;
11509    struct dahdi_ss7 *linkset = (struct dahdi_ss7 *) data;
11510    struct ss7 *ss7 = linkset->ss7;
11511    ss7_event *e = NULL;
11512    struct dahdi_pvt *p;
11513    int chanpos;
11514    struct pollfd pollers[NUM_DCHANS];
11515    int cic;
11516    unsigned int dpc;
11517    int nextms = 0;
11518 
11519    ss7_start(ss7);
11520 
11521    while(1) {
11522       ast_mutex_lock(&linkset->lock);
11523       if ((next = ss7_schedule_next(ss7))) {
11524          tv = ast_tvnow();
11525          tv.tv_sec = next->tv_sec - tv.tv_sec;
11526          tv.tv_usec = next->tv_usec - tv.tv_usec;
11527          if (tv.tv_usec < 0) {
11528             tv.tv_usec += 1000000;
11529             tv.tv_sec -= 1;
11530          }
11531          if (tv.tv_sec < 0) {
11532             tv.tv_sec = 0;
11533             tv.tv_usec = 0;
11534          }
11535          nextms = tv.tv_sec * 1000;
11536          nextms += tv.tv_usec / 1000;
11537       }
11538       ast_mutex_unlock(&linkset->lock);
11539 
11540       for (i = 0; i < linkset->numsigchans; i++) {
11541          pollers[i].fd = linkset->fds[i];
11542          pollers[i].events = ss7_pollflags(ss7, linkset->fds[i]);
11543          pollers[i].revents = 0;
11544       }
11545 
11546       res = poll(pollers, linkset->numsigchans, nextms);
11547       if ((res < 0) && (errno != EINTR)) {
11548          ast_log(LOG_ERROR, "poll(%s)\n", strerror(errno));
11549       } else if (!res) {
11550          ast_mutex_lock(&linkset->lock);
11551          ss7_schedule_run(ss7);
11552          ast_mutex_unlock(&linkset->lock);
11553          continue;
11554       }
11555 
11556       ast_mutex_lock(&linkset->lock);
11557       for (i = 0; i < linkset->numsigchans; i++) {
11558          if (pollers[i].revents & POLLPRI) {
11559             int x;
11560             if (ioctl(pollers[i].fd, DAHDI_GETEVENT, &x)) {
11561                ast_log(LOG_ERROR, "Error in exception retrieval!\n");
11562             }
11563             switch (x) {
11564             case DAHDI_EVENT_OVERRUN:
11565                ast_debug(1, "Overrun detected!\n");
11566                break;
11567             case DAHDI_EVENT_BADFCS:
11568                ast_debug(1, "Bad FCS\n");
11569                break;
11570             case DAHDI_EVENT_ABORT:
11571                ast_debug(1, "HDLC Abort\n");
11572                break;
11573             case DAHDI_EVENT_ALARM:
11574                ast_log(LOG_ERROR, "Alarm on link!\n");
11575                linkset->linkstate[i] |= (LINKSTATE_DOWN | LINKSTATE_INALARM);
11576                linkset->linkstate[i] &= ~LINKSTATE_UP;
11577                ss7_link_alarm(ss7, pollers[i].fd);
11578                break;
11579             case DAHDI_EVENT_NOALARM:
11580                ast_log(LOG_ERROR, "Alarm cleared on link\n");
11581                linkset->linkstate[i] &= ~(LINKSTATE_INALARM | LINKSTATE_DOWN);
11582                linkset->linkstate[i] |= LINKSTATE_STARTING;
11583                ss7_link_noalarm(ss7, pollers[i].fd);
11584                break;
11585             default:
11586                ast_log(LOG_ERROR, "Got exception %d!\n", x);
11587                break;
11588             }
11589          }
11590 
11591          if (pollers[i].revents & POLLIN) {
11592             res = ss7_read(ss7, pollers[i].fd);
11593          }
11594 
11595          if (pollers[i].revents & POLLOUT) {
11596             res = ss7_write(ss7, pollers[i].fd);
11597             if (res < 0) {
11598                ast_debug(1, "Error in write %s\n", strerror(errno));
11599             }
11600          }
11601       }
11602 
11603       while ((e = ss7_check_event(ss7))) {
11604          switch (e->e) {
11605          case SS7_EVENT_UP:
11606             if (linkset->state != LINKSET_STATE_UP) {
11607                ast_verbose("--- SS7 Up ---\n");
11608                ss7_reset_linkset(linkset);
11609             }
11610             linkset->state = LINKSET_STATE_UP;
11611             break;
11612          case SS7_EVENT_DOWN:
11613             ast_verbose("--- SS7 Down ---\n");
11614             linkset->state = LINKSET_STATE_DOWN;
11615             for (i = 0; i < linkset->numchans; i++) {
11616                struct dahdi_pvt *p = linkset->pvts[i];
11617                if (p)
11618                   p->inalarm = 1;
11619             }
11620             break;
11621          case MTP2_LINK_UP:
11622             ast_verbose("MTP2 link up (SLC %d)\n", e->gen.data);
11623             break;
11624          case MTP2_LINK_DOWN:
11625             ast_log(LOG_WARNING, "MTP2 link down (SLC %d)\n", e->gen.data);
11626             break;
11627          case ISUP_EVENT_CPG:
11628             chanpos = ss7_find_cic(linkset, e->cpg.cic, e->cpg.opc);
11629             if (chanpos < 0) {
11630                ast_log(LOG_WARNING, "CPG on unconfigured CIC %d\n", e->cpg.cic);
11631                break;
11632             }
11633             p = linkset->pvts[chanpos];
11634             ast_mutex_lock(&p->lock);
11635             switch (e->cpg.event) {
11636             case CPG_EVENT_ALERTING:
11637                p->alerting = 1;
11638                p->subs[SUB_REAL].needringing = 1;
11639                break;
11640             case CPG_EVENT_PROGRESS:
11641             case CPG_EVENT_INBANDINFO:
11642                {
11643                   struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, };
11644                   ast_debug(1, "Queuing frame PROGRESS on CIC %d\n", p->cic);
11645                   dahdi_queue_frame(p, &f, linkset);
11646                   p->progress = 1;
11647                   p->dialing = 0;
11648                   if (p->dsp && p->dsp_features) {
11649                      ast_dsp_set_features(p->dsp, p->dsp_features);
11650                      p->dsp_features = 0;
11651                   }
11652                }
11653                break;
11654             default:
11655                ast_debug(1, "Do not handle CPG with event type 0x%x\n", e->cpg.event);
11656             }
11657 
11658             ast_mutex_unlock(&p->lock);
11659             break;
11660          case ISUP_EVENT_RSC:
11661             ast_verbose("Resetting CIC %d\n", e->rsc.cic);
11662             chanpos = ss7_find_cic(linkset, e->rsc.cic, e->rsc.opc);
11663             if (chanpos < 0) {
11664                ast_log(LOG_WARNING, "RSC on unconfigured CIC %d\n", e->rsc.cic);
11665                break;
11666             }
11667             p = linkset->pvts[chanpos];
11668             ast_mutex_lock(&p->lock);
11669             p->inservice = 1;
11670             p->remotelyblocked = 0;
11671             dpc = p->dpc;
11672             isup_set_call_dpc(e->rsc.call, dpc);
11673             if (p->ss7call)
11674                p->ss7call = NULL;
11675             if (p->owner)
11676                p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
11677             ast_mutex_unlock(&p->lock);
11678             isup_rlc(ss7, e->rsc.call);
11679             break;
11680          case ISUP_EVENT_GRS:
11681             ast_debug(1, "Got Reset for CICs %d to %d: Acknowledging\n", e->grs.startcic, e->grs.endcic);
11682             chanpos = ss7_find_cic(linkset, e->grs.startcic, e->grs.opc);
11683             if (chanpos < 0) {
11684                ast_log(LOG_WARNING, "GRS on unconfigured CIC %d\n", e->grs.startcic);
11685                break;
11686             }
11687             p = linkset->pvts[chanpos];
11688             isup_gra(ss7, e->grs.startcic, e->grs.endcic, e->grs.opc);
11689             ss7_block_cics(linkset, e->grs.startcic, e->grs.endcic, e->grs.opc, NULL, 0);
11690             ss7_hangup_cics(linkset, e->grs.startcic, e->grs.endcic, e->grs.opc);
11691             break;
11692          case ISUP_EVENT_CQM:
11693             ast_debug(1, "Got Circuit group query message from CICs %d to %d\n", e->cqm.startcic, e->cqm.endcic);
11694             ss7_handle_cqm(linkset, e->cqm.startcic, e->cqm.endcic, e->cqm.opc);
11695             break;
11696          case ISUP_EVENT_GRA:
11697             ast_verbose("Got reset acknowledgement from CIC %d to %d.\n", e->gra.startcic, e->gra.endcic);
11698             ss7_inservice(linkset, e->gra.startcic, e->gra.endcic, e->gra.opc);
11699             ss7_block_cics(linkset, e->gra.startcic, e->gra.endcic, e->gra.opc, e->gra.status, 1);
11700             break;
11701          case ISUP_EVENT_IAM:
11702             ast_debug(1, "Got IAM for CIC %d and called number %s, calling number %s\n", e->iam.cic, e->iam.called_party_num, e->iam.calling_party_num);
11703             chanpos = ss7_find_cic(linkset, e->iam.cic, e->iam.opc);
11704             if (chanpos < 0) {
11705                ast_log(LOG_WARNING, "IAM on unconfigured CIC %d\n", e->iam.cic);
11706                isup_rel(ss7, e->iam.call, -1);
11707                break;
11708             }
11709             p = linkset->pvts[chanpos];
11710             ast_mutex_lock(&p->lock);
11711             if (p->owner) {
11712                if (p->ss7call == e->iam.call) {
11713                   ast_mutex_unlock(&p->lock);
11714                   ast_log(LOG_WARNING, "Duplicate IAM requested on CIC %d\n", e->iam.cic);
11715                   break;
11716                } else {
11717                   ast_mutex_unlock(&p->lock);
11718                   ast_log(LOG_WARNING, "Ring requested on CIC %d already in use!\n", e->iam.cic);
11719                   break;
11720                }
11721             }
11722 
11723             dpc = p->dpc;
11724             p->ss7call = e->iam.call;
11725             isup_set_call_dpc(p->ss7call, dpc);
11726 
11727             if ((p->use_callerid) && (!ast_strlen_zero(e->iam.calling_party_num))) {
11728                ss7_apply_plan_to_number(p->cid_num, sizeof(p->cid_num), linkset, e->iam.calling_party_num, e->iam.calling_nai);
11729                p->callingpres = ss7_pres_scr2cid_pres(e->iam.presentation_ind, e->iam.screening_ind);
11730             } else
11731                p->cid_num[0] = 0;
11732 
11733             if (p->immediate) {
11734                p->exten[0] = 's';
11735                p->exten[1] = '\0';
11736             } else if (!ast_strlen_zero(e->iam.called_party_num)) {
11737                char *st;
11738                ss7_apply_plan_to_number(p->exten, sizeof(p->exten), linkset, e->iam.called_party_num, e->iam.called_nai);
11739                st = strchr(p->exten, '#');
11740                if (st)
11741                   *st = '\0';
11742                } else
11743                   p->exten[0] = '\0';
11744 
11745             p->cid_ani[0] = '\0';
11746             if ((p->use_callerid) && (!ast_strlen_zero(e->iam.generic_name)))
11747                ast_copy_string(p->cid_name, e->iam.generic_name, sizeof(p->cid_name));
11748             else
11749                p->cid_name[0] = '\0';
11750 
11751             p->cid_ani2 = e->iam.oli_ani2;
11752             p->cid_ton = 0;
11753             ast_copy_string(p->charge_number, e->iam.charge_number, sizeof(p->charge_number));
11754             ast_copy_string(p->gen_add_number, e->iam.gen_add_number, sizeof(p->gen_add_number));
11755             p->gen_add_type = e->iam.gen_add_type;
11756             p->gen_add_nai = e->iam.gen_add_nai;
11757             p->gen_add_pres_ind = e->iam.gen_add_pres_ind;
11758             p->gen_add_num_plan = e->iam.gen_add_num_plan;
11759             ast_copy_string(p->gen_dig_number, e->iam.gen_dig_number, sizeof(p->gen_dig_number));
11760             p->gen_dig_type = e->iam.gen_dig_type;
11761             p->gen_dig_scheme = e->iam.gen_dig_scheme;
11762             ast_copy_string(p->jip_number, e->iam.jip_number, sizeof(p->jip_number));
11763             ast_copy_string(p->orig_called_num, e->iam.orig_called_num, sizeof(p->orig_called_num));
11764             ast_copy_string(p->redirecting_num, e->iam.redirecting_num, sizeof(p->redirecting_num));
11765             ast_copy_string(p->generic_name, e->iam.generic_name, sizeof(p->generic_name));
11766             p->calling_party_cat = e->iam.calling_party_cat;
11767 
11768             /* Set DNID */
11769             if (!ast_strlen_zero(e->iam.called_party_num))
11770                ss7_apply_plan_to_number(p->dnid, sizeof(p->dnid), linkset, e->iam.called_party_num, e->iam.called_nai);
11771 
11772             if (ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num)) {
11773 
11774                if (e->iam.cot_check_required) {
11775                   dahdi_loopback(p, 1);
11776                } else
11777                   ss7_start_call(p, linkset);
11778             } else {
11779                ast_debug(1, "Call on CIC for unconfigured extension %s\n", p->exten);
11780                p->alreadyhungup = 1;
11781                isup_rel(ss7, e->iam.call, AST_CAUSE_UNALLOCATED);
11782             }
11783             ast_mutex_unlock(&p->lock);
11784             break;
11785          case ISUP_EVENT_COT:
11786             chanpos = ss7_find_cic(linkset, e->cot.cic, e->cot.opc);
11787             if (chanpos < 0) {
11788                ast_log(LOG_WARNING, "COT on unconfigured CIC %d\n", e->cot.cic);
11789                isup_rel(ss7, e->cot.call, -1);
11790                break;
11791             }
11792             p = linkset->pvts[chanpos];
11793 
11794             ast_mutex_lock(&p->lock);
11795 
11796             if (p->loopedback) {
11797                dahdi_loopback(p, 0);
11798                ss7_start_call(p, linkset);
11799             }
11800 
11801             ast_mutex_unlock(&p->lock);
11802 
11803             break;
11804          case ISUP_EVENT_CCR:
11805             ast_debug(1, "Got CCR request on CIC %d\n", e->ccr.cic);
11806             chanpos = ss7_find_cic(linkset, e->ccr.cic, e->ccr.opc);
11807             if (chanpos < 0) {
11808                ast_log(LOG_WARNING, "CCR on unconfigured CIC %d\n", e->ccr.cic);
11809                break;
11810             }
11811 
11812             p = linkset->pvts[chanpos];
11813 
11814             ast_mutex_lock(&p->lock);
11815             dahdi_loopback(p, 1);
11816             ast_mutex_unlock(&p->lock);
11817 
11818             isup_lpa(linkset->ss7, e->ccr.cic, p->dpc);
11819             break;
11820          case ISUP_EVENT_CVT:
11821             ast_debug(1, "Got CVT request on CIC %d\n", e->cvt.cic);
11822             chanpos = ss7_find_cic(linkset, e->cvt.cic, e->cvt.opc);
11823             if (chanpos < 0) {
11824                ast_log(LOG_WARNING, "CVT on unconfigured CIC %d\n", e->cvt.cic);
11825                break;
11826             }
11827 
11828             p = linkset->pvts[chanpos];
11829 
11830             ast_mutex_lock(&p->lock);
11831             dahdi_loopback(p, 1);
11832             ast_mutex_unlock(&p->lock);
11833 
11834             isup_cvr(linkset->ss7, e->cvt.cic, p->dpc);
11835             break;
11836          case ISUP_EVENT_REL:
11837             chanpos = ss7_find_cic(linkset, e->rel.cic, e->rel.opc);
11838             if (chanpos < 0) {
11839                ast_log(LOG_WARNING, "REL on unconfigured CIC %d\n", e->rel.cic);
11840                break;
11841             }
11842             p = linkset->pvts[chanpos];
11843             ast_mutex_lock(&p->lock);
11844             if (p->owner) {
11845                p->owner->hangupcause = e->rel.cause;
11846                p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
11847             } else if (!p->restartpending)
11848                ast_log(LOG_WARNING, "REL on channel (CIC %d) without owner!\n", p->cic);
11849 
11850             /* End the loopback if we have one */
11851             dahdi_loopback(p, 0);
11852 
11853             isup_rlc(ss7, e->rel.call);
11854             p->ss7call = NULL;
11855 
11856             ast_mutex_unlock(&p->lock);
11857             break;
11858          case ISUP_EVENT_ACM:
11859             chanpos = ss7_find_cic(linkset, e->acm.cic, e->acm.opc);
11860             if (chanpos < 0) {
11861                ast_log(LOG_WARNING, "ACM on unconfigured CIC %d\n", e->acm.cic);
11862                isup_rel(ss7, e->acm.call, -1);
11863                break;
11864             } else {
11865                struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROCEEDING, };
11866 
11867                p = linkset->pvts[chanpos];
11868 
11869                ast_debug(1, "Queueing frame from SS7_EVENT_ACM on CIC %d\n", p->cic);
11870 
11871                if (e->acm.call_ref_ident > 0) {
11872                   p->rlt = 1; /* Setting it but not using it here*/
11873                }
11874 
11875                ast_mutex_lock(&p->lock);
11876                dahdi_queue_frame(p, &f, linkset);
11877                p->proceeding = 1;
11878                p->dialing = 0;
11879                /* Send alerting if subscriber is free */
11880                if (e->acm.called_party_status_ind == 1) {
11881                   p->alerting = 1;
11882                   p->subs[SUB_REAL].needringing = 1;
11883                }
11884                ast_mutex_unlock(&p->lock);
11885             }
11886             break;
11887          case ISUP_EVENT_CGB:
11888             chanpos = ss7_find_cic(linkset, e->cgb.startcic, e->cgb.opc);
11889             if (chanpos < 0) {
11890                ast_log(LOG_WARNING, "CGB on unconfigured CIC %d\n", e->cgb.startcic);
11891                break;
11892             }
11893             p = linkset->pvts[chanpos];
11894             ss7_block_cics(linkset, e->cgb.startcic, e->cgb.endcic, e->cgb.opc, e->cgb.status, 1);
11895             isup_cgba(linkset->ss7, e->cgb.startcic, e->cgb.endcic, e->cgb.opc, e->cgb.status, e->cgb.type);
11896             break;
11897          case ISUP_EVENT_CGU:
11898             chanpos = ss7_find_cic(linkset, e->cgu.startcic, e->cgu.opc);
11899             if (chanpos < 0) {
11900                ast_log(LOG_WARNING, "CGU on unconfigured CIC %d\n", e->cgu.startcic);
11901                break;
11902             }
11903             p = linkset->pvts[chanpos];
11904             ss7_block_cics(linkset, e->cgu.startcic, e->cgu.endcic, e->cgu.opc, e->cgu.status, 0);
11905             isup_cgua(linkset->ss7, e->cgu.startcic, e->cgu.endcic, e->cgu.opc, e->cgu.status, e->cgu.type);
11906             break;
11907          case ISUP_EVENT_UCIC:
11908             chanpos = ss7_find_cic(linkset, e->ucic.cic, e->ucic.opc);
11909             if (chanpos < 0) {
11910                ast_log(LOG_WARNING, "UCIC on unconfigured CIC %d\n", e->ucic.cic);
11911                break;
11912             }
11913             p = linkset->pvts[chanpos];
11914             ast_debug(1, "Unequiped Circuit Id Code on CIC %d\n", e->ucic.cic);
11915             ast_mutex_lock(&p->lock);
11916             p->remotelyblocked = 1;
11917             p->inservice = 0;
11918             ast_mutex_unlock(&p->lock);         //doesn't require a SS7 acknowledgement
11919             break;
11920          case ISUP_EVENT_BLO:
11921             chanpos = ss7_find_cic(linkset, e->blo.cic, e->blo.opc);
11922             if (chanpos < 0) {
11923                ast_log(LOG_WARNING, "BLO on unconfigured CIC %d\n", e->blo.cic);
11924                break;
11925             }
11926             p = linkset->pvts[chanpos];
11927             ast_debug(1, "Blocking CIC %d\n", e->blo.cic);
11928             ast_mutex_lock(&p->lock);
11929             p->remotelyblocked = 1;
11930             ast_mutex_unlock(&p->lock);
11931             isup_bla(linkset->ss7, e->blo.cic, p->dpc);
11932             break;
11933          case ISUP_EVENT_BLA:
11934             chanpos = ss7_find_cic(linkset, e->bla.cic, e->bla.opc);
11935             if (chanpos < 0) {
11936                ast_log(LOG_WARNING, "BLA on unconfigured CIC %d\n", e->bla.cic);
11937                break;
11938             }
11939             ast_debug(1, "Blocking CIC %d\n", e->bla.cic);
11940             p = linkset->pvts[chanpos];
11941             ast_mutex_lock(&p->lock);
11942             p->locallyblocked = 1;
11943             ast_mutex_unlock(&p->lock);
11944             break;
11945          case ISUP_EVENT_UBL:
11946             chanpos = ss7_find_cic(linkset, e->ubl.cic, e->ubl.opc);
11947             if (chanpos < 0) {
11948                ast_log(LOG_WARNING, "UBL on unconfigured CIC %d\n", e->ubl.cic);
11949                break;
11950             }
11951             p = linkset->pvts[chanpos];
11952             ast_debug(1, "Unblocking CIC %d\n", e->ubl.cic);
11953             ast_mutex_lock(&p->lock);
11954             p->remotelyblocked = 0;
11955             ast_mutex_unlock(&p->lock);
11956             isup_uba(linkset->ss7, e->ubl.cic, p->dpc);
11957             break;
11958          case ISUP_EVENT_UBA:
11959             chanpos = ss7_find_cic(linkset, e->uba.cic, e->uba.opc);
11960             if (chanpos < 0) {
11961                ast_log(LOG_WARNING, "UBA on unconfigured CIC %d\n", e->uba.cic);
11962                break;
11963             }
11964             p = linkset->pvts[chanpos];
11965             ast_debug(1, "Unblocking CIC %d\n", e->uba.cic);
11966             ast_mutex_lock(&p->lock);
11967             p->locallyblocked = 0;
11968             ast_mutex_unlock(&p->lock);
11969             break;
11970          case ISUP_EVENT_CON:
11971          case ISUP_EVENT_ANM:
11972             if (e->e == ISUP_EVENT_CON)
11973                cic = e->con.cic;
11974             else
11975                cic = e->anm.cic;
11976 
11977             chanpos = ss7_find_cic(linkset, cic, (e->e == ISUP_EVENT_ANM) ? e->anm.opc : e->con.opc);
11978             if (chanpos < 0) {
11979                ast_log(LOG_WARNING, "ANM/CON on unconfigured CIC %d\n", cic);
11980                isup_rel(ss7, (e->e == ISUP_EVENT_ANM) ? e->anm.call : e->con.call, -1);
11981                break;
11982             } else {
11983                p = linkset->pvts[chanpos];
11984                ast_mutex_lock(&p->lock);
11985                p->subs[SUB_REAL].needanswer = 1;
11986                if (p->dsp && p->dsp_features) {
11987                   ast_dsp_set_features(p->dsp, p->dsp_features);
11988                   p->dsp_features = 0;
11989                }
11990                dahdi_enable_ec(p);
11991                ast_mutex_unlock(&p->lock);
11992             }
11993             break;
11994          case ISUP_EVENT_RLC:
11995             chanpos = ss7_find_cic(linkset, e->rlc.cic, e->rlc.opc);
11996             if (chanpos < 0) {
11997                ast_log(LOG_WARNING, "RLC on unconfigured CIC %d\n", e->rlc.cic);
11998                break;
11999             } else {
12000                p = linkset->pvts[chanpos];
12001                ast_mutex_lock(&p->lock);
12002                if (p->alreadyhungup)
12003                   p->ss7call = NULL;
12004                else
12005                   ast_log(LOG_NOTICE, "Received RLC out and we haven't sent REL.  Ignoring.\n");
12006                ast_mutex_unlock(&p->lock);
12007                }
12008                break;
12009          case ISUP_EVENT_FAA:
12010             chanpos = ss7_find_cic(linkset, e->faa.cic, e->faa.opc);
12011             if (chanpos < 0) {
12012                ast_log(LOG_WARNING, "FAA on unconfigured CIC %d\n", e->faa.cic);
12013                break;
12014             } else {
12015                p = linkset->pvts[chanpos];
12016                ast_debug(1, "FAA received on CIC %d\n", e->faa.cic);
12017                ast_mutex_lock(&p->lock);
12018                if (p->alreadyhungup){
12019                   p->ss7call = NULL;
12020                   ast_log(LOG_NOTICE, "Received FAA and we haven't sent FAR.  Ignoring.\n");
12021                }
12022                ast_mutex_unlock(&p->lock);
12023             }
12024             break;
12025          default:
12026             ast_debug(1, "Unknown event %s\n", ss7_event2str(e->e));
12027             break;
12028          }
12029       }
12030       ast_mutex_unlock(&linkset->lock);
12031    }
12032 
12033    return 0;
12034 }

static int ss7_pres_scr2cid_pres ( char  presentation_ind,
char  screening_ind 
) [static]

Definition at line 11498 of file chan_dahdi.c.

Referenced by ss7_linkset().

11499 {
11500    return ((presentation_ind & 0x3) << 5) | (screening_ind & 0x3);
11501 }

static void ss7_rel ( struct dahdi_ss7 *  ss7  )  [inline, static]

Definition at line 1451 of file chan_dahdi.c.

References ast_mutex_unlock(), and dahdi_ss7::lock.

Referenced by dahdi_answer(), dahdi_call(), dahdi_hangup(), and dahdi_indicate().

01452 {
01453    ast_mutex_unlock(&ss7->lock);
01454 }

static void ss7_reset_linkset ( struct dahdi_ss7 *  linkset  )  [static]

Definition at line 11307 of file chan_dahdi.c.

References ast_verbose, dahdi_pvt::cic, dahdi_pvt::dpc, dahdi_ss7::numchans, dahdi_ss7::pvts, and dahdi_ss7::ss7.

Referenced by ss7_linkset().

11308 {
11309    int i, startcic = -1, endcic, dpc;
11310 
11311    if (linkset->numchans <= 0)
11312       return;
11313 
11314    startcic = linkset->pvts[0]->cic;
11315    /* DB: CIC's DPC fix */
11316    dpc = linkset->pvts[0]->dpc;
11317 
11318    for (i = 0; i < linkset->numchans; i++) {
11319       if (linkset->pvts[i+1] && linkset->pvts[i+1]->dpc == dpc && ((linkset->pvts[i+1]->cic - linkset->pvts[i]->cic) == 1) && (linkset->pvts[i]->cic - startcic < 31)) {
11320          continue;
11321       } else {
11322          endcic = linkset->pvts[i]->cic;
11323          ast_verbose("Resetting CICs %d to %d\n", startcic, endcic);
11324          isup_grs(linkset->ss7, startcic, endcic, dpc);
11325 
11326          /* DB: CIC's DPC fix */
11327          if (linkset->pvts[i+1]) {
11328             startcic = linkset->pvts[i+1]->cic;
11329             dpc = linkset->pvts[i+1]->dpc;
11330          }
11331       }
11332    }
11333 }

static struct dahdi_ss7* ss7_resolve_linkset ( int  linkset  )  [static, read]

Definition at line 9978 of file chan_dahdi.c.

References linksets, and NUM_SPANS.

Referenced by linkset_addsigchan(), mkintf(), and process_dahdi().

09979 {
09980    if ((linkset < 0) || (linkset >= NUM_SPANS))
09981       return NULL;
09982    else
09983       return &linksets[linkset - 1];
09984 }

static void ss7_start_call ( struct dahdi_pvt *  p,
struct dahdi_ss7 *  linkset 
) [static]

Definition at line 11351 of file chan_dahdi.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_RING, ast_strlen_zero(), ast_verb, dahdi_pvt::call_ref_ident, dahdi_pvt::call_ref_pc, dahdi_pvt::calling_party_cat, dahdi_pvt::channel, dahdi_pvt::charge_number, dahdi_pvt::cic, dahdi_enable_ec(), dahdi_new(), dahdi_setlaw(), dahdi_subchannel::dfd, errno, dahdi_pvt::exten, dahdi_ss7::flags, dahdi_pvt::gen_add_number, dahdi_pvt::gen_dig_number, dahdi_pvt::gen_dig_scheme, dahdi_pvt::gen_dig_type, dahdi_pvt::generic_name, dahdi_pvt::jip_number, LINKSET_FLAG_EXPLICITACM, dahdi_pvt::lock, dahdi_ss7::lock, LOG_WARNING, dahdi_pvt::lspi_ident, dahdi_pvt::orig_called_num, pbx_builtin_setvar_helper(), dahdi_pvt::proceeding, dahdi_pvt::redirecting_num, dahdi_ss7::ss7, dahdi_pvt::ss7call, SUB_REAL, dahdi_pvt::subs, and dahdi_ss7::type.

Referenced by ss7_linkset().

11352 {
11353    struct ss7 *ss7 = linkset->ss7;
11354    int res;
11355    int law = 1;
11356    struct ast_channel *c;
11357    char tmp[256];
11358 
11359    if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &law) == -1)
11360       ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n", p->channel, law, strerror(errno));
11361 
11362    if (linkset->type == SS7_ITU)
11363       law = DAHDI_LAW_ALAW;
11364    else
11365       law = DAHDI_LAW_MULAW;
11366 
11367    res = dahdi_setlaw(p->subs[SUB_REAL].dfd, law);
11368    if (res < 0)
11369       ast_log(LOG_WARNING, "Unable to set law on channel %d\n", p->channel);
11370 
11371    if (!(linkset->flags & LINKSET_FLAG_EXPLICITACM)) {
11372       p->proceeding = 1;
11373       isup_acm(ss7, p->ss7call);
11374    }
11375 
11376    ast_mutex_unlock(&linkset->lock);
11377    c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, law, 0);
11378 
11379    if (!c) {
11380       ast_log(LOG_WARNING, "Unable to start PBX on CIC %d\n", p->cic);
11381       /* Holding this lock is assumed entering the function */
11382       ast_mutex_lock(&linkset->lock);
11383       return;
11384    } else
11385       ast_verb(3, "Accepting call to '%s' on CIC %d\n", p->exten, p->cic);
11386 
11387    dahdi_enable_ec(p);
11388 
11389    /* We only reference these variables in the context of the ss7_linkset function
11390     * when receiving either and IAM or a COT message.  Since they are only accessed
11391     * from this context, we should be safe to unlock around them */
11392 
11393    ast_mutex_unlock(&p->lock);
11394 
11395    if (!ast_strlen_zero(p->charge_number)) {
11396       pbx_builtin_setvar_helper(c, "SS7_CHARGE_NUMBER", p->charge_number);
11397       /* Clear this after we set it */
11398       p->charge_number[0] = 0;
11399    }
11400    if (!ast_strlen_zero(p->gen_add_number)) {
11401       pbx_builtin_setvar_helper(c, "SS7_GENERIC_ADDRESS", p->gen_add_number);
11402       /* Clear this after we set it */
11403       p->gen_add_number[0] = 0;
11404    }
11405    if (!ast_strlen_zero(p->jip_number)) {
11406       pbx_builtin_setvar_helper(c, "SS7_JIP", p->jip_number);
11407       /* Clear this after we set it */
11408       p->jip_number[0] = 0;
11409    }
11410    if (!ast_strlen_zero(p->gen_dig_number)) {
11411       pbx_builtin_setvar_helper(c, "SS7_GENERIC_DIGITS", p->gen_dig_number);
11412       /* Clear this after we set it */
11413       p->gen_dig_number[0] = 0;
11414    }
11415    if (!ast_strlen_zero(p->orig_called_num)) {
11416       pbx_builtin_setvar_helper(c, "SS7_ORIG_CALLED_NUM", p->orig_called_num);
11417       /* Clear this after we set it */
11418       p->orig_called_num[0] = 0;
11419    }
11420 
11421    snprintf(tmp, sizeof(tmp), "%d", p->gen_dig_type);
11422    pbx_builtin_setvar_helper(c, "SS7_GENERIC_DIGTYPE", tmp);
11423    /* Clear this after we set it */
11424    p->gen_dig_type = 0;
11425 
11426    snprintf(tmp, sizeof(tmp), "%d", p->gen_dig_scheme);
11427    pbx_builtin_setvar_helper(c, "SS7_GENERIC_DIGSCHEME", tmp);
11428    /* Clear this after we set it */
11429    p->gen_dig_scheme = 0;
11430 
11431    if (!ast_strlen_zero(p->lspi_ident)) {
11432       pbx_builtin_setvar_helper(c, "SS7_LSPI_IDENT", p->lspi_ident);
11433       /* Clear this after we set it */
11434       p->lspi_ident[0] = 0;
11435    }
11436 
11437    snprintf(tmp, sizeof(tmp), "%d", p->call_ref_ident);
11438    pbx_builtin_setvar_helper(c, "SS7_CALLREF_IDENT", tmp);
11439    /* Clear this after we set it */
11440    p->call_ref_ident = 0;
11441 
11442    snprintf(tmp, sizeof(tmp), "%d", p->call_ref_pc);
11443    pbx_builtin_setvar_helper(c, "SS7_CALLREF_PC", tmp);
11444    /* Clear this after we set it */
11445    p->call_ref_pc = 0;
11446 
11447    snprintf(tmp, sizeof(tmp), "%d", p->calling_party_cat);
11448    pbx_builtin_setvar_helper(c, "SS7_CALLING_PARTY_CATEGORY", tmp);
11449    /* Clear this after we set it */
11450    p->calling_party_cat = 0;
11451 
11452    if (!ast_strlen_zero(p->redirecting_num)) {
11453       pbx_builtin_setvar_helper(c, "SS7_REDIRECTING_NUMBER", p->redirecting_num);
11454       /* Clear this after we set it */
11455       p->redirecting_num[0] = 0;
11456    }
11457    if (!ast_strlen_zero(p->generic_name)) {
11458       pbx_builtin_setvar_helper(c, "SS7_GENERIC_NAME", p->generic_name);
11459       /* Clear this after we set it */
11460       p->generic_name[0] = 0;
11461    }
11462 
11463    ast_mutex_lock(&p->lock);
11464    ast_mutex_lock(&linkset->lock);
11465 }

static void * ss_thread ( void *  data  )  [static]

Definition at line 7752 of file chan_dahdi.c.

References ast_channel::_state, alloc_sub(), ARRAY_LEN, ast_bridged_channel(), ast_canmatch_extension(), AST_CAUSE_UNALLOCATED, ast_clear_flag, ast_cond_signal(), AST_CONTROL_RING, AST_CONTROL_UNHOLD, ast_copy_string(), ast_db_put(), ast_debug, ast_dsp_digitreset(), ast_dsp_free(), ast_dsp_set_digitmode(), ast_exists_extension(), AST_FLAG_END_DTMF_ONLY, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_free, ast_frfree, ast_hangup(), ast_ignore_pattern(), AST_LAW, ast_log(), ast_masq_park_call(), ast_matchmore_extension(), AST_MAX_EXTENSION, ast_mutex_lock(), ast_mutex_unlock(), ast_parking_ext(), ast_pbx_run(), ast_pickup_call(), ast_pickup_ext(), ast_queue_control(), ast_read(), ast_safe_sleep(), ast_say_digit_str(), ast_set_callerid(), ast_set_flag, ast_setstate(), ast_shrink_phone_number(), ast_smdi_md_message_destroy(), ast_smdi_md_message_wait(), AST_STATE_PRERING, AST_STATE_RING, AST_STATE_RINGING, ast_streamfile(), ast_strlen_zero(), ast_verb, ast_waitfor(), ast_waitfordigit(), ast_waitstream(), ASTOBJ_UNREF, buf, bump_gains(), dahdi_pvt::call, dahdi_pvt::call_forward, callerid_feed(), callerid_feed_jp(), callerid_free(), callerid_get(), callerid_get_dtmf(), callerid_new(), ast_smdi_md_message::calling_st, dahdi_pvt::callreturn, dahdi_pvt::callwaiting, dahdi_pvt::cancallforward, dahdi_pvt::canpark, dahdi_pvt::channel, ast_channel::cid, CID_MSGWAITING, ast_callerid::cid_name, dahdi_pvt::cid_name, CID_NOMSGWAITING, ast_callerid::cid_num, dahdi_pvt::cid_num, CID_SIG_DTMF, CID_SIG_SMDI, CID_SIG_V23, CID_SIG_V23_JP, dahdi_pvt::cid_signalling, dahdi_pvt::cid_start, CID_START_POLARITY, CID_START_POLARITY_IN, CID_START_RING, dahdi_pvt::context, ast_channel::context, ringContextData::contextData, dahdi_dnd(), dahdi_enable_ec(), dahdi_get_event(), dahdi_get_index(), DAHDI_OVERLAPDIAL_INCOMING, dahdi_set_hook(), dahdi_setlinear(), dahdi_wait_event(), dahdi_wink(), dahdi_pvt::defcontext, dahdi_subchannel::dfd, dahdi_pvt::dop, dahdi_pvt::drings, dahdi_pvt::dsp, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, dahdi_pvt::dtmfrelax, errno, event2str(), ast_channel::exten, dahdi_pvt::exten, exten, f, ast_frame::frametype, ast_smdi_md_message::fwd_st, ast_channel::hangupcause, dahdi_pvt::hanguponpolarityswitch, dahdi_pvt::hardwaredtmf, dahdi_pvt::hidecallerid, dahdi_pvt::immediate, dahdi_pvt::inalarm, ISTRUNK, ast_channel::language, dahdi_pvt::lastcid_num, len(), dahdi_subchannel::linear, dahdi_pvt::lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, dahdi_pvt::mailbox, dahdi_pvt::mwimonitor_rpas, my_getsigstr(), ast_channel::name, name, NEED_MFDETECT, notify_message(), dahdi_pri::overlapdial, dahdi_pvt::owner, dahdi_subchannel::owner, pbx_builtin_setvar_helper(), dahdi_pvt::polarity, POLARITY_IDLE, POLARITY_REV, dahdi_pri::pri, dahdi_pvt::pri, pri_grab(), pri_rel(), dahdi_pvt::proceeding, PVT_TO_CHANNEL, quit, distRingData::range, restore_gains(), distRingData::ring, dahdi_distRings::ringContext, dahdi_distRings::ringnum, ast_channel::rings, dahdi_pvt::ringt, dahdi_pvt::ringt_base, dahdi_pvt::sig, sig2str, SIG_BRI, SIG_BRI_PTMP, SIG_E911, SIG_EM, SIG_EM_E1, SIG_EMWINK, SIG_FEATB, SIG_FEATD, SIG_FEATDMF, SIG_FEATDMF_TA, SIG_FGC_CAMA, SIG_FGC_CAMAMF, SIG_FXOGS, SIG_FXOKS, SIG_FXOLS, SIG_FXSGS, SIG_FXSKS, SIG_FXSLS, SIG_PRI, SIG_SF, SIG_SF_FEATB, SIG_SF_FEATD, SIG_SF_FEATDMF, SIG_SFWINK, dahdi_pvt::smdi_iface, SMDI_MD_WAIT_TIMEOUT, dahdi_pvt::span, ss_thread_lock, strsep(), SUB_CALLWAIT, SUB_REAL, SUB_THREEWAY, ast_frame::subclass, dahdi_pvt::subs, swap_subs(), ast_channel::tech, ast_channel::tech_pvt, dahdi_pvt::transfer, ast_smdi_md_message::type, unalloc_sub(), dahdi_pvt::use_callerid, dahdi_pvt::use_smdi, and dahdi_pvt::usedistinctiveringdetection.

Referenced by dahdi_handle_event(), handle_init_event(), mwi_thread(), and pri_dchannel().

07753 {
07754    struct ast_channel *chan = data;
07755    struct dahdi_pvt *p = chan->tech_pvt;
07756    char exten[AST_MAX_EXTENSION] = "";
07757    char exten2[AST_MAX_EXTENSION] = "";
07758    unsigned char buf[256];
07759    char dtmfcid[300];
07760    char dtmfbuf[300];
07761    struct callerid_state *cs = NULL;
07762    char *name = NULL, *number = NULL;
07763    int distMatches;
07764    int curRingData[3];
07765    int receivedRingT;
07766    int counter1;
07767    int counter;
07768    int samples = 0;
07769    struct ast_smdi_md_message *smdi_msg = NULL;
07770    int flags = 0;
07771    int i;
07772    int timeout;
07773    int getforward = 0;
07774    char *s1, *s2;
07775    int len = 0;
07776    int res;
07777    int idx;
07778 
07779    ast_mutex_lock(&ss_thread_lock);
07780    ss_thread_count++;
07781    ast_mutex_unlock(&ss_thread_lock);
07782    /* in the bizarre case where the channel has become a zombie before we
07783       even get started here, abort safely
07784    */
07785    if (!p) {
07786       ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", chan->name);
07787       ast_hangup(chan);
07788       goto quit;
07789    }
07790    ast_verb(3, "Starting simple switch on '%s'\n", chan->name);
07791    idx = dahdi_get_index(chan, p, 1);
07792    if (idx < 0) {
07793       ast_log(LOG_WARNING, "Huh?\n");
07794       ast_hangup(chan);
07795       goto quit;
07796    }
07797    if (p->dsp)
07798       ast_dsp_digitreset(p->dsp);
07799    switch (p->sig) {
07800 #ifdef HAVE_PRI
07801    case SIG_PRI:
07802    case SIG_BRI:
07803    case SIG_BRI_PTMP:
07804       /* Now loop looking for an extension */
07805       ast_copy_string(exten, p->exten, sizeof(exten));
07806       len = strlen(exten);
07807       res = 0;
07808       while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
07809          if (len && !ast_ignore_pattern(chan->context, exten))
07810             tone_zone_play_tone(p->subs[idx].dfd, -1);
07811          else
07812             tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALTONE);
07813          if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num))
07814             timeout = matchdigittimeout;
07815          else
07816             timeout = gendigittimeout;
07817          res = ast_waitfordigit(chan, timeout);
07818          if (res < 0) {
07819             ast_debug(1, "waitfordigit returned < 0...\n");
07820             ast_hangup(chan);
07821             goto quit;
07822          } else if (res) {
07823             exten[len++] = res;
07824             exten[len] = '\0';
07825          } else
07826             break;
07827       }
07828       /* if no extension was received ('unspecified') on overlap call, use the 's' extension */
07829       if (ast_strlen_zero(exten)) {
07830          ast_verb(3, "Going to extension s|1 because of empty extension received on overlap call\n");
07831          exten[0] = 's';
07832          exten[1] = '\0';
07833       }
07834       tone_zone_play_tone(p->subs[idx].dfd, -1);
07835       if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) {
07836          /* Start the real PBX */
07837          ast_copy_string(chan->exten, exten, sizeof(chan->exten));
07838          if (p->dsp) {
07839             ast_dsp_digitreset(p->dsp);
07840          }
07841          if (p->pri->overlapdial & DAHDI_OVERLAPDIAL_INCOMING) {
07842             ast_mutex_lock(&p->lock);
07843             if (p->pri->pri) {      
07844                if (!pri_grab(p, p->pri)) {
07845                   pri_proceeding(p->pri->pri, p->call, PVT_TO_CHANNEL(p), 0);
07846                   p->proceeding = 1;
07847                   pri_rel(p->pri);
07848                } else {
07849                   ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
07850                }
07851             }
07852             ast_mutex_unlock(&p->lock);
07853          }
07854          dahdi_enable_ec(p);
07855          ast_setstate(chan, AST_STATE_RING);
07856          res = ast_pbx_run(chan);
07857          if (res) {
07858             ast_log(LOG_WARNING, "PBX exited non-zero!\n");
07859          }
07860       } else {
07861          ast_debug(1, "No such possible extension '%s' in context '%s'\n", exten, chan->context);
07862          chan->hangupcause = AST_CAUSE_UNALLOCATED;
07863          ast_hangup(chan);
07864          p->exten[0] = '\0';
07865          /* Since we send release complete here, we won't get one */
07866          p->call = NULL;
07867       }
07868       goto quit;
07869       break;
07870 #endif
07871    case SIG_FEATD:
07872    case SIG_FEATDMF:
07873    case SIG_FEATDMF_TA:
07874    case SIG_E911:
07875    case SIG_FGC_CAMAMF:
07876    case SIG_FEATB:
07877    case SIG_EMWINK:
07878    case SIG_SF_FEATD:
07879    case SIG_SF_FEATDMF:
07880    case SIG_SF_FEATB:
07881    case SIG_SFWINK:
07882       if (dahdi_wink(p, idx))
07883          goto quit;
07884       /* Fall through */
07885    case SIG_EM:
07886    case SIG_EM_E1:
07887    case SIG_SF:
07888    case SIG_FGC_CAMA:
07889       res = tone_zone_play_tone(p->subs[idx].dfd, -1);
07890       if (p->dsp)
07891          ast_dsp_digitreset(p->dsp);
07892       /* set digit mode appropriately */
07893       if (p->dsp) {
07894          if (NEED_MFDETECT(p))
07895             ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
07896          else
07897             ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
07898       }
07899       memset(dtmfbuf, 0, sizeof(dtmfbuf));
07900       /* Wait for the first digit only if immediate=no */
07901       if (!p->immediate)
07902          /* Wait for the first digit (up to 5 seconds). */
07903          res = ast_waitfordigit(chan, 5000);
07904       else
07905          res = 0;
07906       if (res > 0) {
07907          /* save first char */
07908          dtmfbuf[0] = res;
07909          switch (p->sig) {
07910          case SIG_FEATD:
07911          case SIG_SF_FEATD:
07912             res = my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
07913             if (res > 0)
07914                res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
07915             if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
07916             break;
07917          case SIG_FEATDMF_TA:
07918             res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
07919             if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
07920             if (dahdi_wink(p, idx)) goto quit;
07921             dtmfbuf[0] = 0;
07922             /* Wait for the first digit (up to 5 seconds). */
07923             res = ast_waitfordigit(chan, 5000);
07924             if (res <= 0) break;
07925             dtmfbuf[0] = res;
07926             /* fall through intentionally */
07927          case SIG_FEATDMF:
07928          case SIG_E911:
07929          case SIG_FGC_CAMAMF:
07930          case SIG_SF_FEATDMF:
07931             res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
07932             /* if international caca, do it again to get real ANO */
07933             if ((p->sig == SIG_FEATDMF) && (dtmfbuf[1] != '0') && (strlen(dtmfbuf) != 14))
07934             {
07935                if (dahdi_wink(p, idx)) goto quit;
07936                dtmfbuf[0] = 0;
07937                /* Wait for the first digit (up to 5 seconds). */
07938                res = ast_waitfordigit(chan, 5000);
07939                if (res <= 0) break;
07940                dtmfbuf[0] = res;
07941                res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
07942             }
07943             if (res > 0) {
07944                /* if E911, take off hook */
07945                if (p->sig == SIG_E911)
07946                   dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
07947                res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
07948             }
07949             if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
07950             break;
07951          case SIG_FEATB:
07952          case SIG_SF_FEATB:
07953             res = my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
07954             if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
07955             break;
07956          case SIG_EMWINK:
07957             /* if we received a '*', we are actually receiving Feature Group D
07958                dial syntax, so use that mode; otherwise, fall through to normal
07959                mode
07960             */
07961             if (res == '*') {
07962                res = my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
07963                if (res > 0)
07964                   res = my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
07965                if ((res < 1) && (p->dsp)) ast_dsp_digitreset(p->dsp);
07966                break;
07967             }
07968          default:
07969             /* If we got the first digit, get the rest */
07970             len = 1;
07971             dtmfbuf[len] = '\0';
07972             while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
07973                if (ast_exists_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
07974                   timeout = matchdigittimeout;
07975                } else {
07976                   timeout = gendigittimeout;
07977                }
07978                res = ast_waitfordigit(chan, timeout);
07979                if (res < 0) {
07980                   ast_debug(1, "waitfordigit returned < 0...\n");
07981                   ast_hangup(chan);
07982                   goto quit;
07983                } else if (res) {
07984                   dtmfbuf[len++] = res;
07985                   dtmfbuf[len] = '\0';
07986                } else {
07987                   break;
07988                }
07989             }
07990             break;
07991          }
07992       }
07993       if (res == -1) {
07994          ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
07995          ast_hangup(chan);
07996          goto quit;
07997       } else if (res < 0) {
07998          ast_debug(1, "Got hung up before digits finished\n");
07999          ast_hangup(chan);
08000          goto quit;
08001       }
08002 
08003       if (p->sig == SIG_FGC_CAMA) {
08004          char anibuf[100];
08005 
08006          if (ast_safe_sleep(chan,1000) == -1) {
08007             ast_hangup(chan);
08008             goto quit;
08009          }
08010          dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
08011          ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
08012          res = my_getsigstr(chan, anibuf, "#", 10000);
08013          if ((res > 0) && (strlen(anibuf) > 2)) {
08014             if (anibuf[strlen(anibuf) - 1] == '#')
08015                anibuf[strlen(anibuf) - 1] = 0;
08016             ast_set_callerid(chan, anibuf + 2, NULL, anibuf + 2);
08017          }
08018          ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
08019       }
08020 
08021       ast_copy_string(exten, dtmfbuf, sizeof(exten));
08022       if (ast_strlen_zero(exten))
08023          ast_copy_string(exten, "s", sizeof(exten));
08024       if (p->sig == SIG_FEATD || p->sig == SIG_EMWINK) {
08025          /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
08026          if (exten[0] == '*') {
08027             char *stringp=NULL;
08028             ast_copy_string(exten2, exten, sizeof(exten2));
08029             /* Parse out extension and callerid */
08030             stringp=exten2 +1;
08031             s1 = strsep(&stringp, "*");
08032             s2 = strsep(&stringp, "*");
08033             if (s2) {
08034                if (!ast_strlen_zero(p->cid_num))
08035                   ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
08036                else
08037                   ast_set_callerid(chan, s1, NULL, s1);
08038                ast_copy_string(exten, s2, sizeof(exten));
08039             } else
08040                ast_copy_string(exten, s1, sizeof(exten));
08041          } else if (p->sig == SIG_FEATD)
08042             ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d.  Assuming E&M Wink instead\n", p->channel);
08043       }
08044       if ((p->sig == SIG_FEATDMF) || (p->sig == SIG_FEATDMF_TA)) {
08045          if (exten[0] == '*') {
08046             char *stringp=NULL;
08047             ast_copy_string(exten2, exten, sizeof(exten2));
08048             /* Parse out extension and callerid */
08049             stringp=exten2 +1;
08050             s1 = strsep(&stringp, "#");
08051             s2 = strsep(&stringp, "#");
08052             if (s2) {
08053                if (!ast_strlen_zero(p->cid_num))
08054                   ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
08055                else
08056                   if (*(s1 + 2))
08057                      ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
08058                ast_copy_string(exten, s2 + 1, sizeof(exten));
08059             } else
08060                ast_copy_string(exten, s1 + 2, sizeof(exten));
08061          } else
08062             ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d.  Assuming E&M Wink instead\n", p->channel);
08063       }
08064       if ((p->sig == SIG_E911) || (p->sig == SIG_FGC_CAMAMF)) {
08065          if (exten[0] == '*') {
08066             char *stringp=NULL;
08067             ast_copy_string(exten2, exten, sizeof(exten2));
08068             /* Parse out extension and callerid */
08069             stringp=exten2 +1;
08070             s1 = strsep(&stringp, "#");
08071             s2 = strsep(&stringp, "#");
08072             if (s2 && (*(s2 + 1) == '0')) {
08073                if (*(s2 + 2))
08074                   ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
08075             }
08076             if (s1)  ast_copy_string(exten, s1, sizeof(exten));
08077             else ast_copy_string(exten, "911", sizeof(exten));
08078          } else
08079             ast_log(LOG_WARNING, "Got a non-E911/FGC CAMA input on channel %d.  Assuming E&M Wink instead\n", p->channel);
08080       }
08081       if (p->sig == SIG_FEATB) {
08082          if (exten[0] == '*') {
08083             char *stringp=NULL;
08084             ast_copy_string(exten2, exten, sizeof(exten2));
08085             /* Parse out extension and callerid */
08086             stringp=exten2 +1;
08087             s1 = strsep(&stringp, "#");
08088             ast_copy_string(exten, exten2 + 1, sizeof(exten));
08089          } else
08090             ast_log(LOG_WARNING, "Got a non-Feature Group B input on channel %d.  Assuming E&M Wink instead\n", p->channel);
08091       }
08092       if ((p->sig == SIG_FEATDMF) || (p->sig == SIG_FEATDMF_TA)) {
08093          dahdi_wink(p, idx);
08094          /* some switches require a minimum guard time between
08095             the last FGD wink and something that answers
08096             immediately. This ensures it */
08097          if (ast_safe_sleep(chan,100)) goto quit;
08098       }
08099       dahdi_enable_ec(p);
08100       if (NEED_MFDETECT(p)) {
08101          if (p->dsp) {
08102             if (!p->hardwaredtmf)
08103                ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
08104             else {
08105                ast_dsp_free(p->dsp);
08106                p->dsp = NULL;
08107             }
08108          }
08109       }
08110 
08111       if (ast_exists_extension(chan, chan->context, exten, 1, chan->cid.cid_num)) {
08112          ast_copy_string(chan->exten, exten, sizeof(chan->exten));
08113          if (p->dsp) ast_dsp_digitreset(p->dsp);
08114          res = ast_pbx_run(chan);
08115          if (res) {
08116             ast_log(LOG_WARNING, "PBX exited non-zero\n");
08117             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08118          }
08119          goto quit;
08120       } else {
08121          ast_verb(2, "Unknown extension '%s' in context '%s' requested\n", exten, chan->context);
08122          sleep(2);
08123          res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_INFO);
08124          if (res < 0)
08125             ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
08126          else
08127             sleep(1);
08128          res = ast_streamfile(chan, "ss-noservice", chan->language);
08129          if (res >= 0)
08130             ast_waitstream(chan, "");
08131          res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08132          ast_hangup(chan);
08133          goto quit;
08134       }
08135       break;
08136    case SIG_FXOLS:
08137    case SIG_FXOGS:
08138    case SIG_FXOKS:
08139       /* Read the first digit */
08140       timeout = firstdigittimeout;
08141       /* If starting a threeway call, never timeout on the first digit so someone
08142          can use flash-hook as a "hold" feature */
08143       if (p->subs[SUB_THREEWAY].owner)
08144          timeout = 999999;
08145       while (len < AST_MAX_EXTENSION-1) {
08146          /* Read digit unless it's supposed to be immediate, in which case the
08147             only answer is 's' */
08148          if (p->immediate)
08149             res = 's';
08150          else
08151             res = ast_waitfordigit(chan, timeout);
08152          timeout = 0;
08153          if (res < 0) {
08154             ast_debug(1, "waitfordigit returned < 0...\n");
08155             res = tone_zone_play_tone(p->subs[idx].dfd, -1);
08156             ast_hangup(chan);
08157             goto quit;
08158          } else if (res) {
08159             ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
08160             exten[len++]=res;
08161             exten[len] = '\0';
08162          }
08163          if (!ast_ignore_pattern(chan->context, exten))
08164             tone_zone_play_tone(p->subs[idx].dfd, -1);
08165          else
08166             tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALTONE);
08167          if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num) && strcmp(exten, ast_parking_ext())) {
08168             if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
08169                if (getforward) {
08170                   /* Record this as the forwarding extension */
08171                   ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
08172                   ast_verb(3, "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
08173                   res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08174                   if (res)
08175                      break;
08176                   usleep(500000);
08177                   res = tone_zone_play_tone(p->subs[idx].dfd, -1);
08178                   sleep(1);
08179                   memset(exten, 0, sizeof(exten));
08180                   res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALTONE);
08181                   len = 0;
08182                   getforward = 0;
08183                } else {
08184                   res = tone_zone_play_tone(p->subs[idx].dfd, -1);
08185                   ast_copy_string(chan->exten, exten, sizeof(chan->exten));
08186                   if (!ast_strlen_zero(p->cid_num)) {
08187                      if (!p->hidecallerid)
08188                         ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
08189                      else
08190                         ast_set_callerid(chan, NULL, NULL, p->cid_num);
08191                   }
08192                   if (!ast_strlen_zero(p->cid_name)) {
08193                      if (!p->hidecallerid)
08194                         ast_set_callerid(chan, NULL, p->cid_name, NULL);
08195                   }
08196                   ast_setstate(chan, AST_STATE_RING);
08197                   dahdi_enable_ec(p);
08198                   res = ast_pbx_run(chan);
08199                   if (res) {
08200                      ast_log(LOG_WARNING, "PBX exited non-zero\n");
08201                      res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08202                   }
08203                   goto quit;
08204                }
08205             } else {
08206                /* It's a match, but they just typed a digit, and there is an ambiguous match,
08207                   so just set the timeout to matchdigittimeout and wait some more */
08208                timeout = matchdigittimeout;
08209             }
08210          } else if (res == 0) {
08211             ast_debug(1, "not enough digits (and no ambiguous match)...\n");
08212             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08213             dahdi_wait_event(p->subs[idx].dfd);
08214             ast_hangup(chan);
08215             goto quit;
08216          } else if (p->callwaiting && !strcmp(exten, "*70")) {
08217             ast_verb(3, "Disabling call waiting on %s\n", chan->name);
08218             /* Disable call waiting if enabled */
08219             p->callwaiting = 0;
08220             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08221             if (res) {
08222                ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
08223                   chan->name, strerror(errno));
08224             }
08225             len = 0;
08226             ioctl(p->subs[idx].dfd,DAHDI_CONFDIAG,&len);
08227             memset(exten, 0, sizeof(exten));
08228             timeout = firstdigittimeout;
08229 
08230          } else if (!strcmp(exten,ast_pickup_ext())) {
08231             /* Scan all channels and see if there are any
08232              * ringing channels that have call groups
08233              * that equal this channels pickup group
08234              */
08235             if (idx == SUB_REAL) {
08236                /* Switch us from Third call to Call Wait */
08237                if (p->subs[SUB_THREEWAY].owner) {
08238                   /* If you make a threeway call and the *8# a call, it should actually
08239                      look like a callwait */
08240                   alloc_sub(p, SUB_CALLWAIT);
08241                   swap_subs(p, SUB_CALLWAIT, SUB_THREEWAY);
08242                   unalloc_sub(p, SUB_THREEWAY);
08243                }
08244                dahdi_enable_ec(p);
08245                if (ast_pickup_call(chan)) {
08246                   ast_debug(1, "No call pickup possible...\n");
08247                   res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08248                   dahdi_wait_event(p->subs[idx].dfd);
08249                }
08250                ast_hangup(chan);
08251                goto quit;
08252             } else {
08253                ast_log(LOG_WARNING, "Huh?  Got *8# on call not on real\n");
08254                ast_hangup(chan);
08255                goto quit;
08256             }
08257 
08258          } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
08259             ast_verb(3, "Disabling Caller*ID on %s\n", chan->name);
08260             /* Disable Caller*ID if enabled */
08261             p->hidecallerid = 1;
08262             if (chan->cid.cid_num)
08263                ast_free(chan->cid.cid_num);
08264             chan->cid.cid_num = NULL;
08265             if (chan->cid.cid_name)
08266                ast_free(chan->cid.cid_name);
08267             chan->cid.cid_name = NULL;
08268             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08269             if (res) {
08270                ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
08271                   chan->name, strerror(errno));
08272             }
08273             len = 0;
08274             memset(exten, 0, sizeof(exten));
08275             timeout = firstdigittimeout;
08276          } else if (p->callreturn && !strcmp(exten, "*69")) {
08277             res = 0;
08278             if (!ast_strlen_zero(p->lastcid_num)) {
08279                res = ast_say_digit_str(chan, p->lastcid_num, "", chan->language);
08280             }
08281             if (!res)
08282                res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08283             break;
08284          } else if (!strcmp(exten, "*78")) {
08285             dahdi_dnd(p, 1);
08286             /* Do not disturb */
08287             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08288             getforward = 0;
08289             memset(exten, 0, sizeof(exten));
08290             len = 0;
08291          } else if (!strcmp(exten, "*79")) {
08292             dahdi_dnd(p, 0);
08293             /* Do not disturb */
08294             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08295             getforward = 0;
08296             memset(exten, 0, sizeof(exten));
08297             len = 0;
08298          } else if (p->cancallforward && !strcmp(exten, "*72")) {
08299             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08300             getforward = 1;
08301             memset(exten, 0, sizeof(exten));
08302             len = 0;
08303          } else if (p->cancallforward && !strcmp(exten, "*73")) {
08304             ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
08305             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08306             memset(p->call_forward, 0, sizeof(p->call_forward));
08307             getforward = 0;
08308             memset(exten, 0, sizeof(exten));
08309             len = 0;
08310          } else if ((p->transfer || p->canpark) && !strcmp(exten, ast_parking_ext()) &&
08311                   p->subs[SUB_THREEWAY].owner &&
08312                   ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
08313             /* This is a three way call, the main call being a real channel,
08314                and we're parking the first call. */
08315             ast_masq_park_call(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), chan, 0, NULL);
08316             ast_verb(3, "Parking call to '%s'\n", chan->name);
08317             break;
08318          } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
08319             ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
08320             res = ast_db_put("blacklist", p->lastcid_num, "1");
08321             if (!res) {
08322                res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08323                memset(exten, 0, sizeof(exten));
08324                len = 0;
08325             }
08326          } else if (p->hidecallerid && !strcmp(exten, "*82")) {
08327             ast_verb(3, "Enabling Caller*ID on %s\n", chan->name);
08328             /* Enable Caller*ID if enabled */
08329             p->hidecallerid = 0;
08330             if (chan->cid.cid_num)
08331                ast_free(chan->cid.cid_num);
08332             chan->cid.cid_num = NULL;
08333             if (chan->cid.cid_name)
08334                ast_free(chan->cid.cid_name);
08335             chan->cid.cid_name = NULL;
08336             ast_set_callerid(chan, p->cid_num, p->cid_name, NULL);
08337             res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
08338             if (res) {
08339                ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
08340                   chan->name, strerror(errno));
08341             }
08342             len = 0;
08343             memset(exten, 0, sizeof(exten));
08344             timeout = firstdigittimeout;
08345          } else if (!strcmp(exten, "*0")) {
08346             struct ast_channel *nbridge =
08347                p->subs[SUB_THREEWAY].owner;
08348             struct dahdi_pvt *pbridge = NULL;
08349             /* set up the private struct of the bridged one, if any */
08350             if (nbridge && ast_bridged_channel(nbridge))
08351                pbridge = ast_bridged_channel(nbridge)->tech_pvt;
08352             if (nbridge && pbridge &&
08353                (nbridge->tech == &dahdi_tech) &&
08354                (ast_bridged_channel(nbridge)->tech == &dahdi_tech) &&
08355                ISTRUNK(pbridge)) {
08356                int func = DAHDI_FLASH;
08357                /* Clear out the dial buffer */
08358                p->dop.dialstr[0] = '\0';
08359                /* flash hookswitch */
08360                if ((ioctl(pbridge->subs[SUB_REAL].dfd,DAHDI_HOOK,&func) == -1) && (errno != EINPROGRESS)) {
08361                   ast_log(LOG_WARNING, "Unable to flash external trunk on channel %s: %s\n",
08362                      nbridge->name, strerror(errno));
08363                }
08364                swap_subs(p, SUB_REAL, SUB_THREEWAY);
08365                unalloc_sub(p, SUB_THREEWAY);
08366                p->owner = p->subs[SUB_REAL].owner;
08367                if (ast_bridged_channel(p->subs[SUB_REAL].owner))
08368                   ast_queue_control(p->subs[SUB_REAL].owner, AST_CONTROL_UNHOLD);
08369                ast_hangup(chan);
08370                goto quit;
08371             } else {
08372                tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08373                dahdi_wait_event(p->subs[idx].dfd);
08374                tone_zone_play_tone(p->subs[idx].dfd, -1);
08375                swap_subs(p, SUB_REAL, SUB_THREEWAY);
08376                unalloc_sub(p, SUB_THREEWAY);
08377                p->owner = p->subs[SUB_REAL].owner;
08378                ast_hangup(chan);
08379                goto quit;
08380             }
08381          } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
08382                      ((exten[0] != '*') || (strlen(exten) > 2))) {
08383             ast_debug(1, "Can't match %s from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context);
08384             break;
08385          }
08386          if (!timeout)
08387             timeout = gendigittimeout;
08388          if (len && !ast_ignore_pattern(chan->context, exten))
08389             tone_zone_play_tone(p->subs[idx].dfd, -1);
08390       }
08391       break;
08392    case SIG_FXSLS:
08393    case SIG_FXSGS:
08394    case SIG_FXSKS:
08395 #ifdef HAVE_PRI
08396       if (p->pri) {
08397          /* This is a GR-303 trunk actually.  Wait for the first ring... */
08398          struct ast_frame *f;
08399          int res;
08400          time_t start;
08401 
08402          time(&start);
08403          ast_setstate(chan, AST_STATE_RING);
08404          while (time(NULL) < start + 3) {
08405             res = ast_waitfor(chan, 1000);
08406             if (res) {
08407                f = ast_read(chan);
08408                if (!f) {
08409                   ast_log(LOG_WARNING, "Whoa, hangup while waiting for first ring!\n");
08410                   ast_hangup(chan);
08411                   goto quit;
08412                } else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
08413                   res = 1;
08414                } else
08415                   res = 0;
08416                ast_frfree(f);
08417                if (res) {
08418                   ast_debug(1, "Got ring!\n");
08419                   res = 0;
08420                   break;
08421                }
08422             }
08423          }
08424       }
08425 #endif
08426       /* check for SMDI messages */
08427       if (p->use_smdi && p->smdi_iface) {
08428          smdi_msg = ast_smdi_md_message_wait(p->smdi_iface, SMDI_MD_WAIT_TIMEOUT);
08429 
08430          if (smdi_msg != NULL) {
08431             ast_copy_string(chan->exten, smdi_msg->fwd_st, sizeof(chan->exten));
08432 
08433             if (smdi_msg->type == 'B')
08434                pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
08435             else if (smdi_msg->type == 'N')
08436                pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
08437 
08438             ast_debug(1, "Received SMDI message on %s\n", chan->name);
08439          } else {
08440             ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
08441          }
08442       }
08443 
08444       if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
08445          number = smdi_msg->calling_st;
08446 
08447       /* If we want caller id, we're in a prering state due to a polarity reversal
08448        * and we're set to use a polarity reversal to trigger the start of caller id,
08449        * grab the caller id and wait for ringing to start... */
08450       } else if (p->use_callerid && (chan->_state == AST_STATE_PRERING && (p->cid_start == CID_START_POLARITY || p->cid_start == CID_START_POLARITY_IN))) {
08451          /* If set to use DTMF CID signalling, listen for DTMF */
08452          if (p->cid_signalling == CID_SIG_DTMF) {
08453             int k = 0;
08454             cs = NULL;
08455             ast_debug(1, "Receiving DTMF cid on channel %s\n", chan->name);
08456             dahdi_setlinear(p->subs[idx].dfd, 0);
08457             /*
08458              * We are the only party interested in the Rx stream since
08459              * we have not answered yet.  We don't need or even want DTMF
08460              * emulation.  The DTMF digits can come so fast that emulation
08461              * can drop some of them.
08462              */
08463             ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
08464             res = 4000;/* This is a typical OFF time between rings. */
08465             for (;;) {
08466                struct ast_frame *f;
08467                res = ast_waitfor(chan, res);
08468                if (res <= 0) {
08469                   /*
08470                    * We do not need to restore the dahdi_setlinear()
08471                    * or AST_FLAG_END_DTMF_ONLY flag settings since we
08472                    * are hanging up the channel.
08473                    */
08474                   ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
08475                      "Exiting simple switch\n");
08476                   ast_hangup(chan);
08477                   goto quit;
08478                }
08479                f = ast_read(chan);
08480                if (!f)
08481                   break;
08482                if (f->frametype == AST_FRAME_DTMF) {
08483                   if (k < ARRAY_LEN(dtmfbuf) - 1) {
08484                      dtmfbuf[k++] = f->subclass;
08485                   }
08486                   ast_debug(1, "CID got digit '%c'\n", f->subclass);
08487                   res = 4000;/* This is a typical OFF time between rings. */
08488                }
08489                ast_frfree(f);
08490                if (chan->_state == AST_STATE_RING ||
08491                   chan->_state == AST_STATE_RINGING)
08492                   break; /* Got ring */
08493             }
08494             ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
08495             dtmfbuf[k] = '\0';
08496             dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
08497             /* Got cid and ring. */
08498             ast_debug(1, "CID got string '%s'\n", dtmfbuf);
08499             callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
08500             ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
08501             /* If first byte is NULL, we have no cid */
08502             if (!ast_strlen_zero(dtmfcid))
08503                number = dtmfcid;
08504             else
08505                number = NULL;
08506          /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
08507          } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
08508             cs = callerid_new(p->cid_signalling);
08509             if (cs) {
08510                samples = 0;
08511 #if 1
08512                bump_gains(p);
08513 #endif
08514                /* Take out of linear mode for Caller*ID processing */
08515                dahdi_setlinear(p->subs[idx].dfd, 0);
08516 
08517                /* First we wait and listen for the Caller*ID */
08518                for (;;) {
08519                   i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
08520                   if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
08521                      ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
08522                      callerid_free(cs);
08523                      ast_hangup(chan);
08524                      goto quit;
08525                   }
08526                   if (i & DAHDI_IOMUX_SIGEVENT) {
08527                      res = dahdi_get_event(p->subs[idx].dfd);
08528                      ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
08529                      if (res == DAHDI_EVENT_NOALARM) {
08530                         p->inalarm = 0;
08531                      }
08532 
08533                      if (p->cid_signalling == CID_SIG_V23_JP) {
08534                         if (res == DAHDI_EVENT_RINGBEGIN) {
08535                            res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
08536                            usleep(1);
08537                         }
08538                      } else {
08539                         res = 0;
08540                         break;
08541                      }
08542                   } else if (i & DAHDI_IOMUX_READ) {
08543                      res = read(p->subs[idx].dfd, buf, sizeof(buf));
08544                      if (res < 0) {
08545                         if (errno != ELAST) {
08546                            ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
08547                            callerid_free(cs);
08548                            ast_hangup(chan);
08549                            goto quit;
08550                         }
08551                         break;
08552                      }
08553                      samples += res;
08554 
08555                      if (p->cid_signalling == CID_SIG_V23_JP) {
08556                         res = callerid_feed_jp(cs, buf, res, AST_LAW(p));
08557                      } else {
08558                         res = callerid_feed(cs, buf, res, AST_LAW(p));
08559                      }
08560                      if (res < 0) {
08561                         /*
08562                          * The previous diagnostic message output likely
08563                          * explains why it failed.
08564                          */
08565                         ast_log(LOG_WARNING,
08566                            "Failed to decode CallerID on channel '%s'\n",
08567                            chan->name);
08568                         break;
08569                      } else if (res)
08570                         break;
08571                      else if (samples > (8000 * 10))
08572                         break;
08573                   }
08574                }
08575                if (res == 1) {
08576                   callerid_get(cs, &name, &number, &flags);
08577                   ast_log(LOG_NOTICE, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
08578                }
08579 
08580                if (p->cid_signalling == CID_SIG_V23_JP) {
08581                   res = dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_ONHOOK);
08582                   usleep(1);
08583                }
08584 
08585                /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
08586                res = 4000;/* This is a typical OFF time between rings. */
08587                for (;;) {
08588                   struct ast_frame *f;
08589                   res = ast_waitfor(chan, res);
08590                   if (res <= 0) {
08591                      ast_log(LOG_WARNING, "CID timed out waiting for ring. "
08592                         "Exiting simple switch\n");
08593                      ast_hangup(chan);
08594                      goto quit;
08595                   }
08596                   if (!(f = ast_read(chan))) {
08597                      ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
08598                      ast_hangup(chan);
08599                      goto quit;
08600                   }
08601                   ast_frfree(f);
08602                   if (chan->_state == AST_STATE_RING ||
08603                      chan->_state == AST_STATE_RINGING)
08604                      break; /* Got ring */
08605                }
08606 
08607                /* We must have a ring by now, so, if configured, lets try to listen for
08608                 * distinctive ringing */
08609                if (p->usedistinctiveringdetection) {
08610                   len = 0;
08611                   distMatches = 0;
08612                   /* Clear the current ring data array so we dont have old data in it. */
08613                   for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++)
08614                      curRingData[receivedRingT] = 0;
08615                   receivedRingT = 0;
08616                   counter = 0;
08617                   counter1 = 0;
08618                   /* Check to see if context is what it should be, if not set to be. */
08619                   if (strcmp(p->context,p->defcontext) != 0) {
08620                      ast_copy_string(p->context, p->defcontext, sizeof(p->context));
08621                      ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
08622                   }
08623 
08624                   for (;;) {
08625                      i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
08626                      if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
08627                         ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
08628                         callerid_free(cs);
08629                         ast_hangup(chan);
08630                         goto quit;
08631                      }
08632                      if (i & DAHDI_IOMUX_SIGEVENT) {
08633                         res = dahdi_get_event(p->subs[idx].dfd);
08634                         ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
08635                         if (res == DAHDI_EVENT_NOALARM) {
08636                            p->inalarm = 0;
08637                         }
08638                         res = 0;
08639                         /* Let us detect distinctive ring */
08640 
08641                         curRingData[receivedRingT] = p->ringt;
08642 
08643                         if (p->ringt < p->ringt_base/2)
08644                            break;
08645                         /* Increment the ringT counter so we can match it against
08646                            values in chan_dahdi.conf for distinctive ring */
08647                         if (++receivedRingT == ARRAY_LEN(curRingData))
08648                            break;
08649                      } else if (i & DAHDI_IOMUX_READ) {
08650                         res = read(p->subs[idx].dfd, buf, sizeof(buf));
08651                         if (res < 0) {
08652                            if (errno != ELAST) {
08653                               ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
08654                               callerid_free(cs);
08655                               ast_hangup(chan);
08656                               goto quit;
08657                            }
08658                            break;
08659                         }
08660                         if (p->ringt)
08661                            p->ringt--;
08662                         if (p->ringt == 1) {
08663                            res = -1;
08664                            break;
08665                         }
08666                      }
08667                   }
08668                      /* this only shows up if you have n of the dring patterns filled in */
08669                   ast_verb(3, "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
08670                   for (counter = 0; counter < 3; counter++) {
08671                      /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this
08672                      channel */
08673                      distMatches = 0;
08674                      for (counter1 = 0; counter1 < 3; counter1++) {
08675                         ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
08676                         if (p->drings.ringnum[counter].ring[counter1] == -1) {
08677                            ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
08678                            curRingData[counter1]);
08679                            distMatches++;
08680                         } else if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
08681                               curRingData[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
08682                            ast_verb(3, "Ring pattern matched in range: %d to %d\n",
08683                            (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
08684                            (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
08685                            distMatches++;
08686                         }
08687                      }
08688 
08689                      if (distMatches == 3) {
08690                         /* The ring matches, set the context to whatever is for distinctive ring.. */
08691                         ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
08692                         ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
08693                         ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
08694                         break;
08695                      }
08696                   }
08697                }
08698                /* Restore linear mode (if appropriate) for Caller*ID processing */
08699                dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
08700 #if 1
08701                restore_gains(p);
08702 #endif
08703             } else
08704                ast_log(LOG_WARNING, "Unable to get caller ID space\n");
08705          } else {
08706             ast_log(LOG_WARNING, "Channel %s in prering "
08707                "state, but I have nothing to do. "
08708                "Terminating simple switch, should be "
08709                "restarted by the actual ring.\n",
08710                chan->name);
08711             ast_hangup(chan);
08712             goto quit;
08713          }
08714       } else if (p->use_callerid && p->cid_start == CID_START_RING) {
08715          if (p->cid_signalling == CID_SIG_DTMF) {
08716             int k = 0;
08717             cs = NULL;
08718             dahdi_setlinear(p->subs[idx].dfd, 0);
08719             res = 2000;
08720             for (;;) {
08721                struct ast_frame *f;
08722                res = ast_waitfor(chan, res);
08723                if (res <= 0) {
08724                   ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
08725                      "Exiting simple switch\n");
08726                   ast_hangup(chan);
08727                   return NULL;
08728                }
08729                f = ast_read(chan);
08730                if (f->frametype == AST_FRAME_DTMF) {
08731                   dtmfbuf[k++] = f->subclass;
08732                   ast_log(LOG_DEBUG, "CID got digit '%c'\n", f->subclass);
08733                   res = 2000;
08734                }
08735                ast_frfree(f);
08736 
08737                if (p->ringt_base == p->ringt)
08738                   break;
08739             }
08740             dtmfbuf[k] = '\0';
08741             dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
08742             /* Got cid and ring. */
08743             callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
08744             ast_log(LOG_DEBUG, "CID is '%s', flags %d\n",
08745                dtmfcid, flags);
08746             /* If first byte is NULL, we have no cid */
08747             if (!ast_strlen_zero(dtmfcid))
08748                number = dtmfcid;
08749             else
08750                number = NULL;
08751             /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
08752          } else {
08753             /* FSK Bell202 callerID */
08754             cs = callerid_new(p->cid_signalling);
08755             if (cs) {
08756 #if 1
08757                bump_gains(p);
08758 #endif
08759                samples = 0;
08760                len = 0;
08761                distMatches = 0;
08762                /* Clear the current ring data array so we dont have old data in it. */
08763                for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++)
08764                   curRingData[receivedRingT] = 0;
08765                receivedRingT = 0;
08766                counter = 0;
08767                counter1 = 0;
08768                /* Check to see if context is what it should be, if not set to be. */
08769                if (strcmp(p->context,p->defcontext) != 0) {
08770                   ast_copy_string(p->context, p->defcontext, sizeof(p->context));
08771                   ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
08772                }
08773 
08774                /* Take out of linear mode for Caller*ID processing */
08775                dahdi_setlinear(p->subs[idx].dfd, 0);
08776                for (;;) {
08777                   i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
08778                   if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
08779                      ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
08780                      callerid_free(cs);
08781                      ast_hangup(chan);
08782                      goto quit;
08783                   }
08784                   if (i & DAHDI_IOMUX_SIGEVENT) {
08785                      res = dahdi_get_event(p->subs[idx].dfd);
08786                      ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
08787                      if (res == DAHDI_EVENT_NOALARM) {
08788                         p->inalarm = 0;
08789                      }
08790                      /* If we get a PR event, they hung up while processing calerid */
08791                      if ( res == DAHDI_EVENT_POLARITY && p->hanguponpolarityswitch && p->polarity == POLARITY_REV) {
08792                         ast_log(LOG_DEBUG, "Hanging up due to polarity reversal on channel %d while detecting callerid\n", p->channel);
08793                         p->polarity = POLARITY_IDLE;
08794                         callerid_free(cs);
08795                         ast_hangup(chan);
08796                         goto quit;
08797                      }
08798                      res = 0;
08799                      /* Let us detect callerid when the telco uses distinctive ring */
08800 
08801                      curRingData[receivedRingT] = p->ringt;
08802 
08803                      if (p->ringt < p->ringt_base/2)
08804                         break;
08805                      /* Increment the ringT counter so we can match it against
08806                         values in chan_dahdi.conf for distinctive ring */
08807                      if (++receivedRingT == ARRAY_LEN(curRingData))
08808                         break;
08809                   } else if (i & DAHDI_IOMUX_READ) {
08810                      res = read(p->subs[idx].dfd, buf, sizeof(buf));
08811                      if (res < 0) {
08812                         if (errno != ELAST) {
08813                            ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
08814                            callerid_free(cs);
08815                            ast_hangup(chan);
08816                            goto quit;
08817                         }
08818                         break;
08819                      }
08820                      if (p->ringt)
08821                         p->ringt--;
08822                      if (p->ringt == 1) {
08823                         res = -1;
08824                         break;
08825                      }
08826                      samples += res;
08827                      res = callerid_feed(cs, buf, res, AST_LAW(p));
08828                      if (res < 0) {
08829                         /*
08830                          * The previous diagnostic message output likely
08831                          * explains why it failed.
08832                          */
08833                         ast_log(LOG_WARNING,
08834                            "Failed to decode CallerID on channel '%s'\n",
08835                            chan->name);
08836                         break;
08837                      } else if (res)
08838                         break;
08839                      else if (samples > (8000 * 10))
08840                         break;
08841                   }
08842                }
08843                if (res == 1) {
08844                   callerid_get(cs, &name, &number, &flags);
08845                   ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
08846                }
08847                if (distinctiveringaftercid == 1) {
08848                   /* Clear the current ring data array so we dont have old data in it. */
08849                   for (receivedRingT = 0; receivedRingT < 3; receivedRingT++) {
08850                      curRingData[receivedRingT] = 0;
08851                   }
08852                   receivedRingT = 0;
08853                   ast_verb(3, "Detecting post-CID distinctive ring\n");
08854                   for (;;) {
08855                      i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
08856                      if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
08857                         ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
08858                         callerid_free(cs);
08859                         ast_hangup(chan);
08860                         goto quit;
08861                      }
08862                      if (i & DAHDI_IOMUX_SIGEVENT) {
08863                         res = dahdi_get_event(p->subs[idx].dfd);
08864                         ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
08865                         if (res == DAHDI_EVENT_NOALARM) {
08866                            p->inalarm = 0;
08867                         }
08868                         res = 0;
08869                         /* Let us detect callerid when the telco uses distinctive ring */
08870 
08871                         curRingData[receivedRingT] = p->ringt;
08872 
08873                         if (p->ringt < p->ringt_base/2)
08874                            break;
08875                         /* Increment the ringT counter so we can match it against
08876                            values in chan_dahdi.conf for distinctive ring */
08877                         if (++receivedRingT == ARRAY_LEN(curRingData))
08878                            break;
08879                      } else if (i & DAHDI_IOMUX_READ) {
08880                         res = read(p->subs[idx].dfd, buf, sizeof(buf));
08881                         if (res < 0) {
08882                            if (errno != ELAST) {
08883                               ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
08884                               callerid_free(cs);
08885                               ast_hangup(chan);
08886                               goto quit;
08887                            }
08888                            break;
08889                         }
08890                      if (p->ringt)
08891                         p->ringt--;
08892                         if (p->ringt == 1) {
08893                            res = -1;
08894                            break;
08895                         }
08896                      }
08897                   }
08898                }
08899                if (p->usedistinctiveringdetection) {
08900                   /* this only shows up if you have n of the dring patterns filled in */
08901                   ast_verb(3, "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
08902 
08903                   for (counter = 0; counter < 3; counter++) {
08904                      /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this
08905                      channel */
08906                      /* this only shows up if you have n of the dring patterns filled in */
08907                      ast_verb(3, "Checking %d,%d,%d\n",
08908                            p->drings.ringnum[counter].ring[0],
08909                            p->drings.ringnum[counter].ring[1],
08910                            p->drings.ringnum[counter].ring[2]);
08911                      distMatches = 0;
08912                      for (counter1 = 0; counter1 < 3; counter1++) {
08913                         ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
08914                         if (p->drings.ringnum[counter].ring[counter1] == -1) {
08915                            ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
08916                            curRingData[counter1]);
08917                            distMatches++;
08918                         }
08919                         else if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
08920                            curRingData[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
08921                            ast_verb(3, "Ring pattern matched in range: %d to %d\n",
08922                            (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
08923                            (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
08924                            distMatches++;
08925                         }
08926                      }
08927                      if (distMatches == 3) {
08928                         /* The ring matches, set the context to whatever is for distinctive ring.. */
08929                         ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
08930                         ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
08931                         ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
08932                         break;
08933                      }
08934                   }
08935                }
08936                /* Restore linear mode (if appropriate) for Caller*ID processing */
08937                dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
08938 #if 1
08939                restore_gains(p);
08940 #endif
08941                if (res < 0) {
08942                   ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name);
08943                }
08944             } else
08945                ast_log(LOG_WARNING, "Unable to get caller ID space\n");
08946          }
08947       } else
08948          cs = NULL;
08949 
08950       if (number)
08951          ast_shrink_phone_number(number);
08952       ast_set_callerid(chan, number, name, number);
08953 
08954       if (smdi_msg)
08955          ASTOBJ_UNREF(smdi_msg, ast_smdi_md_message_destroy);
08956 
08957       if (cs)
08958          callerid_free(cs);
08959       /* If the CID had Message waiting payload, assume that this for MWI only and hangup the call */
08960       if (flags & CID_MSGWAITING) {
08961          ast_log(LOG_NOTICE, "MWI: Channel %d message waiting!\n", p->channel);
08962          notify_message(p->mailbox, 1);
08963          /* If generated using Ring Pulse Alert, then ring has been answered as a call and needs to be hungup */
08964          if (p->mwimonitor_rpas) {
08965             ast_hangup(chan);
08966             return NULL;
08967          }
08968       } else if (flags & CID_NOMSGWAITING) {
08969          ast_log(LOG_NOTICE, "MWI: Channel %d no message waiting!\n", p->channel);
08970          notify_message(p->mailbox, 0);
08971          /* If generated using Ring Pulse Alert, then ring has been answered as a call and needs to be hungup */
08972          if (p->mwimonitor_rpas) {
08973             ast_hangup(chan);
08974             return NULL;
08975          }
08976       }
08977 
08978       ast_setstate(chan, AST_STATE_RING);
08979       chan->rings = 1;
08980       p->ringt = p->ringt_base;
08981       res = ast_pbx_run(chan);
08982       if (res) {
08983          ast_hangup(chan);
08984          ast_log(LOG_WARNING, "PBX exited non-zero\n");
08985       }
08986       goto quit;
08987    default:
08988       ast_log(LOG_WARNING, "Don't know how to handle simple switch with signalling %s on channel %d\n", sig2str(p->sig), p->channel);
08989       res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08990       if (res < 0)
08991             ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
08992    }
08993    res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_CONGESTION);
08994    if (res < 0)
08995          ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
08996    ast_hangup(chan);
08997 quit:
08998    ast_mutex_lock(&ss_thread_lock);
08999    ss_thread_count--;
09000    ast_cond_signal(&ss_thread_complete);
09001    ast_mutex_unlock(&ss_thread_lock);
09002    return NULL;
09003 }

static int start_pri ( struct dahdi_pri *  pri  )  [static]

Definition at line 13653 of file chan_dahdi.c.

References ast_log(), ast_pthread_create_background, DAHDI_CHAN_MAPPING_LOGICAL, dahdi_close_pri_fd(), DAHDI_OVERLAPDIAL_BOTH, DAHDI_OVERLAPDIAL_OUTGOING, DCHAN_NOTINALARM, dahdi_pri::dchanavail, dahdi_pri::dchannels, dahdi_pri::dchans, DEFAULT_PRI_DEBUG, errno, dahdi_pri::fds, dahdi_pri::inbanddisconnect, LOG_ERROR, dahdi_pri::master, dahdi_pri::nodetype, dahdi_pri::nsf, NUM_DCHANS, dahdi_pri::overlapdial, dahdi_pri::pri, pri_dchannel(), dahdi_pri::qsigchannelmapping, dahdi_pri::resetpos, dahdi_pri::sig, SIG_BRI, SIG_BRI_PTMP, and dahdi_pri::switchtype.

Referenced by setup_dahdi().

13654 {
13655    int res, x;
13656    struct dahdi_params p;
13657    struct dahdi_bufferinfo bi;
13658    struct dahdi_spaninfo si;
13659    int i;
13660 
13661    for (i = 0; i < NUM_DCHANS; i++) {
13662       if (!pri->dchannels[i])
13663          break;
13664       pri->fds[i] = open("/dev/dahdi/channel", O_RDWR);
13665       x = pri->dchannels[i];
13666       if ((pri->fds[i] < 0) || (ioctl(pri->fds[i],DAHDI_SPECIFY,&x) == -1)) {
13667          ast_log(LOG_ERROR, "Unable to open D-channel %d (%s)\n", x, strerror(errno));
13668          return -1;
13669       }
13670       memset(&p, 0, sizeof(p));
13671       res = ioctl(pri->fds[i], DAHDI_GET_PARAMS, &p);
13672       if (res) {
13673          dahdi_close_pri_fd(pri, i);
13674          ast_log(LOG_ERROR, "Unable to get parameters for D-channel %d (%s)\n", x, strerror(errno));
13675          return -1;
13676       }
13677       if ((p.sigtype != DAHDI_SIG_HDLCFCS) && (p.sigtype != DAHDI_SIG_HARDHDLC)) {
13678          dahdi_close_pri_fd(pri, i);
13679          ast_log(LOG_ERROR, "D-channel %d is not in HDLC/FCS mode.\n", x);
13680          return -1;
13681       }
13682       memset(&si, 0, sizeof(si));
13683       res = ioctl(pri->fds[i], DAHDI_SPANSTAT, &si);
13684       if (res) {
13685          dahdi_close_pri_fd(pri, i);
13686          ast_log(LOG_ERROR, "Unable to get span state for D-channel %d (%s)\n", x, strerror(errno));
13687       }
13688       if (!si.alarms)
13689          pri->dchanavail[i] |= DCHAN_NOTINALARM;
13690       else
13691          pri->dchanavail[i] &= ~DCHAN_NOTINALARM;
13692       memset(&bi, 0, sizeof(bi));
13693       bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
13694       bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
13695       bi.numbufs = 32;
13696       bi.bufsize = 1024;
13697       if (ioctl(pri->fds[i], DAHDI_SET_BUFINFO, &bi)) {
13698          ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", x, strerror(errno));
13699          dahdi_close_pri_fd(pri, i);
13700          return -1;
13701       }
13702       switch (pri->sig) {
13703       case SIG_BRI:
13704          pri->dchans[i] = pri_new_bri(pri->fds[i], 1, pri->nodetype, pri->switchtype);
13705          break;
13706       case SIG_BRI_PTMP:
13707          pri->dchans[i] = pri_new_bri(pri->fds[i], 0, pri->nodetype, pri->switchtype);
13708          break;
13709       default:
13710          pri->dchans[i] = pri_new(pri->fds[i], pri->nodetype, pri->switchtype);
13711          break;
13712       }
13713       /* Force overlap dial if we're doing GR-303! */
13714       if (pri->switchtype == PRI_SWITCH_GR303_TMC)
13715          pri->overlapdial |= DAHDI_OVERLAPDIAL_BOTH;
13716       pri_set_overlapdial(pri->dchans[i],(pri->overlapdial & DAHDI_OVERLAPDIAL_OUTGOING)?1:0);
13717 #ifdef HAVE_PRI_PROG_W_CAUSE
13718       pri_set_chan_mapping_logical(pri->dchans[i], pri->qsigchannelmapping == DAHDI_CHAN_MAPPING_LOGICAL);
13719 #endif
13720 #ifdef HAVE_PRI_INBANDDISCONNECT
13721       pri_set_inbanddisconnect(pri->dchans[i], pri->inbanddisconnect);
13722 #endif
13723       /* Enslave to master if appropriate */
13724       if (i)
13725          pri_enslave(pri->dchans[0], pri->dchans[i]);
13726       if (!pri->dchans[i]) {
13727          dahdi_close_pri_fd(pri, i);
13728          ast_log(LOG_ERROR, "Unable to create PRI structure\n");
13729          return -1;
13730       }
13731       pri_set_debug(pri->dchans[i], DEFAULT_PRI_DEBUG);
13732       pri_set_nsf(pri->dchans[i], pri->nsf);
13733 #ifdef PRI_GETSET_TIMERS
13734       for (x = 0; x < PRI_MAX_TIMERS; x++) {
13735          if (pritimers[x] != 0)
13736             pri_set_timer(pri->dchans[i], x, pritimers[x]);
13737       }
13738 #endif
13739    }
13740    /* Assume primary is the one we use */
13741    pri->pri = pri->dchans[0];
13742    pri->resetpos = -1;
13743    if (ast_pthread_create_background(&pri->master, NULL, pri_dchannel, pri)) {
13744       for (i = 0; i < NUM_DCHANS; i++) {
13745          if (!pri->dchannels[i])
13746             break;
13747          dahdi_close_pri_fd(pri, i);
13748       }
13749       ast_log(LOG_ERROR, "Unable to spawn D-channel: %s\n", strerror(errno));
13750       return -1;
13751    }
13752    return 0;
13753 }

static void swap_subs ( struct dahdi_pvt *  p,
int  a,
int  b 
) [static]

Definition at line 2064 of file chan_dahdi.c.

References ast_channel_set_fd(), ast_debug, dahdi_subchannel::chan, dahdi_subchannel::dfd, dahdi_subchannel::inthreeway, dahdi_subchannel::owner, dahdi_pvt::subs, and wakeup_sub().

Referenced by attempt_transfer(), dahdi_answer(), dahdi_handle_event(), dahdi_hangup(), and ss_thread().

02065 {
02066    int tchan;
02067    int tinthreeway;
02068    struct ast_channel *towner;
02069 
02070    ast_debug(1, "Swapping %d and %d\n", a, b);
02071 
02072    tchan = p->subs[a].chan;
02073    towner = p->subs[a].owner;
02074    tinthreeway = p->subs[a].inthreeway;
02075 
02076    p->subs[a].chan = p->subs[b].chan;
02077    p->subs[a].owner = p->subs[b].owner;
02078    p->subs[a].inthreeway = p->subs[b].inthreeway;
02079 
02080    p->subs[b].chan = tchan;
02081    p->subs[b].owner = towner;
02082    p->subs[b].inthreeway = tinthreeway;
02083 
02084    if (p->subs[a].owner)
02085       ast_channel_set_fd(p->subs[a].owner, 0, p->subs[a].dfd);
02086    if (p->subs[b].owner)
02087       ast_channel_set_fd(p->subs[b].owner, 0, p->subs[b].dfd);
02088    wakeup_sub(p, a, NULL);
02089    wakeup_sub(p, b, NULL);
02090 }

static int unalloc_sub ( struct dahdi_pvt *  p,
int  x 
) [static]

Definition at line 2214 of file chan_dahdi.c.

References ast_debug, ast_log(), dahdi_subchannel::chan, dahdi_pvt::channel, dahdi_subchannel::curconf, dahdi_close_sub(), dahdi_subchannel::inthreeway, dahdi_subchannel::linear, LOG_WARNING, dahdi_subchannel::owner, dahdi_pvt::polarity, POLARITY_IDLE, and dahdi_pvt::subs.

Referenced by attempt_transfer(), dahdi_handle_event(), dahdi_hangup(), and ss_thread().

02215 {
02216    if (!x) {
02217       ast_log(LOG_WARNING, "Trying to unalloc the real channel %d?!?\n", p->channel);
02218       return -1;
02219    }
02220    ast_debug(1, "Released sub %d of channel %d\n", x, p->channel);
02221    dahdi_close_sub(p, x);
02222    p->subs[x].linear = 0;
02223    p->subs[x].chan = 0;
02224    p->subs[x].owner = NULL;
02225    p->subs[x].inthreeway = 0;
02226    p->polarity = POLARITY_IDLE;
02227    memset(&p->subs[x].curconf, 0, sizeof(p->subs[x].curconf));
02228    return 0;
02229 }

static int unload_module ( void   )  [static]

Definition at line 16049 of file chan_dahdi.c.

References __unload_module(), ast_mutex_destroy(), linksets, lock, NUM_SPANS, and pris.

16050 {
16051 #if defined(HAVE_PRI) || defined(HAVE_SS7)
16052    int y;
16053 #endif
16054 #ifdef HAVE_PRI
16055    for (y = 0; y < NUM_SPANS; y++)
16056       ast_mutex_destroy(&pris[y].lock);
16057 #endif
16058 #ifdef HAVE_SS7
16059    for (y = 0; y < NUM_SPANS; y++)
16060       ast_mutex_destroy(&linksets[y].lock);
16061 #endif /* HAVE_SS7 */
16062    return __unload_module();
16063 }

static int update_conf ( struct dahdi_pvt *  p  )  [static]

Definition at line 2606 of file chan_dahdi.c.

References ast_debug, dahdi_pvt::channel, conf_add(), conf_del(), dahdi_pvt::confno, dahdi_subchannel::dfd, GET_CHANNEL, dahdi_pvt::inconference, dahdi_subchannel::inthreeway, isslavenative(), dahdi_pvt::master, MAX_SLAVES, dahdi_pvt::slaves, SUB_REAL, and dahdi_pvt::subs.

Referenced by __dahdi_exception(), dahdi_bridge(), dahdi_fixup(), dahdi_handle_event(), dahdi_hangup(), dahdi_unlink(), and mkintf().

02607 {
02608    int needconf = 0;
02609    int x;
02610    int useslavenative;
02611    struct dahdi_pvt *slave = NULL;
02612 
02613    useslavenative = isslavenative(p, &slave);
02614    /* Start with the obvious, general stuff */
02615    for (x = 0; x < 3; x++) {
02616       /* Look for three way calls */
02617       if ((p->subs[x].dfd > -1) && p->subs[x].inthreeway) {
02618          conf_add(p, &p->subs[x], x, 0);
02619          needconf++;
02620       } else {
02621          conf_del(p, &p->subs[x], x);
02622       }
02623    }
02624    /* If we have a slave, add him to our conference now. or DAX
02625       if this is slave native */
02626    for (x = 0; x < MAX_SLAVES; x++) {
02627       if (p->slaves[x]) {
02628          if (useslavenative)
02629             conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
02630          else {
02631             conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
02632             needconf++;
02633          }
02634       }
02635    }
02636    /* If we're supposed to be in there, do so now */
02637    if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
02638       if (useslavenative)
02639          conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
02640       else {
02641          conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
02642          needconf++;
02643       }
02644    }
02645    /* If we have a master, add ourselves to his conference */
02646    if (p->master) {
02647       if (isslavenative(p->master, NULL)) {
02648          conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
02649       } else {
02650          conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
02651       }
02652    }
02653    if (!needconf) {
02654       /* Nobody is left (or should be left) in our conference.
02655          Kill it. */
02656       p->confno = -1;
02657    }
02658    ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
02659    return 0;
02660 }

static void wakeup_sub ( struct dahdi_pvt *  p,
int  a,
struct dahdi_pri *  pri 
) [static]

Definition at line 1522 of file chan_dahdi.c.

References ast_channel_trylock, ast_channel_unlock, ast_mutex_lock(), ast_mutex_unlock(), ast_null_frame, ast_queue_frame(), DEADLOCK_AVOIDANCE, dahdi_pvt::lock, dahdi_pri::lock, dahdi_subchannel::owner, and dahdi_pvt::subs.

Referenced by pri_fixup_principle(), and swap_subs().

01523 {
01524 #ifdef HAVE_PRI
01525    if (pri)
01526       ast_mutex_unlock(&pri->lock);
01527 #endif
01528    for (;;) {
01529       if (p->subs[a].owner) {
01530          if (ast_channel_trylock(p->subs[a].owner)) {
01531             DEADLOCK_AVOIDANCE(&p->lock);
01532          } else {
01533             ast_queue_frame(p->subs[a].owner, &ast_null_frame);
01534             ast_channel_unlock(p->subs[a].owner);
01535             break;
01536          }
01537       } else
01538          break;
01539    }
01540 #ifdef HAVE_PRI
01541    if (pri)
01542       ast_mutex_lock(&pri->lock);
01543 #endif
01544 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = tdesc , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 17588 of file chan_dahdi.c.

int alarm

Definition at line 2369 of file chan_dahdi.c.

Referenced by alarm2str().

struct { ... } alarms[] [static]

Referenced by alarm2str().

struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}} [static]

Definition at line 1497 of file chan_dahdi.c.

Definition at line 17588 of file chan_dahdi.c.

struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] [static]

Definition at line 1478 of file chan_dahdi.c.

int cidrings[NUM_CADENCE_MAX] [static]

cidrings says in which pause to transmit the cid information, where the first pause is 1, the second pause is 2 and so on.

Definition at line 1489 of file chan_dahdi.c.

const char config[] = "chan_dahdi.conf" [static]

Definition at line 238 of file chan_dahdi.c.

int cur_adjpointcode = -1 [static]

Definition at line 456 of file chan_dahdi.c.

int cur_cicbeginswith = -1 [static]

Definition at line 455 of file chan_dahdi.c.

int cur_defaultdpc = -1 [static]

Definition at line 458 of file chan_dahdi.c.

int cur_linkset = -1 [static]

Definition at line 453 of file chan_dahdi.c.

int cur_networkindicator = -1 [static]

Definition at line 457 of file chan_dahdi.c.

int cur_pointcode = -1 [static]

Definition at line 454 of file chan_dahdi.c.

int cur_ss7type = -1 [static]

Definition at line 452 of file chan_dahdi.c.

const char* dahdi_accept_r2_call_app = "DAHDIAcceptR2Call" [static]

Definition at line 4173 of file chan_dahdi.c.

struct ast_cli_entry dahdi_cli[] [static]

Definition at line 15286 of file chan_dahdi.c.

struct ast_cli_entry dahdi_mfcr2_cli[] [static]

Definition at line 14391 of file chan_dahdi.c.

struct ast_cli_entry dahdi_pri_cli[] [static]

Definition at line 14059 of file chan_dahdi.c.

openr2_event_interface_t dahdi_r2_event_iface [static]

Definition at line 2024 of file chan_dahdi.c.

openr2_transcoder_interface_t dahdi_r2_transcode_iface [static]

Initial value:

Definition at line 2055 of file chan_dahdi.c.

char* dahdi_send_keypad_facility_app = "DAHDISendKeypadFacility" [static]

Definition at line 3962 of file chan_dahdi.c.

struct ast_cli_entry dahdi_ss7_cli[] [static]

Definition at line 15955 of file chan_dahdi.c.

struct ast_channel_tech dahdi_tech [static]

Definition at line 1402 of file chan_dahdi.c.

struct ast_jb_conf default_jbconf [static]

Global jitterbuffer configuration - by default, jb is disabled

Definition at line 173 of file chan_dahdi.c.

char defaultcic[64] = "" [static]

Definition at line 296 of file chan_dahdi.c.

char defaultozz[64] = "" [static]

Definition at line 297 of file chan_dahdi.c.

int distinctiveringaftercid = 0 [static]

Definition at line 310 of file chan_dahdi.c.

char* events[] [static]

Definition at line 2346 of file chan_dahdi.c.

int firstdigittimeout = 16000 [static]

Wait up to 16 seconds for first digit (FXO logic).

Definition at line 326 of file chan_dahdi.c.

Referenced by disa_exec().

int gendigittimeout = 8000 [static]

How long to wait for following digits (FXO logic).

Definition at line 329 of file chan_dahdi.c.

struct ast_jb_conf global_jbconf [static]

Definition at line 181 of file chan_dahdi.c.

Referenced by dahdi_new(), process_dahdi(), and setup_dahdi().

int ifcount = 0 [static]

Definition at line 342 of file chan_dahdi.c.

struct dahdi_pvt * ifend [static]

struct dahdi_pvt * iflist [static]

ast_mutex_t iflock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static]

struct ast_channel inuse [static]

const char* lbostr[] [static]

Definition at line 161 of file chan_dahdi.c.

struct dahdi_ss7 linksets[NUM_SPANS] [static]

int matchdigittimeout = 3000 [static]

How long to wait for an extra digit, if there is an ambiguous match.

Definition at line 332 of file chan_dahdi.c.

pthread_t monitor_thread = AST_PTHREADT_NULL [static]

This is the thread for the monitor which checks for input on the channels which are not currently in use.

Definition at line 354 of file chan_dahdi.c.

ast_mutex_t monlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static]

Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical.

Definition at line 350 of file chan_dahdi.c.

Referenced by __unload_module(), dahdi_restart(), and restart_monitor().

int mwilevel = 512 [static]

Definition at line 314 of file chan_dahdi.c.

char mwimonitornotify[PATH_MAX] = "" [static]

Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled

Definition at line 302 of file chan_dahdi.c.

char* name

Definition at line 2370 of file chan_dahdi.c.

int num_cadence = 4 [static]

Definition at line 1475 of file chan_dahdi.c.

int num_restart_pending = 0 [static]

Definition at line 359 of file chan_dahdi.c.

int numbufs = 4 [static]

Definition at line 312 of file chan_dahdi.c.

char parkinglot[AST_MAX_EXTENSION] = "" [static]

int pridebugfd = -1 [static]

Definition at line 321 of file chan_dahdi.c.

ast_mutex_t pridebugfdlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static]

char pridebugfilename[1024] = "" [static]

Definition at line 322 of file chan_dahdi.c.

struct dahdi_pri pris[NUM_SPANS] [static]

char progzone[10] = "" [static]

Definition at line 307 of file chan_dahdi.c.

struct dahdi_mfcr2** r2links [static]

Definition at line 494 of file chan_dahdi.c.

int r2links_count = 0 [static]

Definition at line 496 of file chan_dahdi.c.

ast_mutex_t restart_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static]

Definition at line 357 of file chan_dahdi.c.

Referenced by dahdi_restart().

int ringt_base = DEFAULT_RINGT [static]

Configured ring timeout base.

Note:
Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.

Definition at line 414 of file chan_dahdi.c.

struct dahdi_pvt* round_robin[32]

Definition at line 1430 of file chan_dahdi.c.

Definition at line 355 of file chan_dahdi.c.

int ss_thread_count = 0 [static]

Definition at line 358 of file chan_dahdi.c.

ast_mutex_t ss_thread_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static]

Definition at line 356 of file chan_dahdi.c.

Referenced by dahdi_restart(), and ss_thread().

char* subnames[] [static]

Initial value:

 {
   "Real",
   "Callwait",
   "Threeway"
}

Definition at line 600 of file chan_dahdi.c.

const char tdesc[] [static]

Definition at line 215 of file chan_dahdi.c.

int usedistinctiveringdetection = 0 [static]

Definition at line 309 of file chan_dahdi.c.

int user_has_defined_cadences = 0 [static]

Definition at line 1476 of file chan_dahdi.c.


Generated on Wed Aug 11 01:07:07 2010 for Asterisk - the Open Source PBX by  doxygen 1.5.9