libosmo-e1d  0.5.0
Osmocom e1d client library
proto_clnt.c File Reference

e1d protocol client library (libosmo-e1d). More...

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <talloc.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/select.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/utils.h>
#include <osmocom/e1d/proto.h>
#include <osmocom/e1d/proto_clnt.h>
#include "log.h"

Data Structures

struct  osmo_e1dp_client
 Internal representation of client program connected to the CTL socket. More...
 

Functions

struct osmo_e1dp_clientosmo_e1dp_client_create (void *ctx, const char *path)
 Create a new client talking to the CTL server socket of osmo-e1d. More...
 
void osmo_e1dp_client_destroy (struct osmo_e1dp_client *clnt)
 Destroy a previously created client. More...
 
int osmo_e1dp_client_intf_query (struct osmo_e1dp_client *clnt, struct osmo_e1dp_intf_info **ii, int *n, uint8_t intf)
 Query osmo-e1d for information about a specific E1 interface. More...
 
int osmo_e1dp_client_line_query (struct osmo_e1dp_client *clnt, struct osmo_e1dp_line_info **li, int *n, uint8_t intf, uint8_t line)
 Query osmo-e1d for information about a specific E1 line. More...
 
int osmo_e1dp_client_ts_query (struct osmo_e1dp_client *clnt, struct osmo_e1dp_ts_info **ti, int *n, uint8_t intf, uint8_t line, uint8_t ts)
 Query osmo-e1d for information about a specific E1 timeslot. More...
 
int osmo_e1dp_client_line_config (struct osmo_e1dp_client *clnt, uint8_t intf, uint8_t line, enum osmo_e1dp_line_mode mode)
 Configure a specific E1 line in osmo-e1d. More...
 
int osmo_e1dp_client_ts_open (struct osmo_e1dp_client *clnt, uint8_t intf, uint8_t line, uint8_t ts, enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize)
 Open a specific E1 timeslot of osmo-e1d. More...
 
int osmo_e1dp_client_ts_open_force (struct osmo_e1dp_client *clnt, uint8_t intf, uint8_t line, uint8_t ts, enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize)
 Force-Open a specific E1 timeslot of osmo-e1d. More...
 

Detailed Description

e1d protocol client library (libosmo-e1d).

This library implements ways how an external client (application program) can talk to osmo-e1d. The primary purpose is to open specific E1 timeslots in order to receive and/or transmit data on them.

Each such open timeslot is represented to the client program as a file descriptor, which the client can read and/or write as usual. This is implemented using underlying UNIX domain sockets and file descriptor passing.

In addition to opening timeslots, client applications can also query osmo-e1d for information about its E1 interfaces, E1 lines and E1 timeslots.

The functions provided by this client library are implemented as synchronous/blocking calls to osmo-e1d. This means that an API call will be blocking until there is a response received from osmo-e1d.

Function Documentation

◆ osmo_e1dp_client_create()

struct osmo_e1dp_client* osmo_e1dp_client_create ( void *  ctx,
const char *  path 
)

Create a new client talking to the CTL server socket of osmo-e1d.

Parameters
[in]ctxtalloc context from which this client is allocated
[in]pathpath of the CTL unix domain socket of osmo-e1d
Returns
handle to newly-created client; NULL in case of errors

References osmo_e1dp_client::ctl_fd, and osmo_e1dp_client::ctx.

◆ osmo_e1dp_client_destroy()

void osmo_e1dp_client_destroy ( struct osmo_e1dp_client clnt)

Destroy a previously created client.

Closes socket and releases memory.

Parameters
[in]clntClient previously returned from osmo_e1dp_client_create().

References osmo_e1dp_client::ctl_fd.

◆ osmo_e1dp_client_intf_query()

int osmo_e1dp_client_intf_query ( struct osmo_e1dp_client clnt,
struct osmo_e1dp_intf_info **  ii,
int *  n,
uint8_t  intf 
)

Query osmo-e1d for information about a specific E1 interface.

Parameters
[in]clntClient previously returned from osmo_e1dp_client_create().
[out]iicallee-allocated array of interface information structures.
[out]ncaller-provided pointer to integer. Will contain number of entries in ii.
[in]intfE1 interface number to query, or E1DP_INVALID to query all interfaces.
Returns
zero in case of success; negative in case of error.

References E1DP_CMD_INTF_QUERY, E1DP_INVALID, intf, osmo_e1dp_msg_hdr::intf, osmo_e1dp_msg_hdr::line, osmo_e1dp_msg_hdr::ts, and osmo_e1dp_msg_hdr::type.

◆ osmo_e1dp_client_line_config()

int osmo_e1dp_client_line_config ( struct osmo_e1dp_client clnt,
uint8_t  intf,
uint8_t  line,
enum osmo_e1dp_line_mode  mode 
)

Configure a specific E1 line in osmo-e1d.

Parameters
[in]clntClient previously returned from osmo_e1dp_client_create().
[in]intfE1 interface number to configure.
[in]lineE1 line number (within interface) to configure.
[in]modeE1 line mode to set on line.
Returns
zero in case of success; negative in case of error.

References cfg, E1DP_CMD_LINE_CONFIG, E1DP_INVALID, intf, osmo_e1dp_msg_hdr::intf, line, osmo_e1dp_msg_hdr::line, mode, osmo_e1dp_line_config::mode, osmo_e1dp_msg_hdr::ts, and osmo_e1dp_msg_hdr::type.

◆ osmo_e1dp_client_line_query()

int osmo_e1dp_client_line_query ( struct osmo_e1dp_client clnt,
struct osmo_e1dp_line_info **  li,
int *  n,
uint8_t  intf,
uint8_t  line 
)

Query osmo-e1d for information about a specific E1 line.

Parameters
[in]clntClient previously returned from osmo_e1dp_client_create().
[out]licallee-allocated array of line information structures.
[out]ncaller-provided pointer to integer. Will contain number of entries in li.
[in]intfE1 interface number to query.
[in]lineE1 line number (within interface) to query, or E1DP_INVALID to query all lines within the interface.
Returns
zero in case of success; negative in case of error.

References E1DP_CMD_LINE_QUERY, E1DP_INVALID, intf, osmo_e1dp_msg_hdr::intf, line, osmo_e1dp_msg_hdr::line, osmo_e1dp_msg_hdr::ts, and osmo_e1dp_msg_hdr::type.

◆ osmo_e1dp_client_ts_open()

int osmo_e1dp_client_ts_open ( struct osmo_e1dp_client clnt,
uint8_t  intf,
uint8_t  line,
uint8_t  ts,
enum osmo_e1dp_ts_mode  mode,
uint16_t  read_bufsize 
)

Open a specific E1 timeslot of osmo-e1d.

Parameters
[in]clntClient previously returned from osmo_e1dp_client_create().
[in]intfE1 interface number of line containing timeslot.
[in]lineE1 line number (within interface) of line containing timeslot.
[in]tsE1 timeslot number (within line) to open.
[in]modetimeslot mode (RAW, HDLC-FCE) in which to open timeslot.
[in]read_bufsizesize of read buffer (in octets) to use.
Returns
file descriptor of opened timeslot in case of success; negative in case of error.

◆ osmo_e1dp_client_ts_open_force()

int osmo_e1dp_client_ts_open_force ( struct osmo_e1dp_client clnt,
uint8_t  intf,
uint8_t  line,
uint8_t  ts,
enum osmo_e1dp_ts_mode  mode,
uint16_t  read_bufsize 
)

Force-Open a specific E1 timeslot of osmo-e1d.

The normal (non-force) opening of a timeslot will fail in case the given timeslot is already open (by either this or some other client). Using the open_force variant you can force osmo-e1d to disregard the existing client/timeslot and transfer ownership of the timeslot to this client.

Parameters
[in]clntClient previously returned from osmo_e1dp_client_create().
[in]intfE1 interface number of line containing timeslot.
[in]lineE1 line number (within interface) of line containing timeslot.
[in]tsE1 timeslot number (within line) to open.
[in]modetimeslot mode (RAW, HDLC-FCE) in which to open timeslot.
[in]read_bufsizesize of read buffer (in octets) to use.
Returns
file descriptor of opened timeslot in case of success; negative in case of error.

◆ osmo_e1dp_client_ts_query()

int osmo_e1dp_client_ts_query ( struct osmo_e1dp_client clnt,
struct osmo_e1dp_ts_info **  ti,
int *  n,
uint8_t  intf,
uint8_t  line,
uint8_t  ts 
)

Query osmo-e1d for information about a specific E1 timeslot.

Parameters
[in]clntClient previously returned from osmo_e1dp_client_create().
[out]ticallee-allocated array of timeslot information structures.
[out]ncaller-provided pointer to integer. Will contain number of entries in ti.
[in]intfE1 interface number to query.
[in]lineE1 line number (within interface) to query.
[in]tsE1 timeslot numer (within line) to query, or E1DP_INVALID to query all of the timeslots within the line.
Returns
zero in case of success; negative in case of error.

References E1DP_CMD_TS_QUERY, intf, osmo_e1dp_msg_hdr::intf, line, osmo_e1dp_msg_hdr::line, ts, osmo_e1dp_msg_hdr::ts, and osmo_e1dp_msg_hdr::type.