Verify the message address before accepting
This commit is contained in:
parent
b8f2fdc7a8
commit
5d25e39dd1
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
|
|||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.OmnipodAction;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalResponseException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageSequenceNumberException;
|
||||
|
@ -218,6 +219,9 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
|
|||
while (receivedMessage == null) {
|
||||
try {
|
||||
receivedMessage = OmnipodMessage.decodeMessage(receivedMessageData);
|
||||
if(receivedMessage.getAddress() != message.getAddress()) {
|
||||
throw new IllegalMessageAddressException(message.getAddress(), receivedMessage.getAddress());
|
||||
}
|
||||
if (receivedMessage.getSequenceNumber() != podState.getMessageNumber()) {
|
||||
throw new IllegalMessageSequenceNumberException(podState.getMessageNumber(), receivedMessage.getSequenceNumber());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.comm.exception;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
|
||||
|
||||
public class IllegalMessageAddressException extends OmnipodException {
|
||||
private final int expected;
|
||||
private final int actual;
|
||||
|
||||
public IllegalMessageAddressException(int expected, int actual) {
|
||||
super("Invalid message address. Expected="+ expected +", actual="+ actual, false);
|
||||
this.expected = expected;
|
||||
this.actual = actual;
|
||||
}
|
||||
|
||||
public int getExpected() {
|
||||
return expected;
|
||||
}
|
||||
|
||||
public int getActual() {
|
||||
return actual;
|
||||
}
|
||||
}
|
|
@ -97,6 +97,10 @@ public class OmnipodMessage {
|
|||
}
|
||||
}
|
||||
|
||||
public int getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public List<MessageBlock> getMessageBlocks() {
|
||||
return messageBlocks;
|
||||
}
|
||||
|
@ -135,7 +139,6 @@ public class OmnipodMessage {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OmnipodMessage{" +
|
||||
|
|
|
@ -37,6 +37,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageSequenceNumberException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
|
||||
|
@ -615,6 +616,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
comment = getStringResource(R.string.omnipod_driver_error_invalid_response);
|
||||
} else if (ex instanceof IllegalMessageSequenceNumberException) {
|
||||
comment = getStringResource(R.string.omnipod_driver_error_invalid_message_sequence_number);
|
||||
} else if (ex instanceof IllegalMessageAddressException) {
|
||||
comment = getStringResource(R.string.omnipod_driver_error_invalid_message_address);
|
||||
} else if (ex instanceof MessageDecodingException) {
|
||||
comment = getStringResource(R.string.omnipod_driver_error_message_decoding_failed);
|
||||
} else if (ex instanceof NonceOutOfSyncException) {
|
||||
|
|
|
@ -1757,6 +1757,7 @@
|
|||
<string name="omnipod_driver_error_invalid_progress_state">Communication failed: the Pod is in a wrong state.</string>
|
||||
<string name="omnipod_driver_error_invalid_response">Communication failed: received an invalid response from the Pod.</string>
|
||||
<string name="omnipod_driver_error_invalid_message_sequence_number">Communication failed: received a message with an invalid sequence number from the Pod.</string>
|
||||
<string name="omnipod_driver_error_invalid_message_address">Communication failed: received a message with an invalid address from the Pod.</string>
|
||||
<string name="omnipod_driver_error_message_decoding_failed">Communication failed: failed to decode message from the Pod.</string>
|
||||
<string name="omnipod_driver_error_nonce_resync_failed">Communication failed: nonce resync failed.</string>
|
||||
<string name="omnipod_driver_error_nonce_out_of_sync">Communication failed: nonce out of sync.</string>
|
||||
|
|
Loading…
Reference in a new issue