blob: f62e4b0c2ec52e590d795ee703ca4dc43baf9f99 [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>
Pablo Neira Ayusoeb434132011-07-07 19:19:46 +020029#include <stdbool.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020030#include <errno.h>
Daniel Willmann85980722014-01-09 14:30:55 +010031#include <netinet/tcp.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020032#include <string.h>
33#include <time.h>
34#include <sys/fcntl.h>
35#include <sys/socket.h>
36#include <sys/ioctl.h>
37#include <arpa/inet.h>
38
39#include <osmocom/core/select.h>
40#include <osmocom/gsm/tlv.h>
41#include <osmocom/core/msgb.h>
42#include <osmocom/core/logging.h>
Harald Welte71d87b22011-07-18 14:49:56 +020043#include <osmocom/core/talloc.h>
Pablo Neira Ayuso177094b2011-06-07 12:21:51 +020044#include <osmocom/abis/e1_input.h>
45#include <osmocom/abis/ipaccess.h>
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +020046#include <osmocom/core/socket.h>
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +020047#include <osmocom/abis/ipa.h>
Pablo Neira Ayusoef132692013-07-08 01:17:27 +020048#include <osmocom/core/backtrace.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020049
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +020050static void *tall_ipa_ctx;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020051
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020052#define TS1_ALLOC_SIZE 900
53
Daniel Willmann85980722014-01-09 14:30:55 +010054#define DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT 30
55#define DEFAULT_TCP_KEEPALIVE_INTERVAL 3
56#define DEFAULT_TCP_KEEPALIVE_RETRY_COUNT 10
57
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020058/*
59 * Common propietary IPA messages:
60 * - PONG: in reply to PING.
61 * - ID_REQUEST: first messages once OML has been established.
62 * - ID_ACK: in reply to ID_ACK.
63 */
Holger Hans Peter Freyther901ef1c2014-01-16 15:35:53 +010064static const uint8_t ipa_pong_msg[] = {
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020065 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG
66};
67
Holger Hans Peter Freyther901ef1c2014-01-16 15:35:53 +010068static const uint8_t ipa_id_ack_msg[] = {
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020069 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK
70};
71
Holger Hans Peter Freyther901ef1c2014-01-16 15:35:53 +010072static const uint8_t ipa_id_req_msg[] = {
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020073 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
74 0x01, IPAC_IDTAG_UNIT,
75 0x01, IPAC_IDTAG_MACADDR,
76 0x01, IPAC_IDTAG_LOCATION1,
77 0x01, IPAC_IDTAG_LOCATION2,
78 0x01, IPAC_IDTAG_EQUIPVERS,
79 0x01, IPAC_IDTAG_SWVERSION,
80 0x01, IPAC_IDTAG_UNITNAME,
81 0x01, IPAC_IDTAG_SERNR,
82};
83
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +020084static const char *idtag_names[] = {
85 [IPAC_IDTAG_SERNR] = "Serial_Number",
86 [IPAC_IDTAG_UNITNAME] = "Unit_Name",
87 [IPAC_IDTAG_LOCATION1] = "Location_1",
88 [IPAC_IDTAG_LOCATION2] = "Location_2",
89 [IPAC_IDTAG_EQUIPVERS] = "Equipment_Version",
90 [IPAC_IDTAG_SWVERSION] = "Software_Version",
91 [IPAC_IDTAG_IPADDR] = "IP_Address",
92 [IPAC_IDTAG_MACADDR] = "MAC_Address",
93 [IPAC_IDTAG_UNIT] = "Unit_ID",
94};
95
96const char *ipaccess_idtag_name(uint8_t tag)
97{
98 if (tag >= ARRAY_SIZE(idtag_names))
99 return "unknown";
100
101 return idtag_names[tag];
102}
103
104int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len)
105{
106 uint8_t t_len;
107 uint8_t t_tag;
108 uint8_t *cur = buf;
109
110 memset(dec, 0, sizeof(*dec));
111
112 while (len >= 2) {
113 len -= 2;
114 t_len = *cur++;
115 t_tag = *cur++;
116
117 if (t_len > len + 1) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200118 LOGP(DLMI, LOGL_ERROR, "The tag does not fit: %d\n", t_len);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200119 return -EINVAL;
120 }
121
Harald Weltecc2241b2011-07-19 16:06:06 +0200122 DEBUGPC(DLMI, "%s='%s' ", ipaccess_idtag_name(t_tag), cur);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200123
124 dec->lv[t_tag].len = t_len;
125 dec->lv[t_tag].val = cur;
126
127 cur += t_len;
128 len -= t_len;
129 }
130 return 0;
131}
132
133int ipaccess_parse_unitid(const char *str, struct ipaccess_unit *unit_data)
134{
135 unsigned long ul;
136 char *endptr;
137 const char *nptr;
138
139 nptr = str;
140 ul = strtoul(nptr, &endptr, 10);
141 if (endptr <= nptr)
142 return -EINVAL;
Pablo Neira Ayuso62d345a2011-07-05 16:37:37 +0200143 unit_data->site_id = ul & 0xffff;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200144
145 if (*endptr++ != '/')
146 return -EINVAL;
147
148 nptr = endptr;
149 ul = strtoul(nptr, &endptr, 10);
150 if (endptr <= nptr)
151 return -EINVAL;
Pablo Neira Ayuso62d345a2011-07-05 16:37:37 +0200152 unit_data->bts_id = ul & 0xffff;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200153
154 if (*endptr++ != '/')
155 return -EINVAL;
156
157 nptr = endptr;
158 ul = strtoul(nptr, &endptr, 10);
159 if (endptr <= nptr)
160 return -EINVAL;
Pablo Neira Ayuso62d345a2011-07-05 16:37:37 +0200161 unit_data->trx_id = ul & 0xffff;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200162
163 return 0;
164}
165
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200166static int ipaccess_send(int fd, const void *msg, size_t msglen)
167{
168 int ret;
169
170 ret = write(fd, msg, msglen);
171 if (ret < 0)
172 return ret;
173 if (ret < msglen) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200174 LOGP(DLINP, LOGL_ERROR, "ipaccess_send: short write\n");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200175 return -EIO;
176 }
177 return ret;
178}
179
180int ipaccess_send_pong(int fd)
181{
182 return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg));
183}
184
185int ipaccess_send_id_ack(int fd)
186{
187 return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg));
188}
189
190int ipaccess_send_id_req(int fd)
191{
192 return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg));
193}
194
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200195/* base handling of the ip.access protocol */
Harald Weltebc25bca2011-08-19 22:32:38 +0200196int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd)
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200197{
198 uint8_t msg_type = *(msg->l2h);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200199 int ret;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200200
201 switch (msg_type) {
202 case IPAC_MSGT_PING:
203 ret = ipaccess_send_pong(bfd->fd);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200204 if (ret < 0) {
205 LOGP(DLINP, LOGL_ERROR, "Cannot send PING "
206 "message. Reason: %s\n", strerror(errno));
207 break;
208 }
209 ret = 1;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200210 break;
211 case IPAC_MSGT_PONG:
Harald Weltecc2241b2011-07-19 16:06:06 +0200212 DEBUGP(DLMI, "PONG!\n");
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200213 ret = 1;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200214 break;
215 case IPAC_MSGT_ID_ACK:
Harald Weltecc2241b2011-07-19 16:06:06 +0200216 DEBUGP(DLMI, "ID_ACK? -> ACK!\n");
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200217 ret = ipaccess_send_id_ack(bfd->fd);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200218 if (ret < 0) {
219 LOGP(DLINP, LOGL_ERROR, "Cannot send ID_ACK "
220 "message. Reason: %s\n", strerror(errno));
221 break;
222 }
223 ret = 1;
224 break;
225 default:
226 /* This is not an IPA PING, PONG or ID_ACK message */
227 ret = 0;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200228 break;
229 }
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200230 return ret;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200231}
232
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200233/* base handling of the ip.access protocol */
234int ipaccess_rcvmsg_bts_base(struct msgb *msg,
235 struct osmo_fd *bfd)
236{
237 uint8_t msg_type = *(msg->l2h);
238 int ret = 0;
239
240 switch (msg_type) {
241 case IPAC_MSGT_PING:
242 ret = ipaccess_send_pong(bfd->fd);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200243 if (ret < 0) {
244 LOGP(DLINP, LOGL_ERROR, "Cannot send PONG "
245 "message. Reason: %s\n", strerror(errno));
246 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200247 break;
248 case IPAC_MSGT_PONG:
Harald Weltecc2241b2011-07-19 16:06:06 +0200249 DEBUGP(DLMI, "PONG!\n");
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200250 break;
251 case IPAC_MSGT_ID_ACK:
Harald Weltecc2241b2011-07-19 16:06:06 +0200252 DEBUGP(DLMI, "ID_ACK\n");
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200253 break;
254 }
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200255 return ret;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200256}
257
Harald Welte10b41302013-06-30 14:05:49 +0200258static int ipaccess_drop(struct osmo_fd *bfd, struct e1inp_line *line)
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200259{
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200260 int ret = 1;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200261 unsigned int ts_nr = bfd->priv_nr;
262 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200263
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200264 /* Error case: we did not see any ID_RESP yet for this socket. */
265 if (bfd->fd != -1) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200266 LOGP(DLINP, LOGL_ERROR, "Forcing socket shutdown with "
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200267 "no signal link set\n");
Pablo Neira Ayuso9621b412011-07-07 16:19:21 +0200268 osmo_fd_unregister(bfd);
269 close(bfd->fd);
270 bfd->fd = -1;
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200271 ret = -ENOENT;
Pablo Neira Ayuso9621b412011-07-07 16:19:21 +0200272 }
Pablo Neira Ayuso6cc3f922012-08-22 13:57:58 +0200273
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200274 msgb_free(e1i_ts->pending_msg);
275 e1i_ts->pending_msg = NULL;
276
Pablo Neira Ayuso6cc3f922012-08-22 13:57:58 +0200277 /* e1inp_sign_link_destroy releases the socket descriptors for us. */
278 line->ops->sign_link_down(line);
279
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200280 return ret;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200281}
282
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200283static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg,
284 struct osmo_fd *bfd)
285{
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200286 struct tlv_parsed tlvp;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200287 uint8_t msg_type = *(msg->l2h);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200288 struct ipaccess_unit unit_data = {};
289 struct e1inp_sign_link *sign_link;
290 char *unitid;
291 int len, ret;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200292
Pablo Neira Ayusoeb434132011-07-07 19:19:46 +0200293 /* Handle IPA PING, PONG and ID_ACK messages. */
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200294 ret = ipaccess_rcvmsg_base(msg, bfd);
295 switch(ret) {
296 case -1:
297 /* error in IPA control message handling */
298 goto err;
299 case 1:
300 /* this is an IPA control message, skip further processing */
Pablo Neira Ayusoeb434132011-07-07 19:19:46 +0200301 return 0;
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200302 case 0:
303 /* this is not an IPA control message, continue */
304 break;
305 default:
306 LOGP(DLINP, LOGL_ERROR, "Unexpected return from "
307 "ipaccess_rcvmsg_base "
308 "(ret=%d)\n", ret);
309 goto err;
310 }
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200311
312 switch (msg_type) {
313 case IPAC_MSGT_ID_RESP:
Harald Weltecc2241b2011-07-19 16:06:06 +0200314 DEBUGP(DLMI, "ID_RESP\n");
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200315 /* parse tags, search for Unit ID */
316 ret = ipaccess_idtag_parse(&tlvp, (uint8_t *)msg->l2h + 2,
317 msgb_l2len(msg)-2);
Harald Weltecc2241b2011-07-19 16:06:06 +0200318 DEBUGP(DLMI, "\n");
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200319 if (ret < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200320 LOGP(DLINP, LOGL_ERROR, "IPA response message "
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200321 "with malformed TLVs\n");
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200322 ret = -EINVAL;
323 goto err;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200324 }
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200325 if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT)) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200326 LOGP(DLINP, LOGL_ERROR, "IPA response message "
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200327 "without unit ID\n");
328 ret = -EINVAL;
329 goto err;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200330
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200331 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200332 len = TLVP_LEN(&tlvp, IPAC_IDTAG_UNIT);
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200333 if (len < 1) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200334 LOGP(DLINP, LOGL_ERROR, "IPA response message "
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200335 "with too small unit ID\n");
336 ret = -EINVAL;
337 goto err;
338 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200339 unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT);
340 unitid[len - 1] = '\0';
341 ipaccess_parse_unitid(unitid, &unit_data);
342
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200343 if (!line->ops->sign_link_up) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200344 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +0200345 "Unable to set signal link, closing socket.\n");
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200346 ret = -EINVAL;
347 goto err;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200348 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200349 /* the BSC creates the new sign links at this stage. */
350 if (bfd->priv_nr == E1INP_SIGN_OML) {
351 sign_link =
352 line->ops->sign_link_up(&unit_data, line,
353 E1INP_SIGN_OML);
354 if (sign_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200355 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +0200356 "Unable to set signal link, "
357 "closing socket.\n");
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200358 ret = -EINVAL;
359 goto err;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200360 }
361 } else if (bfd->priv_nr == E1INP_SIGN_RSL) {
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200362 struct e1inp_ts *ts;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200363 struct osmo_fd *newbfd;
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200364 struct e1inp_line *new_line;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200365
366 sign_link =
367 line->ops->sign_link_up(&unit_data, line,
368 E1INP_SIGN_RSL);
369 if (sign_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200370 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayusocd8d2e52011-07-02 17:05:21 +0200371 "Unable to set signal link, "
372 "closing socket.\n");
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200373 ret = -EINVAL;
374 goto err;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200375 }
Pablo Neira Ayusodb1c8a72011-07-08 15:12:03 +0200376 /* this is a bugtrap, the BSC should be using the
377 * virtual E1 line used by OML for this RSL link. */
378 if (sign_link->ts->line == line) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200379 LOGP(DLINP, LOGL_ERROR,
Pablo Neira Ayusodb1c8a72011-07-08 15:12:03 +0200380 "Fix your BSC, you should use the "
381 "E1 line used by the OML link for "
382 "your RSL link.\n");
383 return 0;
384 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200385 /* Finally, we know which OML link is associated with
386 * this RSL link, attach it to this socket. */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200387 bfd->data = new_line = sign_link->ts->line;
388 e1inp_line_get(new_line);
389 ts = &new_line->ts[E1INP_SIGN_RSL+unit_data.trx_id-1];
390 newbfd = &ts->driver.ipaccess.fd;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200391
392 /* get rid of our old temporary bfd */
393 memcpy(newbfd, bfd, sizeof(*newbfd));
394 newbfd->priv_nr = E1INP_SIGN_RSL + unit_data.trx_id;
395 osmo_fd_unregister(bfd);
396 bfd->fd = -1;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200397 osmo_fd_register(newbfd);
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200398 /* now we can release the dummy RSL line. */
399 e1inp_line_put(line);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200400 }
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200401 break;
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200402 default:
Harald Weltecc2241b2011-07-19 16:06:06 +0200403 LOGP(DLINP, LOGL_ERROR, "Unknown IPA message type\n");
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200404 ret = -EINVAL;
405 goto err;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200406 }
407 return 0;
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200408err:
409 osmo_fd_unregister(bfd);
410 close(bfd->fd);
411 bfd->fd = -1;
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200412 e1inp_line_put(line);
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200413 return ret;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200414}
415
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200416static int handle_ts1_read(struct osmo_fd *bfd)
417{
418 struct e1inp_line *line = bfd->data;
419 unsigned int ts_nr = bfd->priv_nr;
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200420 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200421 struct e1inp_sign_link *link;
422 struct ipaccess_head *hh;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200423 struct msgb *msg = NULL;
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200424 int ret;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200425
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200426 ret = ipa_msg_recv_buffered(bfd->fd, &msg, &e1i_ts->pending_msg);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200427 if (ret < 0) {
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200428 if (ret == -EAGAIN)
429 return 0;
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200430 LOGP(DLINP, LOGL_NOTICE, "Sign link problems, "
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200431 "closing socket. Reason: %s\n", strerror(-ret));
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200432 goto err;
433 } else if (ret == 0) {
434 LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, dead socket\n");
435 goto err;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200436 }
Harald Weltecc2241b2011-07-19 16:06:06 +0200437 DEBUGP(DLMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200438
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200439 hh = (struct ipaccess_head *) msg->data;
440 if (hh->proto == IPAC_PROTO_IPACCESS) {
441 ipaccess_rcvmsg(line, msg, bfd);
442 msgb_free(msg);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200443 return 0;
Holger Hans Peter Freyther63ddf462013-12-28 21:19:19 +0100444 } else if (e1i_ts->type == E1INP_TS_TYPE_NONE) {
445 /* this sign link is not know yet.. complain. */
446 LOGP(DLINP, LOGL_ERROR, "Timeslot is not configured.\n");
447 ret = -EINVAL;
448 goto err_msg;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200449 }
450 /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg()
451 * might have free'd it !!! */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200452
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200453 link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
454 if (!link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200455 LOGP(DLINP, LOGL_ERROR, "no matching signalling link for "
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200456 "hh->proto=0x%02x\n", hh->proto);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200457 ret = -EINVAL;
458 goto err_msg;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200459 }
460 msg->dst = link;
461
462 /* XXX better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200463 if (!e1i_ts->line->ops->sign_link) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200464 LOGP(DLINP, LOGL_ERROR, "Fix your application, "
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200465 "no action set for signalling messages.\n");
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200466 ret = -EINVAL;
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200467 goto err_msg;
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200468 }
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200469 if (e1i_ts->line->ops->sign_link(msg) < 0) {
Pablo Neira Ayusoa49c24d2012-10-16 11:24:08 +0200470 /* Don't close the signalling link if the upper layers report
471 * an error, that's too strict. BTW, the signalling layer is
472 * resposible for releasing the message.
473 */
Harald Weltecc2241b2011-07-19 16:06:06 +0200474 LOGP(DLINP, LOGL_ERROR, "Bad signalling message,"
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200475 "sign_link returned error\n");
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200476 }
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200477
478 return 0;
479err_msg:
480 msgb_free(msg);
Pablo Neira Ayuso466c5462011-07-07 19:17:20 +0200481err:
Harald Welte10b41302013-06-30 14:05:49 +0200482 ipaccess_drop(bfd, line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200483 return ret;
484}
485
486void ipaccess_prepend_header_ext(struct msgb *msg, int proto)
487{
488 struct ipaccess_head_ext *hh_ext;
489
490 /* prepend the osmo ip.access header extension */
491 hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext));
492 hh_ext->proto = proto;
493}
494
495void ipaccess_prepend_header(struct msgb *msg, int proto)
496{
497 struct ipaccess_head *hh;
498
499 /* prepend the ip.access header */
500 hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh));
501 hh->len = htons(msg->len - sizeof(*hh));
502 hh->proto = proto;
503}
504
505static int ts_want_write(struct e1inp_ts *e1i_ts)
506{
507 e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE;
508
509 return 0;
510}
511
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200512static void ipaccess_close(struct e1inp_sign_link *sign_link)
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200513{
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200514 struct e1inp_ts *e1i_ts = sign_link->ts;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200515 struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd;
Holger Hans Peter Freyther55467f02011-12-28 19:47:07 +0100516 return e1inp_close_socket(e1i_ts, sign_link, bfd);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200517}
518
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200519static void timeout_ts1_write(void *data)
520{
521 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
522
523 /* trigger write of ts1, due to tx delay timer */
524 ts_want_write(e1i_ts);
525}
526
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200527static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200528{
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200529 unsigned int ts_nr = bfd->priv_nr;
530 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
531 struct e1inp_sign_link *sign_link;
532 struct msgb *msg;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200533 int ret;
534
535 bfd->when &= ~BSC_FD_WRITE;
536
537 /* get the next msg for this timeslot */
538 msg = e1inp_tx_ts(e1i_ts, &sign_link);
539 if (!msg) {
540 /* no message after tx delay timer */
541 return 0;
542 }
543
544 switch (sign_link->type) {
545 case E1INP_SIGN_OML:
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200546 break;
547 case E1INP_SIGN_RSL:
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200548 break;
549 default:
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200550 bfd->when |= BSC_FD_WRITE; /* come back for more msg */
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200551 ret = -EINVAL;
552 goto out;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200553 }
554
555 msg->l2h = msg->data;
Pablo Neira Ayusob9ed7e32011-07-05 18:31:59 +0200556 ipaccess_prepend_header(msg, sign_link->tei);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200557
Harald Weltecc2241b2011-07-19 16:06:06 +0200558 DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg)));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200559
560 ret = send(bfd->fd, msg->data, msg->len, 0);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200561 if (ret != msg->len) {
562 LOGP(DLINP, LOGL_ERROR, "failed to send A-bis IPA signalling "
563 "message. Reason: %s\n", strerror(errno));
564 goto err;
565 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200566
567 /* set tx delay timer for next event */
568 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
569 e1i_ts->sign.tx_timer.data = e1i_ts;
570
571 /* Reducing this might break the nanoBTS 900 init. */
572 osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
573
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200574out:
575 msgb_free(msg);
576 return ret;
577err:
Harald Welte10b41302013-06-30 14:05:49 +0200578 ipaccess_drop(bfd, line);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200579 msgb_free(msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200580 return ret;
581}
582
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200583static int handle_ts1_write(struct osmo_fd *bfd)
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200584{
585 struct e1inp_line *line = bfd->data;
586
587 return __handle_ts1_write(bfd, line);
588}
589
Pablo Neira Ayusof0995672011-09-08 12:58:38 +0200590static int ipaccess_bts_write_cb(struct ipa_client_conn *link)
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200591{
592 struct e1inp_line *line = link->line;
593
594 return __handle_ts1_write(link->ofd, line);
595}
596
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200597/* callback from select.c in case one of the fd's can be read/written */
Pablo Neira Ayuso495ddb62011-07-08 21:04:11 +0200598int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200599{
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200600 int rc = 0;
601
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200602 if (what & BSC_FD_READ)
603 rc = handle_ts1_read(bfd);
604 if (what & BSC_FD_WRITE)
605 rc = handle_ts1_write(bfd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200606
607 return rc;
608}
609
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200610static int ipaccess_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200611
612struct e1inp_driver ipaccess_driver = {
613 .name = "ipa",
614 .want_write = ts_want_write,
615 .line_update = ipaccess_line_update,
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200616 .close = ipaccess_close,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200617 .default_delay = 0,
Jacob Erlbeck8fe15712014-01-09 14:30:58 +0100618 .has_keepalive = 1,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200619};
620
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100621static void update_fd_settings(struct e1inp_line *line, int fd)
622{
623 int ret;
624 int val;
625
Jacob Erlbeck8fe15712014-01-09 14:30:58 +0100626 if (line->keepalive_num_probes) {
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100627 /* Enable TCP keepalive to find out if the connection is gone */
628 val = 1;
629 ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
630 if (ret < 0)
631 LOGP(DLINP, LOGL_NOTICE, "Failed to set keepalive: %s\n",
632 strerror(errno));
633 else
634 LOGP(DLINP, LOGL_NOTICE, "Keepalive is set: %i\n", ret);
635
636#if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL) && defined(TCP_KEEPCNT)
637 /* The following options are not portable! */
Jacob Erlbeck8fe15712014-01-09 14:30:58 +0100638 val = line->keepalive_idle_timeout > 0 ?
639 line->keepalive_idle_timeout :
640 DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT;
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100641 ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE,
642 &val, sizeof(val));
643 if (ret < 0)
644 LOGP(DLINP, LOGL_NOTICE,
645 "Failed to set keepalive idle time: %s\n",
646 strerror(errno));
Jacob Erlbeck8fe15712014-01-09 14:30:58 +0100647 val = line->keepalive_probe_interval > -1 ?
648 line->keepalive_probe_interval :
649 DEFAULT_TCP_KEEPALIVE_INTERVAL;
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100650 ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL,
651 &val, sizeof(val));
652 if (ret < 0)
653 LOGP(DLINP, LOGL_NOTICE,
654 "Failed to set keepalive interval: %s\n",
655 strerror(errno));
Jacob Erlbeck8fe15712014-01-09 14:30:58 +0100656 val = line->keepalive_num_probes > 0 ?
657 line->keepalive_num_probes :
658 DEFAULT_TCP_KEEPALIVE_RETRY_COUNT;
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100659 ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT,
660 &val, sizeof(val));
661 if (ret < 0)
662 LOGP(DLINP, LOGL_NOTICE,
663 "Failed to set keepalive count: %s\n",
664 strerror(errno));
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100665#endif
Holger Hans Peter Freytherf465a4c2014-02-03 09:34:02 +0100666 }
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100667}
668
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200669/* callback of the OML listening filedescriptor */
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200670static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200671{
672 int ret;
673 int idx = 0;
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100674 int i;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200675 struct e1inp_line *line;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200676 struct e1inp_ts *e1i_ts;
677 struct osmo_fd *bfd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200678
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200679 /* clone virtual E1 line for this new OML link. */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200680 line = e1inp_line_clone(tall_ipa_ctx, link->line);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200681 if (line == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200682 LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n");
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200683 return -ENOMEM;
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200684 }
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200685
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200686 /* create virrtual E1 timeslots for signalling */
Pablo Neira Ayuso59301852011-06-27 15:44:23 +0200687 e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200688
689 /* initialize the fds */
690 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
691 line->ts[i].driver.ipaccess.fd.fd = -1;
692
693 e1i_ts = &line->ts[idx];
694
Pablo Neira Ayuso93c62012011-06-26 19:12:47 +0200695 bfd = &e1i_ts->driver.ipaccess.fd;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200696 bfd->fd = fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200697 bfd->data = line;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200698 bfd->priv_nr = E1INP_SIGN_OML;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200699 bfd->cb = ipaccess_fd_cb;
700 bfd->when = BSC_FD_READ;
701 ret = osmo_fd_register(bfd);
702 if (ret < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200703 LOGP(DLINP, LOGL_ERROR, "could not register FD\n");
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200704 goto err_line;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200705 }
706
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100707 update_fd_settings(line, bfd->fd);
Daniel Willmann85980722014-01-09 14:30:55 +0100708
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200709 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
710 ret = ipaccess_send_id_req(bfd->fd);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200711 if (ret < 0) {
712 LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n",
713 strerror(errno));
714 goto err_socket;
715 }
716 return ret;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200717
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200718err_socket:
719 osmo_fd_unregister(bfd);
720err_line:
721 close(bfd->fd);
722 bfd->fd = -1;
723 e1inp_line_put(line);
724 return ret;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200725}
726
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200727static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200728{
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200729 struct e1inp_line *line;
730 struct e1inp_ts *e1i_ts;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200731 struct osmo_fd *bfd;
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200732 int i, ret;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200733
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200734 /* We don't know yet which OML link to associate it with. Thus, we
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200735 * allocate a temporary E1 line until we have received ID. */
736 line = e1inp_line_clone(tall_ipa_ctx, link->line);
737 if (line == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200738 LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n");
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200739 return -ENOMEM;
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200740 }
741 /* initialize the fds */
742 for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
743 line->ts[i].driver.ipaccess.fd.fd = -1;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200744
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200745 /* we need this to initialize this in case to avoid crashes in case
746 * that the socket is closed before we've seen an ID_RESP. */
747 e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line);
748
749 e1i_ts = &line->ts[E1INP_SIGN_RSL-1];
750
751 bfd = &e1i_ts->driver.ipaccess.fd;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +0200752 bfd->fd = fd;
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200753 bfd->data = line;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200754 bfd->priv_nr = E1INP_SIGN_RSL;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200755 bfd->cb = ipaccess_fd_cb;
756 bfd->when = BSC_FD_READ;
757 ret = osmo_fd_register(bfd);
758 if (ret < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200759 LOGP(DLINP, LOGL_ERROR, "could not register FD\n");
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200760 goto err_line;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200761 }
762 /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
763 ret = ipaccess_send_id_req(bfd->fd);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200764 if (ret < 0) {
765 LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n",
766 strerror(errno));
767 goto err_socket;
768 }
Jacob Erlbecka4ec51e2014-01-09 14:30:56 +0100769 update_fd_settings(line, bfd->fd);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200770 return ret;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200771
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200772err_socket:
773 osmo_fd_unregister(bfd);
774err_line:
775 close(bfd->fd);
776 bfd->fd = -1;
777 e1inp_line_put(line);
778 return ret;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200779}
780
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200781#define IPA_STRING_MAX 64
782
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200783static struct msgb *
784ipa_bts_id_resp(struct ipaccess_unit *dev, uint8_t *data, int len)
785{
786 struct msgb *nmsg;
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200787 char str[IPA_STRING_MAX];
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200788 uint8_t *tag;
789
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200790 nmsg = ipa_msg_alloc(0);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200791 if (!nmsg)
792 return NULL;
793
794 *msgb_put(nmsg, 1) = IPAC_MSGT_ID_RESP;
795 while (len) {
796 if (len < 2) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200797 LOGP(DLINP, LOGL_NOTICE,
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200798 "Short read of ipaccess tag\n");
799 msgb_free(nmsg);
800 return NULL;
801 }
802 switch (data[1]) {
803 case IPAC_IDTAG_UNIT:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200804 snprintf(str, sizeof(str), "%u/%u/%u",
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200805 dev->site_id, dev->bts_id, dev->trx_id);
806 break;
807 case IPAC_IDTAG_MACADDR:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200808 snprintf(str, sizeof(str),
809 "%02x:%02x:%02x:%02x:%02x:%02x",
810 dev->mac_addr[0], dev->mac_addr[1],
811 dev->mac_addr[2], dev->mac_addr[3],
812 dev->mac_addr[4], dev->mac_addr[5]);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200813 break;
814 case IPAC_IDTAG_LOCATION1:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200815 strncpy(str, dev->location1, IPA_STRING_MAX);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200816 break;
817 case IPAC_IDTAG_LOCATION2:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200818 strncpy(str, dev->location2, IPA_STRING_MAX);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200819 break;
820 case IPAC_IDTAG_EQUIPVERS:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200821 strncpy(str, dev->equipvers, IPA_STRING_MAX);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200822 break;
823 case IPAC_IDTAG_SWVERSION:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200824 strncpy(str, dev->swversion, IPA_STRING_MAX);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200825 break;
826 case IPAC_IDTAG_UNITNAME:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200827 snprintf(str, sizeof(str),
828 "%s-%02x-%02x-%02x-%02x-%02x-%02x",
829 dev->unit_name,
830 dev->mac_addr[0], dev->mac_addr[1],
831 dev->mac_addr[2], dev->mac_addr[3],
832 dev->mac_addr[4], dev->mac_addr[5]);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200833 break;
834 case IPAC_IDTAG_SERNR:
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200835 strncpy(str, dev->serno, IPA_STRING_MAX);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200836 break;
837 default:
Harald Weltecc2241b2011-07-19 16:06:06 +0200838 LOGP(DLINP, LOGL_NOTICE,
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200839 "Unknown ipaccess tag 0x%02x\n", *data);
840 msgb_free(nmsg);
841 return NULL;
842 }
Pablo Neira Ayuso4bab3bf2013-07-05 15:00:13 +0200843 str[IPA_STRING_MAX-1] = '\0';
844
Harald Weltecc2241b2011-07-19 16:06:06 +0200845 LOGP(DLINP, LOGL_INFO, " tag %d: %s\n", data[1], str);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200846 tag = msgb_put(nmsg, 3 + strlen(str) + 1);
847 tag[0] = 0x00;
848 tag[1] = 1 + strlen(str) + 1;
849 tag[2] = data[1];
850 memcpy(tag + 3, str, strlen(str) + 1);
851 data += 2;
852 len -= 2;
853 }
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200854 ipa_msg_push_header(nmsg, IPAC_PROTO_IPACCESS);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200855 return nmsg;
856}
857
858static struct msgb *ipa_bts_id_ack(void)
859{
860 struct msgb *nmsg2;
861
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200862 nmsg2 = ipa_msg_alloc(0);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200863 if (!nmsg2)
864 return NULL;
865
866 *msgb_put(nmsg2, 1) = IPAC_MSGT_ID_ACK;
Pablo Neira Ayuso88136fc2011-07-08 16:21:55 +0200867 ipa_msg_push_header(nmsg2, IPAC_PROTO_IPACCESS);
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200868
869 return nmsg2;
870}
871
Harald Welte51de9ca2013-06-30 20:13:16 +0200872static void ipaccess_bts_updown_cb(struct ipa_client_conn *link, int up)
873{
874 struct e1inp_line *line = link->line;
875
876 if (up)
877 return;
878
879 if (line->ops->sign_link_down)
880 line->ops->sign_link_down(line);
881}
882
Harald Welte783715b2014-08-17 18:24:51 +0200883/* handle incoming message to BTS, check if it is an IPA CCM, and if yes,
884 * handle it accordingly (PING/PONG/ID_REQ/ID_RESP/ID_ACK) */
885int ipaccess_bts_handle_ccm(struct ipa_client_conn *link,
886 struct ipaccess_unit *dev, struct msgb *msg)
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200887{
888 struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200889 struct msgb *rmsg;
890 int ret = 0;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200891
892 /* special handling for IPA CCM. */
893 if (hh->proto == IPAC_PROTO_IPACCESS) {
894 uint8_t msg_type = *(msg->l2h);
895
896 /* ping, pong and acknowledgment cases. */
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200897 ret = ipaccess_rcvmsg_bts_base(msg, link->ofd);
898 if (ret < 0)
899 goto err;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200900
901 /* this is a request for identification from the BSC. */
902 if (msg_type == IPAC_MSGT_ID_GET) {
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200903 uint8_t *data = msgb_l2(msg);
904 int len = msgb_l2len(msg);
905
Harald Weltecc2241b2011-07-19 16:06:06 +0200906 LOGP(DLINP, LOGL_NOTICE, "received ID get\n");
Harald Welte783715b2014-08-17 18:24:51 +0200907 rmsg = ipa_bts_id_resp(dev, data + 1, len - 1);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200908 ret = ipaccess_send(link->ofd->fd, rmsg->data,
909 rmsg->len);
910 if (ret != rmsg->len) {
911 LOGP(DLINP, LOGL_ERROR, "cannot send ID_RESP "
912 "message. Reason: %s\n", strerror(errno));
913 goto err_rmsg;
914 }
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200915 msgb_free(rmsg);
916
917 /* send ID_ACK. */
918 rmsg = ipa_bts_id_ack();
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200919 ret = ipaccess_send(link->ofd->fd, rmsg->data,
920 rmsg->len);
921 if (ret != rmsg->len) {
922 LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK "
923 "message. Reason: %s\n", strerror(errno));
924 goto err_rmsg;
925 }
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200926 msgb_free(rmsg);
Harald Welte783715b2014-08-17 18:24:51 +0200927 }
928 return 1;
929 }
Harald Welte6eddd472013-06-30 20:18:53 +0200930
Harald Welte783715b2014-08-17 18:24:51 +0200931 return 0;
932
933err_rmsg:
934 msgb_free(rmsg);
935err:
936 ipa_client_conn_close(link);
937 return -1;
938}
939
940static int ipaccess_bts_read_cb(struct ipa_client_conn *link, struct msgb *msg)
941{
942 struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
943 struct e1inp_ts *e1i_ts = NULL;
944 struct e1inp_sign_link *sign_link;
945 int ret = 0;
946
947 /* special handling for IPA CCM. */
948 if (hh->proto == IPAC_PROTO_IPACCESS) {
949 uint8_t msg_type = *(msg->l2h);
950
951 /* this is a request for identification from the BSC. */
952 if (msg_type == IPAC_MSGT_ID_GET) {
953 if (!link->line->ops->sign_link_up) {
954 LOGP(DLINP, LOGL_ERROR,
955 "Unable to set signal link, "
956 "closing socket.\n");
957 ret = -EINVAL;
958 goto err;
959 }
960 }
961 }
962
963 /* core CCM handling */
964 ret = ipaccess_bts_handle_ccm(link, link->line->ops->cfg.ipa.dev, msg);
965 if (ret < 0)
966 goto err;
967
968 if (ret == 1 && hh->proto == IPAC_PROTO_IPACCESS) {
969 uint8_t msg_type = *(msg->l2h);
970
971 if (msg_type == IPAC_MSGT_ID_GET) {
Harald Welte6eddd472013-06-30 20:18:53 +0200972 sign_link = link->line->ops->sign_link_up(msg,
973 link->line,
974 link->ofd->priv_nr);
975 if (sign_link == NULL) {
976 LOGP(DLINP, LOGL_ERROR,
977 "Unable to set signal link, "
978 "closing socket.\n");
979 ret = -EINVAL;
980 goto err;
981 }
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200982 }
Pablo Neira Ayuso84e5cb92012-08-23 23:41:54 +0200983 msgb_free(msg);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200984 return ret;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200985 } else if (link->port == IPA_TCP_PORT_OML)
986 e1i_ts = &link->line->ts[0];
987 else if (link->port == IPA_TCP_PORT_RSL)
988 e1i_ts = &link->line->ts[1];
989
Pablo Neira Ayusob9487012013-07-05 14:38:43 +0200990 OSMO_ASSERT(e1i_ts != NULL);
991
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200992 /* look up for some existing signaling link. */
993 sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0);
994 if (sign_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200995 LOGP(DLINP, LOGL_ERROR, "no matching signalling link for "
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200996 "hh->proto=0x%02x\n", hh->proto);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +0200997 ret = -EIO;
998 goto err;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +0200999 }
1000 msg->dst = sign_link;
1001
1002 /* XXX better use e1inp_ts_rx? */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +02001003 if (!link->line->ops->sign_link) {
Harald Weltecc2241b2011-07-19 16:06:06 +02001004 LOGP(DLINP, LOGL_ERROR, "Fix your application, "
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +02001005 "no action set for signalling messages.\n");
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +02001006 ret = -ENOENT;
1007 goto err;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +02001008 }
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +02001009 link->line->ops->sign_link(msg);
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +02001010 return 0;
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +02001011
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +02001012err:
Harald Welte783715b2014-08-17 18:24:51 +02001013 ipa_client_conn_close(link);
Pablo Neira Ayuso1e401942012-08-22 14:16:24 +02001014 msgb_free(msg);
1015 return ret;
Pablo Neira Ayuso591ddad2011-06-21 18:16:42 +02001016}
1017
Pablo Neira Ayusod6216402011-08-31 16:47:44 +02001018struct ipaccess_line {
1019 int line_already_initialized;
1020};
1021
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +02001022static int ipaccess_line_update(struct e1inp_line *line)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001023{
1024 int ret = -ENOENT;
Pablo Neira Ayusod6216402011-08-31 16:47:44 +02001025 struct ipaccess_line *il;
1026
1027 if (!line->driver_data)
1028 line->driver_data = talloc_zero(line, struct ipaccess_line);
1029
1030 if (!line->driver_data) {
1031 LOGP(DLINP, LOGL_ERROR, "ipaccess: OOM in line update\n");
1032 return -ENOMEM;
1033 }
1034 il = line->driver_data;
1035
1036 /* We only initialize this line once. */
1037 if (il->line_already_initialized)
1038 return 0;
1039
1040 il->line_already_initialized = 1;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001041
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +02001042 switch(line->ops->cfg.ipa.role) {
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001043 case E1INP_LINE_R_BSC: {
1044 struct ipa_server_link *oml_link, *rsl_link;
1045
Harald Weltecc2241b2011-07-19 16:06:06 +02001046 LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n");
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001047
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001048 oml_link = ipa_server_link_create(tall_ipa_ctx, line,
1049 "0.0.0.0", IPA_TCP_PORT_OML,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +02001050 ipaccess_bsc_oml_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001051 if (oml_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +02001052 LOGP(DLINP, LOGL_ERROR, "cannot create OML "
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001053 "BSC link: %s\n", strerror(errno));
1054 return -ENOMEM;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +02001055 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001056 if (ipa_server_link_open(oml_link) < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +02001057 LOGP(DLINP, LOGL_ERROR, "cannot open OML BSC link: %s\n",
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001058 strerror(errno));
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001059 ipa_server_link_destroy(oml_link);
1060 return -EIO;
Pablo Neira Ayusof67471f2011-06-07 11:25:49 +02001061 }
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001062 rsl_link = ipa_server_link_create(tall_ipa_ctx, line,
1063 "0.0.0.0", IPA_TCP_PORT_RSL,
Pablo Neira Ayusoe009f4a2011-06-23 13:36:34 +02001064 ipaccess_bsc_rsl_cb, NULL);
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001065 if (rsl_link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +02001066 LOGP(DLINP, LOGL_ERROR, "cannot create RSL "
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001067 "BSC link: %s\n", strerror(errno));
1068 return -ENOMEM;
1069 }
1070 if (ipa_server_link_open(rsl_link) < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +02001071 LOGP(DLINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n",
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001072 strerror(errno));
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001073 ipa_server_link_destroy(rsl_link);
1074 return -EIO;
1075 }
1076 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001077 break;
Pablo Neira Ayuso986191f2011-06-21 19:56:26 +02001078 }
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001079 case E1INP_LINE_R_BTS: {
Harald Welte84f67b22013-06-30 13:13:59 +02001080 struct ipa_client_conn *link;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001081
Harald Weltecc2241b2011-07-19 16:06:06 +02001082 LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n");
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001083
Pablo Neira Ayusof0995672011-09-08 12:58:38 +02001084 link = ipa_client_conn_create(tall_ipa_ctx,
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +02001085 &line->ts[E1INP_SIGN_OML-1],
Pablo Neira Ayuso00af7722011-09-08 12:47:06 +02001086 E1INP_SIGN_OML,
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +02001087 line->ops->cfg.ipa.addr,
1088 IPA_TCP_PORT_OML,
Harald Welte51de9ca2013-06-30 20:13:16 +02001089 ipaccess_bts_updown_cb,
Harald Weltea3e9dd52013-06-30 14:25:07 +02001090 ipaccess_bts_read_cb,
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +02001091 ipaccess_bts_write_cb,
Harald Welte10b41302013-06-30 14:05:49 +02001092 line);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001093 if (link == NULL) {
Harald Weltecc2241b2011-07-19 16:06:06 +02001094 LOGP(DLINP, LOGL_ERROR, "cannot create OML "
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +02001095 "BTS link: %s\n", strerror(errno));
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001096 return -ENOMEM;
1097 }
Pablo Neira Ayusof0995672011-09-08 12:58:38 +02001098 if (ipa_client_conn_open(link) < 0) {
Harald Weltecc2241b2011-07-19 16:06:06 +02001099 LOGP(DLINP, LOGL_ERROR, "cannot open OML BTS link: %s\n",
Pablo Neira Ayuso29465d32011-06-21 14:21:33 +02001100 strerror(errno));
Pablo Neira Ayusof0995672011-09-08 12:58:38 +02001101 ipa_client_conn_close(link);
1102 ipa_client_conn_destroy(link);
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001103 return -EIO;
1104 }
1105 ret = 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001106 break;
Pablo Neira Ayuso96e81282011-06-09 15:06:11 +02001107 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001108 default:
1109 break;
1110 }
1111 return ret;
1112}
1113
Harald Welte84f67b22013-06-30 13:13:59 +02001114int e1inp_ipa_bts_rsl_connect(struct e1inp_line *line,
1115 const char *rem_addr, uint16_t rem_port)
1116{
1117 struct ipa_client_conn *rsl_link;
1118
1119 rsl_link = ipa_client_conn_create(tall_ipa_ctx,
1120 &line->ts[E1INP_SIGN_RSL-1],
1121 E1INP_SIGN_RSL,
1122 rem_addr, rem_port,
Harald Welte51de9ca2013-06-30 20:13:16 +02001123 ipaccess_bts_updown_cb,
Harald Weltea3e9dd52013-06-30 14:25:07 +02001124 ipaccess_bts_read_cb,
Harald Welte84f67b22013-06-30 13:13:59 +02001125 ipaccess_bts_write_cb,
Harald Welte10b41302013-06-30 14:05:49 +02001126 line);
Harald Welte84f67b22013-06-30 13:13:59 +02001127 if (rsl_link == NULL) {
1128 LOGP(DLINP, LOGL_ERROR, "cannot create RSL "
1129 "BTS link: %s\n", strerror(errno));
1130 return -ENOMEM;
1131 }
1132 if (ipa_client_conn_open(rsl_link) < 0) {
1133 LOGP(DLINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n",
1134 strerror(errno));
1135 ipa_client_conn_close(rsl_link);
1136 ipa_client_conn_destroy(rsl_link);
1137 return -EIO;
1138 }
1139 return 0;
1140}
1141
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001142void e1inp_ipaccess_init(void)
1143{
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +02001144 tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001145 e1inp_driver_register(&ipaccess_driver);
1146}