blob: d2572fb38e099b10176f5b684681c6ed9026fb92 [file] [log] [blame]
Harald Welte5fd8a542009-02-13 02:43:36 +00001/* OpenBSC Abis input driver for ip.access */
2
3/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +02004 * (C) 2010 by Holger Hans Peter Freyther
5 * (C) 2010 by On-Waves
Harald Welte5fd8a542009-02-13 02:43:36 +00006 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
Harald Welte5fd8a542009-02-13 02:43:36 +000012 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Harald Welte5fd8a542009-02-13 02:43:36 +000018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte5fd8a542009-02-13 02:43:36 +000021 *
22 */
23
24#include <stdio.h>
25#include <unistd.h>
26#include <stdlib.h>
27#include <errno.h>
28#include <string.h>
29#include <time.h>
30#include <sys/fcntl.h>
Harald Welte5fd8a542009-02-13 02:43:36 +000031#include <sys/socket.h>
32#include <sys/ioctl.h>
33#include <arpa/inet.h>
34
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010035#include <osmocom/core/select.h>
36#include <osmocom/gsm/tlv.h>
37#include <osmocom/core/msgb.h>
38#include <osmocom/core/talloc.h>
Harald Welte5fd8a542009-02-13 02:43:36 +000039#include <openbsc/debug.h>
40#include <openbsc/gsm_data.h>
41#include <openbsc/abis_nm.h>
42#include <openbsc/abis_rsl.h>
43#include <openbsc/subchan_demux.h>
44#include <openbsc/e1_input.h>
Harald Welte4f361fc2009-02-15 15:32:53 +000045#include <openbsc/ipaccess.h>
Harald Welte5540c4c2010-05-19 14:38:50 +020046#include <openbsc/socket.h>
Harald Weltef338a032011-01-14 15:55:42 +010047#include <openbsc/signal.h>
Harald Welte5fd8a542009-02-13 02:43:36 +000048
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +010049#define PRIV_OML 1
50#define PRIV_RSL 2
51
Harald Welte5fd8a542009-02-13 02:43:36 +000052/* data structure for one E1 interface with A-bis */
53struct ia_e1_handle {
54 struct bsc_fd listen_fd;
Harald Welte5c1e4582009-02-15 11:57:29 +000055 struct bsc_fd rsl_listen_fd;
Harald Welteedb37782009-05-01 14:59:07 +000056 struct gsm_network *gsmnet;
Harald Welte5fd8a542009-02-13 02:43:36 +000057};
58
Harald Welteedb37782009-05-01 14:59:07 +000059static struct ia_e1_handle *e1h;
60
61
Holger Hans Peter Freyther6c8c0dd2010-04-04 18:12:37 +020062#define TS1_ALLOC_SIZE 900
Harald Welte5fd8a542009-02-13 02:43:36 +000063
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +020064/*
65 * Common propietary IPA messages:
66 * - PONG: in reply to PING.
67 * - ID_REQUEST: first messages once OML has been established.
68 * - ID_ACK: in reply to ID_ACK.
69 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020070const uint8_t ipa_pong_msg[] = {
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +020071 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG
72};
73
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020074const uint8_t ipa_id_ack_msg[] = {
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +020075 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK
76};
77
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020078const uint8_t ipa_id_req_msg[] = {
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +020079 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
80 0x01, IPAC_IDTAG_UNIT,
81 0x01, IPAC_IDTAG_MACADDR,
82 0x01, IPAC_IDTAG_LOCATION1,
83 0x01, IPAC_IDTAG_LOCATION2,
84 0x01, IPAC_IDTAG_EQUIPVERS,
85 0x01, IPAC_IDTAG_SWVERSION,
86 0x01, IPAC_IDTAG_UNITNAME,
87 0x01, IPAC_IDTAG_SERNR,
88};
Harald Welte5fd8a542009-02-13 02:43:36 +000089
Harald Welteedb37782009-05-01 14:59:07 +000090static const char *idtag_names[] = {
91 [IPAC_IDTAG_SERNR] = "Serial_Number",
92 [IPAC_IDTAG_UNITNAME] = "Unit_Name",
93 [IPAC_IDTAG_LOCATION1] = "Location_1",
94 [IPAC_IDTAG_LOCATION2] = "Location_2",
95 [IPAC_IDTAG_EQUIPVERS] = "Equipment_Version",
96 [IPAC_IDTAG_SWVERSION] = "Software_Version",
97 [IPAC_IDTAG_IPADDR] = "IP_Address",
98 [IPAC_IDTAG_MACADDR] = "MAC_Address",
99 [IPAC_IDTAG_UNIT] = "Unit_ID",
100};
101
Pablo Neira Ayuso0d20b632011-04-11 16:32:47 +0200102const char *ipaccess_idtag_name(uint8_t tag)
Harald Welte5fd8a542009-02-13 02:43:36 +0000103{
Harald Welteedb37782009-05-01 14:59:07 +0000104 if (tag >= ARRAY_SIZE(idtag_names))
105 return "unknown";
106
107 return idtag_names[tag];
108}
109
Holger Hans Peter Freytherd3d5be12010-02-09 14:37:23 +0100110int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len)
Harald Welteedb37782009-05-01 14:59:07 +0000111{
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200112 uint8_t t_len;
113 uint8_t t_tag;
114 uint8_t *cur = buf;
Harald Welteedb37782009-05-01 14:59:07 +0000115
Holger Hans Peter Freyther949e0ba2010-10-14 17:21:04 +0200116 memset(dec, 0, sizeof(*dec));
117
Holger Hans Peter Freytherd9e81d02010-10-14 20:42:45 +0200118 while (len >= 2) {
119 len -= 2;
Harald Welteedb37782009-05-01 14:59:07 +0000120 t_len = *cur++;
121 t_tag = *cur++;
122
Holger Hans Peter Freytherd9e81d02010-10-14 20:42:45 +0200123 if (t_len > len + 1) {
124 LOGP(DMI, LOGL_ERROR, "The tag does not fit: %d\n", t_len);
Pablo Neira Ayusoca05d432011-04-11 16:32:50 +0200125 return -EINVAL;
Holger Hans Peter Freytherd9e81d02010-10-14 20:42:45 +0200126 }
127
Pablo Neira Ayuso66add642011-04-07 14:15:11 +0200128 DEBUGPC(DMI, "%s='%s' ", ipaccess_idtag_name(t_tag), cur);
Harald Welteedb37782009-05-01 14:59:07 +0000129
130 dec->lv[t_tag].len = t_len;
131 dec->lv[t_tag].val = cur;
132
133 cur += t_len;
Holger Hans Peter Freytherd9e81d02010-10-14 20:42:45 +0200134 len -= t_len;
Harald Welteedb37782009-05-01 14:59:07 +0000135 }
136 return 0;
137}
138
139struct gsm_bts *find_bts_by_unitid(struct gsm_network *net,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200140 uint16_t site_id, uint16_t bts_id)
Harald Welteedb37782009-05-01 14:59:07 +0000141{
Harald Weltee441d9c2009-06-21 16:17:15 +0200142 struct gsm_bts *bts;
Harald Welteedb37782009-05-01 14:59:07 +0000143
Harald Weltee441d9c2009-06-21 16:17:15 +0200144 llist_for_each_entry(bts, &net->bts_list, list) {
Harald Welteedb37782009-05-01 14:59:07 +0000145
146 if (!is_ipaccess_bts(bts))
147 continue;
148
149 if (bts->ip_access.site_id == site_id &&
150 bts->ip_access.bts_id == bts_id)
151 return bts;
152 }
153
154 return NULL;
155}
156
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200157int ipaccess_parse_unitid(const char *str, uint16_t *site_id,
158 uint16_t *bts_id, uint16_t *trx_id)
Harald Welteedb37782009-05-01 14:59:07 +0000159{
160 unsigned long ul;
161 char *endptr;
162 const char *nptr;
163
164 nptr = str;
165 ul = strtoul(nptr, &endptr, 10);
166 if (endptr <= nptr)
167 return -EINVAL;
168 if (site_id)
169 *site_id = ul & 0xffff;
170
171 if (*endptr++ != '/')
172 return -EINVAL;
173
174 nptr = endptr;
175 ul = strtoul(nptr, &endptr, 10);
176 if (endptr <= nptr)
177 return -EINVAL;
178 if (bts_id)
179 *bts_id = ul & 0xffff;
180
181 if (*endptr++ != '/')
182 return -EINVAL;
183
184 nptr = endptr;
185 ul = strtoul(nptr, &endptr, 10);
186 if (endptr <= nptr)
187 return -EINVAL;
188 if (trx_id)
189 *trx_id = ul & 0xffff;
190
191 return 0;
192}
193
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +0200194static int ipaccess_send(int fd, const void *msg, size_t msglen)
195{
196 int ret;
197
198 ret = write(fd, msg, msglen);
199 if (ret < 0)
200 return ret;
201 if (ret < msglen) {
Pablo Neira Ayuso91afbbc2011-04-11 16:32:53 +0200202 LOGP(DINP, LOGL_ERROR, "ipaccess_send: short write\n");
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +0200203 return -EIO;
204 }
205 return ret;
206}
207
208int ipaccess_send_pong(int fd)
209{
210 return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg));
211}
212
Holger Hans Peter Freyther301e6282010-01-13 09:06:46 +0100213int ipaccess_send_id_ack(int fd)
214{
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +0200215 return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg));
Holger Hans Peter Freyther301e6282010-01-13 09:06:46 +0100216}
217
Holger Hans Peter Freyther3bc856b2010-02-07 12:04:07 +0100218int ipaccess_send_id_req(int fd)
219{
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +0200220 return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg));
Holger Hans Peter Freyther3bc856b2010-02-07 12:04:07 +0100221}
222
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200223/* base handling of the ip.access protocol */
224int ipaccess_rcvmsg_base(struct msgb *msg,
225 struct bsc_fd *bfd)
Harald Welteedb37782009-05-01 14:59:07 +0000226{
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200227 uint8_t msg_type = *(msg->l2h);
Holger Freytherff9592f2009-03-09 16:17:14 +0000228 int ret = 0;
Harald Welte5fd8a542009-02-13 02:43:36 +0000229
Harald Welte5fd8a542009-02-13 02:43:36 +0000230 switch (msg_type) {
Harald Welte4f361fc2009-02-15 15:32:53 +0000231 case IPAC_MSGT_PING:
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +0200232 ret = ipaccess_send_pong(bfd->fd);
Harald Welte5fd8a542009-02-13 02:43:36 +0000233 break;
Harald Welte4f361fc2009-02-15 15:32:53 +0000234 case IPAC_MSGT_PONG:
Harald Welte5fd8a542009-02-13 02:43:36 +0000235 DEBUGP(DMI, "PONG!\n");
236 break;
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200237 case IPAC_MSGT_ID_ACK:
238 DEBUGP(DMI, "ID_ACK? -> ACK!\n");
Holger Hans Peter Freyther301e6282010-01-13 09:06:46 +0100239 ret = ipaccess_send_id_ack(bfd->fd);
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200240 break;
241 }
242 return 0;
243}
244
245static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg,
246 struct bsc_fd *bfd)
247{
248 struct tlv_parsed tlvp;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200249 uint8_t msg_type = *(msg->l2h);
250 uint16_t site_id = 0, bts_id = 0, trx_id = 0;
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200251 struct gsm_bts *bts;
Holger Hans Peter Freythere3839802010-10-14 21:17:30 +0200252 char *unitid;
Pablo Neira Ayusoca05d432011-04-11 16:32:50 +0200253 int len, ret;
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200254
255 /* handle base messages */
256 ipaccess_rcvmsg_base(msg, bfd);
257
258 switch (msg_type) {
Harald Welte4f361fc2009-02-15 15:32:53 +0000259 case IPAC_MSGT_ID_RESP:
Harald Welteedb37782009-05-01 14:59:07 +0000260 DEBUGP(DMI, "ID_RESP ");
261 /* parse tags, search for Unit ID */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200262 ret = ipaccess_idtag_parse(&tlvp, (uint8_t *)msg->l2h + 2,
Pablo Neira Ayusoca05d432011-04-11 16:32:50 +0200263 msgb_l2len(msg)-2);
Harald Welteedb37782009-05-01 14:59:07 +0000264 DEBUGP(DMI, "\n");
Pablo Neira Ayusoca05d432011-04-11 16:32:50 +0200265 if (ret < 0) {
266 LOGP(DINP, LOGL_ERROR, "ignoring IPA response message "
267 "with malformed TLVs\n");
268 return ret;
269 }
Harald Welteedb37782009-05-01 14:59:07 +0000270 if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT))
271 break;
272
Holger Hans Peter Freythere3839802010-10-14 21:17:30 +0200273 len = TLVP_LEN(&tlvp, IPAC_IDTAG_UNIT);
274 if (len < 1)
275 break;
276
Harald Welteedb37782009-05-01 14:59:07 +0000277 /* lookup BTS, create sign_link, ... */
Holger Hans Peter Freythere3839802010-10-14 21:17:30 +0200278 unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT);
279 unitid[len - 1] = '\0';
Pablo Neira Ayusoc281b4e2011-04-07 14:15:20 +0200280 ipaccess_parse_unitid(unitid, &site_id, &bts_id, &trx_id);
Harald Welteedb37782009-05-01 14:59:07 +0000281 bts = find_bts_by_unitid(e1h->gsmnet, site_id, bts_id);
282 if (!bts) {
Harald Welteafdca0f2009-12-23 23:01:04 +0100283 LOGP(DINP, LOGL_ERROR, "Unable to find BTS configuration for "
Harald Welteedb37782009-05-01 14:59:07 +0000284 " %u/%u/%u, disconnecting\n", site_id, bts_id,
285 trx_id);
286 return -EIO;
287 }
288 DEBUGP(DINP, "Identified BTS %u/%u/%u\n", site_id, bts_id, trx_id);
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100289 if (bfd->priv_nr == PRIV_OML) {
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200290 /* drop any old oml connection */
291 ipaccess_drop_oml(bts);
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100292 bts->oml_link = e1inp_sign_link_create(&line->ts[PRIV_OML - 1],
Harald Welteedb37782009-05-01 14:59:07 +0000293 E1INP_SIGN_OML, bts->c0,
Harald Welte8175e952009-10-20 00:22:00 +0200294 bts->oml_tei, 0);
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100295 } else if (bfd->priv_nr == PRIV_RSL) {
Harald Welteedb37782009-05-01 14:59:07 +0000296 struct e1inp_ts *e1i_ts;
297 struct bsc_fd *newbfd;
Harald Welte8175e952009-10-20 00:22:00 +0200298 struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, trx_id);
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200299
300 /* drop any old rsl connection */
301 ipaccess_drop_rsl(trx);
302
303 if (!bts->oml_link) {
304 bsc_unregister_fd(bfd);
305 close(bfd->fd);
306 bfd->fd = -1;
307 talloc_free(bfd);
308 return 0;
309 }
310
Harald Welteedb37782009-05-01 14:59:07 +0000311 bfd->data = line = bts->oml_link->ts->line;
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100312 e1i_ts = &line->ts[PRIV_RSL + trx_id - 1];
Harald Welteedb37782009-05-01 14:59:07 +0000313 newbfd = &e1i_ts->driver.ipaccess.fd;
Harald Welte8175e952009-10-20 00:22:00 +0200314 e1inp_ts_config(e1i_ts, line, E1INP_TS_TYPE_SIGN);
Harald Welteedb37782009-05-01 14:59:07 +0000315
Harald Welte8175e952009-10-20 00:22:00 +0200316 trx->rsl_link = e1inp_sign_link_create(e1i_ts,
317 E1INP_SIGN_RSL, trx,
318 trx->rsl_tei, 0);
Holger Hans Peter Freytherd49fc5a2010-11-15 20:36:21 +0100319 trx->rsl_link->ts->sign.delay = 0;
Holger Hans Peter Freyther354ef812010-03-24 04:02:55 +0100320
Harald Welteedb37782009-05-01 14:59:07 +0000321 /* get rid of our old temporary bfd */
322 memcpy(newbfd, bfd, sizeof(*newbfd));
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100323 newbfd->priv_nr = PRIV_RSL + trx_id;
Harald Welteedb37782009-05-01 14:59:07 +0000324 bsc_unregister_fd(bfd);
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200325 bfd->fd = -1;
Harald Weltea4ffea92009-06-22 01:36:25 +0200326 talloc_free(bfd);
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200327 bsc_register_fd(newbfd);
Harald Welteedb37782009-05-01 14:59:07 +0000328 }
Harald Welte5fd8a542009-02-13 02:43:36 +0000329 break;
Harald Welte5fd8a542009-02-13 02:43:36 +0000330 }
Harald Welte5fd8a542009-02-13 02:43:36 +0000331 return 0;
332}
333
Harald Welte88a412a2009-12-16 17:32:37 +0100334#define OML_UP 0x0001
335#define RSL_UP 0x0002
Harald Welte7782c142009-02-15 03:39:51 +0000336
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200337/*
338 * read one ipa message from the socket
339 * return NULL in case of error
340 */
341struct msgb *ipaccess_read_msg(struct bsc_fd *bfd, int *error)
Harald Welte5fd8a542009-02-13 02:43:36 +0000342{
Harald Welte966636f2009-06-26 19:39:35 +0200343 struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "Abis/IP");
Harald Welte5fd8a542009-02-13 02:43:36 +0000344 struct ipaccess_head *hh;
Sylvain Munautd7d1c992009-10-29 16:33:59 +0100345 int len, ret = 0;
Harald Welte5fd8a542009-02-13 02:43:36 +0000346
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200347 if (!msg) {
348 *error = -ENOMEM;
349 return NULL;
350 }
Harald Welte5fd8a542009-02-13 02:43:36 +0000351
352 /* first read our 3-byte header */
353 hh = (struct ipaccess_head *) msg->data;
Holger Hans Peter Freytherb3121c52010-03-24 08:40:55 +0100354 ret = recv(bfd->fd, msg->data, sizeof(*hh), 0);
355 if (ret == 0) {
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200356 msgb_free(msg);
357 *error = ret;
358 return NULL;
Holger Hans Peter Freytherb3121c52010-03-24 08:40:55 +0100359 } else if (ret != sizeof(*hh)) {
360 if (errno != EAGAIN)
361 LOGP(DINP, LOGL_ERROR, "recv error %d %s\n", ret, strerror(errno));
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200362 msgb_free(msg);
363 *error = ret;
364 return NULL;
Harald Welte5fd8a542009-02-13 02:43:36 +0000365 }
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200366
Harald Welte5fd8a542009-02-13 02:43:36 +0000367 msgb_put(msg, ret);
368
369 /* then read te length as specified in header */
370 msg->l2h = msg->data + sizeof(*hh);
Sylvain Munautd7d1c992009-10-29 16:33:59 +0100371 len = ntohs(hh->len);
Holger Hans Peter Freytherb3121c52010-03-24 08:40:55 +0100372
373 if (len < 0 || TS1_ALLOC_SIZE < len + sizeof(*hh)) {
374 LOGP(DINP, LOGL_ERROR, "Can not read this packet. %d avail\n", len);
375 msgb_free(msg);
376 *error = -EIO;
377 return NULL;
378 }
379
Sylvain Munautd7d1c992009-10-29 16:33:59 +0100380 ret = recv(bfd->fd, msg->l2h, len, 0);
381 if (ret < len) {
Holger Hans Peter Freytherb3121c52010-03-24 08:40:55 +0100382 LOGP(DINP, LOGL_ERROR, "short read! Got %d from %d\n", ret, len);
Harald Welte5c1e4582009-02-15 11:57:29 +0000383 msgb_free(msg);
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200384 *error = -EIO;
385 return NULL;
Harald Welte5fd8a542009-02-13 02:43:36 +0000386 }
387 msgb_put(msg, ret);
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200388
389 return msg;
390}
391
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200392int ipaccess_drop_oml(struct gsm_bts *bts)
393{
394 struct gsm_bts_trx *trx;
395 struct e1inp_ts *ts;
396 struct e1inp_line *line;
397 struct bsc_fd *bfd;
398
399 if (!bts || !bts->oml_link)
400 return -1;
401
402 /* send OML down */
403 ts = bts->oml_link->ts;
404 line = ts->line;
Harald Weltef338a032011-01-14 15:55:42 +0100405 e1inp_event(ts, S_INP_TEI_DN, bts->oml_link->tei, bts->oml_link->sapi);
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200406
407 bfd = &ts->driver.ipaccess.fd;
408 bsc_unregister_fd(bfd);
409 close(bfd->fd);
410 bfd->fd = -1;
411
412 /* clean up OML and RSL */
413 e1inp_sign_link_destroy(bts->oml_link);
414 bts->oml_link = NULL;
415 bts->ip_access.flags = 0;
416
417 /* drop all RSL connections too */
418 llist_for_each_entry(trx, &bts->trx_list, list)
419 ipaccess_drop_rsl(trx);
420
421 /* kill the E1 line now... as we have no one left to use it */
422 talloc_free(line);
423
424 return -1;
425}
426
427static int ipaccess_drop(struct e1inp_ts *ts, struct bsc_fd *bfd)
428{
429 struct e1inp_sign_link *link;
430 int bts_nr;
431
432 if (!ts) {
433 /*
434 * If we don't have a TS this means that this is a RSL
435 * connection but we are not past the authentication
436 * handling yet. So we can safely delete this bfd and
437 * wait for a reconnect.
438 */
439 bsc_unregister_fd(bfd);
440 close(bfd->fd);
441 bfd->fd = -1;
442 talloc_free(bfd);
443 return -1;
444 }
445
446 /* attempt to find a signalling link */
447 if (ts->type == E1INP_TS_TYPE_SIGN) {
448 llist_for_each_entry(link, &ts->sign.sign_links, list) {
449 bts_nr = link->trx->bts->bts_nr;
450 /* we have issues just reconnecting RLS so we drop OML */
451 ipaccess_drop_oml(link->trx->bts);
452 return bts_nr;
453 }
454 }
455
456 /* error case */
457 LOGP(DINP, LOGL_ERROR, "Failed to find a signalling link for ts: %p\n", ts);
458 bsc_unregister_fd(bfd);
459 close(bfd->fd);
460 bfd->fd = -1;
461 return -1;
462}
463
464int ipaccess_drop_rsl(struct gsm_bts_trx *trx)
465{
466 struct bsc_fd *bfd;
467 struct e1inp_ts *ts;
468
469 if (!trx || !trx->rsl_link)
470 return -1;
471
472 /* send RSL down */
473 ts = trx->rsl_link->ts;
Harald Weltef338a032011-01-14 15:55:42 +0100474 e1inp_event(ts, S_INP_TEI_DN, trx->rsl_link->tei, trx->rsl_link->sapi);
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200475
476 /* close the socket */
477 bfd = &ts->driver.ipaccess.fd;
478 bsc_unregister_fd(bfd);
479 close(bfd->fd);
480 bfd->fd = -1;
481
482 /* destroy */
483 e1inp_sign_link_destroy(trx->rsl_link);
484 trx->rsl_link = NULL;
485
486 return -1;
487}
488
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200489static int handle_ts1_read(struct bsc_fd *bfd)
490{
491 struct e1inp_line *line = bfd->data;
492 unsigned int ts_nr = bfd->priv_nr;
493 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
494 struct e1inp_sign_link *link;
495 struct msgb *msg;
496 struct ipaccess_head *hh;
Holger Hans Peter Freyther67b59612009-10-27 10:08:38 +0100497 int ret = 0, error;
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200498
499 msg = ipaccess_read_msg(bfd, &error);
500 if (!msg) {
501 if (error == 0) {
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200502 int ret = ipaccess_drop(e1i_ts, bfd);
503 if (ret >= 0)
Harald Welte (local)7971d3d2009-12-28 17:52:11 +0100504 LOGP(DINP, LOGL_NOTICE, "BTS %u disappeared, dead socket\n",
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200505 ret);
506 else
Harald Welte (local)7971d3d2009-12-28 17:52:11 +0100507 LOGP(DINP, LOGL_NOTICE, "unknown BTS disappeared, dead socket\n");
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200508 }
509 return error;
510 }
511
Sylvain Munaut86538c72009-09-30 22:35:04 +0200512 DEBUGP(DMI, "RX %u: %s\n", ts_nr, hexdump(msgb_l2(msg), msgb_l2len(msg)));
Harald Welte5fd8a542009-02-13 02:43:36 +0000513
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200514 hh = (struct ipaccess_head *) msg->data;
Harald Welteedb37782009-05-01 14:59:07 +0000515 if (hh->proto == IPAC_PROTO_IPACCESS) {
516 ret = ipaccess_rcvmsg(line, msg, bfd);
Holger Hans Peter Freyther70402a42010-04-15 11:17:24 +0200517 if (ret < 0)
518 ipaccess_drop(e1i_ts, bfd);
Harald Welteedb37782009-05-01 14:59:07 +0000519 msgb_free(msg);
520 return ret;
521 }
522 /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg()
523 * might have free'd it !!! */
524
Harald Welte8175e952009-10-20 00:22:00 +0200525 link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
Harald Welte5fd8a542009-02-13 02:43:36 +0000526 if (!link) {
Harald Welteafdca0f2009-12-23 23:01:04 +0100527 LOGP(DINP, LOGL_ERROR, "no matching signalling link for "
528 "hh->proto=0x%02x\n", hh->proto);
Harald Welte5fd8a542009-02-13 02:43:36 +0000529 msgb_free(msg);
530 return -EIO;
531 }
532 msg->trx = link->trx;
533
Harald Welte8175e952009-10-20 00:22:00 +0200534 switch (link->type) {
535 case E1INP_SIGN_RSL:
Harald Welte1394fea2009-12-21 23:01:33 +0100536 if (!(msg->trx->bts->ip_access.flags & (RSL_UP << msg->trx->nr))) {
Harald Weltef338a032011-01-14 15:55:42 +0100537 e1inp_event(e1i_ts, S_INP_TEI_UP, link->tei, link->sapi);
Harald Welte1394fea2009-12-21 23:01:33 +0100538 msg->trx->bts->ip_access.flags |= (RSL_UP << msg->trx->nr);
Harald Weltee73501a2009-10-21 21:16:00 +0200539 }
Harald Welte5fd8a542009-02-13 02:43:36 +0000540 ret = abis_rsl_rcvmsg(msg);
541 break;
Harald Welte8175e952009-10-20 00:22:00 +0200542 case E1INP_SIGN_OML:
Harald Welte88a412a2009-12-16 17:32:37 +0100543 if (!(msg->trx->bts->ip_access.flags & OML_UP)) {
Harald Weltef338a032011-01-14 15:55:42 +0100544 e1inp_event(e1i_ts, S_INP_TEI_UP, link->tei, link->sapi);
Harald Welte88a412a2009-12-16 17:32:37 +0100545 msg->trx->bts->ip_access.flags |= OML_UP;
Harald Welte7782c142009-02-15 03:39:51 +0000546 }
Harald Welte5fd8a542009-02-13 02:43:36 +0000547 ret = abis_nm_rcvmsg(msg);
548 break;
549 default:
Harald Welteafdca0f2009-12-23 23:01:04 +0100550 LOGP(DINP, LOGL_NOTICE, "Unknown IP.access protocol proto=0x%02x\n", hh->proto);
Harald Welte5fd8a542009-02-13 02:43:36 +0000551 msgb_free(msg);
552 break;
553 }
554 return ret;
555}
556
Holger Hans Peter Freyther5d7b65b2011-04-07 23:31:58 +0200557void ipaccess_prepend_header_ext(struct msgb *msg, int proto)
558{
559 struct ipaccess_head_ext *hh_ext;
560
561 /* prepend the osmo ip.access header extension */
562 hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext));
563 hh_ext->proto = proto;
564}
565
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200566void ipaccess_prepend_header(struct msgb *msg, int proto)
567{
568 struct ipaccess_head *hh;
569
570 /* prepend the ip.access header */
571 hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh));
Sylvain Munautd7d1c992009-10-29 16:33:59 +0100572 hh->len = htons(msg->len - sizeof(*hh));
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200573 hh->proto = proto;
574}
575
Andreas Eversberg38ae5cb2009-10-08 12:53:16 +0200576static int ts_want_write(struct e1inp_ts *e1i_ts)
577{
578 e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE;
579
580 return 0;
581}
582
583static void timeout_ts1_write(void *data)
584{
585 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
586
587 /* trigger write of ts1, due to tx delay timer */
588 ts_want_write(e1i_ts);
589}
590
Harald Welte5fd8a542009-02-13 02:43:36 +0000591static int handle_ts1_write(struct bsc_fd *bfd)
592{
593 struct e1inp_line *line = bfd->data;
594 unsigned int ts_nr = bfd->priv_nr;
595 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
596 struct e1inp_sign_link *sign_link;
597 struct msgb *msg;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200598 uint8_t proto;
Harald Welte5fd8a542009-02-13 02:43:36 +0000599 int ret;
600
Andreas Eversberg38ae5cb2009-10-08 12:53:16 +0200601 bfd->when &= ~BSC_FD_WRITE;
602
Harald Welte5fd8a542009-02-13 02:43:36 +0000603 /* get the next msg for this timeslot */
604 msg = e1inp_tx_ts(e1i_ts, &sign_link);
605 if (!msg) {
Andreas Eversberg38ae5cb2009-10-08 12:53:16 +0200606 /* no message after tx delay timer */
Harald Welte5fd8a542009-02-13 02:43:36 +0000607 return 0;
608 }
609
Harald Welte5fd8a542009-02-13 02:43:36 +0000610 switch (sign_link->type) {
611 case E1INP_SIGN_OML:
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200612 proto = IPAC_PROTO_OML;
Harald Welte5fd8a542009-02-13 02:43:36 +0000613 break;
614 case E1INP_SIGN_RSL:
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200615 proto = IPAC_PROTO_RSL;
Harald Welte5fd8a542009-02-13 02:43:36 +0000616 break;
617 default:
618 msgb_free(msg);
Andreas Eversberg38ae5cb2009-10-08 12:53:16 +0200619 bfd->when |= BSC_FD_WRITE; /* come back for more msg */
Harald Welte5fd8a542009-02-13 02:43:36 +0000620 return -EINVAL;
621 }
622
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200623 msg->l2h = msg->data;
Harald Welte8175e952009-10-20 00:22:00 +0200624 ipaccess_prepend_header(msg, sign_link->tei);
Holger Hans Peter Freytherd5f05222009-08-18 10:05:45 +0200625
626 DEBUGP(DMI, "TX %u: %s\n", ts_nr, hexdump(msg->l2h, msgb_l2len(msg)));
Harald Welte5fd8a542009-02-13 02:43:36 +0000627
628 ret = send(bfd->fd, msg->data, msg->len, 0);
629 msgb_free(msg);
Andreas Eversberg38ae5cb2009-10-08 12:53:16 +0200630
631 /* set tx delay timer for next event */
632 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
633 e1i_ts->sign.tx_timer.data = e1i_ts;
Holger Hans Peter Freyther63cb4472010-04-11 10:10:04 +0200634
635 /* Reducing this might break the nanoBTS 900 init. */
Holger Hans Peter Freytherd85642a2010-04-26 16:02:04 +0800636 bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
Harald Welte5fd8a542009-02-13 02:43:36 +0000637
638 return ret;
639}
640
Harald Welte5fd8a542009-02-13 02:43:36 +0000641/* callback from select.c in case one of the fd's can be read/written */
642static int ipaccess_fd_cb(struct bsc_fd *bfd, unsigned int what)
643{
644 struct e1inp_line *line = bfd->data;
645 unsigned int ts_nr = bfd->priv_nr;
646 unsigned int idx = ts_nr-1;
Harald Welteedb37782009-05-01 14:59:07 +0000647 struct e1inp_ts *e1i_ts;
Harald Welte5fd8a542009-02-13 02:43:36 +0000648 int rc = 0;
649
Harald Welteedb37782009-05-01 14:59:07 +0000650 /* In case of early RSL we might not yet have a line */
651
652 if (line)
653 e1i_ts = &line->ts[idx];
654
655 if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) {
Harald Welte5fd8a542009-02-13 02:43:36 +0000656 if (what & BSC_FD_READ)
657 rc = handle_ts1_read(bfd);
658 if (what & BSC_FD_WRITE)
659 rc = handle_ts1_write(bfd);
Harald Welteedb37782009-05-01 14:59:07 +0000660 } else
Harald Welteafdca0f2009-12-23 23:01:04 +0100661 LOGP(DINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type);
Harald Welte5fd8a542009-02-13 02:43:36 +0000662
663 return rc;
664}
665
Harald Welte5fd8a542009-02-13 02:43:36 +0000666struct e1inp_driver ipaccess_driver = {
667 .name = "ip.access",
668 .want_write = ts_want_write,
Holger Hans Peter Freytherd49fc5a2010-11-15 20:36:21 +0100669 .default_delay = 0,
Harald Welte5fd8a542009-02-13 02:43:36 +0000670};
671
Harald Welteedb37782009-05-01 14:59:07 +0000672/* callback of the OML listening filedescriptor */
Harald Welte5fd8a542009-02-13 02:43:36 +0000673static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what)
674{
Harald Welte5fd8a542009-02-13 02:43:36 +0000675 int ret;
Harald Welteedb37782009-05-01 14:59:07 +0000676 int idx = 0;
Holger Hans Peter Freytheredee7942010-03-24 11:20:27 +0100677 int i;
Harald Welteedb37782009-05-01 14:59:07 +0000678 struct e1inp_line *line;
679 struct e1inp_ts *e1i_ts;
680 struct bsc_fd *bfd;
681 struct sockaddr_in sa;
682 socklen_t sa_len = sizeof(sa);
Harald Welte5fd8a542009-02-13 02:43:36 +0000683
Harald Welteedb37782009-05-01 14:59:07 +0000684 if (!(what & BSC_FD_READ))
685 return 0;
Harald Welte5fd8a542009-02-13 02:43:36 +0000686
Harald Welteedb37782009-05-01 14:59:07 +0000687 ret = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len);
688 if (ret < 0) {
689 perror("accept");
690 return ret;
Harald Welte5fd8a542009-02-13 02:43:36 +0000691 }
Harald Welteafdca0f2009-12-23 23:01:04 +0100692 LOGP(DINP, LOGL_NOTICE, "accept()ed new OML link from %s\n",
693 inet_ntoa(sa.sin_addr));
Harald Welteedb37782009-05-01 14:59:07 +0000694
Holger Hans Peter Freyther5ea73132009-10-29 02:29:45 +0100695 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welteedb37782009-05-01 14:59:07 +0000696 if (!line) {
697 close(ret);
698 return -ENOMEM;
699 }
Harald Welteedb37782009-05-01 14:59:07 +0000700 line->driver = &ipaccess_driver;
701 //line->driver_data = e1h;
702 /* create virrtual E1 timeslots for signalling */
703 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
Harald Welteedb37782009-05-01 14:59:07 +0000704
Holger Hans Peter Freytheredee7942010-03-24 11:20:27 +0100705 /* initialize the fds */
706 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
707 line->ts[i].driver.ipaccess.fd.fd = -1;
708
Harald Welteedb37782009-05-01 14:59:07 +0000709 e1i_ts = &line->ts[idx];
710
711 bfd = &e1i_ts->driver.ipaccess.fd;
712 bfd->fd = ret;
713 bfd->data = line;
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100714 bfd->priv_nr = PRIV_OML;
Harald Welteedb37782009-05-01 14:59:07 +0000715 bfd->cb = ipaccess_fd_cb;
716 bfd->when = BSC_FD_READ;
717 ret = bsc_register_fd(bfd);
718 if (ret < 0) {
Harald Welteafdca0f2009-12-23 23:01:04 +0100719 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
Harald Welteedb37782009-05-01 14:59:07 +0000720 close(bfd->fd);
Harald Weltea4ffea92009-06-22 01:36:25 +0200721 talloc_free(line);
Harald Welteedb37782009-05-01 14:59:07 +0000722 return ret;
723 }
724
725 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
Holger Hans Peter Freyther3bc856b2010-02-07 12:04:07 +0100726 ret = ipaccess_send_id_req(bfd->fd);
Harald Welteedb37782009-05-01 14:59:07 +0000727
Holger Hans Peter Freyther09e364b2009-08-10 07:59:27 +0200728 return ret;
Harald Welte42581822009-08-08 16:12:58 +0200729 //return e1inp_line_register(line);
Harald Welte5fd8a542009-02-13 02:43:36 +0000730}
731
Harald Welte5c1e4582009-02-15 11:57:29 +0000732static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what)
733{
Harald Welteedb37782009-05-01 14:59:07 +0000734 struct sockaddr_in sa;
735 socklen_t sa_len = sizeof(sa);
Harald Weltea4ffea92009-06-22 01:36:25 +0200736 struct bsc_fd *bfd;
Harald Welte5c1e4582009-02-15 11:57:29 +0000737 int ret;
738
Harald Welteedb37782009-05-01 14:59:07 +0000739 if (!(what & BSC_FD_READ))
740 return 0;
Harald Welte5c1e4582009-02-15 11:57:29 +0000741
Holger Hans Peter Freyther5ea73132009-10-29 02:29:45 +0100742 bfd = talloc_zero(tall_bsc_ctx, struct bsc_fd);
Harald Weltea4ffea92009-06-22 01:36:25 +0200743 if (!bfd)
744 return -ENOMEM;
Harald Weltea4ffea92009-06-22 01:36:25 +0200745
Harald Welteedb37782009-05-01 14:59:07 +0000746 /* Some BTS has connected to us, but we don't know yet which line
747 * (as created by the OML link) to associate it with. Thus, we
Holger Hans Peter Freytherc7df7c62009-11-15 13:50:39 +0100748 * allocate a temporary bfd until we have received ID from BTS */
Harald Welteedb37782009-05-01 14:59:07 +0000749
750 bfd->fd = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len);
751 if (bfd->fd < 0) {
752 perror("accept");
753 return bfd->fd;
Harald Welte5c1e4582009-02-15 11:57:29 +0000754 }
Harald Welteafdca0f2009-12-23 23:01:04 +0100755 LOGP(DINP, LOGL_NOTICE, "accept()ed new RSL link from %s\n", inet_ntoa(sa.sin_addr));
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100756 bfd->priv_nr = PRIV_RSL;
Harald Welteedb37782009-05-01 14:59:07 +0000757 bfd->cb = ipaccess_fd_cb;
758 bfd->when = BSC_FD_READ;
759 ret = bsc_register_fd(bfd);
760 if (ret < 0) {
Harald Welteafdca0f2009-12-23 23:01:04 +0100761 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
Harald Welteedb37782009-05-01 14:59:07 +0000762 close(bfd->fd);
Harald Weltea4ffea92009-06-22 01:36:25 +0200763 talloc_free(bfd);
Harald Welteedb37782009-05-01 14:59:07 +0000764 return ret;
765 }
766 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
Pablo Neira Ayuso22f58a92011-04-07 14:15:06 +0200767 ret = ipaccess_send_id_req(bfd->fd);
Harald Welteedb37782009-05-01 14:59:07 +0000768
Harald Welte5c1e4582009-02-15 11:57:29 +0000769 return 0;
770}
771
Harald Welte25de9912009-04-30 15:53:07 +0000772/* Actively connect to a BTS. Currently used by ipaccess-config.c */
773int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa)
774{
775 struct e1inp_ts *e1i_ts = &line->ts[0];
776 struct bsc_fd *bfd = &e1i_ts->driver.ipaccess.fd;
777 int ret, on = 1;
778
779 bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
780 bfd->cb = ipaccess_fd_cb;
781 bfd->when = BSC_FD_READ | BSC_FD_WRITE;
782 bfd->data = line;
Holger Hans Peter Freytherdc6af632010-03-24 04:56:13 +0100783 bfd->priv_nr = PRIV_OML;
Harald Welte25de9912009-04-30 15:53:07 +0000784
Holger Hans Peter Freyther4d2d95b2010-02-19 13:07:05 +0100785 if (bfd->fd < 0) {
786 LOGP(DINP, LOGL_ERROR, "could not create TCP socket.\n");
787 return -EIO;
788 }
789
Harald Welte25de9912009-04-30 15:53:07 +0000790 setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
791
792 ret = connect(bfd->fd, (struct sockaddr *) sa, sizeof(*sa));
793 if (ret < 0) {
Harald Welteafdca0f2009-12-23 23:01:04 +0100794 LOGP(DINP, LOGL_ERROR, "could not connect socket\n");
Harald Welte25de9912009-04-30 15:53:07 +0000795 close(bfd->fd);
796 return ret;
797 }
798
799 ret = bsc_register_fd(bfd);
800 if (ret < 0) {
801 close(bfd->fd);
802 return ret;
803 }
804
805 line->driver = &ipaccess_driver;
806
Holger Hans Peter Freyther09e364b2009-08-10 07:59:27 +0200807 return ret;
Harald Welte42581822009-08-08 16:12:58 +0200808 //return e1inp_line_register(line);
Harald Welte25de9912009-04-30 15:53:07 +0000809}
810
Harald Welteedb37782009-05-01 14:59:07 +0000811int ipaccess_setup(struct gsm_network *gsmnet)
Harald Welte5c1e4582009-02-15 11:57:29 +0000812{
Harald Welte5c1e4582009-02-15 11:57:29 +0000813 int ret;
Harald Welte5fd8a542009-02-13 02:43:36 +0000814
815 /* register the driver with the core */
816 /* FIXME: do this in the plugin initializer function */
817 ret = e1inp_driver_register(&ipaccess_driver);
818 if (ret)
819 return ret;
820
Holger Hans Peter Freyther5ea73132009-10-29 02:29:45 +0100821 e1h = talloc_zero(tall_bsc_ctx, struct ia_e1_handle);
Harald Weltea4ffea92009-06-22 01:36:25 +0200822 if (!e1h)
823 return -ENOMEM;
Harald Weltea4ffea92009-06-22 01:36:25 +0200824
Harald Welteedb37782009-05-01 14:59:07 +0000825 e1h->gsmnet = gsmnet;
Harald Welte5fd8a542009-02-13 02:43:36 +0000826
Harald Welte5c1e4582009-02-15 11:57:29 +0000827 /* Listen for OML connections */
Pablo Neira Ayuso165fe562011-04-05 18:33:24 +0200828 ret = make_sock(&e1h->listen_fd, IPPROTO_TCP, INADDR_ANY,
829 IPA_TCP_PORT_OML, 0, listen_fd_cb, NULL);
Harald Weltecf559782009-05-01 15:43:49 +0000830 if (ret < 0)
831 return ret;
Harald Welte5fd8a542009-02-13 02:43:36 +0000832
Harald Welte5c1e4582009-02-15 11:57:29 +0000833 /* Listen for RSL connections */
Pablo Neira Ayuso165fe562011-04-05 18:33:24 +0200834 ret = make_sock(&e1h->rsl_listen_fd, IPPROTO_TCP, INADDR_ANY,
835 IPA_TCP_PORT_RSL, 0, rsl_listen_fd_cb, NULL);
Harald Welte9b455bf2010-03-14 15:45:01 +0800836 if (ret < 0)
837 return ret;
838
Harald Welteedb37782009-05-01 14:59:07 +0000839 return ret;
Harald Welte5fd8a542009-02-13 02:43:36 +0000840}