lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

October 2025

  • 1 participants
  • 631 discussions
[M] Change in libosmocore[master]: AMR codec: add conversion between s-bits and codec parameters
by falconia 26 Oct '25

26 Oct '25
falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/41256?usp=email ) Change subject: AMR codec: add conversion between s-bits and codec parameters ...................................................................... AMR codec: add conversion between s-bits and codec parameters At the lowest level of frame information content, before introducing higher layers of RTP or TRAU frame or other encoding, an AMR codec frame (speech or SID) can be represented in 3 fundamental ways: * 35 to 244 s-bits as defined theoretically in TS 26.090 & 26.092 and used in practice in 2G TRAU frames; * 39 to 244 d-bits as defined theoretically in TS 26.101 and used in practice in 3G IuUP and in RTP; * 5 to 57 codec parameters, each fitting into uint16_t, as implemented in 3GPP reference C code (TS 26.073) and assumed by the same spec in its listing of decoder homing frame bit patterns. libosmocodec previously provided conversion functions between s-bits and d-bits, as well as a table that gives the number of d-bits per mode - but no conversion to or from arrays of codec parameters. Add the latter functionality. Change-Id: I28eae702204d7f7ff164e17c5e26152a94a12cba --- M include/osmocom/codec/codec.h M src/codec/gsm690.c 2 files changed, 198 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/56/41256/1 diff --git a/include/osmocom/codec/codec.h b/include/osmocom/codec/codec.h index 008eab1..b697cfb 100644 --- a/include/osmocom/codec/codec.h +++ b/include/osmocom/codec/codec.h @@ -90,6 +90,14 @@ } } +extern const uint8_t osmo_amr_sbits_per_mode[AMR_NO_DATA+1]; +extern const uint8_t osmo_amr_params_per_mode[AMR_NO_DATA+1]; + +int osmo_amr_param_to_sbits(ubit_t *s_bits, const uint16_t *param, + enum osmo_amr_type mode); +int osmo_amr_sbits_to_param(uint16_t *param, const ubit_t *s_bits, + enum osmo_amr_type mode); + /* SID ternary classification per GSM 06.31 & 06.81 section 6.1.1 */ enum osmo_gsm631_sid_class { OSMO_GSM631_SID_CLASS_SPEECH = 0, diff --git a/src/codec/gsm690.c b/src/codec/gsm690.c index 3b2e669..5730718 100644 --- a/src/codec/gsm690.c +++ b/src/codec/gsm690.c @@ -322,6 +322,196 @@ return n_bits; } +/*! This table provides the number of s-bits (as defined in TS 26.090 and + * TS 26.092, clause 7 in each spec) for every possible speech or SID mode + * in AMR. It differs from gsm690_bitlength[] in the case of SID: there are + * 35 s-bits in the original 2G definition that started out as GSM 06.92, + * captured in this table, whereas 3G-oriented TS 26.101 AMR Core Frame + * definition captured in gsm690_bitlength[] has 39 d-bits for SID instead. + * + * The array is allocated up to AMR_NO_DATA in order to reduce the probability + * of buggy code making an out-of-bounds read access. + */ +const uint8_t osmo_amr_sbits_per_mode[AMR_NO_DATA+1] = { + [AMR_4_75] = 95, + [AMR_5_15] = 103, + [AMR_5_90] = 118, + [AMR_6_70] = 134, + [AMR_7_40] = 148, + [AMR_7_95] = 159, + [AMR_10_2] = 204, + [AMR_12_2] = 244, + [AMR_SID] = 35, +}; + +/*! This table provides the number of distinct codec parameters (groupings + * of s-bits into 16-bit parameter words as implemented in 3GPP reference + * C code and assumed in TS 26.073 definition of decoder homing frames) + * that exist for every possible speech or SID mode in AMR. + * + * The array is allocated up to AMR_NO_DATA in order to reduce the probability + * of buggy code making an out-of-bounds read access. + */ +const uint8_t osmo_amr_params_per_mode[AMR_NO_DATA+1] = { + [AMR_4_75] = 17, + [AMR_5_15] = 19, + [AMR_5_90] = 19, + [AMR_6_70] = 19, + [AMR_7_40] = 19, + [AMR_7_95] = 23, + [AMR_10_2] = 39, + [AMR_12_2] = 57, + [AMR_SID] = 5, +}; + +/* parameter sizes (# of bits), one table per mode */ + +static const uint8_t bit_counts_4_75[17] = { + 8, 8, 7, /* LSP VQ */ + 8, 7, 2, 8, /* 1st subframe */ + 4, 7, 2, /* 2nd subframe */ + 4, 7, 2, 8, /* 3rd subframe */ + 4, 7, 2, /* 4th subframe */ +}; + +static const uint8_t bit_counts_5_15[19] = { + 8, 8, 7, /* LSP VQ */ + 8, 7, 2, 6, /* 1st subframe */ + 4, 7, 2, 6, /* 2nd subframe */ + 4, 7, 2, 6, /* 3rd subframe */ + 4, 7, 2, 6, /* 4th subframe */ +}; + +static const uint8_t bit_counts_5_90[19] = { + 8, 9, 9, /* LSP VQ */ + 8, 9, 2, 6, /* 1st subframe */ + 4, 9, 2, 6, /* 2nd subframe */ + 8, 9, 2, 6, /* 3rd subframe */ + 4, 9, 2, 6, /* 4th subframe */ +}; + +static const uint8_t bit_counts_6_70[19] = { + 8, 9, 9, /* LSP VQ */ + 8, 11, 3, 7, /* 1st subframe */ + 4, 11, 3, 7, /* 2nd subframe */ + 8, 11, 3, 7, /* 3rd subframe */ + 4, 11, 3, 7, /* 4th subframe */ +}; + +static const uint8_t bit_counts_7_40[19] = { + 8, 9, 9, /* LSP VQ */ + 8, 13, 4, 7, /* 1st subframe */ + 5, 13, 4, 7, /* 2nd subframe */ + 8, 13, 4, 7, /* 3rd subframe */ + 5, 13, 4, 7, /* 4th subframe */ +}; + +static const uint8_t bit_counts_7_95[23] = { + 9, 9, 9, /* LSP VQ */ + 8, 13, 4, 4, 5, /* 1st subframe */ + 6, 13, 4, 4, 5, /* 2nd subframe */ + 8, 13, 4, 4, 5, /* 3rd subframe */ + 6, 13, 4, 4, 5, /* 4th subframe */ +}; + +static const uint8_t bit_counts_10_2[39] = { + 8, 9, 9, /* LSP VQ */ + 8, 1, 1, 1, 1, 10, 10, 7, 7, /* 1st subframe */ + 5, 1, 1, 1, 1, 10, 10, 7, 7, /* 2nd subframe */ + 8, 1, 1, 1, 1, 10, 10, 7, 7, /* 3rd subframe */ + 5, 1, 1, 1, 1, 10, 10, 7, 7, /* 4th subframe */ +}; + +static const uint8_t bit_counts_12_2[57] = { + 7, 8, 9, 8, 6, /* LSP VQ */ + 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* 1st subframe */ + 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* 2nd subframe */ + 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* 3rd subframe */ + 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* 4th subframe */ +}; + +static const uint8_t bit_counts_sid[5] = { 3, 8, 9, 9, 6 }; + +/* overall table with all parameter sizes for all modes */ +static const uint8_t * const bit_counts_per_mode[AMR_SID + 1] = { + bit_counts_4_75, + bit_counts_5_15, + bit_counts_5_90, + bit_counts_6_70, + bit_counts_7_40, + bit_counts_7_95, + bit_counts_10_2, + bit_counts_12_2, + bit_counts_sid, +}; + +/*! Convert AMR codec frame from parameters to s-bits + * + * \param[out] s_bits Caller-provided array of unpacked bits to be filled + * with s-bits of the converted codec frame. + * \param[in] param Array of AMR codec speech or SID parameters. + * \param[in] mode Speech or SID mode according to which conversion shall + * be performed. + * \returns 0 if successful, or negative if \ref mode is invalid. + */ +int osmo_amr_param_to_sbits(ubit_t *s_bits, const uint16_t *param, + enum osmo_amr_type mode) +{ + if (mode > AMR_SID) + return -EINVAL; + + const uint8_t *table = bit_counts_per_mode[mode]; + unsigned nparam = osmo_amr_params_per_mode[mode]; + unsigned n, p, mask; + ubit_t *b = s_bits; + + for (n = 0; n < nparam; n++) { + p = param[n]; + mask = 1 << (*table++ - 1); + for (; mask; mask >>= 1) { + if (p & mask) + *b++ = 1; + else + *b++ = 0; + } + } + return 0; +} + +/*! Convert AMR codec frame from s-bits to parameters + * + * \param[out] param Caller-provided buffer for array of AMR codec speech + * or SID parameters. + * \param[in] s_bits Unpacked s-bits of the frame to be converted. + * \param[in] mode Speech or SID mode according to which conversion shall + * be performed. + * \returns 0 if successful, or negative if \ref mode is invalid. + */ +int osmo_amr_sbits_to_param(uint16_t *param, const ubit_t *s_bits, + enum osmo_amr_type mode) +{ + if (mode > AMR_SID) + return -EINVAL; + + const ubit_t *bit = s_bits; + const uint8_t *table = bit_counts_per_mode[mode]; + unsigned nparam = osmo_amr_params_per_mode[mode]; + unsigned n, m, acc; + + for (n = 0; n < nparam; n++) { + acc = 0; + for (m = 0; m < *table; m++) { + acc <<= 1; + if (*bit) + acc |= 1; + bit++; + } + param[n] = acc; + table++; + } + return 0; +} + /* See also RFC 4867 §3.6, Table 1, Column "Total speech bits" */ static const uint8_t amr_len_by_ft[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/41256?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I28eae702204d7f7ff164e17c5e26152a94a12cba Gerrit-Change-Number: 41256 Gerrit-PatchSet: 1 Gerrit-Owner: falconia <falcon(a)freecalypso.org>
1 0
0 0
[M] Change in libosmocore[master]: AMR codec: add decoder homing frame const patterns
by falconia 26 Oct '25

26 Oct '25
falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/41257?usp=email ) Change subject: AMR codec: add decoder homing frame const patterns ...................................................................... AMR codec: add decoder homing frame const patterns ETSI-defined decoder homing frames for HRv1 and EFR are already captured in osmo_gsm620_homing_frame[] and osmo_gsm660_homing_frame[]; now add 3GPP-defined DHFs for AMR, all 8 modes. These AMR DHFs are useful to have in libosmocodec: * Future AMR-capable tw-e1abis-mgw will emit DHFs toward the BTS/CCU during prolonged absence of RTP input - needed because the alternative of emitting an endless stream of No_Data frames may produce undesirable effects on Um with some E1 BTS models. If it is desired to bring tw-e1abis-mgw functionality into mainline Osmocom at some point, DHF bits need to reside somewhere in libosmo*. * In future improvements of AMR support in osmo-bts-trx, it may be likewise desirable to transmit DHFs on Um downlink during the same conditions of prolonged absence of RTP input. Change-Id: I1f8f8ec36cc13270a1d1fa633583107317abe894 --- M include/osmocom/codec/codec.h M src/codec/gsm690.c 2 files changed, 75 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/57/41257/1 diff --git a/include/osmocom/codec/codec.h b/include/osmocom/codec/codec.h index b697cfb..8ec9e62 100644 --- a/include/osmocom/codec/codec.h +++ b/include/osmocom/codec/codec.h @@ -98,6 +98,15 @@ int osmo_amr_sbits_to_param(uint16_t *param, const ubit_t *s_bits, enum osmo_amr_type mode); +extern const uint16_t osmo_amr_dhf_4_75[]; +extern const uint16_t osmo_amr_dhf_5_15[]; +extern const uint16_t osmo_amr_dhf_5_90[]; +extern const uint16_t osmo_amr_dhf_6_70[]; +extern const uint16_t osmo_amr_dhf_7_40[]; +extern const uint16_t osmo_amr_dhf_7_95[]; +extern const uint16_t osmo_amr_dhf_10_2[]; +extern const uint16_t osmo_amr_dhf_12_2[]; + /* SID ternary classification per GSM 06.31 & 06.81 section 6.1.1 */ enum osmo_gsm631_sid_class { OSMO_GSM631_SID_CLASS_SPEECH = 0, diff --git a/src/codec/gsm690.c b/src/codec/gsm690.c index 5730718..fc7e584 100644 --- a/src/codec/gsm690.c +++ b/src/codec/gsm690.c @@ -512,6 +512,72 @@ return 0; } +/* For each of the 8 modes of AMR codec, there exists a special encoded frame + * bit pattern which the speech decoder is required to recognize as a special + * decoder homing frame (DHF), as specified in TS 26.090 section 8.4. Bit + * patterns of these 8 DHFs are specified in TS 26.073 Tables 9a through 9h + * and captured in the following const arrays. Note that the canonical form + * of each DHF is an array of codec parameters; in order to emit any of these + * DHFs as an RTP payload or a TRAU frame, the application will need to + * convert it to s-bits with osmo_amr_param_to_sbits(), followed by + * osmo_amr_s_to_d() in the case of RTP output. + */ + +const uint16_t osmo_amr_dhf_4_75[17] = { + 0x00F8, 0x009D, 0x001C, 0x0066, 0x0000, 0x0003, 0x0028, 0x000F, + 0x0038, 0x0001, 0x000F, 0x0031, 0x0002, 0x0008, 0x000F, 0x0026, + 0x0003 +}; + +const uint16_t osmo_amr_dhf_5_15[19] = { + 0x00F8, 0x009D, 0x001C, 0x0066, 0x0000, 0x0003, 0x0037, 0x000F, + 0x0000, 0x0003, 0x0005, 0x000F, 0x0037, 0x0003, 0x0037, 0x000F, + 0x0023, 0x0003, 0x001F +}; + +const uint16_t osmo_amr_dhf_5_90[19] = { + 0x00F8, 0x00E3, 0x002F, 0x00BD, 0x0000, 0x0003, 0x0037, 0x000F, + 0x0001, 0x0003, 0x000F, 0x0060, 0x00F9, 0x0003, 0x0037, 0x000F, + 0x0000, 0x0003, 0x0037 +}; + +const uint16_t osmo_amr_dhf_6_70[19] = { + 0x00F8, 0x00E3, 0x002F, 0x00BD, 0x0002, 0x0007, 0x0000, 0x000F, + 0x0098, 0x0007, 0x0061, 0x0060, 0x05C5, 0x0007, 0x0000, 0x000F, + 0x0318, 0x0007, 0x0000 +}; + +const uint16_t osmo_amr_dhf_7_40[19] = { + 0x00F8, 0x00E3, 0x002F, 0x00BD, 0x0006, 0x000F, 0x0000, 0x001B, + 0x0208, 0x000F, 0x0062, 0x0060, 0x1BA6, 0x000F, 0x0000, 0x001B, + 0x0006, 0x000F, 0x0000 +}; + +const uint16_t osmo_amr_dhf_7_95[23] = { + 0x00C2, 0x00E3, 0x002F, 0x00BD, 0x0006, 0x000F, 0x000A, 0x0000, + 0x0039, 0x1C08, 0x0007, 0x000A, 0x000B, 0x0063, 0x11A6, 0x000F, + 0x0001, 0x0000, 0x0039, 0x09A0, 0x000F, 0x0002, 0x0001 +}; + +const uint16_t osmo_amr_dhf_10_2[39] = { + 0x00F8, 0x00E3, 0x002F, 0x0045, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x001B, 0x0000, 0x0001, 0x0000, + 0x0001, 0x0326, 0x00CE, 0x007E, 0x0051, 0x0062, 0x0000, 0x0000, + 0x0000, 0x0000, 0x015A, 0x0359, 0x0076, 0x0000, 0x001B, 0x0000, + 0x0000, 0x0000, 0x0000, 0x017C, 0x0215, 0x0038, 0x0030 +}; + +const uint16_t osmo_amr_dhf_12_2[57] = { + 0x0004, 0x002A, 0x00DB, 0x0096, 0x002A, 0x0156, 0x000B, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0036, 0x000B, 0x0000, 0x000F, 0x000E, 0x000C, + 0x000D, 0x0000, 0x0001, 0x0005, 0x0007, 0x0001, 0x0008, 0x0024, + 0x0000, 0x0001, 0x0000, 0x0005, 0x0006, 0x0001, 0x0002, 0x0004, + 0x0007, 0x0004, 0x0002, 0x0003, 0x0036, 0x000B, 0x0000, 0x0002, + 0x0004, 0x0000, 0x0003, 0x0006, 0x0001, 0x0007, 0x0006, 0x0005, + 0x0000 +}; + /* See also RFC 4867 §3.6, Table 1, Column "Total speech bits" */ static const uint8_t amr_len_by_ft[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/41257?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I1f8f8ec36cc13270a1d1fa633583107317abe894 Gerrit-Change-Number: 41257 Gerrit-PatchSet: 1 Gerrit-Owner: falconia <falcon(a)freecalypso.org>
1 0
0 0
[L] Change in pysim[master]: pySim-shell: add a logger class to centralize logging
by laforge 25 Oct '25

25 Oct '25
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/41229?usp=email ) Change subject: pySim-shell: add a logger class to centralize logging ...................................................................... pySim-shell: add a logger class to centralize logging In many sub modules we still use print() to occassionally print status messages or warnings. This technically does not hurt, but it is an unclean solution which we should replace with something more mature. Let's use python's built in logging framework to create a static logger class that fits our needs. To maintain compatibility let's also make sure that the logger class will behave like a normal print() statement when no configuration parameters are supplied by the API user. To illustrate how the approach can be used in sub-modules, this patch replaces the print statements in runtime.py. The other print statements will the be fixed in follow-up patches. Related: OS#6864 Change-Id: I187f117e7e1ccdb2a85dfdfb18e84bd7561704eb --- M pySim-shell.py A pySim/log.py M pySim/runtime.py M tests/pySim-trace_test/pySim-trace_test_gsmtap.pcapng.ok A tests/unittests/test_log.py 5 files changed, 289 insertions(+), 13 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/pySim-shell.py b/pySim-shell.py index 977666c..5a2e4b6 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -22,19 +22,24 @@ import json import traceback import re - import cmd2 from packaging import version from cmd2 import style + +import logging +from pySim.log import PySimLogger + # cmd2 >= 2.3.0 has deprecated the bg/fg in favor of Bg/Fg :( if version.parse(cmd2.__version__) < version.parse("2.3.0"): from cmd2 import fg, bg # pylint: disable=no-name-in-module RED = fg.red + YELLOW = fg.yellow LIGHT_RED = fg.bright_red LIGHT_GREEN = fg.bright_green else: from cmd2 import Fg, Bg # pylint: disable=no-name-in-module RED = Fg.RED + YELLOW = Fg.YELLOW LIGHT_RED = Fg.LIGHT_RED LIGHT_GREEN = Fg.LIGHT_GREEN from cmd2 import CommandSet, with_default_category, with_argparser @@ -67,6 +72,7 @@ from pySim.app import init_card +log = PySimLogger.get("main") class Cmd2Compat(cmd2.Cmd): """Backwards-compatibility wrapper around cmd2.Cmd to support older and newer @@ -92,15 +98,19 @@ (C) 2021-2023 by Harald Welte, sysmocom - s.f.m.c. GmbH and contributors Online manual available at https://downloads.osmocom.org/docs/pysim/master/html/shell.html """ - def __init__(self, card, rs, sl, ch, script=None): + def __init__(self, verbose, card, rs, sl, ch, script=None): if version.parse(cmd2.__version__) < version.parse("2.0.0"): kwargs = {'use_ipython': True} else: kwargs = {'include_ipy': True} + self.verbose = verbose + self._onchange_verbose('verbose', False, self.verbose); + # pylint: disable=unexpected-keyword-arg super().__init__(persistent_history_file='~/.pysim_shell_history', allow_cli_args=False, auto_load_commands=False, startup_script=script, **kwargs) + PySimLogger.setup(self.poutput, {logging.WARN: YELLOW}) self.intro = style(self.BANNER, fg=RED) self.default_category = 'pySim-shell built-in commands' self.card = None @@ -126,6 +136,9 @@ self.add_settable(Settable2Compat('apdu_strict', bool, 'Enforce APDU responses according to ISO/IEC 7816-3, table 12', self, onchange_cb=self._onchange_apdu_strict)) + self.add_settable(Settable2Compat('verbose', bool, + 'Enable/disable verbose logging', self, + onchange_cb=self._onchange_verbose)) self.equip(card, rs) def equip(self, card, rs): @@ -210,6 +223,13 @@ else: self.card._scc._tp.apdu_strict = False + def _onchange_verbose(self, param_name, old, new): + PySimLogger.set_verbose(new) + if new == True: + PySimLogger.set_level(logging.DEBUG) + else: + PySimLogger.set_level() + class Cmd2ApduTracer(ApduTracer): def __init__(self, cmd2_app): self.cmd2 = cmd2_app @@ -1081,6 +1101,8 @@ action='store_true', default=False) global_group.add_argument("--skip-card-init", help="Skip all card/profile initialization", action='store_true', default=False) +global_group.add_argument("--verbose", help="Enable verbose logging", + action='store_true', default=False) adm_group = global_group.add_mutually_exclusive_group() adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM1', dest='pin_adm', default=None, @@ -1095,12 +1117,16 @@ option_parser.add_argument('command_args', nargs=argparse.REMAINDER, help="Optional Arguments for command") - if __name__ == '__main__': - startup_errors = False opts = option_parser.parse_args() + # Ensure that we are able to print formatted warnings from the beginning. + PySimLogger.setup(print, {logging.WARN: YELLOW}) + if (opts.verbose): + PySimLogger.set_verbose(True) + PySimLogger.set_level(logging.DEBUG) + # Register csv-file as card data provider, either from specified CSV # or from CSV file in home directory csv_column_keys = {} @@ -1127,7 +1153,7 @@ # able to tolerate and recover from that. try: rs, card = init_card(sl, opts.skip_card_init) - app = PysimApp(card, rs, sl, ch) + app = PysimApp(opts.verbose, card, rs, sl, ch) except: startup_errors = True print("Card initialization (%s) failed with an exception:" % str(sl)) @@ -1139,7 +1165,7 @@ print(" it should also be noted that some readers may behave strangely when no card") print(" is inserted.)") print("") - app = PysimApp(None, None, sl, ch) + app = PysimApp(opts.verbose, None, None, sl, ch) # If the user supplies an ADM PIN at via commandline args authenticate # immediately so that the user does not have to use the shell commands diff --git a/pySim/log.py b/pySim/log.py new file mode 100644 index 0000000..997627f --- /dev/null +++ b/pySim/log.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- + +""" pySim: Logging +""" + +# +# (C) 2025 by Sysmocom s.f.m.c. GmbH +# All Rights Reserved +# +# Author: Philipp Maier <pmaier(a)sysmocom.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import logging +from cmd2 import style + +class _PySimLogHandler(logging.Handler): + def __init__(self, log_callback): + super().__init__() + self.log_callback = log_callback + + def emit(self, record): + formatted_message = self.format(record) + self.log_callback(formatted_message, record) + +class PySimLogger: + """ + Static class to centralize the log output of PySim applications. This class can be used to print log messages from + any pySim module. Configuration of the log behaviour (see setup and set_ methods) is entirely optional. In case no + print callback is set (see setup method), the logger will pass the log messages directly to print() without applying + any formatting to the original log message. + """ + + LOG_FMTSTR = "%(levelname)s: %(message)s" + LOG_FMTSTR_VERBOSE = "%(module)s.%(lineno)d -- %(name)s - " + LOG_FMTSTR + __formatter = logging.Formatter(LOG_FMTSTR) + __formatter_verbose = logging.Formatter(LOG_FMTSTR_VERBOSE) + + # No print callback by default, means that log messages are passed directly to print() + print_callback = None + + # No specific color scheme by default + colors = {} + + # The logging default is non-verbose logging on logging level DEBUG. This is a safe default that works for + # applications that ignore the presence of the PySimLogger class. + verbose = False + logging.root.setLevel(logging.DEBUG) + + def __init__(self): + raise RuntimeError('static class, do not instantiate') + + @staticmethod + def setup(print_callback = None, colors:dict = {}): + """ + Set a print callback function and color scheme. This function call is optional. In case this method is not + called, default settings apply. + Args: + print_callback : A callback function that accepts the resulting log string as input. The callback should + have the following format: print_callback(message:str) + colors : An optional dict through which certain log levels can be assigned a color. + (e.g. {logging.WARN: YELLOW}) + """ + PySimLogger.print_callback = print_callback + PySimLogger.colors = colors + + @staticmethod + def set_verbose(verbose:bool = False): + """ + Enable/disable verbose logging. (has no effect in case no print callback is set, see method setup) + Args: + verbose: verbosity (True = verbose logging, False = normal logging) + """ + PySimLogger.verbose = verbose; + + @staticmethod + def set_level(level:int = logging.DEBUG): + """ + Set the logging level. + Args: + level: Logging level, valis log leves are: DEBUG, INFO, WARNING, ERROR and CRITICAL + """ + logging.root.setLevel(level) + + @staticmethod + def _log_callback(message, record): + if not PySimLogger.print_callback: + # In case no print callback has been set display the message as if it were printed trough a normal + # python print statement. + print(record.message) + else: + # When a print callback is set, use it to display the log line. Apply color if the API user chose one + if PySimLogger.verbose: + formatted_message = logging.Formatter.format(PySimLogger.__formatter_verbose, record) + else: + formatted_message = logging.Formatter.format(PySimLogger.__formatter, record) + color = PySimLogger.colors.get(record.levelno) + if color: + PySimLogger.print_callback(style(formatted_message, fg = color)) + else: + PySimLogger.print_callback(formatted_message) + + @staticmethod + def get(log_facility: str): + """ + Set up and return a new python logger object + Args: + log_facility : Name of log facility (e.g. "MAIN", "RUNTIME"...) + """ + logger = logging.getLogger(log_facility) + handler = _PySimLogHandler(log_callback=PySimLogger._log_callback) + logger.addHandler(handler) + return logger diff --git a/pySim/runtime.py b/pySim/runtime.py index 5bb730e..ab21912 100644 --- a/pySim/runtime.py +++ b/pySim/runtime.py @@ -23,6 +23,9 @@ from pySim.exceptions import * from pySim.filesystem import * +from pySim.log import PySimLogger + +log = PySimLogger.get("RUNTIME") def lchan_nr_from_cla(cla: int) -> int: """Resolve the logical channel number from the CLA byte.""" @@ -44,6 +47,7 @@ card : pysim.cards.Card instance profile : CardProfile instance """ + self.mf = CardMF(profile=profile) self.card = card self.profile = profile @@ -66,7 +70,7 @@ for addon_cls in self.profile.addons: addon = addon_cls() if addon.probe(self.card): - print("Detected %s Add-on \"%s\"" % (self.profile, addon)) + log.info("Detected %s Add-on \"%s\"" % (self.profile, addon)) for f in addon.files_in_mf: self.mf.add_file(f) @@ -100,18 +104,18 @@ apps_taken = [] if aids_card: aids_taken = [] - print("AIDs on card:") + log.info("AIDs on card:") for a in aids_card: for f in apps_profile: if f.aid in a: - print(" %s: %s (EF.DIR)" % (f.name, a)) + log.info(" %s: %s (EF.DIR)" % (f.name, a)) aids_taken.append(a) apps_taken.append(f) aids_unknown = set(aids_card) - set(aids_taken) for a in aids_unknown: - print(" unknown: %s (EF.DIR)" % a) + log.info(" unknown: %s (EF.DIR)" % a) else: - print("warning: EF.DIR seems to be empty!") + log.warn("EF.DIR seems to be empty!") # Some card applications may not be registered in EF.DIR, we will actively # probe for those applications @@ -126,7 +130,7 @@ _data, sw = self.card.select_adf_by_aid(f.aid) self.selected_adf = f if sw == "9000": - print(" %s: %s" % (f.name, f.aid)) + log.info(" %s: %s" % (f.name, f.aid)) apps_taken.append(f) except (SwMatchError, ProtocolError): pass diff --git a/tests/pySim-trace_test/pySim-trace_test_gsmtap.pcapng.ok b/tests/pySim-trace_test/pySim-trace_test_gsmtap.pcapng.ok index 395acbf..423f25e 100644 --- a/tests/pySim-trace_test/pySim-trace_test_gsmtap.pcapng.ok +++ b/tests/pySim-trace_test/pySim-trace_test_gsmtap.pcapng.ok @@ -2,7 +2,7 @@ Detected UICC Add-on "GSM-R" Detected UICC Add-on "RUIM" Can't read AIDs from SIM -- 'list' object has no attribute 'lower' -warning: EF.DIR seems to be empty! +EF.DIR seems to be empty! ADF.ECASD: a0000005591010ffffffff8900000200 ADF.ISD-R: a0000005591010ffffffff8900000100 ISIM: a0000000871004 diff --git a/tests/unittests/test_log.py b/tests/unittests/test_log.py new file mode 100755 index 0000000..cc67b78 --- /dev/null +++ b/tests/unittests/test_log.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 + +# (C) 2025 by Sysmocom s.f.m.c. GmbH +# All Rights Reserved +# +# Author: Philipp Maier <pmaier(a)sysmocom.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import unittest +import logging +from pySim.log import PySimLogger +import io +import sys +from inspect import currentframe, getframeinfo + +log = PySimLogger.get("TEST") + +TEST_MSG_DEBUG = "this is a debug message" +TEST_MSG_INFO = "this is an info message" +TEST_MSG_WARNING = "this is a warning message" +TEST_MSG_ERROR = "this is an error message" +TEST_MSG_CRITICAL = "this is a critical message" + +expected_message = None + +class PySimLogger_Test(unittest.TestCase): + + def __test_01_safe_defaults_one(self, callback, message:str): + # When log messages are sent to an unconfigured PySimLogger class, we expect the unmodified message being + # logged to stdout, just as if it were printed via a normal print() statement. + log_output = io.StringIO() + sys.stdout = log_output + callback(message) + assert(log_output.getvalue().strip() == message) + sys.stdout = sys.__stdout__ + + def test_01_safe_defaults(self): + # When log messages are sent to an unconfigured PySimLogger class, we expect that all messages are logged, + # regardless of the logging level. + self.__test_01_safe_defaults_one(log.debug, TEST_MSG_DEBUG) + self.__test_01_safe_defaults_one(log.info, TEST_MSG_INFO) + self.__test_01_safe_defaults_one(log.warning, TEST_MSG_WARNING) + self.__test_01_safe_defaults_one(log.error, TEST_MSG_ERROR) + self.__test_01_safe_defaults_one(log.critical, TEST_MSG_CRITICAL) + + @staticmethod + def _test_print_callback(message): + assert(message.strip() == expected_message) + + def test_02_normal(self): + # When the PySimLogger is set up with its default values, we expect formatted log messages on all logging + # levels. + global expected_message + PySimLogger.setup(self._test_print_callback) + expected_message = "DEBUG: " + TEST_MSG_DEBUG + log.debug(TEST_MSG_DEBUG) + expected_message = "INFO: " + TEST_MSG_INFO + log.info(TEST_MSG_INFO) + expected_message = "WARNING: " + TEST_MSG_WARNING + log.warning(TEST_MSG_WARNING) + expected_message = "ERROR: " + TEST_MSG_ERROR + log.error(TEST_MSG_ERROR) + expected_message = "CRITICAL: " + TEST_MSG_CRITICAL + log.critical(TEST_MSG_CRITICAL) + + def test_03_verbose(self): + # When the PySimLogger is set up with its default values, we expect verbose formatted log messages on all + # logging levels. + global expected_message + PySimLogger.setup(self._test_print_callback) + PySimLogger.set_verbose(True) + frame = currentframe() + expected_message = __name__ + "." + str(getframeinfo(frame).lineno + 1) + " -- TEST - DEBUG: " + TEST_MSG_DEBUG + log.debug(TEST_MSG_DEBUG) + expected_message = __name__ + "." + str(getframeinfo(frame).lineno + 1) + " -- TEST - INFO: " + TEST_MSG_INFO + log.info(TEST_MSG_INFO) + expected_message = __name__ + "." + str(getframeinfo(frame).lineno + 1) + " -- TEST - WARNING: " + TEST_MSG_WARNING + log.warning(TEST_MSG_WARNING) + expected_message = __name__ + "." + str(getframeinfo(frame).lineno + 1) + " -- TEST - ERROR: " + TEST_MSG_ERROR + log.error(TEST_MSG_ERROR) + expected_message = __name__ + "." + str(getframeinfo(frame).lineno + 1) + " -- TEST - CRITICAL: " + TEST_MSG_CRITICAL + log.critical(TEST_MSG_CRITICAL) + + def test_04_level(self): + # When the PySimLogger is set up with its default values, we expect formatted log messages but since we will + # limit the log level to INFO, we should not see any messages of level DEBUG + global expected_message + PySimLogger.setup(self._test_print_callback) + PySimLogger.set_level(logging.INFO) + + # We test this in non verbose mode, this will also confirm that disabeling the verbose mode works. + PySimLogger.set_verbose(False) + + # Debug messages should not appear + expected_message = None + log.debug(TEST_MSG_DEBUG) + + # All other messages should appear normally + expected_message = "INFO: " + TEST_MSG_INFO + log.info(TEST_MSG_INFO) + expected_message = "WARNING: " + TEST_MSG_WARNING + log.warning(TEST_MSG_WARNING) + expected_message = "ERROR: " + TEST_MSG_ERROR + log.error(TEST_MSG_ERROR) + expected_message = "CRITICAL: " + TEST_MSG_CRITICAL + log.critical(TEST_MSG_CRITICAL) + +if __name__ == '__main__': + unittest.main() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/41229?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I187f117e7e1ccdb2a85dfdfb18e84bd7561704eb Gerrit-Change-Number: 41229 Gerrit-PatchSet: 9 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
1 0
0 0
[L] Change in pysim[master]: pySim-shell: add a logger class to centralize logging
by laforge 25 Oct '25

25 Oct '25
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/41229?usp=email ) Change subject: pySim-shell: add a logger class to centralize logging ...................................................................... Patch Set 8: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/41229?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I187f117e7e1ccdb2a85dfdfb18e84bd7561704eb Gerrit-Change-Number: 41229 Gerrit-PatchSet: 8 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Sat, 25 Oct 2025 19:46:30 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in pysim[master]: pySim-shell: add a logger class to centralize logging
by laforge 25 Oct '25

25 Oct '25
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/41229?usp=email ) Change subject: pySim-shell: add a logger class to centralize logging ...................................................................... Patch Set 8: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/41229?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I187f117e7e1ccdb2a85dfdfb18e84bd7561704eb Gerrit-Change-Number: 41229 Gerrit-PatchSet: 8 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Sat, 25 Oct 2025 19:46:18 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[XS] Change in osmo-ci[master]: OBS: let osmocom-keyring not depend on other pgks
by laforge 25 Oct '25

25 Oct '25
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ci/+/41255?usp=email ) Change subject: OBS: let osmocom-keyring not depend on other pgks ...................................................................... OBS: let osmocom-keyring not depend on other pgks The osmocom-latest, osmocom-nightly etc. meta-packages depend on the osmocom-keyring package. Fix that the osmocom-keyring package was also depending on these meta packages. This fixes that when uninstalling all osmocom:latest packages by removing the osmocom-latest meta package, the osmocom-keyring package would also get removed. This is undesirable for switching between latest and nightly, as the osmocom-keyring package must remain installed to be able to install new packages from the repository (as it has the repo key). Change-Id: If8fbbc40ee45e603de281003db2f61dcb7603e7b --- M scripts/obs/lib/srcpkg.py 1 file changed, 1 insertion(+), 1 deletion(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve diff --git a/scripts/obs/lib/srcpkg.py b/scripts/obs/lib/srcpkg.py index b0f76b8..7b93937 100644 --- a/scripts/obs/lib/srcpkg.py +++ b/scripts/obs/lib/srcpkg.py @@ -195,7 +195,7 @@ print(f"{project}: building source package {version_epoch}") write_tarball_version(project, version_epoch) - if project in lib.config.projects_osmocom and not lib.args.no_meta: + if project in lib.config.projects_osmocom and not lib.args.no_meta and project != "osmocom-keyring": metapkg = lib.args.conflict_pkgname or f"osmocom-{feed}" lib.debian.control_add_depend(project, metapkg, conflict_version) if has_rpm_spec: -- To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/41255?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-ci Gerrit-Branch: master Gerrit-Change-Id: If8fbbc40ee45e603de281003db2f61dcb7603e7b Gerrit-Change-Number: 41255 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
1 0
0 0
[XS] Change in osmo-ci[master]: OBS: let osmocom-keyring not depend on other pgks
by laforge 25 Oct '25

25 Oct '25
Attention is currently required from: jolly, osmith. laforge has posted comments on this change by osmith. ( https://gerrit.osmocom.org/c/osmo-ci/+/41255?usp=email ) Change subject: OBS: let osmocom-keyring not depend on other pgks ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/41255?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-ci Gerrit-Branch: master Gerrit-Change-Id: If8fbbc40ee45e603de281003db2f61dcb7603e7b Gerrit-Change-Number: 41255 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: jolly <andreas(a)eversberg.eu> Gerrit-Comment-Date: Sat, 25 Oct 2025 19:44:42 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[M] Change in osmo-msc[master]: sqlite optimisation: check VLR earlier for dest. subscriber
by laforge 25 Oct '25

25 Oct '25
Attention is currently required from: keith. laforge has posted comments on this change by keith. ( https://gerrit.osmocom.org/c/osmo-msc/+/41221?usp=email ) Change subject: sqlite optimisation: check VLR earlier for dest. subscriber ...................................................................... Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-msc/+/41221?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-msc Gerrit-Branch: master Gerrit-Change-Id: Ibd07b9d200b48108d705ed4c461cc4ddfa421fd2 Gerrit-Change-Number: 41221 Gerrit-PatchSet: 2 Gerrit-Owner: keith <keith(a)rhizomatica.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: keith <keith(a)rhizomatica.org> Gerrit-Comment-Date: Sat, 25 Oct 2025 19:41:38 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in pysim[master]: pySim-shell: update help strings for chv command parameter --pin-nr
by laforge 25 Oct '25

25 Oct '25
Attention is currently required from: dexter. laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/41251?usp=email ) Change subject: pySim-shell: update help strings for chv command parameter --pin-nr ...................................................................... Patch Set 1: Code-Review-1 (1 comment) Patchset: PS1: I would rather prefer if we had something more user friendly, translating string names to pin numbers. "0x81" is still somewhat understandable due to the highest bit being set for applicatoin bits, but requiring the uesr then to convert that manually to decimal is just not a good idea. I suggest we use the pySim.ts_102_221.pin_names bidict in this context by default, and accept decimal numeric values only as a compatibility fall-back. -- To view, visit https://gerrit.osmocom.org/c/pysim/+/41251?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I0b58c402d95cbc4fe690e6edb214829d463e9f2c Gerrit-Change-Number: 41251 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Sat, 25 Oct 2025 19:40:33 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in osmo-trx[master]: trx: Fix tx/rx-sps 4 for USRP1 devices
by laforge 25 Oct '25

25 Oct '25
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-trx/+/41231?usp=email ) Change subject: trx: Fix tx/rx-sps 4 for USRP1 devices ...................................................................... trx: Fix tx/rx-sps 4 for USRP1 devices The existing code sets the pingOffset variable to -7231(269 - 7500) with tx-sps = 4. The (apparent) correct value for pingOffset for tx/rx-sps 4 is 272. While I'm not completely sure how this patch works to fix the increased sps value, my theory is that the original OpenBTS TRX only supported a split sps setup(tx-sps=4, rx_sps=1 for sps=4), which created differing decimation rates between Tx and Rx on the board. In this case, apparently you needed to account for an advance in the timestamp for a correct output. With tx_sps == rx_sps, the decimation/sample rates will be the same, and(I guess) this advance doesn't need to be accounted for. Also changed a line in the initialization of the Rx end of the USRP device to use the correct decimation rate when tx/rx-sps == 4. Since osmo-trx won't allow nonequal values for tx-sps and rx-sps, I commented out the logic that selected pingOffset based on sps. I left it visible in the file for reference however. Tested & working on the URAN-1, a USRP1 clone designed for GSM. Change-Id: I3b08c23a3e7d4a226cd23b9fe42558f596a63257 --- M Transceiver52M/device/usrp1/USRPDevice.cpp 1 file changed, 8 insertions(+), 7 deletions(-) Approvals: laforge: Looks good to me, approved fixeria: Looks good to me, but someone else must approve; Verified diff --git a/Transceiver52M/device/usrp1/USRPDevice.cpp b/Transceiver52M/device/usrp1/USRPDevice.cpp index 63a9bcc..21cbd7e 100644 --- a/Transceiver52M/device/usrp1/USRPDevice.cpp +++ b/Transceiver52M/device/usrp1/USRPDevice.cpp @@ -75,18 +75,19 @@ * split sample rate Tx/Rx - 4/1 sps we need to need to * compensate for advance rather than delay. */ - if (tx_sps == 1) - pingOffset = 272; - else if (tx_sps == 4) - pingOffset = 269 - 7500; - else - pingOffset = 0; + pingOffset = 272; + + /* Split SPS (4/1) unsupported on USRP1 + * if(tx_sps == 4 && rx_sps == 1) + * pingOffset = 269 - 7500; + */ #ifdef SWLOOPBACK samplePeriod = 1.0e6/actualSampleRate; loopbackBufferSize = 0; gettimeofday(&lastReadTime,NULL); firstRead = false; + pingOffset = 0; #endif } @@ -101,7 +102,7 @@ m_uRx.reset(); try { m_uRx = usrp_standard_rx_sptr(usrp_standard_rx::make( - 0, decimRate * tx_sps, 1, -1, + 0, decimRate, 1, -1, usrp_standard_rx::FPGA_MODE_NORMAL, 1024, 16 * 8, rbf)); m_uRx->set_fpga_master_clock_freq(masterClockRate); -- To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/41231?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: I3b08c23a3e7d4a226cd23b9fe42558f596a63257 Gerrit-Change-Number: 41231 Gerrit-PatchSet: 2 Gerrit-Owner: tempest <jackleea1b(a)gmail.com> Gerrit-Reviewer: Hoernchen <ewild(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: tnt <tnt(a)246tNt.com> Gerrit-Reviewer: ttsou <tom(a)tsou.cc> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • ...
  • 64
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.