Commit graph

225 commits

Author SHA1 Message Date
Bart Sopers 1872e1ceb7 Correctly handle NAK response for Omnipod Dash 2021-03-14 21:45:52 +01:00
Bart Sopers 10c316edd9 Omnipod Dash: provide and verify expected response type 2021-03-14 21:25:15 +01:00
Andrei Vereha 442a0b274f dash ble: add comment about why I think the NACK logic is not ok 2021-03-14 21:21:47 +01:00
Andrei Vereha 109f66a48d dash ble: start implementing retries
Handle NACKs for now.
2021-03-14 21:21:47 +01:00
AdrianLxM 95d7f0737c fix gitignore and tests 2021-03-14 21:19:24 +01:00
Bart Sopers aff38851e1 Add Omnipod Dash response parsing 2021-03-14 20:14:11 +01:00
AdrianLxM 7db5c28632 delint 2021-03-14 19:52:08 +01:00
AdrianLxM bf3fe19a4e only open for tests/debug 2021-03-14 19:42:02 +01:00
AdrianLxM 3d93e4d84d mock provider instead of constructor parameter 2021-03-14 18:24:15 +01:00
Andrei Vereha b33c55273c dash ble: fix detekt issues 2021-03-14 16:14:00 +01:00
Andrei Vereha b71f065974 dash ble tests: ktlintFormat 2021-03-14 16:00:59 +01:00
Andrei Vereha a94d6ce652 dash ble test: remove fixed TODO 2021-03-14 15:59:36 +01:00
Andrei Vereha 379c0cd8c7 dash bke tests: fix decrypt test
We were trying to use an encryption NONCE for decryption.
The fix was to replac data with data from logs.
2021-03-14 15:58:12 +01:00
Andrei Vereha 752f393f3b dash ble: add test for MessagePacket 2021-03-14 15:57:16 +01:00
Andrei Vereha eff6247f77 dash ble: remove unused class 2021-03-14 15:57:16 +01:00
Andrei Vereha eda52857e5 dash ble: add tests for StringLengthPrefixEncodingTest
We tested this part with a real pod and confirmed that it's working
2021-03-14 15:57:16 +01:00
Andrei Vereha 5f71e1b27f dash ble: add tests for payload splitting and joining 2021-03-14 15:57:16 +01:00
Andrei Vereha 50d1dad786 dash LTK: add test
Now that we know this part is working, I'm adding a test with data from
logs
Moved the key exchange logic to its own class so it is easier to
test
2021-03-14 15:44:28 +01:00
Andrei Vereha 27daa4554a
Merge pull request #22 from 0pen-dash/andrei/detekt-max-issues
dash detekt: set maxIssues to -1
2021-03-14 15:42:03 +01:00
Andrei Vereha 0396b9ca99 dash ble: use .let(Id::fromLong)
https://github.com/0pen-dash/AndroidAPS/pull/21#pullrequestreview-610227073
2021-03-11 23:06:00 +01:00
Andrei Vereha a1f8cf807d dash detekt: set maxIssues to -1
I noticed that with this setting I can detekt from android-studio and
see all the issues reported in the Build Output.

Without it, I can only see: "Build failed with X issues."
2021-03-11 21:43:25 +01:00
Andrei Vereha 27e9b25e86 dash: update TODO comment 2021-03-11 21:40:51 +01:00
Andrei Vereha 1a678a9507 dash/ble: stop reading a message on send
We were receiving a message in that case just because we used the `eqos`
parameter incorrectly.
2021-03-11 21:36:43 +01:00
Andrei Vereha 2aed2005ef dash ble: renames and fixes after testing 2021-03-11 21:27:18 +01:00
Andrei Vereha 8154e16c94 dash ble: add a separate method for activating a new pod
So we can call it explicitly instead of activating a new pod on
connect()
2021-03-09 23:19:22 +01:00
Andrei Vereha c337b52aa0 dash/ble: support both 1 and 2 byte command
It seems that the PDM is sending 1 byte commands and the POD answers
with 2 byte commands.

Add logging for decrypted responses.

I think `eqos` means that we are expecting an ACK for the last message.
Read (and log for now) a pending message if the POD is trying to sending it back while we want
to send a command.
2021-03-08 22:52:04 +01:00
Andrei Vereha db51b762ca dash ble: disconnect on errors 2021-03-08 22:52:04 +01:00
Andrei Vereha 64aa05f7f9 dash en/decrypt test: add comment about failing test 2021-03-08 22:52:04 +01:00
Andrei Vereha 923d8d33ef dash eap: bugfix
Shift the MSB of the lenght by 1 byte, not one bit.
2021-03-08 22:52:04 +01:00
Andrei Vereha 7dd8fc1bf6 dash/ble: ktlintFormat 2021-03-08 22:52:04 +01:00
Andrei Vereha e7a9e24093 dash: start using podState for BLE
implement disconnect()
various fixes after testing with a real pod(cmd is 2 bytes, message
joining, etc)
2021-03-08 22:52:04 +01:00
Andrei Vereha 4046828567 format: ktlint 2021-03-08 22:52:04 +01:00
Andrei Vereha c71433ad1a format: remove trailing commao 2021-03-08 22:52:04 +01:00
Andrei Vereha 5211d4ddc6 dash ble: implement sessions and sending commands
Tested with the fake pod:
```
DEBU[0185] got command. CRC: 82b2. Type: 7 :: GET_VERSION
DEBU[0185] got command. CRC: 0003. Type: 3 :: SET_UNIQUE_ID
DEBU[0186] got command. CRC: 019a. Type: 19 :: PROGRAM_ALERTS
DEBU[0186] got command. CRC: 0385. Type: 19 :: PROGRAM_ALERTS
DEBU[0187] got command. CRC: 81f3. Type: 1a :: PROGRAM_INSULIN
DEBU[0187] got command. CRC: 8178. Type: e :: GET_STATUS
```
2021-03-08 22:52:04 +01:00
Andrei Vereha 5647007190 dash/ble: remove retries for connect for now
It's easier to debug for now if we stop on the first issue/error
2021-03-08 22:52:04 +01:00
Andrei Vereha 9c586c4942 dash encryption: add encryption and decryption for messsages 2021-03-08 22:52:04 +01:00
Andrei Vereha c2627176cf dash BleIO: s/let/also 2021-03-03 17:07:18 +01:00
Andrei Vereha 7976df596e dash eap-aka: use named parameters 2021-03-03 17:02:59 +01:00
Andrei Vereha c3d7cf9483 dash LTK exchange: s/var/val 2021-03-03 17:02:12 +01:00
Andrei Vereha 7c0e2af053 dash: rename EAP AKA to SessionEstablisher 2021-03-03 14:24:23 +01:00
Andrei Vereha b2797fa57f dash: undo ktLint 2021-03-03 14:22:09 +01:00
Andrei Vereha da84c35b31 format: CTRL+Alt+L 2021-03-03 14:18:20 +01:00
Andrei Vereha 154e74fc22 dash ble: fix detekt issues 2021-03-03 14:10:33 +01:00
Andrei Vereha c9beb21404 format: klintFormat 2021-03-02 22:22:03 +01:00
Andrei Vereha ada3560f49 format: remove trailing commas 2021-03-02 22:20:30 +01:00
Andrei Vereha e90bda0234 dash eap-aka: complete the session key exchange
Fake pod logs
```
INFO[0021] got CK: daff384a4098571975d136a480a71b36
INFO[0021] got Nonce: 33a0c6dd0a0a0a0a
```

The application logs:
```
[OmnipodDashBleManagerImpl$connect$1.subscribe():139]: CK: daff384a4098571975d136a480a71b36
 [OmnipodDashBleManagerImpl$connect$1.subscribe():140]: noncePrefix: 33a0c6dd0a0a0a0a
```
2021-03-02 22:17:11 +01:00
Andrei Vereha 9c42e5749f ble/milenage: fix and add tests 2021-03-02 18:39:03 +01:00
Andrei Vereha 099ec0a328 ble scan: improve log message 2021-03-02 18:37:45 +01:00
Andrei Vereha b6692a5ac6 WIP: add Milenage
AUTN is not correct yet
2021-03-02 10:44:36 +01:00
Andrei Vereha e82826bf5a dash/ble: start implement EAP-AKA 2021-03-01 15:22:52 +01:00
Andrei Vereha 0523f7c17c format: remove trailing commas 2021-03-01 15:20:02 +01:00
AdrianLxM 89ff502518 a bit more formatting 2021-03-01 14:35:50 +01:00
AdrianLxM 5ef07dd0be detekt resolve a few more 2021-03-01 13:52:43 +01:00
AdrianLxM e7b3d85639 detekt resolve a few 2021-03-01 13:49:39 +01:00
AdrianLxM 77c816e813 ktlint format 2021-03-01 13:39:02 +01:00
AdrianLxM 9a6a81248d Merge remote-tracking branch 'origin/bart/implement-managers' into adrian/linting 2021-03-01 12:40:42 +01:00
AdrianLxM 070ba1cfc2 add ktlint and detekt 2021-03-01 12:34:47 +01:00
Bart Sopers 59bfa7a04d Implement Pod activation command flow 2021-03-01 01:23:40 +01:00
Bart Sopers 82d2f9ae36 Merge branch 'dash' into bart/improvements 2021-02-28 21:10:09 +01:00
Andrei Vereha c8bded99ab remove tailing comma 2021-02-28 19:45:21 +01:00
Andrei Vereha a7ca5fd863 format code: Ctrl+Alt+L 2021-02-28 19:44:10 +01:00
Bart Sopers 8e7b1d3612 Review: use fold in AlertUtil.encodeAlerts 2021-02-28 19:28:52 +01:00
Andrei Vereha 57c2d2d9a1 Address review comments:
- move think dependency to core_dependencies and make it's version
   configurable: https://github.com/0pen-dash/AndroidAPS/pull/10#discussion_r584329468
 - add message string to exceptions. Renames
2021-02-28 19:11:42 +01:00
Bart Sopers 8e7e2450ae Update active alerts from default status response in Pod state 2021-02-28 18:46:49 +01:00
Bart Sopers bf060da878 Fix typo 2021-02-28 18:42:17 +01:00
Andrei Vereha b1f099c506 rename LTK to Pair 2021-02-28 18:38:43 +01:00
Andrei Vereha ee0ac46c5a Finish implementing the LTK exchange
On the fake pod:
```
INFO[0067] LTK 21f4a9d825ce5e57bad5b4958c6ff95e
```
Logcat:
```
2021-02-28 18:21:04.763 19530-22490/info.nightscout.androidaps I/PUMPCOMM: [AsyncTask #4]: [OmnipodDashBleManagerImpl.connect():86]: Got LTK: 21f4a9d825ce5e57bad5b4958c6ff95e
``
2021-02-28 18:37:36 +01:00
Andrei Vereha ddb1c18349 ble ltk: implement encryption and message parsing 2021-02-28 18:33:07 +01:00
Andrei Vereha ddfbd2e7bd dash ble tlk: start generating keys 2021-02-28 18:33:07 +01:00
Andrei Vereha 39408ac535 BLE LTK: define all the steps 2021-02-28 18:33:07 +01:00
Andrei Vereha 1aa6d02893 ble: implement message reading&joining
Now are able to read the first message:
```
INFO[0005] Received SPS1  6b943ec06b594f8a0383f384a3c916da75e1c7846c3e1b73f72f86ee2dc48774b2b4e5ad62d798b76cfd06be1cd4c937
DEBU[0005] Donna LTK: b874cb3cbe487040442138452faeb02d284ac55f489f19593265ff52f7310f1f
DEBU[0005] First key 58cb3b742dc48774000000001cd4c937 :: 16
DEBU[0005] CMACY: 16
DEBU[0005] Intermediar key 4c13eebc4cf09795a07c50bf13786c18 :: 16
DEBU[0005] Pod public 2fe57da347cd62431528daac5fbb290730fff684afc4cfc2ed90995f58cb3b74 :: 32
DEBU[0005] Pod nonce 00000000000000000000000000000000 :: 16
DEBU[0005] Generated SPS1: 535053313d00302fe57da347cd62431528daac5fbb290730fff684afc4cfc2ed90995f58cb3b7400000000000000000000000000000000
TRAC[0005] CMD notification return: 4/00
TRAC[0005] received CMD:  01
TRAC[0005] Sending message: 54570003000006e00000109100001092535053313d00302fe57da347cd62431528daac5fbb290730fff684afc4cfc2ed90995f58cb3b7400000000000000000000000000000000
TRAC[0005] DATA notification return: 23/000354570003000006e000001091000010925350
TRAC[0005] DATA notification return: 23/0153313d00302fe57da347cd62431528daac5fbb
TRAC[0005] DATA notification return: 23/02290730fff684afc4cfc2ed90995f58cb3b7400
TRAC[0005] DATA notification return: 23/030f7d02931d0000000000000000000000000000
TRAC[0005] DATA notification return: 23/0401000000000000000000000000000000000000
TRAC[0005] received CMD:  04
```
2021-02-28 18:33:05 +01:00
Andrei Vereha 81ad52ebce implement SPS1 command
I had to add a new dependency: `tink-android:1.5.0` for X25519
2021-02-28 18:32:21 +01:00
Andrei Vereha 11633995f6
Merge pull request #11 from 0pen-dash/bart/observable-connect
Make OmnipodDashBleManager.connect() return an Observable of PodEvents
2021-02-28 18:30:06 +01:00
Bart Sopers c93705e88f Add retry for connecting to Pod 2021-02-28 18:22:56 +01:00
Bart Sopers 256cfe077d Replace single booleans for alerts with EnumSet of AlertType and introduce sealed class AlertTrigger 2021-02-28 18:20:17 +01:00
Bart Sopers 5c8ba98682 Remove TODO 2021-02-28 15:30:12 +01:00
Bart Sopers aa14843d33 Address review findings 2021-02-28 15:18:10 +01:00
AdrianLxM 76756fabaa a bit more readable 2021-02-28 14:18:17 +01:00
AdrianLxM 6dce871ed4 fix database 2021-02-28 03:55:01 +01:00
AdrianLxM 2d0d38f70f database integration test working 2021-02-28 03:30:13 +01:00
Bart Sopers 634b9c20e7 Add interceptors for PodEvents and errors 2021-02-28 00:42:32 +01:00
Bart Sopers 8d629977ec Improvement 2021-02-27 23:52:06 +01:00
AdrianLxM 86d965a7f1 initial history database 2021-02-27 23:50:51 +01:00
Bart Sopers 7e5667705d Minor improvement 2021-02-27 23:46:57 +01:00
Bart Sopers d08a979da3 Make OmnipodDashManager.connect() return an Observable of PodEvents 2021-02-27 23:21:09 +01:00
Andrei Vereha 5ca622a923 Merge branch 'dash-bart-random' into ble-message 2021-02-27 18:45:01 +01:00
Andrei Vereha 899a3d4213 Merge branch 'dash-bart-random' into ble-message 2021-02-27 18:35:14 +01:00
Bart Sopers dcf7672a24 More cleanup after conversion 2021-02-27 00:39:55 +01:00
Bart Sopers ba65a47380 Merge branch 'dash-bart-random' into adrian/something 2021-02-26 22:12:39 +01:00
Bart Sopers 0a013b6d2b Serializable instead of Any for data in PodEvent 2021-02-26 22:10:25 +01:00
AdrianLxM ae30387a25 cleanups 2021-02-26 21:45:17 +01:00
Andrei Vereha fb7a84bdf7 ble: add meaninful constants in the PayloadSplitter and getPodId 2021-02-26 21:30:29 +01:00
Andrei Vereha 358748654e ble: reformat(Ctrl+Alt+L) 2021-02-26 18:30:59 +01:00
Bart Sopers dbff1c6e50 Add Profile to BasalProgram mapper function, add some preliminary code in OmnipodDashManagerImpl 2021-02-26 17:38:45 +01:00
Andrei Vereha 9170cc6f76 move the test code to "connect"
this is wrong, for now I just need an easy way to test the initial handshake
2021-02-26 17:06:03 +01:00
Andrei Vereha 4664d21ddf format, cleanups 2021-02-26 17:01:53 +01:00
Andrei Vereha badf8fe24d ble: sending the first SP1/SP2 pairing command
from the fake pod logs
```
INFO[0007] Received SP1 SP2 payload 5350313d0004000010912c5350323d000bffc32dbd08030e0100008a
TRAC[0007] Read field: SP1= :: 00001091 :: 4
TRAC[0007] Read field: ,SP2= :: ffc32dbd08030e0100008a :: 11
INFO[0007] Received SP1 SP2: 00001091 :: ffc32dbd08030e0100008a
```
2021-02-26 17:01:53 +01:00
Andrei Vereha 318c0c642c WIP: sp1sp2 2021-02-26 17:01:53 +01:00
Andrei Vereha 4e6ad3f113 add comments with the LTK steps 2021-02-26 17:01:53 +01:00
Andrei Vereha 1661d978d0 mark not implemented yet functions 2021-02-26 17:01:53 +01:00