~ubuntu-branches/ubuntu/gutsy/wireshark/gutsy-security

« back to all changes in this revision

Viewing changes to epan/dissectors/packet-radiotap.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2007-04-01 08:58:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070401085840-or3qhrpv8alt1bwg
Tags: 0.99.5-1
* New upstream release.
* debian/patches/09_idl2wrs.dpatch: updated to patch idl2wrs.sh.in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  packet-radiotap.c
3
3
 *      Decode packets with a Radiotap header
4
4
 *
5
 
 * $Id: packet-radiotap.c 19749 2006-10-31 01:51:39Z gerald $
 
5
 * $Id: packet-radiotap.c 19963 2006-11-23 01:49:18Z gerald $
6
6
 *
7
7
 * Wireshark - Network traffic analyzer
8
8
 * By Gerald Combs <gerald@wireshark.org>
141
141
static int hf_radiotap_length = -1;
142
142
static int hf_radiotap_present = -1;
143
143
static int hf_radiotap_mactime = -1;
 
144
static int hf_radiotap_channel = -1;
144
145
static int hf_radiotap_channel_frequency = -1;
145
146
static int hf_radiotap_channel_flags = -1;
 
147
static int hf_radiotap_fhss_hopset = -1;
 
148
static int hf_radiotap_fhss_pattern = -1;
146
149
static int hf_radiotap_datarate = -1;
147
150
static int hf_radiotap_antenna = -1;
148
151
static int hf_radiotap_dbm_antsignal = -1;
149
152
static int hf_radiotap_db_antsignal = -1;
150
153
static int hf_radiotap_dbm_antnoise = -1;
151
154
static int hf_radiotap_db_antnoise = -1;
 
155
static int hf_radiotap_tx_attenuation = -1;
 
156
static int hf_radiotap_db_tx_attenuation = -1;
152
157
static int hf_radiotap_txpower = -1;
153
158
 
154
159
/* "Present" flags */
200
205
#define BIT(n)  (1 << n)
201
206
 
202
207
/*
203
 
 * XXX - There are roundup macros defined in other dissectors.  We should
204
 
 * move them to a common location at some point.
205
 
 */
206
 
#ifndef roundup2
207
 
#define roundup2(x, y)  (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
208
 
#endif
 
208
 * The NetBSD ieee80211_radiotap man page
 
209
 * (http://netbsd.gw.com/cgi-bin/man-cgi?ieee80211_radiotap+9+NetBSD-current)
 
210
 * says:
 
211
 *
 
212
 *    Radiotap capture fields must be naturally aligned.  That is, 16-, 32-,
 
213
 *    and 64-bit fields must begin on 16-, 32-, and 64-bit boundaries, respec-
 
214
 *    tively.  In this way, drivers can avoid unaligned accesses to radiotap
 
215
 *    capture fields.  radiotap-compliant drivers must insert padding before a
 
216
 *    capture field to ensure its natural alignment.  radiotap-compliant packet
 
217
 *    dissectors, such as tcpdump(8), expect the padding.
 
218
 */
 
219
 
 
220
/*
 
221
 * Returns the amount required to align "offset" with "width"
 
222
 */
 
223
#define ALIGN_OFFSET(offset, width) \
 
224
    ( (((offset) + ((width) - 1)) & (~((width) - 1))) - offset )
 
225
 
209
226
 
210
227
void
211
228
capture_radiotap(const guchar *pd, int offset, int len, packet_counts *ld)
425
442
    { &hf_radiotap_fcs,
426
443
       { "802.11 FCS", "radiotap.fcs",
427
444
         FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL } },
 
445
    { &hf_radiotap_channel,
 
446
      { "Channel", "radiotap.channel",
 
447
        FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL } },
428
448
    { &hf_radiotap_channel_frequency,
429
449
      { "Channel frequency", "radiotap.channel.freq",
430
450
        FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL } },
431
451
    { &hf_radiotap_channel_flags,
432
452
      { "Channel type", "radiotap.channel.flags",
433
453
        FT_UINT16, BASE_HEX, VALS(phy_type), 0x0, "", HFILL } },
 
454
    { &hf_radiotap_fhss_hopset,
 
455
      { "FHSS Hop Set", "radiotap.fhss.hopset",
 
456
        FT_UINT8, BASE_DEC, NULL,  0x0, "", HFILL } },
 
457
    { &hf_radiotap_fhss_pattern,
 
458
      { "FHSS Pattern", "radiotap.fhss.pattern",
 
459
        FT_UINT8, BASE_DEC, NULL,  0x0, "", HFILL } },
434
460
    { &hf_radiotap_datarate,
435
461
      { "Data rate", "radiotap.datarate",
436
462
        FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL } },
449
475
    { &hf_radiotap_db_antnoise,
450
476
      { "SSI Noise (dB)", "radiotap.db_antnoise",
451
477
        FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL } },
 
478
    { &hf_radiotap_tx_attenuation,
 
479
      { "Transmit attenuation", "radiotap.txattenuation",
 
480
        FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL } },
 
481
    { &hf_radiotap_db_tx_attenuation,
 
482
      { "Transmit attenuation (dB)", "radiotap.db_txattenuation",
 
483
        FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL } },
452
484
    { &hf_radiotap_txpower,
453
485
      { "Transmit power", "radiotap.txpower",
454
486
        FT_INT32, BASE_DEC, NULL, 0x0, "", HFILL } },
520
552
    proto_item *ti = NULL;
521
553
    proto_item *hdr_fcs_ti = NULL;
522
554
    int hdr_fcs_offset = 0;
523
 
    int offset;
 
555
    int align_offset, offset;
524
556
    guint32 sent_fcs = 0;
525
557
    guint32 calc_fcs;
526
558
    tvbuff_t *next_tvb;
530
562
    gint8 dbm;
531
563
    guint8 db, rflags;
532
564
    guint32 present, next_present;
533
 
    int bit;
 
565
    int bit, channel;
534
566
 
535
567
    if(check_col(pinfo->cinfo, COL_PROTOCOL))
536
568
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "WLAN");
745
777
            length_remaining--;
746
778
            break;
747
779
        case IEEE80211_RADIOTAP_CHANNEL:
748
 
            if (length_remaining < 4)
 
780
            align_offset = ALIGN_OFFSET(offset, 2);
 
781
            offset += align_offset;
 
782
            length_remaining -= align_offset;
 
783
            if (length_remaining < 2)
749
784
                break;
750
785
            if (tree) {
751
786
                freq = tvb_get_letohs(tvb, offset);
752
787
                flags = tvb_get_letohs(tvb, offset+2);
753
 
                proto_tree_add_uint_format(radiotap_tree, hf_radiotap_channel_frequency,
754
 
                        tvb, offset, 2, freq,
755
 
                        "Channel: %u (chan %u)", freq, ieee80211_mhz2ieee(freq, flags));
756
 
                proto_tree_add_uint(radiotap_tree, hf_radiotap_channel_flags,
 
788
                channel = ieee80211_mhz2ieee(freq, flags);
 
789
                if (channel < 1) {
 
790
                        proto_tree_add_uint_format(radiotap_tree, hf_radiotap_channel_frequency,
 
791
                                tvb, offset, 2, freq,
 
792
                                "Channel frequency: %u (invalid)", freq);
 
793
                } else {
 
794
                        proto_tree_add_uint(radiotap_tree, hf_radiotap_channel,
 
795
                                tvb, offset, 2, (guint32) channel);
 
796
                        proto_tree_add_uint(radiotap_tree, hf_radiotap_channel_frequency,
 
797
                                tvb, offset, 2, freq);
 
798
                }
 
799
                /* We're already 2-byte aligned. */
 
800
                proto_tree_add_uint(radiotap_tree, hf_radiotap_channel_flags,
757
801
                        tvb, offset+2, 2, flags);
758
802
            }
759
 
            offset+=4;
 
803
            offset+=4 /* Channel + flags */;
760
804
            length_remaining-=4;
761
805
            break;
762
806
        case IEEE80211_RADIOTAP_FHSS:
 
807
            align_offset = ALIGN_OFFSET(offset, 2);
 
808
            offset += align_offset;
 
809
            length_remaining -= align_offset;
 
810
            if (length_remaining < 2)
 
811
                break;
 
812
            proto_tree_add_item(radiotap_tree, hf_radiotap_fhss_hopset,
 
813
                tvb, offset, 1, FALSE);
 
814
            proto_tree_add_item(radiotap_tree, hf_radiotap_fhss_pattern,
 
815
                tvb, offset, 1, FALSE);
 
816
            offset+=2;
 
817
            length_remaining-=2;
 
818
            break;
763
819
        case IEEE80211_RADIOTAP_TX_ATTENUATION:
 
820
            align_offset = ALIGN_OFFSET(offset, 2);
 
821
            offset += align_offset;
 
822
            length_remaining -= align_offset;
 
823
            if (length_remaining < 2)
 
824
                break;
 
825
            proto_tree_add_item(radiotap_tree, hf_radiotap_tx_attenuation,
 
826
                tvb, offset, 2, FALSE);
 
827
            offset+=2;
 
828
            length_remaining-=2;
 
829
            break;
764
830
        case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
 
831
            align_offset = ALIGN_OFFSET(offset, 2);
 
832
            offset += align_offset;
 
833
            length_remaining -= align_offset;
765
834
            if (length_remaining < 2)
766
835
                break;
767
 
#if 0
768
 
            tvb_get_letohs(tvb, offset);
769
 
#endif
 
836
            proto_tree_add_item(radiotap_tree, hf_radiotap_db_tx_attenuation,
 
837
                tvb, offset, 2, FALSE);
770
838
            offset+=2;
771
839
            length_remaining-=2;
772
840
            break;
773
841
        case IEEE80211_RADIOTAP_TSFT:
 
842
            align_offset = ALIGN_OFFSET(offset, 8);
 
843
            offset += align_offset;
 
844
            length_remaining -= align_offset;
774
845
            if (length_remaining < 8)
775
846
                break;
776
847
            if (tree) {
781
852
            length_remaining-=8;
782
853
            break;
783
854
        case IEEE80211_RADIOTAP_LOCK_QUALITY:
 
855
            align_offset = ALIGN_OFFSET(offset, 2);
 
856
            offset += align_offset;
 
857
            length_remaining -= align_offset;
784
858
            if (length_remaining < 2)
785
859
                break;
786
860
            if (tree) {
792
866
            break;
793
867
        case IEEE80211_RADIOTAP_FCS:
794
868
        /* This handles the case of an FCS existing inside the radiotap header. */
795
 
            offset = roundup2(offset, 4);
 
869
            align_offset = ALIGN_OFFSET(offset, 4);
 
870
            offset += align_offset;
 
871
            length_remaining -= align_offset;
796
872
            if (length_remaining < 4)
797
873
                break;
798
874
        if (tree) {