blob: 703a67e40239716c6368d1a6f45d552ff2645ba6 [file] [log] [blame]
Harald Welte39cfbf42016-07-28 09:04:11 +02001#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 Welteb7e40232016-07-29 14:26:50 +02006#include <osmocom/vty/logging.h>
Harald Welte39cfbf42016-07-28 09:04:11 +02007
8#include <osmocom/abis/abis.h>
9#include <osmocom/abis/e1_input.h>
10
11#include "storage.h"
12#include "recorder.h"
13
14static 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;
Harald Welte13351132016-10-17 22:13:36 +020019 case E1INP_TS_TYPE_HDLC:
Harald Welte39cfbf42016-07-28 09:04:11 +020020 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 */
29void e1ts_raw_recv(struct e1inp_ts *ts, struct msgb *msg)
30{
Harald Welte0e91aa12016-07-28 21:03:40 +020031 struct e1_recorder_line *rline = &g_recorder.line[ts->line->num];
Harald Welte39cfbf42016-07-28 09:04:11 +020032 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 Welte0e91aa12016-07-28 21:03:40 +020038 if (rline->mirror.enabled) {
Harald Welteb7e40232016-07-29 14:26:50 +020039 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 Welte4a92d0b2016-10-18 21:36:01 +020043 if (!other_ts) {
44 msgb_free(msg);
Harald Welteb7e40232016-07-29 14:26:50 +020045 return;
Harald Welte4a92d0b2016-10-18 21:36:01 +020046 }
Harald Welte39cfbf42016-07-28 09:04:11 +020047 /* forward data to destination line */
Harald Welteb7e40232016-07-29 14:26:50 +020048 OSMO_ASSERT(other_ts->type == ts->type);
49 msgb_enqueue(&other_ts->raw.tx_queue, msg);
Harald Welte4a92d0b2016-10-18 21:36:01 +020050 } else
51 msgb_free(msg);
Harald Welte39cfbf42016-07-28 09:04:11 +020052}
53
54static 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 Welte39cfbf42016-07-28 09:04:11 +020064static const struct log_info_cat recorder_categories[] = {
65 [DMAIN] = {
66 .name = "MAIN",
Harald Welteb7e40232016-07-29 14:26:50 +020067 .description = "Osmocom E1 Recorder",
Harald Welte39cfbf42016-07-28 09:04:11 +020068 .enabled = 1, .loglevel = LOGL_DEBUG,
69 },
70};
71static struct log_info info = {
72 .cat = recorder_categories,
73 .num_cat = ARRAY_SIZE(recorder_categories),
74};
75
76struct 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
82static void *rec_tall_ctx;
83struct e1_recorder g_recorder;
84
85int 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 Welteb7e40232016-07-29 14:26:50 +020093 logging_vty_add_cmds(&info);
Harald Welte39cfbf42016-07-28 09:04:11 +020094 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}