TDI shutdown

I have a storage filter driver that is also a TDI client. At system start
time, I have a worker thread which establishes a TCP connection to a remote
server. I use TdiRegisterPnPHandlers() to register for notification of the
TDI system being up and running (via the opcode TDI_PNP_OP_NETREADY) and
then I subsequently make the call to connect. However, at shutdown time I
am having difficulty finding the best way to send the disconnect. Although
I receive calls to my AddAddress() handler at startup, I never get any
corresponding calls to my DelAddress() handler at shutdown. By the time my
filter driver is called with the shutdown IRP, TDI seems to have already
left the building (I create and send the disconnect IRP (IoCallDriver()
returns STATUS_PENDING), but no network traffic is produced and the
completion routine is never called). I found the post below in the
archives, but considering that I never get any calls to the DelAddress
handler, is there anything else that TdiRegisterPnPHandlers() can do for me?

It’s beginning to look like my core problem is that my TDI client is a
storage driver, which doesn’t get shut down until after the networking
drivers. Does that imply that I would need to build a separate TDI or NDIS
filter driver and have that driver send the disconnect just before
networking is shut down? Or would there be a cleaner way to handle all of
this from within my storage driver?

Thanks,
Jeff

I don’t think that IP stack itself is ever shut down, but the underlying
miniports are surely yes, and sometimes this can cause problems in TDI
client
code - for instance, being unable to send a FIN on shutdown due to NIC
adapter
already down. TDI PnP callbacks can be helpful to solve this.

The order of shutdown is:

  • MJ_SHUTDOWN for the drivers which registered for it
  • MJ_SHUTDOWN for FSD volumes
  • MJ_SHUTDOWN for disk stacks (in fact propagated by the FSD down the
    disk
    stack)
  • MJ_POWER IRPs.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

> server. I use TdiRegisterPnPHandlers() to register for notification of the

TDI system being up and running (via the opcode TDI_PNP_OP_NETREADY)
and
then I subsequently make the call to connect. However, at shutdown time I
am having difficulty finding the best way to send the disconnect. Although
I receive calls to my AddAddress() handler at startup, I never get any
corresponding calls to my DelAddress() handler at shutdown. By the time my

I think that TdiRegisterPnPHandlers will also deliver you the notification just
before powering down the NIC over which this connection is established. It is
the time to send a FIN (TDI_DISCONNECT_RELEASE).

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Maxim,

Thanks for responding.

This is the part that I do not understand. When I call
TdiRegisterPnPHandlers() I specify all four callback functions (AddAddress,
DelAddress, PowerChange, BindingChange). But after the machine comes up
(where I *do* receive the BindingChange and AddAddress calls) I never get
another callback. The machine will completely shutdown and none of my
functions get called at all. Am I missing something here or is this just
not functioning as expected? What you are describing - where I get called
just before NIC X gets shut down - would be absolutely perfect. I just
don’t get any such notifications through this interface. ???

Thank you,
Jeff

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> server. I use TdiRegisterPnPHandlers() to register for notification of
>> the
>> TDI system being up and running (via the opcode TDI_PNP_OP_NETREADY)
>>and
>> then I subsequently make the call to connect. However, at shutdown time
>> I
>> am having difficulty finding the best way to send the disconnect.
>> Although
>> I receive calls to my AddAddress() handler at startup, I never get any
>> corresponding calls to my DelAddress() handler at shutdown. By the time
>> my
>
> I think that TdiRegisterPnPHandlers will also deliver you the notification
> just
> before powering down the NIC over which this connection is established.
> It is
> the time to send a FIN (TDI_DISCONNECT_RELEASE).
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

> TdiRegisterPnPHandlers() I specify all four callback functions (AddAddress,

DelAddress, PowerChange, BindingChange). But after the machine comes up

I expect PowerChange to be called, is it so?

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Actually, no. PowerChange never gets called at all. I call
TdiRegisterPnPHandlers during the DriverEntry of my boot time storage
filter, so that’s about as early as it could possibly be called I would
think. During the call to register handlers, I get a call to binding
change. Then when the system comes up I get two calls to AddAddress and 3
more calls to binding change. After that, throughout the system operation
and during the entire shutdown process, none of the 4 handlers are called.
That’s why I’m confused??

Thanks again,
Jeff

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> TdiRegisterPnPHandlers() I specify all four callback functions
>> (AddAddress,
>> DelAddress, PowerChange, BindingChange). But after the machine comes up
>
> I expect PowerChange to be called, is it so?
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

To re-cap, I never seem to get any TDI notifications that the adapter is
going down, and because my driver is a storage filter driver by the time it
sees an actual system shutdown notification TDI is no longer functioning.

So I am thinking that my only choice here is to create a second filter
driver and attach it to a networking device so that I can intercept just
before TDI actually shuts down. I need a way to be able to send a TCP
disconnect right before the system shuts down.

Is there some other better/cleaner way to approach this?

Thanks,
Jeff

“Jeff B.” wrote in message news:xxxxx@ntdev…
> Actually, no. PowerChange never gets called at all. I call
> TdiRegisterPnPHandlers during the DriverEntry of my boot time storage
> filter, so that’s about as early as it could possibly be called I would
> think. During the call to register handlers, I get a call to binding
> change. Then when the system comes up I get two calls to AddAddress and 3
> more calls to binding change. After that, throughout the system operation
> and during the entire shutdown process, none of the 4 handlers are called.
> That’s why I’m confused??
>
> Thanks again,
> Jeff
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntdev…
>>> TdiRegisterPnPHandlers() I specify all four callback functions
>>> (AddAddress,
>>> DelAddress, PowerChange, BindingChange). But after the machine comes up
>>
>> I expect PowerChange to be called, is it so?
>>
>> Maxim Shatskih, Windows DDK MVP
>> StorageCraft Corporation
>> xxxxx@storagecraft.com
>> http://www.storagecraft.com
>>
>>
>
>
>