aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/wimax/msg_arq.c
blob: 488aa0786bd2c4d00733632ac3234a6aabefddf8 (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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
/* msg_arq.c
 * WiMax MAC Management ARQ Feedback, Discard, Reset Message decoders
 *
 * Copyright (c) 2007 by Intel Corporation.
 *
 * Author: John R. Underwood <junderx@yahoo.com>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1999 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* Include files */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "moduleinfo.h"

#include <gmodule.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include "crc.h"
#include "wimax_tlv.h"
#include "wimax_mac.h"

extern gint man_ofdma;

/* Forward reference */
void dissect_mac_mgmt_msg_arq_feedback_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
void dissect_mac_mgmt_msg_arq_discard_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
void dissect_mac_mgmt_msg_arq_reset_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);

static gint proto_mac_mgmt_msg_arq_feedback_decoder = -1;
static gint proto_mac_mgmt_msg_arq_discard_decoder = -1;
static gint proto_mac_mgmt_msg_arq_reset_decoder = -1;

static gint ett_mac_mgmt_msg_arq_decoder = -1;

/* Setup protocol subtree array */
static gint *ett[] =
{
	&ett_mac_mgmt_msg_arq_decoder,
};


/* ARQ fields */
static gint hf_arq_cid			= -1;
static gint hf_arq_last			= -1;
static gint hf_arq_ack_type		= -1;
static gint hf_ack_type_reserved	= -1;
static gint hf_arq_bsn			= -1;
static gint hf_arq_num_ack_maps		= -1;
static gint hf_arq_selective_map	= -1;
static gint hf_arq_seq_format		= -1;
static gint hf_arq_0seq_ack_map		= -1;
static gint hf_arq_0seq1_len		= -1;
static gint hf_arq_0seq2_len		= -1;
static gint hf_arq_1seq_ack_map		= -1;
static gint hf_arq_1seq1_len		= -1;
static gint hf_arq_1seq2_len		= -1;
static gint hf_arq_1seq3_len		= -1;
static gint hf_arq_reserved		= -1;

static gint hf_arq_discard_cid		= -1;
static gint hf_arq_discard_reserved	= -1;
static gint hf_arq_discard_bsn		= -1;

static gint hf_arq_reset_cid		= -1;
static gint hf_arq_reset_type		= -1;
static gint hf_arq_reset_direction	= -1;
static gint hf_arq_reset_reserved	= -1;

static gint hf_arq_message_type = -1;

/* STRING RESOURCES */

static const true_false_string tfs_present = {
	"present",
	"absent"
};

static const true_false_string tfs_rng_req_aas_broadcast = {
	"SS cannot receive broadcast messages",
	"SS can receive broadcast messages"
};

static const true_false_string tfs_arq_last = {
	"Last ARQ feedback IE in the list",
	"More ARQ feedback IE in the list"
};

static const value_string vals_arq_ack_type[] = {
	{0,				"Selective ACK entry"},
	{1,				"Cumulative ACK entry"},
	{2,				"Cumulative with Selective ACK entry"},
	{3,				"Cumulative ACK with Block Sequence Ack entry"},
	{0,				NULL}
};

static const value_string vals_arq_reset_type[] = {
	{0,				"Original message from Initiator"},
	{1,				"Acknowledgment from Responder"},
	{2,				"Confirmation from Initiator"},
	{3,				"Reserved"},
	{0,				NULL}
};

static const value_string vals_arq_reset_direction[] = {
	{0,				"Uplink or downlink"},
	{1,				"Uplink"},
	{2,				"Downlink"},
	{3,				"Reserved"},
	{0,				NULL}
};

/* ARQ fields display */
static hf_register_info hf[] =
{
	/* TODO: Make three separate arq message types */
	{
		&hf_arq_message_type,
		{
			"MAC Management Message Type", "wimax.macmgtmsgtype.arq",
			FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL
		}
	},
	{
		&hf_arq_ack_type,
		{
			"ACK Type", "wimax.arq.ack_type", 
			FT_UINT8, BASE_DEC, VALS(vals_arq_ack_type), 0x60, "", HFILL
		}
	},
	{
		&hf_arq_bsn,
		{
			"BSN", "wimax.arq.bsn", 
			FT_UINT16, BASE_DEC, NULL, 0x1FFC, "", HFILL
		}
	},
	{
		&hf_arq_cid,
		{
			"Connection ID", "wimax.arq.cid", 
			FT_UINT16, BASE_DEC, NULL, 0x00, "The ID of the connection being referenced", HFILL
		}
	},
	{
		&hf_arq_discard_bsn,
		{
			"BSN", "wimax.arq.discard_bsn", 
			FT_UINT16, BASE_DEC, NULL, 0x07FF, "", HFILL
		}
	},
	{
		&hf_arq_discard_cid,
		{
			"Connection ID", "wimax.arq.discard_cid", 
			FT_UINT16, BASE_DEC, NULL, 0x00, "", HFILL
		}
	},
	{
		&hf_arq_discard_reserved,
		{
			"Reserved", "wimax.arq.discard_reserved", 
			FT_UINT8, BASE_DEC, NULL, 0xF8, "", HFILL
		}
	},
	{
		&hf_arq_last,
		{
			"LAST", "wimax.arq.last", 
			FT_BOOLEAN, 8, TFS(&tfs_arq_last), 0x80, "", HFILL
		}
	},
	{
		&hf_arq_num_ack_maps,
		{
			"Number of ACK Maps", "wimax.arq.num_maps", 
			FT_UINT8, BASE_DEC, NULL, 0x03, "", HFILL
		}
	},
	{
		&hf_arq_reserved,
		{
			"Reserved", "wimax.arq.reserved", 
			FT_UINT8, BASE_DEC, NULL, 0x01, "", HFILL
		}
	},
	{
		&hf_arq_reset_cid,
		{
			"Connection ID", "wimax.arq.reset_cid", 
			FT_UINT16, BASE_DEC, NULL, 0x00, "", HFILL
		}
	},
	{
		&hf_arq_reset_direction,
		{
			"Direction", "wimax.arq.reset_direction", 
			FT_UINT8, BASE_DEC, VALS(vals_arq_reset_direction), 0x30, "", HFILL
		}
	},
	{
		&hf_arq_reset_reserved,
		{
			"Reserved", "wimax.arq.reset_reserved", 
			FT_UINT8, BASE_DEC, NULL, 0x0F, "", HFILL
		}
	},
	{
		&hf_arq_reset_type,
		{
			"Type", "wimax.arq.reset_type", 
			FT_UINT8, BASE_DEC, VALS(vals_arq_reset_type), 0xC0, "", HFILL
		}
	},
	{
		&hf_arq_selective_map,
		{
			"Selective ACK Map", "wimax.arq.selective_map", 
			FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL
		}
	},
	{
		&hf_arq_0seq_ack_map,
		{
			"Sequence ACK Map", "wimax.arq.seq_ack_map", 
			FT_UINT8, BASE_HEX, NULL, 0x60, "", HFILL
		}
	},
	{
		&hf_arq_1seq_ack_map,
		{
			"Sequence ACK Map", "wimax.arq.seq_ack_map", 
			FT_UINT8, BASE_HEX, NULL, 0x70, "", HFILL
		}
	},
	{
		&hf_arq_seq_format,
		{
			"Sequence Format", "wimax.arq.seq_format", 
			FT_UINT8, BASE_DEC, NULL, 0x80, "", HFILL
		}
	},
	{
		&hf_arq_0seq1_len,
		{
			"Sequence 1 Length", "wimax.arq.seq1_len", 
			FT_UINT16, BASE_DEC, NULL, 0x1F80, "", HFILL
		}
	},
	{
		&hf_arq_0seq2_len,
		{
			"Sequence 2 Length", "wimax.arq.seq2_len", 
			FT_UINT16, BASE_DEC, NULL, 0x007E, "", HFILL
		}
	},
	{
		&hf_arq_1seq1_len,
		{
			"Sequence 1 Length", "wimax.arq.seq1_len", 
			FT_UINT8, BASE_DEC, NULL, 0x0F, "", HFILL
		}
	},
	{
		&hf_arq_1seq2_len,
		{
			"Sequence 2 Length", "wimax.arq.seq2_len", 
			FT_UINT8, BASE_DEC, NULL, 0xF0, "", HFILL
		}
	},
	{
		&hf_arq_1seq3_len,
		{
			"Sequence 3 Length", "wimax.arq.seq3_len", 
			FT_UINT8, BASE_DEC, NULL, 0x0F, "", HFILL
		}
	},
	{
		&hf_ack_type_reserved,
		{
			"Reserved", "wimax.ack_type.reserved", 
			FT_UINT8, BASE_DEC, NULL, 0x03, "", HFILL
		}
	}
};

/* Register Wimax Mac Payload Protocol and Dissector */
void proto_register_mac_mgmt_msg_arq_feedback(void)
{
	if (proto_mac_mgmt_msg_arq_feedback_decoder == -1)
	{
		proto_mac_mgmt_msg_arq_feedback_decoder = proto_register_protocol (
							"WiMax ARQ Feedback/Discard/Reset Messages", /* name */
							"WiMax ARQ Feedback/Discard/Reset (arq)", /* short name */
							"arq" /* abbrev */
							);

		proto_register_field_array(proto_mac_mgmt_msg_arq_feedback_decoder, hf, array_length(hf));
		proto_register_subtree_array(ett, array_length(ett));
	}
}

/* Register Wimax Mac Payload Protocol and Dissector */
void proto_register_mac_mgmt_msg_arq_discard(void)
{
	if (proto_mac_mgmt_msg_arq_discard_decoder == -1)
	{
		proto_mac_mgmt_msg_arq_discard_decoder = proto_mac_mgmt_msg_arq_feedback_decoder;

		proto_register_subtree_array(ett, array_length(ett));
	}
}

/* Register Wimax Mac Payload Protocol and Dissector */
void proto_register_mac_mgmt_msg_arq_reset(void)
{
	if (proto_mac_mgmt_msg_arq_reset_decoder == -1)
	{
		proto_mac_mgmt_msg_arq_reset_decoder = proto_mac_mgmt_msg_arq_feedback_decoder;

		proto_register_subtree_array(ett, array_length(ett));
	}
}

/* Decode ARQ-Feedback messages. */
void dissect_mac_mgmt_msg_arq_feedback_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint offset = 0;
	guint arq_feedback_ie_count = 0;
	guint arq_cid;
	gboolean arq_last = FALSE;
	guint arq_ack_type;
	guint arq_bsn;
	guint arq_num_ack_maps;
	guint tvb_len, payload_type;
	proto_item *arq_feedback_item = NULL;
	proto_tree *arq_feedback_tree = NULL;
	proto_item *arq_fb_item = NULL;
	proto_tree *arq_fb_tree = NULL;
	proto_item *ti = NULL;
	guint i, seq_format;

	/* Ensure the right payload type */
	payload_type = tvb_get_guint8(tvb, offset);
	if(payload_type != MAC_MGMT_MSG_ARQ_FEEDBACK)
	{
		return;
	}

	if (tree)
	{	/* we are being asked for details */

		/* Get the tvb length */
		tvb_len =  tvb_length(tvb);
		/* display MAC payload type ARQ-Feedback */
		arq_feedback_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_arq_feedback_decoder, tvb, offset, tvb_len, "MAC Management Message, ARQ-Feedback (33)");
		/* add MAC ARQ Feedback subtree */
		arq_feedback_tree = proto_item_add_subtree(arq_feedback_item, ett_mac_mgmt_msg_arq_decoder);
		/* display the Message Type */
		proto_tree_add_item(arq_feedback_tree, hf_arq_message_type, tvb, offset, 1, FALSE);
		offset += 1;

		while(offset < tvb_len && !arq_last)
		{
			arq_feedback_ie_count++;
			arq_cid = tvb_get_ntohs(tvb, offset);
			arq_last = ((tvb_get_guint8(tvb, offset + 2) & 0x80) != 0);
			arq_ack_type = (tvb_get_guint8(tvb, offset + 2) & 0x60) >> 5;
			arq_bsn = (tvb_get_ntohs(tvb, offset + 2) & 0x1FFC) >> 2;
			arq_num_ack_maps = 1 + (tvb_get_guint8(tvb, offset + 3) & 0x03);

			arq_fb_item = proto_tree_add_protocol_format(arq_feedback_tree, proto_mac_mgmt_msg_arq_feedback_decoder, tvb, offset, tvb_len, "ARQ_Feedback_IE");
			proto_item_append_text(arq_fb_item, ", CID: %u, %s ARQ feedback IE, %s, BSN: %u",
				arq_cid, arq_last ? "Last" : "More", val_to_str(arq_ack_type, vals_arq_ack_type, ""), arq_bsn);
			if (arq_ack_type != ARQ_CUMULATIVE_ACK_ENTRY) {
				proto_item_append_text(arq_fb_item, ", %u ACK Map(s)", arq_num_ack_maps);
			}
			/* add ARQ Feedback IE subtree */
			arq_fb_tree = proto_item_add_subtree(arq_fb_item, ett_mac_mgmt_msg_arq_decoder);
			proto_tree_add_item(arq_fb_tree, hf_arq_cid, tvb, offset, 2, FALSE);
			proto_tree_add_item(arq_fb_tree, hf_arq_last, tvb, offset + 2, 1, FALSE);
			proto_tree_add_item(arq_fb_tree, hf_arq_ack_type, tvb, offset + 2, 1, FALSE);
			proto_tree_add_item(arq_fb_tree, hf_arq_bsn, tvb, offset + 2, 2, FALSE);
			if (arq_ack_type != ARQ_CUMULATIVE_ACK_ENTRY) {
				ti = proto_tree_add_item(arq_fb_tree, hf_arq_num_ack_maps, tvb, offset + 3, 1, FALSE);
				proto_item_append_text(ti, " (%d map(s))", arq_num_ack_maps);
				offset += 2;

				for (i = 0; i < arq_num_ack_maps; i++) {
					/* Each ACK Map is 16 bits. */
					offset += 2;
					if (arq_ack_type != 3) {
						proto_tree_add_item(arq_fb_tree, hf_arq_selective_map, tvb, offset, 2, FALSE);
					} else {
						proto_tree_add_item(arq_fb_tree, hf_arq_seq_format, tvb, offset, 1, FALSE);
						seq_format = (tvb_get_guint8(tvb, offset) & 0x80) >> 7;
						if (seq_format == 0) {
							proto_tree_add_item(arq_fb_tree, hf_arq_0seq_ack_map, tvb, offset, 1, FALSE);
							proto_tree_add_item(arq_fb_tree, hf_arq_0seq1_len, tvb, offset, 2, FALSE);
							proto_tree_add_item(arq_fb_tree, hf_arq_0seq2_len, tvb, offset, 2, FALSE);
							proto_tree_add_item(arq_fb_tree, hf_arq_reserved, tvb, offset + 1, 1, FALSE);
						} else {
							proto_tree_add_item(arq_fb_tree, hf_arq_1seq_ack_map, tvb, offset, 1, FALSE);
							proto_tree_add_item(arq_fb_tree, hf_arq_1seq1_len, tvb, offset, 1, FALSE);
							proto_tree_add_item(arq_fb_tree, hf_arq_1seq2_len, tvb, offset + 1, 1, FALSE);
							proto_tree_add_item(arq_fb_tree, hf_arq_1seq3_len, tvb, offset + 1, 1, FALSE);
						}
					}
				}
			} else {
				/* Number of ACK Maps bits are reserved when ACK TYPE == 1 */
				proto_tree_add_item(arq_fb_tree, hf_ack_type_reserved, tvb, offset + 3, 1, FALSE);
				/* update the offset */
				offset += 2;
			}
			/* update the offset */
			offset += 2;
		}
		proto_item_append_text(arq_feedback_item, ", %u ARQ_feedback_IE(s)", arq_feedback_ie_count);
	}
}

/* Decode ARQ-Discard messages. */
void dissect_mac_mgmt_msg_arq_discard_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint tvb_len, payload_type;
	proto_item *arq_discard_item = NULL;
	proto_tree *arq_discard_tree = NULL;

	/* Ensure the right payload type */
	payload_type = tvb_get_guint8(tvb, 0);
	if(payload_type != MAC_MGMT_MSG_ARQ_DISCARD)
	{
		return;
	}

	if (tree)
	{	/* we are being asked for details */

		/* Get the tvb length */
		tvb_len =  tvb_length(tvb);
		/* display MAC payload type ARQ-Discard */
		arq_discard_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_arq_discard_decoder, tvb, 0, tvb_len, "MAC Management Message, ARQ-Discard (34)");
		/* add MAC ARQ Discard subtree */
		arq_discard_tree = proto_item_add_subtree(arq_discard_item, ett_mac_mgmt_msg_arq_decoder);
		/* display the Message Type */
		proto_tree_add_item(arq_discard_tree, hf_arq_message_type, tvb, 0, 1, FALSE);

		proto_tree_add_item(arq_discard_tree, hf_arq_discard_cid, tvb, 1, 2, FALSE);
		proto_tree_add_item(arq_discard_tree, hf_arq_discard_reserved, tvb, 3, 1, FALSE);
		proto_tree_add_item(arq_discard_tree, hf_arq_discard_bsn, tvb, 3, 2, FALSE);
	}
}

/* Decode ARQ-Reset messages. */
void dissect_mac_mgmt_msg_arq_reset_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint tvb_len, payload_type;
	proto_item *arq_reset_item = NULL;
	proto_tree *arq_reset_tree = NULL;

	/* Ensure the right payload type */
	payload_type = tvb_get_guint8(tvb, 0);
	if(payload_type != MAC_MGMT_MSG_ARQ_RESET)
	{
		return;
	}

	if (tree)
	{	/* we are being asked for details */

		/* Get the tvb length */
		tvb_len =  tvb_length(tvb);
		/* display MAC payload type ARQ-Reset */
		arq_reset_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_arq_reset_decoder, tvb, 0, tvb_len, "MAC Management Message, ARQ-Reset (35)");
		/* add MAC ARQ Reset subtree */
		arq_reset_tree = proto_item_add_subtree(arq_reset_item, ett_mac_mgmt_msg_arq_decoder);
		/* display the Message Type */
		proto_tree_add_item(arq_reset_tree, hf_arq_message_type, tvb, 0, 1, FALSE);

		proto_tree_add_item(arq_reset_tree, hf_arq_reset_cid, tvb, 1, 2, FALSE);
		proto_tree_add_item(arq_reset_tree, hf_arq_reset_type, tvb, 3, 1, FALSE);
		proto_tree_add_item(arq_reset_tree, hf_arq_reset_direction, tvb, 3, 1, FALSE);
		proto_tree_add_item(arq_reset_tree, hf_arq_reset_reserved, tvb, 3, 1, FALSE);
	}
}