summaryrefslogtreecommitdiff
path: root/staging/cli_rtp.c
blob: 28a6c2bf63f8cd187012098c2a49cd3d2543e0c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
 * Mausezahn - A fast versatile traffic generator
 * Copyright (C) 2008-2010 Herbert Haas
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the 
 * Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with 
 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
 * 
*/



#include "mz.h"
#include "cli.h"
#include "mops.h"


int cmd_rtp_version (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	int v=2;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Set the RTP version (0..3, default: v2).\n");
		return CLI_OK;
	}
	if (mz_strisnum(argv[0])==0) {
		cli_print(cli, "Invalid number.\n");
		return CLI_OK;
	}
	v = (int) str2int(argv[0]);
	if (v>3) {
		cli_print(cli, "Range exceeded (0..3).\n");
		return CLI_OK;
	}
	pd->v = v;
	return CLI_OK;
}

int cmd_rtp_padding (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	char state[8];

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Sets or unsets the RTP padding flag (default: disabled).\n");
		cli_print(cli, "Use the keywords 'set' or 'unset'.\n");
		sprintf(state, "%s", (pd->p) ? "SET" : "UNSET");
		cli_print(cli, "Current state of the padding flag: %s\n",state);
		return CLI_OK;
	}
	
	if (mz_strcmp(argv[0], "set", 1)==0) {
		pd->p = 1;
	} else 	if (mz_strcmp(argv[0], "unset", 1)==0) {
		pd->p = 0;
	}
	else {
		cli_print(cli, "Invalid keyword. Use 'set' or 'unset'.\n");
	}
		
	return CLI_OK;
}

int cmd_rtp_xten (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	char state[8];

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Sets or unsets the RTP extension flag (default: disabled).\n");
		cli_print(cli, "NOTE: This command only sets the extension flag in the RTP header.\r");
		cli_print(cli, "If you really want an extension header use the 'extension' command.\n");
		cli_print(cli, "Use the keywords 'set' or 'unset'.\n");
		sprintf(state, "%s", (pd->x) ? "SET" : "UNSET");
		cli_print(cli, "Current state of the extension flag: %s\n",state);
		return CLI_OK;
	}
	
	if (mz_strcmp(argv[0], "set", 1)==0) {
		pd->x = 1;
	} else 	if (mz_strcmp(argv[0], "unset", 1)==0) {
		pd->x = 0;
	}
	else {
		cli_print(cli, "Invalid keyword. Use 'set' or 'unset'.\n");
	}
		
	return CLI_OK;
}


int cmd_rtp_marker (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	char state[8];

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Sets or unsets the RTP marker flag (default: disabled).\n");
		cli_print(cli, "Use the keywords 'set' or 'unset'.\n");
		sprintf(state, "%s", (pd->m) ? "SET" : "UNSET");
		cli_print(cli, "Current state of the marker flag: %s\n",state);
		return CLI_OK;
	}
	if (mz_strcmp(argv[0], "set", 1)==0) {
		pd->m = 1;
	} else 	if (mz_strcmp(argv[0], "unset", 1)==0) {
		pd->m = 0;
	}
	else {
		cli_print(cli, "Invalid keyword. Use 'set' or 'unset'.\n");
	}
	return CLI_OK;
}


int cmd_rtp_cc (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	int cc=0;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Configure the RTP CSRC count (0..15, default: 0).\n");
		cli_print(cli, "NOTE: This command only configures the CSRC value in the RTP header.\r");
		cli_print(cli, "If you want to add a valid CSRC list use the 'csrc-list' command.\r");
		cli_print(cli, "The main purpose of this command is to create an invalid RTP packet.\r");
		return CLI_OK;
	}
	if (mz_strisnum(argv[0])==0) {
		cli_print(cli, "Invalid number.\n");
		return CLI_OK;
	}
	cc = (int) str2int(argv[0]);
	if (cc>15) {
		cli_print(cli, "Range exceeded (0..15).\n");
		return CLI_OK;
	}
	pd->cc = cc;
	return CLI_OK;
}


int cmd_rtp_pt (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	int pt=0;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Configure the RTP payload type (0..127, default: 8 (G.711, A-law)).\n");
		// TODO: provide a list with well-known PT values
		return CLI_OK;
	}
	if (mz_strisnum(argv[0])==0) {
		cli_print(cli, "Invalid number.\n");
		return CLI_OK;
	}
	pt = (int) str2int(argv[0]);
	if (pt>127) {
		cli_print(cli, "Range exceeded (0..127).\n");
		return CLI_OK;
	}
	pd->pt = pt;
	return CLI_OK;
}

int cmd_rtp_ssrc (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	unsigned long long int ssrc = 0xcafefeed;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Configure the RTP SSRC (source identifier) (0..ffffffff, default: random!).\n");
		cli_print(cli, "NOTE: The SSRC value is used by another Mausezahn receiver to identify a original\r");
		cli_print(cli, "Mausezahn RTP stream. By default, Mausezahn receivers check for the magic number\r");
		cli_print(cli, "'cafebabe' (hex). Use another number for another RTP stream (e. g. bidirectional\r");
		cli_print(cli, "measurements).\n");
		return CLI_OK;
	}
	
	if (mz_strishex(argv[0])==0) {
		cli_print(cli, "Invalid number.\n");
		return CLI_OK;
	}
	
	ssrc =  xstr2lint(argv[0]);
	if (ssrc>0xffffffff) {
		cli_print(cli, "Range exceeded (0..ffffffff).\n");
		return CLI_OK;
	}
	pd->ssrc = (u_int32_t) ssrc;
	return CLI_OK;
}


int cmd_rtp_sqnr (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	unsigned long long int sqnr = 0;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Configure the RTP initial sequence number (0..ffffffff, default: 0).\n");
		return CLI_OK;
	}
	
	if (mz_strishex(argv[0])==0) {
		cli_print(cli, "Invalid number.\n");
		return CLI_OK;
	}
	sqnr =  xstr2lint(argv[0]);
	if (sqnr>0xffffffff) {
		cli_print(cli, "Range exceeded (0..ffffffff).\n");
		return CLI_OK;
	}
	pd->sqnr = (u_int32_t) sqnr;
	return CLI_OK;
}


int cmd_rtp_time (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	unsigned long long int t = 0;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Configure the RTP initial timestamp (0..ffffffff, default: 0).\n");
		return CLI_OK;
	}
	
	if (mz_strishex(argv[0])==0) {
		cli_print(cli, "Invalid number.\n");
		return CLI_OK;
	}
	t =  xstr2lint(argv[0]);
	if (t>0xffffffff) {
		cli_print(cli, "Range exceeded (0..ffffffff).\n");
		return CLI_OK;
	}
	pd->tst = (u_int32_t) t;
	return CLI_OK;
}


int cmd_rtp_extension (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Configure an RTP extension header (default: none).\n");
		cli_print(cli, "Currently supported RTP extension headers:\n");
		cli_print(cli, "none          Don't use any extension.\r");
		cli_print(cli, "mausezahn     Use the new Mausezahn jitter/RTT measurement extension.\r");
		cli_print(cli, "              (Note that this is incompatible with Mausezahn's direct\r");
		cli_print(cli, "              mode jitter measurement.)\r");
		cli_print(cli, "\n");
		return CLI_OK;
	}

	if (mz_strcmp(argv[0], "none", 1)==0) {
		pd->x_type = 0;
		pd->x = 0; // X bit in header
	} else 	if (mz_strcmp(argv[0], "mausezahn", 1)==0) {
		pd->x_type = 42;
		pd->x = 1; // X bit in header
		pd->ssrc = 0xcafefeed;
	} else {
		cli_print(cli, "Unknown keyword.\n");
		return CLI_OK;
		
	}

	mops_update_rtp (clipkt); // re-build RTP packet (for proper show commands)
	return CLI_OK;
}



int cmd_rtp_source (struct cli_def *cli, const char *command, char *argv[], int argc)
{
//	struct mops_ext_rtp * pd = clipkt->p_desc;

	if ( (strcmp(argv[argc-1],"?")==0) || (argc!=1)) {
		cli_print(cli, "Specify a RTP media source.\n");
		return CLI_OK;
	}
	
	// [TODO] -- Allow to use /dev/dsp or a mixer source ...
	// 
	cli_print(cli, "Currently not supported.\n");
	
	return CLI_OK;
}


int cmd_rtp_cclist (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	struct mops_ext_rtp * pd = clipkt->p_desc;
	unsigned long long int csrc=0;
	char str[80];
	int i=0, n=0;

	
	if ((strcmp(argv[argc-1],"?")==0) || (argc==0)) {
		cli_print(cli, "Specify a CSRC list consisting of 1-15 CSRC values.\r");
		cli_print(cli, "Each CSRC is a 4-byte value and must be specified in hexadecimal notation,\r");
		cli_print(cli, "hence each value must be within 0..ffffffff.\n");
		return CLI_OK;
	}
	
	if ((n=argc)>15) {
		cli_print(cli, "The CSRC list must not exceed 15 items!\n");
		return CLI_OK;
	}
	
	for (i=0; i<n; i++) {
		if (mz_strishex(argv[i])==0) {
			sprintf(str, "Parameter %i: Invalid number!", i);
			cli_print(cli, "%s\n", str);
			return CLI_OK;
		}
		csrc =  xstr2lint(argv[i]);
		if (csrc>0xffffffff) {
			sprintf(str, "Parameter %i: Range exceeded (0..ffffffff)", i);
			cli_print(cli, "%s\n", str);
			return CLI_OK;
		}
		pd->csrc[i] = (u_int32_t) csrc;
	}
	pd->cc = n; // this one can be accessed and modified to "wrong" values by the user
	pd->cc_real = n;
	
	return CLI_OK;
}