diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-16 22:12:04 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-16 22:12:04 +0000 |
commit | 9e15c4be04516ac9957f33ea179a188cc2a081a0 (patch) | |
tree | 77fe706483352a68b683ecde64215d54cbc89f4f /nuttx/include/net/uip | |
parent | 4077a70fc256a7dd65febe986f176b8ac62091fc (diff) | |
download | px4-nuttx-9e15c4be04516ac9957f33ea179a188cc2a081a0.tar.gz px4-nuttx-9e15c4be04516ac9957f33ea179a188cc2a081a0.tar.bz2 px4-nuttx-9e15c4be04516ac9957f33ea179a188cc2a081a0.zip |
Associate address with network driver; implement ioctl calls to set addresses
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@345 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include/net/uip')
-rw-r--r-- | nuttx/include/net/uip/uip-arch.h | 10 | ||||
-rw-r--r-- | nuttx/include/net/uip/uip-arp.h | 23 | ||||
-rw-r--r-- | nuttx/include/net/uip/uip.h | 137 | ||||
-rw-r--r-- | nuttx/include/net/uip/uipopt.h | 32 |
4 files changed, 38 insertions, 164 deletions
diff --git a/nuttx/include/net/uip/uip-arch.h b/nuttx/include/net/uip/uip-arch.h index e54956888..42e01cbcd 100644 --- a/nuttx/include/net/uip/uip-arch.h +++ b/nuttx/include/net/uip/uip-arch.h @@ -101,6 +101,16 @@ struct uip_driver_s char d_ifname[IFNAMSIZ]; #endif + /* Device identitity */ + + struct uip_eth_addr d_mac; /* Device MAC address */ + + /* Network identity */ + + uip_ipaddr_t d_ipaddr; /* Host IP address assigned to the network interface */ + uip_ipaddr_t d_draddr; /* Default router IP address */ + uip_ipaddr_t d_netmask; /* Network subnet mask */ + /* The d_buf array is used to hold incoming and outgoing * packets. The device driver should place incoming data into this * buffer. When sending data, the device driver should read the link diff --git a/nuttx/include/net/uip/uip-arp.h b/nuttx/include/net/uip/uip-arp.h index 3a697a3c5..e7c636357 100644 --- a/nuttx/include/net/uip/uip-arp.h +++ b/nuttx/include/net/uip/uip-arp.h @@ -37,8 +37,6 @@ #include <sys/types.h> #include <net/uip/uip.h> -extern struct uip_eth_addr uip_ethaddr; - /* The Ethernet header */ struct uip_eth_hdr @@ -97,25 +95,4 @@ void uip_arp_out(struct uip_driver_s *dev); void uip_arp_timer(void); -/* Specifiy the Ethernet MAC address. - * - * The ARP code needs to know the MAC address of the Ethernet card in - * order to be able to respond to ARP queries and to generate working - * Ethernet headers. - * - * Note: This macro only specifies the Ethernet MAC address to the ARP - * code. It cannot be used to change the MAC address of the Ethernet - * card. - * - * eaddr A pointer to a struct uip_eth_addr containing the - * Ethernet MAC address of the Ethernet card. - */ - -#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \ - uip_ethaddr.addr[1] = eaddr.addr[1];\ - uip_ethaddr.addr[2] = eaddr.addr[2];\ - uip_ethaddr.addr[3] = eaddr.addr[3];\ - uip_ethaddr.addr[4] = eaddr.addr[4];\ - uip_ethaddr.addr[5] = eaddr.addr[5];} while(0) - #endif /* __UIP_ARP_H__ */ diff --git a/nuttx/include/net/uip/uip.h b/nuttx/include/net/uip/uip.h index 740f01aa9..ed511f92e 100644 --- a/nuttx/include/net/uip/uip.h +++ b/nuttx/include/net/uip/uip.h @@ -141,7 +141,7 @@ /* Repressentation of an IP address. */ -typedef uint16 uip_ip4addr_t[2]; +typedef in_addr_t uip_ip4addr_t; typedef uint16 uip_ip6addr_t[8]; #ifdef CONFIG_NET_IPv6 @@ -282,12 +282,13 @@ struct uip_tcpip_hdr /* IPv6 header. */ - uint8 vtc; - uint8 tcflow; + uint8 vtc; + uint8 tcflow; uint16 flow; - uint8 len[2]; - uint8 proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; + uint8 len[2]; + uint8 proto, ttl; + uip_ip6addr_t srcipaddr; + uip_ip6addr_t destipaddr; #else /* CONFIG_NET_IPv6 */ @@ -301,8 +302,8 @@ struct uip_tcpip_hdr uint8 ttl; uint8 proto; uint16 ipchksum; - uint16 srcipaddr[2]; - uint16 destipaddr[2]; + in_addr_t srcipaddr; + in_addr_t destipaddr; #endif /* CONFIG_NET_IPv6 */ @@ -349,8 +350,8 @@ struct uip_icmpip_hdr uint8 ttl; uint8 proto; uint16 ipchksum; - uint16 srcipaddr[2]; - uint16 destipaddr[2]; + in_addr_t srcipaddr; + in_addr_t destipaddr; #endif /* CONFIG_NET_IPv6 */ @@ -405,8 +406,8 @@ struct uip_udpip_hdr uint8 ttl; uint8 proto; uint16 ipchksum; - uint16 srcipaddr[2]; - uint16 destipaddr[2]; + in_addr_t srcipaddr; + in_addr_t destipaddr; #endif /* CONFIG_NET_IPv6 */ @@ -483,88 +484,11 @@ extern struct uip_stats uip_stat; extern uint8 uip_flags; -#if UIP_FIXEDADDR -extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; -#else /* UIP_FIXEDADDR */ -extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; -#endif /* UIP_FIXEDADDR */ - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -/* uIP configuration functions - * - * The uIP configuration functions are used for setting run-time - * parameters in uIP such as IP addresses. - * - * Set the IP address of this host. - * - * The IP address is represented as a 4-byte array where the first - * octet of the IP address is put in the first member of the 4-byte - * array. - * - * Example: - * - * uip_ipaddr_t addr; - * - * uip_ipaddr(&addr, 192,168,1,2); - * uip_sethostaddr(&addr); - * - * addr A pointer to an IP address of type uip_ipaddr_t; - */ - -#define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr)) - -/* Get the IP address of this host. - * - * The IP address is represented as a 4-byte array where the first - * octet of the IP address is put in the first member of the 4-byte - * array. - * - * Example: - * - * uip_ipaddr_t hostaddr; - * - * uip_gethostaddr(&hostaddr); - * - * addr A pointer to a uip_ipaddr_t variable that will be - * filled in with the currently configured IP address. - */ - -#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr) - -/* Set the default router's IP address. - * - * addr A pointer to a uip_ipaddr_t variable containing the IP - * address of the default router. - */ - -#define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr)) - -/* Set the netmask. - * - * addr A pointer to a uip_ipaddr_t variable containing the IP - * address of the netmask. - */ - -#define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr)) - -/* Get the default router's IP address. - * - * addr A pointer to a uip_ipaddr_t variable that will be - * filled in with the IP address of the default router. - */ - -#define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr) - -/* Get the netmask. - * - * addr A pointer to a uip_ipaddr_t variable that will be - * filled in with the value of the netmask. - */ - -#define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask) +/* uIP configuration functions */ /* uIP initialization functions * @@ -906,8 +830,7 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); #define uip_ipaddr(addr, addr0, addr1, addr2, addr3) \ do { \ - ((uint16 *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ - ((uint16 *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ + addr = HTONL((addr0) << 24 | (addr1) << 16 | (addr2) << 8 | (addr3)); \ } while(0) /* Construct an IPv6 address from eight 16-bit words. @@ -942,12 +865,12 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); */ #ifndef CONFIG_NET_IPv6 -#define uip_ipaddr_copy(dest, src) do { \ - ((uint16 *)dest)[0] = ((uint16 *)src)[0]; \ - ((uint16 *)dest)[1] = ((uint16 *)src)[1]; \ - } while(0) +#define uip_ipaddr_copy(dest, src) \ + do { \ + (dest) = (in_addr_t)(src); \ + } while(0) #else /* !CONFIG_NET_IPv6 */ -#define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t)) +#define uip_ipaddr_copy(dest, src) memcpy(&dest, &src, sizeof(uip_ip6addr_t)) #endif /* !CONFIG_NET_IPv6 */ /* Compare two IP addresses @@ -972,8 +895,7 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) #endif /* !CONFIG_NET_IPv6 */ -/** - * Compare two IP addresses with netmasks +/* Compare two IP addresses with netmasks * * Compares two IP addresses with netmasks. The masks are used to mask * out the bits that are to be compared. @@ -995,14 +917,9 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); */ #define uip_ipaddr_maskcmp(addr1, addr2, mask) \ - (((((uint16 *)addr1)[0] & ((uint16 *)mask)[0]) == \ - (((uint16 *)addr2)[0] & ((uint16 *)mask)[0])) && \ - ((((uint16 *)addr1)[1] & ((uint16 *)mask)[1]) == \ - (((uint16 *)addr2)[1] & ((uint16 *)mask)[1]))) - + (((in_addr_t)addr1 & (in_addr_t)mask) == ((in_addr_t)addr2 & (in_addr_t)mask)) -/** - * Mask out the network part of an IP address. +/* Mask out the network part of an IP address. * * Masks out the network part of an IP address, given the address and * the netmask. @@ -1023,10 +940,10 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); * mask The netmask. */ -#define uip_ipaddr_mask(dest, src, mask) do { \ - ((uint16 *)dest)[0] = ((uint16 *)src)[0] & ((uint16 *)mask)[0]; \ - ((uint16 *)dest)[1] = ((uint16 *)src)[1] & ((uint16 *)mask)[1]; \ - } while(0) +#define uip_ipaddr_mask(dest, src, mask) \ + do { \ + (in_addr_t)(dest) = (in_addr_t)(src) & (in_addr_t)(mask); \ + } while(0) /* Pick the first octet of an IP address. * diff --git a/nuttx/include/net/uip/uipopt.h b/nuttx/include/net/uip/uipopt.h index a9a5b2840..3123a7135 100644 --- a/nuttx/include/net/uip/uipopt.h +++ b/nuttx/include/net/uip/uipopt.h @@ -69,26 +69,7 @@ * Public Type Definitions ****************************************************************************/ -/* Static configuration options - * - * These configuration options can be used for setting the IP address - * settings statically, but only if UIP_FIXEDADDR is set to 1. The - * configuration options for a specific node includes IP address, - * netmask and default router as well as the Ethernet address. The - * netmask, default router and Ethernet address are appliciable only - * if uIP should be run over Ethernet. - * - * All of these should be changed to suit your project. - */ - -/* Determines if uIP should use a fixed IP address or not. - * - * If uIP should use a fixed IP address, the settings are set in the - * uipopt.h file. If not, the macros uip_sethostaddr(), - * uip_setdraddr() and uip_setnetmask() should be used instead. - */ - -#define UIP_FIXEDADDR 0 +/* Static configuration options */ /* Ping IP address asignment. * @@ -96,8 +77,6 @@ * option is set. If so, uIP will start with an empty IP address and * the destination IP address of the first incoming "ping" (ICMP echo) * packet will be used for setting the hosts IP address. - * - * Note: This works only if UIP_FIXEDADDR is 0. */ #ifdef CONFIG_NET_PINGADDRCONF @@ -106,15 +85,6 @@ #define UIP_PINGADDRCONF 0 #endif /* CONFIG_NET_PINGADDRCONF */ -/* Specifies if the uIP ARP module should be compiled with a fixed - * Ethernet MAC address or not. - * - * If this configuration option is 0, the macro uip_setethaddr() can - * be used to specify the Ethernet address at run-time. - */ - -#define UIP_FIXEDETHADDR 0 - /* IP configuration options */ /* The IP TTL (time to live) of IP packets sent by uIP. |