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

December 2023

  • 1 participants
  • 1601 discussions
[S] Change in osmo-bsc[master]: ctrl: Add rxlev access min control
by matanp 27 Dec '23

27 Dec '23
matanp has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/35446?usp=email ) Change subject: ctrl: Add rxlev access min control ...................................................................... ctrl: Add rxlev access min control Change-Id: I25bf4bb11bf8e34e80f740fb89a467fc6e491962 --- M src/osmo-bsc/bts_ctrl.c 1 file changed, 45 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/46/35446/1 diff --git a/src/osmo-bsc/bts_ctrl.c b/src/osmo-bsc/bts_ctrl.c index 4311145..17e210b 100644 --- a/src/osmo-bsc/bts_ctrl.c +++ b/src/osmo-bsc/bts_ctrl.c @@ -1143,6 +1143,41 @@ CTRL_CMD_DEFINE(bts_cell_reselection_hysteresis, "cell-reselection-hysteresis"); +static int verify_bts_rxlev_access_min(struct ctrl_cmd *cmd, const char *value, void *_data) +{ + int rxlev_access_min = atoi(cmd->value); + + if (rxlev_access_min < 0 || rxlev_access_min > 63) { + cmd->reply = "Value is out of range"; + return 1; + } + + return 0; +} + +static int get_bts_rxlev_access_min(struct ctrl_cmd *cmd, void *data) +{ + struct gsm_bts *bts = cmd->node; + + cmd->reply = talloc_asprintf(cmd, "%u", bts->si_common.cell_sel_par.rxlev_acc_min); + if (!cmd->reply) { + cmd->reply = "OOM"; + return CTRL_CMD_ERROR; + } + + return CTRL_CMD_REPLY; +} + +static int set_bts_rxlev_access_min(struct ctrl_cmd *cmd, void *data) +{ + struct gsm_bts *bts = cmd->node; + bts->si_common.cell_sel_par.rxlev_acc_min = atoi(cmd->value); + cmd->reply = "OK"; + return CTRL_CMD_REPLY; +} + +CTRL_CMD_DEFINE(bts_rxlev_access_min, "rach-rxlev-access-min"); + /* Return space concatenated set of pairs <class>,<barred/allowed> */ static int get_bts_rach_access_control_class(struct ctrl_cmd *cmd, void *data) { @@ -1394,6 +1429,7 @@ rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_cell_reselection_offset); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_cell_reselection_penalty_time); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_cell_reselection_hysteresis); + rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_rxlev_access_min); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_rach_access_control_class); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_rach_access_control_class_bar); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_rach_access_control_class_allow); -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/35446?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I25bf4bb11bf8e34e80f740fb89a467fc6e491962 Gerrit-Change-Number: 35446 Gerrit-PatchSet: 1 Gerrit-Owner: matanp <matan1008(a)gmail.com> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in libosmocore[master]: tests/fsm: also test .onenter and .onleave callbacks
by fixeria 26 Dec '23

26 Dec '23
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35445?usp=email ) Change subject: tests/fsm: also test .onenter and .onleave callbacks ...................................................................... tests/fsm: also test .onenter and .onleave callbacks Extend the existing testing coverage to check per-state enter/leave callbacks. An interesting behavior can be seen from the test output: when allocating an FSM instance, the .onenter callback is not being called for the initial FSM state (ST_NULL). Likewise, the .onleave callback is not being called when free()ing an FSM instance. Change-Id: I22edcf91375a09854f0dab1e2e02e034629310f7 --- M tests/fsm/fsm_test.c M tests/fsm/fsm_test.err 2 files changed, 57 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/45/35445/1 diff --git a/tests/fsm/fsm_test.c b/tests/fsm/fsm_test.c index 960042c..3b83941 100644 --- a/tests/fsm/fsm_test.c +++ b/tests/fsm/fsm_test.c @@ -41,6 +41,18 @@ { 0, NULL } }; +static void test_fsm_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + LOGPFSM(fi, "%s() prev_state=%s\n", + __func__, osmo_fsm_state_name(fi->fsm, prev_state)); +} + +static void test_fsm_onleave(struct osmo_fsm_inst *fi, uint32_t next_state) +{ + LOGPFSM(fi, "%s() next_state=%s\n", + __func__, osmo_fsm_state_name(fi->fsm, next_state)); +} + static void test_fsm_null(struct osmo_fsm_inst *fi, uint32_t event, void *data) { switch (event) { @@ -86,17 +98,23 @@ .out_state_mask = (1 << ST_ONE), .name = "NULL", .action = test_fsm_null, + .onenter = test_fsm_onenter, + .onleave = test_fsm_onleave, }, [ST_ONE]= { .in_event_mask = (1 << EV_B), .out_state_mask = (1 << ST_TWO), .name = "ONE", .action= test_fsm_one, + .onenter = test_fsm_onenter, + .onleave = test_fsm_onleave, }, [ST_TWO]= { .in_event_mask = 0, .name = "TWO", .action = NULL, + .onenter = test_fsm_onenter, + .onleave = test_fsm_onleave, }, }; diff --git a/tests/fsm/fsm_test.err b/tests/fsm/fsm_test.err index 51bf5da..fffb913 100644 --- a/tests/fsm/fsm_test.err +++ b/tests/fsm/fsm_test.err @@ -3,9 +3,13 @@ Test_FSM(my_id){NULL}: Received Event EV_B Test_FSM(my_id){NULL}: Event EV_B not permitted Test_FSM(my_id){NULL}: Received Event EV_A +Test_FSM(my_id){NULL}: test_fsm_onleave() next_state=ONE Test_FSM(my_id){NULL}: State change to ONE (no timeout) +Test_FSM(my_id){ONE}: test_fsm_onenter() prev_state=NULL Test_FSM(my_id){ONE}: Received Event EV_B +Test_FSM(my_id){ONE}: test_fsm_onleave() next_state=TWO Test_FSM(my_id){ONE}: State change to TWO (T2342, 1s) +Test_FSM(my_id){TWO}: test_fsm_onenter() prev_state=ONE Test_FSM(my_id){TWO}: Timeout of T2342 Timer Test_FSM(my_id){TWO}: Deallocated @@ -83,16 +87,24 @@ --- test_state_chg_keep_timer() Test_FSM{NULL}: Allocated +Test_FSM{NULL}: test_fsm_onleave() next_state=ONE Test_FSM{NULL}: State change to ONE (no timeout) +Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL +Test_FSM{ONE}: test_fsm_onleave() next_state=TWO Test_FSM{ONE}: State change to TWO (no timeout) +Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST) Test_FSM{TWO}: Freeing instance Test_FSM{TWO}: Deallocated Total time passed: 0.000000 s Test_FSM{NULL}: Allocated +Test_FSM{NULL}: test_fsm_onleave() next_state=ONE Test_FSM{NULL}: State change to ONE (T10, 10s) +Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL Total time passed: 2.000342 s +Test_FSM{ONE}: test_fsm_onleave() next_state=TWO Test_FSM{ONE}: State change to TWO (keeping T10, 7.999s remaining) +Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE Total time passed: 2.000342 s Total time passed: 9.999999 s Total time passed: 10.000000 s @@ -104,14 +116,22 @@ --- test_state_chg_T() Test_FSM{NULL}: Allocated +Test_FSM{NULL}: test_fsm_onleave() next_state=ONE Test_FSM{NULL}: State change to ONE (T42, 23s) +Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL +Test_FSM{ONE}: test_fsm_onleave() next_state=TWO Test_FSM{ONE}: State change to TWO (no timeout) +Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST) Test_FSM{TWO}: Freeing instance Test_FSM{TWO}: Deallocated Test_FSM{NULL}: Allocated +Test_FSM{NULL}: test_fsm_onleave() next_state=ONE Test_FSM{NULL}: State change to ONE (T42, 23s) +Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL +Test_FSM{ONE}: test_fsm_onleave() next_state=TWO Test_FSM{ONE}: State change to TWO (no timeout) +Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST) Test_FSM{TWO}: Freeing instance Test_FSM{TWO}: Deallocated @@ -120,7 +140,9 @@ --- test_state_chg_Ts() Total time passed: 0.000000 s Test_FSM{NULL}: Allocated +Test_FSM{NULL}: test_fsm_onleave() next_state=ONE Test_FSM{NULL}: State change to ONE (T4242, 8s) +Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL Total time passed: 3.000000 s Total time passed: 5.500000 s Total time passed: 8.000000 s @@ -133,7 +155,9 @@ --- test_state_chg_Tms() Total time passed: 0.000000 s Test_FSM{NULL}: Allocated +Test_FSM{NULL}: test_fsm_onleave() next_state=ONE Test_FSM{NULL}: State change to ONE (T4242, 1337ms) +Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL Total time passed: 0.500000 s Total time passed: 0.750000 s Total time passed: 1.100000 s -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35445?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I22edcf91375a09854f0dab1e2e02e034629310f7 Gerrit-Change-Number: 35445 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[L] Change in libosmocore[master]: isdn: initial implementation of the V.110 TA
by fixeria 26 Dec '23

26 Dec '23
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35444?usp=email ) Change subject: isdn: initial implementation of the V.110 TA ...................................................................... isdn: initial implementation of the V.110 TA Initial (Work-in-Progress) implementation by Harald Welte, completed and co-authored by Vadim Yanitskiy. Change-Id: I5716bd6fd0201ee7a7a29e72f775972cd374082f Related: OS#4396 --- M include/osmocom/isdn/Makefile.am A include/osmocom/isdn/v110_ta.h M src/isdn/Makefile.am M src/isdn/libosmoisdn.map A src/isdn/v110_ta.c 5 files changed, 633 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/44/35444/1 diff --git a/include/osmocom/isdn/Makefile.am b/include/osmocom/isdn/Makefile.am index ad2d8dd..fbc92d8 100644 --- a/include/osmocom/isdn/Makefile.am +++ b/include/osmocom/isdn/Makefile.am @@ -2,6 +2,7 @@ i460_mux.h \ lapd_core.h \ v110.h \ + v110_ta.h \ $(NULL) osmoisdndir = $(includedir)/osmocom/isdn diff --git a/include/osmocom/isdn/v110_ta.h b/include/osmocom/isdn/v110_ta.h new file mode 100644 index 0000000..9991c2d --- /dev/null +++ b/include/osmocom/isdn/v110_ta.h @@ -0,0 +1,66 @@ +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +#include <osmocom/core/bits.h> +#include <osmocom/isdn/v110.h> + +/* Definition of this struct is kept private. */ +struct osmo_v110_ta; + +/*! Configuration for a V.110 TA instance. */ +struct osmo_v110_ta_cfg { + /*! Is end-to-end flow-control enabled or not? */ + bool end_to_end_flowctrl; + /*! Synchronous user rate. */ + enum osmo_v100_sync_ra1_rate rate; + + /*! Opaque application-private data; passed to call-backs. */ + void *priv; + + /*! Receive call-back of the application. + * \param[in] priv opaque application-private data. + * \param[in] buf output buffer for writing to be transmitted data. + * \param[in] buf_size size of the output buffer. */ + void (*rx_cb)(void *priv, const ubit_t *buf, size_t buf_size); + + /*! Transmit call-back of the application. + * \param[in] priv opaque application-private data. + * \param[out] buf output buffer for writing to be transmitted data. + * \param[in] buf_size size of the output buffer. */ + void (*tx_cb)(void *priv, ubit_t *buf, size_t buf_size); + + /*! Modem status line update call-back (optional). + * \param[in] priv opaque application-private data. + * \param[in] status updated status; bit-mask of XXX. */ + void (*status_update_cb)(void *priv, unsigned int status); +}; + +struct osmo_v110_ta *osmo_v110_ta_alloc(void *ctx, const char *name, + const struct osmo_v110_ta_cfg *cfg); +void osmo_v110_ta_free(struct osmo_v110_ta *ta); + +int osmo_v110_ta_frame_in(struct osmo_v110_ta *ta, const struct osmo_v110_decoded_frame *in); +int osmo_v110_ta_frame_out(struct osmo_v110_ta *ta, struct osmo_v110_decoded_frame *out); + +/*! ITU-T V.24 Chapter 3 + * TODO: move into its own header? */ +enum osmo_v24_circuit { + OSMO_V24_C_105, /* DTE->DCE | RTS (Request to Send) */ + OSMO_V24_C_106, /* DTE<-DCE | CTS (Clear to Send) */ + OSMO_V24_C_107, /* DTE<-DCE | DSR (Data Set Ready) */ + OSMO_V24_C_108_1, /* XXX--XXX | Connect data set to line */ + OSMO_V24_C_108_2, /* XXX--XXX | DTR (Data Terminal Ready) */ + OSMO_V24_C_109, /* DTE<-DCE | DCD (Data Carrier Detect) */ + OSMO_V24_C_125, /* DTE<-DCE | RI (Ring Indicator) */ + OSMO_V24_C_133, /* DTE->DCE | Ready for receiving */ +}; + +unsigned int osmo_v110_ta_get_status(const struct osmo_v110_ta *ta); +int osmo_v110_ta_set_status(struct osmo_v110_ta *ta, unsigned int status); + +bool osmo_v110_ta_get_circuit(const struct osmo_v110_ta *ta, + enum osmo_v24_circuit circuit); +void osmo_v110_ta_set_circuit(struct osmo_v110_ta *ta, + enum osmo_v24_circuit circuit, bool active); diff --git a/src/isdn/Makefile.am b/src/isdn/Makefile.am index f8314bd..3e7f86e 100644 --- a/src/isdn/Makefile.am +++ b/src/isdn/Makefile.am @@ -13,7 +13,7 @@ noinst_LTLIBRARIES = libisdnint.la lib_LTLIBRARIES = libosmoisdn.la -libisdnint_la_SOURCES = i460_mux.c lapd_core.c v110.c +libisdnint_la_SOURCES = i460_mux.c lapd_core.c v110.c v110_ta.c libisdnint_la_LDFLAGS = -no-undefined libisdnint_la_LIBADD = $(top_builddir)/src/core/libosmocore.la diff --git a/src/isdn/libosmoisdn.map b/src/isdn/libosmoisdn.map index c29240b..df20ad5 100644 --- a/src/isdn/libosmoisdn.map +++ b/src/isdn/libosmoisdn.map @@ -33,5 +33,14 @@ osmo_v110_sync_ra1_user_to_ir; osmo_v110_sync_ra1_ir_to_user; +osmo_v110_ta_alloc; +osmo_v110_ta_free; +osmo_v110_ta_frame_in; +osmo_v110_ta_frame_out; +osmo_v110_ta_get_status; +osmo_v110_ta_set_status; +osmo_v110_ta_get_circuit; +osmo_v110_ta_set_circuit; + local: *; }; diff --git a/src/isdn/v110_ta.c b/src/isdn/v110_ta.c new file mode 100644 index 0000000..c8463bd --- /dev/null +++ b/src/isdn/v110_ta.c @@ -0,0 +1,543 @@ +/*! \file v110_ta.c + * TA (Terminal Adapter) implementation as per ITU-T V.110. */ +/* + * (C) 2022 by Harald Welte <laforge(a)gnumonks.org> + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * Initial (Work-in-Progress) implementation by Harald Welte, + * completed and co-authored by Vadim Yanitskiy. + * + * All Rights Reserved + * + * SPDX-License-Identifier: GPL-2.0+ + * + * 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. + * + */ + +#include <stdbool.h> +#include <stdint.h> +#include <errno.h> + +#include <osmocom/core/logging.h> +#include <osmocom/core/utils.h> +#include <osmocom/core/bits.h> +#include <osmocom/core/fsm.h> + +#include <osmocom/isdn/v110.h> +#include <osmocom/isdn/v110_ta.h> + +#define S(x) (1 << (x)) + +#define V24_FLAGMASK_IS_ON(flags, circuit) \ + (((flags) & S(circuit)) != 0) + +#define V24_FLAGMASK_IS_OFF(flags, circuit) \ + (((flags) & S(circuit)) == 0) + +#define V24_FLAGMASK_SET_ON(flags, circuit) \ + do { \ + (flags) |= S(circuit); \ + } while (0) + +#define V24_FLAGMASK_SET_OFF(flags, circuit) \ + do { \ + (flags) &= ~S(circuit); \ + } while (0) + +/* inverse logic: ON = binary 0; OFF = binary 1 */ +#define V110_SX_BIT_ON 0 +#define V110_SX_BIT_OFF 1 + +/********************************************************************************* + * V.110 TERMINAL ADAPTER FSMs + *********************************************************************************/ + +enum v110_ta_fsm_state { + V110_TA_ST_IDLE_READY, /* 7.1.1 Idle (or ready) state */ + V110_TA_ST_CON_TA_LINE, /* 7.1.2 Connect TA to line state */ + V110_TA_ST_DATA_TRANSFER, /* 7.1.3 Data transfer state */ + V110_TA_ST_DISCONNECT, /* 7.1.4 Disconnect mode */ + V110_TA_ST_RESYNCING, /* 7.1.5 Re-synchronizing state */ +}; + +enum v110_ta_fsm_event { + V110_TA_EV_RX_FRAME_IND, /* Received V.110 frame indication */ + V110_TA_EV_TX_FRAME_RTS, /* V.110 frame Ready-to-send indication */ +#if 1 + V110_TA_EV_V24_STATUS_CHG, + V110_TA_EV_SWITCH_TO_DATA_MODE, + V110_TA_EV_RX_SYNC_IND, +#endif +}; + +static const struct value_string v110_ta_fsm_event_names[] = { + { V110_TA_EV_RX_FRAME_IND, "RX_FRAME_IND" }, + { V110_TA_EV_TX_FRAME_RTS, "TX_FRAME_RTS" }, + { 0, NULL } +}; + +enum v110_ta_tx_d_bit_mode { + V110_TA_TX_FRAME_ALL_ONE, + V110_TA_TX_FRAME_ALL_ZERO, + V110_TA_TX_FRAME_FROM_DTE, +}; + +struct v110_ta_state { + /*! V.24 status flags shared between DTE (user) and DCE (TA, us) */ + unsigned int v24_flags; + struct { + /* what kind of D-bits to transmit in V.110 frames */ + enum v110_ta_tx_d_bit_mode d_bit_mode; + /* what to put in S-bits of transmitted V.110 frames */ + ubit_t s_bits; + /* what to put in X-bits of transmitted V.110 frames */ + ubit_t x_bits; + /* what to put in E-bits of transmitted V.110 frames */ + ubit_t e_bits[MAX_E_BITS]; + } tx; + struct { + enum v110_ta_tx_d_bit_mode bit_mode; + } rx; +}; + +struct osmo_v110_ta { + const char *name; + struct osmo_fsm_inst *fi; + struct osmo_v110_ta_cfg *cfg; + struct v110_ta_state state; +}; + +/* decode one V.110 frame and forward user bits to the application */ +static void v110_ta_decode_frame(const struct osmo_v110_ta *ta, + const struct osmo_v110_decoded_frame *fr) +{ + const struct osmo_v110_ta_cfg *cfg = ta->cfg; + ubit_t user_bits[MAX_D_BITS]; + int rc; + + rc = osmo_v110_sync_ra1_ir_to_user(cfg->rate, &user_bits[0], sizeof(user_bits), fr); + if (rc > 0) + cfg->rx_cb(cfg->priv, &user_bits[0], rc); +} + +/* build one V.110 frame to transmit */ +static void v110_ta_build_frame(const struct osmo_v110_ta *ta, + struct osmo_v110_decoded_frame *fr) +{ + const struct osmo_v110_ta_cfg *cfg = ta->cfg; + const struct v110_ta_state *ts = &ta->state; + ubit_t user_bits[MAX_D_BITS]; + int num_user_bits; + int rc; + + /* D-bits */ + switch (ts->tx.d_bit_mode) { + case V110_TA_TX_FRAME_ALL_ONE: + memset(fr->d_bits, 1, sizeof(fr->d_bits)); + break; + case V110_TA_TX_FRAME_ALL_ZERO: + memset(fr->d_bits, 0, sizeof(fr->d_bits)); + break; + case V110_TA_TX_FRAME_FROM_DTE: + /* how many user bits to retrieve */ + num_user_bits = osmo_v110_sync_ra1_get_user_data_chunk_bitlen(cfg->rate); + OSMO_ASSERT(num_user_bits > 0); + /* retrieve user bits from the application */ + cfg->tx_cb(cfg->priv, &user_bits[0], num_user_bits); + /* convert user bits to intermediate rate (store to fr) */ + rc = osmo_v110_sync_ra1_user_to_ir(cfg->rate, fr, &user_bits[0], num_user_bits); + OSMO_ASSERT(rc == 0); + break; + } + + /* E-bits */ + memcpy(fr->e_bits, ts->tx.e_bits, sizeof(fr->e_bits)); + /* S-bits */ + memset(fr->s_bits, ts->tx.s_bits, sizeof(fr->s_bits)); + /* X-bits */ + memset(fr->x_bits, ts->tx.x_bits, sizeof(fr->x_bits)); +} + +static void v110_ta_flags_updated(const struct osmo_v110_ta *ta) +{ + const struct osmo_v110_ta_cfg *cfg = ta->cfg; + + if (cfg->status_update_cb != NULL) + cfg->status_update_cb(cfg->priv, ta->state.v24_flags); +} + +/* ITU-T V.110 Section 7.1.1 */ +static void v110_ta_fsm_idle_ready_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + struct osmo_v110_ta *ta = (struct osmo_v110_ta *)fi->priv; + struct v110_ta_state *ts = &ta->state; + + /* E4 .. E7 bits (lower 3 bits are generated by v110 frame encoder) */ + memset(&ts->tx.e_bits[3], 1, MAX_E_BITS - 3); + + /* 7.1.1.2 During the idle (or ready) state the TA will transmit continuous binary 1s into the B-channel */ + /* 7.1.1.3 During the idle (or ready) state the TA (DCE) will transmit the following toward the DTE: * */ + /* - 104: continuous binary 1 */ + ts->rx.bit_mode = V110_TA_TX_FRAME_ALL_ONE; + /* - 107, 106, 109 = OFF */ + V24_FLAGMASK_SET_OFF(ts->v24_flags, OSMO_V24_C_106); + V24_FLAGMASK_SET_OFF(ts->v24_flags, OSMO_V24_C_107); + V24_FLAGMASK_SET_OFF(ts->v24_flags, OSMO_V24_C_109); + v110_ta_flags_updated(ta); +} + +/* ITU-T V.110 Section 7.1.1 */ +static void v110_ta_fsm_idle_ready(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct osmo_v110_ta *ta = (struct osmo_v110_ta *)fi->priv; + struct v110_ta_state *ts = &ta->state; + + switch (event) { + case V110_TA_EV_RX_FRAME_IND: + /* XXX: should we really handle V.110 frames in this state? */ + v110_ta_decode_frame(ta, (const struct osmo_v110_decoded_frame *)data); + break; + case V110_TA_EV_TX_FRAME_RTS: + /* XXX: transmit continuous binary 1 to B channels */ + break; + case V110_TA_EV_SWITCH_TO_DATA_MODE: + /* When the TA is to be switched to the data mode, circuit 108 must be ON */ + if (V24_FLAGMASK_IS_ON(ts->v24_flags, OSMO_V24_C_108_2)) { + /* 7.12.2: Start timer T1 when switching to CON_TA_LINE */ + osmo_fsm_inst_state_chg(fi, V110_TA_ST_CON_TA_LINE, 10, 1); + } + break; + default: + OSMO_ASSERT(0); + } +} + +/* ITU-T V.110 Section 7.1.2 */ +static void v110_ta_fsm_connect_ta_to_line_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + struct osmo_v110_ta *ta = (struct osmo_v110_ta *)fi->priv; + struct v110_ta_state *ts = &ta->state; + + /* FIXME: frame sync pattern as per 5.1.3.1 / 5.2.1 */ + /* data bits: binary 1 */ + ts->tx.d_bit_mode = V110_TA_TX_FRAME_ALL_ONE; + /* S = OFF, X = OFF (ON = binary 0; OFF = binary 1) */ + ts->tx.s_bits = V110_SX_BIT_OFF; + ts->tx.x_bits = V110_SX_BIT_OFF; + /* onenter: T1 has been started */ + OSMO_ASSERT(fi->T == 1); +} + +static bool all_bits_are(const ubit_t *in, ubit_t cmp, size_t in_len) +{ + for (unsigned int i = 0; i < in_len; i++) { + if (in[i] != cmp) + return false; + } + return true; +} +#define ARRAY_ALL_BITS_ONE(arr) all_bits_are((arr), 1, sizeof(arr)) +#define ARRAY_ALL_BITS_ZERO(arr) all_bits_are((arr), 0, sizeof(arr)) + +/* ITU-T V.110 Section 7.1.2 */ +static void v110_ta_fsm_connect_ta_to_line(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct osmo_v110_ta *ta = (struct osmo_v110_ta *)fi->priv; + struct v110_ta_state *ts = &ta->state; + + switch (event) { + case V110_TA_EV_RX_FRAME_IND: + { + const struct osmo_v110_decoded_frame *fr = data; + + /* 7.1.2.4 When the receiver recognizes that the status of bits S and X are in the ON + * condition, it will perform the following functions: */ + if (!ARRAY_ALL_BITS_ZERO(fr->s_bits)) + break; + if (!ARRAY_ALL_BITS_ZERO(fr->x_bits)) + break; + /* a) Turn ON circuit 107 toward the DTE and stop timer T1. */ + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_107); + /* b) Then, circuit 103 may be connected to the data bits in the frame; however, the + * DTE must maintain a binary 1 condition on circuit 103 until circuit 106 is turned + * ON in the next portion of the sequence. */ + /* c) Turn ON circuit 109 and connect the data bits to circuit 104. */ + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_109); + /* d) After an interval of N bits (see 6.3), it will turn ON circuit 106. */ + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_106); + v110_ta_flags_updated(ta); + /* Circuit 106 transitioning from OFF to ON will cause the transmitted data to + * transition from binary 1 to the data mode. */ + osmo_fsm_inst_state_chg(fi, V110_TA_ST_DATA_TRANSFER, 0, 0); + + v110_ta_decode_frame(ta, fr); + break; + } + case V110_TA_EV_TX_FRAME_RTS: + v110_ta_build_frame(ta, (struct osmo_v110_decoded_frame *)data); + break; + case V110_TA_EV_RX_SYNC_IND: + /* 7.1.2.3 When the receiver recognizes the frame synchronization pattern, it causes the S- + * and X-bits in the transmitted frames to be turned ON (provided that circuit 108 is ON). */ + if (V24_FLAGMASK_IS_ON(ts->v24_flags, OSMO_V24_C_108_2)) { + ts->tx.s_bits = V110_SX_BIT_ON; + ts->tx.x_bits = V110_SX_BIT_ON; + } + break; + default: + OSMO_ASSERT(0); + } +} + +/* ITU-T V.110 Section 7.1.3 */ +static void v110_ta_fsm_data_transfer_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + struct osmo_v110_ta *ta = (struct osmo_v110_ta *)fi->priv; + struct v110_ta_state *ts = &ta->state; + + ts->tx.d_bit_mode = V110_TA_TX_FRAME_FROM_DTE; + + /* 7.1.3.1 a): 105, 107, 108/1, 108/2 and 109 are in the ON condition */ + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_105); + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_107); + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_108_1); + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_108_2); + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_109); + /* 7.1.3.1 c): 133 (when implemented) and 106 are in the ON condition unless local out-of-band + * flow control is being used, either or both circuits may be in the ON or the OFF condition. */ + if (!ta->cfg->end_to_end_flowctrl) { + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_133); + V24_FLAGMASK_SET_ON(ts->v24_flags, OSMO_V24_C_106); + } + v110_ta_flags_updated(ta); + /* 7.1.3.2 While in the data transfer state, the following status bit conditions exist: */ + /* a) status bits S in both directions are in the ON condition; */ + ts->tx.s_bits = V110_SX_BIT_ON; + /* b) status bits X in both directions are in the ON condition unless end-to-end flow control is + * being used, in which case status bit X in either or both directions may be in the ON or the OFF + * condition. */ + if (!ta->cfg->end_to_end_flowctrl) + ts->tx.x_bits = V110_SX_BIT_ON; +} + +/* ITU-T V.110 Section 7.1.3 */ +static void v110_ta_fsm_data_transfer(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct osmo_v110_ta *ta = (struct osmo_v110_ta *)fi->priv; + struct v110_ta_state *ts = &ta->state; + + switch (event) { + case V110_TA_EV_V24_STATUS_CHG: + /* 7.1.4.1 At the completion of the data transfer phase, the local DTE will indicate a + * disconnect request by turning OFF circuit 108 */ + if (!V24_FLAGMASK_IS_OFF(ts->v24_flags, OSMO_V24_C_108_2)) + break; + /* a) the status bits S in the frame toward ISDN will turn OFF, status bits X are kept ON */ + ts->tx.s_bits = V110_SX_BIT_OFF; + /* b) circuit 106 will be turned OFF */ + V24_FLAGMASK_SET_OFF(ts->v24_flags, OSMO_V24_C_106); + v110_ta_flags_updated(ta); + /* c) the data bits in the frame will be set to binary 0. */ + ts->tx.d_bit_mode = V110_TA_TX_FRAME_ALL_ZERO; + /* to guard against the failure of the remote TA to respond to the disconnect request, + * the local TA may start a timer T2 (suggested value 5 s) which is stopped by the + * reception or transmission of any D-channel clearing message (DISCONNECT, RELEASE, + * RELEASE COMPLETE) */ + osmo_fsm_inst_state_chg(fi, V110_TA_ST_DISCONNECT, 5, 2); + break; + case V110_TA_EV_TX_FRAME_RTS: + v110_ta_build_frame(ta, (struct osmo_v110_decoded_frame *)data); + break; + case V110_TA_EV_RX_FRAME_IND: + v110_ta_decode_frame(ta, (const struct osmo_v110_decoded_frame *)data); + break; + default: + OSMO_ASSERT(0); + } +} + +static int v110_ta_timer_cb(struct osmo_fsm_inst *fi) +{ + switch (fi->T) { + case 1: /* T1: wait for sync pattern */ + break; + case 2: /* T2: wait for response to disconnect */ + break; + } + + return 0; +} + +static const struct osmo_fsm_state v110_ta_states[] = { + [V110_TA_ST_IDLE_READY] = { + .name = "IDLE_READY", + .in_event_mask = S(V110_TA_EV_TX_FRAME_RTS), + .out_state_mask = S(V110_TA_ST_CON_TA_LINE), + .action = &v110_ta_fsm_idle_ready, + .onenter = &v110_ta_fsm_idle_ready_onenter, + }, + [V110_TA_ST_CON_TA_LINE] = { + .name = "CONNECT_TA_TA_LINE", + .in_event_mask = S(V110_TA_EV_TX_FRAME_RTS) + | S(V110_TA_EV_RX_FRAME_IND), + .out_state_mask = S(V110_TA_ST_DATA_TRANSFER) + | S(V110_TA_ST_IDLE_READY), + .action = &v110_ta_fsm_connect_ta_to_line, + .onenter = &v110_ta_fsm_connect_ta_to_line_onenter, + }, + [V110_TA_ST_DATA_TRANSFER] = { + .name = "DATA_TRANSFER", + .in_event_mask = S(V110_TA_EV_TX_FRAME_RTS) + | S(V110_TA_EV_RX_FRAME_IND), + .out_state_mask = S(V110_TA_ST_RESYNCING) + | S(V110_TA_ST_DISCONNECT), + .action = &v110_ta_fsm_data_transfer, + .onenter = &v110_ta_fsm_data_transfer_onenter, + }, +#if 0 + [V110_TA_ST_DISCONNECT] = { + .name = "DISCONNECT", + .out_state_mask = S(V110_TA_ST_IDLE_READY), + }, + [V110_TA_ST_RESYNCING] = { + .name = "RESYNCING", + .out_state_mask = S(V110_TA_ST_DATA_TRANSFER) + | S(V110_TA_ST_DISCONNECT), + }, +#endif +}; + +static struct osmo_fsm osmo_v110_ta_fsm = { + .name = "V110-TA", + .states = v110_ta_states, + .num_states = ARRAY_SIZE(v110_ta_states), + .timer_cb = v110_ta_timer_cb, + .log_subsys = DLGLOBAL, + .event_names = v110_ta_fsm_event_names, +}; + +static __attribute__((constructor)) void on_dso_load(void) +{ + OSMO_ASSERT(osmo_fsm_register(&osmo_v110_ta_fsm) == 0); +} + +/*! Allocate a V.110 TA (Terminal Adapter) instance. + * \param[in] ctx parent talloc context. + * \param[in] name name of the TA instance. + * \param[in] cfg initial configuration of the TA instance. + * \returns pointer to allocated TA instance; NULL on error. */ +struct osmo_v110_ta *osmo_v110_ta_alloc(void *ctx, const char *name, + const struct osmo_v110_ta_cfg *cfg) +{ + struct osmo_v110_ta *ta; + + OSMO_ASSERT(cfg != NULL); + OSMO_ASSERT(cfg->rx_cb != NULL); + OSMO_ASSERT(cfg->tx_cb != NULL); + + ta = talloc_zero(ctx, struct osmo_v110_ta); + if (ta == NULL) + return NULL; + + ta->name = talloc_strdup(ta, name); + ta->cfg = talloc_memdup(ta, cfg, sizeof(*cfg)); + if (ta->name == NULL || ta->cfg == NULL) + goto exit_free; + + ta->fi = osmo_fsm_inst_alloc(&osmo_v110_ta_fsm, ta, ta, LOGL_INFO, name); + if (ta->fi == NULL) + goto exit_free; + + return ta; + +exit_free: + if (ta->fi != NULL) + osmo_fsm_inst_free(ta->fi); + talloc_free(ta); + return NULL; +} + +/*! Release memory taken by the given V.110 TA instance. + * \param[in] ta TA instance to be free()d. */ +void osmo_v110_ta_free(struct osmo_v110_ta *ta) +{ + if (ta == NULL) + return; + if (ta->fi != NULL) + osmo_fsm_inst_free(ta->fi); + talloc_free(ta); /* also free()s name and cfg */ +} + +/* XXX + * \returns 0 in case of success; negative on error. */ +int osmo_v110_ta_frame_in(struct osmo_v110_ta *ta, const struct osmo_v110_decoded_frame *in) +{ + return osmo_fsm_inst_dispatch(ta->fi, V110_TA_EV_RX_FRAME_IND, (void *)in); +} + +/* XXX + * \returns 0 in case of success; negative on error. */ +int osmo_v110_ta_frame_out(struct osmo_v110_ta *ta, struct osmo_v110_decoded_frame *out) +{ + return osmo_fsm_inst_dispatch(ta->fi, V110_TA_EV_TX_FRAME_RTS, (void *)out); +} + +/*! Get the V.24 status bitmask of the given TA instance. + * \param[in] ta TA instance to get the circuit bitmask. + * \returns bitmask of OSMO_V24_C_*. */ +unsigned int osmo_v110_ta_get_status(const struct osmo_v110_ta *ta) +{ + return ta->state.v24_flags; +} + +/*! Set the V.24 status bitmask of the given TA instance. + * \param[in] ta TA instance to update the circuit state. + * \param[in] status bitmask of OSMO_V24_C_*. + * \returns 0 on success; negative on error. */ +int osmo_v110_ta_set_status(struct osmo_v110_ta *ta, unsigned int status) +{ + const unsigned int old_status = ta->state.v24_flags; + int rc = 0; + + ta->state.v24_flags = status; + if (status != old_status) + rc = osmo_fsm_inst_dispatch(ta->fi, V110_TA_EV_V24_STATUS_CHG, NULL); + + return rc; +} + +/*! Get state of a V.24 circuit of the given TA instance. + * \param[in] ta TA instance to get the circuit state. + * \param[in] circuit a V.24 circuit, one of OSMO_V24_C_*. + * \returns circuit state: active (true) or inactive (false). */ +bool osmo_v110_ta_get_circuit(const struct osmo_v110_ta *ta, + enum osmo_v24_circuit circuit) +{ + return V24_FLAGMASK_IS_ON(ta->state.v24_flags, circuit); +} + +/*! Activate/deactivate a V.24 circuit of the given TA instance. + * \param[in] ta TA instance to update the circuit state. + * \param[in] circuit a V.24 circuit, one of OSMO_V24_C_*. + * \param[in] active activate (true) or deactivate (false) the circuit. */ +void osmo_v110_ta_set_circuit(struct osmo_v110_ta *ta, + enum osmo_v24_circuit circuit, bool active) +{ + unsigned int status = ta->state.v24_flags; + + if (active) + V24_FLAGMASK_SET_ON(status, circuit); + else + V24_FLAGMASK_SET_OFF(status, circuit); + + osmo_v110_ta_set_status(ta, status); +} -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35444?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I5716bd6fd0201ee7a7a29e72f775972cd374082f Gerrit-Change-Number: 35444 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in osmo-bsc[master]: VTY: fix config indentation for pcu-socket
by keith 26 Dec '23

26 Dec '23
keith has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email ) Change subject: VTY: fix config indentation for pcu-socket ...................................................................... Patch Set 2: (1 comment) Patchset: PS2: I'd be tempted to just merge this based on https://osmocom.org/projects/cellular-infrastructure/wiki/Gerrit#Exceptions… -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I36a66794e654989b4b8bf54bb3727ccbfc2131fa Gerrit-Change-Number: 35443 Gerrit-PatchSet: 2 Gerrit-Owner: keith <keith(a)rhizomatica.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: keith <keith(a)rhizomatica.org> Gerrit-Comment-Date: Tue, 26 Dec 2023 00:35:34 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
1 0
0 0
[S] Change in osmo-bsc[master]: VTY: fix config indentation for pcu-socket
by keith 26 Dec '23

26 Dec '23
keith has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email ) Change subject: VTY: fix config indentation for pcu-socket ...................................................................... Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I36a66794e654989b4b8bf54bb3727ccbfc2131fa Gerrit-Change-Number: 35443 Gerrit-PatchSet: 2 Gerrit-Owner: keith <keith(a)rhizomatica.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: keith <keith(a)rhizomatica.org> Gerrit-Comment-Date: Tue, 26 Dec 2023 00:33:10 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in osmo-bsc[master]: VTY: fix config indentation for pcu-socket
by keith 26 Dec '23

26 Dec '23
keith has uploaded a new patch set (#2). ( https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email ) Change subject: VTY: fix config indentation for pcu-socket ...................................................................... VTY: fix config indentation for pcu-socket osmo-bsc would not start with a config written from the vty due to incorrect identation on the pcu-socket parameter. Change-Id: I36a66794e654989b4b8bf54bb3727ccbfc2131fa --- M src/osmo-bsc/bsc_vty.c 1 file changed, 13 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/43/35443/2 -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I36a66794e654989b4b8bf54bb3727ccbfc2131fa Gerrit-Change-Number: 35443 Gerrit-PatchSet: 2 Gerrit-Owner: keith <keith(a)rhizomatica.org> Gerrit-CC: Jenkins Builder Gerrit-MessageType: newpatchset
1 0
0 0
[S] Change in osmo-bsc[master]: VTY: fix config indentation for pcu-socket
by keith 26 Dec '23

26 Dec '23
keith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email ) Change subject: VTY: fix config indentation for pcu-socket ...................................................................... VTY: fix config indentation for pcu-socket osmo-bsc would not start with a config written from the vty due to incorrect identation on the pcu-socket parameter. Change-Id: I36a66794e654989b4b8bf54bb3727ccbfc2131fa --- M src/osmo-bsc/bsc_vty.c 1 file changed, 13 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/43/35443/1 diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c index bdc18b6..cc0a61a 100644 --- a/src/osmo-bsc/bsc_vty.c +++ b/src/osmo-bsc/bsc_vty.c @@ -415,7 +415,7 @@ } if (gsmnet->pcu_sock_path) - vty_out(vty, " pcu-socket %s%s", gsmnet->pcu_sock_path, VTY_NEWLINE); + vty_out(vty, " pcu-socket %s%s", gsmnet->pcu_sock_path, VTY_NEWLINE); neighbor_ident_vty_write_network(vty, " "); mgcp_client_pool_config_write(vty, " "); -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/35443?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I36a66794e654989b4b8bf54bb3727ccbfc2131fa Gerrit-Change-Number: 35443 Gerrit-PatchSet: 1 Gerrit-Owner: keith <keith(a)rhizomatica.org> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in pysim[master]: data-driven TLV unit data test support
by laforge 23 Dec '23

23 Dec '23
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35441?usp=email ) Change subject: data-driven TLV unit data test support ...................................................................... data-driven TLV unit data test support While we do have the _test_de_encode data driven tests for file definitions, we don't yet have something similar for derived classes of BER_TLV_IE. This means that TLVs used outside of the filesystem context (for example, decoding the SELECT/STATUS response, but also eUICC and other stuff) do not yet have test coverage. This commit just adds the related test code, but no test data yet. Related: OS#6317 Change-Id: Ied85f292bb57fde11dc188be84e3384dc3ff1601 --- A tests/test_tlvs.py 1 file changed, 138 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/41/35441/1 diff --git a/tests/test_tlvs.py b/tests/test_tlvs.py new file mode 100755 index 0000000..d35be3b --- /dev/null +++ b/tests/test_tlvs.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 + +# (C) 2023 by Harald Welte <laforge(a)osmocom.org> +# +# 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.utils import b2h, h2b, all_subclasses +from pySim.tlv import * + +import pySim.iso7816_4 +import pySim.ts_102_221 +import pySim.ts_102_222 +import pySim.ts_31_102 +import pySim.ts_31_103 +import pySim.ts_51_011 +import pySim.sysmocom_sja2 +import pySim.gsm_r +import pySim.cdma_ruim + +if 'unittest.util' in __import__('sys').modules: + # Show full diff in self.assertEqual. + __import__('sys').modules['unittest.util']._MAX_LENGTH = 999999999 + +def get_qualified_name(c): + """return the qualified (by module) name of a class.""" + return "%s.%s" % (c.__module__, c.__name__) + +class TLV_IE_Test(unittest.TestCase): + maxDiff = None + + @classmethod + def get_classes(cls): + """get list of TLV_IE sub-classes.""" + return all_subclasses(TLV_IE) + + @classmethod + def setUpClass(cls): + """set-up method called once for this class by unittest framework""" + cls.classes = cls.get_classes() + + def test_decode_tlv(self): + """Test the decoder for a TLV_IE. Requires the given TLV_IE subclass + to have a '_test_decode' attribute, containing a list of tuples. Each tuple + is a 2-tuple (hexstring, decoded_dict). + """ + for c in self.classes: + name = get_qualified_name(c) + if hasattr(c, '_test_decode'): + for t in c._test_decode: + with self.subTest(name, test_decode=t): + inst = c() + encoded = t[0] + decoded = t[1] + context = t[2] if len(t) == 3 else {} + logging.debug("Testing decode of %s", name) + re_dec, remainder = inst.from_tlv(h2b(encoded), context=context) + self.assertEqual(decoded, re_dec) + + def test_encode_tlv(self): + """Test the encoder for a TLV_IE. Requires the given TLV_IE subclass + to have a '_test_encode' attribute, containing a list of tuples. Each tuple + is a 2-tuple (hexstring, decoded_dict). + """ + for c in self.classes: + name = get_qualified_name(c) + if hasattr(c, '_test_encode'): + for t in c._test_encode: + with self.subTest(name, test_encode=t): + inst = c() + encoded = t[0] + decoded = t[1] + context = t[2] if len(t) == 3 else {} + logging.debug("Testing encode of %s", name) + inst.from_dict(decoded) + re_enc = b2h(inst.to_tlv(context)) + self.assertEqual(encoded.upper(), re_enc.upper()) + + def test_de_encode_tlv(self): + """Test the decoder and encoder for a TLV_IE. Performs first a decoder + test, and then re-encodes the decoded data, comparing the re-encoded data with the + initial input data. + + Requires the given TLV_IE subclass to have a '_test_de_encode' attribute, + containing a list of tuples. Each tuple is a 2-tuple (hexstring, decoded_dict). + """ + for c in self.classes: + name = get_qualified_name(c) + if hasattr(c, '_test_de_encode'): + for t in c._test_de_encode: + with self.subTest(name, test_de_encode=t): + inst = c() + encoded = t[0] + decoded = t[1] + context = t[2] if len(t) == 3 else {} + logging.debug("Testing decode of %s", name) + re_dec, remainder = inst.from_tlv(h2b(encoded), context=context) + self.assertEqual(decoded, re_dec) + logging.debug("Testing re-encode of %s", name) + re_enc = b2h(inst.to_tlv(context=context)) + self.assertEqual(encoded.upper(), re_enc.upper()) + + +if __name__ == '__main__': + logger = logging.getLogger() + logger.setLevel(logging.DEBUG) + unittest.main() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35441?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Ied85f292bb57fde11dc188be84e3384dc3ff1601 Gerrit-Change-Number: 35441 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: Fix enumeration of GlobbalPlatformISDR during card_init()
by laforge 23 Dec '23

23 Dec '23
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35440?usp=email ) Change subject: Fix enumeration of GlobbalPlatformISDR during card_init() ...................................................................... Fix enumeration of GlobbalPlatformISDR during card_init() We used __subclasses__(), but this only returns the immediate subclasses and not all further/nested subclasses. Instead, we must use the pySim.utils.all_subclasses() function to really get all of them. The hack to use the method signature of the constructor to determine if it's an intermediate class didn't work, as even GlobbalPlatformISDR has a optional argument for non-default AIDs. So let's introduce an explicit class attribute for that purpose. Change-Id: I7fb1637f8f7a149b536c4d77dac92736c526aa6c --- M pySim/app.py M pySim/global_platform.py 2 files changed, 23 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/40/35440/1 diff --git a/pySim/app.py b/pySim/app.py index b0df85f..421cb4d 100644 --- a/pySim/app.py +++ b/pySim/app.py @@ -14,7 +14,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -import inspect from typing import Tuple from pySim.transport import LinkBase @@ -26,6 +25,7 @@ from pySim.profile import CardProfile from pySim.cdma_ruim import CardProfileRUIM from pySim.ts_102_221 import CardProfileUICC +from pySim.utils import all_subclasses # we need to import this module so that the SysmocomSJA2 sub-class of # CardModel is created, which will add the ATR-based matching and @@ -87,10 +87,9 @@ # We cannot do it within pySim/profile.py as that would create circular # dependencies between the individual profiles and profile.py. if isinstance(profile, CardProfileUICC): - for app_cls in CardApplication.__subclasses__(): - constr_sig = inspect.signature(app_cls.__init__) + for app_cls in all_subclasses(CardApplication): # skip any intermediary sub-classes such as CardApplicationSD - if len(constr_sig.parameters) != 1: + if hasattr(app_cls, 'intermediate') and app_cls.intermediate: continue profile.add_application(app_cls()) # We have chosen SimCard() above, but we now know it actually is an UICC diff --git a/pySim/global_platform.py b/pySim/global_platform.py index 136cccc..5382f93 100644 --- a/pySim/global_platform.py +++ b/pySim/global_platform.py @@ -253,11 +253,13 @@ # Card Application of a Security Domain class CardApplicationSD(CardApplication): + intermediate = True def __init__(self, aid: str, name: str, desc: str): super().__init__(name, adf=ADF_SD(aid, name, desc), sw=sw_table) # Card Application of Issuer Security Domain class CardApplicationISD(CardApplicationSD): + intermediate = False # FIXME: ISD AID is not static, but could be different. One can select the empty # application using '00a4040000' and then parse the response FCI to get the ISD AID def __init__(self, aid='a000000003000000'): -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35440?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I7fb1637f8f7a149b536c4d77dac92736c526aa6c Gerrit-Change-Number: 35440 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: filesystem: use pySim.utils.build_construct()
by laforge 23 Dec '23

23 Dec '23
Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/35439?usp=email to look at the new patch set (#2). The following approvals got outdated and were removed: Verified+1 by Jenkins Builder Change subject: filesystem: use pySim.utils.build_construct() ...................................................................... filesystem: use pySim.utils.build_construct() We recently introduced a pySim.utils.build_construct() wrapper around the raw call of the construct.build() method. So far, this wrapper was only used from pySim.tlv, but let's also use it from pySim.filesystem. Basically, whenever we use parse_construct(), we should use build_construct() as the inverse operation. Change-Id: Ibfd61cd87edc72882aa66d6ff17861a3e918affb --- M pySim/filesystem.py M pySim/sysmocom_sja2.py 2 files changed, 26 insertions(+), 9 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/39/35439/2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35439?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Ibfd61cd87edc72882aa66d6ff17861a3e918affb Gerrit-Change-Number: 35439 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-MessageType: newpatchset
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • ...
  • 161
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.