在 BlueZ 中,使用固定 PIN 码进行连接可能不够安全。建议使用随机 PIN 码以增强安全性。以下是一个示例:
$ echo -n "000000" > /var/lib/bluetooth/[bluetooth address]/[device address]/info
$ bluetoothctl
> agent on
> default-agent
> pairable on
> scan on
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
device.createBond();
# On the service side
$ echo -n "pin_of_your_choice" > /var/lib/bluetooth/[bluetooth address]/[device address]/info
最后,BlueZ 将使用您指定的 PIN 码进行连接。