⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chan_skinny.c

📁 Asterisk中信道部分的源码 。。。。
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Asterisk -- An open source telephony toolkit. * * Copyright (C) 1999 - 2005, Digium, Inc. * * chan_skinny was developed by Jeremy McNamara & Florian Overkamp * chan_skinny was heavily modified/fixed by North Antara * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact * any of the maintainers of this project for assistance; * the project provides a web site, mailing lists and IRC * channels for your use. * * This program is free software, distributed under the terms of * the GNU General Public License Version 2. See the LICENSE file * at the top of the source tree. *//*! \file * * \brief Implementation of the Skinny protocol * * \author Jeremy McNamara & Florian Overkamp & North Antara * \ingroup channel_drivers */#include "asterisk.h"ASTERISK_FILE_VERSION(__FILE__, "$Revision: 136062 $")#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/lock.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"/************************************* * Skinny/Asterisk Protocol Settings * *************************************/static const char tdesc[] = "Skinny Client Control Protocol (Skinny)";static const char config[] = "skinny.conf";static int default_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW;static struct ast_codec_pref default_prefs;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, /* XXX Which packing order does this translate to? */	SKINNY_CODEC_H261 = 100,	SKINNY_CODEC_H263 = 101};#define DEFAULT_SKINNY_PORT	2000#define DEFAULT_SKINNY_BACKLOG	2#define SKINNY_MAX_PACKET	1000static int keep_alive = 120;static char date_format[6] = "D-M-Y";static char version_id[16] = "P002F202";#if __BYTE_ORDER == __LITTLE_ENDIAN#define letohl(x) (x)#define letohs(x) (x)#define htolel(x) (x)#define htoles(x) (x)#else#if defined(SOLARIS) || defined(__Darwin__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)#define __bswap_16(x) \	((((x) & 0xff00) >> 8) | \	 (((x) & 0x00ff) << 8))#define __bswap_32(x) \	((((x) & 0xff000000) >> 24) | \	 (((x) & 0x00ff0000) >>  8) | \	 (((x) & 0x0000ff00) <<  8) | \	 (((x) & 0x000000ff) << 24))#else#include <bits/byteswap.h>#endif#define letohl(x) __bswap_32(x)#define letohs(x) __bswap_16(x)#define htolel(x) __bswap_32(x)#define htoles(x) __bswap_16(x)#endif/*! Global jitterbuffer configuration - by default, jb is disabled */static struct ast_jb_conf default_jbconf ={	.flags = 0,	.max_size = -1,	.resync_threshold = -1,	.impl = ""};static struct ast_jb_conf global_jbconf;AST_THREADSTORAGE(device2str_threadbuf, device2str_threadbuf_init);#define DEVICE2STR_BUFSIZE   15AST_THREADSTORAGE(control2str_threadbuf, control2str_threadbuf_init);#define CONTROL2STR_BUFSIZE   100/********************* * Protocol Messages * *********************//* message types */#define KEEP_ALIVE_MESSAGE 0x0000/* no additional struct */#define REGISTER_MESSAGE 0x0001struct register_message {	char name[16];	uint32_t userId;	uint32_t instance;	uint32_t ip;	uint32_t type;	uint32_t maxStreams;};#define IP_PORT_MESSAGE	0x0002#define KEYPAD_BUTTON_MESSAGE 0x0003struct keypad_button_message {	uint32_t button;	uint32_t lineInstance;	uint32_t callReference;};#define ENBLOC_CALL_MESSAGE 0x0004struct enbloc_call_message {       char calledParty[24];};#define STIMULUS_MESSAGE 0x0005struct stimulus_message {	uint32_t stimulus;	uint32_t stimulusInstance;	uint32_t callreference;};#define OFFHOOK_MESSAGE 0x0006struct offhook_message {	uint32_t unknown1;	uint32_t unknown2;};#define ONHOOK_MESSAGE 0x0007struct onhook_message {	uint32_t unknown1;	uint32_t unknown2;};#define CAPABILITIES_RES_MESSAGE 0x0010struct station_capabilities {	uint32_t codec;	uint32_t frames;	union {		char res[8];		uint32_t rate;	} payloads;};#define SKINNY_MAX_CAPABILITIES 18struct capabilities_res_message {	uint32_t count;	struct station_capabilities caps[SKINNY_MAX_CAPABILITIES];};#define SPEED_DIAL_STAT_REQ_MESSAGE 0x000Astruct speed_dial_stat_req_message {	uint32_t speedDialNumber;};#define LINE_STATE_REQ_MESSAGE 0x000Bstruct line_state_req_message {	uint32_t lineNumber;};#define TIME_DATE_REQ_MESSAGE 0x000D#define BUTTON_TEMPLATE_REQ_MESSAGE 0x000E#define VERSION_REQ_MESSAGE 0x000F#define SERVER_REQUEST_MESSAGE 0x0012#define ALARM_MESSAGE 0x0020struct alarm_message {	uint32_t alarmSeverity;	char displayMessage[80];	uint32_t alarmParam1;	uint32_t alarmParam2;};#define OPEN_RECEIVE_CHANNEL_ACK_MESSAGE 0x0022struct open_receive_channel_ack_message {	uint32_t status;	uint32_t ipAddr;	uint32_t port;	uint32_t passThruId;};#define SOFT_KEY_SET_REQ_MESSAGE 0x0025#define SOFT_KEY_EVENT_MESSAGE 0x0026struct soft_key_event_message {	uint32_t softKeyEvent;	uint32_t instance;	uint32_t callreference;};#define UNREGISTER_MESSAGE 0x0027#define SOFT_KEY_TEMPLATE_REQ_MESSAGE 0x0028#define HEADSET_STATUS_MESSAGE 0x002B#define REGISTER_AVAILABLE_LINES_MESSAGE 0x002D#define REGISTER_ACK_MESSAGE 0x0081struct register_ack_message {	uint32_t keepAlive;	char dateTemplate[6];	char res[2];	uint32_t secondaryKeepAlive;	char res2[4];};#define START_TONE_MESSAGE 0x0082struct start_tone_message {	uint32_t tone;	uint32_t space;	uint32_t instance;	uint32_t reference;};#define STOP_TONE_MESSAGE 0x0083struct stop_tone_message {	uint32_t instance;	uint32_t reference;};#define SET_RINGER_MESSAGE 0x0085struct set_ringer_message {	uint32_t ringerMode;	uint32_t unknown1; /* See notes in transmit_ringer_mode */	uint32_t unknown2;	uint32_t space[2];};#define SET_LAMP_MESSAGE 0x0086struct set_lamp_message {	uint32_t stimulus;	uint32_t stimulusInstance;	uint32_t deviceStimulus;};#define SET_SPEAKER_MESSAGE 0x0088struct set_speaker_message {	uint32_t mode;};/* XXX When do we need to use this? */#define SET_MICROPHONE_MESSAGE 0x0089struct set_microphone_message {	uint32_t mode;};#define START_MEDIA_TRANSMISSION_MESSAGE 0x008Astruct media_qualifier {	uint32_t precedence;	uint32_t vad;	uint16_t packets;	uint32_t bitRate;};struct start_media_transmission_message {	uint32_t conferenceId;	uint32_t passThruPartyId;	uint32_t remoteIp;	uint32_t remotePort;	uint32_t packetSize;	uint32_t payloadType;	struct media_qualifier qualifier;	uint32_t space[16];};#define STOP_MEDIA_TRANSMISSION_MESSAGE 0x008Bstruct stop_media_transmission_message {	uint32_t conferenceId;	uint32_t passThruPartyId;	uint32_t space[3];};#define CALL_INFO_MESSAGE 0x008Fstruct call_info_message {	char callingPartyName[40];	char callingParty[24];	char calledPartyName[40];	char calledParty[24];	uint32_t instance;	uint32_t reference;	uint32_t type;	char originalCalledPartyName[40];	char originalCalledParty[24];	char lastRedirectingPartyName[40];	char lastRedirectingParty[24];	uint32_t originalCalledPartyRedirectReason;	uint32_t lastRedirectingReason;	char callingPartyVoiceMailbox[24];	char calledPartyVoiceMailbox[24];	char originalCalledPartyVoiceMailbox[24];	char lastRedirectingVoiceMailbox[24];	uint32_t space[3];};#define SPEED_DIAL_STAT_RES_MESSAGE 0x0091struct speed_dial_stat_res_message {	uint32_t speedDialNumber;	char speedDialDirNumber[24];	char speedDialDisplayName[40];};#define LINE_STAT_RES_MESSAGE 0x0092struct line_stat_res_message {	uint32_t lineNumber;	char lineDirNumber[24];	char lineDisplayName[24];	uint32_t space[15];};#define DEFINETIMEDATE_MESSAGE 0x0094struct definetimedate_message {	uint32_t year;	/* since 1900 */	uint32_t month;	uint32_t dayofweek;	/* monday = 1 */	uint32_t day;	uint32_t hour;	uint32_t minute;	uint32_t seconds;	uint32_t milliseconds;	uint32_t timestamp;};#define BUTTON_TEMPLATE_RES_MESSAGE 0x0097struct button_definition {	uint8_t instanceNumber;	uint8_t buttonDefinition;};struct button_definition_template {	uint8_t buttonDefinition;	/* for now, anything between 0xB0 and 0xCF is custom */	/*int custom;*/};#define STIMULUS_REDIAL			0x01#define STIMULUS_SPEEDDIAL		0x02#define STIMULUS_HOLD			0x03#define STIMULUS_TRANSFER		0x04#define STIMULUS_FORWARDALL		0x05#define STIMULUS_FORWARDBUSY		0x06#define STIMULUS_FORWARDNOANSWER	0x07#define STIMULUS_DISPLAY		0x08#define STIMULUS_LINE			0x09#define STIMULUS_VOICEMAIL		0x0F#define STIMULUS_AUTOANSWER		0x11#define STIMULUS_CONFERENCE		0x7D#define STIMULUS_CALLPARK		0x7E#define STIMULUS_CALLPICKUP		0x7F#define STIMULUS_NONE			0xFF/* Button types */#define BT_REDIAL			STIMULUS_REDIAL#define BT_SPEEDDIAL			STIMULUS_SPEEDDIAL#define BT_HOLD				STIMULUS_HOLD#define BT_TRANSFER			STIMULUS_TRANSFER#define BT_FORWARDALL			STIMULUS_FORWARDALL#define BT_FORWARDBUSY			STIMULUS_FORWARDBUSY#define BT_FORWARDNOANSWER		STIMULUS_FORWARDNOANSWER#define BT_DISPLAY 			STIMULUS_DISPLAY#define BT_LINE				STIMULUS_LINE#define BT_VOICEMAIL			STIMULUS_VOICEMAIL#define BT_AUTOANSWER			STIMULUS_AUTOANSWER#define BT_CONFERENCE			STIMULUS_CONFERENCE#define BT_CALLPARK			STIMULUS_CALLPARK#define BT_CALLPICKUP			STIMULUS_CALLPICKUP#define BT_NONE				0x00/* Custom button types - add our own between 0xB0 and 0xCF.   This may need to be revised in the future,   if stimuluses are ever added in this range. */#define BT_CUST_LINESPEEDDIAL		0xB0	/* line or speeddial */#define BT_CUST_HINT			0xB1	/* pipe dream */struct button_template_res_message {	uint32_t buttonOffset;	uint32_t buttonCount;	uint32_t totalButtonCount;	struct button_definition definition[42];};#define VERSION_RES_MESSAGE 0x0098struct version_res_message {	char version[16];};#define DISPLAYTEXT_MESSAGE 0x0099struct displaytext_message {	char text[40];};#define CLEAR_NOTIFY_MESSAGE  0x0115#define CLEAR_DISPLAY_MESSAGE 0x009A#define CAPABILITIES_REQ_MESSAGE 0x009B#define REGISTER_REJ_MESSAGE 0x009Dstruct register_rej_message {	char errMsg[33];};#define SERVER_RES_MESSAGE 0x009Estruct server_identifier {	char serverName[48];};struct server_res_message {	struct server_identifier server[5];	uint32_t serverListenPort[5];	uint32_t serverIpAddr[5];};#define RESET_MESSAGE 0x009Fstruct reset_message {	uint32_t resetType;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -