summaryrefslogtreecommitdiffstats
path: root/lib/edi/ETIDecoder.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-12-26 22:20:35 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-12-26 22:20:35 +0100
commit37f5c2d4654580aa9d1195490d4a911b9b079acb (patch)
tree8cd76a87fe430eb0959f759ff7894c6667aa4016 /lib/edi/ETIDecoder.cpp
parentfd6d695275f88e83ebba6fa39afc044e329a690f (diff)
downloaddabmod-37f5c2d4654580aa9d1195490d4a911b9b079acb.tar.gz
dabmod-37f5c2d4654580aa9d1195490d4a911b9b079acb.tar.bz2
dabmod-37f5c2d4654580aa9d1195490d4a911b9b079acb.zip
EDI: Handle RFU bits and add some sanity checks
Diffstat (limited to 'lib/edi/ETIDecoder.cpp')
-rw-r--r--lib/edi/ETIDecoder.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/edi/ETIDecoder.cpp b/lib/edi/ETIDecoder.cpp
index 36e49fa..c79054b 100644
--- a/lib/edi/ETIDecoder.cpp
+++ b/lib/edi/ETIDecoder.cpp
@@ -154,9 +154,18 @@ decode_state_t ETIDecoder::decode_afpacket(
// read length from packet
uint32_t taglength = read_32b(input_data.begin() + 2);
uint16_t seq = read_16b(input_data.begin() + 6);
+ if (m_last_seq + 1 != seq) {
+ etiLog.level(warn) << "EDI AF Packet sequence error";
+ }
+ m_last_seq = seq;
bool has_crc = (input_data[8] & 0x80) ? true : false;
- uint8_t revision = input_data[8] & 0x7F;
+ uint8_t major_revision = (input_data[8] & 0x70) >> 4;
+ uint8_t minor_revision = input_data[8] & 0x0F;
+ if (major_revision != 1 or minor_revision != 0) {
+ throw invalid_argument("EDI AF Packet has wrong revision " +
+ to_string(major_revision) + "." + to_string(minor_revision));
+ }
uint8_t pt = input_data[9];
if (pt != 'T') {
// only support Tag
@@ -298,9 +307,13 @@ bool ETIDecoder::decode_deti(const vector<uint8_t> &value)
fc.mid = (etiHeader >> 22) & 0x03;
fc.fp = (etiHeader >> 19) & 0x07;
- bool rfa = (etiHeader >> 17) & 0x1;
+ uint8_t rfa = (etiHeader >> 17) & 0x3;
+ if (rfa != 0) {
+ etiLog.log(warn, "EDI deti TAG: rfa non-zero");
+ }
+
bool rfu = (etiHeader >> 16) & 0x1;
- uint16_t mnsc = etiHeader & 0xFFFF;
+ uint16_t mnsc = rfu ? 0xFFFF : etiHeader & 0xFFFF;
const size_t fic_length_words = (fc.ficf ? (fc.mid == 3 ? 32 : 24) : 0);
const size_t fic_length = 4 * fic_length_words;
@@ -311,9 +324,10 @@ bool ETIDecoder::decode_deti(const vector<uint8_t> &value)
(rfudf ? 3 : 0);
if (value.size() != expected_length) {
- etiLog.log(warn, " Assertion error: value.size() != expected_length: %zu %zu\n",
- value.size(), expected_length);
- assert(false);
+ throw std::logic_error("EDI deti: Assertion error:"
+ "value.size() != expected_length: " +
+ to_string(value.size()) + " " +
+ to_string(expected_length));
}
m_eti_writer.update_err(stat);
@@ -352,6 +366,13 @@ bool ETIDecoder::decode_deti(const vector<uint8_t> &value)
if (rfudf) {
uint32_t rfud = read_24b(value.begin() + i);
+ // high 16 bits: RFU in LIDATA EOH
+ // low 8 bits: RFU in TIST (not supported)
+ m_eti_writer.update_rfu(rfud >> 8);
+ if ((rfud & 0xFF) != 0xFF) {
+ etiLog.level(warn) << "EDI: RFU in TIST not supported";
+ }
+
i += 3;
}
@@ -370,6 +391,9 @@ bool ETIDecoder::decode_estn(const vector<uint8_t> &value, uint8_t n)
stc.sad = (sstc >> 8) & 0x3FF;
stc.tpl = (sstc >> 2) & 0x3F;
uint8_t rfa = sstc & 0x3;
+ if (rfa != 0) {
+ etiLog.level(warn) << "EDI: rfa field in ESTn tag non-null";
+ }
copy( value.begin() + 3,
value.end(),