<p>Max <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/12954">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Rewrite Packet Downlink Assignment<br><br>Use bitvec_set_*() directly without external write pointer tracking to<br>simplify the code. This is part of IA Rest Octets (3GPP TS 44.018<br>§10.5.2.16) which is the last part of the message so it should not<br>interfere with the rest of encoding functions.<br><br>That's updated version of commit with the same topic reverted earlier.<br><br>Change-Id: Ie180733d2584ebb16fb80b84526d0dbc70e3d441<br>Related: OS#3014<br>---<br>M src/encoding.cpp<br>1 file changed, 112 insertions(+), 33 deletions(-)<br><br></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 2648b02..e7e13ac 100644</span><br><span>--- a/src/encoding.cpp</span><br><span>+++ b/src/encoding.cpp</span><br><span>@@ -35,7 +35,72 @@</span><br><span> #include <errno.h></span><br><span> #include <string.h></span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define CHECK(rc) { if (rc < 0) return rc; }</span><br><span style="color: hsl(120, 100%, 40%);">+#define SET_X(bv, x) { if (bitvec_set_bit(bv, x) < 0) return -EOWNERDEAD; }</span><br><span style="color: hsl(120, 100%, 40%);">+#define SET_0(bv) SET_X(bv, ZERO)</span><br><span style="color: hsl(120, 100%, 40%);">+#define SET_1(bv) SET_X(bv, ONE)</span><br><span style="color: hsl(120, 100%, 40%);">+#define SET_L(bv) SET_X(bv, L)</span><br><span style="color: hsl(120, 100%, 40%);">+#define SET_H(bv) SET_X(bv, H)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* 3GPP TS 44.018 § 10.5.2.16:</span><br><span style="color: hsl(120, 100%, 40%);">+   { 0 | 1 < ALPHA : bit (4) > }</span><br><span style="color: hsl(120, 100%, 40%);">+   < GAMMA : bit (5) ></span><br><span style="color: hsl(120, 100%, 40%);">+*/</span><br><span style="color: hsl(120, 100%, 40%);">+static int write_alpha_gamma(bitvec *dest, uint8_t alpha, uint8_t gamma)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (alpha) {</span><br><span style="color: hsl(120, 100%, 40%);">+          SET_1(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+          rc = bitvec_set_u64(dest, alpha, 4, false);</span><br><span style="color: hsl(120, 100%, 40%);">+           CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+    } else</span><br><span style="color: hsl(120, 100%, 40%);">+                SET_0(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        rc = bitvec_set_u64(dest, gamma, 5, false);</span><br><span style="color: hsl(120, 100%, 40%);">+   CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* TBF_STARTING_TIME -- same as 3GPP TS 44.018 §10.5.2.38 Starting Time without tag: */</span><br><span style="color: hsl(120, 100%, 40%);">+static int write_tbf_start_time(bitvec *dest, uint32_t fn)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Set values according to 3GPP TS 44.018 Table 10.5.2.38.1 */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* T1' */</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = bitvec_set_u64(dest, (fn / (26 * 51)) % 32, 5, false);</span><br><span style="color: hsl(120, 100%, 40%);">+   CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* T3  */</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = bitvec_set_u64(dest, fn % 51, 6, false);</span><br><span style="color: hsl(120, 100%, 40%);">+ CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* T2  */</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = bitvec_set_u64(dest, fn % 26, 5, false);</span><br><span style="color: hsl(120, 100%, 40%);">+ CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  return rc;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* { 0 | 1 < TIMING_ADVANCE_INDEX : bit (4) > } */</span><br><span style="color: hsl(120, 100%, 40%);">+static int write_ta_index(bitvec *dest, int8_t tai)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (tai < 0) /* No TIMING_ADVANCE_INDEX: */</span><br><span style="color: hsl(120, 100%, 40%);">+                SET_0(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* TIMING_ADVANCE_INDEX: */</span><br><span style="color: hsl(120, 100%, 40%);">+   SET_1(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = bitvec_set_u64(dest, tai, 4, false);</span><br><span style="color: hsl(120, 100%, 40%);">+     CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static inline bool write_tai(bitvec *dest, unsigned& wp, int8_t tai)</span><br><span> {</span><br><span>      if (tai < 0) { /* No TIMING_ADVANCE_INDEX: */</span><br><span>@@ -88,43 +153,55 @@</span><br><span> }</span><br><span> </span><br><span> static int write_ia_rest_downlink(const gprs_rlcmac_dl_tbf *tbf, bitvec * dest, bool polling, bool ta_valid,</span><br><span style="color: hsl(0, 100%, 40%);">-                                  uint32_t fn, uint8_t alpha, uint8_t gamma, int8_t ta_idx, unsigned& wp)</span><br><span style="color: hsl(120, 100%, 40%);">+                           uint32_t fn, uint8_t alpha, uint8_t gamma, int8_t ta_idx)</span><br><span> {</span><br><span>     int rc = 0;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- bitvec_write_field(dest, &wp, 3, 2);   // "HH"</span><br><span style="color: hsl(0, 100%, 40%);">-    bitvec_write_field(dest, &wp, 1, 2);   // "01" Packet Downlink Assignment</span><br><span style="color: hsl(0, 100%, 40%);">- bitvec_write_field(dest, &wp,tbf->tlli(),32); // TLLI</span><br><span style="color: hsl(0, 100%, 40%);">-    bitvec_write_field(dest, &wp,0x1,1);   // switch TFI   : on</span><br><span style="color: hsl(0, 100%, 40%);">- bitvec_write_field(dest, &wp,tbf->tfi(),5);   // TFI</span><br><span style="color: hsl(0, 100%, 40%);">-     bitvec_write_field(dest, &wp,0x0,1);   // RLC acknowledged mode</span><br><span style="color: hsl(0, 100%, 40%);">-     if (alpha) {</span><br><span style="color: hsl(0, 100%, 40%);">-            bitvec_write_field(dest, &wp,0x1,1);   // ALPHA = present</span><br><span style="color: hsl(0, 100%, 40%);">-           bitvec_write_field(dest, &wp,alpha,4);   // ALPHA</span><br><span style="color: hsl(0, 100%, 40%);">-   } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                bitvec_write_field(dest, &wp,0x0,1);   // ALPHA = not present</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-       bitvec_write_field(dest, &wp,gamma,5);   // GAMMA power control parameter</span><br><span style="color: hsl(0, 100%, 40%);">-   bitvec_write_field(dest, &wp,polling,1);   // Polling Bit</span><br><span style="color: hsl(0, 100%, 40%);">-   bitvec_write_field(dest, &wp, ta_valid, 1); // N. B: NOT related to TAI!</span><br><span style="color: hsl(0, 100%, 40%);">-    write_tai(dest, wp, ta_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+  SET_H(dest); SET_H(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+     SET_0(dest); SET_1(dest); /* 00 Packet Downlink Assignment */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       rc = bitvec_set_u64(dest, tbf->tlli(), 32, false); /* TLLI */</span><br><span style="color: hsl(120, 100%, 40%);">+      CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  SET_1(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = bitvec_set_u64(dest, tbf->tfi(), 5, false);   /* TFI_ASSIGNMENT */</span><br><span style="color: hsl(120, 100%, 40%);">+    CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* RLC acknowledged mode */</span><br><span style="color: hsl(120, 100%, 40%);">+   SET_0(dest); /* RLC_MODE */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = write_alpha_gamma(dest, alpha, gamma);</span><br><span style="color: hsl(120, 100%, 40%);">+   CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = bitvec_set_bit(dest, (bit_value)polling); /* POLLING */</span><br><span style="color: hsl(120, 100%, 40%);">+  CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* N. B: NOT related to TAI! */</span><br><span style="color: hsl(120, 100%, 40%);">+       rc = bitvec_set_bit(dest, (bit_value)ta_valid); /* TA_VALID */</span><br><span style="color: hsl(120, 100%, 40%);">+        CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = write_ta_index(dest, ta_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+    CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         if (polling) {</span><br><span style="color: hsl(0, 100%, 40%);">-          bitvec_write_field(dest, &wp,0x1,1);   // TBF Starting TIME present</span><br><span style="color: hsl(0, 100%, 40%);">-         bitvec_write_field(dest, &wp,(fn / (26 * 51)) % 32,5); // T1'</span><br><span style="color: hsl(0, 100%, 40%);">-           bitvec_write_field(dest, &wp,fn % 51,6);               // T3</span><br><span style="color: hsl(0, 100%, 40%);">-                bitvec_write_field(dest, &wp,fn % 26,5);               // T2</span><br><span style="color: hsl(0, 100%, 40%);">-        } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                bitvec_write_field(dest, &wp,0x0,1);   // TBF Starting TIME present</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-       bitvec_write_field(dest, &wp,0x0,1);   // P0 not present</span><br><span style="color: hsl(0, 100%, 40%);">-    //              bitvec_write_field(dest, &wp,0x1,1);   // P0 not present</span><br><span style="color: hsl(0, 100%, 40%);">-    //              bitvec_write_field(dest, &wp,,0xb,4);</span><br><span style="color: hsl(120, 100%, 40%);">+             SET_1(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+          rc = write_tbf_start_time(dest, fn);</span><br><span style="color: hsl(120, 100%, 40%);">+          CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+       } else</span><br><span style="color: hsl(120, 100%, 40%);">+             SET_0(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        SET_0(dest); /* No P0 nor PR_MODE */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       if (tbf->is_egprs_enabled()) {</span><br><span style="color: hsl(0, 100%, 40%);">-               bitvec_write_field(dest, &wp, 1, 1);  // "H"</span><br><span style="color: hsl(0, 100%, 40%);">-              write_ws(dest, &wp, tbf->window_size()); // EGPRS Window Size</span><br><span style="color: hsl(0, 100%, 40%);">-            bitvec_write_field(dest, &wp, 0x0, 2);    // LINK_QUALITY_MEASUREMENT_MODE</span><br><span style="color: hsl(0, 100%, 40%);">-          bitvec_write_field(dest, &wp, 0, 1);      // BEP_PERIOD2 not present</span><br><span style="color: hsl(0, 100%, 40%);">-        }</span><br><span style="color: hsl(120, 100%, 40%);">+             SET_H(dest);</span><br><span style="color: hsl(120, 100%, 40%);">+          rc = bitvec_set_u64(dest, enc_ws(tbf->window_size()), 5, false); /* EGPRS Window Size */</span><br><span style="color: hsl(120, 100%, 40%);">+           CHECK(rc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+               /* The mobile station shall not report measurements: (see 3GPP TS 44.060 Table 11.2.7.1) */</span><br><span style="color: hsl(120, 100%, 40%);">+              SET_0(dest); SET_0(dest); /* LINK_QUALITY_MEASUREMENT_MODE */</span><br><span style="color: hsl(120, 100%, 40%);">+         SET_1(dest);              /* No BEP_PERIOD2 */</span><br><span style="color: hsl(120, 100%, 40%);">+        } else</span><br><span style="color: hsl(120, 100%, 40%);">+                SET_L(dest);              /* No Additions for Rel-6 */</span><br><span> </span><br><span>   return rc;</span><br><span> }</span><br><span>@@ -393,8 +470,10 @@</span><br><span>                       LOGP(DRLCMACDL, LOGL_ERROR, "Cannot encode DL IMMEDIATE ASSIGNMENT without TBF\n");</span><br><span>                        return -EINVAL;</span><br><span>              }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           dest->cur_bit = wp;</span><br><span>               rc = write_ia_rest_downlink(as_dl_tbf(tbf), dest, polling, gsm48_ta_is_valid(ta), fn, alpha, gamma,</span><br><span style="color: hsl(0, 100%, 40%);">-                                         ta_idx, wp);</span><br><span style="color: hsl(120, 100%, 40%);">+                                          ta_idx);</span><br><span>         } else if (((burst_type == GSM_L1_BURST_TYPE_ACCESS_1) || (burst_type == GSM_L1_BURST_TYPE_ACCESS_2))) {</span><br><span>             bitvec_write_field(dest, &wp, 1, 2);    /* LH */</span><br><span>                 bitvec_write_field(dest, &wp, 0, 2);    /* 0 EGPRS Uplink Assignment */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/12954">change 12954</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/12954"/><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-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ie180733d2584ebb16fb80b84526d0dbc70e3d441 </div>
<div style="display:none"> Gerrit-Change-Number: 12954 </div>
<div style="display:none"> Gerrit-PatchSet: 6 </div>
<div style="display:none"> Gerrit-Owner: Max <msuraev@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-Reviewer: Max <msuraev@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Pau Espin Pedrol <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: osmith <osmith@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: tnt <tnt@246tNt.com> </div>
<div style="display:none"> Gerrit-CC: Daniel Willmann <dwillmann@sysmocom.de> </div>
<div style="display:none"> Gerrit-CC: Vadim Yanitskiy <axilirator@gmail.com> </div>