Changeset 799


Ignore:
Timestamp:
05/12/06 17:07:59 (7 years ago)
Author:
spa1
Message:

dag_read_packet now returns a DUCK packet occasionally in place of a regular packet - changing the DUCK frequency will *soon* be a config option
wag_start and wag_pause will now turn the radio on and off, respectively
Added DUCK structures to rt_protocol.h for use with RT_DUCK_* packets
Updated format_rt to deal with RT_DUCK properly
Removed erroneous free(packet->buffer) when packet is not under our control in format_pcap.
Added check for DAG 2.4 in configure

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.in

    r797 r799  
    338338        if grep '2.4.' $dag_root/VERSION > /dev/null 2>&1; then 
    339339                libtrace_dag2_4=true 
     340                AC_DEFINE(DAG_VERSION_2_4, 1, [define if using DAG 2.4]) 
    340341        else 
    341342                libtrace_dag2_4=false 
  • trunk/lib/format_erf.c

    r796 r799  
    7777#if HAVE_DAG 
    7878#define DAG DATA(libtrace)->dag 
     79#define DUCK DATA(libtrace)->duck 
    7980#endif 
    8081#define OPTIONS DATAOUT(libtrace)->options 
     
    100101#if HAVE_DAG 
    101102        struct { 
     103                uint32_t last_duck;      
     104                uint32_t duck_freq; 
     105                uint32_t last_pkt; 
     106                libtrace_t *dummy_rt; 
     107        } duck; 
     108         
     109        struct { 
    102110                void *buf;  
    103111                unsigned bottom; 
     
    173181                return -1; 
    174182        } 
     183 
     184        DUCK.last_duck = 0; 
     185        DUCK.duck_freq = 60;  /** 5 minutes */ 
     186        DUCK.last_pkt = 0; 
     187        DUCK.dummy_rt = NULL; 
     188         
    175189        return 0; 
    176190} 
     
    422436        /* dag pause input implicitly called to cleanup before this */ 
    423437        dag_close(INPUT.fd); 
     438        if (DUCK.dummy_rt) 
     439                trace_destroy_dead(DUCK.dummy_rt); 
    424440        free(libtrace->format_data); 
    425441        return 0; /* success */ 
     
    447463  
    448464#if HAVE_DAG 
     465#if DAG_VERSION_2_4 
     466static int dag_get_duckinfo(libtrace_t *libtrace,  
     467                                libtrace_packet_t *packet) { 
     468        dag_inf lt_dag_inf; 
     469         
     470        if (packet->buf_control == TRACE_CTRL_EXTERNAL ||  
     471                        !packet->buffer) { 
     472                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 
     473                packet->buf_control = TRACE_CTRL_PACKET; 
     474                if (!packet->buffer) { 
     475                        trace_set_err(libtrace, errno, 
     476                                        "Cannot allocate packet buffer"); 
     477                        return -1; 
     478                } 
     479        } 
     480         
     481        packet->header = 0; 
     482        packet->payload = packet->buffer; 
     483         
     484        if ((ioctl(INPUT.fd, DAG_IOINF, &lt_dag_inf) < 0)) { 
     485                trace_set_err(libtrace, errno, 
     486                                "Error using DAG_IOINF"); 
     487                return -1; 
     488        } 
     489        if (!IsDUCK(&lt_dag_inf)) { 
     490                printf("WARNING: %s does not have modern clock support - No DUCK information will be gathered\n", libtrace->uridata); 
     491                return 0; 
     492        } 
     493 
     494        if ((ioctl(INPUT.fd, DAG_IOGETDUCK, (duck_inf *)packet->payload)  
     495                                < 0)) { 
     496                trace_set_err(libtrace, errno, "Error using DAG_IOGETDUCK"); 
     497                return -1; 
     498        } 
     499 
     500        packet->type = RT_DUCK_2_4; 
     501        packet->size = sizeof(duck_inf); 
     502        if (!DUCK.dummy_rt)  
     503                DUCK.dummy_rt = trace_create_dead("rt:localhost:3434"); 
     504        packet->trace = DUCK.dummy_rt;   
     505}        
     506#else 
     507static int dag_get_duckinfo(libtrace_t *libtrace,  
     508                                libtrace_packet_t *packet) { 
     509        daginf_t lt_dag_inf; 
     510         
     511        if (packet->buf_control == TRACE_CTRL_EXTERNAL ||  
     512                        !packet->buffer) { 
     513                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 
     514                packet->buf_control = TRACE_CTRL_PACKET; 
     515                if (!packet->buffer) { 
     516                        trace_set_err(libtrace, errno, 
     517                                        "Cannot allocate packet buffer"); 
     518                        return -1; 
     519                } 
     520        } 
     521         
     522        packet->header = 0; 
     523        packet->payload = packet->buffer; 
     524         
     525        if ((ioctl(INPUT.fd, DAGIOCINFO, &lt_dag_inf) < 0)) { 
     526                trace_set_err(libtrace, errno, 
     527                                "Error using DAGIOCINFO"); 
     528                return -1; 
     529        } 
     530        if (!IsDUCK(&lt_dag_inf)) { 
     531                printf("WARNING: %s does not have modern clock support - No DUCK information will be gathered\n", libtrace->uridata); 
     532                return 0; 
     533        } 
     534 
     535        if ((ioctl(INPUT.fd, DAGIOCDUCK, (duckinf_t *)packet->payload)  
     536                                < 0)) { 
     537                trace_set_err(libtrace, errno, "Error using DAGIOCDUCK"); 
     538                return -1; 
     539        } 
     540 
     541        packet->type = RT_DUCK_2_5; 
     542        packet->size = sizeof(duckinf_t); 
     543        if (!DUCK.dummy_rt)  
     544                DUCK.dummy_rt = trace_create_dead("rt:localhost:3434"); 
     545        packet->trace = DUCK.dummy_rt;   
     546}        
     547#endif 
     548 
    449549static int dag_read(libtrace_t *libtrace, int block_flag) { 
    450550 
     
    471571        int numbytes; 
    472572        int size; 
     573        struct timeval tv; 
    473574        dag_record_t *erfptr; 
    474575 
     576        if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq &&  
     577                        DUCK.duck_freq != 0) { 
     578                size = dag_get_duckinfo(libtrace, packet); 
     579                DUCK.last_duck = DUCK.last_pkt; 
     580                if (size != 0) { 
     581                        return size; 
     582                } 
     583                /* No DUCK support, so don't waste our time anymore */ 
     584                DUCK.duck_freq = 0; 
     585        } 
     586         
    475587        if (packet->buf_control == TRACE_CTRL_PACKET) { 
    476588                packet->buf_control = TRACE_CTRL_EXTERNAL; 
     
    505617        DAG.diff -= size; 
    506618 
     619        packet->size = size; 
     620        tv = trace_get_timeval(packet); 
     621        DUCK.last_pkt = tv.tv_sec; 
     622         
    507623        return (size); 
    508624} 
  • trunk/lib/format_pcap.c

    r795 r799  
    267267        linktype = pcap_datalink(DATA(libtrace)->input.pcap); 
    268268        packet->type = pcap_dlt_to_rt(linktype); 
    269  
    270         if (packet->buf_control==TRACE_CTRL_EXTERNAL) 
    271                 free(packet->buffer); 
    272269 
    273270        packet->buf_control = TRACE_CTRL_PACKET; 
  • trunk/lib/format_rt.c

    r770 r799  
    539539static int rt_get_capture_length(const libtrace_packet_t *packet) { 
    540540        switch (packet->type) { 
    541                 case RT_DUCK: 
    542                         return 0; /* FIXME */ 
     541                case RT_DUCK_2_4: 
     542                        return sizeof(duck2_4_t);  
     543                case RT_DUCK_2_5: 
     544                        return sizeof(duck2_5_t); 
    543545                case RT_STATUS: 
    544546                        return sizeof(rt_status_t); 
  • trunk/lib/format_wag.c

    r782 r799  
    105105        if (S_ISCHR(buf.st_mode)) { 
    106106                INPUT.fd = open(libtrace->uridata, O_RDONLY); 
     107                if (ioctl (INPUT.fd, CAPTURE_RADIOON, 0) == -1) { 
     108                        trace_set_err(libtrace, errno, 
     109                                "Could not turn WAG radio on"); 
     110                        return -1; 
     111                } 
    107112                return 0; 
    108113        } 
     
    179184static int wag_pause_input(libtrace_t *libtrace) 
    180185{ 
     186        if (ioctl (INPUT.fd, CAPTURE_RADIOON, 0) == -1) { 
     187                trace_set_err(libtrace, errno, 
     188                                "Could not turn WAG radio off"); 
     189        } 
    181190        close(INPUT.fd); 
    182191        return 0; 
     
    184193 
    185194static int wag_fin_input(libtrace_t *libtrace) { 
     195        ioctl (INPUT.fd, CAPTURE_RADIOON, 0); 
    186196        free(libtrace->format_data); 
    187197        return 0; 
  • trunk/lib/rt_protocol.h

    r722 r799  
    33 
    44#include "libtrace.h" 
     5#include <time.h> 
    56 
    67#define CAPTURE_PORT 3434 
     
    1718 * 
    1819 * Add type to the enum list 
    19  * Add a struct below (even if it is empty) 
     20 * Add a struct below (even if it is empty - wrap it in an #if 0) 
    2021 * Update rt_get_capture_length 
    2122 * If type is intended to be sent TO clients, update rt_read_packet 
     
    3738 */ 
    3839 
    39 /* Type field definitions */ 
     40/** Type field definitions */ 
    4041enum rt_field_t { 
    41  RT_HELLO       =1,     /* Connection accepted */ 
    42  RT_START       =2,     /* Request for data transmission to begin */ 
    43  RT_ACK         =3,     /* Data acknowledgement */ 
    44  RT_STATUS      =4,     /* Fifo status packet */ 
    45  RT_DUCK        =5,     /* Dag duck info packet */ 
    46  RT_END_DATA    =6,     /* Server is exiting message */ 
    47  RT_CLOSE       =7,     /* Client is exiting message */ 
    48  RT_DENY_CONN   =8,     /* Connection has been denied */ 
    49  RT_PAUSE       =9,     /* Request server to suspend sending data */ 
    50  RT_PAUSE_ACK   =10,    /* Server is paused message */ 
    51  RT_OPTION      =11,    /* Option request */ 
    52  RT_KEYCHANGE   =12,    /* Anonymisation key has changed */  
     42 RT_HELLO       =1,     /**< Connection accepted */ 
     43 RT_START       =2,     /**< Request for data transmission to begin */ 
     44 RT_ACK         =3,     /**< Data acknowledgement */ 
     45 RT_STATUS      =4,     /**< Fifo status packet */ 
     46 RT_DUCK        =5,     /**< Dag duck info packet */ 
     47 RT_END_DATA    =6,     /**< Server is exiting message */ 
     48 RT_CLOSE       =7,     /**< Client is exiting message */ 
     49 RT_DENY_CONN   =8,     /**< Connection has been denied */ 
     50 RT_PAUSE       =9,     /**< Request server to suspend sending data */ 
     51 RT_PAUSE_ACK   =10,    /**< Server is paused message */ 
     52 RT_OPTION      =11,    /**< Option request */ 
     53 RT_KEYCHANGE   =12,    /**< Anonymisation key has changed */  
     54 RT_DUCK_2_4    =13,    /**< Dag 2.4 Duck */ 
     55 RT_DUCK_2_5    =14,    /**< Dag 2.5 Duck */ 
    5356  
    5457 RT_DATA_ERF            =RT_DATA_SIMPLE + TRACE_FORMAT_ERF,  
     
    7679} fifo_info_t; 
    7780 
    78 /* RT packet header */ 
     81/** RT packet header */ 
    7982typedef struct rt_header { 
    8083        enum rt_field_t type; 
     
    8487 
    8588/* TODO: Reorganise this struct once more hello info is added */ 
     89/** RT Hello packet sub-header */ 
    8690typedef struct rt_hello { 
    8791        uint8_t reliable; 
     
    9498#endif 
    9599 
     100/** RT Ack sub-header */ 
    96101typedef struct rt_ack { 
    97102        uint32_t sequence; 
    98103} rt_ack_t; 
    99104 
     105/** RT Status sub-header */ 
    100106typedef struct rt_status { 
    101107        fifo_info_t fifo_status; 
     
    120126#endif 
    121127 
    122 /* Connection denied reasons */ 
     128/** Connection denied reasons */ 
    123129enum rt_conn_denied_t { 
    124130 RT_DENY_WRAPPER        =1, 
     
    127133}; 
    128134 
     135/** RT Denied Connection sub-header */ 
    129136typedef struct rt_deny_conn { 
    130137        enum rt_conn_denied_t reason; 
     
    155162#endif 
    156163 
    157 #endif 
     164/** Specifications of duck structures - duck2_4 and duck2_5 match Endace's 
     165 * duck_inf and duckinf_t respectively */ 
     166 
     167/** DAG 2.4 DUCK */ 
     168typedef struct duck2_4 { 
     169        uint32_t        Command; 
     170        uint32_t        Config; 
     171        uint32_t        Clock_Inc; 
     172        uint32_t        Clock_Wrap; 
     173        uint32_t        DDS_Rate; 
     174        uint32_t        Crystal_Freq; 
     175        uint32_t        Synth_Freq;  
     176        uint32_t        Sync_Rate; 
     177        uint64_t        Last_Ticks; 
     178        uint32_t        Resyncs; 
     179        uint32_t        Bad_Diffs; 
     180        uint32_t        Bad_Offs; 
     181        uint32_t        Bad_Pulses; 
     182        uint32_t        Worst_Error; 
     183        uint32_t        Worst_Off; 
     184        uint32_t        Off_Limit; 
     185        uint32_t        Off_Damp; 
     186        uint32_t        Pulses; 
     187        uint32_t        Single_Pulses_Missing; 
     188        uint32_t        Longest_Pulse_Missing; 
     189        uint32_t        Health; 
     190        uint32_t        Sickness; 
     191        int32_t         Error; 
     192        int32_t         Offset; 
     193        time_t          Stat_Start; 
     194        time_t          Stat_End;    
     195        uint32_t        Set_Duck_Field; 
     196} duck2_4_t; 
     197 
     198/** DAG 2.5 DUCK */ 
     199typedef struct duck2_5 { 
     200        uint32_t        Crystal_Freq; 
     201        uint32_t        Synth_Freq; 
     202        uint64_t        Last_Ticks; 
     203        uint32_t        Resyncs; 
     204        uint32_t        Bad_Pulses; 
     205        uint32_t        Worst_Freq_Err; 
     206        uint32_t        Worst_Phase_Err; 
     207        uint32_t        Health_Thresh; 
     208        uint32_t        Pulses; 
     209        uint32_t        Single_Pulses_Missing; 
     210        uint32_t        Longest_Pulse_Missing; 
     211        uint32_t        Health; 
     212        uint32_t        Sickness; 
     213        int32_t         Freq_Err; 
     214        int32_t         Phase_Err; 
     215        uint32_t        Set_Duck_Field; 
     216        time_t          Stat_Start; 
     217        time_t          Stat_End; 
     218        uint64_t        Last_TSC; 
     219} duck2_5_t; 
     220 
     221typedef struct rt_duck_2_4 { 
     222        duck2_4_t duck; 
     223} rt_duck_2_4_t; 
     224 
     225typedef struct rt_duck_2_5 { 
     226        duck2_5_t duck; 
     227} rt_duck_2_5_t; 
     228 
     229#endif 
  • trunk/lib/wag.h

    r680 r799  
    3131#ifndef _WAG_H 
    3232#define _WAG_H 
     33 
     34/* Once a proper wag api is released, most of this file will become irrelevant 
     35 * but for now, we need to define a lot of this stuff ourselves 
     36 */ 
     37 
     38/* IOCTL's that we use */ 
     39#define CAPTURE_RADIOON         101 
     40#define CAPTURE_RADIOOFF        102 
     41#define CAPTURE_SETCHANNEL      103 
    3342 
    3443/* This is the WAG magic number - used to delimit frames */ 
Note: See TracChangeset for help on using the changeset viewer.