2008-02-03 21:11:53 +00:00
|
|
|
/* btsnoop.c
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2008-02-03 21:11:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "file_wrappers.h"
|
|
|
|
#include "btsnoop.h"
|
2008-06-24 18:00:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Symbian's btsnoop format is derived from Sun's snoop format.
|
|
|
|
* See RFC 1761 for a description of the "snoop" file format.
|
2021-02-07 09:11:06 +00:00
|
|
|
* See
|
|
|
|
*
|
|
|
|
* https://gitlab.com/wireshark/wireshark/uploads/6d44fa94c164b58516e8577f44a6ccdc/btmodified_rfc1761.txt
|
|
|
|
*
|
|
|
|
* for a description of the btsnoop format.
|
2008-06-24 18:00:14 +00:00
|
|
|
*/
|
2008-02-03 21:11:53 +00:00
|
|
|
|
|
|
|
/* Magic number in "btsnoop" files. */
|
|
|
|
static const char btsnoop_magic[] = {
|
2015-01-02 00:45:22 +00:00
|
|
|
'b', 't', 's', 'n', 'o', 'o', 'p', '\0'
|
2008-02-03 21:11:53 +00:00
|
|
|
};
|
|
|
|
|
2008-06-24 18:00:14 +00:00
|
|
|
/* "btsnoop" file header (minus magic number). */
|
2008-02-03 21:11:53 +00:00
|
|
|
struct btsnoop_hdr {
|
2015-01-02 00:45:22 +00:00
|
|
|
guint32 version; /* version number (should be 1) */
|
|
|
|
guint32 datalink; /* datalink type */
|
2008-02-03 21:11:53 +00:00
|
|
|
};
|
|
|
|
|
2008-06-24 18:00:14 +00:00
|
|
|
/* "btsnoop" record header. */
|
2008-02-03 21:11:53 +00:00
|
|
|
struct btsnooprec_hdr {
|
2015-01-02 00:45:22 +00:00
|
|
|
guint32 orig_len; /* actual length of packet */
|
|
|
|
guint32 incl_len; /* number of octets captured in file */
|
|
|
|
guint32 flags; /* packet flags */
|
|
|
|
guint32 cum_drops; /* cumulative number of dropped packets */
|
|
|
|
gint64 ts_usec; /* timestamp microseconds */
|
2008-02-03 21:11:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* H1 is unframed data with the packet type encoded in the flags field of capture header */
|
|
|
|
/* It can be used for any datalink by placing logging above the datalink layer of HCI */
|
2015-01-02 00:45:22 +00:00
|
|
|
#define KHciLoggerDatalinkTypeH1 1001
|
2008-02-03 21:11:53 +00:00
|
|
|
/* H4 is the serial HCI with packet type encoded in the first byte of each packet */
|
2015-01-02 00:45:22 +00:00
|
|
|
#define KHciLoggerDatalinkTypeH4 1002
|
2008-02-03 21:11:53 +00:00
|
|
|
/* CSR's PPP derived bluecore serial protocol - in practice we log in H1 format after deframing */
|
2015-01-02 00:45:22 +00:00
|
|
|
#define KHciLoggerDatalinkTypeBCSP 1003
|
2008-02-03 21:11:53 +00:00
|
|
|
/* H5 is the official three wire serial protocol derived from BCSP*/
|
2015-01-02 00:45:22 +00:00
|
|
|
#define KHciLoggerDatalinkTypeH5 1004
|
2014-01-12 00:50:41 +00:00
|
|
|
/* Linux Monitor */
|
2015-01-02 00:45:22 +00:00
|
|
|
#define KHciLoggerDatalinkLinuxMonitor 2001
|
2013-11-23 21:41:08 +00:00
|
|
|
/* BlueZ 5 Simulator */
|
2015-01-02 00:45:22 +00:00
|
|
|
#define KHciLoggerDatalinkBlueZ5Simulator 2002
|
2008-02-03 21:11:53 +00:00
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
#define KHciLoggerHostToController 0
|
|
|
|
#define KHciLoggerControllerToHost 0x00000001
|
|
|
|
#define KHciLoggerACLDataFrame 0
|
|
|
|
#define KHciLoggerCommandOrEvent 0x00000002
|
2008-02-03 21:11:53 +00:00
|
|
|
|
2013-05-16 22:14:11 +00:00
|
|
|
static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* offset from symbian - unix time */
|
2008-02-03 21:11:53 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf,
|
|
|
|
int *err, gchar **err_info, gint64 *offset);
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info);
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info);
|
2008-02-03 21:11:53 +00:00
|
|
|
|
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
|
|
|
static int btsnoop_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_btsnoop(void);
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info)
|
2008-02-03 21:11:53 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
char magic[sizeof btsnoop_magic];
|
|
|
|
struct btsnoop_hdr hdr;
|
|
|
|
|
|
|
|
int file_encap=WTAP_ENCAP_UNKNOWN;
|
|
|
|
|
|
|
|
/* Read in the string that should be at the start of a "btsnoop" file */
|
|
|
|
if (!wtap_read_bytes(wth->fh, magic, sizeof magic, err, err_info)) {
|
|
|
|
if (*err != WTAP_ERR_SHORT_READ)
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(magic, btsnoop_magic, sizeof btsnoop_magic) != 0) {
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the rest of the header. */
|
|
|
|
if (!wtap_read_bytes(wth->fh, &hdr, sizeof hdr, err, err_info))
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure it's a version we support.
|
|
|
|
*/
|
|
|
|
hdr.version = g_ntohl(hdr.version);
|
|
|
|
if (hdr.version != 1) {
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("btsnoop: version %u unsupported", hdr.version);
|
2015-01-02 00:45:22 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr.datalink = g_ntohl(hdr.datalink);
|
|
|
|
switch (hdr.datalink) {
|
|
|
|
case KHciLoggerDatalinkTypeH1:
|
|
|
|
file_encap=WTAP_ENCAP_BLUETOOTH_HCI;
|
|
|
|
break;
|
|
|
|
case KHciLoggerDatalinkTypeH4:
|
|
|
|
file_encap=WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR;
|
|
|
|
break;
|
|
|
|
case KHciLoggerDatalinkTypeBCSP:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2016-06-06 02:24:47 +00:00
|
|
|
*err_info = g_strdup("btsnoop: BCSP capture logs unsupported");
|
2015-01-02 00:45:22 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
case KHciLoggerDatalinkTypeH5:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2016-06-06 02:24:47 +00:00
|
|
|
*err_info = g_strdup("btsnoop: H5 capture logs unsupported");
|
2015-01-02 00:45:22 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
case KHciLoggerDatalinkLinuxMonitor:
|
|
|
|
file_encap=WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR;
|
|
|
|
break;
|
|
|
|
case KHciLoggerDatalinkBlueZ5Simulator:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2016-06-06 02:24:47 +00:00
|
|
|
*err_info = g_strdup("btsnoop: BlueZ 5 Simulator capture logs unsupported");
|
2015-01-02 00:45:22 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
default:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("btsnoop: datalink type %u unknown or unsupported", hdr.datalink);
|
2015-01-02 00:45:22 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
wth->subtype_read = btsnoop_read;
|
|
|
|
wth->subtype_seek_read = btsnoop_seek_read;
|
|
|
|
wth->file_encap = file_encap;
|
|
|
|
wth->snapshot_length = 0; /* not available in header */
|
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
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
|
|
|
wth->file_type_subtype = btsnoop_file_type_subtype;
|
2020-07-29 08:30:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an IDB; we don't know how many interfaces were
|
|
|
|
* involved, so we just say one interface, about which
|
|
|
|
* we only know the link-layer type, snapshot length,
|
|
|
|
* and time stamp resolution.
|
|
|
|
*/
|
|
|
|
wtap_add_generated_idb(wth);
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2008-02-03 21:11:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf,
|
|
|
|
int *err, gchar **err_info, gint64 *offset)
|
2008-02-03 21:11:53 +00:00
|
|
|
{
|
2019-04-05 01:56:27 +00:00
|
|
|
*offset = file_tell(wth->fh);
|
2013-05-16 22:14:11 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
return btsnoop_read_record(wth, wth->fh, rec, buf, err, err_info);
|
2013-05-16 22:14:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info)
|
2013-05-16 22:14:11 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
2013-05-16 22:14:11 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
return btsnoop_read_record(wth, wth->random_fh, rec, buf, err, err_info);
|
2013-05-16 22:14:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info)
|
2013-05-16 22:14:11 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
struct btsnooprec_hdr hdr;
|
|
|
|
guint32 packet_size;
|
|
|
|
guint32 flags;
|
|
|
|
guint32 orig_size;
|
|
|
|
gint64 ts;
|
|
|
|
|
|
|
|
/* Read record header. */
|
|
|
|
|
|
|
|
if (!wtap_read_bytes_or_eof(fh, &hdr, sizeof hdr, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
packet_size = g_ntohl(hdr.incl_len);
|
|
|
|
orig_size = g_ntohl(hdr.orig_len);
|
|
|
|
flags = g_ntohl(hdr.flags);
|
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
|
|
|
if (packet_size > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
2015-01-02 00:45:22 +00:00
|
|
|
/*
|
|
|
|
* 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("btsnoop: File has %u-byte packet, bigger than maximum of %u",
|
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
|
|
|
packet_size, WTAP_MAX_PACKET_SIZE_STANDARD);
|
2015-01-02 00:45:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts = GINT64_FROM_BE(hdr.ts_usec);
|
|
|
|
ts -= KUnixTimeBase;
|
|
|
|
|
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|WTAP_HAS_CAP_LEN;
|
|
|
|
rec->ts.secs = (guint)(ts / 1000000);
|
|
|
|
rec->ts.nsecs = (guint)((ts % 1000000) * 1000);
|
|
|
|
rec->rec_header.packet_header.caplen = packet_size;
|
|
|
|
rec->rec_header.packet_header.len = orig_size;
|
2015-01-02 00:45:22 +00:00
|
|
|
if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR)
|
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.p2p.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE;
|
2015-01-02 00:45:22 +00:00
|
|
|
} else if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_HCI) {
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.bthci.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE;
|
2015-01-02 00:45:22 +00:00
|
|
|
if(flags & KHciLoggerCommandOrEvent)
|
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
if(rec->rec_header.packet_header.pseudo_header.bthci.sent)
|
2015-01-02 00:45:22 +00:00
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.bthci.channel = BTHCI_CHANNEL_COMMAND;
|
2015-01-02 00:45:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.bthci.channel = BTHCI_CHANNEL_EVENT;
|
2015-01-02 00:45:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.bthci.channel = BTHCI_CHANNEL_ACL;
|
2015-01-02 00:45:22 +00:00
|
|
|
}
|
|
|
|
} else if (wth->file_encap == WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR) {
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.btmon.opcode = flags & 0xFFFF;
|
|
|
|
rec->rec_header.packet_header.pseudo_header.btmon.adapter_id = flags >> 16;
|
2015-01-02 00:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read packet data. */
|
2018-02-09 00:19:12 +00:00
|
|
|
return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info);
|
2008-02-03 21:11:53 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 00:05:19 +00:00
|
|
|
/* Returns 0 if we could write the specified encapsulation type,
|
|
|
|
an error indication otherwise. */
|
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
|
|
|
static int btsnoop_dump_can_write_encap(int encap)
|
2009-05-22 00:05:19 +00:00
|
|
|
{
|
|
|
|
/* Per-packet encapsulations aren't supported. */
|
|
|
|
if (encap == WTAP_ENCAP_PER_PACKET)
|
|
|
|
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
|
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
/*
|
|
|
|
* XXX - for now we only support WTAP_ENCAP_BLUETOOTH_HCI,
|
|
|
|
* WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR, and
|
|
|
|
* WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR.
|
|
|
|
*/
|
|
|
|
if (encap != WTAP_ENCAP_BLUETOOTH_HCI &&
|
|
|
|
encap != WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR &&
|
|
|
|
encap != WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR)
|
2014-12-17 06:40:45 +00:00
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
static gboolean btsnoop_dump(wtap_dumper *wdh,
|
2018-02-09 00:19:12 +00:00
|
|
|
const wtap_rec *rec,
|
2014-12-18 00:02:50 +00:00
|
|
|
const guint8 *pd, int *err, gchar **err_info)
|
2009-05-22 00:05:19 +00:00
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header;
|
2009-05-22 00:05:19 +00:00
|
|
|
struct btsnooprec_hdr rec_hdr;
|
2021-02-07 09:11:06 +00:00
|
|
|
guint32 flags;
|
|
|
|
gint64 nsecs;
|
|
|
|
gint64 ts_usec;
|
2009-05-22 00:05:19 +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;
|
|
|
|
}
|
|
|
|
|
Catch attempts to write multiple encapsulation types if unsupported.
If, in the process of opening the input file, we determine that it has
packets of more than one link-layer type, we can catch attempts to write
that file to a file of a format that doesn't support more than one
link-layer type at the time we try to open the output file.
If, however, we don't discover that the file has more than one
link-layer type until we've already created the output file - for
example, if we have a pcapng file with a new IDB, with a different
link-layer type from previous IDBs, after packet blocks for the earlier
interfces - we can't catch that until we try to write the packet.
Currently, that causes the packet's data to be written out as is, so the
output file claims it's of the file's link-layer type, causing programs
reading the file to misdissect the packet.
Report WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on the write attempt
instead, and have a nicer error message for
WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on a write.
Change-Id: Ic41f2e4367cfe5667eb30c88cc6d3bfe422462f6
Reviewed-on: https://code.wireshark.org/review/30617
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-14 03:38:12 +00:00
|
|
|
/*
|
|
|
|
* Make sure this packet doesn't have a link-layer type that
|
|
|
|
* differs from the one for the file.
|
|
|
|
*/
|
|
|
|
if (wdh->encap != rec->rec_header.packet_header.pkt_encap) {
|
|
|
|
*err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
/* Don't write out anything bigger than we can read. */
|
|
|
|
if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
2014-01-22 00:26:36 +00:00
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
rec_hdr.incl_len = GUINT32_TO_BE(rec->rec_header.packet_header.caplen);
|
|
|
|
rec_hdr.orig_len = GUINT32_TO_BE(rec->rec_header.packet_header.len);
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
switch (wdh->encap) {
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case WTAP_ENCAP_BLUETOOTH_HCI:
|
|
|
|
switch (pseudo_header->bthci.channel) {
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case BTHCI_CHANNEL_COMMAND:
|
|
|
|
if (!pseudo_header->bthci.sent) {
|
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_DATA;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("btsnoop: Command channel, sent FALSE");
|
2021-02-07 09:11:06 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
flags = KHciLoggerCommandOrEvent|KHciLoggerHostToController;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTHCI_CHANNEL_EVENT:
|
|
|
|
if (pseudo_header->bthci.sent) {
|
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_DATA;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("btsnoop: Event channel, sent TRUE");
|
2021-02-07 09:11:06 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
flags = KHciLoggerCommandOrEvent|KHciLoggerControllerToHost;
|
|
|
|
break;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case BTHCI_CHANNEL_ACL:
|
|
|
|
if (pseudo_header->bthci.sent)
|
|
|
|
flags = KHciLoggerACLDataFrame|KHciLoggerHostToController;
|
|
|
|
else
|
|
|
|
flags = KHciLoggerACLDataFrame|KHciLoggerControllerToHost;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_DATA;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("btsnoop: Unknown channel %u",
|
2021-02-07 09:11:06 +00:00
|
|
|
pseudo_header->bthci.channel);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2014-05-24 18:28:30 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
|
|
|
|
if (pseudo_header->p2p.sent)
|
|
|
|
flags = KHciLoggerHostToController;
|
|
|
|
else
|
|
|
|
flags = KHciLoggerControllerToHost;
|
|
|
|
if (rec->rec_header.packet_header.caplen >= 1 &&
|
|
|
|
(pd[0] == 0x01 || pd[0] == 0x04))
|
|
|
|
flags |= KHciLoggerCommandOrEvent;
|
|
|
|
break;
|
Catch attempts to write multiple encapsulation types if unsupported.
If, in the process of opening the input file, we determine that it has
packets of more than one link-layer type, we can catch attempts to write
that file to a file of a format that doesn't support more than one
link-layer type at the time we try to open the output file.
If, however, we don't discover that the file has more than one
link-layer type until we've already created the output file - for
example, if we have a pcapng file with a new IDB, with a different
link-layer type from previous IDBs, after packet blocks for the earlier
interfces - we can't catch that until we try to write the packet.
Currently, that causes the packet's data to be written out as is, so the
output file claims it's of the file's link-layer type, causing programs
reading the file to misdissect the packet.
Report WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on the write attempt
instead, and have a nicer error message for
WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on a write.
Change-Id: Ic41f2e4367cfe5667eb30c88cc6d3bfe422462f6
Reviewed-on: https://code.wireshark.org/review/30617
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-14 03:38:12 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
|
|
|
|
flags = (pseudo_header->btmon.adapter_id << 16) | pseudo_header->btmon.opcode;
|
|
|
|
break;
|
Catch attempts to write multiple encapsulation types if unsupported.
If, in the process of opening the input file, we determine that it has
packets of more than one link-layer type, we can catch attempts to write
that file to a file of a format that doesn't support more than one
link-layer type at the time we try to open the output file.
If, however, we don't discover that the file has more than one
link-layer type until we've already created the output file - for
example, if we have a pcapng file with a new IDB, with a different
link-layer type from previous IDBs, after packet blocks for the earlier
interfces - we can't catch that until we try to write the packet.
Currently, that causes the packet's data to be written out as is, so the
output file claims it's of the file's link-layer type, causing programs
reading the file to misdissect the packet.
Report WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on the write attempt
instead, and have a nicer error message for
WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on a write.
Change-Id: Ic41f2e4367cfe5667eb30c88cc6d3bfe422462f6
Reviewed-on: https://code.wireshark.org/review/30617
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-14 03:38:12 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
default:
|
|
|
|
/* We should never get here - our open routine should only get
|
|
|
|
called for the types above. */
|
|
|
|
*err = WTAP_ERR_INTERNAL;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("btsnoop: invalid encapsulation %u",
|
2021-02-07 09:11:06 +00:00
|
|
|
wdh->encap);
|
2014-01-22 00:26:36 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 09:11:06 +00:00
|
|
|
rec_hdr.flags = GUINT32_TO_BE(flags);
|
|
|
|
rec_hdr.cum_drops = GUINT32_TO_BE(0);
|
2014-01-22 00:26:36 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
nsecs = rec->ts.nsecs;
|
|
|
|
ts_usec = ((gint64) rec->ts.secs * 1000000) + (nsecs / 1000);
|
|
|
|
ts_usec += KUnixTimeBase;
|
|
|
|
rec_hdr.ts_usec = GINT64_TO_BE(ts_usec);
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err))
|
2009-05-22 00:05:19 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
wdh->bytes_dumped += sizeof rec_hdr;
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err))
|
2009-05-22 00:05:19 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
wdh->bytes_dumped += rec->rec_header.packet_header.caplen;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
|
|
|
|
failure */
|
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
|
|
|
static gboolean btsnoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
|
2009-05-22 00:05:19 +00:00
|
|
|
{
|
|
|
|
struct btsnoop_hdr file_hdr;
|
2021-02-07 09:11:06 +00:00
|
|
|
guint32 datalink;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2015-11-09 19:54:18 +00:00
|
|
|
/* This is a btsnoop file */
|
2021-02-07 09:11:06 +00:00
|
|
|
wdh->subtype_write = btsnoop_dump;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
switch (wdh->encap) {
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case WTAP_ENCAP_BLUETOOTH_HCI:
|
|
|
|
datalink = KHciLoggerDatalinkTypeH1;
|
|
|
|
break;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
|
|
|
|
datalink = KHciLoggerDatalinkTypeH4;
|
|
|
|
break;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
|
|
|
|
datalink = KHciLoggerDatalinkLinuxMonitor;
|
|
|
|
break;
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2021-02-07 09:11:06 +00:00
|
|
|
default:
|
|
|
|
/* We should never get here - our open routine should only get
|
|
|
|
called for the types above. */
|
|
|
|
*err = WTAP_ERR_INTERNAL;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("btsnoop: invalid encapsulation %u",
|
2021-02-07 09:11:06 +00:00
|
|
|
wdh->encap);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-05-22 00:05:19 +00:00
|
|
|
|
|
|
|
/* Write the file header. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err))
|
2009-05-22 00:05:19 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
wdh->bytes_dumped += sizeof btsnoop_magic;
|
|
|
|
|
|
|
|
/* current "btsnoop" format is 1 */
|
|
|
|
file_hdr.version = GUINT32_TO_BE(1);
|
|
|
|
/* HCI type encoded in first byte */
|
2021-02-07 09:11:06 +00:00
|
|
|
file_hdr.datalink = GUINT32_TO_BE(datalink);
|
2009-05-22 00:05:19 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
|
2009-05-22 00:05:19 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
wdh->bytes_dumped += sizeof file_hdr;
|
|
|
|
|
|
|
|
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 btsnoop_blocks_supported[] = {
|
|
|
|
/*
|
|
|
|
* We support packet blocks, with no comments or other options.
|
|
|
|
*/
|
|
|
|
{ WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED }
|
|
|
|
};
|
|
|
|
|
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
|
|
|
static const struct file_type_subtype_info btsnoop_info = {
|
|
|
|
"Symbian OS btsnoop", "btsnoop", "log", 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(btsnoop_blocks_supported),
|
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
|
|
|
btsnoop_dump_can_write_encap, btsnoop_dump_open, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
void register_btsnoop(void)
|
|
|
|
{
|
2021-02-24 03:10:35 +00:00
|
|
|
btsnoop_file_type_subtype = wtap_register_file_type_subtype(&btsnoop_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.
|
|
|
|
*/
|
|
|
|
wtap_register_backwards_compatibility_lua_name("BTSNOOP",
|
|
|
|
btsnoop_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: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|