CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

EDTP Packet Whacker UDP transmit problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kieran



Joined: 28 Nov 2003
Posts: 39
Location: Essex UK

View user's profile Send private message

EDTP Packet Whacker UDP transmit problems
PostPosted: Fri Nov 05, 2004 3:23 am     Reply with quote

Edited and reposted as a new thread
EDTP Packet Whacker (RTL8019AS)

I have one of these hooked up to a 18F452 and have all the demo programs running.

I want to extend the UDP features and I am stuck.
I am trying to send a string back to a PC with the following
triggered by an incomming UDP message from the PC.
Src and Dest are derived from the incoming message.

Code:


byte dat_buff[128];

// Src source PORT
// Dest PORT
// *dat string to send
send_UDP(int16 Src, int16 Dest, byte *dat)
{
   memset(&packet[UDP_data],0,50); // Flush UDP data section of packet
   txlen = strlen(dat) + 8; // UDP data + header len

   ip_packet_len = 20 + txlen; // Allow for IP header
// Set IP header up
   packet[ip_pktlen] = make8(ip_packet_len,1);
   packet[ip_pktlen+1] = make8(ip_packet_len,0);

   setipaddrs();
// UDP header 
   packet[UDP_srcport] = make8(Src,1);
   packet[UDP_srcport + 1] = Src;
   packet[UDP_destport] = make8(Dest,1);
   packet[UDP_destport + 1] = Dest;

   txlen = strlen(dat) + 8; // UDP data + header len

   printf("send %s len %ld\r",dat,txlen);
   packet[UDP_len] = make8(txlen,1);  // Should be 0 - buffer size
   packet[UDP_len + 1] = txlen;

// Write data to packet
   strcpy(&packet[UDP_data],dat);

//calculate the UDP checksum
   packet[UDP_cksum] = 0x00;
   packet[UDP_cksum+1] = 0x00;

   hdr_chksum =0;
   hdrlen = 0x08;
   addr = &packet[ip_srcaddr];
   cksum();
   hdr_chksum = hdr_chksum + packet[ip_proto];
   hdrlen = 0x02;
   addr = &packet[UDP_len];
   cksum();
   hdrlen = make16(packet[UDP_len],packet[UDP_len+1]);
   addr = &packet[UDP_srcport];
   cksum();
   chksum16= ~(hdr_chksum + ((hdr_chksum & 0xFFFF0000) >> 16));
   packet[UDP_cksum] = make8(chksum16,1);
   packet[UDP_cksum+1] = make8(chksum16,0);

// Calculate length and send
   txlen = ip_packet_len + 14; // total packet len
   if(txlen < 60)
      txlen = 60;

   dump_header(); 
   show_packet();

   data_L = make8(txlen,0);
   data_H = make8(txlen,1);
// Data to RTL8019
   write_creg(CR,0x22);
   write_creg(TPSR,txstart);
   write_creg(RSAR0,0x00);
   write_creg(RSAR1,0x40);
   write_creg(ISR,0xFF);
   write_creg(RBCR0,data_L);
   write_creg(RBCR1,data_H);
   write_creg(CR,0x12);

   for(i=0;i<(txlen);++i)
      write_creg(RDMAPORT,packet[enetpacketDest0+i]);

   byte_read = 0;
   while(!bit_test(byte_read,RDC))
      read_creg(ISR);

   write_creg(TBCR0,txlen - 4);
   write_creg(TBCR1,make8(txlen,1));
   write_creg(RBCR0,data_L);
   write_creg(RBCR1,data_H);
   write_creg(CR,0x24);
 
}



Calls and variables are from the packet whacker code.
If I replace the code from below the checksum with the Packet Whacker echo_packet() function then all is well. Any ideas?
Kieran
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Nov 05, 2004 7:00 am     Reply with quote

The packet is probably malformed...Install on the PC in your network a packet sniffer ( ethereal ...free download from the web). It will show you the error in the packet you are sending assuming the packet makes it out onto the ethernet link. Once you know the error eg. checksum you can work back from there into your code. It's a bit more work than just pouring over your code but the packet snifer will catch intermittent issues that you might encounter going forward and is a very useful tool.
Kieran



Joined: 28 Nov 2003
Posts: 39
Location: Essex UK

View user's profile Send private message

PostPosted: Fri Nov 05, 2004 2:30 pm     Reply with quote

Fixed

Code:

   write_creg(TBCR0,txlen - 4);
   write_creg(TBCR1,make8(txlen,1));
   write_creg(RBCR0,data_L);
   write_creg(RBCR1,data_H);


Replaced by

Code:

   write_creg(TBCR0,data_L);
   write_creg(TBCR1,data_H);


Whoops - over ambitious cut and paste!
Embarassed
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group