/* Copyright © 2024 TP-Link Systems Inc.
*
* file msg_common.h
* brief
* details
*
* author Yang Lei
* version
* date 12Sep12
*
* history \arg
*/
#ifndef __MSG_COMMON_H__
#define __MSG_COMMON_H__
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/if_ether.h>
#include "cutil_lib.h"
/**************************************************************************************************/
/* DEFINES */
/**************************************************************************************************/
/*
* brief Debug level definition
*/
#define LOG_NONE 0
#define LOG_ERROR 1
#define LOG_NOTICE 2
#define LOG_DEBUG 3
#define LOG_LEVEL LOG_ERROR
#if LOG_LEVEL > LOG_NONE
#define MSG_LOG(fmt, args...) fprintf(stderr, "\033[4m%s#%s[%d]: "fmt"\033[0m\n", __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define MSG_LOG(fmt, args...)
#endif
#if LOG_LEVEL >= LOG_ERROR
#define MSG_ERROR MSG_LOG
#else
#define MSG_ERROR(fmt, args...)
#endif
#if LOG_LEVEL >= LOG_NOTICE
#define MSG_NOTICE MSG_LOG
#define msg_execSystem(cmd, args...) { sprintf(cmd, args); MSG_LOG("cmd: %s", cmd); \
if (NULL == strchr(cmd, ';')) {system(cmd);} }
#define msg_execSystem2(cmd) { MSG_LOG("cmd: %s", cmd); if (NULL == strchr(cmd, ';')) {system(cmd);} }
#else
#define MSG_NOTICE(fmt, args...)
#define msg_execSystem(cmd, args...) { sprintf(cmd, args); if (NULL == strchr(cmd, ';')) {system(cmd);} }
#define msg_execSystem2 system
#endif
#if LOG_LEVEL >= LOG_DEBUG
#include <assert.h>
#define MSG_ASSERT assert
#define MSG_DEBUG MSG_LOG
#else
#define MSG_ASSERT(expr)
#define MSG_DEBUG(fmt, args...)
#endif
/*
* brief whether use packet_mmap for rx (to improve performance)
*/
#define USE_RX_MMAP
/*
* brief MAC string length
*/
#define MAC_STR_LEN 18
/*
* brief Protocol definition
*/
#define MSG_ETH_PROTO 0x88b5
#define MSG_VERSION 0x01
#define MSG_6332_VER ((MSG_VERSION << 4) | 0x00)
#define MSG_9344_VER ((MSG_VERSION << 4) | 0x01)
#define MSG_MIN_LEN ETH_ZLEN
#ifdef USE_RX_MMAP
#define MSG_MAX_LEN 950
#define UPGRADE_BLOCK_SIZE 900
#define RX_FRAME_SIZE 1024
#define RX_FRAME_COUNT 128
#else
#define MSG_MAX_LEN ETH_FRAME_LEN
#define UPGRADE_BLOCK_SIZE 1024
#endif
/*
* brief max pvc count
*/
#define ATM_PVC_MAX 8
/*
* brief vlan id range for dsl bridge interface, VLAN_COUNT <= 32
*/
#define MIN_VLAN_ID 2000
#define VLAN_COUNT 8
#define MAX_VLAN_ID (MIN_VLAN_ID + VLAN_COUNT - 1)
#define MAX_WAN_TAG_VID 4094
#define MAX_WAN_TAG_PR 7
/* VDSL2 profile parameters */
#define kVdslProfile8a 0x00000001
#define kVdslProfile8b 0x00000002
#define kVdslProfile8c 0x00000004
#define kVdslProfile8d 0x00000008
#define kVdslProfile12a 0x00000010
#define kVdslProfile12b 0x00000020
#define kVdslProfile17a 0x00000040
#define kVdslProfile30a 0x00000080
#define kVdslProfile35b 0x00000100
#define kVdslUS0MaskShift 16
#define kVdsl8aUS0Mask (0x00000001 << kVdslUS0MaskShift)
/**************************************************************************************************/
/* TYPES */
/**************************************************************************************************/
typedef enum {
VDSL_PROF_SHIFT_8A = 0,
VDSL_PROF_SHIFT_8B,
VDSL_PROF_SHIFT_8C,
VDSL_PROF_SHIFT_8D,
VDSL_PROF_SHIFT_12A,
VDSL_PROF_SHIFT_12B,
VDSL_PROF_SHIFT_17A,
VDSL_PROF_SHIFT_30A,
VDSL_PROF_SHIFT_35B,
VDSL_PROF_SHIFT_US0MASK = 16,
VDSL_PROF_SHIFT_END
} VDSL_PROFILE_SHIFT;
#ifndef BUFLEN_16
/*
* brief Common buffer length
*/
#define BUFLEN_16 16
#define BUFLEN_32 32
#define BUFLEN_64 64
#define BUFLEN_128 128
#define BUFLEN_256 256
#define BUFLEN_512 512
/*
* brief UBOOL8
*/
/*typedef enum {
FALSE = 0,
TRUE = 1,
} UBOOL8;*/
/*
* brief Integer types
*/
typedef int8_t SINT8;
typedef int16_t SINT16;
typedef int32_t SINT32;
typedef int64_t SINT64;
typedef uint8_t UINT8;
typedef uint16_t UINT16;
typedef uint32_t UINT32;
typedef uint64_t UINT64;
#endif
/*
* brief Message header (include ether header)
*/
typedef struct _MSG_HDR {
struct ethhdr ethHdr; /* ether header */
UINT8 vertype; /* version, current 0x10 for 6332, 0x11 for 9344 */
UINT8 code; /* message command code */
UINT32 id; /* message request unique id, generated by 9344 */
UINT16 length; /* message body length */
UINT16 checksum; /* crc16 from code to message body end, fill 0 before calculated */
} __attribute__((packed)) MSG_HDR;
/*
* brief Structure to store request info
*/
typedef struct _MSG_REQUEST {
union {
MSG_HDR sendMsg; /* send message */
UINT8 sendBuf[MSG_MAX_LEN]; /* send buffer */
};
union {
MSG_HDR recvMsg; /* recv message */
UINT8 recvBuf[MSG_MAX_LEN]; /* recv buffer */
};
UINT16 sendLen; /* valid send buffer length */
int sock; /* message socket */
} MSG_REQUEST;
/*
* brief general error code
*/
typedef enum _MSG_RET {
MRET_OK = 0, /* Success */
MRET_ERROR, /* Failed */
MRET_INVALID_PARAM, /* Invalid parameters */
MRET_UPDATE_FILE_LEN_ERR, /* CMM_UPDATE_FILE_LEN_ERR */
MRET_UPDATE_FILE_VER_ERR, /* CMM_UPDATE_FILE_VER_ERR */
MRET_UPDATE_ADDI_HW_VER_ERR,/* CMM_UPDATE_ADDI_HW_VER_ERR */
#ifdef INCLUDE_WAN_DETECT
MRET_VPI_VCI_ALREADY_EXIST, /* CMM_VPI_VCI_ALREADY_EXIST */
#endif
} MSG_RET;
/*
* brief CMD_DSL_CFG_SET Message
*/
typedef struct _DSL_CFG_SET_MSG {
UINT8 modulation; /* AdslModulationCfg */
UINT8 annexType; /* AnnexType */
UINT8 bitswap; /* Bitswap */
UINT8 sra; /* SRA */
UINT8 sos; /* SOS */
/* add by wanghao */
long vdslProfile;/* VDSLprofile */
/* add end */
} __attribute__((packed)) DSL_CFG_SET_MSG;
/*
* brief dsl modulation enumeration
*/
typedef enum _DSL_MODULATION {
ADSL_ANSI_T1_413,
ADSL_G_DMT,
ADSL_G_LITE,
ADSL_G_DMT_BIS,
ADSL_2PLUS,
ADSL_MULTIMODE,
#ifdef INCLUDE_VDSLWAN
VDSL_2,
#endif /*INCLUDE_VDSLWAN*/
MULTIMODE
} DSL_MODULATION;
/*
* brief dsl annexType enumeration
*/
typedef enum _DSL_ANNEX_TYPE {
ANNEX_A,
ANNEX_B,
ANNEX_I,
ANNEX_M,
ANNEX_A_L,
ANNEX_A_L_M,
ANNEX_A_I_J_L_M,
ANNEX_J,
ANNEX_B_J,
ANNEX_AUTO
} DSL_ANNEX_TYPE;
/*
* brief CMD_DSL_CFG_GET Response
*/
typedef struct _DSL_CFG_GET_RESP {
UINT32 ret;
UINT8 status;
UINT8 modulationType;
UINT8 dataPath;
UINT8 annexType;
UINT32 downstreamCurrRate;
UINT32 upstreamCurrRate;
UINT32 downstreamMaxRate;
UINT32 upstreamMaxRate;
SINT32 downstreamNoiseMargin;
SINT32 upstreamNoiseMargin;
SINT32 downstreamAttenuation;
SINT32 upstreamAttenuation;
SINT32 downstreamPower;
SINT32 upstreamPower;
UINT32 showtimeStart;
UINT32 totalStart;
#ifdef INCLUDE_VDSLWAN
UINT8 isATM;
UINT16 currentProfile;
#endif
} __attribute__((packed)) DSL_CFG_GET_RESP;
/*
* brief dsl status enumeration
*/
typedef enum _DSL_STATUS {
DSL_NOT_INIT,
DSL_UP,
DSL_NOSIGNAL,
DSL_INITIALIZING,
DSL_ESTABLISHINGLINK,
} DSL_STATUS;
/*
* brief dsl dataPath enumeration
*/
typedef enum _DSL_DATAPATH {
DSL_FAST,
DSL_INTERLEAVED,
} DSL_DATAPATH;
/*
* brief CMD_DSL_STATS Response
*/
typedef struct _DSL_STATS_RESP {
UINT32 ret; /* MSG_RET */
UINT32 ATUCFECErrors;
UINT32 ATUCCRCErrors;
UINT32 ATUCHECErrors;
UINT32 FECErrors;
UINT32 CRCErrors;
UINT32 HECErrors;
} __attribute__((packed)) DSL_STATS_RESP;
/*
* brief CMD_DSL_LINK_ADD Message
*/
typedef struct _DSL_LINK_ADD_MSG {
UINT8 atmQos; /* ATMQoS */
UINT8 vpi; /* VPI */
UINT16 vci; /* VCI */
UINT32 pcr; /* ATMPeakCellRate */
UINT32 scr; /* ATMSustainableCellRate */
UINT32 mbs; /* ATMMaximumBurstSize */
// UINT8 aal; /* ATMAAL */ /* always use AAL5 */
UINT8 encapMode; /* ATMEncapsulation */
UINT8 linkType; /* LinkType */
UINT16 vlanId; /* unique VLAN ID */
UINT8 WanTagEnabled; /* the flag if the wan tag vlan is enabled. */
SINT16 wanTagVid; /* wan tag vlan id, namely 802.1Q VLAN ID, 0-4094. */
SINT8 wanTagPr; /* wan tag priority bits, namely 802.1P priority, 0-7 */
} __attribute__((packed)) DSL_LINK_ADD_MSG;
/* add by wanghao */
#ifdef INCLUDE_VDSLWAN
/*
* brief CMD_VDSL_LINK_ADD Message, add by wanghao for BCM63168
*/
typedef struct _VDSL_LINK_ADD_MSG {
UINT8 vlanEnabled; /* PTM vlan status*/
UINT16 vid; /* PTM vlan id */
UINT16 qosMark; /* PTM QosMark */
UINT8 linkType; /* LinkType */
UINT16 vlanId; /* unique VLAN ID */
#if 0
UINT8 WanTagEnabled; /* the flag if the wan tag vlan is enabled. */
SINT16 wanTagVid; /* wan tag vlan id, namely 802.1Q VLAN ID, 0-4094. */
SINT8 wanTagPr; /* wan tag priority bits, namely 802.1P priority, 0-7 */
#endif
} __attribute__((packed)) VDSL_LINK_ADD_MSG;
#endif
/* add end */
/*
* brief ATMQoS enumeration
*/
typedef enum _ATM_QOS {
UBR = 0,
UBR_PCR,
CBR,
NRTVBR,
RTVBR,
MBR,
} ATM_QOS;
/*
* brief ATMAAL enumeration
*/
// typedef enum _ATM_AAL {
// AAL5 = 0,
// AAL2,
// AAL0_PKT,
// AAL0_CELL,
// AAL_TRANSPARENT,
// } ATM_AAL;
/*
* brief ATMEncapsulation enumeration
*/
typedef enum _ATM_ENCAPSULATION {
LLC = 0,
VCMUX,
#ifdef INCLUDE_WAN_DETECT
PPPOA_LLC,
PPPOA_VCMUX,
ENCAP_END,
#endif
} ATM_ENCAPSULATION;
/*
* brief LinkType enumeration
*/
typedef enum _ATM_LINKTYPE {
LINK_PPPOE = 0,
LINK_DIPOE,
LINK_SIPOE,
LINK_PPPOE_RELAY,
LINK_BRIDGE,
LINK_EOA, /* only for mark */
LINK_PPPOA,
LINK_IPOA,
} ATM_LINKTYPE;
/*
* brief DSL_LINK_SET_MSG Message
*/
typedef struct _DSL_LINK_SET_MSG {
UINT16 vlanId; /* unique VLAN ID */
UINT8 cmd; /* command */
} __attribute__((packed)) DSL_LINK_SET_MSG;
/* add by wanghao */
#ifdef INCLUDE_VDSLWAN
/*
* brief VDSL_LINK_SET_MSG Message
*/
typedef struct _VDSL_LINK_SET_MSG {
UINT16 vlanId; /* unique VLAN ID */
UINT8 cmd; /* command */
} __attribute__((packed)) VDSL_LINK_SET_MSG;
#endif
/* add end */
/*
* brief DSL_LINK_SET_MSG.cmd
*/
typedef enum _DSL_LINK_SET_CMD {
DSL_LINK_SET_DOWN = 0, /* down interface */
DSL_LINK_SET_UP, /* up interface */
DSL_LINK_SET_REUP, /* down&up interface */
DSL_LINK_SET_DEL , /* delete interface */
} DSL_LINK_SET_CMD;
/* add by wanghao */
#ifdef INCLUDE_VDSLWAN
/*
* brief VDSL_LINK_SET_MSG.cmd
*/
typedef enum _VDSL_LINK_SET_CMD {
VDSL_LINK_SET_DOWN = 0, /* down interface */
VDSL_LINK_SET_UP, /* up interface */
VDSL_LINK_SET_REUP, /* down&up interface */
VDSL_LINK_SET_DEL , /* delete interface */
} VDSL_LINK_SET_CMD;
#endif
/* add end */
/*
* brief DSL_LINK_WAN_TAG_MSG Message
*/
typedef struct _DSL_LINK_WAN_TAG_MSG {
UINT16 vlanId; /* unique VLAN ID */
UINT8 linkType; /* LinkType */
UINT8 WanTagEnabled; /* the flag if the wan tag vlan is enabled. */
SINT16 wanTagVid; /* wan tag vlan id, namely 802.1Q VLAN ID, 0-4094. */
SINT8 wanTagPr; /* wan tag priority bits, namely 802.1P priority, 0-7 */
} __attribute__((packed)) DSL_LINK_WAN_TAG_MSG;
/*
* brief Upgrade state
*/
typedef enum _UPGRADE_STATE {
UPGRADE_REQ = 0, /* request upgrade */
UPGRADE_TRANSFER, /* transfer image */
UPGRADE_VERIFY, /* verify image */
UPGRADE_WRITE, /* request write to flash */
} UPGRADE_STATE;
/*
* brief Upgrade message
*/
typedef struct _UPGRADE_REQ_MSG {
UINT8 state; /* UPGRADE_REQ */
UINT32 imageSize;
} __attribute__((packed)) UPGRADE_REQ_MSG;
typedef struct _UPGRADE_RESP {
UINT8 state; /* UPGRADE_REQ */
UINT32 ret;
} __attribute__((packed)) UPGRADE_RESP;
typedef struct _UPGRADE_BLOCK_MSG {
UINT8 state; /* UPGRADE_TRANSFER */
UINT16 block; /* block id, bgein 0 */
// UINT16 length; /* valid length in block */
UINT8 data[0]; /* UINT8 data[UPGRADE_BLOCK_SIZE] */
} __attribute__((packed)) UPGRADE_BLOCK_MSG;
typedef struct _UPGRADE_BLOCK_RESP {
UINT8 state; /* UPGRADE_TRANSFER */
UINT16 block; /* next block to receive */
} __attribute__((packed)) UPGRADE_BLOCK_RESP;
typedef struct _UPGRADE_WRITE_MSG {
UINT8 state; /* UPGRADE_WRITE */
} __attribute__((packed)) UPGRADE_WRITE_MSG ;
/*
* brief 6332 LED state
*/
typedef enum _DSL_LED_STATE {
DSL_LED_OFF,
DSL_LED_ON,
DSL_LED_FAIL,
} DSL_LED_STATE;
/*
* brief CMD_LED_CONTROL Message
*/
typedef struct _LED_CONTROL_MSG {
UINT8 led; /* which LED, currently not use */
UINT8 state; /* DSL_LED_STATE */
} __attribute__((packed)) LED_CONTROL_MSG;
#ifdef INCLUDE_WAN_DETECT
#define MAX_PVC_SEARCH_PAIRS 32 /* supports most 32 pairs */
/*
* brief the connection type enumeration
*/
typedef enum _PACKET_TYPE {
PKT_PADO = 0, /* PPPOE detected! */
PKT_DHCP_OFFER, /* DHCP detected! */
PKT_LCP, /* PPPOA detected! */
PKT_UNKOWN,
} PACKET_TYPE;
/*
* brief the status of dsl auto pvc detection.
*/
typedef enum _STATUS_AUTO_PVC {
AUTO_PVC_UNKNOWN = 0, /* Auto pvc never called. */
AUTO_PVC_DETECTING, /* Detecting, at most 2 minutes. */
AUTO_PVC_SUCCEED, /* Succeed, ATUO_PVC_DETECT_RESP should be filled. */
AUTO_PVC_FAILED, /* Detect failed, after all of the pvc pairs has been tried. */
AUTO_PVC_DSL_NOT_READY, /* DSL status is not up. */
} STATUS_AUTO_PVC;
/*
* brief CMD_AUTO_PVC_DETECT response.
*/
typedef struct _AUTO_PVC_DETECT_RESP {
STATUS_AUTO_PVC status; /* the status of the detecting. */
UINT8 vpi; /* the vpi of the detected pvc. */
UINT16 vci; /* the vci of the detected pvc. */
ATM_ENCAPSULATION encap; /* the type of encapsulation. */
PACKET_TYPE type; /* the connection type, PPPOE, DHCP or PPPOA. */
char macAddr[MAC_STR_LEN]; /* the mac address used to detect the pvc. */
} __attribute__((packed)) AUTO_PVC_DETECT_RESP;
/*
* brief CMD_AUTO_PVC_SET_POOL msg.
*/
typedef struct _AUTO_PVC_SET_POOL_MSG {
UINT8 idx; /* the index in the pvc pool to be set. */
UINT8 vpi; /* vpi to be set. */
UINT16 vci; /* vci to be set. */
} __attribute__((packed)) AUTO_PVC_SET_POOL_MSG;
#endif /* INCLUDE_WAN_DETECT */
/**************************************************************************************************/
/* VARIABLES */
/**************************************************************************************************/
/**************************************************************************************************/
/* FUNCTIONS */
/**************************************************************************************************/
#if LOG_LEVEL > LOG_DEBUG
void msg__dumpPacket(const UINT8 *pkt, int size);
#define msg_dumpPacket(pkt, size) \
{ \
MSG_DEBUG(#pkt"=%p "#size"=%d:", pkt, size); \
msg__dumpPacket(pkt, size); \
}
#else
#define msg_dumpPacket(pkt, size)
#endif
/*
* fn void msg_fillChecksum(MSG_REQUEST *hdr)
* brief change byteorder from host to network, then fill checksum field
* details
*
* param[in] hdr - Message to be filled
*
* return N/A
* retval
*
* note
*/
void msg_fillChecksum(MSG_REQUEST *hdr);
/*
* fn UBOOL8 msg_validateChecksum(MSG_REQUEST *hdr)
* brief validate checksum field, then change byteorder from network to host
* details
*
* param[in] hdr - Message to be checked
*
* return UBOOL8
* retval TRUE if valid, FALSE if invalid
*
* note
*/
UBOOL8 msg_validateChecksum(MSG_REQUEST *hdr);
/*
* fn int msg_initSocket(char const *ifname, UINT8 *hwaddr)
* brief init message socket, get MAC of interface
* details
*
* param[in] ifname - interface name
* param[out] hwaddr - MAC of interface
*
* return sock
* retval -1 if failed
*
* note
*/
int msg_initSocket(char const *ifname, UINT8 *hwaddr);
/*
* fn int msg_bindIfName(int sock, char const *ifname)
* brief bind socket to interface
* details
*
* param[in] sock - socket
* param[in] ifname - interface name
*
* return int
* retval 0 if ok, -1 if failed
*
* note
*/
int msg_bindIfName(int sock, char const *ifname);
#endif /* __MSG_COMMON_H__ */
从上面的定义内容中,能看出来ATM是什么吗
最新发布