PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/inc/Ethernet.h

https://bitbucket.org/cyanogenmod/cm-kernel
C Header | 165 lines | 86 code | 36 blank | 43 comment | 8 complexity | 105a225bbaae01a1a6c26c94daabab9f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /****************************************************************************
  2. **+-----------------------------------------------------------------------+**
  3. **| |**
  4. **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
  5. **| All rights reserved. |**
  6. **| |**
  7. **| Redistribution and use in source and binary forms, with or without |**
  8. **| modification, are permitted provided that the following conditions |**
  9. **| are met: |**
  10. **| |**
  11. **| * Redistributions of source code must retain the above copyright |**
  12. **| notice, this list of conditions and the following disclaimer. |**
  13. **| * Redistributions in binary form must reproduce the above copyright |**
  14. **| notice, this list of conditions and the following disclaimer in |**
  15. **| the documentation and/or other materials provided with the |**
  16. **| distribution. |**
  17. **| * Neither the name Texas Instruments nor the names of its |**
  18. **| contributors may be used to endorse or promote products derived |**
  19. **| from this software without specific prior written permission. |**
  20. **| |**
  21. **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
  22. **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
  23. **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
  24. **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
  25. **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
  26. **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
  27. **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
  28. **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
  29. **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
  30. **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
  31. **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
  32. **| |**
  33. **+-----------------------------------------------------------------------+**
  34. ****************************************************************************/
  35. /***************************************************************************/
  36. /* */
  37. /* MODULE: Ethernet.h */
  38. /* PURPOSE: */
  39. /* */
  40. /***************************************************************************/
  41. #ifndef _ETHERNET_H_
  42. #define _ETHERNET_H_
  43. #pragma pack(1)
  44. typedef struct
  45. {
  46. macAddress_t DstAddr;
  47. macAddress_t SrcAddr;
  48. UINT16 TypeLength;
  49. } EthernetHeader_t;
  50. #pragma pack()
  51. #define ETHERTYPE_802_1D 0x8100
  52. typedef struct
  53. {
  54. macAddress_t DstAddr;
  55. macAddress_t SrcAddr;
  56. UINT16 Length;
  57. UINT8 DSAP;
  58. UINT8 SSAP;
  59. UINT8 Control;
  60. UINT8 OUI[3];
  61. UINT16 Type;
  62. } LlcSnapHeader_t;
  63. #pragma pack()
  64. #define MAC_ADDRESS_GROUP_BIT ( 0x01 ) /* in byte [ 0 ] of the MAC Address*/
  65. #define ETHERNET_HDR_LEN 14
  66. #define IEEE802_3_HDR_LEN 14
  67. #define LLC_SNAP_HDR_LEN 20
  68. #define SNAP_CHANNEL_ID 0xAA
  69. #define LLC_CONTROL_UNNUMBERED_INFORMATION 0x03
  70. #define ETHERNET_MAX_PAYLOAD_SIZE 1500
  71. #define SNAP_OUI_802_1H_BYTE0 0x00
  72. #define SNAP_OUI_802_1H_BYTE1 0x00
  73. #define SNAP_OUI_802_1H_BYTE2 0xf8
  74. #define SNAP_OUI_802_1H_BYTES { SNAP_OUI_802_1H_BYTE0, SNAP_OUI_802_1H_BYTE1, SNAP_OUI_802_1H_BYTE2 }
  75. #define SNAP_OUI_RFC1042_BYTE0 0x00
  76. #define SNAP_OUI_RFC1042_BYTE1 0x00
  77. #define SNAP_OUI_RFC1042_BYTE2 0x00
  78. #define SNAP_OUI_RFC1042_LEN 3
  79. #define SNAP_OUI_RFC1042_BYTES { SNAP_OUI_RFC1042_BYTE0, SNAP_OUI_RFC1042_BYTE1, SNAP_OUI_RFC1042_BYTE2 }
  80. typedef enum tETHERTYPES
  81. {
  82. ETHERTYPE_APPLE_AARP = 0x80f3,
  83. ETHERTYPE_DIX_II_IPX = 0x8137
  84. } ETHERTYPES, *PETHERTYPES;
  85. static __inline BOOL IsMacAddressZero( macAddress_t *pMacAddr )
  86. {
  87. return( (BOOL)( ( 0 == * (unsigned long *)pMacAddr ) &&
  88. ( 0 == *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) ) ) );
  89. }
  90. static __inline void ClearMacAddress( macAddress_t *pMacAddr )
  91. {
  92. * (unsigned long *)pMacAddr = 0;
  93. *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) = 0;
  94. }
  95. static __inline BOOL IsMacAddressEqual( macAddress_t *pMacAddr1, macAddress_t *pMacAddr2 )
  96. {
  97. return( (BOOL)(
  98. ( * (unsigned long *)pMacAddr1 ==
  99. * (unsigned long *)pMacAddr2 ) &&
  100. ( *( (unsigned short *)( ( (unsigned long *)pMacAddr1 ) + 1 ) ) ==
  101. *( (unsigned short *)( ( (unsigned long *)pMacAddr2 ) + 1 ) ) ) ) );
  102. }
  103. static __inline void SetMacAddressBroadcast( macAddress_t *pMacAddr )
  104. {
  105. * (unsigned long *)pMacAddr = 0xffffffff;
  106. *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) = 0xffff;
  107. }
  108. static __inline BOOL IsMacAddressGroup( macAddress_t *pMACAddr )
  109. {
  110. return( pMACAddr->addr[ 0 ] & MAC_ADDRESS_GROUP_BIT );
  111. }
  112. static __inline BOOL IsMacAddressDirected( macAddress_t *pMACAddr )
  113. {
  114. return( !IsMacAddressGroup( pMACAddr ) );
  115. }
  116. static __inline BOOL IsMacAddressBroadcast( macAddress_t *pMacAddr )
  117. {
  118. /* In WinCE an adrress that is not divided by 4 causes exception here */
  119. return( (BOOL)( ( 0xffff == *(unsigned short *)pMacAddr ) &&
  120. ( 0xffff == *(((unsigned short *)pMacAddr) + 1 ) ) &&
  121. ( 0xffff == *(((unsigned short *)pMacAddr) + 2 ) )));
  122. /* return( (BOOL)( ( 0xffffffff == * (unsigned long *)pMacAddr ) &&
  123. ( 0xffff == *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) ) ) );*/
  124. }
  125. static __inline BOOL IsMacAddressMulticast( macAddress_t *pMACAddr )
  126. {
  127. return( IsMacAddressGroup( pMACAddr ) && !IsMacAddressBroadcast( pMACAddr ) );
  128. }
  129. #endif