blob: 5d084d866b954d8bd2d33514339ccb1facd650e7 [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;
Pablo Neira Ayusoff663632011-06-26 19:10:56 +0200197 msg->trx = link->trx;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200198
199 /* XXX better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200200 if (!e1i_ts->line->ops->sign_link) {
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200201 LOGP(DINP, LOGL_ERROR, "Fix your application, "
202 "no action set for signalling messages.\n");
203 return -ENOENT;
204 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200205 e1i_ts->line->ops->sign_link(msg, line, link);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200206
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200207 return ret;
208}
209
210void ipaccess_prepend_header_ext(struct msgb *msg, int proto)
211{
212 struct ipaccess_head_ext *hh_ext;
213
214 /* prepend the osmo ip.access header extension */
215 hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext));
216 hh_ext->proto = proto;
217}
218
219void ipaccess_prepend_header(struct msgb *msg, int proto)
220{
221 struct ipaccess_head *hh;
222
223 /* prepend the ip.access header */
224 hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh));
225 hh->len = htons(msg->len - sizeof(*hh));
226 hh->proto = proto;
227}
228
229static int ts_want_write(struct e1inp_ts *e1i_ts)
230{
231 e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE;
232
233 return 0;
234}
235
236static void timeout_ts1_write(void *data)
237{
238 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
239
240 /* trigger write of ts1, due to tx delay timer */
241 ts_want_write(e1i_ts);
242}
243
244static int handle_ts1_write(struct osmo_fd *bfd)
245{
246 struct e1inp_line *line = bfd->data;
247 unsigned int ts_nr = bfd->priv_nr;
248 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
249 struct e1inp_sign_link *sign_link;
250 struct msgb *msg;
251 uint8_t proto;
252 int ret;
253
254 bfd->when &= ~BSC_FD_WRITE;
255
256 /* get the next msg for this timeslot */
257 msg = e1inp_tx_ts(e1i_ts, &sign_link);
258 if (!msg) {
259 /* no message after tx delay timer */
260 return 0;
261 }
262
263 switch (sign_link->type) {
264 case E1INP_SIGN_OML:
265 proto = IPAC_PROTO_OML;
266 break;
267 case E1INP_SIGN_RSL:
268 proto = IPAC_PROTO_RSL;
269 break;
270 default:
271 msgb_free(msg);
272 bfd->when |= BSC_FD_WRITE; /* come back for more msg */
273 return -EINVAL;
274 }
275
276 msg->l2h = msg->data;
277 ipaccess_prepend_header(msg, sign_link->tei);
278
279 DEBUGP(DMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg)));
280
281 ret = send(bfd->fd, msg->data, msg->len, 0);
282 msgb_free(msg);
283
284 /* set tx delay timer for next event */
285 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
286 e1i_ts->sign.tx_timer.data = e1i_ts;
287
288 /* Reducing this might break the nanoBTS 900 init. */
289 osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
290
291 return ret;
292}
293
294/* callback from select.c in case one of the fd's can be read/written */
295static int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what)
296{
297 struct e1inp_line *line = bfd->data;
298 unsigned int ts_nr = bfd->priv_nr;
299 unsigned int idx = ts_nr-1;
300 struct e1inp_ts *e1i_ts;
301 int rc = 0;
302
303 /* In case of early RSL we might not yet have a line */
304
305 if (line)
306 e1i_ts = &line->ts[idx];
307
308 if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) {
309 if (what & BSC_FD_READ)
310 rc = handle_ts1_read(bfd);
311 if (what & BSC_FD_WRITE)
312 rc = handle_ts1_write(bfd);
313 } else
314 LOGP(DINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type);
315
316 return rc;
317}
318
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200319static int ipaccess_line_update(struct e1inp_line *line,
320 enum e1inp_line_role role, const char *addr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200321
322struct e1inp_driver ipaccess_driver = {
323 .name = "ipa",
324 .want_write = ts_want_write,
325 .line_update = ipaccess_line_update,
326 .default_delay = 0,
327};
328
329/* callback of the OML listening filedescriptor */
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200330static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200331{
332 int ret;
333 int idx = 0;
334 int i;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200335 struct e1inp_line *line = link->line;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200336 struct e1inp_ts *e1i_ts;
337 struct osmo_fd *bfd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200338
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200339 /* create virrtual E1 timeslots for signalling */
340 e1inp_ts_config_sign(&line->ts[1-1], line);
341
342 /* initialize the fds */
343 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
344 line->ts[i].driver.ipaccess.fd.fd = -1;
345
346 e1i_ts = &line->ts[idx];
347
Pablo Neira Ayuso93c62012011-06-26 19:12:47 +0200348 bfd = &e1i_ts->driver.ipaccess.fd;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200349 bfd->fd = fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200350 bfd->data = line;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200351 bfd->priv_nr = E1INP_SIGN_OML;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200352 bfd->cb = ipaccess_fd_cb;
353 bfd->when = BSC_FD_READ;
354 ret = osmo_fd_register(bfd);
355 if (ret < 0) {
356 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
357 close(bfd->fd);
358 return ret;
359 }
360
361 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
362 ret = ipaccess_send_id_req(bfd->fd);
363
364 return ret;
365}
366
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200367static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200368{
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200369 struct osmo_fd *bfd;
370 int ret;
371
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200372 bfd = talloc_zero(tall_ipa_ctx, struct osmo_fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200373 if (!bfd)
374 return -ENOMEM;
375
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200376 bfd->fd = fd;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200377 bfd->priv_nr = E1INP_SIGN_RSL;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200378 bfd->cb = ipaccess_fd_cb;
379 bfd->when = BSC_FD_READ;
380 ret = osmo_fd_register(bfd);
381 if (ret < 0) {
382 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
383 close(bfd->fd);
384 talloc_free(bfd);
385 return ret;
386 }
387 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
388 ret = ipaccess_send_id_req(bfd->fd);
389
390 return 0;
391}
392
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200393static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg)
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200394{
395 struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
396 struct e1inp_ts *e1i_ts = NULL;
397 struct e1inp_sign_link *sign_link;
398
399 /* special handling for IPA CCM. */
400 if (hh->proto == IPAC_PROTO_IPACCESS) {
401 uint8_t msg_type = *(msg->l2h);
402
403 /* ping, pong and acknowledgment cases. */
404 ipaccess_rcvmsg_base(msg, &link->ofd);
405
406 /* this is a request for identification from the BSC. */
407 if (msg_type == IPAC_MSGT_ID_GET) {
408 LOGP(DINP, LOGL_NOTICE, "received ID get\n");
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200409 if (!link->line->ops->sign_link_up) {
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200410 LOGP(DINP, LOGL_ERROR, "Fix your application, "
411 "no action set if the signalling link "
412 "becomes ready\n");
413 return -EINVAL;
414 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200415 link->line->ops->sign_link_up(msg, link->line,
416 link->port == IPA_TCP_PORT_OML ?
417 E1INP_SIGN_OML : E1INP_SIGN_RSL);
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200418 }
419 return 0;
420 } else if (link->port == IPA_TCP_PORT_OML)
421 e1i_ts = &link->line->ts[0];
422 else if (link->port == IPA_TCP_PORT_RSL)
423 e1i_ts = &link->line->ts[1];
424
425 /* look up for some existing signaling link. */
426 sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
427 if (sign_link == NULL) {
428 LOGP(DINP, LOGL_ERROR, "no matching signalling link for "
429 "hh->proto=0x%02x\n", hh->proto);
430 msgb_free(msg);
431 return -EIO;
432 }
433 msg->dst = sign_link;
Pablo Neira Ayusoff663632011-06-26 19:10:56 +0200434 msg->trx = sign_link->trx;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200435
436 /* XXX better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200437 if (!link->line->ops->sign_link) {
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200438 LOGP(DINP, LOGL_ERROR, "Fix your application, "
439 "no action set for signalling messages.\n");
440 return -ENOENT;
441 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200442 link->line->ops->sign_link(msg, link->line, sign_link);
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200443 return 0;
444}
445
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200446static int ipaccess_line_update(struct e1inp_line *line,
447 enum e1inp_line_role role, const char *addr)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200448{
449 int ret = -ENOENT;
450
451 switch(role) {
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200452 case E1INP_LINE_R_BSC: {
453 struct ipa_server_link *oml_link, *rsl_link;
454
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200455 LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n");
456
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200457 oml_link = ipa_server_link_create(tall_ipa_ctx, line,
458 "0.0.0.0", IPA_TCP_PORT_OML,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200459 ipaccess_bsc_oml_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200460 if (oml_link == NULL) {
461 LOGP(DINP, LOGL_ERROR, "cannot create OML "
462 "BSC link: %s\n", strerror(errno));
463 return -ENOMEM;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200464 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200465 if (ipa_server_link_open(oml_link) < 0) {
466 LOGP(DINP, LOGL_ERROR, "cannot open OML BSC link: %s\n",
467 strerror(errno));
468 ipa_server_link_close(oml_link);
469 ipa_server_link_destroy(oml_link);
470 return -EIO;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200471 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200472 rsl_link = ipa_server_link_create(tall_ipa_ctx, line,
473 "0.0.0.0", IPA_TCP_PORT_RSL,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200474 ipaccess_bsc_rsl_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200475 if (rsl_link == NULL) {
476 LOGP(DINP, LOGL_ERROR, "cannot create RSL "
477 "BSC link: %s\n", strerror(errno));
478 return -ENOMEM;
479 }
480 if (ipa_server_link_open(rsl_link) < 0) {
481 LOGP(DINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n",
482 strerror(errno));
483 ipa_server_link_close(rsl_link);
484 ipa_server_link_destroy(rsl_link);
485 return -EIO;
486 }
487 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200488 break;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200489 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200490 case E1INP_LINE_R_BTS: {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200491 struct ipa_client_link *link, *rsl_link;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200492
493 LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n");
494
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200495 link = ipa_client_link_create(tall_ipa_ctx, line,
496 addr, IPA_TCP_PORT_OML,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200497 ipaccess_bts_cb, NULL);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200498 if (link == NULL) {
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200499 LOGP(DINP, LOGL_ERROR, "cannot create OML "
500 "BTS link: %s\n", strerror(errno));
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200501 return -ENOMEM;
502 }
503 if (ipa_client_link_open(link) < 0) {
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200504 LOGP(DINP, LOGL_ERROR, "cannot open OML BTS link: %s\n",
505 strerror(errno));
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200506 ipa_client_link_close(link);
507 ipa_client_link_destroy(link);
508 return -EIO;
509 }
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200510 rsl_link = ipa_client_link_create(tall_ipa_ctx, line,
511 addr, IPA_TCP_PORT_RSL,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200512 ipaccess_bts_cb, NULL);
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200513 if (rsl_link == NULL) {
514 LOGP(DINP, LOGL_ERROR, "cannot create RSL "
515 "BTS link: %s\n", strerror(errno));
516 return -ENOMEM;
517 }
518 if (ipa_client_link_open(rsl_link) < 0) {
519 LOGP(DINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n",
520 strerror(errno));
521 ipa_client_link_close(rsl_link);
522 ipa_client_link_destroy(rsl_link);
523 return -EIO;
524 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200525 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200526 break;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200527 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200528 default:
529 break;
530 }
531 return ret;
532}
533
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200534void e1inp_ipaccess_init(void)
535{
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200536 tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200537 e1inp_driver_register(&ipaccess_driver);
538}