2013-03-30 09:56:57 +00:00
|
|
|
/* camins.c
|
|
|
|
*
|
|
|
|
* File format support for Rabbit Labs CAM Inspector files
|
|
|
|
* Copyright (c) 2013 by Martin Kaiser <martin@kaiser.cx>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-18 21:40:50 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* CAM Inspector is a commercial log tool for DVB-CI
|
|
|
|
it stores recorded packets between a CI module and a DVB receiver,
|
|
|
|
using a proprietary file format
|
|
|
|
|
|
|
|
a CAM Inspector file consists of 16bit blocks
|
|
|
|
the first byte contains payload data,
|
|
|
|
the second byte contains a "transaction type"
|
|
|
|
|
|
|
|
we currently support the following transaction types
|
|
|
|
|
|
|
|
0x20 == data transfer from CI module to host
|
|
|
|
0x22 == host reads the lower byte of the size register
|
|
|
|
0x23 == host reads the higher byte of the size register
|
|
|
|
0x2A == host writes the lower byte of the size register
|
|
|
|
0x2B == host writes the higher byte of the size register
|
|
|
|
0x28 == data transfer from host to CI module
|
|
|
|
|
|
|
|
using these transaction types, we can identify and assemble data transfers
|
2013-09-07 09:03:21 +00:00
|
|
|
from the host to the CAM and vice versa
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
a host->module data transfer will use the following transactions
|
|
|
|
one 0x2A and one 0x2B transaction to write the 16bit size
|
|
|
|
<size> 0x28 transactions to transfer one byte at a time
|
|
|
|
this will be assembled into one packet
|
|
|
|
|
|
|
|
the module->host transfer is similar
|
|
|
|
|
2018-05-01 17:12:49 +00:00
|
|
|
a CAM Inspector file uses a 44-bit time counter to keep track of the
|
|
|
|
time. the counter is in units of 1us. a timestamp block in the file
|
|
|
|
updates a part of the global time counter. a timestamp contains a 2-bit
|
|
|
|
relative position within the time counter and an 11-bit value for
|
|
|
|
this position.
|
|
|
|
|
2013-03-30 09:56:57 +00:00
|
|
|
error handling
|
|
|
|
when we run into an error while assembling a data transfer, the
|
|
|
|
primary goal is to recover so that we can handle the next transfer
|
|
|
|
correctly (all files I used for testing contained errors where
|
|
|
|
apparently the logging hardware missed some bytes)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 17:12:49 +00:00
|
|
|
#include <glib.h>
|
2013-03-30 09:56:57 +00:00
|
|
|
#include <string.h>
|
2016-04-03 17:14:40 +00:00
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "file_wrappers.h"
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
#include "camins.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define TRANS_CAM_HOST 0x20
|
|
|
|
#define TRANS_READ_SIZE_LOW 0x22
|
|
|
|
#define TRANS_READ_SIZE_HIGH 0x23
|
|
|
|
#define TRANS_HOST_CAM 0x28
|
|
|
|
#define TRANS_WRITE_SIZE_LOW 0x2A
|
|
|
|
#define TRANS_WRITE_SIZE_HIGH 0x2B
|
|
|
|
|
|
|
|
#define IS_TRANS_SIZE(x) \
|
|
|
|
((x)==TRANS_WRITE_SIZE_LOW || (x)==TRANS_WRITE_SIZE_HIGH || \
|
|
|
|
(x)==TRANS_READ_SIZE_LOW || (x)==TRANS_READ_SIZE_HIGH)
|
|
|
|
|
2018-05-01 17:12:49 +00:00
|
|
|
/* a block contains a timestamp if the upper three bits are 0 */
|
|
|
|
#define IS_TIMESTAMP(x) (((x) & 0xE0) == 0x00)
|
|
|
|
|
|
|
|
/* a timestamp consists of a 2-bit position, followed by an 11-bit value. */
|
|
|
|
#define TS_VALUE_SHIFT 11
|
|
|
|
#define TS_POS_MASK (0x3 << TS_VALUE_SHIFT)
|
|
|
|
#define TS_VALUE_MASK G_GUINT64_CONSTANT((1 << TS_VALUE_SHIFT) - 1)
|
|
|
|
|
2013-03-30 09:56:57 +00:00
|
|
|
typedef enum {
|
|
|
|
SIZE_HAVE_NONE,
|
|
|
|
SIZE_HAVE_LOW,
|
|
|
|
SIZE_HAVE_HIGH,
|
2013-11-08 17:17:57 +00:00
|
|
|
SIZE_HAVE_ALL
|
2013-03-30 09:56:57 +00:00
|
|
|
} size_read_t;
|
|
|
|
|
|
|
|
#define RESET_STAT_VALS \
|
|
|
|
{ \
|
|
|
|
*dat_trans_type = 0x00; \
|
|
|
|
*dat_len = 0x00; \
|
|
|
|
size_stat = SIZE_HAVE_NONE; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SIZE_ADD_LOW \
|
|
|
|
{ size_stat = (size_stat==SIZE_HAVE_HIGH ? SIZE_HAVE_ALL : SIZE_HAVE_LOW); }
|
|
|
|
|
|
|
|
#define SIZE_ADD_HIGH \
|
|
|
|
{ size_stat = (size_stat==SIZE_HAVE_LOW ? SIZE_HAVE_ALL : SIZE_HAVE_HIGH); }
|
|
|
|
|
2019-07-28 04:20:27 +00:00
|
|
|
/* PCAP DVB-CI pseudo-header, see https://www.kaiser.cx/pcap-dvbci.html */
|
2013-03-30 09:56:57 +00:00
|
|
|
#define DVB_CI_PSEUDO_HDR_VER 0
|
|
|
|
#define DVB_CI_PSEUDO_HDR_LEN 4
|
|
|
|
#define DVB_CI_PSEUDO_HDR_CAM_TO_HOST 0xFF
|
|
|
|
#define DVB_CI_PSEUDO_HDR_HOST_TO_CAM 0xFE
|
|
|
|
|
|
|
|
|
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 camins_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_camins(void);
|
|
|
|
|
2017-01-08 17:04:56 +00:00
|
|
|
/* Detect a camins file by looking at the blocks that access the 16bit
|
|
|
|
size register. The matching blocks to access the upper and lower 8bit
|
|
|
|
must be no further than 5 blocks apart.
|
|
|
|
A file may have errors that affect the size blocks. Therefore, we
|
|
|
|
read the entire file and require that we have much more valid pairs
|
|
|
|
than errors. */
|
2020-04-12 03:43:09 +00:00
|
|
|
static wtap_open_return_val detect_camins_file(FILE_T fh)
|
2017-01-08 17:04:56 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
gchar *err_info;
|
|
|
|
guint8 block[2];
|
|
|
|
guint8 search_block = 0;
|
|
|
|
guint8 gap_count = 0;
|
|
|
|
guint32 valid_pairs = 0, invalid_pairs = 0;
|
|
|
|
|
|
|
|
while (wtap_read_bytes(fh, block, sizeof(block), &err, &err_info)) {
|
|
|
|
if (search_block != 0) {
|
|
|
|
/* We're searching for a matching block to complete the pair. */
|
|
|
|
|
|
|
|
if (block[1] == search_block) {
|
|
|
|
/* We found it */
|
|
|
|
valid_pairs++;
|
|
|
|
search_block = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* We didn't find it. */
|
|
|
|
gap_count++;
|
|
|
|
if (gap_count > 5) {
|
|
|
|
/* Give up the search, we have no pair. */
|
|
|
|
invalid_pairs++;
|
|
|
|
search_block = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* We're not searching for a matching block at the moment.
|
|
|
|
If we see a size read/write block of one type, the matching
|
|
|
|
block is the the other type and we can start searching. */
|
|
|
|
|
|
|
|
if (block[1] == TRANS_READ_SIZE_LOW) {
|
|
|
|
search_block = TRANS_READ_SIZE_HIGH;
|
|
|
|
gap_count = 0;
|
|
|
|
}
|
|
|
|
else if (block[1] == TRANS_READ_SIZE_HIGH) {
|
|
|
|
search_block = TRANS_READ_SIZE_LOW;
|
|
|
|
gap_count = 0;
|
|
|
|
}
|
|
|
|
else if (block[1] == TRANS_WRITE_SIZE_LOW) {
|
|
|
|
search_block = TRANS_WRITE_SIZE_HIGH;
|
|
|
|
gap_count = 0;
|
|
|
|
}
|
|
|
|
else if (block[1] == TRANS_WRITE_SIZE_HIGH) {
|
|
|
|
search_block = TRANS_WRITE_SIZE_LOW;
|
|
|
|
gap_count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-12 03:43:09 +00:00
|
|
|
if (err != WTAP_ERR_SHORT_READ) {
|
|
|
|
/* A real read error. */
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-01-08 17:04:56 +00:00
|
|
|
/* For valid_pairs == invalid_pairs == 0, this isn't a camins file.
|
|
|
|
Don't change > into >= */
|
|
|
|
if (valid_pairs > 10 * invalid_pairs)
|
2020-04-12 03:43:09 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2017-01-08 17:04:56 +00:00
|
|
|
|
2020-04-12 03:43:09 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2017-01-08 17:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-01 17:12:49 +00:00
|
|
|
/* update the current time counter with infos from a timestamp block */
|
|
|
|
static void process_timestamp(guint16 timestamp, guint64 *time_us)
|
|
|
|
{
|
|
|
|
guint8 pos, shift;
|
|
|
|
guint64 val;
|
|
|
|
|
|
|
|
if (!time_us)
|
|
|
|
return;
|
|
|
|
|
|
|
|
val = timestamp & TS_VALUE_MASK;
|
|
|
|
pos = (timestamp & TS_POS_MASK) >> TS_VALUE_SHIFT;
|
|
|
|
shift = TS_VALUE_SHIFT * pos;
|
|
|
|
|
|
|
|
*time_us &= ~(TS_VALUE_MASK << shift);
|
|
|
|
*time_us |= (val << shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-30 09:56:57 +00:00
|
|
|
/* find the transaction type for the data bytes of the next packet
|
2018-05-01 17:12:49 +00:00
|
|
|
and the number of data bytes in that packet
|
2013-03-30 09:56:57 +00:00
|
|
|
the fd is moved such that it can be used in a subsequent call
|
2018-05-01 17:12:49 +00:00
|
|
|
to retrieve the data
|
|
|
|
if requested by the caller, we increment the time counter as we
|
|
|
|
walk through the file */
|
2013-03-30 09:56:57 +00:00
|
|
|
static gboolean
|
2018-05-01 17:12:49 +00:00
|
|
|
find_next_pkt_info(FILE_T fh,
|
2013-03-30 09:56:57 +00:00
|
|
|
guint8 *dat_trans_type, /* transaction type used for the data bytes */
|
|
|
|
guint16 *dat_len, /* the number of data bytes in the packet */
|
2018-05-01 17:12:49 +00:00
|
|
|
guint64 *time_us,
|
2013-03-30 09:56:57 +00:00
|
|
|
int *err, gchar **err_info)
|
|
|
|
{
|
|
|
|
guint8 block[2];
|
|
|
|
size_read_t size_stat;
|
|
|
|
|
|
|
|
if (!dat_trans_type || !dat_len)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
RESET_STAT_VALS;
|
|
|
|
|
|
|
|
do {
|
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, block, sizeof(block), err, err_info)) {
|
2013-03-30 09:56:57 +00:00
|
|
|
RESET_STAT_VALS;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* our strategy is to continue reading until we have a high and a
|
|
|
|
low size byte for the same direction, duplicates or spurious data
|
|
|
|
bytes are ignored */
|
|
|
|
|
|
|
|
switch (block[1]) {
|
|
|
|
case TRANS_READ_SIZE_LOW:
|
|
|
|
if (*dat_trans_type != TRANS_CAM_HOST)
|
|
|
|
RESET_STAT_VALS;
|
|
|
|
*dat_trans_type = TRANS_CAM_HOST;
|
|
|
|
*dat_len |= block[0];
|
|
|
|
SIZE_ADD_LOW;
|
|
|
|
break;
|
|
|
|
case TRANS_READ_SIZE_HIGH:
|
|
|
|
if (*dat_trans_type != TRANS_CAM_HOST)
|
|
|
|
RESET_STAT_VALS;
|
|
|
|
*dat_trans_type = TRANS_CAM_HOST;
|
|
|
|
*dat_len |= (block[0] << 8);
|
|
|
|
SIZE_ADD_HIGH;
|
|
|
|
break;
|
|
|
|
case TRANS_WRITE_SIZE_LOW:
|
|
|
|
if (*dat_trans_type != TRANS_HOST_CAM)
|
|
|
|
RESET_STAT_VALS;
|
|
|
|
*dat_trans_type = TRANS_HOST_CAM;
|
|
|
|
*dat_len |= block[0];
|
|
|
|
SIZE_ADD_LOW;
|
|
|
|
break;
|
|
|
|
case TRANS_WRITE_SIZE_HIGH:
|
|
|
|
if (*dat_trans_type != TRANS_HOST_CAM)
|
|
|
|
RESET_STAT_VALS;
|
|
|
|
*dat_trans_type = TRANS_HOST_CAM;
|
|
|
|
*dat_len |= (block[0] << 8);
|
|
|
|
SIZE_ADD_HIGH;
|
|
|
|
break;
|
|
|
|
default:
|
2018-05-01 17:12:49 +00:00
|
|
|
if (IS_TIMESTAMP(block[1]))
|
|
|
|
process_timestamp(pletoh16(block), time_us);
|
2013-03-30 09:56:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (size_stat != SIZE_HAVE_ALL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* buffer allocated by the caller, must be long enough to hold
|
|
|
|
dat_len bytes, ... */
|
|
|
|
static gint
|
|
|
|
read_packet_data(FILE_T fh, guint8 dat_trans_type, guint8 *buf, guint16 dat_len,
|
2018-05-01 17:12:49 +00:00
|
|
|
guint64 *time_us, int *err, gchar **err_info)
|
2013-11-08 17:17:57 +00:00
|
|
|
{
|
2013-03-30 09:56:57 +00:00
|
|
|
guint8 *p;
|
|
|
|
guint8 block[2];
|
|
|
|
guint16 bytes_count = 0;
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* we're not checking for end-of-file here, we read as many bytes as
|
|
|
|
we can get (up to dat_len) and return those
|
|
|
|
end-of-file will be detected when we search for the next packet */
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
while (bytes_count < dat_len) {
|
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, block, sizeof(block), err, err_info))
|
2013-03-30 09:56:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (block[1] == dat_trans_type) {
|
|
|
|
*p++ = block[0];
|
|
|
|
bytes_count++;
|
|
|
|
}
|
2018-05-01 17:12:49 +00:00
|
|
|
else if (IS_TIMESTAMP(block[1])) {
|
|
|
|
process_timestamp(pletoh16(block), time_us);
|
|
|
|
}
|
2013-03-30 09:56:57 +00:00
|
|
|
else if (IS_TRANS_SIZE(block[1])) {
|
|
|
|
/* go back before the size transaction block
|
|
|
|
the next packet should be able to pick up this block */
|
2013-11-08 17:17:57 +00:00
|
|
|
if (-1 == file_seek(fh, -(gint64)sizeof(block), SEEK_CUR, err))
|
2013-03-30 09:56:57 +00:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes_count;
|
|
|
|
}
|
2013-11-08 17:17:57 +00:00
|
|
|
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
/* create a DVB-CI pseudo header
|
|
|
|
return its length or -1 for error */
|
|
|
|
static gint
|
2020-10-14 01:48:46 +00:00
|
|
|
create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len,
|
|
|
|
gchar **err_info)
|
2013-03-30 09:56:57 +00:00
|
|
|
{
|
|
|
|
buf[0] = DVB_CI_PSEUDO_HDR_VER;
|
|
|
|
|
|
|
|
if (dat_trans_type==TRANS_CAM_HOST)
|
|
|
|
buf[1] = DVB_CI_PSEUDO_HDR_CAM_TO_HOST;
|
|
|
|
else if (dat_trans_type==TRANS_HOST_CAM)
|
|
|
|
buf[1] = DVB_CI_PSEUDO_HDR_HOST_TO_CAM;
|
2020-10-14 01:48:46 +00:00
|
|
|
else {
|
|
|
|
*err_info = g_strdup_printf("camins: invalid dat_trans_type %u", dat_trans_type);
|
2013-03-30 09:56:57 +00:00
|
|
|
return -1;
|
2020-10-14 01:48:46 +00:00
|
|
|
}
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
buf[2] = (dat_len>>8) & 0xFF;
|
|
|
|
buf[3] = dat_len & 0xFF;
|
|
|
|
|
|
|
|
return DVB_CI_PSEUDO_HDR_LEN;
|
|
|
|
}
|
|
|
|
|
2013-11-08 17:17:57 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
|
2018-05-01 17:12:49 +00:00
|
|
|
guint64 *time_us, int *err, gchar **err_info)
|
2013-03-30 09:56:57 +00:00
|
|
|
{
|
|
|
|
guint8 dat_trans_type;
|
|
|
|
guint16 dat_len;
|
|
|
|
guint8 *p;
|
|
|
|
gint offset, bytes_read;
|
|
|
|
|
2018-05-01 17:12:49 +00:00
|
|
|
if (!find_next_pkt_info(
|
|
|
|
fh, &dat_trans_type, &dat_len, time_us, 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 length is 65535, which, even after
|
|
|
|
* DVB_CI_PSEUDO_HDR_LEN is added to it, is less than
|
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
|
|
|
* WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check
|
2016-04-30 02:04:17 +00:00
|
|
|
* it.
|
|
|
|
*/
|
2013-03-30 09:56:57 +00:00
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_assure_space(buf, DVB_CI_PSEUDO_HDR_LEN+dat_len);
|
|
|
|
p = ws_buffer_start_ptr(buf);
|
2020-10-14 01:48:46 +00:00
|
|
|
offset = create_pseudo_hdr(p, dat_trans_type, dat_len, err_info);
|
2013-03-30 09:56:57 +00:00
|
|
|
if (offset<0) {
|
|
|
|
/* shouldn't happen, all invalid packets must be detected by
|
2018-05-01 17:12:49 +00:00
|
|
|
find_next_pkt_info() */
|
2013-03-30 09:56:57 +00:00
|
|
|
*err = WTAP_ERR_INTERNAL;
|
2020-10-14 01:48:46 +00:00
|
|
|
/* create_pseudo_hdr() set err_info appropriately */
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-03-30 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
bytes_read = read_packet_data(fh, dat_trans_type,
|
2018-05-01 17:12:49 +00:00
|
|
|
&p[offset], dat_len, time_us, err, err_info);
|
2013-03-30 09:56:57 +00:00
|
|
|
/* 0<=bytes_read<=dat_len is very likely a corrupted packet
|
|
|
|
we let the dissector handle this */
|
|
|
|
if (bytes_read < 0)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-03-30 09:56:57 +00:00
|
|
|
offset += bytes_read;
|
|
|
|
|
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);
|
2020-05-01 21:19:14 +00:00
|
|
|
rec->presence_flags = 0; /* we may or may not have a time stamp */
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_DVBCI;
|
2018-05-01 17:12:49 +00:00
|
|
|
if (time_us) {
|
|
|
|
rec->presence_flags = WTAP_HAS_TS;
|
|
|
|
rec->ts.secs = (time_t)(*time_us / (1000 * 1000));
|
|
|
|
rec->ts.nsecs = (int)(*time_us % (1000 *1000) * 1000);
|
|
|
|
}
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.caplen = offset;
|
|
|
|
rec->rec_header.packet_header.len = offset;
|
2013-03-30 09:56:57 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2013-03-30 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2019-04-05 01:56:27 +00:00
|
|
|
camins_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
|
|
|
gchar **err_info, gint64 *data_offset)
|
2013-03-30 09:56:57 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2013-03-30 09:56:57 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
return camins_read_packet(wth->fh, rec, buf, (guint64 *)(wth->priv),
|
|
|
|
err, err_info);
|
2013-06-17 21:18:47 +00:00
|
|
|
}
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
camins_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf,
|
|
|
|
int *err, gchar **err_info)
|
2013-06-17 21:18:47 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-05-16 22:01:44 +00:00
|
|
|
|
2018-05-01 17:12:49 +00:00
|
|
|
return camins_read_packet(wth->random_fh, rec, buf, NULL, err, err_info);
|
2013-03-30 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-08 17:04:56 +00:00
|
|
|
wtap_open_return_val camins_open(wtap *wth, int *err, gchar **err_info _U_)
|
2013-03-30 09:56:57 +00:00
|
|
|
{
|
2020-04-12 03:43:09 +00:00
|
|
|
wtap_open_return_val status;
|
|
|
|
|
|
|
|
status = detect_camins_file(wth->fh);
|
|
|
|
if (status != WTAP_OPEN_MINE) {
|
|
|
|
/* A read error or a failed heuristic. */
|
|
|
|
return status;
|
|
|
|
}
|
2013-03-30 09:56:57 +00:00
|
|
|
|
2013-05-16 22:01:44 +00:00
|
|
|
/* rewind the fh so we re-read from the beginning */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (-1 == file_seek(wth->fh, 0, SEEK_SET, err))
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2013-03-30 09:56:57 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_DVBCI;
|
|
|
|
wth->snapshot_length = 0;
|
2018-05-01 17:12:49 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
2013-03-30 09:56:57 +00:00
|
|
|
|
2018-05-01 17:12:49 +00:00
|
|
|
/* wth->priv stores a pointer to the global time counter. we update
|
|
|
|
it as we go through the file sequentially. */
|
2020-12-22 19:24:09 +00:00
|
|
|
wth->priv = g_new0(guint64, 1);
|
2013-03-30 09:56:57 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->subtype_read = camins_read;
|
|
|
|
wth->subtype_seek_read = camins_seek_read;
|
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 = camins_file_type_subtype;
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
*err = 0;
|
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);
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2013-03-30 09:56:57 +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 camins_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 camins_info = {
|
|
|
|
"CAM Inspector file", "camins", "camins", 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(camins_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
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
void register_camins(void)
|
|
|
|
{
|
2021-02-24 03:10:35 +00:00
|
|
|
camins_file_type_subtype = wtap_register_file_type_subtype(&camins_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("CAMINS",
|
|
|
|
camins_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
|
|
|
}
|
2013-03-30 09:56:57 +00:00
|
|
|
|
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2013-03-30 09:56:57 +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:
|
|
|
|
*/
|