📄 en_encap.h
字号:
typedef struct encap_obj_hdr
{
UINT16 iObj_type; /* Structure type code */
UINT16 iObj_length; /* Length of remaining structure */
} GNU_PACKED ENCAP_OBJ_HDR;
#define ENCAP_OBJ_HDR_SIZE 4 /* Gets around alignment */
/*
* Definition of a socket address. Matches the old-style socket
* address still in use by older BSD-derived network implementations.
*/
typedef struct encap_sockaddr
{
INT16 iSin_family;
INT16 iSin_port;
UINT32 lSin_addr;
UINT8 abSin_zero[8];
} GNU_PACKED ENCAP_SOCKADDR;
#define ENCAP_SOCKADDR_SIZE 16 /* For consistent lengths */
/*
* Structure which provides information about the Target of an ENCAP command.
*/
typedef struct encap_target
{
UINT16 iS_version; /* Protocol version */
UINT16 iS_flags; /* Capability flags */
ENCAP_SOCKADDR s_sock; /* Socket address */
UINT8 achS_name[ENCAP_OBJ_NAME_SIZE]; /* Server Name */
} GNU_PACKED ENCAP_TARGET;
#define ENCAP_TARGET_SIZE sizeof(ENCAP_TARGET)
/*
* The definition for a target structure.
*/
typedef struct encap_obj_target
{
ENCAP_OBJ_HDR sH; /* Standard object header */
ENCAP_TARGET sS; /* Target information */
} GNU_PACKED ENCAP_OBJ_TARGET;
#define ENCAP_OBJ_TARGET_SIZE sizeof(ENCAP_OBJ_TARGET)
/*
* Structure which provides information about the services supported by
* a target.
*/
typedef struct encap_service
{
UINT16 iS_version;
UINT16 iS_flags;
UINT8 achS_name[ENCAP_OBJ_NAME_SIZE];
} GNU_PACKED ENCAP_SERVICE;
#define ENCAP_SERVICE_SIZE sizeof(ENCAP_SERVICE)
/*
* The definition for a service object.
*/
typedef struct encap_obj_service
{
ENCAP_OBJ_HDR sH; /* Standard object header */
ENCAP_SERVICE sS; /* Service information */
} GNU_PACKED ENCAP_OBJ_SERVICE;
#define ENCAP_OBJ_SERVICE_SIZE sizeof(ENCAP_OBJ_SERVICE)
/*
* Command specific data for the REGISTER SESSION command. Request and response
* data have the same format.
*/
typedef struct encap_rc_data
{
UINT16 iRc_version; /* Requested/supported protocol revision */
UINT16 iRc_flags; /* Requested/supported option flags */
} GNU_PACKED ENCAP_RC_DATA;
#define ENCAP_RC_DATA_SIZE sizeof(ENCAP_RC_DATA)
/*
* Command specific data for the data transfer commands (SEND_PACKET, etc).
*/
typedef struct encap_dt_hdr
{
UINT32 lDt_target; /* Communications target identifier */
UINT16 iDt_timeout; /* Requested timeout */
} GNU_PACKED ENCAP_DT_HDR;
#define ENCAP_DT_HDR_SIZE 6 /* Gets around alignment */
/* Definitions for Common Packet Format Encoding. The data portion of a
* SendPacket command has a common general-purpose format used for
* encapsulation. The format consists of a set of tagged fields
* preceeded by a two byte count field. The count field indicates
* the number of tags in the packet.
*/
/* All tags have a common format header. */
typedef struct cpf_tag
{
UINT16 iTag_type; /* Type of tag */
UINT16 iTag_length; /* Length of field (excludes tag) */
} GNU_PACKED CPF_TAG;
#define CPF_TAG_SIZE 4 /* Gets around alignment */
/* Common Packet Format (CPF) header for CLASS 1 I/O packets. This structure
* is a shorthand for creating/decoding the ENCAP protocol CPF format used by
* I/O. It may need to be changed if ENCAP is ever changed or modified.
*/
typedef struct cpfhdr
{
UINT16 iS_count; /* Structure count */
UINT16 iAs_type; /* Address structure type */
UINT16 iAs_length; /* Address structure length */
UINT16 aiAs_cid[2]; /* Address structure connection id */
UINT16 aiAs_seq[2]; /* Address structure sequence number */
UINT16 iDs_type; /* Data structure type */
UINT16 iDs_length; /* Data structure length */
} GNU_PACKED CPFHDR, *CPFHDR_P;
#define CPFHDR_SIZE sizeof(CPFHDR)
/* Define format for the currently defined and supported tag data. These definitions
* DO NOT include the common header (type, length) which precedes each tag.
*/
/* NULL ADDRESS TAG consists of the header. */
/* CONNECTED ADDRESS TAG */
typedef struct cpf_adr_connected
{
UINT32 lCid; /* Connection identifier */
} GNU_PACKED CPF_ADR_CONNECTED;
typedef struct cpf_adr_sequenced
{
UINT32 lCid; /* Connection identifier */
UINT32 lSeq; /* Connection sequence numbered */
} GNU_PACKED CPF_ADR_SEQUENCED;
/* UCMM PACKET TAG consists of the header */
/* CONNECTED PACKET TAG consists of the header */
/* Define Generic Address Tag */
typedef struct cpf_adr_tag
{
CPF_TAG sTag; /* Common Tag */
union
{
UINT8 g[1]; /* Generic data */
CPF_ADR_CONNECTED sC; /* Connected address */
CPF_ADR_SEQUENCED sS; /* Sequenced address */
} data;
UINT8 pad[1];
} GNU_PACKED CPF_ADR_TAG;
#define CPF_ADR_TAG_SIZE sizeof(CPF_ADR_TAG)
/* Define Generic Packet Tag */
typedef struct cpf_pkt_tag
{
CPF_TAG sTag; /* Common Tag */
union
{
UINT8 g[1]; /* Generic data */
} data;
} GNU_PACKED CPF_PKT_TAG;
#define CPF_PKT_TAG_SIZE sizeof(CPF_PKT_TAG)
/* Define Generic Socket Address Tag */
typedef struct cpf_sockaddr_tag
{
CPF_TAG sTag; /* Common Tag */
union
{
UINT8 g[1]; /* Generic data */
ENCAP_SOCKADDR sSo;
} sock;
} GNU_PACKED CPF_SOCKADDR_TAG;
#define CPF_SOCKADDR_TAG_SIZE (CPF_TAG_SIZE + ENCAP_SOCKADDR_SIZE)
/* Structure containing the source socket address and decoded socket
* address tags that may be present in CIP Forward Open messages sent
* between connection managers.
*/
typedef struct
{
struct sockaddr_in sEce_sin; /* ENCAP session source address */
struct sockaddr_in sReceive; /* Socket address for receiving data */
struct sockaddr_in sTransmit; /* Socket address for tranmitting data */
} ECM_SOCK_ADDR;
/* END NEW...*/
/* Format of multicast address allocation descriptor. An IP multicast address
* is allocated whenever an CIP connection needs to PRODUCE data for
* a multicast CIP connection.
*/
typedef struct
{
INT32 lFree; /* Entry is available for allocation */
struct sockaddr_in sMc_addr; /* Actual multicast address */
} MCAST, *MCAST_P;
/* Format of the table containing multicast addresses for CIP. The table itself
* has a separate valid flag to indicate whether or not the table entries have
* been generated. The multicast addresses used for production change if there
* are any changes to the IP configuration.
*/
typedef struct
{
INT32 lValid; /* Table is valid */
MCAST asMcast[NUM_MCAST_BLOCKS]; /* Multicast address entries */
} CIP_MCAST_TABLE;
/*
* Internal handle used to identify ENCAP connection endpoints. Every endpoint has
* a unique handle described by the structure defined below. There are two types
* of endpoints:
*
* 1.) INBOUND - Initiated by another node. The other node establishes an
* ENCAP session by sending the RegisterClient command.
* Identified by the constant ECI_TYPE_INBOUND
* 2.) OUTBOUND - Initiated by local process. Local task establishes an ENCAP session to
* another node by sending the RegisterClient command.
* Identified by the constant ECI_TYPE_OUTBOUND
*
* A session identifier is present in most encap messages.
*
* For OUTBOUND sessions the target of the RegisterClient command
* generates a session identifier that is meaningful to the target.
* An outbound session has a session identifier that is different
* from the connection endpoint identifier.
*
* For INBOUND sessions the session and connection endpoint identifiers are the same.
*
*/
typedef union
{
UINT32 l; /* longword handle */
struct
{
unsigned seq : 16; /* sequence count */
unsigned type : 8; /* type of INBOUND or originator */
unsigned idx : 8; /* table index for quick lookups */
} u;
} ECI;
typedef struct
{
INT32 lState; /* state of the entry */
UINT32 lFlags; /* Generic Options Flags. */
ECI sEid; /* ENCAP connection endpoint id */
UINT32 lSid; /* ENCAP session id */
struct sockaddr_in sAddr; /* IP address of the remote host */
MCAST_P psMcast; /* Allocated Multicast address (if any) */
ECM_SOCK_ADDR sSa; /* decoded socket address tags */
ENCAP_SERVICE sServices; /* Services supported by endpoint (outbound) */
UINT8 achName[MAXHOSTNAMELEN]; /* DNS name (if any) */
UINT32 lSockFd; /* fd associated with the connection */
UINT32 lRecvTaskID; /* ID of the receive task */
UINT32 lSendTaskID; /* ID of the receive task */
OE_Q_ID sOutputQ; /* Message Queue for task handling TCP Output */
} ECE;
/* Note the following definition assumes that the driver will read the
* fixed size ENCAP header directly into the hdr field. Therefore
* space is provided to read in the remaining fields and data of a typical
* CIP message (rounded to the next longword).
*
* Maximum amount of data in PKTBUF
*/
#define PKTBUF_MAX_DATA (((ENCAP_DT_HDR_SIZE + ENCAP_OBJ_LIST_SIZE + \
CPF_ADR_TAG_SIZE + CPF_PKT_TAG_SIZE + CIP_MAX_PACKET + \
(2 * (ENCAP_OBJ_HDR_SIZE + ENCAP_SOCKADDR_SIZE))) \
+ 3) & ~3)
typedef struct pktbuf
{
ECE sEce; /* Copy of the original ECE. Since an ECE can be free'd while
a message is in progress, passing by value rather than
reference is prefered */
struct
{
ENCAPH sHdr; /* ENCAP command header */
ENCAP_DT_HDR sDt_hdr; /* ENCAP Data Transfer header */
ENCAP_OBJ_LIST sObj_list; /* ENCAP object list count */
CPF_ADR_TAG sAdr_tag; /* ENCAP address tag */
CPF_PKT_TAG sPkt_tag; /* ENCAP packet tag */
UINT32 lValid; /* Valid fields in encap area */
} sEncap;
UINT32 lFlags; /* Generic flags for use by targets */
INT32 lLength; /* Length of data area */
void *pData; /* Pointer into packet data */
void *pAdd; /* Addendum pointer */
INT32 lAdd_len; /* Addendum length */
CB_ComBufType *pCb; /* Pointer to commbuffer */
UINT8 abData[PKTBUF_MAX_DATA];/* Packet data */
OE_Q_ID sOutputQ; /* Queue for task handling TCP Output */
} GNU_PACKED PKTBUF, *PKTBUF_P;
#define PKTBUF_SIZE sizeof(PKTBUF)
/*
* Define the lowest level structures used to perform I/O to a socket.
* These structures are defined using I/O vectors to allow scatter/gather
* writing and reading of data.
*/
typedef struct sock_wdesc
{
INT32 lW_state; /* Write state */
PKTBUF_P psW_msg; /* Buffer in progress (if any) */
INT32 lW_length; /* Total message length */
struct iovec *psW_iov; /* Pointer to first vector of message */
INT32 lW_iovlen; /* Number of vector elements */
struct iovec asW_iovec[NWVEC]; /* Scatter/gather I/O */
} SOCK_WDESC;
/****************************************************************************
**
** Globals
**
*****************************************************************************
*/
extern INT32 lEncapServerPort; /* ENCAP connection port */
/****************************************************************************
**
** Services
**
*****************************************************************************
*/
/*---------------------------------------------------------------------------
**
** en_cd_CheckSocketAddresses()
**
** This function checks the socket addresses extracted from an ENCAP
** message and verifies that they are compatible with the specified
** type of network connection.
**
**---------------------------------------------------------------------------
**
** Inputs:
** ECM_SOCK_ADDR *sa pointer to connection parameters
** INT32 ot_type O->T connection type
** INT32 to_type T->O connection type
**
**
** Outputs:
** none
**
** Return
** INT32
** TRUE addresses consistent for connection type
** FALSE addresses not consistent for connection type
**
** Usage:
** en_cd_CheckSocketAddresses();
**
**---------------------------------------------------------------------------
*/
EXTFUNC INT32 en_cd_CheckSocketAddresses( ECM_SOCK_ADDR *sa, INT32 ot_type, INT32 to_type );
/*---------------------------------------------------------------------------
**
** en_cd_GetSocketAddresses()
**
** This function will extract additional socket addressing tags
** from an ENCAP Common Packet Format message.
**
** Assumes that basic verification of the tags has already been performed
** so that this function really needs to do no semantic checking.
**
**---------------------------------------------------------------------------
**
** Inputs:
** PKTBUF_P msg pointer to PKTBUF with possible tags
** ECM_SOCK_ADDR *sa pointer to socket addresses
**
** Outputs:
** none
**
** Return
** none
**
** Usage:
** en_cd_GetSocketAddresses();
**
**---------------------------------------------------------------------------
*/
EXTFUNC void en_cd_GetSocketAddresses( PKTBUF_P msg, ECM_SOCK_ADDR *sa );
/*---------------------------------------------------------------------------
**
** en_cd_SetSocketAddresses()
**
** This function will insert additional socket addressing tags
** into an ENCAP Common Packet Format message.
**
** The tags are created in a scratch area and then copied to avoid
** byte alignment concerns. This function assumes that the rest of
** the packet fields have already been created.
**---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -