Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1 | /* OpenBSC Abis interface to E1 */ |
| 2 | |
| 3 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
Harald Welte | 323d39d | 2017-11-13 01:09:21 +0900 | [diff] [blame] | 7 | * SPDX-License-Identifier: AGPL-3.0+ |
| 8 | * |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 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" |
Harald Welte | 3bc7885 | 2011-08-24 08:32:38 +0200 | [diff] [blame] | 25 | #include "../config.h" |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <unistd.h> |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 29 | #include <inttypes.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 30 | #include <stdlib.h> |
| 31 | #include <errno.h> |
| 32 | #include <string.h> |
| 33 | #include <time.h> |
Holger Hans Peter Freyther | 2547458 | 2017-01-23 19:49:07 +0100 | [diff] [blame] | 34 | #include <fcntl.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 35 | #include <sys/socket.h> |
| 36 | #include <sys/ioctl.h> |
| 37 | #include <arpa/inet.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 38 | |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 39 | #include <osmocom/abis/lapd.h> |
| 40 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 41 | #include <osmocom/core/linuxlist.h> |
| 42 | #include <osmocom/core/talloc.h> |
| 43 | #include <osmocom/core/rate_ctr.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 44 | #include <osmocom/core/logging.h> |
| 45 | #include <osmocom/core/signal.h> |
Neels Hofmeyr | a160e4b | 2018-11-16 00:16:57 +0100 | [diff] [blame] | 46 | #include <osmocom/core/endian.h> |
Harald Welte | b3952c6 | 2020-06-20 22:07:36 +0200 | [diff] [blame] | 47 | #include <osmocom/gsm/i460_mux.h> |
Pablo Neira Ayuso | 177094b | 2011-06-07 12:21:51 +0200 | [diff] [blame] | 48 | #include <osmocom/abis/e1_input.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 49 | |
| 50 | #define NUM_E1_TS 32 |
| 51 | |
| 52 | static void *tall_e1inp_ctx; |
| 53 | |
| 54 | /* list of all E1 drivers */ |
| 55 | LLIST_HEAD(e1inp_driver_list); |
| 56 | |
| 57 | /* list of all E1 lines */ |
| 58 | LLIST_HEAD(e1inp_line_list); |
| 59 | |
| 60 | static void *tall_sigl_ctx; |
| 61 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 62 | static const struct rate_ctr_desc e1inp_ctr_d[] = { |
| 63 | [E1I_CTR_HDLC_ABORT] = { |
Pau Espin Pedrol | a210684 | 2018-07-24 15:00:11 +0200 | [diff] [blame] | 64 | "hdlc:abort", "HDLC abort" |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 65 | }, |
| 66 | [E1I_CTR_HDLC_BADFCS] = { |
Pau Espin Pedrol | a210684 | 2018-07-24 15:00:11 +0200 | [diff] [blame] | 67 | "hdlc:bad_fcs", "HLDC Bad FCS" |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 68 | }, |
| 69 | [E1I_CTR_HDLC_OVERR] = { |
Pau Espin Pedrol | a210684 | 2018-07-24 15:00:11 +0200 | [diff] [blame] | 70 | "hdlc:overrun", "HDLC Overrun" |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 71 | }, |
| 72 | [E1I_CTR_ALARM] = { |
Harald Welte | dd0c2ef | 2011-08-11 12:54:07 +0200 | [diff] [blame] | 73 | "alarm", "Alarm" |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 74 | }, |
| 75 | [E1I_CTR_REMOVED] = { |
Harald Welte | dd0c2ef | 2011-08-11 12:54:07 +0200 | [diff] [blame] | 76 | "removed", "Line removed" |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 77 | }, |
| 78 | }; |
| 79 | |
| 80 | static const struct rate_ctr_group_desc e1inp_ctr_g_d = { |
| 81 | .group_name_prefix = "e1inp", |
| 82 | .group_description = "E1 Input subsystem", |
| 83 | .num_ctr = ARRAY_SIZE(e1inp_ctr_d), |
| 84 | .ctr_desc = e1inp_ctr_d, |
| 85 | }; |
| 86 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 87 | /* |
| 88 | * pcap writing of the misdn load |
| 89 | * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat |
| 90 | */ |
| 91 | #define DLT_LINUX_LAPD 177 |
| 92 | #define PCAP_INPUT 0 |
| 93 | #define PCAP_OUTPUT 1 |
| 94 | |
| 95 | struct pcap_hdr { |
| 96 | uint32_t magic_number; |
| 97 | uint16_t version_major; |
| 98 | uint16_t version_minor; |
| 99 | int32_t thiszone; |
| 100 | uint32_t sigfigs; |
| 101 | uint32_t snaplen; |
| 102 | uint32_t network; |
| 103 | } __attribute__((packed)); |
| 104 | |
| 105 | struct pcaprec_hdr { |
| 106 | uint32_t ts_sec; |
| 107 | uint32_t ts_usec; |
| 108 | uint32_t incl_len; |
| 109 | uint32_t orig_len; |
| 110 | } __attribute__((packed)); |
| 111 | |
| 112 | struct fake_linux_lapd_header { |
| 113 | uint16_t pkttype; |
| 114 | uint16_t hatype; |
| 115 | uint16_t halen; |
| 116 | uint64_t addr; |
| 117 | int16_t protocol; |
| 118 | } __attribute__((packed)); |
| 119 | |
| 120 | struct lapd_header { |
Neels Hofmeyr | a160e4b | 2018-11-16 00:16:57 +0100 | [diff] [blame] | 121 | #if OSMO_IS_LITTLE_ENDIAN |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 122 | uint8_t ea1 : 1; |
| 123 | uint8_t cr : 1; |
| 124 | uint8_t sapi : 6; |
| 125 | uint8_t ea2 : 1; |
| 126 | uint8_t tei : 7; |
| 127 | uint8_t control_foo; /* fake UM's ... */ |
Neels Hofmeyr | a160e4b | 2018-11-16 00:16:57 +0100 | [diff] [blame] | 128 | #elif OSMO_IS_BIG_ENDIAN |
| 129 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ |
| 130 | uint8_t sapi:6, cr:1, ea1:1; |
| 131 | uint8_t tei:7, ea2:1; |
| 132 | uint8_t control_foo; |
| 133 | #endif |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 134 | } __attribute__((packed)); |
| 135 | |
| 136 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, hatype) == 2, hatype_offset); |
| 137 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, halen) == 4, halen_offset); |
| 138 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, addr) == 6, addr_offset); |
| 139 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, protocol) == 14, proto_offset); |
| 140 | osmo_static_assert(sizeof(struct fake_linux_lapd_header) == 16, lapd_header_size); |
| 141 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 142 | int e1_set_pcap_fd2(struct e1inp_line *line, int fd) |
| 143 | { |
| 144 | static const struct pcap_hdr header = { |
| 145 | .magic_number = 0xa1b2c3d4, |
| 146 | .version_major = 2, |
| 147 | .version_minor = 4, |
| 148 | .thiszone = 0, |
| 149 | .sigfigs = 0, |
| 150 | .snaplen = 65535, |
| 151 | .network = DLT_LINUX_LAPD, |
| 152 | }; |
| 153 | int i; |
| 154 | |
| 155 | /* write header */ |
| 156 | if (fd >= 0) { |
| 157 | int rc = write(fd, &header, sizeof(header)); |
| 158 | if (rc < 0) |
| 159 | return rc; |
| 160 | } |
| 161 | |
| 162 | /* Set the PCAP file descriptor for all timeslots that have |
| 163 | * software LAPD instances, to ensure the osmo_lapd_pcap code is |
| 164 | * used to write PCAP files (if requested) */ |
| 165 | for (i = 0; i < ARRAY_SIZE(line->ts); i++) { |
| 166 | struct e1inp_ts *e1i_ts = &line->ts[i]; |
| 167 | if (e1i_ts->lapd) |
| 168 | e1i_ts->lapd->pcap_fd = fd; |
| 169 | } |
| 170 | /* close previous and update */ |
| 171 | if (line->pcap_fd >= 0) |
| 172 | close(line->pcap_fd); |
| 173 | line->pcap_fd = fd; |
| 174 | return 0; |
| 175 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 176 | |
| 177 | static int pcap_fd = -1; |
| 178 | |
Pablo Neira Ayuso | 2e11f5c | 2013-07-05 15:08:18 +0200 | [diff] [blame] | 179 | int e1_set_pcap_fd(int fd) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 180 | { |
Sylvain Munaut | 4b45e9d | 2020-05-08 09:40:44 +0200 | [diff] [blame] | 181 | const struct pcap_hdr header = { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 182 | .magic_number = 0xa1b2c3d4, |
| 183 | .version_major = 2, |
| 184 | .version_minor = 4, |
| 185 | .thiszone = 0, |
| 186 | .sigfigs = 0, |
| 187 | .snaplen = 65535, |
| 188 | .network = DLT_LINUX_LAPD, |
| 189 | }; |
Sylvain Munaut | 4b45e9d | 2020-05-08 09:40:44 +0200 | [diff] [blame] | 190 | struct e1inp_line *line; |
| 191 | int i; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 192 | |
Sylvain Munaut | 4b45e9d | 2020-05-08 09:40:44 +0200 | [diff] [blame] | 193 | /* write header */ |
| 194 | if (fd >= 0) { |
| 195 | int rc = write(fd, &header, sizeof(header)); |
| 196 | if (rc < 0) |
| 197 | return rc; |
| 198 | } |
| 199 | |
| 200 | /* update fd in all lines in our global list of e1 lines */ |
| 201 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 202 | /* Set the PCAP file descriptor for all timeslots that have |
| 203 | * software LAPD instances, to ensure the osmo_lapd_pcap code is |
| 204 | * used to write PCAP files (if requested) */ |
| 205 | for (i = 0; i < ARRAY_SIZE(line->ts); i++) { |
| 206 | struct e1inp_ts *e1i_ts = &line->ts[i]; |
| 207 | if (e1i_ts->lapd) |
| 208 | e1i_ts->lapd->pcap_fd = fd; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* close previous and update global */ |
| 213 | if (pcap_fd >= 0) |
| 214 | close(pcap_fd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 215 | pcap_fd = fd; |
Sylvain Munaut | 4b45e9d | 2020-05-08 09:40:44 +0200 | [diff] [blame] | 216 | |
| 217 | return 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* This currently only works for the D-Channel */ |
| 221 | static void write_pcap_packet(int direction, int sapi, int tei, |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 222 | struct msgb *msg, int pcap_fd) { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 223 | if (pcap_fd < 0) |
| 224 | return; |
| 225 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 226 | time_t cur_time; |
| 227 | struct tm *tm; |
| 228 | |
| 229 | struct fake_linux_lapd_header header = { |
| 230 | .pkttype = 4, |
| 231 | .hatype = 0, |
| 232 | .halen = 0, |
| 233 | .addr = direction == PCAP_OUTPUT ? 0x0 : 0x1, |
| 234 | .protocol = ntohs(48), |
| 235 | }; |
| 236 | |
| 237 | struct lapd_header lapd_header = { |
| 238 | .ea1 = 0, |
| 239 | .cr = direction == PCAP_OUTPUT ? 1 : 0, |
| 240 | .sapi = sapi & 0x3F, |
| 241 | .ea2 = 1, |
| 242 | .tei = tei & 0x7F, |
| 243 | .control_foo = 0x03 /* UI */, |
| 244 | }; |
| 245 | |
| 246 | struct pcaprec_hdr payload_header = { |
| 247 | .ts_sec = 0, |
| 248 | .ts_usec = 0, |
| 249 | .incl_len = msgb_l2len(msg) + sizeof(struct fake_linux_lapd_header) |
| 250 | + sizeof(struct lapd_header), |
| 251 | .orig_len = msgb_l2len(msg) + sizeof(struct fake_linux_lapd_header) |
| 252 | + sizeof(struct lapd_header), |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | cur_time = time(NULL); |
| 257 | tm = localtime(&cur_time); |
| 258 | payload_header.ts_sec = mktime(tm); |
| 259 | |
Harald Welte | c9295ea | 2014-08-21 02:41:41 +0200 | [diff] [blame] | 260 | write(pcap_fd, &payload_header, sizeof(payload_header)); |
| 261 | write(pcap_fd, &header, sizeof(header)); |
| 262 | write(pcap_fd, &lapd_header, sizeof(lapd_header)); |
| 263 | write(pcap_fd, msg->l2h, msgb_l2len(msg)); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Harald Welte | 4ca5c53 | 2016-07-27 23:05:03 +0200 | [diff] [blame] | 266 | const struct value_string e1inp_sign_type_names[5] = { |
| 267 | { E1INP_SIGN_NONE, "None" }, |
| 268 | { E1INP_SIGN_OML, "OML" }, |
| 269 | { E1INP_SIGN_RSL, "RSL" }, |
| 270 | { E1INP_SIGN_OSMO, "OSMO" }, |
| 271 | { 0, NULL } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 272 | }; |
Harald Welte | 4ca5c53 | 2016-07-27 23:05:03 +0200 | [diff] [blame] | 273 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 274 | const char *e1inp_signtype_name(enum e1inp_sign_type tp) |
| 275 | { |
Harald Welte | 4ca5c53 | 2016-07-27 23:05:03 +0200 | [diff] [blame] | 276 | return get_value_string(e1inp_sign_type_names, tp); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Harald Welte | b3952c6 | 2020-06-20 22:07:36 +0200 | [diff] [blame] | 279 | const struct value_string e1inp_ts_type_names[] = { |
Harald Welte | 4ca5c53 | 2016-07-27 23:05:03 +0200 | [diff] [blame] | 280 | { E1INP_TS_TYPE_NONE, "None" }, |
| 281 | { E1INP_TS_TYPE_SIGN, "Signalling" }, |
| 282 | { E1INP_TS_TYPE_TRAU, "TRAU" }, |
Harald Welte | a0108e7 | 2016-07-27 21:44:50 +0200 | [diff] [blame] | 283 | { E1INP_TS_TYPE_RAW, "RAW" }, |
Harald Welte | 7a228eb | 2016-07-28 11:09:31 +0200 | [diff] [blame] | 284 | { E1INP_TS_TYPE_HDLC, "HDLC" }, |
Harald Welte | b3952c6 | 2020-06-20 22:07:36 +0200 | [diff] [blame] | 285 | { E1INP_TS_TYPE_I460, "I460" }, |
Harald Welte | 4ca5c53 | 2016-07-27 23:05:03 +0200 | [diff] [blame] | 286 | { 0, NULL } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | const char *e1inp_tstype_name(enum e1inp_ts_type tp) |
| 290 | { |
Harald Welte | 4ca5c53 | 2016-07-27 23:05:03 +0200 | [diff] [blame] | 291 | return get_value_string(e1inp_ts_type_names, tp); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Pablo Neira Ayuso | 96e7263 | 2011-06-26 19:08:05 +0200 | [diff] [blame] | 294 | int abis_sendmsg(struct msgb *msg) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 295 | { |
| 296 | struct e1inp_sign_link *sign_link = msg->dst; |
| 297 | struct e1inp_driver *e1inp_driver; |
| 298 | struct e1inp_ts *e1i_ts; |
Alexander Couzens | 35daa67 | 2016-11-08 16:17:20 +0100 | [diff] [blame] | 299 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 300 | msg->l2h = msg->data; |
| 301 | |
| 302 | /* don't know how to route this message. */ |
| 303 | if (sign_link == NULL) { |
Harald Welte | 40b0e8c | 2011-07-21 16:57:34 +0200 | [diff] [blame] | 304 | LOGP(DLINP, LOGL_ERROR, "abis_sendmsg: msg->dst == NULL: %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 305 | osmo_hexdump(msg->data, msg->len)); |
| 306 | talloc_free(msg); |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | e1i_ts = sign_link->ts; |
| 310 | if (!osmo_timer_pending(&e1i_ts->sign.tx_timer)) { |
| 311 | /* notify the driver we have something to write */ |
| 312 | e1inp_driver = sign_link->ts->line->driver; |
| 313 | e1inp_driver->want_write(e1i_ts); |
| 314 | } |
| 315 | msgb_enqueue(&sign_link->tx_list, msg); |
| 316 | |
Harald Welte | 7f9d851 | 2016-07-04 09:59:46 +0200 | [diff] [blame] | 317 | /* we only need to write a 'Fake LAPD' packet here, if the |
| 318 | * underlying driver hides LAPD from us. If we use the |
| 319 | * libosmocore LAPD implementation, it will take care of writing |
| 320 | * the _actual_ LAPD packet */ |
| 321 | if (!e1i_ts->lapd) { |
| 322 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 323 | sign_link->tei, msg, e1i_ts->line->pcap_fd); |
Harald Welte | 7f9d851 | 2016-07-04 09:59:46 +0200 | [diff] [blame] | 324 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
Pablo Neira Ayuso | 96e7263 | 2011-06-26 19:08:05 +0200 | [diff] [blame] | 329 | int abis_rsl_sendmsg(struct msgb *msg) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 330 | { |
Pablo Neira Ayuso | 96e7263 | 2011-06-26 19:08:05 +0200 | [diff] [blame] | 331 | return abis_sendmsg(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 332 | } |
| 333 | |
Andreas Eversberg | 917454d | 2022-12-04 13:11:45 +0100 | [diff] [blame] | 334 | int e1inp_ts_send_raw(struct e1inp_ts *ts, struct msgb *msg) |
| 335 | { |
| 336 | struct e1inp_driver *driver; |
| 337 | |
| 338 | OSMO_ASSERT(ts->type == E1INP_TS_TYPE_RAW); |
| 339 | |
| 340 | /* notify the driver we have something to write */ |
| 341 | driver = ts->line->driver; |
| 342 | driver->want_write(ts); |
| 343 | |
| 344 | msgb_enqueue(&ts->raw.tx_queue, msg); |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | int e1inp_ts_send_hdlc(struct e1inp_ts *ts, struct msgb *msg) |
| 350 | { |
| 351 | struct e1inp_driver *driver; |
| 352 | |
| 353 | OSMO_ASSERT(ts->type == E1INP_TS_TYPE_HDLC); |
| 354 | |
| 355 | /* notify the driver we have something to write */ |
| 356 | driver = ts->line->driver; |
| 357 | driver->want_write(ts); |
| 358 | |
| 359 | msgb_enqueue(&ts->hdlc.tx_queue, msg); |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 364 | /* Timeslot */ |
| 365 | int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line, |
Pablo Neira Ayuso | 211d2ca | 2011-06-07 17:15:10 +0200 | [diff] [blame] | 366 | int (*trau_rcv_cb)(struct subch_demux *dmx, int ch, |
Harald Welte | 5226e5b | 2020-05-07 23:09:16 +0200 | [diff] [blame] | 367 | const ubit_t *data, int len, void *_priv)) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 368 | { |
| 369 | if (ts->type == E1INP_TS_TYPE_TRAU && ts->line && line) |
| 370 | return 0; |
| 371 | |
| 372 | ts->type = E1INP_TS_TYPE_TRAU; |
| 373 | ts->line = line; |
| 374 | |
| 375 | subchan_mux_init(&ts->trau.mux); |
Pablo Neira Ayuso | 211d2ca | 2011-06-07 17:15:10 +0200 | [diff] [blame] | 376 | ts->trau.demux.out_cb = trau_rcv_cb; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 377 | ts->trau.demux.data = ts; |
| 378 | subch_demux_init(&ts->trau.demux); |
| 379 | return 0; |
| 380 | } |
| 381 | |
Harald Welte | b3952c6 | 2020-06-20 22:07:36 +0200 | [diff] [blame] | 382 | int e1inp_ts_config_i460(struct e1inp_ts *ts, struct e1inp_line *line) |
| 383 | { |
| 384 | if (ts->type == E1INP_TS_TYPE_I460 && ts->line && line) |
| 385 | return 0; |
| 386 | |
| 387 | ts->type = E1INP_TS_TYPE_I460; |
| 388 | ts->line = line; |
| 389 | osmo_i460_ts_init(&ts->i460.i460_ts); |
| 390 | return 0; |
| 391 | } |
| 392 | |
Harald Welte | b903188 | 2020-05-02 21:09:15 +0200 | [diff] [blame] | 393 | void e1inp_ts_name(char *out, size_t out_len, const struct e1inp_ts *ts) |
| 394 | { |
| 395 | if (ts->line->name) |
| 396 | snprintf(out, out_len, "%s:%u", ts->line->name, ts->num); |
| 397 | else |
| 398 | snprintf(out, out_len, "%u:%u", ts->line->num, ts->num); |
| 399 | } |
| 400 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 401 | int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line) |
| 402 | { |
| 403 | if (ts->type == E1INP_TS_TYPE_SIGN && ts->line && line) |
| 404 | return 0; |
| 405 | |
| 406 | ts->type = E1INP_TS_TYPE_SIGN; |
| 407 | ts->line = line; |
| 408 | |
| 409 | if (line && line->driver) |
| 410 | ts->sign.delay = line->driver->default_delay; |
| 411 | else |
| 412 | ts->sign.delay = 100000; |
| 413 | INIT_LLIST_HEAD(&ts->sign.sign_links); |
| 414 | return 0; |
| 415 | } |
| 416 | |
Harald Welte | a0108e7 | 2016-07-27 21:44:50 +0200 | [diff] [blame] | 417 | int e1inp_ts_config_raw(struct e1inp_ts *ts, struct e1inp_line *line, |
| 418 | void (*raw_recv_cb)(struct e1inp_ts *ts, |
| 419 | struct msgb *msg)) |
| 420 | { |
| 421 | if (ts->type == E1INP_TS_TYPE_RAW && ts->line && line) |
| 422 | return 0; |
| 423 | |
| 424 | ts->type = E1INP_TS_TYPE_RAW; |
| 425 | ts->line = line; |
| 426 | ts->raw.recv_cb = raw_recv_cb; |
| 427 | INIT_LLIST_HEAD(&ts->raw.tx_queue); |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
Harald Welte | 7a228eb | 2016-07-28 11:09:31 +0200 | [diff] [blame] | 432 | int e1inp_ts_config_hdlc(struct e1inp_ts *ts, struct e1inp_line *line, |
| 433 | void (*hdlc_recv_cb)(struct e1inp_ts *ts, |
| 434 | struct msgb *msg)) |
| 435 | { |
| 436 | if (ts->type == E1INP_TS_TYPE_HDLC && ts->line && line) |
| 437 | return 0; |
| 438 | |
| 439 | ts->type = E1INP_TS_TYPE_HDLC; |
| 440 | ts->line = line; |
| 441 | ts->hdlc.recv_cb = hdlc_recv_cb; |
| 442 | INIT_LLIST_HEAD(&ts->hdlc.tx_queue); |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Philipp Maier | cc42444 | 2023-02-13 12:05:50 +0100 | [diff] [blame] | 447 | int e1inp_ts_config_none(struct e1inp_ts *ts, struct e1inp_line *line) |
| 448 | { |
| 449 | if (ts->type == E1INP_TS_TYPE_NONE && ts->line && line) |
| 450 | return 0; |
| 451 | |
| 452 | ts->type = E1INP_TS_TYPE_NONE; |
| 453 | ts->line = line; |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
Andreas Eversberg | 9a15109 | 2023-01-03 18:50:53 +0100 | [diff] [blame] | 458 | int e1inp_ts_set_sa_bits(struct e1inp_line *line, uint8_t sa_bits) |
| 459 | { |
| 460 | struct e1inp_driver *driver; |
| 461 | |
| 462 | driver = line->driver; |
| 463 | if (!driver->set_sa_bits) |
| 464 | return -ENOTSUP; |
| 465 | return driver->set_sa_bits(line, sa_bits); |
| 466 | } |
| 467 | |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 468 | static int e1inp_line_use_cb(struct osmo_use_count_entry *use_count_entry, int32_t old_use_count, |
| 469 | const char *file, int file_line) |
| 470 | { |
| 471 | char buf[512]; |
| 472 | struct osmo_use_count *uc = use_count_entry->use_count; |
| 473 | struct e1inp_line *line = uc->talloc_object; |
| 474 | |
| 475 | LOGPSRC(DLINP, LOGL_INFO, file, file_line, |
| 476 | "E1L(%u) Line (%p) reference count %s changed %" PRId32 " -> %" PRId32 " [%s]\n", |
| 477 | (line)->num, line, use_count_entry->use, |
| 478 | old_use_count, use_count_entry->count, |
| 479 | osmo_use_count_name_buf(buf, sizeof(buf), uc)); |
| 480 | |
| 481 | if (!use_count_entry->count) |
| 482 | osmo_use_count_free(use_count_entry); |
| 483 | |
| 484 | if (osmo_use_count_total(uc) > 0) |
| 485 | return 0; |
| 486 | |
| 487 | /* Remove our counter group from libosmocore's global counter |
| 488 | * list if we are freeing the last remaining talloc context. |
| 489 | * Otherwise we get a use-after-free when libosmocore's timer |
| 490 | * ticks again and attempts to update these counters (OS#3011). |
| 491 | * |
| 492 | * Note that talloc internally counts "secondary" references |
| 493 | * _in addition to_ the initial allocation context, so yes, |
| 494 | * we must check for *zero* remaining secondary contexts here. */ |
| 495 | if (talloc_reference_count(line->rate_ctr) == 0) { |
| 496 | rate_ctr_group_free(line->rate_ctr); |
| 497 | } else { |
| 498 | /* We are not freeing the last talloc context. |
| 499 | * Instead of calling talloc_free(), unlink this 'line' pointer |
| 500 | * which serves as one of several talloc contexts for the rate |
| 501 | * counters and driver private state. */ |
| 502 | talloc_unlink(line, line->rate_ctr); |
| 503 | if (line->driver_data) |
| 504 | talloc_unlink(line, line->driver_data); |
| 505 | } |
Pau Espin Pedrol | 49924f0 | 2021-09-22 19:31:54 +0200 | [diff] [blame] | 506 | |
| 507 | llist_del(&line->list); |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 508 | talloc_free(line); |
| 509 | return 0; |
| 510 | } |
| 511 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 512 | struct e1inp_line *e1inp_line_find(uint8_t e1_nr) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 513 | { |
| 514 | struct e1inp_line *e1i_line; |
| 515 | |
| 516 | /* iterate over global list of e1 lines */ |
| 517 | llist_for_each_entry(e1i_line, &e1inp_line_list, list) { |
| 518 | if (e1i_line->num == e1_nr) |
| 519 | return e1i_line; |
| 520 | } |
| 521 | return NULL; |
| 522 | } |
| 523 | |
Pau Espin Pedrol | dd48e25 | 2021-09-22 19:37:54 +0200 | [diff] [blame] | 524 | /*! Create a new e1inp line object. |
| 525 | * \param[in] e1_nr The line number of the new line to be created. |
| 526 | * \param[in] driver_name String identifying the driver (see e1inp_driver_register() for more info). |
| 527 | * \returns pointer to the new object created. |
| 528 | * |
| 529 | * The allocated object is returned with a count reference with name "ctor", |
| 530 | * which must be dropped in order to free the object [e1inp_line_put2(line, "ctor")]. |
| 531 | */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 532 | struct e1inp_line * |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 533 | e1inp_line_create(uint8_t e1_nr, const char *driver_name) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 534 | { |
| 535 | struct e1inp_driver *driver; |
| 536 | struct e1inp_line *line; |
| 537 | int i; |
| 538 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 539 | line = e1inp_line_find(e1_nr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 540 | if (line) { |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 541 | LOGPIL(line, DLINP, LOGL_ERROR, "E1 Line %u already exists\n", e1_nr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 542 | return NULL; |
| 543 | } |
| 544 | |
| 545 | driver = e1inp_driver_find(driver_name); |
| 546 | if (!driver) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 547 | LOGP(DLINP, LOGL_ERROR, "No such E1 driver '%s'\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 548 | driver_name); |
| 549 | return NULL; |
| 550 | } |
| 551 | |
| 552 | line = talloc_zero(tall_e1inp_ctx, struct e1inp_line); |
| 553 | if (!line) |
| 554 | return NULL; |
| 555 | |
| 556 | line->driver = driver; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 557 | line->num = e1_nr; |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 558 | line->pcap_fd = -1; |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 559 | |
Oliver Smith | ef0f7c2 | 2022-11-23 12:32:36 +0100 | [diff] [blame] | 560 | line->keepalive_idle_timeout = E1INP_USE_DEFAULT; |
| 561 | line->keepalive_num_probes = E1INP_USE_DEFAULT; |
| 562 | line->keepalive_probe_interval = E1INP_USE_DEFAULT; |
Daniel Willmann | c20af05 | 2022-12-15 11:50:34 +0100 | [diff] [blame] | 563 | line->connect_timeout = 0; |
Oliver Smith | ef0f7c2 | 2022-11-23 12:32:36 +0100 | [diff] [blame] | 564 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 565 | line->rate_ctr = rate_ctr_group_alloc(line, &e1inp_ctr_g_d, line->num); |
Harald Welte | ff8eed2 | 2017-07-12 00:38:25 +0200 | [diff] [blame] | 566 | if (!line->rate_ctr) { |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 567 | LOGPIL(line, DLINP, LOGL_ERROR, "Cannot allocate counter group\n"); |
Harald Welte | ff8eed2 | 2017-07-12 00:38:25 +0200 | [diff] [blame] | 568 | talloc_free(line); |
| 569 | return NULL; |
| 570 | } |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 571 | |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 572 | line->num_ts = NUM_E1_TS; |
| 573 | for (i = 0; i < line->num_ts; i++) { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 574 | line->ts[i].num = i+1; |
| 575 | line->ts[i].line = line; |
| 576 | } |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 577 | |
| 578 | line->use_count.talloc_object = line; |
| 579 | line->use_count.use_cb = e1inp_line_use_cb; |
| 580 | e1inp_line_get2(line, "ctor"); |
| 581 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 582 | llist_add_tail(&line->list, &e1inp_line_list); |
| 583 | |
| 584 | return line; |
| 585 | } |
| 586 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 587 | struct e1inp_line * |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 588 | e1inp_line_clone(void *ctx, struct e1inp_line *line, const char *use) |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 589 | { |
| 590 | struct e1inp_line *clone; |
| 591 | |
| 592 | /* clone virtual E1 line for this new OML link. */ |
| 593 | clone = talloc_zero(ctx, struct e1inp_line); |
| 594 | if (clone == NULL) |
| 595 | return NULL; |
| 596 | |
| 597 | memcpy(clone, line, sizeof(struct e1inp_line)); |
Stefan Sperling | b016207 | 2018-05-22 18:19:00 +0200 | [diff] [blame] | 598 | |
| 599 | if (line->name) { |
| 600 | clone->name = talloc_strdup(clone, line->name); |
| 601 | OSMO_ASSERT(clone->name); |
| 602 | } |
| 603 | if (line->sock_path) { |
| 604 | clone->sock_path = talloc_strdup(clone, line->sock_path); |
| 605 | OSMO_ASSERT(clone->sock_path); |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * Rate counters and driver data are shared between clones. These are pointers |
| 610 | * to dynamic memory so we use reference counting to avoid a double-free (see OS#3137). |
| 611 | */ |
| 612 | OSMO_ASSERT(line->rate_ctr); |
| 613 | clone->rate_ctr = talloc_reference(clone, line->rate_ctr); |
| 614 | if (line->driver_data) |
| 615 | clone->driver_data = talloc_reference(clone, line->driver_data); |
| 616 | |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 617 | clone->use_count = (struct osmo_use_count) { |
| 618 | .talloc_object = clone, |
| 619 | .use_cb = e1inp_line_use_cb, |
| 620 | .use_counts = {0}, |
| 621 | }; |
Pau Espin Pedrol | 57ff57a | 2021-10-13 16:37:59 +0200 | [diff] [blame] | 622 | /* initialize list so it can be safely deleted without affecting original line */ |
| 623 | INIT_LLIST_HEAD(&clone->list); |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 624 | e1inp_line_get2(clone, use); /* Clone is used internally for bfd */ |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 625 | return clone; |
| 626 | } |
| 627 | |
| 628 | void e1inp_line_get(struct e1inp_line *line) |
| 629 | { |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 630 | e1inp_line_get2(line, "unknown"); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | void e1inp_line_put(struct e1inp_line *line) |
| 634 | { |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 635 | e1inp_line_put2(line, "unknown"); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 636 | } |
| 637 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 638 | void |
| 639 | e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops) |
| 640 | { |
| 641 | line->ops = ops; |
| 642 | } |
| 643 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 644 | #if 0 |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 645 | struct e1inp_line *e1inp_line_find_create(uint8_t e1_nr) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 646 | { |
| 647 | struct e1inp_line *line; |
| 648 | int i; |
| 649 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 650 | line = e1inp_line_find(e1_nr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 651 | if (line) |
| 652 | return line; |
| 653 | |
| 654 | line = talloc_zero(tall_e1inp_ctx, struct e1inp_line); |
| 655 | if (!line) |
| 656 | return NULL; |
| 657 | |
| 658 | line->num = e1_nr; |
| 659 | for (i = 0; i < NUM_E1_TS; i++) { |
| 660 | line->ts[i].num = i+1; |
| 661 | line->ts[i].line = line; |
| 662 | } |
| 663 | llist_add_tail(&line->list, &e1inp_line_list); |
| 664 | |
| 665 | return line; |
| 666 | } |
| 667 | #endif |
| 668 | |
| 669 | static struct e1inp_ts *e1inp_ts_get(uint8_t e1_nr, uint8_t ts_nr) |
| 670 | { |
| 671 | struct e1inp_line *e1i_line; |
| 672 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 673 | e1i_line = e1inp_line_find(e1_nr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 674 | if (!e1i_line) |
| 675 | return NULL; |
| 676 | |
| 677 | return &e1i_line->ts[ts_nr-1]; |
| 678 | } |
| 679 | |
| 680 | struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr) |
| 681 | { |
| 682 | struct e1inp_ts *e1i_ts = e1inp_ts_get(e1_nr, ts_nr); |
| 683 | |
| 684 | if (!e1i_ts) |
| 685 | return NULL; |
| 686 | |
| 687 | return &e1i_ts->trau.mux; |
| 688 | } |
| 689 | |
| 690 | /* Signalling Link */ |
| 691 | |
| 692 | struct e1inp_sign_link *e1inp_lookup_sign_link(struct e1inp_ts *e1i, |
| 693 | uint8_t tei, uint8_t sapi) |
| 694 | { |
| 695 | struct e1inp_sign_link *link; |
| 696 | |
| 697 | llist_for_each_entry(link, &e1i->sign.sign_links, list) { |
| 698 | if (link->sapi == sapi && link->tei == tei) |
| 699 | return link; |
| 700 | } |
| 701 | |
| 702 | return NULL; |
| 703 | } |
| 704 | |
| 705 | /* create a new signalling link in a E1 timeslot */ |
| 706 | |
| 707 | struct e1inp_sign_link * |
| 708 | e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type, |
| 709 | struct gsm_bts_trx *trx, uint8_t tei, |
| 710 | uint8_t sapi) |
| 711 | { |
| 712 | struct e1inp_sign_link *link; |
| 713 | |
| 714 | if (ts->type != E1INP_TS_TYPE_SIGN) |
| 715 | return NULL; |
| 716 | |
| 717 | link = talloc_zero(tall_sigl_ctx, struct e1inp_sign_link); |
| 718 | if (!link) |
| 719 | return NULL; |
| 720 | |
| 721 | link->ts = ts; |
| 722 | link->type = type; |
| 723 | INIT_LLIST_HEAD(&link->tx_list); |
| 724 | link->trx = trx; |
| 725 | link->tei = tei; |
| 726 | link->sapi = sapi; |
| 727 | |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 728 | e1inp_line_get2(link->ts->line, "e1inp_sign_link"); |
Pau Espin Pedrol | 89c6b8a | 2020-06-08 20:26:44 +0200 | [diff] [blame] | 729 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 730 | llist_add_tail(&link->list, &ts->sign.sign_links); |
| 731 | |
| 732 | return link; |
| 733 | } |
| 734 | |
| 735 | void e1inp_sign_link_destroy(struct e1inp_sign_link *link) |
| 736 | { |
| 737 | struct msgb *msg; |
| 738 | |
| 739 | llist_del(&link->list); |
| 740 | while (!llist_empty(&link->tx_list)) { |
| 741 | msg = msgb_dequeue(&link->tx_list); |
| 742 | msgb_free(msg); |
| 743 | } |
| 744 | |
| 745 | if (link->ts->type == E1INP_TS_TYPE_SIGN) |
| 746 | osmo_timer_del(&link->ts->sign.tx_timer); |
| 747 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 748 | if (link->ts->line->driver->close) |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 749 | link->ts->line->driver->close(link); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 750 | |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 751 | e1inp_line_put2(link->ts->line, "e1inp_sign_link"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 752 | talloc_free(link); |
| 753 | } |
| 754 | |
| 755 | /* XXX */ |
| 756 | /* the E1 driver tells us he has received something on a TS */ |
| 757 | int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg, |
| 758 | uint8_t tei, uint8_t sapi) |
| 759 | { |
| 760 | struct e1inp_sign_link *link; |
| 761 | int ret = 0; |
| 762 | |
| 763 | switch (ts->type) { |
| 764 | case E1INP_TS_TYPE_SIGN: |
Harald Welte | 7f9d851 | 2016-07-04 09:59:46 +0200 | [diff] [blame] | 765 | /* we only need to write a 'Fake LAPD' packet here, if |
| 766 | * the underlying driver hides LAPD from us. If we use |
| 767 | * the libosmocore LAPD implementation, it will take |
| 768 | * care of writing the _actual_ LAPD packet */ |
| 769 | if (!ts->lapd) |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 770 | write_pcap_packet(PCAP_INPUT, sapi, tei, msg, ts->line->pcap_fd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 771 | /* consult the list of signalling links */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 772 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 773 | if (!link) { |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 774 | LOGPITS(ts, DLMI, LOGL_ERROR, "didn't find signalling link for " |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 775 | "tei %d, sapi %d\n", tei, sapi); |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 776 | msgb_free(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 777 | return -EINVAL; |
| 778 | } |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 779 | if (!ts->line->ops->sign_link) { |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 780 | LOGPITS(ts, DLINP, LOGL_ERROR, "Fix your application, " |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 781 | "no action set for signalling messages.\n"); |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 782 | msgb_free(msg); |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 783 | return -ENOENT; |
| 784 | } |
Pablo Neira Ayuso | dbd82fb | 2011-07-05 15:29:23 +0200 | [diff] [blame] | 785 | msg->dst = link; |
| 786 | ts->line->ops->sign_link(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 787 | break; |
| 788 | case E1INP_TS_TYPE_TRAU: |
Pablo Neira Ayuso | 211d2ca | 2011-06-07 17:15:10 +0200 | [diff] [blame] | 789 | ret = subch_demux_in(&ts->trau.demux, msg->l2h, msgb_l2len(msg)); |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 790 | msgb_free(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 791 | break; |
Harald Welte | a0108e7 | 2016-07-27 21:44:50 +0200 | [diff] [blame] | 792 | case E1INP_TS_TYPE_RAW: |
| 793 | ts->raw.recv_cb(ts, msg); |
| 794 | break; |
Harald Welte | 7a228eb | 2016-07-28 11:09:31 +0200 | [diff] [blame] | 795 | case E1INP_TS_TYPE_HDLC: |
| 796 | ts->hdlc.recv_cb(ts, msg); |
| 797 | break; |
Harald Welte | b3952c6 | 2020-06-20 22:07:36 +0200 | [diff] [blame] | 798 | case E1INP_TS_TYPE_I460: |
| 799 | osmo_i460_demux_in(&ts->i460.i460_ts, msg->l2h, msgb_l2len(msg)); |
| 800 | msgb_free(msg); |
| 801 | break; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 802 | default: |
| 803 | ret = -EINVAL; |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 804 | LOGPITS(ts, DLMI, LOGL_ERROR, "unknown TS type %u\n", ts->type); |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 805 | msgb_free(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 806 | break; |
| 807 | } |
| 808 | |
| 809 | return ret; |
| 810 | } |
| 811 | |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 812 | /*! \brief Receive some data from the L1/HDLC into LAPD of a timeslot |
| 813 | * \param[in] e1i_ts E1 Timeslot data structure |
| 814 | * \param[in] msg Message buffer containing full LAPD message |
| 815 | * |
| 816 | * This is a wrapper around e1inp_rx_ts(), but feeding the incoming |
| 817 | * message first into our LAPD code. This allows a driver to read raw |
| 818 | * (HDLC decoded) data from the timeslot, instead of a LAPD stack |
| 819 | * present in any underlying driver. |
| 820 | */ |
| 821 | int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg) |
| 822 | { |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 823 | unsigned int sapi, tei; |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 824 | int ret = 0, error = 0; |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 825 | |
| 826 | sapi = msg->data[0] >> 2; |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 827 | if ((msg->data[0] & 0x1)) |
| 828 | tei = 0; |
| 829 | else |
| 830 | tei = msg->data[1] >> 1; |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 831 | |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 832 | LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "<= len = %d, sapi(%d) tei(%d)\n", msg->len, sapi, tei); |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 833 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 834 | ret = lapd_receive(e1i_ts->lapd, msg, &error); |
| 835 | if (ret < 0) { |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 836 | switch(error) { |
| 837 | case LAPD_ERR_UNKNOWN_TEI: |
| 838 | /* We don't know about this TEI, probably the BSC |
| 839 | * lost local states (it crashed or it was stopped), |
| 840 | * notify the driver to see if it can do anything to |
| 841 | * recover the existing signalling links with the BTS. |
| 842 | */ |
| 843 | e1inp_event(e1i_ts, S_L_INP_TEI_UNKNOWN, tei, sapi); |
| 844 | return -EIO; |
| 845 | } |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 846 | } |
| 847 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 848 | return 0; |
| 849 | } |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 850 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 851 | void e1inp_dlsap_up(struct osmo_dlsap_prim *dp, uint8_t tei, uint8_t sapi, |
| 852 | void *rx_cbdata) |
| 853 | { |
| 854 | struct e1inp_ts *e1i_ts = rx_cbdata; |
| 855 | struct msgb *msg = dp->oph.msg; |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 856 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 857 | switch (dp->oph.primitive) { |
| 858 | case PRIM_DL_EST: |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 859 | LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "DL_EST: sapi(%d) tei(%d)\n", sapi, tei); |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 860 | e1inp_event(e1i_ts, S_L_INP_TEI_UP, tei, sapi); |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 861 | break; |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 862 | case PRIM_DL_REL: |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 863 | LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "DL_REL: sapi(%d) tei(%d)\n", sapi, tei); |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 864 | e1inp_event(e1i_ts, S_L_INP_TEI_DN, tei, sapi); |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 865 | break; |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 866 | case PRIM_DL_DATA: |
| 867 | case PRIM_DL_UNIT_DATA: |
| 868 | if (dp->oph.operation == PRIM_OP_INDICATION) { |
| 869 | msg->l2h = msg->l3h; |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 870 | LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "RX: %s sapi=%d tei=%d\n", |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 871 | osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)), |
| 872 | sapi, tei); |
| 873 | e1inp_rx_ts(e1i_ts, msg, tei, sapi); |
| 874 | return; |
| 875 | } |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 876 | break; |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 877 | case PRIM_MDL_ERROR: |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 878 | LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "MDL_EERROR: cause(%d)\n", dp->u.error_ind.cause); |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 879 | break; |
| 880 | default: |
| 881 | printf("ERROR: unknown prim\n"); |
| 882 | break; |
| 883 | } |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 884 | |
| 885 | msgb_free(msg); |
| 886 | |
| 887 | return; |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 888 | } |
| 889 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 890 | #define TSX_ALLOC_SIZE 4096 |
| 891 | |
| 892 | /* called by driver if it wants to transmit on a given TS */ |
| 893 | struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts, |
| 894 | struct e1inp_sign_link **sign_link) |
| 895 | { |
| 896 | struct e1inp_sign_link *link; |
| 897 | struct msgb *msg = NULL; |
| 898 | int len; |
| 899 | |
| 900 | switch (e1i_ts->type) { |
| 901 | case E1INP_TS_TYPE_SIGN: |
| 902 | /* FIXME: implement this round robin */ |
| 903 | llist_for_each_entry(link, &e1i_ts->sign.sign_links, list) { |
| 904 | msg = msgb_dequeue(&link->tx_list); |
| 905 | if (msg) { |
| 906 | if (sign_link) |
| 907 | *sign_link = link; |
| 908 | break; |
| 909 | } |
| 910 | } |
| 911 | break; |
| 912 | case E1INP_TS_TYPE_TRAU: |
| 913 | msg = msgb_alloc(TSX_ALLOC_SIZE, "TRAU_TX"); |
| 914 | if (!msg) |
| 915 | return NULL; |
| 916 | len = subchan_mux_out(&e1i_ts->trau.mux, msg->data, 40); |
Pablo Neira Ayuso | 33f7175 | 2013-07-05 15:44:12 +0200 | [diff] [blame] | 917 | if (len != 40) { |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 918 | LOGPITS(e1i_ts, DLMI, LOGL_ERROR, "cannot transmit, failed to mux\n"); |
Pablo Neira Ayuso | 33f7175 | 2013-07-05 15:44:12 +0200 | [diff] [blame] | 919 | msgb_free(msg); |
| 920 | return NULL; |
| 921 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 922 | msgb_put(msg, 40); |
| 923 | break; |
Harald Welte | a0108e7 | 2016-07-27 21:44:50 +0200 | [diff] [blame] | 924 | case E1INP_TS_TYPE_RAW: |
| 925 | /* Get msgb from tx_queue */ |
| 926 | msg = msgb_dequeue(&e1i_ts->raw.tx_queue); |
| 927 | break; |
Harald Welte | 7a228eb | 2016-07-28 11:09:31 +0200 | [diff] [blame] | 928 | case E1INP_TS_TYPE_HDLC: |
| 929 | /* Get msgb from tx_queue */ |
| 930 | msg = msgb_dequeue(&e1i_ts->hdlc.tx_queue); |
| 931 | break; |
Harald Welte | b3952c6 | 2020-06-20 22:07:36 +0200 | [diff] [blame] | 932 | case E1INP_TS_TYPE_I460: |
| 933 | msg = msgb_alloc(TSX_ALLOC_SIZE, "I460_TX"); |
| 934 | if (!msg) |
| 935 | return NULL; |
| 936 | len = osmo_i460_mux_out(&e1i_ts->i460.i460_ts, msg->data, 160); |
| 937 | msgb_put(msg, len); |
| 938 | break; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 939 | default: |
Harald Welte | b5af099 | 2020-01-12 12:59:52 +0100 | [diff] [blame] | 940 | LOGPITS(e1i_ts, DLMI, LOGL_ERROR, "unsupported E1 TS type %u\n", e1i_ts->type); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 941 | return NULL; |
| 942 | } |
| 943 | return msg; |
| 944 | } |
| 945 | |
Pau Espin Pedrol | 8737ad4 | 2020-07-14 21:11:56 +0200 | [diff] [blame] | 946 | int e1inp_int_snd_event(struct e1inp_ts *ts, struct e1inp_sign_link *link, int evt) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 947 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 948 | struct input_signal_data isd; |
Pablo Neira Ayuso | 31fe5f2 | 2011-08-09 23:15:38 +0200 | [diff] [blame] | 949 | isd.line = ts->line; |
Harald Welte | f35d889 | 2016-10-16 15:33:52 +0200 | [diff] [blame] | 950 | isd.ts_nr = ts->num; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 951 | isd.link_type = link->type; |
| 952 | isd.trx = link->trx; |
Holger Hans Peter Freyther | 55467f0 | 2011-12-28 19:47:07 +0100 | [diff] [blame] | 953 | isd.tei = link->tei; |
| 954 | isd.sapi = link->sapi; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 955 | |
| 956 | /* report further upwards */ |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 957 | osmo_signal_dispatch(SS_L_INPUT, evt, &isd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 958 | return 0; |
| 959 | } |
| 960 | |
Holger Hans Peter Freyther | 55467f0 | 2011-12-28 19:47:07 +0100 | [diff] [blame] | 961 | |
| 962 | /* called by driver in case some kind of link state event */ |
| 963 | int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi) |
| 964 | { |
| 965 | struct e1inp_sign_link *link; |
| 966 | |
| 967 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 968 | if (!link) |
| 969 | return -EINVAL; |
| 970 | return e1inp_int_snd_event(ts, link, evt); |
| 971 | } |
| 972 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 973 | /* register a driver with the E1 core */ |
| 974 | int e1inp_driver_register(struct e1inp_driver *drv) |
| 975 | { |
| 976 | llist_add_tail(&drv->list, &e1inp_driver_list); |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | struct e1inp_driver *e1inp_driver_find(const char *name) |
| 981 | { |
| 982 | struct e1inp_driver *drv; |
| 983 | |
| 984 | llist_for_each_entry(drv, &e1inp_driver_list, list) { |
| 985 | if (!strcasecmp(name, drv->name)) |
| 986 | return drv; |
| 987 | } |
| 988 | return NULL; |
| 989 | } |
| 990 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 991 | int e1inp_line_update(struct e1inp_line *line) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 992 | { |
| 993 | struct input_signal_data isd; |
Harald Welte | 7f9d851 | 2016-07-04 09:59:46 +0200 | [diff] [blame] | 994 | int i, rc; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 995 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 996 | if (line->driver && line->ops && line->driver->line_update) { |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 997 | rc = line->driver->line_update(line); |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 998 | } else |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 999 | rc = 0; |
| 1000 | |
Harald Welte | 7f9d851 | 2016-07-04 09:59:46 +0200 | [diff] [blame] | 1001 | /* Set the PCAP file descriptor for all timeslots that have |
| 1002 | * software LAPD instances, to ensure the osmo_lapd_pcap code is |
| 1003 | * used to write PCAP files (if requested) */ |
| 1004 | for (i = 0; i < ARRAY_SIZE(line->ts); i++) { |
| 1005 | struct e1inp_ts *e1i_ts = &line->ts[i]; |
| 1006 | if (e1i_ts->lapd) |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 1007 | e1i_ts->lapd->pcap_fd = line->pcap_fd; |
Harald Welte | 7f9d851 | 2016-07-04 09:59:46 +0200 | [diff] [blame] | 1008 | } |
| 1009 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1010 | /* Send a signal to anyone who is interested in new lines being |
| 1011 | * configured */ |
| 1012 | memset(&isd, 0, sizeof(isd)); |
| 1013 | isd.line = line; |
Pablo Neira Ayuso | de66891 | 2011-08-16 17:26:23 +0200 | [diff] [blame] | 1014 | osmo_signal_dispatch(SS_L_INPUT, S_L_INP_LINE_INIT, &isd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1015 | |
| 1016 | return rc; |
| 1017 | } |
| 1018 | |
Pablo Neira Ayuso | a20762a | 2011-07-02 19:01:58 +0200 | [diff] [blame] | 1019 | static int e1i_sig_cb(unsigned int subsys, unsigned int signal, |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1020 | void *handler_data, void *signal_data) |
| 1021 | { |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 1022 | struct e1inp_line *line; |
| 1023 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1024 | if (subsys != SS_L_GLOBAL || |
| 1025 | signal != S_L_GLOBAL_SHUTDOWN) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1026 | return 0; |
| 1027 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 1028 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 1029 | if (line->pcap_fd >=0) |
| 1030 | close(line->pcap_fd); |
| 1031 | line->pcap_fd = -1; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Harald Welte | cac78fe | 2017-05-25 19:13:13 +0200 | [diff] [blame] | 1037 | const struct value_string e1inp_signal_names[] = { |
| 1038 | { S_L_INP_NONE, "NONE" }, |
| 1039 | { S_L_INP_TEI_UP, "TEI-UP" }, |
| 1040 | { S_L_INP_TEI_DN, "TEI-DOWN" }, |
| 1041 | { S_L_INP_TEI_UNKNOWN, "TEI-UNKNOWN" }, |
| 1042 | { S_L_INP_LINE_INIT, "LINE-INIT" }, |
| 1043 | { S_L_INP_LINE_ALARM, "LINE-ALARM" }, |
| 1044 | { S_L_INP_LINE_NOALARM, "LINE-NOALARM" }, |
Andreas Eversberg | eb4030f | 2023-01-03 18:47:52 +0100 | [diff] [blame] | 1045 | { S_L_INP_LINE_LOS, "LINE-LOS" }, |
| 1046 | { S_L_INP_LINE_NOLOS, "LINE-NOLOS" }, |
| 1047 | { S_L_INP_LINE_AIS, "LINE-AIS" }, |
| 1048 | { S_L_INP_LINE_NOAIS, "LINE-NOAIS" }, |
| 1049 | { S_L_INP_LINE_RAI, "LINE-RAI" }, |
| 1050 | { S_L_INP_LINE_NORAI, "LINE-NORAI" }, |
| 1051 | { S_L_INP_LINE_SLIP_RX, "LINE-SLIP-RX" }, |
| 1052 | { S_L_INP_LINE_SLIP_TX, "LINE-SLIP-TX" }, |
| 1053 | { S_L_INP_LINE_SA_BITS, "LINE-SA-BITS" }, |
Harald Welte | cac78fe | 2017-05-25 19:13:13 +0200 | [diff] [blame] | 1054 | { 0, NULL } |
| 1055 | }; |
| 1056 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1057 | void e1inp_misdn_init(void); |
| 1058 | void e1inp_dahdi_init(void); |
Harald Welte | c6c7076 | 2019-05-12 21:54:59 +0200 | [diff] [blame] | 1059 | void e1inp_e1d_init(void); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1060 | void e1inp_ipaccess_init(void); |
Pablo Neira Ayuso | 7e0d006 | 2011-08-19 11:36:15 +0200 | [diff] [blame] | 1061 | void e1inp_rs232_init(void); |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 1062 | void e1inp_unixsocket_init(void); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1063 | |
| 1064 | void e1inp_init(void) |
| 1065 | { |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 1066 | tall_e1inp_ctx = talloc_named_const(libosmo_abis_ctx, 1, "e1inp"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1067 | tall_sigl_ctx = talloc_named_const(tall_e1inp_ctx, 1, |
| 1068 | "e1inp_sign_link"); |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1069 | osmo_signal_register_handler(SS_L_GLOBAL, e1i_sig_cb, NULL); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1070 | |
| 1071 | e1inp_misdn_init(); |
Harald Welte | 3bc7885 | 2011-08-24 08:32:38 +0200 | [diff] [blame] | 1072 | #ifdef HAVE_DAHDI_USER_H |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1073 | e1inp_dahdi_init(); |
Harald Welte | 3bc7885 | 2011-08-24 08:32:38 +0200 | [diff] [blame] | 1074 | #endif |
Harald Welte | 52b0d45 | 2019-05-12 21:54:26 +0200 | [diff] [blame] | 1075 | #ifdef HAVE_E1D |
Sylvain Munaut | b559a53 | 2019-05-09 11:14:26 +0200 | [diff] [blame] | 1076 | e1inp_e1d_init(); |
| 1077 | #endif |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1078 | e1inp_ipaccess_init(); |
Pablo Neira Ayuso | 7e0d006 | 2011-08-19 11:36:15 +0200 | [diff] [blame] | 1079 | e1inp_rs232_init(); |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 1080 | e1inp_unixsocket_init(); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1081 | } |