Changeset c4cf162


Ignore:
Timestamp:
09/12/06 13:46:45 (14 years ago)
Author:
Scott Raynel <smr26@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
935c3d0
Parents:
07a1cec
Message:

Adds initial wireless support to libtrace. Applications can now use the trace_get_wireless_* functions to get wireless information such as signal strength, noise levels, frame check sequences, etc.

Location:
lib
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • lib/Makefile.am

    r8bf0517 rc4cf162  
    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
  • lib/format_linux.c

    r9cad9c9 rc4cf162  
    5050#include <sys/ioctl.h>
    5151#include <errno.h>
     52
    5253
    5354struct libtrace_format_data_t {
     
    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);
  • lib/libtrace.h.in

    r835a1ec rc4cf162  
    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
     
    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
     
    249251        TRACE_DIR_OTHER    = 2          /**< Packets with an unknown direction, or one that's unknown */
    250252} libtrace_direction_t;
     253
     254/** Enumeration of Radiotap fields */
     255typedef enum {
     256    TRACE_RADIOTAP_TSFT = 0, /**< Timer synchronisation function, in microseconds (uint64) */
     257    TRACE_RADIOTAP_FLAGS = 1, /**< Wireless flags (uint8) */
     258    TRACE_RADIOTAP_RATE = 2, /**< Bitrate in units of 500kbps (uint8) */
     259    TRACE_RADIOTAP_CHANNEL = 3, /**< Frequency in MHz (uint16) and channel flags (uint16) */
     260    TRACE_RADIOTAP_FHSS = 4, /**< FHSS hop set (uint8) and hopping pattern (uint8) */
     261    TRACE_RADIOTAP_DBM_ANTSIGNAL = 5, /**< Signal power in dBm (int8) */
     262    TRACE_RADIOTAP_DBM_ANTNOISE = 6, /**< Noise power in dBm (int8) */
     263    TRACE_RADIOTAP_LOCK_QUALITY = 7, /**< Barker Code lock quality (uint16) */
     264    TRACE_RADIOTAP_TX_ATTENUATION = 8, /**< TX attenuation as unitless distance from max power (uint16) */
     265    TRACE_RADIOTAP_DB_TX_ATTENUATION = 9, /**< TX attenutation as dB from max power (uint16) */
     266    TRACE_RADIOTAP_DBM_TX_POWER = 10, /**< TX Power in dBm (int8) */
     267    TRACE_RADIOTAP_ANTENNA = 11, /**< Antenna frame was rx'd or tx'd on (uint8) */
     268    TRACE_RADIOTAP_DB_ANTSIGNAL = 12, /**< Signal power in dB from a fixed reference (uint8) */
     269    TRACE_RADIOTAP_DB_ANTNOISE = 13, /**< Noise power in dB from a fixed reference (uint8) */
     270    TRACE_RADIOTAP_FCS = 14, /**< Received frame check sequence (uint32) */
     271    TRACE_RADIOTAP_EXT = 31,
     272} libtrace_radiotap_field_t;
     273
    251274
    252275/** @name Protocol structures
     
    467490} PACKED libtrace_80211_t;
    468491
     492/** The Radiotap header pre-amble
     493 *
     494 * All Radiotap headers start with this pre-amble, followed by the fields
     495 * specified in the it_present bitmask. If bit 31 of it_present is set, then
     496 * another bitmask follows.
     497 * NB: All of the radiotap data fields are in little-endian byte-order.
     498 */
     499typedef struct libtrace_radiotap_t {
     500    uint8_t     it_version; /**< Radiotap version */
     501    uint8_t     it_pad; /**< Padding for natural alignment */
     502    uint16_t    it_len; /**< Length in bytes of the entire Radiotap header */
     503    uint32_t    it_present; /**< Which Radiotap fields are present */
     504} libtrace_radiotap_t;
     505
     506
    469507#ifdef WIN32
    470508#pragma pack(pop)
     
    815853
    816854
    817 /** Gets a pointer to the payload given a pointer to the IP header
     855/** Gets a pointer to the payload given a pointer to the Radiotap header
     856 * @param link a pointer to the Radiotap header
     857 * @param[out] type     An output variable of the ethernet type
     858 * @param[in,out] remaining Updated with the number of bytes remaining
     859 *
     860 * @return a pointer to the 802.11 header, or NULL if header isn't
     861 * present.
     862 *
     863 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
     864 * of bytes captured of the linklayer and beyond.  It will be updated after
     865 * this function to the number of bytes remaining after the Radiotap header has been
     866 * removed.
     867 *
     868 * type may be NULL if not needed.
     869 */
     870DLLEXPORT void *trace_get_payload_from_radiotap(void *link,
     871                uint16_t *type, uint32_t *remaining);
     872
     873
     874/** Gets a pointer to the payload given a pointer to the Prism monitoring header
     875 * @param link a pointer to the Prism monitoring header
     876 * @param[out] type     An output variable of the ethernet type
     877 * @param[in,out] remaining Updated with the number of bytes remaining
     878 *
     879 * @return a pointer to the 802.11 header, or NULL if header isn't
     880 * present.
     881 *
     882 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
     883 * of bytes captured of the linklayer and beyond.  It will be updated after
     884 * this function to the number of bytes remaining after the Radiotap header has been
     885 * removed.
     886 *
     887 * type may be NULL if not needed.
     888 */
     889DLLEXPORT void *trace_get_payload_from_prism(void *link,
     890                uint16_t *type, uint32_t *remaining);
     891
     892
     893/** Gets a pointer to the payload given a pointer to the link header
    818894 * @param ip            The link pointer
    819895 * @param[out] type     An output variable of the ethernet type
     
    829905 *
    830906 * type may be NULL if not needed.
     907 *
    831908 */
    832909DLLEXPORT void *trace_get_payload_from_link(void *link,
     
    12991376                libtrace_linktype_t linktype, const void *data, uint16_t len);
    13001377
     1378/*@}*/
     1379
     1380/** @name Wireless trace support
     1381 * Functions to access wireless information from packets that have wireless
     1382 * monitoring headers such as Radiotap or Prism.
     1383 *
     1384 * The trace_get_wireless_* functions provide an abstract interface for
     1385 * retrieving information from wireless traces. They take a pointer to the
     1386 * wireless monitoring header (usually found with trace_get_link(packet)) and
     1387 * the linktype of the header passed in.
     1388 *
     1389 * All of the trace_get_wireless_* functions return false if the requested
     1390 * information was unavailable, or true if it was. The actual data is stored
     1391 * in an output variable supplied by the caller. Values returned into the
     1392 * output variable will always be returned in host byte order.
     1393 * @{
     1394 */
     1395
     1396
     1397#ifndef ARPHRD_80211_RADIOTAP
     1398/* libc doesn't define this yet, but it seems to be what everyone is using
     1399 */
     1400#define ARPHRD_80211_RADIOTAP 803
     1401#endif
     1402
     1403/** Get the wireless Timer Syncronisation Function
     1404 *
     1405 * Gets the value of the timer syncronisation function for this frame, which
     1406 * is a value in microseconds indicating the time that the first bit of the
     1407 * MPDU was received by the MAC.
     1408 *
     1409 * @param link the wireless header
     1410 * @param linktype the linktype of the wireless header passed in
     1411 * @param[out] tsft the value of the timer syncronisation function.
     1412 * @return true if the field was available, false if not.
     1413 */
     1414DLLEXPORT bool trace_get_wireless_tsft(void *link,
     1415        libtrace_linktype_t linktype, uint64_t *tsft);
     1416
     1417/** Get the wireless flags
     1418 * @param link the wireless header
     1419 * @param linktype the linktype of the wireless header passed in
     1420 * @param[out] flags the wireless flags.
     1421 * @return true if the field was available, false if not.
     1422 */
     1423DLLEXPORT bool trace_get_wireless_flags(void *link,
     1424        libtrace_linktype_t linktype, uint8_t *flags);
     1425
     1426/** Get the wireless rate
     1427 * @param link the wireless header
     1428 * @param linktype the linktype of the wireless header passed in
     1429 * @param[out] rate the data-rate of the frame in units of 500kbps
     1430 * @return true if the field was available, false if not.
     1431 */
     1432DLLEXPORT bool trace_get_wireless_rate(void *link,
     1433        libtrace_linktype_t linktype, uint8_t *rate);
     1434
     1435/** Get the wireless channel frequency
     1436 * @param link the wireless header
     1437 * @param linktype the linktype of the wireless header passed in
     1438 * @param[out] freq the frequency in MHz of the channel the frame was transmitted
     1439 * or received on.
     1440 * @return true if the field was available, false if not.
     1441 */
     1442DLLEXPORT bool trace_get_wireless_freq(void *link,
     1443        libtrace_linktype_t linktype, uint16_t *freq);
     1444
     1445/** Get the wireless channel flags
     1446 * @param link the wireless header
     1447 * @param linktype the linktype of the wireless header passed in
     1448 * @param[out] flags the channel flags
     1449 * @return true if the field was available, false if not.
     1450 */
     1451DLLEXPORT bool trace_get_wireless_channel_flags(void *link,
     1452        libtrace_linktype_t linktype, uint16_t *flags);
     1453
     1454/** Get the wireless FHSS Hop Set
     1455 * @param link the wireless header
     1456 * @param linktype the linktype of the wireless header passed in
     1457 * @param[out] hopset the fhss hop set
     1458 * @return true if the field was available, false if not.
     1459 */
     1460DLLEXPORT bool trace_get_wireless_fhss_hopset(void *link,
     1461        libtrace_linktype_t linktype, uint8_t *hopset);
     1462       
     1463/** Get the wireless FHSS Hop Pattern
     1464 * @param link the wireless header
     1465 * @param linktype the linktype of the wireless header passed in
     1466 * @param[out] hoppattern the fhss hoppattern
     1467 * @return true if the field was available, false if not.
     1468 */
     1469DLLEXPORT bool trace_get_wireless_fhss_hoppattern(void *link,
     1470        libtrace_linktype_t linktype, uint8_t *hoppattern);
     1471
     1472/** Get the wireless signal strength in dBm
     1473 * @param link the wireless header
     1474 * @param linktype the linktype of the wireless header passed in
     1475 * @param[out] strength the RF signal power at the antenna, in dB difference
     1476 * from 1mW.
     1477 * @return true if the field was available, false if not.
     1478 */
     1479DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *link,
     1480        libtrace_linktype_t linktype, int8_t *strength);
     1481
     1482/** Get the wireless noise strength in dBm
     1483 * @param link the wireless header
     1484 * @param linktype the linktype of the wireless header passed in
     1485 * @param[out] strength the RF noise power at the antenna, in dB difference
     1486 * from 1mW.
     1487 * @return true if the field was available, false if not.
     1488 */
     1489DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *link,
     1490        libtrace_linktype_t linktype, int8_t *strength);
     1491
     1492/** Get the wireless signal strength in dB
     1493 * @param link the wireless header
     1494 * @param linktype the linktype of the wireless header passed in
     1495 * @param[out] strength the RF signal power at the antenna,in dB difference
     1496 * from a fixed reference.
     1497 * @return true if the field was available, false if not.
     1498 */
     1499DLLEXPORT bool trace_get_wireless_signal_strength_db(void *link,
     1500        libtrace_linktype_t linktype, uint8_t *strength);
     1501
     1502/** Get the wireless noise strength in dB
     1503 * @param link the wireless header
     1504 * @param linktype the linktype of the wireless header passed in
     1505 * @param[out] strength the RF noise power at the antenna, in dB difference
     1506 * from a fixed reference.
     1507 * @return true if the field was available, false if not.
     1508 */
     1509DLLEXPORT bool trace_get_wireless_noise_strength_db(void *link,
     1510        libtrace_linktype_t linktype, uint8_t *strength);
     1511
     1512/** Get the wireless Barker code lock quality
     1513 * @param link the wireless header
     1514 * @param linktype the linktype of the wireless header passed in
     1515 * @param[out] quality the quality of the Barker Code lock.
     1516 * @return true if the field was available, false if not.
     1517 */
     1518DLLEXPORT bool trace_get_wireless_lock_quality(void *link,
     1519        libtrace_linktype_t linktype, uint16_t *quality);
     1520
     1521/** Get the wireless transmit attenuation
     1522 * @param link the wireless header
     1523 * @param linktype the linktype of the wireless header passed in
     1524 * @param[out] attenuation the transmit power as a unitless distance from maximum
     1525 * power set at factory calibration. 0 indicates maximum transmission power.
     1526 * @return true if the field was available, false if not.
     1527 */
     1528DLLEXPORT bool trace_get_wireless_tx_attenuation(void *link,
     1529        libtrace_linktype_t linktype, uint16_t *attenuation);
     1530
     1531/** Get the wireless transmit attenuation in dB
     1532 * @param link the wireless header
     1533 * @param linktype the linktype of the wireless header passed in
     1534 * @param[out] attenuation the transmit power as dB difference from maximum power
     1535 * set at factory calibration. 0 indicates maximum power.
     1536 * @return true if the field was available, false if not.
     1537 */
     1538DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *link,
     1539        libtrace_linktype_t linktype, uint16_t *attenuation);
     1540
     1541/** Get the wireless transmit power in dBm
     1542 * @param link the wireless header
     1543 * @param linktype the linktype of the wireless header passed in
     1544 * @param[out] txpower the transmit power as dB from a 1mW reference. This is the
     1545 * absolute power level measured at the antenna port.
     1546 * @return true if the field was available, false if not.
     1547 */
     1548DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *link,
     1549        libtrace_linktype_t linktype, int8_t *txpower);
     1550
     1551/** Get the wireless antenna
     1552 * @param link the wireless header
     1553 * @param linktype the linktype of the wireless header passed in
     1554 * @param[out] antenna which antenna was used to transmit or receive the frame.
     1555 * @return true if the field was available, false if not.
     1556 */
     1557DLLEXPORT bool trace_get_wireless_antenna(void *link,
     1558        libtrace_linktype_t linktype, uint8_t *antenna);
     1559
     1560/** Get the wireless Frame Check Sequence field
     1561 * @param link the wireless header
     1562 * @param linktype the linktype of the wireless header passed in
     1563 * @param[out] fcs the Frame Check Sequence of the frame.
     1564 * @return true if the field was available, false if not.
     1565 */
     1566DLLEXPORT bool trace_get_wireless_fcs(void *link,
     1567        libtrace_linktype_t linktype, uint32_t *fcs);
     1568
     1569/*@}*/
    13011570
    13021571#ifdef __cplusplus
  • lib/linktypes.c

    r85a79b0 rc4cf162  
    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;
     
    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;
  • lib/protocols.c

    re0f9c80 rc4cf162  
    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;
     
    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);
Note: See TracChangeset for help on using the changeset viewer.