Refactor 802.11 radio flags.
[metze/wireshark/wip.git] / wiretap / commview.c
1 /* commview.c
2  * Routines for opening CommView file format packet captures
3  * Copyright 2007, Stephen Fisher (see AUTHORS file)
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * Based on csids.c and nettl.c
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
24  * USA.
25  */
26
27 /* A brief description of this file format is available at:
28  *    http://www.tamos.com/htmlhelp/commview/logformat.htm
29  */
30
31 #include "config.h"
32
33 #include <stdlib.h>
34 #include <errno.h>
35 #include <string.h>
36
37 #include "wtap-int.h"
38 #include "file_wrappers.h"
39 #include "commview.h"
40
41 #include <wsutil/frequency-utils.h>
42
43 typedef struct commview_header {
44         guint16         data_len;
45         guint16         source_data_len;
46         guint8          version;
47         guint16         year;
48         guint8          month;
49         guint8          day;
50         guint8          hours;
51         guint8          minutes;
52         guint8          seconds;
53         guint32         usecs;
54         guint8          flags;          /* Bit-field positions defined below */
55         guint8          signal_level_percent;
56         guint8          rate;
57         guint8          band;
58         guint8          channel;
59         guint8          direction;      /* Or for WiFi, high order byte of
60                                          * packet rate. */
61         gint8           signal_level_dbm;
62         gint8           noise_level;    /* In dBm (WiFi only) */
63 } commview_header_t;
64
65 #define COMMVIEW_HEADER_SIZE 24
66
67 /* Bit-field positions for various fields in the flags variable of the header */
68 #define FLAGS_MEDIUM            0x0F
69 #define FLAGS_DECRYPTED         0x10
70 #define FLAGS_BROKEN            0x20
71 #define FLAGS_COMPRESSED        0x40
72 #define FLAGS_RESERVED          0x80
73
74 /* Values for the band variable of the header */
75 #define BAND_11A                0x01
76 #define BAND_11B                0x02
77 #define BAND_11G                0x04
78 #define BAND_11A_TURBO          0x08
79 #define BAND_SUPERG             0x10
80 #define BAND_PUBLIC_SAFETY      0x20    /* 4.99 GHz public safety */
81 #define BAND_11N_5GHZ           0x40
82 #define BAND_11N_2_4GHZ         0x80
83
84 /* Capture mediums as defined by the commview file format */
85 #define MEDIUM_ETHERNET         0
86 #define MEDIUM_WIFI             1
87 #define MEDIUM_TOKEN_RING       2
88
89 static gboolean commview_read(wtap *wth, int *err, gchar **err_info,
90                               gint64 *data_offset);
91 static gboolean commview_seek_read(wtap *wth, gint64 seek_off,
92                                    struct wtap_pkthdr *phdr,
93                                    Buffer *buf, int *err, gchar **err_info);
94 static gboolean commview_read_header(commview_header_t *cv_hdr, FILE_T fh,
95                                      int *err, gchar **err_info);
96 static gboolean commview_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
97                               const guint8 *pd, int *err, gchar **err_info);
98
99 wtap_open_return_val commview_open(wtap *wth, int *err, gchar **err_info)
100 {
101         commview_header_t cv_hdr;
102
103         if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) {
104                 if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
105                         return WTAP_OPEN_ERROR;
106                 return WTAP_OPEN_NOT_MINE;
107         }
108
109         /* If any of these fields do not match what we expect, bail out. */
110         if(cv_hdr.version != 0 ||
111            cv_hdr.year < 1970 || cv_hdr.year >= 2038 ||
112            cv_hdr.month < 1 || cv_hdr.month > 12 ||
113            cv_hdr.day < 1 || cv_hdr.day > 31 ||
114            cv_hdr.hours > 23 ||
115            cv_hdr.minutes > 59 ||
116            cv_hdr.seconds > 60 ||
117            cv_hdr.signal_level_percent > 100 ||
118            (cv_hdr.flags & FLAGS_RESERVED) != 0 ||
119            ((cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_ETHERNET &&
120             (cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_WIFI &&
121             (cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_TOKEN_RING))
122                 return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
123
124         /* No file header. Reset the fh to 0 so we can read the first packet */
125         if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
126                 return WTAP_OPEN_ERROR;
127
128         /* Set up the pointers to the handlers for this file type */
129         wth->subtype_read = commview_read;
130         wth->subtype_seek_read = commview_seek_read;
131
132         wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COMMVIEW;
133         wth->file_encap = WTAP_ENCAP_PER_PACKET;
134         wth->file_tsprec = WTAP_TSPREC_USEC;
135
136         return WTAP_OPEN_MINE; /* Our kind of file */
137 }
138
139 static int
140 commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
141     int *err, gchar **err_info)
142 {
143         commview_header_t cv_hdr;
144         struct tm tm;
145         guint frequency;
146
147         if(!commview_read_header(&cv_hdr, fh, err, err_info))
148                 return FALSE;
149
150         switch(cv_hdr.flags & FLAGS_MEDIUM) {
151
152         case MEDIUM_ETHERNET :
153                 phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
154                 phdr->pseudo_header.eth.fcs_len = -1; /* Unknown */
155                 break;
156
157         case MEDIUM_WIFI :
158                 phdr->pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
159                 memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11));
160                 phdr->pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */
161                 phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
162                 phdr->pseudo_header.ieee_802_11.datapad = FALSE;
163                 phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN;
164                 switch (cv_hdr.band) {
165
166                 case BAND_11A:
167                         phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
168                         phdr->pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE;
169                         phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type =
170                             PHDR_802_11A_TURBO_TYPE_NORMAL;
171                         frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
172                         break;
173
174                 case BAND_11B:
175                         phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B;
176                         frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
177                         break;
178
179                 case BAND_11G:
180                         phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
181                         phdr->pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE;
182                         phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode =
183                             PHDR_802_11G_MODE_NORMAL;
184                         frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
185                         break;
186
187                 case BAND_11A_TURBO:
188                         phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
189                         phdr->pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE;
190                         phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type =
191                             PHDR_802_11A_TURBO_TYPE_TURBO;
192                         frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
193                         break;
194
195                 case BAND_SUPERG:
196                         phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
197                         phdr->pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE;
198                         phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode =
199                             PHDR_802_11G_MODE_SUPER_G;
200                         frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
201                         break;
202
203                 case BAND_11N_5GHZ:
204                         phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N;
205                         frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
206                         break;
207
208                 case BAND_11N_2_4GHZ:
209                         phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N;
210                         frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
211                         break;
212
213                 case BAND_PUBLIC_SAFETY:
214                         /*
215                          * XXX - what do we do here?  What are the channel
216                          * numbers?  How do we distinguish the several
217                          * different flavors of 4.9 GHz frequencies?
218                          */
219                         frequency = 0;
220                         break;
221
222                 default:
223                         frequency = 0;
224                         break;
225                 }
226                 if (frequency != 0) {
227                         phdr->pseudo_header.ieee_802_11.has_frequency = TRUE;
228                         phdr->pseudo_header.ieee_802_11.frequency = frequency;
229                 }
230                 phdr->pseudo_header.ieee_802_11.has_channel = TRUE;
231                 phdr->pseudo_header.ieee_802_11.channel = cv_hdr.channel;
232
233                 phdr->pseudo_header.ieee_802_11.has_data_rate = TRUE;
234                 phdr->pseudo_header.ieee_802_11.data_rate =
235                     cv_hdr.rate | (cv_hdr.direction << 8);
236
237                 phdr->pseudo_header.ieee_802_11.has_signal_percent = TRUE;
238                 phdr->pseudo_header.ieee_802_11.signal_percent = cv_hdr.signal_level_percent;
239
240                 /*
241                  * XXX - these are positive in captures I've seen; does
242                  * that mean that they are the negative of the actual
243                  * dBm value?  (80 dBm is a bit more power than most
244                  * countries' regulatory agencies are likely to allow
245                  * any individual to have in their home. :-))
246                  *
247                  * XXX - sometimes these are 0; assume that means that no
248                  * value is provided.
249                  */
250                 if (cv_hdr.signal_level_dbm != 0) {
251                         phdr->pseudo_header.ieee_802_11.signal_dbm = -cv_hdr.signal_level_dbm;
252                         phdr->pseudo_header.ieee_802_11.has_signal_dbm = TRUE;
253                 }
254                 if (cv_hdr.noise_level != 0) {
255                         phdr->pseudo_header.ieee_802_11.noise_dbm = -cv_hdr.noise_level;
256                         phdr->pseudo_header.ieee_802_11.has_noise_dbm = TRUE;
257                 }
258                 break;
259
260         case MEDIUM_TOKEN_RING :
261                 phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING;
262                 break;
263
264         default :
265                 *err = WTAP_ERR_BAD_FILE;
266                 *err_info = g_strdup_printf("commview: unsupported encap: %u",
267                                             cv_hdr.flags & FLAGS_MEDIUM);
268                 return FALSE;
269         }
270
271         tm.tm_year = cv_hdr.year - 1900;
272         tm.tm_mon = cv_hdr.month - 1;
273         tm.tm_mday = cv_hdr.day;
274         tm.tm_hour = cv_hdr.hours;
275         tm.tm_min = cv_hdr.minutes;
276         tm.tm_sec = cv_hdr.seconds;
277         tm.tm_isdst = -1;
278
279         phdr->rec_type = REC_TYPE_PACKET;
280         phdr->presence_flags = WTAP_HAS_TS;
281
282         phdr->len = cv_hdr.data_len;
283         phdr->caplen = cv_hdr.data_len;
284
285         phdr->ts.secs = mktime(&tm);
286         phdr->ts.nsecs = cv_hdr.usecs * 1000;
287
288         return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
289 }
290
291 static gboolean
292 commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
293 {
294         *data_offset = file_tell(wth->fh);
295
296         return commview_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err,
297             err_info);
298 }
299
300 static gboolean
301 commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
302                    Buffer *buf, int *err, gchar **err_info)
303 {
304         if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
305                 return FALSE;
306
307         return commview_read_packet(wth->random_fh, phdr, buf, err, err_info);
308 }
309
310 static gboolean
311 commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err,
312     gchar **err_info)
313 {
314         if (!wtap_read_bytes_or_eof(fh, &cv_hdr->data_len, 2, err, err_info))
315                 return FALSE;
316         if (!wtap_read_bytes(fh, &cv_hdr->source_data_len, 2, err, err_info))
317                 return FALSE;
318         if (!wtap_read_bytes(fh, &cv_hdr->version, 1, err, err_info))
319                 return FALSE;
320         if (!wtap_read_bytes(fh, &cv_hdr->year, 2, err, err_info))
321                 return FALSE;
322         if (!wtap_read_bytes(fh, &cv_hdr->month, 1, err, err_info))
323                 return FALSE;
324         if (!wtap_read_bytes(fh, &cv_hdr->day, 1, err, err_info))
325                 return FALSE;
326         if (!wtap_read_bytes(fh, &cv_hdr->hours, 1, err, err_info))
327                 return FALSE;
328         if (!wtap_read_bytes(fh, &cv_hdr->minutes, 1, err, err_info))
329                 return FALSE;
330         if (!wtap_read_bytes(fh, &cv_hdr->seconds, 1, err, err_info))
331                 return FALSE;
332         if (!wtap_read_bytes(fh, &cv_hdr->usecs, 4, err, err_info))
333                 return FALSE;
334         if (!wtap_read_bytes(fh, &cv_hdr->flags, 1, err, err_info))
335                 return FALSE;
336         if (!wtap_read_bytes(fh, &cv_hdr->signal_level_percent, 1, err, err_info))
337                 return FALSE;
338         if (!wtap_read_bytes(fh, &cv_hdr->rate, 1, err, err_info))
339                 return FALSE;
340         if (!wtap_read_bytes(fh, &cv_hdr->band, 1, err, err_info))
341                 return FALSE;
342         if (!wtap_read_bytes(fh, &cv_hdr->channel, 1, err, err_info))
343                 return FALSE;
344         if (!wtap_read_bytes(fh, &cv_hdr->direction, 1, err, err_info))
345                 return FALSE;
346         if (!wtap_read_bytes(fh, &cv_hdr->signal_level_dbm, 1, err, err_info))
347                 return FALSE;
348         if (!wtap_read_bytes(fh, &cv_hdr->noise_level, 1, err, err_info))
349                 return FALSE;
350
351         /* Convert multi-byte values from little endian to host endian format */
352         cv_hdr->data_len = GUINT16_FROM_LE(cv_hdr->data_len);
353         cv_hdr->source_data_len = GUINT16_FROM_LE(cv_hdr->source_data_len);
354         cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year);
355         cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs);
356
357         return TRUE;
358 }
359
360 /* Returns 0 if we can write out the specified encapsulation type
361  * into a CommView format file. */
362 int commview_dump_can_write_encap(int encap)
363 {
364         switch (encap) {
365
366         case WTAP_ENCAP_ETHERNET :
367         case WTAP_ENCAP_IEEE_802_11 :
368         case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
369         case WTAP_ENCAP_TOKEN_RING :
370         case WTAP_ENCAP_PER_PACKET :
371                 return 0;
372
373         default:
374                 return WTAP_ERR_UNWRITABLE_ENCAP;
375         }
376 }
377
378 /* Returns TRUE on success, FALSE on failure;
379    sets "*err" to an error code on failure */
380 gboolean commview_dump_open(wtap_dumper *wdh, int *err _U_)
381 {
382         wdh->subtype_write = commview_dump;
383
384         /* There is no file header to write out */
385         wdh->bytes_dumped = 0;
386
387         return TRUE;
388 }
389
390 /* Write a record for a packet to a dump file.
391  * Returns TRUE on success, FALSE on failure. */
392 static gboolean commview_dump(wtap_dumper *wdh,
393                               const struct wtap_pkthdr *phdr,
394                               const guint8 *pd, int *err, gchar **err_info _U_)
395 {
396         commview_header_t cv_hdr;
397         struct tm *tm;
398
399         /* We can only write packet records. */
400         if (phdr->rec_type != REC_TYPE_PACKET) {
401                 *err = WTAP_ERR_UNWRITABLE_REC_TYPE;
402                 return FALSE;
403         }
404
405         /* Don't write out anything bigger than we can read.
406          * (The length field in packet headers is 16 bits, which
407          * imposes a hard limit.) */
408         if (phdr->caplen > 65535) {
409                 *err = WTAP_ERR_PACKET_TOO_LARGE;
410                 return FALSE;
411         }
412
413         memset(&cv_hdr, 0, sizeof(cv_hdr));
414
415         cv_hdr.data_len = GUINT16_TO_LE((guint16)phdr->caplen);
416         cv_hdr.source_data_len = GUINT16_TO_LE((guint16)phdr->caplen);
417         cv_hdr.version = 0;
418
419         tm = localtime(&phdr->ts.secs);
420         cv_hdr.year = tm->tm_year + 1900;
421         cv_hdr.month = tm->tm_mon + 1;
422         cv_hdr.day = tm->tm_mday;
423         cv_hdr.hours = tm->tm_hour;
424         cv_hdr.minutes = tm->tm_min;
425         cv_hdr.seconds = tm->tm_sec;
426         cv_hdr.usecs = GUINT32_TO_LE(phdr->ts.nsecs / 1000);
427
428         switch(phdr->pkt_encap) {
429
430         case WTAP_ENCAP_ETHERNET :
431                 cv_hdr.flags |= MEDIUM_ETHERNET;
432                 break;
433
434         case WTAP_ENCAP_IEEE_802_11 :
435                 cv_hdr.flags |=  MEDIUM_WIFI;
436                 break;
437
438         case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
439                 cv_hdr.flags |=  MEDIUM_WIFI;
440
441                 switch (phdr->pseudo_header.ieee_802_11.phy) {
442
443                 case PHDR_802_11_PHY_11A:
444                         /*
445                          * If we don't know whether it's turbo, say it's
446                          * not.
447                          */
448                         if (!phdr->pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type ||
449                             phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type == PHDR_802_11A_TURBO_TYPE_NORMAL)
450                                 cv_hdr.band = BAND_11A;
451                         else
452                                 cv_hdr.band = BAND_11A_TURBO;
453                         break;
454
455                 case PHDR_802_11_PHY_11B:
456                         cv_hdr.band = BAND_11B;
457                         break;
458
459                 case PHDR_802_11_PHY_11G:
460                         /*
461                          * If we don't know whether it's Super G, say it's
462                          * not.
463                          */
464                         if (!phdr->pseudo_header.ieee_802_11.phy_info.info_11g.has_mode)
465                                 cv_hdr.band = BAND_11G;
466                         else {
467                                 switch (phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode) {
468
469                                 case PHDR_802_11G_MODE_NORMAL:
470                                         cv_hdr.band = BAND_11G;
471                                         break;
472
473                                 case PHDR_802_11G_MODE_SUPER_G:
474                                         cv_hdr.band = BAND_SUPERG;
475                                         break;
476
477                                 default:
478                                         cv_hdr.band = BAND_11G;
479                                         break;
480                                 }
481                         }
482                         break;
483
484                 case PHDR_802_11_PHY_11N:
485                         /*
486                          * Pick the band based on the frequency.
487                          */
488                         if (phdr->pseudo_header.ieee_802_11.has_frequency) {
489                                 if (phdr->pseudo_header.ieee_802_11.frequency > 2484) {
490                                         /* 5 GHz band */
491                                         cv_hdr.band = BAND_11N_5GHZ;
492                                 } else {
493                                         /* 2.4 GHz band */
494                                         cv_hdr.band = BAND_11N_2_4GHZ;
495                                 }
496                         } else {
497                                 /* Band is unknown. */
498                                 cv_hdr.band = 0;
499                         }
500                         break;
501
502                 default:
503                         /*
504                          * It's not documented how they handle 11ac,
505                          * and they don't support the older PHYs.
506                          */
507                         cv_hdr.band = 0;
508                         break;
509                 }
510                 cv_hdr.channel =
511                     phdr->pseudo_header.ieee_802_11.has_channel ?
512                       phdr->pseudo_header.ieee_802_11.channel :
513                       0;
514                 cv_hdr.rate =
515                     phdr->pseudo_header.ieee_802_11.has_data_rate ?
516                       (guint8)(phdr->pseudo_header.ieee_802_11.data_rate & 0xFF) :
517                       0;
518                 cv_hdr.direction =
519                     phdr->pseudo_header.ieee_802_11.has_data_rate ?
520                       (guint8)((phdr->pseudo_header.ieee_802_11.data_rate >> 8) & 0xFF) :
521                       0;
522                 cv_hdr.signal_level_percent =
523                     phdr->pseudo_header.ieee_802_11.has_signal_percent ?
524                       phdr->pseudo_header.ieee_802_11.signal_percent :
525                       0;
526                 cv_hdr.signal_level_dbm =
527                     phdr->pseudo_header.ieee_802_11.has_signal_dbm ?
528                       -phdr->pseudo_header.ieee_802_11.signal_dbm :
529                       0;
530                 cv_hdr.noise_level =
531                     phdr->pseudo_header.ieee_802_11.has_noise_dbm ?
532                       -phdr->pseudo_header.ieee_802_11.noise_dbm :
533                       0;
534                 break;
535
536         case WTAP_ENCAP_TOKEN_RING :
537                 cv_hdr.flags |= MEDIUM_TOKEN_RING;
538                 break;
539
540         default :
541                 *err = WTAP_ERR_UNWRITABLE_ENCAP;
542                 return FALSE;
543         }
544
545         if (!wtap_dump_file_write(wdh, &cv_hdr.data_len, 2, err))
546                 return FALSE;
547         if (!wtap_dump_file_write(wdh, &cv_hdr.source_data_len, 2, err))
548                 return FALSE;
549         if (!wtap_dump_file_write(wdh, &cv_hdr.version, 1, err))
550                 return FALSE;
551         if (!wtap_dump_file_write(wdh, &cv_hdr.year, 2, err))
552                 return FALSE;
553         if (!wtap_dump_file_write(wdh, &cv_hdr.month, 1, err))
554                 return FALSE;
555         if (!wtap_dump_file_write(wdh, &cv_hdr.day, 1, err))
556                 return FALSE;
557         if (!wtap_dump_file_write(wdh, &cv_hdr.hours, 1, err))
558                 return FALSE;
559         if (!wtap_dump_file_write(wdh, &cv_hdr.minutes, 1, err))
560                 return FALSE;
561         if (!wtap_dump_file_write(wdh, &cv_hdr.seconds, 1, err))
562                 return FALSE;
563         if (!wtap_dump_file_write(wdh, &cv_hdr.usecs, 4, err))
564                 return FALSE;
565         if (!wtap_dump_file_write(wdh, &cv_hdr.flags, 1, err))
566                 return FALSE;
567         if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_percent, 1, err))
568                 return FALSE;
569         if (!wtap_dump_file_write(wdh, &cv_hdr.rate, 1, err))
570                 return FALSE;
571         if (!wtap_dump_file_write(wdh, &cv_hdr.band, 1, err))
572                 return FALSE;
573         if (!wtap_dump_file_write(wdh, &cv_hdr.channel, 1, err))
574                 return FALSE;
575         if (!wtap_dump_file_write(wdh, &cv_hdr.direction, 1, err))
576                 return FALSE;
577         if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_dbm, 2, err))
578                 return FALSE;
579         if (!wtap_dump_file_write(wdh, &cv_hdr.noise_level, 2, err))
580                 return FALSE;
581         wdh->bytes_dumped += COMMVIEW_HEADER_SIZE;
582
583         if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
584                 return FALSE;
585         wdh->bytes_dumped += phdr->caplen;
586
587         return TRUE;
588 }
589
590 /*
591  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
592  *
593  * Local variables:
594  * c-basic-offset: 8
595  * tab-width: 8
596  * indent-tabs-mode: t
597  * End:
598  *
599  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
600  * :indentSize=8:tabSize=8:noTabs=false:
601  */