gpt4 book ai didi

ios - 如何以编程方式处理 BLE 外设从 iOS 设备移除配对

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:17 24 4
gpt4 key购买 nike

在中央模式下运行的 iOS 应用程序和具有加密 GATT 特性的 BLE 外围设备(例如 BLE113) - 当 iOS 应用程序扫描并连接到外围设备时,它会在发现加密的 GATT 特性时自动请求配对.

如果 iOS 设备和 BLE 外设都保持配对状态,则一切正常。

但是,如何处理 BLE 外围设备在内部删除所有绑定(bind)信息而不通知 iOS 设备它正在删除配对 key 的情况?

iOS CoreBluetooth 命令只会失败。

是否可以通过编程方式解决此问题?是重新请求配对,还是取消配对 iOS 端?

iOS 对蓝牙有很大的限制 - 所以我看不到太多好的解决方案,除了检测写入失败的时间,并要求用户手动取消配对(这是蹩脚的)

最佳答案

我终于能够解决这个问题,事实证明,你甚至不需要取消配对!!!

我在这里写下我的经历:

http://www.sureshjoshi.com/embedded/bgscript-pairing-hell/在这里:http://community.silabs.com/t5/Wireless/Bonding-issues-with-BLE121/m-p/163221#M10850

基本上,从固件方面来说,当设备发现配对没有立即发生时,您可以重新请求加密。对于 BGScript,这里是相关代码:

event sm_bonding_fail(handle, result) 
# If bonding fails, handle it gracefully based on the following possible results:
# - 0x018B - Out of bonds (no space left, all 8 bonding slots taken)
# - 0x0205 - Authentication failure (shouldn't happen with "just works" mode, but might otherwise)
# - 0x0206 - Pin or key missing (probably local or remote device is missing the key, but not both)
# - 0x0301 - Passkey entry failed (also shouldn't happen in "just works" mode unless bonding is cancelled)
# - 0x0302 - OOB data not available (only occurs if OOB is required and not supported on both ends)
# - 0x0303 - Authentication requirements (I/O capabilities required but not supported)
# - 0x0304 - Confirm value failed (PIN entry/comparison attempted but failed)
# - 0x0305 - Pairing not supported (also occurs if bond info removed from remote device but not local module)
# - 0x0306 - Encryption key size (key size insufficient to meet security requirements)
# - 0x0307 - Command not supported (SMP command is not supported on this device)
# - 0x0308 - Unspecified reason (may occur if bond info is present remotely but not locally)
# - 0x0309 - Repeated attempts (too little time has elapsed since last pairing/security request)
# - 0x030A - Invalid parameters (bad parameters sent during pairing/bonding process)

# NOTE: The most common cases:
# - 0x018B, which means you ran out of space and must remove at least one bond in order to bond again
# - 0x0206, which typically means the pairing info was removed on the remote device but not locally
# - 0x0301, which typically means the user cancelled the pairing request or entered the wrong passkey
# - 0x0305, which is like 0x0206 but is often generated instead if the remote device is a smartphone
# - 0x0308, which typically means the pairing info was removed on the local device but not remotely
if result = $018b then
# Only solved by removing bonds - requires the user to reset the bonds...
end if

if result = $0301 then
# Usually solved simply by trying again
# Seems to solve most problems on iOS
# On Android, pairing rejected a few times if Android deleted pairing without informing device
call sm_encrypt_start(0, 1)
end if

if result = $0305 || result = $0206 then
# Remove local bonding info first, then the remote device needs to reconnect
# If current_bond_handle is $ff, that means we don't have a bonding handle - so not much we can do
if current_bond_handle != $ff then
call sm_delete_bonding(current_bond_handle)
end if

# Sometimes takes a few tries
call connection_disconnect(0)
end if

if result = $0308 then
# Remove remote bonding info first, then the remote device needs to reconnect
# Android can recover automatically, iOS cannot
# Instead of disconnecting, just force a re-encryption... Usually works
call sm_encrypt_start(0, 1)
end if
end

关于ios - 如何以编程方式处理 BLE 外设从 iOS 设备移除配对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34410070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com