blob: d1ada9435385c9c604b6c2cf4c069ee3fb34fafb [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 Ayuso986191f2011-06-21 19:56:26 +0200339 bfd = talloc_zero(tall_ipa_ctx, struct osmo_fd);
340 if (!bfd)
341 return -ENOMEM;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200342
343 /* create virrtual E1 timeslots for signalling */
344 e1inp_ts_config_sign(&line->ts[1-1], line);
345
346 /* initialize the fds */
347 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
348 line->ts[i].driver.ipaccess.fd.fd = -1;
349
350 e1i_ts = &line->ts[idx];
351
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200352 bfd->fd = fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200353 bfd->data = line;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200354 bfd->priv_nr = E1INP_SIGN_OML;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200355 bfd->cb = ipaccess_fd_cb;
356 bfd->when = BSC_FD_READ;
357 ret = osmo_fd_register(bfd);
358 if (ret < 0) {
359 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
360 close(bfd->fd);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200361 talloc_free(bfd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200362 return ret;
363 }
364
365 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
366 ret = ipaccess_send_id_req(bfd->fd);
367
368 return ret;
369}
370
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200371static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200372{
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200373 struct osmo_fd *bfd;
374 int ret;
375
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200376 bfd = talloc_zero(tall_ipa_ctx, struct osmo_fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200377 if (!bfd)
378 return -ENOMEM;
379
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200380 bfd->fd = fd;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200381 bfd->priv_nr = E1INP_SIGN_RSL;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200382 bfd->cb = ipaccess_fd_cb;
383 bfd->when = BSC_FD_READ;
384 ret = osmo_fd_register(bfd);
385 if (ret < 0) {
386 LOGP(DINP, LOGL_ERROR, "could not register FD\n");
387 close(bfd->fd);
388 talloc_free(bfd);
389 return ret;
390 }
391 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
392 ret = ipaccess_send_id_req(bfd->fd);
393
394 return 0;
395}
396
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200397static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg)
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200398{
399 struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
400 struct e1inp_ts *e1i_ts = NULL;
401 struct e1inp_sign_link *sign_link;
402
403 /* special handling for IPA CCM. */
404 if (hh->proto == IPAC_PROTO_IPACCESS) {
405 uint8_t msg_type = *(msg->l2h);
406
407 /* ping, pong and acknowledgment cases. */
408 ipaccess_rcvmsg_base(msg, &link->ofd);
409
410 /* this is a request for identification from the BSC. */
411 if (msg_type == IPAC_MSGT_ID_GET) {
412 LOGP(DINP, LOGL_NOTICE, "received ID get\n");
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200413 if (!link->line->ops->sign_link_up) {
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200414 LOGP(DINP, LOGL_ERROR, "Fix your application, "
415 "no action set if the signalling link "
416 "becomes ready\n");
417 return -EINVAL;
418 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200419 link->line->ops->sign_link_up(msg, link->line,
420 link->port == IPA_TCP_PORT_OML ?
421 E1INP_SIGN_OML : E1INP_SIGN_RSL);
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200422 }
423 return 0;
424 } else if (link->port == IPA_TCP_PORT_OML)
425 e1i_ts = &link->line->ts[0];
426 else if (link->port == IPA_TCP_PORT_RSL)
427 e1i_ts = &link->line->ts[1];
428
429 /* look up for some existing signaling link. */
430 sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
431 if (sign_link == NULL) {
432 LOGP(DINP, LOGL_ERROR, "no matching signalling link for "
433 "hh->proto=0x%02x\n", hh->proto);
434 msgb_free(msg);
435 return -EIO;
436 }
437 msg->dst = sign_link;
Pablo Neira Ayusoff663632011-06-26 19:10:56 +0200438 msg->trx = sign_link->trx;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200439
440 /* XXX better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200441 if (!link->line->ops->sign_link) {
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200442 LOGP(DINP, LOGL_ERROR, "Fix your application, "
443 "no action set for signalling messages.\n");
444 return -ENOENT;
445 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200446 link->line->ops->sign_link(msg, link->line, sign_link);
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200447 return 0;
448}
449
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200450static int ipaccess_line_update(struct e1inp_line *line,
451 enum e1inp_line_role role, const char *addr)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200452{
453 int ret = -ENOENT;
454
455 switch(role) {
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200456 case E1INP_LINE_R_BSC: {
457 struct ipa_server_link *oml_link, *rsl_link;
458
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200459 LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n");
460
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200461 oml_link = ipa_server_link_create(tall_ipa_ctx, line,
462 "0.0.0.0", IPA_TCP_PORT_OML,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200463 ipaccess_bsc_oml_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200464 if (oml_link == NULL) {
465 LOGP(DINP, LOGL_ERROR, "cannot create OML "
466 "BSC link: %s\n", strerror(errno));
467 return -ENOMEM;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200468 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200469 if (ipa_server_link_open(oml_link) < 0) {
470 LOGP(DINP, LOGL_ERROR, "cannot open OML BSC link: %s\n",
471 strerror(errno));
472 ipa_server_link_close(oml_link);
473 ipa_server_link_destroy(oml_link);
474 return -EIO;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200475 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200476 rsl_link = ipa_server_link_create(tall_ipa_ctx, line,
477 "0.0.0.0", IPA_TCP_PORT_RSL,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200478 ipaccess_bsc_rsl_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200479 if (rsl_link == NULL) {
480 LOGP(DINP, LOGL_ERROR, "cannot create RSL "
481 "BSC link: %s\n", strerror(errno));
482 return -ENOMEM;
483 }
484 if (ipa_server_link_open(rsl_link) < 0) {
485 LOGP(DINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n",
486 strerror(errno));
487 ipa_server_link_close(rsl_link);
488 ipa_server_link_destroy(rsl_link);
489 return -EIO;
490 }
491 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200492 break;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200493 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200494 case E1INP_LINE_R_BTS: {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200495 struct ipa_client_link *link, *rsl_link;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200496
497 LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n");
498
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200499 link = ipa_client_link_create(tall_ipa_ctx, line,
500 addr, IPA_TCP_PORT_OML,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200501 ipaccess_bts_cb, NULL);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200502 if (link == NULL) {
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200503 LOGP(DINP, LOGL_ERROR, "cannot create OML "
504 "BTS link: %s\n", strerror(errno));
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200505 return -ENOMEM;
506 }
507 if (ipa_client_link_open(link) < 0) {
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200508 LOGP(DINP, LOGL_ERROR, "cannot open OML BTS link: %s\n",
509 strerror(errno));
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200510 ipa_client_link_close(link);
511 ipa_client_link_destroy(link);
512 return -EIO;
513 }
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200514 rsl_link = ipa_client_link_create(tall_ipa_ctx, line,
515 addr, IPA_TCP_PORT_RSL,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +0200516 ipaccess_bts_cb, NULL);
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +0200517 if (rsl_link == NULL) {
518 LOGP(DINP, LOGL_ERROR, "cannot create RSL "
519 "BTS link: %s\n", strerror(errno));
520 return -ENOMEM;
521 }
522 if (ipa_client_link_open(rsl_link) < 0) {
523 LOGP(DINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n",
524 strerror(errno));
525 ipa_client_link_close(rsl_link);
526 ipa_client_link_destroy(rsl_link);
527 return -EIO;
528 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200529 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200530 break;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +0200531 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200532 default:
533 break;
534 }
535 return ret;
536}
537
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200538void e1inp_ipaccess_init(void)
539{
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200540 tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200541 e1inp_driver_register(&ipaccess_driver);
542}