e1_input: minor API changes to adapt it to openbsc
While working on the openbsc over libosmo-abis port, I noticed several API changes that we need to perform for better adaptation.
This commit is contained in:
parent
130c4fbe2e
commit
f163d23bf6
|
@ -120,9 +120,12 @@ struct e1inp_driver {
|
|||
};
|
||||
|
||||
struct e1inp_line_ops {
|
||||
int (*sign_link_up)(struct msgb *msg, struct e1inp_line *line);
|
||||
int (*sign_link)(struct msgb *msg, struct e1inp_sign_link *link);
|
||||
int (*error)(struct msgb *msg, int error);
|
||||
enum e1inp_line_role role;
|
||||
char *addr;
|
||||
|
||||
int (*sign_link_up)(struct msgb *msg, struct e1inp_line *line, enum e1inp_sign_type type);
|
||||
int (*sign_link)(struct msgb *msg, struct e1inp_line *line, struct e1inp_sign_link *link);
|
||||
int (*error)(struct msgb *msg, struct e1inp_line *line, enum e1inp_sign_type type, int error);
|
||||
};
|
||||
|
||||
struct e1inp_line {
|
||||
|
@ -135,7 +138,7 @@ struct e1inp_line {
|
|||
/* array of timestlots */
|
||||
struct e1inp_ts ts[NUM_E1_TS];
|
||||
|
||||
struct e1inp_line_ops ops;
|
||||
const struct e1inp_line_ops *ops;
|
||||
|
||||
struct e1inp_driver *driver;
|
||||
void *driver_data;
|
||||
|
@ -164,7 +167,10 @@ int e1inp_line_register(struct e1inp_line *line);
|
|||
struct e1inp_line *e1inp_line_get(uint8_t e1_nr);
|
||||
|
||||
/* create a line in the E1 input core */
|
||||
struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name, const struct e1inp_line_ops *ops);
|
||||
struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
|
||||
|
||||
/* bind operations to one E1 input line */
|
||||
void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
|
||||
|
||||
/* find a sign_link for given TEI and SAPI in a TS */
|
||||
struct e1inp_sign_link *
|
||||
|
@ -206,7 +212,7 @@ void e1_set_pcap_fd(int fd);
|
|||
struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
|
||||
|
||||
void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
|
||||
int e1inp_line_update(struct e1inp_line *line, enum e1inp_line_role role, const char *addr);
|
||||
int e1inp_line_update(struct e1inp_line *line);
|
||||
|
||||
struct gsm_network;
|
||||
int ipaccess_setup(struct gsm_network *gsmnet);
|
||||
|
|
|
@ -306,8 +306,7 @@ struct e1inp_line *e1inp_line_get(uint8_t e1_nr)
|
|||
}
|
||||
|
||||
struct e1inp_line *
|
||||
e1inp_line_create(uint8_t e1_nr, const char *driver_name,
|
||||
const struct e1inp_line_ops *ops)
|
||||
e1inp_line_create(uint8_t e1_nr, const char *driver_name)
|
||||
{
|
||||
struct e1inp_driver *driver;
|
||||
struct e1inp_line *line;
|
||||
|
@ -332,7 +331,6 @@ e1inp_line_create(uint8_t e1_nr, const char *driver_name,
|
|||
return NULL;
|
||||
|
||||
line->driver = driver;
|
||||
memcpy(&line->ops, ops, sizeof(struct e1inp_line_ops));
|
||||
|
||||
line->num = e1_nr;
|
||||
for (i = 0; i < NUM_E1_TS; i++) {
|
||||
|
@ -344,6 +342,12 @@ e1inp_line_create(uint8_t e1_nr, const char *driver_name,
|
|||
return line;
|
||||
}
|
||||
|
||||
void
|
||||
e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops)
|
||||
{
|
||||
line->ops = ops;
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct e1inp_line *e1inp_line_get_create(uint8_t e1_nr)
|
||||
{
|
||||
|
@ -467,12 +471,12 @@ int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
|
|||
"tei %d, sapi %d\n", tei, sapi);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!ts->line->ops.sign_link) {
|
||||
if (!ts->line->ops->sign_link) {
|
||||
LOGP(DINP, LOGL_ERROR, "Fix your application, "
|
||||
"no action set for signalling messages.\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
ts->line->ops.sign_link(msg, link);
|
||||
ts->line->ops->sign_link(msg, ts->line, link);
|
||||
break;
|
||||
case E1INP_TS_TYPE_TRAU:
|
||||
ret = subch_demux_in(&ts->trau.demux, msg->l2h, msgb_l2len(msg));
|
||||
|
@ -560,8 +564,7 @@ struct e1inp_driver *e1inp_driver_find(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int e1inp_line_update(struct e1inp_line *line,
|
||||
enum e1inp_line_role role, const char *addr)
|
||||
int e1inp_line_update(struct e1inp_line *line)
|
||||
{
|
||||
struct input_signal_data isd;
|
||||
int rc;
|
||||
|
@ -570,9 +573,10 @@ int e1inp_line_update(struct e1inp_line *line,
|
|||
if (++line->refcnt > 1)
|
||||
return 0;
|
||||
|
||||
if (line->driver && line->driver->line_update)
|
||||
rc = line->driver->line_update(line, role, addr);
|
||||
else
|
||||
if (line->driver && line->ops && line->driver->line_update) {
|
||||
rc = line->driver->line_update(line, line->ops->role,
|
||||
line->ops->addr);
|
||||
} else
|
||||
rc = 0;
|
||||
|
||||
/* Send a signal to anyone who is interested in new lines being
|
||||
|
|
|
@ -122,8 +122,8 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
|
||||
idata = lapd_receive(e1i_ts->driver.dahdi.lapd, msg->data, msg->len, &ilen, &prim);
|
||||
if (!idata && prim == 0) {
|
||||
if (line->ops.error)
|
||||
line->ops.error(NULL, -EBADMSG);
|
||||
if (line->ops->error)
|
||||
line->ops->error(NULL, -EBADMSG);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,8 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
ret = e1inp_rx_ts(e1i_ts, msg, tei, sapi);
|
||||
break;
|
||||
default:
|
||||
if (line->ops.error)
|
||||
line->ops.error(NULL, -EBADMSG);
|
||||
if (line->ops->error)
|
||||
line->ops->error(NULL, -EBADMSG);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,8 +86,8 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
|
||||
error = ipa_msg_recv(bfd->fd, &msg);
|
||||
if (error <= 0) {
|
||||
if (e1i_ts->line->ops.error)
|
||||
e1i_ts->line->ops.error(NULL, error);
|
||||
if (e1i_ts->line->ops->error)
|
||||
e1i_ts->line->ops->error(NULL, line, ts_nr, error);
|
||||
if (error == 0) {
|
||||
osmo_fd_unregister(bfd);
|
||||
close(bfd->fd);
|
||||
|
@ -106,17 +106,18 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
|
||||
/* HSL proprietary RSL extension */
|
||||
if (hh->proto == 0 && (msg->l2h[0] == 0x81 || msg->l2h[0] == 0x80)) {
|
||||
if (!line->ops.sign_link_up) {
|
||||
if (!line->ops->sign_link_up) {
|
||||
LOGP(DINP, LOGL_ERROR, "Fix your application, no "
|
||||
"action set if the signalling link "
|
||||
"becomes ready.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = line->ops.sign_link_up(msg, line);
|
||||
ret = line->ops->sign_link_up(msg, line, E1INP_SIGN_RSL);
|
||||
if (ret < 0) {
|
||||
/* FIXME: close connection */
|
||||
if (line->ops.error)
|
||||
line->ops.error(msg, -EBADMSG);
|
||||
if (line->ops->error)
|
||||
line->ops->error(msg, line,
|
||||
E1INP_SIGN_RSL, -EBADMSG);
|
||||
return ret;
|
||||
} else if (ret == 1)
|
||||
return 0;
|
||||
|
@ -138,12 +139,12 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
msg->dst = link;
|
||||
|
||||
/* XXX: better use e1inp_ts_rx? */
|
||||
if (!e1i_ts->line->ops.sign_link) {
|
||||
if (!e1i_ts->line->ops->sign_link) {
|
||||
LOGP(DINP, LOGL_ERROR, "Fix your application, "
|
||||
"no action set for signalling messages.\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
e1i_ts->line->ops.sign_link(msg, link);
|
||||
e1i_ts->line->ops->sign_link(msg, line, link);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -45,9 +45,6 @@
|
|||
#include <osmocom/abis/logging.h>
|
||||
#include <osmocom/abis/ipa.h>
|
||||
|
||||
#define PRIV_OML 1
|
||||
#define PRIV_RSL 2
|
||||
|
||||
static void *tall_ipa_ctx;
|
||||
|
||||
#define TS1_ALLOC_SIZE 900
|
||||
|
@ -140,13 +137,13 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg,
|
|||
switch (msg_type) {
|
||||
case IPAC_MSGT_ID_RESP:
|
||||
DEBUGP(DMI, "ID_RESP\n");
|
||||
if (!line->ops.sign_link_up) {
|
||||
if (!line->ops->sign_link_up) {
|
||||
LOGP(DINP, LOGL_ERROR, "Fix your application, "
|
||||
"no action set if the signalling link "
|
||||
"becomes ready\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
line->ops.sign_link_up(msg, line);
|
||||
line->ops->sign_link_up(msg, line, bfd->priv_nr);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -165,8 +162,8 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
error = ipa_msg_recv(bfd->fd, &msg);
|
||||
if (error <= 0) {
|
||||
/* skip if RSL line is not set yet. */
|
||||
if (e1i_ts && e1i_ts->line->ops.error)
|
||||
e1i_ts->line->ops.error(NULL, error);
|
||||
if (e1i_ts && e1i_ts->line->ops->error)
|
||||
e1i_ts->line->ops->error(NULL, line, ts_nr, error);
|
||||
if (error == 0) {
|
||||
osmo_fd_unregister(bfd);
|
||||
close(bfd->fd);
|
||||
|
@ -199,12 +196,12 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
msg->dst = link;
|
||||
|
||||
/* XXX better use e1inp_ts_rx? */
|
||||
if (!e1i_ts->line->ops.sign_link) {
|
||||
if (!e1i_ts->line->ops->sign_link) {
|
||||
LOGP(DINP, LOGL_ERROR, "Fix your application, "
|
||||
"no action set for signalling messages.\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
e1i_ts->line->ops.sign_link(msg, link);
|
||||
e1i_ts->line->ops->sign_link(msg, line, link);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -353,7 +350,7 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
|
|||
|
||||
bfd->fd = fd;
|
||||
bfd->data = line;
|
||||
bfd->priv_nr = PRIV_OML;
|
||||
bfd->priv_nr = E1INP_SIGN_OML;
|
||||
bfd->cb = ipaccess_fd_cb;
|
||||
bfd->when = BSC_FD_READ;
|
||||
ret = osmo_fd_register(bfd);
|
||||
|
@ -380,7 +377,7 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd)
|
|||
return -ENOMEM;
|
||||
|
||||
bfd->fd = fd;
|
||||
bfd->priv_nr = PRIV_RSL;
|
||||
bfd->priv_nr = E1INP_SIGN_RSL;
|
||||
bfd->cb = ipaccess_fd_cb;
|
||||
bfd->when = BSC_FD_READ;
|
||||
ret = osmo_fd_register(bfd);
|
||||
|
@ -412,13 +409,15 @@ static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg)
|
|||
/* this is a request for identification from the BSC. */
|
||||
if (msg_type == IPAC_MSGT_ID_GET) {
|
||||
LOGP(DINP, LOGL_NOTICE, "received ID get\n");
|
||||
if (!link->line->ops.sign_link_up) {
|
||||
if (!link->line->ops->sign_link_up) {
|
||||
LOGP(DINP, LOGL_ERROR, "Fix your application, "
|
||||
"no action set if the signalling link "
|
||||
"becomes ready\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
link->line->ops.sign_link_up(msg, link->line);
|
||||
link->line->ops->sign_link_up(msg, link->line,
|
||||
link->port == IPA_TCP_PORT_OML ?
|
||||
E1INP_SIGN_OML : E1INP_SIGN_RSL);
|
||||
}
|
||||
return 0;
|
||||
} else if (link->port == IPA_TCP_PORT_OML)
|
||||
|
@ -437,12 +436,12 @@ static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg)
|
|||
msg->dst = sign_link;
|
||||
|
||||
/* XXX better use e1inp_ts_rx? */
|
||||
if (!link->line->ops.sign_link) {
|
||||
if (!link->line->ops->sign_link) {
|
||||
LOGP(DINP, LOGL_ERROR, "Fix your application, "
|
||||
"no action set for signalling messages.\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
link->line->ops.sign_link(msg, sign_link);
|
||||
link->line->ops->sign_link(msg, link->line, sign_link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,8 +109,8 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
}
|
||||
|
||||
if (alen != sizeof(l2addr)) {
|
||||
if (line->ops.error)
|
||||
line->ops.error(NULL, -EBADMSG);
|
||||
if (line->ops->error)
|
||||
line->ops->error(NULL, line, ts_nr, -EBADMSG);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -173,8 +173,8 @@ static int handle_ts1_read(struct osmo_fd *bfd)
|
|||
l2addr.channel, l2addr.sapi, l2addr.tei);
|
||||
break;
|
||||
default:
|
||||
if (line->ops.error)
|
||||
line->ops.error(NULL, -EBADMSG);
|
||||
if (line->ops->error)
|
||||
line->ops->error(NULL, line, ts_nr, -EBADMSG);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -7,19 +7,22 @@
|
|||
|
||||
static void *tall_test;
|
||||
|
||||
static int sign_link_up(struct msgb *msg, struct e1inp_line *line)
|
||||
static int sign_link_up(struct msgb *msg, struct e1inp_line *line,
|
||||
enum e1inp_sign_type type)
|
||||
{
|
||||
printf("ID_RESP received, create sign link.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sign_link(struct msgb *msg, struct e1inp_sign_link *link)
|
||||
static int sign_link(struct msgb *msg, struct e1inp_line *line,
|
||||
struct e1inp_sign_link *link)
|
||||
{
|
||||
printf("OML/RSL data received\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int error(struct msgb *msg, int error)
|
||||
static int error(struct msgb *msg, struct e1inp_line *line,
|
||||
enum e1inp_sign_type type, int error)
|
||||
{
|
||||
printf("error, malformed message\n");
|
||||
return 0;
|
||||
|
@ -52,6 +55,8 @@ int main(void)
|
|||
osmo_init_logging(&bsc_test_log_info);
|
||||
|
||||
struct e1inp_line_ops ops = {
|
||||
.addr = "0.0.0.0",
|
||||
.role = E1INP_LINE_R_BSC,
|
||||
.sign_link_up = sign_link_up,
|
||||
.sign_link = sign_link,
|
||||
.error = error,
|
||||
|
@ -59,12 +64,14 @@ int main(void)
|
|||
|
||||
#define LINENR 0
|
||||
|
||||
line = e1inp_line_create(LINENR, "ipa", &ops);
|
||||
line = e1inp_line_create(LINENR, "ipa");
|
||||
if (line == NULL) {
|
||||
LOGP(DBSCTEST, LOGL_ERROR, "problem creating E1 line\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
e1inp_line_bind_ops(line, &ops);
|
||||
|
||||
/*
|
||||
* Depending if this is a real or virtual E1 lines:
|
||||
* - real (ISDN): create signal link for OML and RSL before line up.
|
||||
|
@ -76,7 +83,7 @@ int main(void)
|
|||
* it explains how this is done with ISDN.
|
||||
*/
|
||||
|
||||
if (e1inp_line_update(line, E1INP_LINE_R_BSC, "0.0.0.0") < 0) {
|
||||
if (e1inp_line_update(line) < 0) {
|
||||
LOGP(DBSCTEST, LOGL_ERROR, "problem creating E1 line\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -7,19 +7,22 @@
|
|||
|
||||
static void *tall_test;
|
||||
|
||||
static int sign_link_up(struct msgb *msg, struct e1inp_line *line)
|
||||
static int sign_link_up(struct msgb *msg, struct e1inp_line *line,
|
||||
enum e1inp_sign_type type)
|
||||
{
|
||||
printf("ID_RESP received, create sign link.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sign_link(struct msgb *msg, struct e1inp_sign_link *link)
|
||||
static int sign_link(struct msgb *msg, struct e1inp_line *line,
|
||||
struct e1inp_sign_link *link)
|
||||
{
|
||||
printf("OML/RSL data received\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int error(struct msgb *msg, int error)
|
||||
static int error(struct msgb *msg, struct e1inp_line *line,
|
||||
enum e1inp_sign_type type, int error)
|
||||
{
|
||||
printf("error, malformed message\n");
|
||||
return 0;
|
||||
|
@ -52,6 +55,8 @@ int main(void)
|
|||
osmo_init_logging(&bts_test_log_info);
|
||||
|
||||
struct e1inp_line_ops ops = {
|
||||
.role = E1INP_LINE_R_BTS,
|
||||
.addr = "127.0.0.1",
|
||||
.sign_link_up = sign_link_up,
|
||||
.sign_link = sign_link,
|
||||
.error = error,
|
||||
|
@ -59,11 +64,12 @@ int main(void)
|
|||
|
||||
#define LINENR 0
|
||||
|
||||
line = e1inp_line_create(LINENR, "ipa", &ops);
|
||||
line = e1inp_line_create(LINENR, "ipa");
|
||||
if (line == NULL) {
|
||||
LOGP(DBTSTEST, LOGL_ERROR, "problem enabling E1 line\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
e1inp_line_bind_ops(line, &ops);
|
||||
|
||||
/*
|
||||
* Depending if this is a real or virtual E1 lines:
|
||||
|
@ -76,7 +82,7 @@ int main(void)
|
|||
* it explains how this is done with ISDN.
|
||||
*/
|
||||
|
||||
if (e1inp_line_update(line, E1INP_LINE_R_BTS, "127.0.0.1") < 0) {
|
||||
if (e1inp_line_update(line) < 0) {
|
||||
LOGP(DBTSTEST, LOGL_ERROR, "problem enabling E1 line\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue