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 |
| 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> |
Holger Freyther | 66e092b | 2009-03-31 12:13:50 +0000 | [diff] [blame] | 38 | #ifndef AF_ISDN |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 39 | #define AF_ISDN 34 |
| 40 | #define PF_ISDN AF_ISDN |
Holger Freyther | 66e092b | 2009-03-31 12:13:50 +0000 | [diff] [blame] | 41 | #endif |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 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> |
Harald Welte | 45b407a | 2009-05-23 15:51:12 +0000 | [diff] [blame] | 52 | #include <openbsc/trau_frame.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 53 | #include <openbsc/trau_mux.h> |
| 54 | |
| 55 | #define NUM_E1_TS 32 |
| 56 | |
| 57 | /* list of all E1 drivers */ |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 58 | LLIST_HEAD(e1inp_driver_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 59 | |
| 60 | /* list of all E1 lines */ |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 61 | LLIST_HEAD(e1inp_line_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 62 | |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 63 | /* to be implemented, e.g. by bsc_hack.c */ |
| 64 | void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx); |
| 65 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 66 | /* |
| 67 | * pcap writing of the misdn load |
| 68 | * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat |
| 69 | */ |
| 70 | #define DLT_LINUX_LAPD 177 |
| 71 | #define PCAP_INPUT 0 |
| 72 | #define PCAP_OUTPUT 1 |
| 73 | |
| 74 | struct pcap_hdr { |
| 75 | u_int32_t magic_number; |
| 76 | u_int16_t version_major; |
| 77 | u_int16_t version_minor; |
| 78 | int32_t thiszone; |
| 79 | u_int32_t sigfigs; |
| 80 | u_int32_t snaplen; |
| 81 | u_int32_t network; |
| 82 | } __attribute__((packed)); |
| 83 | |
| 84 | struct pcaprec_hdr { |
| 85 | u_int32_t ts_sec; |
| 86 | u_int32_t ts_usec; |
| 87 | u_int32_t incl_len; |
| 88 | u_int32_t orig_len; |
| 89 | } __attribute__((packed)); |
| 90 | |
| 91 | struct fake_linux_lapd_header { |
| 92 | u_int16_t pkttype; |
| 93 | u_int16_t hatype; |
| 94 | u_int16_t halen; |
| 95 | u_int64_t addr; |
| 96 | int16_t protocol; |
| 97 | } __attribute__((packed)); |
| 98 | |
| 99 | struct lapd_header { |
| 100 | u_int8_t ea1 : 1; |
| 101 | u_int8_t cr : 1; |
| 102 | u_int8_t sapi : 6; |
| 103 | u_int8_t ea2 : 1; |
| 104 | u_int8_t tei : 7; |
| 105 | u_int8_t control_foo; /* fake UM's ... */ |
| 106 | } __attribute__((packed)); |
| 107 | |
| 108 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->hatype == 2, hatype_offset); |
| 109 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->halen == 4, halen_offset); |
| 110 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->addr == 6, addr_offset); |
| 111 | static_assert((int)&((struct fake_linux_lapd_header*)NULL)->protocol == 14, proto_offset); |
| 112 | static_assert(sizeof(struct fake_linux_lapd_header) == 16, lapd_header_size); |
| 113 | |
| 114 | |
| 115 | static int pcap_fd = -1; |
| 116 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 117 | void e1_set_pcap_fd(int fd) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 118 | { |
| 119 | int ret; |
| 120 | struct pcap_hdr header = { |
| 121 | .magic_number = 0xa1b2c3d4, |
| 122 | .version_major = 2, |
| 123 | .version_minor = 4, |
| 124 | .thiszone = 0, |
| 125 | .sigfigs = 0, |
| 126 | .snaplen = 65535, |
| 127 | .network = DLT_LINUX_LAPD, |
| 128 | }; |
| 129 | |
| 130 | pcap_fd = fd; |
| 131 | ret = write(pcap_fd, &header, sizeof(header)); |
| 132 | } |
| 133 | |
| 134 | /* This currently only works for the D-Channel */ |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 135 | static void write_pcap_packet(int direction, int sapi, int tei, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 136 | struct msgb *msg) { |
| 137 | if (pcap_fd < 0) |
| 138 | return; |
| 139 | |
| 140 | int ret; |
| 141 | time_t cur_time; |
| 142 | struct tm *tm; |
| 143 | |
| 144 | struct fake_linux_lapd_header header = { |
| 145 | .pkttype = 4, |
| 146 | .hatype = 0, |
| 147 | .halen = 0, |
| 148 | .addr = direction == PCAP_OUTPUT ? 0x0 : 0x1, |
| 149 | .protocol = ntohs(48), |
| 150 | }; |
| 151 | |
| 152 | struct lapd_header lapd_header = { |
| 153 | .ea1 = 0, |
| 154 | .cr = direction == PCAP_OUTPUT ? 1 : 0, |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 155 | .sapi = sapi & 0x3F, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 156 | .ea2 = 1, |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 157 | .tei = tei & 0x7F, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 158 | .control_foo = 0x03 /* UI */, |
| 159 | }; |
| 160 | |
| 161 | struct pcaprec_hdr payload_header = { |
| 162 | .ts_sec = 0, |
| 163 | .ts_usec = 0, |
| 164 | .incl_len = msg->len + sizeof(struct fake_linux_lapd_header) |
| 165 | + sizeof(struct lapd_header) |
| 166 | - MISDN_HEADER_LEN, |
| 167 | .orig_len = msg->len + sizeof(struct fake_linux_lapd_header) |
| 168 | + sizeof(struct lapd_header) |
| 169 | - MISDN_HEADER_LEN, |
| 170 | }; |
| 171 | |
| 172 | |
| 173 | cur_time = time(NULL); |
| 174 | tm = localtime(&cur_time); |
| 175 | payload_header.ts_sec = mktime(tm); |
| 176 | |
| 177 | ret = write(pcap_fd, &payload_header, sizeof(payload_header)); |
| 178 | ret = write(pcap_fd, &header, sizeof(header)); |
| 179 | ret = write(pcap_fd, &lapd_header, sizeof(lapd_header)); |
| 180 | ret = write(pcap_fd, msg->data + MISDN_HEADER_LEN, |
| 181 | msg->len - MISDN_HEADER_LEN); |
| 182 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 183 | |
Harald Welte | d256d4f | 2009-03-10 19:44:48 +0000 | [diff] [blame] | 184 | static const char *sign_types[] = { |
| 185 | [E1INP_SIGN_NONE] = "None", |
| 186 | [E1INP_SIGN_OML] = "OML", |
| 187 | [E1INP_SIGN_RSL] = "RSL", |
| 188 | }; |
| 189 | const char *e1inp_signtype_name(enum e1inp_sign_type tp) |
| 190 | { |
| 191 | if (tp >= ARRAY_SIZE(sign_types)) |
| 192 | return "undefined"; |
| 193 | return sign_types[tp]; |
| 194 | } |
| 195 | |
| 196 | static const char *ts_types[] = { |
| 197 | [E1INP_TS_TYPE_NONE] = "None", |
| 198 | [E1INP_TS_TYPE_SIGN] = "Signalling", |
| 199 | [E1INP_TS_TYPE_TRAU] = "TRAU", |
| 200 | }; |
| 201 | |
| 202 | const char *e1inp_tstype_name(enum e1inp_ts_type tp) |
| 203 | { |
| 204 | if (tp >= ARRAY_SIZE(ts_types)) |
| 205 | return "undefined"; |
| 206 | return ts_types[tp]; |
| 207 | } |
| 208 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 209 | /* callback when a TRAU frame was received */ |
| 210 | static int subch_cb(struct subch_demux *dmx, int ch, u_int8_t *data, int len, |
| 211 | void *_priv) |
| 212 | { |
| 213 | struct e1inp_ts *e1i_ts = _priv; |
| 214 | struct gsm_e1_subslot src_ss; |
| 215 | |
| 216 | src_ss.e1_nr = e1i_ts->line->num; |
| 217 | src_ss.e1_ts = e1i_ts->num; |
| 218 | src_ss.e1_ts_ss = ch; |
| 219 | |
| 220 | return trau_mux_input(&src_ss, data, len); |
| 221 | } |
| 222 | |
| 223 | int abis_rsl_sendmsg(struct msgb *msg) |
| 224 | { |
| 225 | struct e1inp_sign_link *sign_link; |
| 226 | struct e1inp_driver *e1inp_driver; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 227 | struct e1inp_ts *e1i_ts; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 228 | |
| 229 | msg->l2h = msg->data; |
| 230 | |
| 231 | if (!msg->trx || !msg->trx->rsl_link) { |
| 232 | fprintf(stderr, "rsl_sendmsg: msg->trx == NULL\n"); |
| 233 | return -EINVAL; |
| 234 | } |
| 235 | |
| 236 | sign_link = msg->trx->rsl_link; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 237 | e1i_ts = sign_link->ts; |
| 238 | if (!bsc_timer_pending(&e1i_ts->sign.tx_timer)) { |
| 239 | /* notify the driver we have something to write */ |
| 240 | e1inp_driver = sign_link->ts->line->driver; |
| 241 | e1inp_driver->want_write(e1i_ts); |
| 242 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 243 | msgb_enqueue(&sign_link->tx_list, msg); |
| 244 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 245 | /* dump it */ |
| 246 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 247 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | int _abis_nm_sendmsg(struct msgb *msg) |
| 252 | { |
| 253 | struct e1inp_sign_link *sign_link; |
| 254 | struct e1inp_driver *e1inp_driver; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 255 | struct e1inp_ts *e1i_ts; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 256 | |
| 257 | msg->l2h = msg->data; |
| 258 | |
| 259 | if (!msg->trx || !msg->trx->bts || !msg->trx->bts->oml_link) { |
Holger Freyther | fb3f519 | 2009-02-09 23:09:15 +0000 | [diff] [blame] | 260 | fprintf(stderr, "nm_sendmsg: msg->trx == NULL\n"); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 261 | return -EINVAL; |
| 262 | } |
Holger Freyther | fb3f519 | 2009-02-09 23:09:15 +0000 | [diff] [blame] | 263 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 264 | sign_link = msg->trx->bts->oml_link; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 265 | e1i_ts = sign_link->ts; |
| 266 | if (!bsc_timer_pending(&e1i_ts->sign.tx_timer)) { |
| 267 | /* notify the driver we have something to write */ |
| 268 | e1inp_driver = sign_link->ts->line->driver; |
| 269 | e1inp_driver->want_write(e1i_ts); |
| 270 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 271 | msgb_enqueue(&sign_link->tx_list, msg); |
| 272 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 273 | /* dump it */ |
| 274 | write_pcap_packet(PCAP_OUTPUT, sign_link->sapi, sign_link->tei, msg); |
| 275 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | /* Timeslot */ |
| 280 | |
| 281 | /* configure and initialize one e1inp_ts */ |
| 282 | int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line, |
| 283 | enum e1inp_ts_type type) |
| 284 | { |
| 285 | ts->type = type; |
| 286 | ts->line = line; |
| 287 | |
| 288 | switch (type) { |
| 289 | case E1INP_TS_TYPE_SIGN: |
| 290 | INIT_LLIST_HEAD(&ts->sign.sign_links); |
| 291 | break; |
| 292 | case E1INP_TS_TYPE_TRAU: |
| 293 | subchan_mux_init(&ts->trau.mux); |
| 294 | ts->trau.demux.out_cb = subch_cb; |
| 295 | ts->trau.demux.data = ts; |
| 296 | subch_demux_init(&ts->trau.demux); |
| 297 | break; |
| 298 | default: |
| 299 | fprintf(stderr, "unsupported E1 timeslot type %u\n", |
| 300 | ts->type); |
| 301 | return -EINVAL; |
| 302 | } |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static struct e1inp_line *e1inp_line_get(u_int8_t e1_nr) |
| 307 | { |
| 308 | struct e1inp_line *e1i_line; |
| 309 | |
| 310 | /* iterate over global list of e1 lines */ |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 311 | llist_for_each_entry(e1i_line, &e1inp_line_list, list) { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 312 | if (e1i_line->num == e1_nr) |
| 313 | return e1i_line; |
| 314 | } |
| 315 | return NULL; |
| 316 | } |
| 317 | |
| 318 | static struct e1inp_ts *e1inp_ts_get(u_int8_t e1_nr, u_int8_t ts_nr) |
| 319 | { |
| 320 | struct e1inp_line *e1i_line; |
| 321 | |
| 322 | e1i_line = e1inp_line_get(e1_nr); |
| 323 | if (!e1i_line) |
| 324 | return NULL; |
| 325 | |
| 326 | return &e1i_line->ts[ts_nr-1]; |
| 327 | } |
| 328 | |
| 329 | struct subch_mux *e1inp_get_mux(u_int8_t e1_nr, u_int8_t ts_nr) |
| 330 | { |
| 331 | struct e1inp_ts *e1i_ts = e1inp_ts_get(e1_nr, ts_nr); |
| 332 | |
| 333 | if (!e1i_ts) |
| 334 | return NULL; |
| 335 | |
| 336 | return &e1i_ts->trau.mux; |
| 337 | } |
| 338 | |
| 339 | /* Signalling Link */ |
| 340 | |
| 341 | struct e1inp_sign_link *e1inp_lookup_sign_link(struct e1inp_ts *e1i, |
| 342 | u_int8_t tei, u_int8_t sapi) |
| 343 | { |
| 344 | struct e1inp_sign_link *link; |
| 345 | |
| 346 | llist_for_each_entry(link, &e1i->sign.sign_links, list) { |
| 347 | if (link->sapi == sapi && link->tei == tei) |
| 348 | return link; |
| 349 | } |
| 350 | |
| 351 | return NULL; |
| 352 | } |
| 353 | |
| 354 | /* create a new signalling link in a E1 timeslot */ |
| 355 | |
| 356 | struct e1inp_sign_link * |
| 357 | e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type, |
| 358 | struct gsm_bts_trx *trx, u_int8_t tei, |
| 359 | u_int8_t sapi) |
| 360 | { |
| 361 | struct e1inp_sign_link *link; |
| 362 | |
| 363 | if (ts->type != E1INP_TS_TYPE_SIGN) |
| 364 | return NULL; |
| 365 | |
| 366 | link = malloc(sizeof(*link)); |
| 367 | if (!link) |
| 368 | return NULL; |
| 369 | |
| 370 | memset(link, 0, sizeof(*link)); |
| 371 | |
| 372 | link->ts = ts; |
| 373 | link->type = type; |
| 374 | INIT_LLIST_HEAD(&link->tx_list); |
| 375 | link->trx = trx; |
Holger Freyther | fb3f519 | 2009-02-09 23:09:15 +0000 | [diff] [blame] | 376 | link->tei = tei; |
| 377 | link->sapi = sapi; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 378 | |
| 379 | llist_add_tail(&link->list, &ts->sign.sign_links); |
| 380 | |
| 381 | return link; |
| 382 | } |
| 383 | |
| 384 | /* the E1 driver tells us he has received something on a TS */ |
| 385 | int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg, |
| 386 | u_int8_t tei, u_int8_t sapi) |
| 387 | { |
| 388 | struct e1inp_sign_link *link; |
| 389 | int ret; |
| 390 | |
| 391 | switch (ts->type) { |
| 392 | case E1INP_TS_TYPE_SIGN: |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 393 | /* consult the list of signalling links */ |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 394 | write_pcap_packet(PCAP_INPUT, sapi, tei, msg); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 395 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 396 | if (!link) { |
| 397 | fprintf(stderr, "didn't find singalling link for " |
| 398 | "tei %d, sapi %d\n", tei, sapi); |
| 399 | return -EINVAL; |
| 400 | } |
| 401 | switch (link->type) { |
| 402 | case E1INP_SIGN_OML: |
| 403 | msg->trx = link->trx; |
| 404 | ret = abis_nm_rcvmsg(msg); |
| 405 | break; |
| 406 | case E1INP_SIGN_RSL: |
| 407 | msg->trx = link->trx; |
| 408 | ret = abis_rsl_rcvmsg(msg); |
| 409 | break; |
| 410 | default: |
| 411 | ret = -EINVAL; |
| 412 | fprintf(stderr, "unknown link type %u\n", link->type); |
| 413 | break; |
| 414 | } |
| 415 | break; |
| 416 | case E1INP_TS_TYPE_TRAU: |
Harald Welte | 9e78331 | 2009-02-17 19:02:29 +0000 | [diff] [blame] | 417 | ret = subch_demux_in(&ts->trau.demux, msg->l2h, msgb_l2len(msg)); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 418 | break; |
| 419 | default: |
| 420 | ret = -EINVAL; |
| 421 | fprintf(stderr, "unknown TS type %u\n", ts->type); |
| 422 | break; |
| 423 | } |
| 424 | |
| 425 | return ret; |
| 426 | } |
| 427 | |
| 428 | #define TSX_ALLOC_SIZE 4096 |
| 429 | |
| 430 | /* called by driver if it wants to transmit on a given TS */ |
| 431 | struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts, |
| 432 | struct e1inp_sign_link **sign_link) |
| 433 | { |
| 434 | struct e1inp_sign_link *link; |
| 435 | struct msgb *msg = NULL; |
| 436 | int len; |
| 437 | |
| 438 | switch (e1i_ts->type) { |
| 439 | case E1INP_TS_TYPE_SIGN: |
| 440 | /* FIXME: implement this round robin */ |
| 441 | llist_for_each_entry(link, &e1i_ts->sign.sign_links, list) { |
| 442 | msg = msgb_dequeue(&link->tx_list); |
| 443 | if (msg) { |
| 444 | if (sign_link) |
| 445 | *sign_link = link; |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | break; |
| 450 | case E1INP_TS_TYPE_TRAU: |
| 451 | msg = msgb_alloc(TSX_ALLOC_SIZE); |
| 452 | if (!msg) |
| 453 | return NULL; |
| 454 | len = subchan_mux_out(&e1i_ts->trau.mux, msg->data, 40); |
| 455 | msgb_put(msg, 40); |
| 456 | break; |
| 457 | default: |
| 458 | fprintf(stderr, "unsupported E1 TS type %u\n", e1i_ts->type); |
| 459 | return NULL; |
| 460 | } |
| 461 | return msg; |
| 462 | } |
| 463 | |
| 464 | /* called by driver in case some kind of link state event */ |
| 465 | int e1inp_event(struct e1inp_ts *ts, int evt, u_int8_t tei, u_int8_t sapi) |
| 466 | { |
| 467 | struct e1inp_sign_link *link; |
| 468 | |
| 469 | link = e1inp_lookup_sign_link(ts, tei, sapi); |
| 470 | if (!link) |
| 471 | return -EINVAL; |
| 472 | |
| 473 | /* FIXME: report further upwards */ |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 474 | input_event(evt, link->type, link->trx); |
| 475 | return 0; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /* register a driver with the E1 core */ |
| 479 | int e1inp_driver_register(struct e1inp_driver *drv) |
| 480 | { |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 481 | llist_add_tail(&drv->list, &e1inp_driver_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* register a line with the E1 core */ |
| 486 | int e1inp_line_register(struct e1inp_line *line) |
| 487 | { |
| 488 | int i; |
| 489 | |
Harald Welte | d256d4f | 2009-03-10 19:44:48 +0000 | [diff] [blame] | 490 | for (i = 0; i < NUM_E1_TS; i++) { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 491 | line->ts[i].num = i+1; |
Harald Welte | d256d4f | 2009-03-10 19:44:48 +0000 | [diff] [blame] | 492 | line->ts[i].line = line; |
| 493 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 494 | |
Harald Welte | 44d542e | 2009-03-10 18:24:35 +0000 | [diff] [blame] | 495 | llist_add_tail(&line->list, &e1inp_line_list); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 496 | |
| 497 | return 0; |
| 498 | } |