init ems server code

This commit is contained in:
2024-09-27 15:39:34 +08:00
parent 9d4009aaca
commit 9930e4e58f
1551 changed files with 110216 additions and 102864 deletions

View File

@@ -0,0 +1,88 @@
#ifndef _M2UA__H
#define _M2UA__H
typedef struct _m2ua_up_msg
{
BYTE link __attribute__((packed));
BYTE len __attribute__((packed));
BYTE sio __attribute__((packed));
union
{
struct
{
BYTE content[256] __attribute__((packed));
}mtp3 __attribute__((packed));
struct
{
BYTE mtp3_ip __attribute__((packed));
BYTE opercode __attribute__((packed));
BYTE alarmcode __attribute__((packed));
}lm __attribute__((packed));
}msg __attribute__((packed));
}m2ua_up_msg_t;
void m2ua_init(BYTE);
void m2ua_timer(void);
int get_m2ua_msg(m2ua_up_msg_t **data_ptr);
int put_m2ua_msg(m2ua_up_msg_t *data_ptr);
int set_m2ua_link(BYTE link, BYTE *data_ptr);
int set_m2ua_sg(WORD sg, BYTE *data_ptr);
int m2ua_restart();
//add by yizane
typedef struct _xua_lm_lk
{
BYTE link __attribute__((packed));
BYTE len __attribute__((packed)); /* len = 3 */
BYTE mtp3_ip __attribute__((packed));
BYTE opercode __attribute__((packed));
BYTE alarmcode __attribute__((packed));
}xua_lm_lk;
typedef struct _xua_iua_msg
{
BYTE link __attribute__((packed));
BYTE len __attribute__((packed)); /* len for content */
BYTE content[256] __attribute__((packed));
}xua_iua_msg;
typedef struct _xua_m2ua_msg
{
BYTE link __attribute__((packed));
BYTE len __attribute__((packed)); /* len for content */
BYTE content[256] __attribute__((packed));
}xua_m2ua_msg;
typedef struct _xua_up_msg
{
BYTE msg_class __attribute__((packed));
union
{
xua_lm_lk lm_lk __attribute__((packed));
xua_m2ua_msg m2ua __attribute__((packed));
xua_iua_msg iua __attribute__((packed));
}msg __attribute__((packed));
}xua_up_msg_t;
int get_xua_msg(BYTE xUA_type, xua_up_msg_t **data_ptr);
int put_xua_msg(xua_up_msg_t *data_ptr);
#define XUAHEADOFFSET 3
#define RESERVE_FOR_IUAHEAD (28 - XUAHEADOFFSET)
#define RESERVE_FOR_M2UAHEAD (20 - XUAHEADOFFSET)
//msg_class
#define IUA_QPTM_MSG 0x05
#define M2UA_MAUP_MSG 0x06
#define IUA_MGMT_CMD 0xA5
#define M2UA_MGMT_CMD 0xA6
#define IUA_APP 1
#define M2UA_APP 0
//add by yizane
#endif

View File

@@ -0,0 +1,330 @@
#ifndef _M2UA_CONST__H
#define _M2UA_CONST__H
#define M2UA_MAX_LK_NUM 256
#define M2UA_MAX_MSG_LEN 256
#define M2UA_MAX_SG_NUM 512
#define M2UA_LISTEN_SG_NUM_0 512
#define IUA_LISTEN_SG_NUM_0 513
#define IUA_PORT_0 9900
#define M2UA_PORT_0 2904
#define M2UA_LISTEN_SG_NUM_1 514
#define IUA_LISTEN_SG_NUM_1 515
#define IUA_PORT_1 9901
#define M2UA_PORT_1 2905
#define M2UA_MAX_SG_FSM_NUM (512+4)//for listen m2ua*2,iua*2
#define M2UA_MAX_M3MSG_NUM 2048
#define M2UA_MAX_M3MSG_NUM_1 2047
#define M2UA_SCTP_CMD_BUFSIZE 5*1024
#define M2UA_SCTP_DAT_BUFSIZE 5*1024
#define M2UA_FAILURE -1
#define M2UA_SUCCESS 0
#define M2UA_CMD_IDLEW 0xEEEE
// M2UA Message Class
#define M2UA_MCLASS_MGMT 0
#define M2UA_MCLASS_ASPSM 3
#define M2UA_MCLASS_ASPTM 4
#define M2UA_MCLASS_MAUP 6
#define M2UA_MCLASS_IIM 10
//add by yizane
#define xUA_MCLASS_MGMT 0
#define xUA_MCLASS_TRMSG 1
#define xUA_MCLASS_SSNM 2
#define xUA_MCLASS_ASPSM 3
#define xUA_MCLASS_ASPTM 4
#define xUA_MCLASS_QPTM 5
#define xUA_MCLASS_MAUP 6
#define xUA_MCLASS_IIM 10
//add by yizane
// M2UA ASPSM Message Type
#define ASP_UP 1
#define ASP_DOWN 2
#define HEARTBEAT 3
#define ASP_UP_ACK 4
#define ASP_DOWN_ACK 5
#define HEARTBEAT_ACK 6
// M2UA ASPSM Combined Message Type
#define M2UA_ASPSM_ASP_UP (M2UA_MCLASS_ASPSM << 8) + ASP_UP
#define M2UA_ASPSM_ASP_DOWN (M2UA_MCLASS_ASPSM << 8) + ASP_DOWN
#define M2UA_ASPSM_HEARTBEAT (M2UA_MCLASS_ASPSM << 8) + HEARTBEAT
#define M2UA_ASPSM_ASP_UP_ACK (M2UA_MCLASS_ASPSM << 8) + ASP_UP_ACK
#define M2UA_ASPSM_ASP_DOWN_ACK (M2UA_MCLASS_ASPSM << 8) + ASP_DOWN_ACK
#define M2UA_ASPSM_HEARTBEAT_ACK (M2UA_MCLASS_ASPSM << 8) + HEARTBEAT_ACK
//add by yizane
#define xUA_ASPSM_ASP_UP (xUA_MCLASS_ASPSM << 8) + ASP_UP
#define xUA_ASPSM_ASP_DOWN (xUA_MCLASS_ASPSM << 8) + ASP_DOWN
#define xUA_ASPSM_HEARTBEAT (xUA_MCLASS_ASPSM << 8) + HEARTBEAT
#define xUA_ASPSM_ASP_UP_ACK (xUA_MCLASS_ASPSM << 8) + ASP_UP_ACK
#define xUA_ASPSM_ASP_DOWN_ACK (xUA_MCLASS_ASPSM << 8) + ASP_DOWN_ACK
#define xUA_ASPSM_HEARTBEAT_ACK (xUA_MCLASS_ASPSM << 8) + HEARTBEAT_ACK
//add by yizane
#define ASP_ACTIVE 1
#define ASP_INACTIVE 2
#define ASP_ACTIVE_ACK 3
#define ASP_INACTIVE_ACK 4
#define M2UA_ASPTM_ASP_ACTIVE (M2UA_MCLASS_ASPTM << 8) + ASP_ACTIVE
#define M2UA_ASPTM_ASP_INACTIVE (M2UA_MCLASS_ASPTM << 8) + ASP_INACTIVE
#define M2UA_ASPTM_ASP_ACTIVE_ACK (M2UA_MCLASS_ASPTM << 8) + ASP_ACTIVE_ACK
#define M2UA_ASPTM_ASP_INACTIVE_ACK (M2UA_MCLASS_ASPTM << 8) + ASP_INACTIVE_ACK
//add by yizane
#define xUA_ASPTM_ASP_ACTIVE (xUA_MCLASS_ASPTM << 8) + ASP_ACTIVE
#define xUA_ASPTM_ASP_INACTIVE (xUA_MCLASS_ASPTM << 8) + ASP_INACTIVE
#define xUA_ASPTM_ASP_ACTIVE_ACK (xUA_MCLASS_ASPTM << 8) + ASP_ACTIVE_ACK
#define xUA_ASPTM_ASP_INACTIVE_ACK (xUA_MCLASS_ASPTM << 8) + ASP_INACTIVE_ACK
//add by yizane
//for MAUP
#define DATA 1
#define ESTABLISH_REQ 2
#define ESTABLISH_CFM 3
#define RELEASE_REQ 4
#define RELEASE_CFM 5
#define RELEASE_IND 6
#define STATE_REQ 7
#define STATE_CFM 8
#define STATE_IND 9
#define DATA_RETIEVE_REQ 10
#define DATA_RETIEVE_CFM 11
#define DATA_RETIEVE_IND 12
#define DATA_RETIEVE_CMP 13
#define CONGESTION_IND 14
#define DATA_ACK 15
#define M2UA_MAUP_DATA (M2UA_MCLASS_MAUP << 8) + DATA
#define M2UA_MAUP_ESTABLISH_REQ (M2UA_MCLASS_MAUP << 8) + ESTABLISH_REQ
#define M2UA_MAUP_ESTABLISH_CFM (M2UA_MCLASS_MAUP << 8) + ESTABLISH_CFM
#define M2UA_MAUP_RELEASE_REQ (M2UA_MCLASS_MAUP << 8) + RELEASE_REQ
#define M2UA_MAUP_RELEASE_CFM (M2UA_MCLASS_MAUP << 8) + RELEASE_CFM
#define M2UA_MAUP_RELEASE_IND (M2UA_MCLASS_MAUP << 8) + RELEASE_IND
#define M2UA_MAUP_STATE_REQ (M2UA_MCLASS_MAUP << 8) + STATE_REQ
#define M2UA_MAUP_STATE_CFM (M2UA_MCLASS_MAUP << 8) + STATE_CFM
#define M2UA_MAUP_STATE_IND (M2UA_MCLASS_MAUP << 8) + STATE_IND
#define M2UA_MAUP_DATA_RETIEVE_REQ (M2UA_MCLASS_MAUP << 8) + DATA_RETIEVE_REQ
#define M2UA_MAUP_DATA_RETIEVE_CFM (M2UA_MCLASS_MAUP << 8) + DATA_RETIEVE_CFM
#define M2UA_MAUP_DATA_RETIEVE_IND (M2UA_MCLASS_MAUP << 8) + DATA_RETIEVE_IND
#define M2UA_MAUP_DATA_RETIEVE_CMP (M2UA_MCLASS_MAUP << 8) + DATA_RETIEVE_CMP
#define M2UA_MAUP_CONGESTION_IND (M2UA_MCLASS_MAUP << 8) + CONGESTION_IND
#define M2UA_MAUP_DATA_ACK (M2UA_MCLASS_MAUP << 8) + DATA_ACK
//add by yizane
//for QPTM
#define IUA_DATA_REQ 1
#define IUA_DATA_IND 2
#define IUA_UDATA_REQ 3
#define IUA_UDATA_IND 4
#define IUA_ESTABLISH_REQ 5
#define IUA_ESTABLISH_CFM 6
#define IUA_ESTABLISH_IND 7
#define IUA_RELEASE_REQ 8
#define IUA_RELEASE_CFM 9
#define IUA_RELEASE_IND 10
#define IUA_QPTM_DATA_REQ (xUA_MCLASS_QPTM << 8) + IUA_DATA_REQ
#define IUA_QPTM_DATA_IND (xUA_MCLASS_QPTM << 8) + IUA_DATA_IND
#define IUA_QPTM_UDATA_REQ (xUA_MCLASS_QPTM << 8) + IUA_UDATA_REQ
#define IUA_QPTM_UDATA_IND (xUA_MCLASS_QPTM << 8) + IUA_UDATA_IND
#define IUA_QPTM_ESTABLISH_REQ (xUA_MCLASS_QPTM << 8) + IUA_ESTABLISH_REQ
#define IUA_QPTM_ESTABLISH_CFM (xUA_MCLASS_QPTM << 8) + IUA_ESTABLISH_CFM
#define IUA_QPTM_ESTABLISH_IND (xUA_MCLASS_QPTM << 8) + IUA_ESTABLISH_IND
#define IUA_QPTM_RELEASE_REQ (xUA_MCLASS_QPTM << 8) + IUA_RELEASE_REQ
#define IUA_QPTM_RELEASE_CFM (xUA_MCLASS_QPTM << 8) + IUA_RELEASE_CFM
#define IUA_QPTM_RELEASE_IND (xUA_MCLASS_QPTM << 8) + IUA_RELEASE_IND
//add by yizane
#define ERROR 0
#define NOTIFY 1
//add by yizane
#define TEI_S_REQ 2
#define TEI_S_CFM 3
#define TEI_S_IND 4
//add by yizane
#define M2UA_MGMT_ERROR (M2UA_MCLASS_MGMT << 8) + ERROR
#define M2UA_MGMT_NOTIFY (M2UA_MCLASS_MGMT << 8) + NOTIFY
//add by yizane
#define xUA_MGMT_ERROR (xUA_MCLASS_MGMT << 8) + ERROR
#define xUA_MGMT_NOTIFY (xUA_MCLASS_MGMT << 8) + NOTIFY
#define xUA_MGMT_TEI_S_REQ (xUA_MCLASS_MGMT << 8) + TEI_S_REQ
#define xUA_MGMT_TEI_S_CFM (xUA_MCLASS_MGMT << 8) + TEI_S_CFM
#define xUA_MGMT_TEI_S_IND (xUA_MCLASS_MGMT << 8) + TEI_S_IND
//add by yizane
#define M2UA_IIM_REG_REQ 1
#define M2UA_IIM_REG_RSP 2
#define M2UA_IIM_DEREG_REQ 3
#define M2UA_IIM_DEREG_RSP 4
#define M2UA_PAR_INTERFACE_ID_INT 0x0001
#define M2UA_PAR_INTERFACE_ID_TXT 0x0003
#define M2UA_PAR_TRAFFIC_MODE 0x000B
#define M2UA_PAR_ASP_IDENTIFIER 0x0011
#define M2UA_PAR_PROTO_DATA_1 0x0300
#define M2UA_PAR_CORRELATION_ID 0x0013
#define M2UA_PAR_STATE 0x0302
#define M2UA_PAR_STATUS 0x000D
#define M2UA_PAR_ERR_CODE 0x000C
//add by yizane
#define xUA_PAR_DLCI 0x0005
#define xUA_PAR_PROTOCOL_DATA 0x000E
#define xUA_PAR_REL_REASON 0x000F
#define xUA_PAR_TEI_STATUS 0x0010
//add by yizane
#define M2UA_STATUS_LPO_SET 0x0
#define M2UA_STATUS_LPO_CLEAR 0x1
#define M2UA_STATUS_EMER_SET 0x2
#define M2UA_STATUS_EMER_CLEAR 0x3
#define M2UA_STATUS_FLUSH_BUFFERS 0x4
#define M2UA_STATUS_CONTINUE 0x5
#define M2UA_STATUS_CLEAR_RTB 0x6
#define M2UA_STATUS_AUDIT 0x7
#define M2UA_STATUS_CONG_CLEAR 0x8
#define M2UA_STATUS_CONG_ACCEPT 0x9
#define M2UA_STATUS_CONG_DISCARD 0xa
#define M2UA_STATUS_TYPE_AS_STATE_CHG 1
#define M2UA_STATUS_TYPE_OTHER 2
#define M2UA_STATUS_INFO_AS_RESERVED 1
#define M2UA_STATUS_INFO_AS_INACTIVE 2
#define M2UA_STATUS_INFO_AS_ACTIVE 3
#define M2UA_STATUS_INFO_AS_PENDING 4
#define M2UA_ERR_INVALID_VERSION 0x1
#define M2UA_ERR_INVALID_IID 0x2
#define M2UA_ERR_UNSUPPORTED_MSG_CLASS 0x3
#define M2UA_ERR_UNSUPPORTED_MSG_TYPE 0x4
#define M2UA_ERR_UNSUPPORTED_TRA_HDL_MODE 0x5
#define M2UA_ERR_UNEXPECTED_MSG 0x6
#define M2UA_ERR_PROTOCOL_ERROR 0x7
#define M2UA_ERR_UNSUPPORTED_IIT 0x8
#define M2UA_ERR_INVALID_SID 0x9
#define M2UA_ERR_REFUSED_MGMT_BLOCK 0xd
#define M2UA_ERR_ASP_ID_REQUIRED 0xe
#define M2UA_ERR_INVALID_ASP_ID 0xf
#define M2UA_ERR_ASP_ACTIVE_FOR_IID 0x10
#define M2UA_ERR_INVALID_PARA_VAL 0x11
#define M2UA_ERR_PARA_FIELD_ERROR 0x12
#define M2UA_ERR_UNEXPECTED_PARA 0x13
#define M2UA_ERR_MISSING_PARA 0x16
//add by yizane
#define IUA_TEI_ASSIGNED 0x0
#define IUA_TEI_UNASSIGNED 0x1
#define IUA_RELEASE_MGMT 0x00
#define IUA_RELEASE_PHYS 0x01
#define IUA_RELEASE_DM 0x02
#define IUA_RELEASE_OTHER 0x03
//add by yizane
#define M2UA_TRAFFIC_MODE_OVERRIDE 1
#define M2UA_TRAFFIC_MODE_LOADSHARE 2
#define M2UA_TRAFFIC_MODE_BROADCAST 3
#define M2UA_LK_IDLE 0
#define M2UA_LK_DOWN 1
#define M2UA_LK_UP 5
#define M2UA_LK_PO 6
#define M2UA_MCLASS_MTP3 1
#define M2UA_MCLASS_LM 2
#define M2UA_MTP3_SIO_CMD 0xFF
#define M2UA_SIO_CMD 0xEF
#define M2UA_MTP3_SIO_MSG 0x80
#define M2UA_LK_ATTR_SIGTRAN 1
#define M2UA_MTP3_MAX_LS_NUM 128
#define M2UA_MTP3_CMD_ACTIVE_LK 1
#define M2UA_MTP3_CMD_DEACTIVE_LK 2
#define M2UA_MTP3_CMD_STOP_L2 3
#define M2UA_MTP3_CMD_EMERG_ALIGN 4
#define M2UA_T_ACK 100 // 2 seconds = 100 * 20ms
#define M2UA_T_R 100 // 2 seconds
#define M2UA_T_LK_ESTAB 4 // 10 seconds = 4 * 2.56s
#define M2UA_T_SG_ESTAB_1 500 // 10 seconds
#define M2UA_T_SG_ESTAB_2 6000 // 120 seconds
#define M2UA_T_SG_ESTAB_3 1500 // 30 seconds
#define M2UA_T_SG_WAIT 100 // 2 seconds
#define M2UA_CMD_IDLE 0
#define M2UA_CMD_PARA_SAVE 1
#define M2UA_CMD_PARA_INIT 2
#define M2UA_CMD_STATUS_INIT 3
#define M2UA_MGMT_CMD_LK_LOCK 1
//add by yizane
#define IUA_MGMT_CMD_LK_LOCK 2
//add by yizane
#define MAX_ASCIIIN_LEN 4096
#define MAX_ASCIIOUT_LEN 4096
#define MAX_ASCITMP_LEN 4096
#define MONITOR_NONE 0x0000
#define MONITOR_MTP3 0x0001
#define MONITOR_M2UA 0x0002
#define MONITOR_MAUP 0x0004
#define MONITOR_SCTP 0x0008
#define MONITOR_ERROR 0x0010
#define MONITOR_ALL 0xffff
#define M2UA_MAX_RETRANS 10
#define M2UA_STOP_M2UA_LINK 6
#define M2UA_ENABLE_M2UA_LINK 7
//add by yizane
#define xUA_STOP_xUA_LINK 6
#define xUA_ENABLE_xUA_LINK 7
//add by yizane
#define M2UA_LKSCTP_ASSOC_CHANGE_COMM_UP ((SCTP_ASSOC_CHANGE << 16) | (SCTP_COMM_UP & 0xFFFF))
#define M2UA_LKSCTP_ASSOC_CHANGE_COMM_LOST ((SCTP_ASSOC_CHANGE << 16) | (SCTP_COMM_LOST & 0xFFFF))
#define M2UA_LKSCTP_ASSOC_CHANGE_SHUTDOWN_COMP ((SCTP_ASSOC_CHANGE << 16) | (SCTP_SHUTDOWN_COMP & 0xFFFF))
#define M2UA_LKSCTP_ASSOC_CHANGE_RESTART ((SCTP_ASSOC_CHANGE << 16) | (SCTP_RESTART & 0xFFFF))
#define M2UA_LKSCTP_ASSOC_CHANGE_CANT_STR_ASSOC ((SCTP_ASSOC_CHANGE << 16) | (SCTP_CANT_STR_ASSOC & 0xFFFF))
#define M2UA_LKSCTP_SEND_FAILED (SCTP_SEND_FAILED << 16)
#define M2UA_LKSCTP_PEER_ADDR_CHANGE (SCTP_PEER_ADDR_CHANGE << 16)
#define M2UA_LKSCTP_REMOTE_ERROR (SCTP_REMOTE_ERROR << 16)
#define M2UA_LKSCTP_SHUTDOWN_EVENT (SCTP_SHUTDOWN_EVENT << 16)
#define M2UA_LKSCTP_DATA_IND 0x7FFFFFFE
#define M2UA_LKSCTP_UNKNOWN_EVENT 0x7FFFFFFF
#define M2UA_ALARM_CODE_NORMAL 0
#define M2UA_ALARM_CODE_SCTP_FAILURE 1
#define M2UA_ALARM_CODE_REMOTE_AS_DOWN 2
#define M2UA_ALARM_CODE_REMOTE_LINK_RELEASE 3
#define M2UA_ALARM_CODE_LOCAL_MTP3_REQUEST_LINK_DOWN 4
#define M2UA_ALARM_CODE_LOCAL_SG_MAINTENANCE 5
#define M2UA_ALARM_CODE_LOCAL_LINK_MAINTENANCE 6
#endif

View File

@@ -0,0 +1,10 @@
#ifndef _M2UA_DEBUG__H
#define _M2UA_DEBUG__H
void m2ua_mon(void);
int m2ua_debug_set(void);
int m2ua_asciout_proc(BYTE *out_str);
int m2ua_hex_to_ascii(BYTE *from_hex, BYTE from_len, BYTE *to_asc);
int m2ua_log_err(WORD sg_id, BYTE *err_msg);
#endif

View File

@@ -0,0 +1,64 @@
#ifndef _M2UA_DEF__H
#define _M2UA_DEF__H
#include "m2ua_pub.h"
#include "m2ua.h"
#include "m2ua_const.h"
#include "m2ua_struct.h"
//const BYTE m2ua_ver[3] = {10, 0, 6};
BYTE m2ua_command = 0;
m2ua_sg_info_t m2ua_sg_info[M2UA_MAX_SG_FSM_NUM];//for listen m2ua*2,iua*2
m2ua_lk_info_t m2ua_lk_info[M2UA_MAX_LK_NUM];
m2ua_sctp_addr_t m2ua_sctp_addr;
m2ua_sctp_cmd_t m2ua_sctp_cmd;
BYTE m2ua_sctp_dat[M2UA_SCTP_DAT_BUFSIZE];
int m2ua_sctp_cmd_len;
int m2ua_sctp_dat_len;
#ifndef _LKSCTP
struct strbuf m2ua_sctp_ctrl = {M2UA_SCTP_CMD_BUFSIZE, 0, m2ua_sctp_cmd.cbuf};
struct strbuf m2ua_sctp_data = {M2UA_SCTP_DAT_BUFSIZE, 0, m2ua_sctp_dat};
#else
m2ua_sctp_data_t m2ua_sctp_data = {M2UA_SCTP_DAT_BUFSIZE, 0, m2ua_sctp_dat};
#endif
m2ua_para_t m2ua_para;
BYTE m2ua_mtp3_sd[M2UA_MAX_MSG_LEN * M2UA_MAX_M3MSG_NUM];
WORD m2ua_mtp3_sd_h;
WORD m2ua_mtp3_sd_t;
//add by yizane
BYTE iua_q931_sd[M2UA_MAX_MSG_LEN * M2UA_MAX_M3MSG_NUM];
WORD iua_q931_sd_h;
WORD iua_q931_sd_t;
//add by yizane
DWORD x256[M2UA_MAX_M3MSG_NUM];
char hostip[20];
char hostname[50];
DWORD host_ip;
BYTE plat_id;
m2ua_sctp_addr_t m2ua_sctp_server_addr;
m2ua_csta_t m2ua_csta;
BYTE m2ua_asciin_buf[MAX_ASCIIIN_LEN];
BYTE m2ua_asciout_buf[MAX_ASCIIOUT_LEN];
BYTE m2ua_ascitemp_buf[MAX_ASCITMP_LEN];
WORD moniter_fg;
BYTE m2ua_sg_mon_fg[M2UA_MAX_SG_FSM_NUM];
BYTE m2ua_lk_mon_fg[M2UA_MAX_LK_NUM];
WORD m2ua_sg_mon_count;
WORD m2ua_lk_mon_count;
DWORD err[64];
BYTE init_flag;
#endif

View File

@@ -0,0 +1,64 @@
#ifndef _M2UA_EXT__H
#define _M2UA_EXT__H
#include "m2ua_pub.h"
#include "m2ua.h"
#include "m2ua_const.h"
#include "m2ua_struct.h"
//extern const BYTE m2ua_ver[3];
extern BYTE m2ua_command;
extern m2ua_sg_info_t m2ua_sg_info[M2UA_MAX_SG_FSM_NUM];
extern m2ua_lk_info_t m2ua_lk_info[M2UA_MAX_LK_NUM];
extern m2ua_sctp_addr_t m2ua_sctp_addr;
extern m2ua_sctp_cmd_t m2ua_sctp_cmd;
extern BYTE m2ua_sctp_dat[M2UA_SCTP_DAT_BUFSIZE];
extern int m2ua_sctp_cmd_len;
extern int m2ua_sctp_dat_len;
#ifndef _LKSCTP
extern struct strbuf m2ua_sctp_ctrl;
extern struct strbuf m2ua_sctp_data;
#else
extern m2ua_sctp_data_t m2ua_sctp_data;
#endif
extern m2ua_para_t m2ua_para;
extern BYTE m2ua_mtp3_sd[M2UA_MAX_MSG_LEN * M2UA_MAX_M3MSG_NUM];
extern WORD m2ua_mtp3_sd_h;
extern WORD m2ua_mtp3_sd_t;
//add by yizane
extern BYTE iua_q931_sd[M2UA_MAX_MSG_LEN * M2UA_MAX_M3MSG_NUM];
extern WORD iua_q931_sd_h;
extern WORD iua_q931_sd_t;
//add by yizane
extern DWORD x256[M2UA_MAX_M3MSG_NUM];
extern char hostip[20];
extern char hostname[50];
extern DWORD host_ip;
extern BYTE plat_id;
extern m2ua_sctp_addr_t m2ua_sctp_server_addr;
extern m2ua_csta_t m2ua_csta;
extern BYTE m2ua_asciin_buf[MAX_ASCIIIN_LEN];
extern BYTE m2ua_asciout_buf[MAX_ASCIIOUT_LEN];
extern BYTE m2ua_ascitemp_buf[MAX_ASCITMP_LEN];
extern WORD moniter_fg;
extern BYTE m2ua_sg_mon_fg[M2UA_MAX_SG_FSM_NUM];
extern BYTE m2ua_lk_mon_fg[M2UA_MAX_LK_NUM];
extern WORD m2ua_sg_mon_count;
extern WORD m2ua_lk_mon_count;
extern DWORD err[64];
extern BYTE init_flag;
#endif

View File

@@ -0,0 +1,9 @@
#ifndef _M2UA_FSM__H
#define _M2UA_FSM__H
int m2ua_sg_fsm(WORD sg_id);
int m2ua_fsm(WORD sg_id);
int rel_sid(WORD sg, BYTE lk);
#endif

View File

@@ -0,0 +1,53 @@
#ifndef _M2UA_MSG__H
#define _M2UA_MSG__H
#define COMBO_W(par_class,par_type) ((par_class << 8) + par_type)
int m2ua_sctp_close(int fd, WORD sg_id);
int m2ua_dec_msg(WORD sg_id);
int m2ua_send_msg(WORD sg_id, WORD msg);
int m2ua_sd_mtp3_primi(BYTE lk, BYTE primi);
int m2ua_sd_mtp3_msg(WORD sg, BYTE lk);
//add by yizane
int iua_sd_q931_primi(BYTE lk, BYTE primi);
int iua_sd_q931_msg(WORD sg, BYTE lk);
//add by yizane
int m2ua_sg_init(WORD id);
int m2ua_lk_init(BYTE id);
int enable_sg(WORD sg);
int rm_sg_lk(WORD sg, BYTE lk);
char *dec_sctp_primi(long sctp_primi);
#ifndef _LKSCTP
int m2ua_sctp_t_open(WORD sg);
int expect(int fd, int sg, int *msg, int want);
int m2ua_sctp_optmgmt_req(int fd, int sg, DWORD flags);
int m2ua_sctp_bind_req(int fd, int sg, m2ua_sctp_addr_t *addr, int coninds);
int m2ua_sctp_conn_res(int fd, int fd2, int sg, long seq);
int m2ua_sctp_ordrel_req(int fd, int sg);
int m2ua_sctp_discon_req(int fd, int sg, DWORD seq);
int m2ua_sctp_conn_req(int fd, int sg, m2ua_sctp_addr_t *addr);
int m2ua_sctp_optdata_req(int fd, int sg, BYTE len);
#else
int m2ua_sctp_optmgmt_req_lksctp(int fd, int sg);
int m2ua_sctp_optmgmt_req_lksctp_ext(int fd, int sg);
int m2ua_sctp_bind_req_lksctp(int fd, int sg, m2ua_sctp_addr_t *addr, int coninds);
int m2ua_sctp_open_lksctp(WORD sg);
int m2ua_sctp_conn_req_lksctp(int fd, int sg, m2ua_sctp_addr_t *addr);
int m2ua_sctp_get_msg_lksctp(int fd, WORD sg);
int expect_lksctp(int fd, int sg, int *msg, int want);
int m2ua_sctp_discon_req_lksctp(int fd, int sg, int flag);
int m2ua_sctp_put_msg_lksctp(int fd, int sg);
int m2ua_sctp_optdata_req_lksctp(int fd, int sg, int len);
#endif
#endif

View File

@@ -0,0 +1,63 @@
#ifndef _M2UA_PUB__H
#define _M2UA_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>
#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 _LKSCTP
#include <sys/tpi.h>
#include <sys/tpi_sctp.h>
#include <sys/xti_ip.h>
#include <sys/xti_sctp.h>
#else
#include <netinet/sctp.h>
#endif
#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

View File

@@ -0,0 +1,240 @@
#ifndef _M2UA_STRUCT__H
#define _M2UA_STRUCT__H
#include "m2ua_const.h"
#ifndef _LKSCTP
typedef union _m2ua_sctp_cmd
{
union T_primitives tpi;
BYTE cbuf[M2UA_SCTP_CMD_BUFSIZE];
}m2ua_sctp_cmd_t;
// Data Options
typedef struct _m2ua_sctp_opt_data
{
struct t_opthdr sid_hdr __attribute__((packed));
t_scalar_t sid_val __attribute__((packed));
}m2ua_sctp_opt_data_t;
// Connect Options
typedef struct _m2ua_sctp_opt_conn
{
struct t_opthdr ist_hdr __attribute__((packed));
t_scalar_t ist_val __attribute__((packed));
struct t_opthdr ost_hdr __attribute__((packed));
t_scalar_t ost_val __attribute__((packed));
}m2ua_sctp_opt_conn_t;
// Management Options
typedef struct _m2ua_sctp_opt_optm
{
struct t_opthdr nod_hdr __attribute__((packed));
t_scalar_t nod_val __attribute__((packed));
struct t_opthdr crk_hdr __attribute__((packed));
t_scalar_t crk_val __attribute__((packed));
struct t_opthdr ppi_hdr __attribute__((packed));
t_scalar_t ppi_val __attribute__((packed));
struct t_opthdr sid_hdr __attribute__((packed));
t_scalar_t sid_val __attribute__((packed));
struct t_opthdr rcv_hdr __attribute__((packed));
t_scalar_t rcv_val __attribute__((packed));
struct t_opthdr ckl_hdr __attribute__((packed));
t_scalar_t ckl_val __attribute__((packed));
struct t_opthdr skd_hdr __attribute__((packed));
t_scalar_t skd_val __attribute__((packed));
struct t_opthdr prt_hdr __attribute__((packed));
t_scalar_t prt_val __attribute__((packed));
struct t_opthdr art_hdr __attribute__((packed));
t_scalar_t art_val __attribute__((packed));
struct t_opthdr irt_hdr __attribute__((packed));
t_scalar_t irt_val __attribute__((packed));
struct t_opthdr hbi_hdr __attribute__((packed));
t_scalar_t hbi_val __attribute__((packed));
struct t_opthdr rin_hdr __attribute__((packed));
t_scalar_t rin_val __attribute__((packed));
struct t_opthdr rmn_hdr __attribute__((packed));
t_scalar_t rmn_val __attribute__((packed));
struct t_opthdr rmx_hdr __attribute__((packed));
t_scalar_t rmx_val __attribute__((packed));
struct t_opthdr ist_hdr __attribute__((packed));
t_scalar_t ist_val __attribute__((packed));
struct t_opthdr ost_hdr __attribute__((packed));
t_scalar_t ost_val __attribute__((packed));
struct t_opthdr cin_hdr __attribute__((packed));
t_scalar_t cin_val __attribute__((packed));
struct t_opthdr tin_hdr __attribute__((packed));
t_scalar_t tin_val __attribute__((packed));
struct t_opthdr mac_hdr __attribute__((packed));
t_scalar_t mac_val __attribute__((packed));
struct t_opthdr dbg_hdr __attribute__((packed));
t_scalar_t dbg_val __attribute__((packed));
}m2ua_sctp_opt_optm_t;
#else
typedef union _m2ua_sctp_cmd
{
struct cmsghdr cmsg __attribute__((packed));
BYTE cbuf[M2UA_SCTP_CMD_BUFSIZE] __attribute__((packed));
}m2ua_sctp_cmd_t;
typedef struct _m2ua_sctp_data
{
int len __attribute__((packed));
int sid __attribute__((packed));
BYTE *buf __attribute__((packed));
}m2ua_sctp_data_t;
#endif
typedef struct _m2ua_sctp_addr
{
uint16_t port __attribute__((packed));
struct in_addr addr __attribute__((packed));
}m2ua_sctp_addr_t;
typedef struct _m2ua_lk_info
{
BYTE enable __attribute__((packed));
BYTE lk_st __attribute__((packed));
WORD sid __attribute__((packed));
DWORD lk_timer __attribute__((packed));
BYTE alarm_code __attribute__((packed));
BYTE lk_act __attribute__((packed));
}m2ua_lk_info_t;
typedef struct _m2ua_sg_info
{
BYTE enable __attribute__((packed));
BYTE sctp_state __attribute__((packed));
BYTE sctp_state_1 __attribute__((packed));
BYTE m2ua_state __attribute__((packed));
DWORD sctp_cmd __attribute__((packed));
WORD m2ua_cmd __attribute__((packed));
WORD mtp3_cmd __attribute__((packed));
WORD mgmt_cmd __attribute__((packed));
WORD fd __attribute__((packed));
WORD iid __attribute__((packed));
DWORD sid_st[8] __attribute__((packed));
BYTE *msg __attribute__((packed));
WORD msg_len __attribute__((packed));
WORD rem_ostrs __attribute__((packed));
WORD T_ack __attribute__((packed));
WORD T_r __attribute__((packed));
BYTE con_sg __attribute__((packed));
BYTE state __attribute__((packed));
BYTE err_code __attribute__((packed));
BYTE tra_hdl_mode __attribute__((packed));
WORD act_lks __attribute__((packed));
WORD istrs __attribute__((packed));
WORD ostrs __attribute__((packed));
DWORD status __attribute__((packed));
DWORD seq __attribute__((packed));
DWORD cor_id __attribute__((packed));
WORD up_lks_pre __attribute__((packed));
WORD up_lks_cur __attribute__((packed));
DWORD sg_timer __attribute__((packed));
BYTE retrans_times __attribute__((packed));
WORD rem_port __attribute__((packed));
BYTE alarm_code __attribute__((packed));
//add by yizane
BYTE rel_reason __attribute__((packed));
BYTE tei_state __attribute__((packed));
BYTE dlci __attribute__((packed));
//add by yizane
}m2ua_sg_info_t;
typedef struct _m2ua_comhdr
{
BYTE version __attribute__((packed));
BYTE spare __attribute__((packed));
BYTE msg_class __attribute__((packed));
BYTE msg_type __attribute__((packed));
DWORD len __attribute__((packed));
}m2ua_comhdr_t;
typedef struct _m2ua_par_hdr
{
WORD tag __attribute__((packed));
WORD len __attribute__((packed));
}m2ua_par_hdr_t;
typedef struct _m2ua_var_par
{
m2ua_par_hdr_t hdr __attribute__((packed));
BYTE val[M2UA_MAX_MSG_LEN] __attribute__((packed));
}m2ua_var_par_t;
typedef struct _m2ua_msg
{
m2ua_comhdr_t comhdr __attribute__((packed));
BYTE msg[M2UA_MAX_MSG_LEN] __attribute__((packed));
}m2ua_msg_t;
typedef struct _sg_para
{
BYTE enable __attribute__((packed));
BYTE server __attribute__((packed));
BYTE xUA_ack __attribute__((packed)); //BIT 1-7:xUA_type,0/1:M2UA/IUA ,Bit 0: ACK
DWORD ip __attribute__((packed));
WORD plat_port[2] __attribute__((packed));
}sg_para_t;
typedef struct _lk_para
{
BYTE enable __attribute__((packed));
WORD lk_sg __attribute__((packed));
BYTE iid __attribute__((packed));
WORD dlci __attribute__((packed));
}lk_para_t;
typedef struct _m2ua_para
{
sg_para_t sg_para[M2UA_MAX_SG_NUM] __attribute__((packed));
lk_para_t lk_para[M2UA_MAX_LK_NUM] __attribute__((packed));
BYTE cmd __attribute__((packed));
}m2ua_para_t;
typedef struct _m2ua_lk_pro
{
BYTE e1_to_linkset __attribute__((packed));
BYTE e1_to_slc __attribute__((packed));
DWORD e1_to_mtp3 __attribute__((packed));
BYTE e1_lk_type __attribute__((packed));
BYTE e1_to_sg __attribute__((packed));
BYTE e1_to_iid __attribute__((packed));
DWORD remote_ip __attribute__((packed));
BYTE inactive __attribute__((packed));
BYTE inactive_tm __attribute__((packed));
DWORD e1_to_alterMTP3 __attribute__((packed));
}m2ua_lk_pro_t;
typedef struct _m2ua_sg_csta
{
DWORD timestamp __attribute__((packed));
DWORD sg_out_msg __attribute__((packed));
DWORD sg_in_msg __attribute__((packed));
DWORD sg_out_bytes __attribute__((packed));
DWORD sg_in_bytes __attribute__((packed));
DWORD sg_asp_dn_times __attribute__((packed));
}m2ua_sg_csta_t;
typedef struct _m2ua_lk_csta
{
DWORD timestamp __attribute__((packed));
DWORD lk_out_msg __attribute__((packed));
DWORD lk_in_msg __attribute__((packed));
DWORD lk_out_bytes __attribute__((packed));
DWORD lk_in_bytes __attribute__((packed));
DWORD lk_dn_times __attribute__((packed));
}m2ua_lk_csta_t;
typedef struct _m2ua_csta
{
m2ua_sg_csta_t sg_csta[M2UA_MAX_SG_NUM] __attribute__((packed));
m2ua_lk_csta_t lk_csta[M2UA_MAX_LK_NUM] __attribute__((packed));
}m2ua_csta_t;
#endif

View File

@@ -0,0 +1,655 @@
/* SCTP kernel reference Implementation
* (C) Copyright IBM Corp. 2001, 2004
* Copyright (c) 1999-2000 Cisco, Inc.
* Copyright (c) 1999-2001 Motorola, Inc.
*
* This file is part of the SCTP kernel reference Implementation
*
* This header represents the structures and constants needed to support
* the SCTP Extension to the Sockets API.
*
* The SCTP reference implementation 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, or (at your option)
* any later version.
*
* The SCTP reference implementation 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 GNU CC; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Please send any bug reports or fixes you make to the
* email address(es):
* lksctp developers <lksctp-developers@lists.sourceforge.net>
*
* Or submit a bug report through the following website:
* http://www.sf.net/projects/lksctp
*
* Written or modified by:
* La Monte H.P. Yarroll <piggy@acm.org>
* R. Stewart <randall@sctp.chicago.il.us>
* K. Morneau <kmorneau@cisco.com>
* Q. Xie <qxie1@email.mot.com>
* Karl Knutson <karl@athena.chicago.il.us>
* Jon Grimm <jgrimm@austin.ibm.com>
* Daisy Chang <daisyc@us.ibm.com>
* Inaky Perez-Gonzalez <inaky.gonzalez@intel.com>
* Sridhar Samudrala <sri@us.ibm.com>
*
* Any bugs reported given to us we will try to fix... any fixes shared will
* be incorporated into the next SCTP release.
*/
#ifndef __linux_sctp_h__
#define __linux_sctp_h__
#include <stdint.h>
#include <linux/types.h>
#include <sys/socket.h>
__BEGIN_DECLS
typedef void * sctp_assoc_t;
/* Socket option layer for SCTP */
#ifndef SOL_SCTP
#define SOL_SCTP 132
#endif
#ifndef IPPROTO_SCTP
#define IPPROTO_SCTP 132
#endif
/* 9. Preprocessor constants */
#define HAVE_SCTP
#define HAVE_KERNEL_SCTP
#define HAVE_SCTP_MULTIBUF
#define HAVE_SCTP_NOCONNECT
/* The following symbols come from the Sockets API Extensions for
* SCTP <draft-ietf-tsvwg-sctpsocket-07.txt>.
*/
enum sctp_optname {
SCTP_RTOINFO,
#define SCTP_RTOINFO SCTP_RTOINFO
SCTP_ASSOCINFO,
#define SCTP_ASSOCINFO SCTP_ASSOCINFO
SCTP_INITMSG,
#define SCTP_INITMSG SCTP_INITMSG
SCTP_NODELAY, /* Get/set nodelay option. */
#define SCTP_NODELAY SCTP_NODELAY
SCTP_AUTOCLOSE,
#define SCTP_AUTOCLOSE SCTP_AUTOCLOSE
SCTP_SET_PEER_PRIMARY_ADDR,
#define SCTP_SET_PEER_PRIMARY_ADDR SCTP_SET_PEER_PRIMARY_ADDR
SCTP_PRIMARY_ADDR,
#define SCTP_PRIMARY_ADDR SCTP_PRIMARY_ADDR
SCTP_ADAPTION_LAYER,
#define SCTP_ADAPTION_LAYER SCTP_ADAPTION_LAYER
SCTP_DISABLE_FRAGMENTS,
#define SCTP_DISABLE_FRAGMENTS SCTP_DISABLE_FRAGMENTS
SCTP_PEER_ADDR_PARAMS,
#define SCTP_PEER_ADDR_PARAMS SCTP_PEER_ADDR_PARAMS
SCTP_DEFAULT_SEND_PARAM,
#define SCTP_DEFAULT_SEND_PARAM SCTP_DEFAULT_SEND_PARAM
SCTP_EVENTS,
#define SCTP_EVENTS SCTP_EVENTS
SCTP_I_WANT_MAPPED_V4_ADDR, /* Turn on/off mapped v4 addresses */
#define SCTP_I_WANT_MAPPED_V4_ADDR SCTP_I_WANT_MAPPED_V4_ADDR
SCTP_MAXSEG, /* Get/set maximum fragment. */
#define SCTP_MAXSEG SCTP_MAXSEG
SCTP_STATUS,
#define SCTP_STATUS SCTP_STATUS
SCTP_GET_PEER_ADDR_INFO,
#define SCTP_GET_PEER_ADDR_INFO SCTP_GET_PEER_ADDR_INFO
/* Internal Socket Options. Some of the sctp library functions are
* implemented using these socket options.
*/
SCTP_SOCKOPT_BINDX_ADD = 100,/* BINDX requests for adding addresses. */
#define SCTP_SOCKOPT_BINDX_ADD SCTP_SOCKOPT_BINDX_ADD
SCTP_SOCKOPT_BINDX_REM, /* BINDX requests for removing addresses. */
#define SCTP_SOCKOPT_BINDX_REM SCTP_SOCKOPT_BINDX_REM
SCTP_SOCKOPT_PEELOFF, /* peel off association. */
#define SCTP_SOCKOPT_PEELOFF SCTP_SOCKOPT_PEELOFF
SCTP_GET_PEER_ADDRS_NUM, /* Get number of peer addresss. */
#define SCTP_GET_PEER_ADDRS_NUM SCTP_GET_PEER_ADDRS_NUM
SCTP_GET_PEER_ADDRS, /* Get all peer addresss. */
#define SCTP_GET_PEER_ADDRS SCTP_GET_PEER_ADDRS
SCTP_GET_LOCAL_ADDRS_NUM, /* Get number of local addresss. */
#define SCTP_GET_LOCAL_ADDRS_NUM SCTP_GET_LOCAL_ADDRS_NUM
SCTP_GET_LOCAL_ADDRS, /* Get all local addresss. */
#define SCTP_GET_LOCAL_ADDRS SCTP_GET_LOCAL_ADDRS
};
/*
* 5.2.1 SCTP Initiation Structure (SCTP_INIT)
*
* This cmsghdr structure provides information for initializing new
* SCTP associations with sendmsg(). The SCTP_INITMSG socket option
* uses this same data structure. This structure is not used for
* recvmsg().
*
* cmsg_level cmsg_type cmsg_data[]
* ------------ ------------ ----------------------
* IPPROTO_SCTP SCTP_INIT struct sctp_initmsg
*
*/
struct sctp_initmsg {
__u16 sinit_num_ostreams;
__u16 sinit_max_instreams;
__u16 sinit_max_attempts;
__u16 sinit_max_init_timeo;
};
/*
* 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
*
* This cmsghdr structure specifies SCTP options for sendmsg() and
* describes SCTP header information about a received message through
* recvmsg().
*
* cmsg_level cmsg_type cmsg_data[]
* ------------ ------------ ----------------------
* IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo
*
*/
struct sctp_sndrcvinfo {
__u16 sinfo_stream;
__u16 sinfo_ssn;
__u16 sinfo_flags;
__u32 sinfo_ppid;
__u32 sinfo_context;
__u32 sinfo_timetolive;
__u32 sinfo_tsn;
__u32 sinfo_cumtsn;
sctp_assoc_t sinfo_assoc_id;
};
/*
* sinfo_flags: 16 bits (unsigned integer)
*
* This field may contain any of the following flags and is composed of
* a bitwise OR of these values.
*/
enum sctp_sinfo_flags {
MSG_UNORDERED = 1, /* Send/receive message unordered. */
MSG_ADDR_OVER = 2, /* Override the primary destination. */
MSG_ABORT=4, /* Send an ABORT message to the peer. */
MSG_EOF=MSG_FIN, /* Initiate graceful shutdown process. */
};
typedef union {
__u8 raw;
struct sctp_initmsg init;
struct sctp_sndrcvinfo sndrcv;
} sctp_cmsg_data_t;
/* These are cmsg_types. */
typedef enum sctp_cmsg_type {
SCTP_INIT, /* 5.2.1 SCTP Initiation Structure */
SCTP_SNDRCV, /* 5.2.2 SCTP Header Information Structure */
} sctp_cmsg_t;
/*
* 5.3.1.1 SCTP_ASSOC_CHANGE
*
* Communication notifications inform the ULP that an SCTP association
* has either begun or ended. The identifier for a new association is
* provided by this notificaion. The notification information has the
* following format:
*
*/
struct sctp_assoc_change {
__u16 sac_type;
__u16 sac_flags;
__u32 sac_length;
__u16 sac_state;
__u16 sac_error;
__u16 sac_outbound_streams;
__u16 sac_inbound_streams;
sctp_assoc_t sac_assoc_id;
};
/*
* sac_state: 32 bits (signed integer)
*
* This field holds one of a number of values that communicate the
* event that happened to the association. They include:
*
* Note: The following state names deviate from the API draft as
* the names clash too easily with other kernel symbols.
*/
enum sctp_sac_state {
SCTP_COMM_UP,
SCTP_COMM_LOST,
SCTP_RESTART,
SCTP_SHUTDOWN_COMP,
SCTP_CANT_STR_ASSOC,
};
/*
* 5.3.1.2 SCTP_PEER_ADDR_CHANGE
*
* When a destination address on a multi-homed peer encounters a change
* an interface details event is sent. The information has the
* following structure:
*/
struct sctp_paddr_change {
__u16 spc_type;
__u16 spc_flags;
__u32 spc_length;
struct sockaddr_storage spc_aaddr;
int spc_state;
int spc_error;
sctp_assoc_t spc_assoc_id;
};
/*
* spc_state: 32 bits (signed integer)
*
* This field holds one of a number of values that communicate the
* event that happened to the address. They include:
*/
enum sctp_spc_state {
SCTP_ADDR_AVAILABLE,
SCTP_ADDR_UNREACHABLE,
SCTP_ADDR_REMOVED,
SCTP_ADDR_ADDED,
SCTP_ADDR_MADE_PRIM,
};
/*
* 5.3.1.3 SCTP_REMOTE_ERROR
*
* A remote peer may send an Operational Error message to its peer.
* This message indicates a variety of error conditions on an
* association. The entire error TLV as it appears on the wire is
* included in a SCTP_REMOTE_ERROR event. Please refer to the SCTP
* specification [SCTP] and any extensions for a list of possible
* error formats. SCTP error TLVs have the format:
*/
struct sctp_remote_error {
__u16 sre_type;
__u16 sre_flags;
__u32 sre_length;
__u16 sre_error;
sctp_assoc_t sre_assoc_id;
__u8 sre_data[0];
};
/*
* 5.3.1.4 SCTP_SEND_FAILED
*
* If SCTP cannot deliver a message it may return the message as a
* notification.
*/
struct sctp_send_failed {
__u16 ssf_type;
__u16 ssf_flags;
__u32 ssf_length;
__u32 ssf_error;
struct sctp_sndrcvinfo ssf_info;
sctp_assoc_t ssf_assoc_id;
__u8 ssf_data[0];
};
/*
* ssf_flags: 16 bits (unsigned integer)
*
* The flag value will take one of the following values
*
* SCTP_DATA_UNSENT - Indicates that the data was never put on
* the wire.
*
* SCTP_DATA_SENT - Indicates that the data was put on the wire.
* Note that this does not necessarily mean that the
* data was (or was not) successfully delivered.
*/
enum sctp_ssf_flags {
SCTP_DATA_UNSENT,
SCTP_DATA_SENT,
};
/*
* 5.3.1.5 SCTP_SHUTDOWN_EVENT
*
* When a peer sends a SHUTDOWN, SCTP delivers this notification to
* inform the application that it should cease sending data.
*/
struct sctp_shutdown_event {
__u16 sse_type;
__u16 sse_flags;
__u32 sse_length;
sctp_assoc_t sse_assoc_id;
};
/*
* 5.3.1.6 SCTP_ADAPTION_INDICATION
*
* When a peer sends a Adaption Layer Indication parameter , SCTP
* delivers this notification to inform the application
* that of the peers requested adaption layer.
*/
struct sctp_adaption_event {
__u16 sai_type;
__u16 sai_flags;
__u32 sai_length;
__u32 sai_adaption_ind;
sctp_assoc_t sai_assoc_id;
};
/*
* 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
*
* When a reciever is engaged in a partial delivery of a
* message this notification will be used to inidicate
* various events.
*/
struct sctp_pdapi_event {
__u16 pdapi_type;
__u16 pdapi_flags;
__u32 pdapi_length;
__u32 pdapi_indication;
sctp_assoc_t pdapi_assoc_id;
};
enum { SCTP_PARTIAL_DELIVERY_ABORTED=0, };
/*
* Described in Section 7.3
* Ancillary Data and Notification Interest Options
*/
struct sctp_event_subscribe {
__u8 sctp_data_io_event;
__u8 sctp_association_event;
__u8 sctp_address_event;
__u8 sctp_send_failure_event;
__u8 sctp_peer_error_event;
__u8 sctp_shutdown_event;
__u8 sctp_partial_delivery_event;
__u8 sctp_adaption_layer_event;
};
/*
* 5.3.1 SCTP Notification Structure
*
* The notification structure is defined as the union of all
* notification types.
*
*/
union sctp_notification {
struct {
__u16 sn_type; /* Notification type. */
__u16 sn_flags;
__u32 sn_length;
} sn_header;
struct sctp_assoc_change sn_assoc_change;
struct sctp_paddr_change sn_paddr_change;
struct sctp_remote_error sn_remote_error;
struct sctp_send_failed sn_send_failed;
struct sctp_shutdown_event sn_shutdown_event;
struct sctp_adaption_event sn_adaption_event;
struct sctp_pdapi_event sn_pdapi_event;
};
/* Section 5.3.1
* All standard values for sn_type flags are greater than 2^15.
* Values from 2^15 and down are reserved.
*/
enum sctp_sn_type {
SCTP_SN_TYPE_BASE = (1<<15),
SCTP_ASSOC_CHANGE,
SCTP_PEER_ADDR_CHANGE,
SCTP_SEND_FAILED,
SCTP_REMOTE_ERROR,
SCTP_SHUTDOWN_EVENT,
SCTP_PARTIAL_DELIVERY_EVENT,
SCTP_ADAPTION_INDICATION,
};
/* Notification error codes used to fill up the error fields in some
* notifications.
* SCTP_PEER_ADDRESS_CHAGE : spc_error
* SCTP_ASSOC_CHANGE : sac_error
* These names should be potentially included in the draft 04 of the SCTP
* sockets API specification.
*/
typedef enum sctp_sn_error {
SCTP_FAILED_THRESHOLD,
SCTP_RECEIVED_SACK,
SCTP_HEARTBEAT_SUCCESS,
SCTP_RESPONSE_TO_USER_REQ,
SCTP_INTERNAL_ERROR,
SCTP_SHUTDOWN_GUARD_EXPIRES,
SCTP_PEER_FAULTY,
} sctp_sn_error_t;
/*
* 7.1.1 Retransmission Timeout Parameters (SCTP_RTOINFO)
*
* The protocol parameters used to initialize and bound retransmission
* timeout (RTO) are tunable. See [SCTP] for more information on how
* these parameters are used in RTO calculation.
*/
struct sctp_rtoinfo {
sctp_assoc_t srto_assoc_id;
__u32 srto_initial;
__u32 srto_max;
__u32 srto_min;
};
/*
* 7.1.2 Association Parameters (SCTP_ASSOCINFO)
*
* This option is used to both examine and set various association and
* endpoint parameters.
*/
struct sctp_assocparams {
sctp_assoc_t sasoc_assoc_id;
__u16 sasoc_asocmaxrxt;
__u16 sasoc_number_peer_destinations;
__u32 sasoc_peer_rwnd;
__u32 sasoc_local_rwnd;
__u32 sasoc_cookie_life;
};
/*
* 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR)
*
* Requests that the peer mark the enclosed address as the association
* primary. The enclosed address must be one of the association's
* locally bound addresses. The following structure is used to make a
* set primary request:
*/
struct sctp_setpeerprim {
sctp_assoc_t sspp_assoc_id;
struct sockaddr_storage sspp_addr;
};
/*
* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
*
* Requests that the local SCTP stack use the enclosed peer address as
* the association primary. The enclosed address must be one of the
* association peer's addresses. The following structure is used to
* make a set peer primary request:
*/
struct sctp_prim {
sctp_assoc_t ssp_assoc_id;
struct sockaddr_storage ssp_addr;
};
/*
* 7.1.11 Set Adaption Layer Indicator (SCTP_ADAPTION_LAYER)
*
* Requests that the local endpoint set the specified Adaption Layer
* Indication parameter for all future INIT and INIT-ACK exchanges.
*/
struct sctp_setadaption {
__u32 ssb_adaption_ind;
};
/*
* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS)
*
* Applications can enable or disable heartbeats for any peer address
* of an association, modify an address's heartbeat interval, force a
* heartbeat to be sent immediately, and adjust the address's maximum
* number of retransmissions sent before an address is considered
* unreachable. The following structure is used to access and modify an
* address's parameters:
*/
struct sctp_paddrparams {
sctp_assoc_t spp_assoc_id;
struct sockaddr_storage spp_address;
__u32 spp_hbinterval;
__u16 spp_pathmaxrxt;
};
/*
* 7.2.2 Peer Address Information
*
* Applications can retrieve information about a specific peer address
* of an association, including its reachability state, congestion
* window, and retransmission timer values. This information is
* read-only. The following structure is used to access this
* information:
*/
struct sctp_paddrinfo {
sctp_assoc_t spinfo_assoc_id;
struct sockaddr_storage spinfo_address;
__s32 spinfo_state;
__u32 spinfo_cwnd;
__u32 spinfo_srtt;
__u32 spinfo_rto;
__u32 spinfo_mtu;
};
/* Peer addresses's state. */
enum sctp_spinfo_state {
SCTP_INACTIVE,
SCTP_ACTIVE,
};
/*
* 7.2.1 Association Status (SCTP_STATUS)
*
* Applications can retrieve current status information about an
* association, including association state, peer receiver window size,
* number of unacked data chunks, and number of data chunks pending
* receipt. This information is read-only. The following structure is
* used to access this information:
*/
struct sctp_status {
sctp_assoc_t sstat_assoc_id;
__s32 sstat_state;
__u32 sstat_rwnd;
__u16 sstat_unackdata;
__u16 sstat_penddata;
__u16 sstat_instrms;
__u16 sstat_outstrms;
__u32 sstat_fragmentation_point;
struct sctp_paddrinfo sstat_primary;
};
/*
* 8.3, 8.5 get all peer/local addresses on a socket
* This parameter struct is for getsockopt
*/
struct sctp_getaddrs {
sctp_assoc_t assoc_id;
int addr_num;
struct sockaddr *addrs;
};
/* These are bit fields for msghdr->msg_flags. See section 5.1. */
/* On user space Linux, these live in <bits/socket.h> as an enum. */
enum sctp_msg_flags {
MSG_NOTIFICATION = 0x8000,
#define MSG_NOTIFICATION MSG_NOTIFICATION
};
/*
* 8.1 sctp_bindx()
*
* The flags parameter is formed from the bitwise OR of zero or more of the
* following currently defined flags:
*/
#define SCTP_BINDX_ADD_ADDR 0x01
#define SCTP_BINDX_REM_ADDR 0x02
/* This is the structure that is passed as an argument(optval) to
* getsockopt(SCTP_SOCKOPT_PEELOFF).
*/
typedef struct {
sctp_assoc_t associd;
int sd;
} sctp_peeloff_arg_t;
int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags);
int sctp_peeloff(int sd, sctp_assoc_t assoc_id);
/* Prototype for the library function sctp_opt_info defined in
* API 7. Socket Options.
*/
int sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t *size);
/* Get all peer address on a socket. This is a new SCTP API
* described in the section 8.3 of the Sockets API Extensions for SCTP.
* This is implemented using the getsockopt() interface.
*/
int sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **addrs);
/* Frees all resources allocated by sctp_getpaddrs(). This is a new SCTP API
* described in the section 8.4 of the Sockets API Extensions for SCTP.
*/
int sctp_freepaddrs(struct sockaddr *addrs);
/* Get all locally bound address on a socket. This is a new SCTP API
* described in the section 8.5 of the Sockets API Extensions for SCTP.
* This is implemented using the getsockopt() interface.
*/
int sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **addrs);
/* Frees all resources allocated by sctp_getladdrs(). This is a new SCTP API
* described in the section 8.6 of the Sockets API Extensions for SCTP.
*/
int sctp_freeladdrs(struct sockaddr *addrs);
/* This library function assists the user with the advanced features
* of SCTP. This is a new SCTP API described in the section 8.7 of the
* Sockets API Extensions for SCTP. This is implemented using the
* sendmsg() interface.
*/
int sctp_sendmsg(int s, const void *msg, size_t len, struct sockaddr *to,
socklen_t tolen, uint32_t ppid, uint32_t flags,
uint16_t stream_no, uint32_t timetolive, uint32_t context);
/* This library function assists the user with the advanced features
* of SCTP. This is a new SCTP API described in the section 8.8 of the
* Sockets API Extensions for SCTP. This is implemented using the
* recvmsg() interface.
*/
int sctp_recvmsg(int s, void *msg, size_t len, struct sockaddr *from,
socklen_t *fromlen, struct sctp_sndrcvinfo *sinfo,
int *msg_flags);
__END_DECLS
#endif /* __linux_sctp_h__ */

362
plat/m2ua/src_old/m2ua.c Normal file
View File

@@ -0,0 +1,362 @@
/****************************************************************/
/* M2UA Implementation Program */
/* Version 10.0.3 */
/* Designed By Ying Min */
/* Last Update: 2006-2-14 */
/****************************************************************/
#include "./include/m2ua_pub.h"
#include "./include/m2ua.h"
#include "./include/m2ua_const.h"
#include "./include/m2ua_def.h"
#include "./include/m2ua_struct.h"
#include "./include/m2ua_msg.h"
#include "./include/m2ua_fsm.h"
#include "./include/m2ua_debug.h"
int m2ua_get_local_ip(void)
{
struct hostent *host;
if (gethostname(hostname, 50) == -1)
{
printf("M2UA gethostname fail!\n");
exit(3);
}
if ((host = gethostbyname(hostname)) == NULL)
{
printf("M2UA gethostbyname fail!\n");
exit(4);
}
else
{
sprintf(hostip, "%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]);
host_ip = inet_addr(hostip); // Network byte order host_ip, like 0xE60012AC
printf("hostip: %s (0x%lX)\n", hostip, host_ip);
}
return 0;
}
/*
int m2ua_get_mtp3_para(void)
{
DWORD oid[20] = {1,3,6,1,4,1,1373,1,3,2,2,2,2,9,1}; // SG Attributes
BYTE msg[64], vartype;
int i;
printf("M2UA start to get MTP3 link_para!\n");
for (i = 0; i < M2UA_MAX_SG_NUM; i++)
{
oid[15] = i;
if (get_response(16, oid, msg, &vartype) < 0)
{
printf("M2UA get MTP3 sg_para failed, please set it from MTP3!\n");
return -1;
}
else
set_m2ua_sg(i, msg);
}
oid[14] = 5; // Link Attributes
for (i = 0; i < M2UA_MAX_LK_NUM; i++)
{
oid[15] = i;
if (get_response(16, oid, msg, &vartype) < 0)
{
printf("M2UA get MTP3 link_para failed, please set it from MTP3!\n");
return -1;
}
else
set_m2ua_link(i, msg);
}
return 0;
}
*/
void m2ua_init(BYTE system_id)
{
int id, fd;
//static DWORD init_times = 0;
printf("M2UA Init Start!\n");
plat_id = system_id%2;
m2ua_get_local_ip();
for (id = 0; id < M2UA_MAX_SG_FSM_NUM; id++)
{
m2ua_sg_init(id);
m2ua_sg_mon_fg[id] = 0;
}
m2ua_sg_mon_count = 0;
#ifndef _LKSCTP
if ((fd = m2ua_sctp_t_open(M2UA_LISTEN_SG_NUM_0)) <= 0)
{
printf("M2UA_LISTEN_SG_NUM_0 sctp_t open failure!\n");
exit(2);
}
#else
if ((fd = m2ua_sctp_open_lksctp(M2UA_LISTEN_SG_NUM_0)) <= 0)
{
printf("M2UA_LISTEN_SG_NUM_0 lksctp open failure!\n");
exit(2);
}
#endif
else
{
m2ua_sg_info[M2UA_LISTEN_SG_NUM_0].fd = fd;
m2ua_sg_info[M2UA_LISTEN_SG_NUM_0].enable = 1;
printf("M2UA_LISTEN_SG_NUM_0 listening fd open succeed!\n");
}
#ifndef _LKSCTP
if ((fd = m2ua_sctp_t_open(M2UA_LISTEN_SG_NUM_1)) <= 0)
{
printf("M2UA_LISTEN_SG_NUM_1 sctp_t open failure!\n");
exit(2);
}
#else
if ((fd = m2ua_sctp_open_lksctp(M2UA_LISTEN_SG_NUM_1)) <= 0)
{
printf("M2UA_LISTEN_SG_NUM_1 lksctp open failure!\n");
exit(2);
}
#endif
else
{
m2ua_sg_info[M2UA_LISTEN_SG_NUM_1].fd = fd;
m2ua_sg_info[M2UA_LISTEN_SG_NUM_1].enable = 1;
printf("M2UA_LISTEN_SG_NUM_1 listening fd open succeed!\n");
}
//add by yizane
#ifndef _LKSCTP
if ((fd = m2ua_sctp_t_open(IUA_LISTEN_SG_NUM_0)) <= 0)
{
printf("IUA_LISTEN_SG_NUM_0 sctp_t open failure!\n");
exit(2);
}
#else
if ((fd = m2ua_sctp_open_lksctp(IUA_LISTEN_SG_NUM_0)) <= 0)
{
printf("IUA_LISTEN_SG_NUM_0 lksctp open failure!\n");
exit(2);
}
#endif
else
{
m2ua_sg_info[IUA_LISTEN_SG_NUM_0].fd = fd;
m2ua_sg_info[IUA_LISTEN_SG_NUM_0].enable = 1;
printf("IUA_LISTEN_SG_NUM_0 listening fd open succeed!\n");
}
#ifndef _LKSCTP
if ((fd = m2ua_sctp_t_open(IUA_LISTEN_SG_NUM_1)) <= 0)
{
printf("IUA_LISTEN_SG_NUM_1 sctp_t open failure!\n");
exit(2);
}
#else
if ((fd = m2ua_sctp_open_lksctp(IUA_LISTEN_SG_NUM_1)) <= 0)
{
printf("IUA_LISTEN_SG_NUM_1 lksctp open failure!\n");
exit(2);
}
#endif
else
{
m2ua_sg_info[IUA_LISTEN_SG_NUM_1].fd = fd;
m2ua_sg_info[IUA_LISTEN_SG_NUM_1].enable = 1;
printf("IUA_LISTEN_SG_NUM_1 listening fd open succeed!\n");
}
//add by yizane
for (id = 0; id < M2UA_MAX_LK_NUM; id++)
{
m2ua_lk_init(id);
m2ua_lk_mon_fg[id] = 0;
}
m2ua_lk_mon_count = 0;
for (id = 0; id < M2UA_MAX_M3MSG_NUM; id++)
x256[id] = 256 * id;
bzero(&m2ua_csta, sizeof(m2ua_csta_t));
bzero(err, 256);
m2ua_mtp3_sd_h = 0;
m2ua_mtp3_sd_t = 0;
iua_q931_sd_h = 0;
iua_q931_sd_t = 0;
m2ua_sctp_cmd_len = 0;
m2ua_sctp_dat_len = 0;
m2ua_sctp_addr.port = htons(2904);
m2ua_sctp_server_addr.port = htons(2904);
inet_aton(hostip, &m2ua_sctp_addr.addr);
strcpy(m2ua_asciin_buf, "\0");
strcpy(m2ua_asciout_buf, "\0");
moniter_fg = MONITOR_NONE;
m2ua_debug_set();
init_flag = 0;
m2ua_command = M2UA_CMD_IDLE;
//if (init_times++);
//m2ua_get_mtp3_para();
printf("M2UA Init Complete!\n");
}
void m2ua_t10ms()
{
static int cnt_10ms = 0;
static int ls_hb_flag = 0;
static int ls_hb_lk = 0;
WORD nsg;
WORD i, fd;
if (ls_hb_flag)
{
if (ls_hb_lk < M2UA_MAX_LK_NUM)
{
if (m2ua_para.lk_para[ls_hb_lk].enable == 1)
{
nsg = m2ua_para.lk_para[ls_hb_lk].lk_sg;
if ((m2ua_para.sg_para[nsg].xUA_ack>>1) == M2UA_APP)
m2ua_sd_mtp3_primi(ls_hb_lk, m2ua_lk_info[ls_hb_lk].lk_st);
else if ((m2ua_para.sg_para[nsg].xUA_ack>>1) == IUA_APP)
iua_sd_q931_primi(ls_hb_lk, m2ua_lk_info[ls_hb_lk].lk_st);
}
ls_hb_lk++;
}
else
{
ls_hb_flag = 0;
ls_hb_lk = 0;
}
}
if (!(++cnt_10ms % 10))
{ // 100 ms
m2ua_mon();
if (!(cnt_10ms % 100))
{ // 1 seconds
if (m2ua_command != M2UA_CMD_IDLE)
{
sprintf(m2ua_ascitemp_buf, "M2UA Restart! m2ua_command=%d\n\r", m2ua_command);
m2ua_asciout_proc(m2ua_ascitemp_buf);
m2ua_asciout_proc("\n\r");
m2ua_command = M2UA_CMD_IDLE;
for (i = 0; i < M2UA_MAX_SG_FSM_NUM; i++)
{
if ((fd = m2ua_sg_info[i].fd) > 0)
{
if ((m2ua_sg_info[i].sctp_state > 2) ||
((m2ua_sg_info[i].sctp_state == 2) &&
(m2ua_sg_info[i].sctp_state_1 > 0)))
{
#ifndef _LKSCTP
if (i >= M2UA_MAX_SG_NUM)
m2ua_sctp_discon_req(fd, i, m2ua_sg_info[i].seq);
else
m2ua_sctp_discon_req(fd, i, 0);
#else
m2ua_sctp_discon_req_lksctp(fd, i, 0);
#endif
}
#ifndef _LKSCTP
m2ua_sctp_close(m2ua_sg_info[i].fd, i);
#endif
}
}
m2ua_init(plat_id);
}
else if (cnt_10ms >= 1500)
{ // 15 seconds
cnt_10ms = 0;
ls_hb_flag = 1;
}
}
}
}
// Called every 10 ms
void m2ua_timer(void)
{
WORD sg, sg_dual, i;
static BYTE sg_start = 0;
static BYTE lk_scan = 0;
for (sg = sg_start; sg < sg_start + 128; sg++)
{
sg_dual = sg;
if (m2ua_sg_info[sg_dual].m2ua_state == 3)
{
for (i = 0; i < 32; i++)
{
if (m2ua_sg_fsm(sg_dual) < 0)
break;
}
}
else
m2ua_sg_fsm(sg_dual);
sg_dual = sg + M2UA_MAX_SG_NUM/2;
if (m2ua_sg_info[sg_dual].m2ua_state == 3)
{
for (i = 0; i < 32; i++)
{
if (m2ua_sg_fsm(sg_dual) < 0)
break;
}
}
else
m2ua_sg_fsm(sg_dual);
}
sg_start += 128;
if (sg_start == 0)
{
m2ua_sg_fsm(M2UA_LISTEN_SG_NUM_0);
m2ua_sg_fsm(M2UA_LISTEN_SG_NUM_1);
m2ua_sg_fsm(IUA_LISTEN_SG_NUM_0);
m2ua_sg_fsm(IUA_LISTEN_SG_NUM_1);
}
if (m2ua_lk_info[lk_scan].lk_timer > 0)
m2ua_lk_info[lk_scan].lk_timer--;
lk_scan ++;
m2ua_t10ms();
}
int m2ua_restart()
{
if (m2ua_command != M2UA_CMD_IDLE)
return 0;
else if (init_flag == 2)
{
m2ua_command = M2UA_CMD_STATUS_INIT;
return 0;
}
return 1;
}

View File

@@ -0,0 +1,510 @@
#include "./include/m2ua_pub.h"
#include "./include/m2ua.h"
#include "./include/m2ua_const.h"
#include "./include/m2ua_struct.h"
#include "./include/m2ua_ext.h"
#include "../../debug/src/include/debug.h"
#define M2UA_DEBUG_ID 16
#define M2UA_VER_DEBUG "R9V0_03b"
static char ascii[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
static BYTE log_help[] = {
"M2UA 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 (sg only)\n\r\
4.[log mtp3/maup on/off] display mtp3/maup logs (sg or link)\n\r\
5.[log m2ua/sctp on/off] display m2ua/sctp logs (sg only)\n\r\
6.[log sg-xxx/lk-xxx on/off] display sg/lk 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,M2UA_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,M2UA_DEBUG_ID + 2,2
};
static DWORD debug_ascin_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,M2UA_DEBUG_ID + 2,3
};
static DWORD debug_ascout_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,M2UA_DEBUG_ID + 2,4
};
static DWORD debug_page_title[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,M2UA_DEBUG_ID + 2,1,1
};
static DWORD debug_page_line[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,M2UA_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[] =
{
" M2UA Page 01 SG Para\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Subpage\n\r\
SG_Para\n\r"
};
static BYTE title2_p[] =
{
" M2UA Page 02 Link Para\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Subpage\n\r\
LK_Para\n\r"
};
static BYTE title3_p[] =
{
" M2UA Page 03 SG Info\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Subpage\n\r\
SG_Info\n\r"
};
static BYTE title4_p[] =
{
" M2UA Page 04 Link Info\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
LK_Info\n\r"
};
static BYTE title5_p[] =
{
" M2UA Page 05 SG CSTA\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Subpage\n\r\
SG_CSTA\n\r"
};
static BYTE title6_p[] =
{
" M2UA Page 06 Link CSTA\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
LK_CSTA\n\r"
};
static BYTE title7_p[] =
{
" M2UA Page 07 Watchdog\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Watchdog\n\r"
};
BYTE m2ua_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 if (line < 17)
{
disp_ptr = (BYTE *) m2ua_para.sg_para + ((line - 1) * sizeof(sg_para_t)) + (disp_page[page] * 16 * sizeof(sg_para_t));
disp_length = sizeof(sg_para_t);
}
else
disp_length = 0;
break;
case 2: // Page 2: LK Para
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else if (line < 17)
{
disp_ptr = (BYTE *) m2ua_para.lk_para + ((line - 1) * sizeof(lk_para_t)) + disp_page[page] * 16 * sizeof(lk_para_t);
disp_length = sizeof(lk_para_t);
}
else
disp_length = 0;
break;
case 3: // Page 3: SG Info
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else if (line < 7)
disp_ptr = (BYTE *) &m2ua_sg_info[disp_page[page]] + ((line - 1) * 16);
else
disp_length = 0;
break;
case 4: // Page 4: LK Info
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else if (line < 17)
{
disp_ptr = (BYTE *) m2ua_lk_info + ((line - 1) * sizeof(m2ua_lk_info_t)) + disp_page[page] * 16 * sizeof(m2ua_lk_info_t);
disp_length = sizeof(m2ua_lk_info_t);
}
else
disp_length = 0;
break;
case 5: // Page 5: SG CSTA
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else if (line < 3)
disp_ptr = (BYTE *) &m2ua_csta.sg_csta[disp_page[page]] + ((line - 1) * 16);
else
disp_length = 0;
break;
case 6: // Page 6: LK CSTA
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else if (line < 3)
disp_ptr = (BYTE *) &m2ua_csta.lk_csta[disp_page[page]] + ((line - 1) * 16);
else
disp_length = 0;
break;
case 7: // Page 7: Err
if (line < 16)
disp_ptr = (BYTE *)err + (line * 16);
else
disp_length = 0;
break;
default:
disp_length = 0;
break;
}
return disp_length;
}
void m2ua_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 = m2ua_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 m2ua_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, M2UA_VER_DEBUG, 10);
debug_set_response(BASE_ID_LEN, debug_ascin_id, m2ua_asciin_buf, 4096);
debug_set_response(BASE_ID_LEN, debug_ascout_id, m2ua_asciout_buf, 4096);
for (page = 1; page < 8; page++)
{
switch (page)
{
case 1: //page 1
ptr = title1_p;
break;
case 2: //page 2
ptr = title2_p;
break;
case 3: //page 3
ptr = title3_p;
break;
case 4: //page 4
ptr = title4_p;
break;
case 5: //page 5
ptr = title5_p;
break;
case 6: //page 6
ptr = title6_p;
break;
case 7: //page 7
ptr = title7_p;
break;
default:
break;
}
debug_page_title[PAGE_POINT] = 5 + page;
debug_set_response(BASE_ID_LEN + 1, debug_page_title, ptr, strlen(ptr));
m2ua_disp_page(page);
}
return 1;
}
int m2ua_asciout_proc(BYTE *out_str)
{
int out_len;
out_len = strlen(out_str);
if (out_len + strlen(m2ua_asciout_buf) > MAX_ASCIIOUT_LEN - 2)
{
strcpy(m2ua_asciout_buf, out_str);
}
else
strcat(m2ua_asciout_buf, out_str);
return 1;
}
void m2ua_mon(void)
{
BYTE in_page, err_fg = 0;
BYTE *ascii_in_ptr = NULL;
BYTE *str_start = NULL;
WORD str_len, num;
if ((str_len = strlen(m2ua_asciin_buf)) > 0)
{
in_page = m2ua_asciin_buf[0] - 1;
ascii_in_ptr = m2ua_asciin_buf + 1;
if (in_page > 7)
err_fg = 1;
else if (strcmp(ascii_in_ptr,"c") == 0)
{
bzero(&m2ua_csta, sizeof(m2ua_csta_t));
bzero(err, 256);
}
else if (strcmp(ascii_in_ptr,"log mtp3 on") == 0)
{
moniter_fg = moniter_fg | MONITOR_MTP3;
}
else if (strcmp(ascii_in_ptr,"log mtp3 off") == 0)
{
moniter_fg = moniter_fg & (~MONITOR_MTP3);
}
else if (strcmp(ascii_in_ptr,"log m2ua on") == 0)
{
moniter_fg = moniter_fg | MONITOR_M2UA;
}
else if (strcmp(ascii_in_ptr,"log m2ua off") == 0)
{
moniter_fg = moniter_fg & (~MONITOR_M2UA);
}
else if (strcmp(ascii_in_ptr,"log maup on") == 0)
{
moniter_fg = moniter_fg | MONITOR_MAUP;
}
else if (strcmp(ascii_in_ptr,"log maup off") == 0)
{
moniter_fg = moniter_fg & (~MONITOR_MAUP);
}
else if (strcmp(ascii_in_ptr,"log sctp on") == 0)
{
moniter_fg = moniter_fg | MONITOR_SCTP;
}
else if (strcmp(ascii_in_ptr,"log sctp off") == 0)
{
moniter_fg = moniter_fg & (~MONITOR_SCTP);
}
else if (strcmp(ascii_in_ptr,"log error on") == 0)
{
moniter_fg = moniter_fg | MONITOR_ERROR;
}
else if (strcmp(ascii_in_ptr,"log error off") == 0)
{
moniter_fg = moniter_fg & (~MONITOR_ERROR);
}
else if (strcmp(ascii_in_ptr,"log all") == 0)
{
moniter_fg = MONITOR_ALL;
if (!m2ua_sg_mon_count && !m2ua_lk_mon_count)
{
memset(m2ua_sg_mon_fg, 1, M2UA_MAX_SG_FSM_NUM);
memset(m2ua_lk_mon_fg, 1, M2UA_MAX_LK_NUM);
}
else
err_fg = 2;
}
else if (strcmp(ascii_in_ptr,"log none") == 0)
{
moniter_fg = MONITOR_NONE;
memset(m2ua_sg_mon_fg, 0, M2UA_MAX_SG_FSM_NUM);
memset(m2ua_lk_mon_fg, 0, M2UA_MAX_LK_NUM);
m2ua_sg_mon_count = 0;
m2ua_lk_mon_count = 0;
}
else if (strcmp(ascii_in_ptr,"help") == 0)
{
m2ua_asciout_proc(log_help);
}
else if (strstr(ascii_in_ptr, "log sg") != NULL)
{
if ((moniter_fg == MONITOR_ALL) &&
!m2ua_sg_mon_count &&
!m2ua_lk_mon_count)
err_fg = 3;
else if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
{
num = strtoul(str_start + 1, NULL, 10);
if (num >= M2UA_MAX_SG_FSM_NUM)
err_fg = 1;
else if (strstr(ascii_in_ptr, "on") != NULL)
{
m2ua_sg_mon_fg[num] = 1;
if (m2ua_sg_mon_count < M2UA_MAX_SG_NUM+2)
m2ua_sg_mon_count++;
}
else if (strstr(ascii_in_ptr, "off") != NULL)
{
m2ua_sg_mon_fg[num] = 0;
if (m2ua_sg_mon_count > 0)
m2ua_sg_mon_count--;
}
else
err_fg = 1;
}
else
err_fg = 1;
}
else if (strstr(ascii_in_ptr, "log lk") != NULL)
{
if ((moniter_fg == MONITOR_ALL) &&
!m2ua_sg_mon_count &&
!m2ua_lk_mon_count)
err_fg = 3;
else if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
{
num = strtoul(str_start + 1, NULL, 10);
if (num >= M2UA_MAX_LK_NUM)
err_fg = 1;
else if (strstr(ascii_in_ptr, "on") != NULL)
{
m2ua_lk_mon_fg[num] = 1;
if (m2ua_lk_mon_count < M2UA_MAX_LK_NUM)
m2ua_lk_mon_count++;
}
else if (strstr(ascii_in_ptr, "off") != NULL)
{
m2ua_lk_mon_fg[num] = 0;
if (m2ua_lk_mon_count > 0)
m2ua_lk_mon_count--;
}
else
err_fg = 1;
}
else
err_fg = 1;
}
else if (isdigit(ascii_in_ptr[0]))
{
num = strtoul(ascii_in_ptr, NULL, 10);
disp_page[in_page] = num;
m2ua_disp_page(in_page);
}
else if ((str_start = strstr(ascii_in_ptr, ">")) != NULL)
{
num = strtoul(str_start + 1, NULL, 10);
disp_page[in_page] += num;
m2ua_disp_page(in_page);
}
else if ((str_start = strstr(ascii_in_ptr, "<"))!= NULL)
{
num = strtoul(str_start + 1, NULL, 10);
disp_page[in_page] -= num;
m2ua_disp_page(in_page);
}
else
err_fg = 1;
if (err_fg == 0)
m2ua_asciout_proc("Command OK!\n\r");
else if (err_fg == 2)
m2ua_asciout_proc("Log all for some SGs or Links!\n\r");
else if (err_fg == 3)
m2ua_asciout_proc("Log all already done for all SGs and Links, log none to clear!\n\r");
else
m2ua_asciout_proc("Command Error!\n\r");
strcpy(m2ua_asciin_buf, "\0");
}
}
int m2ua_hex_to_ascii(BYTE *from_hex, WORD from_len, BYTE *to_asc)
{
int i, j;
j = 0;
for (i = 0; i< from_len; i++)
{
to_asc[j] = ascii[from_hex[i] >> 4];
j++;
to_asc[j] = ascii[from_hex[i] & 0x0F];
j++;
to_asc[j] = ' ';
j++;
}
to_asc[j] = '\0';
return 1;
}
int m2ua_log_err(WORD sg_id, BYTE *err_msg)
{
if ((moniter_fg & MONITOR_ERROR) == MONITOR_ERROR)
{
if ((m2ua_sg_mon_fg[sg_id] == 0))
return 0;
m2ua_asciout_proc("\33[31m");
if (strlen(err_msg) >= MAX_ASCITMP_LEN)
sprintf(m2ua_ascitemp_buf, "SG[%d] log msg is too long: %d\n\r", sg_id, strlen(err_msg));
else
sprintf(m2ua_ascitemp_buf, "SG[%d]: %s\n\r", sg_id, err_msg);
strcat(m2ua_ascitemp_buf, "\33[37m");
m2ua_asciout_proc(m2ua_ascitemp_buf);
}
return 1;
}

1505
plat/m2ua/src_old/m2ua_fsm.c Normal file

File diff suppressed because it is too large Load Diff

2749
plat/m2ua/src_old/m2ua_msg.c Normal file

File diff suppressed because it is too large Load Diff