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 | |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 249 | int abis_sendmsg(struct msgb *msg) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 250 | { |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 251 | struct e1inp_sign_link *sign_link = msg->dst; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 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 | |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 257 | /* don't know how to route this message. */ |
| 258 | if (sign_link == NULL) { |
| 259 | LOGP(DLINP, LOGL_ERROR, "abis_sendmsg: msg->dst == NULL: %s\n", |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 260 | osmo_hexdump(msg->data, msg->len)); |
Harald Welte | eab3335 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 261 | talloc_free(msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 262 | return -EINVAL; |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 263 | } |
| 264 | e1i_ts = sign_link->ts; |
| 265 | if (!osmo_timer_pending(&e1i_ts->sign.tx_timer)) { |
| 266 | /* notify the driver we have something to write */ |
| 267 | e1inp_driver = sign_link->ts->line->driver; |
| 268 | e1inp_driver->want_write(e1i_ts); |
| 269 | } |
| 270 | msgb_enqueue(&sign_link->tx_list, msg); |
| 271 | |
| 272 | /* dump it */ |
| 273 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | int abis_rsl_sendmsg(struct msgb *msg) |
| 279 | { |
| 280 | struct e1inp_sign_link *sign_link = (struct e1inp_sign_link *)msg->dst; |
| 281 | struct e1inp_driver *e1inp_driver; |
| 282 | struct e1inp_ts *e1i_ts; |
| 283 | |
| 284 | msg->l2h = msg->data; |
| 285 | |
| 286 | if (!sign_link) { |
| 287 | LOGP(DRSL, LOGL_ERROR, "rsl_sendmsg: msg->dst == NULL: %s\n", |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 288 | osmo_hexdump(msg->data, msg->len)); |
Harald Welte (local) | 5fe3318 | 2009-12-28 17:05:43 +0100 | [diff] [blame] | 289 | talloc_free(msg); |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 290 | return -EINVAL; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 291 | } |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 292 | e1i_ts = sign_link->ts; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 293 | if (!osmo_timer_pending(&e1i_ts->sign.tx_timer)) { |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 294 | /* notify the driver we have something to write */ |
| 295 | e1inp_driver = sign_link->ts->line->driver; |
| 296 | e1inp_driver->want_write(e1i_ts); |
| 297 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 298 | msgb_enqueue(&sign_link->tx_list, msg); |
| 299 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 300 | /* dump it */ |
| 301 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 302 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
Harald Welte | d88a387 | 2011-02-14 15:26:13 +0100 | [diff] [blame] | 306 | int _abis_nm_sendmsg(struct msgb *msg, int to_trx_oml) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 307 | { |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 308 | struct e1inp_sign_link *sign_link = msg->dst; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 309 | |
| 310 | msg->l2h = msg->data; |
| 311 | |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 312 | if (!msg->dst) { |
| 313 | LOGP(DNM, LOGL_ERROR, "_abis_nm_sendmsg: msg->dst == NULL\n"); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 314 | return -EINVAL; |
| 315 | } |
Holger Freyther | fb3f519 | 2009-02-09 23:09:15 +0000 | [diff] [blame] | 316 | |
Harald Welte | 15ccc77 | 2011-02-13 19:36:18 +0100 | [diff] [blame] | 317 | /* Check for TRX-specific OML link first */ |
Harald Welte | d88a387 | 2011-02-14 15:26:13 +0100 | [diff] [blame] | 318 | if (to_trx_oml) { |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 319 | if (!sign_link->trx->oml_link) |
Harald Welte | d88a387 | 2011-02-14 15:26:13 +0100 | [diff] [blame] | 320 | return -ENODEV; |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 321 | msg->dst = sign_link->trx->oml_link; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 322 | } |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 323 | return abis_sendmsg(msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* Timeslot */ |
| 327 | |
| 328 | /* configure and initialize one e1inp_ts */ |
| 329 | int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line, |
| 330 | enum e1inp_ts_type type) |
| 331 | { |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 332 | if (ts->type == type && ts->line && line) |
| 333 | return 0; |
| 334 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 335 | ts->type = type; |
| 336 | ts->line = line; |
| 337 | |
| 338 | switch (type) { |
| 339 | case E1INP_TS_TYPE_SIGN: |
Holger Hans Peter Freyther | 91f587e | 2011-01-16 18:12:13 +0100 | [diff] [blame] | 340 | if (line && line->driver) |
Holger Hans Peter Freyther | d85642a | 2010-04-26 16:02:04 +0800 | [diff] [blame] | 341 | ts->sign.delay = line->driver->default_delay; |
| 342 | else |
| 343 | ts->sign.delay = 100000; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 344 | INIT_LLIST_HEAD(&ts->sign.sign_links); |
| 345 | break; |
| 346 | case E1INP_TS_TYPE_TRAU: |
| 347 | subchan_mux_init(&ts->trau.mux); |
| 348 | ts->trau.demux.out_cb = subch_cb; |
| 349 | ts->trau.demux.data = ts; |
| 350 | subch_demux_init(&ts->trau.demux); |
| 351 | break; |
| 352 | default: |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 353 | LOGP(DMI, LOGL_ERROR, "unsupported E1 timeslot type %u\n", |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 354 | ts->type); |
| 355 | return -EINVAL; |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 360 | struct e1inp_line *e1inp_line_get(uint8_t e1_nr) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 361 | { |
| 362 | struct e1inp_line *e1i_line; |
| 363 | |
| 364 | /* iterate over global list of e1 lines */ |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 365 | llist_for_each_entry(e1i_line, &e1inp_line_list, list) { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 366 | if (e1i_line->num == e1_nr) |
| 367 | return e1i_line; |
| 368 | } |
| 369 | return NULL; |
| 370 | } |
| 371 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 372 | 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] | 373 | { |
| 374 | struct e1inp_driver *driver; |
| 375 | struct e1inp_line *line; |
| 376 | int i; |
| 377 | |
| 378 | line = e1inp_line_get(e1_nr); |
Harald Welte | 07bb0da | 2011-02-05 15:57:42 +0100 | [diff] [blame] | 379 | if (line) { |
| 380 | LOGP(DINP, LOGL_ERROR, "E1 Line %u already exists\n", |
| 381 | e1_nr); |
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 | driver = e1inp_driver_find(driver_name); |
Harald Welte | 07bb0da | 2011-02-05 15:57:42 +0100 | [diff] [blame] | 386 | if (!driver) { |
| 387 | LOGP(DINP, LOGL_ERROR, "No such E1 driver '%s'\n", |
| 388 | driver_name); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 389 | return NULL; |
Harald Welte | 07bb0da | 2011-02-05 15:57:42 +0100 | [diff] [blame] | 390 | } |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 391 | |
| 392 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
| 393 | if (!line) |
| 394 | return NULL; |
| 395 | |
| 396 | line->driver = driver; |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 397 | line->num = e1_nr; |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame] | 398 | |
| 399 | line->rate_ctr = rate_ctr_group_alloc(line, &e1inp_ctr_g_d, line->num); |
| 400 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 401 | for (i = 0; i < NUM_E1_TS; i++) { |
| 402 | line->ts[i].num = i+1; |
| 403 | line->ts[i].line = line; |
| 404 | } |
| 405 | llist_add_tail(&line->list, &e1inp_line_list); |
| 406 | |
| 407 | return line; |
| 408 | } |
| 409 | |
| 410 | #if 0 |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 411 | struct e1inp_line *e1inp_line_get_create(uint8_t e1_nr) |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 412 | { |
| 413 | struct e1inp_line *line; |
| 414 | int i; |
| 415 | |
| 416 | line = e1inp_line_get(e1_nr); |
| 417 | if (line) |
| 418 | return line; |
| 419 | |
| 420 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
| 421 | if (!line) |
| 422 | return NULL; |
| 423 | |
| 424 | line->num = e1_nr; |
| 425 | for (i = 0; i < NUM_E1_TS; i++) { |
| 426 | line->ts[i].num = i+1; |
| 427 | line->ts[i].line = line; |
| 428 | } |
| 429 | llist_add_tail(&line->list, &e1inp_line_list); |
| 430 | |
| 431 | return line; |
| 432 | } |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 433 | #endif |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 434 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 435 | 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] | 436 | { |
| 437 | struct e1inp_line *e1i_line; |
| 438 | |
| 439 | e1i_line = e1inp_line_get(e1_nr); |
| 440 | if (!e1i_line) |
| 441 | return NULL; |
| 442 | |
| 443 | return &e1i_line->ts[ts_nr-1]; |
| 444 | } |
| 445 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 446 | 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] | 447 | { |
| 448 | struct e1inp_ts *e1i_ts = e1inp_ts_get(e1_nr, ts_nr); |
| 449 | |
| 450 | if (!e1i_ts) |
| 451 | return NULL; |
| 452 | |
| 453 | return &e1i_ts->trau.mux; |
| 454 | } |
| 455 | |
| 456 | /* Signalling Link */ |
| 457 | |
| 458 | 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] | 459 | uint8_t tei, uint8_t sapi) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 460 | { |
| 461 | struct e1inp_sign_link *link; |
| 462 | |
| 463 | llist_for_each_entry(link, &e1i->sign.sign_links, list) { |
| 464 | if (link->sapi == sapi && link->tei == tei) |
| 465 | return link; |
| 466 | } |
| 467 | |
| 468 | return NULL; |
| 469 | } |
| 470 | |
| 471 | /* create a new signalling link in a E1 timeslot */ |
| 472 | |
| 473 | struct e1inp_sign_link * |
| 474 | 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] | 475 | struct gsm_bts_trx *trx, uint8_t tei, |
| 476 | uint8_t sapi) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 477 | { |
| 478 | struct e1inp_sign_link *link; |
| 479 | |
| 480 | if (ts->type != E1INP_TS_TYPE_SIGN) |
| 481 | return NULL; |
| 482 | |
Harald Welte | 470ec29 | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 483 | link = talloc_zero(tall_sigl_ctx, struct e1inp_sign_link); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 484 | if (!link) |
| 485 | return NULL; |
| 486 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 487 | link->ts = ts; |
| 488 | link->type = type; |
| 489 | INIT_LLIST_HEAD(&link->tx_list); |
| 490 | link->trx = trx; |
Holger Freyther | fb3f519 | 2009-02-09 23:09:15 +0000 | [diff] [blame] | 491 | link->tei = tei; |
| 492 | link->sapi = sapi; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 493 | |
| 494 | llist_add_tail(&link->list, &ts->sign.sign_links); |
| 495 | |
| 496 | return link; |
| 497 | } |
| 498 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 499 | void e1inp_sign_link_destroy(struct e1inp_sign_link *link) |
| 500 | { |
Holger Hans Peter Freyther | 4ac100e | 2010-04-11 14:13:10 +0200 | [diff] [blame] | 501 | struct msgb *msg; |
| 502 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 503 | llist_del(&link->list); |
Holger Hans Peter Freyther | 4ac100e | 2010-04-11 14:13:10 +0200 | [diff] [blame] | 504 | while (!llist_empty(&link->tx_list)) { |
| 505 | msg = msgb_dequeue(&link->tx_list); |
| 506 | msgb_free(msg); |
| 507 | } |
| 508 | |
Holger Hans Peter Freyther | f51b900 | 2010-04-11 17:18:02 +0200 | [diff] [blame] | 509 | if (link->ts->type == E1INP_TS_TYPE_SIGN) |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 510 | osmo_timer_del(&link->ts->sign.tx_timer); |
Holger Hans Peter Freyther | f51b900 | 2010-04-11 17:18:02 +0200 | [diff] [blame] | 511 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 512 | talloc_free(link); |
| 513 | } |
| 514 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 515 | /* the E1 driver tells us he has received something on a TS */ |
| 516 | 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] | 517 | uint8_t tei, uint8_t sapi) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 518 | { |
| 519 | struct e1inp_sign_link *link; |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 520 | struct gsm_bts *bts; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 521 | int ret; |
| 522 | |
| 523 | switch (ts->type) { |
| 524 | case E1INP_TS_TYPE_SIGN: |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 525 | /* consult the list of signalling links */ |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 526 | write_pcap_packet(PCAP_INPUT, sapi, tei, msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 527 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 528 | if (!link) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 529 | LOGP(DMI, LOGL_ERROR, "didn't find signalling link for " |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 530 | "tei %d, sapi %d\n", tei, sapi); |
| 531 | return -EINVAL; |
| 532 | } |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 533 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 534 | log_set_context(BSC_CTX_BTS, link->trx->bts); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 535 | switch (link->type) { |
| 536 | case E1INP_SIGN_OML: |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 537 | msg->dst = link; |
| 538 | bts = link->trx->bts; |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 539 | ret = bts->model->oml_rcvmsg(msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 540 | break; |
| 541 | case E1INP_SIGN_RSL: |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame^] | 542 | msg->dst = link; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 543 | ret = abis_rsl_rcvmsg(msg); |
| 544 | break; |
| 545 | default: |
| 546 | ret = -EINVAL; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 547 | LOGP(DMI, LOGL_ERROR, "unknown link type %u\n", link->type); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 548 | break; |
| 549 | } |
| 550 | break; |
| 551 | case E1INP_TS_TYPE_TRAU: |
Harald Welte | 9e78331 | 2009-02-17 19:02:29 +0000 | [diff] [blame] | 552 | ret = subch_demux_in(&ts->trau.demux, msg->l2h, msgb_l2len(msg)); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 553 | break; |
| 554 | default: |
| 555 | ret = -EINVAL; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 556 | LOGP(DMI, LOGL_ERROR, "unknown TS type %u\n", ts->type); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 557 | break; |
| 558 | } |
| 559 | |
| 560 | return ret; |
| 561 | } |
| 562 | |
| 563 | #define TSX_ALLOC_SIZE 4096 |
| 564 | |
| 565 | /* called by driver if it wants to transmit on a given TS */ |
| 566 | struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts, |
| 567 | struct e1inp_sign_link **sign_link) |
| 568 | { |
| 569 | struct e1inp_sign_link *link; |
| 570 | struct msgb *msg = NULL; |
| 571 | int len; |
| 572 | |
| 573 | switch (e1i_ts->type) { |
| 574 | case E1INP_TS_TYPE_SIGN: |
| 575 | /* FIXME: implement this round robin */ |
| 576 | llist_for_each_entry(link, &e1i_ts->sign.sign_links, list) { |
| 577 | msg = msgb_dequeue(&link->tx_list); |
| 578 | if (msg) { |
| 579 | if (sign_link) |
| 580 | *sign_link = link; |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | break; |
| 585 | case E1INP_TS_TYPE_TRAU: |
Harald Welte | 966636f | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 586 | msg = msgb_alloc(TSX_ALLOC_SIZE, "TRAU_TX"); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 587 | if (!msg) |
| 588 | return NULL; |
| 589 | len = subchan_mux_out(&e1i_ts->trau.mux, msg->data, 40); |
| 590 | msgb_put(msg, 40); |
| 591 | break; |
| 592 | default: |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 593 | 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] | 594 | return NULL; |
| 595 | } |
| 596 | return msg; |
| 597 | } |
| 598 | |
| 599 | /* 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] | 600 | 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] | 601 | { |
| 602 | struct e1inp_sign_link *link; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 603 | struct input_signal_data isd; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 604 | |
| 605 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 606 | if (!link) |
| 607 | return -EINVAL; |
| 608 | |
Pablo Neira Ayuso | cd98656 | 2011-08-09 23:15:38 +0200 | [diff] [blame] | 609 | isd.line = ts->line; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 610 | isd.link_type = link->type; |
| 611 | isd.trx = link->trx; |
Harald Welte | bd3137c | 2011-02-13 19:44:21 +0100 | [diff] [blame] | 612 | isd.tei = tei; |
| 613 | isd.sapi = sapi; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 614 | |
| 615 | /* report further upwards */ |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 616 | osmo_signal_dispatch(SS_INPUT, evt, &isd); |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 617 | return 0; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | /* register a driver with the E1 core */ |
| 621 | int e1inp_driver_register(struct e1inp_driver *drv) |
| 622 | { |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 623 | llist_add_tail(&drv->list, &e1inp_driver_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 624 | return 0; |
| 625 | } |
| 626 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 627 | struct e1inp_driver *e1inp_driver_find(const char *name) |
| 628 | { |
| 629 | struct e1inp_driver *drv; |
| 630 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 631 | llist_for_each_entry(drv, &e1inp_driver_list, list) { |
| 632 | if (!strcasecmp(name, drv->name)) |
| 633 | return drv; |
| 634 | } |
| 635 | return NULL; |
| 636 | } |
| 637 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 638 | int e1inp_line_update(struct e1inp_line *line) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 639 | { |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 640 | struct input_signal_data isd; |
| 641 | int rc; |
| 642 | |
Harald Welte | 5455243 | 2011-02-05 12:26:55 +0100 | [diff] [blame] | 643 | if (line->driver && line->driver->line_update) |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 644 | rc = line->driver->line_update(line); |
Harald Welte | 5455243 | 2011-02-05 12:26:55 +0100 | [diff] [blame] | 645 | else |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 646 | rc = 0; |
| 647 | |
| 648 | /* Send a signal to anyone who is interested in new lines being |
| 649 | * configured */ |
| 650 | memset(&isd, 0, sizeof(isd)); |
| 651 | isd.line = line; |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 652 | osmo_signal_dispatch(SS_INPUT, S_INP_LINE_INIT, &isd); |
Harald Welte | f27d043 | 2011-02-11 16:49:41 +0100 | [diff] [blame] | 653 | |
| 654 | return rc; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 655 | } |
Harald Welte | 7bfc267 | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 656 | |
Harald Welte | 29b9cf8 | 2009-11-30 19:43:54 +0100 | [diff] [blame] | 657 | static int e1i_sig_cb(unsigned int subsys, unsigned int signal, |
| 658 | void *handler_data, void *signal_data) |
| 659 | { |
| 660 | if (subsys != SS_GLOBAL || |
| 661 | signal != S_GLOBAL_SHUTDOWN) |
| 662 | return 0; |
| 663 | |
| 664 | if (pcap_fd) { |
| 665 | close(pcap_fd); |
| 666 | pcap_fd = -1; |
| 667 | } |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 672 | void e1inp_misdn_init(void); |
Harald Welte | 1dd68c3 | 2011-02-05 13:58:46 +0100 | [diff] [blame] | 673 | void e1inp_dahdi_init(void); |
Pablo Neira Ayuso | c68f754 | 2011-05-14 11:32:47 +0200 | [diff] [blame] | 674 | void e1inp_ipaccess_init(void); |
| 675 | void e1inp_hsl_init(void); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 676 | |
| 677 | void e1inp_init(void) |
Harald Welte | 7bfc267 | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 678 | { |
| 679 | tall_sigl_ctx = talloc_named_const(tall_bsc_ctx, 1, |
| 680 | "e1inp_sign_link"); |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 681 | osmo_signal_register_handler(SS_GLOBAL, e1i_sig_cb, NULL); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 682 | |
| 683 | e1inp_misdn_init(); |
Harald Welte | ca17ef8 | 2011-02-05 15:13:27 +0100 | [diff] [blame] | 684 | #ifdef HAVE_DAHDI_USER_H |
Harald Welte | 1dd68c3 | 2011-02-05 13:58:46 +0100 | [diff] [blame] | 685 | e1inp_dahdi_init(); |
Harald Welte | ca17ef8 | 2011-02-05 15:13:27 +0100 | [diff] [blame] | 686 | #endif |
Pablo Neira Ayuso | c68f754 | 2011-05-14 11:32:47 +0200 | [diff] [blame] | 687 | e1inp_ipaccess_init(); |
| 688 | e1inp_hsl_init(); |
Harald Welte | 7bfc267 | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 689 | } |