aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Couzens <lynxis@fe80.eu>2019-06-16 18:35:09 +0200
committerAlexander Couzens <lynxis@fe80.eu>2019-06-16 18:35:09 +0200
commit5fec67df825fac6e77ac15fe583ad926dfaf6955 (patch)
tree487f6817243d3ec26eeccd237baa372707d6b340
parenteace104a05f6b386b7141e355a94bd0f98d8286f (diff)
Encoding: ACK/NACK: rework uncompressed length calculation when CRBB is presentlynxis/gprs-ack-nack
-rw-r--r--src/encoding.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/encoding.cpp b/src/encoding.cpp
index a8fdae29..d5ba3466 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -927,23 +927,28 @@ static void write_packet_ack_nack_desc_egprs(
len = urbb_len + 15;
} else {
- if (num_blocks > uclen_crbb) {
- eow = false;
- urbb_len = num_blocks - uclen_crbb;
- }
- /* Union bit takes 1 bit */
- /* Other fields in descr of compresed bitmap takes 23 bits
- * -8 = CRBB_STARTING_COLOR_CODE + CRBB_LENGTH */
- if (urbb_len > (rest_bits - crbb_len - 8)) {
+ /* 8 = 7 (CRBBlength) + 1 (CRBB starting color code) */
+ if (num_blocks > uclen_crbb + (rest_bits - crbb_len - 8)) {
eow = false;
len_coded = false;
urbb_len = rest_bits - crbb_len - 8;
- /* -16 = ACKNACK Dissector length + CRBB_STARTING_COLOR_CODE + CRBB_LENGTH */
- } else if (urbb_len > (rest_bits - crbb_len - 16)) {
- eow = false;
+ } else if (num_blocks == uclen_crbb + (rest_bits - crbb_len - 8)) {
len_coded = false;
+ urbb_len = rest_bits - crbb_len - 8;
+ /* 16 = 8 (Length) + 7 (CRBBlength) + 1 (CRBB starting color code) */
+ } else if (num_blocks <= uclen_crbb + (rest_bits - crbb_len - 16)) {
+ urbb_len = rest_bits - crbb_len - 16;
+ } else {
+ /* Same problem when not compressing, last case.
+ * The spec is not clear, what happens this case.
+ * The problem here is an URBB without length field, but the URBB would
+ * have more bits than the window is valid.
+ * Enfore the length field and might loose 7 bits in worst case of performance
+ * to have a clear case. */
+ eow = false;
urbb_len = rest_bits - crbb_len - 16;
}
+
len = urbb_len + crbb_len + 23;
}