libosmo-trx 1.8.0.50-7f5e
Osmocom TRX protocol (TRXC/TRXD) library
trxc_client.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <stdint.h>
6#include <stddef.h>
7
8#include <osmocom/trx/trxc.h>
9
18struct osmo_trxc_client;
19
28typedef int osmo_trxc_client_rsp_cb(struct osmo_trxc_client *client,
29 const struct osmo_trxc_msg *rsp,
30 void *cb_data);
31
41 const struct osmo_trxc_msg *msg);
42
50 const struct osmo_trxc_msg *rsp);
51
53void osmo_trxc_client_free(struct osmo_trxc_client *client);
54void osmo_trxc_client_set_priv(struct osmo_trxc_client *client, void *priv);
55void *osmo_trxc_client_get_priv(const struct osmo_trxc_client *client);
56int osmo_trxc_client_set_name(struct osmo_trxc_client *client, const char *fmt, ...);
58int osmo_trxc_client_set_retrans(struct osmo_trxc_client *client, unsigned int sec);
59void osmo_trxc_client_set_max_retrans(struct osmo_trxc_client *client, unsigned int n);
66
68#define OSMO_TRXC_F_CRITICAL (1 << 0)
70#define OSMO_TRXC_F_MATCH_PARAMS (1 << 1)
71
72int osmo_trxc_client_send_cmd(struct osmo_trxc_client *client, uint32_t flags,
73 osmo_trxc_client_rsp_cb *cb, void *cb_data,
74 const char *cmd, const char *fmt, ...);
75void osmo_trxc_client_flush(struct osmo_trxc_client *client);
76
78 const struct osmo_trxc_msg *rsp);
79int osmo_trxc_client_rx(struct osmo_trxc_client *client, const char *buf, size_t len);
80
85typedef void osmo_trxc_setformat_cb(struct osmo_trxc_client *client,
86 uint8_t ver_use, void *cb_data);
88 uint8_t ver_max,
89 osmo_trxc_setformat_cb *cb, void *cb_data);
90
91/* Convenience wrappers for the common command set (thin, optional) */
92static inline int osmo_trxc_client_poweron(struct osmo_trxc_client *client,
93 osmo_trxc_client_rsp_cb *cb, void *cb_data)
94{
95 return osmo_trxc_client_send_cmd(client, OSMO_TRXC_F_CRITICAL, cb, cb_data,
97}
98static inline int osmo_trxc_client_poweroff(struct osmo_trxc_client *client,
99 osmo_trxc_client_rsp_cb *cb, void *cb_data)
100{
101 return osmo_trxc_client_send_cmd(client, OSMO_TRXC_F_CRITICAL, cb, cb_data,
103}
104static inline int osmo_trxc_client_rxtune(struct osmo_trxc_client *client,
105 unsigned int freq_khz,
106 osmo_trxc_client_rsp_cb *cb, void *cb_data)
107{
108 return osmo_trxc_client_send_cmd(client, OSMO_TRXC_F_CRITICAL, cb, cb_data,
109 OSMO_TRXC_CMD_RXTUNE, "%u", freq_khz);
110}
111static inline int osmo_trxc_client_txtune(struct osmo_trxc_client *client,
112 unsigned int freq_khz,
113 osmo_trxc_client_rsp_cb *cb, void *cb_data)
114{
115 return osmo_trxc_client_send_cmd(client, OSMO_TRXC_F_CRITICAL, cb, cb_data,
116 OSMO_TRXC_CMD_TXTUNE, "%u", freq_khz);
117}
Definition: trxc_client.c:60
int log_cat
Definition: trxc_client.c:65
void * priv
Definition: trxc_client.c:63
A single de-/serialized TRXC message.
Definition: trxc.h:32
TRXC (control) protocol and clock indications: I/O-free message codec.
#define OSMO_TRXC_CMD_POWERON
Definition: trxc.h:48
#define OSMO_TRXC_CMD_TXTUNE
Definition: trxc.h:51
#define OSMO_TRXC_CMD_POWEROFF
Definition: trxc.h:49
#define OSMO_TRXC_CMD_RXTUNE
Definition: trxc.h:50
int osmo_trxc_client_set_name(struct osmo_trxc_client *client, const char *fmt,...)
Set the name (log prefix) of the given instance, e.g.
Definition: trxc_client.c:189
void osmo_trxc_client_set_fatal_error_cb(struct osmo_trxc_client *client, osmo_trxc_client_fatal_error_cb *cb)
set the fatal_error call-back (optional; default: log)
Definition: trxc_client.c:182
#define OSMO_TRXC_F_CRITICAL
escalate to the fatal_error call-back on NACK
Definition: trxc_client.h:68
void osmo_trxc_setformat_cb(struct osmo_trxc_client *client, uint8_t ver_use, void *cb_data)
TRXD PDU version negotiation result call-back.
Definition: trxc_client.h:85
int osmo_trxc_client_rsp_cb(struct osmo_trxc_client *client, const struct osmo_trxc_msg *rsp, void *cb_data)
Response call-back, invoked when a response to a command is received.
Definition: trxc_client.h:28
void osmo_trxc_client_set_log_cat(struct osmo_trxc_client *client, int log_cat)
Set the logging category (e.g.
Definition: trxc_client.c:207
int osmo_trxc_client_rx_msg(struct osmo_trxc_client *client, const struct osmo_trxc_msg *rsp)
Feed a received (parsed) response message into the engine.
Definition: trxc_client.c:380
int osmo_trxc_client_send_cmd(struct osmo_trxc_client *client, uint32_t flags, osmo_trxc_client_rsp_cb *cb, void *cb_data, const char *cmd, const char *fmt,...)
Enqueue a new command for transmission.
Definition: trxc_client.c:250
static int osmo_trxc_client_rxtune(struct osmo_trxc_client *client, unsigned int freq_khz, osmo_trxc_client_rsp_cb *cb, void *cb_data)
Definition: trxc_client.h:104
static int osmo_trxc_client_poweron(struct osmo_trxc_client *client, osmo_trxc_client_rsp_cb *cb, void *cb_data)
Definition: trxc_client.h:92
static int osmo_trxc_client_poweroff(struct osmo_trxc_client *client, osmo_trxc_client_rsp_cb *cb, void *cb_data)
Definition: trxc_client.h:98
void osmo_trxc_client_set_tx_msg_cb(struct osmo_trxc_client *client, osmo_trxc_client_tx_msg_cb *cb)
set the tx_msg call-back (mandatory before the first command is sent)
Definition: trxc_client.c:175
void osmo_trxc_client_fatal_error_cb(struct osmo_trxc_client *client, const struct osmo_trxc_msg *rsp)
Fatal error call-back, invoked when a critical command definitively fails (optional; default: log),...
Definition: trxc_client.h:49
int osmo_trxc_client_rx(struct osmo_trxc_client *client, const char *buf, size_t len)
Feed a datagram received on the ctrl socket into the engine.
Definition: trxc_client.c:479
void osmo_trxc_client_set_priv(struct osmo_trxc_client *client, void *priv)
Set the application-private data.
Definition: trxc_client.c:163
static int osmo_trxc_client_txtune(struct osmo_trxc_client *client, unsigned int freq_khz, osmo_trxc_client_rsp_cb *cb, void *cb_data)
Definition: trxc_client.h:111
void osmo_trxc_client_set_max_retrans(struct osmo_trxc_client *client, unsigned int n)
Set the maximum number of retransmissions of a command (default: 0).
Definition: trxc_client.c:229
void * osmo_trxc_client_get_priv(const struct osmo_trxc_client *client)
Obtain the application-private data.
Definition: trxc_client.c:169
void osmo_trxc_client_flush(struct osmo_trxc_client *client)
Flush (drop) all pending commands.
Definition: trxc_client.c:307
int osmo_trxc_client_negotiate_format(struct osmo_trxc_client *client, uint8_t ver_max, osmo_trxc_setformat_cb *cb, void *cb_data)
Negotiate the TRXD PDU version with the transceiver (SETFORMAT).
Definition: trxc_client.c:550
int osmo_trxc_client_set_retrans(struct osmo_trxc_client *client, unsigned int sec)
Set the retransmit timeout in seconds (default: 2).
Definition: trxc_client.c:216
struct osmo_trxc_client * osmo_trxc_client_alloc(void *ctx)
Allocate a TRXC client instance.
Definition: trxc_client.c:133
void osmo_trxc_client_free(struct osmo_trxc_client *client)
Free the given TRXC client instance (flushes the command queue).
Definition: trxc_client.c:153
int osmo_trxc_client_tx_msg_cb(struct osmo_trxc_client *client, const struct osmo_trxc_msg *msg)
Transmit call-back, invoked to emit a parsed TRXC message (mandatory, see osmo_trxc_client_set_tx_msg...
Definition: trxc_client.h:40