aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoding.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-01-25encoding: fix typos in commentPau Espin Pedrol1-2/+2
Change-Id: I0867935ad08d6e49c62e061742d3d76eeac35844
2021-01-19Unify BTS into a C usable structurePau Espin Pedrol1-0/+1
Previous work on BTS class started to get stuff out of the C++ struct into a C struct (BTS -> struct gprs_glcmac_bts) so that some parts of it were accessible from C code. Doing so, however, ended up being messy too, since all code needs to be switching from one object to another, which actually refer to the same logical component. Let's instead rejoin the structures and make sure the struct is accessible and usable from both C and C++ code by rewriting all methods to be C compatible and converting 3 allocated suboject as pointers. This way BTS can internally still use those C++ objects while providing a clean APi to both C and C++ code. Change-Id: I7d12c896c5ded659ca9d3bff4cf3a3fc857db9dd
2021-01-05Convert GprsMS and helpers classes to CPau Espin Pedrol1-10/+10
As we integrate osmo-pcu more and more with libosmocore features, it becomes really hard to use them since libosmocore relies heavily on C specific compilation features, which are not available in old C++ compilers (such as designated initializers for complex types in FSMs). GprsMs is right now a quite simple object since initial design of osmo-pcu made it optional and most of the logic was placed and stored duplicated in TBF objects. However, that's changing as we introduce more features, with the GprsMS class getting more weight. Hence, let's move it now to be a C struct in order to be able to easily use libosmocore features there, such as FSMs. Some helper classes which GprsMs uses are also mostly move to C since they are mostly structs with methods, so there's no point in having duplicated APIs for C++ and C for such simple cases. For some more complex classes, like (ul_,dl_)tbf, C API bindings are added where needed so that GprsMs can use functionalitites from that class. Most of those APIs can be kept afterwards and drop the C++ ones since they provide no benefit in general. Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-01Dl TBF: Get rid of LLC UI dummy blocks following other dataPau Espin Pedrol1-55/+64
According to: * 3GPP TS 44.060 version 16.0.0 "9.3.1a Delayed release of downlink Temporary Block Flow" * 3GPP TS 44.064 version 16.0.0 "6.4.2.2 Unconfirmed Information (UI) Dummy command" LLC UI Dummy frames are to be used when there no more data to send, only in order to delay the release of a TBF. Hence, while not incorrect per se, makes no sense to send those LLC UI Dummy frames inserted into rlcmac blocks which already contain other LLC frames, since the MS in that case is already being kept active. It only makes sense to send those LLC UI Dummy frames when we have nothing else to send, that is, alone inside a RLCMAC block without other LLC frames. Related: OS#4849 Change-Id: Ifae1a7b2b3dfad8df19585063088ba0df2749c8f
2020-11-17encoding: Fix duplicate word in log strPau Espin Pedrol1-1/+1
Change-Id: Ifb0b359c43e79bab5599625fae20750ae5a6ae54
2020-11-05Fix mcs_is_valid(): UNKNOWN value is not a valid (M)CSPau Espin Pedrol1-0/+1
Also add a few more asserts to make sure a valid CS/MCS is passed in some placed where we expect (M)CS to be set. Change-Id: I0a973e10cd9477f72d8bd47a06048414b33ae96a
2020-10-29cosmetic: Fix ws between if keyword and parenthesisPau Espin Pedrol1-1/+1
Change-Id: I5932f21c58e76552f7187a175b8e281c5846536c
2020-10-24tbf: Make window() available to tbf base classPau Espin Pedrol1-2/+5
Return an interface to the window base class so that the tbf base class can access the common window methods, such as set_ws(). It will be used in next commit to get rid of duplicated function enable_egprs in both dl_tbf and ul_tbf subclasses. The user of the function can then decide to access more specific functionaltiites of the window class by static casting it to the specific direction (which is known by the caller since it operates on a ul_tbf or a dl_tbf). Change-Id: Ia2e1decf91be1184668e28297c2126affb9c7ae4
2020-09-10encoding: fix gen_freq_params(): do not check pdch twiceVadim Yanitskiy1-1/+1
This is a left-over from an earlier version of [1] that makes Coverity think that there can be NULL pointer dereference, even despite we assert(pdch != NULL). [1] I8adc0cdb1b05a87b4df5d4bc196f6d381283a06f Change-Id: I3490c38e0c1186dfd2fae63526a05c694547cebb Fixes: CID#214230
2020-09-08encoding: implement handing of hopping parametersVadim Yanitskiy1-11/+59
The following test cases verify coding of the hopping parameters: + (RR) Immediate Assignment - TC_pcuif_fh_imm_ass_ul_egprs, - TC_pcuif_fh_imm_ass_ul, - TC_pcuif_fh_imm_ass_dl, + (RLC/MAC) Packet Uplink/Downlink Assignment: - TC_pcuif_fh_pkt_ass_ul, - TC_pcuif_fh_pkt_ass_dl, all of them pass with this (and the upcoming) change applied. Change-Id: I8adc0cdb1b05a87b4df5d4bc196f6d381283a06f Related: SYS#4868, OS#4547
2020-09-08encoding: use CSN.1 codec to generate Packet Uplink AssignmentVadim Yanitskiy1-75/+105
It's quite odd to see that in write_packet_downlink_assignment() we initialize an 'RlcMacDownlink_t', so then the caller can use the power of CSN.1 codec to generate the final sequence of bytes to be transmitted, while in write_packet_uplink_assignment() we already compose the final RLC/MAC message straight away using the low-level bitvec API (like bitvec_write_field()). I guess the reason is that at the time of writing this code, the CSN.1 codec was not stable enough, so it was safer to generate the message 'by hand'. This would also explain why we *decode* the final RLC/MAC message in create_ul_ass() right after encoding. Rewrite write_packet_uplink_assignment(), so now it initializes a caller-provided 'RlcMacDownlink_t' structure. Given that it's allocated on heap using talloc_zero(), do not initialize presence indicators of fields that are not present in the message. This would facilitate handling of frequency hopping parameters in the upcoming changes, in particular we can now introduce a function that would compose Frequency Parameters IE for both write_packet_{downlink,uplink}_assignment(). Tested manually by running a GPRS-enabled network, as well as by running test cases from ttcn3-pcu-test => no regressions observed. Change-Id: I2850b91e0043cdca8ae7498a5fc727eeedd029b6 Related: SYS#4868, OS#4547
2020-09-08encoding: clarify docstring for write_packet_downlink_assignment()Vadim Yanitskiy1-3/+2
Change-Id: I7c4458c2e7767b6cf03462ba79acdd9c9904ee83
2020-08-24encoding: pass pdch slot directly to encoding functionsVadim Yanitskiy1-6/+8
In order to be able to encode frequency hopping parameters, let's pass a const pointer to 'gprs_rlcmac_pdch' (PDCH slot) directly, instead of passing all related parameters separately. Change-Id: I6bccad508f0fdccc4a763211008dd847a9111a8d Related: SYS#4868, OS#4547
2020-08-24encoding: use bool for use_egprs in write_packet_uplink_assignment()Vadim Yanitskiy1-1/+1
Change-Id: Iab4fb44c666a0d4fe8c98f5ff9221e23a6f1f2fa
2020-08-24encoding: fix RRBP field in write_packet_uplink_assignment()Vadim Yanitskiy1-1/+1
Do not hard-code 0x00, write what was passed as a parameter. Change-Id: I9eb362292e9f4c16d4b8f8d4253df0422062eeb4
2020-08-24encoding: do not encode out of range Timing Advance valuesVadim Yanitskiy1-3/+8
According to 3GPP TS 44.060, section 12.12 "Packet Timing Advance", the 'TIMING_ADVANCE_VALUE' field is optional, and takes 6 bits if present. This means that a value that fits in range 0..63 (inclusive) can be encoded (0b111111 == 63). It's possible that tbf->ta() returns GSM48_TA_INVALID == 220, so the bitvec API would encode only 6 LSBs of it: 220 & 0b111111 == 28 Let's ensure that the 'TIMING_ADVANCE_VALUE' is present iff tbf->ta() returns a correct (0 <= x <= 63), and absent otherwise. Change-Id: I342288ea4ef1e218e5744e9be6a8e528d4e697fa
2020-08-24encoding: constify 'tbf' in UL/DL assignment functionsVadim Yanitskiy1-2/+2
Change-Id: I9b80ce22914a355592502c936046b233c3ba216d
2020-08-24paging: pass struct osmo_mobile_identity, not encoded IE bytesNeels Hofmeyr1-2/+8
In get_paging_mi(), before this, an encoded buffer of Mobile Identity bytes is returned. Code paths following this repeatedly decode the Mobile Identity bytes, e.g. for logging. Also, in get_paging_mi(), since the TMSI is read in from a different encoding than a typical Mobile Identity IE, the TMSI was manually encoded into a typical Mobile Identity IE. This is essentially a code dup of osmo_mobile_identity_encode(). Stop this madness. Instead, in get_paging_mi(), return a decoded struct osmo_mobile_identity. Code paths after this use the struct osmo_mobile_identity directly without repeated decoding. At the point of finally needing an encoded Mobile Identity IE (in Encoding::write_paging_request()), do a proper osmo_mobile_identity_encode(). Since this may return errors, add an rc check for the caller of write_paging_request(), gprs_rlcmac_paging_request(). A side effect is stricter validation of the Mobile Identity passing through the Paging code path. Before, invalid MI might have passed through unnoticed. Change-Id: Iad845acb0096b75dc453105c9c16b2252879b4ca
2020-07-18encoding: assert() presence of Downlink TBFVadim Yanitskiy1-4/+1
This is not something that should normally happen. If it happens, then it's definitely a bug, and we should not tolerate it. Change-Id: I6e46ba42650f0db2399649b536a1d2b3f0fcbf04
2020-07-18encoding: drop log_alert_exit(), use OSMO_ASSERT() insteadVadim Yanitskiy1-13/+2
Change-Id: Id5ef1c3c08dc7f264ad801e519d727d86f5ae5b8
2020-07-09encoding.cpp: Fix missing spacing in function paramPau Espin Pedrol1-2/+2
Change-Id: I4f30a0cea615d57cd7783a92ae782790c8075a6c
2020-07-09encoding: Encode TA as unsigned and check validty against GSM48_TA_INVALIDPau Espin Pedrol1-3/+3
According to 3GPP TS 44.018 sec 10.5.2.40, Timing Advance value is 8 bit and range is 0-63 (0-219 on GSM400). Unsigned value (uint8_t) is used everywhere else, so avoid using a signed one here, and simply check for GSM48_TA_INVALID here, which we use everywhere else to initialize when the value is not known. Ideally we should check for value based on band, but it makes more sense to check that when receiving the data and storing in in set_ta(). Change-Id: I82b13561d0fe5ebafb5c3a8b9a501045c29809bc
2020-05-25encoding: fix write_ia_rest_egprs_uplink_sba(): add missing CHECK(rc)Vadim Yanitskiy1-0/+1
Change-Id: I8e41c2912aaff689b0e311c8e2d3e961d2f1ac2c
2020-05-23encoding: cosmetic: use RLC_MODE_ACKNOWLEDGED where possibleVadim Yanitskiy1-2/+3
Change-Id: Ic69d120f622f512f05016596bfdd4a89b96e3e3b
2020-05-20Get rid of class GprsCodingSchemePau Espin Pedrol1-3/+3
We have same kind of object splitted into two layers, in coding_scheme and gprs_coding_scheme. Let's merge them together and get rid of the class, which is not really useful because it's only a set of functions operating on one enum value. This change also fixes gcc 10.1.0 error about memseting a complex type in rlc.h init(). Change-Id: Ie9ce2144ba9e8dbba9704d4e0000a2929e3e41df
2020-02-10encoding: assert return value of bitvec_set_u64()Vadim Yanitskiy1-1/+2
Change-Id: Ic0de3ae34f06e41aacacb917f5a0214623259bdc Fixes: OS#182120
2020-01-29encoding: fix log_alert_exit(): do not treat error as format stringVadim Yanitskiy1-1/+1
This is rather a cosmetic change aimed to make ASAN / Coverity happy. In general, we never pass any input from an untrusted source. Change-Id: I26d654da4c3bf5fd86a298c3027fd9820c932308
2020-01-06Allow Gb PAGING-PS without P-TMSIPau Espin Pedrol1-9/+4
P-TMSI is optional IE, but IE is mandatory and hence always available. Since the encoding is actually a Mobile Identity, the IMSI is used in case P-TMSI is not available. Change-Id: I4dbf8db04e81f98352a42ce34a5d91326be9bfd1
2019-12-10Fix trailing whitespacePau Espin Pedrol1-5/+5
Change-Id: I0515b5c8f6744fa501de88fa7808b7fc91981f0e
2019-10-09encoding: fix space, tabsAlexander Couzens1-30/+30
Change-Id: I80ac88f50bfedfd2b86d548883313b5a187b1e8f
2019-09-25Move out tbf subclasses from tbf.h to their own headersPau Espin Pedrol1-0/+1
It's a good start towards clearing current mess between parent and the 2 children classes. Change-Id: Ibc22ea2e02609af7ee058b8bc15df2115d4c6f60
2019-07-17fix spelling errors detected by lintianThorsten Alteholz1-1/+1
Change-Id: I381618eb55cc513cfa9c2e384c27cead0935c8bf
2019-07-11Encoding: ACK/NACK: always encode with length field presentAlexander Couzens1-43/+39
In most cases the length field was present and this field takes 7 bits of the maximum available 110 rest bits. The length field was only removed when encoding huge bitmaps usually only happen on lossy connections with packet lost. However the cases without length field were encoded incorrect, because all remaining bits must be used by the uncompressed bitmaps, but the PCU violates this by encoding always the "release 5" bit. Rather than fixing the encoding without length field, simply remove it and always encode with length field. This also reduces the code complexity. Change-Id: I7bc2e18d647b72b8f17ba7a5c9c5e421d88275fb
2019-07-11Encoding: use uint16_t when interacting with the window objectAlexander Couzens1-4/+4
The ESN, SSN and uncompress bitmap len are uint16_t. The Window is using uint16_t in function arguments and return values. Don't do so many integer conversions. Change-Id: If62fa09d7bfa8e91ce707824f7019edb1b83da9e
2019-07-11Encoding: write_packet_ack_nack_desc_egprs: don't use a reference for rest_bitsAlexander Couzens1-1/+1
The rest_bits are never read after calling this function nor are rest_bits updated properly. Change-Id: Ic350b0365b125638a6c752f692bef981ad6b9d89
2019-06-24Encoding: drop struct gprs_rlcmac_bts* from all functionsAlexander Couzens1-11/+9
The bts is not used at all. Change-Id: Ia07755e825913a16352ab13f6cf55f2918de8681
2019-06-17encoding: use `/* */` for comments instead of `#if 0 #endif`Alexander Couzens1-4/+3
Change-Id: Ifff9526b15bfda7a0f85c92bcb0d3fabab61ca32
2019-06-13encoding: correct encoding of CRBB in ACK/NACK when not byte alignedAlexander Couzens1-1/+1
The last bits of the CRBB (compressed receive block bitmap) was incorrect encoded when the CRBB is not byte aligned. Related: OS#3728 Change-Id: I7261aa71b37d7ead52992f8db462f72a3804988e
2019-03-27Update IA Rest Octets encodingMax1-17/+13
Write initial bits of 3GPP TS 44.018 §10.5.2.16 IA Rest Octets the same way as write_ia_rest_*() routines do. This should also fix the issue addressed in I75dd5bebc74eea85edf9582607c774d0bba0d2a6 initially by properly encoding L/H bits. Change-Id: I7ed5270bf95c3f6e9e026ff447eef8539f6f0314
2019-03-27Use Timing Advance Index in UL assignmentsMax1-8/+8
Write TAI (if available) when generating Rest Octets for UL Assignment. This should not affect actual PCU behavior because TAI is not yet supported by upper layers but we have to adjust corresponding tests anyway. That's updated version of reverted commit. Change-Id: I69407793bdb863be5fc42adadf75842d22f27335 Related: OS#3014
2019-03-27Rewrite Packet Uplink IA Rest Octets for SBAMax1-15/+22
Use bitvec_set_*() directly without external write pointer tracking to simplify the code. This is part of IA Rest Octets (3GPP TS 44.018 §10.5.2.16) which is the last part of the message so it should not interfere with the rest of encoding functions. The difference in the expected test output is due to proper handling of TAI which should not be transmitted for SBA according to the Note in Table 10.5.2.16.1 in 3GPP TS 44.018. The change was manually tested against real mobile phone using options 'gprs mode gprs' in osmo-bsc.cfg and 'two-phase-access' in osmo-pcu.cfg to make sure appropriate code path is actually triggered. That's partially based on reverted commit 93d947f5e8a30acc9250c124bf9d5bb6a8863526. Change-Id: I97d53c27c1ca9e032d431b3aa7f915027d63ddc0 Related: OS#3014
2019-03-27Rewrite Packet Uplink IA Rest Octets for MBAMax1-20/+21
Use bitvec_set_*() directly without external write pointer tracking to simplify the code. This is part of IA Rest Octets (3GPP TS 44.018 §10.5.2.16) which is the last part of the message so it should not interfere with the rest of encoding functions. That's partially based on reverted commit 93d947f5e8a30acc9250c124bf9d5bb6a8863526. Change-Id: Ibe294b26ac374b9264a734db9663cacc105a4474 Related: OS#3014
2019-03-27Fix Channel Coding Command for MCSMax1-6/+6
Previously result of ".to_num() - 1" was used without any checks which means that in case of to_num() returning zero we would effectively try to encode (uint8_t)(-1). Let's fix this by using proper mcs_chan_code() function which returns Channel Coding Command for MCS without the need to further correct it and adjust expected tests output accordingly. Change-Id: I868062a81fffe6714a811c032215f25a79259905
2019-03-26MCS: add mcs_is_*() helpersMax1-2/+2
In preparation for Channel Coding Command encoder in follow-up patches let's add necessary helpers. Those are similar to previously used helpers from GprsCodingScheme class but without CamelCase and with less typo chances between Gprs and Egprs cases. Change-Id: I6699cbc8d7ae766fa4d2b3d37e5f9ff1cf158b7e
2019-03-19Fix TA index encoderMax1-6/+6
The TAI is described as { 0 | 1 < TIMING_ADVANCE_INDEX : bit (4) > } in 3GPP TS 44.018 §10.5.2.16.1 so it should be encoded with if-else. Change-Id: I54482790e1cf3cb13a635a99a481250576deabaf
2019-03-19MCS: use value_string for conversionMax1-2/+2
Change-Id: I212ebb892ab162821633974d5a6c7e315d308370
2019-03-19MCS: move HeaderType enum outside of class definitionMax1-4/+4
Move functions which compute number of blocks or bits depending on header type and corresponding enum outside of GprsCodingScheme class. This will allows us to use standard libosmocore value_sting functions in upcoming patches for IA Rest Octet encoding/decoding. Change-Id: Id0873f85e1f16a72e17e7fbc4ad76b194917067f
2019-03-11encoding: Fixes TMSI vs MI bit selection in repeated page infoJF Dionne1-1/+15
Change-Id: Iddb00b9133f523f4ba09c8f1fc5694e62dc46fbf
2019-02-26Rewrite EGPRS Packet Uplink IA Rest Octets for SBAMax1-26/+58
Use bitvec_set_*() directly without external write pointer tracking to simplify the code. This is part of IA Rest Octets (3GPP TS 44.018 §10.5.2.16) which is the last part of the message so it should not interfere with the rest of encoding functions. That's partially based on reverted commit 529ce885450946d85d1920fb3d1a994c3efe5849. Change-Id: I143b3dd02aa54b9ce206d9e780a5554f6d9fd118 Related: OS#3014
2019-02-19Rewrite EGPRS Packet Uplink IA Rest Octets for MBAMax1-15/+11
Use bitvec_set_*() directly without external write pointer tracking to simplify the code. This is part of IA Rest Octets (3GPP TS 44.018 §10.5.2.16) which is the last part of the message so it should not interfere with the rest of encoding functions. That's partially based on reverted commit 529ce885450946d85d1920fb3d1a994c3efe5849. Change-Id: I19cc4226e7e831e7d7f70212b2078f5589a87ff0 Related: OS#3014