Commit Graph

546 Commits

Author SHA1 Message Date
Simon Rozman
7176236b4e Mark canceled NBL status as NDIS_STATUS_SEND_ABORTED
NDIS expects this from a miniport driver.

References: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ndis/nc-ndis-miniport_cancel_send
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 12:57:31 +02:00
Simon Rozman
bf48214c8c Upgrade OID_GEN_XMIT_OK and OID_GEN_RCV_OK to support 64-bit counters
This commit addresses issues reported by NDISTEST/1c_64bitoids.

It also revises the OID request writing, as adaptive 32/64-bit responses
required by OID_GEN_XMIT_OK and OID_GEN_RCV_OK would grow the current
TunOidQuery() design quite complex and introduce duplicated code.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 12:57:22 +02:00
Simon Rozman
1c13736068 Access PowerState interlocked
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 12:51:15 +02:00
Simon Rozman
480000f429 Revert "Implement NDIS 6.30's NDIS_MINIPORT_ATTRIBUTES_NO_PAUSE_ON_SUSPEND"
This reverts commit 683cf83befbc8d95de3b13994851087306b19963.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
1b9fee728b Upgrade NDIS_PM_CAPABILITIES to NDIS 6.30
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
9436da8f7e Report correct NDIS version to NdisMRegisterMiniportDriver
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
b6056b95d3 Add extra ASSERT to check PoweredTransactionCount is 0 on power-on
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
e7d5cdc4f0 Implement NDIS 6.30's NDIS_MINIPORT_ATTRIBUTES_NO_PAUSE_ON_SUSPEND
NDIS >=6.30 allows bringing adapter to low-power state without pausing
it. As Wintun's pause cancels all pending IRP and we want to keep
disturbing client to a minimum, OID_PNP_SET_POWER cancels pending NBLs
and wait for active NBLs to finish only.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:24 +02:00
Simon Rozman
58900a4841 Implement dynamic NDIS 6.30 detection
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:24 +02:00
Simon Rozman
934923bbc1 Change TunOidSet/TunOidQuery() parameters
All parameters to TunOidSet/TunOidQuery() are contained inside a
NDIS_OID_REQUEST struct. But, the main rationale behind this commit is
that OID_PNP_SET_POWER set request will require pointer to original
NDIS_OID_REQUEST struct for NdisMOidRequestComplete() call, should we
want to implement pending PnP power-down.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:24 +02:00
Simon Rozman
8eefe85bb2 Move packet queue clearing into a reusable function
We will need this in OID_PNP_SET_POWER.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:23 +02:00
Jason A. Donenfeld
bba0f6aecf Do not call NdisMPauseComplete before TunPause returns
Otherwise we trigger a bugcheck on Server 2019.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-29 21:42:46 +01:00
Simon Rozman
7b3ea2a8a9 Reintroduce outgoing statistics
Outgoing statistics-keeping was accidentally dropped in
ed93692ca0049123979e0497aa3c4a4698f844cd. This commit reintroduces it.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-29 16:23:24 +01:00
Simon Rozman
f6972f147c Reintroduce .editorconfig and suggest tab usage
This time we don't impose 8-space tabulators, but merely suggest text
editors to use tabulator indenting. Otherwise, Visual Studio IDE
configured to use spaces instead of tabulators keeps corrupting
indentation.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-29 16:23:24 +01:00
Simon Rozman
cf01a7ded2 Use tabs for indentation and spaces for horizontal alignment
Screen is a valuable real-estate on small displays or when working in
less than maximized or full-screen Visual Studio IDE.

This commit replaces tabulators used for horizontal alignment with
spaces, and stops imposing 8-space tabulators on everyone.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-29 06:05:17 +01:00
Jason A. Donenfeld
93638dd074 Add link to readme
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-28 16:54:38 +01:00
Simon Rozman
06851f8497 Fix driver service name
AddService:
- ServiceName parameter must not be localized. [1]
- EventName does not need to be specified when same as ServiceName.
   [1]

Service-related Ndi key:
- The Service value must match the ServiceName parameter of the
  AddService directive that references the service-install-section for
  the primary service. [2]

[1](https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-addservice-directive)
[2](https://docs.microsoft.com/en-us/windows-hardware/drivers/network/adding-service-related-values-to-the-ndi-key)

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 14:30:44 +01:00
Simon Rozman
55e911020e Add documentation files to the .vcxproj
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 14:30:44 +01:00
Simon Rozman
5e5cb74553 Limit minimum size of exchange buffer
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 12:08:14 +01:00
Simon Rozman
6085957d9d Check buffer for oversize after MDL size consultation
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 11:48:01 +01:00
Simon Rozman
69d6f003e4 Clean TunQueueProcess()
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 11:48:01 +01:00
Simon Rozman
745acc8b95 Tighten code analysis annotations
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 11:22:16 +01:00
Simon Rozman
49847b5508 Skip IRPs we fail to get MDL access from
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 11:12:59 +01:00
Jason A. Donenfeld
f0275285a3 Skip impossibly large NBs when removing
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-28 09:11:06 +01:00
Jason A. Donenfeld
64c408a2e4 Don't discard unfitting NBLs and fix prepend ref counting
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-28 08:30:37 +01:00
Simon Rozman
9294d4b498 Fix uninitialized status and remove redundant locking in TunQueueProcess
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 07:41:44 +01:00
Simon Rozman
5e87977cf8 Kill some more Camels
Disclaimer: No animals were hurt in this commit.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-28 07:41:43 +01:00
Jason A. Donenfeld
03a45fb768 Better ctx management
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-27 17:16:35 +01:00
Jason A. Donenfeld
51f9f59ea9 Further specify LUID member 2019-03-27 16:13:00 +01:00
Simon Rozman
7c6591b4f6 Update documentation
Device name actually uses LUID index only. Not an entire LUID. IfType
in LUID is always 53 (IF_TYPE_PROP_VIRTUAL).

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-27 15:18:37 +01:00
Simon Rozman
015999430f Simplify adapter context extraction from device extension
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-27 15:18:37 +01:00
Simon Rozman
b157105c58 Revise adapter pausing
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-27 13:47:38 +01:00
Jason A. Donenfeld
2ee3a99690 Add basic usage info
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-27 11:44:15 +01:00
Simon Rozman
269007f606 Kill some more Camels
Disclaimer: No animals were hurt in this commit.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-27 10:12:53 +01:00
Simon Rozman
894a7f54a1 Upgrade TunNBLRefDec() to provide IRQL hints to NDIS
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-27 09:18:47 +01:00
Jason A. Donenfeld
0dac9b2bc7 Use CSQ instead of StartIO
This also introduces a proper queueing and refcounting system, which
should increase performance and allow for IRP cancelation.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-27 09:00:19 +01:00
Jason A. Donenfeld
ce9936089c Add description of IO_CSQ algorithms
Remove this file when this is done.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-26 08:01:50 +01:00
Simon Rozman
9704a4d11f Terminate device connection on NDIS pause
If device connection is not terminated on NDIS pause, the driver doesn't
unload when adapter is disabled. This also prevents driver updates
without reboot.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Simon Rozman
9fbc8091ab Add some basic assert checks
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Simon Rozman
b6f0e07c2f Unify and revise NDIS pause checks
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Simon Rozman
d6dfda0421 Rename ActiveNBLCount to ActiveTransactionCount
We are not using this counter for NBL counting only.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Simon Rozman
775386173c Enable better debugging support for Debug driver builds
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Simon Rozman
2e35974a24 Fix ActiveNBLCount management in TunDispatchWrite()
The ActiveNBLCount must be bumped _before_ adapter state is checked.
Otherwise, there is a window of code that may allow adapter transition
from pausing to paused state, followed by a
NdisMIndicateReceiveNetBufferLists() call.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Simon Rozman
999cfaabcc Optimize ActiveNBLCount management in TunSendNetBufferLists
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Simon Rozman
a9afa3a692 Fix the UAF issue with premature MDL release in IRP_MJ_WRITE
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00
Jason A. Donenfeld
03479caf9d Initial commit
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-22 16:52:31 -06:00