2007-11-24 03:33:18 +00:00
|
|
|
/* commview.c
|
2021-04-19 03:15:23 +00:00
|
|
|
* Routines for opening CommView NCF and NCFX file format packet captures
|
2009-05-31 05:55:15 +00:00
|
|
|
* Copyright 2007, Stephen Fisher (see AUTHORS file)
|
2007-11-24 03:33:18 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2007-11-26 05:34:07 +00:00
|
|
|
* Based on csids.c and nettl.c
|
2007-11-24 03:33:18 +00:00
|
|
|
*
|
2018-02-18 21:40:50 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2007-11-24 03:33:18 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
/* A brief description of these file formats is available at:
|
2019-07-28 04:20:27 +00:00
|
|
|
* https://www.tamos.com/htmlhelp/commview/logformat.htm
|
2021-04-19 03:15:23 +00:00
|
|
|
* https://www.tamos.com/htmlhelp/commwifi/logformat.htm
|
2018-11-12 23:14:33 +00:00
|
|
|
*
|
|
|
|
* Use
|
|
|
|
*
|
|
|
|
* https://web.archive.org/web/20171022225753/http://www.tamos.com/htmlhelp/commview/logformat.htm
|
|
|
|
*
|
|
|
|
* if that doesn't display anything.
|
2007-11-24 03:33:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "file_wrappers.h"
|
|
|
|
#include "commview.h"
|
|
|
|
|
2021-03-04 23:41:00 +00:00
|
|
|
#include <wsutil/802_11-utils.h>
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
/*
|
|
|
|
* Capture medium types used in NCF and NCFX;
|
|
|
|
* Token Ring isn't used in NCFX.
|
|
|
|
*/
|
|
|
|
#define MEDIUM_ETHERNET 0
|
|
|
|
#define MEDIUM_WIFI 1
|
|
|
|
#define MEDIUM_TOKEN_RING 2
|
|
|
|
|
|
|
|
typedef struct commview_ncf_header {
|
2007-11-24 03:33:18 +00:00
|
|
|
guint16 data_len;
|
|
|
|
guint16 source_data_len;
|
|
|
|
guint8 version;
|
|
|
|
guint16 year;
|
|
|
|
guint8 month;
|
2014-10-07 05:01:12 +00:00
|
|
|
guint8 day;
|
2007-11-24 03:33:18 +00:00
|
|
|
guint8 hours;
|
|
|
|
guint8 minutes;
|
|
|
|
guint8 seconds;
|
|
|
|
guint32 usecs;
|
|
|
|
guint8 flags; /* Bit-field positions defined below */
|
2010-12-20 23:34:14 +00:00
|
|
|
guint8 signal_level_percent;
|
2012-10-12 20:51:04 +00:00
|
|
|
guint8 rate;
|
2007-11-24 03:33:18 +00:00
|
|
|
guint8 band;
|
|
|
|
guint8 channel;
|
2010-12-20 23:34:14 +00:00
|
|
|
guint8 direction; /* Or for WiFi, high order byte of
|
|
|
|
* packet rate. */
|
2021-04-19 03:15:23 +00:00
|
|
|
gint8 signal_level_dbm; /* WiFi-only */
|
|
|
|
gint8 noise_level_dbm; /* WiFi-only */
|
|
|
|
} commview_ncf_header_t;
|
2007-11-24 03:33:18 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
#define COMMVIEW_NCF_HEADER_SIZE 24
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* Bit-field positions for various fields in the flags variable of the header */
|
|
|
|
#define FLAGS_MEDIUM 0x0F
|
|
|
|
#define FLAGS_DECRYPTED 0x10
|
|
|
|
#define FLAGS_BROKEN 0x20
|
|
|
|
#define FLAGS_COMPRESSED 0x40
|
|
|
|
#define FLAGS_RESERVED 0x80
|
|
|
|
|
2015-06-22 22:04:28 +00:00
|
|
|
/* Values for the band variable of the header */
|
|
|
|
#define BAND_11A 0x01
|
|
|
|
#define BAND_11B 0x02
|
|
|
|
#define BAND_11G 0x04
|
|
|
|
#define BAND_11A_TURBO 0x08
|
|
|
|
#define BAND_SUPERG 0x10
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
#define BAND_PUBLIC_SAFETY 0x20 /* 4.99 GHz public safety */
|
2015-06-22 22:04:28 +00:00
|
|
|
#define BAND_11N_5GHZ 0x40
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
#define BAND_11N_2_4GHZ 0x80
|
2015-06-22 22:04:28 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
static gboolean commview_ncf_read(wtap *wth, wtap_rec *rec, Buffer *buf,
|
2019-04-05 01:56:27 +00:00
|
|
|
int *err, gchar **err_info, gint64 *data_offset);
|
2021-04-19 03:15:23 +00:00
|
|
|
static gboolean commview_ncf_seek_read(wtap *wth, gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec,
|
2014-05-23 10:50:02 +00:00
|
|
|
Buffer *buf, int *err, gchar **err_info);
|
2021-04-19 03:15:23 +00:00
|
|
|
static gboolean commview_ncf_read_header(commview_ncf_header_t *cv_hdr, FILE_T fh,
|
2014-05-09 05:18:49 +00:00
|
|
|
int *err, gchar **err_info);
|
2021-04-19 03:15:23 +00:00
|
|
|
static gboolean commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec,
|
2014-12-18 00:02:50 +00:00
|
|
|
const guint8 *pd, int *err, gchar **err_info);
|
2007-11-24 03:33:18 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
static int commview_ncf_file_type_subtype = -1;
|
|
|
|
static int commview_ncfx_file_type_subtype = -1;
|
wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in
wiretap/file_access.c and, instead, have the file types register
themselves, using wtap_register_file_type_subtypes().
This reduces the source code changes needed to add a new file type from
three (add the handler, add the file type to the table in file_access.c,
add a #define for the file type in wiretap/wtap.h) to one (add the
handler). (It also requires adding the handler's source file to
wiretap/CMakeLists.txt, but that's required in both cases.)
A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used
elsewhere; that needs to be fixed.
Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now
contains a registration routine. In the process, avoid scanning files
that don't implement a file type and won't ever have a registration
routine.
Add a Lua routine to fetch the total number of file types; we use that
in some code to construct the wtap_filetypes table, which we need to do
in order to continue to have all the values that used to come from the
WTAP_FILE_TYPE_SUBTYPE_ types.
While we're at it, add modelines to a file that lacked them.
2021-02-14 08:34:10 +00:00
|
|
|
|
|
|
|
void register_commview(void);
|
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
wtap_open_return_val
|
|
|
|
commview_ncf_open(wtap *wth, int *err, gchar **err_info)
|
2007-11-24 03:33:18 +00:00
|
|
|
{
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_header_t cv_hdr;
|
2007-11-24 03:33:18 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
if(!commview_ncf_read_header(&cv_hdr, wth->fh, err, err_info)) {
|
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").
When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.
For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.
svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
|
|
|
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2012-12-26 12:01:14 +00:00
|
|
|
}
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* If any of these fields do not match what we expect, bail out. */
|
|
|
|
if(cv_hdr.version != 0 ||
|
|
|
|
cv_hdr.year < 1970 || cv_hdr.year >= 2038 ||
|
|
|
|
cv_hdr.month < 1 || cv_hdr.month > 12 ||
|
|
|
|
cv_hdr.day < 1 || cv_hdr.day > 31 ||
|
|
|
|
cv_hdr.hours > 23 ||
|
|
|
|
cv_hdr.minutes > 59 ||
|
|
|
|
cv_hdr.seconds > 60 ||
|
2010-12-20 23:34:14 +00:00
|
|
|
cv_hdr.signal_level_percent > 100 ||
|
2007-11-24 03:33:18 +00:00
|
|
|
(cv_hdr.flags & FLAGS_RESERVED) != 0 ||
|
|
|
|
((cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_ETHERNET &&
|
|
|
|
(cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_WIFI &&
|
2010-12-20 23:34:14 +00:00
|
|
|
(cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_TOKEN_RING))
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* No file header. Reset the fh to 0 so we can read the first packet */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* Set up the pointers to the handlers for this file type */
|
2021-04-19 03:15:23 +00:00
|
|
|
wth->subtype_read = commview_ncf_read;
|
|
|
|
wth->subtype_seek_read = commview_ncf_seek_read;
|
2007-11-26 05:34:07 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
wth->file_type_subtype = commview_ncf_file_type_subtype;
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_PER_PACKET;
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE; /* Our kind of file */
|
2007-11-24 03:33:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 23:14:17 +00:00
|
|
|
static int
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
|
2013-05-16 23:14:17 +00:00
|
|
|
int *err, gchar **err_info)
|
2011-09-01 04:14:54 +00:00
|
|
|
{
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_header_t cv_hdr;
|
2012-10-17 20:28:22 +00:00
|
|
|
struct tm tm;
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
guint frequency;
|
2012-10-17 20:28:22 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
if(!commview_ncf_read_header(&cv_hdr, fh, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2016-04-30 02:04:17 +00:00
|
|
|
/*
|
|
|
|
* The maximum value of cv_hdr.data_len is 65535, which is less
|
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
|
|
|
* than WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to
|
2016-04-30 02:04:17 +00:00
|
|
|
* check it.
|
|
|
|
*/
|
2012-10-17 20:28:22 +00:00
|
|
|
|
2013-05-16 23:14:17 +00:00
|
|
|
switch(cv_hdr.flags & FLAGS_MEDIUM) {
|
2011-09-01 04:14:54 +00:00
|
|
|
|
|
|
|
case MEDIUM_ETHERNET :
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.eth.fcs_len = -1; /* Unknown */
|
2013-05-16 23:14:17 +00:00
|
|
|
break;
|
2011-09-01 04:14:54 +00:00
|
|
|
|
|
|
|
case MEDIUM_WIFI :
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
|
|
|
|
memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11));
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN;
|
2015-06-22 22:04:28 +00:00
|
|
|
switch (cv_hdr.band) {
|
|
|
|
|
|
|
|
case BAND_11A:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
|
2021-03-10 19:09:57 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_channel_type = FALSE;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type =
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
PHDR_802_11A_TURBO_TYPE_NORMAL;
|
|
|
|
frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
|
2015-06-22 22:04:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BAND_11B:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B;
|
2021-03-10 19:09:57 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE;
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
|
2015-06-22 22:04:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BAND_11G:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode =
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
PHDR_802_11G_MODE_NORMAL;
|
|
|
|
frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
|
2015-06-22 22:04:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BAND_11A_TURBO:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type =
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
PHDR_802_11A_TURBO_TYPE_TURBO;
|
|
|
|
frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
|
2015-06-22 22:04:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BAND_SUPERG:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode =
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
PHDR_802_11G_MODE_SUPER_G;
|
|
|
|
frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
|
2015-06-22 22:04:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BAND_11N_5GHZ:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N;
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
|
2015-06-22 22:04:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BAND_11N_2_4GHZ:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N;
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
|
|
|
|
break;
|
|
|
|
|
2015-07-06 02:05:52 +00:00
|
|
|
case BAND_PUBLIC_SAFETY:
|
|
|
|
/*
|
|
|
|
* XXX - what do we do here? What are the channel
|
|
|
|
* numbers? How do we distinguish the several
|
|
|
|
* different flavors of 4.9 GHz frequencies?
|
|
|
|
*/
|
|
|
|
frequency = 0;
|
|
|
|
break;
|
|
|
|
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
default:
|
|
|
|
frequency = 0;
|
2015-06-22 22:04:28 +00:00
|
|
|
break;
|
|
|
|
}
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
if (frequency != 0) {
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency = frequency;
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
}
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = cv_hdr.channel;
|
2015-12-09 22:26:46 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate =
|
2013-06-03 06:36:55 +00:00
|
|
|
cv_hdr.rate | (cv_hdr.direction << 8);
|
2015-12-09 22:26:46 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = cv_hdr.signal_level_percent;
|
2014-10-29 23:03:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - these are positive in captures I've seen; does
|
|
|
|
* that mean that they are the negative of the actual
|
|
|
|
* dBm value? (80 dBm is a bit more power than most
|
|
|
|
* countries' regulatory agencies are likely to allow
|
|
|
|
* any individual to have in their home. :-))
|
|
|
|
*
|
|
|
|
* XXX - sometimes these are 0; assume that means that no
|
|
|
|
* value is provided.
|
|
|
|
*/
|
|
|
|
if (cv_hdr.signal_level_dbm != 0) {
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm = -cv_hdr.signal_level_dbm;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm = TRUE;
|
2014-10-29 23:03:08 +00:00
|
|
|
}
|
2021-04-19 03:15:23 +00:00
|
|
|
if (cv_hdr.noise_level_dbm != 0) {
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm = -cv_hdr.noise_level_dbm;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm = TRUE;
|
2014-10-29 23:03:08 +00:00
|
|
|
}
|
2021-03-10 19:09:57 +00:00
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy == PHDR_802_11_PHY_UNKNOWN) {
|
|
|
|
/*
|
|
|
|
* We don't know they PHY, but we do have the
|
|
|
|
* data rate; try to guess it based on the
|
|
|
|
* data rate and center frequency.
|
|
|
|
*/
|
|
|
|
if (RATE_IS_DSSS(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) {
|
|
|
|
/* 11b */
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE;
|
|
|
|
} else if (RATE_IS_OFDM(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) {
|
|
|
|
/* 11a or 11g, depending on the band. */
|
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency) {
|
|
|
|
if (FREQ_IS_BG(rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency)) {
|
|
|
|
/* 11g */
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
|
|
|
|
} else {
|
|
|
|
/* 11a */
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy == PHDR_802_11_PHY_11G) {
|
|
|
|
if (RATE_IS_DSSS(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) {
|
|
|
|
/* DSSS, so 11b. */
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 23:14:17 +00:00
|
|
|
break;
|
2011-09-01 04:14:54 +00:00
|
|
|
|
2012-10-17 20:28:22 +00:00
|
|
|
case MEDIUM_TOKEN_RING :
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_TOKEN_RING;
|
2013-05-16 23:14:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("commview: unsupported encap for NCF: %u",
|
2013-05-16 23:14:17 +00:00
|
|
|
cv_hdr.flags & FLAGS_MEDIUM);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2011-09-01 04:14:54 +00:00
|
|
|
}
|
2012-10-17 20:28:22 +00:00
|
|
|
|
2013-05-16 23:14:17 +00:00
|
|
|
tm.tm_year = cv_hdr.year - 1900;
|
|
|
|
tm.tm_mon = cv_hdr.month - 1;
|
|
|
|
tm.tm_mday = cv_hdr.day;
|
|
|
|
tm.tm_hour = cv_hdr.hours;
|
|
|
|
tm.tm_min = cv_hdr.minutes;
|
|
|
|
tm.tm_sec = cv_hdr.seconds;
|
|
|
|
tm.tm_isdst = -1;
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_type = REC_TYPE_PACKET;
|
2021-08-30 02:12:13 +00:00
|
|
|
rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->presence_flags = WTAP_HAS_TS;
|
2013-05-16 23:14:17 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.len = cv_hdr.data_len;
|
|
|
|
rec->rec_header.packet_header.caplen = cv_hdr.data_len;
|
2013-05-16 23:14:17 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->ts.secs = mktime(&tm);
|
|
|
|
rec->ts.nsecs = cv_hdr.usecs * 1000;
|
2013-05-16 23:14:17 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info);
|
2011-09-01 04:14:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
|
|
|
gchar **err_info, gint64 *data_offset)
|
2013-05-16 23:23:08 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
return commview_ncf_read_packet(wth->fh, rec, buf, err, err_info);
|
2007-11-24 03:33:18 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
|
|
|
|
Buffer *buf, int *err, gchar **err_info)
|
2007-11-24 03:33:18 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
return commview_ncf_read_packet(wth->random_fh, rec, buf, err, err_info);
|
2007-11-24 03:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_read_header(commview_ncf_header_t *cv_hdr, FILE_T fh, int *err,
|
2011-04-21 09:41:52 +00:00
|
|
|
gchar **err_info)
|
2007-11-24 03:33:18 +00:00
|
|
|
{
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes_or_eof(fh, &cv_hdr->data_len, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->source_data_len, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->version, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->year, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->month, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->day, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->hours, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->minutes, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->seconds, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->usecs, 4, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->flags, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->signal_level_percent, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->rate, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->band, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->channel, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->direction, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->signal_level_dbm, 1, err, err_info))
|
|
|
|
return FALSE;
|
2021-04-19 03:15:23 +00:00
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->noise_level_dbm, 1, err, err_info))
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
return FALSE;
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* Convert multi-byte values from little endian to host endian format */
|
|
|
|
cv_hdr->data_len = GUINT16_FROM_LE(cv_hdr->data_len);
|
|
|
|
cv_hdr->source_data_len = GUINT16_FROM_LE(cv_hdr->source_data_len);
|
|
|
|
cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year);
|
|
|
|
cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-10-01 13:57:41 +00:00
|
|
|
/* Returns 0 if we can write out the specified encapsulation type
|
2007-11-26 05:34:07 +00:00
|
|
|
* into a CommView format file. */
|
2021-04-16 18:24:52 +00:00
|
|
|
static int
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_dump_can_write_encap(int encap)
|
2007-11-26 05:34:07 +00:00
|
|
|
{
|
|
|
|
switch (encap) {
|
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET :
|
|
|
|
case WTAP_ENCAP_IEEE_802_11 :
|
2007-11-27 05:43:29 +00:00
|
|
|
case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
|
2007-11-26 05:34:07 +00:00
|
|
|
case WTAP_ENCAP_TOKEN_RING :
|
|
|
|
case WTAP_ENCAP_PER_PACKET :
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2014-12-17 06:40:45 +00:00
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
2007-11-26 05:34:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns TRUE on success, FALSE on failure;
|
|
|
|
sets "*err" to an error code on failure */
|
2021-04-16 18:24:52 +00:00
|
|
|
static gboolean
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
|
2007-11-26 05:34:07 +00:00
|
|
|
{
|
2021-04-19 03:15:23 +00:00
|
|
|
wdh->subtype_write = commview_ncf_dump;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2007-11-26 05:34:07 +00:00
|
|
|
/* There is no file header to write out */
|
|
|
|
wdh->bytes_dumped = 0;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2007-11-26 05:34:07 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a record for a packet to a dump file.
|
|
|
|
* Returns TRUE on success, FALSE on failure. */
|
2021-04-19 03:15:23 +00:00
|
|
|
static gboolean
|
|
|
|
commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd,
|
|
|
|
int *err, gchar **err_info _U_)
|
2007-11-26 05:34:07 +00:00
|
|
|
{
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_header_t cv_hdr = {0};
|
2011-09-01 04:14:54 +00:00
|
|
|
struct tm *tm;
|
2007-11-26 05:34:07 +00:00
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
/* We can only write packet records. */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_type != REC_TYPE_PACKET) {
|
2014-12-18 00:31:49 +00:00
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_TYPE;
|
2014-05-24 18:28:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
/* Don't write out anything bigger than we can read.
|
|
|
|
* (The length field in packet headers is 16 bits, which
|
|
|
|
* imposes a hard limit.) */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_header.packet_header.caplen > 65535) {
|
2014-01-22 00:26:36 +00:00
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
cv_hdr.data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen);
|
|
|
|
cv_hdr.source_data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen);
|
2007-11-26 05:34:07 +00:00
|
|
|
cv_hdr.version = 0;
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
tm = localtime(&rec->ts.secs);
|
2016-10-22 02:18:15 +00:00
|
|
|
if (tm != NULL) {
|
2019-09-04 20:27:45 +00:00
|
|
|
cv_hdr.year = GUINT16_TO_LE(tm->tm_year + 1900);
|
2016-10-22 02:18:15 +00:00
|
|
|
cv_hdr.month = tm->tm_mon + 1;
|
|
|
|
cv_hdr.day = tm->tm_mday;
|
|
|
|
cv_hdr.hours = tm->tm_hour;
|
|
|
|
cv_hdr.minutes = tm->tm_min;
|
|
|
|
cv_hdr.seconds = tm->tm_sec;
|
2018-02-09 00:19:12 +00:00
|
|
|
cv_hdr.usecs = GUINT32_TO_LE(rec->ts.nsecs / 1000);
|
2016-10-22 02:18:15 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Second before the Epoch.
|
|
|
|
*/
|
2019-09-04 20:27:45 +00:00
|
|
|
cv_hdr.year = GUINT16_TO_LE(1969);
|
2016-10-22 02:18:15 +00:00
|
|
|
cv_hdr.month = 12;
|
|
|
|
cv_hdr.day = 31;
|
|
|
|
cv_hdr.hours = 23;
|
|
|
|
cv_hdr.minutes = 59;
|
|
|
|
cv_hdr.seconds = 59;
|
|
|
|
cv_hdr.usecs = 0;
|
|
|
|
}
|
2007-11-26 05:34:07 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
switch(rec->rec_header.packet_header.pkt_encap) {
|
2007-11-26 05:34:07 +00:00
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET :
|
|
|
|
cv_hdr.flags |= MEDIUM_ETHERNET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_IEEE_802_11 :
|
|
|
|
cv_hdr.flags |= MEDIUM_WIFI;
|
|
|
|
break;
|
|
|
|
|
2007-11-27 05:43:29 +00:00
|
|
|
case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
|
|
|
|
cv_hdr.flags |= MEDIUM_WIFI;
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
switch (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy) {
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11A:
|
|
|
|
/*
|
|
|
|
* If we don't know whether it's turbo, say it's
|
|
|
|
* not.
|
|
|
|
*/
|
2018-02-09 00:19:12 +00:00
|
|
|
if (!rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type ||
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type == PHDR_802_11A_TURBO_TYPE_NORMAL)
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
cv_hdr.band = BAND_11A;
|
|
|
|
else
|
|
|
|
cv_hdr.band = BAND_11A_TURBO;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11B:
|
|
|
|
cv_hdr.band = BAND_11B;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11G:
|
|
|
|
/*
|
|
|
|
* If we don't know whether it's Super G, say it's
|
|
|
|
* not.
|
|
|
|
*/
|
2018-02-09 00:19:12 +00:00
|
|
|
if (!rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode)
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
cv_hdr.band = BAND_11G;
|
|
|
|
else {
|
2018-02-09 00:19:12 +00:00
|
|
|
switch (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode) {
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
|
|
|
|
case PHDR_802_11G_MODE_NORMAL:
|
|
|
|
cv_hdr.band = BAND_11G;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11G_MODE_SUPER_G:
|
|
|
|
cv_hdr.band = BAND_SUPERG;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
cv_hdr.band = BAND_11G;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11N:
|
|
|
|
/*
|
|
|
|
* Pick the band based on the frequency.
|
|
|
|
*/
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency) {
|
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency > 2484) {
|
Clean up 802.11 radio information handling.
Have a field that holds the PHY type but nothing else. Have
a union with structures holding PHY-type-specific information, as a
bunch of attributes are PHY-specific.
If we have a channel and band, but don't have the frequency, attempt to
calculate the frequency, and add that to the radio information if we
succeed. If we have the frequency, but don't have the channel, attempt
to calculate the channel, and add that to the radio information if we
succeed.
Handle FHSS information, 11a "half/quarter-clocked" and turbo
information, 11g normal vs. Super G, additional 11n and 11ac
information, and the "short preamble" flag for 11b and 11g.
Add a PHY type for 11 legacy DSSS and detect it if possible.
Clean up the AVS dissector - make all fields wlancap. fields (if you
want generic fields, use the wlan_radio. fields).
Set more fields when writing out Commview Wi-Fi files.
Change-Id: I691ac59f5e9e1a23779b56a65124049914b72e69
Reviewed-on: https://code.wireshark.org/review/9146
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-06-25 19:14:39 +00:00
|
|
|
/* 5 GHz band */
|
|
|
|
cv_hdr.band = BAND_11N_5GHZ;
|
|
|
|
} else {
|
|
|
|
/* 2.4 GHz band */
|
|
|
|
cv_hdr.band = BAND_11N_2_4GHZ;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Band is unknown. */
|
|
|
|
cv_hdr.band = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* It's not documented how they handle 11ac,
|
|
|
|
* and they don't support the older PHYs.
|
|
|
|
*/
|
|
|
|
cv_hdr.band = 0;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-29 23:03:08 +00:00
|
|
|
cv_hdr.channel =
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel ?
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel :
|
2015-12-09 22:26:46 +00:00
|
|
|
0;
|
2014-10-29 23:03:08 +00:00
|
|
|
cv_hdr.rate =
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ?
|
|
|
|
(guint8)(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate & 0xFF) :
|
2015-12-09 22:26:46 +00:00
|
|
|
0;
|
2014-10-29 23:03:08 +00:00
|
|
|
cv_hdr.direction =
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ?
|
|
|
|
(guint8)((rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate >> 8) & 0xFF) :
|
2015-12-09 22:26:46 +00:00
|
|
|
0;
|
2014-10-29 23:03:08 +00:00
|
|
|
cv_hdr.signal_level_percent =
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent ?
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent :
|
2015-12-09 22:26:46 +00:00
|
|
|
0;
|
2014-10-29 23:03:08 +00:00
|
|
|
cv_hdr.signal_level_dbm =
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm ?
|
|
|
|
-rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm :
|
2015-12-09 22:26:46 +00:00
|
|
|
0;
|
2021-04-19 03:15:23 +00:00
|
|
|
cv_hdr.noise_level_dbm =
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm ?
|
|
|
|
-rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm :
|
2015-12-09 22:26:46 +00:00
|
|
|
0;
|
2007-11-27 05:43:29 +00:00
|
|
|
break;
|
|
|
|
|
2007-11-26 05:34:07 +00:00
|
|
|
case WTAP_ENCAP_TOKEN_RING :
|
|
|
|
cv_hdr.flags |= MEDIUM_TOKEN_RING;
|
2011-03-27 13:15:14 +00:00
|
|
|
break;
|
2007-11-26 05:34:07 +00:00
|
|
|
|
|
|
|
default :
|
2014-12-17 06:40:45 +00:00
|
|
|
*err = WTAP_ERR_UNWRITABLE_ENCAP;
|
2007-11-26 05:34:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.data_len, 2, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.source_data_len, 2, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.version, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.year, 2, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.month, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.day, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.hours, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.minutes, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.seconds, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.usecs, 4, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.flags, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_percent, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.rate, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.band, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.channel, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.direction, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2019-09-04 19:56:27 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_dbm, 1, err))
|
2010-12-20 23:34:14 +00:00
|
|
|
return FALSE;
|
2021-04-19 03:15:23 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.noise_level_dbm, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
wdh->bytes_dumped += COMMVIEW_NCF_HEADER_SIZE;
|
|
|
|
|
|
|
|
if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err))
|
|
|
|
return FALSE;
|
|
|
|
wdh->bytes_dumped += rec->rec_header.packet_header.caplen;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct commview_ncfx_header {
|
|
|
|
guint32 data_len;
|
|
|
|
guint16 year;
|
|
|
|
guint8 month;
|
|
|
|
guint8 day;
|
|
|
|
guint8 hours;
|
|
|
|
guint8 minutes;
|
|
|
|
guint8 seconds;
|
|
|
|
guint32 usecs;
|
|
|
|
guint8 medium_type;
|
|
|
|
guint8 decryption_flag;
|
|
|
|
guint8 direction;
|
|
|
|
guint8 reserved1;
|
|
|
|
guint8 reserved2;
|
|
|
|
} commview_ncfx_header_t;
|
|
|
|
|
|
|
|
#define COMMVIEW_NCFX_HEADER_SIZE 20
|
|
|
|
|
|
|
|
typedef struct commview_ncfx_rf_header {
|
|
|
|
guint16 header_len; /* includes extension headers */
|
|
|
|
guint16 status_modulation;
|
|
|
|
guint16 frequency_band;
|
|
|
|
guint16 channel;
|
|
|
|
guint8 noise_level_dbm; /* abs(noise in dBm) */
|
|
|
|
guint8 signal_level_dbm; /* abs(signal in dBm) */
|
|
|
|
guint8 signal_level_percent;
|
|
|
|
guint8 reserved;
|
|
|
|
guint32 phy_rate; /* in 100Kbps units */
|
|
|
|
guint32 extensions_present;
|
|
|
|
} commview_ncfx_rf_header_t;
|
|
|
|
|
|
|
|
#define COMMVIEW_NCFX_RF_HEADER_SIZE 20
|
|
|
|
|
|
|
|
typedef struct commview_ncfx_mcs_header {
|
|
|
|
guint8 mcs_index;
|
|
|
|
guint8 n_streams;
|
|
|
|
guint8 channel_width;
|
|
|
|
guint8 guard_interval;
|
|
|
|
} commview_ncfx_mcs_header_t;
|
|
|
|
|
|
|
|
#define COMMVIEW_NCFX_MCS_HEADER_SIZE 4
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bit-field positions for various fields in the status_modulation variable
|
|
|
|
* of the header.
|
|
|
|
*/
|
|
|
|
#define STATUS_MODULATION_BAD_FCS 0x01
|
|
|
|
#define STATUS_MODULATION_HT_PHY 0x02
|
|
|
|
#define STATUS_MODULATION_VHT_PHY 0x04
|
|
|
|
#define STATUS_MODULATION_HE_PHY 0x08
|
|
|
|
#define STATUS_MODULATION_HE_OFDMA 0x10
|
|
|
|
|
|
|
|
/* Values for the frequency_band variable of the header */
|
|
|
|
#define BAND_5GHZ 0x40
|
|
|
|
#define BAND_2_4GHZ 0x80
|
|
|
|
|
|
|
|
/* Presence bits */
|
|
|
|
#define PRESENCE_MCS_HEADER 0x00000001 /* type 0, bit 0 */
|
|
|
|
|
|
|
|
static gboolean commview_ncfx_read(wtap *wth, wtap_rec *rec, Buffer *buf,
|
|
|
|
int *err, gchar **err_info, gint64 *data_offset);
|
|
|
|
static gboolean commview_ncfx_seek_read(wtap *wth, gint64 seek_off,
|
|
|
|
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info);
|
|
|
|
static gboolean commview_ncfx_read_header(commview_ncfx_header_t *cv_hdr,
|
|
|
|
FILE_T fh, int *err, gchar **err_info);
|
|
|
|
static gboolean commview_ncfx_read_rf_header(commview_ncfx_rf_header_t *cv_rf_hdr,
|
|
|
|
FILE_T fh, int *err, gchar **err_info);
|
|
|
|
static gboolean commview_ncfx_read_mcs_header(commview_ncfx_mcs_header_t *cv_mcs_hdr,
|
|
|
|
FILE_T fh, int *err, gchar **err_info);
|
|
|
|
static gboolean commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec,
|
|
|
|
const guint8 *pd, int *err, gchar **err_info);
|
|
|
|
|
|
|
|
wtap_open_return_val
|
|
|
|
commview_ncfx_open(wtap *wth, int *err, gchar **err_info)
|
|
|
|
{
|
|
|
|
commview_ncfx_header_t cv_hdr;
|
|
|
|
|
|
|
|
if(!commview_ncfx_read_header(&cv_hdr, wth->fh, err, err_info)) {
|
|
|
|
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If any of these fields do not match what we expect, bail out. */
|
|
|
|
if(cv_hdr.year < 2000 || /* XXX - when was this format introduced? */
|
|
|
|
cv_hdr.month < 1 || cv_hdr.month > 12 ||
|
|
|
|
cv_hdr.day < 1 || cv_hdr.day > 31 ||
|
|
|
|
cv_hdr.hours > 23 ||
|
|
|
|
cv_hdr.minutes > 59 ||
|
|
|
|
cv_hdr.seconds > 60)
|
|
|
|
return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
|
|
|
|
switch (cv_hdr.medium_type) {
|
|
|
|
|
|
|
|
case MEDIUM_ETHERNET:
|
|
|
|
if (cv_hdr.direction != 0x00 &&
|
|
|
|
cv_hdr.direction != 0x01 &&
|
|
|
|
cv_hdr.direction != 0x02)
|
|
|
|
return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEDIUM_WIFI:
|
|
|
|
if (cv_hdr.decryption_flag != 0x00 &&
|
|
|
|
cv_hdr.decryption_flag != 0x01)
|
|
|
|
return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
|
|
|
|
if (cv_hdr.direction != 0x00)
|
|
|
|
return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No file header. Reset the fh to 0 so we can read the first packet */
|
|
|
|
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
|
|
|
|
/* Set up the pointers to the handlers for this file type */
|
|
|
|
wth->subtype_read = commview_ncfx_read;
|
|
|
|
wth->subtype_seek_read = commview_ncfx_seek_read;
|
|
|
|
|
|
|
|
wth->file_type_subtype = commview_ncfx_file_type_subtype;
|
|
|
|
wth->file_encap = WTAP_ENCAP_PER_PACKET;
|
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
|
|
|
|
|
|
|
return WTAP_OPEN_MINE; /* Our kind of file */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
|
|
|
|
int *err, gchar **err_info)
|
|
|
|
{
|
|
|
|
commview_ncfx_header_t cv_hdr;
|
|
|
|
guint32 length_remaining;
|
|
|
|
struct tm tm;
|
|
|
|
commview_ncfx_rf_header_t cv_rf_hdr;
|
|
|
|
guint frequency;
|
|
|
|
commview_ncfx_mcs_header_t cv_mcs_hdr;
|
|
|
|
|
|
|
|
if (!commview_ncfx_read_header(&cv_hdr, fh, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Amount of data remaining in the record, after the header */
|
|
|
|
length_remaining = cv_hdr.data_len - COMMVIEW_NCFX_HEADER_SIZE;
|
|
|
|
|
|
|
|
switch(cv_hdr.medium_type) {
|
|
|
|
|
|
|
|
case MEDIUM_ETHERNET :
|
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.eth.fcs_len = -1; /* Unknown */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEDIUM_WIFI :
|
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
|
|
|
|
memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11));
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; /* No FCS */
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = (cv_hdr.decryption_flag == 0x01);
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we have enough data left for the RF header.
|
|
|
|
*/
|
|
|
|
if (length_remaining < COMMVIEW_NCFX_RF_HEADER_SIZE) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("commview: RF header goes past the NCFX data length %u",
|
2021-04-19 03:15:23 +00:00
|
|
|
cv_hdr.data_len);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
length_remaining -= COMMVIEW_NCFX_RF_HEADER_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the RF header.
|
|
|
|
*/
|
|
|
|
if (!commview_ncfx_read_rf_header(&cv_rf_hdr, fh, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (cv_rf_hdr.status_modulation & STATUS_MODULATION_HE_PHY)
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11AX;
|
|
|
|
else if (cv_rf_hdr.status_modulation & STATUS_MODULATION_VHT_PHY)
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11AC;
|
|
|
|
else if (cv_rf_hdr.status_modulation & STATUS_MODULATION_HT_PHY)
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Unknown PHY, for now.
|
|
|
|
*/
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN;
|
|
|
|
}
|
|
|
|
switch (cv_rf_hdr.frequency_band) {
|
|
|
|
|
|
|
|
case BAND_5GHZ:
|
|
|
|
frequency = ieee80211_chan_to_mhz(cv_rf_hdr.channel, FALSE);
|
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy == PHDR_802_11_PHY_UNKNOWN) {
|
|
|
|
/*
|
|
|
|
* None of the modulation bits were set, so
|
|
|
|
* this is presumably the 11a OFDM PHY.
|
|
|
|
*/
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BAND_2_4GHZ:
|
|
|
|
frequency = ieee80211_chan_to_mhz(cv_rf_hdr.channel, TRUE);
|
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy == PHDR_802_11_PHY_UNKNOWN) {
|
|
|
|
/*
|
|
|
|
* None of the modulation bits were set, so
|
|
|
|
* guess the PHY based on the data rate.
|
|
|
|
*
|
|
|
|
* cv_rf_hdr.phy_rate is in units of 100
|
|
|
|
* Kbits/s.
|
|
|
|
*/
|
|
|
|
if (cv_rf_hdr.phy_rate == 10 /* 1 Mb/s */ ||
|
|
|
|
cv_rf_hdr.phy_rate == 20 /* 2 Mb/s */ ||
|
|
|
|
cv_rf_hdr.phy_rate == 55 /* 5.5 Mb/s */ ||
|
|
|
|
cv_rf_hdr.phy_rate == 110 /* 11 Mb/s */ ||
|
|
|
|
cv_rf_hdr.phy_rate == 220 /* 22 Mb/s */ ||
|
|
|
|
cv_rf_hdr.phy_rate == 330 /* 33 Mb/s */)
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B;
|
|
|
|
else
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
frequency = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (frequency != 0) {
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency = frequency;
|
|
|
|
}
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = cv_rf_hdr.channel;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_rf_hdr.phy_rate is in units of 100 Kbits/s.
|
|
|
|
*
|
|
|
|
* pseudo_header.ieee_802_11.data_rate is in units of 500
|
|
|
|
* Kbits/s.
|
|
|
|
*/
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate =
|
|
|
|
cv_rf_hdr.phy_rate/5;
|
|
|
|
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = cv_rf_hdr.signal_level_percent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These is the absolute value of the signal and noise,
|
|
|
|
* in dBm. The value is the negative of that.
|
|
|
|
*
|
|
|
|
* XXX - sometimes these are 0; assume that means that no
|
|
|
|
* value is provided.
|
|
|
|
*/
|
|
|
|
if (cv_rf_hdr.signal_level_dbm != 0) {
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm = -cv_rf_hdr.signal_level_dbm;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm = TRUE;
|
|
|
|
}
|
|
|
|
if (cv_rf_hdr.noise_level_dbm != 0) {
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm = -cv_rf_hdr.noise_level_dbm;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cv_rf_hdr.extensions_present & PRESENCE_MCS_HEADER) {
|
|
|
|
/*
|
|
|
|
* Make sure we have enough data left for the
|
|
|
|
* MCS header.
|
|
|
|
*/
|
|
|
|
if (length_remaining < COMMVIEW_NCFX_MCS_HEADER_SIZE) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("commview: MCS header goes past the NCFX data length %u",
|
2021-04-19 03:15:23 +00:00
|
|
|
cv_hdr.data_len);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
length_remaining -= COMMVIEW_NCFX_MCS_HEADER_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the MCS header.
|
|
|
|
*/
|
|
|
|
if (!commview_ncfx_read_mcs_header(&cv_mcs_hdr, fh,
|
|
|
|
err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
switch (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy) {
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11N:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_mcs_index = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.mcs_index = cv_mcs_hdr.mcs_index;
|
|
|
|
/* number of STBC streams? */
|
|
|
|
switch (cv_mcs_hdr.channel_width) {
|
|
|
|
|
|
|
|
case 0x00:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_20_MHZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x01:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_40_MHZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Guard interval? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11AC:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.mcs[0] = cv_mcs_hdr.mcs_index;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.mcs[1] = 0;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.mcs[2] = 0;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.mcs[3] = 0;
|
|
|
|
/* Remaining MCS indices? */
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.nss[0] = cv_mcs_hdr.n_streams;
|
|
|
|
switch (cv_mcs_hdr.channel_width) {
|
|
|
|
|
|
|
|
case 0x00:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.bandwidth = PHDR_802_11_BANDWIDTH_20_MHZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x01:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.bandwidth = PHDR_802_11_BANDWIDTH_40_MHZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.bandwidth = PHDR_802_11_BANDWIDTH_80_MHZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Guard interval? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11AX:
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ax.has_mcs_index = TRUE;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ax.mcs = cv_mcs_hdr.mcs_index;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ax.nsts = cv_mcs_hdr.n_streams;
|
|
|
|
/* Bandwidth stuff? */
|
|
|
|
/* Guard interval? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("commview: unsupported encap for NCFX: %u",
|
2021-04-19 03:15:23 +00:00
|
|
|
cv_hdr.medium_type);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tm.tm_year = cv_hdr.year - 1900;
|
|
|
|
tm.tm_mon = cv_hdr.month - 1;
|
|
|
|
tm.tm_mday = cv_hdr.day;
|
|
|
|
tm.tm_hour = cv_hdr.hours;
|
|
|
|
tm.tm_min = cv_hdr.minutes;
|
|
|
|
tm.tm_sec = cv_hdr.seconds;
|
|
|
|
tm.tm_isdst = -1;
|
|
|
|
|
|
|
|
rec->rec_type = REC_TYPE_PACKET;
|
2021-08-30 02:12:13 +00:00
|
|
|
rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
|
2021-04-19 03:15:23 +00:00
|
|
|
rec->presence_flags = WTAP_HAS_TS;
|
|
|
|
|
|
|
|
if (length_remaining > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
|
|
|
/*
|
|
|
|
* Probably a corrupt capture file; don't blow up trying
|
|
|
|
* to allocate space for an immensely-large packet.
|
|
|
|
*/
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("commview: File has %u-byte packet, bigger than maximum of %u",
|
2021-04-19 03:15:23 +00:00
|
|
|
length_remaining, WTAP_MAX_PACKET_SIZE_STANDARD);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec->rec_header.packet_header.len = length_remaining;
|
|
|
|
rec->rec_header.packet_header.caplen = length_remaining;
|
|
|
|
|
|
|
|
rec->ts.secs = mktime(&tm);
|
|
|
|
rec->ts.nsecs = cv_hdr.usecs * 1000;
|
|
|
|
|
|
|
|
return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
commview_ncfx_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
|
|
|
gchar **err_info, gint64 *data_offset)
|
|
|
|
{
|
|
|
|
*data_offset = file_tell(wth->fh);
|
|
|
|
|
|
|
|
return commview_ncfx_read_packet(wth->fh, rec, buf, err, err_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
commview_ncfx_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
|
|
|
|
Buffer *buf, int *err, gchar **err_info)
|
|
|
|
{
|
|
|
|
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return commview_ncfx_read_packet(wth->random_fh, rec, buf, err, err_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
commview_ncfx_read_header(commview_ncfx_header_t *cv_hdr, FILE_T fh, int *err,
|
|
|
|
gchar **err_info)
|
|
|
|
{
|
|
|
|
if (!wtap_read_bytes_or_eof(fh, &cv_hdr->data_len, 4, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Convert data length from little endian to host endian format */
|
|
|
|
cv_hdr->data_len = GUINT32_FROM_LE(cv_hdr->data_len);
|
|
|
|
|
|
|
|
/* It must be at least the length of the general header. */
|
|
|
|
if (cv_hdr->data_len < COMMVIEW_NCFX_HEADER_SIZE) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("commview: NCFX data length %u < %u",
|
2021-04-19 03:15:23 +00:00
|
|
|
cv_hdr->data_len,
|
|
|
|
COMMVIEW_NCFX_HEADER_SIZE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->year, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->month, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->day, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->hours, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->minutes, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->seconds, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->usecs, 4, err, err_info))
|
2007-11-26 05:34:07 +00:00
|
|
|
return FALSE;
|
2021-04-19 03:15:23 +00:00
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->medium_type, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->decryption_flag, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->direction, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->reserved1, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->reserved2, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Convert multi-byte values from little endian to host endian format */
|
|
|
|
cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year);
|
|
|
|
cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
commview_ncfx_read_rf_header(commview_ncfx_rf_header_t *cv_rf_hdr, FILE_T fh,
|
|
|
|
int *err, gchar **err_info)
|
|
|
|
{
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->header_len, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Convert header length from little endian to host endian format */
|
|
|
|
cv_rf_hdr->header_len = GUINT16_FROM_LE(cv_rf_hdr->header_len);
|
|
|
|
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->status_modulation, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->frequency_band, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->channel, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->noise_level_dbm, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->signal_level_dbm, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->signal_level_percent, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->reserved, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->phy_rate, 4, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_rf_hdr->extensions_present, 4, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Convert remaining multi-byte values from little endian to host endian format */
|
|
|
|
cv_rf_hdr->status_modulation = GUINT16_FROM_LE(cv_rf_hdr->status_modulation);
|
|
|
|
cv_rf_hdr->frequency_band = GUINT16_FROM_LE(cv_rf_hdr->frequency_band);
|
|
|
|
cv_rf_hdr->channel = GUINT16_FROM_LE(cv_rf_hdr->channel);
|
|
|
|
cv_rf_hdr->phy_rate = GUINT32_FROM_LE(cv_rf_hdr->phy_rate);
|
|
|
|
cv_rf_hdr->extensions_present = GUINT32_FROM_LE(cv_rf_hdr->extensions_present);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
commview_ncfx_read_mcs_header(commview_ncfx_mcs_header_t *cv_mcs_hdr, FILE_T fh,
|
|
|
|
int *err, gchar **err_info)
|
|
|
|
{
|
|
|
|
if (!wtap_read_bytes(fh, &cv_mcs_hdr->mcs_index, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_mcs_hdr->n_streams, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_mcs_hdr->channel_width, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_mcs_hdr->guard_interval, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 if we can write out the specified encapsulation type
|
|
|
|
* into a CommView format file. */
|
|
|
|
static int
|
|
|
|
commview_ncfx_dump_can_write_encap(int encap)
|
|
|
|
{
|
|
|
|
switch (encap) {
|
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET :
|
|
|
|
case WTAP_ENCAP_IEEE_802_11 :
|
|
|
|
case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
|
|
|
|
case WTAP_ENCAP_PER_PACKET :
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns TRUE on success, FALSE on failure;
|
|
|
|
sets "*err" to an error code on failure */
|
|
|
|
static gboolean
|
|
|
|
commview_ncfx_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
|
|
|
|
{
|
|
|
|
wdh->subtype_write = commview_ncfx_dump;
|
|
|
|
|
|
|
|
/* There is no file header to write out */
|
|
|
|
wdh->bytes_dumped = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a record for a packet to a dump file.
|
|
|
|
* Returns TRUE on success, FALSE on failure. */
|
|
|
|
static gboolean
|
|
|
|
commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd,
|
|
|
|
int *err, gchar **err_info _U_)
|
|
|
|
{
|
|
|
|
commview_ncfx_header_t cv_hdr = {0};
|
|
|
|
struct tm *tm;
|
|
|
|
|
|
|
|
/* We can only write packet records. */
|
|
|
|
if (rec->rec_type != REC_TYPE_PACKET) {
|
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_TYPE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't write out anything bigger than we can read.
|
|
|
|
* (The length field in packet headers is 16 bits, which
|
|
|
|
* imposes a hard limit.) */
|
|
|
|
if (rec->rec_header.packet_header.caplen > 65535) {
|
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cv_hdr.data_len = GUINT32_TO_LE((guint32)rec->rec_header.packet_header.caplen);
|
|
|
|
|
|
|
|
tm = localtime(&rec->ts.secs);
|
|
|
|
if (tm != NULL) {
|
|
|
|
cv_hdr.year = GUINT16_TO_LE(tm->tm_year + 1900);
|
|
|
|
cv_hdr.month = tm->tm_mon + 1;
|
|
|
|
cv_hdr.day = tm->tm_mday;
|
|
|
|
cv_hdr.hours = tm->tm_hour;
|
|
|
|
cv_hdr.minutes = tm->tm_min;
|
|
|
|
cv_hdr.seconds = tm->tm_sec;
|
|
|
|
cv_hdr.usecs = GUINT32_TO_LE(rec->ts.nsecs / 1000);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Second before the Epoch.
|
|
|
|
*/
|
|
|
|
cv_hdr.year = GUINT16_TO_LE(1969);
|
|
|
|
cv_hdr.month = 12;
|
|
|
|
cv_hdr.day = 31;
|
|
|
|
cv_hdr.hours = 23;
|
|
|
|
cv_hdr.minutes = 59;
|
|
|
|
cv_hdr.seconds = 59;
|
|
|
|
cv_hdr.usecs = 0;
|
|
|
|
}
|
|
|
|
cv_hdr.reserved1 = 0;
|
|
|
|
cv_hdr.reserved2 = 0;
|
|
|
|
|
|
|
|
switch(rec->rec_header.packet_header.pkt_encap) {
|
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET :
|
|
|
|
cv_hdr.medium_type = MEDIUM_ETHERNET;
|
|
|
|
cv_hdr.decryption_flag = 0x00;
|
|
|
|
cv_hdr.direction = 0x00; /* what does this mean? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_IEEE_802_11 :
|
|
|
|
/* XXX - the claim is that the RF header is mandatory */
|
|
|
|
cv_hdr.medium_type = MEDIUM_WIFI;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
|
|
|
|
cv_hdr.medium_type = MEDIUM_WIFI;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
switch (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy) {
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11N:
|
|
|
|
cv_hdr.status_modulation = STATUS_MODULATION_HT_PHY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11AC:
|
|
|
|
cv_hdr.status_modulation = STATUS_MODULATION_VHT_PHY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHDR_802_11_PHY_11AX:
|
|
|
|
cv_hdr.status_modulation = STATUS_MODULATION_HE_PHY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
cv_hdr.status_modulation = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pick the band based on the frequency.
|
|
|
|
*/
|
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency) {
|
|
|
|
if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency > 2484) {
|
|
|
|
/* 5 GHz band */
|
|
|
|
cv_hdr.frequency_band = BAND_5GHZ;
|
|
|
|
} else {
|
|
|
|
/* 2.4 GHz band */
|
|
|
|
cv_hdr.frequency_band = BAND_2_4GHZ;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Band is unknown. */
|
|
|
|
cv_hdr.band = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cv_hdr.channel =
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel ?
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel :
|
|
|
|
0;
|
|
|
|
cv_hdr.noise_level_dbm =
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm ?
|
|
|
|
-rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm :
|
|
|
|
0;
|
|
|
|
cv_hdr.signal_level_dbm =
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm ?
|
|
|
|
-rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm :
|
|
|
|
0;
|
|
|
|
cv_hdr.signal_level_percent =
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent ?
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent :
|
|
|
|
0;
|
|
|
|
cv_hdr.reserved = 0;
|
|
|
|
cv_hdr.phy_rate =
|
|
|
|
rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ?
|
|
|
|
(guint32)(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate & 0xFF) :
|
|
|
|
0;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
*err = WTAP_ERR_UNWRITABLE_ENCAP;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.data_len, 4, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.year, 2, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.month, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.day, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.hours, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.minutes, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.seconds, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.usecs, 4, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.medium_type, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.decryption_flag, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.direction, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.reserved1, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.reserved2, 1, err))
|
|
|
|
return FALSE;
|
|
|
|
wdh->bytes_dumped += COMMVIEW_NCFX_HEADER_SIZE;
|
|
|
|
|
|
|
|
/* XXX - RF and MCS headers */
|
2007-11-26 05:34:07 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err))
|
2007-11-26 05:34:07 +00:00
|
|
|
return FALSE;
|
2018-02-09 00:19:12 +00:00
|
|
|
wdh->bytes_dumped += rec->rec_header.packet_header.caplen;
|
2007-11-26 05:34:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-01-02 00:45:22 +00:00
|
|
|
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
static const struct supported_block_type commview_blocks_supported[] = {
|
|
|
|
/*
|
|
|
|
* We support packet blocks, with no comments or other options.
|
|
|
|
*/
|
|
|
|
{ WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED }
|
|
|
|
};
|
|
|
|
|
2021-04-19 03:15:23 +00:00
|
|
|
static const struct file_type_subtype_info commview_ncf_info = {
|
|
|
|
"TamoSoft CommView NCF", "commview-ncf", "ncf", NULL,
|
|
|
|
FALSE, BLOCKS_SUPPORTED(commview_blocks_supported),
|
|
|
|
commview_ncf_dump_can_write_encap, commview_ncf_dump_open, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_type_subtype_info commview_ncfx_info = {
|
|
|
|
"TamoSoft CommView NCFX", "commview-ncfx", "ncfx", NULL,
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
FALSE, BLOCKS_SUPPORTED(commview_blocks_supported),
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncfx_dump_can_write_encap, commview_ncfx_dump_open, NULL
|
wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in
wiretap/file_access.c and, instead, have the file types register
themselves, using wtap_register_file_type_subtypes().
This reduces the source code changes needed to add a new file type from
three (add the handler, add the file type to the table in file_access.c,
add a #define for the file type in wiretap/wtap.h) to one (add the
handler). (It also requires adding the handler's source file to
wiretap/CMakeLists.txt, but that's required in both cases.)
A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used
elsewhere; that needs to be fixed.
Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now
contains a registration routine. In the process, avoid scanning files
that don't implement a file type and won't ever have a registration
routine.
Add a Lua routine to fetch the total number of file types; we use that
in some code to construct the wtap_filetypes table, which we need to do
in order to continue to have all the values that used to come from the
WTAP_FILE_TYPE_SUBTYPE_ types.
While we're at it, add modelines to a file that lacked them.
2021-02-14 08:34:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void register_commview(void)
|
|
|
|
{
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_file_type_subtype = wtap_register_file_type_subtype(&commview_ncf_info);
|
|
|
|
commview_ncfx_file_type_subtype = wtap_register_file_type_subtype(&commview_ncfx_info);
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register name for backwards compatibility with the
|
|
|
|
* wtap_filetypes table in Lua.
|
2021-04-19 03:15:23 +00:00
|
|
|
*
|
|
|
|
* We don't need to register the new type, as the Wireshark
|
|
|
|
* version with which we're providing backwards compatibility
|
|
|
|
* didn't support the NCFX format. New code should fetch
|
|
|
|
* the file type/subtype with wtap_name_to_file_type_subtype().
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
*/
|
|
|
|
wtap_register_backwards_compatibility_lua_name("COMMVIEW",
|
2021-04-19 03:15:23 +00:00
|
|
|
commview_ncf_file_type_subtype);
|
wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in
wiretap/file_access.c and, instead, have the file types register
themselves, using wtap_register_file_type_subtypes().
This reduces the source code changes needed to add a new file type from
three (add the handler, add the file type to the table in file_access.c,
add a #define for the file type in wiretap/wtap.h) to one (add the
handler). (It also requires adding the handler's source file to
wiretap/CMakeLists.txt, but that's required in both cases.)
A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used
elsewhere; that needs to be fixed.
Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now
contains a registration routine. In the process, avoid scanning files
that don't implement a file type and won't ever have a registration
routine.
Add a Lua routine to fetch the total number of file types; we use that
in some code to construct the wtap_filetypes table, which we need to do
in order to continue to have all the values that used to come from the
WTAP_FILE_TYPE_SUBTYPE_ types.
While we're at it, add modelines to a file that lacked them.
2021-02-14 08:34:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2015-01-02 00:45:22 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|