UPD Packets via uIP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UPD Packets via uIP

2,870 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DiamondS on Fri Nov 25 01:38:02 MST 2011
Hi,

I have a problem, cant send UDP packets via uIP TCP/IP Stack.
Maybe someone can share a small example of how to do it?
Because on Wireshark i cant see any of packets, when i send UDP.
I use uIP RBD1768 DHCP example. Everything is working.
0 Kudos
77 Replies

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cks on Thu Nov 05 23:52:26 MST 2015
In this MYMAC 1 to 6 not defined... I am getting it as an error... Is there any suggestion???
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mmarchli on Thu Jan 23 03:56:42 MST 2014
Hi Ex-Zero !,

could you please reupload the project or file "LPC17_UDPIPsample22032012.zip". I can not find it at all on the forum.

BR,
Michal


0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nagaraj.baddi on Wed Oct 30 02:27:59 MST 2013
Hi Dave,


Could please upload UDP working example?
I am working TFTP server on LPC1788 controller. The using TFTP I am trying to transfer/receive file file on Ethernet.


Thanks & Regards
Nagaraj Baddi

0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nagaraj.baddi on Sun Oct 20 23:33:46 MST 2013
hi,

I am working on ftp client with lpc1768 controller using UDP packet via uIP TCP/IP stack. I am new to UDP could you please share UDP example, which may help me to work on ftp client.


Regards
Nagaraj
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by zemansky on Thu May 16 19:25:58 MST 2013

Quote: Zero
This is a working sample. It's transmitting a message to SOURCE_IP / SOURCE_PORT (string and number) and displaying it via semihosting.

It's expecting a message from TARGET_IP / TARGET_PORT (string and number) with same format like transmitted.

I've tested this with Windows (Win7/32) without problems (Debug and Release mode)

ARP and ICMP are working, so pinging this SOURCE_IP (or Scanner like http://www.softperfect.com/products/networkscanner/) are working.

To use it in your network you just have to use a valid SOURCE_IP and TARGET_IP.

To enable printf just  #define USE_PRINTF

[B]Note: I've changed a few things in included udpip library from Aart (see notes in udpip.c).[/B]

/*
===============================================================================
 Name        : main.c
 Author      : Zero
 Version     : 1.0 / 22.03.2012
 Copyright   : $(copyright)
 Description : UDPIP sample using udpip library
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

//#define USE_PRINTF //comment out to avoid printf

#ifdef USE_PRINTF
 #include <stdio.h>                        //used for printf
#else
 #define printf(...)
#endif

#include <string.h>                        //used for mem functions
#include "udpip.h"                        //include UDP/IP

//MAC
uint8_t MY_MAC[6]={0x1E,0x30,0x6C,0xA2,0x45,0x5E};
//IPs
static uint8_t SOURCE_IP[4]={192,168,178,120};
static uint8_t TARGET_IP[4]={192,168,178, 26};
//Ports
static uint16_t SOURCE_PORT=50100;
static uint16_t TARGET_PORT=50101;

//predefine message
//transmit data
uint8_t trans_message[16] = {'S','p','e','e','d','1',':',0,0,0,0,0,0,0,0,0};
uint16_t trans_number;                    //transmit number
uint16_t trans_counter;                    //transmit counter

uint8_t  rec_message[20];                //receive buffer
uint16_t rec_number;                    //receive number
uint16_t rec_counter;                    //receive counter

//conversions
uint32_t conversion_long;

void read_UDP1(unsigned char* msg, short len, unsigned char broadcast)
{
 memcpy(rec_message,msg,7);        //copy 7 char string
 rec_message[7]='\0';            //end
 memcpy(&rec_number,msg + 10,2);//copy number (2 bytes at 10)
 rec_counter++;
 printf("RxD %04d: %s %d\n",rec_counter,rec_message,rec_number);
}

int main(void)                            //start main
{
//let's show the basic settings
 printf("UDP-IP Sample Init...\n");
 printf("MY_MAC:      %02x-%02x-%02x-%02x-%02x-%02x\n",MY_MAC[0],MY_MAC[1],MY_MAC[2],MY_MAC[3],MY_MAC[4],MY_MAC[5]);
 printf("SOURCE_IP:   %03d.%03d.%03d.%03d\n",SOURCE_IP[0],SOURCE_IP[1],SOURCE_IP[2],SOURCE_IP[3]);
 printf("TARGET_IP:   %03d.%03d.%03d.%03d\n",TARGET_IP[0],TARGET_IP[1],TARGET_IP[2],TARGET_IP[3]);
 printf("SOURCE_PORT: %d\n",SOURCE_PORT);
 printf("TARGET_PORT: %d\n",TARGET_PORT);

//init source MAC and IP
 memcpy(&conversion_long,&SOURCE_IP[0],4);//convert IP to long
 udpipInit(&MY_MAC[0],conversion_long); //read IP as long
//setup source port for broadcast (MAC = FF-FF-FF-FF-FF-FF)
//udpipSetBroadcastForService(2,TARGET_PORT);
 memcpy(&conversion_long,&TARGET_IP[0],4);//convert IP to long
 udpipSetIPForService(2,conversion_long,TARGET_PORT);
 udpipSetService(1,SOURCE_PORT,read_UDP1);//set receive port callback service 1
 udpipSetService(2,SOURCE_PORT,NULL);    //set receive port callback service 2

 while(1)                                //endless loop
 {
  volatile static int i = 500000;        //start to transmit
  i++;
  if(i>500000)                            //delay
  {
   trans_number++;                        //inc transmit number
   i=0;
//copy trans_number(2 bytes) in trans_message at offset 10
   memcpy(&trans_message[10],(uint8_t*)(&trans_number),sizeof(trans_number));
//transmit message
   udpipSend(2,trans_message,sizeof(trans_message)); //service 2, trans_message, 16 bytes
   printf("TxD %04d: %s %d\n",trans_counter,trans_message,trans_number);
   trans_counter++;
  }
  udpipWork();                            //do udp work
 }                                        //end endless loop
 return 0;
}                                        //end main


Hi Zero!
I've been reading your helpful posts but I can't seem to find your modified version of  the udpip library. Could you upload it again?

Thanks!
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by magnetron on Thu Dec 27 12:38:20 MST 2012
hello forum ,

I am trying to send empty UDP packet to visual basic 6.0 winsock
with the first example given in this thread by Zero
with wireshark I can see packets going in LAN ( my adsl router led blink )

however winsock never go into below subroutine
[COLOR=deepskyblue]Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Text1 = bytesTotal
End Sub[/COLOR]
[COLOR=lime][/COLOR]
[COLOR=lime][COLOR=black]I have set winsock protocol to UDP[/COLOR][/COLOR]
[COLOR=lime][COLOR=black]winsock has no port open method for UDP[/COLOR][/COLOR]
I have set winsock localport to 1023 remoteport to 1024
[COLOR=lime][COLOR=#000000]I calculate the UDP checksum like below [/COLOR][/COLOR]
[COLOR=lime][SIZE=2][LEFT]frame->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]srcport[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = HTONS(1024); [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//source port[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]frame->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]destport[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = HTONS(1023); [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//destination port[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]frame->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]udplen[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = HTONS(data_len+8); [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//data [U]len[/U] + 8 byte [U]udp[/U] header[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]frame->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]udpchksum[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=~uip_chksum(([/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint16_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*)&uip_buf[34],6); [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//6 byte header checksum[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE]
[COLOR=black]however wireshark says [/COLOR]
[COLOR=black]good checksum : false [/COLOR]
[COLOR=black]bad checksum : false [/COLOR]
[COLOR=black][/COLOR]
[COLOR=black]how can I correctly calculate UDP checksum ?[/COLOR]
[COLOR=black]what other can cause this error ?[/COLOR]

[COLOR=black]thank you [/COLOR]
[/COLOR]
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tmltml51 on Sun Dec 02 13:20:41 MST 2012
attachments....
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Dec 02 13:11:42 MST 2012

Quote: tmltml51
I've been following what you've written above, but I still can not receive data
this is the program I used to receive udp data (visual studio)
attachments....



No, this is a faulty ZIP :confused::eek::confused:
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tmltml51 on Sun Dec 02 13:07:14 MST 2012
I've been following what you've written above, but I still can not receive data
this is the program I used to receive udp data (visual studio)
attachments....
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Dec 02 10:11:16 MST 2012

Quote: tmltml51

do i need to set  the correct static IP address on my PC matches target_ip / port above?



Of course :eek:


Quote: tmltml51

how i can set TARGET_PORT on my PC?


That's doing your PC software ;)

So you should somewhere tell your Compiler that it should open an UDP connection and listen to port = target port of LPC :)

UDP transmission is done from Source UDP IP & PORT to Target UDP IP & PORT. If you don't know which Port your PC software is listening to, that's obviously your problem :p
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tmltml51 on Sun Dec 02 09:54:50 MST 2012
zero.
I used the programs simple and I also write a program to receive udp packet but both are do not get packet data. i dont know where my problem?
I changed the sample:
uint8_t MY_MAC [6] = {0x1E, 0x30, 0x6C, 0xA2, 0x45, 0x5E};
/ / IPs
static uint8_t SOURCE_IP [4] = {192,168,0,120};
static uint8_t TARGET_IP [4] = {192,168,0, 26};
/ / Ports
static uint16_t SOURCE_PORT = 4002;
static uint16_t TARGET_PORT = 4001;
do i need to set  the correct static IP address on my PC matches target_ip / port above?

how i can set TARGET_PORT on my PC?

thank.
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Dec 02 08:46:12 MST 2012
Since your PC is the target, your PC software has to open a port (with target port number of LPCXpresso sample) as UDP connection.

If Wireshark shows transmitted data from LPC your problem is your PC software ;)
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tmltml51 on Sun Dec 02 08:22:06 MST 2012
Thanks for the quick reply.

wireshark shows packages uploaded from lpc1769 but I do not get on my pc (used visual studio). I can only transmit data to lpc1769.I use static IP addresses
how can I know the exchange port on the PC and change it?
my problem with port?
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Dec 02 07:25:10 MST 2012
What's Wireshark telling you :confused:
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tmltml51 on Sun Dec 02 06:34:09 MST 2012
I  used Zero's UDP Sample from Post # 24 on lpc1769.I software using  Visual Studio to receive udp data transmission from the lpc1769.
but  I did not receive any packets from lpc1769 I changed the port and IP  address of the sample even if I can transfer data from PC (VStudio) to  lpc1769.
I need to do to receive the packet?.
I need to change port on pc coincides with the port on the  Zero's UDP Sample?
I saw port (SOURCE_PORT) when data transfer from pc (Visual Studio) to lpc1769 different TARGET_PORT on lpc1769.I need to change it to coincide with TARGET_PORT?
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Mon Aug 13 05:10:40 MST 2012

Quote:

Is the read_UDP1 function called automatically if something received?

Now you're kidding us

What do you think is happening here

static void ProcessUDP(void)
{
  RemotePort = SWAPB(*(unsigned short *)&RxBuffer[UDP_SRCPORT_OFS]);
  unsigned short LocalPort = SWAPB(*(unsigned short *)&RxBuffer[UDP_DESTPORT_OFS]);
  short Length = SWAPB(*(unsigned short *)&RxBuffer[UDP_LEN_OFS]);
  // checksum = SWAPB(*(unsigned short *)&RxBuffer[UDP_CHKSUM_OFS]);

  if (Length<=MAX_UDP_RX_DATA_SIZE)
  {
    short i;

    for (i=0;i<UDPIP_SERVICES;i++)
    {
      if (Services.LocalPort==LocalPort)
      {
        // simple callback mechanism, callback function should already
        // know which service index to use
        if (Services.Callback) [SIZE=4][B][COLOR=Red]Services.Callback(&RxBuffer[UDP_DATA_OFS],Length-UDP_HEADER_SIZE,Broadcast[/COLOR][/B][/SIZE]);
      }
    }
  }
}

Quote:

A general question: should the PC answer the UDP-packet automatically or do I need a additional software to send UDP-packets?

Your UDP is answered if someone is programmed to answer it. In general: PC's use Software to handle UDP, so if you're not running a program to transmit / receive UDP there's nothing happening :eek:

Wiki is your friend: http://de.wikipedia.org/wiki/User_Datagram_Protocol
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kranked on Mon Aug 13 03:00:15 MST 2012
I have seen the readUDP1 function but I was wondering why it isn't called in the endless loop of main. Then i saw this line udpipSetService(1,SOURCE_PORT,read_UDP1);

But I'm not sure how that works. Is the read_UDP1 function called automatically if something received?

A general question: should the PC answer the UDP-packet automatically or do I need a additional software to send UDP-packets?

Because i didn't see the printf output of
 printf("RxD %04d: %s %d\n",rec_counter,rec_message,rec_number);
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 13 02:42:38 MST 2012

Quote:

Ok. If i want to process the received data.

And are there any religious problems using callback functions of this sample, which hand your received data on a plate :confused:

udpipSetService(1,SOURCE_PORT,[COLOR=Blue]read_UDP1[/COLOR]);//set receive port callback service 1
...
void [COLOR=Blue]read_UDP1[/COLOR](unsigned char*[B][COLOR=Red] msg[/COLOR][/B], short len, unsigned char broadcast)
{
 memcpy(rec_message,msg,7);        //copy 7 char string
 rec_message[7]='\0';            //end
 memcpy(&rec_number,msg + 10,2);//copy number (2 bytes at 10)
 rec_counter++;
 printf("RxD %04d: %s %d\n",rec_counter,rec_message,rec_number);
}
...
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kranked on Mon Aug 13 02:32:52 MST 2012
Ok. If i want to process the received data. Should I use the struct emacData? Or was this a answer for a stupid question;)
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 13 01:49:34 MST 2012

Quote:
Where will be the recieved message saved?

AHB SRAM, where all this pointers point to
// NOTE: Verify that no data is declared anywhere else for the AHB SRAM section
static struct _emacData * const emacData=(struct _emacData *)0x2007C000;

Quote:

Is the Bold line the recieved data? What happened in that line?

No, this line is calling callback function, defined in udpipSetService()
0 Kudos