better check for RS v3 failed encryption

This commit is contained in:
Milos Kozak 2020-08-11 00:21:03 +02:00
parent 4bacfad0db
commit 272f91d90b
2 changed files with 16 additions and 14 deletions

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.danars.activities.EnterPinActivity
import info.nightscout.androidaps.danars.activities.PairingHelperActivity import info.nightscout.androidaps.danars.activities.PairingHelperActivity
import info.nightscout.androidaps.danars.comm.DanaRSMessageHashTable import info.nightscout.androidaps.danars.comm.DanaRSMessageHashTable
import info.nightscout.androidaps.danars.comm.DanaRS_Packet import info.nightscout.androidaps.danars.comm.DanaRS_Packet
import info.nightscout.androidaps.danars.comm.DanaRS_Packet_Etc_Keep_Connection
import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.androidaps.danars.encryption.BleEncryption
import info.nightscout.androidaps.danars.events.EventDanaRSPairingSuccess import info.nightscout.androidaps.danars.events.EventDanaRSPairingSuccess
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
@ -131,6 +132,7 @@ class BLEComm @Inject internal constructor(
if (!encryptedDataRead && encryptedCommandSent && v3Encryption) { if (!encryptedDataRead && encryptedCommandSent && v3Encryption) {
// there was no response from pump after started encryption // there was no response from pump after started encryption
// assume pairing keys are invalid // assume pairing keys are invalid
aapsLogger.error("Clearing pairing keys !!!")
sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName)
sp.remove(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName)
sp.remove(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName)
@ -705,6 +707,9 @@ class BLEComm @Inject internal constructor(
aapsLogger.warn(LTag.PUMPBTCOMM, "Reply not received " + message.friendlyName) aapsLogger.warn(LTag.PUMPBTCOMM, "Reply not received " + message.friendlyName)
message.handleMessageNotReceived() message.handleMessageNotReceived()
} }
// verify encryption for v3
if (message is DanaRS_Packet_Etc_Keep_Connection)
if (!message.isReceived) disconnect("KeepAlive not received")
} }
// process common packet response // process common packet response

View file

@ -116,19 +116,17 @@ class DanaRSService : DaggerService() {
try { try {
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
val pump = activePlugin.activePump val pump = activePlugin.activePump
if (danaPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized) { rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings)))
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))) sendMessage(DanaRS_Packet_Etc_Keep_Connection(injector)) // test encryption for v3
sendMessage(DanaRS_Packet_General_Get_Shipping_Information(injector)) // serial no sendMessage(DanaRS_Packet_General_Get_Shipping_Information(injector)) // serial no
sendMessage(DanaRS_Packet_General_Get_Pump_Check(injector)) // firmware sendMessage(DanaRS_Packet_General_Get_Pump_Check(injector)) // firmware
sendMessage(DanaRS_Packet_Basal_Get_Profile_Number(injector)) sendMessage(DanaRS_Packet_Basal_Get_Profile_Number(injector))
sendMessage(DanaRS_Packet_Bolus_Get_Bolus_Option(injector)) // isExtendedEnabled sendMessage(DanaRS_Packet_Bolus_Get_Bolus_Option(injector)) // isExtendedEnabled
sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(injector)) // basal profile, basalStep, maxBasal sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(injector)) // basal profile, basalStep, maxBasal
sendMessage(DanaRS_Packet_Bolus_Get_Calculation_Information(injector)) // target sendMessage(DanaRS_Packet_Bolus_Get_Calculation_Information(injector)) // target
if (danaPump.profile24) sendMessage(DanaRS_Packet_Bolus_Get_24_CIR_CF_Array(injector)) if (danaPump.profile24) sendMessage(DanaRS_Packet_Bolus_Get_24_CIR_CF_Array(injector))
else sendMessage(DanaRS_Packet_Bolus_Get_CIR_CF_Array(injector)) else sendMessage(DanaRS_Packet_Bolus_Get_CIR_CF_Array(injector))
sendMessage(DanaRS_Packet_Option_Get_User_Option(injector)) // Getting user options sendMessage(DanaRS_Packet_Option_Get_User_Option(injector)) // Getting user options
danaPump.lastSettingsRead = now
}
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus)))
sendMessage(DanaRS_Packet_General_Initial_Screen_Information(injector)) sendMessage(DanaRS_Packet_General_Initial_Screen_Information(injector))
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus)))
@ -414,7 +412,6 @@ class DanaRSService : DaggerService() {
sendMessage(msgSet) sendMessage(msgSet)
val msgActivate = DanaRS_Packet_Basal_Set_Profile_Number(injector, 0) val msgActivate = DanaRS_Packet_Basal_Set_Profile_Number(injector, 0)
sendMessage(msgActivate) sendMessage(msgActivate)
danaPump.lastSettingsRead = 0 // force read full settings
readPumpStatus() readPumpStatus()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return true