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

TRXD (burst data) protocol: I/O-free PDU codec. More...

#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/gsm0502.h>
#include <osmocom/trx/trxd.h>

Macros

#define TRXD_IND_V0HDR_LEN   (1 + 4 + 1 + 2)
 
#define TRXD_IND_V1HDR_LEN   (TRXD_IND_V0HDR_LEN + 1 + 2)
 
#define TRXD_IND_V2HDR_LEN   (1 + 1 + 1 + 1 + 2 + 2)
 
#define TRXD_REQ_V01HDR_LEN   (1 + 4 + 1)
 
#define TRXD_REQ_V2HDR_LEN   (1 + 1 + 1 + 1 + 1 + 3)
 

Functions

void osmo_trxd_parse_state_init (struct osmo_trxd_parse_state *st)
 Initialize a parser state; call before parsing each datagram. More...
 
static int burst_len_by_mod (enum osmo_trxd_mod_type mod)
 
static int mts_parse (uint32_t *flags, enum osmo_trxd_mod_type *mod, uint8_t *tsc_set, uint8_t *tsc, uint8_t mts)
 
int trxd_mts_parse_ind (struct osmo_trxd_burst_ind *bi, uint8_t mts)
 
int trxd_mts_parse_req (struct osmo_trxd_burst_req *br, uint8_t mts)
 
static int mts_build (uint8_t *mts, uint32_t flags, enum osmo_trxd_mod_type mod, uint8_t tsc_set, uint8_t tsc)
 
int trxd_mts_build_ind (uint8_t *mts, const struct osmo_trxd_burst_ind *bi)
 
int trxd_mts_build_req (uint8_t *mts, const struct osmo_trxd_burst_req *br)
 
static void soft_bits_parse (sbit_t *out, const uint8_t *in, size_t len)
 
static void soft_bits_build (uint8_t *out, const sbit_t *in, size_t len)
 
static void trxd_burst_ind_parse_hdr_v0 (struct osmo_trxd_burst_ind *bi, const uint8_t *buf)
 
static int trxd_burst_ind_parse_v0 (struct osmo_trxd_burst_ind *bi, const uint8_t *buf, size_t buf_len)
 
static int trxd_burst_ind_parse_v1 (struct osmo_trxd_burst_ind *bi, const uint8_t *buf, size_t buf_len)
 
static int trxd_burst_ind_parse_v2 (struct osmo_trxd_parse_state *st, struct osmo_trxd_burst_ind *bi, const uint8_t *buf, size_t buf_len)
 
int osmo_trxd_burst_ind_parse (struct osmo_trxd_parse_state *st, struct osmo_trxd_burst_ind *bi, const uint8_t *buf, size_t buf_len)
 Parse one burst indication (TRX -> L1) PDU from the given buffer. More...
 
int osmo_trxd_burst_ind_build (struct msgb *msg, uint8_t pdu_ver, const struct osmo_trxd_burst_ind *bi)
 Append one encoded burst indication (TRX -> L1) PDU to the given msgb. More...
 
static int trxd_burst_req_parse_v01 (struct osmo_trxd_burst_req *br, const uint8_t *buf, size_t buf_len)
 
static int trxd_burst_req_parse_v2 (struct osmo_trxd_parse_state *st, struct osmo_trxd_burst_req *br, const uint8_t *buf, size_t buf_len)
 
int osmo_trxd_burst_req_parse (struct osmo_trxd_parse_state *st, struct osmo_trxd_burst_req *br, const uint8_t *buf, size_t buf_len)
 Parse one burst transmit request (L1 -> TRX) PDU from the given buffer. More...
 
int osmo_trxd_burst_req_build (struct msgb *msg, uint8_t pdu_ver, const struct osmo_trxd_burst_req *br)
 Append one encoded burst transmit request (L1 -> TRX) PDU to the given msgb. More...
 
void osmo_trxd_build_fin (struct msgb *msg, uint8_t pdu_ver)
 Finalize a datagram built by osmo_trxd_burst_{ind,req}_build(). More...
 
const char * osmo_trxd_burst_ind_name (const struct osmo_trxd_burst_ind *bi)
 Compose a human-readable representation of the given burst indication (for logging), store into a thread-local static buffer. More...
 
char * osmo_trxd_burst_ind_name_buf (char *buf, size_t buf_len, const struct osmo_trxd_burst_ind *bi)
 Compose a human-readable representation of the given burst indication (for logging), store into the given buffer. More...
 
const char * osmo_trxd_burst_req_name (const struct osmo_trxd_burst_req *br)
 Compose a human-readable representation of the given burst transmit request (for logging), store into a thread-local static buffer. More...
 
char * osmo_trxd_burst_req_name_buf (char *buf, size_t buf_len, const struct osmo_trxd_burst_req *br)
 Compose a human-readable representation of the given burst transmit request (for logging), store into the given buffer. More...
 

Variables

const struct value_string osmo_trxd_mod_type_names []
 

Detailed Description

TRXD (burst data) protocol: I/O-free PDU codec.

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

Macro Definition Documentation

◆ TRXD_IND_V0HDR_LEN

#define TRXD_IND_V0HDR_LEN   (1 + 4 + 1 + 2)

◆ TRXD_IND_V1HDR_LEN

#define TRXD_IND_V1HDR_LEN   (TRXD_IND_V0HDR_LEN + 1 + 2)

◆ TRXD_IND_V2HDR_LEN

#define TRXD_IND_V2HDR_LEN   (1 + 1 + 1 + 1 + 2 + 2)

◆ TRXD_REQ_V01HDR_LEN

#define TRXD_REQ_V01HDR_LEN   (1 + 4 + 1)

◆ TRXD_REQ_V2HDR_LEN

#define TRXD_REQ_V2HDR_LEN   (1 + 1 + 1 + 1 + 1 + 3)

Function Documentation

◆ burst_len_by_mod()

◆ mts_build()

static int mts_build ( uint8_t *  mts,
uint32_t  flags,
enum osmo_trxd_mod_type  mod,
uint8_t  tsc_set,
uint8_t  tsc 
)
static

◆ mts_parse()

static int mts_parse ( uint32_t *  flags,
enum osmo_trxd_mod_type *  mod,
uint8_t *  tsc_set,
uint8_t *  tsc,
uint8_t  mts 
)
static

◆ osmo_trxd_build_fin()

void osmo_trxd_build_fin ( struct msgb *  msg,
uint8_t  pdu_ver 
)

Finalize a datagram built by osmo_trxd_burst_{ind,req}_build().

Parameters
[in,out]msgmessage buffer holding the encoded PDU(s)
[in]pdu_verTRXD PDU version in use

Referenced by trx_ep_data_tx_flush().

◆ osmo_trxd_burst_ind_build()

int osmo_trxd_burst_ind_build ( struct msgb *  msg,
uint8_t  pdu_ver,
const struct osmo_trxd_burst_ind *  bi 
)

Append one encoded burst indication (TRX -> L1) PDU to the given msgb.

For TRXDv2, PDU batching works by calling this function repeatedly on the same msgb; call osmo_trxd_build_fin() once the datagram is complete (it clears the BATCH.ind bit of the last PDU).

Parameters
[in,out]msgdestination message buffer
[in]pdu_verTRXD PDU version to encode
[in]biburst indication to be encoded
Returns
0 on success; negative on error. Note that TRXDv0 has no MTS field, so a NOPE.ind is encoded as a header-only PDU with the burst payload omitted.

References osmo_trxd_burst_ind::burst, osmo_trxd_burst_ind::burst_len, osmo_trxd_burst_ind::ci_cb, osmo_trxd_burst_ind::flags, osmo_trxd_burst_ind::fn, OSMO_TRXD_F_NOPE_IND, OSMO_TRXD_F_SHADOW_IND, osmo_trxd_burst_ind::rssi, soft_bits_build(), osmo_trxd_burst_ind::tn, osmo_trxd_burst_ind::toa256, osmo_trxd_burst_ind::trx_num, TRXD_IND_V0HDR_LEN, TRXD_IND_V1HDR_LEN, TRXD_IND_V2HDR_LEN, and trxd_mts_build_ind().

Referenced by osmo_trx_ep_send_burst_ind().

◆ osmo_trxd_burst_ind_name()

const char * osmo_trxd_burst_ind_name ( const struct osmo_trxd_burst_ind *  bi)

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

Parameters
[in]biBURST.ind to get a human-readable representation of
Returns
pointer to a thread-local static buffer

References osmo_trxd_burst_ind_name_buf().

◆ osmo_trxd_burst_ind_name_buf()

char * osmo_trxd_burst_ind_name_buf ( char *  buf,
size_t  buf_len,
const struct osmo_trxd_burst_ind *  bi 
)

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

Parameters
[out]bufoutput buffer to store the result
[in]buf_lensize of the output buffer
[in]biBURST.ind to get a human-readable representation of
Returns
pointer to the given buffer

References osmo_trxd_burst_ind::burst_len, osmo_trxd_burst_ind::ci_cb, osmo_trxd_burst_ind::flags, osmo_trxd_burst_ind::fn, osmo_trxd_burst_ind::mod, OSMO_TRXD_F_CI_CB, OSMO_TRXD_F_MOD_TYPE, OSMO_TRXD_F_NOPE_IND, OSMO_TRXD_F_TRX_NUM, OSMO_TRXD_F_TS_INFO, osmo_trxd_mod_type_name(), osmo_trxd_burst_ind::rssi, osmo_trxd_burst_ind::tn, osmo_trxd_burst_ind::toa256, osmo_trxd_burst_ind::trx_num, osmo_trxd_burst_ind::tsc, and osmo_trxd_burst_ind::tsc_set.

Referenced by osmo_trxd_burst_ind_name().

◆ osmo_trxd_burst_ind_parse()

int osmo_trxd_burst_ind_parse ( struct osmo_trxd_parse_state *  st,
struct osmo_trxd_burst_ind *  bi,
const uint8_t *  buf,
size_t  buf_len 
)

Parse one burst indication (TRX -> L1) PDU from the given buffer.

The PDU version is parsed from the first PDU of a datagram and kept in st. Starting from TRXDv2, a datagram may batch multiple PDUs: call this function repeatedly on the remaining buffer as long as the parsed PDU has OSMO_TRXD_F_BATCH_IND set in bi->flags.

Parameters
[in,out]stparser state (see osmo_trxd_parse_state_init())
[out]biparsed burst indication
[in]bufbuffer positioned at the beginning of a PDU
[in]buf_lenremaining length of the buffer
Returns
number of consumed bytes on success; negative on error

References osmo_trxd_burst_ind::burst, osmo_trxd_burst_ind::burst_len, burst_len_by_mod(), osmo_trxd_burst_ind::flags, osmo_trxd_burst_ind::fn, osmo_trxd_burst_ind::mod, osmo_trxd_parse_state::num_pdus, OSMO_TRXD_F_NOPE_IND, OSMO_TRXD_PDU_VER_MAX, osmo_trxd_parse_state::pdu_ver, soft_bits_parse(), trxd_burst_ind_parse_v0(), trxd_burst_ind_parse_v1(), trxd_burst_ind_parse_v2(), TRXD_IND_V0HDR_LEN, TRXD_IND_V1HDR_LEN, and TRXD_IND_V2HDR_LEN.

Referenced by trx_ep_data_read_cb().

◆ osmo_trxd_burst_req_build()

int osmo_trxd_burst_req_build ( struct msgb *  msg,
uint8_t  pdu_ver,
const struct osmo_trxd_burst_req *  br 
)

Append one encoded burst transmit request (L1 -> TRX) PDU to the given msgb.

For TRXDv2, PDU batching works by calling this function repeatedly on the same msgb; call osmo_trxd_build_fin() once the datagram is complete (it clears the BATCH.ind bit of the last PDU).

Parameters
[in,out]msgdestination message buffer
[in]pdu_verTRXD PDU version to encode
[in]brburst transmit request to be encoded
Returns
0 on success; negative on error

References osmo_trxd_burst_req::att, osmo_trxd_burst_req::burst, osmo_trxd_burst_req::burst_len, osmo_trxd_burst_req::flags, osmo_trxd_burst_req::fn, OSMO_TRXD_F_NOPE_REQ, osmo_trxd_burst_req::scpir, osmo_trxd_burst_req::tn, osmo_trxd_burst_req::trx_num, trxd_mts_build_req(), TRXD_REQ_V01HDR_LEN, and TRXD_REQ_V2HDR_LEN.

Referenced by osmo_trx_ep_send_burst_req().

◆ osmo_trxd_burst_req_name()

const char * osmo_trxd_burst_req_name ( const struct osmo_trxd_burst_req *  br)

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

Parameters
[in]brBURST.req to get a human-readable representation of
Returns
pointer to a thread-local static buffer

References osmo_trxd_burst_req_name_buf().

◆ osmo_trxd_burst_req_name_buf()

char * osmo_trxd_burst_req_name_buf ( char *  buf,
size_t  buf_len,
const struct osmo_trxd_burst_req *  br 
)

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

Parameters
[out]bufoutput buffer to store the result
[in]buf_lensize of the output buffer
[in]brBURST.req to get a human-readable representation of
Returns
pointer to the given buffer

References osmo_trxd_burst_req::att, osmo_trxd_burst_req::burst_len, osmo_trxd_burst_req::flags, osmo_trxd_burst_req::fn, osmo_trxd_burst_req::mod, OSMO_TRXD_F_MOD_TYPE, OSMO_TRXD_F_NOPE_REQ, OSMO_TRXD_F_TRX_NUM, OSMO_TRXD_F_TS_INFO, osmo_trxd_mod_type_name(), osmo_trxd_burst_req::tn, osmo_trxd_burst_req::trx_num, osmo_trxd_burst_req::tsc, and osmo_trxd_burst_req::tsc_set.

Referenced by osmo_trxd_burst_req_name().

◆ osmo_trxd_burst_req_parse()

int osmo_trxd_burst_req_parse ( struct osmo_trxd_parse_state *  st,
struct osmo_trxd_burst_req *  br,
const uint8_t *  buf,
size_t  buf_len 
)

Parse one burst transmit request (L1 -> TRX) PDU from the given buffer.

The PDU version is parsed from the first PDU of a datagram and kept in st. Starting from TRXDv2, a datagram may batch multiple PDUs: call this function repeatedly on the remaining buffer as long as the parsed PDU has OSMO_TRXD_F_BATCH_IND set in br->flags.

Parameters
[in,out]stparser state (see osmo_trxd_parse_state_init())
[out]brparsed burst transmit request
[in]bufbuffer positioned at the beginning of a PDU
[in]buf_lenremaining length of the buffer
Returns
number of consumed bytes on success; negative on error

References osmo_trxd_burst_req::fn, osmo_trxd_parse_state::num_pdus, OSMO_TRXD_PDU_VER_MAX, osmo_trxd_parse_state::pdu_ver, trxd_burst_req_parse_v01(), trxd_burst_req_parse_v2(), TRXD_REQ_V01HDR_LEN, and TRXD_REQ_V2HDR_LEN.

Referenced by trx_ep_data_read_cb().

◆ osmo_trxd_parse_state_init()

void osmo_trxd_parse_state_init ( struct osmo_trxd_parse_state *  st)

Initialize a parser state; call before parsing each datagram.

Parameters
[out]stparser state to be initialized

Referenced by trx_ep_data_read_cb().

◆ soft_bits_build()

static void soft_bits_build ( uint8_t *  out,
const sbit_t *  in,
size_t  len 
)
static

◆ soft_bits_parse()

static void soft_bits_parse ( sbit_t *  out,
const uint8_t *  in,
size_t  len 
)
static

◆ trxd_burst_ind_parse_hdr_v0()

static void trxd_burst_ind_parse_hdr_v0 ( struct osmo_trxd_burst_ind *  bi,
const uint8_t *  buf 
)
static

◆ trxd_burst_ind_parse_v0()

◆ trxd_burst_ind_parse_v1()

static int trxd_burst_ind_parse_v1 ( struct osmo_trxd_burst_ind *  bi,
const uint8_t *  buf,
size_t  buf_len 
)
static

◆ trxd_burst_ind_parse_v2()

◆ trxd_burst_req_parse_v01()

◆ trxd_burst_req_parse_v2()

◆ trxd_mts_build_ind()

int trxd_mts_build_ind ( uint8_t *  mts,
const struct osmo_trxd_burst_ind *  bi 
)

◆ trxd_mts_build_req()

int trxd_mts_build_req ( uint8_t *  mts,
const struct osmo_trxd_burst_req *  br 
)

◆ trxd_mts_parse_ind()

◆ trxd_mts_parse_req()

Variable Documentation

◆ osmo_trxd_mod_type_names

const struct value_string osmo_trxd_mod_type_names[]
Initial value:
= {
{ OSMO_TRXD_MOD_T_GMSK, "GMSK" },
{ OSMO_TRXD_MOD_T_8PSK, "8-PSK" },
{ OSMO_TRXD_MOD_T_AQPSK, "AQPSK" },
{ 0, NULL }
}
@ OSMO_TRXD_MOD_T_AQPSK
Definition: trxd.h:36
@ OSMO_TRXD_MOD_T_GMSK
Definition: trxd.h:34
@ OSMO_TRXD_MOD_T_8PSK
Definition: trxd.h:35

Referenced by osmo_trxd_mod_type_name().