Error with Go program ( Bettercap 2 ) depending on which bluetooth dongle I use on Ubuntu/Raspberry Pi OS when running ble scan

huangapple go评论148阅读模式
英文:

Error with Go program ( Bettercap 2 ) depending on which bluetooth dongle I use on Ubuntu/Raspberry Pi OS when running ble scan

问题

我在Ubuntu 20.04和Raspberry Pi OS 5.10上使用这个程序,但这不是一个与Linux相关的问题。

我在使用一个叫做Bettercap 2的Go程序时遇到了问题(https://www.bettercap.org/和https://github.com/bettercap/bettercap的存储库),当我使用它的蓝牙设备扫描功能"ble.recon on"与不同的蓝牙适配器一起使用时。

当我使用一个使用Realtek RTL8761b驱动程序的适配器(MPOW MPBH456AB),你可以在亚马逊上找到它,它工作正常,但是当我使用一个NordicSemi nrf52840适配器(https://www.nordicsemi.com/Products/Development-hardware/nrf52840-dongle)这是我的目标,刷上Zephyr RTOS的hci_usb示例(https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/hci_usb),它应该将任何使用蓝牙的微控制器转换为任何计算机都应该识别的常规蓝牙适配器时,它会抛出以下错误:

>> ble.recon on
   panic: runtime error: slice bounds out of range [:1] with capacity 0

   goroutine 1 [running]:
   github.com/bettercap/gatt/linux/cmd.(*Cmd).SendAndCheckResp(0x1c637c0, 0xa0c760, 0x1c64fe8, 0x1c6501c, 0x1, 0x1, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/cmd/cmd.go:98 +0x1b4
   github.com/bettercap/gatt/linux.(*HCI).resetDevice(0x18ac0a0, 0x93dc10, 0x18ac0a0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/hci.go:273 +0x2f0
   github.com/bettercap/gatt/linux.NewHCI(0xffffffff, 0x184fd01, 0xff, 0x2, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/hci.go:90 +0x4c0
   github.com/bettercap/gatt.NewDevice(0x184fd1c, 0x2, 0x2, 0x3c, 0x184fd24, 0x1, 0x1)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/device_linux.go:57 +0x114
   github.com/bettercap/bettercap/modules/ble.(*BLERecon).Configure(0x18a2780, 0x0, 0x4)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:165 +0x1cc
   github.com/bettercap/bettercap/modules/ble.(*BLERecon).Start(0x18a2780, 0x1, 0x1b2c001)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:183 +0x1c
   github.com/bettercap/bettercap/modules/ble.NewBLERecon.func1(0x0, 0x0, 0x0, 0x84f358, 0xc)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:56 +0x1c
   github.com/bettercap/bettercap/session.(*ModuleHandler).Exec(0x1b2c0c0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/session/module_handler.go:74 +0x80
   github.com/bettercap/bettercap/session.(*Session).Run(0x18fb2c0, 0x1c64e30, 0xc, 0x1, 0x1)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/session/session.go:416 +0x284
   main.main()
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/main.go:94 +0x8c8

我不知道这是什么意思,因为我不是Go开发人员,也从未使用过这种语言,我看了一下错误,似乎是在代码中,但是由于不了解Go,我更愿意在修改任何内容之前先询问。

问题只出现在我使用nrf适配器时,否则它可以与主机的蓝牙和其他realtek适配器一起使用。

nrf适配器可以与BlueZ堆栈一起使用,以下是结果:

bluetoothctl(有一个BD地址)
扫描可以工作

$ sudo bluetoothctl
  Agent registered
  [bluetooth]# list
  Controller EB:XX:XX:XX:XX:XX BlueZ 5.50 [default]

btmgmt(找到控制器)
扫描可以工作

$ sudo btmgmt --index 0
   [hci0]# auto-power
   Found controller with index 0
   [hci0]# find -l

但是,尽管已经过时,hciconfig和hcitool可以识别realtek适配器,但对于这个问题,以下是结果:

hciconfig(没有BD地址)

$ hciconfig
  hci0:   Type: Primary  Bus: USB
    BD Address: 00:00:00:00:00:00  ACL MTU: 27:7  SCO MTU: 0:0
    UP RUNNING
    RX bytes:1593 acl:0 sco:0 events:88 errors:0
    TX bytes:285 acl:0 sco:0 commands:51 errors:0

hcitool(找不到控制器)

$ hcitool scan
  Scanning ...
  Inquiry failed: Operation not supported

所以,我认为该适配器与BlueZ一起工作正常,作为Linux官方蓝牙堆栈,这是一个好迹象,但我认为Bettercap也在使用BlueZ,在这个意义上,适配器应该工作。

我认为不需要安装任何驱动程序,因为当它被刷写(J-Link)时,它会变成一个通用的蓝牙适配器。

你有任何关于问题可能是什么的想法吗?

英文:

I use this on Ubuntu 20.04 and Raspberry Pi OS 5.10 but this is not a Linux related issue.

I'm having an issue with a Go program called Bettercap 2 ( https://www.bettercap.org/ and the repository: https://github.com/bettercap/bettercap ) when I use its function to scan bluetooth devices "ble.recon on" with a different bluetooth dongle.

When I use it with a dongle using Realtek RTL8761b drivers ( MPOW MPBH456AB ) you can find on amazon it works well, but when I use a NordicSemi nrf52840 dongle ( https://www.nordicsemi.com/Products/Development-hardware/nrf52840-dongle ) which is my goal, flashed with Zephyr RTOS' hci_usb sample ( https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/hci_usb ) which is supposed to turn any micro controller using bluetooth into a regular bluetooth dongle that any computer is supposed to recognize as, it throws this error:

>> ble.recon on
   panic: runtime error: slice bounds out of range [:1] with capacity 0

   goroutine 1 [running]:
   github.com/bettercap/gatt/linux/cmd.(*Cmd).SendAndCheckResp(0x1c637c0, 0xa0c760, 0x1c64fe8, 0x1c6501c, 0x1, 0x1, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/cmd/cmd.go:98 +0x1b4
   github.com/bettercap/gatt/linux.(*HCI).resetDevice(0x18ac0a0, 0x93dc10, 0x18ac0a0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/hci.go:273 +0x2f0
   github.com/bettercap/gatt/linux.NewHCI(0xffffffff, 0x184fd01, 0xff, 0x2, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/hci.go:90 +0x4c0
   github.com/bettercap/gatt.NewDevice(0x184fd1c, 0x2, 0x2, 0x3c, 0x184fd24, 0x1, 0x1)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/device_linux.go:57 +0x114
   github.com/bettercap/bettercap/modules/ble.(*BLERecon).Configure(0x18a2780, 0x0, 0x4)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:165 +0x1cc
   github.com/bettercap/bettercap/modules/ble.(*BLERecon).Start(0x18a2780, 0x1, 0x1b2c001)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:183 +0x1c
   github.com/bettercap/bettercap/modules/ble.NewBLERecon.func1(0x0, 0x0, 0x0, 0x84f358, 0xc)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:56 +0x1c
   github.com/bettercap/bettercap/session.(*ModuleHandler).Exec(0x1b2c0c0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/session/module_handler.go:74 +0x80
   github.com/bettercap/bettercap/session.(*Session).Run(0x18fb2c0, 0x1c64e30, 0xc, 0x1, 0x1)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/session/session.go:416 +0x284
   main.main()
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/main.go:94 +0x8c8

I have no idea what it means as I'm not a Go developer and have never used this language, I've looked at the error and it seems to be in the code but not knowing Go, I prefer to ask before I modify anything.

The problem is only when I'm using the nrf dongle, otherwise it works with the host's bluetooth and the other realtek dongle.

The nrf dongle works with the BlueZ stack, here are the results:

bluetoothctl ( has a BD address )
Scan does work

$ sudo bluetoothctl
  Agent registered
  [bluetooth]# list
  Controller EB:XX:XX:XX:XX:XX BlueZ 5.50 [default]

btmgmt ( finds the controller )
Scan does work

$ sudo btmgmt --index 0
   [hci0]# auto-power
   Found controller with index 0
   [hci0]# find -l

But, although deprecated, hciconfig and hcitool recognize the realtek dongle but for this one, here are the results:

hciconfig ( no BD address )

$ hciconfig
  hci0:   Type: Primary  Bus: USB
    BD Address: 00:00:00:00:00:00  ACL MTU: 27:7  SCO MTU: 0:0
    UP RUNNING
    RX bytes:1593 acl:0 sco:0 events:88 errors:0
    TX bytes:285 acl:0 sco:0 commands:51 errors:0

hcitool ( Doesn't find the controller )

$ hcitool scan
  Scanning ...
  Inquiry failed: Operation not supported

So, I assume the dongle works well with BlueZ, being the Linux official bluetooth stack it's a good sign, but I thought that Bettercap was also using BlueZ and in that sense the dongle should work.

I don't think there are any drivers to install for the dongle as of the fact that when it is flashed ( J-Link ) it turns into a generic bluetooth dongle.

Do you have any idea what the problem could be ?

答案1

得分: 3

我相信错误来自于https://github.com/bettercap/gatt/blob/master/linux/cmd/cmd.go#L98

该程序试图向设备写入一些内容,并期望只要发送没有错误,就会收到响应。但显然,发送调用是成功的,但接收到的响应为空。

我建议你在那里打开一个问题,并提出你的问题。

英文:

I believe the error is coming from https://github.com/bettercap/gatt/blob/master/linux/cmd/cmd.go#L98

The program is attempting to write something to the device and expects that it will receive a response as long as there was no error sending. But apparently the Send call is successful but receives an empty response.

I'd suggest opening an issue over there and asking your question.

huangapple
  • 本文由 发表于 2021年9月5日 09:23:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/69059990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定