Running Intel 7260 in AP mode under Ubuntu 14.04 - linux

I would like to use the built-in WiFi on a Gigabyte mini-ITX system I just bought as an access point. And for some reason I am going in circles.
lspci | grep -i wireless reveals:
04:00.0 Network controller: Intel Corporation Wireless 7260 (rev 73)
lsmod | grep 80211 gives:
mac80211 630669 1 iwlmvm
cfg80211 484040 3 iwlwifi,mac80211,iwlmvm
I installed hostapd. Here is the (more than) minimal hostapd.conf I created:
interface=wlan0
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=test
hw_mode=g
channel=1
beacon_int=100
dtim_period=2
max_num_sta=255
rts_threshold=2347
fragm_threshold=2346
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
wmm_enabled=1
wmm_ac_bk_cwmin=4
wmm_ac_bk_cwmax=10
wmm_ac_bk_aifs=7
wmm_ac_bk_txop_limit=0
wmm_ac_bk_acm=0
wmm_ac_be_aifs=3
wmm_ac_be_cwmin=4
wmm_ac_be_cwmax=10
wmm_ac_be_txop_limit=0
wmm_ac_be_acm=0
wmm_ac_vi_aifs=2
wmm_ac_vi_cwmin=3
wmm_ac_vi_cwmax=4
wmm_ac_vi_txop_limit=94
wmm_ac_vi_acm=0
wmm_ac_vo_aifs=2
wmm_ac_vo_cwmin=2
wmm_ac_vo_cwmax=3
wmm_ac_vo_txop_limit=47
own_ip_addr=127.0.0.1
When I try to run hostapd, I get this:
$ sudo hostapd ./hostapd.conf
Configuration file: ./hostapd.conf
nl80211: Could not configure driver mode
nl80211 driver initialization failed.
hostapd_free_hapd_data: Interface wlan0 wasn't started
So, I read there was a problem with Ubuntu 14.04 and how to get around it.
https://bugs.launchpad.net/ubuntu/+source/wpa/+bug/1289047
Interestingly it appears that now the driver (version 2.1) does something with error, and before it ignored it.
a solution (in desktop cases) is to do following to release resource.. then hostapd has no error....
sudo nmcli nm wifi off
sudo rfkill unblock wlan
this info has been gleaned from https://bbs.archlinux.org/viewtopic.php?pid=1221799
nmcli is part of network-manager, which needed to be installed.
Next,
/etc/hostapd$ sudo nmcli nm wifi off
** (process:5724): WARNING **: Could not initialize NMClient /org/freedesktop/NetworkManager: The name org.freedesktop.NetworkManager was not provided by any .service files
So I ran these commands, which are supposedly a workaround.
/etc/hostapd$ sudo service network-manager start
network-manager start/running, process 5763
/etc/hostapd$ sudo nmcli nm wifi off
/etc/hostapd$ sudo rfkill unblock wlan
But still the same problem with trying to run hostapd.
https://askubuntu.com/questions/472794/hostapd-error-nl80211-could-not-configure-driver-mode recommends this:
sudo ifconfig wlan0 10.15.0.1/24 up
sleep 1
sudo service isc-dhcp-server restart
sudo service hostapd restart
isc-dhcp-server is not yet installed. Everything else ran without showing any error.
Still having the problem though!
ifconfig wlan0 shows:
wlan0 Link encap:Ethernet HWaddr 80:19:34:32:20:a3
inet addr:10.15.0.1 Bcast:10.15.0.255 Mask:255.255.255.0
inet6 addr: fd04:bd3:80e8:1:91e9:7f2e:f005:5af9/64 Scope:Global
inet6 addr: fe80::8219:34ff:fe32:20a3/64 Scope:Link
inet6 addr: fd04:bd3:80e8:1:8219:34ff:fe32:20a3/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:43138 errors:0 dropped:0 overruns:0 frame:0
TX packets:638 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6824297 (6.8 MB) TX bytes:121399 (121.3 KB)
iw list shows:
Wiphy phy0
Band 1:
Capabilities: 0x1062
HT20/HT40
Static SM Power Save
RX HT20 SGI
RX HT40 SGI
No RX STBC
Max AMSDU length: 3839 bytes
DSSS/CCK HT40
Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
Minimum RX AMPDU time spacing: 4 usec (0x05)
HT TX/RX MCS rate indexes supported: 0-15, 32
Frequencies:
* 2412 MHz [1] (22.0 dBm)
* 2417 MHz [2] (22.0 dBm)
* 2422 MHz [3] (22.0 dBm)
* 2427 MHz [4] (22.0 dBm)
* 2432 MHz [5] (22.0 dBm)
* 2437 MHz [6] (22.0 dBm)
* 2442 MHz [7] (22.0 dBm)
* 2447 MHz [8] (22.0 dBm)
* 2452 MHz [9] (22.0 dBm)
* 2457 MHz [10] (22.0 dBm)
* 2462 MHz [11] (22.0 dBm)
* 2467 MHz [12] (22.0 dBm) (passive scanning, no IBSS)
* 2472 MHz [13] (22.0 dBm) (passive scanning, no IBSS)
Bitrates (non-HT):
* 1.0 Mbps
* 2.0 Mbps (short preamble supported)
* 5.5 Mbps (short preamble supported)
* 11.0 Mbps (short preamble supported)
* 6.0 Mbps
* 9.0 Mbps
* 12.0 Mbps
* 18.0 Mbps
* 24.0 Mbps
* 36.0 Mbps
* 48.0 Mbps
* 54.0 Mbps
Band 2:
Capabilities: 0x1062
HT20/HT40
Static SM Power Save
RX HT20 SGI
RX HT40 SGI
No RX STBC
Max AMSDU length: 3839 bytes
DSSS/CCK HT40
Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
Minimum RX AMPDU time spacing: 4 usec (0x05)
HT TX/RX MCS rate indexes supported: 0-15, 32
Frequencies:
* 5180 MHz [36] (22.0 dBm) (passive scanning, no IBSS)
* 5200 MHz [40] (22.0 dBm) (passive scanning, no IBSS)
* 5220 MHz [44] (22.0 dBm) (passive scanning, no IBSS)
* 5240 MHz [48] (22.0 dBm) (passive scanning, no IBSS)
* 5260 MHz [52] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5280 MHz [56] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5300 MHz [60] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5320 MHz [64] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5500 MHz [100] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5520 MHz [104] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5540 MHz [108] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5560 MHz [112] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5580 MHz [116] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5600 MHz [120] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5620 MHz [124] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5640 MHz [128] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5660 MHz [132] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5680 MHz [136] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5700 MHz [140] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5720 MHz [144] (22.0 dBm) (passive scanning, no IBSS, radar detection)
* 5745 MHz [149] (22.0 dBm) (passive scanning, no IBSS)
* 5765 MHz [153] (22.0 dBm) (passive scanning, no IBSS)
* 5785 MHz [157] (22.0 dBm) (passive scanning, no IBSS)
* 5805 MHz [161] (22.0 dBm) (passive scanning, no IBSS)
* 5825 MHz [165] (22.0 dBm) (passive scanning, no IBSS)
Bitrates (non-HT):
* 6.0 Mbps
* 9.0 Mbps
* 12.0 Mbps
* 18.0 Mbps
* 24.0 Mbps
* 36.0 Mbps
* 48.0 Mbps
* 54.0 Mbps
max # scan SSIDs: 20
max scan IEs length: 393 bytes
Coverage class: 0 (up to 0m)
Supported Ciphers:
* WEP40 (00-0f-ac:1)
* WEP104 (00-0f-ac:5)
* TKIP (00-0f-ac:2)
* CCMP (00-0f-ac:4)
* CMAC (00-0f-ac:6)
Available Antennas: TX 0 RX 0
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* monitor
* P2P-client
* P2P-GO
* Unknown mode (10)
software interface modes (can always be added):
* AP/VLAN
* monitor
valid interface combinations:
* #{ managed } <= 1, #{ AP, P2P-client, P2P-GO } <= 1, #{ Unknown mode (10) } <= 1,
total <= 3, #channels <= 1
Supported commands:
* new_interface
* set_interface
* new_key
* new_beacon
* new_station
* new_mpath
* set_mesh_params
* set_bss
* authenticate
* associate
* deauthenticate
* disassociate
* join_ibss
* join_mesh
* remain_on_channel
* set_tx_bitrate_mask
* action
* frame_wait_cancel
* set_wiphy_netns
* set_channel
* set_wds_peer
* Unknown command (84)
* Unknown command (87)
* Unknown command (85)
* Unknown command (89)
* Unknown command (92)
* connect
* disconnect
Supported TX frame types:
* IBSS: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
* managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
* AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
* AP/VLAN: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
* mesh point: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
* P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
* P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
* Unknown mode (10): 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
Supported RX frame types:
* IBSS: 0x40 0xb0 0xc0 0xd0
* managed: 0x40 0xd0
* AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
* AP/VLAN: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
* mesh point: 0xb0 0xc0 0xd0
* P2P-client: 0x40 0xd0
* P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
* Unknown mode (10): 0x40 0xd0
Device supports RSN-IBSS.
WoWLAN support:
* wake up on disconnect
* wake up on magic packet
* wake up on pattern match, up to 20 patterns of 16-128 bytes
* can do GTK rekeying
* wake up on GTK rekey failure
* wake up on EAP identity request
* wake up on 4-way handshake
* wake up on rfkill release
HT Capability overrides:
* MCS: ff ff ff ff ff ff ff ff ff ff
* maximum A-MSDU length
* supported channel width
* short GI for 40 MHz
* max A-MPDU length exponent
* min MPDU start spacing
Device supports TX status socket option.
Device supports HT-IBSS.
Using iwconfig to set it to "Master" mode, which I think means to set it to AP mode, results in this:
$ sudo iwconfig wlan0 mode Master
Error for wireless request "Set Mode" (8B06) :
SET failed on device wlan0 ; Invalid argument.
So, I guess it's possible that the 7260 driver does not want to work in AP mode. However, the iwlist command output shows AP mode as one of the possibilities.

(Question solved by edit. Converted to community wiki answer.)
The OP wrote:
All right, looks like happy day, I just needed to add this:
### Set your bridge name ###
bridge=br0
to the hostapd.conf file. Now I get:
$ sudo hostapd /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
Using interface wlan0 with hwaddr 80:19:34:32:20:a3 and ssid "test"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED

Related

USB audio Device to Host volume control

I'm currently working on USB headset using stm32 microcontroller. I used example code from X-CUBE-USB-AUDIO package to stream audio to\from PC. Everything seems to work fine. Now I want to modify the code to allow USB device to notify the host of volume/mute changes. According to USB audio specification 1.0 p.30, an optional Status Interrupt Endpoint can be used for this purpose. So I modified device descriptor to include that optional endpoint. Here is the original descriptor:
Information for device STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730):
Connection Information:
------------------------------
Device current bus speed: FullSpeed
Device supports USB 1.1 specification
Device supports USB 2.0 specification
Device address: 0x004B
Current configuration value: 0x01
Number of open pipes: 0
Device Descriptor:
------------------------------
0x12 bLength
0x01 bDescriptorType
0x0200 bcdUSB
0x00 bDeviceClass
0x00 bDeviceSubClass
0x00 bDeviceProtocol
0x40 bMaxPacketSize0 (64 bytes)
0x0483 idVendor
0x5730 idProduct
0x0200 bcdDevice
0x01 iManufacturer "STMicroelectronics"
0x02 iProduct "STM32 AUDIO Streaming in FS Mode"
0x03 iSerialNumber "368932633438"
0x01 bNumConfigurations
Configuration Descriptor:
------------------------------
0x09 bLength
0x02 bDescriptorType
0x00CB wTotalLength (203 bytes)
0x03 bNumInterfaces
0x01 bConfigurationValue
0x00 iConfiguration
0xC0 bmAttributes (Self-powered Device)
0x32 bMaxPower (100 mA)
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x00 bInterfaceNumber
0x00 bAlternateSetting
0x00 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x01 bInterfaceSubClass (Audio Control Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
AC Interface Header Descriptor:
------------------------------
0x0A bLength
0x24 bDescriptorType
0x01 bDescriptorSubtype
0x0100 bcdADC
0x0048 wTotalLength (72 bytes)
0x02 bInCollection
0x01 baInterfaceNr(1)
0x02 baInterfaceNr(2)
AC Input Terminal Descriptor:
------------------------------
0x0C bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x12 bTerminalID
0x0101 wTerminalType (USB Streaming)
0x00 bAssocTerminal
0x02 bNrChannels (2 channels)
0x0003 wChannelConfig
0x00 iChannelNames
0x00 iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A bLength
0x24 bDescriptorType
0x06 bDescriptorSubtype
0x16 bUnitID
0x12 bSourceID
0x01 bControlSize
bmaControls:
0x03 Channel(0) - Mute / Volume
0x00 Channel(1)
0x00 Channel(2)
0x00 iFeature
AC Output Terminal Descriptor:
------------------------------
0x09 bLength
0x24 bDescriptorType
0x03 bDescriptorSubtype
0x14 bTerminalID
0x0301 wTerminalType (Speaker)
0x00 bAssocTerminal
0x16 bSourceID
0x00 iTerminal
AC Input Terminal Descriptor:
------------------------------
0x0C bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x11 bTerminalID
0x0201 wTerminalType (Microphone)
0x00 bAssocTerminal
0x02 bNrChannels (2 channels)
0x0003 wChannelConfig
0x00 iChannelNames
0x00 iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A bLength
0x24 bDescriptorType
0x06 bDescriptorSubtype
0x15 bUnitID
0x11 bSourceID
0x01 bControlSize
bmaControls:
0x03 Channel(0) - Mute / Volume
0x00 Channel(1)
0x00 Channel(2)
0x00 iFeature
AC Output Terminal Descriptor:
------------------------------
0x09 bLength
0x24 bDescriptorType
0x03 bDescriptorSubtype
0x13 bTerminalID
0x0101 wTerminalType (USB Streaming)
0x00 bAssocTerminal
0x15 bSourceID
0x00 iTerminal
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x01 bInterfaceNumber
0x00 bAlternateSetting
0x00 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x01 bInterfaceNumber
0x01 bAlternateSetting
0x02 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
AS Interface Descriptor:
------------------------------
0x07 bLength
0x24 bDescriptorType
0x01 bDescriptorSubtype
0x12 bTerminalLink
0x01 bDelay
0x0001 wFormatTag (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x01 bFormatType (FORMAT_TYPE_1)
0x02 bNrChannels (2 channels)
0x02 bSubframeSize
0x10 bBitResolution (16 bits per sample)
0x01 bSamFreqType (Discrete sampling frequencies)
0x00BB80 tSamFreq(1) (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09 bLength
0x05 bDescriptorType
0x01 bEndpointAddress (OUT endpoint 1)
0x05 bmAttributes (Transfer: Isochronous / Synch: Asynchronous / Usage: Data)
0x00C4 wMaxPacketSize (1 x 196 bytes)
0x01 bInterval (1 frames)
0x00 bRefresh
0x81 bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07 bLength
0x25 bDescriptorType
0x01 bDescriptorSubtype
0x00 bmAttributes
0x00 bLockDelayUnits (undefined)
0x0000 wLockDelay
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09 bLength
0x05 bDescriptorType
0x81 bEndpointAddress (IN endpoint 1)
0x01 bmAttributes (Transfer: Isochronous / Synch: None / Usage: Data)
0x0003 wMaxPacketSize (1 x 3 bytes)
0x01 bInterval (1 frames)
0x07 bRefresh
0x00 bSynchAddress
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x02 bInterfaceNumber
0x00 bAlternateSetting
0x00 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x02 bInterfaceNumber
0x01 bAlternateSetting
0x01 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
AS Interface Descriptor:
------------------------------
0x07 bLength
0x24 bDescriptorType
0x01 bDescriptorSubtype
0x13 bTerminalLink
0x01 bDelay
0x0001 wFormatTag (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x01 bFormatType (FORMAT_TYPE_1)
0x02 bNrChannels (2 channels)
0x02 bSubframeSize
0x10 bBitResolution (16 bits per sample)
0x01 bSamFreqType (Discrete sampling frequencies)
0x00BB80 tSamFreq(1) (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09 bLength
0x05 bDescriptorType
0x82 bEndpointAddress (IN endpoint 2)
0x01 bmAttributes (Transfer: Isochronous / Synch: None / Usage: Data)
0x00C0 wMaxPacketSize (1 x 192 bytes)
0x01 bInterval (1 frames)
0x00 bRefresh
0x00 bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07 bLength
0x25 bDescriptorType
0x01 bDescriptorSubtype
0x00 bmAttributes
0x00 bLockDelayUnits (undefined)
0x0000 wLockDelay
Microsoft OS Descriptor is not available. Error code: 0x0000001F
String Descriptor Table
--------------------------------
Index LANGID String
0x00 0x0000 0x0409
0x01 0x0409 "STMicroelectronics"
0x02 0x0409 "STM32 AUDIO Streaming in FS Mode"
0x03 0x0409 "368932633438"
------------------------------
Connection path for device:
USB xHCI Compliant Host Controller
Root Hub
STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730) Port: 5
Running on: Windows 10 or greater (Build Version 19043)
Brought to you by TDD v2.15.0, Jun 8 2020, 17:18:07
And here is the modified descriptor:
Information for device STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730):
Connection Information:
------------------------------
Device current bus speed: FullSpeed
Device supports USB 1.1 specification
Device supports USB 2.0 specification
Device address: 0x001B
Current configuration value: 0x01
Number of open pipes: 1
Device Descriptor:
------------------------------
0x12 bLength
0x01 bDescriptorType
0x0200 bcdUSB
0x00 bDeviceClass
0x00 bDeviceSubClass
0x00 bDeviceProtocol
0x40 bMaxPacketSize0 (64 bytes)
0x0483 idVendor
0x5730 idProduct
0x0200 bcdDevice
0x01 iManufacturer "STMicroelectronics"
0x02 iProduct "STM32 AUDIO Streaming in FS Mode"
0x03 iSerialNumber "368932633438"
0x01 bNumConfigurations
Configuration Descriptor:
------------------------------
0x09 bLength
0x02 bDescriptorType
0x00D4 wTotalLength (212 bytes)
0x03 bNumInterfaces
0x01 bConfigurationValue
0x00 iConfiguration
0xC0 bmAttributes (Self-powered Device)
0x32 bMaxPower (100 mA)
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x00 bInterfaceNumber
0x00 bAlternateSetting
0x01 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x01 bInterfaceSubClass (Audio Control Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
AC Interface Header Descriptor:
------------------------------
0x0A bLength
0x24 bDescriptorType
0x01 bDescriptorSubtype
0x0100 bcdADC
0x0048 wTotalLength (72 bytes)
0x02 bInCollection
0x01 baInterfaceNr(1)
0x02 baInterfaceNr(2)
AC Input Terminal Descriptor:
------------------------------
0x0C bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x12 bTerminalID
0x0101 wTerminalType (USB Streaming)
0x00 bAssocTerminal
0x02 bNrChannels (2 channels)
0x0003 wChannelConfig
0x00 iChannelNames
0x00 iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A bLength
0x24 bDescriptorType
0x06 bDescriptorSubtype
0x16 bUnitID
0x12 bSourceID
0x01 bControlSize
bmaControls:
0x03 Channel(0) - Mute / Volume
0x00 Channel(1)
0x00 Channel(2)
0x00 iFeature
AC Output Terminal Descriptor:
------------------------------
0x09 bLength
0x24 bDescriptorType
0x03 bDescriptorSubtype
0x14 bTerminalID
0x0301 wTerminalType (Speaker)
0x00 bAssocTerminal
0x16 bSourceID
0x00 iTerminal
AC Input Terminal Descriptor:
------------------------------
0x0C bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x11 bTerminalID
0x0201 wTerminalType (Microphone)
0x00 bAssocTerminal
0x02 bNrChannels (2 channels)
0x0003 wChannelConfig
0x00 iChannelNames
0x00 iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A bLength
0x24 bDescriptorType
0x06 bDescriptorSubtype
0x15 bUnitID
0x11 bSourceID
0x01 bControlSize
bmaControls:
0x03 Channel(0) - Mute / Volume
0x00 Channel(1)
0x00 Channel(2)
0x00 iFeature
AC Output Terminal Descriptor:
------------------------------
0x09 bLength
0x24 bDescriptorType
0x03 bDescriptorSubtype
0x13 bTerminalID
0x0101 wTerminalType (USB Streaming)
0x00 bAssocTerminal
0x15 bSourceID
0x00 iTerminal
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09 bLength
0x05 bDescriptorType
0x83 bEndpointAddress (IN endpoint 3)
0x03 bmAttributes (Transfer: Interrupt / Synch: None / Usage: Data)
0x0002 wMaxPacketSize (1 x 2 bytes)
0x0A bInterval (10 frames)
0x00 bRefresh
0x00 bSynchAddress
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x01 bInterfaceNumber
0x00 bAlternateSetting
0x00 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x01 bInterfaceNumber
0x01 bAlternateSetting
0x02 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
AS Interface Descriptor:
------------------------------
0x07 bLength
0x24 bDescriptorType
0x01 bDescriptorSubtype
0x12 bTerminalLink
0x01 bDelay
0x0001 wFormatTag (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x01 bFormatType (FORMAT_TYPE_1)
0x02 bNrChannels (2 channels)
0x02 bSubframeSize
0x10 bBitResolution (16 bits per sample)
0x01 bSamFreqType (Discrete sampling frequencies)
0x00BB80 tSamFreq(1) (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09 bLength
0x05 bDescriptorType
0x01 bEndpointAddress (OUT endpoint 1)
0x05 bmAttributes (Transfer: Isochronous / Synch: Asynchronous / Usage: Data)
0x00C4 wMaxPacketSize (1 x 196 bytes)
0x01 bInterval (1 frames)
0x00 bRefresh
0x81 bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07 bLength
0x25 bDescriptorType
0x01 bDescriptorSubtype
0x00 bmAttributes
0x00 bLockDelayUnits (undefined)
0x0000 wLockDelay
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09 bLength
0x05 bDescriptorType
0x81 bEndpointAddress (IN endpoint 1)
0x01 bmAttributes (Transfer: Isochronous / Synch: None / Usage: Data)
0x0003 wMaxPacketSize (1 x 3 bytes)
0x01 bInterval (1 frames)
0x07 bRefresh
0x00 bSynchAddress
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x02 bInterfaceNumber
0x00 bAlternateSetting
0x00 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x02 bInterfaceNumber
0x01 bAlternateSetting
0x01 bNumEndPoints
0x01 bInterfaceClass (Audio Device Class)
0x02 bInterfaceSubClass (Audio Streaming Interface)
0x00 bInterfaceProtocol (Audio Protocol undefined)
0x00 iInterface
AS Interface Descriptor:
------------------------------
0x07 bLength
0x24 bDescriptorType
0x01 bDescriptorSubtype
0x13 bTerminalLink
0x01 bDelay
0x0001 wFormatTag (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B bLength
0x24 bDescriptorType
0x02 bDescriptorSubtype
0x01 bFormatType (FORMAT_TYPE_1)
0x02 bNrChannels (2 channels)
0x02 bSubframeSize
0x10 bBitResolution (16 bits per sample)
0x01 bSamFreqType (Discrete sampling frequencies)
0x00BB80 tSamFreq(1) (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09 bLength
0x05 bDescriptorType
0x82 bEndpointAddress (IN endpoint 2)
0x01 bmAttributes (Transfer: Isochronous / Synch: None / Usage: Data)
0x00C0 wMaxPacketSize (1 x 192 bytes)
0x01 bInterval (1 frames)
0x00 bRefresh
0x00 bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07 bLength
0x25 bDescriptorType
0x01 bDescriptorSubtype
0x00 bmAttributes
0x00 bLockDelayUnits (undefined)
0x0000 wLockDelay
Microsoft OS Descriptor is not available. Error code: 0x0000001F
String Descriptor Table
--------------------------------
Index LANGID String
0x00 0x0000 0x0409
0x01 0x0409 "STMicroelectronics"
0x02 0x0409 "STM32 AUDIO Streaming in FS Mode"
0x03 0x0409 "368932633438"
------------------------------
Connection path for device:
USB xHCI Compliant Host Controller
Root Hub
STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730) Port: 5
Running on: Windows 10 or greater (Build Version 19043)
Brought to you by TDD v2.15.0, Jun 8 2020, 17:18:07
The changes I've made are:
Add AC Interrupt endpoint descriptor.
Change wTotalLength in Configuration Descriptor.
Change bNumEndPoints in AC Interface descriptor from 0 to 1.
USB device seems to enumerate fine and there is audio, however when looking at the output of Beagle USB logic analyzer, I don't see any data being requested by the host from the interrupt endpoint. So my question is, is there something wrong with the way I modified the descriptors or is it something else? Has anyone managed to get the Status Interrupt Endpoint working properly for USB audio devices?
Running on: Windows 10 or greater (Build Version 19043)
Windows doesn't handle this interrupt in my experience. Try it on Linux or MacOS.

How to access USB device data using pyusb?

I am trying to stream data from a USB sensor-type device. I have tried the following code:
import usb.core
device = usb.find(idVendor=0x1234, idProduct=0x4321)
print(device.read(0x81, 7))
The output I get is:
array('B', [1, 96])
I'm really unsure how to use this and get meaningful sensor data. Could anyone point me in the right direction?
For info, here's the output I get when I run print(device):
DEVICE ID 1234:4321 on Bus 001 Address 013 =================
bLength : 0x12 (18 bytes)
bDescriptorType : 0x1 Device
bcdUSB : 0x200 USB 2.0
bDeviceClass : 0x0 Specified at interface
bDeviceSubClass : 0x0
bDeviceProtocol : 0x0
bMaxPacketSize0 : 0x8 (8 bytes)
idVendor : 0x0403
idProduct : 0xc2b0
bcdDevice : 0x1000 Device 16.0
iManufacturer : 0x1 XXXXXXXXXXXX
iProduct : 0x2 XXXX
iSerialNumber : 0x0
bNumConfigurations : 0x1
CONFIGURATION 1: 500 mA ==================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x2 Configuration
wTotalLength : 0x20 (32 bytes)
bNumInterfaces : 0x1
bConfigurationValue : 0x1
iConfiguration : 0x0
bmAttributes : 0x80 Bus Powered
bMaxPower : 0xfa (500 mA)
INTERFACE 0: Vendor Specific ===========================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x2
bInterfaceClass : 0xff Vendor Specific
bInterfaceSubClass : 0xff
bInterfaceProtocol : 0xff
iInterface : 0x2 XXXX
ENDPOINT 0x81: Bulk IN ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0x0
ENDPOINT 0x2: Bulk OUT ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x2 OUT
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0x0

Raspberry BLE Encryption / Pairing

I'm trying to use my Raspberry Pi 3B to communicate with a BLE enabled device which dosen't require a PIN.
I first tried with Ionic on iOS using cordova BLE central (https://github.com/don/cordova-plugin-ble-central), which worked as expected, here is the exchanged packets :
iOS (PacketLogger)
May 21 07:59:36.825 Note 0x0000 Product: iPhone9,3
May 21 07:59:36.825 Note 0x0000 Software: Version 13.4 (Build 17E255)
May 21 08:09:42.178 Config 0x0041 315X Connected: C4:64:E3:9B:04:44 - Handle: 0x41 - 315X - C7D0F30E-78B4-C82C-6912-DD0F5A5BCA2E
May 21 08:09:43.690 HCI Command 0x0041 00:00:00:00:00:00 Disconnect - Connection Handle: 0x0041 - Reason: Remote User Terminated Connection
May 21 08:09:43.690 Power 0x0000 H4 wake
May 21 08:09:43.690 HCI Event 0x0000 Command Status - Disconnect
May 21 08:09:43.705 LMP Sent 0x0041 00:00:00:00:00:00 LE Terminate Indicator - Error: 0x13
May 21 08:09:43.706 HCI Event 0x0041 00:00:00:00:00:00 Disconnection Complete - Success
May 21 08:09:43.710 Config 0x0000 (
May 21 08:09:43.710 Config 0x0000 Invalid packet
May 21 08:09:43.710 Config 0x0000 (
May 21 08:09:43.710 Config 0x0000 Invalid packet
May 21 08:09:43.710 Config 0x0000 Invalid packet
May 21 08:09:43.710 Config 0x0000 Invalid packet
May 21 08:09:43.891 Power 0x0000 H4 sleep
May 21 08:09:47.801 HCI Command 0x0000 LE Set Scan Enable - 0x00, Filter Duplicates: 1
May 21 08:09:47.801 Power 0x0000 H4 wake
May 21 08:09:47.803 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
May 21 08:09:47.803 HCI Command 0x0000 Vendor Specific Command
May 21 08:09:47.804 HCI Event 0x0000 Command Complete [FCE9] -
May 21 08:09:47.804 HCI Command 0x0000 Vendor Specific Command
May 21 08:09:47.804 HCI Event 0x0000 Command Complete [FCE9] -
May 21 08:09:47.804 HCI Command 0x0000 Vendor Specific Command
May 21 08:09:47.804 HCI Event 0x0000 Command Complete [FCE9] -
May 21 08:09:47.804 HCI Command 0x0000 Vendor Specific Command
May 21 08:09:47.805 HCI Event 0x0000 Command Complete [FCE9] -
May 21 08:09:47.805 HCI Command 0x0000 LE Set Scan Parameters - Active - 30/40 (ms)
May 21 08:09:47.805 HCI Event 0x0000 Command Complete [200B] - LE Set Scan Parameters
May 21 08:09:47.805 HCI Command 0x0000 LE Set Scan Enable - 0x01, Filter Duplicates: 1
May 21 08:09:47.805 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
May 21 08:09:47.808 HCI Event 0x0000 315X LE - Advertising Report - 1 Report - Normal - Public - C4:64:E3:9B:04:44 -59 dBm - Channel 37
May 21 08:09:47.809 HCI Event 0x0000 315X LE - Advertising Report - 1 Report - Normal - Public - C4:64:E3:9B:04:44 -60 dBm - Manufacturer Specific Data - 315X - Channel 37
May 21 08:09:48.006 Power 0x0000 H4 sleep
May 21 08:09:48.636 HCI Command 0x0000 315X LE Add Device To White List - Public - C4:64:E3:9B:04:44
May 21 08:09:48.636 Power 0x0000 H4 wake
May 21 08:09:48.636 HCI Event 0x0000 Command Complete [2011] - LE Add Device To White List
May 21 08:09:48.643 HCI Command 0x0000 LE Create Connection - 00:00:00:00:00:00, Scan Window/Interval: 30ms/30ms, Min/Max Conn Interval: 10ms/30ms
May 21 08:09:48.647 HCI Event 0x0000 Command Status - LE Create Connection
May 21 08:09:48.701 HCI Event 0x0000 315X LE - Advertising Report - 1 Report - Normal - Public - C4:64:E3:9B:04:44 -57 dBm - Channel 38/37
May 21 08:09:48.702 HCI Event 0x0041 315X LE - Enhanced Connection Complete - Master - Public - C4:64:E3:9B:04:44 local - 00:00:00:00:00:00 peer - 00:00:00:00:00:00 - Conn Interval: 30 ms
May 21 08:09:48.704 HCI Command 0x0000 315X LE Remove Device From White List - 0 - C4:64:E3:9B:04:44
May 21 08:09:48.704 HCI Event 0x0000 Command Complete [2012] - LE Remove Device From White List
May 21 08:09:48.704 HCI Command 0x0000 Vendor Specific Command
May 21 08:09:48.704 HCI Event 0x0000 Command Complete [FDC1] -
May 21 08:09:48.706 HCI Command 0x0041 315X LE Start Encryption - Connection Handle: 0x0041
May 21 08:09:48.706 HCI Event 0x0000 Command Status - LE Start Encryption
May 21 08:09:48.712 LMP Sent 0x0041 315X LE Version Indicator
May 21 08:09:48.741 LMP Received 0x0041 315X LE Version Indicator
May 21 08:09:48.772 LMP Sent 0x0041 315X LE Encryption Request
May 21 08:09:48.801 LMP Received 0x0041 315X LE Encryption Response
May 21 08:09:48.861 LMP Received 0x0041 315X LE Start Encryption Request
May 21 08:09:48.891 LMP Sent 0x0041 315X LE Start Encryption Response
May 21 08:09:48.922 HCI Event 0x0041 315X Encryption Change Complete - Encryption Enabled
May 21 08:09:48.922 HCI Command 0x0041 315X Read Remote Version Information - Connection Handle: 0x0041
May 21 08:09:48.922 LMP Received 0x0041 315X LE Start Encryption Response
May 21 08:09:48.922 HCI Event 0x0000 Command Status - Read Remote Version Information
May 21 08:09:48.922 HCI Event 0x0041 315X Read Remote Version Information Complete
May 21 08:09:48.922 HCI Command 0x0041 315X LE Read Remote Used Features - Connection Handle: 0x0041
May 21 08:09:48.922 HCI Event 0x0000 Command Status - LE Read Remote Used Features
May 21 08:09:48.923 HCI Command 0x0000 Vendor Specific Command
May 21 08:09:48.923 HCI Event 0x0000 Command Complete [FD82] -
May 21 08:09:48.952 LMP Sent 0x0041 315X LE Feature Request - Feature Set: 0x00000000000000FD
May 21 08:09:48.982 HCI Event 0x0041 315X LE - Read Remote Used Features Complete - DPLE Supported
May 21 08:09:48.982 LMP Received 0x0041 315X LE Feature Response - Feature Set: 0x00000000000000FD
May 21 08:09:49.012 LMP Sent 0x0041 315X LE Length Request
May 21 08:09:49.042 HCI Event 0x0041 315X LE - Data Length Change
May 21 08:09:49.042 LMP Received 0x0041 315X LE Length Response
May 21 08:09:49.044 ATT Send 0x0041 315X Exchange MTU Request - MTU: 185
May 21 08:09:49.101 ATT Receive 0x0041 315X Exchange MTU Response - MTU: 65
May 21 08:09:49.102 Config 0x0000 A(
May 21 08:09:49.102 Config 0x0000 Invalid packet
May 21 08:09:49.102 Config 0x0000 A(
May 21 08:09:49.102 Config 0x0000 Invalid packet
May 21 08:09:49.102 Config 0x0000 Invalid packet
May 21 08:09:49.102 Config 0x0000 Invalid packet
May 21 08:09:49.102 ATT Send 0x0041 315X Read By Type Request - Start Handle: 0x0008 - End Handle: 0x0008 - UUID: GATT Characteristic Declaration
May 21 08:09:49.130 HCI Event 0x0041 315X Number Of Completed Packets - Handle: 0x0041 - Packets: 0x0002
May 21 08:09:49.161 ATT Receive 0x0041 315X Error Response - Attribute Handle: 0x0008 - Error Code: Attribute Not Found (0x0A)
May 21 08:09:49.162 Config 0x0000 Invalid packet
May 21 08:09:49.162 Config 0x0000 Invalid packet
May 21 08:09:49.162 Config 0x0000 Invalid packet
May 21 08:09:49.162 Config 0x0000 Invalid packet
May 21 08:09:49.165 Config 0x0000 Invalid packet
May 21 08:09:49.165 Config 0x0000 Invalid packet
May 21 08:09:49.165 Config 0x0000 Invalid packet
May 21 08:09:49.165 Config 0x0000 Invalid packet
May 21 08:09:49.165 Config 0x0000 Invalid packet
May 21 08:09:49.165 Config 0x0000 Invalid packet
May 21 08:09:49.169 ATT Send 0x0041 315X Read Request - Handle:0x0012
May 21 08:09:49.222 ATT Receive 0x0041 315X Read Response - Value: 4175 746F 6D6F 7765 7200 0000 0000 0000 …
May 21 08:09:49.224 ATT Send 0x0041 315X Write Request - Handle:0x000F - Value: 0100
May 21 08:09:49.250 HCI Event 0x0041 315X Number Of Completed Packets - Handle: 0x0041 - Packets: 0x0002
May 21 08:09:49.281 ATT Receive 0x0041 315X Write Response
For raspberry I'm using noble (https://github.com/abandonware/noble), I'm able to discover device and read characteristics but look like the write commands dosen't work as expected.
hcidump
pi#raspberrypi:~ $ sudo hcidump -t -x
HCI sniffer - Bluetooth packet analyzer ver 5.50
device: hci0 snap_len: 1500 filter: 0xffffffff
2020-06-02 08:49:48.643635 < HCI Command: Set Event Mask (0x03|0x0001) plen 8
Mask: 0xfffffbff07f8bf3d
2020-06-02 08:49:48.644192 > HCI Event: Command Complete (0x0e) plen 4
Set Event Mask (0x03|0x0001) ncmd 1
status 0x00
2020-06-02 08:49:48.644641 < HCI Command: LE Set Event Mask (0x08|0x0001) plen 8
mask 0x1f00000000000000 (Reserved)
2020-06-02 08:49:48.645116 > HCI Event: Command Complete (0x0e) plen 4
LE Set Event Mask (0x08|0x0001) ncmd 1
status 0x00
2020-06-02 08:49:48.645147 < HCI Command: Read Local Version Information (0x04|0x0001) plen 0
2020-06-02 08:49:48.645641 > HCI Event: Command Complete (0x0e) plen 12
Read Local Version Information (0x04|0x0001) ncmd 1
status 0x00
HCI Version: 4.1 (0x7) HCI Revision: 0x1ed
LMP Version: 4.1 (0x7) LMP Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
2020-06-02 08:49:48.645672 < HCI Command: Write LE Host Supported (0x03|0x006d) plen 2
01 00
2020-06-02 08:49:48.646081 > HCI Event: Command Complete (0x0e) plen 4
Write LE Host Supported (0x03|0x006d) ncmd 1
00
2020-06-02 08:49:48.646264 < HCI Command: Read LE Host Supported (0x03|0x006c) plen 0
2020-06-02 08:49:48.646731 > HCI Event: Command Complete (0x0e) plen 6
Read LE Host Supported (0x03|0x006c) ncmd 1
00 01 00
2020-06-02 08:49:48.646767 < HCI Command: Read BD ADDR (0x04|0x0009) plen 0
2020-06-02 08:49:48.647206 > HCI Event: Command Complete (0x0e) plen 10
Read BD ADDR (0x04|0x0009) ncmd 1
status 0x00 bdaddr B8:27:EB:08:5F:F0
2020-06-02 08:49:48.654744 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
value 0x00 (scanning disabled)
filter duplicates 0x01 (enabled)
2020-06-02 08:49:48.655164 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 1
status 0x0c
Error: Command Disallowed
2020-06-02 08:49:48.655465 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
type 0x01 (active)
interval 10.000ms window 10.000ms
own address: 0x00 (Public) policy: All
2020-06-02 08:49:48.655928 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Parameters (0x08|0x000b) ncmd 1
status 0x00
2020-06-02 08:49:48.669824 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
value 0x00 (scanning disabled)
filter duplicates 0x01 (enabled)
2020-06-02 08:49:48.670225 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 1
status 0x0c
Error: Command Disallowed
2020-06-02 08:49:48.670261 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
type 0x01 (active)
interval 10.000ms window 10.000ms
own address: 0x00 (Public) policy: All
2020-06-02 08:49:48.670716 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Parameters (0x08|0x000b) ncmd 1
status 0x00
2020-06-02 08:49:48.670754 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
value 0x01 (scanning enabled)
filter duplicates 0x01 (enabled)
2020-06-02 08:49:48.671215 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 1
status 0x00
2020-06-02 08:49:48.842103 > HCI Event: LE Meta Event (0x3e) plen 27
LE Advertising Report
ADV_IND - Connectable undirected advertising (0)
bdaddr 9C:20:7B:BE:14:6E (Public)
Flags: 0x1a
Unknown type 0xff with 10 bytes data
RSSI: -68
2020-06-02 08:49:48.842525 > HCI Event: LE Meta Event (0x3e) plen 12
LE Advertising Report
SCAN_RSP - Scan Response (4)
bdaddr 9C:20:7B:BE:14:6E (Public)
RSSI: -68
2020-06-02 08:49:49.384917 > HCI Event: LE Meta Event (0x3e) plen 33
LE Advertising Report
ADV_IND - Connectable undirected advertising (0)
bdaddr C4:64:E3:9B:04:44 (Public)
Flags: 0x06
Unknown type 0x06 with 16 bytes data
RSSI: -95
2020-06-02 08:49:49.385781 > HCI Event: LE Meta Event (0x3e) plen 28
LE Advertising Report
SCAN_RSP - Scan Response (4)
bdaddr C4:64:E3:9B:04:44 (Public)
Unknown type 0xff with 8 bytes data
Shortened local name: '315X'
RSSI: -95
2020-06-02 08:49:49.392478 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
value 0x00 (scanning disabled)
filter duplicates 0x01 (enabled)
2020-06-02 08:49:49.394279 > HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 1
status 0x00
2020-06-02 08:49:49.399822 < HCI Command: LE Create Connection (0x08|0x000d) plen 25
bdaddr C4:64:E3:9B:04:44 type 0
interval 96 window 48 initiator_filter 0
own_bdaddr_type 0 min_interval 6 max_interval 12
latency 0 supervision_to 200 min_ce 4 max_ce 6
2020-06-02 08:49:49.400717 > HCI Event: Command Status (0x0f) plen 4
LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
2020-06-02 08:49:59.914436 > HCI Event: LE Meta Event (0x3e) plen 19
LE Connection Complete
status 0x00 handle 64, role master
bdaddr C4:64:E3:9B:04:44 (Public)
2020-06-02 08:49:59.914783 < HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2
40 00
2020-06-02 08:49:59.915700 > HCI Event: Command Status (0x0f) plen 4
LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1
2020-06-02 08:50:00.205123 > HCI Event: LE Meta Event (0x3e) plen 12
LE Read Remote Used Features Complete
status 0x00 handle 64
Features: 0x1d 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2020-06-02 08:50:00.211514 < ACL data: handle 64 flags 0x00 dlen 7
ATT: MTU req (0x02)
client rx mtu 256
2020-06-02 08:50:00.249993 > ACL data: handle 64 flags 0x02 dlen 7
ATT: MTU resp (0x03)
server rx mtu 65
2020-06-02 08:50:00.252698 < ACL data: handle 64 flags 0x00 dlen 11
ATT: Read By Group req (0x10)
start 0x0001, end 0xffff
type-uuid 0x2800
2020-06-02 08:50:00.295009 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 2
2020-06-02 08:50:00.385200 > ACL data: handle 64 flags 0x02 dlen 18
ATT: Read By Group resp (0x11)
attr handle 0x0001, end group handle 0x0007
value 0x00 0x18
attr handle 0x0008, end group handle 0x0008
value 0x01 0x18
2020-06-02 08:50:00.386993 < ACL data: handle 64 flags 0x00 dlen 11
ATT: Read By Group req (0x10)
start 0x0009, end 0xffff
type-uuid 0x2800
2020-06-02 08:50:00.460829 > ACL data: handle 64 flags 0x02 dlen 26
ATT: Read By Group resp (0x11)
attr handle 0x0009, end group handle 0xffff
value 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x01 0x00 0xbd 0x98
2020-06-02 08:50:00.464756 < ACL data: handle 64 flags 0x00 dlen 11
ATT: Read By Type req (0x08)
start 0x0009, end 0xffff
type-uuid 0x2803
2020-06-02 08:50:00.490056 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 2
2020-06-02 08:50:00.520226 > ACL data: handle 64 flags 0x02 dlen 27
2020-06-02 08:50:00.535226 > ACL data: handle 64 flags 0x01 dlen 27
2020-06-02 08:50:00.580143 > ACL data: handle 64 flags 0x01 dlen 15
ATT: Read By Type resp (0x09)
length: 21
handle 0x000a, value 0x04 0x0b 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x02 0x00 0xbd 0x98
handle 0x000d, value 0x12 0x0e 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x03 0x00 0xbd 0x98
handle 0x0011, value 0x02 0x12 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x04 0x00 0xbd 0x98
2020-06-02 08:50:00.582577 < ACL data: handle 64 flags 0x00 dlen 11
ATT: Read By Type req (0x08)
start 0x0013, end 0xffff
type-uuid 0x2803
2020-06-02 08:50:00.730061 > ACL data: handle 64 flags 0x02 dlen 9
ATT: Error (0x01)
Error: Attribute not found (10)
Read By Type req (0x08) on handle 0x0013
2020-06-02 08:50:00.737443 < ACL data: handle 64 flags 0x00 dlen 7
ATT: Read req (0x0a)
handle 0x0012
2020-06-02 08:50:00.759998 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 2
2020-06-02 08:50:00.760889 > ACL data: handle 64 flags 0x02 dlen 25
ATT: Read resp (0x0b)
41 75 74 6F 6D 6F 77 65 72 00 00 00 00 00 00 00 00 00 00 00
2020-06-02 08:50:00.823478 < ACL data: handle 64 flags 0x00 dlen 32
ATT: Write cmd (0x52)
handle 0x000b value 0x02 0xfd 0x01 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x2e 0x01 0x49 0x01 0x1f 0x8f 0x07 0x50 0x00 0x00 0x00 0x00 0x04 0x0d
2020-06-02 08:50:00.828900 < ACL data: handle 64 flags 0x00 dlen 14
ATT: Write cmd (0x52)
handle 0x000b value 0x61 0x69 0x06 0xe0 0x00 0xf0 0x03
2020-06-02 08:50:00.940081 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 2
2020-06-02 08:50:01.294462 < ACL data: handle 64 flags 0x00 dlen 24
ATT: Write cmd (0x52)
handle 0x000b value 0x02 0xfd 0x00 0xa0 0x00 0x91 0x1f 0x08 0xf7 0x05 0x00 0x7c 0x00 0x80 0x01 0x28 0x03
2020-06-02 08:50:01.562877 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 1
2020-06-02 08:50:01.774077 < ACL data: handle 64 flags 0x00 dlen 32
ATT: Write cmd (0x52)
handle 0x000b value 0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0x5a 0x12 0x00 0x20 0x00 0x00 0x00 0x02 0x30 0x03
2020-06-02 08:50:01.937876 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 1
2020-06-02 08:50:02.281245 < ACL data: handle 64 flags 0x00 dlen 32
ATT: Write cmd (0x52)
handle 0x000b value 0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0x38 0x12 0x00 0x20 0x00 0x00 0x00 0x08 0xe0 0x03
2020-06-02 08:50:02.562878 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 1
2020-06-02 08:50:02.773394 < ACL data: handle 64 flags 0x00 dlen 32
ATT: Write cmd (0x52)
handle 0x000b value 0x02 0xfd 0x01 0x20 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x28 0x00 0x0a 0x0f 0x38 0x12 0x00 0x40 0x00 0x02 0x00 0x0d 0x20 0x04
2020-06-02 08:50:02.776651 < ACL data: handle 64 flags 0x00 dlen 9
ATT: Write cmd (0x52)
handle 0x000b value 0xee 0x03
2020-06-02 08:50:02.876322 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 2
2020-06-02 08:50:03.284576 < ACL data: handle 64 flags 0x00 dlen 32
ATT: Write cmd (0x52)
handle 0x000b value 0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0x38 0x12 0x00 0x30 0x00 0x00 0x00 0x00 0x10 0x03
2020-06-02 08:50:03.437917 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 1
2020-06-02 08:50:03.773593 < ACL data: handle 64 flags 0x00 dlen 32
ATT: Write cmd (0x52)
handle 0x000b value 0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0xea 0x11 0x00 0x50 0x00 0x00 0x00 0x0e 0xc0 0x03
2020-06-02 08:50:03.937996 > HCI Event: Number of Completed Packets (0x13) plen 5
handle 64 packets 1
I've noticed that on iOs I've an encryption process which look like triggered automatically on connect :
a May 21 08:09:48.706 HCI Command 0x0041 315X LE Start Encryption - Connection Handle: 0x0041
while on the Pi I only have a create connection :
2020-06-02 08:49:49.399822 < HCI Command: LE Create Connection (0x08|0x000d) plen 25
bdaddr C4:64:E3:9B:04:44 type 0
interval 96 window 48 initiator_filter 0
own_bdaddr_type 0 min_interval 6 max_interval 12
latency 0 supervision_to 200 min_ce 4 max_ce 6
I've tried to manually pair the BLE device using bluetoothctl but look like the pairing isn't working :
pi#raspberrypi:~ $ bluetoothctl
Agent registered
[bluetooth]# connect C4:64:E3:9B:04:44
Attempting to connect to C4:64:E3:9B:04:44
[CHG] Device C4:64:E3:9B:04:44 Connected: yes
Connection successful
[NEW] Primary Service
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0008
00001801-0000-1000-8000-00805f9b34fb
Generic Attribute Profile
[NEW] Primary Service
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009
98bd0001-0b0e-421a-84e5-ddbf75dc6de4
Vendor specific
[NEW] Characteristic
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000a
98bd0002-0b0e-421a-84e5-ddbf75dc6de4
Vendor specific
[NEW] Descriptor
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000a/desc000c
00002901-0000-1000-8000-00805f9b34fb
Characteristic User Description
[NEW] Characteristic
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000d
98bd0003-0b0e-421a-84e5-ddbf75dc6de4
Vendor specific
[NEW] Descriptor
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000d/desc000f
00002902-0000-1000-8000-00805f9b34fb
Client Characteristic Configuration
[NEW] Descriptor
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000d/desc0010
00002901-0000-1000-8000-00805f9b34fb
Characteristic User Description
[NEW] Characteristic
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char0011
98bd0004-0b0e-421a-84e5-ddbf75dc6de4
Vendor specific
[NEW] Descriptor
/org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char0011/desc0013
00002901-0000-1000-8000-00805f9b34fb
Characteristic User Description
[CHG] Device C4:64:E3:9B:04:44 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device C4:64:E3:9B:04:44 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device C4:64:E3:9B:04:44 UUIDs: 98bd0001-0b0e-421a-84e5-ddbf75dc6de4
[CHG] Device C4:64:E3:9B:04:44 ServicesResolved: yes
[315X]# pair C4:64:E3:9B:04:44
Attempting to pair with C4:64:E3:9B:04:44
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device C4:64:E3:9B:04:44 ServicesResolved: no
[CHG] Device C4:64:E3:9B:04:44 Connected: no
EDIT
Ok, it's look like the encryption process is being triggered when I try to subscribe to the notify characteristics but pairing fail :
2020-06-02 10:57:45.657381 > ACL data: handle 64 flags 0x02 dlen 9
ATT: Error (0x01)
Error: Insufficient authentication (5)
Read By Type req (0x08) on handle 0x000f
2020-06-02 10:57:45.658692 < ACL data: handle 64 flags 0x00 dlen 11
SMP: Pairing Request (0x01)
capability 0x03 oob 0x00 auth req 0x01
max key size 0x10 init key dist 0x00 resp key dist 0x01
Capability: NoInputNoOutput (OOB data not present)
Authentication: Bonding (No MITM Protection)
Initiator Key Distribution:
Responder Key Distribution: LTK
2020-06-02 10:57:45.687326 > ACL data: handle 64 flags 0x02 dlen 6
SMP: Pairing Failed (0x05)
reason 0x05
Reason Pairing Not Supported
I don't know how to solve this pairing issue
Edit 2
It look like this was a device issue which allow pairing inconsistently or is being activated via a specific gatt command, I'll dive deeper to figure out
This looks to be happening because pairing is not supported on the Raspberry Pi. You can resolve this through a combination of btmgmt and bluetoothctl commands:-
sudo btmgmt power off
sudo btmgmt discov on
sudo btmgmt connectable on
sudo btmgmt pairable on
sudo btmgmt power on
Also, according to your logs you have set the IO Capability to 0x03 (NoInputNoOutput). You can change this by launching bluetoothctl using:-
bluetoothctl --agent KeyboardDisplay
After that, you should be prompted to enter a passkey or accept incoming connection on the Raspberry Pi. You can play with all the different IO Capabilities to see which one works best for you. The commands for doing this are:-
bluetoothctl --agent DisplayOnly
bluetoothctl --agent DisplayYesNo
bluetoothctl --agent KeyboardOnly
bluetoothctl --agent NoInputNoOutput
bluetoothctl --agent KeyboardDisplay
More details can be found in the links below
BLE Pairing the Raspberry Pi 3 Model B
Configuring Bluetooth devices with bluetoothctl
How to Encrypt Data Using BLE Connection Using BlueZ
I hope this helps.
I had a similar issue. I used Raspberry Pi 4 and nRF Connect tool.
I could bond the devices and connect it. But, it failed to read encrypted gatt characteristic even after bonding. StackOverflow Link to the problem.
The root cause of the issue and the solution is given in this Github Link.
Issue:
Boot up the Pi.
Start the agent, advertisement and gatt server.
Bond the device.
Connect it.
Try to read the encrypted characteristic. It fails.
Root Cause:
After much digging, I noticed that this problem is caused by the state
the bluetooth chip is in at the time BlueZ is fired up (you can check
the state with hciconfig hci0). If it's in "UP RUNNING" state or in
"UP RUNNING PSCAN ISCAN" state, BlueZ complains with one or more of
these:
Failed to set mode: Rejected (0x0b) Failed to set mode: Rejected
(0x0b) Failed to set privacy: Rejected (0x0b)
But if it's in "DOWN" state, BlueZ starts with no issues. So, you
first have to do hciconfig hci0 down before the bluetooth service
starts up. But before you can use hciconfig, you also need to ensure
the sys-subsystem-bluetooth-devices-hci0.device service has started!
Solution 1:
I ended up disabling the automatic boot sequence, and run this script instead:
systemctl start sys-subsystem-bluetooth-devices-hci0.device; hciconfig hci0 down; systemctl start bluetooth
Solution 2:
Delaying the running of bthelper by a couple of seconds fixed this
issue for me, without me having to disable the automatic boot sequence
and run any manual commands.
I added an ExecStartPre line to /lib/systemd/system/bthelper#.service
such that the Service section now looks like this:
[Service]
Type=simple
ExecStartPre=/bin/sleep 2
ExecStart=/usr/bin/bthelper %I

read data with pyusb

I have a digital caliper and want to receave the output data via usb, with no result so far
Here is what I tried:
after reading the docs pyusb
I need to useread() function for this type of data.
so I need to find the correct endpoint address first
import usb.core
import usb.util
dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)
ENDPOINT 0x81: Bulk IN ===============================
bEndpointAddress : 0x81 IN # Endpoint in
wMaxPacketSize : 0x40 (64 bytes)
The second parameter is the data payload (write) or the number of bytes to read (read)
Im not sure but I assume its wMaxPacketSize : 0x40 (64 bytes)
for the time out argument I use the Device.default_timeout property as the operation timeout .
so I wrote a loop to wait for receaving data
import usb.core
import usb.util
dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)
while True:
ret = dev.read(0x81, 0x44 )
print(ret)
and got a raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 10060] Operation timed out
What am I missing here?
Full Device Desription
DEVICE ID 0403:6001 on Bus 001 Address 007 =================
bLength : 0x12 (18 bytes)
bDescriptorType : 0x1 Device
bcdUSB : 0x200 USB 2.0
bDeviceClass : 0x0 Specified at interface
bDeviceSubClass : 0x0
bDeviceProtocol : 0x0
bMaxPacketSize0 : 0x8 (8 bytes)
idVendor : 0x0403
idProduct : 0x6001
bcdDevice : 0x400 Device 4.0
iManufacturer : 0x1 MAHR
iProduct : 0x2 16EXu
iSerialNumber : 0x3 MAO74LCR
bNumConfigurations : 0x1
CONFIGURATION 1: 44 mA ===================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x2 Configuration
wTotalLength : 0x20 (32 bytes)
bNumInterfaces : 0x1
bConfigurationValue : 0x1
iConfiguration : 0x0
bmAttributes : 0xa0 Bus Powered, Remote Wakeup
bMaxPower : 0x16 (44 mA)
INTERFACE 0: Vendor Specific ===========================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x2
bInterfaceClass : 0xff Vendor Specific
bInterfaceSubClass : 0xff
bInterfaceProtocol : 0xff
iInterface : 0x2 16EXu
ENDPOINT 0x81: Bulk IN ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0x0
ENDPOINT 0x2: Bulk OUT ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x2 OUT
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0x0

Is device.is_kernel_driver_active() not working in libusb-1.0.22.7z?

Why am I getting the "Operation not supported or unimplemented on this platform" message?
I am running windows 10 64 bit and have installed python 3.7 64 bit, pyusb 1.0.2 and libusb-1.0.22.7z. For libusb-1.0.22.7z I unzipped it and copied the MS64\dll\libusb-1.0.dll to C:\Users..\AppData\Local\Programs\Python\Python37\ folder.
import usb
device = usb.core.find(idVendor = 0x0461, idProduct = 0x4d65) #mouse
if device is None:
raise ValueError('No device')
print(device)
interface = 0
if device.is_kernel_driver_active(interface):
print("kernel driver active")
The output is:
DEVICE ID 0461:4d65 on Bus 008 Address 002 =================
bLength : 0x12 (18 bytes)
bDescriptorType : 0x1 Device
bcdUSB : 0x200 USB 2.0
bDeviceClass : 0x0 Specified at interface
bDeviceSubClass : 0x0
bDeviceProtocol : 0x0
bMaxPacketSize0 : 0x8 (8 bytes)
idVendor : 0x0461
idProduct : 0x4d65
bcdDevice : 0x200 Device 2.0
iManufacturer : 0x0
iProduct : 0x2 USB Optical Mouse
iSerialNumber : 0x0
bNumConfigurations : 0x1
CONFIGURATION 1: 98 mA ===================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x2 Configuration
wTotalLength : 0x22 (34 bytes)
bNumInterfaces : 0x1
bConfigurationValue : 0x1
iConfiguration : 0x0
bmAttributes : 0xa0 Bus Powered, Remote Wakeup
bMaxPower : 0x31 (98 mA)
INTERFACE 0: Human Interface Device ====================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x1
bInterfaceClass : 0x3 Human Interface Device
bInterfaceSubClass : 0x1
bInterfaceProtocol : 0x2
iInterface : 0x0
ENDPOINT 0x81: Interrupt IN ==========================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x3 Interrupt
wMaxPacketSize : 0x6 (6 bytes)
bInterval : 0xa
Traceback (most recent call last):
File "c:\Users\me\Documents\Python\usb\usb test.py", line 16, in <module>
if device.is_kernel_driver_active(interface):
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\usb\core.py", line 1064, in is_kernel_driver_active
interface)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\usb\backend\libusb1.py", line 898, in is_kernel_driver_active
intf)))
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\usb\backend\libusb1.py", line 593, in _check
raise NotImplementedError(_strerror(ret))
NotImplementedError: Operation not supported or unimplemented on this platform

Resources