From efd389f792aff35cb90b8b85b21eb5f7ff45fc63 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 22 Apr 2011 15:54:21 +0000 Subject: Minor RTL/WLAN update git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3531 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/wlan/wlan_main.c | 164 ++++++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 75 deletions(-) (limited to 'apps') diff --git a/apps/examples/wlan/wlan_main.c b/apps/examples/wlan/wlan_main.c index 9993e8deb..04210909a 100755 --- a/apps/examples/wlan/wlan_main.c +++ b/apps/examples/wlan/wlan_main.c @@ -122,14 +122,14 @@ static struct usbhost_driver_s *g_drvr; ****************************************************************************/ /**************************************************************************** - * Name: wlan_waiter + * Name: wlan_bringup * * Description: * Wait for USB devices to be connected. * ****************************************************************************/ -static int wlan_waiter(int argc, char *argv[]) +static inline void wlan_bringup(void) { #if defined(CONFIG_EXAMPLE_WLAN_DHCPC) || defined(CONFIG_EXAMPLE_WLAN_NOMAC) uint8_t mac[IFHWADDRLEN]; @@ -138,6 +138,92 @@ static int wlan_waiter(int argc, char *argv[]) #ifdef CONFIG_EXAMPLE_WLAN_DHCPC void *handle; #endif + + /* 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 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); + + /* 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); + +#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 +} + +/**************************************************************************** + * Name: wlan_waiter + * + * Description: + * Wait for USB devices to be connected. + * + ****************************************************************************/ + +static int wlan_waiter(int argc, char *argv[]) +{ bool connected = false; int ret; @@ -162,79 +248,7 @@ static int wlan_waiter(int argc, char *argv[]) /* 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 + wlan_bringup(); } } -- cgit v1.2.3