2015-12-22 160 views
3

在iOS應用程序以中央模式運行時,以及具有加密GATT特性的BLE外圍設備(例如BLE113) - iOS應用程序掃描並連接到外圍設備時,會在發現加密的GATT特徵時自動請求配對。如何以編程方式處理BLE外圍設備從iOS設備中刪除配對

如果iOS設備和BLE外圍設備每個都保持配對狀態,則一切正常。

但是,如何處理BLE外設在內部刪除所有綁定信息的情況,而不通知iOS設備它正在刪除配對密鑰?

iOS CoreBluetooth命令將會失敗。

有沒有什麼可以通過編程來解決這個問題?要麼重新請求配對,要麼取消配對iOS端?

的iOS是相當限制與藍牙 - 所以我不能看到太多了良好的解決方案,除了檢測時寫入失敗,並要求用戶手動取消配對(這是跛)

+0

您是對的,用戶需要從iOS的藍牙設置屏幕中刪除配對/綁定。沒有任何應用可以做。 – Paulw11

+0

@ Paulw11 Thannks。有沒有相關的文檔或例子?另外,CoreBluetooth是否會返回任何跡象表明這可能是這種情況? – SJoshi

+0

不幸的是沒有其他解決方案,只能委託用戶。我有同樣的問題,我找不到任何其他解決方案! – GeekRiky

回答

3

我終於能夠解決這個問題,事實證明,你甚至不需要解除配合!

我寫了我的經驗在這裏:

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 
相關問題