File: MDUTrafficStats.c

package info (click to toggle)
open-plc-utils 0.0.6%2Bgit20250517.7fb8ac5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,212 kB
  • sloc: ansic: 60,860; xml: 16,179; sh: 1,216; makefile: 698
file content (454 lines) | stat: -rw-r--r-- 12,272 bytes parent folder | download | duplicates (2)
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
/*====================================================================*
 *
 *   Copyright (c) 2013 Qualcomm Atheros, Inc.
 *
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or
 *   without modification, are permitted (subject to the limitations
 *   in the disclaimer below) provided that the following conditions
 *   are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials
 *     provided with the distribution.
 *
 *   * Neither the name of Qualcomm Atheros nor the names of
 *     its contributors may be used to endorse or promote products
 *     derived from this software without specific prior written
 *     permission.
 *
 *   NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
 *   GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
 *   COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 *   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 *   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 *   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *
 *   signed MDUTrafficStats (struct plc * plc);
 *
 *   plc.h
 *
 *
 *   Contributor(s):
 *      Charles Maier
 *
 *--------------------------------------------------------------------*/

#ifndef MDUTRAFFICSTATS_SOURCE
#define MDUTRAFFICSTATS_SOURCE

#include <stdint.h>
#include <memory.h>

#include "../plc/plc.h"
#include "../tools/flags.h"
#include "../tools/error.h"
#include "../tools/memory.h"

/*====================================================================*
 *   constants;
 *--------------------------------------------------------------------*/

#define CC1_RDRP (1 <<  0)
#define CC1_RJBR (1 <<  1)
#define CC1_RFRG (1 <<  2)
#define CC1_ROVR (1 <<  3)
#define CC1_RUND (1 <<  4)
#define CC1_RCSE (1 <<  5)
#define CC1_RCDE (1 <<  6)
#define CC1_RFLR (1 <<  7)
#define CC1_RALN (1 <<  8)
#define CC1_RXUO (1 <<  9)
#define CC1_RXPF (1 << 10)
#define CC1_RXCF (1 << 11)
#define CC1_RBCA (1 << 12)
#define CC1_RMCA (1 << 13)
#define CC1_RFCS (1 << 14)
#define CC1_RPTK (1 << 15)
#define CC1_TRMGV (1 << 25)
#define CC1_TRMAX (1 << 26)
#define CC1_TR1K (1 << 27)
#define CC1_TR511 (1 << 28)
#define CC1_TR255 (1 << 29)
#define CC1_TR127 (1 << 30)
#define CC1_TR64 (1 << 31)

#define CC2_TDRP (1 <<  0)
#define CC2_TPFH (1 <<  1)
#define CC2_TNCL (1 <<  2)
#define CC2_TXCL (1 <<  3)
#define CC2_TLCL (1 <<  4)
#define CC2_TMCL (1 <<  5)
#define CC2_TSCL (1 <<  6)
#define CC2_TEDF (1 <<  7)
#define CC2_TDFR (1 <<  8)
#define CC2_TXPF (1 <<  9)
#define CC2_TBCA (1 << 10)
#define CC2_TMCA (1 << 11)
#define CC2_TPKT (1 << 12)
#define CC2_TBYT (1 << 13)
#define CC2_TFRG (1 << 14)
#define CC2_TUND (1 << 15)
#define CC2_TOVR (1 << 16)
#define CC2_TXCF (1 << 17)
#define CC2_TFCS (1 << 18)
#define CC2_TJBR (1 << 19)

#define MASTER_TX_RX 	(1 << 0)
#define SLAVE_TX_RX 	(1 << 1)
#define MASTER_FETCH 	(1 << 2)
#define SLAVE_CLEAR 	(1 << 3)
#define ETHERNET_STATS 	(1 << 4)

/*====================================================================*
 *   variables;
 *--------------------------------------------------------------------*/

/*
 *  Station Statistics;
 */

#ifndef __GNUC__
#pragma pack (push,1)
#endif

typedef struct __packed station_stats

{
	uint8_t TEI;
	uint8_t RESULT_CODE;
	uint32_t UPSTREAM_MME_FRAMES;
	uint32_t UPSTREAM_ETH_FRAMES_UNI;
	uint32_t UPSTREAM_ETH_FRAMES_MULTI;
	uint32_t UPSTREAM_ETH_FRAMES_BROAD;
	uint32_t UPSTREAM_DROP_MME_FROM_HOST;
	uint32_t UPSTREAM_DROP_MME_FW_GEN;
	uint32_t UPSTREAM_DROP_ETH_FROM_HOST;
	uint32_t DOWNSTREAM_MME_FRAMES;
	uint32_t DOWNSTREAM_ETH_FRAMES_UNI;
	uint32_t DOWNSTREAM_ETH_FRAMES_MULTI;
	uint32_t DOWNSTREAM_ETH_FRAMES_BROAD;
	uint32_t DOWNSTREAM_DROP_MME_FROM_HOST;
	uint32_t DOWNSTREAM_DROP_MME_FW_GEN;
	uint32_t DOWNSTREAM_DROP_ETH_FROM_HOST;
}

statistics;

#ifndef __GNUC__
#pragma pack (pop)
#endif

/*
 *  Ethernet Statistics;
 */

#ifndef __GNUC__
#pragma pack (push,1)
#endif

typedef struct __packed ethernet_stats

{
	uint16_t HW_MODULE_TYPE;
	uint16_t HW_MODULE_STATS_LEN;
	uint32_t TR64;
	uint32_t TR127;
	uint32_t TR255;
	uint32_t TR511;
	uint32_t TR1K;
	uint32_t TRMAX;
	uint32_t TRMGV;
	uint32_t RBYT;
	uint32_t RBKT;
	uint32_t RFCS;
	uint32_t RFCA;
	uint32_t RBCA;
	uint32_t RXCF;
	uint32_t RXPF;
	uint32_t RXUO;
	uint32_t RALN;
	uint32_t RFLR;
	uint32_t RCDE;
	uint32_t RCSE;
	uint32_t RUND;
	uint32_t ROVR;
	uint32_t RFRG;
	uint32_t RJBR;
	uint32_t RDRP;
	uint32_t TBYT;
	uint32_t TPKT;
	uint32_t TMCA;
	uint32_t TBCA;
	uint32_t TXPF;
	uint32_t TDFR;
	uint32_t TEDF;
	uint32_t TSCL;
	uint32_t TMCL;
	uint32_t TLCL;
	uint32_t TXCL;
	uint32_t TNCL;
	uint32_t TPFH;
	uint32_t TDRP;
	uint32_t TJBR;
	uint32_t TFCS;
	uint32_t TXCF;
	uint32_t TOVR;
	uint32_t TUND;
	uint32_t TFRG;
	uint32_t CARRY1;
	uint32_t CARRY2;
}

ethernet_stats;

#ifndef __GNUC__
#pragma pack (pop)
#endif

/*
 *   Classification Counters
 */

#ifndef __GNUC__
#pragma pack (push,1)
#endif

typedef struct __packed class_counters

{
	uint16_t HW_MODULE_TYPE;
	uint16_t HW_MODULE_STATS_LEN;
	uint32_t IcvFailure;
	uint32_t InvalidMacFrame;
	uint32_t CorruptedMacFrameHeader;
	uint32_t MacDaCompareRule;
	uint32_t PriorityOrTHresholdLessWatermark;
	uint32_t OversizePacket;
	uint32_t Other;
	uint32_t SA_Learning;
}

class_counters;

#ifndef __GNUC__
#pragma pack (pop)
#endif

/*====================================================================*
 *
 *   void StationStats (struct plc * plc, struct station_stats * stats);
 *
 *   display station statistics in human readable format; there may
 *   be one or more such functions depending on the audience; this
 *   output was designed by the Product Verification Team in Ocala;
 *
 *
 *--------------------------------------------------------------------*/

static void StationStats (struct plc * plc, struct station_stats * stats)

{
	fprintf (stderr, "TEI %d\n", stats->TEI);
	fprintf (stderr, "ERR 0x%02X\n", stats->RESULT_CODE);
	fprintf (stderr, "UPSTREAM_MME 0x%08X\n", stats->UPSTREAM_MME_FRAMES);
	fprintf (stderr, "UPSTREAM_UNICAST 0x%08X\n", stats->UPSTREAM_ETH_FRAMES_UNI);
	fprintf (stderr, "UPSTREAM_MULTICAST 0x%08X\n", stats->UPSTREAM_ETH_FRAMES_MULTI);
	fprintf (stderr, "UPSTREAM_BROADCAST 0x%08X\n", stats->UPSTREAM_ETH_FRAMES_BROAD);
	fprintf (stderr, "UPSTREAM_DROP_HOST_MME 0x%08X\n", stats->UPSTREAM_DROP_MME_FROM_HOST);
	fprintf (stderr, "UPSTREAM_DROP_FW_MME 0x%08X\n", stats->UPSTREAM_DROP_MME_FW_GEN);
	fprintf (stderr, "UPSTREAM_DROP_HOST_ETH 0x%08X\n", stats->UPSTREAM_DROP_ETH_FROM_HOST);
	fprintf (stderr, "DOWNSTREAM_MME 0x%08X\n", stats->DOWNSTREAM_MME_FRAMES);
	fprintf (stderr, "DOWNSTREAM_UNICAST 0x%08X\n", stats->DOWNSTREAM_ETH_FRAMES_UNI);
	fprintf (stderr, "DOWNSTREAM_MULTICAST 0x%08X\n", stats->DOWNSTREAM_ETH_FRAMES_MULTI);
	fprintf (stderr, "DOWNSTREAM_BROADCAST 0x%08X\n", stats->DOWNSTREAM_ETH_FRAMES_BROAD);
	fprintf (stderr, "DOWNSTREAM_DROP_HOST_MME 0x%08X\n", stats->DOWNSTREAM_DROP_MME_FROM_HOST);
	fprintf (stderr, "DOWNSTREAM_DROP_FW_MME 0x%08X\n", stats->DOWNSTREAM_DROP_MME_FW_GEN);
	fprintf (stderr, "DOWNSTREAM_DROP_HOST_ETH 0x%08X\n", stats->DOWNSTREAM_DROP_ETH_FROM_HOST);
	fprintf (stderr, "\n");
	return;
}


/*====================================================================*
 *
 *   void EthernetStats (struct plc * plc, struct ethernet_stats * stats);
 *
 *
 *--------------------------------------------------------------------*/

static void EthernetStats (struct plc * plc, struct ethernet_stats * stats)

{
	return;
}


/*====================================================================*
 *
 *   void ClassificationCounters (struct plc * plc, struct class_counters * counters);
 *
 *
 *--------------------------------------------------------------------*/

#if 0

static void ClassificationCounters (struct plc * plc, struct class_counters * counters)

{
	return;
}


#endif

/*====================================================================*
 *
 *   signed MDUTrafficStats (struct plc * plc, uint8_t command, uint8_t session, uint8_t slave);
 *
 *   request MDU traffic statistics using one VS_MDU_TRAFFIC_STATS
 *   request type; different types of confirmations are returned
 *   depending on the type of request;
 *
 *
 *--------------------------------------------------------------------*/

signed MDUTrafficStats (struct plc * plc, uint8_t command, uint8_t session, uint8_t slave)

{
	struct channel * channel = (struct channel *)(plc->channel);
	struct message * message = (struct message *)(plc->message);

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_mdu_station_stats_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t COMMAND;
		uint8_t SESSION;
		uint32_t SLAVE_BITMAP [8];
	}
	* request = (struct vs_mdu_station_stats_request *) (message);
	struct __packed vs_mdu_traffic_master_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t COMMAND;
		uint8_t SESSION;
		uint16_t RESERVED;
		uint8_t NUM_SLAVES;
		uint8_t NUM_SLAVES_LEFT;
		uint16_t STATS_LEN;
		struct station_stats STATS [1];
	}
	* master_confirm = (struct vs_mdu_traffic_master_confirm *) (message);
	struct __packed vs_mdu_traffic_slave_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t COMMAND;
		uint8_t SESSION;
		uint16_t STATS_LEN;
		struct station_stats STATS [1];
	}
	* slave_confirm = (struct vs_mdu_traffic_slave_confirm *) (message);

#if 1

	struct __packed vs_eth_hardware_stats_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t COMMAND;
		uint8_t SESSION;
		uint8_t CHIPTYPE;
		uint8_t STATUS;
		uint16_t STATS_LEN;
		struct ethernet_stats STATS [1];
	}
	* ether_confirm = (struct vs_eth_hardware_stats_confirm *) (message);

#endif

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, "Request MDU Traffic Statistics (1)");
	memset (message, 0, sizeof (* message));
	EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_MDU_TRAFFIC_STATS | MMTYPE_REQ));
	request->COMMAND = command;
	request->SESSION = session;
	set32bitmap (request->SLAVE_BITMAP, slave);
	plc->packetsize = sizeof (* request);
	if (SendMME (plc) <= 0)
	{
		error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
		return (-1);
	}
	while (ReadMME (plc, 0, (VS_MDU_TRAFFIC_STATS | MMTYPE_CNF)) > 0)
	{
		if ((request->COMMAND > 0x00) && (request->COMMAND < 0x0020))
		{
			struct station_stats * stats;
			unsigned count;
			if (_anyset (request->COMMAND, MASTER_TX_RX | SLAVE_TX_RX))
			{
				stats = master_confirm->STATS;
				count = LE16TOH (master_confirm->STATS_LEN);
			}
			else
			{
				stats = slave_confirm->STATS;
				count = LE16TOH (slave_confirm->STATS_LEN);
			}
			while (count >= sizeof (struct station_stats))
			{
				StationStats (plc, stats++);
				count -= sizeof (struct station_stats);
			}
			continue;
		}
		if ((request->COMMAND >= 0x20) && (request->COMMAND < 0x24))
		{
			EthernetStats (plc, ether_confirm->STATS);
			continue;
		}
		if ((request->COMMAND >= 0x24) && (request->COMMAND < 0x28))
		{
			EthernetStats (plc, ether_confirm->STATS);
			continue;
		}
		if ((request->COMMAND >= 0x28) && (request->COMMAND < 0x32))
		{
			EthernetStats (plc, ether_confirm->STATS);
			continue;
		}
	}
	return (0);
}


#endif