lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] transmit data using udp in raw mode


From: bobbyb
Subject: [lwip-users] transmit data using udp in raw mode
Date: Fri, 18 Sep 2009 07:36:18 -0700 (PDT)

To familiarize myself with lwip, i've been trying to use it to send one
single udp packet in raw mode from xilinx virtex5 board to the connected pc.
My code is based off the sample tftp code but i can't seem to get it to
work. The transmit light never blinks and wireshark never receives any
packets from the board. I've attached my code and the debug output. does
anything look wrong with this? please help!

My code
--------------------------------------
int main()
{
        xil_printf("\n\r-- Starting main() -- \n\r");

        struct netif *netif, server_netif;
        struct ip_addr ipaddr, netmask, gw;

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

        netif = &server_netif;

        microblaze_init_icache_range(0, XPAR_MICROBLAZE_0_CACHE_BYTE_SIZE);
        microblaze_init_dcache_range(0, XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);

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

        //platform_setup_interrupts();

        /* initliaze IP addresses to be used */
        IP4_ADDR(&ipaddr,  192, 168,   1, 10);
        IP4_ADDR(&netmask, 255, 255, 255,  0);
        IP4_ADDR(&gw,      192, 168,   1,  1);

        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 network interface\n\r");
                return -1;
        }
        netif_set_default(netif);
        netif_set_up(netif);
        //print_netif(netif);

        udp_raw_test();
 
        XCACHE_DISABLE_DCACHE();
        XCACHE_DISABLE_ICACHE();

        microblaze_init_dcache_range(0, XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);
        microblaze_init_icache_range(0, XPAR_MICROBLAZE_0_CACHE_BYTE_SIZE);

        return 0;
}

#include "lwip/udp.h"
void udp_raw_test()
{
        struct ip_addr to_ip, from_ip;
        struct udp_pcb *pcb;
        struct pbuf *pb;
        int i=0;
        err_t err;
        char msg[1200] = "hello";
        
        IP4_ADDR(&from_ip,  192, 168,   1, 10);
        IP4_ADDR(&to_ip,  192, 168,   1, 100);

        pcb = udp_new();
        if(!pcb){ xil_printf("Error creating PCB. Out of Memory\n\r"); return; }
        err = udp_bind(pcb, &from_ip, 7);
        if(err != ERR_OK){ xil_printf("Unable to bind to port\n\r"); return; }
        err = udp_connect(pcb, &to_ip, 7);
        if(err != ERR_OK){ xil_printf("Unable to connect\n\r"); return; }
        xil_printf("11111\n\r");
        pb = pbuf_alloc(PBUF_TRANSPORT, 1200, PBUF_POOL);
        if(!pb){ xil_printf("Error while allocating pbuf\n\r"); return; }
        memcpy(pb->payload, msg, 1200);
        xil_printf("22222\n\r");
        //print_udp_pcb(pcb);
        //print_pbuf(pb);       
        
                err = udp_send(pcb, pb);
                if(err == ERR_MEM){
                        xil_printf("Error sending packet. Out of memory\n\r");
                } else if(err == ERR_RTE){
                        xil_printf("Could not find route to destinations 
address\n\r");
                } else if(err != ERR_OK){
                        xil_printf("Error sending packet - %d\n\r", err);
                } else {
                        xil_printf("Packet sent\n\r");
                }
        xil_printf("33333\n\r");
        pbuf_free(pb);
        udp_remove(pcb);
}

And my debug output
--------------------------------------------------
-- Starting main() --
netif: IP address of interface  set to 192.168.1.10
netif: netmask of interface  set to 255.255.255.0
netif: GW address of interface  set to 192.168.1.1
XLlTemac detect_phy: PHY detected at address 7.
XLlTemac detect_phy: PHY detected.
auto-negotiated link speed: 1000
netif: added interface te IP addr 192.168.1.10 netmask 255.255.255.0 gw
192.168.
1.1
netif: setting default interface te
find_entry: found empty entry 0
find_entry: selecting empty entry 0
etharp_request: sending ARP request.
pbuf_alloc(length=42)
pbuf_alloc(length=42) == 0x90020570
etharp_raw: sending raw ARP packet.
pbuf_free(0x90020570)
pbuf_free: 0x90020570 has ref 1, ending here.
udp_bind(ipaddr = 192.168.1.10, port = 7)
udp_bind: bound to 192.168.1.10, port 7
udp_connect: connected to 192.168.1.100,port 7
11111
pbuf_alloc(length=1200)
pbuf_alloc: allocated pbuf 0x90087bb8
pbuf_alloc(length=1200) == 0x90087bb8
22222
udp_send
pbuf_header: old 0x90087c00 new 0x90087bf8 (8)
udp_send: added header in given pbuf 0x90087bb8
udp_send: sending datagram of length 1208
udp_send: UDP packet length 1208
inet_chksum_pseudo(): checksumming pbuf 0x90087bb8 (has next 0x0)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=d120
udp_send: UDP checksum 0x2edf
udp_send: ip_output_if (,,,,IP_PROTO_UDP,)
pbuf_header: old 0x90087bf8 new 0x90087be4 (20)
ip_output_if: te0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |      1228     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0x3362     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |    1  |   10  | (src)
+-------------------------------+
|  192  |  168  |    1  |  100  | (dest)
+-------------------------------+
netif->output()pbuf_header: old 0x90087be4 new 0x90087bd6 (14)
find_entry: found empty entry 1
find_entry: selecting empty entry 1
etharp_request: sending ARP request.
pbuf_alloc(length=42)
pbuf_alloc(length=42) == 0x900205d0
etharp_raw: sending raw ARP packet.
pbuf_free(0x900205d0)
pbuf_free: 0x900205d0 has ref 1, ending here.
pbuf_alloc(length=1242)
pbuf_alloc(length=1242) == 0x90020630
pbuf_copy(0x90020630, 0x90087bb8)
pbuf_copy: end of chain reached.
etharp_query: queued packet 0x90087bb8 on ARP entry 1
Packet sent
33333
pbuf_free(0x90087bb8)
pbuf_free: deallocating 0x90087bb8

I
-- 
View this message in context: 
http://www.nabble.com/transmit-data-using-udp-in-raw-mode-tp25492137p25492137.html
Sent from the lwip-users mailing list archive at Nabble.com.





reply via email to

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