Coverage Report

Created: 2026-09-28 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/wiretap/eri_enb_log.c
Line
Count
Source
1
/* eri_enb_log.c
2
 *
3
 * Ericsson eNode-B raw log file format decoder for the Wiretap library.
4
 *
5
 * Wiretap Library
6
 *
7
 * SPDX-License-Identifier: GPL-2.0-or-later
8
 */
9
10
#include "eri_enb_log.h"
11
12
#include <string.h>
13
14
#include "file_wrappers.h"
15
#include "wtap_module.h"
16
17
static const char eri_enb_log_magic[] = "com_ericsson";
18
19
static int eri_enb_log_file_type_subtype = -1;
20
21
void register_eri_enb_log(void);
22
23
#define MAX_LINE_LENGTH            131072
24
25
typedef struct {
26
    char line[MAX_LINE_LENGTH];
27
} eri_enb_log_t;
28
29
static bool eri_enb_log_get_packet(wtap *wth, FILE_T fh, wtap_rec* rec,
30
  int* err _U_, char** err_info _U_)
31
0
{
32
0
  eri_enb_log_t *eri_enb = (eri_enb_log_t *)wth->priv;
33
  /* Read in a line */
34
0
  int64_t pos_before = file_tell(fh);
35
36
0
  while (file_gets(eri_enb->line, sizeof(eri_enb->line), fh) != NULL)
37
0
  {
38
0
    nstime_t packet_time;
39
0
    int length;
40
    /* Set length (avoiding strlen()) and offset.. */
41
0
    length = (int)(file_tell(fh) - pos_before);
42
43
    /* ...but don't want to include newline in line length */
44
0
    if (length > 0 && eri_enb->line[length - 1] == '\n') {
45
0
      eri_enb->line[length - 1] = '\0';
46
0
      length = length - 1;
47
0
    }
48
    /* Nor do we want '\r' (as will be written when log is created on windows) */
49
0
    if (length > 0 && eri_enb->line[length - 1] == '\r') {
50
0
      eri_enb->line[length - 1] = '\0';
51
0
      length = length - 1;
52
0
    }
53
54
0
    if (NULL != iso8601_to_nstime(&packet_time, eri_enb->line+1, ISO8601_DATETIME)) {
55
0
      rec->ts.secs = packet_time.secs;
56
0
      rec->ts.nsecs = packet_time.nsecs;
57
0
      rec->presence_flags |= WTAP_HAS_TS;
58
0
    } else {
59
0
      rec->ts.secs = 0;
60
0
      rec->ts.nsecs = 0;
61
0
      rec->presence_flags = 0; /* no time stamp, no separate "on the wire" length */
62
0
    }
63
    /* We've got a full packet! */
64
0
    wtap_setup_packet_rec(rec, wth->file_encap);
65
0
    rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
66
0
    rec->rec_header.packet_header.caplen = length;
67
0
    rec->rec_header.packet_header.len = length;
68
69
0
    *err = 0;
70
71
    /* Append data to the packet buffer */
72
0
    ws_buffer_append(&rec->data, (const uint8_t*)eri_enb->line, rec->rec_header.packet_header.caplen);
73
74
0
    return true;
75
76
0
  }
77
0
  return false;
78
0
}
79
80
/* Find the next packet and parse it; called from wtap_read(). */
81
static bool eri_enb_log_read(wtap* wth, wtap_rec* rec,
82
  int* err, char** err_info, int64_t* data_offset)
83
0
{
84
0
  *data_offset = file_tell(wth->fh);
85
86
0
  return eri_enb_log_get_packet(wth, wth->fh, rec, err, err_info);
87
0
}
88
89
/* Used to read packets in random-access fashion */
90
static bool eri_enb_log_seek_read(wtap* wth, int64_t seek_off,
91
  wtap_rec* rec, int* err, char** err_info)
92
0
{
93
0
  if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
94
0
  {
95
0
    return false;
96
0
  }
97
98
0
  return eri_enb_log_get_packet(wth, wth->random_fh, rec, err, err_info);
99
0
}
100
101
static void eri_enb_log_close(wtap *wth)
102
0
{
103
0
  eri_enb_log_t *eri_enb = (eri_enb_log_t *)wth->priv;
104
105
0
  g_free(eri_enb);
106
  /* XXX: Prevent double free by wtap_close() */
107
0
  wth->priv = NULL;
108
0
}
109
110
wtap_open_return_val
111
eri_enb_log_open(wtap *wth, int *err, char **err_info)
112
0
{
113
0
  char line1[64];
114
115
  /* Look for Ericsson eNode-B log header */
116
0
  if (file_gets(line1, sizeof(line1), wth->fh) == NULL)
117
0
  {
118
0
    *err = file_error(wth->fh, err_info);
119
0
    if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
120
0
      return WTAP_OPEN_ERROR;
121
0
    return WTAP_OPEN_NOT_MINE;
122
0
  }
123
124
0
  if (g_strstr_len(line1, sizeof(line1), eri_enb_log_magic) == NULL)
125
0
  {
126
0
    return WTAP_OPEN_NOT_MINE;
127
0
  }
128
129
0
  if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
130
0
    return WTAP_OPEN_ERROR;
131
132
0
  wth->file_type_subtype = eri_enb_log_file_type_subtype;
133
0
  wth->file_encap = WTAP_ENCAP_ERI_ENB_LOG;
134
0
  wth->file_tsprec = WTAP_TSPREC_NSEC;
135
0
  wth->subtype_read = eri_enb_log_read;
136
0
  wth->subtype_seek_read = eri_enb_log_seek_read;
137
0
  wth->subtype_close = eri_enb_log_close;
138
0
  wth->snapshot_length = 0;
139
0
  wth->priv = g_new(eri_enb_log_t, 1);
140
141
0
  return WTAP_OPEN_MINE;
142
0
}
143
144
static const struct supported_block_type eri_enb_log_blocks_supported[] = {
145
  /*
146
   * This is a file format that we dissect, so we provide
147
   * only one "packet" with the file's contents, and don't
148
   * support any options.
149
   */
150
  { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED }
151
};
152
153
static const struct file_type_subtype_info eri_enb_log_info = {
154
  "Ericsson eNode-B raw log", "eri_enb_log", "eri_enb_log", NULL,
155
  false, BLOCKS_SUPPORTED(eri_enb_log_blocks_supported),
156
  NULL, NULL, NULL
157
};
158
159
void register_eri_enb_log(void)
160
16
{
161
16
  eri_enb_log_file_type_subtype = wtap_register_file_type_subtype(&eri_enb_log_info);
162
163
  /*
164
   * Register name for backwards compatibility with the
165
   * wtap_filetypes table in Lua.
166
   */
167
  //wtap_register_backwards_compatibility_lua_name("MP4",
168
  //    eri_enb_log_file_type_subtype);
169
16
}
170
171
/*
172
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
173
 *
174
 * Local variables:
175
 * c-basic-offset: 8
176
 * tab-width: 8
177
 * indent-tabs-mode: t
178
 * End:
179
 *
180
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
181
 * :indentSize=8:tabSize=8:noTabs=false:
182
 */