示例#1
0
int
main( int argc, char *argv[] )
{

    deliver_sm_t a;
    deliver_sm_t b;
    tlv_t tlv;

    memset(&a, 0, sizeof(deliver_sm_t));
    memset(&b, 0, sizeof(deliver_sm_t));
    memset(&tlv, 0, sizeof(tlv_t));

    /* Init PDU ***********************************************************/
    b.command_length   = 0;
    b.command_id       = DELIVER_SM;
    b.command_status   = ESME_ROK;
    b.sequence_number  = 1;
    snprintf((char*)b.service_type, SERVICE_TYPE_LENGTH, "%s", "CMT");
    b.source_addr_ton  = 2;
    b.source_addr_npi  = 1;
    snprintf((char*)b.source_addr, ADDRESS_LENGTH, "%s", "0900001111");
    b.dest_addr_ton    = 2;
    b.dest_addr_npi    = 1;
    snprintf((char*)b.destination_addr, ADDRESS_LENGTH, "%s", "0900001111");
    b.esm_class        = 0;
    b.protocol_id      = 0;
    b.priority_flag    = 0;
    memset(b.schedule_delivery_time, 0, sizeof(b.schedule_delivery_time));
    memset(b.validity_period, 0, sizeof(b.validity_period));
    b.registered_delivery = 0;
    b.replace_if_present_flag =0;
    b.data_coding         = 0;
    b.sm_default_msg_id   = 0;
    b.sm_length           = strlen(TEXTO);
    memcpy(b.short_message, TEXTO, b.sm_length);

    tlv.tag = TLVID_user_message_reference;
    tlv.length = sizeof(uint16_t);
    tlv.value.val16 = 0x0024;
    build_tlv( &(b.tlv), &tlv );

    tlv.tag = TLVID_message_payload;
    tlv.length = strlen(TEXTO);
    memcpy(tlv.value.octet, TEXTO, tlv.length);
    build_tlv( &(b.tlv), &tlv );

    tlv.tag = 0x1501;

    tlv.length = strlen(TEXTO);
    memcpy(tlv.value.octet, TEXTO, tlv.length);
    build_tlv( &(b.tlv), &tlv );

    doTest(DELIVER_SM, &a, &b);
    destroy_tlv( b.tlv );
    destroy_tlv( a.tlv );
    return( 0 );
};
int
main( int argc, char *argv[] )
{
    bind_transceiver_resp_t a;
    bind_transceiver_resp_t b;
    tlv_t tlv;

    memset(&a, 0, sizeof(bind_transceiver_resp_t));
    memset(&b, 0, sizeof(bind_transceiver_resp_t));
    memset(&tlv, 0, sizeof(tlv));

    /* Init PDU ***********************************************************/
    b.command_length   = 0;
    b.command_id       = BIND_TRANSCEIVER_RESP;
    b.command_status   = ESME_ROK;
    b.sequence_number  = 1;
    snprintf((char*)b.system_id, sizeof(b.system_id), "%s", "system_id");

    tlv.tag = TLVID_sc_interface_version;
    tlv.length = sizeof(uint8_t);
    tlv.value.val16 = 0x34;
    build_tlv( &(b.tlv), &tlv );

    doTest(BIND_TRANSCEIVER_RESP, &a, &b);
    destroy_tlv( b.tlv );
    destroy_tlv( a.tlv );
    return( 0 );
};
示例#3
0
void speed_test_prep(struct etherate *eth)
{

    build_tlv(&eth->frm, htons(TYPE_TESTFRAME), htonl(VALUE_TEST_SUB_TLV));

    // By default test until F_DURATION_DEF has passed
    eth->speed_test.testMax = (uint64_t*)&eth->params.f_duration;
    eth->speed_test.testBase = (uint64_t*)&eth->params.s_elapsed;

    if (eth->params.f_bytes > 0) ///// Move all this recuring code to a parent function
    {    
        // Testing until N bytes sent
        eth->speed_test.testMax  = &eth->params.f_bytes;
        eth->speed_test.testBase = &eth->speed_test.b_tx;

    } else if (eth->params.f_count > 0) {   
        // Testing until N frames sent
        eth->speed_test.testMax  = &eth->params.f_count;
        eth->speed_test.testBase = &eth->params.f_tx_count;

    } else if (eth->params.f_duration > 0) {
        // Testing until N seconds have passed
        eth->params.f_duration -= 1;
    }

    if (eth->app.tx_mode == true)
    {

        printf("Seconds\t\tMbps Tx\t\tMBs Tx\t\tFrmTx/s\t\tFrames Tx\n");

        if (eth->speed_test.b_tx_speed_max != B_TX_SPEED_MAX_DEF) {
            speed_test_bps(eth);
        } else if (eth->params.f_tx_count_max != F_TX_COUNT_MAX_DEF) {
            speed_test_fps(eth);
        } else if (eth->params.f_tx_dly != F_TX_DLY_DEF) {
            speed_test_pacing(eth);
        } else {
            speed_test_full(eth);
        }


    // Else, Rx mode
    } else {

        printf("Seconds\t\tMbps Rx\t\tMBs Rx\t\tFrmRx/s\t\tFrames Rx\n");

        speed_test_rx(eth);

    }

    if (eth->params.s_elapsed > 0)
    {
        eth->speed_test.b_speed_avg = (eth->speed_test.b_speed_avg / eth->params.s_elapsed);
        eth->speed_test.f_speed_avg = (eth->speed_test.f_speed_avg / eth->params.s_elapsed);
    }

    printf("Speed test complete\n");
    speed_test_results(eth);

}
示例#4
0
int do_smpp_send_message(SMS *p, int sock_tcp){
    char message[256];
    tlv_t tlv;
    submit_sm_t      req;
    submit_sm_resp_t res;
    memset(&req, 0, sizeof(submit_sm_t));
    memset(&res, 0, sizeof(submit_sm_resp_t));

    /* Init PDU ***********************************************************/
    req.command_length   = 0;
    req.command_id       = SUBMIT_SM;
    req.command_status   = ESME_ROK;
    req.sequence_number  = 2;
    
    req.source_addr_ton  = TON_International;
    req.source_addr_npi  = NPI_ISDN_E163_E164;
    sprintf((char*)req.source_addr,"%s",(char*)p->src);
///printf("................%s",req.source_addr); 
    req.dest_addr_ton    = TON_International;
    req.dest_addr_npi    = NPI_ISDN_E163_E164;
    sprintf((char*)req.destination_addr,"%s",(char*)p->dst);
/*#if 0 // if you need this
    b.esm_class        = 0;
    b.protocol_id      = 0;
    b.priority_flag    = 0;
    snprintf( b.schedule_delivery_time, TIME_LENGTH, "%s", "");
    snprintf( b.validity_period, TIME_LENGTH, "%s", "");
    b.registered_delivery = 0;
    b.replace_if_present_flag =0;
    b.data_coding         = 0;
    b.sm_default_msg_id   = 0;
#endif*/

    sprintf((char*)message,"%s",(char*)p->msg);
/*#if 0 // Message in short_message scope
    b.sm_length           = strlen(TEXTO);
    memcpy(b.short_message, TEXTO, b.sm_length);
//#else // Message in Payload*/
    tlv.tag = TLVID_message_payload;
    tlv.length = strlen(message);
    memcpy(tlv.value.octet, message, tlv.length);
    build_tlv( &(req.tlv), &tlv );
//#endif

    /* Add other optional param */
    tlv.tag = TLVID_user_message_reference;
    tlv.length = sizeof(uint16_t);
    tlv.value.val16 = 0x0024;
    build_tlv( &(req.tlv), &tlv );

    /* FIRST STEP: PACK AND SEND */
#include "pack_and_send.inc"
    destroy_tlv( req.tlv ); /* Por las dudas */
    /* Set a timer (PENDIENTE) ********************************************/
    /* SECOND STEP: READ AND UNPACK Response */
#include "recv_and_unpack.inc"

    if( res.command_id != SUBMIT_SM_RESP ||
        res.command_status != ESME_ROK ){
        printf("Error in send(SUBMIT_SM)[%08X:%08X]\n", 
                                       res.command_id, res.command_status);
        return( -1 );
    };
    return( 0 );
}
示例#5
0
int main(int argc, char *argv[]) {


    struct FRAME_HEADERS FRAME_HEADERS;
    struct TEST_INTERFACE TEST_INTERFACE;
    struct TEST_PARAMS TEST_PARAMS;
    struct MTU_TEST MTU_TEST;
    struct QM_TEST QM_TEST;
    struct APP_PARAMS APP_PARAMS;

    char TESTING = true;

    while(TESTING)
    {

        /*
         ******************************************************* DEFAULT VALUES
         */

        pFRAME_HEADERS                  = &FRAME_HEADERS;
        FRAME_HEADERS.SOURCE_MAC[0]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[1]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[2]     = 0x5E;
        FRAME_HEADERS.SOURCE_MAC[3]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[4]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[5]     = 0x01;
        FRAME_HEADERS.DEST_MAC[0]       = 0x00;
        FRAME_HEADERS.DEST_MAC[1]       = 0x00;
        FRAME_HEADERS.DEST_MAC[2]       = 0x5E;
        FRAME_HEADERS.DEST_MAC[3]       = 0x00;
        FRAME_HEADERS.DEST_MAC[4]       = 0x00;
        FRAME_HEADERS.DEST_MAC[5]       = 0x02;
        FRAME_HEADERS.LENGTH            = HEADERS_LEN_DEF;
        FRAME_HEADERS.ETHERTYPE         = ETHERTYPE_DEF;
        FRAME_HEADERS.PCP               = PCP_DEF;
        FRAME_HEADERS.VLAN_ID           = VLAN_ID_DEF;
        FRAME_HEADERS.QINQ_ID           = QINQ_ID_DEF;
        FRAME_HEADERS.QINQ_PCP          = QINQ_PCP_DEF;
        FRAME_HEADERS.LSP_SOURCE_MAC[0] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[1] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[2] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[3] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[4] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[5] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[6] = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[0]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[1]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[2]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[3]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[4]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[5]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[6]   = 0x00;
        FRAME_HEADERS.MPLS_LABELS       = 0;
        for (int i = 0; i<MPLS_LABELS_MAX; i++) {
            FRAME_HEADERS.MPLS_LABEL[i] = 0;
            FRAME_HEADERS.MPLS_EXP[i]   = 0;
            FRAME_HEADERS.MPLS_TTL[i]   = 0;
        }
        FRAME_HEADERS.PWE_CONTROL_WORD  = 0;
        FRAME_HEADERS.MPLS_IGNORE       = 0;
        FRAME_HEADERS.TLV_SIZE          = sizeof(char) + sizeof(short) +
                                          sizeof(unsigned long);
        FRAME_HEADERS.SUB_TLV_SIZE      = FRAME_HEADERS.TLV_SIZE + 
                                          sizeof(char) + sizeof(short) + 
                                          sizeof(unsigned long long);

        pTEST_INTERFACE         = &TEST_INTERFACE;
        TEST_INTERFACE.IF_INDEX = IF_INDEX_DEF;
        for (int i = 0; i<IFNAMSIZ; i++) {
            TEST_INTERFACE.IF_NAME[i] = 0;
        }

        TEST_PARAMS.F_SIZE          = F_SIZE_DEF;
        TEST_PARAMS.F_SIZE_TOTAL    = F_SIZE_DEF + FRAME_HEADERS.LENGTH;
        TEST_PARAMS.F_DURATION      = F_DURATION_DEF;
        TEST_PARAMS.F_COUNT         = F_COUNT_DEF; 
        TEST_PARAMS.F_BYTES         = F_BYTES_DEF;
        TEST_PARAMS.S_ELAPSED       = 0;
        TEST_PARAMS.B_TX_SPEED_MAX  = B_TX_SPEED_MAX_DEF;
        TEST_PARAMS.B_TX_SPEED_PREV = 0;
        TEST_PARAMS.F_TX_COUNT      = 0;
        TEST_PARAMS.F_TX_COUNT_PREV = 0;
        TEST_PARAMS.F_TX_SPEED_MAX  = F_TX_SPEED_MAX_DEF;
        TEST_PARAMS.B_TX            = 0;
        TEST_PARAMS.B_TX_PREV       = 0;
        TEST_PARAMS.F_RX_COUNT      = 0;
        TEST_PARAMS.F_RX_COUNT_PREV = 0;
        TEST_PARAMS.B_RX            = 0;
        TEST_PARAMS.B_RX_PREV       = 0;
        TEST_PARAMS.F_INDEX_PREV    = 0;
        TEST_PARAMS.F_RX_ONTIME     = 0;
        TEST_PARAMS.F_RX_EARLY      = 0;
        TEST_PARAMS.F_RX_LATE       = 0;
        TEST_PARAMS.F_RX_OTHER      = 0;
        TEST_PARAMS.B_SPEED         = 0;
        TEST_PARAMS.B_SPEED_MAX     = 0;
        TEST_PARAMS.B_SPEED_AVG     = 0;
        TEST_PARAMS.F_ACK           = false;
        TEST_PARAMS.F_WAITING_ACK   = false;

        MTU_TEST.ENABLED    = false;
        MTU_TEST.MTU_TX_MIN = 1400;
        MTU_TEST.MTU_TX_MAX = 1500;

        pQM_TEST                 = &QM_TEST;
        QM_TEST.ENABLED          = false;
        QM_TEST.INTERVAL         = 1000;
        QM_TEST.INTERVAL_SEC     = 0;
        QM_TEST.INTERVAL_NSEC    = 0;
        QM_TEST.INTERVAL_MIN     = 99999.99999;
        QM_TEST.INTERVAL_MAX     = 0.0;
        QM_TEST.TIMEOUT          = 1000;
        QM_TEST.TIMEOUT_NSEC     = 0;
        QM_TEST.TIMEOUT_SEC      = 0;
        QM_TEST.TIMEOUT_COUNT    = 0;
        QM_TEST.DELAY_TEST_COUNT = 10000;
        QM_TEST.RTT_MIN          = 999999.999999;
        QM_TEST.RTT_MAX          = 0.0;
        QM_TEST.JITTER_MIN       = 999999.999999;
        QM_TEST.JITTER_MAX       = 0.0;
        QM_TEST.pDELAY_RESULTS   = (double*)calloc(QM_TEST.DELAY_TEST_COUNT,
                                                   sizeof(double));

        APP_PARAMS.TX_MODE     = true;
        APP_PARAMS.TX_SYNC     = true;
        APP_PARAMS.TX_DELAY    = TX_DELAY_DEF;
        


        /*
         ************************************************************* CLI ARGS
         */

        int CLI_RET_VAL = cli_args(argc, argv, &APP_PARAMS, &FRAME_HEADERS,
                                   &TEST_INTERFACE, &TEST_PARAMS, &MTU_TEST,
                                   &QM_TEST);

        if (CLI_RET_VAL == -2) {
            return EXIT_SUCCESS;
        } else if (CLI_RET_VAL == -1) {
            return EX_USAGE;
        }


        // Check for root privs because low level socket access is required
        if (getuid() != 0) {
            printf("Must be root to use this program!\n");
            return EX_NOPERM;
        }


        if (APP_PARAMS.TX_MODE) printf("Running in TX mode\n");
        else printf("Running in RX mode\n");


        /*
         ****************************************************** INTERFACE SETUP
         */

        TEST_INTERFACE.SOCKET_FD = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

///// Monitor sock1 for input
TEST_INTERFACE.fds[0].fd = TEST_INTERFACE.SOCKET_FD;
TEST_INTERFACE.fds[0].events = POLLIN;
TEST_INTERFACE.fds[0].revents = 0;

        if (TEST_INTERFACE.SOCKET_FD < 0 )
        {
          printf("Error defining socket!\n");
          perror("socket() ");
          close(TEST_INTERFACE.SOCKET_FD);
          return EX_SOFTWARE;
        }


        // If the user has supplied an interface index try to use that
        if (TEST_INTERFACE.IF_INDEX != IF_INDEX_DEF) {

            TEST_INTERFACE.IF_INDEX = set_sock_interface_index(&TEST_INTERFACE);
            if (TEST_INTERFACE.IF_INDEX == 0)
            {
                printf("Error: Couldn't set interface with index, "
                       "returned index was 0!\n");
                return EX_SOFTWARE;
            }

        // Or if the user has supplied an interface name try to use that        
        } else if (strcmp(TEST_INTERFACE.IF_NAME, "") != 0) {

            TEST_INTERFACE.IF_INDEX = set_sock_interface_name(&TEST_INTERFACE);
            if (TEST_INTERFACE.IF_INDEX == 0)
            {
                printf("Error: Couldn't set interface index from name, "
                       "returned index was 0!\n");
                return EX_SOFTWARE;
            }

        // Otherwise, try and best guess an interface
        } else if (TEST_INTERFACE.IF_INDEX == IF_INDEX_DEF) {

            TEST_INTERFACE.IF_INDEX = get_sock_interface(&TEST_INTERFACE);
            if (TEST_INTERFACE.IF_INDEX == 0)
            {
                printf("Error: Couldn't find appropriate interface ID, "
                      "returned ID was 0!\n Try supplying a source MAC address "
                      "with the -s option.\n");
                return EX_SOFTWARE;
            }

        }


        // Link layer socket setup
        TEST_INTERFACE.SOCKET_ADDRESS.sll_family   = PF_PACKET;	
        TEST_INTERFACE.SOCKET_ADDRESS.sll_protocol = htons(ETH_P_IP);
        TEST_INTERFACE.SOCKET_ADDRESS.sll_ifindex  = TEST_INTERFACE.IF_INDEX;    
        TEST_INTERFACE.SOCKET_ADDRESS.sll_hatype   = ARPHRD_ETHER;
        TEST_INTERFACE.SOCKET_ADDRESS.sll_pkttype  = PACKET_OTHERHOST;
        TEST_INTERFACE.SOCKET_ADDRESS.sll_halen    = ETH_ALEN;		
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[0]  = FRAME_HEADERS.DEST_MAC[0];		
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[1]  = FRAME_HEADERS.DEST_MAC[1];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[2]  = FRAME_HEADERS.DEST_MAC[2];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[3]  = FRAME_HEADERS.DEST_MAC[3];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[4]  = FRAME_HEADERS.DEST_MAC[4];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[5]  = FRAME_HEADERS.DEST_MAC[5];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[6]  = 0x00;
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[7]  = 0x00;

        // Send and receive buffers for incoming/outgoing ethernet frames
        FRAME_HEADERS.RX_BUFFER = (char*)calloc(1, F_SIZE_MAX);
        FRAME_HEADERS.TX_BUFFER = (char*)calloc(1, F_SIZE_MAX);

        build_headers(&FRAME_HEADERS);

        // Total size of the frame data (paylod size+headers), this excludes the
        // preamble & start frame delimiter, FCS and inter frame gap
        TEST_PARAMS.F_SIZE_TOTAL = TEST_PARAMS.F_SIZE + FRAME_HEADERS.LENGTH;


        int PHY_MTU = get_interface_mtu_by_name(&TEST_INTERFACE);
        
        if (PHY_MTU==-1) {

            printf("\nPhysical interface MTU unknown, "
                   "test might exceed physical MTU!\n\n");

        } else if (TEST_PARAMS.F_SIZE_TOTAL > PHY_MTU + 14) {
            
            printf("\nPhysical interface MTU (%u with headers) is less than\n"
                   "the test frame size (%u with headers). Test frames shall\n"
                   "bo limited to the interface MTU size\n\n",
                   PHY_MTU+14, TEST_PARAMS.F_SIZE_TOTAL);
            
            TEST_PARAMS.F_SIZE_TOTAL = PHY_MTU + 14;

        }

        // Fill the test frame with some random data
        for (unsigned int i = 0; i < (F_SIZE_MAX-FRAME_HEADERS.LENGTH); i++)
        {
            FRAME_HEADERS.TX_DATA[i] = (char)((255.0*rand()/(RAND_MAX+1.0)));
        }

        
        // Send and receive ret vals
        int TX_RET_VAL = 0;


        // Set the network interface to promiscuos mode
        printf("Entering promiscuous mode\n");
        strncpy(ethreq.ifr_name,TEST_INTERFACE.IF_NAME,IFNAMSIZ);

        if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCGIFFLAGS,&ethreq) == -1) 
        {

            printf("Error getting socket flags, entering promiscuous mode failed!\n");
            perror("ioctl() ");
            close(TEST_INTERFACE.SOCKET_FD);
            return EX_SOFTWARE;

        }

        ethreq.ifr_flags|=IFF_PROMISC;

        if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCSIFFLAGS,&ethreq) == -1)
        {

            printf("Error setting socket flags, entering promiscuous mode failed!\n");
            perror("ioctl() ");
            close(TEST_INTERFACE.SOCKET_FD);
            return EX_SOFTWARE;

        }


        // Declare sigint handler, TX will signal RX to reset when it quits
        signal (SIGINT,signal_handler);


        printf("Source MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
               FRAME_HEADERS.SOURCE_MAC[0],FRAME_HEADERS.SOURCE_MAC[1],
               FRAME_HEADERS.SOURCE_MAC[2],FRAME_HEADERS.SOURCE_MAC[3],
               FRAME_HEADERS.SOURCE_MAC[4],FRAME_HEADERS.SOURCE_MAC[5]);

        printf("Destination MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
               FRAME_HEADERS.DEST_MAC[0],FRAME_HEADERS.DEST_MAC[1],
               FRAME_HEADERS.DEST_MAC[2],FRAME_HEADERS.DEST_MAC[3],
               FRAME_HEADERS.DEST_MAC[4],FRAME_HEADERS.DEST_MAC[5]);


        // Broadcacst to populate any TCAM or MAC tables
        unsigned char TEMP_MAC[6] = {
            FRAME_HEADERS.DEST_MAC[0],
            FRAME_HEADERS.DEST_MAC[1],
            FRAME_HEADERS.DEST_MAC[2],
            FRAME_HEADERS.DEST_MAC[3],
            FRAME_HEADERS.DEST_MAC[4],
            FRAME_HEADERS.DEST_MAC[5],
        };

        FRAME_HEADERS.DEST_MAC[0] = 0xFF;
        FRAME_HEADERS.DEST_MAC[1] = 0xFF;
        FRAME_HEADERS.DEST_MAC[2] = 0xFF;
        FRAME_HEADERS.DEST_MAC[3] = 0xFF;
        FRAME_HEADERS.DEST_MAC[4] = 0xFF;
        FRAME_HEADERS.DEST_MAC[5] = 0xFF;

        // Rebuild frame headers with destination MAC
        build_headers(&FRAME_HEADERS);

        build_tlv(&FRAME_HEADERS, htons(TYPE_BROADCAST), htonl(VALUE_PRESENCE));
        // Build a dummy sub-TLV to align the buffers and pointers
        build_sub_tlv(&FRAME_HEADERS, htons(TYPE_APPLICATION_SUB_TLV),
                      htonll(VALUE_DUMMY));

        printf("Sending gratuitous broadcasts...\n");
        for (int i=1; i<=3; i++)
        {

            TX_RET_VAL = sendto(TEST_INTERFACE.SOCKET_FD, FRAME_HEADERS.TX_BUFFER,
                                FRAME_HEADERS.LENGTH+FRAME_HEADERS.TLV_SIZE, 0, 
                                (struct sockaddr*)&TEST_INTERFACE.SOCKET_ADDRESS,
                                sizeof(TEST_INTERFACE.SOCKET_ADDRESS));

            sleep(1);

        }


        FRAME_HEADERS.DEST_MAC[0] = TEMP_MAC[0];
        FRAME_HEADERS.DEST_MAC[1] = TEMP_MAC[1];
        FRAME_HEADERS.DEST_MAC[2] = TEMP_MAC[2];
        FRAME_HEADERS.DEST_MAC[3] = TEMP_MAC[3];
        FRAME_HEADERS.DEST_MAC[4] = TEMP_MAC[4];
        FRAME_HEADERS.DEST_MAC[5] = TEMP_MAC[5];

        build_headers(&FRAME_HEADERS);
        /////build_tlv(&FRAME_HEADERS, htons(TYPE_BROADCAST), htonl(VALUE_PRESENCE));
        /////build_sub_tlv(&FRAME_HEADERS, htons(TYPE_APPLICATION_SUB_TLV),
        /////htonll(VALUE_DUMMY));

        // Total size of the frame data (paylod size+headers), this excludes the
        // preamble & start frame delimiter, FCS and inter frame gap
/////        TEST_PARAMS.F_SIZE_TOTAL = TEST_PARAMS.F_SIZE + FRAME_HEADERS.LENGTH;



        /*
         ******************************************************** SETTINGS SYNC
         */

        sync_settings(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE, &TEST_PARAMS,
                      &MTU_TEST, &QM_TEST);

        // Pause to allow the RX host to process the sent settings
        sleep(1);

        // Rebuild the test frame headers in case any settings have been changed
        // by the TX host
        if (!APP_PARAMS.TX_MODE) build_headers(&FRAME_HEADERS);


        // Try to measure the TX to RX one way delay
        if (APP_PARAMS.TX_DELAY)
            delay_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE, &TEST_PARAMS,
                       &QM_TEST);


        /*
         ****************************************************** MAIN TEST PHASE
         */    

        if (MTU_TEST.ENABLED) {

            mtu_sweep_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE,
                           &TEST_PARAMS, &MTU_TEST);

        } else if (QM_TEST.ENABLED) {

            latency_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE,
                         &TEST_PARAMS, &QM_TEST);

        } else {

            speed_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE,
                       &TEST_PARAMS);

        }
        

        // End the testing loop if TX host
        if (APP_PARAMS.TX_MODE) TESTING=false;

    }


    printf("Leaving promiscuous mode\n");

    strncpy(ethreq.ifr_name,TEST_INTERFACE.IF_NAME,IFNAMSIZ);

    if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCGIFFLAGS,&ethreq) == -1)
    {
        printf("Error getting socket flags, leaving promiscuous mode failed!\n");
        perror("ioctl() ");
        close(TEST_INTERFACE.SOCKET_FD);
        return EX_SOFTWARE;
    }

    ethreq.ifr_flags &= ~IFF_PROMISC;

    if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCSIFFLAGS,&ethreq) == -1)
    {
        printf("Error setting socket flags, leaving promiscuous mode failed\n");
        perror("ioctl() ");
        close(TEST_INTERFACE.SOCKET_FD);
        return EX_SOFTWARE;
    }

    close(TEST_INTERFACE.SOCKET_FD);

    free (QM_TEST.pDELAY_RESULTS);
    free (FRAME_HEADERS.RX_BUFFER);
    free (FRAME_HEADERS.TX_BUFFER);

    return EXIT_SUCCESS;

}