pothosware / SoapyPlutoSDR

Soapy SDR plugin for PlutoSDR
https://github.com/pothosware/SoapyPlutoSDR/wiki
GNU Lesser General Public License v2.1
57 stars 22 forks source link

Unable to claim interface #68

Closed rherban closed 1 week ago

rherban commented 2 weeks ago

Debian 9 on Beaglebone Black

Soapy bits Lib Version: v0.8.1-gbb33b2d2 API Version: v0.8.200 ABI Version: v0.8-3

SoapyPlutoSDR 0.2.2-03b5ae2-cache (Removing the cache results from issue #66 )

libiio 0.25 Built with: ../../cmake-3.27.4/bin/cmake ../ -DCPP_BINDINGS=ON -DPYTHON_BINDINGS=ON -WITH_USB_BACKEND=ON -WITH_LOCAL_BACKEND=ON And also tried (per recommendations in #50 ): ../../cmake-3.27.4/bin/cmake ../ -DCPP_BINDINGS=ON -DPYTHON_BINDINGS=ON -DWITH_USB_BACKEND=ON -DWITH_LOCAL_BACKEND=NO -DWITH_IIOD=NO

But it still fails to load the device:

Aug 27 14:44:55 7afa start.py[19081]: Adding Soapy device: usb:1.4.5 PlutoSDR #0 usb:1.4.5
Aug 27 14:44:55 7afa start.py[19081]: [WARNING] Unable to scan local: -19
Aug 27 14:44:55 7afa start.py[19081]:
Aug 27 14:44:56 7afa start.py[19081]: [INFO] Opening PlutoSDR #0 usb:1.4.5...
Aug 27 14:44:57 7afa start.py[19081]: - frequency range: 7e+07, 6e+09
Aug 27 14:45:03 7afa start.py[19081]: [WARNING] Unable to scan local: -19
Aug 27 14:45:03 7afa start.py[19081]:
Aug 27 14:45:04 7afa start.py[19081]: ERROR: Unable to claim interface 1:4:5: Device or resource busy (16)
Aug 27 14:45:05 7afa start.py[19081]: Removing Soapy device: PlutoSDR #0 usb:1.4.5

(The Adding and Removing lines are from my code)

dmesg:

[67370.495235] usb 1-1.3: new high-speed USB device number 4 using musb-hdrc
[67370.595432] usb 1-1.3: New USB device found, idVendor=0456, idProduct=b673
[67370.595457] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[67370.595465] usb 1-1.3: Product: PlutoSDR (ADALM-PLUTO)
[67370.595473] usb 1-1.3: Manufacturer: Analog Devices Inc.
[67370.595481] usb 1-1.3: SerialNumber: 10447384b9040006230015004923dbd425
[67370.611955] rndis_host 1-1.3:1.0 eth1: register 'rndis_host' at usb-musb-hdrc.1-1.3, RNDIS device, 00:e0:22:51:cb:ad
[67370.617573] usb-storage 1-1.3:1.2: USB Mass Storage device detected
[67370.631849] scsi host0: usb-storage 1-1.3:1.2
[67370.649579] cdc_acm 1-1.3:1.3: ttyACM0: USB ACM device
[67371.647027] scsi 0:0:0:0: Direct-Access     Linux    File-Stor Gadget 0419 PQ: 0 ANSI: 2
[67371.659314] sd 0:0:0:0: [sda] 61441 512-byte logical blocks: (31.5 MB/30.0 MiB)
[67371.659640] sd 0:0:0:0: [sda] Write Protect is off
[67371.659657] sd 0:0:0:0: [sda] Mode Sense: 0f 00 00 00
[67371.659928] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[67371.670592] sd 0:0:0:0: Attached scsi generic sg0 type 0
[67371.671707]  sda: sda1
[67371.682044] sd 0:0:0:0: [sda] Attached SCSI removable disk

SoapySDRUtil:

SoapySDRUtil --probe="driver=plutosdr"
######################################################
##     Soapy SDR -- the SDR abstraction library     ##
######################################################

Probe device driver=plutosdr
[WARNING] Unable to scan local: -19

[INFO] Opening PlutoSDR #0 usb:1.4.5...

----------------------------------------------------
-- Device identification
----------------------------------------------------
  driver=PlutoSDR
  hardware=ADALM-PLUTO
  ad9361-phy,model=ad9363a
  ad9361-phy,xo_correction=39999899
  backend_version=0.21 (git tag: v0.21  )
  fw_version=v0.32
  hw_model=Analog Devices PlutoSDR Rev.C (Z7010-AD9363A)
  hw_model_variant=0
  hw_serial=10447384b9040006230015004923dbd425
  library_version=0.25 (git tag: v0.25)
  local,kernel=4.19.0-119999-g6edc6cd
  uri=usb:1.4.5
  usb,idProduct=b673
  usb,idVendor=0456
  usb,libusb=1.0.21.11156
  usb,product=PlutoSDR (ADALM-PLUTO)
  usb,release=2.0
  usb,serial=10447384b9040006230015004923dbd425
  usb,vendor=Analog Devices Inc.

----------------------------------------------------
-- Peripheral summary
----------------------------------------------------
  Channels: 1 Rx, 1 Tx
  Timestamps: NO
  Sensors: xadc_temp0, xadc_voltage0, xadc_voltage1, xadc_voltage2, xadc_voltage3, xadc_voltage4, xadc_voltage5, xadc_voltage6, xadc_voltage7, xadc_voltage8, adm1177_current0, adm1177_voltage0, ad9361-phy_temp0, ad9361-phy_voltage2
     * xadc_temp0: 52.907532 C
     * xadc_voltage0 (vccint): 1.004150 V
     * xadc_voltage1 (vccaux): 1.787842 V
     * xadc_voltage2 (vccbram): 1.004150 V
     * xadc_voltage3 (vccpint): 1.001953 V
     * xadc_voltage4 (vccpaux): 1.787842 V
     * xadc_voltage5 (vccoddr): 1.346924 V
     * xadc_voltage6 (vrefp): 1.238525 V
     * xadc_voltage7 (vrefn): -0.008057 V
     * xadc_voltage8: 0.804199 V
     * adm1177_current0:
     * adm1177_voltage0:
     * ad9361-phy_temp0: 35.965000 C
     * ad9361-phy_voltage2: 0.421245 V

----------------------------------------------------
-- RX Channel 0
----------------------------------------------------
  Full-duplex: YES
  Supports AGC: YES
  Stream formats: CS8, CS12, CS16, CF32
  Native format: CS16 [full-scale=2048]
  Antennas: A_BALANCED
  Full gain range: [0, 73] dB
    PGA gain range: [0, 73] dB
  Full freq range: [70, 6000] MHz
    RF freq range: [70, 6000] MHz
  Sample rates: [0.260417, 61.44] MSps
  Filter bandwidths: 0.2, 1, 2, 3, 4, 6, 7, 8, 9, 10 MHz

----------------------------------------------------
-- TX Channel 0
----------------------------------------------------
  Full-duplex: YES
  Supports AGC: NO
  Stream formats: CS8, CS12, CS16, CF32
  Native format: CS16 [full-scale=32768]
  Antennas: A
  Full gain range: [0, 89] dB
    PGA gain range: [0, 89] dB
  Full freq range: [70, 6000] MHz
    RF freq range: [70, 6000] MHz
  Sample rates: [0.260417, 61.44] MSps
  Filter bandwidths: 0.2, 1, 2, 3, 4, 6, 7, 8, 9, 10 MHz

If I revert to SoapyPlutSDR 0.2.1 it works as expected, as evidenced on another beaglebone here:

SoapySDRUtil --info
######################################################
##     Soapy SDR -- the SDR abstraction library     ##
######################################################

Lib Version: v0.8.1-gbb33b2d2
API Version: v0.8.200
ABI Version: v0.8-3
Install root: /usr/local
Search path:  /usr/local/lib/SoapySDR/modules0.8-3
Module found: /usr/local/lib/SoapySDR/modules0.8-3/libHackRFSupport.so   (0.3.4-6c0c33f)
Module found: /usr/local/lib/SoapySDR/modules0.8-3/libPlutoSDRSupport.so (0.2.1-b906b27)
Module found: /usr/local/lib/SoapySDR/modules0.8-3/librtlsdrSupport.so   (0.3.3-068aa77)
Aug 27 14:49:20 a542 start.py[28209]: Adding Soapy device: usb:1.20.5 PlutoSDR #0 usb:1.20.5
Aug 27 14:49:20 a542 start.py[28209]: [INFO] Opening PlutoSDR #0 usb:1.20.5...
Aug 27 14:49:20 a542 start.py[28209]: - frequency range: 7e+07, 6e+09
rherban commented 2 weeks ago

Yeah, I'm not downloading that.

zuckschwerdt commented 2 weeks ago

It's malware and mediafire already flagged and removed it. It seems there is a surge of these malware attacks on GitHub. Only yesterday there was another malware post on SoapySDR.

zuckschwerdt commented 2 weeks ago

Interestingly the malware poster seems to be a recent target of malware himself: https://github.com/contentauth/c2pa-c/issues/17

zuckschwerdt commented 2 weeks ago

To your question: is it possible that this is a race condition where you still have the usb descriptor open? Those Adding and Removing lines enumerate USB devices in your codes, right?

rherban commented 2 weeks ago

Yes, the adding and removing lines are from my code.

I have a periodic call to SoapySDR.Device.enumerate() and stash that into an array and subsequent removal when the device is unplugged, hence the issues I'm opening. But if Soapy still thinks a device is attached, it throws a wrench into the works.

zuckschwerdt commented 2 weeks ago

That sounds like safe operations and if you are not accessing USB yourself this error should not happen. It might be that the Python wrapper somehow keeps the device open, but for that there would need to be a make device somewhere not just enumerate. I'll try to test this in C.

zuckschwerdt commented 2 weeks ago

I can confirm that this happens in plain C too. The [WARNING] Unable to scan local: -19 just means a backend is not available (e.g. "local:" on MacOS). The ERROR: Unable to claim interface happens when the Device is still open (e.g. SoapySDRDevice_make() but no matching SoapySDRDevice_unmake() before a rescan). But that's limited to the usb: backend, the ip: backend should still work, if you have that available.

rherban commented 2 weeks ago

I'll get rid of the local backend as I don't think I have a real use for that.

But for unmake(), I'm not sure how to do that in Python. None of the examples do an explicit unmake, they just deactivate and close the stream.

Can you provide an example?

zuckschwerdt commented 2 weeks ago

As far as I can see close() will also unmake the device and del will close(). So sdr.close() or del sdr should do. https://github.com/pothosware/SoapySDR/blob/master/swig/python/SoapySDR.in.i#L410