mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 01:05:54 +08:00
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
This commit is contained in:
+3
-2
@@ -63,8 +63,9 @@
|
||||
#else
|
||||
# define HTONS(ns) \
|
||||
(uint16)((((uint16) (ns)) << 8) | (((uint16) (ns)) >> 8))
|
||||
# define HTONL(nl) htonl(nl) \
|
||||
(((uint32)HTONS((uint16)((hs) & 0xffff)) << 16) | (uint32)HTONS((uint16)((uint16)((hs) >> 16))))
|
||||
# define HTONL(nl) \
|
||||
((((nl) & 0xff) << 24) | (((nl) & 0xff00) << 8) | \
|
||||
(((nl) & 0xff0000) >> 8) | (((nl) & 0xff000000) >> 24))
|
||||
#endif
|
||||
|
||||
#define NTOHS(hs) HTONS(hs)
|
||||
|
||||
+14
-10
@@ -57,15 +57,17 @@
|
||||
|
||||
#define SIOCGIFADDR (_SIOCBASE|0x0001) /* Get IP address */
|
||||
#define SIOCSIFADDR (_SIOCBASE|0x0002) /* Set IP address */
|
||||
#define SIOCGIFBRDADDR (_SIOCBASE|0x0003) /* Get broadcast IP address */
|
||||
#define SIOCSIFBRDADDR (_SIOCBASE|0x0004) /* Set broadcast IP address */
|
||||
#define SIOCGIFNETMASK (_SIOCBASE|0x0005) /* Get network mask */
|
||||
#define SIOCSIFNETMASK (_SIOCBASE|0x0006) /* Set network mask */
|
||||
#define SIOCGIFMTU (_SIOCBASE|0x0007) /* Get MTU size */
|
||||
#define SIOCSIFHWADDR (_SIOCBASE|0x0008) /* Set hardware address */
|
||||
#define SIOCGIFHWADDR (_SIOCBASE|0x0009) /* Get hardware address */
|
||||
#define SIOCDIFADDR (_SIOCBASE|0x000a) /* Delete IP address */
|
||||
#define SIOCGIFCOUNT (_SIOCBASE|0x000b) /* Get number of devices */
|
||||
#define SIOCGIFDSTADDR (_SIOCBASE|0x0003) /* Get P-to-P address */
|
||||
#define SIOCSIFDSTADDR (_SIOCBASE|0x0004) /* Set P-to-P address */
|
||||
#define SIOCGIFBRDADDR (_SIOCBASE|0x0005) /* Get broadcast IP address */
|
||||
#define SIOCSIFBRDADDR (_SIOCBASE|0x0006) /* Set broadcast IP address */
|
||||
#define SIOCGIFNETMASK (_SIOCBASE|0x0007) /* Get network mask */
|
||||
#define SIOCSIFNETMASK (_SIOCBASE|0x0008) /* Set network mask */
|
||||
#define SIOCGIFMTU (_SIOCBASE|0x0009) /* Get MTU size */
|
||||
#define SIOCGIFHWADDR (_SIOCBASE|0x000a) /* Get hardware address */
|
||||
#define SIOCSIFHWADDR (_SIOCBASE|0x000b) /* Set hardware address */
|
||||
#define SIOCDIFADDR (_SIOCBASE|0x000c) /* Delete IP address */
|
||||
#define SIOCGIFCOUNT (_SIOCBASE|0x000d) /* Get number of devices */
|
||||
|
||||
/* Sizing parameters */
|
||||
|
||||
@@ -82,6 +84,7 @@ struct ifreq
|
||||
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 */
|
||||
@@ -90,7 +93,8 @@ struct ifreq
|
||||
} ifr_ifru;
|
||||
};
|
||||
|
||||
#define ifr_addr ifr_ifru.ifru_addr /* Address */
|
||||
#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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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__ */
|
||||
|
||||
+27
-110
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user