使用相同用户空间蓝牙库的相同 C 代码在一台 Ubuntu 22.04 笔记本电脑上工作正常,但在另一台笔记本电脑上失败

问题描述 投票:0回答:1

我有一个基于 cwiid 用户空间库的自定义库,用于 Nintendo Wiimote 连接。您可以在https://github.com/pd-l2ork/cwiid找到它。

假设您已经设置了开发环境(您将需要蓝牙和 gtk 开发库,配置将识别您可能缺少的任何其他库),您可以通过以下方式构建程序(此过程应该只需要一分钟左右):

./configure --disable-python
make
sudo cp libcwiid/libcwiid.so* /usr/lib/
wmgui/wmgui

然后尝试使用“文件”->“连接”选项连接到 Nintendo Wiimote。

测试完成后,如果您想恢复系统,只需使用 sudo 权限删除 /usr/lib/libcwiid.so* 文件即可。

sudo rm /usr/lib/libcwiid.so*

万一您在此之前已经安装了 libcwiid,您可以随时重新安装该软件包。

这个库及其演示应用程序 wmgui 在旧笔记本电脑上的 Ubuntu 20.04 中运行得很好 并且 在升级到 Ubuntu 22.04 后在这些相同的笔记本电脑上也运行得很好。现在,在较新的 Thinkpad L14 Gen4 笔记本电脑上,我遇到了一个问题:在 libcwiid/bluetooth.c 的第 84 行中未正确检测到 Nintendo Wiimote 设备:

if ((dev_count = hci_inquiry(dev_id, timeout, max_inquiry, NULL,
                             &dev_list, IREQ_CACHE_FLUSH)) == -1) {
    cwiid_err(NULL, "Bluetooth device inquiry error");
    err = 1;
    goto CODA;
}

尝试重新发现 Nintendo Wiimote 设备后,它检测到它,但随后挂起(根据 gdb 的回溯)在 libcwiid/connect.c 的第 100 行:

unsigned char handshake;
if (read(wiimote->ctl_socket, &handshake, 1) != 1) {
    cwiid_err(wiimote, "Socket read error (handshake)");
    return -1;
}

任天堂 Wiimote 通过 Ubuntu 设置小部件连接良好,并被检测为操纵杆。然而,如果在那里配对,则无法通过上述cwiid库访问它。因此,允许检测到它的唯一方法是通过“设置”->“蓝牙”选项不配对(或取消配对)。

代码在运行 Ubuntu 22.04 的两台笔记本电脑上编译得很好(在旧笔记本电脑和新笔记本电脑上都会弹出一些警告),这让我想知道较新的蓝牙硬件是否可能是导致此问题的原因。考虑到这一点,我想知道可能是什么问题。

请注意,我知道现在有其他库可以与 Nintendo Wiimotes 连接。然而,我有一个较旧的项目,十多年来一直依赖这种方法,并且正在寻求更新代码。鉴于这种神秘且不一致的行为,我不确定该去哪里寻找。

是否可以运行蓝牙库来请求旧版本的 API 功能(例如通过 C 代码内部的定义)?这可能是一个潜在的临时解决方案吗?

另一个想法是,当涉及到用户空间访问蓝牙设备时,这是否可能是某种高级安全问题?如果是,有没有办法绕过这种限制?

谢谢您的帮助。

编辑:这是我能够捕获的一些日志。

应用程序输出:

Found old version of the wiimote (Nintendo RVL-CNT-01
ERROR:ssl_client_socket_impl.cc(983) handshake failed; returned -1, SSL error code 1, net_error -100
(not sure if the 2nd line is relevant to the issue or something else threw out this error to the console.

系统日志:

Mar 19 12:17:45 Monsoon kernel: [10402.437307] Bluetooth: hci0: unexpected cc 0x041a length: 7 > 1
Mar 19 12:17:48 Monsoon kernel: [10405.931519] Bluetooth: hci0: unexpected cc 0x041a length: 7 > 1
Mar 19 12:17:48 Monsoon kernel: [10405.931535] Bluetooth: hci0: Opcode 0x041a failed: -22
...
Mar 19 14:24:58 Monsoon systemd[1]: Starting Bluetooth service...
Mar 19 14:24:58 Monsoon kernel: [    3.883602] Bluetooth: Core ver 2.22
Mar 19 14:24:58 Monsoon kernel: [    3.883630] NET: Registered PF_BLUETOOTH protocol family
Mar 19 14:24:58 Monsoon kernel: [    3.883632] Bluetooth: HCI device and connection manager initialized
Mar 19 14:24:58 Monsoon kernel: [    3.883636] Bluetooth: HCI socket layer initialized
Mar 19 14:24:58 Monsoon kernel: [    3.883639] Bluetooth: L2CAP socket layer initialized
Mar 19 14:24:58 Monsoon kernel: [    3.883644] Bluetooth: SCO socket layer initialized
...
Mar 19 14:24:58 Monsoon kernel: [    4.031959] thinkpad_acpi: rfkill switch tpacpi_bluetooth_sw: radio is unblocked
...
Mar 19 14:24:58 Monsoon bluetoothd[836]: Bluetooth daemon 5.64
Mar 19 14:24:58 Monsoon systemd[1]: Started Bluetooth service.
Mar 19 14:24:58 Monsoon systemd[1]: Reached target Bluetooth Support.
Mar 19 14:24:58 Monsoon bluetoothd[836]: Starting SDP server
...
Mar 19 14:24:58 Monsoon bluetoothd[836]: Bluetooth daemon 5.64
Mar 19 14:24:58 Monsoon systemd[1]: Started Bluetooth service.
Mar 19 14:24:58 Monsoon systemd[1]: Reached target Bluetooth Support.
Mar 19 14:24:58 Monsoon bluetoothd[836]: Starting SDP server
...
Mar 19 14:24:58 Monsoon bluetoothd[836]: Bluetooth management interface 1.22 initialized
Mar 19 14:24:58 Monsoon kernel: [    4.188765] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Mar 19 14:24:58 Monsoon kernel: [    4.188770] Bluetooth: BNEP filters: protocol multicast
Mar 19 14:24:58 Monsoon kernel: [    4.188775] Bluetooth: BNEP socket layer initialized
...
Mar 19 14:25:01 Monsoon kernel: [    7.430940] Bluetooth: hci0: Device setup in 3340604 usecs
Mar 19 14:25:01 Monsoon kernel: [    7.430949] Bluetooth: hci0: HCI Enhanced Setup Synchronous Connection command is advertised, but not supported.
Mar 19 14:25:01 Monsoon kernel: [    7.500941] Bluetooth: hci0: AOSP extensions version v1.00
Mar 19 14:25:01 Monsoon kernel: [    7.500947] Bluetooth: hci0: AOSP quality report is supported
Mar 19 14:25:01 Monsoon kernel: [    7.501104] Bluetooth: MGMT ver 1.22
Mar 19 14:25:09 Monsoon bluetoothd[836]: Player registered: sender=:1.36 path=/media_player0
...
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.36 path=/MediaEndpoint/A2DPSource/ldac
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.36 path=/MediaEndpoint/A2DPSink/sbc
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.36 path=/MediaEndpoint/A2DPSource/sbc
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.36 path=/MediaEndpoint/A2DPSink/sbc_xq
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.36 path=/MediaEndpoint/A2DPSource/sbc_xq
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.36 path=/MediaEndpoint/A2DPSource/faststream
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.36 path=/MediaEndpoint/A2DPSource/faststream_duplex
Mar 19 14:25:09 Monsoon wireplumber[1150]: listen(): Address already in use
Mar 19 14:25:09 Monsoon bluetoothd[836]: src/profile.c:register_profile() :1.41 tried to register 00001108-0000-1000-8000-00805F9B34FB which is already registered
Mar 19 14:25:09 Monsoon bluetoothd[836]: src/profile.c:register_profile() :1.41 tried to register 0000111F-0000-1000-8000-00805F9B34FB which is already registered
Mar 19 14:25:09 Monsoon bluetoothd[836]: Player registered: sender=:1.41 path=/media_player1
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.41 path=/MediaEndpoint/A2DPSource/ldac
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.41 path=/MediaEndpoint/A2DPSink/sbc
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.41 path=/MediaEndpoint/A2DPSource/sbc
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.41 path=/MediaEndpoint/A2DPSink/sbc_xq
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.41 path=/MediaEndpoint/A2DPSource/sbc_xq
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.41 path=/MediaEndpoint/A2DPSource/faststream
Mar 19 14:25:09 Monsoon bluetoothd[836]: Endpoint registered: sender=:1.41 path=/MediaEndpoint/A2DPSource/faststream_duplex
Mar 19 14:25:09 Monsoon kernel: [   14.740513] Bluetooth: RFCOMM TTY layer initialized
Mar 19 14:25:09 Monsoon kernel: [   14.740521] Bluetooth: RFCOMM socket layer initialized
Mar 19 14:25:09 Monsoon kernel: [   14.740525] Bluetooth: RFCOMM ver 1.11
...
Mar 19 14:25:17 Monsoon bluetoothd[836]: Endpoint unregistered: sender=:1.41 path=/MediaEndpoint/A2DPSource/ldac
...
Mar 19 14:25:55 Monsoon systemd[1678]: Reached target Bluetooth.

编辑 2:添加 btmon 输出:

Bluetooth monitor ver 5.64
= Note: Linux version 6.1.0-1035-oem (x86_64)                          0.884488
= Note: Bluetooth subsystem version 2.22                               0.884490
= New Index: E8:65:38:20:9E:AC (Primary,USB,hci0)               [hci0] 0.884492
= Open Index: E8:65:38:20:9E:AC                                 [hci0] 0.884492
= Index Info: E8:65:38:20:9E:AC (MediaTek, Inc.)                [hci0] 0.884493
@ MGMT Open: bluetoothd (privileged) version 1.22             {0x0001} 0.884494
@ RAW Open: wmgui version 2.22                                {0x0002} 8.551253
@ RAW Close: wmgui                                            {0x0002} 8.551268
@ RAW Open: wmgui version 2.22                                {0x0002} 8.551294
< HCI Command: Inquiry (0x01|0x0001) plen 5                  #1 [hci0] 8.551332
        Access code: 0x9e8b33 (General Inquiry)
        Length: 6.40s (0x05)
        Num responses: 0
> HCI Event: Command Status (0x0f) plen 4                    #2 [hci0] 8.667822
      Inquiry (0x01|0x0001) ncmd 1
        Status: Success (0x00)
> HCI Event: Extended Inquiry Result (0x2f) plen 255         #3 [hci0] 9.212558
        Num responses: 1
        Address: 5C:17:CF:C3:71:27 (OnePlus Technology (Shenzhen) Co., Ltd)
        Page scan repetition mode: R1 (0x01)
        Page period mode: P2 (0x02)
        Class: 0x5a020c
          Major class: Phone (cellular, cordless, payphone, modem)
          Minor class: Smart phone
          Networking (LAN, Ad hoc)
          Capturing (Scanner, Microphone)
          Object Transfer (v-Inbox, v-Folder)
          Telephony (Cordless telephony, Modem, Headset)
        Clock offset: 0x779c
        RSSI: -84 dBm (0xac)
        Name (complete): OnePlus 8T+ 5G
        16-bit Service UUIDs (complete): 11 entries
          OBEX Object Push (0x1105)
          Audio Source (0x110a)
          A/V Remote Control Target (0x110c)
          A/V Remote Control (0x110e)
          Headset AG (0x1112)
          PANU (0x1115)
          NAP (0x1116)
          Handsfree Audio Gateway (0x111f)
          Phonebook Access Server (0x112f)
          PnP Information (0x1200)
          Message Access Server (0x1132)
        128-bit Service UUIDs (complete): 8 entries
          Vendor specific
          Vendor specific
          Vendor specific
          Vendor specific
          Vendor specific
          Vendor specific
          Vendor specific
          Vendor specific
> HCI Event: Extended Inquiry Result (0x2f) plen 255         #4 [hci0] 9.225053
        Num responses: 1
        Address: 40:49:0F:19:F5:40 (Hon Hai Precision Ind. Co.,Ltd.)
        Page scan repetition mode: R1 (0x01)
        Page period mode: P2 (0x02)
        Class: 0x08043c
          Major class: Audio/Video (headset, speaker, stereo, video, vcr)
          Minor class: Video Display and Loudspeaker
          Capturing (Scanner, Microphone)
        Clock offset: 0x2e54
        RSSI: -100 dBm (0x9c)
> HCI Event: Inquiry Result with RSSI (0x22) plen 15        #5 [hci0] 10.657527
        Num responses: 1
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Page scan repetition mode: R1 (0x01)
        Page period mode: P2 (0x02)
        Class: 0x002504
          Major class: Peripheral (mouse, joystick, keyboards)
          Minor class: 0x01
          Limited Discoverable Mode
        Clock offset: 0x12fb
        RSSI: -56 dBm (0xc8)
> HCI Event: Inquiry Complete (0x01) plen 1                 #6 [hci0] 15.155581
        Status: Success (0x00)
@ RAW Close: wmgui                                           {0x0002} 15.155776
@ RAW Open: wmgui version 2.22                        {0x0002} [hci0] 15.155839
< HCI Command: Remote Name Request (0x01|0x0019) plen 10    #7 [hci0] 15.155876
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Page scan repetition mode: R2 (0x02)
        Page scan mode: Mandatory (0x00)
        Clock offset: 0x0000
> HCI Event: Command Status (0x0f) plen 4                   #8 [hci0] 15.157081
      Remote Name Request (0x01|0x0019) ncmd 1
        Status: Success (0x00)
> HCI Event: Remote Name Req Complete (0x07) plen 255       #9 [hci0] 15.287859
        Status: Success (0x00)
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Name: Nintendo RVL-CNT-01
@ RAW Close: wmgui                                    {0x0002} [hci0] 15.288112
@ RAW Open: wmgui version 2.22                        {0x0002} [hci0] 16.288561
< HCI Command: Remote Name Request (0x01|0x0019) plen 10   #10 [hci0] 16.288656
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Page scan repetition mode: R2 (0x02)
        Page scan mode: Mandatory (0x00)
        Clock offset: 0x0000
> HCI Event: Command Status (0x0f) plen 4                  #11 [hci0] 16.291213
      Remote Name Request (0x01|0x0019) ncmd 1
        Status: Success (0x00)
> HCI Event: Remote Name Req Complete (0x07) plen 255      #12 [hci0] 16.441082
        Status: Success (0x00)
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Name: Nintendo RVL-CNT-01
@ RAW Close: wmgui                                    {0x0002} [hci0] 16.441323
< HCI Command: Create Connection (0x01|0x0005) plen 13     #13 [hci0] 16.441414
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Packet type: 0xcc18
          DM1 may be used
          DH1 may be used
          DM3 may be used
          DH3 may be used
          DM5 may be used
          DH5 may be used
        Page scan repetition mode: R1 (0x01)
        Page scan mode: Mandatory (0x00)
        Clock offset: 0x92fb
        Role switch: Allow peripheral (0x01)
> HCI Event: Command Status (0x0f) plen 4                  #14 [hci0] 16.443061
      Create Connection (0x01|0x0005) ncmd 1
        Status: Success (0x00)
> HCI Event: Connect Complete (0x03) plen 11               #15 [hci0] 16.937802
        Status: Success (0x00)
        Handle: 50
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Link type: ACL (0x01)
        Encryption: Disabled (0x00)
< HCI Command: Read Remote Support.. (0x01|0x001b) plen 2  #16 [hci0] 16.937971
        Handle: 50
> HCI Event: Command Status (0x0f) plen 4                  #17 [hci0] 16.938540
      Read Remote Supported Features (0x01|0x001b) ncmd 1
        Status: Success (0x00)
> HCI Event: Read Remote Supported Featu.. (0x0b) plen 11  #18 [hci0] 16.944036
        Status: Success (0x00)
        Handle: 50
        Features: 0xbc 0x02 0x04 0x38 0x08 0x00 0x00 0x00
          Encryption
          Slot offset
          Timing accuracy
          Role switch
          Sniff mode
          Power control requests
          Power control
          Enhanced inquiry scan
          Interlaced inquiry scan
          Interlaced page scan
          AFH capable peripheral
< HCI Command: Remote Name Request (0x01|0x0019) plen 10   #19 [hci0] 16.944069
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Page scan repetition mode: R2 (0x02)
        Page scan mode: Mandatory (0x00)
        Clock offset: 0x0000
< ACL Data TX: Handle 50 flags 0x00 dlen 10                #20 [hci0] 16.944081
      L2CAP: Information Request (0x0a) ident 1 len 2
        Type: Extended features supported (0x0002)
> HCI Event: Command Status (0x0f) plen 4                  #21 [hci0] 16.944660
      Remote Name Request (0x01|0x0019) ncmd 1
        Status: Success (0x00)
> HCI Event: Number of Completed Packets (0x13) plen 5     #22 [hci0] 16.949035
        Num handles: 1
        Handle: 50
        Count: 1
> ACL Data RX: Handle 50 flags 0x02 dlen 16                #23 [hci0] 16.952842
      L2CAP: Information Response (0x0b) ident 1 len 8
        Type: Extended features supported (0x0002)
        Result: Success (0x0000)
        Features: 0x00000004
          Bi-directional QoS
< ACL Data TX: Handle 50 flags 0x00 dlen 12                #24 [hci0] 16.952871
      L2CAP: Connection Request (0x02) ident 2 len 4
        PSM: 17 (0x0011)
        Source CID: 64
> HCI Event: Number of Completed Packets (0x13) plen 5     #25 [hci0] 16.955287
        Num handles: 1
        Handle: 50
        Count: 1
> HCI Event: Remote Name Req Complete (0x07) plen 255      #26 [hci0] 16.958654
        Status: Success (0x00)
        Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Name: Nintendo RVL-CNT-01
@ MGMT Event: Device Connected (0x000b) plen 39       {0x0001} [hci0] 16.958670
        BR/EDR Address: CC:9E:00:C6:41:82 (Nintendo Co., Ltd.)
        Flags: 0x00000008
          Connection Locally Initiated
        Data length: 26
        Name (complete): Nintendo RVL-CNT-01
        Class: 0x002504
          Major class: Peripheral (mouse, joystick, keyboards)
          Minor class: 0x01
          Limited Discoverable Mode
> ACL Data RX: Handle 50 flags 0x02 dlen 16                #27 [hci0] 16.958932
      L2CAP: Connection Response (0x03) ident 2 len 8
        Destination CID: 105
        Source CID: 64
        Result: Connection pending (0x0001)
        Status: No further information available (0x0000)
> ACL Data RX: Handle 50 flags 0x02 dlen 16                #28 [hci0] 16.986624
      L2CAP: Connection Response (0x03) ident 2 len 8
        Destination CID: 105
        Source CID: 64
        Result: Connection successful (0x0000)
        Status: No further information available (0x0000)
< ACL Data TX: Handle 50 flags 0x00 dlen 12                #29 [hci0] 16.986695
      L2CAP: Configure Request (0x04) ident 3 len 4
        Destination CID: 105
        Flags: 0x0000
> HCI Event: Number of Completed Packets (0x13) plen 5     #30 [hci0] 16.989044
        Num handles: 1
        Handle: 50
        Count: 1
> ACL Data RX: Handle 50 flags 0x02 dlen 18                #31 [hci0] 16.991540
      L2CAP: Configure Response (0x05) ident 3 len 10
        Source CID: 64
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 185
> ACL Data RX: Handle 50 flags 0x02 dlen 16                #32 [hci0] 16.992849
      L2CAP: Configure Request (0x04) ident 49 len 8
        Destination CID: 64
        Flags: 0x0000
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 185
< ACL Data TX: Handle 50 flags 0x00 dlen 18                #33 [hci0] 16.992879
      L2CAP: Configure Response (0x05) ident 49 len 10
        Source CID: 105
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 185
< ACL Data TX: Handle 50 flags 0x00 dlen 12                #34 [hci0] 16.992967
      L2CAP: Connection Request (0x02) ident 4 len 4
        PSM: 19 (0x0013)
        Source CID: 65
> HCI Event: Number of Completed Packets (0x13) plen 5     #35 [hci0] 16.995919
        Num handles: 1
        Handle: 50
        Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5     #36 [hci0] 16.996525
        Num handles: 1
        Handle: 50
        Count: 1
> ACL Data RX: Handle 50 flags 0x02 dlen 16                #37 [hci0] 16.999099
      L2CAP: Connection Response (0x03) ident 4 len 8
        Destination CID: 106
        Source CID: 65
        Result: Connection successful (0x0000)
        Status: No further information available (0x0000)
< ACL Data TX: Handle 50 flags 0x00 dlen 12                #38 [hci0] 16.999119
      L2CAP: Configure Request (0x04) ident 5 len 4
        Destination CID: 106
        Flags: 0x0000
> HCI Event: Number of Completed Packets (0x13) plen 5     #39 [hci0] 17.001534
        Num handles: 1
        Handle: 50
        Count: 1
> ACL Data RX: Handle 50 flags 0x02 dlen 18                #40 [hci0] 17.004036
      L2CAP: Configure Response (0x05) ident 5 len 10
        Source CID: 65
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 185
> ACL Data RX: Handle 50 flags 0x02 dlen 16                #41 [hci0] 17.005346
      L2CAP: Configure Request (0x04) ident 50 len 8
        Destination CID: 65
        Flags: 0x0000
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 185
< ACL Data TX: Handle 50 flags 0x00 dlen 18                #42 [hci0] 17.005419
      L2CAP: Configure Response (0x05) ident 50 len 10
        Source CID: 106
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 185
< ACL Data TX: Handle 50 flags 0x00 dlen 7                 #43 [hci0] 17.006051
      Channel: 105 len 3 [PSM 17 mode Basic (0x00)] {chan 0}
        52 11 00                                         R..             
> HCI Event: Number of Completed Packets (0x13) plen 5     #44 [hci0] 17.007784
        Num handles: 1
        Handle: 50
        Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5     #45 [hci0] 17.009034
        Num handles: 1
        Handle: 50
        Count: 1
> HCI Event: QoS Setup Complete (0x0d) plen 21             #46 [hci0] 17.063028
        Status: Success (0x00)
        Handle: 50
        Flags: 0x00
        Service type: Best Effort (0x01)
        Token rate: 2700
        Peak bandwidth: 0
        Latency: 10000
        Delay variation: 0
> ACL Data RX: Handle 50 flags 0x02 dlen 12                #47 [hci0] 17.064057
      Channel: 65 len 8 [PSM 19 mode Basic (0x00)] {chan 1}
        a1 20 00 00 02 00 00 b3                          . ...... 
(at this point the program hangs, whereas on the older laptop with the same Ubuntu 22.04 and bluetooth stack, but also different bluetooth interface, the result is wiimote vibrating and finishing connection, after which you can retrieve its data and you see received data showing on the wmgui's GUI)

我还尝试添加 lp 蓝牙和 dialout 组来匹配用户对这些组权限的访问权限,但这没有什么区别。

最后,风扇在挂起时似乎会启动,这表明 CPU 使用率增加,并且程序陷入某种循环(此时 wmgui 占用了 100% 的 CPU)。

编辑 3:在下面添加了 gdb 输出

Thread 1 "wmgui" received signal SIGINT, Interrupt.
__GI___libc_read (nbytes=1, buf=0x7fffffffd167, fd=12) at ../sysdeps/unix/sysv/linux/read.c:26
26  ../sysdeps/unix/sysv/linux/read.c: No such file or directory.
(gdb) back
#0  __GI___libc_read (nbytes=1, buf=0x7fffffffd167, fd=12)
    at ../sysdeps/unix/sysv/linux/read.c:26
#1  __GI___libc_read (fd=12, buf=0x7fffffffd167, nbytes=1)
    at ../sysdeps/unix/sysv/linux/read.c:24
#2  0x00007ffff7e834db in verify_handshake (wiimote=0x555555821670)
    at util.c:105
#3  0x00007ffff7e7e309 in cwiid_send_rpt
    (wiimote=0x555555821670, flags=0 '\000', report=17 '\021', len=1, data=0x7fffffffd1d7) at command.c:130
#4  0x00007ffff7e7e411 in cwiid_set_led (wiimote=0x555555821670, led=0 '\000')
    at command.c:159
#5  0x00007ffff7e7f6ad in cwiid_open_timeout
    (bdaddr=0x555555570048 <bdaddr>, flags=1, timeout=5) at connect.c:264
#6  0x00007ffff7e7ef1a in cwiid_open (bdaddr=0x555555570048 <bdaddr>, flags=1)
    at connect.c:85
#7  0x000055555555bd3c in menuConnect_activate () at main.c:705
#8  0x00007ffff79b4d2f in g_closure_invoke ()
    at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#9  0x00007ffff79d0c36 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#10 0x00007ffff79d2614 in g_signal_emit_valist ()
    at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#11 0x00007ffff79d2863 in g_signal_emit ()
    at /lib/x86_64-linux-gnu/libgobject-2.0.so.0

编辑4:添加更多信息

因此,我在两台笔记本电脑之间测试了一系列 BT USB 适配器,但它们都无法在两台笔记本电脑上工作。此外,我更换了 wifi/蓝牙内置笔记本电脑卡,发现虽然 intel 8265 wifi/蓝牙卡可以在运行 Ubuntu 22.04 的旧笔记本电脑上工作,但在新笔记本电脑上却不能工作。这几乎消除了除内核之外的所有内容。因此,似乎内核蓝牙堆栈发生了一些变化,导致用户空间蓝牙访问要么被弃用,要么其 API 中的某些内容使得通常的配对变得不可能。如果是后者,我还无法找到任何显示可能丢失的内容......

编辑 5:看起来每次库到达 read() 请求并尝试从套接字读取时,程序/库就会冻结并陷入 100% CPU 使用率。写入似乎可以工作,因为在第一次读取之前,cwiid 会写入阻止 Wiimote 的 LED 闪烁的数据。我还将用户添加到输入组中,这没有什么区别。

c ubuntu bluetooth userspace
1个回答
0
投票

我克隆并构建了 https://github.com/pd-l2ork/cwiid.git 并且已经让 Wiimote 在我的 Raspberry Pi 4 中工作了一段时间。

最近我买了一个 Raspberry Pi 5 并运行了相同的代码,但它不起作用。经过一堆 printfs 后,发现它挂在 verify_handshake 中的 read() 调用处。

我尝试使用与 4、5 中相同的 python (3.9.2) 和 bluez (5.66) 版本,但没有运气。我看到的唯一区别是 Rpi 4 有 openssl 1.1.1,而 5 有 openssl 3.0。

如果成功的话请在这里更新?

© www.soinside.com 2019 - 2024. All rights reserved.