blob: 22d5cd11cdb944b8dffda6cb7c1842f5534fb89f [file] [log] [blame]
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001/* OpenBSC Abis input driver for ip.access */
2
3/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2010 by Holger Hans Peter Freyther
5 * (C) 2010 by On-Waves
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * 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
12 * (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
17 * GNU Affero General Public License for more details.
18 *
19 * 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/>.
21 *
22 */
23
24#include "internal.h"
25
26#include <stdio.h>
27#include <unistd.h>
28#include <stdlib.h>
29#include <errno.h>
30#include <string.h>
31#include <time.h>
32#include <sys/fcntl.h>
33#include <sys/socket.h>
34#include <sys/ioctl.h>
35#include <arpa/inet.h>
36
37#include <osmocom/core/select.h>
38#include <osmocom/gsm/tlv.h>
39#include <osmocom/core/msgb.h>
40#include <osmocom/core/logging.h>
41#include <talloc.h>
Pablo Neira Ayuso177094b2011-06-07 12:21:51 +020042#include <osmocom/abis/e1_input.h>
43#include <osmocom/abis/ipaccess.h>
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +020044#include <osmocom/core/socket.h>
Pablo Neira Ayuso0b099b22011-06-09 13:14:11 +020045#include <osmocom/abis/logging.h>
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020046#include <osmocom/abis/ipa.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020047
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +020048static void *tall_ipa_ctx;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020049
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020050#define TS1_ALLOC_SIZE 900
51
52/*
53 * Common propietary IPA messages:
54 * - PONG: in reply to PING.
55 * - ID_REQUEST: first messages once OML has been established.
56 * - ID_ACK: in reply to ID_ACK.
57 */
58const uint8_t ipa_pong_msg[] = {
59 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG
60};
61
62const uint8_t ipa_id_ack_msg[] = {
63 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK
64};
65
66const uint8_t ipa_id_req_msg[] = {
67 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
68 0x01, IPAC_IDTAG_UNIT,
69 0x01, IPAC_IDTAG_MACADDR,
70 0x01, IPAC_IDTAG_LOCATION1,
71 0x01, IPAC_IDTAG_LOCATION2,
72 0x01, IPAC_IDTAG_EQUIPVERS,
73 0x01, IPAC_IDTAG_SWVERSION,
74 0x01, IPAC_IDTAG_UNITNAME,
75 0x01, IPAC_IDTAG_SERNR,
76};
77
78static int ipaccess_send(int fd, const void *msg, size_t msglen)
79{
80 int ret;
81
82 ret = write(fd, msg, msglen);
83 if (ret < 0)
84 return ret;
85 if (ret < msglen) {
86 LOGP(DINP, LOGL_ERROR, "ipaccess_send: short write\n");
87 return -EIO;
88 }
89 return ret;
90}
91
92int ipaccess_send_pong(int fd)
93{
94 return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg));
95}
96
97int ipaccess_send_id_ack(int fd)
98{
99 return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg));
100}
101
102int ipaccess_send_id_req(int fd)
103{
104 return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg));
105}
106
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200107/* base handling of the ip.access protocol */
108int ipaccess_rcvmsg_base(struct msgb *msg,
109 struct osmo_fd *bfd)
110{
111 uint8_t msg_type = *(msg->l2h);
112 int ret = 0;
113
114 switch (msg_type) {
115 case IPAC_MSGT_PING:
116 ret = ipaccess_send_pong(bfd->fd);
117 break;
118 case IPAC_MSGT_PONG:
119 DEBUGP(DMI, "PONG!\n");
120 break;
121 case IPAC_MSGT_ID_ACK:
122 DEBUGP(DMI, "ID_ACK? -> ACK!\n");
123 ret = ipaccess_send_id_ack(bfd->fd);
124 break;
125 }
126 return 0;
127}
128
129static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg,
130 struct osmo_fd *bfd)
131{
132 uint8_t msg_type = *(msg->l2h);
133
134 /* handle base messages */
135 ipaccess_rcvmsg_base(msg, bfd);
136
137 switch (msg_type) {
138 case IPAC_MSGT_ID_RESP:
139 DEBUGP(DMI, "ID_RESP\n");
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200140 if (!line->ops->sign_link_up) {
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200141 LOGP(DINP, LOGL_ERROR, "Fix your application, "
142 "no action set if the signalling link "
143 "becomes ready\n");
144 return -EINVAL;
145 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200146 line->ops->sign_link_up(msg, line, bfd->priv_nr);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200147 break;
148 }
149 return 0;
150}
151
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200152static int handle_ts1_read(struct osmo_fd *bfd)
153{
154 struct e1inp_line *line = bfd->data;
155 unsigned int ts_nr = bfd->priv_nr;
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200156 struct e1inp_ts *e1i_ts = NULL;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200157 struct e1inp_sign_link *link;
158 struct ipaccess_head *hh;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200159 struct msgb *msg;
160 int ret = 0, error;
161
Pablo Neira Ayuso7a249402011-06-21 14:15:46 +0200162 error = ipa_msg_recv(bfd->fd, &msg);
163 if (error <= 0) {
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200164 /* skip if RSL line is not set yet. */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200165 if (e1i_ts && e1i_ts->line->ops->error)
166 e1i_ts->line->ops->error(NULL, line, ts_nr, error);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200167 if (error == 0) {
168 osmo_fd_unregister(bfd);
169 close(bfd->fd);
170 bfd->fd = -1;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200171 talloc_free(bfd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200172 }
173 return error;
174 }
175 DEBUGP(DMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)));
176
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200177 /* Now that we're sure that we've got a line for socket. */
178 e1i_ts = &line->ts[ts_nr-1];
179
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200180 hh = (struct ipaccess_head *) msg->data;
181 if (hh->proto == IPAC_PROTO_IPACCESS) {
182 ipaccess_rcvmsg(line, msg, bfd);
183 msgb_free(msg);
184 return ret;
185 }
186 /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg()
187 * might have free'd it !!! */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200188
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200189 link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
190 if (!link) {
191 LOGP(DINP, LOGL_ERROR, "no matching signalling link for "
192 "hh->proto=0x%02x\n", hh->proto);
193 msgb_free(msg);
194 return -EIO;
195 }
196 msg->dst = link;
197
198 /* XXX better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200199 if (!e1i_ts->line->ops->sign_link) {
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200200 LOGP(DINP, LOGL_ERROR, "Fix your application, "
201 "no action set for signalling messages.\n");
202 return -ENOENT;
203 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200204 e1i_ts->line->ops->sign_link(msg, line, link);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200205
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200206 return ret;
207}
208
209void ipaccess_prepend_header_ext(struct msgb *msg, int proto)
210{
211 struct ipaccess_head_ext *hh_ext;
212
213 /* prepend the osmo ip.access header extension */
214 hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext));
215 hh_ext->proto = proto;
216}
217
218void ipaccess_prepend_header(struct msgb *msg, int proto)
219{
220 struct ipaccess_head *hh;
221
222 /* prepend the ip.access header */
223 hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh));
224 hh->len = htons(msg->len - sizeof(*hh));
225 hh->proto = proto;
226}
227
228static int ts_want_write(struct e1inp_ts *e1i_ts)
229{
230 e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE;
231
232 return 0;
233}
234
235static void timeout_ts1_write(void *data)
236{
237 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
238
239 /* trigger write of ts1, due to tx delay timer */
240 ts_want_write(e1i_ts);
241}
242
243static int handle_ts1_write(struct osmo_fd *bfd)
244{
245 struct e1inp_line *line = bfd->data;
246 unsigned int ts_nr = bfd->priv_nr;
247 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
248 struct e1inp_sign_link *sign_link;
249 struct msgb *msg;
250 uint8_t proto;
251 int ret;
252
253 bfd->when &= ~BSC_FD_WRITE;
254
255 /* get the next msg for this timeslot */
256 msg = e1inp_tx_ts(e1i_ts, &sign_link);
257 if (!msg) {
258 /* no message after tx delay timer */
259 return 0;
260 }
261
262 switch (sign_link->type) {
263 case E1INP_SIGN_OML:
264 proto = IPAC_PROTO_OML;
265 break;
266 case E1INP_SIGN_RSL:
267 proto = IPAC_PROTO_RSL;
268 break;
269 default:
270 msgb_free(msg);
271 bfd->when |= BSC_FD_WRITE; /* come back for more msg */
272 return -EINVAL;
273 }
274
275 msg->l2h = msg->data;
276 ipaccess_prepend_header(msg, sign_link->tei);
277
278 DEBUGP(DMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg)));
279
280 ret = send(bfd->fd, msg->data, msg->len, 0);
281 msgb_free(msg);
282
283 /* set tx delay timer for next event */
284 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
285 e1i_ts->sign.tx_timer.data = e1i_ts;
286
287 /* Reducing this might break the nanoBTS 900 init. */
288 osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
289
290 return ret;
291}
292
293/* callback from select.c in case one of the fd's can be read/written */
294static int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what)
295{
296 struct e1inp_line *line = bfd->data;
297 unsigned int ts_nr = bfd->priv_nr;
298 unsigned int idx = ts_nr-1;
299 struct e1inp_ts *e1i_ts;
300 int rc = 0;
301
302 /* In case of early RSL we might not yet have a line */
303
304 if (line)
305 e1i_ts = &line->ts[idx];
306
307 if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) {
308 if (what & BSC_FD_READ)
309 rc = handle_ts1_read(bfd);
310 if (what & BSC_FD_WRITE)
311 rc = handle_ts1_write(bfd);
312 } else
313 LOGP(DINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type);
314
315 return rc;
316}
317
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200318static int ipaccess_line_update(struct e1inp_line *line,
319 enum e1inp_line_role role, const char *addr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200320
321struct e1inp_driver ipaccess_driver = {
322 .name = "ipa",
323 .want_write = ts_want_write,
324 .line_update = ipaccess_line_update,
325 .default_delay = 0,
326};
327
328/* callback of the OML listening filedescriptor */
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200329static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200330{
331 int ret;
332 int idx = 0;
333 int i;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200334 struct e1inp_line *line = link->line;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200335 struct e1inp_ts *e1i_ts;
336 struct osmo_fd *bfd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200337
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200338 bfd = talloc_zero(tall_ipa_ctx, struct osmo_fd);
339 if (!bfd)
340 return -ENOMEM;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200341
342 /* create virrtual E1 timeslots for signalling */
343 e1inp_ts_config_sign(&line->ts[1-1], line);
344
345 /* initialize the fds */
346 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
347 line->ts[i].driver.ipaccess.fd.fd = -1;
348
349 e1i_ts = &line->ts[idx];
350
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200351 bfd->fd = fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200352 bfd->data = line;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200353 bfd->priv_nr = E1INP_SIGN_OML;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200354 bfd->cb = ipaccess_fd_cb;
355 bfd->when = BSC_FD_READ;
356 ret = osmo_fd_register(bfd);
357 if (ret < 0) {
358 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
359 close(bfd->fd);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200360 talloc_free(bfd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200361 return ret;
362 }
363
364 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
365 ret = ipaccess_send_id_req(bfd->fd);
366
367 return ret;
368}
369
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200370static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200371{
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200372 struct osmo_fd *bfd;
373 int ret;
374
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200375 bfd = talloc_zero(tall_ipa_ctx, struct osmo_fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200376 if (!bfd)
377 return -ENOMEM;
378
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200379 bfd->fd = fd;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200380 bfd->priv_nr = E1INP_SIGN_RSL;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200381 bfd->cb = ipaccess_fd_cb;
382 bfd->when = BSC_FD_READ;
383 ret = osmo_fd_register(bfd);
384 if (ret < 0) {
385 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
386 close(bfd->fd);
387 talloc_free(bfd);
388 return ret;
389 }
390 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
391 ret = ipaccess_send_id_req(bfd->fd);
392
393 return 0;
394}
395
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200396static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg)
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200397{
398 struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
399 struct e1inp_ts *e1i_ts = NULL;
400 struct e1inp_sign_link *sign_link;
401
402 /* special handling for IPA CCM. */
403 if (hh->proto == IPAC_PROTO_IPACCESS) {
404 uint8_t msg_type = *(msg->l2h);
405
406 /* ping, pong and acknowledgment cases. */
407 ipaccess_rcvmsg_base(msg, &link->ofd);
408
409 /* this is a request for identification from the BSC. */
410 if (msg_type == IPAC_MSGT_ID_GET) {
411 LOGP(DINP, LOGL_NOTICE, "received ID get\n");
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200412 if (!link->line->ops->sign_link_up) {
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200413 LOGP(DINP, LOGL_ERROR, "Fix your application, "
414 "no action set if the signalling link "
415 "becomes ready\n");
416 return -EINVAL;
417 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200418 link->line->ops->sign_link_up(msg, link->line,
419 link->port == IPA_TCP_PORT_OML ?
420 E1INP_SIGN_OML : E1INP_SIGN_RSL);
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200421 }
422 return 0;
423 } else if (link->port == IPA_TCP_PORT_OML)
424 e1i_ts = &link->line->ts[0];
425 else if (link->port == IPA_TCP_PORT_RSL)
426 e1i_ts = &link->line->ts[1];
427
428 /* look up for some existing signaling link. */
429 sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
430 if (sign_link == NULL) {
431 LOGP(DINP, LOGL_ERROR, "no matching signalling link for "
432 "hh->proto=0x%02x\n", hh->proto);
433 msgb_free(msg);
434 return -EIO;
435 }
436 msg->dst = sign_link;
437
438 /* XXX better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200439 if (!link->line->ops->sign_link) {
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200440 LOGP(DINP, LOGL_ERROR, "Fix your application, "
441 "no action set for signalling messages.\n");
442 return -ENOENT;
443 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200444 link->line->ops->sign_link(msg, link->line, sign_link);
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200445 return 0;
446}
447
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200448static int ipaccess_line_update(struct e1inp_line *line,
449 enum e1inp_line_role role, const char *addr)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200450{
451 int ret = -ENOENT;
452
453 switch(role) {
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200454 case E1INP_LINE_R_BSC: {
455 struct ipa_server_link *oml_link, *rsl_link;
456
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200457 LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n");
458
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200459 oml_link = ipa_server_link_create(tall_ipa_ctx, line,
460 "0.0.0.0", IPA_TCP_PORT_OML,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200461 ipaccess_bsc_oml_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200462 if (oml_link == NULL) {
463 LOGP(DINP, LOGL_ERROR, "cannot create OML "
464 "BSC link: %s\n", strerror(errno));
465 return -ENOMEM;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200466 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200467 if (ipa_server_link_open(oml_link) < 0) {
468 LOGP(DINP, LOGL_ERROR, "cannot open OML BSC link: %s\n",
469 strerror(errno));
470 ipa_server_link_close(oml_link);
471 ipa_server_link_destroy(oml_link);
472 return -EIO;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200473 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200474 rsl_link = ipa_server_link_create(tall_ipa_ctx, line,
475 "0.0.0.0", IPA_TCP_PORT_RSL,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200476 ipaccess_bsc_rsl_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200477 if (rsl_link == NULL) {
478 LOGP(DINP, LOGL_ERROR, "cannot create RSL "
479 "BSC link: %s\n", strerror(errno));
480 return -ENOMEM;
481 }
482 if (ipa_server_link_open(rsl_link) < 0) {
483 LOGP(DINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n",
484 strerror(errno));
485 ipa_server_link_close(rsl_link);
486 ipa_server_link_destroy(rsl_link);
487 return -EIO;
488 }
489 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200490 break;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200491 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200492 case E1INP_LINE_R_BTS: {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200493 struct ipa_client_link *link, *rsl_link;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200494
495 LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n");
496
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200497 link = ipa_client_link_create(tall_ipa_ctx, line,
498 addr, IPA_TCP_PORT_OML,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200499 ipaccess_bts_cb, NULL);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200500 if (link == NULL) {
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200501 LOGP(DINP, LOGL_ERROR, "cannot create OML "
502 "BTS link: %s\n", strerror(errno));
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200503 return -ENOMEM;
504 }
505 if (ipa_client_link_open(link) < 0) {
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200506 LOGP(DINP, LOGL_ERROR, "cannot open OML BTS link: %s\n",
507 strerror(errno));
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200508 ipa_client_link_close(link);
509 ipa_client_link_destroy(link);
510 return -EIO;
511 }
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200512 rsl_link = ipa_client_link_create(tall_ipa_ctx, line,
513 addr, IPA_TCP_PORT_RSL,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200514 ipaccess_bts_cb, NULL);
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200515 if (rsl_link == NULL) {
516 LOGP(DINP, LOGL_ERROR, "cannot create RSL "
517 "BTS link: %s\n", strerror(errno));
518 return -ENOMEM;
519 }
520 if (ipa_client_link_open(rsl_link) < 0) {
521 LOGP(DINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n",
522 strerror(errno));
523 ipa_client_link_close(rsl_link);
524 ipa_client_link_destroy(rsl_link);
525 return -EIO;
526 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200527 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200528 break;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200529 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200530 default:
531 break;
532 }
533 return ret;
534}
535
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200536void e1inp_ipaccess_init(void)
537{
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200538 tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200539 e1inp_driver_register(&ipaccess_driver);
540}