Hello,
I have compiled and tried to get the 'eric' FreeRTOS port to work. My setup differs from the working reports in this forum in that I don't have a micro-SD card to test with. This results in a platform that starts up, but cannot complete the DHCP lookup :-(
I have checked with Wireshark and I can see the platform sends a DHCP DISCOVER packet periodically, and I can see my home router replying with a DHCP OFFER. For reasons unknown, the dhcpc.c code never receives this packet (confirmed with calls to log_message() inside parse_msg not being hit. I wondered if anyone has tried a similar setup, or if I should just buy a microSD card?
[hr:][/hr:]
Update: the problem was my router's DHCP packets were bigger than our Ethernet maximum frame size. See below for patches.
Here is a svn diff to show the logging added, and the console output. Strange observations:
More prints of "uip_udp_apcall for port 68" than packets seen on network.
First "uip_udp_apcall for port 68" printed before the DHCP discover sent!
Console log:
[tt:]Dangerous Prototypes Web Platform
Hardware v1.X, Firmware A2 v(trunk) built at 22:30:40 on Jan 20 2011.
Last system reset caused by one or more of:
Reset Button press.
SD Power on
CardType=0
SD power off
0 disk_initialize(0) returns 1
SD Power on
CardType=0
SD power off
1 disk_initialize(0) returns 1
SD Power on
CardType=0
SD power off
2 disk_initialize(0) returns 1
Reading SD Card...
Failed to open dir
fs_type=0 csize=0
NIC DMA Init
nic init
uip init
arp init
dhcp init
uip_udp_apcall for port 68
dhcp sent discover
uip_udp_apcall for port 68
uip_udp_apcall for port 68
dhcp sent discover
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
dhcp sent discover
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
dhcp sent discover
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
dhcp sent discover
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68[/tt:]
[tt:][chris@chris-desktop port-eric]$ svn diff
Index: trunk/src/dhcpc/dhcpc.c
===================================================================
--- trunk/src/dhcpc/dhcpc.c (revision 615)
+++ trunk/src/dhcpc/dhcpc.c (working copy)
@@ -38,6 +38,7 @@
#include "dhcpc.h"
#include "../uip/timer.h"
#include "../uip/pt.h"
+#include "../logger.h"
#define STATE_INITIAL 0
#define STATE_SENDING 1
@@ -177,6 +178,7 @@
end = add_end(end);
uip_send(uip_appdata, end - (u8_t *)uip_appdata);
+ uip_log(" dhcp sent discovern");
}
/*---------------------------------------------------------------------------*/
static void
@@ -193,6 +195,7 @@
end = add_end(end);
uip_send(uip_appdata, end - (u8_t *)uip_appdata);
+ uip_log(" dhcp sent requestn");
}
/*---------------------------------------------------------------------------*/
static u8_t
@@ -235,6 +238,7 @@
{
struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;
+ log_message(" dhcp got packet type %dn", m->op);
if(m->op == DHCP_REPLY &&
memcmp(m->xid, xid, sizeof(xid)) == 0 &&
memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) {
Index: trunk/src/uip/uip_task.c
===================================================================
--- trunk/src/uip/uip_task.c (revision 615)
+++ trunk/src/uip/uip_task.c (working copy)
@@ -65,13 +65,16 @@
// init uIP
uip_init();
- uip_log("uip init");
+ uip_log("uip initn");
// init ARP cache
uip_arp_init();
- uip_log("arp init");
+ uip_log("arp initn");
dhcpc_init(&mac, 6);
+
+ uip_log("dhcp initn");
+
//telnetd_init();
httpd_init();
@@ -174,6 +177,8 @@
}
void uip_udp_appcall(void) {
+ log_message("uip_udp_apcall for port %dn", HTONS(uip_udp_conn->lport));
+
switch (uip_udp_conn->lport) {
case HTONS(DHCPC_CLIENT_PORT):
dhcpc_appcall();
[chris@chris-desktop port-eric]$[/tt:]
Strange, I get the same result (no dhcp address) with a micro-SD card!
[tt:]Dangerous Prototypes Web Platform
Hardware v1.X, Firmware A2 v(trunk) built at 22:30:40 on Jan 20 2011.
Last system reset caused by one or more of:
Reset Button press.
SD Power on
CardType=4
0 disk_initialize(0) returns 0
f_mount(0) returns 0
Reading SD Card...
SD Power on
CardType=4
fs_type=2 csize=64
NIC DMA Init
nic init
uip init
arp init
dhcp init
uip_udp_apcall for port 68
dhcp sent discover
uip_udp_apcall for port 68
uip_udp_apcall for port 68
dhcp sent discover
uip_udp_apcall for port 68
uip_udp_apcall for port 68
uip_udp_apcall for port 68[/tt:]
Tracked this down... my DHCP server (Netgear WGR613) sends a DHCP_OFFER of 548 bytes. Since DHCP traffic is over UDP, there's no flow control or window negotiation. Since the packet is sent as one ethernet frame, which is bigger than the maximum ethernet frame size (512bytes) we program into the enc28j60 chip, the packets were being dropped by the enc28j60. By using up more DMA space by setting the uip_buf to 1500 bytes, the packets now make it though into the stack. The callbacks logged earlier were the 500ms periodic timer, and ARP packets (63 bytes)!
There are two bugs I want to fix:
* stack sends the DHCP_REQUEST and DHCP_ACK packets twice
* Because the ARP table is not updated by uip_arp_ipin(); using data from a new TCP packet SYN, the socket opening time is lengthened by the time to do an ARP broadcast/table update via. ARP packets in uip_arp_arpin(); :-(
Here's the patch to switch to 1500 bytes frame size, tidy up some of the logging etc.
[tt:][chris@chris-desktop trunk]$ svn diff
Index: src/dhcpc/dhcpc.c
===================================================================
--- src/dhcpc/dhcpc.c (revision 615)
+++ src/dhcpc/dhcpc.c (working copy)
@@ -38,6 +38,7 @@
#include "dhcpc.h"
#include "../uip/timer.h"
#include "../uip/pt.h"
+#include "../logger.h"
#define STATE_INITIAL 0
#define STATE_SENDING 1
@@ -177,6 +178,7 @@
end = add_end(end);
uip_send(uip_appdata, end - (u8_t *)uip_appdata);
+ uip_log(" dhcp sent discovern");
}
/*---------------------------------------------------------------------------*/
static void
@@ -193,6 +195,7 @@
end = add_end(end);
uip_send(uip_appdata, end - (u8_t *)uip_appdata);
+ uip_log(" dhcp sent requestn");
}
/*---------------------------------------------------------------------------*/
static u8_t
@@ -235,6 +238,7 @@
{
struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;
+ log_message(" dhcp got packet type %dn", m->op);
if(m->op == DHCP_REPLY &&
memcmp(m->xid, xid, sizeof(xid)) == 0 &&
memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) {
Index: src/uip/uip_task.c
===================================================================
--- src/uip/uip_task.c (revision 615)
+++ src/uip/uip_task.c (working copy)
@@ -65,11 +65,11 @@
// init uIP
uip_init();
- uip_log("uip init");
+ uip_log("uip initn");
// init ARP cache
uip_arp_init();
- uip_log("arp init");
+ uip_log("arp initn");
dhcpc_init(&mac, 6);
//telnetd_init();
Index: src/uip/uip-conf.h
===================================================================
--- src/uip/uip-conf.h (revision 615)
+++ src/uip/uip-conf.h (working copy)
@@ -107,7 +107,7 @@
*
* hideinitializer
*/
-#define UIP_CONF_BUFFER_SIZE 512
+#define UIP_CONF_BUFFER_SIZE 1500
#define UIP_CONF_EXTERNAL_BUFFER
@@ -132,7 +132,7 @@
* hideinitializer
*/
#define UIP_CONF_UDP 1
-
+#define UIP_CONF_BROADCAST 1
/**
* UDP checksums on or off
*
Index: src/nic/enc28j60.h
===================================================================
--- src/nic/enc28j60.h (revision 615)
+++ src/nic/enc28j60.h (working copy)
@@ -242,7 +242,7 @@
//#define RXSTART_INIT 0x46
//#define RXSTOP_INIT 0x60
-#define MAX_FRAMELEN 512 // maximum ethernet frame length; should match UIP Buffer size
+#define MAX_FRAMELEN 1500 // maximum ethernet frame length; should match UIP Buffer size
// Ethernet constants
#define ETHERNET_MIN_PACKET_LENGTH 0x3C
[chris@chris-desktop trunk]$[/tt:]
Console trace:
[tt:]Dangerous Prototypes Web Platform
Hardware v1.X, Firmware A2 v(trunk) built at 11:57:05 on Jan 23 2011.
Last system reset caused by one or more of:
Reset Button press.
SD Power on
CardType=4
0 disk_initialize(0) returns 0
f_mount(0) returns 0
Reading SD Card...
SD Power on
CardType=4
fs_type=2 csize=64
NIC DMA Init
nic init
uip initarp init dhcp sent discover
dhcp sent discover
dhcp sent discover
dhcp got packet type 2
dhcp sent request
dhcp sent request
dhcp got packet type 2
dhcp configured. My IP=192.168.1.3[/tt:]
What an odd problem, great catch. I applied the patch and committed it to SVN, thank you.