Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Enumerations | Functions | Variables
isdn_lib.c File Reference

Interface to mISDN. More...

#include <syslog.h>
#include <sys/time.h>
#include <mISDNuser/isdn_debug.h>
#include "isdn_lib_intern.h"
#include "isdn_lib.h"
#include "asterisk/causes.h"
#include <mISDNuser/net_l2.h>
#include <mISDNuser/tone.h>
#include <unistd.h>
#include <semaphore.h>
#include <pthread.h>
#include <signal.h>
Include dependency graph for isdn_lib.c:

Go to the source code of this file.

Data Structures

struct  misdn_lib
 

Macros

#define ARRAY_LEN(a)   (sizeof(a) / sizeof(a[0]))
 
#define ECHOCAN_OFF   124
 
#define ECHOCAN_ON   123
 
#define ISDN_PID_L3_B_USER   0x430000ff
 
#define ISDN_PID_L4_B_USER   0x440000ff
 
#define MISDN_DEBUG   0
 
#define MISDN_DSP
 
#define MISDN_GEN_SILENCE
 
#define MISDN_IBUF_SIZE   512
 
#define RETURN(a, b)   {retval=a; goto b;}
 
#define TONE_ALERT_CNT   41 /* 1 Sec */
 
#define TONE_ALERT_SILENCE_CNT   200 /* 4 Sec */
 
#define TONE_BUSY_CNT   20 /* ? */
 
#define TONE_BUSY_SILENCE_CNT   48 /* ? */
 

Enumerations

enum  global_states { MISDN_INITIALIZING, MISDN_INITIALIZED }
 

Functions

static void bc_next_state_change (struct misdn_bchannel *bc, enum bchannel_state state)
 
char * bc_state2str (enum bchannel_state state)
 
void bc_state_change (struct misdn_bchannel *bc, enum bchannel_state state)
 
int bchdev_echocancel_activate (struct misdn_bchannel *dev)
 
void bchdev_echocancel_deactivate (struct misdn_bchannel *dev)
 
static char * bearer2str (int cap)
 
static int clean_up_bc (struct misdn_bchannel *bc)
 
static void clear_l3 (struct misdn_stack *stack)
 
static msg_t * create_l2msg (int prim, int dinfo, int size)
 
msg_t * create_l3msg (int prim, int mt, int dinfo, int size, int ntmode)
 
static int create_process (int midev, struct misdn_bchannel *bc)
 
static int do_tone (struct misdn_bchannel *bc, int len)
 
static void dump_chan_list (struct misdn_stack *stack)
 
void ec_chunk (struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size)
 
static void empty_bc (struct misdn_bchannel *bc)
 
static void empty_chan_in_stack (struct misdn_stack *stack, int channel)
 
static const char * fac2str (enum FacFunction facility)
 
static msg_t * fetch_msg (int midev)
 
static struct misdn_bchannelfind_bc_by_addr (unsigned long addr)
 
static struct misdn_bchannelfind_bc_by_confid (unsigned long confid)
 
struct misdn_bchannelfind_bc_by_l3id (struct misdn_stack *stack, unsigned long l3id)
 
static struct misdn_bchannelfind_bc_by_masked_l3id (struct misdn_stack *stack, unsigned long l3id, unsigned long mask)
 
static int find_free_chan_in_stack (struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
 
static struct misdn_stackfind_stack_by_addr (int addr)
 
static struct misdn_stackfind_stack_by_mgr (manager_t *mgr_nt)
 
static struct misdn_stackfind_stack_by_port (int port)
 
static char * flip_buf_bits (char *buf, int len)
 
struct misdn_stackget_misdn_stack (void)
 
void get_show_stack_details (int port, char *buf)
 
struct misdn_stackget_stack_by_bc (struct misdn_bchannel *bc)
 
static int handle_bchan (msg_t *msg)
 
static int handle_cr (struct misdn_stack *stack, iframe_t *frm)
 
static int handle_err (msg_t *msg)
 
static int handle_event_nt (void *dat, void *arg)
 
static int handle_event_te (struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
 
static int handle_frm_nt (msg_t *msg)
 
static int handle_frm_te (msg_t *msg)
 
static int handle_l1 (msg_t *msg)
 
static int handle_l2 (msg_t *msg)
 
static int handle_mgmt (msg_t *msg)
 
static int handle_timers (msg_t *msg)
 
static int init_bc (struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx)
 
static void init_flip_bits (void)
 
void isdn_lib_stop_dtmf (struct misdn_bchannel *bc)
 
void isdn_lib_update_ec (struct misdn_bchannel *bc)
 
void isdn_lib_update_rxgain (struct misdn_bchannel *bc)
 
void isdn_lib_update_txgain (struct misdn_bchannel *bc)
 
void manager_bchannel_activate (struct misdn_bchannel *bc)
 
void manager_bchannel_cleanup (struct misdn_bchannel *bc)
 
void manager_bchannel_deactivate (struct misdn_bchannel *bc)
 
void manager_bchannel_setup (struct misdn_bchannel *bc)
 
void manager_clean_bc (struct misdn_bchannel *bc)
 
void manager_ec_disable (struct misdn_bchannel *bc)
 
void manager_ec_enable (struct misdn_bchannel *bc)
 
static void manager_event_handler (void *arg)
 
struct misdn_bchannelmanager_find_bc_by_pid (int pid)
 
char * manager_isdn_get_info (enum event_e event)
 
int manager_isdn_handler (iframe_t *frm, msg_t *msg)
 
void manager_ph_control (struct misdn_bchannel *bc, int c1, int c2)
 
void manager_ph_control_block (struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
 
int misdn_cap_is_speech (int cap)
 
void misdn_dump_chanlist (void)
 
int misdn_inband_avail (struct misdn_bchannel *bc)
 
void misdn_join_conf (struct misdn_bchannel *bc, int conf_id)
 
void misdn_lib_bridge (struct misdn_bchannel *bc1, struct misdn_bchannel *bc2)
 
void misdn_lib_destroy (void)
 
void misdn_lib_echo (struct misdn_bchannel *bc, int onoff)
 
struct misdn_bchannelmisdn_lib_find_held_bc (int port, int l3_id)
 Find a held call's B channel record. More...
 
struct misdn_bchannelmisdn_lib_get_free_bc (int port, int channel, int inout, int dec)
 
static int misdn_lib_get_l1_down (struct misdn_stack *stack)
 
static int misdn_lib_get_l1_up (struct misdn_stack *stack)
 
static int misdn_lib_get_l2_down (struct misdn_stack *stack)
 
int misdn_lib_get_l2_up (struct misdn_stack *stack)
 
int misdn_lib_get_maxchans (int port)
 
int misdn_lib_get_port_down (int port)
 
int misdn_lib_get_port_info (int port)
 
int misdn_lib_get_port_up (int port)
 
static int misdn_lib_get_short_status (struct misdn_stack *stack)
 
int misdn_lib_init (char *portlist, struct misdn_lib_iface *iface, void *user_data)
 
int misdn_lib_is_port_blocked (int port)
 
int misdn_lib_is_ptp (int port)
 
static void misdn_lib_isdn_event_catcher (void *arg)
 
void misdn_lib_isdn_l1watcher (int port)
 
void misdn_lib_log_ies (struct misdn_bchannel *bc)
 
int misdn_lib_maxports_get (void)
 
void misdn_lib_nt_debug_init (int flags, char *file)
 
void misdn_lib_nt_keepcalls (int kc)
 
int misdn_lib_pid_restart (int pid)
 
int misdn_lib_port_block (int port)
 
int misdn_lib_port_is_nt (int port)
 
int misdn_lib_port_is_pri (int port)
 
int misdn_lib_port_restart (int port)
 
int misdn_lib_port_unblock (int port)
 
int misdn_lib_port_up (int port, int check)
 
void misdn_lib_reinit_nt_stack (int port)
 
void misdn_lib_release (struct misdn_bchannel *bc)
 
int misdn_lib_send_event (struct misdn_bchannel *bc, enum event_e event)
 
int misdn_lib_send_restart (int port, int channel)
 
void misdn_lib_send_tone (struct misdn_bchannel *bc, enum tone_e tone)
 
void misdn_lib_split_bridge (struct misdn_bchannel *bc1, struct misdn_bchannel *bc2)
 
void misdn_lib_tone_generator_start (struct misdn_bchannel *bc)
 
void misdn_lib_tone_generator_stop (struct misdn_bchannel *bc)
 
int misdn_lib_tx2misdn_frm (struct misdn_bchannel *bc, void *data, int len)
 
void misdn_make_dummy (struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
 
static void misdn_send_lock (struct misdn_bchannel *bc)
 
static void misdn_send_unlock (struct misdn_bchannel *bc)
 
void misdn_split_conf (struct misdn_bchannel *bc, int conf_id)
 
void misdn_tx_jitter (struct misdn_bchannel *bc, int len)
 
static void prepare_bc (struct misdn_bchannel *bc, int channel)
 
static int release_cr (struct misdn_stack *stack, mISDNuser_head_t *hh)
 
static int send_msg (int midev, struct misdn_bchannel *bc, msg_t *dmsg)
 
static int set_chan_in_stack (struct misdn_stack *stack, int channel)
 
static int setup_bc (struct misdn_bchannel *bc)
 
static void stack_destroy (struct misdn_stack *stack)
 
void stack_holder_add (struct misdn_stack *stack, struct misdn_bchannel *holder)
 
struct misdn_bchannelstack_holder_find (struct misdn_stack *stack, unsigned long l3id)
 
void stack_holder_remove (struct misdn_stack *stack, struct misdn_bchannel *holder)
 
static struct misdn_stackstack_init (int midev, int port, int ptp)
 
void te_lib_destroy (int midev)
 
static int te_lib_init (void)
 
static int test_inuse (struct misdn_bchannel *bc)
 

Variables

enum event_response_e(* cb_event )(enum event_e event, struct misdn_bchannel *bc, void *user_data)
 
int(* cb_jb_empty )(struct misdn_bchannel *bc, char *buffer, int len)
 
void(* cb_log )(int level, int port, char *tmpl,...)
 
static int entity
 
static char flip_table [256]
 
static struct misdn_libglob_mgr
 
static enum global_states global_state =MISDN_INITIALIZING
 
static sem_t handler_started
 
struct isdn_msg msgs_g []
 
static int mypid =1
 
static int new_te_id = 0
 
static int nt_err_cnt =0
 
static char tone_425_flip [TONE_425_SIZE]
 
static char tone_silence_flip [TONE_SILENCE_SIZE]
 

Detailed Description

Interface to mISDN.

Author
Christian Richter crich[email protected]@ber[email protected]onet.[email protected]com

Definition in file isdn_lib.c.

Macro Definition Documentation

◆ ARRAY_LEN

#define ARRAY_LEN (   a)    (sizeof(a) / sizeof(a[0]))

Definition at line 42 of file isdn_lib.c.

Referenced by __analog_ss_thread(), __ast_cli_generator(), __init_manager(), __unload_module(), _sip_show_peer(), aco_init(), action_dahdishowchannels(), action_events(), add_exten_to_pattern_tree(), add_required_respheader(), add_static_payload(), ademco_verify_checksum(), adpcm_sample(), alarm2str(), alaw_sample(), allocate_dns_record(), analog_cidtype_to_str(), analog_sigtype_to_str(), analog_ss_thread(), analog_str_to_cidtype(), analog_str_to_sigtype(), analyse_softmix_stats(), ao2_container_unregister(), aoc_s_add_entry(), aoc_shutdown(), ast_aoc_add_unit_entry(), ast_aoc_cli_init(), ast_ari_applications_subscribe_cb(), ast_ari_applications_unsubscribe_cb(), ast_ari_asterisk_get_info_cb(), ast_ari_bridges_add_channel_cb(), ast_ari_bridges_play_cb(), ast_ari_bridges_play_with_id_cb(), ast_ari_bridges_remove_channel_cb(), ast_ari_channels_play_cb(), ast_ari_channels_play_with_id_cb(), ast_ari_cli_register(), ast_ari_cli_unregister(), ast_ari_events_event_websocket_ws_attempted_cb(), ast_ari_events_event_websocket_ws_established_cb(), ast_ari_events_user_event_cb(), ast_bridge_channel_feature_digit(), ast_bridge_features_do(), ast_bridge_features_enable(), ast_bridge_features_register(), ast_bridge_features_unregister(), ast_bridge_interval_register(), ast_bridge_interval_unregister(), ast_bridging_init(), ast_builtins_init(), ast_cause2str(), ast_cel_str_to_event_type(), ast_channels_init(), ast_cli_netstats(), ast_codec_init(), ast_compile_ael2(), ast_connected_line_source_describe(), ast_connected_line_source_name(), ast_connected_line_source_parse(), ast_describe_caller_presentation(), ast_dsp_set_call_progress_zone(), ast_dynamic_logger_level(), ast_event_get_ie_pltype(), ast_event_get_ie_type_name(), ast_event_get_type_name(), ast_extension_state2str(), ast_file_init(), ast_get_http_method(), ast_hook_send_action(), ast_http_ftype2mtype(), ast_image_init(), ast_jb_get_impl(), ast_local_init(), ast_logger_get_channels(), ast_logger_unregister_level(), ast_media_cache_init(), ast_msg_data_alloc2(), ast_named_caller_presentation(), ast_parse_caller_presentation(), ast_party_name_charset_describe(), ast_party_name_charset_parse(), ast_party_name_charset_str(), ast_presence_state2str(), ast_presence_state_val(), ast_redirecting_reason_describe(), ast_redirecting_reason_name(), ast_redirecting_reason_parse(), ast_res_pjsip_cleanup_options_handling(), ast_res_pjsip_destroy_configuration(), ast_res_pjsip_init_options_handling(), ast_res_pjsip_initialize_configuration(), ast_rtp_instance_extmap_get_uri(), ast_rtp_instance_extmap_negotiate(), ast_security_event_severity_get_name(), ast_sendtext(), ast_sip_destroy_cli(), ast_sip_destroy_distributor(), ast_sip_destroy_scheduler(), ast_sip_destroy_sorcery_auth(), ast_sip_destroy_sorcery_location(), ast_sip_destroy_sorcery_transport(), ast_sip_get_contact_short_status_label(), ast_sip_get_contact_status_label(), ast_sip_get_distributor_serializer(), ast_sip_initialize_cli(), ast_sip_initialize_distributor(), ast_sip_initialize_scheduler(), ast_sip_initialize_sorcery_auth(), ast_sip_initialize_sorcery_location(), ast_sip_initialize_sorcery_transport(), ast_state_chan2dev(), ast_str2cause(), ast_str2tos(), ast_str_retrieve_variable(), ast_syslog_facility(), ast_syslog_facility_name(), ast_syslog_priority(), ast_syslog_priority_from_loglevel(), ast_syslog_priority_name(), AST_TEST_DEFINE(), ast_test_init(), ast_timing_init(), ast_to_misdn_reason(), ast_tos2str(), ast_tps_init(), ast_translate_init(), ast_utils_init(), ast_xmldoc_printable(), astdb_atexit(), astdb_init(), asterisk_daemon(), astman_append_headers(), astobj2_cleanup(), astobj2_init(), attended_transfer_dtor(), authority_to_str(), autopause2int(), available(), bearer2str(), block_msg_header(), bridge_channel_feature_digit_add(), bridge_cleanup(), bridge_snapshot_update(), bridges_scrape_cb(), build_cfg(), build_expression_queue(), cache_get_callno_locked(), callerid_read(), callerid_write(), cb_events(), cdr_engine_shutdown(), cel_snapshot_update_cb(), chan_pjsip_sendtext(), channel_snapshot_update(), channels_scrape_cb(), channels_shutdown(), check_blacklist(), cleanup_module(), clear_l3(), cli_init(), cli_shutdown(), cli_unload_cb(), close_logger(), codec_choose_from_prefs(), codec_pref_remove(), codec_pref_remove_index(), codec_shutdown(), common_exec(), complete_dpreply(), complete_ulimit(), conf_destroy_config(), conf_exec(), conf_load_config(), config_shutdown(), connectedline_read(), connectedline_write(), container_init(), convert_attribute_name_from_ldap(), convert_attribute_name_to_ldap(), corosync_show_config(), corosync_show_members(), cpg_confchg_cb(), crypto_init(), destroy_escs(), destroy_peer(), determine_starting_point(), dispatch_thread_handler(), distributor_pool_setup(), distributor_pool_shutdown(), do_message(), dtmf_features_flags_to_string(), dump_cause(), dump_chan_list(), dump_ies(), dundi_eid_zero(), dundi_ie2str(), dundi_query_read(), dundi_showframe(), empty_chan_in_stack(), endpoints_scrape_cb(), event2str(), exceptional_accept(), ext_cmp_pattern(), fac2str(), file_shutdown(), fill_rxgain(), fill_txgain(), find_alias(), find_bc_by_l3id(), find_bc_by_masked_l3id(), find_cache(), find_free_chan_in_stack(), find_full_alias(), find_sip_method(), find_subscription_type(), frame_drop_helper(), frame_trace_helper(), g722_sample(), g726_sample(), gather_softmix_stats(), gen_events(), generate_dns_answer(), generate_dns_header(), generate_dns_question(), get_allowed_field(), get_chan_by_ast_name(), get_esc(), get_folder_by_name(), get_perm(), get_pjsip_method(), geteventbyname(), getjustifybyname(), handle_cli_dynamic_level_test(), handle_cli_iax2_show_cache(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_stats(), handle_cli_misdn_send_facility(), handle_cli_performance_test(), handle_cli_ulimit(), handle_input(), handle_jack_audio(), handle_logger_set_level(), handle_logger_show_channels(), handle_request_bye(), handle_request_invite(), hfp_parse_ciev(), hfp_parse_cind_indicator(), hfp_parse_clip(), hook_event_cb(), iax2_codec_pref_append_bitfield(), iax2_codec_pref_best_bitfield2cap(), iax2_codec_pref_convert(), iax2_codec_pref_format_bitfield_to_order_value(), iax2_codec_pref_index(), iax2_codec_pref_order_value_to_format_bitfield(), iax2_codec_pref_prepend(), iax2_codec_pref_remove_missing(), iax2_codec_pref_to_cap(), iax2_format_compatibility_best(), iax_ie2str(), iax_provflags2str(), iax_showframe(), iax_str2flags(), image_shutdown(), init_logger(), initialize_escs(), int2strat(), is_digest_algorithm_supported(), is_msg_var_blocked(), is_reserved_word(), jack_status_to_str(), jb_choose_impl(), jingle_action_hook(), jingle_action_session_terminate(), jingle_hangup(), keyset_translatebitmask(), load_features_config(), load_general_config(), load_module(), load_parking_ui(), load_pbx(), load_pbx_app(), load_pbx_builtins(), load_pbx_functions_cli(), load_pbx_hangup_handler(), load_pbx_switch(), load_pbx_variables(), loadresult2str(), local_ast_moh_start(), local_shutdown(), logger_register_level(), main(), main_atexit(), make_components(), manager_shutdown(), mbox(), media_cache_shutdown(), milliwatt_generate(), minivm_accmess_exec(), minivm_greet_exec(), minivm_mwi_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_get_ch_state(), misdn_lib_get_free_bc(), misdn_lib_init(), mkintf(), mute_fragment(), nominal_test(), not_allowed(), off_nominal_test(), parse_naptr(), parse_sip_options(), pjsip_channel_cli_register(), pjsip_channel_cli_unregister(), play_message_by_id(), process_dahdi(), process_echocancel(), process_opcode(), process_returncode(), prometheus_config_post_apply(), queue_voice_frame(), rb_ao2_destroy(), reason_code_to_cause(), reason_code_to_str(), redirecting_read(), redirecting_write(), register_config_cli(), reload(), res_sdp_srtp_get_attr(), rotate_file(), send_message(), sendtext_exec(), set_chan_in_stack(), set_event(), set_next_mime_type(), set_queue_result(), sip_reason_code_to_str(), sip_show_channel(), slin16_sample(), slin8_sample(), stasis_cleanup(), stasis_init(), stir_shaken_certificate_load(), stir_shaken_certificate_unload(), stir_shaken_general_load(), stir_shaken_general_unload(), stir_shaken_store_load(), stir_shaken_store_unload(), str2desc(), str2limit(), strat2int(), strings_to_mask(), sub_channel_update_handler(), subscription_type2str(), test_chan_string(), test_chan_variable(), test_cleanup(), test_config_validity(), test_dtmf_amplitude_sweep(), test_dtmf_twist_sweep(), test_new_subscribe(), test_tone_amplitude_sweep(), test_traversal_nonsorted(), test_traversal_sorted(), threadstorage_init(), timing_shutdown(), tls_method_to_str(), tps_shutdown(), translate_shutdown(), transmit_softkeysetres(), try_merge_optimize_out(), two_bridge_attended_transfer(), udptl_rx_packet(), ulaw_sample(), unload_features_config(), unload_module(), unload_parking_ui(), unload_pbx(), unload_pbx_app(), unload_pbx_builtins(), unload_pbx_functions_cli(), unload_pbx_hangup_handler(), unload_pbx_switch(), unload_pbx_variables(), update_modem_bits(), user_authority_to_str(), utils_shutdown(), validate_metric(), vm_mailbox_snapshot_create(), wait_for_winner(), write_config_file(), xmldoc_get_syntax_type(), xmldoc_has_specialtags(), xmldoc_parse_specialtags(), xmldoc_update_config_option(), and xmpp_action_hook().

◆ ECHOCAN_OFF

#define ECHOCAN_OFF   124

Definition at line 230 of file isdn_lib.c.

Referenced by manager_ec_disable().

◆ ECHOCAN_ON

#define ECHOCAN_ON   123

Definition at line 229 of file isdn_lib.c.

Referenced by manager_ec_enable().

◆ ISDN_PID_L3_B_USER

#define ISDN_PID_L3_B_USER   0x430000ff

Definition at line 246 of file isdn_lib.c.

Referenced by setup_bc().

◆ ISDN_PID_L4_B_USER

#define ISDN_PID_L4_B_USER   0x440000ff

Definition at line 247 of file isdn_lib.c.

Referenced by setup_bc().

◆ MISDN_DEBUG

#define MISDN_DEBUG   0

Definition at line 233 of file isdn_lib.c.

◆ MISDN_DSP

#define MISDN_DSP

◆ MISDN_GEN_SILENCE

#define MISDN_GEN_SILENCE

◆ MISDN_IBUF_SIZE

#define MISDN_IBUF_SIZE   512

Definition at line 250 of file isdn_lib.c.

Referenced by init_bc().

◆ RETURN

#define RETURN (   a,
  b 
)    {retval=a; goto b;}

Definition at line 3507 of file isdn_lib.c.

Referenced by misdn_lib_send_event().

◆ TONE_ALERT_CNT

#define TONE_ALERT_CNT   41 /* 1 Sec */

Definition at line 253 of file isdn_lib.c.

◆ TONE_ALERT_SILENCE_CNT

#define TONE_ALERT_SILENCE_CNT   200 /* 4 Sec */

Definition at line 254 of file isdn_lib.c.

◆ TONE_BUSY_CNT

#define TONE_BUSY_CNT   20 /* ? */

Definition at line 256 of file isdn_lib.c.

◆ TONE_BUSY_SILENCE_CNT

#define TONE_BUSY_SILENCE_CNT   48 /* ? */

Definition at line 257 of file isdn_lib.c.

Enumeration Type Documentation

◆ global_states

Enumerator
MISDN_INITIALIZING 
MISDN_INITIALIZED 

Definition at line 194 of file isdn_lib.c.

Function Documentation

◆ bc_next_state_change()

static void bc_next_state_change ( struct misdn_bchannel bc,
enum bchannel_state  state 
)
static

Definition at line 659 of file isdn_lib.c.

References bc_state2str(), cb_log, misdn_bchannel::next_bc_state, misdn_bchannel::port, and state.

Referenced by misdn_lib_bridge().

660 {
661  cb_log(5,bc->port,"BC_NEXT_STATE_CHANGE: from:%s to:%s\n",
663  bc_state2str(state) );
664 
665  bc->next_bc_state=state;
666 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
char * bc_state2str(enum bchannel_state state)
Definition: isdn_lib.c:617
enum bchannel_state next_bc_state
This is used as a pending bridge join request for when bc_state becomes BCHAN_ACTIVATED.
Definition: isdn_lib.h:550
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ bc_state2str()

char* bc_state2str ( enum bchannel_state  state)

Definition at line 617 of file isdn_lib.c.

References BCHAN_ACTIVATED, BCHAN_BRIDGED, BCHAN_CLEANED, BCHAN_EMPTY, BCHAN_ERROR, and BCHAN_RELEASE.

Referenced by bc_next_state_change(), bc_state_change(), cb_events(), misdn_lib_send_event(), misdn_lib_split_bridge(), misdn_lib_tx2misdn_frm(), print_bc_info(), and setup_bc().

617  {
618  int i;
619 
620  struct bchan_state_s {
621  char *n;
622  enum bchannel_state s;
623  } states[] = {
624  {"BCHAN_CLEANED", BCHAN_CLEANED },
625  {"BCHAN_EMPTY", BCHAN_EMPTY},
626  {"BCHAN_ACTIVATED", BCHAN_ACTIVATED},
627  {"BCHAN_BRIDGED", BCHAN_BRIDGED},
628  {"BCHAN_RELEASE", BCHAN_RELEASE},
629  {"BCHAN_ERROR", BCHAN_ERROR}
630  };
631 
632  for (i=0; i< sizeof(states)/sizeof(struct bchan_state_s); i++)
633  if ( states[i].s == state)
634  return states[i].n;
635 
636  return "UNKNOWN";
637 }
bchannel_state
Definition: isdn_lib.h:78

◆ bc_state_change()

void bc_state_change ( struct misdn_bchannel bc,
enum bchannel_state  state 
)

Definition at line 639 of file isdn_lib.c.

References misdn_bchannel::bc_state, bc_state2str(), BCHAN_ACTIVATED, BCHAN_BRIDGED, BCHAN_EMPTY, cb_log, misdn_bchannel::conf_id, misdn_bchannel::l3_id, misdn_join_conf(), misdn_bchannel::next_bc_state, misdn_bchannel::port, and state.

Referenced by clean_up_bc(), init_bc(), manager_bchannel_deactivate(), misdn_join_conf(), misdn_lib_send_event(), misdn_split_conf(), and setup_bc().

640 {
641  cb_log(5,bc->port,"BC_STATE_CHANGE: l3id:%x from:%s to:%s\n",
642  bc->l3_id,
643  bc_state2str(bc->bc_state),
644  bc_state2str(state) );
645 
646  switch (state) {
647  case BCHAN_ACTIVATED:
648  if (bc->next_bc_state == BCHAN_BRIDGED) {
649  misdn_join_conf(bc, bc->conf_id);
651  return;
652  }
653  default:
654  bc->bc_state=state;
655  break;
656  }
657 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
int conf_id
Bridging conference ID.
Definition: isdn_lib.h:553
char * bc_state2str(enum bchannel_state state)
Definition: isdn_lib.c:617
enum bchannel_state next_bc_state
This is used as a pending bridge join request for when bc_state becomes BCHAN_ACTIVATED.
Definition: isdn_lib.h:550
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
void misdn_join_conf(struct misdn_bchannel *bc, int conf_id)
Definition: isdn_lib.c:4705
enum bchannel_state bc_state
Current B Channel state.
Definition: isdn_lib.h:547
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
int l3_id
Layer 3 process ID.
Definition: isdn_lib.h:399

◆ bchdev_echocancel_activate()

int bchdev_echocancel_activate ( struct misdn_bchannel dev)

◆ bchdev_echocancel_deactivate()

void bchdev_echocancel_deactivate ( struct misdn_bchannel dev)

◆ bearer2str()

static char* bearer2str ( int  cap)
static

Definition at line 290 of file isdn_lib.c.

References INFO_CAPABILITY_AUDIO_3_1K, INFO_CAPABILITY_DIGITAL_RESTRICTED, INFO_CAPABILITY_DIGITAL_UNRESTRICTED, and INFO_CAPABILITY_SPEECH.

Referenced by misdn_lib_log_ies().

290  {
291  static char *bearers[]={
292  "Speech",
293  "Audio 3.1k",
294  "Unres Digital",
295  "Res Digital",
296  "Unknown Bearer"
297  };
298 
299  switch (cap) {
301  return bearers[0];
302  break;
304  return bearers[1];
305  break;
307  return bearers[2];
308  break;
310  return bearers[3];
311  break;
312  default:
313  return bearers[4];
314  break;
315  }
316 }

◆ clean_up_bc()

static int clean_up_bc ( struct misdn_bchannel bc)
static

Definition at line 815 of file isdn_lib.c.

References misdn_bchannel::b_stid, misdn_bchannel::bc_state, bc_state_change(), BCHAN_CLEANED, buff, cb_log, get_stack_by_bc(), misdn_bchannel::layer_id, manager_bchannel_deactivate(), manager_ec_disable(), misdn_stack::midev, NULL, misdn_bchannel::pid, misdn_stack::port, and misdn_bchannel::port.

Referenced by clear_l3(), handle_cr(), handle_event_nt(), handle_frm_te(), misdn_lib_release(), misdn_lib_send_event(), and misdn_lib_send_restart().

816 {
817  int ret=0;
818  unsigned char buff[32];
819  struct misdn_stack * stack;
820 
821  cb_log(3, bc->port, "$$$ CLEANUP CALLED pid:%d\n", bc->pid);
822 
823  stack=get_stack_by_bc(bc);
824 
825  if (!stack) return -1;
826 
827  switch (bc->bc_state ) {
828  case BCHAN_CLEANED:
829  cb_log(5, stack->port, "$$$ Already cleaned up bc with stid :%x\n", bc->b_stid);
830  return -1;
831 
832  default:
833  break;
834  }
835 
836  cb_log(2, stack->port, "$$$ Cleaning up bc with stid :%x pid:%d\n", bc->b_stid, bc->pid);
837 
838  manager_ec_disable(bc);
839 
841 
842  mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
843 
844  bc->b_stid = 0;
846 
847  return ret;
848 }
void manager_bchannel_deactivate(struct misdn_bchannel *bc)
Definition: isdn_lib.c:4351
int midev
mISDN device handle returned by mISDN_open()
#define NULL
Definition: resample.c:96
int layer_id
B Channel mISDN driver layer ID from mISDN_new_layer()
Definition: isdn_lib.h:379
void manager_ec_disable(struct misdn_bchannel *bc)
Definition: isdn_lib.c:4677
void bc_state_change(struct misdn_bchannel *bc, enum bchannel_state state)
Definition: isdn_lib.c:639
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
int b_stid
B Channel mISDN driver stack ID.
Definition: isdn_lib.h:374
int pid
B channel process ID (1-5000)
Definition: isdn_lib.h:402
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
enum bchannel_state bc_state
Current B Channel state.
Definition: isdn_lib.h:547
static unsigned char * buff
Definition: chan_unistim.c:259
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ clear_l3()

static void clear_l3 ( struct misdn_stack stack)
static

Definition at line 852 of file isdn_lib.c.

References ARRAY_LEN, misdn_stack::b_num, misdn_stack::bc, cb_event, clean_up_bc(), empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, misdn_bchannel::in_use, MAX_BCHANS, MISDN_INITIALIZED, and NULL.

Referenced by handle_mgmt(), and misdn_lib_port_restart().

853 {
854  int i;
855 
857  for (i = 0; i <= stack->b_num; ++i) {
858  cb_event(EVENT_CLEANUP, &stack->bc[i], NULL);
859  empty_bc(&stack->bc[i]);
860  clean_up_bc(&stack->bc[i]);
861  empty_chan_in_stack(stack, i + 1);
862  stack->bc[i].in_use = 0;
863  }
864 #if defined(AST_MISDN_ENHANCEMENTS)
865  for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) {
866  empty_bc(&stack->bc[i]);
867  empty_chan_in_stack(stack, i + 1);
868  stack->bc[i].in_use = 0;
869  }
870 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
871  }
872 }
static void empty_chan_in_stack(struct misdn_stack *stack, int channel)
Definition: isdn_lib.c:605
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static int clean_up_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:815
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
static enum global_states global_state
Definition: isdn_lib.c:199
#define NULL
Definition: resample.c:96
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
static void empty_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:679
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
#define MAX_BCHANS
Definition: isdn_lib.h:76

◆ create_l2msg()

static msg_t* create_l2msg ( int  prim,
int  dinfo,
int  size 
)
static

Definition at line 349 of file isdn_lib.c.

References NULL.

Referenced by misdn_lib_get_l2_down(), and misdn_lib_get_l2_up().

350 {
351  int i = 0;
352  msg_t *dmsg;
353 
354  while(i < 10)
355  {
356  dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
357  if (dmsg)
358  return(dmsg);
359 
360  if (!i)
361  printf("cannot allocate memory, trying again...\n");
362  i++;
363  usleep(300000);
364  }
365  printf("cannot allocate memory, system overloaded.\n");
366  exit(-1);
367 }
#define NULL
Definition: resample.c:96

◆ create_l3msg()

msg_t* create_l3msg ( int  prim,
int  mt,
int  dinfo,
int  size,
int  ntmode 
)

Definition at line 371 of file isdn_lib.c.

References NULL.

Referenced by build_alerting(), build_connect(), build_connect_acknowledge(), build_disconnect(), build_facility(), build_hold(), build_hold_acknowledge(), build_hold_reject(), build_information(), build_notify(), build_proceeding(), build_progress(), build_release(), build_release_complete(), build_restart(), build_resume(), build_resume_acknowledge(), build_resume_reject(), build_retrieve(), build_retrieve_acknowledge(), build_retrieve_reject(), build_setup(), build_setup_acknowledge(), build_status(), build_status_enquiry(), build_suspend(), build_suspend_acknowledge(), build_suspend_reject(), build_timeout(), build_user_information(), and handle_event_nt().

372 {
373  int i = 0;
374  msg_t *dmsg;
375  Q931_info_t *qi;
376  iframe_t *frm;
377 
378  if (!ntmode)
379  size = sizeof(Q931_info_t)+2;
380 
381  while(i < 10) {
382  if (ntmode) {
383  dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
384  if (dmsg) {
385  return(dmsg);
386  }
387  } else {
388  dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
389  if (dmsg)
390  {
391  memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
392  frm = (iframe_t *)dmsg->data;
393  frm->prim = prim;
394  frm->dinfo = dinfo;
395  qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
396  qi->type = mt;
397  return(dmsg);
398  }
399  }
400 
401  if (!i) printf("cannot allocate memory, trying again...\n");
402  i++;
403  usleep(300000);
404  }
405  printf("cannot allocate memory, system overloaded.\n");
406  exit(-1);
407 }
#define NULL
Definition: resample.c:96

◆ create_process()

static int create_process ( int  midev,
struct misdn_bchannel bc 
)
static

Definition at line 976 of file isdn_lib.c.

References cb_log, misdn_bchannel::channel, misdn_bchannel::channel_preselected, misdn_bchannel::dec, find_free_chan_in_stack(), get_stack_by_bc(), misdn_bchannel::l3_id, MAXPROCS, misdn_stack::nt, misdn_stack::port, misdn_stack::pri, misdn_stack::procids, misdn_stack::ptp, misdn_bchannel::te_choose_channel, and misdn_stack::upper_id.

Referenced by misdn_lib_send_event().

977 {
978  iframe_t ncr;
979  int l3_id;
980  int proc_id;
981  struct misdn_stack *stack;
982 
983  stack = get_stack_by_bc(bc);
984  if (stack->nt) {
985  if (find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, 0) < 0) {
986  return -1;
987  }
988  cb_log(4, stack->port, " --> found channel: %d\n", bc->channel);
989 
990  for (proc_id = 0; proc_id < MAXPROCS; ++proc_id) {
991  if (stack->procids[proc_id] == 0) {
992  break;
993  }
994  }
995  if (proc_id == MAXPROCS) {
996  cb_log(0, stack->port, "Couldn't Create New ProcId.\n");
997  return -1;
998  }
999 
1000  stack->procids[proc_id] = 1;
1001 
1002  l3_id = 0xff00 | proc_id;
1003  bc->l3_id = l3_id;
1004  cb_log(3, stack->port, " --> new_l3id %x\n", l3_id);
1005  } else {
1006  if ((stack->pri && stack->ptp) || bc->te_choose_channel) {
1007  /* we know exactly which channels are in use */
1008  if (find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, bc->dec) < 0) {
1009  return -1;
1010  }
1011  cb_log(2, stack->port, " --> found channel: %d\n", bc->channel);
1012  } else {
1013  /* other phones could have made a call also on this port (ptmp) */
1014  bc->channel = 0xff;
1015  }
1016 
1017  /* if we are in te-mode, we need to create a process first */
1018  if (++new_te_id > 0xffff) {
1019  new_te_id = 0x0001;
1020  }
1021 
1022  l3_id = (entity << 16) | new_te_id;
1023  bc->l3_id = l3_id;
1024  cb_log(3, stack->port, "--> new_l3id %x\n", l3_id);
1025 
1026  /* send message */
1027  ncr.prim = CC_NEW_CR | REQUEST;
1028  ncr.addr = (stack->upper_id | FLG_MSG_DOWN);
1029  ncr.dinfo = l3_id;
1030  ncr.len = 0;
1031  mISDN_write(midev, &ncr, mISDN_HEADER_LEN + ncr.len, TIMEOUT_1SEC);
1032  }
1033 
1034  return l3_id;
1035 }
int upper_id
Upper layer mISDN ID (addr) (Layer 2/4)
int procids[MAXPROCS]
CR Process ID allocation table. TRUE if ID allocated.
int midev
mISDN device handle returned by mISDN_open()
static int new_te_id
Definition: isdn_lib.c:874
static int entity
Definition: isdn_lib.c:259
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
Definition: isdn_lib.c:513
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
int dec
TRUE if allocate higher B channels first.
Definition: isdn_lib.h:395
int ptp
TRUE if Point-To-Point(PTP) (Point-To-Multipoint(PTMP) otherwise)
#define MAXPROCS
int nt
TRUE if NT side of protocol (TE otherwise)
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
int channel_preselected
TRUE if the B channel number is preselected.
Definition: isdn_lib.h:414
int te_choose_channel
TRUE if the TE side should choose the B channel to use.
Definition: isdn_lib.h:444
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
int l3_id
Layer 3 process ID.
Definition: isdn_lib.h:399

◆ do_tone()

static int do_tone ( struct misdn_bchannel bc,
int  len 
)
static

Definition at line 2282 of file isdn_lib.c.

References cb_event, cb_log, errno, EVENT_TONE_GENERATE, misdn_bchannel::generate_tone, len(), misdn_tx_jitter(), misdn_bchannel::nojitter, misdn_bchannel::tone_cnt, and misdn_lib::user_data.

Referenced by handle_bchan().

2283 {
2284  bc->tone_cnt=len;
2285 
2286  if (bc->generate_tone) {
2288 
2289  if ( !bc->nojitter ) {
2290  misdn_tx_jitter(bc,len);
2291  }
2292 
2293  return 1;
2294  }
2295 
2296  return 0;
2297 }
int tone_cnt
Number of tone samples to generate.
Definition: isdn_lib.h:544
void misdn_tx_jitter(struct misdn_bchannel *bc, int len)
Definition: isdn_lib.c:2330
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
void * user_data
Definition: isdn_lib.c:219
int nojitter
TRUE if we will not use the jitter buffer system.
Definition: isdn_lib.h:477
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int generate_tone
TRUE if tone generator allowed to start.
Definition: isdn_lib.h:541

◆ dump_chan_list()

static void dump_chan_list ( struct misdn_stack stack)
static

Definition at line 464 of file isdn_lib.c.

References ARRAY_LEN, misdn_stack::b_num, misdn_stack::bc, cb_log, misdn_stack::channels, misdn_bchannel::in_use, MAX_BCHANS, and misdn_stack::port.

Referenced by empty_chan_in_stack(), find_free_chan_in_stack(), handle_cr(), misdn_dump_chanlist(), and set_chan_in_stack().

465 {
466  int i;
467 
468  for (i = 0; i <= stack->b_num; ++i) {
469  cb_log(6, stack->port, "Idx:%d stack->cchan:%d in_use:%d Chan:%d\n",
470  i, stack->channels[i], stack->bc[i].in_use, i + 1);
471  }
472 #if defined(AST_MISDN_ENHANCEMENTS)
473  for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) {
474  if (stack->bc[i].in_use) {
475  cb_log(6, stack->port, "Idx:%d stack->cchan:%d REGISTER Chan:%d in_use\n",
476  i, stack->channels[i], i + 1);
477  }
478  }
479 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
480 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
char channels[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
Array of B channels in use (a[0] = B1). TRUE if B channel in use. (Must be dimensioned the same as st...
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
#define MAX_BCHANS
Definition: isdn_lib.h:76

◆ ec_chunk()

void ec_chunk ( struct misdn_bchannel bc,
unsigned char *  rxchunk,
unsigned char *  txchunk,
int  chunk_size 
)

◆ empty_bc()

static void empty_bc ( struct misdn_bchannel bc)
static

Set Default Bearer Caps

Definition at line 679 of file isdn_lib.c.

References misdn_bchannel::active, misdn_bchannel::AOCD_need_export, AST_CAUSE_NORMAL_CLEARING, misdn_bchannel::bframe_len, misdn_bchannel::caller, misdn_bchannel::capability, misdn_bchannel::cause, misdn_bchannel::channel, misdn_bchannel::channel_found, misdn_bchannel::conf_id, misdn_bchannel::connected, misdn_party_redirecting::count, misdn_bchannel::crypt, misdn_bchannel::crypt_key, misdn_bchannel::curprx, misdn_bchannel::curptx, misdn_bchannel::cw, misdn_bchannel::dec, misdn_bchannel::dialed, misdn_bchannel::display, misdn_bchannel::display_connected, misdn_bchannel::display_setup, misdn_bchannel::dummy, misdn_bchannel::early_bconnect, misdn_bchannel::ec_deftaps, misdn_bchannel::ec_enable, misdn_bchannel::fac_in, misdn_bchannel::fac_out, misdn_party_redirecting::from, misdn_bchannel::generate_tone, misdn_bchannel::hdlc, INFO_CAPABILITY_SPEECH, INFO_CODEC_ALAW, misdn_bchannel::info_dad, misdn_bchannel::infos_pending, misdn_bchannel::last_used, misdn_bchannel::law, mISDN_NOTIFY_CODE_INVALID, mISDN_REDIRECTING_REASON_UNKNOWN, misdn_bchannel::mode, misdn_party_id::name, misdn_bchannel::need_more_infos, misdn_bchannel::nodsp, misdn_bchannel::nojitter, misdn_bchannel::notify_description_code, NULL, misdn_party_dialing::number, misdn_party_id::number, misdn_party_id::number_plan, misdn_party_dialing::number_plan, misdn_party_id::number_type, misdn_party_dialing::number_type, NUMPLAN_ISDN, NUMTYPE_UNKNOWN, misdn_bchannel::orig, misdn_bchannel::out_cause, misdn_bchannel::outgoing_colp, misdn_party_id::presentation, misdn_bchannel::presentation, misdn_bchannel::progress_coding, misdn_bchannel::progress_indicator, misdn_bchannel::progress_location, misdn_bchannel::rate, misdn_party_redirecting::reason, misdn_bchannel::redirecting, misdn_bchannel::restart_channel, misdn_bchannel::rxgain, misdn_bchannel::send_dtmf, misdn_bchannel::sending_complete, misdn_bchannel::set_presentation, misdn_party_dialing::subaddress, misdn_party_id::subaddress, misdn_bchannel::te_choose_channel, misdn_bchannel::time_usec, misdn_party_redirecting::to, misdn_party_redirecting::to_changed, misdn_bchannel::tone_cnt, misdn_bchannel::txgain, misdn_bchannel::urate, misdn_bchannel::user1, misdn_bchannel::uu, and misdn_bchannel::uulen.

Referenced by clear_l3(), handle_cr(), handle_event_nt(), handle_frm_te(), init_bc(), manager_clean_bc(), misdn_lib_release(), misdn_lib_send_event(), and misdn_lib_send_restart().

680 {
681  bc->caller.presentation = 0; /* allowed */
684  bc->caller.name[0] = 0;
685  bc->caller.number[0] = 0;
686  bc->caller.subaddress[0] = 0;
687 
688  bc->connected.presentation = 0; /* allowed */
691  bc->connected.name[0] = 0;
692  bc->connected.number[0] = 0;
693  bc->connected.subaddress[0] = 0;
694 
695  bc->redirecting.from.presentation = 0; /* allowed */
698  bc->redirecting.from.name[0] = 0;
699  bc->redirecting.from.number[0] = 0;
700  bc->redirecting.from.subaddress[0] = 0;
701 
702  bc->redirecting.to.presentation = 0; /* allowed */
705  bc->redirecting.to.name[0] = 0;
706  bc->redirecting.to.number[0] = 0;
707  bc->redirecting.to.subaddress[0] = 0;
708 
710  bc->redirecting.count = 0;
711  bc->redirecting.to_changed = 0;
712 
713  bc->dummy=0;
714 
715  bc->bframe_len=0;
716 
717  bc->cw= 0;
718 
719  bc->dec=0;
720  bc->channel = 0;
721 
722  bc->sending_complete = 0;
723 
724  bc->restart_channel=0;
725 
726  bc->conf_id = 0;
727 
728  bc->need_more_infos = 0;
729 
730  bc->send_dtmf=0;
731  bc->nodsp=0;
732  bc->nojitter=0;
733 
734  bc->time_usec=0;
735 
736  bc->rxgain=0;
737  bc->txgain=0;
738 
739  bc->crypt=0;
740  bc->curptx=0; bc->curprx=0;
741 
742  bc->crypt_key[0] = 0;
743 
744  bc->generate_tone=0;
745  bc->tone_cnt=0;
746 
747  bc->active = 0;
748 
749  bc->early_bconnect = 1;
750 
751 #ifdef MISDN_1_2
752  *bc->pipeline = 0;
753 #else
754  bc->ec_enable = 0;
755  bc->ec_deftaps = 128;
756 #endif
757 
758  bc->AOCD_need_export = 0;
759 
760  bc->orig=0;
761 
764 
765  bc->display_connected = 0; /* none */
766  bc->display_setup = 0; /* none */
767 
768  bc->outgoing_colp = 0;/* pass */
769 
770  bc->presentation = 0; /* allowed */
771  bc->set_presentation = 0;
772 
774 
775  bc->progress_coding=0;
776  bc->progress_location=0;
777  bc->progress_indicator=0;
778 
779 #if defined(AST_MISDN_ENHANCEMENTS)
780  bc->div_leg_3_rx_wanted = 0;
781  bc->div_leg_3_tx_pending = 0;
782 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
783 
784 /** Set Default Bearer Caps **/
786  bc->law=INFO_CODEC_ALAW;
787  bc->mode=0;
788  bc->rate=0x10;
789  bc->user1=0;
790  bc->urate=0;
791 
792  bc->hdlc=0;
793 
796  bc->dialed.number[0] = 0;
797  bc->dialed.subaddress[0] = 0;
798 
799  bc->info_dad[0] = 0;
800  bc->display[0] = 0;
801  bc->infos_pending[0] = 0;
802  bc->uu[0]=0;
803  bc->uulen=0;
804 
805  bc->fac_in.Function = Fac_None;
806  bc->fac_out.Function = Fac_None;
807 
808  bc->te_choose_channel = 0;
809  bc->channel_found= 0;
810 
811  gettimeofday(&bc->last_used, NULL);
812 }
int display_setup
Put a display ie in the SETUP message.
Definition: isdn_lib.h:585
struct FacParm fac_out
Outbound FACILITY message function type and contents.
Definition: isdn_lib.h:512
char number[MISDN_MAX_NUMBER_LEN]
Phone number (Address)
Definition: isdn_lib.h:298
int nodsp
TRUE if we will not use jollys dsp.
Definition: isdn_lib.h:474
int txgain
Tx gain setting (range -8 to 8)
Definition: isdn_lib.h:708
int ec_enable
TRUE if the echo cancellor is enabled.
Definition: isdn_lib.h:688
int tone_cnt
Number of tone samples to generate.
Definition: isdn_lib.h:544
int presentation
User set presentation restriction code 0=Allowed, 1=Restricted, 2=Unavailable.
Definition: isdn_lib.h:600
int uulen
User-User information string length in uu[].
Definition: isdn_lib.h:666
char uu[256]
User-User information string.
Definition: isdn_lib.h:663
int dummy
TRUE if this is a dummy BC record.
Definition: isdn_lib.h:361
int restart_channel
B channel to restart if received a RESTART message.
Definition: isdn_lib.h:408
int bframe_len
B channel speech sample data buffer size.
Definition: isdn_lib.h:435
int mode
Q.931 Bearer Capability IE Transfer Mode field. Initialized to 0 (Circuit). Altered by incoming SETUP...
Definition: isdn_lib.h:619
int cw
TRUE if call waiting.
Definition: isdn_lib.h:426
int hdlc
TRUE if call made in digital HDLC mode.
Definition: isdn_lib.h:635
int outgoing_colp
Select what to do with outgoing COLP information.
Definition: isdn_lib.h:594
int presentation
Number presentation restriction code 0=Allowed, 1=Restricted, 2=Unavailable.
Definition: isdn_lib.h:277
int sending_complete
TRUE if all digits necessary to complete the call are available. No more INFORMATION messages are nee...
Definition: isdn_lib.h:470
char crypt_key[255]
Blowfish encryption key string (secret)
Definition: isdn_lib.h:529
int capability
SETUP message bearer capability field code value.
Definition: isdn_lib.h:609
int AOCD_need_export
TRUE if AOCDtype and AOCD data are ready to export to Asterisk.
Definition: isdn_lib.h:521
#define NULL
Definition: resample.c:96
struct misdn_party_id to
Where the call is being redirected toward (Sent to the calling party)
Definition: isdn_lib.h:310
int progress_location
Progress Indicator IE location field.
Definition: isdn_lib.h:487
int set_presentation
TRUE if the user set the presentation restriction code.
Definition: isdn_lib.h:603
char number[MISDN_MAX_NUMBER_LEN]
Dialed/Called Phone Number (Address)
Definition: isdn_lib.h:266
char display[84]
Display message that can be displayed by the user phone.
Definition: isdn_lib.h:642
int conf_id
Bridging conference ID.
Definition: isdn_lib.h:553
char subaddress[MISDN_MAX_SUBADDRESS_LEN]
Dialed/Called Subaddress number.
Definition: isdn_lib.h:269
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
enum mISDN_NUMBER_TYPE number_type
Type-of-number in ISDN terms for the number.
Definition: isdn_lib.h:285
int display_connected
Put a display ie in the CONNECT message.
Definition: isdn_lib.h:573
int nojitter
TRUE if we will not use the jitter buffer system.
Definition: isdn_lib.h:477
char infos_pending[MISDN_MAX_NUMBER_LEN]
Collected digits to go into info_dad[] while waiting for a SETUP_ACKNOWLEDGE to come in...
Definition: isdn_lib.h:653
struct misdn_party_id caller
Originating/Caller ID information struct.
Definition: isdn_lib.h:343
char name[MISDN_MAX_NAME_LEN]
Subscriber Name.
Definition: isdn_lib.h:295
int rxgain
Rx gain setting (range -8 to 8)
Definition: isdn_lib.h:714
int progress_coding
Progress Indicator IE coding standard field.
Definition: isdn_lib.h:482
struct misdn_party_id connected
Connected-Party/Connected-Line ID information struct.
Definition: isdn_lib.h:353
struct misdn_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition: isdn_lib.h:307
int dec
TRUE if allocate higher B channels first.
Definition: isdn_lib.h:395
enum mISDN_NUMBER_TYPE number_type
Type-of-number in ISDN terms for the dialed/called number.
Definition: isdn_lib.h:260
char subaddress[MISDN_MAX_SUBADDRESS_LEN]
Subaddress number.
Definition: isdn_lib.h:301
int channel_found
TRUE if the channel was allocated from the available B channels.
Definition: isdn_lib.h:697
int send_dtmf
TRUE if we should produce DTMF tones ourselves.
Definition: isdn_lib.h:457
struct misdn_party_redirecting redirecting
Redirecting information struct (Where a call diversion or transfer was invoked)
Definition: isdn_lib.h:358
int urate
Q.931 Bearer Capability IE Layer 1 User Rate field.
Definition: isdn_lib.h:629
struct misdn_party_dialing dialed
Dialed/Called information struct.
Definition: isdn_lib.h:337
int active
Seems to have been intended for something to do with the jitter buffer.
Definition: isdn_lib.h:537
int to_changed
TRUE if the redirecting.to information has changed.
Definition: isdn_lib.h:319
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
int out_cause
Q.931 Cause for disconnection code (sent)
Definition: isdn_lib.h:677
enum mISDN_REDIRECTING_REASON reason
Reason a call is being redirected (Q.931 field value)
Definition: isdn_lib.h:313
int need_more_infos
TRUE if we send SETUP_ACKNOWLEDGE on incoming calls anyway (instead of PROCEEDING).
Definition: isdn_lib.h:465
int user1
Q.931 Bearer Capability IE User Information Layer 1 Protocol field code.
Definition: isdn_lib.h:624
enum mISDN_NOTIFY_CODE notify_description_code
Notification indicator ie description code.
Definition: isdn_lib.h:606
int progress_indicator
Progress Indicator IE progress description field. Used to determine if there is an inband audio messa...
Definition: isdn_lib.h:492
int rate
Q.931 Bearer Capability IE Information Transfer Rate field. Initialized to 0x10 (64kbit). Altered by incoming SETUP messages.
Definition: isdn_lib.h:616
int ec_deftaps
Number of taps in the echo cancellor when enabled.
Definition: isdn_lib.h:693
int cause
Q.931 Cause for disconnection code (received)
Definition: isdn_lib.h:671
char info_dad[MISDN_MAX_NUMBER_LEN]
Current overlap dialing digits to/from INFORMATION messages.
Definition: isdn_lib.h:650
int te_choose_channel
TRUE if the TE side should choose the B channel to use.
Definition: isdn_lib.h:444
struct timeval last_used
Time when empty_bc() last called on this record.
Definition: isdn_lib.h:423
int law
Companding ALaw/uLaw encoding (INFO_CODEC_ALAW / INFO_CODEC_ULAW)
Definition: isdn_lib.h:612
int orig
Who originated the call (ORG_AST, ORG_MISDN)
Definition: isdn_lib.h:702
struct FacParm fac_in
Inbound FACILITY message function type and contents.
Definition: isdn_lib.h:507
int generate_tone
TRUE if tone generator allowed to start.
Definition: isdn_lib.h:541
enum mISDN_NUMBER_PLAN number_plan
Type-of-number numbering plan.
Definition: isdn_lib.h:288
int count
Number of times the call has been redirected.
Definition: isdn_lib.h:316
enum mISDN_NUMBER_PLAN number_plan
Type-of-number numbering plan.
Definition: isdn_lib.h:263
int early_bconnect
TRUE if the call progress indicators can indicate an inband audio message for the user to listen to...
Definition: isdn_lib.h:449

◆ empty_chan_in_stack()

static void empty_chan_in_stack ( struct misdn_stack stack,
int  channel 
)
static

Definition at line 605 of file isdn_lib.c.

References ARRAY_LEN, cb_log, misdn_stack::channels, dump_chan_list(), and misdn_stack::port.

Referenced by clear_l3(), handle_cr(), handle_event_nt(), handle_frm_te(), manager_clean_bc(), misdn_lib_release(), and misdn_lib_send_event().

606 {
607  if (channel < 1 || ARRAY_LEN(stack->channels) < channel) {
608  cb_log(0, stack->port, "empty_chan_in_stack: cannot empty channel %d\n", channel);
609  return;
610  }
611 
612  cb_log(4, stack->port, "empty_chan_in_stack: %d\n", channel);
613  stack->channels[channel - 1] = 0;
614  dump_chan_list(stack);
615 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Definition: muted.c:95
char channels[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
Array of B channels in use (a[0] = B1). TRUE if B channel in use. (Must be dimensioned the same as st...
static void dump_chan_list(struct misdn_stack *stack)
Definition: isdn_lib.c:464
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ fac2str()

static const char* fac2str ( enum FacFunction  facility)
static

Definition at line 3338 of file isdn_lib.c.

References ARRAY_LEN, and name.

Referenced by misdn_lib_log_ies().

3339 {
3340  static const struct {
3341  enum FacFunction facility;
3342  char *name;
3343  } arr[] = {
3344 /* *INDENT-OFF* */
3345  { Fac_None, "Fac_None" },
3346 #if defined(AST_MISDN_ENHANCEMENTS)
3347  { Fac_ERROR, "Fac_ERROR" },
3348  { Fac_RESULT, "Fac_RESULT" },
3349  { Fac_REJECT, "Fac_REJECT" },
3350 
3351  { Fac_ActivationDiversion, "Fac_ActivationDiversion" },
3352  { Fac_DeactivationDiversion, "Fac_DeactivationDiversion" },
3353  { Fac_ActivationStatusNotificationDiv, "Fac_ActivationStatusNotificationDiv" },
3354  { Fac_DeactivationStatusNotificationDiv, "Fac_DeactivationStatusNotificationDiv" },
3355  { Fac_InterrogationDiversion, "Fac_InterrogationDiversion" },
3356  { Fac_DiversionInformation, "Fac_DiversionInformation" },
3357  { Fac_CallDeflection, "Fac_CallDeflection" },
3358  { Fac_CallRerouteing, "Fac_CallRerouteing" },
3359  { Fac_DivertingLegInformation2, "Fac_DivertingLegInformation2" },
3360  { Fac_InterrogateServedUserNumbers, "Fac_InterrogateServedUserNumbers" },
3361  { Fac_DivertingLegInformation1, "Fac_DivertingLegInformation1" },
3362  { Fac_DivertingLegInformation3, "Fac_DivertingLegInformation3" },
3363 
3364  { Fac_EctExecute, "Fac_EctExecute" },
3365  { Fac_ExplicitEctExecute, "Fac_ExplicitEctExecute" },
3366  { Fac_RequestSubaddress, "Fac_RequestSubaddress" },
3367  { Fac_SubaddressTransfer, "Fac_SubaddressTransfer" },
3368  { Fac_EctLinkIdRequest, "Fac_EctLinkIdRequest" },
3369  { Fac_EctInform, "Fac_EctInform" },
3370  { Fac_EctLoopTest, "Fac_EctLoopTest" },
3371 
3372  { Fac_ChargingRequest, "Fac_ChargingRequest" },
3373  { Fac_AOCSCurrency, "Fac_AOCSCurrency" },
3374  { Fac_AOCSSpecialArr, "Fac_AOCSSpecialArr" },
3375  { Fac_AOCDCurrency, "Fac_AOCDCurrency" },
3376  { Fac_AOCDChargingUnit, "Fac_AOCDChargingUnit" },
3377  { Fac_AOCECurrency, "Fac_AOCECurrency" },
3378  { Fac_AOCEChargingUnit, "Fac_AOCEChargingUnit" },
3379 
3380  { Fac_StatusRequest, "Fac_StatusRequest" },
3381 
3382  { Fac_CallInfoRetain, "Fac_CallInfoRetain" },
3383  { Fac_EraseCallLinkageID, "Fac_EraseCallLinkageID" },
3384  { Fac_CCBSDeactivate, "Fac_CCBSDeactivate" },
3385  { Fac_CCBSErase, "Fac_CCBSErase" },
3386  { Fac_CCBSRemoteUserFree, "Fac_CCBSRemoteUserFree" },
3387  { Fac_CCBSCall, "Fac_CCBSCall" },
3388  { Fac_CCBSStatusRequest, "Fac_CCBSStatusRequest" },
3389  { Fac_CCBSBFree, "Fac_CCBSBFree" },
3390  { Fac_CCBSStopAlerting, "Fac_CCBSStopAlerting" },
3391 
3392  { Fac_CCBSRequest, "Fac_CCBSRequest" },
3393  { Fac_CCBSInterrogate, "Fac_CCBSInterrogate" },
3394 
3395  { Fac_CCNRRequest, "Fac_CCNRRequest" },
3396  { Fac_CCNRInterrogate, "Fac_CCNRInterrogate" },
3397 
3398  { Fac_CCBS_T_Call, "Fac_CCBS_T_Call" },
3399  { Fac_CCBS_T_Suspend, "Fac_CCBS_T_Suspend" },
3400  { Fac_CCBS_T_Resume, "Fac_CCBS_T_Resume" },
3401  { Fac_CCBS_T_RemoteUserFree, "Fac_CCBS_T_RemoteUserFree" },
3402  { Fac_CCBS_T_Available, "Fac_CCBS_T_Available" },
3403 
3404  { Fac_CCBS_T_Request, "Fac_CCBS_T_Request" },
3405 
3406  { Fac_CCNR_T_Request, "Fac_CCNR_T_Request" },
3407 
3408 #else
3409 
3410  { Fac_CFActivate, "Fac_CFActivate" },
3411  { Fac_CFDeactivate, "Fac_CFDeactivate" },
3412  { Fac_CD, "Fac_CD" },
3413 
3414  { Fac_AOCDCurrency, "Fac_AOCDCurrency" },
3415  { Fac_AOCDChargingUnit, "Fac_AOCDChargingUnit" },
3416 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
3417 /* *INDENT-ON* */
3418  };
3419 
3420  unsigned index;
3421 
3422  for (index = 0; index < ARRAY_LEN(arr); ++index) {
3423  if (arr[index].facility == facility) {
3424  return arr[index].name;
3425  }
3426  }
3427 
3428  return "unknown";
3429 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const char name[]
Definition: cdr_mysql.c:74

◆ fetch_msg()

static msg_t* fetch_msg ( int  midev)
static

Definition at line 3011 of file isdn_lib.c.

References cb_log, errno, and NULL.

Referenced by misdn_lib_isdn_event_catcher().

3012 {
3013  msg_t *msg=alloc_msg(MAX_MSG_SIZE);
3014  int r;
3015 
3016  if (!msg) {
3017  cb_log(0, 0, "fetch_msg: alloc msg failed !!");
3018  return NULL;
3019  }
3020 
3021  AGAIN:
3022  r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC);
3023  msg->len=r;
3024 
3025  if (r==0) {
3026  free_msg(msg); /* danger, cause usually freeing in main_loop */
3027  cb_log(6,0,"Got empty Msg..\n");
3028  return NULL;
3029  }
3030 
3031  if (r<0) {
3032  if (errno == EAGAIN) {
3033  /*we wait for mISDN here*/
3034  cb_log(4,0,"mISDN_read wants us to wait\n");
3035  usleep(5000);
3036  goto AGAIN;
3037  }
3038 
3039  cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno);
3040  }
3041 
3042 #if 0
3043  if (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION)))
3044  cb_log(0,0,"prim: %x dinfo:%x addr:%x msglen:%d frm->len:%d\n",frm->prim, frm->dinfo, frm->addr, msg->len,frm->len );
3045 #endif
3046  return msg;
3047 }
#define NULL
Definition: resample.c:96
int errno
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ find_bc_by_addr()

static struct misdn_bchannel* find_bc_by_addr ( unsigned long  addr)
static

Definition at line 1556 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::in_use, misdn_bchannel::layer_id, misdn_stack::next, NULL, and misdn_lib::stack_list.

Referenced by handle_bchan().

1557 {
1558  struct misdn_stack *stack;
1559  int i;
1560 
1561  for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
1562  for (i = 0; i <= stack->b_num; i++) {
1563  if (stack->bc[i].in_use
1564  && ((stack->bc[i].addr & STACK_ID_MASK) == (addr & STACK_ID_MASK)
1565  || stack->bc[i].layer_id == addr)) {
1566  return &stack->bc[i];
1567  }
1568  }
1569  }
1570 
1571  return NULL;
1572 }
#define NULL
Definition: resample.c:96
int layer_id
B Channel mISDN driver layer ID from mISDN_new_layer()
Definition: isdn_lib.h:379
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429
struct misdn_stack * next
Next stack in the list of stacks.
struct misdn_stack * stack_list
Definition: isdn_lib.c:225

◆ find_bc_by_confid()

static struct misdn_bchannel* find_bc_by_confid ( unsigned long  confid)
static

Definition at line 1574 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::conf_id, misdn_bchannel::in_use, misdn_stack::next, NULL, and misdn_lib::stack_list.

Referenced by misdn_lib_send_event().

1575 {
1576  struct misdn_stack *stack;
1577  int i;
1578 
1579  for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
1580  for (i = 0; i <= stack->b_num; i++) {
1581  if (stack->bc[i].in_use && stack->bc[i].conf_id == confid) {
1582  return &stack->bc[i];
1583  }
1584  }
1585  }
1586  return NULL;
1587 }
#define NULL
Definition: resample.c:96
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
int conf_id
Bridging conference ID.
Definition: isdn_lib.h:553
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
struct misdn_stack * next
Next stack in the list of stacks.
struct misdn_stack * stack_list
Definition: isdn_lib.c:225

◆ find_bc_by_l3id()

struct misdn_bchannel * find_bc_by_l3id ( struct misdn_stack stack,
unsigned long  l3id 
)

Definition at line 1536 of file isdn_lib.c.

References ARRAY_LEN, misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::in_use, misdn_bchannel::l3_id, MAX_BCHANS, and stack_holder_find().

Referenced by handle_cr(), handle_event_nt(), handle_frm_te(), manager_event_handler(), and release_cr().

1537 {
1538  int i;
1539 
1540  for (i = 0; i <= stack->b_num; ++i) {
1541  if (stack->bc[i].in_use && stack->bc[i].l3_id == l3id) {
1542  return &stack->bc[i];
1543  }
1544  }
1545 #if defined(AST_MISDN_ENHANCEMENTS)
1546  /* Search the B channel records for a REGISTER signaling link. */
1547  for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) {
1548  if (stack->bc[i].in_use && stack->bc[i].l3_id == l3id) {
1549  return &stack->bc[i];
1550  }
1551  }
1552 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1553  return stack_holder_find(stack, l3id);
1554 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct misdn_bchannel * stack_holder_find(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:4553
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
#define MAX_BCHANS
Definition: isdn_lib.h:76
int l3_id
Layer 3 process ID.
Definition: isdn_lib.h:399

◆ find_bc_by_masked_l3id()

static struct misdn_bchannel* find_bc_by_masked_l3id ( struct misdn_stack stack,
unsigned long  l3id,
unsigned long  mask 
)
static

Definition at line 1515 of file isdn_lib.c.

References ARRAY_LEN, misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::in_use, misdn_bchannel::l3_id, MAX_BCHANS, and stack_holder_find().

Referenced by handle_event_nt().

1516 {
1517  int i;
1518 
1519  for (i = 0; i <= stack->b_num; ++i) {
1520  if (stack->bc[i].in_use && (stack->bc[i].l3_id & mask) == (l3id & mask)) {
1521  return &stack->bc[i];
1522  }
1523  }
1524 #if defined(AST_MISDN_ENHANCEMENTS)
1525  /* Search the B channel records for a REGISTER signaling link. */
1526  for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) {
1527  if (stack->bc[i].in_use && (stack->bc[i].l3_id & mask) == (l3id & mask)) {
1528  return &stack->bc[i];
1529  }
1530  }
1531 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1532  return stack_holder_find(stack, l3id);
1533 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct misdn_bchannel * stack_holder_find(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:4553
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
#define MAX_BCHANS
Definition: isdn_lib.h:76
int l3_id
Layer 3 process ID.
Definition: isdn_lib.h:399

◆ find_free_chan_in_stack()

static int find_free_chan_in_stack ( struct misdn_stack stack,
struct misdn_bchannel bc,
int  channel,
int  dec 
)
static

Definition at line 513 of file isdn_lib.c.

References ARRAY_LEN, AST_CAUSE_NORMAL_CIRCUIT_CONGESTION, AST_CAUSE_REQUESTED_CHAN_UNAVAIL, misdn_stack::b_num, cb_log, misdn_bchannel::channel, misdn_bchannel::channel_found, misdn_stack::channels, dump_chan_list(), misdn_bchannel::is_register_pool, MAX_BCHANS, misdn_bchannel::out_cause, misdn_stack::port, misdn_stack::pri, pthread_mutex_lock, pthread_mutex_unlock, set_chan_in_stack(), and misdn_stack::st_lock.

Referenced by create_process(), handle_event_nt(), handle_event_te(), and misdn_lib_send_event().

514 {
515  int i;
516  int chan = 0;
517  int bnums;
518 
519  if (bc->channel_found) {
520  return 0;
521  }
522 
523  bc->channel_found = 1;
524 
525 #if defined(AST_MISDN_ENHANCEMENTS)
526  if (bc->is_register_pool) {
527  pthread_mutex_lock(&stack->st_lock);
528  for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->channels); ++i) {
529  if (!stack->channels[i]) {
530  chan = i + 1;
531  cb_log(3, stack->port, " --> found REGISTER chan: %d\n", chan);
532  break;
533  }
534  }
535  } else
536 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
537  {
538  cb_log(5, stack->port, "find_free_chan: req_chan:%d\n", channel);
539 
541  cb_log(0, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel);
542  return 0;
543  }
544 
545  --channel;
546 
547  pthread_mutex_lock(&stack->st_lock);
548  bnums = stack->pri ? stack->b_num : stack->b_num - 1;
549  if (dec) {
550  for (i = bnums; i >= 0; --i) {
551  if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 D channel ;) and work with chan preselection */
552  if (!stack->channels[i]) {
553  chan = i + 1;
554  cb_log(3, stack->port, " --> found chan%s: %d\n", channel >= 0 ? " (preselected)" : "", chan);
555  break;
556  }
557  }
558  }
559  } else {
560  for (i = 0; i <= bnums; ++i) {
561  if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 D channel ;) and work with chan preselection */
562  if (!stack->channels[i]) {
563  chan = i + 1;
564  cb_log(3, stack->port, " --> found chan%s: %d\n", channel >= 0 ? " (preselected)" : "", chan);
565  break;
566  }
567  }
568  }
569  }
570  }
571 
572  if (!chan) {
573  pthread_mutex_unlock(&stack->st_lock);
574  cb_log(1, stack->port, " !! NO FREE CHAN IN STACK\n");
575  dump_chan_list(stack);
577  return -1;
578  }
579 
580  if (set_chan_in_stack(stack, chan) < 0) {
581  pthread_mutex_unlock(&stack->st_lock);
582  cb_log(0, stack->port, "Channel Already in use:%d\n", chan);
584  return -1;
585  }
586  pthread_mutex_unlock(&stack->st_lock);
587 
588  bc->channel = chan;
589  return 0;
590 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Definition: muted.c:95
#define AST_CAUSE_NORMAL_CIRCUIT_CONGESTION
Definition: causes.h:119
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
#define pthread_mutex_lock
Definition: lock.h:623
static int set_chan_in_stack(struct misdn_stack *stack, int channel)
Definition: isdn_lib.c:492
int channel_found
TRUE if the channel was allocated from the available B channels.
Definition: isdn_lib.h:697
char channels[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
Array of B channels in use (a[0] = B1). TRUE if B channel in use. (Must be dimensioned the same as st...
int is_register_pool
TRUE if the B channel is allocated from the REGISTER pool.
Definition: isdn_lib.h:417
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
int out_cause
Q.931 Cause for disconnection code (sent)
Definition: isdn_lib.h:677
#define AST_CAUSE_REQUESTED_CHAN_UNAVAIL
Definition: causes.h:124
static void dump_chan_list(struct misdn_stack *stack)
Definition: isdn_lib.c:464
#define pthread_mutex_unlock
Definition: lock.h:624
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
#define MAX_BCHANS
Definition: isdn_lib.h:76
pthread_mutex_t st_lock
Stack struct critical section lock.

◆ find_stack_by_addr()

static struct misdn_stack* find_stack_by_addr ( int  addr)
static

Definition at line 1472 of file isdn_lib.c.

References misdn_stack::next, misdn_lib::stack_list, and misdn_stack::upper_id.

Referenced by handle_frm_nt(), handle_frm_te(), handle_l1(), handle_l2(), and handle_mgmt().

1473 {
1474  struct misdn_stack *stack;
1475 
1476  for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
1477  if ((stack->upper_id & STACK_ID_MASK) == (addr & STACK_ID_MASK)) {
1478  /* Found the stack */
1479  break;
1480  }
1481  }
1482 
1483  return stack;
1484 }
int upper_id
Upper layer mISDN ID (addr) (Layer 2/4)
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
struct misdn_stack * next
Next stack in the list of stacks.
struct misdn_stack * stack_list
Definition: isdn_lib.c:225

◆ find_stack_by_mgr()

static struct misdn_stack* find_stack_by_mgr ( manager_t *  mgr_nt)
static

Definition at line 1501 of file isdn_lib.c.

References misdn_stack::mgr, misdn_stack::next, and misdn_lib::stack_list.

Referenced by handle_event_nt().

1502 {
1503  struct misdn_stack *stack;
1504 
1505  for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
1506  if (&stack->mgr == mgr_nt) {
1507  /* Found the stack */
1508  break;
1509  }
1510  }
1511 
1512  return stack;
1513 }
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
manager_t mgr
struct misdn_stack * next
Next stack in the list of stacks.
struct misdn_stack * stack_list
Definition: isdn_lib.c:225

◆ find_stack_by_port()

static struct misdn_stack* find_stack_by_port ( int  port)
static

Definition at line 1487 of file isdn_lib.c.

References misdn_stack::next, misdn_stack::port, and misdn_lib::stack_list.

Referenced by misdn_lib_get_free_bc(), misdn_lib_get_port_info(), misdn_lib_port_restart(), misdn_lib_reinit_nt_stack(), and misdn_lib_send_restart().

1488 {
1489  struct misdn_stack *stack;
1490 
1491  for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
1492  if (stack->port == port) {
1493  /* Found the stack */
1494  break;
1495  }
1496  }
1497 
1498  return stack;
1499 }
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
struct misdn_stack * next
Next stack in the list of stacks.
int port
Logical Layer 1 port associated with this stack.
struct misdn_stack * stack_list
Definition: isdn_lib.c:225

◆ flip_buf_bits()

static char* flip_buf_bits ( char *  buf,
int  len 
)
static

Definition at line 334 of file isdn_lib.c.

References buf, and len().

Referenced by handle_bchan(), misdn_lib_init(), misdn_lib_tx2misdn_frm(), and misdn_tx_jitter().

335 {
336  int i;
337  char * start = buf;
338 
339  for (i = 0 ; i < len; i++) {
340  buf[i] = flip_table[(unsigned char)buf[i]];
341  }
342 
343  return start;
344 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static char flip_table[256]
Definition: isdn_lib.c:319
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ get_misdn_stack()

struct misdn_stack * get_misdn_stack ( void  )

◆ get_show_stack_details()

void get_show_stack_details ( int  port,
char *  buf 
)

Definition at line 168 of file isdn_lib.c.

References misdn_stack::blocked, get_misdn_stack(), misdn_stack::l1link, misdn_stack::l2link, misdn_stack::next, misdn_stack::nt, misdn_stack::port, and misdn_stack::ptp.

Referenced by handle_cli_misdn_show_port(), and handle_cli_misdn_show_stacks().

169 {
170  struct misdn_stack *stack = get_misdn_stack();
171 
172  for (; stack; stack = stack->next) {
173  if (stack->port == port) {
174  break;
175  }
176  }
177 
178  if (stack) {
179  sprintf(buf, "* Port %2d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d",
180  stack->port,
181  stack->nt ? "NT" : "TE",
182  stack->ptp ? "PTP" : "PMP",
183  (stack->nt && !stack->ptp) ? "UNKN" : stack->l2link ? "UP " : "DOWN",
184  stack->l1link ? "UP " : "DOWN",
185  stack->blocked);
186  } else {
187  buf[0] = 0;
188  }
189 }
struct misdn_stack * get_misdn_stack(void)
Definition: isdn_lib.c:4698
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int l1link
TRUE if Layer 1 is UP.
int l2link
TRUE if Layer 2 is UP.
int ptp
TRUE if Point-To-Point(PTP) (Point-To-Multipoint(PTMP) otherwise)
int nt
TRUE if NT side of protocol (TE otherwise)
struct misdn_stack * next
Next stack in the list of stacks.
int blocked
TRUE if port is blocked.
int port
Logical Layer 1 port associated with this stack.

◆ get_stack_by_bc()

struct misdn_stack* get_stack_by_bc ( struct misdn_bchannel bc)

Definition at line 152 of file isdn_lib.c.

References get_misdn_stack(), misdn_stack::next, NULL, misdn_stack::port, and misdn_bchannel::port.

Referenced by clean_up_bc(), create_process(), dec_ie_channel_id(), enc_ie_channel_id(), handle_bchan(), handle_event_te(), manager_bchannel_activate(), manager_bchannel_deactivate(), manager_clean_bc(), manager_ec_disable(), manager_ec_enable(), misdn_lib_log_ies(), misdn_lib_release(), misdn_lib_send_event(), misdn_lib_tx2misdn_frm(), parse_release_complete(), parse_restart(), send_msg(), and setup_bc().

153 {
154  struct misdn_stack *stack = get_misdn_stack();
155 
156  if (!bc)
157  return NULL;
158 
159  for ( ; stack; stack = stack->next) {
160  if (bc->port == stack->port)
161  return stack;
162  }
163 
164  return NULL;
165 }
struct misdn_stack * get_misdn_stack(void)
Definition: isdn_lib.c:4698
#define NULL
Definition: resample.c:96
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
struct misdn_stack * next
Next stack in the list of stacks.
int port
Logical Layer 1 port associated with this stack.

◆ handle_bchan()

static int handle_bchan ( msg_t *  msg)
static

Anyway flip the bufbits

Definition at line 2395 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::bc_state, BCHAN_ACTIVATED, misdn_bchannel::bframe, misdn_bchannel::bframe_len, buf, misdn_bchannel::caller, misdn_bchannel::capability, cb_event, cb_log, misdn_bchannel::channel, misdn_bchannel::dialed, do_tone(), misdn_bchannel::dtmf, EVENT_BCHAN_DATA, EVENT_DTMF_TONE, find_bc_by_addr(), flip_buf_bits(), get_stack_by_bc(), if(), misdn_stack::midev, misdn_cap_is_speech(), misdn_tx_jitter(), misdn_party_id::name, misdn_bchannel::nojitter, NULL, misdn_party_dialing::number, misdn_party_id::number, misdn_party_id::number_type, misdn_party_dialing::number_type, misdn_bchannel::pid, misdn_stack::port, misdn_bchannel::port, and misdn_lib::user_data.

Referenced by handle_err(), and manager_isdn_handler().

2396 {
2397  iframe_t *frm= (iframe_t*)msg->data;
2398  struct misdn_bchannel *bc=find_bc_by_addr(frm->addr);
2399  struct misdn_stack *stack;
2400 
2401  if (!bc) {
2402  cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo);
2403  return 0 ;
2404  }
2405 
2406  stack = get_stack_by_bc(bc);
2407 
2408  if (!stack) {
2409  cb_log(0, bc->port,"handle_bchan: STACK not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo);
2410  return 0;
2411  }
2412 
2413  switch (frm->prim) {
2414 
2415  case MGR_SETSTACK| CONFIRM:
2416  cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid);
2417  break;
2418 
2419  case MGR_SETSTACK| INDICATION:
2420  cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid);
2421  break;
2422 
2423  case MGR_DELLAYER| INDICATION:
2424  cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid);
2425  break;
2426 
2427  case MGR_DELLAYER| CONFIRM:
2428  cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid);
2429 
2430  bc->pid=0;
2431  bc->addr=0;
2432 
2433  free_msg(msg);
2434  return 1;
2435 
2436  case PH_ACTIVATE | INDICATION:
2437  case DL_ESTABLISH | INDICATION:
2438  cb_log(3, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid);
2439 
2440  free_msg(msg);
2441  return 1;
2442 
2443  case PH_ACTIVATE | CONFIRM:
2444  case DL_ESTABLISH | CONFIRM:
2445 
2446  cb_log(3, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid);
2447  free_msg(msg);
2448 
2449  return 1;
2450 
2451  case DL_ESTABLISH | REQUEST:
2452  {
2453  char buf[128];
2454  mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_ESTABLISH | CONFIRM, 0,0, NULL, TIMEOUT_1SEC);
2455  }
2456  free_msg(msg);
2457  return 1;
2458 
2459  case DL_RELEASE|REQUEST:
2460  {
2461  char buf[128];
2462  mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN, DL_RELEASE| CONFIRM, 0,0, NULL, TIMEOUT_1SEC);
2463  }
2464  free_msg(msg);
2465  return 1;
2466 
2467  case PH_DEACTIVATE | INDICATION:
2468  case DL_RELEASE | INDICATION:
2469  cb_log (3, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid);
2470 
2471  free_msg(msg);
2472  return 1;
2473 
2474  case PH_DEACTIVATE | CONFIRM:
2475  case DL_RELEASE | CONFIRM:
2476  cb_log(3, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid);
2477 
2478  free_msg(msg);
2479  return 1;
2480 
2481  case PH_CONTROL|INDICATION:
2482  {
2483  unsigned int *cont = (unsigned int *) &frm->data.p;
2484 
2485  cb_log(4, stack->port,
2486  "PH_CONTROL: channel:%d caller%d:\"%s\" <%s> dialed%d:%s \n",
2487  bc->channel,
2488  bc->caller.number_type,
2489  bc->caller.name,
2490  bc->caller.number,
2491  bc->dialed.number_type,
2492  bc->dialed.number);
2493 
2494  if ((*cont & ~DTMF_TONE_MASK) == DTMF_TONE_VAL) {
2495  int dtmf = *cont & DTMF_TONE_MASK;
2496  cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf);
2497  bc->dtmf=dtmf;
2499 
2500  free_msg(msg);
2501  return 1;
2502  }
2503  if (*cont == BF_REJECT) {
2504  cb_log(4, stack->port, " --> BF REJECT\n");
2505  free_msg(msg);
2506  return 1;
2507  }
2508  if (*cont == BF_ACCEPT) {
2509  cb_log(4, stack->port, " --> BF ACCEPT\n");
2510  free_msg(msg);
2511  return 1;
2512  }
2513  }
2514  break;
2515 
2516  case PH_DATA|REQUEST:
2517  case DL_DATA|REQUEST:
2518  cb_log(0, stack->port, "DL_DATA REQUEST \n");
2519  do_tone(bc, 64);
2520 
2521  free_msg(msg);
2522  return 1;
2523 
2524 
2525  case PH_DATA|INDICATION:
2526  case DL_DATA|INDICATION:
2527  {
2528  bc->bframe = (void*)&frm->data.i;
2529  bc->bframe_len = frm->len;
2530 
2531  /** Anyway flip the bufbits **/
2532  if ( misdn_cap_is_speech(bc->capability) )
2533  flip_buf_bits(bc->bframe, bc->bframe_len);
2534 
2535 
2536  if (!bc->bframe_len) {
2537  cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr);
2538  free_msg(msg);
2539  return 1;
2540  }
2541 
2542  if ( (bc->addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) {
2543  cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr);
2544  free_msg(msg);
2545  return 1;
2546  }
2547 
2548 #if MISDN_DEBUG
2549  cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len);
2550 
2551 #endif
2552 
2553  if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) {
2554  int t;
2555 
2556 #ifdef MISDN_B_DEBUG
2557  cb_log(0,bc->port,"do_tone START\n");
2558 #endif
2559  t=do_tone(bc,frm->len);
2560 
2561 #ifdef MISDN_B_DEBUG
2562  cb_log(0,bc->port,"do_tone STOP (%d)\n",t);
2563 #endif
2564  if ( !t ) {
2565  int i;
2566 
2567  if ( misdn_cap_is_speech(bc->capability)) {
2568  if ( !bc->nojitter ) {
2569 #ifdef MISDN_B_DEBUG
2570  cb_log(0,bc->port,"tx_jitter START\n");
2571 #endif
2572  misdn_tx_jitter(bc,frm->len);
2573 #ifdef MISDN_B_DEBUG
2574  cb_log(0,bc->port,"tx_jitter STOP\n");
2575 #endif
2576  }
2577  }
2578 
2579 #ifdef MISDN_B_DEBUG
2580  cb_log(0,bc->port,"EVENT_B_DATA START\n");
2581 #endif
2582 
2584 #ifdef MISDN_B_DEBUG
2585  cb_log(0,bc->port,"EVENT_B_DATA STOP\n");
2586 #endif
2587 
2588  if (i<0) {
2589  cb_log(10,stack->port,"cb_event returned <0\n");
2590  /*clean_up_bc(bc);*/
2591  }
2592  }
2593  }
2594  free_msg(msg);
2595  return 1;
2596  }
2597 
2598 
2599  case PH_CONTROL | CONFIRM:
2600  cb_log(4, stack->port, "PH_CONTROL|CNF bc->addr:%x\n", frm->addr);
2601  free_msg(msg);
2602  return 1;
2603 
2604  case PH_DATA | CONFIRM:
2605  case DL_DATA|CONFIRM:
2606 #if MISDN_DEBUG
2607 
2608  cb_log(0, stack->port, "Data confirmed\n");
2609 
2610 #endif
2611  free_msg(msg);
2612  return 1;
2613  case DL_DATA|RESPONSE:
2614 #if MISDN_DEBUG
2615  cb_log(0, stack->port, "Data response\n");
2616 
2617 #endif
2618  break;
2619  }
2620 
2621  return 0;
2622 }
void misdn_tx_jitter(struct misdn_bchannel *bc, int len)
Definition: isdn_lib.c:2330
#define bc
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int do_tone(struct misdn_bchannel *bc, int len)
Definition: isdn_lib.c:2282
int midev
mISDN device handle returned by mISDN_open()
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
B channel control structure.
Definition: isdn_lib.h:324
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
static struct misdn_bchannel * find_bc_by_addr(unsigned long addr)
Definition: isdn_lib.c:1556
#define NULL
Definition: resample.c:96
int misdn_cap_is_speech(int cap)
Definition: isdn_lib.c:436
void * user_data
Definition: isdn_lib.c:219
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
static char * flip_buf_bits(char *buf, int len)
Definition: isdn_lib.c:334
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ handle_cr()

static int handle_cr ( struct misdn_stack stack,
iframe_t *  frm 
)
static

Definition at line 1686 of file isdn_lib.c.

References bc, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), dump_chan_list(), empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, find_bc_by_l3id(), free(), misdn_bchannel::in_use, misdn_bchannel::l3_id, misdn_lib_get_free_bc(), misdn_make_dummy(), misdn_bchannel::need_disconnect, misdn_bchannel::need_release, misdn_bchannel::need_release_complete, misdn_stack::nt, misdn_stack::port, misdn_bchannel::stack_holder, stack_holder_remove(), and misdn_lib::user_data.

Referenced by handle_event_nt(), handle_frm_te(), and release_cr().

1687 {
1688  struct misdn_bchannel dummybc;
1689  struct misdn_bchannel *bc;
1690  int channel;
1691 
1692  if (!stack) return -1;
1693 
1694  switch (frm->prim) {
1695  case CC_NEW_CR|INDICATION:
1696  cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo);
1697 
1698  bc = misdn_lib_get_free_bc(stack->port, 0, 1, 0);
1699  if (!bc) {
1700  cb_log(0, stack->port, " --> !! lib: No free channel!\n");
1701  return -1;
1702  }
1703 
1704  cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo);
1705  bc->l3_id=frm->dinfo;
1706  return 1;
1707  case CC_NEW_CR|CONFIRM:
1708  return 1;
1709  case CC_NEW_CR|REQUEST:
1710  return 1;
1711  case CC_RELEASE_CR|REQUEST:
1712  return 1;
1713  case CC_RELEASE_CR|CONFIRM:
1714  break;
1715  case CC_RELEASE_CR|INDICATION:
1716  cb_log(4, stack->port, " --> lib: RELEASE_CR Ind with l3id:%x\n", frm->dinfo);
1717  bc = find_bc_by_l3id(stack, frm->dinfo);
1718  if (!bc) {
1719  cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
1720  misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0);
1721  bc = &dummybc;
1722  }
1723 
1724  channel = bc->channel;
1725  cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n", frm->dinfo);
1726 
1727  /* bc->pid = 0; */
1728  bc->need_disconnect = 0;
1729  bc->need_release = 0;
1730  bc->need_release_complete = 0;
1731 
1733 
1734  empty_bc(bc);
1735  clean_up_bc(bc);
1736 
1737  if (channel > 0)
1738  empty_chan_in_stack(stack, channel);
1739  bc->in_use = 0;
1740 
1741  dump_chan_list(stack);
1742 
1743  if (bc->stack_holder) {
1744  cb_log(4, stack->port, "REMOVING Holder\n");
1745  stack_holder_remove(stack, bc);
1746  free(bc);
1747  }
1748 
1749  return 1;
1750  default:
1751  break;
1752  }
1753 
1754  return 0;
1755 }
static void empty_chan_in_stack(struct misdn_stack *stack, int channel)
Definition: isdn_lib.c:605
#define bc
static int clean_up_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:815
int stack_holder
TRUE if this channel is on the misdn_stack->holding list.
Definition: isdn_lib.h:561
void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
Definition: isdn_lib.c:77
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
B channel control structure.
Definition: isdn_lib.h:324
struct misdn_bchannel * find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:1536
void * user_data
Definition: isdn_lib.c:219
void free()
int need_release_complete
TRUE if RELEASE_COMPLETE needs to be sent to clear a call.
Definition: isdn_lib.h:392
static void empty_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:679
void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holder)
Definition: isdn_lib.c:4527
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
int nt
TRUE if NT side of protocol (TE otherwise)
struct misdn_bchannel * misdn_lib_get_free_bc(int port, int channel, int inout, int dec)
Definition: isdn_lib.c:3205
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
int need_release
TRUE if RELEASE needs to be sent to clear a call.
Definition: isdn_lib.h:389
static void dump_chan_list(struct misdn_stack *stack)
Definition: isdn_lib.c:464
int need_disconnect
TRUE if DISCONNECT needs to be sent to clear a call.
Definition: isdn_lib.h:386
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
int l3_id
Layer 3 process ID.
Definition: isdn_lib.h:399

◆ handle_err()

static int handle_err ( msg_t *  msg)
static

Definition at line 3779 of file isdn_lib.c.

References cb_log, handle_bchan(), and if().

Referenced by manager_isdn_handler().

3780 {
3781  iframe_t *frm = (iframe_t*) msg->data;
3782 
3783 
3784  if (!frm->addr) {
3785  static int cnt=0;
3786  if (!cnt)
3787  cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo);
3788  cnt++;
3789  if (cnt>100) {
3790  cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo);
3791  cnt=0;
3792  }
3793 
3794  free_msg(msg);
3795  return 1;
3796 
3797  }
3798 
3799  switch (frm->prim) {
3800  case MGR_SETSTACK|INDICATION:
3801  return handle_bchan(msg);
3802  break;
3803 
3804  case MGR_SETSTACK|CONFIRM:
3805  case MGR_CLEARSTACK|CONFIRM:
3806  free_msg(msg) ;
3807  return 1;
3808  break;
3809 
3810  case DL_DATA|CONFIRM:
3811  cb_log(4,0,"DL_DATA|CONFIRM\n");
3812  free_msg(msg);
3813  return 1;
3814 
3815  case PH_CONTROL|CONFIRM:
3816  cb_log(4,0,"PH_CONTROL|CONFIRM\n");
3817  free_msg(msg);
3818  return 1;
3819 
3820  case DL_DATA|INDICATION:
3821  {
3822  int port=(frm->addr&MASTER_ID_MASK) >> 8;
3823  int channel=(frm->addr&CHILD_ID_MASK) >> 16;
3824 
3825  /*we flush the read buffer here*/
3826 
3827  cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel);
3828 
3829  free_msg(msg);
3830  return 1;
3831  }
3832  }
3833 
3834  return 0;
3835 }
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
Definition: muted.c:95
static int handle_bchan(msg_t *msg)
Definition: isdn_lib.c:2395
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ handle_event_nt()

static int handle_event_nt ( void *  dat,
void *  arg 
)
static

Definition at line 1890 of file isdn_lib.c.

References misdn_bchannel::addr, AST_CAUSE_USER_BUSY, misdn_bchannel::b_stid, bc, misdn_stack::bc, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), create_l3msg(), empty_bc(), empty_chan_in_stack(), EVENT_NEW_L3ID, EVENT_PORT_ALARM, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_SETUP, find_bc_by_l3id(), find_bc_by_masked_l3id(), find_free_chan_in_stack(), find_stack_by_mgr(), free(), handle_cr(), misdn_bchannel::holded, misdn_bchannel::in_use, misdn_bchannel::is_register_pool, isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), misdn_stack::l1link, misdn_stack::l2link, misdn_stack::l2upcnt, misdn_bchannel::l3_id, misdn_lib_get_free_bc(), misdn_lib_get_l2_up(), misdn_lib_send_event(), misdn_lib_send_restart(), misdn_make_dummy(), mISDNUSER_HEAD_SIZE, msgs_g, misdn_stack::nst, misdn_stack::nstlock, misdn_stack::nt, misdn_stack::port, misdn_bchannel::port, misdn_stack::procids, pthread_mutex_lock, pthread_mutex_unlock, misdn_stack::ptp, release_cr(), misdn_stack::restart_sent, stack_holder_find(), stack_holder_remove(), misdn_stack::upper_id, and misdn_lib::user_data.

Referenced by misdn_lib_reinit_nt_stack(), and stack_init().

1891 {
1892  struct misdn_bchannel dummybc;
1893  struct misdn_bchannel *bc;
1894  manager_t *mgr = (manager_t *)dat;
1895  msg_t *msg = (msg_t *)arg;
1896  msg_t *dmsg;
1897  mISDNuser_head_t *hh;
1898  struct misdn_stack *stack;
1899  enum event_e event;
1900  int reject=0;
1901  int l3id;
1902  int channel;
1903  int tmpcause;
1904 
1905  if (!msg || !mgr)
1906  return(-EINVAL);
1907 
1908  stack = find_stack_by_mgr(mgr);
1909  hh=(mISDNuser_head_t*)msg->data;
1910 
1911  /*
1912  * When we are called from the mISDNuser lib, the nstlock is held and it
1913  * must be held when we return. We unlock here because the lib may be
1914  * entered again recursively.
1915  */
1916  pthread_mutex_unlock(&stack->nstlock);
1917 
1918  cb_log(5, stack->port, " --> lib: prim %x dinfo %x\n",hh->prim, hh->dinfo);
1919  switch(hh->prim) {
1920  case CC_RETRIEVE|INDICATION:
1921  {
1922  struct misdn_bchannel *hold_bc;
1923  iframe_t frm; /* fake te frm to add callref to global callreflist */
1924 
1925  frm.dinfo = hh->dinfo;
1926  frm.addr=stack->upper_id | FLG_MSG_DOWN;
1927  frm.prim = CC_NEW_CR|INDICATION;
1928  if (handle_cr( stack, &frm)< 0) {
1929  goto ERR_NO_CHANNEL;
1930  }
1931 
1932  bc = find_bc_by_l3id(stack, hh->dinfo);
1933  hold_bc = stack_holder_find(stack, bc->l3_id);
1934  cb_log(4, stack->port, "bc_l3id:%x holded_bc_l3id:%x\n",bc->l3_id, hold_bc->l3_id);
1935 
1936  if (hold_bc) {
1937  cb_log(4, stack->port, "REMOVING Holder\n");
1938 
1939  /* swap the backup to our new channel back */
1940  stack_holder_remove(stack, hold_bc);
1941  memcpy(bc, hold_bc, sizeof(*bc));
1942  free(hold_bc);
1943 
1944  bc->holded=0;
1945  bc->b_stid=0;
1946  }
1947  break;
1948  }
1949 
1950  case CC_SETUP | CONFIRM:
1951  l3id = *((int *) (msg->data + mISDNUSER_HEAD_SIZE));
1952 
1953  cb_log(4, stack->port, " --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID is %x\n", l3id);
1954 
1955  bc = find_bc_by_l3id(stack, hh->dinfo);
1956  if (bc) {
1957  cb_log (2, bc->port, "I IND :CC_SETUP|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id);
1958  bc->l3_id = l3id;
1960  } else {
1961  cb_log(4, stack->port, "Bc Not found (after SETUP CONFIRM)\n");
1962  }
1963  free_msg(msg);
1964  pthread_mutex_lock(&stack->nstlock);
1965  return 0;
1966 
1967  case CC_SETUP | INDICATION:
1968  bc = misdn_lib_get_free_bc(stack->port, 0, 1, 0);
1969  if (!bc) {
1970  goto ERR_NO_CHANNEL;
1971  }
1972 
1973  cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo);
1974  bc->l3_id=hh->dinfo;
1975  break;
1976 
1977 #if defined(AST_MISDN_ENHANCEMENTS)
1978  case CC_REGISTER | CONFIRM:
1979  l3id = *((int *) (msg->data + mISDNUSER_HEAD_SIZE));
1980 
1981  cb_log(4, stack->port, " --> lib: Event_ind:REGISTER CONFIRM [NT] : new L3ID is %x\n", l3id);
1982 
1983  bc = find_bc_by_l3id(stack, hh->dinfo);
1984  if (bc) {
1985  cb_log (2, bc->port, "I IND :CC_REGISTER|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id);
1986  bc->l3_id = l3id;
1987  } else {
1988  cb_log(4, stack->port, "Bc Not found (after REGISTER CONFIRM)\n");
1989  }
1990  free_msg(msg);
1991  pthread_mutex_lock(&stack->nstlock);
1992  return 0;
1993 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
1994 
1995 #if defined(AST_MISDN_ENHANCEMENTS)
1996  case CC_REGISTER | INDICATION:
1997  bc = misdn_lib_get_register_bc(stack->port);
1998  if (!bc) {
1999  goto ERR_NO_CHANNEL;
2000  }
2001 
2002  cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo);
2003  bc->l3_id=hh->dinfo;
2004  break;
2005 #endif /* defined(AST_MISDN_ENHANCEMENTS) */
2006 
2007  case CC_CONNECT_ACKNOWLEDGE|INDICATION:
2008  break;
2009 
2010  case CC_ALERTING|INDICATION:
2011  case CC_PROCEEDING|INDICATION:
2012  case CC_SETUP_ACKNOWLEDGE|INDICATION:
2013  case CC_CONNECT|INDICATION:
2014  break;
2015  case CC_DISCONNECT|INDICATION:
2016  bc = find_bc_by_l3id(stack, hh->dinfo);
2017  if (!bc) {
2018  bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000);
2019  if (bc) {
2020  int myprocid=bc->l3_id&0x0000ffff;
2021 
2022  hh->dinfo=(hh->dinfo&0xffff0000)|myprocid;
2023  cb_log(3,stack->port,"Reject dinfo: %x cause:%d\n",hh->dinfo,bc->cause);
2024  reject=1;
2025  }
2026  }
2027  break;
2028 
2029  case CC_FACILITY|INDICATION:
2030  bc = find_bc_by_l3id(stack, hh->dinfo);
2031  if (!bc) {
2032  bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000);
2033  if (bc) {
2034  int myprocid=bc->l3_id&0x0000ffff;
2035 
2036  hh->dinfo=(hh->dinfo&0xffff0000)|myprocid;
2037  cb_log(4,bc->port,"Repaired reject Bug, new dinfo: %x\n",hh->dinfo);
2038  }
2039  }
2040  break;
2041 
2042  case CC_RELEASE_COMPLETE|INDICATION:
2043  break;
2044 
2045  case CC_SUSPEND|INDICATION:
2046  cb_log(4, stack->port, " --> Got Suspend, sending Reject for now\n");
2047  dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
2048  pthread_mutex_lock(&stack->nstlock);
2049  stack->nst.manager_l3(&stack->nst, dmsg);
2050  free_msg(msg);
2051  return 0;
2052 
2053  case CC_RESUME|INDICATION:
2054  break;
2055 
2056  case CC_RELEASE|CONFIRM:
2057  bc = find_bc_by_l3id(stack, hh->dinfo);
2058  if (bc) {
2059  cb_log(1, stack->port, "CC_RELEASE|CONFIRM (l3id:%x), sending RELEASE_COMPLETE\n", hh->dinfo);
2061  }
2062  break;
2063 
2064  case CC_RELEASE|INDICATION:
2065  break;
2066 
2067  case CC_RELEASE_CR|INDICATION:
2068  release_cr(stack, hh);
2069  free_msg(msg);
2070  pthread_mutex_lock(&stack->nstlock);
2071  return 0;
2072 
2073  case CC_NEW_CR|INDICATION:
2074  /* Got New CR for bchan, for now I handle this one in */
2075  /* connect_ack, Need to be changed */
2076  l3id = *((int *) (msg->data + mISDNUSER_HEAD_SIZE));
2077 
2078  bc = find_bc_by_l3id(stack, hh->dinfo);
2079  if (!bc) {
2080  cb_log(0, stack->port, " --> In NEW_CR: didn't found bc ??\n");
2081  pthread_mutex_lock(&stack->nstlock);
2082  return -1;
2083  }
2084  if (((l3id&0xff00)!=0xff00) && ((bc->l3_id&0xff00)==0xff00)) {
2085  cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", 0xff&bc->l3_id);
2086  stack->procids[bc->l3_id&0xff] = 0 ;
2087  }
2088  cb_log(4, stack->port, "lib: Event_ind:CC_NEW_CR : very new L3ID is %x\n",l3id );
2089 
2090  bc->l3_id =l3id;
2091  if (!bc->is_register_pool) {
2093  }
2094 
2095  free_msg(msg);
2096  pthread_mutex_lock(&stack->nstlock);
2097  return 0;
2098 
2099  case DL_ESTABLISH | INDICATION:
2100  case DL_ESTABLISH | CONFIRM:
2101  cb_log(3, stack->port, "%% GOT L2 Activate Info.\n");
2102 
2103  if (stack->ptp && stack->l2link) {
2104  cb_log(0, stack->port, "%% GOT L2 Activate Info. but we're activated already.. this l2 is faulty, blocking port\n");
2106  }
2107 
2108  if (stack->ptp && !stack->restart_sent) {
2109  /* make sure we restart the interface of the
2110  * other side */
2111  stack->restart_sent=1;
2112  misdn_lib_send_restart(stack->port, -1);
2113 
2114  }
2115 
2116  /* when we get the L2 UP, the L1 is UP definitely too*/
2117  stack->l2link = 1;
2118  stack->l2upcnt=0;
2119 
2120  free_msg(msg);
2121  pthread_mutex_lock(&stack->nstlock);
2122  return 0;
2123 
2124  case DL_RELEASE | INDICATION:
2125  case DL_RELEASE | CONFIRM:
2126  cb_log(3, stack->port, "%% GOT L2 DeActivate Info.\n");
2127  if (stack->ptp) {
2128 
2129  if (stack->l2upcnt>3) {
2130  cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attempts!!!\n");
2131  } else {
2132  if (stack->l1link) {
2133  misdn_lib_get_l2_up(stack);
2134  stack->l2upcnt++;
2135  }
2136  }
2137  }
2138 
2139  stack->l2link = 0;
2140  free_msg(msg);
2141  pthread_mutex_lock(&stack->nstlock);
2142  return 0;
2143 
2144  default:
2145  break;
2146  }
2147 
2148  /* Parse Events and fire_up to App. */
2149  event = isdn_msg_get_event(msgs_g, msg, 1);
2150 
2151  bc = find_bc_by_l3id(stack, hh->dinfo);
2152  if (!bc) {
2153  cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x).\n", hh->dinfo);
2154  misdn_make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0);
2155  bc = &dummybc;
2156  }
2157 
2158  isdn_msg_parse_event(msgs_g, msg, bc, 1);
2159 
2160  switch (event) {
2161  case EVENT_SETUP:
2162  if (bc->channel <= 0 || bc->channel == 0xff) {
2163  bc->channel = 0;
2164  }
2165 
2166  if (find_free_chan_in_stack(stack, bc, bc->channel, 0) < 0) {
2167  goto ERR_NO_CHANNEL;
2168  }
2169  break;
2170  case EVENT_RELEASE:
2172  channel = bc->channel;
2173  tmpcause = bc->cause;
2174 
2175  empty_bc(bc);
2176  bc->cause = tmpcause;
2177  clean_up_bc(bc);
2178 
2179  if (channel > 0)
2180  empty_chan_in_stack(stack, channel);
2181  bc->in_use = 0;
2182  break;
2183  default:
2184  break;
2185  }
2186 
2187  if(!isdn_get_info(msgs_g, event, 1)) {
2188  cb_log(4, stack->port, "Unknown Event Ind: prim %x dinfo %x\n", hh->prim, hh->dinfo);
2189  } else {
2190  if (reject) {
2191  switch(bc->cause) {
2192  case AST_CAUSE_USER_BUSY:
2193  cb_log(1, stack->port, "Siemens Busy reject..\n");
2194  break;
2195  default:
2196  break;
2197  }
2198  }
2199  cb_event(event, bc, glob_mgr->user_data);
2200  }
2201 
2202  free_msg(msg);
2203  pthread_mutex_lock(&stack->nstlock);
2204  return 0;
2205 
2206 ERR_NO_CHANNEL:
2207  cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo);
2208  dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), 1);
2209  pthread_mutex_lock(&stack->nstlock);
2210  stack->nst.manager_l3(&stack->nst, dmsg);
2211  free_msg(msg);
2212  return 0;
2213 }
static void empty_chan_in_stack(struct misdn_stack *stack, int channel)
Definition: isdn_lib.c:605
int upper_id
Upper layer mISDN ID (addr) (Layer 2/4)
static int handle_cr(struct misdn_stack *stack, iframe_t *frm)
Definition: isdn_lib.c:1686
int procids[MAXPROCS]
CR Process ID allocation table. TRUE if ID allocated.
char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
#define bc
struct isdn_msg msgs_g[]
static int clean_up_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:815
#define mISDNUSER_HEAD_SIZE
static struct misdn_stack * find_stack_by_mgr(manager_t *mgr_nt)
Definition: isdn_lib.c:1501
void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
Definition: isdn_lib.c:77
struct misdn_bchannel * stack_holder_find(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:4553
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
B channel control structure.
Definition: isdn_lib.h:324
Definition: astman.c:222
pthread_mutex_t nstlock
net_stack_t nst
Definition: muted.c:95
struct misdn_bchannel * find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:1536
enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *frm, int nt)
msg_t * create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
Definition: isdn_lib.c:371
int l1link
TRUE if Layer 1 is UP.
static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
Definition: isdn_lib.c:513
int misdn_lib_get_l2_up(struct misdn_stack *stack)
Definition: isdn_lib.c:932
void * user_data
Definition: isdn_lib.c:219
void free()
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
#define pthread_mutex_lock
Definition: lock.h:623
static int release_cr(struct misdn_stack *stack, mISDNuser_head_t *hh)
Definition: isdn_lib.c:1861
int holded
TRUE if this channel is on hold.
Definition: isdn_lib.h:556
static void empty_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:679
int restart_sent
TRUE if restart has been sent to the other side after stack startup.
int b_stid
B Channel mISDN driver stack ID.
Definition: isdn_lib.h:374
void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holder)
Definition: isdn_lib.c:4527
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
int misdn_lib_send_restart(int port, int channel)
Definition: isdn_lib.c:3943
int l2link
TRUE if Layer 2 is UP.
int l2upcnt
Number of consecutive times PTP Layer 2 declared down.
int ptp
TRUE if Point-To-Point(PTP) (Point-To-Multipoint(PTMP) otherwise)
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
int is_register_pool
TRUE if the B channel is allocated from the REGISTER pool.
Definition: isdn_lib.h:417
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429
int nt
TRUE if NT side of protocol (TE otherwise)
struct misdn_bchannel * misdn_lib_get_free_bc(int port, int channel, int inout, int dec)
Definition: isdn_lib.c:3205
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
#define AST_CAUSE_USER_BUSY
Definition: causes.h:106
int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event)
Definition: isdn_lib.c:3523
static struct misdn_bchannel * find_bc_by_masked_l3id(struct misdn_stack *stack, unsigned long l3id, unsigned long mask)
Definition: isdn_lib.c:1515
#define pthread_mutex_unlock
Definition: lock.h:624
int cause
Q.931 Cause for disconnection code (received)
Definition: isdn_lib.h:671
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *frm, struct misdn_bchannel *bc, int nt)
int l3_id
Layer 3 process ID.
Definition: isdn_lib.h:399
event_e
Definition: isdn_lib.h:119

◆ handle_event_te()

static int handle_event_te ( struct misdn_bchannel bc,
enum event_e  event,
iframe_t *  frm 
)
static

Definition at line 1590 of file isdn_lib.c.

References misdn_bchannel::caller, misdn_bchannel::capability, cb_log, misdn_bchannel::channel, misdn_bchannel::crypt_key, misdn_bchannel::cw, misdn_bchannel::dialed, EVENT_ALERTING, EVENT_CONNECT, EVENT_CONNECT_ACKNOWLEDGE, EVENT_PROCEEDING, EVENT_PROGRESS, EVENT_RELEASE, EVENT_RELEASE_COMPLETE, EVENT_SETUP, EVENT_SETUP_ACKNOWLEDGE, find_free_chan_in_stack(), get_stack_by_bc(), manager_ec_enable(), manager_ph_control(), manager_ph_control_block(), misdn_cap_is_speech(), misdn_lib_send_event(), misdn_party_id::name, misdn_bchannel::nodsp, misdn_party_dialing::number, misdn_party_id::number, misdn_party_id::number_type, misdn_party_dialing::number_type, misdn_bchannel::out_cause, misdn_stack::port, misdn_stack::pri, misdn_stack::ptp, misdn_bchannel::rxgain, setup_bc(), and misdn_bchannel::txgain.

Referenced by handle_frm_te().

1591 {
1592  struct misdn_stack *stack=get_stack_by_bc(bc);
1593 
1594  switch (event) {
1596  setup_bc(bc);
1597 
1598  if ( *bc->crypt_key ) {
1599  cb_log(4, stack->port,
1600  "ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n",
1601  bc->channel,
1602  bc->caller.number_type,
1603  bc->caller.name,
1604  bc->caller.number,
1605  bc->dialed.number_type,
1606  bc->dialed.number);
1607  manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
1608  }
1609 
1610  if (misdn_cap_is_speech(bc->capability)) {
1611  if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0);
1612  manager_ec_enable(bc);
1613 
1614  if ( bc->txgain != 0 ) {
1615  cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain);
1616  manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
1617  }
1618  if ( bc->rxgain != 0 ) {
1619  cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain);
1620  manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
1621  }
1622  }
1623 
1624  break;
1625  case EVENT_CONNECT:
1626 
1627  if ( *bc->crypt_key ) {
1628  cb_log(4, stack->port,
1629  "ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n",
1630  bc->channel,
1631  bc->caller.number_type,
1632  bc->caller.name,
1633  bc->caller.number,
1634  bc->dialed.number_type,
1635  bc->dialed.number);
1636  manager_ph_control_block(bc, BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
1637  }
1638  case EVENT_ALERTING:
1639  case EVENT_PROGRESS:
1640  case EVENT_PROCEEDING:
1642  case EVENT_SETUP:
1643  {
1644  if (bc->channel == 0xff || bc->channel<=0)
1645  bc->channel=0;
1646 
1647  if (find_free_chan_in_stack(stack, bc, bc->channel, 0)<0){
1648  if (!stack->pri && !stack->ptp) {
1649  bc->cw=1;
1650  break;
1651  }
1652 
1653  if (!bc->channel) {
1654  cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
1655  } else {
1656  cb_log(0, stack->port,
1657  "Requested Channel Already in Use releasing this call with cause %d!!!!\n",
1658  bc->out_cause);
1659  }
1660 
1661  /* when the channel is already in use, we can't
1662  * simply clear it, we need to make sure that
1663  * it will still be marked as in_use in the
1664  * available channels list.*/
1665  bc->channel=0;
1666 
1668  return -1;
1669  }
1670 
1671  if (event != EVENT_SETUP) {
1672  setup_bc(bc);
1673  }
1674  break;
1675  }
1676 
1678  case EVENT_RELEASE:
1679  break;
1680  default:
1681  break;
1682  }
1683  return 0;
1684 }
char number[MISDN_MAX_NUMBER_LEN]
Phone number (Address)
Definition: isdn_lib.h:298
int nodsp
TRUE if we will not use jollys dsp.
Definition: isdn_lib.h:474
int txgain
Tx gain setting (range -8 to 8)
Definition: isdn_lib.h:708
void manager_ec_enable(struct misdn_bchannel *bc)
Definition: isdn_lib.c:4628
int cw
TRUE if call waiting.
Definition: isdn_lib.h:426
Definition: astman.c:222
char crypt_key[255]
Blowfish encryption key string (secret)
Definition: isdn_lib.h:529
static int setup_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:1038
int capability
SETUP message bearer capability field code value.
Definition: isdn_lib.h:609
int misdn_cap_is_speech(int cap)
Definition: isdn_lib.c:436
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
Definition: isdn_lib.c:513
char number[MISDN_MAX_NUMBER_LEN]
Dialed/Called Phone Number (Address)
Definition: isdn_lib.h:266
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
Definition: isdn_lib.c:4419
enum mISDN_NUMBER_TYPE number_type
Type-of-number in ISDN terms for the number.
Definition: isdn_lib.h:285
struct misdn_party_id caller
Originating/Caller ID information struct.
Definition: isdn_lib.h:343
char name[MISDN_MAX_NAME_LEN]
Subscriber Name.
Definition: isdn_lib.h:295
int rxgain
Rx gain setting (range -8 to 8)
Definition: isdn_lib.h:714
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
enum mISDN_NUMBER_TYPE number_type
Type-of-number in ISDN terms for the dialed/called number.
Definition: isdn_lib.h:260
void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
Definition: isdn_lib.c:4470
int ptp
TRUE if Point-To-Point(PTP) (Point-To-Multipoint(PTMP) otherwise)
struct misdn_party_dialing dialed
Dialed/Called information struct.
Definition: isdn_lib.h:337
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
int out_cause
Q.931 Cause for disconnection code (sent)
Definition: isdn_lib.h:677
int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event)
Definition: isdn_lib.c:3523
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ handle_frm_nt()

static int handle_frm_nt ( msg_t *  msg)
static

Definition at line 2626 of file isdn_lib.c.

References cb_log, find_stack_by_addr(), pthread_mutex_lock, and pthread_mutex_unlock.

Referenced by manager_isdn_handler().

2627 {
2628  iframe_t *frm= (iframe_t*)msg->data;
2629  struct misdn_stack *stack;
2630  int err=0;
2631 
2632  stack=find_stack_by_addr( frm->addr );
2633 
2634 
2635 
2636  if (!stack || !stack->nt) {
2637  return 0;
2638  }
2639 
2640 
2641  pthread_mutex_lock(&stack->nstlock);
2642  if ((err=stack->nst.l1_l2(&stack->nst,msg))) {
2643  pthread_mutex_unlock(&stack->nstlock);
2644  if (nt_err_cnt > 0 ) {
2645  if (nt_err_cnt < 100) {
2646  nt_err_cnt++;
2647  cb_log(0, stack->port, "NT Stack sends us error: %d \n", err);
2648  } else if (nt_err_cnt < 105){
2649  cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err);
2650  nt_err_cnt = - 1;
2651  }
2652  }
2653  free_msg(msg);
2654  return 1;
2655  }
2656  pthread_mutex_unlock(&stack->nstlock);
2657  return 1;
2658 }
#define pthread_mutex_lock
Definition: lock.h:623
static int nt_err_cnt
Definition: isdn_lib.c:192
static struct misdn_stack * find_stack_by_addr(int addr)
Definition: isdn_lib.c:1472
#define pthread_mutex_unlock
Definition: lock.h:624
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ handle_frm_te()

static int handle_frm_te ( msg_t *  msg)
static

Definition at line 2661 of file isdn_lib.c.

References AST_CAUSE_NORMAL_CLEARING, AST_CAUSE_REQUESTED_CHAN_UNAVAIL, bc, misdn_bchannel::cause, cb_event, cb_log, misdn_bchannel::channel, clean_up_bc(), empty_bc(), empty_chan_in_stack(), EVENT_RELEASE_COMPLETE, EVENT_RESTART, EVENT_SETUP, find_bc_by_l3id(), find_stack_by_addr(), handle_cr(), handle_event_te(), misdn_bchannel::in_use, isdn_get_info(), isdn_msg_get_event(), isdn_msg_parse_event(), misdn_bchannel::l3_id, misdn_lib_send_event(), misdn_lib_send_restart(), misdn_make_dummy(), msgs_g, misdn_bchannel::need_release_complete, misdn_stack::nt, misdn_bchannel::out_cause, misdn_stack::port, RESPONSE_IGNORE_SETUP, RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE, RESPONSE_OK, RESPONSE_RELEASE_SETUP, misdn_bchannel::restart_channel, and misdn_lib::user_data.

Referenced by manager_isdn_handler().

2662 {
2663  struct misdn_bchannel dummybc;
2664  struct misdn_bchannel *bc;
2665  iframe_t *frm;
2666  struct misdn_stack *stack;
2667  enum event_e event;
2668  enum event_response_e response;
2669  int ret;
2670  int channel;
2671  int tmpcause;
2672  int tmp_out_cause;
2673 
2674  frm = (iframe_t*) msg->data;
2675  stack = find_stack_by_addr(frm->addr);
2676  if (!stack || stack->nt) {
2677  return 0;
2678  }
2679 
2680  cb_log(4, stack->port, "handle_frm_te: frm->addr:%x frm->prim:%x\n", frm->addr, frm->prim);
2681 
2682  ret = handle_cr(stack, frm);
2683  if (ret < 0) {
2684  cb_log(3, stack->port, "handle_frm_te: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr);
2685  }
2686  if (ret) {
2687  free_msg(msg);
2688  return 1;
2689  }
2690 
2691  bc = find_bc_by_l3id(stack, frm->dinfo);
2692  if (!bc) {
2693  misdn_make_dummy(&dummybc, stack->port, 0, stack->nt, 0);
2694  switch (frm->prim) {
2695  case CC_RESTART | CONFIRM:
2696  dummybc.l3_id = MISDN_ID_GLOBAL;
2697  bc = &dummybc;
2698  break;
2699  case CC_SETUP | INDICATION:
2700  dummybc.l3_id = frm->dinfo;
2701  bc = &dummybc;
2702 
2703  /* set a reasonable cause */
2705  /* if we want to send something the flag must be set! */
2706  bc->need_release_complete = 1;
2708 
2709  free_msg(msg);
2710  return 1;
2711  default:
2712  if (frm->prim == (CC_FACILITY | INDICATION)) {
2713  cb_log(5, stack->port, " --> Using Dummy BC for FACILITY\n");
2714  } else {
2715  cb_log(0, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
2716  dummybc.l3_id = frm->dinfo;
2717  }
2718  bc = &dummybc;
2719  break;
2720  }
2721  }
2722 
2723  event = isdn_msg_get_event(msgs_g, msg, 0);
2724  isdn_msg_parse_event(msgs_g, msg, bc, 0);
2725 
2726  /* Preprocess some Events */
2727  ret = handle_event_te(bc, event, frm);
2728  if (ret < 0) {
2729  cb_log(0, stack->port, "couldn't handle event\n");
2730  free_msg(msg);
2731  return 1;
2732  }
2733 
2734  /* shoot up event to App: */
2735  cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n", frm->addr, frm->prim, frm->dinfo);
2736 
2737  if (!isdn_get_info(msgs_g, event, 0)) {
2738  cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n", frm->addr, frm->prim, frm->dinfo);
2739  response = RESPONSE_OK;
2740  } else {
2741  response = cb_event(event, bc, glob_mgr->user_data);
2742  }
2743 
2744  switch (event) {
2745  case EVENT_SETUP:
2746  switch (response) {
2748  cb_log(0, stack->port, "TOTALLY IGNORING SETUP\n");
2749  break;
2750  case RESPONSE_IGNORE_SETUP:
2751  cb_log(0, stack->port, "GOT IGNORE SETUP\n");
2752  /* I think we should send CC_RELEASE_CR, but am not sure*/
2754  /* fall through */
2756  if (response == RESPONSE_RELEASE_SETUP) {
2757  cb_log(0, stack->port, "GOT RELEASE SETUP\n");
2758  }
2760  break;
2761  case RESPONSE_OK:
2762  cb_log(4, stack->port, "GOT SETUP OK\n");
2763  break;
2764  default:
2765  cb_log(0, stack->port, "GOT UNKNOWN SETUP RESPONSE\n");
2766  break;
2767  }
2768  break;
2770  /* release bchannel only after we've announced the RELEASE_COMPLETE */
2771  channel = bc->channel;
2772  tmpcause = bc->cause;
2773  tmp_out_cause = bc->out_cause;
2774 
2775  empty_bc(bc);
2776  bc->cause = tmpcause;
2777  bc->out_cause = tmp_out_cause;
2778  clean_up_bc(bc);
2779  bc->in_use = 0;
2780 
2781  if (tmpcause == AST_CAUSE_REQUESTED_CHAN_UNAVAIL) {
2782  cb_log(0, stack->port, "**** Received CAUSE:%d, restarting channel %d\n", AST_CAUSE_REQUESTED_CHAN_UNAVAIL, channel);
2783  misdn_lib_send_restart(stack->port, channel);
2784  }
2785  if (channel > 0) {
2786  empty_chan_in_stack(stack, channel);
2787  }
2788  break;
2789  case EVENT_RESTART:
2790  cb_log(0, stack->port, "**** Received RESTART channel:%d\n", bc->restart_channel);
2792  break;
2793  default:
2794  break;
2795  }
2796 
2797  cb_log(5, stack->port, "Freeing Msg on prim:%x \n", frm->prim);
2798  free_msg(msg);
2799  return 1;
2800 }
static void empty_chan_in_stack(struct misdn_stack *stack, int channel)
Definition: isdn_lib.c:605
static int handle_cr(struct misdn_stack *stack, iframe_t *frm)
Definition: isdn_lib.c:1686
char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
static int handle_event_te(struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
Definition: isdn_lib.c:1590
#define bc
struct isdn_msg msgs_g[]
static int clean_up_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:815
int restart_channel
B channel to restart if received a RESTART message.
Definition: isdn_lib.h:408
void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
Definition: isdn_lib.c:77
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
B channel control structure.
Definition: isdn_lib.h:324
Definition: astman.c:222
Definition: muted.c:95
struct misdn_bchannel * find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:1536
enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *frm, int nt)
void * user_data
Definition: isdn_lib.c:219
event_response_e
Definition: isdn_lib.h:110
int need_release_complete
TRUE if RELEASE_COMPLETE needs to be sent to clear a call.
Definition: isdn_lib.h:392
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
static void empty_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:679
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
int misdn_lib_send_restart(int port, int channel)
Definition: isdn_lib.c:3943
int nt
TRUE if NT side of protocol (TE otherwise)
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
int out_cause
Q.931 Cause for disconnection code (sent)
Definition: isdn_lib.h:677
#define AST_CAUSE_REQUESTED_CHAN_UNAVAIL
Definition: causes.h:124
static struct misdn_stack * find_stack_by_addr(int addr)
Definition: isdn_lib.c:1472
int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event)
Definition: isdn_lib.c:3523
int cause
Q.931 Cause for disconnection code (received)
Definition: isdn_lib.h:671
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *frm, struct misdn_bchannel *bc, int nt)
int l3_id
Layer 3 process ID.
Definition: isdn_lib.h:399
event_e
Definition: isdn_lib.h:119

◆ handle_l1()

static int handle_l1 ( msg_t *  msg)
static

Definition at line 2803 of file isdn_lib.c.

References cb_event, cb_log, EVENT_CLEANUP, find_stack_by_addr(), MISDN_INITIALIZED, misdn_lib_get_l2_up(), pthread_mutex_lock, pthread_mutex_unlock, and misdn_lib::user_data.

Referenced by manager_isdn_handler().

2804 {
2805  iframe_t *frm = (iframe_t*) msg->data;
2806  struct misdn_stack *stack = find_stack_by_addr(frm->addr);
2807 
2808  if (!stack) return 0 ;
2809 
2810  switch (frm->prim) {
2811  case PH_ACTIVATE | CONFIRM:
2812  /* we have to check for errors! */
2813  if (frm->len) {
2814  cb_log (3, stack->port, "L1: PH_ACTIVATE|REQUEST returned error!\n");
2815  free_msg(msg);
2816  return 1;
2817  }
2818  /* fall through */
2819  case PH_ACTIVATE | INDICATION:
2820  cb_log (3, stack->port, "L1: PH L1Link Up!\n");
2821  stack->l1link=1;
2822 
2823  if (stack->nt) {
2824 
2825  pthread_mutex_lock(&stack->nstlock);
2826  if (stack->nst.l1_l2(&stack->nst, msg))
2827  free_msg(msg);
2828  pthread_mutex_unlock(&stack->nstlock);
2829 
2830  if (stack->ptp)
2831  misdn_lib_get_l2_up(stack);
2832  } else {
2833  free_msg(msg);
2834  }
2835  return 1;
2836 
2837  case PH_ACTIVATE | REQUEST:
2838  free_msg(msg);
2839  cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n");
2840  return 1;
2841 
2842  case PH_DEACTIVATE | REQUEST:
2843  free_msg(msg);
2844  cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n");
2845  return 1;
2846 
2847  case PH_DEACTIVATE | CONFIRM:
2848  /* we have to check for errors! */
2849  if (frm->len) {
2850  cb_log (3, stack->port, "L1: PH_DEACTIVATE|REQUEST returned error!\n");
2851  free_msg(msg);
2852  return 1;
2853  }
2854  /* fall through */
2855  case PH_DEACTIVATE | INDICATION:
2856  cb_log (3, stack->port, "L1: PH L1Link Down! \n");
2857 
2858 #if 0
2859  for (i=0; i<=stack->b_num; i++) {
2861  cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data);
2862  }
2863  }
2864 #endif
2865 
2866  if (stack->nt) {
2867  pthread_mutex_lock(&stack->nstlock);
2868  if (stack->nst.l1_l2(&stack->nst, msg))
2869  free_msg(msg);
2870  pthread_mutex_unlock(&stack->nstlock);
2871  } else {
2872  free_msg(msg);
2873  }
2874 
2875  stack->l1link=0;
2876  stack->l2link=0;
2877  return 1;
2878  }
2879 
2880  return 0;
2881 }
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
static enum global_states global_state
Definition: isdn_lib.c:199
int misdn_lib_get_l2_up(struct misdn_stack *stack)
Definition: isdn_lib.c:932
void * user_data
Definition: isdn_lib.c:219
#define pthread_mutex_lock
Definition: lock.h:623
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
static struct misdn_stack * find_stack_by_addr(int addr)
Definition: isdn_lib.c:1472
#define pthread_mutex_unlock
Definition: lock.h:624
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ handle_l2()

static int handle_l2 ( msg_t *  msg)
static

Definition at line 2883 of file isdn_lib.c.

References cb_event, cb_log, EVENT_PORT_ALARM, find_stack_by_addr(), and misdn_lib::user_data.

Referenced by manager_isdn_handler().

2884 {
2885  iframe_t *frm = (iframe_t*) msg->data;
2886 
2887  struct misdn_stack *stack = find_stack_by_addr(frm->addr);
2888 
2889  if (!stack) {
2890  return 0 ;
2891  }
2892 
2893  switch(frm->prim) {
2894 
2895  case DL_ESTABLISH | REQUEST:
2896  cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n");
2897  free_msg(msg);
2898  return 1;
2899  case DL_RELEASE | REQUEST:
2900  cb_log(1,stack->port,"DL_RELEASE|REQUEST \n");
2901  free_msg(msg);
2902  return 1;
2903 
2904  case DL_ESTABLISH | INDICATION:
2905  case DL_ESTABLISH | CONFIRM:
2906  {
2907  cb_log (3, stack->port, "L2: L2Link Up! \n");
2908  if (stack->ptp && stack->l2link) {
2909  cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n");
2910  cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data);
2911  }
2912  stack->l2link=1;
2913  free_msg(msg);
2914  return 1;
2915  }
2916  break;
2917 
2918  case DL_RELEASE | INDICATION:
2919  case DL_RELEASE | CONFIRM:
2920  {
2921  cb_log (3, stack->port, "L2: L2Link Down! \n");
2922  stack->l2link=0;
2923 
2924  free_msg(msg);
2925  return 1;
2926  }
2927  break;
2928  }
2929  return 0;
2930 }
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
void * user_data
Definition: isdn_lib.c:219
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
static struct misdn_stack * find_stack_by_addr(int addr)
Definition: isdn_lib.c:1472
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ handle_mgmt()

static int handle_mgmt ( msg_t *  msg)
static

Definition at line 2932 of file isdn_lib.c.

References cb_log, clear_l3(), find_stack_by_addr(), and if().

Referenced by manager_isdn_handler().

2933 {
2934  iframe_t *frm = (iframe_t*) msg->data;
2935  struct misdn_stack *stack;
2936 
2937  if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) {
2938  cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ;
2939  free_msg(msg);
2940  return 1;
2941  }
2942 
2943  stack = find_stack_by_addr(frm->addr);
2944 
2945  if (!stack) {
2946  if (frm->prim == (MGR_DELLAYER|CONFIRM)) {
2947  cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n",
2948  frm->addr) ;
2949  free_msg(msg);
2950  return 1;
2951  }
2952 
2953  return 0;
2954  }
2955 
2956  switch(frm->prim) {
2957  case MGR_SHORTSTATUS | INDICATION:
2958  case MGR_SHORTSTATUS | CONFIRM:
2959  cb_log(5, stack->port, "MGMT: Short status dinfo %x\n",frm->dinfo);
2960 
2961  switch (frm->dinfo) {
2962  case SSTATUS_L1_ACTIVATED:
2963  cb_log(3, stack->port, "MGMT: SSTATUS: L1_ACTIVATED \n");
2964  stack->l1link=1;
2965 
2966  break;
2967  case SSTATUS_L1_DEACTIVATED:
2968  cb_log(3, stack->port, "MGMT: SSTATUS: L1_DEACTIVATED \n");
2969  stack->l1link=0;
2970 #if 0
2971  clear_l3(stack);
2972 #endif
2973  break;
2974 
2975  case SSTATUS_L2_ESTABLISHED:
2976  cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n");
2977  stack->l2link=1;
2978  break;
2979 
2980  case SSTATUS_L2_RELEASED:
2981  cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n");
2982  stack->l2link=0;
2983  break;
2984  }
2985 
2986  free_msg(msg);
2987  return 1;
2988 
2989  case MGR_SETSTACK | INDICATION:
2990  cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo);
2991  free_msg(msg);
2992  return 1;
2993  case MGR_DELLAYER | CONFIRM:
2994  cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ;
2995  free_msg(msg);
2996  return 1;
2997 
2998  }
2999 
3000  /*
3001  if ( (frm->prim & 0x0f0000) == 0x0f0000) {
3002  cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ;
3003  free_msg(msg);
3004  return 1;
3005  } */
3006 
3007  return 0;
3008 }
static void clear_l3(struct misdn_stack *stack)
Definition: isdn_lib.c:852
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
static struct misdn_stack * find_stack_by_addr(int addr)
Definition: isdn_lib.c:1472
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ handle_timers()

static int handle_timers ( msg_t *  msg)
static

Definition at line 2216 of file isdn_lib.c.

References cb_log, misdn_stack::next, NULL, pthread_mutex_lock, pthread_mutex_unlock, and misdn_lib::stack_list.

Referenced by manager_isdn_handler().

2217 {
2218  iframe_t *frm= (iframe_t*)msg->data;
2219  struct misdn_stack *stack;
2220 
2221  /* Timer Stuff */
2222  switch (frm->prim) {
2223  case MGR_INITTIMER | CONFIRM:
2224  case MGR_ADDTIMER | CONFIRM:
2225  case MGR_DELTIMER | CONFIRM:
2226  case MGR_REMOVETIMER | CONFIRM:
2227  free_msg(msg);
2228  return(1);
2229  }
2230 
2231 
2232 
2233  if (frm->prim==(MGR_TIMER | INDICATION) ) {
2234  for (stack = glob_mgr->stack_list;
2235  stack;
2236  stack = stack->next) {
2237  itimer_t *it;
2238 
2239  if (!stack->nt) continue;
2240 
2241  it = stack->nst.tlist;
2242  /* find timer */
2243  for(it=stack->nst.tlist;
2244  it;
2245  it=it->next) {
2246  if (it->id == (int)frm->addr)
2247  break;
2248  }
2249  if (it) {
2250  mISDN_write_frame(stack->midev, msg->data, frm->addr,
2251  MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC);
2252  test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags);
2253  pthread_mutex_lock(&stack->nstlock);
2254  it->function(it->data);
2255  pthread_mutex_unlock(&stack->nstlock);
2256  free_msg(msg);
2257  return 1;
2258  }
2259  }
2260 
2261  cb_log(0, 0, "Timer Msg without Timer ??\n");
2262  free_msg(msg);
2263  return 1;
2264  }
2265 
2266  return 0;
2267 }
#define NULL
Definition: resample.c:96
#define pthread_mutex_lock
Definition: lock.h:623
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
struct misdn_stack * next
Next stack in the list of stacks.
#define pthread_mutex_unlock
Definition: lock.h:624
struct misdn_stack * stack_list
Definition: isdn_lib.c:225
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ init_bc()

static int init_bc ( struct misdn_stack stack,
struct misdn_bchannel bc,
int  midev,
int  port,
int  bidx 
)
static

IFACE

Definition at line 1210 of file isdn_lib.c.

References misdn_bchannel::astbuf, misdn_stack::b_num, bc_state_change(), BCHAN_CLEANED, buff, cb_log, empty_bc(), send_lock::lock, malloc(), MISDN_IBUF_SIZE, misdn_stack::nt, misdn_bchannel::nt, NULL, misdn_stack::port, misdn_bchannel::port, misdn_stack::pri, misdn_bchannel::pri, pthread_mutex_init, and misdn_bchannel::send_lock.

Referenced by misdn_lib_init().

1211 {
1212  if (!bc) {
1213  return -1;
1214  }
1215 
1216  cb_log(8, port, "Init.BC %d.\n",bidx);
1217 
1218  bc->send_lock = malloc(sizeof(struct send_lock)); /* XXX BUG! memory leak never freed */
1219  if (!bc->send_lock) {
1220  return -1;
1221  }
1223 
1224  empty_bc(bc);
1225 
1226  bc->port=stack->port;
1228  bc->nt=stack->nt?1:0;
1229  bc->pri=stack->pri;
1230 
1231  {
1232  ibuffer_t* ibuf= init_ibuffer(MISDN_IBUF_SIZE);
1233 
1234  if (!ibuf) return -1;
1235 
1236  clear_ibuffer( ibuf);
1237 
1238  ibuf->rsem=malloc(sizeof(sem_t));
1239  if (!ibuf->rsem) {
1240  return -1;
1241  }
1242 
1243  bc->astbuf=ibuf;
1244 
1245  if (sem_init(ibuf->rsem,1,0)<0)
1246  sem_init(ibuf->rsem,0,0);
1247 
1248  }
1249 
1250 #if 0 /* This code does not seem to do anything useful */
1251  if (bidx <= stack->b_num) {
1252  unsigned char buff[1025];
1253  iframe_t *frm = (iframe_t *) buff;
1254  stack_info_t *stinf;
1255  int ret;
1256 
1257  ret = mISDN_get_stack_info(midev, stack->port, buff, sizeof(buff));
1258  if (ret < 0) {
1259  cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret);
1260  return -1;
1261  }
1262 
1263  stinf = (stack_info_t *)&frm->data.p;
1264 
1265  cb_log(8, port, " --> Child %x\n",stinf->child[bidx]);
1266  }
1267 #endif
1268 
1269  return 0;
1270 }
#define pthread_mutex_init
Definition: lock.h:626
pthread_mutex_t lock
int midev
mISDN device handle returned by mISDN_open()
struct send_lock * send_lock
B channel send locking structure.
Definition: isdn_lib.h:326
void * astbuf
Not used. Contents are setup but not used.
Definition: isdn_lib.h:439
#define NULL
Definition: resample.c:96
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
char * malloc()
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
Definition: isdn_lib.h:367
int nt
TRUE if NT side of protocol (TE otherwise)
Definition: isdn_lib.h:364
void bc_state_change(struct misdn_bchannel *bc, enum bchannel_state state)
Definition: isdn_lib.c:639
static void empty_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:679
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
int nt
TRUE if NT side of protocol (TE otherwise)
#define MISDN_IBUF_SIZE
Definition: isdn_lib.c:250
static unsigned char * buff
Definition: chan_unistim.c:259
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ init_flip_bits()

static void init_flip_bits ( void  )
static

Definition at line 321 of file isdn_lib.c.

Referenced by misdn_lib_init().

322 {
323  int i,k;
324 
325  for (i = 0 ; i < 256 ; i++) {
326  unsigned char sample = 0 ;
327  for (k = 0; k<8; k++) {
328  if ( i & 1 << k ) sample |= 0x80 >> k;
329  }
330  flip_table[i] = sample;
331  }
332 }
static char flip_table[256]
Definition: isdn_lib.c:319

◆ isdn_lib_stop_dtmf()

void isdn_lib_stop_dtmf ( struct misdn_bchannel bc)

Definition at line 4462 of file isdn_lib.c.

References manager_ph_control().

Referenced by process_ast_dsp().

4463 {
4464  manager_ph_control(bc, DTMF_TONE_STOP, 0);
4465 }
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
Definition: isdn_lib.c:4419

◆ isdn_lib_update_ec()

void isdn_lib_update_ec ( struct misdn_bchannel bc)

Definition at line 4450 of file isdn_lib.c.

References misdn_bchannel::ec_enable, manager_ec_disable(), and manager_ec_enable().

Referenced by process_ast_dsp().

4451 {
4452 #ifdef MISDN_1_2
4453  if (*bc->pipeline)
4454 #else
4455  if (bc->ec_enable)
4456 #endif
4457  manager_ec_enable(bc);
4458  else
4459  manager_ec_disable(bc);
4460 }
int ec_enable
TRUE if the echo cancellor is enabled.
Definition: isdn_lib.h:688
void manager_ec_enable(struct misdn_bchannel *bc)
Definition: isdn_lib.c:4628
void manager_ec_disable(struct misdn_bchannel *bc)
Definition: isdn_lib.c:4677

◆ isdn_lib_update_rxgain()

void isdn_lib_update_rxgain ( struct misdn_bchannel bc)

Definition at line 4440 of file isdn_lib.c.

References manager_ph_control(), and misdn_bchannel::rxgain.

Referenced by process_ast_dsp().

4441 {
4442  manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain);
4443 }
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
Definition: isdn_lib.c:4419
int rxgain
Rx gain setting (range -8 to 8)
Definition: isdn_lib.h:714

◆ isdn_lib_update_txgain()

void isdn_lib_update_txgain ( struct misdn_bchannel bc)

Definition at line 4445 of file isdn_lib.c.

References manager_ph_control(), and misdn_bchannel::txgain.

Referenced by process_ast_dsp().

4446 {
4447  manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain);
4448 }
int txgain
Tx gain setting (range -8 to 8)
Definition: isdn_lib.h:708
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
Definition: isdn_lib.c:4419

◆ manager_bchannel_activate()

void manager_bchannel_activate ( struct misdn_bchannel bc)

Definition at line 4329 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::astbuf, buf, cb_log, get_stack_by_bc(), misdn_stack::midev, NULL, misdn_stack::port, and misdn_bchannel::port.

Referenced by setup_bc().

4330 {
4331  char buf[128];
4332 
4333  struct misdn_stack *stack=get_stack_by_bc(bc);
4334 
4335  if (!stack) {
4336  cb_log(0, bc->port, "bchannel_activate: Stack not found !");
4337  return ;
4338  }
4339 
4340  /* we must activate if we are deactivated */
4341  clear_ibuffer(bc->astbuf);
4342 
4343  cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr);
4344 
4345  mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC);
4346 
4347  return ;
4348 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int midev
mISDN device handle returned by mISDN_open()
void * astbuf
Not used. Contents are setup but not used.
Definition: isdn_lib.h:439
#define NULL
Definition: resample.c:96
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ manager_bchannel_cleanup()

void manager_bchannel_cleanup ( struct misdn_bchannel bc)

◆ manager_bchannel_deactivate()

void manager_bchannel_deactivate ( struct misdn_bchannel bc)

Definition at line 4351 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_bchannel::astbuf, misdn_bchannel::bc_state, bc_state_change(), BCHAN_ACTIVATED, BCHAN_BRIDGED, BCHAN_RELEASE, buf, cb_log, misdn_bchannel::conf_id, misdn_bchannel::generate_tone, get_stack_by_bc(), misdn_stack::midev, misdn_split_conf(), NULL, misdn_stack::port, and misdn_bchannel::port.

Referenced by clean_up_bc().

4352 {
4353  struct misdn_stack *stack=get_stack_by_bc(bc);
4354  char buf[128];
4355 
4356  switch (bc->bc_state) {
4357  case BCHAN_ACTIVATED:
4358  break;
4359  case BCHAN_BRIDGED:
4360  misdn_split_conf(bc,bc->conf_id);
4361  break;
4362  default:
4363  cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n");
4364  return ;
4365 
4366  }
4367 
4368  cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr);
4369 
4370  bc->generate_tone=0;
4371 
4372  mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC);
4373 
4374  clear_ibuffer(bc->astbuf);
4375 
4377 
4378  return;
4379 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int midev
mISDN device handle returned by mISDN_open()
void * astbuf
Not used. Contents are setup but not used.
Definition: isdn_lib.h:439
#define NULL
Definition: resample.c:96
int conf_id
Bridging conference ID.
Definition: isdn_lib.h:553
void bc_state_change(struct misdn_bchannel *bc, enum bchannel_state state)
Definition: isdn_lib.c:639
void misdn_split_conf(struct misdn_bchannel *bc, int conf_id)
Definition: isdn_lib.c:4719
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429
enum bchannel_state bc_state
Current B Channel state.
Definition: isdn_lib.h:547
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
int generate_tone
TRUE if tone generator allowed to start.
Definition: isdn_lib.h:541

◆ manager_bchannel_setup()

void manager_bchannel_setup ( struct misdn_bchannel bc)

◆ manager_clean_bc()

void manager_clean_bc ( struct misdn_bchannel bc)

Definition at line 4489 of file isdn_lib.c.

References cb_event, misdn_bchannel::channel, empty_bc(), empty_chan_in_stack(), EVENT_CLEANUP, get_stack_by_bc(), misdn_bchannel::in_use, and NULL.

Referenced by misdn_lib_pid_restart().

4490 {
4491  struct misdn_stack *stack=get_stack_by_bc(bc);
4492 
4493  if (stack && bc->channel > 0) {
4494  empty_chan_in_stack(stack, bc->channel);
4495  }
4496  empty_bc(bc);
4497  bc->in_use=0;
4498 
4499  cb_event(EVENT_CLEANUP, bc, NULL);
4500 }
static void empty_chan_in_stack(struct misdn_stack *stack, int channel)
Definition: isdn_lib.c:605
enum event_response_e(* cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data)
Definition: isdn_lib.c:30
#define NULL
Definition: resample.c:96
static void empty_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:679
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411

◆ manager_ec_disable()

void manager_ec_disable ( struct misdn_bchannel bc)

Definition at line 4677 of file isdn_lib.c.

References misdn_bchannel::capability, cb_log, misdn_bchannel::ec_enable, ECHOCAN_OFF, get_stack_by_bc(), manager_ph_control(), manager_ph_control_block(), misdn_cap_is_speech(), and misdn_stack::port.

Referenced by clean_up_bc(), handle_cli_misdn_toggle_echocancel(), and isdn_lib_update_ec().

4678 {
4679  struct misdn_stack *stack=get_stack_by_bc(bc);
4680 
4681  cb_log(4, stack?stack->port:0," --> ec_disable\n");
4682 
4683  if (!misdn_cap_is_speech(bc->capability)) {
4684  cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n");
4685  return;
4686  }
4687 
4688 #ifdef MISDN_1_2
4689  manager_ph_control_block(bc, PIPELINE_CFG, "", 0);
4690 #else
4691  if ( ! bc->ec_enable) {
4692  cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
4694  }
4695 #endif
4696 }
#define ECHOCAN_OFF
Definition: isdn_lib.c:230
int ec_enable
TRUE if the echo cancellor is enabled.
Definition: isdn_lib.h:688
int capability
SETUP message bearer capability field code value.
Definition: isdn_lib.h:609
int misdn_cap_is_speech(int cap)
Definition: isdn_lib.c:436
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
Definition: isdn_lib.c:4419
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
Definition: isdn_lib.c:4470
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ manager_ec_enable()

void manager_ec_enable ( struct misdn_bchannel bc)

Definition at line 4628 of file isdn_lib.c.

References misdn_bchannel::capability, cb_log, misdn_bchannel::ec_deftaps, misdn_bchannel::ec_enable, ECHOCAN_ON, get_stack_by_bc(), manager_ph_control_block(), misdn_cap_is_speech(), and misdn_stack::port.

Referenced by handle_cli_misdn_toggle_echocancel(), handle_event_te(), isdn_lib_update_ec(), and misdn_lib_send_event().

4629 {
4630  struct misdn_stack *stack=get_stack_by_bc(bc);
4631 
4632  cb_log(4, stack?stack->port:0,"ec_enable\n");
4633 
4634  if (!misdn_cap_is_speech(bc->capability)) {
4635  cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n");
4636  } else {
4637 
4638 #ifdef MISDN_1_2
4639  if (*bc->pipeline) {
4640  cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline);
4641  manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1);
4642  }
4643 #else
4644  int ec_arr[2];
4645 
4646  if (bc->ec_enable) {
4647  cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps);
4648 
4649  switch (bc->ec_deftaps) {
4650  case 4:
4651  case 8:
4652  case 16:
4653  case 32:
4654  case 64:
4655  case 128:
4656  case 256:
4657  case 512:
4658  case 1024:
4659  cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps);
4660  break;
4661  default:
4662  cb_log(0, stack->port, "Taps should be power of 2\n");
4663  bc->ec_deftaps=128;
4664  }
4665 
4666  ec_arr[0]=bc->ec_deftaps;
4667  ec_arr[1]=0;
4668 
4669  manager_ph_control_block(bc, ECHOCAN_ON, ec_arr, sizeof(ec_arr));
4670  }
4671 #endif
4672  }
4673 }
int ec_enable
TRUE if the echo cancellor is enabled.
Definition: isdn_lib.h:688
int capability
SETUP message bearer capability field code value.
Definition: isdn_lib.h:609
int misdn_cap_is_speech(int cap)
Definition: isdn_lib.c:436
#define ECHOCAN_ON
Definition: isdn_lib.c:229
struct misdn_stack * get_stack_by_bc(struct misdn_bchannel *bc)
Definition: isdn_lib.c:152
void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len)
Definition: isdn_lib.c:4470
int ec_deftaps
Number of taps in the echo cancellor when enabled.
Definition: isdn_lib.h:693
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ manager_event_handler()

static void manager_event_handler ( void *  arg)
static

wait for events

Definition at line 4025 of file isdn_lib.c.

References misdn_lib::activatequeue, cb_log, misdn_stack::downqueue, find_bc_by_l3id(), misdn_lib::midev, misdn_make_dummy(), misdn_lib::new_msg, misdn_stack::next, misdn_stack::nst, misdn_stack::nstlock, misdn_stack::nt, misdn_stack::port, pthread_mutex_lock, pthread_mutex_unlock, send_msg(), and misdn_lib::stack_list.

Referenced by misdn_lib_init().

4026 {
4027  sem_post(&handler_started);
4028  while (1) {
4029  struct misdn_stack *stack;
4030  msg_t *msg;
4031 
4032  /** wait for events **/
4033  sem_wait(&glob_mgr->new_msg);
4034 
4035  for (msg=msg_dequeue(&glob_mgr->activatequeue);
4036  msg;
4037  msg=msg_dequeue(&glob_mgr->activatequeue)
4038  )
4039  {
4040 
4041  iframe_t *frm = (iframe_t*) msg->data ;
4042 
4043  switch ( frm->prim) {
4044  case MGR_SETSTACK | REQUEST :
4045  free_msg(msg);
4046  break;
4047  default:
4048  mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
4049  free_msg(msg);
4050  }
4051  }
4052 
4053  for (stack=glob_mgr->stack_list;
4054  stack;
4055  stack=stack->next ) {
4056  /* Here we should check if we really want to
4057  send all the messages we've queued, lets
4058  assume we've queued a Disconnect, but
4059  received it already from the other side!*/
4060 
4061  while ( (msg=msg_dequeue(&stack->downqueue)) ) {
4062  if (stack->nt ) {
4063  pthread_mutex_lock(&stack->nstlock);
4064  if (stack->nst.manager_l3(&stack->nst, msg))
4065  cb_log(0, stack->port, "[email protected] Sending Message in NT-Stack.\n");
4066  pthread_mutex_unlock(&stack->nstlock);
4067  } else {
4068  iframe_t *frm = (iframe_t *)msg->data;
4069  struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo);
4070  if (bc)
4071  send_msg(glob_mgr->midev, bc, msg);
4072  else {
4073  struct misdn_bchannel dummybc;
4074 
4075  misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0);
4076  if (frm->dinfo == MISDN_ID_GLOBAL || frm->dinfo == MISDN_ID_DUMMY ) {
4077  cb_log(5,0," --> GLOBAL/DUMMY\n");
4078  } else {
4079  /*
4080  * We need to be able to at least answer with RELEASE_COMPLETE
4081  * on SETUP|INDICATION errors so use a dummy bc.
4082  */
4083  cb_log(0,0,"No bc for Message. Using dummy_bc\n");
4084  }
4085  send_msg(glob_mgr->midev, &dummybc, msg);
4086  }
4087  }
4088  }
4089  }
4090  }
4091 }
int midev
mISDN device handle returned by mISDN_open()
Definition: isdn_lib.c:214
#define bc
void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel)
Definition: isdn_lib.c:77
B channel control structure.
Definition: isdn_lib.h:324
pthread_mutex_t nstlock
net_stack_t nst
struct misdn_bchannel * find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:1536
sem_t new_msg
Definition: isdn_lib.c:223
#define pthread_mutex_lock
Definition: lock.h:623
static int send_msg(int midev, struct misdn_bchannel *bc, msg_t *dmsg)
Definition: isdn_lib.c:410
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
msg_queue_t downqueue
Queue of Event messages to send to mISDN.
int nt
TRUE if NT side of protocol (TE otherwise)
struct misdn_stack * next
Next stack in the list of stacks.
#define pthread_mutex_unlock
Definition: lock.h:624
int port
Logical Layer 1 port associated with this stack.
msg_queue_t activatequeue
Definition: isdn_lib.c:221
struct misdn_stack * stack_list
Definition: isdn_lib.c:225
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
static sem_t handler_started
Definition: isdn_lib.c:4022

◆ manager_find_bc_by_pid()

struct misdn_bchannel * manager_find_bc_by_pid ( int  pid)

Definition at line 3152 of file isdn_lib.c.

References misdn_stack::b_num, misdn_stack::bc, misdn_bchannel::in_use, misdn_stack::next, NULL, misdn_bchannel::pid, and misdn_lib::stack_list.

Referenced by misdn_lib_pid_restart().

3153 {
3154  struct misdn_stack *stack;
3155  int i;
3156 
3157  for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
3158  for (i = 0; i <= stack->b_num; i++) {
3159  if (stack->bc[i].in_use && stack->bc[i].pid == pid) {
3160  return &stack->bc[i];
3161  }
3162  }
3163  }
3164 
3165  return NULL;
3166 }
#define NULL
Definition: resample.c:96
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
int pid
B channel process ID (1-5000)
Definition: isdn_lib.h:402
int in_use
TRUE if B channel record is in use.
Definition: isdn_lib.h:420
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
struct misdn_stack * next
Next stack in the list of stacks.
struct misdn_stack * stack_list
Definition: isdn_lib.c:225

◆ manager_isdn_get_info()

char* manager_isdn_get_info ( enum event_e  event)

Definition at line 4324 of file isdn_lib.c.

References isdn_get_info(), and msgs_g.

Referenced by cb_events().

4325 {
4326  return isdn_get_info(msgs_g , event, 0);
4327 }
char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
struct isdn_msg msgs_g[]
Definition: astman.c:222

◆ manager_isdn_handler()

int manager_isdn_handler ( iframe_t *  frm,
msg_t *  msg 
)

Definition at line 3837 of file isdn_lib.c.

References cb_log, handle_bchan(), handle_err(), handle_frm_nt(), handle_frm_te(), handle_l1(), handle_l2(), handle_mgmt(), handle_timers(), and LOG_NOTICE.

Referenced by misdn_lib_isdn_event_catcher().

3838 {
3839 
3840  if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) {
3841  cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n");
3842  }
3843 
3844  /* Timer primitives must be handled first, because the frm->addr is a different
3845  * "address space" than the stack/instance address of other Lx primitives.
3846  */
3847  if (handle_timers(msg)) {
3848  return 0;
3849  }
3850 
3851  if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) {
3852  static int unhandled_bmsg_count=1000;
3853  if (handle_bchan(msg)) {
3854  return 0 ;
3855  }
3856 
3857  if (unhandled_bmsg_count==1000) {
3858  cb_log(0, 0, "received 1k Unhandled Bchannel Messages: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo);
3859  unhandled_bmsg_count=0;
3860  }
3861 
3862  unhandled_bmsg_count++;
3863  free_msg(msg);
3864  return 0;
3865  }
3866 
3867 #ifdef RECV_FRM_SYSLOG_DEBUG
3868  syslog(LOG_NOTICE,"mISDN recv: ADDR:%x PRIM:%x DINFO:%x\n", frm->addr, frm->prim, frm->dinfo);
3869 #endif
3870 
3871  if (handle_mgmt(msg))
3872  return 0 ;
3873 
3874  if (handle_l2(msg))
3875  return 0 ;
3876 
3877  /* Its important to handle l1 AFTER l2 */
3878  if (handle_l1(msg))
3879  return 0 ;
3880 
3881  if (handle_frm_nt(msg)) {
3882  return 0;
3883  }
3884 
3885  if (handle_frm_te(msg)) {
3886  return 0;
3887  }
3888 
3889  if (handle_err(msg)) {
3890  return 0 ;
3891  }
3892 
3893  cb_log(0, 0, "Unhandled Message: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo);
3894  free_msg(msg);
3895 
3896 
3897  return 0;
3898 }
static int handle_mgmt(msg_t *msg)
Definition: isdn_lib.c:2932
static int handle_l1(msg_t *msg)
Definition: isdn_lib.c:2803
static int handle_bchan(msg_t *msg)
Definition: isdn_lib.c:2395
static int handle_err(msg_t *msg)
Definition: isdn_lib.c:3779
static int handle_frm_nt(msg_t *msg)
Definition: isdn_lib.c:2626
#define LOG_NOTICE
Definition: logger.h:263
static int handle_timers(msg_t *msg)
Definition: isdn_lib.c:2216
static int handle_l2(msg_t *msg)
Definition: isdn_lib.c:2883
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
static int handle_frm_te(msg_t *msg)
Definition: isdn_lib.c:2661

◆ manager_ph_control()

void manager_ph_control ( struct misdn_bchannel bc,
int  c1,
int  c2 
)

Definition at line 4419 of file isdn_lib.c.

References misdn_bchannel::addr, cb_log, d, misdn_lib::midev, and misdn_bchannel::port.

Referenced by handle_event_te(), isdn_lib_stop_dtmf(), isdn_lib_update_rxgain(), isdn_lib_update_txgain(), manager_ec_disable(), misdn_join_conf(), misdn_lib_echo(), misdn_lib_send_event(), misdn_lib_send_tone(), and misdn_split_conf().

4420 {
4421  unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)];
4422  iframe_t *ctrl = (iframe_t *)buffer; /* preload data */
4423  unsigned int *d = (unsigned int*)&ctrl->data.p;
4424  /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
4425 
4426  cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2);
4427 
4428  ctrl->prim = PH_CONTROL | REQUEST;
4429  ctrl->addr = bc->addr | FLG_MSG_DOWN;
4430  ctrl->dinfo = 0;
4431  ctrl->len = sizeof(unsigned int)*2;
4432  *d++ = c1;
4433  *d++ = c2;
4434  mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
4435 }
int midev
mISDN device handle returned by mISDN_open()
Definition: isdn_lib.c:214
static struct test_val d
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ manager_ph_control_block()

void manager_ph_control_block ( struct misdn_bchannel bc,
int  c1,
void *  c2,
int  c2_len 
)

Definition at line 4470 of file isdn_lib.c.

References misdn_bchannel::addr, d, and misdn_lib::midev.

Referenced by handle_event_te(), manager_ec_disable(), manager_ec_enable(), and misdn_lib_send_event().

4471 {
4472  unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len];
4473  iframe_t *ctrl = (iframe_t *)buffer;
4474  unsigned int *d = (unsigned int *)&ctrl->data.p;
4475  /*struct misdn_stack *stack=get_stack_by_bc(bc);*/
4476 
4477  ctrl->prim = PH_CONTROL | REQUEST;
4478  ctrl->addr = bc->addr | FLG_MSG_DOWN;
4479  ctrl->dinfo = 0;
4480  ctrl->len = sizeof(unsigned int) + c2_len;
4481  *d++ = c1;
4482  memcpy(d, c2, c2_len);
4483  mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC);
4484 }
int midev
mISDN device handle returned by mISDN_open()
Definition: isdn_lib.c:214
static struct test_val d
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429

◆ misdn_cap_is_speech()

int misdn_cap_is_speech ( int  cap)

◆ misdn_dump_chanlist()

void misdn_dump_chanlist ( void  )

Definition at line 483 of file isdn_lib.c.

References dump_chan_list(), get_misdn_stack(), and misdn_stack::next.

Referenced by handle_cli_misdn_show_channels().

484 {
485  struct misdn_stack *stack=get_misdn_stack();
486  for ( ; stack; stack=stack->next) {
487  dump_chan_list(stack);
488  }
489 
490 }
struct misdn_stack * get_misdn_stack(void)
Definition: isdn_lib.c:4698
struct misdn_stack * next
Next stack in the list of stacks.
static void dump_chan_list(struct misdn_stack *stack)
Definition: isdn_lib.c:464

◆ misdn_inband_avail()

int misdn_inband_avail ( struct misdn_bchannel bc)

Definition at line 444 of file isdn_lib.c.

References misdn_bchannel::early_bconnect, INFO_PI_CALL_NOT_E2E_ISDN, INFO_PI_CALLED_NOT_ISDN, INFO_PI_INBAND_AVAILABLE, and misdn_bchannel::progress_indicator.

Referenced by cb_events().

445 {
446 
447  if (!bc->early_bconnect) {
448  /* We have opted to never receive any available inband recorded messages */
449  return 0;
450  }
451 
452  switch (bc->progress_indicator) {
456  return 1;
457  default:
458  return 0;
459  }
460  return 0;
461 }
int progress_indicator
Progress Indicator IE progress description field. Used to determine if there is an inband audio messa...
Definition: isdn_lib.h:492
int early_bconnect
TRUE if the call progress indicators can indicate an inband audio message for the user to listen to...
Definition: isdn_lib.h:449

◆ misdn_join_conf()

void misdn_join_conf ( struct misdn_bchannel bc,
int  conf_id 
)

Definition at line 4705 of file isdn_lib.c.

References misdn_bchannel::addr, bc_state_change(), BCHAN_BRIDGED, cb_log, manager_ph_control(), misdn_lib_tx2misdn_frm(), and misdn_bchannel::port.

Referenced by bc_state_change(), and misdn_lib_bridge().

4706 {
4707  char data[16] = "";
4708 
4710  manager_ph_control(bc, CMX_RECEIVE_OFF, 0);
4711  manager_ph_control(bc, CMX_CONF_JOIN, conf_id);
4712 
4713  cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id);
4714 
4715  misdn_lib_tx2misdn_frm(bc, data, sizeof(data) - 1);
4716 }
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
Definition: isdn_lib.c:4419
void bc_state_change(struct misdn_bchannel *bc, enum bchannel_state state)
Definition: isdn_lib.c:639
int misdn_lib_tx2misdn_frm(struct misdn_bchannel *bc, void *data, int len)
Definition: isdn_lib.c:4382
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ misdn_lib_bridge()

void misdn_lib_bridge ( struct misdn_bchannel bc1,
struct misdn_bchannel bc2 
)

Definition at line 4728 of file isdn_lib.c.

References bc, bc_next_state_change(), BCHAN_ACTIVATED, BCHAN_BRIDGED, cb_log, misdn_bchannel::conf_id, misdn_join_conf(), NULL, misdn_bchannel::pid, and misdn_bchannel::port.

Referenced by misdn_write().

4729 {
4730  int conf_id = bc1->pid + 1;
4731  struct misdn_bchannel *bc_list[] = { bc1, bc2, NULL };
4732  struct misdn_bchannel **bc;
4733 
4734  cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port);
4735 
4736  for (bc=bc_list; *bc; bc++) {
4737  (*bc)->conf_id=conf_id;
4738  cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr);
4739 
4740  switch((*bc)->bc_state) {
4741  case BCHAN_ACTIVATED:
4742  misdn_join_conf(*bc,conf_id);
4743  break;
4744  default:
4746  break;
4747  }
4748  }
4749 }
#define bc
B channel control structure.
Definition: isdn_lib.h:324
#define NULL
Definition: resample.c:96
static void bc_next_state_change(struct misdn_bchannel *bc, enum bchannel_state state)
Definition: isdn_lib.c:659
int conf_id
Bridging conference ID.
Definition: isdn_lib.h:553
int pid
B channel process ID (1-5000)
Definition: isdn_lib.h:402
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
void misdn_join_conf(struct misdn_bchannel *bc, int conf_id)
Definition: isdn_lib.c:4705
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ misdn_lib_destroy()

void misdn_lib_destroy ( void  )

Definition at line 4285 of file isdn_lib.c.

References misdn_bchannel::addr, misdn_stack::b_num, misdn_stack::bc, buf, cb_log, misdn_lib::event_handler_thread, misdn_lib::event_thread, free(), misdn_stack::midev, misdn_lib::midev, MISDN_INITIALIZED, misdn_stack::next, NULL, misdn_stack::port, stack_destroy(), misdn_lib::stack_list, and te_lib_destroy().

Referenced by unload_module().

4286 {
4287  struct misdn_stack *help;
4288  int i;
4289 
4290  for ( help=glob_mgr->stack_list; help; help=help->next ) {
4291  for(i=0;i<=help->b_num; i++) {
4292  char buf[1024];
4293  mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
4294  help->bc[i].addr = 0;
4295  }
4296  cb_log (1, help->port, "Destroying this port.\n");
4297  stack_destroy(help);
4298  }
4299 
4301  cb_log(4, 0, "Killing Handler Thread\n");
4302  if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) {
4303  cb_log(4, 0, "Joining Handler Thread\n");
4304  pthread_join(glob_mgr->event_handler_thread, NULL);
4305  }
4306 
4307  cb_log(4, 0, "Killing Main Thread\n");
4308  if ( pthread_cancel(glob_mgr->event_thread) == 0 ) {
4309  cb_log(4, 0, "Joining Main Thread\n");
4310  pthread_join(glob_mgr->event_thread, NULL);
4311  }
4312  }
4313 
4314  cb_log(1, 0, "Closing mISDN device\n");
4316  while ((help = glob_mgr->stack_list)) {
4317  glob_mgr->stack_list = help->next;
4318  free(help);
4319  }
4320  free(glob_mgr);
4321  glob_mgr = NULL;
4322 }
int midev
mISDN device handle returned by mISDN_open()
Definition: isdn_lib.c:214
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int midev
mISDN device handle returned by mISDN_open()
static enum global_states global_state
Definition: isdn_lib.c:199
#define NULL
Definition: resample.c:96
void free()
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
static struct misdn_lib * glob_mgr
Definition: isdn_lib.c:261
int addr
B Channel mISDN driver layer ID from mISDN_get_layerid()
Definition: isdn_lib.h:429
struct misdn_stack * next
Next stack in the list of stacks.
void te_lib_destroy(int midev)
Definition: isdn_lib.c:3142
static void stack_destroy(struct misdn_stack *stack)
Definition: isdn_lib.c:1454
pthread_t event_handler_thread
Definition: isdn_lib.c:217
pthread_t event_thread
Definition: isdn_lib.c:216
int port
Logical Layer 1 port associated with this stack.
struct misdn_stack * stack_list
Definition: isdn_lib.c:225
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ misdn_lib_echo()

void misdn_lib_echo ( struct misdn_bchannel bc,
int  onoff 
)

Definition at line 4771 of file isdn_lib.c.

References cb_log, manager_ph_control(), and misdn_bchannel::port.

4772 {
4773  cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF");
4774  manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0);
4775 }
void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2)
Definition: isdn_lib.c:4419
int port
Logical Layer 1 port associated with this B channel.
Definition: isdn_lib.h:370
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ misdn_lib_find_held_bc()

struct misdn_bchannel* misdn_lib_find_held_bc ( int  port,
int  l3_id 
)

Find a held call's B channel record.

Parameters
portPort the call is on.
l3_idmISDN Layer 3 ID of held call.
Returns
Found bc-record or NULL.

Definition at line 4580 of file isdn_lib.c.

References bc, get_misdn_stack(), misdn_stack::next, NULL, misdn_stack::port, and stack_holder_find().

Referenced by misdn_hangup().

4581 {
4582  struct misdn_bchannel *bc;
4583  struct misdn_stack *stack;
4584 
4585  bc = NULL;
4586  for (stack = get_misdn_stack(); stack; stack = stack->next) {
4587  if (stack->port == port) {
4588  bc = stack_holder_find(stack, l3_id);
4589  break;
4590  }
4591  }
4592 
4593  return bc;
4594 }
struct misdn_stack * get_misdn_stack(void)
Definition: isdn_lib.c:4698
#define bc
struct misdn_bchannel * stack_holder_find(struct misdn_stack *stack, unsigned long l3id)
Definition: isdn_lib.c:4553
B channel control structure.
Definition: isdn_lib.h:324
#define NULL
Definition: resample.c:96
struct misdn_stack * next
Next stack in the list of stacks.
int port
Logical Layer 1 port associated with this stack.

◆ misdn_lib_get_free_bc()

struct misdn_bchannel* misdn_lib_get_free_bc ( int  port,
int  channel,
int  inout,
int  dec 
)

Definition at line 3205 of file isdn_lib.c.

References ARRAY_LEN, misdn_stack::b_num, bc, misdn_stack::bc, misdn_stack::blocked, cb_log, misdn_bchannel::channel, misdn_bchannel::cw, misdn_bchannel::dec, find_stack_by_port(), if(), MAX_BCHANS, misdn_bchannel::need_disconnect, misdn_bchannel::need_release, NULL, misdn_bchannel::port, prepare_bc(), misdn_stack::pri, pthread_mutex_lock, pthread_mutex_unlock, misdn_stack::ptp, misdn_stack::st_lock, and test_inuse().

Referenced by handle_cr(), handle_event_nt(), and misdn_request().

3206 {
3207  struct misdn_stack *stack;
3208  int i;
3209  int maxnum;
3210 
3212  cb_log(0, port, "Requested channel out of bounds (%d)\n", channel);
3213  return NULL;
3214  }
3215 
3216  /* Find the port stack structure */
3217  stack = find_stack_by_port(port);
3218  if (!stack) {
3219  cb_log(0, port, "Port is not configured (%d)\n", port);
3220  return NULL;
3221  }
3222 
3223  if (stack->blocked) {
3224  cb_log(0, port, "Port is blocked\n");
3225  return NULL;
3226  }
3227 
3228  pthread_mutex_lock(&stack->st_lock);
3229  if (channel > 0) {
3231  for (i = 0; i < stack->b_num; i++) {
3232  if (stack->bc[i].channel == channel) {
3233  if (test_inuse(&stack->bc[i])) {
3234  pthread_mutex_unlock(&stack->st_lock);
3235  cb_log(0, port, "Requested channel:%d on port:%d is already in use\n", channel, port);
3236  return NULL;
3237  } else {
3238  prepare_bc(&stack->bc[i], channel);
3239  pthread_mutex_unlock(&stack->st_lock);
3240  return &stack->bc[i];
3241  }
3242  }
3243  }
3244  } else {
3245  pthread_mutex_unlock(&stack->st_lock);
3246  cb_log(0, port, "Requested channel:%d is out of bounds on port:%d\n", channel, port);
3247  return NULL;
3248  }
3249  }
3250 
3251  /* Note: channel == 0 here */
3252  maxnum = (inout && !stack->pri && !stack->ptp) ? stack->b_num + 1 : stack->b_num;
3253  if (dec) {
3254  for (i = maxnum - 1; i >= 0; --i) {
3255  if (!test_inuse(&stack->bc[i])) {
3256  /* 3. channel on bri means CW*/
3257  if (!stack->pri && i == stack->b_num) {
3258  stack->bc[i].cw = 1;
3259  }
3260 
3261  prepare_bc(&stack->bc[i], channel);
3262  stack->bc[i].dec = 1;
3263  pthread_mutex_unlock(&stack->st_lock);
3264  return &stack->bc[i];
3265  }
3266  }
3267  } else {
3268  for (i = 0; i < maxnum; ++i) {
3269  if (!test_inuse(&stack->bc[i])) {
3270  /* 3. channel on bri means CW */
3271  if (!stack->pri && i == stack->b_num) {
3272  stack->bc[i].cw = 1;
3273  }
3274 
3275  prepare_bc(&stack->bc[i], channel);
3276  pthread_mutex_unlock(&stack->st_lock);
3277  return &stack->bc[i];
3278  }
3279  }
3280  }
3281  pthread_mutex_unlock(&stack->st_lock);
3282 
3283  cb_log(1, port, "There is no free channel on port (%d)\n", port);
3284  return NULL;
3285 }
int cw
TRUE if call waiting.
Definition: isdn_lib.h:426
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
Definition: muted.c:95
#define NULL
Definition: resample.c:96
int pri
TRUE if ISDN-PRI (ISDN-BRI otherwise)
struct misdn_bchannel bc[MAX_BCHANS+1+MISDN_MAX_REGISTER_LINKS]
B Channel record pool array (Must be dimensioned the same as struct misdn_stack.channels[]) ...
#define pthread_mutex_lock
Definition: lock.h:623
static void prepare_bc(struct misdn_bchannel *bc, int channel)
Definition: isdn_lib.c:3190
int dec
TRUE if allocate higher B channels first.
Definition: isdn_lib.h:395
int ptp
TRUE if Point-To-Point(PTP) (Point-To-Multipoint(PTMP) otherwise)
static struct misdn_stack * find_stack_by_port(int port)
Definition: isdn_lib.c:1487
int channel
Assigned B channel number B1, B2... 0 if not assigned.
Definition: isdn_lib.h:411
int blocked
TRUE if port is blocked.
#define pthread_mutex_unlock
Definition: lock.h:624
static int test_inuse(struct misdn_bchannel *bc)
Definition: isdn_lib.c:3168
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32
#define MAX_BCHANS
Definition: isdn_lib.h:76
pthread_mutex_t st_lock
Stack struct critical section lock.

◆ misdn_lib_get_l1_down()

static int misdn_lib_get_l1_down ( struct misdn_stack stack)
static

Definition at line 876 of file isdn_lib.c.

References cb_log, misdn_stack::midev, misdn_stack::port, and misdn_stack::upper_id.

Referenced by misdn_lib_get_port_down().

877 {
878  /* Pull Up L1 */
879  iframe_t act;
880  act.prim = PH_DEACTIVATE | REQUEST;
881  act.addr = stack->upper_id | FLG_MSG_DOWN;
882  act.dinfo = 0;
883  act.len = 0;
884 
885  cb_log(1, stack->port, "SENDING PH_DEACTIVATE | REQ\n");
886  return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
887 }
int upper_id
Upper layer mISDN ID (addr) (Layer 2/4)
int midev
mISDN device handle returned by mISDN_open()
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ misdn_lib_get_l1_up()

static int misdn_lib_get_l1_up ( struct misdn_stack stack)
static

Definition at line 918 of file isdn_lib.c.

References cb_log, misdn_stack::midev, misdn_stack::port, and misdn_stack::upper_id.

Referenced by misdn_lib_get_port_up(), misdn_lib_isdn_l1watcher(), misdn_lib_reinit_nt_stack(), misdn_lib_send_event(), and stack_init().

919 {
920  /* Pull Up L1 */
921  iframe_t act;
922  act.prim = PH_ACTIVATE | REQUEST;
923  act.addr = stack->upper_id | FLG_MSG_DOWN;
924 
925  act.dinfo = 0;
926  act.len = 0;
927 
928  cb_log(1, stack->port, "SENDING PH_ACTIVATE | REQ\n");
929  return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
930 }
int upper_id
Upper layer mISDN ID (addr) (Layer 2/4)
int midev
mISDN device handle returned by mISDN_open()
int port
Logical Layer 1 port associated with this stack.
void(* cb_log)(int level, int port, char *tmpl,...)
Definition: isdn_lib.c:32

◆ misdn_lib_get_l2_down()

static int misdn_lib_get_l2_down ( struct misdn_stack stack)
static

Definition at line 890 of file isdn_lib.c.

References create_l2msg(), misdn_stack::midev, misdn_stack::nst, misdn_stack::nstlock, misdn_stack::nt, pthread_mutex_lock, pthread_mutex_unlock, misdn_stack::ptp, and misdn_stack::upper_id.

Referenced by misdn_lib_get_port_down().

891 {
892 
893  if (stack->ptp && stack->nt) {
894  msg_t *dmsg;
895  /* L2 */
89