blob: 694dab1e06597afa3339a9662a02a83f74746e71 [file] [log] [blame]
Harald Welte39cfbf42016-07-28 09:04:11 +02001
2#include <osmocom/abis/e1_input.h>
3#include <osmocom/vty/command.h>
4#include <osmocom/vty/vty.h>
5
6#include "recorder.h"
7
8#define LINE_STR "Configure Recording for given Line\nE1/T1 Line Number\n"
9
10DEFUN(cfg_recorder, cfg_recorder_cmd,
11 "recorder",
12 "Configuration of E1 Recorder\n")
13{
14 vty->node = RECORDER_NODE;
15 return CMD_SUCCESS;
16}
17
18DEFUN(cfg_rec_line_ts_mode, cfg_rec_line_ts_mode_cmd,
19 "line <0-255> ts <0-31> mode (none|signalling|trau|raw)",
20 LINE_STR
21 "E1/T1 Timeslot Number\n"
22 "E1/T1 Timeslot Number\n"
23 "Recording Mode\n"
24 "No recording\n"
25 "Signalling Data (HDLC)\n"
26 "TRAU Frames\n"
27 "Raw Data\n")
28{
29 int line_nr = atoi(argv[0]);
30 int ts_nr = atoi(argv[1]);
31 int mode = get_string_value(e1inp_ts_type_names, argv[2]);
32 struct e1inp_line *line;
33 struct e1inp_ts *ts;
34
35 if (mode < 0) {
36 vty_out(vty, "Cannot parse mode %s%s", argv[2], VTY_NEWLINE);
37 return CMD_WARNING;
38 }
39
40 line = e1inp_line_find(line_nr);
41 if (!line) {
42 vty_out(vty, "Cannot find line %d%s", line_nr, VTY_NEWLINE);
43 return CMD_WARNING;
44 }
45 if (ts_nr >= line->num_ts) {
46 vty_out(vty, "Timeslot %d is too large%s", ts_nr, VTY_NEWLINE);
47 return CMD_WARNING;
48 }
49 ts = &line->ts[ts_nr];
50
51 switch (mode) {
52 case E1INP_TS_TYPE_NONE:
53 /* TOOD: have eqinp_ts_config_none ? */
54 ts->type = E1INP_TS_TYPE_NONE;
55 break;
56 case E1INP_TS_TYPE_SIGN:
57 e1inp_ts_config_sign(ts, line);
58 break;
59 case E1INP_TS_TYPE_RAW:
60 e1inp_ts_config_raw(ts, line, &e1ts_raw_recv);
61 break;
62 }
63
64 /* notify driver of change */
65 e1inp_line_update(line);
66
67 return CMD_SUCCESS;
68}
69
70DEFUN(cfg_rec_line_mirror, cfg_rec_line_mirror_cmd,
71 "line <0-255> mirror <0-255>",
72 LINE_STR "Mirror this line to another line\n"
73 "E1/T1 Line Number\n")
74{
75 uint8_t line_nr = atoi(argv[0]);
76 uint8_t peer_nr = atoi(argv[1]);
77 struct e1_recorder_line *line = &g_recorder.line[line_nr];
78 struct e1_recorder_line *peer = &g_recorder.line[peer_nr];
79 /* look up morror peer and enable mirror flag on peer */
80 if (peer->mirror.enabled &&
81 peer->mirror.line_nr != line_nr) {
82 vty_out(vty, "Peer line %u already part of another mirror%s",
83 peer_nr, VTY_NEWLINE);
84 return CMD_WARNING;
85 }
86 peer->mirror.enabled = true;
87 peer->mirror.line_nr = line_nr;
88 /* enable mirror flag of current line */
89 if (line->mirror.enabled &&
90 line->mirror.line_nr != peer_nr) {
91 vty_out(vty, "Line %u already part of another mirror%s",
92 line_nr, VTY_NEWLINE);
93 return CMD_WARNING;
94 }
95 line->mirror.enabled = true;
96 line->mirror.line_nr = peer_nr;
97 return CMD_SUCCESS;
98}
99
100DEFUN(cfg_rec_no_line_mirror, cfg_rec_no_line_mirror_cmd,
101 "no line <0-255> mirror",
102 LINE_STR "Mirror this line to another line\n"
103 "E1/T1 Line Number\n")
104{
105 uint8_t line_nr = atoi(argv[0]);
106 struct e1_recorder_line *line = &g_recorder.line[line_nr];
107 struct e1_recorder_line *peer;
108
109 if (!line->mirror.enabled)
110 return CMD_WARNING;
111 /* look up morror peer (if any) and disable mirror flag on peer */
112 peer = &g_recorder.line[line->mirror.line_nr];
113 if (peer->mirror.enabled) {
114 peer->mirror.enabled = false;
115 peer->mirror.line_nr = 0;
116 }
117 /* dsiable mirror flag of current line */
118 if (line->mirror.enabled){
119 line->mirror.enabled = false;
120 line->mirror.line_nr = 0;
121 }
122 return CMD_SUCCESS;
123}
124
125
126DEFUN(cfg_rec_save_path, cfg_rec_save_path_cmd,
127 "storage-path PATH",
128 "Configure the directory for storing recordings\n"
129 "Directory to which recordings are stored\n")
130{
131 osmo_talloc_replace_string(NULL, &g_recorder.storage_path, argv[0]);
132 return CMD_SUCCESS;
133}
134
135DEFUN(cfg_rec_file_size, cfg_rec_file_size_cmd,
136 "file-size-mb <1-9999999>",
137 "Configure the maximum file size before starting new file\n"
138 "Megabytes\n")
139{
140 g_recorder.max_file_size_mb = atoi(argv[0]);
141 return CMD_SUCCESS;
142}
143
144static void config_write_recorder_line(struct vty *vty, unsigned int lnr)
145{
146 struct e1inp_line *line = e1inp_line_find(lnr);
147 struct e1_recorder_line *rline = &g_recorder.line[lnr];
148 unsigned int i;
149
150 if (rline->mirror.enabled) {
151 vty_out(vty, " line %u mirror %u%s",
152 lnr, rline->mirror.line_nr, VTY_NEWLINE);
153 }
154
155 if (!line)
156 return;
157
158 for (i = 0; i < line->num_ts; i++) {
159 struct e1inp_ts *ts = &line->ts[i];
160 }
161}
162
163static int config_write_recorder(struct vty *vty)
164{
165 unsigned int i;
166
167 vty_out(vty, "recorder%s", VTY_NEWLINE);
168 vty_out(vty, " file-size-mb %u%s", g_recorder.max_file_size_mb,
169 VTY_NEWLINE);
170 vty_out(vty, " storage-path %s%s", g_recorder.storage_path,
171 VTY_NEWLINE);
172 for (i = 0; i < 255; i++) {
173 config_write_recorder_line(vty, i);
174 }
175
176 return 0;
177}
178
179static struct cmd_node cfg_recorder_node = {
180 RECORDER_NODE,
181 "%s(config-recorder)# ",
182 1,
183};
184
185void recorder_vty_init(void)
186{
187 install_element(CONFIG_NODE, &cfg_recorder_cmd);
188
189 install_node(&cfg_recorder_node, config_write_recorder);
190 install_element(RECORDER_NODE, &cfg_rec_line_ts_mode_cmd);
191 install_element(RECORDER_NODE, &cfg_rec_line_mirror_cmd);
192 install_element(RECORDER_NODE, &cfg_rec_no_line_mirror_cmd);
193 install_element(RECORDER_NODE, &cfg_rec_save_path_cmd);
194 install_element(RECORDER_NODE, &cfg_rec_file_size_cmd);
195}