📄 chan_skinny.c
字号:
#define KEEP_ALIVE_ACK_MESSAGE 0x0100#define OPEN_RECEIVE_CHANNEL_MESSAGE 0x0105struct open_receive_channel_message { uint32_t conferenceId; uint32_t partyId; uint32_t packets; uint32_t capability; uint32_t echo; uint32_t bitrate; uint32_t space[16];};#define CLOSE_RECEIVE_CHANNEL_MESSAGE 0x0106struct close_receive_channel_message { uint32_t conferenceId; uint32_t partyId; uint32_t space[2];};#define SOFT_KEY_TEMPLATE_RES_MESSAGE 0x0108struct soft_key_template_definition { char softKeyLabel[16]; uint32_t softKeyEvent;};#define KEYDEF_ONHOOK 0#define KEYDEF_CONNECTED 1#define KEYDEF_ONHOLD 2#define KEYDEF_RINGIN 3#define KEYDEF_OFFHOOK 4#define KEYDEF_CONNWITHTRANS 5#define KEYDEF_DADFD 6 /* Digits After Dialing First Digit */#define KEYDEF_CONNWITHCONF 7#define KEYDEF_RINGOUT 8#define KEYDEF_OFFHOOKWITHFEAT 9#define KEYDEF_UNKNOWN 10#define SOFTKEY_NONE 0x00#define SOFTKEY_REDIAL 0x01#define SOFTKEY_NEWCALL 0x02#define SOFTKEY_HOLD 0x03#define SOFTKEY_TRNSFER 0x04#define SOFTKEY_CFWDALL 0x05#define SOFTKEY_CFWDBUSY 0x06#define SOFTKEY_CFWDNOANSWER 0x07#define SOFTKEY_BKSPC 0x08#define SOFTKEY_ENDCALL 0x09#define SOFTKEY_RESUME 0x0A#define SOFTKEY_ANSWER 0x0B#define SOFTKEY_INFO 0x0C#define SOFTKEY_CONFRN 0x0D#define SOFTKEY_PARK 0x0E#define SOFTKEY_JOIN 0x0F#define SOFTKEY_MEETME 0x10#define SOFTKEY_PICKUP 0x11#define SOFTKEY_GPICKUP 0x12struct soft_key_template_definition soft_key_template_default[] = { { "Redial", 0x01 }, { "NewCall", 0x02 }, { "Hold", 0x03 }, { "Trnsfer", 0x04 }, { "CFwdAll", 0x05 }, { "CFwdBusy", 0x06 }, { "CFwdNoAnswer", 0x07 }, { "<<", 0x08 }, { "EndCall", 0x09 }, { "Resume", 0x0A }, { "Answer", 0x0B }, { "Info", 0x0C }, { "Confrn", 0x0D }, { "Park", 0x0E }, { "Join", 0x0F }, { "MeetMe", 0x10 }, { "PickUp", 0x11 }, { "GPickUp", 0x12 },};struct soft_key_definitions { const uint8_t mode; const uint8_t *defaults; const int count;};static const uint8_t soft_key_default_onhook[] = { SOFTKEY_REDIAL, SOFTKEY_NEWCALL, SOFTKEY_CFWDALL, SOFTKEY_CFWDBUSY, /*SOFTKEY_GPICKUP, SOFTKEY_CONFRN,*/};static const uint8_t soft_key_default_connected[] = { SOFTKEY_HOLD, SOFTKEY_ENDCALL, SOFTKEY_TRNSFER, SOFTKEY_PARK, SOFTKEY_CFWDALL, SOFTKEY_CFWDBUSY,};static const uint8_t soft_key_default_onhold[] = { SOFTKEY_RESUME, SOFTKEY_NEWCALL, SOFTKEY_ENDCALL, SOFTKEY_TRNSFER,};static const uint8_t soft_key_default_ringin[] = { SOFTKEY_ANSWER, SOFTKEY_ENDCALL, SOFTKEY_TRNSFER,};static const uint8_t soft_key_default_offhook[] = { SOFTKEY_REDIAL, SOFTKEY_ENDCALL, SOFTKEY_CFWDALL, SOFTKEY_CFWDBUSY, /*SOFTKEY_GPICKUP,*/};static const uint8_t soft_key_default_connwithtrans[] = { SOFTKEY_HOLD, SOFTKEY_ENDCALL, SOFTKEY_TRNSFER, SOFTKEY_PARK, SOFTKEY_CFWDALL, SOFTKEY_CFWDBUSY,};static const uint8_t soft_key_default_dadfd[] = { SOFTKEY_BKSPC, SOFTKEY_ENDCALL,};static const uint8_t soft_key_default_connwithconf[] = { SOFTKEY_NONE,};static const uint8_t soft_key_default_ringout[] = { SOFTKEY_NONE, SOFTKEY_ENDCALL,};static const uint8_t soft_key_default_offhookwithfeat[] = { SOFTKEY_REDIAL, SOFTKEY_ENDCALL,};static const uint8_t soft_key_default_unknown[] = { SOFTKEY_NONE,};static const struct soft_key_definitions soft_key_default_definitions[] = { {KEYDEF_ONHOOK, soft_key_default_onhook, sizeof(soft_key_default_onhook) / sizeof(uint8_t)}, {KEYDEF_CONNECTED, soft_key_default_connected, sizeof(soft_key_default_connected) / sizeof(uint8_t)}, {KEYDEF_ONHOLD, soft_key_default_onhold, sizeof(soft_key_default_onhold) / sizeof(uint8_t)}, {KEYDEF_RINGIN, soft_key_default_ringin, sizeof(soft_key_default_ringin) / sizeof(uint8_t)}, {KEYDEF_OFFHOOK, soft_key_default_offhook, sizeof(soft_key_default_offhook) / sizeof(uint8_t)}, {KEYDEF_CONNWITHTRANS, soft_key_default_connwithtrans, sizeof(soft_key_default_connwithtrans) / sizeof(uint8_t)}, {KEYDEF_DADFD, soft_key_default_dadfd, sizeof(soft_key_default_dadfd) / sizeof(uint8_t)}, {KEYDEF_CONNWITHCONF, soft_key_default_connwithconf, sizeof(soft_key_default_connwithconf) / sizeof(uint8_t)}, {KEYDEF_RINGOUT, soft_key_default_ringout, sizeof(soft_key_default_ringout) / sizeof(uint8_t)}, {KEYDEF_OFFHOOKWITHFEAT, soft_key_default_offhookwithfeat, sizeof(soft_key_default_offhookwithfeat) / sizeof(uint8_t)}, {KEYDEF_UNKNOWN, soft_key_default_unknown, sizeof(soft_key_default_unknown) / sizeof(uint8_t)}};struct soft_key_template_res_message { uint32_t softKeyOffset; uint32_t softKeyCount; uint32_t totalSoftKeyCount; struct soft_key_template_definition softKeyTemplateDefinition[32];};#define SOFT_KEY_SET_RES_MESSAGE 0x0109struct soft_key_set_definition { uint8_t softKeyTemplateIndex[16]; uint16_t softKeyInfoIndex[16];};struct soft_key_set_res_message { uint32_t softKeySetOffset; uint32_t softKeySetCount; uint32_t totalSoftKeySetCount; struct soft_key_set_definition softKeySetDefinition[16]; uint32_t res;};#define SELECT_SOFT_KEYS_MESSAGE 0x0110struct select_soft_keys_message { uint32_t instance; uint32_t reference; uint32_t softKeySetIndex; uint32_t validKeyMask;};#define CALL_STATE_MESSAGE 0x0111struct call_state_message { uint32_t callState; uint32_t lineInstance; uint32_t callReference; uint32_t space[3];};#define DISPLAY_PROMPT_STATUS_MESSAGE 0x0112struct display_prompt_status_message { uint32_t messageTimeout; char promptMessage[32]; uint32_t lineInstance; uint32_t callReference;};#define CLEAR_PROMPT_MESSAGE 0x0113struct clear_prompt_message { uint32_t lineInstance; uint32_t callReference;};#define DISPLAY_NOTIFY_MESSAGE 0x0114struct display_notify_message { uint32_t displayTimeout; char displayMessage[100];};#define ACTIVATE_CALL_PLANE_MESSAGE 0x0116struct activate_call_plane_message { uint32_t lineInstance;};#define DIALED_NUMBER_MESSAGE 0x011Dstruct dialed_number_message { char dialedNumber[24]; uint32_t lineInstance; uint32_t callReference;};union skinny_data { struct alarm_message alarm; struct speed_dial_stat_req_message speeddialreq; struct register_message reg; struct register_ack_message regack; struct register_rej_message regrej; struct capabilities_res_message caps; struct version_res_message version; struct button_template_res_message buttontemplate; struct displaytext_message displaytext; struct display_prompt_status_message displaypromptstatus; struct clear_prompt_message clearpromptstatus; struct definetimedate_message definetimedate; struct start_tone_message starttone; struct stop_tone_message stoptone; struct speed_dial_stat_res_message speeddial; struct line_state_req_message line; struct line_stat_res_message linestat; struct soft_key_set_res_message softkeysets; struct soft_key_template_res_message softkeytemplate; struct server_res_message serverres; struct reset_message reset; struct set_lamp_message setlamp; struct set_ringer_message setringer; struct call_state_message callstate; struct keypad_button_message keypad; struct select_soft_keys_message selectsoftkey; struct activate_call_plane_message activatecallplane; struct stimulus_message stimulus; struct offhook_message offhook; struct onhook_message onhook; struct set_speaker_message setspeaker; struct set_microphone_message setmicrophone; struct call_info_message callinfo; struct start_media_transmission_message startmedia; struct stop_media_transmission_message stopmedia; struct open_receive_channel_message openreceivechannel; struct open_receive_channel_ack_message openreceivechannelack; struct close_receive_channel_message closereceivechannel; struct display_notify_message displaynotify; struct dialed_number_message dialednumber; struct soft_key_event_message softkeyeventmessage; struct enbloc_call_message enbloccallmessage;};/* packet composition */struct skinny_req { int len; int res; int e; union skinny_data data;};/* XXX This is the combined size of the variables above. (len, res, e) If more are added, this MUST change. (sizeof(skinny_req) - sizeof(skinny_data)) DOES NOT WORK on all systems (amd64?). */int skinny_header_size = 12;/***************************** * Asterisk specific globals * *****************************/static int skinnydebug = 0;/* a hostname, portnumber, socket and such is usefull for VoIP protocols */static struct sockaddr_in bindaddr;static char ourhost[256];static int ourport;static struct in_addr __ourip;struct ast_hostent ahp;struct hostent *hp;static int skinnysock = -1;static pthread_t accept_t;static char context[AST_MAX_CONTEXT] = "default";static char language[MAX_LANGUAGE] = "";static char mohinterpret[MAX_MUSICCLASS] = "default";static char mohsuggest[MAX_MUSICCLASS] = "";static char cid_num[AST_MAX_EXTENSION] = "";static char cid_name[AST_MAX_EXTENSION] = "";static char linelabel[AST_MAX_EXTENSION] ="";static int nat = 0;static ast_group_t cur_callergroup = 0;static ast_group_t cur_pickupgroup = 0;static int immediate = 0;static int callwaiting = 0;static int callreturn = 0;static int threewaycalling = 0;static int mwiblink = 0;/* This is for flashhook transfers */static int transfer = 0;static int cancallforward = 0;/* static int busycount = 3;*/static char accountcode[AST_MAX_ACCOUNT_CODE] = "";static char mailbox[AST_MAX_EXTENSION];static int amaflags = 0;static int callnums = 1;#define SKINNY_DEVICE_UNKNOWN -1#define SKINNY_DEVICE_NONE 0#define SKINNY_DEVICE_30SPPLUS 1#define SKINNY_DEVICE_12SPPLUS 2#define SKINNY_DEVICE_12SP 3#define SKINNY_DEVICE_12 4#define SKINNY_DEVICE_30VIP 5#define SKINNY_DEVICE_7910 6#define SKINNY_DEVICE_7960 7#define SKINNY_DEVICE_7940 8#define SKINNY_DEVICE_7935 9#define SKINNY_DEVICE_ATA186 12 /* Cisco ATA-186 */#define SKINNY_DEVICE_7941 115#define SKINNY_DEVICE_7971 119#define SKINNY_DEVICE_7914 124 /* Expansion module */#define SKINNY_DEVICE_7985 302#define SKINNY_DEVICE_7911 307#define SKINNY_DEVICE_7961GE 308#define SKINNY_DEVICE_7941GE 309#define SKINNY_DEVICE_7931 348#define SKINNY_DEVICE_7921 365#define SKINNY_DEVICE_7906 369#define SKINNY_DEVICE_7962 404 /* Not found */#define SKINNY_DEVICE_7937 431#define SKINNY_DEVICE_7942 434#define SKINNY_DEVICE_7945 435#define SKINNY_DEVICE_7965 436#define SKINNY_DEVICE_7975 437#define SKINNY_DEVICE_7905 20000#define SKINNY_DEVICE_7920 30002#define SKINNY_DEVICE_7970 30006#define SKINNY_DEVICE_7912 30007#define SKINNY_DEVICE_7902 30008#define SKINNY_DEVICE_CIPC 30016 /* Cisco IP Communicator */#define SKINNY_DEVICE_7961 30018#define SKINNY_DEVICE_7936 30019#define SKINNY_DEVICE_SCCPGATEWAY_AN 30027 /* ??? */#define SKINNY_DEVICE_SCCPGATEWAY_BRI 30028 /* ??? */#define SKINNY_SPEAKERON 1#define SKINNY_SPEAKEROFF 2#define SKINNY_MICON 1#define SKINNY_MICOFF 2#define SKINNY_OFFHOOK 1#define SKINNY_ONHOOK 2#define SKINNY_RINGOUT 3#define SKINNY_RINGIN 4#define SKINNY_CONNECTED 5#define SKINNY_BUSY 6#define SKINNY_CONGESTION 7#define SKINNY_HOLD 8#define SKINNY_CALLWAIT 9#define SKINNY_TRANSFER 10#define SKINNY_PARK 11#define SKINNY_PROGRESS 12#define SKINNY_INVALID 14#define SKINNY_SILENCE 0x00#define SKINNY_DIALTONE 0x21#define SKINNY_BUSYTONE 0x23#define SKINNY_ALERT 0x24#define SKINNY_REORDER 0x25#define SKINNY_CALLWAITTONE 0x2D#define SKINNY_NOTONE 0x7F#define SKINNY_LAMP_OFF 1#define SKINNY_LAMP_ON 2#define SKINNY_LAMP_WINK 3#define SKINNY_LAMP_FLASH 4#define SKINNY_LAMP_BLINK 5#define SKINNY_RING_OFF 1#define SKINNY_RING_INSIDE 2#define SKINNY_RING_OUTSIDE 3#define SKINNY_RING_FEATURE 4#define TYPE_TRUNK 1#define TYPE_LINE 2/* Skinny rtp stream modes. Do we really need this? */#define SKINNY_CX_SENDONLY 0#define SKINNY_CX_RECVONLY 1#define SKINNY_CX_SENDRECV 2#define SKINNY_CX_CONF 3#define SKINNY_CX_CONFERENCE 3#define SKINNY_CX_MUTE 4#define SKINNY_CX_INACTIVE 4#if 0static char *skinny_cxmodes[] = { "sendonly", "recvonly", "sendrecv", "confrnce", "inactive"};#endif/* driver scheduler */static struct sched_context *sched = NULL;static struct io_context *io;/* Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. */AST_MUTEX_DEFINE_STATIC(monlock);/* Protect the network socket */AST_MUTEX_DEFINE_STATIC(netlock);/* Protect the session list */AST_MUTEX_DEFINE_STATIC(sessionlock);/* Protect the device list */AST_MUTEX_DEFINE_STATIC(devicelock);#if 0/* Protect the paging device list */AST_MUTEX_DEFINE_STATIC(pagingdevicelock);#endif/* This is the thread for the monitor which checks for input on the channels which are not currently in use. */static pthread_t monitor_thread = AST_PTHREADT_NULL;/* Wait up to 16 seconds for first digit */static int firstdigittimeout = 16000;/* How long to wait for following digits */static int gendigittimeout = 8000;/* How long to wait for an extra digit, if there is an ambiguous match */static int matchdigittimeout = 3000;struct skinny_subchannel { ast_mutex_t lock; struct ast_channel *owner; struct ast_rtp *rtp; struct ast_rtp *vrtp; unsigned int callid;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -