<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-pcu/+/19731">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">encoding: do not encode out of range Timing Advance values<br><br>According to 3GPP TS 44.060, section 12.12 "Packet Timing Advance",<br>the 'TIMING_ADVANCE_VALUE' field is optional, and takes 6 bits<br>if present.  This means that a value that fits in range 0..63<br>(inclusive) can be encoded (0b111111 == 63).<br><br>It's possible that tbf->ta() returns GSM48_TA_INVALID == 220,<br>so the bitvec API would encode only 6 LSBs of it:<br><br>  220 & 0b111111 == 28<br><br>Let's ensure that the 'TIMING_ADVANCE_VALUE' is present iff<br>tbf->ta() returns a correct (0 <= x <= 63), and absent otherwise.<br><br>Change-Id: I342288ea4ef1e218e5744e9be6a8e528d4e697fa<br>---<br>M src/encoding.cpp<br>1 file changed, 8 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/31/19731/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/encoding.cpp b/src/encoding.cpp</span><br><span>index cc9fd0a..bbc80bc 100644</span><br><span>--- a/src/encoding.cpp</span><br><span>+++ b/src/encoding.cpp</span><br><span>@@ -144,7 +144,7 @@</span><br><span> /* { 0 | 1 < TIMING_ADVANCE_VALUE : bit (6) > } */</span><br><span> static inline void write_ta(bitvec *dest, unsigned& wp, uint8_t ta)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-    if (ta >= GSM48_TA_INVALID) /* No TIMING_ADVANCE_VALUE: */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ta > 63) /* No TIMING_ADVANCE_VALUE: */</span><br><span>               bitvec_write_field(dest, &wp, 0, 1);</span><br><span>     else { /* TIMING_ADVANCE_VALUE: */</span><br><span>           bitvec_write_field(dest, &wp, 1, 1);</span><br><span>@@ -666,8 +666,13 @@</span><br><span>                      block->u.Packet_Downlink_Assignment.TIMESLOT_ALLOCATION |= 0x80 >> tn;   // timeslot(s)</span><br><span>     }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_TIMING_ADVANCE_VALUE = 0x1; // TIMING_ADVANCE_VALUE = on</span><br><span style="color: hsl(0, 100%, 40%);">-     block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.TIMING_ADVANCE_VALUE       = tbf->ta();  // TIMING_ADVANCE_VALUE</span><br><span style="color: hsl(120, 100%, 40%);">+      if (tbf->ta() > 63) { /* { 0 | 1  < TIMING_ADVANCE_VALUE : bit (6) > } */</span><br><span style="color: hsl(120, 100%, 40%);">+         block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_TIMING_ADVANCE_VALUE = 0x0; // TIMING_ADVANCE_VALUE = off</span><br><span style="color: hsl(120, 100%, 40%);">+  } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_TIMING_ADVANCE_VALUE = 0x1; // TIMING_ADVANCE_VALUE = on</span><br><span style="color: hsl(120, 100%, 40%);">+           block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.TIMING_ADVANCE_VALUE       = tbf->ta();  // TIMING_ADVANCE_VALUE</span><br><span style="color: hsl(120, 100%, 40%);">+      }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  if (ta_idx < 0) {</span><br><span>                 block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_IndexAndtimeSlot     = 0x0; // TIMING_ADVANCE_INDEX = off</span><br><span>         } else {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-pcu/+/19731">change 19731</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-pcu/+/19731"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-pcu </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I342288ea4ef1e218e5744e9be6a8e528d4e697fa </div>
<div style="display:none"> Gerrit-Change-Number: 19731 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>