Author Topic: Can be access the usb port like a file?  (Read 19037 times)

mr_asadi

  • Member
  • ***
  • Posts: 11
Can be access the usb port like a file?
« on: August 12, 2012, 02:51:07 am »
Hello
I am trying to write my own project about usb management over network,so my essential question is " what can we do with usb ports in management scope?"
For example , can we block all of them for limit the user access,or can we set a password on a specific usb port?or can we treat with usb ports like a file that this action enable us to set attributes such as readonly,hidden and etc? what about sharing them?
Thank you


mr_asadi
« Last Edit: August 12, 2012, 03:11:52 am by mr_asadi »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Can be access the usb port like a file?
« Reply #1 on: August 12, 2012, 08:16:11 pm »
How an application communicates with a USB device depends on the device driver that the host OS has assigned to the device. Under Windows, the choice of driver depends on finding a match between the information in the descriptors that Windows retrieves on device attachment or bootup and the information stored in the PC's INF files. For example, host applications can access devices in the USB mass storage class using the OS's file system.

Also see this information about the devcon utilty:

http://support.microsoft.com/kb/311272

mr_asadi

  • Member
  • ***
  • Posts: 11
Re: Can be access the usb port like a file?
« Reply #2 on: August 13, 2012, 05:26:35 am »
Hi again dear Jan
I studied your book USB Complete,in Chapter 10 you explain about how applications can obtain information about attached devices and request a handle for communicating with a device and detect when a device is attached or removed.
But at the end of this chapter,I dont understand how communicate with a device!"Communication with device" Exactly what that means?
I use  the API Functions that you describe and I got the DevicePathName base on this Guid:

Guid:
"{3abf6f2d-71c4-462a-8a92-1e6861e6af27}"

DevicePathName:
"\\\\?\\pci#ven_8086&dev_2934&subsys_02bc1028&rev_03#3&11583659&0&e8#{3abf6f2d-71c4-462a-8a92-1e6861e6af27}"

1)who can I get the Guid for USB Ports dynamically?(the "HidD_GetHidGuid()" not working and some of the API Functions returns false value)
2)what's your mind about the DevicePathName that I have?Is it a true DevicePathName for USB Ports?If it is not,where is the problem?
3)What can I do with CreateFile() and the other API Functions about arrive to my goal?

My goal is management USB Ports completely,that this management consist of:
Blocking USB Ports,sharing USB Ports over network,setting a password over them,enable or disable them,setting the attributes on USB Ports such as readonly,hidden, and etc.
I googled about CreateFile() and other API Function but I dont get my answer yet.
Thank you


mr_asadi
« Last Edit: August 13, 2012, 05:55:21 am by mr_asadi »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Can be access the usb port like a file?
« Reply #3 on: August 13, 2012, 10:03:40 am »
My HID example code shows how applications can communicate with HID-class devices. For other devices, the host system uses different APIs, .NET classes, or other code. For example, to access a USB drive, an application uses file system functions. These communications carry out the device's purpose such as sending keypresses, storing files, etc.

For functions such as enabling and disabling devices, see the devcon example I referenced in my earlier post.

Whether applications can read or write to a USB device depends on the driver. For example, applications can read keyboard keypresses and can write to the keyboard's LEDs. I don't know of any way to change that other than possibly writing a filter driver, and that would apply to keyboards only. 

The same goes for password protection and other characteristics.

Bret

  • Frequent Contributor
  • ****
  • Posts: 68
Re: Can be access the usb port like a file?
« Reply #4 on: August 13, 2012, 10:24:05 pm »
To put it simply, no, you cannot treat a USB port like a file.  As the name indicates, USB is a bus, not a file system.  It can handle many, many different types of devices (keyboards, mice, joysticks, printers, video & audio devices, network adapters, etc.) in addition to MSD's (Mass Storage Devices) which contain files.  E.g., assigning a read-only or hidden file attribute to a keyboard (or a port that a keyboard is attached to) doesn't even make sense.

mr_asadi

  • Member
  • ***
  • Posts: 11
Re: Can be access the usb port like a file?
« Reply #5 on: August 14, 2012, 05:21:27 am »
Hi,
Ok, so what is your mind about USB mass storage class?!
You tell me that the host applications can access devices in the USB mass storage class using the OS's file system.From programming viewpoint can I do my work with spesific API Functions that communicate with the USB mass storage devices?
What is defference between communicatin with the USB device that we learn about that in chapter 10 of USB complete book and communicate with USB mass storage devices that is a subclass of the USB devices?
have you any sample code  or API Functions to help me in this content?

In addition I have been some question in my earlier post that they are not solved yet!

I use  the API Functions that you describe and I got the DevicePathName base on this Guid:

Guid:
"{3abf6f2d-71c4-462a-8a92-1e6861e6af27}"

DevicePathName:
"\\\\?\\pci#ven_8086&dev_2934&subsys_02bc1028&rev_03#3&11583659&0&e8#{3abf6f2d-71c4-462a-8a92-1e6861e6af27}"

1)who can I get the Guid for USB Ports dynamically?(the "HidD_GetHidGuid()" not working and some of the API Functions returns false value)
2)what's your mind about the DevicePathName that I have?Is it a true DevicePathName for USB Ports?If it is not,where is the problem?
3)What can I do with CreateFile()


Thank you for your time
« Last Edit: August 14, 2012, 05:24:47 am by mr_asadi »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Can be access the usb port like a file?
« Reply #6 on: August 14, 2012, 09:25:55 am »
>From programming viewpoint can I do my work with spesific API Functions that communicate with the USB mass storage devices?

Yes, if the USB device you're communicating with is a mass-storage-class device.

>What is defference between communicatin with the USB device that we learn about that in chapter 10 of USB complete book and communicate with USB mass storage devices that is a subclass of the USB devices?

Chapter 10 is about detecting devices. Host applications use class-specific APIs, .NET classes, etc. to perform communications that carry out the device's function (detect keypresses, read files, etc.)

>have you any sample code  or API Functions to help me in this content?

What you need depends on the device class. Lvr.com has example code for HIDs, devices that use the WinUSB driver, and USB virtual serial-port devices.

>1)who can I get the Guid for USB Ports dynamically?(the "HidD_GetHidGuid()" not working and some of the API Functions returns false value)

See

http://msdn.microsoft.com/en-us/library/ff552240.aspx

>2)what's your mind about the DevicePathName that I have?Is it a true DevicePathName for USB Ports?If it is not,where is the problem?

see above

>3)What can I do with CreateFile()

What you can do with CreateFile varies with the driver assigned to the device attached to the port.