marcus905 / libnfc

Automatically exported from code.google.com/p/libnfc
GNU Lesser General Public License v3.0
0 stars 0 forks source link

[PATCH] nfc_list_devices never gives different results after the first run #252

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile the (attached) looping nfc-list program.
2. Run it and wait for a line of output.
3. Plug in a supported nfc device and wait for another line of output.

What is the expected output?

./nfc-list uses libnfc 1.7.0-rc7
No NFC device found.
./nfc-list uses libnfc 1.7.0-rc7
NFC device: SCM Micro / SCL3711-NFC&RW opened

What do you see instead?

./nfc-list uses libnfc 1.7.0-rc7
No NFC device found.
./nfc-list uses libnfc 1.7.0-rc7
No NFC device found.

What version of the product are you using? On what operating system?

libnfc-1.7.0_rc7 on linux

Please provide any additional information below.

So, it looks as though this is because usb_prepare() maintains an initialized 
state after the first time it's called, which effectively blocks the calls to 
usb_find_busses() and usb_find_devices() to recheck for new devices.  As such, 
usb_get_busses() returns the old global bus object that contains the old 
devices.

This means that unplugging a device and replugging it in won't work, but 
instead results in a broken file descriptor error, since it's trying to access 
the location of the old usb device's descriptor rather than the one that was 
assigned when the device was plugged back in.  It also means that after the 
first run of usb_list_devices (and the associated scan command which calls 
usb_prepare()), the list of devices will never change whilst the nfc module is 
still loaded.

I've attached a patch that reruns the usb_find_busses() and usb_find_devices() 
functions, but without recalling usb_init().  It seems to solve the problem, 
but I'd appreciate someone looking it over.

Just let me know if anyone needs any further information or has any 
comments/questions about this...

Original issue reported on code.google.com by mike.auty@gmail.com on 21 Jun 2013 at 11:46

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision ebe6335fc1f7.

Original comment by mike.auty@gmail.com on 22 Jun 2013 at 9:06

GoogleCodeExporter commented 9 years ago
Thanks Mike, you solved a problem we never thought of ;-)

Original comment by yob...@gmail.com on 22 Jun 2013 at 9:19