Ticket #65: libtrace3_wireless_support2.patch

File libtrace3_wireless_support2.patch, 30.5 KB (added by smr26@…, 16 years ago)

Third time lucky?

  • lib/link_wireless.c

     
     1/*
     2 * This file is part of libtrace
     3 *
     4 * link_wireless.c
     5 * Implements the trace_get_wireless_* methods defined in libtrace.h
     6 *
     7 * Copyright (c) 2006 The University of Waikato, Hamilton, New Zealand.
     8 * Authors: Scott Raynel
     9 *          Perry Lorier
     10 *         
     11 * All rights reserved.
     12 *
     13 * This code has been developed by the University of Waikato WAND
     14 * research group. For further information please see http://www.wand.net.nz/
     15 *
     16 * libtrace is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * libtrace is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with libtrace; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 */
     31
     32#include "libtrace.h"
     33#include "libtrace_int.h"
     34
     35/* Used for Radiotap fields which must be naturally aligned */
     36#define ALIGN_NATURAL_64(_p,_s) \
     37    while ( (_p - _s) % sizeof(uint64_t)) _p++
     38#define ALIGN_NATURAL_32(_p,_s) \
     39    while ( (_p - _s) % sizeof(uint32_t)) _p++
     40#define ALIGN_NATURAL_16(_p,_s) \
     41    while ( (_p - _s) % sizeof(uint16_t)) _p++
     42
     43/** Gets a field from a Radiotap header.
     44 * @param link the radiotap header
     45 * @param field the radiotap field we want to access
     46 * @return a void pointer to the field. It is up to the caller to cast to the
     47 * appropriate type.
     48 * @note Radiotap fields are always little-endian
     49 */
     50static void *trace_get_radiotap_field(void *link, libtrace_radiotap_field_t field)
     51{
     52    struct libtrace_radiotap_t *rtap = (struct libtrace_radiotap_t *)link;
     53    uint8_t *p;
     54    uint8_t *s;
     55   
     56    /* Check if the field exists in the radiotap header before proceeding
     57     */
     58    if (rtap->it_present & (1 << field) == 0) return NULL;
     59
     60    /* Skip over any extended bitmasks */
     61    p = (uint8_t *) &(rtap->it_present);
     62   
     63    while ( *((uint32_t*)p) & (1 << TRACE_RADIOTAP_EXT) ) {
     64        p += sizeof (uint32_t);
     65    }
     66
     67    /* Point p at the first field of radiotap data and remember it for later
     68     * when we're doing field alignment
     69     */
     70    p += sizeof(uint32_t);
     71    s = p;
     72   
     73    if (field == TRACE_RADIOTAP_TSFT)
     74        /* Always aligned */
     75        return (void*)p;
     76    if (rtap->it_present & (1 << TRACE_RADIOTAP_TSFT))
     77        p += sizeof (uint64_t);
     78
     79    if (field == TRACE_RADIOTAP_FLAGS)
     80        /* Always aligned */
     81        return (void*)p;
     82    if (rtap->it_present & (1 << TRACE_RADIOTAP_FLAGS))
     83        p += sizeof (uint8_t);
     84
     85    if (field == TRACE_RADIOTAP_RATE)
     86        /* Always aligned */
     87        return (void*)p;
     88    if (rtap->it_present & (1 << TRACE_RADIOTAP_RATE))
     89        p+= sizeof (uint8_t);
     90
     91    if (field == TRACE_RADIOTAP_CHANNEL)
     92    {
     93        ALIGN_NATURAL_16(p,s);
     94        return (void *)p;
     95    }
     96    if (rtap->it_present & (1 << TRACE_RADIOTAP_CHANNEL))
     97        p+= sizeof (uint32_t);
     98
     99    if (field == TRACE_RADIOTAP_FHSS)
     100    {
     101        ALIGN_NATURAL_16(p,s);
     102        return (void *)p;
     103    }
     104    if (rtap->it_present & (1 << TRACE_RADIOTAP_FHSS))
     105        p+= sizeof (uint16_t);
     106
     107    if (field == TRACE_RADIOTAP_DBM_ANTSIGNAL)
     108        return (void *)p;
     109    if (rtap->it_present & (1 << TRACE_RADIOTAP_DBM_ANTSIGNAL))
     110        p+= sizeof (uint8_t);
     111
     112    if (field == TRACE_RADIOTAP_DBM_ANTNOISE)
     113        return (void *)p;
     114    if (rtap->it_present & (1 << TRACE_RADIOTAP_DBM_ANTNOISE))
     115        p+= sizeof (uint8_t);
     116
     117    if (field == TRACE_RADIOTAP_LOCK_QUALITY)
     118    {
     119        ALIGN_NATURAL_16(p,s);
     120        return (void *)p;
     121    }
     122    if (rtap->it_present & (1 << TRACE_RADIOTAP_LOCK_QUALITY))
     123        p+= sizeof (uint16_t);
     124
     125    if (field == TRACE_RADIOTAP_TX_ATTENUATION)
     126    {
     127        ALIGN_NATURAL_16(p,s);
     128        return (void *)p;
     129    }
     130    if (rtap->it_present & (1 << TRACE_RADIOTAP_TX_ATTENUATION))
     131        p+= sizeof (uint16_t);
     132
     133    if (field == TRACE_RADIOTAP_DB_TX_ATTENUATION)
     134    {
     135        ALIGN_NATURAL_16(p,s);
     136        return (void *)p;
     137    }
     138    if (rtap->it_present & (1 << TRACE_RADIOTAP_DB_TX_ATTENUATION))
     139        p+= sizeof (uint16_t);
     140
     141    if (field == TRACE_RADIOTAP_DBM_TX_POWER)
     142        return (void *)p;
     143    if (rtap->it_present & (1 << TRACE_RADIOTAP_DBM_TX_POWER))
     144        p+= sizeof (uint8_t);
     145   
     146    if (field == TRACE_RADIOTAP_ANTENNA)
     147        return (void *)p;
     148    if (rtap->it_present & (1 << TRACE_RADIOTAP_ANTENNA))
     149        p+= sizeof (uint8_t);
     150
     151    if (field == TRACE_RADIOTAP_DB_ANTSIGNAL)
     152        return (void *)p;
     153    if (rtap->it_present & (1 << TRACE_RADIOTAP_DB_ANTSIGNAL))
     154        p+= sizeof (uint8_t);
     155
     156    if (field == TRACE_RADIOTAP_DB_ANTNOISE)
     157        return (void *) p;
     158    if (rtap->it_present & (1 << TRACE_RADIOTAP_DB_ANTNOISE))
     159        p+= sizeof (uint8_t);
     160   
     161    if (field == TRACE_RADIOTAP_FCS)
     162        ALIGN_NATURAL_32(p,s);
     163        return (void *)p;
     164
     165    /* Unknown field */
     166    return NULL;
     167}
     168   
     169DLLEXPORT bool trace_get_wireless_tsft(void *link,
     170        libtrace_linktype_t linktype, uint64_t *tsft)
     171{
     172    uint64_t *p;
     173
     174    if (link == NULL || tsft == NULL) return false;
     175
     176    switch (linktype) {
     177        case TRACE_TYPE_80211_RADIO:
     178            if( p = (uint64_t *) trace_get_radiotap_field(link,
     179                        TRACE_RADIOTAP_TSFT)) {
     180                *tsft = bswap_le_to_host64(*p);
     181                return true;
     182            } else break;
     183           
     184        case TRACE_TYPE_80211_PRISM:
     185            return false;
     186    }
     187    /* Unsupported link type */
     188    return false;
     189}
     190
     191DLLEXPORT bool trace_get_wireless_flags(void *link,
     192        libtrace_linktype_t linktype, uint8_t *flags)
     193{
     194    uint8_t *p;
     195   
     196    if (link == NULL || flags == NULL) return false;
     197   
     198    switch(linktype) {
     199        case TRACE_TYPE_80211_RADIO:
     200            if ( p = (uint8_t *) trace_get_radiotap_field(link,
     201                TRACE_RADIOTAP_FLAGS)) {
     202                *flags = *p;
     203                return true;
     204            } else break;
     205    }
     206    /* Unsupported link type */
     207    return false;
     208}
     209
     210DLLEXPORT bool trace_get_wireless_rate(void *link,
     211        libtrace_linktype_t linktype, uint8_t *rate)
     212{
     213    uint8_t * p;
     214    if (link == NULL || rate == NULL) return false ;
     215    switch (linktype) {
     216        case TRACE_TYPE_80211_RADIO:
     217            if ( p = (uint8_t *) trace_get_radiotap_field(link,
     218                TRACE_RADIOTAP_RATE)) {
     219                *rate = *p;
     220                return true;
     221            } else break;
     222           
     223    }
     224    return false;
     225}
     226
     227DLLEXPORT bool trace_get_wireless_freq(void *link,
     228        libtrace_linktype_t linktype, uint16_t *freq)
     229{
     230    uint16_t *p;
     231
     232    if (link == NULL || freq == NULL) return false;
     233    switch (linktype) {
     234        case TRACE_TYPE_80211_RADIO:
     235            /* NB: The channel field is actually two 16 bit fields.
     236             * The chan_freq field is the first of those two, so we
     237             * just cast it to a uint16_t.
     238             */
     239            if ( p = (uint16_t *) trace_get_radiotap_field(link,
     240                    TRACE_RADIOTAP_CHANNEL)) {
     241                *freq = bswap_le_to_host16(*p);
     242                return true;
     243            } else break;
     244    }
     245    return false;
     246}
     247   
     248DLLEXPORT bool trace_get_wireless_channel_flags(void *link,
     249        libtrace_linktype_t linktype, uint16_t *flags)
     250{
     251    uint16_t *p;
     252    if (link == NULL || flags == NULL) return false;
     253    switch (linktype) {
     254        case TRACE_TYPE_80211_RADIO:
     255            /* NB: The channel field is actually two 16 bit fields.
     256             * The chan_flags field is the second of the two, so we need
     257             * to take the pointer returned by getting the channel field
     258             * and increment it.
     259             */
     260            if (p = (uint16_t *) trace_get_radiotap_field(link,
     261                    TRACE_RADIOTAP_CHANNEL)) {
     262                *flags = bswap_le_to_host16(*(p++));
     263                return true;
     264            } else break;
     265    }
     266    return false;
     267}
     268
     269DLLEXPORT bool trace_get_wireless_fhss_hopset(void *link,
     270        libtrace_linktype_t linktype, uint8_t *hopset)
     271{
     272    uint8_t *p;
     273   
     274    if (link == NULL || hopset == NULL) return false;
     275    switch(linktype) {
     276        case TRACE_TYPE_80211_RADIO:
     277            /* NB: As above with the channel field, the fhss field is
     278             * similar.
     279             */
     280            if( p = (uint8_t *) trace_get_radiotap_field(link,
     281                    TRACE_RADIOTAP_FHSS)) {
     282                *hopset = *p;
     283                return true;
     284            } else break;
     285    }
     286    return false;
     287}
     288
     289DLLEXPORT bool trace_get_wireless_fhss_hoppattern(void *link,
     290        libtrace_linktype_t linktype, uint8_t *hoppattern)
     291{
     292    uint8_t *p;
     293    if (link == NULL || hoppattern == NULL) return false;
     294    switch (linktype) {
     295        case TRACE_TYPE_80211_RADIO:
     296            if(p = (uint8_t *) trace_get_radiotap_field(link,
     297                    TRACE_RADIOTAP_FHSS)) {
     298                *hoppattern = *(p++);
     299                return true;
     300            } else break;
     301    }
     302    return false;
     303}
     304
     305DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *link,
     306        libtrace_linktype_t linktype, int8_t *strength)
     307{
     308    int8_t *p;
     309   
     310    if (link == NULL || strength == NULL) return false;
     311    switch(linktype) {
     312        case TRACE_TYPE_80211_RADIO:
     313            if (p =  (int8_t *) trace_get_radiotap_field(link,
     314                    TRACE_RADIOTAP_DBM_ANTSIGNAL)) {
     315                *strength = *p;
     316                return true;
     317            } else break;
     318    }
     319    return false;
     320}
     321
     322DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *link,
     323        libtrace_linktype_t linktype, int8_t *strength)
     324{
     325    uint8_t *p;
     326    if (link == NULL || strength == NULL) return false;
     327    switch (linktype) {
     328        case TRACE_TYPE_80211_RADIO:
     329            if ( p = (int8_t *) trace_get_radiotap_field(link,
     330                    TRACE_RADIOTAP_DBM_ANTNOISE)) {
     331                *strength = *p;
     332                return true;
     333            } else break;
     334    }
     335    return false;
     336}
     337
     338DLLEXPORT bool trace_get_wireless_signal_strength_db(void *link,
     339        libtrace_linktype_t linktype, uint8_t *strength)
     340{
     341    uint8_t *p;
     342   
     343    if (link == NULL || strength == NULL) return false;
     344    switch (linktype) {
     345        case TRACE_TYPE_80211_RADIO:
     346            if (p =  (uint8_t *) trace_get_radiotap_field(link,
     347                    TRACE_RADIOTAP_DB_ANTSIGNAL)) {
     348                *strength = *p;
     349                return true;
     350            } else break;
     351    }
     352    return false ;
     353}
     354
     355DLLEXPORT bool trace_get_wireless_noise_strength_db(void *link,
     356        libtrace_linktype_t linktype, uint8_t *strength)
     357{
     358    uint8_t *p;
     359   
     360    if (link == NULL || strength == NULL) return false;
     361    switch (linktype) {
     362        case TRACE_TYPE_80211_RADIO:
     363            if (p = (uint8_t *) trace_get_radiotap_field(link,
     364                    TRACE_RADIOTAP_DB_ANTNOISE)) {
     365                *strength = *p;
     366                return true;
     367            } else break;
     368    }
     369    return false;
     370}
     371
     372DLLEXPORT bool trace_get_wireless_lock_quality(void *link,
     373        libtrace_linktype_t linktype, uint16_t *quality)
     374{
     375    uint16_t *p;
     376   
     377    if (link == NULL || quality == NULL) return false;
     378    switch (linktype) {
     379        case TRACE_TYPE_80211_RADIO:
     380            if(p = (uint16_t *) trace_get_radiotap_field(link,
     381                    TRACE_RADIOTAP_LOCK_QUALITY)) {
     382                *quality = bswap_le_to_host16(*p);
     383                return true;
     384            } else break;
     385    }
     386    return false;
     387}
     388
     389DLLEXPORT bool trace_get_wireless_tx_attenuation(void *link,
     390        libtrace_linktype_t linktype, uint16_t *attenuation)
     391{
     392    uint16_t *p;
     393    if (link == NULL || attenuation == 0) return false;
     394    switch (linktype) {
     395        case TRACE_TYPE_80211_RADIO:
     396            if (p = (uint16_t *) trace_get_radiotap_field(link,
     397                    TRACE_RADIOTAP_TX_ATTENUATION)) {
     398                *attenuation = bswap_le_to_host16(*p);
     399                return true;
     400            } else break;
     401    }
     402    return false;
     403}
     404
     405DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *link,
     406        libtrace_linktype_t linktype, uint16_t *attenuation)
     407{
     408    uint16_t *p;
     409    if (link == NULL || attenuation == NULL) return false;
     410    switch (linktype) {
     411        case TRACE_TYPE_80211_RADIO:
     412            if (p = (uint16_t *) trace_get_radiotap_field(link,
     413                    TRACE_RADIOTAP_DB_TX_ATTENUATION)) {
     414                *attenuation = bswap_le_to_host16(*p);
     415                return true;
     416            } else break;
     417    }
     418    return false;
     419}
     420
     421DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *link,
     422        libtrace_linktype_t linktype, int8_t *txpower)
     423{
     424    int8_t *p;
     425   
     426    if (link == NULL || txpower == NULL) return false;
     427    switch (linktype) {
     428        case TRACE_TYPE_80211_RADIO:
     429            if (p=(int8_t *) trace_get_radiotap_field(link,
     430                    TRACE_RADIOTAP_DBM_TX_POWER)) {
     431                *txpower = *p;
     432                return true;
     433            } else break;
     434    }
     435    return false;
     436}
     437
     438
     439DLLEXPORT bool trace_get_wireless_antenna(void *link,
     440        libtrace_linktype_t linktype, uint8_t *antenna)
     441{
     442    uint8_t *p;
     443    if (link == NULL || antenna == NULL) return false;
     444    switch (linktype) {
     445        case TRACE_TYPE_80211_RADIO:
     446            if (p = (uint8_t *) trace_get_radiotap_field(link,
     447                    TRACE_RADIOTAP_ANTENNA)) {
     448                *antenna = *p;
     449                return true;
     450            } else break;
     451    }
     452    return false;
     453}
     454
     455DLLEXPORT bool trace_get_wireless_fcs(void *link,
     456        libtrace_linktype_t linktype, uint32_t *fcs)
     457{
     458    uint32_t *p;
     459    if (link == NULL || fcs == NULL) return false;
     460    switch (linktype) {
     461        case TRACE_TYPE_80211_RADIO:
     462            if (p = (uint32_t *) trace_get_radiotap_field(link,
     463                    TRACE_RADIOTAP_FCS)) {
     464                *fcs = bswap_le_to_host32(*p);
     465                return true;
     466            } else break;
     467    }
     468    return false;
     469}
     470
  • lib/protocols.c

     
    170170                uint16_t *type, uint32_t *remaining)
    171171{
    172172        libtrace_pflog_header_t *pflog = (libtrace_pflog_header_t*)link;
    173         if (remaining) {
     173    if (remaining) {
    174174                if (*remaining<sizeof(*pflog))
    175175                        return NULL;
    176176                *remaining-=sizeof(*pflog);
     
    187187        return (void*)((char*)pflog+ sizeof(*pflog));
    188188}
    189189
     190/* Returns the 'payload' of the prism header, which is the 802.11 frame */
     191static void *trace_get_payload_from_prism (void *link,
     192        uint16_t *type, uint32_t *remaining)
     193{
     194    if (remaining) {
     195        if (*remaining<144)
     196            return NULL;
     197        *remaining-=144;
     198    }
     199
     200    if (type) *type = 0;
     201
     202    return (void *) ((char*)link+144);
     203}
     204
     205/* Returns the 'payload' of the radiotap header, which is the 802.11 frame */
     206static void *trace_get_payload_from_radiotap (void *link,
     207        uint16_t *type, uint32_t *remaining)
     208{
     209    struct libtrace_radiotap_t *rtap = (struct libtrace_radiotap_t*)link;
     210    if (remaining) {
     211                if (*remaining<rtap->it_len)
     212                        return NULL;
     213                *remaining-=rtap->it_len;
     214        }
     215
     216        if (type) *type = 0;
     217   
     218        return (void*) ((char*)link + rtap->it_len);
     219}
     220       
    190221void *trace_get_payload_from_link(void *link, libtrace_linktype_t linktype,
    191222                uint16_t *type, uint32_t *remaining)
    192223{
     224    void *l;
     225   
    193226        switch(linktype) {
    194227                case TRACE_TYPE_80211_PRISM:
    195                         return trace_get_payload_from_80211((char*)link+144,
    196                                         type,remaining);
     228            l = trace_get_payload_from_prism(link,type,remaining);
     229            l ? trace_get_payload_from_80211(l,type,remaining) : NULL;
     230        case TRACE_TYPE_80211_RADIO:
     231            l = trace_get_payload_from_radiotap(link,type,remaining);
     232            l ? trace_get_payload_from_80211(l,type,remaining) : NULL ;
    197233                case TRACE_TYPE_80211:
    198234                        return trace_get_payload_from_80211(link,type,remaining);
    199235                case TRACE_TYPE_ETH:
  • lib/libtrace.h.in

     
    216216        TRACE_DLT_ATM_RFC1483 = 11,
    217217        TRACE_DLT_IEEE802_11 = 105,
    218218        TRACE_DLT_LINUX_SLL = 113,
    219         TRACE_DLT_PFLOG = 117
     219        TRACE_DLT_PFLOG = 117,
     220    TRACE_DLT_IEEE802_11_RADIO = 127 /**< Radiotap */
    220221} libtrace_dlt_t ;
    221222
    222223/** Enumeration of link layer types supported by libtrace */
     
    235236    /* TRACE_TYPE_LEGACY_ETH            Obsolete */
    236237       TRACE_TYPE_80211_PRISM = 12,
    237238       TRACE_TYPE_AAL5 = 13,
    238        TRACE_TYPE_DUCK = 14             /**< Pseudo link layer for DUCK packets */
     239       TRACE_TYPE_DUCK = 14,            /**< Pseudo link layer for DUCK packets */
     240       TRACE_TYPE_80211_RADIO = 15 /**< Radiotap + 802.11 */
    239241     } libtrace_linktype_t;
    240242
    241243/** Trace directions
     
    814816                uint32_t *remaining);
    815817
    816818
    817 /** Gets a pointer to the payload given a pointer to the IP header
     819/** Gets a pointer to the payload given a pointer to the Radiotap header
     820 * @param link a pointer to the Radiotap header
     821 * @param[out] type     An output variable of the ethernet type
     822 * @param[in,out] remaining Updated with the number of bytes remaining
     823 *
     824 * @return a pointer to the 802.11 header, or NULL if header isn't
     825 * present.
     826 *
     827 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
     828 * of bytes captured of the linklayer and beyond.  It will be updated after
     829 * this function to the number of bytes remaining after the Radiotap header has been
     830 * removed.
     831 *
     832 * type may be NULL if not needed.
     833 */
     834DLLEXPORT void *trace_get_payload_from_radiotap(void *link,
     835                uint16_t *type, uint32_t *remaining);
     836
     837
     838/** Gets a pointer to the payload given a pointer to the Prism monitoring header
     839 * @param link a pointer to the Prism monitoring header
     840 * @param[out] type     An output variable of the ethernet type
     841 * @param[in,out] remaining Updated with the number of bytes remaining
     842 *
     843 * @return a pointer to the 802.11 header, or NULL if header isn't
     844 * present.
     845 *
     846 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
     847 * of bytes captured of the linklayer and beyond.  It will be updated after
     848 * this function to the number of bytes remaining after the Radiotap header has been
     849 * removed.
     850 *
     851 * type may be NULL if not needed.
     852 */
     853DLLEXPORT void *trace_get_payload_from_prism(void *link,
     854                uint16_t *type, uint32_t *remaining);
     855
     856
     857/** Gets a pointer to the payload given a pointer to the link header
    818858 * @param ip            The link pointer
    819859 * @param[out] type     An output variable of the ethernet type
    820860 * @param[in,out] remaining Updated with the number of bytes remaining
     
    828868 * IP options) have been removed.
    829869 *
    830870 * type may be NULL if not needed.
     871 *
    831872 */
    832873DLLEXPORT void *trace_get_payload_from_link(void *link,
    833874                libtrace_linktype_t linktype,
     
    12981339void trace_construct_packet(libtrace_packet_t *packet,
    12991340                libtrace_linktype_t linktype, const void *data, uint16_t len);
    13001341
     1342/*@}*/
    13011343
     1344/** @name Wireless trace support
     1345 * Functions to access wireless information from packets that have wireless
     1346 * monitoring headers such as Radiotap or Prism.
     1347 *
     1348 * The trace_get_wireless_* functions provide an abstract interface for
     1349 * retrieving information from wireless traces. They take a pointer to the
     1350 * wireless monitoring header (usually found with trace_get_link(packet)) and
     1351 * the linktype of the header passed in.
     1352 *
     1353 * All of the trace_get_wireless_* functions return false if the requested
     1354 * information was unavailable, or true if it was. The actual data is stored
     1355 * in an output variable supplied by the caller. Values returned into the
     1356 * output variable will always be returned in host byte order.
     1357 * @{
     1358 */
     1359
     1360
     1361#ifndef ARPHRD_80211_RADIOTAP
     1362/* libc doesn't define this yet, but it seems to be what everyone is using
     1363 */
     1364#define ARPHRD_80211_RADIOTAP 803
     1365#endif
     1366
     1367/** Radiotap field selectors
     1368 */
     1369typedef enum {
     1370    TRACE_RADIOTAP_TSFT = 0,
     1371    TRACE_RADIOTAP_FLAGS = 1,
     1372    TRACE_RADIOTAP_RATE = 2,
     1373    TRACE_RADIOTAP_CHANNEL = 3,
     1374    TRACE_RADIOTAP_FHSS = 4,
     1375    TRACE_RADIOTAP_DBM_ANTSIGNAL = 5,
     1376    TRACE_RADIOTAP_DBM_ANTNOISE = 6,
     1377    TRACE_RADIOTAP_LOCK_QUALITY = 7,
     1378    TRACE_RADIOTAP_TX_ATTENUATION = 8,
     1379    TRACE_RADIOTAP_DB_TX_ATTENUATION = 9,
     1380    TRACE_RADIOTAP_DBM_TX_POWER = 10,
     1381    TRACE_RADIOTAP_ANTENNA = 11,
     1382    TRACE_RADIOTAP_DB_ANTSIGNAL = 12,
     1383    TRACE_RADIOTAP_DB_ANTNOISE = 13,
     1384    TRACE_RADIOTAP_FCS = 14,
     1385    TRACE_RADIOTAP_EXT = 31,
     1386} libtrace_radiotap_field_t;
     1387
     1388/** The Radiotap header pre-amble
     1389 *
     1390 * All Radiotap headers start with this pre-amble, followed by the fields
     1391 * specified in the it_present bitmask. If bit 31 of it_present is set, then
     1392 * another bitmask follows.
     1393 * NB: All of the radiotap data fields are in little-endian byte-order.
     1394 */
     1395typedef struct libtrace_radiotap_t {
     1396    uint8_t     it_version; /**< Radiotap version */
     1397    uint8_t     it_pad; /**< Padding for natural alignment */
     1398    uint16_t    it_len; /**< Length in bytes of the entire Radiotap header */
     1399    uint32_t    it_present; /**< Which Radiotap fields are present */
     1400} libtrace_radiotap_t;
     1401
     1402/** Get the wireless Timer Syncronisation Function
     1403 *
     1404 * Gets the value of the timer syncronisation function for this frame, which
     1405 * is a value in microseconds indicating the time that the first bit of the
     1406 * MPDU was received by the MAC.
     1407 *
     1408 * @param link the wireless header
     1409 * @param linktype the linktype of the wireless header passed in
     1410 * @param[out] tsft the value of the timer syncronisation function.
     1411 * @return true if the field was available, false if not.
     1412 */
     1413DLLEXPORT bool trace_get_wireless_tsft(void *link,
     1414        libtrace_linktype_t linktype, uint64_t *tsft);
     1415
     1416/** Get the wireless flags
     1417 * @param link the wireless header
     1418 * @param linktype the linktype of the wireless header passed in
     1419 * @param[out] flags the wireless flags.
     1420 * @return true if the field was available, false if not.
     1421 */
     1422DLLEXPORT bool trace_get_wireless_flags(void *link,
     1423        libtrace_linktype_t linktype, uint8_t *flags);
     1424
     1425/** Get the wireless rate
     1426 * @param link the wireless header
     1427 * @param linktype the linktype of the wireless header passed in
     1428 * @param[out] rate the data-rate of the frame in units of 500kbps
     1429 * @return true if the field was available, false if not.
     1430 */
     1431DLLEXPORT bool trace_get_wireless_rate(void *link,
     1432        libtrace_linktype_t linktype, uint8_t *rate);
     1433
     1434/** Get the wireless channel frequency
     1435 * @param link the wireless header
     1436 * @param linktype the linktype of the wireless header passed in
     1437 * @param[out] freq the frequency in MHz of the channel the frame was transmitted
     1438 * or received on.
     1439 * @return true if the field was available, false if not.
     1440 */
     1441DLLEXPORT bool trace_get_wireless_freq(void *link,
     1442        libtrace_linktype_t linktype, uint16_t *freq);
     1443
     1444/** Get the wireless channel flags
     1445 * @param link the wireless header
     1446 * @param linktype the linktype of the wireless header passed in
     1447 * @param[out] flags the channel flags
     1448 * @return true if the field was available, false if not.
     1449 */
     1450DLLEXPORT bool trace_get_wireless_channel_flags(void *link,
     1451        libtrace_linktype_t linktype, uint16_t *flags);
     1452
     1453/** Get the wireless FHSS Hop Set
     1454 * @param link the wireless header
     1455 * @param linktype the linktype of the wireless header passed in
     1456 * @param[out] hopset the fhss hop set
     1457 * @return true if the field was available, false if not.
     1458 */
     1459DLLEXPORT bool trace_get_wireless_fhss_hopset(void *link,
     1460        libtrace_linktype_t linktype, uint8_t *hopset);
     1461       
     1462/** Get the wireless FHSS Hop Pattern
     1463 * @param link the wireless header
     1464 * @param linktype the linktype of the wireless header passed in
     1465 * @param[out] hoppattern the fhss hoppattern
     1466 * @return true if the field was available, false if not.
     1467 */
     1468DLLEXPORT bool trace_get_wireless_fhss_hoppattern(void *link,
     1469        libtrace_linktype_t linktype, uint8_t *hoppattern);
     1470
     1471/** Get the wireless signal strength in dBm
     1472 * @param link the wireless header
     1473 * @param linktype the linktype of the wireless header passed in
     1474 * @param[out] strength the RF signal power at the antenna, in dB difference
     1475 * from 1mW.
     1476 * @return true if the field was available, false if not.
     1477 */
     1478DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *link,
     1479        libtrace_linktype_t linktype, int8_t *strength);
     1480
     1481/** Get the wireless noise strength in dBm
     1482 * @param link the wireless header
     1483 * @param linktype the linktype of the wireless header passed in
     1484 * @param[out] strength the RF noise power at the antenna, in dB difference
     1485 * from 1mW.
     1486 * @return true if the field was available, false if not.
     1487 */
     1488DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *link,
     1489        libtrace_linktype_t linktype, int8_t *strength);
     1490
     1491/** Get the wireless signal strength in dB
     1492 * @param link the wireless header
     1493 * @param linktype the linktype of the wireless header passed in
     1494 * @param[out] strength the RF signal power at the antenna,in dB difference
     1495 * from a fixed reference.
     1496 * @return true if the field was available, false if not.
     1497 */
     1498DLLEXPORT bool trace_get_wireless_signal_strength_db(void *link,
     1499        libtrace_linktype_t linktype, uint8_t *strength);
     1500
     1501/** Get the wireless noise strength in dB
     1502 * @param link the wireless header
     1503 * @param linktype the linktype of the wireless header passed in
     1504 * @param[out] strength the RF noise power at the antenna, in dB difference
     1505 * from a fixed reference.
     1506 * @return true if the field was available, false if not.
     1507 */
     1508DLLEXPORT bool trace_get_wireless_noise_strength_db(void *link,
     1509        libtrace_linktype_t linktype, uint8_t *strength);
     1510
     1511/** Get the wireless Barker code lock quality
     1512 * @param link the wireless header
     1513 * @param linktype the linktype of the wireless header passed in
     1514 * @param[out] quality the quality of the Barker Code lock.
     1515 * @return true if the field was available, false if not.
     1516 */
     1517DLLEXPORT bool trace_get_wireless_lock_quality(void *link,
     1518        libtrace_linktype_t linktype, uint16_t *quality);
     1519
     1520/** Get the wireless transmit attenuation
     1521 * @param link the wireless header
     1522 * @param linktype the linktype of the wireless header passed in
     1523 * @param[out] attenuation the transmit power as a unitless distance from maximum
     1524 * power set at factory calibration. 0 indicates maximum transmission power.
     1525 * @return true if the field was available, false if not.
     1526 */
     1527DLLEXPORT bool trace_get_wireless_tx_attenuation(void *link,
     1528        libtrace_linktype_t linktype, uint16_t *attenuation);
     1529
     1530/** Get the wireless transmit attenuation in dB
     1531 * @param link the wireless header
     1532 * @param linktype the linktype of the wireless header passed in
     1533 * @param[out] attenuation the transmit power as dB difference from maximum power
     1534 * set at factory calibration. 0 indicates maximum power.
     1535 * @return true if the field was available, false if not.
     1536 */
     1537DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *link,
     1538        libtrace_linktype_t linktype, uint16_t *attenuation);
     1539
     1540/** Get the wireless transmit power in dBm
     1541 * @param link the wireless header
     1542 * @param linktype the linktype of the wireless header passed in
     1543 * @param[out] txpower the transmit power as dB from a 1mW reference. This is the
     1544 * absolute power level measured at the antenna port.
     1545 * @return true if the field was available, false if not.
     1546 */
     1547DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *link,
     1548        libtrace_linktype_t linktype, int8_t *txpower);
     1549
     1550/** Get the wireless antenna
     1551 * @param link the wireless header
     1552 * @param linktype the linktype of the wireless header passed in
     1553 * @param[out] antenna which antenna was used to transmit or receive the frame.
     1554 * @return true if the field was available, false if not.
     1555 */
     1556DLLEXPORT bool trace_get_wireless_antenna(void *link,
     1557        libtrace_linktype_t linktype, uint8_t *antenna);
     1558
     1559/** Get the wireless Frame Check Sequence field
     1560 * @param link the wireless header
     1561 * @param linktype the linktype of the wireless header passed in
     1562 * @param[out] fcs the Frame Check Sequence of the frame.
     1563 * @return true if the field was available, false if not.
     1564 */
     1565DLLEXPORT bool trace_get_wireless_fcs(void *link,
     1566        libtrace_linktype_t linktype, uint32_t *fcs);
     1567
     1568/*@}*/
     1569
    13021570#ifdef __cplusplus
    13031571} /* extern "C" */
    13041572#endif /* #ifdef __cplusplus */
  • lib/format_linux.c

     
    5050#include <sys/ioctl.h>
    5151#include <errno.h>
    5252
     53
    5354struct libtrace_format_data_t {
    5455        int fd;
    5556        int snaplen;
     
    308309                        return TRACE_TYPE_ETH;
    309310                case ARPHRD_PPP:
    310311                        return TRACE_TYPE_NONE;
     312        case ARPHRD_80211_RADIOTAP:
     313            return TRACE_TYPE_80211_RADIO;
    311314                default: /* shrug, beyond me! */
    312315                        printf("unknown Linux ARPHRD type 0x%04x\n",linktype);
    313316                        return (libtrace_linktype_t)~0U;
  • lib/linktypes.c

     
    3535                case TRACE_DLT_IEEE802_11: return TRACE_TYPE_80211;
    3636                case TRACE_DLT_LINUX_SLL: return TRACE_TYPE_LINUX_SLL;
    3737                case TRACE_DLT_PFLOG: return TRACE_TYPE_PFLOG;
     38        case TRACE_DLT_IEEE802_11_RADIO: return TRACE_TYPE_80211_RADIO;
    3839        }
    3940        return ~0;
    4041}
     
    4849                case TRACE_TYPE_80211: return TRACE_DLT_IEEE802_11;
    4950                case TRACE_TYPE_LINUX_SLL: return TRACE_DLT_LINUX_SLL;
    5051                case TRACE_TYPE_PFLOG: return TRACE_DLT_PFLOG;
     52        case TRACE_TYPE_80211_RADIO: return TRACE_DLT_IEEE802_11_RADIO;
    5153        }
    5254        return ~0;
    5355}
  • lib/Makefile.am

     
    1919                format_rt.c format_helper.c format_helper.h format_pcapfile.c \
    2020                format_duck.c $(NATIVEFORMATS) \
    2121                parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h \
    22                 linktypes.c protocols.c libtraceio.h
     22                linktypes.c protocols.c libtraceio.h link_wireless.c
    2323
    2424if DAG2_4
    2525nodist_libtrace_la_SOURCES = dagopts.c dagapi.c