Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 1 | #include <osmocom/core/signal.h> |
| 2 | #include <osmocom/core/logging.h> |
| 3 | #include <osmocom/core/application.h> |
| 4 | #include <osmocom/vty/vty.h> |
| 5 | #include <osmocom/vty/telnet_interface.h> |
Harald Welte | b7e4023 | 2016-07-29 14:26:50 +0200 | [diff] [blame] | 6 | #include <osmocom/vty/logging.h> |
Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 7 | |
| 8 | #include <osmocom/abis/abis.h> |
| 9 | #include <osmocom/abis/e1_input.h> |
| 10 | |
| 11 | #include "storage.h" |
| 12 | #include "recorder.h" |
| 13 | |
| 14 | static enum osmo_e1cap_capture_mode ts2cap_mode(struct e1inp_ts *ts) |
| 15 | { |
| 16 | switch (ts->type) { |
| 17 | case E1INP_TS_TYPE_RAW: |
| 18 | return OSMO_E1CAP_MODE_RAW; |
| 19 | case E1INP_TS_TYPE_SIGN: |
| 20 | return OSMO_E1CAP_MODE_HDLC; |
| 21 | case E1INP_TS_TYPE_TRAU: |
| 22 | return OSMO_E1CAP_MODE_TRAU; |
| 23 | default: |
| 24 | OSMO_ASSERT(0); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /* receive a raw message frome the E1 timeslot */ |
| 29 | void e1ts_raw_recv(struct e1inp_ts *ts, struct msgb *msg) |
| 30 | { |
Harald Welte | 0e91aa1 | 2016-07-28 21:03:40 +0200 | [diff] [blame] | 31 | struct e1_recorder_line *rline = &g_recorder.line[ts->line->num]; |
Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 32 | enum osmo_e1cap_capture_mode cap_mode = ts2cap_mode(ts); |
| 33 | |
| 34 | /* FIXME: special processing of TFP and PGSL */ |
| 35 | |
| 36 | e1frame_store(ts, msg, cap_mode); |
| 37 | |
Harald Welte | 0e91aa1 | 2016-07-28 21:03:40 +0200 | [diff] [blame] | 38 | if (rline->mirror.enabled) { |
Harald Welte | b7e4023 | 2016-07-29 14:26:50 +0200 | [diff] [blame] | 39 | struct e1inp_line *other_line = |
| 40 | e1inp_line_find(rline->mirror.line_nr); |
| 41 | struct e1inp_ts *other_ts; |
| 42 | other_ts = &other_line->ts[ts->num-1]; |
Harald Welte | 4a92d0b | 2016-10-18 21:36:01 +0200 | [diff] [blame] | 43 | if (!other_ts) { |
| 44 | msgb_free(msg); |
Harald Welte | b7e4023 | 2016-07-29 14:26:50 +0200 | [diff] [blame] | 45 | return; |
Harald Welte | 4a92d0b | 2016-10-18 21:36:01 +0200 | [diff] [blame] | 46 | } |
Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 47 | /* forward data to destination line */ |
Harald Welte | b7e4023 | 2016-07-29 14:26:50 +0200 | [diff] [blame] | 48 | OSMO_ASSERT(other_ts->type == ts->type); |
| 49 | msgb_enqueue(&other_ts->raw.tx_queue, msg); |
Harald Welte | 4a92d0b | 2016-10-18 21:36:01 +0200 | [diff] [blame] | 50 | } else |
| 51 | msgb_free(msg); |
Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static int inp_sig_cb(unsigned int subsys, unsigned int signal, |
| 55 | void *handler_data, void *signal_data) |
| 56 | { |
| 57 | OSMO_ASSERT(subsys == SS_L_INPUT); |
| 58 | |
| 59 | /* FIXME */ |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 64 | static const struct log_info_cat recorder_categories[] = { |
| 65 | [DMAIN] = { |
| 66 | .name = "MAIN", |
Harald Welte | b7e4023 | 2016-07-29 14:26:50 +0200 | [diff] [blame] | 67 | .description = "Osmocom E1 Recorder", |
Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 68 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 69 | }, |
| 70 | }; |
| 71 | static struct log_info info = { |
| 72 | .cat = recorder_categories, |
| 73 | .num_cat = ARRAY_SIZE(recorder_categories), |
| 74 | }; |
| 75 | |
| 76 | struct vty_app_info vty_info = { |
| 77 | .name = "osmo-e1-recorder", |
| 78 | .version = "0", |
| 79 | .copyright = "(C) 2016 by Harald Welte <laforge@gnumonks.org>\n", |
| 80 | }; |
| 81 | |
| 82 | static void *rec_tall_ctx; |
| 83 | struct e1_recorder g_recorder; |
| 84 | |
| 85 | int main(int argc, char **argv) |
| 86 | { |
| 87 | int rc; |
| 88 | |
| 89 | rec_tall_ctx = talloc_named_const(NULL, 0, "recorder"); |
| 90 | |
| 91 | osmo_init_logging(&info); |
| 92 | vty_init(&vty_info); |
Harald Welte | b7e4023 | 2016-07-29 14:26:50 +0200 | [diff] [blame] | 93 | logging_vty_add_cmds(&info); |
Harald Welte | 39cfbf4 | 2016-07-28 09:04:11 +0200 | [diff] [blame] | 94 | osmo_signal_register_handler(SS_L_INPUT, inp_sig_cb, NULL); |
| 95 | libosmo_abis_init(rec_tall_ctx); |
| 96 | e1inp_vty_init(); |
| 97 | recorder_vty_init(); |
| 98 | |
| 99 | rc = vty_read_config_file("osmo-e1-recorder.cfg", NULL); |
| 100 | if (rc < 0) |
| 101 | exit(1); |
| 102 | |
| 103 | /* start telne tafte reading config for vty_get_bind_adr() */ |
| 104 | telnet_init_dynif(rec_tall_ctx, NULL, vty_get_bind_addr(), 4444); |
| 105 | |
| 106 | while (1) { |
| 107 | osmo_select_main(0); |
| 108 | }; |
| 109 | } |