Sun Dec 18 20:55:48 2011

Asterisk developer's documentation


chan_skinny.c File Reference

Implementation of the Skinny protocol. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/signal.h>
#include <signal.h>
#include <ctype.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/say.h"
#include "asterisk/cdr.h"
#include "asterisk/astdb.h"
#include "asterisk/features.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/utils.h"
#include "asterisk/dsp.h"
#include "asterisk/stringfields.h"
#include "asterisk/astobj.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/threadstorage.h"

Include dependency graph for chan_skinny.c:

Go to the source code of this file.

Data Structures

struct  activate_call_plane_message
struct  alarm_message
struct  button_definition
struct  button_definition_template
struct  button_template_res_message
struct  call_info_message
struct  call_state_message
struct  capabilities_res_message
struct  clear_prompt_message
struct  close_receive_channel_message
struct  definetimedate_message
struct  dialed_number_message
struct  display_notify_message
struct  display_prompt_status_message
struct  displaytext_message
struct  enbloc_call_message
struct  keypad_button_message
struct  line_stat_res_message
struct  line_state_req_message
struct  media_qualifier
struct  offhook_message
struct  onhook_message
struct  open_receive_channel_ack_message
struct  open_receive_channel_message
struct  register_ack_message
struct  register_message
struct  register_rej_message
struct  reset_message
struct  select_soft_keys_message
struct  server_identifier
struct  server_res_message
struct  set_lamp_message
struct  set_microphone_message
struct  set_ringer_message
struct  set_speaker_message
struct  skinny_addon
union  skinny_data
struct  skinny_device
struct  skinny_line
struct  skinny_paging_device
struct  skinny_req
struct  skinny_speeddial
struct  skinny_subchannel
struct  skinnysession
struct  soft_key_definitions
struct  soft_key_event_message
struct  soft_key_set_definition
struct  soft_key_set_res_message
struct  soft_key_template_definition
struct  soft_key_template_res_message
struct  speed_dial_stat_req_message
struct  speed_dial_stat_res_message
struct  start_media_transmission_message
struct  start_tone_message
struct  station_capabilities
struct  stimulus_message
struct  stop_media_transmission_message
struct  stop_tone_message
struct  version_res_message

Defines

#define ACTIVATE_CALL_PLANE_MESSAGE   0x0116
#define ALARM_MESSAGE   0x0020
#define BT_AUTOANSWER   STIMULUS_AUTOANSWER
#define BT_CALLPARK   STIMULUS_CALLPARK
#define BT_CALLPICKUP   STIMULUS_CALLPICKUP
#define BT_CONFERENCE   STIMULUS_CONFERENCE
#define BT_CUST_HINT   0xB1
#define BT_CUST_LINESPEEDDIAL   0xB0
#define BT_DISPLAY   STIMULUS_DISPLAY
#define BT_FORWARDALL   STIMULUS_FORWARDALL
#define BT_FORWARDBUSY   STIMULUS_FORWARDBUSY
#define BT_FORWARDNOANSWER   STIMULUS_FORWARDNOANSWER
#define BT_HOLD   STIMULUS_HOLD
#define BT_LINE   STIMULUS_LINE
#define BT_NONE   0x00
#define BT_REDIAL   STIMULUS_REDIAL
#define BT_SPEEDDIAL   STIMULUS_SPEEDDIAL
#define BT_TRANSFER   STIMULUS_TRANSFER
#define BT_VOICEMAIL   STIMULUS_VOICEMAIL
#define BUTTON_TEMPLATE_REQ_MESSAGE   0x000E
#define BUTTON_TEMPLATE_RES_MESSAGE   0x0097
#define CALL_INFO_MESSAGE   0x008F
#define CALL_STATE_MESSAGE   0x0111
#define CAPABILITIES_REQ_MESSAGE   0x009B
#define CAPABILITIES_RES_MESSAGE   0x0010
#define CLEAR_DISPLAY_MESSAGE   0x009A
#define CLEAR_NOTIFY_MESSAGE   0x0115
#define CLEAR_PROMPT_MESSAGE   0x0113
#define CLOSE_RECEIVE_CHANNEL_MESSAGE   0x0106
#define CONTROL2STR_BUFSIZE   100
#define DEFAULT_AUTH_LIMIT   50
#define DEFAULT_AUTH_TIMEOUT   30
#define DEFAULT_SKINNY_BACKLOG   2
#define DEFAULT_SKINNY_PORT   2000
#define DEFINETIMEDATE_MESSAGE   0x0094
#define DEVICE2STR_BUFSIZE   15
#define DIALED_NUMBER_MESSAGE   0x011D
#define DISPLAY_NOTIFY_MESSAGE   0x0114
#define DISPLAY_PROMPT_STATUS_MESSAGE   0x0112
#define DISPLAYTEXT_MESSAGE   0x0099
#define ENBLOC_CALL_MESSAGE   0x0004
#define HEADSET_STATUS_MESSAGE   0x002B
#define htolel(x)   (x)
#define htoles(x)   (x)
#define IP_PORT_MESSAGE   0x0002
#define KEEP_ALIVE_ACK_MESSAGE   0x0100
#define KEEP_ALIVE_MESSAGE   0x0000
#define KEYDEF_CONNECTED   1
#define KEYDEF_CONNWITHCONF   7
#define KEYDEF_CONNWITHTRANS   5
#define KEYDEF_DADFD   6
#define KEYDEF_OFFHOOK   4
#define KEYDEF_OFFHOOKWITHFEAT   9
#define KEYDEF_ONHOLD   2
#define KEYDEF_ONHOOK   0
#define KEYDEF_RINGIN   3
#define KEYDEF_RINGOUT   8
#define KEYDEF_UNKNOWN   10
#define KEYPAD_BUTTON_MESSAGE   0x0003
#define letohl(x)   (x)
#define letohs(x)   (x)
#define LINE_STAT_RES_MESSAGE   0x0092
#define LINE_STATE_REQ_MESSAGE   0x000B
#define OFFHOOK_MESSAGE   0x0006
#define ONHOOK_MESSAGE   0x0007
#define OPEN_RECEIVE_CHANNEL_ACK_MESSAGE   0x0022
#define OPEN_RECEIVE_CHANNEL_MESSAGE   0x0105
#define REGISTER_ACK_MESSAGE   0x0081
#define REGISTER_AVAILABLE_LINES_MESSAGE   0x002D
#define REGISTER_MESSAGE   0x0001
#define REGISTER_REJ_MESSAGE   0x009D
#define RESET_MESSAGE   0x009F
#define SELECT_SOFT_KEYS_MESSAGE   0x0110
#define SERVER_REQUEST_MESSAGE   0x0012
#define SERVER_RES_MESSAGE   0x009E
#define SET_LAMP_MESSAGE   0x0086
#define SET_MICROPHONE_MESSAGE   0x0089
#define SET_RINGER_MESSAGE   0x0085
#define SET_SPEAKER_MESSAGE   0x0088
#define SKINNY_ALERT   0x24
#define SKINNY_BUSY   6
#define SKINNY_BUSYTONE   0x23
#define SKINNY_CALLWAIT   9
#define SKINNY_CALLWAITTONE   0x2D
#define SKINNY_CONGESTION   7
#define SKINNY_CONNECTED   5
#define SKINNY_CX_CONF   3
#define SKINNY_CX_CONFERENCE   3
#define SKINNY_CX_INACTIVE   4
#define SKINNY_CX_MUTE   4
#define SKINNY_CX_RECVONLY   1
#define SKINNY_CX_SENDONLY   0
#define SKINNY_CX_SENDRECV   2
#define SKINNY_DEVICE_12   4
#define SKINNY_DEVICE_12SP   3
#define SKINNY_DEVICE_12SPPLUS   2
#define SKINNY_DEVICE_30SPPLUS   1
#define SKINNY_DEVICE_30VIP   5
#define SKINNY_DEVICE_7902   30008
#define SKINNY_DEVICE_7905   20000
#define SKINNY_DEVICE_7906   369
#define SKINNY_DEVICE_7910   6
#define SKINNY_DEVICE_7911   307
#define SKINNY_DEVICE_7912   30007
#define SKINNY_DEVICE_7914   124
#define SKINNY_DEVICE_7920   30002
#define SKINNY_DEVICE_7921   365
#define SKINNY_DEVICE_7931   348
#define SKINNY_DEVICE_7935   9
#define SKINNY_DEVICE_7936   30019
#define SKINNY_DEVICE_7937   431
#define SKINNY_DEVICE_7940   8
#define SKINNY_DEVICE_7941   115
#define SKINNY_DEVICE_7941GE   309
#define SKINNY_DEVICE_7942   434
#define SKINNY_DEVICE_7945   435
#define SKINNY_DEVICE_7960   7
#define SKINNY_DEVICE_7961   30018
#define SKINNY_DEVICE_7961GE   308
#define SKINNY_DEVICE_7962   404
#define SKINNY_DEVICE_7965   436
#define SKINNY_DEVICE_7970   30006
#define SKINNY_DEVICE_7971   119
#define SKINNY_DEVICE_7975   437
#define SKINNY_DEVICE_7985   302
#define SKINNY_DEVICE_ATA186   12
#define SKINNY_DEVICE_CIPC   30016
#define SKINNY_DEVICE_NONE   0
#define SKINNY_DEVICE_SCCPGATEWAY_AN   30027
#define SKINNY_DEVICE_SCCPGATEWAY_BRI   30028
#define SKINNY_DEVICE_UNKNOWN   -1
#define SKINNY_DIALTONE   0x21
#define SKINNY_HOLD   8
#define SKINNY_INVALID   14
#define SKINNY_LAMP_BLINK   5
#define SKINNY_LAMP_FLASH   4
#define SKINNY_LAMP_OFF   1
#define SKINNY_LAMP_ON   2
#define SKINNY_LAMP_WINK   3
#define SKINNY_MAX_CAPABILITIES   18
#define SKINNY_MAX_PACKET   1000
#define SKINNY_MICOFF   2
#define SKINNY_MICON   1
#define SKINNY_NOTONE   0x7F
#define SKINNY_OFFHOOK   1
#define SKINNY_ONHOOK   2
#define SKINNY_PARK   11
#define SKINNY_PROGRESS   12
#define SKINNY_REORDER   0x25
#define SKINNY_RING_FEATURE   4
#define SKINNY_RING_INSIDE   2
#define SKINNY_RING_OFF   1
#define SKINNY_RING_OUTSIDE   3
#define SKINNY_RINGIN   4
#define SKINNY_RINGOUT   3
#define SKINNY_SILENCE   0x00
#define SKINNY_SPEAKEROFF   2
#define SKINNY_SPEAKERON   1
#define SKINNY_TRANSFER   10
#define SOFT_KEY_EVENT_MESSAGE   0x0026
#define SOFT_KEY_SET_REQ_MESSAGE   0x0025
#define SOFT_KEY_SET_RES_MESSAGE   0x0109
#define SOFT_KEY_TEMPLATE_REQ_MESSAGE   0x0028
#define SOFT_KEY_TEMPLATE_RES_MESSAGE   0x0108
#define SOFTKEY_ANSWER   0x0B
#define SOFTKEY_BKSPC   0x08
#define SOFTKEY_CFWDALL   0x05
#define SOFTKEY_CFWDBUSY   0x06
#define SOFTKEY_CFWDNOANSWER   0x07
#define SOFTKEY_CONFRN   0x0D
#define SOFTKEY_ENDCALL   0x09
#define SOFTKEY_GPICKUP   0x12
#define SOFTKEY_HOLD   0x03
#define SOFTKEY_INFO   0x0C
#define SOFTKEY_JOIN   0x0F
#define SOFTKEY_MEETME   0x10
#define SOFTKEY_NEWCALL   0x02
#define SOFTKEY_NONE   0x00
#define SOFTKEY_PARK   0x0E
#define SOFTKEY_PICKUP   0x11
#define SOFTKEY_REDIAL   0x01
#define SOFTKEY_RESUME   0x0A
#define SOFTKEY_TRNSFER   0x04
#define SPEED_DIAL_STAT_REQ_MESSAGE   0x000A
#define SPEED_DIAL_STAT_RES_MESSAGE   0x0091
#define START_MEDIA_TRANSMISSION_MESSAGE   0x008A
#define START_TONE_MESSAGE   0x0082
#define STIMULUS_AUTOANSWER   0x11
#define STIMULUS_CALLPARK   0x7E
#define STIMULUS_CALLPICKUP   0x7F
#define STIMULUS_CONFERENCE   0x7D
#define STIMULUS_DISPLAY   0x08
#define STIMULUS_FORWARDALL   0x05
#define STIMULUS_FORWARDBUSY   0x06
#define STIMULUS_FORWARDNOANSWER   0x07
#define STIMULUS_HOLD   0x03
#define STIMULUS_LINE   0x09
#define STIMULUS_MESSAGE   0x0005
#define STIMULUS_NONE   0xFF
#define STIMULUS_REDIAL   0x01
#define STIMULUS_SPEEDDIAL   0x02
#define STIMULUS_TRANSFER   0x04
#define STIMULUS_VOICEMAIL   0x0F
#define STOP_MEDIA_TRANSMISSION_MESSAGE   0x008B
#define STOP_TONE_MESSAGE   0x0083
#define TIME_DATE_REQ_MESSAGE   0x000D
#define TYPE_LINE   2
#define TYPE_TRUNK   1
#define UNREGISTER_MESSAGE   0x0027
#define VERSION_REQ_MESSAGE   0x000F
#define VERSION_RES_MESSAGE   0x0098

Enumerations

enum  skinny_codecs {
  SKINNY_CODEC_ALAW = 2, SKINNY_CODEC_ULAW = 4, SKINNY_CODEC_G723_1 = 9, SKINNY_CODEC_G729A = 12,
  SKINNY_CODEC_G726_32 = 82, SKINNY_CODEC_H261 = 100, SKINNY_CODEC_H263 = 101
}

Functions

static void * accept_thread (void *ignore)
 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"Skinny Client Control Protocol (Skinny)",.load=load_module,.unload=unload_module,)
 AST_MUTEX_DEFINE_STATIC (devicelock)
 AST_MUTEX_DEFINE_STATIC (sessionlock)
 AST_MUTEX_DEFINE_STATIC (netlock)
 AST_MUTEX_DEFINE_STATIC (monlock)
 AST_THREADSTORAGE (control2str_threadbuf, control2str_threadbuf_init)
 AST_THREADSTORAGE (device2str_threadbuf, device2str_threadbuf_init)
static struct skinny_devicebuild_device (const char *cat, struct ast_variable *v)
static int codec_ast2skinny (int astcodec)
static int codec_skinny2ast (enum skinny_codecs skinnycodec)
static char * complete_skinny_reset (const char *line, const char *word, int pos, int state)
static char * control2str (int ind)
static void delete_devices (void)
static void destroy_session (struct skinnysession *s)
static char * device2str (int type)
static void do_housekeeping (struct skinnysession *s)
static void * do_monitor (void *data)
static struct skinny_linefind_line_by_instance (struct skinny_device *d, int instance)
static struct skinny_linefind_line_by_name (const char *dest)
static struct skinny_speeddialfind_speeddial_by_instance (struct skinny_device *d, int instance)
static struct skinny_subchannelfind_subchannel_by_instance_reference (struct skinny_device *d, int instance, int reference)
static struct skinny_subchannelfind_subchannel_by_reference (struct skinny_device *d, int reference)
static void * get_button_template (struct skinnysession *s, struct button_definition_template *btn)
static int get_input (struct skinnysession *s)
static int handle_alarm_message (struct skinny_req *req, struct skinnysession *s)
static int handle_button_template_req_message (struct skinny_req *req, struct skinnysession *s)
static int handle_capabilities_res_message (struct skinny_req *req, struct skinnysession *s)
static int handle_enbloc_call_message (struct skinny_req *req, struct skinnysession *s)
static int handle_headset_status_message (struct skinny_req *req, struct skinnysession *s)
static int handle_ip_port_message (struct skinny_req *req, struct skinnysession *s)
static int handle_keep_alive_message (struct skinny_req *req, struct skinnysession *s)
static int handle_keypad_button_message (struct skinny_req *req, struct skinnysession *s)
static int handle_line_state_req_message (struct skinny_req *req, struct skinnysession *s)
static int handle_message (struct skinny_req *req, struct skinnysession *s)
static int handle_offhook_message (struct skinny_req *req, struct skinnysession *s)
static int handle_onhook_message (struct skinny_req *req, struct skinnysession *s)
static int handle_open_receive_channel_ack_message (struct skinny_req *req, struct skinnysession *s)
static int handle_register_available_lines_message (struct skinny_req *req, struct skinnysession *s)
static int handle_register_message (struct skinny_req *req, struct skinnysession *s)
static int handle_server_request_message (struct skinny_req *req, struct skinnysession *s)
static int handle_soft_key_event_message (struct skinny_req *req, struct skinnysession *s)
static int handle_soft_key_set_req_message (struct skinny_req *req, struct skinnysession *s)
static int handle_soft_key_template_req_message (struct skinny_req *req, struct skinnysession *s)
static int handle_speed_dial_stat_req_message (struct skinny_req *req, struct skinnysession *s)
static int handle_stimulus_message (struct skinny_req *req, struct skinnysession *s)
static int handle_time_date_req_message (struct skinny_req *req, struct skinnysession *s)
static int handle_unregister_message (struct skinny_req *req, struct skinnysession *s)
static int handle_version_req_message (struct skinny_req *req, struct skinnysession *s)
static int load_module (void)
static int reload_config (void)
static struct skinny_reqreq_alloc (size_t size, int response_message)
static int restart_monitor (void)
static int skinny_answer (struct ast_channel *ast)
static int skinny_call (struct ast_channel *ast, char *dest, int timeout)
static int skinny_do_debug (int fd, int argc, char *argv[])
static int skinny_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
static enum ast_rtp_get_result skinny_get_rtp_peer (struct ast_channel *c, struct ast_rtp **rtp)
static enum ast_rtp_get_result skinny_get_vrtp_peer (struct ast_channel *c, struct ast_rtp **rtp)
static int skinny_hangup (struct ast_channel *ast)
static int skinny_hold (struct skinny_subchannel *sub)
static int skinny_indicate (struct ast_channel *ast, int ind, const void *data, size_t datalen)
static struct ast_channelskinny_new (struct skinny_line *l, int state)
static void * skinny_newcall (void *data)
static int skinny_no_debug (int fd, int argc, char *argv[])
static struct ast_frameskinny_read (struct ast_channel *ast)
static int skinny_register (struct skinny_req *req, struct skinnysession *s)
static struct skinny_reqskinny_req_parse (struct skinnysession *s)
static struct ast_channelskinny_request (const char *type, int format, void *data, int *cause)
static int skinny_reset_device (int fd, int argc, char *argv[])
static struct ast_frameskinny_rtp_read (struct skinny_subchannel *sub)
static int skinny_senddigit_begin (struct ast_channel *ast, char digit)
static int skinny_senddigit_end (struct ast_channel *ast, char digit, unsigned int duration)
static void * skinny_session (void *data)
static int skinny_set_rtp_peer (struct ast_channel *c, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active)
static int skinny_show_devices (int fd, int argc, char *argv[])
static int skinny_show_lines (int fd, int argc, char *argv[])
static void * skinny_ss (void *data)
static int skinny_unhold (struct skinny_subchannel *sub)
static int skinny_unregister (struct skinny_req *req, struct skinnysession *s)
static int skinny_write (struct ast_channel *ast, struct ast_frame *frame)
static void start_rtp (struct skinny_subchannel *sub)
static void transmit_callinfo (struct skinnysession *s, const char *fromname, const char *fromnum, const char *toname, const char *tonum, int instance, int callid, int calltype)
static void transmit_callstate (struct skinnysession *s, int instance, int state, unsigned callid)
static void transmit_connect (struct skinnysession *s, struct skinny_subchannel *sub)
static void transmit_dialednumber (struct skinnysession *s, const char *text, int instance, int callid)
static void transmit_displaymessage (struct skinnysession *s, const char *text, int instance, int reference)
static void transmit_displaynotify (struct skinnysession *s, const char *text, int t)
static void transmit_displaypromptstatus (struct skinnysession *s, const char *text, int t, int instance, int callid)
static void transmit_lamp_indication (struct skinnysession *s, int stimulus, int instance, int indication)
static int transmit_response (struct skinnysession *s, struct skinny_req *req)
static void transmit_ringer_mode (struct skinnysession *s, int mode)
static void transmit_selectsoftkeys (struct skinnysession *s, int instance, int callid, int softkey)
static void transmit_speaker_mode (struct skinnysession *s, int mode)
static void transmit_tone (struct skinnysession *s, int tone, int instance, int reference)
static int unload_module (void)

Variables

static struct in_addr __ourip
static pthread_t accept_t
static char accountcode [AST_MAX_ACCOUNT_CODE] = ""
struct ast_hostent ahp
static int amaflags = 0
static int auth_limit = DEFAULT_AUTH_LIMIT
static int auth_timeout = DEFAULT_AUTH_TIMEOUT
static struct sockaddr_in bindaddr
static int callnums = 1
static int callreturn = 0
static int callwaiting = 0
static int cancallforward = 0
static char cid_name [AST_MAX_EXTENSION] = ""
static char cid_num [AST_MAX_EXTENSION] = ""
static struct ast_cli_entry cli_skinny []
static const char config [] = "skinny.conf"
static char context [AST_MAX_CONTEXT] = "default"
static ast_group_t cur_callergroup = 0
static ast_group_t cur_pickupgroup = 0
static char date_format [6] = "D-M-Y"
static char debug_usage []
static int default_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW
static struct ast_jb_conf default_jbconf
static struct ast_codec_pref default_prefs
static struct skinny_devicedevices
static int firstdigittimeout = 16000
static int gendigittimeout = 8000
static struct ast_jb_conf global_jbconf
struct hostent * hp
static int immediate = 0
static struct io_contextio
static int keep_alive = 120
static char language [MAX_LANGUAGE] = ""
static char linelabel [AST_MAX_EXTENSION] = ""
static char mailbox [AST_MAX_EXTENSION]
static int matchdigittimeout = 3000
static char mohinterpret [MAX_MUSICCLASS] = "default"
static char mohsuggest [MAX_MUSICCLASS] = ""
static pthread_t monitor_thread = AST_PTHREADT_NULL
static int mwiblink = 0
static int nat = 0
static char no_debug_usage []
static char ourhost [256]
static int ourport
static char reset_usage []
static struct sched_contextsched = NULL
static struct skinnysessionsessions
static char show_devices_usage []
static char show_lines_usage []
int skinny_header_size = 12
static struct ast_rtp_protocol skinny_rtp
static struct ast_channel_tech skinny_tech
static int skinnydebug = 0
static int skinnysock = -1
static const uint8_t soft_key_default_connected []
static const uint8_t soft_key_default_connwithconf []
static const uint8_t soft_key_default_connwithtrans []
static const uint8_t soft_key_default_dadfd []
static struct soft_key_definitions soft_key_default_definitions []
static const uint8_t soft_key_default_offhook []
static const uint8_t soft_key_default_offhookwithfeat []
static const uint8_t soft_key_default_onhold []
static const uint8_t soft_key_default_onhook []
static const uint8_t soft_key_default_ringin []
static const uint8_t soft_key_default_ringout []
static const uint8_t soft_key_default_unknown []
struct soft_key_template_definition soft_key_template_default []
static const char tdesc [] = "Skinny Client Control Protocol (Skinny)"
static int threewaycalling = 0
static int transfer = 0
static int unauth_sessions = 0
static char version_id [16] = "P002F202"


Detailed Description

Implementation of the Skinny protocol.

Author:
Jeremy McNamara & Florian Overkamp & North Antara

Definition in file chan_skinny.c.


Define Documentation

#define ACTIVATE_CALL_PLANE_MESSAGE   0x0116

Definition at line 710 of file chan_skinny.c.

Referenced by skinny_hold(), skinny_unhold(), and transmit_callstate().

#define ALARM_MESSAGE   0x0020

Definition at line 232 of file chan_skinny.c.

Referenced by handle_message().

#define BT_AUTOANSWER   STIMULUS_AUTOANSWER

Definition at line 426 of file chan_skinny.c.

#define BT_CALLPARK   STIMULUS_CALLPARK

Definition at line 428 of file chan_skinny.c.

Referenced by get_button_template().

#define BT_CALLPICKUP   STIMULUS_CALLPICKUP

Definition at line 429 of file chan_skinny.c.

#define BT_CONFERENCE   STIMULUS_CONFERENCE

Definition at line 427 of file chan_skinny.c.

Referenced by get_button_template().

#define BT_CUST_HINT   0xB1

Definition at line 436 of file chan_skinny.c.

Referenced by handle_button_template_req_message().

#define BT_CUST_LINESPEEDDIAL   0xB0

Definition at line 435 of file chan_skinny.c.

Referenced by get_button_template(), and handle_button_template_req_message().

#define BT_DISPLAY   STIMULUS_DISPLAY

Definition at line 423 of file chan_skinny.c.

Referenced by get_button_template().

#define BT_FORWARDALL   STIMULUS_FORWARDALL

Definition at line 420 of file chan_skinny.c.

Referenced by get_button_template().

#define BT_FORWARDBUSY   STIMULUS_FORWARDBUSY

Definition at line 421 of file chan_skinny.c.

#define BT_FORWARDNOANSWER   STIMULUS_FORWARDNOANSWER

Definition at line 422 of file chan_skinny.c.

#define BT_HOLD   STIMULUS_HOLD

Definition at line 418 of file chan_skinny.c.

Referenced by get_button_template().

#define BT_LINE   STIMULUS_LINE

Definition at line 424 of file chan_skinny.c.

Referenced by get_button_template(), and handle_button_template_req_message().

#define BT_NONE   0x00

Definition at line 430 of file chan_skinny.c.

Referenced by get_button_template(), and handle_button_template_req_message().

#define BT_REDIAL   STIMULUS_REDIAL

Definition at line 416 of file chan_skinny.c.

Referenced by get_button_template().

#define BT_SPEEDDIAL   STIMULUS_SPEEDDIAL

Definition at line 417 of file chan_skinny.c.

Referenced by get_button_template(), and handle_button_template_req_message().

#define BT_TRANSFER   STIMULUS_TRANSFER

Definition at line 419 of file chan_skinny.c.

Referenced by get_button_template().

#define BT_VOICEMAIL   STIMULUS_VOICEMAIL

Definition at line 425 of file chan_skinny.c.

Referenced by get_button_template().

#define BUTTON_TEMPLATE_REQ_MESSAGE   0x000E

Definition at line 228 of file chan_skinny.c.

Referenced by handle_message().

#define BUTTON_TEMPLATE_RES_MESSAGE   0x0097

Definition at line 387 of file chan_skinny.c.

Referenced by handle_button_template_req_message().

#define CALL_INFO_MESSAGE   0x008F

Definition at line 337 of file chan_skinny.c.

Referenced by transmit_callinfo().

#define CALL_STATE_MESSAGE   0x0111

Definition at line 682 of file chan_skinny.c.

Referenced by transmit_callstate().

#define CAPABILITIES_REQ_MESSAGE   0x009B

Definition at line 458 of file chan_skinny.c.

Referenced by handle_register_message().

#define CAPABILITIES_RES_MESSAGE   0x0010

Definition at line 200 of file chan_skinny.c.

Referenced by handle_message().

#define CLEAR_DISPLAY_MESSAGE   0x009A

Definition at line 456 of file chan_skinny.c.

Referenced by transmit_displaymessage().

#define CLEAR_NOTIFY_MESSAGE   0x0115

Definition at line 455 of file chan_skinny.c.

#define CLEAR_PROMPT_MESSAGE   0x0113

Definition at line 698 of file chan_skinny.c.

Referenced by transmit_displaypromptstatus().

#define CLOSE_RECEIVE_CHANNEL_MESSAGE   0x0106

Definition at line 494 of file chan_skinny.c.

Referenced by skinny_hold(), and transmit_callstate().

#define CONTROL2STR_BUFSIZE   100

Definition at line 147 of file chan_skinny.c.

Referenced by control2str().

#define DEFAULT_AUTH_LIMIT   50

Definition at line 100 of file chan_skinny.c.

Referenced by reload_config().

#define DEFAULT_AUTH_TIMEOUT   30

Definition at line 99 of file chan_skinny.c.

Referenced by reload_config().

#define DEFAULT_SKINNY_BACKLOG   2

Definition at line 97 of file chan_skinny.c.

Referenced by reload_config().

#define DEFAULT_SKINNY_PORT   2000

Definition at line 96 of file chan_skinny.c.

Referenced by build_device(), and reload_config().

#define DEFINETIMEDATE_MESSAGE   0x0094

Definition at line 374 of file chan_skinny.c.

Referenced by handle_time_date_req_message().

#define DEVICE2STR_BUFSIZE   15

Definition at line 144 of file chan_skinny.c.

Referenced by device2str().

#define DIALED_NUMBER_MESSAGE   0x011D

Definition at line 715 of file chan_skinny.c.

Referenced by transmit_dialednumber().

#define DISPLAY_NOTIFY_MESSAGE   0x0114

Definition at line 704 of file chan_skinny.c.

Referenced by transmit_displaynotify().

#define DISPLAY_PROMPT_STATUS_MESSAGE   0x0112

Definition at line 690 of file chan_skinny.c.

Referenced by transmit_displaypromptstatus().

#define DISPLAYTEXT_MESSAGE   0x0099

Definition at line 450 of file chan_skinny.c.

Referenced by transmit_displaymessage().

#define ENBLOC_CALL_MESSAGE   0x0004

Definition at line 176 of file chan_skinny.c.

Referenced by handle_message().

#define HEADSET_STATUS_MESSAGE   0x002B

Definition at line 259 of file chan_skinny.c.

Referenced by handle_message().

#define htolel (  )     (x)

#define htoles (  )     (x)

Definition at line 113 of file chan_skinny.c.

#define IP_PORT_MESSAGE   0x0002

Definition at line 166 of file chan_skinny.c.

Referenced by handle_message().

#define KEEP_ALIVE_ACK_MESSAGE   0x0100

Definition at line 481 of file chan_skinny.c.

Referenced by handle_keep_alive_message().

#define KEEP_ALIVE_MESSAGE   0x0000

Definition at line 153 of file chan_skinny.c.

Referenced by handle_message().

#define KEYDEF_CONNECTED   1

#define KEYDEF_CONNWITHCONF   7

Definition at line 515 of file chan_skinny.c.

#define KEYDEF_CONNWITHTRANS   5

Definition at line 513 of file chan_skinny.c.

#define KEYDEF_DADFD   6

Definition at line 514 of file chan_skinny.c.

#define KEYDEF_OFFHOOK   4

#define KEYDEF_OFFHOOKWITHFEAT   9

Definition at line 517 of file chan_skinny.c.

#define KEYDEF_ONHOLD   2

Definition at line 510 of file chan_skinny.c.

#define KEYDEF_ONHOOK   0

Definition at line 508 of file chan_skinny.c.

Referenced by handle_soft_key_set_req_message(), and transmit_callstate().

#define KEYDEF_RINGIN   3

Definition at line 511 of file chan_skinny.c.

Referenced by skinny_call().

#define KEYDEF_RINGOUT   8

Definition at line 516 of file chan_skinny.c.

Referenced by handle_soft_key_event_message(), and handle_stimulus_message().

#define KEYDEF_UNKNOWN   10

Definition at line 518 of file chan_skinny.c.

#define KEYPAD_BUTTON_MESSAGE   0x0003

Definition at line 168 of file chan_skinny.c.

Referenced by handle_message().

#define letohl (  )     (x)

#define letohs (  )     (x)

Definition at line 111 of file chan_skinny.c.

#define LINE_STAT_RES_MESSAGE   0x0092

Definition at line 366 of file chan_skinny.c.

Referenced by handle_line_state_req_message().

#define LINE_STATE_REQ_MESSAGE   0x000B

Definition at line 222 of file chan_skinny.c.

Referenced by handle_message().

#define OFFHOOK_MESSAGE   0x0006

Definition at line 188 of file chan_skinny.c.

Referenced by handle_message().

#define ONHOOK_MESSAGE   0x0007

Definition at line 194 of file chan_skinny.c.

Referenced by handle_message().

#define OPEN_RECEIVE_CHANNEL_ACK_MESSAGE   0x0022

Definition at line 240 of file chan_skinny.c.

Referenced by handle_message().

#define OPEN_RECEIVE_CHANNEL_MESSAGE   0x0105

Definition at line 483 of file chan_skinny.c.

Referenced by transmit_connect().

#define REGISTER_ACK_MESSAGE   0x0081

Definition at line 262 of file chan_skinny.c.

Referenced by handle_register_message().

#define REGISTER_AVAILABLE_LINES_MESSAGE   0x002D

Definition at line 260 of file chan_skinny.c.

Referenced by handle_message().

#define REGISTER_MESSAGE   0x0001

Definition at line 156 of file chan_skinny.c.

Referenced by handle_message().

#define REGISTER_REJ_MESSAGE   0x009D

Definition at line 460 of file chan_skinny.c.

Referenced by handle_register_message().

#define RESET_MESSAGE   0x009F

Definition at line 476 of file chan_skinny.c.

Referenced by skinny_reset_device().

#define SELECT_SOFT_KEYS_MESSAGE   0x0110

Definition at line 674 of file chan_skinny.c.

Referenced by transmit_selectsoftkeys().

#define SERVER_REQUEST_MESSAGE   0x0012

Definition at line 230 of file chan_skinny.c.

Referenced by handle_message().

#define SERVER_RES_MESSAGE   0x009E

Definition at line 465 of file chan_skinny.c.

Referenced by handle_server_request_message().

#define SET_LAMP_MESSAGE   0x0086

Definition at line 293 of file chan_skinny.c.

Referenced by transmit_lamp_indication().

#define SET_MICROPHONE_MESSAGE   0x0089

Definition at line 306 of file chan_skinny.c.

#define SET_RINGER_MESSAGE   0x0085

Definition at line 285 of file chan_skinny.c.

Referenced by transmit_ringer_mode().

#define SET_SPEAKER_MESSAGE   0x0088

Definition at line 300 of file chan_skinny.c.

Referenced by transmit_speaker_mode().

#define SKINNY_ALERT   0x24

Definition at line 881 of file chan_skinny.c.

Referenced by skinny_call(), and skinny_indicate().

#define SKINNY_BUSY   6

Definition at line 869 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_BUSYTONE   0x23

Definition at line 880 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_CALLWAIT   9

Definition at line 872 of file chan_skinny.c.

#define SKINNY_CALLWAITTONE   0x2D

Definition at line 883 of file chan_skinny.c.

Referenced by skinny_call().

#define SKINNY_CONGESTION   7

Definition at line 870 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_CONNECTED   5

#define SKINNY_CX_CONF   3

Definition at line 904 of file chan_skinny.c.

#define SKINNY_CX_CONFERENCE   3

Definition at line 905 of file chan_skinny.c.

#define SKINNY_CX_INACTIVE   4

Definition at line 907 of file chan_skinny.c.

Referenced by skinny_new().

#define SKINNY_CX_MUTE   4

Definition at line 906 of file chan_skinny.c.

#define SKINNY_CX_RECVONLY   1

Definition at line 902 of file chan_skinny.c.

Referenced by handle_onhook_message(), and handle_soft_key_event_message().

#define SKINNY_CX_SENDONLY   0

Definition at line 901 of file chan_skinny.c.

#define SKINNY_CX_SENDRECV   2

Definition at line 903 of file chan_skinny.c.

Referenced by skinny_answer().

#define SKINNY_DEVICE_12   4

Definition at line 824 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_12SP   3

Definition at line 823 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_12SPPLUS   2

Definition at line 822 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_30SPPLUS   1

Definition at line 821 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_30VIP   5

Definition at line 825 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7902   30008

Definition at line 851 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7905   20000

Definition at line 847 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7906   369

Definition at line 840 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7910   6

Definition at line 826 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7911   307

Definition at line 835 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7912   30007

Definition at line 850 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7914   124

Definition at line 833 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7920   30002

Definition at line 848 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7921   365

Definition at line 839 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7931   348

Definition at line 838 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7935   9

Definition at line 829 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7936   30019

Definition at line 854 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7937   431

Definition at line 842 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7940   8

Definition at line 828 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7941   115

Definition at line 831 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7941GE   309

Definition at line 837 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7942   434

Definition at line 843 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7945   435

Definition at line 844 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7960   7

Definition at line 827 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7961   30018

Definition at line 853 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7961GE   308

Definition at line 836 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7962   404

Definition at line 841 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7965   436

Definition at line 845 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7970   30006

Definition at line 849 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7971   119

Definition at line 832 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7975   437

Definition at line 846 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_7985   302

Definition at line 834 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_ATA186   12

Definition at line 830 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_CIPC   30016

Definition at line 852 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_NONE   0

Definition at line 820 of file chan_skinny.c.

Referenced by device2str().

#define SKINNY_DEVICE_SCCPGATEWAY_AN   30027

Definition at line 855 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_SCCPGATEWAY_BRI   30028

Definition at line 856 of file chan_skinny.c.

Referenced by device2str(), and get_button_template().

#define SKINNY_DEVICE_UNKNOWN   -1

Definition at line 819 of file chan_skinny.c.

Referenced by device2str().

#define SKINNY_DIALTONE   0x21

#define SKINNY_HOLD   8

Definition at line 871 of file chan_skinny.c.

#define SKINNY_INVALID   14

Definition at line 876 of file chan_skinny.c.

#define SKINNY_LAMP_BLINK   5

Definition at line 890 of file chan_skinny.c.

Referenced by skinny_call(), and skinny_hold().

#define SKINNY_LAMP_FLASH   4

Definition at line 889 of file chan_skinny.c.

#define SKINNY_LAMP_OFF   1

#define SKINNY_LAMP_ON   2

#define SKINNY_LAMP_WINK   3

Definition at line 888 of file chan_skinny.c.

#define SKINNY_MAX_CAPABILITIES   18

Definition at line 210 of file chan_skinny.c.

Referenced by handle_capabilities_res_message().

#define SKINNY_MAX_PACKET   1000

Definition at line 98 of file chan_skinny.c.

Referenced by skinny_req_parse(), and transmit_response().

#define SKINNY_MICOFF   2

Definition at line 862 of file chan_skinny.c.

#define SKINNY_MICON   1

Definition at line 861 of file chan_skinny.c.

#define SKINNY_NOTONE   0x7F

Definition at line 884 of file chan_skinny.c.

Referenced by transmit_tone().

#define SKINNY_OFFHOOK   1

#define SKINNY_ONHOOK   2

#define SKINNY_PARK   11

Definition at line 874 of file chan_skinny.c.

#define SKINNY_PROGRESS   12

Definition at line 875 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_REORDER   0x25

Definition at line 882 of file chan_skinny.c.

Referenced by skinny_indicate(), skinny_newcall(), and skinny_ss().

#define SKINNY_RING_FEATURE   4

Definition at line 895 of file chan_skinny.c.

#define SKINNY_RING_INSIDE   2

Definition at line 893 of file chan_skinny.c.

Referenced by skinny_call().

#define SKINNY_RING_OFF   1

#define SKINNY_RING_OUTSIDE   3

Definition at line 894 of file chan_skinny.c.

#define SKINNY_RINGIN   4

Definition at line 867 of file chan_skinny.c.

Referenced by skinny_call().

#define SKINNY_RINGOUT   3

Definition at line 866 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_SILENCE   0x00

#define SKINNY_SPEAKEROFF   2

Definition at line 859 of file chan_skinny.c.

Referenced by handle_stimulus_message(), skinny_hangup(), and transmit_callstate().

#define SKINNY_SPEAKERON   1

Definition at line 858 of file chan_skinny.c.

Referenced by handle_soft_key_event_message(), and handle_stimulus_message().

#define SKINNY_TRANSFER   10

Definition at line 873 of file chan_skinny.c.

#define SOFT_KEY_EVENT_MESSAGE   0x0026

Definition at line 250 of file chan_skinny.c.

Referenced by handle_message().

#define SOFT_KEY_SET_REQ_MESSAGE   0x0025

Definition at line 248 of file chan_skinny.c.

Referenced by handle_message().

#define SOFT_KEY_SET_RES_MESSAGE   0x0109

Definition at line 659 of file chan_skinny.c.

Referenced by handle_soft_key_set_req_message().

#define SOFT_KEY_TEMPLATE_REQ_MESSAGE   0x0028

Definition at line 258 of file chan_skinny.c.

Referenced by handle_message().

#define SOFT_KEY_TEMPLATE_RES_MESSAGE   0x0108

Definition at line 501 of file chan_skinny.c.

Referenced by handle_soft_key_template_req_message().

#define SOFTKEY_ANSWER   0x0B

Definition at line 531 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_BKSPC   0x08

Definition at line 528 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_CFWDALL   0x05

Definition at line 525 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_CFWDBUSY   0x06

Definition at line 526 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_CFWDNOANSWER   0x07

Definition at line 527 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_CONFRN   0x0D

Definition at line 533 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_ENDCALL   0x09

Definition at line 529 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_GPICKUP   0x12

Definition at line 538 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_HOLD   0x03

Definition at line 523 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_INFO   0x0C

Definition at line 532 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_JOIN   0x0F

Definition at line 535 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_MEETME   0x10

Definition at line 536 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_NEWCALL   0x02

Definition at line 522 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_NONE   0x00

Definition at line 520 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_PARK   0x0E

Definition at line 534 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_PICKUP   0x11

Definition at line 537 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_REDIAL   0x01

Definition at line 521 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_RESUME   0x0A

Definition at line 530 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SOFTKEY_TRNSFER   0x04

Definition at line 524 of file chan_skinny.c.

Referenced by handle_soft_key_event_message().

#define SPEED_DIAL_STAT_REQ_MESSAGE   0x000A

Definition at line 217 of file chan_skinny.c.

Referenced by handle_message().

#define SPEED_DIAL_STAT_RES_MESSAGE   0x0091

Definition at line 359 of file chan_skinny.c.

Referenced by handle_speed_dial_stat_req_message().

#define START_MEDIA_TRANSMISSION_MESSAGE   0x008A

Definition at line 311 of file chan_skinny.c.

Referenced by handle_open_receive_channel_ack_message().

#define START_TONE_MESSAGE   0x0082

Definition at line 271 of file chan_skinny.c.

Referenced by transmit_tone().

#define STIMULUS_AUTOANSWER   0x11

Definition at line 409 of file chan_skinny.c.

#define STIMULUS_CALLPARK   0x7E

Definition at line 411 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_CALLPICKUP   0x7F

Definition at line 412 of file chan_skinny.c.

#define STIMULUS_CONFERENCE   0x7D

Definition at line 410 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_DISPLAY   0x08

Definition at line 406 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_FORWARDALL   0x05

Definition at line 403 of file chan_skinny.c.

Referenced by handle_soft_key_event_message(), and handle_stimulus_message().

#define STIMULUS_FORWARDBUSY   0x06

Definition at line 404 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_FORWARDNOANSWER   0x07

Definition at line 405 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_HOLD   0x03

Definition at line 401 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_LINE   0x09

#define STIMULUS_MESSAGE   0x0005

Definition at line 181 of file chan_skinny.c.

Referenced by handle_message().

#define STIMULUS_NONE   0xFF

Definition at line 413 of file chan_skinny.c.

#define STIMULUS_REDIAL   0x01

Definition at line 399 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_SPEEDDIAL   0x02

Definition at line 400 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_TRANSFER   0x04

Definition at line 402 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STIMULUS_VOICEMAIL   0x0F

Definition at line 408 of file chan_skinny.c.

Referenced by handle_stimulus_message().

#define STOP_MEDIA_TRANSMISSION_MESSAGE   0x008B

Definition at line 330 of file chan_skinny.c.

Referenced by skinny_hold(), and transmit_callstate().

#define STOP_TONE_MESSAGE   0x0083

Definition at line 279 of file chan_skinny.c.

Referenced by transmit_tone().

#define TIME_DATE_REQ_MESSAGE   0x000D

Definition at line 227 of file chan_skinny.c.

Referenced by handle_message().

#define TYPE_LINE   2

Definition at line 898 of file chan_skinny.c.

#define TYPE_TRUNK   1

Definition at line 897 of file chan_skinny.c.

#define UNREGISTER_MESSAGE   0x0027

Definition at line 257 of file chan_skinny.c.

Referenced by handle_message().

#define VERSION_REQ_MESSAGE   0x000F

Definition at line 229 of file chan_skinny.c.

Referenced by handle_message().

#define VERSION_RES_MESSAGE   0x0098

Definition at line 445 of file chan_skinny.c.

Referenced by handle_version_req_message().


Enumeration Type Documentation

Enumerator:
SKINNY_CODEC_ALAW 
SKINNY_CODEC_ULAW 
SKINNY_CODEC_G723_1 
SKINNY_CODEC_G729A 
SKINNY_CODEC_G726_32 
SKINNY_CODEC_H261 
SKINNY_CODEC_H263 

Definition at line 86 of file chan_skinny.c.

00086                    {
00087    SKINNY_CODEC_ALAW = 2,
00088    SKINNY_CODEC_ULAW = 4,
00089    SKINNY_CODEC_G723_1 = 9,
00090    SKINNY_CODEC_G729A = 12,
00091    SKINNY_CODEC_G726_32 = 82, /* XXX Which packing order does this translate to? */
00092    SKINNY_CODEC_H261 = 100,
00093    SKINNY_CODEC_H263 = 101
00094 };


Function Documentation

static void* accept_thread ( void *  ignore  )  [static]

Definition at line 4598 of file chan_skinny.c.

References ast_calloc, ast_log(), ast_mutex_init(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create, ast_verbose(), destroy_session(), errno, skinnysession::fd, skinnysession::lock, LOG_ERROR, LOG_NOTICE, LOG_WARNING, skinnysession::next, s, sessions, skinnysession::sin, skinny_session(), and skinnysession::start.

04599 {
04600    int as;
04601    struct sockaddr_in sin;
04602    socklen_t sinlen;
04603    struct skinnysession *s;
04604    struct protoent *p;
04605    int arg = 1;
04606    pthread_attr_t attr;
04607    pthread_t tcp_thread;
04608 
04609    pthread_attr_init(&attr);
04610    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
04611 
04612    for (;;) {
04613       sinlen = sizeof(sin);
04614       as = accept(skinnysock, (struct sockaddr *)&sin, &sinlen);
04615       if (as < 0) {
04616          ast_log(LOG_NOTICE, "Accept returned -1: %s\n", strerror(errno));
04617          continue;
04618       }
04619 
04620       if (ast_atomic_fetchadd_int(&unauth_sessions, +1) >= auth_limit) {
04621          close(as);
04622          ast_atomic_fetchadd_int(&unauth_sessions, -1);
04623          continue;
04624       }
04625 
04626       p = getprotobyname("tcp");
04627       if(p) {
04628          if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
04629             ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
04630          }
04631       }
04632       if (!(s = ast_calloc(1, sizeof(struct skinnysession)))) {
04633          close(as);
04634          ast_atomic_fetchadd_int(&unauth_sessions, -1);
04635          continue;
04636       }
04637 
04638       memcpy(&s->sin, &sin, sizeof(sin));
04639       ast_mutex_init(&s->lock);
04640       s->fd = as;
04641 
04642       if(time(&s->start) == -1) {
04643          ast_log(LOG_ERROR, "error executing time(): %s; disconnecting client\n", strerror(errno));
04644          destroy_session(s);
04645          continue;
04646       }
04647 
04648       ast_mutex_lock(&sessionlock);
04649       s->next = sessions;
04650       sessions = s;
04651       ast_mutex_unlock(&sessionlock);
04652 
04653       if (ast_pthread_create(&tcp_thread, &attr, skinny_session, s)) {
04654          destroy_session(s);
04655       }
04656    }
04657    if (skinnydebug)
04658       ast_verbose("killing accept thread\n");
04659    close(as);
04660    pthread_attr_destroy(&attr);
04661    return 0;
04662 }

AST_MODULE_INFO ( ASTERISK_GPL_KEY  ,
AST_MODFLAG_DEFAULT  ,
"Skinny Client Control Protocol (Skinny)"  ,
load = load_module,
unload = unload_module 
)

AST_MUTEX_DEFINE_STATIC ( devicelock   ) 

AST_MUTEX_DEFINE_STATIC ( sessionlock   ) 

AST_MUTEX_DEFINE_STATIC ( netlock   ) 

AST_MUTEX_DEFINE_STATIC ( monlock   ) 

AST_THREADSTORAGE ( control2str_threadbuf  ,
control2str_threadbuf_init   
)

AST_THREADSTORAGE ( device2str_threadbuf  ,
device2str_threadbuf_init   
)

static struct skinny_device* build_device ( const char *  cat,
struct ast_variable v 
) [static, read]

Definition at line 2137 of file chan_skinny.c.

References __ourip, skinny_device::addons, skinny_device::addr, ast_append_ha(), ast_callerid_split(), ast_calloc, ast_cdr_amaflags2int(), ast_get_group(), ast_get_ip(), ast_log(), ast_mutex_init(), ast_ouraddrfor(), ast_parse_allow_disallow(), ast_strlen_zero(), ast_true(), ast_verbose(), skinny_line::callgroup, skinny_line::callreturn, skinny_line::callwaiting, skinny_line::cancallforward, skinny_line::capability, skinny_device::capability, skinny_line::cid_name, skinny_line::cid_num, skinny_line::context, default_prefs, DEFAULT_SKINNY_PORT, skinny_device::earlyrtp, skinny_speeddial::exten, exten, free, skinny_device::ha, skinny_line::hookstate, skinny_device::id, skinny_line::immediate, skinny_line::instance, skinny_speeddial::instance, skinny_line::label, skinny_speeddial::label, skinny_line::language, skinny_device::lastlineinstance, ast_variable::lineno, skinny_device::lines, skinny_line::lock, skinny_addon::lock, skinny_speeddial::lock, LOG_ERROR, LOG_WARNING, skinny_line::mailbox, skinny_line::mohinterpret, skinny_line::mohsuggest, skinny_line::msgstate, skinny_line::mwiblink, skinny_line::name, ast_variable::name, skinny_device::name, skinny_line::nat, ast_variable::next, skinny_line::next, skinny_addon::next, skinny_speeddial::next, skinny_line::onhooktime, option_verbose, skinny_device::ourip, skinny_line::parent, skinny_speeddial::parent, skinny_line::pickupgroup, skinny_line::prefs, skinny_device::prefs, SKINNY_ONHOOK, skinny_device::speeddials, strsep(), skinny_line::threewaycalling, skinny_line::transfer, skinny_line::type, skinny_addon::type, TYPE_LINE, TYPE_TRUNK, ast_variable::value, VERBOSE_PREFIX_3, and skinny_device::version_id.

Referenced by reload_config().

02138 {
02139    struct skinny_device *d;
02140    struct skinny_line *l;
02141    struct skinny_speeddial *sd;
02142    struct skinny_addon *a;
02143    int lineInstance = 1;
02144    int speeddialInstance = 1;
02145    int y = 0;
02146 
02147    if (!(d = ast_calloc(1, sizeof(struct skinny_device)))) {
02148       return NULL;
02149    } else {
02150       ast_copy_string(d->name, cat, sizeof(d->name));
02151       d->lastlineinstance = 1;
02152       d->capability = default_capability;
02153       d->prefs = default_prefs;
02154       d->earlyrtp = 1;
02155       while(v) {
02156          if (!strcasecmp(v->name, "host")) {
02157             if (ast_get_ip(&d->addr, v->value)) {
02158                free(d);
02159                return NULL;
02160             }
02161          } else if (!strcasecmp(v->name, "port")) {
02162             d->addr.sin_port = htons(atoi(v->value));
02163          } else if (!strcasecmp(v->name, "device")) {
02164             ast_copy_string(d->id, v->value, sizeof(d->id));
02165          } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
02166             d->ha = ast_append_ha(v->name, v->value, d->ha);
02167          } else if (!strcasecmp(v->name, "context")) {
02168             ast_copy_string(context, v->value, sizeof(context));
02169          } else if (!strcasecmp(v->name, "allow")) {
02170             ast_parse_allow_disallow(&d->prefs, &d->capability, v->value, 1);
02171          } else if (!strcasecmp(v->name, "disallow")) {
02172             ast_parse_allow_disallow(&d->prefs, &d->capability, v->value, 0);
02173          } else if (!strcasecmp(v->name, "version")) {
02174             ast_copy_string(d->version_id, v->value, sizeof(d->version_id));
02175          } else if (!strcasecmp(v->name, "earlyrtp")) {
02176             d->earlyrtp = ast_true(v->value);
02177          } else if (!strcasecmp(v->name, "nat")) {
02178             nat = ast_true(v->value);
02179          } else if (!strcasecmp(v->name, "callerid")) {
02180             if (!strcasecmp(v->value, "asreceived")) {
02181                cid_num[0] = '\0';
02182                cid_name[0] = '\0';
02183             } else {
02184                ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
02185             }
02186          } else if (!strcasecmp(v->name, "language")) {
02187             ast_copy_string(language, v->value, sizeof(language));
02188          } else if (!strcasecmp(v->name, "accountcode")) {
02189             ast_copy_string(accountcode, v->value, sizeof(accountcode));
02190          } else if (!strcasecmp(v->name, "amaflags")) {
02191             y = ast_cdr_amaflags2int(v->value);
02192             if (y < 0) {
02193                ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
02194             } else {
02195                amaflags = y;
02196             }
02197          } else if (!strcasecmp(v->name, "mohinterpret") || !strcasecmp(v->name, "musiconhold")) {
02198             ast_copy_string(mohinterpret, v->value, sizeof(mohinterpret));
02199          } else if (!strcasecmp(v->name, "mohsuggest")) {
02200             ast_copy_string(mohsuggest, v->value, sizeof(mohsuggest));
02201          } else if (!strcasecmp(v->name, "callgroup")) {
02202             cur_callergroup = ast_get_group(v->value);
02203          } else if (!strcasecmp(v->name, "pickupgroup")) {
02204             cur_pickupgroup = ast_get_group(v->value);
02205          } else if (!strcasecmp(v->name, "immediate")) {
02206             immediate = ast_true(v->value);
02207          } else if (!strcasecmp(v->name, "cancallforward")) {
02208             cancallforward = ast_true(v->value);
02209          } else if (!strcasecmp(v->name, "mailbox")) {
02210             ast_copy_string(mailbox, v->value, sizeof(mailbox));
02211          } else if (!strcasecmp(v->name, "callreturn")) {
02212             callreturn = ast_true(v->value);
02213          } else if (!strcasecmp(v->name, "callwaiting")) {
02214             callwaiting = ast_true(v->value);
02215          } else if (!strcasecmp(v->name, "transfer")) {
02216             transfer = ast_true(v->value);
02217          } else if (!strcasecmp(v->name, "threewaycalling")) {
02218             threewaycalling = ast_true(v->value);
02219          } else if (!strcasecmp(v->name, "mwiblink")) {
02220             mwiblink = ast_true(v->value);
02221          } else if (!strcasecmp(v->name, "linelabel")) {
02222             ast_copy_string(linelabel, v->value, sizeof(linelabel));
02223          } else if (!strcasecmp(v->name, "speeddial")) {
02224             if (!(sd = ast_calloc(1, sizeof(struct skinny_speeddial)))) {
02225                return NULL;
02226             } else {
02227                char *stringp, *exten, *label;
02228                stringp = v->value;
02229                exten = strsep(&stringp, ",");
02230                label = strsep(&stringp, ",");
02231                ast_mutex_init(&sd->lock);
02232                ast_copy_string(sd->exten, exten, sizeof(sd->exten));
02233                if (label)
02234                   ast_copy_string(sd->label, label, sizeof(sd->label));
02235                else
02236                   ast_copy_string(sd->label, exten, sizeof(sd->label));
02237                sd->instance = speeddialInstance++;
02238 
02239                sd->parent = d;
02240 
02241                sd->next = d->speeddials;
02242                d->speeddials = sd;
02243             }
02244          } else if (!strcasecmp(v->name, "addon")) {
02245             if (!(a = ast_calloc(1, sizeof(struct skinny_addon)))) {
02246                return NULL;
02247             } else {
02248                ast_mutex_init(&a->lock);
02249                ast_copy_string(a->type, v->value, sizeof(a->type));
02250 
02251                a->next = d->addons;
02252                d->addons = a;
02253             }
02254          } else if (!strcasecmp(v->name, "trunk") || !strcasecmp(v->name, "line")) {
02255             if (!(l = ast_calloc(1, sizeof(struct skinny_line)))) {
02256                return NULL;
02257             } else {
02258                ast_mutex_init(&l->lock);
02259                ast_copy_string(l->name, v->value, sizeof(l->name));
02260 
02261                /* XXX Should we check for uniqueness?? XXX */
02262                ast_copy_string(l->context, context, sizeof(l->context));
02263                ast_copy_string(l->cid_num, cid_num, sizeof(l->cid_num));
02264                ast_copy_string(l->cid_name, cid_name, sizeof(l->cid_name));
02265                ast_copy_string(l->label, linelabel, sizeof(l->label));
02266                ast_copy_string(l->language, language, sizeof(l->language));
02267                ast_copy_string(l->mohinterpret, mohinterpret, sizeof(l->mohinterpret));
02268                ast_copy_string(l->mohsuggest, mohsuggest, sizeof(l->mohsuggest));
02269                ast_copy_string(l->mailbox, mailbox, sizeof(l->mailbox));
02270                if (!ast_strlen_zero(mailbox)) {
02271                   if (option_verbose > 2)
02272                      ast_verbose(VERBOSE_PREFIX_3 "Setting mailbox '%s' on %s@%s\n", mailbox, d->name, l->name);
02273                }
02274                l->msgstate = -1;
02275                l->capability = d->capability;
02276                l->prefs = d->prefs;
02277                l->parent = d;
02278                if (!strcasecmp(v->name, "trunk")) {
02279                   l->type = TYPE_TRUNK;
02280                } else {
02281                   l->type = TYPE_LINE;
02282                }
02283                l->immediate = immediate;
02284                l->callgroup = cur_callergroup;
02285                l->pickupgroup = cur_pickupgroup;
02286                l->callreturn = callreturn;
02287                l->cancallforward = cancallforward;
02288                l->callwaiting = callwaiting;
02289                l->transfer = transfer;
02290                l->threewaycalling = threewaycalling;
02291                l->mwiblink = mwiblink;
02292                l->onhooktime = time(NULL);
02293                l->instance = lineInstance++;
02294                /* ASSUME we're onhook at this point */
02295                l->hookstate = SKINNY_ONHOOK;
02296                l->nat = nat;
02297 
02298                l->next = d->lines;
02299                d->lines = l;
02300             }
02301          } else {
02302             ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno);
02303          }
02304          v = v->next;
02305       }
02306 
02307       if (!d->lines) {
02308          ast_log(LOG_ERROR, "A Skinny device must have at least one line!\n");
02309          return NULL;
02310       }
02311       if (/*d->addr.sin_addr.s_addr && */!ntohs(d->addr.sin_port)) {
02312          d->addr.sin_port = htons(DEFAULT_SKINNY_PORT);
02313       }
02314 #if 0
02315       /* I don't think we need this anymore at all, since d->ourip is set in skinny_register now */
02316       if (d->addr.sin_addr.s_addr) {
02317          /* XXX See note above, in 'host' option. */
02318          if (ast_ouraddrfor(&d->addr.sin_addr, &d->ourip)) {
02319             d->ourip = __ourip;
02320          }
02321       } else {
02322          d->ourip = __ourip;
02323       }
02324 #endif
02325    }
02326    return d;
02327 }

static int codec_ast2skinny ( int  astcodec  )  [static]

Definition at line 1398 of file chan_skinny.c.

References AST_FORMAT_ALAW, AST_FORMAT_G723_1, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_H261, AST_FORMAT_H263, AST_FORMAT_ULAW, SKINNY_CODEC_ALAW, SKINNY_CODEC_G723_1, SKINNY_CODEC_G726_32, SKINNY_CODEC_G729A, SKINNY_CODEC_H261, SKINNY_CODEC_H263, and SKINNY_CODEC_ULAW.

Referenced by handle_open_receive_channel_ack_message(), and transmit_connect().

01399 {
01400    switch (astcodec) {
01401    case AST_FORMAT_ALAW:
01402       return SKINNY_CODEC_ALAW;
01403    case AST_FORMAT_ULAW:
01404       return SKINNY_CODEC_ULAW;
01405    case AST_FORMAT_G723_1:
01406       return SKINNY_CODEC_G723_1;
01407    case AST_FORMAT_G729A:
01408       return SKINNY_CODEC_G729A;
01409    case AST_FORMAT_G726_AAL2: /* XXX Is this right? */
01410       return SKINNY_CODEC_G726_32;
01411    case AST_FORMAT_H261:
01412       return SKINNY_CODEC_H261;
01413    case AST_FORMAT_H263:
01414       return SKINNY_CODEC_H263;
01415    default:
01416       return 0;
01417    }
01418 }

static int codec_skinny2ast ( enum skinny_codecs  skinnycodec  )  [static]

Definition at line 1376 of file chan_skinny.c.

References AST_FORMAT_ALAW, AST_FORMAT_G723_1, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_H261, AST_FORMAT_H263, AST_FORMAT_ULAW, SKINNY_CODEC_ALAW, SKINNY_CODEC_G723_1, SKINNY_CODEC_G726_32, SKINNY_CODEC_G729A, SKINNY_CODEC_H261, SKINNY_CODEC_H263, and SKINNY_CODEC_ULAW.

Referenced by handle_capabilities_res_message().

01377 {
01378    switch (skinnycodec) {
01379    case SKINNY_CODEC_ALAW:
01380       return AST_FORMAT_ALAW;
01381    case SKINNY_CODEC_ULAW:
01382       return AST_FORMAT_ULAW;
01383    case SKINNY_CODEC_G723_1:
01384       return AST_FORMAT_G723_1;
01385    case SKINNY_CODEC_G729A:
01386       return AST_FORMAT_G729A;
01387    case SKINNY_CODEC_G726_32:
01388       return AST_FORMAT_G726_AAL2; /* XXX Is this right? */
01389    case SKINNY_CODEC_H261:
01390       return AST_FORMAT_H261;
01391    case SKINNY_CODEC_H263:
01392       return AST_FORMAT_H263;
01393    default:
01394       return 0;
01395    }
01396 }

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

Definition at line 1888 of file chan_skinny.c.

References ast_strdup, devices, skinny_device::id, and skinny_device::next.

01889 {
01890    struct skinny_device *d;
01891 
01892    char *result = NULL;
01893    int wordlen = strlen(word);
01894    int which = 0;
01895 
01896    if (pos == 2) {
01897       for (d = devices; d && !result; d = d->next) {
01898          if (!strncasecmp(word, d->id, wordlen) && ++which > state)
01899             result = ast_strdup(d->id);
01900       }
01901    }
01902 
01903    return result;
01904 }

static char* control2str ( int  ind  )  [static]

Definition at line 2736 of file chan_skinny.c.

References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_WINK, and CONTROL2STR_BUFSIZE.

02736                                   {
02737    char *tmp;
02738 
02739    switch (ind) {
02740    case AST_CONTROL_HANGUP:
02741       return "Other end has hungup";
02742    case AST_CONTROL_RING:
02743       return "Local ring";
02744    case AST_CONTROL_RINGING:
02745       return "Remote end is ringing";
02746    case AST_CONTROL_ANSWER:
02747       return "Remote end has answered";
02748    case AST_CONTROL_BUSY:
02749       return "Remote end is busy";
02750    case AST_CONTROL_TAKEOFFHOOK:
02751       return "Make it go off hook";
02752    case AST_CONTROL_OFFHOOK:
02753       return "Line is off hook";
02754    case AST_CONTROL_CONGESTION:
02755       return "Congestion (circuits busy)";
02756    case AST_CONTROL_FLASH:
02757       return "Flash hook";
02758    case AST_CONTROL_WINK:
02759       return "Wink";
02760    case AST_CONTROL_OPTION:
02761       return "Set a low-level option";
02762    case AST_CONTROL_RADIO_KEY:
02763       return "Key Radio";
02764    case AST_CONTROL_RADIO_UNKEY:
02765       return "Un-Key Radio";
02766    case AST_CONTROL_PROGRESS:
02767       return "Remote end is making Progress";
02768    case AST_CONTROL_PROCEEDING:
02769       return "Remote end is proceeding";
02770    case AST_CONTROL_HOLD:
02771       return "Hold";
02772    case AST_CONTROL_UNHOLD:
02773       return "Unhold";
02774    case -1:
02775       return "Stop tone";
02776    default:
02777       if (!(tmp = ast_threadstorage_get(&control2str_threadbuf, CONTROL2STR_BUFSIZE)))
02778                         return "Unknown";
02779       snprintf(tmp, CONTROL2STR_BUFSIZE, "UNKNOWN-%d", ind);
02780       return tmp;
02781    }
02782 }

static void delete_devices ( void   )  [static]

Definition at line 4919 of file chan_skinny.c.

References skinny_device::addons, ast_mutex_destroy(), ast_mutex_lock(), ast_mutex_unlock(), devices, free, skinny_device::lines, skinny_addon::lock, skinny_speeddial::lock, skinny_line::lock, skinny_device::next, skinny_addon::next, skinny_speeddial::next, skinny_line::next, and skinny_device::speeddials.

Referenced by unload_module().

04920 {
04921    struct skinny_device *d, *dlast;
04922    struct skinny_line *l, *llast;
04923    struct skinny_speeddial *sd, *sdlast;
04924    struct skinny_addon *a, *alast;
04925 
04926    ast_mutex_lock(&devicelock);
04927 
04928    /* Delete all devices */
04929    for (d=devices;d;) {
04930       /* Delete all lines for this device */
04931       for (l=d->lines;l;) {
04932          llast = l;
04933          l = l->next;
04934          ast_mutex_destroy(&llast->lock);
04935          free(llast);
04936       }
04937       /* Delete all speeddials for this device */
04938       for (sd=d->speeddials;sd;) {
04939          sdlast = sd;
04940          sd = sd->next;
04941          ast_mutex_destroy(&sdlast->lock);
04942          free(sdlast);
04943       }
04944       /* Delete all addons for this device */
04945       for (a=d->addons;a;) {
04946          alast = a;
04947          a = a->next;
04948          ast_mutex_destroy(&alast->lock);
04949          free(alast);
04950       }
04951       dlast = d;
04952       d = d->next;
04953       free(dlast);
04954    }
04955    devices=NULL;
04956    ast_mutex_unlock(&devicelock);
04957 }

static void destroy_session ( struct skinnysession s  )  [static]

Definition at line 4410 of file chan_skinny.c.

References ast_log(), ast_mutex_destroy(), ast_mutex_lock(), ast_mutex_unlock(), skinnysession::device, skinnysession::fd, free, skinnysession::lock, LOG_WARNING, skinnysession::next, and sessions.

04411 {
04412    struct skinnysession *cur, *prev = NULL;
04413    ast_mutex_lock(&sessionlock);
04414    cur = sessions;
04415    while(cur) {
04416       if (cur == s) {
04417          break;
04418       }
04419       prev = cur;
04420       cur = cur->next;
04421    }
04422    if (cur) {
04423       if (prev) {
04424          prev->next = cur->next;
04425       } else {
04426          sessions = cur->next;
04427       }
04428       if (s->fd > -1) {
04429          close(s->fd);
04430       }
04431       if (!s->device) {
04432          ast_atomic_fetchadd_int(&unauth_sessions, -1);
04433       }
04434       ast_mutex_destroy(&s->lock);
04435       free(s);
04436    } else {
04437       ast_log(LOG_WARNING, "Trying to delete nonexistent session %p?\n", s);
04438    }
04439    ast_mutex_unlock(&sessionlock);
04440 }

static char* device2str ( int  type  )  [static]

Definition at line 1942 of file chan_skinny.c.

References DEVICE2STR_BUFSIZE, SKINNY_DEVICE_12, SKINNY_DEVICE_12SP, SKINNY_DEVICE_12SPPLUS, SKINNY_DEVICE_30SPPLUS, SKINNY_DEVICE_30VIP, SKINNY_DEVICE_7902, SKINNY_DEVICE_7905, SKINNY_DEVICE_7906, SKINNY_DEVICE_7910, SKINNY_DEVICE_7911, SKINNY_DEVICE_7912, SKINNY_DEVICE_7914, SKINNY_DEVICE_7920, SKINNY_DEVICE_7921, SKINNY_DEVICE_7931, SKINNY_DEVICE_7935, SKINNY_DEVICE_7936, SKINNY_DEVICE_7937, SKINNY_DEVICE_7940, SKINNY_DEVICE_7941, SKINNY_DEVICE_7941GE, SKINNY_DEVICE_7942, SKINNY_DEVICE_7945, SKINNY_DEVICE_7960, SKINNY_DEVICE_7961, SKINNY_DEVICE_7961GE, SKINNY_DEVICE_7962, SKINNY_DEVICE_7965, SKINNY_DEVICE_7970, SKINNY_DEVICE_7971, SKINNY_DEVICE_7975, SKINNY_DEVICE_7985, SKINNY_DEVICE_ATA186, SKINNY_DEVICE_CIPC, SKINNY_DEVICE_NONE, SKINNY_DEVICE_SCCPGATEWAY_AN, SKINNY_DEVICE_SCCPGATEWAY_BRI, and SKINNY_DEVICE_UNKNOWN.

Referenced by skinny_show_devices().

01943 {
01944    char *tmp;
01945 
01946    switch (type) {
01947    case SKINNY_DEVICE_NONE:
01948       return "No Device";
01949    case SKINNY_DEVICE_30SPPLUS:
01950       return "30SP Plus";
01951    case SKINNY_DEVICE_12SPPLUS:
01952       return "12SP Plus";
01953    case SKINNY_DEVICE_12SP:
01954       return "12SP";
01955    case SKINNY_DEVICE_12:
01956       return "12";
01957    case SKINNY_DEVICE_30VIP:
01958       return "30VIP";
01959    case SKINNY_DEVICE_7910:
01960       return "7910";
01961    case SKINNY_DEVICE_7960:
01962       return "7960";
01963    case SKINNY_DEVICE_7940:
01964       return "7940";
01965    case SKINNY_DEVICE_7935:
01966       return "7935";
01967    case SKINNY_DEVICE_ATA186:
01968       return "ATA186";
01969    case SKINNY_DEVICE_7941:
01970       return "7941";
01971    case SKINNY_DEVICE_7971:
01972       return "7971";
01973    case SKINNY_DEVICE_7914:
01974       return "7914";
01975    case SKINNY_DEVICE_7985:
01976       return "7985";
01977    case SKINNY_DEVICE_7911:
01978       return "7911";
01979    case SKINNY_DEVICE_7961GE:
01980       return "7961GE";
01981    case SKINNY_DEVICE_7941GE:
01982       return "7941GE";
01983    case SKINNY_DEVICE_7931:
01984       return "7931";
01985    case SKINNY_DEVICE_7921:
01986       return "7921";
01987    case SKINNY_DEVICE_7906:
01988       return "7906";
01989    case SKINNY_DEVICE_7962:
01990       return "7962";
01991    case SKINNY_DEVICE_7937:
01992       return "7937";
01993    case SKINNY_DEVICE_7942:
01994       return "7942";
01995    case SKINNY_DEVICE_7945:
01996       return "7945";
01997    case SKINNY_DEVICE_7965:
01998       return "7965";
01999    case SKINNY_DEVICE_7975:
02000       return "7975";
02001    case SKINNY_DEVICE_7905:
02002       return "7905";
02003    case SKINNY_DEVICE_7920:
02004       return "7920";
02005    case SKINNY_DEVICE_7970:
02006       return "7970";
02007    case SKINNY_DEVICE_7912:
02008       return "7912";
02009    case SKINNY_DEVICE_7902:
02010       return "7902";
02011    case SKINNY_DEVICE_CIPC:
02012       return "IP Communicator";
02013    case SKINNY_DEVICE_7961:
02014       return "7961";
02015    case SKINNY_DEVICE_7936:
02016       return "7936";
02017    case SKINNY_DEVICE_SCCPGATEWAY_AN:
02018       return "SCCPGATEWAY_AN";
02019    case SKINNY_DEVICE_SCCPGATEWAY_BRI:
02020       return "SCCPGATEWAY_BRI";
02021    case SKINNY_DEVICE_UNKNOWN:
02022       return "Unknown";
02023    default:
02024       if (!(tmp = ast_threadstorage_get(&device2str_threadbuf, DEVICE2STR_BUFSIZE)))
02025          return "Unknown";
02026       snprintf(tmp, DEVICE2STR_BUFSIZE, "UNKNOWN-%d", type);
02027       return tmp;
02028    }
02029 }

static void do_housekeeping ( struct skinnysession s  )  [static]

Definition at line 1795 of file chan_skinny.c.

References handle_time_date_req_message().

Referenced by handle_keep_alive_message(), handle_onhook_message(), handle_soft_key_event_message(), and skinny_hangup().

01796 {
01797 /*
01798    int new;
01799    int old;
01800    struct skinny_device *d = s->device;
01801    struct skinny_line *l;
01802 */
01803 
01804    /* Update time on device */
01805    handle_time_date_req_message(NULL, s);
01806 
01807 /*
01808    for (l = d->lines; l; l = l->next) {
01809       if (has_voicemail(l)) {
01810          if (skinnydebug)
01811             ast_verbose("Checking for voicemail Skinny %s@%s\n", l->name, d->name);
01812          ast_app_inboxcount(l->mailbox, &new, &old);
01813          if (skinnydebug)
01814             ast_verbose("Skinny %s@%s has voicemail!\n", l->name, d->name);
01815          transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
01816       } else {
01817          transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF);
01818       }
01819    }
01820 */
01821 }

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

Definition at line 4664 of file chan_skinny.c.

References ast_io_wait(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_runq(), and ast_sched_wait().

04665 {
04666    int res;
04667 
04668    /* This thread monitors all the interfaces which are not yet in use
04669       (and thus do not have a separate thread) indefinitely */
04670    /* From here on out, we die whenever asked */
04671    for(;;) {
04672       pthread_testcancel();
04673       /* Wait for sched or io */
04674       res = ast_sched_wait(sched);
04675       if ((res < 0) || (res > 1000)) {
04676          res = 1000;
04677       }
04678       res = ast_io_wait(io, res);
04679       ast_mutex_lock(&monlock);
04680       if (res >= 0) {
04681          ast_sched_runq(sched);
04682       }
04683       ast_mutex_unlock(&monlock);
04684    }
04685    /* Never reached */
04686    return NULL;
04687 
04688 }

static struct skinny_line* find_line_by_instance ( struct skinny_device d,
int  instance 
) [static, read]

Definition at line 1257 of file chan_skinny.c.

References ast_log(), skinny_line::instance, skinny_device::lines, LOG_WARNING, skinny_device::name, and skinny_line::next.

Referenced by find_subchannel_by_instance_reference(), handle_enbloc_call_message(), handle_line_state_req_message(), handle_offhook_message(), handle_soft_key_event_message(), and handle_stimulus_message().

01258 {
01259    struct skinny_line *l;
01260 
01261    if (!instance)
01262       instance = 1;
01263 
01264    for (l = d->lines; l; l = l->next) {
01265       if (l->instance == instance)
01266          break;
01267    }
01268 
01269    if (!l) {
01270       ast_log(LOG_WARNING, "Could not find line with instance '%d' on device '%s'\n", instance, d->name);
01271    }
01272    return l;
01273 }

static struct skinny_line* find_line_by_name ( const char *  dest  )  [static, read]

Definition at line 1275 of file chan_skinny.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), devices, skinny_device::lines, LOG_NOTICE, skinny_line::name, skinny_device::name, skinny_line::next, and skinny_device::next.

Referenced by skinny_request().

01276 {
01277    struct skinny_line *l;
01278    struct skinny_device *d;
01279    char line[256];
01280    char *at;
01281    char *device;
01282 
01283    ast_copy_string(line, dest, sizeof(line));
01284    at = strchr(line, '@');
01285    if (!at) {
01286       ast_log(LOG_NOTICE, "Device '%s' has no @ (at) sign!\n", dest);
01287       return NULL;
01288    }
01289    *at++ = '\0';
01290    device = at;
01291    ast_mutex_lock(&devicelock);
01292    for (d = devices; d; d = d->next) {
01293       if (!strcasecmp(d->name, device)) {
01294          if (skinnydebug)
01295             ast_verbose("Found device: %s\n", d->name);
01296          /* Found the device */
01297          for (l = d->lines; l; l = l->next) {
01298             /* Search for the right line */
01299             if (!strcasecmp(l->name, line)) {
01300                ast_mutex_unlock(&devicelock);
01301                return l;
01302             }
01303          }
01304       }
01305    }
01306    /* Device not found */
01307    ast_mutex_unlock(&devicelock);
01308    return NULL;
01309 }

static struct skinny_speeddial* find_speeddial_by_instance ( struct skinny_device d,
int  instance 
) [static, read]

Definition at line 1361 of file chan_skinny.c.

References ast_log(), skinny_speeddial::instance, LOG_WARNING, skinny_device::name, skinny_speeddial::next, and skinny_device::speeddials.

Referenced by handle_speed_dial_stat_req_message(), and handle_stimulus_message().

01362 {
01363    struct skinny_speeddial *sd;
01364 
01365    for (sd = d->speeddials; sd; sd = sd->next) {
01366       if (sd->instance == instance)
01367          break;
01368    }
01369 
01370    if (!sd) {
01371       ast_log(LOG_WARNING, "Could not find speeddial with instance '%d' on device '%s'\n", instance, d->name);
01372    }
01373    return sd;
01374 }

static struct skinny_subchannel* find_subchannel_by_instance_reference ( struct skinny_device d,
int  instance,
int  reference 
) [static, read]

Definition at line 1312 of file chan_skinny.c.

References ast_log(), skinny_subchannel::callid, find_line_by_instance(), LOG_WARNING, skinny_device::name, skinny_subchannel::next, and skinny_line::sub.

Referenced by handle_enbloc_call_message(), handle_keypad_button_message(), handle_message(), handle_offhook_message(), handle_onhook_message(), handle_soft_key_event_message(), and handle_stimulus_message().

01313 {
01314    struct skinny_line *l = find_line_by_instance(d, instance);
01315    struct skinny_subchannel *sub;
01316 
01317    if (!l) {
01318       return NULL;
01319    }
01320 
01321    if (!reference)
01322       sub = l->sub;
01323    else {
01324       for (sub = l->sub; sub; sub = sub->next) {
01325          if (sub->callid == reference)
01326             break;
01327       }
01328    }
01329 
01330    if (!sub) {
01331       ast_log(LOG_WARNING, "Could not find subchannel with reference '%d' on '%s'\n", reference, d->name);
01332    }
01333    return sub;
01334 }

static struct skinny_subchannel* find_subchannel_by_reference ( struct skinny_device d,
int  reference 
) [static, read]

Definition at line 1337 of file chan_skinny.c.

References ast_log(), skinny_subchannel::callid, skinny_device::lines, LOG_WARNING, skinny_line::name, skinny_device::name, skinny_subchannel::next, skinny_line::next, and skinny_line::sub.

Referenced by handle_open_receive_channel_ack_message().

01338 {
01339    struct skinny_line *l;
01340    struct skinny_subchannel *sub = NULL;
01341 
01342    for (l = d->lines; l; l = l->next) {
01343       for (sub = l->sub; sub; sub = sub->next) {
01344          if (sub->callid == reference)
01345             break;
01346       }
01347       if (sub)
01348          break;
01349    }
01350 
01351    if (!l) {
01352       ast_log(LOG_WARNING, "Could not find any lines that contained a subchannel with reference '%d' on device '%s'\n", reference, d->name);
01353    } else {
01354       if (!sub) {
01355          ast_log(LOG_WARNING, "Could not find subchannel with reference '%d' on '%s@%s'\n", reference, l->name, d->name);
01356       }
01357    }
01358    return sub;
01359 }

static void* get_button_template ( struct skinnysession s,
struct button_definition_template btn 
) [static]

Definition at line 1107 of file chan_skinny.c.

References skinny_device::addons, ast_log(), BT_CALLPARK, BT_CONFERENCE, BT_CUST_LINESPEEDDIAL, BT_DISPLAY, BT_FORWARDALL, BT_HOLD, BT_LINE, BT_NONE, BT_REDIAL, BT_SPEEDDIAL, BT_TRANSFER, BT_VOICEMAIL, skinnysession::device, LOG_WARNING, skinny_addon::next, SKINNY_DEVICE_12, SKINNY_DEVICE_12SP, SKINNY_DEVICE_12SPPLUS, SKINNY_DEVICE_30SPPLUS, SKINNY_DEVICE_30VIP, SKINNY_DEVICE_7902, SKINNY_DEVICE_7905, SKINNY_DEVICE_7906, SKINNY_DEVICE_7910, SKINNY_DEVICE_7911, SKINNY_DEVICE_7912, SKINNY_DEVICE_7914, SKINNY_DEVICE_7920, SKINNY_DEVICE_7921, SKINNY_DEVICE_7931, SKINNY_DEVICE_7935, SKINNY_DEVICE_7936, SKINNY_DEVICE_7937, SKINNY_DEVICE_7940, SKINNY_DEVICE_7941, SKINNY_DEVICE_7941GE, SKINNY_DEVICE_7942, SKINNY_DEVICE_7945, SKINNY_DEVICE_7960, SKINNY_DEVICE_7961, SKINNY_DEVICE_7961GE, SKINNY_DEVICE_7962, SKINNY_DEVICE_7965, SKINNY_DEVICE_7970, SKINNY_DEVICE_7971, SKINNY_DEVICE_7975, SKINNY_DEVICE_7985, SKINNY_DEVICE_ATA186, SKINNY_DEVICE_CIPC, SKINNY_DEVICE_SCCPGATEWAY_AN, SKINNY_DEVICE_SCCPGATEWAY_BRI, skinny_addon::type, and skinny_device::type.

Referenced by handle_button_template_req_message().

01108 {
01109    struct skinny_device *d = s->device;
01110    struct skinny_addon *a = d->addons;
01111    int i;
01112 
01113    switch (d->type) {
01114       case SKINNY_DEVICE_30SPPLUS:
01115       case SKINNY_DEVICE_30VIP:
01116          /* 13 rows, 2 columns */
01117          for (i = 0; i < 4; i++)
01118             (btn++)->buttonDefinition = BT_LINE;
01119          (btn++)->buttonDefinition = BT_REDIAL;
01120          (btn++)->buttonDefinition = BT_VOICEMAIL;
01121          (btn++)->buttonDefinition = BT_CALLPARK;
01122          (btn++)->buttonDefinition = BT_FORWARDALL;
01123          (btn++)->buttonDefinition = BT_CONFERENCE;
01124          for (i = 0; i < 4; i++)
01125             (btn++)->buttonDefinition = BT_NONE;
01126          for (i = 0; i < 13; i++)
01127             (btn++)->buttonDefinition = BT_SPEEDDIAL;
01128          
01129          break;
01130       case SKINNY_DEVICE_12SPPLUS:
01131       case SKINNY_DEVICE_12SP:
01132       case SKINNY_DEVICE_12:
01133          /* 6 rows, 2 columns */
01134          for (i = 0; i < 2; i++)
01135             (btn++)->buttonDefinition = BT_LINE;
01136          (btn++)->buttonDefinition = BT_REDIAL;
01137          for (i = 0; i < 3; i++)
01138             (btn++)->buttonDefinition = BT_SPEEDDIAL;
01139          (btn++)->buttonDefinition = BT_HOLD;
01140          (btn++)->buttonDefinition = BT_TRANSFER;
01141          (btn++)->buttonDefinition = BT_FORWARDALL;
01142          (btn++)->buttonDefinition = BT_CALLPARK;
01143          (btn++)->buttonDefinition = BT_VOICEMAIL;
01144          (btn++)->buttonDefinition = BT_CONFERENCE;
01145          break;
01146       case SKINNY_DEVICE_7910:
01147          (btn++)->buttonDefinition = BT_LINE;
01148          (btn++)->buttonDefinition = BT_HOLD;
01149          (btn++)->buttonDefinition = BT_TRANSFER;
01150          (btn++)->buttonDefinition = BT_DISPLAY;
01151          (btn++)->buttonDefinition = BT_VOICEMAIL;
01152          (btn++)->buttonDefinition = BT_CONFERENCE;
01153          (btn++)->buttonDefinition = BT_FORWARDALL;
01154          for (i = 0; i < 2; i++)
01155             (btn++)->buttonDefinition = BT_SPEEDDIAL;
01156          (btn++)->buttonDefinition = BT_REDIAL;
01157          break;
01158       case SKINNY_DEVICE_7960:
01159       case SKINNY_DEVICE_7961:
01160       case SKINNY_DEVICE_7961GE:
01161       case SKINNY_DEVICE_7962:
01162       case SKINNY_DEVICE_7965:
01163          for (i = 0; i < 6; i++)
01164             (btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
01165          break;
01166       case SKINNY_DEVICE_7940:
01167       case SKINNY_DEVICE_7941:
01168       case SKINNY_DEVICE_7941GE:
01169       case SKINNY_DEVICE_7942:
01170       case SKINNY_DEVICE_7945:
01171          for (i = 0; i < 2; i++)
01172             (btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
01173          break;
01174       case SKINNY_DEVICE_7935:
01175       case SKINNY_DEVICE_7936:
01176          for (i = 0; i < 2; i++)
01177             (btn++)->buttonDefinition = BT_LINE;
01178          break;
01179       case SKINNY_DEVICE_ATA186:
01180          (btn++)->buttonDefinition = BT_LINE;
01181          break;
01182       case SKINNY_DEVICE_7970:
01183       case SKINNY_DEVICE_7971:
01184       case SKINNY_DEVICE_7975:
01185       case SKINNY_DEVICE_CIPC:
01186          for (i = 0; i < 8; i++)
01187             (btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
01188          break;
01189       case SKINNY_DEVICE_7985:
01190          /* XXX I have no idea what the buttons look like on these. */
01191          ast_log(LOG_WARNING, "Unsupported device type '%d (7985)' found.\n", d->type);
01192          break;
01193       case SKINNY_DEVICE_7912:
01194       case SKINNY_DEVICE_7911:
01195       case SKINNY_DEVICE_7905:
01196          (btn++)->buttonDefinition = BT_LINE;
01197          (btn++)->buttonDefinition = BT_HOLD;
01198          break;
01199       case SKINNY_DEVICE_7920:
01200          /* XXX I don't know if this is right. */
01201          for (i = 0; i < 4; i++)
01202             (btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
01203          break;
01204       case SKINNY_DEVICE_7921:
01205          for (i = 0; i < 6; i++)
01206             (btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
01207          break;
01208       case SKINNY_DEVICE_7902:
01209          ast_log(LOG_WARNING, "Unsupported device type '%d (7902)' found.\n", d->type);
01210          break;
01211       case SKINNY_DEVICE_7906:
01212          ast_log(LOG_WARNING, "Unsupported device type '%d (7906)' found.\n", d->type);
01213          break;
01214       case SKINNY_DEVICE_7931:
01215          ast_log(LOG_WARNING, "Unsupported device type '%d (7931)' found.\n", d->type);
01216          break;
01217       case SKINNY_DEVICE_7937:
01218          ast_log(LOG_WARNING, "Unsupported device type '%d (7937)' found.\n", d->type);
01219          break;
01220       case SKINNY_DEVICE_7914:
01221          ast_log(LOG_WARNING, "Unsupported device type '%d (7914)' found.  Expansion module registered by itself?\n", d->type);
01222          break;
01223       case SKINNY_DEVICE_SCCPGATEWAY_AN:
01224       case SKINNY_DEVICE_SCCPGATEWAY_BRI:
01225          ast_log(LOG_WARNING, "Unsupported device type '%d (SCCP gateway)' found.\n", d->type);
01226          break;
01227       default:
01228          ast_log(LOG_WARNING, "Unknown device type '%d' found.\n", d->type);
01229          break;
01230    }
01231 
01232    for (a = d->addons; a; a = a->next) {
01233       if (!strcasecmp(a->type, "7914")) {
01234          for (i = 0; i < 14; i++)
01235             (btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
01236       } else {
01237          ast_log(LOG_WARNING, "Unknown addon type '%s' found.  Skipping.\n", a->type);
01238       }
01239    }
01240 
01241    return btn;
01242 }

static int get_input ( struct skinnysession s  )  [static]

Definition at line 4442 of file chan_skinny.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), skinnysession::device, errno, pollfd::events, skinnysession::fd, pollfd::fd, htolel, skinnysession::inbuf, letohl, skinnysession::lock, LOG_ERROR, LOG_WARNING, poll(), POLLIN, pollfd::revents, skinny_unregister(), and skinnysession::start.

04443 {
04444    int res;
04445    int dlen = 0;
04446    int timeout = keep_alive * 1100;
04447    time_t now;
04448    struct pollfd fds[1];
04449 
04450    if (!s->device) {
04451       if(time(&now) == -1) {
04452          ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
04453          return -1;
04454       }
04455 
04456       timeout = (auth_timeout - (now - s->start)) * 1000;
04457       if (timeout < 0) {
04458          /* we have timed out */
04459          if (skinnydebug)
04460             ast_verbose("Skinny Client failed to authenticate in %d seconds\n", auth_timeout);
04461          return -1;
04462       }
04463    }
04464 
04465    fds[0].fd = s->fd;
04466    fds[0].events = POLLIN;
04467    fds[0].revents = 0;
04468    res = poll(fds, 1, timeout); /* If nothing has happen, client is dead */
04469                    /* we add 10% to the keep_alive to deal */
04470                    /* with network delays, etc */
04471    if (res < 0) {
04472       if (errno != EINTR) {
04473          ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
04474          return res;
04475       }
04476    } else if (res == 0) {
04477       if (skinnydebug) {
04478          if (s->device) {
04479             ast_verbose("Skinny Client was lost, unregistering\n");
04480          } else {
04481             ast_verbose("Skinny Client failed to authenticate in %d seconds\n", auth_timeout);
04482          }
04483       }
04484       skinny_unregister(NULL, s);
04485       return -1;
04486    }
04487            
04488    if (fds[0].revents) {
04489       ast_mutex_lock(&s->lock);
04490       memset(s->inbuf,0,sizeof(s->inbuf));
04491       res = read(s->fd, s->inbuf, 4);
04492       if (res < 0) {
04493          ast_log(LOG_WARNING, "read() returned error: %s\n", strerror(errno));
04494 
04495          if (skinnydebug)
04496             ast_verbose("Skinny Client was lost, unregistering\n");
04497          
04498          skinny_unregister(NULL,s);
04499          ast_mutex_unlock(&s->lock);
04500          return res;
04501       } else if (res != 4) {
04502          ast_log(LOG_WARNING, "Skinny Client sent less data than expected.  Expected 4 but got %d.\n", res);
04503          ast_mutex_unlock(&s->lock);
04504          
04505          if (res == 0) {
04506             if (skinnydebug)
04507                ast_verbose("Skinny Client was lost, unregistering\n");
04508             skinny_unregister(NULL, s);
04509          }
04510            
04511          return -1;
04512       }
04513       
04514       dlen = letohl(*(int *)s->inbuf);
04515       if (dlen < 4) {
04516          ast_log(LOG_WARNING, "Skinny Client sent invalid data.\n");
04517          ast_mutex_unlock(&s->lock);
04518          return -1;
04519       }
04520       if (dlen+8 > sizeof(s->inbuf)) {
04521          dlen = sizeof(s->inbuf) - 8;
04522       }
04523       *(int *)s->inbuf = htolel(dlen);
04524 
04525       res = read(s->fd, s->inbuf+4, dlen+4);
04526       ast_mutex_unlock(&s->lock);
04527       if (res < 0) {
04528          ast_log(LOG_WARNING, "read() returned error: %s\n", strerror(errno));
04529          return res;
04530       } else if (res != (dlen+4)) {
04531          ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
04532          return -1;
04533       }
04534       return res;
04535    }
04536    return 0;
04537 }

static int handle_alarm_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3790 of file chan_skinny.c.

References skinny_data::alarm, ast_verbose(), skinny_req::data, and alarm_message::displayMessage.

Referenced by handle_message().

03791 {
03792    /* no response necessary */
03793    if (skinnydebug)
03794       ast_verbose("Received Alarm Message: %s\n", req->data.alarm.displayMessage);
03795 
03796    return 1;
03797 }

static int handle_button_template_req_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3654 of file chan_skinny.c.

References ast_verbose(), BT_CUST_HINT, BT_CUST_LINESPEEDDIAL, BT_LINE, BT_NONE, BT_SPEEDDIAL, BUTTON_TEMPLATE_RES_MESSAGE, button_template_res_message::buttonCount, button_definition::buttonDefinition, button_definition_template::buttonDefinition, button_template_res_message::buttonOffset, skinny_data::buttontemplate, skinny_req::data, button_template_res_message::definition, skinnysession::device, get_button_template(), htolel, skinny_speeddial::instance, skinny_line::instance, button_definition::instanceNumber, skinny_device::lines, skinny_device::name, skinny_speeddial::next, skinny_line::next, req_alloc(), skinny_device::speeddials, button_template_res_message::totalButtonCount, transmit_response(), and skinny_device::type.

Referenced by handle_message().

03655 {
03656    struct skinny_device *d = s->device;
03657    struct skinny_line *l;
03658    int i;
03659 
03660    struct skinny_speeddial *sd;
03661    struct button_definition_template btn[42];
03662    int lineInstance = 1;
03663    int speeddialInstance = 1;
03664    int buttonCount = 0;
03665 
03666    if (!(req = req_alloc(sizeof(struct button_template_res_message), BUTTON_TEMPLATE_RES_MESSAGE)))
03667       return -1;
03668 
03669    memset(&btn, 0, sizeof(btn));
03670 
03671    get_button_template(s, btn);
03672 
03673    for (i=0; i<42; i++) {
03674       int btnSet = 0;
03675       switch (btn[i].buttonDefinition) {
03676          case BT_CUST_LINESPEEDDIAL:
03677             /* assume failure */
03678             req->data.buttontemplate.definition[i].buttonDefinition = BT_NONE;
03679             req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
03680 
03681             for (l = d->lines; l; l = l->next) {
03682                if (l->instance == lineInstance) {
03683                   ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
03684                   req->data.buttontemplate.definition[i].buttonDefinition = BT_LINE;
03685                   req->data.buttontemplate.definition[i].instanceNumber = htolel(lineInstance);
03686                   lineInstance++;
03687                   buttonCount++;
03688                   btnSet = 1;
03689                   break;
03690                }
03691             }
03692 
03693             if (!btnSet) {
03694                for (sd = d->speeddials; sd; sd = sd->next) {
03695                   if (sd->instance == speeddialInstance) {
03696                      ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
03697                      req->data.buttontemplate.definition[i].buttonDefinition = BT_SPEEDDIAL;
03698                      req->data.buttontemplate.definition[i].instanceNumber = htolel(speeddialInstance);
03699                      speeddialInstance++;
03700                      buttonCount++;
03701                      btnSet = 1;
03702                      break;
03703                   }
03704                }
03705             }
03706             break;
03707          case BT_LINE:
03708             req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_NONE);
03709             req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
03710 
03711             for (l = d->lines; l; l = l->next) {
03712                if (l->instance == lineInstance) {
03713                   ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
03714                   req->data.buttontemplate.definition[i].buttonDefinition = BT_LINE;
03715                   req->data.buttontemplate.definition[i].instanceNumber = htolel(lineInstance);
03716                   lineInstance++;
03717                   buttonCount++;
03718                   btnSet = 1;
03719                   break;
03720                }
03721             }
03722             break;
03723          case BT_SPEEDDIAL:
03724             req->data.buttontemplate.definition[i].buttonDefinition = BT_NONE;
03725             req->data.buttontemplate.definition[i].instanceNumber = 0;
03726 
03727             for (sd = d->speeddials; sd; sd = sd->next) {
03728                if (sd->instance == speeddialInstance) {
03729                   ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
03730                   req->data.buttontemplate.definition[i].buttonDefinition = BT_SPEEDDIAL;
03731                   req->data.buttontemplate.definition[i].instanceNumber = htolel(speeddialInstance);
03732                   speeddialInstance++;
03733                   buttonCount++;
03734                   btnSet = 1;
03735                   break;
03736                }
03737             }
03738             break;
03739          case BT_CUST_HINT:
03740             break;
03741          case BT_NONE:
03742             break;
03743          default:
03744             ast_verbose("Adding button: %d, %d\n", btn[i].buttonDefinition, 0);
03745             req->data.buttontemplate.definition[i].buttonDefinition = htolel(btn[i].buttonDefinition);
03746             req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
03747             buttonCount++;
03748             btnSet = 1;
03749             break;
03750       }
03751    }
03752 
03753    req->data.buttontemplate.buttonOffset = htolel(0);
03754    req->data.buttontemplate.buttonCount = htolel(buttonCount);
03755    req->data.buttontemplate.totalButtonCount = htolel(buttonCount);
03756 
03757    if (skinnydebug)
03758       ast_verbose("Sending %d template to %s\n",
03759                d->type,
03760                d->name);
03761    transmit_response(s, req);
03762    return 1;
03763 }

static int handle_capabilities_res_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3541 of file chan_skinny.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), skinny_line::capability, skinny_device::capability, capabilities_res_message::caps, skinny_data::caps, station_capabilities::codec, codec_skinny2ast(), capabilities_res_message::count, skinny_req::data, skinnysession::device, letohl, skinny_device::lines, skinny_line::lock, LOG_WARNING, skinny_line::next, and SKINNY_MAX_CAPABILITIES.

Referenced by handle_message().

03542 {
03543    struct skinny_device *d = s->device;
03544    struct skinny_line *l;
03545    uint32_t count = 0;
03546    int codecs = 0;
03547    int i;
03548 
03549    count = letohl(req->data.caps.count);
03550    if (count > SKINNY_MAX_CAPABILITIES) {
03551       count = SKINNY_MAX_CAPABILITIES;
03552       ast_log(LOG_WARNING, "Received more capabilities than we can handle (%d).  Ignoring the rest.\n", SKINNY_MAX_CAPABILITIES);
03553    }
03554 
03555    for (i = 0; i < count; i++) {
03556       int acodec = 0;
03557       int scodec = 0;
03558       scodec = letohl(req->data.caps.caps[i].codec);
03559       acodec = codec_skinny2ast(scodec);
03560       if (skinnydebug)
03561          ast_verbose("Adding codec capability '%d (%d)'\n", acodec, scodec);
03562       codecs |= acodec;
03563    }
03564 
03565    d->capability &= codecs;
03566    ast_verbose("Device capability set to '%d'\n", d->capability);
03567    for (l = d->lines; l; l = l->next) {
03568       ast_mutex_lock(&l->lock);
03569       l->capability = d->capability;
03570       ast_mutex_unlock(&l->lock);
03571    }
03572 
03573    return 1;
03574 }

static int handle_enbloc_call_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3868 of file chan_skinny.c.

References ast_hangup(), ast_ignore_pattern(), ast_log(), ast_pthread_create, AST_STATE_DOWN, ast_verbose(), enbloc_call_message::calledParty, skinny_subchannel::callid, ast_channel::context, skinny_req::data, skinnysession::device, skinny_data::enbloccallmessage, errno, ast_channel::exten, find_line_by_instance(), find_subchannel_by_instance_reference(), skinny_line::hookstate, skinny_line::instance, skinny_device::lastcallreference, skinny_device::lastlineinstance, LOG_WARNING, skinny_device::name, skinny_line::name, skinny_subchannel::parent, SKINNY_DIALTONE, skinny_new(), skinny_newcall(), SKINNY_OFFHOOK, SKINNY_SILENCE, t, ast_channel::tech_pvt, transmit_callstate(), transmit_displaymessage(), and transmit_tone().

Referenced by handle_message().

03869 {
03870    struct skinny_device *d = s->device;
03871    struct skinny_line *l;
03872    struct skinny_subchannel *sub = NULL;
03873    struct ast_channel *c;
03874    pthread_t t;
03875 
03876    if (skinnydebug)
03877       ast_verbose("Received Enbloc Call: %s\n", req->data.enbloccallmessage.calledParty);
03878 
03879    sub = find_subchannel_by_instance_reference(d, d->lastlineinstance, d->lastcallreference);
03880 
03881    if (!sub) {
03882       l = find_line_by_instance(d, d->lastlineinstance);
03883       if (!l) {
03884          return 0;
03885       }
03886    } else {
03887       l = sub->parent;
03888    }
03889 
03890    c = skinny_new(l, AST_STATE_DOWN);
03891 
03892    if(!c) {
03893       ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
03894    } else {
03895       l->hookstate = SKINNY_OFFHOOK;
03896 
03897       sub = c->tech_pvt;
03898       transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
03899       if (skinnydebug)
03900          ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, d->name);
03901       transmit_displaymessage(s, NULL, l->instance, sub->callid); /* clear display */
03902       transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
03903 
03904       if (!ast_ignore_pattern(c->context, req->data.enbloccallmessage.calledParty)) {
03905          transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
03906       }
03907       ast_copy_string(c->exten, req->data.enbloccallmessage.calledParty, sizeof(c->exten));
03908       if (ast_pthread_create(&t, NULL, skinny_newcall, c)) {
03909          ast_log(LOG_WARNING, "Unable to create new call thread: %s\n", strerror(errno));
03910          ast_hangup(c);
03911       }
03912    }
03913    
03914    return 1;
03915 }

static int handle_headset_status_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 4230 of file chan_skinny.c.

Referenced by handle_message().

04231 {
04232    /* XXX umm...okay?  Why do I care? */
04233    return 1;
04234 }

static int handle_ip_port_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3093 of file chan_skinny.c.

Referenced by handle_message().

03094 {
03095    /* no response necessary */
03096    return 1;
03097 }

static int handle_keep_alive_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3040 of file chan_skinny.c.

References do_housekeeping(), KEEP_ALIVE_ACK_MESSAGE, req_alloc(), and transmit_response().

Referenced by handle_message().

03041 {
03042    if (!(req = req_alloc(0, KEEP_ALIVE_ACK_MESSAGE)))
03043       return -1;
03044 
03045    transmit_response(s, req);
03046    do_housekeeping(s);
03047    return 1;
03048 }

static int handle_keypad_button_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3099 of file chan_skinny.c.

References ast_channel::_state, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_log(), ast_queue_frame(), ast_verbose(), keypad_button_message::button, keypad_button_message::callReference, skinny_req::data, skinnysession::device, find_subchannel_by_instance_reference(), ast_frame::frametype, skinny_data::keypad, skinny_device::lastcallreference, skinny_device::lastlineinstance, letohl, keypad_button_message::lineInstance, LOG_WARNING, skinny_line::name, skinny_subchannel::next, skinny_subchannel::owner, skinny_subchannel::parent, ast_frame::src, and ast_frame::subclass.

Referenced by handle_message().

03100 {
03101    struct skinny_subchannel *sub = NULL;
03102    struct skinny_line *l;
03103    struct skinny_device *d = s->device;
03104    struct ast_frame f = { 0, };
03105    char dgt;
03106    int digit;
03107    int lineInstance;
03108    int callReference;
03109 
03110    digit = letohl(req->data.keypad.button);
03111    lineInstance = letohl(req->data.keypad.lineInstance);
03112    callReference = letohl(req->data.keypad.callReference);
03113 
03114    if (digit == 14) {
03115       dgt = '*';
03116    } else if (digit == 15) {
03117       dgt = '#';
03118    } else if (digit >= 0 && digit <= 9) {
03119       dgt = '0' + digit;
03120    } else {
03121       /* digit=10-13 (A,B,C,D ?), or
03122        * digit is bad value
03123        *
03124        * probably should not end up here, but set
03125        * value for backward compatibility, and log
03126        * a warning.
03127        */
03128       dgt = '0' + digit;
03129       ast_log(LOG_WARNING, "Unsupported digit %d\n", digit);
03130    }
03131 
03132    f.subclass = dgt;
03133 
03134    f.src = "skinny";
03135 
03136    if (lineInstance && callReference)
03137       sub = find_subchannel_by_instance_reference(d, lineInstance, callReference);
03138    else
03139       sub = find_subchannel_by_instance_reference(d, d->lastlineinstance, d->lastcallreference);
03140 
03141    if (!sub)
03142       return 0;
03143 
03144    l = sub->parent;
03145    if (sub->owner) {
03146       if (sub->owner->_state == 0) {
03147          f.frametype = AST_FRAME_DTMF_BEGIN;
03148          ast_queue_frame(sub->owner, &f);
03149       }
03150       /* XXX MUST queue this frame to all lines in threeway call if threeway call is active */
03151       f.frametype = AST_FRAME_DTMF_END;
03152       ast_queue_frame(sub->owner, &f);
03153       /* XXX This seriously needs to be fixed */
03154       if (sub->next && sub->next->owner) {
03155          if (sub->owner->_state == 0) {
03156             f.frametype = AST_FRAME_DTMF_BEGIN;
03157             ast_queue_frame(sub->next->owner, &f);
03158          }
03159          f.frametype = AST_FRAME_DTMF_END;
03160          ast_queue_frame(sub->next->owner, &f);
03161       }
03162    } else {
03163       if (skinnydebug)
03164          ast_verbose("No owner: %s\n", l->name);
03165    }
03166    return 1;
03167 }

static int handle_line_state_req_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3601 of file chan_skinny.c.

References ast_mutex_lock(), ast_mutex_unlock(), skinny_req::data, skinnysession::device, find_line_by_instance(), skinny_line::instance, skinny_line::label, letohl, skinny_data::line, LINE_STAT_RES_MESSAGE, line_stat_res_message::lineDirNumber, line_stat_res_message::lineDisplayName, line_stat_res_message::lineNumber, line_state_req_message::lineNumber, skinny_data::linestat, skinny_line::name, req_alloc(), and transmit_response().

Referenced by handle_message().

03602 {
03603    struct skinny_device *d = s->device;
03604    struct skinny_line *l;
03605    int instance;
03606 
03607    instance = letohl(req->data.line.lineNumber);
03608 
03609    ast_mutex_lock(&devicelock);
03610 
03611    l = find_line_by_instance(d, instance);
03612 
03613    if (!l) {
03614       return 0;
03615    }
03616 
03617    ast_mutex_unlock(&devicelock);
03618 
03619    if (!(req = req_alloc(sizeof(struct line_stat_res_message), LINE_STAT_RES_MESSAGE)))
03620       return -1;
03621 
03622    req->data.linestat.lineNumber = letohl(instance);
03623    memcpy(req->data.linestat.lineDirNumber, l->name,
03624          sizeof(req->data.linestat.lineDirNumber));
03625    memcpy(req->data.linestat.lineDisplayName, l->label,
03626          sizeof(req->data.linestat.lineDisplayName));
03627    transmit_response(s,req);
03628    return 1;
03629 }

static int handle_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 4242 of file chan_skinny.c.

References ast_channel::_state, ALARM_MESSAGE, ast_log(), AST_STATE_UP, ast_verbose(), keypad_button_message::button, BUTTON_TEMPLATE_REQ_MESSAGE, keypad_button_message::callReference, CAPABILITIES_RES_MESSAGE, skinny_req::data, skinnysession::device, skinny_req::e, ENBLOC_CALL_MESSAGE, skinny_device::exten, find_subchannel_by_instance_reference(), free, handle_alarm_message(), handle_button_template_req_message(), handle_capabilities_res_message(), handle_enbloc_call_message(), handle_headset_status_message(), handle_ip_port_message(), handle_keep_alive_message(), handle_keypad_button_message(), handle_line_state_req_message(), handle_offhook_message(), handle_onhook_message(), handle_open_receive_channel_ack_message(), handle_register_available_lines_message(), handle_register_message(), handle_server_request_message(), handle_soft_key_event_message(), handle_soft_key_set_req_message(), handle_soft_key_template_req_message(), handle_speed_dial_stat_req_message(), handle_stimulus_message(), handle_time_date_req_message(), handle_unregister_message(), handle_version_req_message(), HEADSET_STATUS_MESSAGE, IP_PORT_MESSAGE, KEEP_ALIVE_MESSAGE, skinny_data::keypad, KEYPAD_BUTTON_MESSAGE, len, letohl, LINE_STATE_REQ_MESSAGE, keypad_button_message::lineInstance, LOG_WARNING, register_message::name, OFFHOOK_MESSAGE, ONHOOK_MESSAGE, OPEN_RECEIVE_CHANNEL_ACK_MESSAGE, skinny_subchannel::owner, skinny_data::reg, REGISTER_AVAILABLE_LINES_MESSAGE, REGISTER_MESSAGE, SERVER_REQUEST_MESSAGE, SOFT_KEY_EVENT_MESSAGE, SOFT_KEY_SET_REQ_MESSAGE, SOFT_KEY_TEMPLATE_REQ_MESSAGE, SPEED_DIAL_STAT_REQ_MESSAGE, STIMULUS_MESSAGE, TIME_DATE_REQ_MESSAGE, UNREGISTER_MESSAGE, and VERSION_REQ_MESSAGE.

Referenced by skinny_session().

04243 {
04244    int res = 0;
04245    struct skinny_device *d = s->device;
04246    struct skinny_subchannel *sub;
04247    int lineInstance;
04248    int callReference;
04249 
04250    if ((!s->device) && (letohl(req->e) != REGISTER_MESSAGE && letohl(req->e) != ALARM_MESSAGE)) {
04251       ast_log(LOG_WARNING, "Client sent message #%d without first registering.\n", req->e);
04252       free(req);
04253       return 0;
04254    }
04255 
04256    switch(letohl(req->e))  {
04257    case KEEP_ALIVE_MESSAGE:
04258       res = handle_keep_alive_message(req, s);
04259       break;
04260    case REGISTER_MESSAGE:
04261       if (skinnydebug)
04262          ast_verbose("Device %s is attempting to register\n", req->data.reg.name);
04263 
04264       res = handle_register_message(req, s);
04265       break;
04266    case IP_PORT_MESSAGE:
04267       res = handle_ip_port_message(req, s);
04268       break;
04269    case KEYPAD_BUTTON_MESSAGE:
04270       if (skinnydebug)
04271          ast_verbose("Collected digit: [%d]\n", letohl(req->data.keypad.button));
04272 
04273       lineInstance = letohl(req->data.keypad.lineInstance);
04274       callReference = letohl(req->data.keypad.callReference);
04275 
04276       sub = find_subchannel_by_instance_reference(d, lineInstance, callReference);
04277 
04278       if (sub && (sub->owner && sub->owner->_state <  AST_STATE_UP)) {
04279          char dgt;
04280          int digit = letohl(req->data.keypad.button);
04281          size_t len;
04282 
04283          if (digit == 14) {
04284             dgt = '*';
04285          } else if (digit == 15) {
04286             dgt = '#';
04287          } else if (digit >= 0 && digit <= 9) {
04288             dgt = '0' + digit;
04289          } else {
04290             /* digit=10-13 (A,B,C,D ?), or
04291             * digit is bad value
04292             *
04293             * probably should not end up here, but set
04294             * value for backward compatibility, and log
04295             * a warning.
04296             */
04297             dgt = '0' + digit;
04298             ast_log(LOG_WARNING, "Unsupported digit %d\n", digit);
04299          }
04300 
04301          len = strlen(d->exten);
04302          if (len < sizeof(d->exten) - 1) {
04303             d->exten[len] = dgt;
04304             d->exten[len+1] = '\0';
04305          } else {
04306             ast_log(LOG_WARNING, "Dropping digit with value %d because digit queue is full\n", dgt);
04307          }
04308       } else
04309          res = handle_keypad_button_message(req, s);
04310       break;
04311    case ENBLOC_CALL_MESSAGE:
04312       res = handle_enbloc_call_message(req, s);
04313       break;
04314    case STIMULUS_MESSAGE:
04315       res = handle_stimulus_message(req, s);
04316       break;
04317    case OFFHOOK_MESSAGE:
04318       res = handle_offhook_message(req, s);
04319       break;
04320    case ONHOOK_MESSAGE:
04321       res = handle_onhook_message(req, s);
04322       break;
04323    case CAPABILITIES_RES_MESSAGE:
04324       if (skinnydebug)
04325          ast_verbose("Received CapabilitiesRes\n");
04326 
04327       res = handle_capabilities_res_message(req, s);
04328       break;
04329    case SPEED_DIAL_STAT_REQ_MESSAGE:
04330       if (skinnydebug)
04331          ast_verbose("Received SpeedDialStatRequest\n");
04332 
04333       res = handle_speed_dial_stat_req_message(req, s);
04334       break;
04335    case LINE_STATE_REQ_MESSAGE:
04336       if (skinnydebug)
04337          ast_verbose("Received LineStatRequest\n");
04338       res = handle_line_state_req_message(req, s);
04339       break;
04340    case TIME_DATE_REQ_MESSAGE:
04341       if (skinnydebug)
04342          ast_verbose("Received Time/Date Request\n");
04343 
04344       res = handle_time_date_req_message(req, s);
04345       break;
04346    case BUTTON_TEMPLATE_REQ_MESSAGE:
04347       if (skinnydebug)
04348          ast_verbose("Buttontemplate requested\n");
04349 
04350       res = handle_button_template_req_message(req, s);
04351       break;
04352    case VERSION_REQ_MESSAGE:
04353       if (skinnydebug)
04354          ast_verbose("Version Request\n");
04355 
04356       res = handle_version_req_message(req, s);
04357       break;
04358    case SERVER_REQUEST_MESSAGE:
04359       if (skinnydebug)
04360          ast_verbose("Received Server Request\n");
04361 
04362       res = handle_server_request_message(req, s);
04363       break;
04364    case ALARM_MESSAGE:
04365       res = handle_alarm_message(req, s);
04366       break;
04367    case OPEN_RECEIVE_CHANNEL_ACK_MESSAGE:
04368       if (skinnydebug)
04369          ast_verbose("Received Open Receive Channel Ack\n");
04370 
04371       res = handle_open_receive_channel_ack_message(req, s);
04372       break;
04373    case SOFT_KEY_SET_REQ_MESSAGE:
04374       if (skinnydebug)
04375          ast_verbose("Received SoftKeySetReq\n");
04376 
04377       res = handle_soft_key_set_req_message(req, s);
04378       break;
04379    case SOFT_KEY_EVENT_MESSAGE:
04380       res = handle_soft_key_event_message(req, s);
04381       break;
04382    case UNREGISTER_MESSAGE:
04383       if (skinnydebug)
04384          ast_verbose("Received Unregister Request\n");
04385 
04386       res = handle_unregister_message(req, s);
04387       break;
04388    case SOFT_KEY_TEMPLATE_REQ_MESSAGE:
04389       if (skinnydebug)
04390          ast_verbose("Received SoftKey Template Request\n");
04391 
04392       res = handle_soft_key_template_req_message(req, s);
04393       break;
04394    case HEADSET_STATUS_MESSAGE:
04395       res = handle_headset_status_message(req, s);
04396       break;
04397    case REGISTER_AVAILABLE_LINES_MESSAGE:
04398       res = handle_register_available_lines_message(req, s);
04399       break;
04400    default:
04401       if (skinnydebug)
04402          ast_verbose("RECEIVED UNKNOWN MESSAGE TYPE:  %x\n", letohl(req->e));
04403       break;
04404    }
04405    if (res >= 0 && req)
04406       free(req);
04407    return res;
04408 }

static int handle_offhook_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3408 of file chan_skinny.c.

References AST_CONTROL_ANSWER, ast_hangup(), ast_log(), ast_pthread_create, ast_queue_control(), ast_setstate(), AST_STATE_DOWN, AST_STATE_UP, ast_verbose(), skinny_subchannel::callid, skinny_req::data, skinnysession::device, errno, find_line_by_instance(), find_subchannel_by_instance_reference(), skinny_line::hookstate, skinny_line::instance, KEYDEF_CONNECTED, KEYDEF_OFFHOOK, skinny_device::lastcallreference, skinny_device::lastlineinstance, letohl, LOG_DEBUG, LOG_WARNING, skinny_device::name, skinny_line::name, skinny_data::offhook, skinny_subchannel::onhold, skinny_subchannel::outgoing, skinny_subchannel::owner, skinny_subchannel::parent, SKINNY_CONNECTED, SKINNY_DIALTONE, SKINNY_LAMP_ON, skinny_new(), SKINNY_OFFHOOK, SKINNY_RING_OFF, SKINNY_SILENCE, skinny_ss(), start_rtp(), STIMULUS_LINE, t, ast_channel::tech_pvt, transmit_callstate(), transmit_displaymessage(), transmit_lamp_indication(), transmit_ringer_mode(), transmit_selectsoftkeys(), transmit_tone(), offhook_message::unknown1, and offhook_message::unknown2.

Referenced by handle_message().

03409 {
03410    struct skinny_device *d = s->device;
03411    struct skinny_line *l;
03412    struct skinny_subchannel *sub;
03413    struct ast_channel *c;
03414    pthread_t t;
03415    int unknown1;
03416    int unknown2;
03417 
03418    unknown1 = letohl(req->data.offhook.unknown1);
03419    unknown2 = letohl(req->data.offhook.unknown2);
03420 
03421    sub = find_subchannel_by_instance_reference(d, d->lastlineinstance, d->lastcallreference);
03422 
03423    if (!sub) {
03424       l = find_line_by_instance(d, d->lastlineinstance);
03425       if (!l) {
03426          return 0;
03427       }
03428    } else {
03429       l = sub->parent;
03430    }
03431 
03432    transmit_ringer_mode(s, SKINNY_RING_OFF);
03433    l->hookstate = SKINNY_OFFHOOK;
03434 
03435    if (sub && sub->onhold) {
03436       return 1;
03437    }
03438 
03439    transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
03440 
03441    if (sub && sub->outgoing) {
03442       /* We're answering a ringing call */
03443       ast_queue_control(sub->owner, AST_CONTROL_ANSWER);
03444       transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
03445       transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
03446       transmit_callstate(s, l->instance, SKINNY_CONNECTED, sub->callid);
03447       transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_CONNECTED);
03448       start_rtp(sub);
03449       ast_setstate(sub->owner, AST_STATE_UP);
03450    } else {
03451       if (sub && sub->owner) {
03452          ast_log(LOG_DEBUG, "Current sub [%s] already has owner\n", sub->owner->name);
03453       } else {
03454          c = skinny_new(l, AST_STATE_DOWN);
03455          if(c) {
03456             sub = c->tech_pvt;
03457             transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
03458             if (skinnydebug)
03459                ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, d->name);
03460             transmit_displaymessage(s, NULL, l->instance, sub->callid); /* clear display */
03461             transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
03462             transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_OFFHOOK);
03463 
03464             /* start the switch thread */
03465             if (ast_pthread_create(&t, NULL, skinny_ss, c)) {
03466                ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
03467                ast_hangup(c);
03468             }
03469          } else {
03470             ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
03471          }
03472       }
03473    }
03474    return 1;
03475 }

static int handle_onhook_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3477 of file chan_skinny.c.

References skinny_subchannel::alreadygone, ast_log(), ast_queue_hangup(), ast_verbose(), attempt_transfer(), skinny_subchannel::callid, skinny_subchannel::cxmode, skinny_req::data, skinnysession::device, do_housekeeping(), find_subchannel_by_instance_reference(), skinny_line::hookstate, skinny_line::instance, skinny_device::lastcallreference, skinny_device::lastlineinstance, letohl, LOG_WARNING, skinny_device::name, skinny_line::name, skinny_subchannel::next, skinny_subchannel::onhold, skinny_data::onhook, skinny_subchannel::outgoing, skinny_subchannel::owner, skinny_subchannel::parent, skinny_subchannel::rtp, SKINNY_CX_RECVONLY, SKINNY_ONHOOK, skinny_line::transfer, transmit_callstate(), onhook_message::unknown1, and onhook_message::unknown2.

Referenced by handle_message().

03478 {
03479    struct skinny_device *d = s->device;
03480    struct skinny_line *l;
03481    struct skinny_subchannel *sub;
03482    int unknown1;
03483    int unknown2;
03484 
03485    unknown1 = letohl(req->data.onhook.unknown1);
03486    unknown2 = letohl(req->data.onhook.unknown2);
03487 
03488    sub = find_subchannel_by_instance_reference(d, d->lastlineinstance, d->lastcallreference);
03489 
03490    if (!sub) {
03491       return 0;
03492    }
03493    l = sub->parent;
03494 
03495    if (l->hookstate == SKINNY_ONHOOK) {
03496       /* Something else already put us back on hook */
03497       return 0;
03498    }
03499    l->hookstate = SKINNY_ONHOOK;
03500 
03501    if (sub->onhold) {
03502       return 0;
03503    }
03504 
03505    sub->cxmode = SKINNY_CX_RECVONLY;
03506    transmit_callstate(s, l->instance, l->hookstate, sub->callid);
03507    if (skinnydebug)
03508       ast_verbose("Skinny %s@%s went on hook\n", l->name, d->name);
03509    if (l->transfer && (sub->owner && sub->next && sub->next->owner) && ((!sub->outgoing) || (sub->next && !sub->next->outgoing))) {
03510       /* We're allowed to transfer, we have two active calls and
03511          we made at least one of the calls.  Let's try and transfer */
03512 
03513 #if 0
03514       if ((res = attempt_transfer(p)) < 0) {
03515          if (sub->next && sub->next->owner) {
03516             sub->next->alreadygone = 1;
03517             ast_queue_hangup(sub->next->owner,1);
03518          }
03519       } else if (res) {
03520          ast_log(LOG_WARNING, "Transfer attempt failed\n");
03521          return 0;
03522       }
03523 #endif
03524    } else {
03525       /* Hangup the current call */
03526       /* If there is another active call, skinny_hangup will ring the phone with the other call */
03527       if (sub->owner) {
03528          sub->alreadygone = 1;
03529          ast_queue_hangup(sub->owner);
03530       } else {
03531          ast_log(LOG_WARNING, "Skinny(%s@%s-%d) channel already destroyed\n",
03532             l->name, d->name, sub->callid);
03533       }
03534    }
03535    if ((l->hookstate == SKINNY_ONHOOK) && (sub->next && !sub->next->rtp)) {
03536       do_housekeeping(s);
03537    }
03538    return 1;
03539 }

static int handle_open_receive_channel_ack_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3799 of file chan_skinny.c.

References ast_best_codec(), ast_codec_pref_getsize(), ast_inet_ntoa(), ast_log(), ast_rtp_get_us(), ast_rtp_set_peer(), ast_verbose(), media_qualifier::bitRate, ast_format_list::bits, skinny_subchannel::callid, skinny_line::capability, codec_ast2skinny(), start_media_transmission_message::conferenceId, ast_format_list::cur_ms, skinny_req::data, skinnysession::device, find_subchannel_by_reference(), htolel, open_receive_channel_ack_message::ipAddr, letohl, LOG_ERROR, skinny_data::openreceivechannelack, skinny_device::ourip, media_qualifier::packets, start_media_transmission_message::packetSize, skinny_subchannel::parent, open_receive_channel_ack_message::passThruId, start_media_transmission_message::passThruPartyId, start_media_transmission_message::payloadType, open_receive_channel_ack_message::port, media_qualifier::precedence, skinny_line::prefs, start_media_transmission_message::qualifier, start_media_transmission_message::remoteIp, start_media_transmission_message::remotePort, req_alloc(), skinny_subchannel::rtp, START_MEDIA_TRANSMISSION_MESSAGE, skinny_data::startmedia, open_receive_channel_ack_message::status, transmit_response(), and media_qualifier::vad.

Referenced by handle_message().

03800 {
03801    struct skinny_device *d = s->device;
03802    struct skinny_line *l;
03803    struct skinny_subchannel *sub;
03804    struct ast_format_list fmt;
03805    struct sockaddr_in sin;
03806    struct sockaddr_in us;
03807    uint32_t addr;
03808    int port;
03809    int status;
03810    int passthruid;
03811 
03812    status = letohl(req->data.openreceivechannelack.status);
03813    if (status) {
03814       ast_log(LOG_ERROR, "Open Receive Channel Failure\n");
03815       return 0;
03816    }
03817    addr = letohl(req->data.openreceivechannelack.ipAddr);
03818    port = letohl(req->data.openreceivechannelack.port);
03819    passthruid = letohl(req->data.openreceivechannelack.passThruId);
03820 
03821    sin.sin_family = AF_INET;
03822    sin.sin_addr.s_addr = addr;
03823    sin.sin_port = htons(port);
03824 
03825    sub = find_subchannel_by_reference(d, passthruid);
03826 
03827    if (!sub)
03828       return 0;
03829 
03830    l = sub->parent;
03831 
03832    if (sub->rtp) {
03833       ast_rtp_set_peer(sub->rtp, &sin);
03834       ast_rtp_get_us(sub->rtp, &us);
03835    } else {
03836       ast_log(LOG_ERROR, "No RTP structure, this is very bad\n");
03837       return 0;
03838    }
03839 
03840    if (skinnydebug) {
03841       ast_verbose("ipaddr = %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
03842       ast_verbose("ourip = %s:%d\n", ast_inet_ntoa(d->ourip), ntohs(us.sin_port));
03843    }
03844 
03845    if (!(req = req_alloc(sizeof(struct start_media_transmission_message), START_MEDIA_TRANSMISSION_MESSAGE)))
03846       return -1;
03847 
03848    fmt = ast_codec_pref_getsize(&l->prefs, ast_best_codec(l->capability));
03849 
03850    if (skinnydebug)
03851       ast_verbose("Setting payloadType to '%d' (%d ms)\n", fmt.bits, fmt.cur_ms);
03852 
03853    req->data.startmedia.conferenceId = htolel(sub->callid);
03854    req->data.startmedia.passThruPartyId = htolel(sub->callid);
03855    req->data.startmedia.remoteIp = htolel(d->ourip.s_addr);
03856    req->data.startmedia.remotePort = htolel(ntohs(us.sin_port));
03857    req->data.startmedia.packetSize = htolel(fmt.cur_ms);
03858    req->data.startmedia.payloadType = htolel(codec_ast2skinny(fmt.bits));
03859    req->data.startmedia.qualifier.precedence = htolel(127);
03860    req->data.startmedia.qualifier.vad = htolel(0);
03861    req->data.startmedia.qualifier.packets = htolel(0);
03862    req->data.startmedia.qualifier.bitRate = htolel(0);
03863    transmit_response(s, req);
03864 
03865    return 1;
03866 }

static int handle_register_available_lines_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 4236 of file chan_skinny.c.

Referenced by handle_message().

04237 {
04238    /* XXX I have no clue what this is for, but my phone was sending it, so... */
04239    return 1;
04240 }

static int handle_register_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3050 of file chan_skinny.c.

References ast_log(), ast_verbose(), CAPABILITIES_REQ_MESSAGE, skinny_req::data, register_ack_message::dateTemplate, register_rej_message::errMsg, htolel, register_ack_message::keepAlive, LOG_ERROR, register_message::name, name, option_verbose, skinny_data::reg, skinny_data::regack, REGISTER_ACK_MESSAGE, REGISTER_REJ_MESSAGE, skinny_data::regrej, req_alloc(), register_ack_message::res, skinny_req::res, register_ack_message::res2, register_ack_message::secondaryKeepAlive, skinny_register(), transmit_response(), and VERBOSE_PREFIX_3.

Referenced by handle_message().

03051 {
03052    char name[16];
03053    int res;
03054 
03055    memcpy(&name, req->data.reg.name, sizeof(name));
03056 
03057    res = skinny_register(req, s);
03058    if (!res) {
03059       ast_log(LOG_ERROR, "Rejecting Device %s: Device not found\n", name);
03060       if (!(req = req_alloc(sizeof(struct register_rej_message), REGISTER_REJ_MESSAGE)))
03061          return -1;
03062 
03063       snprintf(req->data.regrej.errMsg, sizeof(req->data.regrej.errMsg), "No Authority: %s", name);
03064       transmit_response(s, req);
03065       return 0;
03066    }
03067    ast_atomic_fetchadd_int(&unauth_sessions, -1);
03068    if (option_verbose > 2)
03069       ast_verbose(VERBOSE_PREFIX_3 "Device '%s' successfully registered\n", name);
03070 
03071    if (!(req = req_alloc(sizeof(struct register_ack_message), REGISTER_ACK_MESSAGE)))
03072       return -1;
03073 
03074    req->data.regack.res[0] = '0';
03075    req->data.regack.res[1] = '\0';
03076    req->data.regack.keepAlive = htolel(keep_alive);
03077    memcpy(req->data.regack.dateTemplate, date_format, sizeof(req->data.regack.dateTemplate));
03078    req->data.regack.res2[0] = '0';
03079    req->data.regack.res2[1] = '\0';
03080    req->data.regack.secondaryKeepAlive = htolel(keep_alive);
03081    transmit_response(s, req);
03082    if (skinnydebug)
03083       ast_verbose("Requesting capabilities\n");
03084 
03085    if (!(req = req_alloc(0, CAPABILITIES_REQ_MESSAGE)))
03086       return -1;
03087 
03088    transmit_response(s, req);
03089 
03090    return res;
03091 }

static int handle_server_request_message ( struct skinny_req req,
struct skinnysession s 
) [static]

static int handle_soft_key_event_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3950 of file chan_skinny.c.

References skinny_subchannel::alreadygone, AST_CONTROL_ANSWER, ast_hangup(), ast_ignore_pattern(), ast_log(), ast_pthread_create, ast_queue_control(), ast_queue_hangup(), ast_setstate(), AST_STATE_DOWN, AST_STATE_UP, ast_verbose(), attempt_transfer(), skinny_subchannel::callid, soft_key_event_message::callreference, ast_channel::context, skinny_subchannel::cxmode, skinny_req::data, skinnysession::device, skinny_line::dnd, do_housekeeping(), errno, event, ast_channel::exten, find_line_by_instance(), find_subchannel_by_instance_reference(), skinny_line::hookstate, skinny_line::instance, soft_key_event_message::instance, KEYDEF_CONNECTED, KEYDEF_OFFHOOK, KEYDEF_RINGOUT, skinny_device::lastcallreference, skinny_device::lastlineinstance, skinny_line::lastnumberdialed, letohl, LOG_WARNING, skinny_device::name, skinny_line::name, skinny_subchannel::next, skinny_subchannel::onhold, option_verbose, skinny_subchannel::outgoing, skinny_subchannel::owner, skinny_subchannel::rtp, SKINNY_CONNECTED, SKINNY_CX_RECVONLY, SKINNY_DIALTONE, skinny_hold(), SKINNY_LAMP_OFF, SKINNY_LAMP_ON, skinny_new(), skinny_newcall(), SKINNY_OFFHOOK, SKINNY_ONHOOK, SKINNY_RING_OFF, SKINNY_SILENCE, SKINNY_SPEAKERON, skinny_ss(), skinny_unhold(), SOFTKEY_ANSWER, SOFTKEY_BKSPC, SOFTKEY_CFWDALL, SOFTKEY_CFWDBUSY, SOFTKEY_CFWDNOANSWER, SOFTKEY_CONFRN, SOFTKEY_ENDCALL, SOFTKEY_GPICKUP, SOFTKEY_HOLD, SOFTKEY_INFO, SOFTKEY_JOIN, SOFTKEY_MEETME, SOFTKEY_NEWCALL, SOFTKEY_NONE, SOFTKEY_PARK, SOFTKEY_PICKUP, SOFTKEY_REDIAL, SOFTKEY_RESUME, SOFTKEY_TRNSFER, soft_key_event_message::softKeyEvent, skinny_data::softkeyeventmessage, start_rtp(), STIMULUS_FORWARDALL, STIMULUS_LINE, t, ast_channel::tech_pvt, skinny_line::transfer, transmit_callstate(), transmit_displaymessage(), transmit_displaynotify(), transmit_lamp_indication(), transmit_ringer_mode(), transmit_selectsoftkeys(), transmit_speaker_mode(), transmit_tone(), and VERBOSE_PREFIX_3.

Referenced by handle_message().

03951 {
03952    struct skinny_device *d = s->device;
03953    struct skinny_line *l;
03954    struct skinny_subchannel *sub = NULL;
03955    struct ast_channel *c;
03956    pthread_t t;
03957    int event;
03958    int instance;
03959    int callreference;
03960 
03961    event = letohl(req->data.softkeyeventmessage.softKeyEvent);
03962    instance = letohl(req->data.softkeyeventmessage.instance);
03963    callreference = letohl(req->data.softkeyeventmessage.callreference);
03964 
03965    if (instance) {
03966       l = find_line_by_instance(d, instance);
03967       if (callreference) {
03968          sub = find_subchannel_by_instance_reference(d, instance, callreference);
03969       } else {
03970          sub = find_subchannel_by_instance_reference(d, instance, d->lastcallreference);
03971       }
03972    } else {
03973       l = find_line_by_instance(d, d->lastlineinstance);
03974    }
03975 
03976    if (!l) {
03977       if (skinnydebug)
03978          ast_verbose("Received Softkey Event: %d(%d/%d)\n", event, instance, callreference);
03979       return 0;
03980    }
03981 
03982    switch(event) {
03983    case SOFTKEY_NONE:
03984       if (skinnydebug)
03985          ast_verbose("Received Softkey Event: None(%d/%d)\n", instance, callreference);
03986       break;
03987    case SOFTKEY_REDIAL:
03988       if (skinnydebug)
03989          ast_verbose("Received Softkey Event: Redial(%d/%d)\n", instance, callreference);
03990 
03991 #if 0
03992       if (!sub || !sub->owner) {
03993          c = skinny_new(l, AST_STATE_DOWN);
03994       } else {
03995          c = sub->owner;
03996       }
03997 
03998       if(!c) {
03999          ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
04000       } else {
04001          sub = c->tech_pvt;
04002          transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
04003          if (skinnydebug)
04004             ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, d->name);
04005          transmit_displaymessage(s, NULL, l->instance, sub->callid); /* clear display */
04006          transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
04007          transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_RINGOUT);
04008 
04009          if (!ast_ignore_pattern(c->context, l->lastnumberdialed)) {
04010             transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
04011          }
04012          ast_copy_string(c->exten, l->lastnumberdialed, sizeof(c->exten));
04013          if (ast_pthread_create(&t, NULL, skinny_newcall, c)) {
04014             ast_log(LOG_WARNING, "Unable to create new call thread: %s\n", strerror(errno));
04015             ast_hangup(c);
04016          }
04017       }
04018 #endif
04019       break;
04020    case SOFTKEY_NEWCALL:  /* Actually the DIAL softkey */
04021       if (skinnydebug)
04022          ast_verbose("Received Softkey Event: New Call(%d/%d)\n", instance, callreference);
04023 
04024       if (!sub || !sub->owner) {
04025          c = skinny_new(l, AST_STATE_DOWN);
04026       } else {
04027          c = sub->owner;
04028       }
04029 
04030       if (!c) {
04031          ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
04032       } else {
04033          sub = c->tech_pvt;
04034          if (l->hookstate == SKINNY_ONHOOK) {
04035             l->hookstate = SKINNY_OFFHOOK;
04036             transmit_speaker_mode(s, SKINNY_SPEAKERON);
04037             transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
04038          }
04039 
04040          if (skinnydebug)
04041             ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, d->name);
04042          transmit_displaymessage(s, NULL, l->instance, sub->callid); /* clear display */
04043          transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
04044          transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_OFFHOOK);
04045 
04046          /* start the switch thread */
04047          if (ast_pthread_create(&t, NULL, skinny_ss, c)) {
04048             ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
04049             ast_hangup(c);
04050          }
04051       }
04052       break;
04053    case SOFTKEY_HOLD:
04054       if (skinnydebug)
04055          ast_verbose("Received Softkey Event: Hold(%d/%d)\n", instance, callreference);
04056 
04057       if (sub) {
04058          if (sub->onhold) {
04059             skinny_unhold(sub);
04060          } else {
04061             skinny_hold(sub);
04062          }
04063       }
04064             
04065       break;
04066    case SOFTKEY_TRNSFER:
04067       if (skinnydebug)
04068          ast_verbose("Received Softkey Event: Transfer(%d/%d)\n", instance, callreference);
04069       /* XXX figure out how to transfer */
04070       break;
04071    case SOFTKEY_CFWDALL:
04072       if (skinnydebug)
04073          ast_verbose("Received Softkey Event: Forward All(%d/%d)\n", instance, callreference);
04074 
04075       /* Do not disturb */
04076       if (l->dnd != 0){
04077          if (option_verbose > 2)
04078             ast_verbose(VERBOSE_PREFIX_3 "Disabling DND on %s@%s\n", l->name, d->name);
04079          l->dnd = 0;
04080          transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_ON);
04081          transmit_displaynotify(s, "DnD disabled", 10);
04082       } else {
04083          if (option_verbose > 2)
04084             ast_verbose(VERBOSE_PREFIX_3 "Enabling DND on %s@%s\n", l->name, d->name);
04085          l->dnd = 1;
04086          transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_OFF);
04087          transmit_displaynotify(s, "DnD enabled", 10);
04088       }
04089       break;
04090    case SOFTKEY_CFWDBUSY:
04091       if (skinnydebug)
04092          ast_verbose("Received Softkey Event: Forward Busy (%d/%d)\n", instance, callreference);
04093       break;
04094    case SOFTKEY_CFWDNOANSWER:
04095       if (skinnydebug)
04096          ast_verbose("Received Softkey Event: Forward No Answer (%d/%d)\n", instance, callreference);
04097       break;
04098    case SOFTKEY_BKSPC:
04099       if (skinnydebug)
04100          ast_verbose("Received Softkey Event: Backspace(%d/%d)\n", instance, callreference);
04101       break;
04102    case SOFTKEY_ENDCALL:
04103       if (skinnydebug)
04104          ast_verbose("Received Softkey Event: End Call(%d/%d)\n", instance, callreference);
04105 
04106       if (l->hookstate == SKINNY_ONHOOK) {
04107          /* Something else already put us back on hook */
04108          break;
04109       }
04110       if (sub) {
04111          sub->cxmode = SKINNY_CX_RECVONLY;
04112          l->hookstate = SKINNY_ONHOOK;
04113          transmit_callstate(s, l->instance, l->hookstate, sub->callid);
04114          if (skinnydebug)
04115             ast_verbose("Skinny %s@%s went on hook\n", l->name, d->name);
04116          if (l->transfer && (sub->owner && sub->next && sub->next->owner) && ((!sub->outgoing) || (sub->next && !sub->next->outgoing))) {
04117             /* We're allowed to transfer, we have two active calls and
04118                we made at least one of the calls.  Let's try and transfer */
04119 
04120 #if 0
04121             if ((res = attempt_transfer(p)) < 0) {
04122                if (sub->next && sub->next->owner) {
04123                   sub->next->alreadygone = 1;
04124                   ast_queue_hangup(sub->next->owner, 1);
04125                }
04126             } else if (res) {
04127                ast_log(LOG_WARNING, "Transfer attempt failed\n");
04128                break;
04129             }
04130 #endif
04131          } else {
04132             /* Hangup the current call */
04133             /* If there is another active call, skinny_hangup will ring the phone with the other call */
04134             if (sub->owner) {
04135                sub->alreadygone = 1;
04136                ast_queue_hangup(sub->owner);
04137             } else {
04138                ast_log(LOG_WARNING, "Skinny(%s@%s-%d) channel already destroyed\n",
04139                   l->name, d->name, sub->callid);
04140             }
04141          }
04142          if ((l->hookstate == SKINNY_ONHOOK) && (sub->next && !sub->next->rtp)) {
04143             do_housekeeping(s);
04144          }
04145       }
04146       break;
04147    case SOFTKEY_RESUME:
04148       if (skinnydebug)
04149          ast_verbose("Received Softkey Event: Resume(%d/%d)\n", instance, callreference);
04150       break;
04151    case SOFTKEY_ANSWER:
04152       if (skinnydebug)
04153          ast_verbose("Received Softkey Event: Answer(%d/%d)\n", instance, callreference);
04154 
04155       transmit_ringer_mode(s,SKINNY_RING_OFF);
04156       transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
04157 
04158       l->hookstate = SKINNY_OFFHOOK;
04159 
04160       if (sub && sub->outgoing) {
04161          /* We're answering a ringing call */
04162          ast_queue_control(sub->owner, AST_CONTROL_ANSWER);
04163          transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
04164          transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
04165          transmit_callstate(s, l->instance, SKINNY_CONNECTED, sub->callid);
04166          transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_CONNECTED);
04167          start_rtp(sub);
04168          ast_setstate(sub->owner, AST_STATE_UP);
04169       }
04170       break;
04171    case SOFTKEY_INFO:
04172       if (skinnydebug)
04173          ast_verbose("Received Softkey Event: Info(%d/%d)\n", instance, callreference);
04174       break;
04175    case SOFTKEY_CONFRN:
04176       if (skinnydebug)
04177          ast_verbose("Received Softkey Event: Conference(%d/%d)\n", instance, callreference);
04178       /* XXX determine the best way to pull off a conference.  Meetme? */
04179       break;
04180    case SOFTKEY_PARK:
04181       if (skinnydebug)
04182          ast_verbose("Received Softkey Event: Park Call(%d/%d)\n", instance, callreference);
04183       /* XXX Park the call */
04184       break;
04185    case SOFTKEY_JOIN:
04186       if (skinnydebug)
04187          ast_verbose("Received Softkey Event: Join(%d/%d)\n", instance, callreference);
04188       break;
04189    case SOFTKEY_MEETME:
04190       /* XXX How is this different from CONFRN? */
04191       if (skinnydebug)
04192          ast_verbose("Received Softkey Event: Meetme(%d/%d)\n", instance, callreference);
04193       break;
04194    case SOFTKEY_PICKUP:
04195       if (skinnydebug)
04196          ast_verbose("Received Softkey Event: Pickup(%d/%d)\n", instance, callreference);
04197       break;
04198    case SOFTKEY_GPICKUP:
04199       if (skinnydebug)
04200          ast_verbose("Received Softkey Event: Group Pickup(%d/%d)\n", instance, callreference);
04201       break;
04202    default:
04203       if (skinnydebug)
04204          ast_verbose("Received unknown Softkey Event: %d(%d/%d)\n", event, instance, callreference);
04205       break;
04206    }
04207    return 1;
04208 }

static int handle_soft_key_set_req_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3918 of file chan_skinny.c.

References soft_key_definitions::count, skinny_req::data, soft_key_definitions::defaults, htolel, KEYDEF_ONHOOK, soft_key_definitions::mode, req_alloc(), SOFT_KEY_SET_RES_MESSAGE, soft_key_set_definition::softKeyInfoIndex, soft_key_set_res_message::softKeySetCount, soft_key_set_res_message::softKeySetDefinition, soft_key_set_res_message::softKeySetOffset, skinny_data::softkeysets, soft_key_set_definition::softKeyTemplateIndex, soft_key_set_res_message::totalSoftKeySetCount, transmit_response(), and transmit_selectsoftkeys().

Referenced by handle_message().

03919 {
03920    int i;
03921    int x;
03922    int y;
03923    const struct soft_key_definitions *softkeymode = soft_key_default_definitions;
03924 
03925    if (!(req = req_alloc(sizeof(struct soft_key_set_res_message), SOFT_KEY_SET_RES_MESSAGE)))
03926       return -1;
03927 
03928    req->data.softkeysets.softKeySetOffset = htolel(0);
03929    req->data.softkeysets.softKeySetCount = htolel(11);
03930    req->data.softkeysets.totalSoftKeySetCount = htolel(11);
03931    for (x = 0; x < sizeof(soft_key_default_definitions) / sizeof(struct soft_key_definitions); x++) {
03932       const uint8_t *defaults = softkeymode->defaults;
03933       /* XXX I wanted to get the size of the array dynamically, but that wasn't wanting to work.
03934          This will have to do for now. */
03935       for (y = 0; y < softkeymode->count; y++) {
03936          for (i = 0; i < (sizeof(soft_key_template_default) / sizeof(struct soft_key_template_definition)); i++) {
03937             if (defaults[y] == i+1) {
03938                req->data.softkeysets.softKeySetDefinition[softkeymode->mode].softKeyTemplateIndex[y] = htolel(i+1);
03939                req->data.softkeysets.softKeySetDefinition[softkeymode->mode].softKeyInfoIndex[y] = htolel(i+301);
03940             }
03941          }
03942       }
03943       softkeymode++;
03944    }
03945    transmit_response(s,req);
03946    transmit_selectsoftkeys(s, 0, 0, KEYDEF_ONHOOK);
03947    return 1;
03948 }

static int handle_soft_key_template_req_message ( struct skinny_req req,
struct skinnysession s 
) [static]

static int handle_speed_dial_stat_req_message ( struct skinny_req req,
struct skinnysession s 
) [static]

static int handle_stimulus_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3169 of file chan_skinny.c.

References AST_CONTROL_ANSWER, ast_exists_extension(), ast_hangup(), ast_ignore_pattern(), ast_log(), ast_matchmore_extension(), ast_pthread_create, ast_queue_control(), ast_setstate(), AST_STATE_DOWN, AST_STATE_UP, ast_strlen_zero(), ast_verbose(), skinny_subchannel::callid, stimulus_message::callreference, skinny_line::cid_num, ast_channel::context, skinny_req::data, skinnysession::device, skinny_line::dnd, errno, event, ast_channel::exten, find_line_by_instance(), find_speeddial_by_instance(), find_subchannel_by_instance_reference(), skinny_line::hookstate, skinny_line::instance, KEYDEF_CONNECTED, KEYDEF_OFFHOOK, KEYDEF_RINGOUT, skinny_device::lastcallreference, skinny_device::lastlineinstance, skinny_line::lastnumberdialed, letohl, LOG_DEBUG, LOG_WARNING, skinny_device::name, skinny_line::name, skinny_subchannel::onhold, option_verbose, skinny_subchannel::outgoing, skinny_subchannel::owner, skinny_subchannel::parent, SKINNY_CONNECTED, SKINNY_DIALTONE, skinny_hold(), SKINNY_LAMP_OFF, SKINNY_LAMP_ON, skinny_new(), skinny_newcall(), SKINNY_OFFHOOK, SKINNY_ONHOOK, SKINNY_RING_OFF, SKINNY_SILENCE, SKINNY_SPEAKEROFF, SKINNY_SPEAKERON, skinny_ss(), skinny_unhold(), start_rtp(), stimulus_message::stimulus, skinny_data::stimulus, STIMULUS_CALLPARK, STIMULUS_CONFERENCE, STIMULUS_DISPLAY, STIMULUS_FORWARDALL, STIMULUS_FORWARDBUSY, STIMULUS_FORWARDNOANSWER, STIMULUS_HOLD, STIMULUS_LINE, STIMULUS_REDIAL, STIMULUS_SPEEDDIAL, STIMULUS_TRANSFER, STIMULUS_VOICEMAIL, stimulus_message::stimulusInstance, t, ast_channel::tech_pvt, transmit_callstate(), transmit_displaymessage(), transmit_displaynotify(), transmit_displaypromptstatus(), transmit_lamp_indication(), transmit_ringer_mode(), transmit_selectsoftkeys(), transmit_speaker_mode(), transmit_tone(), and VERBOSE_PREFIX_3.

Referenced by handle_message().

03170 {
03171    struct skinny_device *d = s->device;
03172    struct skinny_line *l;
03173    struct skinny_subchannel *sub;
03174    /*struct skinny_speeddial *sd;*/
03175    struct ast_channel *c;
03176    pthread_t t;
03177    int event;
03178    int instance;
03179    int callreference;
03180    /*int res = 0;*/
03181 
03182    event = letohl(req->data.stimulus.stimulus);
03183    instance = letohl(req->data.stimulus.stimulusInstance);
03184    callreference = letohl(req->data.stimulus.callreference); 
03185    if (skinnydebug)
03186       ast_verbose("callreference in handle_stimulus_message is '%d'\n", callreference);
03187 
03188    /*  Note that this call should be using the passed in instance and callreference */
03189    sub = find_subchannel_by_instance_reference(d, d->lastlineinstance, d->lastcallreference);
03190 
03191    if (!sub) {
03192       l = find_line_by_instance(d, d->lastlineinstance);
03193       if (!l) {
03194          return 0;
03195       }
03196    } else {
03197       l = sub->parent;
03198    }
03199 
03200    switch(event) {
03201    case STIMULUS_REDIAL:
03202       if (skinnydebug)
03203          ast_verbose("Received Stimulus: Redial(%d/%d)\n", instance, callreference);
03204 
03205 #if 0
03206       if (ast_strlen_zero(l->lastnumberdialed)) {
03207          ast_log(LOG_WARNING, "Attempted redial, but no previously dialed number found.\n");
03208          l->hookstate = SKINNY_ONHOOK;
03209          transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
03210          transmit_callstate(s, l->instance, SKINNY_ONHOOK, instance);
03211          break;
03212       }
03213 
03214       c = skinny_new(l, AST_STATE_DOWN);
03215       if(!c) {
03216          ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
03217       } else {
03218          sub = c->tech_pvt;
03219          transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
03220          if (skinnydebug)
03221             ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, d->name);
03222          transmit_displaymessage(s, NULL, l->instance, sub->callid); /* clear display */
03223          transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
03224          transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_RINGOUT);
03225 
03226          if (!ast_ignore_pattern(c->context, l->lastnumberdialed)) {
03227             transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
03228          }
03229          ast_copy_string(c->exten, l->lastnumberdialed, sizeof(c->exten));
03230          if (ast_pthread_create(&t, NULL, skinny_newcall, c)) {
03231             ast_log(LOG_WARNING, "Unable to create new call thread: %s\n", strerror(errno));
03232             ast_hangup(c);
03233          }
03234       }
03235 #endif
03236       break;
03237    case STIMULUS_SPEEDDIAL:
03238       if (skinnydebug)
03239          ast_verbose("Received Stimulus: SpeedDial(%d/%d)\n", instance, callreference);
03240 
03241 #if 0
03242       if (!(sd = find_speeddial_by_instance(d, instance))) {
03243          return 0;
03244       }
03245 
03246       if (ast_strlen_zero(l->lastnumberdialed)) {
03247          ast_log(LOG_WARNING, "Attempted redial, but no previously dialed number found.\n");
03248          l->hookstate = SKINNY_ONHOOK;
03249          transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
03250          transmit_callstate(s, l->instance, SKINNY_ONHOOK, instance);
03251          break;
03252       }
03253 
03254       c = skinny_new(l, AST_STATE_DOWN);
03255       if(c) {
03256          sub = c->tech_pvt;
03257          l = sub->parent;
03258          transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
03259          if (skinnydebug)
03260             ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, d->name);
03261          transmit_displaymessage(s, NULL, l->instance, sub->callid); /* clear display */
03262          transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
03263          transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_RINGOUT);
03264 
03265          if (!ast_ignore_pattern(c->context, sd->exten)) {
03266             transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
03267          }
03268          if (ast_exists_extension(c, c->context, sd->exten, 1, l->cid_num)) {
03269             if (!ast_matchmore_extension(c, c->context, sd->exten, 1, l->cid_num)) {
03270                ast_copy_string(c->exten, sd->exten, sizeof(c->exten));
03271                ast_copy_string(l->lastnumberdialed, sd->exten, sizeof(l->lastnumberdialed));
03272                skinny_newcall(c);
03273                break;
03274             }
03275          }
03276       } else {
03277          ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
03278       }
03279 #endif
03280       break;
03281    case STIMULUS_HOLD:
03282       if (skinnydebug)
03283          ast_verbose("Received Stimulus: Hold(%d/%d)\n", instance, callreference);
03284 
03285       if (!sub)
03286          break;
03287 
03288       if (sub->onhold) {
03289          skinny_unhold(sub);
03290       } else {
03291          skinny_hold(sub);
03292       }
03293       break;
03294    case STIMULUS_TRANSFER:
03295       if (skinnydebug)
03296          ast_verbose("Received Stimulus: Transfer(%d/%d)\n", instance, callreference);
03297       /* XXX figure out how to transfer */
03298       break;
03299    case STIMULUS_CONFERENCE:
03300       if (skinnydebug)
03301          ast_verbose("Received Stimulus: Conference(%d/%d)\n", instance, callreference);
03302       /* XXX determine the best way to pull off a conference.  Meetme? */
03303       break;
03304    case STIMULUS_VOICEMAIL:
03305       if (skinnydebug)
03306          ast_verbose("Received Stimulus: Voicemail(%d/%d)\n", instance, callreference);
03307       /* XXX Find and dial voicemail extension */
03308       break;
03309    case STIMULUS_CALLPARK:
03310       if (skinnydebug)
03311          ast_verbose("Received Stimulus: Park Call(%d/%d)\n", instance, callreference);
03312       /* XXX Park the call */
03313       break;
03314    case STIMULUS_FORWARDALL:
03315       if (skinnydebug)
03316          ast_verbose("Received Stimulus: Forward All(%d/%d)\n", instance, callreference);
03317       /* Why is DND under FORWARDALL? */
03318       /* Because it's the same thing. */
03319 
03320       /* Do not disturb */
03321       if (l->dnd != 0){
03322          if (option_verbose > 2)
03323             ast_verbose(VERBOSE_PREFIX_3 "Disabling DND on %s@%s\n", l->name, d->name);
03324          l->dnd = 0;
03325          transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_ON);
03326          transmit_displaynotify(s, "DnD disabled", 10);
03327       } else {
03328          if (option_verbose > 2)
03329             ast_verbose(VERBOSE_PREFIX_3 "Enabling DND on %s@%s\n", l->name, d->name);
03330          l->dnd = 1;
03331          transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_OFF);
03332          transmit_displaynotify(s, "DnD enabled", 10);
03333       }
03334       break;
03335    case STIMULUS_FORWARDBUSY:
03336       if (skinnydebug)
03337          ast_verbose("Received Stimulus: Forward Busy (%d/%d)\n", instance, callreference);
03338       break;
03339    case STIMULUS_FORWARDNOANSWER:
03340       if (skinnydebug)
03341          ast_verbose("Received Stimulus: Forward No Answer (%d/%d)\n", instance, callreference);
03342       break;
03343    case STIMULUS_DISPLAY:
03344       /* Not sure what this is */
03345       if (skinnydebug)
03346          ast_verbose("Received Stimulus: Display(%d/%d)\n", instance, callreference);
03347       break;
03348    case STIMULUS_LINE:
03349       if (skinnydebug)
03350          ast_verbose("Received Stimulus: Line(%d/%d)\n", instance, callreference);
03351 
03352       l = find_line_by_instance(s->device, instance);
03353 
03354       if (!l) {
03355          return 0;
03356       }
03357 
03358       /* turn the speaker on */
03359       transmit_speaker_mode(s, SKINNY_SPEAKERON);
03360       transmit_ringer_mode(s, SKINNY_RING_OFF);
03361       transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
03362 
03363       l->hookstate = SKINNY_OFFHOOK;
03364 
03365       if (sub && sub->outgoing) {
03366          /* We're answering a ringing call */
03367          ast_queue_control(sub->owner, AST_CONTROL_ANSWER);
03368          transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
03369          transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
03370          transmit_callstate(s, l->instance, SKINNY_CONNECTED, sub->callid);
03371          transmit_displaypromptstatus(s, "Connected", 0, l->instance, sub->callid);
03372          transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_CONNECTED);
03373          start_rtp(sub);
03374          ast_setstate(sub->owner, AST_STATE_UP);
03375       } else {
03376          if (sub && sub->owner) {
03377             ast_log(LOG_DEBUG, "Current subchannel [%s] already has owner\n", sub->owner->name);
03378          } else {
03379             c = skinny_new(l, AST_STATE_DOWN);
03380             if(c) {
03381                sub = c->tech_pvt;
03382                transmit_callstate(s, l->instance, SKINNY_OFFHOOK, sub->callid);
03383                if (skinnydebug)
03384                   ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, d->name);
03385                transmit_displaymessage(s, NULL, l->instance, sub->callid); /* clear display */
03386                transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
03387                transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_OFFHOOK);
03388 
03389                /* start the switch thread */
03390                if (ast_pthread_create(&t, NULL, skinny_ss, c)) {
03391                   ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
03392                   ast_hangup(c);
03393                }
03394             } else {
03395                ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
03396             }
03397          }
03398       }
03399       break;
03400    default:
03401       if (skinnydebug)
03402          ast_verbose("RECEIVED UNKNOWN STIMULUS:  %d(%d/%d)\n", event, instance, callreference);
03403       break;
03404    }
03405    return 1;
03406 }

static int handle_time_date_req_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3631 of file chan_skinny.c.

References skinny_req::data, definetimedate_message::day, definetimedate_message::dayofweek, skinny_data::definetimedate, DEFINETIMEDATE_MESSAGE, definetimedate_message::hour, htolel, definetimedate_message::milliseconds, definetimedate_message::minute, definetimedate_message::month, req_alloc(), definetimedate_message::seconds, definetimedate_message::timestamp, transmit_response(), and definetimedate_message::year.

Referenced by do_housekeeping(), and handle_message().

03632 {
03633    time_t timer;
03634    struct tm *cmtime;
03635 
03636    if (!(req = req_alloc(sizeof(struct definetimedate_message), DEFINETIMEDATE_MESSAGE)))
03637       return -1;
03638 
03639    timer = time(NULL);
03640    cmtime = localtime(&timer);
03641    req->data.definetimedate.year = htolel(cmtime->tm_year+1900);
03642    req->data.definetimedate.month = htolel(cmtime->tm_mon+1);
03643    req->data.definetimedate.dayofweek = htolel(cmtime->tm_wday);
03644    req->data.definetimedate.day = htolel(cmtime->tm_mday);
03645    req->data.definetimedate.hour = htolel(cmtime->tm_hour);
03646    req->data.definetimedate.minute = htolel(cmtime->tm_min);
03647    req->data.definetimedate.seconds = htolel(cmtime->tm_sec);
03648    req->data.definetimedate.milliseconds = htolel(0);
03649    req->data.definetimedate.timestamp = htolel(timer);
03650    transmit_response(s, req);
03651    return 1;
03652 }

static int handle_unregister_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 4210 of file chan_skinny.c.

References skinny_unregister().

Referenced by handle_message().

04211 {
04212    return skinny_unregister(req, s);
04213 }

static int handle_version_req_message ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 3765 of file chan_skinny.c.

References skinny_req::data, skinnysession::device, req_alloc(), transmit_response(), version_res_message::version, skinny_data::version, skinny_device::version_id, and VERSION_RES_MESSAGE.

Referenced by handle_message().

03766 {
03767    struct skinny_device *d = s->device;
03768    if (!(req = req_alloc(sizeof(struct version_res_message), VERSION_RES_MESSAGE)))
03769       return -1;
03770 
03771    snprintf(req->data.version.version, sizeof(req->data.version.version), d->version_id);
03772    transmit_response(s, req);
03773    return 1;
03774 }

static int load_module ( void   )  [static]

Definition at line 4973 of file chan_skinny.c.

References ast_channel_register(), ast_cli_register_multiple(), ast_log(), AST_MODULE_LOAD_DECLINE, ast_rtp_proto_register(), htolel, io_context_create(), LOG_ERROR, LOG_WARNING, reload_config(), restart_monitor(), sched_context_create(), and soft_key_template_definition::softKeyEvent.

04974 {
04975    int res = 0;
04976 
04977    for (; res < (sizeof(soft_key_template_default) / sizeof(soft_key_template_default[0])); res++) {
04978       soft_key_template_default[res].softKeyEvent = htolel(soft_key_template_default[res].softKeyEvent);
04979    }
04980    /* load and parse config */
04981    res = reload_config();
04982    if (res == -1) {
04983       return AST_MODULE_LOAD_DECLINE;
04984    }
04985 
04986    /* Make sure we can register our skinny channel type */
04987    if (ast_channel_register(&skinny_tech)) {
04988       ast_log(LOG_ERROR, "Unable to register channel class 'Skinny'\n");
04989       return -1;
04990    }
04991 
04992    ast_rtp_proto_register(&skinny_rtp);
04993    ast_cli_register_multiple(cli_skinny, sizeof(cli_skinny) / sizeof(struct ast_cli_entry));
04994    sched = sched_context_create();
04995    if (!sched) {
04996       ast_log(LOG_WARNING, "Unable to create schedule context\n");
04997    }
04998    io = io_context_create();
04999    if (!io) {
05000       ast_log(LOG_WARNING, "Unable to create I/O context\n");
05001    }
05002    /* And start the monitor for the first time */
05003    restart_monitor();
05004 
05005    return res;
05006 }

static int reload_config ( void   )  [static]

Todo:
Remove 'port' option after 1.4

Definition at line 4754 of file chan_skinny.c.

References __ourip, accept_thread(), ahp, 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_parse_allow_disallow(), ast_pthread_create_background, ast_variable_browse(), ast_verbose(), bindaddr, build_device(), DEFAULT_AUTH_LIMIT, DEFAULT_AUTH_TIMEOUT, default_prefs, DEFAULT_SKINNY_BACKLOG, DEFAULT_SKINNY_PORT, devices, errno, global_jbconf, ast_variable::lineno, LOG_ERROR, LOG_NOTICE, LOG_WARNING, skinny_device::name, ast_variable::name, skinny_device::next, ast_variable::next, option_verbose, ast_variable::value, VERBOSE_PREFIX_2, and VERBOSE_PREFIX_3.

04755 {
04756    int on = 1;
04757    struct ast_config *cfg;
04758    struct ast_variable *v;
04759    char *cat;
04760    struct skinny_device *d;
04761    int oldport = ntohs(bindaddr.sin_port);
04762 
04763    if (gethostname(ourhost, sizeof(ourhost))) {
04764       ast_log(LOG_WARNING, "Unable to get hostname, Skinny disabled\n");
04765       return 0;
04766    }
04767    cfg = ast_config_load(config);
04768 
04769    /* We *must* have a config file otherwise stop immediately */
04770    if (!cfg) {
04771       ast_log(LOG_NOTICE, "Unable to load config %s, Skinny disabled\n", config);
04772       return -1;
04773    }
04774    memset(&bindaddr, 0, sizeof(bindaddr));
04775    memset(&default_prefs, 0, sizeof(default_prefs));
04776 
04777    /* Copy the default jb config over global_jbconf */
04778    memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
04779 
04780    /* load the general section */
04781    v = ast_variable_browse(cfg, "general");
04782    while (v) {
04783       /* handle jb conf */
04784       if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) {
04785          v = v->next;
04786          continue;
04787       }
04788 
04789       /* Create the interface list */
04790       if (!strcasecmp(v->name, "bindaddr")) {
04791          if (!(hp = ast_gethostbyname(v->value, &ahp))) {
04792             ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
04793          } else {
04794             memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
04795          }
04796       } else if (!strcasecmp(v->name, "keepalive")) {
04797          keep_alive = atoi(v->value);
04798       } else if (!strcasecmp(v->name, "authtimeout")) {
04799          int timeout = atoi(v->value);
04800 
04801          if (timeout < 1) {
04802             ast_log(LOG_WARNING, "Invalid authtimeout value '%s', using default value\n", v->value);
04803             auth_timeout = DEFAULT_AUTH_TIMEOUT;
04804          } else {
04805             auth_timeout = timeout;
04806          }
04807       } else if (!strcasecmp(v->name, "authlimit")) {
04808          int limit = atoi(v->value);
04809 
04810          if (limit < 1) {
04811             ast_log(LOG_WARNING, "Invalid authlimit value '%s', using default value\n", v->value);
04812             auth_limit = DEFAULT_AUTH_LIMIT;
04813          } else {
04814             auth_limit = limit;
04815          }
04816       } else if (!strcasecmp(v->name, "dateformat")) {
04817          memcpy(date_format, v->value, sizeof(date_format));
04818       } else if (!strcasecmp(v->name, "allow")) {
04819          ast_parse_allow_disallow(&default_prefs, &default_capability, v->value, 1);
04820       } else if (!strcasecmp(v->name, "disallow")) {
04821          ast_parse_allow_disallow(&default_prefs, &default_capability, v->value, 0);
04822       } else if (!strcasecmp(v->name, "bindport") || !strcasecmp(v->name, "port")) {
04823          if (sscanf(v->value, "%d", &ourport) == 1) {
04824             bindaddr.sin_port = htons(ourport);
04825          } else {
04826             ast_log(LOG_WARNING, "Invalid bindport '%s' at line %d of %s\n", v->value, v->lineno, config);
04827          }
04828          if (!strcasecmp(v->name, "port")) { /*! \todo Remove 'port' option after 1.4 */
04829             ast_log(LOG_WARNING, "Option 'port' at line %d of %s has been deprecated.  Please use 'bindport' instead.\n", v->lineno, config);
04830          }
04831       }
04832       v = v->next;
04833    }
04834 
04835    if (ntohl(bindaddr.sin_addr.s_addr)) {
04836       __ourip = bindaddr.sin_addr;
04837    } else {
04838       hp = ast_gethostbyname(ourhost, &ahp);
04839       if (!hp) {
04840          ast_log(LOG_WARNING, "Unable to get our IP address, Skinny disabled\n");
04841          ast_config_destroy(cfg);
04842          return 0;
04843       }
04844       memcpy(&__ourip, hp->h_addr, sizeof(__ourip));
04845    }
04846    if (!ntohs(bindaddr.sin_port)) {
04847       bindaddr.sin_port = ntohs(DEFAULT_SKINNY_PORT);
04848    }
04849    bindaddr.sin_family = AF_INET;
04850 
04851    /* load the device sections */
04852    cat = ast_category_browse(cfg, NULL);
04853    while(cat) {
04854       if (!strcasecmp(cat, "general")) {
04855          /* Nothing to do */
04856 #if 0
04857       } else if (!strncasecmp(cat, "paging-", 7)) {
04858          p = build_paging_device(cat, ast_variable_browse(cfg, cat));
04859          if (p) {
04860          }
04861 #endif
04862       } else {
04863          d = build_device(cat, ast_variable_browse(cfg, cat));
04864          if (d) {
04865             if (option_verbose > 2)
04866                ast_verbose(VERBOSE_PREFIX_3 "Added device '%s'\n", d->name);
04867             ast_mutex_lock(&devicelock);
04868             d->next = devices;
04869             devices = d;
04870             ast_mutex_unlock(&devicelock);
04871          }
04872       }
04873       cat = ast_category_browse(cfg, cat);
04874    }
04875    ast_mutex_lock(&netlock);
04876    if ((skinnysock > -1) && (ntohs(bindaddr.sin_port) != oldport)) {
04877       close(skinnysock);
04878       skinnysock = -1;
04879    }
04880    if (skinnysock < 0) {
04881       skinnysock = socket(AF_INET, SOCK_STREAM, 0);
04882       if(setsockopt(skinnysock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
04883          ast_log(LOG_ERROR, "Set Socket Options failed: errno %d, %s\n", errno, strerror(errno));
04884          ast_config_destroy(cfg);
04885          return 0;
04886       }
04887       if (skinnysock < 0) {
04888          ast_log(LOG_WARNING, "Unable to create Skinny socket: %s\n", strerror(errno));
04889       } else {
04890          if (bind(skinnysock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
04891             ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n",
04892                   ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port),
04893                      strerror(errno));
04894             close(skinnysock);
04895             skinnysock = -1;
04896             ast_config_destroy(cfg);
04897             return 0;
04898          }
04899          if (listen(skinnysock,DEFAULT_SKINNY_BACKLOG)) {
04900                ast_log(LOG_WARNING, "Failed to start listening to %s:%d: %s\n",
04901                   ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port),
04902                      strerror(errno));
04903                close(skinnysock);
04904                skinnysock = -1;
04905                ast_config_destroy(cfg);
04906                return 0;
04907          }
04908          if (option_verbose > 1)
04909             ast_verbose(VERBOSE_PREFIX_2 "Skinny listening on %s:%d\n",
04910                ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port));
04911          ast_pthread_create_background(&accept_t,NULL, accept_thread, NULL);
04912       }
04913    }
04914    ast_mutex_unlock(&netlock);
04915    ast_config_destroy(cfg);
04916    return 1;
04917 }

static struct skinny_req* req_alloc ( size_t  size,
int  response_message 
) [static, read]

static int restart_monitor ( void   )  [static]

Definition at line 4690 of file chan_skinny.c.

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

04691 {
04692    /* If we're supposed to be stopped -- stay stopped */
04693    if (monitor_thread == AST_PTHREADT_STOP)
04694       return 0;
04695 
04696    ast_mutex_lock(&monlock);
04697    if (monitor_thread == pthread_self()) {
04698       ast_mutex_unlock(&monlock);
04699       ast_log(LOG_WARNING, "Cannot kill myself\n");
04700       return -1;
04701    }
04702    if (monitor_thread != AST_PTHREADT_NULL) {
04703       /* Wake up the thread */
04704       pthread_kill(monitor_thread, SIGURG);
04705    } else {
04706       /* Start a new monitor */
04707       if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
04708          ast_mutex_unlock(&monlock);
04709          ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
04710          return -1;
04711       }
04712    }
04713    ast_mutex_unlock(&monlock);
04714    return 0;
04715 }

static int skinny_answer ( struct ast_channel ast  )  [static]

Definition at line 2586 of file chan_skinny.c.

References ast_channel::_state, AST_MAX_EXTENSION, ast_setstate(), AST_STATE_UP, ast_verbose(), skinny_subchannel::callid, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, skinny_subchannel::cxmode, ast_channel::exten, exten, skinny_line::instance, KEYDEF_CONNECTED, ast_channel::macroexten, skinny_device::name, skinny_line::name, skinny_line::parent, skinny_subchannel::parent, skinny_subchannel::rtp, s, S_OR, skinny_device::session, SKINNY_CONNECTED, SKINNY_CX_SENDRECV, SKINNY_SILENCE, start_rtp(), ast_channel::tech_pvt, transmit_callinfo(), transmit_callstate(), transmit_dialednumber(), transmit_displaypromptstatus(), transmit_selectsoftkeys(), and transmit_tone().

02587 {
02588    int res = 0;
02589    struct skinny_subchannel *sub = ast->tech_pvt;
02590    struct skinny_line *l = sub->parent;
02591    struct skinny_device *d = l->parent;
02592    struct skinnysession *s = d->session;
02593    char exten[AST_MAX_EXTENSION] = "";
02594 
02595    ast_copy_string(exten, S_OR(ast->macroexten, ast->exten), sizeof(exten));
02596 
02597    sub->cxmode = SKINNY_CX_SENDRECV;
02598    if (!sub->rtp) {
02599       start_rtp(sub);
02600    }
02601    if (skinnydebug)
02602       ast_verbose("skinny_answer(%s) on %s@%s-%d\n", ast->name, l->name, d->name, sub->callid);
02603    if (ast->_state != AST_STATE_UP) {
02604       ast_setstate(ast, AST_STATE_UP);
02605    }
02606 
02607    transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
02608    /* order matters here...
02609       for some reason, transmit_callinfo must be before transmit_callstate,
02610       or you won't get keypad messages in some situations. */
02611    transmit_callinfo(s, ast->cid.cid_name, ast->cid.cid_num, exten, exten, l->instance, sub->callid, 2);
02612    transmit_callstate(s, l->instance, SKINNY_CONNECTED, sub->callid);
02613    transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_CONNECTED);
02614    transmit_dialednumber(s, exten, l->instance, sub->callid);
02615    transmit_displaypromptstatus(s, "Connected", 0, l->instance, sub->callid);
02616    return res;
02617 }

static int skinny_call ( struct ast_channel ast,
char *  dest,
int  timeout 
) [static]

Definition at line 2490 of file chan_skinny.c.

References ast_channel::_state, AST_CONTROL_BUSY, AST_CONTROL_RINGING, ast_log(), ast_queue_control(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_RINGING, ast_verbose(), skinny_subchannel::callid, ast_channel::cid, skinny_line::cid_name, ast_callerid::cid_name, skinny_line::cid_num, ast_callerid::cid_num, skinny_line::dnd, skinny_line::hookstate, skinny_line::instance, KEYDEF_RINGIN, LOG_ERROR, LOG_WARNING, skinny_subchannel::outgoing, skinny_line::parent, skinny_subchannel::parent, skinny_device::registered, s, skinny_device::session, SKINNY_ALERT, SKINNY_CALLWAITTONE, SKINNY_LAMP_BLINK, SKINNY_OFFHOOK, SKINNY_ONHOOK, SKINNY_RING_INSIDE, SKINNY_RINGIN, STIMULUS_LINE, ast_channel::tech_pvt, transmit_callinfo(), transmit_callstate(), transmit_displaypromptstatus(), transmit_lamp_indication(), transmit_ringer_mode(), transmit_selectsoftkeys(), and VERBOSE_PREFIX_3.

02491 {
02492    int res = 0;
02493    int tone = 0;
02494    struct skinny_subchannel *sub = ast->tech_pvt;
02495    struct skinny_line *l = sub->parent;
02496    struct skinny_device *d = l->parent;
02497    struct skinnysession *s = d->session;
02498 
02499    if (!d->registered) {
02500       ast_log(LOG_ERROR, "Device not registered, cannot call %s\n", dest);
02501       return -1;
02502    }
02503 
02504    if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
02505       ast_log(LOG_WARNING, "skinny_call called on %s, neither down nor reserved\n", ast->name);
02506       return -1;
02507    }
02508 
02509    if (skinnydebug)
02510       ast_verbose(VERBOSE_PREFIX_3 "skinny_call(%s)\n", ast->name);
02511 
02512    if (l->dnd) {
02513       ast_queue_control(ast, AST_CONTROL_BUSY);
02514       return -1;
02515    }
02516 
02517    switch (l->hookstate) {
02518    case SKINNY_OFFHOOK:
02519       tone = SKINNY_CALLWAITTONE;
02520       break;
02521    case SKINNY_ONHOOK:
02522       tone = SKINNY_ALERT;
02523       break;
02524    default:
02525       ast_log(LOG_ERROR, "Don't know how to deal with hookstate %d\n", l->hookstate);
02526       break;
02527    }
02528 
02529    transmit_callstate(s, l->instance, SKINNY_RINGIN, sub->callid);
02530    transmit_selectsoftkeys(s, l->instance, sub->callid, KEYDEF_RINGIN);
02531    transmit_displaypromptstatus(s, "Ring-In", 0, l->instance, sub->callid);
02532    transmit_callinfo(s, ast->cid.cid_name, ast->cid.cid_num, l->cid_name, l->cid_num, l->instance, sub->callid, 1);
02533    transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_BLINK);
02534    transmit_ringer_mode(s, SKINNY_RING_INSIDE);
02535 
02536    ast_setstate(ast, AST_STATE_RINGING);
02537    ast_queue_control(ast, AST_CONTROL_RINGING);
02538    sub->outgoing = 1;
02539    return res;
02540 }

static int skinny_do_debug ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1868 of file chan_skinny.c.

References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01869 {
01870    if (argc != 3) {
01871       return RESULT_SHOWUSAGE;
01872    }
01873    skinnydebug = 1;
01874    ast_cli(fd, "Skinny Debugging Enabled\n");
01875    return RESULT_SUCCESS;
01876 }

static int skinny_fixup ( struct ast_channel oldchan,
struct ast_channel newchan 
) [static]

Definition at line 2705 of file chan_skinny.c.

References ast_log(), LOG_NOTICE, LOG_WARNING, skinny_subchannel::owner, and ast_channel::tech_pvt.

02706 {
02707    struct skinny_subchannel *sub = newchan->tech_pvt;
02708    ast_log(LOG_NOTICE, "skinny_fixup(%s, %s)\n", oldchan->name, newchan->name);
02709    if (sub->owner != oldchan) {
02710       ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, sub->owner);
02711       return -1;
02712    }
02713    sub->owner = newchan;
02714    return 0;
02715 }

static enum ast_rtp_get_result skinny_get_rtp_peer ( struct ast_channel c,
struct ast_rtp **  rtp 
) [static]

Definition at line 1838 of file chan_skinny.c.

References AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, skinny_subchannel::rtp, and ast_channel::tech_pvt.

01839 {
01840    struct skinny_subchannel *sub = NULL;
01841 
01842    if (!(sub = c->tech_pvt) || !(sub->rtp))
01843       return AST_RTP_GET_FAILED;
01844 
01845    *rtp = sub->rtp;
01846 
01847    return AST_RTP_TRY_NATIVE;
01848 }

static enum ast_rtp_get_result skinny_get_vrtp_peer ( struct ast_channel c,
struct ast_rtp **  rtp 
) [static]

Definition at line 1826 of file chan_skinny.c.

References AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, ast_channel::tech_pvt, and skinny_subchannel::vrtp.

01827 {
01828    struct skinny_subchannel *sub = NULL;
01829 
01830    if (!(sub = c->tech_pvt) || !(sub->vrtp))
01831       return AST_RTP_GET_FAILED;
01832 
01833    *rtp = sub->vrtp;
01834 
01835    return AST_RTP_TRY_NATIVE;
01836 }

static int skinny_hangup ( struct ast_channel ast  )  [static]

Definition at line 2542 of file chan_skinny.c.

References skinny_subchannel::alreadygone, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_destroy(), ast_verbose(), skinny_subchannel::callid, do_housekeeping(), skinny_line::hookstate, skinny_line::instance, skinny_subchannel::lock, LOG_DEBUG, skinny_device::name, skinny_line::name, skinny_subchannel::outgoing, skinny_subchannel::owner, skinny_line::parent, skinny_subchannel::parent, skinny_device::registered, skinny_subchannel::rtp, s, skinny_device::session, SKINNY_LAMP_OFF, SKINNY_OFFHOOK, SKINNY_ONHOOK, SKINNY_RING_OFF, SKINNY_SILENCE, SKINNY_SPEAKEROFF, STIMULUS_LINE, ast_channel::tech_pvt, transmit_callstate(), transmit_lamp_indication(), transmit_ringer_mode(), transmit_speaker_mode(), transmit_tone(), skinny_line::type, and TYPE_LINE.

02543 {
02544    struct skinny_subchannel *sub = ast->tech_pvt;
02545    struct skinny_line *l;
02546    struct skinny_device *d;
02547    struct skinnysession *s;
02548 
02549    if (!sub) {
02550       ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n");
02551       return 0;
02552    }
02553    l = sub->parent;
02554    d = l->parent;
02555    s = d->session;
02556    if (skinnydebug)
02557       ast_verbose("skinny_hangup(%s) on %s@%s\n", ast->name, l->name, d->name);
02558 
02559    if (d->registered) {
02560       if ((l->type = TYPE_LINE) && (l->hookstate == SKINNY_OFFHOOK)) {
02561          l->hookstate = SKINNY_ONHOOK;
02562          transmit_callstate(s, l->instance, SKINNY_ONHOOK, sub->callid);
02563          transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_OFF);
02564          transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
02565       } else if ((l->type = TYPE_LINE) && (l->hookstate == SKINNY_ONHOOK)) {
02566          transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
02567          transmit_callstate(s, l->instance, SKINNY_ONHOOK, sub->callid);
02568          transmit_ringer_mode(s, SKINNY_RING_OFF);
02569          transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_OFF);
02570          do_housekeeping(s);
02571       }
02572    }
02573    ast_mutex_lock(&sub->lock);
02574    sub->owner = NULL;
02575    ast->tech_pvt = NULL;
02576    sub->alreadygone = 0;
02577    sub->outgoing = 0;
02578    if (sub->rtp) {
02579       ast_rtp_destroy(sub->rtp);
02580       sub->rtp = NULL;
02581    }
02582    ast_mutex_unlock(&sub->lock);
02583    return 0;
02584 }

static int skinny_hold ( struct skinny_subchannel sub  )  [static]

Definition at line 2967 of file chan_skinny.c.

References ACTIVATE_CALL_PLANE_MESSAGE, skinny_data::activatecallplane, AST_CONTROL_HOLD, ast_queue_control_data(), ast_strlen_zero(), ast_verbose(), skinny_subchannel::callid, CLOSE_RECEIVE_CHANNEL_MESSAGE, skinny_data::closereceivechannel, stop_media_transmission_message::conferenceId, close_receive_channel_message::conferenceId, skinny_req::data, htolel, skinny_line::instance, activate_call_plane_message::lineInstance, skinny_line::mohsuggest, skinny_subchannel::onhold, skinny_subchannel::owner, skinny_line::parent, skinny_subchannel::parent, close_receive_channel_message::partyId, stop_media_transmission_message::passThruPartyId, req_alloc(), s, S_OR, skinny_device::session, SKINNY_LAMP_BLINK, STIMULUS_LINE, STOP_MEDIA_TRANSMISSION_MESSAGE, skinny_data::stopmedia, transmit_lamp_indication(), and transmit_response().

Referenced by handle_soft_key_event_message(), and handle_stimulus_message().

02968 {
02969    struct skinny_line *l = sub->parent;
02970    struct skinny_device *d = l->parent;
02971    struct skinnysession *s = d->session;
02972    struct skinny_req *req;
02973 
02974    /* Don't try to hold a channel that doesn't exist */
02975    if (!sub || !sub->owner)
02976       return 0;
02977 
02978    /* Channel needs to be put on hold */
02979    if (skinnydebug)
02980       ast_verbose("Putting on Hold(%d)\n", l->instance);
02981 
02982    ast_queue_control_data(sub->owner, AST_CONTROL_HOLD,
02983       S_OR(l->mohsuggest, NULL),
02984       !ast_strlen_zero(l->mohsuggest) ? strlen(l->mohsuggest) + 1 : 0);
02985 
02986    if (!(req = req_alloc(sizeof(struct activate_call_plane_message), ACTIVATE_CALL_PLANE_MESSAGE)))
02987       return 0;
02988 
02989    req->data.activatecallplane.lineInstance = htolel(l->instance);
02990    transmit_response(s, req);
02991 
02992    if (!(req = req_alloc(sizeof(struct close_receive_channel_message), CLOSE_RECEIVE_CHANNEL_MESSAGE)))
02993       return 0;
02994 
02995    req->data.closereceivechannel.conferenceId = htolel(sub->callid);
02996    req->data.closereceivechannel.partyId = htolel(sub->callid);
02997    transmit_response(s, req);
02998 
02999    if (!(req = req_alloc(sizeof(struct stop_media_transmission_message), STOP_MEDIA_TRANSMISSION_MESSAGE)))
03000       return 0;
03001 
03002    req->data.stopmedia.conferenceId = htolel(sub->callid);
03003    req->data.stopmedia.passThruPartyId = htolel(sub->callid);
03004    transmit_response(s, req);
03005 
03006    transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_BLINK);
03007    sub->onhold = 1;
03008    return 1;
03009 }

static int skinny_indicate ( struct ast_channel ast,
int  ind,
const void *  data,
size_t  datalen 
) [static]

Definition at line 2785 of file chan_skinny.c.

References ast_channel::_state, skinny_subchannel::alreadygone, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, ast_log(), AST_MAX_EXTENSION, ast_moh_start(), ast_moh_stop(), ast_rtp_new_source(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_UP, ast_verbose(), skinny_subchannel::callid, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, control2str(), skinny_device::earlyrtp, ast_channel::exten, exten, skinny_line::instance, LOG_NOTICE, LOG_WARNING, ast_channel::macroexten, skinny_line::mohinterpret, skinny_subchannel::outgoing, skinny_line::parent, skinny_subchannel::parent, skinny_subchannel::progress, skinny_subchannel::ringing, skinny_subchannel::rtp, s, S_OR, skinny_device::session, SKINNY_ALERT, SKINNY_BUSY, SKINNY_BUSYTONE, SKINNY_CONGESTION, SKINNY_PROGRESS, SKINNY_REORDER, SKINNY_RINGOUT, SKINNY_SILENCE, ast_channel::tech_pvt, transmit_callinfo(), transmit_callstate(), transmit_dialednumber(), transmit_displaypromptstatus(), transmit_tone(), and VERBOSE_PREFIX_3.

02786 {
02787    struct skinny_subchannel *sub = ast->tech_pvt;
02788    struct skinny_line *l = sub->parent;
02789    struct skinny_device *d = l->parent;
02790    struct skinnysession *s = d->session;
02791    char exten[AST_MAX_EXTENSION] = "";
02792 
02793    if (!s) {
02794       ast_log(LOG_NOTICE, "Asked to indicate '%s' condition on channel %s, but session does not exist.\n", control2str(ind), ast->name);
02795       return -1;
02796    }
02797 
02798    ast_copy_string(exten, S_OR(ast->macroexten, ast->exten), sizeof(exten));
02799 
02800    if (skinnydebug)
02801       ast_verbose(VERBOSE_PREFIX_3 "Asked to indicate '%s' condition on channel %s\n", control2str(ind), ast->name);
02802    switch(ind) {
02803    case AST_CONTROL_RINGING:
02804       if (ast->_state != AST_STATE_UP) {
02805          if (!sub->progress) {
02806             if (!d->earlyrtp) {
02807                transmit_tone(s, SKINNY_ALERT, l->instance, sub->callid);
02808             }
02809             transmit_callstate(s, l->instance, SKINNY_RINGOUT, sub->callid);
02810             transmit_dialednumber(s, exten, l->instance, sub->callid);
02811             transmit_displaypromptstatus(s, "Ring Out", 0, l->instance, sub->callid);
02812             transmit_callinfo(s, ast->cid.cid_name, ast->cid.cid_num, exten, exten, l->instance, sub->callid, 2); /* 2 = outgoing from phone */
02813             sub->ringing = 1;
02814             if (!d->earlyrtp) {
02815                break;
02816             }
02817          }
02818       }
02819       return -1; /* Tell asterisk to provide inband signalling */
02820    case AST_CONTROL_BUSY:
02821       if (ast->_state != AST_STATE_UP) {
02822          if (!d->earlyrtp) {
02823             transmit_tone(s, SKINNY_BUSYTONE, l->instance, sub->callid);
02824          }
02825          transmit_callstate(s, l->instance, SKINNY_BUSY, sub->callid);
02826          sub->alreadygone = 1;
02827          ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV);
02828          if (!d->earlyrtp) {
02829             break;
02830          }
02831       }
02832       return -1; /* Tell asterisk to provide inband signalling */
02833    case AST_CONTROL_CONGESTION:
02834       if (ast->_state != AST_STATE_UP) {
02835          if (!d->earlyrtp) {
02836             transmit_tone(s, SKINNY_REORDER, l->instance, sub->callid);
02837          }
02838          transmit_callstate(s, l->instance, SKINNY_CONGESTION, sub->callid);
02839          sub->alreadygone = 1;
02840          ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV);
02841          if (!d->earlyrtp) {
02842             break;
02843          }
02844       }
02845       return -1; /* Tell asterisk to provide inband signalling */
02846    case AST_CONTROL_PROGRESS:
02847       if ((ast->_state != AST_STATE_UP) && !sub->progress && !sub->outgoing) {
02848          if (!d->earlyrtp) {
02849             transmit_tone(s, SKINNY_ALERT, l->instance, sub->callid);
02850          }
02851          transmit_callstate(s, l->instance, SKINNY_PROGRESS, sub->callid);
02852          transmit_displaypromptstatus(s, "Call Progress", 0, l->instance, sub->callid);
02853          transmit_callinfo(s, ast->cid.cid_name, ast->cid.cid_num, exten, exten, l->instance, sub->callid, 2); /* 2 = outgoing from phone */
02854          sub->progress = 1;
02855          if (!d->earlyrtp) {
02856             break;
02857          }
02858       }
02859       return -1; /* Tell asterisk to provide inband signalling */
02860    case -1:  /* STOP_TONE */
02861       transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
02862       break;
02863    case AST_CONTROL_HOLD:
02864       ast_moh_start(ast, data, l->mohinterpret);
02865       break;
02866    case AST_CONTROL_UNHOLD:
02867       ast_moh_stop(ast);
02868       break;
02869    case AST_CONTROL_PROCEEDING:
02870       break;
02871    case AST_CONTROL_SRCUPDATE:
02872       if (sub->rtp) {
02873          ast_rtp_new_source(sub->rtp);
02874       }
02875       break;
02876    default:
02877       ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", ind);
02878       return -1; /* Tell asterisk to provide inband signalling */
02879    }
02880    return 0;
02881 }

static struct ast_channel* skinny_new ( struct skinny_line l,
int  state 
) [static, read]

Definition at line 2883 of file chan_skinny.c.

References skinny_line::accountcode, ast_channel::adsicpe, ast_channel::amaflags, skinny_line::amaflags, AST_ADSI_UNAVAILABLE, ast_best_codec(), ast_calloc, ast_channel_alloc(), ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_mutex_init(), ast_pbx_start(), ast_rtp_fd(), AST_STATE_DOWN, AST_STATE_RING, ast_strdup, ast_string_field_set, ast_strlen_zero(), ast_verbose(), skinny_line::call_forward, skinny_line::callgroup, ast_channel::callgroup, skinny_subchannel::callid, skinny_line::capability, ast_channel::cid, ast_callerid::cid_ani, skinny_line::cid_name, skinny_line::cid_num, ast_channel::context, skinny_line::context, skinny_subchannel::cxmode, ast_channel::exten, skinny_line::exten, ast_channel::fds, fmt, global_jbconf, skinny_line::instance, skinny_line::language, skinny_device::lastcallreference, skinny_device::lastlineinstance, skinny_subchannel::lock, LOG_WARNING, skinny_device::name, skinny_line::name, skinny_line::nat, skinny_subchannel::nat, ast_channel::nativeformats, skinny_subchannel::next, skinny_subchannel::onhold, skinny_subchannel::owner, skinny_subchannel::parent, skinny_line::parent, skinny_line::pickupgroup, ast_channel::pickupgroup, ast_channel::priority, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::rings, skinny_subchannel::rtp, SKINNY_CX_INACTIVE, skinny_line::sub, ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.

Referenced by handle_enbloc_call_message(), handle_offhook_message(), handle_soft_key_event_message(), handle_stimulus_message(), and skinny_request().

02884 {
02885    struct ast_channel *tmp;
02886    struct skinny_subchannel *sub;
02887    struct skinny_device *d = l->parent;
02888    int fmt;
02889 
02890    tmp = ast_channel_alloc(1, state, l->cid_num, l->cid_name, l->accountcode, l->exten, l->context, l->amaflags, "Skinny/%s@%s-%d", l->name, d->name, callnums);
02891    if (!tmp) {
02892       ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
02893       return NULL;
02894    } else {
02895       sub = ast_calloc(1, sizeof(struct skinny_subchannel));
02896       if (!sub) {
02897          ast_log(LOG_WARNING, "Unable to allocate Skinny subchannel\n");
02898          return NULL;
02899       } else {
02900          ast_mutex_init(&sub->lock);
02901 
02902          sub->owner = tmp;
02903          sub->callid = callnums++;
02904          d->lastlineinstance = l->instance;
02905          d->lastcallreference = sub->callid;
02906          sub->cxmode = SKINNY_CX_INACTIVE;
02907          sub->nat = l->nat;
02908          sub->parent = l;
02909          sub->onhold = 0;
02910 
02911          sub->next = l->sub;
02912          l->sub = sub;
02913       }
02914       tmp->tech = &skinny_tech;
02915       tmp->tech_pvt = sub;
02916       tmp->nativeformats = l->capability;
02917       if (!tmp->nativeformats)
02918          tmp->nativeformats = default_capability;
02919       fmt = ast_best_codec(tmp->nativeformats);
02920       if (skinnydebug)
02921          ast_verbose("skinny_new: tmp->nativeformats=%d fmt=%d\n", tmp->nativeformats, fmt);
02922       if (sub->rtp) {
02923          tmp->fds[0] = ast_rtp_fd(sub->rtp);
02924       }
02925       if (state == AST_STATE_RING) {
02926          tmp->rings = 1;
02927       }
02928       tmp->writeformat = fmt;
02929       tmp->rawwriteformat = fmt;
02930       tmp->readformat = fmt;
02931       tmp->rawreadformat = fmt;
02932       if (!ast_strlen_zero(l->language))
02933          ast_string_field_set(tmp, language, l->language);
02934       if (!ast_strlen_zero(l->accountcode))
02935          ast_string_field_set(tmp, accountcode, l->accountcode);
02936       if (l->amaflags)
02937          tmp->amaflags = l->amaflags;
02938 
02939       ast_module_ref(ast_module_info->self);
02940       tmp->callgroup = l->callgroup;
02941       tmp->pickupgroup = l->pickupgroup;
02942       ast_string_field_set(tmp, call_forward, l->call_forward);
02943       ast_copy_string(tmp->context, l->context, sizeof(tmp->context));
02944       ast_copy_string(tmp->exten, l->exten, sizeof(tmp->exten));
02945 
02946       /* Don't use ast_set_callerid() here because it will
02947        * generate a needless NewCallerID event */
02948       tmp->cid.cid_ani = ast_strdup(l->cid_num);
02949 
02950       tmp->priority = 1;
02951       tmp->adsicpe = AST_ADSI_UNAVAILABLE;
02952 
02953       if (sub->rtp)
02954          ast_jb_configure(tmp, &global_jbconf);
02955 
02956       if (state != AST_STATE_DOWN) {
02957          if (ast_pbx_start(tmp)) {
02958             ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
02959             ast_hangup(tmp);
02960             tmp = NULL;
02961          }
02962       }
02963    }
02964    return tmp;
02965 }

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

Definition at line 2364 of file chan_skinny.c.

References ast_log(), ast_pbx_run(), ast_set_callerid(), ast_setstate(), AST_STATE_RING, skinny_subchannel::callid, ast_channel::cid, ast_callerid::cid_ani, skinny_line::cid_name, skinny_line::cid_num, ast_channel::exten, skinny_line::hidecallerid, skinny_line::instance, skinny_line::lastnumberdialed, LOG_WARNING, skinny_line::parent, skinny_subchannel::parent, skinny_subchannel::rtp, s, skinny_device::session, SKINNY_REORDER, start_rtp(), ast_channel::tech_pvt, and transmit_tone().

Referenced by handle_enbloc_call_message(), handle_soft_key_event_message(), handle_stimulus_message(), and skinny_ss().

02365 {
02366    struct ast_channel *c = data;
02367    struct skinny_subchannel *sub = c->tech_pvt;
02368    struct skinny_line *l = sub->parent;
02369    struct skinny_device *d = l->parent;
02370    struct skinnysession *s = d->session;
02371    int res = 0;
02372 
02373    ast_copy_string(l->lastnumberdialed, c->exten, sizeof(l->lastnumberdialed));
02374    ast_set_callerid(c,
02375       l->hidecallerid ? "" : l->cid_num,
02376       l->hidecallerid ? "" : l->cid_name,
02377       c->cid.cid_ani ? NULL : l->cid_num);
02378    ast_setstate(c, AST_STATE_RING);
02379    if (!sub->rtp) {
02380       start_rtp(sub);
02381    }
02382    res = ast_pbx_run(c);
02383    if (res) {
02384       ast_log(LOG_WARNING, "PBX exited non-zero\n");
02385       transmit_tone(s, SKINNY_REORDER, l->instance, sub->callid);
02386    }
02387    return NULL;
02388 }

static int skinny_no_debug ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1878 of file chan_skinny.c.

References ast_cli(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

01879 {
01880    if (argc != 4) {
01881       return RESULT_SHOWUSAGE;
01882    }
01883    skinnydebug = 0;
01884    ast_cli(fd, "Skinny Debugging Disabled\n");
01885    return RESULT_SUCCESS;
01886 }

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

Definition at line 2667 of file chan_skinny.c.

References ast_mutex_lock(), ast_mutex_unlock(), skinny_subchannel::lock, skinny_rtp_read(), and ast_channel::tech_pvt.

02668 {
02669    struct ast_frame *fr;
02670    struct skinny_subchannel *sub = ast->tech_pvt;
02671    ast_mutex_lock(&sub->lock);
02672    fr = skinny_rtp_read(sub);
02673    ast_mutex_unlock(&sub->lock);
02674    return fr;
02675 }

static int skinny_register ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 1421 of file chan_skinny.c.

References __ourip, ast_apply_ha(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), skinny_req::data, skinnysession::device, devices, skinnysession::fd, skinny_device::ha, skinny_device::id, letohl, LOG_WARNING, register_message::name, skinny_device::next, skinny_device::ourip, skinny_data::reg, skinny_device::registered, skinny_device::session, skinnysession::sin, register_message::type, skinny_device::type, and skinny_device::version_id.

Referenced by handle_register_message().

01422 {
01423    struct skinny_device *d;
01424    struct sockaddr_in sin;
01425    socklen_t slen;
01426 
01427    ast_mutex_lock(&devicelock);
01428    for (d = devices; d; d = d->next) {
01429       if (!strcasecmp(req->data.reg.name, d->id)
01430             && ast_apply_ha(d->ha, &(s->sin))) {
01431          s->device = d;
01432          d->type = letohl(req->data.reg.type);
01433          if (ast_strlen_zero(d->version_id)) {
01434             ast_copy_string(d->version_id, version_id, sizeof(d->version_id));
01435          }
01436          d->registered = 1;
01437          d->session = s;
01438 
01439          slen = sizeof(sin);
01440          if (getsockname(s->fd, (struct sockaddr *)&sin, &slen)) {
01441             ast_log(LOG_WARNING, "Cannot get socket name\n");
01442             sin.sin_addr = __ourip;
01443          }
01444          d->ourip = sin.sin_addr;
01445          break;
01446       }
01447    }
01448    ast_mutex_unlock(&devicelock);
01449    if (!d) {
01450       return 0;
01451    }
01452    return 1;
01453 }

static struct skinny_req* skinny_req_parse ( struct skinnysession s  )  [static, read]

Definition at line 4539 of file chan_skinny.c.

References ast_calloc, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), skinny_req::data, skinny_req::e, skinnysession::fd, free, skinnysession::inbuf, letohl, skinnysession::lock, LOG_ERROR, and SKINNY_MAX_PACKET.

Referenced by skinny_session().

04540 {
04541    struct skinny_req *req;
04542 
04543    if (!(req = ast_calloc(1, SKINNY_MAX_PACKET)))
04544       return NULL;
04545 
04546    ast_mutex_lock(&s->lock);
04547    memcpy(req, s->inbuf, skinny_header_size);
04548    memcpy(&req->data, s->inbuf+skinny_header_size, letohl(*(int*)(s->inbuf))-4);
04549 
04550    ast_mutex_unlock(&s->lock);
04551 
04552    if (letohl(req->e) < 0) {
04553       ast_log(LOG_ERROR, "Event Message is NULL from socket %d, This is bad\n", s->fd);
04554       free(req);
04555       return NULL;
04556    }
04557 
04558    return req;
04559 }

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

Definition at line 4717 of file chan_skinny.c.

References AST_FORMAT_MAX_AUDIO, ast_log(), AST_STATE_DOWN, ast_strlen_zero(), ast_verbose(), find_line_by_name(), LOG_NOTICE, LOG_WARNING, option_verbose, restart_monitor(), skinny_new(), and VERBOSE_PREFIX_3.

04718 {
04719    int oldformat;
04720    
04721    struct skinny_line *l;
04722    struct ast_channel *tmpc = NULL;
04723    char tmp[256];
04724    char *dest = data;
04725 
04726    oldformat = format;
04727    
04728    if (!(format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1))) {
04729       ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format);
04730       return NULL;   
04731    }     
04732 
04733    ast_copy_string(tmp, dest, sizeof(tmp));
04734    if (ast_strlen_zero(tmp)) {
04735       ast_log(LOG_NOTICE, "Skinny channels require a device\n");
04736       return NULL;
04737    }
04738    l = find_line_by_name(tmp);
04739    if (!l) {
04740       ast_log(LOG_NOTICE, "No available lines on: %s\n", dest);
04741       return NULL;
04742    }
04743    if (option_verbose > 2) {
04744       ast_verbose(VERBOSE_PREFIX_3 "skinny_request(%s)\n", tmp);
04745    }
04746    tmpc = skinny_new(l, AST_STATE_DOWN);
04747    if (!tmpc) {
04748       ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp);
04749    }
04750    restart_monitor();
04751    return tmpc;
04752 }

static int skinny_reset_device ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1906 of file chan_skinny.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), skinny_req::data, devices, skinny_device::id, skinny_device::next, option_verbose, req_alloc(), skinny_data::reset, RESET_MESSAGE, reset_message::resetType, RESULT_SHOWUSAGE, RESULT_SUCCESS, skinny_device::session, transmit_response(), and VERBOSE_PREFIX_3.

01907 {
01908    struct skinny_device *d;
01909    struct skinny_req *req;
01910 
01911    if (argc < 3 || argc > 4) {
01912       return RESULT_SHOWUSAGE;
01913    }
01914    ast_mutex_lock(&devicelock);
01915 
01916    for (d = devices; d; d = d->next) {
01917       int fullrestart = 0;
01918       if (!strcasecmp(argv[2], d->id) || !strcasecmp(argv[2], "all")) {
01919          if (!(d->session))
01920             continue;
01921 
01922          if (!(req = req_alloc(sizeof(struct reset_message), RESET_MESSAGE)))
01923             continue;
01924 
01925          if (argc == 4 && !strcasecmp(argv[3], "restart"))
01926             fullrestart = 1;
01927 
01928          if (fullrestart)
01929             req->data.reset.resetType = 2;
01930          else
01931             req->data.reset.resetType = 1;
01932 
01933          if (option_verbose > 2)
01934             ast_verbose(VERBOSE_PREFIX_3 "%s device %s.\n", (fullrestart) ? "Restarting" : "Resetting", d->id);
01935          transmit_response(d->session, req);
01936       }
01937    }
01938    ast_mutex_unlock(&devicelock);
01939    return RESULT_SUCCESS;
01940 }

static struct ast_frame* skinny_rtp_read ( struct skinny_subchannel sub  )  [static, read]

Definition at line 2620 of file chan_skinny.c.

References AST_FRAME_VOICE, ast_log(), ast_null_frame, ast_rtcp_read(), ast_rtp_read(), ast_set_read_format(), ast_set_write_format(), ast_udptl_read(), f, ast_channel::fdno, ast_frame::frametype, LOG_DEBUG, ast_channel::nativeformats, skinny_subchannel::owner, ast_channel::readformat, skinny_subchannel::rtp, ast_frame::subclass, skinny_subchannel::vrtp, and ast_channel::writeformat.

Referenced by skinny_read().

02621 {
02622    struct ast_channel *ast = sub->owner;
02623    struct ast_frame *f;
02624 
02625    if (!sub->rtp) {
02626       /* We have no RTP allocated for this channel */
02627       return &ast_null_frame;
02628    }
02629 
02630    switch(ast->fdno) {
02631    case 0:
02632       f = ast_rtp_read(sub->rtp);   /* RTP Audio */
02633       break;
02634    case 1:
02635       f = ast_rtcp_read(sub->rtp);  /* RTCP Control Channel */
02636       break;
02637    case 2:
02638       f = ast_rtp_read(sub->vrtp);  /* RTP Video */
02639       break;
02640    case 3:
02641       f = ast_rtcp_read(sub->vrtp); /* RTCP Control Channel for video */
02642       break;
02643 #if 0
02644    case 5:
02645       /* Not yet supported */
02646       f = ast_udptl_read(sub->udptl);  /* UDPTL for T.38 */
02647       break;
02648 #endif
02649    default:
02650       f = &ast_null_frame;
02651    }
02652 
02653    if (ast) {
02654       /* We already hold the channel lock */
02655       if (f->frametype == AST_FRAME_VOICE) {
02656          if (f->subclass != ast->nativeformats) {
02657             ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
02658             ast->nativeformats = f->subclass;
02659             ast_set_read_format(ast, ast->readformat);
02660             ast_set_write_format(ast, ast->writeformat);
02661          }
02662       }
02663    }
02664    return f;
02665 }

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

Definition at line 2717 of file chan_skinny.c.

02718 {
02719    return -1; /* Start inband indications */
02720 }

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

Definition at line 2722 of file chan_skinny.c.

References skinny_subchannel::callid, skinny_line::instance, skinny_line::parent, skinny_subchannel::parent, skinny_device::session, ast_channel::tech_pvt, and transmit_tone().

02723 {
02724 #if 0
02725    struct skinny_subchannel *sub = ast->tech_pvt;
02726    struct skinny_line *l = sub->parent;
02727    struct skinny_device *d = l->parent;
02728    int tmp;
02729    /* not right */
02730    sprintf(tmp, "%d", digit);
02731    transmit_tone(d->session, digit, l->instance, sub->callid);
02732 #endif
02733    return -1; /* Stop inband indications */
02734 }

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

Definition at line 4561 of file chan_skinny.c.

References ast_inet_ntoa(), ast_log(), ast_verbose(), destroy_session(), errno, get_input(), handle_message(), LOG_NOTICE, option_verbose, skinny_req::res, s, skinnysession::sin, skinny_req_parse(), and VERBOSE_PREFIX_3.

Referenced by accept_thread().

04562 {
04563    int res;
04564    struct skinny_req *req;
04565    struct skinnysession *s = data;
04566 
04567    if (option_verbose > 2)
04568       ast_verbose(VERBOSE_PREFIX_3 "Starting Skinny session from %s\n", ast_inet_ntoa(s->sin.sin_addr));
04569 
04570    for (;;) {
04571       res = get_input(s);
04572       if (res < 0) {
04573          break;
04574       }
04575 
04576       if (res > 0)
04577       {
04578          if (!(req = skinny_req_parse(s))) {
04579             destroy_session(s);
04580             return NULL;
04581          }
04582 
04583          res = handle_message(req, s);
04584          if (res < 0) {
04585             destroy_session(s);
04586             return NULL;
04587          }
04588       }
04589    }
04590    ast_log(LOG_NOTICE, "Skinny Session returned: %s\n", strerror(errno));
04591 
04592    if (s) 
04593       destroy_session(s);
04594    
04595    return 0;
04596 }

static int skinny_set_rtp_peer ( struct ast_channel c,
struct ast_rtp rtp,
struct ast_rtp vrtp,
int  codecs,
int  nat_active 
) [static]

Definition at line 1850 of file chan_skinny.c.

References ast_channel::tech_pvt.

01851 {
01852    struct skinny_subchannel *sub;
01853    sub = c->tech_pvt;
01854    if (sub) {
01855       /* transmit_modify_with_sdp(sub, rtp); @@FIXME@@ if needed */
01856       return 0;
01857    }
01858    return -1;
01859 }

static int skinny_show_devices ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2031 of file chan_skinny.c.

References ast_cli(), ast_inet_ntoa(), ast_mutex_lock(), ast_mutex_unlock(), device2str(), devices, skinny_device::id, skinny_device::lines, skinny_device::name, skinny_line::next, skinny_device::next, skinny_device::registered, RESULT_SHOWUSAGE, RESULT_SUCCESS, skinny_device::session, skinnysession::sin, and skinny_device::type.

02032 {
02033    struct skinny_device *d;
02034    struct skinny_line *l;
02035    int numlines = 0;
02036 
02037    if (argc != 3) {
02038       return RESULT_SHOWUSAGE;
02039    }
02040    ast_mutex_lock(&devicelock);
02041 
02042    ast_cli(fd, "Name                 DeviceId         IP              Type            R NL\n");
02043    ast_cli(fd, "-------------------- ---------------- --------------- --------------- - --\n");
02044    for (d = devices; d; d = d->next) {
02045       numlines = 0;
02046       for (l = d->lines; l; l = l->next) {
02047          numlines++;
02048       }
02049 
02050       ast_cli(fd, "%-20s %-16s %-15s %-15s %c %2d\n",
02051             d->name,
02052             d->id,
02053             d->session?ast_inet_ntoa(d->session->sin.sin_addr):"",
02054             device2str(d->type),
02055             d->registered?'Y':'N',
02056             numlines);
02057    }
02058    ast_mutex_unlock(&devicelock);
02059    return RESULT_SUCCESS;
02060 }

static int skinny_show_lines ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2062 of file chan_skinny.c.

References ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), devices, skinny_line::instance, skinny_line::label, skinny_device::lines, skinny_line::name, skinny_device::name, skinny_line::next, skinny_device::next, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

02063 {
02064    struct skinny_device *d;
02065    struct skinny_line *l;
02066 
02067    if (argc != 3) {
02068       return RESULT_SHOWUSAGE;
02069    }
02070    ast_mutex_lock(&devicelock);
02071 
02072    ast_cli(fd, "Device Name          Instance Name                 Label               \n");
02073    ast_cli(fd, "-------------------- -------- -------------------- --------------------\n");
02074    for (d = devices; d; d = d->next) {
02075       for (l = d->lines; l; l = l->next) {
02076          ast_cli(fd, "%-20s %8d %-20s %-20s\n",
02077             d->name,
02078             l->instance,
02079             l->name,
02080             l->label);
02081       }
02082    }
02083 
02084    ast_mutex_unlock(&devicelock);
02085    return RESULT_SUCCESS;
02086 }

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

Definition at line 2390 of file chan_skinny.c.

References ast_channel::_state, ast_canmatch_extension(), ast_exists_extension(), ast_hangup(), ast_ignore_pattern(), ast_indicate(), ast_log(), ast_matchmore_extension(), AST_MAX_EXTENSION, ast_safe_sleep(), AST_STATE_UP, ast_strlen_zero(), ast_verbose(), skinny_line::call_forward, skinny_subchannel::callid, ast_channel::cid, ast_callerid::cid_num, skinny_line::cid_num, ast_channel::context, ast_channel::exten, skinny_device::exten, skinny_line::instance, skinny_line::lastnumberdialed, len, LOG_DEBUG, LOG_WARNING, skinny_device::name, skinny_line::name, option_verbose, skinny_subchannel::owner, skinny_line::parent, skinny_subchannel::parent, s, skinny_device::session, SKINNY_DIALTONE, skinny_newcall(), SKINNY_REORDER, SKINNY_SILENCE, ast_channel::tech_pvt, transmit_tone(), and VERBOSE_PREFIX_3.

Referenced by handle_offhook_message(), handle_soft_key_event_message(), and handle_stimulus_message().

02391 {
02392    struct ast_channel *c = data;
02393    struct skinny_subchannel *sub = c->tech_pvt;
02394    struct skinny_line *l = sub->parent;
02395    struct skinny_device *d = l->parent;
02396    struct skinnysession *s = d->session;
02397    int len = 0;
02398    int timeout = firstdigittimeout;
02399    int res = 0;
02400    int getforward=0;
02401    int loop_pause = 100;
02402 
02403    if (option_verbose > 2)
02404       ast_verbose( VERBOSE_PREFIX_3 "Starting simple switch on '%s@%s'\n", l->name, d->name);
02405    len = strlen(d->exten);
02406 
02407    while (len < AST_MAX_EXTENSION-1) {
02408 
02409       res = 1;  /* Assume we will get a digit */
02410       while (strlen(d->exten) == len) {
02411          ast_safe_sleep(c, loop_pause);
02412          timeout -= loop_pause;
02413          if (timeout <= 0){
02414             res = 0;
02415             break;
02416          }
02417       }
02418 
02419       len = strlen(d->exten);
02420 
02421       if (!ast_ignore_pattern(c->context, d->exten)) {
02422          transmit_tone(s, SKINNY_SILENCE, l->instance, sub->callid);
02423       }
02424 
02425       if (ast_exists_extension(c, c->context, d->exten, 1, l->cid_num)) {
02426          if (!res || !ast_matchmore_extension(c, c->context, d->exten, 1, l->cid_num)) {
02427             if (getforward) {
02428                /* Record this as the forwarding extension */
02429                ast_copy_string(l->call_forward, d->exten, sizeof(l->call_forward));
02430                if (option_verbose > 2)
02431                   ast_verbose(VERBOSE_PREFIX_3 "Setting call forward to '%s' on channel %s\n",
02432                      l->call_forward, c->name);
02433                transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
02434                if (res) {
02435                   break;
02436                }
02437                ast_safe_sleep(c, 500);
02438                ast_indicate(c, -1);
02439                ast_safe_sleep(c, 1000);
02440                memset(d->exten, 0, sizeof(d->exten));
02441                transmit_tone(s, SKINNY_DIALTONE, l->instance, sub->callid);
02442                len = 0;
02443                getforward = 0;
02444             } else {
02445                ast_copy_string(c->exten, d->exten, sizeof(c->exten));
02446                ast_copy_string(l->lastnumberdialed, d->exten, sizeof(l->lastnumberdialed));
02447                memset (d->exten, 0, sizeof(d->exten));
02448                skinny_newcall(c);
02449                return NULL;
02450             }
02451          } else {
02452             /* It's a match, but they just typed a digit, and there is an ambiguous match,
02453                so just set the timeout to matchdigittimeout and wait some more */
02454             timeout = matchdigittimeout;
02455          }
02456       } else if (res == 0) {
02457          ast_log(LOG_DEBUG, "Not enough digits (and no ambiguous match)...\n");
02458          memset(d->exten, 0, sizeof(d->exten));
02459          transmit_tone(s, SKINNY_REORDER, l->instance, sub->callid);
02460          if (sub->owner && sub->owner->_state != AST_STATE_UP) {
02461             ast_indicate(c, -1);
02462             ast_hangup(c);
02463          }
02464          return NULL;
02465       } else if (!ast_canmatch_extension(c, c->context, d->exten, 1, c->cid.cid_num) &&
02466             ((d->exten[0] != '*') || (!ast_strlen_zero(d->exten) > 2))) {
02467          ast_log(LOG_WARNING, "Can't match [%s] from '%s' in context %s\n", d->exten, c->cid.cid_num ? c->cid.cid_num : "<Unknown Caller>", c->context);
02468          memset(d->exten, 0, sizeof(d->exten));
02469          transmit_tone(s, SKINNY_REORDER, l->instance, sub->callid);
02470          /* hang out for 3 seconds to let congestion play */
02471          ast_safe_sleep(c, 3000);
02472          break;
02473       }
02474       if (!timeout) {
02475          timeout = gendigittimeout;
02476       }
02477       if (len && !ast_ignore_pattern(c->context, d->exten)) {
02478          ast_indicate(c, -1);
02479       }
02480    }
02481    if (c)
02482       ast_hangup(c);
02483 
02484    memset(d->exten, 0, sizeof(d->exten));
02485    return NULL;
02486 }

static int skinny_unhold ( struct skinny_subchannel sub  )  [static]

Definition at line 3011 of file chan_skinny.c.

References ACTIVATE_CALL_PLANE_MESSAGE, skinny_data::activatecallplane, AST_CONTROL_UNHOLD, ast_queue_control(), ast_verbose(), skinny_req::data, htolel, skinny_line::instance, activate_call_plane_message::lineInstance, skinny_subchannel::onhold, skinny_subchannel::owner, skinny_line::parent, skinny_subchannel::parent, req_alloc(), s, skinny_device::session, SKINNY_LAMP_ON, STIMULUS_LINE, transmit_connect(), transmit_lamp_indication(), and transmit_response().

Referenced by handle_soft_key_event_message(), and handle_stimulus_message().

03012 {
03013    struct skinny_line *l = sub->parent;
03014    struct skinny_device *d = l->parent;
03015    struct skinnysession *s = d->session;
03016    struct skinny_req *req;
03017 
03018    /* Don't try to unhold a channel that doesn't exist */
03019    if (!sub || !sub->owner)
03020       return 0;
03021 
03022    /* Channel is on hold, so we will unhold */
03023    if (skinnydebug)
03024       ast_verbose("Taking off Hold(%d)\n", l->instance);
03025 
03026    ast_queue_control(sub->owner, AST_CONTROL_UNHOLD);
03027 
03028    if (!(req = req_alloc(sizeof(struct activate_call_plane_message), ACTIVATE_CALL_PLANE_MESSAGE)))
03029       return 0;
03030 
03031    req->data.activatecallplane.lineInstance = htolel(l->instance);
03032    transmit_response(s, req);
03033 
03034    transmit_connect(s, sub);
03035    transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
03036    sub->onhold = 0;
03037    return 1;
03038 }

static int skinny_unregister ( struct skinny_req req,
struct skinnysession s 
) [static]

Definition at line 1455 of file chan_skinny.c.

References skinnysession::device, skinny_device::registered, and skinny_device::session.

Referenced by get_input(), handle_unregister_message(), and transmit_response().

01456 {
01457    struct skinny_device *d;
01458 
01459    d = s->device;
01460 
01461    if (d) {
01462       d->session = NULL;
01463       d->registered = 0;
01464    }
01465 
01466    return -1; /* main loop will destroy the session */
01467 }

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

Definition at line 2677 of file chan_skinny.c.

References AST_FRAME_IMAGE, AST_FRAME_VOICE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_write(), ast_frame::frametype, skinny_subchannel::lock, LOG_WARNING, ast_channel::nativeformats, ast_channel::readformat, skinny_subchannel::rtp, ast_frame::subclass, ast_channel::tech_pvt, and ast_channel::writeformat.

02678 {
02679    struct skinny_subchannel *sub = ast->tech_pvt;
02680    int res = 0;
02681    if (frame->frametype != AST_FRAME_VOICE) {
02682       if (frame->frametype == AST_FRAME_IMAGE) {
02683          return 0;
02684       } else {
02685          ast_log(LOG_WARNING, "Can't send %d type frames with skinny_write\n", frame->frametype);
02686          return 0;
02687       }
02688    } else {
02689       if (!(frame->subclass & ast->nativeformats)) {
02690          ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
02691             frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat);
02692          return -1;
02693       }
02694    }
02695    if (sub) {
02696       ast_mutex_lock(&sub->lock);
02697       if (sub->rtp) {
02698          res = ast_rtp_write(sub->rtp, frame);
02699       }
02700       ast_mutex_unlock(&sub->lock);
02701    }
02702    return res;
02703 }

static void start_rtp ( struct skinny_subchannel sub  )  [static]

Definition at line 2329 of file chan_skinny.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_rtcp_fd(), ast_rtp_codec_setpref(), ast_rtp_fd(), ast_rtp_new_with_bindaddr(), ast_rtp_setnat(), bindaddr, ast_channel::fds, skinny_subchannel::lock, skinny_line::nat, skinny_subchannel::owner, skinny_line::parent, skinny_subchannel::parent, skinny_line::prefs, skinny_subchannel::rtp, skinny_device::session, transmit_connect(), and skinny_subchannel::vrtp.

02330 {
02331    struct skinny_line *l = sub->parent;
02332    struct skinny_device *d = l->parent;
02333    int hasvideo = 0;
02334 
02335    ast_mutex_lock(&sub->lock);
02336    /* Allocate the RTP */
02337    sub->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
02338    if (hasvideo)
02339       sub->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
02340    
02341    if (sub->rtp && sub->owner) {
02342       sub->owner->fds[0] = ast_rtp_fd(sub->rtp);
02343       sub->owner->fds[1] = ast_rtcp_fd(sub->rtp);
02344    }
02345    if (hasvideo && sub->vrtp && sub->owner) {
02346       sub->owner->fds[2] = ast_rtp_fd(sub->vrtp);
02347       sub->owner->fds[3] = ast_rtcp_fd(sub->vrtp);
02348    }
02349    if (sub->rtp) {
02350       ast_rtp_setnat(sub->rtp, l->nat);
02351    }
02352    if (sub->vrtp) {
02353       ast_rtp_setnat(sub->vrtp, l->nat);
02354    }
02355    /* Set Frame packetization */
02356    if (sub->rtp)
02357       ast_rtp_codec_setpref(sub->rtp, &l->prefs);
02358 
02359    /* Create the RTP connection */
02360    transmit_connect(d->session, sub);
02361    ast_mutex_unlock(&sub->lock);
02362 }

static void transmit_callinfo ( struct skinnysession s,
const char *  fromname,
const char *  fromnum,
const char *  toname,
const char *  tonum,
int  instance,
int  callid,
int  calltype 
) [static]

Definition at line 1531 of file chan_skinny.c.

References ast_verbose(), CALL_INFO_MESSAGE, call_info_message::calledParty, call_info_message::calledPartyName, skinny_data::callinfo, call_info_message::callingParty, call_info_message::callingPartyName, skinny_req::data, skinnysession::device, htolel, call_info_message::instance, skinny_device::name, call_info_message::reference, req_alloc(), transmit_response(), and call_info_message::type.

Referenced by skinny_answer(), skinny_call(), and skinny_indicate().

01532 {
01533    struct skinny_req *req;
01534 
01535    if (!(req = req_alloc(sizeof(struct call_info_message), CALL_INFO_MESSAGE)))
01536       return;
01537 
01538    if (skinnydebug)
01539          ast_verbose("Setting Callinfo to %s(%s) from %s(%s) on %s(%d)\n", fromname, fromnum, toname, tonum, s->device->name, instance);
01540 
01541    if (fromname) {
01542       ast_copy_string(req->data.callinfo.callingPartyName, fromname, sizeof(req->data.callinfo.callingPartyName));
01543    }
01544    if (fromnum) {
01545       ast_copy_string(req->data.callinfo.callingParty, fromnum, sizeof(req->data.callinfo.callingParty));
01546    }
01547    if (toname) {
01548       ast_copy_string(req->data.callinfo.calledPartyName, toname, sizeof(req->data.callinfo.calledPartyName));
01549    }
01550    if (tonum) {
01551       ast_copy_string(req->data.callinfo.calledParty, tonum, sizeof(req->data.callinfo.calledParty));
01552    }
01553    req->data.callinfo.instance = htolel(instance);
01554    req->data.callinfo.reference = htolel(callid);
01555    req->data.callinfo.type = htolel(calltype);
01556    transmit_response(s, req);
01557 }

static void transmit_callstate ( struct skinnysession s,
int  instance,
int  state,
unsigned  callid 
) [static]

Definition at line 1743 of file chan_skinny.c.

References ACTIVATE_CALL_PLANE_MESSAGE, skinny_data::activatecallplane, CALL_STATE_MESSAGE, call_state_message::callReference, call_state_message::callState, skinny_data::callstate, CLOSE_RECEIVE_CHANNEL_MESSAGE, skinny_data::closereceivechannel, stop_media_transmission_message::conferenceId, close_receive_channel_message::conferenceId, skinny_req::data, htolel, KEYDEF_ONHOOK, activate_call_plane_message::lineInstance, call_state_message::lineInstance, close_receive_channel_message::partyId, stop_media_transmission_message::passThruPartyId, req_alloc(), SKINNY_OFFHOOK, SKINNY_ONHOOK, SKINNY_SPEAKEROFF, STOP_MEDIA_TRANSMISSION_MESSAGE, skinny_data::stopmedia, transmit_displaypromptstatus(), transmit_response(), transmit_selectsoftkeys(), and transmit_speaker_mode().

Referenced by handle_enbloc_call_message(), handle_offhook_message(), handle_onhook_message(), handle_soft_key_event_message(), handle_stimulus_message(), skinny_answer(), skinny_call(), skinny_hangup(), and skinny_indicate().

01744 {
01745    struct skinny_req *req;
01746 
01747    if (state == SKINNY_ONHOOK) {
01748       if (!(req = req_alloc(sizeof(struct close_receive_channel_message), CLOSE_RECEIVE_CHANNEL_MESSAGE)))
01749          return;
01750 
01751       req->data.closereceivechannel.conferenceId = htolel(callid);
01752       req->data.closereceivechannel.partyId = htolel(callid);
01753       transmit_response(s, req);
01754 
01755       if (!(req = req_alloc(sizeof(struct stop_media_transmission_message), STOP_MEDIA_TRANSMISSION_MESSAGE)))
01756          return;
01757 
01758       req->data.stopmedia.conferenceId = htolel(callid);
01759       req->data.stopmedia.passThruPartyId = htolel(callid);
01760       transmit_response(s, req);
01761 
01762       transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
01763 
01764       transmit_displaypromptstatus(s, NULL, 0, instance, callid);
01765    }
01766 
01767    if (!(req = req_alloc(sizeof(struct call_state_message), CALL_STATE_MESSAGE)))
01768       return;
01769 
01770    req->data.callstate.callState = htolel(state);
01771    req->data.callstate.lineInstance = htolel(instance);
01772    req->data.callstate.callReference = htolel(callid);
01773    transmit_response(s, req);
01774 
01775    if (state == SKINNY_ONHOOK) {
01776       transmit_selectsoftkeys(s, 0, 0, KEYDEF_ONHOOK);
01777    }
01778 
01779    if (state == SKINNY_OFFHOOK || state == SKINNY_ONHOOK) {
01780       if (!(req = req_alloc(sizeof(struct activate_call_plane_message), ACTIVATE_CALL_PLANE_MESSAGE)))
01781          return;
01782 
01783       req->data.activatecallplane.lineInstance = htolel(instance);
01784       transmit_response(s, req);
01785    }
01786 }

static void transmit_connect ( struct skinnysession s,
struct skinny_subchannel sub 
) [static]

static void transmit_dialednumber ( struct skinnysession s,
const char *  text,
int  instance,
int  callid 
) [static]

Definition at line 1729 of file chan_skinny.c.

References dialed_number_message::callReference, skinny_req::data, DIALED_NUMBER_MESSAGE, dialed_number_message::dialedNumber, skinny_data::dialednumber, htolel, dialed_number_message::lineInstance, req_alloc(), and transmit_response().

Referenced by skinny_answer(), and skinny_indicate().

01730 {
01731    struct skinny_req *req;
01732 
01733    if (!(req = req_alloc(sizeof(struct dialed_number_message), DIALED_NUMBER_MESSAGE)))
01734       return;
01735 
01736    ast_copy_string(req->data.dialednumber.dialedNumber, text, sizeof(req->data.dialednumber.dialedNumber));
01737    req->data.dialednumber.lineInstance = htolel(instance);
01738    req->data.dialednumber.callReference = htolel(callid);
01739 
01740    transmit_response(s, req);
01741 }

static void transmit_displaymessage ( struct skinnysession s,
const char *  text,
int  instance,
int  reference 
) [static]

Definition at line 1659 of file chan_skinny.c.

References ast_verbose(), clear_prompt_message::callReference, CLEAR_DISPLAY_MESSAGE, skinny_data::clearpromptstatus, skinny_req::data, skinny_data::displaytext, DISPLAYTEXT_MESSAGE, clear_prompt_message::lineInstance, req_alloc(), displaytext_message::text, and transmit_response().

Referenced by handle_enbloc_call_message(), handle_offhook_message(), handle_soft_key_event_message(), and handle_stimulus_message().

01660 {
01661    struct skinny_req *req;
01662 
01663    if (text == 0) {
01664       if (!(req = req_alloc(0, CLEAR_DISPLAY_MESSAGE)))
01665          return;
01666 
01667       req->data.clearpromptstatus.lineInstance = instance;
01668       req->data.clearpromptstatus.callReference = reference;
01669 
01670       if (skinnydebug)
01671          ast_verbose("Clearing Display\n");
01672    } else {
01673       if (!(req = req_alloc(sizeof(struct displaytext_message), DISPLAYTEXT_MESSAGE)))
01674          return;
01675 
01676       ast_copy_string(req->data.displaytext.text, text, sizeof(req->data.displaytext.text));
01677       if (skinnydebug)
01678          ast_verbose("Displaying message '%s'\n", req->data.displaytext.text);
01679    }
01680 
01681    transmit_response(s, req);
01682 }

static void transmit_displaynotify ( struct skinnysession s,
const char *  text,
int  t 
) [static]

Definition at line 1684 of file chan_skinny.c.

References ast_verbose(), skinny_req::data, DISPLAY_NOTIFY_MESSAGE, display_notify_message::displayMessage, skinny_data::displaynotify, display_notify_message::displayTimeout, htolel, req_alloc(), and transmit_response().

Referenced by handle_soft_key_event_message(), and handle_stimulus_message().

01685 {
01686    struct skinny_req *req;
01687 
01688    if (!(req = req_alloc(sizeof(struct display_notify_message), DISPLAY_NOTIFY_MESSAGE)))
01689       return;
01690 
01691    ast_copy_string(req->data.displaynotify.displayMessage, text, sizeof(req->data.displaynotify.displayMessage));
01692    req->data.displaynotify.displayTimeout = htolel(t);
01693 
01694    if (skinnydebug)
01695       ast_verbose("Displaying notify '%s'\n", text);
01696 
01697    transmit_response(s, req);
01698 }

static void transmit_displaypromptstatus ( struct skinnysession s,
const char *  text,
int  t,
int  instance,
int  callid 
) [static]

Definition at line 1700 of file chan_skinny.c.

References ast_verbose(), display_prompt_status_message::callReference, clear_prompt_message::callReference, CLEAR_PROMPT_MESSAGE, skinny_data::clearpromptstatus, skinny_req::data, DISPLAY_PROMPT_STATUS_MESSAGE, skinny_data::displaypromptstatus, htolel, display_prompt_status_message::lineInstance, clear_prompt_message::lineInstance, display_prompt_status_message::messageTimeout, display_prompt_status_message::promptMessage, req_alloc(), and transmit_response().

Referenced by handle_stimulus_message(), skinny_answer(), skinny_call(), skinny_indicate(), and transmit_callstate().

01701 {
01702    struct skinny_req *req;
01703 
01704    if (text == 0) {
01705       if (!(req = req_alloc(sizeof(struct clear_prompt_message), CLEAR_PROMPT_MESSAGE)))
01706          return;
01707 
01708       req->data.clearpromptstatus.lineInstance = htolel(instance);
01709       req->data.clearpromptstatus.callReference = htolel(callid);
01710 
01711       if (skinnydebug)
01712          ast_verbose("Clearing Prompt\n");
01713    } else {
01714       if (!(req = req_alloc(sizeof(struct display_prompt_status_message), DISPLAY_PROMPT_STATUS_MESSAGE)))
01715          return;
01716 
01717       ast_copy_string(req->data.displaypromptstatus.promptMessage, text, sizeof(req->data.displaypromptstatus.promptMessage));
01718       req->data.displaypromptstatus.messageTimeout = htolel(t);
01719       req->data.displaypromptstatus.lineInstance = htolel(instance);
01720       req->data.displaypromptstatus.callReference = htolel(callid);
01721 
01722       if (skinnydebug)
01723          ast_verbose("Displaying Prompt Status '%s'\n", text);
01724    }
01725 
01726    transmit_response(s, req);
01727 }

static void transmit_lamp_indication ( struct skinnysession s,
int  stimulus,
int  instance,
int  indication 
) [static]

static int transmit_response ( struct skinnysession s,
struct skinny_req req 
) [static]

Definition at line 1469 of file chan_skinny.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), skinny_req::data, skinny_req::e, errno, skinnysession::fd, skinny_req::len, letohl, skinnysession::lock, LOG_VERBOSE, LOG_WARNING, skinnysession::outbuf, SKINNY_MAX_PACKET, and skinny_unregister().

01470 {
01471    int res = 0;
01472 
01473    if (!s) {
01474       ast_log(LOG_WARNING, "Asked to transmit to a non-existant session!\n");
01475       return -1;
01476    }
01477 
01478    ast_mutex_lock(&s->lock);
01479 
01480    if (skinnydebug)
01481       ast_log(LOG_VERBOSE, "writing packet type %04X (%d bytes) to socket %d\n", letohl(req->e), letohl(req->len)+8, s->fd);
01482 
01483    if (letohl(req->len > SKINNY_MAX_PACKET) || letohl(req->len < 0)) {
01484       ast_log(LOG_WARNING, "transmit_response: the length of the request is out of bounds\n");
01485       return -1;
01486    }
01487 
01488    memset(s->outbuf,0,sizeof(s->outbuf));
01489    memcpy(s->outbuf, req, skinny_header_size);
01490    memcpy(s->outbuf+skinny_header_size, &req->data, letohl(req->len));
01491 
01492    res = write(s->fd, s->outbuf, letohl(req->len)+8);
01493 
01494    if (res != letohl(req->len)+8) {
01495       ast_log(LOG_WARNING, "Transmit: write only sent %d out of %d bytes: %s\n", res, letohl(req->len)+8, strerror(errno));
01496       if (res == -1) {
01497          if (skinnydebug)
01498             ast_log(LOG_WARNING, "Transmit: Skinny Client was lost, unregistering\n");
01499          skinny_unregister(NULL, s);
01500       }
01501       
01502    }
01503    
01504    ast_mutex_unlock(&s->lock);
01505    return 1;
01506 }

static void transmit_ringer_mode ( struct skinnysession s,
int  mode 
) [static]

Definition at line 1634 of file chan_skinny.c.

References ast_verbose(), skinny_req::data, htolel, req_alloc(), set_ringer_message::ringerMode, SET_RINGER_MESSAGE, skinny_data::setringer, transmit_response(), set_ringer_message::unknown1, and set_ringer_message::unknown2.

Referenced by handle_offhook_message(), handle_soft_key_event_message(), handle_stimulus_message(), skinny_call(), and skinny_hangup().

01635 {
01636    struct skinny_req *req;
01637 
01638    if (skinnydebug)
01639       ast_verbose("Setting ringer mode to '%d'.\n", mode);
01640 
01641    if (!(req = req_alloc(sizeof(struct set_ringer_message), SET_RINGER_MESSAGE)))
01642       return;
01643 
01644    req->data.setringer.ringerMode = htolel(mode);
01645    /* XXX okay, I don't quite know what this is, but here's what happens (on a 7960).
01646       Note: The phone will always show as ringing on the display.
01647 
01648       1: phone will audibly ring over and over
01649       2: phone will audibly ring only once
01650       any other value, will NOT cause the phone to audibly ring
01651    */
01652    req->data.setringer.unknown1 = htolel(1);
01653    /* XXX the value here doesn't seem to change anything.  Must be higher than 0.
01654       Perhaps a packet capture can shed some light on this. */
01655    req->data.setringer.unknown2 = htolel(1);
01656    transmit_response(s, req);
01657 }

static void transmit_selectsoftkeys ( struct skinnysession s,
int  instance,
int  callid,
int  softkey 
) [static]

static void transmit_speaker_mode ( struct skinnysession s,
int  mode 
) [static]

Definition at line 1508 of file chan_skinny.c.

References skinny_req::data, htolel, set_speaker_message::mode, req_alloc(), SET_SPEAKER_MESSAGE, skinny_data::setspeaker, and transmit_response().

Referenced by handle_soft_key_event_message(), handle_stimulus_message(), skinny_hangup(), and transmit_callstate().

01509 {
01510    struct skinny_req *req;
01511 
01512    if (!(req = req_alloc(sizeof(struct set_speaker_message), SET_SPEAKER_MESSAGE)))
01513       return;
01514 
01515    req->data.setspeaker.mode = htolel(mode);
01516    transmit_response(s, req);
01517 }

static void transmit_tone ( struct skinnysession s,
int  tone,
int  instance,
int  reference 
) [static]

Definition at line 1579 of file chan_skinny.c.

References skinny_req::data, htolel, stop_tone_message::instance, start_tone_message::instance, stop_tone_message::reference, start_tone_message::reference, req_alloc(), SKINNY_NOTONE, START_TONE_MESSAGE, skinny_data::starttone, STOP_TONE_MESSAGE, skinny_data::stoptone, start_tone_message::tone, and transmit_response().

Referenced by handle_enbloc_call_message(), handle_offhook_message(), handle_soft_key_event_message(), handle_stimulus_message(), skinny_answer(), skinny_hangup(), skinny_indicate(), skinny_newcall(), skinny_senddigit_end(), and skinny_ss().

01580 {
01581    struct skinny_req *req;
01582 
01583    if (tone == SKINNY_NOTONE) {
01584       /* This is bad, mmm'kay? */
01585       return;
01586    }
01587 
01588    if (tone > 0) {
01589       if (!(req = req_alloc(sizeof(struct start_tone_message), START_TONE_MESSAGE)))
01590          return;
01591       req->data.starttone.tone = htolel(tone);
01592       req->data.starttone.instance = htolel(instance);
01593       req->data.starttone.reference = htolel(reference);
01594    } else {
01595       if (!(req = req_alloc(sizeof(struct stop_tone_message), STOP_TONE_MESSAGE)))
01596          return;
01597       req->data.stoptone.instance = htolel(instance);
01598       req->data.stoptone.reference = htolel(reference);
01599    }
01600 
01601    if (tone > 0) {
01602       req->data.starttone.tone = htolel(tone);
01603    }
01604    transmit_response(s, req);
01605 }

static int unload_module ( void   )  [static]

Definition at line 5008 of file chan_skinny.c.

References skinny_subchannel::alreadygone, ast_channel_unregister(), ast_cli_unregister_multiple(), ast_mutex_destroy(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_rtp_proto_unregister(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, delete_devices(), skinnysession::device, skinnysession::fd, free, skinny_device::lines, skinnysession::lock, skinny_subchannel::lock, skinny_line::lock, skinny_subchannel::next, skinny_line::next, skinny_device::next, skinnysession::next, skinny_subchannel::owner, s, sched_context_destroy(), sessions, and skinny_line::sub.

05009 {
05010    struct skinnysession *s, *slast;
05011    struct skinny_device *d;
05012    struct skinny_line *l;
05013    struct skinny_subchannel *sub;
05014 
05015    ast_mutex_lock(&sessionlock);
05016    /* Destroy all the interfaces and free their memory */
05017    s = sessions;
05018    while(s) {
05019       slast = s;
05020       s = s->next;
05021       for (d = slast->device; d; d = d->next) {
05022          for (l = d->lines; l; l = l->next) {
05023             ast_mutex_lock(&l->lock);
05024             for (sub = l->sub; sub; sub = sub->next) {
05025                ast_mutex_lock(&sub->lock);
05026                if (sub->owner) {
05027                   sub->alreadygone = 1;
05028                   ast_softhangup(sub->owner, AST_SOFTHANGUP_APPUNLOAD);
05029                }
05030                ast_mutex_unlock(&sub->lock);
05031             }
05032             ast_mutex_unlock(&l->lock);
05033          }
05034       }
05035       if (slast->fd > -1)
05036          close(slast->fd);
05037       ast_mutex_destroy(&slast->lock);
05038       free(slast);
05039    }
05040    sessions = NULL;
05041    ast_mutex_unlock(&sessionlock);
05042 
05043    delete_devices();
05044 
05045    ast_mutex_lock(&monlock);
05046    if ((monitor_thread != AST_PTHREADT_NULL) && (monitor_thread != AST_PTHREADT_STOP)) {
05047       pthread_cancel(monitor_thread);
05048       pthread_kill(monitor_thread, SIGURG);
05049       pthread_join(monitor_thread, NULL);
05050    }
05051    monitor_thread = AST_PTHREADT_STOP;
05052    ast_mutex_unlock(&monlock);
05053 
05054    ast_mutex_lock(&netlock);
05055    if (accept_t && (accept_t != AST_PTHREADT_STOP)) {
05056       pthread_cancel(accept_t);
05057       pthread_kill(accept_t, SIGURG);
05058       pthread_join(accept_t, NULL);
05059    }
05060    accept_t = AST_PTHREADT_STOP;
05061    ast_mutex_unlock(&netlock);
05062 
05063    ast_rtp_proto_unregister(&skinny_rtp);
05064    ast_channel_unregister(&skinny_tech);
05065    ast_cli_unregister_multiple(cli_skinny, sizeof(cli_skinny) / sizeof(struct ast_cli_entry));
05066 
05067    close(skinnysock);
05068    if (sched)
05069       sched_context_destroy(sched);
05070 
05071    return 0;
05072 }


Variable Documentation

struct in_addr __ourip [static]

Definition at line 790 of file chan_skinny.c.

pthread_t accept_t [static]

Definition at line 794 of file chan_skinny.c.

char accountcode[AST_MAX_ACCOUNT_CODE] = "" [static]

Definition at line 814 of file chan_skinny.c.

struct ast_hostent ahp

Definition at line 791 of file chan_skinny.c.

Referenced by reload_config(), and rpt_exec().

int amaflags = 0 [static]

Definition at line 816 of file chan_skinny.c.

int auth_limit = DEFAULT_AUTH_LIMIT [static]

Definition at line 104 of file chan_skinny.c.

int auth_timeout = DEFAULT_AUTH_TIMEOUT [static]

Definition at line 103 of file chan_skinny.c.

struct sockaddr_in bindaddr [static]

Definition at line 787 of file chan_skinny.c.

int callnums = 1 [static]

Definition at line 817 of file chan_skinny.c.

int callreturn = 0 [static]

Definition at line 807 of file chan_skinny.c.

int callwaiting = 0 [static]

Definition at line 806 of file chan_skinny.c.

int cancallforward = 0 [static]

Definition at line 812 of file chan_skinny.c.

char cid_name[AST_MAX_EXTENSION] = "" [static]

Definition at line 800 of file chan_skinny.c.

char cid_num[AST_MAX_EXTENSION] = "" [static]

Definition at line 799 of file chan_skinny.c.

struct ast_cli_entry cli_skinny[] [static]

Definition at line 2108 of file chan_skinny.c.

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

Definition at line 81 of file chan_skinny.c.

char context[AST_MAX_CONTEXT] = "default" [static]

Definition at line 795 of file chan_skinny.c.

Definition at line 803 of file chan_skinny.c.

Definition at line 804 of file chan_skinny.c.

char date_format[6] = "D-M-Y" [static]

Definition at line 106 of file chan_skinny.c.

char debug_usage[] [static]

Initial value:

"Usage: skinny set debug\n"
"       Enables dumping of Skinny packets for debugging purposes\n"

Definition at line 2096 of file chan_skinny.c.

int default_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW [static]

Definition at line 83 of file chan_skinny.c.

struct ast_jb_conf default_jbconf [static]

Global jitterbuffer configuration - by default, jb is disabled

Definition at line 134 of file chan_skinny.c.

struct ast_codec_pref default_prefs [static]

Definition at line 84 of file chan_skinny.c.

struct skinny_device * devices [static]

int firstdigittimeout = 16000 [static]

Definition at line 942 of file chan_skinny.c.

int gendigittimeout = 8000 [static]

Definition at line 945 of file chan_skinny.c.

struct ast_jb_conf global_jbconf [static]

Definition at line 141 of file chan_skinny.c.

struct hostent* hp

int immediate = 0 [static]

Definition at line 805 of file chan_skinny.c.

struct io_context* io [static]

Definition at line 921 of file chan_skinny.c.

int keep_alive = 120 [static]

Definition at line 102 of file chan_skinny.c.

char language[MAX_LANGUAGE] = "" [static]

Definition at line 796 of file chan_skinny.c.

char linelabel[AST_MAX_EXTENSION] = "" [static]

Definition at line 801 of file chan_skinny.c.

char mailbox[AST_MAX_EXTENSION] [static]

Definition at line 815 of file chan_skinny.c.

int matchdigittimeout = 3000 [static]

Definition at line 948 of file chan_skinny.c.

char mohinterpret[MAX_MUSICCLASS] = "default" [static]

Definition at line 797 of file chan_skinny.c.

char mohsuggest[MAX_MUSICCLASS] = "" [static]

Definition at line 798 of file chan_skinny.c.

pthread_t monitor_thread = AST_PTHREADT_NULL [static]

Definition at line 939 of file chan_skinny.c.

int mwiblink = 0 [static]

Definition at line 809 of file chan_skinny.c.

int nat = 0 [static]

Definition at line 802 of file chan_skinny.c.

char no_debug_usage[] [static]

Initial value:

"Usage: skinny set debug off\n"
"       Disables dumping of Skinny packets for debugging purposes\n"

Definition at line 2100 of file chan_skinny.c.

char ourhost[256] [static]

Definition at line 788 of file chan_skinny.c.

int ourport [static]

Definition at line 789 of file chan_skinny.c.

char reset_usage[] [static]

Initial value:

"Usage: skinny reset <DeviceId|all> [restart]\n"
"       Causes a Skinny device to reset itself, optionally with a full restart\n"

Definition at line 2104 of file chan_skinny.c.

struct sched_context* sched = NULL [static]

Definition at line 920 of file chan_skinny.c.

struct skinnysession * sessions [static]

char show_devices_usage[] [static]

Initial value:

"Usage: skinny show devices\n"
"       Lists all devices known to the Skinny subsystem.\n"

Definition at line 2088 of file chan_skinny.c.

char show_lines_usage[] [static]

Initial value:

"Usage: skinny show lines\n"
"       Lists all lines known to the Skinny subsystem.\n"

Definition at line 2092 of file chan_skinny.c.

Definition at line 778 of file chan_skinny.c.

struct ast_rtp_protocol skinny_rtp [static]

Definition at line 1861 of file chan_skinny.c.

struct ast_channel_tech skinny_tech [static]

Definition at line 1089 of file chan_skinny.c.

int skinnydebug = 0 [static]

Definition at line 784 of file chan_skinny.c.

int skinnysock = -1 [static]

Definition at line 793 of file chan_skinny.c.

const uint8_t soft_key_default_connected[] [static]

Definition at line 576 of file chan_skinny.c.

const uint8_t soft_key_default_connwithconf[] [static]

Initial value:

Definition at line 620 of file chan_skinny.c.

const uint8_t soft_key_default_connwithtrans[] [static]

Definition at line 606 of file chan_skinny.c.

const uint8_t soft_key_default_dadfd[] [static]

Initial value:

Definition at line 615 of file chan_skinny.c.

Definition at line 638 of file chan_skinny.c.

const uint8_t soft_key_default_offhook[] [static]

Definition at line 598 of file chan_skinny.c.

const uint8_t soft_key_default_offhookwithfeat[] [static]

Initial value:

Definition at line 629 of file chan_skinny.c.

const uint8_t soft_key_default_onhold[] [static]

Definition at line 585 of file chan_skinny.c.

const uint8_t soft_key_default_onhook[] [static]

Definition at line 567 of file chan_skinny.c.

const uint8_t soft_key_default_ringin[] [static]

Initial value:

Definition at line 592 of file chan_skinny.c.

const uint8_t soft_key_default_ringout[] [static]

Initial value:

Definition at line 624 of file chan_skinny.c.

const uint8_t soft_key_default_unknown[] [static]

Initial value:

Definition at line 634 of file chan_skinny.c.

Definition at line 540 of file chan_skinny.c.

const char tdesc[] = "Skinny Client Control Protocol (Skinny)" [static]

Definition at line 80 of file chan_skinny.c.

int threewaycalling = 0 [static]

Definition at line 808 of file chan_skinny.c.

int transfer = 0 [static]

Definition at line 811 of file chan_skinny.c.

int unauth_sessions = 0 [static]

Definition at line 105 of file chan_skinny.c.

char version_id[16] = "P002F202" [static]

Definition at line 107 of file chan_skinny.c.


Generated on Sun Dec 18 20:55:48 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.6