diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2020-05-23 18:17:19 +0700 |
---|---|---|
committer | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2020-05-23 19:26:58 +0700 |
commit | 93ad3fd9b9aed26a609551c06a80db0e276eb4f1 (patch) | |
tree | 10e66f12cd5093a32bc407d6be510b08f8af8b0a /src/gsm_rlcmac.h | |
parent | 0614e9333fb5072640ba9939a28ffc1588cfe5bd (diff) |
csn1: fix: never use enumerated types in codec structures
I faced a problem while working on EGPRS Packet Channel Request
coding support: the unit test I wrote for it was passing when
compiled with AddressSanitizer, but failing when compiled
without it o_O. Somehow this was observed only with GCC 10.
Here is a part the standard output diff for that unit test:
*** testEGPRSPktChReq ***
decode_egprs_pkt_ch_req(0x2b5) returns 0
- ==> One Phase Access
+ ==> unknown 0xdd5f4e00
decode_egprs_pkt_ch_req(0x14a) returns 0
- ==> One Phase Access
+ ==> unknown 0xdd5f4e00
decode_egprs_pkt_ch_req(0x428) returns 0
- ==> Short Access
+ ==> unknown 0xdd5f4e01
At the same time, debug output of the CSN.1 decoder looked fine.
So WYSINWYG (What You See Is *NOT* What You Get)! As it turned
out, this was happening because I used an enumerated type to
represent the sub-type of EGPRS Packet Channel Request.
typedef struct
{
EGPRS_PacketChannelRequestType_t Type; // <-- enum
EGPRS_PacketChannelRequestContent_t Content;
} EGPRS_PacketChannelRequest_t;
The problem is that length of an enumerated field, more precisely
the amount of bytes it takes in the memory, is compiler/machine
dependent. While the CSN.1 decoder assumes that the field holding
sequential number of the chosen element is one octet long, so its
address is getting casted to (guint8 *) and the value is written
to the first MSB.
// csnStreamDecoder(), case CSN_CHOICE:
pui8 = pui8DATA(data, pDescr->offset);
*pui8 = i; // [ --> xx .. .. .. ]
Let's make sure that none of the existing RLC/MAC definitions is
using enumerated types, and add a warning comment to CSN_CHOICE.
Affected CSN.1 definitions (unit test output adjusted):
- Additional_access_technologies_struct_t,
- Channel_Request_Description_t.
Change-Id: I917a40647480c6f6f3b0e68674ce9894379a9e7f
Diffstat (limited to 'src/gsm_rlcmac.h')
-rw-r--r-- | src/gsm_rlcmac.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/gsm_rlcmac.h b/src/gsm_rlcmac.h index e9ae20ae..9d859f33 100644 --- a/src/gsm_rlcmac.h +++ b/src/gsm_rlcmac.h @@ -158,7 +158,7 @@ typedef struct { guint8 PEAK_THROUGHPUT_CLASS; guint8 RADIO_PRIORITY; - RLC_MODE_t RLC_MODE; + guint8 RLC_MODE; guint8 LLC_PDU_TYPE; guint16 RLC_OCTET_COUNT; } Channel_Request_Description_t; @@ -1245,7 +1245,7 @@ typedef enum typedef struct { - AccessTechnology_t Access_Technology_Type; + guint8 Access_Technology_Type; guint8 GMSK_Power_class; guint8 Eight_PSK_Power_class; } Additional_access_technologies_struct_t; |