Sat Oct 11 06:50:23 2008

Asterisk developer's documentation


chan_skinny.c File Reference

Implementation of the Skinny protocol. More...

#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.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 dependency graph for chan_skinny.c:

Go to the source code of this file.

Data Structures

struct  activate_call_plane_message
struct  button_defs
struct  button_template_res_message
struct  buttondefinition
struct  call_info_message
struct  call_state_message
struct  capabilities_res_message
struct  close_recieve_channel_message
struct  definetimedate_message
struct  dialled_number_message
struct  display_notify_message
struct  display_prompt_status_message
struct  displaytext_message
struct  keypad_button_message
struct  line_stat_res_message
struct  line_state_req_message
struct  media_qualifier
struct  open_recieve_channel_ack_message
struct  open_recieve_channel_message
struct  register_ack_message
struct  register_message
struct  register_rej_message
struct  select_soft_keys_message
struct  server_identifier
struct  server_res_message
struct  set_lamp_message
struct  set_ringer_message
struct  set_speaker_message
struct  skinny_device
struct  skinny_line
struct  skinny_paging_device
struct  skinny_req
struct  skinny_subchannel
struct  skinnysession
struct  soft_key_set_definition
struct  soft_key_sets
struct  soft_key_template
struct  soft_key_template_definition
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  version_res_message

Defines

#define ACTIVATE_CALL_PLANE_MESSAGE   0x0116
#define ALARM_MESSAGE   0x0020
#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 CLOSE_RECIEVE_CHANNEL_MESSAGE   0x0106
#define DEFAULT_SKINNY_BACKLOG   2
#define DEFAULT_SKINNY_PORT   2000
#define DEFINETIMEDATE_MESSAGE   0x0094
#define DIALLED_NUMBER_MESSAGE   0x011D
#define DISPLAY_NOTIFY_MESSAGE   0x0114
#define DISPLAY_PROMPT_STATUS_MESSAGE   0x0112
#define DISPLAYTEXT_MESSAGE   0x0099
#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 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 MAX_SUBS   2
#define OFFHOOK_MESSAGE   0x0006
#define ONHOOK_MESSAGE   0x0007
#define OPEN_RECIEVE_CHANNEL_ACK_MESSAGE   0x0022
#define OPEN_RECIEVE_CHANNEL_MESSAGE   0x0105
#define REGISTER_ACK_MESSAGE   0x0081
#define REGISTER_MESSAGE   0x0001
#define REGISTER_REJ_MESSAGE   0x009D
#define SELECT_SOFT_KEYS_MESSAGE   0x0110
#define SERVER_REQUEST_MESSAGE   0x0012
#define SERVER_RES_MESSAGE   0x009E
#define SET_LAMP_MESSAGE   0x0086
#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_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_PACKET   1000
#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_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 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 SUB_ALT   1
#define SUB_REAL   0
#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

Typedefs

typedef buttondefinition button_definition
typedef button_defs button_defs_t
typedef unsigned short UINT16
typedef unsigned int UINT32
typedef unsigned char UINT8

Functions

static void * accept_thread (void *ignore)
 AST_MUTEX_DEFINE_STATIC (devicelock)
 AST_MUTEX_DEFINE_STATIC (sessionlock)
 AST_MUTEX_DEFINE_STATIC (netlock)
 AST_MUTEX_DEFINE_STATIC (monlock)
 AST_MUTEX_DEFINE_STATIC (usecnt_lock)
static struct skinny_devicebuild_device (char *cat, struct ast_variable *v)
static char * control2str (int ind)
static int convert_cap (int capability)
static void delete_devices (void)
char * description ()
 Provides a description of the module.
static void destroy_session (struct skinnysession *s)
static void do_housekeeping (struct skinnysession *s)
static void * do_monitor (void *data)
static struct skinny_subchannelfind_subchannel_by_line (struct skinny_line *l)
static struct skinny_subchannelfind_subchannel_by_name (char *dest)
static int get_input (struct skinnysession *s)
static int handle_message (skinny_req *req, struct skinnysession *s)
static int has_voicemail (struct skinny_line *l)
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module ()
 Initialize the module.
int reload (void)
 Reload stuff.
static int reload_config (void)
static skinny_reqreq_alloc (size_t size)
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 struct ast_rtpskinny_get_rtp_peer (struct ast_channel *chan)
static struct ast_rtpskinny_get_vrtp_peer (struct ast_channel *chan)
static int skinny_hangup (struct ast_channel *ast)
static int skinny_indicate (struct ast_channel *ast, int ind)
static struct ast_channelskinny_new (struct skinny_subchannel *sub, int state)
static int skinny_no_debug (int fd, int argc, char *argv[])
static struct ast_frameskinny_read (struct ast_channel *ast)
static int skinny_register (skinny_req *req, struct skinnysession *s)
static skinny_reqskinny_req_parse (struct skinnysession *s)
static struct ast_channelskinny_request (const char *type, int format, void *data, int *cause)
static struct ast_frameskinny_rtp_read (struct skinny_subchannel *sub)
static int skinny_senddigit (struct ast_channel *ast, char digit)
static void * skinny_session (void *data)
static int skinny_set_rtp_peer (struct ast_channel *chan, 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_write (struct ast_channel *ast, struct ast_frame *frame)
static void start_rtp (struct skinny_subchannel *sub)
static void transmit_callinfo (struct skinnysession *s, char *fromname, char *fromnum, char *toname, 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)
static void transmit_diallednumber (struct skinnysession *s, char *text, int instance, int callid)
static void transmit_displaymessage (struct skinnysession *s, char *text)
static void transmit_displaynotify (struct skinnysession *s, char *text, int t)
static void transmit_displaypromptstatus (struct skinnysession *s, 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, skinny_req *req)
static void transmit_ringer_mode (struct skinnysession *s, int mode)
static void transmit_speaker_mode (struct skinnysession *s, int mode)
static void transmit_tone (struct skinnysession *s, int tone)
int unload_module ()
 Cleanup all module structures, sockets, etc.
int usecount ()
 Provides a usecount.

Variables

static struct in_addr __ourip
static pthread_t accept_t
static char accountcode [AST_MAX_ACCOUNT_CODE] = ""
ast_hostent ahp
static int amaflags = 0
static struct sockaddr_in bindaddr
button_definition button_def_12sp []
button_definition button_def_30vip []
button_definition button_def_7902 []
button_definition button_def_7910 []
button_definition button_def_7920 []
button_definition button_def_7935 []
button_definition button_def_7940 []
button_definition button_def_7960 []
button_definition button_def_7970 []
button_definition button_def_none = { 0, STIMULUS_NONE }
button_defs_t button_defs []
static int callnums = 1
static int callreturn = 0
static int callwaiting = 0
static int cancallforward = 0
static int capability = AST_FORMAT_ULAW
static char cid_name [AST_MAX_EXTENSION] = ""
static char cid_num [AST_MAX_EXTENSION] = ""
static struct ast_cli_entry cli_debug
static struct ast_cli_entry cli_no_debug
static struct ast_cli_entry cli_show_devices
static struct ast_cli_entry cli_show_lines
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 const char desc [] = "Skinny Client Control Protocol (Skinny)"
static struct skinny_devicedevices
static int firstdigittimeout = 16000
static int gendigittimeout = 8000
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 pthread_t monitor_thread = AST_PTHREADT_NULL
static char musicclass [MAX_MUSICCLASS] = ""
static int mwiblink = 0
static int nat = 0
static char no_debug_usage []
static char ourhost [256]
static int ourport
static struct sched_contextsched
static struct skinnysessionsessions
static char show_devices_usage []
static char show_lines_usage []
static struct ast_rtp_protocol skinny_rtp
static struct ast_channel_tech skinny_tech
static int skinnydebug = 1
static int skinnysock = -1
static const char * soft_key_set_hack
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 const char type [] = "Skinny"
static int usecnt = 0
static char version_id [16] = "P002F202"


Detailed Description

Implementation of the Skinny protocol.

Author:
Jeremy McNamara & Florian Overkamp

Definition in file chan_skinny.c.


Define Documentation

#define ACTIVATE_CALL_PLANE_MESSAGE   0x0116

Definition at line 618 of file chan_skinny.c.

Referenced by transmit_callstate().

#define ALARM_MESSAGE   0x0020

Definition at line 183 of file chan_skinny.c.

Referenced by handle_message().

#define BUTTON_TEMPLATE_REQ_MESSAGE   0x000E

Definition at line 181 of file chan_skinny.c.

Referenced by handle_message().

#define BUTTON_TEMPLATE_RES_MESSAGE   0x0097

Definition at line 320 of file chan_skinny.c.

Referenced by handle_message().

#define CALL_INFO_MESSAGE   0x008F

Definition at line 254 of file chan_skinny.c.

Referenced by transmit_callinfo().

#define CALL_STATE_MESSAGE   0x0111

Definition at line 597 of file chan_skinny.c.

Referenced by transmit_callstate().

#define CAPABILITIES_REQ_MESSAGE   0x009B

Definition at line 307 of file chan_skinny.c.

Referenced by handle_message().

#define CAPABILITIES_RES_MESSAGE   0x0010

Definition at line 154 of file chan_skinny.c.

Referenced by handle_message().

#define CLEAR_DISPLAY_MESSAGE   0x009A

Definition at line 300 of file chan_skinny.c.

Referenced by transmit_displaymessage().

#define CLOSE_RECIEVE_CHANNEL_MESSAGE   0x0106

Definition at line 498 of file chan_skinny.c.

Referenced by transmit_callstate().

#define DEFAULT_SKINNY_BACKLOG   2

Definition at line 84 of file chan_skinny.c.

Referenced by reload_config().

#define DEFAULT_SKINNY_PORT   2000

Definition at line 83 of file chan_skinny.c.

Referenced by build_device(), and reload_config().

#define DEFINETIMEDATE_MESSAGE   0x0094

Definition at line 282 of file chan_skinny.c.

Referenced by handle_message().

#define DIALLED_NUMBER_MESSAGE   0x011D

Definition at line 623 of file chan_skinny.c.

Referenced by transmit_diallednumber().

#define DISPLAY_NOTIFY_MESSAGE   0x0114

Definition at line 612 of file chan_skinny.c.

Referenced by transmit_displaynotify().

#define DISPLAY_PROMPT_STATUS_MESSAGE   0x0112

Definition at line 604 of file chan_skinny.c.

Referenced by transmit_displaypromptstatus().

#define DISPLAYTEXT_MESSAGE   0x0099

Definition at line 295 of file chan_skinny.c.

Referenced by transmit_displaymessage().

#define htolel (  )     (x)

Definition at line 99 of file chan_skinny.c.

Referenced by get_input(), handle_message(), load_module(), transmit_callinfo(), transmit_callstate(), transmit_connect(), transmit_diallednumber(), transmit_displaymessage(), transmit_displaynotify(), transmit_displaypromptstatus(), transmit_lamp_indication(), transmit_ringer_mode(), transmit_speaker_mode(), and transmit_tone().

#define htoles (  )     (x)

Definition at line 100 of file chan_skinny.c.

#define IP_PORT_MESSAGE   0x0002

Definition at line 138 of file chan_skinny.c.

Referenced by handle_message().

#define KEEP_ALIVE_ACK_MESSAGE   0x0100

Definition at line 486 of file chan_skinny.c.

Referenced by handle_message().

#define KEEP_ALIVE_MESSAGE   0x0000

Definition at line 125 of file chan_skinny.c.

Referenced by handle_message().

#define KEYPAD_BUTTON_MESSAGE   0x0003

Definition at line 140 of file chan_skinny.c.

Referenced by handle_message().

#define letohl (  )     (x)

Definition at line 97 of file chan_skinny.c.

Referenced by get_input(), handle_message(), skinny_register(), skinny_req_parse(), and transmit_response().

#define letohs (  )     (x)

Definition at line 98 of file chan_skinny.c.

#define LINE_STAT_RES_MESSAGE   0x0092

Definition at line 274 of file chan_skinny.c.

Referenced by handle_message().

#define LINE_STATE_REQ_MESSAGE   0x000B

Definition at line 174 of file chan_skinny.c.

Referenced by handle_message().

#define MAX_SUBS   2

Definition at line 711 of file chan_skinny.c.

#define OFFHOOK_MESSAGE   0x0006

Definition at line 151 of file chan_skinny.c.

Referenced by handle_message().

#define ONHOOK_MESSAGE   0x0007

Definition at line 152 of file chan_skinny.c.

Referenced by handle_message().

#define OPEN_RECIEVE_CHANNEL_ACK_MESSAGE   0x0022

Definition at line 185 of file chan_skinny.c.

Referenced by handle_message().

#define OPEN_RECIEVE_CHANNEL_MESSAGE   0x0105

Definition at line 488 of file chan_skinny.c.

Referenced by transmit_connect().

#define REGISTER_ACK_MESSAGE   0x0081

Definition at line 197 of file chan_skinny.c.

Referenced by handle_message().

#define REGISTER_MESSAGE   0x0001

Definition at line 128 of file chan_skinny.c.

Referenced by handle_message().

#define REGISTER_REJ_MESSAGE   0x009D

Definition at line 302 of file chan_skinny.c.

Referenced by handle_message().

#define SELECT_SOFT_KEYS_MESSAGE   0x0110

Definition at line 589 of file chan_skinny.c.

#define SERVER_REQUEST_MESSAGE   0x0012

Definition at line 182 of file chan_skinny.c.

Referenced by handle_message().

#define SERVER_RES_MESSAGE   0x009E

Definition at line 309 of file chan_skinny.c.

Referenced by handle_message().

#define SET_LAMP_MESSAGE   0x0086

Definition at line 218 of file chan_skinny.c.

Referenced by transmit_lamp_indication().

#define SET_RINGER_MESSAGE   0x0085

Definition at line 213 of file chan_skinny.c.

Referenced by transmit_ringer_mode().

#define SET_SPEAKER_MESSAGE   0x0088

Definition at line 225 of file chan_skinny.c.

Referenced by transmit_speaker_mode().

#define SKINNY_ALERT   0x24

Definition at line 733 of file chan_skinny.c.

Referenced by skinny_call(), and skinny_indicate().

#define SKINNY_BUSY   6

Definition at line 721 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_BUSYTONE   0x23

Definition at line 732 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_CALLWAIT   9

Definition at line 724 of file chan_skinny.c.

#define SKINNY_CALLWAITTONE   0x2D

Definition at line 735 of file chan_skinny.c.

Referenced by skinny_call().

#define SKINNY_CONGESTION   7

Definition at line 722 of file chan_skinny.c.

Referenced by skinny_indicate().

#define SKINNY_CONNECTED   5

Definition at line 720 of file chan_skinny.c.

Referenced by handle_message(), and skinny_answer().

#define SKINNY_CX_CONF   3

Definition at line 756 of file chan_skinny.c.

#define SKINNY_CX_CONFERENCE   3

Definition at line 757 of file chan_skinny.c.

#define SKINNY_CX_INACTIVE   4

Definition at line 759 of file chan_skinny.c.

Referenced by build_device().

#define SKINNY_CX_MUTE   4

Definition at line 758 of file chan_skinny.c.

#define SKINNY_CX_RECVONLY   1

Definition at line 754 of file chan_skinny.c.

Referenced by handle_message().

#define SKINNY_CX_SENDONLY   0

Definition at line 753 of file chan_skinny.c.

#define SKINNY_CX_SENDRECV   2

Definition at line 755 of file chan_skinny.c.

Referenced by skinny_answer().

#define SKINNY_DIALTONE   0x21

Definition at line 731 of file chan_skinny.c.

Referenced by handle_message(), and skinny_ss().

#define SKINNY_HOLD   8

Definition at line 723 of file chan_skinny.c.

#define SKINNY_INVALID   14

Definition at line 728 of file chan_skinny.c.

#define SKINNY_LAMP_BLINK   5

Definition at line 742 of file chan_skinny.c.

Referenced by do_housekeeping(), and skinny_call().

#define SKINNY_LAMP_FLASH   4

Definition at line 741 of file chan_skinny.c.

#define SKINNY_LAMP_OFF   1

Definition at line 738 of file chan_skinny.c.

Referenced by do_housekeeping(), handle_message(), and skinny_hangup().

#define SKINNY_LAMP_ON   2

Definition at line 739 of file chan_skinny.c.

Referenced by do_housekeeping(), and handle_message().

#define SKINNY_LAMP_WINK   3

Definition at line 740 of file chan_skinny.c.

#define SKINNY_MAX_PACKET   1000

Definition at line