wpcap update for uIPv6

This commit is contained in:
dak664 2009-08-08 19:51:25 +00:00
parent d5047f43c1
commit 72d5442e05
3 changed files with 69 additions and 16 deletions

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: wpcap-drv.c,v 1.4 2008/06/23 19:53:16 adamdunkels Exp $ * @(#)$Id: wpcap-drv.c,v 1.5 2009/08/08 19:51:25 dak664 Exp $
*/ */
#include "contiki-net.h" #include "contiki-net.h"
@ -43,6 +43,7 @@
PROCESS(wpcap_process, "WinPcap driver"); PROCESS(wpcap_process, "WinPcap driver");
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if !UIP_CONF_IPV6
u8_t u8_t
wpcap_output(void) wpcap_output(void)
{ {
@ -51,6 +52,7 @@ wpcap_output(void)
return 0; return 0;
} }
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
pollhandler(void) pollhandler(void)
@ -61,7 +63,7 @@ pollhandler(void)
if(uip_len > 0) { if(uip_len > 0) {
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
if(BUF->type == htons(UIP_ETHTYPE_IPV6)) { if(BUF->type == htons(UIP_ETHTYPE_IPV6)) {
uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src); // uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
tcpip_input(); tcpip_input();
} else } else
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
@ -69,6 +71,7 @@ pollhandler(void)
uip_len -= sizeof(struct uip_eth_hdr); uip_len -= sizeof(struct uip_eth_hdr);
tcpip_input(); tcpip_input();
} else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
#if !UIP_CONF_IPV6 //math
uip_arp_arpin(); uip_arp_arpin();
/* If the above function invocation resulted in data that /* If the above function invocation resulted in data that
should be sent out on the network, the global variable should be sent out on the network, the global variable
@ -76,6 +79,9 @@ pollhandler(void)
if(uip_len > 0) { if(uip_len > 0) {
wpcap_send(); wpcap_send();
} }
#endif
// } else {
// uip_len = 0;
} }
} }
} }
@ -88,7 +94,11 @@ PROCESS_THREAD(wpcap_process, ev, data)
wpcap_init(); wpcap_init();
#if !UIP_CONF_IPV6
tcpip_set_outputfunc(wpcap_output); tcpip_set_outputfunc(wpcap_output);
#else
tcpip_set_outputfunc(wpcap_send);
#endif
process_poll(&wpcap_process); process_poll(&wpcap_process);

View file

@ -30,7 +30,7 @@
* *
* Author: Oliver Schmidt <ol.sc@web.de> * Author: Oliver Schmidt <ol.sc@web.de>
* *
* $Id: wpcap.c,v 1.14 2008/06/23 19:52:44 adamdunkels Exp $ * $Id: wpcap.c,v 1.15 2009/08/08 19:51:25 dak664 Exp $
*/ */
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@ -60,6 +60,11 @@
__attribute__((dllimport)) extern char **__argv[]; __attribute__((dllimport)) extern char **__argv[];
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
#if UIP_CONF_IPV6 /*TODO: put this in the right place */
//CCIF struct uip_eth_addr uip_ethaddr={{0xff,0xff,0xff,0xff,0xff,0xff}};
struct uip_eth_addr uip_ethaddr={{0xff,0xff,0xff,0xff,0xff,0xff}};
#endif /* #if UIP_CONF_IPV6 */
struct pcap; struct pcap;
struct pcap_if { struct pcap_if {
@ -92,6 +97,7 @@ static int (* pcap_next_ex)(struct pcap *, struct pcap_pkthdr **, unsigned char
static int (* pcap_sendpacket)(struct pcap *, unsigned char *, int); static int (* pcap_sendpacket)(struct pcap *, unsigned char *, int);
#define BUF ((struct uip_eth_hdr *)&uip_buf[0]) #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
@ -187,8 +193,9 @@ set_ethaddr(struct in_addr addr)
adapters->PhysicalAddress[2], adapters->PhysicalAddress[3], adapters->PhysicalAddress[2], adapters->PhysicalAddress[3],
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]); adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
log_message("set_ethaddr: ethernetaddr: ", buffer); log_message("set_ethaddr: ethernetaddr: ", buffer);
#if !UIP_CONF_IPV6
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress)); uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
#endif
break; break;
} }
} }
@ -255,6 +262,37 @@ wpcap_poll(void)
return (u16_t)packet_header->caplen; return (u16_t)packet_header->caplen;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if UIP_CONF_IPV6
u8_t
wpcap_send(uip_lladdr_t *lladdr)
{
if(lladdr == NULL) {
/* the dest must be multicast */
(&BUF->dest)->addr[0] = 0x33;
(&BUF->dest)->addr[1] = 0x33;
// (&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12]; //destipaddr is zero
// (&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13];
// (&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14];
// (&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15];
(&BUF->dest)->addr[2] = uip_ethaddr.addr[2];
(&BUF->dest)->addr[3] = uip_ethaddr.addr[3];
(&BUF->dest)->addr[4] = uip_ethaddr.addr[4];
(&BUF->dest)->addr[5] = uip_ethaddr.addr[5];
} else {
memcpy(&BUF->dest, lladdr, UIP_LLADDR_LEN);
}
if ((&BUF->src)->addr[0]) { //Linux tap6 does this always
memcpy(&BUF->src, &uip_lladdr, UIP_LLADDR_LEN);
}
// BUF->type = HTONS(UIP_ETHTYPE_IPV6); //math tmp //This causes a silent exit
uip_len += sizeof(struct uip_eth_hdr);
if(pcap_sendpacket(pcap, uip_buf, uip_len) == -1) {
error_exit("error on send\n");
}
return 0;
}
#else /* UIP_CONF_IPV6 */
void void
wpcap_send(void) wpcap_send(void)
{ {
@ -269,6 +307,7 @@ wpcap_send(void)
error_exit("error on send\n"); error_exit("error on send\n");
} }
} }
#endif /* UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
wpcap_exit(void) wpcap_exit(void)

View file

@ -30,7 +30,7 @@
* *
* Author: Oliver Schmidt <ol.sc@web.de> * Author: Oliver Schmidt <ol.sc@web.de>
* *
* $Id: wpcap.h,v 1.2 2007/05/20 21:32:24 oliverschmidt Exp $ * $Id: wpcap.h,v 1.3 2009/08/08 19:51:25 dak664 Exp $
*/ */
#ifndef __WPCAP_H__ #ifndef __WPCAP_H__
@ -38,7 +38,11 @@
void wpcap_init(void); void wpcap_init(void);
u16_t wpcap_poll(void); u16_t wpcap_poll(void);
#if UIP_CONF_IPV6
u8_t wpcap_send(uip_lladdr_t *lladdr);
#else
void wpcap_send(void); void wpcap_send(void);
#endif
void wpcap_exit(void); void wpcap_exit(void);
#endif /* __WPCAP_H__ */ #endif /* __WPCAP_H__ */