diff options
Diffstat (limited to 'src/libabis/input')
-rw-r--r-- | src/libabis/input/dahdi.c | 49 | ||||
-rw-r--r-- | src/libabis/input/hsl.c | 54 | ||||
-rw-r--r-- | src/libabis/input/ipaccess.c | 209 | ||||
-rw-r--r-- | src/libabis/input/lapd.c | 18 | ||||
-rw-r--r-- | src/libabis/input/lapd.h | 2 | ||||
-rw-r--r-- | src/libabis/input/misdn.c | 37 |
6 files changed, 205 insertions, 164 deletions
diff --git a/src/libabis/input/dahdi.c b/src/libabis/input/dahdi.c index 572bb5ae9..6f8983763 100644 --- a/src/libabis/input/dahdi.c +++ b/src/libabis/input/dahdi.c @@ -33,14 +33,13 @@ #include <string.h> #include <time.h> #include <sys/fcntl.h> -#include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <arpa/inet.h> #include <dahdi/user.h> -#include <osmocore/select.h> -#include <osmocore/msgb.h> +#include <osmocom/core/select.h> +#include <osmocom/core/msgb.h> #include <openbsc/debug.h> #include <openbsc/gsm_data.h> #include <openbsc/abis_nm.h> @@ -48,7 +47,7 @@ #include <openbsc/subchan_demux.h> #include <openbsc/e1_input.h> #include <openbsc/signal.h> -#include <osmocore/talloc.h> +#include <osmocom/core/talloc.h> #include "lapd.h" @@ -84,16 +83,16 @@ static void handle_dahdi_exception(struct e1inp_ts *ts) switch (evt) { case DAHDI_EVENT_ALARM: /* we should notify the code that the line is gone */ - dispatch_signal(SS_INPUT, S_INP_LINE_ALARM, &isd); + osmo_signal_dispatch(SS_INPUT, S_INP_LINE_ALARM, &isd); break; case DAHDI_EVENT_NOALARM: /* alarm has gone, we should re-start the SABM requests */ - dispatch_signal(SS_INPUT, S_INP_LINE_NOALARM, &isd); + osmo_signal_dispatch(SS_INPUT, S_INP_LINE_NOALARM, &isd); break; } } -static int handle_ts1_read(struct bsc_fd *bfd) +static int handle_ts1_read(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -148,7 +147,7 @@ static int handle_ts1_read(struct bsc_fd *bfd) msg->l2h = msg->data + 2; else msg->l2h = msg->data + 1; - DEBUGP(DMI, "RX: %s\n", hexdump(msgb_l2(msg), ret)); + DEBUGP(DMI, "RX: %s\n", osmo_hexdump(msgb_l2(msg), ret)); ret = e1inp_rx_ts(e1i_ts, msg, tei, sapi); break; default: @@ -185,7 +184,7 @@ static void timeout_ts1_write(void *data) static void dahdi_write_msg(uint8_t *data, int len, void *cbdata) { - struct bsc_fd *bfd = cbdata; + struct osmo_fd *bfd = cbdata; struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; @@ -198,7 +197,7 @@ static void dahdi_write_msg(uint8_t *data, int len, void *cbdata) LOGP(DMI, LOGL_NOTICE, "%s write failed %d\n", __func__, ret); } -static int handle_ts1_write(struct bsc_fd *bfd) +static int handle_ts1_write(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -215,7 +214,7 @@ static int handle_ts1_write(struct bsc_fd *bfd) return 0; } - DEBUGP(DMI, "TX: %s\n", hexdump(msg->data, msg->len)); + DEBUGP(DMI, "TX: %s\n", osmo_hexdump(msg->data, msg->len)); lapd_transmit(e1i_ts->driver.dahdi.lapd, sign_link->tei, sign_link->sapi, msg->data, msg->len); msgb_free(msg); @@ -223,7 +222,7 @@ static int handle_ts1_write(struct bsc_fd *bfd) /* set tx delay timer for next event */ e1i_ts->sign.tx_timer.cb = timeout_ts1_write; e1i_ts->sign.tx_timer.data = e1i_ts; - bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 50000); + osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, 50000); return 0; } @@ -231,14 +230,14 @@ static int handle_ts1_write(struct bsc_fd *bfd) static int invertbits = 1; -static u_int8_t flip_table[256]; +static uint8_t flip_table[256]; static void init_flip_bits(void) { int i,k; for (i = 0 ; i < 256 ; i++) { - u_int8_t sample = 0 ; + uint8_t sample = 0 ; for (k = 0; k<8; k++) { if ( i & 1 << k ) sample |= 0x80 >> k; } @@ -246,13 +245,13 @@ static void init_flip_bits(void) } } -static u_int8_t * flip_buf_bits ( u_int8_t * buf , int len) +static uint8_t * flip_buf_bits ( uint8_t * buf , int len) { int i; - u_int8_t * start = buf; + uint8_t * start = buf; for (i = 0 ; i < len; i++) { - buf[i] = flip_table[(u_int8_t)buf[i]]; + buf[i] = flip_table[(uint8_t)buf[i]]; } return start; @@ -260,12 +259,12 @@ static u_int8_t * flip_buf_bits ( u_int8_t * buf , int len) #define D_BCHAN_TX_GRAN 160 /* write to a B channel TS */ -static int handle_tsX_write(struct bsc_fd *bfd) +static int handle_tsX_write(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; - u_int8_t tx_buf[D_BCHAN_TX_GRAN]; + uint8_t tx_buf[D_BCHAN_TX_GRAN]; struct subch_mux *mx = &e1i_ts->trau.mux; int ret; @@ -278,7 +277,7 @@ static int handle_tsX_write(struct bsc_fd *bfd) } DEBUGP(DMIB, "BCHAN TX: %s\n", - hexdump(tx_buf, D_BCHAN_TX_GRAN)); + osmo_hexdump(tx_buf, D_BCHAN_TX_GRAN)); if (invertbits) { flip_buf_bits(tx_buf, ret); @@ -294,7 +293,7 @@ static int handle_tsX_write(struct bsc_fd *bfd) #define D_TSX_ALLOC_SIZE (D_BCHAN_TX_GRAN) /* FIXME: read from a B channel TS */ -static int handle_tsX_read(struct bsc_fd *bfd) +static int handle_tsX_read(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -319,7 +318,7 @@ static int handle_tsX_read(struct bsc_fd *bfd) msg->l2h = msg->data; DEBUGP(DMIB, "BCHAN RX: %s\n", - hexdump(msgb_l2(msg), ret)); + osmo_hexdump(msgb_l2(msg), ret)); ret = e1inp_rx_ts(e1i_ts, msg, 0, 0); /* physical layer indicates that data has been sent, * we thus can send some more data */ @@ -330,7 +329,7 @@ static int handle_tsX_read(struct bsc_fd *bfd) } /* callback from select.c in case one of the fd's can be read/written */ -static int dahdi_fd_cb(struct bsc_fd *bfd, unsigned int what) +static int dahdi_fd_cb(struct osmo_fd *bfd, unsigned int what) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -421,7 +420,7 @@ static int dahdi_e1_setup(struct e1inp_line *line) unsigned int idx = ts-1; char openstr[128]; struct e1inp_ts *e1i_ts = &line->ts[idx]; - struct bsc_fd *bfd = &e1i_ts->driver.dahdi.fd; + struct osmo_fd *bfd = &e1i_ts->driver.dahdi.fd; bfd->data = line; bfd->priv_nr = ts; @@ -464,7 +463,7 @@ static int dahdi_e1_setup(struct e1inp_line *line) return bfd->fd; } - ret = bsc_register_fd(bfd); + ret = osmo_fd_register(bfd); if (ret < 0) { fprintf(stderr, "could not register FD: %s\n", strerror(ret)); diff --git a/src/libabis/input/hsl.c b/src/libabis/input/hsl.c index 1afe82b49..c98a22cb4 100644 --- a/src/libabis/input/hsl.c +++ b/src/libabis/input/hsl.c @@ -38,14 +38,13 @@ #include <string.h> #include <time.h> #include <sys/fcntl.h> -#include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <arpa/inet.h> -#include <osmocore/select.h> -#include <osmocore/tlv.h> -#include <osmocore/msgb.h> +#include <osmocom/core/select.h> +#include <osmocom/gsm/tlv.h> +#include <osmocom/core/msgb.h> #include <openbsc/debug.h> #include <openbsc/gsm_data.h> #include <openbsc/abis_nm.h> @@ -55,7 +54,7 @@ #include <openbsc/ipaccess.h> #include <openbsc/socket.h> #include <openbsc/signal.h> -#include <osmocore/talloc.h> +#include <osmocom/core/talloc.h> #define HSL_TCP_PORT 2500 #define HSL_PROTO_DEBUG 0xdd @@ -65,7 +64,7 @@ /* data structure for one E1 interface with A-bis */ struct hsl_e1_handle { - struct bsc_fd listen_fd; + struct osmo_fd listen_fd; struct gsm_network *gsmnet; }; @@ -82,7 +81,7 @@ int hsl_drop_oml(struct gsm_bts *bts) struct gsm_bts_trx *trx; struct e1inp_ts *ts; struct e1inp_line *line; - struct bsc_fd *bfd; + struct osmo_fd *bfd; if (!bts || !bts->oml_link) return -1; @@ -93,7 +92,7 @@ int hsl_drop_oml(struct gsm_bts *bts) e1inp_event(ts, S_INP_TEI_DN, bts->oml_link->tei, bts->oml_link->sapi); bfd = &ts->driver.ipaccess.fd; - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; @@ -110,7 +109,7 @@ int hsl_drop_oml(struct gsm_bts *bts) return -1; } -static int hsl_drop_ts_fd(struct e1inp_ts *ts, struct bsc_fd *bfd) +static int hsl_drop_ts_fd(struct e1inp_ts *ts, struct osmo_fd *bfd) { struct e1inp_sign_link *link, *link2; int bts_nr = -1; @@ -120,7 +119,7 @@ static int hsl_drop_ts_fd(struct e1inp_ts *ts, struct bsc_fd *bfd) e1inp_sign_link_destroy(link); } - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; @@ -196,7 +195,7 @@ static int process_hsl_rsl(struct msgb *msg, struct e1inp_line *line) return 0; } -static int handle_ts1_read(struct bsc_fd *bfd) +static int handle_ts1_read(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -219,7 +218,7 @@ static int handle_ts1_read(struct bsc_fd *bfd) return error; } - DEBUGP(DMI, "RX %u: %s\n", ts_nr, hexdump(msgb_l2(msg), msgb_l2len(msg))); + DEBUGP(DMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); hh = (struct ipaccess_head *) msg->data; if (hh->proto == HSL_PROTO_DEBUG) { @@ -291,14 +290,14 @@ static void timeout_ts1_write(void *data) ts_want_write(e1i_ts); } -static int handle_ts1_write(struct bsc_fd *bfd) +static int handle_ts1_write(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; struct e1inp_sign_link *sign_link; struct msgb *msg; - u_int8_t proto; + uint8_t proto; int ret; bfd->when &= ~BSC_FD_WRITE; @@ -331,7 +330,7 @@ static int handle_ts1_write(struct bsc_fd *bfd) msg->l2h = msg->data; ipaccess_prepend_header(msg, sign_link->tei); - DEBUGP(DMI, "TX %u: %s\n", ts_nr, hexdump(msg->l2h, msgb_l2len(msg))); + DEBUGP(DMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); ret = send(bfd->fd, msg->data, msg->len, 0); msgb_free(msg); @@ -341,13 +340,13 @@ static int handle_ts1_write(struct bsc_fd *bfd) e1i_ts->sign.tx_timer.data = e1i_ts; /* Reducing this might break the nanoBTS 900 init. */ - bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); + osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); return ret; } /* callback from select.c in case one of the fd's can be read/written */ -static int hsl_fd_cb(struct bsc_fd *bfd, unsigned int what) +static int hsl_fd_cb(struct osmo_fd *bfd, unsigned int what) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -378,14 +377,14 @@ struct e1inp_driver hsl_driver = { }; /* callback of the OML listening filedescriptor */ -static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) +static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what) { int ret; int idx = 0; int i; struct e1inp_line *line; struct e1inp_ts *e1i_ts; - struct bsc_fd *bfd; + struct osmo_fd *bfd; struct sockaddr_in sa; socklen_t sa_len = sizeof(sa); @@ -422,7 +421,7 @@ static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) bfd->priv_nr = PRIV_OML; bfd->cb = hsl_fd_cb; bfd->when = BSC_FD_READ; - ret = bsc_register_fd(bfd); + ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DINP, LOGL_ERROR, "could not register FD\n"); close(bfd->fd); @@ -438,12 +437,6 @@ int hsl_setup(struct gsm_network *gsmnet) { int ret; - /* register the driver with the core */ - /* FIXME: do this in the plugin initializer function */ - ret = e1inp_driver_register(&hsl_driver); - if (ret) - return ret; - e1h = talloc_zero(tall_bsc_ctx, struct hsl_e1_handle); if (!e1h) return -ENOMEM; @@ -451,10 +444,15 @@ int hsl_setup(struct gsm_network *gsmnet) e1h->gsmnet = gsmnet; /* Listen for connections */ - ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, 0, HSL_TCP_PORT, - listen_fd_cb); + ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, INADDR_ANY, HSL_TCP_PORT, + 0, listen_fd_cb, NULL); if (ret < 0) return ret; return 0; } + +void e1inp_hsl_init(void) +{ + e1inp_driver_register(&hsl_driver); +} diff --git a/src/libabis/input/ipaccess.c b/src/libabis/input/ipaccess.c index dcf8d1a53..cc2a7a055 100644 --- a/src/libabis/input/ipaccess.c +++ b/src/libabis/input/ipaccess.c @@ -28,15 +28,14 @@ #include <string.h> #include <time.h> #include <sys/fcntl.h> -#include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <arpa/inet.h> -#include <osmocore/select.h> -#include <osmocore/tlv.h> -#include <osmocore/msgb.h> -#include <osmocore/talloc.h> +#include <osmocom/core/select.h> +#include <osmocom/gsm/tlv.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/talloc.h> #include <openbsc/debug.h> #include <openbsc/gsm_data.h> #include <openbsc/abis_nm.h> @@ -52,8 +51,8 @@ /* data structure for one E1 interface with A-bis */ struct ia_e1_handle { - struct bsc_fd listen_fd; - struct bsc_fd rsl_listen_fd; + struct osmo_fd listen_fd; + struct osmo_fd rsl_listen_fd; struct gsm_network *gsmnet; }; @@ -62,18 +61,31 @@ static struct ia_e1_handle *e1h; #define TS1_ALLOC_SIZE 900 -static const u_int8_t pong[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG }; -static const u_int8_t id_ack[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK }; -static const u_int8_t id_req[] = { 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET, - 0x01, IPAC_IDTAG_UNIT, - 0x01, IPAC_IDTAG_MACADDR, - 0x01, IPAC_IDTAG_LOCATION1, - 0x01, IPAC_IDTAG_LOCATION2, - 0x01, IPAC_IDTAG_EQUIPVERS, - 0x01, IPAC_IDTAG_SWVERSION, - 0x01, IPAC_IDTAG_UNITNAME, - 0x01, IPAC_IDTAG_SERNR, - }; +/* + * Common propietary IPA messages: + * - PONG: in reply to PING. + * - ID_REQUEST: first messages once OML has been established. + * - ID_ACK: in reply to ID_ACK. + */ +const uint8_t ipa_pong_msg[] = { + 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG +}; + +const uint8_t ipa_id_ack_msg[] = { + 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK +}; + +const uint8_t ipa_id_req_msg[] = { + 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET, + 0x01, IPAC_IDTAG_UNIT, + 0x01, IPAC_IDTAG_MACADDR, + 0x01, IPAC_IDTAG_LOCATION1, + 0x01, IPAC_IDTAG_LOCATION2, + 0x01, IPAC_IDTAG_EQUIPVERS, + 0x01, IPAC_IDTAG_SWVERSION, + 0x01, IPAC_IDTAG_UNITNAME, + 0x01, IPAC_IDTAG_SERNR, +}; static const char *idtag_names[] = { [IPAC_IDTAG_SERNR] = "Serial_Number", @@ -87,7 +99,7 @@ static const char *idtag_names[] = { [IPAC_IDTAG_UNIT] = "Unit_ID", }; -static const char *ipac_idtag_name(int tag) +const char *ipaccess_idtag_name(uint8_t tag) { if (tag >= ARRAY_SIZE(idtag_names)) return "unknown"; @@ -97,9 +109,9 @@ static const char *ipac_idtag_name(int tag) int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len) { - u_int8_t t_len; - u_int8_t t_tag; - u_int8_t *cur = buf; + uint8_t t_len; + uint8_t t_tag; + uint8_t *cur = buf; memset(dec, 0, sizeof(*dec)); @@ -110,10 +122,10 @@ int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len) if (t_len > len + 1) { LOGP(DMI, LOGL_ERROR, "The tag does not fit: %d\n", t_len); - return -1; + return -EINVAL; } - DEBUGPC(DMI, "%s='%s' ", ipac_idtag_name(t_tag), cur); + DEBUGPC(DMI, "%s='%s' ", ipaccess_idtag_name(t_tag), cur); dec->lv[t_tag].len = t_len; dec->lv[t_tag].val = cur; @@ -125,7 +137,7 @@ int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len) } struct gsm_bts *find_bts_by_unitid(struct gsm_network *net, - u_int16_t site_id, u_int16_t bts_id) + uint16_t site_id, uint16_t bts_id) { struct gsm_bts *bts; @@ -142,8 +154,8 @@ struct gsm_bts *find_bts_by_unitid(struct gsm_network *net, return NULL; } -static int parse_unitid(const char *str, u_int16_t *site_id, u_int16_t *bts_id, - u_int16_t *trx_id) +int ipaccess_parse_unitid(const char *str, uint16_t *site_id, + uint16_t *bts_id, uint16_t *trx_id) { unsigned long ul; char *endptr; @@ -179,27 +191,45 @@ static int parse_unitid(const char *str, u_int16_t *site_id, u_int16_t *bts_id, return 0; } -/* send the id ack */ +static int ipaccess_send(int fd, const void *msg, size_t msglen) +{ + int ret; + + ret = write(fd, msg, msglen); + if (ret < 0) + return ret; + if (ret < msglen) { + LOGP(DINP, LOGL_ERROR, "ipaccess_send: short write\n"); + return -EIO; + } + return ret; +} + +int ipaccess_send_pong(int fd) +{ + return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg)); +} + int ipaccess_send_id_ack(int fd) { - return write(fd, id_ack, sizeof(id_ack)); + return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg)); } int ipaccess_send_id_req(int fd) { - return write(fd, id_req, sizeof(id_req)); + return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg)); } /* base handling of the ip.access protocol */ int ipaccess_rcvmsg_base(struct msgb *msg, - struct bsc_fd *bfd) + struct osmo_fd *bfd) { - u_int8_t msg_type = *(msg->l2h); + uint8_t msg_type = *(msg->l2h); int ret = 0; switch (msg_type) { case IPAC_MSGT_PING: - ret = write(bfd->fd, pong, sizeof(pong)); + ret = ipaccess_send_pong(bfd->fd); break; case IPAC_MSGT_PONG: DEBUGP(DMI, "PONG!\n"); @@ -213,14 +243,14 @@ int ipaccess_rcvmsg_base(struct msgb *msg, } static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, - struct bsc_fd *bfd) + struct osmo_fd *bfd) { struct tlv_parsed tlvp; - u_int8_t msg_type = *(msg->l2h); - u_int16_t site_id = 0, bts_id = 0, trx_id = 0; + uint8_t msg_type = *(msg->l2h); + uint16_t site_id = 0, bts_id = 0, trx_id = 0; struct gsm_bts *bts; char *unitid; - int len; + int len, ret; /* handle base messages */ ipaccess_rcvmsg_base(msg, bfd); @@ -229,10 +259,14 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, case IPAC_MSGT_ID_RESP: DEBUGP(DMI, "ID_RESP "); /* parse tags, search for Unit ID */ - ipaccess_idtag_parse(&tlvp, (u_int8_t *)msg->l2h + 2, - msgb_l2len(msg)-2); + ret = ipaccess_idtag_parse(&tlvp, (uint8_t *)msg->l2h + 2, + msgb_l2len(msg)-2); DEBUGP(DMI, "\n"); - + if (ret < 0) { + LOGP(DINP, LOGL_ERROR, "ignoring IPA response message " + "with malformed TLVs\n"); + return ret; + } if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT)) break; @@ -243,7 +277,7 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, /* lookup BTS, create sign_link, ... */ unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT); unitid[len - 1] = '\0'; - parse_unitid(unitid, &site_id, &bts_id, &trx_id); + ipaccess_parse_unitid(unitid, &site_id, &bts_id, &trx_id); bts = find_bts_by_unitid(e1h->gsmnet, site_id, bts_id); if (!bts) { LOGP(DINP, LOGL_ERROR, "Unable to find BTS configuration for " @@ -260,14 +294,14 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, bts->oml_tei, 0); } else if (bfd->priv_nr == PRIV_RSL) { struct e1inp_ts *e1i_ts; - struct bsc_fd *newbfd; + struct osmo_fd *newbfd; struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, trx_id); /* drop any old rsl connection */ ipaccess_drop_rsl(trx); if (!bts->oml_link) { - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; talloc_free(bfd); @@ -287,10 +321,10 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, /* get rid of our old temporary bfd */ memcpy(newbfd, bfd, sizeof(*newbfd)); newbfd->priv_nr = PRIV_RSL + trx_id; - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); bfd->fd = -1; talloc_free(bfd); - bsc_register_fd(newbfd); + osmo_fd_register(newbfd); } break; } @@ -304,7 +338,7 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, * read one ipa message from the socket * return NULL in case of error */ -struct msgb *ipaccess_read_msg(struct bsc_fd *bfd, int *error) +struct msgb *ipaccess_read_msg(struct osmo_fd *bfd, int *error) { struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "Abis/IP"); struct ipaccess_head *hh; @@ -360,7 +394,7 @@ int ipaccess_drop_oml(struct gsm_bts *bts) struct gsm_bts_trx *trx; struct e1inp_ts *ts; struct e1inp_line *line; - struct bsc_fd *bfd; + struct osmo_fd *bfd; if (!bts || !bts->oml_link) return -1; @@ -371,7 +405,7 @@ int ipaccess_drop_oml(struct gsm_bts *bts) e1inp_event(ts, S_INP_TEI_DN, bts->oml_link->tei, bts->oml_link->sapi); bfd = &ts->driver.ipaccess.fd; - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; @@ -390,19 +424,22 @@ int ipaccess_drop_oml(struct gsm_bts *bts) return -1; } -static int ipaccess_drop(struct e1inp_ts *ts, struct bsc_fd *bfd) +static int ipaccess_drop(struct e1inp_ts *ts, struct osmo_fd *bfd) { struct e1inp_sign_link *link; int bts_nr; - if (!ts) { + if (!ts || !bfd->data) { /* * If we don't have a TS this means that this is a RSL * connection but we are not past the authentication * handling yet. So we can safely delete this bfd and * wait for a reconnect. + * If we don't have bfd->data this means that a RSL + * connection was accept()ed, but nothing was recv()ed + * and the connection gets close()ed. */ - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; talloc_free(bfd); @@ -421,7 +458,7 @@ static int ipaccess_drop(struct e1inp_ts *ts, struct bsc_fd *bfd) /* error case */ LOGP(DINP, LOGL_ERROR, "Failed to find a signalling link for ts: %p\n", ts); - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; return -1; @@ -429,7 +466,7 @@ static int ipaccess_drop(struct e1inp_ts *ts, struct bsc_fd *bfd) int ipaccess_drop_rsl(struct gsm_bts_trx *trx) { - struct bsc_fd *bfd; + struct osmo_fd *bfd; struct e1inp_ts *ts; if (!trx || !trx->rsl_link) @@ -441,7 +478,7 @@ int ipaccess_drop_rsl(struct gsm_bts_trx *trx) /* close the socket */ bfd = &ts->driver.ipaccess.fd; - bsc_unregister_fd(bfd); + osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; @@ -452,7 +489,7 @@ int ipaccess_drop_rsl(struct gsm_bts_trx *trx) return -1; } -static int handle_ts1_read(struct bsc_fd *bfd) +static int handle_ts1_read(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -475,7 +512,7 @@ static int handle_ts1_read(struct bsc_fd *bfd) return error; } - DEBUGP(DMI, "RX %u: %s\n", ts_nr, hexdump(msgb_l2(msg), msgb_l2len(msg))); + DEBUGP(DMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); hh = (struct ipaccess_head *) msg->data; if (hh->proto == IPAC_PROTO_IPACCESS) { @@ -520,6 +557,15 @@ static int handle_ts1_read(struct bsc_fd *bfd) return ret; } +void ipaccess_prepend_header_ext(struct msgb *msg, int proto) +{ + struct ipaccess_head_ext *hh_ext; + + /* prepend the osmo ip.access header extension */ + hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext)); + hh_ext->proto = proto; +} + void ipaccess_prepend_header(struct msgb *msg, int proto) { struct ipaccess_head *hh; @@ -545,14 +591,14 @@ static void timeout_ts1_write(void *data) ts_want_write(e1i_ts); } -static int handle_ts1_write(struct bsc_fd *bfd) +static int handle_ts1_write(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; struct e1inp_sign_link *sign_link; struct msgb *msg; - u_int8_t proto; + uint8_t proto; int ret; bfd->when &= ~BSC_FD_WRITE; @@ -580,7 +626,7 @@ static int handle_ts1_write(struct bsc_fd *bfd) msg->l2h = msg->data; ipaccess_prepend_header(msg, sign_link->tei); - DEBUGP(DMI, "TX %u: %s\n", ts_nr, hexdump(msg->l2h, msgb_l2len(msg))); + DEBUGP(DMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); ret = send(bfd->fd, msg->data, msg->len, 0); msgb_free(msg); @@ -590,13 +636,13 @@ static int handle_ts1_write(struct bsc_fd *bfd) e1i_ts->sign.tx_timer.data = e1i_ts; /* Reducing this might break the nanoBTS 900 init. */ - bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); + osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); return ret; } /* callback from select.c in case one of the fd's can be read/written */ -static int ipaccess_fd_cb(struct bsc_fd *bfd, unsigned int what) +static int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -627,14 +673,14 @@ struct e1inp_driver ipaccess_driver = { }; /* callback of the OML listening filedescriptor */ -static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) +static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what) { int ret; int idx = 0; int i; struct e1inp_line *line; struct e1inp_ts *e1i_ts; - struct bsc_fd *bfd; + struct osmo_fd *bfd; struct sockaddr_in sa; socklen_t sa_len = sizeof(sa); @@ -671,7 +717,7 @@ static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) bfd->priv_nr = PRIV_OML; bfd->cb = ipaccess_fd_cb; bfd->when = BSC_FD_READ; - ret = bsc_register_fd(bfd); + ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DINP, LOGL_ERROR, "could not register FD\n"); close(bfd->fd); @@ -686,17 +732,17 @@ static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) //return e1inp_line_register(line); } -static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) +static int rsl_listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what) { struct sockaddr_in sa; socklen_t sa_len = sizeof(sa); - struct bsc_fd *bfd; + struct osmo_fd *bfd; int ret; if (!(what & BSC_FD_READ)) return 0; - bfd = talloc_zero(tall_bsc_ctx, struct bsc_fd); + bfd = talloc_zero(tall_bsc_ctx, struct osmo_fd); if (!bfd) return -ENOMEM; @@ -713,7 +759,7 @@ static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) bfd->priv_nr = PRIV_RSL; bfd->cb = ipaccess_fd_cb; bfd->when = BSC_FD_READ; - ret = bsc_register_fd(bfd); + ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DINP, LOGL_ERROR, "could not register FD\n"); close(bfd->fd); @@ -721,7 +767,7 @@ static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) return ret; } /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ - ret = write(bfd->fd, id_req, sizeof(id_req)); + ret = ipaccess_send_id_req(bfd->fd); return 0; } @@ -730,7 +776,7 @@ static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa) { struct e1inp_ts *e1i_ts = &line->ts[0]; - struct bsc_fd *bfd = &e1i_ts->driver.ipaccess.fd; + struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd; int ret, on = 1; bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -753,7 +799,7 @@ int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa) return ret; } - ret = bsc_register_fd(bfd); + ret = osmo_fd_register(bfd); if (ret < 0) { close(bfd->fd); return ret; @@ -769,12 +815,6 @@ int ipaccess_setup(struct gsm_network *gsmnet) { int ret; - /* register the driver with the core */ - /* FIXME: do this in the plugin initializer function */ - ret = e1inp_driver_register(&ipaccess_driver); - if (ret) - return ret; - e1h = talloc_zero(tall_bsc_ctx, struct ia_e1_handle); if (!e1h) return -ENOMEM; @@ -782,16 +822,21 @@ int ipaccess_setup(struct gsm_network *gsmnet) e1h->gsmnet = gsmnet; /* Listen for OML connections */ - ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, 0, IPA_TCP_PORT_OML, - listen_fd_cb); + ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, INADDR_ANY, + IPA_TCP_PORT_OML, 0, listen_fd_cb, NULL); if (ret < 0) return ret; /* Listen for RSL connections */ - ret = make_sock(&e1h->rsl_listen_fd, IPPROTO_TCP, 0, - IPA_TCP_PORT_RSL, rsl_listen_fd_cb); + ret = make_sock(&e1h->rsl_listen_fd, IPPROTO_TCP, INADDR_ANY, + IPA_TCP_PORT_RSL, 0, rsl_listen_fd_cb, NULL); if (ret < 0) return ret; return ret; } + +void e1inp_ipaccess_init(void) +{ + e1inp_driver_register(&ipaccess_driver); +} diff --git a/src/libabis/input/lapd.c b/src/libabis/input/lapd.c index 7bce6cc51..d0fab1815 100644 --- a/src/libabis/input/lapd.c +++ b/src/libabis/input/lapd.c @@ -36,10 +36,10 @@ #include "lapd.h" -#include <osmocore/linuxlist.h> -#include <osmocore/talloc.h> -#include <osmocore/msgb.h> -#include <osmocore/timer.h> +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/timer.h> #include <openbsc/debug.h> #define SABM_INTERVAL 0, 300000 @@ -137,7 +137,7 @@ struct lapd_sap { int va; /* last acked by peer */ int vr; /* next expected to be received */ - struct timer_list sabme_timer; /* timer to re-transmit SABM message */ + struct osmo_timer_list sabme_timer; /* timer to re-transmit SABM message */ }; /* 3.5.2.2 Send state variable V(S) @@ -259,11 +259,11 @@ static void lapd_sap_set_state(struct lapd_tei *teip, uint8_t sapi, switch (sap->state) { case SAP_STATE_SABM_RETRANS: if (newstate != SAP_STATE_SABM_RETRANS) - bsc_del_timer(&sap->sabme_timer); + osmo_timer_del(&sap->sabme_timer); break; default: if (newstate == SAP_STATE_SABM_RETRANS) - bsc_schedule_timer(&sap->sabme_timer, SABM_INTERVAL); + osmo_timer_schedule(&sap->sabme_timer, SABM_INTERVAL); break; } @@ -290,7 +290,7 @@ static void lapd_tei_receive(struct lapd_instance *li, uint8_t *data, int len) teip = teip_from_tei(li, action); if (!teip) { LOGP(DMI, LOGL_INFO, "TEI MGR: New TEI %u\n", action); - lapd_tei_alloc(li, action); + teip = lapd_tei_alloc(li, action); } /* Send ACCEPT */ @@ -608,7 +608,7 @@ static void sabme_timer_cb(void *_sap) lapd_send_sabm(sap->tei->li, sap->tei->tei, sap->sapi); if (sap->state == SAP_STATE_SABM_RETRANS) - bsc_schedule_timer(&sap->sabme_timer, SABM_INTERVAL); + osmo_timer_schedule(&sap->sabme_timer, SABM_INTERVAL); } /* Start a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */ diff --git a/src/libabis/input/lapd.h b/src/libabis/input/lapd.h index fd11edaa3..fb980d104 100644 --- a/src/libabis/input/lapd.h +++ b/src/libabis/input/lapd.h @@ -3,7 +3,7 @@ #include <stdint.h> -#include <osmocore/linuxlist.h> +#include <osmocom/core/linuxlist.h> typedef enum { LAPD_MPH_NONE = 0, diff --git a/src/libabis/input/misdn.c b/src/libabis/input/misdn.c index 459887917..ab92d612f 100644 --- a/src/libabis/input/misdn.c +++ b/src/libabis/input/misdn.c @@ -27,7 +27,6 @@ #include <string.h> #include <time.h> #include <sys/fcntl.h> -#include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <arpa/inet.h> @@ -40,9 +39,9 @@ #define PF_ISDN AF_ISDN #endif -#include <osmocore/select.h> -#include <osmocore/msgb.h> -#include <osmocore/talloc.h> +#include <osmocom/core/select.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/talloc.h> #include <openbsc/debug.h> #include <openbsc/gsm_data.h> #include <openbsc/abis_nm.h> @@ -86,7 +85,7 @@ const char *get_prim_name(unsigned int prim) return "UNKNOWN"; } -static int handle_ts1_read(struct bsc_fd *bfd) +static int handle_ts1_read(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -163,7 +162,7 @@ static int handle_ts1_read(struct bsc_fd *bfd) case DL_DATA_IND: case DL_UNITDATA_IND: msg->l2h = msg->data + MISDN_HEADER_LEN; - DEBUGP(DMI, "RX: %s\n", hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN)); + DEBUGP(DMI, "RX: %s\n", osmo_hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN)); ret = e1inp_rx_ts(e1i_ts, msg, l2addr.tei, l2addr.sapi); break; case PH_ACTIVATE_IND: @@ -201,7 +200,7 @@ static void timeout_ts1_write(void *data) ts_want_write(e1i_ts); } -static int handle_ts1_write(struct bsc_fd *bfd) +static int handle_ts1_write(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -210,7 +209,7 @@ static int handle_ts1_write(struct bsc_fd *bfd) struct sockaddr_mISDN sa; struct msgb *msg; struct mISDNhead *hh; - u_int8_t *l2_data; + uint8_t *l2_data; int ret; bfd->when &= ~BSC_FD_WRITE; @@ -230,7 +229,7 @@ static int handle_ts1_write(struct bsc_fd *bfd) DEBUGP(DMI, "TX channel(%d) TEI(%d) SAPI(%d): %s\n", sign_link->driver.misdn.channel, sign_link->tei, - sign_link->sapi, hexdump(l2_data, msg->len - MISDN_HEADER_LEN)); + sign_link->sapi, osmo_hexdump(l2_data, msg->len - MISDN_HEADER_LEN)); /* construct the sockaddr */ sa.family = AF_ISDN; @@ -247,20 +246,20 @@ static int handle_ts1_write(struct bsc_fd *bfd) /* set tx delay timer for next event */ e1i_ts->sign.tx_timer.cb = timeout_ts1_write; e1i_ts->sign.tx_timer.data = e1i_ts; - bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); + osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); return ret; } #define BCHAN_TX_GRAN 160 /* write to a B channel TS */ -static int handle_tsX_write(struct bsc_fd *bfd) +static int handle_tsX_write(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; struct mISDNhead *hh; - u_int8_t tx_buf[BCHAN_TX_GRAN + sizeof(*hh)]; + uint8_t tx_buf[BCHAN_TX_GRAN + sizeof(*hh)]; struct subch_mux *mx = &e1i_ts->trau.mux; int ret; @@ -270,7 +269,7 @@ static int handle_tsX_write(struct bsc_fd *bfd) subchan_mux_out(mx, tx_buf+sizeof(*hh), BCHAN_TX_GRAN); DEBUGP(DMIB, "BCHAN TX: %s\n", - hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN)); + osmo_hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN)); ret = send(bfd->fd, tx_buf, sizeof(*hh) + BCHAN_TX_GRAN, 0); if (ret < sizeof(*hh) + BCHAN_TX_GRAN) @@ -282,7 +281,7 @@ static int handle_tsX_write(struct bsc_fd *bfd) #define TSX_ALLOC_SIZE 4096 /* FIXME: read from a B channel TS */ -static int handle_tsX_read(struct bsc_fd *bfd) +static int handle_tsX_read(struct osmo_fd *bfd) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -312,7 +311,7 @@ static int handle_tsX_read(struct bsc_fd *bfd) case PH_DATA_IND: msg->l2h = msg->data + MISDN_HEADER_LEN; DEBUGP(DMIB, "BCHAN RX: %s\n", - hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN)); + osmo_hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN)); ret = e1inp_rx_ts(e1i_ts, msg, 0, 0); break; case PH_ACTIVATE_IND: @@ -330,7 +329,7 @@ static int handle_tsX_read(struct bsc_fd *bfd) } /* callback from select.c in case one of the fd's can be read/written */ -static int misdn_fd_cb(struct bsc_fd *bfd, unsigned int what) +static int misdn_fd_cb(struct osmo_fd *bfd, unsigned int what) { struct e1inp_line *line = bfd->data; unsigned int ts_nr = bfd->priv_nr; @@ -366,7 +365,7 @@ static int activate_bchan(struct e1inp_line *line, int ts, int act) int ret; unsigned int idx = ts-1; struct e1inp_ts *e1i_ts = &line->ts[idx]; - struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd; + struct osmo_fd *bfd = &e1i_ts->driver.misdn.fd; fprintf(stdout, "activate bchan\n"); if (act) @@ -401,7 +400,7 @@ static int mi_e1_setup(struct e1inp_line *line, int release_l2) for (ts = 1; ts < NUM_E1_TS; ts++) { unsigned int idx = ts-1; struct e1inp_ts *e1i_ts = &line->ts[idx]; - struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd; + struct osmo_fd *bfd = &e1i_ts->driver.misdn.fd; struct sockaddr_mISDN addr; bfd->data = line; @@ -471,7 +470,7 @@ static int mi_e1_setup(struct e1inp_line *line, int release_l2) if (e1i_ts->type == E1INP_TS_TYPE_TRAU) activate_bchan(line, ts, 1); - ret = bsc_register_fd(bfd); + ret = osmo_fd_register(bfd); if (ret < 0) { fprintf(stderr, "could not register FD: %s\n", strerror(ret)); |