libosmoisdn 1.9.0.197-fb8cd
Osmocom ISDN library
v110_ta.c File Reference

TA (Terminal Adapter) implementation as per ITU-T V.110. More...

#include <stdbool.h>
#include <stdint.h>
#include <errno.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/tdef.h>
#include <osmocom/core/fsm.h>
#include <osmocom/isdn/v110.h>
#include <osmocom/isdn/v110_ta.h>

Data Structures

struct  v110_ta_state
 
struct  osmo_v110_ta
 

Macros

#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)    (flags) |= S(circuit)
 
#define V24_FLAGMASK_SET_OFF(flags, circuit)    (flags) &= ~S(circuit)
 
#define V110_SX_BIT_ON   0
 
#define V110_SX_BIT_OFF   1
 
#define v110_ta_fsm_state_chg(state)
 

Enumerations

enum  v110_ta_fsm_state {
  V110_TA_ST_IDLE_READY ,
  V110_TA_ST_CON_TA_TO_LINE ,
  V110_TA_ST_DATA_TRANSFER ,
  V110_TA_ST_DISCONNECTING ,
  V110_TA_ST_RESYNCING
}
 
enum  v110_ta_fsm_event {
  V110_TA_EV_RX_FRAME_IND ,
  V110_TA_EV_TX_FRAME_RTS ,
  V110_TA_EV_V24_STATUS_CHG ,
  V110_TA_EV_SYNC_IND ,
  V110_TA_EV_DESYNC_IND ,
  V110_TA_EV_TIMEOUT
}
 
enum  v110_ta_d_bit_mode {
  V110_TA_DBIT_M_ALL_ZERO = 0 ,
  V110_TA_DBIT_M_ALL_ONE = 1 ,
  V110_TA_DBIT_M_FORWARD
}
 

Functions

static bool v110_df_x_bits_are (const struct osmo_v110_decoded_frame *df, ubit_t cmp)
 
static bool v110_df_s_bits_are (const struct osmo_v110_decoded_frame *df, ubit_t cmp)
 
static bool v110_df_d_bits_are (const struct osmo_v110_decoded_frame *df, ubit_t cmp)
 
static void v110_ta_handle_frame (const struct osmo_v110_ta *ta, const struct osmo_v110_decoded_frame *df)
 
static void v110_ta_build_frame (const struct osmo_v110_ta *ta, struct osmo_v110_decoded_frame *df)
 
static void v110_ta_flags_update (struct osmo_v110_ta *ta, unsigned int v24_flags)
 
static void v110_ta_fsm_idle_ready_onenter (struct osmo_fsm_inst *fi, uint32_t prev_state)
 
static void v110_ta_fsm_idle_ready (struct osmo_fsm_inst *fi, uint32_t event, void *data)
 
static void v110_ta_fsm_connect_ta_to_line_onenter (struct osmo_fsm_inst *fi, uint32_t prev_state)
 
static void v110_ta_fsm_connect_ta_to_line (struct osmo_fsm_inst *fi, uint32_t event, void *data)
 
static void v110_ta_fsm_data_transfer_onenter (struct osmo_fsm_inst *fi, uint32_t prev_state)
 
static void v110_ta_fsm_data_transfer (struct osmo_fsm_inst *fi, uint32_t event, void *data)
 
static void v110_ta_fsm_disconnect_onenter (struct osmo_fsm_inst *fi, uint32_t prev_state)
 
static void v110_ta_fsm_disconnect (struct osmo_fsm_inst *fi, uint32_t event, void *data)
 
static void v110_ta_fsm_resyncing_onenter (struct osmo_fsm_inst *fi, uint32_t prev_state)
 
static void v110_ta_fsm_resyncing (struct osmo_fsm_inst *fi, uint32_t event, void *data)
 
static int v110_ta_timer_cb (struct osmo_fsm_inst *fi)
 
static __attribute__ ((constructor))
 
struct osmo_v110_taosmo_v110_ta_alloc (void *ctx, const char *name, const struct osmo_v110_ta_cfg *cfg)
 Allocate a V.110 TA (Terminal Adapter) instance. More...
 
void osmo_v110_ta_free (struct osmo_v110_ta *ta)
 Release memory taken by the given V.110 TA instance. More...
 
int osmo_v110_ta_set_timer_val_ms (struct osmo_v110_ta *ta, enum osmo_v110_ta_timer timer, unsigned long val_ms)
 Configure a timer of the given V.110 TA instance. More...
 
int osmo_v110_ta_frame_in (struct osmo_v110_ta *ta, const struct osmo_v110_decoded_frame *in)
 Feed a [decoded] V.110 frame into the given TA instance. More...
 
int osmo_v110_ta_frame_out (struct osmo_v110_ta *ta, struct osmo_v110_decoded_frame *out)
 Pull a [decoded] V.110 frame out of the given TA instance. More...
 
int osmo_v110_ta_sync_ind (struct osmo_v110_ta *ta)
 Indicate a synchronization establishment event. More...
 
int osmo_v110_ta_desync_ind (struct osmo_v110_ta *ta)
 Indicate a synchronization loss event. More...
 
unsigned int osmo_v110_ta_get_status (const struct osmo_v110_ta *ta)
 Get the V.24 status bit-mask of the given TA instance. More...
 
static int v110_ta_set_status (struct osmo_v110_ta *ta, unsigned int status)
 Set the V.24 status bit-mask of the given TA instance. More...
 
bool osmo_v110_ta_get_circuit (const struct osmo_v110_ta *ta, enum osmo_v110_ta_circuit circuit)
 Get state of a V.24 circuit of the given TA instance. More...
 
int osmo_v110_ta_set_circuit (struct osmo_v110_ta *ta, enum osmo_v110_ta_circuit circuit, bool active)
 Activate/deactivate a V.24 circuit of the given TA instance. More...
 

Variables

const struct value_string osmo_v110_ta_circuit_names []
 
const struct value_string osmo_v110_ta_circuit_descs []
 
static const struct osmo_tdef v110_ta_tdef []
 
static const struct value_string v110_ta_fsm_event_names []
 
static const struct osmo_tdef_state_timeout v110_ta_fsm_timeouts [32]
 
static const struct osmo_fsm_state v110_ta_states []
 
static struct osmo_fsm osmo_v110_ta_fsm
 

Detailed Description

TA (Terminal Adapter) implementation as per ITU-T V.110.

Macro Definition Documentation

◆ S

#define S (   x)    (1 << (x))

◆ V110_SX_BIT_OFF

#define V110_SX_BIT_OFF   1

◆ V110_SX_BIT_ON

#define V110_SX_BIT_ON   0

◆ v110_ta_fsm_state_chg

#define v110_ta_fsm_state_chg (   state)
Value:
((struct osmo_v110_ta *)(fi->priv))->Tdefs, \
0)
#define osmo_tdef_fsm_inst_state_chg(fi, state, timeouts_array, tdefs, default_timeout)
Definition: v110_ta.c:144
static const struct osmo_tdef_state_timeout v110_ta_fsm_timeouts[32]
Definition: v110_ta.c:261

◆ V24_FLAGMASK_IS_OFF

#define V24_FLAGMASK_IS_OFF (   flags,
  circuit 
)     (((flags) & S(circuit)) == 0)

◆ V24_FLAGMASK_IS_ON

#define V24_FLAGMASK_IS_ON (   flags,
  circuit 
)     (((flags) & S(circuit)) != 0)

◆ V24_FLAGMASK_SET_OFF

#define V24_FLAGMASK_SET_OFF (   flags,
  circuit 
)     (flags) &= ~S(circuit)

◆ V24_FLAGMASK_SET_ON

#define V24_FLAGMASK_SET_ON (   flags,
  circuit 
)     (flags) |= S(circuit)

Enumeration Type Documentation

◆ v110_ta_d_bit_mode

Enumerator
V110_TA_DBIT_M_ALL_ZERO 
V110_TA_DBIT_M_ALL_ONE 
V110_TA_DBIT_M_FORWARD 

◆ v110_ta_fsm_event

Enumerator
V110_TA_EV_RX_FRAME_IND 
V110_TA_EV_TX_FRAME_RTS 
V110_TA_EV_V24_STATUS_CHG 
V110_TA_EV_SYNC_IND 
V110_TA_EV_DESYNC_IND 
V110_TA_EV_TIMEOUT 

◆ v110_ta_fsm_state

Enumerator
V110_TA_ST_IDLE_READY 
V110_TA_ST_CON_TA_TO_LINE 
V110_TA_ST_DATA_TRANSFER 
V110_TA_ST_DISCONNECTING 
V110_TA_ST_RESYNCING 

Function Documentation

◆ __attribute__()

static __attribute__ ( (constructor)  )
static

◆ osmo_v110_ta_alloc()

struct osmo_v110_ta * osmo_v110_ta_alloc ( void *  ctx,
const char *  name,
const struct osmo_v110_ta_cfg cfg 
)

Allocate a V.110 TA (Terminal Adapter) instance.

Parameters
[in]ctxparent talloc context.
[in]namename of the TA instance.
[in]cfginitial configuration of the TA instance.
Returns
pointer to allocated TA instance; NULL on error.

References osmo_v110_ta::cfg, DLGLOBAL, osmo_v110_ta::fi, osmo_v110_ta_cfg::flow_ctrl, osmo_v110_ta_cfg::local, LOGL_DEBUG, LOGL_ERROR, LOGP, name, osmo_v110_ta::name, OSMO_ASSERT, osmo_fsm_inst_alloc(), osmo_fsm_inst_free(), osmo_fsm_inst_state_chg, osmo_tdefs_reset(), OSMO_V110_LOCAL_FLOW_CTRL_NONE, osmo_v110_ta_fsm, osmo_v110_ta_cfg::rx_cb, osmo_v110_ta::Tdefs, osmo_v110_ta_cfg::tx_cb, V110_TA_ST_IDLE_READY, and v110_ta_tdef.

◆ osmo_v110_ta_desync_ind()

int osmo_v110_ta_desync_ind ( struct osmo_v110_ta ta)

Indicate a synchronization loss event.

This function is intended to be called when the lower layer experiences a loss of synchronization with the frame clock.

Parameters
[in]taTA instance to indicate the event to.
Returns
0 in case of success; negative on error.

References osmo_v110_ta::fi, osmo_fsm_inst_dispatch, and V110_TA_EV_DESYNC_IND.

◆ osmo_v110_ta_frame_in()

int osmo_v110_ta_frame_in ( struct osmo_v110_ta ta,
const struct osmo_v110_decoded_frame in 
)

Feed a [decoded] V.110 frame into the given TA instance.

This function, like its out counterpart, is intended to be used by the lower layers receiving V.110 frames over some medium. The caller of this function is responsible for finding the synchronization pattern (if needed), aligning to the frame boundaries, and decoding frames using osmo_v110_decode_frame() or osmo_csd*_decode_frame().

Bits E1/E2/E3 are expected to be set by the caller (if not being transmitted over the medium) in accordance with the configured synchronous user rate.

Bits D1..D48 are passed to the bit rate adaption function RA1. The resulting output is then passed to the upper layer (application) via the configured .rx_cb(). Though, in certain states of the TA's FSM, bits D1..D48 are ignored and the upper layer gets a sequence of binary '0' or '1'.

Parameters
[in]taTA instance to feed the given frame into.
[in]inpointer to a [decoded] V.110 frame.
Returns
0 in case of success; negative on error.

References osmo_v110_ta::fi, osmo_fsm_inst_dispatch, and V110_TA_EV_RX_FRAME_IND.

◆ osmo_v110_ta_frame_out()

int osmo_v110_ta_frame_out ( struct osmo_v110_ta ta,
struct osmo_v110_decoded_frame out 
)

Pull a [decoded] V.110 frame out of the given TA instance.

This function, like its in counterpart, is intended to be used by the lower layers transmitting V.110 frames over some medium. The caller of this function is responsible for encoding the output frame using osmo_v110_encode_frame() or osmo_csd*_encode_frame().

Bits E1/E2/E3 are set in accordance with the configured synchronous user rate. Bits E4/E5/E6/E7 are unconditionally set to binary '1'.

Bits D1..D48 are set depending on the state of TA's FSM:

  • In data transfer mode, the user bits are obtained from the upper layer (application) via the configured .tx_cb(), and then passed to the bit rate adaption function RA1, which generates bits D1..D48.
  • In other modes, bits D1..D48 are all set to binary '0' or '1'.
Parameters
[in]taTA instance to pull a frame from.
[out]outwhere to store a [decoded] V.110 frame.
Returns
0 in case of success; negative on error.

References osmo_v110_ta::fi, osmo_fsm_inst_dispatch, and V110_TA_EV_TX_FRAME_RTS.

◆ osmo_v110_ta_free()

void osmo_v110_ta_free ( struct osmo_v110_ta ta)

Release memory taken by the given V.110 TA instance.

Parameters
[in]taTA instance to be free()d.

References osmo_v110_ta::fi, and osmo_fsm_inst_free().

◆ osmo_v110_ta_get_circuit()

bool osmo_v110_ta_get_circuit ( const struct osmo_v110_ta ta,
enum osmo_v110_ta_circuit  circuit 
)

Get state of a V.24 circuit of the given TA instance.

Parameters
[in]taTA instance to get the circuit state.
[in]circuita V.24 circuit, one of OSMO_V110_TA_C_*.
Returns
circuit state: active (true) or inactive (false).

References osmo_v110_ta::state, V24_FLAGMASK_IS_ON, and v110_ta_state::v24_flags.

◆ osmo_v110_ta_get_status()

unsigned int osmo_v110_ta_get_status ( const struct osmo_v110_ta ta)

Get the V.24 status bit-mask of the given TA instance.

Parameters
[in]taTA instance to get the circuit bit-mask.
Returns
bitmask of OSMO_V110_TA_C_*.

References osmo_v110_ta::state, and v110_ta_state::v24_flags.

◆ osmo_v110_ta_set_circuit()

int osmo_v110_ta_set_circuit ( struct osmo_v110_ta ta,
enum osmo_v110_ta_circuit  circuit,
bool  active 
)

Activate/deactivate a V.24 circuit of the given TA instance.

Parameters
[in]taTA instance to update the circuit state.
[in]circuita V.24 circuit, one of OSMO_V110_TA_C_* (DTE->DCE).
[in]activeactivate (true) or deactivate (false) the circuit.
Returns
0 on success; negative on error.

References osmo_v110_ta::fi, LOGL_ERROR, LOGPFSML, OSMO_V110_TA_C_105, OSMO_V110_TA_C_108, OSMO_V110_TA_C_133, osmo_v110_ta_circuit_name(), osmo_v110_ta::state, v110_ta_set_status(), V24_FLAGMASK_SET_OFF, V24_FLAGMASK_SET_ON, and v110_ta_state::v24_flags.

◆ osmo_v110_ta_set_timer_val_ms()

int osmo_v110_ta_set_timer_val_ms ( struct osmo_v110_ta ta,
enum osmo_v110_ta_timer  timer,
unsigned long  val_ms 
)

Configure a timer of the given V.110 TA instance.

Parameters
[in]taTA instance to be configured.
[in]timera timer to be configured.
[in]val_msthe new timeout value to set (in milliseconds).
Returns
0 in case of success; negative on error.

References OSMO_TDEF_MS, osmo_tdef_set(), and osmo_v110_ta::Tdefs.

◆ osmo_v110_ta_sync_ind()

int osmo_v110_ta_sync_ind ( struct osmo_v110_ta ta)

Indicate a synchronization establishment event.

This function is intended to be called when the lower layer achieves synchronization to the frame clock.

Parameters
[in]taTA instance to indicate the event to.
Returns
0 in case of success; negative on error.

References osmo_v110_ta::fi, osmo_fsm_inst_dispatch, and V110_TA_EV_SYNC_IND.

◆ v110_df_d_bits_are()

static bool v110_df_d_bits_are ( const struct osmo_v110_decoded_frame df,
ubit_t  cmp 
)
inlinestatic

◆ v110_df_s_bits_are()

static bool v110_df_s_bits_are ( const struct osmo_v110_decoded_frame df,
ubit_t  cmp 
)
inlinestatic

◆ v110_df_x_bits_are()

static bool v110_df_x_bits_are ( const struct osmo_v110_decoded_frame df,
ubit_t  cmp 
)
inlinestatic

◆ v110_ta_build_frame()

◆ v110_ta_flags_update()

◆ v110_ta_fsm_connect_ta_to_line()

◆ v110_ta_fsm_connect_ta_to_line_onenter()

static void v110_ta_fsm_connect_ta_to_line_onenter ( struct osmo_fsm_inst fi,
uint32_t  prev_state 
)
static

◆ v110_ta_fsm_data_transfer()

◆ v110_ta_fsm_data_transfer_onenter()

◆ v110_ta_fsm_disconnect()

◆ v110_ta_fsm_disconnect_onenter()

◆ v110_ta_fsm_idle_ready()

◆ v110_ta_fsm_idle_ready_onenter()

◆ v110_ta_fsm_resyncing()

◆ v110_ta_fsm_resyncing_onenter()

static void v110_ta_fsm_resyncing_onenter ( struct osmo_fsm_inst fi,
uint32_t  prev_state 
)
static

◆ v110_ta_handle_frame()

◆ v110_ta_set_status()

static int v110_ta_set_status ( struct osmo_v110_ta ta,
unsigned int  status 
)
static

Set the V.24 status bit-mask of the given TA instance.

Parameters
[in]taTA instance to update the circuit state.
[in]statusbit-mask of OSMO_V110_TA_C_*.
Returns
0 on success; negative on error.

References osmo_v110_ta::fi, osmo_fsm_inst_dispatch, osmo_v110_ta::state, V110_TA_EV_V24_STATUS_CHG, and v110_ta_state::v24_flags.

Referenced by osmo_v110_ta_set_circuit().

◆ v110_ta_timer_cb()

static int v110_ta_timer_cb ( struct osmo_fsm_inst fi)
static

Variable Documentation

◆ osmo_v110_ta_circuit_descs

const struct value_string osmo_v110_ta_circuit_descs[]
Initial value:
= {
{ OSMO_V110_TA_C_105, "Request to Send" },
{ OSMO_V110_TA_C_106, "Clear to Send" },
{ OSMO_V110_TA_C_107, "Data Set Ready" },
{ OSMO_V110_TA_C_108, "Data Terminal Ready" },
{ OSMO_V110_TA_C_109, "Data Carrier Detect" },
{ OSMO_V110_TA_C_133, "Ready for receiving" },
{ 0, NULL }
}
@ OSMO_V110_TA_C_107
DTE<-DCE | DSR (Data Set Ready)
Definition: v110_ta.h:88
@ OSMO_V110_TA_C_109
DTE<-DCE | DCD (Data Carrier Detect)
Definition: v110_ta.h:90
@ OSMO_V110_TA_C_106
DTE<-DCE | CTS (Clear to Send)
Definition: v110_ta.h:87
@ OSMO_V110_TA_C_108
DTE->DCE | DTR (Data Terminal Ready)
Definition: v110_ta.h:89
@ OSMO_V110_TA_C_105
DTE->DCE | RTS (Request to Send)
Definition: v110_ta.h:86
@ OSMO_V110_TA_C_133
DTE->DCE | Ready for receiving.
Definition: v110_ta.h:91

Referenced by osmo_v110_ta_circuit_desc().

◆ osmo_v110_ta_circuit_names

const struct value_string osmo_v110_ta_circuit_names[]
Initial value:
= {
{ OSMO_V110_TA_C_105, "105/RTS" },
{ OSMO_V110_TA_C_106, "106/CTS" },
{ OSMO_V110_TA_C_107, "107/DSR" },
{ OSMO_V110_TA_C_108, "108/DTR" },
{ OSMO_V110_TA_C_109, "109/DCD" },
{ OSMO_V110_TA_C_133, "133" },
{ 0, NULL }
}

Referenced by osmo_v110_ta_circuit_name().

◆ osmo_v110_ta_fsm

struct osmo_fsm osmo_v110_ta_fsm
static
Initial value:
= {
.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,
}
#define DLGLOBAL
#define ARRAY_SIZE(x)
static int v110_ta_timer_cb(struct osmo_fsm_inst *fi)
Definition: v110_ta.c:596
static const struct osmo_fsm_state v110_ta_states[]
Definition: v110_ta.c:602
static const struct value_string v110_ta_fsm_event_names[]
Definition: v110_ta.c:112

Referenced by __attribute__(), and osmo_v110_ta_alloc().

◆ v110_ta_fsm_event_names

const struct value_string v110_ta_fsm_event_names[]
static
Initial value:
= {
{ V110_TA_EV_RX_FRAME_IND, "RX_FRAME_IND" },
{ V110_TA_EV_TX_FRAME_RTS, "TX_FRAME_RTS" },
{ V110_TA_EV_V24_STATUS_CHG, "V24_STATUS_CHG" },
{ V110_TA_EV_SYNC_IND, "SYNC_IND" },
{ V110_TA_EV_DESYNC_IND, "DESYNC_IND" },
{ V110_TA_EV_TIMEOUT, "TIMEOUT" },
{ 0, NULL }
}
@ V110_TA_EV_DESYNC_IND
Definition: v110_ta.c:108
@ V110_TA_EV_V24_STATUS_CHG
Definition: v110_ta.c:106
@ V110_TA_EV_RX_FRAME_IND
Definition: v110_ta.c:104
@ V110_TA_EV_TIMEOUT
Definition: v110_ta.c:109
@ V110_TA_EV_TX_FRAME_RTS
Definition: v110_ta.c:105
@ V110_TA_EV_SYNC_IND
Definition: v110_ta.c:107

◆ v110_ta_fsm_timeouts

const struct osmo_tdef_state_timeout v110_ta_fsm_timeouts[32]
static
Initial value:
= {
}
@ V110_TA_ST_CON_TA_TO_LINE
Definition: v110_ta.c:97
@ V110_TA_ST_RESYNCING
Definition: v110_ta.c:100
@ V110_TA_ST_DISCONNECTING
Definition: v110_ta.c:99
@ OSMO_V110_TA_TIMER_T1
7.1.2 Connect TA to line: sync establishment timer
Definition: v110_ta.h:67
@ OSMO_V110_TA_TIMER_T2
7.1.4 Disconnect mode: disconnect confirmation timer
Definition: v110_ta.h:69
@ OSMO_V110_TA_TIMER_X1
7.1.5 Loss of frame synchronization: sync recovery timer.
Definition: v110_ta.h:65

◆ v110_ta_states

const struct osmo_fsm_state v110_ta_states[]
static

◆ v110_ta_tdef

const struct osmo_tdef v110_ta_tdef[]
static
Initial value:
= {
.unit = OSMO_TDEF_MS, .default_val = 3000,
.desc = "ITU-T V.110 7.1.5 Loss of frame synchronization: sync recovery timer" },
.unit = OSMO_TDEF_MS, .default_val = 10000,
.desc = "ITU-T V.110 7.1.2 Connect TA to line: sync establishment timer" },
.unit = OSMO_TDEF_MS, .default_val = 5000,
.desc = "ITU-T V.110 7.1.4 Disconnect mode: disconnect confirmation timer" },
{ }
}
OSMO_TDEF_MS

Referenced by osmo_v110_ta_alloc().