oidrequest.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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-2014 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. //
  25. // Include files.
  26. //
  27. #include "tap.h"
  28. #ifndef DBG
  29. #define DBG_PRINT_OID_NAME
  30. #else
  31. VOID
  32. DBG_PRINT_OID_NAME(
  33. __in NDIS_OID Oid
  34. )
  35. {
  36. PCHAR oidName = NULL;
  37. switch (Oid){
  38. #undef MAKECASE
  39. #define MAKECASE(oidx) case oidx: oidName = #oidx "\n"; break;
  40. /* Operational OIDs */
  41. MAKECASE(OID_GEN_SUPPORTED_LIST)
  42. MAKECASE(OID_GEN_HARDWARE_STATUS)
  43. MAKECASE(OID_GEN_MEDIA_SUPPORTED)
  44. MAKECASE(OID_GEN_MEDIA_IN_USE)
  45. MAKECASE(OID_GEN_MAXIMUM_LOOKAHEAD)
  46. MAKECASE(OID_GEN_MAXIMUM_FRAME_SIZE)
  47. MAKECASE(OID_GEN_LINK_SPEED)
  48. MAKECASE(OID_GEN_TRANSMIT_BUFFER_SPACE)
  49. MAKECASE(OID_GEN_RECEIVE_BUFFER_SPACE)
  50. MAKECASE(OID_GEN_TRANSMIT_BLOCK_SIZE)
  51. MAKECASE(OID_GEN_RECEIVE_BLOCK_SIZE)
  52. MAKECASE(OID_GEN_VENDOR_ID)
  53. MAKECASE(OID_GEN_VENDOR_DESCRIPTION)
  54. MAKECASE(OID_GEN_VENDOR_DRIVER_VERSION)
  55. MAKECASE(OID_GEN_CURRENT_PACKET_FILTER)
  56. MAKECASE(OID_GEN_CURRENT_LOOKAHEAD)
  57. MAKECASE(OID_GEN_DRIVER_VERSION)
  58. MAKECASE(OID_GEN_MAXIMUM_TOTAL_SIZE)
  59. MAKECASE(OID_GEN_PROTOCOL_OPTIONS)
  60. MAKECASE(OID_GEN_MAC_OPTIONS)
  61. MAKECASE(OID_GEN_MEDIA_CONNECT_STATUS)
  62. MAKECASE(OID_GEN_MAXIMUM_SEND_PACKETS)
  63. MAKECASE(OID_GEN_SUPPORTED_GUIDS)
  64. MAKECASE(OID_GEN_NETWORK_LAYER_ADDRESSES)
  65. MAKECASE(OID_GEN_TRANSPORT_HEADER_OFFSET)
  66. MAKECASE(OID_GEN_MEDIA_CAPABILITIES)
  67. MAKECASE(OID_GEN_PHYSICAL_MEDIUM)
  68. MAKECASE(OID_GEN_MACHINE_NAME)
  69. MAKECASE(OID_GEN_VLAN_ID)
  70. MAKECASE(OID_GEN_RNDIS_CONFIG_PARAMETER)
  71. /* Operational OIDs for NDIS 6.0 */
  72. MAKECASE(OID_GEN_MAX_LINK_SPEED)
  73. MAKECASE(OID_GEN_LINK_STATE)
  74. MAKECASE(OID_GEN_LINK_PARAMETERS)
  75. MAKECASE(OID_GEN_MINIPORT_RESTART_ATTRIBUTES)
  76. MAKECASE(OID_GEN_ENUMERATE_PORTS)
  77. MAKECASE(OID_GEN_PORT_STATE)
  78. MAKECASE(OID_GEN_PORT_AUTHENTICATION_PARAMETERS)
  79. MAKECASE(OID_GEN_INTERRUPT_MODERATION)
  80. MAKECASE(OID_GEN_PHYSICAL_MEDIUM_EX)
  81. /* Statistical OIDs */
  82. MAKECASE(OID_GEN_XMIT_OK)
  83. MAKECASE(OID_GEN_RCV_OK)
  84. MAKECASE(OID_GEN_XMIT_ERROR)
  85. MAKECASE(OID_GEN_RCV_ERROR)
  86. MAKECASE(OID_GEN_RCV_NO_BUFFER)
  87. MAKECASE(OID_GEN_DIRECTED_BYTES_XMIT)
  88. MAKECASE(OID_GEN_DIRECTED_FRAMES_XMIT)
  89. MAKECASE(OID_GEN_MULTICAST_BYTES_XMIT)
  90. MAKECASE(OID_GEN_MULTICAST_FRAMES_XMIT)
  91. MAKECASE(OID_GEN_BROADCAST_BYTES_XMIT)
  92. MAKECASE(OID_GEN_BROADCAST_FRAMES_XMIT)
  93. MAKECASE(OID_GEN_DIRECTED_BYTES_RCV)
  94. MAKECASE(OID_GEN_DIRECTED_FRAMES_RCV)
  95. MAKECASE(OID_GEN_MULTICAST_BYTES_RCV)
  96. MAKECASE(OID_GEN_MULTICAST_FRAMES_RCV)
  97. MAKECASE(OID_GEN_BROADCAST_BYTES_RCV)
  98. MAKECASE(OID_GEN_BROADCAST_FRAMES_RCV)
  99. MAKECASE(OID_GEN_RCV_CRC_ERROR)
  100. MAKECASE(OID_GEN_TRANSMIT_QUEUE_LENGTH)
  101. /* Statistical OIDs for NDIS 6.0 */
  102. MAKECASE(OID_GEN_STATISTICS)
  103. MAKECASE(OID_GEN_BYTES_RCV)
  104. MAKECASE(OID_GEN_BYTES_XMIT)
  105. MAKECASE(OID_GEN_RCV_DISCARDS)
  106. MAKECASE(OID_GEN_XMIT_DISCARDS)
  107. /* Misc OIDs */
  108. MAKECASE(OID_GEN_GET_TIME_CAPS)
  109. MAKECASE(OID_GEN_GET_NETCARD_TIME)
  110. MAKECASE(OID_GEN_NETCARD_LOAD)
  111. MAKECASE(OID_GEN_DEVICE_PROFILE)
  112. MAKECASE(OID_GEN_INIT_TIME_MS)
  113. MAKECASE(OID_GEN_RESET_COUNTS)
  114. MAKECASE(OID_GEN_MEDIA_SENSE_COUNTS)
  115. /* PnP power management operational OIDs */
  116. MAKECASE(OID_PNP_CAPABILITIES)
  117. MAKECASE(OID_PNP_SET_POWER)
  118. MAKECASE(OID_PNP_QUERY_POWER)
  119. MAKECASE(OID_PNP_ADD_WAKE_UP_PATTERN)
  120. MAKECASE(OID_PNP_REMOVE_WAKE_UP_PATTERN)
  121. MAKECASE(OID_PNP_ENABLE_WAKE_UP)
  122. MAKECASE(OID_PNP_WAKE_UP_PATTERN_LIST)
  123. /* PnP power management statistical OIDs */
  124. MAKECASE(OID_PNP_WAKE_UP_ERROR)
  125. MAKECASE(OID_PNP_WAKE_UP_OK)
  126. /* Ethernet operational OIDs */
  127. MAKECASE(OID_802_3_PERMANENT_ADDRESS)
  128. MAKECASE(OID_802_3_CURRENT_ADDRESS)
  129. MAKECASE(OID_802_3_MULTICAST_LIST)
  130. MAKECASE(OID_802_3_MAXIMUM_LIST_SIZE)
  131. MAKECASE(OID_802_3_MAC_OPTIONS)
  132. /* Ethernet operational OIDs for NDIS 6.0 */
  133. MAKECASE(OID_802_3_ADD_MULTICAST_ADDRESS)
  134. MAKECASE(OID_802_3_DELETE_MULTICAST_ADDRESS)
  135. /* Ethernet statistical OIDs */
  136. MAKECASE(OID_802_3_RCV_ERROR_ALIGNMENT)
  137. MAKECASE(OID_802_3_XMIT_ONE_COLLISION)
  138. MAKECASE(OID_802_3_XMIT_MORE_COLLISIONS)
  139. MAKECASE(OID_802_3_XMIT_DEFERRED)
  140. MAKECASE(OID_802_3_XMIT_MAX_COLLISIONS)
  141. MAKECASE(OID_802_3_RCV_OVERRUN)
  142. MAKECASE(OID_802_3_XMIT_UNDERRUN)
  143. MAKECASE(OID_802_3_XMIT_HEARTBEAT_FAILURE)
  144. MAKECASE(OID_802_3_XMIT_TIMES_CRS_LOST)
  145. MAKECASE(OID_802_3_XMIT_LATE_COLLISIONS)
  146. /* TCP/IP OIDs */
  147. MAKECASE(OID_TCP_TASK_OFFLOAD)
  148. MAKECASE(OID_TCP_TASK_IPSEC_ADD_SA)
  149. MAKECASE(OID_TCP_TASK_IPSEC_DELETE_SA)
  150. MAKECASE(OID_TCP_SAN_SUPPORT)
  151. MAKECASE(OID_TCP_TASK_IPSEC_ADD_UDPESP_SA)
  152. MAKECASE(OID_TCP_TASK_IPSEC_DELETE_UDPESP_SA)
  153. MAKECASE(OID_TCP4_OFFLOAD_STATS)
  154. MAKECASE(OID_TCP6_OFFLOAD_STATS)
  155. MAKECASE(OID_IP4_OFFLOAD_STATS)
  156. MAKECASE(OID_IP6_OFFLOAD_STATS)
  157. /* TCP offload OIDs for NDIS 6 */
  158. MAKECASE(OID_TCP_OFFLOAD_CURRENT_CONFIG)
  159. MAKECASE(OID_TCP_OFFLOAD_PARAMETERS)
  160. MAKECASE(OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES)
  161. MAKECASE(OID_TCP_CONNECTION_OFFLOAD_CURRENT_CONFIG)
  162. MAKECASE(OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES)
  163. MAKECASE(OID_OFFLOAD_ENCAPSULATION)
  164. #if (NDIS_SUPPORT_NDIS620)
  165. /* VMQ OIDs for NDIS 6.20 */
  166. MAKECASE(OID_RECEIVE_FILTER_FREE_QUEUE)
  167. MAKECASE(OID_RECEIVE_FILTER_CLEAR_FILTER)
  168. MAKECASE(OID_RECEIVE_FILTER_ALLOCATE_QUEUE)
  169. MAKECASE(OID_RECEIVE_FILTER_QUEUE_ALLOCATION_COMPLETE)
  170. MAKECASE(OID_RECEIVE_FILTER_SET_FILTER)
  171. #endif
  172. #if (NDIS_SUPPORT_NDIS630)
  173. /* NDIS QoS OIDs for NDIS 6.30 */
  174. MAKECASE(OID_QOS_PARAMETERS)
  175. #endif
  176. }
  177. if (oidName)
  178. {
  179. DEBUGP(("OID: %s", oidName));
  180. }
  181. else
  182. {
  183. DEBUGP(("<** Unknown OID 0x%08x **>\n", Oid));
  184. }
  185. }
  186. #endif // DBG
  187. //======================================================================
  188. // TAP NDIS 6 OID Request Callbacks
  189. //======================================================================
  190. NDIS_STATUS
  191. tapSetMulticastList(
  192. __in PTAP_ADAPTER_CONTEXT Adapter,
  193. __in PNDIS_OID_REQUEST OidRequest
  194. )
  195. {
  196. NDIS_STATUS status = NDIS_STATUS_SUCCESS;
  197. //
  198. // Initialize.
  199. //
  200. OidRequest->DATA.SET_INFORMATION.BytesNeeded = MACADDR_SIZE;
  201. OidRequest->DATA.SET_INFORMATION.BytesRead
  202. = OidRequest->DATA.SET_INFORMATION.InformationBufferLength;
  203. do
  204. {
  205. if (OidRequest->DATA.SET_INFORMATION.InformationBufferLength % MACADDR_SIZE)
  206. {
  207. status = NDIS_STATUS_INVALID_LENGTH;
  208. break;
  209. }
  210. if (OidRequest->DATA.SET_INFORMATION.InformationBufferLength > (TAP_MAX_MCAST_LIST * MACADDR_SIZE))
  211. {
  212. status = NDIS_STATUS_MULTICAST_FULL;
  213. OidRequest->DATA.SET_INFORMATION.BytesNeeded = TAP_MAX_MCAST_LIST * MACADDR_SIZE;
  214. break;
  215. }
  216. // BUGBUG!!! Is lock needed??? If so, use NDIS_RW_LOCK. Also apply to packet filter.
  217. NdisZeroMemory(Adapter->MCList,
  218. TAP_MAX_MCAST_LIST * MACADDR_SIZE);
  219. NdisMoveMemory(Adapter->MCList,
  220. OidRequest->DATA.SET_INFORMATION.InformationBuffer,
  221. OidRequest->DATA.SET_INFORMATION.InformationBufferLength);
  222. Adapter->ulMCListSize = OidRequest->DATA.SET_INFORMATION.InformationBufferLength / MACADDR_SIZE;
  223. } while(FALSE);
  224. return status;
  225. }
  226. NDIS_STATUS
  227. tapSetPacketFilter(
  228. __in PTAP_ADAPTER_CONTEXT Adapter,
  229. __in ULONG PacketFilter
  230. )
  231. {
  232. NDIS_STATUS status = NDIS_STATUS_SUCCESS;
  233. // any bits not supported?
  234. if (PacketFilter & ~(TAP_SUPPORTED_FILTERS))
  235. {
  236. DEBUGP (("[TAP] Unsupported packet filter: 0x%08x\n", PacketFilter));
  237. status = NDIS_STATUS_NOT_SUPPORTED;
  238. }
  239. else
  240. {
  241. // Any actual filtering changes?
  242. if (PacketFilter != Adapter->PacketFilter)
  243. {
  244. //
  245. // Change the filtering modes on hardware
  246. //
  247. // Save the new packet filter value
  248. Adapter->PacketFilter = PacketFilter;
  249. }
  250. }
  251. return status;
  252. }
  253. NDIS_STATUS
  254. AdapterSetPowerD0(
  255. __in PTAP_ADAPTER_CONTEXT Adapter
  256. )
  257. /*++
  258. Routine Description:
  259. NIC power has been restored to the working power state (D0).
  260. Prepare the NIC for normal operation:
  261. - Restore hardware context (packet filters, multicast addresses, MAC address, etc.)
  262. - Enable interrupts and the NIC's DMA engine.
  263. Arguments:
  264. Adapter - Pointer to adapter block
  265. Return Value:
  266. NDIS_STATUS
  267. --*/
  268. {
  269. NDIS_STATUS status = NDIS_STATUS_SUCCESS;
  270. DEBUGP (("[TAP] PowerState: Fully powered\n"));
  271. // Start data path...
  272. return status;
  273. }
  274. NDIS_STATUS
  275. AdapterSetPowerLow(
  276. __in PTAP_ADAPTER_CONTEXT Adapter,
  277. __in NDIS_DEVICE_POWER_STATE PowerState
  278. )
  279. /*++
  280. Routine Description:
  281. The NIC is about to be transitioned to a low power state.
  282. Prepare the NIC for the sleeping state:
  283. - Disable interrupts and the NIC's DMA engine, cancel timers.
  284. - Save any hardware context that the NIC cannot preserve in
  285. a sleeping state (packet filters, multicast addresses,
  286. the current MAC address, etc.)
  287. A miniport driver cannot access the NIC hardware after
  288. the NIC has been set to the D3 state by the bus driver.
  289. Miniport drivers NDIS v6.30 and above
  290. Do NOT wait for NDIS to return the ownership of all
  291. NBLs from outstanding receive indications
  292. Retain ownership of all the receive descriptors and
  293. packet buffers previously owned by the hardware.
  294. Arguments:
  295. Adapter - Pointer to adapter block
  296. PowerState - New power state
  297. Return Value:
  298. NDIS_STATUS
  299. --*/
  300. {
  301. NDIS_STATUS status = NDIS_STATUS_SUCCESS;
  302. DEBUGP (("[TAP] PowerState: Low-power\n"));
  303. //
  304. // Miniport drivers NDIS v6.20 and below are
  305. // paused prior the low power transition
  306. //
  307. // Check for paused state...
  308. // Verify data path stopped...
  309. return status;
  310. }
  311. NDIS_STATUS
  312. tapSetInformation(
  313. __in PTAP_ADAPTER_CONTEXT Adapter,
  314. __in PNDIS_OID_REQUEST OidRequest
  315. )
  316. /*++
  317. Routine Description:
  318. Helper function to perform a set OID request
  319. Arguments:
  320. Adapter -
  321. NdisSetRequest - The OID to set
  322. Return Value:
  323. NDIS_STATUS
  324. --*/
  325. {
  326. NDIS_STATUS status = NDIS_STATUS_SUCCESS;
  327. DBG_PRINT_OID_NAME(OidRequest->DATA.SET_INFORMATION.Oid);
  328. switch(OidRequest->DATA.SET_INFORMATION.Oid)
  329. {
  330. case OID_802_3_MULTICAST_LIST:
  331. //
  332. // Set the multicast address list on the NIC for packet reception.
  333. // The NIC driver can set a limit on the number of multicast
  334. // addresses bound protocol drivers can enable simultaneously.
  335. // NDIS returns NDIS_STATUS_MULTICAST_FULL if a protocol driver
  336. // exceeds this limit or if it specifies an invalid multicast
  337. // address.
  338. //
  339. status = tapSetMulticastList(Adapter,OidRequest);
  340. break;
  341. case OID_GEN_CURRENT_LOOKAHEAD:
  342. //
  343. // A protocol driver can set a suggested value for the number
  344. // of bytes to be used in its binding; however, the underlying
  345. // NIC driver is never required to limit its indications to
  346. // the value set.
  347. //
  348. if (OidRequest->DATA.SET_INFORMATION.InformationBufferLength != sizeof(ULONG))
  349. {
  350. OidRequest->DATA.SET_INFORMATION.BytesNeeded = sizeof(ULONG);
  351. status = NDIS_STATUS_INVALID_LENGTH;
  352. break;
  353. }
  354. Adapter->ulLookahead = *(PULONG)OidRequest->DATA.SET_INFORMATION.InformationBuffer;
  355. OidRequest->DATA.SET_INFORMATION.BytesRead = sizeof(ULONG);
  356. status = NDIS_STATUS_SUCCESS;
  357. break;
  358. case OID_GEN_CURRENT_PACKET_FILTER:
  359. //
  360. // Program the hardware to indicate the packets
  361. // of certain filter types.
  362. //
  363. if(OidRequest->DATA.SET_INFORMATION.InformationBufferLength != sizeof(ULONG))
  364. {
  365. OidRequest->DATA.SET_INFORMATION.BytesNeeded = sizeof(ULONG);
  366. status = NDIS_STATUS_INVALID_LENGTH;
  367. break;
  368. }
  369. OidRequest->DATA.SET_INFORMATION.BytesRead
  370. = OidRequest->DATA.SET_INFORMATION.InformationBufferLength;
  371. status = tapSetPacketFilter(
  372. Adapter,
  373. *((PULONG)OidRequest->DATA.SET_INFORMATION.InformationBuffer)
  374. );
  375. break;
  376. case OID_PNP_SET_POWER:
  377. {
  378. // Sanity check.
  379. if (OidRequest->DATA.SET_INFORMATION.InformationBufferLength
  380. < sizeof(NDIS_DEVICE_POWER_STATE)
  381. )
  382. {
  383. status = NDIS_STATUS_INVALID_LENGTH;
  384. }
  385. else
  386. {
  387. NDIS_DEVICE_POWER_STATE PowerState;
  388. PowerState = *(PNDIS_DEVICE_POWER_STATE UNALIGNED)OidRequest->DATA.SET_INFORMATION.InformationBuffer;
  389. OidRequest->DATA.SET_INFORMATION.BytesRead = sizeof(NDIS_DEVICE_POWER_STATE);
  390. if(PowerState < NdisDeviceStateD0 ||
  391. PowerState > NdisDeviceStateD3)
  392. {
  393. status = NDIS_STATUS_INVALID_DATA;
  394. }
  395. else
  396. {
  397. Adapter->CurrentPowerState = PowerState;
  398. if (PowerState == NdisDeviceStateD0)
  399. {
  400. status = AdapterSetPowerD0(Adapter);
  401. }
  402. else
  403. {
  404. status = AdapterSetPowerLow(Adapter, PowerState);
  405. }
  406. }
  407. }
  408. }
  409. break;
  410. #if (NDIS_SUPPORT_NDIS61)
  411. case OID_PNP_ADD_WAKE_UP_PATTERN:
  412. case OID_PNP_REMOVE_WAKE_UP_PATTERN:
  413. case OID_PNP_ENABLE_WAKE_UP:
  414. #endif
  415. ASSERT(!"NIC does not support wake on LAN OIDs");
  416. default:
  417. //
  418. // The entry point may by used by other requests
  419. //
  420. status = NDIS_STATUS_NOT_SUPPORTED;
  421. break;
  422. }
  423. return status;
  424. }
  425. NDIS_STATUS
  426. tapQueryInformation(
  427. __in PTAP_ADAPTER_CONTEXT Adapter,
  428. __in PNDIS_OID_REQUEST OidRequest
  429. )
  430. /*++
  431. Routine Description:
  432. Helper function to perform a query OID request
  433. Arguments:
  434. Adapter -
  435. OidRequest - The OID request that is being queried
  436. Return Value:
  437. NDIS_STATUS
  438. --*/
  439. {
  440. NDIS_STATUS status = NDIS_STATUS_SUCCESS;
  441. NDIS_MEDIUM Medium = TAP_MEDIUM_TYPE;
  442. NDIS_HARDWARE_STATUS HardwareStatus = NdisHardwareStatusReady;
  443. UCHAR VendorDesc[] = TAP_VENDOR_DESC;
  444. ULONG ulInfo;
  445. USHORT usInfo;
  446. ULONG64 ulInfo64;
  447. // Default to returning the ULONG value
  448. PVOID pInfo=NULL;
  449. ULONG ulInfoLen = sizeof(ulInfo);
  450. // ATTENTION!!! Ignore OIDs to noisy to print...
  451. if((OidRequest->DATA.QUERY_INFORMATION.Oid != OID_GEN_STATISTICS)
  452. && (OidRequest->DATA.QUERY_INFORMATION.Oid != OID_IP4_OFFLOAD_STATS)
  453. && (OidRequest->DATA.QUERY_INFORMATION.Oid != OID_IP6_OFFLOAD_STATS)
  454. )
  455. {
  456. DBG_PRINT_OID_NAME(OidRequest->DATA.QUERY_INFORMATION.Oid);
  457. }
  458. // Dispatch based on object identifier (OID).
  459. switch(OidRequest->DATA.QUERY_INFORMATION.Oid)
  460. {
  461. case OID_GEN_HARDWARE_STATUS:
  462. //
  463. // Specify the current hardware status of the underlying NIC as
  464. // one of the following NDIS_HARDWARE_STATUS-type values.
  465. //
  466. pInfo = (PVOID) &HardwareStatus;
  467. ulInfoLen = sizeof(NDIS_HARDWARE_STATUS);
  468. break;
  469. case OID_802_3_PERMANENT_ADDRESS:
  470. //
  471. // Return the MAC address of the NIC burnt in the hardware.
  472. //
  473. pInfo = Adapter->PermanentAddress;
  474. ulInfoLen = MACADDR_SIZE;
  475. break;
  476. case OID_802_3_CURRENT_ADDRESS:
  477. //
  478. // Return the MAC address the NIC is currently programmed to
  479. // use. Note that this address could be different from the
  480. // permananent address as the user can override using
  481. // registry. Read NdisReadNetworkAddress doc for more info.
  482. //
  483. pInfo = Adapter->CurrentAddress;
  484. ulInfoLen = MACADDR_SIZE;
  485. break;
  486. case OID_GEN_MEDIA_SUPPORTED:
  487. //
  488. // Return an array of media that are supported by the miniport.
  489. // This miniport only supports one medium (Ethernet), so the OID
  490. // returns identical results to OID_GEN_MEDIA_IN_USE.
  491. //
  492. __fallthrough;
  493. case OID_GEN_MEDIA_IN_USE:
  494. //
  495. // Return an array of media that are currently in use by the
  496. // miniport. This array should be a subset of the array returned
  497. // by OID_GEN_MEDIA_SUPPORTED.
  498. //
  499. pInfo = &Medium;
  500. ulInfoLen = sizeof(Medium);
  501. break;
  502. case OID_GEN_MAXIMUM_TOTAL_SIZE:
  503. //
  504. // Specify the maximum total packet length, in bytes, the NIC
  505. // supports including the header. A protocol driver might use
  506. // this returned length as a gauge to determine the maximum
  507. // size packet that a NIC driver could forward to the
  508. // protocol driver. The miniport driver must never indicate
  509. // up to the bound protocol driver packets received over the
  510. // network that are longer than the packet size specified by
  511. // OID_GEN_MAXIMUM_TOTAL_SIZE.
  512. //
  513. __fallthrough;
  514. case OID_GEN_TRANSMIT_BLOCK_SIZE:
  515. //
  516. // The OID_GEN_TRANSMIT_BLOCK_SIZE OID specifies the minimum
  517. // number of bytes that a single net packet occupies in the
  518. // transmit buffer space of the NIC. In our case, the transmit
  519. // block size is identical to its maximum packet size.
  520. __fallthrough;
  521. case OID_GEN_RECEIVE_BLOCK_SIZE:
  522. //
  523. // The OID_GEN_RECEIVE_BLOCK_SIZE OID specifies the amount of
  524. // storage, in bytes, that a single packet occupies in the receive
  525. // buffer space of the NIC.
  526. //
  527. ulInfo = (ULONG) TAP_MAX_FRAME_SIZE;
  528. pInfo = &ulInfo;
  529. break;
  530. case OID_GEN_INTERRUPT_MODERATION:
  531. {
  532. PNDIS_INTERRUPT_MODERATION_PARAMETERS moderationParams
  533. = (PNDIS_INTERRUPT_MODERATION_PARAMETERS)OidRequest->DATA.QUERY_INFORMATION.InformationBuffer;
  534. moderationParams->Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
  535. moderationParams->Header.Revision = NDIS_INTERRUPT_MODERATION_PARAMETERS_REVISION_1;
  536. moderationParams->Header.Size = NDIS_SIZEOF_INTERRUPT_MODERATION_PARAMETERS_REVISION_1;
  537. moderationParams->Flags = 0;
  538. moderationParams->InterruptModeration = NdisInterruptModerationNotSupported;
  539. ulInfoLen = NDIS_SIZEOF_INTERRUPT_MODERATION_PARAMETERS_REVISION_1;
  540. }
  541. break;
  542. case OID_PNP_QUERY_POWER:
  543. // Simply succeed this.
  544. break;
  545. case OID_GEN_VENDOR_ID:
  546. //
  547. // Specify a three-byte IEEE-registered vendor code, followed
  548. // by a single byte that the vendor assigns to identify a
  549. // particular NIC. The IEEE code uniquely identifies the vendor
  550. // and is the same as the three bytes appearing at the beginning
  551. // of the NIC hardware address. Vendors without an IEEE-registered
  552. // code should use the value 0xFFFFFF.
  553. //
  554. ulInfo = TAP_VENDOR_ID;
  555. pInfo = &ulInfo;
  556. break;
  557. case OID_GEN_VENDOR_DESCRIPTION:
  558. //
  559. // Specify a zero-terminated string describing the NIC vendor.
  560. //
  561. pInfo = VendorDesc;
  562. ulInfoLen = sizeof(VendorDesc);
  563. break;
  564. case OID_GEN_VENDOR_DRIVER_VERSION:
  565. //
  566. // Specify the vendor-assigned version number of the NIC driver.
  567. // The low-order half of the return value specifies the minor
  568. // version; the high-order half specifies the major version.
  569. //
  570. ulInfo = TAP_DRIVER_VENDOR_VERSION;
  571. pInfo = &ulInfo;
  572. break;
  573. case OID_GEN_DRIVER_VERSION:
  574. //
  575. // Specify the NDIS version in use by the NIC driver. The high
  576. // byte is the major version number; the low byte is the minor
  577. // version number.
  578. //
  579. usInfo = (USHORT) (TAP_NDIS_MAJOR_VERSION<<8) + TAP_NDIS_MINOR_VERSION;
  580. pInfo = (PVOID) &usInfo;
  581. ulInfoLen = sizeof(USHORT);
  582. break;
  583. case OID_802_3_MAXIMUM_LIST_SIZE:
  584. //
  585. // The maximum number of multicast addresses the NIC driver
  586. // can manage. This list is global for all protocols bound
  587. // to (or above) the NIC. Consequently, a protocol can receive
  588. // NDIS_STATUS_MULTICAST_FULL from the NIC driver when
  589. // attempting to set the multicast address list, even if
  590. // the number of elements in the given list is less than
  591. // the number originally returned for this query.
  592. //
  593. ulInfo = TAP_MAX_MCAST_LIST;
  594. pInfo = &ulInfo;
  595. break;
  596. case OID_GEN_XMIT_ERROR:
  597. ulInfo = (ULONG)
  598. (Adapter->TxAbortExcessCollisions +
  599. Adapter->TxDmaUnderrun +
  600. Adapter->TxLostCRS +
  601. Adapter->TxLateCollisions+
  602. Adapter->TransmitFailuresOther);
  603. pInfo = &ulInfo;
  604. break;
  605. case OID_GEN_RCV_ERROR:
  606. ulInfo = (ULONG)
  607. (Adapter->RxCrcErrors +
  608. Adapter->RxAlignmentErrors +
  609. Adapter->RxDmaOverrunErrors +
  610. Adapter->RxRuntErrors);
  611. pInfo = &ulInfo;
  612. break;
  613. case OID_GEN_RCV_DISCARDS:
  614. ulInfo = (ULONG)Adapter->RxResourceErrors;
  615. pInfo = &ulInfo;
  616. break;
  617. case OID_GEN_RCV_NO_BUFFER:
  618. ulInfo = (ULONG)Adapter->RxResourceErrors;
  619. pInfo = &ulInfo;
  620. break;
  621. case OID_GEN_XMIT_OK:
  622. ulInfo64 = Adapter->FramesTxBroadcast
  623. + Adapter->FramesTxMulticast
  624. + Adapter->FramesTxDirected;
  625. pInfo = &ulInfo64;
  626. if (OidRequest->DATA.QUERY_INFORMATION.InformationBufferLength >= sizeof(ULONG64) ||
  627. OidRequest->DATA.QUERY_INFORMATION.InformationBufferLength == 0)
  628. {
  629. ulInfoLen = sizeof(ULONG64);
  630. }
  631. else
  632. {
  633. ulInfoLen = sizeof(ULONG);
  634. }
  635. // We should always report that only 8 bytes are required to keep ndistest happy
  636. OidRequest->DATA.QUERY_INFORMATION.BytesNeeded = sizeof(ULONG64);
  637. break;
  638. case OID_GEN_RCV_OK:
  639. ulInfo64 = Adapter->FramesRxBroadcast
  640. + Adapter->FramesRxMulticast
  641. + Adapter->FramesRxDirected;
  642. pInfo = &ulInfo64;
  643. if (OidRequest->DATA.QUERY_INFORMATION.InformationBufferLength >= sizeof(ULONG64) ||
  644. OidRequest->DATA.QUERY_INFORMATION.InformationBufferLength == 0)
  645. {
  646. ulInfoLen = sizeof(ULONG64);
  647. }
  648. else
  649. {
  650. ulInfoLen = sizeof(ULONG);
  651. }
  652. // We should always report that only 8 bytes are required to keep ndistest happy
  653. OidRequest->DATA.QUERY_INFORMATION.BytesNeeded = sizeof(ULONG64);
  654. break;
  655. case OID_802_3_RCV_ERROR_ALIGNMENT:
  656. ulInfo = Adapter->RxAlignmentErrors;
  657. pInfo = &ulInfo;
  658. break;
  659. case OID_802_3_XMIT_ONE_COLLISION:
  660. ulInfo = Adapter->OneRetry;
  661. pInfo = &ulInfo;
  662. break;
  663. case OID_802_3_XMIT_MORE_COLLISIONS:
  664. ulInfo = Adapter->MoreThanOneRetry;
  665. pInfo = &ulInfo;
  666. break;
  667. case OID_802_3_XMIT_DEFERRED:
  668. ulInfo = Adapter->TxOKButDeferred;
  669. pInfo = &ulInfo;
  670. break;
  671. case OID_802_3_XMIT_MAX_COLLISIONS:
  672. ulInfo = Adapter->TxAbortExcessCollisions;
  673. pInfo = &ulInfo;
  674. break;
  675. case OID_802_3_RCV_OVERRUN:
  676. ulInfo = Adapter->RxDmaOverrunErrors;
  677. pInfo = &ulInfo;
  678. break;
  679. case OID_802_3_XMIT_UNDERRUN:
  680. ulInfo = Adapter->TxDmaUnderrun;
  681. pInfo = &ulInfo;
  682. break;
  683. case OID_GEN_STATISTICS:
  684. if (OidRequest->DATA.QUERY_INFORMATION.InformationBufferLength < sizeof(NDIS_STATISTICS_INFO))
  685. {
  686. status = NDIS_STATUS_INVALID_LENGTH;
  687. OidRequest->DATA.QUERY_INFORMATION.BytesNeeded = sizeof(NDIS_STATISTICS_INFO);
  688. break;
  689. }
  690. else
  691. {
  692. PNDIS_STATISTICS_INFO Statistics
  693. = (PNDIS_STATISTICS_INFO)OidRequest->DATA.QUERY_INFORMATION.InformationBuffer;
  694. {C_ASSERT(sizeof(NDIS_STATISTICS_INFO) >= NDIS_SIZEOF_STATISTICS_INFO_REVISION_1);}
  695. Statistics->Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
  696. Statistics->Header.Size = NDIS_SIZEOF_STATISTICS_INFO_REVISION_1;
  697. Statistics->Header.Revision = NDIS_STATISTICS_INFO_REVISION_1;
  698. Statistics->SupportedStatistics = TAP_SUPPORTED_STATISTICS;
  699. /* Bytes in */
  700. Statistics->ifHCInOctets =
  701. Adapter->BytesRxDirected +
  702. Adapter->BytesRxMulticast +
  703. Adapter->BytesRxBroadcast;
  704. Statistics->ifHCInUcastOctets =
  705. Adapter->BytesRxDirected;
  706. Statistics->ifHCInMulticastOctets =
  707. Adapter->BytesRxMulticast;
  708. Statistics->ifHCInBroadcastOctets =
  709. Adapter->BytesRxBroadcast;
  710. /* Packets in */
  711. Statistics->ifHCInUcastPkts =
  712. Adapter->FramesRxDirected;
  713. Statistics->ifHCInMulticastPkts =
  714. Adapter->FramesRxMulticast;
  715. Statistics->ifHCInBroadcastPkts =
  716. Adapter->FramesRxBroadcast;
  717. /* Errors in */
  718. Statistics->ifInErrors =
  719. Adapter->RxCrcErrors +
  720. Adapter->RxAlignmentErrors +
  721. Adapter->RxDmaOverrunErrors +
  722. Adapter->RxRuntErrors;
  723. Statistics->ifInDiscards =
  724. Adapter->RxResourceErrors;
  725. /* Bytes out */
  726. Statistics->ifHCOutOctets =
  727. Adapter->BytesTxDirected +
  728. Adapter->BytesTxMulticast +
  729. Adapter->BytesTxBroadcast;
  730. Statistics->ifHCOutUcastOctets =
  731. Adapter->BytesTxDirected;
  732. Statistics->ifHCOutMulticastOctets =
  733. Adapter->BytesTxMulticast;
  734. Statistics->ifHCOutBroadcastOctets =
  735. Adapter->BytesTxBroadcast;
  736. /* Packets out */
  737. Statistics->ifHCOutUcastPkts =
  738. Adapter->FramesTxDirected;
  739. Statistics->ifHCOutMulticastPkts =
  740. Adapter->FramesTxMulticast;
  741. Statistics->ifHCOutBroadcastPkts =
  742. Adapter->FramesTxBroadcast;
  743. /* Errors out */
  744. Statistics->ifOutErrors =
  745. Adapter->TxAbortExcessCollisions +
  746. Adapter->TxDmaUnderrun +
  747. Adapter->TxLostCRS +
  748. Adapter->TxLateCollisions+
  749. Adapter->TransmitFailuresOther;
  750. Statistics->ifOutDiscards = 0ULL;
  751. ulInfoLen = NDIS_SIZEOF_STATISTICS_INFO_REVISION_1;
  752. }
  753. break;
  754. // TODO: Inplement these query information requests.
  755. case OID_GEN_RECEIVE_BUFFER_SPACE:
  756. case OID_GEN_MAXIMUM_SEND_PACKETS:
  757. case OID_GEN_TRANSMIT_QUEUE_LENGTH:
  758. case OID_802_3_XMIT_HEARTBEAT_FAILURE:
  759. case OID_802_3_XMIT_TIMES_CRS_LOST:
  760. case OID_802_3_XMIT_LATE_COLLISIONS:
  761. default:
  762. //
  763. // The entry point may by used by other requests
  764. //
  765. status = NDIS_STATUS_NOT_SUPPORTED;
  766. break;
  767. }
  768. if (status == NDIS_STATUS_SUCCESS)
  769. {
  770. ASSERT(ulInfoLen > 0);
  771. if (ulInfoLen <= OidRequest->DATA.QUERY_INFORMATION.InformationBufferLength)
  772. {
  773. if(pInfo)
  774. {
  775. // Copy result into InformationBuffer
  776. NdisMoveMemory(
  777. OidRequest->DATA.QUERY_INFORMATION.InformationBuffer,
  778. pInfo,
  779. ulInfoLen
  780. );
  781. }
  782. OidRequest->DATA.QUERY_INFORMATION.BytesWritten = ulInfoLen;
  783. }
  784. else
  785. {
  786. // too short
  787. OidRequest->DATA.QUERY_INFORMATION.BytesNeeded = ulInfoLen;
  788. status = NDIS_STATUS_BUFFER_TOO_SHORT;
  789. }
  790. }
  791. return status;
  792. }
  793. NDIS_STATUS
  794. AdapterOidRequest(
  795. __in NDIS_HANDLE MiniportAdapterContext,
  796. __in PNDIS_OID_REQUEST OidRequest
  797. )
  798. /*++
  799. Routine Description:
  800. Entry point called by NDIS to get or set the value of a specified OID.
  801. Arguments:
  802. MiniportAdapterContext - Our adapter handle
  803. NdisRequest - The OID request to handle
  804. Return Value:
  805. Return code from the NdisRequest below.
  806. --*/
  807. {
  808. PTAP_ADAPTER_CONTEXT adapter = (PTAP_ADAPTER_CONTEXT )MiniportAdapterContext;
  809. NDIS_STATUS status;
  810. // Dispatch based on request type.
  811. switch (OidRequest->RequestType)
  812. {
  813. case NdisRequestSetInformation:
  814. status = tapSetInformation(adapter,OidRequest);
  815. break;
  816. case NdisRequestQueryInformation:
  817. case NdisRequestQueryStatistics:
  818. status = tapQueryInformation(adapter,OidRequest);
  819. break;
  820. case NdisRequestMethod: // TAP doesn't need to respond to this request type.
  821. default:
  822. //
  823. // The entry point may by used by other requests
  824. //
  825. status = NDIS_STATUS_NOT_SUPPORTED;
  826. break;
  827. }
  828. return status;
  829. }
  830. VOID
  831. AdapterCancelOidRequest(
  832. __in NDIS_HANDLE MiniportAdapterContext,
  833. __in PVOID RequestId
  834. )
  835. {
  836. PTAP_ADAPTER_CONTEXT adapter = (PTAP_ADAPTER_CONTEXT )MiniportAdapterContext;
  837. UNREFERENCED_PARAMETER(RequestId);
  838. //
  839. // This miniport sample does not pend any OID requests, so we don't have
  840. // to worry about cancelling them.
  841. //
  842. }