init ems server code
This commit is contained in:
99
plat/sip/Makefile
Normal file
99
plat/sip/Makefile
Normal file
@@ -0,0 +1,99 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile for module template : V1.6.3 ##
|
||||
## ##
|
||||
## Created : Wei Liu 07/04/11 ##
|
||||
## Revision: [Last]Wei Liu 07/07/07 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project correlation(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## MODULE= [Module Name]
|
||||
## TYPE = app/plat => Module Type
|
||||
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
|
||||
|
||||
## BUILD = lib/exef => Output file format
|
||||
## CFG = debug/release => Build Configuration
|
||||
|
||||
## SRC_PATH = [Source file path]
|
||||
## INC_PATH = [Include file path]
|
||||
## APP_PATH = [App Module path]
|
||||
## PLT_PATH = [Plat Module path]
|
||||
|
||||
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
|
||||
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
|
||||
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
|
||||
|
||||
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
|
||||
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
|
||||
## snmp iptrans debug sccp public
|
||||
##
|
||||
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
|
||||
## LIB_ADD e.g. = -liba3a8 -lm
|
||||
|
||||
## OBJ_ADD = [Extend third party object files needed]
|
||||
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
MODULE = sip
|
||||
TYPE = plat
|
||||
|
||||
DBUG_FLAGS_ADD =
|
||||
RELS_FLAGS_ADD =
|
||||
|
||||
##Default commonly as below
|
||||
|
||||
BUILD = lib
|
||||
CFG = debug
|
||||
|
||||
|
||||
PLT_LIB =
|
||||
|
||||
APP_LIB =
|
||||
LIB_ADD = -lm
|
||||
|
||||
SRC_PATH = ./src
|
||||
INC_PATH = ./src/include
|
||||
PLT_PATH = ../../plat
|
||||
APP_PATH = ../../app
|
||||
|
||||
OBJ_ADD =
|
||||
TEST_OBJ_PATH =
|
||||
|
||||
PREPROC_CMD =
|
||||
POSTPROC_CMD =
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make configuration(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## CCFLAG_SWITCH = on/off => gcc flag show on/off
|
||||
## COVER_NEED = yes/no => PTF cover report needed
|
||||
## COVER_REPORT_PATH = [path ] => PTF cover report path
|
||||
|
||||
CCFLAG_SWITCH = off
|
||||
COVER_NEED = no
|
||||
COVER_REPORT_PATH = ./output
|
||||
MAKE_INCLUDE = $(HOME)/ems.git/include
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## include makefile.rules (Do not change)
|
||||
##
|
||||
##--------------------------------------
|
||||
include $(MAKE_INCLUDE)/Makefile.rules
|
||||
720
plat/sip/src/include/sip.h
Normal file
720
plat/sip/src/include/sip.h
Normal file
@@ -0,0 +1,720 @@
|
||||
#ifndef _SIP__H
|
||||
#define _SIP__H
|
||||
|
||||
#include "sip_pub.h"
|
||||
|
||||
// SIP general constant
|
||||
#define SIP_MAX_USER_NAME_LEN 64//128
|
||||
#define SIP_MAX_PASSWORD_LEN 16
|
||||
#define SIP_MAX_DOMAIN_NAME_LEN 128//256
|
||||
#define SIP_MAX_REASON_PHRASE_LEN 128
|
||||
#define SIP_MAX_HDR_FLAG_NUM 2
|
||||
#define SIP_MAX_BODY_LEN 1500
|
||||
#define SIP_MAX_DISPLAY_NAME_LEN 64
|
||||
#define SIP_MAX_CALL_ID_LEN 128
|
||||
#define SIP_MAX_GEN_PARA_NUM 8
|
||||
#define SIP_MAX_PARA_STRING_LEN 64//128
|
||||
#define SIP_MAX_PARA_VAL_LEN 4
|
||||
#define SIP_MAX_PARA_NUM 4//8
|
||||
#define SIP_MAX_NUM_OF_TRANS 4096//8192
|
||||
#define SIP_MAX_NUM_OF_VIAS 8//32
|
||||
#define SIP_MAX_NUM_OF_CONTACTS 4
|
||||
#define SIP_MAX_NUM_OF_RECORD_ROUTES 8//32
|
||||
#define SIP_MAX_NUM_OF_ROUTES 8//32
|
||||
#define SIP_MAX_NUM_OF_ALLOW 8//32
|
||||
#define SIP_MAX_NUM_OF_ACCEPT 8
|
||||
#define SIP_MAX_NUM_OF_ACCEPT_ENCODING 4
|
||||
#define SIP_MAX_NUM_OF_ACCEPT_LANGUAGE 8
|
||||
#define SIP_MAX_LENGTH_OF_EVENT 32
|
||||
#define SIP_MAX_LENGTH_OF_USER_AGENT 64
|
||||
#define SIP_MAX_LENGTH_OF_SUBJECT 128
|
||||
#define SIP_MAX_LENGTH_OF_SUB_STATE 128
|
||||
#define SIP_MAX_VIA_DOMAIN_NAME_LEN 64
|
||||
|
||||
#define SIP_MAX_NUM_OF_SIP_SUB_BODY 2
|
||||
|
||||
#define SIP_URI_TYPE_SIP 1
|
||||
#define SIP_URI_TYPE_SIPS 2
|
||||
#define SIP_URI_TYPE_TEL 3
|
||||
|
||||
#define SIP_API_TYPE_REQUEST 1
|
||||
#define SIP_API_TYPE_RESPONSE 2
|
||||
#define SIP_API_TYPE_MANAGEMENT 3
|
||||
|
||||
#define SIP_API_PNAME_TAG 1
|
||||
#define SIP_API_PNAME_BRANCH 2
|
||||
#define SIP_API_PNAME_EXPIRES 3
|
||||
#define SIP_API_PNAME_USER 4
|
||||
#define SIP_API_PNAME_LR 5
|
||||
#define SIP_API_PNAME_BOUNDARY 6
|
||||
#define SIP_API_PNAME_HANDLING 7
|
||||
#define SIP_API_PNAME_TRANSPORT 8
|
||||
#define SIP_API_PNAME_RPOTR 9
|
||||
#define SIP_API_PNAME_VERSION 10
|
||||
#define SIP_API_PNAME_BASE 11
|
||||
|
||||
#define SIP_API_PTYPE_STRING 1
|
||||
#define SIP_API_PTYPE_VALUE 2
|
||||
#define SIP_API_PTYPE_TAG 3
|
||||
|
||||
#define SIP_API_PROTO_UDP 1
|
||||
#define SIP_API_PROTO_TCP 2
|
||||
#define SIP_API_PROTO_SCTP 3
|
||||
|
||||
#define SIP_NULL_TRANS_ID 0xFFFF
|
||||
#define SIP_NULL_UP_PORT 0xFFFF
|
||||
|
||||
#define SIP_TRANSPORT_LAYER 1
|
||||
#define SIP_TRANSACTION_LAYER 2
|
||||
|
||||
#define SIP_API_REQ_MSG 1
|
||||
#define SIP_API_RES_MSG 2
|
||||
#define SIP_API_MANAGE_MSG 3
|
||||
|
||||
#define SIP_TRANS_CLIENT 1
|
||||
#define SIP_TRANS_SERVER 2
|
||||
|
||||
#define SIP_TRANS_INVITE 1
|
||||
#define SIP_TRANS_NON_INVITE 2
|
||||
|
||||
#define SIP_ACCEPT_TYPE_APPLICATION 1
|
||||
#define SIP_ACCEPT_TYPE_MULTIPART 2
|
||||
#define SIP_ACCEPT_TYPE_WILDCARD 3
|
||||
|
||||
#define SIP_ACCEPT_SUB_TYPE_SDP 1
|
||||
#define SIP_ACCEPT_SUB_TYPE_ISUP 2
|
||||
#define SIP_ACCEPT_SUB_TYPE_MIXED 3
|
||||
#define SIP_ACCEPT_SUB_TYPE_WILDCARD 4
|
||||
|
||||
#define SIP_ACCEPT_ENCODING_IDENTITY 1
|
||||
#define SIP_ACCEPT_ENCODING_GZIP 2
|
||||
#define SIP_ACCEPT_ENCODING_TAR 3
|
||||
|
||||
#define SIP_ACCEPT_LANGUAGE_EN 1
|
||||
|
||||
#define SIP_CONTENT_TYPE_APPLICATION 1
|
||||
#define SIP_CONTENT_TYPE_MULTIPART 2
|
||||
#define SIP_CONTENT_TYPE_TEXT 3
|
||||
#define SIP_CONTENT_TYPE_IMAGE 4
|
||||
#define SIP_CONTENT_TYPE_AUDIO 5
|
||||
#define SIP_CONTENT_TYPE_VEDIO 6
|
||||
|
||||
#define SIP_CONTENT_SUB_TYPE_SDP 1
|
||||
#define SIP_CONTENT_SUB_TYPE_ISUP 2
|
||||
#define SIP_CONTENT_SUB_TYPE_MIXED 3
|
||||
#define SIP_CONTENT_SUB_TYPE_MESSAGE 4
|
||||
#define SIP_CONTENT_SUB_TYPE_SIGNED 5
|
||||
#define SIP_CONTENT_SUB_TYPE_PKCS7_MIME 6
|
||||
|
||||
#define SIP_CONTENT_DISPOSITION_SIGNAL 1
|
||||
|
||||
#define SIP_CONTENT_ENCODING_IDENTITY 1
|
||||
#define SIP_CONTENT_ENCODING_GZIP 2
|
||||
#define SIP_CONTENT_ENCODING_TAR 3
|
||||
|
||||
#define SIP_CONTENT_LANGUAGE_EN 1
|
||||
|
||||
#define SIP_DATE_TYPE_GMT 1
|
||||
|
||||
#define SIP_DATE_WEEK_DAY_SUN 1
|
||||
#define SIP_DATE_WEEK_DAY_MON 2
|
||||
#define SIP_DATE_WEEK_DAY_TUE 3
|
||||
#define SIP_DATE_WEEK_DAY_WED 4
|
||||
#define SIP_DATE_WEEK_DAY_THU 5
|
||||
#define SIP_DATE_WEEK_DAY_FRI 6
|
||||
#define SIP_DATE_WEEK_DAY_SAT 7
|
||||
|
||||
#define SIP_DATE_MONTH_JAN 1
|
||||
#define SIP_DATE_MONTH_FEB 2
|
||||
#define SIP_DATE_MONTH_MAR 3
|
||||
#define SIP_DATE_MONTH_APR 4
|
||||
#define SIP_DATE_MONTH_MAY 5
|
||||
#define SIP_DATE_MONTH_JUN 6
|
||||
#define SIP_DATE_MONTH_JUL 7
|
||||
#define SIP_DATE_MONTH_AUG 8
|
||||
#define SIP_DATE_MONTH_SEP 9
|
||||
#define SIP_DATE_MONTH_OCT 10
|
||||
#define SIP_DATE_MONTH_NOV 11
|
||||
#define SIP_DATE_MONTH_DEC 12
|
||||
|
||||
#define SIP_OPTION_TAG_100_REL 1
|
||||
#define SIP_OPTION_TAG_FOO 2
|
||||
|
||||
#define SIP_TRANSACTION_TIMEOUT 99
|
||||
#define SIP_TRANSPORT_ERROR 98
|
||||
|
||||
// SIP general headers mask
|
||||
#define SIP_HDR_ACCEPT_MASK 0x00000001
|
||||
#define SIP_HDR_ACCEPT_ENCODING_MASK 0x00000002
|
||||
#define SIP_HDR_ACCEPT_LANGUAGE_MASK 0x00000004
|
||||
#define SIP_HDR_ALLOW_MASK 0x00000008
|
||||
#define SIP_HDR_CALL_ID_MASK 0x00000010
|
||||
#define SIP_HDR_CONTACT_MASK 0x00000020
|
||||
#define SIP_HDR_CSEQ_MASK 0x00000040
|
||||
#define SIP_HDR_DATE_MASK 0x00000080
|
||||
#define SIP_HDR_EXPIRES_MASK 0x00000100
|
||||
#define SIP_HDR_FROM_MASK 0x00000200
|
||||
#define SIP_HDR_TO_MASK 0x00000400
|
||||
#define SIP_HDR_VIA_MASK 0x00000800
|
||||
#define SIP_HDR_CONTENT_DISPOSITION_MASK 0x00001000
|
||||
#define SIP_HDR_CONTENT_TYPE_MASK 0x00002000
|
||||
#define SIP_HDR_CONTENT_ENCODING_MASK 0x00004000
|
||||
#define SIP_HDR_CONTENT_LANGUAGE_MASK 0x00008000
|
||||
#define SIP_HDR_CONTENT_LENGTH_MASK 0x00010000
|
||||
#define SIP_HDR_RECORD_ROUTE_MASK 0x00020000
|
||||
#define SIP_HDR_TIMESTAMP_MASK 0x00040000
|
||||
#define SIP_HDR_MIME_VERSION_MASK 0x00080000
|
||||
#define SIP_HDR_SUPPORTED_MASK 0x00100000
|
||||
#define SIP_HDR_USER_AGENT_MASK 0x00200000
|
||||
|
||||
// SIP request headers mask
|
||||
#define SIP_HDR_MAX_FORWARDS_MASK 0x00000001
|
||||
#define SIP_HDR_ROUTE_MASK 0x00000002
|
||||
#define SIP_HDR_PROXY_REQUIRE_MASK 0x00000004
|
||||
#define SIP_HDR_SUBJECT_MASK 0x00000008
|
||||
#define SIP_HDR_REQUIRE_MASK 0x00000010
|
||||
#define SIP_HDR_REFER_TO_MASK 0x00000020
|
||||
#define SIP_HDR_EVENT_MASK 0x00000040
|
||||
#define SIP_HDR_SUBSCRIPTION_STATE_MASK 0x00000080
|
||||
|
||||
//SIP response headers mask
|
||||
#define SIP_HDR_UNSUPPORTED_MASK 0x00000001//just used in 420 response
|
||||
#define SIP_HDR_SERVER_MASK 0x00000002
|
||||
|
||||
#define SIP_METHOD_REGISTER 1
|
||||
#define SIP_METHOD_INVITE 2
|
||||
#define SIP_METHOD_ACK 3
|
||||
#define SIP_METHOD_CANCEL 4
|
||||
#define SIP_METHOD_BYE 5
|
||||
#define SIP_METHOD_OPTIONS 6
|
||||
#define SIP_METHOD_INFO 7
|
||||
#define SIP_METHOD_PRACK 8
|
||||
#define SIP_METHOD_UPDATE 9
|
||||
#define SIP_METHOD_REFER 10
|
||||
#define SIP_METHOD_NOTIFY 11
|
||||
#define SIP_METHOD_RE_INVITE 12
|
||||
|
||||
#define SIP_METHOD_RESPONSE_INV_RINGING 30
|
||||
#define SIP_METHOD_RESPONSE_INV_PROGRESS 31
|
||||
#define SIP_METHOD_RESPONSE_INV_CONFIRM 32
|
||||
#define SIP_METHOD_RESPONSE_INV_REDIR 33
|
||||
#define SIP_METHOD_RESPONSE_INV_REL 34
|
||||
#define SIP_METHOD_RESPONSE_CANCEL 35
|
||||
#define SIP_METHOD_RESPONSE_BYE 36
|
||||
#define SIP_METHOD_RESPONSE_CONFIRM 37//just for other method response
|
||||
#define SIP_METHOD_RESPONSE_REL 38//just for other method response
|
||||
#define SIP_METHOD_RESPONSE_TIMEOUT 39
|
||||
#define SIP_METHOD_RESPONSE_RE_INV_RINGING 40
|
||||
#define SIP_METHOD_RESPONSE_RE_INV_PROGRESS 41
|
||||
#define SIP_METHOD_RESPONSE_RE_INV_CONFIRM 43
|
||||
#define SIP_METHOD_RESPONSE_RE_INV_RETRANSMIT 44
|
||||
#define SIP_METHOD_RESPONSE_RE_INV_FAILED 45
|
||||
#define SIP_METHOD_RESPONSE_RE_INV_RELEASE 46
|
||||
#define SIP_METHOD_RESPONSE_UPDATE_CONFIRM 47
|
||||
#define SIP_METHOD_RESPONSE_UPDATE_FAILED 48
|
||||
|
||||
#define SIP_PROXY_TYPE_NONE 0
|
||||
#define SIP_PROXY_TYPE_STATEFUL 1
|
||||
#define SIP_PROXY_TYPE_STATELESS 2
|
||||
|
||||
// SIP general parameters struct
|
||||
|
||||
typedef struct _SIP_GEN_PARA
|
||||
{
|
||||
BYTE paraName;
|
||||
BYTE paraType;
|
||||
// char paraStr[SIP_MAX_PARA_STRING_LEN];
|
||||
// DWORD paraVal[SIP_MAX_PARA_VAL_LEN];
|
||||
union
|
||||
{
|
||||
char paraStr[SIP_MAX_PARA_STRING_LEN];
|
||||
DWORD paraVal[SIP_MAX_PARA_VAL_LEN];
|
||||
}para;
|
||||
|
||||
}SIP_GEN_PARA;
|
||||
|
||||
typedef struct _SIP_GEN_PARAMS
|
||||
{
|
||||
BYTE paraNum;
|
||||
SIP_GEN_PARA para[SIP_MAX_PARA_NUM];
|
||||
}SIP_GEN_PARAMS;
|
||||
|
||||
// SIP URI struct
|
||||
typedef struct _SIP_URI
|
||||
{
|
||||
BYTE uriType;
|
||||
char userName[SIP_MAX_USER_NAME_LEN];
|
||||
char password[SIP_MAX_PASSWORD_LEN];
|
||||
struct
|
||||
{
|
||||
BYTE type;
|
||||
union
|
||||
{
|
||||
DWORD ipV4;
|
||||
DWORD ipV6[4];
|
||||
char domain[SIP_MAX_DOMAIN_NAME_LEN];
|
||||
}addr;
|
||||
}host;
|
||||
WORD port;
|
||||
BYTE transport;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_URI;
|
||||
|
||||
typedef struct _SIP_VIA_URI
|
||||
{
|
||||
char domain[SIP_MAX_VIA_DOMAIN_NAME_LEN];
|
||||
WORD port;
|
||||
// SIP_GEN_PARAMS params;
|
||||
}SIP_VIA_URI;
|
||||
|
||||
// SIP general header struct
|
||||
|
||||
typedef struct _SIP_HDR_ACCEPT
|
||||
{
|
||||
BYTE type;
|
||||
BYTE subType;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_ACCEPT;
|
||||
|
||||
typedef struct _SIP_HDR_ACCEPT_ENCODING
|
||||
{
|
||||
BYTE acceptEncoding;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_ACCEPT_ENCODING;
|
||||
|
||||
typedef struct _SIP_HDR_ACCEPT_LANGUAGE
|
||||
{
|
||||
BYTE acceptLanguage;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_ACCEPT_LANGUAGE;
|
||||
|
||||
typedef struct _SIP_HDR_CALL_ID
|
||||
{
|
||||
char value[SIP_MAX_CALL_ID_LEN];
|
||||
char host[SIP_MAX_DOMAIN_NAME_LEN];
|
||||
}SIP_HDR_CALL_ID;
|
||||
|
||||
typedef struct _SIP_HDR_CONTACT
|
||||
{
|
||||
char dispName[SIP_MAX_DISPLAY_NAME_LEN];
|
||||
SIP_URI url;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_CONTACT;
|
||||
|
||||
typedef struct _SIP_HDR_CONTACTS
|
||||
{
|
||||
BYTE num;
|
||||
BYTE head;
|
||||
SIP_HDR_CONTACT contacts[SIP_MAX_NUM_OF_CONTACTS];
|
||||
}SIP_HDR_CONTACTS;
|
||||
|
||||
typedef struct _SIP_HDR_CSEQ
|
||||
{
|
||||
DWORD value;
|
||||
BYTE method;
|
||||
}SIP_HDR_CSEQ;
|
||||
|
||||
typedef struct _SIP_HDR_DATE
|
||||
{
|
||||
BYTE wkDay;
|
||||
BYTE mDay;
|
||||
BYTE mon;
|
||||
DWORD year;
|
||||
BYTE hour;
|
||||
BYTE min;
|
||||
BYTE sec;
|
||||
BYTE dateType;
|
||||
|
||||
}SIP_HDR_DATE;
|
||||
|
||||
typedef struct _SIP_HDR_MIME_VERSION
|
||||
{
|
||||
BYTE mimeVersion;
|
||||
}SIP_HDR_MIME_VERSION;
|
||||
|
||||
typedef struct _SIP_HDR_ENCRYPTION
|
||||
{
|
||||
}SIP_HDR_ENCRYPTION;
|
||||
|
||||
typedef struct _SIP_HDR_EXPIRES
|
||||
{
|
||||
DWORD value;
|
||||
}SIP_HDR_EXPIRES;
|
||||
|
||||
typedef struct _SIP_HDR_FROM
|
||||
{
|
||||
char dispName[SIP_MAX_DISPLAY_NAME_LEN];
|
||||
SIP_URI url;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_FROM;
|
||||
|
||||
typedef struct _SIP_HDR_ORGANIZATION
|
||||
{
|
||||
}SIP_HDR_ORGANIZATION;
|
||||
|
||||
typedef struct _SIP_HDR_RECORD_ROUTE
|
||||
{
|
||||
char dispName[SIP_MAX_DISPLAY_NAME_LEN];
|
||||
SIP_URI url;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_RECORD_ROUTE;
|
||||
|
||||
typedef struct _SIP_HDR_RECORD_ROUTES
|
||||
{
|
||||
BYTE num;
|
||||
BYTE head;
|
||||
SIP_HDR_RECORD_ROUTE recRoutes[SIP_MAX_NUM_OF_RECORD_ROUTES];
|
||||
}SIP_HDR_RECORD_ROUTES;
|
||||
|
||||
typedef struct _SIP_HDR_TIMESTAMP
|
||||
{
|
||||
DWORD timeStamp;
|
||||
}SIP_HDR_TIMESTAMP;
|
||||
|
||||
typedef struct _SIP_HDR_TO
|
||||
{
|
||||
char dispName[SIP_MAX_DISPLAY_NAME_LEN];
|
||||
SIP_URI url;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_TO;
|
||||
|
||||
typedef struct _SIP_HDR_USER_AGENT
|
||||
{
|
||||
BYTE agent[SIP_MAX_LENGTH_OF_USER_AGENT];
|
||||
}SIP_HDR_USER_AGENT;
|
||||
|
||||
typedef struct _SIP_HDR_VIA
|
||||
{
|
||||
BYTE version;
|
||||
BYTE protocol;
|
||||
// SIP_URI url;
|
||||
SIP_VIA_URI url;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_VIA;
|
||||
|
||||
typedef struct _SIP_HDR_VIAS
|
||||
{
|
||||
BYTE num;
|
||||
BYTE head;
|
||||
SIP_HDR_VIA vias[SIP_MAX_NUM_OF_VIAS];
|
||||
}SIP_HDR_VIAS;
|
||||
|
||||
// SIP request header struct
|
||||
typedef struct _SIP_HDR_AUTHORIZATION
|
||||
{
|
||||
}SIP_HDR_AUTHORIZATION;
|
||||
|
||||
typedef struct _SIP_HDR_HIDE
|
||||
{
|
||||
}SIP_HDR_HIDE;
|
||||
|
||||
typedef struct _SIP_HDR_MAX_FORWARDS
|
||||
{
|
||||
WORD value;
|
||||
}SIP_HDR_MAX_FORWARDS;
|
||||
|
||||
typedef struct _SIP_HDR_PRIORITY
|
||||
{
|
||||
}SIP_HDR_PRIORITY;
|
||||
|
||||
typedef struct _SIP_HDR_PROXY_AUTHORIZATION
|
||||
{
|
||||
}SIP_HDR_PROXY_AUTHORIZATION;
|
||||
|
||||
typedef struct _SIP_HDR_PROXY_REQUIRE
|
||||
{
|
||||
BYTE optionTag;
|
||||
}SIP_HDR_PROXY_REQUIRE;
|
||||
|
||||
typedef struct _SIP_HDR_ROUTE
|
||||
{
|
||||
char dispName[SIP_MAX_DISPLAY_NAME_LEN];
|
||||
SIP_URI url;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_ROUTE;
|
||||
|
||||
typedef struct _SIP_HDR_ROUTES
|
||||
{
|
||||
BYTE num;
|
||||
BYTE head;
|
||||
SIP_HDR_ROUTE routes[SIP_MAX_NUM_OF_ROUTES];
|
||||
}SIP_HDR_ROUTES;
|
||||
|
||||
typedef struct _SIP_HDR_REFER_TO
|
||||
{
|
||||
char dispName[SIP_MAX_DISPLAY_NAME_LEN];
|
||||
SIP_URI url;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_HDR_REFER_TO;
|
||||
|
||||
typedef struct _SIP_HDR_SUBSCRIPTION_STATE
|
||||
{
|
||||
char subscriptionState[SIP_MAX_LENGTH_OF_SUB_STATE];
|
||||
}SIP_HDR_SUBSCRIPTION_STATE;
|
||||
|
||||
typedef struct _SIP_HDR_EVENT
|
||||
{
|
||||
char event[SIP_MAX_LENGTH_OF_EVENT];
|
||||
}SIP_HDR_EVENT;
|
||||
|
||||
typedef struct _SIP_HDR_REQUIRE
|
||||
{
|
||||
BYTE optionTag;
|
||||
}SIP_HDR_REQUIRE;
|
||||
|
||||
typedef struct _SIP_HDR_RESPONSE_KEY
|
||||
{
|
||||
}SIP_HDR_RESPONSE_KEY;
|
||||
|
||||
typedef struct _SIP_HDR_SUBJECT
|
||||
{
|
||||
BYTE subject[SIP_MAX_LENGTH_OF_SUBJECT];
|
||||
}SIP_HDR_SUBJECT;
|
||||
|
||||
typedef struct _SIP_HDR_SUPPORTED
|
||||
{
|
||||
BYTE optionTag;
|
||||
}SIP_HDR_SUPPORTED;
|
||||
|
||||
// SIP response header struct
|
||||
typedef struct _SIP_HDR_ALLOW
|
||||
{
|
||||
BYTE num;
|
||||
BYTE allowMethod[SIP_MAX_NUM_OF_ALLOW];
|
||||
}SIP_HDR_ALLOW;
|
||||
|
||||
typedef struct _SIP_HDR_PROXY_AUTHENTICATE
|
||||
{
|
||||
}SIP_HDR_PROXY_AUTHENTICATE;
|
||||
|
||||
typedef struct _SIP_HDR_RETRY_AFTER
|
||||
{
|
||||
}SIP_HDR_RETRY_AFTER;
|
||||
|
||||
typedef struct _SIP_HDR_SERVER
|
||||
{
|
||||
BYTE server[64];
|
||||
}SIP_HDR_SERVER;
|
||||
|
||||
typedef struct _SIP_HDR_UNSUPPORTED
|
||||
{
|
||||
BYTE optionTag;
|
||||
}SIP_HDR_UNSUPPORTED;
|
||||
|
||||
typedef struct _SIP_HDR_WARNING
|
||||
{
|
||||
}SIP_HDR_WARNING;
|
||||
|
||||
typedef struct _SIP_HDR_WWW_AUTHENTICATE
|
||||
{
|
||||
}SIP_HDR_WWW_AUTHENTICATE;
|
||||
|
||||
// SIP message struct
|
||||
typedef struct _SIP_START_LINE
|
||||
{
|
||||
BYTE sipVersion; // Public
|
||||
|
||||
BYTE sipMethod; // Request
|
||||
SIP_URI requestUri;
|
||||
|
||||
int statusCode; // Response
|
||||
char reasonPhrase[SIP_MAX_REASON_PHRASE_LEN];
|
||||
}SIP_START_LINE;
|
||||
|
||||
typedef struct _SIP_CONTENT_TYPE
|
||||
{
|
||||
BYTE type;
|
||||
BYTE subType;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_CONTENT_TYPE;
|
||||
|
||||
typedef struct _SIP_CONTENT_DISPOSITION
|
||||
{
|
||||
BYTE contentDisposition;
|
||||
SIP_GEN_PARAMS params;
|
||||
}SIP_CONTENT_DISPOSITION;
|
||||
|
||||
typedef struct _SIP_MESSAGE_BODY
|
||||
{
|
||||
DWORD sipBodyHdrFlg[SIP_MAX_HDR_FLAG_NUM];
|
||||
SIP_CONTENT_TYPE sipBodyContentType;
|
||||
SIP_CONTENT_DISPOSITION sipBodyContentDisposition;
|
||||
BYTE msgBody[SIP_MAX_BODY_LEN];
|
||||
}SIP_MESSAGE_BODY;
|
||||
|
||||
typedef struct _SIP_MESSAGE_BODYS
|
||||
{
|
||||
BYTE sipBodyNum;
|
||||
SIP_MESSAGE_BODY sipBody[SIP_MAX_NUM_OF_SIP_SUB_BODY];
|
||||
}SIP_MESSAGE_BODYS;
|
||||
|
||||
typedef struct _SIP_ENTITY
|
||||
{
|
||||
DWORD sipEntityHdrFlag[SIP_MAX_HDR_FLAG_NUM];
|
||||
BYTE sipHdrContentEncoding;
|
||||
SIP_CONTENT_DISPOSITION sipHdrContentDisposition;
|
||||
WORD sipHdrContentLength;
|
||||
SIP_CONTENT_TYPE sipHdrContentType;
|
||||
BYTE sipHdrContentLanguage;
|
||||
// BYTE sipBody[SIP_MAX_BODY_LEN];
|
||||
SIP_MESSAGE_BODYS sipBodys;
|
||||
}SIP_ENTITY;
|
||||
|
||||
typedef struct _SIP_REQUEST_HDR
|
||||
{
|
||||
SIP_HDR_AUTHORIZATION sipHdrAuthorization;
|
||||
SIP_HDR_HIDE sipHdrHide;
|
||||
SIP_HDR_MAX_FORWARDS sipHdrMaxForwards;
|
||||
SIP_HDR_PRIORITY sipHdrPriority;
|
||||
SIP_HDR_PROXY_AUTHORIZATION sipHdrProxyAuthorization;
|
||||
SIP_HDR_PROXY_REQUIRE sipHdrProxyRequire;
|
||||
SIP_HDR_ROUTES sipHdrRoutes;
|
||||
SIP_HDR_REQUIRE sipHdrRequire;
|
||||
SIP_HDR_RESPONSE_KEY sipHdrResKey;
|
||||
SIP_HDR_SUBJECT sipHdrSubject;
|
||||
SIP_HDR_REFER_TO sipHdrReferTo;
|
||||
SIP_HDR_SUBSCRIPTION_STATE sipHdrSubscriptionState;
|
||||
SIP_HDR_EVENT sipHdrEvent;
|
||||
}SIP_REQUEST_HDR;
|
||||
|
||||
typedef struct _SIP_RESPONSE_HDR
|
||||
{
|
||||
SIP_HDR_PROXY_AUTHENTICATE sipHdrProxyAuthenticate;
|
||||
SIP_HDR_RETRY_AFTER sipHdrRetryAfter;
|
||||
SIP_HDR_SERVER sipHdrServer;
|
||||
SIP_HDR_UNSUPPORTED sipHdrUnsupported;
|
||||
SIP_HDR_WARNING sipHdrWarning;
|
||||
SIP_HDR_WWW_AUTHENTICATE sipHdrWWWAuthenticate;
|
||||
}SIP_RESPONSE_HDR;
|
||||
|
||||
typedef struct _SIP_MSG
|
||||
{
|
||||
SIP_START_LINE sipStartLine;
|
||||
|
||||
// General Headers
|
||||
DWORD sipGenHdrFlag[SIP_MAX_HDR_FLAG_NUM];
|
||||
SIP_HDR_ACCEPT sipHdrAccept;
|
||||
SIP_HDR_ALLOW sipHdrAllow;
|
||||
SIP_HDR_ACCEPT_ENCODING sipHdrAcceptEncoding;
|
||||
SIP_HDR_ACCEPT_LANGUAGE sipHdrAcceptLanguage;
|
||||
SIP_HDR_CALL_ID sipHdrCallId;
|
||||
SIP_HDR_CONTACTS sipHdrContacts;
|
||||
SIP_HDR_CSEQ sipHdrCseq;
|
||||
SIP_HDR_DATE sipHdrDate;
|
||||
SIP_HDR_MIME_VERSION sipHdrMimeVer;
|
||||
SIP_HDR_ENCRYPTION sipHdrEncryption;
|
||||
SIP_HDR_EXPIRES sipHdrExpires;
|
||||
SIP_HDR_FROM sipHdrFrom;
|
||||
SIP_HDR_ORGANIZATION sipHdrOrganization;
|
||||
SIP_HDR_RECORD_ROUTES sipHdrRecordRoutes;
|
||||
SIP_HDR_TIMESTAMP sipHdrStamp;
|
||||
SIP_HDR_SUPPORTED sipHdrSupported;
|
||||
SIP_HDR_TO sipHdrTo;
|
||||
SIP_HDR_VIAS sipHdrVias;
|
||||
SIP_HDR_USER_AGENT sipHdrUserAgent;
|
||||
|
||||
struct
|
||||
{
|
||||
DWORD sipReHdrFlag[SIP_MAX_HDR_FLAG_NUM];
|
||||
union
|
||||
{
|
||||
SIP_REQUEST_HDR sipReqHdr;
|
||||
SIP_RESPONSE_HDR sipRspHdr;
|
||||
}sipReHdr;
|
||||
}sipReStruct;
|
||||
|
||||
SIP_ENTITY sipEntity;
|
||||
}SIP_MSG;
|
||||
|
||||
typedef struct _SIP_MANAGE
|
||||
{
|
||||
BYTE cmd;
|
||||
}SIP_MANAGE;
|
||||
|
||||
typedef struct _SIP_TRANSPORT_ADDR
|
||||
{
|
||||
BYTE type;
|
||||
WORD port;
|
||||
union
|
||||
{
|
||||
DWORD ipV4;
|
||||
DWORD ipV6[4];
|
||||
}addr;
|
||||
}SIP_TRANSPORT_ADDR;
|
||||
|
||||
typedef struct _SIP_API_STRUCT
|
||||
{
|
||||
BYTE sipApiType; // SIP_API_REQ_MSG/SIP_API_RES_MSG/SIP_API_MANAGE_MSG
|
||||
SIP_TRANSPORT_ADDR sipTransAddr; // Transport address of the SIP message
|
||||
union
|
||||
{
|
||||
SIP_MSG sipMsg; // Including request and response
|
||||
SIP_MANAGE sipManage;
|
||||
}sipApiMsg;
|
||||
}SIP_API_STRUCT;
|
||||
|
||||
typedef struct _SIP_CR_MSG
|
||||
{
|
||||
SIP_TRANSPORT_ADDR sipTransAddr;
|
||||
SIP_START_LINE sipCrStartLine;
|
||||
SIP_HDR_VIA sipCrHdrVia;
|
||||
SIP_HDR_CSEQ sipCrHdrCseq;
|
||||
SIP_HDR_TO sipCrHdrTo;
|
||||
SIP_HDR_FROM sipCrHdrFrom;
|
||||
SIP_HDR_CALL_ID sipCrHdrCallId;
|
||||
}SIP_CR_MSG;
|
||||
|
||||
// SIP USER struct
|
||||
/* The upper layer register recv_proc call-back function to receive sip messages
|
||||
upPort: destination UP port the message will be sent to, if unknown, it should be set to 0xFFFF.
|
||||
sipPort: source SIP port the UP message is sent from, if no sip_port is maintained, it's set to 0xFFFF
|
||||
transFlag: indicates whether this message sent from SIP transport layer directly or sent from SIP transaction layer.
|
||||
sipApiMsg: a pointer to the message pointer that is pointing to the message struct of the upper layer, so the received message can be accessed at that address
|
||||
returns 0 if succeeds, otherwise returns -1
|
||||
*/
|
||||
typedef struct _SIP_USER
|
||||
{
|
||||
BYTE proxyType;
|
||||
char userName[16];
|
||||
char domain[SIP_MAX_DOMAIN_NAME_LEN];
|
||||
int (*recv_proc)(WORD sipPort, WORD upPort, BYTE transFlag, SIP_API_STRUCT *sipApiMsg);
|
||||
}SIP_USER;
|
||||
|
||||
/*typedef struct _SIP_SIP_UA_USER
|
||||
{
|
||||
char domain[SIP_MAX_DOMAIN_NAME_LEN];
|
||||
}SIP_SIP_UA_USER;*/
|
||||
|
||||
// Should be called in the main program when system starts up,
|
||||
// Returns 0 if succeeds, otherwise returns -1
|
||||
int sip_init();
|
||||
|
||||
// Should be called every 10 ms in the platform section of the main program
|
||||
void sip_timer();
|
||||
void sip_t10ms();
|
||||
|
||||
/* The upper layer uses this function to send sip message to the peer
|
||||
sipTransId: destination SIP port the UP message will be sent to, if unknown, it should be set to 0xFFFF
|
||||
upPort: source UP port the message is sent from
|
||||
transFlag: indicates whether this message will be sent within SIP transaction layer (stateful proxy or user agent),
|
||||
or directly goes to the SIP transport layer (stateless proxy)
|
||||
sipApiMsg: a pointer pointing to the actual struct of the message to be sent to the SIP module
|
||||
if succeeds, returns sip_port, otherwise return a negative value
|
||||
if succeeds, and no sip_port is maintained for this message, returns 0xFFFF
|
||||
*/
|
||||
int sip_send_msg(WORD sipTransId, WORD upPort, BYTE transFlag, SIP_API_STRUCT *sipApiMsg);
|
||||
|
||||
/* The upper layer register its domain name and message receive callback function to the SIP module
|
||||
if succeeds, returns 0, otherwise returns -1
|
||||
*/
|
||||
int sip_register_user(SIP_USER *sipUser);
|
||||
|
||||
/* The upper layer use this function to create trascation
|
||||
client: clent/server
|
||||
method: invite/non-invite
|
||||
*/
|
||||
int sip_create_transaction(BYTE client, BYTE method, BYTE userIndex, WORD upPort, SIP_API_STRUCT *msg);
|
||||
|
||||
int sip_create_trans_branch(WORD transId, SIP_GEN_PARA *branch);
|
||||
|
||||
#endif
|
||||
154
plat/sip/src/include/sip_const.h
Normal file
154
plat/sip/src/include/sip_const.h
Normal file
@@ -0,0 +1,154 @@
|
||||
#ifndef _SIP_CONST__H
|
||||
#define _SIP_CONST__H
|
||||
|
||||
#define SIP_TCP_BACKLOG 64
|
||||
|
||||
#define SIP_MAX_NUM_OF_TCP_SOCK 512
|
||||
|
||||
#define SIP_MAX_NUM_OF_USERS 4
|
||||
|
||||
#define SIP_MAX_NUM_OF_SIP_UA_USER 4
|
||||
|
||||
#define SIP_MAX_NUM_OF_TRANS_1 4095//8191
|
||||
|
||||
#define SIP_MAX_TCP_MSG_LEN 1500
|
||||
|
||||
#define SIP_MAX_UDP_MSG_LEN 1500
|
||||
#define SIP_MAX_UDP_MSG_GET_TIMES 64
|
||||
|
||||
#define SIP_MAX_ESCAPE_BUF_LEN 64
|
||||
|
||||
#define SIP_STR_TO_API 1
|
||||
#define SIP_API_TO_STR 2
|
||||
|
||||
#define SIP_MESSAGE_BODY_FLAG 1
|
||||
#define SIP_SUB_BODY_FLAG 2
|
||||
|
||||
#define SIP_COMMAND_IDLE 0
|
||||
|
||||
#define SIP_VERSION_2_0 20
|
||||
|
||||
#define SIP_MIME_VERSION_1_0 10
|
||||
|
||||
#define SIP_HASH_TABLE_SIZE 200 // 150 is the first size where no conflicts occur
|
||||
#define SIP_MAX_NUM_OF_HEADERS 48
|
||||
|
||||
#define SIP_HNAME_ACCEPT "accept"
|
||||
#define SIP_HNAME_ACCEPT_ENCODING "accept-encoding"
|
||||
#define SIP_HNAME_ACCEPT_LANGUAGE "accept-language"
|
||||
#define SIP_HNAME_ALERT_INFO "alert-info"
|
||||
#define SIP_HNAME_ALLOW "allow"
|
||||
#define SIP_HNAME_AUTHENTICATION_INFO "authentication-info"
|
||||
#define SIP_HNAME_AUTHORIZATION "authorization"
|
||||
#define SIP_HNAME_CALL_ID "call-id"
|
||||
#define SIP_HNAME_CALL_ID_SHORT "i"
|
||||
#define SIP_HNAME_CALL_INFO "call-info"
|
||||
#define SIP_HNAME_CONTACT "contact"
|
||||
#define SIP_HNAME_CONTACT_SHORT "m"
|
||||
#define SIP_HNAME_CONTENT_DISPOSITION "content-disposition"
|
||||
#define SIP_HNAME_CONTENT_ENCODING_SHORT "e"
|
||||
#define SIP_HNAME_CONTENT_ENCODING "content-encoding"
|
||||
#define SIP_HNAME_CONTENT_LANGUAGE "content-language"
|
||||
#define SIP_HNAME_CONTENT_LENGTH_SHORT "l"
|
||||
#define SIP_HNAME_CONTENT_LENGTH "content-length"
|
||||
#define SIP_HNAME_CONTENT_TYPE_SHORT "c"
|
||||
#define SIP_HNAME_CONTENT_TYPE "content-type"
|
||||
#define SIP_HNAME_CSEQ "cseq"
|
||||
#define SIP_HNAME_SIPDATE "date"
|
||||
#define SIP_HNAME_ERROR_INFO "error-info"
|
||||
#define SIP_HNAME_EVENT "event"
|
||||
#define SIP_HNAME_EXPIRES "expires"
|
||||
#define SIP_HNAME_FROM "from"
|
||||
#define SIP_HNAME_FROM_SHORT "f"
|
||||
#define SIP_HNAME_IN_REPLY_TO "in-reply-to"
|
||||
#define SIP_HNAME_MAX_FORWARDS "max-forwards"
|
||||
#define SIP_HNAME_MIME_VERSION "mime-version"
|
||||
#define SIP_HNAME_MIN_EXPIRES "min-expires"
|
||||
#define SIP_HNAME_ORGANIZATION "organization"
|
||||
#define SIP_HNAME_PRIORITY "priority"
|
||||
#define SIP_HNAME_PROXY_AUTHENTICATE "proxy-authenticate"
|
||||
#define SIP_HNAME_PROXY_AUTHENTICATION_INFO "proxy-authentication-info"
|
||||
#define SIP_HNAME_PROXY_AUTHORIZATION "proxy-authorization"
|
||||
#define SIP_HNAME_PROXY_REQUIRE "proxy-require"
|
||||
#define SIP_HNAME_RECORD_ROUTE "record-route"
|
||||
#define SIP_HNAME_REFER_TO "refer-to"
|
||||
#define SIP_HNAME_REFER_TO_SHORT "r"
|
||||
#define SIP_HNAME_REPLY_TO "reply-to"
|
||||
#define SIP_HNAME_REQUIRE "require"
|
||||
#define SIP_HNAME_RETRY_AFTER "retry-after"
|
||||
#define SIP_HNAME_ROUTE "route"
|
||||
#define SIP_HNAME_SERVER "server"
|
||||
#define SIP_HNAME_SUBJECT "subject"
|
||||
#define SIP_HNAME_SUBJECT_SHORT "s"
|
||||
#define SIP_HNAME_SUPPORTED "supported"
|
||||
#define SIP_HNAME_SUPPORTED_SHORT "k"
|
||||
#define SIP_HNAME_SUBSCRIPTION_STATE "subscription-state"
|
||||
#define SIP_HNAME_TIMESTAMP "timestamp"
|
||||
#define SIP_HNAME_TO "to"
|
||||
#define SIP_HNAME_TO_SHORT "t"
|
||||
#define SIP_HNAME_UNSUPPORTED "unsupported"
|
||||
#define SIP_HNAME_USER_AGENT "user-agent"
|
||||
#define SIP_HNAME_VIA "via"
|
||||
#define SIP_HNAME_VIA_SHORT "v"
|
||||
#define SIP_HNAME_WARNING "warning"
|
||||
#define SIP_HNAME_WWW_AUTHENTICATE "www-authenticate"
|
||||
#define SIP_HNAME_MAX_FORWARDS "max-forwards"
|
||||
|
||||
#define SIP_TRANS_MAIN_STATE_INIT 0
|
||||
#define SIP_TRANS_MAIN_STATE_SVR_NON_INV 1
|
||||
#define SIP_TRANS_MAIN_STATE_SVR_INV 2
|
||||
#define SIP_TRANS_MAIN_STATE_CLT_NON_INV 3
|
||||
#define SIP_TRANS_MAIN_STATE_CLT_INV 4
|
||||
|
||||
#define SIP_TRANS_STATE_IDLE 0
|
||||
#define SIP_TRANS_STATE_TRYING 1
|
||||
#define SIP_TRANS_STATE_CALLING 2
|
||||
#define SIP_TRANS_STATE_PROCEEDING 3
|
||||
#define SIP_TRANS_STATE_COMPLETED 4
|
||||
#define SIP_TRANS_STATE_CONFIRMED 5
|
||||
#define SIP_TRANS_STATE_TERMINATED 6
|
||||
|
||||
#define SIP_PNAME_TAG "tag"
|
||||
#define SIP_PNAME_BRANCH "branch"
|
||||
#define SIP_PNAME_EXPIRES "expires"
|
||||
#define SIP_PNAME_USER "user"
|
||||
#define SIP_PNAME_LR "lr"
|
||||
#define SIP_PNAME_BOUNDARY "boundary"
|
||||
#define SIP_PNAME_HANDLING "handling"
|
||||
#define SIP_PNAME_TRANSPORT "transport"
|
||||
#define SIP_PNAME_RPORT "rport"
|
||||
#define SIP_PNAME_VERSION "version"
|
||||
#define SIP_PNAME_BASE "base"
|
||||
|
||||
#define SIP_TIMER_T1 25 // default: 500 ms
|
||||
#define SIP_TIMER_T2 400 // default: 4 s
|
||||
#define SIP_TIMER_T4 500 // default: 5 s
|
||||
#define SIP_TIMER_A SIP_TIMER_T1
|
||||
#define SIP_TIMER_B (128 * SIP_TIMER_T1)//(64 * SIP_TIMER_T1)
|
||||
#define SIP_TIMER_D (32 *SIP_TIMER_T1)//(64 * SIP_TIMER_T1)//
|
||||
#define SIP_TIMER_E_INITIAL SIP_TIMER_T1
|
||||
#define SIP_TIMER_F (32 * SIP_TIMER_T1)//(64 * SIP_TIMER_T1)//
|
||||
#define SIP_TIMER_G SIP_TIMER_T1
|
||||
#define SIP_TIMER_H (32 * SIP_TIMER_T1)//(64 * SIP_TIMER_T1)//
|
||||
#define SIP_TIMER_I 2//SIP_TIMER_T4
|
||||
#define SIP_TIMER_J (32 * SIP_TIMER_T1)//(64 * SIP_TIMER_T1)//
|
||||
#define SIP_TIMER_K 2//SIP_TIMER_T4
|
||||
#define SIP_TIMER_200MS 20
|
||||
|
||||
#define SIP_ENCODE_URL_ALL 0x00
|
||||
#define SIP_ENCODE_URL_NO_BRACKETS 0x01
|
||||
#define SIP_ENCODE_URL_NO_USER_PART 0x02
|
||||
|
||||
#define SIP_BRANCH_BASE_TRANS_ID 10000
|
||||
#define SIP_BRANCH_BASE_TRANS_ID_LEN 5
|
||||
|
||||
#define SIP_MAX_ASCIIIN_LEN 4096
|
||||
#define SIP_MAX_ASCIIOUT_LEN 4096
|
||||
#define SIP_MAX_ASCITMP_LEN 4096
|
||||
|
||||
#define SIP_MONITOR_NONE 0x0000
|
||||
#define MONITOR_SIP_MSG 0x0001
|
||||
#define SIP_MONITOR_ERROR 0x0002
|
||||
#define SIP_MONITOR_ALL 0xffff
|
||||
|
||||
#endif
|
||||
10
plat/sip/src/include/sip_debug.h
Normal file
10
plat/sip/src/include/sip_debug.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _SIP_DEBUG__H
|
||||
#define _SIP_DEBUG__H
|
||||
|
||||
void sip_mon(void);
|
||||
int sip_debug_set(void);
|
||||
int sip_asciout_proc(BYTE *outStr);
|
||||
int sip_hex_to_ascii(BYTE *fromHex, BYTE fromLen, BYTE *toAsc);
|
||||
int sip_log_err(BYTE *errMsg);
|
||||
|
||||
#endif
|
||||
49
plat/sip/src/include/sip_def.h
Normal file
49
plat/sip/src/include/sip_def.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef _SIP_DEF__H
|
||||
#define _SIP_DEF__H
|
||||
|
||||
#include "sip_pub.h"
|
||||
#include "sip.h"
|
||||
#include "sip_const.h"
|
||||
#include "sip_struct.h"
|
||||
|
||||
int sipUdpSocketFd;
|
||||
int sipTcpServerSocketFd;
|
||||
|
||||
char sipHostName[50];
|
||||
char sipDottedHostIp[20];
|
||||
DWORD sipHostIp;
|
||||
|
||||
BYTE sipUdpMsgSdBuf[SIP_MAX_UDP_MSG_LEN];
|
||||
BYTE sipUdpMsgRvBuf[SIP_MAX_UDP_MSG_LEN];
|
||||
BYTE sipTcpMsgRvBuf[SIP_MAX_TCP_MSG_LEN];
|
||||
|
||||
BYTE sipEncBuf[SIP_MAX_UDP_MSG_LEN];
|
||||
char sipEscapeBuf[SIP_MAX_ESCAPE_BUF_LEN];
|
||||
|
||||
SIP_TCP_SOCK sipTcpSock[SIP_MAX_NUM_OF_TCP_SOCK];
|
||||
|
||||
SIP_API_STRUCT sipRecvMsg;
|
||||
SIP_API_STRUCT sipSendMsg;
|
||||
|
||||
SIP_API_STRUCT sipToUpMsg;
|
||||
|
||||
struct sockaddr_in sipSrcInAddr;
|
||||
struct sockaddr_in sipDstInAddr;
|
||||
|
||||
int sipHdrRefTable[SIP_HASH_TABLE_SIZE]; // the hash table contains indices to the sipParseConfig table
|
||||
SIP_HDR_CONFIG sipParseConfig[SIP_MAX_NUM_OF_HEADERS];
|
||||
|
||||
SIP_USERS_STRUCT sipUsers;
|
||||
SIP_TRANSACTION sipTrans[SIP_MAX_NUM_OF_TRANS];
|
||||
|
||||
//SIP_SIP_UA_USER sipSipUaUser[SIP_MAX_NUM_OF_SIP_UA_USER];
|
||||
|
||||
WORD sipTransHead;
|
||||
WORD sipDlgSelect;
|
||||
|
||||
BYTE sipAsciInBuf[SIP_MAX_ASCIIIN_LEN];
|
||||
BYTE sipAsciOutBuf[SIP_MAX_ASCIIOUT_LEN];
|
||||
BYTE sipAsciTempBuf[SIP_MAX_ASCITMP_LEN];
|
||||
WORD sipMonitorFg;
|
||||
|
||||
#endif
|
||||
48
plat/sip/src/include/sip_ext.h
Normal file
48
plat/sip/src/include/sip_ext.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef _SIP_EXT__H
|
||||
#define _SIP_EXT__H
|
||||
|
||||
#include "sip_pub.h"
|
||||
#include "sip.h"
|
||||
#include "sip_const.h"
|
||||
#include "sip_struct.h"
|
||||
|
||||
extern int sipUdpSocketFd;
|
||||
extern int sipTcpServerSocketFd;
|
||||
|
||||
extern char sipHostName[50];
|
||||
extern char sipDottedHostIp[20];
|
||||
extern DWORD sipHostIp;
|
||||
|
||||
extern BYTE sipUdpMsgSdBuf[SIP_MAX_UDP_MSG_LEN];
|
||||
extern BYTE sipUdpMsgRvBuf[SIP_MAX_UDP_MSG_LEN];
|
||||
extern BYTE sipTcpMsgRvBuf[SIP_MAX_TCP_MSG_LEN];
|
||||
|
||||
extern BYTE sipEncBuf[SIP_MAX_UDP_MSG_LEN];
|
||||
extern char sipEscapeBuf[SIP_MAX_ESCAPE_BUF_LEN];
|
||||
|
||||
extern SIP_TCP_SOCK sipTcpSock[SIP_MAX_NUM_OF_TCP_SOCK];
|
||||
|
||||
extern SIP_API_STRUCT sipRecvMsg;
|
||||
extern SIP_API_STRUCT sipSendMsg;
|
||||
|
||||
extern SIP_API_STRUCT sipToUpMsg;
|
||||
|
||||
extern struct sockaddr_in sipSrcInAddr;
|
||||
extern struct sockaddr_in sipDstInAddr;
|
||||
|
||||
extern int sipHdrRefTable[SIP_HASH_TABLE_SIZE];
|
||||
extern SIP_HDR_CONFIG sipParseConfig[SIP_MAX_NUM_OF_HEADERS];
|
||||
|
||||
extern SIP_USERS_STRUCT sipUsers;
|
||||
extern SIP_TRANSACTION sipTrans[SIP_MAX_NUM_OF_TRANS];
|
||||
|
||||
//extern SIP_SIP_UA_USER sipSipUaUser[SIP_MAX_NUM_OF_SIP_UA_USER];
|
||||
|
||||
extern WORD sipTransHead;
|
||||
|
||||
extern BYTE sipAsciInBuf[SIP_MAX_ASCIIIN_LEN];
|
||||
extern BYTE sipAsciOutBuf[SIP_MAX_ASCIIOUT_LEN];
|
||||
extern BYTE sipAsciTempBuf[SIP_MAX_ASCITMP_LEN];
|
||||
extern WORD sipMonitorFg;
|
||||
|
||||
#endif
|
||||
36
plat/sip/src/include/sip_msg.h
Normal file
36
plat/sip/src/include/sip_msg.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _SIP_MSG__H
|
||||
#define _SIP_MSG__H
|
||||
|
||||
#define sip_generic_param_add(LIST,NAME,VALUE) sip_uri_param_add(LIST,NAME,VALUE)
|
||||
#define sip_uri_uparam_add(url,name,value) sip_uri_param_add((&(url)->params),name,value)
|
||||
|
||||
int sip_recv_msg_handling(char *msg, WORD len, int tcpSockIndex);
|
||||
int sip_method_api_conv(char *str, BYTE *method, BYTE flag);
|
||||
int sip_uri_type_api_conv(char *str, BYTE *uriType, BYTE flag);
|
||||
int sip_ver_api_conv(char *str, BYTE *ver, BYTE flag);
|
||||
int sip_proto_api_conv(char *str, BYTE *proto, BYTE flag);
|
||||
int sip_content_type_api_conv(char *str, BYTE *contentType, BYTE flag);
|
||||
int sip_content_sub_type_api_conv(char *str, BYTE *contentSubType, BYTE flag);
|
||||
int sip_accept_type_api_conv(char *str, BYTE *acceptType, BYTE flag);
|
||||
int sip_accept_sub_type_api_conv(char *str, BYTE *acceptSubType, BYTE flag);
|
||||
int sip_accept_encoding_api_conv(char *str, BYTE *acceptEncoding, BYTE flag);
|
||||
int sip_accept_language_api_conv(char *str, BYTE *acceptLanguage, BYTE flag) ;
|
||||
int sip_allow_api_conv(char *str, BYTE *allowMethod, BYTE flag);
|
||||
int sip_option_tag_api_conv(char *str, BYTE *option, BYTE flag);
|
||||
int sip_mime_version_api_conv(char *str, BYTE *mimeVersion, BYTE flag);
|
||||
int sip_date_weekday_api_conv(char *str, BYTE *weekday, BYTE flag);
|
||||
int sip_date_month_api_conv(char *str, BYTE *month, BYTE flag);
|
||||
int sip_date_type_api_conv(char *str, BYTE *dateType, BYTE flag);
|
||||
int sip_content_disposition_api_conv(char *str, BYTE *contentDisposition, BYTE flag);
|
||||
int sip_content_encoding_api_conv(char *str, BYTE *contentEncoding, BYTE flag);
|
||||
int sip_content_language_api_conv(char *str, BYTE *contentLanguage, BYTE flag);
|
||||
void sip_fill_msg_with_cr(SIP_MSG *sipMsg, SIP_CR_MSG *sipCrMsg);
|
||||
void sip_fill_cr_msg(SIP_CR_MSG *sipCrMsg, SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_send_ack(SIP_API_STRUCT *ackMsg, SIP_TRANSACTION *trans);
|
||||
int sip_send_100(SIP_CR_MSG *ackMsg, SIP_TRANSACTION *trans);
|
||||
int sip_send_option_rsp(SIP_API_STRUCT *sipApiMsg);
|
||||
BYTE sip_search_user_by_domain(SIP_URI *sipUri);
|
||||
int sip_send_call_not_exit_rsp(SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_send_not_find_rsp(SIP_API_STRUCT *sipApiMsg);
|
||||
|
||||
#endif
|
||||
24
plat/sip/src/include/sip_msg_encode.h
Normal file
24
plat/sip/src/include/sip_msg_encode.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef _SIP_MSG_ENCODE__H
|
||||
#define _SIP_MSG_ENCODE__H
|
||||
|
||||
#define _ALPHANUM_ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\0"
|
||||
#define _RESERVED_ ";/?:@&=+$\0"
|
||||
#define _MARK_ "-_.!~*'()\0"
|
||||
|
||||
#define _MARK__USER_UNRESERVED_ "-_.!~*'()&=+$,;?/\0"
|
||||
#define _MARK__PWORD_UNRESERVED_ "-_.!~*'()&=+$,\0"
|
||||
#define _MARK__URI_PARAM_UNRESERVED_ "-_.!~*'()[]/:&+$\0"
|
||||
#define _MARK__HEADER_PARAM_UNRESERVED_ "-_.!~*'()[]/?:+$\0"
|
||||
|
||||
#define sip_is_alphanum(in) ( \
|
||||
(in >= 'a' && in <= 'z') || \
|
||||
(in >= 'A' && in <= 'Z') || \
|
||||
(in >= '0' && in <= '9'))
|
||||
|
||||
int sip_transport_encode_start_line(char *dest, SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_transport_encode_headers(char *dest, SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_transport_encode_body(char *dest, SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_transport_set_addr(struct sockaddr_in *dstAddr, SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_transport_set_sd_addr(struct sockaddr_in *dstAddr, SIP_TRANSPORT_ADDR *sipTransAddr);
|
||||
|
||||
#endif
|
||||
12
plat/sip/src/include/sip_msg_parse.h
Normal file
12
plat/sip/src/include/sip_msg_parse.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _SIP_MSG_PARSE__H
|
||||
#define _SIP_MSG_PARSE__H
|
||||
|
||||
void sip_util_replace_all_lws(char *msg);
|
||||
int sip_set_next_token(char **dest, char *buf, int endSeparator, char **next);
|
||||
int sip_msg_start_line_parse(SIP_API_STRUCT *dest, char *buf, char **nextHeader);
|
||||
int sip_uri_parse(SIP_URI *sipUri, char *buf);
|
||||
int sip_msg_headers_parse(SIP_API_STRUCT *sip, char *buf, char **body);
|
||||
int sip_body_parse(SIP_API_STRUCT *sip, char *buf, WORD len);
|
||||
int sip_parser_init(void);
|
||||
|
||||
#endif
|
||||
55
plat/sip/src/include/sip_pub.h
Normal file
55
plat/sip/src/include/sip_pub.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef _SIP_PUB__H
|
||||
#define _SIP_PUB__H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#include <netdb.h>
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
//by simon at 23/9/22
|
||||
//#include <stropts.h>
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
#include <termio.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/io.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/msg.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#ifndef _T_BYTE
|
||||
#define _T_BYTE
|
||||
typedef unsigned char BYTE;
|
||||
#endif
|
||||
|
||||
#ifndef _T_WORD
|
||||
#define _T_WORD
|
||||
typedef unsigned short WORD;
|
||||
#endif
|
||||
|
||||
#ifndef _T_DWORD
|
||||
#define _T_DWORD
|
||||
typedef unsigned int DWORD;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
62
plat/sip/src/include/sip_struct.h
Normal file
62
plat/sip/src/include/sip_struct.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef _SIP_STRUCT__H
|
||||
#define _SIP_STRUCT__H
|
||||
|
||||
#include "sip_pub.h"
|
||||
#include "sip.h"
|
||||
#include "sip_const.h"
|
||||
|
||||
// Internal type for parser's config
|
||||
typedef struct _SIP_HDR_CONFIG
|
||||
{
|
||||
char *hname;
|
||||
int (*setheader)(SIP_API_STRUCT *, char *);
|
||||
}SIP_HDR_CONFIG;
|
||||
|
||||
typedef struct _SIP_USER_STRUCT
|
||||
{
|
||||
BYTE flag;
|
||||
SIP_USER sipUser;
|
||||
}SIP_USER_STRUCT;
|
||||
|
||||
typedef struct _SIP_USERS_STRUCT
|
||||
{
|
||||
BYTE proxyIndex;
|
||||
SIP_USER_STRUCT sipUsers[SIP_MAX_NUM_OF_USERS];
|
||||
}SIP_USERS_STRUCT;
|
||||
|
||||
typedef struct _SIP_TRANS_SD_MSG
|
||||
{
|
||||
SIP_TRANSPORT_ADDR sipSdAddr;
|
||||
BYTE sdMsg[SIP_MAX_UDP_MSG_LEN];
|
||||
}SIP_TRANS_SD_MSG;
|
||||
|
||||
typedef struct _SIP_TRANSACTION
|
||||
{
|
||||
BYTE flag;
|
||||
BYTE userIndex;
|
||||
BYTE tcpSockIndex;
|
||||
BYTE client;
|
||||
BYTE method;
|
||||
BYTE mainState;
|
||||
BYTE state;
|
||||
WORD upPort;
|
||||
WORD rvCmd;
|
||||
WORD sdCmd;
|
||||
DWORD timer;
|
||||
DWORD timer2;
|
||||
BYTE retransTimes;
|
||||
|
||||
SIP_CR_MSG crMsg;
|
||||
// SIP_API_STRUCT sdMsg;
|
||||
|
||||
SIP_TRANS_SD_MSG transSdMsg;
|
||||
}SIP_TRANSACTION;
|
||||
|
||||
typedef struct _SIP_TCP_SOCK
|
||||
{
|
||||
BYTE flag;
|
||||
int sendRecvSock;
|
||||
struct sockaddr_in remoteAddr;
|
||||
}SIP_TCP_SOCK;
|
||||
|
||||
#endif
|
||||
11
plat/sip/src/include/sip_transaction.h
Normal file
11
plat/sip/src/include/sip_transaction.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _SIP_TRANSACTION__H
|
||||
#define _SIP_TRANSACTION_H
|
||||
|
||||
void sip_transaction_proc(WORD transid);
|
||||
void sip_trans_init(WORD trans_id);
|
||||
WORD sip_request_match_server_trans(SIP_API_STRUCT *recvMsg);
|
||||
WORD sip_response_match_client_trans(SIP_API_STRUCT *recvMsg);
|
||||
int sip_set_trans_send_cmd(SIP_TRANSACTION *trans, SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_msg_transport_to_transaction(SIP_API_STRUCT *recvMsg, WORD transId);
|
||||
|
||||
#endif
|
||||
9
plat/sip/src/include/sip_transport.h
Normal file
9
plat/sip/src/include/sip_transport.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _SIP_TRANSPORT__H
|
||||
#define _SIP_TRANSPORT_H
|
||||
|
||||
void sip_transport_proc();
|
||||
int sip_transport_encode_trans_msg(SIP_TRANSACTION *trans, SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_transport_send_msg(SIP_API_STRUCT *sipApiMsg);
|
||||
int sip_transport_send_trans_msg(SIP_TRANS_SD_MSG *transSdMsg);
|
||||
|
||||
#endif
|
||||
39
plat/sip/src/include/sip_ua.h
Normal file
39
plat/sip/src/include/sip_ua.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef _SIP_UA_H
|
||||
#define _SIP_UA_H
|
||||
|
||||
#include "sip_ua_pub.h"
|
||||
#include "sip.h"
|
||||
#include "../../../pal/pal.h"
|
||||
|
||||
#define sip_response_match_ua_dialog(sipMsg) sip_ua_match_dialog_with_rsp(sipMsg)
|
||||
|
||||
typedef struct _SIP_UA_SAP
|
||||
{
|
||||
BYTE proxyType;
|
||||
char userName[16];
|
||||
char domain[SIP_MAX_DOMAIN_NAME_LEN];
|
||||
int (*recv_req)(WORD sipUaPort, WORD usrPort, WORD dialogId, BYTE method, SIP_API_STRUCT *sipApiMsg, pal_cg_struct *cg);
|
||||
int (*recv_resp)(WORD usrPort, WORD dialogId, WORD statusCode, SIP_API_STRUCT *sipApiMsg);
|
||||
}SIP_UA_SAP;
|
||||
|
||||
typedef struct _SIP_EVENTHANDLE_STRUCT
|
||||
{
|
||||
int (*recv_req)(WORD sipUaPort, WORD usrPort, WORD dialogId, BYTE method, SIP_API_STRUCT *sipApiMsg, pal_cg_struct *cg);
|
||||
int (*recv_resp)(WORD usrPort, WORD dialogId, WORD statusCode, SIP_API_STRUCT *sipApiMsg);
|
||||
}SIP_EVENTHANDLE_STRUCT;
|
||||
|
||||
int sip_ua_init();
|
||||
//int sip_ua_bind(SIP_UA_SAP *sap);
|
||||
int sip_ua_init_port(WORD port);
|
||||
int sip_ua_init_dialog(WORD dialogId);
|
||||
|
||||
int sip_ua_get_port();
|
||||
|
||||
|
||||
WORD sip_ua_match_dialog_with_req(SIP_API_STRUCT *request);
|
||||
WORD sip_ua_match_dialog_with_rsp(SIP_API_STRUCT *response);
|
||||
|
||||
int sip_query_sip_ua_users(SIP_URI *sipUri);
|
||||
|
||||
#endif
|
||||
|
||||
57
plat/sip/src/include/sip_ua_const.h
Normal file
57
plat/sip/src/include/sip_ua_const.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef _SIP_UA_CONST_H
|
||||
#define _SIP_UA_CONST_H
|
||||
|
||||
#define SIP_UA_MAX_NUM_OF_PORT 4096//8192
|
||||
|
||||
#define SIP_UA_MAX_NUM_OF_DIALOG 4096//8192
|
||||
|
||||
#define SIP_UA_MAX_NUM_OF_SAP 4
|
||||
|
||||
#define SIP_UA_NULL_DIALOG 0xFFFF
|
||||
|
||||
#define SIP_UA_NULL_PORT 0xFFFF
|
||||
|
||||
#define SIP_UA_NULL_UP_PORT 0xFFFF
|
||||
|
||||
#define SIP_UA_SEND_COM_NULL 0
|
||||
|
||||
#define SIP_UA_RECV_COM_NULL 0
|
||||
|
||||
#define SIP_UA_FSM_STATE_INDICATE 1
|
||||
#define SIP_UA_FSM_STATE_REQUEST 2
|
||||
|
||||
#define SIP_UA_MAIN_STATE_IDLE 0
|
||||
#define SIP_UA_MAIN_STATE_INVITE_REQ 1
|
||||
#define SIP_UA_MAIN_STATE_NON_INVITE_REQ 2
|
||||
#define SIP_UA_MAIN_STATE_INVITE_RSP 3
|
||||
#define SIP_UA_MAIN_STATE_NON_INVITE_RSP 4
|
||||
#define SIP_UA_MAIN_STATE_INIT 5
|
||||
|
||||
#define SIP_UA_SEND_REQUEST 1
|
||||
#define SIP_UA_REQ_WAIT_FOR_RSP 2
|
||||
#define SIP_UA_INV_REQ_TERMINATED 3
|
||||
#define SIP_UA_SEND_RESPONSE 4
|
||||
#define SIP_UA_INV_200_RSP_WAIT_FOR_ACK 5
|
||||
#define SIP_UA_INV_RSP_TERMINATED 6
|
||||
|
||||
#define WAIT_200_ACK_TIME_OUT 97
|
||||
#define WAIT_RSP_TIME_OUT 98
|
||||
|
||||
#define SIP_UA_TIMER_RETRANSMIT_200 50
|
||||
#define SIP_UA_TIMER_WAIT_INV_RSP 3300
|
||||
#define SIP_UA_TIMER_WAIT_INV_200_RSP 5000
|
||||
#define SIP_UA_TIMER_WAIT_NON_INV_RSP 1000
|
||||
#define SIP_UA_TIMER_WAIT_ACK 1000
|
||||
#define SIP_UA_TIMER_T1 300//3200
|
||||
#define SIP_UA_TIMER_TIME_OUT 18000
|
||||
|
||||
#define SIP_UA_TIMER_T2 5
|
||||
#define SIP_UA_TIMER_T3 20
|
||||
|
||||
#define SIP_UA_FSM_TIMER 3300//SIP_UA_TIMER_T1;
|
||||
|
||||
#define SIP_UA_MAX_TAG_LEN 64//128
|
||||
#define SIP_UA_MAX_BRANCH_LEN 64
|
||||
|
||||
#endif
|
||||
|
||||
28
plat/sip/src/include/sip_ua_def.h
Normal file
28
plat/sip/src/include/sip_ua_def.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef _SIP_UA_DEF_H
|
||||
#define _SIP_UA_DEF_H
|
||||
|
||||
#include "sip_ua_pub.h"
|
||||
#include "sip.h"
|
||||
#include "sip_ua_struct.h"
|
||||
#include "sip_ua_const.h"
|
||||
#include "sip_ua_dialog.h"
|
||||
|
||||
char sipUaHostName[50];
|
||||
char sipUaDottedHostIp[20];
|
||||
DWORD sipUaHostIp;
|
||||
|
||||
int sipUaSipIndex;
|
||||
SIP_USER sipUaSipUser;
|
||||
|
||||
SIP_UA_SAPS sipUaSaps[SIP_UA_MAX_NUM_OF_SAP];
|
||||
|
||||
SIP_DIALOG sipUaDialog[SIP_UA_MAX_NUM_OF_DIALOG];
|
||||
|
||||
SIP_UA_PORT sipUaPort[SIP_UA_MAX_NUM_OF_PORT];
|
||||
|
||||
SIP_API_STRUCT sipUaRecvMsg;
|
||||
|
||||
WORD sipUaPortSelect;
|
||||
WORD sipUaDialogSelect;
|
||||
|
||||
#endif
|
||||
72
plat/sip/src/include/sip_ua_dialog.h
Normal file
72
plat/sip/src/include/sip_ua_dialog.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef _SIP_UA_DIALOG_H
|
||||
#define _SIP_UA_DIALOG_H
|
||||
|
||||
#include "sip_ua_pub.h"
|
||||
#include "sip.h"
|
||||
#include "sip_ua_const.h"
|
||||
|
||||
#define SIP_CALLEE 1
|
||||
#define SIP_CALLER 2
|
||||
|
||||
#define SIP_UA_DIALOG_IDLE 0
|
||||
#define SIP_UA_DIALOG_EARLY 1
|
||||
#define SIP_UA_DIALOG_WAIT_ACK_FOR_200 2
|
||||
#define SIP_UA_DIALOG_CONFIRMED 3
|
||||
#define SIP_UA_DIALOG_DESTROY 4
|
||||
|
||||
#define SIP_UA_DIALOG_REMOTE_TARGET_FLAG 0x0001
|
||||
#define SIP_UA_DIALOG_RECORD_ROUTE_SEND_FLAG 0x0002
|
||||
|
||||
typedef struct _SIP_UA_URI
|
||||
{
|
||||
BYTE uriType;
|
||||
char userName[SIP_MAX_USER_NAME_LEN];
|
||||
char password[SIP_MAX_PASSWORD_LEN];
|
||||
|
||||
char domain[SIP_MAX_DOMAIN_NAME_LEN];
|
||||
|
||||
}SIP_UA_URI;
|
||||
|
||||
typedef struct _SIP_DIALOG
|
||||
{
|
||||
BYTE flag;
|
||||
BYTE cgId;//BYTE userIndex;
|
||||
WORD usrPort;
|
||||
BYTE type;
|
||||
BYTE state;
|
||||
|
||||
union
|
||||
{
|
||||
WORD rvInvUaPort;
|
||||
WORD sdInvUaPort;
|
||||
}invUaPort;
|
||||
|
||||
WORD sipUaPort;
|
||||
|
||||
WORD uaPort;//only used to store the ua port of sending invite rsp
|
||||
WORD uaAckPort;//only used to store the ua port of sending ACK for invite 200
|
||||
DWORD invCSeq;
|
||||
DWORD remoteInvCseq;
|
||||
|
||||
char invBranch[SIP_UA_MAX_BRANCH_LEN];
|
||||
|
||||
WORD paramFlag;
|
||||
SIP_HDR_CALL_ID callId;
|
||||
char localTag[SIP_UA_MAX_TAG_LEN];
|
||||
char remoteTag[SIP_UA_MAX_TAG_LEN];
|
||||
SIP_HDR_CSEQ localCseq;
|
||||
SIP_HDR_CSEQ remoteCseq;
|
||||
SIP_UA_URI localURI;
|
||||
SIP_UA_URI remoteURI;
|
||||
SIP_UA_URI remoteTarget;
|
||||
SIP_HDR_RECORD_ROUTES routeSets;
|
||||
int secure;
|
||||
}SIP_DIALOG;
|
||||
|
||||
int sip_ua_update_dialog_with_req(WORD dialogId, SIP_API_STRUCT *sipApiMsg);
|
||||
|
||||
int sip_ua_init_dialog_as_client_with_inv(BYTE cgId, WORD usrPort, SIP_MSG *sipMsg);//BYTE sapIndex
|
||||
int sip_ua_init_dialog_as_server_with_inv(BYTE cgId, WORD hdlPort, WORD usrPort, SIP_MSG *sipMsg);//BYTE cgId
|
||||
|
||||
int sip_ua_free_dialog(DWORD usrPort, WORD dialogId);
|
||||
#endif
|
||||
29
plat/sip/src/include/sip_ua_ext.h
Normal file
29
plat/sip/src/include/sip_ua_ext.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _SIP_UA_EXT_H
|
||||
#define _SIP_UA_EXT_H
|
||||
|
||||
#include "sip_ua_pub.h"
|
||||
#include "sip.h"
|
||||
#include "sip_ua_struct.h"
|
||||
#include "sip_ua_const.h"
|
||||
#include "sip_ua_dialog.h"
|
||||
|
||||
extern char sipUaHostName[50];
|
||||
extern char sipUaDottedHostIp[20];
|
||||
extern DWORD sipUaHostIp;
|
||||
|
||||
extern int sipUaSipIndex;
|
||||
extern SIP_USER sipUaSipUser;
|
||||
|
||||
extern SIP_UA_SAPS sipUaSaps[SIP_UA_MAX_NUM_OF_SAP];
|
||||
|
||||
extern SIP_DIALOG sipUaDialog[SIP_UA_MAX_NUM_OF_DIALOG];
|
||||
|
||||
extern SIP_UA_PORT sipUaPort[SIP_UA_MAX_NUM_OF_PORT];
|
||||
|
||||
extern SIP_API_STRUCT sipUaRecvMsg;
|
||||
|
||||
extern WORD sipUaPortSelect;
|
||||
extern WORD sipUaDialogSelect;
|
||||
|
||||
#endif
|
||||
|
||||
31
plat/sip/src/include/sip_ua_msg.h
Normal file
31
plat/sip/src/include/sip_ua_msg.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _SIP_UA_MSG_H
|
||||
#define _SIP_UA_MSG_H
|
||||
|
||||
#include "sip_ua_pub.h"
|
||||
|
||||
#define sip_ua_send_update(cgId, dialogId, usrPort, method, sdMsg) sip_ua_send_non_inv(cgId, dialogId, usrPort, method, sdMsg)
|
||||
#define sip_ua_send_cancel(cgId, dialogId, usrPort, method, sdMsg) sip_ua_send_non_inv(cgId, dialogId, usrPort, method, sdMsg)
|
||||
#define sip_ua_send_bye(cgId, dialogId, usrPort, method, sdMsg) sip_ua_send_non_inv(cgId, dialogId, usrPort, method, sdMsg)
|
||||
#define sip_ua_send_200_ack(cgId, dialogId, usrPort, method, sdMsg) sip_ua_send_non_inv(cgId, dialogId, usrPort, method, sdMsg)
|
||||
#define sip_ua_send_info(cgId, dialogId, usrPort, method, sdMsg) sip_ua_send_non_inv(cgId, dialogId, usrPort, method, sdMsg)
|
||||
#define sip_ua_send_bye_inv_rsp(cgId, dialogId, usrPort, sdMsg) sip_ua_send_cancel_inv_rsp(cgId, dialogId, usrPort, sdMsg)
|
||||
|
||||
int sip_ua_send_invite(BYTE cgId,WORD dialogId, WORD usrPort, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_re_invite(BYTE cgId, WORD dialogId, WORD usrPort, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_non_inv(BYTE cgId,WORD dialogId, WORD usrPort, BYTE method, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_cancel(BYTE cgId,WORD dialogId, WORD usrPort, BYTE method, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_bye(BYTE sapIncgIddex,WORD dialogId, WORD usrPort, BYTE method, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_200_ack(BYTE cgId,WORD dialogId, WORD usrPort, BYTE method, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_info(BYTE cgId,WORD dialogId, WORD usrPort, BYTE method, SIP_API_STRUCT *sdMsg);
|
||||
|
||||
int sip_ua_send_options(BYTE cgId,WORD dialogId, WORD usrPort, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_refer(BYTE cgId,WORD dialogId, WORD usrPort, SIP_API_STRUCT *sdMsg);
|
||||
|
||||
int sip_ua_set_inv_temp_rsp(WORD uaPort,SIP_API_STRUCT *sdMsg);
|
||||
|
||||
int sip_ua_send_inv_rsp(BYTE cgId,WORD dialogId, WORD usrPort, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_cancel_inv_rsp(BYTE cgId,WORD dialogId, WORD usrPort, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_re_inv_rsp(BYTE cgId,WORD dialogId, WORD usrPort, SIP_API_STRUCT *sdMsg);
|
||||
int sip_ua_send_non_inv_rsp(BYTE cgId, WORD dialogId, WORD usrPort, BYTE method, SIP_API_STRUCT *sdMsg);
|
||||
|
||||
#endif
|
||||
56
plat/sip/src/include/sip_ua_pub.h
Normal file
56
plat/sip/src/include/sip_ua_pub.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef _SIP_UA_PUB__H
|
||||
#define _SIP_UA_PUB__H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#include <netdb.h>
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
// by simon at 23/9/22
|
||||
//#include <stropts.h>
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
#include <termio.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/io.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/msg.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#ifndef _T_BYTE
|
||||
#define _T_BYTE
|
||||
typedef unsigned char BYTE;
|
||||
#endif
|
||||
|
||||
#ifndef _T_WORD
|
||||
#define _T_WORD
|
||||
typedef unsigned short WORD;
|
||||
#endif
|
||||
|
||||
#ifndef _T_DWORD
|
||||
#define _T_DWORD
|
||||
typedef unsigned int DWORD;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
47
plat/sip/src/include/sip_ua_struct.h
Normal file
47
plat/sip/src/include/sip_ua_struct.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef _SIP_UA_STRUCT_H
|
||||
#define _SIP_UA_STRUCT_H
|
||||
|
||||
#include "sip_ua_pub.h"
|
||||
#include "sip_ua.h"
|
||||
#include "sip.h"
|
||||
|
||||
typedef struct _SIP_UA_CALL_STRUCT
|
||||
{
|
||||
SIP_HDR_CALL_ID callId;
|
||||
char fromTag[128];
|
||||
}SIP_UA_CALL_STRUCT;
|
||||
|
||||
typedef struct _SIP_UA_PORT
|
||||
{
|
||||
BYTE flag;
|
||||
BYTE cgId;//BYTE sapIndex;
|
||||
WORD dialogId;
|
||||
WORD usrPort;
|
||||
WORD llPort;
|
||||
|
||||
SIP_UA_CALL_STRUCT callStruct;
|
||||
|
||||
BYTE sipuafState;
|
||||
DWORD sipuafTimer;
|
||||
|
||||
BYTE mainState;
|
||||
BYTE state;
|
||||
WORD rcvCmd;
|
||||
WORD sdCmd;
|
||||
|
||||
DWORD timer;
|
||||
DWORD timer2;
|
||||
DWORD waitAckTimer;
|
||||
BYTE retrans200Times;
|
||||
|
||||
SIP_API_STRUCT sdSipMsg;
|
||||
}SIP_UA_PORT;
|
||||
|
||||
typedef struct _SIP_UA_SAPS
|
||||
{
|
||||
BYTE flag;
|
||||
SIP_UA_SAP sipUaSap;
|
||||
}SIP_UA_SAPS;
|
||||
|
||||
#endif
|
||||
|
||||
280
plat/sip/src/sip.c
Normal file
280
plat/sip/src/sip.c
Normal file
@@ -0,0 +1,280 @@
|
||||
/****************************************************************/
|
||||
/* SIP Implementation Program */
|
||||
/* Version 10.0.1 */
|
||||
/* Designed By Ying Min */
|
||||
/* Last Update: 2006-10-19 */
|
||||
/****************************************************************/
|
||||
|
||||
#include "./include/sip_pub.h"
|
||||
#include "./include/sip.h"
|
||||
#include "./include/sip_const.h"
|
||||
#include "./include/sip_struct.h"
|
||||
#include "./include/sip_def.h"
|
||||
#include "./include/sip_transaction.h"
|
||||
#include "./include/sip_transport.h"
|
||||
#include "./include/sip_msg_parse.h"
|
||||
#include "./include/sip_debug.h"
|
||||
|
||||
int sip_get_local_ip(void)
|
||||
{
|
||||
struct hostent *host;
|
||||
|
||||
if (gethostname(sipHostName, 50) == -1)
|
||||
{
|
||||
printf("SIP gethostname fail!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((host = gethostbyname(sipHostName)) == NULL)
|
||||
{
|
||||
printf("SIP gethostbyname fail!\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(sipDottedHostIp, "%d.%d.%d.%d",
|
||||
(BYTE)host->h_addr_list[0][0],
|
||||
(BYTE)host->h_addr_list[0][1],
|
||||
(BYTE)host->h_addr_list[0][2],
|
||||
(BYTE)host->h_addr_list[0][3]);
|
||||
sipHostIp = inet_addr(sipDottedHostIp); // Network byte order sipHostIp, like 0xE60012AC
|
||||
printf("sipHostName: %s, sipHostIp: %s (0x%lX)\n", sipHostName, sipDottedHostIp, sipHostIp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_init_udp_socket(struct sockaddr_in saddr, int multicast)
|
||||
{
|
||||
int sock;
|
||||
long sockBuf = 40*1024;
|
||||
int on = 1, timeout = 20;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if (sock < 0)
|
||||
{
|
||||
fprintf(stderr, "Socket() failed\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
|
||||
&sockBuf, sizeof(sockBuf)) != 0)
|
||||
{
|
||||
fprintf(stderr, "SIP set socket buffer failed\n");
|
||||
close(sock);
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||
&on,sizeof(on)) != 0)
|
||||
{
|
||||
fprintf(stderr, "SIP set addr reusable failed\n");
|
||||
close(sock);
|
||||
return -5;
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&timeout, sizeof(timeout)) != 0)
|
||||
{
|
||||
fprintf(stderr, "SIP set keepalive failed\n");
|
||||
close(sock);
|
||||
return -6;
|
||||
}
|
||||
|
||||
if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0)
|
||||
{
|
||||
fprintf(stderr, "SIP set nonblock failed\n");
|
||||
close(sock);
|
||||
return -7;
|
||||
}
|
||||
|
||||
if (bind(sock, (struct sockaddr *) &saddr, sizeof(struct sockaddr)) < 0)
|
||||
{
|
||||
fprintf(stderr, "SIP binding failed, port: %d\n", htons(saddr.sin_port));
|
||||
close(sock);
|
||||
return -2;
|
||||
}
|
||||
|
||||
sip_debug_set();
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
int sip_init_tcp_server_socket(struct sockaddr_in saddr, int multicast)
|
||||
{
|
||||
int sock;
|
||||
int on = 1, timeout = 20;
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (sock < 0)
|
||||
{
|
||||
fprintf(stderr, "TCP Socket() failed\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||
&on,sizeof(on)) != 0)
|
||||
{
|
||||
fprintf(stderr, "SIP set tcp addr reusable failed\n");
|
||||
close(sock);
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
&timeout, sizeof(timeout)) != 0)
|
||||
{
|
||||
fprintf(stderr, "SIP set tcp keepalive failed\n");
|
||||
close(sock);
|
||||
return -5;
|
||||
}
|
||||
|
||||
if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0)
|
||||
{
|
||||
fprintf(stderr, "SIP set tcp nonblock failed\n");
|
||||
close(sock);
|
||||
return -6;
|
||||
}
|
||||
|
||||
if (bind(sock, (struct sockaddr *) &saddr, sizeof(struct sockaddr)) < 0)
|
||||
{
|
||||
fprintf(stderr, "SIP tcp binding failed, port: %d\n", htons(saddr.sin_port));
|
||||
close(sock);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (listen(sock, SIP_TCP_BACKLOG) < 0)
|
||||
{
|
||||
fprintf(stderr, "listen error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
int sip_init_socket()
|
||||
{
|
||||
struct sockaddr_in sinAddr;
|
||||
WORD port = 5060;
|
||||
|
||||
memset(&sinAddr, 0, sizeof(struct sockaddr));
|
||||
sinAddr.sin_family = AF_INET;
|
||||
sinAddr.sin_port = htons(port);
|
||||
sinAddr.sin_addr.s_addr = INADDR_ANY;
|
||||
memset(&(sinAddr.sin_zero), 0, 8);
|
||||
|
||||
sipUdpSocketFd = sip_init_udp_socket(sinAddr, 0);
|
||||
if (sipUdpSocketFd < 0)
|
||||
{
|
||||
printf("SIP UDP Socket(%d) failed\n", port);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipTcpServerSocketFd = sip_init_tcp_server_socket(sinAddr, 0);
|
||||
if (sipTcpServerSocketFd < 0)
|
||||
{
|
||||
printf("SIP TCP Socket(%d) failed\n", port);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_init()
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("SIP Module Init Start!\n");
|
||||
|
||||
if (sip_get_local_ip() < 0)
|
||||
exit(1);
|
||||
|
||||
if (sip_init_socket() < 0)
|
||||
exit(2);
|
||||
|
||||
// memset((BYTE *)sipSipUaUser, 0, sizeof(SIP_SIP_UA_USER));
|
||||
memset((BYTE *)&sipRecvMsg, 0, sizeof(SIP_API_STRUCT));
|
||||
memset((BYTE *)&sipUsers, 0, sizeof(SIP_USERS_STRUCT));
|
||||
sipUsers.proxyIndex = SIP_MAX_NUM_OF_USERS;
|
||||
|
||||
sipTransHead = 0;
|
||||
for (i = 0; i < SIP_MAX_NUM_OF_TRANS; i++)
|
||||
sip_trans_init(i);
|
||||
|
||||
sip_parser_init();
|
||||
|
||||
printf("SIP Module Init Complete!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sip_t10ms()
|
||||
{
|
||||
static DWORD cnt_10ms = 0;
|
||||
|
||||
if (!(++cnt_10ms % 10))
|
||||
{ // 100 ms
|
||||
sip_mon();
|
||||
}
|
||||
}
|
||||
|
||||
void sip_timer()
|
||||
{
|
||||
WORD transId;
|
||||
|
||||
sip_transport_proc();
|
||||
|
||||
for (transId = 0; transId < SIP_MAX_NUM_OF_TRANS; transId++)
|
||||
{
|
||||
if (sipTrans[transId].flag == 0)
|
||||
continue;
|
||||
sip_transaction_proc(transId);
|
||||
}
|
||||
|
||||
sip_t10ms();
|
||||
}
|
||||
|
||||
int sip_register_user(SIP_USER *sipUser)
|
||||
{
|
||||
BYTE i;
|
||||
|
||||
for (i = 0; i < SIP_MAX_NUM_OF_USERS; i++)
|
||||
{ // Search for already registered user
|
||||
if ((sipUsers.sipUsers[i].flag == 1) &&
|
||||
(strcmp(sipUsers.sipUsers[i].sipUser.userName, sipUser->userName) == 0))
|
||||
{
|
||||
memcpy(&sipUsers.sipUsers[i].sipUser, sipUser, sizeof(SIP_USER));
|
||||
if (sipUser->proxyType != SIP_PROXY_TYPE_NONE)
|
||||
sipUsers.proxyIndex = i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < SIP_MAX_NUM_OF_USERS; i++)
|
||||
{
|
||||
if (sipUsers.sipUsers[i].flag == 0)
|
||||
{
|
||||
memcpy(&sipUsers.sipUsers[i].sipUser, sipUser, sizeof(SIP_USER));
|
||||
sipUsers.sipUsers[i].flag = 1;
|
||||
if (sipUser->proxyType != SIP_PROXY_TYPE_NONE)
|
||||
sipUsers.proxyIndex = i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(sipAsciTempBuf, "SIP register user fail\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*int sip_store_sip_ua_user(BYTE index, char *domain)
|
||||
{
|
||||
if ((domain == NULL) || (index >= SIP_MAX_NUM_OF_SIP_UA_USER))
|
||||
return -1;
|
||||
|
||||
strcpy(sipSipUaUser[index].domain, domain);
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
272
plat/sip/src/sip_debug.c
Normal file
272
plat/sip/src/sip_debug.c
Normal file
@@ -0,0 +1,272 @@
|
||||
#include "./include/sip_pub.h"
|
||||
#include "./include/sip.h"
|
||||
#include "./include/sip_const.h"
|
||||
#include "./include/sip_struct.h"
|
||||
#include "./include/sip_ext.h"
|
||||
#include "../../debug/src/include/debug.h"
|
||||
|
||||
#define SIP_DEBUG_ID 29
|
||||
#define SIP_VER_DEBUG "R9V2_01"
|
||||
|
||||
static char ascii[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
|
||||
|
||||
static BYTE log_help[] = {
|
||||
"SIP Debug Monitor Help:\n\r\
|
||||
\n\r\
|
||||
1.[help] display help menu\n\r\
|
||||
2.[log all/none] display all/none logs\n\r\
|
||||
3.[log error on/off] display error logs\n\r\
|
||||
4.[log sip on/off] display sip msg logs\n\r\n\r"
|
||||
};
|
||||
|
||||
static WORD disp_page[10];
|
||||
static BYTE *disp_ptr = (BYTE *) disp_page;
|
||||
|
||||
static DWORD debug_status_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,SIP_DEBUG_ID + 2,1
|
||||
};
|
||||
|
||||
static BYTE debug_status = 1;
|
||||
|
||||
static DWORD debug_name_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,SIP_DEBUG_ID + 2,2
|
||||
};
|
||||
|
||||
static DWORD debug_ascin_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,SIP_DEBUG_ID + 2,3
|
||||
};
|
||||
|
||||
static DWORD debug_ascout_id[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,SIP_DEBUG_ID + 2,4
|
||||
};
|
||||
|
||||
static DWORD debug_page_title[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,SIP_DEBUG_ID + 2,1,1
|
||||
};
|
||||
|
||||
static DWORD debug_page_line[20] =
|
||||
{
|
||||
1,3,6,1,4,1,1373,1,1,2,3,1,2,SIP_DEBUG_ID + 2,1,2,1
|
||||
};
|
||||
|
||||
const static BYTE PAGE_POINT = 14;
|
||||
const static BYTE LINE_POINT = 15;
|
||||
const static BYTE BASE_ID_LEN = 15;
|
||||
|
||||
static BYTE title1_p[] =
|
||||
{
|
||||
" SIP Page 01 Transaction Status\n\r\
|
||||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
|
||||
Subpage\n\r\
|
||||
Trans_Status\n\r"
|
||||
};
|
||||
|
||||
BYTE sip_disp_line(BYTE page, BYTE line)
|
||||
{
|
||||
BYTE disp_length;
|
||||
|
||||
disp_length = 16;
|
||||
disp_ptr = (BYTE *) disp_page;
|
||||
|
||||
switch (page)
|
||||
{
|
||||
case 1: // Page 1: SG Para
|
||||
if (line == 0)
|
||||
{
|
||||
disp_ptr = (BYTE *) &disp_page[page];
|
||||
disp_length = 2;
|
||||
}
|
||||
else
|
||||
disp_ptr = (BYTE *) &sipTrans[disp_page[page]];
|
||||
break;
|
||||
default:
|
||||
disp_length = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return disp_length;
|
||||
}
|
||||
|
||||
void sip_disp_page(BYTE page)
|
||||
{
|
||||
BYTE disp_line;
|
||||
BYTE disp_length;
|
||||
|
||||
debug_page_line[PAGE_POINT] = page + 5;
|
||||
|
||||
for (disp_line = 0; disp_line < 22; disp_line++)
|
||||
{
|
||||
disp_length = sip_disp_line(page, disp_line);
|
||||
debug_page_line[LINE_POINT] = disp_line + 2;
|
||||
debug_page_line[LINE_POINT + 1] = 2; // Data Pointer
|
||||
debug_set_response(BASE_ID_LEN + 2, debug_page_line, disp_ptr, disp_length);
|
||||
}
|
||||
}
|
||||
|
||||
int sip_debug_set(void)
|
||||
{
|
||||
BYTE page;
|
||||
BYTE data[10];
|
||||
BYTE *ptr;
|
||||
|
||||
bzero(disp_page, 20);
|
||||
|
||||
ptr = data;
|
||||
|
||||
debug_set_response(BASE_ID_LEN, debug_status_id, &debug_status, 1);
|
||||
debug_set_response(BASE_ID_LEN, debug_name_id, SIP_VER_DEBUG, 10);
|
||||
debug_set_response(BASE_ID_LEN, debug_ascin_id, sipAsciInBuf, 4096);
|
||||
debug_set_response(BASE_ID_LEN, debug_ascout_id, sipAsciOutBuf, 4096);
|
||||
|
||||
for (page = 1; page < 2; page++)
|
||||
{
|
||||
switch (page)
|
||||
{
|
||||
case 1: //page 1
|
||||
ptr = title1_p;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
debug_page_title[PAGE_POINT] = 5 + page;
|
||||
debug_set_response(BASE_ID_LEN + 1, debug_page_title, ptr, strlen(ptr));
|
||||
sip_disp_page(page);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sip_asciout_proc(BYTE *outStr)
|
||||
{
|
||||
int outLen;
|
||||
|
||||
outLen = strlen(outStr);
|
||||
|
||||
if (outLen + strlen(sipAsciOutBuf) > SIP_MAX_ASCIIOUT_LEN - 2)
|
||||
{
|
||||
strcpy(sipAsciOutBuf, outStr);
|
||||
}
|
||||
else
|
||||
strcat(sipAsciOutBuf, outStr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sip_mon(void)
|
||||
{
|
||||
BYTE inPage, errFg = 0;
|
||||
BYTE *asciiInPtr = NULL;
|
||||
BYTE *strStart = NULL;
|
||||
WORD strLen, num;
|
||||
|
||||
if ((strLen = strlen(sipAsciInBuf)) > 0)
|
||||
{
|
||||
inPage = sipAsciInBuf[0] - 1;
|
||||
asciiInPtr = sipAsciInBuf + 1;
|
||||
|
||||
if (inPage > 7)
|
||||
errFg = 1;
|
||||
else if (strcmp(asciiInPtr,"c") == 0)
|
||||
{
|
||||
}
|
||||
else if (strcmp(asciiInPtr,"log error on") == 0)
|
||||
{
|
||||
sipMonitorFg = sipMonitorFg | SIP_MONITOR_ERROR;
|
||||
}
|
||||
else if (strcmp(asciiInPtr,"log error off") == 0)
|
||||
{
|
||||
sipMonitorFg = sipMonitorFg & (~SIP_MONITOR_ERROR);
|
||||
}
|
||||
else if (strcmp(asciiInPtr,"log sip on") == 0)
|
||||
{
|
||||
sipMonitorFg = sipMonitorFg | MONITOR_SIP_MSG;
|
||||
}
|
||||
else if (strcmp(asciiInPtr,"log sip off") == 0)
|
||||
{
|
||||
sipMonitorFg = sipMonitorFg & (~MONITOR_SIP_MSG);
|
||||
}
|
||||
else if (strcmp(asciiInPtr,"log all") == 0)
|
||||
{
|
||||
sipMonitorFg = SIP_MONITOR_ALL;
|
||||
}
|
||||
else if (strcmp(asciiInPtr,"log none") == 0)
|
||||
{
|
||||
sipMonitorFg = SIP_MONITOR_NONE;
|
||||
}
|
||||
else if (strcmp(asciiInPtr,"help") == 0)
|
||||
{
|
||||
sip_asciout_proc(log_help);
|
||||
}
|
||||
else if (isdigit(asciiInPtr[0]))
|
||||
{
|
||||
num = strtoul(asciiInPtr, NULL, 10);
|
||||
disp_page[inPage] = num;
|
||||
sip_disp_page(inPage);
|
||||
}
|
||||
else if ((strStart = strstr(asciiInPtr, ">")) != NULL)
|
||||
{
|
||||
num = strtoul(strStart + 1, NULL, 10);
|
||||
disp_page[inPage] += num;
|
||||
sip_disp_page(inPage);
|
||||
}
|
||||
else if ((strStart = strstr(asciiInPtr, "<"))!= NULL)
|
||||
{
|
||||
num = strtoul(strStart + 1, NULL, 10);
|
||||
disp_page[inPage] -= num;
|
||||
sip_disp_page(inPage);
|
||||
}
|
||||
else
|
||||
errFg = 1;
|
||||
|
||||
if (errFg == 0)
|
||||
sip_asciout_proc("Command OK!\n\r");
|
||||
else
|
||||
sip_asciout_proc("Command Error!\n\r");
|
||||
|
||||
strcpy(sipAsciInBuf, "\0");
|
||||
}
|
||||
}
|
||||
|
||||
int sip_hex_to_ascii(BYTE *fromHex, BYTE fromLen, BYTE *toAsc)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
j = 0;
|
||||
|
||||
for (i = 0; i< fromLen; i++)
|
||||
{
|
||||
toAsc[j] = ascii[fromHex[i] >> 4];
|
||||
j++;
|
||||
toAsc[j] = ascii[fromHex[i] & 0x0F];
|
||||
j++;
|
||||
toAsc[j] = ' ';
|
||||
j++;
|
||||
}
|
||||
|
||||
toAsc[j] = '\0';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sip_log_err(BYTE *errMsg)
|
||||
{
|
||||
if ((sipMonitorFg & SIP_MONITOR_ERROR) == SIP_MONITOR_ERROR)
|
||||
{
|
||||
sip_asciout_proc("\33[31m");
|
||||
if (strlen(errMsg) >= SIP_MAX_ASCITMP_LEN)
|
||||
sprintf(sipAsciTempBuf, "log msg is too long: %d\n\r", strlen(errMsg));
|
||||
else
|
||||
sprintf(sipAsciTempBuf, "%s\n\r", errMsg);
|
||||
strcat(sipAsciTempBuf, "\33[37m");
|
||||
sip_asciout_proc(sipAsciTempBuf);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
1508
plat/sip/src/sip_msg.c
Normal file
1508
plat/sip/src/sip_msg.c
Normal file
File diff suppressed because it is too large
Load Diff
1676
plat/sip/src/sip_msg_encode.c
Normal file
1676
plat/sip/src/sip_msg_encode.c
Normal file
File diff suppressed because it is too large
Load Diff
4027
plat/sip/src/sip_msg_parse.c
Normal file
4027
plat/sip/src/sip_msg_parse.c
Normal file
File diff suppressed because it is too large
Load Diff
1002
plat/sip/src/sip_transaction.c
Normal file
1002
plat/sip/src/sip_transaction.c
Normal file
File diff suppressed because it is too large
Load Diff
192
plat/sip/src/sip_transport.c
Normal file
192
plat/sip/src/sip_transport.c
Normal file
@@ -0,0 +1,192 @@
|
||||
#include "./include/sip_pub.h"
|
||||
#include "./include/sip.h"
|
||||
#include "./include/sip_const.h"
|
||||
#include "./include/sip_struct.h"
|
||||
#include "./include/sip_ext.h"
|
||||
#include "./include/sip_msg.h"
|
||||
#include "./include/sip_msg_encode.h"
|
||||
#include "./include/sip_debug.h"
|
||||
|
||||
int sip_transport_send_udp_msg()
|
||||
{
|
||||
int ret, len;
|
||||
|
||||
sipUdpMsgSdBuf[SIP_MAX_UDP_MSG_LEN - 1] = '\0';
|
||||
len = strlen(sipUdpMsgSdBuf);
|
||||
if (len >= SIP_MAX_UDP_MSG_LEN)
|
||||
return -1;
|
||||
|
||||
ret = sendto(sipUdpSocketFd, sipUdpMsgSdBuf, len, 0, (struct sockaddr *) &sipDstInAddr, sizeof(sipDstInAddr));
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
sipUdpMsgSdBuf[len] = '\0';
|
||||
if ((sipMonitorFg & MONITOR_SIP_MSG) == MONITOR_SIP_MSG)
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "Send SIP Msg (UDP) ===> dest port: %d, dest ipV4: %s\r\n", ntohs(sipDstInAddr.sin_port), inet_ntoa(sipDstInAddr.sin_addr));
|
||||
sip_asciout_proc(sipAsciTempBuf);
|
||||
sip_asciout_proc(sipUdpMsgSdBuf);
|
||||
sip_asciout_proc("\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "Send SIP Msg (UDP) Failed ===> dest port: %d, dest ipV4: %s\r\n", ntohs(sipDstInAddr.sin_port), inet_ntoa(sipDstInAddr.sin_addr));
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sip_transport_recv_udp_msg()
|
||||
{
|
||||
int i, len, addrLen = sizeof(struct sockaddr);
|
||||
|
||||
for (i = 0; i < SIP_MAX_UDP_MSG_GET_TIMES; i++)
|
||||
{
|
||||
len = recvfrom(sipUdpSocketFd, sipUdpMsgRvBuf, SIP_MAX_UDP_MSG_LEN,
|
||||
0, (struct sockaddr *)&sipSrcInAddr, &addrLen);
|
||||
if (len < 0)
|
||||
break;
|
||||
|
||||
if (len >= SIP_MAX_UDP_MSG_LEN)
|
||||
continue;
|
||||
|
||||
sipUdpMsgRvBuf[len] = '\0';
|
||||
|
||||
memset((BYTE *)&sipRecvMsg, 0, sizeof(SIP_API_STRUCT));
|
||||
|
||||
sipRecvMsg.sipTransAddr.type = 0; // ipv4 & udp
|
||||
sipRecvMsg.sipTransAddr.port = ntohs(sipSrcInAddr.sin_port);
|
||||
sipRecvMsg.sipTransAddr.addr.ipV4 = sipSrcInAddr.sin_addr.s_addr;
|
||||
|
||||
if ((sipMonitorFg & MONITOR_SIP_MSG) == MONITOR_SIP_MSG)
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "Receive SIP Msg (UDP) <=== src port: %d, src ipV4: %s\r\n", sipRecvMsg.sipTransAddr.port, inet_ntoa(sipSrcInAddr.sin_addr));
|
||||
sip_asciout_proc(sipAsciTempBuf);
|
||||
sip_asciout_proc(sipUdpMsgRvBuf);
|
||||
sip_asciout_proc("\r\n");
|
||||
}
|
||||
|
||||
sip_recv_msg_handling(sipUdpMsgRvBuf, len, -1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*int sip_transport_recv_tcp_msg()
|
||||
{
|
||||
int i, newSock, len;
|
||||
struct sockaddr_in remote_addr;
|
||||
|
||||
for (i = 0; i < SIP_MAX_NUM_OF_TCP_SOCK; i++)
|
||||
{
|
||||
if (sipTcpSock[i].flag != 1)
|
||||
continue;
|
||||
|
||||
len = recv(sipTcpSock[i].sendRecvSock, sipTcpMsgRvBuf, SIP_MAX_TCP_MSG_LEN, 0);
|
||||
|
||||
if (len < 0)
|
||||
break;
|
||||
|
||||
sip_recv_msg_handling(sipTcpMsgRvBuf, len, i);
|
||||
}
|
||||
|
||||
len = sizeof(remote_addr);
|
||||
bzero((char *)&remote_addr, len);
|
||||
|
||||
if ((newSock = accept(sipTcpServerSocketFd, (struct sockaddr *)&remote_addr, (int *)&len)) < 0)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < SIP_MAX_NUM_OF_TCP_SOCK; i++)
|
||||
{
|
||||
if (sipTcpSock[i].flag == 1)
|
||||
continue;
|
||||
|
||||
sipTcpSock[i].sendRecvSock = newSock;
|
||||
memcpy(&sipTcpSock[i].remoteAddr, &remote_addr, sizeof(struct sockaddr_in));
|
||||
|
||||
len = recv(sipTcpSock[i].sendRecvSock, sipTcpMsgRvBuf, SIP_MAX_TCP_MSG_LEN, 0);
|
||||
|
||||
if (len < 0)
|
||||
break;
|
||||
|
||||
sip_recv_msg_handling(sipTcpMsgRvBuf, len, i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
int sip_transport_encode_trans_msg(SIP_TRANSACTION *trans, SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
char dest[SIP_MAX_UDP_MSG_LEN] = "";
|
||||
|
||||
if (sip_transport_encode_start_line(dest, sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
if (sip_transport_encode_headers(dest, sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
if (sip_transport_encode_body(dest, sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
memcpy(&trans->transSdMsg.sipSdAddr, &sipApiMsg->sipTransAddr, sizeof(SIP_TRANSPORT_ADDR));
|
||||
|
||||
strcpy(trans->transSdMsg.sdMsg, dest);
|
||||
trans->transSdMsg.sdMsg[SIP_MAX_UDP_MSG_LEN - 1] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_transport_encode_msg(SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
char *dest = sipUdpMsgSdBuf;
|
||||
|
||||
strcpy(dest, "");
|
||||
|
||||
if (sip_transport_encode_start_line(dest, sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
if (sip_transport_encode_headers(dest, sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
if (sip_transport_encode_body(dest, sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
if (sip_transport_set_addr(&sipDstInAddr, sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_transport_send_trans_msg(SIP_TRANS_SD_MSG *transSdMsg)
|
||||
{
|
||||
strcpy(sipUdpMsgSdBuf, transSdMsg->sdMsg);
|
||||
|
||||
if (sip_transport_set_sd_addr(&sipDstInAddr, &transSdMsg->sipSdAddr) < 0)
|
||||
return -1;
|
||||
|
||||
sip_transport_send_udp_msg();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_transport_send_msg(SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
if ((sipApiMsg->sipApiType != SIP_API_REQ_MSG)
|
||||
&& (sipApiMsg->sipApiType != SIP_API_RES_MSG))
|
||||
return -1;
|
||||
|
||||
if (sip_transport_encode_msg(sipApiMsg) < 0)
|
||||
return -1;
|
||||
|
||||
sip_transport_send_udp_msg();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sip_transport_proc()
|
||||
{
|
||||
sip_transport_recv_udp_msg();
|
||||
// sip_transport_recv_tcp_msg();
|
||||
}
|
||||
678
plat/sip/src/sip_ua.c
Normal file
678
plat/sip/src/sip_ua.c
Normal file
@@ -0,0 +1,678 @@
|
||||
/****************************************************************/
|
||||
/* SIP UA Implementation Program */
|
||||
/* Version 9.0.1 */
|
||||
/* Designed By Francis */
|
||||
/* Last Update: 2008-5-21 */
|
||||
/****************************************************************/
|
||||
|
||||
#include "./include/sip_ua_pub.h"
|
||||
#include "./include/sip_ua_def.h"
|
||||
#include "./include/sip_ua_dialog.h"
|
||||
#include "./include/sip_ua_const.h"
|
||||
#include "./include/sip.h"
|
||||
#include "./include/sip_ext.h"
|
||||
#include "./include/sip_debug.h"
|
||||
#include "./include/sip_ua_msg.h"
|
||||
|
||||
extern void sip_ua_fsm(WORD port);
|
||||
|
||||
int sip_ua_get_local_ip(void)
|
||||
{
|
||||
struct hostent *host;
|
||||
|
||||
if (gethostname(sipUaHostName, 50) == -1)
|
||||
{
|
||||
printf("SIP gethostname fail!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((host = gethostbyname(sipUaHostName)) == NULL)
|
||||
{
|
||||
printf("SIP gethostbyname fail!\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(sipUaDottedHostIp, "%d.%d.%d.%d",
|
||||
(BYTE)host->h_addr_list[0][0],
|
||||
(BYTE)host->h_addr_list[0][1],
|
||||
(BYTE)host->h_addr_list[0][2],
|
||||
(BYTE)host->h_addr_list[0][3]);
|
||||
sipUaHostIp = inet_addr(sipUaDottedHostIp); // Network byte order sipHostIp, like 0xE60012AC
|
||||
printf("sipHostName: %s, sipHostIp: %s (0x%lX)\n", sipUaHostName, sipUaDottedHostIp, sipUaHostIp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_get_port()
|
||||
{
|
||||
int i;
|
||||
int port = sipUaPortSelect;
|
||||
|
||||
if (port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_get_port:port select have been changed\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
port = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_PORT; i++)
|
||||
{
|
||||
if (sipUaPort[port].flag == 1)
|
||||
{
|
||||
if (++port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
port = 0;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
sip_ua_init_port(port);
|
||||
|
||||
sipUaPort[port].flag = 1;
|
||||
|
||||
sipUaPortSelect = (port + 1)%SIP_UA_MAX_NUM_OF_PORT;
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
WORD sip_ua_match_dialog_with_req(SIP_API_STRUCT *request)
|
||||
{
|
||||
WORD i;
|
||||
BYTE method;
|
||||
SIP_HDR_CALL_ID *callId;
|
||||
char *toTag;
|
||||
char *fromTag;
|
||||
SIP_DIALOG *sipDlgPtr;
|
||||
char *branchRecv;
|
||||
|
||||
if (request == NULL)
|
||||
{
|
||||
return SIP_UA_MAX_NUM_OF_DIALOG;
|
||||
}
|
||||
|
||||
method = request->sipApiMsg.sipMsg.sipStartLine.sipMethod;
|
||||
branchRecv = request->sipApiMsg.sipMsg.sipHdrVias.vias[1].params.para[0].para.paraStr;
|
||||
callId = &request->sipApiMsg.sipMsg.sipHdrCallId;
|
||||
toTag = request->sipApiMsg.sipMsg.sipHdrTo.params.para[0].para.paraStr;
|
||||
fromTag = request->sipApiMsg.sipMsg.sipHdrFrom.params.para[0].para.paraStr;
|
||||
|
||||
/* if (method == SIP_METHOD_INVITE)
|
||||
return SIP_UA_MAX_NUM_OF_DIALOG;*/
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_DIALOG; i++)
|
||||
{
|
||||
sipDlgPtr = &sipUaDialog[i];
|
||||
|
||||
if ((sipDlgPtr->flag == 0) || (sipDlgPtr->state == SIP_UA_DIALOG_DESTROY) || (strcmp(sipDlgPtr->callId.value, callId->value) != 0)
|
||||
|| (strcmp(sipDlgPtr->remoteTag, fromTag) != 0))
|
||||
continue;
|
||||
|
||||
if (method == SIP_METHOD_INVITE)
|
||||
return i;
|
||||
|
||||
if (method == SIP_METHOD_CANCEL)
|
||||
{
|
||||
if ((sipDlgPtr->state < SIP_UA_DIALOG_WAIT_ACK_FOR_200) && (strcmp(sipDlgPtr->invBranch, branchRecv) == 0))
|
||||
return i;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(sipDlgPtr->localTag, toTag) != 0)
|
||||
continue;
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return SIP_UA_MAX_NUM_OF_DIALOG;
|
||||
}
|
||||
|
||||
WORD sip_ua_match_dialog_with_rsp(SIP_API_STRUCT *response)
|
||||
{
|
||||
WORD i;
|
||||
SIP_HDR_CALL_ID *callId;
|
||||
char *toTag;
|
||||
char *fromTag;
|
||||
|
||||
if (response == NULL)
|
||||
{
|
||||
return SIP_UA_MAX_NUM_OF_DIALOG;
|
||||
}
|
||||
|
||||
callId = &response->sipApiMsg.sipMsg.sipHdrCallId;
|
||||
toTag = response->sipApiMsg.sipMsg.sipHdrTo.params.para[0].para.paraStr;
|
||||
fromTag = response->sipApiMsg.sipMsg.sipHdrFrom.params.para[0].para.paraStr;
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_DIALOG; i++)
|
||||
{
|
||||
if ((sipUaDialog[i].flag == 0)
|
||||
|| (strcmp(sipUaDialog[i].callId.value, callId->value) != 0)
|
||||
|| (strcmp(sipUaDialog[i].localTag, fromTag) != 0))
|
||||
continue;
|
||||
|
||||
if (sipUaDialog[i].state < SIP_UA_DIALOG_WAIT_ACK_FOR_200)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(sipUaDialog[i].remoteTag, toTag) != 0)
|
||||
continue;
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return SIP_UA_MAX_NUM_OF_DIALOG;
|
||||
}
|
||||
|
||||
int sip_ua_select_user_by_domain(SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
int i;
|
||||
SIP_URI *sipUri;
|
||||
|
||||
if (sipApiMsg == NULL)
|
||||
return -1;
|
||||
|
||||
sipUri = &sipApiMsg->sipApiMsg.sipMsg.sipStartLine.requestUri;
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_SAP; i++)
|
||||
{
|
||||
if ((sipUaSaps[i].flag == 1)
|
||||
&& (strcmp(sipUaSaps[i].sipUaSap.domain, sipUri->host.addr.domain) == 0))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sip_ua_check_retransmit_invit(SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
SIP_HDR_CALL_ID *callId;
|
||||
char *fromTag;
|
||||
int i;
|
||||
|
||||
callId = &sipApiMsg->sipApiMsg.sipMsg.sipHdrCallId;
|
||||
fromTag = sipApiMsg->sipApiMsg.sipMsg.sipHdrFrom.params.para[0].para.paraStr;
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_PORT; i++)
|
||||
{
|
||||
if (sipUaPort[i].flag != 1)
|
||||
continue;
|
||||
|
||||
if ((strcmp(sipUaPort[i].callStruct.callId.value, callId->value) == 0)
|
||||
&& (strcmp(sipUaPort[i].callStruct.callId.host, callId->host) == 0)
|
||||
&& (strcmp(sipUaPort[i].callStruct.fromTag, fromTag) == 0))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sip_ua_allocate_port_for_req(BYTE method, SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
int port;
|
||||
|
||||
if (((sipApiMsg->sipApiMsg.sipMsg.sipGenHdrFlag[0] & SIP_HDR_EXPIRES_MASK) == SIP_HDR_EXPIRES_MASK)
|
||||
&& (sipApiMsg->sipApiMsg.sipMsg.sipHdrExpires.value == 0))
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_allocate_port_for_req:expier value is 0\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if ((port = sip_ua_get_port()) < 0)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_allocate_port_for_req:no enough resource\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipUaPort[port].sipuafState = SIP_UA_FSM_STATE_INDICATE;
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_IDLE;
|
||||
|
||||
if ((sipApiMsg->sipApiMsg.sipMsg.sipGenHdrFlag[0] & SIP_HDR_EXPIRES_MASK) == SIP_HDR_EXPIRES_MASK)
|
||||
{
|
||||
sipUaPort[port].sipuafTimer = (sipApiMsg->sipApiMsg.sipMsg.sipHdrExpires.value * 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
sipUaPort[port].sipuafTimer = SIP_UA_FSM_TIMER;
|
||||
}
|
||||
|
||||
sipUaPort[port].rcvCmd = method;
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
int sip_ua_sip_recv_proc(WORD sipPort, WORD upPort, BYTE transFlag, SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
int ret;
|
||||
// int sapIndex;
|
||||
WORD dialogId;
|
||||
BYTE method;
|
||||
int statusCode;
|
||||
SIP_API_STRUCT sdSipMsg;
|
||||
int port;
|
||||
DWORD usrPort;
|
||||
pal_cg_struct *cg;
|
||||
char *localDomain;
|
||||
char *destDomain;
|
||||
SIP_EVENTHANDLE_STRUCT *event_handle = NULL;
|
||||
|
||||
if (sipApiMsg == NULL)
|
||||
return -1;
|
||||
|
||||
localDomain = sipApiMsg->sipApiMsg.sipMsg.sipStartLine.requestUri.host.addr.domain;
|
||||
destDomain = sipApiMsg->sipApiMsg.sipMsg.sipHdrVias.vias[sipApiMsg->sipApiMsg.sipMsg.sipHdrVias.head].url.domain;
|
||||
|
||||
memset(&sipUaRecvMsg, 0, sizeof(SIP_API_STRUCT));
|
||||
|
||||
switch(transFlag)
|
||||
{
|
||||
case SIP_TRANSPORT_LAYER:
|
||||
if (sipApiMsg->sipApiType == SIP_API_REQ_MSG)
|
||||
{
|
||||
/* if ((sapIndex = sip_ua_select_user_by_domain(sipApiMsg)) < 0)
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "sip ua recv msg can not find user\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
if ((cg = (pal_cg_struct *)pal_sip_find_cg(localDomain, destDomain)) == NULL)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv: can not find cg!\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((dialogId = sip_ua_match_dialog_with_req(sipApiMsg)) >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
dialogId = SIP_UA_NULL_DIALOG;
|
||||
|
||||
method = sipApiMsg->sipApiMsg.sipMsg.sipStartLine.sipMethod;
|
||||
|
||||
if ((method == SIP_METHOD_INVITE) && (dialogId <= SIP_UA_MAX_NUM_OF_DIALOG))
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip ua recv retransmitted invite\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (((method == SIP_METHOD_RE_INVITE) || (method == SIP_METHOD_CANCEL) || (method == SIP_METHOD_ACK) || (method == SIP_METHOD_BYE) || (method == SIP_METHOD_INFO))
|
||||
&& (dialogId == SIP_UA_NULL_DIALOG))
|
||||
{
|
||||
if (method != SIP_METHOD_ACK)
|
||||
{
|
||||
memcpy(&sdSipMsg, sipApiMsg, sizeof(SIP_API_STRUCT));
|
||||
sdSipMsg.sipApiType = SIP_API_RES_MSG;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipStartLine.statusCode = 481;
|
||||
strcpy(sdSipMsg.sipApiMsg.sipMsg.sipStartLine.reasonPhrase, "Call/Transaction Does Not Exist");
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipEntity.sipHdrContentLength = 0;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipGenHdrFlag[0] = SIP_HDR_CALL_ID_MASK | SIP_HDR_CSEQ_MASK
|
||||
| SIP_HDR_FROM_MASK | SIP_HDR_TO_MASK | SIP_HDR_VIA_MASK;
|
||||
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipReStruct.sipReHdrFlag[0] = 0;
|
||||
sip_send_msg(SIP_NULL_TRANS_ID, SIP_NULL_UP_PORT, SIP_TRANSPORT_LAYER, &sdSipMsg);
|
||||
}
|
||||
|
||||
sprintf((char *)sipAsciTempBuf, "sip ua recv a inside msg without relational dialog\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -7;
|
||||
}
|
||||
|
||||
if (dialogId < SIP_UA_NULL_DIALOG)
|
||||
{
|
||||
if ((method != SIP_METHOD_ACK) && (method != SIP_METHOD_CANCEL))
|
||||
{
|
||||
if ((ret =sip_ua_update_dialog_with_req(dialogId, sipApiMsg)) < 0)
|
||||
{
|
||||
if (ret == -2)
|
||||
{
|
||||
//need forward develop
|
||||
memset(&sdSipMsg, 0, sizeof(SIP_API_STRUCT));
|
||||
memcpy(&sdSipMsg, sipApiMsg, sizeof(SIP_API_STRUCT));
|
||||
sdSipMsg.sipApiType = SIP_API_RES_MSG;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipStartLine.statusCode = 500;
|
||||
strcpy( sdSipMsg.sipApiMsg.sipMsg.sipStartLine.reasonPhrase, "Server Internal Error");
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipEntity.sipHdrContentLength = 0;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipGenHdrFlag[0] = SIP_HDR_CALL_ID_MASK | SIP_HDR_CSEQ_MASK |
|
||||
SIP_HDR_FROM_MASK | SIP_HDR_TO_MASK | SIP_HDR_VIA_MASK;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipReStruct.sipReHdrFlag[0] = 0;
|
||||
sip_send_msg(SIP_NULL_TRANS_ID, SIP_NULL_UP_PORT, SIP_TRANSPORT_LAYER, &sdSipMsg);
|
||||
}
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:update dialog with req failed, ret=%d\r\n", ret);
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sipApiMsg->sipApiMsg.sipMsg.sipHdrCseq.value != sipUaDialog[dialogId].remoteInvCseq)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:ack or cancel cseq is not equal to invite\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (method != SIP_METHOD_ACK)
|
||||
{
|
||||
if (method == SIP_METHOD_INVITE)
|
||||
{
|
||||
if (sip_ua_check_retransmit_invit(sipApiMsg) >= 0)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:retransmit invit already in progress\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((port = sip_ua_allocate_port_for_req(method, sipApiMsg)) < 0)
|
||||
{
|
||||
if (port == -2)
|
||||
{
|
||||
memset(&sdSipMsg, 0, sizeof(SIP_API_STRUCT));
|
||||
memcpy(&sdSipMsg, sipApiMsg, sizeof(SIP_API_STRUCT));
|
||||
sdSipMsg.sipApiType = SIP_API_RES_MSG;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipStartLine.statusCode = 487;
|
||||
strcpy(sdSipMsg.sipApiMsg.sipMsg.sipStartLine.reasonPhrase, "Request Terminated");
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipEntity.sipHdrContentLength = 0;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipGenHdrFlag[0] = SIP_HDR_CALL_ID_MASK | SIP_HDR_CSEQ_MASK |
|
||||
SIP_HDR_FROM_MASK | SIP_HDR_TO_MASK | SIP_HDR_VIA_MASK;
|
||||
sdSipMsg.sipApiMsg.sipMsg.sipReStruct.sipReHdrFlag[0] = 0;
|
||||
sip_send_msg(SIP_NULL_TRANS_ID, SIP_NULL_UP_PORT, SIP_TRANSPORT_LAYER, &sdSipMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:no enough resource\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (method == SIP_METHOD_INVITE)
|
||||
{
|
||||
memcpy(&sipUaPort[port].callStruct.callId, &sipApiMsg->sipApiMsg.sipMsg.sipHdrCallId, sizeof(SIP_HDR_CALL_ID));
|
||||
strcpy(sipUaPort[port].callStruct.fromTag, sipApiMsg->sipApiMsg.sipMsg.sipHdrFrom.params.para[0].para.paraStr);
|
||||
|
||||
/* cg = pal_sip_find_cg(sipApiMsg->sipApiMsg.sipMsg.sipHdrVias.vias[sipApiMsg->sipApiMsg.sipMsg.sipHdrVias.head].url.host.addr.domain);
|
||||
|
||||
if (cg == NULL)
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "sip_ua_sip_recv: Invite req can not find cg!\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
sip_ua_init_port(port);
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
sip_ua_set_inv_temp_rsp(port, sipApiMsg);
|
||||
|
||||
usrPort = SIP_UA_NULL_UP_PORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dialogId < SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
{
|
||||
usrPort = sipUaDialog[dialogId].usrPort;
|
||||
sipUaDialog[dialogId].sipUaPort = port;
|
||||
}
|
||||
else
|
||||
{
|
||||
usrPort = SIP_UA_NULL_UP_PORT;
|
||||
}
|
||||
// cg = NULL;
|
||||
}
|
||||
|
||||
event_handle = (SIP_EVENTHANDLE_STRUCT *)pal_get_handler(cg->id);
|
||||
event_handle->recv_req(port, usrPort, dialogId, method, sipApiMsg, cg);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_req(port, usrPort, dialogId, method, sipApiMsg, cg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sipUaDialog[dialogId].uaPort >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:recv ack, but no port in dialog to proc inv rsp\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -3;
|
||||
}
|
||||
|
||||
sipUaPort[sipUaDialog[dialogId].uaPort].rcvCmd = SIP_METHOD_ACK;
|
||||
|
||||
memcpy(&sipUaRecvMsg, sipApiMsg, sizeof(SIP_API_STRUCT));
|
||||
|
||||
sip_ua_fsm(sipUaDialog[dialogId].uaPort);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sipApiMsg->sipApiMsg.sipMsg.sipHdrCseq.method == SIP_METHOD_INVITE) && (sipApiMsg->sipApiMsg.sipMsg.sipStartLine.statusCode == 200)
|
||||
&& ((dialogId = sip_ua_match_dialog_with_rsp(sipApiMsg)) < SIP_UA_MAX_NUM_OF_DIALOG))
|
||||
{
|
||||
if (sipUaDialog[dialogId].uaAckPort >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:recv retransmitted 200, no ack proc port in dialog\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -5;
|
||||
}
|
||||
|
||||
sipUaPort[sipUaDialog[dialogId].uaAckPort].rcvCmd = 200;
|
||||
|
||||
memcpy(&sipUaRecvMsg, sipApiMsg, sizeof(SIP_API_STRUCT));
|
||||
|
||||
sip_ua_fsm(sipUaDialog[dialogId].uaAckPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:recv rsp from transport layer\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SIP_TRANSACTION_LAYER:
|
||||
if ((upPort >= SIP_UA_MAX_NUM_OF_PORT) || (sipUaPort[upPort].flag != 1))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sipApiMsg->sipApiType == SIP_API_REQ_MSG)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:recv req from transaction layer\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((dialogId = sip_ua_match_dialog_with_rsp(sipApiMsg)) >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
dialogId = SIP_UA_NULL_DIALOG;
|
||||
|
||||
if (sipUaPort[upPort].dialogId != dialogId)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv:find dialog wrong\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
dialogId = sipUaPort[upPort].dialogId;
|
||||
// return -1;
|
||||
}
|
||||
|
||||
if ((dialogId < SIP_UA_MAX_NUM_OF_DIALOG) && (sipUaPort[upPort].cgId != sipUaDialog[dialogId].cgId))//sipUaPort[upPort].sapIndex != sipUaDialog[dialogId].userIndex
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_sip_recv: cg id wrong\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
statusCode = sipApiMsg->sipApiMsg.sipMsg.sipStartLine.statusCode;
|
||||
|
||||
sipUaPort[upPort].rcvCmd= statusCode;
|
||||
|
||||
memcpy(&sipUaRecvMsg, sipApiMsg, sizeof(SIP_API_STRUCT));
|
||||
|
||||
sip_ua_fsm(upPort);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_init_dialog(WORD dialogId)
|
||||
{
|
||||
if (dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&sipUaDialog[dialogId], 0, sizeof(SIP_DIALOG));
|
||||
sipUaDialog[dialogId].uaPort = 0xFFFF;
|
||||
sipUaDialog[dialogId].uaAckPort = 0xFFFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_init_port(WORD port)
|
||||
{
|
||||
if (port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&sipUaPort[port], 0, sizeof(SIP_UA_PORT));
|
||||
sipUaPort[port].dialogId = SIP_UA_NULL_DIALOG;
|
||||
sipUaPort[port].llPort = 0xFFFF;
|
||||
sipUaPort[port].usrPort = 0xFFFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sip_ua_timer()
|
||||
{
|
||||
WORD port;
|
||||
|
||||
for (port = 0; port < SIP_UA_MAX_NUM_OF_PORT; port++)
|
||||
{
|
||||
if (sipUaPort[port].flag == 0)
|
||||
continue;
|
||||
|
||||
sip_ua_fsm(port);
|
||||
}
|
||||
|
||||
sip_t10ms();
|
||||
}
|
||||
|
||||
int sip_ua_regist_in_sip()
|
||||
{
|
||||
sipUaSipUser.proxyType= SIP_PROXY_TYPE_NONE;
|
||||
strcpy(sipUaSipUser.userName, "SIP_UA");
|
||||
strcpy(sipUaSipUser.domain, sipUaDottedHostIp);
|
||||
sipUaSipUser.recv_proc = sip_ua_sip_recv_proc;
|
||||
|
||||
if ((sipUaSipIndex = sip_register_user(&sipUaSipUser)) < 0)
|
||||
{
|
||||
printf("SIP UA Module register in SIP Module Failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_init()
|
||||
{
|
||||
WORD i;
|
||||
|
||||
printf("SIP UA Module Init Start!\n");
|
||||
|
||||
if (sip_ua_get_local_ip() < 0)
|
||||
exit(1);
|
||||
|
||||
if (sip_ua_regist_in_sip() < 0)
|
||||
{
|
||||
printf("SIP UA Module regist in sip fail\r\n");
|
||||
}
|
||||
|
||||
sipUaPortSelect = 0;
|
||||
sipUaDialogSelect = 0;
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_DIALOG; i++)
|
||||
{
|
||||
sip_ua_init_dialog(i);
|
||||
}
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_PORT; i++)
|
||||
{
|
||||
sip_ua_init_port(i);
|
||||
}
|
||||
|
||||
memset((BYTE *)&sipUaSaps[0], 0, sizeof(SIP_UA_SAPS) * SIP_UA_MAX_NUM_OF_SAP);
|
||||
|
||||
memset((BYTE *)&sipUaRecvMsg, 0, sizeof(SIP_API_STRUCT));
|
||||
|
||||
printf("SIP UA Module Init Complete!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*int sip_ua_bind(SIP_UA_SAP *sap)
|
||||
{
|
||||
BYTE sapIndex;
|
||||
|
||||
if ((sap == NULL) || (sap->recv_req == NULL) || (sap->recv_resp == NULL)
|
||||
|| (sap->proxyType != SIP_PROXY_TYPE_NONE))
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "sip_ua_bind:sap malformed\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (sapIndex = 0; sapIndex < SIP_UA_MAX_NUM_OF_SAP; sapIndex++)
|
||||
{
|
||||
if ((sipUaSaps[sapIndex].flag == 1) &&
|
||||
(strcmp(sipUaSaps[sapIndex].sipUaSap.userName, sap->userName) == 0))
|
||||
{
|
||||
memcpy(&sipUaSaps[sapIndex].sipUaSap, sap, sizeof(SIP_UA_SAP));
|
||||
|
||||
if (sip_store_sip_ua_user(sapIndex, sap->domain) < 0)
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "sip_ua_bind:sip store sip ua user failed!\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
}
|
||||
|
||||
return sapIndex;
|
||||
}
|
||||
}
|
||||
|
||||
for (sapIndex = 0; sapIndex < SIP_UA_MAX_NUM_OF_SAP; sapIndex++)
|
||||
{
|
||||
if (sipUaSaps[sapIndex].flag != 0)
|
||||
continue;
|
||||
|
||||
sipUaSaps[sapIndex].flag = 1;
|
||||
|
||||
memcpy((BYTE *)&sipUaSaps[sapIndex].sipUaSap, sap, sizeof(SIP_UA_SAP));
|
||||
|
||||
if (sip_store_sip_ua_user(sapIndex, sap->domain) < 0)
|
||||
{
|
||||
sprintf(sipAsciTempBuf, "sip_ua_bind:sip store sip ua user failed\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
}
|
||||
|
||||
return sapIndex;
|
||||
}
|
||||
|
||||
sprintf(sipAsciTempBuf, "sip ua user bind fail\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
|
||||
return -1;
|
||||
}*/
|
||||
336
plat/sip/src/sip_ua_dialog.c
Normal file
336
plat/sip/src/sip_ua_dialog.c
Normal file
@@ -0,0 +1,336 @@
|
||||
#include "./include/sip_ua_pub.h"
|
||||
#include "./include/sip.h"
|
||||
#include "./include/sip_ua_dialog.h"
|
||||
#include "./include/sip_ua_const.h"
|
||||
#include "./include/sip_ua_ext.h"
|
||||
#include "./include/sip_ext.h"
|
||||
#include "./include/sip_debug.h"
|
||||
|
||||
int sip_ua_create_tag(WORD dialogId)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
if (dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
return -1;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
sprintf(sipUaDialog[dialogId].localTag, "%X%lX%lX", dialogId, tv.tv_sec, tv.tv_usec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_create_call_id(WORD usrPort, WORD dialogId)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
if (dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
return -1;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
sprintf(sipUaDialog[dialogId].callId.value, "%X%lX%lX", usrPort, tv.tv_usec, tv.tv_sec);
|
||||
strcpy(sipUaDialog[dialogId].callId.host, sipUaDottedHostIp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sip_ua_fill_dialog_uri(SIP_UA_URI *sipUaUri, SIP_URI *sipUri)
|
||||
{
|
||||
if ((sipUaUri == NULL) || (sipUri == NULL))
|
||||
return;
|
||||
|
||||
sipUaUri->uriType = sipUri->uriType;
|
||||
strcpy(sipUaUri->userName, sipUri->userName);
|
||||
strcpy(sipUaUri->password, sipUri->password);
|
||||
strcpy(sipUaUri->domain, sipUri->host.addr.domain);
|
||||
}
|
||||
|
||||
int sip_ua_set_dialog_state(WORD dialogId, BYTE state)
|
||||
{
|
||||
if ((dialogId>= SIP_UA_MAX_NUM_OF_DIALOG) || (sipUaDialog[dialogId].flag == 0))
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_set_dialog_state: dialogId wrong\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipUaDialog[dialogId].state = state;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_update_dialog_with_req(WORD dialogId, SIP_API_STRUCT *sipApiMsg)
|
||||
{
|
||||
SIP_DIALOG *sipUaDlgPtr;
|
||||
BYTE method;
|
||||
|
||||
if (sipApiMsg == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((dialogId >= SIP_UA_MAX_NUM_OF_DIALOG) || (sipUaDialog[dialogId].flag == 0))
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_update_dialog_with_req:dialogId wrong\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipUaDlgPtr = &sipUaDialog[dialogId];
|
||||
method = sipApiMsg->sipApiMsg.sipMsg.sipStartLine.sipMethod;
|
||||
|
||||
/* if (method == SIP_METHOD_INVITE)
|
||||
{
|
||||
strcpy(sipUaDlgPtr->invBranch, sipApiMsg->sipApiMsg.sipMsg.sipHdrVias.vias[1].params.para[0].para.paraStr);
|
||||
}//for cancel*/
|
||||
|
||||
if ((method != SIP_METHOD_ACK) && (method != SIP_METHOD_CANCEL))
|
||||
{
|
||||
if (sipApiMsg->sipApiMsg.sipMsg.sipHdrCseq.value <= sipUaDlgPtr->remoteCseq.value)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_update_dialog_with_req:req seq is less than seq in dialog\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
sipUaDlgPtr->remoteCseq.value = sipApiMsg->sipApiMsg.sipMsg.sipHdrCseq.value;
|
||||
}
|
||||
|
||||
if ((method == SIP_METHOD_RE_INVITE)
|
||||
|| ((method == SIP_METHOD_ACK) && ((sipUaDlgPtr->paramFlag & SIP_UA_DIALOG_REMOTE_TARGET_FLAG) != SIP_UA_DIALOG_REMOTE_TARGET_FLAG)))
|
||||
{
|
||||
if ((sipApiMsg->sipApiMsg.sipMsg.sipGenHdrFlag[0] & SIP_HDR_CONTACT_MASK) == SIP_HDR_CONTACT_MASK)
|
||||
{
|
||||
sip_ua_fill_dialog_uri(&sipUaDlgPtr->remoteTarget, &sipApiMsg->sipApiMsg.sipMsg.sipHdrContacts.contacts[sipApiMsg->sipApiMsg.sipMsg.sipHdrContacts.head].url);
|
||||
sipUaDlgPtr->paramFlag |= SIP_UA_DIALOG_REMOTE_TARGET_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_update_dialog_with_rsp(WORD dialogId, SIP_API_STRUCT * sipApiMsg, BYTE flag)
|
||||
{
|
||||
SIP_DIALOG *sipUaDlgPtr;
|
||||
BYTE head;
|
||||
BYTE num;
|
||||
int i;
|
||||
BYTE method;
|
||||
BYTE endHead;
|
||||
|
||||
if (sipApiMsg == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((dialogId >= SIP_UA_MAX_NUM_OF_DIALOG) || (sipUaDialog[dialogId].flag == 0))
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_update_dialog_with_rsp: dialogId wrong\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
method = sipApiMsg->sipApiMsg.sipMsg.sipHdrCseq.method;
|
||||
sipUaDlgPtr = &sipUaDialog[dialogId];
|
||||
|
||||
if (sipApiMsg->sipApiMsg.sipMsg.sipHdrCseq.value != sipUaDlgPtr->localCseq.value)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_update_dialog_with_rsp: rsp seq is not equal to seq in dialog\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if ((method != SIP_METHOD_INVITE) && (method != SIP_METHOD_RE_INVITE))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flag == 1)
|
||||
strcpy(sipUaDlgPtr->remoteTag, sipApiMsg->sipApiMsg.sipMsg.sipHdrTo.params.para[0].para.paraStr);
|
||||
|
||||
if ((method == SIP_METHOD_INVITE) && ((sipApiMsg->sipApiMsg.sipMsg.sipGenHdrFlag[0] & SIP_HDR_RECORD_ROUTE_MASK) == SIP_HDR_RECORD_ROUTE_MASK))
|
||||
{
|
||||
head = sipApiMsg->sipApiMsg.sipMsg.sipHdrRecordRoutes.head;
|
||||
sipUaDlgPtr->routeSets.num = endHead = num = sipApiMsg->sipApiMsg.sipMsg.sipHdrRecordRoutes.num;
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
--endHead;
|
||||
|
||||
memcpy(&sipUaDlgPtr->routeSets.recRoutes[endHead], &sipApiMsg->sipApiMsg.sipMsg.sipHdrRecordRoutes.recRoutes[head], sizeof(SIP_HDR_RECORD_ROUTE));
|
||||
|
||||
if (++head >= SIP_MAX_NUM_OF_RECORD_ROUTES)
|
||||
head = 0;
|
||||
}
|
||||
|
||||
sipUaDlgPtr->routeSets.head = 0;
|
||||
}
|
||||
|
||||
if ((sipApiMsg->sipApiMsg.sipMsg.sipGenHdrFlag[0] & SIP_HDR_CONTACT_MASK) == SIP_HDR_CONTACT_MASK)
|
||||
{
|
||||
sip_ua_fill_dialog_uri(&sipUaDlgPtr->remoteTarget, &sipApiMsg->sipApiMsg.sipMsg.sipHdrContacts.contacts[sipApiMsg->sipApiMsg.sipMsg.sipHdrContacts.head].url);
|
||||
sipUaDlgPtr->paramFlag |= SIP_UA_DIALOG_REMOTE_TARGET_FLAG;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_init_dialog_as_client_with_inv(BYTE cgId, WORD usrPort, SIP_MSG *sipMsg)//sapIndex
|
||||
{
|
||||
WORD dialogId = sipUaDialogSelect;
|
||||
int i;
|
||||
|
||||
if (sipMsg == NULL)//if ((sapIndex >= SIP_UA_MAX_NUM_OF_SAP) || (sipMsg == NULL))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
{
|
||||
dialogId = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_DIALOG; i++)
|
||||
{
|
||||
if (sipUaDialog[dialogId].flag == 1)
|
||||
{
|
||||
if (++dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
dialogId = 0;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
sip_ua_init_dialog(dialogId);
|
||||
sipUaDialog[dialogId].flag = 1;
|
||||
sipUaDialog[dialogId].type = SIP_CALLER;
|
||||
sipUaDialog[dialogId].cgId = cgId;//sipUaDialog[dialogId].userIndex = sapIndex;
|
||||
sipUaDialog[dialogId].usrPort = usrPort;
|
||||
sipUaDialog[dialogId].state = SIP_UA_DIALOG_IDLE;
|
||||
|
||||
sip_ua_create_tag(dialogId);
|
||||
sip_ua_create_call_id(usrPort, dialogId);
|
||||
sipUaDialog[dialogId].invCSeq = sipUaDialog[dialogId].localCseq.value= 0;
|
||||
sipUaDialog[dialogId].remoteCseq.value = 0;
|
||||
|
||||
sip_ua_fill_dialog_uri(&sipUaDialog[dialogId].localURI, &sipMsg->sipHdrFrom.url);
|
||||
sip_ua_fill_dialog_uri(&sipUaDialog[dialogId].remoteURI, &sipMsg->sipHdrTo.url);
|
||||
|
||||
sipUaDialogSelect = (dialogId + 1) % SIP_UA_MAX_NUM_OF_DIALOG;
|
||||
|
||||
return dialogId;
|
||||
}
|
||||
|
||||
sprintf((char *)sipAsciTempBuf, "client initial dialog with inv failed\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sip_ua_init_dialog_as_server_with_inv(BYTE cgId, WORD hdlPort, WORD usrPort, SIP_MSG *sipMsg)//BYTE sapIndex
|
||||
{
|
||||
WORD dialogId = sipUaDialogSelect;
|
||||
int i;
|
||||
int j;
|
||||
BYTE head;
|
||||
|
||||
if (sipMsg == NULL)//if ((sapIndex >= SIP_UA_MAX_NUM_OF_SAP) || (sipMsg == NULL))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
{
|
||||
dialogId = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < SIP_UA_MAX_NUM_OF_DIALOG; i++)
|
||||
{
|
||||
if (sipUaDialog[dialogId].flag == 1)
|
||||
{
|
||||
if (++dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
dialogId = 0;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
sip_ua_init_dialog(dialogId);
|
||||
sipUaDialog[dialogId].flag = 1;
|
||||
sipUaDialog[dialogId].type = SIP_CALLEE;
|
||||
sipUaDialog[dialogId].cgId = cgId;//sipUaDialog[dialogId].userIndex = sapIndex;
|
||||
sipUaDialog[dialogId].usrPort = usrPort;
|
||||
sipUaDialog[dialogId].sipUaPort = hdlPort;
|
||||
sipUaDialog[dialogId].invUaPort.rvInvUaPort = hdlPort;
|
||||
sipUaDialog[dialogId].state = SIP_UA_DIALOG_IDLE;
|
||||
|
||||
if (sipMsg->sipHdrTo.params.para[0].paraName == SIP_API_PNAME_TAG)
|
||||
{
|
||||
strcpy(sipUaDialog[dialogId].localTag, sipMsg->sipHdrTo.params.para[0].para.paraStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
sip_ua_create_tag(dialogId);
|
||||
}
|
||||
|
||||
strcpy(sipUaDialog[dialogId].invBranch, sipMsg->sipHdrVias.vias[1].params.para[0].para.paraStr);
|
||||
sipUaDialog[dialogId].invCSeq = sipUaDialog[dialogId].localCseq.value = 0;
|
||||
sipUaDialog[dialogId].remoteCseq.value = sipUaDialog[dialogId].remoteInvCseq = sipMsg->sipHdrCseq.value;
|
||||
memcpy(&sipUaDialog[dialogId].callId, &sipMsg->sipHdrCallId, sizeof(SIP_HDR_CALL_ID));
|
||||
sip_ua_fill_dialog_uri(&sipUaDialog[dialogId].localURI, &sipMsg->sipHdrTo.url);
|
||||
sip_ua_fill_dialog_uri(&sipUaDialog[dialogId].remoteURI, &sipMsg->sipHdrFrom.url);
|
||||
|
||||
if ((sipMsg->sipGenHdrFlag[0] & SIP_HDR_CONTACT_MASK) == SIP_HDR_CONTACT_MASK)
|
||||
{
|
||||
sip_ua_fill_dialog_uri(&sipUaDialog[dialogId].remoteTarget, &sipMsg->sipHdrContacts.contacts[sipMsg->sipHdrContacts.head].url);
|
||||
sipUaDialog[dialogId].paramFlag |= SIP_UA_DIALOG_REMOTE_TARGET_FLAG;
|
||||
}
|
||||
|
||||
strcpy(sipUaDialog[dialogId].remoteTag, sipMsg->sipHdrFrom.params.para[0].para.paraStr);
|
||||
|
||||
if ((sipMsg->sipGenHdrFlag[0] & SIP_HDR_RECORD_ROUTE_MASK) == SIP_HDR_RECORD_ROUTE_MASK)
|
||||
{
|
||||
sipUaDialog[dialogId].routeSets.num = sipMsg->sipHdrRecordRoutes.num;
|
||||
sipUaDialog[dialogId].routeSets.head = 0;
|
||||
head = sipMsg->sipHdrRecordRoutes.head;
|
||||
|
||||
for (j = 0; j < sipMsg->sipHdrRecordRoutes.num; j++)
|
||||
{
|
||||
memcpy(&sipUaDialog[dialogId].routeSets.recRoutes[j], &sipMsg->sipHdrRecordRoutes.recRoutes[head], sizeof(SIP_HDR_RECORD_ROUTES));
|
||||
|
||||
if (++head >= SIP_MAX_NUM_OF_RECORD_ROUTES)
|
||||
head = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sipUaDialogSelect = (dialogId + 1) % SIP_UA_MAX_NUM_OF_DIALOG;
|
||||
|
||||
return dialogId;
|
||||
}
|
||||
|
||||
sprintf((char *)sipAsciTempBuf, "server initial dialog with inv failed\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sip_ua_free_dialog(DWORD usrPort, WORD dialogId)
|
||||
{
|
||||
if (dialogId >= SIP_UA_MAX_NUM_OF_DIALOG)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sipUaDialog[dialogId].flag != 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sipUaDialog[dialogId].usrPort != usrPort)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&sipUaDialog[dialogId], 0, sizeof(SIP_DIALOG));
|
||||
sipUaDialog[dialogId].uaPort = 0xFFFF;
|
||||
sipUaDialog[dialogId].uaAckPort = 0xFFFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
628
plat/sip/src/sip_ua_fsm.c
Normal file
628
plat/sip/src/sip_ua_fsm.c
Normal file
@@ -0,0 +1,628 @@
|
||||
#include "./include/sip_ua_pub.h"
|
||||
#include "./include/sip.h"
|
||||
#include "./include/sip_ua_const.h"
|
||||
#include "./include/sip_ua_struct.h"
|
||||
#include "./include/sip_ua_ext.h"
|
||||
#include "./include/sip_ua_dialog.h"
|
||||
#include "./include/sip_ua.h"
|
||||
#include "./include/sip_ext.h"
|
||||
#include "./include/sip_debug.h"
|
||||
|
||||
extern int sip_ua_set_dialog_state(WORD dialogId, BYTE state);
|
||||
extern int sip_ua_update_dialog_with_rsp(WORD dialogId, SIP_API_STRUCT * sipApiMsg, BYTE flag);
|
||||
|
||||
WORD sip_ua_find_rsp_method(BYTE method, WORD resp)
|
||||
{
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case SIP_METHOD_INVITE:
|
||||
if (resp == 180)
|
||||
return SIP_METHOD_RESPONSE_INV_RINGING;
|
||||
else if ((resp > 100) && (resp < 200))
|
||||
return SIP_METHOD_RESPONSE_INV_PROGRESS;
|
||||
else if ((resp >= 200) && (resp < 300))
|
||||
return SIP_METHOD_RESPONSE_INV_CONFIRM;
|
||||
else if ((resp >= 300) && (resp < 400))
|
||||
return SIP_METHOD_RESPONSE_INV_REDIR;
|
||||
else
|
||||
return SIP_METHOD_RESPONSE_INV_REL;
|
||||
break;
|
||||
case SIP_METHOD_RE_INVITE:
|
||||
if (resp == 180)
|
||||
return SIP_METHOD_RESPONSE_RE_INV_RINGING;
|
||||
else if ((resp > 100) && (resp < 200))
|
||||
return SIP_METHOD_RESPONSE_RE_INV_PROGRESS;
|
||||
else if ((resp >= 200) && (resp < 300))
|
||||
return SIP_METHOD_RESPONSE_RE_INV_CONFIRM;
|
||||
else if (resp == 491)
|
||||
return SIP_METHOD_RESPONSE_RE_INV_RETRANSMIT;
|
||||
else if ((481 == resp) || (408 == resp) || (99 == resp))
|
||||
return SIP_METHOD_RESPONSE_RE_INV_RELEASE;
|
||||
else
|
||||
return SIP_METHOD_RESPONSE_RE_INV_FAILED;
|
||||
break;
|
||||
case SIP_METHOD_UPDATE:
|
||||
if ((resp >= 200) && (resp < 300))
|
||||
return SIP_METHOD_RESPONSE_UPDATE_CONFIRM;
|
||||
else
|
||||
return SIP_METHOD_RESPONSE_UPDATE_FAILED;
|
||||
break;
|
||||
case SIP_METHOD_CANCEL:
|
||||
return SIP_METHOD_RESPONSE_CANCEL;
|
||||
break;
|
||||
case SIP_METHOD_BYE:
|
||||
return SIP_METHOD_RESPONSE_BYE;
|
||||
break;
|
||||
default:
|
||||
if ((resp >= 200) && (resp < 300))
|
||||
return SIP_METHOD_RESPONSE_CONFIRM;
|
||||
else
|
||||
return SIP_METHOD_RESPONSE_REL;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sip_ua_fsm(WORD port);
|
||||
|
||||
DWORD sip_ua_min(DWORD A, DWORD B)
|
||||
{
|
||||
if (A <= B)
|
||||
return A;
|
||||
|
||||
return B;
|
||||
}
|
||||
|
||||
int sip_ua_inv_req_proc(WORD port)
|
||||
{
|
||||
WORD rvCmd;
|
||||
WORD rspMethod;
|
||||
WORD sdCmd;
|
||||
SIP_UA_PORT *sipUaPortPtr;
|
||||
BYTE cgId;//BYTE sapIndex;
|
||||
WORD usrPort;
|
||||
WORD dialogId;
|
||||
WORD sipTransId;
|
||||
BYTE sdMethod;
|
||||
SIP_API_STRUCT *sipApiMsg;
|
||||
SIP_EVENTHANDLE_STRUCT *event_handle = NULL;
|
||||
|
||||
if (port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipUaPortPtr = &sipUaPort[port];
|
||||
rvCmd = sipUaPortPtr->rcvCmd;
|
||||
sipTransId = sipUaPortPtr->llPort;
|
||||
sdCmd = sipUaPortPtr->sdCmd;
|
||||
cgId = sipUaPortPtr->cgId;//sapIndex = sipUaPortPtr->sapIndex;
|
||||
dialogId = sipUaPortPtr->dialogId;
|
||||
usrPort = sipUaPortPtr->usrPort;
|
||||
|
||||
if ((event_handle = (SIP_EVENTHANDLE_STRUCT *)pal_get_handler(cgId)) == NULL)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_inv_req_proc: can not find handle function!\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (sipUaPortPtr->state)
|
||||
{
|
||||
case SIP_UA_SEND_REQUEST:
|
||||
if (sdCmd != SIP_UA_SEND_COM_NULL)
|
||||
{
|
||||
sipUaPortPtr->sdCmd = SIP_UA_SEND_COM_NULL;
|
||||
sipApiMsg = &sipUaPortPtr->sdSipMsg;
|
||||
|
||||
if (sip_send_msg(sipTransId, port, SIP_TRANSACTION_LAYER, sipApiMsg) < 0)
|
||||
return 1;
|
||||
|
||||
sipUaPortPtr->state = SIP_UA_REQ_WAIT_FOR_RSP;
|
||||
sipUaPortPtr->timer = SIP_UA_TIMER_WAIT_INV_RSP;
|
||||
}
|
||||
break;
|
||||
case SIP_UA_REQ_WAIT_FOR_RSP:
|
||||
if (rvCmd != SIP_UA_RECV_COM_NULL)
|
||||
{
|
||||
sdMethod = sipUaPortPtr->sdSipMsg.sipApiMsg.sipMsg.sipStartLine.sipMethod;
|
||||
|
||||
sipUaPortPtr->rcvCmd = SIP_UA_RECV_COM_NULL;
|
||||
|
||||
/* if (sapIndex >= SIP_UA_MAX_NUM_OF_SAP)
|
||||
{
|
||||
return 1;
|
||||
}*/
|
||||
|
||||
rspMethod = sip_ua_find_rsp_method(sdMethod, rvCmd);
|
||||
|
||||
if ((rvCmd >= 200) && (rvCmd < 300))
|
||||
{
|
||||
sip_ua_set_dialog_state(dialogId, SIP_UA_DIALOG_CONFIRMED);
|
||||
sip_ua_update_dialog_with_rsp(dialogId, &sipUaRecvMsg, 1);
|
||||
event_handle->recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
return 1;
|
||||
}
|
||||
else if ((rvCmd >= 100) && (rvCmd < 200))
|
||||
{
|
||||
if (rvCmd != 100)
|
||||
{
|
||||
sip_ua_set_dialog_state(dialogId, SIP_UA_DIALOG_EARLY);
|
||||
sip_ua_update_dialog_with_rsp(dialogId, &sipUaRecvMsg, 1);
|
||||
sipUaPortPtr->timer = SIP_UA_TIMER_WAIT_INV_200_RSP;
|
||||
event_handle->recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sdMethod == SIP_METHOD_RE_INVITE) && (rspMethod != SIP_METHOD_RESPONSE_RE_INV_RELEASE))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
sipUaPortPtr->state = SIP_UA_INV_REQ_TERMINATED;
|
||||
sipUaPortPtr->timer = SIP_UA_TIMER_T3;
|
||||
sip_ua_set_dialog_state(dialogId, SIP_UA_DIALOG_DESTROY);
|
||||
event_handle->recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (sipUaPortPtr->timer > 0)
|
||||
{
|
||||
if (--sipUaPortPtr->timer == 0)
|
||||
{
|
||||
event_handle->recv_resp(usrPort, dialogId, SIP_METHOD_RESPONSE_TIMEOUT, NULL);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_resp(usrPort, dialogId, SIP_METHOD_RESPONSE_TIMEOUT, NULL);
|
||||
sip_ua_init_dialog(dialogId);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SIP_UA_INV_REQ_TERMINATED:
|
||||
if (sipUaPortPtr->timer > 0)
|
||||
{
|
||||
if (--sipUaPortPtr->timer == 0)
|
||||
{
|
||||
sip_ua_init_dialog(dialogId);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_non_inv_req_proc(WORD port)
|
||||
{
|
||||
WORD rvCmd;
|
||||
WORD rspMethod;
|
||||
WORD sdCmd;
|
||||
SIP_UA_PORT *sipUaPortPtr;
|
||||
BYTE cgId;//BYTE sapIndex;
|
||||
WORD usrPort;
|
||||
WORD dialogId;
|
||||
WORD sipTransId;
|
||||
SIP_API_STRUCT *sipApiMsg;
|
||||
BYTE sdMethod;
|
||||
SIP_EVENTHANDLE_STRUCT *event_handle = NULL;
|
||||
|
||||
if (port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipUaPortPtr = &sipUaPort[port];
|
||||
sdCmd = sipUaPortPtr->sdCmd;
|
||||
rvCmd = sipUaPortPtr->rcvCmd;
|
||||
sipTransId = sipUaPortPtr->llPort;
|
||||
cgId = sipUaPortPtr->cgId;//sapIndex = sipUaPortPtr->sapIndex;
|
||||
dialogId = sipUaPortPtr->dialogId;
|
||||
usrPort = sipUaPortPtr->usrPort;
|
||||
|
||||
if ((event_handle = (SIP_EVENTHANDLE_STRUCT *)pal_get_handler(cgId)) == NULL)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_non_inv_req_proc: can not find handle function!\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (sipUaPortPtr->state)
|
||||
{
|
||||
case SIP_UA_SEND_REQUEST:
|
||||
if (sdCmd != SIP_UA_SEND_COM_NULL)
|
||||
{
|
||||
sipApiMsg = &sipUaPortPtr->sdSipMsg;
|
||||
sipUaPortPtr->sdCmd = SIP_UA_SEND_COM_NULL;
|
||||
|
||||
if (sip_send_msg(sipTransId, port, SIP_TRANSACTION_LAYER, sipApiMsg) < 0)
|
||||
return 1;
|
||||
|
||||
if (sipApiMsg->sipApiMsg.sipMsg.sipStartLine.sipMethod == SIP_METHOD_ACK)
|
||||
{
|
||||
sipUaPortPtr->timer2 = SIP_UA_TIMER_T1;
|
||||
}
|
||||
|
||||
sipUaPortPtr->state = SIP_UA_REQ_WAIT_FOR_RSP;
|
||||
sipUaPortPtr->timer = SIP_UA_TIMER_WAIT_NON_INV_RSP;
|
||||
}
|
||||
break;
|
||||
case SIP_UA_REQ_WAIT_FOR_RSP:
|
||||
sdMethod = sipUaPortPtr->sdSipMsg.sipApiMsg.sipMsg.sipStartLine.sipMethod;
|
||||
|
||||
if (rvCmd != SIP_UA_RECV_COM_NULL)
|
||||
{
|
||||
sipUaPortPtr->rcvCmd = SIP_UA_RECV_COM_NULL;
|
||||
|
||||
/* if (sapIndex >= SIP_UA_MAX_NUM_OF_SAP)
|
||||
{
|
||||
return 1;
|
||||
}*/
|
||||
|
||||
rspMethod = sip_ua_find_rsp_method(sdMethod, rvCmd);
|
||||
|
||||
if (sdMethod == SIP_METHOD_ACK)
|
||||
{
|
||||
if ((rvCmd == 200) && (sipUaRecvMsg.sipApiMsg.sipMsg.sipHdrCseq.method == SIP_METHOD_INVITE))
|
||||
{
|
||||
sip_ua_update_dialog_with_rsp(dialogId, &sipUaRecvMsg, 1);//need forward
|
||||
sip_ua_update_retransmit_para(dialogId, &sipUaPortPtr->sdSipMsg);
|
||||
sip_send_msg(sipTransId, port, SIP_TRANSPORT_LAYER, &sipUaPortPtr->sdSipMsg);
|
||||
}
|
||||
}
|
||||
else if (sdMethod == SIP_METHOD_BYE)
|
||||
{
|
||||
event_handle->recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
sip_ua_init_dialog(dialogId);
|
||||
return 1;
|
||||
}
|
||||
else if ((rvCmd >= 200) || (rvCmd <= SIP_TRANSACTION_TIMEOUT))
|
||||
{
|
||||
event_handle->recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_resp(usrPort, dialogId, rspMethod, &sipUaRecvMsg);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sdMethod == SIP_METHOD_ACK)
|
||||
{
|
||||
if ((sipUaPortPtr->timer2 > 0))
|
||||
{
|
||||
if (--sipUaPortPtr->timer2 == 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sipUaPortPtr->timer > 0)
|
||||
{
|
||||
if (--sipUaPortPtr->timer == 0)
|
||||
{
|
||||
event_handle->recv_resp(usrPort, dialogId, SIP_METHOD_RESPONSE_TIMEOUT, NULL);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_resp(usrPort, dialogId, SIP_METHOD_RESPONSE_TIMEOUT, NULL);
|
||||
|
||||
if (sdMethod == SIP_METHOD_BYE)
|
||||
sip_ua_init_dialog(dialogId);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sip_ua_inv_rsp_proc(WORD port)
|
||||
{
|
||||
WORD rvCmd;
|
||||
WORD sdCmd;
|
||||
SIP_UA_PORT *sipUaPortPtr;
|
||||
BYTE cgId;//BYTE sapIndex;
|
||||
WORD usrPort;
|
||||
WORD dialogId;
|
||||
WORD sipTransId;
|
||||
BYTE sdMethod;
|
||||
SIP_API_STRUCT *sipApiMsg;
|
||||
SIP_EVENTHANDLE_STRUCT *event_handle = NULL;
|
||||
|
||||
if (port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipUaPortPtr = &sipUaPort[port];
|
||||
cgId = sipUaPortPtr->cgId;//sapIndex = sipUaPortPtr->sapIndex;
|
||||
usrPort = sipUaPortPtr->usrPort;
|
||||
rvCmd = sipUaPortPtr->rcvCmd;
|
||||
sdCmd = sipUaPortPtr->sdCmd;
|
||||
sipTransId = sipUaPortPtr->llPort;
|
||||
sipApiMsg = &sipUaPortPtr->sdSipMsg;
|
||||
dialogId = sipUaPortPtr->dialogId;
|
||||
|
||||
if ((event_handle = (SIP_EVENTHANDLE_STRUCT *)pal_get_handler(cgId)) == NULL)
|
||||
{
|
||||
sprintf((char *)sipAsciTempBuf, "sip_ua_non_inv_req_proc: can not find handle function!\r\n");
|
||||
sip_log_err(sipAsciTempBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (sipUaPortPtr->state)
|
||||
{
|
||||
case SIP_UA_SEND_RESPONSE:
|
||||
if (sdCmd != SIP_UA_SEND_COM_NULL)
|
||||
{
|
||||
sipUaPortPtr->sdCmd = SIP_UA_SEND_COM_NULL;
|
||||
sdMethod = sipApiMsg->sipApiMsg.sipMsg.sipStartLine.sipMethod;
|
||||
|
||||
if (sip_send_msg(sipTransId, port, SIP_TRANSACTION_LAYER, sipApiMsg) < 0)
|
||||
return 1;
|
||||
|
||||
if ((sdCmd > 100) && (sdCmd < 200))
|
||||
{
|
||||
if (sdMethod == SIP_METHOD_INVITE)
|
||||
{
|
||||
sip_ua_set_dialog_state(dialogId, SIP_UA_DIALOG_EARLY);
|
||||
}
|
||||
}
|
||||
else if ((sdCmd >= 200) && (sdCmd < 300))
|
||||
{
|
||||
if (sdMethod == SIP_METHOD_INVITE)
|
||||
{
|
||||
sip_ua_set_dialog_state(dialogId, SIP_UA_DIALOG_CONFIRMED);
|
||||
}
|
||||
sipUaPortPtr->state = SIP_UA_INV_200_RSP_WAIT_FOR_ACK;
|
||||
|
||||
sipUaPortPtr->retrans200Times = 0;
|
||||
sipUaPortPtr->timer = SIP_UA_TIMER_WAIT_ACK;
|
||||
sipUaPortPtr->waitAckTimer = SIP_UA_TIMER_RETRANSMIT_200;
|
||||
}
|
||||
else if (sdCmd >= 300)
|
||||
{
|
||||
if ((sdMethod == SIP_METHOD_RE_INVITE) && (sdCmd != 481) && (sdCmd != 408))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sipUaPortPtr->state = SIP_UA_INV_RSP_TERMINATED;
|
||||
sipUaPortPtr->timer = SIP_UA_TIMER_T2;
|
||||
sip_ua_set_dialog_state(dialogId, SIP_UA_DIALOG_DESTROY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((sipUaPortPtr->state == SIP_UA_SEND_RESPONSE) && (sipUaPortPtr->timer > 0))
|
||||
{
|
||||
if (--sipUaPortPtr->timer == 0)
|
||||
{
|
||||
sip_ua_init_dialog(dialogId);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SIP_UA_INV_200_RSP_WAIT_FOR_ACK:
|
||||
if (rvCmd != SIP_UA_RECV_COM_NULL)
|
||||
{
|
||||
sipUaPortPtr->rcvCmd= SIP_UA_RECV_COM_NULL;
|
||||
|
||||
/* if (sapIndex >= SIP_UA_MAX_NUM_OF_SAP)
|
||||
{
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
if (rvCmd == SIP_METHOD_ACK)
|
||||
{
|
||||
event_handle->recv_req(port, usrPort, dialogId, rvCmd, &sipUaRecvMsg, NULL);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_req(port, usrPort, dialogId, rvCmd, &sipUaRecvMsg, NULL);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sipUaPortPtr->waitAckTimer > 0)
|
||||
{
|
||||
if (--sipUaPortPtr->waitAckTimer == 0)
|
||||
{
|
||||
sip_send_msg(sipTransId, port, SIP_TRANSPORT_LAYER, sipApiMsg);
|
||||
sipUaPortPtr->retrans200Times++;
|
||||
sipUaPortPtr->waitAckTimer = sip_ua_min((1 << sipUaPortPtr->retrans200Times) * SIP_UA_TIMER_RETRANSMIT_200, SIP_UA_TIMER_T1);
|
||||
}
|
||||
}
|
||||
|
||||
if (sipUaPortPtr->timer > 0)
|
||||
{
|
||||
if (--sipUaPortPtr->timer == 0)
|
||||
{
|
||||
//need forward develop send bye
|
||||
event_handle->recv_resp(usrPort, dialogId, SIP_METHOD_RESPONSE_TIMEOUT, NULL);
|
||||
// sipUaSaps[sapIndex].sipUaSap.recv_resp(usrPort, dialogId, SIP_METHOD_RESPONSE_TIMEOUT, NULL);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SIP_UA_INV_RSP_TERMINATED:
|
||||
if (sipUaPortPtr->timer > 0)
|
||||
{
|
||||
if (--sipUaPortPtr->timer == 0)
|
||||
{
|
||||
sip_ua_init_dialog(dialogId);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int sip_ua_non_inv_rsp_proc(WORD port)
|
||||
{
|
||||
WORD rvCmd;
|
||||
WORD sdCmd;
|
||||
SIP_UA_PORT *sipUaPortPtr;
|
||||
WORD sipTransId;
|
||||
SIP_API_STRUCT *sipApiMsg;
|
||||
|
||||
if (port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
sipUaPortPtr = &sipUaPort[port];
|
||||
rvCmd = sipUaPortPtr->rcvCmd;
|
||||
sdCmd = sipUaPortPtr->sdCmd;
|
||||
sipTransId = sipUaPortPtr->llPort;
|
||||
sipApiMsg = &sipUaPortPtr->sdSipMsg;
|
||||
|
||||
switch (sipUaPortPtr->state)
|
||||
{
|
||||
case SIP_UA_SEND_RESPONSE:
|
||||
if (sdCmd != SIP_UA_SEND_COM_NULL)
|
||||
{
|
||||
sipUaPortPtr->sdCmd = SIP_UA_SEND_COM_NULL;
|
||||
|
||||
sip_send_msg(sipTransId, port, SIP_TRANSACTION_LAYER, sipApiMsg);
|
||||
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sip_ua_fsm_request(WORD port)
|
||||
{
|
||||
switch (sipUaPort[port].mainState)
|
||||
{
|
||||
case SIP_UA_MAIN_STATE_INVITE_REQ:
|
||||
switch (sip_ua_inv_req_proc(port))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_INIT;
|
||||
sip_ua_fsm(port);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SIP_UA_MAIN_STATE_NON_INVITE_REQ:
|
||||
switch (sip_ua_non_inv_req_proc(port))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_INIT;
|
||||
sip_ua_fsm(port);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SIP_UA_MAIN_STATE_INIT:
|
||||
sip_ua_init_port(port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void sip_ua_fsm_indicate(WORD port)
|
||||
{
|
||||
switch (sipUaPort[port].mainState)
|
||||
{
|
||||
case SIP_UA_MAIN_STATE_IDLE:
|
||||
if (sipUaPort[port].sdCmd != 0)
|
||||
{
|
||||
if ((sipUaPort[port].rcvCmd == SIP_METHOD_INVITE) || (sipUaPort[port].rcvCmd == SIP_METHOD_RE_INVITE))
|
||||
{
|
||||
sipUaPort[port].rcvCmd = SIP_UA_RECV_COM_NULL;
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_INVITE_RSP;
|
||||
}
|
||||
else
|
||||
{
|
||||
sipUaPort[port].rcvCmd = SIP_UA_RECV_COM_NULL;
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_NON_INVITE_RSP;
|
||||
}
|
||||
sip_ua_fsm(port);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sipUaPort[port].sipuafTimer > 0)
|
||||
{
|
||||
if (--sipUaPort[port].sipuafTimer == 0)
|
||||
{
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_INIT;
|
||||
sip_ua_fsm(port);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SIP_UA_MAIN_STATE_INVITE_RSP:
|
||||
switch (sip_ua_inv_rsp_proc(port))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_INIT;
|
||||
sip_ua_fsm(port);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SIP_UA_MAIN_STATE_NON_INVITE_RSP:
|
||||
switch (sip_ua_non_inv_rsp_proc(port))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
sipUaPort[port].mainState = SIP_UA_MAIN_STATE_INIT;
|
||||
sip_ua_fsm(port);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SIP_UA_MAIN_STATE_INIT:
|
||||
sip_ua_init_port(port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void sip_ua_fsm(WORD port)
|
||||
{
|
||||
if (port >= SIP_UA_MAX_NUM_OF_PORT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch(sipUaPort[port].sipuafState)
|
||||
{
|
||||
case SIP_UA_FSM_STATE_REQUEST:
|
||||
sip_ua_fsm_request(port);
|
||||
break;
|
||||
case SIP_UA_FSM_STATE_INDICATE:
|
||||
sip_ua_fsm_indicate(port);
|
||||
break;
|
||||
default:
|
||||
sip_ua_init_port(port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
1022
plat/sip/src/sip_ua_msg.c
Normal file
1022
plat/sip/src/sip_ua_msg.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user