dash ble: ktLintFormat

This commit is contained in:
Andrei Vereha 2021-04-04 12:43:17 +02:00
parent 5b10ad13ec
commit 210a446123
11 changed files with 40 additions and 25 deletions

View file

@ -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.utils.extensions.toHex
import io.reactivex.Observable
import java.nio.ByteBuffer
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject
import javax.inject.Singleton
@ -85,7 +84,6 @@ class OmnipodDashBleManagerImpl @Inject constructor(
}
}
override fun getStatus(): ConnectionStatus {
// TODO is this used?
var s: ConnectionStatus

View file

@ -121,7 +121,7 @@ class BleCommCallbacks(
val insertResult = incomingPackets.byCharacteristicType(characteristicType).add(payload)
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")
}
}

View file

@ -107,7 +107,7 @@ class MessageIO(
maxMessageReadTries = joiner.fullFragments * 2 + 2
for (i in 1 until joiner.fullFragments + 1) {
expected++
val nackOnTimeout = !joiner.oneExtraPacket && i==joiner.fullFragments // last packet
val nackOnTimeout = !joiner.oneExtraPacket && i == joiner.fullFragments // last packet
val packet = expectBlePacket(expected, nackOnTimeout)
if (packet !is PacketReceiveSuccess) {
aapsLogger.warn(LTag.PUMPBTCOMM, "Error reading packet:$packet")
@ -191,8 +191,11 @@ class MessageIO(
if (received == null || received.isEmpty()) {
if (nackOnTimeout)
cmdBleIO.sendAndConfirmPacket(BleCommandNack(index).data)
aapsLogger.info(LTag.PUMPBTCOMM, "Error reading index: $index. Received: $received. NackOnTimeout: " +
"$nackOnTimeout")
aapsLogger.info(
LTag.PUMPBTCOMM,
"Error reading index: $index. Received: $received. NackOnTimeout: " +
"$nackOnTimeout"
)
continue
}
if (received[0] == index) {

View file

@ -5,7 +5,6 @@ import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothManager
import android.bluetooth.BluetoothProfile
import android.content.Context
import android.provider.ContactsContract
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig
@ -27,8 +26,11 @@ sealed class ConnectionState
object Connected : ConnectionState()
object NotConnected : ConnectionState()
class Connection(private val podDevice: BluetoothDevice, private val aapsLogger: AAPSLogger, context: Context)
: DisconnectHandler {
class Connection(
private val podDevice: BluetoothDevice,
private val aapsLogger: AAPSLogger,
context: Context
) : DisconnectHandler {
private val incomingPackets = IncomingPackets()
private val bleCommCallbacks = BleCommCallbacks(aapsLogger, incomingPackets, this)
@ -36,6 +38,7 @@ class Connection(private val podDevice: BluetoothDevice, private val aapsLogger:
private val bluetoothManager: BluetoothManager =
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
// The session is Synchronized because we can lose the connection right when establishing it
var session: Session? = null
@Synchronized get
@ -138,6 +141,7 @@ class Connection(private val podDevice: BluetoothDevice, private val aapsLogger:
}
keys.synchronizedEapSqn
}
is SessionKeys -> {
if (BuildConfig.DEBUG) {
aapsLogger.info(LTag.PUMPCOMM, "CK: ${keys.ck.toHex()}")

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session
interface DisconnectHandler {
fun onConnectionLost(status: Int)
}
}

View file

@ -128,7 +128,7 @@ data class EapAkaAttributeAuts(val payload: ByteArray) : EapAkaAttribute() {
companion object {
fun parse(payload: ByteArray): EapAkaAttribute {
if (payload.size < SIZE-2) {
if (payload.size < SIZE - 2) {
throw MessageIOException("Could not parse AUTS attribute: ${payload.toHex()}")
}
return EapAkaAttributeAuts(payload)

View file

@ -1,13 +1,12 @@
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
class EapSqn(val value: ByteArray) {
constructor(v: Long): this(fromLong(v))
constructor(v: Long) : this(fromLong(v))
init {
require(value.size == SIZE) {"Eap SQN is $SIZE bytes long"}
require(value.size == SIZE) { "Eap SQN is $SIZE bytes long" }
}
fun increment(): EapSqn {
@ -17,7 +16,7 @@ class EapSqn(val value: ByteArray) {
fun toLong(): Long {
return ByteBuffer.wrap(
byteArrayOf(0x00, 0x00) +
value
value
).long
}
@ -26,10 +25,10 @@ class EapSqn(val value: ByteArray) {
}
companion object {
private const val SIZE = 6
private fun fromLong(v: Long): ByteArray {
return ByteBuffer.allocate(8).putLong(v).array().copyOfRange(2, 8)
}
}
}
}

View file

@ -20,9 +20,11 @@ class Milenage(
init {
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(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." +
"Received: ${amf.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." +
"Received: ${amf.toHex()}"
}
}
private val secretKeySpec = SecretKeySpec(k, "AES")
@ -84,12 +86,14 @@ class Milenage(
// Used for re-synchronisation AUTS = SQN^AK || MAC-S
private val akStarInput = ByteArray(KEY_SIZE)
init {
for (i in 0..15) {
akStarInput[(i + 4) % 16] = randOpcEncryptedXorOpc[i]
}
akStarInput[15] = (akStarInput[15].toInt() xor 8).toByte()
}
private val akStarFull = cipher.doFinal(akStarInput) xor opc
private val akStar = akStarFull.copyOfRange(0, 6)

View file

@ -137,7 +137,7 @@ class SessionEstablisher(
if (eapMsg.attributes.size == 1 && eapMsg.attributes[0] is EapAkaAttributeClientErrorCode) {
throw SessionEstablishmentException(
"Received CLIENT_ERROR_CODE for EAP-AKA challenge: ${
eapMsg.attributes[0].toByteArray().toHex()
eapMsg.attributes[0].toByteArray().toHex()
}"
)
}

View file

@ -4,11 +4,18 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.endecryp
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 {
require(ck.size == 16) { "CK has to be 16 bytes long" }
}
}
data class SessionNegotiationResynchronization(val synchronizedEapSqn: EapSqn, val msgSequenceNumber: Byte)
: SessionNegotiationResponse()
data class SessionNegotiationResynchronization(
val synchronizedEapSqn: EapSqn,
val msgSequenceNumber: Byte
) : SessionNegotiationResponse()

View file

@ -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.utils.sharedPreferences.SP
import java.io.Serializable
import java.nio.ByteBuffer
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton