From ee5006097db23e9fc9dc085cad115fcd05ad63cf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 3 Jul 2014 17:53:16 -0600 Subject: NET: More renaming --- nuttx/arch/sim/src/Makefile | 2 +- nuttx/arch/sim/src/nuttx-names.dat | 72 ++++++------ nuttx/arch/sim/src/up_idle.c | 2 +- nuttx/arch/sim/src/up_initialize.c | 2 +- nuttx/arch/sim/src/up_internal.h | 8 +- nuttx/arch/sim/src/up_netdriver.c | 230 +++++++++++++++++++++++++++++++++++++ nuttx/arch/sim/src/up_tapdev.c | 22 ++-- nuttx/arch/sim/src/up_uipdriver.c | 230 ------------------------------------- nuttx/arch/sim/src/up_wpcap.c | 12 +- nuttx/net/netdev/netdev_carrier.c | 4 +- 10 files changed, 291 insertions(+), 293 deletions(-) create mode 100644 nuttx/arch/sim/src/up_netdriver.c delete mode 100644 nuttx/arch/sim/src/up_uipdriver.c diff --git a/nuttx/arch/sim/src/Makefile b/nuttx/arch/sim/src/Makefile index 02eda68bd..963c1b38e 100644 --- a/nuttx/arch/sim/src/Makefile +++ b/nuttx/arch/sim/src/Makefile @@ -73,7 +73,7 @@ CSRCS += up_romgetc.c endif ifeq ($(CONFIG_NET),y) -CSRCS += up_uipdriver.c +CSRCS += up_netdriver.c HOSTCFLAGS += -DNETDEV_BUFSIZE=$(CONFIG_NET_BUFSIZE) ifneq ($(HOSTOS),Cygwin) HOSTSRCS += up_tapdev.c up_netdev.c diff --git a/nuttx/arch/sim/src/nuttx-names.dat b/nuttx/arch/sim/src/nuttx-names.dat index 1acdb1a6c..0e8785067 100644 --- a/nuttx/arch/sim/src/nuttx-names.dat +++ b/nuttx/arch/sim/src/nuttx-names.dat @@ -1,36 +1,36 @@ -calloc NXcalloc -close NXclose -closedir NXclosedir -dup NXdup -free NXfree -fclose NXfclose -fopen NXfopen -fputc NXfputc -fread NXfread -fwrite NXfwrite -fsync NXfsync -gettimeofday NXgettimeofday -ioctl NXioctl -lseek NXlseek -malloc NXmalloc -malloc_init NXmalloc_init -mkdir NXmkdir -mount NXmount -open NXopen -opendir NXopendir -read NXread -realloc NXrealloc -rewinddir NXrewinddir -rmdir NXrmdir -seekdir NXseekdir -select NXselect -sleep NXsleep -socket NXsocket -stat NXstat -statfs NXstatfs -system NXsystem -umount NXumount -unlink NXunlink -usleep NXusleep -write NXwrite -zmalloc NXzmalloc +calloc NXcalloc +close NXclose +closedir NXclosedir +dup NXdup +free NXfree +fclose NXfclose +fopen NXfopen +fputc NXfputc +fread NXfread +fwrite NXfwrite +fsync NXfsync +gettimeofday NXgettimeofday +ioctl NXioctl +lseek NXlseek +malloc NXmalloc +malloc_init NXmalloc_init +mkdir NXmkdir +mount NXmount +open NXopen +opendir NXopendir +read NXread +realloc NXrealloc +rewinddir NXrewinddir +rmdir NXrmdir +seekdir NXseekdir +select NXselect +sleep NXsleep +socket NXsocket +stat NXstat +statfs NXstatfs +system NXsystem +umount NXumount +unlink NXunlink +usleep NXusleep +write NXwrite +zmalloc NXzmalloc diff --git a/nuttx/arch/sim/src/up_idle.c b/nuttx/arch/sim/src/up_idle.c index f493a2dbd..87b870e4c 100644 --- a/nuttx/arch/sim/src/up_idle.c +++ b/nuttx/arch/sim/src/up_idle.c @@ -103,7 +103,7 @@ void up_idle(void) /* Run the network if enabled */ #ifdef CONFIG_NET - uipdriver_loop(); + netdriver_loop(); #endif /* Fake some power management stuff for testing purposes */ diff --git a/nuttx/arch/sim/src/up_initialize.c b/nuttx/arch/sim/src/up_initialize.c index 38527aca8..b8409e0c2 100644 --- a/nuttx/arch/sim/src/up_initialize.c +++ b/nuttx/arch/sim/src/up_initialize.c @@ -128,6 +128,6 @@ void up_initialize(void) #endif #ifdef CONFIG_NET - uipdriver_init(); /* Our "real" network driver */ + netdriver_init(); /* Our "real" network driver */ #endif } diff --git a/nuttx/arch/sim/src/up_internal.h b/nuttx/arch/sim/src/up_internal.h index dff51b9cf..3d004f4d0 100644 --- a/nuttx/arch/sim/src/up_internal.h +++ b/nuttx/arch/sim/src/up_internal.h @@ -222,12 +222,12 @@ extern void wpcap_send(unsigned char *buf, unsigned int buflen); #define netdev_send(buf,buflen) wpcap_send(buf,buflen) #endif -/* up_uipdriver.c *********************************************************/ +/* up_netdriver.c *********************************************************/ #ifdef CONFIG_NET -extern int uipdriver_init(void); -extern int uipdriver_setmacaddr(unsigned char *macaddr); -extern void uipdriver_loop(void); +extern int netdriver_init(void); +extern int netdriver_setmacaddr(unsigned char *macaddr); +extern void netdriver_loop(void); #endif #endif /* __ASSEMBLY__ */ diff --git a/nuttx/arch/sim/src/up_netdriver.c b/nuttx/arch/sim/src/up_netdriver.c new file mode 100644 index 000000000..649b9afaf --- /dev/null +++ b/nuttx/arch/sim/src/up_netdriver.c @@ -0,0 +1,230 @@ +/**************************************************************************** + * arch/sim/src/up_netdriver.c + * + * Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Based on code from uIP which also has a BSD-like license: + * + * Copyright (c) 2001, Adam Dunkels. + * 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 NuttX 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_NET + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "up_internal.h" + +/**************************************************************************** + * Private Definitions + ****************************************************************************/ + +#define BUF ((struct ether_header*)g_sim_dev.d_buf) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct timer +{ + uint32_t interval; + uint32_t start; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct timer g_periodic_timer; +static struct net_driver_s g_sim_dev; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void timer_set(struct timer *t, unsigned int interval) +{ + t->interval = interval; + t->start = up_getwalltime(); +} + +static bool timer_expired( struct timer *t ) +{ + return (up_getwalltime() - t->start) >= t->interval; +} + +void timer_reset(struct timer *t) +{ + t->start += t->interval; +} + +#ifdef CONFIG_NET_PROMISCUOUS +# define up_comparemac(a,b) (0) +#else +static inline int up_comparemac(uint8_t *paddr1, struct ether_addr *paddr2) +{ + return memcmp(paddr1, paddr2->ether_addr_octet, ETHER_ADDR_LEN); +} +#endif + +static int sim_txpoll(struct net_driver_s *dev) +{ + /* If the polling resulted in data that should be sent out on the network, + * the field d_len is set to a value > 0. + */ + + if (g_sim_dev.d_len > 0) + { + arp_out(&g_sim_dev); + netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + } + + /* If zero is returned, the polling will continue until all connections have + * been examined. + */ + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void netdriver_loop(void) +{ + /* netdev_read will return 0 on a timeout event and >0 on a data received event */ + + g_sim_dev.d_len = netdev_read((unsigned char*)g_sim_dev.d_buf, CONFIG_NET_BUFSIZE); + + /* Disable preemption through to the following so that it behaves a little more + * like an interrupt (otherwise, the following logic gets pre-empted an behaves + * oddly. + */ + + sched_lock(); + if (g_sim_dev.d_len > 0) + { + /* Data received event. Check for valid Ethernet header with destination == our + * MAC address + */ + + if (g_sim_dev.d_len > UIP_LLH_LEN && up_comparemac(BUF->ether_dhost, &g_sim_dev.d_mac) == 0) + { + /* We only accept IP packets of the configured type and ARP packets */ + +#ifdef CONFIG_NET_IPv6 + if (BUF->ether_type == htons(UIP_ETHTYPE_IP6)) +#else + if (BUF->ether_type == htons(UIP_ETHTYPE_IP)) +#endif + { + arp_ipin(&g_sim_dev); + devif_input(&g_sim_dev); + + /* If the above function invocation resulted in data that + * should be sent out on the network, the global variable + * d_len is set to a value > 0. + */ + + if (g_sim_dev.d_len > 0) + { + arp_out(&g_sim_dev); + netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + } + } + else if (BUF->ether_type == htons(UIP_ETHTYPE_ARP)) + { + arp_arpin(&g_sim_dev); + + /* If the above function invocation resulted in data that + * should be sent out on the network, the global variable + * d_len is set to a value > 0. + */ + + if (g_sim_dev.d_len > 0) + { + netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + } + } + } + } + + /* Otherwise, it must be a timeout event */ + + else if (timer_expired(&g_periodic_timer)) + { + timer_reset(&g_periodic_timer); + devif_timer(&g_sim_dev, sim_txpoll, 1); + } + sched_unlock(); +} + +int netdriver_init(void) +{ + /* Internal initalization */ + + timer_set(&g_periodic_timer, 500); + netdev_init(); + + /* Register the device with the OS so that socket IOCTLs can be performed */ + + (void)netdev_register(&g_sim_dev); + return OK; +} + +int netdriver_setmacaddr(unsigned char *macaddr) +{ + (void)memcpy(g_sim_dev.d_mac.ether_addr_octet, macaddr, IFHWADDRLEN); + return 0; +} + +#endif /* CONFIG_NET */ + diff --git a/nuttx/arch/sim/src/up_tapdev.c b/nuttx/arch/sim/src/up_tapdev.c index 6805eae08..91166ceb1 100644 --- a/nuttx/arch/sim/src/up_tapdev.c +++ b/nuttx/arch/sim/src/up_tapdev.c @@ -62,7 +62,7 @@ #include extern int syslog(const char *format, ...); -extern int uipdriver_setmacaddr(unsigned char *macaddr); +extern int netdriver_setmacaddr(unsigned char *macaddr); /**************************************************************************** * Private Definitions @@ -73,15 +73,15 @@ extern int uipdriver_setmacaddr(unsigned char *macaddr); #define DEVTAP "/dev/net/tun" #ifndef CONFIG_EXAMPLES_WEBSERVER_DHCPC -# define UIP_IPADDR0 192 -# define UIP_IPADDR1 168 -# define UIP_IPADDR2 0 -# define UIP_IPADDR3 128 +# define TAP_IPADDR0 192 +# define TAP_IPADDR1 168 +# define TAP_IPADDR2 0 +# define TAP_IPADDR3 128 #else -# define UIP_IPADDR0 0 -# define UIP_IPADDR1 0 -# define UIP_IPADDR2 0 -# define UIP_IPADDR3 0 +# define TAP_IPADDR0 0 +# define TAP_IPADDR1 0 +# define TAP_IPADDR2 0 +# define TAP_IPADDR3 0 #endif /**************************************************************************** @@ -157,7 +157,7 @@ static int up_setmacaddr(void) { /* Set the MAC address */ - ret = uipdriver_setmacaddr(&req.ifr_hwaddr.sa_data); + ret = netdriver_setmacaddr(&req.ifr_hwaddr.sa_data); } } @@ -197,7 +197,7 @@ void tapdev_init(void) /* Assign an IPv4 address to the tap device */ snprintf(buf, sizeof(buf), "/sbin/ifconfig tap0 inet %d.%d.%d.%d\n", - UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3); + TAP_IPADDR0, TAP_IPADDR1, TAP_IPADDR2, TAP_IPADDR3); system(buf); /* Set the MAC address */ diff --git a/nuttx/arch/sim/src/up_uipdriver.c b/nuttx/arch/sim/src/up_uipdriver.c deleted file mode 100644 index 5c8d21f2c..000000000 --- a/nuttx/arch/sim/src/up_uipdriver.c +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** - * up_uipdriver.c - * - * Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Based on code from uIP which also has a BSD-like license: - * - * Copyright (c) 2001, Adam Dunkels. - * 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 NuttX 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#ifdef CONFIG_NET - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "up_internal.h" - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -#define BUF ((struct ether_header*)g_sim_dev.d_buf) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct timer -{ - uint32_t interval; - uint32_t start; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct timer g_periodic_timer; -static struct net_driver_s g_sim_dev; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void timer_set(struct timer *t, unsigned int interval) -{ - t->interval = interval; - t->start = up_getwalltime(); -} - -static bool timer_expired( struct timer *t ) -{ - return (up_getwalltime() - t->start) >= t->interval; -} - -void timer_reset(struct timer *t) -{ - t->start += t->interval; -} - -#ifdef CONFIG_NET_PROMISCUOUS -# define up_comparemac(a,b) (0) -#else -static inline int up_comparemac(uint8_t *paddr1, struct ether_addr *paddr2) -{ - return memcmp(paddr1, paddr2->ether_addr_octet, ETHER_ADDR_LEN); -} -#endif - -static int sim_txpoll(struct net_driver_s *dev) -{ - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ - - if (g_sim_dev.d_len > 0) - { - arp_out(&g_sim_dev); - netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); - } - - /* If zero is returned, the polling will continue until all connections have - * been examined. - */ - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void uipdriver_loop(void) -{ - /* netdev_read will return 0 on a timeout event and >0 on a data received event */ - - g_sim_dev.d_len = netdev_read((unsigned char*)g_sim_dev.d_buf, CONFIG_NET_BUFSIZE); - - /* Disable preemption through to the following so that it behaves a little more - * like an interrupt (otherwise, the following logic gets pre-empted an behaves - * oddly. - */ - - sched_lock(); - if (g_sim_dev.d_len > 0) - { - /* Data received event. Check for valid Ethernet header with destination == our - * MAC address - */ - - if (g_sim_dev.d_len > UIP_LLH_LEN && up_comparemac(BUF->ether_dhost, &g_sim_dev.d_mac) == 0) - { - /* We only accept IP packets of the configured type and ARP packets */ - -#ifdef CONFIG_NET_IPv6 - if (BUF->ether_type == htons(UIP_ETHTYPE_IP6)) -#else - if (BUF->ether_type == htons(UIP_ETHTYPE_IP)) -#endif - { - arp_ipin(&g_sim_dev); - devif_input(&g_sim_dev); - - /* If the above function invocation resulted in data that - * should be sent out on the network, the global variable - * d_len is set to a value > 0. - */ - - if (g_sim_dev.d_len > 0) - { - arp_out(&g_sim_dev); - netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); - } - } - else if (BUF->ether_type == htons(UIP_ETHTYPE_ARP)) - { - arp_arpin(&g_sim_dev); - - /* If the above function invocation resulted in data that - * should be sent out on the network, the global variable - * d_len is set to a value > 0. - */ - - if (g_sim_dev.d_len > 0) - { - netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); - } - } - } - } - - /* Otherwise, it must be a timeout event */ - - else if (timer_expired(&g_periodic_timer)) - { - timer_reset(&g_periodic_timer); - devif_timer(&g_sim_dev, sim_txpoll, 1); - } - sched_unlock(); -} - -int uipdriver_init(void) -{ - /* Internal initalization */ - - timer_set(&g_periodic_timer, 500); - netdev_init(); - - /* Register the device with the OS so that socket IOCTLs can be performed */ - - (void)netdev_register(&g_sim_dev); - return OK; -} - -int uipdriver_setmacaddr(unsigned char *macaddr) -{ - (void)memcpy(g_sim_dev.d_mac.ether_addr_octet, macaddr, IFHWADDRLEN); - return 0; -} - -#endif /* CONFIG_NET */ - diff --git a/nuttx/arch/sim/src/up_wpcap.c b/nuttx/arch/sim/src/up_wpcap.c index 15cfcb406..87f376e70 100644 --- a/nuttx/arch/sim/src/up_wpcap.c +++ b/nuttx/arch/sim/src/up_wpcap.c @@ -54,18 +54,16 @@ #include #include -extern int uipdriver_setmacaddr(unsigned char *macaddr); +extern int netdriver_setmacaddr(unsigned char *macaddr); /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define BUF ((struct eth_hdr_s *)&uip_buf[0]) - #ifndef CONFIG_EXAMPLES_WEBSERVER_DHCPC -# define UIP_IPADDR (10 << 24 | 0 << 16 | 0 << 8 | 1) +# define WCAP_IPADDR (10 << 24 | 0 << 16 | 0 << 8 | 1) #else -# define UIP_IPADDR (0) +# define WCAP_IPADDR (0) #endif /**************************************************************************** @@ -231,7 +229,7 @@ static void set_ethaddr(struct in_addr addr) adapters->PhysicalAddress[2], adapters->PhysicalAddress[3], adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]); - (void)uipdriver_setmacaddr(adapters->PhysicalAddress); + (void)netdriver_setmacaddr(adapters->PhysicalAddress); break; } } @@ -253,7 +251,7 @@ void wpcap_init(void) struct in_addr addr; FARPROC dlladdr; - addr.s_addr = htonl(UIP_IPADDR); + addr.s_addr = htonl(WCAP_IPADDR); printf("wpcap_init: IP address: %s\n", inet_ntoa(addr)); wpcap = LoadLibrary("wpcap.dll"); diff --git a/nuttx/net/netdev/netdev_carrier.c b/nuttx/net/netdev/netdev_carrier.c index fb2dead4f..1f026db33 100644 --- a/nuttx/net/netdev/netdev_carrier.c +++ b/nuttx/net/netdev/netdev_carrier.c @@ -82,7 +82,7 @@ * Function: netdev_carrier_on * * Description: - * Notifies the uip layer about an available carrier. + * Notifies the networking layer about an available carrier. * (e.g. a cable was plugged in) * * Parameters: @@ -108,7 +108,7 @@ int netdev_carrier_on(FAR struct net_driver_s *dev) * Function: netdev_carrier_off * * Description: - * Notifies the uip layer about an disappeared carrier. + * Notifies the networking layer about an disappeared carrier. * (e.g. a cable was unplugged) * * Parameters: -- cgit v1.2.3