types.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * TAP-Windows -- A kernel driver to provide virtual tap
  3. * device functionality on Windows.
  4. *
  5. * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
  6. *
  7. * This source code is Copyright (C) 2002-2010 OpenVPN Technologies, Inc.,
  8. * and is released under the GPL version 2 (see below).
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program (see the file COPYING included with this
  21. * distribution); if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #ifndef TAP_TYPES_DEFINED
  25. #define TAP_TYPES_DEFINED
  26. typedef struct _Queue
  27. {
  28. ULONG base;
  29. ULONG size;
  30. ULONG capacity;
  31. ULONG max_size;
  32. PVOID data[];
  33. } Queue;
  34. typedef struct _TapAdapter;
  35. typedef struct _TapPacket;
  36. typedef union _TapAdapterQuery
  37. {
  38. NDIS_HARDWARE_STATUS m_HardwareStatus;
  39. NDIS_MEDIUM m_Medium;
  40. NDIS_PHYSICAL_MEDIUM m_PhysicalMedium;
  41. UCHAR m_MacAddress [6];
  42. UCHAR m_Buffer [256];
  43. ULONG m_Long;
  44. USHORT m_Short;
  45. UCHAR m_Byte;
  46. }
  47. TapAdapterQuery, *TapAdapterQueryPointer;
  48. typedef struct _TapExtension
  49. {
  50. // TAP device object and packet queues
  51. Queue *m_PacketQueue, *m_IrpQueue;
  52. PDEVICE_OBJECT m_TapDevice;
  53. NDIS_HANDLE m_TapDeviceHandle;
  54. ULONG m_TapOpens;
  55. // Used to lock packet queues
  56. NDIS_SPIN_LOCK m_QueueLock;
  57. BOOLEAN m_AllocatedSpinlocks;
  58. // Used to bracket open/close
  59. // state changes.
  60. MUTEX m_OpenCloseMutex;
  61. // True if device has been permanently halted
  62. BOOLEAN m_Halt;
  63. // TAP device name
  64. unsigned char *m_TapName;
  65. UNICODE_STRING m_UnicodeLinkName;
  66. BOOLEAN m_CreatedUnicodeLinkName;
  67. // Used for device status ioctl only
  68. const char *m_LastErrorFilename;
  69. int m_LastErrorLineNumber;
  70. LONG m_NumTapOpens;
  71. // Flags
  72. BOOLEAN m_TapIsRunning;
  73. BOOLEAN m_CalledTapDeviceFreeResources;
  74. #if 0
  75. // DPC queue for deferred packet injection
  76. BOOLEAN m_InjectDpcInitialized;
  77. KDPC m_InjectDpc;
  78. NDIS_SPIN_LOCK m_InjectLock;
  79. Queue *m_InjectQueue;
  80. #endif
  81. }
  82. TapExtension, *TapExtensionPointer;
  83. typedef struct _TapPacket
  84. {
  85. # define TAP_PACKET_SIZE(data_size) (sizeof (TapPacket) + (data_size))
  86. # define TP_TUN 0x80000000
  87. # define TP_SIZE_MASK (~TP_TUN)
  88. ULONG m_SizeFlags;
  89. UCHAR m_Data []; // m_Data must be the last struct member
  90. }
  91. TapPacket, *TapPacketPointer;
  92. #if 0
  93. typedef struct _InjectPacket
  94. {
  95. # define INJECT_PACKET_SIZE(data_size) (sizeof (InjectPacket) + (data_size))
  96. # define INJECT_PACKET_FREE(ib) NdisFreeMemory ((ib), INJECT_PACKET_SIZE ((ib)->m_Size), 0)
  97. ULONG m_Size;
  98. UCHAR m_Data []; // m_Data must be the last struct member
  99. }
  100. InjectPacket, *InjectPacketPointer;
  101. #endif
  102. typedef struct _TapAdapter
  103. {
  104. # define NAME(a) ((a)->m_NameAnsi.Buffer)
  105. ANSI_STRING m_NameAnsi;
  106. MACADDR m_MAC;
  107. BOOLEAN m_InterfaceIsRunning;
  108. NDIS_HANDLE m_MiniportAdapterHandle;
  109. LONG m_Rx, m_Tx, m_RxErr, m_TxErr;
  110. #if PACKET_TRUNCATION_CHECK
  111. LONG m_RxTrunc, m_TxTrunc;
  112. #endif
  113. NDIS_MEDIUM m_Medium;
  114. ULONG m_Lookahead;
  115. ULONG m_MTU;
  116. // TRUE if adapter should always be
  117. // "connected" even when device node
  118. // is not open by a userspace process.
  119. BOOLEAN m_MediaStateAlwaysConnected;
  120. // TRUE if device is "connected"
  121. BOOLEAN m_MediaState;
  122. // Adapter power state
  123. char m_DeviceState;
  124. // Help to tear down the adapter by keeping
  125. // some state information on allocated
  126. // resources.
  127. BOOLEAN m_CalledAdapterFreeResources;
  128. BOOLEAN m_RegisteredAdapterShutdownHandler;
  129. // Multicast list info
  130. NDIS_SPIN_LOCK m_MCLock;
  131. BOOLEAN m_MCLockAllocated;
  132. ULONG m_MCListSize;
  133. MC_LIST m_MCList;
  134. // Information on the TAP device
  135. TapExtension m_Extension;
  136. } TapAdapter, *TapAdapterPointer;
  137. #endif