Ticket #65: libtrace3_wireless_support.patch

File libtrace3_wireless_support.patch, 30.6 KB (added by smr26@…, 16 years ago)

Replaces the previous patch, adds generic wireless support

  • 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/* Used for Radiotap fields which must be naturally aligned */
     35#define ALIGN_NATURAL_64(_p,_s) \
     36    while ( (_p - _s) & (sizeof(uint64_t) * 8 - 1) != 0) _p++
     37#define ALIGN_NATURAL_32(_p,_s) \
     38    while ( (_p - _s) & (sizeof(uint32_t) * 8 - 1) != 0) _p++
     39#define ALIGN_NATURAL_16(_p,_s) \
     40    while ( (_p - _s) & (sizeof(uint16_t) * 8 - 1) != 0) _p++
     41
     42/** Gets a field from a Radiotap header.
     43 * @param link the radiotap header
     44 * @param field the radiotap field we want to access
     45 * @return a void pointer to the field. It is up to the caller to cast to the
     46 * appropriate type.
     47 * @note Radiotap fields are always little-endian
     48 */
     49static void *trace_get_radiotap_field(void *link, libtrace_radiotap_field_t field)
     50{
     51    struct libtrace_radiotap_t *rtap = (struct libtrace_radiotap_t *)link;
     52    uint8_t *p;
     53    uint8_t *s;
     54   
     55    /* Check if the field exists in the radiotap header before proceeding
     56     */
     57    if (rtap->it_present & (1 << field) == 0) return NULL;
     58
     59    /* Skip over any extended bitmasks */
     60    p = (uint8_t *) &(rtap->it_present);
     61   
     62    while ( *((uint32_t*)p) & (1 << IEEE80211_RADIOTAP_EXT) ) {
     63        p += sizeof (uint32_t);
     64    }
     65
     66    /* Point p at the first field of radiotap data and remember it for later
     67     * when we're doing field alignment
     68     */
     69    p += sizeof(uint32_t);
     70    s = p;
     71   
     72    if (field == IEEE80211_RADIOTAP_TSFT)
     73        /* Always aligned */
     74        return (void*)p;
     75    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_TSFT))
     76        p += sizeof (uint64_t);
     77
     78    if (field == IEEE80211_RADIOTAP_FLAGS)
     79        /* Always aligned */
     80        return (void*)p;
     81    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_FLAGS))
     82        p += sizeof (uint8_t);
     83
     84    if (field == IEEE80211_RADIOTAP_RATE)
     85        /* Always aligned */
     86        return (void*)p;
     87    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_RATE))
     88        p+= sizeof (uint8_t);
     89
     90    if (field == IEEE80211_RADIOTAP_CHANNEL)
     91    {
     92        ALIGN_NATURAL_32(p,s);
     93        return (void *)p;
     94    }
     95    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_CHANNEL))
     96        p+= sizeof (uint32_t);
     97
     98    if (field == IEEE80211_RADIOTAP_FHSS)
     99    {
     100        ALIGN_NATURAL_16(p,s);
     101        return (void *)p;
     102    }
     103    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_FHSS))
     104        p+= sizeof (uint16_t);
     105
     106    if (field == IEEE80211_RADIOTAP_DBM_ANTSIGNAL)
     107        return (void *)p;
     108    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL))
     109        p+= sizeof (uint8_t);
     110
     111    if (field == IEEE80211_RADIOTAP_DBM_ANTNOISE)
     112        return (void *)p;
     113    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
     114        p+= sizeof (uint8_t);
     115
     116    if (field == IEEE80211_RADIOTAP_LOCK_QUALITY)
     117    {
     118        ALIGN_NATURAL_16(p,s);
     119        return (void *)p;
     120    }
     121    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_LOCK_QUALITY))
     122        p+= sizeof (uint16_t);
     123
     124    if (field == IEEE80211_RADIOTAP_TX_ATTENUATION)
     125    {
     126        ALIGN_NATURAL_16(p,s);
     127        return (void *)p;
     128    }
     129    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_TX_ATTENUATION))
     130        p+= sizeof (uint16_t);
     131
     132    if (field == IEEE80211_RADIOTAP_DB_TX_ATTENUATION)
     133    {
     134        ALIGN_NATURAL_16(p,s);
     135        return (void *)p;
     136    }
     137    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_DB_TX_ATTENUATION))
     138        p+= sizeof (uint16_t);
     139
     140    if (field == IEEE80211_RADIOTAP_DBM_TX_POWER)
     141        return (void *)p;
     142    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_DBM_TX_POWER))
     143        p+= sizeof (uint8_t);
     144   
     145    if (field == IEEE80211_RADIOTAP_ANTENNA)
     146        return (void *)p;
     147    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_ANTENNA))
     148        p+= sizeof (uint8_t);
     149
     150    if (field == IEEE80211_RADIOTAP_DB_ANTSIGNAL)
     151        return (void *)p;
     152    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
     153        p+= sizeof (uint8_t);
     154
     155    if (field == IEEE80211_RADIOTAP_DB_ANTNOISE)
     156        return (void *) p;
     157    if (rtap->it_present & (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
     158        p+= sizeof (uint8_t);
     159   
     160    if (field == IEEE80211_RADIOTAP_FCS)
     161        ALIGN_NATURAL_32(p,s);
     162        return (void *)p;
     163
     164    /* Unknown field */
     165    return NULL;
     166}
     167   
     168DLLEXPORT int trace_get_wireless_tsft(void *link,
     169        libtrace_linktype_t linktype, uint64_t *tsft)
     170{
     171    uint64_t *p;
     172
     173    if (link == NULL || tsft == NULL) return 0;
     174
     175    switch (linktype) {
     176        case TRACE_TYPE_80211_RADIO:
     177            if( p = (uint64_t *) trace_get_radiotap_field(link,
     178                        IEEE80211_RADIOTAP_TSFT)) {
     179                *tsft = bswap_le_to_host64(*p);
     180                return 1;
     181            } else break;
     182           
     183        case TRACE_TYPE_80211_PRISM:
     184            return 0;
     185    }
     186    /* Unsupported link type */
     187    return 0;
     188}
     189
     190DLLEXPORT int trace_get_wireless_flags(void *link,
     191        libtrace_linktype_t linktype, uint8_t *flags)
     192{
     193    uint8_t *p;
     194   
     195    if (link == NULL || flags == NULL) return 0;
     196   
     197    switch(linktype) {
     198        case TRACE_TYPE_80211_RADIO:
     199            if ( p = (uint8_t *) trace_get_radiotap_field(link,
     200                IEEE80211_RADIOTAP_FLAGS)) {
     201                *flags = *p;
     202                return 1;
     203            } else break;
     204    }
     205    /* Unsupported link type */
     206    return 0;
     207}
     208
     209DLLEXPORT int trace_get_wireless_rate(void *link,
     210        libtrace_linktype_t linktype, uint8_t *rate)
     211{
     212    uint8_t * p;
     213    if (link == NULL || rate == NULL) return 0 ;
     214    switch (linktype) {
     215        case TRACE_TYPE_80211_RADIO:
     216            if ( p = (uint8_t *) trace_get_radiotap_field(link,
     217                IEEE80211_RADIOTAP_RATE)) {
     218                *rate = *p;
     219                return 1;
     220            } else break;
     221           
     222    }
     223    return 0;
     224}
     225
     226DLLEXPORT int trace_get_wireless_freq(void *link,
     227        libtrace_linktype_t linktype, uint16_t *freq)
     228{
     229    uint16_t *p;
     230
     231    if (link == NULL || freq == NULL) return 0;
     232    switch (linktype) {
     233        case TRACE_TYPE_80211_RADIO:
     234            /* NB: The channel field is actually two 16 bit fields.
     235             * The chan_freq field is the first of those two, so we
     236             * just cast it to a uint16_t.
     237             */
     238            if ( p = (uint16_t *) trace_get_radiotap_field(link,
     239                    IEEE80211_RADIOTAP_CHANNEL)) {
     240                *freq = bswap_le_to_host16(*p);
     241                return 1;
     242            } else break;
     243    }
     244    return 0;
     245}
     246   
     247DLLEXPORT int trace_get_wireless_channel_flags(void *link,
     248        libtrace_linktype_t linktype, uint16_t *flags)
     249{
     250    uint16_t *p;
     251    if (link == NULL || flags == NULL) return 0;
     252    switch (linktype) {
     253        case TRACE_TYPE_80211_RADIO:
     254            /* NB: The channel field is actually two 16 bit fields.
     255             * The chan_flags field is the second of the two, so we need
     256             * to take the pointer returned by getting the channel field
     257             * and increment it.
     258             */
     259            if (p = (uint16_t *) trace_get_radiotap_field(link,
     260                    IEEE80211_RADIOTAP_CHANNEL)) {
     261                *flags = bswap_le_to_host16(*(p++));
     262                return 1;
     263            } else break;
     264    }
     265    return 0;
     266}
     267
     268DLLEXPORT int trace_get_wireless_fhss_hopset(void *link,
     269        libtrace_linktype_t linktype, uint8_t *hopset)
     270{
     271    uint8_t *p;
     272   
     273    if (link == NULL || hopset == NULL) return 0;
     274    switch(linktype) {
     275        case TRACE_TYPE_80211_RADIO:
     276            /* NB: As above with the channel field, the fhss field is
     277             * similar.
     278             */
     279            if( p = (uint8_t *) trace_get_radiotap_field(link,
     280                    IEEE80211_RADIOTAP_FHSS)) {
     281                *hopset = *p;
     282                return 1;
     283            } else break;
     284    }
     285    return 0;
     286}
     287
     288DLLEXPORT int trace_get_wireless_fhss_hoppattern(void *link,
     289        libtrace_linktype_t linktype, uint8_t *hoppattern)
     290{
     291    uint8_t *p;
     292    if (link == NULL || hoppattern == NULL) return 0;
     293    switch (linktype) {
     294        case TRACE_TYPE_80211_RADIO:
     295            if(p = (uint8_t *) trace_get_radiotap_field(link,
     296                    IEEE80211_RADIOTAP_FHSS)) {
     297                *hoppattern = *(p++);
     298                return 1;
     299            } else break;
     300    }
     301    return 0;
     302}
     303
     304DLLEXPORT int trace_get_wireless_signal_strength_dbm(void *link,
     305        libtrace_linktype_t linktype, int8_t *strength)
     306{
     307    int8_t *p;
     308   
     309    if (link == NULL || strength == NULL) return 0;
     310    switch(linktype) {
     311        case TRACE_TYPE_80211_RADIO:
     312            if (p =  (int8_t *) trace_get_radiotap_field(link,
     313                    IEEE80211_RADIOTAP_DBM_ANTSIGNAL)) {
     314                *strength = *p;
     315                return 1;
     316            } else break;
     317    }
     318    return 0;
     319}
     320
     321DLLEXPORT int trace_get_wireless_noise_strength_dbm(void *link,
     322        libtrace_linktype_t linktype, int8_t *strength)
     323{
     324    uint8_t *p;
     325    if (link == NULL || strength == NULL) return 0;
     326    switch (linktype) {
     327        case TRACE_TYPE_80211_RADIO:
     328            if ( p = (int8_t *) trace_get_radiotap_field(link,
     329                    IEEE80211_RADIOTAP_DBM_ANTNOISE)) {
     330                *strength = *p;
     331                return 1;
     332            } else break;
     333    }
     334    return 0;
     335}
     336
     337DLLEXPORT int trace_get_wireless_signal_strength_db(void *link,
     338        libtrace_linktype_t linktype, uint8_t *strength)
     339{
     340    uint8_t *p;
     341   
     342    if (link == NULL || strength == NULL) return 0;
     343    switch (linktype) {
     344        case TRACE_TYPE_80211_RADIO:
     345            if (p =  (uint8_t *) trace_get_radiotap_field(link,
     346                    IEEE80211_RADIOTAP_DB_ANTSIGNAL)) {
     347                *strength = *p;
     348                return 1;
     349            } else break;
     350    }
     351    return 0 ;
     352}
     353
     354DLLEXPORT int trace_get_wireless_noise_strength_db(void *link,
     355        libtrace_linktype_t linktype, uint8_t *strength)
     356{
     357    uint8_t *p;
     358   
     359    if (link == NULL || strength == NULL) return 0;
     360    switch (linktype) {
     361        case TRACE_TYPE_80211_RADIO:
     362            if (p = (uint8_t *) trace_get_radiotap_field(link,
     363                    IEEE80211_RADIOTAP_DB_ANTNOISE)) {
     364                *strength = *p;
     365                return 1;
     366            } else break;
     367    }
     368    return 0;
     369}
     370
     371DLLEXPORT int trace_get_wireless_lock_quality(void *link,
     372        libtrace_linktype_t linktype, uint16_t *quality)
     373{
     374    uint16_t *p;
     375   
     376    if (link == NULL || quality == NULL) return 0;
     377    switch (linktype) {
     378        case TRACE_TYPE_80211_RADIO:
     379            if(p = (uint16_t *) trace_get_radiotap_field(link,
     380                    IEEE80211_RADIOTAP_LOCK_QUALITY)) {
     381                *quality = bswap_le_to_host16(*p);
     382                return 1;
     383            } else break;
     384    }
     385    return 0;
     386}
     387
     388DLLEXPORT int trace_get_wireless_tx_attenuation(void *link,
     389        libtrace_linktype_t linktype, uint16_t *attenuation)
     390{
     391    uint16_t *p;
     392    if (link == NULL || attenuation == 0) return 0;
     393    switch (linktype) {
     394        case TRACE_TYPE_80211_RADIO:
     395            if (p = (uint16_t *) trace_get_radiotap_field(link,
     396                    IEEE80211_RADIOTAP_TX_ATTENUATION)) {
     397                *attenuation = bswap_le_to_host16(*p);
     398                return 1;
     399            } else break;
     400    }
     401    return 0;
     402}
     403
     404DLLEXPORT int trace_get_wireless_tx_attenuation_db(void *link,
     405        libtrace_linktype_t linktype, uint16_t *attenuation)
     406{
     407    uint16_t *p;
     408    if (link == NULL || attenuation == NULL) return 0;
     409    switch (linktype) {
     410        case TRACE_TYPE_80211_RADIO:
     411            if (p = (uint16_t *) trace_get_radiotap_field(link,
     412                    IEEE80211_RADIOTAP_DB_TX_ATTENUATION)) {
     413                *attenuation = bswap_le_to_host16(*p);
     414                return 1;
     415            } else break;
     416    }
     417    return 0;
     418}
     419
     420DLLEXPORT int trace_get_wireless_tx_power_dbm(void *link,
     421        libtrace_linktype_t linktype, int8_t *txpower)
     422{
     423    int8_t *p;
     424   
     425    if (link == NULL || txpower == NULL) return 0;
     426    switch (linktype) {
     427        case TRACE_TYPE_80211_RADIO:
     428            if (p=(int8_t *) trace_get_radiotap_field(link,
     429                    IEEE80211_RADIOTAP_DBM_TX_POWER)) {
     430                *txpower = *p;
     431                return 1;
     432            } else break;
     433    }
     434    return 0;
     435}
     436
     437
     438DLLEXPORT int trace_get_wireless_antenna(void *link,
     439        libtrace_linktype_t linktype, uint8_t *antenna)
     440{
     441    uint8_t *p;
     442    if (link == NULL || antenna == NULL) return 0;
     443    switch (linktype) {
     444        case TRACE_TYPE_80211_RADIO:
     445            if (p = (uint8_t *) trace_get_radiotap_field(link,
     446                    IEEE80211_RADIOTAP_ANTENNA)) {
     447                *antenna = *p;
     448                return 1;
     449            } else break;
     450    }
     451    return 0;
     452}
     453
     454DLLEXPORT int trace_get_wireless_fcs(void *link,
     455        libtrace_linktype_t linktype, uint32_t *fcs)
     456{
     457    uint32_t *p;
     458    if (link == NULL || fcs == NULL) return 0;
     459    switch (linktype) {
     460        case TRACE_TYPE_80211_RADIO:
     461            if (p = (uint32_t *) trace_get_radiotap_field(link,
     462                    IEEE80211_RADIOTAP_FCS)) {
     463                *fcs = bswap_le_to_host32(*p);
     464                return 1;
     465            } else break;
     466    }
     467    return 0;
     468}
     469
  • 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 0 if the requested
     1354 * information was unavailable, or 1 if it was. The actual data is stored in
     1355 * an output variable supplied by the caller. Values returned into the output
     1356 * 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    IEEE80211_RADIOTAP_TSFT = 0,
     1371    IEEE80211_RADIOTAP_FLAGS = 1,
     1372    IEEE80211_RADIOTAP_RATE = 2,
     1373    IEEE80211_RADIOTAP_CHANNEL = 3,
     1374    IEEE80211_RADIOTAP_FHSS = 4,
     1375    IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
     1376    IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
     1377    IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
     1378    IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
     1379    IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
     1380    IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
     1381    IEEE80211_RADIOTAP_ANTENNA = 11,
     1382    IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
     1383    IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
     1384    IEEE80211_RADIOTAP_FCS = 14,
     1385    IEEE80211_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 0 if the field is not available, 1 otherwise.
     1412 */
     1413DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1421 */
     1422DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1430 */
     1431DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1440 */
     1441DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1449 */
     1450DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1458 */
     1459DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1467 */
     1468DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1477 */
     1478DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1487 */
     1488DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1497 */
     1498DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1507 */
     1508DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1516 */
     1517DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1526 */
     1527DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1536 */
     1537DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1546 */
     1547DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1555 */
     1556DLLEXPORT int 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 0 if the field was not available, 1 otherwise.
     1564 */
     1565DLLEXPORT int 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