summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/Documentation/NuttX.html2
-rw-r--r--nuttx/TODO11
-rw-r--r--nuttx/drivers/net/dm90x0.c22
-rw-r--r--nuttx/examples/uip/main.c15
-rw-r--r--nuttx/fs/fs_ioctl.c5
-rw-r--r--nuttx/include/net/if.h85
-rw-r--r--nuttx/include/net/ioctls.h30
-rw-r--r--nuttx/include/net/uip/dhcpc.h26
-rw-r--r--nuttx/include/net/uip/dhcpd.h73
-rw-r--r--nuttx/include/net/uip/uip-arch.h1
-rw-r--r--nuttx/net/netdev-ioctl.c1
-rw-r--r--nuttx/net/netdev-register.c1
-rw-r--r--nuttx/net/sendto.c3
-rw-r--r--nuttx/net/uip/uip-arp.c1
-rw-r--r--nuttx/net/uip/uip-icmpinput.c1
-rw-r--r--nuttx/net/uip/uip-send.c1
-rw-r--r--nuttx/netutils/Makefile20
-rw-r--r--nuttx/netutils/dhcpc/dhcpc.c119
-rw-r--r--nuttx/netutils/uiplib/uip-gethostaddr.c3
-rw-r--r--nuttx/netutils/uiplib/uip-getmacaddr.c3
-rw-r--r--nuttx/netutils/uiplib/uip-setdraddr.c3
-rw-r--r--nuttx/netutils/uiplib/uip-sethostaddr.c3
-rw-r--r--nuttx/netutils/uiplib/uip-setmacaddr.c3
-rw-r--r--nuttx/netutils/uiplib/uip-setnetmask.c3
25 files changed, 317 insertions, 120 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index fc5cfa443..1cfdfbb39 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -259,3 +259,5 @@
and polling intervals. Greatly improves send performance.
0.3.4 2007-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
+
+ * Added netutils/dhcpd
diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html
index 4255dd17a..20a4a29eb 100644
--- a/nuttx/Documentation/NuttX.html
+++ b/nuttx/Documentation/NuttX.html
@@ -747,6 +747,8 @@ Other memory:
<pre><ul>
0.3.4 2007-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
+
+ * Added netutils/dhcpd
</pre></ul>
<table width ="100%">
diff --git a/nuttx/TODO b/nuttx/TODO
index c0aff5318..500013d14 100644
--- a/nuttx/TODO
+++ b/nuttx/TODO
@@ -70,14 +70,19 @@ o Build system
o Applications & Tests
-o C5471
+o ARM
+- Add option to use a separate stack for interrupt handling. At present,
+ each interrupt executes on top of the user stack allocation making each
+ user stack allocation larger than needed.
-o DM320
+o ARM/C5471
+
+o ARM/DM320
- It seems that when a lot of debug statements are added, the system no
longer boots. This has been diagnosed as a stack problem.. making the stack
bigger or removing arrays on the stack fixes the problem.
-o LPC214x
+o ARM/LPC214x
- Finish bringup
- Add MMC and USB support
diff --git a/nuttx/drivers/net/dm90x0.c b/nuttx/drivers/net/dm90x0.c
index b6d932cb9..2a63d7383 100644
--- a/nuttx/drivers/net/dm90x0.c
+++ b/nuttx/drivers/net/dm90x0.c
@@ -294,6 +294,7 @@ union rx_desc_u
struct dm9x_driver_s
{
+ boolean dm_bifup; /* TRUE:ifup FALSE:ifdown */
boolean dm_b100M; /* TRUE:speed == 100M; FALSE:speed == 10M */
WDOG_ID dm_txpoll; /* TX poll timer */
WDOG_ID dm_txtimeout; /* TX timeout timer */
@@ -1396,6 +1397,7 @@ static int dm9x_ifup(struct uip_driver_s *dev)
/* Enable the DM9X interrupt */
+ dm9x->dm_bifup = TRUE;
up_enable_irq(CONFIG_DM9X_IRQ);
return OK;
}
@@ -1440,6 +1442,8 @@ static int dm9x_ifdown(struct uip_driver_s *dev)
putreg(DM9X_IMR, DM9X_IMRDISABLE); /* Disable all interrupts */
putreg(DM9X_RXC, 0x00); /* Disable RX */
putreg(DM9X_ISR, DM9X_INT_ALL); /* Clear interrupt status */
+
+ dm9x->dm_bifup = FALSE;
irqrestore(flags);
/* Dump statistics */
@@ -1475,15 +1479,21 @@ static int dm9x_txavail(struct uip_driver_s *dev)
ndbg("Polling\n");
flags = irqsave();
- /* Check if there is room in the DM90x0 to hold another packet. In 100M mode,
- * that can be 2 packets, otherwise it is a single packet.
- */
+ /* Ignore the notification if the interface is not yet up */
- if (dm9x->dm_ntxpending < 1 || (dm9x->dm_b100M && dm9x->dm_ntxpending < 2))
+ if (dm9x->dm_bifup)
{
- /* If so, then poll uIP for new XMIT data */
- (void)uip_poll(&dm9x->dm_dev, dm9x_uiptxpoll);
+ /* Check if there is room in the DM90x0 to hold another packet. In 100M
+ * mode, that can be 2 packets, otherwise it is a single packet.
+ */
+
+ if (dm9x->dm_ntxpending < 1 || (dm9x->dm_b100M && dm9x->dm_ntxpending < 2))
+ {
+ /* If so, then poll uIP for new XMIT data */
+
+ (void)uip_poll(&dm9x->dm_dev, dm9x_uiptxpoll);
+ }
}
irqrestore(flags);
return OK;
diff --git a/nuttx/examples/uip/main.c b/nuttx/examples/uip/main.c
index 83da6fe2c..a5640f848 100644
--- a/nuttx/examples/uip/main.c
+++ b/nuttx/examples/uip/main.c
@@ -51,6 +51,7 @@
#include <time.h>
#include <debug.h>
+#include <net/if.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arp.h>
#include <net/uip/uip-lib.h>
@@ -85,6 +86,12 @@
* Definitions
****************************************************************************/
+#ifdef CONFIG_DEBUG
+# define message(...) lib_lowprintf(__VA_ARGS__)
+#else
+# define message(...) printf(__VA_ARGS__)
+#endif
+
/****************************************************************************
* Private Data
****************************************************************************/
@@ -120,9 +127,7 @@ void user_initialize(void)
int user_start(int argc, char *argv[])
{
-#if !defined(CONFIG_EXAMPLE_UIP_DHCPC)
struct in_addr addr;
-#endif
#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_EXAMPLE_UIP_NOMAC)
uint8 mac[IFHWADDRLEN];
#endif
@@ -142,10 +147,13 @@ int user_start(int argc, char *argv[])
uip_setmacaddr("eth0", mac);
#endif
-#if !defined(CONFIG_EXAMPLE_UIP_DHCPC)
/* Set up our host address */
+#if !defined(CONFIG_EXAMPLE_UIP_DHCPC)
addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_IPADDR);
+#else
+ addr.s_addr = 0;
+#endif
uip_sethostaddr("eth0", &addr);
/* Set up the default router address */
@@ -157,7 +165,6 @@ int user_start(int argc, char *argv[])
addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_NETMASK);
uip_setnetmask("eth0", &addr);
-#endif
#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
/* Set up the resolver */
diff --git a/nuttx/fs/fs_ioctl.c b/nuttx/fs/fs_ioctl.c
index 52329d60c..ba81228c1 100644
--- a/nuttx/fs/fs_ioctl.c
+++ b/nuttx/fs/fs_ioctl.c
@@ -43,9 +43,12 @@
#include <nuttx/config.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
+
#include <sched.h>
#include <errno.h>
-#include <sys/ioctl.h>
+
+#include <net/if.h>
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
# include <nuttx/net.h>
diff --git a/nuttx/include/net/if.h b/nuttx/include/net/if.h
new file mode 100644
index 000000000..7d8ea6007
--- /dev/null
+++ b/nuttx/include/net/if.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * net/if.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __NET_IF_H
+#define __NET_IF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/socket.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Sizing parameters */
+
+#define IFNAMSIZ 6
+#define IFHWADDRLEN 6
+
+/****************************************************************************
+ * Type Definitions
+ ****************************************************************************/
+
+struct ifreq
+{
+ char ifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */
+ union
+ {
+ struct sockaddr ifru_addr; /* IP Address */
+ struct sockaddr ifru_dstaddr; /* P-to-P Address */
+ struct sockaddr ifru_broadaddr; /* Broadcast address */
+ struct sockaddr ifru_netmask; /* Netmask */
+ struct sockaddr ifru_hwaddr; /* MAC address */
+ int ifru_count; /* Number of devices */
+ int ifru_mtu; /* MTU size */
+ } ifr_ifru;
+};
+
+#define ifr_addr ifr_ifru.ifru_addr /* IP address */
+#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* P-to-P Address */
+#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* Broadcast address */
+#define ifr_netmask ifr_ifru.ifru_netmask /* Interface net mask */
+#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
+#define ifr_mtu ifr_ifru.ifru_mtu /* MTU */
+#define ifr_count ifr_ifru.ifru_count /* Number of devices */
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#endif /* __NET_IF_H */
diff --git a/nuttx/include/net/ioctls.h b/nuttx/include/net/ioctls.h
index 4be5727ac..785c7d4f2 100644
--- a/nuttx/include/net/ioctls.h
+++ b/nuttx/include/net/ioctls.h
@@ -40,8 +40,6 @@
* Included Files
****************************************************************************/
-#include <sys/socket.h>
-
/****************************************************************************
* Definitions
****************************************************************************/
@@ -69,38 +67,10 @@
#define SIOCDIFADDR (_SIOCBASE|0x000c) /* Delete IP address */
#define SIOCGIFCOUNT (_SIOCBASE|0x000d) /* Get number of devices */
-/* Sizing parameters */
-
-#define IFNAMSIZ 6
-#define IFHWADDRLEN 6
-
/****************************************************************************
* Type Definitions
****************************************************************************/
-struct ifreq
-{
- char ifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */
- union
- {
- struct sockaddr ifru_addr; /* IP Address */
- struct sockaddr ifru_dstaddr; /* P-to-P Address */
- struct sockaddr ifru_broadaddr; /* Broadcast address */
- struct sockaddr ifru_netmask; /* Netmask */
- struct sockaddr ifru_hwaddr; /* MAC address */
- int ifru_count; /* Number of devices */
- int ifru_mtu; /* MTU size */
- } ifr_ifru;
-};
-
-#define ifr_addr ifr_ifru.ifru_addr /* IP address */
-#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* P-to-P Address */
-#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* Broadcast address */
-#define ifr_netmask ifr_ifru.ifru_netmask /* Interface net mask */
-#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
-#define ifr_mtu ifr_ifru.ifru_mtu /* MTU */
-#define ifr_count ifr_ifru.ifru_count /* Number of devices */
-
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
diff --git a/nuttx/include/net/uip/dhcpc.h b/nuttx/include/net/uip/dhcpc.h
index 12f3f0a9b..606d818b0 100644
--- a/nuttx/include/net/uip/dhcpc.h
+++ b/nuttx/include/net/uip/dhcpc.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * dhcpc.c
+ * net/uip/dhcpc.n
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
@@ -35,8 +35,8 @@
* SUCH DAMAGE.
*/
-#ifndef NET_UIP_DHCP_H__
-#define NET_UIP_DHCP_H__
+#ifndef __NET_UIP_DHCPC_H
+#define __NET_UIP_DHCPC_H
/****************************************************************************
* Included Files
@@ -66,8 +66,20 @@ struct dhcpc_state
* Public Function Prototypes
****************************************************************************/
-void *dhcpc_open(const void *mac_addr, int mac_len);
-int dhcpc_request(void *handle, struct dhcpc_state *presult);
-void dhcpc_close(void *handle);
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
-#endif /* NET_UIP_DHCP_H__ */
+EXTERN void *dhcpc_open(const void *mac_addr, int mac_len);
+EXTERN int dhcpc_request(void *handle, struct dhcpc_state *presult);
+EXTERN void dhcpc_close(void *handle);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NET_UIP_DHCPC_H */
diff --git a/nuttx/include/net/uip/dhcpd.h b/nuttx/include/net/uip/dhcpd.h
new file mode 100644
index 000000000..ed8770f03
--- /dev/null
+++ b/nuttx/include/net/uip/dhcpd.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * net/uipt/dhcpd.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * This logic was leveraged from uIP which also has a BSD-style license:
+ *
+ * Copyright (c) 2005, Swedish Institute of Computer Science
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __NET_UIP_DHCPD_H
+#define __NET_UIP_DHCPD_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN int dhcpd_run(void);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NET_UIP_DHCPD_H */
diff --git a/nuttx/include/net/uip/uip-arch.h b/nuttx/include/net/uip/uip-arch.h
index eb5a0e5ba..9de911e00 100644
--- a/nuttx/include/net/uip/uip-arch.h
+++ b/nuttx/include/net/uip/uip-arch.h
@@ -45,6 +45,7 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <net/if.h>
#include <net/uip/uip.h>
/****************************************************************************
diff --git a/nuttx/net/netdev-ioctl.c b/nuttx/net/netdev-ioctl.c
index 9adc2ae0a..81cfce689 100644
--- a/nuttx/net/netdev-ioctl.c
+++ b/nuttx/net/netdev-ioctl.c
@@ -50,6 +50,7 @@
#include <nuttx/net.h>
+#include <net/if.h>
#include <net/uip/uip-arch.h>
#include <net/uip/uip.h>
diff --git a/nuttx/net/netdev-register.c b/nuttx/net/netdev-register.c
index 03a978880..b1ab57a44 100644
--- a/nuttx/net/netdev-register.c
+++ b/nuttx/net/netdev-register.c
@@ -49,6 +49,7 @@
#include <errno.h>
#include <debug.h>
+#include <net/if.h>
#include <net/uip/uip-arch.h>
#include "net-internal.h"
diff --git a/nuttx/net/sendto.c b/nuttx/net/sendto.c
index a0f3cc4a1..0e5b80032 100644
--- a/nuttx/net/sendto.c
+++ b/nuttx/net/sendto.c
@@ -44,6 +44,7 @@
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
+#include <debug.h>
#include <arch/irq.h>
#include <net/uip/uip-arch.h>
@@ -93,6 +94,8 @@ struct sendto_s
void sendto_interrupt(struct uip_driver_s *dev, struct uip_udp_conn *conn, uint8 flags)
{
struct sendto_s *pstate = (struct sendto_s *)conn->private;
+
+ nvdbg("flags: %02x\n");
if (pstate)
{
/* Check if the connection was rejected */
diff --git a/nuttx/net/uip/uip-arp.c b/nuttx/net/uip/uip-arp.c
index 59558072b..838d99b72 100644
--- a/nuttx/net/uip/uip-arp.c
+++ b/nuttx/net/uip/uip-arp.c
@@ -62,6 +62,7 @@
#include <debug.h>
#include <netinet/in.h>
+#include <net/if.h>
#include <net/uip/uip-arch.h>
#include <net/uip/uip-arp.h>
diff --git a/nuttx/net/uip/uip-icmpinput.c b/nuttx/net/uip/uip-icmpinput.c
index 2f14945b7..747301f2b 100644
--- a/nuttx/net/uip/uip-icmpinput.c
+++ b/nuttx/net/uip/uip-icmpinput.c
@@ -48,6 +48,7 @@
#include <sys/types.h>
#include <debug.h>
+#include <net/if.h>
#include <net/uip/uipopt.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arch.h>
diff --git a/nuttx/net/uip/uip-send.c b/nuttx/net/uip/uip-send.c
index c9899db9e..6e83cb0d8 100644
--- a/nuttx/net/uip/uip-send.c
+++ b/nuttx/net/uip/uip-send.c
@@ -42,6 +42,7 @@
****************************************************************************/
#include <string.h>
+#include <debug.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arch.h>
diff --git a/nuttx/netutils/Makefile b/nuttx/netutils/Makefile
index 752a6d0b1..0c14a1094 100644
--- a/nuttx/netutils/Makefile
+++ b/nuttx/netutils/Makefile
@@ -47,16 +47,17 @@ include webserver/Make.defs
endif
ifeq ($(CONFIG_NET_UDP),y)
include dhcpc/Make.defs
+include dhcpd/Make.defs
include resolv/Make.defs
endif
endif
-ASRCS = $(UIPLIB_ASRCS) $(DHCPC_ASRCS) $(RESOLV_ASRCS) $(SMTP_ASRCS) \
- $(TELNETD_ASRCS) $(WEBCLIENT_ASRCS) $(WEBSERVER_ASRCS) $(STRNG_ASRCS)
+ASRCS = $(UIPLIB_ASRCS) $(DHCPC_ASRCS) $(DHCPD_ASRCS) $(RESOLV_ASRCS) \
+ $(SMTP_ASRCS) $(TELNETD_ASRCS) $(WEBCLIENT_ASRCS) $(WEBSERVER_ASRCS)
AOBJS = $(ASRCS:.S=$(OBJEXT))
-CSRCS = $(UIPLIB_CSRCS) $(DHCPC_CSRCS) $(RESOLV_CSRCS) $(SMTP_CSRCS) \
- $(TELNETD_CSRCS) $(WEBCLIENT_CSRCS) $(WEBSERVER_CSRCS) $(STRNG_CSRCS)
+CSRCS = $(UIPLIB_CSRCS) $(DHCPC_CSRCS) $(DHCPD_CSRCS) $(RESOLV_CSRCS) \
+ $(SMTP_CSRCS) $(TELNETD_CSRCS) $(WEBCLIENT_CSRCS) $(WEBSERVER_CSRCS)
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
@@ -64,7 +65,7 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libnetutils$(LIBEXT)
-VPATH = uiplib:dhcpc:resolv:smtp:telnetd:webclient:webserver
+VPATH = uiplib:dhcpc:dhcpd:resolv:smtp:telnetd:webclient:webserver
all: $(BIN)
@@ -82,8 +83,9 @@ $(BIN): $(OBJS)
.depend: Makefile $(SRCS)
ifeq ($(CONFIG_NET),y)
- @$(MKDEP) --dep-path . --dep-path uiplib --dep-path dhcpc --dep-path smtp --dep-path webclient \
- --dep-path resolv --dep-path telnetd --dep-path webserver \
+ @$(MKDEP) --dep-path . --dep-path uiplib --dep-path dhcpc --dep-path dhcpd \
+ --dep-path smtp --dep-path webclient --dep-path resolv \
+ --dep-path telnetd --dep-path webserver \
$(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
endif
@touch $@
@@ -92,11 +94,11 @@ depend: .depend
clean:
@rm -f $(BIN) *.o *.rel *.asm *.lst *.sym *.adb *~
- @rm -f uiplib/*~ dhcpc/*~ resolv/*~ smtp/*~ telnetd/*~ webclient/*~ webserver/*~
+ @rm -f uiplib/*~ dhcpc/*~ dhcpd/*~ resolv/*~ smtp/*~ telnetd/*~ webclient/*~ webserver/*~
@if [ ! -z "$(OBJEXT)" ]; then rm -f *$(OBJEXT); fi
+ @$(MAKE) -C dhcpd -f Makefile.host clean
distclean: clean
@rm -f Make.dep .depend
- @rm -f $(STRNG_CSRCS) $(STRNG_ASRCS)
-include Make.dep
diff --git a/nuttx/netutils/dhcpc/dhcpc.c b/nuttx/netutils/dhcpc/dhcpc.c
index bdb885ccc..6b7bc9535 100644
--- a/nuttx/netutils/dhcpc/dhcpc.c
+++ b/nuttx/netutils/dhcpc/dhcpc.c
@@ -100,15 +100,6 @@
* Private Types
****************************************************************************/
-struct dhcpc_state_internal
-{
- struct uip_udp_conn *conn;
- const void *mac_addr;
- int mac_len;
- int sockfd;
- char buffer[256];
-};
-
struct dhcp_msg
{
uint8 op;
@@ -130,6 +121,15 @@ struct dhcp_msg
uint8 options[312];
};
+struct dhcpc_state_s
+{
+ struct uip_udp_conn *ds_conn;
+ const void *ds_macaddr;
+ int ds_maclen;
+ int sockfd;
+ struct dhcp_msg packet;
+};
+
/****************************************************************************
* Private Data
****************************************************************************/
@@ -181,74 +181,66 @@ static uint8 *add_end(uint8 *optptr)
return optptr;
}
-static void create_msg(struct dhcpc_state_internal *pdhcpc, struct dhcp_msg *pmsg)
+static void create_msg(struct dhcpc_state_s *pdhcpc)
{
struct in_addr addr;
- pmsg->op = DHCP_REQUEST;
- pmsg->htype = DHCP_HTYPE_ETHERNET;
- pmsg->hlen = pdhcpc->mac_len;
- pmsg->hops = 0;
- memcpy(pmsg->xid, xid, sizeof(pmsg->xid));
- pmsg->secs = 0;
- pmsg->flags = HTONS(BOOTP_BROADCAST); /* Broadcast bit. */
+ memset(&pdhcpc->packet, 0, sizeof(struct dhcp_msg));
+ pdhcpc->packet.op = DHCP_REQUEST;
+ pdhcpc->packet.htype = DHCP_HTYPE_ETHERNET;
+ pdhcpc->packet.hlen = pdhcpc->ds_maclen;
+ memcpy(pdhcpc->packet.xid, xid, 4);
+ pdhcpc->packet.flags = HTONS(BOOTP_BROADCAST); /* Broadcast bit. */
uip_gethostaddr("eth0", &addr);
- memcpy(&pmsg->ciaddr, &addr.s_addr, sizeof(pmsg->ciaddr));
- memset(pmsg->yiaddr, 0, sizeof(pmsg->yiaddr));
- memset(pmsg->siaddr, 0, sizeof(pmsg->siaddr));
- memset(pmsg->giaddr, 0, sizeof(pmsg->giaddr));
-
- memcpy(pmsg->chaddr, pdhcpc->mac_addr, pdhcpc->mac_len);
- memset(&pmsg->chaddr[pdhcpc->mac_len], 0, sizeof(pmsg->chaddr) - pdhcpc->mac_len);
-#ifndef CONFIG_NET_DHCP_LIGHT
- memset(pmsg->sname, 0, sizeof(pmsg->sname));
- memset(pmsg->file, 0, sizeof(pmsg->file));
-#endif
+ memcpy(&pdhcpc->packet.ciaddr, &addr.s_addr, 4);
- memcpy(pmsg->options, magic_cookie, sizeof(magic_cookie));
+ memcpy(pdhcpc->packet.chaddr, pdhcpc->ds_macaddr, pdhcpc->ds_maclen);
+ memset(&pdhcpc->packet.chaddr[pdhcpc->ds_maclen], 0, 16 - pdhcpc->ds_maclen);
+ memcpy(pdhcpc->packet.options, magic_cookie, sizeof(magic_cookie));
}
-static int send_discover(struct dhcpc_state_internal *pdhcpc)
+static int send_discover(struct dhcpc_state_s *pdhcpc)
{
- struct dhcp_msg msg;
struct sockaddr_in addr;
uint8 *pend;
int len;
- create_msg(pdhcpc, &msg);
- pend = add_msg_type(&msg.options[4], DHCPDISCOVER);
+dbg("Calling create_msg\n");
+ create_msg(pdhcpc);
+ pend = &pdhcpc->packet.options[4];
+ pend = add_msg_type(pend, DHCPDISCOVER);
pend = add_req_options(pend);
pend = add_end(pend);
- len = pend - (uint8*)&msg;
+ len = pend - (uint8*)&pdhcpc->packet;
addr.sin_family = AF_INET;
addr.sin_port = HTONS(DHCPC_SERVER_PORT);
addr.sin_addr.s_addr = INADDR_BROADCAST;
- return sendto(pdhcpc->sockfd, &msg, len, 0,
+dbg("Calling sendto, len=%d\n", len);
+ return sendto(pdhcpc->sockfd, &pdhcpc->packet, len, 0,
(struct sockaddr*)&addr, sizeof(struct sockaddr_in));
}
-
-static int send_request(struct dhcpc_state_internal *pdhcpc, struct dhcpc_state *presult)
+static int send_request(struct dhcpc_state_s *pdhcpc, struct dhcpc_state *presult)
{
- struct dhcp_msg msg;
struct sockaddr_in addr;
uint8 *pend;
int len;
- create_msg(pdhcpc, &msg);
- pend = add_msg_type(&msg.options[4], DHCPREQUEST);
+ create_msg(pdhcpc);
+ pend = &pdhcpc->packet.options[4];
+ pend = add_msg_type(pend, DHCPREQUEST);
pend = add_server_id(presult, pend);
pend = add_req_ipaddr(presult, pend);
pend = add_end(pend);
- len = pend - (uint8*)&msg;
+ len = pend - (uint8*)&pdhcpc->packet;
addr.sin_family = AF_INET;
addr.sin_port = HTONS(DHCPC_SERVER_PORT);
addr.sin_addr.s_addr = INADDR_BROADCAST;
- return sendto(pdhcpc->sockfd, &msg, len, 0,
+ return sendto(pdhcpc->sockfd, &pdhcpc->packet, len, 0,
(struct sockaddr*)&addr, sizeof(struct sockaddr_in));
}
@@ -288,16 +280,15 @@ static uint8 parse_options(struct dhcpc_state *presult, uint8 *optptr, int len)
return type;
}
-static uint8 parse_msg(struct dhcpc_state_internal *pdhcpc, int buflen, struct dhcpc_state *presult)
+static uint8 parse_msg(struct dhcpc_state_s *pdhcpc, int buflen,
+ struct dhcpc_state *presult)
{
- struct dhcp_msg *pbuffer = (struct dhcp_msg *)pdhcpc->buffer;
-
- if (pbuffer->op == DHCP_REPLY &&
- memcmp(pbuffer->xid, xid, sizeof(xid)) == 0 &&
- memcmp(pbuffer->chaddr, pdhcpc->mac_addr, pdhcpc->mac_len) == 0)
+ if (pdhcpc->packet.op == DHCP_REPLY &&
+ memcmp(pdhcpc->packet.xid, xid, sizeof(xid)) == 0 &&
+ memcmp(pdhcpc->packet.chaddr, pdhcpc->ds_macaddr, pdhcpc->ds_maclen) == 0)
{
- memcpy(&presult->ipaddr.s_addr, pbuffer->yiaddr, 4);
- return parse_options(presult, &pbuffer->options[4], buflen);
+ memcpy(&presult->ipaddr.s_addr, pdhcpc->packet.yiaddr, 4);
+ return parse_options(presult, &pdhcpc->packet.options[4], buflen);
}
return 0;
}
@@ -306,22 +297,22 @@ static uint8 parse_msg(struct dhcpc_state_internal *pdhcpc, int buflen, struct d
* Global Functions
****************************************************************************/
-void *dhcpc_open(const void *mac_addr, int mac_len)
+void *dhcpc_open(const void *macaddr, int maclen)
{
- struct dhcpc_state_internal *pdhcpc;
+ struct dhcpc_state_s *pdhcpc;
struct sockaddr_in addr;
struct timeval tv;
/* Allocate an internal DHCP structure */
- pdhcpc = (struct dhcpc_state_internal *)malloc(sizeof(struct dhcpc_state_internal));
+ pdhcpc = (struct dhcpc_state_s *)malloc(sizeof(struct dhcpc_state_s));
if (pdhcpc)
{
/* Initialize the allocated structure */
- memset(pdhcpc, 0, sizeof(struct dhcpc_state_internal));
- pdhcpc->mac_addr = mac_addr;
- pdhcpc->mac_len = mac_len;
+ memset(pdhcpc, 0, sizeof(struct dhcpc_state_s));
+ pdhcpc->ds_macaddr = macaddr;
+ pdhcpc->ds_maclen = maclen;
/* Create a UDP socket */
@@ -357,6 +348,7 @@ void *dhcpc_open(const void *mac_addr, int mac_len)
}
}
+ dbg("Return %p\n", pdhcpc);
return (void*)pdhcpc;
}
@@ -371,12 +363,13 @@ void dhcpc_close(void *handle)
int dhcpc_request(void *handle, struct dhcpc_state *presult)
{
- struct dhcpc_state_internal *pdhcpc = (struct dhcpc_state_internal *)handle;
+ struct dhcpc_state_s *pdhcpc = (struct dhcpc_state_s *)handle;
ssize_t result;
int state;
/* Loop until we receive the offer */
+ dbg("Handle %p\n", handle);
do
{
state = STATE_SENDING;
@@ -385,18 +378,22 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
{
/* Send the command */
+ dbg("Send DHCPDISCOVER, @4=%08x\n", *(uint32*)4);
if (send_discover(pdhcpc) < 0)
{
return ERROR;
}
/* Get the response */
-
- result = recv(pdhcpc->sockfd, pdhcpc->buffer, BUFFER_SIZE, 0);
+dbg("Sent DHCPDISCOVER\n");
+ result = recv(pdhcpc->sockfd, &pdhcpc->packet, sizeof(struct dhcp_msg), 0);
+dbg("recv returned %d\n");
if (result >= 0)
{
+dbg("Calling parse_msg\n");
if (parse_msg(pdhcpc, result, presult) == DHCPOFFER)
{
+ dbg("Received DHCPOFFER\n");
state = STATE_OFFER_RECEIVED;
}
}
@@ -413,6 +410,7 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
{
/* Send the request */
+ dbg("Send DHCPREQUEST\n");
if (send_request(pdhcpc, presult) < 0)
{
return ERROR;
@@ -420,11 +418,12 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
/* Get the response */
- result = recv(pdhcpc->sockfd, pdhcpc->buffer, BUFFER_SIZE, 0);
+ result = recv(pdhcpc->sockfd, &pdhcpc->packet, sizeof(struct dhcp_msg), 0);
if (result >= 0)
{
if (parse_msg(pdhcpc, result, presult) == DHCPACK)
{
+ dbg("Received ACK\n");
state = STATE_CONFIG_RECEIVED;
}
}
diff --git a/nuttx/netutils/uiplib/uip-gethostaddr.c b/nuttx/netutils/uiplib/uip-gethostaddr.c
index 732721b10..d20344d8c 100644
--- a/nuttx/netutils/uiplib/uip-gethostaddr.c
+++ b/nuttx/netutils/uiplib/uip-gethostaddr.c
@@ -43,9 +43,12 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+
#include <string.h>
#include <errno.h>
+
#include <netinet/in.h>
+#include <net/if.h>
#include <net/uip/uip-lib.h>
diff --git a/nuttx/netutils/uiplib/uip-getmacaddr.c b/nuttx/netutils/uiplib/uip-getmacaddr.c
index 9e7a368ab..c45072c86 100644
--- a/nuttx/netutils/uiplib/uip-getmacaddr.c
+++ b/nuttx/netutils/uiplib/uip-getmacaddr.c
@@ -43,9 +43,12 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+
#include <string.h>
#include <errno.h>
+
#include <netinet/in.h>
+#include <net/if.h>
#include <net/uip/uip-lib.h>
diff --git a/nuttx/netutils/uiplib/uip-setdraddr.c b/nuttx/netutils/uiplib/uip-setdraddr.c
index e8ab142ec..6d61f2d5d 100644
--- a/nuttx/netutils/uiplib/uip-setdraddr.c
+++ b/nuttx/netutils/uiplib/uip-setdraddr.c
@@ -43,10 +43,13 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+
#include <unistd.h>
#include <string.h>
#include <errno.h>
+
#include <netinet/in.h>
+#include <net/if.h>
#include <net/uip/uip-lib.h>
diff --git a/nuttx/netutils/uiplib/uip-sethostaddr.c b/nuttx/netutils/uiplib/uip-sethostaddr.c
index 6247184ba..3f3cd7a6d 100644
--- a/nuttx/netutils/uiplib/uip-sethostaddr.c
+++ b/nuttx/netutils/uiplib/uip-sethostaddr.c
@@ -43,10 +43,13 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+
#include <unistd.h>
#include <string.h>
#include <errno.h>
+
#include <netinet/in.h>
+#include <net/if.h>
#include <net/uip/uip-lib.h>
diff --git a/nuttx/netutils/uiplib/uip-setmacaddr.c b/nuttx/netutils/uiplib/uip-setmacaddr.c
index 4b1e67530..969238362 100644
--- a/nuttx/netutils/uiplib/uip-setmacaddr.c
+++ b/nuttx/netutils/uiplib/uip-setmacaddr.c
@@ -43,10 +43,13 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+
#include <unistd.h>
#include <string.h>
#include <errno.h>
+
#include <netinet/in.h>
+#include <net/if.h>
#include <net/uip/uip-lib.h>
diff --git a/nuttx/netutils/uiplib/uip-setnetmask.c b/nuttx/netutils/uiplib/uip-setnetmask.c
index ff70e5a37..619a5e8fa 100644
--- a/nuttx/netutils/uiplib/uip-setnetmask.c
+++ b/nuttx/netutils/uiplib/uip-setnetmask.c
@@ -43,10 +43,13 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+
#include <unistd.h>
#include <string.h>
#include <errno.h>
+
#include <netinet/in.h>
+#include <net/if.h>
#include <net/uip/uip-lib.h>