Protocol.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /************************************
  2. * Protocol.h
  3. *************************************/
  4. #ifndef __PROTOCOL_H__
  5. #define __PROTOCOL_H__
  6. #define IPV4 4
  7. #define IPV6 6
  8. struct ArpHeader {
  9. struct arphdr arp;
  10. unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
  11. unsigned char ar_sip[4]; /* sender IP address */
  12. unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
  13. unsigned char ar_tip[4]; /* target IP address */
  14. };
  15. struct bcm_transport_header {
  16. union {
  17. struct udphdr uhdr;
  18. struct tcphdr thdr;
  19. };
  20. } __packed;
  21. enum bcm_ip_frame_type {
  22. eNonIPPacket,
  23. eIPv4Packet,
  24. eIPv6Packet
  25. };
  26. enum bcm_eth_frame_type {
  27. eEthUnsupportedFrame,
  28. eEth802LLCFrame,
  29. eEth802LLCSNAPFrame,
  30. eEth802QVLANFrame,
  31. eEthOtherFrame
  32. };
  33. struct bcm_eth_packet_info {
  34. enum bcm_ip_frame_type eNwpktIPFrameType;
  35. enum bcm_eth_frame_type eNwpktEthFrameType;
  36. unsigned short usEtherType;
  37. unsigned char ucDSAP;
  38. };
  39. struct bcm_eth_q_frame {
  40. struct bcm_eth_header EThHdr;
  41. unsigned short UserPriority:3;
  42. unsigned short CFI:1;
  43. unsigned short VLANID:12;
  44. unsigned short EthType;
  45. } __packed;
  46. struct bcm_eth_llc_frame {
  47. struct bcm_eth_header EThHdr;
  48. unsigned char DSAP;
  49. unsigned char SSAP;
  50. unsigned char Control;
  51. } __packed;
  52. struct bcm_eth_llc_snap_frame {
  53. struct bcm_eth_header EThHdr;
  54. unsigned char DSAP;
  55. unsigned char SSAP;
  56. unsigned char Control;
  57. unsigned char OUI[3];
  58. unsigned short usEtherType;
  59. } __packed;
  60. struct bcm_ethernet2_frame {
  61. struct bcm_eth_header EThHdr;
  62. } __packed;
  63. #define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800)
  64. #define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd)
  65. #define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100)
  66. /* Per SF CS Specification Encodings */
  67. enum bcm_spec_encoding {
  68. eCSSpecUnspecified = 0,
  69. eCSPacketIPV4,
  70. eCSPacketIPV6,
  71. eCS802_3PacketEthernet,
  72. eCS802_1QPacketVLAN,
  73. eCSPacketIPV4Over802_3Ethernet,
  74. eCSPacketIPV6Over802_3Ethernet,
  75. eCSPacketIPV4Over802_1QVLAN,
  76. eCSPacketIPV6Over802_1QVLAN,
  77. eCSPacketUnsupported
  78. };
  79. #define IP6_HEADER_LEN 40
  80. #define IP_VERSION(byte) (((byte&0xF0)>>4))
  81. #define MAC_ADDRESS_SIZE 6
  82. #define ETH_AND_IP_HEADER_LEN (14 + 20)
  83. #define L4_SRC_PORT_LEN 2
  84. #define L4_DEST_PORT_LEN 2
  85. #define CTRL_PKT_LEN (8 + ETH_AND_IP_HEADER_LEN)
  86. #define ETH_ARP_FRAME 0x806
  87. #define ETH_IPV4_FRAME 0x800
  88. #define ETH_IPV6_FRAME 0x86DD
  89. #define UDP 0x11
  90. #define TCP 0x06
  91. #define ARP_OP_REQUEST 0x01
  92. #define ARP_OP_REPLY 0x02
  93. #define ARP_PKT_SIZE 60
  94. /* This is the format for the TCP packet header */
  95. struct bcm_tcp_header {
  96. unsigned short usSrcPort;
  97. unsigned short usDestPort;
  98. unsigned long ulSeqNumber;
  99. unsigned long ulAckNumber;
  100. unsigned char HeaderLength;
  101. unsigned char ucFlags;
  102. unsigned short usWindowsSize;
  103. unsigned short usChkSum;
  104. unsigned short usUrgetPtr;
  105. };
  106. #define TCP_HEADER_LEN sizeof(struct bcm_tcp_header)
  107. #define TCP_ACK 0x10 /* Bit 4 in tcpflags field. */
  108. #define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4)
  109. #endif /* __PROTOCOL_H__ */