blob: d5010d19a4b4e7341507d06f9263645b9c6f18a2 [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;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200223 int ret;
224
225 bfd->when &= ~BSC_FD_WRITE;
226
227 /* get the next msg for this timeslot */
228 msg = e1inp_tx_ts(e1i_ts, &sign_link);
229 if (!msg) {
230 /* no message after tx delay timer */
231 return 0;
232 }
233
234 switch (sign_link->type) {
235 case E1INP_SIGN_OML:
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200236#ifdef HSL_SR_1_0
237 /* HSL uses 0x81 for FOM for some reason */
238 if (msg->data[0] == ABIS_OM_MDISC_FOM)
239 msg->data[0] = ABIS_OM_MDISC_FOM | 0x01;
240#endif
241 break;
242 case E1INP_SIGN_RSL:
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200243 break;
244 default:
245 msgb_free(msg);
246 bfd->when |= BSC_FD_WRITE; /* come back for more msg */
247 return -EINVAL;
248 }
249
250 msg->l2h = msg->data;
251 ipaccess_prepend_header(msg, sign_link->tei);
252
Harald Weltecc2241b2011-07-19 16:06:06 +0200253 DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg)));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200254
255 ret = send(bfd->fd, msg->data, msg->len, 0);
256 msgb_free(msg);
257
258 /* set tx delay timer for next event */
259 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
260 e1i_ts->sign.tx_timer.data = e1i_ts;
261
262 /* Reducing this might break the nanoBTS 900 init. */
263 osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
264
265 return ret;
266}
267
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200268static int handle_ts1_write(struct osmo_fd *bfd)
269{
270 struct e1inp_line *line = bfd->data;
271
272 return __handle_ts1_write(bfd, line);
273}
274
275int hsl_bts_write(struct ipa_client_link *link)
276{
277 struct e1inp_line *line = link->line;
278
279 return __handle_ts1_write(link->ofd, line);
280}
281
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200282/* callback from select.c in case one of the fd's can be read/written */
283static int hsl_fd_cb(struct osmo_fd *bfd, unsigned int what)
284{
285 struct e1inp_line *line = bfd->data;
286 unsigned int ts_nr = bfd->priv_nr;
287 unsigned int idx = ts_nr-1;
288 struct e1inp_ts *e1i_ts;
289 int rc = 0;
290
291 /* In case of early RSL we might not yet have a line */
292
293 if (line)
294 e1i_ts = &line->ts[idx];
295
296 if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) {
297 if (what & BSC_FD_READ)
298 rc = handle_ts1_read(bfd);
299 if (what & BSC_FD_WRITE)
300 rc = handle_ts1_write(bfd);
301 } else
Harald Weltecc2241b2011-07-19 16:06:06 +0200302 LOGP(DLINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200303
304 return rc;
305}
306
Pablo Neira Ayuso34073fb2011-07-08 20:36:05 +0200307static void hsl_close(struct e1inp_sign_link *sign_link)
308{
309 struct e1inp_ts *ts = sign_link->ts;
310 struct osmo_fd *bfd = &ts->driver.ipaccess.fd;
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200311 e1inp_event(ts, S_L_INP_TEI_DN, sign_link->tei, sign_link->sapi);
Pablo Neira Ayuso34073fb2011-07-08 20:36:05 +0200312 /* the first e1inp_sign_link_destroy call closes the socket. */
313 if (bfd->fd != -1) {
314 osmo_fd_unregister(bfd);
315 close(bfd->fd);
316 bfd->fd = -1;
317 }
318}
319
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200320static int hsl_line_update(struct e1inp_line *line,
321 enum e1inp_line_role role, const char *addr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200322
323struct e1inp_driver hsl_driver = {
324 .name = "hsl",
325 .want_write = ts_want_write,
326 .line_update = hsl_line_update,
Pablo Neira Ayuso34073fb2011-07-08 20:36:05 +0200327 .close = hsl_close,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200328 .default_delay = 0,
329};
330
331/* callback of the OML listening filedescriptor */
332static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what)
333{
334 int ret;
335 int idx = 0;
336 int i;
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200337 struct e1inp_line *line;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200338 struct e1inp_ts *e1i_ts;
339 struct osmo_fd *bfd;
340 struct sockaddr_in sa;
341 socklen_t sa_len = sizeof(sa);
342
343 if (!(what & BSC_FD_READ))
344 return 0;
345
346 ret = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len);
347 if (ret < 0) {
348 perror("accept");
349 return ret;
350 }
Harald Weltecc2241b2011-07-19 16:06:06 +0200351 LOGP(DLINP, LOGL_NOTICE, "accept()ed new HSL link from %s\n",
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200352 inet_ntoa(sa.sin_addr));
353
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200354 /* clone virtual E1 line for this new signalling link. */
355 line = e1inp_line_clone(tall_hsl_ctx, listen_bfd->data);
356 if (line == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200357 LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n");
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200358 return -1;
359 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200360 /* create virrtual E1 timeslots for signalling */
361 e1inp_ts_config_sign(&line->ts[1-1], line);
362
363 /* initialize the fds */
364 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
365 line->ts[i].driver.ipaccess.fd.fd = -1;
366
367 e1i_ts = &line->ts[idx];
368
369 bfd = &e1i_ts->driver.ipaccess.fd;
370 bfd->fd = ret;
371 bfd->data = line;
372 bfd->priv_nr = PRIV_OML;
373 bfd->cb = hsl_fd_cb;
374 bfd->when = BSC_FD_READ;
375 ret = osmo_fd_register(bfd);
376 if (ret < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200377 LOGP(DLINP, LOGL_ERROR, "could not register FD\n");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200378 close(bfd->fd);
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200379 e1inp_line_put(line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200380 return ret;
381 }
382
383 return ret;
384}
385
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200386static int hsl_bts_process(struct ipa_client_link *link, struct msgb *msg)
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200387{
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200388 struct ipaccess_head *hh;
389 struct e1inp_sign_link *sign_link;
390 struct e1inp_ts *e1i_ts = &link->line->ts[0];
391
392 hh = (struct ipaccess_head *) msg->data;
393 if (hh->proto == HSL_PROTO_DEBUG) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200394 LOGP(DLINP, LOGL_NOTICE, "HSL debug: %s\n",
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200395 msg->data + sizeof(*hh));
396 msgb_free(msg);
397 return 0;
398 }
399 sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
400 if (!sign_link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200401 LOGP(DLINP, LOGL_ERROR, "no matching signalling link for "
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200402 "hh->proto=0x%02x\n", hh->proto);
403 msgb_free(msg);
404 return -EIO;
405 }
406 msg->dst = sign_link;
407
408 /* XXX better use e1inp_ts_rx? */
409 if (!link->line->ops->sign_link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200410 LOGP(DLINP, LOGL_ERROR, "Fix your application, "
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200411 "no action set for signalling messages.\n");
412 return -ENOENT;
413 }
414 link->line->ops->sign_link(msg);
415 return 0;
416}
417
418static int hsl_bts_connect(struct ipa_client_link *link)
419{
420 struct msgb *msg;
421 uint8_t *serno;
422 char serno_buf[16];
423 struct hsl_unit *unit = link->line->ops->data;
424 struct e1inp_sign_link *sign_link;
425
426 /* send the minimal message to identify this BTS. */
427 msg = ipa_msg_alloc(0);
428 if (!msg)
429 return -ENOMEM;
430
431 *msgb_put(msg, 1) = 0x80;
432 *msgb_put(msg, 1) = 0x80;
433 *msgb_put(msg, 1) = unit->swversion;
434 snprintf(serno_buf, sizeof(serno_buf), "%llx", unit->serno);
435 serno = msgb_put(msg, strlen(serno_buf)+1);
436 memcpy(serno, serno_buf, strlen(serno_buf));
437 ipa_msg_push_header(msg, 0);
438 send(link->ofd->fd, msg->data, msg->len, 0);
439 msgb_free(msg);
440
441 /* ... and enable the signalling link. */
442 if (!link->line->ops->sign_link_up) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200443 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200444 "Unable to set signal link, closing socket.\n");
445 ipa_client_link_close(link);
446 return -EINVAL;
447 }
448 sign_link = link->line->ops->sign_link_up(&unit,
449 link->line, E1INP_SIGN_NONE);
450 if (sign_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200451 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200452 "Unable to set signal link, closing socket.\n");
453 ipa_client_link_close(link);
454 return -EINVAL;
455 }
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200456 return 0;
457}
458
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200459static int hsl_line_update(struct e1inp_line *line,
460 enum e1inp_line_role role, const char *addr)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200461{
462 int ret = -ENOENT;
463
464 switch(role) {
465 case E1INP_LINE_R_BSC:
Harald Weltecc2241b2011-07-19 16:06:06 +0200466 LOGP(DLINP, LOGL_NOTICE, "enabling hsl BSC mode\n");
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200467
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200468 ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200469 addr, HSL_TCP_PORT, OSMO_SOCK_F_BIND);
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +0200470 if (ret < 0)
471 return ret;
472
473 e1h->listen_fd.fd = ret;
474 e1h->listen_fd.when |= BSC_FD_READ;
475 e1h->listen_fd.cb = listen_fd_cb;
476 e1h->listen_fd.data = line;
477
478 if (osmo_fd_register(&e1h->listen_fd) < 0) {
479 close(ret);
480 return ret;
481 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200482 break;
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200483 case E1INP_LINE_R_BTS: {
Pablo Neira Ayusoc07a8e72011-06-21 19:50:04 +0200484 struct ipa_client_link *link;
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200485
Harald Weltecc2241b2011-07-19 16:06:06 +0200486 LOGP(DLINP, LOGL_NOTICE, "enabling hsl BTS mode\n");
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200487
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200488 link = ipa_client_link_create(tall_hsl_ctx,
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200489 &line->ts[E1INP_SIGN_OML-1],
490 "hsl", E1INP_SIGN_OML,
491 addr, HSL_TCP_PORT,
492 hsl_bts_connect,
493 hsl_bts_process,
494 hsl_bts_write,
495 NULL);
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200496 if (link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200497 LOGP(DLINP, LOGL_ERROR, "cannot create BTS link: %s\n",
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200498 strerror(errno));
499 return -ENOMEM;
500 }
501 if (ipa_client_link_open(link) < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200502 LOGP(DLINP, LOGL_ERROR, "cannot open BTS link: %s\n",
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200503 strerror(errno));
504 ipa_client_link_close(link);
505 ipa_client_link_destroy(link);
506 return -EIO;
507 }
508 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200509 break;
Pablo Neira Ayuso9b3a33c2011-06-21 13:52:41 +0200510 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200511 default:
512 break;
513 }
514 return ret;
515}
516
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200517void e1inp_hsl_init(void)
518{
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200519 tall_hsl_ctx = talloc_named_const(libosmo_abis_ctx, 1, "hsl");
520
521 e1h = talloc_zero(tall_hsl_ctx, struct hsl_e1_handle);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200522 if (!e1h)
523 return;
524
525 e1inp_driver_register(&hsl_driver);
526}