3 * Copyright (c) 2003 by Marcel Holtmann <marcel@holtmann.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "file_wrappers.h"
34 #define DUMP_HDR_SIZE (sizeof(struct dump_hdr))
36 static gboolean hcidump_read_packet(FILE_T fh, struct wtap_pkthdr *phdr,
37 Buffer *buf, int *err, gchar **err_info)
42 if (!wtap_read_bytes_or_eof(fh, &dh, DUMP_HDR_SIZE, err, err_info))
45 packet_size = GUINT16_FROM_LE(dh.len);
46 if (packet_size > WTAP_MAX_PACKET_SIZE) {
48 * Probably a corrupt capture file; don't blow up trying
49 * to allocate space for an immensely-large packet.
51 *err = WTAP_ERR_BAD_FILE;
52 *err_info = g_strdup_printf("hcidump: File has %u-byte packet, bigger than maximum of %u",
53 packet_size, WTAP_MAX_PACKET_SIZE);
57 phdr->rec_type = REC_TYPE_PACKET;
58 phdr->presence_flags = WTAP_HAS_TS;
59 phdr->ts.secs = GUINT32_FROM_LE(dh.ts_sec);
60 phdr->ts.nsecs = GUINT32_FROM_LE(dh.ts_usec) * 1000;
61 phdr->caplen = packet_size;
62 phdr->len = packet_size;
64 phdr->pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE);
66 return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
69 static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
72 *data_offset = file_tell(wth->fh);
74 return hcidump_read_packet(wth->fh, &wth->phdr, wth->frame_buffer,
78 static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off,
79 struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
81 if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
84 return hcidump_read_packet(wth->random_fh, phdr, buf, err, err_info);
87 wtap_open_return_val hcidump_open(wtap *wth, int *err, gchar **err_info)
92 if (!wtap_read_bytes(wth->fh, &dh, DUMP_HDR_SIZE, err, err_info)) {
93 if (*err != WTAP_ERR_SHORT_READ)
94 return WTAP_OPEN_ERROR;
95 return WTAP_OPEN_NOT_MINE;
98 if ((dh.in != 0 && dh.in != 1) || dh.pad != 0
99 || GUINT16_FROM_LE(dh.len) < 1)
100 return WTAP_OPEN_NOT_MINE;
102 if (!wtap_read_bytes(wth->fh, &type, 1, err, err_info)) {
103 if (*err != WTAP_ERR_SHORT_READ)
104 return WTAP_OPEN_ERROR;
105 return WTAP_OPEN_NOT_MINE;
108 if (type < 1 || type > 4)
109 return WTAP_OPEN_NOT_MINE;
111 if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
112 return WTAP_OPEN_ERROR;
114 wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_HCIDUMP;
115 wth->file_encap = WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR;
116 wth->snapshot_length = 0;
118 wth->subtype_read = hcidump_read;
119 wth->subtype_seek_read = hcidump_seek_read;
120 wth->file_tsprec = WTAP_TSPREC_USEC;
122 return WTAP_OPEN_MINE;
126 * Editor modelines - http://www.wireshark.org/tools/modelines.html
131 * indent-tabs-mode: t
134 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
135 * :indentSize=8:tabSize=8:noTabs=false: