blob: df61c7b1713a026d5e75e04f58cbc180fe0c5c83 [file] [log] [blame]
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001/* OpenBSC Abis interface to E1 */
2
3/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
Harald Welte323d39d2017-11-13 01:09:21 +09007 * SPDX-License-Identifier: AGPL-3.0+
8 *
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02009 * 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"
Harald Welte3bc78852011-08-24 08:32:38 +020025#include "../config.h"
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020026
27#include <stdio.h>
28#include <unistd.h>
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +020029#include <inttypes.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020030#include <stdlib.h>
31#include <errno.h>
32#include <string.h>
33#include <time.h>
Holger Hans Peter Freyther25474582017-01-23 19:49:07 +010034#include <fcntl.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020035#include <sys/socket.h>
36#include <sys/ioctl.h>
37#include <arpa/inet.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020038
Harald Weltefd44a5f2011-08-21 00:48:54 +020039#include <osmocom/abis/lapd.h>
40
Harald Weltef2737fc2011-08-16 14:30:10 +020041#include <osmocom/core/linuxlist.h>
42#include <osmocom/core/talloc.h>
43#include <osmocom/core/rate_ctr.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020044#include <osmocom/core/logging.h>
45#include <osmocom/core/signal.h>
Neels Hofmeyra160e4b2018-11-16 00:16:57 +010046#include <osmocom/core/endian.h>
Pablo Neira Ayuso177094b2011-06-07 12:21:51 +020047#include <osmocom/abis/e1_input.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020048
49#define NUM_E1_TS 32
50
51static void *tall_e1inp_ctx;
52
53/* list of all E1 drivers */
54LLIST_HEAD(e1inp_driver_list);
55
56/* list of all E1 lines */
57LLIST_HEAD(e1inp_line_list);
58
59static void *tall_sigl_ctx;
60
Harald Weltef2737fc2011-08-16 14:30:10 +020061static const struct rate_ctr_desc e1inp_ctr_d[] = {
62 [E1I_CTR_HDLC_ABORT] = {
Pau Espin Pedrola2106842018-07-24 15:00:11 +020063 "hdlc:abort", "HDLC abort"
Harald Weltef2737fc2011-08-16 14:30:10 +020064 },
65 [E1I_CTR_HDLC_BADFCS] = {
Pau Espin Pedrola2106842018-07-24 15:00:11 +020066 "hdlc:bad_fcs", "HLDC Bad FCS"
Harald Weltef2737fc2011-08-16 14:30:10 +020067 },
68 [E1I_CTR_HDLC_OVERR] = {
Pau Espin Pedrola2106842018-07-24 15:00:11 +020069 "hdlc:overrun", "HDLC Overrun"
Harald Weltef2737fc2011-08-16 14:30:10 +020070 },
71 [E1I_CTR_ALARM] = {
Harald Weltedd0c2ef2011-08-11 12:54:07 +020072 "alarm", "Alarm"
Harald Weltef2737fc2011-08-16 14:30:10 +020073 },
74 [E1I_CTR_REMOVED] = {
Harald Weltedd0c2ef2011-08-11 12:54:07 +020075 "removed", "Line removed"
Harald Weltef2737fc2011-08-16 14:30:10 +020076 },
77};
78
79static const struct rate_ctr_group_desc e1inp_ctr_g_d = {
80 .group_name_prefix = "e1inp",
81 .group_description = "E1 Input subsystem",
82 .num_ctr = ARRAY_SIZE(e1inp_ctr_d),
83 .ctr_desc = e1inp_ctr_d,
84};
85
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020086/*
87 * pcap writing of the misdn load
88 * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat
89 */
90#define DLT_LINUX_LAPD 177
91#define PCAP_INPUT 0
92#define PCAP_OUTPUT 1
93
94struct pcap_hdr {
95 uint32_t magic_number;
96 uint16_t version_major;
97 uint16_t version_minor;
98 int32_t thiszone;
99 uint32_t sigfigs;
100 uint32_t snaplen;
101 uint32_t network;
102} __attribute__((packed));
103
104struct pcaprec_hdr {
105 uint32_t ts_sec;
106 uint32_t ts_usec;
107 uint32_t incl_len;
108 uint32_t orig_len;
109} __attribute__((packed));
110
111struct fake_linux_lapd_header {
112 uint16_t pkttype;
113 uint16_t hatype;
114 uint16_t halen;
115 uint64_t addr;
116 int16_t protocol;
117} __attribute__((packed));
118
119struct lapd_header {
Neels Hofmeyra160e4b2018-11-16 00:16:57 +0100120#if OSMO_IS_LITTLE_ENDIAN
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200121 uint8_t ea1 : 1;
122 uint8_t cr : 1;
123 uint8_t sapi : 6;
124 uint8_t ea2 : 1;
125 uint8_t tei : 7;
126 uint8_t control_foo; /* fake UM's ... */
Neels Hofmeyra160e4b2018-11-16 00:16:57 +0100127#elif OSMO_IS_BIG_ENDIAN
128/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
129 uint8_t sapi:6, cr:1, ea1:1;
130 uint8_t tei:7, ea2:1;
131 uint8_t control_foo;
132#endif
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200133} __attribute__((packed));
134
135osmo_static_assert(offsetof(struct fake_linux_lapd_header, hatype) == 2, hatype_offset);
136osmo_static_assert(offsetof(struct fake_linux_lapd_header, halen) == 4, halen_offset);
137osmo_static_assert(offsetof(struct fake_linux_lapd_header, addr) == 6, addr_offset);
138osmo_static_assert(offsetof(struct fake_linux_lapd_header, protocol) == 14, proto_offset);
139osmo_static_assert(sizeof(struct fake_linux_lapd_header) == 16, lapd_header_size);
140
141
142static int pcap_fd = -1;
143
Pablo Neira Ayuso2e11f5c2013-07-05 15:08:18 +0200144int e1_set_pcap_fd(int fd)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200145{
Sylvain Munaut4b45e9d2020-05-08 09:40:44 +0200146 const struct pcap_hdr header = {
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200147 .magic_number = 0xa1b2c3d4,
148 .version_major = 2,
149 .version_minor = 4,
150 .thiszone = 0,
151 .sigfigs = 0,
152 .snaplen = 65535,
153 .network = DLT_LINUX_LAPD,
154 };
Sylvain Munaut4b45e9d2020-05-08 09:40:44 +0200155 struct e1inp_line *line;
156 int i;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200157
Sylvain Munaut4b45e9d2020-05-08 09:40:44 +0200158 /* write header */
159 if (fd >= 0) {
160 int rc = write(fd, &header, sizeof(header));
161 if (rc < 0)
162 return rc;
163 }
164
165 /* update fd in all lines in our global list of e1 lines */
166 llist_for_each_entry(line, &e1inp_line_list, list) {
167 /* Set the PCAP file descriptor for all timeslots that have
168 * software LAPD instances, to ensure the osmo_lapd_pcap code is
169 * used to write PCAP files (if requested) */
170 for (i = 0; i < ARRAY_SIZE(line->ts); i++) {
171 struct e1inp_ts *e1i_ts = &line->ts[i];
172 if (e1i_ts->lapd)
173 e1i_ts->lapd->pcap_fd = fd;
174 }
175 }
176
177 /* close previous and update global */
178 if (pcap_fd >= 0)
179 close(pcap_fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200180 pcap_fd = fd;
Sylvain Munaut4b45e9d2020-05-08 09:40:44 +0200181
182 return 0;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200183}
184
185/* This currently only works for the D-Channel */
186static void write_pcap_packet(int direction, int sapi, int tei,
187 struct msgb *msg) {
188 if (pcap_fd < 0)
189 return;
190
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200191 time_t cur_time;
192 struct tm *tm;
193
194 struct fake_linux_lapd_header header = {
195 .pkttype = 4,
196 .hatype = 0,
197 .halen = 0,
198 .addr = direction == PCAP_OUTPUT ? 0x0 : 0x1,
199 .protocol = ntohs(48),
200 };
201
202 struct lapd_header lapd_header = {
203 .ea1 = 0,
204 .cr = direction == PCAP_OUTPUT ? 1 : 0,
205 .sapi = sapi & 0x3F,
206 .ea2 = 1,
207 .tei = tei & 0x7F,
208 .control_foo = 0x03 /* UI */,
209 };
210
211 struct pcaprec_hdr payload_header = {
212 .ts_sec = 0,
213 .ts_usec = 0,
214 .incl_len = msgb_l2len(msg) + sizeof(struct fake_linux_lapd_header)
215 + sizeof(struct lapd_header),
216 .orig_len = msgb_l2len(msg) + sizeof(struct fake_linux_lapd_header)
217 + sizeof(struct lapd_header),
218 };
219
220
221 cur_time = time(NULL);
222 tm = localtime(&cur_time);
223 payload_header.ts_sec = mktime(tm);
224
Harald Weltec9295ea2014-08-21 02:41:41 +0200225 write(pcap_fd, &payload_header, sizeof(payload_header));
226 write(pcap_fd, &header, sizeof(header));
227 write(pcap_fd, &lapd_header, sizeof(lapd_header));
228 write(pcap_fd, msg->l2h, msgb_l2len(msg));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200229}
230
Harald Welte4ca5c532016-07-27 23:05:03 +0200231const struct value_string e1inp_sign_type_names[5] = {
232 { E1INP_SIGN_NONE, "None" },
233 { E1INP_SIGN_OML, "OML" },
234 { E1INP_SIGN_RSL, "RSL" },
235 { E1INP_SIGN_OSMO, "OSMO" },
236 { 0, NULL }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200237};
Harald Welte4ca5c532016-07-27 23:05:03 +0200238
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200239const char *e1inp_signtype_name(enum e1inp_sign_type tp)
240{
Harald Welte4ca5c532016-07-27 23:05:03 +0200241 return get_value_string(e1inp_sign_type_names, tp);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200242}
243
Harald Welte7a228eb2016-07-28 11:09:31 +0200244const struct value_string e1inp_ts_type_names[6] = {
Harald Welte4ca5c532016-07-27 23:05:03 +0200245 { E1INP_TS_TYPE_NONE, "None" },
246 { E1INP_TS_TYPE_SIGN, "Signalling" },
247 { E1INP_TS_TYPE_TRAU, "TRAU" },
Harald Weltea0108e72016-07-27 21:44:50 +0200248 { E1INP_TS_TYPE_RAW, "RAW" },
Harald Welte7a228eb2016-07-28 11:09:31 +0200249 { E1INP_TS_TYPE_HDLC, "HDLC" },
Harald Welte4ca5c532016-07-27 23:05:03 +0200250 { 0, NULL }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200251};
252
253const char *e1inp_tstype_name(enum e1inp_ts_type tp)
254{
Harald Welte4ca5c532016-07-27 23:05:03 +0200255 return get_value_string(e1inp_ts_type_names, tp);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200256}
257
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200258int abis_sendmsg(struct msgb *msg)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200259{
260 struct e1inp_sign_link *sign_link = msg->dst;
261 struct e1inp_driver *e1inp_driver;
262 struct e1inp_ts *e1i_ts;
Alexander Couzens35daa672016-11-08 16:17:20 +0100263
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200264 msg->l2h = msg->data;
265
266 /* don't know how to route this message. */
267 if (sign_link == NULL) {
Harald Welte40b0e8c2011-07-21 16:57:34 +0200268 LOGP(DLINP, LOGL_ERROR, "abis_sendmsg: msg->dst == NULL: %s\n",
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200269 osmo_hexdump(msg->data, msg->len));
270 talloc_free(msg);
271 return -EINVAL;
272 }
273 e1i_ts = sign_link->ts;
274 if (!osmo_timer_pending(&e1i_ts->sign.tx_timer)) {
275 /* notify the driver we have something to write */
276 e1inp_driver = sign_link->ts->line->driver;
277 e1inp_driver->want_write(e1i_ts);
278 }
279 msgb_enqueue(&sign_link->tx_list, msg);
280
Harald Welte7f9d8512016-07-04 09:59:46 +0200281 /* we only need to write a 'Fake LAPD' packet here, if the
282 * underlying driver hides LAPD from us. If we use the
283 * libosmocore LAPD implementation, it will take care of writing
284 * the _actual_ LAPD packet */
285 if (!e1i_ts->lapd) {
286 write_pcap_packet(PCAP_OUTPUT, sign_link->sapi,
287 sign_link->tei, msg);
288 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200289
290 return 0;
291}
292
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200293int abis_rsl_sendmsg(struct msgb *msg)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200294{
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200295 return abis_sendmsg(msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200296}
297
298/* Timeslot */
299int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200300 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
Harald Welte5226e5b2020-05-07 23:09:16 +0200301 const ubit_t *data, int len, void *_priv))
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200302{
303 if (ts->type == E1INP_TS_TYPE_TRAU && ts->line && line)
304 return 0;
305
306 ts->type = E1INP_TS_TYPE_TRAU;
307 ts->line = line;
308
309 subchan_mux_init(&ts->trau.mux);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200310 ts->trau.demux.out_cb = trau_rcv_cb;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200311 ts->trau.demux.data = ts;
312 subch_demux_init(&ts->trau.demux);
313 return 0;
314}
315
Harald Welteb9031882020-05-02 21:09:15 +0200316void e1inp_ts_name(char *out, size_t out_len, const struct e1inp_ts *ts)
317{
318 if (ts->line->name)
319 snprintf(out, out_len, "%s:%u", ts->line->name, ts->num);
320 else
321 snprintf(out, out_len, "%u:%u", ts->line->num, ts->num);
322}
323
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200324int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line)
325{
326 if (ts->type == E1INP_TS_TYPE_SIGN && ts->line && line)
327 return 0;
328
329 ts->type = E1INP_TS_TYPE_SIGN;
330 ts->line = line;
331
332 if (line && line->driver)
333 ts->sign.delay = line->driver->default_delay;
334 else
335 ts->sign.delay = 100000;
336 INIT_LLIST_HEAD(&ts->sign.sign_links);
337 return 0;
338}
339
Harald Weltea0108e72016-07-27 21:44:50 +0200340int e1inp_ts_config_raw(struct e1inp_ts *ts, struct e1inp_line *line,
341 void (*raw_recv_cb)(struct e1inp_ts *ts,
342 struct msgb *msg))
343{
344 if (ts->type == E1INP_TS_TYPE_RAW && ts->line && line)
345 return 0;
346
347 ts->type = E1INP_TS_TYPE_RAW;
348 ts->line = line;
349 ts->raw.recv_cb = raw_recv_cb;
350 INIT_LLIST_HEAD(&ts->raw.tx_queue);
351
352 return 0;
353}
354
Harald Welte7a228eb2016-07-28 11:09:31 +0200355int e1inp_ts_config_hdlc(struct e1inp_ts *ts, struct e1inp_line *line,
356 void (*hdlc_recv_cb)(struct e1inp_ts *ts,
357 struct msgb *msg))
358{
359 if (ts->type == E1INP_TS_TYPE_HDLC && ts->line && line)
360 return 0;
361
362 ts->type = E1INP_TS_TYPE_HDLC;
363 ts->line = line;
364 ts->hdlc.recv_cb = hdlc_recv_cb;
365 INIT_LLIST_HEAD(&ts->hdlc.tx_queue);
366
367 return 0;
368}
369
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200370static int e1inp_line_use_cb(struct osmo_use_count_entry *use_count_entry, int32_t old_use_count,
371 const char *file, int file_line)
372{
373 char buf[512];
374 struct osmo_use_count *uc = use_count_entry->use_count;
375 struct e1inp_line *line = uc->talloc_object;
376
377 LOGPSRC(DLINP, LOGL_INFO, file, file_line,
378 "E1L(%u) Line (%p) reference count %s changed %" PRId32 " -> %" PRId32 " [%s]\n",
379 (line)->num, line, use_count_entry->use,
380 old_use_count, use_count_entry->count,
381 osmo_use_count_name_buf(buf, sizeof(buf), uc));
382
383 if (!use_count_entry->count)
384 osmo_use_count_free(use_count_entry);
385
386 if (osmo_use_count_total(uc) > 0)
387 return 0;
388
389 /* Remove our counter group from libosmocore's global counter
390 * list if we are freeing the last remaining talloc context.
391 * Otherwise we get a use-after-free when libosmocore's timer
392 * ticks again and attempts to update these counters (OS#3011).
393 *
394 * Note that talloc internally counts "secondary" references
395 * _in addition to_ the initial allocation context, so yes,
396 * we must check for *zero* remaining secondary contexts here. */
397 if (talloc_reference_count(line->rate_ctr) == 0) {
398 rate_ctr_group_free(line->rate_ctr);
399 } else {
400 /* We are not freeing the last talloc context.
401 * Instead of calling talloc_free(), unlink this 'line' pointer
402 * which serves as one of several talloc contexts for the rate
403 * counters and driver private state. */
404 talloc_unlink(line, line->rate_ctr);
405 if (line->driver_data)
406 talloc_unlink(line, line->driver_data);
407 }
408 talloc_free(line);
409 return 0;
410}
411
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200412struct e1inp_line *e1inp_line_find(uint8_t e1_nr)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200413{
414 struct e1inp_line *e1i_line;
415
416 /* iterate over global list of e1 lines */
417 llist_for_each_entry(e1i_line, &e1inp_line_list, list) {
418 if (e1i_line->num == e1_nr)
419 return e1i_line;
420 }
421 return NULL;
422}
423
424struct e1inp_line *
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200425e1inp_line_create(uint8_t e1_nr, const char *driver_name)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200426{
427 struct e1inp_driver *driver;
428 struct e1inp_line *line;
429 int i;
430
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200431 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200432 if (line) {
Harald Welteb5af0992020-01-12 12:59:52 +0100433 LOGPIL(line, DLINP, LOGL_ERROR, "E1 Line %u already exists\n", e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200434 return NULL;
435 }
436
437 driver = e1inp_driver_find(driver_name);
438 if (!driver) {
Harald Weltecc2241b2011-07-19 16:06:06 +0200439 LOGP(DLINP, LOGL_ERROR, "No such E1 driver '%s'\n",
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200440 driver_name);
441 return NULL;
442 }
443
444 line = talloc_zero(tall_e1inp_ctx, struct e1inp_line);
445 if (!line)
446 return NULL;
447
448 line->driver = driver;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200449 line->num = e1_nr;
Harald Weltef2737fc2011-08-16 14:30:10 +0200450
451 line->rate_ctr = rate_ctr_group_alloc(line, &e1inp_ctr_g_d, line->num);
Harald Welteff8eed22017-07-12 00:38:25 +0200452 if (!line->rate_ctr) {
Harald Welteb5af0992020-01-12 12:59:52 +0100453 LOGPIL(line, DLINP, LOGL_ERROR, "Cannot allocate counter group\n");
Harald Welteff8eed22017-07-12 00:38:25 +0200454 talloc_free(line);
455 return NULL;
456 }
Harald Weltef2737fc2011-08-16 14:30:10 +0200457
Harald Weltec2889512011-09-13 23:49:04 +0100458 line->num_ts = NUM_E1_TS;
459 for (i = 0; i < line->num_ts; i++) {
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200460 line->ts[i].num = i+1;
461 line->ts[i].line = line;
462 }
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200463
464 line->use_count.talloc_object = line;
465 line->use_count.use_cb = e1inp_line_use_cb;
466 e1inp_line_get2(line, "ctor");
467
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200468 llist_add_tail(&line->list, &e1inp_line_list);
469
470 return line;
471}
472
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200473struct e1inp_line *
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200474e1inp_line_clone(void *ctx, struct e1inp_line *line, const char *use)
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200475{
476 struct e1inp_line *clone;
477
478 /* clone virtual E1 line for this new OML link. */
479 clone = talloc_zero(ctx, struct e1inp_line);
480 if (clone == NULL)
481 return NULL;
482
483 memcpy(clone, line, sizeof(struct e1inp_line));
Stefan Sperlingb0162072018-05-22 18:19:00 +0200484
485 if (line->name) {
486 clone->name = talloc_strdup(clone, line->name);
487 OSMO_ASSERT(clone->name);
488 }
489 if (line->sock_path) {
490 clone->sock_path = talloc_strdup(clone, line->sock_path);
491 OSMO_ASSERT(clone->sock_path);
492 }
493
494 /*
495 * Rate counters and driver data are shared between clones. These are pointers
496 * to dynamic memory so we use reference counting to avoid a double-free (see OS#3137).
497 */
498 OSMO_ASSERT(line->rate_ctr);
499 clone->rate_ctr = talloc_reference(clone, line->rate_ctr);
500 if (line->driver_data)
501 clone->driver_data = talloc_reference(clone, line->driver_data);
502
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200503 clone->use_count = (struct osmo_use_count) {
504 .talloc_object = clone,
505 .use_cb = e1inp_line_use_cb,
506 .use_counts = {0},
507 };
508 e1inp_line_get2(clone, use); /* Clone is used internally for bfd */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200509 return clone;
510}
511
512void e1inp_line_get(struct e1inp_line *line)
513{
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200514 e1inp_line_get2(line, "unknown");
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200515}
516
517void e1inp_line_put(struct e1inp_line *line)
518{
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200519 e1inp_line_put2(line, "unknown");
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200520}
521
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200522void
523e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops)
524{
525 line->ops = ops;
526}
527
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200528#if 0
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200529struct e1inp_line *e1inp_line_find_create(uint8_t e1_nr)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200530{
531 struct e1inp_line *line;
532 int i;
533
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200534 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200535 if (line)
536 return line;
537
538 line = talloc_zero(tall_e1inp_ctx, struct e1inp_line);
539 if (!line)
540 return NULL;
541
542 line->num = e1_nr;
543 for (i = 0; i < NUM_E1_TS; i++) {
544 line->ts[i].num = i+1;
545 line->ts[i].line = line;
546 }
547 llist_add_tail(&line->list, &e1inp_line_list);
548
549 return line;
550}
551#endif
552
553static struct e1inp_ts *e1inp_ts_get(uint8_t e1_nr, uint8_t ts_nr)
554{
555 struct e1inp_line *e1i_line;
556
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200557 e1i_line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200558 if (!e1i_line)
559 return NULL;
560
561 return &e1i_line->ts[ts_nr-1];
562}
563
564struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr)
565{
566 struct e1inp_ts *e1i_ts = e1inp_ts_get(e1_nr, ts_nr);
567
568 if (!e1i_ts)
569 return NULL;
570
571 return &e1i_ts->trau.mux;
572}
573
574/* Signalling Link */
575
576struct e1inp_sign_link *e1inp_lookup_sign_link(struct e1inp_ts *e1i,
577 uint8_t tei, uint8_t sapi)
578{
579 struct e1inp_sign_link *link;
580
581 llist_for_each_entry(link, &e1i->sign.sign_links, list) {
582 if (link->sapi == sapi && link->tei == tei)
583 return link;
584 }
585
586 return NULL;
587}
588
589/* create a new signalling link in a E1 timeslot */
590
591struct e1inp_sign_link *
592e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
593 struct gsm_bts_trx *trx, uint8_t tei,
594 uint8_t sapi)
595{
596 struct e1inp_sign_link *link;
597
598 if (ts->type != E1INP_TS_TYPE_SIGN)
599 return NULL;
600
601 link = talloc_zero(tall_sigl_ctx, struct e1inp_sign_link);
602 if (!link)
603 return NULL;
604
605 link->ts = ts;
606 link->type = type;
607 INIT_LLIST_HEAD(&link->tx_list);
608 link->trx = trx;
609 link->tei = tei;
610 link->sapi = sapi;
611
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200612 e1inp_line_get2(link->ts->line, "e1inp_sign_link");
Pau Espin Pedrol89c6b8a2020-06-08 20:26:44 +0200613
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200614 llist_add_tail(&link->list, &ts->sign.sign_links);
615
616 return link;
617}
618
619void e1inp_sign_link_destroy(struct e1inp_sign_link *link)
620{
621 struct msgb *msg;
622
623 llist_del(&link->list);
624 while (!llist_empty(&link->tx_list)) {
625 msg = msgb_dequeue(&link->tx_list);
626 msgb_free(msg);
627 }
628
629 if (link->ts->type == E1INP_TS_TYPE_SIGN)
630 osmo_timer_del(&link->ts->sign.tx_timer);
631
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200632 if (link->ts->line->driver->close)
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200633 link->ts->line->driver->close(link);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200634
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200635 e1inp_line_put2(link->ts->line, "e1inp_sign_link");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200636 talloc_free(link);
637}
638
639/* XXX */
640/* the E1 driver tells us he has received something on a TS */
641int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
642 uint8_t tei, uint8_t sapi)
643{
644 struct e1inp_sign_link *link;
645 int ret = 0;
646
647 switch (ts->type) {
648 case E1INP_TS_TYPE_SIGN:
Harald Welte7f9d8512016-07-04 09:59:46 +0200649 /* we only need to write a 'Fake LAPD' packet here, if
650 * the underlying driver hides LAPD from us. If we use
651 * the libosmocore LAPD implementation, it will take
652 * care of writing the _actual_ LAPD packet */
653 if (!ts->lapd)
654 write_pcap_packet(PCAP_INPUT, sapi, tei, msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200655 /* consult the list of signalling links */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200656 link = e1inp_lookup_sign_link(ts, tei, sapi);
657 if (!link) {
Harald Welteb5af0992020-01-12 12:59:52 +0100658 LOGPITS(ts, DLMI, LOGL_ERROR, "didn't find signalling link for "
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200659 "tei %d, sapi %d\n", tei, sapi);
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200660 msgb_free(msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200661 return -EINVAL;
662 }
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200663 if (!ts->line->ops->sign_link) {
Harald Welteb5af0992020-01-12 12:59:52 +0100664 LOGPITS(ts, DLINP, LOGL_ERROR, "Fix your application, "
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200665 "no action set for signalling messages.\n");
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200666 msgb_free(msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200667 return -ENOENT;
668 }
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200669 msg->dst = link;
670 ts->line->ops->sign_link(msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200671 break;
672 case E1INP_TS_TYPE_TRAU:
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200673 ret = subch_demux_in(&ts->trau.demux, msg->l2h, msgb_l2len(msg));
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200674 msgb_free(msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200675 break;
Harald Weltea0108e72016-07-27 21:44:50 +0200676 case E1INP_TS_TYPE_RAW:
677 ts->raw.recv_cb(ts, msg);
678 break;
Harald Welte7a228eb2016-07-28 11:09:31 +0200679 case E1INP_TS_TYPE_HDLC:
680 ts->hdlc.recv_cb(ts, msg);
681 break;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200682 default:
683 ret = -EINVAL;
Harald Welteb5af0992020-01-12 12:59:52 +0100684 LOGPITS(ts, DLMI, LOGL_ERROR, "unknown TS type %u\n", ts->type);
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200685 msgb_free(msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200686 break;
687 }
688
689 return ret;
690}
691
Harald Weltefd44a5f2011-08-21 00:48:54 +0200692/*! \brief Receive some data from the L1/HDLC into LAPD of a timeslot
693 * \param[in] e1i_ts E1 Timeslot data structure
694 * \param[in] msg Message buffer containing full LAPD message
695 *
696 * This is a wrapper around e1inp_rx_ts(), but feeding the incoming
697 * message first into our LAPD code. This allows a driver to read raw
698 * (HDLC decoded) data from the timeslot, instead of a LAPD stack
699 * present in any underlying driver.
700 */
701int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg)
702{
Harald Weltefd44a5f2011-08-21 00:48:54 +0200703 unsigned int sapi, tei;
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200704 int ret = 0, error = 0;
Harald Weltefd44a5f2011-08-21 00:48:54 +0200705
706 sapi = msg->data[0] >> 2;
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200707 if ((msg->data[0] & 0x1))
708 tei = 0;
709 else
710 tei = msg->data[1] >> 1;
Harald Weltefd44a5f2011-08-21 00:48:54 +0200711
Harald Welteb5af0992020-01-12 12:59:52 +0100712 LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "<= len = %d, sapi(%d) tei(%d)\n", msg->len, sapi, tei);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200713
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200714 ret = lapd_receive(e1i_ts->lapd, msg, &error);
715 if (ret < 0) {
Harald Weltefd44a5f2011-08-21 00:48:54 +0200716 switch(error) {
717 case LAPD_ERR_UNKNOWN_TEI:
718 /* We don't know about this TEI, probably the BSC
719 * lost local states (it crashed or it was stopped),
720 * notify the driver to see if it can do anything to
721 * recover the existing signalling links with the BTS.
722 */
723 e1inp_event(e1i_ts, S_L_INP_TEI_UNKNOWN, tei, sapi);
724 return -EIO;
725 }
Harald Weltefd44a5f2011-08-21 00:48:54 +0200726 }
727
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200728 return 0;
729}
Harald Weltefd44a5f2011-08-21 00:48:54 +0200730
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200731void e1inp_dlsap_up(struct osmo_dlsap_prim *dp, uint8_t tei, uint8_t sapi,
732 void *rx_cbdata)
733{
734 struct e1inp_ts *e1i_ts = rx_cbdata;
735 struct msgb *msg = dp->oph.msg;
Harald Weltefd44a5f2011-08-21 00:48:54 +0200736
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200737 switch (dp->oph.primitive) {
738 case PRIM_DL_EST:
Harald Welteb5af0992020-01-12 12:59:52 +0100739 LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "DL_EST: sapi(%d) tei(%d)\n", sapi, tei);
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200740 e1inp_event(e1i_ts, S_L_INP_TEI_UP, tei, sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200741 break;
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200742 case PRIM_DL_REL:
Harald Welteb5af0992020-01-12 12:59:52 +0100743 LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "DL_REL: sapi(%d) tei(%d)\n", sapi, tei);
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200744 e1inp_event(e1i_ts, S_L_INP_TEI_DN, tei, sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200745 break;
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200746 case PRIM_DL_DATA:
747 case PRIM_DL_UNIT_DATA:
748 if (dp->oph.operation == PRIM_OP_INDICATION) {
749 msg->l2h = msg->l3h;
Harald Welteb5af0992020-01-12 12:59:52 +0100750 LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "RX: %s sapi=%d tei=%d\n",
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200751 osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)),
752 sapi, tei);
753 e1inp_rx_ts(e1i_ts, msg, tei, sapi);
754 return;
755 }
Harald Weltefd44a5f2011-08-21 00:48:54 +0200756 break;
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200757 case PRIM_MDL_ERROR:
Harald Welteb5af0992020-01-12 12:59:52 +0100758 LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "MDL_EERROR: cause(%d)\n", dp->u.error_ind.cause);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200759 break;
760 default:
761 printf("ERROR: unknown prim\n");
762 break;
763 }
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200764
765 msgb_free(msg);
766
767 return;
Harald Weltefd44a5f2011-08-21 00:48:54 +0200768}
769
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200770#define TSX_ALLOC_SIZE 4096
771
772/* called by driver if it wants to transmit on a given TS */
773struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
774 struct e1inp_sign_link **sign_link)
775{
776 struct e1inp_sign_link *link;
777 struct msgb *msg = NULL;
778 int len;
779
780 switch (e1i_ts->type) {
781 case E1INP_TS_TYPE_SIGN:
782 /* FIXME: implement this round robin */
783 llist_for_each_entry(link, &e1i_ts->sign.sign_links, list) {
784 msg = msgb_dequeue(&link->tx_list);
785 if (msg) {
786 if (sign_link)
787 *sign_link = link;
788 break;
789 }
790 }
791 break;
792 case E1INP_TS_TYPE_TRAU:
793 msg = msgb_alloc(TSX_ALLOC_SIZE, "TRAU_TX");
794 if (!msg)
795 return NULL;
796 len = subchan_mux_out(&e1i_ts->trau.mux, msg->data, 40);
Pablo Neira Ayuso33f71752013-07-05 15:44:12 +0200797 if (len != 40) {
Harald Welteb5af0992020-01-12 12:59:52 +0100798 LOGPITS(e1i_ts, DLMI, LOGL_ERROR, "cannot transmit, failed to mux\n");
Pablo Neira Ayuso33f71752013-07-05 15:44:12 +0200799 msgb_free(msg);
800 return NULL;
801 }
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200802 msgb_put(msg, 40);
803 break;
Harald Weltea0108e72016-07-27 21:44:50 +0200804 case E1INP_TS_TYPE_RAW:
805 /* Get msgb from tx_queue */
806 msg = msgb_dequeue(&e1i_ts->raw.tx_queue);
807 break;
Harald Welte7a228eb2016-07-28 11:09:31 +0200808 case E1INP_TS_TYPE_HDLC:
809 /* Get msgb from tx_queue */
810 msg = msgb_dequeue(&e1i_ts->hdlc.tx_queue);
811 break;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200812 default:
Harald Welteb5af0992020-01-12 12:59:52 +0100813 LOGPITS(e1i_ts, DLMI, LOGL_ERROR, "unsupported E1 TS type %u\n", e1i_ts->type);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200814 return NULL;
815 }
816 return msg;
817}
818
Pau Espin Pedrol8737ad42020-07-14 21:11:56 +0200819int e1inp_int_snd_event(struct e1inp_ts *ts, struct e1inp_sign_link *link, int evt)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200820{
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200821 struct input_signal_data isd;
Pablo Neira Ayuso31fe5f22011-08-09 23:15:38 +0200822 isd.line = ts->line;
Harald Weltef35d8892016-10-16 15:33:52 +0200823 isd.ts_nr = ts->num;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200824 isd.link_type = link->type;
825 isd.trx = link->trx;
Holger Hans Peter Freyther55467f02011-12-28 19:47:07 +0100826 isd.tei = link->tei;
827 isd.sapi = link->sapi;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200828
829 /* report further upwards */
Harald Weltecc2241b2011-07-19 16:06:06 +0200830 osmo_signal_dispatch(SS_L_INPUT, evt, &isd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200831 return 0;
832}
833
Holger Hans Peter Freyther55467f02011-12-28 19:47:07 +0100834
835/* called by driver in case some kind of link state event */
836int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi)
837{
838 struct e1inp_sign_link *link;
839
840 link = e1inp_lookup_sign_link(ts, tei, sapi);
841 if (!link)
842 return -EINVAL;
843 return e1inp_int_snd_event(ts, link, evt);
844}
845
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200846/* register a driver with the E1 core */
847int e1inp_driver_register(struct e1inp_driver *drv)
848{
849 llist_add_tail(&drv->list, &e1inp_driver_list);
850 return 0;
851}
852
853struct e1inp_driver *e1inp_driver_find(const char *name)
854{
855 struct e1inp_driver *drv;
856
857 llist_for_each_entry(drv, &e1inp_driver_list, list) {
858 if (!strcasecmp(name, drv->name))
859 return drv;
860 }
861 return NULL;
862}
863
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200864int e1inp_line_update(struct e1inp_line *line)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200865{
866 struct input_signal_data isd;
Harald Welte7f9d8512016-07-04 09:59:46 +0200867 int i, rc;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200868
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200869 if (line->driver && line->ops && line->driver->line_update) {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200870 rc = line->driver->line_update(line);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200871 } else
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200872 rc = 0;
873
Harald Welte7f9d8512016-07-04 09:59:46 +0200874 /* Set the PCAP file descriptor for all timeslots that have
875 * software LAPD instances, to ensure the osmo_lapd_pcap code is
876 * used to write PCAP files (if requested) */
877 for (i = 0; i < ARRAY_SIZE(line->ts); i++) {
878 struct e1inp_ts *e1i_ts = &line->ts[i];
879 if (e1i_ts->lapd)
880 e1i_ts->lapd->pcap_fd = pcap_fd;
881 }
882
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200883 /* Send a signal to anyone who is interested in new lines being
884 * configured */
885 memset(&isd, 0, sizeof(isd));
886 isd.line = line;
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200887 osmo_signal_dispatch(SS_L_INPUT, S_L_INP_LINE_INIT, &isd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200888
889 return rc;
890}
891
Pablo Neira Ayusoa20762a2011-07-02 19:01:58 +0200892static int e1i_sig_cb(unsigned int subsys, unsigned int signal,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200893 void *handler_data, void *signal_data)
894{
Harald Weltecc2241b2011-07-19 16:06:06 +0200895 if (subsys != SS_L_GLOBAL ||
896 signal != S_L_GLOBAL_SHUTDOWN)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200897 return 0;
898
899 if (pcap_fd) {
900 close(pcap_fd);
901 pcap_fd = -1;
902 }
903
904 return 0;
905}
906
Harald Weltecac78fe2017-05-25 19:13:13 +0200907const struct value_string e1inp_signal_names[] = {
908 { S_L_INP_NONE, "NONE" },
909 { S_L_INP_TEI_UP, "TEI-UP" },
910 { S_L_INP_TEI_DN, "TEI-DOWN" },
911 { S_L_INP_TEI_UNKNOWN, "TEI-UNKNOWN" },
912 { S_L_INP_LINE_INIT, "LINE-INIT" },
913 { S_L_INP_LINE_ALARM, "LINE-ALARM" },
914 { S_L_INP_LINE_NOALARM, "LINE-NOALARM" },
915 { 0, NULL }
916};
917
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200918void e1inp_misdn_init(void);
919void e1inp_dahdi_init(void);
Harald Weltec6c70762019-05-12 21:54:59 +0200920void e1inp_e1d_init(void);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200921void e1inp_ipaccess_init(void);
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200922void e1inp_rs232_init(void);
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100923void e1inp_unixsocket_init(void);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200924
925void e1inp_init(void)
926{
Pablo Neira Ayuso54b49792011-06-07 12:15:26 +0200927 tall_e1inp_ctx = talloc_named_const(libosmo_abis_ctx, 1, "e1inp");
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200928 tall_sigl_ctx = talloc_named_const(tall_e1inp_ctx, 1,
929 "e1inp_sign_link");
Harald Weltecc2241b2011-07-19 16:06:06 +0200930 osmo_signal_register_handler(SS_L_GLOBAL, e1i_sig_cb, NULL);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200931
932 e1inp_misdn_init();
Harald Welte3bc78852011-08-24 08:32:38 +0200933#ifdef HAVE_DAHDI_USER_H
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200934 e1inp_dahdi_init();
Harald Welte3bc78852011-08-24 08:32:38 +0200935#endif
Harald Welte52b0d452019-05-12 21:54:26 +0200936#ifdef HAVE_E1D
Sylvain Munautb559a532019-05-09 11:14:26 +0200937 e1inp_e1d_init();
938#endif
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200939 e1inp_ipaccess_init();
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200940 e1inp_rs232_init();
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100941 e1inp_unixsocket_init();
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200942}