NdisCompleteBindAdapter question

Hello All.

I read MSDN and WDK’s NdisProt example to understand NDIS. The problem is that I don’t understand when have I use NdisCompleteBindAdapter function. As far as I understand, if I want to defer binding of an adapter I have to return NDIS_STATUS_PENDING from ProtocolBindAdapter and then call NdisCompleteBindAdapter when binding finishes. Tried, it works. But MSDN also says:

“If the input Status is NDIS_STATUS_SUCCESS, ProtocolOpenAdapterComplete carries out whatever driver-determined per-binding operations its ProtocolBindAdapter function would have done in a synchronous binding operation. Next, ProtocolOpenAdapterComplete calls NdisCompleteBindAdapter with NDIS_STATUS_SUCCESS for the Status and OpenStatus arguments and with the BindContext handle stored at ProtocolBindingContext by the ProtocolBindAdapter function. Then, ProtocolOpenAdapterComplete returns control.”

So, has a driver to call this function from its ProtocolOpenAdapterComplete or not? WDK’s NdisProt example doesn’t do that, so I’m in doubts.


Thanking In Advance,
Mikae.

Short answer: sometimes.

It helps if you look at Binding as separate from Opening an adapter. NDIS asks you to Bind, and then you complete the Bind operation back to NDIS. Separately, you can ask NDIS to Open an adapter, and it will complete that Open operation back to you. It’s confusing, of course, because the Open operation occurs “nested” within the Bind operation. Furthermore, both actions can be either synchronous or asynchronous, so there are several paths the code flow can take.

In the simplest case, Open operation completes synchronously, and your Bind completes synchronously:

|--------- Bind ------------|
|------ Open -------|

Now suppose Open needs to pend (NdisOpenAdapter[Ex] returns NDIS_STATUS_PENDING). Then you have two options:

  1. You can have Bind pend too (your ProtocolBindAdapter[Ex] returns NDIS_STATUS_PENDING), and then complete the Bind operation later (via NdisCompleteBindAdapter[Ex]) once the Open completes (via ProtocolOpenAdapterComplete[Ex]).

|--------- Bind ----------- pend / \ complete ----|
|------ Open — pend / \ complete -------------|

  1. You can just block synchronously in your Bind handler, until the Open operation completes. Then you can complete Bind synchronously (return anything except NDIS_STATUS_PENDING from ProtocolBindAdapter[Ex]), and do *not* call NdisCompleteBindAdapter[Ex].

|--------- Bind ----------- (wait) -------------------|
|------ Open — pend / \ complete ----|

As you’ve seen, NDISPROT elects for option #2 (see ndisbind.c:613 for v5, and ndisbind.c:626 for v6.0). However, the docs you are quoting assume you went with option #1. You can select either option. Since it sounds like you have working code using option #2, I’d stick with that.

BTW, if my goofy ASCII diagrams are incomprehensible, don’t spend too much time trying to make sense of them. I just made up the syntax on the spot :).

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Thursday, March 10, 2011 6:37 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] NdisCompleteBindAdapter question

Hello All.

I read MSDN and WDK’s NdisProt example to understand NDIS. The problem is that I don’t understand when have I use NdisCompleteBindAdapter function. As far as I understand, if I want to defer binding of an adapter I have to return NDIS_STATUS_PENDING from ProtocolBindAdapter and then call NdisCompleteBindAdapter when binding finishes. Tried, it works. But MSDN also says:

“If the input Status is NDIS_STATUS_SUCCESS, ProtocolOpenAdapterComplete carries out whatever driver-determined per-binding operations its ProtocolBindAdapter function would have done in a synchronous binding operation. Next, ProtocolOpenAdapterComplete calls NdisCompleteBindAdapter with NDIS_STATUS_SUCCESS for the Status and OpenStatus arguments and with the BindContext handle stored at ProtocolBindingContext by the ProtocolBindAdapter function. Then, ProtocolOpenAdapterComplete returns control.”

So, has a driver to call this function from its ProtocolOpenAdapterComplete or not? WDK’s NdisProt example doesn’t do that, so I’m in doubts.


Thanking In Advance,
Mikae.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thank you for the comprehensive and quick reply. It looks like that I understood your ASCII art :).