Need advice on driver development for usb-flash

Do I understand correctly that the driver for the USB Flash device must be a function driver(USB Function Mass Storage Client Driver)? On the msdn website of the manual for the development of this driver, is WDM technology used or is it more appropriate to use WDF today?

>

the driver for the USB Flash device must be a
function driver(USB Function Mass Storage Client Driver)

Well, there already IS a standard Windows driver for USB Mass Storage Class devices, right?

is WDM technology used or is it
more appropriate to use WDF today?

Assuming you want to write your own driver to match a given VID/PID (for example) you would use WDF. See the thread “Help Stamp Out…”

Peter
OSR
@OSRDrivers

> Well, there already IS a standard Windows driver for USB Mass Storage Class

devices, right?

This is the key point The answer to the question “how do I write a driver for a USB flash device” is that you DON’T. You design your flash device to meet the USB Mass Storage Class specification. As long as you do that, no driver work is required. And please note that your users absolutely do not expect to need a custom driver.

If I want to write a driver that would encrypt the data coming to the USB flash drive, store the keys in certain sectors of the flash drive, share the flash drive on the volume and some other functions. Is it possible that this can be done purely in a filter driver for a flash drive?

Yes it can be done with a filter driver. Be aware that if the encryption
changes the size of the data being stored this effort gets complex quickly.

Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@mail.ru
Sent: Friday, March 16, 2018 3:28 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Need advice on driver development for usb-flash

If I want to write a driver that would encrypt the data coming to the USB
flash drive, store the keys in certain sectors of the flash drive, share the
flash drive on the volume and some other functions. Is it possible that this
can be done purely in a filter driver for a flash drive?


NTDEV is sponsored by OSR

Visit the list online at:
http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software
drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at
http:</http:></http:></http:>

Thank you, Don, for your responding.
I wanted to clarify. Is there a need for a KMDF filter driver or storage filter driver?

kmdf is fine for developing storage filter drivers.

Mark Roddy

On Mon, Mar 19, 2018 at 3:57 AM, xxxxx@mail.ru
wrote:

> Thank you, Don, for your responding.
> I wanted to clarify. Is there a need for a KMDF filter driver or storage
> filter driver?
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:> showlists.cfm?list=ntdev>
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

KMDF is a technology (we refer to it as a “driver model”) that is applicable to writing both device drivers and filter drivers for many different uses.

One entirely appropriate use of KMDF is to write storage filter drivers. So, yes… we would recommend that you use KMDF to write your filter driver for the USB Mass Storage stack.

Peter
OSR
@OSRDrivers

Thank you for your responding.
Do I understand correctly that I need to write the upper filter driver for usb mass storage device, for operations described by the message above?

Yes… I would think an upper filter of USBSTOR would accomplish what you need to do.

Peter
OSR
@OSRDrivers

I tried to add the value of the upper filter to CurrentControlSet \ Enum \ USB by the key of my device, after copying the sys file and creating the service. But there is an error when creating the parameter. Can not create parameter. An error occurred while writing to the registry. Although the user has administrator rights. I tried to use the addfilter application, but it does not see my usb device. Could it be more correct to use an inf file for installation?

create service

sc create USBDRiver1 binPath= \SystemRoot\System32\Drivers\USBDriver1.sys type=
kernel start= demand

xxxxx@mail.ru wrote:

I tried to add the value of the upper filter to CurrentControlSet \ Enum \ USB by the key of my device, after copying the sys file and creating the service. But there is an error when creating the parameter. Can not create parameter. An error occurred while writing to the registry. Although the user has administrator rights. I tried to use the addfilter application, but it does not see my usb device. Could it be more correct to use an inf file for installation?

It’s interesting that you showed us the “sc” command, which worked, but
not the registry manipulation, which did not.

“Can not create parameter” is not a real error.  Exactly what error
value did you get back?

The correct way to manage the UpperFilters value is to use the SetupDi
APIs, which can be rather verbose.  You’ll use SetupDiGetClassDevs and
SetupDiEnumDeviceInfo to find your device. then
SetupDiGetDeviceRegistryProperty to fetch the old SPDRP_UPPERFILTERS
entry.  You then add yourself to that list (if you’re not already in
it), and use SetupDiSetDeviceRegistryProperty to put it back.

Note that simply having administrator rights is not enough.  This has to
be run as an elevated application.  You can do that through the
manifest, or by running it from an administrator shell.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thank you, Tim, for your responding.
For example, I used the code in this article http://www.osronline.com/article.cfm?article=446 (KMDF Filter Driver: 30-Minutes – Installation: Ah…Somewhat Longer). Such callbacks as WdfFltrEvtDeviceAdd, WdfFltrD0Entry, WdfFltrD0Exit are called in windbg when breakpoints are set, but I/O callbacks are not called when trying to read or write to the USB flash drive. Is it possible that something is wrong with the example, or I do not understand something?