-#define EFI_NET_LITTLE_ENDIAN\r
-\r
-typedef UINT32 IP4_ADDR;\r
-typedef UINT32 TCP_SEQNO;\r
-typedef UINT16 TCP_PORTNO;\r
-\r
-enum {\r
- NET_ETHER_ADDR_LEN = 6,\r
- NET_IFTYPE_ETHERNET = 0x01,\r
-\r
- EFI_IP_PROTO_UDP = 0x11,\r
- EFI_IP_PROTO_TCP = 0x06,\r
- EFI_IP_PROTO_ICMP = 0x01,\r
-\r
- //\r
- // The address classfication\r
- //\r
- IP4_ADDR_CLASSA = 1,\r
- IP4_ADDR_CLASSB,\r
- IP4_ADDR_CLASSC,\r
- IP4_ADDR_CLASSD,\r
- IP4_ADDR_CLASSE,\r
-\r
- IP4_MASK_NUM = 33,\r
-};\r
-\r
-#pragma pack(1)\r
-\r
-//\r
-// Ethernet head definition\r
-//\r
-typedef struct {\r
- UINT8 DstMac [NET_ETHER_ADDR_LEN];\r
- UINT8 SrcMac [NET_ETHER_ADDR_LEN];\r
- UINT16 EtherType;\r
-} ETHER_HEAD;\r
-\r
-\r
-//\r
-// The EFI_IP4_HEADER is hard to use because the source and\r
-// destination address are defined as EFI_IPv4_ADDRESS, which\r
-// is a structure. Two structures can't be compared or masked\r
-// directly. This is why there is an internal representation.\r
-//\r
-typedef struct {\r
-#ifdef EFI_NET_LITTLE_ENDIAN\r
- UINT8 HeadLen : 4;\r
- UINT8 Ver : 4;\r
-#else\r
- UINT8 Ver : 4;\r
- UINT8 HeadLen : 4;\r
-#endif\r
- UINT8 Tos;\r
- UINT16 TotalLen;\r
- UINT16 Id;\r
- UINT16 Fragment;\r
- UINT8 Ttl;\r
- UINT8 Protocol;\r
- UINT16 Checksum;\r
- IP4_ADDR Src;\r
- IP4_ADDR Dst;\r
-} IP4_HEAD;\r
-\r
-\r
-//\r
-// ICMP head definition. ICMP message is categoried as either an error\r
-// message or query message. Two message types have their own head format.\r
-//\r
-typedef struct {\r
- UINT8 Type;\r
- UINT8 Code;\r
- UINT16 Checksum;\r
-} IP4_ICMP_HEAD;\r
-\r
-typedef struct {\r
- IP4_ICMP_HEAD Head;\r
- UINT32 Fourth; // 4th filed of the head, it depends on Type.\r
- IP4_HEAD IpHead;\r
-} IP4_ICMP_ERROR_HEAD;\r
-\r
-typedef struct {\r
- IP4_ICMP_HEAD Head;\r
- UINT16 Id;\r
- UINT16 Seq;\r
-} IP4_ICMP_QUERY_HEAD;\r
-\r
-\r
-//\r
-// UDP header definition\r
-//\r
-typedef struct {\r
- UINT16 SrcPort;\r
- UINT16 DstPort;\r
- UINT16 Length;\r
- UINT16 Checksum;\r
-} EFI_UDP4_HEADER;\r
-\r
-\r
-//\r
-// TCP header definition\r
-//\r
-typedef struct {\r
- TCP_PORTNO SrcPort;\r
- TCP_PORTNO DstPort;\r
- TCP_SEQNO Seq;\r
- TCP_SEQNO Ack;\r
-#ifdef EFI_NET_LITTLE_ENDIAN\r
- UINT8 Res : 4;\r
- UINT8 HeadLen : 4;\r
-#else\r
- UINT8 HeadLen : 4;\r
- UINT8 Res : 4;\r
-#endif\r
- UINT8 Flag;\r
- UINT16 Wnd;\r
- UINT16 Checksum;\r
- UINT16 Urg;\r
-} TCP_HEAD;\r
-\r
-#pragma pack()\r
-\r
-#define NET_MAC_EQUAL(pMac1, pMac2, Len) \\r
- (NetCompareMem ((pMac1), (pMac2), Len) == 0)\r
-\r
-#define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \\r
- (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))\r
-\r
-#ifdef EFI_NET_LITTLE_ENDIAN\r
-#define NTOHL(x) (UINT32)((((UINT32) (x) & 0xff) << 24) | \\r
- (((UINT32) (x) & 0xff00) << 8) | \\r
- (((UINT32) (x) & 0xff0000) >> 8) | \\r
- (((UINT32) (x) & 0xff000000) >> 24))\r
-\r
-#define HTONL(x) NTOHL(x)\r
-\r
-#define NTOHS(x) (UINT16)((((UINT16) (x) & 0xff) << 8) | \\r
- (((UINT16) (x) & 0xff00) >> 8))\r
-\r
-#define HTONS(x) NTOHS(x)\r
-#else\r
-#define NTOHL(x) (UINT32)(x)\r
-#define HTONL(x) (UINT32)(x)\r
-#define NTOHS(x) (UINT16)(x)\r
-#define HTONS(x) (UINT16)(x)\r
-#endif\r
-\r
-//\r
-// Test the IP's attribute, All the IPs are in host byte order.\r
-//\r
-#define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)\r
-#define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)\r
-#define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))\r
-#define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != IP4_MASK_NUM)\r
-\r
-//\r
-// Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.\r
-//\r
-#define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))\r
-#define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))\r
-#define EFI_IP4_EQUAL(Ip1, Ip2) (NetCompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)\r
-\r
-INTN\r
-NetGetMaskLength (\r
- IN IP4_ADDR Mask\r
- );\r
-\r
-INTN\r
-NetGetIpClass (\r
- IN IP4_ADDR Addr\r
- );\r
-\r
-BOOLEAN\r
-Ip4IsUnicast (\r
- IN IP4_ADDR Ip,\r
- IN IP4_ADDR NetMask\r
- );\r
-\r