Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [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 |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <unistd.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <errno.h> |
| 27 | #include <string.h> |
| 28 | #include <time.h> |
| 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/socket.h> |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <arpa/inet.h> |
| 34 | #include <mISDNif.h> |
| 35 | |
| 36 | //#define AF_COMPATIBILITY_FUNC |
| 37 | //#include <compat_af_isdn.h> |
| 38 | #ifndef AF_ISDN |
| 39 | #define AF_ISDN 34 |
| 40 | #define PF_ISDN AF_ISDN |
| 41 | #endif |
| 42 | |
| 43 | #include <openbsc/select.h> |
| 44 | #include <openbsc/msgb.h> |
| 45 | #include <openbsc/debug.h> |
| 46 | #include <openbsc/gsm_data.h> |
| 47 | #include <openbsc/e1_input.h> |
| 48 | #include <openbsc/abis_nm.h> |
| 49 | #include <openbsc/abis_rsl.h> |
| 50 | #include <openbsc/linuxlist.h> |
| 51 | #include <openbsc/subchan_demux.h> |
| 52 | #include <openbsc/trau_frame.h> |
| 53 | #include <openbsc/trau_mux.h> |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 54 | #include <openbsc/talloc.h> |
Harald Welte | 4d42bd8 | 2009-11-30 19:43:54 +0100 | [diff] [blame] | 55 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 735cd9e | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 56 | #include <openbsc/misdn.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 57 | |
| 58 | #define NUM_E1_TS 32 |
| 59 | |
| 60 | /* list of all E1 drivers */ |
| 61 | LLIST_HEAD(e1inp_driver_list); |
| 62 | |
| 63 | /* list of all E1 lines */ |
| 64 | LLIST_HEAD(e1inp_line_list); |
| 65 | |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 66 | static void *tall_sigl_ctx; |
| 67 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 68 | /* to be implemented, e.g. by bsc_hack.c */ |
| 69 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx); |
| 70 | |
| 71 | /* |
| 72 | * pcap writing of the misdn load |
| 73 | * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat |
| 74 | */ |
| 75 | #define DLT_LINUX_LAPD 177 |
| 76 | #define PCAP_INPUT 0 |
| 77 | #define PCAP_OUTPUT 1 |
| 78 | |
| 79 | struct pcap_hdr { |
| 80 | u_int32_t magic_number; |
| 81 | u_int16_t version_major; |
| 82 | u_int16_t version_minor; |
| 83 | int32_t thiszone; |
| 84 | u_int32_t sigfigs; |
| 85 | u_int32_t snaplen; |
| 86 | u_int32_t network; |
| 87 | } __attribute__((packed)); |
| 88 | |
| 89 | struct pcaprec_hdr { |
| 90 | u_int32_t ts_sec; |
| 91 | u_int32_t ts_usec; |
| 92 | u_int32_t incl_len; |
| 93 | u_int32_t orig_len; |
| 94 | } __attribute__((packed)); |
| 95 | |
| 96 | struct fake_linux_lapd_header { |
| 97 | u_int16_t pkttype; |
| 98 | u_int16_t hatype; |
| 99 | u_int16_t halen; |
| 100 | u_int64_t addr; |
| 101 | int16_t protocol; |
| 102 | } __attribute__((packed)); |
| 103 | |
| 104 | struct lapd_header { |
| 105 | u_int8_t ea1 : 1; |
| 106 | u_int8_t cr : 1; |
| 107 | u_int8_t sapi : 6; |
| 108 | u_int8_t ea2 : 1; |
| 109 | u_int8_t tei : 7; |
| 110 | u_int8_t control_foo; /* fake UM's ... */ |
| 111 | } __attribute__((packed)); |
| 112 | |
| 113 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->hatype == 2, hatype_offset); |
| 114 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->halen == 4, halen_offset); |
| 115 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->addr == 6, addr_offset); |
| 116 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->protocol == 14, proto_offset); |
| 117 | static_assert(sizeof(struct fake_linux_lapd_header) == 16, lapd_header_size); |
| 118 | |
| 119 | |
| 120 | static int pcap_fd = -1; |
| 121 | |
| 122 | void e1_set_pcap_fd(int fd) |
| 123 | { |
| 124 | int ret; |
| 125 | struct pcap_hdr header = { |
| 126 | .magic_number = 0xa1b2c3d4, |
| 127 | .version_major = 2, |
| 128 | .version_minor = 4, |
| 129 | .thiszone = 0, |
| 130 | .sigfigs = 0, |
| 131 | .snaplen = 65535, |
| 132 | .network = DLT_LINUX_LAPD, |
| 133 | }; |
| 134 | |
| 135 | pcap_fd = fd; |
| 136 | ret = write(pcap_fd, &header, sizeof(header)); |
| 137 | } |
| 138 | |
| 139 | /* This currently only works for the D-Channel */ |
| 140 | static void write_pcap_packet(int direction, int sapi, int tei, |
| 141 | struct msgb *msg) { |
| 142 | if (pcap_fd < 0) |
| 143 | return; |
| 144 | |
| 145 | int ret; |
| 146 | time_t cur_time; |
| 147 | struct tm *tm; |
Andreas Eversberg | b5a3e41 | 2009-06-10 14:47:33 +0200 | [diff] [blame] | 148 | int mi_head = (direction==PCAP_INPUT) ? MISDN_HEADER_LEN : 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 149 | |
| 150 | struct fake_linux_lapd_header header = { |
| 151 | .pkttype = 4, |
| 152 | .hatype = 0, |
| 153 | .halen = 0, |
| 154 | .addr = direction == PCAP_OUTPUT ? 0x0 : 0x1, |
| 155 | .protocol = ntohs(48), |
| 156 | }; |
| 157 | |
| 158 | struct lapd_header lapd_header = { |
| 159 | .ea1 = 0, |
| 160 | .cr = direction == PCAP_OUTPUT ? 1 : 0, |
| 161 | .sapi = sapi & 0x3F, |
| 162 | .ea2 = 1, |
| 163 | .tei = tei & 0x7F, |
| 164 | .control_foo = 0x03 /* UI */, |
| 165 | }; |
| 166 | |
| 167 | struct pcaprec_hdr payload_header = { |
| 168 | .ts_sec = 0, |
| 169 | .ts_usec = 0, |
| 170 | .incl_len = msg->len + sizeof(struct fake_linux_lapd_header) |
| 171 | + sizeof(struct lapd_header) |
Andreas Eversberg | b5a3e41 | 2009-06-10 14:47:33 +0200 | [diff] [blame] | 172 | - mi_head, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 173 | .orig_len = msg->len + sizeof(struct fake_linux_lapd_header) |
| 174 | + sizeof(struct lapd_header) |
Andreas Eversberg | b5a3e41 | 2009-06-10 14:47:33 +0200 | [diff] [blame] | 175 | - mi_head, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | |
| 179 | cur_time = time(NULL); |
| 180 | tm = localtime(&cur_time); |
| 181 | payload_header.ts_sec = mktime(tm); |
| 182 | |
| 183 | ret = write(pcap_fd, &payload_header, sizeof(payload_header)); |
| 184 | ret = write(pcap_fd, &header, sizeof(header)); |
| 185 | ret = write(pcap_fd, &lapd_header, sizeof(lapd_header)); |
Andreas Eversberg | b5a3e41 | 2009-06-10 14:47:33 +0200 | [diff] [blame] | 186 | ret = write(pcap_fd, msg->data + mi_head, |
| 187 | msg->len - mi_head); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static const char *sign_types[] = { |
| 191 | [E1INP_SIGN_NONE] = "None", |
| 192 | [E1INP_SIGN_OML] = "OML", |
| 193 | [E1INP_SIGN_RSL] = "RSL", |
| 194 | }; |
| 195 | const char *e1inp_signtype_name(enum e1inp_sign_type tp) |
| 196 | { |
| 197 | if (tp >= ARRAY_SIZE(sign_types)) |
| 198 | return "undefined"; |
| 199 | return sign_types[tp]; |
| 200 | } |
| 201 | |
| 202 | static const char *ts_types[] = { |
| 203 | [E1INP_TS_TYPE_NONE] = "None", |
| 204 | [E1INP_TS_TYPE_SIGN] = "Signalling", |
| 205 | [E1INP_TS_TYPE_TRAU] = "TRAU", |
| 206 | }; |
| 207 | |
| 208 | const char *e1inp_tstype_name(enum e1inp_ts_type tp) |
| 209 | { |
| 210 | if (tp >= ARRAY_SIZE(ts_types)) |
| 211 | return "undefined"; |
| 212 | return ts_types[tp]; |
| 213 | } |
| 214 | |
| 215 | /* callback when a TRAU frame was received */ |
| 216 | static int subch_cb(struct subch_demux *dmx, int ch, u_int8_t *data, int len, |
| 217 | void *_priv) |
| 218 | { |
| 219 | struct e1inp_ts *e1i_ts = _priv; |
| 220 | struct gsm_e1_subslot src_ss; |
| 221 | |
| 222 | src_ss.e1_nr = e1i_ts->line->num; |
| 223 | src_ss.e1_ts = e1i_ts->num; |
| 224 | src_ss.e1_ts_ss = ch; |
| 225 | |
| 226 | return trau_mux_input(&src_ss, data, len); |
| 227 | } |
| 228 | |
| 229 | int abis_rsl_sendmsg(struct msgb *msg) |
| 230 | { |
| 231 | struct e1inp_sign_link *sign_link; |
| 232 | struct e1inp_driver *e1inp_driver; |
| 233 | struct e1inp_ts *e1i_ts; |
| 234 | |
| 235 | msg->l2h = msg->data; |
| 236 | |
Harald Welte (local) | 42351bf | 2009-12-28 17:05:43 +0100 | [diff] [blame] | 237 | if (!msg->trx) { |
| 238 | LOGP(DRSL, LOGL_ERROR, "rsl_sendmsg: msg->trx == NULL: %s\n", |
| 239 | hexdump(msg->data, msg->len)); |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 240 | talloc_free(msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 241 | return -EINVAL; |
Harald Welte (local) | 42351bf | 2009-12-28 17:05:43 +0100 | [diff] [blame] | 242 | } else if (!msg->trx->rsl_link) { |
| 243 | LOGP(DRSL, LOGL_ERROR, "rsl_sendmsg: msg->trx->rsl_link == NULL: %s\n", |
| 244 | hexdump(msg->data, msg->len)); |
| 245 | talloc_free(msg); |
| 246 | return -EIO; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | sign_link = msg->trx->rsl_link; |
| 250 | e1i_ts = sign_link->ts; |
| 251 | if (!bsc_timer_pending(&e1i_ts->sign.tx_timer)) { |
| 252 | /* notify the driver we have something to write */ |
| 253 | e1inp_driver = sign_link->ts->line->driver; |
| 254 | e1inp_driver->want_write(e1i_ts); |
| 255 | } |
| 256 | msgb_enqueue(&sign_link->tx_list, msg); |
| 257 | |
| 258 | /* dump it */ |
| 259 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int _abis_nm_sendmsg(struct msgb *msg) |
| 265 | { |
| 266 | struct e1inp_sign_link *sign_link; |
| 267 | struct e1inp_driver *e1inp_driver; |
| 268 | struct e1inp_ts *e1i_ts; |
| 269 | |
| 270 | msg->l2h = msg->data; |
| 271 | |
| 272 | if (!msg->trx || !msg->trx->bts || !msg->trx->bts->oml_link) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 273 | LOGP(DRSL, LOGL_ERROR, "nm_sendmsg: msg->trx == NULL\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 274 | return -EINVAL; |
| 275 | } |
| 276 | |
| 277 | sign_link = msg->trx->bts->oml_link; |
| 278 | e1i_ts = sign_link->ts; |
| 279 | if (!bsc_timer_pending(&e1i_ts->sign.tx_timer)) { |
| 280 | /* notify the driver we have something to write */ |
| 281 | e1inp_driver = sign_link->ts->line->driver; |
| 282 | e1inp_driver->want_write(e1i_ts); |
| 283 | } |
| 284 | msgb_enqueue(&sign_link->tx_list, msg); |
| 285 | |
| 286 | /* dump it */ |
| 287 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /* Timeslot */ |
| 293 | |
| 294 | /* configure and initialize one e1inp_ts */ |
| 295 | int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line, |
| 296 | enum e1inp_ts_type type) |
| 297 | { |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 298 | if (ts->type == type && ts->line && line) |
| 299 | return 0; |
| 300 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 301 | ts->type = type; |
| 302 | ts->line = line; |
| 303 | |
| 304 | switch (type) { |
| 305 | case E1INP_TS_TYPE_SIGN: |
| 306 | INIT_LLIST_HEAD(&ts->sign.sign_links); |
| 307 | break; |
| 308 | case E1INP_TS_TYPE_TRAU: |
| 309 | subchan_mux_init(&ts->trau.mux); |
| 310 | ts->trau.demux.out_cb = subch_cb; |
| 311 | ts->trau.demux.data = ts; |
| 312 | subch_demux_init(&ts->trau.demux); |
| 313 | break; |
| 314 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 315 | LOGP(DMI, LOGL_ERROR, "unsupported E1 timeslot type %u\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 316 | ts->type); |
| 317 | return -EINVAL; |
| 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static struct e1inp_line *e1inp_line_get(u_int8_t e1_nr) |
| 323 | { |
| 324 | struct e1inp_line *e1i_line; |
| 325 | |
| 326 | /* iterate over global list of e1 lines */ |
| 327 | llist_for_each_entry(e1i_line, &e1inp_line_list, list) { |
| 328 | if (e1i_line->num == e1_nr) |
| 329 | return e1i_line; |
| 330 | } |
| 331 | return NULL; |
| 332 | } |
| 333 | |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 334 | struct e1inp_line *e1inp_line_get_create(u_int8_t e1_nr) |
| 335 | { |
| 336 | struct e1inp_line *line; |
| 337 | int i; |
| 338 | |
| 339 | line = e1inp_line_get(e1_nr); |
| 340 | if (line) |
| 341 | return line; |
| 342 | |
| 343 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
| 344 | if (!line) |
| 345 | return NULL; |
| 346 | |
| 347 | line->num = e1_nr; |
| 348 | for (i = 0; i < NUM_E1_TS; i++) { |
| 349 | line->ts[i].num = i+1; |
| 350 | line->ts[i].line = line; |
| 351 | } |
| 352 | llist_add_tail(&line->list, &e1inp_line_list); |
| 353 | |
| 354 | return line; |
| 355 | } |
| 356 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 357 | static struct e1inp_ts *e1inp_ts_get(u_int8_t e1_nr, u_int8_t ts_nr) |
| 358 | { |
| 359 | struct e1inp_line *e1i_line; |
| 360 | |
| 361 | e1i_line = e1inp_line_get(e1_nr); |
| 362 | if (!e1i_line) |
| 363 | return NULL; |
| 364 | |
| 365 | return &e1i_line->ts[ts_nr-1]; |
| 366 | } |
| 367 | |
| 368 | struct subch_mux *e1inp_get_mux(u_int8_t e1_nr, u_int8_t ts_nr) |
| 369 | { |
| 370 | struct e1inp_ts *e1i_ts = e1inp_ts_get(e1_nr, ts_nr); |
| 371 | |
| 372 | if (!e1i_ts) |
| 373 | return NULL; |
| 374 | |
| 375 | return &e1i_ts->trau.mux; |
| 376 | } |
| 377 | |
| 378 | /* Signalling Link */ |
| 379 | |
| 380 | struct e1inp_sign_link *e1inp_lookup_sign_link(struct e1inp_ts *e1i, |
| 381 | u_int8_t tei, u_int8_t sapi) |
| 382 | { |
| 383 | struct e1inp_sign_link *link; |
| 384 | |
| 385 | llist_for_each_entry(link, &e1i->sign.sign_links, list) { |
| 386 | if (link->sapi == sapi && link->tei == tei) |
| 387 | return link; |
| 388 | } |
| 389 | |
| 390 | return NULL; |
| 391 | } |
| 392 | |
| 393 | /* create a new signalling link in a E1 timeslot */ |
| 394 | |
| 395 | struct e1inp_sign_link * |
| 396 | e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type, |
| 397 | struct gsm_bts_trx *trx, u_int8_t tei, |
| 398 | u_int8_t sapi) |
| 399 | { |
| 400 | struct e1inp_sign_link *link; |
| 401 | |
| 402 | if (ts->type != E1INP_TS_TYPE_SIGN) |
| 403 | return NULL; |
| 404 | |
Harald Welte | 857e00d | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 405 | link = talloc_zero(tall_sigl_ctx, struct e1inp_sign_link); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 406 | if (!link) |
| 407 | return NULL; |
| 408 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 409 | link->ts = ts; |
| 410 | link->type = type; |
| 411 | INIT_LLIST_HEAD(&link->tx_list); |
| 412 | link->trx = trx; |
| 413 | link->tei = tei; |
| 414 | link->sapi = sapi; |
| 415 | |
| 416 | llist_add_tail(&link->list, &ts->sign.sign_links); |
| 417 | |
| 418 | return link; |
| 419 | } |
| 420 | |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 421 | void e1inp_sign_link_destroy(struct e1inp_sign_link *link) |
| 422 | { |
| 423 | llist_del(&link->list); |
| 424 | talloc_free(link); |
| 425 | } |
| 426 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 427 | /* the E1 driver tells us he has received something on a TS */ |
| 428 | int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg, |
| 429 | u_int8_t tei, u_int8_t sapi) |
| 430 | { |
| 431 | struct e1inp_sign_link *link; |
| 432 | int ret; |
| 433 | |
| 434 | switch (ts->type) { |
| 435 | case E1INP_TS_TYPE_SIGN: |
| 436 | /* consult the list of signalling links */ |
| 437 | write_pcap_packet(PCAP_INPUT, sapi, tei, msg); |
| 438 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 439 | if (!link) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 440 | LOGP(DMI, LOGL_ERROR, "didn't find signalling link for " |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 441 | "tei %d, sapi %d\n", tei, sapi); |
| 442 | return -EINVAL; |
| 443 | } |
Holger Hans Peter Freyther | c8d862e | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 444 | |
| 445 | debug_set_context(BSC_CTX_BTS, link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 446 | switch (link->type) { |
| 447 | case E1INP_SIGN_OML: |
| 448 | msg->trx = link->trx; |
| 449 | ret = abis_nm_rcvmsg(msg); |
| 450 | break; |
| 451 | case E1INP_SIGN_RSL: |
| 452 | msg->trx = link->trx; |
| 453 | ret = abis_rsl_rcvmsg(msg); |
| 454 | break; |
| 455 | default: |
| 456 | ret = -EINVAL; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 457 | LOGP(DMI, LOGL_ERROR, "unknown link type %u\n", link->type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 458 | break; |
| 459 | } |
| 460 | break; |
| 461 | case E1INP_TS_TYPE_TRAU: |
| 462 | ret = subch_demux_in(&ts->trau.demux, msg->l2h, msgb_l2len(msg)); |
| 463 | break; |
| 464 | default: |
| 465 | ret = -EINVAL; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 466 | LOGP(DMI, LOGL_ERROR, "unknown TS type %u\n", ts->type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | |
| 470 | return ret; |
| 471 | } |
| 472 | |
| 473 | #define TSX_ALLOC_SIZE 4096 |
| 474 | |
| 475 | /* called by driver if it wants to transmit on a given TS */ |
| 476 | struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts, |
| 477 | struct e1inp_sign_link **sign_link) |
| 478 | { |
| 479 | struct e1inp_sign_link *link; |
| 480 | struct msgb *msg = NULL; |
| 481 | int len; |
| 482 | |
| 483 | switch (e1i_ts->type) { |
| 484 | case E1INP_TS_TYPE_SIGN: |
| 485 | /* FIXME: implement this round robin */ |
| 486 | llist_for_each_entry(link, &e1i_ts->sign.sign_links, list) { |
| 487 | msg = msgb_dequeue(&link->tx_list); |
| 488 | if (msg) { |
| 489 | if (sign_link) |
| 490 | *sign_link = link; |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | break; |
| 495 | case E1INP_TS_TYPE_TRAU: |
Harald Welte | 9cfc935 | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 496 | msg = msgb_alloc(TSX_ALLOC_SIZE, "TRAU_TX"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 497 | if (!msg) |
| 498 | return NULL; |
| 499 | len = subchan_mux_out(&e1i_ts->trau.mux, msg->data, 40); |
| 500 | msgb_put(msg, 40); |
| 501 | break; |
| 502 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 503 | LOGP(DMI, LOGL_ERROR, "unsupported E1 TS type %u\n", e1i_ts->type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 504 | return NULL; |
| 505 | } |
| 506 | return msg; |
| 507 | } |
| 508 | |
| 509 | /* called by driver in case some kind of link state event */ |
| 510 | int e1inp_event(struct e1inp_ts *ts, int evt, u_int8_t tei, u_int8_t sapi) |
| 511 | { |
| 512 | struct e1inp_sign_link *link; |
| 513 | |
| 514 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 515 | if (!link) |
| 516 | return -EINVAL; |
| 517 | |
| 518 | /* FIXME: report further upwards */ |
| 519 | input_event(evt, link->type, link->trx); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | /* register a driver with the E1 core */ |
| 524 | int e1inp_driver_register(struct e1inp_driver *drv) |
| 525 | { |
| 526 | llist_add_tail(&drv->list, &e1inp_driver_list); |
| 527 | return 0; |
| 528 | } |
| 529 | |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 530 | int e1inp_line_update(struct e1inp_line *line) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 531 | { |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 532 | return mi_e1_line_update(line); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 533 | } |
Harald Welte | 932e20d | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 534 | |
Harald Welte | 4d42bd8 | 2009-11-30 19:43:54 +0100 | [diff] [blame] | 535 | static int e1i_sig_cb(unsigned int subsys, unsigned int signal, |
| 536 | void *handler_data, void *signal_data) |
| 537 | { |
| 538 | if (subsys != SS_GLOBAL || |
| 539 | signal != S_GLOBAL_SHUTDOWN) |
| 540 | return 0; |
| 541 | |
| 542 | if (pcap_fd) { |
| 543 | close(pcap_fd); |
| 544 | pcap_fd = -1; |
| 545 | } |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
Harald Welte | 932e20d | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 550 | static __attribute__((constructor)) void on_dso_load_e1_inp(void) |
| 551 | { |
| 552 | tall_sigl_ctx = talloc_named_const(tall_bsc_ctx, 1, |
| 553 | "e1inp_sign_link"); |
Harald Welte | 4d42bd8 | 2009-11-30 19:43:54 +0100 | [diff] [blame] | 554 | register_signal_handler(SS_GLOBAL, e1i_sig_cb, NULL); |
Harald Welte | 932e20d | 2009-07-28 00:41:45 +0200 | [diff] [blame] | 555 | } |