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

chan_unistim channel driver for Asterisk More...

#include "asterisk.h"
#include <sys/stat.h>
#include <signal.h>
#include "asterisk/paths.h"
#include "asterisk/network.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/unaligned.h"
#include "asterisk/netsock2.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/mwi.h"
#include "asterisk/musiconhold.h"
#include "asterisk/causes.h"
#include "asterisk/indications.h"
#include "asterisk/pickup.h"
#include "asterisk/astobj2.h"
#include "asterisk/astdb.h"
#include "asterisk/features_config.h"
#include "asterisk/bridge.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/format_cache.h"
Include dependency graph for chan_unistim.c:

Go to the source code of this file.

Data Structures

struct  unistim_device
 A device containing one or more lines. More...
 
struct  unistim_languages
 
struct  unistim_line
 
struct  unistim_menu_item
 
struct  unistim_subchannel
 
struct  unistimsession
 
struct  ustm_lang_entry
 
struct  wsabuf
 

Macros

#define AST_CONFIG_MAX_PATH   255
 
#define BUFFSEND   unsigned char buffsend[64] = { 0x00, 0x00, 0xaa, 0xbb, 0x02, 0x01 }
 
#define DEBUG_TIMER   dummy
 
#define DEFAULT_CODEC   0x00
 
#define DEFAULT_INTERDIGIT_TIMER   4000
 
#define DEFAULTCALLERID   "Unknown"
 
#define DEFAULTCALLERNAME   " "
 
#define DEFAULTCONTEXT   "default"
 
#define DEFAULTHEIGHT   3
 
#define DEVICE_NAME_LEN   16
 
#define EXPNUM   24
 
#define FAV_BLINK_FAST   0x20
 
#define FAV_BLINK_SLOW   0x40
 
#define FAV_ICON_BOX   0x3F
 
#define FAV_ICON_CALL_CENTER   0x34
 
#define FAV_ICON_CITY   0x31
 
#define FAV_ICON_COMPUTER   0x38
 
#define FAV_ICON_FAX   0x35
 
#define FAV_ICON_FORWARD   0x39
 
#define FAV_ICON_HEADPHONES   0x2E
 
#define FAV_ICON_HEADPHONES_ONHOLD   0x2F
 
#define FAV_ICON_HOME   0x30
 
#define FAV_ICON_INBOX   0x3C
 
#define FAV_ICON_LOCKED   0x3A
 
#define FAV_ICON_MAILBOX   0x36
 
#define FAV_ICON_MEETING   0x3E
 
#define FAV_ICON_NONE   0x00
 
#define FAV_ICON_OFFHOOK_BLACK   0x24
 
#define FAV_ICON_OFFHOOK_WHITE   0x25
 
#define FAV_ICON_ONHOLD_BLACK   0x26
 
#define FAV_ICON_ONHOLD_WHITE   0x27
 
#define FAV_ICON_ONHOOK_BLACK   0x20
 
#define FAV_ICON_ONHOOK_WHITE   0x21
 
#define FAV_ICON_OUTBOX   0x3D
 
#define FAV_ICON_PAGER   0x33
 
#define FAV_ICON_PHONE_BLACK   0x2A
 
#define FAV_ICON_PHONE_WHITE   0x2B
 
#define FAV_ICON_REFLECT   0x37
 
#define FAV_ICON_SHARP   0x32
 
#define FAV_ICON_SPEAKER_OFFHOOK_BLACK   0x28
 
#define FAV_ICON_SPEAKER_OFFHOOK_WHITE   0x29
 
#define FAV_ICON_SPEAKER_ONHOLD_BLACK   0x2C
 
#define FAV_ICON_SPEAKER_ONHOLD_WHITE   0x2D
 
#define FAV_ICON_SPEAKER_ONHOOK_BLACK   0x22
 
#define FAV_ICON_SPEAKER_ONHOOK_WHITE   0x23
 
#define FAV_ICON_TRASH   0x3B
 
#define FAV_LINE_ICON   FAV_ICON_ONHOOK_BLACK
 
#define FAV_MAX_LENGTH   0x0A
 
#define FAVNUM   6
 
#define IDLE_WAIT   1000
 
#define LED_BAR_OFF   0x00 /* bar off */
 
#define LED_BAR_ON   0x01 /* bar on */
 
#define LED_BAR_P2   0x02 /* bar 1s on/1s */
 
#define LED_BAR_P3   0x03 /* bar 2.5s on/0.5s off */
 
#define LED_BAR_P4   0x04 /* bar 0.6s on/0.3s off */
 
#define LED_BAR_P5   0x05 /* bar 0.5s on/0.5s off */
 
#define LED_BAR_P6   0x06 /* bar 2s on/0.5s off */
 
#define LED_BAR_P7   0x07 /* bar off */
 
#define LED_HEADPHONE_OFF   0x010
 
#define LED_HEADPHONE_ON   0x011
 
#define LED_MUTE_BLINK   0x1A
 
#define LED_MUTE_OFF   0x018
 
#define LED_MUTE_ON   0x019
 
#define LED_SPEAKER_OFF   0x08
 
#define LED_SPEAKER_ON   0x09
 
#define MAX_BUF_NUMBER   150
 
#define MAX_BUF_SIZE   64
 
#define MAX_ENTRY_LOG   30
 
#define MAX_SCREEN_NUMBER   15
 
#define MONTH_LABEL_SIZE   3
 
#define MUTE_OFF   0x00
 
#define MUTE_ON   0xFF
 
#define MUTE_ON_DISCRET   0xCE
 
#define NB_MAX_RETRANSMIT   8
 
#define OUTPUT_HANDSET   0xC0
 
#define OUTPUT_HEADPHONE   0xC1
 
#define OUTPUT_SPEAKER   0xC2
 
#define RETRANSMIT_TIMER   2000
 
#define SELECTCODEC_MAX_LENGTH   2
 
#define SELECTCODEC_MSG   "Codec number : .."
 
#define SELECTCODEC_START_ENTRY_POS   15
 
#define SELECTEXTENSION_MAX_LENGTH   10
 
#define SELECTEXTENSION_MSG   ".........."
 
#define SELECTEXTENSION_START_ENTRY_POS   0
 
#define SIZE_HEADER   6
 
#define SIZE_MAC_ADDR   17
 
#define SIZE_PAGE   4096
 
#define STATUS_LENGTH_MAX   28
 
#define SUB_REAL   0
 
#define SUB_RING   1
 
#define SUB_THREEWAY   2
 
#define TEXT_INVERSE   0x25
 
#define TEXT_LENGTH_MAX   24
 
#define TEXT_LINE0   0x00
 
#define TEXT_LINE1   0x20
 
#define TEXT_LINE2   0x40
 
#define TEXT_NORMAL   0x05
 
#define TIMER_MWI   5000
 
#define USTM_LANG_DIR   "unistimLang"
 
#define USTM_LOG_DIR   "unistimHistory"
 
#define VOLUME_INSANELY_LOUD   0x07
 
#define VOLUME_LOW   0x01
 
#define VOLUME_LOW_SPEAKER   0x03
 
#define VOLUME_NORMAL   0x02
 

Enumerations

enum  autoprov_extn { EXTENSION_NONE = 0, EXTENSION_ASK, EXTENSION_LINE, EXTENSION_TN }
 
enum  autoprovision { AUTOPROVISIONING_NO = 0, AUTOPROVISIONING_YES, AUTOPROVISIONING_TN }
 
enum  charset {
  LANG_DEFAULT, ISO_8859_1, ISO_8859_2, ISO_8859_4,
  ISO_8859_5, ISO_2022_JP
}
 
enum  handset_state { STATE_ONHOOK, STATE_OFFHOOK }
 
enum  phone_key {
  KEY_0 = 0x40, KEY_1 = 0x41, KEY_2 = 0x42, KEY_3 = 0x43,
  KEY_4 = 0x44, KEY_5 = 0x45, KEY_6 = 0x46, KEY_7 = 0x47,
  KEY_8 = 0x48, KEY_9 = 0x49, KEY_STAR = 0x4a, KEY_SHARP = 0x4b,
  KEY_UP = 0x4c, KEY_DOWN = 0x4d, KEY_RIGHT = 0x4e, KEY_LEFT = 0x4f,
  KEY_QUIT = 0x50, KEY_COPY = 0x51, KEY_FUNC1 = 0x54, KEY_FUNC2 = 0x55,
  KEY_FUNC3 = 0x56, KEY_FUNC4 = 0x57, KEY_ONHOLD = 0x5b, KEY_HANGUP = 0x5c,
  KEY_MUTE = 0x5d, KEY_HEADPHN = 0x5e, KEY_LOUDSPK = 0x5f, KEY_FAV0 = 0x60,
  KEY_FAV1 = 0x61, KEY_FAV2 = 0x62, KEY_FAV3 = 0x63, KEY_FAV4 = 0x64,
  KEY_FAV5 = 0x65, KEY_COMPUTR = 0x7b, KEY_CONF = 0x7c, KEY_SNDHIST = 0x7d,
  KEY_RCVHIST = 0x7e, KEY_INDEX = 0x7f
}
 
enum  phone_state {
  STATE_INIT, STATE_AUTHDENY, STATE_MAINPAGE, STATE_EXTENSION,
  STATE_DIALPAGE, STATE_RINGING, STATE_CALL, STATE_SELECTOPTION,
  STATE_SELECTCODEC, STATE_SELECTLANGUAGE, STATE_CLEANING, STATE_HISTORY
}
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int attempt_transfer (struct unistim_subchannel *p1, struct unistim_subchannel *p2)
 
static struct unistim_devicebuild_device (const char *cat, const struct ast_variable *v)
 
static void change_callerid (struct unistimsession *pte, int type, char *callerid)
 
static void change_favorite_icon (struct unistimsession *pte, unsigned char status)
 
static struct unistimsessionchannel_to_session (struct ast_channel *ast)
 
static void check_send_queue (struct unistimsession *pte)
 
static void close_call (struct unistimsession *pte)
 
static void close_client (struct unistimsession *s)
 
static char * control2str (int ind)
 
static struct unistimsessioncreate_client (const struct sockaddr_in *addr_from)
 
static void delete_device (struct unistim_device *d)
 
static void discard_call (struct unistimsession *pte)
 
static void display_last_error (const char *sz_msg)
 
static void * do_monitor (void *data)
 
static void dummy (char *unused,...)
 
static int find_language (const char *)
 
static struct unistim_linefind_line_by_number (struct unistim_device *d, const char *val)
 
static int find_rtp_port (struct unistim_subchannel *s)
 
static struct unistim_subchannelfind_subchannel_by_name (const char *dest)
 
static void finish_bookmark (void)
 
static int get_active_softkey (struct unistimsession *pte)
 
static int get_avail_softkey (struct unistimsession *pte, const char *name)
 
static struct unistim_subchannelget_sub (struct unistim_device *device, int type)
 
static struct unistim_subchannelget_sub_holding (struct unistim_device *device, int type, int holding)
 
static unsigned int get_tick_count (void)
 
static int get_to_address (int fd, struct sockaddr_in *toAddr)
 
static void handle_call_incoming (struct unistimsession *s)
 
static void handle_call_outgoing (struct unistimsession *s)
 
static void handle_dial_page (struct unistimsession *pte)
 
static void handle_key_fav (struct unistimsession *pte, char keycode)
 
static void handle_select_codec (struct unistimsession *)
 
static void handle_select_language (struct unistimsession *)
 
static void handle_select_option (struct unistimsession *pte)
 
static void ignore_call (struct unistimsession *pte)
 
static void in_band_indication (struct ast_channel *ast, const struct ast_tone_zone *tz, const char *indication)
 
static void init_phone_step2 (struct unistimsession *pte)
 
static int is_key_favorite (struct unistim_device *d, int fav)
 
static int is_key_line (struct unistim_device *d, int fav)
 
static void key_call (struct unistimsession *pte, char keycode)
 
static void key_dial_page (struct unistimsession *pte, char keycode)
 
static void key_favorite (struct unistimsession *, char)
 
static void key_history (struct unistimsession *pte, char keycode)
 
static void key_main_page (struct unistimsession *pte, char keycode)
 
static void key_ringing (struct unistimsession *pte, char keycode)
 
static void key_select_codec (struct unistimsession *pte, char keycode)
 
static void key_select_extension (struct unistimsession *pte, char keycode)
 
static void key_select_language (struct unistimsession *pte, char keycode)
 
static void key_select_option (struct unistimsession *pte, char keycode)
 
static int lang_cmp_fn (void *obj, void *arg, int flags)
 
static int lang_hash_fn (const void *obj, const int flags)
 
static int load_module (void)
 
static void microphone_mute_toggle (struct unistimsession *pte)
 
static char open_history (struct unistimsession *pte, char way, FILE **f)
 
static int parse_bookmark (const char *text, struct unistim_device *d)
 
static void parsing (int size, unsigned char *buf, struct unistimsession *pte, struct sockaddr_in *addr_from)
 
static void process_request (int size, unsigned char *buf, struct unistimsession *pte)
 
static const char * ptestate_tostr (const int type)
 
static void rcv_mac_addr (struct unistimsession *pte, const unsigned char *buf)
 
static void rcv_resume_connection_with_server (struct unistimsession *pte)
 
static void refresh_all_favorite (struct unistimsession *pte)
 
static int register_extension (const struct unistimsession *pte)
 
static int reload (void)
 
static int reload_config (void)
 
static int restart_monitor (void)
 
static void send_blink_cursor (struct unistimsession *pte)
 
static void send_callerid_screen (struct unistimsession *, struct unistim_subchannel *)
 
static void send_charset_update (struct unistimsession *pte, int charset)
 
static void send_client (int size, const unsigned char *data, struct unistimsession *pte)
 
static void send_cursor_pos (struct unistimsession *pte, unsigned char pos)
 
static void send_date_time (struct unistimsession *pte)
 
static void send_date_time2 (struct unistimsession *pte)
 
static void send_date_time3 (struct unistimsession *pte)
 
static void send_dial_tone (struct unistimsession *pte)
 
static int send_dtmf_tone (struct unistimsession *pte, char digit)
 
static void send_end_call (struct unistimsession *pte)
 
static void send_expansion_icon (unsigned char pos, unsigned char status, struct unistimsession *pte)
 
static void send_expansion_next (struct unistimsession *pte)
 
static void send_expansion_short (unsigned char pos, unsigned char status, struct unistimsession *pte)
 
static void send_expansion_text (unsigned char pos, struct unistimsession *pte, const char *text)
 
static void send_favorite (unsigned char pos, unsigned char status, struct unistimsession *pte, const char *text)
 
static void send_favorite_selected (unsigned char status, struct unistimsession *pte)
 
static void send_favorite_short (unsigned char pos, unsigned char status, struct unistimsession *pte)
 
static void send_icon (unsigned char pos, unsigned char status, struct unistimsession *pte)
 
static void send_idle_clock (struct unistimsession *pte)
 
static void send_led_update (struct unistimsession *pte, unsigned char led)
 
static void send_month_labels (struct unistimsession *pte, int month)
 
static void send_mute (struct unistimsession *pte, unsigned char mute)
 
static void send_no_ring (struct unistimsession *pte)
 
static void send_ping (struct unistimsession *pte)
 
static void send_raw_client (int size, const unsigned char *data, struct sockaddr_in *addr_to, const struct sockaddr_in *addr_ourip)
 
static int send_retransmit (struct unistimsession *pte)
 
static void send_ring (struct unistimsession *pte, signed char volume, signed char style)
 
static void send_select_output (struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
 
static void send_start_rtp (struct unistim_subchannel *)
 
static void send_start_timer (struct unistimsession *pte)
 
static void send_stop_timer (struct unistimsession *pte)
 
static void send_text (unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
 
static void send_text_status (struct unistimsession *pte, const char *text)
 
static void send_texttitle (struct unistimsession *pte, const char *text)
 
static void send_tone (struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
 
static void set_ping_timer (struct unistimsession *pte)
 
static void show_entry_history (struct unistimsession *pte, FILE **f)
 
static void show_extension_page (struct unistimsession *pte)
 
static void show_history (struct unistimsession *pte, char way)
 
static void show_main_page (struct unistimsession *pte)
 
static void show_phone_number (struct unistimsession *pte)
 
static int soft_key_visible (struct unistim_device *d, unsigned char num)
 
static void start_rtp (struct unistim_subchannel *sub)
 
static void sub_hold (struct unistimsession *pte, struct unistim_subchannel *sub)
 
static void sub_start_silence (struct unistimsession *pte, struct unistim_subchannel *sub)
 
static void sub_stop_silence (struct unistimsession *pte, struct unistim_subchannel *sub)
 
static void sub_unhold (struct unistimsession *pte, struct unistim_subchannel *sub)
 
static const char * subtype_tostr (const int type)
 
static void swap_subs (struct unistim_subchannel *a, struct unistim_subchannel *b)
 
static void transfer_call_step1 (struct unistimsession *pte)
 
static void transfer_cancel_step2 (struct unistimsession *pte)
 
static struct unistim_subchannelunistim_alloc_sub (struct unistim_device *d, int x)
 
static int unistim_answer (struct ast_channel *ast)
 
static int unistim_call (struct ast_channel *ast, const char *dest, int timeout)
 
static char * unistim_do_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int unistim_do_senddigit (struct unistimsession *pte, char digit)
 
static int unistim_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
 
static int unistim_free_sub (struct unistim_subchannel *)
 
static enum ast_rtp_glue_result unistim_get_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance)
 
static int unistim_hangup (struct ast_channel *ast)
 
static int unistim_hangup_clean (struct ast_channel *ast, struct unistim_subchannel *sub)
 
static int unistim_indicate (struct ast_channel *ast, int ind, const void *data, size_t datalen)
 
static struct unistim_lineunistim_line_alloc (void)
 
static void unistim_line_copy (struct unistim_line *dst, struct unistim_line *src)
 
static struct unistim_lineunistim_line_destroy (struct unistim_line *l)
 
static struct ast_channelunistim_new (struct unistim_subchannel *sub, int state, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
 
static struct ast_frameunistim_read (struct ast_channel *ast)
 
static int unistim_register (struct unistimsession *s)
 
static char * unistim_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 — unistim_reload: Force reload of module from cli — Runs in the asterisk main thread, so don't do anything useful but setting a flag and waiting for do_monitor to do the job in our thread More...
 
static struct ast_channelunistim_request (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *dest, int *cause)
 
static struct ast_frameunistim_rtp_read (const struct ast_channel *ast, const struct unistim_subchannel *sub)
 
static int unistim_send_mwi_to_peer (struct unistim_line *peer, unsigned int tick)
 
static int unistim_senddigit_begin (struct ast_channel *ast, char digit)
 
static int unistim_senddigit_end (struct ast_channel *ast, char digit, unsigned int duration)
 
static int unistim_sendtext (struct ast_channel *ast, const char *text)
 
static void unistim_set_owner (struct unistim_subchannel *sub, struct ast_channel *chan)
 
static int unistim_set_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *codecs, int nat_active)
 
static char * unistim_show_devices (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * unistim_show_info (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * unistim_sp (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void * unistim_ss (void *data)
 
static int unistim_unalloc_sub (struct unistim_device *d, struct unistim_subchannel *sub)
 
static int unistim_write (struct ast_channel *ast, struct ast_frame *frame)
 
static int unistimsock_read (int *id, int fd, short events, void *ignore)
 
static int unload_module (void)
 
static void unquote (char *out, const char *src, int maxlen)
 
static int unregister_extension (const struct unistimsession *pte)
 
static const char * ustmtext (const char *str, struct unistimsession *pte)
 
static int write_entry_history (struct unistimsession *pte, FILE *f, char c, char *line1)
 
static int write_history (struct unistimsession *pte, char way, char ismissed)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "UNISTIM Protocol (USTM)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static enum autoprovision autoprovisioning = AUTOPROVISIONING_NO
 
static unsigned char * buff
 
static const char channel_type [] = "USTM"
 
static struct ast_jb_conf default_jbconf
 Global jitterbuffer configuration - by default, jb is disabled. More...
 
static ast_mutex_t devicelock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static struct unistim_devicedevices = NULL
 
static const float dtmf_col [] = { 1209, 1336, 1477, 1633 }
 
static const int dtmf_row [] = { 697, 770, 852, 941 }
 
struct ast_format_capglobal_cap
 
static struct ast_jb_conf global_jbconf
 
static struct io_contextio
 
static pthread_t monitor_thread = AST_PTHREADT_NULL
 
static ast_mutex_t monlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static unsigned char monthlabels []
 
static struct unistim_languages options_languages []
 
static struct unistim_menu_item options_menu []
 
static const unsigned char packet_rcv_discovery []
 
static const unsigned char packet_recv_expansion_pressed_key []
 
static const unsigned char packet_recv_firm_version []
 
static const unsigned char packet_recv_hangup []
 
static const unsigned char packet_recv_it_type []
 
static const unsigned char packet_recv_mac_addr []
 
static const unsigned char packet_recv_pick_up []
 
static const unsigned char packet_recv_pressed_key []
 
static const unsigned char packet_recv_r2 [] = { 0x00, 0x00, 0x00, 0x13, 0x96, 0x03, 0x03 }
 
static const unsigned char packet_recv_resume_connection_with_server []
 
static const unsigned char packet_send_arrow [] = { 0x17, 0x04, 0x04, 0x00 }
 
static const unsigned char packet_send_blink_cursor [] = { 0x17, 0x04, 0x10, 0x86 }
 
static const unsigned char packet_send_call []
 
static const unsigned char packet_send_charset_iso_2022_jp []
 
static const unsigned char packet_send_charset_iso_8859_1 []
 
static const unsigned char packet_send_charset_iso_8859_2 []
 
static const unsigned char packet_send_charset_iso_8859_4 []
 
static const unsigned char packet_send_charset_iso_8859_5 []
 
static const unsigned char packet_send_Contrast []
 
static const unsigned char packet_send_date_time []
 
static const unsigned char packet_send_date_time2 []
 
static const unsigned char packet_send_date_time3 []
 
static const unsigned char packet_send_discovery_ack []
 
static const unsigned char packet_send_end_call []
 
static const unsigned char packet_send_expansion_icon [] = { 0x09, 0x06, 0x59, 0x05, 0x47, 0x20 }
 
static const unsigned char packet_send_expansion_next [] = { 0x09, 0x03, 0x17 }
 
static const unsigned char packet_send_expansion_text []
 
static const unsigned char packet_send_favorite []
 
static const unsigned char packet_send_icon [] = { 0x17, 0x05, 0x14, 0x00, 0x25 }
 
static const unsigned char packet_send_jitter_buffer_conf []
 
static const unsigned char packet_send_led_update [] = { 0x19, 0x04, 0x00, 0x00 }
 
static unsigned char packet_send_monthlabels_download []
 
static const unsigned char packet_send_mute [] = { 0x16, 0x05, 0x04, 0x00, 0x00 }
 
static const unsigned char packet_send_no_ring []
 
static const unsigned char packet_send_open_audio_stream_rx []
 
static const unsigned char packet_send_open_audio_stream_rx3 []
 
static const unsigned char packet_send_open_audio_stream_tx []
 
static const unsigned char packet_send_open_audio_stream_tx3 []
 
static unsigned char packet_send_ping []
 
static const unsigned char packet_send_query_basic_manager_04 [] = { 0x1a, 0x04, 0x01, 0x04 }
 
static const unsigned char packet_send_query_basic_manager_10 [] = { 0x1a, 0x04, 0x01, 0x10 }
 
static const unsigned char packet_send_query_mac_address [] = { 0x1a, 0x04, 0x01, 0x08 }
 
static const unsigned char packet_send_ring []
 
static const unsigned char packet_send_rtp_packet_size []
 
static const unsigned char packet_send_S1 [] = { 0x1a, 0x07, 0x07, 0x00, 0x00, 0x00, 0x13 }
 
static const unsigned char packet_send_s4 []
 
static const unsigned char packet_send_S7 [] = { 0x17, 0x06, 0x0f, 0x30, 0x07, 0x07 }
 
static const unsigned char packet_send_s9 []
 
static const unsigned char packet_send_select_output []
 
static const unsigned char packet_send_set_pos_cursor []
 
static const unsigned char packet_send_start_timer []
 
static const unsigned char packet_send_status []
 
static const unsigned char packet_send_status2 []
 
static const unsigned char packet_send_stop_timer [] = { 0x17, 0x05, 0x0b, 0x02, 0x00 }
 
static const unsigned char packet_send_stream_based_tone_dual_freq []
 
static const unsigned char packet_send_stream_based_tone_off []
 
static const unsigned char packet_send_stream_based_tone_on []
 
static const unsigned char packet_send_stream_based_tone_single_freq []
 
static const unsigned char packet_send_text []
 
static const unsigned char packet_send_title []
 
static struct sockaddr_in public_ip = { 0, }
 
struct {
   unsigned int   cos
 
   unsigned int   cos_audio
 
   unsigned int   tos
 
   unsigned int   tos_audio
 
qos = { 0, 0, 0, 0 }
 
static struct ast_sched_contextsched
 
static ast_mutex_t sessionlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static struct unistimsessionsessions = NULL
 
static const char tdesc [] = "UNISTIM Channel Driver"
 
static struct ast_cli_entry unistim_cli []
 
static int unistim_keepalive
 
static int unistim_port
 
static ast_mutex_t unistim_reload_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static int unistim_reloading = 0
 
static struct ast_rtp_glue unistim_rtp_glue
 
static struct ast_channel_tech unistim_tech
 
static int unistimdebug = 0
 
static int unistimsock = -1
 
static char ustm_strcopy [1024]
 

Detailed Description

chan_unistim channel driver for Asterisk

Author
Cedric Hans cedri.nosp@m.c.ha.nosp@m.ns@ml.nosp@m.kj.n.nosp@m.et

Unistim (Unified Networks IP Stimulus) channel driver for Nortel i2002, i2004 and i2050

Definition in file chan_unistim.c.

Macro Definition Documentation

◆ AST_CONFIG_MAX_PATH

#define AST_CONFIG_MAX_PATH   255

Definition at line 113 of file chan_unistim.c.

Referenced by open_history(), and write_history().

◆ BUFFSEND

#define BUFFSEND   unsigned char buffsend[64] = { 0x00, 0x00, 0xaa, 0xbb, 0x02, 0x01 }

◆ DEBUG_TIMER

#define DEBUG_TIMER   dummy

Definition at line 241 of file chan_unistim.c.

Referenced by do_monitor(), and set_ping_timer().

◆ DEFAULT_CODEC

#define DEFAULT_CODEC   0x00

Not used

Definition at line 110 of file chan_unistim.c.

Referenced by key_select_extension(), and unistim_register().

◆ DEFAULT_INTERDIGIT_TIMER

#define DEFAULT_INTERDIGIT_TIMER   4000

Timeout value for entered number being dialed

Definition at line 107 of file chan_unistim.c.

Referenced by build_device().

◆ DEFAULTCALLERID

#define DEFAULTCALLERID   "Unknown"

Definition at line 84 of file chan_unistim.c.

Referenced by send_callerid_screen().

◆ DEFAULTCALLERNAME

#define DEFAULTCALLERNAME   " "

Definition at line 85 of file chan_unistim.c.

Referenced by send_callerid_screen().

◆ DEFAULTCONTEXT

#define DEFAULTCONTEXT   "default"

Definition at line 83 of file chan_unistim.c.

Referenced by build_device().

◆ DEFAULTHEIGHT

#define DEFAULTHEIGHT   3

Definition at line 86 of file chan_unistim.c.

Referenced by build_device().

◆ DEVICE_NAME_LEN

#define DEVICE_NAME_LEN   16

Definition at line 112 of file chan_unistim.c.

◆ EXPNUM

#define EXPNUM   24

Definition at line 217 of file chan_unistim.c.

Referenced by refresh_all_favorite().

◆ FAV_BLINK_FAST

#define FAV_BLINK_FAST   0x20

Definition at line 211 of file chan_unistim.c.

Referenced by unistim_call().

◆ FAV_BLINK_SLOW

#define FAV_BLINK_SLOW   0x40

Definition at line 212 of file chan_unistim.c.

Referenced by show_main_page(), and sub_hold().

◆ FAV_ICON_BOX

#define FAV_ICON_BOX   0x3F

Definition at line 209 of file chan_unistim.c.

◆ FAV_ICON_CALL_CENTER

#define FAV_ICON_CALL_CENTER   0x34

Definition at line 198 of file chan_unistim.c.

Referenced by show_main_page().

◆ FAV_ICON_CITY

#define FAV_ICON_CITY   0x31

Definition at line 195 of file chan_unistim.c.

◆ FAV_ICON_COMPUTER

#define FAV_ICON_COMPUTER   0x38

Definition at line 202 of file chan_unistim.c.

◆ FAV_ICON_FAX

#define FAV_ICON_FAX   0x35

Definition at line 199 of file chan_unistim.c.

◆ FAV_ICON_FORWARD

#define FAV_ICON_FORWARD   0x39

Definition at line 203 of file chan_unistim.c.

◆ FAV_ICON_HEADPHONES

#define FAV_ICON_HEADPHONES   0x2E

Definition at line 192 of file chan_unistim.c.

Referenced by send_select_output().

◆ FAV_ICON_HEADPHONES_ONHOLD

#define FAV_ICON_HEADPHONES_ONHOLD   0x2F

Definition at line 193 of file chan_unistim.c.

Referenced by send_select_output().

◆ FAV_ICON_HOME

#define FAV_ICON_HOME   0x30

Definition at line 194 of file chan_unistim.c.

◆ FAV_ICON_INBOX

#define FAV_ICON_INBOX   0x3C

Definition at line 206 of file chan_unistim.c.

◆ FAV_ICON_LOCKED

#define FAV_ICON_LOCKED   0x3A

Definition at line 204 of file chan_unistim.c.

◆ FAV_ICON_MAILBOX

#define FAV_ICON_MAILBOX   0x36

Definition at line 200 of file chan_unistim.c.

◆ FAV_ICON_MEETING

#define FAV_ICON_MEETING   0x3E

Definition at line 208 of file chan_unistim.c.

◆ FAV_ICON_NONE

#define FAV_ICON_NONE   0x00

◆ FAV_ICON_OFFHOOK_BLACK

#define FAV_ICON_OFFHOOK_BLACK   0x24

◆ FAV_ICON_OFFHOOK_WHITE

#define FAV_ICON_OFFHOOK_WHITE   0x25

Definition at line 183 of file chan_unistim.c.

◆ FAV_ICON_ONHOLD_BLACK

#define FAV_ICON_ONHOLD_BLACK   0x26

Definition at line 184 of file chan_unistim.c.

Referenced by send_select_output(), and sub_hold().

◆ FAV_ICON_ONHOLD_WHITE

#define FAV_ICON_ONHOLD_WHITE   0x27

Definition at line 185 of file chan_unistim.c.

◆ FAV_ICON_ONHOOK_BLACK

#define FAV_ICON_ONHOOK_BLACK   0x20

Definition at line 178 of file chan_unistim.c.

◆ FAV_ICON_ONHOOK_WHITE

#define FAV_ICON_ONHOOK_WHITE   0x21

Definition at line 179 of file chan_unistim.c.

◆ FAV_ICON_OUTBOX

#define FAV_ICON_OUTBOX   0x3D

Definition at line 207 of file chan_unistim.c.

◆ FAV_ICON_PAGER

#define FAV_ICON_PAGER   0x33

Definition at line 197 of file chan_unistim.c.

◆ FAV_ICON_PHONE_BLACK

#define FAV_ICON_PHONE_BLACK   0x2A

Definition at line 188 of file chan_unistim.c.

Referenced by handle_dial_page().

◆ FAV_ICON_PHONE_WHITE

#define FAV_ICON_PHONE_WHITE   0x2B

Definition at line 189 of file chan_unistim.c.

◆ FAV_ICON_REFLECT

#define FAV_ICON_REFLECT   0x37

Definition at line 201 of file chan_unistim.c.

Referenced by show_main_page().

◆ FAV_ICON_SHARP

#define FAV_ICON_SHARP   0x32

Definition at line 196 of file chan_unistim.c.

Referenced by parse_bookmark().

◆ FAV_ICON_SPEAKER_OFFHOOK_BLACK

#define FAV_ICON_SPEAKER_OFFHOOK_BLACK   0x28

Definition at line 186 of file chan_unistim.c.

Referenced by send_select_output().

◆ FAV_ICON_SPEAKER_OFFHOOK_WHITE

#define FAV_ICON_SPEAKER_OFFHOOK_WHITE   0x29

Definition at line 187 of file chan_unistim.c.

◆ FAV_ICON_SPEAKER_ONHOLD_BLACK

#define FAV_ICON_SPEAKER_ONHOLD_BLACK   0x2C

Definition at line 190 of file chan_unistim.c.

Referenced by send_select_output().

◆ FAV_ICON_SPEAKER_ONHOLD_WHITE

#define FAV_ICON_SPEAKER_ONHOLD_WHITE   0x2D

Definition at line 191 of file chan_unistim.c.

◆ FAV_ICON_SPEAKER_ONHOOK_BLACK

#define FAV_ICON_SPEAKER_ONHOOK_BLACK   0x22

Definition at line 180 of file chan_unistim.c.

Referenced by send_select_output(), and unistim_call().

◆ FAV_ICON_SPEAKER_ONHOOK_WHITE

#define FAV_ICON_SPEAKER_ONHOOK_WHITE   0x23

Definition at line 181 of file chan_unistim.c.

Referenced by refresh_all_favorite().

◆ FAV_ICON_TRASH

#define FAV_ICON_TRASH   0x3B

Definition at line 205 of file chan_unistim.c.

◆ FAV_LINE_ICON

#define FAV_LINE_ICON   FAV_ICON_ONHOOK_BLACK

◆ FAV_MAX_LENGTH

#define FAV_MAX_LENGTH   0x0A

Definition at line 214 of file chan_unistim.c.

Referenced by send_favorite().

◆ FAVNUM

#define FAVNUM   6

◆ IDLE_WAIT

#define IDLE_WAIT   1000

Nb of milliseconds waited when no events are scheduled

Definition at line 101 of file chan_unistim.c.

Referenced by do_monitor().

◆ LED_BAR_OFF

#define LED_BAR_OFF   0x00 /* bar off */

◆ LED_BAR_ON

#define LED_BAR_ON   0x01 /* bar on */

Definition at line 152 of file chan_unistim.c.

Referenced by unistim_send_mwi_to_peer().

◆ LED_BAR_P2

#define LED_BAR_P2   0x02 /* bar 1s on/1s */

Definition at line 153 of file chan_unistim.c.

◆ LED_BAR_P3

#define LED_BAR_P3   0x03 /* bar 2.5s on/0.5s off */

Definition at line 154 of file chan_unistim.c.

◆ LED_BAR_P4

#define LED_BAR_P4   0x04 /* bar 0.6s on/0.3s off */

Definition at line 155 of file chan_unistim.c.

◆ LED_BAR_P5

#define LED_BAR_P5   0x05 /* bar 0.5s on/0.5s off */

Definition at line 156 of file chan_unistim.c.

◆ LED_BAR_P6

#define LED_BAR_P6   0x06 /* bar 2s on/0.5s off */

Definition at line 157 of file chan_unistim.c.

◆ LED_BAR_P7

#define LED_BAR_P7   0x07 /* bar off */

Definition at line 158 of file chan_unistim.c.

◆ LED_HEADPHONE_OFF

#define LED_HEADPHONE_OFF   0x010

Definition at line 161 of file chan_unistim.c.

Referenced by key_dial_page(), send_select_output(), and show_main_page().

◆ LED_HEADPHONE_ON

#define LED_HEADPHONE_ON   0x011

Definition at line 162 of file chan_unistim.c.

Referenced by send_select_output().

◆ LED_MUTE_BLINK

#define LED_MUTE_BLINK   0x1A

Definition at line 165 of file chan_unistim.c.

◆ LED_MUTE_OFF

#define LED_MUTE_OFF   0x018

Definition at line 163 of file chan_unistim.c.

Referenced by microphone_mute_toggle().

◆ LED_MUTE_ON

#define LED_MUTE_ON   0x019

Definition at line 164 of file chan_unistim.c.

Referenced by microphone_mute_toggle().

◆ LED_SPEAKER_OFF

#define LED_SPEAKER_OFF   0x08

Definition at line 159 of file chan_unistim.c.

Referenced by key_dial_page(), send_select_output(), and show_main_page().

◆ LED_SPEAKER_ON

#define LED_SPEAKER_ON   0x09

Definition at line 160 of file chan_unistim.c.

Referenced by send_select_output().

◆ MAX_BUF_NUMBER

#define MAX_BUF_NUMBER   150

Number of slots for the transmit queue

Definition at line 93 of file chan_unistim.c.

Referenced by create_client(), and send_client().

◆ MAX_BUF_SIZE

#define MAX_BUF_SIZE   64

Size of the transmit buffer

Definition at line 91 of file chan_unistim.c.

◆ MAX_ENTRY_LOG

#define MAX_ENTRY_LOG   30

Definition at line 114 of file chan_unistim.c.

Referenced by open_history(), and write_history().

◆ MAX_SCREEN_NUMBER

#define MAX_SCREEN_NUMBER   15

Number of digits displayed on screen

Definition at line 95 of file chan_unistim.c.

Referenced by show_phone_number().

◆ MONTH_LABEL_SIZE

#define MONTH_LABEL_SIZE   3

Length of month label size

Definition at line 97 of file chan_unistim.c.

Referenced by send_month_labels().

◆ MUTE_OFF

#define MUTE_OFF   0x00

◆ MUTE_ON

#define MUTE_ON   0xFF

Definition at line 148 of file chan_unistim.c.

Referenced by microphone_mute_toggle(), send_select_output(), and sub_hold().

◆ MUTE_ON_DISCRET

#define MUTE_ON_DISCRET   0xCE

Definition at line 149 of file chan_unistim.c.

Referenced by send_select_output(), and show_main_page().

◆ NB_MAX_RETRANSMIT

#define NB_MAX_RETRANSMIT   8

Try x times before removing the phone

Definition at line 99 of file chan_unistim.c.

Referenced by reload_config(), and send_retransmit().

◆ OUTPUT_HANDSET

#define OUTPUT_HANDSET   0xC0

◆ OUTPUT_HEADPHONE

#define OUTPUT_HEADPHONE   0xC1

◆ OUTPUT_SPEAKER

#define OUTPUT_SPEAKER   0xC2

◆ RETRANSMIT_TIMER

#define RETRANSMIT_TIMER   2000

Wait x milliseconds before resending a packet

Definition at line 103 of file chan_unistim.c.

Referenced by create_client(), reload_config(), send_client(), and send_retransmit().

◆ SELECTCODEC_MAX_LENGTH

#define SELECTCODEC_MAX_LENGTH   2

Definition at line 3730 of file chan_unistim.c.

Referenced by key_select_codec().

◆ SELECTCODEC_MSG

#define SELECTCODEC_MSG   "Codec number : .."

Definition at line 3731 of file chan_unistim.c.

Referenced by handle_select_codec(), and key_select_codec().

◆ SELECTCODEC_START_ENTRY_POS

#define SELECTCODEC_START_ENTRY_POS   15

Definition at line 3729 of file chan_unistim.c.

Referenced by handle_select_codec(), and key_select_codec().

◆ SELECTEXTENSION_MAX_LENGTH

#define SELECTEXTENSION_MAX_LENGTH   10

Definition at line 3874 of file chan_unistim.c.

Referenced by key_select_extension().

◆ SELECTEXTENSION_MSG

#define SELECTEXTENSION_MSG   ".........."

Definition at line 3875 of file chan_unistim.c.

Referenced by key_select_extension(), and show_extension_page().

◆ SELECTEXTENSION_START_ENTRY_POS

#define SELECTEXTENSION_START_ENTRY_POS   0

Definition at line 3873 of file chan_unistim.c.

Referenced by key_select_extension(), and show_extension_page().

◆ SIZE_HEADER

#define SIZE_HEADER   6

◆ SIZE_MAC_ADDR

#define SIZE_MAC_ADDR   17

Definition at line 168 of file chan_unistim.c.

◆ SIZE_PAGE

#define SIZE_PAGE   4096

Definition at line 111 of file chan_unistim.c.

Referenced by load_module(), and unistimsock_read().

◆ STATUS_LENGTH_MAX

#define STATUS_LENGTH_MAX   28

Definition at line 175 of file chan_unistim.c.

Referenced by send_text_status(), and show_entry_history().

◆ SUB_REAL

#define SUB_REAL   0

◆ SUB_RING

#define SUB_RING   1

◆ SUB_THREEWAY

#define SUB_THREEWAY   2

◆ TEXT_INVERSE

#define TEXT_INVERSE   0x25

Definition at line 174 of file chan_unistim.c.

Referenced by handle_select_codec(), and key_select_codec().

◆ TEXT_LENGTH_MAX

#define TEXT_LENGTH_MAX   24

◆ TEXT_LINE0

#define TEXT_LINE0   0x00

◆ TEXT_LINE1

#define TEXT_LINE1   0x20

◆ TEXT_LINE2

#define TEXT_LINE2   0x40

◆ TEXT_NORMAL

#define TEXT_NORMAL   0x05

◆ TIMER_MWI

#define TIMER_MWI   5000

How often the mailbox is checked for new messages

Definition at line 105 of file chan_unistim.c.

Referenced by unistim_send_mwi_to_peer().

◆ USTM_LANG_DIR

#define USTM_LANG_DIR   "unistimLang"

Definition at line 88 of file chan_unistim.c.

Referenced by ustmtext().

◆ USTM_LOG_DIR

#define USTM_LOG_DIR   "unistimHistory"

Definition at line 87 of file chan_unistim.c.

Referenced by open_history(), and write_history().

◆ VOLUME_INSANELY_LOUD

#define VOLUME_INSANELY_LOUD   0x07

Definition at line 145 of file chan_unistim.c.

◆ VOLUME_LOW

#define VOLUME_LOW   0x01

Definition at line 142 of file chan_unistim.c.

Referenced by build_device(), and send_select_output().

◆ VOLUME_LOW_SPEAKER

#define VOLUME_LOW_SPEAKER   0x03

Definition at line 143 of file chan_unistim.c.

Referenced by send_select_output().

◆ VOLUME_NORMAL

#define VOLUME_NORMAL   0x02

Definition at line 144 of file chan_unistim.c.

Enumeration Type Documentation

◆ autoprov_extn

Enumerator
EXTENSION_NONE 

Do not create an extension into the default dialplan

EXTENSION_ASK 

Prompt user for an extension number and register it

EXTENSION_LINE 

Register an extension with the line=> value

EXTENSION_TN 

Used with AUTOPROVISIONING_TN

Definition at line 128 of file chan_unistim.c.

128  {
129  /*! Do not create an extension into the default dialplan */
130  EXTENSION_NONE = 0,
131  /*! Prompt user for an extension number and register it */
133  /*! Register an extension with the line=> value */
135  /*! Used with AUTOPROVISIONING_TN */
137 };

◆ autoprovision

Enumerator
AUTOPROVISIONING_NO 
AUTOPROVISIONING_YES 
AUTOPROVISIONING_TN 

Definition at line 122 of file chan_unistim.c.

◆ charset

enum charset
Enumerator
LANG_DEFAULT 
ISO_8859_1 
ISO_8859_2 
ISO_8859_4 
ISO_8859_5 
ISO_2022_JP 

Definition at line 336 of file chan_unistim.c.

◆ handset_state

Enumerator
STATE_ONHOOK 
STATE_OFFHOOK 

Definition at line 290 of file chan_unistim.c.

290  {
291  STATE_ONHOOK,
293 };

◆ phone_key

enum phone_key
Enumerator
KEY_0 
KEY_1 
KEY_2 
KEY_3 
KEY_4 
KEY_5 
KEY_6 
KEY_7 
KEY_8 
KEY_9 
KEY_STAR 
KEY_SHARP 
KEY_UP 
KEY_DOWN 
KEY_RIGHT 
KEY_LEFT 
KEY_QUIT 
KEY_COPY 
KEY_FUNC1 
KEY_FUNC2 
KEY_FUNC3 
KEY_FUNC4 
KEY_ONHOLD 
KEY_HANGUP 
KEY_MUTE 
KEY_HEADPHN 
KEY_LOUDSPK 
KEY_FAV0 
KEY_FAV1 
KEY_FAV2 
KEY_FAV3 
KEY_FAV4 
KEY_FAV5 
KEY_COMPUTR 
KEY_CONF 
KEY_SNDHIST 
KEY_RCVHIST 
KEY_INDEX 

Definition at line 295 of file chan_unistim.c.

295  {
296  KEY_0 = 0x40,
297  KEY_1 = 0x41,
298  KEY_2 = 0x42,
299  KEY_3 = 0x43,
300  KEY_4 = 0x44,
301  KEY_5 = 0x45,
302  KEY_6 = 0x46,
303  KEY_7 = 0x47,
304  KEY_8 = 0x48,
305  KEY_9 = 0x49,
306  KEY_STAR = 0x4a,
307  KEY_SHARP = 0x4b,
308  KEY_UP = 0x4c,
309  KEY_DOWN = 0x4d,
310  KEY_RIGHT = 0x4e,
311  KEY_LEFT = 0x4f,
312  KEY_QUIT = 0x50,
313  KEY_COPY = 0x51,
314  KEY_FUNC1 = 0x54,
315  KEY_FUNC2 = 0x55,
316  KEY_FUNC3 = 0x56,
317  KEY_FUNC4 = 0x57,
318  KEY_ONHOLD = 0x5b,
319  KEY_HANGUP = 0x5c,
320  KEY_MUTE = 0x5d,
321  KEY_HEADPHN = 0x5e,
322  KEY_LOUDSPK = 0x5f,
323  KEY_FAV0 = 0x60,
324  KEY_FAV1 = 0x61,
325  KEY_FAV2 = 0x62,
326  KEY_FAV3 = 0x63,
327  KEY_FAV4 = 0x64,
328  KEY_FAV5 = 0x65,
329  KEY_COMPUTR = 0x7b,
330  KEY_CONF = 0x7c,
331  KEY_SNDHIST = 0x7d,
332  KEY_RCVHIST = 0x7e,
333  KEY_INDEX = 0x7f
334 };

◆ phone_state

Enumerator
STATE_INIT 
STATE_AUTHDENY 
STATE_MAINPAGE 
STATE_EXTENSION 
STATE_DIALPAGE 
STATE_RINGING 
STATE_CALL 
STATE_SELECTOPTION 
STATE_SELECTCODEC 
STATE_SELECTLANGUAGE 
STATE_CLEANING 
STATE_HISTORY 

Definition at line 275 of file chan_unistim.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 7208 of file chan_unistim.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 7208 of file chan_unistim.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 7208 of file chan_unistim.c.

◆ attempt_transfer()

static int attempt_transfer ( struct unistim_subchannel p1,
struct unistim_subchannel p2 
)
static

Definition at line 2440 of file chan_unistim.c.

References ast_bridge_transfer_attended(), AST_BRIDGE_TRANSFER_FAIL, AST_BRIDGE_TRANSFER_INVALID, AST_BRIDGE_TRANSFER_NOT_PERMITTED, AST_BRIDGE_TRANSFER_SUCCESS, ast_channel_ref, ast_channel_unref, ast_log, AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), LOG_WARNING, NULL, unistim_subchannel::owner, and RAII_VAR.

Referenced by close_call().

2441 {
2442  RAII_VAR(struct ast_channel *, chana, NULL, ast_channel_unref);
2443  RAII_VAR(struct ast_channel *, chanb, NULL, ast_channel_unref);
2444 
2445  if (!p1->owner || !p2->owner) {
2446  ast_log(LOG_WARNING, "Transfer attempted without dual ownership?\n");
2447  return -1;
2448  }
2449  chana = ast_channel_ref(p1->owner);
2450  chanb = ast_channel_ref(p2->owner);
2451 
2452  switch (ast_bridge_transfer_attended(chana, chanb)) {
2454  ast_log(LOG_WARNING, "Transfer failed. Invalid bridge setup\n");
2455  break;
2457  ast_log(LOG_WARNING, "Transfer not permitted\n");
2458  break;
2460  ast_log(LOG_WARNING, "Transfer encountered internal error\n");
2461  break;
2463  return 0;
2464  }
2465 
2466  /* Control only reaches this point if transfer has failed */
2469  return -1;
2470 }
struct ast_channel * owner
Definition: chan_unistim.c:356
Main Channel structure associated with a channel.
enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee, struct ast_channel *to_transfer_target)
Attended transfer.
Definition: bridge.c:4729
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2463
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2970

◆ build_device()

static struct unistim_device* build_device ( const char *  cat,
const struct ast_variable v 
)
static

Definition at line 6501 of file chan_unistim.c.

References ast_append_ha(), ast_calloc, ast_channel_string2amaflag(), ast_copy_string(), ast_format_cap_append_from_cap(), ast_free, ast_get_group(), ast_get_indication_zone(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_localtime(), ast_log, AST_MAX_EXTENSION, AST_MEDIA_TYPE_UNKNOWN, ast_mutex_init, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, ast_tone_zone_unref(), ast_true(), ast_tvnow(), ast_verb, autoprovisioning, AUTOPROVISIONING_TN, unistim_device::callhistory, unistim_line::cap, unistim_device::context, unistim_device::contrast, unistim_device::country, unistim_device::cwstyle, unistim_device::cwvolume, d, dateformat, unistim_device::datetimeformat, DEFAULT_INTERDIGIT_TIMER, DEFAULTCONTEXT, DEFAULTHEIGHT, delete_device(), devicelock, devices, unistim_device::dtmfduration, unistim_device::extension, EXTENSION_ASK, EXTENSION_LINE, EXTENSION_NONE, unistim_device::extension_number, EXTENSION_TN, FAV_ICON_NONE, FAV_LINE_ICON, find_line_by_number(), unistim_line::fullname, unistim_device::ha, unistim_device::hasexp, unistim_device::height, unistim_device::id, unistim_device::interdigit_timer, unistim_device::language, len(), ast_variable::lineno, unistim_device::lines, unistim_line::list, unistim_line::lock, unistim_device::lock, LOG_ERROR, LOG_WARNING, unistim_line::mailbox, unistim_device::maintext0, unistim_device::maintext1, unistim_device::maintext2, unistim_device::microphone, MUTE_OFF, ast_variable::name, unistim_line::name, unistim_device::name, unistim_device::nat, ast_variable::next, unistim_device::next, NULL, unistim_device::output, OUTPUT_HANDSET, unistim_line::parent, parse_bookmark(), unistim_device::previous_output, unistim_device::ringstyle, unistim_device::ringvolume, unistim_device::rtp_method, unistim_device::rtp_port, unistim_device::selected, unistim_device::sharp_dial, unistim_device::sline, unistim_device::softkeydevice, unistim_device::softkeyicon, unistim_device::softkeylabel, unistim_device::softkeynumber, unistim_device::sp, unistim_device::ssub, unistim_device::status_method, unistim_device::titledefault, ast_tm::tm_zone, unistim_device::to_delete, unistim_device::tz, unistim_line_alloc(), unistim_line_destroy(), unistimdebug, unistimsock, unquote(), ast_variable::value, unistim_device::volume, and VOLUME_LOW.

Referenced by reload_config().

6502 {
6503  struct unistim_device *d;
6504  struct unistim_line *l = NULL, *lt = NULL;
6505  int create = 1;
6506  int nbsoftkey, dateformat, timeformat, callhistory, sharpdial, linecnt;
6507  char linelabel[AST_MAX_EXTENSION];
6508  signed char ringvolume, ringstyle, cwvolume, cwstyle;
6509 
6510  /* First, we need to know if we already have this name in our list */
6511  /* Get a lock for the device chained list */
6513  d = devices;
6514  while (d) {
6515  if (!strcmp(d->name, cat)) {
6516  /* Yep, we alreay have this one */
6517  if (unistimsock < 0) {
6518  /* It's a dupe */
6519  ast_log(LOG_WARNING, "Duplicate entry found (%s), ignoring.\n", cat);
6521  return NULL;
6522  }
6523  /* we're reloading right now */
6524  create = 0;
6525  break;
6526  }
6527  d = d->next;
6528  }
6530  if (!(lt = ast_calloc(1, sizeof(*lt)))) {
6531  return NULL;
6532  }
6533  if (create) {
6534  if (!(d = ast_calloc(1, sizeof(*d)))) {
6535  return NULL;
6536  }
6537  ast_mutex_init(&d->lock);
6538  ast_copy_string(d->name, cat, sizeof(d->name));
6539 
6540  ast_copy_string(d->context, DEFAULTCONTEXT, sizeof(d->context));
6541  d->contrast = -1;
6542  d->output = OUTPUT_HANDSET;
6544  d->volume = VOLUME_LOW;
6545  d->microphone = MUTE_OFF;
6546  d->height = DEFAULTHEIGHT;
6547  d->selected = -1;
6549  } else {
6550  /* Delete existing line information */
6551  AST_LIST_LOCK(&d->lines);
6555  }
6557  AST_LIST_UNLOCK(&d->lines);
6558 
6559  /* reset bookmarks */
6560  memset(d->softkeylabel, 0, sizeof(d->softkeylabel));
6561  memset(d->softkeynumber, 0, sizeof(d->softkeynumber));
6562  memset(d->softkeyicon, 0, sizeof(d->softkeyicon));
6563  memset(d->softkeydevice, 0, sizeof(d->softkeydevice));
6564  memset(d->ssub, 0, sizeof(d->ssub));
6565  memset(d->sline, 0, sizeof(d->sline));
6566  memset(d->sp, 0, sizeof(d->sp));
6567  }
6568  linelabel[0] = '\0';
6569  dateformat = 1;
6570  timeformat = 1;
6571  ringvolume = 2;
6572  cwvolume = 1;
6573  callhistory = 1;
6574  sharpdial = 0;
6575  ringstyle = 3;
6576  cwstyle = 2;
6577  nbsoftkey = 0;
6578  linecnt = 0;
6579  d->dtmfduration = 0;
6580  while (v) {
6581  if (!strcasecmp(v->name, "rtp_port")) {
6582  d->rtp_port = atoi(v->value);
6583  } else if (!strcasecmp(v->name, "rtp_method")) {
6584  d->rtp_method = atoi(v->value);
6585  } else if (!strcasecmp(v->name, "status_method")) {
6586  d->status_method = atoi(v->value);
6587  } else if (!strcasecmp(v->name, "device")) {
6588  ast_copy_string(d->id, v->value, sizeof(d->id));
6589  } else if (!strcasecmp(v->name, "tn")) {
6591  } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
6592  int acl_error = 0;
6593  d->ha = ast_append_ha(v->name, v->value, d->ha, &acl_error);
6594  if (acl_error) {
6595  ast_log(LOG_ERROR, "Invalid ACL '%s' specified for device '%s' on line %d. Deleting device\n",
6596  v->value, cat, v->lineno);
6597  delete_device(d);
6598  return NULL;
6599  }
6600  } else if (!strcasecmp(v->name, "context")) {
6601  ast_copy_string(d->context, v->value, sizeof(d->context));
6602  } else if (!strcasecmp(v->name, "maintext0")) {
6603  unquote(d->maintext0, v->value, sizeof(d->maintext0) - 1);
6604  } else if (!strcasecmp(v->name, "maintext1")) {
6605  unquote(d->maintext1, v->value, sizeof(d->maintext1) - 1);
6606  } else if (!strcasecmp(v->name, "maintext2")) {
6607  unquote(d->maintext2, v->value, sizeof(d->maintext2) - 1);
6608  } else if (!strcasecmp(v->name, "titledefault")) {
6609  unquote(d->titledefault, v->value, sizeof(d->titledefault) - 1);
6610  } else if (!strcasecmp(v->name, "dateformat")) {
6611  dateformat = atoi(v->value);
6612  } else if (!strcasecmp(v->name, "timeformat")) {
6613  timeformat = atoi(v->value);
6614  } else if (!strcasecmp(v->name, "contrast")) {
6615  d->contrast = atoi(v->value);
6616  if ((d->contrast < 0) || (d->contrast > 15)) {
6617  ast_log(LOG_WARNING, "contrast must be beetween 0 and 15\n");
6618  d->contrast = 8;
6619  }
6620  } else if (!strcasecmp(v->name, "nat")) {
6621  d->nat = ast_true(v->value);
6622  } else if (!strcasecmp(v->name, "hasexp")) {
6623  d->hasexp = ast_true(v->value);
6624  } else if (!strcasecmp(v->name, "ringvolume")) {
6625  ringvolume = atoi(v->value);
6626  } else if (!strcasecmp(v->name, "ringstyle")) {
6627  ringstyle = atoi(v->value);
6628  } else if (!strcasecmp(v->name, "cwvolume")) {
6629  cwvolume = atoi(v->value);
6630  } else if (!strcasecmp(v->name, "cwstyle")) {
6631  cwstyle = atoi(v->value);
6632  } else if (!strcasecmp(v->name, "callhistory")) {
6633  callhistory = atoi(v->value);
6634  } else if (!strcasecmp(v->name, "sharpdial")) {
6635  sharpdial = ast_true(v->value) ? 1 : 0;
6636  } else if (!strcasecmp(v->name, "interdigit_timer")) {
6637  d->interdigit_timer = atoi(v->value);
6638  } else if (!strcasecmp(v->name, "dtmf_duration")) {
6639  d->dtmfduration = atoi(v->value);
6640  if (d->dtmfduration > 150) {
6641  d->dtmfduration = 150;
6642  }
6643  } else if (!strcasecmp(v->name, "callerid")) {
6644  if (!strcasecmp(v->value, "asreceived")) {
6645  lt->cid_num[0] = '\0';
6646  } else {
6647  ast_copy_string(lt->cid_num, v->value, sizeof(lt->cid_num));
6648  }
6649  } else if (!strcasecmp(v->name, "language")) {
6650  ast_copy_string(d->language, v->value, sizeof(d->language));
6651  } else if (!strcasecmp(v->name, "country")) {
6652  ast_copy_string(d->country, v->value, sizeof(d->country));
6653  } else if (!strcasecmp(v->name, "accountcode")) {
6654  ast_copy_string(lt->accountcode, v->value, sizeof(lt->accountcode));
6655  } else if (!strcasecmp(v->name, "amaflags")) {
6656  int y;
6658  if (y < 0) {
6659  ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value,
6660  v->lineno);
6661  } else {
6662  lt->amaflags = y;
6663  }
6664  } else if (!strcasecmp(v->name, "musiconhold")) {
6665  ast_copy_string(lt->musicclass, v->value, sizeof(lt->musicclass));
6666  } else if (!strcasecmp(v->name, "callgroup")) {
6667  lt->callgroup = ast_get_group(v->value);
6668  } else if (!strcasecmp(v->name, "pickupgroup")) {
6669  lt->pickupgroup = ast_get_group(v->value);
6670  } else if (!strcasecmp(v->name, "mailbox")) {
6671  ast_copy_string(lt->mailbox, v->value, sizeof(lt->mailbox));
6672  } else if (!strcasecmp(v->name, "parkinglot")) {
6673  ast_copy_string(lt->parkinglot, v->value, sizeof(lt->parkinglot));
6674  } else if (!strcasecmp(v->name, "linelabel")) {
6675  unquote(linelabel, v->value, sizeof(linelabel) - 1);
6676  } else if (!strcasecmp(v->name, "extension")) {
6677  if (!strcasecmp(v->value, "none")) {
6679  } else if (!strcasecmp(v->value, "ask")) {
6680  d->extension = EXTENSION_ASK;
6681  } else if (!strcasecmp(v->value, "line")) {
6683  } else {
6684  ast_log(LOG_WARNING, "Unknown extension option.\n");
6685  }
6686  } else if (!strcasecmp(v->name, "bookmark")) {
6687  if (nbsoftkey > 5) {
6689  "More than 6 softkeys defined. Ignoring new entries.\n");
6690  } else {
6691  if (parse_bookmark(v->value, d)) {
6692  nbsoftkey++;
6693  }
6694  }
6695  } else if (!strcasecmp(v->name, "line")) {
6696  int len = strlen(linelabel);
6697  int create_line = 0;
6698 
6699  l = find_line_by_number(d, v->value);
6700  if (!l) { /* If line still not exists */
6701  if (!(l = unistim_line_alloc())) {
6702  ast_free(d);
6703  ast_free(lt);
6704  return NULL;
6705  }
6706  lt->cap = l->cap;
6707  memcpy(l, lt, sizeof(*l));
6708  ast_mutex_init(&l->lock);
6709  create_line = 1;
6710  }
6711  d->to_delete = 0;
6712 
6713  /* Set softkey info for new line*/
6714  d->sline[nbsoftkey] = l;
6715  d->softkeyicon[nbsoftkey] = FAV_LINE_ICON;
6716  if (!len) { /* label is undefined ? */
6717  ast_copy_string(d->softkeylabel[nbsoftkey], v->value, sizeof(d->softkeylabel[nbsoftkey]));
6718  } else {
6719  int softkeylinepos = 0;
6720  if ((len > 2) && (linelabel[1] == '@')) {
6721  softkeylinepos = linelabel[0];
6722  if ((softkeylinepos >= '0') && (softkeylinepos <= '5')) {
6723  softkeylinepos -= '0';
6724  d->softkeyicon[nbsoftkey] = FAV_ICON_NONE;
6725  } else {
6727  "Invalid position for linelabel : must be between 0 and 5\n");
6728  }
6729  ast_copy_string(d->softkeylabel[softkeylinepos], linelabel + 2,
6730  sizeof(d->softkeylabel[softkeylinepos]));
6731  d->softkeyicon[softkeylinepos] = FAV_LINE_ICON;
6732  } else {
6733  ast_copy_string(d->softkeylabel[nbsoftkey], linelabel,
6734  sizeof(d->softkeylabel[nbsoftkey]));
6735  }
6736  }
6737  nbsoftkey++;
6738 
6739  if (create_line) {
6740  ast_copy_string(l->name, v->value, sizeof(l->name));
6741  snprintf(l->fullname, sizeof(l->fullname), "USTM/%s@%s", l->name, d->name);
6742  if (!ast_strlen_zero(l->mailbox)) {
6743  if (unistimdebug) {
6744  ast_verb(3, "Setting mailbox '%s' on %s@%s\n", l->mailbox, d->name, l->name);
6745  }
6746  }
6748  l->parent = d;
6749  linecnt++;
6750  AST_LIST_LOCK(&d->lines);
6751  AST_LIST_INSERT_TAIL(&d->lines, l, list);
6752  AST_LIST_UNLOCK(&d->lines);
6753  }
6754  } else if (!strcasecmp(v->name, "height")) {
6755  /* Allow the user to lower the expected display lines on the phone
6756  * For example the Nortel i2001 and i2002 only have one ! */
6757  d->height = atoi(v->value);
6758  } else
6759  ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name,
6760  v->lineno);
6761  v = v->next;
6762  }
6763  ast_free(lt);
6764  if (linecnt == 0) {
6765  ast_log(LOG_ERROR, "An Unistim device must have at least one line!\n");
6766  ast_free(d);
6767  return NULL;
6768  }
6769  d->ringvolume = ringvolume;
6770  d->ringstyle = ringstyle;
6771  d->cwvolume = cwvolume;
6772  d->cwstyle = cwstyle;
6773  d->callhistory = callhistory;
6774  d->sharp_dial = sharpdial;
6776  if ((d->tz == NULL) && !ast_strlen_zero(d->country)) {
6777  ast_log(LOG_WARNING, "Country '%s' was not found in indications.conf\n",
6778  d->country);
6779  }
6780  d->datetimeformat = 48 + (dateformat * 4);
6781  d->datetimeformat += timeformat;
6784  d->extension = EXTENSION_TN;
6785  if (!ast_strlen_zero(d->id)) {
6787  "tn= and device= can't be used together. Ignoring device= entry\n");
6788  }
6789  d->id[0] = 'T'; /* magic : this is a tn entry */
6790  ast_copy_string((d->id) + 1, d->extension_number, sizeof(d->id) - 1);
6791  d->extension_number[0] = '\0';
6792  } else if (ast_strlen_zero(d->id)) {
6793  if (strcmp(d->name, "template")) {
6794  ast_log(LOG_ERROR, "You must specify the mac address with device=\n");
6795  if (d->tz) {
6796  d->tz = ast_tone_zone_unref(d->tz);
6797  }
6798  ast_free(d);
6799  return NULL;
6800  } else {
6801  strcpy(d->id, "000000000000");
6802  }
6803  }
6804  if (!d->rtp_port) {
6805  d->rtp_port = 10000;
6806  }
6807  if (d->contrast == -1) {
6808  d->contrast = 8;
6809  }
6810  if (ast_strlen_zero(d->maintext1)) {
6811  strcpy(d->maintext1, d->name);
6812  }
6813  if (ast_strlen_zero(d->titledefault)) {
6814  struct ast_tm tm = { 0, };
6815  struct timeval cur_time = ast_tvnow();
6816 
6817  if ((ast_localtime(&cur_time, &tm, 0)) == 0 || ast_strlen_zero(tm.tm_zone)) {
6818  ast_log(LOG_WARNING, "Error in ast_localtime()\n");
6819  ast_copy_string(d->titledefault, "UNISTIM for*", 12);
6820  } else {
6821  if (strlen(tm.tm_zone) < 4) {
6822  strcpy(d->titledefault, "TimeZone ");
6823  strcat(d->titledefault, tm.tm_zone);
6824  } else if (strlen(tm.tm_zone) < 9) {
6825  strcpy(d->titledefault, "TZ ");
6826  strcat(d->titledefault, tm.tm_zone);
6827  } else {
6828  ast_copy_string(d->titledefault, tm.tm_zone, 12);
6829  }
6830  }
6831  }
6832  /* Update the chained link if it's a new device */
6833  if (create) {
6835  d->next = devices;
6836  devices = d;
6838  ast_verb(3, "Added device '%s'\n", d->name);
6839  } else {
6840  ast_verb(3, "Device '%s' reloaded\n", d->name);
6841  }
6842  return d;
6843 }
char * tm_zone
Definition: localtime.h:46
struct ast_variable * next
struct unistim_device * sp[FAVNUM]
Definition: chan_unistim.c:411
struct unistim_line::@151 list
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
static struct unistim_line * unistim_line_alloc(void)
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:205
static struct unistim_line * unistim_line_destroy(struct unistim_line *l)
static int unistimsock
Definition: chan_unistim.c:247
struct unistim_device::@153 lines
static struct unistim_line * find_line_by_number(struct unistim_device *d, const char *val)
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static struct test_val d
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
static void unquote(char *out, const char *src, int maxlen)
signed char ringvolume
Definition: chan_unistim.c:422
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
char softkeynumber[FAVNUM][AST_MAX_EXTENSION]
Definition: chan_unistim.c:406
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
signed char ringstyle
Definition: chan_unistim.c:423
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define ast_verb(level,...)
Definition: logger.h:463
#define VOLUME_LOW
Definition: chan_unistim.c:142
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_ha * ha
Definition: chan_unistim.c:453
char name[80]
Definition: chan_unistim.c:374
enum ama_flags ast_channel_string2amaflag(const char *flag)
Convert a string to a detail record AMA flag.
Definition: channel.c:4405
char titledefault[13]
Definition: chan_unistim.c:417
#define MUTE_OFF
Definition: chan_unistim.c:147
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
signed char cwstyle
Definition: chan_unistim.c:425
#define ast_log
Definition: astobj2.c:42
ast_mutex_t lock
Definition: chan_unistim.c:373
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
signed char to_delete
Definition: chan_unistim.c:449
struct unistim_device * next
Definition: chan_unistim.c:455
#define AST_MAX_EXTENSION
Definition: channel.h:135
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
char mailbox[AST_MAX_EXTENSION]
Definition: chan_unistim.c:378
#define FAV_ICON_NONE
Definition: chan_unistim.c:177
signed char cwvolume
Definition: chan_unistim.c:424
char maintext0[25]
Definition: chan_unistim.c:414
ast_group_t ast_get_group(const char *s)
Definition: channel.c:7718
struct ast_tone_zone * tz
Definition: chan_unistim.c:421
#define FAV_LINE_ICON
Definition: chan_unistim.c:218
enum autoprov_extn extension
Definition: chan_unistim.c:447
#define LOG_ERROR
Definition: logger.h:285
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
#define DEFAULT_INTERDIGIT_TIMER
Definition: chan_unistim.c:107
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:433
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char softkeydevice[FAVNUM][16]
Definition: chan_unistim.c:408
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410
ast_mutex_t lock
Definition: chan_unistim.c:395
char softkeyicon[FAVNUM]
Definition: chan_unistim.c:407
signed char contrast
Definition: chan_unistim.c:419
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define DEFAULTHEIGHT
Definition: chan_unistim.c:86
static struct unistim_device * devices
static int parse_bookmark(const char *text, struct unistim_device *d)
struct ast_format_cap * global_cap
Definition: chan_unistim.c:120
char context[AST_MAX_EXTENSION]
Definition: chan_unistim.c:398
static char dateformat[256]
Definition: logger.c:79
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char fullname[101]
Definition: chan_unistim.c:375
static enum autoprovision autoprovisioning
Definition: chan_unistim.c:245
static void delete_device(struct unistim_device *d)
struct unistim_device * parent
Definition: chan_unistim.c:387
char maintext1[25]
Definition: chan_unistim.c:415
struct ast_ha * ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule to a list of HAs.
Definition: acl.c:713
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
#define ast_mutex_init(pmutex)
Definition: lock.h:184
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
struct ast_format_cap * cap
Definition: chan_unistim.c:384
char extension_number[11]
Definition: chan_unistim.c:448
#define DEFAULTCONTEXT
Definition: chan_unistim.c:83
#define ast_mutex_unlock(a)
Definition: lock.h:188
char maintext2[25]
Definition: chan_unistim.c:416

◆ change_callerid()

void change_callerid ( struct unistimsession pte,
int  type,
char *  callerid 
)
static

Definition at line 2472 of file chan_unistim.c.

References unistimsession::device, unistim_device::lst_cid, unistim_device::lst_cnm, and TEXT_LENGTH_MAX.

Referenced by close_call(), and send_callerid_screen().

2473 {
2474  char *data;
2475  int size;
2476 
2477  if (type) {
2478  data = pte->device->lst_cnm;
2479  } else {
2480  data = pte->device->lst_cid;
2481  }
2482 
2483  /* This is very nearly strncpy(), except that the remaining buffer
2484  * is padded with ' ', instead of '\0' */
2485  memset(data, ' ', TEXT_LENGTH_MAX);
2486  size = strlen(callerid);
2487  if (size > TEXT_LENGTH_MAX) {
2488  size = TEXT_LENGTH_MAX;
2489  }
2490  memcpy(data, callerid, size);
2491 }
static const char type[]
Definition: chan_ooh323.c:109
char lst_cnm[TEXT_LENGTH_MAX]
Definition: chan_unistim.c:437
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
struct unistim_device * device
Definition: chan_unistim.c:476
char lst_cid[TEXT_LENGTH_MAX]
Definition: chan_unistim.c:436

◆ change_favorite_icon()

static void change_favorite_icon ( struct unistimsession pte,
unsigned char  status 
)
static

Definition at line 1418 of file chan_unistim.c.

References d, unistimsession::device, devices, FAVNUM, get_active_softkey(), unistim_device::next, send_favorite(), send_favorite_short(), unistim_device::session, unistim_device::softkeyicon, unistim_device::softkeylabel, unistim_device::sp, unistimsession::state, STATE_CLEANING, and status.

Referenced by close_client(), handle_dial_page(), send_select_output(), show_main_page(), and unistim_call().

1419 {
1420  struct unistim_device *d = devices;
1421  int i;
1422  /* Update the current phone line softkey icon */
1423  if (pte->state != STATE_CLEANING) {
1424  int softkeylinepos = get_active_softkey(pte);
1425  if (softkeylinepos != -1) {
1426  send_favorite_short(softkeylinepos, status, pte);
1427  }
1428  }
1429  /* Notify other phones if we're in their bookmark */
1430  while (d) {
1431  for (i = 0; i < FAVNUM; i++) {
1432  if (d->sp[i] == pte->device) { /* It's us ? */
1433  if (d->softkeyicon[i] != status) { /* Avoid resending the same icon */
1434  d->softkeyicon[i] = status;
1435  if (d->session) {
1436  send_favorite(i, status + 1, d->session, d->softkeylabel[i]);
1437  }
1438  }
1439  }
1440  }
1441  d = d->next;
1442  }
1443 }
struct unistim_device * sp[FAVNUM]
Definition: chan_unistim.c:411
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
A device containing one or more lines.
Definition: chan_unistim.c:394
#define FAVNUM
Definition: chan_unistim.c:216
static struct test_val d
struct unistim_device * device
Definition: chan_unistim.c:476
struct unistim_device * next
Definition: chan_unistim.c:455
struct unistimsession * session
Definition: chan_unistim.c:454
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
static void send_favorite(unsigned char pos, unsigned char status, struct unistimsession *pte, const char *text)
char softkeyicon[FAVNUM]
Definition: chan_unistim.c:407
static int get_active_softkey(struct unistimsession *pte)
static struct unistim_device * devices
jack_status_t status
Definition: app_jack.c:146

◆ channel_to_session()

static struct unistimsession* channel_to_session ( struct ast_channel ast)
static

Definition at line 4794 of file chan_unistim.c.

References ast_channel_tech_pvt(), ast_log, ast_mutex_lock, ast_mutex_unlock, unistim_device::lock, LOG_WARNING, NULL, unistim_subchannel::parent, unistim_line::parent, unistim_device::session, and sub.

Referenced by unistim_answer(), unistim_call(), unistim_hangup(), unistim_indicate(), unistim_senddigit_begin(), unistim_senddigit_end(), and unistim_sendtext().

4795 {
4796  struct unistim_subchannel *sub;
4797  if (!ast) {
4798  ast_log(LOG_WARNING, "Unistim callback function called with a null channel\n");
4799  return NULL;
4800  }
4801  if (!ast_channel_tech_pvt(ast)) {
4802  ast_log(LOG_WARNING, "Unistim callback function called without a tech_pvt\n");
4803  return NULL;
4804  }
4805  sub = ast_channel_tech_pvt(ast);
4806 
4807  if (!sub->parent) {
4808  ast_log(LOG_WARNING, "Unistim callback function called without a line\n");
4809  return NULL;
4810  }
4811  if (!sub->parent->parent) {
4812  ast_log(LOG_WARNING, "Unistim callback function called without a device\n");
4813  return NULL;
4814  }
4815  ast_mutex_lock(&sub->parent->parent->lock);
4816  if (!sub->parent->parent->session) {
4817  ast_log(LOG_WARNING, "Unistim callback function called without a session\n");
4819  return NULL;
4820  }
4822  return sub->parent->parent->session;
4823 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define LOG_WARNING
Definition: logger.h:274
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
struct unistimsession * session
Definition: chan_unistim.c:454
ast_mutex_t lock
Definition: chan_unistim.c:395
struct unistim_line * parent
Definition: chan_unistim.c:357
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ check_send_queue()

static void check_send_queue ( struct unistimsession pte)
static

Definition at line 1101 of file chan_unistim.c.

References ast_verb, unistimsession::last_buf_available, unistimsession::last_seq_ack, unistimsession::seq_server, set_ping_timer(), and unistimdebug.

Referenced by parsing().

1102 {
1103  /* Check if our send queue contained only one element */
1104  if (pte->last_buf_available == 1) {
1105  if (unistimdebug) {
1106  ast_verb(0, "Our single packet was ACKed.\n");
1107  }
1108  pte->last_buf_available--;
1109  set_ping_timer(pte);
1110  return;
1111  }
1112  /* Check if this ACK catch up our latest packet */
1113  else if (pte->last_seq_ack + 1 == pte->seq_server + 1) {
1114  if (unistimdebug) {
1115  ast_verb(0, "Our send queue is completely ACKed.\n");
1116  }
1117  pte->last_buf_available = 0; /* Purge the send queue */
1118  set_ping_timer(pte);
1119  return;
1120  }
1121  if (unistimdebug) {
1122  ast_verb(0, "We still have packets in our send queue\n");
1123  }
1124  return;
1125 }
unsigned short seq_server
Definition: chan_unistim.c:464
static void set_ping_timer(struct unistimsession *pte)
#define ast_verb(level,...)
Definition: logger.h:463
unsigned short last_seq_ack
Definition: chan_unistim.c:465
static int unistimdebug
Definition: chan_unistim.c:243

◆ close_call()

static void close_call ( struct unistimsession pte)
static

Definition at line 2599 of file chan_unistim.c.

References unistim_subchannel::alreadygone, AST_CAUSE_NORMAL_CLEARING, ast_log, ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_verb, attempt_transfer(), change_callerid(), unistimsession::device, FAV_LINE_ICON, get_sub(), LOG_WARNING, unistim_device::missed_call, unistim_line::name, unistim_device::name, unistim_subchannel::owner, unistim_subchannel::parent, unistim_device::redial_number, send_favorite_short(), send_stop_timer(), show_main_page(), unistim_subchannel::softkey, sub, SUB_REAL, SUB_THREEWAY, and write_history().

Referenced by key_call(), process_request(), and unistim_hangup().

2600 {
2601  struct unistim_subchannel *sub, *sub_transf;
2602 
2603  sub = get_sub(pte->device, SUB_REAL);
2604  sub_transf = get_sub(pte->device, SUB_THREEWAY);
2605  send_stop_timer(pte);
2606  if (!sub) {
2607  ast_log(LOG_WARNING, "Close call without sub\n");
2608  return;
2609  }
2611  if (sub->owner) {
2612  sub->alreadygone = 1;
2613  if (sub_transf) {
2614  sub_transf->alreadygone = 1;
2615  if (attempt_transfer(sub, sub_transf) < 0) {
2616  ast_verb(0, "attempt_transfer failed.\n");
2617  }
2618  } else {
2619  ast_queue_hangup(sub->owner);
2620  }
2621  } else {
2622  if (sub_transf) {
2623  if (sub_transf->owner) {
2625  } else {
2626  ast_log(LOG_WARNING, "threeway sub without owner\n");
2627  }
2628  } else {
2629  ast_verb(0, "USTM(%s@%s-%d) channel already destroyed\n", sub->parent->name,
2630  pte->device->name, sub->softkey);
2631  }
2632  }
2633  change_callerid(pte, 0, pte->device->redial_number);
2634  change_callerid(pte, 1, "");
2635  write_history(pte, 'o', pte->device->missed_call);
2636  pte->device->missed_call = 0;
2637  show_main_page(pte);
2638  return;
2639 }
struct ast_channel * owner
Definition: chan_unistim.c:356
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
Definition: channel.c:1150
static int write_history(struct unistimsession *pte, char way, char ismissed)
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define LOG_WARNING
Definition: logger.h:274
#define SUB_THREEWAY
Definition: chan_unistim.c:118
static int attempt_transfer(struct unistim_subchannel *p1, struct unistim_subchannel *p2)
#define ast_verb(level,...)
Definition: logger.h:463
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1166
struct unistim_device * device
Definition: chan_unistim.c:476
char name[80]
Definition: chan_unistim.c:374
#define ast_log
Definition: astobj2.c:42
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
#define FAV_LINE_ICON
Definition: chan_unistim.c:218
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
static void send_stop_timer(struct unistimsession *pte)
static void show_main_page(struct unistimsession *pte)
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
#define SUB_REAL
Definition: chan_unistim.c:116
struct unistim_line * parent
Definition: chan_unistim.c:357
struct stasis_forward * sub
Definition: res_corosync.c:240
static void change_callerid(struct unistimsession *pte, int type, char *callerid)
char redial_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:400

◆ close_client()

static void close_client ( struct unistimsession s)
static

Definition at line 1470 of file chan_unistim.c.

References AST_CAUSE_NETWORK_OUT_OF_ORDER, ast_debug, ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log, ast_mutex_destroy, ast_mutex_lock, ast_mutex_unlock, ast_queue_hangup_with_cause(), ast_strlen_zero, ast_verb, change_favorite_icon(), unistimsession::device, unistim_device::extension_number, FAV_ICON_NONE, unistim_device::lock, unistimsession::lock, LOG_WARNING, unistim_line::name, unistim_device::name, unistimsession::next, NULL, unistim_subchannel::owner, unistim_subchannel::parent, unistim_device::session, sessionlock, sessions, unistimsession::state, STATE_CLEANING, sub, unistim_device::subs, unistim_subchannel::subtype, unistim_free_sub(), unistimdebug, and unregister_extension().

Referenced by parsing(), and send_retransmit().

1471 {
1472  struct unistim_subchannel *sub = NULL;
1473  struct unistimsession *cur, *prev = NULL;
1475  cur = sessions;
1476  /* Looking for the session in the linked chain */
1477  while (cur) {
1478  if (cur == s) {
1479  break;
1480  }
1481  prev = cur;
1482  cur = cur->next;
1483  }
1484  if (cur) { /* Session found ? */
1485  if (cur->device) { /* This session was registered ? */
1486  s->state = STATE_CLEANING;
1487  if (unistimdebug) {
1488  ast_verb(0, "close_client session %p device %p\n", s, s->device);
1489  }
1491  ast_mutex_lock(&s->device->lock);
1492  AST_LIST_LOCK(&s->device->subs);
1493  AST_LIST_TRAVERSE_SAFE_BEGIN(&s->device->subs, sub, list) {
1494  if (!sub) {
1495  continue;
1496  }
1497  if (sub->owner) { /* Call in progress ? */
1498  if (unistimdebug) {
1499  ast_verb(0, "Aborting call\n");
1500  }
1502  } else {
1503  if (unistimdebug) {
1504  ast_debug(1, "Released sub %u of channel %s@%s\n", sub->subtype, sub->parent->name, s->device->name);
1505  }
1507  unistim_free_sub(sub);
1508  }
1509  }
1511  AST_LIST_UNLOCK(&s->device->subs);
1512 
1515  }
1516  cur->device->session = NULL;
1518  } else {
1519  if (unistimdebug) {
1520  ast_verb(0, "Freeing an unregistered client\n");
1521  }
1522  }
1523  if (prev) {
1524  prev->next = cur->next;
1525  } else {
1526  sessions = cur->next;
1527  }
1528  ast_mutex_destroy(&s->lock);
1529  ast_free(s);
1530  } else {
1531  ast_log(LOG_WARNING, "Trying to delete non-existent session %p?\n", s);
1532  }
1534  return;
1535 }
struct unistim_device::@152 subs
struct ast_channel * owner
Definition: chan_unistim.c:356
static struct unistimsession * sessions
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define AST_CAUSE_NETWORK_OUT_OF_ORDER
Definition: causes.h:120
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static void change_favorite_icon(struct unistimsession *pte, unsigned char status)
static int unregister_extension(const struct unistimsession *pte)
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define ast_verb(level,...)
Definition: logger.h:463
static ast_mutex_t sessionlock
Definition: chan_unistim.c:271
ast_mutex_t lock
Definition: chan_unistim.c:459
static int unistimdebug
Definition: chan_unistim.c:243
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1166
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
struct unistimsession * next
Definition: chan_unistim.c:477
char name[80]
Definition: chan_unistim.c:374
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
struct unistimsession * session
Definition: chan_unistim.c:454
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
#define FAV_ICON_NONE
Definition: chan_unistim.c:177
static int unistim_free_sub(struct unistim_subchannel *)
ast_mutex_t lock
Definition: chan_unistim.c:395
#define ast_free(a)
Definition: astmm.h:182
struct unistim_line * parent
Definition: chan_unistim.c:357
struct stasis_forward * sub
Definition: res_corosync.c:240
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
#define ast_mutex_destroy(a)
Definition: lock.h:186
char extension_number[11]
Definition: chan_unistim.c:448
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ control2str()

static char* control2str ( int  ind)
static

Definition at line 5279 of file chan_unistim.c.

References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_TAKEOFFHOOK, and AST_CONTROL_WINK.

Referenced by unistim_indicate().

5280 {
5281  switch (ind) {
5282  case AST_CONTROL_HANGUP:
5283  return "Other end has hungup";
5284  case AST_CONTROL_RING:
5285  return "Local ring";
5286  case AST_CONTROL_RINGING:
5287  return "Remote end is ringing";
5288  case AST_CONTROL_ANSWER:
5289  return "Remote end has answered";
5290  case AST_CONTROL_BUSY:
5291  return "Remote end is busy";
5293  return "Make it go off hook";
5294  case AST_CONTROL_OFFHOOK:
5295  return "Line is off hook";
5297  return "Congestion (circuits busy)";
5298  case AST_CONTROL_FLASH:
5299  return "Flash hook";
5300  case AST_CONTROL_WINK:
5301  return "Wink";
5302  case AST_CONTROL_OPTION:
5303  return "Set a low-level option";
5304  case AST_CONTROL_RADIO_KEY:
5305  return "Key Radio";
5307  return "Un-Key Radio";
5309  return "Remote end changed";
5310  case AST_CONTROL_SRCCHANGE:
5311  return "RTP source updated";
5312  case AST_CONTROL_SRCUPDATE:
5313  return "Source of media changed";
5314  case -1:
5315  return "Stop tone";
5316  }
5317  return "UNKNOWN";
5318 }

◆ create_client()

static struct unistimsession* create_client ( const struct sockaddr_in *  addr_from)
static

Definition at line 1046 of file chan_unistim.c.

References ast_calloc, ast_free, ast_inet_ntoa(), ast_mutex_init, ast_mutex_lock, ast_mutex_unlock, ast_verb, wsabuf::buf, unistimsession::buf, get_tick_count(), get_to_address(), unistimsession::lock, MAX_BUF_NUMBER, unistimsession::next, NULL, RETRANSMIT_TIMER, sessionlock, sessions, unistimsession::sin, unistimsession::sout, unistimsession::state, STATE_INIT, unistimsession::tick_next_ping, unistimsession::timeout, tmp(), unistim_keepalive, unistimdebug, unistimsock, and unistimsession::wsabufsend.

Referenced by parsing().

1047 {
1048  int tmp;
1049  struct unistimsession *s;
1050 
1051  if (!(s = ast_calloc(1, sizeof(*s))))
1052  return NULL;
1053 
1054  memcpy(&s->sin, addr_from, sizeof(struct sockaddr_in));
1055  if (get_to_address(unistimsock, &s->sout) < 0) {
1056  ast_free(s);
1057  return NULL;
1058  }
1059  s->sout.sin_family = AF_INET;
1060  if (unistimdebug) {
1061  ast_verb(0, "Creating a new entry for the phone from %s received via server ip %s\n",
1062  ast_inet_ntoa(addr_from->sin_addr), ast_inet_ntoa(s->sout.sin_addr));
1063  }
1064  ast_mutex_init(&s->lock);
1066  s->next = sessions;
1067  sessions = s;
1068 
1070  s->state = STATE_INIT;
1072  /* Initialize struct wsabuf */
1073  for (tmp = 0; tmp < MAX_BUF_NUMBER; tmp++) {
1074  s->wsabufsend[tmp].buf = s->buf[tmp];
1075  }
1077  return s;
1078 }
static struct unistimsession * sessions
struct sockaddr_in sout
Definition: chan_unistim.c:461
static int unistimsock
Definition: chan_unistim.c:247
struct wsabuf wsabufsend[MAX_BUF_NUMBER]
Definition: chan_unistim.c:474
static int tmp()
Definition: bt_open.c:389
unsigned char buf[MAX_BUF_NUMBER][MAX_BUF_SIZE]
Definition: chan_unistim.c:475
#define ast_mutex_lock(a)
Definition: lock.h:187
#define MAX_BUF_NUMBER
Definition: chan_unistim.c:93
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static ast_mutex_t sessionlock
Definition: chan_unistim.c:271
ast_mutex_t lock
Definition: chan_unistim.c:459
static int unistimdebug
Definition: chan_unistim.c:243
#define RETRANSMIT_TIMER
Definition: chan_unistim.c:103
struct unistimsession * next
Definition: chan_unistim.c:477
unsigned long tick_next_ping
Definition: chan_unistim.c:466
static int get_to_address(int fd, struct sockaddr_in *toAddr)
static int unistim_keepalive
Definition: chan_unistim.c:246
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct sockaddr_in sin
Definition: chan_unistim.c:460
unsigned char * buf
Definition: chan_unistim.c:350
static unsigned int get_tick_count(void)
Definition: chan_unistim.c:895
#define ast_mutex_init(pmutex)
Definition: lock.h:184
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ delete_device()

static void delete_device ( struct unistim_device d)
static

Definition at line 6422 of file chan_unistim.c.

References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log, ast_mutex_destroy, ast_tone_zone_unref(), ast_verb, devices, unistim_device::lines, unistim_subchannel::lock, unistim_line::lock, unistim_device::lock, unistimsession::lock, LOG_WARNING, unistim_device::name, unistim_device::next, unistimsession::next, unistim_subchannel::owner, unistim_device::session, sessions, sub, SUB_REAL, SUB_THREEWAY, unistim_device::subs, unistim_subchannel::subtype, unistim_device::tz, unistim_line_destroy(), and unistimdebug.

Referenced by build_device(), and reload_config().

6423 {
6424  struct unistim_line *l;
6425  struct unistim_subchannel *sub;
6426  struct unistimsession *s;
6427 
6428  if (unistimdebug) {
6429  ast_verb(0, "Removing device '%s'\n", d->name);
6430  }
6431  AST_LIST_LOCK(&d->subs);
6432  AST_LIST_TRAVERSE_SAFE_BEGIN(&d->subs, sub, list){
6433  if (sub->subtype == SUB_REAL) {
6434  if (sub->owner) {
6436  "Device '%s' was not deleted : a call is in progress. Try again later.\n",
6437  d->name);
6438  AST_LIST_UNLOCK(&d->subs);
6439  return;
6440  }
6441  }
6442  if (sub->subtype == SUB_THREEWAY) {
6444  "Device '%s' with threeway call subchannels allocated, aborting.\n",
6445  d->name);
6446  AST_LIST_UNLOCK(&d->subs);
6447  return;
6448  }
6450  ast_mutex_destroy(&sub->lock);
6451  ast_free(sub);
6452  }
6454  AST_LIST_UNLOCK(&d->subs);
6455 
6456 
6457  AST_LIST_LOCK(&d->lines);
6458  AST_LIST_TRAVERSE_SAFE_BEGIN(&d->lines, l, list){
6460  ast_mutex_destroy(&l->lock);
6462  }
6464  AST_LIST_UNLOCK(&d->lines);
6465 
6466  if (d->session) {
6467  if (sessions == d->session) {
6468  sessions = d->session->next;
6469  } else {
6470  s = sessions;
6471  while (s) {
6472  if (s->next == d->session) {
6473  s->next = d->session->next;
6474  break;
6475  }
6476  s = s->next;
6477  }
6478  }
6480  ast_free(d->session);
6481  }
6482  if (devices == d) {
6483  devices = d->next;
6484  } else {
6485  struct unistim_device *d2 = devices;
6486  while (d2) {
6487  if (d2->next == d) {
6488  d2->next = d->next;
6489  break;
6490  }
6491  d2 = d2->next;
6492  }
6493  }
6494  if (d->tz) {
6495  d->tz = ast_tone_zone_unref(d->tz);
6496  }
6497  ast_mutex_destroy(&d->lock);
6498  ast_free(d);
6499 }
ast_mutex_t lock
Definition: chan_unistim.c:354
struct unistim_device::@152 subs
struct ast_channel * owner
Definition: chan_unistim.c:356
static struct unistimsession * sessions
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:205
static struct unistim_line * unistim_line_destroy(struct unistim_line *l)
struct unistim_device::@153 lines
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define SUB_THREEWAY
Definition: chan_unistim.c:118
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define ast_verb(level,...)
Definition: logger.h:463
ast_mutex_t lock
Definition: chan_unistim.c:459
static int unistimdebug
Definition: chan_unistim.c:243
unsigned int subtype
Definition: chan_unistim.c:355
struct unistimsession * next
Definition: chan_unistim.c:477
#define ast_log
Definition: astobj2.c:42
ast_mutex_t lock
Definition: chan_unistim.c:373
struct unistim_device * next
Definition: chan_unistim.c:455
struct unistimsession * session
Definition: chan_unistim.c:454
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
struct ast_tone_zone * tz
Definition: chan_unistim.c:421
ast_mutex_t lock
Definition: chan_unistim.c:395
#define ast_free(a)
Definition: astmm.h:182
static struct unistim_device * devices
#define SUB_REAL
Definition: chan_unistim.c:116
struct stasis_forward * sub
Definition: res_corosync.c:240
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
#define ast_mutex_destroy(a)
Definition: lock.h:186

◆ discard_call()

static void discard_call ( struct unistimsession pte)
static

Definition at line 2647 of file chan_unistim.c.

References AST_CAUSE_NORMAL_CLEARING, ast_queue_hangup_with_cause(), unistimsession::device, get_sub(), unistim_subchannel::owner, sub, and SUB_RING.

Referenced by key_ringing().

2648 {
2649  struct unistim_subchannel* sub;
2650  sub = get_sub(pte->device, SUB_RING);
2651  if (!sub) {
2652  return;
2653  }
2654 
2656  return;
2657 }
struct ast_channel * owner
Definition: chan_unistim.c:356
#define SUB_RING
Definition: chan_unistim.c:117
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1166
struct unistim_device * device
Definition: chan_unistim.c:476
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
struct stasis_forward * sub
Definition: res_corosync.c:240

◆ display_last_error()

static void display_last_error ( const char *  sz_msg)
static

Definition at line 889 of file chan_unistim.c.

References ast_log, errno, and LOG_WARNING.

Referenced by key_history(), open_history(), send_raw_client(), show_entry_history(), write_entry_history(), and write_history().

890 {
891  /* Display the error message */
892  ast_log(LOG_WARNING, "%s : (%d) %s\n", sz_msg, errno, strerror(errno));
893 }
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
int errno

◆ do_monitor()

static void* do_monitor ( void *  data)
static

Definition at line 5835 of file chan_unistim.c.

References ast_io_add(), AST_IO_IN, ast_io_wait(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, ast_verb, DEBUG_TIMER, unistimsession::device, get_tick_count(), handle_call_outgoing(), IDLE_WAIT, unistimsession::last_buf_available, unistim_device::lines, unistim_line::list, unistim_line::mailbox, unistimsession::next, unistim_device::nextdial, unistim_device::nextmsgcheck, NULL, unistim_line::parent, reload_config(), send_ping(), send_retransmit(), sessionlock, sessions, unistimsession::timeout, unistim_reload_lock, unistim_reloading, unistim_send_mwi_to_peer(), unistimsock, and unistimsock_read().

Referenced by restart_monitor().

5836 {
5837  struct unistimsession *cur = NULL;
5838  unsigned int dw_timeout = 0;
5839  unsigned int tick;
5840  int res;
5841  int reloading;
5842 
5843  /* Add an I/O event to our UDP socket */
5844  if (unistimsock > -1) {
5846  }
5847  /* This thread monitors our UDP socket and timers */
5848  for (;;) {
5849  /* This loop is executed at least every IDLE_WAITus (1s) or every time a packet is received */
5850  /* Looking for the smallest time-out value */
5851  tick = get_tick_count();
5852  dw_timeout = UINT_MAX;
5854  cur = sessions;
5855  DEBUG_TIMER("checking timeout for session %p with tick = %u\n", cur, tick);
5856  while (cur) {
5857  DEBUG_TIMER("checking timeout for session %p timeout = %u\n", cur,
5858  cur->timeout);
5859  /* Check if we have miss something */
5860  if (cur->timeout <= tick) {
5861  DEBUG_TIMER("Event for session %p\n", cur);
5862  /* If the queue is empty, send a ping */
5863  if (cur->last_buf_available == 0) {
5864  send_ping(cur);
5865  } else {
5866  if (send_retransmit(cur)) {
5867  DEBUG_TIMER("The chained link was modified, restarting...\n");
5868  cur = sessions;
5869  dw_timeout = UINT_MAX;
5870  continue;
5871  }
5872  }
5873  }
5874  if (dw_timeout > cur->timeout - tick) {
5875  dw_timeout = cur->timeout - tick;
5876  }
5877  /* Checking if the phone is logged on for a new MWI */
5878  if (cur->device) {
5879  struct unistim_line *l;
5880  AST_LIST_LOCK(&cur->device->lines);
5881  AST_LIST_TRAVERSE(&cur->device->lines, l, list) {
5882  if ((!ast_strlen_zero(l->mailbox)) && (tick >= l->parent->nextmsgcheck)) {
5883  DEBUG_TIMER("Checking mailbox for MWI\n");
5884  unistim_send_mwi_to_peer(l, tick);
5885  break;
5886  }
5887  }
5888  AST_LIST_UNLOCK(&cur->device->lines);
5889  if (cur->device->nextdial && tick >= cur->device->nextdial) {
5890  handle_call_outgoing(cur);
5891  cur->device->nextdial = 0;
5892  }
5893  }
5894  cur = cur->next;
5895  }
5897  DEBUG_TIMER("Waiting for %dus\n", dw_timeout);
5898  res = dw_timeout;
5899  /* We should not wait more than IDLE_WAIT */
5900  if ((res < 0) || (res > IDLE_WAIT)) {
5901  res = IDLE_WAIT;
5902  }
5903  /* Wait for UDP messages for a maximum of res us */
5904  res = ast_io_wait(io, res); /* This function will call unistimsock_read if a packet is received */
5905  /* Check for a reload request */
5907  reloading = unistim_reloading;
5908  unistim_reloading = 0;
5910  if (reloading) {
5911  ast_verb(1, "Reloading unistim.conf...\n");
5912  reload_config();
5913  }
5914  pthread_testcancel();
5915  }
5916  /* Never reached */
5917  return NULL;
5918 }
int ast_io_wait(struct io_context *ioc, int howlong)
Waits for IO.
Definition: io.c:278
static struct unistimsession * sessions
struct unistim_line::@151 list
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
static int unistimsock
Definition: chan_unistim.c:247
struct unistim_device::@153 lines
static int send_retransmit(struct unistimsession *pte)
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static struct io_context * io
Definition: chan_unistim.c:256
static void send_ping(struct unistimsession *pte)
Definition: chan_unistim.c:991
#define DEBUG_TIMER
Definition: chan_unistim.c:241
#define AST_IO_IN
Definition: io.h:34
int * ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data)
Adds an IO context.
Definition: io.c:162
#define IDLE_WAIT
Definition: chan_unistim.c:101
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static ast_mutex_t sessionlock
Definition: chan_unistim.c:271
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
struct unistimsession * next
Definition: chan_unistim.c:477
static int reload_config(void)
char mailbox[AST_MAX_EXTENSION]
Definition: chan_unistim.c:378
time_t nextmsgcheck
Definition: chan_unistim.c:445
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
static int unistim_send_mwi_to_peer(struct unistim_line *peer, unsigned int tick)
static void handle_call_outgoing(struct unistimsession *s)
static int unistim_reloading
Definition: chan_unistim.c:260
struct unistim_device * parent
Definition: chan_unistim.c:387
static unsigned int get_tick_count(void)
Definition: chan_unistim.c:895
static int unistimsock_read(int *id, int fd, short events, void *ignore)
static ast_mutex_t unistim_reload_lock
Definition: chan_unistim.c:261
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ dummy()

static void dummy ( char *  unused,
  ... 
)
static

◆ find_language()

static int find_language ( const char *  lang)
static

Definition at line 3807 of file chan_unistim.c.

References NULL.

Referenced by handle_select_language(), init_phone_step2(), reload_config(), send_charset_update(), and ustmtext().

3808 {
3809  int i = 0;
3810  while (options_languages[i].lang_short != NULL) {
3811  if(!strcmp(options_languages[i].lang_short, lang)) {
3812  return i;
3813  }
3814  i++;
3815  }
3816  return 0;
3817 }
static struct unistim_languages options_languages[]
Definition: chan_unistim.c:771
#define NULL
Definition: resample.c:96

◆ find_line_by_number()

static struct unistim_line* find_line_by_number ( struct unistim_device d,
const char *  val 
)
static

Definition at line 6408 of file chan_unistim.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, unistim_device::lines, unistim_line::list, unistim_line::name, and NULL.

Referenced by build_device().

6408  {
6409  struct unistim_line *l, *ret = NULL;
6410 
6411  AST_LIST_LOCK(&d->lines);
6412  AST_LIST_TRAVERSE(&d->lines, l, list) {
6413  if (!strcmp(l->name, val)) {
6414  ret = l;
6415  break;
6416  }
6417  }
6418  AST_LIST_UNLOCK(&d->lines);
6419  return ret;
6420 }
struct unistim_line::@151 list
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
Definition: ast_expr2.c:325
struct unistim_device::@153 lines
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
char name[80]
Definition: chan_unistim.c:374
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490

◆ find_rtp_port()

static int find_rtp_port ( struct unistim_subchannel s)
static

Definition at line 2685 of file chan_unistim.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_rtp_instance_get_remote_address, ast_sockaddr_to_sin, NULL, unistim_subchannel::parent, unistim_line::parent, unistim_subchannel::rtp, unistim_device::rtp_port, sub, and unistim_device::subs.

Referenced by start_rtp().

2686 {
2687  struct unistim_subchannel *sub = NULL;
2688  int rtp_start = s->parent->parent->rtp_port;
2689  struct ast_sockaddr us_tmp;
2690  struct sockaddr_in us = { 0, };
2691 
2693  AST_LIST_TRAVERSE(&s->parent->parent->subs, sub, list) {
2694  if (!sub) {
2695  continue;
2696  }
2697  if (sub->rtp) {
2699  ast_sockaddr_to_sin(&us_tmp, &us);
2700  if (htons(us.sin_port)) {
2701  rtp_start = htons(us.sin_port) + 1;
2702  break;
2703  }
2704  }
2705  }
2707  return rtp_start;
2708 }
struct unistim_device::@152 subs
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
Socket address structure.
Definition: netsock2.h:97
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct unistim_line * parent
Definition: chan_unistim.c:357
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
#define ast_sockaddr_to_sin(addr, sin)
Converts a struct ast_sockaddr to a struct sockaddr_in.
Definition: netsock2.h:769
#define ast_rtp_instance_get_remote_address(instance, address)
Get the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.h:1192

◆ find_subchannel_by_name()

static struct unistim_subchannel* find_subchannel_by_name ( const char *  dest)
static

Definition at line 5421 of file chan_unistim.c.

References ast_copy_string(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_verb, d, devicelock, devices, get_sub(), unistim_subchannel::holding, unistim_device::lines, unistim_subchannel::list, LOG_NOTICE, LOG_WARNING, unistim_line::name, unistim_device::name, unistim_device::next, NULL, unistim_subchannel::owner, unistim_subchannel::parent, unistim_subchannel::ringstyle, unistim_subchannel::ringvolume, sub, SUB_REAL, unistim_alloc_sub(), and unistimdebug.

Referenced by unistim_request(), and unistim_sp().

5422 {
5423  struct unistim_line *l;
5424  struct unistim_device *d;
5425  struct unistim_subchannel *sub = NULL;
5426  char line[256];
5427  char *at;
5428  char *device;
5429 
5430  ast_copy_string(line, dest, sizeof(line));
5431  at = strchr(line, '@');
5432  if (!at) {
5433  ast_log(LOG_NOTICE, "Device '%s' has no @ (at) sign!\n", dest);
5434  return NULL;
5435  }
5436  *at = '\0';
5437  at++;
5438  device = at;
5440  d = devices;
5441  at = strchr(device, '/'); /* Extra options ? */
5442  if (at) {
5443  *at = '\0';
5444  }
5445  while (d) {
5446  if (!strcasecmp(d->name, device)) {
5447  if (unistimdebug) {
5448  ast_verb(0, "Found device: %s\n", d->name);
5449  }
5450  /* Found the device */
5451  AST_LIST_LOCK(&d->lines);
5452  AST_LIST_TRAVERSE(&d->lines, l, list) {
5453  /* Search for the right line */
5454  if (!strcasecmp(l->name, line)) {
5455  if (unistimdebug) {
5456  ast_verb(0, "Found line: %s\n", l->name);
5457  }
5458  sub = get_sub(d, SUB_REAL);
5459  if (!sub) {
5460  sub = unistim_alloc_sub(d, SUB_REAL);
5461  }
5462  if (sub->owner) {
5463  /* Allocate additional channel if asterisk channel already here */
5464  sub = unistim_alloc_sub(d, SUB_REAL);
5465  sub->holding = 1;
5466  }
5467  sub->ringvolume = -1;
5468  sub->ringstyle = -1;
5469  if (at) { /* Other options ? */
5470  at++; /* Skip slash */
5471  if (*at == 'r') { /* distinctive ring */
5472  at++;
5473  if ((*at < '0') || (*at > '7')) { /* ring style */
5474  ast_log(LOG_WARNING, "Invalid ring selection (%s)", at);
5475  } else {
5476  signed char ring_volume = -1;
5477  signed char ring_style = *at - '0';
5478  at++;
5479  if ((*at >= '0') && (*at <= '3')) { /* ring volume */
5480  ring_volume = *at - '0';
5481  }
5482  if (unistimdebug) {
5483  ast_verb(0, "Distinctive ring: style #%d volume %d\n",
5484  ring_style, ring_volume);
5485  }
5486  sub->ringvolume = ring_volume;
5487  sub->ringstyle = ring_style;
5488  }
5489  }
5490  }
5491  sub->parent = l;
5492  break;
5493  }
5494  }
5495  AST_LIST_UNLOCK(&d->lines);
5496  if (sub) {
5498  return sub;
5499  }
5500  }
5501  d = d->next;
5502  }
5503  /* Device not found */
5505 
5506  return NULL;
5507 }
struct ast_channel * owner
Definition: chan_unistim.c:356
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
struct unistim_device::@153 lines
signed char ringvolume
Definition: chan_unistim.c:363
signed char ringstyle
Definition: chan_unistim.c:364
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static struct test_val d
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
char name[80]
Definition: chan_unistim.c:374
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
#define ast_log
Definition: astobj2.c:42
static struct unistim_subchannel * unistim_alloc_sub(struct unistim_device *d, int x)
struct unistim_device * next
Definition: chan_unistim.c:455
#define LOG_NOTICE
Definition: logger.h:263
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
static struct unistim_device * devices
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
#define SUB_REAL
Definition: chan_unistim.c:116
struct unistim_subchannel::@150 list
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
struct unistim_line * parent
Definition: chan_unistim.c:357
struct stasis_forward * sub
Definition: res_corosync.c:240
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ finish_bookmark()

static void finish_bookmark ( void  )
static

Definition at line 6380 of file chan_unistim.c.

References ast_log, ast_mutex_lock, ast_mutex_unlock, d, devicelock, devices, LOG_NOTICE, unistim_device::name, unistim_device::next, NULL, unistim_device::softkeydevice, unistim_device::softkeyicon, and unistim_device::sp.

Referenced by reload_config().

6381 {
6382  struct unistim_device *d = devices;
6383  int i;
6385  while (d) {
6386  for (i = 0; i < 6; i++) {
6387  if (d->softkeyicon[i] == 1) { /* Something for us */
6388  struct unistim_device *d2 = devices;
6389  while (d2) {
6390  if (!strcmp(d->softkeydevice[i], d2->name)) {
6391  d->sp[i] = d2;
6392  d->softkeyicon[i] = 0;
6393  break;
6394  }
6395  d2 = d2->next;
6396  }
6397  if (d->sp[i] == NULL) {
6398  ast_log(LOG_NOTICE, "Bookmark entry with device %s not found\n",
6399  d->softkeydevice[i]);
6400  }
6401  }
6402  }
6403  d = d->next;
6404  }
6406 }
struct unistim_device * sp[FAVNUM]
Definition: chan_unistim.c:411
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
static struct test_val d
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
#define ast_log
Definition: astobj2.c:42
struct unistim_device * next
Definition: chan_unistim.c:455
char softkeydevice[FAVNUM][16]
Definition: chan_unistim.c:408
char softkeyicon[FAVNUM]
Definition: chan_unistim.c:407
#define LOG_NOTICE
Definition: logger.h:263
static struct unistim_device * devices
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ get_active_softkey()

static int get_active_softkey ( struct unistimsession pte)
static

Definition at line 1380 of file chan_unistim.c.

References unistimsession::device, and unistim_device::selected.

Referenced by change_favorite_icon().

1381 {
1382  return pte->device->selected;
1383 }
struct unistim_device * device
Definition: chan_unistim.c:476

◆ get_avail_softkey()

static int get_avail_softkey ( struct unistimsession pte,
const char *  name 
)
static

Definition at line 1385 of file chan_unistim.c.

References ast_verb, unistimsession::device, FAVNUM, is_key_line(), unistim_line::name, unistim_device::selected, unistim_device::sline, soft_key_visible(), unistim_device::ssub, and unistimdebug.

Referenced by handle_call_outgoing(), key_main_page(), process_request(), and unistim_request().

1386 {
1387  int i;
1388 
1389  if (!is_key_line(pte->device, pte->device->selected)) {
1390  pte->device->selected = -1;
1391  }
1392  for (i = 0; i < FAVNUM; i++) {
1393  if (pte->device->selected != -1 && pte->device->selected != i) {
1394  continue;
1395  }
1396  if (!soft_key_visible(pte->device, i)) {
1397  continue;
1398  }
1399  if (pte->device->ssub[i]) {
1400  continue;
1401  }
1402  if (is_key_line(pte->device, i)) {
1403  if (name && strcmp(name, pte->device->sline[i]->name)) {
1404  continue;
1405  }
1406  if (unistimdebug) {
1407  ast_verb(0, "Found softkey %d for device %s\n", i, name);
1408  }
1409  return i;
1410  }
1411  }
1412  return -1;
1413 }
static int soft_key_visible(struct unistim_device *d, unsigned char num)
#define FAVNUM
Definition: chan_unistim.c:216
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
char name[80]
Definition: chan_unistim.c:374
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410
static const char name[]
Definition: cdr_mysql.c:74
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
static int is_key_line(struct unistim_device *d, int fav)

◆ get_sub()

static struct unistim_subchannel* get_sub ( struct unistim_device device,
int  type 
)
static

Definition at line 2493 of file chan_unistim.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, unistim_subchannel::list, NULL, sub, unistim_device::subs, and unistim_subchannel::subtype.

Referenced by close_call(), discard_call(), find_subchannel_by_name(), handle_call_incoming(), handle_call_outgoing(), key_call(), key_dial_page(), sub_unhold(), transfer_call_step1(), transfer_cancel_step2(), unistim_answer(), unistim_call(), unistim_do_senddigit(), unistim_hangup(), and unistim_request().

2494 {
2495  struct unistim_subchannel *sub = NULL;
2496 
2497  AST_LIST_LOCK(&device->subs);
2498  AST_LIST_TRAVERSE(&device->subs, sub, list) {
2499  if (!sub) {
2500  continue;
2501  }
2502  if (sub->subtype == type) {
2503  break;
2504  }
2505  }
2506  AST_LIST_UNLOCK(&device->subs);
2507 
2508  return sub;
2509 }
struct unistim_device::@152 subs
static const char type[]
Definition: chan_ooh323.c:109
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
unsigned int subtype
Definition: chan_unistim.c:355
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct unistim_subchannel::@150 list
struct stasis_forward * sub
Definition: res_corosync.c:240

◆ get_sub_holding()

static struct unistim_subchannel* get_sub_holding ( struct unistim_device device,
int  type,
int  holding 
)
static

Definition at line 2511 of file chan_unistim.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, unistim_subchannel::holding, unistim_subchannel::list, NULL, sub, unistim_device::subs, and unistim_subchannel::subtype.

Referenced by handle_key_fav().

2512 {
2513  struct unistim_subchannel *sub = NULL;
2514 
2515  AST_LIST_LOCK(&device->subs);
2516  AST_LIST_TRAVERSE(&device->subs, sub, list) {
2517  if (!sub) {
2518  continue;
2519  }
2520  if (sub->subtype == type && sub->holding == holding) {
2521  break;
2522  }
2523  }
2524  AST_LIST_UNLOCK(&device->subs);
2525 
2526  return sub;
2527 }
struct unistim_device::@152 subs
static const char type[]
Definition: chan_ooh323.c:109
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
unsigned int subtype
Definition: chan_unistim.c:355
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct unistim_subchannel::@150 list
struct stasis_forward * sub
Definition: res_corosync.c:240

◆ get_tick_count()

static unsigned int get_tick_count ( void  )
static

Definition at line 895 of file chan_unistim.c.

References ast_tvnow().

Referenced by create_client(), do_monitor(), key_dial_page(), send_client(), send_ping(), and send_retransmit().

896 {
897  struct timeval now = ast_tvnow();
898 
899  return (now.tv_sec * 1000) + (now.tv_usec / 1000);
900 }
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150

◆ get_to_address()

static int get_to_address ( int  fd,
struct sockaddr_in *  toAddr 
)
static

Definition at line 1002 of file chan_unistim.c.

References ast_inet_ntoa(), ast_log, ast_verb, errno, LOG_WARNING, NULL, public_ip, and unistimdebug.

Referenced by create_client().

1003 {
1004 #ifdef HAVE_PKTINFO
1005  int err;
1006  char cmbuf[0x100];
1007  struct cmsghdr *cmsg;
1008  struct sockaddr_in peeraddr;
1009  struct in_addr addr;
1010  struct msghdr mh = {
1011  .msg_name = &peeraddr,
1012  .msg_namelen = sizeof(peeraddr),
1013  .msg_control = cmbuf,
1014  .msg_controllen = sizeof(cmbuf),
1015  };
1016  memset(&addr, 0, sizeof(addr));
1017  /* Get info about the incoming packet */
1018  err = recvmsg(fd, &mh, MSG_PEEK);
1019  if (err == -1) {
1020  ast_log(LOG_WARNING, "recvmsg returned an error: %s\n", strerror(errno));
1021  return err;
1022  }
1023  for(cmsg = CMSG_FIRSTHDR(&mh);
1024  cmsg != NULL;
1025  cmsg = CMSG_NXTHDR(&mh, cmsg))
1026  {
1027  if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO) {
1028  struct in_pktinfo *pkt = (struct in_pktinfo*)CMSG_DATA(cmsg);
1029  addr = pkt->ipi_addr;
1030  if (unistimdebug) {
1031  ast_verb(0, "message received on address %s\n", ast_inet_ntoa(addr));
1032  }
1033  }
1034  }
1035  memcpy(&toAddr->sin_addr, &addr, sizeof(struct in_addr));
1036  return err;
1037 #else
1038  memcpy(toAddr, &public_ip, sizeof(*toAddr));
1039  return 0;
1040 #endif
1041 }
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_log
Definition: astobj2.c:42
static struct sockaddr_in public_ip
Definition: chan_unistim.c:258
int errno
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782

◆ handle_call_incoming()

static void handle_call_incoming ( struct unistimsession s)
static

Definition at line 3262 of file chan_unistim.c.

References AST_CONTROL_ANSWER, ast_log, ast_queue_control(), ast_verb, unistimsession::device, FAV_ICON_OFFHOOK_BLACK, FAV_LINE_ICON, FAVNUM, get_sub(), LOG_WARNING, unistim_device::missed_call, MUTE_OFF, unistim_line::name, unistim_device::name, NULL, unistim_device::output, OUTPUT_HANDSET, OUTPUT_SPEAKER, unistim_subchannel::owner, unistim_subchannel::parent, unistim_device::receiver_state, unistim_subchannel::rtp, send_favorite_short(), send_no_ring(), send_select_output(), send_start_timer(), send_text(), send_text_status(), unistim_device::sline, unistim_subchannel::softkey, unistim_device::ssub, start_rtp(), unistimsession::state, STATE_CALL, STATE_ONHOOK, sub, sub_hold(), SUB_REAL, SUB_RING, unistim_subchannel::subtype, TEXT_LINE2, TEXT_NORMAL, unistimdebug, ustmtext(), unistim_device::volume, and write_history().

Referenced by handle_key_fav(), key_ringing(), and process_request().

3263 {
3264  struct unistim_subchannel *sub = NULL;
3265  int i;
3266 
3267  s->state = STATE_CALL;
3268  s->device->missed_call = 0;
3269  send_no_ring(s);
3270  sub = get_sub(s->device, SUB_RING); /* Put other SUB_REAL call on hold */
3271  if (!sub) {
3272  ast_log(LOG_WARNING, "No ringing lines on: %s\n", s->device->name);
3273  return;
3274  }
3275  /* Change icons for all ringing keys */
3276  for (i = 0; i < FAVNUM; i++) {
3277  if (!s->device->ssub[i]) { /* No sub assigned - skip */
3278  continue;
3279  }
3280  if (s->device->ssub[i]->subtype == SUB_REAL) {
3281  sub_hold(s, s->device->ssub[i]);
3282  }
3283  if (s->device->ssub[i] != sub) {
3284  continue;
3285  }
3286  if (sub->softkey == i) { /* If softkey assigned at this moment - do not erase */
3287  continue;
3288  }
3289  if (sub->softkey < 0) { /* If softkey not defined - first one used */
3290  sub->softkey = i;
3291  continue;
3292  }
3294  s->device->ssub[i] = NULL;
3295  }
3296  if (sub->softkey < 0) {
3297  ast_log(LOG_WARNING, "Can not assign softkey for incoming call on: %s\n", s->device->name);
3298  return;
3299  }
3301  sub->parent = s->device->sline[sub->softkey];
3302  sub->subtype = SUB_REAL;
3303  if (unistimdebug) {
3304  ast_verb(0, "Handle Call Incoming for %s@%s\n", sub->parent->name,
3305  s->device->name);
3306  }
3307  start_rtp(sub);
3308  if (!sub->rtp) {
3309  ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", sub->parent->name, s->device->name);
3310  return;
3311  }
3312  if (sub->owner) {
3314  }
3315  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("is on-line", s));
3316  send_text_status(s, ustmtext(" Transf Hangup", s));
3317  send_start_timer(s);
3318 
3319  if ((s->device->output == OUTPUT_HANDSET) &&
3320  (s->device->receiver_state == STATE_ONHOOK)) {
3322  } else {
3324  }
3325  write_history(s, 'i', 0);
3326  return;
3327 }
struct ast_channel * owner
Definition: chan_unistim.c:356
static int write_history(struct unistimsession *pte, char way, char ismissed)
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1231
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define TEXT_LINE2
Definition: chan_unistim.c:172
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
#define FAVNUM
Definition: chan_unistim.c:216
#define LOG_WARNING
Definition: logger.h:274
#define SUB_RING
Definition: chan_unistim.c:117
static void sub_hold(struct unistimsession *pte, struct unistim_subchannel *sub)
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
#define NULL
Definition: resample.c:96
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
char name[80]
Definition: chan_unistim.c:374
#define MUTE_OFF
Definition: chan_unistim.c:147
static void start_rtp(struct unistim_subchannel *sub)
#define ast_log
Definition: astobj2.c:42
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
#define FAV_LINE_ICON
Definition: chan_unistim.c:218
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
static void send_text_status(struct unistimsession *pte, const char *text)
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
#define SUB_REAL
Definition: chan_unistim.c:116
static void send_no_ring(struct unistimsession *pte)
struct unistim_line * parent
Definition: chan_unistim.c:357
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
struct stasis_forward * sub
Definition: res_corosync.c:240
static void send_start_timer(struct unistimsession *pte)
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
#define FAV_ICON_OFFHOOK_BLACK
Definition: chan_unistim.c:182

◆ handle_call_outgoing()

static void handle_call_outgoing ( struct unistimsession s)
static

Definition at line 3111 of file chan_unistim.c.

References ao2_cleanup, AST_CAUSE_CALL_REJECTED, AST_CAUSE_NORMAL_CLEARING, AST_CAUSE_SWITCH_CONGESTION, ast_channel_hangupcause_set(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_debug, ast_get_chan_features_pickup_config(), ast_hangup(), ast_log, ast_pickup_call(), ast_pthread_create, AST_PTHREADT_NULL, ast_queue_hangup_with_cause(), AST_STATE_DOWN, ast_strdupa, ast_verb, c, d, unistimsession::device, FAV_ICON_OFFHOOK_BLACK, get_avail_softkey(), get_sub(), unistim_device::height, LOG_ERROR, LOG_NOTICE, LOG_WARNING, MUTE_OFF, unistim_line::name, unistim_device::name, NULL, unistim_device::output, unistim_subchannel::owner, unistim_subchannel::parent, unistim_device::phone_number, RAII_VAR, unistim_subchannel::rtp, unistim_device::selected, send_favorite_short(), send_select_output(), send_start_timer(), send_text(), send_text_status(), send_tone(), unistim_device::sline, unistim_subchannel::softkey, unistim_subchannel::ss_thread, unistim_device::ssub, start_rtp(), unistimsession::state, STATE_CALL, sub, sub_hold(), SUB_REAL, sub_stop_silence(), SUB_THREEWAY, unistim_subchannel::subtype, swap_subs(), TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, unistim_alloc_sub(), unistim_new(), unistim_ss(), unistimdebug, ustmtext(), and unistim_device::volume.

Referenced by do_monitor(), key_dial_page(), key_favorite(), and key_main_page().

3112 {
3113  struct ast_channel *c;
3114  struct unistim_subchannel *sub;
3115  int softkey;
3116 
3117  s->state = STATE_CALL;
3118 
3119  sub = get_sub(s->device, SUB_THREEWAY);
3120  if (sub) {
3121  /* If sub for threway call created than we use transfer behaviuor */
3122  struct unistim_subchannel *sub_trans = NULL;
3123  struct unistim_device *d = s->device;
3124 
3125  sub_trans = get_sub(d, SUB_REAL);
3126  if (sub_trans) {
3127  ast_log(LOG_WARNING, "Can't transfer while active subchannel exists!\n");
3128  return;
3129  }
3130  if (!sub->owner) {
3131  ast_log(LOG_WARNING, "Unable to find subchannel with music on hold\n");
3132  return;
3133  }
3134 
3135  sub_trans = unistim_alloc_sub(d, SUB_REAL);
3136  if (!sub_trans) {
3137  ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3138  return;
3139  }
3140  sub_trans->parent = sub->parent;
3141  sub_stop_silence(s, sub);
3142  send_tone(s, 0, 0);
3143  /* Make new channel */
3144  c = unistim_new(sub_trans, AST_STATE_DOWN, NULL, NULL);
3145  if (!c) {
3146  ast_log(LOG_WARNING, "Cannot allocate new structure on channel %p\n", sub->parent);
3147  return;
3148  }
3149  /* Swap things around between the three-way and real call */
3150  swap_subs(sub, sub_trans);
3152  if (s->device->height == 1) {
3154  } else {
3155  send_text(TEXT_LINE0, TEXT_NORMAL, s, ustmtext("Calling (pre-transfer)", s));
3157  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("Dialing...", s));
3158  }
3159  send_text_status(s, ustmtext("TransfrCancel", s));
3160 
3161  if (ast_pthread_create(&sub->ss_thread, NULL, unistim_ss, c)) {
3162  ast_log(LOG_WARNING, "Unable to start simple switch on channel %p\n", c);
3164  ast_hangup(c);
3165  return;
3166  }
3167  if (unistimdebug) {
3168  ast_verb(0, "Started three way call on channel %p (%s) subchan %u\n",
3169  sub_trans->owner, ast_channel_name(sub_trans->owner), sub_trans->subtype);
3170  }
3171  return;
3172  }
3173 
3174  softkey = get_avail_softkey(s, NULL);
3175  if (softkey == -1) {
3176  ast_log(LOG_WARNING, "Have no avail softkey for calling\n");
3177  return;
3178  }
3179  sub = get_sub(s->device, SUB_REAL);
3180  if (sub) { /* have already call assigned */
3181  sub_hold(s, sub); /* Need to put on hold */
3182  }
3183  if (!(sub = unistim_alloc_sub(s->device, SUB_REAL))) {
3184  ast_log(LOG_WARNING, "Unable to allocate subchannel!\n");
3185  return;
3186  }
3187  sub->parent = s->device->sline[softkey];
3188  s->device->ssub[softkey] = sub;
3189  sub->softkey = softkey;
3190 
3191  if (unistimdebug) {
3192  ast_verb(0, "Using softkey %d, line %p\n", sub->softkey, sub->parent);
3193  }
3195  s->device->selected = -1;
3196  if (!sub->owner) { /* A call is already in progress ? */
3197  RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
3198  const char *pickupexten;
3199 
3200  c = unistim_new(sub, AST_STATE_DOWN, NULL, NULL); /* No, starting a new one */
3201  if (!sub->rtp) { /* Need to start RTP before calling ast_pbx_run */
3202  start_rtp(sub);
3203  }
3204  if (c) {
3205  ast_channel_lock(c);
3206  pickup_cfg = ast_get_chan_features_pickup_config(c);
3207  if (!pickup_cfg) {
3208  ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
3209  pickupexten = "";
3210  } else {
3211  pickupexten = ast_strdupa(pickup_cfg->pickupexten);
3212  }
3213  ast_channel_unlock(c);
3214  }
3215  if (c && !strcmp(s->device->phone_number, pickupexten)) {
3216  if (unistimdebug) {
3217  ast_verb(0, "Try to pickup in unistim_new\n");
3218  }
3219  send_text(TEXT_LINE0, TEXT_NORMAL, s, "");
3220  send_text_status(s, ustmtext(" Transf Hangup", s));
3221  send_start_timer(s);
3222  if (ast_pickup_call(c)) {
3223  ast_log(LOG_NOTICE, "Nothing to pick up\n");
3225  } else {
3227  }
3228  ast_hangup(c);
3229  c = NULL;
3230  } else if (c) {
3232  send_tone(s, 0, 0); /* Dialing empty number should also stop dial tone */
3233  if (s->device->height == 1) {
3234  if (strlen(s->device->phone_number) > 0) {
3236  } else {
3237  send_text(TEXT_LINE0, TEXT_NORMAL, s, ustmtext("Calling...", s));
3238  }
3239  } else {
3240  send_text(TEXT_LINE0, TEXT_NORMAL, s, ustmtext("Calling :", s));
3242  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("Dialing...", s));
3243  }
3244  send_text_status(s, ustmtext(" Hangup", s));
3245 
3246  /* start switch */
3247  if (ast_pthread_create(&sub->ss_thread, NULL, unistim_ss, c)) {
3248  ast_log(LOG_WARNING, "Unable to create switch thread\n");
3251  }
3252  } else
3253  ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n",
3254  sub->parent->name, s->device->name);
3255  } else {
3256  ast_debug(1, "Current sub [%s] already has owner\n", ast_channel_name(sub->owner));
3257  }
3258  return;
3259 }
struct ast_channel * owner
Definition: chan_unistim.c:356
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
struct ast_features_pickup_config * ast_get_chan_features_pickup_config(struct ast_channel *chan)
Get the pickup configuration options for a channel.
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define TEXT_LINE2
Definition: chan_unistim.c:172
static struct ast_channel * unistim_new(struct unistim_subchannel *sub, int state, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
#define AST_CAUSE_SWITCH_CONGESTION
Definition: causes.h:122
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
#define TEXT_LINE1
Definition: chan_unistim.c:171
#define LOG_WARNING
Definition: logger.h:274
static void sub_hold(struct unistimsession *pte, struct unistim_subchannel *sub)
char phone_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:399
static struct test_val d
#define SUB_THREEWAY
Definition: chan_unistim.c:118
static void swap_subs(struct unistim_subchannel *a, struct unistim_subchannel *b)
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
static struct test_val c
#define NULL
Definition: resample.c:96
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static void * unistim_ss(void *data)
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1166
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
char name[80]
Definition: chan_unistim.c:374
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
#define MUTE_OFF
Definition: chan_unistim.c:147
static void start_rtp(struct unistim_subchannel *sub)
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define AST_PTHREADT_NULL
Definition: lock.h:66
static struct unistim_subchannel * unistim_alloc_sub(struct unistim_device *d, int x)
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static int get_avail_softkey(struct unistimsession *pte, const char *name)
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
#define LOG_ERROR
Definition: logger.h:285
static void send_text_status(struct unistimsession *pte, const char *text)
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition: pickup.c:200
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410
#define LOG_NOTICE
Definition: logger.h:263
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:559
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
#define SUB_REAL
Definition: chan_unistim.c:116
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct unistim_line * parent
Definition: chan_unistim.c:357
const char * ast_channel_name(const struct ast_channel *chan)
struct stasis_forward * sub
Definition: res_corosync.c:240
static void send_start_timer(struct unistimsession *pte)
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
#define AST_CAUSE_CALL_REJECTED
Definition: causes.h:110
static void sub_stop_silence(struct unistimsession *pte, struct unistim_subchannel *sub)
#define FAV_ICON_OFFHOOK_BLACK
Definition: chan_unistim.c:182
Configuration relating to call pickup.

◆ handle_dial_page()

static void handle_dial_page ( struct unistimsession pte)
static

Definition at line 2983 of file chan_unistim.c.

References ast_copy_string(), ast_strlen_zero, unistim_device::call_forward, change_favorite_icon(), unistimsession::device, FAV_ICON_NONE, FAV_ICON_PHONE_BLACK, unistim_device::height, unistim_device::lastmsgssent, LED_BAR_OFF, unistim_device::missed_call, MUTE_OFF, unistim_device::output, OUTPUT_HANDSET, OUTPUT_SPEAKER, unistim_device::phone_number, unistim_device::receiver_state, unistim_device::redial_number, send_dial_tone(), send_icon(), send_led_update(), send_select_output(), send_text(), send_text_status(), show_phone_number(), unistim_device::size_phone_number, unistimsession::state, STATE_DIALPAGE, STATE_ONHOOK, TEXT_LINE0, TEXT_LINE1, TEXT_NORMAL, ustmtext(), and unistim_device::volume.

Referenced by handle_key_fav(), key_main_page(), process_request(), and transfer_call_step1().

2984 {
2985  pte->state = STATE_DIALPAGE;
2986  if (pte->device->call_forward[0] == -1) {
2987  send_text(TEXT_LINE0, TEXT_NORMAL, pte, "");
2988  send_text(TEXT_LINE1, TEXT_NORMAL, pte, ustmtext("Enter forward", pte));
2989  send_text_status(pte, ustmtext("Fwd Cancel BackSp Erase", pte));
2990  if (pte->device->call_forward[1] != 0) {
2992  sizeof(pte->device->phone_number));
2993  show_phone_number(pte);
2995  return;
2996  }
2997  } else {
2998  if ((pte->device->output == OUTPUT_HANDSET) &&
2999  (pte->device->receiver_state == STATE_ONHOOK)) {
3001  } else {
3002  send_select_output(pte, pte->device->output, pte->device->volume, MUTE_OFF);
3003  }
3004  send_dial_tone(pte);
3005 
3006  if (pte->device->height > 1) {
3007  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext("Enter the number to dial", pte));
3008  send_text(TEXT_LINE1, TEXT_NORMAL, pte, ustmtext("and press Call", pte));
3009  }
3010  if (ast_strlen_zero(pte->device->redial_number)) {
3011  send_text_status(pte, ustmtext("Call BackSp Erase", pte));
3012  } else {
3013  send_text_status(pte, ustmtext("Call Redial BackSp Erase", pte));
3014  }
3015  }
3016 
3017  pte->device->size_phone_number = 0;
3018  pte->device->phone_number[0] = 0;
3019  show_phone_number(pte);
3022  pte->device->missed_call = 0;
3024  pte->device->lastmsgssent = -1;
3025  return;
3026 }
char call_forward[AST_MAX_EXTENSION]
Definition: chan_unistim.c:438
static void send_dial_tone(struct unistimsession *pte)
#define TEXT_LINE1
Definition: chan_unistim.c:171
char phone_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:399
static void change_favorite_icon(struct unistimsession *pte, unsigned char status)
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_icon(unsigned char pos, unsigned char status, struct unistimsession *pte)
#define MUTE_OFF
Definition: chan_unistim.c:147
#define FAV_ICON_PHONE_BLACK
Definition: chan_unistim.c:188
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
#define FAV_ICON_NONE
Definition: chan_unistim.c:177
static void show_phone_number(struct unistimsession *pte)
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text_status(struct unistimsession *pte, const char *text)
static void send_led_update(struct unistimsession *pte, unsigned char led)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
#define LED_BAR_OFF
Definition: chan_unistim.c:151
char redial_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:400

◆ handle_key_fav()

static void handle_key_fav ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3380 of file chan_unistim.c.

References ast_verb, unistimsession::device, FAV_LINE_ICON, get_sub_holding(), handle_call_incoming(), handle_dial_page(), unistim_subchannel::holding, is_key_favorite(), is_key_line(), KEY_FAV0, key_favorite(), MUTE_OFF, NULL, unistim_device::output, OUTPUT_HANDSET, OUTPUT_SPEAKER, unistim_device::receiver_state, unistim_device::selected, send_callerid_screen(), send_favorite_selected(), send_select_output(), send_stop_timer(), send_tone(), show_main_page(), unistim_subchannel::softkey, unistim_device::ssub, unistimsession::state, STATE_CALL, STATE_DIALPAGE, STATE_ONHOOK, sub, sub_hold(), SUB_REAL, SUB_RING, sub_unhold(), unistim_subchannel::subtype, unistimdebug, and unistim_device::volume.

Referenced by key_call(), key_dial_page(), key_main_page(), and key_ringing().

3381 {
3382  int keynum = keycode - KEY_FAV0;
3383  struct unistim_subchannel *sub, *sub_key = NULL;
3384  sub = get_sub_holding(pte->device, SUB_REAL, 0);
3385 
3386  /* Make an action on selected favorite key */
3387  if (!pte->device->ssub[keynum]) { /* Key have no assigned call */
3388  sub = get_sub_holding(pte->device, SUB_REAL, 0);
3390  if (is_key_line(pte->device, keynum)) {
3391  if (unistimdebug) {
3392  ast_verb(0, "Handle line w/o sub - dialpage\n");
3393  }
3394  pte->device->selected = keynum;
3395  sub_hold(pte, sub); /* Put active call on hold */
3396  send_stop_timer(pte);
3397  handle_dial_page(pte);
3398  } else if (is_key_favorite(pte->device, keynum)) {
3399  /* Put active call on hold in handle_call_outgoing function, after preparation and
3400  checking if lines available for calling */
3401  if (unistimdebug) {
3402  ast_verb(0, "Handle favorite w/o sub - dialing\n");
3403  }
3404  if ((pte->device->output == OUTPUT_HANDSET) &&
3405  (pte->device->receiver_state == STATE_ONHOOK)) {
3407  } else {
3408  send_select_output(pte, pte->device->output, pte->device->volume, MUTE_OFF);
3409  }
3410  key_favorite(pte, keycode);
3411  }
3412  } else {
3413  sub_key = pte->device->ssub[keynum];
3414  /* Favicon have assigned sub, activate it and put current on hold */
3415  if (sub_key->subtype == SUB_REAL && !sub_key->holding) {
3416  sub_hold(pte, sub_key);
3417  show_main_page(pte);
3418  } else if (sub_key->subtype == SUB_REAL && sub_key->holding) {
3419  /* We are going to unhold line (we should put active line on hold, of any) */
3420  if (pte->state == STATE_DIALPAGE){
3421  send_tone(pte, 0, 0);
3422  }
3423  sub_hold(pte, sub);
3424  send_callerid_screen(pte, sub_key);
3425  sub_unhold(pte, sub_key);
3426  pte->state = STATE_CALL;
3427  } else if (sub_key->subtype == SUB_RING) {
3428  sub_hold(pte, sub);
3429  sub_key->softkey = keynum;
3430  handle_call_incoming(pte);
3431  }
3432  }
3433 }
static void send_favorite_selected(unsigned char status, struct unistimsession *pte)
static int is_key_favorite(struct unistim_device *d, int fav)
#define SUB_RING
Definition: chan_unistim.c:117
static void sub_hold(struct unistimsession *pte, struct unistim_subchannel *sub)
static struct unistim_subchannel * get_sub_holding(struct unistim_device *device, int type, int holding)
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
static void send_callerid_screen(struct unistimsession *, struct unistim_subchannel *)
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
#define MUTE_OFF
Definition: chan_unistim.c:147
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
static void handle_dial_page(struct unistimsession *pte)
#define FAV_LINE_ICON
Definition: chan_unistim.c:218
static void send_stop_timer(struct unistimsession *pte)
static void show_main_page(struct unistimsession *pte)
#define SUB_REAL
Definition: chan_unistim.c:116
static void sub_unhold(struct unistimsession *pte, struct unistim_subchannel *sub)
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
struct stasis_forward * sub
Definition: res_corosync.c:240
static void key_favorite(struct unistimsession *, char)
static void handle_call_incoming(struct unistimsession *s)
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
static int is_key_line(struct unistim_device *d, int fav)

◆ handle_select_codec()

static void handle_select_codec ( struct unistimsession pte)
static

Definition at line 3732 of file chan_unistim.c.

References ast_copy_string(), buf, buf2, unistim_device::codec_number, unistimsession::device, SELECTCODEC_MSG, SELECTCODEC_START_ENTRY_POS, send_blink_cursor(), send_cursor_pos(), send_text(), send_text_status(), unistimsession::size_buff_entry, unistimsession::state, STATE_SELECTCODEC, TEXT_INVERSE, TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, and ustmtext().

3733 {
3734  char buf[30], buf2[6];
3735 
3736  pte->state = STATE_SELECTCODEC;
3737  ast_copy_string(buf, ustmtext("Using codec", pte), sizeof(buf));
3738  snprintf(buf2, sizeof(buf2), " %d", pte->device->codec_number);
3739  strcat(buf, buf2);
3740  strcat(buf, " (G711u=0,");
3741 
3742  send_text(TEXT_LINE0, TEXT_NORMAL, pte, buf);
3743  send_text(TEXT_LINE1, TEXT_NORMAL, pte, "G723=4,G711a=8,G729A=18)");
3745  send_blink_cursor(pte);
3747  pte->size_buff_entry = 0;
3748  send_text_status(pte, ustmtext("Select BackSp Erase Cancel", pte));
3749  return;
3750 }
#define TEXT_LINE2
Definition: chan_unistim.c:172
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define TEXT_LINE1
Definition: chan_unistim.c:171
static struct ast_threadstorage buf2
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
static void send_blink_cursor(struct unistimsession *pte)
struct unistim_device * device
Definition: chan_unistim.c:476
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text_status(struct unistimsession *pte, const char *text)
#define TEXT_INVERSE
Definition: chan_unistim.c:174
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static void send_cursor_pos(struct unistimsession *pte, unsigned char pos)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define SELECTCODEC_START_ENTRY_POS
#define SELECTCODEC_MSG

◆ handle_select_language()

static void handle_select_language ( struct unistimsession pte)
static

Definition at line 3819 of file chan_unistim.c.

References ast_copy_string(), unistimsession::buff_entry, unistimsession::device, unistim_languages::encoding, find_language(), unistim_languages::label, unistim_languages::lang_short, unistim_device::language, send_charset_update(), send_text(), send_text_status(), unistimsession::size_buff_entry, unistimsession::state, STATE_SELECTLANGUAGE, TEXT_LINE0, TEXT_NORMAL, and ustmtext().

Referenced by key_select_language().

3820 {
3821  char tmp_language[40];
3822  struct unistim_languages lang;
3823 
3824  if (pte->state != STATE_SELECTLANGUAGE) {
3825  pte->state = STATE_SELECTLANGUAGE;
3826  pte->size_buff_entry = 1;
3827  pte->buff_entry[0] = find_language(pte->device->language);
3828  }
3829  lang = options_languages[(int)pte->buff_entry[0]];
3830  ast_copy_string(tmp_language, pte->device->language, sizeof(tmp_language));
3831  ast_copy_string(pte->device->language, lang.lang_short, sizeof(pte->device->language));
3832  send_charset_update(pte, lang.encoding);
3833  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext(lang.label, pte));
3834 
3835  ast_copy_string(pte->device->language, tmp_language, sizeof(pte->device->language));
3837  send_charset_update(pte, lang.encoding);
3838  send_text_status(pte, ustmtext("Select Cancel", pte));
3839  return;
3840 }
static struct unistim_languages options_languages[]
Definition: chan_unistim.c:771
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
struct unistim_device * device
Definition: chan_unistim.c:476
static int find_language(const char *)
static void send_charset_update(struct unistimsession *pte, int charset)
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text_status(struct unistimsession *pte, const char *text)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char buff_entry[16]
Definition: chan_unistim.c:471
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412

◆ handle_select_option()

static void handle_select_option ( struct unistimsession pte)
static

Definition at line 3687 of file chan_unistim.c.

References unistimsession::buff_entry, unistim_menu_item::label, send_text(), send_text_status(), unistimsession::size_buff_entry, unistimsession::state, STATE_SELECTOPTION, TEXT_LINE0, TEXT_NORMAL, tmp(), and ustmtext().

Referenced by key_main_page(), key_select_language(), and key_select_option().

3688 {
3689  char tmp[128];
3690 
3691  if (pte->state != STATE_SELECTOPTION) {
3692  pte->state = STATE_SELECTOPTION;
3693  pte->size_buff_entry = 1;
3694  pte->buff_entry[0] = 0; /* Position in menu */
3695  }
3696  snprintf(tmp, sizeof(tmp), "%d. %s", pte->buff_entry[0] + 1, ustmtext(options_menu[(int)pte->buff_entry[0]].label, pte));
3697  send_text(TEXT_LINE0, TEXT_NORMAL, pte, tmp);
3698  send_text_status(pte, ustmtext("Select Cancel", pte));
3699  return;
3700 }
static int tmp()
Definition: bt_open.c:389
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text_status(struct unistimsession *pte, const char *text)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
char buff_entry[16]
Definition: chan_unistim.c:471
static struct unistim_menu_item options_menu[]
Definition: chan_unistim.c:764

◆ ignore_call()

static void ignore_call ( struct unistimsession pte)
static

Definition at line 2641 of file chan_unistim.c.

References send_no_ring().

Referenced by key_ringing().

2642 {
2643  send_no_ring(pte);
2644  return;
2645 }
static void send_no_ring(struct unistimsession *pte)

◆ in_band_indication()

static void in_band_indication ( struct ast_channel ast,
const struct ast_tone_zone tz,
const char *  indication 
)
static

Definition at line 5320 of file chan_unistim.c.

References ast_get_indication_tone(), ast_log, ast_playtones_start(), ast_tone_zone_sound_unref(), ast_tone_zone_sound::data, LOG_WARNING, and NULL.

Referenced by unistim_indicate().

5322 {
5323  struct ast_tone_zone_sound *ts = NULL;
5324 
5325  if ((ts = ast_get_indication_tone(tz, indication))) {
5326  ast_playtones_start(ast, 0, ts->data, 1);
5327  ts = ast_tone_zone_sound_unref(ts);
5328  } else {
5329  ast_log(LOG_WARNING, "Unable to get indication tone for %s\n", indication);
5330  }
5331 }
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
Definition: indications.h:227
Description of a tone.
Definition: indications.h:35
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:455
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:302
const char * data
Description of a tone.
Definition: indications.h:52

◆ init_phone_step2()

static void init_phone_step2 ( struct unistimsession pte)
static

Definition at line 4381 of file chan_unistim.c.

References ast_verb, autoprovisioning, AUTOPROVISIONING_TN, BUFFSEND, unistim_device::contrast, unistimsession::device, unistim_languages::encoding, FAVNUM, find_language(), unistim_device::language, LED_BAR_OFF, unistimsession::macaddr, NULL, packet_send_arrow, packet_send_Contrast, packet_send_s4, packet_send_S7, packet_send_s9, refresh_all_favorite(), send_charset_update(), send_client(), send_date_time2(), send_date_time3(), send_favorite(), send_led_update(), send_no_ring(), send_ping(), send_text(), send_text_status(), send_texttitle(), show_extension_page(), show_main_page(), SIZE_HEADER, unistimsession::state, STATE_MAINPAGE, TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, tmp(), unistimdebug, and ustmtext().

Referenced by process_request().

4382 {
4383  BUFFSEND;
4384  if (unistimdebug) {
4385  ast_verb(0, "Sending S4\n");
4386  }
4387  memcpy(buffsend + SIZE_HEADER, packet_send_s4, sizeof(packet_send_s4));
4388  send_client(SIZE_HEADER + sizeof(packet_send_s4), buffsend, pte);
4389  send_date_time2(pte);
4390  send_date_time3(pte);
4391  if (unistimdebug) {
4392  ast_verb(0, "Sending S7\n");
4393  }
4394  memcpy(buffsend + SIZE_HEADER, packet_send_S7, sizeof(packet_send_S7));
4395  send_client(SIZE_HEADER + sizeof(packet_send_S7), buffsend, pte);
4396  if (unistimdebug) {
4397  ast_verb(0, "Sending Contrast\n");
4398  }
4399  memcpy(buffsend + SIZE_HEADER, packet_send_Contrast, sizeof(packet_send_Contrast));
4400  if (pte->device != NULL) {
4401  buffsend[9] = pte->device->contrast;
4402  }
4403  send_client(SIZE_HEADER + sizeof(packet_send_Contrast), buffsend, pte);
4404 
4405  if (unistimdebug) {
4406  ast_verb(0, "Sending S9\n");
4407  }
4408  memcpy(buffsend + SIZE_HEADER, packet_send_s9, sizeof(packet_send_s9));
4409  send_client(SIZE_HEADER + sizeof(packet_send_s9), buffsend, pte);
4410  send_no_ring(pte);
4411 
4412  if (unistimdebug) {
4413  ast_verb(0, "Sending S7\n");
4414  }
4415  memcpy(buffsend + SIZE_HEADER, packet_send_S7, sizeof(packet_send_S7));
4416  send_client(SIZE_HEADER + sizeof(packet_send_S7), buffsend, pte);
4418  send_ping(pte);
4419  if (unistimdebug) {
4420  ast_verb(0, "Sending init language\n");
4421  }
4422  if (pte->device) {
4424  }
4425  if (pte->state < STATE_MAINPAGE) {
4427  show_extension_page(pte);
4428  return;
4429  } else {
4430  int i;
4431  char tmp[30];
4432 
4433  for (i = 1; i < FAVNUM; i++) {
4434  send_favorite(i, 0, pte, "");
4435  }
4436  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext("Phone is not registered", pte));
4437  send_text(TEXT_LINE1, TEXT_NORMAL, pte, ustmtext("in unistim.conf", pte));
4438  strcpy(tmp, "MAC = ");
4439  strcat(tmp, pte->macaddr);
4440  send_text(TEXT_LINE2, TEXT_NORMAL, pte, tmp);
4441  send_text_status(pte, "");
4442  send_texttitle(pte, ustmtext("UNISTIM for*", pte));
4443  return;
4444  }
4445  }
4446  show_main_page(pte);
4447  refresh_all_favorite(pte);
4448  if (unistimdebug) {
4449  ast_verb(0, "Sending arrow\n");
4450  }
4451  memcpy(buffsend + SIZE_HEADER, packet_send_arrow, sizeof(packet_send_arrow));
4452  send_client(SIZE_HEADER + sizeof(packet_send_arrow), buffsend, pte);
4453  return;
4454 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define TEXT_LINE2
Definition: chan_unistim.c:172
#define FAVNUM
Definition: chan_unistim.c:216
static void show_extension_page(struct unistimsession *pte)
static const unsigned char packet_send_s4[]
Definition: chan_unistim.c:551
#define TEXT_LINE1
Definition: chan_unistim.c:171
static const unsigned char packet_send_Contrast[]
Definition: chan_unistim.c:638
static int tmp()
Definition: bt_open.c:389
static void send_ping(struct unistimsession *pte)
Definition: chan_unistim.c:991
static struct unistim_languages options_languages[]
Definition: chan_unistim.c:771
#define BUFFSEND
Definition: chan_unistim.c:704
#define NULL
Definition: resample.c:96
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static void send_date_time3(struct unistimsession *pte)
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
static const unsigned char packet_send_S7[]
Definition: chan_unistim.c:645
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
static int find_language(const char *)
static void send_texttitle(struct unistimsession *pte, const char *text)
static void refresh_all_favorite(struct unistimsession *pte)
char macaddr[18]
Definition: chan_unistim.c:472
static void send_charset_update(struct unistimsession *pte, int charset)
#define SIZE_HEADER
Definition: chan_unistim.c:167
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_favorite(unsigned char pos, unsigned char status, struct unistimsession *pte, const char *text)
static void send_text_status(struct unistimsession *pte, const char *text)
static void show_main_page(struct unistimsession *pte)
static const unsigned char packet_send_s9[]
Definition: chan_unistim.c:594
signed char contrast
Definition: chan_unistim.c:419
static void send_led_update(struct unistimsession *pte, unsigned char led)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static void send_no_ring(struct unistimsession *pte)
static enum autoprovision autoprovisioning
Definition: chan_unistim.c:245
#define LED_BAR_OFF
Definition: chan_unistim.c:151
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412
static const unsigned char packet_send_arrow[]
Definition: chan_unistim.c:633
static void send_date_time2(struct unistimsession *pte)

◆ is_key_favorite()

static int is_key_favorite ( struct unistim_device d,
int  fav 
)
static

Definition at line 1352 of file chan_unistim.c.

References FAVNUM, unistim_device::sline, and unistim_device::softkeynumber.

Referenced by handle_key_fav(), is_key_line(), and key_favorite().

1353 {
1354  if ((fav < 0) || (fav >= FAVNUM)) {
1355  return 0;
1356  }
1357  if (d->sline[fav]) {
1358  return 0;
1359  }
1360  if (d->softkeynumber[fav][0] == '\0') {
1361  return 0;
1362  }
1363  return 1;
1364 }
#define FAVNUM
Definition: chan_unistim.c:216
char softkeynumber[FAVNUM][AST_MAX_EXTENSION]
Definition: chan_unistim.c:406
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410

◆ is_key_line()

static int is_key_line ( struct unistim_device d,
int  fav 
)
static

Definition at line 1366 of file chan_unistim.c.

References FAVNUM, is_key_favorite(), and unistim_device::sline.

Referenced by get_avail_softkey(), handle_key_fav(), unistim_call(), and unistim_hangup().

1367 {
1368  if ((fav < 0) || (fav >= FAVNUM)) {
1369  return 0;
1370  }
1371  if (!d->sline[fav]) {
1372  return 0;
1373  }
1374  if (is_key_favorite(d, fav)) {
1375  return 0;
1376  }
1377  return 1;
1378 }
#define FAVNUM
Definition: chan_unistim.c:216
static int is_key_favorite(struct unistim_device *d, int fav)
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410

◆ key_call()

static void key_call ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3435 of file chan_unistim.c.

References AST_STATE_UP, close_call(), unistimsession::device, get_sub(), handle_key_fav(), unistim_subchannel::holding, KEY_0, KEY_FAV0, KEY_FAV1, KEY_FAV2, KEY_FAV3, KEY_FAV4, KEY_FAV5, KEY_FUNC1, KEY_FUNC2, KEY_FUNC4, KEY_HANGUP, KEY_HEADPHN, KEY_LOUDSPK, KEY_ONHOLD, KEY_SHARP, KEY_STAR, MUTE_OFF, unistim_device::output, OUTPUT_HANDSET, OUTPUT_HEADPHONE, OUTPUT_SPEAKER, unistim_subchannel::owner, unistim_device::previous_output, unistim_device::selected, send_select_output(), unistim_device::ssub, sub, sub_hold(), SUB_REAL, SUB_THREEWAY, sub_unhold(), transfer_call_step1(), transfer_cancel_step2(), unistim_do_senddigit(), and unistim_device::volume.

Referenced by process_request().

3436 {
3437  struct unistim_subchannel *sub = get_sub(pte->device, SUB_REAL);
3438  struct unistim_subchannel *sub_3way = get_sub(pte->device, SUB_THREEWAY);
3439 
3440  if (!sub) {
3441  return;
3442  }
3443  if ((keycode >= KEY_0) && (keycode <= KEY_SHARP)) {
3444  if (keycode == KEY_SHARP) {
3445  keycode = '#';
3446  } else if (keycode == KEY_STAR) {
3447  keycode = '*';
3448  } else {
3449  keycode -= 0x10;
3450  }
3451  unistim_do_senddigit(pte, keycode);
3452  return;
3453  }
3454  switch (keycode) {
3455  case KEY_FUNC1:
3456  if (sub->owner && ast_channel_state(sub->owner) == AST_STATE_UP) {
3457  if (sub_3way) {
3458  close_call(pte);
3459  }
3460  }
3461  break;
3462  case KEY_FUNC2:
3463  if (sub_3way) {
3464  transfer_cancel_step2(pte);
3465  } else if (ast_channel_state(sub->owner) == AST_STATE_UP) {
3466  transfer_call_step1(pte);
3467  }
3468  break;
3469  case KEY_HANGUP:
3470  case KEY_FUNC4:
3471  if (!sub_3way) {
3472  close_call(pte);
3473  }
3474  break;
3475  case KEY_FAV0:
3476  case KEY_FAV1:
3477  case KEY_FAV2:
3478  case KEY_FAV3:
3479  case KEY_FAV4:
3480  case KEY_FAV5:
3481  handle_key_fav(pte, keycode);
3482  break;
3483  case KEY_HEADPHN:
3484  if (pte->device->output == OUTPUT_HEADPHONE) {
3486  } else {
3488  }
3489  break;
3490  case KEY_LOUDSPK:
3491  if (pte->device->output != OUTPUT_SPEAKER)
3493  else
3495  MUTE_OFF);
3496  break;
3497  case KEY_ONHOLD:
3498  if (!sub) {
3499  if(pte->device->ssub[pte->device->selected]) {
3500  sub = pte->device->ssub[pte->device->selected];
3501  } else {
3502  break;
3503  }
3504  }
3505  if (sub->holding) {
3506  sub_unhold(pte, sub);
3507  } else {
3508  sub_hold(pte, sub);
3509  }
3510  break;
3511  }
3512  return;
3513 }
struct ast_channel * owner
Definition: chan_unistim.c:356
static void sub_hold(struct unistimsession *pte, struct unistim_subchannel *sub)
#define SUB_THREEWAY
Definition: chan_unistim.c:118
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
static void close_call(struct unistimsession *pte)
static void transfer_call_step1(struct unistimsession *pte)
struct unistim_device * device
Definition: chan_unistim.c:476
#define MUTE_OFF
Definition: chan_unistim.c:147
#define OUTPUT_HEADPHONE
Definition: chan_unistim.c:139
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
static int unistim_do_senddigit(struct unistimsession *pte, char digit)
static void transfer_cancel_step2(struct unistimsession *pte)
static void handle_key_fav(struct unistimsession *pte, char keycode)
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
#define SUB_REAL
Definition: chan_unistim.c:116
static void sub_unhold(struct unistimsession *pte, struct unistim_subchannel *sub)
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
struct stasis_forward * sub
Definition: res_corosync.c:240
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409

◆ key_dial_page()

static void key_dial_page ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3561 of file chan_unistim.c.

References ast_copy_string(), ast_exists_extension(), ast_matchmore_extension(), ast_queue_unhold(), ast_strlen_zero, unistim_device::call_forward, unistim_device::context, unistimsession::device, FAV_LINE_ICON, get_sub(), get_tick_count(), handle_call_outgoing(), handle_key_fav(), unistim_device::interdigit_timer, KEY_0, KEY_FAV0, KEY_FAV1, KEY_FAV2, KEY_FAV3, KEY_FAV4, KEY_FAV5, KEY_FUNC1, KEY_FUNC2, KEY_FUNC3, KEY_FUNC4, KEY_HANGUP, KEY_HEADPHN, KEY_LOUDSPK, KEY_SHARP, KEY_STAR, LED_HEADPHONE_OFF, LED_SPEAKER_OFF, unistim_subchannel::moh, MUTE_OFF, unistim_device::nextdial, NULL, unistim_device::output, OUTPUT_HANDSET, OUTPUT_HEADPHONE, OUTPUT_SPEAKER, unistim_subchannel::owner, unistim_device::phone_number, unistim_device::previous_output, unistim_device::receiver_state, unistim_device::redial_number, unistim_device::selected, send_callerid_screen(), send_favorite_selected(), send_led_update(), send_select_output(), send_text_status(), send_tone(), unistim_device::sharp_dial, show_main_page(), show_phone_number(), unistim_device::size_phone_number, unistimsession::state, STATE_CALL, STATE_OFFHOOK, sub, SUB_REAL, sub_stop_silence(), SUB_THREEWAY, unistim_subchannel::subtype, ustmtext(), and unistim_device::volume.

Referenced by key_main_page(), and process_request().

3562 {
3564 
3565  pte->device->nextdial = 0;
3566  if (keycode == KEY_FUNC3) {
3567  if (pte->device->size_phone_number <= 1) {
3568  keycode = KEY_FUNC4;
3569  } else {
3570  pte->device->size_phone_number -= 2;
3571  keycode = pte->device->phone_number[pte->device->size_phone_number] + 0x10;
3572  }
3573  }
3574  if (keycode == KEY_SHARP && pte->device->sharp_dial == 1) {
3575  keycode = KEY_FUNC1;
3576  }
3577  if ((keycode >= KEY_0) && (keycode <= KEY_SHARP)) {
3578  int i = pte->device->size_phone_number;
3579 
3580  if (pte->device->size_phone_number == 0) {
3581  send_tone(pte, 0, 0);
3582  }
3583  if (keycode == KEY_SHARP) {
3584  keycode = '#';
3585  } else if (keycode == KEY_STAR) {
3586  keycode = '*';
3587  } else {
3588  keycode -= 0x10;
3589  }
3590  pte->device->phone_number[i] = keycode;
3591  pte->device->size_phone_number++;
3592  pte->device->phone_number[i + 1] = 0;
3593  show_phone_number(pte);
3594 
3595  if (ast_exists_extension(NULL, pte->device->context, pte->device->phone_number, 1, NULL) &&
3597  keycode = KEY_FUNC1;
3598  } else {
3599  if (pte->device->interdigit_timer) {
3601  }
3602  }
3603  }
3604  if (keycode == KEY_FUNC4) {
3605  pte->device->size_phone_number = 0;
3606  show_phone_number(pte);
3607  return;
3608  }
3609 
3610  if (pte->device->call_forward[0] == -1) {
3611  if (keycode == KEY_FUNC1) {
3613  sizeof(pte->device->call_forward));
3614  show_main_page(pte);
3615  } else if ((keycode == KEY_FUNC2) || (keycode == KEY_HANGUP)) {
3616  pte->device->call_forward[0] = '\0';
3619  show_main_page(pte);
3620  }
3621  return;
3622  }
3623  switch (keycode) {
3624  case KEY_FUNC2:
3625  if (ast_strlen_zero(pte->device->redial_number)) {
3626  break;
3627  }
3629  sizeof(pte->device->phone_number));
3630  case KEY_FUNC1:
3631  handle_call_outgoing(pte);
3632  break;
3633  case KEY_HANGUP:
3634  if (sub && sub->owner) {
3635  sub_stop_silence(pte, sub);
3636  send_tone(pte, 0, 0);
3637  ast_queue_unhold(sub->owner);
3638  sub->moh = 0;
3639  sub->subtype = SUB_REAL;
3640  pte->state = STATE_CALL;
3641 
3642  send_text_status(pte, ustmtext(" Transf Hangup", pte));
3643  send_callerid_screen(pte, sub);
3644  } else {
3647  show_main_page(pte);
3648  }
3649  break;
3650  case KEY_FAV0:
3651  case KEY_FAV1:
3652  case KEY_FAV2:
3653  case KEY_FAV3:
3654  case KEY_FAV4:
3655  case KEY_FAV5:
3657  pte->device->selected = -1;
3658  handle_key_fav(pte, keycode);
3659  break;
3660  case KEY_LOUDSPK:
3661  if (pte->device->output == OUTPUT_SPEAKER) {
3662  if (pte->device->receiver_state == STATE_OFFHOOK) {
3664  MUTE_OFF);
3665  } else {
3666  show_main_page(pte);
3667  }
3668  } else {
3670  }
3671  break;
3672  case KEY_HEADPHN:
3673  if (pte->device->output == OUTPUT_HEADPHONE) {
3674  if (pte->device->receiver_state == STATE_OFFHOOK) {
3676  } else {
3677  show_main_page(pte);
3678  }
3679  } else {
3681  }
3682  break;
3683  }
3684  return;
3685 }
struct ast_channel * owner
Definition: chan_unistim.c:356
char call_forward[AST_MAX_EXTENSION]
Definition: chan_unistim.c:438
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch) ...
Definition: pbx.c:4199
static void send_favorite_selected(unsigned char status, struct unistimsession *pte)
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1216
char phone_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:399
#define SUB_THREEWAY
Definition: chan_unistim.c:118
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
static void send_callerid_screen(struct unistimsession *, struct unistim_subchannel *)
#define NULL
Definition: resample.c:96
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define LED_SPEAKER_OFF
Definition: chan_unistim.c:159
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
#define MUTE_OFF
Definition: chan_unistim.c:147
#define OUTPUT_HEADPHONE
Definition: chan_unistim.c:139
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
static void show_phone_number(struct unistimsession *pte)
#define FAV_LINE_ICON
Definition: chan_unistim.c:218
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4179
static void send_text_status(struct unistimsession *pte, const char *text)
static void show_main_page(struct unistimsession *pte)
static void handle_key_fav(struct unistimsession *pte, char keycode)
static void handle_call_outgoing(struct unistimsession *s)
static void send_led_update(struct unistimsession *pte, unsigned char led)
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
char context[AST_MAX_EXTENSION]
Definition: chan_unistim.c:398
#define SUB_REAL
Definition: chan_unistim.c:116
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
struct stasis_forward * sub
Definition: res_corosync.c:240
static unsigned int get_tick_count(void)
Definition: chan_unistim.c:895
#define LED_HEADPHONE_OFF
Definition: chan_unistim.c:161
static void sub_stop_silence(struct unistimsession *pte, struct unistim_subchannel *sub)
char redial_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:400

◆ key_favorite()

static void key_favorite ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3548 of file chan_unistim.c.

References ast_copy_string(), ast_log, unistimsession::device, handle_call_outgoing(), is_key_favorite(), KEY_FAV0, LOG_WARNING, unistim_device::phone_number, and unistim_device::softkeynumber.

Referenced by handle_key_fav().

3549 {
3550  int fav = keycode - KEY_FAV0;
3551  if (!is_key_favorite(pte->device, fav)) {
3552  ast_log(LOG_WARNING, "It's not a favorite key\n");
3553  return;
3554  }
3556  sizeof(pte->device->phone_number));
3557  handle_call_outgoing(pte);
3558  return;
3559 }
static int is_key_favorite(struct unistim_device *d, int fav)
#define LOG_WARNING
Definition: logger.h:274
char phone_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:399
char softkeynumber[FAVNUM][AST_MAX_EXTENSION]
Definition: chan_unistim.c:406
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
static void handle_call_outgoing(struct unistimsession *s)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ key_history()

static void key_history ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 4294 of file chan_unistim.c.

References ast_copy_string(), ast_strlen_zero, unistimsession::buff_entry, unistimsession::device, display_last_error(), unistim_device::height, KEY_DOWN, KEY_FUNC1, KEY_FUNC2, KEY_FUNC3, KEY_FUNC4, KEY_HANGUP, KEY_LEFT, key_main_page(), KEY_RCVHIST, KEY_RIGHT, KEY_SNDHIST, KEY_UP, unistim_device::lst_cid, open_history(), unistim_device::redial_number, show_entry_history(), show_history(), show_main_page(), and TEXT_LENGTH_MAX.

Referenced by process_request().

4295 {
4296  FILE *f;
4297  char count;
4298  long offset;
4299  int flag = 0;
4300 
4301  switch (keycode) {
4302  case KEY_LEFT:
4303  if (pte->device->height == 1) {
4304  if (pte->buff_entry[3] <= 1) {
4305  return;
4306  }
4307  pte->buff_entry[3]--;
4308  flag = 1;
4309  break;
4310  }
4311  case KEY_UP:
4312  case KEY_FUNC1:
4313  if (pte->buff_entry[2] <= 1) {
4314  return;
4315  }
4316  pte->buff_entry[2]--;
4317  flag = 1;
4318  break;
4319  case KEY_RIGHT:
4320  if (pte->device->height == 1) {
4321  if (pte->buff_entry[3] == 3) {
4322  return;
4323  }
4324  pte->buff_entry[3]++;
4325  flag = 1;
4326  break;
4327  }
4328  case KEY_DOWN:
4329  case KEY_FUNC2:
4330  if (pte->buff_entry[2] >= pte->buff_entry[1]) {
4331  return;
4332  }
4333  pte->buff_entry[2]++;
4334  flag = 1;
4335  break;
4336  case KEY_FUNC3:
4337  if (ast_strlen_zero(pte->device->lst_cid)) {
4338  break;
4339  }
4341  sizeof(pte->device->redial_number));
4342  key_main_page(pte, KEY_FUNC2);
4343  break;
4344  case KEY_FUNC4:
4345  case KEY_HANGUP:
4346  show_main_page(pte);
4347  break;
4348  case KEY_SNDHIST:
4349  if (pte->buff_entry[0] == 'i') {
4350  show_history(pte, 'o');
4351  } else {
4352  show_main_page(pte);
4353  }
4354  break;
4355  case KEY_RCVHIST:
4356  if (pte->buff_entry[0] == 'i') {
4357  show_main_page(pte);
4358  } else {
4359  show_history(pte, 'i');
4360  }
4361  break;
4362  }
4363 
4364  if (flag) {
4365  count = open_history(pte, pte->buff_entry[0], &f);
4366  if (!count) {
4367  return;
4368  }
4369  offset = ((pte->buff_entry[2] - 1) * TEXT_LENGTH_MAX * 3);
4370  if (fseek(f, offset, SEEK_CUR)) {
4371  display_last_error("Unable to seek history entry.");
4372  fclose(f);
4373  return;
4374  }
4375  show_entry_history(pte, &f);
4376  }
4377 
4378  return;
4379 }
static void show_history(struct unistimsession *pte, char way)
static void key_main_page(struct unistimsession *pte, char keycode)
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
static void show_main_page(struct unistimsession *pte)
long int flag
Definition: f2c.h:83
static char open_history(struct unistimsession *pte, char way, FILE **f)
char lst_cid[TEXT_LENGTH_MAX]
Definition: chan_unistim.c:436
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char buff_entry[16]
Definition: chan_unistim.c:471
static void show_entry_history(struct unistimsession *pte, FILE **f)
static void display_last_error(const char *sz_msg)
Definition: chan_unistim.c:889
char redial_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:400

◆ key_main_page()

static void key_main_page ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 4191 of file chan_unistim.c.

References ao2_cleanup, ast_copy_string(), ast_get_chan_features_pickup_config(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, unistimsession::buff_entry, unistim_device::call_forward, unistimsession::device, devicelock, unistim_device::extension, EXTENSION_ASK, unistim_device::extension_number, EXTENSION_TN, FAV_ICON_NONE, get_avail_softkey(), handle_call_outgoing(), handle_dial_page(), handle_key_fav(), handle_select_option(), unistim_device::id, KEY_0, KEY_CONF, key_dial_page(), KEY_FAV0, KEY_FAV1, KEY_FAV2, KEY_FAV3, KEY_FAV4, KEY_FAV5, KEY_FUNC1, KEY_FUNC2, KEY_FUNC3, KEY_FUNC4, KEY_HEADPHN, KEY_LOUDSPK, KEY_RCVHIST, KEY_SHARP, KEY_SNDHIST, LOG_ERROR, unistim_device::missed_call, MUTE_OFF, NULL, unistim_device::output, OUTPUT_HANDSET, OUTPUT_HEADPHONE, OUTPUT_SPEAKER, unistim_device::phone_number, RAII_VAR, unistim_device::receiver_state, unistim_device::redial_number, unistim_device::selected, send_icon(), send_select_output(), unistim_device::session, show_extension_page(), show_history(), show_main_page(), unistimsession::size_buff_entry, STATE_ONHOOK, TEXT_LINE0, unregister_extension(), and unistim_device::volume.

Referenced by key_history(), and process_request().

4192 {
4193  if (pte->device->missed_call) {
4195  pte->device->missed_call = 0;
4196  }
4197  if ((keycode >= KEY_0) && (keycode <= KEY_SHARP)) {
4198  handle_dial_page(pte);
4199  key_dial_page(pte, keycode);
4200  return;
4201  }
4202  switch (keycode) {
4203  case KEY_FUNC1:
4204  pte->device->selected = get_avail_softkey(pte, NULL);
4205  handle_dial_page(pte);
4206  break;
4207  case KEY_FUNC2:
4208  if (ast_strlen_zero(pte->device->redial_number)) {
4209  break;
4210  }
4211  if ((pte->device->output == OUTPUT_HANDSET) &&
4212  (pte->device->receiver_state == STATE_ONHOOK)) {
4214  } else {
4215  send_select_output(pte, pte->device->output, pte->device->volume, MUTE_OFF);
4216  }
4218  sizeof(pte->device->phone_number));
4219  handle_call_outgoing(pte);
4220  break;
4221  case KEY_FUNC3:
4222  if (!ast_strlen_zero(pte->device->call_forward)) {
4223  /* Cancel call forwarding */
4224  memmove(pte->device->call_forward + 1, pte->device->call_forward,
4225  sizeof(pte->device->call_forward) - 1);
4226  pte->device->call_forward[0] = '\0';
4228  pte->device->output = OUTPUT_HANDSET; /* Seems to be reseted somewhere */
4229  show_main_page(pte);
4230  break;
4231  }
4232  pte->device->call_forward[0] = -1;
4233  handle_dial_page(pte);
4234  break;
4235  case KEY_FUNC4:
4236  if (pte->device->extension == EXTENSION_ASK) {
4237  unregister_extension(pte);
4238  pte->device->extension_number[0] = '\0';
4239  show_extension_page(pte);
4240  } else if (pte->device->extension == EXTENSION_TN) {
4242  strcpy(pte->device->id, pte->device->extension_number);
4243  pte->buff_entry[0] = '\0';
4244  pte->size_buff_entry = 0;
4245  pte->device->session = NULL;
4246  pte->device = NULL;
4248  show_extension_page(pte);
4249  } else { /* Pickup function */
4250  /* XXX Is there a way to get a specific channel here? */
4251  RAII_VAR(struct ast_features_pickup_config *, pickup_cfg,
4253 
4254  if (!pickup_cfg) {
4255  ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
4256  break;
4257  }
4258 
4259  pte->device->selected = -1;
4260  ast_copy_string(pte->device->phone_number, pickup_cfg->pickupexten,
4261  sizeof(pte->device->phone_number));
4262  handle_call_outgoing(pte);
4263  }
4264  break;
4265  case KEY_FAV0:
4266  case KEY_FAV1:
4267  case KEY_FAV2:
4268  case KEY_FAV3:
4269  case KEY_FAV4:
4270  case KEY_FAV5:
4271  handle_key_fav(pte, keycode);
4272  break;
4273  case KEY_CONF:
4274  handle_select_option(pte);
4275  break;
4276  case KEY_LOUDSPK:
4278  handle_dial_page(pte);
4279  break;
4280  case KEY_HEADPHN:
4282  handle_dial_page(pte);
4283  break;
4284  case KEY_SNDHIST:
4285  show_history(pte, 'o');
4286  break;
4287  case KEY_RCVHIST:
4288  show_history(pte, 'i');
4289  break;
4290  }
4291  return;
4292 }
char call_forward[AST_MAX_EXTENSION]
Definition: chan_unistim.c:438
static void show_history(struct unistimsession *pte, char way)
struct ast_features_pickup_config * ast_get_chan_features_pickup_config(struct ast_channel *chan)
Get the pickup configuration options for a channel.
static void show_extension_page(struct unistimsession *pte)
char phone_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:399
static int unregister_extension(const struct unistimsession *pte)
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_icon(unsigned char pos, unsigned char status, struct unistimsession *pte)
#define MUTE_OFF
Definition: chan_unistim.c:147
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
#define ast_log
Definition: astobj2.c:42
#define OUTPUT_HEADPHONE
Definition: chan_unistim.c:139
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct unistimsession * session
Definition: chan_unistim.c:454
#define FAV_ICON_NONE
Definition: chan_unistim.c:177
static int get_avail_softkey(struct unistimsession *pte, const char *name)
static void handle_dial_page(struct unistimsession *pte)
#define TEXT_LINE0
Definition: chan_unistim.c:170
enum autoprov_extn extension
Definition: chan_unistim.c:447
#define LOG_ERROR
Definition: logger.h:285
static void show_main_page(struct unistimsession *pte)
static void handle_key_fav(struct unistimsession *pte, char keycode)
static void handle_call_outgoing(struct unistimsession *s)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char buff_entry[16]
Definition: chan_unistim.c:471
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
static void handle_select_option(struct unistimsession *pte)
static void key_dial_page(struct unistimsession *pte, char keycode)
char extension_number[11]
Definition: chan_unistim.c:448
char redial_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:400
#define ast_mutex_unlock(a)
Definition: lock.h:188
Configuration relating to call pickup.

◆ key_ringing()

static void key_ringing ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3515 of file chan_unistim.c.

References unistimsession::device, discard_call(), handle_call_incoming(), handle_key_fav(), ignore_call(), KEY_FAV0, KEY_FAV1, KEY_FAV2, KEY_FAV3, KEY_FAV4, KEY_FAV5, KEY_FUNC1, KEY_FUNC3, KEY_FUNC4, KEY_HANGUP, KEY_HEADPHN, KEY_LOUDSPK, unistim_device::output, OUTPUT_HEADPHONE, and OUTPUT_SPEAKER.

Referenced by process_request().

3516 {
3517  switch (keycode) {
3518  case KEY_FAV0:
3519  case KEY_FAV1:
3520  case KEY_FAV2:
3521  case KEY_FAV3:
3522  case KEY_FAV4:
3523  case KEY_FAV5:
3524  handle_key_fav(pte, keycode);
3525  break;
3526  case KEY_FUNC3:
3527  ignore_call(pte);
3528  break;
3529  case KEY_HANGUP:
3530  case KEY_FUNC4:
3531  discard_call(pte);
3532  break;
3533  case KEY_LOUDSPK:
3534  pte->device->output = OUTPUT_SPEAKER;
3535  handle_call_incoming(pte);
3536  break;
3537  case KEY_HEADPHN:
3538  pte->device->output = OUTPUT_HEADPHONE;
3539  handle_call_incoming(pte);
3540  break;
3541  case KEY_FUNC1:
3542  handle_call_incoming(pte);
3543  break;
3544  }
3545  return;
3546 }
static void discard_call(struct unistimsession *pte)
struct unistim_device * device
Definition: chan_unistim.c:476
#define OUTPUT_HEADPHONE
Definition: chan_unistim.c:139
static void ignore_call(struct unistimsession *pte)
static void handle_key_fav(struct unistimsession *pte, char keycode)
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
static void handle_call_incoming(struct unistimsession *s)

◆ key_select_codec()

static void key_select_codec ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3752 of file chan_unistim.c.

References unistimsession::buff_entry, unistim_device::codec_number, unistimsession::device, KEY_0, KEY_9, KEY_FUNC1, KEY_FUNC2, KEY_FUNC3, KEY_FUNC4, KEY_HANGUP, SELECTCODEC_MAX_LENGTH, SELECTCODEC_MSG, SELECTCODEC_START_ENTRY_POS, send_blink_cursor(), send_cursor_pos(), send_text(), show_main_page(), unistimsession::size_buff_entry, TEXT_INVERSE, and TEXT_LINE2.

Referenced by process_request().

3753 {
3754  if (keycode == KEY_FUNC2) {
3755  if (pte->size_buff_entry <= 1) {
3756  keycode = KEY_FUNC3;
3757  } else {
3758  pte->size_buff_entry -= 2;
3759  keycode = pte->buff_entry[pte->size_buff_entry] + 0x10;
3760  }
3761  }
3762  if ((keycode >= KEY_0) && (keycode <= KEY_9)) {
3763  char tmpbuf[] = SELECTCODEC_MSG;
3764  int i = 0;
3765 
3767  return;
3768  }
3769  while (i < pte->size_buff_entry) {
3770  tmpbuf[i + SELECTCODEC_START_ENTRY_POS] = pte->buff_entry[i];
3771  i++;
3772  }
3773  tmpbuf[i + SELECTCODEC_START_ENTRY_POS] = keycode - 0x10;
3774  pte->buff_entry[i] = keycode - 0x10;
3775  pte->size_buff_entry++;
3776  send_text(TEXT_LINE2, TEXT_INVERSE, pte, tmpbuf);
3777  send_blink_cursor(pte);
3778  send_cursor_pos(pte,
3779  (unsigned char) (TEXT_LINE2 + SELECTCODEC_START_ENTRY_POS + 1 + i));
3780  return;
3781  }
3782 
3783  switch (keycode) {
3784  case KEY_FUNC1:
3785  if (pte->size_buff_entry == 1) {
3786  pte->device->codec_number = pte->buff_entry[0] - 48;
3787  } else if (pte->size_buff_entry == 2) {
3788  pte->device->codec_number =
3789  ((pte->buff_entry[0] - 48) * 10) + (pte->buff_entry[1] - 48);
3790  }
3791  show_main_page(pte);
3792  break;
3793  case KEY_FUNC3:
3794  pte->size_buff_entry = 0;
3796  send_blink_cursor(pte);
3798  break;
3799  case KEY_HANGUP:
3800  case KEY_FUNC4:
3801  show_main_page(pte);
3802  break;
3803  }
3804  return;
3805 }
#define TEXT_LINE2
Definition: chan_unistim.c:172
static void send_blink_cursor(struct unistimsession *pte)
struct unistim_device * device
Definition: chan_unistim.c:476
static void show_main_page(struct unistimsession *pte)
#define TEXT_INVERSE
Definition: chan_unistim.c:174
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static void send_cursor_pos(struct unistimsession *pte, unsigned char pos)
char buff_entry[16]
Definition: chan_unistim.c:471
#define SELECTCODEC_START_ENTRY_POS
#define SELECTCODEC_MAX_LENGTH
#define SELECTCODEC_MSG

◆ key_select_extension()

static void key_select_extension ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3890 of file chan_unistim.c.

References ast_copy_string(), ast_mutex_lock, ast_mutex_unlock, autoprovisioning, AUTOPROVISIONING_TN, unistimsession::buff_entry, unistim_device::codec_number, d, DEFAULT_CODEC, unistimsession::device, devicelock, devices, unistim_device::extension, unistim_device::extension_number, EXTENSION_TN, unistim_device::id, KEY_0, KEY_9, KEY_FUNC1, KEY_FUNC2, KEY_FUNC3, unistimsession::macaddr, unistim_device::missed_call, unistim_device::next, unistim_device::receiver_state, refresh_all_favorite(), register_extension(), SELECTEXTENSION_MAX_LENGTH, SELECTEXTENSION_MSG, SELECTEXTENSION_START_ENTRY_POS, send_blink_cursor(), send_cursor_pos(), send_text(), unistim_device::session, show_main_page(), unistimsession::size_buff_entry, STATE_ONHOOK, TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, and ustmtext().

Referenced by process_request().

3891 {
3892  if (keycode == KEY_FUNC2) {
3893  if (pte->size_buff_entry <= 1) {
3894  keycode = KEY_FUNC3;
3895  } else {
3896  pte->size_buff_entry -= 2;
3897  keycode = pte->buff_entry[pte->size_buff_entry] + 0x10;
3898  }
3899  }
3900  if ((keycode >= KEY_0) && (keycode <= KEY_9)) {
3901  char tmpbuf[] = SELECTEXTENSION_MSG;
3902  int i = 0;
3903 
3905  return;
3906  }
3907  while (i < pte->size_buff_entry) {
3908  tmpbuf[i + SELECTEXTENSION_START_ENTRY_POS] = pte->buff_entry[i];
3909  i++;
3910  }
3911  tmpbuf[i + SELECTEXTENSION_START_ENTRY_POS] = keycode - 0x10;
3912  pte->buff_entry[i] = keycode - 0x10;
3913  pte->size_buff_entry++;
3914  send_text(TEXT_LINE2, TEXT_NORMAL, pte, tmpbuf);
3915  send_blink_cursor(pte);
3916  send_cursor_pos(pte, (unsigned char) (TEXT_LINE2 + SELECTEXTENSION_START_ENTRY_POS + 1 + i));
3917  return;
3918  }
3919 
3920  switch (keycode) {
3921  case KEY_FUNC1:
3922  if (pte->size_buff_entry < 1) {
3923  return;
3924  }
3926  struct unistim_device *d;
3927 
3928  /* First step : looking for this TN in our device list */
3930  d = devices;
3931  pte->buff_entry[pte->size_buff_entry] = '\0';
3932  while (d) {
3933  if (d->id[0] == 'T') { /* It's a TN device ? */
3934  /* It's the TN we're looking for ? */
3935  if (!strcmp((d->id) + 1, pte->buff_entry)) {
3936  pte->device = d;
3937  d->session = pte;
3939  d->missed_call = 0;
3941  strcpy(d->id, pte->macaddr);
3942  pte->device->extension_number[0] = 'T';
3943  pte->device->extension = EXTENSION_TN;
3945  pte->buff_entry, pte->size_buff_entry + 1);
3947  show_main_page(pte);
3948  refresh_all_favorite(pte);
3949  return;
3950  }
3951  }
3952  d = d->next;
3953  }
3955  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext("Invalid Terminal Number.", pte));
3956  send_text(TEXT_LINE1, TEXT_NORMAL, pte, ustmtext("Please try again :", pte));
3958  pte->size_buff_entry));
3959  send_blink_cursor(pte);
3960  } else {
3962  pte->size_buff_entry + 1);
3963  if (register_extension(pte)) {
3964  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext("Invalid extension.", pte));
3965  send_text(TEXT_LINE1, TEXT_NORMAL, pte, ustmtext("Please try again :", pte));
3966  send_cursor_pos(pte, (unsigned char) (TEXT_LINE2 +
3968  pte->size_buff_entry));
3969  send_blink_cursor(pte);
3970  } else
3971  show_main_page(pte);
3972  }
3973  break;
3974  case KEY_FUNC3:
3975  pte->size_buff_entry = 0;
3977  send_blink_cursor(pte);
3979  break;
3980  }
3981  return;
3982 }
#define SELECTEXTENSION_START_ENTRY_POS
A device containing one or more lines.
Definition: chan_unistim.c:394
#define TEXT_LINE2
Definition: chan_unistim.c:172
#define TEXT_LINE1
Definition: chan_unistim.c:171
static struct test_val d
#define ast_mutex_lock(a)
Definition: lock.h:187
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
static void send_blink_cursor(struct unistimsession *pte)
struct unistim_device * device
Definition: chan_unistim.c:476
static void refresh_all_favorite(struct unistimsession *pte)
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
char macaddr[18]
Definition: chan_unistim.c:472
#define DEFAULT_CODEC
Definition: chan_unistim.c:110
struct unistim_device * next
Definition: chan_unistim.c:455
struct unistimsession * session
Definition: chan_unistim.c:454
#define TEXT_LINE0
Definition: chan_unistim.c:170
enum autoprov_extn extension
Definition: chan_unistim.c:447
static void show_main_page(struct unistimsession *pte)
static int register_extension(const struct unistimsession *pte)
#define SELECTEXTENSION_MAX_LENGTH
static struct unistim_device * devices
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static void send_cursor_pos(struct unistimsession *pte, unsigned char pos)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char buff_entry[16]
Definition: chan_unistim.c:471
static enum autoprovision autoprovisioning
Definition: chan_unistim.c:245
#define SELECTEXTENSION_MSG
char extension_number[11]
Definition: chan_unistim.c:448
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ key_select_language()

static void key_select_language ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3842 of file chan_unistim.c.

References ast_copy_string(), unistimsession::buff_entry, unistimsession::device, unistim_languages::encoding, handle_select_language(), handle_select_option(), KEY_DOWN, KEY_FUNC1, KEY_FUNC4, KEY_HANGUP, KEY_UP, unistim_languages::label, unistim_languages::lang_short, unistim_device::language, NULL, refresh_all_favorite(), send_charset_update(), and show_main_page().

Referenced by process_request().

3843 {
3844  switch (keycode) {
3845  case KEY_DOWN:
3846  pte->buff_entry[0]++;
3847  if (options_languages[(int)pte->buff_entry[0]].label == NULL) {
3848  pte->buff_entry[0]--;
3849  }
3850  break;
3851  case KEY_UP:
3852  if (pte->buff_entry[0] > 0) {
3853  pte->buff_entry[0]--;
3854  }
3855  break;
3856  case KEY_FUNC1:
3859  refresh_all_favorite(pte);
3860  show_main_page(pte);
3861  return;
3862  case KEY_HANGUP:
3863  case KEY_FUNC4:
3864  handle_select_option(pte);
3865  return;
3866  }
3867 
3869  return;
3870 }
static struct unistim_languages options_languages[]
Definition: chan_unistim.c:771
#define NULL
Definition: resample.c:96
struct unistim_device * device
Definition: chan_unistim.c:476
static void refresh_all_favorite(struct unistimsession *pte)
static void handle_select_language(struct unistimsession *)
static void send_charset_update(struct unistimsession *pte, int charset)
static void show_main_page(struct unistimsession *pte)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char buff_entry[16]
Definition: chan_unistim.c:471
static void handle_select_option(struct unistimsession *pte)
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412

◆ key_select_option()

static void key_select_option ( struct unistimsession pte,
char  keycode 
)
static

Definition at line 3702 of file chan_unistim.c.

References unistimsession::buff_entry, unistim_menu_item::handle_option, handle_select_option(), KEY_DOWN, KEY_FUNC1, KEY_FUNC4, KEY_HANGUP, KEY_UP, unistim_menu_item::label, NULL, and show_main_page().

Referenced by process_request().

3703 {
3704  switch (keycode) {
3705  case KEY_DOWN:
3706  pte->buff_entry[0]++;
3707  if (options_menu[(int)pte->buff_entry[0]].label == NULL) {
3708  pte->buff_entry[0]--;
3709  }
3710  break;
3711  case KEY_UP:
3712  if (pte->buff_entry[0] > 0) {
3713  pte->buff_entry[0]--;
3714  }
3715  break;
3716  case KEY_FUNC1:
3717  options_menu[(int)pte->buff_entry[0]].handle_option(pte);
3718  return;
3719  case KEY_HANGUP:
3720  case KEY_FUNC4:
3721  show_main_page(pte);
3722  return;
3723  }
3724 
3725  handle_select_option(pte);
3726  return;
3727 }
void(* handle_option)(struct unistimsession *)
Definition: chan_unistim.c:484
#define NULL
Definition: resample.c:96
static void show_main_page(struct unistimsession *pte)
char buff_entry[16]
Definition: chan_unistim.c:471
static void handle_select_option(struct unistimsession *pte)
static struct unistim_menu_item options_menu[]
Definition: chan_unistim.c:764

◆ lang_cmp_fn()

static int lang_cmp_fn ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 792 of file chan_unistim.c.

References CMP_MATCH, CMP_STOP, and ustm_lang_entry::str_orig.

Referenced by ustmtext().

793 {
794  struct ustm_lang_entry *entry1 = obj;
795  struct ustm_lang_entry *entry2 = arg;
796 
797  return (!strcmp(entry1->str_orig, entry2->str_orig)) ? (CMP_MATCH | CMP_STOP) : 0;
798 }
const char * str_orig
Definition: chan_unistim.c:782
Definition: chan_unistim.c:781

◆ lang_hash_fn()

static int lang_hash_fn ( const void *  obj,
const int  flags 
)
static

Definition at line 786 of file chan_unistim.c.

References ast_str_hash(), and ustm_lang_entry::str_orig.

Referenced by ustmtext().

787 {
788  const struct ustm_lang_entry *entry = obj;
789  return ast_str_hash(entry->str_orig);
790 }
const char * str_orig
Definition: chan_unistim.c:782
Definition: search.h:40
Definition: chan_unistim.c:781
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1206

◆ load_module()

int load_module ( void  )
static

XXX

Todo:
Leaking anything allocated by reload_config() ...

Definition at line 7082 of file chan_unistim.c.

References ao2_cleanup, ao2_ref, ARRAY_LEN, ast_channel_register(), ast_cli_register_multiple, ast_format_alaw, ast_format_cap_alloc, ast_format_cap_append, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_ulaw, ast_free, ast_log, ast_malloc, AST_MEDIA_TYPE_AUDIO, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_rtp_glue_register, ast_sched_context_create(), ast_sched_context_destroy(), buff, ast_channel_tech::capabilities, channel_type, io_context_create(), io_context_destroy(), LOG_ERROR, NULL, reload_config(), restart_monitor(), and SIZE_PAGE.

Referenced by reload().

7083 {
7084  int res;
7085 
7087  goto buff_failed;
7088  }
7090  goto buff_failed;
7091  }
7092 
7096 
7097  if (!(buff = ast_malloc(SIZE_PAGE))) {
7098  goto buff_failed;
7099  }
7100 
7101  io = io_context_create();
7102  if (!io) {
7103  ast_log(LOG_ERROR, "Failed to allocate IO context\n");
7104  goto io_failed;
7105  }
7106 
7108  if (!sched) {
7109  ast_log(LOG_ERROR, "Failed to allocate scheduler context\n");
7110  goto sched_failed;
7111  }
7112 
7113  res = reload_config();
7114  if (res) {
7116  ao2_ref(global_cap, -1);
7119  return AST_MODULE_LOAD_DECLINE;
7120  }
7121  /* Make sure we can register our unistim channel type */
7123  ast_log(LOG_ERROR, "Unable to register channel type '%s'\n", channel_type);
7124  goto chanreg_failed;
7125  }
7126 
7128 
7130 
7131  restart_monitor();
7132 
7133  return AST_MODULE_LOAD_SUCCESS;
7134 
7135 chanreg_failed:
7136  /*! XXX \todo Leaking anything allocated by reload_config() ... */
7138  sched = NULL;
7139 sched_failed:
7141  io = NULL;
7142 io_failed:
7143  ast_free(buff);
7144  buff = NULL;
7145 buff_failed:
7147  global_cap = NULL;
7150  return AST_MODULE_LOAD_DECLINE;
7151 }
static const char channel_type[]
Definition: chan_unistim.c:707
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
static struct ast_cli_entry unistim_cli[]
static struct io_context * io
Definition: chan_unistim.c:256
#define ast_rtp_glue_register(glue)
Definition: rtp_engine.h:847
Definition: sched.c:76
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
int ast_channel_register(const struct ast_channel_tech *tech)
Register a channel technology (a new channel driver) Called by a channel module to register the kind ...
Definition: channel.c:539
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
void io_context_destroy(struct io_context *ioc)
Destroys a context.
Definition: io.c:107
static int reload_config(void)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition: sched.c:236
#define LOG_ERROR
Definition: logger.h:285
struct ast_format_cap * capabilities
Definition: channel.h:633
#define ast_free(a)
Definition: astmm.h:182
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
struct ast_format_cap * global_cap
Definition: chan_unistim.c:120
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
static unsigned char * buff
Definition: chan_unistim.c:259
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
static int restart_monitor(void)
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition: sched.c:269
#define SIZE_PAGE
Definition: chan_unistim.c:111
static struct ast_channel_tech unistim_tech
Definition: chan_unistim.c:736
static struct ast_rtp_glue unistim_rtp_glue
struct io_context * io_context_create(void)
Creates a context Create a context for I/O operations Basically mallocs an IO structure and sets up s...
Definition: io.c:81

◆ microphone_mute_toggle()

static void microphone_mute_toggle ( struct unistimsession pte)
static

Definition at line 4457 of file chan_unistim.c.

References unistimsession::device, LED_MUTE_OFF, LED_MUTE_ON, unistim_device::microphone, MUTE_OFF, MUTE_ON, send_led_update(), and send_mute().

Referenced by process_request().

4458 {
4459  if (pte->device->microphone == MUTE_OFF) {
4460  pte->device->microphone = MUTE_ON;
4462  } else if (pte->device->microphone == MUTE_ON) {
4463  pte->device->microphone = MUTE_OFF;
4465  }
4466  send_mute(pte, (pte->device->microphone & 0x01));
4467 }
struct unistim_device * device
Definition: chan_unistim.c:476
#define MUTE_OFF
Definition: chan_unistim.c:147
#define LED_MUTE_OFF
Definition: chan_unistim.c:163
#define LED_MUTE_ON
Definition: chan_unistim.c:164
static void send_led_update(struct unistimsession *pte, unsigned char led)
#define MUTE_ON
Definition: chan_unistim.c:148
static void send_mute(struct unistimsession *pte, unsigned char mute)

◆ open_history()

static char open_history ( struct unistimsession pte,
char  way,
FILE **  f 
)
static

Definition at line 4058 of file chan_unistim.c.

References ast_config_AST_LOG_DIR, AST_CONFIG_MAX_PATH, ast_log, unistimsession::device, display_last_error(), LOG_WARNING, MAX_ENTRY_LOG, unistim_device::name, NULL, tmp(), and USTM_LOG_DIR.

Referenced by key_history(), and show_history().

4059 {
4060  char tmp[AST_CONFIG_MAX_PATH];
4061  char count;
4062 
4063  snprintf(tmp, sizeof(tmp), "%s/%s/%s-%c.csv", ast_config_AST_LOG_DIR,
4064  USTM_LOG_DIR, pte->device->name, way);
4065  *f = fopen(tmp, "r");
4066  if (!*f) {
4067  display_last_error("Unable to open history file");
4068  return 0;
4069  }
4070  if (fread(&count, 1, 1, *f) != 1) {
4071  display_last_error("Unable to read history header - display.");
4072  fclose(*f);
4073  *f = NULL;
4074  return 0;
4075  }
4076  if (count > MAX_ENTRY_LOG) {
4077  ast_log(LOG_WARNING, "Invalid count in history header of %s (%d max %d)\n", tmp,
4078  count, MAX_ENTRY_LOG);
4079  fclose(*f);
4080  *f = NULL;
4081  return 0;
4082  }
4083  return count;
4084 }
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_CONFIG_MAX_PATH
Definition: chan_unistim.c:113
#define NULL
Definition: resample.c:96
#define USTM_LOG_DIR
Definition: chan_unistim.c:87
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
#define MAX_ENTRY_LOG
Definition: chan_unistim.c:114
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
static void display_last_error(const char *sz_msg)
Definition: chan_unistim.c:889

◆ parse_bookmark()

static int parse_bookmark ( const char *  text,
struct unistim_device d 
)
static

Definition at line 6297 of file chan_unistim.c.

References ast_copy_string(), ast_log, ast_strlen_zero, ast_verb, FAV_ICON_SHARP, FAVNUM, len(), LOG_NOTICE, LOG_WARNING, unistim_device::softkeydevice, unistim_device::softkeyicon, unistim_device::softkeylabel, unistim_device::softkeynumber, and unistimdebug.

Referenced by build_device().

6298 {
6299  char line[256];
6300  char *at;
6301  char *number;
6302  char *icon;
6303  int p;
6304  int len = strlen(text);
6305 
6306  ast_copy_string(line, text, sizeof(line));
6307  /* Position specified ? */
6308  if ((len > 2) && (line[1] == '@')) {
6309  p = line[0];
6310  if ((p >= '0') && (p <= '5')) {
6311  p -= '0';
6312  } else {
6314  "Invalid position for bookmark : must be between 0 and 5\n");
6315  return 0;
6316  }
6317  if (d->softkeyicon[p] != 0) {
6318  ast_log(LOG_WARNING, "Invalid position %d for bookmark : already used:\n", p);
6319  return 0;
6320  }
6321  memmove(line, line + 2, sizeof(line) - 2);
6322  } else {
6323  /* No position specified, looking for a free slot */
6324  for (p = 0; p < FAVNUM; p++) {
6325  if (!d->softkeyicon[p]) {
6326  break;
6327  }
6328  }
6329  if (p == FAVNUM) {
6330  ast_log(LOG_WARNING, "No more free bookmark position\n");
6331  return 0;
6332  }
6333  }
6334  at = strchr(line, '@');
6335  if (!at) {
6336  ast_log(LOG_NOTICE, "Bookmark entry '%s' has no @ (at) sign!\n", text);
6337  return 0;
6338  }
6339  *at = '\0';
6340  at++;
6341  number = at;
6342  at = strchr(at, '@');
6343  if (ast_strlen_zero(number)) {
6344  ast_log(LOG_NOTICE, "Bookmark entry '%s' has no number\n", text);
6345  return 0;
6346  }
6347  if (ast_strlen_zero(line)) {
6348  ast_log(LOG_NOTICE, "Bookmark entry '%s' has no description\n", text);
6349  return 0;
6350  }
6351 
6352  at = strchr(number, '@');
6353  if (!at) {
6354  d->softkeyicon[p] = FAV_ICON_SHARP; /* default icon */
6355  } else {
6356  *at = '\0';
6357  at++;
6358  icon = at;
6359  if (ast_strlen_zero(icon)) {
6360  ast_log(LOG_NOTICE, "Bookmark entry '%s' has no icon value\n", text);
6361  return 0;
6362  }
6363  if (strncmp(icon, "USTM/", 5)) {
6364  d->softkeyicon[p] = atoi(icon);
6365  } else {
6366  d->softkeyicon[p] = 1;
6367  ast_copy_string(d->softkeydevice[p], icon + 5, sizeof(d->softkeydevice[p]));
6368  }
6369  }
6370  ast_copy_string(d->softkeylabel[p], line, sizeof(d->softkeylabel[p]));
6371  ast_copy_string(d->softkeynumber[p], number, sizeof(d->softkeynumber[p]));
6372  if (unistimdebug) {
6373  ast_verb(0, "New bookmark at pos %d label='%s' number='%s' icon=%#x\n",
6374  p, d->softkeylabel[p], d->softkeynumber[p], (unsigned)d->softkeyicon[p]);
6375  }
6376  return 1;
6377 }
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
#define FAVNUM
Definition: chan_unistim.c:216
#define LOG_WARNING
Definition: logger.h:274
#define FAV_ICON_SHARP
Definition: chan_unistim.c:196
char softkeynumber[FAVNUM][AST_MAX_EXTENSION]
Definition: chan_unistim.c:406
char * text
Definition: app_queue.c:1508
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
Number structure.
Definition: app_followme.c:154
#define ast_log
Definition: astobj2.c:42
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char softkeydevice[FAVNUM][16]
Definition: chan_unistim.c:408
char softkeyicon[FAVNUM]
Definition: chan_unistim.c:407
#define LOG_NOTICE
Definition: logger.h:263
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ parsing()

static void parsing ( int  size,
unsigned char *  buf,
struct unistimsession pte,
struct sockaddr_in *  addr_from 
)
static

Definition at line 4633 of file chan_unistim.c.

References ast_inet_ntoa(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_verb, check_send_queue(), close_client(), create_client(), unistimsession::last_seq_ack, unistimsession::lock, LOG_NOTICE, LOG_WARNING, unistimsession::nb_retransmit, packet_rcv_discovery, packet_send_discovery_ack, process_request(), send_raw_client(), send_retransmit(), seq, unistimsession::seq_phone, unistimsession::seq_server, SIZE_HEADER, unistimsession::sout, unistimsession::state, STATE_INIT, and unistimdebug.

Referenced by load_module(), unistimsock_read(), and unload_module().

4635 {
4636  unsigned short *sbuf = (unsigned short *) buf;
4637  unsigned short seq;
4638  char tmpbuf[255];
4639 
4640  strcpy(tmpbuf, ast_inet_ntoa(addr_from->sin_addr));
4641 
4642  if (size < 10) {
4643  if (size == 0) {
4644  ast_log(LOG_WARNING, "%s Read error\n", tmpbuf);
4645  } else {
4646  ast_log(LOG_NOTICE, "%s Packet too short - ignoring\n", tmpbuf);
4647  }
4648  return;
4649  }
4650  if (sbuf[0] == 0xffff) { /* Starting with 0xffff ? *//* Yes, discovery packet ? */
4651  if (size != sizeof(packet_rcv_discovery)) {
4652  ast_log(LOG_NOTICE, "%s Invalid size of a discovery packet\n", tmpbuf);
4653  } else {
4654  if (memcmp(buf, packet_rcv_discovery, sizeof(packet_rcv_discovery)) == 0) {
4655  if (unistimdebug) {
4656  ast_verb(0, "Discovery packet received - Sending Discovery ACK\n");
4657  }
4658  if (pte) { /* A session was already active for this IP ? */
4659  if (pte->state == STATE_INIT) { /* Yes, but it's a dupe */
4660  if (unistimdebug) {
4661  ast_verb(1, "Duplicated Discovery packet\n");
4662  }
4664  packet_send_discovery_ack, addr_from, &pte->sout);
4665  pte->seq_phone = (short) 0x0000; /* reset sequence number */
4666  } else { /* No, probably a reboot, phone side */
4667  close_client(pte); /* Cleanup the previous session */
4668  if (create_client(addr_from)) {
4670  packet_send_discovery_ack, addr_from, &pte->sout);
4671  }
4672  }
4673  } else {
4674  /* Creating new entry in our phone list */
4675  if ((pte = create_client(addr_from))) {
4677  packet_send_discovery_ack, addr_from, &pte->sout);
4678  }
4679  }
4680  return;
4681  }
4682  ast_log(LOG_NOTICE, "%s Invalid discovery packet\n", tmpbuf);
4683  }
4684  return;
4685  }
4686  if (!pte) {
4687  if (unistimdebug) {
4688  ast_verb(0, "%s Not a discovery packet from an unknown source : ignoring\n", tmpbuf);
4689  }
4690  return;
4691  }
4692 
4693  if (sbuf[0] != 0) { /* Starting with something else than 0x0000 ? */
4694  ast_log(LOG_NOTICE, "Unknown packet received - ignoring\n");
4695  return;
4696  }
4697  if (buf[5] != 2) {
4698  ast_log(LOG_NOTICE, "%s Wrong direction : got 0x%02hhx expected 0x02\n", tmpbuf, buf[5]);
4699  return;
4700  }
4701  seq = ntohs(sbuf[1]);
4702  if (buf[4] == 1) {
4703  ast_mutex_lock(&pte->lock);
4704  if (unistimdebug) {
4705  ast_verb(0, "ACK received for packet #0x%04x\n", (unsigned)seq);
4706  }
4707  pte->nb_retransmit = 0;
4708 
4709  if ((pte->last_seq_ack) + 1 == seq) {
4710  pte->last_seq_ack++;
4711  check_send_queue(pte);
4712  ast_mutex_unlock(&pte->lock);
4713  return;
4714  }
4715  if (pte->last_seq_ack > seq) {
4716  if (pte->last_seq_ack == 0xffff) {
4717  ast_verb(0, "ACK at 0xffff, restarting counter.\n");
4718  pte->last_seq_ack = 0;
4719  } else {
4721  "%s Warning : ACK received for an already ACKed packet : #0x%04x we are at #0x%04x\n",
4722  tmpbuf, (unsigned)seq, (unsigned)pte->last_seq_ack);
4723  }
4724  ast_mutex_unlock(&pte->lock);
4725  return;
4726  }
4727  if (pte->seq_server < seq) {
4729  "%s Error : ACK received for a non-existent packet : #0x%04x\n",
4730  tmpbuf, (unsigned)pte->seq_server);
4731  ast_mutex_unlock(&pte->lock);
4732  return;
4733  }
4734  if (unistimdebug) {
4735  ast_verb(0, "%s ACK gap : Received ACK #0x%04x, previous was #0x%04x\n",
4736  tmpbuf, (unsigned)seq, (unsigned)pte->last_seq_ack);
4737  }
4738  pte->last_seq_ack = seq;
4739  check_send_queue(pte);
4740  ast_mutex_unlock(&pte->lock);
4741  return;
4742  }
4743  if (buf[4] == 2) {
4744  if (unistimdebug) {
4745  ast_verb(0, "Request received\n");
4746  }
4747  if (pte->seq_phone == seq) {
4748  /* Send ACK */
4749  buf[4] = 1;
4750  buf[5] = 1;
4751  send_raw_client(SIZE_HEADER, buf, addr_from, &pte->sout);
4752  pte->seq_phone++;
4753 
4754  process_request(size, buf, pte);
4755  return;
4756  }
4757  if (pte->seq_phone > seq) {
4759  "%s Warning : received a retransmitted packet : #0x%04x (we are at #0x%04x)\n",
4760  tmpbuf, (unsigned)seq, (unsigned)pte->seq_phone);
4761  /* BUG ? pte->device->seq_phone = seq; */
4762  /* Send ACK */
4763  buf[4] = 1;
4764  buf[5] = 1;
4765  send_raw_client(SIZE_HEADER, buf, addr_from, &pte->sout);
4766  return;
4767  }
4769  "%s Warning : we lost a packet : received #0x%04x (we are at #0x%04x)\n",
4770  tmpbuf, (unsigned)seq, (unsigned)pte->seq_phone);
4771  return;
4772  }
4773  if (buf[4] == 0) {
4774  ast_log(LOG_NOTICE, "%s Retransmit request for packet #0x%04x\n", tmpbuf, (unsigned)seq);
4775  if (pte->last_seq_ack > seq) {
4777  "%s Error : received a request for an already ACKed packet : #0x%04x\n",
4778  tmpbuf, (unsigned)pte->last_seq_ack);
4779  return;
4780  }
4781  if (pte->seq_server < seq) {
4783  "%s Error : received a request for a non-existent packet : #0x%04x\n",
4784  tmpbuf, (unsigned)pte->seq_server);
4785  return;
4786  }
4787  send_retransmit(pte);
4788  return;
4789  }
4790  ast_log(LOG_NOTICE, "%s Unknown request : got 0x%02hhx expected 0x00,0x01 or 0x02\n", tmpbuf, buf[4]);
4791  return;
4792 }
struct sockaddr_in sout
Definition: chan_unistim.c:461
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static void check_send_queue(struct unistimsession *pte)
#define LOG_WARNING
Definition: logger.h:274
static int send_retransmit(struct unistimsession *pte)
unsigned short seq_server
Definition: chan_unistim.c:464
#define ast_mutex_lock(a)
Definition: lock.h:187
static void close_client(struct unistimsession *s)
#define ast_verb(level,...)
Definition: logger.h:463
ast_mutex_t lock
Definition: chan_unistim.c:459
unsigned short last_seq_ack
Definition: chan_unistim.c:465
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_log
Definition: astobj2.c:42
#define SIZE_HEADER
Definition: chan_unistim.c:167
static struct unistimsession * create_client(const struct sockaddr_in *addr_from)
#define LOG_NOTICE
Definition: logger.h:263
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
unsigned short seq_phone
Definition: chan_unistim.c:463
static volatile unsigned int seq
Definition: app_sms.c:120
static void process_request(int size, unsigned char *buf, struct unistimsession *pte)
static const unsigned char packet_rcv_discovery[]
Definition: chan_unistim.c:506
static const unsigned char packet_send_discovery_ack[]
Definition: chan_unistim.c:508
#define ast_mutex_unlock(a)
Definition: lock.h:188
static void send_raw_client(int size, const unsigned char *data, struct sockaddr_in *addr_to, const struct sockaddr_in *addr_ourip)
Definition: chan_unistim.c:903

◆ process_request()

static void process_request ( int  size,
unsigned char *  buf,
struct unistimsession pte 
)
static

Definition at line 4469 of file chan_unistim.c.

References ast_copy_string(), ast_debug, ast_inet_ntoa(), ast_log, ast_verb, close_call(), unistimsession::device, unistimsession::firmware, get_avail_softkey(), handle_call_incoming(), handle_dial_page(), unistim_device::height, init_phone_step2(), key_call(), key_dial_page(), key_history(), key_main_page(), KEY_MUTE, key_ringing(), key_select_codec(), key_select_extension(), key_select_language(), key_select_option(), LOG_WARNING, microphone_mute_toggle(), MUTE_OFF, unistim_device::nextdial, NULL, unistim_device::output, OUTPUT_HANDSET, OUTPUT_HEADPHONE, OUTPUT_SPEAKER, packet_recv_expansion_pressed_key, packet_recv_firm_version, packet_recv_hangup, packet_recv_it_type, packet_recv_mac_addr, packet_recv_pick_up, packet_recv_pressed_key, packet_recv_r2, packet_recv_resume_connection_with_server, ptestate_tostr(), rcv_mac_addr(), rcv_resume_connection_with_server(), unistim_device::receiver_state, unistim_device::selected, send_select_output(), show_main_page(), unistimsession::sin, SIZE_HEADER, unistimsession::state, STATE_AUTHDENY, STATE_CALL, STATE_DIALPAGE, STATE_EXTENSION, STATE_HISTORY, STATE_INIT, STATE_MAINPAGE, STATE_OFFHOOK, STATE_ONHOOK, STATE_RINGING, STATE_SELECTCODEC, STATE_SELECTLANGUAGE, STATE_SELECTOPTION, type, unistimdebug, and unistim_device::volume.

Referenced by parsing().

4470 {
4471  char tmpbuf[255];
4472  if (memcmp
4476  return;
4477  }
4478  if (memcmp(buf + SIZE_HEADER, packet_recv_firm_version, sizeof(packet_recv_firm_version)) == 0) {
4479  buf[size] = 0;
4480  if (unistimdebug) {
4481  ast_verb(0, "Got the firmware version : '%s'\n", buf + 13);
4482  }
4483  ast_copy_string(pte->firmware, (char *) (buf + 13), sizeof(pte->firmware));
4484  init_phone_step2(pte);
4485  return;
4486  }
4487  if (memcmp(buf + SIZE_HEADER, packet_recv_it_type, sizeof(packet_recv_it_type)) == 0) {
4488  char type = buf[13];
4489  if (unistimdebug) {
4490  ast_verb(0, "Got the equipment type: '%d'\n", type);
4491  }
4492  switch (type) {
4493  case 0x03: /* i2002 */
4494  if (pte->device) {
4495  pte->device->height = 1;
4496  }
4497  break;
4498  }
4499  return;
4500  }
4501  if (memcmp(buf + SIZE_HEADER, packet_recv_mac_addr, sizeof(packet_recv_mac_addr)) == 0) {
4502  rcv_mac_addr(pte, buf);
4503  return;
4504  }
4505  if (memcmp(buf + SIZE_HEADER, packet_recv_r2, sizeof(packet_recv_r2)) == 0) {
4506  if (unistimdebug) {
4507  ast_verb(0, "R2 received\n");
4508  }
4509  return;
4510  }
4511 
4512  if (pte->state < STATE_MAINPAGE) {
4513  if (unistimdebug) {
4514  ast_verb(0, "Request not authorized in this state\n");
4515  }
4516  return;
4517  }
4519  char keycode = buf[13];
4520 
4521  if (unistimdebug) {
4522  ast_verb(0, "Expansion key pressed: keycode = 0x%02hhx - current state: %s\n", (unsigned char)keycode,
4523  ptestate_tostr(pte->state));
4524  }
4525  }
4527  char keycode = buf[13];
4528 
4529  if (unistimdebug) {
4530  ast_verb(0, "Key pressed: keycode = 0x%02hhx - current state: %s\n", (unsigned char)keycode,
4531  ptestate_tostr(pte->state));
4532  }
4533  if (keycode == KEY_MUTE) {
4535  }
4536  switch (pte->state) {
4537  case STATE_INIT:
4538  if (unistimdebug) {
4539  ast_verb(0, "No keys allowed in the init state\n");
4540  }
4541  break;
4542  case STATE_AUTHDENY:
4543  if (unistimdebug) {
4544  ast_verb(0, "No keys allowed in authdeny state\n");
4545  }
4546  break;
4547  case STATE_MAINPAGE:
4548  key_main_page(pte, keycode);
4549  break;
4550  case STATE_DIALPAGE:
4551  key_dial_page(pte, keycode);
4552  break;
4553  case STATE_RINGING:
4554  key_ringing(pte, keycode);
4555  break;
4556  case STATE_CALL:
4557  key_call(pte, keycode);
4558  break;
4559  case STATE_EXTENSION:
4560  key_select_extension(pte, keycode);
4561  break;
4562  case STATE_SELECTOPTION:
4563  key_select_option(pte, keycode);
4564  break;
4565  case STATE_SELECTCODEC:
4566  key_select_codec(pte, keycode);
4567  break;
4568  case STATE_SELECTLANGUAGE:
4569  key_select_language(pte, keycode);
4570  break;
4571  case STATE_HISTORY:
4572  key_history(pte, keycode);
4573  break;
4574  default:
4575  ast_log(LOG_WARNING, "Key : Unknown state\n");
4576  }
4577  return;
4578  }
4579  if (memcmp(buf + SIZE_HEADER, packet_recv_pick_up, sizeof(packet_recv_pick_up)) == 0) {
4580  if (unistimdebug) {
4581  ast_verb(0, "Handset off hook, current state: %s\n", ptestate_tostr(pte->state));
4582  }
4583  if (!pte->device) { /* We are not yet registered (asking for a TN in AUTOPROVISIONING_TN) */
4584  return;
4585  }
4587  if (pte->device->output == OUTPUT_HEADPHONE) {
4589  } else {
4591  }
4592  if (pte->state == STATE_RINGING) {
4593  handle_call_incoming(pte);
4594  } else if ((pte->state == STATE_DIALPAGE) || (pte->state == STATE_CALL)) {
4596  } else if (pte->state == STATE_EXTENSION) { /* We must have a TN before calling */
4597  return;
4598  } else {
4599  pte->device->selected = get_avail_softkey(pte, NULL);
4601  handle_dial_page(pte);
4602  }
4603  return;
4604  }
4605  if (memcmp(buf + SIZE_HEADER, packet_recv_hangup, sizeof(packet_recv_hangup)) == 0) {
4606  if (unistimdebug) {
4607  ast_verb(0, "Handset on hook, current state: %s\n", ptestate_tostr(pte->state));
4608  }
4609  if (!pte->device) {
4610  return;
4611  }
4613  if (pte->state == STATE_CALL) {
4614  if (pte->device->output != OUTPUT_SPEAKER) {
4615  close_call(pte);
4616  }
4617  } else if (pte->state == STATE_EXTENSION) {
4618  return;
4619  } else {
4620  pte->device->nextdial = 0;
4621  show_main_page(pte);
4622  }
4623  return;
4624  }
4625  strcpy(tmpbuf, ast_inet_ntoa(pte->sin.sin_addr));
4626  strcat(tmpbuf, " Unknown request packet\n");
4627  if (unistimdebug) {
4628  ast_debug(1, "%s", tmpbuf);
4629  }
4630  return;
4631 }
static void rcv_mac_addr(struct unistimsession *pte, const unsigned char *buf)
static const char type[]
Definition: chan_ooh323.c:109
static void rcv_resume_connection_with_server(struct unistimsession *pte)
char firmware[8]
Definition: chan_unistim.c:473
static const unsigned char packet_recv_it_type[]
Definition: chan_unistim.c:513
static void key_select_language(struct unistimsession *pte, char keycode)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
static const unsigned char packet_recv_pick_up[]
Definition: chan_unistim.c:517
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
static void key_main_page(struct unistimsession *pte, char keycode)
static void close_call(struct unistimsession *pte)
static void microphone_mute_toggle(struct unistimsession *pte)
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
#define MUTE_OFF
Definition: chan_unistim.c:147
static const unsigned char packet_recv_firm_version[]
Definition: chan_unistim.c:511
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define OUTPUT_HEADPHONE
Definition: chan_unistim.c:139
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
#define SIZE_HEADER
Definition: chan_unistim.c:167
static void key_select_extension(struct unistimsession *pte, char keycode)
static int get_avail_softkey(struct unistimsession *pte, const char *name)
static void handle_dial_page(struct unistimsession *pte)
static void key_select_option(struct unistimsession *pte, char keycode)
static const unsigned char packet_recv_resume_connection_with_server[]
Definition: chan_unistim.c:533
static const unsigned char packet_recv_hangup[]
Definition: chan_unistim.c:519
static void show_main_page(struct unistimsession *pte)
static const unsigned char packet_recv_pressed_key[]
Definition: chan_unistim.c:515
static void key_history(struct unistimsession *pte, char keycode)
static const char * ptestate_tostr(const int type)
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
static const unsigned char packet_recv_expansion_pressed_key[]
Definition: chan_unistim.c:524
struct sockaddr_in sin
Definition: chan_unistim.c:460
static void key_select_codec(struct unistimsession *pte, char keycode)
static void key_call(struct unistimsession *pte, char keycode)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
static const unsigned char packet_recv_mac_addr[]
Definition: chan_unistim.c:535
static void handle_call_incoming(struct unistimsession *s)
static void key_ringing(struct unistimsession *pte, char keycode)
static void key_dial_page(struct unistimsession *pte, char keycode)
static void init_phone_step2(struct unistimsession *pte)
static const unsigned char packet_recv_r2[]
Definition: chan_unistim.c:521

◆ ptestate_tostr()

static const char* ptestate_tostr ( const int  type)
static

Definition at line 2040 of file chan_unistim.c.

References STATE_AUTHDENY, STATE_CALL, STATE_CLEANING, STATE_DIALPAGE, STATE_EXTENSION, STATE_HISTORY, STATE_INIT, STATE_MAINPAGE, STATE_RINGING, STATE_SELECTCODEC, STATE_SELECTLANGUAGE, and STATE_SELECTOPTION.

Referenced by process_request(), unistim_hangup(), and unistim_show_info().

2041 {
2042  switch (type) {
2043  case STATE_INIT:
2044  return "INIT";
2045  case STATE_AUTHDENY:
2046  return "AUTHDENY";
2047  case STATE_MAINPAGE:
2048  return "MAINPAGE";
2049  case STATE_EXTENSION:
2050  return "EXTENSION";
2051  case STATE_DIALPAGE:
2052  return "DIALPAGE";
2053  case STATE_RINGING:
2054  return "RINGING";
2055  case STATE_CALL:
2056  return "CALL";
2057  case STATE_SELECTOPTION:
2058  return "SELECTOPTION";
2059  case STATE_SELECTCODEC:
2060  return "SELECTCODEC";
2061  case STATE_SELECTLANGUAGE:
2062  return "SELECTLANGUAGE";
2063  case STATE_CLEANING:
2064  return "CLEARING";
2065  case STATE_HISTORY:
2066  return "HISTORY";
2067  }
2068  return "UNKNOWN";
2069 }
static const char type[]
Definition: chan_ooh323.c:109

◆ rcv_mac_addr()

static void rcv_mac_addr ( struct unistimsession pte,
const unsigned char *  buf 
)
static

Definition at line 2071 of file chan_unistim.c.

References ast_copy_string(), ast_free, AST_LIST_FIRST, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log, ast_malloc, ast_mutex_init, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, ast_verb, autoprovisioning, AUTOPROVISIONING_NO, AUTOPROVISIONING_TN, AUTOPROVISIONING_YES, BUFFSEND, d, unistimsession::device, devicelock, devices, unistim_device::extension, EXTENSION_ASK, EXTENSION_LINE, EXTENSION_NONE, unistim_device::extension_number, EXTENSION_TN, unistim_line::fullname, unistim_device::lines, unistim_subchannel::list, unistim_line::list, LOG_ERROR, LOG_WARNING, unistimsession::macaddr, unistim_line::name, unistim_device::name, unistim_device::next, unistimsession::next, NULL, packet_send_query_basic_manager_04, packet_send_query_basic_manager_10, packet_send_S1, unistim_line::parent, register_extension(), send_client(), send_date_time(), SIZE_HEADER, unistimsession::state, STATE_AUTHDENY, STATE_EXTENSION, STATE_MAINPAGE, STATE_ONHOOK, sub, unistim_device::subs, tmp(), unistim_line_alloc(), unistim_line_copy(), unistim_register(), and unistimdebug.

Referenced by process_request().

2072 {
2073  BUFFSEND;
2074  int tmp, i = 0;
2075  char addrmac[19];
2076  int res = 0;
2077  for (tmp = 15; tmp < 15 + SIZE_HEADER; tmp++) {
2078  sprintf(&addrmac[i], "%02hhx", buf[tmp]);
2079  i += 2;
2080  }
2081  if (unistimdebug) {
2082  ast_verb(0, "MAC Address received: %s\n", addrmac);
2083  }
2084  strcpy(pte->macaddr, addrmac);
2085  res = unistim_register(pte);
2086  if (!res) {
2087  switch (autoprovisioning) {
2088  case AUTOPROVISIONING_NO:
2089  ast_log(LOG_WARNING, "No entry found for this phone : %s\n", addrmac);
2090  pte->state = STATE_AUTHDENY;
2091  break;
2092  case AUTOPROVISIONING_YES:
2093  {
2094  struct unistim_device *d = NULL, *newd = NULL;
2095  struct unistim_line *newl = NULL, *l = NULL;
2096  if (unistimdebug) {
2097  ast_verb(0, "New phone, autoprovisioning on\n");
2098  }
2099  /* First : locate the [template] section */
2101  d = devices;
2102  while (d) {
2103  if (strcasecmp(d->name, "template")) {
2104  d = d->next;
2105  continue;
2106  }
2107  /* Found, cloning this entry */
2108  if (!(newd = ast_malloc(sizeof(*newd)))) {
2110  return;
2111  }
2112  memcpy(newd, d, sizeof(*newd));
2113  ast_mutex_init(&newd->lock);
2114  newd->lines.first = NULL;
2115  newd->lines.last = NULL;
2116  AST_LIST_LOCK(&d->lines);
2117  AST_LIST_TRAVERSE(&d->lines, l, list) {
2118  if (!(newl = unistim_line_alloc())) {
2119  break;
2120  }
2121  unistim_line_copy(l, newl);
2122  newl->parent = newd;
2123  ast_copy_string(newl->name, l->name, sizeof(newl->name));
2124  snprintf(newl->fullname, sizeof(newl->fullname), "USTM/%s@%s",
2125  newl->name, newd->name);
2126  snprintf(l->name, sizeof(l->name), "%d", atoi(l->name) + 1);
2127 
2128  AST_LIST_LOCK(&newd->lines);
2129  AST_LIST_INSERT_TAIL(&newd->lines, newl, list);
2130  AST_LIST_UNLOCK(&newd->lines);
2131  }
2132  AST_LIST_UNLOCK(&d->lines);
2133  if (!newl) {
2134  ast_free(newd);
2136  }
2137 
2138  /* Ok, now updating some fields */
2139  ast_copy_string(newd->id, addrmac, sizeof(newd->id));
2140  ast_copy_string(newd->name, addrmac, sizeof(newd->name));
2141  if (newd->extension == EXTENSION_NONE) {
2142  newd->extension = EXTENSION_ASK;
2143  }
2144 
2145  newd->receiver_state = STATE_ONHOOK;
2146  newd->session = pte;
2147  newd->language[0] = '\0';
2148  newd->to_delete = -1;
2149  newd->next = NULL;
2150  pte->device = newd;
2151 
2152  /* Go to the end of the linked chain */
2153  while (d->next) {
2154  d = d->next;
2155  }
2156  d->next = newd;
2157  d = newd;
2158  break;
2159  }
2161  if (!d) {
2162  ast_log(LOG_WARNING, "No entry [template] found in unistim.conf\n");
2163  pte->state = STATE_AUTHDENY;
2164  }
2165  }
2166  break;
2167  case AUTOPROVISIONING_TN:
2168  pte->state = STATE_AUTHDENY;
2169  break;
2170  default:
2171  ast_log(LOG_WARNING, "Internal error : unknown autoprovisioning value = %u\n",
2173  }
2174  }
2175  if (pte->state != STATE_AUTHDENY) {
2176  struct unistim_line *line;
2177  struct unistim_subchannel *sub;
2178 
2179  ast_verb(3, "Device '%s' successfuly registered\n", pte->device->name);
2180 
2181  AST_LIST_LOCK(&pte->device->subs);
2183  if (sub) {
2184  ast_log(LOG_ERROR, "Subchannel lost sice reboot. Hanged channel may apear!\n");
2186  ast_free(sub);
2187  }
2188  }
2190  AST_LIST_UNLOCK(&pte->device->subs);
2191 
2192  switch (pte->device->extension) {
2193  case EXTENSION_NONE:
2194  pte->state = STATE_MAINPAGE;
2195  break;
2196  case EXTENSION_ASK:
2197  /* Checking if we already have an extension number */
2199  pte->state = STATE_EXTENSION;
2200  } else {
2201  /* Yes, because of a phone reboot. We don't ask again for the TN */
2202  if (register_extension(pte)) {
2203  pte->state = STATE_EXTENSION;
2204  } else {
2205  pte->state = STATE_MAINPAGE;
2206  }
2207  }
2208  break;
2209  case EXTENSION_LINE:
2210  line = AST_LIST_FIRST(&pte->device->lines);
2212  sizeof(pte->device->extension_number));
2213  if (register_extension(pte)) {
2214  pte->state = STATE_EXTENSION;
2215  } else {
2216  pte->state = STATE_MAINPAGE;
2217  }
2218  break;
2219  case EXTENSION_TN:
2220  /* If we are here, it's because of a phone reboot */
2221  pte->state = STATE_MAINPAGE;
2222  break;
2223  default:
2224  ast_log(LOG_WARNING, "Internal error, extension value unknown : %u\n",
2225  pte->device->extension);
2226  pte->state = STATE_AUTHDENY;
2227  break;
2228  }
2229  }
2230  if (pte->state == STATE_EXTENSION) {
2231  if (pte->device->extension != EXTENSION_TN) {
2232  pte->device->extension = EXTENSION_ASK;
2233  }
2234  pte->device->extension_number[0] = '\0';
2235  }
2236  if (unistimdebug) {
2237  ast_verb(0, "\nSending S1\n");
2238  }
2239  memcpy(buffsend + SIZE_HEADER, packet_send_S1, sizeof(packet_send_S1));
2240  send_client(SIZE_HEADER + sizeof(packet_send_S1), buffsend, pte);
2241 
2242  if (unistimdebug) {
2243  ast_verb(0, "Sending query_basic_manager_04\n");
2244  }
2245  memcpy(buffsend + SIZE_HEADER, packet_send_query_basic_manager_04,
2247  send_client(SIZE_HEADER + sizeof(packet_send_query_basic_manager_04), buffsend, pte);
2248 
2249  if (unistimdebug) {
2250  ast_verb(0, "Sending query_basic_manager_10\n");
2251  }
2252  memcpy(buffsend + SIZE_HEADER, packet_send_query_basic_manager_10,
2254  send_client(SIZE_HEADER + sizeof(packet_send_query_basic_manager_10), buffsend, pte);
2255 
2256  send_date_time(pte);
2257  return;
2258 }
static const unsigned char packet_send_query_basic_manager_10[]
Definition: chan_unistim.c:698
struct unistim_device::@152 subs
static const unsigned char packet_send_S1[]
Definition: chan_unistim.c:699
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
struct unistim_line::@151 list
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
static struct unistim_line * unistim_line_alloc(void)
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
struct unistim_device::@153 lines
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static struct test_val d
static int tmp()
Definition: bt_open.c:389
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
static void unistim_line_copy(struct unistim_line *dst, struct unistim_line *src)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define ast_verb(level,...)
Definition: logger.h:463
static int unistim_register(struct unistimsession *s)
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
struct unistimsession * next
Definition: chan_unistim.c:477
char name[80]
Definition: chan_unistim.c:374
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
char macaddr[18]
Definition: chan_unistim.c:472
#define ast_log
Definition: astobj2.c:42
struct unistim_device * next
Definition: chan_unistim.c:455
#define SIZE_HEADER
Definition: chan_unistim.c:167
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static const unsigned char packet_send_query_basic_manager_04[]
Definition: chan_unistim.c:696
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
enum autoprov_extn extension
Definition: chan_unistim.c:447
#define LOG_ERROR
Definition: logger.h:285
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
static int register_extension(const struct unistimsession *pte)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_free(a)
Definition: astmm.h:182
static struct unistim_device * devices
struct unistim_subchannel::@150 list
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char fullname[101]
Definition: chan_unistim.c:375
static enum autoprovision autoprovisioning
Definition: chan_unistim.c:245
static void send_date_time(struct unistimsession *pte)
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
#define ast_mutex_init(pmutex)
Definition: lock.h:184
char extension_number[11]
Definition: chan_unistim.c:448
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ rcv_resume_connection_with_server()

static void rcv_resume_connection_with_server ( struct unistimsession pte)
static

Definition at line 1907 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_query_mac_address, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by process_request().

1908 {
1909  BUFFSEND;
1910  if (unistimdebug) {
1911  ast_verb(0, "ResumeConnectionWithServer received\n");
1912  ast_verb(0, "Sending packet_send_query_mac_address\n");
1913  }
1914  memcpy(buffsend + SIZE_HEADER, packet_send_query_mac_address,
1916  send_client(SIZE_HEADER + sizeof(packet_send_query_mac_address), buffsend, pte);
1917  return;
1918 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
static const unsigned char packet_send_query_mac_address[]
Definition: chan_unistim.c:697
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167

◆ refresh_all_favorite()

static void refresh_all_favorite ( struct unistimsession pte)
static

Definition at line 1321 of file chan_unistim.c.

References ast_db_get(), AST_LIST_FIRST, ast_verb, unistimsession::device, EXPNUM, FAV_ICON_NONE, FAV_ICON_SPEAKER_ONHOOK_WHITE, FAVNUM, unistim_device::hasexp, unistim_device::lines, unistim_line::name, send_expansion_short(), send_favorite_short(), soft_key_visible(), unistim_device::softkeyicon, unistim_device::softkeylabel, status, and unistimdebug.

Referenced by init_phone_step2(), key_select_extension(), key_select_language(), and reload_config().

1322 {
1323  unsigned char i = 0;
1324  char data[256];
1325  struct unistim_line *line;
1326  line = AST_LIST_FIRST(&pte->device->lines);
1327 
1328  if (unistimdebug) {
1329  ast_verb(0, "Refreshing all favorite\n");
1330  }
1331  for (i = 0; i < FAVNUM; i++) {
1332  unsigned char status = pte->device->softkeyicon[i];
1333 
1334  if (!soft_key_visible(pte->device, i)) {
1335  continue;
1336  }
1337  if (!strcasecmp(pte->device->softkeylabel[i], "DND") && line) {
1338  if (!ast_db_get("DND", line->name, data, sizeof(data))) {
1340  }
1341  }
1342 
1343  send_favorite_short(i, status, pte);
1344  }
1345  if (pte->device->hasexp) {
1346  for (i = 0; i < EXPNUM; i++) {
1348  }
1349  }
1350 }
static int soft_key_visible(struct unistim_device *d, unsigned char num)
#define FAV_ICON_SPEAKER_ONHOOK_WHITE
Definition: chan_unistim.c:181
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
struct unistim_device::@153 lines
#define FAVNUM
Definition: chan_unistim.c:216
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
char name[80]
Definition: chan_unistim.c:374
#define FAV_ICON_NONE
Definition: chan_unistim.c:177
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
char softkeyicon[FAVNUM]
Definition: chan_unistim.c:407
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:412
#define EXPNUM
Definition: chan_unistim.c:217
static void send_expansion_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
jack_status_t status
Definition: app_jack.c:146

◆ register_extension()

static int register_extension ( const struct unistimsession pte)
static

Definition at line 1445 of file chan_unistim.c.

References ast_add_extension(), AST_LIST_FIRST, ast_verb, unistim_device::context, unistimsession::device, unistim_device::extension_number, unistim_line::fullname, unistim_device::lines, NULL, and unistimdebug.

Referenced by key_select_extension(), and rcv_mac_addr().

1446 {
1447  struct unistim_line *line;
1448  line = AST_LIST_FIRST(&pte->device->lines);
1449  if (unistimdebug) {
1450  ast_verb(0, "Trying to register extension '%s' into context '%s' to %s\n",
1451  pte->device->extension_number, pte->device->context,
1452  line->fullname);
1453  }
1454  return ast_add_extension(pte->device->context, 0,
1455  pte->device->extension_number, 1, NULL, NULL, "Dial",
1456  line->fullname, 0, "Unistim");
1457 }
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
struct unistim_device::@153 lines
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
char context[AST_MAX_EXTENSION]
Definition: chan_unistim.c:398
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
Definition: pbx.c:6970
char fullname[101]
Definition: chan_unistim.c:375
char extension_number[11]
Definition: chan_unistim.c:448

◆ reload()

int reload ( void  )
static

reload: Part of Asterisk module interface —

Definition at line 7187 of file chan_unistim.c.

References AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_SUPPORT_EXTENDED, ast_mutex_lock, ast_mutex_unlock, ast_verb, ASTERISK_GPL_KEY, load_module(), restart_monitor(), unistim_reload_lock, unistim_reloading, unistimdebug, and unload_module().

Referenced by unistim_reload().

7188 {
7189  if (unistimdebug) {
7190  ast_verb(0, "reload unistim\n");
7191  }
7193  if (!unistim_reloading) {
7194  unistim_reloading = 1;
7195  }
7197 
7198  restart_monitor();
7199 
7200  return 0;
7201 }
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
static int unistim_reloading
Definition: chan_unistim.c:260
static int restart_monitor(void)
static ast_mutex_t unistim_reload_lock
Definition: chan_unistim.c:261
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ reload_config()

static int reload_config ( void  )
static

Definition at line 6846 of file chan_unistim.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load, ast_gethostbyname(), ast_inet_ntoa(), ast_jb_read_conf(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_set_qos(), ast_str2cos(), ast_str2tos(), ast_strlen_zero, ast_variable_browse(), ast_verb, autoprovisioning, AUTOPROVISIONING_NO, AUTOPROVISIONING_TN, AUTOPROVISIONING_YES, build_device(), config, CONFIG_STATUS_FILEINVALID, d, delete_device(), unistimsession::device, devicelock, devices, errno, find_language(), finish_bookmark(), global_jbconf, hp, unistim_device::language, ast_variable::lineno, LOG_ERROR, LOG_WARNING, ast_variable::name, NB_MAX_RETRANSMIT, ast_variable::next, unistim_device::next, unistimsession::next, NULL, packet_send_ping, public_ip, qos, refresh_all_favorite(), RETRANSMIT_TIMER, send_charset_update(), sessionlock, sessions, unistim_device::to_delete, unistim_keepalive, unistim_port, unistimdebug, unistimsock, and ast_variable::value.

Referenced by do_monitor(), and load_module().

6847 {
6848  struct ast_config *cfg;
6849  struct ast_variable *v;
6850  struct ast_hostent ahp;
6851  struct hostent *hp;
6852  struct sockaddr_in bindaddr = { 0, };
6853  char *config = "unistim.conf";
6854  char *cat;
6855  struct unistim_device *d;
6856  const int reuseFlag = 1;
6857  struct unistimsession *s;
6858  struct ast_flags config_flags = { 0, };
6859 
6860  cfg = ast_config_load(config, config_flags);
6861  /* We *must* have a config file otherwise stop immediately */
6862  if (!cfg) {
6863  ast_log(LOG_ERROR, "Unable to load config %s\n", config);
6864  return -1;
6865  } else if (cfg == CONFIG_STATUS_FILEINVALID) {
6866  ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", config);
6867  return -1;
6868  }
6869 
6870  /* Copy the default jb config over global_jbconf */
6871  memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
6872 
6873  unistim_keepalive = 120;
6874  unistim_port = 0;
6875  v = ast_variable_browse(cfg, "general");
6876  while (v) {
6877  /* handle jb conf */
6878  if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) {
6879  continue;
6880  }
6881  if (!strcasecmp(v->name, "keepalive")) {
6882  unistim_keepalive = atoi(v->value);
6883  } else if (!strcasecmp(v->name, "port")) {
6884  unistim_port = atoi(v->value);
6885  } else if (!strcasecmp(v->name, "tos")) {
6886  if (ast_str2tos(v->value, &qos.tos)) {
6887  ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
6888  }
6889  } else if (!strcasecmp(v->name, "tos_audio")) {
6890  if (ast_str2tos(v->value, &qos.tos_audio)) {
6891  ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, refer to QoS documentation\n", v->lineno);
6892  }
6893  } else if (!strcasecmp(v->name, "cos")) {
6894  if (ast_str2cos(v->value, &qos.cos)) {
6895  ast_log(LOG_WARNING, "Invalid cos value at line %d, refer to QoS documentation\n", v->lineno);
6896  }
6897  } else if (!strcasecmp(v->name, "cos_audio")) {
6898  if (ast_str2cos(v->value, &qos.cos_audio)) {
6899  ast_log(LOG_WARNING, "Invalid cos_audio value at line %d, refer to QoS documentation\n", v->lineno);
6900  }
6901  } else if (!strcasecmp(v->name, "debug")) {
6902  if (!strcasecmp(v->value, "no")) {
6903  unistimdebug = 0;
6904  } else if (!strcasecmp(v->value, "yes")) {
6905  unistimdebug = 1;
6906  }
6907  } else if (!strcasecmp(v->name, "autoprovisioning")) {
6908  if (!strcasecmp(v->value, "no")) {
6910  } else if (!strcasecmp(v->value, "yes")) {
6912  } else if (!strcasecmp(v->value, "tn")) {
6914  } else {
6915  ast_log(LOG_WARNING, "Unknown autoprovisioning option.\n");
6916  }
6917  } else if (!strcasecmp(v->name, "public_ip")) {
6918  if (!ast_strlen_zero(v->value)) {
6919  if (!(hp = ast_gethostbyname(v->value, &ahp))) {
6920  ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
6921  } else {
6922  memcpy(&public_ip.sin_addr, hp->h_addr, sizeof(public_ip.sin_addr));
6923  public_ip.sin_family = AF_INET;
6924  }
6925  }
6926  }
6927  v = v->next;
6928  }
6929  if ((unistim_keepalive < 10) ||
6931  255 - (((NB_MAX_RETRANSMIT + 1) * RETRANSMIT_TIMER) / 1000))) {
6932  ast_log(LOG_ERROR, "keepalive is invalid in %s\n", config);
6933  ast_config_destroy(cfg);
6934  return -1;
6935  }
6936  packet_send_ping[4] =
6938  if ((unistim_port < 1) || (unistim_port > 65535)) {
6939  ast_log(LOG_ERROR, "port is not set or invalid in %s\n", config);
6940  ast_config_destroy(cfg);
6941  return -1;
6942  }
6943  unistim_keepalive *= 1000;
6944 
6946  d = devices;
6947  while (d) {
6948  if (d->to_delete >= 0) {
6949  d->to_delete = 1;
6950  }
6951  d = d->next;
6952  }
6954  /* load the device sections */
6955  cat = ast_category_browse(cfg, NULL);
6956  while (cat) {
6957  if (strcasecmp(cat, "general")) {
6958  d = build_device(cat, ast_variable_browse(cfg, cat));
6959  }
6960  cat = ast_category_browse(cfg, cat);
6961  }
6963  d = devices;
6964  while (d) {
6965  if (d->to_delete) {
6966  delete_device(d);
6967  d = devices;
6968  continue;
6969  }
6970  d = d->next;
6971  }
6972  finish_bookmark();
6974  ast_config_destroy(cfg);
6976  s = sessions;
6977  while (s) {
6978  if (s->device) {
6980  if (ast_strlen_zero(s->device->language)) {
6981  struct unistim_languages lang;
6983  send_charset_update(s, lang.encoding);
6984  }
6985  }
6986  s = s->next;
6987  }
6989  /* We don't recreate a socket when reloading (locks would be necessary). */
6990  if (unistimsock > -1) {
6991  return 0;
6992  }
6993  bindaddr.sin_addr.s_addr = INADDR_ANY;
6994  bindaddr.sin_port = htons(unistim_port);
6995  bindaddr.sin_family = AF_INET;
6996  unistimsock = socket(AF_INET, SOCK_DGRAM, 0);
6997  if (unistimsock < 0) {
6998  ast_log(LOG_WARNING, "Unable to create UNISTIM socket: %s\n", strerror(errno));
6999  return -1;
7000  }
7001 #ifdef HAVE_PKTINFO
7002  {
7003  const int pktinfoFlag = 1;
7004  setsockopt(unistimsock, IPPROTO_IP, IP_PKTINFO, &pktinfoFlag,
7005  sizeof(pktinfoFlag));
7006  }
7007 #else
7008  if (public_ip.sin_family == 0) {
7010  "Your OS does not support IP_PKTINFO, you must set public_ip.\n");
7011  unistimsock = -1;
7012  return -1;
7013  }
7014 #endif
7015  setsockopt(unistimsock, SOL_SOCKET, SO_REUSEADDR, (const char *) &reuseFlag,
7016  sizeof(reuseFlag));
7017  if (bind(unistimsock, (struct sockaddr *) &bindaddr, sizeof(bindaddr)) < 0) {
7018  ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n",
7019  ast_inet_ntoa(bindaddr.sin_addr), htons(bindaddr.sin_port),
7020  strerror(errno));
7021  close(unistimsock);
7022  unistimsock = -1;
7023  } else {
7024  ast_verb(2, "UNISTIM Listening on %s:%d\n", ast_inet_ntoa(bindaddr.sin_addr), htons(bindaddr.sin_port));
7025  ast_set_qos(unistimsock, qos.tos, qos.cos, "UNISTIM");
7026  }
7027  return 0;
7028 }
struct ast_variable * next
static int unistim_port
Definition: chan_unistim.c:244
static struct unistimsession * sessions
A device containing one or more lines.
Definition: chan_unistim.c:394
char * config
Definition: conf2ael.c:66
static int unistimsock
Definition: chan_unistim.c:247
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
static struct @149 qos
#define LOG_WARNING
Definition: logger.h:274
static struct test_val d
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
Sets jitterbuffer configuration property.
Definition: abstract_jb.c:545
#define CONFIG_STATUS_FILEINVALID
Structure for variables, used for configurations and for channel variables.
static struct unistim_device * build_device(const char *cat, const struct ast_variable *v)
static struct unistim_languages options_languages[]
Definition: chan_unistim.c:771
#define ast_mutex_lock(a)
Definition: lock.h:187
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
Definition: acl.c:967
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3328
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static ast_mutex_t sessionlock
Definition: chan_unistim.c:271
static int unistimdebug
Definition: chan_unistim.c:243
#define RETRANSMIT_TIMER
Definition: chan_unistim.c:103
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
struct unistimsession * next
Definition: chan_unistim.c:477
static int find_language(const char *)
static void refresh_all_favorite(struct unistimsession *pte)
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
#define ast_log
Definition: astobj2.c:42
#define ast_config_load(filename, flags)
Load a config file.
static struct sockaddr_in public_ip
Definition: chan_unistim.c:258
signed char to_delete
Definition: chan_unistim.c:449
static void send_charset_update(struct unistimsession *pte, int charset)
struct unistim_device * next
Definition: chan_unistim.c:455
#define NB_MAX_RETRANSMIT
Definition: chan_unistim.c:99
static struct ast_jb_conf default_jbconf
Global jitterbuffer configuration - by default, jb is disabled.
Definition: chan_unistim.c:227
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
static int unistim_keepalive
Definition: chan_unistim.c:246
static struct ast_hostent ahp
Definition: chan_skinny.c:1235
static struct ast_jb_conf global_jbconf
Definition: chan_unistim.c:235
#define LOG_ERROR
Definition: logger.h:285
int ast_set_qos(int sockfd, int tos, int cos, const char *desc)
Set type of service.
Definition: netsock2.c:621
int errno
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
int ast_str2cos(const char *value, unsigned int *cos)
Convert a string to the appropriate COS value.
Definition: acl.c:953
static struct unistim_device * devices
Structure used to handle boolean flags.
Definition: utils.h:199
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
Definition: main/utils.c:197
static enum autoprovision autoprovisioning
Definition: chan_unistim.c:245
static void delete_device(struct unistim_device *d)
static void finish_bookmark(void)
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412
static struct hostent * hp
Definition: chan_skinny.c:1236
General jitterbuffer configuration.
Definition: abstract_jb.h:69
struct ast_sockaddr bindaddr
Definition: chan_ooh323.c:353
#define ast_mutex_unlock(a)
Definition: lock.h:188
static unsigned char packet_send_ping[]
Definition: chan_unistim.c:701

◆ restart_monitor()

static int restart_monitor ( void  )
static

Definition at line 5921 of file chan_unistim.c.

References ast_log, ast_mutex_lock, ast_mutex_unlock, ast_pthread_create, AST_PTHREADT_NULL, AST_PTHREADT_STOP, do_monitor(), LOG_ERROR, LOG_WARNING, monitor_thread, monlock, and NULL.

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

5922 {
5923  pthread_attr_t attr;
5924  /* If we're supposed to be stopped -- stay stopped */
5926  return 0;
5927  }
5928  if (ast_mutex_lock(&monlock)) {
5929  ast_log(LOG_WARNING, "Unable to lock monitor\n");
5930  return -1;
5931  }
5932  if (monitor_thread == pthread_self()) {
5934  ast_log(LOG_WARNING, "Cannot kill myself\n");
5935  return -1;
5936  }
5938  /* Wake up the thread */
5939  pthread_kill(monitor_thread, SIGURG);
5940  } else {
5941  pthread_attr_init(&attr);
5942  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
5943  /* Start a new monitor */
5944  if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
5946  ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
5947  return -1;
5948  }
5949  }
5951  return 0;
5952 }
static pthread_t monitor_thread
Definition: chan_unistim.c:265
#define LOG_WARNING
Definition: logger.h:274
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
static void * do_monitor(void *data)
#define ast_log
Definition: astobj2.c:42
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define LOG_ERROR
Definition: logger.h:285
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:559
#define AST_PTHREADT_STOP
Definition: lock.h:67
#define ast_mutex_unlock(a)
Definition: lock.h:188
static ast_mutex_t monlock
Definition: chan_unistim.c:269

◆ send_blink_cursor()

static void send_blink_cursor ( struct unistimsession pte)
static

Definition at line 1844 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_blink_cursor, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by handle_select_codec(), key_select_codec(), key_select_extension(), show_extension_page(), and show_phone_number().

1845 {
1846  BUFFSEND;
1847  if (unistimdebug) {
1848  ast_verb(0, "Sending set blink\n");
1849  }
1850  memcpy(buffsend + SIZE_HEADER, packet_send_blink_cursor, sizeof(packet_send_blink_cursor));
1851  send_client(SIZE_HEADER + sizeof(packet_send_blink_cursor), buffsend, pte);
1852  return;
1853 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_blink_cursor[]
Definition: chan_unistim.c:634

◆ send_callerid_screen()

static void send_callerid_screen ( struct unistimsession pte,
struct unistim_subchannel sub 
)
static

Definition at line 4825 of file chan_unistim.c.

References ast_channel_connected(), change_callerid(), DEFAULTCALLERID, DEFAULTCALLERNAME, unistimsession::device, unistim_device::height, ast_party_connected_line::id, ast_party_id::name, ast_party_id::number, unistim_subchannel::owner, send_text(), ast_party_name::str, ast_party_number::str, TEXT_LINE0, TEXT_LINE1, TEXT_NORMAL, ustmtext(), ast_party_name::valid, and ast_party_number::valid.

Referenced by handle_key_fav(), key_dial_page(), unistim_call(), unistim_hangup(), and unistim_indicate().

4826 {
4827  char *cidname_str;
4828  char *cidnum_str;
4829 
4830  if (!sub) {
4831  return;
4832  }
4833  if (sub->owner) {
4835  cidnum_str = ast_channel_connected(sub->owner)->id.number.str;
4836  } else {
4837  cidnum_str = DEFAULTCALLERID;
4838  }
4839  change_callerid(pte, 0, cidnum_str);
4840  if (strlen(cidnum_str) == 0) {
4841  cidnum_str = DEFAULTCALLERID;
4842  }
4843 
4845  cidname_str = ast_channel_connected(sub->owner)->id.name.str;
4846  } else {
4847  cidname_str = DEFAULTCALLERNAME;
4848  }
4849  change_callerid(pte, 1, cidname_str);
4850  if (strlen(cidname_str) == 0) {
4851  cidname_str = DEFAULTCALLERNAME;
4852  }
4853 
4854  if (pte->device->height == 1) {
4855  char tmpstr[256];
4856  snprintf(tmpstr, sizeof(tmpstr), "%s %s", cidnum_str, ustmtext(cidname_str, pte));
4857  send_text(TEXT_LINE0, TEXT_NORMAL, pte, tmpstr);
4858  } else {
4859  send_text(TEXT_LINE0, TEXT_NORMAL, pte, cidname_str);
4860  send_text(TEXT_LINE1, TEXT_NORMAL, pte, ustmtext(cidnum_str, pte));
4861  }
4862  }
4863 }
struct ast_channel * owner
Definition: chan_unistim.c:356
char * str
Subscriber phone number (Malloced)
Definition: channel.h:292
struct ast_party_id id
Connected party ID.
Definition: channel.h:459
struct ast_party_name name
Subscriber name.
Definition: channel.h:341
#define TEXT_LINE1
Definition: chan_unistim.c:171
char * str
Subscriber name (Malloced)
Definition: channel.h:265
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
struct unistim_device * device
Definition: chan_unistim.c:476
#define DEFAULTCALLERNAME
Definition: chan_unistim.c:85
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
#define DEFAULTCALLERID
Definition: chan_unistim.c:84
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:280
static void change_callerid(struct unistimsession *pte, int type, char *callerid)
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:298
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343

◆ send_charset_update()

static void send_charset_update ( struct unistimsession pte,
int  charset 
)
static

Definition at line 1869 of file chan_unistim.c.

References ast_verb, BUFFSEND, unistimsession::device, unistim_languages::encoding, find_language(), ISO_2022_JP, ISO_8859_1, ISO_8859_2, ISO_8859_4, ISO_8859_5, LANG_DEFAULT, unistim_device::language, packet_send_charset_iso_2022_jp, packet_send_charset_iso_8859_1, packet_send_charset_iso_8859_2, packet_send_charset_iso_8859_4, packet_send_charset_iso_8859_5, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by handle_select_language(), init_phone_step2(), key_select_language(), and reload_config().

1870 {
1871  const unsigned char* packet_send_charset;
1872  int packet_size;
1873  BUFFSEND;
1874  if (unistimdebug) {
1875  ast_verb(0, "Sending set default charset\n");
1876  }
1877  if (charset == LANG_DEFAULT) {
1879  }
1880  switch (charset) {
1881  case ISO_8859_2:
1882  packet_send_charset = packet_send_charset_iso_8859_2;
1883  packet_size = sizeof(packet_send_charset_iso_8859_2);
1884  break;
1885  case ISO_8859_4:
1886  packet_send_charset = packet_send_charset_iso_8859_4;
1887  packet_size = sizeof(packet_send_charset_iso_8859_4);
1888  break;
1889  case ISO_8859_5:
1890  packet_send_charset = packet_send_charset_iso_8859_5;
1891  packet_size = sizeof(packet_send_charset_iso_8859_5);
1892  break;
1893  case ISO_2022_JP:
1894  packet_send_charset = packet_send_charset_iso_2022_jp;
1895  packet_size = sizeof(packet_send_charset_iso_2022_jp);
1896  break;
1897  case ISO_8859_1:
1898  default:
1899  packet_send_charset = packet_send_charset_iso_8859_1;
1900  packet_size = sizeof(packet_send_charset_iso_8859_1);
1901  }
1902  memcpy(buffsend + SIZE_HEADER, packet_send_charset, packet_size);
1903  send_client(SIZE_HEADER + packet_size, buffsend, pte);
1904  return;
1905 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
static struct unistim_languages options_languages[]
Definition: chan_unistim.c:771
#define BUFFSEND
Definition: chan_unistim.c:704
static const unsigned char packet_send_charset_iso_8859_5[]
Definition: chan_unistim.c:688
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
static int find_language(const char *)
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_charset_iso_2022_jp[]
Definition: chan_unistim.c:691
charset
Definition: chan_unistim.c:336
static const unsigned char packet_send_charset_iso_8859_4[]
Definition: chan_unistim.c:685
static const unsigned char packet_send_charset_iso_8859_1[]
Definition: chan_unistim.c:679
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412
static const unsigned char packet_send_charset_iso_8859_2[]
Definition: chan_unistim.c:682

◆ send_client()

static void send_client ( int  size,
const unsigned char *  data,
struct unistimsession pte 
)
static

Definition at line 959 of file chan_unistim.c.

References ast_log, ast_mutex_lock, ast_mutex_unlock, ast_verb, wsabuf::buf, get_tick_count(), unistimsession::last_buf_available, wsabuf::len, unistimsession::lock, LOG_WARNING, MAX_BUF_NUMBER, RETRANSMIT_TIMER, send_raw_client(), seq, unistimsession::seq_server, unistimsession::sin, unistimsession::sout, unistimsession::timeout, unistimdebug, and unistimsession::wsabufsend.

Referenced by init_phone_step2(), rcv_mac_addr(), rcv_resume_connection_with_server(), send_blink_cursor(), send_charset_update(), send_cursor_pos(), send_date_time(), send_date_time2(), send_date_time3(), send_end_call(), send_expansion_icon(), send_expansion_next(), send_expansion_text(), send_favorite(), send_icon(), send_led_update(), send_month_labels(), send_mute(), send_no_ring(), send_ping(), send_ring(), send_select_output(), send_start_rtp(), send_start_timer(), send_stop_timer(), send_text(), send_text_status(), send_texttitle(), send_tone(), and unistim_sp().

960 {
961  unsigned int tick;
962  int buf_pos;
963  unsigned short seq = ntohs(++pte->seq_server);
964 
965  ast_mutex_lock(&pte->lock);
966  buf_pos = pte->last_buf_available;
967 
968  if (buf_pos >= MAX_BUF_NUMBER) {
969  ast_log(LOG_WARNING, "Error : send queue overflow\n");
970  ast_mutex_unlock(&pte->lock);
971  return;
972  }
973  memcpy((void *)data + sizeof(unsigned short), (void *)&seq, sizeof(unsigned short));
974  pte->wsabufsend[buf_pos].len = size;
975  memcpy(pte->wsabufsend[buf_pos].buf, data, size);
976 
977  tick = get_tick_count();
978  pte->timeout = tick + RETRANSMIT_TIMER;
979 
980 /*#ifdef DUMP_PACKET */
981  if (unistimdebug) {
982  ast_verb(0, "Sending datas with seq #0x%04x Using slot #%d :\n", (unsigned)pte->seq_server, buf_pos);
983  }
984 /*#endif */
985  send_raw_client(pte->wsabufsend[buf_pos].len, pte->wsabufsend[buf_pos].buf, &(pte->sin),
986  &(pte->sout));
987  pte->last_buf_available++;
988  ast_mutex_unlock(&pte->lock);
989 }
struct sockaddr_in sout
Definition: chan_unistim.c:461
struct wsabuf wsabufsend[MAX_BUF_NUMBER]
Definition: chan_unistim.c:474
#define LOG_WARNING
Definition: logger.h:274
unsigned short seq_server
Definition: chan_unistim.c:464
#define ast_mutex_lock(a)
Definition: lock.h:187
#define MAX_BUF_NUMBER
Definition: chan_unistim.c:93
#define ast_verb(level,...)
Definition: logger.h:463
ast_mutex_t lock
Definition: chan_unistim.c:459
static int unistimdebug
Definition: chan_unistim.c:243
#define RETRANSMIT_TIMER
Definition: chan_unistim.c:103
#define ast_log
Definition: astobj2.c:42
u_long len
Definition: chan_unistim.c:349
struct sockaddr_in sin
Definition: chan_unistim.c:460
static volatile unsigned int seq
Definition: app_sms.c:120
unsigned char * buf
Definition: chan_unistim.c:350
static unsigned int get_tick_count(void)
Definition: chan_unistim.c:895
#define ast_mutex_unlock(a)
Definition: lock.h:188
static void send_raw_client(int size, const unsigned char *data, struct sockaddr_in *addr_to, const struct sockaddr_in *addr_ourip)
Definition: chan_unistim.c:903

◆ send_cursor_pos()

static void send_cursor_pos ( struct unistimsession pte,
unsigned char  pos 
)
static

Definition at line 1856 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_set_pos_cursor, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by handle_select_codec(), key_select_codec(), key_select_extension(), show_extension_page(), and show_phone_number().

1857 {
1858  BUFFSEND;
1859  if (unistimdebug) {
1860  ast_verb(0, "Sending set cursor position\n");
1861  }
1862  memcpy(buffsend + SIZE_HEADER, packet_send_set_pos_cursor,
1863  sizeof(packet_send_set_pos_cursor));
1864  buffsend[11] = pos;
1865  send_client(SIZE_HEADER + sizeof(packet_send_set_pos_cursor), buffsend, pte);
1866  return;
1867 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
static const unsigned char packet_send_set_pos_cursor[]
Definition: chan_unistim.c:646
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167

◆ send_date_time()

static void send_date_time ( struct unistimsession pte)
static

Definition at line 1784 of file chan_unistim.c.

References ast_localtime(), ast_tvnow(), ast_verb, BUFFSEND, NULL, packet_send_date_time, send_client(), send_month_labels(), SIZE_HEADER, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, and unistimdebug.

Referenced by rcv_mac_addr().

1785 {
1786  BUFFSEND;
1787  struct timeval now = ast_tvnow();
1788  struct ast_tm atm = { 0, };
1789 
1790  if (unistimdebug) {
1791  ast_verb(0, "Sending Time & Date\n");
1792  }
1793  memcpy(buffsend + SIZE_HEADER, packet_send_date_time, sizeof(packet_send_date_time));
1794  ast_localtime(&now, &atm, NULL);
1795  buffsend[10] = (unsigned char) atm.tm_mon + 1;
1796  buffsend[11] = (unsigned char) atm.tm_mday;
1797  buffsend[12] = (unsigned char) atm.tm_hour;
1798  buffsend[13] = (unsigned char) atm.tm_min;
1799  send_client(SIZE_HEADER + sizeof(packet_send_date_time), buffsend, pte);
1800  send_month_labels(pte, atm.tm_mon);
1801 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
#define BUFFSEND
Definition: chan_unistim.c:704
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define NULL
Definition: resample.c:96
static const unsigned char packet_send_date_time[]
Definition: chan_unistim.c:542
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
int tm_mon
Definition: localtime.h:40
int tm_mday
Definition: localtime.h:39
static void send_month_labels(struct unistimsession *pte, int month)
int tm_hour
Definition: localtime.h:38
int tm_min
Definition: localtime.h:37

◆ send_date_time2()

static void send_date_time2 ( struct unistimsession pte)
static

Definition at line 1803 of file chan_unistim.c.

References ast_localtime(), ast_tvnow(), ast_verb, BUFFSEND, unistim_device::datetimeformat, unistimsession::device, NULL, packet_send_date_time2, send_client(), SIZE_HEADER, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, and unistimdebug.

Referenced by init_phone_step2(), and show_main_page().

1804 {
1805  BUFFSEND;
1806  struct timeval now = ast_tvnow();
1807  struct ast_tm atm = { 0, };
1808 
1809  if (unistimdebug) {
1810  ast_verb(0, "Sending Time & Date #2\n");
1811  }
1812  memcpy(buffsend + SIZE_HEADER, packet_send_date_time2, sizeof(packet_send_date_time2));
1813  ast_localtime(&now, &atm, NULL);
1814  if (pte->device) {
1815  buffsend[9] = pte->device->datetimeformat;
1816  } else {
1817  buffsend[9] = 61;
1818  }
1819  buffsend[14] = (unsigned char) atm.tm_mon + 1;
1820  buffsend[15] = (unsigned char) atm.tm_mday;
1821  buffsend[16] = (unsigned char) atm.tm_hour;
1822  buffsend[17] = (unsigned char) atm.tm_min;
1823  send_client(SIZE_HEADER + sizeof(packet_send_date_time2), buffsend, pte);
1824 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
static const unsigned char packet_send_date_time2[]
Definition: chan_unistim.c:635
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
#define BUFFSEND
Definition: chan_unistim.c:704
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
#define SIZE_HEADER
Definition: chan_unistim.c:167
int tm_mon
Definition: localtime.h:40
int tm_mday
Definition: localtime.h:39
int tm_hour
Definition: localtime.h:38
int tm_min
Definition: localtime.h:37

◆ send_date_time3()

static void send_date_time3 ( struct unistimsession pte)
static

Definition at line 1826 of file chan_unistim.c.

References ast_localtime(), ast_tvnow(), ast_verb, BUFFSEND, NULL, packet_send_date_time3, send_client(), SIZE_HEADER, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, and unistimdebug.

Referenced by init_phone_step2().

1827 {
1828  BUFFSEND;
1829  struct timeval now = ast_tvnow();
1830  struct ast_tm atm = { 0, };
1831 
1832  if (unistimdebug) {
1833  ast_verb(0, "Sending Time & Date #3\n");
1834  }
1835  memcpy(buffsend + SIZE_HEADER, packet_send_date_time3, sizeof(packet_send_date_time3));
1836  ast_localtime(&now, &atm, NULL);
1837  buffsend[10] = (unsigned char) atm.tm_mon + 1;
1838  buffsend[11] = (unsigned char) atm.tm_mday;
1839  buffsend[12] = (unsigned char) atm.tm_hour;
1840  buffsend[13] = (unsigned char) atm.tm_min;
1841  send_client(SIZE_HEADER + sizeof(packet_send_date_time3), buffsend, pte);
1842 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
#define BUFFSEND
Definition: chan_unistim.c:704
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
static const unsigned char packet_send_date_time3[]
Definition: chan_unistim.c:538
#define SIZE_HEADER
Definition: chan_unistim.c:167
int tm_mon
Definition: localtime.h:40
int tm_mday
Definition: localtime.h:39
int tm_hour
Definition: localtime.h:38
int tm_min
Definition: localtime.h:37

◆ send_dial_tone()

static void send_dial_tone ( struct unistimsession pte)
static

Definition at line 2924 of file chan_unistim.c.

References ast_get_indication_tone(), ast_strdupa, ast_tone_zone_part_parse(), ast_tone_zone_sound_unref(), ast_verb, ast_tone_zone::country, ast_tone_zone_sound::data, unistimsession::device, ast_tone_zone_part::freq1, ast_tone_zone_part::freq2, NULL, send_tone(), strsep(), unistim_device::tz, and unistimdebug.

Referenced by handle_dial_page().

2925 {
2926  struct ast_tone_zone_sound *ts = NULL;
2927  struct ast_tone_zone_part tone_data;
2928  char *s = NULL;
2929  char *ind;
2930 
2931  if ((ts = ast_get_indication_tone(pte->device->tz, "dial"))) {
2932  ind = ast_strdupa(ts->data);
2933  s = strsep(&ind, ",");
2934  ast_tone_zone_part_parse(s, &tone_data);
2935  send_tone(pte, tone_data.freq1, tone_data.freq2);
2936  if (unistimdebug) {
2937  ast_verb(0, "Country code found (%s), freq1=%u freq2=%u\n",
2938  pte->device->tz->country, tone_data.freq1, tone_data.freq2);
2939  }
2940  ts = ast_tone_zone_sound_unref(ts);
2941  }
2942 }
char country[MAX_TONEZONE_COUNTRY]
Country code that this set of tones is for.
Definition: indications.h:76
A description of a part of a tone.
Definition: indications.h:109
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
Definition: indications.h:227
struct ast_tone_zone * tz
Definition: chan_unistim.c:421
Description of a tone.
Definition: indications.h:35
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:455
char * strsep(char **str, const char *delims)
const char * data
Description of a tone.
Definition: indications.h:52
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
Parse a tone part.
Definition: indications.c:245

◆ send_dtmf_tone()

static int send_dtmf_tone ( struct unistimsession pte,
char  digit 
)
static

Definition at line 3329 of file chan_unistim.c.

References ast_verb, unistimsession::device, dtmf_col, dtmf_row, unistim_device::dtmfduration, send_tone(), and unistimdebug.

Referenced by unistim_do_senddigit(), and unistim_senddigit_begin().

3330 {
3331  int row, col;
3332 
3333  if (unistimdebug) {
3334  ast_verb(0, "Phone Play Digit %c\n", digit);
3335  }
3336  if (pte->device->dtmfduration > 0) {
3337  row = (digit - '1') % 3;
3338  col = (digit - '1' - row) / 3;
3339  if (digit >= '1' && digit <='9') {
3340  send_tone(pte, dtmf_row[row], dtmf_col[col]);
3341  } else if (digit >= 'A' && digit <= 'D') {
3342  send_tone(pte, dtmf_row[digit-'A'], dtmf_col[3]);
3343  } else if (digit == '*') {
3344  send_tone(pte, dtmf_row[3], dtmf_col[0]);
3345  } else if (digit == '0') {
3346  send_tone(pte, dtmf_row[3], dtmf_col[1]);
3347  } else if (digit == '#') {
3348  send_tone(pte, dtmf_row[3], dtmf_col[2]);
3349  } else {
3350  send_tone(pte, 500, 2000);
3351  }
3352  }
3353  return 0;
3354 }
char digit
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
static const float dtmf_col[]
Definition: chan_unistim.c:346
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
static const int dtmf_row[]
Definition: chan_unistim.c:345

◆ send_end_call()

static void send_end_call ( struct unistimsession pte)
static

Definition at line 1080 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_end_call, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by unistim_hangup().

1081 {
1082  BUFFSEND;
1083  if (unistimdebug) {
1084  ast_verb(0, "Sending end call\n");
1085  }
1086  memcpy(buffsend + SIZE_HEADER, packet_send_end_call, sizeof(packet_send_end_call));
1087  send_client(SIZE_HEADER + sizeof(packet_send_end_call), buffsend, pte);
1088 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_end_call[]
Definition: chan_unistim.c:592

◆ send_expansion_icon()

static void send_expansion_icon ( unsigned char  pos,
unsigned char  status,
struct unistimsession pte 
)
static

Definition at line 1167 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_expansion_icon, send_client(), SIZE_HEADER, status, and unistimdebug.

Referenced by send_expansion_short().

1168 {
1169  BUFFSEND;
1170  if (unistimdebug) {
1171  ast_verb(0, "Sending expansion icon pos %d with status 0x%02hhx\n", pos, status);
1172  }
1174  buffsend[10] = pos;
1175  buffsend[11] = status;
1176  send_client(SIZE_HEADER + sizeof(packet_send_expansion_icon), buffsend, pte);
1177 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static const unsigned char packet_send_expansion_icon[]
Definition: chan_unistim.c:527
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
jack_status_t status
Definition: app_jack.c:146

◆ send_expansion_next()

static void send_expansion_next ( struct unistimsession pte)
static

Definition at line 1159 of file chan_unistim.c.

References BUFFSEND, packet_send_expansion_next, send_client(), and SIZE_HEADER.

Referenced by send_expansion_short().

1160 {
1161  BUFFSEND;
1163  send_client(SIZE_HEADER + sizeof(packet_send_expansion_next), buffsend, pte);
1164 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
static const unsigned char packet_send_expansion_next[]
Definition: chan_unistim.c:526
#define SIZE_HEADER
Definition: chan_unistim.c:167

◆ send_expansion_short()

static void send_expansion_short ( unsigned char  pos,
unsigned char  status,
struct unistimsession pte 
)
static

Definition at line 1306 of file chan_unistim.c.

References unistimsession::device, unistim_device::expsoftkeylabel, send_expansion_icon(), send_expansion_next(), send_expansion_text(), and ustmtext().

Referenced by refresh_all_favorite().

1306  {
1307  send_expansion_icon(pos, status, pte);
1308  send_expansion_text(pos, pte, ustmtext(pte->device->expsoftkeylabel[pos], pte));
1309  send_expansion_next(pte);
1310  return;
1311 }
static void send_expansion_text(unsigned char pos, struct unistimsession *pte, const char *text)
static void send_expansion_next(struct unistimsession *pte)
char expsoftkeylabel[EXPNUM][11]
Definition: chan_unistim.c:404
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_expansion_icon(unsigned char pos, unsigned char status, struct unistimsession *pte)
jack_status_t status
Definition: app_jack.c:146

◆ send_expansion_text()

static void send_expansion_text ( unsigned char  pos,
struct unistimsession pte,
const char *  text 
)
static

Definition at line 1180 of file chan_unistim.c.

References ast_log, ast_verb, BUFFSEND, LOG_ERROR, packet_send_expansion_text, send_client(), SIZE_HEADER, TEXT_LENGTH_MAX, and unistimdebug.

Referenced by send_expansion_short().

1181 {
1182  int i;
1183  BUFFSEND;
1184  if (!text) {
1185  ast_log(LOG_ERROR, "[expansion] Asked to display NULL text (pos %d)\n", pos);
1186  return;
1187  }
1188  if (unistimdebug) {
1189  ast_verb(0, "[expansion] Sending text at pos %d\n", pos);
1190  }
1192  buffsend[10] = pos;
1193  i = strlen(text);
1194  if (i > TEXT_LENGTH_MAX) {
1195  i = TEXT_LENGTH_MAX;
1196  }
1197  memcpy(buffsend + 11, text, i);
1198  send_client(SIZE_HEADER + sizeof(packet_send_expansion_text), buffsend, pte);
1199 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
static const unsigned char packet_send_expansion_text[]
Definition: chan_unistim.c:528
char * text
Definition: app_queue.c:1508
#define ast_verb(level,...)
Definition: logger.h:463
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_log
Definition: astobj2.c:42
#define SIZE_HEADER
Definition: chan_unistim.c:167
#define LOG_ERROR
Definition: logger.h:285

◆ send_favorite()

static void send_favorite ( unsigned char  pos,
unsigned char  status,
struct unistimsession pte,
const char *  text 
)
static

Definition at line 1273 of file chan_unistim.c.

References ast_verb, BUFFSEND, FAV_MAX_LENGTH, packet_send_favorite, send_client(), SIZE_HEADER, status, unistimdebug, and ustmtext().

Referenced by change_favorite_icon(), init_phone_step2(), send_favorite_selected(), send_favorite_short(), and unistim_sendtext().

1275 {
1276  BUFFSEND;
1277  int i;
1278 
1279  if (unistimdebug) {
1280  ast_verb(0, "Sending favorite pos %d with status 0x%02hhx\n", pos, status);
1281  }
1282  memcpy(buffsend + SIZE_HEADER, packet_send_favorite, sizeof(packet_send_favorite));
1283  buffsend[10] = pos;
1284  buffsend[24] = pos;
1285  buffsend[25] = status;
1286  i = strlen(ustmtext(text, pte));
1287  if (i > FAV_MAX_LENGTH) {
1288  i = FAV_MAX_LENGTH;
1289  }
1290  memcpy(buffsend + FAV_MAX_LENGTH + 1, ustmtext(text, pte), i);
1291  send_client(SIZE_HEADER + sizeof(packet_send_favorite), buffsend, pte);
1292 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
char * text
Definition: app_queue.c:1508
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
static const unsigned char packet_send_favorite[]
Definition: chan_unistim.c:654
#define SIZE_HEADER
Definition: chan_unistim.c:167
#define FAV_MAX_LENGTH
Definition: chan_unistim.c:214
jack_status_t status
Definition: app_jack.c:146

◆ send_favorite_selected()

static void send_favorite_selected ( unsigned char  status,
struct unistimsession pte 
)
static

Definition at line 1299 of file chan_unistim.c.

References unistimsession::device, unistim_device::selected, send_favorite(), and unistim_device::softkeylabel.

Referenced by handle_key_fav(), and key_dial_page().

1299  {
1300  if (pte->device->selected != -1) {
1302  }
1303  return;
1304 }
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_favorite(unsigned char pos, unsigned char status, struct unistimsession *pte, const char *text)
jack_status_t status
Definition: app_jack.c:146

◆ send_favorite_short()

static void send_favorite_short ( unsigned char  pos,
unsigned char  status,
struct unistimsession pte 
)
static

Definition at line 1294 of file chan_unistim.c.

References unistimsession::device, send_favorite(), and unistim_device::softkeylabel.

Referenced by change_favorite_icon(), close_call(), handle_call_incoming(), handle_call_outgoing(), refresh_all_favorite(), sub_hold(), sub_unhold(), unistim_call(), and unistim_hangup().

1294  {
1295  send_favorite(pos, status, pte, pte->device->softkeylabel[pos]);
1296  return;
1297 }
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_favorite(unsigned char pos, unsigned char status, struct unistimsession *pte, const char *text)
jack_status_t status
Definition: app_jack.c:146

◆ send_icon()

static void send_icon ( unsigned char  pos,
unsigned char  status,
struct unistimsession pte 
)
static

Definition at line 1147 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_icon, send_client(), SIZE_HEADER, status, and unistimdebug.

Referenced by handle_dial_page(), key_main_page(), and show_main_page().

1148 {
1149  BUFFSEND;
1150  if (unistimdebug) {
1151  ast_verb(0, "Sending icon pos %d with status 0x%02hhx\n", pos, status);
1152  }
1153  memcpy(buffsend + SIZE_HEADER, packet_send_icon, sizeof(packet_send_icon));
1154  buffsend[9] = pos;
1155  buffsend[10] = status;
1156  send_client(SIZE_HEADER + sizeof(packet_send_icon), buffsend, pte);
1157 }
static const unsigned char packet_send_icon[]
Definition: chan_unistim.c:644
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
jack_status_t status
Definition: app_jack.c:146

◆ send_idle_clock()

static void send_idle_clock ( struct unistimsession pte)
static

Definition at line 1757 of file chan_unistim.c.

References send_text(), TEXT_LINE0, and TEXT_NORMAL.

Referenced by show_main_page().

1758 {
1759  send_text(TEXT_LINE0, TEXT_NORMAL, pte, "");
1760 }
#define TEXT_NORMAL
Definition: chan_unistim.c:173
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)

◆ send_led_update()

static void send_led_update ( struct unistimsession pte,
unsigned char  led 
)
static

Definition at line 1639 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_led_update, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by handle_dial_page(), init_phone_step2(), key_dial_page(), microphone_mute_toggle(), send_select_output(), show_main_page(), show_phone_number(), and unistim_send_mwi_to_peer().

1640 {
1641  BUFFSEND;
1642  if (unistimdebug) {
1643  ast_verb(0, "Sending led_update (%x)\n", (unsigned)led);
1644  }
1645  memcpy(buffsend + SIZE_HEADER, packet_send_led_update, sizeof(packet_send_led_update));
1646  buffsend[9] = led;
1647  send_client(SIZE_HEADER + sizeof(packet_send_led_update), buffsend, pte);
1648 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
static const unsigned char packet_send_led_update[]
Definition: chan_unistim.c:694
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167

◆ send_month_labels()

static void send_month_labels ( struct unistimsession pte,
int  month 
)
static

Definition at line 1762 of file chan_unistim.c.

References ast_log, ast_verb, BUFFSEND, LOG_WARNING, MONTH_LABEL_SIZE, monthlabels, packet_send_monthlabels_download, send_client(), SIZE_HEADER, unistimdebug, and ustmtext().

Referenced by send_date_time().

1763 {
1764  BUFFSEND;
1765  char month_name[MONTH_LABEL_SIZE + 1];
1766  int i = 0;
1767  if (unistimdebug) {
1768  ast_verb(0, "Sending Month Labels\n");
1769  }
1770  month_name[MONTH_LABEL_SIZE] = '\0';
1772  while (i < 2) {
1773  memcpy(month_name, &monthlabels[month * MONTH_LABEL_SIZE], MONTH_LABEL_SIZE);
1774  memcpy(buffsend + SIZE_HEADER + 3 + i*MONTH_LABEL_SIZE, ustmtext(month_name, pte), MONTH_LABEL_SIZE);
1775  ast_log(LOG_WARNING,"%s\n", month_name);
1776  ast_log(LOG_WARNING,"%s\n", ustmtext(month_name, pte));
1777  month = (month + 1)%12;
1778  i++;
1779  }
1780  send_client(SIZE_HEADER + sizeof(packet_send_monthlabels_download), buffsend, pte);
1781 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define LOG_WARNING
Definition: logger.h:274
static unsigned char packet_send_monthlabels_download[]
Definition: chan_unistim.c:652
#define BUFFSEND
Definition: chan_unistim.c:704
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_log
Definition: astobj2.c:42
#define SIZE_HEADER
Definition: chan_unistim.c:167
static unsigned char monthlabels[]
Definition: chan_unistim.c:649
#define MONTH_LABEL_SIZE
Definition: chan_unistim.c:97

◆ send_mute()

static void send_mute ( struct unistimsession pte,
unsigned char  mute 
)
static

Definition at line 1650 of file chan_unistim.c.

References ast_verb, BUFFSEND, mute, packet_send_mute, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by microphone_mute_toggle().

1651 {
1652 /*
1653  0x00 = unmute TX, 0x01 = mute TX
1654  0x20 = unmute RX, 0x21 = mute RX
1655 */
1656  BUFFSEND;
1657  if (unistimdebug) {
1658  ast_verb(0, "Sending mute packet (%x)\n", (unsigned)mute);
1659  }
1660  memcpy(buffsend + SIZE_HEADER, packet_send_mute, sizeof(packet_send_mute));
1661  buffsend[9] = mute;
1662  send_client(SIZE_HEADER + sizeof(packet_send_mute), buffsend, pte);
1663 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int mute
Definition: chan_alsa.c:144
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_mute[]
Definition: chan_unistim.c:570

◆ send_no_ring()

static void send_no_ring ( struct unistimsession pte)
static

Definition at line 1731 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_no_ring, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by handle_call_incoming(), ignore_call(), init_phone_step2(), and unistim_hangup().

1732 {
1733  BUFFSEND;
1734  if (unistimdebug) {
1735  ast_verb(0, "Sending no ring packet\n");
1736  }
1737  memcpy(buffsend + SIZE_HEADER, packet_send_no_ring, sizeof(packet_send_no_ring));
1738  send_client(SIZE_HEADER + sizeof(packet_send_no_ring), buffsend, pte);
1739 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_no_ring[]
Definition: chan_unistim.c:549

◆ send_ping()

static void send_ping ( struct unistimsession pte)
static

Definition at line 991 of file chan_unistim.c.

References ast_verb, BUFFSEND, get_tick_count(), packet_send_ping, send_client(), SIZE_HEADER, unistimsession::tick_next_ping, unistim_keepalive, and unistimdebug.

Referenced by do_monitor(), and init_phone_step2().

992 {
993  BUFFSEND;
994  if (unistimdebug) {
995  ast_verb(0, "Sending ping\n");
996  }
998  memcpy(buffsend + SIZE_HEADER, packet_send_ping, sizeof(packet_send_ping));
999  send_client(SIZE_HEADER + sizeof(packet_send_ping), buffsend, pte);
1000 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
unsigned long tick_next_ping
Definition: chan_unistim.c:466
#define SIZE_HEADER
Definition: chan_unistim.c:167
static int unistim_keepalive
Definition: chan_unistim.c:246
static unsigned int get_tick_count(void)
Definition: chan_unistim.c:895
static unsigned char packet_send_ping[]
Definition: chan_unistim.c:701

◆ send_raw_client()

static void send_raw_client ( int  size,
const unsigned char *  data,
struct sockaddr_in *  addr_to,
const struct sockaddr_in *  addr_ourip 
)
static

Definition at line 903 of file chan_unistim.c.

References ast_inet_ntoa(), ast_verb, display_last_error(), tmp(), unistimdebug, and unistimsock.

Referenced by parsing(), send_client(), and send_retransmit().

905 {
906 #ifdef HAVE_PKTINFO
907  struct iovec msg_iov;
908  struct msghdr msg;
909  char buffer[CMSG_SPACE(sizeof(struct in_pktinfo))];
910  struct cmsghdr *ip_msg = (struct cmsghdr *) buffer;
911  struct in_pktinfo *pki = (struct in_pktinfo *) CMSG_DATA(ip_msg);
912 
913  /* cast this to a non-const pointer, since the sendmsg() API
914  * does not provide read-only and write-only flavors of the
915  * structures used for its arguments, but in this case we know
916  * the data will not be modified
917  */
918  msg_iov.iov_base = (char *) data;
919  msg_iov.iov_len = size;
920 
921  msg.msg_name = addr_to; /* optional address */
922  msg.msg_namelen = sizeof(struct sockaddr_in); /* size of address */
923  msg.msg_iov = &msg_iov; /* scatter/gather array */
924  msg.msg_iovlen = 1; /* # elements in msg_iov */
925  msg.msg_control = ip_msg; /* ancillary data */
926  msg.msg_controllen = sizeof(buffer); /* ancillary data buffer len */
927  msg.msg_flags = 0; /* flags on received message */
928 
929  ip_msg->cmsg_len = CMSG_LEN(sizeof(*pki));
930  ip_msg->cmsg_level = IPPROTO_IP;
931  ip_msg->cmsg_type = IP_PKTINFO;
932  pki->ipi_ifindex = 0; /* Interface index, 0 = use interface specified in routing table */
933  pki->ipi_spec_dst.s_addr = addr_ourip->sin_addr.s_addr; /* Local address */
934  /* pki->ipi_addr = ; Header Destination address - ignored by kernel */
935 
936 #ifdef DUMP_PACKET
937  if (unistimdebug) {
938  int tmp;
939  ast_verb(0, "\n**> From %s sending %d bytes to %s ***\n",
940  ast_inet_ntoa(addr_ourip->sin_addr), (int) size,
941  ast_inet_ntoa(addr_to->sin_addr));
942  for (tmp = 0; tmp < size; tmp++)
943  ast_verb(0, "%02hhx ", data[tmp]);
944  ast_verb(0, "\n******************************************\n");
945 
946  }
947 #endif
948 
949  if (sendmsg(unistimsock, &msg, 0) == -1) {
950  display_last_error("Error sending datas");
951  }
952 #else
953  if (sendto(unistimsock, data, size, 0, (struct sockaddr *) addr_to, sizeof(*addr_to))
954  == -1)
955  display_last_error("Error sending datas");
956 #endif
957 }
static int unistimsock
Definition: chan_unistim.c:247
static int tmp()
Definition: bt_open.c:389
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
static void display_last_error(const char *sz_msg)
Definition: chan_unistim.c:889

◆ send_retransmit()

static int send_retransmit ( struct unistimsession pte)
static

Definition at line 1538 of file chan_unistim.c.

References ast_log, ast_mutex_lock, ast_mutex_unlock, ast_verb, wsabuf::buf, close_client(), get_tick_count(), unistimsession::last_buf_available, unistimsession::last_seq_ack, wsabuf::len, unistimsession::lock, LOG_WARNING, NB_MAX_RETRANSMIT, unistimsession::nb_retransmit, RETRANSMIT_TIMER, send_raw_client(), seq, unistimsession::seq_server, unistimsession::sin, unistimsession::sout, unistimsession::timeout, unistimdebug, and unistimsession::wsabufsend.

Referenced by do_monitor(), and parsing().

1539 {
1540  int i;
1541 
1542  ast_mutex_lock(&pte->lock);
1543  if (++pte->nb_retransmit >= NB_MAX_RETRANSMIT) {
1544  if (unistimdebug) {
1545  ast_verb(0, "Too many retransmit - freeing client\n");
1546  }
1547  ast_mutex_unlock(&pte->lock);
1548  close_client(pte);
1549  return 1;
1550  }
1552 
1553  for (i = pte->last_buf_available - (pte->seq_server - pte->last_seq_ack);
1554  i < pte->last_buf_available; i++) {
1555  if (i < 0) {
1557  "Asked to retransmit an ACKed slot ! last_buf_available=%d, seq_server = #0x%04x last_seq_ack = #0x%04x\n",
1558  pte->last_buf_available, (unsigned)pte->seq_server, (unsigned)pte->last_seq_ack);
1559  continue;
1560  }
1561 
1562  if (unistimdebug) {
1563  unsigned short *sbuf = (unsigned short *) pte->wsabufsend[i].buf;
1564  unsigned short seq;
1565 
1566  seq = ntohs(sbuf[1]);
1567  ast_verb(0, "Retransmit slot #%d (seq=#0x%04x), last ack was #0x%04x\n", i,
1568  (unsigned)seq, (unsigned)pte->last_seq_ack);
1569  }
1570  send_raw_client(pte->wsabufsend[i].len, pte->wsabufsend[i].buf, &pte->sin,
1571  &pte->sout);
1572  }
1573  ast_mutex_unlock(&pte->lock);
1574  return 0;
1575 }
struct sockaddr_in sout
Definition: chan_unistim.c:461
struct wsabuf wsabufsend[MAX_BUF_NUMBER]
Definition: chan_unistim.c:474
#define LOG_WARNING
Definition: logger.h:274
unsigned short seq_server
Definition: chan_unistim.c:464
#define ast_mutex_lock(a)
Definition: lock.h:187
static void close_client(struct unistimsession *s)
#define ast_verb(level,...)
Definition: logger.h:463
ast_mutex_t lock
Definition: chan_unistim.c:459
unsigned short last_seq_ack
Definition: chan_unistim.c:465
static int unistimdebug
Definition: chan_unistim.c:243
#define RETRANSMIT_TIMER
Definition: chan_unistim.c:103
#define ast_log
Definition: astobj2.c:42
#define NB_MAX_RETRANSMIT
Definition: chan_unistim.c:99
u_long len
Definition: chan_unistim.c:349
struct sockaddr_in sin
Definition: chan_unistim.c:460
static volatile unsigned int seq
Definition: app_sms.c:120
unsigned char * buf
Definition: chan_unistim.c:350
static unsigned int get_tick_count(void)
Definition: chan_unistim.c:895
#define ast_mutex_unlock(a)
Definition: lock.h:188
static void send_raw_client(int size, const unsigned char *data, struct sockaddr_in *addr_to, const struct sockaddr_in *addr_ourip)
Definition: chan_unistim.c:903

◆ send_ring()

static void send_ring ( struct unistimsession pte,
signed char  volume,
signed char  style 
)
static

Definition at line 1719 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_ring, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by unistim_call().

1720 {
1721  BUFFSEND;
1722  if (unistimdebug) {
1723  ast_verb(0, "Sending ring packet\n");
1724  }
1725  memcpy(buffsend + SIZE_HEADER, packet_send_ring, sizeof(packet_send_ring));
1726  buffsend[24] = style + 0x10;
1727  buffsend[29] = volume * 0x10;
1728  send_client(SIZE_HEADER + sizeof(packet_send_ring), buffsend, pte);
1729 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
static const unsigned char packet_send_ring[]
Definition: chan_unistim.c:584
#define SIZE_HEADER
Definition: chan_unistim.c:167

◆ send_select_output()

static void send_select_output ( struct unistimsession pte,
unsigned char  output,
unsigned char  volume,
unsigned char  mute 
)
static

Definition at line 1670 of file chan_unistim.c.

References ast_log, ast_verb, BUFFSEND, change_favorite_icon(), unistimsession::device, FAV_ICON_HEADPHONES, FAV_ICON_HEADPHONES_ONHOLD, FAV_ICON_OFFHOOK_BLACK, FAV_ICON_ONHOLD_BLACK, FAV_ICON_SPEAKER_OFFHOOK_BLACK, FAV_ICON_SPEAKER_ONHOLD_BLACK, FAV_ICON_SPEAKER_ONHOOK_BLACK, LED_HEADPHONE_OFF, LED_HEADPHONE_ON, LED_SPEAKER_OFF, LED_SPEAKER_ON, LOG_WARNING, mute, MUTE_ON, MUTE_ON_DISCRET, unistim_device::output, OUTPUT_HANDSET, OUTPUT_HEADPHONE, OUTPUT_SPEAKER, packet_send_select_output, unistim_device::previous_output, unistim_device::receiver_state, send_client(), send_led_update(), SIZE_HEADER, STATE_OFFHOOK, unistimdebug, VOLUME_LOW, and VOLUME_LOW_SPEAKER.

Referenced by handle_call_incoming(), handle_call_outgoing(), handle_dial_page(), handle_key_fav(), key_call(), key_dial_page(), key_main_page(), process_request(), show_main_page(), sub_hold(), and sub_unhold().

1672 {
1673  BUFFSEND;
1674  int mute_icon = -1;
1675  if (unistimdebug) {
1676  ast_verb(0, "Sending select output packet output=%x volume=%x mute=%x\n",
1677  (unsigned)output, (unsigned)volume, (unsigned)mute);
1678  }
1679  memcpy(buffsend + SIZE_HEADER, packet_send_select_output,
1680  sizeof(packet_send_select_output));
1681  buffsend[9] = output;
1682  if (output == OUTPUT_SPEAKER && volume == VOLUME_LOW) {
1684  }
1685  buffsend[10] = volume;
1686  if (mute == MUTE_ON_DISCRET) {
1687  buffsend[11] = MUTE_ON;
1688  } else {
1689  buffsend[11] = mute;
1690  }
1691  send_client(SIZE_HEADER + sizeof(packet_send_select_output), buffsend, pte);
1692  if (output == OUTPUT_HANDSET) {
1696  } else if (output == OUTPUT_HEADPHONE) {
1700  } else if (output == OUTPUT_SPEAKER) {
1703  if (pte->device->receiver_state == STATE_OFFHOOK) {
1705  } else {
1707  }
1708  } else {
1709  ast_log(LOG_WARNING, "Invalid output (%d)\n", output);
1710  }
1711  if (mute_icon != -1) {
1712  change_favorite_icon(pte, mute_icon);
1713  }
1714  if (output != pte->device->output) {
1715  pte->device->previous_output = pte->device->output;
1716  }
1717  pte->device->output = output;
1718 }
static const unsigned char packet_send_select_output[]
Definition: chan_unistim.c:581
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define FAV_ICON_ONHOLD_BLACK
Definition: chan_unistim.c:184
#define FAV_ICON_HEADPHONES_ONHOLD
Definition: chan_unistim.c:193
#define LOG_WARNING
Definition: logger.h:274
#define LED_SPEAKER_ON
Definition: chan_unistim.c:160
static void change_favorite_icon(struct unistimsession *pte, unsigned char status)
#define BUFFSEND
Definition: chan_unistim.c:704
#define LED_SPEAKER_OFF
Definition: chan_unistim.c:159
#define ast_verb(level,...)
Definition: logger.h:463
static int mute
Definition: chan_alsa.c:144
#define VOLUME_LOW
Definition: chan_unistim.c:142
static int unistimdebug
Definition: chan_unistim.c:243
#define FAV_ICON_HEADPHONES
Definition: chan_unistim.c:192
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
#define VOLUME_LOW_SPEAKER
Definition: chan_unistim.c:143
#define OUTPUT_HEADPHONE
Definition: chan_unistim.c:139
#define OUTPUT_HANDSET
Definition: chan_unistim.c:138
#define SIZE_HEADER
Definition: chan_unistim.c:167
#define FAV_ICON_SPEAKER_ONHOLD_BLACK
Definition: chan_unistim.c:190
#define FAV_ICON_SPEAKER_ONHOOK_BLACK
Definition: chan_unistim.c:180
#define FAV_ICON_SPEAKER_OFFHOOK_BLACK
Definition: chan_unistim.c:186
static void send_led_update(struct unistimsession *pte, unsigned char led)
#define MUTE_ON
Definition: chan_unistim.c:148
#define MUTE_ON_DISCRET
Definition: chan_unistim.c:149
#define LED_HEADPHONE_ON
Definition: chan_unistim.c:162
#define OUTPUT_SPEAKER
Definition: chan_unistim.c:140
#define LED_HEADPHONE_OFF
Definition: chan_unistim.c:161
#define FAV_ICON_OFFHOOK_BLACK
Definition: chan_unistim.c:182

◆ send_start_rtp()

static void send_start_rtp ( struct unistim_subchannel sub)
static

Definition at line 2710 of file chan_unistim.c.

References ast_channel_readformat(), ast_format_alaw, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_g723, ast_format_g729, ast_format_get_name(), ast_format_ulaw, ast_inet_ntoa(), ast_log, ast_rtp_codecs_payload_code_tx(), ast_rtp_instance_get_codecs(), ast_rtp_instance_get_local_address(), ast_rtp_instance_get_remote_address, ast_sockaddr_to_sin, ast_verb, BUFFSEND, unistimsession::device, LOG_WARNING, unistim_subchannel::owner, packet_send_call, packet_send_jitter_buffer_conf, packet_send_open_audio_stream_rx, packet_send_open_audio_stream_rx3, packet_send_open_audio_stream_tx, packet_send_open_audio_stream_tx3, packet_send_rtp_packet_size, unistim_subchannel::parent, unistim_line::parent, public_ip, put_unaligned_uint16(), unistim_subchannel::rtp, unistim_device::rtp_method, send_client(), unistim_device::session, SIZE_HEADER, and unistimdebug.

Referenced by start_rtp(), and sub_unhold().

2711 {
2712  BUFFSEND;
2713 
2714  int codec;
2715  struct sockaddr_in public = { 0, };
2716  struct sockaddr_in us = { 0, };
2717  struct sockaddr_in sin = { 0, };
2718  struct ast_sockaddr us_tmp;
2719  struct ast_sockaddr sin_tmp;
2720  struct unistimsession *pte;
2721 
2722  ast_rtp_instance_get_local_address(sub->rtp, &us_tmp);
2723  ast_sockaddr_to_sin(&us_tmp, &us);
2724  ast_rtp_instance_get_remote_address(sub->rtp, &sin_tmp);
2725  ast_sockaddr_to_sin(&sin_tmp, &sin);
2726 
2727  /* Setting up RTP of the phone */
2728  if (public_ip.sin_family == 0) { /* NAT IP override ? */
2729  memcpy(&public, &us, sizeof(public)); /* No defined, using IP from recvmsg */
2730  } else {
2731  memcpy(&public, &public_ip, sizeof(public)); /* override */
2732  }
2733  if (unistimdebug) {
2734  ast_verb(0, "RTP started : Our IP/port is : %s:%hd with codec %s\n",
2735  ast_inet_ntoa(us.sin_addr),
2736  htons(us.sin_port), ast_format_get_name(ast_channel_readformat(sub->owner)));
2737  ast_verb(0, "Starting phone RTP stack. Our public IP is %s\n",
2738  ast_inet_ntoa(public.sin_addr));
2739  }
2740 
2741  pte = sub->parent->parent->session;
2743  1, ast_channel_readformat(sub->owner), 0);
2746  if (unistimdebug) {
2747  ast_verb(0, "Sending packet_send_rtp_packet_size for codec %d\n", codec);
2748  }
2749  memcpy(buffsend + SIZE_HEADER, packet_send_rtp_packet_size,
2750  sizeof(packet_send_rtp_packet_size));
2751  buffsend[10] = (int) codec & 0xffffffffLL;
2752  send_client(SIZE_HEADER + sizeof(packet_send_rtp_packet_size), buffsend, pte);
2753  }
2754  if (unistimdebug) {
2755  ast_verb(0, "Sending Jitter Buffer Parameters Configuration\n");
2756  }
2757  memcpy(buffsend + SIZE_HEADER, packet_send_jitter_buffer_conf,
2759  send_client(SIZE_HEADER + sizeof(packet_send_jitter_buffer_conf), buffsend, pte);
2760  if (pte->device->rtp_method != 0) {
2761  uint16_t rtcpsin_port = ntohs(us.sin_port) + 1; /* RTCP port is RTP + 1 */
2762 
2763  if (unistimdebug) {
2764  ast_verb(0, "Sending OpenAudioStreamTX using method #%d\n", pte->device->rtp_method);
2765  }
2766  if (pte->device->rtp_method == 3) {
2769  } else {
2770  memcpy(buffsend + SIZE_HEADER, packet_send_open_audio_stream_tx,
2772  }
2773  if (pte->device->rtp_method != 2) {
2774  memcpy(buffsend + 28, &public.sin_addr, sizeof(public.sin_addr));
2775  put_unaligned_uint16(&buffsend[20], sin.sin_port);
2776  put_unaligned_uint16(&buffsend[22], htons(rtcpsin_port));
2777  put_unaligned_uint16(&buffsend[24], us.sin_port);
2778  put_unaligned_uint16(&buffsend[26], htons(rtcpsin_port));
2779  } else {
2780  memcpy(buffsend + 23, &public.sin_addr, sizeof(public.sin_addr));
2781  put_unaligned_uint16(&buffsend[15], sin.sin_port);
2782  put_unaligned_uint16(&buffsend[19], us.sin_port);
2783  }
2784  buffsend[11] = codec; /* rx */
2785  buffsend[12] = codec; /* tx */
2786  send_client(SIZE_HEADER + sizeof(packet_send_open_audio_stream_tx), buffsend, pte);
2787 
2788  if (unistimdebug) {
2789  ast_verb(0, "Sending OpenAudioStreamRX\n");
2790  }
2791  if (pte->device->rtp_method == 3) {
2794  } else {
2795  memcpy(buffsend + SIZE_HEADER, packet_send_open_audio_stream_rx,
2797  }
2798  if (pte->device->rtp_method != 2) {
2799  memcpy(buffsend + 28, &public.sin_addr, sizeof(public.sin_addr));
2800  put_unaligned_uint16(&buffsend[20], sin.sin_port);
2801  put_unaligned_uint16(&buffsend[22], htons(rtcpsin_port));
2802  put_unaligned_uint16(&buffsend[24], us.sin_port);
2803  put_unaligned_uint16(&buffsend[26], htons(rtcpsin_port));
2804  } else {
2805  memcpy(buffsend + 23, &public.sin_addr, sizeof(public.sin_addr));
2806  put_unaligned_uint16(&buffsend[15], sin.sin_port);
2807  put_unaligned_uint16(&buffsend[19], us.sin_port);
2808  }
2809  buffsend[11] = codec; /* rx */
2810  buffsend[12] = codec; /* tx */
2811  send_client(SIZE_HEADER + sizeof(packet_send_open_audio_stream_rx), buffsend, pte);
2812  } else {
2813  uint16_t rtcpsin_port = htons(us.sin_port) + 1; /* RTCP port is RTP + 1 */
2814 
2815  if (unistimdebug) {
2816  ast_verb(0, "Sending packet_send_call default method\n");
2817  }
2818 
2819  memcpy(buffsend + SIZE_HEADER, packet_send_call, sizeof(packet_send_call));
2820  memcpy(buffsend + 53, &public.sin_addr, sizeof(public.sin_addr));
2821  /* Destination port when sending RTP */
2822  put_unaligned_uint16(&buffsend[49], us.sin_port);
2823  /* Destination port when sending RTCP */
2824  put_unaligned_uint16(&buffsend[51], htons(rtcpsin_port));
2825  /* Codec */
2826  buffsend[40] = codec;
2827  buffsend[41] = codec;
2829  buffsend[42] = 1; /* 1 = 20ms (160 bytes), 2 = 40ms (320 bytes) */
2831  buffsend[42] = 1; /* 1 = 20ms (160 bytes), 2 = 40ms (320 bytes) */
2833  buffsend[42] = 2; /* 1 = 30ms (24 bytes), 2 = 60 ms (48 bytes) */
2835  buffsend[42] = 2; /* 1 = 10ms (10 bytes), 2 = 20ms (20 bytes) */
2836  } else {
2837  ast_log(LOG_WARNING, "Unsupported codec %s!\n",
2839  }
2840  /* Source port for transmit RTP and Destination port for receiving RTP */
2841  put_unaligned_uint16(&buffsend[45], sin.sin_port);
2842  put_unaligned_uint16(&buffsend[47], htons(rtcpsin_port));
2843  send_client(SIZE_HEADER + sizeof(packet_send_call), buffsend, pte);
2844  }
2845 }
struct ast_channel * owner
Definition: chan_unistim.c:356
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:151
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
struct ast_rtp_codecs * ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance)
Get the codecs structure of an RTP instance.
Definition: rtp_engine.c:727
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
#define LOG_WARNING
Definition: logger.h:274
static void put_unaligned_uint16(void *p, unsigned short datum)
Definition: unaligned.h:65
#define BUFFSEND
Definition: chan_unistim.c:704
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
static const unsigned char packet_send_open_audio_stream_tx[]
Definition: chan_unistim.c:613
Socket address structure.
Definition: netsock2.h:97
#define ast_verb(level,...)
Definition: logger.h:463
int ast_rtp_codecs_payload_code_tx(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code...
Definition: rtp_engine.c:1928
static const unsigned char packet_send_open_audio_stream_rx3[]
Definition: chan_unistim.c:619
static int unistimdebug
Definition: chan_unistim.c:243
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
static const unsigned char packet_send_jitter_buffer_conf[]
Definition: chan_unistim.c:599
static struct sockaddr_in public_ip
Definition: chan_unistim.c:258
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
#define SIZE_HEADER
Definition: chan_unistim.c:167
struct unistimsession * session
Definition: chan_unistim.c:454
static const unsigned char packet_send_open_audio_stream_tx3[]
Definition: chan_unistim.c:626
static const unsigned char packet_send_call[]
Definition: chan_unistim.c:558
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
static const unsigned char packet_send_rtp_packet_size[]
Definition: chan_unistim.c:597
void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the local address that we are expecting RTP on.
Definition: rtp_engine.c:643
static const unsigned char packet_send_open_audio_stream_rx[]
Definition: chan_unistim.c:608
struct unistim_line * parent
Definition: chan_unistim.c:357
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
struct unistim_device * parent
Definition: chan_unistim.c:387
#define ast_sockaddr_to_sin(addr, sin)
Converts a struct ast_sockaddr to a struct sockaddr_in.
Definition: netsock2.h:769
struct ast_format * ast_format_g729
Built-in cached g729 format.
Definition: format_cache.c:156
#define ast_rtp_instance_get_remote_address(instance, address)
Get the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.h:1192

◆ send_start_timer()

static void send_start_timer ( struct unistimsession pte)
static

Definition at line 1127 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_start_timer, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by handle_call_incoming(), handle_call_outgoing(), sub_unhold(), and unistim_answer().

1128 {
1129  BUFFSEND;
1130  if (unistimdebug) {
1131  ast_verb(0, "Sending start timer\n");
1132  }
1133  memcpy(buffsend + SIZE_HEADER, packet_send_start_timer, sizeof(packet_send_start_timer));
1134  send_client(SIZE_HEADER + sizeof(packet_send_start_timer), buffsend, pte);
1135 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_start_timer[]
Definition: chan_unistim.c:640

◆ send_stop_timer()

static void send_stop_timer ( struct unistimsession pte)
static

Definition at line 1137 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_stop_timer, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by close_call(), handle_key_fav(), show_main_page(), and sub_hold().

1138 {
1139  BUFFSEND;
1140  if (unistimdebug) {
1141  ast_verb(0, "Sending stop timer\n");
1142  }
1143  memcpy(buffsend + SIZE_HEADER, packet_send_stop_timer, sizeof(packet_send_stop_timer));
1144  send_client(SIZE_HEADER + sizeof(packet_send_stop_timer), buffsend, pte);
1145 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
static const unsigned char packet_send_stop_timer[]
Definition: chan_unistim.c:643
#define SIZE_HEADER
Definition: chan_unistim.c:167

◆ send_text()

static void send_text ( unsigned char  pos,
unsigned char  inverse,
struct unistimsession pte,
const char *  text 
)
static

Definition at line 1578 of file chan_unistim.c.

References ast_log, ast_verb, BUFFSEND, unistimsession::device, unistim_device::height, LOG_ERROR, packet_send_text, send_client(), SIZE_HEADER, TEXT_LENGTH_MAX, TEXT_LINE0, and unistimdebug.

Referenced by ast_sendtext_data(), handle_call_incoming(), handle_call_outgoing(), handle_dial_page(), handle_select_codec(), handle_select_language(), handle_select_option(), init_phone_step2(), key_select_codec(), key_select_extension(), send_callerid_screen(), send_idle_clock(), sendtext_exec(), show_entry_history(), show_extension_page(), show_main_page(), show_phone_number(), unistim_answer(), unistim_call(), unistim_hangup(), unistim_indicate(), and unistim_sendtext().

1580 {
1581  int i;
1582  BUFFSEND;
1583  if (!text) {
1584  ast_log(LOG_ERROR, "Asked to display NULL text (pos %d, inverse flag %d)\n", pos, inverse);
1585  return;
1586  }
1587  if (pte->device && pte->device->height == 1 && pos != TEXT_LINE0) {
1588  return;
1589  }
1590  if (unistimdebug) {
1591  ast_verb(0, "Sending text at pos %d, inverse flag %d\n", pos, inverse);
1592  }
1593  memcpy(buffsend + SIZE_HEADER, packet_send_text, sizeof(packet_send_text));
1594  buffsend[10] = pos;
1595  buffsend[11] = inverse;
1596  i = strlen(text);
1597  if (i > TEXT_LENGTH_MAX) {
1598  i = TEXT_LENGTH_MAX;
1599  }
1600  memcpy(buffsend + 12, text, i);
1601  send_client(SIZE_HEADER + sizeof(packet_send_text), buffsend, pte);
1602 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
char * text
Definition: app_queue.c:1508
#define ast_verb(level,...)
Definition: logger.h:463
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
#define SIZE_HEADER
Definition: chan_unistim.c:167
#define TEXT_LINE0
Definition: chan_unistim.c:170
#define LOG_ERROR
Definition: logger.h:285
static const unsigned char packet_send_text[]
Definition: chan_unistim.c:662

◆ send_text_status()

static void send_text_status ( struct unistimsession pte,
const char *  text 
)
static

Definition at line 1604 of file chan_unistim.c.

References ast_verb, BUFFSEND, unistimsession::device, packet_send_status, packet_send_status2, send_client(), SIZE_HEADER, STATUS_LENGTH_MAX, unistim_device::status_method, and unistimdebug.

Referenced by handle_call_incoming(), handle_call_outgoing(), handle_dial_page(), handle_select_codec(), handle_select_language(), handle_select_option(), init_phone_step2(), key_dial_page(), show_entry_history(), show_extension_page(), show_main_page(), unistim_answer(), unistim_call(), and unistim_hangup().

1605 {
1606  BUFFSEND;
1607  int i;
1608  if (unistimdebug) {
1609  ast_verb(0, "Sending status text\n");
1610  }
1611  if (pte->device) {
1612  if (pte->device->status_method == 1) { /* For new firmware and i2050 soft phone */
1613  int n = strlen(text);
1614  /* Must send individual button separately */
1615  int j;
1616  for (i = 0, j = 0; i < 4; i++, j += 7) {
1617  int pos = 0x08 + (i * 0x20);
1618  memcpy(buffsend + SIZE_HEADER, packet_send_status2,
1619  sizeof(packet_send_status2));
1620 
1621  buffsend[9] = pos;
1622  memcpy(buffsend + 10, (j < n) ? (text + j) : " ", 7);
1623  send_client(SIZE_HEADER + sizeof(packet_send_status2), buffsend, pte);
1624  }
1625  return;
1626  }
1627  }
1628 
1629  memcpy(buffsend + SIZE_HEADER, packet_send_status, sizeof(packet_send_status));
1630  i = strlen(text);
1631  if (i > STATUS_LENGTH_MAX) {
1632  i = STATUS_LENGTH_MAX;
1633  }
1634  memcpy(buffsend + 10, text, i);
1635  send_client(SIZE_HEADER + sizeof(packet_send_status), buffsend, pte);
1636 
1637 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
char * text
Definition: app_queue.c:1508
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define STATUS_LENGTH_MAX
Definition: chan_unistim.c:175
struct unistim_device * device
Definition: chan_unistim.c:476
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_status2[]
Definition: chan_unistim.c:673
static const unsigned char packet_send_status[]
Definition: chan_unistim.c:668

◆ send_texttitle()

static void send_texttitle ( struct unistimsession pte,
const char *  text 
)
static

Definition at line 1741 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_title, send_client(), SIZE_HEADER, and unistimdebug.

Referenced by init_phone_step2(), show_entry_history(), and show_main_page().

1742 {
1743  BUFFSEND;
1744  int i;
1745  if (unistimdebug) {
1746  ast_verb(0, "Sending title text\n");
1747  }
1748  memcpy(buffsend + SIZE_HEADER, packet_send_title, sizeof(packet_send_title));
1749  i = strlen(text);
1750  if (i > 12) {
1751  i = 12;
1752  }
1753  memcpy(buffsend + 10, text, i);
1754  send_client(SIZE_HEADER + sizeof(packet_send_title), buffsend, pte);
1755 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
#define BUFFSEND
Definition: chan_unistim.c:704
char * text
Definition: app_queue.c:1508
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167
static const unsigned char packet_send_title[]
Definition: chan_unistim.c:659

◆ send_tone()

static void send_tone ( struct unistimsession pte,
uint16_t  tone1,
uint16_t  tone2 
)
static

Definition at line 1201 of file chan_unistim.c.

References ast_verb, BUFFSEND, packet_send_stream_based_tone_dual_freq, packet_send_stream_based_tone_off, packet_send_stream_based_tone_on, packet_send_stream_based_tone_single_freq, put_unaligned_uint16(), send_client(), SIZE_HEADER, and unistimdebug.

Referenced by handle_call_outgoing(), handle_key_fav(), key_dial_page(), send_dial_tone(), send_dtmf_tone(), show_main_page(), unistim_do_senddigit(), unistim_senddigit_end(), and unistim_ss().

1202 {
1203  BUFFSEND;
1204  if (!tone1) {
1205  if (unistimdebug) {
1206  ast_verb(0, "Sending Stream Based Tone Off\n");
1207  }
1210  send_client(SIZE_HEADER + sizeof(packet_send_stream_based_tone_off), buffsend, pte);
1211  return;
1212  }
1213  /* Since most of the world use a continuous tone, it's useless
1214  if (unistimdebug)
1215  ast_verb(0, "Sending Stream Based Tone Cadence Download\n");
1216  memcpy (buffsend + SIZE_HEADER, packet_send_StreamBasedToneCad, sizeof (packet_send_StreamBasedToneCad));
1217  send_client (SIZE_HEADER + sizeof (packet_send_StreamBasedToneCad), buffsend, pte); */
1218  if (unistimdebug) {
1219  ast_verb(0, "Sending Stream Based Tone Frequency Component List Download %d %d\n", tone1, tone2);
1220  }
1221  tone1 *= 8;
1222  if (!tone2) {
1225  put_unaligned_uint16(&buffsend[10], htons(tone1));
1227  pte);
1228  } else {
1229  tone2 *= 8;
1232  put_unaligned_uint16(&buffsend[10], htons(tone1));
1233  put_unaligned_uint16(&buffsend[12], htons(tone2));
1235  pte);
1236  }
1237 
1238  if (unistimdebug) {
1239  ast_verb(0, "Sending Stream Based Tone On\n");
1240  }
1241  memcpy(buffsend + SIZE_HEADER, packet_send_stream_based_tone_on,
1243  send_client(SIZE_HEADER + sizeof(packet_send_stream_based_tone_on), buffsend, pte);
1244 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
static const unsigned char packet_send_stream_based_tone_off[]
Definition: chan_unistim.c:567
static const unsigned char packet_send_stream_based_tone_single_freq[]
Definition: chan_unistim.c:577
static const unsigned char packet_send_stream_based_tone_dual_freq[]
Definition: chan_unistim.c:579
static void put_unaligned_uint16(void *p, unsigned short datum)
Definition: unaligned.h:65
#define BUFFSEND
Definition: chan_unistim.c:704
static const unsigned char packet_send_stream_based_tone_on[]
Definition: chan_unistim.c:575
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define SIZE_HEADER
Definition: chan_unistim.c:167

◆ set_ping_timer()

static void set_ping_timer ( struct unistimsession pte)
static

Definition at line 1090 of file chan_unistim.c.

References DEBUG_TIMER, unistimsession::tick_next_ping, and unistimsession::timeout.

Referenced by check_send_queue().

1091 {
1092  unsigned int tick = 0; /* XXX what is this for, anyways */
1093 
1094  pte->timeout = pte->tick_next_ping;
1095  DEBUG_TIMER("tick = %u next ping at %u tick\n", tick, pte->timeout);
1096  return;
1097 }
#define DEBUG_TIMER
Definition: chan_unistim.c:241
unsigned long tick_next_ping
Definition: chan_unistim.c:466

◆ show_entry_history()

static void show_entry_history ( struct unistimsession pte,
FILE **  f 
)
static

Definition at line 3984 of file chan_unistim.c.

References ast_copy_string(), ast_trim_blanks(), unistimsession::buff_entry, unistimsession::device, display_last_error(), unistim_device::height, unistim_device::lst_cid, send_text(), send_text_status(), send_texttitle(), status, STATUS_LENGTH_MAX, TEXT_LENGTH_MAX, TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, and ustmtext().

Referenced by key_history(), and show_history().

3985 {
3986  char line[TEXT_LENGTH_MAX + 1], status[STATUS_LENGTH_MAX + 1], func1[10], func2[10],
3987  func3[10];
3988 
3989  /* Display date/time and call status */
3990  if (fread(line, TEXT_LENGTH_MAX, 1, *f) != 1) {
3991  display_last_error("Can't read history date entry");
3992  fclose(*f);
3993  return;
3994  }
3995  line[sizeof(line) - 1] = '\0';
3996  if (pte->device->height == 1) {
3997  if (pte->buff_entry[3] == 1) {
3998  send_text(TEXT_LINE0, TEXT_NORMAL, pte, line);
3999  }
4000  } else {
4001  send_text(TEXT_LINE0, TEXT_NORMAL, pte, line);
4002  }
4003  /* Display number */
4004  if (fread(line, TEXT_LENGTH_MAX, 1, *f) != 1) {
4005  display_last_error("Can't read callerid entry");
4006  fclose(*f);
4007  return;
4008  }
4009  line[sizeof(line) - 1] = '\0';
4010  ast_copy_string(pte->device->lst_cid, line, sizeof(pte->device->lst_cid));
4012  if (pte->device->height == 1) {
4013  if (pte->buff_entry[3] == 2) {
4014  send_text(TEXT_LINE0, TEXT_NORMAL, pte, line);
4015  }
4016  } else {
4017  send_text(TEXT_LINE1, TEXT_NORMAL, pte, line);
4018  }
4019  /* Display name */
4020  if (fread(line, TEXT_LENGTH_MAX, 1, *f) != 1) {
4021  display_last_error("Can't read callername entry");
4022  fclose(*f);
4023  return;
4024  }
4025  line[sizeof(line) - 1] = '\0';
4026  if (pte->device->height == 1) {
4027  if (pte->buff_entry[3] == 3) {
4028  send_text(TEXT_LINE0, TEXT_NORMAL, pte, line);
4029  }
4030  } else {
4031  send_text(TEXT_LINE2, TEXT_NORMAL, pte, line);
4032  }
4033  fclose(*f);
4034 
4035  snprintf(line, sizeof(line), "%s %03d/%03d", ustmtext("Call", pte), pte->buff_entry[2],
4036  pte->buff_entry[1]);
4037  send_texttitle(pte, line);
4038 
4039  if (pte->buff_entry[2] == 1) {
4040  ast_copy_string(func1, " ", sizeof(func1));
4041  } else {
4042  ast_copy_string(func1, ustmtext("Prev ", pte), sizeof(func1));
4043  }
4044  if (pte->buff_entry[2] >= pte->buff_entry[1]) {
4045  ast_copy_string(func2, " ", sizeof(func2));
4046  } else {
4047  ast_copy_string(func2, ustmtext("Next ", pte), sizeof(func2));
4048  }
4049  if (strlen(pte->device->lst_cid)) {
4050  ast_copy_string(func3, ustmtext("Redial ", pte), sizeof(func3));
4051  } else {
4052  ast_copy_string(func3, " ", sizeof(func3));
4053  }
4054  snprintf(status, sizeof(status), "%s%s%s%s", func1, func2, func3, ustmtext("Cancel", pte));
4055  send_text_status(pte, status);
4056 }
#define TEXT_LINE2
Definition: chan_unistim.c:172
#define TEXT_LINE1
Definition: chan_unistim.c:171
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
#define STATUS_LENGTH_MAX
Definition: chan_unistim.c:175
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_texttitle(struct unistimsession *pte, const char *text)
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text_status(struct unistimsession *pte, const char *text)
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
Definition: strings.h:182
char lst_cid[TEXT_LENGTH_MAX]
Definition: chan_unistim.c:436
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char buff_entry[16]
Definition: chan_unistim.c:471
static void display_last_error(const char *sz_msg)
Definition: chan_unistim.c:889
jack_status_t status
Definition: app_jack.c:146

◆ show_extension_page()

static void show_extension_page ( struct unistimsession pte)
static

Definition at line 3876 of file chan_unistim.c.

References SELECTEXTENSION_MSG, SELECTEXTENSION_START_ENTRY_POS, send_blink_cursor(), send_cursor_pos(), send_text(), send_text_status(), unistimsession::size_buff_entry, unistimsession::state, STATE_EXTENSION, TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, and ustmtext().

Referenced by init_phone_step2(), key_main_page(), and show_main_page().

3877 {
3878  pte->state = STATE_EXTENSION;
3879 
3880  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext("Please enter a Terminal", pte));
3881  send_text(TEXT_LINE1, TEXT_NORMAL, pte, ustmtext("Number (TN) :", pte));
3883  send_blink_cursor(pte);
3885  send_text_status(pte, ustmtext("Enter BackSpcErase", pte));
3886  pte->size_buff_entry = 0;
3887  return;
3888 }
#define SELECTEXTENSION_START_ENTRY_POS
#define TEXT_LINE2
Definition: chan_unistim.c:172
#define TEXT_LINE1
Definition: chan_unistim.c:171
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
static void send_blink_cursor(struct unistimsession *pte)
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_text_status(struct unistimsession *pte, const char *text)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static void send_cursor_pos(struct unistimsession *pte, unsigned char pos)
#define SELECTEXTENSION_MSG

◆ show_history()

static void show_history ( struct unistimsession pte,
char  way 
)
static

Definition at line 4086 of file chan_unistim.c.

References unistimsession::buff_entry, unistim_device::callhistory, unistimsession::device, open_history(), show_entry_history(), unistimsession::state, and STATE_HISTORY.

Referenced by key_history(), and key_main_page().

4087 {
4088  FILE *f;
4089  char count;
4090 
4091  if (!pte->device) {
4092  return;
4093  }
4094  if (!pte->device->callhistory) {
4095  return;
4096  }
4097  count = open_history(pte, way, &f);
4098  if (!count) {
4099  return;
4100  }
4101  pte->buff_entry[0] = way;
4102  pte->buff_entry[1] = count;
4103  pte->buff_entry[2] = 1;
4104  pte->buff_entry[3] = 1;
4105  show_entry_history(pte, &f);
4106  pte->state = STATE_HISTORY;
4107 }
struct unistim_device * device
Definition: chan_unistim.c:476
static char open_history(struct unistimsession *pte, char way, FILE **f)
char buff_entry[16]
Definition: chan_unistim.c:471
static void show_entry_history(struct unistimsession *pte, FILE **f)

◆ show_main_page()

static void show_main_page ( struct unistimsession pte)
static

Definition at line 4109 of file chan_unistim.c.

References ast_inet_ntoa(), ast_strlen_zero, unistim_device::call_forward, change_favorite_icon(), unistimsession::device, unistim_device::extension, EXTENSION_ASK, unistim_device::extension_number, EXTENSION_TN, FAV_BLINK_SLOW, FAV_ICON_CALL_CENTER, FAV_ICON_REFLECT, FAV_LINE_ICON, unistim_device::height, unistim_device::lastmsgssent, LED_BAR_OFF, LED_HEADPHONE_OFF, LED_SPEAKER_OFF, unistim_device::maintext0, unistim_device::maintext1, unistim_device::maintext2, unistim_device::missed_call, MUTE_ON_DISCRET, unistim_device::output, unistim_device::redial_number, send_date_time2(), send_icon(), send_idle_clock(), send_led_update(), send_select_output(), send_stop_timer(), send_text(), send_text_status(), send_texttitle(), send_tone(), show_extension_page(), unistimsession::sin, unistimsession::state, STATE_MAINPAGE, text, TEXT_LENGTH_MAX, TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, unistim_device::titledefault, ustmtext(), and unistim_device::volume.

Referenced by close_call(), handle_key_fav(), init_phone_step2(), key_dial_page(), key_history(), key_main_page(), key_select_codec(), key_select_extension(), key_select_language(), key_select_option(), process_request(), and unistim_hangup().

4110 {
4111  char tmpbuf[TEXT_LENGTH_MAX + 1];
4112  const char *text;
4113 
4114  if ((pte->device->extension == EXTENSION_ASK) &&
4116  show_extension_page(pte);
4117  return;
4118  }
4119 
4120  pte->state = STATE_MAINPAGE;
4122  pte->device->lastmsgssent = -1;
4123 
4124  send_tone(pte, 0, 0);
4125  send_stop_timer(pte); /* case of holding call */
4129 
4130  if (!ast_strlen_zero(pte->device->call_forward)) {
4131  if (pte->device->height == 1) {
4132  char tmp_field[100];
4133  snprintf(tmp_field, sizeof(tmp_field), "%s %s", ustmtext("Fwd to:", pte), pte->device->call_forward);
4134  send_text(TEXT_LINE0, TEXT_NORMAL, pte, tmp_field);
4135  } else {
4136  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext("Call forwarded to :", pte));
4138  }
4140  if (ast_strlen_zero(pte->device->redial_number)) {
4141  send_text_status(pte, ustmtext("Dial NoFwd ", pte));
4142  } else {
4143  send_text_status(pte, ustmtext("Dial Redial NoFwd ", pte));
4144  }
4145  } else {
4146  if ((pte->device->extension == EXTENSION_ASK) || (pte->device->extension == EXTENSION_TN)) {
4147  if (ast_strlen_zero(pte->device->redial_number)) {
4148  send_text_status(pte, ustmtext("Dial Fwd Unregis", pte));
4149  } else {
4150  send_text_status(pte, ustmtext("Dial Redial Fwd Unregis", pte));
4151  }
4152  } else {
4153  if (ast_strlen_zero(pte->device->redial_number)) {
4154  send_text_status(pte, ustmtext("Dial Fwd Pickup", pte));
4155  } else {
4156  send_text_status(pte, ustmtext("Dial Redial Fwd Pickup", pte));
4157  }
4158  }
4160  if (pte->device->missed_call == 0) {
4161  send_date_time2(pte);
4162  send_idle_clock(pte);
4163  if (strlen(pte->device->maintext0)) {
4165  }
4166  } else {
4167  if (pte->device->missed_call == 1) {
4168  text = ustmtext("unanswered call", pte);
4169  } else {
4170  text = ustmtext("unanswered calls", pte);
4171  }
4172  snprintf(tmpbuf, sizeof(tmpbuf), "%d %s", pte->device->missed_call, text);
4173  send_text(TEXT_LINE0, TEXT_NORMAL, pte, tmpbuf);
4175  }
4176  }
4177  if (pte->device->height > 1) {
4178  if (ast_strlen_zero(pte->device->maintext2)) {
4179  strcpy(tmpbuf, "IP : ");
4180  strcat(tmpbuf, ast_inet_ntoa(pte->sin.sin_addr));
4181  send_text(TEXT_LINE2, TEXT_NORMAL, pte, tmpbuf);
4182  } else {
4184  }
4185  }
4186 
4187  send_texttitle(pte, ustmtext(pte->device->titledefault, pte));
4189 }
char call_forward[AST_MAX_EXTENSION]
Definition: chan_unistim.c:438
#define TEXT_LINE2
Definition: chan_unistim.c:172
static void show_extension_page(struct unistimsession *pte)
#define TEXT_LINE1
Definition: chan_unistim.c:171
static void change_favorite_icon(struct unistimsession *pte, unsigned char status)
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
char * text
Definition: app_queue.c:1508
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define LED_SPEAKER_OFF
Definition: chan_unistim.c:159
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_icon(unsigned char pos, unsigned char status, struct unistimsession *pte)
static void send_texttitle(struct unistimsession *pte, const char *text)
char titledefault[13]
Definition: chan_unistim.c:417
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
#define FAV_BLINK_SLOW
Definition: chan_unistim.c:212
static void send_idle_clock(struct unistimsession *pte)
#define TEXT_LINE0
Definition: chan_unistim.c:170
char maintext0[25]
Definition: chan_unistim.c:414
#define FAV_LINE_ICON
Definition: chan_unistim.c:218
enum autoprov_extn extension
Definition: chan_unistim.c:447
static void send_stop_timer(struct unistimsession *pte)
static void send_text_status(struct unistimsession *pte, const char *text)
#define FAV_ICON_CALL_CENTER
Definition: chan_unistim.c:198
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
struct sockaddr_in sin
Definition: chan_unistim.c:460
static void send_led_update(struct unistimsession *pte, unsigned char led)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
#define MUTE_ON_DISCRET
Definition: chan_unistim.c:149
#define LED_BAR_OFF
Definition: chan_unistim.c:151
char maintext1[25]
Definition: chan_unistim.c:415
#define LED_HEADPHONE_OFF
Definition: chan_unistim.c:161
#define FAV_ICON_REFLECT
Definition: chan_unistim.c:201
static void send_date_time2(struct unistimsession *pte)
char extension_number[11]
Definition: chan_unistim.c:448
char redial_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:400
char maintext2[25]
Definition: chan_unistim.c:416

◆ show_phone_number()

static void show_phone_number ( struct unistimsession pte)
static

Definition at line 2944 of file chan_unistim.c.

References ast_copy_string(), unistimsession::device, unistim_device::height, LED_BAR_OFF, MAX_SCREEN_NUMBER, unistim_device::phone_number, send_blink_cursor(), send_cursor_pos(), send_led_update(), send_text(), unistim_device::size_phone_number, TEXT_LENGTH_MAX, TEXT_LINE0, TEXT_LINE2, TEXT_NORMAL, tmp(), and ustmtext().

Referenced by handle_dial_page(), and key_dial_page().

2945 {
2946  char tmp[TEXT_LENGTH_MAX + 1];
2947  const char *tmp_number = ustmtext("Number:", pte);
2948  int line, tmp_copy, offset = 0, i;
2949 
2950  pte->device->phone_number[pte->device->size_phone_number] = '\0';
2952  offset = pte->device->size_phone_number - MAX_SCREEN_NUMBER - 1;
2953  if (offset > strlen(tmp_number)) {
2954  offset = strlen(tmp_number);
2955  }
2956  tmp_copy = strlen(tmp_number) - offset + 1;
2957  if (tmp_copy > sizeof(tmp)) {
2958  tmp_copy = sizeof(tmp);
2959  }
2960  memcpy(tmp, tmp_number + offset, tmp_copy);
2961  } else {
2962  ast_copy_string(tmp, tmp_number, sizeof(tmp));
2963  }
2964 
2965  offset = (pte->device->size_phone_number >= TEXT_LENGTH_MAX) ? (pte->device->size_phone_number - TEXT_LENGTH_MAX +1) : 0;
2966  if (pte->device->size_phone_number) {
2967  memcpy(tmp + strlen(tmp), pte->device->phone_number + offset, pte->device->size_phone_number - offset + 1);
2968  }
2969  offset = strlen(tmp);
2970 
2971  for (i = strlen(tmp); i < TEXT_LENGTH_MAX; i++) {
2972  tmp[i] = '.';
2973  }
2974  tmp[i] = '\0';
2975 
2976  line = (pte->device->height == 1) ? TEXT_LINE0 : TEXT_LINE2;
2977  send_text(line, TEXT_NORMAL, pte, tmp);
2978  send_blink_cursor(pte);
2979  send_cursor_pos(pte, (unsigned char) (line + offset));
2981 }
#define TEXT_LINE2
Definition: chan_unistim.c:172
char phone_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:399
static int tmp()
Definition: bt_open.c:389
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
static void send_blink_cursor(struct unistimsession *pte)
struct unistim_device * device
Definition: chan_unistim.c:476
#define TEXT_LINE0
Definition: chan_unistim.c:170
#define MAX_SCREEN_NUMBER
Definition: chan_unistim.c:95
static void send_led_update(struct unistimsession *pte, unsigned char led)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static void send_cursor_pos(struct unistimsession *pte, unsigned char pos)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define LED_BAR_OFF
Definition: chan_unistim.c:151

◆ soft_key_visible()

static int soft_key_visible ( struct unistim_device d,
unsigned char  num 
)
static

Definition at line 1313 of file chan_unistim.c.

References unistim_device::height.

Referenced by get_avail_softkey(), refresh_all_favorite(), unistim_call(), unistim_hangup(), and unistim_show_info().

1314 {
1315  if(d->height == 1 && num % 3 == 2) {
1316  return 0;
1317  }
1318  return 1;
1319 }

◆ start_rtp()

static void start_rtp ( struct unistim_subchannel sub)
static

Definition at line 2847 of file chan_unistim.c.

References ao2_ref, ast_channel_internal_fd_set(), ast_channel_nativeformats(), ast_channel_readformat(), ast_channel_set_readformat(), ast_channel_set_writeformat(), ast_channel_uniqueid(), ast_format_cap_get_format(), ast_format_cap_get_names(), ast_format_cap_iscompatible_format(), AST_FORMAT_CAP_NAMES_LEN, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_name(), ast_inet_ntoa(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_rtp_instance_fd(), ast_rtp_instance_new(), ast_rtp_instance_set_channel_id(), ast_rtp_instance_set_prop(), ast_rtp_instance_set_qos(), ast_rtp_instance_set_remote_address, AST_RTP_PROPERTY_NAT, AST_RTP_PROPERTY_RTCP, ast_sockaddr_from_sin, ast_str_alloca, ast_verb, errno, find_rtp_port(), unistim_subchannel::lock, LOG_WARNING, unistim_device::nat, NULL, unistim_subchannel::owner, unistim_subchannel::parent, unistim_line::parent, qos, unistim_subchannel::rtp, send_start_rtp(), unistim_device::session, unistimsession::sin, unistimsession::sout, and unistimdebug.

Referenced by handle_call_incoming(), and handle_call_outgoing().

2848 {
2849  struct sockaddr_in sin = { 0, };
2850  struct sockaddr_in sout = { 0, };
2851  struct ast_sockaddr sin_tmp;
2852  struct ast_sockaddr sout_tmp;
2853 
2854  /* Sanity checks */
2855  if (!sub) {
2856  ast_log(LOG_WARNING, "start_rtp with a null subchannel !\n");
2857  return;
2858  }
2859  if (!sub->parent) {
2860  ast_log(LOG_WARNING, "start_rtp with a null line!\n");
2861  return;
2862  }
2863  if (!sub->parent->parent) {
2864  ast_log(LOG_WARNING, "start_rtp with a null device!\n");
2865  return;
2866  }
2867  if (!sub->parent->parent->session) {
2868  ast_log(LOG_WARNING, "start_rtp with a null session!\n");
2869  return;
2870  }
2871  if (!sub->owner) {
2872  ast_log(LOG_WARNING, "start_rtp with a null asterisk channel!\n");
2873  return;
2874  }
2875  sout = sub->parent->parent->session->sout;
2876  ast_mutex_lock(&sub->lock);
2877  /* Allocate the RTP */
2878  if (unistimdebug) {
2879  ast_verb(0, "Starting RTP. Bind on %s\n", ast_inet_ntoa(sout.sin_addr));
2880  }
2881  ast_sockaddr_from_sin(&sout_tmp, &sout);
2882  sub->rtp = ast_rtp_instance_new("asterisk", sched, &sout_tmp, NULL);
2883  if (!sub->rtp) {
2884  ast_log(LOG_WARNING, "Unable to create RTP session: %s binaddr=%s\n",
2885  strerror(errno), ast_inet_ntoa(sout.sin_addr));
2886  ast_mutex_unlock(&sub->lock);
2887  return;
2888  }
2893  ast_rtp_instance_set_qos(sub->rtp, qos.tos_audio, qos.cos_audio, "UNISTIM RTP");
2895 
2896  /* Create the RTP connection */
2897  sin.sin_family = AF_INET;
2898  /* Setting up RTP for our side */
2899  memcpy(&sin.sin_addr, &sub->parent->parent->session->sin.sin_addr,
2900  sizeof(sin.sin_addr));
2901 
2902  sin.sin_port = htons(find_rtp_port(sub));
2903  ast_sockaddr_from_sin(&sin_tmp, &sin);
2904  ast_rtp_instance_set_remote_address(sub->rtp, &sin_tmp);
2906  struct ast_format *tmpfmt;
2907  struct ast_str *cap_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
2908 
2911  "Our read/writeformat has been changed to something incompatible: %s, using %s best codec from %s\n",
2913  ast_format_get_name(tmpfmt),
2915 
2916  ast_channel_set_readformat(sub->owner, tmpfmt);
2917  ast_channel_set_writeformat(sub->owner, tmpfmt);
2918  ao2_ref(tmpfmt, -1);
2919  }
2920  send_start_rtp(sub);
2921  ast_mutex_unlock(&sub->lock);
2922 }
ast_mutex_t lock
Definition: chan_unistim.c:354
struct ast_channel * owner
Definition: chan_unistim.c:356
struct sockaddr_in sout
Definition: chan_unistim.c:461
void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
Set the channel that owns this RTP instance.
Definition: rtp_engine.c:553
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
static struct @149 qos
#define LOG_WARNING
Definition: logger.h:274
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
Set QoS parameters on an RTP session.
Definition: rtp_engine.c:2169
Definition: sched.c:76
static int find_rtp_port(struct unistim_subchannel *s)
Definition of a media format.
Definition: format.c:43
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define NULL
Definition: resample.c:96
Socket address structure.
Definition: netsock2.h:97
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
enum ast_format_cmp_res ast_format_cap_iscompatible_format(const struct ast_format_cap *cap, const struct ast_format *format)
Find if ast_format is within the capabilities of the ast_format_cap object.
Definition: format_cap.c:583
#define ast_log
Definition: astobj2.c:42
#define ast_sockaddr_from_sin(addr, sin)
Converts a struct sockaddr_in to a struct ast_sockaddr.
Definition: netsock2.h:782
struct unistimsession * session
Definition: chan_unistim.c:454
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_rtp_instance_set_remote_address(instance, address)
Set the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.h:1080
int errno
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
Get the file descriptor for an RTP session (or RTCP)
Definition: rtp_engine.c:2192
struct sockaddr_in sin
Definition: chan_unistim.c:460
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct unistim_line * parent
Definition: chan_unistim.c:357
struct unistim_device * parent
Definition: chan_unistim.c:387
static void send_start_rtp(struct unistim_subchannel *)
void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Set the value of an RTP instance property.
Definition: rtp_engine.c:705
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
struct ast_rtp_instance * ast_rtp_instance_new(const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
Create a new RTP instance.
Definition: rtp_engine.c:465
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ sub_hold()

static void sub_hold ( struct unistimsession pte,
struct unistim_subchannel sub 
)
static

Definition at line 2560 of file chan_unistim.c.

References ast_queue_hold(), unistimsession::device, FAV_BLINK_SLOW, FAV_ICON_ONHOLD_BLACK, unistim_subchannel::holding, unistim_subchannel::moh, MUTE_ON, NULL, unistim_device::output, unistim_subchannel::owner, send_favorite_short(), send_select_output(), send_stop_timer(), unistim_subchannel::softkey, and unistim_device::volume.

Referenced by handle_call_incoming(), handle_call_outgoing(), handle_key_fav(), key_call(), and sub_unhold().

2561 {
2562  if (!sub) {
2563  return;
2564  }
2565  sub->moh = 1;
2566  sub->holding = 1;
2568  send_select_output(pte, pte->device->output, pte->device->volume, MUTE_ON);
2569  send_stop_timer(pte);
2570  if (sub->owner) {
2571  ast_queue_hold(sub->owner, NULL);
2572  }
2573  return;
2574 }
struct ast_channel * owner
Definition: chan_unistim.c:356
#define FAV_ICON_ONHOLD_BLACK
Definition: chan_unistim.c:184
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
#define NULL
Definition: resample.c:96
struct unistim_device * device
Definition: chan_unistim.c:476
#define FAV_BLINK_SLOW
Definition: chan_unistim.c:212
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition: channel.c:1191
static void send_stop_timer(struct unistimsession *pte)
#define MUTE_ON
Definition: chan_unistim.c:148

◆ sub_start_silence()

static void sub_start_silence ( struct unistimsession pte,
struct unistim_subchannel sub 
)
static

Definition at line 2529 of file chan_unistim.c.

References ast_channel_start_silence_generator(), ast_log, ast_verb, unistimsession::device, LOG_WARNING, NULL, unistim_subchannel::owner, unistim_device::silence_generator, and unistimdebug.

Referenced by transfer_call_step1().

2530 {
2531  /* Silence our channel */
2532  if (!pte->device->silence_generator) {
2533  pte->device->silence_generator =
2535  if (pte->device->silence_generator == NULL) {
2536  ast_log(LOG_WARNING, "Unable to start a silence generator.\n");
2537  } else if (unistimdebug) {
2538  ast_verb(0, "Starting silence generator\n");
2539  }
2540  }
2541 
2542 }
struct ast_channel * owner
Definition: chan_unistim.c:356
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8266
struct ast_silence_generator * silence_generator
Definition: chan_unistim.c:450

◆ sub_stop_silence()

static void sub_stop_silence ( struct unistimsession pte,
struct unistim_subchannel sub 
)
static

Definition at line 2544 of file chan_unistim.c.

References ast_channel_stop_silence_generator(), ast_log, ast_verb, unistimsession::device, LOG_WARNING, NULL, unistim_subchannel::owner, unistim_device::silence_generator, and unistimdebug.

Referenced by handle_call_outgoing(), key_dial_page(), and unistim_hangup().

2545 {
2546  /* Stop the silence generator */
2547  if (pte->device->silence_generator) {
2548  if (unistimdebug) {
2549  ast_verb(0, "Stopping silence generator\n");
2550  }
2551  if (sub->owner) {
2553  } else {
2554  ast_log(LOG_WARNING, "Trying to stop silence generator on a null channel!\n");
2555  }
2556  pte->device->silence_generator = NULL;
2557  }
2558 }
struct ast_channel * owner
Definition: chan_unistim.c:356
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
Definition: channel.c:8312
struct ast_silence_generator * silence_generator
Definition: chan_unistim.c:450

◆ sub_unhold()

static void sub_unhold ( struct unistimsession pte,
struct unistim_subchannel sub 
)
static

Definition at line 2576 of file chan_unistim.c.

References ast_queue_unhold(), unistimsession::device, FAV_ICON_OFFHOOK_BLACK, get_sub(), unistim_subchannel::holding, unistim_subchannel::moh, MUTE_OFF, unistim_device::output, unistim_subchannel::owner, unistim_subchannel::rtp, send_favorite_short(), send_select_output(), send_start_rtp(), send_start_timer(), unistim_subchannel::softkey, sub_hold(), SUB_REAL, and unistim_device::volume.

Referenced by handle_key_fav(), and key_call().

2577 {
2578  struct unistim_subchannel *sub_real;
2579 
2580  sub_real = get_sub(pte->device, SUB_REAL);
2581  if (sub_real) {
2582  sub_hold(pte, sub_real);
2583  }
2584 
2585  sub->moh = 0;
2586  sub->holding = 0;
2588  send_select_output(pte, pte->device->output, pte->device->volume, MUTE_OFF);
2589  send_start_timer(pte);
2590  if (sub->owner) {
2591  ast_queue_unhold(sub->owner);
2592  if (sub->rtp) {
2593  send_start_rtp(sub);
2594  }
2595  }
2596  return;
2597 }
struct ast_channel * owner
Definition: chan_unistim.c:356
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1216
static void sub_hold(struct unistimsession *pte, struct unistim_subchannel *sub)
static void send_select_output(struct unistimsession *pte, unsigned char output, unsigned char volume, unsigned char mute)
struct unistim_device * device
Definition: chan_unistim.c:476
#define MUTE_OFF
Definition: chan_unistim.c:147
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
#define SUB_REAL
Definition: chan_unistim.c:116
static void send_start_timer(struct unistimsession *pte)
static void send_start_rtp(struct unistim_subchannel *)
#define FAV_ICON_OFFHOOK_BLACK
Definition: chan_unistim.c:182

◆ subtype_tostr()

static const char* subtype_tostr ( const int  type)
static

Definition at line 2027 of file chan_unistim.c.

References SUB_REAL, SUB_RING, and SUB_THREEWAY.

Referenced by unistim_show_info().

2028 {
2029  switch (type) {
2030  case SUB_REAL:
2031  return "REAL";
2032  case SUB_RING:
2033  return "RINGING";
2034  case SUB_THREEWAY:
2035  return "THREEWAY";
2036  }
2037  return "UNKNOWN";
2038 }
static const char type[]
Definition: chan_ooh323.c:109
#define SUB_RING
Definition: chan_unistim.c:117
#define SUB_THREEWAY
Definition: chan_unistim.c:118
#define SUB_REAL
Definition: chan_unistim.c:116

◆ swap_subs()

static void swap_subs ( struct unistim_subchannel a,
struct unistim_subchannel b 
)
static

Definition at line 3028 of file chan_unistim.c.

References ast_channel_fd(), ast_channel_internal_fd_set(), ast_log, ast_verb, LOG_WARNING, unistim_subchannel::owner, unistim_subchannel::rtp, and unistimdebug.

Referenced by handle_call_outgoing(), transfer_cancel_step2(), and unistim_hangup().

3029 {
3030  struct ast_rtp_instance *rtp;
3031  int fds;
3032 
3033  if (unistimdebug) {
3034  ast_verb(0, "Swapping %p and %p\n", a, b);
3035  }
3036  if ((!a->owner) || (!b->owner)) {
3038  "Attempted to swap subchannels with a null owner : sub #%p=%p sub #%p=%p\n",
3039  a, a->owner, b, b->owner);
3040  return;
3041  }
3042  rtp = a->rtp;
3043  a->rtp = b->rtp;
3044  b->rtp = rtp;
3045 
3046  fds = ast_channel_fd(a->owner, 0);
3048  ast_channel_internal_fd_set(b->owner, 0, fds);
3049 
3050  fds = ast_channel_fd(a->owner, 1);
3052  ast_channel_internal_fd_set(b->owner, 1, fds);
3053 }
struct ast_channel * owner
Definition: chan_unistim.c:356
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
#define LOG_WARNING
Definition: logger.h:274
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_log
Definition: astobj2.c:42
int ast_channel_fd(const struct ast_channel *chan, int which)
void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)

◆ transfer_call_step1()

static void transfer_call_step1 ( struct unistimsession pte)
static

Definition at line 3056 of file chan_unistim.c.

References ast_log, ast_queue_hold(), d, unistimsession::device, get_sub(), handle_dial_page(), LOG_WARNING, unistim_subchannel::moh, unistim_line::musicclass, unistim_subchannel::owner, unistim_subchannel::parent, sub, SUB_REAL, sub_start_silence(), SUB_THREEWAY, and unistim_subchannel::subtype.

Referenced by key_call().

3057 {
3058  struct unistim_subchannel *sub /*, *sub_trans */;
3059  struct unistim_device *d = pte->device;
3060 
3061  sub = get_sub(d, SUB_REAL);
3062  /* sub_trans = get_sub(d, SUB_THREEWAY); */
3063 
3064  if (!sub || !sub->owner) {
3065  ast_log(LOG_WARNING, "Unable to find subchannel for music on hold\n");
3066  return;
3067  }
3068  /* Start music on hold if appropriate */
3069  if (sub->moh) {
3070  ast_log(LOG_WARNING, "Transfer with peer already listening music on hold\n");
3071  } else {
3072  ast_queue_hold(sub->owner, sub->parent->musicclass);
3073  sub->moh = 1;
3074  sub->subtype = SUB_THREEWAY;
3075  }
3076  sub_start_silence(pte, sub);
3077  handle_dial_page(pte);
3078 }
struct ast_channel * owner
Definition: chan_unistim.c:356
A device containing one or more lines.
Definition: chan_unistim.c:394
#define LOG_WARNING
Definition: logger.h:274
static struct test_val d
#define SUB_THREEWAY
Definition: chan_unistim.c:118
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
#define ast_log
Definition: astobj2.c:42
static void handle_dial_page(struct unistimsession *pte)
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition: channel.c:1191
char musicclass[MAX_MUSICCLASS]
Definition: chan_unistim.c:379
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
#define SUB_REAL
Definition: chan_unistim.c:116
struct unistim_line * parent
Definition: chan_unistim.c:357
struct stasis_forward * sub
Definition: res_corosync.c:240
static void sub_start_silence(struct unistimsession *pte, struct unistim_subchannel *sub)

◆ transfer_cancel_step2()

static void transfer_cancel_step2 ( struct unistimsession pte)
static

Definition at line 3080 of file chan_unistim.c.

References AST_CAUSE_NORMAL_CLEARING, ast_log, ast_queue_hangup_with_cause(), ast_queue_unhold(), ast_verb, d, unistimsession::device, get_sub(), LOG_WARNING, unistim_subchannel::moh, unistim_subchannel::owner, sub, SUB_REAL, SUB_THREEWAY, unistim_subchannel::subtype, swap_subs(), and unistimdebug.

Referenced by key_call().

3081 {
3082  struct unistim_subchannel *sub, *sub_trans;
3083  struct unistim_device *d = pte->device;
3084 
3085  sub = get_sub(d, SUB_REAL);
3086  sub_trans = get_sub(d, SUB_THREEWAY);
3087 
3088  if (!sub || !sub->owner) {
3089  ast_log(LOG_WARNING, "Unable to find subchannel for music on hold\n");
3090  return;
3091  }
3092  if (sub_trans) {
3093  if (unistimdebug) {
3094  ast_verb(0, "Transfer canceled, hangup our threeway channel\n");
3095  }
3096  if (sub->owner) {
3097  swap_subs(sub, sub_trans);
3098  ast_queue_unhold(sub_trans->owner);
3099  sub_trans->moh = 0;
3100  sub_trans->subtype = SUB_REAL;
3101  sub->subtype = SUB_THREEWAY;
3103  } else {
3104  ast_log(LOG_WARNING, "Canceling a threeway channel without owner\n");
3105  }
3106  return;
3107  }
3108 }
struct ast_channel * owner
Definition: chan_unistim.c:356
A device containing one or more lines.
Definition: chan_unistim.c:394
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1216
#define LOG_WARNING
Definition: logger.h:274
static struct test_val d
#define SUB_THREEWAY
Definition: chan_unistim.c:118
static void swap_subs(struct unistim_subchannel *a, struct unistim_subchannel *b)
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1166
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
#define ast_log
Definition: astobj2.c:42
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
#define SUB_REAL
Definition: chan_unistim.c:116
struct stasis_forward * sub
Definition: res_corosync.c:240

◆ unistim_alloc_sub()

static struct unistim_subchannel* unistim_alloc_sub ( struct unistim_device d,
int  x 
)
static

Definition at line 1988 of file chan_unistim.c.

References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_mutex_init, AST_PTHREADT_NULL, ast_verb, unistim_subchannel::list, unistim_subchannel::lock, unistim_device::name, NULL, unistim_subchannel::ss_thread, sub, unistim_device::subs, unistim_subchannel::subtype, and unistimdebug.

Referenced by find_subchannel_by_name(), and handle_call_outgoing().

1989 {
1990  struct unistim_subchannel *sub;
1991  if (!(sub = ast_calloc(1, sizeof(*sub)))) {
1992  return NULL;
1993  }
1994 
1995  if (unistimdebug) {
1996  ast_verb(3, "Allocating UNISTIM subchannel #%d on %s ptr=%p\n", x, d->name, sub);
1997  }
1999  sub->subtype = x;
2000  AST_LIST_LOCK(&d->subs);
2001  AST_LIST_INSERT_TAIL(&d->subs, sub, list);
2002  AST_LIST_UNLOCK(&d->subs);
2003  ast_mutex_init(&sub->lock);
2004  return sub;
2005 }
ast_mutex_t lock
Definition: chan_unistim.c:354
struct unistim_device::@152 subs
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
unsigned int subtype
Definition: chan_unistim.c:355
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct unistim_subchannel::@150 list
struct stasis_forward * sub
Definition: res_corosync.c:240
#define ast_mutex_init(pmutex)
Definition: lock.h:184

◆ unistim_answer()

static int unistim_answer ( struct ast_channel ast)
static

Definition at line 5054 of file chan_unistim.c.

References ast_channel_name(), ast_channel_tech_pvt(), ast_log, ast_setstate(), AST_STATE_UP, ast_verb, channel_to_session(), d, get_sub(), LOG_WARNING, unistim_line::name, unistim_device::name, unistim_subchannel::parent, unistim_line::parent, send_start_timer(), send_text(), send_text_status(), unistim_subchannel::softkey, sub, SUB_THREEWAY, TEXT_LINE2, TEXT_NORMAL, unistimdebug, and ustmtext().

5055 {
5056  int res = 0;
5057  struct unistim_subchannel *sub;
5058  struct unistim_line *l;
5059  struct unistim_device *d;
5060  struct unistimsession *s;
5061 
5062  s = channel_to_session(ast);
5063  if (!s) {
5064  ast_log(LOG_WARNING, "unistim_answer on a disconnected device ?\n");
5065  return -1;
5066  }
5067  sub = ast_channel_tech_pvt(ast);
5068  l = sub->parent;
5069  d = l->parent;
5070 
5071  if (unistimdebug) {
5072  ast_verb(0, "unistim_answer(%s) on %s@%s-%d\n", ast_channel_name(ast), l->name,
5073  l->parent->name, sub->softkey);
5074  }
5075  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("is now on-line", s));
5076  if (get_sub(d, SUB_THREEWAY)) {
5077  send_text_status(s, ustmtext("Transf Cancel", s));
5078  } else {
5079  send_text_status(s, ustmtext(" Transf Hangup", s));
5080  }
5081  send_start_timer(s);
5082  if (ast_channel_state(ast) != AST_STATE_UP)
5083  ast_setstate(ast, AST_STATE_UP);
5084  return res;
5085 }
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define TEXT_LINE2
Definition: chan_unistim.c:172
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define LOG_WARNING
Definition: logger.h:274
static struct test_val d
#define SUB_THREEWAY
Definition: chan_unistim.c:118
ast_channel_state
ast_channel states
Definition: channelstate.h:35
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
char name[80]
Definition: chan_unistim.c:374
#define ast_log
Definition: astobj2.c:42
static void send_text_status(struct unistimsession *pte, const char *text)
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
struct unistim_line * parent
Definition: chan_unistim.c:357
const char * ast_channel_name(const struct ast_channel *chan)
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7486
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
static void send_start_timer(struct unistimsession *pte)
static struct unistimsession * channel_to_session(struct ast_channel *ast)

◆ unistim_call()

static int unistim_call ( struct ast_channel ast,
const char *  dest,
int  timeout 
)
static

Definition at line 4867 of file chan_unistim.c.

References ast_channel_call_forward(), ast_channel_name(), ast_channel_tech_pvt(), AST_CONTROL_RINGING, ast_log, ast_queue_control(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_RINGING, ast_strlen_zero, ast_verb, change_favorite_icon(), channel_to_session(), unistim_device::cwstyle, unistim_device::cwvolume, unistimsession::device, FAV_BLINK_FAST, FAV_ICON_SPEAKER_ONHOOK_BLACK, FAVNUM, get_sub(), is_key_line(), LOG_ERROR, LOG_WARNING, unistim_line::name, unistim_subchannel::parent, unistim_subchannel::ringstyle, unistim_device::ringstyle, unistim_subchannel::ringvolume, unistim_device::ringvolume, send_callerid_screen(), send_favorite_short(), send_ring(), send_text(), send_text_status(), session, unistim_device::sline, soft_key_visible(), unistim_device::ssub, unistimsession::state, STATE_RINGING, sub, SUB_REAL, TEXT_LINE2, TEXT_NORMAL, unistimdebug, and ustmtext().

4868 {
4869  int res = 0, i;
4870  struct unistim_subchannel *sub, *sub_real;
4871  struct unistimsession *session;
4872  signed char ringstyle, ringvolume;
4873 
4874  session = channel_to_session(ast);
4875  if (!session) {
4876  ast_log(LOG_ERROR, "Device not registered, cannot call %s\n", dest);
4877  return -1;
4878  }
4879  sub = ast_channel_tech_pvt(ast);
4880  sub_real = get_sub(session->device, SUB_REAL);
4882  ast_log(LOG_WARNING, "unistim_call called on %s, neither down nor reserved\n",
4883  ast_channel_name(ast));
4884  return -1;
4885  }
4886 
4887  if (unistimdebug) {
4888  ast_verb(3, "unistim_call(%s)\n", ast_channel_name(ast));
4889  }
4890  session->state = STATE_RINGING;
4891  send_callerid_screen(session, sub);
4892  if (ast_strlen_zero(ast_channel_call_forward(ast))) { /* Send ring only if no call forward, otherwise short ring will apear */
4893  send_text(TEXT_LINE2, TEXT_NORMAL, session, ustmtext("is calling you.", session));
4894  send_text_status(session, ustmtext("Accept Ignore Hangup", session));
4895 
4896  if (sub_real) {
4897  ringstyle = session->device->cwstyle;
4898  ringvolume = session->device->cwvolume;
4899  } else {
4900  ringstyle = (sub->ringstyle == -1) ? session->device->ringstyle : sub->ringstyle;
4901  ringvolume = (sub->ringvolume == -1) ? session->device->ringvolume : sub->ringvolume;
4902  }
4903  send_ring(session, ringvolume, ringstyle);
4905  /* Send call identification to all */
4906  for (i = 0; i < FAVNUM; i++) {
4907  if (!soft_key_visible(session->device, i)) {
4908  continue;
4909  }
4910  if (session->device->ssub[i]) {
4911  continue;
4912  }
4913  if (is_key_line(session->device, i) && !strcmp(sub->parent->name, session->device->sline[i]->name)) {
4914  if (unistimdebug) {
4915  ast_verb(0, "Found softkey %d for line %s\n", i, sub->parent->name);
4916  }
4918  session->device->ssub[i] = sub;
4919  }
4920  }
4921  }
4924  return res;
4925 }
static int soft_key_visible(struct unistim_device *d, unsigned char num)
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1231
#define TEXT_LINE2
Definition: chan_unistim.c:172
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define FAVNUM
Definition: chan_unistim.c:216
signed char ringvolume
Definition: chan_unistim.c:363
signed char ringstyle
Definition: chan_unistim.c:364
#define LOG_WARNING
Definition: logger.h:274
static void change_favorite_icon(struct unistimsession *pte, unsigned char status)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
signed char ringvolume
Definition: chan_unistim.c:422
static void send_callerid_screen(struct unistimsession *, struct unistim_subchannel *)
#define TEXT_NORMAL
Definition: chan_unistim.c:173
signed char ringstyle
Definition: chan_unistim.c:423
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
const char * ast_channel_call_forward(const struct ast_channel *chan)
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
char name[80]
Definition: chan_unistim.c:374
signed char cwstyle
Definition: chan_unistim.c:425
#define ast_log
Definition: astobj2.c:42
static struct ast_mansession session
signed char cwvolume
Definition: chan_unistim.c:424
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
#define FAV_BLINK_FAST
Definition: chan_unistim.c:211
#define FAV_ICON_SPEAKER_ONHOOK_BLACK
Definition: chan_unistim.c:180
#define LOG_ERROR
Definition: logger.h:285
static void send_text_status(struct unistimsession *pte, const char *text)
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
#define SUB_REAL
Definition: chan_unistim.c:116
struct unistim_line * parent
Definition: chan_unistim.c:357
const char * ast_channel_name(const struct ast_channel *chan)
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7486
struct stasis_forward * sub
Definition: res_corosync.c:240
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
static struct unistimsession * channel_to_session(struct ast_channel *ast)
static int is_key_line(struct unistim_device *d, int fav)
static void send_ring(struct unistimsession *pte, signed char volume, signed char style)

◆ unistim_do_debug()

static char* unistim_do_debug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 6212 of file chan_unistim.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, unistimdebug, and ast_cli_entry::usage.

6213 {
6214  switch (cmd) {
6215  case CLI_INIT:
6216  e->command = "unistim set debug {on|off}";
6217  e->usage =
6218  "Usage: unistim set debug\n"
6219  " Display debug messages.\n";
6220  return NULL;
6221 
6222  case CLI_GENERATE:
6223  return NULL; /* no completion */
6224  }
6225 
6226  if (a->argc != e->args) {
6227  return CLI_SHOWUSAGE;
6228  }
6229  if (!strcasecmp(a->argv[3], "on")) {
6230  unistimdebug = 1;
6231  ast_cli(a->fd, "UNISTIM Debugging Enabled\n");
6232  } else if (!strcasecmp(a->argv[3], "off")) {
6233  unistimdebug = 0;
6234  ast_cli(a->fd, "UNISTIM Debugging Disabled\n");
6235  } else {
6236  return CLI_SHOWUSAGE;
6237  }
6238  return CLI_SUCCESS;
6239 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static int unistimdebug
Definition: chan_unistim.c:243
int args
This gets set in ast_cli_register()
Definition: cli.h:185
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ unistim_do_senddigit()

static int unistim_do_senddigit ( struct unistimsession pte,
char  digit 
)
static

Definition at line 3356 of file chan_unistim.c.

References unistim_subchannel::alreadygone, AST_FRAME_DTMF, ast_log, ast_queue_frame(), ast_verb, unistimsession::device, digit, unistim_device::dtmfduration, ast_frame::frametype, get_sub(), LOG_WARNING, unistim_subchannel::owner, send_dtmf_tone(), send_tone(), sub, SUB_REAL, and unistimdebug.

Referenced by key_call().

3357 {
3358  struct ast_frame f = { .frametype = AST_FRAME_DTMF, .subclass.integer = digit, .src = "unistim" };
3359  struct unistim_subchannel *sub;
3360 
3361  sub = get_sub(pte->device, SUB_REAL);
3362  if (!sub || !sub->owner || sub->alreadygone) {
3363  ast_log(LOG_WARNING, "Unable to find subchannel in dtmf senddigit\n");
3364  return -1;
3365  }
3366 
3367  /* Send DTMF indication _before_ playing sounds */
3368  ast_queue_frame(sub->owner, &f);
3369  if (pte->device->dtmfduration > 0) {
3370  if (unistimdebug) {
3371  ast_verb(0, "Send Digit %c (%i ms)\n", digit, pte->device->dtmfduration);
3372  }
3373  send_dtmf_tone(pte, digit);
3374  usleep(pte->device->dtmfduration * 1000); /* XXX Less than perfect, blocking an important thread is not a good idea */
3375  send_tone(pte, 0, 0);
3376  }
3377  return 0;
3378 }
struct ast_channel * owner
Definition: chan_unistim.c:356
char digit
#define LOG_WARNING
Definition: logger.h:274
#define AST_FRAME_DTMF
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
#define ast_log
Definition: astobj2.c:42
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1139
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
#define SUB_REAL
Definition: chan_unistim.c:116
struct stasis_forward * sub
Definition: res_corosync.c:240
Data structure associated with a single frame of data.
enum ast_frame_type frametype
static int send_dtmf_tone(struct unistimsession *pte, char digit)

◆ unistim_fixup()

static int unistim_fixup ( struct ast_channel oldchan,
struct ast_channel newchan 
)
static

Definition at line 5254 of file chan_unistim.c.

References ast_channel_name(), ast_channel_tech_pvt(), ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, unistim_subchannel::lock, LOG_WARNING, unistim_line::name, unistim_device::name, unistim_subchannel::owner, unistim_subchannel::parent, unistim_line::parent, unistim_subchannel::subtype, and unistim_set_owner().

5255 {
5256  struct unistim_subchannel *p = ast_channel_tech_pvt(newchan);
5257  struct unistim_line *l = p->parent;
5258 
5259  ast_mutex_lock(&p->lock);
5260 
5261  ast_debug(1, "New owner for channel USTM/%s@%s-%u is %s\n", l->name,
5262  l->parent->name, p->subtype, ast_channel_name(newchan));
5263 
5264  if (p->owner != oldchan) {
5265  ast_log(LOG_WARNING, "old channel wasn't %s (%p) but was %s (%p)\n",
5266  ast_channel_name(oldchan), oldchan, ast_channel_name(p->owner), p->owner);
5267  ast_mutex_unlock(&p->lock);
5268  return -1;
5269  }
5270 
5271  unistim_set_owner(p, newchan);
5272 
5273  ast_mutex_unlock(&p->lock);
5274 
5275  return 0;
5276 
5277 }
ast_mutex_t lock
Definition: chan_unistim.c:354
struct ast_channel * owner
Definition: chan_unistim.c:356
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define LOG_WARNING
Definition: logger.h:274
#define ast_mutex_lock(a)
Definition: lock.h:187
unsigned int subtype
Definition: chan_unistim.c:355
char name[80]
Definition: chan_unistim.c:374
static void unistim_set_owner(struct unistim_subchannel *sub, struct ast_channel *chan)
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
struct unistim_line * parent
Definition: chan_unistim.c:357
const char * ast_channel_name(const struct ast_channel *chan)
struct unistim_device * parent
Definition: chan_unistim.c:387
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unistim_free_sub()

static int unistim_free_sub ( struct unistim_subchannel sub)
static

Definition at line 1979 of file chan_unistim.c.

References ast_debug, ast_free, ast_mutex_destroy, unistim_subchannel::lock, unistim_line::name, unistim_device::name, unistim_subchannel::parent, unistim_line::parent, unistim_subchannel::subtype, and unistimdebug.

Referenced by close_client(), and unistim_unalloc_sub().

1979  {
1980  if (unistimdebug) {
1981  ast_debug(1, "Released sub %u of channel %s@%s\n", sub->subtype, sub->parent->name, sub->parent->parent->name);
1982  }
1983  ast_mutex_destroy(&sub->lock);
1984  ast_free(sub);
1985  return 0;
1986 }
ast_mutex_t lock
Definition: chan_unistim.c:354
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
static int unistimdebug
Definition: chan_unistim.c:243
unsigned int subtype
Definition: chan_unistim.c:355
char name[80]
Definition: chan_unistim.c:374
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_free(a)
Definition: astmm.h:182
struct unistim_line * parent
Definition: chan_unistim.c:357
struct unistim_device * parent
Definition: chan_unistim.c:387
#define ast_mutex_destroy(a)
Definition: lock.h:186

◆ unistim_get_rtp_peer()

static enum ast_rtp_glue_result unistim_get_rtp_peer ( struct ast_channel chan,
struct ast_rtp_instance **  instance 
)
static

Definition at line 7030 of file chan_unistim.c.

References ao2_ref, ast_channel_tech_pvt(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_LOCAL, unistim_subchannel::rtp, and sub.

7031 {
7033 
7034  if (!sub) {
7036  }
7037  if (!sub->rtp) {
7039  }
7040 
7041  ao2_ref(sub->rtp, +1);
7042  *instance = sub->rtp;
7043 
7045 }
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct stasis_forward * sub
Definition: res_corosync.c:240

◆ unistim_hangup()

static int unistim_hangup ( struct ast_channel ast)
static

Definition at line 4945 of file chan_unistim.c.

References AST_CAUSE_ANSWERED_ELSEWHERE, ast_channel_hangupcause(), ast_channel_name(), ast_channel_tech_pvt(), ast_debug, ast_queue_unhold(), ast_verb, channel_to_session(), close_call(), d, unistimsession::device, FAV_ICON_OFFHOOK_BLACK, FAV_LINE_ICON, FAVNUM, get_sub(), is_key_line(), unistim_device::missed_call, unistim_subchannel::moh, unistim_line::name, unistim_device::name, NULL, unistim_subchannel::parent, unistim_line::parent, ptestate_tostr(), send_callerid_screen(), send_end_call(), send_favorite_short(), send_no_ring(), send_text(), send_text_status(), show_main_page(), unistim_device::sline, soft_key_visible(), unistim_subchannel::softkey, unistim_device::ssub, unistimsession::state, STATE_CALL, STATE_RINGING, sub, SUB_REAL, SUB_RING, sub_stop_silence(), SUB_THREEWAY, unistim_subchannel::subtype, swap_subs(), TEXT_LINE2, TEXT_NORMAL, unistim_hangup_clean(), unistim_unalloc_sub(), unistimdebug, ustmtext(), and write_history().

4946 {
4947  struct unistim_subchannel *sub = NULL, *sub_real = NULL, *sub_trans = NULL;
4948  struct unistim_line *l;
4949  struct unistim_device *d;
4950  struct unistimsession *s;
4951  int i,end_call = 1;
4952 
4953  s = channel_to_session(ast);
4954  sub = ast_channel_tech_pvt(ast);
4955  l = sub->parent;
4956  d = l->parent;
4957  if (!s) {
4958  ast_debug(1, "Asked to hangup channel not connected\n");
4959  unistim_hangup_clean(ast, sub);
4960  return 0;
4961  }
4962  if (unistimdebug) {
4963  ast_verb(0, "unistim_hangup(%s) on %s@%s (STATE_%s)\n", ast_channel_name(ast), l->name, l->parent->name, ptestate_tostr(s->state));
4964  }
4965  sub_trans = get_sub(d, SUB_THREEWAY);
4966  sub_real = get_sub(d, SUB_REAL);
4967  if (sub_trans && (sub_trans->owner) && (sub->subtype == SUB_REAL)) { /* 3rd party busy or congested and transfer_cancel_step2 does not called */
4968  if (unistimdebug) {
4969  ast_verb(0, "Threeway call disconnected, switching to real call\n");
4970  }
4971  ast_queue_unhold(sub_trans->owner);
4972  sub_trans->moh = 0;
4973  sub_trans->subtype = SUB_REAL;
4974  swap_subs(sub_trans, sub);
4975  send_text_status(s, ustmtext(" Transf Hangup", s));
4976  send_callerid_screen(s, sub_trans);
4977  unistim_hangup_clean(ast, sub);
4978  unistim_unalloc_sub(d, sub);
4979  return 0;
4980  }
4981  if (sub_real && (sub_real->owner) && (sub->subtype == SUB_THREEWAY) && (s->state == STATE_CALL)) { /* 3way call cancelled by softkey pressed */
4982  if (unistimdebug) {
4983  ast_verb(0, "Real call disconnected, stay in call\n");
4984  }
4985  send_text_status(s, ustmtext(" Transf Hangup", s));
4986  send_callerid_screen(s, sub_real);
4987  unistim_hangup_clean(ast, sub);
4988  unistim_unalloc_sub(d, sub);
4989  return 0;
4990  }
4991  if (sub->subtype == SUB_REAL) {
4992  sub_stop_silence(s, sub);
4993  } else if (sub->subtype == SUB_RING) {
4994  send_no_ring(s);
4995  for (i = 0; i < FAVNUM; i++) {
4996  if (!soft_key_visible(s->device, i)) {
4997  continue;
4998  }
4999  if (d->ssub[i] != sub) {
5000  if (d->ssub[i] != NULL) { /* Found other subchannel active other than hangup'ed one */
5001  end_call = 0;
5002  }
5003  continue;
5004  }
5005  if (is_key_line(d, i) && !strcmp(l->name, d->sline[i]->name)) {
5007  d->ssub[i] = NULL;
5008  continue;
5009  }
5010  }
5011  }
5012  if (end_call) {
5013  send_end_call(s); /* Send end call packet only if ending active call, in other way sound should be loosed */
5014  }
5015  sub->moh = 0;
5016  if (sub->softkey >= 0) {
5018  }
5019  /* Delete assign sub to softkey */
5020  for (i = 0; i < FAVNUM; i++) {
5021  if (d->ssub[i] == sub) {
5022  d->ssub[i] = NULL;
5023  break;
5024  }
5025  }
5026  /*refresh_all_favorite(s); */ /* TODO: Update favicons in case of DND keys */
5027  if (s->state == STATE_RINGING && sub->subtype == SUB_RING) {
5028  send_no_ring(s);
5030  d->missed_call++;
5031  write_history(s, 'i', 1);
5032  }
5033  if (!sub_real) {
5034  show_main_page(s);
5035  } else { /* hangup on a ringing line: reset status to reflect that we're still on an active call */
5036  s->state = STATE_CALL;
5037  send_callerid_screen(s, sub_real);
5038  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("is on-line", s));
5039  send_text_status(s, ustmtext(" Transf Hangup", s));
5041 
5042  }
5043  }
5044  if (s->state == STATE_CALL && sub->subtype == SUB_REAL) {
5045  close_call(s);
5046  }
5047  sub->softkey = -1;
5048  unistim_hangup_clean(ast, sub);
5049  unistim_unalloc_sub(d, sub);
5050  return 0;
5051 }
static int soft_key_visible(struct unistim_device *d, unsigned char num)
static int write_history(struct unistimsession *pte, char way, char ismissed)
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define TEXT_LINE2
Definition: chan_unistim.c:172
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define FAVNUM
Definition: chan_unistim.c:216
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1216
static int unistim_hangup_clean(struct ast_channel *ast, struct unistim_subchannel *sub)
#define SUB_RING
Definition: chan_unistim.c:117
static struct test_val d
#define SUB_THREEWAY
Definition: chan_unistim.c:118
static void swap_subs(struct unistim_subchannel *a, struct unistim_subchannel *b)
static void close_call(struct unistimsession *pte)
static void send_callerid_screen(struct unistimsession *, struct unistim_subchannel *)
#define NULL
Definition: resample.c:96
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
char name[80]
Definition: chan_unistim.c:374
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_CAUSE_ANSWERED_ELSEWHERE
Definition: causes.h:113
#define FAV_LINE_ICON
Definition: chan_unistim.c:218
static void send_favorite_short(unsigned char pos, unsigned char status, struct unistimsession *pte)
static void send_text_status(struct unistimsession *pte, const char *text)
static void show_main_page(struct unistimsession *pte)
static const char * ptestate_tostr(const int type)
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static int unistim_unalloc_sub(struct unistim_device *d, struct unistim_subchannel *sub)
#define SUB_REAL
Definition: chan_unistim.c:116
static void send_no_ring(struct unistimsession *pte)
int ast_channel_hangupcause(const struct ast_channel *chan)
struct unistim_line * parent
Definition: chan_unistim.c:357
const char * ast_channel_name(const struct ast_channel *chan)
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
static struct unistimsession * channel_to_session(struct ast_channel *ast)
static int is_key_line(struct unistim_device *d, int fav)
static void send_end_call(struct unistimsession *pte)
static void sub_stop_silence(struct unistimsession *pte, struct unistim_subchannel *sub)
#define FAV_ICON_OFFHOOK_BLACK
Definition: chan_unistim.c:182

◆ unistim_hangup_clean()

static int unistim_hangup_clean ( struct ast_channel ast,
struct unistim_subchannel sub 
)
static

Definition at line 4927 of file chan_unistim.c.

References unistim_subchannel::alreadygone, ast_channel_tech_pvt_set(), ast_mutex_lock, ast_mutex_unlock, ast_rtp_instance_destroy(), ast_rtp_instance_stop(), ast_verb, unistim_subchannel::lock, NULL, unistim_subchannel::rtp, unistim_set_owner(), and unistimdebug.

Referenced by unistim_hangup().

4927  {
4928  ast_mutex_lock(&sub->lock);
4930  unistim_set_owner(sub, NULL);
4931  sub->alreadygone = 0;
4932  if (sub->rtp) {
4933  if (unistimdebug) {
4934  ast_verb(0, "Destroying RTP session\n");
4935  }
4936  ast_rtp_instance_stop(sub->rtp);
4938  sub->rtp = NULL;
4939  }
4940  ast_mutex_unlock(&sub->lock);
4941  return 0;
4942 }
ast_mutex_t lock
Definition: chan_unistim.c:354
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
static void unistim_set_owner(struct unistim_subchannel *sub, struct ast_channel *chan)
void ast_rtp_instance_stop(struct ast_rtp_instance *instance)
Stop an RTP instance.
Definition: rtp_engine.c:2183
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:458
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unistim_indicate()

static int unistim_indicate ( struct ast_channel ast,
int  ind,
const void *  data,
size_t  datalen 
)
static

Definition at line 5333 of file chan_unistim.c.

References unistim_subchannel::alreadygone, ast_channel_connected(), ast_channel_name(), ast_channel_tech_pvt(), AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_MASQUERADE_NOTIFY, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, ast_log, ast_moh_start(), ast_moh_stop(), ast_playtones_stop(), ast_rtp_instance_change_source(), AST_STATE_UP, ast_verb, channel_to_session(), control2str(), unistimsession::device, in_band_indication(), LOG_NOTICE, LOG_WARNING, unistim_device::missed_call, name, NULL, unistim_subchannel::parent, unistim_line::parent, unistim_subchannel::rtp, S_COR, send_callerid_screen(), send_text(), sub, SUB_REAL, unistim_subchannel::subtype, TEXT_LINE2, TEXT_NORMAL, unistim_device::tz, unistimdebug, and ustmtext().

5334 {
5335  struct unistim_subchannel *sub;
5336  struct unistim_line *l;
5337  struct unistimsession *s;
5338 
5339  if (unistimdebug) {
5340  ast_verb(3, "Asked to indicate '%s' (%d) condition on channel %s\n",
5341  control2str(ind), ind, ast_channel_name(ast));
5342  }
5343 
5344  s = channel_to_session(ast);
5345  if (!s) {
5346  return -1;
5347  }
5348  sub = ast_channel_tech_pvt(ast);
5349  l = sub->parent;
5350 
5351  switch (ind) {
5352  case AST_CONTROL_RINGING:
5353  if (ast_channel_state(ast) != AST_STATE_UP) {
5354  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("Ringing...", s));
5355  in_band_indication(ast, l->parent->tz, "ring");
5356  s->device->missed_call = -1;
5357  break;
5358  }
5359  return -1;
5360  case AST_CONTROL_BUSY:
5361  if (ast_channel_state(ast) != AST_STATE_UP) {
5362  sub->alreadygone = 1;
5363  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("Busy", s));
5364  in_band_indication(ast, l->parent->tz, "busy");
5365  s->device->missed_call = -1;
5366  break;
5367  }
5368  return -1;
5370  /* Overlapped dialing is not currently supported for UNIStim. Treat an indication
5371  * of incomplete as congestion
5372  */
5374  if (ast_channel_state(ast) != AST_STATE_UP) {
5375  sub->alreadygone = 1;
5376  send_text(TEXT_LINE2, TEXT_NORMAL, s, ustmtext("Congestion", s));
5377  in_band_indication(ast, l->parent->tz, "congestion");
5378  s->device->missed_call = -1;
5379  break;
5380  }
5381  return -1;
5382  case AST_CONTROL_HOLD:
5383  ast_moh_start(ast, data, NULL);
5384  break;
5385  case AST_CONTROL_UNHOLD:
5386  ast_moh_stop(ast);
5387  break;
5388  case AST_CONTROL_PROGRESS:
5389  case AST_CONTROL_SRCUPDATE:
5392  break;
5393  case -1:
5394  ast_playtones_stop(ast);
5395  s->device->missed_call = 0;
5396  break;
5398  ast_log(LOG_NOTICE, "Connected party is now %s <%s>\n",
5399  S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, ""),
5400  S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, ""));
5401  if (sub->subtype == SUB_REAL) {
5402  send_callerid_screen(s, sub);
5403  }
5404  break;
5405  case AST_CONTROL_SRCCHANGE:
5406  if (sub->rtp) {
5408  }
5409  break;
5410  default:
5411  ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", ind);
5412  /* fallthrough */
5415  return -1;
5416  }
5417 
5418  return 0;
5419 }
#define TEXT_LINE2
Definition: chan_unistim.c:172
void ast_rtp_instance_change_source(struct ast_rtp_instance *instance)
Indicate a new source of audio has dropped in and the ssrc should change.
Definition: rtp_engine.c:2160
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define LOG_WARNING
Definition: logger.h:274
static void in_band_indication(struct ast_channel *ast, const struct ast_tone_zone *tz, const char *indication)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
static void send_callerid_screen(struct unistimsession *, struct unistim_subchannel *)
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:393
#define NULL
Definition: resample.c:96
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7876
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
Number structure.
Definition: app_followme.c:154
#define ast_log
Definition: astobj2.c:42
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:85
static char * control2str(int ind)
struct ast_tone_zone * tz
Definition: chan_unistim.c:421
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7866
#define LOG_NOTICE
Definition: logger.h:263
static const char name[]
Definition: cdr_mysql.c:74
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
#define SUB_REAL
Definition: chan_unistim.c:116
struct unistim_line * parent
Definition: chan_unistim.c:357
const char * ast_channel_name(const struct ast_channel *chan)
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
static struct unistimsession * channel_to_session(struct ast_channel *ast)

◆ unistim_line_alloc()

static struct unistim_line* unistim_line_alloc ( void  )
static

Definition at line 1965 of file chan_unistim.c.

References ast_calloc, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_free, unistim_line::cap, and NULL.

Referenced by build_device(), and rcv_mac_addr().

1966 {
1967  struct unistim_line *l;
1968  if (!(l = ast_calloc(1, sizeof(*l)))) {
1969  return NULL;
1970  }
1971 
1973  ast_free(l);
1974  return NULL;
1975  }
1976  return l;
1977 }
#define NULL
Definition: resample.c:96
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct ast_format_cap * cap
Definition: chan_unistim.c:384

◆ unistim_line_copy()

static void unistim_line_copy ( struct unistim_line dst,
struct unistim_line src 
)
static

Definition at line 1947 of file chan_unistim.c.

References ast_format_cap_append_from_cap(), AST_MEDIA_TYPE_UNKNOWN, unistim_line::cap, and tmp().

Referenced by rcv_mac_addr().

1948 {
1949  struct ast_format_cap *tmp = src->cap;
1950  memcpy(dst, src, sizeof(*dst)); /* this over writes the cap ptr, so we have to reset it */
1951  src->cap = tmp;
1953 }
static int tmp()
Definition: bt_open.c:389
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
struct ast_format_cap * cap
Definition: chan_unistim.c:384

◆ unistim_line_destroy()

static struct unistim_line* unistim_line_destroy ( struct unistim_line l)
static

Definition at line 1955 of file chan_unistim.c.

References ao2_ref, ast_free, unistim_line::cap, and NULL.

Referenced by build_device(), and delete_device().

1956 {
1957  if (!l) {
1958  return NULL;
1959  }
1960  ao2_ref(l->cap, -1);
1961  ast_free(l);
1962  return NULL;
1963 }
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_free(a)
Definition: astmm.h:182
struct ast_format_cap * cap
Definition: chan_unistim.c:384

◆ unistim_new()

static struct ast_channel * unistim_new ( struct unistim_subchannel sub,
int  state,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor 
)
static

Protos

Definition at line 5704 of file chan_unistim.c.

References unistim_line::accountcode, unistim_line::amaflags, ao2_ref, AST_ADSI_UNAVAILABLE, ast_callerid_parse(), ast_channel_adsicpe_set(), ast_channel_alloc, ast_channel_caller(), ast_channel_callgroup_set(), ast_channel_internal_fd_set(), ast_channel_name(), ast_channel_nativeformats(), ast_channel_nativeformats_set(), ast_channel_pickupgroup_set(), ast_channel_priority_set(), ast_channel_rings_set(), ast_channel_set_rawreadformat(), ast_channel_set_rawwriteformat(), ast_channel_set_readformat(), ast_channel_set_writeformat(), ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_tech_pvt_set(), ast_channel_tech_set(), ast_channel_unlock, ast_format_cap_alloc, ast_format_cap_append_from_cap(), ast_format_cap_count(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_format(), ast_format_cap_get_names(), AST_FORMAT_CAP_NAMES_LEN, ast_format_get_name(), ast_free, ast_hangup(), ast_jb_configure(), ast_log, AST_MEDIA_TYPE_UNKNOWN, ast_pbx_start(), ast_rtp_instance_fd(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RING, ast_str_alloca, ast_strdup, ast_strlen_zero, ast_update_use_count(), ast_verb, unistim_device::call_forward, unistim_line::callgroup, unistim_line::cap, unistim_line::cid_num, unistim_device::context, unistim_line::exten, global_jbconf, ast_party_caller::id, unistim_device::language, LOG_WARNING, name, ast_party_id::name, unistim_line::name, unistim_device::name, NULL, ast_party_id::number, unistim_subchannel::parent, unistim_line::parent, unistim_line::pickupgroup, unistim_subchannel::rtp, ast_party_name::str, ast_party_number::str, unistim_subchannel::subtype, tmp(), unistim_set_owner(), unistimdebug, ast_party_name::valid, and ast_party_number::valid.

Referenced by handle_call_outgoing(), and unistim_request().

5705 {
5706  struct ast_format_cap *caps;
5707  struct ast_channel *tmp;
5708  struct unistim_line *l;
5709  struct ast_format *tmpfmt;
5710 
5711  if (!sub) {
5712  ast_log(LOG_WARNING, "subchannel null in unistim_new\n");
5713  return NULL;
5714  }
5715  if (!sub->parent) {
5716  ast_log(LOG_WARNING, "no line for subchannel %p\n", sub);
5717  return NULL;
5718  }
5719 
5721  if (!caps) {
5722  return NULL;
5723  }
5724 
5725  l = sub->parent;
5726  tmp = ast_channel_alloc(1, state, l->cid_num, NULL, l->accountcode, l->exten,
5727  l->parent->context, assignedids, requestor, l->amaflags, "USTM/%s@%s-%p", l->name, l->parent->name, sub);
5728  if (unistimdebug) {
5729  ast_verb(0, "unistim_new sub=%u (%p) chan=%p line=%s\n", sub->subtype, sub, tmp, l->name);
5730  }
5731  if (!tmp) {
5732  ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
5733  ao2_ref(caps, -1);
5734  return NULL;
5735  }
5736 
5738 
5739  if (ast_format_cap_count(l->cap)) {
5741  } else {
5743  }
5744  ast_channel_nativeformats_set(tmp, caps);
5745  ao2_ref(caps, -1);
5746 
5748 
5749  if (unistimdebug) {
5750  struct ast_str *native_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5751  struct ast_str *cap_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5752  struct ast_str *global_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5753 
5754  ast_verb(0, "Best codec = %s from nativeformats %s (line cap=%s global=%s)\n",
5755  ast_format_get_name(tmpfmt),
5757  ast_format_cap_get_names(l->cap, &cap_buf),
5758  ast_format_cap_get_names(global_cap, &global_buf));
5759  }
5760  if ((sub->rtp) && (sub->subtype == 0)) {
5761  if (unistimdebug) {
5762  ast_verb(0, "New unistim channel with a previous rtp handle ?\n");
5763  }
5766  }
5767  if (sub->rtp) {
5769  }
5770 /* tmp->type = type; */
5771  ast_setstate(tmp, state);
5772  if (state == AST_STATE_RING) {
5773  ast_channel_rings_set(tmp, 1);
5774  }
5776 
5777  ast_channel_set_writeformat(tmp, tmpfmt);
5778  ast_channel_set_rawwriteformat(tmp, tmpfmt);
5779  ast_channel_set_readformat(tmp, tmpfmt);
5780  ast_channel_set_rawreadformat(tmp, tmpfmt);
5781  ao2_ref(tmpfmt, -1);
5782 
5783  ast_channel_tech_pvt_set(tmp, sub);
5785 
5786  if (!ast_strlen_zero(l->parent->language)) {
5787  ast_channel_language_set(tmp, l->parent->language);
5788  }
5789  unistim_set_owner(sub, tmp);
5793  ast_channel_call_forward_set(tmp, l->parent->call_forward);
5794  if (!ast_strlen_zero(l->cid_num)) {
5795  char *name, *loc, *instr;
5796  instr = ast_strdup(l->cid_num);
5797  if (instr) {
5798  ast_callerid_parse(instr, &name, &loc);
5799  ast_channel_caller(tmp)->id.number.valid = 1;
5800  ast_free(ast_channel_caller(tmp)->id.number.str);
5801  ast_channel_caller(tmp)->id.number.str = ast_strdup(loc);
5802  ast_channel_caller(tmp)->id.name.valid = 1;
5803  ast_free(ast_channel_caller(tmp)->id.name.str);
5804  ast_channel_caller(tmp)->id.name.str = ast_strdup(name);
5805  ast_free(instr);
5806  }
5807  }
5808  ast_channel_priority_set(tmp, 1);
5809 
5811  ast_channel_unlock(tmp);
5812 
5813  if (state != AST_STATE_DOWN) {
5814  if (unistimdebug) {
5815  ast_verb(0, "Starting pbx in unistim_new\n");
5816  }
5817  if (ast_pbx_start(tmp)) {
5818  ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
5819  ast_hangup(tmp);
5820  tmp = NULL;
5821  }
5822  }
5823 
5824  return tmp;
5825 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char call_forward[AST_MAX_EXTENSION]
Definition: chan_unistim.c:438
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
Main Channel structure associated with a channel.
char * str
Subscriber phone number (Malloced)
Definition: channel.h:292
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
struct ast_party_name name
Subscriber name.
Definition: channel.h:341
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
#define LOG_WARNING
Definition: logger.h:274
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:4712
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
static int tmp()
Definition: bt_open.c:389
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
char * str
Subscriber name (Malloced)
Definition: channel.h:265
Definition of a media format.
Definition: format.c:43
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
void ast_update_use_count(void)
Notify when usecount has been changed.
Definition: loader.c:2528
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
unsigned int subtype
Definition: chan_unistim.c:355
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
Number structure.
Definition: app_followme.c:154
char name[80]
Definition: chan_unistim.c:374
struct ast_party_id id
Caller party ID.
Definition: channel.h:421
static void unistim_set_owner(struct unistim_subchannel *sub, struct ast_channel *chan)
#define ast_log
Definition: astobj2.c:42
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
ast_group_t callgroup
Definition: chan_unistim.c:380
void ast_channel_rings_set(struct ast_channel *chan, int value)
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
char cid_num[AST_MAX_EXTENSION]
Definition: chan_unistim.c:377
static struct ast_jb_conf global_jbconf
Definition: chan_unistim.c:235
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
Get the file descriptor for an RTP session (or RTCP)
Definition: rtp_engine.c:2192
char exten[AST_MAX_EXTENSION]
Definition: chan_unistim.c:376
void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
Configures a jitterbuffer on a channel.
Definition: abstract_jb.c:593
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct ast_format_cap * global_cap
Definition: chan_unistim.c:120
char context[AST_MAX_EXTENSION]
Definition: chan_unistim.c:398
ast_group_t pickupgroup
Definition: chan_unistim.c:381
char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: chan_unistim.c:382
struct unistim_line * parent
Definition: chan_unistim.c:357
const char * ast_channel_name(const struct ast_channel *chan)
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7486
struct unistim_device * parent
Definition: chan_unistim.c:387
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:280
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
struct ast_format_cap * cap
Definition: chan_unistim.c:384
void ast_channel_priority_set(struct ast_channel *chan, int value)
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1259
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:298
static struct ast_channel_tech unistim_tech
Definition: chan_unistim.c:736
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343

◆ unistim_read()

static struct ast_frame * unistim_read ( struct ast_channel ast)
static

Definition at line 5204 of file chan_unistim.c.

References ast_channel_tech_pvt(), ast_mutex_lock, ast_mutex_unlock, unistim_subchannel::lock, sub, and unistim_rtp_read().

5205 {
5206  struct ast_frame *fr;
5208 
5209  ast_mutex_lock(&sub->lock);
5210  fr = unistim_rtp_read(ast, sub);
5211  ast_mutex_unlock(&sub->lock);
5212 
5213  return fr;
5214 }
ast_mutex_t lock
Definition: chan_unistim.c:354
static struct ast_frame * unistim_rtp_read(const struct ast_channel *ast, const struct unistim_subchannel *sub)
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_mutex_lock(a)
Definition: lock.h:187
struct stasis_forward * sub
Definition: res_corosync.c:240
Data structure associated with a single frame of data.
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unistim_register()

static int unistim_register ( struct unistimsession s)
static

Definition at line 1920 of file chan_unistim.c.

References ast_mutex_lock, ast_mutex_unlock, unistim_device::codec_number, d, DEFAULT_CODEC, unistimsession::device, devicelock, devices, unistim_device::id, unistimsession::macaddr, unistim_device::missed_call, unistim_device::next, unistim_device::receiver_state, unistim_device::session, and STATE_ONHOOK.

Referenced by rcv_mac_addr().

1921 {
1922  struct unistim_device *d;
1923 
1925  d = devices;
1926  while (d) {
1927  if (!strcasecmp(s->macaddr, d->id)) {
1928  /* XXX Deal with IP authentication */
1929  s->device = d;
1930  d->session = s;
1932  d->missed_call = 0;
1934  break;
1935  }
1936  d = d->next;
1937  }
1939 
1940  if (!d) {
1941  return 0;
1942  }
1943 
1944  return 1;
1945 }
A device containing one or more lines.
Definition: chan_unistim.c:394
static struct test_val d
#define ast_mutex_lock(a)
Definition: lock.h:187
struct unistim_device * device
Definition: chan_unistim.c:476
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
char macaddr[18]
Definition: chan_unistim.c:472
#define DEFAULT_CODEC
Definition: chan_unistim.c:110
struct unistim_device * next
Definition: chan_unistim.c:455
struct unistimsession * session
Definition: chan_unistim.c:454
static struct unistim_device * devices
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unistim_reload()

static char* unistim_reload ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

— unistim_reload: Force reload of module from cli — Runs in the asterisk main thread, so don't do anything useful but setting a flag and waiting for do_monitor to do the job in our thread

Definition at line 6245 of file chan_unistim.c.

References ast_cli_args::argc, ast_cli_entry::args, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, reload(), and ast_cli_entry::usage.

6246 {
6247  switch (cmd) {
6248  case CLI_INIT:
6249  e->command = "unistim reload";
6250  e->usage =
6251  "Usage: unistim reload\n"
6252  " Reloads UNISTIM configuration from unistim.conf\n";
6253  return NULL;
6254 
6255  case CLI_GENERATE:
6256  return NULL; /* no completion */
6257  }
6258 
6259  if (e && a && a->argc != e->args) {
6260  return CLI_SHOWUSAGE;
6261  }
6262  reload();
6263 
6264  return CLI_SUCCESS;
6265 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
int args
This gets set in ast_cli_register()
Definition: cli.h:185
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
static int reload(void)

◆ unistim_request()

static struct ast_channel * unistim_request ( const char *  type,
struct ast_format_cap cap,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
const char *  dest,
int *  cause 
)
static

Definition at line 5956 of file chan_unistim.c.

References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, ast_copy_string(), ast_format_cap_append_from_cap(), ast_format_cap_get_names(), ast_format_cap_iscompatible(), AST_FORMAT_CAP_NAMES_LEN, ast_log, AST_MEDIA_TYPE_UNKNOWN, AST_STATE_DOWN, ast_str_alloca, ast_strlen_zero, ast_verb, unistim_line::cap, d, find_subchannel_by_name(), get_avail_softkey(), get_sub(), LOG_NOTICE, LOG_WARNING, unistim_line::name, NULL, unistim_subchannel::owner, unistim_subchannel::parent, unistim_line::parent, restart_monitor(), unistim_device::session, unistim_subchannel::softkey, unistimsession::state, STATE_DIALPAGE, sub, SUB_RING, SUB_THREEWAY, unistim_subchannel::subtype, tmp(), unistim_new(), unistim_unalloc_sub(), and unistimdebug.

5958 {
5959  struct unistim_subchannel *sub, *sub_ring, *sub_trans;
5960  struct unistim_device *d;
5961  struct ast_channel *tmpc = NULL;
5962  char tmp[256];
5963 
5964  if (!(ast_format_cap_iscompatible(cap, global_cap))) {
5965  struct ast_str *cap_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5966  struct ast_str *global_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5968  "Asked to get a channel of unsupported format %s while capability is %s\n",
5969  ast_format_cap_get_names(cap, &cap_buf),
5970  ast_format_cap_get_names(global_cap, &global_buf));
5971  return NULL;
5972  }
5973 
5974  ast_copy_string(tmp, dest, sizeof(tmp));
5975  if (ast_strlen_zero(tmp)) {
5976  ast_log(LOG_NOTICE, "Unistim channels require a device\n");
5977  return NULL;
5978  }
5979  sub = find_subchannel_by_name(tmp);
5980  if (!sub) {
5981  ast_log(LOG_NOTICE, "No available lines on: %s\n", dest);
5982  *cause = AST_CAUSE_CONGESTION;
5983  return NULL;
5984  }
5985  d = sub->parent->parent;
5986  sub_ring = get_sub(d, SUB_RING);
5987  sub_trans = get_sub(d, SUB_THREEWAY);
5988  /* Another request already in progress */
5989  if (!d->session) {
5990  unistim_unalloc_sub(d, sub);
5991  *cause = AST_CAUSE_CONGESTION;
5992  return NULL;
5993  }
5994  if (sub_ring || sub_trans) {
5995  if (unistimdebug) {
5996  ast_verb(0, "Can't create channel, request already in progress: Busy!\n");
5997  }
5998  unistim_unalloc_sub(d, sub);
5999  *cause = AST_CAUSE_BUSY;
6000  return NULL;
6001  }
6002  if (d->session->state == STATE_DIALPAGE) {
6003  if (unistimdebug) {
6004  ast_verb(0, "Can't create channel, user on dialpage: Busy!\n");
6005  }
6006  unistim_unalloc_sub(d, sub);
6007  *cause = AST_CAUSE_BUSY;
6008  return NULL;
6009  }
6010 
6011  if (get_avail_softkey(d->session, sub->parent->name) == -1) {
6012  if (unistimdebug) {
6013  ast_verb(0, "Can't create channel for line %s, all lines busy\n", sub->parent->name);
6014  }
6015  unistim_unalloc_sub(d, sub);
6016  *cause = AST_CAUSE_BUSY;
6017  return NULL;
6018  }
6019  sub->subtype = SUB_RING;
6020  sub->softkey = -1;
6021 
6023  tmpc = unistim_new(sub, AST_STATE_DOWN, assignedids, requestor);
6024  if (!tmpc) {
6025  ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp);
6026  }
6027  if (unistimdebug) {
6028  ast_verb(0, "unistim_request owner = %p\n", sub->owner);
6029  }
6030  restart_monitor();
6031  /* and finish */
6032  return tmpc;
6033 }
struct ast_channel * owner
Definition: chan_unistim.c:356
Main Channel structure associated with a channel.
A device containing one or more lines.
Definition: chan_unistim.c:394
static struct ast_channel * unistim_new(struct unistim_subchannel *sub, int state, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
#define LOG_WARNING
Definition: logger.h:274
#define SUB_RING
Definition: chan_unistim.c:117
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
static struct test_val d
#define SUB_THREEWAY
Definition: chan_unistim.c:118
static int tmp()
Definition: bt_open.c:389
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
static struct unistim_subchannel * find_subchannel_by_name(const char *dest)
unsigned int subtype
Definition: chan_unistim.c:355
char name[80]
Definition: chan_unistim.c:374
#define ast_log
Definition: astobj2.c:42
struct unistimsession * session
Definition: chan_unistim.c:454
static int get_avail_softkey(struct unistimsession *pte, const char *name)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define LOG_NOTICE
Definition: logger.h:263
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
static struct unistim_subchannel * get_sub(struct unistim_device *device, int type)
static int unistim_unalloc_sub(struct unistim_device *d, struct unistim_subchannel *sub)
struct ast_format_cap * global_cap
Definition: chan_unistim.c:120
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
struct unistim_line * parent
Definition: chan_unistim.c:357
#define AST_CAUSE_BUSY
Definition: causes.h:148
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
static int restart_monitor(void)
struct ast_format_cap * cap
Definition: chan_unistim.c:384
#define AST_CAUSE_CONGESTION
Definition: causes.h:152
int ast_format_cap_iscompatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
Determine if any joint capabilities exist between two capabilities structures.
Definition: format_cap.c:655

◆ unistim_rtp_read()

static struct ast_frame* unistim_rtp_read ( const struct ast_channel ast,
const struct unistim_subchannel sub 
)
static

Definition at line 5149 of file chan_unistim.c.

References ao2_ref, ast_channel_fdno(), ast_channel_nativeformats(), ast_channel_nativeformats_set(), ast_channel_readformat(), ast_channel_writeformat(), ast_debug, ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_names(), ast_format_cap_iscompatible_format(), AST_FORMAT_CAP_NAMES_LEN, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_name(), AST_FRAME_VOICE, ast_log, ast_null_frame, ast_rtp_instance_read(), ast_set_read_format(), ast_set_write_format(), ast_str_alloca, ast_frame_subclass::format, ast_frame::frametype, LOG_WARNING, unistim_subchannel::owner, unistim_subchannel::rtp, ast_frame::subclass, and unistim_subchannel::subtype.

Referenced by unistim_read().

5151 {
5152  /* Retrieve audio/etc from channel. Assumes sub->lock is already held. */
5153  struct ast_frame *f;
5154 
5155  if (!ast) {
5156  ast_log(LOG_WARNING, "Channel NULL while reading\n");
5157  return &ast_null_frame;
5158  }
5159 
5160  if (!sub->rtp) {
5161  ast_log(LOG_WARNING, "RTP handle NULL while reading on subchannel %u\n",
5162  sub->subtype);
5163  return &ast_null_frame;
5164  }
5165 
5166  switch (ast_channel_fdno(ast)) {
5167  case 0:
5168  f = ast_rtp_instance_read(sub->rtp, 0); /* RTP Audio */
5169  break;
5170  case 1:
5171  f = ast_rtp_instance_read(sub->rtp, 1); /* RTCP Control Channel */
5172  break;
5173  default:
5174  f = &ast_null_frame;
5175  }
5176 
5177  if (sub->owner) {
5178  /* We already hold the channel lock */
5179  if (f->frametype == AST_FRAME_VOICE) {
5181  struct ast_str *cap_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5182  struct ast_format_cap *caps;
5183 
5184  ast_debug(1,
5185  "Oooh, format changed from %s to %s\n",
5188 
5190  if (caps) {
5191  ast_format_cap_append(caps, f->subclass.format, 0);
5193  ao2_ref(caps, -1);
5194  }
5197  }
5198  }
5199  }
5200 
5201  return f;
5202 }
struct ast_channel * owner
Definition: chan_unistim.c:356
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
#define LOG_WARNING
Definition: logger.h:274
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
struct ast_frame_subclass subclass
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
unsigned int subtype
Definition: chan_unistim.c:355
enum ast_format_cmp_res ast_format_cap_iscompatible_format(const struct ast_format_cap *cap, const struct ast_format *format)
Find if ast_format is within the capabilities of the ast_format_cap object.
Definition: format_cap.c:583
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5849
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5890
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
int ast_channel_fdno(const struct ast_channel *chan)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct ast_frame ast_null_frame
Definition: main/frame.c:79
Data structure associated with a single frame of data.
enum ast_frame_type frametype
struct ast_format * format
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
struct ast_frame * ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
Receive a frame over RTP.
Definition: rtp_engine.c:578

◆ unistim_send_mwi_to_peer()

static int unistim_send_mwi_to_peer ( struct unistim_line peer,
unsigned int  tick 
)
static

Definition at line 5675 of file chan_unistim.c.

References ao2_cleanup, ast_app_has_voicemail(), ast_debug, ast_mwi_state_cache(), ast_mwi_state_type(), unistim_device::lastmsgssent, LED_BAR_OFF, LED_BAR_ON, unistim_line::mailbox, ast_mwi_state::new_msgs, unistim_device::nextmsgcheck, NULL, unistim_line::parent, RAII_VAR, send_led_update(), unistim_device::session, stasis_cache_get(), stasis_message_data(), unistimsession::state, STATE_MAINPAGE, and TIMER_MWI.

Referenced by do_monitor().

5676 {
5677  int new;
5678  RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
5679 
5681  if (msg) {
5682  struct ast_mwi_state *mwi_state = stasis_message_data(msg);
5683  new = mwi_state->new_msgs;
5684  } else { /* Fall back on checking the mailbox directly */
5685  new = ast_app_has_voicemail(peer->mailbox, NULL);
5686  }
5687  ast_debug(3, "MWI Status for mailbox %s is %d, lastmsgsent:%d\n",
5688  peer->mailbox, new, peer->parent->lastmsgssent);
5689  peer->parent->nextmsgcheck = tick + TIMER_MWI;
5690 
5691  /* Return now if it's the same thing we told them last time */
5692  if ((peer->parent->session->state != STATE_MAINPAGE) || (new == peer->parent->lastmsgssent)) {
5693  return 0;
5694  }
5695 
5696  peer->parent->lastmsgssent = new;
5698 
5699  return 0;
5700 }
#define TIMER_MWI
Definition: chan_unistim.c:105
struct stasis_cache * ast_mwi_state_cache(void)
Backend cache for ast_mwi_topic_cached().
Definition: mwi.c:90
#define LED_BAR_ON
Definition: chan_unistim.c:152
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct unistimsession * session
Definition: chan_unistim.c:454
char mailbox[AST_MAX_EXTENSION]
Definition: chan_unistim.c:378
time_t nextmsgcheck
Definition: chan_unistim.c:445
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_message_type * ast_mwi_state_type(void)
Get the Stasis Message Bus API message type for MWI messages.
static void send_led_update(struct unistimsession *pte, unsigned char led)
int ast_app_has_voicemail(const char *mailboxes, const char *folder)
Determine if a given mailbox has any voicemail If folder is NULL, defaults to "INBOX". If folder is "INBOX", includes the number of messages in the "Urgent" folder.
Definition: main/app.c:655
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
int new_msgs
Definition: mwi.h:461
#define LED_BAR_OFF
Definition: chan_unistim.c:151
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_message * stasis_cache_get(struct stasis_cache *cache, struct stasis_message_type *type, const char *id)
Retrieve an item from the cache for the ast_eid_default entity.
Definition: stasis_cache.c:686
The structure that contains MWI state.
Definition: mwi.h:457

◆ unistim_senddigit_begin()

static int unistim_senddigit_begin ( struct ast_channel ast,
char  digit 
)
static

Definition at line 5509 of file chan_unistim.c.

References channel_to_session(), and send_dtmf_tone().

5510 {
5511  struct unistimsession *pte = channel_to_session(ast);
5512 
5513  if (!pte) {
5514  return -1;
5515  }
5516  return send_dtmf_tone(pte, digit);
5517 }
char digit
static struct unistimsession * channel_to_session(struct ast_channel *ast)
static int send_dtmf_tone(struct unistimsession *pte, char digit)

◆ unistim_senddigit_end()

static int unistim_senddigit_end ( struct ast_channel ast,
char  digit,
unsigned int  duration 
)
static

Definition at line 5519 of file chan_unistim.c.

References ast_verb, channel_to_session(), send_tone(), and unistimdebug.

5520 {
5521  struct unistimsession *pte = channel_to_session(ast);
5522 
5523  if (!pte) {
5524  return -1;
5525  }
5526 
5527  if (unistimdebug) {
5528  ast_verb(0, "Send Digit off %c (duration %d)\n", digit, duration);
5529  }
5530  send_tone(pte, 0, 0);
5531  return 0;
5532 }
char digit
#define ast_verb(level,...)
Definition: logger.h:463
static int unistimdebug
Definition: chan_unistim.c:243
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
static struct unistimsession * channel_to_session(struct ast_channel *ast)

◆ unistim_sendtext()

static int unistim_sendtext ( struct ast_channel ast,
const char *  text 
)
static

Definition at line 5536 of file chan_unistim.c.

References ast_log, ast_verb, channel_to_session(), unistimsession::device, unistim_device::height, LOG_WARNING, send_favorite(), send_text(), unistim_device::softkeyicon, unistim_device::softkeylabel, unistim_device::softkeynumber, TEXT_LENGTH_MAX, TEXT_LINE0, TEXT_LINE1, TEXT_LINE2, TEXT_NORMAL, tmp(), unistimdebug, and ustmtext().

5537 {
5538  struct unistimsession *pte = channel_to_session(ast);
5539  int size;
5540  char tmp[TEXT_LENGTH_MAX + 1];
5541 
5542  if (unistimdebug) {
5543  ast_verb(0, "unistim_sendtext called\n");
5544  }
5545  if (!text) {
5546  ast_log(LOG_WARNING, "unistim_sendtext called with a null text\n");
5547  return -1;
5548  }
5549 
5550  if (!pte) {
5551  return -1;
5552  }
5553 
5554  size = strlen(text);
5555  if (text[0] == '@') {
5556  int pos = 0, i = 1, tok = 0, sz = 0;
5557  char label[11];
5558  char number[16];
5559  char icon = '\0';
5560  char cur = '\0';
5561 
5562  memset(label, 0, 11);
5563  memset(number, 0, 16);
5564  while (text[i]) {
5565  cur = text[i++];
5566  switch (tok) {
5567  case 0:
5568  if ((cur < '0') && (cur > '5')) {
5570  "sendtext failed : position must be a number beetween 0 and 5\n");
5571  return 1;
5572  }
5573  pos = cur - '0';
5574  tok = 1;
5575  continue;
5576  case 1:
5577  if (cur != '@') {
5578  ast_log(LOG_WARNING, "sendtext failed : invalid position\n");
5579  return 1;
5580  }
5581  tok = 2;
5582  continue;
5583  case 2:
5584  if ((cur < '3') && (cur > '6')) {
5586  "sendtext failed : icon must be a number beetween 32 and 63 (first digit invalid)\n");
5587  return 1;
5588  }
5589  icon = (cur - '0') * 10;
5590  tok = 3;
5591  continue;
5592  case 3:
5593  if ((cur < '0') && (cur > '9')) {
5595  "sendtext failed : icon must be a number beetween 32 and 63 (second digit invalid)\n");
5596  return 1;
5597  }
5598  icon += (cur - '0');
5599  tok = 4;
5600  continue;
5601  case 4:
5602  if (cur != '@') {
5604  "sendtext failed : icon must be a number beetween 32 and 63 (too many digits)\n");
5605  return 1;
5606  }
5607  tok = 5;
5608  continue;
5609  case 5:
5610  if (cur == '@') {
5611  tok = 6;
5612  sz = 0;
5613  continue;
5614  }
5615  if (sz > 10) {
5616  continue;
5617  }
5618  label[sz] = cur;
5619  sz++;
5620  continue;
5621  case 6:
5622  if (sz > 15) {
5624  "sendtext failed : extension too long = %d (15 car max)\n",
5625  sz);
5626  return 1;
5627  }
5628  number[sz] = cur;
5629  sz++;
5630  continue;
5631  }
5632  }
5633  if (tok != 6) {
5634  ast_log(LOG_WARNING, "sendtext failed : incomplet command\n");
5635  return 1;
5636  }
5637  if (!pte->device) {
5638  ast_log(LOG_WARNING, "sendtext failed : no device ?\n");
5639  return 1;
5640  }
5641  strcpy(pte->device->softkeylabel[pos], label);
5642  strcpy(pte->device->softkeynumber[pos], number);
5643  pte->device->softkeyicon[pos] = icon;
5644  send_favorite(pos, icon, pte, label);
5645  return 0;
5646  }
5647 
5648  if (size <= TEXT_LENGTH_MAX * 2) {
5649  if (pte->device->height == 1) {
5651  } else {
5652  send_text(TEXT_LINE0, TEXT_NORMAL, pte, ustmtext("Message :", pte));
5654  }
5655  if (size <= TEXT_LENGTH_MAX) {
5656  send_text(TEXT_LINE2, TEXT_NORMAL, pte, "");
5657  return 0;
5658  }
5659  memcpy(tmp, text + TEXT_LENGTH_MAX, TEXT_LENGTH_MAX);
5660  tmp[sizeof(tmp) - 1] = '\0';
5661  send_text(TEXT_LINE2, TEXT_NORMAL, pte, tmp);
5662  return 0;
5663  }
5665  memcpy(tmp, text + TEXT_LENGTH_MAX, TEXT_LENGTH_MAX);
5666  tmp[sizeof(tmp) - 1] = '\0';
5667  send_text(TEXT_LINE1, TEXT_NORMAL, pte, tmp);
5668  memcpy(tmp, text + TEXT_LENGTH_MAX * 2, TEXT_LENGTH_MAX);
5669  tmp[sizeof(tmp) - 1] = '\0';
5670  send_text(TEXT_LINE2, TEXT_NORMAL, pte, tmp);
5671  return 0;
5672 }
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
#define TEXT_LINE2
Definition: chan_unistim.c:172
#define TEXT_LINE1
Definition: chan_unistim.c:171
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
char softkeynumber[FAVNUM][AST_MAX_EXTENSION]
Definition: chan_unistim.c:406
char * text
Definition: app_queue.c:1508
#define TEXT_NORMAL
Definition: chan_unistim.c:173
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
#define ast_verb(level,...)
Definition: logger.h:463
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
Number structure.
Definition: app_followme.c:154
#define ast_log
Definition: astobj2.c:42
#define TEXT_LINE0
Definition: chan_unistim.c:170
static void send_favorite(unsigned char pos, unsigned char status, struct unistimsession *pte, const char *text)
char softkeyicon[FAVNUM]
Definition: chan_unistim.c:407
static void send_text(unsigned char pos, unsigned char inverse, struct unistimsession *pte, const char *text)
static struct unistimsession * channel_to_session(struct ast_channel *ast)

◆ unistim_set_owner()

static void unistim_set_owner ( struct unistim_subchannel sub,
struct ast_channel chan 
)
static

Definition at line 5827 of file chan_unistim.c.

References ast_channel_uniqueid(), ast_rtp_instance_set_channel_id(), unistim_subchannel::owner, and unistim_subchannel::rtp.

Referenced by unistim_fixup(), unistim_hangup_clean(), and unistim_new().

5828 {
5829  sub->owner = chan;
5830  if (sub->rtp) {
5832  }
5833 }
struct ast_channel * owner
Definition: chan_unistim.c:356
void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
Set the channel that owns this RTP instance.
Definition: rtp_engine.c:553
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
const char * ast_channel_uniqueid(const struct ast_channel *chan)

◆ unistim_set_rtp_peer()

static int unistim_set_rtp_peer ( struct ast_channel chan,
struct ast_rtp_instance rtp,
struct ast_rtp_instance vrtp,
struct ast_rtp_instance trtp,
const struct ast_format_cap codecs,
int  nat_active 
)
static

Definition at line 7047 of file chan_unistim.c.

References ast_channel_tech_pvt(), ast_log, ast_rtp_instance_get_local_address(), ast_rtp_instance_get_remote_address, ast_sockaddr_to_sin, LOG_ERROR, and sub.

7048 {
7050  struct sockaddr_in them = { 0, };
7051  struct sockaddr_in us = { 0, };
7052 
7053  if (!rtp) {
7054  return 0;
7055  }
7056 
7057  sub = (struct unistim_subchannel *) ast_channel_tech_pvt(chan);
7058  if (!sub) {
7059  ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
7060  return -1;
7061  }
7062  {
7063  struct ast_sockaddr tmp;
7065  ast_sockaddr_to_sin(&tmp, &them);
7067  ast_sockaddr_to_sin(&tmp, &us);
7068  }
7069 
7070  /* TODO: Set rtp on phone in case of direct rtp (not implemented) */
7071 
7072  return 0;
7073 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
static int tmp()
Definition: bt_open.c:389
Socket address structure.
Definition: netsock2.h:97
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the local address that we are expecting RTP on.
Definition: rtp_engine.c:643
struct stasis_forward * sub
Definition: res_corosync.c:240
#define ast_sockaddr_to_sin(addr, sin)
Converts a struct ast_sockaddr to a struct sockaddr_in.
Definition: netsock2.h:769
#define ast_rtp_instance_get_remote_address(instance, address)
Get the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.h:1192

◆ unistim_show_devices()

static char* unistim_show_devices ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 6117 of file chan_unistim.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), ast_inet_ntoa(), ast_mutex_lock, ast_mutex_unlock, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, devicelock, devices, ast_cli_args::fd, unistimsession::firmware, unistim_device::id, unistim_device::name, unistim_device::next, NULL, unistim_device::session, unistimsession::sin, and ast_cli_entry::usage.

6118 {
6119  struct unistim_device *device = devices;
6120 
6121  switch (cmd) {
6122  case CLI_INIT:
6123  e->command = "unistim show devices";
6124  e->usage =
6125  "Usage: unistim show devices\n"
6126  " Lists all known Unistim devices.\n";
6127  return NULL;
6128  case CLI_GENERATE:
6129  return NULL; /* no completion */
6130  }
6131 
6132  if (a->argc != e->args)
6133  return CLI_SHOWUSAGE;
6134 
6135  ast_cli(a->fd, "%-20.20s %-20.20s %-15.15s %-15.15s %s\n", "Name/username", "MAC", "Host", "Firmware", "Status");
6137  while (device) {
6138  ast_cli(a->fd, "%-20.20s %-20.20s %-15.15s %-15.15s %s\n",
6139  device->name, device->id,
6140  (!device->session) ? "(Unspecified)" : ast_inet_ntoa(device->session->sin.sin_addr),
6141  (!device->session) ? "(Unspecified)" : device->session->firmware,
6142  (!device->session) ? "UNKNOWN" : "OK");
6143  device = device->next;
6144  }
6146 
6147  return CLI_SUCCESS;
6148 }
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
char firmware[8]
Definition: chan_unistim.c:473
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int args
This gets set in ast_cli_register()
Definition: cli.h:185
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
const int fd
Definition: cli.h:159
struct unistim_device * next
Definition: chan_unistim.c:455
struct unistimsession * session
Definition: chan_unistim.c:454
#define CLI_SHOWUSAGE
Definition: cli.h:45
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
char * command
Definition: cli.h:186
static struct unistim_device * devices
struct sockaddr_in sin
Definition: chan_unistim.c:460
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unistim_show_info()

static char* unistim_show_info ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 6035 of file chan_unistim.c.

References unistim_subchannel::alreadygone, ast_cli_args::argc, ast_cli_entry::args, ast_cli(), ast_format_cap_get_names(), AST_FORMAT_CAP_NAMES_LEN, ast_inet_ntoa(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock, ast_mutex_unlock, ast_str_alloca, unistim_line::cap, unistim_line::cid_num, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, unistimsession::device, devicelock, devices, unistim_line::exten, FAVNUM, ast_cli_args::fd, unistim_line::fullname, unistim_device::ha, unistim_device::height, unistim_device::id, unistim_device::lines, unistimsession::macaddr, unistim_line::name, unistim_device::name, unistim_device::next, unistimsession::next, NULL, unistim_subchannel::owner, unistim_subchannel::parent, ptestate_tostr(), unistim_subchannel::rtp, unistim_device::selected, unistim_device::session, sessionlock, sessions, unistimsession::sin, unistim_device::sline, soft_key_visible(), unistim_subchannel::softkey, unistim_device::softkeydevice, unistim_device::softkeyicon, unistim_device::softkeylabel, unistim_device::softkeynumber, unistim_device::ssub, unistimsession::state, sub, unistim_device::subs, unistim_subchannel::subtype, subtype_tostr(), unistimsession::timeout, and ast_cli_entry::usage.

6036 {
6037  struct unistim_device *device = devices;
6038  struct unistim_line *line;
6039  struct unistim_subchannel *sub;
6040  struct unistimsession *s;
6041  struct ast_str *cap_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
6042 
6043  switch (cmd) {
6044  case CLI_INIT:
6045  e->command = "unistim show info";
6046  e->usage =
6047  "Usage: unistim show info\n"
6048  " Dump internal structures.\n\n"
6049  " device\n"
6050  " ->line\n"
6051  " -->sub\n"
6052  " ==>key\n";
6053  return NULL;
6054 
6055  case CLI_GENERATE:
6056  return NULL; /* no completion */
6057  }
6058 
6059  if (a->argc != e->args) {
6060  return CLI_SHOWUSAGE;
6061  }
6062  ast_cli(a->fd, "Dumping internal structures:\n");
6064  while (device) {
6065  int i;
6066 
6067  ast_cli(a->fd, "\nname=%s id=%s ha=%p sess=%p device=%p selected=%d height=%d\n",
6068  device->name, device->id, device->ha, device->session,
6069  device, device->selected, device->height);
6070  AST_LIST_LOCK(&device->lines);
6071  AST_LIST_TRAVERSE(&device->lines,line,list) {
6072  ast_cli(a->fd,
6073  "->name=%s fullname=%s exten=%s callid=%s cap=%s line=%p\n",
6074  line->name, line->fullname, line->exten, line->cid_num,
6075  ast_format_cap_get_names(line->cap, &cap_buf), line);
6076  }
6077  AST_LIST_UNLOCK(&device->lines);
6078 
6079  AST_LIST_LOCK(&device->subs);
6080  AST_LIST_TRAVERSE(&device->subs, sub, list) {
6081  if (!sub) {
6082  continue;
6083  }
6084  ast_cli(a->fd,
6085  "-->subtype=%s chan=%p rtp=%p line=%p alreadygone=%d softkey=%d\n",
6086  subtype_tostr(sub->subtype), sub->owner, sub->rtp, sub->parent,
6087  sub->alreadygone, sub->softkey);
6088  }
6089  AST_LIST_UNLOCK(&device->subs);
6090 
6091  for (i = 0; i < FAVNUM; i++) {
6092  if (!soft_key_visible(device, i)) {
6093  continue;
6094  }
6095  ast_cli(a->fd, "==> %d. dev=%s icon=%#-4x label=%-10s number=%-5s sub=%p line=%p\n",
6096  i, device->softkeydevice[i], (unsigned)device->softkeyicon[i], device->softkeylabel[i], device->softkeynumber[i],
6097  device->ssub[i], device->sline[i]);
6098  }
6099  device = device->next;
6100  }
6102  ast_cli(a->fd, "\nSessions:\n");
6104  s = sessions;
6105  while (s) {
6106  ast_cli(a->fd,
6107  "sin=%s timeout=%d state=%s macaddr=%s device=%p session=%p\n",
6108  ast_inet_ntoa(s->sin.sin_addr), s->timeout, ptestate_tostr(s->state), s->macaddr,
6109  s->device, s);
6110  s = s->next;
6111  }
6113 
6114  return CLI_SUCCESS;
6115 }
struct unistim_device::@152 subs
struct ast_channel * owner
Definition: chan_unistim.c:356
static int soft_key_visible(struct unistim_device *d, unsigned char num)
static struct unistimsession * sessions
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
char softkeylabel[FAVNUM][11]
Definition: chan_unistim.c:405
A device containing one or more lines.
Definition: chan_unistim.c:394
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
struct unistim_device::@153 lines
#define FAVNUM
Definition: chan_unistim.c:216
const int argc
Definition: cli.h:160
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
Definition: cli.h:152
char softkeynumber[FAVNUM][AST_MAX_EXTENSION]
Definition: chan_unistim.c:406
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static ast_mutex_t sessionlock
Definition: chan_unistim.c:271
int args
This gets set in ast_cli_register()
Definition: cli.h:185
struct unistim_device * device
Definition: chan_unistim.c:476
unsigned int subtype
Definition: chan_unistim.c:355
struct unistimsession * next
Definition: chan_unistim.c:477
struct ast_ha * ha
Definition: chan_unistim.c:453
char name[80]
Definition: chan_unistim.c:374
static ast_mutex_t devicelock
Definition: chan_unistim.c:273
char macaddr[18]
Definition: chan_unistim.c:472
const int fd
Definition: cli.h:159
struct unistim_device * next
Definition: chan_unistim.c:455
struct unistimsession * session
Definition: chan_unistim.c:454
char cid_num[AST_MAX_EXTENSION]
Definition: chan_unistim.c:377
static const char * subtype_tostr(const int type)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define CLI_SHOWUSAGE
Definition: cli.h:45
char softkeydevice[FAVNUM][16]
Definition: chan_unistim.c:408
static const char * ptestate_tostr(const int type)
struct unistim_line * sline[FAVNUM]
Definition: chan_unistim.c:410
char softkeyicon[FAVNUM]
Definition: chan_unistim.c:407
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
char * command
Definition: cli.h:186
static struct unistim_device * devices
struct sockaddr_in sin
Definition: chan_unistim.c:460
char exten[AST_MAX_EXTENSION]
Definition: chan_unistim.c:376
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
char fullname[101]
Definition: chan_unistim.c:375
struct unistim_line * parent
Definition: chan_unistim.c:357
struct stasis_forward * sub
Definition: res_corosync.c:240
struct unistim_subchannel * ssub[FAVNUM]
Definition: chan_unistim.c:409
struct ast_format_cap * cap
Definition: chan_unistim.c:384
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unistim_sp()

static char* unistim_sp ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 6150 of file chan_unistim.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), BUFFSEND, c, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, find_subchannel_by_name(), len(), NULL, unistim_subchannel::parent, unistim_line::parent, send_client(), unistim_device::session, SIZE_HEADER, sub, tmp(), and ast_cli_entry::usage.

6151 {
6152  BUFFSEND;
6153  struct unistim_subchannel *sub;
6154  int i, j = 0, len;
6155  unsigned char c, cc;
6156  char tmp[256];
6157 
6158  switch (cmd) {
6159  case CLI_INIT:
6160  e->command = "unistim send packet";
6161  e->usage =
6162  "Usage: unistim send packet USTM/line@name hexa\n"
6163  " unistim send packet USTM/1000@hans 19040004\n";
6164  return NULL;
6165 
6166  case CLI_GENERATE:
6167  return NULL; /* no completion */
6168  }
6169 
6170  if (a->argc < 5) {
6171  return CLI_SHOWUSAGE;
6172  }
6173  if (strlen(a->argv[3]) < 9) {
6174  return CLI_SHOWUSAGE;
6175  }
6176  len = strlen(a->argv[4]);
6177  if (len % 2) {
6178  return CLI_SHOWUSAGE;
6179  }
6180  ast_copy_string(tmp, a->argv[3] + 5, sizeof(tmp));
6181  sub = find_subchannel_by_name(tmp);
6182  if (!sub) {
6183  ast_cli(a->fd, "Can't find '%s'\n", tmp);
6184  return CLI_SUCCESS;
6185  }
6186  if (!sub->parent->parent->session) {
6187  ast_cli(a->fd, "'%s' is not connected\n", tmp);
6188  return CLI_SUCCESS;
6189  }
6190  ast_cli(a->fd, "Sending '%s' to %s (%p)\n", a->argv[4], tmp, sub->parent->parent->session);
6191  for (i = 0; i < len; i++) {
6192  c = a->argv[4][i];
6193  if (c >= 'a') {
6194  c -= 'a' - 10;
6195  } else {
6196  c -= '0';
6197  }
6198  i++;
6199  cc = a->argv[4][i];
6200  if (cc >= 'a') {
6201  cc -= 'a' - 10;
6202  } else {
6203  cc -= '0';
6204  }
6205  tmp[j++] = (c << 4) | cc;
6206  }
6207  memcpy(buffsend + SIZE_HEADER, tmp, j);
6208  send_client(SIZE_HEADER + j, buffsend, sub->parent->parent->session);
6209  return CLI_SUCCESS;
6210 }
static void send_client(int size, const unsigned char *data, struct unistimsession *pte)
Definition: chan_unistim.c:959
const int argc
Definition: cli.h:160
static int tmp()
Definition: bt_open.c:389
Definition: cli.h:152
#define BUFFSEND
Definition: chan_unistim.c:704
static struct test_val c
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static struct unistim_subchannel * find_subchannel_by_name(const char *dest)
const int fd
Definition: cli.h:159
#define SIZE_HEADER
Definition: chan_unistim.c:167
struct unistimsession * session
Definition: chan_unistim.c:454
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
struct unistim_line * parent
Definition: chan_unistim.c:357
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240

◆ unistim_ss()

static void* unistim_ss ( void *  data)
static

Definition at line 2659 of file chan_unistim.c.

References ast_channel_exten_set(), ast_channel_lock, ast_channel_tech_pvt(), ast_channel_unlock, ast_copy_string(), ast_log, ast_pbx_run(), ast_setstate(), AST_STATE_RING, ast_verb, ast_channel::data, unistimsession::device, LOG_WARNING, unistim_line::name, unistim_device::name, NULL, unistim_subchannel::parent, unistim_line::parent, unistim_device::phone_number, unistim_device::redial_number, send_tone(), unistim_device::session, unistim_subchannel::softkey, and sub.

Referenced by handle_call_outgoing().

2660 {
2661  struct ast_channel *chan = data;
2663  struct unistim_line *l = sub->parent;
2664  struct unistimsession *s = l->parent->session;
2665  int res;
2666 
2667  if (!s) {
2668  return NULL;
2669  }
2670  ast_verb(3, "Starting switch on '%s@%s-%d' to %s\n", l->name, l->parent->name, sub->softkey, s->device->phone_number);
2671  ast_channel_lock(chan);
2674  ast_channel_unlock(chan);
2676  sizeof(s->device->redial_number));
2677  res = ast_pbx_run(chan);
2678  if (res) {
2679  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2680  send_tone(s, 1000, 0);
2681  }
2682  return NULL;
2683 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define LOG_WARNING
Definition: logger.h:274
char phone_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:399
#define NULL
Definition: resample.c:96
const char * data
#define ast_verb(level,...)
Definition: logger.h:463
struct unistim_device * device
Definition: chan_unistim.c:476
char name[80]
Definition: chan_unistim.c:374
static void send_tone(struct unistimsession *pte, uint16_t tone1, uint16_t tone2)
#define ast_log
Definition: astobj2.c:42
struct unistimsession * session
Definition: chan_unistim.c:454
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
struct unistim_line * parent
Definition: chan_unistim.c:357
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7486
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:4759
struct unistim_device * parent
Definition: chan_unistim.c:387
struct stasis_forward * sub
Definition: res_corosync.c:240
char redial_number[AST_MAX_EXTENSION]
Definition: chan_unistim.c:400

◆ unistim_unalloc_sub()

static int unistim_unalloc_sub ( struct unistim_device d,
struct unistim_subchannel sub 
)
static

Definition at line 2007 of file chan_unistim.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, unistim_subchannel::list, unistim_device::subs, and unistim_free_sub().

Referenced by unistim_hangup(), and unistim_request().

2008 {
2009  struct unistim_subchannel *s;
2010 
2011  AST_LIST_LOCK(&d->subs);
2013  if (!s) {
2014  continue;
2015  }
2016  if (s != sub) {
2017  continue;
2018  }
2020  unistim_free_sub(sub);
2021  }
2023  AST_LIST_UNLOCK(&d->subs);
2024  return 0;
2025 }
struct unistim_device::@152 subs
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static int unistim_free_sub(struct unistim_subchannel *)
struct unistim_subchannel::@150 list
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528

◆ unistim_write()

static int unistim_write ( struct ast_channel ast,
struct ast_frame frame 
)
static

Definition at line 5216 of file chan_unistim.c.

References ast_channel_nativeformats(), ast_channel_readformat(), ast_channel_tech_pvt(), ast_channel_writeformat(), ast_format_cap_get_names(), ast_format_cap_iscompatible_format(), AST_FORMAT_CAP_NAMES_LEN, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_name(), AST_FRAME_IMAGE, AST_FRAME_VOICE, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_rtp_instance_write(), ast_str_alloca, ast_frame_subclass::format, ast_frame::frametype, unistim_subchannel::lock, LOG_WARNING, unistim_subchannel::rtp, sub, and ast_frame::subclass.

5217 {
5219  int res = 0;
5220 
5221  if (frame->frametype != AST_FRAME_VOICE) {
5222  if (frame->frametype == AST_FRAME_IMAGE) {
5223  return 0;
5224  } else {
5225  ast_log(LOG_WARNING, "Can't send %u type frames with unistim_write\n",
5226  frame->frametype);
5227  return 0;
5228  }
5229  } else {
5231  struct ast_str *cap_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
5232 
5234  "Asked to transmit frame type %s, while native formats is %s (read/write = (%s/%s)\n",
5239  return -1;
5240  }
5241  }
5242 
5243  if (sub) {
5244  ast_mutex_lock(&sub->lock);
5245  if (sub->rtp) {
5246  res = ast_rtp_instance_write(sub->rtp, frame);
5247  }
5248  ast_mutex_unlock(&sub->lock);
5249  }
5250 
5251  return res;
5252 }
ast_mutex_t lock
Definition: chan_unistim.c:354
struct ast_rtp_instance * rtp
Definition: chan_unistim.c:358
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define LOG_WARNING
Definition: logger.h:274
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Send a frame out over RTP.
Definition: rtp_engine.c:568
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
struct ast_frame_subclass subclass
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
enum ast_format_cmp_res ast_format_cap_iscompatible_format(const struct ast_format_cap *cap, const struct ast_format *format)
Find if ast_format is within the capabilities of the ast_format_cap object.
Definition: format_cap.c:583
#define ast_log
Definition: astobj2.c:42
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct stasis_forward * sub
Definition: res_corosync.c:240
enum ast_frame_type frametype
struct ast_format * format
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unistimsock_read()

static int unistimsock_read ( int *  id,
int  fd,
short  events,
void *  ignore 
)
static

Definition at line 5089 of file chan_unistim.c.

References ast_inet_ntoa(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_verb, buff, errno, LOG_NOTICE, LOG_WARNING, unistimsession::next, NULL, parsing(), sessionlock, sessions, unistimsession::sin, SIZE_PAGE, tmp(), unistimdebug, and unistimsock.

Referenced by do_monitor().

5090 {
5091  struct sockaddr_in addr_from = { 0, };
5092  struct unistimsession *cur = NULL;
5093  int found = 0;
5094  int tmp = 0;
5095  int dw_num_bytes_rcvd;
5096  unsigned int size_addr_from;
5097 #ifdef DUMP_PACKET
5098  int dw_num_bytes_rcvdd;
5099 #endif
5100 
5101  size_addr_from = sizeof(addr_from);
5102  dw_num_bytes_rcvd =
5103  recvfrom(unistimsock, buff, SIZE_PAGE, 0, (struct sockaddr *) &addr_from,
5104  &size_addr_from);
5105  if (dw_num_bytes_rcvd == -1) {
5106  if (errno == EAGAIN) {
5107  ast_log(LOG_NOTICE, "UNISTIM: Received packet with bad UDP checksum\n");
5108  } else if (errno != ECONNREFUSED) {
5109  ast_log(LOG_WARNING, "Recv error %d (%s)\n", errno, strerror(errno));
5110  }
5111  return 1;
5112  }
5113 
5114  /* Looking in the phone list if we already have a registration for him */
5116  cur = sessions;
5117  while (cur) {
5118  if (cur->sin.sin_addr.s_addr == addr_from.sin_addr.s_addr) {
5119  found = 1;
5120  break;
5121  }
5122  tmp++;
5123  cur = cur->next;
5124  }
5126 
5127 #ifdef DUMP_PACKET
5128  if (unistimdebug)
5129  ast_verb(0, "\n*** Dump %d bytes from %s - phone_table[%d] ***\n",
5130  dw_num_bytes_rcvd, ast_inet_ntoa(addr_from.sin_addr), tmp);
5131  for (dw_num_bytes_rcvdd = 0; dw_num_bytes_rcvdd < dw_num_bytes_rcvd;
5132  dw_num_bytes_rcvdd++)
5133  ast_verb(0, "%02hhx ", buff[dw_num_bytes_rcvdd]);
5134  ast_verb(0, "\n******************************************\n");
5135 #endif
5136 
5137  if (!found) {
5138  if (unistimdebug) {
5139  ast_verb(0, "Received a packet from an unknown source\n");
5140  }
5141  parsing(dw_num_bytes_rcvd, buff, NULL, (struct sockaddr_in *) &addr_from);
5142 
5143  } else {
5144  parsing(dw_num_bytes_rcvd, buff, cur, (struct sockaddr_in *) &addr_from);
5145  }
5146  return 1;
5147 }
static struct unistimsession * sessions
static int unistimsock
Definition: chan_unistim.c:247
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
static ast_mutex_t sessionlock
Definition: chan_unistim.c:271
static int unistimdebug
Definition: chan_unistim.c:243
struct unistimsession * next
Definition: chan_unistim.c:477
#define ast_log
Definition: astobj2.c:42
int errno
#define LOG_NOTICE
Definition: logger.h:263
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
struct sockaddr_in sin
Definition: chan_unistim.c:460
static void parsing(int size, unsigned char *buf, struct unistimsession *pte, struct sockaddr_in *addr_from)
static unsigned char * buff
Definition: chan_unistim.c:259
#define SIZE_PAGE
Definition: chan_unistim.c:111
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 7153 of file chan_unistim.c.

References ao2_cleanup, ao2_ref, ARRAY_LEN, ast_channel_unregister(), ast_cli_unregister_multiple(), ast_free, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_rtp_glue_unregister(), ast_sched_context_destroy(), buff, ast_channel_tech::capabilities, monitor_thread, monlock, NULL, and unistimsock.

Referenced by reload().

7154 {
7155  /* First, take us out of the channel loop */
7156  if (sched) {
7158  }
7159 
7161 
7165 
7168  pthread_cancel(monitor_thread);
7169  pthread_kill(monitor_thread, SIGURG);
7170  pthread_join(monitor_thread, NULL);
7171  }
7174 
7175  if (buff) {
7176  ast_free(buff);
7177  }
7178  if (unistimsock > -1) {
7179  close(unistimsock);
7180  }
7181  ao2_ref(global_cap, -1);
7182 
7183  return 0;
7184 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static pthread_t monitor_thread
Definition: chan_unistim.c:265
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static int unistimsock
Definition: chan_unistim.c:247
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
Definition: channel.c:570
static struct ast_cli_entry unistim_cli[]
Definition: sched.c:76
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_format_cap * capabilities
Definition: channel.h:633
#define ast_free(a)
Definition: astmm.h:182
struct ast_format_cap * global_cap
Definition: chan_unistim.c:120
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static unsigned char * buff
Definition: chan_unistim.c:259
#define AST_PTHREADT_STOP
Definition: lock.h:67
int ast_rtp_glue_unregister(struct ast_rtp_glue *glue)
Unregister RTP glue.
Definition: rtp_engine.c:408
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition: sched.c:269
static struct ast_channel_tech unistim_tech
Definition: chan_unistim.c:736
#define ast_mutex_unlock(a)
Definition: lock.h:188
static ast_mutex_t monlock
Definition: chan_unistim.c:269
static struct ast_rtp_glue unistim_rtp_glue

◆ unquote()

static void unquote ( char *  out,
const char *  src,
int  maxlen 
)
static

Definition at line 6275 of file chan_unistim.c.

References len().

Referenced by build_device().

6276 {
6277  int len = strlen(src);
6278  if (!len) {
6279  return;
6280  }
6281  if ((len > 1) && src[0] == '\"') {
6282  /* This is a quoted string */
6283  src++;
6284  /* Don't take more than what's there */
6285  len--;
6286  if (maxlen > len - 1) {
6287  maxlen = len - 1;
6288  }
6289  memcpy(out, src, maxlen);
6290  ((char *) out)[maxlen] = '\0';
6291  } else {
6292  memcpy(out, src, maxlen);
6293  }
6294  return;
6295 }
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
FILE * out
Definition: utils/frame.c:33

◆ unregister_extension()

static int unregister_extension ( const struct unistimsession pte)
static

Definition at line 1459 of file chan_unistim.c.

References ast_context_remove_extension(), ast_verb, unistim_device::context, unistimsession::device, unistim_device::extension_number, and unistimdebug.

Referenced by close_client(), and key_main_page().

1460 {
1461  if (unistimdebug) {
1462  ast_verb(0, "Trying to unregister extension '%s' context '%s'\n",
1463  pte->device->extension_number, pte->device->context);
1464  }
1466  pte->device->extension_number, 1, "Unistim");
1467 }
#define ast_verb(level,...)
Definition: logger.h:463
int ast_context_remove_extension(const char *context, const char *extension, int priority, const char *registrar)
Simply remove extension from context.
Definition: pbx.c:4952
static int unistimdebug
Definition: chan_unistim.c:243
struct unistim_device * device
Definition: chan_unistim.c:476
char context[AST_MAX_EXTENSION]
Definition: chan_unistim.c:398
char extension_number[11]
Definition: chan_unistim.c:448

◆ ustmtext()

static const char* ustmtext ( const char *  str,
struct unistimsession pte 
)
static

Definition at line 800 of file chan_unistim.c.

References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_find, ao2_link, ao2_ref, ast_config_AST_VAR_DIR, ast_free, ast_log, ast_strdup, ast_strlen_zero, unistimsession::device, find_language(), lang_cmp_fn(), lang_hash_fn(), unistim_languages::lang_short, unistim_device::language, LOG_ERROR, LOG_WARNING, NULL, OBJ_POINTER, str, ustm_lang_entry::str_orig, ustm_lang_entry::str_trans, tmp(), unistim_languages::trans, USTM_LANG_DIR, and ustm_strcopy.

Referenced by handle_call_incoming(), handle_call_outgoing(), handle_dial_page(), handle_select_codec(), handle_select_language(), handle_select_option(), init_phone_step2(), key_dial_page(), key_select_extension(), send_callerid_screen(), send_expansion_short(), send_favorite(), send_month_labels(), show_entry_history(), show_extension_page(), show_main_page(), show_phone_number(), unistim_answer(), unistim_call(), unistim_hangup(), unistim_indicate(), unistim_sendtext(), and write_history().

801 {
802  struct ustm_lang_entry *lang_entry;
803  struct ustm_lang_entry le_search;
804  struct unistim_languages *lang = NULL;
805  int size;
806 
807  if (pte->device) {
809  }
810  if (!lang) {
811  return str;
812  }
813  /* Check if specified language exists */
814  if (!lang->trans) {
815  char tmp[1024], *p, *p_orig = NULL, *p_trans = NULL;
816  FILE *f;
817 
820  if (!lang->trans) {
821  ast_log(LOG_ERROR, "Unable to allocate container for translation!\n");
822  return str;
823  }
824  snprintf(tmp, sizeof(tmp), "%s/%s/%s.po", ast_config_AST_VAR_DIR,
825  USTM_LANG_DIR, lang->lang_short);
826  f = fopen(tmp, "r");
827  if (!f) {
828  ast_log(LOG_WARNING, "There is no translation file for '%s'\n", lang->lang_short);
829  return str;
830  }
831  while (fgets(tmp, sizeof(tmp), f)) {
832  if (!(p = strchr(tmp, '\n'))) {
833  ast_log(LOG_ERROR, "Too long line found in language file - truncated!\n");
834  continue;
835  }
836  *p = '\0';
837  if (!(p = strchr(tmp, '"'))) {
838  continue;
839  }
840  if (tmp == strstr(tmp, "msgid")) {
841  p_orig = ast_strdup(p + 1);
842  p = strchr(p_orig, '"');
843  } else if (tmp == strstr(tmp, "msgstr")) {
844  p_trans = ast_strdup(p + 1);
845  p = strchr(p_trans, '"');
846  } else {
847  continue;
848  }
849  *p = '\0';
850  if (!p_trans || !p_orig) {
851  continue;
852  }
853  if (ast_strlen_zero(p_trans)) {
854  ast_free(p_trans);
855  ast_free(p_orig);
856  p_trans = NULL;
857  p_orig = NULL;
858  continue;
859  }
860  if (!(lang_entry = ao2_alloc(sizeof(*lang_entry), NULL))) {
861  fclose(f);
862  return str;
863  }
864 
865  lang_entry->str_trans = p_trans;
866  lang_entry->str_orig = p_orig;
867  ao2_link(lang->trans, lang_entry);
868  p_trans = NULL;
869  p_orig = NULL;
870  }
871 
872  fclose(f);
873  }
874 
875  le_search.str_orig = str;
876  if ((lang_entry = ao2_find(lang->trans, &le_search, OBJ_POINTER))) {
877  size = strlen(lang_entry->str_trans)+1;
878  if (size > 1024) {
879  size = 1024;
880  }
881  memcpy(ustm_strcopy, lang_entry->str_trans, size);
882  ao2_ref(lang_entry, -1);
883  return ustm_strcopy;
884  }
885 
886  return str;
887 }
#define OBJ_POINTER
Definition: astobj2.h:1154
struct ao2_container * trans
Definition: chan_unistim.c:492
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
static struct unistim_languages options_languages[]
Definition: chan_unistim.c:771
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
const char * str_orig
Definition: chan_unistim.c:782
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct unistim_device * device
Definition: chan_unistim.c:476
static int find_language(const char *)
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define USTM_LANG_DIR
Definition: chan_unistim.c:88
static int lang_cmp_fn(void *obj, void *arg, int flags)
Definition: chan_unistim.c:792
#define LOG_ERROR
Definition: logger.h:285
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static int lang_hash_fn(const void *obj, const int flags)
Definition: chan_unistim.c:786
#define ast_free(a)
Definition: astmm.h:182
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
char language[MAX_LANGUAGE]
Definition: chan_unistim.c:412
const char * str_trans
Definition: chan_unistim.c:783
const char * ast_config_AST_VAR_DIR
Definition: options.c:157
Definition: chan_unistim.c:781
static char ustm_strcopy[1024]
Definition: chan_unistim.c:779
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ write_entry_history()

static int write_entry_history ( struct unistimsession pte,
FILE *  f,
char  c,
char *  line1 
)
static

Definition at line 2260 of file chan_unistim.c.

References unistimsession::device, display_last_error(), unistim_device::lst_cid, unistim_device::lst_cnm, and TEXT_LENGTH_MAX.

Referenced by write_history().

2261 {
2262  if (fwrite(&c, 1, 1, f) != 1) {
2263  display_last_error("Unable to write history log header.");
2264  return -1;
2265  }
2266  if (fwrite(line1, TEXT_LENGTH_MAX, 1, f) != 1) {
2267  display_last_error("Unable to write history entry - date.");
2268  return -1;
2269  }
2270  if (fwrite(pte->device->lst_cid, TEXT_LENGTH_MAX, 1, f) != 1) {
2271  display_last_error("Unable to write history entry - callerid.");
2272  return -1;
2273  }
2274  if (fwrite(pte->device->lst_cnm, TEXT_LENGTH_MAX, 1, f) != 1) {
2275  display_last_error("Unable to write history entry - callername.");
2276  return -1;
2277  }
2278  return 0;
2279 }
char lst_cnm[TEXT_LENGTH_MAX]
Definition: chan_unistim.c:437
static struct test_val c
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
struct unistim_device * device
Definition: chan_unistim.c:476
char lst_cid[TEXT_LENGTH_MAX]
Definition: chan_unistim.c:436
static void display_last_error(const char *sz_msg)
Definition: chan_unistim.c:889

◆ write_history()

static int write_history ( struct unistimsession pte,
char  way,
char  ismissed 
)
static

Definition at line 2281 of file chan_unistim.c.

References ast_config_AST_LOG_DIR, AST_CONFIG_MAX_PATH, ast_copy_string(), ast_free, ast_localtime(), ast_log, ast_malloc, ast_mkdir(), ast_tvnow(), c, unistim_device::callhistory, unistimsession::device, display_last_error(), errno, LOG_WARNING, MAX_ENTRY_LOG, unistim_device::name, NULL, TEXT_LENGTH_MAX, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, ast_tm::tm_sec, ast_tm::tm_year, tmp(), USTM_LOG_DIR, ustmtext(), and write_entry_history().

Referenced by close_call(), handle_call_incoming(), and unistim_hangup().

2282 {
2284  char line1[TEXT_LENGTH_MAX + 1];
2285  char count = 0, *histbuf;
2286  int size;
2287  FILE *f, *f2;
2288  struct timeval now = ast_tvnow();
2289  struct ast_tm atm = { 0, };
2290 
2291  if (!pte->device) {
2292  return -1;
2293  }
2294  if (!pte->device->callhistory) {
2295  return 0;
2296  }
2297  if (strchr(pte->device->name, '/') || (pte->device->name[0] == '.')) {
2298  ast_log(LOG_WARNING, "Account code '%s' insecure for writing file\n",
2299  pte->device->name);
2300  return -1;
2301  }
2302 
2303  snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, USTM_LOG_DIR);
2304  if (ast_mkdir(tmp, 0770)) {
2305  ast_log(LOG_WARNING, "Unable to create directory for history\n");
2306  return -1;
2307  }
2308 
2309  ast_localtime(&now, &atm, NULL);
2310  if (ismissed) {
2311  if (way == 'i') {
2312  ast_copy_string(tmp2, ustmtext("Miss", pte), sizeof(tmp2));
2313  } else {
2314  ast_copy_string(tmp2, ustmtext("Fail", pte), sizeof(tmp2));
2315  }
2316  } else {
2317  ast_copy_string(tmp2, ustmtext("Answ", pte), sizeof(tmp2));
2318  }
2319  snprintf(line1, sizeof(line1), "%04d/%02d/%02d %02d:%02d:%02d %s",
2320  atm.tm_year + 1900, atm.tm_mon + 1, atm.tm_mday, atm.tm_hour,
2321  atm.tm_min, atm.tm_sec, tmp2);
2322 
2323  snprintf(tmp, sizeof(tmp), "%s/%s/%s-%c.csv", ast_config_AST_LOG_DIR,
2324  USTM_LOG_DIR, pte->device->name, way);
2325  if ((f = fopen(tmp, "r"))) {
2326  struct stat bufstat;
2327 
2328  if (stat(tmp, &bufstat)) {
2329  display_last_error("Unable to stat history log.");
2330  fclose(f);
2331  return -1;
2332  }
2333  size = 1 + (MAX_ENTRY_LOG * TEXT_LENGTH_MAX * 3);
2334  if (bufstat.st_size != size) {
2336  "History file %s has an incorrect size (%d instead of %d). It will be replaced by a new one.",
2337  tmp, (int) bufstat.st_size, size);
2338  fclose(f);
2339  f = NULL;
2340  count = 1;
2341  }
2342  }
2343 
2344  /* If we can't open the log file, we create a brand new one */
2345  if (!f) {
2346  char c = 1;
2347  int i;
2348 
2349  if ((errno != ENOENT) && (count == 0)) {
2350  display_last_error("Unable to open history log.");
2351  return -1;
2352  }
2353  f = fopen(tmp, "w");
2354  if (!f) {
2355  display_last_error("Unable to create history log.");
2356  return -1;
2357  }
2358  if (write_entry_history(pte, f, c, line1)) {
2359  fclose(f);
2360  return -1;
2361  }
2362  memset(line1, ' ', TEXT_LENGTH_MAX);
2363  for (i = 3; i < MAX_ENTRY_LOG * 3; i++) {
2364  if (fwrite(line1, TEXT_LENGTH_MAX, 1, f) != 1) {
2365  display_last_error("Unable to write history entry - stuffing.");
2366  fclose(f);
2367  return -1;
2368  }
2369  }
2370  if (fclose(f)) {
2371  display_last_error("Unable to close history - creation.");
2372  }
2373  return 0;
2374  }
2375  /* We can open the log file, we create a temporary one, we add our entry and copy the rest */
2376  if (fread(&count, 1, 1, f) != 1) {
2377  display_last_error("Unable to read history header.");
2378  fclose(f);
2379  return -1;
2380  }
2381  if (count > MAX_ENTRY_LOG) {
2382  ast_log(LOG_WARNING, "Invalid count in history header of %s (%d max %d)\n", tmp,
2383  count, MAX_ENTRY_LOG);
2384  fclose(f);
2385  return -1;
2386  }
2387  snprintf(tmp2, sizeof(tmp2), "%s/%s/%s-%c.csv.tmp", ast_config_AST_LOG_DIR,
2388  USTM_LOG_DIR, pte->device->name, way);
2389  if (!(f2 = fopen(tmp2, "w"))) {
2390  display_last_error("Unable to create temporary history log.");
2391  fclose(f);
2392  return -1;
2393  }
2394 
2395  if (++count > MAX_ENTRY_LOG) {
2396  count = MAX_ENTRY_LOG;
2397  }
2398  if (write_entry_history(pte, f2, count, line1)) {
2399  fclose(f);
2400  fclose(f2);
2401  return -1;
2402  }
2403  size = (MAX_ENTRY_LOG - 1) * TEXT_LENGTH_MAX * 3;
2404  if (!(histbuf = ast_malloc(size))) {
2405  fclose(f);
2406  fclose(f2);
2407  return -1;
2408  }
2409 
2410  if (fread(histbuf, size, 1, f) != 1) {
2411  ast_free(histbuf);
2412  fclose(f);
2413  fclose(f2);
2414  display_last_error("Unable to read previous history entries.");
2415  return -1;
2416  }
2417  if (fwrite(histbuf, size, 1, f2) != 1) {
2418  ast_free(histbuf);
2419  fclose(f);
2420  fclose(f2);
2421  display_last_error("Unable to write previous history entries.");
2422  return -1;
2423  }
2424  ast_free(histbuf);
2425  if (fclose(f)) {
2426  display_last_error("Unable to close history log.");
2427  }
2428  if (fclose(f2)) {
2429  display_last_error("Unable to close temporary history log.");
2430  }
2431  if (unlink(tmp)) {
2432  display_last_error("Unable to remove old history log.");
2433  }
2434  if (rename(tmp2, tmp)) {
2435  display_last_error("Unable to rename new history log.");
2436  }
2437  return 0;
2438 }
char name[DEVICE_NAME_LEN]
Definition: chan_unistim.c:402
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_CONFIG_MAX_PATH
Definition: chan_unistim.c:113
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
static struct test_val c
#define NULL
Definition: resample.c:96
static const char * ustmtext(const char *str, struct unistimsession *pte)
Definition: chan_unistim.c:800
int tm_year
Definition: localtime.h:41
#define TEXT_LENGTH_MAX
Definition: chan_unistim.c:169
#define USTM_LOG_DIR
Definition: chan_unistim.c:87
struct unistim_device * device
Definition: chan_unistim.c:476
#define ast_log
Definition: astobj2.c:42
int tm_mon
Definition: localtime.h:40
#define MAX_ENTRY_LOG
Definition: chan_unistim.c:114
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
int tm_mday
Definition: localtime.h:39
int errno
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
#define ast_free(a)
Definition: astmm.h:182
int tm_hour
Definition: localtime.h:38
static int write_entry_history(struct unistimsession *pte, FILE *f, char c, char *line1)
int tm_sec
Definition: localtime.h:36
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static void display_last_error(const char *sz_msg)
Definition: chan_unistim.c:889
int tm_min
Definition: localtime.h:37
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: main/utils.c:2231

Variable Documentation

◆ __mod_info

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

Definition at line 7208 of file chan_unistim.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 7208 of file chan_unistim.c.

◆ autoprovisioning

enum autoprovision autoprovisioning = AUTOPROVISIONING_NO
static

◆ buff

unsigned char* buff
static

◆ channel_type

const char channel_type[] = "USTM"
static

Definition at line 707 of file chan_unistim.c.

Referenced by load_module().

◆ cos

unsigned int cos

Definition at line 252 of file chan_unistim.c.

◆ cos_audio

unsigned int cos_audio

Definition at line 253 of file chan_unistim.c.

◆ default_jbconf

struct ast_jb_conf default_jbconf
static

Global jitterbuffer configuration - by default, jb is disabled.

Note
Values shown here match the defaults shown in unistim.conf.sample

Definition at line 227 of file chan_unistim.c.

◆ devicelock

ast_mutex_t devicelock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

◆ devices

struct unistim_device * devices = NULL
static

◆ dtmf_col

const float dtmf_col[] = { 1209, 1336, 1477, 1633 }
static

Definition at line 346 of file chan_unistim.c.

Referenced by send_dtmf_tone().

◆ dtmf_row

const int dtmf_row[] = { 697, 770, 852, 941 }
static

Definition at line 345 of file chan_unistim.c.

Referenced by send_dtmf_tone().

◆ global_cap

struct ast_format_cap* global_cap

Definition at line 120 of file chan_unistim.c.

◆ global_jbconf

struct ast_jb_conf global_jbconf
static

Definition at line 235 of file chan_unistim.c.

Referenced by reload_config(), and unistim_new().

◆ io

struct io_context* io
static

Definition at line 256 of file chan_unistim.c.

◆ monitor_thread

pthread_t monitor_thread = AST_PTHREADT_NULL
static

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

Definition at line 265 of file chan_unistim.c.

Referenced by restart_monitor(), and unload_module().

◆ monlock

ast_mutex_t monlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

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

Definition at line 269 of file chan_unistim.c.

Referenced by restart_monitor(), and unload_module().

◆ monthlabels

unsigned char monthlabels[]
static
Initial value:
=
{ 'J', 'a', 'n', 'F', 'e', 'b', 'M', 'a', 'r', 'A', 'p', 'r', 'M', 'a', 'y', 'J', 'u', 'n',
'J', 'u', 'l', 'A', 'u', 'g', 'S', 'e', 'p', 'O', 'c', 't', 'N', 'o', 'v', 'D', 'e', 'c' }

Definition at line 649 of file chan_unistim.c.

Referenced by send_month_labels().

◆ options_languages

struct unistim_languages options_languages[]
static

Definition at line 771 of file chan_unistim.c.

◆ options_menu

struct unistim_menu_item options_menu[]
static

Definition at line 764 of file chan_unistim.c.

◆ packet_rcv_discovery

const unsigned char packet_rcv_discovery[]
static
Initial value:
=
{ 0xff, 0xff, 0xff, 0xff, 0x02, 0x02, 0xff, 0xff, 0xff, 0xff, 0x9e, 0x03, 0x08 }

Definition at line 506 of file chan_unistim.c.

Referenced by parsing().

◆ packet_recv_expansion_pressed_key

const unsigned char packet_recv_expansion_pressed_key[]
static
Initial value:
=
{ 0x00, 0x00, 0x00, 0x13, 0x89, 0x04, 0x59 }

Expansion module (i2004 KEM)

Definition at line 524 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_firm_version

const unsigned char packet_recv_firm_version[]
static
Initial value:
=
{ 0x00, 0x00, 0x00, 0x13, 0x9a, 0x0a, 0x02 }

Definition at line 511 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_hangup

const unsigned char packet_recv_hangup[]
static
Initial value:
=
{ 0x00, 0x00, 0x00, 0x13, 0x99, 0x03, 0x03 }

Definition at line 519 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_it_type

const unsigned char packet_recv_it_type[]
static
Initial value:
=
{ 0x00, 0x00, 0x00, 0x13, 0x9a, 0x04, 0x03 }

Definition at line 513 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_mac_addr

const unsigned char packet_recv_mac_addr[]
static
Initial value:
=
{ 0xff, 0xff, 0xff, 0xff, 0x9a, 0x0d, 0x07 }

Definition at line 535 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_pick_up

const unsigned char packet_recv_pick_up[]
static
Initial value:
=
{ 0x00, 0x00, 0x00, 0x13, 0x99, 0x03, 0x04 }

Definition at line 517 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_pressed_key

const unsigned char packet_recv_pressed_key[]
static
Initial value:
=
{ 0x00, 0x00, 0x00, 0x13, 0x99, 0x04, 0x00 }

Definition at line 515 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_r2

const unsigned char packet_recv_r2[] = { 0x00, 0x00, 0x00, 0x13, 0x96, 0x03, 0x03 }
static

Definition at line 521 of file chan_unistim.c.

Referenced by process_request().

◆ packet_recv_resume_connection_with_server

const unsigned char packet_recv_resume_connection_with_server[]
static
Initial value:
=
{ 0xff, 0xff, 0xff, 0xff, 0x9e, 0x03, 0x08 }

TransportAdapter

Definition at line 533 of file chan_unistim.c.

Referenced by process_request().

◆ packet_send_arrow

const unsigned char packet_send_arrow[] = { 0x17, 0x04, 0x04, 0x00 }
static

Definition at line 633 of file chan_unistim.c.

Referenced by init_phone_step2().

◆ packet_send_blink_cursor

const unsigned char packet_send_blink_cursor[] = { 0x17, 0x04, 0x10, 0x86 }
static

Definition at line 634 of file chan_unistim.c.

Referenced by send_blink_cursor().

◆ packet_send_call

const unsigned char packet_send_call[]
static

Definition at line 558 of file chan_unistim.c.

Referenced by send_start_rtp().

◆ packet_send_charset_iso_2022_jp

const unsigned char packet_send_charset_iso_2022_jp[]
static
Initial value:
=
{ 0x17, 0x08, 0x21, 0x1b, 0x29, 0x49, 0x1b, 0x7e }

Definition at line 691 of file chan_unistim.c.

Referenced by send_charset_update().

◆ packet_send_charset_iso_8859_1

const unsigned char packet_send_charset_iso_8859_1[]
static
Initial value:
=
{ 0x17, 0x08, 0x21, 0x1b, 0x2d, 0x41, 0x1b, 0x00 }

Definition at line 679 of file chan_unistim.c.

Referenced by send_charset_update().

◆ packet_send_charset_iso_8859_2

const unsigned char packet_send_charset_iso_8859_2[]
static
Initial value:
=
{ 0x17, 0x08, 0x21, 0x1b, 0x2d, 0x42, 0x1b, 0x00 }

Definition at line 682 of file chan_unistim.c.

Referenced by send_charset_update().

◆ packet_send_charset_iso_8859_4

const unsigned char packet_send_charset_iso_8859_4[]
static
Initial value:
=
{ 0x17, 0x08, 0x21, 0x1b, 0x2d, 0x44, 0x1b, 0x00 }

Definition at line 685 of file chan_unistim.c.

Referenced by send_charset_update().

◆ packet_send_charset_iso_8859_5

const unsigned char packet_send_charset_iso_8859_5[]
static
Initial value:
=
{ 0x17, 0x08, 0x21, 0x1b, 0x2d, 0x4c, 0x1b, 0x00 }

Definition at line 688 of file chan_unistim.c.

Referenced by send_charset_update().

◆ packet_send_Contrast

const unsigned char packet_send_Contrast[]
static
Initial value:
=
{ 0x17, 0x04, 0x24, 0x08 }

Definition at line 638 of file chan_unistim.c.

Referenced by init_phone_step2().

◆ packet_send_date_time

const unsigned char packet_send_date_time[]
static

Definition at line 542 of file chan_unistim.c.

Referenced by send_date_time().

◆ packet_send_date_time2

const unsigned char packet_send_date_time2[]
static
Initial value:
= { 0x17, 0x04, 0x17, 0x3d, 0x11, 0x09, 0x02, 0x0a, 0x05,
0x06, 0x07, 0x08, 0x32
}

Definition at line 635 of file chan_unistim.c.

Referenced by send_date_time2().

◆ packet_send_date_time3

const unsigned char packet_send_date_time3[]
static
Initial value:
=
{ 0x11, 0x09, 0x02, 0x02, 0x05, 0x06, 0x07,
0x08, 0x32
}

Definition at line 538 of file chan_unistim.c.

Referenced by send_date_time3().

◆ packet_send_discovery_ack

const unsigned char packet_send_discovery_ack[]
static
Initial value:
=
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

Definition at line 508 of file chan_unistim.c.

Referenced by parsing().

◆ packet_send_end_call

const unsigned char packet_send_end_call[]
static
Initial value:
=
{ 0x16, 0x06, 0x32, 0xdf, 0x00, 0xff, 0x16, 0x05, 0x31, 0x00, 0x00, 0x16, 0x04, 0x37, 0x10 }

Definition at line 592 of file chan_unistim.c.

Referenced by send_end_call().

◆ packet_send_expansion_icon

const unsigned char packet_send_expansion_icon[] = { 0x09, 0x06, 0x59, 0x05, 0x47, 0x20 }
static

Definition at line 527 of file chan_unistim.c.

Referenced by send_expansion_icon().

◆ packet_send_expansion_next

const unsigned char packet_send_expansion_next[] = { 0x09, 0x03, 0x17 }
static

Definition at line 526 of file chan_unistim.c.

Referenced by send_expansion_next().

◆ packet_send_expansion_text

const unsigned char packet_send_expansion_text[]
static
Initial value:
= { 0x09, 0x0f, 0x57, 0x19, 0x47, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }

Definition at line 528 of file chan_unistim.c.

Referenced by send_expansion_text().

◆ packet_send_favorite

const unsigned char packet_send_favorite[]
static
Initial value:
=
{ 0x17, 0x0f, 0x19, 0x10, 0x01, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x19,
0x05, 0x0f, 0x01, 0x00
}

Definition at line 654 of file chan_unistim.c.

Referenced by send_favorite().

◆ packet_send_icon

const unsigned char packet_send_icon[] = { 0x17, 0x05, 0x14, 0x00, 0x25 }
static

Definition at line 644 of file chan_unistim.c.

Referenced by send_icon().

◆ packet_send_jitter_buffer_conf

const unsigned char packet_send_jitter_buffer_conf[]
static
Initial value:
=
{ 0x16, 0x0e, 0x3a, 0x00, 0x02, 0x04, 0x00, 0x00,
0x3e, 0x80,
0x00, 0x00, 0x3e, 0x80
}

Definition at line 599 of file chan_unistim.c.

Referenced by send_start_rtp().

◆ packet_send_led_update

const unsigned char packet_send_led_update[] = { 0x19, 0x04, 0x00, 0x00 }
static

Definition at line 694 of file chan_unistim.c.

Referenced by send_led_update().

◆ packet_send_monthlabels_download

unsigned char packet_send_monthlabels_download[]
static
Initial value:
=
{ 0x17, 0x0a, 0x15, '-', '-', '-', '-', '-', '-', 0x20 }

Definition at line 652 of file chan_unistim.c.

Referenced by send_month_labels().

◆ packet_send_mute

const unsigned char packet_send_mute[] = { 0x16, 0x05, 0x04, 0x00, 0x00 }
static

Definition at line 570 of file chan_unistim.c.

Referenced by send_mute().

◆ packet_send_no_ring

const unsigned char packet_send_no_ring[]
static
Initial value:
=
{ 0x16, 0x04, 0x1a, 0x00, 0x16, 0x04, 0x11, 0x00 }

Definition at line 549 of file chan_unistim.c.

Referenced by send_no_ring().

◆ packet_send_open_audio_stream_rx

const unsigned char packet_send_open_audio_stream_rx[]
static
Initial value:
=
{ 0x16, 0x1a, 0x30, 0x00, 0xff, 0x00, 0x00, 0x01, 0x00, 0xb8, 0xb8, 0x0e,
0x0e, 0x01, 0x14, 0x50, 0x00,
0x00, 0x14, 0x50, 0x00, 0x00, 0x0a, 0x93, 0x69, 0x05
}

Definition at line 608 of file chan_unistim.c.

Referenced by send_start_rtp().

◆ packet_send_open_audio_stream_rx3

const unsigned char packet_send_open_audio_stream_rx3[]
static

Definition at line 619 of file chan_unistim.c.

Referenced by send_start_rtp().

◆ packet_send_open_audio_stream_tx

const unsigned char packet_send_open_audio_stream_tx[]
static
Initial value:
=
{ 0x16, 0x1a, 0x30, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0xb8, 0xb8, 0x0e,
0x0e, 0x01, 0x14, 0x50,
0x00, 0x00, 0x14, 0x50, 0x00, 0x00, 0x0a, 0x93, 0x69, 0x05
}

Definition at line 613 of file chan_unistim.c.

Referenced by send_start_rtp().

◆ packet_send_open_audio_stream_tx3

const unsigned char packet_send_open_audio_stream_tx3[]
static

Definition at line 626 of file chan_unistim.c.

Referenced by send_start_rtp().

◆ packet_send_ping

unsigned char packet_send_ping[]
static
Initial value:
=
{ 0x1e, 0x05, 0x12, 0x00, 0x78 }

Definition at line 701 of file chan_unistim.c.

Referenced by reload_config(), and send_ping().

◆ packet_send_query_basic_manager_04

const unsigned char packet_send_query_basic_manager_04[] = { 0x1a, 0x04, 0x01, 0x04 }
static

Definition at line 696 of file chan_unistim.c.

Referenced by rcv_mac_addr().

◆ packet_send_query_basic_manager_10

const unsigned char packet_send_query_basic_manager_10[] = { 0x1a, 0x04, 0x01, 0x10 }
static

Definition at line 698 of file chan_unistim.c.

Referenced by rcv_mac_addr().

◆ packet_send_query_mac_address

const unsigned char packet_send_query_mac_address[] = { 0x1a, 0x04, 0x01, 0x08 }
static

Definition at line 697 of file chan_unistim.c.

Referenced by rcv_resume_connection_with_server().

◆ packet_send_ring

const unsigned char packet_send_ring[]
static
Initial value:
=
{ 0x16, 0x06, 0x32, 0xdf, 0x00, 0xff, 0x16, 0x05, 0x1c, 0x00, 0x00, 0x16,
0x04, 0x1a, 0x01, 0x16, 0x05, 0x12, 0x13 , 0x18, 0x16, 0x04, 0x18,
0x20, 0x16, 0x04, 0x10, 0x00
}

Definition at line 584 of file chan_unistim.c.

Referenced by send_ring().

◆ packet_send_rtp_packet_size

const unsigned char packet_send_rtp_packet_size[]
static
Initial value:
=
{ 0x16, 0x08, 0x38, 0x00, 0x00, 0xe0, 0x00, 0xa0 }

Definition at line 597 of file chan_unistim.c.

Referenced by send_start_rtp().

◆ packet_send_S1

const unsigned char packet_send_S1[] = { 0x1a, 0x07, 0x07, 0x00, 0x00, 0x00, 0x13 }
static

Definition at line 699 of file chan_unistim.c.

Referenced by rcv_mac_addr().

◆ packet_send_s4

const unsigned char packet_send_s4[]
static

Definition at line 551 of file chan_unistim.c.

Referenced by init_phone_step2().

◆ packet_send_S7

const unsigned char packet_send_S7[] = { 0x17, 0x06, 0x0f, 0x30, 0x07, 0x07 }
static

Definition at line 645 of file chan_unistim.c.

Referenced by init_phone_step2().

◆ packet_send_s9

const unsigned char packet_send_s9[]
static
Initial value:
=
{ 0x16, 0x06, 0x32, 0xdf, 0x00, 0xff, 0x19, 0x04, 0x00, 0x10, 0x16, 0x05, 0x1c, 0x00,
0x00 }

Definition at line 594 of file chan_unistim.c.

Referenced by init_phone_step2().

◆ packet_send_select_output

const unsigned char packet_send_select_output[]
static
Initial value:
=
{ 0x16, 0x06, 0x32, 0xc0, 0x01, 0x00 }

Definition at line 581 of file chan_unistim.c.

Referenced by send_select_output().

◆ packet_send_set_pos_cursor

const unsigned char packet_send_set_pos_cursor[]
static
Initial value:
=
{ 0x17, 0x06, 0x10, 0x81, 0x04, 0x20 }

Definition at line 646 of file chan_unistim.c.

Referenced by send_cursor_pos().

◆ packet_send_start_timer

const unsigned char packet_send_start_timer[]
static
Initial value:
=
{ 0x17, 0x05, 0x0b, 0x05, 0x00, 0x17, 0x08, 0x16,
'T', 'i', 'm', 'e', 'r' }

Definition at line 640 of file chan_unistim.c.

Referenced by send_start_timer().

◆ packet_send_status

const unsigned char packet_send_status[]
static
Initial value:
=
{ 0x17, 0x20, 0x19, 0x08, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
}

Definition at line 668 of file chan_unistim.c.

Referenced by send_text_status().

◆ packet_send_status2

const unsigned char packet_send_status2[]
static
Initial value:
=
{ 0x17, 0x0b, 0x19, 0x00, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20 }

Definition at line 673 of file chan_unistim.c.

Referenced by send_text_status().

◆ packet_send_stop_timer

const unsigned char packet_send_stop_timer[] = { 0x17, 0x05, 0x0b, 0x02, 0x00 }
static

Definition at line 643 of file chan_unistim.c.

Referenced by send_stop_timer().

◆ packet_send_stream_based_tone_dual_freq

const unsigned char packet_send_stream_based_tone_dual_freq[]
static
Initial value:
=
{ 0x16, 0x08, 0x1d, 0x00, 0x01, 0xb8, 0x01, 0x5e }

Definition at line 579 of file chan_unistim.c.

Referenced by send_tone().

◆ packet_send_stream_based_tone_off

const unsigned char packet_send_stream_based_tone_off[]
static
Initial value:
=
{ 0x16, 0x05, 0x1c, 0x00, 0x00 }

Definition at line 567 of file chan_unistim.c.

Referenced by send_tone().

◆ packet_send_stream_based_tone_on

const unsigned char packet_send_stream_based_tone_on[]
static
Initial value:
=
{ 0x16, 0x06, 0x1b, 0x00, 0x00, 0x05 }

Definition at line 575 of file chan_unistim.c.

Referenced by send_tone().

◆ packet_send_stream_based_tone_single_freq

const unsigned char packet_send_stream_based_tone_single_freq[]
static
Initial value:
=
{ 0x16, 0x06, 0x1d, 0x00, 0x01, 0xb8 }

Definition at line 577 of file chan_unistim.c.

Referenced by send_tone().

◆ packet_send_text

const unsigned char packet_send_text[]
static

Definition at line 662 of file chan_unistim.c.

Referenced by send_text().

◆ packet_send_title

const unsigned char packet_send_title[]
static
Initial value:
=
{ 0x17, 0x10, 0x19, 0x02, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20 }

Definition at line 659 of file chan_unistim.c.

Referenced by send_texttitle().

◆ public_ip

struct sockaddr_in public_ip = { 0, }
static

Definition at line 258 of file chan_unistim.c.

Referenced by get_to_address(), reload_config(), and send_start_rtp().

◆ qos

struct { ... } qos

Referenced by reload_config(), and start_rtp().

◆ sched

struct ast_sched_context* sched
static

Definition at line 257 of file chan_unistim.c.

◆ sessionlock

ast_mutex_t sessionlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

Protect the session list

Definition at line 271 of file chan_unistim.c.

Referenced by close_client(), create_client(), do_monitor(), reload_config(), unistim_show_info(), and unistimsock_read().

◆ sessions

struct unistimsession * sessions = NULL
static

◆ tdesc

const char tdesc[] = "UNISTIM Channel Driver"
static

Definition at line 706 of file chan_unistim.c.

◆ tos

unsigned int tos

Definition at line 250 of file chan_unistim.c.

◆ tos_audio

unsigned int tos_audio

Definition at line 251 of file chan_unistim.c.

◆ unistim_cli

struct ast_cli_entry unistim_cli[]
static

Definition at line 6267 of file chan_unistim.c.

◆ unistim_keepalive

int unistim_keepalive
static

Definition at line 246 of file chan_unistim.c.

Referenced by create_client(), reload_config(), and send_ping().

◆ unistim_port

int unistim_port
static

Definition at line 244 of file chan_unistim.c.

Referenced by reload_config().

◆ unistim_reload_lock

ast_mutex_t unistim_reload_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

Definition at line 261 of file chan_unistim.c.

Referenced by do_monitor(), and reload().

◆ unistim_reloading

int unistim_reloading = 0
static

Receive buffer address

Definition at line 260 of file chan_unistim.c.

Referenced by do_monitor(), and reload().

◆ unistim_rtp_glue

struct ast_rtp_glue unistim_rtp_glue
static
Initial value:
= {
.type = channel_type,
.get_rtp_info = unistim_get_rtp_peer,
.update_peer = unistim_set_rtp_peer,
}
static const char channel_type[]
Definition: chan_unistim.c:707
static int unistim_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *codecs, int nat_active)
static enum ast_rtp_glue_result unistim_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)

Definition at line 7075 of file chan_unistim.c.

◆ unistim_tech

struct ast_channel_tech unistim_tech
static

Definition at line 736 of file chan_unistim.c.

◆ unistimdebug

int unistimdebug = 0
static

◆ unistimsock

int unistimsock = -1
static

◆ ustm_strcopy

char ustm_strcopy[1024]
static

Definition at line 779 of file chan_unistim.c.

Referenced by ustmtext().