2009-02-13 02:43:36 +00:00
|
|
|
/* OpenBSC Abis input driver for ip.access */
|
|
|
|
|
|
|
|
/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
|
2010-04-15 09:17:24 +00:00
|
|
|
* (C) 2010 by Holger Hans Peter Freyther
|
|
|
|
* (C) 2010 by On-Waves
|
2009-02-13 02:43:36 +00:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2009-02-13 02:43:36 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2009-02-13 02:43:36 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-02-13 02:43:36 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#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>
|
|
|
|
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
#include <osmocore/select.h>
|
|
|
|
#include <osmocore/tlv.h>
|
|
|
|
#include <osmocore/msgb.h>
|
2009-02-13 02:43:36 +00:00
|
|
|
#include <openbsc/debug.h>
|
|
|
|
#include <openbsc/gsm_data.h>
|
|
|
|
#include <openbsc/abis_nm.h>
|
|
|
|
#include <openbsc/abis_rsl.h>
|
|
|
|
#include <openbsc/subchan_demux.h>
|
|
|
|
#include <openbsc/e1_input.h>
|
2009-02-15 15:32:53 +00:00
|
|
|
#include <openbsc/ipaccess.h>
|
2010-05-19 12:38:50 +00:00
|
|
|
#include <openbsc/socket.h>
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
#include <osmocore/talloc.h>
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2010-03-24 03:56:13 +00:00
|
|
|
#define PRIV_OML 1
|
|
|
|
#define PRIV_RSL 2
|
|
|
|
|
2009-02-13 02:43:36 +00:00
|
|
|
/* data structure for one E1 interface with A-bis */
|
|
|
|
struct ia_e1_handle {
|
|
|
|
struct bsc_fd listen_fd;
|
2009-02-15 11:57:29 +00:00
|
|
|
struct bsc_fd rsl_listen_fd;
|
2009-05-01 14:59:07 +00:00
|
|
|
struct gsm_network *gsmnet;
|
2009-02-13 02:43:36 +00:00
|
|
|
};
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
static struct ia_e1_handle *e1h;
|
|
|
|
|
|
|
|
|
2010-04-04 16:12:37 +00:00
|
|
|
#define TS1_ALLOC_SIZE 900
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2009-02-15 15:32:53 +00:00
|
|
|
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 };
|
2009-05-01 14:59:07 +00:00
|
|
|
static const u_int8_t id_req[] = { 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
|
2010-03-29 06:47:44 +00:00
|
|
|
0x01, IPAC_IDTAG_UNIT,
|
2009-05-01 14:59:07 +00:00
|
|
|
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",
|
|
|
|
[IPAC_IDTAG_UNITNAME] = "Unit_Name",
|
|
|
|
[IPAC_IDTAG_LOCATION1] = "Location_1",
|
|
|
|
[IPAC_IDTAG_LOCATION2] = "Location_2",
|
|
|
|
[IPAC_IDTAG_EQUIPVERS] = "Equipment_Version",
|
|
|
|
[IPAC_IDTAG_SWVERSION] = "Software_Version",
|
|
|
|
[IPAC_IDTAG_IPADDR] = "IP_Address",
|
|
|
|
[IPAC_IDTAG_MACADDR] = "MAC_Address",
|
|
|
|
[IPAC_IDTAG_UNIT] = "Unit_ID",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *ipac_idtag_name(int tag)
|
|
|
|
{
|
|
|
|
if (tag >= ARRAY_SIZE(idtag_names))
|
|
|
|
return "unknown";
|
|
|
|
|
|
|
|
return idtag_names[tag];
|
|
|
|
}
|
|
|
|
|
2010-02-09 13:37:23 +00:00
|
|
|
int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len)
|
2009-05-01 14:59:07 +00:00
|
|
|
{
|
|
|
|
u_int8_t t_len;
|
|
|
|
u_int8_t t_tag;
|
|
|
|
u_int8_t *cur = buf;
|
|
|
|
|
2010-10-14 15:21:04 +00:00
|
|
|
memset(dec, 0, sizeof(*dec));
|
|
|
|
|
2010-10-14 18:42:45 +00:00
|
|
|
while (len >= 2) {
|
|
|
|
len -= 2;
|
2009-05-01 14:59:07 +00:00
|
|
|
t_len = *cur++;
|
|
|
|
t_tag = *cur++;
|
|
|
|
|
2010-10-14 18:42:45 +00:00
|
|
|
if (t_len > len + 1) {
|
|
|
|
LOGP(DMI, LOGL_ERROR, "The tag does not fit: %d\n", t_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
DEBUGPC(DMI, "%s='%s' ", ipac_idtag_name(t_tag), cur);
|
|
|
|
|
|
|
|
dec->lv[t_tag].len = t_len;
|
|
|
|
dec->lv[t_tag].val = cur;
|
|
|
|
|
|
|
|
cur += t_len;
|
2010-10-14 18:42:45 +00:00
|
|
|
len -= t_len;
|
2009-05-01 14:59:07 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gsm_bts *find_bts_by_unitid(struct gsm_network *net,
|
|
|
|
u_int16_t site_id, u_int16_t bts_id)
|
|
|
|
{
|
2009-06-21 14:17:15 +00:00
|
|
|
struct gsm_bts *bts;
|
2009-05-01 14:59:07 +00:00
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
llist_for_each_entry(bts, &net->bts_list, list) {
|
2009-05-01 14:59:07 +00:00
|
|
|
|
|
|
|
if (!is_ipaccess_bts(bts))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bts->ip_access.site_id == site_id &&
|
|
|
|
bts->ip_access.bts_id == bts_id)
|
|
|
|
return bts;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_unitid(const char *str, u_int16_t *site_id, u_int16_t *bts_id,
|
|
|
|
u_int16_t *trx_id)
|
|
|
|
{
|
|
|
|
unsigned long ul;
|
|
|
|
char *endptr;
|
|
|
|
const char *nptr;
|
|
|
|
|
|
|
|
nptr = str;
|
|
|
|
ul = strtoul(nptr, &endptr, 10);
|
|
|
|
if (endptr <= nptr)
|
|
|
|
return -EINVAL;
|
|
|
|
if (site_id)
|
|
|
|
*site_id = ul & 0xffff;
|
|
|
|
|
|
|
|
if (*endptr++ != '/')
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nptr = endptr;
|
|
|
|
ul = strtoul(nptr, &endptr, 10);
|
|
|
|
if (endptr <= nptr)
|
|
|
|
return -EINVAL;
|
|
|
|
if (bts_id)
|
|
|
|
*bts_id = ul & 0xffff;
|
|
|
|
|
|
|
|
if (*endptr++ != '/')
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nptr = endptr;
|
|
|
|
ul = strtoul(nptr, &endptr, 10);
|
|
|
|
if (endptr <= nptr)
|
|
|
|
return -EINVAL;
|
|
|
|
if (trx_id)
|
|
|
|
*trx_id = ul & 0xffff;
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-13 08:06:46 +00:00
|
|
|
/* send the id ack */
|
|
|
|
int ipaccess_send_id_ack(int fd)
|
|
|
|
{
|
|
|
|
return write(fd, id_ack, sizeof(id_ack));
|
|
|
|
}
|
|
|
|
|
2010-02-07 11:04:07 +00:00
|
|
|
int ipaccess_send_id_req(int fd)
|
|
|
|
{
|
|
|
|
return write(fd, id_req, sizeof(id_req));
|
|
|
|
}
|
|
|
|
|
2009-08-18 08:05:45 +00:00
|
|
|
/* base handling of the ip.access protocol */
|
|
|
|
int ipaccess_rcvmsg_base(struct msgb *msg,
|
|
|
|
struct bsc_fd *bfd)
|
2009-02-13 02:43:36 +00:00
|
|
|
{
|
|
|
|
u_int8_t msg_type = *(msg->l2h);
|
2009-03-09 16:17:14 +00:00
|
|
|
int ret = 0;
|
2009-02-13 02:43:36 +00:00
|
|
|
|
|
|
|
switch (msg_type) {
|
2009-02-15 15:32:53 +00:00
|
|
|
case IPAC_MSGT_PING:
|
2009-05-01 14:59:07 +00:00
|
|
|
ret = write(bfd->fd, pong, sizeof(pong));
|
2009-02-13 02:43:36 +00:00
|
|
|
break;
|
2009-02-15 15:32:53 +00:00
|
|
|
case IPAC_MSGT_PONG:
|
2009-02-13 02:43:36 +00:00
|
|
|
DEBUGP(DMI, "PONG!\n");
|
|
|
|
break;
|
2009-08-18 08:05:45 +00:00
|
|
|
case IPAC_MSGT_ID_ACK:
|
|
|
|
DEBUGP(DMI, "ID_ACK? -> ACK!\n");
|
2010-01-13 08:06:46 +00:00
|
|
|
ret = ipaccess_send_id_ack(bfd->fd);
|
2009-08-18 08:05:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg,
|
|
|
|
struct bsc_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;
|
|
|
|
struct gsm_bts *bts;
|
2010-10-14 19:17:30 +00:00
|
|
|
char *unitid;
|
|
|
|
int len;
|
2009-08-18 08:05:45 +00:00
|
|
|
|
|
|
|
/* handle base messages */
|
|
|
|
ipaccess_rcvmsg_base(msg, bfd);
|
|
|
|
|
|
|
|
switch (msg_type) {
|
2009-02-15 15:32:53 +00:00
|
|
|
case IPAC_MSGT_ID_RESP:
|
2009-05-01 14:59:07 +00:00
|
|
|
DEBUGP(DMI, "ID_RESP ");
|
|
|
|
/* parse tags, search for Unit ID */
|
2010-02-09 13:37:23 +00:00
|
|
|
ipaccess_idtag_parse(&tlvp, (u_int8_t *)msg->l2h + 2,
|
2009-05-01 14:59:07 +00:00
|
|
|
msgb_l2len(msg)-2);
|
|
|
|
DEBUGP(DMI, "\n");
|
|
|
|
|
|
|
|
if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT))
|
|
|
|
break;
|
|
|
|
|
2010-10-14 19:17:30 +00:00
|
|
|
len = TLVP_LEN(&tlvp, IPAC_IDTAG_UNIT);
|
|
|
|
if (len < 1)
|
|
|
|
break;
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
/* lookup BTS, create sign_link, ... */
|
2010-10-14 19:17:30 +00:00
|
|
|
unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT);
|
|
|
|
unitid[len - 1] = '\0';
|
|
|
|
parse_unitid(unitid, &site_id, &bts_id, &trx_id);
|
2009-05-01 14:59:07 +00:00
|
|
|
bts = find_bts_by_unitid(e1h->gsmnet, site_id, bts_id);
|
|
|
|
if (!bts) {
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "Unable to find BTS configuration for "
|
2009-05-01 14:59:07 +00:00
|
|
|
" %u/%u/%u, disconnecting\n", site_id, bts_id,
|
|
|
|
trx_id);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
DEBUGP(DINP, "Identified BTS %u/%u/%u\n", site_id, bts_id, trx_id);
|
2010-03-24 03:56:13 +00:00
|
|
|
if (bfd->priv_nr == PRIV_OML) {
|
2010-04-15 09:17:24 +00:00
|
|
|
/* drop any old oml connection */
|
|
|
|
ipaccess_drop_oml(bts);
|
2010-03-24 03:56:13 +00:00
|
|
|
bts->oml_link = e1inp_sign_link_create(&line->ts[PRIV_OML - 1],
|
2009-05-01 14:59:07 +00:00
|
|
|
E1INP_SIGN_OML, bts->c0,
|
2009-10-19 22:22:00 +00:00
|
|
|
bts->oml_tei, 0);
|
2010-03-24 03:56:13 +00:00
|
|
|
} else if (bfd->priv_nr == PRIV_RSL) {
|
2009-05-01 14:59:07 +00:00
|
|
|
struct e1inp_ts *e1i_ts;
|
|
|
|
struct bsc_fd *newbfd;
|
2009-10-19 22:22:00 +00:00
|
|
|
struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, trx_id);
|
2010-04-15 09:17:24 +00:00
|
|
|
|
|
|
|
/* drop any old rsl connection */
|
|
|
|
ipaccess_drop_rsl(trx);
|
|
|
|
|
|
|
|
if (!bts->oml_link) {
|
|
|
|
bsc_unregister_fd(bfd);
|
|
|
|
close(bfd->fd);
|
|
|
|
bfd->fd = -1;
|
|
|
|
talloc_free(bfd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
bfd->data = line = bts->oml_link->ts->line;
|
2010-03-24 03:56:13 +00:00
|
|
|
e1i_ts = &line->ts[PRIV_RSL + trx_id - 1];
|
2009-05-01 14:59:07 +00:00
|
|
|
newbfd = &e1i_ts->driver.ipaccess.fd;
|
2009-10-19 22:22:00 +00:00
|
|
|
e1inp_ts_config(e1i_ts, line, E1INP_TS_TYPE_SIGN);
|
2009-05-01 14:59:07 +00:00
|
|
|
|
2009-10-19 22:22:00 +00:00
|
|
|
trx->rsl_link = e1inp_sign_link_create(e1i_ts,
|
|
|
|
E1INP_SIGN_RSL, trx,
|
|
|
|
trx->rsl_tei, 0);
|
2010-11-15 19:36:21 +00:00
|
|
|
trx->rsl_link->ts->sign.delay = 0;
|
2010-03-24 03:02:55 +00:00
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
/* get rid of our old temporary bfd */
|
|
|
|
memcpy(newbfd, bfd, sizeof(*newbfd));
|
2010-03-24 03:56:13 +00:00
|
|
|
newbfd->priv_nr = PRIV_RSL + trx_id;
|
2009-05-01 14:59:07 +00:00
|
|
|
bsc_unregister_fd(bfd);
|
2010-04-15 09:17:24 +00:00
|
|
|
bfd->fd = -1;
|
2009-06-21 23:36:25 +00:00
|
|
|
talloc_free(bfd);
|
2010-04-15 09:17:24 +00:00
|
|
|
bsc_register_fd(newbfd);
|
2009-05-01 14:59:07 +00:00
|
|
|
}
|
2009-02-13 02:43:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-16 16:32:37 +00:00
|
|
|
#define OML_UP 0x0001
|
|
|
|
#define RSL_UP 0x0002
|
2009-02-15 03:39:51 +00:00
|
|
|
|
2009-08-18 08:05:45 +00:00
|
|
|
/*
|
|
|
|
* read one ipa message from the socket
|
|
|
|
* return NULL in case of error
|
|
|
|
*/
|
|
|
|
struct msgb *ipaccess_read_msg(struct bsc_fd *bfd, int *error)
|
2009-02-13 02:43:36 +00:00
|
|
|
{
|
2009-06-26 17:39:35 +00:00
|
|
|
struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "Abis/IP");
|
2009-02-13 02:43:36 +00:00
|
|
|
struct ipaccess_head *hh;
|
2009-10-29 15:33:59 +00:00
|
|
|
int len, ret = 0;
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2009-08-18 08:05:45 +00:00
|
|
|
if (!msg) {
|
|
|
|
*error = -ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-13 02:43:36 +00:00
|
|
|
|
|
|
|
/* first read our 3-byte header */
|
|
|
|
hh = (struct ipaccess_head *) msg->data;
|
2010-03-24 07:40:55 +00:00
|
|
|
ret = recv(bfd->fd, msg->data, sizeof(*hh), 0);
|
|
|
|
if (ret == 0) {
|
2009-08-18 08:05:45 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
*error = ret;
|
|
|
|
return NULL;
|
2010-03-24 07:40:55 +00:00
|
|
|
} else if (ret != sizeof(*hh)) {
|
|
|
|
if (errno != EAGAIN)
|
|
|
|
LOGP(DINP, LOGL_ERROR, "recv error %d %s\n", ret, strerror(errno));
|
2009-08-18 08:05:45 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
*error = ret;
|
|
|
|
return NULL;
|
2009-02-13 02:43:36 +00:00
|
|
|
}
|
2009-08-18 08:05:45 +00:00
|
|
|
|
2009-02-13 02:43:36 +00:00
|
|
|
msgb_put(msg, ret);
|
|
|
|
|
|
|
|
/* then read te length as specified in header */
|
|
|
|
msg->l2h = msg->data + sizeof(*hh);
|
2009-10-29 15:33:59 +00:00
|
|
|
len = ntohs(hh->len);
|
2010-03-24 07:40:55 +00:00
|
|
|
|
|
|
|
if (len < 0 || TS1_ALLOC_SIZE < len + sizeof(*hh)) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Can not read this packet. %d avail\n", len);
|
|
|
|
msgb_free(msg);
|
|
|
|
*error = -EIO;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-29 15:33:59 +00:00
|
|
|
ret = recv(bfd->fd, msg->l2h, len, 0);
|
|
|
|
if (ret < len) {
|
2010-03-24 07:40:55 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "short read! Got %d from %d\n", ret, len);
|
2009-02-15 11:57:29 +00:00
|
|
|
msgb_free(msg);
|
2009-08-18 08:05:45 +00:00
|
|
|
*error = -EIO;
|
|
|
|
return NULL;
|
2009-02-13 02:43:36 +00:00
|
|
|
}
|
|
|
|
msgb_put(msg, ret);
|
2009-08-18 08:05:45 +00:00
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2010-04-15 09:17:24 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
if (!bts || !bts->oml_link)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* send OML down */
|
|
|
|
ts = bts->oml_link->ts;
|
|
|
|
line = ts->line;
|
2010-04-11 16:54:58 +00:00
|
|
|
e1inp_event(ts, EVT_E1_TEI_DN, bts->oml_link->tei, bts->oml_link->sapi);
|
2010-04-15 09:17:24 +00:00
|
|
|
|
|
|
|
bfd = &ts->driver.ipaccess.fd;
|
|
|
|
bsc_unregister_fd(bfd);
|
|
|
|
close(bfd->fd);
|
|
|
|
bfd->fd = -1;
|
|
|
|
|
|
|
|
/* clean up OML and RSL */
|
|
|
|
e1inp_sign_link_destroy(bts->oml_link);
|
|
|
|
bts->oml_link = NULL;
|
|
|
|
bts->ip_access.flags = 0;
|
|
|
|
|
|
|
|
/* drop all RSL connections too */
|
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list)
|
|
|
|
ipaccess_drop_rsl(trx);
|
|
|
|
|
|
|
|
/* kill the E1 line now... as we have no one left to use it */
|
|
|
|
talloc_free(line);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipaccess_drop(struct e1inp_ts *ts, struct bsc_fd *bfd)
|
|
|
|
{
|
|
|
|
struct e1inp_sign_link *link;
|
|
|
|
int bts_nr;
|
|
|
|
|
|
|
|
if (!ts) {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bsc_unregister_fd(bfd);
|
|
|
|
close(bfd->fd);
|
|
|
|
bfd->fd = -1;
|
|
|
|
talloc_free(bfd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attempt to find a signalling link */
|
|
|
|
if (ts->type == E1INP_TS_TYPE_SIGN) {
|
|
|
|
llist_for_each_entry(link, &ts->sign.sign_links, list) {
|
|
|
|
bts_nr = link->trx->bts->bts_nr;
|
|
|
|
/* we have issues just reconnecting RLS so we drop OML */
|
|
|
|
ipaccess_drop_oml(link->trx->bts);
|
|
|
|
return bts_nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* error case */
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Failed to find a signalling link for ts: %p\n", ts);
|
|
|
|
bsc_unregister_fd(bfd);
|
|
|
|
close(bfd->fd);
|
|
|
|
bfd->fd = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ipaccess_drop_rsl(struct gsm_bts_trx *trx)
|
|
|
|
{
|
|
|
|
struct bsc_fd *bfd;
|
|
|
|
struct e1inp_ts *ts;
|
|
|
|
|
|
|
|
if (!trx || !trx->rsl_link)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* send RSL down */
|
|
|
|
ts = trx->rsl_link->ts;
|
2010-04-11 16:54:58 +00:00
|
|
|
e1inp_event(ts, EVT_E1_TEI_DN, trx->rsl_link->tei, trx->rsl_link->sapi);
|
2010-04-15 09:17:24 +00:00
|
|
|
|
|
|
|
/* close the socket */
|
|
|
|
bfd = &ts->driver.ipaccess.fd;
|
|
|
|
bsc_unregister_fd(bfd);
|
|
|
|
close(bfd->fd);
|
|
|
|
bfd->fd = -1;
|
|
|
|
|
|
|
|
/* destroy */
|
|
|
|
e1inp_sign_link_destroy(trx->rsl_link);
|
|
|
|
trx->rsl_link = NULL;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-18 08:05:45 +00:00
|
|
|
static int handle_ts1_read(struct bsc_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 *link;
|
|
|
|
struct msgb *msg;
|
|
|
|
struct ipaccess_head *hh;
|
2009-10-27 09:08:38 +00:00
|
|
|
int ret = 0, error;
|
2009-08-18 08:05:45 +00:00
|
|
|
|
|
|
|
msg = ipaccess_read_msg(bfd, &error);
|
|
|
|
if (!msg) {
|
|
|
|
if (error == 0) {
|
2010-04-15 09:17:24 +00:00
|
|
|
int ret = ipaccess_drop(e1i_ts, bfd);
|
|
|
|
if (ret >= 0)
|
2009-12-28 16:52:11 +00:00
|
|
|
LOGP(DINP, LOGL_NOTICE, "BTS %u disappeared, dead socket\n",
|
2010-04-15 09:17:24 +00:00
|
|
|
ret);
|
|
|
|
else
|
2009-12-28 16:52:11 +00:00
|
|
|
LOGP(DINP, LOGL_NOTICE, "unknown BTS disappeared, dead socket\n");
|
2009-08-18 08:05:45 +00:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2009-09-30 20:35:04 +00:00
|
|
|
DEBUGP(DMI, "RX %u: %s\n", ts_nr, hexdump(msgb_l2(msg), msgb_l2len(msg)));
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2009-08-18 08:05:45 +00:00
|
|
|
hh = (struct ipaccess_head *) msg->data;
|
2009-05-01 14:59:07 +00:00
|
|
|
if (hh->proto == IPAC_PROTO_IPACCESS) {
|
|
|
|
ret = ipaccess_rcvmsg(line, msg, bfd);
|
2010-04-15 09:17:24 +00:00
|
|
|
if (ret < 0)
|
|
|
|
ipaccess_drop(e1i_ts, bfd);
|
2009-05-01 14:59:07 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg()
|
|
|
|
* might have free'd it !!! */
|
|
|
|
|
2009-10-19 22:22:00 +00:00
|
|
|
link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
|
2009-02-13 02:43:36 +00:00
|
|
|
if (!link) {
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "no matching signalling link for "
|
|
|
|
"hh->proto=0x%02x\n", hh->proto);
|
2009-02-13 02:43:36 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
msg->trx = link->trx;
|
|
|
|
|
2009-10-19 22:22:00 +00:00
|
|
|
switch (link->type) {
|
|
|
|
case E1INP_SIGN_RSL:
|
2009-12-21 22:01:33 +00:00
|
|
|
if (!(msg->trx->bts->ip_access.flags & (RSL_UP << msg->trx->nr))) {
|
2009-10-21 19:16:00 +00:00
|
|
|
e1inp_event(e1i_ts, EVT_E1_TEI_UP, link->tei, link->sapi);
|
2009-12-21 22:01:33 +00:00
|
|
|
msg->trx->bts->ip_access.flags |= (RSL_UP << msg->trx->nr);
|
2009-10-21 19:16:00 +00:00
|
|
|
}
|
2009-02-13 02:43:36 +00:00
|
|
|
ret = abis_rsl_rcvmsg(msg);
|
|
|
|
break;
|
2009-10-19 22:22:00 +00:00
|
|
|
case E1INP_SIGN_OML:
|
2009-12-16 16:32:37 +00:00
|
|
|
if (!(msg->trx->bts->ip_access.flags & OML_UP)) {
|
2009-10-19 22:22:00 +00:00
|
|
|
e1inp_event(e1i_ts, EVT_E1_TEI_UP, link->tei, link->sapi);
|
2009-12-16 16:32:37 +00:00
|
|
|
msg->trx->bts->ip_access.flags |= OML_UP;
|
2009-02-15 03:39:51 +00:00
|
|
|
}
|
2009-02-13 02:43:36 +00:00
|
|
|
ret = abis_nm_rcvmsg(msg);
|
|
|
|
break;
|
|
|
|
default:
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_NOTICE, "Unknown IP.access protocol proto=0x%02x\n", hh->proto);
|
2009-02-13 02:43:36 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-18 08:05:45 +00:00
|
|
|
void ipaccess_prepend_header(struct msgb *msg, int proto)
|
|
|
|
{
|
|
|
|
struct ipaccess_head *hh;
|
|
|
|
|
|
|
|
/* prepend the ip.access header */
|
|
|
|
hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh));
|
2009-10-29 15:33:59 +00:00
|
|
|
hh->len = htons(msg->len - sizeof(*hh));
|
2009-08-18 08:05:45 +00:00
|
|
|
hh->proto = proto;
|
|
|
|
}
|
|
|
|
|
2009-10-08 10:53:16 +00:00
|
|
|
static int ts_want_write(struct e1inp_ts *e1i_ts)
|
|
|
|
{
|
|
|
|
e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void timeout_ts1_write(void *data)
|
|
|
|
{
|
|
|
|
struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
|
|
|
|
|
|
|
|
/* trigger write of ts1, due to tx delay timer */
|
|
|
|
ts_want_write(e1i_ts);
|
|
|
|
}
|
|
|
|
|
2009-02-13 02:43:36 +00:00
|
|
|
static int handle_ts1_write(struct bsc_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;
|
2009-08-18 08:05:45 +00:00
|
|
|
u_int8_t proto;
|
2009-02-13 02:43:36 +00:00
|
|
|
int ret;
|
|
|
|
|
2009-10-08 10:53:16 +00:00
|
|
|
bfd->when &= ~BSC_FD_WRITE;
|
|
|
|
|
2009-02-13 02:43:36 +00:00
|
|
|
/* get the next msg for this timeslot */
|
|
|
|
msg = e1inp_tx_ts(e1i_ts, &sign_link);
|
|
|
|
if (!msg) {
|
2009-10-08 10:53:16 +00:00
|
|
|
/* no message after tx delay timer */
|
2009-02-13 02:43:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sign_link->type) {
|
|
|
|
case E1INP_SIGN_OML:
|
2009-08-18 08:05:45 +00:00
|
|
|
proto = IPAC_PROTO_OML;
|
2009-02-13 02:43:36 +00:00
|
|
|
break;
|
|
|
|
case E1INP_SIGN_RSL:
|
2009-08-18 08:05:45 +00:00
|
|
|
proto = IPAC_PROTO_RSL;
|
2009-02-13 02:43:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msgb_free(msg);
|
2009-10-08 10:53:16 +00:00
|
|
|
bfd->when |= BSC_FD_WRITE; /* come back for more msg */
|
2009-02-13 02:43:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-18 08:05:45 +00:00
|
|
|
msg->l2h = msg->data;
|
2009-10-19 22:22:00 +00:00
|
|
|
ipaccess_prepend_header(msg, sign_link->tei);
|
2009-08-18 08:05:45 +00:00
|
|
|
|
|
|
|
DEBUGP(DMI, "TX %u: %s\n", ts_nr, hexdump(msg->l2h, msgb_l2len(msg)));
|
2009-02-13 02:43:36 +00:00
|
|
|
|
|
|
|
ret = send(bfd->fd, msg->data, msg->len, 0);
|
|
|
|
msgb_free(msg);
|
2009-10-08 10:53:16 +00:00
|
|
|
|
|
|
|
/* set tx delay timer for next event */
|
|
|
|
e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
|
|
|
|
e1i_ts->sign.tx_timer.data = e1i_ts;
|
2010-04-11 08:10:04 +00:00
|
|
|
|
|
|
|
/* Reducing this might break the nanoBTS 900 init. */
|
2010-04-26 08:02:04 +00:00
|
|
|
bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
|
2009-02-13 02:43:36 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct e1inp_line *line = bfd->data;
|
|
|
|
unsigned int ts_nr = bfd->priv_nr;
|
|
|
|
unsigned int idx = ts_nr-1;
|
2009-05-01 14:59:07 +00:00
|
|
|
struct e1inp_ts *e1i_ts;
|
2009-02-13 02:43:36 +00:00
|
|
|
int rc = 0;
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
/* In case of early RSL we might not yet have a line */
|
|
|
|
|
|
|
|
if (line)
|
|
|
|
e1i_ts = &line->ts[idx];
|
|
|
|
|
|
|
|
if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) {
|
2009-02-13 02:43:36 +00:00
|
|
|
if (what & BSC_FD_READ)
|
|
|
|
rc = handle_ts1_read(bfd);
|
|
|
|
if (what & BSC_FD_WRITE)
|
|
|
|
rc = handle_ts1_write(bfd);
|
2009-05-01 14:59:07 +00:00
|
|
|
} else
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type);
|
2009-02-13 02:43:36 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct e1inp_driver ipaccess_driver = {
|
|
|
|
.name = "ip.access",
|
|
|
|
.want_write = ts_want_write,
|
2010-11-15 19:36:21 +00:00
|
|
|
.default_delay = 0,
|
2009-02-13 02:43:36 +00:00
|
|
|
};
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
/* callback of the OML listening filedescriptor */
|
2009-02-13 02:43:36 +00:00
|
|
|
static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what)
|
|
|
|
{
|
|
|
|
int ret;
|
2009-05-01 14:59:07 +00:00
|
|
|
int idx = 0;
|
2010-03-24 10:20:27 +00:00
|
|
|
int i;
|
2009-05-01 14:59:07 +00:00
|
|
|
struct e1inp_line *line;
|
|
|
|
struct e1inp_ts *e1i_ts;
|
|
|
|
struct bsc_fd *bfd;
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
socklen_t sa_len = sizeof(sa);
|
|
|
|
|
|
|
|
if (!(what & BSC_FD_READ))
|
|
|
|
return 0;
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
ret = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len);
|
|
|
|
if (ret < 0) {
|
|
|
|
perror("accept");
|
|
|
|
return ret;
|
2009-02-13 02:43:36 +00:00
|
|
|
}
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_NOTICE, "accept()ed new OML link from %s\n",
|
|
|
|
inet_ntoa(sa.sin_addr));
|
2009-05-01 14:59:07 +00:00
|
|
|
|
2009-10-29 01:29:45 +00:00
|
|
|
line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
|
2009-05-01 14:59:07 +00:00
|
|
|
if (!line) {
|
|
|
|
close(ret);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
line->driver = &ipaccess_driver;
|
|
|
|
//line->driver_data = e1h;
|
|
|
|
/* create virrtual E1 timeslots for signalling */
|
|
|
|
e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
|
|
|
|
|
2010-03-24 10:20:27 +00:00
|
|
|
/* initialize the fds */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
|
|
|
|
line->ts[i].driver.ipaccess.fd.fd = -1;
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
e1i_ts = &line->ts[idx];
|
|
|
|
|
|
|
|
bfd = &e1i_ts->driver.ipaccess.fd;
|
|
|
|
bfd->fd = ret;
|
|
|
|
bfd->data = line;
|
2010-03-24 03:56:13 +00:00
|
|
|
bfd->priv_nr = PRIV_OML;
|
2009-05-01 14:59:07 +00:00
|
|
|
bfd->cb = ipaccess_fd_cb;
|
|
|
|
bfd->when = BSC_FD_READ;
|
|
|
|
ret = bsc_register_fd(bfd);
|
|
|
|
if (ret < 0) {
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "could not register FD\n");
|
2009-05-01 14:59:07 +00:00
|
|
|
close(bfd->fd);
|
2009-06-21 23:36:25 +00:00
|
|
|
talloc_free(line);
|
2009-05-01 14:59:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
|
2010-02-07 11:04:07 +00:00
|
|
|
ret = ipaccess_send_id_req(bfd->fd);
|
2009-05-01 14:59:07 +00:00
|
|
|
|
2009-08-10 05:59:27 +00:00
|
|
|
return ret;
|
2009-08-08 14:12:58 +00:00
|
|
|
//return e1inp_line_register(line);
|
2009-02-13 02:43:36 +00:00
|
|
|
}
|
|
|
|
|
2009-02-15 11:57:29 +00:00
|
|
|
static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what)
|
2009-02-13 02:43:36 +00:00
|
|
|
{
|
2009-05-01 14:59:07 +00:00
|
|
|
struct sockaddr_in sa;
|
|
|
|
socklen_t sa_len = sizeof(sa);
|
2009-06-21 23:36:25 +00:00
|
|
|
struct bsc_fd *bfd;
|
2009-02-15 11:57:29 +00:00
|
|
|
int ret;
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
if (!(what & BSC_FD_READ))
|
|
|
|
return 0;
|
|
|
|
|
2009-10-29 01:29:45 +00:00
|
|
|
bfd = talloc_zero(tall_bsc_ctx, struct bsc_fd);
|
2009-06-21 23:36:25 +00:00
|
|
|
if (!bfd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
/* Some BTS has connected to us, but we don't know yet which line
|
|
|
|
* (as created by the OML link) to associate it with. Thus, we
|
2009-11-15 12:50:39 +00:00
|
|
|
* allocate a temporary bfd until we have received ID from BTS */
|
2009-05-01 14:59:07 +00:00
|
|
|
|
|
|
|
bfd->fd = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len);
|
|
|
|
if (bfd->fd < 0) {
|
|
|
|
perror("accept");
|
|
|
|
return bfd->fd;
|
|
|
|
}
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_NOTICE, "accept()ed new RSL link from %s\n", inet_ntoa(sa.sin_addr));
|
2010-03-24 03:56:13 +00:00
|
|
|
bfd->priv_nr = PRIV_RSL;
|
2009-05-01 14:59:07 +00:00
|
|
|
bfd->cb = ipaccess_fd_cb;
|
|
|
|
bfd->when = BSC_FD_READ;
|
|
|
|
ret = bsc_register_fd(bfd);
|
|
|
|
if (ret < 0) {
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "could not register FD\n");
|
2009-05-01 14:59:07 +00:00
|
|
|
close(bfd->fd);
|
2009-06-21 23:36:25 +00:00
|
|
|
talloc_free(bfd);
|
2009-05-01 14:59:07 +00:00
|
|
|
return ret;
|
2009-02-15 11:57:29 +00:00
|
|
|
}
|
2009-05-01 14:59:07 +00:00
|
|
|
/* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
|
|
|
|
ret = write(bfd->fd, id_req, sizeof(id_req));
|
|
|
|
|
2009-02-15 11:57:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-02-13 02:43:36 +00:00
|
|
|
|
2009-04-30 15:53:07 +00:00
|
|
|
/* Actively connect to a BTS. Currently used by ipaccess-config.c */
|
|
|
|
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;
|
|
|
|
int ret, on = 1;
|
|
|
|
|
|
|
|
bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
bfd->cb = ipaccess_fd_cb;
|
|
|
|
bfd->when = BSC_FD_READ | BSC_FD_WRITE;
|
|
|
|
bfd->data = line;
|
2010-03-24 03:56:13 +00:00
|
|
|
bfd->priv_nr = PRIV_OML;
|
2009-04-30 15:53:07 +00:00
|
|
|
|
2010-02-19 12:07:05 +00:00
|
|
|
if (bfd->fd < 0) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "could not create TCP socket.\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2009-04-30 15:53:07 +00:00
|
|
|
setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
|
|
|
|
|
|
|
ret = connect(bfd->fd, (struct sockaddr *) sa, sizeof(*sa));
|
|
|
|
if (ret < 0) {
|
2009-12-23 22:01:04 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "could not connect socket\n");
|
2009-04-30 15:53:07 +00:00
|
|
|
close(bfd->fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = bsc_register_fd(bfd);
|
|
|
|
if (ret < 0) {
|
|
|
|
close(bfd->fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
line->driver = &ipaccess_driver;
|
|
|
|
|
2009-08-10 05:59:27 +00:00
|
|
|
return ret;
|
2009-08-08 14:12:58 +00:00
|
|
|
//return e1inp_line_register(line);
|
2009-04-30 15:53:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
int ipaccess_setup(struct gsm_network *gsmnet)
|
2009-02-15 11:57:29 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2009-10-29 01:29:45 +00:00
|
|
|
e1h = talloc_zero(tall_bsc_ctx, struct ia_e1_handle);
|
2009-06-21 23:36:25 +00:00
|
|
|
if (!e1h)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
e1h->gsmnet = gsmnet;
|
2009-02-15 11:57:29 +00:00
|
|
|
|
|
|
|
/* Listen for OML connections */
|
2010-05-19 12:38:50 +00:00
|
|
|
ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, 0, IPA_TCP_PORT_OML,
|
2010-03-14 07:45:01 +00:00
|
|
|
listen_fd_cb);
|
2009-05-01 15:43:49 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-02-15 11:57:29 +00:00
|
|
|
|
|
|
|
/* Listen for RSL connections */
|
2010-05-19 12:38:50 +00:00
|
|
|
ret = make_sock(&e1h->rsl_listen_fd, IPPROTO_TCP, 0,
|
2010-03-14 07:45:01 +00:00
|
|
|
IPA_TCP_PORT_RSL, rsl_listen_fd_cb);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2009-05-01 14:59:07 +00:00
|
|
|
return ret;
|
2009-02-13 02:43:36 +00:00
|
|
|
}
|