dev: mark paths likely/unlikely
[netsniff-ng.git] / staging / cli_rtp.c
blob28a6c2bf63f8cd187012098c2a49cd3d2543e0c1
1 /*
2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 * details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
21 #include "mz.h"
22 #include "cli.h"
23 #include "mops.h"
26 int cmd_rtp_version (struct cli_def *cli, const char *command, char *argv[], int argc)
28 struct mops_ext_rtp * pd = clipkt->p_desc;
29 int v=2;
31 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
32 cli_print(cli, "Set the RTP version (0..3, default: v2).\n");
33 return CLI_OK;
35 if (mz_strisnum(argv[0])==0) {
36 cli_print(cli, "Invalid number.\n");
37 return CLI_OK;
39 v = (int) str2int(argv[0]);
40 if (v>3) {
41 cli_print(cli, "Range exceeded (0..3).\n");
42 return CLI_OK;
44 pd->v = v;
45 return CLI_OK;
48 int cmd_rtp_padding (struct cli_def *cli, const char *command, char *argv[], int argc)
50 struct mops_ext_rtp * pd = clipkt->p_desc;
51 char state[8];
53 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
54 cli_print(cli, "Sets or unsets the RTP padding flag (default: disabled).\n");
55 cli_print(cli, "Use the keywords 'set' or 'unset'.\n");
56 sprintf(state, "%s", (pd->p) ? "SET" : "UNSET");
57 cli_print(cli, "Current state of the padding flag: %s\n",state);
58 return CLI_OK;
61 if (mz_strcmp(argv[0], "set", 1)==0) {
62 pd->p = 1;
63 } else if (mz_strcmp(argv[0], "unset", 1)==0) {
64 pd->p = 0;
66 else {
67 cli_print(cli, "Invalid keyword. Use 'set' or 'unset'.\n");
70 return CLI_OK;
73 int cmd_rtp_xten (struct cli_def *cli, const char *command, char *argv[], int argc)
75 struct mops_ext_rtp * pd = clipkt->p_desc;
76 char state[8];
78 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
79 cli_print(cli, "Sets or unsets the RTP extension flag (default: disabled).\n");
80 cli_print(cli, "NOTE: This command only sets the extension flag in the RTP header.\r");
81 cli_print(cli, "If you really want an extension header use the 'extension' command.\n");
82 cli_print(cli, "Use the keywords 'set' or 'unset'.\n");
83 sprintf(state, "%s", (pd->x) ? "SET" : "UNSET");
84 cli_print(cli, "Current state of the extension flag: %s\n",state);
85 return CLI_OK;
88 if (mz_strcmp(argv[0], "set", 1)==0) {
89 pd->x = 1;
90 } else if (mz_strcmp(argv[0], "unset", 1)==0) {
91 pd->x = 0;
93 else {
94 cli_print(cli, "Invalid keyword. Use 'set' or 'unset'.\n");
97 return CLI_OK;
101 int cmd_rtp_marker (struct cli_def *cli, const char *command, char *argv[], int argc)
103 struct mops_ext_rtp * pd = clipkt->p_desc;
104 char state[8];
106 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
107 cli_print(cli, "Sets or unsets the RTP marker flag (default: disabled).\n");
108 cli_print(cli, "Use the keywords 'set' or 'unset'.\n");
109 sprintf(state, "%s", (pd->m) ? "SET" : "UNSET");
110 cli_print(cli, "Current state of the marker flag: %s\n",state);
111 return CLI_OK;
113 if (mz_strcmp(argv[0], "set", 1)==0) {
114 pd->m = 1;
115 } else if (mz_strcmp(argv[0], "unset", 1)==0) {
116 pd->m = 0;
118 else {
119 cli_print(cli, "Invalid keyword. Use 'set' or 'unset'.\n");
121 return CLI_OK;
125 int cmd_rtp_cc (struct cli_def *cli, const char *command, char *argv[], int argc)
127 struct mops_ext_rtp * pd = clipkt->p_desc;
128 int cc=0;
130 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
131 cli_print(cli, "Configure the RTP CSRC count (0..15, default: 0).\n");
132 cli_print(cli, "NOTE: This command only configures the CSRC value in the RTP header.\r");
133 cli_print(cli, "If you want to add a valid CSRC list use the 'csrc-list' command.\r");
134 cli_print(cli, "The main purpose of this command is to create an invalid RTP packet.\r");
135 return CLI_OK;
137 if (mz_strisnum(argv[0])==0) {
138 cli_print(cli, "Invalid number.\n");
139 return CLI_OK;
141 cc = (int) str2int(argv[0]);
142 if (cc>15) {
143 cli_print(cli, "Range exceeded (0..15).\n");
144 return CLI_OK;
146 pd->cc = cc;
147 return CLI_OK;
151 int cmd_rtp_pt (struct cli_def *cli, const char *command, char *argv[], int argc)
153 struct mops_ext_rtp * pd = clipkt->p_desc;
154 int pt=0;
156 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
157 cli_print(cli, "Configure the RTP payload type (0..127, default: 8 (G.711, A-law)).\n");
158 // TODO: provide a list with well-known PT values
159 return CLI_OK;
161 if (mz_strisnum(argv[0])==0) {
162 cli_print(cli, "Invalid number.\n");
163 return CLI_OK;
165 pt = (int) str2int(argv[0]);
166 if (pt>127) {
167 cli_print(cli, "Range exceeded (0..127).\n");
168 return CLI_OK;
170 pd->pt = pt;
171 return CLI_OK;
174 int cmd_rtp_ssrc (struct cli_def *cli, const char *command, char *argv[], int argc)
176 struct mops_ext_rtp * pd = clipkt->p_desc;
177 unsigned long long int ssrc = 0xcafefeed;
179 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
180 cli_print(cli, "Configure the RTP SSRC (source identifier) (0..ffffffff, default: random!).\n");
181 cli_print(cli, "NOTE: The SSRC value is used by another Mausezahn receiver to identify a original\r");
182 cli_print(cli, "Mausezahn RTP stream. By default, Mausezahn receivers check for the magic number\r");
183 cli_print(cli, "'cafebabe' (hex). Use another number for another RTP stream (e. g. bidirectional\r");
184 cli_print(cli, "measurements).\n");
185 return CLI_OK;
188 if (mz_strishex(argv[0])==0) {
189 cli_print(cli, "Invalid number.\n");
190 return CLI_OK;
193 ssrc = xstr2lint(argv[0]);
194 if (ssrc>0xffffffff) {
195 cli_print(cli, "Range exceeded (0..ffffffff).\n");
196 return CLI_OK;
198 pd->ssrc = (u_int32_t) ssrc;
199 return CLI_OK;
203 int cmd_rtp_sqnr (struct cli_def *cli, const char *command, char *argv[], int argc)
205 struct mops_ext_rtp * pd = clipkt->p_desc;
206 unsigned long long int sqnr = 0;
208 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
209 cli_print(cli, "Configure the RTP initial sequence number (0..ffffffff, default: 0).\n");
210 return CLI_OK;
213 if (mz_strishex(argv[0])==0) {
214 cli_print(cli, "Invalid number.\n");
215 return CLI_OK;
217 sqnr = xstr2lint(argv[0]);
218 if (sqnr>0xffffffff) {
219 cli_print(cli, "Range exceeded (0..ffffffff).\n");
220 return CLI_OK;
222 pd->sqnr = (u_int32_t) sqnr;
223 return CLI_OK;
227 int cmd_rtp_time (struct cli_def *cli, const char *command, char *argv[], int argc)
229 struct mops_ext_rtp * pd = clipkt->p_desc;
230 unsigned long long int t = 0;
232 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
233 cli_print(cli, "Configure the RTP initial timestamp (0..ffffffff, default: 0).\n");
234 return CLI_OK;
237 if (mz_strishex(argv[0])==0) {
238 cli_print(cli, "Invalid number.\n");
239 return CLI_OK;
241 t = xstr2lint(argv[0]);
242 if (t>0xffffffff) {
243 cli_print(cli, "Range exceeded (0..ffffffff).\n");
244 return CLI_OK;
246 pd->tst = (u_int32_t) t;
247 return CLI_OK;
251 int cmd_rtp_extension (struct cli_def *cli, const char *command, char *argv[], int argc)
253 struct mops_ext_rtp * pd = clipkt->p_desc;
255 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
256 cli_print(cli, "Configure an RTP extension header (default: none).\n");
257 cli_print(cli, "Currently supported RTP extension headers:\n");
258 cli_print(cli, "none Don't use any extension.\r");
259 cli_print(cli, "mausezahn Use the new Mausezahn jitter/RTT measurement extension.\r");
260 cli_print(cli, " (Note that this is incompatible with Mausezahn's direct\r");
261 cli_print(cli, " mode jitter measurement.)\r");
262 cli_print(cli, "\n");
263 return CLI_OK;
266 if (mz_strcmp(argv[0], "none", 1)==0) {
267 pd->x_type = 0;
268 pd->x = 0; // X bit in header
269 } else if (mz_strcmp(argv[0], "mausezahn", 1)==0) {
270 pd->x_type = 42;
271 pd->x = 1; // X bit in header
272 pd->ssrc = 0xcafefeed;
273 } else {
274 cli_print(cli, "Unknown keyword.\n");
275 return CLI_OK;
279 mops_update_rtp (clipkt); // re-build RTP packet (for proper show commands)
280 return CLI_OK;
285 int cmd_rtp_source (struct cli_def *cli, const char *command, char *argv[], int argc)
287 // struct mops_ext_rtp * pd = clipkt->p_desc;
289 if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
290 cli_print(cli, "Specify a RTP media source.\n");
291 return CLI_OK;
294 // [TODO] -- Allow to use /dev/dsp or a mixer source ...
296 cli_print(cli, "Currently not supported.\n");
298 return CLI_OK;
302 int cmd_rtp_cclist (struct cli_def *cli, const char *command, char *argv[], int argc)
304 struct mops_ext_rtp * pd = clipkt->p_desc;
305 unsigned long long int csrc=0;
306 char str[80];
307 int i=0, n=0;
310 if ((strcmp(argv[argc-1],"?")==0) || (argc==0)) {
311 cli_print(cli, "Specify a CSRC list consisting of 1-15 CSRC values.\r");
312 cli_print(cli, "Each CSRC is a 4-byte value and must be specified in hexadecimal notation,\r");
313 cli_print(cli, "hence each value must be within 0..ffffffff.\n");
314 return CLI_OK;
317 if ((n=argc)>15) {
318 cli_print(cli, "The CSRC list must not exceed 15 items!\n");
319 return CLI_OK;
322 for (i=0; i<n; i++) {
323 if (mz_strishex(argv[i])==0) {
324 sprintf(str, "Parameter %i: Invalid number!", i);
325 cli_print(cli, "%s\n", str);
326 return CLI_OK;
328 csrc = xstr2lint(argv[i]);
329 if (csrc>0xffffffff) {
330 sprintf(str, "Parameter %i: Range exceeded (0..ffffffff)", i);
331 cli_print(cli, "%s\n", str);
332 return CLI_OK;
334 pd->csrc[i] = (u_int32_t) csrc;
336 pd->cc = n; // this one can be accessed and modified to "wrong" values by the user
337 pd->cc_real = n;
339 return CLI_OK;