dash ble: ktLintFormat
This commit is contained in:
parent
5b10ad13ec
commit
210a446123
11 changed files with 40 additions and 25 deletions
|
@ -17,7 +17,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||||
import info.nightscout.androidaps.utils.extensions.toHex
|
import info.nightscout.androidaps.utils.extensions.toHex
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import java.nio.ByteBuffer
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
@ -85,7 +84,6 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun getStatus(): ConnectionStatus {
|
override fun getStatus(): ConnectionStatus {
|
||||||
// TODO is this used?
|
// TODO is this used?
|
||||||
var s: ConnectionStatus
|
var s: ConnectionStatus
|
||||||
|
|
|
@ -121,7 +121,7 @@ class BleCommCallbacks(
|
||||||
|
|
||||||
val insertResult = incomingPackets.byCharacteristicType(characteristicType).add(payload)
|
val insertResult = incomingPackets.byCharacteristicType(characteristicType).add(payload)
|
||||||
if (!insertResult) {
|
if (!insertResult) {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "Could not insert read data to the incoming queue: ${characteristicType}")
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Could not insert read data to the incoming queue: $characteristicType")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ class MessageIO(
|
||||||
maxMessageReadTries = joiner.fullFragments * 2 + 2
|
maxMessageReadTries = joiner.fullFragments * 2 + 2
|
||||||
for (i in 1 until joiner.fullFragments + 1) {
|
for (i in 1 until joiner.fullFragments + 1) {
|
||||||
expected++
|
expected++
|
||||||
val nackOnTimeout = !joiner.oneExtraPacket && i==joiner.fullFragments // last packet
|
val nackOnTimeout = !joiner.oneExtraPacket && i == joiner.fullFragments // last packet
|
||||||
val packet = expectBlePacket(expected, nackOnTimeout)
|
val packet = expectBlePacket(expected, nackOnTimeout)
|
||||||
if (packet !is PacketReceiveSuccess) {
|
if (packet !is PacketReceiveSuccess) {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "Error reading packet:$packet")
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Error reading packet:$packet")
|
||||||
|
@ -191,8 +191,11 @@ class MessageIO(
|
||||||
if (received == null || received.isEmpty()) {
|
if (received == null || received.isEmpty()) {
|
||||||
if (nackOnTimeout)
|
if (nackOnTimeout)
|
||||||
cmdBleIO.sendAndConfirmPacket(BleCommandNack(index).data)
|
cmdBleIO.sendAndConfirmPacket(BleCommandNack(index).data)
|
||||||
aapsLogger.info(LTag.PUMPBTCOMM, "Error reading index: $index. Received: $received. NackOnTimeout: " +
|
aapsLogger.info(
|
||||||
"$nackOnTimeout")
|
LTag.PUMPBTCOMM,
|
||||||
|
"Error reading index: $index. Received: $received. NackOnTimeout: " +
|
||||||
|
"$nackOnTimeout"
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (received[0] == index) {
|
if (received[0] == index) {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.bluetooth.BluetoothGatt
|
||||||
import android.bluetooth.BluetoothManager
|
import android.bluetooth.BluetoothManager
|
||||||
import android.bluetooth.BluetoothProfile
|
import android.bluetooth.BluetoothProfile
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.provider.ContactsContract
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig
|
||||||
|
@ -27,8 +26,11 @@ sealed class ConnectionState
|
||||||
object Connected : ConnectionState()
|
object Connected : ConnectionState()
|
||||||
object NotConnected : ConnectionState()
|
object NotConnected : ConnectionState()
|
||||||
|
|
||||||
class Connection(private val podDevice: BluetoothDevice, private val aapsLogger: AAPSLogger, context: Context)
|
class Connection(
|
||||||
: DisconnectHandler {
|
private val podDevice: BluetoothDevice,
|
||||||
|
private val aapsLogger: AAPSLogger,
|
||||||
|
context: Context
|
||||||
|
) : DisconnectHandler {
|
||||||
|
|
||||||
private val incomingPackets = IncomingPackets()
|
private val incomingPackets = IncomingPackets()
|
||||||
private val bleCommCallbacks = BleCommCallbacks(aapsLogger, incomingPackets, this)
|
private val bleCommCallbacks = BleCommCallbacks(aapsLogger, incomingPackets, this)
|
||||||
|
@ -36,6 +38,7 @@ class Connection(private val podDevice: BluetoothDevice, private val aapsLogger:
|
||||||
|
|
||||||
private val bluetoothManager: BluetoothManager =
|
private val bluetoothManager: BluetoothManager =
|
||||||
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
||||||
|
|
||||||
// The session is Synchronized because we can lose the connection right when establishing it
|
// The session is Synchronized because we can lose the connection right when establishing it
|
||||||
var session: Session? = null
|
var session: Session? = null
|
||||||
@Synchronized get
|
@Synchronized get
|
||||||
|
@ -138,6 +141,7 @@ class Connection(private val podDevice: BluetoothDevice, private val aapsLogger:
|
||||||
}
|
}
|
||||||
keys.synchronizedEapSqn
|
keys.synchronizedEapSqn
|
||||||
}
|
}
|
||||||
|
|
||||||
is SessionKeys -> {
|
is SessionKeys -> {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
aapsLogger.info(LTag.PUMPCOMM, "CK: ${keys.ck.toHex()}")
|
aapsLogger.info(LTag.PUMPCOMM, "CK: ${keys.ck.toHex()}")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session
|
||||||
|
|
||||||
interface DisconnectHandler {
|
interface DisconnectHandler {
|
||||||
|
|
||||||
fun onConnectionLost(status: Int)
|
fun onConnectionLost(status: Int)
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ data class EapAkaAttributeAuts(val payload: ByteArray) : EapAkaAttribute() {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun parse(payload: ByteArray): EapAkaAttribute {
|
fun parse(payload: ByteArray): EapAkaAttribute {
|
||||||
if (payload.size < SIZE-2) {
|
if (payload.size < SIZE - 2) {
|
||||||
throw MessageIOException("Could not parse AUTS attribute: ${payload.toHex()}")
|
throw MessageIOException("Could not parse AUTS attribute: ${payload.toHex()}")
|
||||||
}
|
}
|
||||||
return EapAkaAttributeAuts(payload)
|
return EapAkaAttributeAuts(payload)
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
|
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
class EapSqn(val value: ByteArray) {
|
class EapSqn(val value: ByteArray) {
|
||||||
constructor(v: Long): this(fromLong(v))
|
constructor(v: Long) : this(fromLong(v))
|
||||||
|
|
||||||
init {
|
init {
|
||||||
require(value.size == SIZE) {"Eap SQN is $SIZE bytes long"}
|
require(value.size == SIZE) { "Eap SQN is $SIZE bytes long" }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun increment(): EapSqn {
|
fun increment(): EapSqn {
|
||||||
|
@ -17,7 +16,7 @@ class EapSqn(val value: ByteArray) {
|
||||||
fun toLong(): Long {
|
fun toLong(): Long {
|
||||||
return ByteBuffer.wrap(
|
return ByteBuffer.wrap(
|
||||||
byteArrayOf(0x00, 0x00) +
|
byteArrayOf(0x00, 0x00) +
|
||||||
value
|
value
|
||||||
).long
|
).long
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,10 +25,10 @@ class EapSqn(val value: ByteArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val SIZE = 6
|
private const val SIZE = 6
|
||||||
private fun fromLong(v: Long): ByteArray {
|
private fun fromLong(v: Long): ByteArray {
|
||||||
return ByteBuffer.allocate(8).putLong(v).array().copyOfRange(2, 8)
|
return ByteBuffer.allocate(8).putLong(v).array().copyOfRange(2, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,11 @@ class Milenage(
|
||||||
init {
|
init {
|
||||||
require(k.size == KEY_SIZE) { "Milenage key has to be $KEY_SIZE bytes long. Received: ${k.toHex()}" }
|
require(k.size == KEY_SIZE) { "Milenage key has to be $KEY_SIZE bytes long. Received: ${k.toHex()}" }
|
||||||
require(sqn.size == SQN) { "Milenage SQN has to be $SQN long. Received: ${sqn.toHex()}" }
|
require(sqn.size == SQN) { "Milenage SQN has to be $SQN long. Received: ${sqn.toHex()}" }
|
||||||
require(auts.size == AUTS_SIZE) { "Milenage AUTS has to be $AUTS_SIZE long. Received: ${auts.toHex()}"}
|
require(auts.size == AUTS_SIZE) { "Milenage AUTS has to be $AUTS_SIZE long. Received: ${auts.toHex()}" }
|
||||||
require(amf.size == MILENAGE_AMF.size) { "Milenage AMF has to be ${MILENAGE_AMF.size} long." +
|
require(amf.size == MILENAGE_AMF.size) {
|
||||||
"Received: ${amf.toHex()}"}
|
"Milenage AMF has to be ${MILENAGE_AMF.size} long." +
|
||||||
|
"Received: ${amf.toHex()}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val secretKeySpec = SecretKeySpec(k, "AES")
|
private val secretKeySpec = SecretKeySpec(k, "AES")
|
||||||
|
@ -84,12 +86,14 @@ class Milenage(
|
||||||
|
|
||||||
// Used for re-synchronisation AUTS = SQN^AK || MAC-S
|
// Used for re-synchronisation AUTS = SQN^AK || MAC-S
|
||||||
private val akStarInput = ByteArray(KEY_SIZE)
|
private val akStarInput = ByteArray(KEY_SIZE)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (i in 0..15) {
|
for (i in 0..15) {
|
||||||
akStarInput[(i + 4) % 16] = randOpcEncryptedXorOpc[i]
|
akStarInput[(i + 4) % 16] = randOpcEncryptedXorOpc[i]
|
||||||
}
|
}
|
||||||
akStarInput[15] = (akStarInput[15].toInt() xor 8).toByte()
|
akStarInput[15] = (akStarInput[15].toInt() xor 8).toByte()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val akStarFull = cipher.doFinal(akStarInput) xor opc
|
private val akStarFull = cipher.doFinal(akStarInput) xor opc
|
||||||
private val akStar = akStarFull.copyOfRange(0, 6)
|
private val akStar = akStarFull.copyOfRange(0, 6)
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ class SessionEstablisher(
|
||||||
if (eapMsg.attributes.size == 1 && eapMsg.attributes[0] is EapAkaAttributeClientErrorCode) {
|
if (eapMsg.attributes.size == 1 && eapMsg.attributes[0] is EapAkaAttributeClientErrorCode) {
|
||||||
throw SessionEstablishmentException(
|
throw SessionEstablishmentException(
|
||||||
"Received CLIENT_ERROR_CODE for EAP-AKA challenge: ${
|
"Received CLIENT_ERROR_CODE for EAP-AKA challenge: ${
|
||||||
eapMsg.attributes[0].toByteArray().toHex()
|
eapMsg.attributes[0].toByteArray().toHex()
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,18 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.endecryp
|
||||||
|
|
||||||
sealed class SessionNegotiationResponse
|
sealed class SessionNegotiationResponse
|
||||||
|
|
||||||
data class SessionKeys(val ck: ByteArray, val nonce: Nonce, var msgSequenceNumber: Byte):SessionNegotiationResponse() {
|
data class SessionKeys(
|
||||||
|
val ck: ByteArray,
|
||||||
|
val nonce: Nonce,
|
||||||
|
var msgSequenceNumber: Byte
|
||||||
|
) : SessionNegotiationResponse() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
require(ck.size == 16) { "CK has to be 16 bytes long" }
|
require(ck.size == 16) { "CK has to be 16 bytes long" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class SessionNegotiationResynchronization(val synchronizedEapSqn: EapSqn, val msgSequenceNumber: Byte)
|
data class SessionNegotiationResynchronization(
|
||||||
: SessionNegotiationResponse()
|
val synchronizedEapSqn: EapSqn,
|
||||||
|
val msgSequenceNumber: Byte
|
||||||
|
) : SessionNegotiationResponse()
|
||||||
|
|
|
@ -16,7 +16,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.nio.ByteBuffer
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
Loading…
Reference in a new issue