Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [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 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <unistd.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <errno.h> |
| 26 | #include <string.h> |
| 27 | #include <time.h> |
| 28 | #include <sys/fcntl.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 29 | #include <sys/socket.h> |
| 30 | #include <sys/ioctl.h> |
| 31 | #include <arpa/inet.h> |
| 32 | #include <mISDNif.h> |
| 33 | |
| 34 | //#define AF_COMPATIBILITY_FUNC |
| 35 | //#include <compat_af_isdn.h> |
Holger Freyther | 66e092b | 2009-03-31 12:13:50 +0000 | [diff] [blame] | 36 | #ifndef AF_ISDN |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 37 | #define AF_ISDN 34 |
| 38 | #define PF_ISDN AF_ISDN |
Holger Freyther | 66e092b | 2009-03-31 12:13:50 +0000 | [diff] [blame] | 39 | #endif |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 40 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 41 | #include <osmocom/core/select.h> |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 42 | #include <osmocom/core/linuxlist.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 43 | #include <osmocom/core/msgb.h> |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 44 | #include <osmocom/core/talloc.h> |
| 45 | #include <osmocom/core/rate_ctr.h> |
| 46 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 47 | #include <openbsc/debug.h> |
| 48 | #include <openbsc/gsm_data.h> |
| 49 | #include <openbsc/e1_input.h> |
| 50 | #include <openbsc/abis_nm.h> |
| 51 | #include <openbsc/abis_rsl.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 52 | #include <openbsc/subchan_demux.h> |
Harald Welte | 45b407a | 2009-05-23 15:51:12 +0000 | [diff] [blame] | 53 | #include <openbsc/trau_frame.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 54 | #include <openbsc/trau_mux.h> |
Harald Welte | 29b9cf8 | 2009-11-30 19:43:54 +0100 | [diff] [blame] | 55 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 34e9749 | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 56 | #include <openbsc/misdn.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 57 | |
Harald Welte | c08e8be | 2011-03-04 13:53:51 +0100 | [diff] [blame] | 58 | #include "../../bscconfig.h" |
Harald Welte | ca17ef8 | 2011-02-05 15:13:27 +0100 | [diff] [blame] | 59 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 60 | #define NUM_E1_TS 32 |
| 61 | |
| 62 | /* list of all E1 drivers */ |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 63 | LLIST_HEAD(e1inp_driver_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 64 | |
| 65 | /* list of all E1 lines */ |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 66 | LLIST_HEAD(e1inp_line_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 67 | |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 68 | static void *tall_sigl_ctx; |
| 69 | |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 70 | static const struct rate_ctr_desc e1inp_ctr_d[] = { |
| 71 | [E1I_CTR_HDLC_ABORT] = { |
Harald Welte | c21aa18 | 2011-08-11 12:54:07 +0200 | [diff] [blame^] | 72 | "hdlc.abort", "HDLC abort" |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 73 | }, |
| 74 | [E1I_CTR_HDLC_BADFCS] = { |
Harald Welte | c21aa18 | 2011-08-11 12:54:07 +0200 | [diff] [blame^] | 75 | "hdlc.bad_fcs", "HLDC Bad FCS" |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 76 | }, |
| 77 | [E1I_CTR_HDLC_OVERR] = { |
| 78 | "hdlc.overrun", "HDLC Overrun" |
| 79 | }, |
| 80 | [E1I_CTR_ALARM] = { |
Harald Welte | c21aa18 | 2011-08-11 12:54:07 +0200 | [diff] [blame^] | 81 | "alarm", "Alarm" |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 82 | }, |
| 83 | [E1I_CTR_REMOVED] = { |
Harald Welte | c21aa18 | 2011-08-11 12:54:07 +0200 | [diff] [blame^] | 84 | "removed", "Line removed" |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 85 | }, |
| 86 | }; |
| 87 | |
| 88 | static const struct rate_ctr_group_desc e1inp_ctr_g_d = { |
| 89 | .group_name_prefix = "e1inp", |
| 90 | .group_description = "E1 Input subsystem", |
| 91 | .num_ctr = ARRAY_SIZE(e1inp_ctr_d), |
| 92 | .ctr_desc = e1inp_ctr_d, |
| 93 | }; |
| 94 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 95 | /* |
| 96 | * pcap writing of the misdn load |
| 97 | * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat |
| 98 | */ |
| 99 | #define DLT_LINUX_LAPD 177 |
| 100 | #define PCAP_INPUT 0 |
| 101 | #define PCAP_OUTPUT 1 |
| 102 | |
| 103 | struct pcap_hdr { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 104 | uint32_t magic_number; |
| 105 | uint16_t version_major; |
| 106 | uint16_t version_minor; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 107 | int32_t thiszone; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 108 | uint32_t sigfigs; |
| 109 | uint32_t snaplen; |
| 110 | uint32_t network; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 111 | } __attribute__((packed)); |
| 112 | |
| 113 | struct pcaprec_hdr { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 114 | uint32_t ts_sec; |
| 115 | uint32_t ts_usec; |
| 116 | uint32_t incl_len; |
| 117 | uint32_t orig_len; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 118 | } __attribute__((packed)); |
| 119 | |
| 120 | struct fake_linux_lapd_header { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 121 | uint16_t pkttype; |
| 122 | uint16_t hatype; |
| 123 | uint16_t halen; |
| 124 | uint64_t addr; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 125 | int16_t protocol; |
| 126 | } __attribute__((packed)); |
| 127 | |
| 128 | struct lapd_header { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 129 | uint8_t ea1 : 1; |
| 130 | uint8_t cr : 1; |
| 131 | uint8_t sapi : 6; |
| 132 | uint8_t ea2 : 1; |
| 133 | uint8_t tei : 7; |
| 134 | uint8_t control_foo; /* fake UM's ... */ |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 135 | } __attribute__((packed)); |
| 136 | |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 137 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, hatype) == 2, hatype_offset); |
| 138 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, halen) == 4, halen_offset); |
| 139 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, addr) == 6, addr_offset); |
| 140 | osmo_static_assert(offsetof(struct fake_linux_lapd_header, protocol) == 14, proto_offset); |
| 141 | osmo_static_assert(sizeof(struct fake_linux_lapd_header) == 16, lapd_header_size); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 142 | |
| 143 | |
| 144 | static int pcap_fd = -1; |
| 145 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 146 | void e1_set_pcap_fd(int fd) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 147 | { |
| 148 | int ret; |
| 149 | struct pcap_hdr header = { |
| 150 | .magic_number = 0xa1b2c3d4, |
| 151 | .version_major = 2, |
| 152 | .version_minor = 4, |
| 153 | .thiszone = 0, |
| 154 | .sigfigs = 0, |
| 155 | .snaplen = 65535, |
| 156 | .network = DLT_LINUX_LAPD, |
| 157 | }; |
| 158 | |
| 159 | pcap_fd = fd; |
| 160 | ret = write(pcap_fd, &header, sizeof(header)); |
| 161 | } |
| 162 | |
| 163 | /* This currently only works for the D-Channel */ |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 164 | static void write_pcap_packet(int direction, int sapi, int tei, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 165 | struct msgb *msg) { |
| 166 | if (pcap_fd < 0) |
| 167 | return; |
| 168 | |
| 169 | int ret; |
| 170 | time_t cur_time; |
| 171 | struct tm *tm; |
| 172 | |
| 173 | struct fake_linux_lapd_header header = { |
| 174 | .pkttype = 4, |
| 175 | .hatype = 0, |
| 176 | .halen = 0, |
| 177 | .addr = direction == PCAP_OUTPUT ? 0x0 : 0x1, |
| 178 | .protocol = ntohs(48), |
| 179 | }; |
| 180 | |
| 181 | struct lapd_header lapd_header = { |
| 182 | .ea1 = 0, |
| 183 | .cr = direction == PCAP_OUTPUT ? 1 : 0, |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 184 | .sapi = sapi & 0x3F, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 185 | .ea2 = 1, |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 186 | .tei = tei & 0x7F, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 187 | .control_foo = 0x03 /* UI */, |
| 188 | }; |
| 189 | |
| 190 | struct pcaprec_hdr payload_header = { |
| 191 | .ts_sec = 0, |
| 192 | .ts_usec = 0, |
Harald Welte | 95aa5c4 | 2011-02-12 14:00:23 +0100 | [diff] [blame] | 193 | .incl_len = msgb_l2len(msg) + sizeof(struct fake_linux_lapd_header) |
| 194 | + sizeof(struct lapd_header), |
| 195 | .orig_len = msgb_l2len(msg) + sizeof(struct fake_linux_lapd_header) |
| 196 | + sizeof(struct lapd_header), |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | |
| 200 | cur_time = time(NULL); |
| 201 | tm = localtime(&cur_time); |
| 202 | payload_header.ts_sec = mktime(tm); |
| 203 | |
| 204 | ret = write(pcap_fd, &payload_header, sizeof(payload_header)); |
| 205 | ret = write(pcap_fd, &header, sizeof(header)); |
| 206 | ret = write(pcap_fd, &lapd_header, sizeof(lapd_header)); |
Harald Welte | 95aa5c4 | 2011-02-12 14:00:23 +0100 | [diff] [blame] | 207 | ret = write(pcap_fd, msg->l2h, msgb_l2len(msg)); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 208 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 209 | |
Harald Welte | d256d4f | 2009-03-10 19:44:48 +0000 | [diff] [blame] | 210 | static const char *sign_types[] = { |
| 211 | [E1INP_SIGN_NONE] = "None", |
| 212 | [E1INP_SIGN_OML] = "OML", |
| 213 | [E1INP_SIGN_RSL] = "RSL", |
| 214 | }; |
| 215 | const char *e1inp_signtype_name(enum e1inp_sign_type tp) |
| 216 | { |
| 217 | if (tp >= ARRAY_SIZE(sign_types)) |
| 218 | return "undefined"; |
| 219 | return sign_types[tp]; |
| 220 | } |
| 221 | |
| 222 | static const char *ts_types[] = { |
| 223 | [E1INP_TS_TYPE_NONE] = "None", |
| 224 | [E1INP_TS_TYPE_SIGN] = "Signalling", |
| 225 | [E1INP_TS_TYPE_TRAU] = "TRAU", |
| 226 | }; |
| 227 | |
| 228 | const char *e1inp_tstype_name(enum e1inp_ts_type tp) |
| 229 | { |
| 230 | if (tp >= ARRAY_SIZE(ts_types)) |
| 231 | return "undefined"; |
| 232 | return ts_types[tp]; |
| 233 | } |
| 234 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 235 | /* callback when a TRAU frame was received */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 236 | static int subch_cb(struct subch_demux *dmx, int ch, uint8_t *data, int len, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 237 | void *_priv) |
| 238 | { |
| 239 | struct e1inp_ts *e1i_ts = _priv; |
| 240 | struct gsm_e1_subslot src_ss; |
| 241 | |
| 242 | src_ss.e1_nr = e1i_ts->line->num; |
| 243 | src_ss.e1_ts = e1i_ts->num; |
| 244 | src_ss.e1_ts_ss = ch; |
| 245 | |
| 246 | return trau_mux_input(&src_ss, data, len); |
| 247 | } |
| 248 | |
| 249 | int abis_rsl_sendmsg(struct msgb *msg) |
| 250 | { |
| 251 | struct e1inp_sign_link *sign_link; |
| 252 | struct e1inp_driver *e1inp_driver; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 253 | struct e1inp_ts *e1i_ts; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 254 | |
| 255 | msg->l2h = msg->data; |
| 256 | |
Harald Welte (local) | 5fe3318 | 2009-12-28 17:05:43 +0100 | [diff] [blame] | 257 | if (!msg->trx) { |
| 258 | LOGP(DRSL, LOGL_ERROR, "rsl_sendmsg: msg->trx == NULL: %s\n", |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 259 | osmo_hexdump(msg->data, msg->len)); |
Harald Welte | eab3335 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 260 | talloc_free(msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 261 | return -EINVAL; |
Harald Welte (local) | 5fe3318 | 2009-12-28 17:05:43 +0100 | [diff] [blame] | 262 | } else if (!msg->trx->rsl_link) { |
| 263 | LOGP(DRSL, LOGL_ERROR, "rsl_sendmsg: msg->trx->rsl_link == NULL: %s\n", |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 264 | osmo_hexdump(msg->data, msg->len)); |
Harald Welte (local) | 5fe3318 | 2009-12-28 17:05:43 +0100 | [diff] [blame] | 265 | talloc_free(msg); |
| 266 | return -EIO; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | sign_link = msg->trx->rsl_link; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 270 | e1i_ts = sign_link->ts; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 271 | if (!osmo_timer_pending(&e1i_ts->sign.tx_timer)) { |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 272 | /* notify the driver we have something to write */ |
| 273 | e1inp_driver = sign_link->ts->line->driver; |
| 274 | e1inp_driver->want_write(e1i_ts); |
| 275 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 276 | msgb_enqueue(&sign_link->tx_list, msg); |
| 277 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 278 | /* dump it */ |
| 279 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 280 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
Harald Welte | d88a387 | 2011-02-14 15:26:13 +0100 | [diff] [blame] | 284 | int _abis_nm_sendmsg(struct msgb *msg, int to_trx_oml) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 285 | { |
| 286 | struct e1inp_sign_link *sign_link; |
| 287 | struct e1inp_driver *e1inp_driver; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 288 | struct e1inp_ts *e1i_ts; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 289 | |
| 290 | msg->l2h = msg->data; |
| 291 | |
| 292 | if (!msg->trx || !msg->trx->bts || !msg->trx->bts->oml_link) { |
Harald Welte | f933de9 | 2011-02-05 20:18:18 +0100 | [diff] [blame] | 293 | LOGP(DNM, LOGL_ERROR, "nm_sendmsg: msg->trx == NULL\n"); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 294 | return -EINVAL; |
| 295 | } |
Holger Freyther | fb3f519 | 2009-02-09 23:09:15 +0000 | [diff] [blame] | 296 | |
Harald Welte | 15ccc77 | 2011-02-13 19:36:18 +0100 | [diff] [blame] | 297 | /* Check for TRX-specific OML link first */ |
Harald Welte | d88a387 | 2011-02-14 15:26:13 +0100 | [diff] [blame] | 298 | if (to_trx_oml) { |
| 299 | if (!msg->trx->oml_link) |
| 300 | return -ENODEV; |
Harald Welte | 15ccc77 | 2011-02-13 19:36:18 +0100 | [diff] [blame] | 301 | sign_link = msg->trx->oml_link; |
Harald Welte | d88a387 | 2011-02-14 15:26:13 +0100 | [diff] [blame] | 302 | } else |
Harald Welte | 15ccc77 | 2011-02-13 19:36:18 +0100 | [diff] [blame] | 303 | sign_link = msg->trx->bts->oml_link; |
| 304 | |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 305 | e1i_ts = sign_link->ts; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 306 | if (!osmo_timer_pending(&e1i_ts->sign.tx_timer)) { |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 307 | /* notify the driver we have something to write */ |
| 308 | e1inp_driver = sign_link->ts->line->driver; |
| 309 | e1inp_driver->want_write(e1i_ts); |
| 310 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 311 | msgb_enqueue(&sign_link->tx_list, msg); |
| 312 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 313 | /* dump it */ |
| 314 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 315 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /* Timeslot */ |
| 320 | |
| 321 | /* configure and initialize one e1inp_ts */ |
| 322 | int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line, |
| 323 | enum e1inp_ts_type type) |
| 324 | { |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 325 | if (ts->type == type && ts->line && line) |
| 326 | return 0; |
| 327 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 328 | ts->type = type; |
| 329 | ts->line = line; |
| 330 | |
| 331 | switch (type) { |
| 332 | case E1INP_TS_TYPE_SIGN: |
Holger Hans Peter Freyther | 91f587e | 2011-01-16 18:12:13 +0100 | [diff] [blame] | 333 | if (line && line->driver) |
Holger Hans Peter Freyther | d85642a | 2010-04-26 16:02:04 +0800 | [diff] [blame] | 334 | ts->sign.delay = line->driver->default_delay; |
| 335 | else |
| 336 | ts->sign.delay = 100000; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 337 | INIT_LLIST_HEAD(&ts->sign.sign_links); |
| 338 | break; |
| 339 | case E1INP_TS_TYPE_TRAU: |
| 340 | subchan_mux_init(&ts->trau.mux); |
| 341 | ts->trau.demux.out_cb = subch_cb; |
| 342 | ts->trau.demux.data = ts; |
| 343 | subch_demux_init(&ts->trau.demux); |
| 344 | break; |
| 345 | default: |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 346 | LOGP(DMI, LOGL_ERROR, "unsupported E1 timeslot type %u\n", |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 347 | ts->type); |
| 348 | return -EINVAL; |
| 349 | } |
| 350 | return 0; |
| 351 | } |
| 352 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 353 | struct e1inp_line *e1inp_line_get(uint8_t e1_nr) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 354 | { |
| 355 | struct e1inp_line *e1i_line; |
| 356 | |
| 357 | /* iterate over global list of e1 lines */ |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 358 | llist_for_each_entry(e1i_line, &e1inp_line_list, list) { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 359 | if (e1i_line->num == e1_nr) |
| 360 | return e1i_line; |
| 361 | } |
| 362 | return NULL; |
| 363 | } |
| 364 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 365 | struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name) |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 366 | { |
| 367 | struct e1inp_driver *driver; |
| 368 | struct e1inp_line *line; |
| 369 | int i; |
| 370 | |
| 371 | line = e1inp_line_get(e1_nr); |
Harald Welte | 07bb0da | 2011-02-05 15:57:42 +0100 | [diff] [blame] | 372 | if (line) { |
| 373 | LOGP(DINP, LOGL_ERROR, "E1 Line %u already exists\n", |
| 374 | e1_nr); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 375 | return NULL; |
Harald Welte | 07bb0da | 2011-02-05 15:57:42 +0100 | [diff] [blame] | 376 | } |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 377 | |
| 378 | driver = e1inp_driver_find(driver_name); |
Harald Welte | 07bb0da | 2011-02-05 15:57:42 +0100 | [diff] [blame] | 379 | if (!driver) { |
| 380 | LOGP(DINP, LOGL_ERROR, "No such E1 driver '%s'\n", |
| 381 | driver_name); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 382 | return NULL; |
Harald Welte | 07bb0da | 2011-02-05 15:57:42 +0100 | [diff] [blame] | 383 | } |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 384 | |
| 385 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
| 386 | if (!line) |
| 387 | return NULL; |
| 388 | |
| 389 | line->driver = driver; |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 390 | line->num = e1_nr; |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 391 | |
| 392 | line->rate_ctr = rate_ctr_group_alloc(line, &e1inp_ctr_g_d, line->num); |
| 393 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 394 | for (i = 0; i < NUM_E1_TS; i++) { |
| 395 | line->ts[i].num = i+1; |
| 396 | line->ts[i].line = line; |
| 397 | } |
| 398 | llist_add_tail(&line->list, &e1inp_line_list); |
| 399 | |
| 400 | return line; |
| 401 | } |
| 402 | |
| 403 | #if 0 |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 404 | struct e1inp_line *e1inp_line_get_create(uint8_t e1_nr) |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 405 | { |
| 406 | struct e1inp_line *line; |
| 407 | int i; |
| 408 | |
| 409 | line = e1inp_line_get(e1_nr); |
| 410 | if (line) |
| 411 | return line; |
| 412 | |
| 413 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
| 414 | if (!line) |
| 415 | return NULL; |
| 416 | |
| 417 | line->num = e1_nr; |
| 418 | for (i = 0; i < NUM_E1_TS; i++) { |
| 419 | line->ts[i].num = i+1; |
| 420 | line->ts[i].line = line; |
| 421 | } |
| 422 | llist_add_tail(&line->list, &e1inp_line_list); |
| 423 | |
| 424 | return line; |
| 425 | } |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 426 | #endif |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 427 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 428 | static struct e1inp_ts *e1inp_ts_get(uint8_t e1_nr, uint8_t ts_nr) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 429 | { |
| 430 | struct e1inp_line *e1i_line; |
| 431 | |
| 432 | e1i_line = e1inp_line_get(e1_nr); |
| 433 | if (!e1i_line) |
| 434 | return NULL; |
| 435 | |
| 436 | return &e1i_line->ts[ts_nr-1]; |
| 437 | } |
| 438 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 439 | struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 440 | { |
| 441 | struct e1inp_ts *e1i_ts = e1inp_ts_get(e1_nr, ts_nr); |
| 442 | |
| 443 | if (!e1i_ts) |
| 444 | return NULL; |
| 445 | |
| 446 | return &e1i_ts->trau.mux; |
| 447 | } |
| 448 | |
| 449 | /* Signalling Link */ |
| 450 | |
| 451 | struct e1inp_sign_link *e1inp_lookup_sign_link(struct e1inp_ts *e1i, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 452 | uint8_t tei, uint8_t sapi) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 453 | { |
| 454 | struct e1inp_sign_link *link; |
| 455 | |
| 456 | llist_for_each_entry(link, &e1i->sign.sign_links, list) { |
| 457 | if (link->sapi == sapi && link->tei == tei) |
| 458 | return link; |
| 459 | } |
| 460 | |
| 461 | return NULL; |
| 462 | } |
| 463 | |
| 464 | /* create a new signalling link in a E1 timeslot */ |
| 465 | |
| 466 | struct e1inp_sign_link * |
| 467 | e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 468 | struct gsm_bts_trx *trx, uint8_t tei, |
| 469 | uint8_t sapi) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 470 | { |
| 471 | struct e1inp_sign_link *link; |
| 472 | |
| 473 | if (ts->type != E1INP_TS_TYPE_SIGN) |
| 474 | return NULL; |
| 475 | |
Harald Welte | 470ec29 | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 476 | link = talloc_zero(tall_sigl_ctx, struct e1inp_sign_link); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 477 | if (!link) |
| 478 | return NULL; |
| 479 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 480 | link->ts = ts; |
| 481 | link->type = type; |
| 482 | INIT_LLIST_HEAD(&link->tx_list); |
| 483 | link->trx = trx; |
Holger Freyther | fb3f519 | 2009-02-09 23:09:15 +0000 | [diff] [blame] | 484 | link->tei = tei; |
| 485 | link->sapi = sapi; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 486 | |
| 487 | llist_add_tail(&link->list, &ts->sign.sign_links); |
| 488 | |
| 489 | return link; |
| 490 | } |
| 491 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 492 | void e1inp_sign_link_destroy(struct e1inp_sign_link *link) |
| 493 | { |
Holger Hans Peter Freyther | 4ac100e | 2010-04-11 14:13:10 +0200 | [diff] [blame] | 494 | struct msgb *msg; |
| 495 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 496 | llist_del(&link->list); |
Holger Hans Peter Freyther | 4ac100e | 2010-04-11 14:13:10 +0200 | [diff] [blame] | 497 | while (!llist_empty(&link->tx_list)) { |
| 498 | msg = msgb_dequeue(&link->tx_list); |
| 499 | msgb_free(msg); |
| 500 | } |
| 501 | |
Holger Hans Peter Freyther | f51b900 | 2010-04-11 17:18:02 +0200 | [diff] [blame] | 502 | if (link->ts->type == E1INP_TS_TYPE_SIGN) |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 503 | osmo_timer_del(&link->ts->sign.tx_timer); |
Holger Hans Peter Freyther | f51b900 | 2010-04-11 17:18:02 +0200 | [diff] [blame] | 504 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 505 | talloc_free(link); |
| 506 | } |
| 507 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 508 | /* the E1 driver tells us he has received something on a TS */ |
| 509 | int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 510 | uint8_t tei, uint8_t sapi) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 511 | { |
| 512 | struct e1inp_sign_link *link; |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 513 | struct gsm_bts *bts; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 514 | int ret; |
| 515 | |
| 516 | switch (ts->type) { |
| 517 | case E1INP_TS_TYPE_SIGN: |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 518 | /* consult the list of signalling links */ |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 519 | write_pcap_packet(PCAP_INPUT, sapi, tei, msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 520 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 521 | if (!link) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 522 | LOGP(DMI, LOGL_ERROR, "didn't find signalling link for " |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 523 | "tei %d, sapi %d\n", tei, sapi); |
| 524 | return -EINVAL; |
| 525 | } |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 526 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 527 | log_set_context(BSC_CTX_BTS, link->trx->bts); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 528 | switch (link->type) { |
| 529 | case E1INP_SIGN_OML: |
| 530 | msg->trx = link->trx; |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 531 | bts = msg->trx->bts; |
| 532 | ret = bts->model->oml_rcvmsg(msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 533 | break; |
| 534 | case E1INP_SIGN_RSL: |
| 535 | msg->trx = link->trx; |
| 536 | ret = abis_rsl_rcvmsg(msg); |
| 537 | break; |
| 538 | default: |
| 539 | ret = -EINVAL; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 540 | LOGP(DMI, LOGL_ERROR, "unknown link type %u\n", link->type); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 541 | break; |
| 542 | } |
| 543 | break; |
| 544 | case E1INP_TS_TYPE_TRAU: |
Harald Welte | 9e78331 | 2009-02-17 19:02:29 +0000 | [diff] [blame] | 545 | ret = subch_demux_in(&ts->trau.demux, msg->l2h, msgb_l2len(msg)); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 546 | break; |
| 547 | default: |
| 548 | ret = -EINVAL; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 549 | LOGP(DMI, LOGL_ERROR, "unknown TS type %u\n", ts->type); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 550 | break; |
| 551 | } |
| 552 | |
| 553 | return ret; |
| 554 | } |
| 555 | |
| 556 | #define TSX_ALLOC_SIZE 4096 |
| 557 | |
| 558 | /* called by driver if it wants to transmit on a given TS */ |
| 559 | struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts, |
| 560 | struct e1inp_sign_link **sign_link) |
| 561 | { |
| 562 | struct e1inp_sign_link *link; |
| 563 | struct msgb *msg = NULL; |
| 564 | int len; |
| 565 | |
| 566 | switch (e1i_ts->type) { |
| 567 | case E1INP_TS_TYPE_SIGN: |
| 568 | /* FIXME: implement this round robin */ |
| 569 | llist_for_each_entry(link, &e1i_ts->sign.sign_links, list) { |
| 570 | msg = msgb_dequeue(&link->tx_list); |
| 571 | if (msg) { |
| 572 | if (sign_link) |
| 573 | *sign_link = link; |
| 574 | break; |
| 575 | } |
| 576 | } |
| 577 | break; |
| 578 | case E1INP_TS_TYPE_TRAU: |
Harald Welte | 966636f | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 579 | msg = msgb_alloc(TSX_ALLOC_SIZE, "TRAU_TX"); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 580 | if (!msg) |
| 581 | return NULL; |
| 582 | len = subchan_mux_out(&e1i_ts->trau.mux, msg->data, 40); |
| 583 | msgb_put(msg, 40); |
| 584 | break; |
| 585 | default: |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 586 | LOGP(DMI, LOGL_ERROR, "unsupported E1 TS type %u\n", e1i_ts->type); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 587 | return NULL; |
| 588 | } |
| 589 | return msg; |
| 590 | } |
| 591 | |
| 592 | /* called by driver in case some kind of link state event */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 593 | int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 594 | { |
| 595 | struct e1inp_sign_link *link; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 596 | struct input_signal_data isd; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 597 | |
| 598 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 599 | if (!link) |
| 600 | return -EINVAL; |
| 601 | |
Pablo Neira Ayuso | cd98656 | 2011-08-09 23:15:38 +0200 | [diff] [blame] | 602 | isd.line = ts->line; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 603 | isd.link_type = link->type; |
| 604 | isd.trx = link->trx; |
Harald Welte | bd3137c | 2011-02-13 19:44:21 +0100 | [diff] [blame] | 605 | isd.tei = tei; |
| 606 | isd.sapi = sapi; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 607 | |
| 608 | /* report further upwards */ |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 609 | osmo_signal_dispatch(SS_INPUT, evt, &isd); |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 610 | return 0; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* register a driver with the E1 core */ |
| 614 | int e1inp_driver_register(struct e1inp_driver *drv) |
| 615 | { |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 616 | llist_add_tail(&drv->list, &e1inp_driver_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 617 | return 0; |
| 618 | } |
| 619 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 620 | struct e1inp_driver *e1inp_driver_find(const char *name) |
| 621 | { |
| 622 | struct e1inp_driver *drv; |
| 623 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 624 | llist_for_each_entry(drv, &e1inp_driver_list, list) { |
| 625 | if (!strcasecmp(name, drv->name)) |
| 626 | return drv; |
| 627 | } |
| 628 | return NULL; |
| 629 | } |
| 630 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 631 | int e1inp_line_update(struct e1inp_line *line) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 632 | { |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 633 | struct input_signal_data isd; |
| 634 | int rc; |
| 635 | |
Harald Welte | 5455243 | 2011-02-05 12:26:55 +0100 | [diff] [blame] | 636 | if (line->driver && line->driver->line_update) |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 637 | rc = line->driver->line_update(line); |
Harald Welte | 5455243 | 2011-02-05 12:26:55 +0100 | [diff] [blame] | 638 | else |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 639 | rc = 0; |
| 640 | |
| 641 | /* Send a signal to anyone who is interested in new lines being |
| 642 | * configured */ |
| 643 | memset(&isd, 0, sizeof(isd)); |
| 644 | isd.line = line; |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 645 | osmo_signal_dispatch(SS_INPUT, S_INP_LINE_INIT, &isd); |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 646 | |
| 647 | return rc; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 648 | } |
Harald Welte | 7bfc267 | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 649 | |
Harald Welte | 29b9cf8 | 2009-11-30 19:43:54 +0100 | [diff] [blame] | 650 | static int e1i_sig_cb(unsigned int subsys, unsigned int signal, |
| 651 | void *handler_data, void *signal_data) |
| 652 | { |
| 653 | if (subsys != SS_GLOBAL || |
| 654 | signal != S_GLOBAL_SHUTDOWN) |
| 655 | return 0; |
| 656 | |
| 657 | if (pcap_fd) { |
| 658 | close(pcap_fd); |
| 659 | pcap_fd = -1; |
| 660 | } |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 665 | void e1inp_misdn_init(void); |
Harald Welte | 1dd68c3 | 2011-02-05 13:58:46 +0100 | [diff] [blame] | 666 | void e1inp_dahdi_init(void); |
Pablo Neira Ayuso | c68f754 | 2011-05-14 11:32:47 +0200 | [diff] [blame] | 667 | void e1inp_ipaccess_init(void); |
| 668 | void e1inp_hsl_init(void); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 669 | |
| 670 | void e1inp_init(void) |
Harald Welte | 7bfc267 | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 671 | { |
| 672 | tall_sigl_ctx = talloc_named_const(tall_bsc_ctx, 1, |
| 673 | "e1inp_sign_link"); |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 674 | osmo_signal_register_handler(SS_GLOBAL, e1i_sig_cb, NULL); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 675 | |
| 676 | e1inp_misdn_init(); |
Harald Welte | ca17ef8 | 2011-02-05 15:13:27 +0100 | [diff] [blame] | 677 | #ifdef HAVE_DAHDI_USER_H |
Harald Welte | 1dd68c3 | 2011-02-05 13:58:46 +0100 | [diff] [blame] | 678 | e1inp_dahdi_init(); |
Harald Welte | ca17ef8 | 2011-02-05 15:13:27 +0100 | [diff] [blame] | 679 | #endif |
Pablo Neira Ayuso | c68f754 | 2011-05-14 11:32:47 +0200 | [diff] [blame] | 680 | e1inp_ipaccess_init(); |
| 681 | e1inp_hsl_init(); |
Harald Welte | 7bfc267 | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 682 | } |