lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] tcp_connect does not call the callback


From: tijs . van . den . bogaard
Subject: [lwip-users] tcp_connect does not call the callback
Date: Thu, 4 Sep 2008 08:35:15 +0200 (CEST)
User-agent: SquirrelMail/1.4.8-4.0.1..el5.centos.1

Hi Everyone,

I'm trying to setup ethernet communication on a Xilinx ML506
Virtex 5 board using lwIP. The goal is to create a cardiogram
analyzer. But I fail to get a tcp connection. 'tcp_connect'
returns 'ERR_OK' but the callback is never called.
Rawapi.txt, stated that the callback is called with an error
when the connection fails but that doesn't happen either. Can
somebody shed some light on this situation?

Another strange thing is, that the logging shows 5 SYN packets
being sent to my PC but 'tcpdump' doesn't log the packets as
being received by the PC.

At the end if this message I've included the code and a piece
of logging.

I did managed to create an application which is capable of
receiving TCP data with lwIP in Raw mode using 'tcp_listen'.
It receives data from my PC running 'iperf', a tool for
measuring the speed of a connection.

Details:
- lwIP version 1.2.0
- RAW mode
- Protocol TCP
- Checksum is offloaded to hardware

Any ideas comments on the subject are highly appreciated.

Kind regards,
Tijs

- CODE BEGIN -----------------------------------------------------------

/*-----------------------------------------------------------------------------
//
//     AVNET IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
//     SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
//     XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
//     AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
//     OR STANDARD, AVNET IS MAKING NO REPRESENTATION THAT THIS
//     IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
//     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
//     FOR YOUR IMPLEMENTATION.  AVNET EXPRESSLY DISCLAIMS ANY
//     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
//     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
//     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
//     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//     FOR A PARTICULAR PURPOSE.
//
//     (c) Copyright 2006 Avnet, Inc.
//     All rights reserved.
//
//---------------------------------------------------------------------------*/

/*
 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
 * SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
 * XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
 * AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
 * OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
 * IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
 * AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
 * FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
 * WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
 * IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
 * REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
 * INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE.
 *
 * (c) Copyright 2002, 2003 Xilinx, Inc.
 * All rights reserved.
 *
 */

#include <stdio.h>
#include <string.h>

#include "xenv_standalone.h"
#include "xparameters.h"

#include "netif/xadapter.h"
#include "lwip/err.h"
#include "lwip/tcp.h"

static struct tcp_pcb *connected_pcb = NULL;

#define SEND_BUFSIZE (1260)
static char send_buf[SEND_BUFSIZE];

#ifdef XPAR_ETHERNET_MAC_BASEADDR
#define EMAC_BASEADDR  XPAR_ETHERNET_MAC_BASEADDR
#elif XPAR_LLTEMAC_0_BASEADDR
#define EMAC_BASEADDR  XPAR_LLTEMAC_0_BASEADDR
#else
#error
#endif




int     start_application();
int     transfer_data();
void    print_app_header();

static void
print_ip(char *msg, struct ip_addr *ip)
{
        print(msg);
        xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(ip), ip4_addr2(ip),
                        ip4_addr3(ip), ip4_addr4(ip));
}

void
print_ip_settings(struct ip_addr *ip, struct ip_addr *mask, struct ip_addr
*gw)
{

        print_ip("Board IP: ", ip);
        print_ip("Netmask : ", mask);
        print_ip("Gateway : ", gw);
}

int main()
{
        struct netif *netif, server_netif;
        struct ip_addr ipaddr, netmask, gw;

        xil_printf("\n\r\n\r");
    xil_printf("----------------\n\r");
        xil_printf("2008-09-04 08:32\n\r");
    xil_printf("----------------\n\r");

        /* the mac address of the board. this should be unique per board */
        unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x01, 0xca,
0x6e };

#ifdef USE_UART16550
#include "xuartns550_l.h"
#define UART_BAUDRATE 115200                      /* real hardware */
#define UART_BASEADDR XPAR_XPS_UART16550_0_BASEADDR
#define UART_CLOCK    XPAR_XUARTNS550_CLOCK_HZ
        XUartNs550_SetBaud(UART_BASEADDR, UART_CLOCK, UART_BAUDRATE);
        XUartNs550_mSetLineControlReg(UART_BASEADDR, XUN_LCR_8_DATA_BITS);
#endif

        netif = &server_netif;

#ifdef __MICROBLAZE__
        microblaze_init_icache_range(0, XPAR_U_MICROBLAZE_CACHE_BYTE_SIZE);
        microblaze_init_dcache_range(0, XPAR_U_MICROBLAZE_DCACHE_BYTE_SIZE);
#endif

        /* enable caches */
        XCACHE_ENABLE_ICACHE();
        XCACHE_ENABLE_DCACHE();

        platform_setup_interrupts();

        IP4_ADDR(&ipaddr,  192, 168,  10, 241);
        IP4_ADDR(&netmask, 255, 255, 255,   0);
        IP4_ADDR(&gw,      192, 168,  10, 254);

        print_app_header();
        print_ip_settings(&ipaddr, &netmask, &gw);

        lwip_init();

        /* Add network interface to the netif_list, and set it as default */
        if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address,
EMAC_BASEADDR)) {
                xil_printf("Error adding N/W interface\n\r");
                return -1;
        }
        netif_set_default(netif);

        /* now enable interrupts */
        platform_enable_interrupts();

        /* specify that the network if is up */
        netif_set_up(netif);

        /* start the application (web server, rxtest, txtest, etc..) */
        start_application();

        /* receive and process packets */
        while (1) {
                xemacif_input(netif);
                transfer_data();
        }

        XCACHE_DISABLE_DCACHE();
        XCACHE_DISABLE_ICACHE();

#ifdef __MICROBLAZE__
        microblaze_init_dcache_range(0, XPAR_U_MICROBLAZE_DCACHE_BYTE_SIZE);
        microblaze_init_icache_range(0, XPAR_U_MICROBLAZE_CACHE_BYTE_SIZE);
#endif

        return 0;
}

int transfer_data()
{
        int copy = 1;
        err_t err;
        struct tcp_pcb *tpcb = connected_pcb;

        if (!connected_pcb)
                return ERR_OK;

        while (tcp_sndbuf(tpcb) > SEND_BUFSIZE) {
                err = tcp_write(tpcb, send_buf, SEND_BUFSIZE, copy);
                if (err != ERR_OK) {
                        xil_printf("Error on tcp_write: %d\n\r", err);
                        while (1)
                                ;
                        return -1;
                }
        }

        return 0;
}

err_t sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len)
{
        return ERR_OK;
}

err_t connected_callback(void *arg, struct tcp_pcb *tpcb, err_t err)
{
        xil_printf("txperf: Connected to iperf server\n\r");

        /* store state */
        connected_pcb = tpcb;

        /* set callback values & functions */
        tcp_arg(tpcb, NULL);
        tcp_sent(tpcb, sent_callback);

        /* initiate data transfer */
        return ERR_OK;
}

int start_application()
{
        printf("TX_TEST 2008-09-04 08:38\n\r");
        struct tcp_pcb *pcb;
        struct ip_addr ipaddr;
        err_t err;
        u16_t port;
        int i;

        /* create new TCP PCB structure */
        pcb = tcp_new();
        if (!pcb) {
                xil_printf("Error creating PCB. Out of Memory\n\r");
                return -1;
        }

        /* connect to iperf server */
        IP4_ADDR(&ipaddr,  192, 168,   10, 129);                /* iperf server 
address */
        port = 2000;                                    /* iperf port */
        print_ip("Connecting to IP: ", &ipaddr);
        xil_printf("On port: %d\n\r", port);

        err = tcp_connect(pcb, &ipaddr, port, connected_callback);
        xil_printf("tcp_connect issued\n\r");

        if (err != ERR_OK) {
                xil_printf("tcp_connect returned error: %d\n\r", err);
                return err;
        }

        /* initialize data buffer being sent */
        for (i = 0; i < SEND_BUFSIZE; i++)
                send_buf[i] = (i % 10) + '0';

        return 0;
}

void print_app_header()
{
        xil_printf("\n\r\n\r-----lwIP Transmit Test [Board -> Host] 
------\n\r");
        xil_printf("To perform TCP TX bandwidth calculation, run iperf from your
host machine as: \n\r");
        xil_printf("iperf -s -i 2 - p 2000\n\r");
        xil_printf("Board should have IP 192.168.1.129 (can be changed in
txperf.c)\n\r");
}


- CODE END -------------------------------------------------------------

- LOGGING BEGIN --------------------------------------------------------

----------------
2008-09-04 08:32
----------------


-----lwIP Transmit Test [Board -> Host] ------
To perform TCP TX bandwidth calculation, run iperf from your host machine as:
iperf -s -i 2 - p 2000
Board should have IP 192.168.1.129 (can be changed in txperf.c)
Board IP: 192.168.10.241
Netmask : 255.255.255.0
Gateway : 192.168.10.254
netif_set_ipaddr: netif address being changed
netif: IP address of interface  set to 192.168.10.241
netif: netmask of interface  set to 255.255.255.0
netif: GW address of interface  set to 192.168.10.254
XLlTemac detect_phy: PHY detected at address 7.
tijs XLlTemac detect_phy: PHY detected. 2008-09-03 10:03
auto-negotiated link speed: 100
netif: added interface te IP addr 192.168.10.241 netmask 255.255.255.0 gw
192.168.10.254
netif: setting default interface te
TX_TEST 2008-09-04 08:38
Connecting to IP: 192.168.10.129
On port: 2000
tcp_connect to port 2000
tcp_enqueue(pcb=0x900220a8, arg=0x0, len=0, flags=2, copy=0)
tcp_enqueue: queueing 196d:196e (0x2)
tcp_output_segment: 196d:196d
ip_output_if: te0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        0      |010|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xe508     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |   10  |  241  | (src)
+-------------------------------+
|  192  |  168  |   10  |  129  | (dest)
+-------------------------------+
tcp_connect issued
netif->output()tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_output_segment: 196d:196d
ip_output_if: te0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        1      |010|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xe507     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |   10  |  241  | (src)
+-------------------------------+
|  192  |  168  |   10  |  129  | (dest)
+-------------------------------+
netif->output()tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_output_segment: 196d:196d
ip_output_if: te0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        2      |010|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xe506     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |   10  |  241  | (src)
+-------------------------------+
|  192  |  168  |   10  |  129  | (dest)
+-------------------------------+
netif->output()tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_output_segment: 196d:196d
ip_output_if: te0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        3      |010|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xe505     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |   10  |  241  | (src)
+-------------------------------+
|  192  |  168  |   10  |  129  | (dest)
+-------------------------------+
netif->output()tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_output_segment: 196d:196d
ip_output_if: te0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        4      |010|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xe504     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |   10  |  241  | (src)
+-------------------------------+
|  192  |  168  |   10  |  129  | (dest)
+-------------------------------+
netif->output()tcp_slowtmr: polling application
tcp_output: nothing to send (0x0)
tcp_slowtmr: processing active pcb
tcp_slowtmr: max SYN retries reached
tcp_pcb_purge
tcp_pcb_purge: data left on ->unacked
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
tcp_slowtmr: no active pcbs
..........


- LOGGING END ----------------------------------------------------------






reply via email to

[Prev in Thread] Current Thread [Next in Thread]