libosmo-trx 1.8.0.50-7f5e
Osmocom TRX protocol (TRXC/TRXD) library
trxc.c File Reference

TRXC (control) protocol and clock indications: I/O-free message codec. More...

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/gsm0502.h>
#include <osmocom/trx/trxc.h>

Functions

int osmo_trxc_msg_parse (struct osmo_trxc_msg *msg, const char *buf, size_t len)
 Parse a TRXC message ("CMD <verb> [<params>]", "RSP <verb> <status> [<params>]" or "IND <verb> <params>") from a zero-terminated buffer. More...
 
int osmo_trxc_msg_build (char *buf, size_t buf_size, const struct osmo_trxc_msg *msg)
 Serialize a TRXC message into the given buffer (zero-terminated). More...
 
int osmo_trxc_msg_params_scan (const struct osmo_trxc_msg *msg, const char *fmt,...)
 Parse the parameters string of a TRXC message, sscanf() style. More...
 
const char * osmo_trxc_msg_name (const struct osmo_trxc_msg *msg)
 Compose a human-readable representation of the given message (for logging), store into a thread-local static buffer. More...
 
char * osmo_trxc_msg_name_buf (char *buf, size_t buf_size, const struct osmo_trxc_msg *msg)
 Compose a human-readable representation of the given message (for logging), store into the given buffer. More...
 
int osmo_trxc_setslot_parse (struct osmo_trxc_setslot *ss, const struct osmo_trxc_msg *msg)
 Parse SETSLOT parameters ("<tn> <chan_comb> [C<tsc>/S<tsc_set> ...]") from an already-parsed TRXC message's msg->params. More...
 
int osmo_trxc_setslot_build (char *buf, size_t buf_size, const struct osmo_trxc_setslot *ss)
 Serialize SETSLOT parameters ("<tn> <chan_comb> [C<tsc>/S<tsc_set> ...]") into the given buffer (zero-terminated), for use as msg->params. More...
 
int osmo_trxc_clock_ind_parse (uint32_t *fn, const char *buf, size_t len)
 Parse a clock indication ("IND CLOCK <fn>"). More...
 
int osmo_trxc_clock_ind_build (char *buf, size_t buf_size, uint32_t fn)
 Serialize a clock indication ("IND CLOCK <fn>") into the given buffer. More...
 

Variables

static const struct value_string trxc_msg_type_names []
 
const struct value_string osmo_trxc_chan_comb_names []
 
const struct value_string osmo_trxc_vamos_comb_names []
 

Detailed Description

TRXC (control) protocol and clock indications: I/O-free message codec.

Based on the TRXC implementation in osmo-bts-trx and osmo-trx.

Function Documentation

◆ osmo_trxc_clock_ind_build()

int osmo_trxc_clock_ind_build ( char *  buf,
size_t  buf_size,
uint32_t  fn 
)

Serialize a clock indication ("IND CLOCK <fn>") into the given buffer.

Parameters
[out]bufmessage buffer to store the result
[in]buf_sizesize of the message buffer
[in]fnTDMA frame number (validated to be < GSM_TDMA_HYPERFRAME)
Returns
length of the message (excl. '\0') on success; negative on error

Referenced by osmo_trx_ep_send_clck_ind().

◆ osmo_trxc_clock_ind_parse()

int osmo_trxc_clock_ind_parse ( uint32_t *  fn,
const char *  buf,
size_t  len 
)

Parse a clock indication ("IND CLOCK <fn>").

Parameters
[out]fnTDMA frame number (validated to be < GSM_TDMA_HYPERFRAME)
[in]bufmessage buffer (not necessarily zero-terminated)
[in]lenlength of the message in the buffer
Returns
0 on success; negative on error

References osmo_trxc_msg::cmd, osmo_trxc_msg_params_scan(), osmo_trxc_msg_parse(), OSMO_TRXC_MT_IND, and osmo_trxc_msg::type.

Referenced by trx_ep_clck_read_cb().

◆ osmo_trxc_msg_build()

int osmo_trxc_msg_build ( char *  buf,
size_t  buf_size,
const struct osmo_trxc_msg *  msg 
)

Serialize a TRXC message into the given buffer (zero-terminated).

Returns
length of the message (excl. '\0') on success; negative on error

References osmo_trxc_msg::cmd, OSMO_TRXC_MT_CMD, OSMO_TRXC_MT_IND, OSMO_TRXC_MT_RSP, osmo_trxc_msg::params, osmo_trxc_msg::status, trxc_msg_type_names, and osmo_trxc_msg::type.

Referenced by osmo_trx_ep_send_ctrl_msg(), and osmo_trxc_msg_name_buf().

◆ osmo_trxc_msg_name()

const char * osmo_trxc_msg_name ( const struct osmo_trxc_msg *  msg)

Compose a human-readable representation of the given message (for logging), store into a thread-local static buffer.

Parameters
[in]msgparsed TRXC message to get a human-readable representation of
Returns
pointer to a thread-local static buffer; NULL on error

References OSMO_TRXC_MSG_BUF_SIZE, and osmo_trxc_msg_name_buf().

Referenced by osmo_trxc_client_rx_msg(), trxc_client_default_rsp_cb(), trxc_client_fatal(), and trxc_client_send_next().

◆ osmo_trxc_msg_name_buf()

char * osmo_trxc_msg_name_buf ( char *  buf,
size_t  buf_size,
const struct osmo_trxc_msg *  msg 
)

Compose a human-readable representation of the given message (for logging), store into the given buffer.

Parameters
[out]bufoutput buffer to store the result
[in]buf_sizesize of the output buffer
[in]msgparsed TRXC message to get a human-readable representation of
Returns
pointer to the given buffer; NULL on error

References osmo_trxc_msg_build().

Referenced by osmo_trxc_msg_name().

◆ osmo_trxc_msg_params_scan()

int osmo_trxc_msg_params_scan ( const struct osmo_trxc_msg *  msg,
const char *  fmt,
  ... 
)

Parse the parameters string of a TRXC message, sscanf() style.

Returns
number of successfully matched items (see sscanf)

References osmo_trxc_msg::params.

Referenced by osmo_trxc_clock_ind_parse().

◆ osmo_trxc_msg_parse()

int osmo_trxc_msg_parse ( struct osmo_trxc_msg *  msg,
const char *  buf,
size_t  len 
)

Parse a TRXC message ("CMD <verb> [<params>]", "RSP <verb> <status> [<params>]" or "IND <verb> <params>") from a zero-terminated buffer.

Parameters
[out]msgparsed message
[in]bufmessage buffer (not necessarily zero-terminated)
[in]lenlength of the message in the buffer
Returns
0 on success; negative on error

References osmo_trxc_msg::cmd, OSMO_TRXC_MSG_BUF_SIZE, OSMO_TRXC_MT_CMD, OSMO_TRXC_MT_IND, OSMO_TRXC_MT_RSP, osmo_trxc_msg::params, osmo_trxc_msg::status, and osmo_trxc_msg::type.

Referenced by osmo_trxc_client_rx(), osmo_trxc_clock_ind_parse(), and trx_ep_ctrl_recvfrom_cb().

◆ osmo_trxc_setslot_build()

int osmo_trxc_setslot_build ( char *  buf,
size_t  buf_size,
const struct osmo_trxc_setslot *  ss 
)

Serialize SETSLOT parameters ("<tn> <chan_comb> [C<tsc>/S<tsc_set> ...]") into the given buffer (zero-terminated), for use as msg->params.

Returns
length of the string (excl. '\0') on success; negative on error

References osmo_trxc_setslot::chan_comb, osmo_trxc_setslot::num_tsc, osmo_trxc_vamos_comb_name(), osmo_trxc_setslot::tn, osmo_trxc_setslot_tsc::tsc, osmo_trxc_setslot::tsc, osmo_trxc_setslot_tsc::tsc_set, osmo_trxc_setslot::vamos, and osmo_trxc_setslot::vamos_comb.

◆ osmo_trxc_setslot_parse()

int osmo_trxc_setslot_parse ( struct osmo_trxc_setslot *  ss,
const struct osmo_trxc_msg *  msg 
)

Variable Documentation

◆ osmo_trxc_chan_comb_names

const struct value_string osmo_trxc_chan_comb_names[]
Initial value:
= {
{ OSMO_TRXC_CHAN_COMB_TCHH_IDLE, "TCH/H (sub-ch 1 idle)" },
{ OSMO_TRXC_CHAN_COMB_BCCH_SDCCH4, "BCCH+SDCCH/4" },
{ OSMO_TRXC_CHAN_COMB_TCHF_FACCH_SACCHM, "TCH/F+FACCH+SACCH/M" },
{ OSMO_TRXC_CHAN_COMB_TCHF_SACCHM, "TCH/F+SACCH/M" },
{ OSMO_TRXC_CHAN_COMB_TCHFD_SACCHMD, "TCH/FD+SACCH/MD" },
{ 0, NULL }
}
@ OSMO_TRXC_CHAN_COMB_BCCH_SDCCH4
DL: +SDCCH/4+SACCH/4, UL: +SDCCH/4.
Definition: trxc.h:79
@ OSMO_TRXC_CHAN_COMB_BCCH
DL: FCCH+SCH+CCCH+BCCH, UL: RACH.
Definition: trxc.h:78
@ OSMO_TRXC_CHAN_COMB_CCCH
DL: CCCH+BCCH, UL: RACH.
Definition: trxc.h:80
@ OSMO_TRXC_CHAN_COMB_TCHH
Definition: trxc.h:77
@ OSMO_TRXC_CHAN_COMB_TCHF_SACCHM
Definition: trxc.h:83
@ OSMO_TRXC_CHAN_COMB_TCHF_FACCH_SACCHM
Definition: trxc.h:82
@ OSMO_TRXC_CHAN_COMB_PDTCH
PDTCH+PACCH+PTCCH.
Definition: trxc.h:87
@ OSMO_TRXC_CHAN_COMB_SDCCH8
SDCCH/8 + SACCH/8.
Definition: trxc.h:81
@ OSMO_TRXC_CHAN_COMB_UNUSED
Channel is transmitted, but unused.
Definition: trxc.h:74
@ OSMO_TRXC_CHAN_COMB_PCCCH
PCCCH+PDTCH+PACCH+PTCCH.
Definition: trxc.h:86
@ OSMO_TRXC_CHAN_COMB_TCHH_IDLE
TCH/HS, idle every other slot.
Definition: trxc.h:76
@ OSMO_TRXC_CHAN_COMB_PBCCH
PBCCH+PCCCH+PDTCH+PACCH+PTCCH.
Definition: trxc.h:85
@ OSMO_TRXC_CHAN_COMB_TCHFD_SACCHMD
Definition: trxc.h:84
@ OSMO_TRXC_CHAN_COMB_TCHF
Definition: trxc.h:75

Referenced by osmo_trxc_chan_comb_name().

◆ osmo_trxc_vamos_comb_names

const struct value_string osmo_trxc_vamos_comb_names[]
Initial value:
= {
{ 0, NULL }
}
@ OSMO_TRXC_VAMOS_COMB_HVHH
TCH/H0 + V0(TCH/H1) & V1(TCH/H1) (mixed)
Definition: trxc.h:102
@ OSMO_TRXC_VAMOS_COMB_VFH
V0(TCH/F) & V1(TCH/H0) + V0(TCH/F) & V1(TCH/H1)
Definition: trxc.h:101
@ OSMO_TRXC_VAMOS_COMB_VHH
V0(TCH/H0)&V1(TCH/H0) + V0(TCH/H1)&V1(TCH/H1)
Definition: trxc.h:100
@ OSMO_TRXC_VAMOS_COMB_VFF
V0(TCH/F) & V1(TCH/F)
Definition: trxc.h:99

Referenced by osmo_trxc_setslot_parse(), and osmo_trxc_vamos_comb_name().

◆ trxc_msg_type_names

const struct value_string trxc_msg_type_names[]
static
Initial value:
= {
{ OSMO_TRXC_MT_CMD, "CMD" },
{ OSMO_TRXC_MT_RSP, "RSP" },
{ OSMO_TRXC_MT_IND, "IND" },
{ 0, NULL }
}
@ OSMO_TRXC_MT_CMD
"CMD <verb> [<params>]" (L1 -> TRX)
Definition: trxc.h:23
@ OSMO_TRXC_MT_IND
"IND <verb> <params>" (TRX -> L1)
Definition: trxc.h:25
@ OSMO_TRXC_MT_RSP
"RSP <verb> <status> [<params>]" (TRX -> L1)
Definition: trxc.h:24

Referenced by osmo_trxc_msg_build().