修改Android bluedroid的代码使BLE配对为默认LE Legacy pairing而不是LE Secure connection
时间: 2024-03-27 17:41:28 浏览: 17
要将Android Bluedroid的BLE配对方式修改为默认的LE Legacy Pairing而不是LE Secure Connection,可以按照以下步骤进行:
1. 找到Bluedroid源代码中的`btif_dm_ble_sec_req_evt`函数,该函数位于`/system/bt/btif/src/btif_dm.c`文件中。
2. 在该函数中,找到以下代码:
```C
if (btm_ble_get_encryption_key_type(p_data->ble_req.bd_addr) == BTM_BLE_SEC_ENCRYPT) {
bond_type = BOND_TYPE_ENCRYPT;
}
```
3. 将上述代码修改为以下代码:
```C
if (btm_ble_get_encryption_key_type(p_data->ble_req.bd_addr) == BTM_BLE_SEC_ENCRYPT) {
bond_type = BOND_TYPE_LE_LEGACY;
}
```
4. 保存文件并重新编译Bluedroid源代码,生成新的系统镜像文件并刷写到Android设备中即可。
需要注意的是,修改BLE配对方式可能会降低设备的安全性,因此应谨慎操作,并在不需要使用LE Legacy Pairing的情况下尽量使用LE Secure Connection。同时,对于一些定制化的Android系统,可能需要使用其他的方法来修改BLE配对方式,请根据具体情况进行调整。
相关问题
如何配置Android bluedroid的代码使BLE配对为默认LE Legacy pairing而不是LE Secure connection
要配置Android Bluedroid的代码使BLE配对为默认的LE Legacy Pairing而不是LE Secure Connection,需要进行以下步骤:
1. 打开Android源代码中的bluedroid文件夹。
2. 寻找stack目录,然后打开btm目录。
3. 在btm目录中,打开btm_sec.c文件。
4. 在btm_sec.c文件中搜索“btm_sec_auth_req()”函数。
5. 在函数中找到以下代码:
if (p_dev_rec && (p_dev_rec->sec_flags & BTM_SEC_LE_AUTHENTICATED))
{
sec_flag |= BTM_SEC_LE_AUTHENTICATED;
}
6. 将上述代码替换为以下代码:
if (p_dev_rec && (p_dev_rec->sec_flags & BTM_SEC_LE_AUTHENTICATED))
{
sec_flag |= BTM_SEC_LE_LEGACY_PAIRING;
}
7. 保存修改并重新编译Android源代码。
这样,你就可以将BLE配对设置为默认的LE Legacy Pairing,而不是LE Secure Connection。请注意,这只是一种修改代码的方法,如果你不熟悉代码修改,请谨慎操作。
Android 将Bluedroid BLE配对修改为默认LE Legacy pairing而不是LE Secure connection的代码
修改Android设备的系统设置来更改默认的BLE配对方式,可以通过以下代码实现:
```java
// 获取BluetoothAdapter对象
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// 判断当前设备是否支持BLE
if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
// 获取BluetoothGatt对象
BluetoothGatt bluetoothGatt = bluetoothDevice.connectGatt(context, false, bluetoothGattCallback);
// 获取BluetoothDevice对象
BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(deviceAddress);
// 配置BLE安全参数
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 设置BLE安全参数为LE Legacy Pairing
bluetoothDevice.setLeIoCapability(BluetoothDevice.IO_CAPABILITY_IN);
// 设置BLE配对方式为LE Legacy Pairing
bluetoothGatt.getDevice().getBondState();
bluetoothGatt.setPairingConfirmation(false);
bluetoothGatt.setPin(new byte[] {0x00, 0x01, 0x02, 0x03});
}
}
```
需要注意的是,这段代码只是示例,实际使用时需要根据具体情况进行修改。同时,修改BLE配对方式可能会降低设备的安全性,因此应谨慎操作,并在不需要使用LE Legacy Pairing的情况下尽量使用LE Secure Connection。