bRAWcap 1.0.1
b-plus Technologies - Ethernet Performance Transmitter Receiver
Loading...
Searching...
No Matches
brawcap_types_shared.h
Go to the documentation of this file.
1/**
2 * @file brawcap_types_shared.h
3 *
4 * @brief bRAWcap API - Shared types.
5 *
6 * The file includes all (data)types and defines used for bRAWcap (kernel and user space).
7 *
8 * @copyright
9 * <b> © 2021 - b-plus technologies GmbH. All rights reserved!</b>
10 *
11 * All rights exclusively reserved for b-plus GmbH, unless expressly otherwise agreed.
12 *
13 * Redistribution in source or any other form, with or without modification, is not permitted.
14 *
15 *
16 * You may use this code under the according license terms of b-plus.
17 * Please contact b-plus at services@b-plus.com to get the appropriate terms and conditions.
18 */
19#ifndef BRAWCAP_TYPES_SHARED_H
20#define BRAWCAP_TYPES_SHARED_H
21
22// Include required Windows headers for datatypes.
23#if 1
24#if !defined(_WIN64)
25 #error Architecture not defined (please define "_WIN64").
26#else
27 #ifdef WINNT
28 #include <sdkddkver.h>
29 #include <basetsd.h>
30 #include <minwindef.h>
31 #else
32 #define WIN32_LEAN_AND_MEAN
33 #include <Windows.h>
34 #endif
35#endif
36#endif
37
38// Define required BPF structs if the BPF header is not included.
39#if 1
40#ifndef BRAWCAP_BPF_INCLUDED
41 #define _BRAWCAP_DEFINE_BPF_STRUCTS_INTERNAL
42 #ifndef _BRAWCAP_EXPORT
43 #pragma message("<bRAWcap> Please define 'BRAWCAP_BPF_INCLUDED' if you get any redefinition errors on because of BPF.")
44 #endif
45#endif
46#endif
47
48/************************************************ GENERIC ************************************************************/
49#if 1
50/**
51 * @example{lineno} 03_generic_handle_opener.c
52 *
53 * This example shows how to open and close bRAWcap handles to each available adapter on the machine.
54 * If any unexpected status is returned, it will close all handles and print the unexpected status to console.
55 * Therefore @ref brawcap_last_status is used.
56 */
57
58/**
59 * @defgroup brawcap_generics Generics
60 * @brief Contains generic types and functions of bRAWcap.
61 *
62 * Everything in here is not part of any specific module, instead those types and functions are relevant for many
63 * other modules. It contains for example functions to @ref brawcap_open "open/create" and @ref brawcap_close "close"
64 * a @ref brawcap_handle_t "bRAWcap handle".
65 *
66 * List of examples:
67 * 1. @ref 03_generic_handle_opener.c "Handle Opener"
68 * @{
69 */
70
71/**
72 * @brief Specifies the maximum supported bRAWcap handles per adapter.
73 *
74 * @attention If this number of handles is reached (for a specific adapter) each additional @ref brawcap_open "open"
75 * will fail.
76 */
77#define BRAWCAP_HANDLES_PER_ADAPTER_MAX 5
78
79/**
80 * @brief The number of packets which can be (temporary) buffered by the bRAWcap driver queue.
81 *
82 * The total number of packets which can be buffered by the driver queue is limited to:
83 * - receive: @ref BRAWCAP_RX_DRIVER_QUEUE_SIZE_MAX
84 * - transmit: @ref BRAWCAP_TX_DRIVER_QUEUE_SIZE_MAX
85 *
86 * @note Each bRAWcap handle has it´s own driver queue. Therefore the total memory consumption by the driver
87 * depends on the number of adapters and handles to each adapter, and also on how large the driver queue is specified.
88 *
89 * @attention Larger driver queues can minimize packet drops due to more resources. Especially in cases where the user
90 * application requires longer than expected to pick up (call receive) on the handle. But it has to be said that
91 * large queues shouldn´t be required in optimized configurations and that they can consume a lot of memory if they
92 * are not configured with care.
93 */
94typedef UINT32 brawcap_queue_size_t;
95
96/**@}*/
97#endif
98
99/************************************************** STATUS ***********************************************************/
100#if 1
101/**
102 * @defgroup brawcap_status Status
103 * @brief Contains all status/return codes of bRAWcap.
104 *
105 * If a bRAWcap function completed successfully and with no additional information it will indicate
106 * @ref BRAWCAP_STATUS_SUCCESS.
107 *
108 * If an error occurs the status code will always be negative.
109 *
110 * A status which indicates a warning, will always have a positive value (range 1 to 1999).
111 *
112 * While a status with additional information is always represented by high positive value (range 2000 to 4000).
113 *
114 * It is also possible to request the last "non successful" status for the current thread again with
115 * @ref brawcap_last_status. This function works similar to the one defined by the Windows API (GetLastError()).
116 * @{
117 */
118
119/**
120 * @brief Checks if the returned status indicates a success with no additional info.
121 */
122#define BRAWCAP_SUCCESS(status) (status == 0)
123
124/**
125 * @brief Checks if the returned status is a error.
126 */
127#define BRAWCAP_ERROR(status) (status < 0)
128
129/**
130 * @brief Checks if the returned status is a warning.
131 */
132#define BRAWCAP_WARNING(status) (status > 0 && status < 2000)
133
134/**
135 * @brief Checks if the returned status is a info.
136 */
137#define BRAWCAP_INFO(status) (status >= 2000 && status < 4000)
138
139/**
140 * @brief bRAWcap status/return codes.
141 *
142 * Each status is defined with a descriptive name, which indicates it´s reason.
143 * To check for the status code type use one of the defined macros:
144 * - Status indicates @ref BRAWCAP_SUCCESS "success"
145 * - Status indicates @ref BRAWCAP_ERROR "error"
146 * - Status indicates @ref BRAWCAP_WARNING "warning"
147 * - Status indicates @ref BRAWCAP_INFO "info"
148 */
149typedef enum _brawcap_status
150{
151 // SUCCESS (== 0)
152 BRAWCAP_STATUS_SUCCESS = 0, /*!< Executed successfully, with no additional information. */
153
154 // ERROR (< 0)
155 #if 1
156 /**
157 * @brief Detected a - not further specified - failure.
158 *
159 * This shouldn´t happen at all and mostly indicates a issue in OS abstraction.
160 * If it happens in a specific situation, please check the system resources (CPU load, memory usage...).
161 * If the issue can not be located, feel free to contact our support.
162 */
164 /**
165 * @brief Function is not available.
166 *
167 * This may be returned due to several conditions:
168 * - bRAWcap license does not include the requested feature.
169 * - The current machine does not support the feature.
170 * - Higher API registration privilege is required.
171 */
173 /**
174 * @brief At least one specified pointer parameter was invalid.
175 *
176 * This is a caller issue.
177 * Please check the provided pointers to solve this issue.
178 */
180 /**
181 * @brief At least one parameter content is invalid.
182 *
183 * This is a caller issue.
184 * Please check the provided parameters and their contents to solve this issue.
185 */
187 /**
188 * @brief At least one parameter is out of bounds.
189 *
190 * This is a caller issue.
191 * Please check if the provided parameters fit to the given parameter limitations.
192 */
194 /**
195 * @brief Given parameter not found.
196 *
197 * This is in general a caller issue.
198 * For example it can occur if the function expects a local adapter name and the
199 * provided name did not match any of the currently available adapters.
200 */
202 /**
203 * @brief Indicates that operation failed because the provided object is still in use.
204 *
205 * This may happen if another thread uses the same object or another operation for the object is still outstanding.
206 */
208 /**
209 * @brief The packet size is beyond adapter MTU.
210 *
211 * This status is especially for transmitted packets.
212 * It will be applied if the packet could not be transmitted because
213 * it´s length is beyond the configured adapter MTU.
214 */
216 /**
217 * @brief Communication with the driver failed.
218 *
219 * This indicates an error between library and driver communication.
220 *
221 * To fix such issues, make sure that the loaded library version matches with the driver version.
222 *
223 * In general it is not allowed to mix up library and driver versions.
224 * Applications shall always use the deployed bRAWcap library from the system
225 * and not deploy it´s own copy of it.
226 *
227 * If driver and library version matches and this error still occurs, please contact our support.
228 */
230 /**
231 * @brief bRAWcap is not activated (on a specific adapter).
232 *
233 * This will be returned if bRAWcap driver is not available (anymore)
234 * for the specified bRAWcap handle.
235 * For example if the driver was deactivated meanwhile.
236 */
238 /**
239 * @brief A buffer overrun was detected.
240 *
241 * This is the case if:
242 * - The provided buffer length was to short for the content.
243 * - A bRAWcap packet buffer has reached it´s "packet" capacity.
244 */
246 #endif
247
248 // WARNING (1 to 1999)
249 #if 1
250 /**
251 * @brief The operation was not executed due to demo mode limitations.
252 *
253 * This should only be returned if there is no valid license for the requested feature.
254 * For more information about demo limitation see chapter @ref demo-mode "Demo Mode" in the manual.
255 */
257 /**
258 * @brief Will be returned if another operation for the same resource is pending.
259 *
260 * This could be the case for functions which will initiate a receive/transmit while another
261 * receive/transmit is already pending on the specified handle.
262 * In general it is not allowed to use receive/transmits in parallel on the same handle.
263 * For example if a receive is @ref brawcap_rx_start "started", @ref brawcap_rx_packet cannot be used until the
264 * receive is @ref brawcap_rx_stop "stopped". Same applies to transmissions.
265 */
267 /**
268 * @brief Indicates that a bRAWcap limitation is reached.
269 *
270 * This could be the case if there are already max supported number of handles to the same adapter
271 * and the caller tries to open another one.
272 */
274 /**
275 * @brief Indicates that a operation was canceled.
276 *
277 * For example if a packet transmission was initiated and it is somehow canceled.
278 * This could be the case due to bRAWcap driver deactivation.
279 * If so this status will be applied for each packet which was canceled (not transmitted).
280 */
282 /**
283 * @brief Indicates that not all of the specified content/payload was processed.
284 *
285 * It will be returned for example if not all packets of a bRAWcap packet buffer was transmitted.
286 * If so the user should check the status of each packet inside the buffer for further information.
287 */
289 /**
290 * @brief Indicates that there is currently no uplink on the given adapter.
291 *
292 * It will be returned if the user tries to send packets to a adapter which has currently no uplink.
293 */
295 #endif
296
297 // INFO (2000 - 3999)
298 #if 1
299 /**
300 * @brief No operation running.
301 *
302 * This will be returned if the user tries to stop something which is currently not running.
303 * For example when trying to stop receiving while it is not running.
304 */
306 /**
307 * @brief Indicates that the given object is not attached.
308 *
309 * Will be returned for example if the user tries to detach a packet buffer
310 * which is currently not attached to a handle.
311 */
313 /**
314 * @brief Indicates that the given object is not registered.
315 *
316 * Will be returned if user tries to unregister from a bRAWcap notification
317 * which was not registered before.
318 */
320 /**
321 * @brief Indicates that the given object was already registered.
322 *
323 * Will be returned if user tries to register for something again
324 * which is already registered.
325 */
327 /**
328 * @brief Indicates that a function returns without any data.
329 *
330 * This could be the case if a receive function returns without any received packet.
331 * For example if the configured receive timeout is reached.
332 */
334 /**
335 * @brief Indicates that a function returned because of a timeout.
336 *
337 * This could be the case if a function has not finished it´s processing until a configured timeout is reached.
338 */
340 #endif
342
343/**@}*/
344#endif
345
346/************************************************* VERSION ***********************************************************/
347#if 1
348/**
349 * @example{lineno} 04_version_comparator.c
350 *
351 * This example shows how to read library (/API) and driver version of bRAWcap.
352 * After reading the versions it will check if both versions match.
353 */
354
355/**
356 * @defgroup brawcap_version Version
357 * @brief Types and functions for operating with bRAWcap version(s).
358 *
359 * Here our bRAWcap version structure is defined. This structure allows easy access to each part of the version
360 * and due to it´s union the complete value can be used for easy version compares.
361 *
362 * There are currently two functions to retrieve a version.
363 * One for the @ref brawcap_version_api "version of the loaded library" and another one for the
364 * @ref brawcap_version_driver "version of the loaded bRAWcap driver" on the machine.
365 *
366 * @attention In general both versions shall be equal.
367 * This means it is not allowed to deploy copys of the bRAWcap library with any application.
368 * Instead always the bRAWcap library from system path shall be used (which will be deployed by the bRAWcap setup).
369 * This avoids communication issues between the driver and the library.
370 * If there are any issues with driver communication, please check that the driver and library version matches.
371 *
372 * List of examples:
373 * 1. @ref 04_version_comparator.c "Version Comparator"
374 * @{
375 */
376
377/**
378 * @brief Struct containing the separated version parts.
379 */
380typedef struct _brawcap_version_fragments
381{
382 /**
383 * @brief Build version.
384 *
385 * Different for each build.
386 * Releases will always have different version by the upper three values.
387 * Versions with different build versions only should not appear.
388 * API and ABI always stays compatible between different build versions.
389 */
390 UINT16 build;
391 /**
392 * @brief Patch version.
393 *
394 * Different for each bugfix release.
395 * Will be increased if the release contains bugfixes only.
396 * API and ABI always stays compatible between different patch versions.
397 *
398 */
399 UINT16 patch;
400 /**
401 * @brief Minor version.
402 *
403 * Different for each minor release.
404 * Will be increased if the release contains new features (and maybe some bugfixes).
405 * API always stays compatible between different minor versions.
406 */
407 UINT16 minor;
408 /**
409 * @brief Major version.
410 *
411 * Different for each major release.
412 * Will be increased if for example some features have removed or changed in a way which would
413 * break the API compatibility.
414 * API compatibility between different major versions is not guaranteed.
415 */
416 UINT16 major;
418
419/**
420 * @brief bRAWcap version.
421 *
422 * The version is implemented as a union. The complete member allows easy compare between versions.
423 * While the fragments allow easy access to each version part (major, minor, patch, build).
424 */
425typedef union _brawcap_version
426{
427 brawcap_version_fragments_t fragments; /*!< Separated parts of the version.*/
428 UINT64 complete; /*!< Complete version as integer. Use this for comparing versions. */
430
431/**@}*/
432#endif
433
434/*********************************************** TIMESTAMP ***********************************************************/
435#if 1
436/**
437 * @defgroup brawcap_timestamp Timestamp
438 * @brief Types and functions for operating with bRAWcap timestamps.
439 *
440 * At the moment it is not possible to create a standalone @ref brawcap_timestamp_t "timestamp object".
441 * Instead a timestamp is always part of a @ref brawcap_packet "packet".
442 * To get the timestamp object use @ref brawcap_packet_timestamp_get on a specific packet.
443 * This object can be used than for all functions in this module.
444 *
445 * @attention The user application shall never store a timestamp, instead it should always request it from
446 * a packet and only use it as long as the packet itself is valid.
447 *
448 * List of examples:
449 * 1. @ref 08_receive_timestamp_inspector.c "Receive Timestamp Inspector"
450 * 2. @ref 05_receive_simple_packet_receiver.c "Simple Packet Receiver"
451 * @{
452 */
453
454/**
455 * @brief Checks if timestamp mode @ref BRAWCAP_TIMESTAMP_MODE_SYSTEM_LOWPREC "system low precision" is supported.
456 */
457#define BRAWCAP_TIMESTAMP_MODE_SYSL_AVAILABLE(_capabilities) (_capabilities & 0x01)
458
459/**
460 * @brief Checks if timestamp mode @ref BRAWCAP_TIMESTAMP_MODE_SYSTEM_HIGHPREC "system high precision" is supported.
461 */
462#define BRAWCAP_TIMESTAMP_MODE_SYSH_AVAILABLE(_capabilities) (_capabilities & 0x02)
463
464/**
465 * @brief Checks if timestamp mode @ref BRAWCAP_TIMESTAMP_MODE_SOFTWARE "software" is supported.
466 */
467#define BRAWCAP_TIMESTAMP_MODE_SW_AVAILABLE(_capabilities) (_capabilities & 0x04)
468
469/**
470 * @brief Checks if timestamp mode @ref BRAWCAP_TIMESTAMP_MODE_ADAPTER_SYSTEM "adapter system" is supported.
471 */
472#define BRAWCAP_TIMESTAMP_MODE_ADAPTER_SYS_AVAILABLE(_capabilities) (_capabilities & 0x08)
473
474/**
475 * @brief Checks if timestamp mode @ref BRAWCAP_TIMESTAMP_MODE_ADAPTER_SOFTWARE "adapter software" is supported.
476 */
477#define BRAWCAP_TIMESTAMP_MODE_ADAPTER_SW_AVAILABLE(_capabilities) (_capabilities & 0x10)
478
479/**
480 * @brief Checks if timestamp mode @ref BRAWCAP_TIMESTAMP_MODE_ADAPTER_HARDWARE "adapter hardware" is supported.
481 */
482#define BRAWCAP_TIMESTAMP_MODE_ADAPTER_HW_AVAILABLE(_capabilities) (_capabilities & 0x20)
483
484/**
485 * @brief If a timestamp resolution is set to this value,
486 * it´s resolution is unknown - could not be resolved.
487 *
488 * For example this can be the case for adapter hardware timestamps,
489 * if the adapter does not report it´s clock frequency.
490 */
491#define BRAWCAP_TIMESTAMP_RESOLUTION_UNKNOWN 0
492
493/**
494 * @brief Number of nanoseconds per second.
495 */
496#define BRAWCAP_TIMESTAMP_NS_PER_SEC 1000000000
497
498/**
499 * @brief Number of microseconds per second.
500 */
501#define BRAWCAP_TIMESTAMP_US_PER_SEC 1000000
502
503/**
504 * @brief Number of milliseconds per second.
505 */
506#define BRAWCAP_TIMESTAMP_MS_PER_SEC 1000
507
508/**
509 * @brief Number of nanoseconds per microsecond.
510 */
511#define BRAWCAP_TIMESTAMP_NS_PER_US 1000
512
513/**
514 * @brief Number of nanoseconds per millisecond.
515 */
516#define BRAWCAP_TIMESTAMP_NS_PER_MS 1000000
517
518
519/**
520 * @brief Type used for indicating the supported timestamp modes.
521 *
522 * It has to be interpreted as bitfield.
523 */
525
526/**
527 * @brief Represents the timestamp resolution in nanoseconds.
528 *
529 * The resolution can be used to check how accurate a timestamp is.
530 * For example if it is set to 1.000.000 ns the timestamp has a accuracy of "only" one millisecond.
531 * If it is set to 1 ns instead, it would indicate a very precise timestamp with a resolution of one nanosecond.
532 */
534
535/**
536 * @brief List of different timestamp modes.
537 *
538 * The mode of a timestamp can be used to check when the timestamp is generated (time of trigger).
539 * It can also indicate how accurate a timestamp is.
540 *
541 * Description for the different timestamp types:
542 * - System timestamps:
543 * - Less accurate
544 * - Jumps if the system time itself is jumping.
545 * - Source is the system time
546 * - Software timestamps:
547 * - Good accuracy
548 * - Guaranteed to not jump.
549 * - Source is almost ever the local TSC (if the CPU supports it).
550 * If not Windows will take the next accurate source for it.
551 * For more information on QPC, please see the official
552 * <a href=https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps> Microsoft documentation </a>.
553 * - They will always start from zero and increase with system up time.
554 * - Hardware timestamps:
555 * - Highest accuracy because they are not influenced by the system.
556 * - Only jumps if the adapter hardware clock jumps.
557 * - Source is the adapter hardware clock.
558 *
559 * @note Adapter timestamps are features provided by the underlying adapter and not part of bRAWcap.
560 * bRAWcap only provides those timestamps if the underlying adapter supports it.
561 * To check if the underlying adapter supports them use
562 * - @ref brawcap_rx_timestamp_capabilities for receive timestamps
563 * - @ref brawcap_tx_timestamp_capabilities for transmit timestamps
564 *
565 * @note More accurate system or software timestamps can increase the overall CPU load a bit.
566 * These differences can be neglected in most cases, but if the user is not interested in high-precision timestamps,
567 * always timestamps that require less effort should be preferred.
568 *
569 * @note Trigger position for timestamps created by bRAWcap driver:
570 * - Receive: When the packet is recognized by the bRAWcap driver (forwarded from the underlying driver)
571 * - Transmit: When the transmission complete event is recognized by the bRAWcap driver
572 */
573typedef enum _brawcap_timestamp_mode
574{
575 /**
576 * @brief No timestamp.
577 */
579 /**
580 * @brief A low precision system timestamp created by bRAWcap driver.
581 */
583 /**
584 * @brief A high precision system timestamp created by bRAWcap driver.
585 */
587 /**
588 * @brief A software timestamp created by bRAWcap driver.
589 */
591 /**
592 * @brief A system timestamp created by the network adapter driver.
593 */
595 /**
596 * @brief A software timestamp created by the network adapter driver.
597 */
599 /**
600 * @brief A hardware timestamp created by the network adapter hardware/firmware.
601 */
604
605/**
606 * @brief bRAWcap timestamp object.
607 *
608 * The timestamp object is part of each @ref brawcap_packet "packet" and
609 * has to be used for each timestamp module function.
610 * To get a timestamp object from a packet use @ref brawcap_packet_timestamp_get.
611 */
612typedef struct _brawcap_timestamp brawcap_timestamp_t;
613
614/**@}*/
615#endif
616
617/************************************************ PACKET *************************************************************/
618#if 1
619/**
620 * @defgroup brawcap_packet Packet
621 * @brief Types and functions for operating with bRAWcap packets.
622 *
623 * To create a packet use @ref brawcap_packet_create.
624 * If a packet is not required anymore it shall be deleted with @ref brawcap_packet_free.
625 *
626 * @note It is also possible to use "buffered" packets. Those packets must not be created and freed on their one.
627 * Instead they are part of a @ref brawcap_buffer "packet buffer". To access buffered packets use
628 * @ref brawcap_buffer_at_index to get a packet on a specific position of the buffer or
629 * @ref brawcap_buffer_iterator_eval on a @ref brawcap_buffer_iterator_t "packet buffer iterator".
630 * The second one is especially useful while iterating the buffer.
631 *
632 * @attention The user application shall never store buffered packets separately.
633 * Instead it should always request packets directly from the packet buffer and only use them as long as the packet
634 * buffer itself is valid.
635 *
636 * List of examples:
637 * 1. @ref 05_receive_simple_packet_receiver.c "Simple Packet Receiver"
638 * 2. @ref 07_receive_buffered_receiver.c "Buffered Receiver"
639 * 3. @ref 08_receive_timestamp_inspector.c "Receive Timestamp Inspector"
640 *
641 * @{
642 */
643
644/**
645 * @brief The maximum supported (byte) size for a single packet payload.
646 *
647 * This value corresponds to jumbo frame size (9000 Bytes) + Ethernet header (14 Bytes) + single VLAN header (4 Bytes).
648 */
649#define BRAWCAP_PACKET_SIZE_MAX 9018
650
651/**
652 * @brief The minimum required (byte) size for a single packet payload.
653 *
654 * This corresponds to Ethernet header size.
655 *
656 * @note The Ethernet standard defines a minimum packet length of 64 Bytes (including 4 Byte for Ethernet FCS).
657 * If smaller packets are sent the network adapter will automatically add some padding at the end of the payload.
658 * The padding contains zeros only and after the last padding/payload byte the Ethernet FCS will be added.
659 */
660#define BRAWCAP_PACKET_SIZE_MIN 14
661
662/**
663 * @brief Type for handling the number of payload bytes per packet.
664 *
665 * Typically the packet payload size is set to the adapters max transmission unit (MTU) size + Ethernet header size
666 * and maybe a single VLAN header.
667 * Packet payload sizes have to be between @ref BRAWCAP_PACKET_SIZE_MIN and @ref BRAWCAP_PACKET_SIZE_MAX,
668 * values below/beyond are not accepted.
669 */
671
672/**
673 * @brief bRAWcap packet object.
674 *
675 * The packet object has to be used for each packet module function.
676 * Packet objects can be @ref brawcap_packet_create "created" and @ref brawcap_packet_free "freed"
677 * or retrieved from a @ref brawcap_buffer "packet buffer".
678 */
679typedef struct _brawcap_packet brawcap_packet_t;
680
681/**@}*/
682#endif
683
684/************************************************* BUFFER *************************************************************/
685#if 1
686/**
687 * @defgroup brawcap_buffer Packet Buffer
688 * @brief Types and functions for operating with bRAWcap packet buffers.
689 *
690 * To create a new packet buffer use @ref brawcap_buffer_create.
691 * If a packet buffer is not required anymore it shall be deleted with @ref brawcap_buffer_free.
692 *
693 * Packet buffers can be used for
694 * - Receiving:
695 * To use a buffer for receiving on a bRAWcap handle it has to be @ref brawcap_rx_buffer_attach "attached" to it.
696 * If it shall not be used anymore for receiving it should be @ref brawcap_rx_buffer_detach "detached".
697 *
698 * - Transmitting:
699 * For transmitting a packet buffer, fill up the buffer with packets and than @ref brawcap_tx_buffer_send "send"
700 * it on a handle. This will place the buffer into the transmission queue of the specified handle.
701 *
702 * @attention The packet buffer will be locked down after attaching/sending to a specific handle.
703 * This means that it cannot be accessed by user application as long as it is pending for transmission or attached for
704 * receiving. If the user application tries to access a locked buffer a error will be returned by the specific
705 * packet buffer function.
706 *
707 * A packet buffer can be accessed if:
708 * - It is not attached for receiving.
709 * - No transmission is pending.
710 * - While receiving - from inside the @ref brawcap_rx_callback_t "receive callback".
711 * - While transmitting - from inside the @ref brawcap_tx_callback_t "transmit callback".
712 *
713 * List of examples:
714 * 1. @ref 07_receive_buffered_receiver.c "Buffered Receiver"
715 * @{
716 */
717
718/**
719 * @brief The maximum amount of packets, which can be stored in a packet buffer.
720 */
721#define BRAWCAP_BUFFER_PACKETS_MAX 100000
722
723/**
724 * @brief The minimum amount of packets, which a packet buffer must have.
725 */
726#define BRAWCAP_BUFFER_PACKETS_MIN 1
727
728/**
729 * @brief Type for handling the number of packets which can be stored in a packet buffer.
730 *
731 * The total amount of packets per packet buffer has to be between @ref BRAWCAP_BUFFER_PACKETS_MIN -
732 * @ref BRAWCAP_BUFFER_PACKETS_MAX.
733 */
735
736/**
737 * @brief bRAWcap packet buffer object.
738 *
739 * The packet buffer object has to be used for each packet buffer module function.
740 * Packet buffers can be @ref brawcap_buffer_create "created" and @ref brawcap_buffer_free "freed".
741 */
742typedef struct _brawcap_buffer brawcap_buffer_t;
743
744/********************************************* BUFFER ITERATOR ********************************************************/
745#if 1
746/**
747 * @defgroup brawcap_buffer_iterator Packet Buffer Iterator
748 * @brief bRAWcap packet buffer iterators.
749 *
750 * To create a new packet buffer iterator use @ref brawcap_buffer_iterator_create.
751 * If a packet buffer iterator is not required anymore it shall be deleted with @ref brawcap_buffer_iterator_free.
752 *
753 * @note Iterators should only be used as long as the packet buffer for which it was created is still available.
754 *
755 * @attention Packet buffer iterators are not synchronized. This means that if the packet buffer for which the iterator
756 * was created is modified meanwhile, the iterator is not updated.
757 *
758 * List of examples:
759 * 1. @ref 07_receive_buffered_receiver.c "Buffered Receiver"
760 * @{
761 */
762
763/**
764 * @brief bRAWcap packet buffer iterator object.
765 *
766 * The packet buffer object has to be used for each packet buffer iterator module function.
767 * Packet buffer iterators can be @ref brawcap_buffer_iterator_create "created" and @ref brawcap_buffer_iterator_free
768 * "freed".
769 */
770typedef struct _brawcap_buffer_iterator brawcap_buffer_iterator_t;
771
772/**@}*/
773#endif
774
775/**@}*/
776#endif
777
778/************************************************** ADAPTER **********************************************************/
779#if 1
780/**
781 * @example{lineno} 01_adapter_property_reader.c
782 *
783 * This example shows how to get all currently available adapters on the machine.
784 * And how to get the properties for each adapter.
785 * The adapters and their properties will be printed to command line output.
786 *
787 * @attention This example requires a valid bRAWcap license.
788 * Reading adapter properties is not part of the demo.
789 */
790
791/**
792 * @example{lineno} 02_adapter_change_notifier.c
793 *
794 * This example shows how to register and handle adapter change notifications.
795 * It will print each received notification to command line.
796 * Each output will also include the change reason and the new adapter property value.
797 *
798 * @attention This example requires a valid bRAWcap license.
799 * Reading adapter properties is not part of the demo.
800 */
801
802/**
803 * @defgroup brawcap_adapter Adapter
804 * @brief Types and functions for handling bRAWcap (Ethernet) adapters.
805 *
806 * This module provides many features that facilitate the detection of bRAWcap (Ethernet) adapters.
807 * It allows to scan the local machine for available and supported adapters,
808 * to resolve many useful adapter properties for each adapter and also an adapter change notification.
809 *
810 * Adapter change notifications inform your application directly when any of the available properties have changed,
811 * or when a new adapter has been found or an existing one has been removed (e.g. by disabling the interface).
812 *
813 * When you use these functions, they make all calls to the Windows API - related to adapter handling - obsolete.
814 *
815 * List of examples:
816 * 1. @ref 01_adapter_property_reader.c "Adapter Property Reader"
817 * 2. @ref 02_adapter_change_notifier.c "Adapter Change Notifier"
818 * @{
819 */
820
821/**@}*/
822#endif
823
824/************************************************** RECEIVE **********************************************************/
825#if 1
826/**
827 * @example{lineno} 05_receive_simple_packet_receiver.c
828 *
829 * This example shows how to use the bRAWcap single packet receive feature.
830 * It opens a handle to the first available bRAWcap adapter, creates a bRAWcap packet
831 * to store received data to. For each received packet it will print the packet information to console.
832 */
833
834/**
835 * @example{lineno} 07_receive_buffered_receiver.c
836 *
837 * This example shows how to use the bRAWcap single packet receive feature.
838 * It opens a handle to the first available bRAWcap adapter, creates a bRAWcap packet
839 * to store received data to. For each received packet it will print the packet information to console.
840 */
841
842/**
843 * @example{lineno} 08_receive_timestamp_inspector.c
844 *
845 * This example shows how to configure the different timestamp modes and read timestamp information from single
846 * received packets.
847 * It opens a handle to the first available bRAWcap adapter, creates a bRAWcap packet
848 * to store received data to and applies the configured timestamp mode. For each received packet it will print
849 * it´s applied timestamp info.
850 */
851
852/**
853 * @defgroup brawcap_receive Receive
854 * @brief Types and functions for bRAWcap receiving.
855 *
856 * List of examples:
857 * 1. @ref 05_receive_simple_packet_receiver.c "Simple Packet Receiver"
858 * 2. @ref 07_receive_buffered_receiver.c "Buffered Receiver"
859 * 3. @ref 08_receive_timestamp_inspector.c "Timestamp Inspector"
860 * @{
861 */
862
863/********************************************** RECEIVE FILTER *******************************************************/
864#if 1
865/**
866 * @example{lineno} 06_filter_firewall.c
867 *
868 * This example shows how bRAWcap can be used to filter (discard) specific packets by using a byte filter.
869 */
870
871/**
872 * @defgroup brawcap_filter Receive Filter
873 * @brief Types and functions for operating with bRAWcap receive filters.
874 *
875 * To create a new filter use @ref brawcap_filter_create.
876 * If a filter is not required anymore it shall be deleted with @ref brawcap_filter_free.
877 *
878 * @note Applying filters to handles:<br>
879 * Each bRAWcap handle has it´s own filter instance.
880 * Therefore after applying the filter to a bRAWcap handle the filter may be reused to apply the
881 * same (or a different) filter to another handle or freed if not required anymore.
882 *
883 * List of examples:
884 * 1. @ref 06_filter_firewall.c "Firewall"
885 * @{
886 */
887
888/**
889 * @brief The maximum supported filter byte mask length in bytes.
890 */
891#define BRAWCAP_FILTER_BYTE_MAX_LENGTH 64U
892
893/**
894 * @brief Fixed size array for storing a filter byte mask.
895 *
896 * @note It is not necessary to set all bytes.
897 * If the used filter does not require the complete mask length.
898 * bRAWcap evaluates only the bytes up to the specified filter length.
899 */
901
902/**
903 * @brief Fixed size array for storing a byte wise bitfield.
904 *
905 * This allows to ignore specific bits in the specified filter byte mask.
906 * Each bit which is set to one is ignored in the filter byte mask.
907 *
908 * @note It is not necessary to set all bytes.
909 * If the used filter does not require the complete mask length.
910 * bRAWcap evaluates only the bytes up to the specified filter length.
911 */
913
914/**
915 * @brief Type for specifying the byte filter length.
916 */
918
919/**
920 * @brief List of filter types.
921 *
922 * @note Currently only the byte filter is supported.
923 * A BPF (Berkley Packet Filter) filter, which is equivalent to the one which libpcap uses,
924 * may be added in the future.
925 */
926typedef enum _brawcap_filter_type
927{
928 /**
929 * @brief A bRAWcap byte filter.
930 */
932 /**
933 * @brief A Berkley Packet Filter.
934 */
937 typedef struct bpf_insn* brawcap_bpf_insn_t;
938
939 typedef struct bpf_program* brawcap_bpf_program_t;
940#ifdef _BRAWCAP_DEFINE_BPF_STRUCTS_INTERNAL
941 /**
942 * @brief A single BPF pseudo-instruction.
943 *
944 * Contains a single instruction for the BPF.
945 */
946 struct bpf_insn
947 {
948 USHORT code; /*!< Instruction type and addressing mode. */
949 UCHAR jt; /*!< Jump if true. */
950 UCHAR jf; /*!< Jump if false. */
951 UINT32 k; /*!< Generic field used for various purposes. */
952 };
953
954 /**
955 * @brief A BPF pseudo-assembly program.
956 *
957 * The BPF program can be used to filter incoming packets.
958 * To get a BPF program it has to be generated/compiled from a BPF filter string, first.
959 */
961 {
962 UINT bf_len; /*!< Indicates the number of instructions of the program. */
963 struct bpf_insn* bf_insns; /*!< A pointer to the first instruction of the program. */
964 };
965#endif
966
967/**
968 * @brief bRAWcap filter object.
969 *
970 * The filter object can be accessed with the bRAWcap filter functions.
971 * Filters can be @ref brawcap_filter_create "created" and @ref brawcap_filter_free "freed".
972 */
973typedef struct _brawcap_filter brawcap_filter_t;
974
975/**@}*/
976#endif
977
978/**
979 * @brief Default minimum packets to copy value which has to be received before any receive function return
980 * even if configured timeout exceeds.
981 *
982 * @note bRAWcap waits at least up to 10 times the configured timeout before finally returning if
983 * the minimum number of packets has not yet been received.
984 *
985 * @warning If a timeout of zero which is equivalent to infinite wait is configured it blocks until
986 * the minimum amount of packets are received and will not return earlier.
987 */
988#define BRAWCAP_RX_COPY_PACKETS_DEFAULT 0
989
990/**
991 * @brief Default timeout in milliseconds after which a bRAWcap receive returns,
992 * even if buffer is not yet full but the configured receive min packets to copy must be reached.
993 */
994#define BRAWCAP_RX_TIMEOUT_MS_DEFAULT 10
995
996/**
997 * @brief Default receive timestamp mode which will be used.
998 */
999#define BRAWCAP_RX_TIMESTAMP_MODE_DEFAULT BRAWCAP_TIMESTAMP_MODE_SYSTEM_LOWPREC
1000
1001/**
1002 * @brief Default VLAN tagging mode which will be used.
1003 */
1004#define BRAWCAP_RX_VLAN_TAGGING_DEFAULT FALSE
1005
1006/**
1007 * @brief Default size for driver receive queues in number of packets.
1008 */
1009#define BRAWCAP_RX_DRIVER_QUEUE_SIZE_DEFAULT 4096
1010
1011/**
1012 * @brief Maximum supported receive timeout in number of milliseconds.
1013 */
1014#define BRAWCAP_RX_TIMEOUT_MS_MAX 5000
1015
1016/**
1017 * @brief Maximum size (in number of packets) supported for driver receive queues.
1018 */
1019#define BRAWCAP_RX_DRIVER_QUEUE_SIZE_MAX 40000
1020
1021/**
1022 * @brief Default receive direction which will be used.
1023 */
1024#define BRAWCAP_RX_DIRECTION_DEFAULT BRAWCAP_RX_DIRECTION_BOTH
1025
1026/**
1027 * @brief Type for handling receive timeouts in number of milliseconds.
1028 * The timeout specifies the maximum blocking time in milliseconds for pending bRAWcap receives.
1029 * If a packet is received or the receive buffer is full before the timeout is reached, receive will return earlier.
1030 *
1031 * @attention A receive timeout value of zero corresponds to an infinite wait.
1032 * This means that bRAWcap receive will only return if
1033 * - @ref brawcap_rx_packet - a packet is received,
1034 * - @ref brawcap_rx_start - the minimum amount of packets to copy is reached (see @ref brawcap_rx_min_packets_t)
1035 * or the attached buffer is full - whichever comes first.
1036 */
1038
1039/**
1040 * @brief Type for handling the minimum amount of packets to copy before a bRAWcap receive will return.
1041 * It specifies how many packets should be received before a pending receive returns.
1042 * Reading more packets in a single call can improve the performance but leads to higher latency.
1043 *
1044 * @note This setting is only used with looped receive (@ref brawcap_rx_start) and has no impact on single packet
1045 * reception (@ref brawcap_rx_packet).
1046 */
1048
1049/**
1050 * @brief List of receive modes.
1051 */
1052typedef enum _brawcap_rx_mode
1053{
1054 /**
1055 * @brief Received packets are stored in a user created bRAWcap packet (buffer) and provided to the
1056 * calling application for processing.
1057 */
1059 /**
1060 * @brief Received packets are directly written to disk.
1061 *
1062 * @note Dumping mode is not yet supported and may be added to later releases.
1063 */
1066
1067/**
1068 * @brief List of supported receive directions.
1069 *
1070 * The receive direction allows the select for which direction (transmit/receive) the packets shall be captured.
1071 * This setting can be seen as some kind of generic receive filter.
1072 */
1073typedef enum _brawcap_rx_direction
1074{
1075 /**
1076 * @brief Stops to receive packets of any direction.
1077 */
1079 /**
1080 * @brief Only received packets by the network adapter will be received.
1081 */
1083 /**
1084 * @brief Only transmitted packets by bRAWcap or upper network stack drivers will be received.
1085 * This allows some kind of loopback for packets which are transmitted to the network.
1086 *
1087 * @note This currently does not include packets sent to localhost (IP 127.0.0.1), because they are
1088 * not transmitted/received via a real network adapter. Instead Windows creates a separate "virtual" adapter
1089 * for localhost communication. This adapter is currently not supported by bRAWcap.
1090 */
1092 /**
1093 * @brief Both transmitted packets by bRAWcap or upper network stack drivers and received packets from the
1094 * underlying network adapter will be received.
1095 */
1098
1099/**@}*/
1100#endif
1101
1102/************************************************* TRANSMIT **********************************************************/
1103#if 1
1104/**
1105 * @defgroup brawcap_transmit Transmit
1106 * @brief Types and functions for bRAWcap transmitting.
1107 * @{
1108 */
1109
1110/**
1111 * @brief Default size in number of packets for driver transmit queues.
1112 */
1113#define BRAWCAP_TX_DRIVER_QUEUE_SIZE_DEFAULT 512
1114
1115/**
1116 * @brief Minimum size in number of packets supported for driver transmit queues.
1117 */
1118#define BRAWCAP_TX_DRIVER_QUEUE_SIZE_MIN 256
1119
1120/**
1121 * @brief Maximum size in number of packets supported for driver transmit queues.
1122 */
1123#define BRAWCAP_TX_DRIVER_QUEUE_SIZE_MAX 4096
1124
1125/**
1126 * @brief Default timestamp mode for transmitted packets.
1127 */
1128#define BRAWCAP_TX_TIMESTAMP_MODE_DEFAULT BRAWCAP_TIMESTAMP_MODE_NO_TIMESTAMP
1129
1130/**@}*/
1131#endif
1132
1133/*************************************************** STATS ***********************************************************/
1134#if 1
1135/**
1136 * @defgroup brawcap_stats Statistics
1137 * @brief Types and functions for bRAWcap statistics.
1138 * @{
1139 */
1140
1141/**
1142 * @internal
1143 * @brief Returns the offset from the first member to the last member in number of bytes.
1144*/
1145#define _BRAWCAP_LAST_M_OFFSET(type, lastMember) ((LONG)(LONG_PTR)&(((type *)0)->lastMember))
1146/**
1147 * @internal
1148 * @brief Returns the size of the last member in number of bytes.
1149 */
1150#define _BRAWCAP_LAST_M_SIZE(type, lastMember) (sizeof(((type *)0)->lastMember))
1151/**
1152 * @internal
1153 * @brief Returns the total byte size of the structure, depending on the structure and its last member.
1154 * @warning It is very important to always update the lastMember if the struct is going to be extended.
1155 */
1156#define _BRAWCAP_SIZEOF_STRUCT(type, lastMember) \
1157 (_BRAWCAP_LAST_M_OFFSET(type, lastMember) + _BRAWCAP_LAST_M_SIZE(type, lastMember))
1158
1159/**
1160 * @internal
1161 * @brief Indicates if the @ref brawcap_stats_rx_t.adapterReceivedPacketsTotal member of the receive stats is valid.
1162 * @endinternal
1163 */
1164#define _BRAWCAP_STATS_RX_ADAPTER_RECEIVED_PACKETS_TOTAL_VALID 0x00000001
1165/**
1166 * @brief Indicates if the @ref brawcap_stats_rx_t.adapterReceivedPacketsTotal member of the given receive stats is
1167 * valid. This statistic is provided from the underlying network adapter driver and may be supported or not.
1168 */
1169#define BRAWCAP_STATS_RX_ADAPTER_RECEIVED_PACKETS_TOTAL_VALID(__stats_rx) \
1170 (__stats_rx.adapterValid & _BRAWCAP_STATS_RX_ADAPTER_RECEIVED_PACKETS_TOTAL_VALID)
1171/**
1172 * @internal
1173 * @brief Indicates if the @ref brawcap_stats_rx_t.adapterReceivedBytesTotal member of the receive stats is valid.
1174 * @endinternal
1175 */
1176#define _BRAWCAP_STATS_RX_ADAPTER_RECEIVED_BYTES_TOTAL_VALID 0x00000002
1177/**
1178 * @brief Indicates if the @ref brawcap_stats_rx_t.adapterReceivedBytesTotal member of the given receive stats is valid.
1179 * This statistic is provided from the underlying network adapter driver and may be supported or not.
1180 */
1181#define BRAWCAP_STATS_RX_ADAPTER_RECEIVED_BYTES_TOTAL_VALID(__stats_rx) \
1182 (__stats_rx.adapterValid & _BRAWCAP_STATS_RX_ADAPTER_RECEIVED_BYTES_TOTAL_VALID)
1183/**
1184 * @internal
1185 * @brief Indicates if the @ref brawcap_stats_rx_t.adapterDroppedPacketsTotal member of the receive stats is valid.
1186 * @endinternal
1187 */
1188#define _BRAWCAP_STATS_RX_ADAPTER_DROPPED_PACKETS_TOTAL_VALID 0x00000004
1189/**
1190 * @brief Indicates if the @ref brawcap_stats_rx_t.adapterDroppedPacketsTotal member of the given receive stats is
1191 * valid. This statistic is provided from the underlying network adapter driver and may be supported or not.
1192 */
1193#define BRAWCAP_STATS_RX_ADAPTER_DROPPED_PACKETS_TOTAL_VALID(__stats_rx) \
1194 (__stats_rx.adapterValid & _BRAWCAP_STATS_RX_ADAPTER_DROPPED_PACKETS_TOTAL_VALID)
1195
1196/**
1197 * @internal
1198 * @brief Indicates if the @ref brawcap_stats_tx_t.adapterCompletedPacketsTotal member of the transmit stats is valid.
1199 * @endinternal
1200 */
1201#define _BRAWCAP_STATS_TX_ADAPTER_COMPLETED_PACKETS_TOTAL_VALID 0x00000001
1202/**
1203 * @brief Indicates if the @ref brawcap_stats_tx_t.adapterCompletedPacketsTotal member of the given transmit stats is
1204 * valid. This statistic is provided from the underlying network adapter driver and may be supported or not.
1205 */
1206#define BRAWCAP_STATS_TX_ADAPTER_COMPLETED_PACKETS_TOTAL_VALID(__stats_tx) \
1207 (__stats_tx.adapterValid & _BRAWCAP_STATS_TX_ADAPTER_COMPLETED_PACKETS_TOTAL_VALID)
1208/**
1209 * @internal
1210 * @brief Indicates if the @ref brawcap_stats_tx_t.adapterCompletedBytesTotal member of the transmit stats is valid.
1211 * @endinternal
1212 */
1213#define _BRAWCAP_STATS_TX_ADAPTER_COMPLETED_BYTES_TOTAL_VALID 0x00000002
1214/**
1215 * @brief Indicates if the @ref brawcap_stats_tx_t.adapterCompletedBytesTotal member of the given transmit stats is
1216 * valid. This statistic is provided from the underlying network adapter driver and may be supported or not.
1217 */
1218#define BRAWCAP_STATS_TX_ADAPTER_COMPLETED_BYTES_TOTAL_VALID(__stats_tx) \
1219 (__stats_tx.adapterValid & _BRAWCAP_STATS_TX_ADAPTER_COMPLETED_BYTES_TOTAL_VALID)
1220/**
1221 * @internal
1222 * @brief Indicates if the @ref brawcap_stats_tx_t.adapterCanceledPacketsTotal member of the transmit stats is valid.
1223 * @endinternal
1224 */
1225#define _BRAWCAP_STATS_TX_ADAPTER_CANCELED_PACKETS_TOTAL_VALID 0x00000004
1226/**
1227 * @brief Indicates if the @ref brawcap_stats_tx_t.adapterCanceledPacketsTotal member of the given transmit stats is
1228 * valid. This statistic is provided from the underlying network adapter driver and may be supported or not.
1229 */
1230#define BRAWCAP_STATS_TX_ADAPTER_CANCELED_PACKETS_TOTAL_VALID(__stats_tx) \
1231 (__stats_tx.adapterValid & _BRAWCAP_STATS_TX_ADAPTER_CANCELED_PACKETS_TOTAL_VALID )
1232
1233/**
1234 * @brief Header describing given bRAWcap stats structure.
1235 *
1236 * @attention If your create a new bRAWcap stats structure you must always initialize
1237 * the header first before make use of it.
1238 * This is required to allow backward compatibility for applications using older versions.
1239 */
1240typedef struct _brawcap_stats_header
1241{
1242 /**
1243 * @brief Indicates which type of stats it is.
1244 */
1245 BYTE type;
1246 /**
1247 * @brief Indicates the revision of the stats.
1248 * @note It is preferred to always use the latest version available in your bRAWcap header file.
1249 * But you can also use older versions if you dont want to access members added in the newer versions.
1250 */
1252 /**
1253 * @brief Should be set to the size of the structure depending on it´s type and revision.
1254 * You should use the BRAWCAP_STATS_..._SIZEOF_REVISION_X macros for initializing this member.
1255 */
1256 UINT16 size;
1258
1259/**
1260 * @brief List of all available statistic types.
1261 */
1262typedef enum _brawcap_stats_type
1263{
1264 /**
1265 * @brief Type for receive stats.
1266 */
1268 /**
1269 * @brief Type for transmit stats.
1270 */
1273
1274/**
1275 * @brief List of all available receive statistic revisions.
1276 */
1277typedef enum _brawcap_stats_rx_revision
1278{
1279 /**
1280 * @brief Revision 1 for receive stats.
1281 */
1284
1285/**
1286 * @brief The bRAWcap receive statistics.
1287 *
1288 * This can be used to retrieve all available bRAWcap statistics and counters related to receive path.
1289 * After creating the structure, its header has to be initialized.
1290 *
1291 * The @ref brawcap_stats_header_t.type shall be set to @ref BRAWCAP_STATS_TYPE_RX.
1292 *
1293 * The @ref brawcap_stats_header_t.revision shall be set to one of the following values:
1294 * - @ref BRAWCAP_STATS_RX_REVISION_1
1295 *
1296 * The @ref brawcap_stats_header_t.size shall be set depending on your selected version by using the macro:
1297 * - @ref BRAWCAP_STATS_RX_SIZEOF_REVISION_1 (if selected revision is @ref BRAWCAP_STATS_RX_REVISION_1)
1298 *
1299 * @attention User is responsible for initializing the structure header before using it.
1300 * Otherwise it may lead to undefined behaviour.
1301 */
1302typedef struct _brawcap_stats_rx
1303{
1304 /**
1305 * @brief Header for receive statistics.
1306 * This has to be always initialized by the user after creation before using it.
1307 */
1309 /**
1310 * @brief Bitfield indicating which counters provided by the underlying network adapter driver are valid.
1311 */
1313 /**
1314 * @brief Total number of received packets by the underlying network adapter.
1315 * @note You should check if the network adapter supports this counter with
1316 * @ref BRAWCAP_STATS_RX_ADAPTER_RECEIVED_PACKETS_TOTAL_VALID.
1317 * If the counter is not supported it will be always zero.
1318 */
1320 /**
1321 * @brief Total number of received bytes by the underlying network adapter.
1322 * @note You should check if the network adapter supports this counter with
1323 * @ref BRAWCAP_STATS_RX_ADAPTER_RECEIVED_BYTES_TOTAL_VALID.
1324 * If the counter is not supported it will be always zero.
1325 */
1327 /**
1328 * @brief Total number of received bytes by the underlying network adapter.
1329 * @note You should check if the network adapter supports this counter with
1330 * @ref BRAWCAP_STATS_RX_ADAPTER_DROPPED_PACKETS_TOTAL_VALID.
1331 * If the counter is not supported it will be always zero.
1332 */
1334 /**
1335 * @brief The total number of indicated packets to the upper network stack by bRAWcap on the corresponding adapter.
1336 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1337 */
1339 /**
1340 * @brief The total number of received packets by bRAWcap on the corresponding adapter.
1341 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter..
1342 */
1344 /**
1345 * @brief The total number of received packets by the given bRAWcap handle.
1346 * @note This counter relates to a handle and will be deleted when the handle is closed.
1347 */
1349 /**
1350 * @brief The total number of packets which have matched the given bRAWcap handle filter.
1351 * @note This counter relates to a handle and will be deleted when the handle is closed.
1352 */
1354 /**
1355 * @brief The total number of packets which was queued to the handles driver queue.
1356 * @note This counter relates to a handle and will be deleted when the handle is closed.
1357 */
1359 /**
1360 * @brief The total number of packets which could be directly delivered to user space memory.
1361 * @note This counter relates to a handle and will be deleted when the handle is closed.
1362 */
1364 /**
1365 * @brief The total number of received bytes by the given bRAWcap handle.
1366 * @note This counter relates to a handle and will be deleted when the handle is closed
1367 */
1369 /**
1370 * @brief The total number of packets which was dropped for the handle (sum of all reasons).
1371 * @note This counter relates to a handle and will be deleted when the handle is closed.
1372 */
1374 /**
1375 * @brief The total number of packets which was dropped for the handle because of resources (driver queue overrun).
1376 * @note This counter relates to a handle and will be deleted when the handle is closed.
1377 */
1379 /**
1380 * @brief The total number of packets which was dropped for the handle their length exceeds the handles configured max
1381 * packet size.
1382 * @note This counter relates to a handle and will be deleted when the handle is closed.
1383 */
1386
1387/**
1388 * @brief Returns the size of receive statistics revision 1.
1389 */
1390#define BRAWCAP_STATS_RX_SIZEOF_REVISION_1 _BRAWCAP_SIZEOF_STRUCT(brawcap_stats_rx_t, handleDroppedPacketsToLong)
1391
1392/**
1393 * @brief List of all available transmit statistic revisions.
1394 */
1395typedef enum _brawcap_stats_tx_revision
1396{
1397 /**
1398 * @brief Revision 1 for transmit stats.
1399 */
1402
1403/**
1404 * @brief The bRAWcap transmit statistics.
1405 *
1406 * This can be used to retrieve all available bRAWcap statistics and counters related to transmit path.
1407 * After creating the structure, its header has to be initialized.
1408 *
1409 * The @ref brawcap_stats_header_t.type shall be set to @ref BRAWCAP_STATS_TYPE_TX.
1410 *
1411 * The @ref brawcap_stats_header_t.revision shall be set to one of the following values:
1412 * - @ref BRAWCAP_STATS_TX_REVISION_1
1413 *
1414 * The @ref brawcap_stats_header_t.size shall be set depending on your selected version by using the macro:
1415 * - @ref BRAWCAP_STATS_TX_SIZEOF_REVISION_1 (if selected revision is @ref BRAWCAP_STATS_TX_REVISION_1)
1416 *
1417 * @attention User is responsible for initializing the structure header before using it.
1418 * Otherwise it may lead to undefined behaviour.
1419 */
1420typedef struct _brawcap_stats_tx
1421{
1422 /**
1423 * @brief Header for transmit statistics.
1424 * This has to be always initialized by the user after creation before using it.
1425 */
1427 /**
1428 * @brief Bitfield indicating which counters provided by the underlying network adapter driver are valid.
1429 *
1430 */
1432 /**
1433 * @brief Total number of (completed) transmitted packets by the underlying network adapter.
1434 * @note You should check if the network adapter supports this counter with
1435 * @ref BRAWCAP_STATS_TX_ADAPTER_COMPLETED_PACKETS_TOTAL_VALID.
1436 * If the counter is not supported it will be always zero.
1437 */
1439 /**
1440 * @brief Total number of (completed) transmitted bytes by the underlying network adapter.
1441 * @note You should check if the network adapter supports this counter with
1442 * @ref BRAWCAP_STATS_TX_ADAPTER_COMPLETED_BYTES_TOTAL_VALID.
1443 * If the counter is not supported it will be always zero.
1444 */
1446 /**
1447 * @brief Total number of canceled transmitted packets by the underlying network adapter.
1448 * @note You should check if the network adapter supports this counter with
1449 * @ref BRAWCAP_STATS_TX_ADAPTER_CANCELED_PACKETS_TOTAL_VALID.
1450 * If the counter is not supported it will be always zero.
1451 */
1453 /**
1454 * @brief Total number of initiated packets to transmit by the bRAWcap driver on the corresponding adapter.
1455 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1456 */
1458 /**
1459 * @brief Initiated packets to transmit from upper network stack detected by bRAWcap driver on
1460 * the corresponding adapter.
1461 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1462 */
1464 /**
1465 * @brief Initiated packets to transmit from bRAWcap driver itself on the corresponding adapter.
1466 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1467 */
1469 /**
1470 * @brief Total number of canceled packets to transmit by the bRAWcap driver on the corresponding adapter.
1471 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1472 */
1474 /**
1475 * @brief Canceled packets to transmit from the upper network stack detected by bRAWcap driver on the
1476 * corresponding adapter.
1477 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1478 */
1480 /**
1481 * @brief Canceled packets to transmit from bRAWcap driver itself on the corresponding adapter.
1482 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1483 */
1485 /**
1486 * @brief Total number of completed transmitted packets detected by bRAWcap driver on the corresponding adapter.
1487 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1488 */
1490 /**
1491 * @brief Completed packets to transmit from the upper network stack detected by bRAWcap driver on the corresponding
1492 * adapter.
1493 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1494 */
1496 /**
1497 * @brief Completed packets to transmit from the bRAWcap driver itself on the corresponding adapter.
1498 * @note This counter will reset if bRAWcap driver is restarted, or it is deactivated on the adapter.
1499 */
1501 /**
1502 * @brief Total number of initiated packets to transmit for the handle.
1503 * @note This counter relates to a handle and will be deleted when the handle is closed.
1504 */
1506 /**
1507 * @brief Total number of canceled packets to transmit for the handle.
1508 * @note This counter relates to a handle and will be deleted when the handle is closed.
1509 */
1511 /**
1512 * @brief Total number of completed transmitted packets for the handle.
1513 * @note This counter relates to a handle and will be deleted when the handle is closed.
1514 */
1516
1517 UINT64 handleCompletedBytesTotal;
1519
1520/**
1521 * @brief Returns the size of transmit statistics revision 1.
1522 */
1523#define BRAWCAP_STATS_TX_SIZEOF_REVISION_1 _BRAWCAP_SIZEOF_STRUCT(brawcap_stats_tx_t, handleCompletedBytesTotal)
1524
1525/**@}*/
1526#endif
1527
1528#endif // BRAWCAP_TYPES_SHARED_H
UINT32 brawcap_queue_size_t
The number of packets which can be (temporary) buffered by the bRAWcap driver queue.
Definition: brawcap_types_shared.h:94
brawcap_status_t
bRAWcap status/return codes.
Definition: brawcap_types_shared.h:150
@ BRAWCAP_STATUS_INFO_NOT_ATTACHED
Indicates that the given object is not attached.
Definition: brawcap_types_shared.h:312
@ BRAWCAP_STATUS_ERROR_IN_USE
Indicates that operation failed because the provided object is still in use.
Definition: brawcap_types_shared.h:207
@ BRAWCAP_STATUS_ERROR_DRIVER_NOT_AVAILABLE
bRAWcap is not activated (on a specific adapter).
Definition: brawcap_types_shared.h:237
@ BRAWCAP_STATUS_ERROR_FAILED
Detected a - not further specified - failure.
Definition: brawcap_types_shared.h:163
@ BRAWCAP_STATUS_SUCCESS
Definition: brawcap_types_shared.h:152
@ BRAWCAP_STATUS_ERROR_INVALID_PARAM
At least one parameter content is invalid.
Definition: brawcap_types_shared.h:186
@ BRAWCAP_STATUS_ERROR_OVERRUN
A buffer overrun was detected.
Definition: brawcap_types_shared.h:245
@ BRAWCAP_STATUS_ERROR_DRIVER_IO_FAILED
Communication with the driver failed.
Definition: brawcap_types_shared.h:229
@ BRAWCAP_STATUS_WARNING_LIMIT_REACHED
Indicates that a bRAWcap limitation is reached.
Definition: brawcap_types_shared.h:273
@ BRAWCAP_STATUS_ERROR_NOT_FOUND
Given parameter not found.
Definition: brawcap_types_shared.h:201
@ BRAWCAP_STATUS_INFO_ALREADY_REGISTERED
Indicates that the given object was already registered.
Definition: brawcap_types_shared.h:326
@ BRAWCAP_STATUS_ERROR_PARAM_OUT_OF_RANGE
At least one parameter is out of bounds.
Definition: brawcap_types_shared.h:193
@ BRAWCAP_STATUS_WARNING_NO_UPLINK
Indicates that there is currently no uplink on the given adapter.
Definition: brawcap_types_shared.h:294
@ BRAWCAP_STATUS_INFO_TIMEOUT
Indicates that a function returned because of a timeout.
Definition: brawcap_types_shared.h:339
@ BRAWCAP_STATUS_ERROR_INVALID_POINTER
At least one specified pointer parameter was invalid.
Definition: brawcap_types_shared.h:179
@ BRAWCAP_STATUS_INFO_NOT_REGISTERED
Indicates that the given object is not registered.
Definition: brawcap_types_shared.h:319
@ BRAWCAP_STATUS_WARNING_PENDING
Will be returned if another operation for the same resource is pending.
Definition: brawcap_types_shared.h:266
@ BRAWCAP_STATUS_ERROR_BEYOND_MTU
The packet size is beyond adapter MTU.
Definition: brawcap_types_shared.h:215
@ BRAWCAP_STATUS_WARNING_CANCELED
Indicates that a operation was canceled.
Definition: brawcap_types_shared.h:281
@ BRAWCAP_STATUS_INFO_NOT_RUNNING
No operation running.
Definition: brawcap_types_shared.h:305
@ BRAWCAP_STATUS_ERROR_NOT_AVAILABLE
Function is not available.
Definition: brawcap_types_shared.h:172
@ BRAWCAP_STATUS_INFO_NO_DATA
Indicates that a function returns without any data.
Definition: brawcap_types_shared.h:333
@ BRAWCAP_STATUS_WARNING_DEMO_MODE
The operation was not executed due to demo mode limitations.
Definition: brawcap_types_shared.h:256
@ BRAWCAP_STATUS_WARNING_NOT_ALL_PROCESSED
Indicates that not all of the specified content/payload was processed.
Definition: brawcap_types_shared.h:288
Struct containing the separated version parts.
Definition: brawcap_types_shared.h:381
bRAWcap version.
Definition: brawcap_types_shared.h:426
UINT16 minor
Minor version.
Definition: brawcap_types_shared.h:407
UINT16 major
Major version.
Definition: brawcap_types_shared.h:416
UINT16 patch
Patch version.
Definition: brawcap_types_shared.h:399
UINT16 build
Build version.
Definition: brawcap_types_shared.h:390
UINT64 complete
Definition: brawcap_types_shared.h:428
brawcap_version_fragments_t fragments
Definition: brawcap_types_shared.h:427
UINT32 brawcap_timestamp_capabilities_t
Type used for indicating the supported timestamp modes.
Definition: brawcap_types_shared.h:524
struct _brawcap_timestamp brawcap_timestamp_t
bRAWcap timestamp object.
Definition: brawcap_types_shared.h:612
UINT32 brawcap_timestamp_resolution_ns_t
Represents the timestamp resolution in nanoseconds.
Definition: brawcap_types_shared.h:533
brawcap_timestamp_mode_t
List of different timestamp modes.
Definition: brawcap_types_shared.h:574
@ BRAWCAP_TIMESTAMP_MODE_SYSTEM_HIGHPREC
A high precision system timestamp created by bRAWcap driver.
Definition: brawcap_types_shared.h:586
@ BRAWCAP_TIMESTAMP_MODE_ADAPTER_HARDWARE
A hardware timestamp created by the network adapter hardware/firmware.
Definition: brawcap_types_shared.h:602
@ BRAWCAP_TIMESTAMP_MODE_SOFTWARE
A software timestamp created by bRAWcap driver.
Definition: brawcap_types_shared.h:590
@ BRAWCAP_TIMESTAMP_MODE_ADAPTER_SYSTEM
A system timestamp created by the network adapter driver.
Definition: brawcap_types_shared.h:594
@ BRAWCAP_TIMESTAMP_MODE_ADAPTER_SOFTWARE
A software timestamp created by the network adapter driver.
Definition: brawcap_types_shared.h:598
@ BRAWCAP_TIMESTAMP_MODE_NO_TIMESTAMP
No timestamp.
Definition: brawcap_types_shared.h:578
@ BRAWCAP_TIMESTAMP_MODE_SYSTEM_LOWPREC
A low precision system timestamp created by bRAWcap driver.
Definition: brawcap_types_shared.h:582
UINT16 brawcap_packet_size_t
Type for handling the number of payload bytes per packet.
Definition: brawcap_types_shared.h:670
struct _brawcap_packet brawcap_packet_t
bRAWcap packet object.
Definition: brawcap_types_shared.h:679
struct _brawcap_buffer brawcap_buffer_t
bRAWcap packet buffer object.
Definition: brawcap_types_shared.h:742
UINT32 brawcap_buffer_packet_count_t
Type for handling the number of packets which can be stored in a packet buffer.
Definition: brawcap_types_shared.h:734
struct _brawcap_buffer_iterator brawcap_buffer_iterator_t
bRAWcap packet buffer iterator object.
Definition: brawcap_types_shared.h:770
brawcap_rx_mode_t
List of receive modes.
Definition: brawcap_types_shared.h:1053
UINT32 brawcap_rx_min_packets_t
Type for handling the minimum amount of packets to copy before a bRAWcap receive will return....
Definition: brawcap_types_shared.h:1047
UINT16 brawcap_rx_timeout_t
Type for handling receive timeouts in number of milliseconds. The timeout specifies the maximum block...
Definition: brawcap_types_shared.h:1037
brawcap_rx_direction_t
List of supported receive directions.
Definition: brawcap_types_shared.h:1074
@ BRAWCAP_RX_MODE_LIVE
Received packets are stored in a user created bRAWcap packet (buffer) and provided to the calling app...
Definition: brawcap_types_shared.h:1058
@ BRAWCAP_RX_MODE_DUMP
Received packets are directly written to disk.
Definition: brawcap_types_shared.h:1064
@ BRAWCAP_RX_DIRECTION_UNKNOWN
Stops to receive packets of any direction.
Definition: brawcap_types_shared.h:1078
@ BRAWCAP_RX_DIRECTION_IN
Only received packets by the network adapter will be received.
Definition: brawcap_types_shared.h:1082
@ BRAWCAP_RX_DIRECTION_OUT
Only transmitted packets by bRAWcap or upper network stack drivers will be received....
Definition: brawcap_types_shared.h:1091
@ BRAWCAP_RX_DIRECTION_BOTH
Both transmitted packets by bRAWcap or upper network stack drivers and received packets from the unde...
Definition: brawcap_types_shared.h:1096
A single BPF pseudo-instruction.
Definition: brawcap_types_shared.h:947
A BPF pseudo-assembly program.
Definition: brawcap_types_shared.h:961
UCHAR jt
Definition: brawcap_types_shared.h:949
UINT32 k
Definition: brawcap_types_shared.h:951
UCHAR jf
Definition: brawcap_types_shared.h:950
UINT bf_len
Definition: brawcap_types_shared.h:962
struct bpf_insn * bf_insns
Definition: brawcap_types_shared.h:963
USHORT code
Definition: brawcap_types_shared.h:948
#define BRAWCAP_FILTER_BYTE_MAX_LENGTH
The maximum supported filter byte mask length in bytes.
Definition: brawcap_types_shared.h:891
UINT8 brawcap_filter_mask_array_t[BRAWCAP_FILTER_BYTE_MAX_LENGTH]
Fixed size array for storing a filter byte mask.
Definition: brawcap_types_shared.h:900
struct _brawcap_filter brawcap_filter_t
bRAWcap filter object.
Definition: brawcap_types_shared.h:973
brawcap_filter_type_t
List of filter types.
Definition: brawcap_types_shared.h:927
UINT8 brawcap_filter_ignore_bits_array_t[BRAWCAP_FILTER_BYTE_MAX_LENGTH]
Fixed size array for storing a byte wise bitfield.
Definition: brawcap_types_shared.h:912
brawcap_packet_size_t brawcap_filter_byte_length_t
Type for specifying the byte filter length.
Definition: brawcap_types_shared.h:917
@ BRAWCAP_FILTER_TYPE_BPF
A Berkley Packet Filter.
Definition: brawcap_types_shared.h:935
@ BRAWCAP_FILTER_TYPE_BYTE_MASK
A bRAWcap byte filter.
Definition: brawcap_types_shared.h:931
Header describing given bRAWcap stats structure.
Definition: brawcap_types_shared.h:1241
The bRAWcap receive statistics.
Definition: brawcap_types_shared.h:1303
The bRAWcap transmit statistics.
Definition: brawcap_types_shared.h:1421
UINT64 driverInitiatedPacketsHandles
Initiated packets to transmit from bRAWcap driver itself on the corresponding adapter.
Definition: brawcap_types_shared.h:1468
UINT64 handleDroppedPacketsTotal
The total number of packets which was dropped for the handle (sum of all reasons).
Definition: brawcap_types_shared.h:1373
UINT64 driverCompletedPacketsStack
Completed packets to transmit from the upper network stack detected by bRAWcap driver on the correspo...
Definition: brawcap_types_shared.h:1495
UINT64 driverReceivedPacketsTotal
The total number of received packets by bRAWcap on the corresponding adapter.
Definition: brawcap_types_shared.h:1343
UINT64 handleReceivedPacketsMatched
The total number of packets which have matched the given bRAWcap handle filter.
Definition: brawcap_types_shared.h:1353
UINT64 handleCompletedPacketsTotal
Total number of completed transmitted packets for the handle.
Definition: brawcap_types_shared.h:1515
BYTE revision
Indicates the revision of the stats.
Definition: brawcap_types_shared.h:1251
UINT64 adapterDroppedPacketsTotal
Total number of received bytes by the underlying network adapter.
Definition: brawcap_types_shared.h:1333
UINT64 adapterReceivedPacketsTotal
Total number of received packets by the underlying network adapter.
Definition: brawcap_types_shared.h:1319
UINT64 adapterCanceledPacketsTotal
Total number of canceled transmitted packets by the underlying network adapter.
Definition: brawcap_types_shared.h:1452
UINT64 handleReceivedPacketsDirect
The total number of packets which could be directly delivered to user space memory.
Definition: brawcap_types_shared.h:1363
UINT64 handleReceivedPacketsQueued
The total number of packets which was queued to the handles driver queue.
Definition: brawcap_types_shared.h:1358
UINT64 handleDroppedPacketsToLong
The total number of packets which was dropped for the handle their length exceeds the handles configu...
Definition: brawcap_types_shared.h:1384
UINT64 driverCompletedPacketsHandles
Completed packets to transmit from the bRAWcap driver itself on the corresponding adapter.
Definition: brawcap_types_shared.h:1500
UINT64 adapterCompletedBytesTotal
Total number of (completed) transmitted bytes by the underlying network adapter.
Definition: brawcap_types_shared.h:1445
UINT16 size
Should be set to the size of the structure depending on it´s type and revision. You should use the BR...
Definition: brawcap_types_shared.h:1256
UINT64 driverInitiatedPacketsStack
Initiated packets to transmit from upper network stack detected by bRAWcap driver on the correspondin...
Definition: brawcap_types_shared.h:1463
UINT64 driverInitiatedPacketsTotal
Total number of initiated packets to transmit by the bRAWcap driver on the corresponding adapter.
Definition: brawcap_types_shared.h:1457
UINT64 adapterCompletedPacketsTotal
Total number of (completed) transmitted packets by the underlying network adapter.
Definition: brawcap_types_shared.h:1438
UINT64 handleCanceledPacketsTotal
Total number of canceled packets to transmit for the handle.
Definition: brawcap_types_shared.h:1510
BYTE type
Indicates which type of stats it is.
Definition: brawcap_types_shared.h:1245
UINT64 handleDroppedPacketsQueue
The total number of packets which was dropped for the handle because of resources (driver queue overr...
Definition: brawcap_types_shared.h:1378
UINT64 driverCanceledPacketsTotal
Total number of canceled packets to transmit by the bRAWcap driver on the corresponding adapter.
Definition: brawcap_types_shared.h:1473
UINT32 adapterValid
Bitfield indicating which counters provided by the underlying network adapter driver are valid.
Definition: brawcap_types_shared.h:1312
UINT64 handleReceivedPacketsTotal
The total number of received packets by the given bRAWcap handle.
Definition: brawcap_types_shared.h:1348
UINT64 driverCanceledPacketsHandles
Canceled packets to transmit from bRAWcap driver itself on the corresponding adapter.
Definition: brawcap_types_shared.h:1484
brawcap_stats_header_t header
Header for receive statistics. This has to be always initialized by the user after creation before us...
Definition: brawcap_types_shared.h:1308
UINT64 handleInitiatedPacketsTotal
Total number of initiated packets to transmit for the handle.
Definition: brawcap_types_shared.h:1505
UINT64 driverIndicatedPacketsTotal
The total number of indicated packets to the upper network stack by bRAWcap on the corresponding adap...
Definition: brawcap_types_shared.h:1338
UINT64 driverCanceledPacketsStack
Canceled packets to transmit from the upper network stack detected by bRAWcap driver on the correspon...
Definition: brawcap_types_shared.h:1479
UINT64 adapterReceivedBytesTotal
Total number of received bytes by the underlying network adapter.
Definition: brawcap_types_shared.h:1326
UINT64 handleReceivedBytesTotal
The total number of received bytes by the given bRAWcap handle.
Definition: brawcap_types_shared.h:1368
UINT64 driverCompletedPacketsTotal
Total number of completed transmitted packets detected by bRAWcap driver on the corresponding adapter...
Definition: brawcap_types_shared.h:1489
brawcap_stats_rx_revision_t
List of all available receive statistic revisions.
Definition: brawcap_types_shared.h:1278
brawcap_stats_tx_revision_t
List of all available transmit statistic revisions.
Definition: brawcap_types_shared.h:1396
brawcap_stats_type_t
List of all available statistic types.
Definition: brawcap_types_shared.h:1263
@ BRAWCAP_STATS_RX_REVISION_1
Revision 1 for receive stats.
Definition: brawcap_types_shared.h:1282
@ BRAWCAP_STATS_TX_REVISION_1
Revision 1 for transmit stats.
Definition: brawcap_types_shared.h:1400
@ BRAWCAP_STATS_TYPE_RX
Type for receive stats.
Definition: brawcap_types_shared.h:1267
@ BRAWCAP_STATS_TYPE_TX
Type for transmit stats.
Definition: brawcap_types_shared.h:1271