Linux 命令行如何接受没有 pin 的蓝牙设备的配对

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12888589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:36:13  来源:igfitidea点击:

Linux command line howto accept pairing for bluetooth device without pin

linuxcommand-linebluetoothbluez

提问by Roman A. Taycher

Is there a way to pair a device in linux without requiring a pin(for testing purposes so I need it to be done w/out human interaction, assuming you have root access)?

有没有办法在不需要 pin 的情况下在 linux 中配对设备(出于测试目的,所以我需要在没有人为交互的情况下完成它,假设您具有 root 访问权限)?

bluez-simple-agent seems to require a pin except with some simple devices such as mice.

bluez-simple-agent 似乎需要一个 pin,除了一些简单的设备,比如鼠标。

采纳答案by Eric

Try setting security to none in /etc/bluetooth/hcid.conf

尝试在 /etc/bluetooth/hcid.conf 中将 security 设置为 none

http://linux.die.net/man/5/hcid.conf

http://linux.die.net/man/5/hcid.conf

This will probably only work for HCI devices (mouse, keyboard, spaceball, etc.). If you have a different kind of device, there's probably a different but similar setting to change.

这可能仅适用于 HCI 设备(鼠标、键盘、太空球等)。如果您有不同类型的设备,则可能需要更改不同但相似的设置。

回答by Paul Poulsen

Entering a PIN is actually an outdated method of pairing, now called Legacy Pairing. Secure Simple Pairing Mode is available in Bluetooth v2.1 and later, which comprises most modern Bluetooth devices. SSPMode authentication is handled by the Bluetooth protocol stack and thus works without user interaction.

输入 PIN 码实际上是一种过时的配对方法,现在称为Legacy Pairing。安全简单配对模式在蓝牙 v2.1 及更高版本中可用,其中包括大多数现代蓝牙设备。SSPMode 身份验证由蓝牙协议栈处理,因此无需用户交互即可工作。

Here is how one might go about connecting to a device:

以下是连接设备的方法:

# hciconfig hci0 sspmode 1
# hciconfig hci0 sspmode
hci0:   Type: BR/EDR  Bus: USB
BD Address: AA:BB:CC:DD:EE:FF  ACL MTU: 1021:8  SCO MTU: 64:1
Simple Pairing mode: Enabled
# hciconfig hci0 piscan
# sdptool add SP
# hcitool scan
    00:11:22:33:44:55    My_Device
# rfcomm connect /dev/rfcomm0 00:11:22:33:44:55 1 &
Connected /dev/rfcomm0 to 00:11:22:33:44:55 on channel 1
Press CTRL-C for hangup

This would establish a serial connection to the device.

这将建立到设备的串行连接。

回答by AjayKumarBasuthkar

This worked like a charm for me, of-course it requires super-user privileges :-)

这对我来说就像一个魅力,当然它需要超级用户权限:-)

# hcitool cc <target-bdaddr>; hcitool auth <target-bdaddr>

# hcitool cc <target-bdaddr>; hcitool auth <target-bdaddr>

To get <target-bdaddr>you may issue below command:
$ hcitool scan

为了让<target-bdaddr>您可以发出以下命令:
$ hcitool scan

Note: Exclude #& $as they are command line prompts.

注意:排除#&$因为它们是命令行提示。

Courtesy

礼貌

回答by Hyman Miller

For Ubuntu 14.04 and Android try:

对于 Ubuntu 14.04 和 Android,请尝试:

hcitool scan #get hardware address
sudo bluetooth-agent PIN HARDWARE-ADDRESS

PIN dialog pops up on Android device. Enter same PIN.

Android 设备上会弹出 PIN 对话框。输入相同的 PIN。

Note: sudo apt-get install bluez-utilsmight be necessary.

注意:sudo apt-get install bluez-utils可能是必要的。

Note2: If PIN dialog does not appear, try pairing from Android first (will fail because of wrong PIN). Then try again as described above.

注意 2:如果没有出现 PIN 对话框,请先尝试从 Android 配对(会因 PIN 错误而失败)。然后按上述方法重试。

回答by Darren Ng

~ $ hciconfig noauth

This should do the trick (I'm using bluez 5.23 and there's no more simple-egent and blue-utils). However, I'm trying to look for a way to make changes hciconfig permanent because after power out and then power on, authentication is needed again. So far, the changes in hciconfig still stays the same when you reboot it. it reverts back only when power out. If anybody has found a way to make hciconfig permanent, do let me know!

这应该可以解决问题(我使用的是 bluez 5.23 并且不再有 simple-egent 和 blue-utils)。但是,我正在尝试寻找一种方法来使更改 hciconfig 永久化,因为在断电然后再通电后,再次需要身份验证。到目前为止,hciconfig 中的更改在您重新启动时仍然保持不变。仅在断电时恢复。如果有人找到了使 hciconfig 永久化的方法,请告诉我!

回答by hao ran

follow steps (CentOs):

按照步骤(CentOs):

  1. bluetoothctl
  2. devices
  3. scan on
  4. pair 34:88:5D:51:5A:95 (34:88:5D:51:5A:95 is my device code,replace it with yours)
  5. trust 34:88:5D:51:5A:95
  6. connect 34:88:5D:51:5A:95
  1. 蓝牙控制
  2. 设备
  3. 继续扫描
  4. 对 34:88:5D:51:5A:95(34:88:5D:51:5A:95 是我的设备代码,用你的替换它)
  5. 信任 34:88:5D:51:5A:95
  6. 连接 34:88:5D:51:5A:95

If you want more details https://www.youtube.com/watch?v=CB1E4Ir3AV4

如果您想了解更多详情 https://www.youtube.com/watch?v=CB1E4Ir3AV4

回答by Elias Chatzigeorgiou

~ $ hciconfig noauth

It worked for me in "Linux mx 4.19"

它在“Linux mx 4.19”中对我有用

The exact steps are:

具体步骤是:

1) open a terminal - run: "hciconfig noauth"
2) use the blueman-manager gui to pair the device (in my case it was a keyboard)
3) from the blueman-manager choose "connect to HID"

1)打开终端 - 运行:“hciconfig noauth”
2)使用 blueman-manager gui 配对设备(在我的情况下是键盘)
3)从 blueman-manager 选择“连接到 HID”

step(3) is normally asking for a password - the "hciconfig noauth" makes step(3) passwordless

步骤(3)通常要求输入密码 - “hciconfig noauth”使步骤(3)无需密码