<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bts/+/14592">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">osmo-bts-trx/trx_if.c: introduce TRXD header version handling<br><br>It may be necessary to extend the message specific header with<br>more information. Since this is not a TLV-based protocol, we<br>need to include the header format version.<br><br>  +-----------------+---------------------------+<br>  | 7 6 5 4 3 2 1 0 | bit numbers (value range) |<br>  +-----------------+---------------------------+<br>  | X X X X . . . . | header version (0..15)    |<br>  +-----------------+---------------------------+<br>  | . . . . . X X X | TDMA TN (0..7)            |<br>  +-----------------+---------------------------+<br>  | . . . . X . . . | RESERVED (0)              |<br>  +-----------------+---------------------------+<br><br>Instead of prepending an additional byte, it was decided to use<br>4 MSB bits of the first octet, which used to be zero-initialized<br>due to the value range of TDMA TN (0..7). Therefore the current<br>header format has implicit version 0x00.<br><br>Otherwise Wireshark (or trx_sniff.py) would have to guess the<br>header version, or alternatively follow the control channel<br>looking for the version setting command.<br><br>This change introduces a new structure 'trx_ul_burst_ind', which<br>represents an Uplink burst and the corresponding meta info. The<br>purpose of this structure is to avoid overloading the existing<br>functions, such as trx_sched_ul_burst(), with more and more<br>arguments every time we bump the version.<br><br>On receipt of a TRXD message, trx_data_read_cb() now parses<br>the header version, and calls the corresponding dissector<br>function, e.g. trx_data_handle_v0() for version 0x00.<br><br>Change-Id: I171c18229ca3e5cab70de0064a31e47c78602c0c<br>Related: OS#4006<br>---<br>M include/osmo-bts/scheduler.h<br>M src/common/scheduler.c<br>M src/osmo-bts-trx/trx_if.c<br>3 files changed, 180 insertions(+), 53 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/92/14592/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmo-bts/scheduler.h b/include/osmo-bts/scheduler.h</span><br><span>index c862307..695700d 100644</span><br><span>--- a/include/osmo-bts/scheduler.h</span><br><span>+++ b/include/osmo-bts/scheduler.h</span><br><span>@@ -173,10 +173,6 @@</span><br><span> /*! \brief PHY informs us of new (current) GSM frame number */</span><br><span> int trx_sched_clock(struct gsm_bts *bts, uint32_t fn);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief handle an UL burst received by PHY */</span><br><span style="color: hsl(0, 100%, 40%);">-int trx_sched_ul_burst(struct l1sched_trx *l1t, uint8_t tn, uint32_t fn,</span><br><span style="color: hsl(0, 100%, 40%);">-        sbit_t *bits, uint16_t nbits, int8_t rssi, int16_t toa);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*! \brief set multiframe scheduler to given physical channel config */</span><br><span> int trx_sched_set_pchan(struct l1sched_trx *l1t, uint8_t tn,</span><br><span>         enum gsm_phys_chan_config pchan);</span><br><span>@@ -231,4 +227,20 @@</span><br><span> bool trx_sched_is_sacch_fn(struct gsm_bts_trx_ts *ts, uint32_t fn, bool uplink);</span><br><span> extern const struct trx_sched_multiframe trx_sched_multiframes[];</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! UL burst indication with the corresponding meta info */</span><br><span style="color: hsl(120, 100%, 40%);">+struct trx_ul_burst_ind {</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Mandatory fields */</span><br><span style="color: hsl(120, 100%, 40%);">+        uint32_t fn;            /*!< TDMA frame number */</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t tn;             /*!< TDMA time-slot number */</span><br><span style="color: hsl(120, 100%, 40%);">+      int16_t toa256;         /*!< Timing of Arrival in units of 1/256 of symbol */</span><br><span style="color: hsl(120, 100%, 40%);">+      int8_t rssi;            /*!< Received Signal Strength Indication */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* Burst soft-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t burst_len;</span><br><span style="color: hsl(120, 100%, 40%);">+     sbit_t *burst;</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%);">+/*! Handle an UL burst received by PHY */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_ul_burst(struct l1sched_trx *l1t, const struct trx_ul_burst_ind *bi);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif /* TRX_SCHEDULER_H */</span><br><span>diff --git a/src/common/scheduler.c b/src/common/scheduler.c</span><br><span>index 3f804a9..7b51a2a 100644</span><br><span>--- a/src/common/scheduler.c</span><br><span>+++ b/src/common/scheduler.c</span><br><span>@@ -1313,11 +1313,10 @@</span><br><span>        return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* process uplink burst */</span><br><span style="color: hsl(0, 100%, 40%);">-int trx_sched_ul_burst(struct l1sched_trx *l1t, uint8_t tn, uint32_t fn,</span><br><span style="color: hsl(0, 100%, 40%);">-    sbit_t *bits, uint16_t nbits, int8_t rssi, int16_t toa256)</span><br><span style="color: hsl(120, 100%, 40%);">+/* Process an Uplink burst indication */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_ul_burst(struct l1sched_trx *l1t, const struct trx_ul_burst_ind *bi)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-   struct l1sched_ts *l1ts = l1sched_trx_get_ts(l1t, tn);</span><br><span style="color: hsl(120, 100%, 40%);">+        struct l1sched_ts *l1ts = l1sched_trx_get_ts(l1t, bi->tn);</span><br><span>        struct l1sched_chan_state *l1cs;</span><br><span>     const struct trx_sched_frame *frame;</span><br><span>         uint8_t offset, period, bid;</span><br><span>@@ -1329,7 +1328,7 @@</span><br><span> </span><br><span>     /* get frame from multiframe */</span><br><span>      period = l1ts->mf_period;</span><br><span style="color: hsl(0, 100%, 40%);">-    offset = fn % period;</span><br><span style="color: hsl(120, 100%, 40%);">+ offset = bi->fn % period;</span><br><span>         frame = l1ts->mf_frames + offset;</span><br><span> </span><br><span>     chan = frame->ul_chan;</span><br><span>@@ -1346,28 +1345,29 @@</span><br><span>          return -EINVAL;</span><br><span> </span><br><span>  /* calculate how many TDMA frames were potentially lost */</span><br><span style="color: hsl(0, 100%, 40%);">-      trx_sched_calc_frame_loss(l1t, l1cs, tn, fn);</span><br><span style="color: hsl(120, 100%, 40%);">+ trx_sched_calc_frame_loss(l1t, l1cs, bi->tn, bi->fn);</span><br><span> </span><br><span>      /* update TDMA frame counters */</span><br><span style="color: hsl(0, 100%, 40%);">-        l1cs->last_tdma_fn = fn;</span><br><span style="color: hsl(120, 100%, 40%);">+   l1cs->last_tdma_fn = bi->fn;</span><br><span>   l1cs->proc_tdma_fs++;</span><br><span> </span><br><span>         /* decrypt */</span><br><span style="color: hsl(0, 100%, 40%);">-   if (bits && l1cs->ul_encr_algo) {</span><br><span style="color: hsl(120, 100%, 40%);">+  if (bi->burst && l1cs->ul_encr_algo) {</span><br><span>                 ubit_t ks[114];</span><br><span>              int i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-              osmo_a5(l1cs->ul_encr_algo, l1cs->ul_encr_key, fn, NULL, ks);</span><br><span style="color: hsl(120, 100%, 40%);">+           osmo_a5(l1cs->ul_encr_algo, l1cs->ul_encr_key, bi->fn, NULL, ks);</span><br><span>           for (i = 0; i < 57; i++) {</span><br><span>                        if (ks[i])</span><br><span style="color: hsl(0, 100%, 40%);">-                              bits[i + 3] = - bits[i + 3];</span><br><span style="color: hsl(120, 100%, 40%);">+                          bi->burst[i + 3] = - bi->burst[i + 3];</span><br><span>                         if (ks[i + 57])</span><br><span style="color: hsl(0, 100%, 40%);">-                         bits[i + 88] = - bits[i + 88];</span><br><span style="color: hsl(120, 100%, 40%);">+                                bi->burst[i + 88] = - bi->burst[i + 88];</span><br><span>               }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* put burst to function */</span><br><span style="color: hsl(0, 100%, 40%);">-     func(l1t, tn, fn, chan, bid, bits, nbits, rssi, toa256);</span><br><span style="color: hsl(120, 100%, 40%);">+      /* put burst to function</span><br><span style="color: hsl(120, 100%, 40%);">+       * TODO: rather pass a pointer to trx_ul_burst_ind */</span><br><span style="color: hsl(120, 100%, 40%);">+ func(l1t, bi->tn, bi->fn, chan, bid, bi->burst, bi->burst_len, bi->rssi, bi->toa256);</span><br><span> </span><br><span>  return 0;</span><br><span> }</span><br><span>diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c</span><br><span>index fde4d50..e4abc8a 100644</span><br><span>--- a/src/osmo-bts-trx/trx_if.c</span><br><span>+++ b/src/osmo-bts-trx/trx_if.c</span><br><span>@@ -7,6 +7,7 @@</span><br><span>  *</span><br><span>  * Copyright (C) 2013  Andreas Eversberg <jolly@eversberg.eu></span><br><span>  * Copyright (C) 2016-2017  Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2019  Vadim Yanitskiy <axilirator@gmail.com></span><br><span>  *</span><br><span>  * All Rights Reserved</span><br><span>  *</span><br><span>@@ -590,65 +591,179 @@</span><br><span>  * TRX burst data socket</span><br><span>  */</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Common header length: 1/2 VER + 1/2 TDMA TN + 4 TDMA FN */</span><br><span style="color: hsl(120, 100%, 40%);">+#define TRX_CHDR_LEN (1 + 4)</span><br><span style="color: hsl(120, 100%, 40%);">+/* Uplink v0 header length: 1 RSSI + 2 ToA256 */</span><br><span style="color: hsl(120, 100%, 40%);">+#define TRX_UL_V0HDR_LEN (TRX_CHDR_LEN + 1 + 2)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* TRXD header dissector for version 0x00 */</span><br><span style="color: hsl(120, 100%, 40%);">+static int trx_data_handle_v0(struct trx_l1h *l1h,</span><br><span style="color: hsl(120, 100%, 40%);">+                              struct trx_ul_burst_ind *bi,</span><br><span style="color: hsl(120, 100%, 40%);">+                          const uint8_t *buf, size_t buf_len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  /* Make sure we have enough data */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (buf_len < TRX_UL_V0HDR_LEN) {</span><br><span style="color: hsl(120, 100%, 40%);">+          LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                   "Short read on TRXD, missing version 0 header "</span><br><span style="color: hsl(120, 100%, 40%);">+                     "(len=%zu vs expected %d)\n", buf_len, TRX_UL_V0HDR_LEN);</span><br><span style="color: hsl(120, 100%, 40%);">+           return -EIO;</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%);">+   bi->tn = buf[0] & 0b111;</span><br><span style="color: hsl(120, 100%, 40%);">+       bi->fn = osmo_load32be(buf + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+   bi->rssi = -(int8_t)buf[5];</span><br><span style="color: hsl(120, 100%, 40%);">+        bi->toa256 = (int16_t) osmo_load16be(buf + 6);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (bi->fn >= GSM_HYPERFRAME) {</span><br><span style="color: hsl(120, 100%, 40%);">+         LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                   "Illegal TDMA fn=%u\n", bi->fn);</span><br><span style="color: hsl(120, 100%, 40%);">+         return -EINVAL;</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%);">+   return TRX_UL_V0HDR_LEN;</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%);">+/* Parse TRXD message from transceiver, compose an UL burst indication.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This message contains a demodulated Uplink burst with fixed-size</span><br><span style="color: hsl(120, 100%, 40%);">+ * header preceding the burst bits. The header consists of the common</span><br><span style="color: hsl(120, 100%, 40%);">+ * and message specific part.</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%);">+ *   | common header | specific header | burst bits |</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%);">+ * Common header is the same as for Downlink message:</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%);">+ *   | VER (1/2 octet) | TN (1/2 octet) | FN (4 octets, BE) |</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%);">+ * and among with TDMA parameters, contains the version indicator:</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%);">+ *   | 7 6 5 4 3 2 1 0 | bit numbers            |</span><br><span style="color: hsl(120, 100%, 40%);">+ *   +-----------------+------------------------+</span><br><span style="color: hsl(120, 100%, 40%);">+ *   | X X X X . . . . | header version (0..15) |</span><br><span style="color: hsl(120, 100%, 40%);">+ *   +-----------------+------------------------+</span><br><span style="color: hsl(120, 100%, 40%);">+ *   | . . . . . X X X | TDMA TN (0..7)         |</span><br><span style="color: hsl(120, 100%, 40%);">+ *   +-----------------+------------------------+</span><br><span style="color: hsl(120, 100%, 40%);">+ *   | . . . . X . . . | RESERVED (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%);">+ * which is encoded in 4 MSB bits of the first octet, which used to be</span><br><span style="color: hsl(120, 100%, 40%);">+ * zero-initialized due to the value range of TDMA TN. Therefore, the</span><br><span style="color: hsl(120, 100%, 40%);">+ * old header format has implicit version 0x00.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * The message specific header has the following structure:</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * == Version 0x00</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%);">+ *   | RSSI | ToA | soft-bits (254..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%);">+ * where:</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ *   - RSSI (1 octet) - Received Signal Strength Indication</span><br><span style="color: hsl(120, 100%, 40%);">+ *     encoded without the negative sign.</span><br><span style="color: hsl(120, 100%, 40%);">+ *   - ToA (2 octets) - Timing of Arrival in units of 1/256</span><br><span style="color: hsl(120, 100%, 40%);">+ *     of symbol (big endian).</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * == Coding of the burst bits</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Unlike to be transmitted bursts, the received bursts are designated</span><br><span style="color: hsl(120, 100%, 40%);">+ * using the soft-bits notation, so the receiver can indicate its</span><br><span style="color: hsl(120, 100%, 40%);">+ * assurance from 0 to -127 that a given bit is 1, and from 0 to +127</span><br><span style="color: hsl(120, 100%, 40%);">+ * that a given bit is 0.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Each soft-bit (-127..127) of the burst is encoded as an unsigned</span><br><span style="color: hsl(120, 100%, 40%);">+ * value in range (254..0) respectively using the constant shift.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span> static int trx_data_read_cb(struct osmo_fd *ofd, unsigned int what)</span><br><span> {</span><br><span>       struct trx_l1h *l1h = ofd->data;</span><br><span>  uint8_t buf[TRX_MAX_BURST_LEN];</span><br><span style="color: hsl(0, 100%, 40%);">- int len;</span><br><span style="color: hsl(0, 100%, 40%);">-        uint8_t tn;</span><br><span style="color: hsl(0, 100%, 40%);">-     int8_t rssi;</span><br><span style="color: hsl(0, 100%, 40%);">-    int16_t toa256 = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-     uint32_t fn;</span><br><span>         sbit_t bits[EGPRS_BURST_LEN];</span><br><span style="color: hsl(0, 100%, 40%);">-   int i, burst_len = GSM_BURST_LEN;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct trx_ul_burst_ind bi;</span><br><span style="color: hsl(120, 100%, 40%);">+   ssize_t hdr_len, buf_len;</span><br><span style="color: hsl(120, 100%, 40%);">+     uint8_t *burst_bits;</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t hdr_ver;</span><br><span style="color: hsl(120, 100%, 40%);">+      int i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-      len = recv(ofd->fd, buf, sizeof(buf), 0);</span><br><span style="color: hsl(0, 100%, 40%);">-    if (len <= 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-              return len;</span><br><span style="color: hsl(0, 100%, 40%);">-     } else if (len == EGPRS_BURST_LEN + 10) {</span><br><span style="color: hsl(0, 100%, 40%);">-               burst_len = EGPRS_BURST_LEN;</span><br><span style="color: hsl(0, 100%, 40%);">-    /* Accept bursts ending with 2 bytes of padding (OpenBTS compatible trx) or without them: */</span><br><span style="color: hsl(0, 100%, 40%);">-    } else if (len != GSM_BURST_LEN + 10 && len != GSM_BURST_LEN + 8) {</span><br><span style="color: hsl(0, 100%, 40%);">-             LOGPPHI(l1h->phy_inst, DTRX, LOGL_NOTICE, "Got data message with invalid lenght "</span><br><span style="color: hsl(0, 100%, 40%);">-                  "'%d'\n", len);</span><br><span style="color: hsl(120, 100%, 40%);">+     buf_len = recv(ofd->fd, buf, sizeof(buf), 0);</span><br><span style="color: hsl(120, 100%, 40%);">+      if (buf_len <= 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                   "recv() failed on TRXD with rc=%zd\n", buf_len);</span><br><span style="color: hsl(120, 100%, 40%);">+            return buf_len;</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%);">+   /* Parse the header depending on its version */</span><br><span style="color: hsl(120, 100%, 40%);">+       hdr_ver = buf[0] >> 4;</span><br><span style="color: hsl(120, 100%, 40%);">+  switch (hdr_ver) {</span><br><span style="color: hsl(120, 100%, 40%);">+    case 0x00:</span><br><span style="color: hsl(120, 100%, 40%);">+            /* Legacy protocol has no version indicator */</span><br><span style="color: hsl(120, 100%, 40%);">+                hdr_len = trx_data_handle_v0(l1h, &bi, buf, buf_len);</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                   "TRXD header version %u is not supported\n", hdr_ver);</span><br><span style="color: hsl(120, 100%, 40%);">+              return -ENOTSUP;</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%);">+   /* Header parsing error */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (hdr_len < 0)</span><br><span style="color: hsl(120, 100%, 40%);">+           return hdr_len;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* We're done with the header now */</span><br><span style="color: hsl(120, 100%, 40%);">+      burst_bits = buf + hdr_len;</span><br><span style="color: hsl(120, 100%, 40%);">+   buf_len -= hdr_len;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Verify burst length */</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (buf_len) {</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Legacy transceivers append two padding bytes */</span><br><span style="color: hsl(120, 100%, 40%);">+    case EGPRS_BURST_LEN + 2:</span><br><span style="color: hsl(120, 100%, 40%);">+     case GSM_BURST_LEN + 2:</span><br><span style="color: hsl(120, 100%, 40%);">+               buf_len -= 2;</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case EGPRS_BURST_LEN:</span><br><span style="color: hsl(120, 100%, 40%);">+ case GSM_BURST_LEN:</span><br><span style="color: hsl(120, 100%, 40%);">+           break;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      default:</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGPPHI(l1h->phy_inst, DTRX, LOGL_NOTICE,</span><br><span style="color: hsl(120, 100%, 40%);">+                  "Rx TRXD message with odd burst length %zu\n", buf_len);</span><br><span>           return -EINVAL;</span><br><span>      }</span><br><span style="color: hsl(0, 100%, 40%);">-       tn = buf[0];</span><br><span style="color: hsl(0, 100%, 40%);">-    fn =  osmo_load32be(buf + 1);</span><br><span style="color: hsl(0, 100%, 40%);">-   rssi = -(int8_t)buf[5];</span><br><span style="color: hsl(0, 100%, 40%);">- toa256 = (int16_t) osmo_load16be(buf + 6);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  /* copy and convert bits {254..0} to sbits {-127..127} */</span><br><span style="color: hsl(0, 100%, 40%);">-       for (i = 0; i < burst_len; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-            if (buf[8 + i] == 255)</span><br><span style="color: hsl(120, 100%, 40%);">+        /* Convert unsigned soft-bits [254..0] to soft-bits [-127..127] */</span><br><span style="color: hsl(120, 100%, 40%);">+    for (i = 0; i < buf_len; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (burst_bits[i] == 255)</span><br><span>                    bits[i] = -127;</span><br><span>              else</span><br><span style="color: hsl(0, 100%, 40%);">-                    bits[i] = 127 - buf[8 + i];</span><br><span style="color: hsl(120, 100%, 40%);">+                   bits[i] = 127 - burst_bits[i];</span><br><span>       }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (tn >= 8) {</span><br><span style="color: hsl(0, 100%, 40%);">-               LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Illegal TS %d\n", tn);</span><br><span style="color: hsl(0, 100%, 40%);">-           return -EINVAL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-       if (fn >= GSM_HYPERFRAME) {</span><br><span style="color: hsl(0, 100%, 40%);">-          LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Illegal FN %u\n", fn);</span><br><span style="color: hsl(0, 100%, 40%);">-           return -EINVAL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+     bi.burst_len = buf_len;</span><br><span style="color: hsl(120, 100%, 40%);">+       bi.burst = bits;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    LOGPPHI(l1h->phy_inst, DTRX, LOGL_DEBUG, "RX burst tn=%u fn=%u rssi=%d toa256=%d\n",</span><br><span style="color: hsl(0, 100%, 40%);">-               tn, fn, rssi, toa256);</span><br><span style="color: hsl(120, 100%, 40%);">+        LOGPPHI(l1h->phy_inst, DTRX, LOGL_DEBUG,</span><br><span style="color: hsl(120, 100%, 40%);">+           "Rx UL burst (hdr_ver=%u) tn=%u fn=%u rssi=%d toa256=%d\n",</span><br><span style="color: hsl(120, 100%, 40%);">+         hdr_ver, bi.tn, bi.fn, bi.rssi, bi.toa256);</span><br><span> </span><br><span> #ifdef TOA_RSSI_DEBUG</span><br><span>     char deb[128];</span><br><span> </span><br><span>   sprintf(deb, "|                                0              "</span><br><span style="color: hsl(0, 100%, 40%);">-               "                 | rssi=%4d  toa=%5d fn=%u", rssi, toa256, fn);</span><br><span style="color: hsl(0, 100%, 40%);">-      deb[1 + (128 + rssi) / 4] = '*';</span><br><span style="color: hsl(120, 100%, 40%);">+              "                 | rssi=%4d  toa=%5d fn=%u",</span><br><span style="color: hsl(120, 100%, 40%);">+               bi.rssi, bi.toa256, bi.fn);</span><br><span style="color: hsl(120, 100%, 40%);">+   deb[1 + (128 + bi.rssi) / 4] = '*';</span><br><span>  fprintf(stderr, "%s\n", deb);</span><br><span> #endif</span><br><span> </span><br><span>        /* feed received burst into scheduler code */</span><br><span style="color: hsl(0, 100%, 40%);">-   trx_sched_ul_burst(&l1h->l1s, tn, fn, bits, burst_len, rssi, toa256);</span><br><span style="color: hsl(120, 100%, 40%);">+  trx_sched_ul_burst(&l1h->l1s, &bi);</span><br><span> </span><br><span>   return 0;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bts/+/14592">change 14592</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-bts/+/14592"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-bts </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I171c18229ca3e5cab70de0064a31e47c78602c0c </div>
<div style="display:none"> Gerrit-Change-Number: 14592 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>