blob: 98fd40ffa6f39f57d065d1de00bcb3c8bb9bfb89 [file] [log] [blame]
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001/* OpenBSC Abis input driver for HSL Femto */
2
3/* (C) 2011 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2011 by On-Waves
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23/* HSL uses a much more primitive/simplified version of the IPA multiplex.
24 *
25 * They have taken out the nice parts like the ID_GET / ID_RESP for resolving
26 * the UNIT ID, as well as the keepalive ping/pong messages. Furthermore, the
27 * Stream Identifiers are fixed on the BTS side (RSL always 0, OML always 0xff)
28 * and both OML+RSL share a single TCP connection.
29 *
30 * Other oddities include the encapsulation of BSSGP messages in the L3_INFO IE
31 * of RSL
32 */
33
34#include "internal.h"
35
36#include <stdio.h>
37#include <unistd.h>
38#include <stdlib.h>
39#include <errno.h>
40#include <string.h>
41#include <time.h>
42#include <sys/fcntl.h>
43#include <sys/socket.h>
44#include <sys/ioctl.h>
45#include <arpa/inet.h>
46
47#include <osmocom/core/select.h>
48#include <osmocom/gsm/tlv.h>
49#include <osmocom/core/msgb.h>
Pablo Neira Ayuso177094b2011-06-07 12:21:51 +020050#include <osmocom/abis/e1_input.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020051#include <osmocom/core/logging.h>
Pablo Neira Ayusoe47a9782011-06-07 18:03:48 +020052#include <osmocom/abis/ipaccess.h>
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +020053#include <osmocom/core/socket.h>
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +020054#include <osmocom/abis/ipa.h>
Harald Welte71d87b22011-07-18 14:49:56 +020055#include <osmocom/core/talloc.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020056
57#define HSL_TCP_PORT 2500
58#define HSL_PROTO_DEBUG 0xdd
59
60#define PRIV_OML 1
61#define PRIV_RSL 2
62
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +020063static void *tall_hsl_ctx;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020064
65/* data structure for one E1 interface with A-bis */
66struct hsl_e1_handle {
67 struct osmo_fd listen_fd;
68 struct gsm_network *gsmnet;
69};
70
71static struct hsl_e1_handle *e1h;
72
73
74#define TS1_ALLOC_SIZE 900
75
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020076static void hsl_drop(struct e1inp_line *line, struct osmo_fd *bfd)
77{
78 line->ops->sign_link_down(line);
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +020079
80 if (bfd->fd != -1) {
81 osmo_fd_unregister(bfd);
82 close(bfd->fd);
83 bfd->fd = -1;
84 }
85 /* put the virtual E1 line that we cloned for this socket, if
86 * it becomes unused, it gets released. */
87 e1inp_line_put(line);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020088}
89
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +020090static int process_hsl_rsl(struct msgb *msg, struct e1inp_line *line,
91 struct osmo_fd *bfd)
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020092{
93 char serno_buf[16];
94 uint8_t serno_len;
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +020095 struct e1inp_sign_link *sign_link;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020096 struct hsl_unit unit_data;
97
98 switch (msg->l2h[1]) {
99 case 0x80:
100 /*, contains Serial Number + SW version */
101 if (msg->l2h[2] != 0xc0)
102 break;
103 serno_len = msg->l2h[3];
104 if (serno_len > sizeof(serno_buf)-1)
105 serno_len = sizeof(serno_buf)-1;
106 memcpy(serno_buf, msg->l2h+4, serno_len);
107 serno_buf[serno_len] = '\0';
108 unit_data.serno = strtoul(serno_buf, NULL, 10);
109
110 if (!line->ops->sign_link_up) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200111 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +0200112 "Unable to set signal link, closing socket.\n");
113 osmo_fd_unregister(bfd);
114 close(bfd->fd);
115 bfd->fd = -1;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200116 return -EINVAL;
117 }
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +0200118 sign_link = line->ops->sign_link_up(&unit_data,
119 line, E1INP_SIGN_NONE);
120 if (sign_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200121 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +0200122 "Unable to set signal link, closing socket.\n");
123 osmo_fd_unregister(bfd);
124 close(bfd->fd);
125 bfd->fd = -1;
126 return -EINVAL;
127 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200128 msgb_free(msg);
129 return 1; /* == we have taken over the msg */
130 case 0x82:
131 /* FIXME: do something with BSSGP, i.e. forward it over
132 * NSIP to OsmoSGSN */
133 msgb_free(msg);
134 return 1;
135 }
136 return 0;
137}
138
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200139static int handle_ts1_read(struct osmo_fd *bfd)
140{
141 struct e1inp_line *line = bfd->data;
142 unsigned int ts_nr = bfd->priv_nr;
143 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200144 struct e1inp_sign_link *link;
145 struct ipaccess_head *hh;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200146 struct msgb *msg;
147 int ret = 0, error;
148
Pablo Neira Ayuso7a249402011-06-21 14:15:46 +0200149 error = ipa_msg_recv(bfd->fd, &msg);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200150 if (error < 0)
151 return error;
152 else if (error == 0) {
153 hsl_drop(e1i_ts->line, bfd);
Harald Weltecc2241b2011-07-19 16:06:06 +0200154 LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, dead socket\n");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200155 return error;
156 }
Harald Weltecc2241b2011-07-19 16:06:06 +0200157 DEBUGP(DLMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200158
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200159 hh = (struct ipaccess_head *) msg->data;
160 if (hh->proto == HSL_PROTO_DEBUG) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200161 LOGP(DLINP, LOGL_NOTICE, "HSL debug: %s\n", msg->data + sizeof(*hh));
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200162 msgb_free(msg);
163 return ret;
164 }
165
166 /* HSL proprietary RSL extension */
167 if (hh->proto == 0 && (msg->l2h[0] == 0x81 || msg->l2h[0] == 0x80)) {
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +0200168 ret = process_hsl_rsl(msg, line, bfd);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200169 if (ret < 0) {
170 hsl_drop(e1i_ts->line, bfd);
171 return ret;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200172 } else if (ret == 1)
173 return 0;
174 /* else: continue... */
175 }
176
177#ifdef HSL_SR_1_0
178 /* HSL for whatever reason chose to use 0x81 instead of 0x80 for FOM */
179 if (hh->proto == 255 && msg->l2h[0] == (ABIS_OM_MDISC_FOM | 0x01))
180 msg->l2h[0] = ABIS_OM_MDISC_FOM;
181#endif
182 link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
183 if (!link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200184 LOGP(DLINP, LOGL_ERROR, "no matching signalling link for "
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200185 "hh->proto=0x%02x\n", hh->proto);
186 msgb_free(msg);
187 return -EIO;
188 }
189 msg->dst = link;
190
191 /* XXX: better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200192 if (!e1i_ts->line->ops->sign_link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200193 LOGP(DLINP, LOGL_ERROR, "Fix your application, "
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200194 "no action set for signalling messages.\n");
195 return -ENOENT;
196 }
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200197 e1i_ts->line->ops->sign_link(msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200198
199 return ret;
200}
201
202static int ts_want_write(struct e1inp_ts *e1i_ts)
203{
204 e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE;
205
206 return 0;
207}
208
209static void timeout_ts1_write(void *data)
210{
211 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
212
213 /* trigger write of ts1, due to tx delay timer */
214 ts_want_write(e1i_ts);
215}
216
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200217static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200218{
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200219 unsigned int ts_nr = bfd->priv_nr;
220 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
221 struct e1inp_sign_link *sign_link;
222 struct msgb *msg;
223 uint8_t proto;
224 int ret;
225
226 bfd->when &= ~BSC_FD_WRITE;
227
228 /* get the next msg for this timeslot */
229 msg = e1inp_tx_ts(e1i_ts, &sign_link);
230 if (!msg) {
231 /* no message after tx delay timer */
232 return 0;
233 }
234
235 switch (sign_link->type) {
236 case E1INP_SIGN_OML:
237 proto = IPAC_PROTO_OML;
238#ifdef HSL_SR_1_0
239 /* HSL uses 0x81 for FOM for some reason */
240 if (msg->data[0] == ABIS_OM_MDISC_FOM)
241 msg->data[0] = ABIS_OM_MDISC_FOM | 0x01;
242#endif
243 break;
244 case E1INP_SIGN_RSL:
245 proto = IPAC_PROTO_RSL;
246 break;
247 default:
248 msgb_free(msg);
249 bfd->when |= BSC_FD_WRITE; /* come back for more msg */
250 return -EINVAL;
251 }
252
253 msg->l2h = msg->data;
254 ipaccess_prepend_header(msg, sign_link->tei);
255
Harald Weltecc2241b2011-07-19 16:06:06 +0200256 DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg)));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200257
258 ret = send(bfd->fd, msg->data, msg->len, 0);
259 msgb_free(msg);
260
261 /* set tx delay timer for next event */
262 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
263 e1i_ts->sign.tx_timer.data = e1i_ts;
264
265 /* Reducing this might break the nanoBTS 900 init. */
266 osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
267
268 return ret;
269}
270
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200271static int handle_ts1_write(struct osmo_fd *bfd)
272{
273 struct e1inp_line *line = bfd->data;
274
275 return __handle_ts1_write(bfd, line);
276}
277
278int hsl_bts_write(struct ipa_client_link *link)
279{
280 struct e1inp_line *line = link->line;
281
282 return __handle_ts1_write(link->ofd, line);
283}
284
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200285/* callback from select.c in case one of the fd's can be read/written */
286static int hsl_fd_cb(struct osmo_fd *bfd, unsigned int what)
287{
288 struct e1inp_line *line = bfd->data;
289 unsigned int ts_nr = bfd->priv_nr;
290 unsigned int idx = ts_nr-1;
291 struct e1inp_ts *e1i_ts;
292 int rc = 0;
293
294 /* In case of early RSL we might not yet have a line */
295
296 if (line)
297 e1i_ts = &line->ts[idx];
298
299 if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) {
300 if (what & BSC_FD_READ)
301 rc = handle_ts1_read(bfd);
302 if (what & BSC_FD_WRITE)
303 rc = handle_ts1_write(bfd);
304 } else
Harald Weltecc2241b2011-07-19 16:06:06 +0200305 LOGP(DLINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200306
307 return rc;
308}
309
Pablo Neira Ayuso34073fb2011-07-08 20:36:05 +0200310static void hsl_close(struct e1inp_sign_link *sign_link)
311{
312 struct e1inp_ts *ts = sign_link->ts;
313 struct osmo_fd *bfd = &ts->driver.ipaccess.fd;
314 e1inp_event(ts, S_INP_TEI_DN, sign_link->tei, sign_link->sapi);
315 /* the first e1inp_sign_link_destroy call closes the socket. */
316 if (bfd->fd != -1) {
317 osmo_fd_unregister(bfd);
318 close(bfd->fd);
319 bfd->fd = -1;
320 }
321}
322
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200323static int hsl_line_update(struct e1inp_line *line,
324 enum e1inp_line_role role, const char *addr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200325
326struct e1inp_driver hsl_driver = {
327 .name = "hsl",
328 .want_write = ts_want_write,
329 .line_update = hsl_line_update,
Pablo Neira Ayuso34073fb2011-07-08 20:36:05 +0200330 .close = hsl_close,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200331 .default_delay = 0,
332};
333
334/* callback of the OML listening filedescriptor */
335static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what)
336{
337 int ret;
338 int idx = 0;
339 int i;
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200340 struct e1inp_line *line;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200341 struct e1inp_ts *e1i_ts;
342 struct osmo_fd *bfd;
343 struct sockaddr_in sa;
344 socklen_t sa_len = sizeof(sa);
345
346 if (!(what & BSC_FD_READ))
347 return 0;
348
349 ret = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len);
350 if (ret < 0) {
351 perror("accept");
352 return ret;
353 }
Harald Weltecc2241b2011-07-19 16:06:06 +0200354 LOGP(DLINP, LOGL_NOTICE, "accept()ed new HSL link from %s\n",
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200355 inet_ntoa(sa.sin_addr));
356
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200357 /* clone virtual E1 line for this new signalling link. */
358 line = e1inp_line_clone(tall_hsl_ctx, listen_bfd->data);
359 if (line == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200360 LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n");
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200361 return -1;
362 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200363 /* create virrtual E1 timeslots for signalling */
364 e1inp_ts_config_sign(&line->ts[1-1], line);
365
366 /* initialize the fds */
367 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
368 line->ts[i].driver.ipaccess.fd.fd = -1;
369
370 e1i_ts = &line->ts[idx];
371
372 bfd = &e1i_ts->driver.ipaccess.fd;
373 bfd->fd = ret;
374 bfd->data = line;
375 bfd->priv_nr = PRIV_OML;
376 bfd->cb = hsl_fd_cb;
377 bfd->when = BSC_FD_READ;
378 ret = osmo_fd_register(bfd);
379 if (ret < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200380 LOGP(DLINP, LOGL_ERROR, "could not register FD\n");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200381 close(bfd->fd);
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200382 e1inp_line_put(line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200383 return ret;
384 }
385
386 return ret;
387}
388
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200389static int hsl_bts_process(struct ipa_client_link *link, struct msgb *msg)
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200390{
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200391 struct ipaccess_head *hh;
392 struct e1inp_sign_link *sign_link;
393 struct e1inp_ts *e1i_ts = &link->line->ts[0];
394
395 hh = (struct ipaccess_head *) msg->data;
396 if (hh->proto == HSL_PROTO_DEBUG) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200397 LOGP(DLINP, LOGL_NOTICE, "HSL debug: %s\n",
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200398 msg->data + sizeof(*hh));
399 msgb_free(msg);
400 return 0;
401 }
402 sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
403 if (!sign_link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200404 LOGP(DLINP, LOGL_ERROR, "no matching signalling link for "
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200405 "hh->proto=0x%02x\n", hh->proto);
406 msgb_free(msg);
407 return -EIO;
408 }
409 msg->dst = sign_link;
410
411 /* XXX better use e1inp_ts_rx? */
412 if (!link->line->ops->sign_link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200413 LOGP(DLINP, LOGL_ERROR, "Fix your application, "
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200414 "no action set for signalling messages.\n");
415 return -ENOENT;
416 }
417 link->line->ops->sign_link(msg);
418 return 0;
419}
420
421static int hsl_bts_connect(struct ipa_client_link *link)
422{
423 struct msgb *msg;
424 uint8_t *serno;
425 char serno_buf[16];
426 struct hsl_unit *unit = link->line->ops->data;
427 struct e1inp_sign_link *sign_link;
428
429 /* send the minimal message to identify this BTS. */
430 msg = ipa_msg_alloc(0);
431 if (!msg)
432 return -ENOMEM;
433
434 *msgb_put(msg, 1) = 0x80;
435 *msgb_put(msg, 1) = 0x80;
436 *msgb_put(msg, 1) = unit->swversion;
437 snprintf(serno_buf, sizeof(serno_buf), "%llx", unit->serno);
438 serno = msgb_put(msg, strlen(serno_buf)+1);
439 memcpy(serno, serno_buf, strlen(serno_buf));
440 ipa_msg_push_header(msg, 0);
441 send(link->ofd->fd, msg->data, msg->len, 0);
442 msgb_free(msg);
443
444 /* ... and enable the signalling link. */
445 if (!link->line->ops->sign_link_up) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200446 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200447 "Unable to set signal link, closing socket.\n");
448 ipa_client_link_close(link);
449 return -EINVAL;
450 }
451 sign_link = link->line->ops->sign_link_up(&unit,
452 link->line, E1INP_SIGN_NONE);
453 if (sign_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200454 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200455 "Unable to set signal link, closing socket.\n");
456 ipa_client_link_close(link);
457 return -EINVAL;
458 }
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200459 return 0;
460}
461
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200462static int hsl_line_update(struct e1inp_line *line,
463 enum e1inp_line_role role, const char *addr)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200464{
465 int ret = -ENOENT;
466
467 switch(role) {
468 case E1INP_LINE_R_BSC:
Harald Weltecc2241b2011-07-19 16:06:06 +0200469 LOGP(DLINP, LOGL_NOTICE, "enabling hsl BSC mode\n");
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200470
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200471 ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200472 addr, HSL_TCP_PORT, OSMO_SOCK_F_BIND);
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200473 if (ret < 0)
474 return ret;
475
476 e1h->listen_fd.fd = ret;
477 e1h->listen_fd.when |= BSC_FD_READ;
478 e1h->listen_fd.cb = listen_fd_cb;
479 e1h->listen_fd.data = line;
480
481 if (osmo_fd_register(&e1h->listen_fd) < 0) {
482 close(ret);
483 return ret;
484 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200485 break;
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200486 case E1INP_LINE_R_BTS: {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200487 struct ipa_client_link *link;
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200488
Harald Weltecc2241b2011-07-19 16:06:06 +0200489 LOGP(DLINP, LOGL_NOTICE, "enabling hsl BTS mode\n");
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200490
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200491 link = ipa_client_link_create(tall_hsl_ctx,
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200492 &line->ts[E1INP_SIGN_OML-1],
493 "hsl", E1INP_SIGN_OML,
494 addr, HSL_TCP_PORT,
495 hsl_bts_connect,
496 hsl_bts_process,
497 hsl_bts_write,
498 NULL);
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200499 if (link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200500 LOGP(DLINP, LOGL_ERROR, "cannot create BTS link: %s\n",
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200501 strerror(errno));
502 return -ENOMEM;
503 }
504 if (ipa_client_link_open(link) < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200505 LOGP(DLINP, LOGL_ERROR, "cannot open BTS link: %s\n",
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200506 strerror(errno));
507 ipa_client_link_close(link);
508 ipa_client_link_destroy(link);
509 return -EIO;
510 }
511 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200512 break;
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200513 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200514 default:
515 break;
516 }
517 return ret;
518}
519
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200520void e1inp_hsl_init(void)
521{
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200522 tall_hsl_ctx = talloc_named_const(libosmo_abis_ctx, 1, "hsl");
523
524 e1h = talloc_zero(tall_hsl_ctx, struct hsl_e1_handle);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200525 if (!e1h)
526 return;
527
528 e1inp_driver_register(&hsl_driver);
529}