dhcpc debug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@357 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
00093c0a08
commit
105aa81d1f
@ -113,7 +113,7 @@ extern char *up_deviceimage(void);
|
|||||||
extern unsigned long up_getwalltime( void );
|
extern unsigned long up_getwalltime( void );
|
||||||
extern void tapdev_init(void);
|
extern void tapdev_init(void);
|
||||||
extern unsigned int tapdev_read(unsigned char *buf, unsigned int buflen);
|
extern unsigned int tapdev_read(unsigned char *buf, unsigned int buflen);
|
||||||
extern void tapdev_send(char *buf, unsigned int buflen);
|
extern void tapdev_send(unsigned char *buf, unsigned int buflen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* up_uipdriver.c *********************************************************/
|
/* up_uipdriver.c *********************************************************/
|
||||||
|
@ -85,6 +85,17 @@ extern int lib_rawprintf(const char *format, ...);
|
|||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Warning: This is very much Linux version specific! */
|
||||||
|
|
||||||
|
struct sel_arg_struct
|
||||||
|
{
|
||||||
|
unsigned long n;
|
||||||
|
fd_set *inp;
|
||||||
|
fd_set *outp;
|
||||||
|
fd_set *exp;
|
||||||
|
struct timeval *tvp;
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -156,19 +167,35 @@ static inline int up_ioctl(int fd, unsigned int cmd, unsigned long arg)
|
|||||||
return (int)result;
|
return (int)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int up_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval *tvp)
|
static inline int up_select(struct sel_arg_struct *arg)
|
||||||
{
|
{
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
|
|
||||||
__asm__ volatile ("int $0x80" \
|
__asm__ volatile ("int $0x80" \
|
||||||
: "=a" (result) \
|
: "=a" (result) \
|
||||||
: "0" (SELECT),"b" ((long)(n)),"c" ((long)(inp)), \
|
: "0" (SELECT),"b" ((struct sel_arg_struct *)(arg))
|
||||||
"d" ((long)(outp)),"S" ((long)(exp)), "D"((long)tvp) \
|
|
||||||
: "memory");
|
: "memory");
|
||||||
|
|
||||||
return (int)result;
|
return (int)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TAPDEV_DEBUG
|
||||||
|
static inline void dump_ethhdr(const char *msg, unsigned char *buf, int buflen)
|
||||||
|
{
|
||||||
|
lib_rawprintf("TAPDEV: %s %d bytes\n", msg, buflen);
|
||||||
|
lib_rawprintf(" %02x:%02x:%02x:%02x:%02x:%02x %02x:%02x:%02x:%02x:%02x:%02x %02x%02x\n",
|
||||||
|
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
|
||||||
|
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
|
||||||
|
#if UIP_BYTE_ORDER == UIP_LITTLE_ENDIAN
|
||||||
|
buf[12], buf[13]);
|
||||||
|
#else
|
||||||
|
buf[13], buf[12]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define dump_ethhdr(m,b,l)
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -197,7 +224,7 @@ void tapdev_init(void)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
|
ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
|
||||||
ret = up_ioctl(gtapdevfd, TUNSETIFF, (unsigned long *) &ifr);
|
ret = up_ioctl(gtapdevfd, TUNSETIFF, (unsigned long) &ifr);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
lib_rawprintf("TAPDEV: ioctl failed: %d\n", -ret );
|
lib_rawprintf("TAPDEV: ioctl failed: %d\n", -ret );
|
||||||
@ -213,23 +240,33 @@ void tapdev_init(void)
|
|||||||
|
|
||||||
unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
|
unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
|
||||||
{
|
{
|
||||||
|
struct sel_arg_struct arg;
|
||||||
fd_set fdset;
|
fd_set fdset;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* We can't do anything if we failed to open the tap device */
|
/* We can't do anything if we failed to open the tap device */
|
||||||
|
|
||||||
if (gtapdevfd < 0)
|
if (gtapdevfd < 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Wait for data on the tap device (or a timeout) */
|
||||||
|
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 1000;
|
tv.tv_usec = 1000;
|
||||||
|
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
FD_SET(gtapdevfd, &fdset);
|
FD_SET(gtapdevfd, &fdset);
|
||||||
|
|
||||||
ret = up_select(gtapdevfd + 1, &fdset, NULL, NULL, &tv);
|
arg.n = gtapdevfd + 1;
|
||||||
|
arg.inp = &fdset;
|
||||||
|
arg.outp = NULL;
|
||||||
|
arg.exp = NULL;
|
||||||
|
arg.tvp = &tv;
|
||||||
|
|
||||||
|
ret = up_select(&arg);
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@ -242,22 +279,11 @@ unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TAPDEV_DEBUG
|
dump_ethhdr("read", buf, ret);
|
||||||
lib_rawprintf("TAPDEV: read %d bytes\n", ret);
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < 20; i++)
|
|
||||||
{
|
|
||||||
lib_rawprintf("%02x ", buf[i]);
|
|
||||||
}
|
|
||||||
lib_rawprintf("\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tapdev_send(char *buf, unsigned int buflen)
|
void tapdev_send(unsigned char *buf, unsigned int buflen)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef TAPDEV_DEBUG
|
#ifdef TAPDEV_DEBUG
|
||||||
@ -274,9 +300,10 @@ void tapdev_send(char *buf, unsigned int buflen)
|
|||||||
ret = up_write(gtapdevfd, buf, buflen);
|
ret = up_write(gtapdevfd, buf, buflen);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
lib_rawprintf("TAPDEV: write");
|
lib_rawprintf("TAPDEV: write failed: %d", -ret);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
dump_ethhdr("write", buf, buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* linux */
|
#endif /* linux */
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sched.h>
|
||||||
#include <nuttx/net.h>
|
#include <nuttx/net.h>
|
||||||
|
|
||||||
#include <net/uip/uip.h>
|
#include <net/uip/uip.h>
|
||||||
@ -102,6 +104,15 @@ void timer_reset(struct timer *t)
|
|||||||
t->start += t->interval;
|
t->start += t->interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_PROMISCUOUS
|
||||||
|
# define uipdriver_comparemac(a,b) (0)
|
||||||
|
#else
|
||||||
|
static inline int uip_comparemac(struct uip_eth_addr *paddr1, struct uip_eth_addr *paddr2)
|
||||||
|
{
|
||||||
|
return memcmp(paddr1, paddr2, sizeof(struct uip_eth_addr));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -110,10 +121,31 @@ void uipdriver_loop(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* tapdev_read will return 0 on a timeout event and >0 on a data received event */
|
||||||
|
|
||||||
g_sim_dev.d_len = tapdev_read((unsigned char*)g_sim_dev.d_buf, UIP_BUFSIZE);
|
g_sim_dev.d_len = tapdev_read((unsigned char*)g_sim_dev.d_buf, UIP_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)
|
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 && uip_comparemac( &BUF->dest, &g_sim_dev.d_mac) == 0)
|
||||||
|
{
|
||||||
|
/* We only accept IP packets of the configured type and ARP packets */
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
if (BUF->type == htons(UIP_ETHTYPE_IP6))
|
||||||
|
#else
|
||||||
if (BUF->type == htons(UIP_ETHTYPE_IP))
|
if (BUF->type == htons(UIP_ETHTYPE_IP))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
uip_arp_ipin();
|
uip_arp_ipin();
|
||||||
uip_input(&g_sim_dev);
|
uip_input(&g_sim_dev);
|
||||||
@ -126,7 +158,7 @@ void uipdriver_loop(void)
|
|||||||
if (g_sim_dev.d_len > 0)
|
if (g_sim_dev.d_len > 0)
|
||||||
{
|
{
|
||||||
uip_arp_out(&g_sim_dev);
|
uip_arp_out(&g_sim_dev);
|
||||||
tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len);
|
tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
|
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
|
||||||
@ -140,10 +172,14 @@ void uipdriver_loop(void)
|
|||||||
|
|
||||||
if (g_sim_dev.d_len > 0)
|
if (g_sim_dev.d_len > 0)
|
||||||
{
|
{
|
||||||
tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len);
|
tapdev_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))
|
else if (timer_expired(&g_periodic_timer))
|
||||||
{
|
{
|
||||||
timer_reset(&g_periodic_timer);
|
timer_reset(&g_periodic_timer);
|
||||||
@ -159,7 +195,7 @@ void uipdriver_loop(void)
|
|||||||
if (g_sim_dev.d_len > 0)
|
if (g_sim_dev.d_len > 0)
|
||||||
{
|
{
|
||||||
uip_arp_out(&g_sim_dev);
|
uip_arp_out(&g_sim_dev);
|
||||||
tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len);
|
tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +212,7 @@ void uipdriver_loop(void)
|
|||||||
if (g_sim_dev.d_len > 0)
|
if (g_sim_dev.d_len > 0)
|
||||||
{
|
{
|
||||||
uip_arp_out(&g_sim_dev);
|
uip_arp_out(&g_sim_dev);
|
||||||
tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len);
|
tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_NET_UDP */
|
#endif /* CONFIG_NET_UDP */
|
||||||
@ -189,6 +225,7 @@ void uipdriver_loop(void)
|
|||||||
uip_arp_timer();
|
uip_arp_timer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sched_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
int uipdriver_init(void)
|
int uipdriver_init(void)
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
* our project as defined in the config/<board-name>/defconfig file
|
* our project as defined in the config/<board-name>/defconfig file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CONFIG_EXAMPLE_UIP_WEBSERVER 1 /* For now */
|
#define CONFIG_EXAMPLE_UIP_DHCPC 1 /* For now */
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLE_UIP_SMTP)
|
#if defined(CONFIG_EXAMPLE_UIP_SMTP)
|
||||||
# include <net/uip/smtp.h>
|
# include <net/uip/smtp.h>
|
||||||
@ -135,6 +135,7 @@ int user_start(int argc, char *argv[])
|
|||||||
uip_getmacaddr("eth0", mac);
|
uip_getmacaddr("eth0", mac);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CONFIG_EXAMPLE_UIP_DHCPC)
|
||||||
/* Set up our host address */
|
/* Set up our host address */
|
||||||
|
|
||||||
uip_ipaddr(addr.s_addr, 192, 168, 0, 128 );
|
uip_ipaddr(addr.s_addr, 192, 168, 0, 128 );
|
||||||
@ -149,6 +150,7 @@ int user_start(int argc, char *argv[])
|
|||||||
|
|
||||||
uip_ipaddr(addr.s_addr, 255, 255, 255, 0);
|
uip_ipaddr(addr.s_addr, 255, 255, 255, 0);
|
||||||
uip_setnetmask("eth0", &addr);
|
uip_setnetmask("eth0", &addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLE_UIP_WEBSERVER)
|
#if defined(CONFIG_EXAMPLE_UIP_WEBSERVER)
|
||||||
httpd_init();
|
httpd_init();
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
#define UIP_PROTO_UDP 17
|
#define UIP_PROTO_UDP 17
|
||||||
#define UIP_PROTO_ICMP6 58
|
#define UIP_PROTO_ICMP6 58
|
||||||
|
|
||||||
/* Header sizes. */
|
/* Header sizes */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
# define UIP_IPH_LEN 40
|
# define UIP_IPH_LEN 40
|
||||||
@ -302,8 +302,8 @@ struct uip_tcpip_hdr
|
|||||||
uint8 ttl;
|
uint8 ttl;
|
||||||
uint8 proto;
|
uint8 proto;
|
||||||
uint16 ipchksum;
|
uint16 ipchksum;
|
||||||
in_addr_t srcipaddr;
|
uint16 srcipaddr[2];
|
||||||
in_addr_t destipaddr;
|
uint16 destipaddr[2];
|
||||||
|
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
@ -350,8 +350,8 @@ struct uip_icmpip_hdr
|
|||||||
uint8 ttl;
|
uint8 ttl;
|
||||||
uint8 proto;
|
uint8 proto;
|
||||||
uint16 ipchksum;
|
uint16 ipchksum;
|
||||||
in_addr_t srcipaddr;
|
uint16 srcipaddr[2];
|
||||||
in_addr_t destipaddr;
|
uint16 destipaddr[2];
|
||||||
|
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
@ -406,8 +406,8 @@ struct uip_udpip_hdr
|
|||||||
uint8 ttl;
|
uint8 ttl;
|
||||||
uint8 proto;
|
uint8 proto;
|
||||||
uint16 ipchksum;
|
uint16 ipchksum;
|
||||||
in_addr_t srcipaddr;
|
uint16 srcipaddr[2];
|
||||||
in_addr_t destipaddr;
|
uint16 destipaddr[2];
|
||||||
|
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
@ -833,20 +833,28 @@ extern void uip_udpdisable(struct uip_udp_conn *conn);
|
|||||||
addr = HTONL((addr0) << 24 | (addr1) << 16 | (addr2) << 8 | (addr3)); \
|
addr = HTONL((addr0) << 24 | (addr1) << 16 | (addr2) << 8 | (addr3)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
/* Convert an IPv4 address of the form uint16[2] to an in_addr_t */
|
||||||
|
|
||||||
|
#ifdef CONFIG_ENDIAN_BIG
|
||||||
|
# define uip_ip4addr_conv(addr) (((in_addr_t)((uint16*)addr)[1] << 16) | (in_addr_t)((uint16*)addr)[0])
|
||||||
|
#else
|
||||||
|
# define uip_ip4addr_conv(addr) (((in_addr_t)((uint16*)addr)[0] << 16) | (in_addr_t)((uint16*)addr)[1])
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Construct an IPv6 address from eight 16-bit words.
|
/* Construct an IPv6 address from eight 16-bit words.
|
||||||
*
|
*
|
||||||
* This function constructs an IPv6 address.
|
* This function constructs an IPv6 address.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
|
#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
|
||||||
((uint16 *)(addr))[0] = HTONS((addr0)); \
|
((uint16*)(addr))[0] = HTONS((addr0)); \
|
||||||
((uint16 *)(addr))[1] = HTONS((addr1)); \
|
((uint16*)(addr))[1] = HTONS((addr1)); \
|
||||||
((uint16 *)(addr))[2] = HTONS((addr2)); \
|
((uint16*)(addr))[2] = HTONS((addr2)); \
|
||||||
((uint16 *)(addr))[3] = HTONS((addr3)); \
|
((uint16*)(addr))[3] = HTONS((addr3)); \
|
||||||
((uint16 *)(addr))[4] = HTONS((addr4)); \
|
((uint16*)(addr))[4] = HTONS((addr4)); \
|
||||||
((uint16 *)(addr))[5] = HTONS((addr5)); \
|
((uint16*)(addr))[5] = HTONS((addr5)); \
|
||||||
((uint16 *)(addr))[6] = HTONS((addr6)); \
|
((uint16*)(addr))[6] = HTONS((addr6)); \
|
||||||
((uint16 *)(addr))[7] = HTONS((addr7)); \
|
((uint16*)(addr))[7] = HTONS((addr7)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/* Copy an IP address to another IP address.
|
/* Copy an IP address to another IP address.
|
||||||
@ -865,12 +873,18 @@ extern void uip_udpdisable(struct uip_udp_conn *conn);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CONFIG_NET_IPv6
|
#ifndef CONFIG_NET_IPv6
|
||||||
#define uip_ipaddr_copy(dest, src) \
|
# define uip_ipaddr_copy(dest, src) \
|
||||||
do { \
|
do { \
|
||||||
(dest) = (in_addr_t)(src); \
|
(dest) = (in_addr_t)(src); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
# define uiphdr_ipaddr_copy(dest, src) \
|
||||||
|
do { \
|
||||||
|
((uint16*)(dest))[0] = ((uint16*)(src))[0]; \
|
||||||
|
((uint16*)(dest))[1] = ((uint16*)(src))[1]; \
|
||||||
|
} while(0)
|
||||||
#else /* !CONFIG_NET_IPv6 */
|
#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))
|
||||||
|
# define uiphdr_ipaddr_copy(dest, src) uip_ipaddr_copy(dest, src)
|
||||||
#endif /* !CONFIG_NET_IPv6 */
|
#endif /* !CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
/* Compare two IP addresses
|
/* Compare two IP addresses
|
||||||
@ -890,8 +904,10 @@ extern void uip_udpdisable(struct uip_udp_conn *conn);
|
|||||||
|
|
||||||
#ifndef CONFIG_NET_IPv6
|
#ifndef CONFIG_NET_IPv6
|
||||||
# define uip_ipaddr_cmp(addr1, addr2) (addr1 == addr2)
|
# define uip_ipaddr_cmp(addr1, addr2) (addr1 == addr2)
|
||||||
|
# define uiphdr_ipaddr_cmp(addr1, addr2) uip_ipaddr_cmp(uip_ip4addr_conv(addr1), uip_ip4addr_conv(addr2))
|
||||||
#else /* !CONFIG_NET_IPv6 */
|
#else /* !CONFIG_NET_IPv6 */
|
||||||
# define uip_ipaddr_cmp(addr1, addr2) (memcmp(&addr1, &addr2, sizeof(uip_ip6addr_t)) == 0)
|
# define uip_ipaddr_cmp(addr1, addr2) (memcmp(&addr1, &addr2, sizeof(uip_ip6addr_t)) == 0)
|
||||||
|
# define uiphdr_ipaddr_cmp(addr1, addr2) uip_ipaddr_cmp(addr, addr2)
|
||||||
#endif /* !CONFIG_NET_IPv6 */
|
#endif /* !CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
/* Compare two IP addresses with netmasks
|
/* Compare two IP addresses with netmasks
|
||||||
@ -915,8 +931,11 @@ extern void uip_udpdisable(struct uip_udp_conn *conn);
|
|||||||
* mask The netmask.
|
* mask The netmask.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define uip_ipaddr_maskcmp(addr1, addr2, mask) \
|
#ifndef CONFIG_NET_IPv6
|
||||||
(((in_addr_t)addr1 & (in_addr_t)mask) == ((in_addr_t)addr2 & (in_addr_t)mask))
|
# define uip_ipaddr_maskcmp(addr1, addr2, mask) \
|
||||||
|
((uip_ip4addr_conv(addr1) & (in_addr_t)mask) == ((in_addr_t)addr2 & (in_addr_t)mask))
|
||||||
|
#else /* !CONFIG_NET_IPv6 */
|
||||||
|
#endif /* !CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
/* Mask out the network part of an IP address.
|
/* Mask out the network part of an IP address.
|
||||||
*
|
*
|
||||||
|
@ -217,7 +217,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
/* Get the connection reference from the socket */
|
/* Get the connection reference from the socket */
|
||||||
|
|
||||||
conn = psock->s_conn;
|
conn = psock->s_conn;
|
||||||
if (conn) /* Should alwasy be non-NULL */
|
if (conn) /* Should always be non-NULL */
|
||||||
{
|
{
|
||||||
/* Perform the uIP connection operation */
|
/* Perform the uIP connection operation */
|
||||||
|
|
||||||
|
@ -516,7 +516,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(psock->s_flags))
|
||||||
{
|
{
|
||||||
/* The SOCK_STREAM must be connect in order to recive */
|
/* The SOCK_STREAM must be connected in order to receive */
|
||||||
|
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@ struct ethip_hdr
|
|||||||
uint8 ttl;
|
uint8 ttl;
|
||||||
uint8 proto;
|
uint8 proto;
|
||||||
uint16 ipchksum;
|
uint16 ipchksum;
|
||||||
in_addr_t srcipaddr;
|
uint16 srcipaddr[2];
|
||||||
in_addr_t destipaddr;
|
uint16 destipaddr[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ARP_REQUEST 1
|
#define ARP_REQUEST 1
|
||||||
@ -352,7 +352,7 @@ void uip_arp_out(struct uip_driver_s *dev)
|
|||||||
|
|
||||||
/* First check if destination is a local broadcast. */
|
/* First check if destination is a local broadcast. */
|
||||||
|
|
||||||
if (uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr))
|
if (uiphdr_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr))
|
||||||
{
|
{
|
||||||
memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, IFHWADDRLEN);
|
memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, IFHWADDRLEN);
|
||||||
}
|
}
|
||||||
|
@ -118,16 +118,15 @@ static inline void _uip_semtake(sem_t *sem)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static inline struct uip_udp_conn *uip_find_conn( uint16 portno )
|
static struct uip_udp_conn *uip_find_conn( uint16 portno )
|
||||||
{
|
{
|
||||||
uint16 nlastport = htons(g_last_udp_port);
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Now search each connection structure.*/
|
/* Now search each connection structure.*/
|
||||||
|
|
||||||
for (i = 0; i < UIP_UDP_CONNS; i++)
|
for (i = 0; i < UIP_UDP_CONNS; i++)
|
||||||
{
|
{
|
||||||
if (g_udp_connections[ i ].lport == nlastport)
|
if (g_udp_connections[ i ].lport == portno)
|
||||||
{
|
{
|
||||||
return &g_udp_connections[ i ];
|
return &g_udp_connections[ i ];
|
||||||
}
|
}
|
||||||
@ -288,6 +287,35 @@ void uip_udppoll(struct uip_driver_s *dev, unsigned int conn)
|
|||||||
uip_interrupt(dev, UIP_UDP_TIMER);
|
uip_interrupt(dev, UIP_UDP_TIMER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: uip_udpbind()
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function implements the UIP specific parts of the standard UDP
|
||||||
|
* bind() operation.
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* This function is called from normal user level code.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr)
|
||||||
|
#else
|
||||||
|
int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in *addr)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int ret = -EADDRINUSE;
|
||||||
|
irqstate_t flags = irqsave();
|
||||||
|
if (!uip_find_conn(g_last_udp_port))
|
||||||
|
{
|
||||||
|
conn->lport = HTONS(g_last_udp_port);
|
||||||
|
ret = OK;
|
||||||
|
}
|
||||||
|
irqrestore(flags);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: uip_udpconnect()
|
* Name: uip_udpconnect()
|
||||||
*
|
*
|
||||||
@ -314,13 +342,15 @@ int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr)
|
|||||||
int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr)
|
int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
irqstate_t flags;
|
/* Has this structure already been bound to a local port? */
|
||||||
|
|
||||||
/* Find an unused local port number. Loop until we find a valid listen port
|
if (!conn->lport)
|
||||||
* number that is not being used by any other connection.
|
{
|
||||||
|
/* No..Find an unused local port number. Loop until we find a valid
|
||||||
|
* listen port number that is not being used by any other connection.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
irqstate_t flags = irqsave();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Guess that the next available port number will be the one after
|
/* Guess that the next available port number will be the one after
|
||||||
@ -330,6 +360,7 @@ int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr)
|
|||||||
++g_last_udp_port;
|
++g_last_udp_port;
|
||||||
|
|
||||||
/* Make sure that the port number is within range */
|
/* Make sure that the port number is within range */
|
||||||
|
|
||||||
if (g_last_udp_port >= 32000)
|
if (g_last_udp_port >= 32000)
|
||||||
{
|
{
|
||||||
g_last_udp_port = 4096;
|
g_last_udp_port = 4096;
|
||||||
@ -337,10 +368,13 @@ int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr)
|
|||||||
}
|
}
|
||||||
while (uip_find_conn(g_last_udp_port));
|
while (uip_find_conn(g_last_udp_port));
|
||||||
|
|
||||||
/* Initialize and return the connection structure, bind it to the port number */
|
/* Initialize and return the connection structure, bind it to the
|
||||||
|
* port number
|
||||||
|
*/
|
||||||
|
|
||||||
conn->lport = HTONS(g_last_udp_port);
|
conn->lport = HTONS(g_last_udp_port);
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
|
}
|
||||||
|
|
||||||
if (addr)
|
if (addr)
|
||||||
{
|
{
|
||||||
@ -352,6 +386,7 @@ int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr)
|
|||||||
conn->rport = 0;
|
conn->rport = 0;
|
||||||
uip_ipaddr_copy(conn->ripaddr, all_zeroes_addr);
|
uip_ipaddr_copy(conn->ripaddr, all_zeroes_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->ttl = UIP_TTL;
|
conn->ttl = UIP_TTL;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ uint16 uip_ipchksum(struct uip_driver_s *dev)
|
|||||||
uint16 sum;
|
uint16 sum;
|
||||||
|
|
||||||
sum = chksum(0, &dev->d_buf[UIP_LLH_LEN], UIP_IPH_LEN);
|
sum = chksum(0, &dev->d_buf[UIP_LLH_LEN], UIP_IPH_LEN);
|
||||||
dbg("uip_ipchksum: sum 0x%04x\n", sum);
|
dbg("Checksum 0x%04x\n", sum);
|
||||||
return (sum == 0) ? 0xffff : htons(sum);
|
return (sum == 0) ? 0xffff : htons(sum);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -420,8 +420,8 @@ static uint8 uip_reass(void)
|
|||||||
* fragment into the buffer.
|
* fragment into the buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (uip_addr_cmp(BUF->srcipaddr, FBUF->srcipaddr) &&
|
if (uiphdr_addr_cmp(BUF->srcipaddr, FBUF->srcipaddr) &&
|
||||||
uip_addr_cmp(BUF->destipaddr == FBUF->destipaddr) &&
|
uiphdr_addr_cmp(BUF->destipaddr == FBUF->destipaddr) &&
|
||||||
BUF->ipid[0] == FBUF->ipid[0] && BUF->ipid[1] == FBUF->ipid[1])
|
BUF->ipid[0] == FBUF->ipid[0] && BUF->ipid[1] == FBUF->ipid[1])
|
||||||
{
|
{
|
||||||
len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
|
len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
|
||||||
@ -871,7 +871,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
|
|
||||||
/* Check if the packet is destined for our IP address. */
|
/* Check if the packet is destined for our IP address. */
|
||||||
#ifndef CONFIG_NET_IPv6
|
#ifndef CONFIG_NET_IPv6
|
||||||
if (!uip_ipaddr_cmp(BUF->destipaddr, dev->d_ipaddr))
|
if (!uip_ipaddr_cmp(uip_ip4addr_conv(BUF->destipaddr), dev->d_ipaddr))
|
||||||
{
|
{
|
||||||
UIP_STAT(++uip_stat.ip.drop);
|
UIP_STAT(++uip_stat.ip.drop);
|
||||||
goto drop;
|
goto drop;
|
||||||
@ -970,8 +970,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
|
|
||||||
/* Swap IP addresses. */
|
/* Swap IP addresses. */
|
||||||
|
|
||||||
uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
|
uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
|
||||||
uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr);
|
||||||
|
|
||||||
UIP_STAT(++uip_stat.icmp.sent);
|
UIP_STAT(++uip_stat.icmp.sent);
|
||||||
goto send;
|
goto send;
|
||||||
@ -980,7 +980,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
#else /* !CONFIG_NET_IPv6 */
|
#else /* !CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
/* This is IPv6 ICMPv6 processing code. */
|
/* This is IPv6 ICMPv6 processing code. */
|
||||||
dbg("icmp6_input: length %d\n", dev->d_len);
|
dbg("ICMP6 input length %d\n", dev->d_len);
|
||||||
|
|
||||||
if (BUF->proto != UIP_PROTO_ICMP6)
|
if (BUF->proto != UIP_PROTO_ICMP6)
|
||||||
{
|
{
|
||||||
@ -1003,7 +1003,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
if (ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS)
|
if (ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS)
|
||||||
{
|
{
|
||||||
/* Save the sender's address in our neighbor list. */
|
/* Save the sender's address in our neighbor list. */
|
||||||
uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
|
uiphdr_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We should now send a neighbor advertisement back to where the
|
/* We should now send a neighbor advertisement back to where the
|
||||||
@ -1013,8 +1013,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
|
|
||||||
ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
|
ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
|
||||||
|
|
||||||
uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
|
uiphdr_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
|
||||||
uip_ipaddr_copy(ICMPBUF->srcipaddr, dev->d_ipaddr);
|
uiphdr_ipaddr_copy(ICMPBUF->srcipaddr, dev->d_ipaddr);
|
||||||
ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
|
ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
|
||||||
ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */
|
ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */
|
||||||
memcpy(&(ICMPBUF->options[2]), &dev->d_mac, IFHWADDRLEN);
|
memcpy(&(ICMPBUF->options[2]), &dev->d_mac, IFHWADDRLEN);
|
||||||
@ -1032,8 +1032,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
|
|
||||||
ICMPBUF->type = ICMP6_ECHO_REPLY;
|
ICMPBUF->type = ICMP6_ECHO_REPLY;
|
||||||
|
|
||||||
uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
|
uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
|
||||||
uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
uiphdr_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
||||||
ICMPBUF->icmpchksum = 0;
|
ICMPBUF->icmpchksum = 0;
|
||||||
ICMPBUF->icmpchksum = ~uip_icmp6chksum(dev);
|
ICMPBUF->icmpchksum = ~uip_icmp6chksum(dev);
|
||||||
|
|
||||||
@ -1042,7 +1042,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dbg("Unknown icmp6 message type %d\n", ICMPBUF->type);
|
dbg("Unknown ICMP6 message: %d\n", ICMPBUF->type);
|
||||||
UIP_STAT(++uip_stat.icmp.drop);
|
UIP_STAT(++uip_stat.icmp.drop);
|
||||||
UIP_STAT(++uip_stat.icmp.typeerr);
|
UIP_STAT(++uip_stat.icmp.typeerr);
|
||||||
UIP_LOG("icmp: unknown ICMP message.");
|
UIP_LOG("icmp: unknown ICMP message.");
|
||||||
@ -1118,8 +1118,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
BUF->srcport = uip_udp_conn->lport;
|
BUF->srcport = uip_udp_conn->lport;
|
||||||
BUF->destport = uip_udp_conn->rport;
|
BUF->destport = uip_udp_conn->rport;
|
||||||
|
|
||||||
uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr);
|
||||||
uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr);
|
uiphdr_ipaddr_copy(BUF->destipaddr, &uip_udp_conn->ripaddr);
|
||||||
|
|
||||||
dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
|
dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
|
||||||
|
|
||||||
@ -1231,8 +1231,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag)
|
|||||||
BUF->destport = tmp16;
|
BUF->destport = tmp16;
|
||||||
|
|
||||||
/* Swap IP addresses. */
|
/* Swap IP addresses. */
|
||||||
uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
|
uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
|
||||||
uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
uiphdr_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
||||||
|
|
||||||
/* And send out the RST packet! */
|
/* And send out the RST packet! */
|
||||||
goto tcp_send_noconn;
|
goto tcp_send_noconn;
|
||||||
@ -1850,8 +1850,8 @@ tcp_send_synack:
|
|||||||
BUF->srcport = uip_connr->lport;
|
BUF->srcport = uip_connr->lport;
|
||||||
BUF->destport = uip_connr->rport;
|
BUF->destport = uip_connr->rport;
|
||||||
|
|
||||||
uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr);
|
||||||
uip_ipaddr_copy(BUF->destipaddr, uip_connr->ripaddr);
|
uiphdr_ipaddr_copy(BUF->destipaddr, &uip_connr->ripaddr);
|
||||||
|
|
||||||
if (uip_connr->tcpstateflags & UIP_STOPPED)
|
if (uip_connr->tcpstateflags & UIP_STOPPED)
|
||||||
{
|
{
|
||||||
@ -1902,7 +1902,7 @@ tcp_send_synack:
|
|||||||
/* Calculate IP checksum. */
|
/* Calculate IP checksum. */
|
||||||
BUF->ipchksum = 0;
|
BUF->ipchksum = 0;
|
||||||
BUF->ipchksum = ~(uip_ipchksum(dev));
|
BUF->ipchksum = ~(uip_ipchksum(dev));
|
||||||
dbg("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum(dev));
|
dbg("ip_send_nolen checksum: 0x%04x\n", uip_ipchksum(dev));
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
UIP_STAT(++uip_stat.tcp.sent);
|
UIP_STAT(++uip_stat.tcp.sent);
|
||||||
|
Loading…
Reference in New Issue
Block a user