📄 net_if.h
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK INTERFACE LAYER
*
* ETHERNET
*
* Filename : net_if.h
* Version : V1.86
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s) : (1) Supports Ethernet as described in RFC #894; supports IEEE 802 as described in RFC #1042.
*
* (2) Ethernet implementation conforms to RFC #1122, Section 2.3.3, bullets (a) & (b), but
* does NOT implement bullet (c) :
*
* RFC #1122 LINK LAYER October 1989
*
* 2.3.3 ETHERNET (RFC-894) and IEEE 802 (RFC-1042) ENCAPSULATION
*
* Every Internet host connected to a 10Mbps Ethernet cable :
*
* (a) MUST be able to send and receive packets using RFC-894 encapsulation;
*
* (b) SHOULD be able to receive RFC-1042 packets, intermixed with RFC-894 packets; and
*
* (c) MAY be able to send packets using RFC-1042 encapsulation.
*
* (3) REQUIREs the following network protocol files in network directories :
*
* where
* <Network Protocol Suite> directory path for network protocol suite
*
* (a) Packet-based Network Interface Layer located in the following network directory :
*
* \<Network Protocol Suite>\IF\
*
* (b) Address Resolution Protocol Layer located in the following network directory :
*
* \<Network Protocol Suite>\
*
* See also 'net_arp.h Note #1'.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <net_if_pkt.h> /* See 'net_if.h Note #3a'. */
#include <net_arp.h> /* See 'net_if.h Note #3b'. */
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#define NET_IF_MODULE_ETHERNET
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef NET_IF_MODULE
#define NET_IF_EXT
#else
#define NET_IF_EXT extern
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NETWORK INTERFACE / ETHERNET DEFINES
*********************************************************************************************************
*/
#define NET_IF_ADDR_MAC_PRESENT
#define NET_IF_ADDR_SIZE 6 /* 48-bit MAC/net addr size. */
#define NET_IF_ADDR_SIZE_MAC NET_IF_ADDR_SIZE
#define NET_IF_ADDR_BROADCAST 0xFFFFFFFFFFFF
#define NET_IF_ADDR_BROADCAST_xx 0xFF /* ALL broadcast addr octet vals identical. */
#define NET_IF_ADDR_BROADCAST_00 0xFF
#define NET_IF_ADDR_BROADCAST_01 0xFF
#define NET_IF_ADDR_BROADCAST_02 0xFF
#define NET_IF_ADDR_BROADCAST_03 0xFF
#define NET_IF_ADDR_BROADCAST_04 0xFF
#define NET_IF_ADDR_BROADCAST_05 0xFF
/*
*********************************************************************************************************
* NETWORK INTERFACE LAYER / ETHERNET ERROR CODES
*
* Note(s) : (1) ALL IF-independent error codes #define'd in 'net_err.h';
* ALL Ethernet-specific error codes #define'd in this 'net_if.h'.
*
* (2) Network error code '11,000' series reserved for network interfaces.
*********************************************************************************************************
*/
#define NET_IF_ERR_INVALID_MAC 11400 /* Invalid MAC addr. */
#define NET_IF_ERR_INVALID_PROTOCOL 11410 /* Invalid protocol. */
#define NET_IF_ERR_INVALID_ETHER_TYPE 11411 /* Invalid Ethernet type. */
#define NET_IF_ERR_INVALID_LLC_DSAP 11420 /* Invalid IEEE 802.2 LLC DSAP val. */
#define NET_IF_ERR_INVALID_LLC_SSAP 11421 /* Invalid IEEE 802.2 LLC SSAP val. */
#define NET_IF_ERR_INVALID_LLC_CTRL 11422 /* Invalid IEEE 802.2 LLC Ctrl val. */
#define NET_IF_ERR_INVALID_SNAP_CODE 11430 /* Invalid IEEE 802.2 SNAP OUI val. */
#define NET_IF_ERR_INVALID_SNAP_TYPE 11431 /* Invalid IEEE 802.2 SNAP Type val. */
#define NET_IF_ERR_TX_BROADCAST 11600 /* Tx broadcast on local net. */
#define NET_IF_ERR_TX_ARP 11601 /* Tx requires ARP hw addr binding. */
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK INTERFACE HEADER DEFINES
*
* Note(s) : (1) NET_IF_HDR_SIZE_MAX's ideal #define'tion :
*
* (A) max( Ether Hdr, IEEE 802 Hdr)
*
* (a) However, since NET_IF_HDR_SIZE_MAX is used ONLY for network transmit & IEEE 802 is
* NEVER transmitted (see 'net_if.h Note #2'), NET_IF_HDR_SIZE_MAX MUST be #define'd
* with hard-coded knowledge that Ethernet is the only supported frame encapsulation
* for network transmit.
*
* (b) The following network interface values MUST be pre-#define'd in 'net_def.h' PRIOR to
* 'net_cfg.h' so that the developer can configure the network interface for the correct
* network interface link layer values (see 'net_def.h NETWORK INTERFACE LAYER DEFINES'
* & 'net_cfg_net.h NETWORK INTERFACE LAYER CONFIGURATION') :
*
* (1) NET_IF_HDR_SIZE_ETHER 14
* (2) NET_IF_HDR_SIZE_MAX NET_IF_HDR_SIZE_ETHER
*********************************************************************************************************
*/
#define NET_IF_HDR_SIZE_BASE_ETHER 14 /* Ethernet base hdr size. */
#define NET_IF_HDR_SIZE_BASE_IEEE_802 8 /* IEEE 802 base hdr size. */
#if 0 /* See Note #1b1. */
#define NET_IF_HDR_SIZE_ETHER NET_IF_HDR_SIZE_BASE_ETHER
#endif
#define NET_IF_HDR_SIZE_IEEE_802 (NET_IF_HDR_SIZE_BASE_ETHER + NET_IF_HDR_SIZE_BASE_IEEE_802)
#define NET_IF_HDR_SIZE_MIN (DEF_MIN(NET_IF_HDR_SIZE_ETHER, NET_IF_HDR_SIZE_IEEE_802))
#if 0 /* See Notes #1a & #1b2. */
#define NET_IF_HDR_SIZE_MAX NET_IF_HDR_SIZE_ETHER
#endif
/* See Note #1a. */
#define NET_IF_HDR_SIZE_TOT_MIN NET_IF_HDR_SIZE_ETHER
#define NET_IF_HDR_SIZE_TOT_MAX NET_IF_HDR_SIZE_ETHER
#define NET_IF_HDR_SIZE_ADDR NET_IF_ADDR_SIZE
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK INTERFACE TOTAL LENGTH & MAXIMUM TRANSMISSION UNIT (MTU) DEFINES
*
* Note(s) : (1) NET_IF_MTU's ideal #define'tion :
*
* (A) min( Ether MTU, IEEE 802 MTU)
*
* (a) However, since NET_IF_MTU is used by higher network protocol layers ONLY for network
* transmit & IEEE 802 is NEVER transmitted (see 'net_if.h Note #2'), NET_IF_MTU MUST
* be #define'd with hard-coded knowledge that Ethernet is the only supported encapsulation
* for network interface transmit.
*
* (2) Ethernet & IEEE 802 minimum frame size is 64 octets (see RFC #894, Section 'Frame Format'
* & RFC #1042, Section 'Frame Format and MAC Level Issues : For IEEE 802.3'). However, the
* 4-octet CRC trailer is included in this 64 octet minimum frame size. Therefore, the minimum
* size for receive & transmit packets is adjusted by the CRC size.
*
* (3) Since network data value macro's appropriately convert data values from any CPU addresses,
* word-aligned or not; network receive & transmit packets are NOT required to ensure that
* network packet headers (ARP/IP/UDP/TCP/etc.) & header members will locate on CPU word-
* aligned addresses. Therefore, network interface frame packets are NOT required to start
* on any specific buffer indices.
*
* See also 'net_util.h NETWORK DATA VALUE MACRO'S Note #2b'
* & 'net_buf.h NETWORK BUFFER INDEX & SIZE DEFINES Note #2'.
*********************************************************************************************************
*/
#define NET_IF_MTU_ETHER 1500
#define NET_IF_MTU_IEEE_802 1492
/* See Note #1. */
#define NET_IF_MTU_MIN (DEF_MIN(NET_IF_MTU_ETHER, NET_IF_MTU_IEEE_802))
#define NET_IF_MTU_MAX (DEF_MAX(NET_IF_MTU_ETHER, NET_IF_MTU_IEEE_802))
#define NET_IF_MTU NET_IF_MTU_ETHER
#define NET_IF_FRAME_HDR_SIZE NET_IF_HDR_SIZE_ETHER
#define NET_IF_FRAME_HDR_SIZE_ETHER NET_IF_HDR_SIZE_ETHER
#define NET_IF_FRAME_HDR_SIZE_IEEE_802 NET_IF_HDR_SIZE_IEEE_802
#define NET_IF_FRAME_CRC_SIZE 4
#define NET_IF_FRAME_MIN_CRC_SIZE 64 /* See Note #2. */
#define NET_IF_FRAME_MIN_SIZE (NET_IF_FRAME_MIN_CRC_SIZE - NET_IF_FRAME_CRC_SIZE)
#define NET_IF_FRAME_MAX_SIZE (NET_IF_MTU + NET_IF_HDR_SIZE_MAX )
#define NET_IF_FRAME_MAX_CRC_SIZE (NET_IF_FRAME_MAX_SIZE + NET_IF_FRAME_CRC_SIZE)
#define NET_IF_PKT_SIZE_MIN NET_IF_FRAME_MIN_SIZE
#define NET_IF_PKT_SIZE_MAX NET_IF_FRAME_MAX_SIZE
/* See Note #3. */
#define NET_IF_RX_IX NET_BUF_DATA_RX_IX
/*$PAGE*/
/*
*********************************************************************************************************
* ETHERNET DEFINES
*********************************************************************************************************
*/
/* ---------------- ETHER FRAME TYPES ----------------- */
#define NET_IF_FRAME_ETHER_TYPE_IP 0x0800
#define NET_IF_FRAME_ETHER_TYPE_ARP 0x0806
#define NET_IF_FRAME_ETHER_TYPE_RARP 0x8035 /* See 'net_def.h NETWORK PROTOCOL TYPES Note #1'. */
/*
*********************************************************************************************************
* IEEE 802 DEFINES
*
* Note(s) : (1) SNAP 'Organizational Unique Identifier' (OUI) abbreviated to 'SNAP' for some SNAP OUI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -