Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.0 KiB

  1. /*++
  2. Copyright(c) 1998,99 Microsoft Corporation
  3. Module Name:
  4. util.h
  5. Abstract:
  6. Windows Load Balancing Service (WLBS)
  7. Driver - media support definitions
  8. Author:
  9. kyrilf
  10. --*/
  11. #ifndef _Util_h_
  12. #define _Util_h_
  13. #include <ndis.h>
  14. #include <xfilter.h>
  15. #include "wlbsparm.h"
  16. /* CONSTANTS */
  17. /* media-specific constants */
  18. #define ETHERNET_DESTINATION_FIELD_OFFSET 0
  19. #define ETHERNET_SOURCE_FIELD_OFFSET 6
  20. #define ETHERNET_LENGTH_FIELD_OFFSET 12
  21. #define ETHERNET_LENGTH_FIELD_SIZE 2
  22. #define ETHERNET_ADDRESS_FIELD_SIZE 6
  23. #define ETHERNET_HEADER_SIZE 14
  24. /* flags are in byte 0 of ethernet address */
  25. #define ETHERNET_GROUP_FLAG 0x1
  26. #define ETHERNET_LAA_FLAG 0x2
  27. /* max frame size we expect to generate */
  28. #define CVY_MAX_FRAME_SIZE 1500
  29. /* TYPES */
  30. #pragma pack(1)
  31. /* ethernet media header type */
  32. typedef struct
  33. {
  34. UCHAR data [ETHERNET_ADDRESS_FIELD_SIZE];
  35. }
  36. CVY_ETHERNET_ADR, * PCVY_ETHERNET_ADR;
  37. typedef struct
  38. {
  39. UCHAR data [ETHERNET_LENGTH_FIELD_SIZE];
  40. }
  41. CVY_ETHERNET_LEN, * PCVY_ETHERNET_LEN;
  42. typedef struct
  43. {
  44. CVY_ETHERNET_ADR dst;
  45. CVY_ETHERNET_ADR src;
  46. CVY_ETHERNET_LEN len;
  47. }
  48. CVY_ETHERNET_HDR, * PCVY_ETHERNET_HDR;
  49. typedef union
  50. {
  51. CVY_ETHERNET_HDR ethernet;
  52. }
  53. CVY_MEDIA_HDR, * PCVY_MEDIA_HDR;
  54. typedef union
  55. {
  56. CVY_ETHERNET_ADR ethernet;
  57. }
  58. CVY_MAC_ADR, * PCVY_MAC_ADR;
  59. /* V1.3.1b medium independent MAC address manipulation routines - note that these
  60. are optimized for speed and assume that all mediums have the same size addresses.
  61. NOTE: The seemingly silly format of these macros is simply to leave fenceposts
  62. for the future additions of other supported mediums. */
  63. #define CVY_MAC_SRC_OFF(m) ((m) == NdisMedium802_3 ? ETHERNET_SOURCE_FIELD_OFFSET : ETHERNET_SOURCE_FIELD_OFFSET)
  64. #define CVY_MAC_DST_OFF(m) ((m) == NdisMedium802_3 ? ETHERNET_DESTINATION_FIELD_OFFSET : ETHERNET_DESTINATION_FIELD_OFFSET)
  65. #define CVY_MAC_HDR_LEN(m) ((m) == NdisMedium802_3 ? sizeof (CVY_ETHERNET_HDR) : sizeof (CVY_ETHERNET_HDR))
  66. #define CVY_MAC_ADDR_LEN(m) ((m) == NdisMedium802_3 ? ETHERNET_ADDRESS_FIELD_SIZE : ETHERNET_ADDRESS_FIELD_SIZE)
  67. #define CVY_MAC_ADDR_BCAST(m,a) (((PUCHAR)(a))[0] == 0xff)
  68. #define CVY_MAC_ADDR_MCAST(m,a) (((PUCHAR)(a))[0] & 0x1)
  69. #define CVY_MAC_ADDR_GROUP_SET(m,a) ((((PUCHAR)(a))[0]) |= 0x1)
  70. #define CVY_MAC_ADDR_GROUP_TOGGLE(m,a) ((((PUCHAR)(a))[0]) ^= 0x1)
  71. #define CVY_MAC_ADDR_LAA_SET(m,a) ((((PUCHAR)(a))[0]) |= 0x2)
  72. #define CVY_MAC_ADDR_LAA_TOGGLE(m,a) ((((PUCHAR)(a))[0]) ^= 0x2)
  73. #define CVY_MAC_ADDR_COMP(m,a,b) ((* (ULONG UNALIGNED *)(a) == * (ULONG UNALIGNED *)(b)) && \
  74. (* (USHORT UNALIGNED *)((PUCHAR)(a) + sizeof (ULONG)) == \
  75. * (USHORT UNALIGNED *)((PUCHAR)(b) + sizeof (ULONG))))
  76. #define CVY_MAC_ADDR_COPY(m,d,s) ((* (ULONG UNALIGNED *)(d) = * (ULONG UNALIGNED *)(s)), \
  77. (* (USHORT UNALIGNED *)((PUCHAR)(d) + sizeof (ULONG)) = \
  78. * (USHORT UNALIGNED *)((PUCHAR)(s) + sizeof (ULONG))))
  79. #if DBG
  80. #define CVY_MAC_ADDR_PRINT(m,s,a) DbgPrint ("%s %02X-%02X-%02X-%02X-%02X-%02X\n", s, ((PUCHAR)(a))[0], ((PUCHAR)(a))[1], ((PUCHAR)(a))[2], ((PUCHAR)(a))[3], ((PUCHAR)(a))[4], ((PUCHAR)(a))[5])
  81. #else
  82. #define CVY_MAC_ADDR_PRINT(m,s,a)
  83. #endif
  84. /* Medium type field manipulation routines */
  85. #define CVY_ETHERNET_ETYPE_SET(p,l) ((PUCHAR) (p)) [ETHERNET_LENGTH_FIELD_OFFSET] = (UCHAR) ((l) >> 8); \
  86. ((PUCHAR) (p)) [ETHERNET_LENGTH_FIELD_OFFSET + 1] = (UCHAR) (l)
  87. #define CVY_ETHERNET_ETYPE_GET(p) (((USHORT) ((PUCHAR) (p)) [ETHERNET_LENGTH_FIELD_OFFSET]) << 8) | \
  88. ((USHORT) ((PUCHAR) (p)) [ETHERNET_LENGTH_FIELD_OFFSET + 1])
  89. #pragma pack()
  90. #endif /* _Util_h_ */