📄 stackcb.h
字号:
/******************************************************************************
Copyright(C) 2005,2006 Frank ZHANG
All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA.
******************************************************************************
* Authors : Frank ZHANG (openmgcp@gmail.com)
* Description : Define the structs of the control block of
* stack
*
*
* Date of creation : 08/02/2005
*
*
* History :
* 2005/08/02 Frank ZHANG : - Creation
******************************************************************************/
#ifndef __STACK_CB_H__
#define __STACK_CB_H__
#include "mgcpdef.h"
#include "protocalapi.h"
#ifdef __cplusplus
extern "C" {#endif
/********************************************************************
* MGCP Stack structure
********************************************************************/
typedef enum
{
STACK_STATE_CREATED = 1, /* Created but no in running */
STACK_STATE_RUNNING, /* Running */
STACK_STATE_TERMINATING, /* Being destroy */
STACK_STATE_DESTROY /* Being destroy */
} E_STACK_STATE;
typedef struct
{
/* MGCP version */
char *pcMgcpVersion;
/* MGCP profile name */
char *pcProfileName;
/* Stack state */
E_STACK_STATE eStackState;
/* Thread barrier used to synchronize all threads */
pthread_barrier_t pThreadBarrier;
/* Call back function to notify application magpc event */
CBK_MGCP_STACK pCbkNotfyApp;
/* Call back function to get connection parameters */
CBK_GET_CONNEC_PARAMS pCbkGetConnParams;
void *pEndpointCtl; /* H_MGCP_ENDPOINT_CONTROL */
void *pTransacMng; /* H_MGCP_TRANSAC_MANAGER */
} MGCP_STACK, *H_MGCP_STACK;
/********************************************************************
* Transaction manager structure
********************************************************************/
typedef struct
{
/* List of incoming mgcp commands currently being processed, only store the
* transaction ID; Add into list when receive the new Cmd and delete it
* after send Rsp */
SLIST CmdInProcessList;
WORD wLowWaterMark; /* Low mark bellow which send 100 response */
WORD wHighWaterMark; /* High mark over which send 101 response */
BOOL bQueueIsFull; /* Flag to inicate If the CmdInProcessList is
full, if full, send 101 response instead
100 response */
/* List of response sent out, store the whole message info; Add into list
* after sent out and delete when H-HIST timeout (TRANSAC_RSP_OUT type) */
SLIST RspSentList; /* Response without piggybacking */
SLIST RspSentPiggybackList; /* Response piggybacked with RSIP/NTFY */
/* List of response sent out and waiting ack, store the whole message info,
* retransmit if RTO timeout; Add into list after send and delete when H-HIST
* timeout or receive ack response; (TRANSAC_RSP_WAIT_ACK type) */
SLIST RspSentWaitAckList; /* Response waiting ack */
SLIST RspSentPiggyWaitAckList; /* Response piggybacked with RSIP/NTFY and
waiting ack */
/* List of Sent out response and acked, only store the transaction id; Add
* into list when receive ack response and delete when H-HIST timeout after
* Rsp issued; (TRANSAC_RSP_ACKED type) */
SLIST RspAckReceivedList;
/* List of Command sent out, store the whole message info; Add into list
* after sent and delete when Rsp received or wait Rsp timeout;
(TRANSAC_CMD_OUT type) */
SLIST CmdSentList; /* Commands without piggybacking */
SLIST CmdSentPiggybackList; /* Commands piggybacking */
/* List of outgoing ack-response, only store the transaction ID and time
* duration; Add into list after this Ack-response is sent out; delete after
* H-HIST timeout; (TRANSAC_RSPACK_OUT type) */
SLIST AckRspSentList;
} MGCP_MSG_LIST;
typedef struct
{
DWORD TimerID; /* Timer ID used to send periodically TO message */
WORD wTimerInterval; /* Tick interval */
} MGCP_TIMER;
typedef struct
{
/* The stack handle */
H_MGCP_STACK pStack;
/* Message Rx/Tx threads */
pthread_t MsgRxThread;
pthread_t MsgTxThread;
/* Mutex used for access this control block*/
pthread_mutex_t pTranMngMutex;
/* Message queue used for message Rx/Tx thread */
mqd_t MsgQueue;
/* Timer for Tx task */
MGCP_TIMER TickTimer; /* Timer used to send periodically timeout message */
/* Local Network Info */
DWORD dwLocalIpAddr; /* IP addres of the MG */
WORD wLocalPort; /* MGCP port of the MG, default is 2427 */
int iSocket_fd; /* Socket file descriptor */
char *pcDomainName; /* Domain name of the MG */
/* Current output message transaction Id, increment after
each new command sent out */
DWORD dwTransactionId;
/* Timer and counter value for retransmission */
WORD wCounterMax1; /* Threshold of current CA is unreachable, default is 5 */
WORD wCounterMax2; /* Threshold of all CA are unavailable,default is 7 */
DWORD dwTimerMaxRTO; /* Max value of RTO,default is 4s */ // RTO : retransmission timer
DWORD dwTimerInitRTO; /* Initial value of RTO,default is 200ms */
DWORD dwTimerMax; /* Retransmission cease threshold,default is 20s */
DWORD dwTimerHIST; /* The duration response retained after send, and
also used to determine disconnected threshold,
default is 30s */
DWORD dwTimerLongTR; /* RTO value if provision response received, default is 5s */
/* Message validation flag */
BOOL bCheckDomainName; /* Whether need check the Endpoint domain name
validation in the incoming mgcp command */
/* Configuration of DNS lookup for a new call-agent address when
* the suspicion threshold value is reached (Cisco feature) */
BOOL bMax1LookUp; /* If NDS lookup when max1 reached, default is true */
BOOL bMax2LookUp; /* If NDS lookup when max2 reached, default is true */
/* Flag to indicate if use three way handshake */
BOOL bUseThreeWayHandShake;
/* Flag to indicate if use provisional response procedure */
BOOL bUseProvisionalRspProcedure;
/* (Incoming/outgoing) MGCP messages list */
MGCP_MSG_LIST MsgList;
} MGCP_TRANSACTION_MANAGER, *H_MGCP_TRANSAC_MANAGER;
/* Endpoint state */
typedef enum
{
SM_INIT = 1, /* Power up and wait RSIP procedure */
SM_RESTART, /* Sent a RSIP and waiting response */
SM_RESTART_NOTIFY, /* Sent a piggybacked NTFY in RSIP prodefure */
SM_RESTART_WAIT_CMD, /* Receive pemanant error response to RSIP and
wait incoming command to trigger a new RSIP
procedure */
SM_NORMAL, /* Normal state, no message in process */
SM_NOTIFY, /* Sent a NTFY command and waiting response */
SM_NOTIFY_PIGGYBACK, /* Receive a RQNT in NOTIFY state */
SM_STEP_LOCK, /* Step locak state, waiting new RQNT */
SM_WAIT_DISCONNECTED, /* Wait Disconnected procedure */
SM_DISCONNECTED, /* Disconnected procedure started */
SM_DISCONNECTED_WAIT_CMD /* Receive permanent error rsponse in disconnected
procedure */
} E_ENDPOINT_STATE;
/* Endpoint tree */
typedef struct
{
SLIST Root; /* Endpoint tree root */
} MGCP_ENDPOINT_TREE;
typedef struct
{
SLIST PendingCrcxList; /* MGCP_PENDING_CONNEC_CMD type */
SLIST PendingMdcxList; /* MGCP_PENDING_CONNEC_CMD */
} MGCP_PENDING_CMDSIN;
typedef struct
{
/* The endpoint control handle */
void *pEndpointCtrl;
/* CallBack function to check the validity of the signal */
CBK_SIG_CHECK pCbkSigCheck;
/* Endpoint name, only the local name, no domain name */
char *pcEndpointName;
/* Current state of SM */
E_ENDPOINT_STATE eState;
/* Current service state */
BOOL bInService; /* True: in-service, False: out-of-service*/
/* Network round trip delay to current NE */
LONG lAverAckDelay; /* Average acknowledgement delay */
LONG lAverDeviation; /* Average deviation */
/* Command IDs of outgoing command (RSIP/NTFY) that wait response and need
to be piggybacked */
SLIST PendingCmdOutList;
/* Notified entity info */
BOOL bNotifiedEntityProvided; /* If the NE has been provided by CA */
NOTIFIED_ENTITY NotifiedEntity;
/* Hook states, used for race conditions check */
BOOL bOnHookState; /* True: on-hook, False: off-hook */
/* Endpoint capability */
MGCP_CAPABILITIES CapabilityList; /* Capabilities this endpoint can support */
/* Pending command list */
MGCP_PENDING_CMDSIN PendingCmdsIn; /* Incoming MGCP Cmds(CRCX/MDCX/DLCX)
waiting response from application
(MGCP_PENDING_CMDSIN type) */
/* Quarantine handling parameter */
BOOL bQuarantineProcess; /* True: process, False: discard */
BOOL bQuarantineLoop; /* True: loop, False: Step handling */
/* Persistent event list */
SLIST PerSistentEvents; /* MGCP_PERSIS_EVENT type */
/* Requested event/signal */
char *pcRequestedID; /* Current requested identifier */
MGCP_DIGIT_MAP DigitMap; /* Current digit map provided by CA */
/* Current accumulated dial string */
char *pcDialString;
SLIST RequestedEvents; /* Current requested events, (MGCP_REQUESTED_EVENT type) */
SLIST DetectEvents; /* Current detect events, MGCP_DETECT_EVENT */
SLIST RequestedSignals; /* Current Signal Request
(MGCP_SIGNAL type), only store the TO type */
/* Observed Events */
SLIST ObservedEvents; /* Observed event list, (MGCP_OBSERVED_EVENT type) */
SLIST QuarantinedEvents; /* Quarantined event list, (MGCP_OBSERVED_EVENT type) */
SLIST BuffedCmdInDisconected; /* The command buffer used when need send
command out in disconnected procedure,
MGCP_BUF_CMD type */
/* Call list */
SLIST CallList; /* MGCP_CALL type */
DWORD dwCurConnecID; /* Current connection ID used, increment after
one new connection is created; also be used
when connecion ID is "$" wildcard, expand the
"$" to be this connection ID */
/* Timer used for RSIP */
DWORD dwRestartWaitDelay; /* Restart waiting delay */
DWORD dwDisconWaitDelay; /* Disconnected waiting delay */
DWORD dwLastDisconWaitDelay; /* Disconnected waiting delay used currently */
/* Last RSIP information, used for AUEP response */
RESTART_METHOD RestartMethod;
DWORD dwRestartDelay;
WORD wReasonCode; /* The reason code in the last RSIP or DLCX
command issued by the endpoint,if the
endpoint's state is normal used the special
value 000 */
BEARER_INFO BearerInfo; /* The value of the last received Bearer Info
parameter (this includes the case where
Bearer Info was provisioned) */
} MGCP_ENDPOINT, *H_MGCP_ENDPOINT;
/* Endpoint tree node */
typedef struct
{
char *TreeNodeName; /* Name of this node */
H_MGCP_ENDPOINT pEndpoint; /* Handle of the endpoint of this node */
SLIST SubNodeList; /* Sub nodes of this node */
} MGCP_ENDPOINT_TREE_NODE;
typedef struct
{
/* The stack handle */
H_MGCP_STACK pStack;
/* Thread info */
pthread_t EndpointCtrlThread;
/* Mutex to protect this control block */
pthread_mutex_t pEndpoinCtrltMutex;
/* Message queue of endpoint control thread */
mqd_t MsgQueue;
/* Command ID currently used */
DWORD dwCommandID;
/* Timer for endpoint control */
MGCP_TIMER TickTimer; /* Timer used for periodical timeout message */
/* List store handle of all endpoints registered */
SLIST EndpointList;
/* Endpoint tree info */
MGCP_ENDPOINT_TREE EndpointTree; /* Registered endpoints tress */
/* Restart/Disconnect procedure parameter */
DWORD dwMWD; /* Restart maximum waiting delay, default 600s */
DWORD dwTdinit; /* Disconnected initial waiting delay, default 15s */
DWORD dwTdmin; /* Disconnected minimum waiting delay, default 15s */
DWORD dwTdmax; /* Disconnected maximum waiting delay, default 600s */
/* Flag to indicate if contain the supported packages in the response
* whose return code is 518 (unsupported package) */
BOOL bReturnPackageList;
} MGCP_ENDPOINT_CONTROL, *H_MGCP_ENDPOINT_CONTROL;
/*********************************************************************
* MGCP message used in message list
*********************************************************************/
/* Message data of outgoing command message from EndpointCtrl to TranacManager */
#define MAX_PIGGY_MSG_NUM 10 /* Maximum command number can be piggybacked,
if the outgoing piggyback command number
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -