3 * Ericsson eNode-B raw log file format decoder for the Wiretap library.
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #include "eri_enb_log.h"
14 #include "file_wrappers.h"
17 static const char eri_enb_log_magic
[] = "com_ericsson";
19 static int eri_enb_log_file_type_subtype
= -1;
21 void register_eri_enb_log(void);
23 #define MAX_LINE_LENGTH 131072
25 static bool eri_enb_log_get_packet(FILE_T fh
, wtap_rec
* rec
,
26 Buffer
* buf
, int* err _U_
, char** err_info _U_
)
28 static char line
[MAX_LINE_LENGTH
];
30 int64_t pos_before
= file_tell(fh
);
32 while (file_gets(line
, sizeof(line
), fh
) != NULL
)
36 /* Set length (avoiding strlen()) and offset.. */
37 length
= (int)(file_tell(fh
) - pos_before
);
39 /* ...but don't want to include newline in line length */
40 if (length
> 0 && line
[length
- 1] == '\n') {
41 line
[length
- 1] = '\0';
44 /* Nor do we want '\r' (as will be written when log is created on windows) */
45 if (length
> 0 && line
[length
- 1] == '\r') {
46 line
[length
- 1] = '\0';
50 if (NULL
!= iso8601_to_nstime(&packet_time
, line
+1, ISO8601_DATETIME
)) {
51 rec
->ts
.secs
= packet_time
.secs
;
52 rec
->ts
.nsecs
= packet_time
.nsecs
;
53 rec
->presence_flags
|= WTAP_HAS_TS
;
57 rec
->presence_flags
= 0; /* no time stamp, no separate "on the wire" length */
59 /* We've got a full packet! */
60 rec
->rec_type
= REC_TYPE_PACKET
;
61 rec
->block
= wtap_block_create(WTAP_BLOCK_PACKET
);
62 rec
->rec_header
.packet_header
.caplen
= length
;
63 rec
->rec_header
.packet_header
.len
= length
;
67 /* Make sure we have enough room for the packet */
68 ws_buffer_assure_space(buf
, rec
->rec_header
.packet_header
.caplen
);
69 memcpy(ws_buffer_start_ptr(buf
), line
, rec
->rec_header
.packet_header
.caplen
);
77 /* Find the next packet and parse it; called from wtap_read(). */
78 static bool eri_enb_log_read(wtap
* wth
, wtap_rec
* rec
, Buffer
* buf
,
79 int* err
, char** err_info
, int64_t* data_offset
)
81 *data_offset
= file_tell(wth
->fh
);
83 return eri_enb_log_get_packet(wth
->fh
, rec
, buf
, err
, err_info
);
86 /* Used to read packets in random-access fashion */
87 static bool eri_enb_log_seek_read(wtap
* wth
, int64_t seek_off
,
88 wtap_rec
* rec
, Buffer
* buf
, int* err
, char** err_info
)
90 if (file_seek(wth
->random_fh
, seek_off
, SEEK_SET
, err
) == -1)
95 return eri_enb_log_get_packet(wth
->random_fh
, rec
, buf
, err
, err_info
);
99 eri_enb_log_open(wtap
*wth
, int *err
, char **err_info
)
103 /* Look for Gammu DCT3 trace header */
104 if (file_gets(line1
, sizeof(line1
), wth
->fh
) == NULL
)
106 *err
= file_error(wth
->fh
, err_info
);
107 if (*err
!= 0 && *err
!= WTAP_ERR_SHORT_READ
)
108 return WTAP_OPEN_ERROR
;
109 return WTAP_OPEN_NOT_MINE
;
112 if (g_strstr_len(line1
, sizeof(line1
), eri_enb_log_magic
) == NULL
)
114 return WTAP_OPEN_NOT_MINE
;
117 if (file_seek(wth
->fh
, 0, SEEK_SET
, err
) == -1)
118 return WTAP_OPEN_ERROR
;
120 wth
->file_type_subtype
= eri_enb_log_file_type_subtype
;
121 wth
->file_encap
= WTAP_ENCAP_ERI_ENB_LOG
;
122 wth
->file_tsprec
= WTAP_TSPREC_NSEC
;
123 wth
->subtype_read
= eri_enb_log_read
;
124 wth
->subtype_seek_read
= eri_enb_log_seek_read
;
125 wth
->snapshot_length
= 0;
127 return WTAP_OPEN_MINE
;
130 static const struct supported_block_type eri_enb_log_blocks_supported
[] = {
132 * This is a file format that we dissect, so we provide
133 * only one "packet" with the file's contents, and don't
134 * support any options.
136 { WTAP_BLOCK_PACKET
, MULTIPLE_BLOCKS_SUPPORTED
, NO_OPTIONS_SUPPORTED
}
139 static const struct file_type_subtype_info eri_enb_log_info
= {
140 "Ericsson eNode-B raw log", "eri_enb_log", "eri_enb_log", NULL
,
141 false, BLOCKS_SUPPORTED(eri_enb_log_blocks_supported
),
145 void register_eri_enb_log(void)
147 eri_enb_log_file_type_subtype
= wtap_register_file_type_subtype(&eri_enb_log_info
);
150 * Register name for backwards compatibility with the
151 * wtap_filetypes table in Lua.
153 //wtap_register_backwards_compatibility_lua_name("MP4",
154 // eri_enb_log_file_type_subtype);
158 * Editor modelines - https://www.wireshark.org/tools/modelines.html
163 * indent-tabs-mode: t
166 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
167 * :indentSize=8:tabSize=8:noTabs=false: