types.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. }
  75. TapExtension, *TapExtensionPointer;
  76. typedef struct _TapPacket
  77. {
  78. # define TAP_PACKET_SIZE(data_size) (sizeof (TapPacket) + (data_size))
  79. # define TP_TUN 0x80000000
  80. # define TP_SIZE_MASK (~TP_TUN)
  81. ULONG m_SizeFlags;
  82. UCHAR m_Data []; // m_Data must be the last struct member
  83. }
  84. TapPacket, *TapPacketPointer;
  85. typedef struct _TapAdapter
  86. {
  87. # define NAME(a) ((a)->m_NameAnsi.Buffer)
  88. ANSI_STRING m_NameAnsi;
  89. MACADDR m_MAC;
  90. BOOLEAN m_InterfaceIsRunning;
  91. NDIS_HANDLE m_MiniportAdapterHandle;
  92. LONG m_Rx, m_Tx, m_RxErr, m_TxErr;
  93. NDIS_MEDIUM m_Medium;
  94. ULONG m_Lookahead;
  95. ULONG m_MTU;
  96. // TRUE if adapter should always be
  97. // "connected" even when device node
  98. // is not open by a userspace process.
  99. BOOLEAN m_MediaStateAlwaysConnected;
  100. // TRUE if device is "connected"
  101. BOOLEAN m_MediaState;
  102. // Adapter power state
  103. char m_DeviceState;
  104. // Help to tear down the adapter by keeping
  105. // some state information on allocated
  106. // resources.
  107. BOOLEAN m_CalledAdapterFreeResources;
  108. BOOLEAN m_RegisteredAdapterShutdownHandler;
  109. // Multicast list info
  110. NDIS_SPIN_LOCK m_MCLock;
  111. BOOLEAN m_MCLockAllocated;
  112. ULONG m_MCListSize;
  113. MC_LIST m_MCList;
  114. // Information on the TAP device
  115. TapExtension m_Extension;
  116. } TapAdapter, *TapAdapterPointer;
  117. #endif