summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-21 19:03:01 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-21 19:03:01 +0000
commitae5e7206272501ea7f694cbf7486c29ba4787d7d (patch)
tree3f0714b80d042cc8c3041afa18bd4705c35e236a
parent87b4b06d09f0a188286304756f84019e4c177922 (diff)
downloadnuttx-ae5e7206272501ea7f694cbf7486c29ba4787d7d.tar.gz
nuttx-ae5e7206272501ea7f694cbf7486c29ba4787d7d.tar.bz2
nuttx-ae5e7206272501ea7f694cbf7486c29ba4787d7d.zip
Add logic to assign IP address in apps/examples/wlan
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3530 42af7a65-404d-4744-a932-0658087f49c3
-rwxr-xr-xapps/examples/wlan/wlan_main.c104
-rw-r--r--nuttx/configs/detron/wlan/appconfig4
-rwxr-xr-xnuttx/configs/detron/wlan/defconfig9
-rw-r--r--nuttx/configs/olimex-lpc1766stk/nettest/appconfig1
-rw-r--r--nuttx/configs/olimex-lpc1766stk/wlan/appconfig3
-rwxr-xr-xnuttx/configs/olimex-lpc1766stk/wlan/defconfig9
6 files changed, 128 insertions, 2 deletions
diff --git a/apps/examples/wlan/wlan_main.c b/apps/examples/wlan/wlan_main.c
index 652d8269c..9993e8deb 100755
--- a/apps/examples/wlan/wlan_main.c
+++ b/apps/examples/wlan/wlan_main.c
@@ -42,15 +42,34 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <time.h>
#include <sched.h>
#include <errno.h>
+#include <debug.h>
#include <nuttx/usb/usbhost.h>
+#include <net/if.h>
+#include <net/uip/uip.h>
+#include <net/uip/uip-arp.h>
+
+#include <apps/netutils/uiplib.h>
+
+/* DHCPC may be used in conjunction with any other feature (or not) */
+
+#ifdef CONFIG_EXAMPLE_WLAN_DHCPC
+# include <arpa/inet.h>
+# include <apps/netutils/resolv.h>
+# include <apps/netutils/dhcpc.h>
+#endif
+
/****************************************************************************
* Definitions
****************************************************************************/
@@ -112,6 +131,13 @@ static struct usbhost_driver_s *g_drvr;
static int wlan_waiter(int argc, char *argv[])
{
+#if defined(CONFIG_EXAMPLE_WLAN_DHCPC) || defined(CONFIG_EXAMPLE_WLAN_NOMAC)
+ uint8_t mac[IFHWADDRLEN];
+#endif
+ struct in_addr addr;
+#ifdef CONFIG_EXAMPLE_WLAN_DHCPC
+ void *handle;
+#endif
bool connected = false;
int ret;
@@ -132,7 +158,83 @@ static int wlan_waiter(int argc, char *argv[])
{
/* Yes.. enumerate the newly connected device */
- (void)DRVR_ENUMERATE(g_drvr);
+ ret = DRVR_ENUMERATE(g_drvr);
+
+ /* If the enumeration was successful, then bring up the interface */
+
+ /* Many embedded network interfaces must have a software assigned
+ * MAC
+ */
+
+#ifdef CONFIG_EXAMPLE_WLAN_NOMAC
+ mac[0] = 0x00;
+ mac[1] = 0xe0;
+ mac[2] = 0xb0;
+ mac[3] = 0x0b;
+ mac[4] = 0xba;
+ mac[5] = 0xbe;
+ uip_setmacaddr("eth0", mac);
+#endif
+
+ /* Set up our host address */
+
+#ifdef CONFIG_EXAMPLE_WLAN_DHCPC
+ addr.s_addr = 0;
+#else
+ addr.s_addr = HTONL(CONFIG_EXAMPLE_WLAN_IPADDR);
+#endif
+ uip_sethostaddr("eth0", &addr);
+
+ /* Set up the default router address */
+
+ addr.s_addr = HTONL(CONFIG_EXAMPLE_WLAN_DRIPADDR);
+ uip_setdraddr("eth0", &addr);
+
+ /* Setup the subnet mask */
+
+ addr.s_addr = HTONL(CONFIG_EXAMPLE_WLAN_NETMASK);
+ uip_setnetmask("eth0", &addr);
+
+#ifdef CONFIG_EXAMPLE_WLAN_DHCPC
+ /* Set up the resolver */
+
+ resolv_init();
+
+ /* Get the MAC address of the NIC */
+
+ uip_getmacaddr("eth0", mac);
+
+ /* Set up the DHCPC modules */
+
+ handle = dhcpc_open(&mac, IFHWADDRLEN);
+
+ /* Get an IP address. Note: there is no logic here for renewing
+ * the address in this example. The address should be renewed in
+ * ds.lease_time/2 seconds.
+ */
+
+ printf("Getting IP address\n");
+ if (handle)
+ {
+ struct dhcpc_state ds;
+ (void)dhcpc_request(handle, &ds);
+ uip_sethostaddr("eth1", &ds.ipaddr);
+ if (ds.netmask.s_addr != 0)
+ {
+ uip_setnetmask("eth0", &ds.netmask);
+ }
+ if (ds.default_router.s_addr != 0)
+ {
+ uip_setdraddr("eth0", &ds.default_router);
+ }
+ if (ds.dnsaddr.s_addr != 0)
+ {
+ resolv_conf(&ds.dnsaddr);
+ }
+ dhcpc_close(handle);
+ printf("IP: %s\n", inet_ntoa(ds.ipaddr));
+ }
+#endif
}
}
diff --git a/nuttx/configs/detron/wlan/appconfig b/nuttx/configs/detron/wlan/appconfig
index d52942049..d08f73002 100644
--- a/nuttx/configs/detron/wlan/appconfig
+++ b/nuttx/configs/detron/wlan/appconfig
@@ -37,3 +37,7 @@
CONFIGURED_APPS += examples/wlan
+# Networking support
+
+CONFIGURED_APPS += netutils/uiplib
+
diff --git a/nuttx/configs/detron/wlan/defconfig b/nuttx/configs/detron/wlan/defconfig
index 6ab071b01..bb55832aa 100755
--- a/nuttx/configs/detron/wlan/defconfig
+++ b/nuttx/configs/detron/wlan/defconfig
@@ -768,6 +768,15 @@ CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
#
+# Settings for apps/examples/wlan
+#
+CONFIG_EXAMPLE_WLAN_DHCPC=n
+CONFIG_EXAMPLE_WLAN_NOMAC=n
+CONFIG_EXAMPLE_WLAN_IPADDR=(192<<24|168<<16|0<<8|201)
+CONFIG_EXAMPLE_WLAN_DRIPADDR=(192<<24|168<<16|0<<8|1)
+CONFIG_EXAMPLE_WLAN_NETMASK=(255<<24|255<<16|255<<8|0)
+
+#
# Settings for examples/ostest
#
CONFIG_EXAMPLES_OSTEST_LOOPS=1
diff --git a/nuttx/configs/olimex-lpc1766stk/nettest/appconfig b/nuttx/configs/olimex-lpc1766stk/nettest/appconfig
index d90b6e2e9..11b02d4c9 100644
--- a/nuttx/configs/olimex-lpc1766stk/nettest/appconfig
+++ b/nuttx/configs/olimex-lpc1766stk/nettest/appconfig
@@ -37,7 +37,6 @@
CONFIGURED_APPS += examples/nettest
-
# Networking support
CONFIGURED_APPS += netutils/uiplib
diff --git a/nuttx/configs/olimex-lpc1766stk/wlan/appconfig b/nuttx/configs/olimex-lpc1766stk/wlan/appconfig
index 652db8f2d..17055072a 100644
--- a/nuttx/configs/olimex-lpc1766stk/wlan/appconfig
+++ b/nuttx/configs/olimex-lpc1766stk/wlan/appconfig
@@ -37,3 +37,6 @@
CONFIGURED_APPS += examples/wlan
+# Networking support
+
+CONFIGURED_APPS += netutils/uiplib
diff --git a/nuttx/configs/olimex-lpc1766stk/wlan/defconfig b/nuttx/configs/olimex-lpc1766stk/wlan/defconfig
index 02b639bef..53a5f02af 100755
--- a/nuttx/configs/olimex-lpc1766stk/wlan/defconfig
+++ b/nuttx/configs/olimex-lpc1766stk/wlan/defconfig
@@ -767,6 +767,15 @@ CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
#
+# Settings for apps/examples/wlan
+#
+CONFIG_EXAMPLE_WLAN_DHCPC=n
+CONFIG_EXAMPLE_WLAN_NOMAC=n
+CONFIG_EXAMPLE_WLAN_IPADDR=(192<<24|168<<16|0<<8|201)
+CONFIG_EXAMPLE_WLAN_DRIPADDR=(192<<24|168<<16|0<<8|1)
+CONFIG_EXAMPLE_WLAN_NETMASK=(255<<24|255<<16|255<<8|0)
+
+#
# Settings for examples/ostest
#
CONFIG_EXAMPLES_OSTEST_LOOPS=1