Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki
This commit is contained in:
commit
966c21c744
13 changed files with 462 additions and 60 deletions
|
@ -76,6 +76,10 @@
|
|||
#define MACA_INSERT_ACK 1
|
||||
#endif
|
||||
|
||||
/* Bit in first byte of 802.15.4 message that indicates an */
|
||||
/* acknowledgereply frame is expected */
|
||||
#define MAC_ACK_REQUEST_FLAG 0x20
|
||||
|
||||
#define reg(x) (*(volatile uint32_t *)(x))
|
||||
|
||||
int count_packets(void);
|
||||
|
@ -650,7 +654,7 @@ void maca_isr(void) {
|
|||
dma_rx->rx_time = *MACA_TIMESTAMP;
|
||||
|
||||
/* check if received packet needs an ack */
|
||||
if(prm_mode == AUTOACK && (dma_rx->data[1] & 0x20)) {
|
||||
if(prm_mode == AUTOACK && (dma_rx->data[1] & MAC_ACK_REQUEST_FLAG)) {
|
||||
/* this wait is necessary to auto-ack */
|
||||
volatile uint32_t wait_clk;
|
||||
wait_clk = *MACA_CLK + 200;
|
||||
|
@ -682,8 +686,18 @@ void maca_isr(void) {
|
|||
/* PRINTF("maca action complete %d\n\r", get_field(*MACA_CONTROL,SEQUENCE)); */
|
||||
if(last_post == TX_POST) {
|
||||
tx_head->status = get_field(*MACA_STATUS,CODE);
|
||||
|
||||
#if MACA_INSERT_ACK
|
||||
if(tx_head->status == SUCCESS) {
|
||||
/* Having sent a message with the acknowledge request flag set the
|
||||
* MACA hardware will only give a tx success indication if the message
|
||||
* was acknowledged by the remote node. We need to detect this
|
||||
* condition and inject an ACK packet into the internal receive stream
|
||||
* as the higher layers are expecting to see an ACK packet.*/
|
||||
|
||||
if(tx_head->status == SUCCESS && (tx_head->data[0] & MAC_ACK_REQUEST_FLAG)) {
|
||||
|
||||
/* Create the dummy ack packet */
|
||||
|
||||
static volatile packet_t *ack_p;
|
||||
if(ack_p = get_free_packet()) {
|
||||
ack_p->length = 3;
|
||||
|
@ -694,6 +708,7 @@ void maca_isr(void) {
|
|||
ack_p->data[3] = *MACA_TXSEQNR;
|
||||
insert_at_rx_head(ack_p);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -164,16 +164,14 @@ PT_THREAD(send_values(struct httpd_state *s))
|
|||
end_acc_chart();
|
||||
SEND_STRING(&s->sout, buf);
|
||||
|
||||
SEND_STRING(&s->sout, BOTTOM);
|
||||
|
||||
}
|
||||
if(s->filename[1] != 'a') {
|
||||
generate_chart("Temperature", "Celsius", 10, 50, temperature);
|
||||
SEND_STRING(&s->sout, buf);
|
||||
}
|
||||
|
||||
SEND_STRING(&s->sout, BOTTOM);
|
||||
}
|
||||
}
|
||||
|
||||
PSOCK_END(&s->sout);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#define QUEUEBUF_CONF_NUM 2
|
||||
|
||||
#undef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 140
|
||||
#define UIP_CONF_BUFFER_SIZE 128
|
||||
|
||||
#undef UIP_CONF_RECEIVE_WINDOW
|
||||
#define UIP_CONF_RECEIVE_WINDOW 60
|
||||
|
@ -44,4 +44,7 @@
|
|||
#undef WEBSERVER_CONF_CFS_CONNS
|
||||
#define WEBSERVER_CONF_CFS_CONNS 2
|
||||
|
||||
#undef WITH_SERIAL_LINE_INPUT
|
||||
#define WITH_SERIAL_LINE_INPUT 0
|
||||
|
||||
#endif /* __PROJECT_RPL_WEB_CONF_H__ */
|
||||
|
|
|
@ -5,12 +5,18 @@
|
|||
#include "contiki-net.h"
|
||||
#include "rest.h"
|
||||
|
||||
#if defined (CONTIKI_TARGET_SKY) /* Any other targets will be added here (&& defined (OTHER))*/
|
||||
#if defined (PLATFROM_HAS_LIGHT)
|
||||
#include "dev/light-sensor.h"
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_BATT)
|
||||
#include "dev/battery-sensor.h"
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_SHT11)
|
||||
#include "dev/sht11-sensor.h"
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
#include "dev/leds.h"
|
||||
#endif /*defined (CONTIKI_TARGET_SKY)*/
|
||||
#endif
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
|
@ -48,14 +54,44 @@ discover_handler(REQUEST* request, RESPONSE* response)
|
|||
char temp[100];
|
||||
int index = 0;
|
||||
index += sprintf(temp + index, "%s,", "</helloworld>;n=\"HelloWorld\"");
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
index += sprintf(temp + index, "%s,", "</led>;n=\"LedControl\"");
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_LIGHT)
|
||||
index += sprintf(temp + index, "%s", "</light>;n=\"Light\"");
|
||||
#endif
|
||||
|
||||
rest_set_response_payload(response, (uint8_t*)temp, strlen(temp));
|
||||
rest_set_header_content_type(response, APPLICATION_LINK_FORMAT);
|
||||
}
|
||||
|
||||
#if defined (CONTIKI_TARGET_SKY)
|
||||
#if defined (PLATFORM_HAS_LIGHT)
|
||||
uint16_t light_photosynthetic;
|
||||
uint16_t light_solar;
|
||||
|
||||
void
|
||||
read_light_sensor(uint16_t* light_1, uint16_t* light_2)
|
||||
{
|
||||
*light_1 = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
|
||||
*light_2 = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
|
||||
}
|
||||
|
||||
/*A simple getter example. Returns the reading from light sensor with a simple etag*/
|
||||
RESOURCE(light, METHOD_GET, "light");
|
||||
void
|
||||
light_handler(REQUEST* request, RESPONSE* response)
|
||||
{
|
||||
read_light_sensor(&light_photosynthetic, &light_solar);
|
||||
sprintf(temp,"%u;%u", light_photosynthetic, light_solar);
|
||||
|
||||
char etag[4] = "ABCD";
|
||||
rest_set_header_content_type(response, TEXT_PLAIN);
|
||||
rest_set_header_etag(response, etag, sizeof(etag));
|
||||
rest_set_response_payload(response, temp, strlen(temp));
|
||||
}
|
||||
#endif /*PLATFORM_HAS_LIGHT*/
|
||||
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
/*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/
|
||||
RESOURCE(led, METHOD_POST | METHOD_PUT , "led");
|
||||
|
||||
|
@ -102,33 +138,6 @@ led_handler(REQUEST* request, RESPONSE* response)
|
|||
}
|
||||
}
|
||||
|
||||
uint16_t light_photosynthetic;
|
||||
uint16_t light_solar;
|
||||
|
||||
void
|
||||
read_light_sensor(uint16_t* light_1, uint16_t* light_2)
|
||||
{
|
||||
*light_1 = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
|
||||
*light_2 = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
|
||||
}
|
||||
|
||||
/*A simple getter example. Returns the reading from light sensor with a simple etag*/
|
||||
RESOURCE(light, METHOD_GET, "light");
|
||||
void
|
||||
light_handler(REQUEST* request, RESPONSE* response)
|
||||
{
|
||||
#ifdef CONTIKI_TARGET_SKY
|
||||
read_light_sensor(&light_photosynthetic, &light_solar);
|
||||
sprintf(temp,"%u;%u", light_photosynthetic, light_solar);
|
||||
#else /*CONTIKI_TARGET_SKY*/
|
||||
sprintf(temp,"%d.%d", 0, 0);
|
||||
#endif /*CONTIKI_TARGET_SKY*/
|
||||
|
||||
char etag[4] = "ABCD";
|
||||
rest_set_header_content_type(response, TEXT_PLAIN);
|
||||
rest_set_header_etag(response, etag, sizeof(etag));
|
||||
rest_set_response_payload(response, temp, strlen(temp));
|
||||
}
|
||||
|
||||
/*A simple actuator example. Toggles the red led*/
|
||||
RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "toggle");
|
||||
|
@ -137,7 +146,7 @@ toggle_handler(REQUEST* request, RESPONSE* response)
|
|||
{
|
||||
leds_toggle(LEDS_RED);
|
||||
}
|
||||
#endif /*defined (CONTIKI_TARGET_SKY)*/
|
||||
#endif /*defined (CONTIKI_HAS_LEDS)*/
|
||||
|
||||
|
||||
PROCESS(rest_server_example, "Rest Server Example");
|
||||
|
@ -155,12 +164,14 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
|||
|
||||
rest_init();
|
||||
|
||||
#if defined (CONTIKI_TARGET_SKY)
|
||||
#if defined (PLATFORM_HAS_LIGHT)
|
||||
SENSORS_ACTIVATE(light_sensor);
|
||||
rest_activate_resource(&resource_led);
|
||||
rest_activate_resource(&resource_light);
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
rest_activate_resource(&resource_led);
|
||||
rest_activate_resource(&resource_toggle);
|
||||
#endif /*defined (CONTIKI_TARGET_SKY)*/
|
||||
#endif /*defined (PLATFORM_HAS_LEDS)*/
|
||||
|
||||
rest_activate_resource(&resource_helloworld);
|
||||
rest_activate_resource(&resource_discover);
|
||||
|
|
|
@ -97,6 +97,9 @@
|
|||
/* end of mc1322x specific config. */
|
||||
|
||||
/* start of conitki config. */
|
||||
#define PLATFORM_HAS_LEDS 1
|
||||
#define PLATFORM_HAS_BUTTON 1
|
||||
|
||||
#define RIMEADDR_CONF_SIZE 8
|
||||
|
||||
/* EUI64 generation */
|
||||
|
|
|
@ -148,4 +148,7 @@ public interface Mote {
|
|||
* Called when mote is removed from simulation
|
||||
*/
|
||||
public void removed();
|
||||
|
||||
public void setProperty(String key, Object obj);
|
||||
public Object getProperty(String key);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
package se.sics.cooja.motes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import se.sics.cooja.Mote;
|
||||
|
@ -130,4 +132,18 @@ public abstract class AbstractWakeupMote implements Mote {
|
|||
|
||||
public void removed() {
|
||||
}
|
||||
|
||||
private HashMap<String, Object> properties = null;
|
||||
public void setProperty(String key, Object obj) {
|
||||
if (properties == null) {
|
||||
properties = new HashMap<String, Object>();
|
||||
}
|
||||
properties.put(key, obj);
|
||||
}
|
||||
public Object getProperty(String key) {
|
||||
if (properties == null) {
|
||||
return null;
|
||||
}
|
||||
return properties.get(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ ifdef WITH_STDIN
|
|||
endif
|
||||
|
||||
clean:
|
||||
rm -f wpcapslip6.o wpcap6.o
|
||||
rm -f wpcapslip6.o wpcap6.o ip-process.o fakeuip.o
|
||||
|
||||
|
||||
vpath %.c $(CONTIKI)/core/net
|
||||
|
||||
wpcapslip6: wpcapslip6.o wpcap6.o
|
||||
wpcapslip6: wpcapslip6.o wpcap6.o ip-process.o fakeuip.o
|
||||
|
||||
%: %.o
|
||||
$(CC) $(LDFLAGS) $^ /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a -o $@
|
||||
|
|
75
tools/stm32w/wpcapslip6/fakeuip.c
Normal file
75
tools/stm32w/wpcapslip6/fakeuip.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
|
||||
/* Various stub functions and uIP variables other code might need to
|
||||
* compile. Allows you to save needing to compile all of uIP in just
|
||||
* to get a few things */
|
||||
|
||||
#define UIP_CONF_IPV6 1
|
||||
|
||||
#include "net/uip.h"
|
||||
#include <stdio.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#undef uip_buf
|
||||
unsigned char *uip_buf;
|
||||
u16_t uip_len;
|
||||
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
|
||||
static u16_t
|
||||
chksum(u16_t sum, const u8_t *data, u16_t len)
|
||||
{
|
||||
u16_t t;
|
||||
const u8_t *dataptr;
|
||||
const u8_t *last_byte;
|
||||
|
||||
dataptr = data;
|
||||
last_byte = data + len - 1;
|
||||
|
||||
while(dataptr < last_byte) { /* At least two more bytes */
|
||||
t = (dataptr[0] << 8) + dataptr[1];
|
||||
sum += t;
|
||||
if(sum < t) {
|
||||
sum++; /* carry */
|
||||
}
|
||||
dataptr += 2;
|
||||
}
|
||||
|
||||
if(dataptr == last_byte) {
|
||||
t = (dataptr[0] << 8) + 0;
|
||||
sum += t;
|
||||
if(sum < t) {
|
||||
sum++; /* carry */
|
||||
}
|
||||
}
|
||||
|
||||
/* Return sum in host byte order. */
|
||||
return sum;
|
||||
}
|
||||
|
||||
static u16_t
|
||||
upper_layer_chksum(u8_t proto)
|
||||
{
|
||||
u16_t upper_layer_len;
|
||||
u16_t sum;
|
||||
|
||||
upper_layer_len = (((u16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1]) ;
|
||||
|
||||
/* First sum pseudoheader. */
|
||||
/* IP protocol and length fields. This addition cannot carry. */
|
||||
sum = upper_layer_len + proto;
|
||||
/* Sum IP source and destination addresses. */
|
||||
sum = chksum(sum, (u8_t *)&UIP_IP_BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
|
||||
|
||||
/* Sum TCP header and data. */
|
||||
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
|
||||
upper_layer_len);
|
||||
|
||||
return (sum == 0) ? 0xffff : htons(sum);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
uip_icmp6chksum(void)
|
||||
{
|
||||
return upper_layer_chksum(UIP_PROTO_ICMP6);
|
||||
}
|
262
tools/stm32w/wpcapslip6/ip-process.c
Normal file
262
tools/stm32w/wpcapslip6/ip-process.c
Normal file
|
@ -0,0 +1,262 @@
|
|||
|
||||
#define UIP_CONF_IPV6 1
|
||||
#define UIP_CONF_LL_802154 1
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
#include "ip-process.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef uip_buf
|
||||
extern unsigned char *uip_buf;
|
||||
extern u16_t uip_len;
|
||||
|
||||
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
|
||||
|
||||
uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan);
|
||||
int8_t mac_translateIcmpLinkLayer();
|
||||
int8_t mac_translateIPLinkLayer();
|
||||
|
||||
|
||||
/**
|
||||
* \brief Translate IP packet's possible link-layer addresses, passing
|
||||
* the message to the appropriate higher level function for this
|
||||
* packet (aka: ICMP)
|
||||
* \param target The target we want to end up with - either ll_8023_type
|
||||
* for ethernet, or ll_802154_type for 802.15.4
|
||||
* \return Returns how successful the translation was
|
||||
* \retval 0 Addresses, if present, were translated.
|
||||
* \retval <0 Negative return values indicate various errors, as defined
|
||||
* by the higher level function.
|
||||
*/
|
||||
int8_t mac_translateIPLinkLayer()
|
||||
{
|
||||
|
||||
if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) {
|
||||
PRINTF("eth2low: ICMP Message detected\n");
|
||||
return mac_translateIcmpLinkLayer();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "net/uip-icmp6.h"
|
||||
#include "net/uip-nd6.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
uint8_t data[16];
|
||||
} icmp_opts_t;
|
||||
|
||||
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
|
||||
#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x])
|
||||
|
||||
void slide(uint8_t * data, uint8_t length, int16_t slide);
|
||||
|
||||
/**
|
||||
* \brief Translate the link-layer (L2) addresses in an ICMP packet.
|
||||
* This will just be NA/NS/RA/RS packets currently.
|
||||
* \param target The target we want to end up with - either ll_8023_type
|
||||
* for ethernet, or ll_802154_type for 802.15.4
|
||||
* \return Returns how successful the translation was
|
||||
* \retval 0 Addresses, if present, were translated.
|
||||
* \retval -1 ICMP message was unknown type, nothing done.
|
||||
* \retval -2 ICMP Length does not make sense?
|
||||
* \retval -3 Unknown 'target' type
|
||||
*/
|
||||
int8_t mac_translateIcmpLinkLayer()
|
||||
{
|
||||
uint16_t icmp_opt_offset = 0;
|
||||
int16_t len = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0] << 8);
|
||||
|
||||
uint16_t iplen;
|
||||
|
||||
uint8_t i;
|
||||
|
||||
int16_t sizechange;
|
||||
|
||||
uint8_t llbuf[16];
|
||||
|
||||
//Figure out offset to start of options
|
||||
switch(UIP_ICMP_BUF->type) {
|
||||
case ICMP6_NS:
|
||||
case ICMP6_NA:
|
||||
icmp_opt_offset = 24;
|
||||
break;
|
||||
|
||||
case ICMP6_RS:
|
||||
icmp_opt_offset = 8;
|
||||
break;
|
||||
|
||||
case ICMP6_RA:
|
||||
icmp_opt_offset = 16;
|
||||
break;
|
||||
|
||||
case ICMP6_REDIRECT:
|
||||
icmp_opt_offset = 40;
|
||||
break;
|
||||
|
||||
/** Things without link-layer */
|
||||
case ICMP6_DST_UNREACH:
|
||||
case ICMP6_PACKET_TOO_BIG:
|
||||
case ICMP6_TIME_EXCEEDED:
|
||||
case ICMP6_PARAM_PROB:
|
||||
case ICMP6_ECHO_REQUEST:
|
||||
case ICMP6_ECHO_REPLY:
|
||||
return 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Figure out length of options
|
||||
len -= icmp_opt_offset;
|
||||
|
||||
//Sanity check
|
||||
if (len < 8) return -2;
|
||||
|
||||
//While we have options to do...
|
||||
while (len >= 8){
|
||||
|
||||
//If we have one of these, we have something useful!
|
||||
if (((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_SLLAO) ||
|
||||
((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_TLLAO) ) {
|
||||
|
||||
/* Shrinking the buffer may thrash things, so we store the old
|
||||
link-layer address */
|
||||
for(i = 0; i < (UIP_ICMP_OPTS(icmp_opt_offset)->length*8 - 2); i++) {
|
||||
llbuf[i] = UIP_ICMP_OPTS(icmp_opt_offset)->data[i];
|
||||
}
|
||||
|
||||
|
||||
//Shrink/grow buffer as needed
|
||||
/* Current is 802.15.4, Hence current link-layer option is 14 extra
|
||||
* bytes.
|
||||
* (Actual LL is 8 bytes, but total option length is in multiples of
|
||||
* 8 Bytes, hence 8 + 2 = 10. Closest is 16 bytes, then 16 bytes for
|
||||
* total optional length - 2 bytes for type + length leaves 14 )
|
||||
*/
|
||||
sizechange = -8;
|
||||
slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 14, len - 14, sizechange);
|
||||
|
||||
|
||||
mac_createEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data, (uip_lladdr_t *)llbuf);
|
||||
|
||||
//Adjust the length
|
||||
UIP_ICMP_OPTS(icmp_opt_offset)->length = 1;
|
||||
|
||||
//Adjust the IP header length, as well as uIP length
|
||||
iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0]<<8);
|
||||
iplen += sizechange;
|
||||
len += sizechange;
|
||||
|
||||
UIP_IP_BUF->len[1] = (uint8_t)iplen;
|
||||
UIP_IP_BUF->len[0] = (uint8_t)(iplen >> 8);
|
||||
|
||||
uip_len += sizechange;
|
||||
|
||||
//We broke ICMP checksum, be sure to fix that
|
||||
UIP_ICMP_BUF->icmpchksum = 0;
|
||||
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
|
||||
|
||||
//Finally set up next run in while loop
|
||||
len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
|
||||
icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
|
||||
} else {
|
||||
|
||||
//Not an option we care about, ignore it
|
||||
len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
|
||||
|
||||
//This shouldn't happen!
|
||||
if (UIP_ICMP_OPTS(icmp_opt_offset)->length == 0) {
|
||||
PRINTF("Option in ND packet has length zero, error?\n");
|
||||
len = 0;
|
||||
}
|
||||
|
||||
icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
|
||||
|
||||
} //If ICMP_OPT is one we care about
|
||||
|
||||
} //while(len >= 8)
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create a 802.3 address from a 802.15.4 long address
|
||||
* \param ethernet Pointer to ethernet address
|
||||
* \param lowpan Pointer to 802.15.4 address
|
||||
*/
|
||||
uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
|
||||
{
|
||||
/* uint8_t j, match; */
|
||||
|
||||
u8_t tmp[8];
|
||||
|
||||
memcpy(tmp,lowpan,sizeof(uip_lladdr_t));
|
||||
|
||||
memcpy(ethernet, tmp, 3);
|
||||
memcpy(ethernet+3, tmp+5, 3);
|
||||
ethernet[0] |= 0x02;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Slide the pointed to memory up a certain amount,
|
||||
* growing/shrinking a buffer
|
||||
* \param data Pointer to start of data buffer
|
||||
* \param length Length of the data buffer
|
||||
* \param slide How many bytes to slide the buffer up in memory (if +) or
|
||||
* down in memory (if -)
|
||||
*/
|
||||
void slide(uint8_t * data, uint8_t length, int16_t slide)
|
||||
{
|
||||
//Sanity checks
|
||||
if (!length) return;
|
||||
if (!slide) return;
|
||||
|
||||
uint8_t i = 0;
|
||||
|
||||
while(length) {
|
||||
length--;
|
||||
|
||||
//If we are sliding up, we do from the top of the buffer down
|
||||
if (slide > 0) {
|
||||
*(data + length + slide) = *(data + length);
|
||||
|
||||
//If we are sliding down, we do from the bottom of the buffer up
|
||||
} else {
|
||||
*(data + slide + i) = *(data + i);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
u16_t ip_process(unsigned char *buf, unsigned int len)
|
||||
{
|
||||
uip_buf = buf;
|
||||
uip_len = len;
|
||||
|
||||
mac_translateIPLinkLayer();
|
||||
|
||||
return uip_len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
6
tools/stm32w/wpcapslip6/ip-process.h
Normal file
6
tools/stm32w/wpcapslip6/ip-process.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef IP_PROCESS_H
|
||||
#define IP_PROCESS_H
|
||||
|
||||
u16_t ip_process(unsigned char *buf, unsigned int len);
|
||||
|
||||
#endif /* IP_PROCESS_H */
|
|
@ -70,12 +70,9 @@
|
|||
#include <windows.h>
|
||||
|
||||
|
||||
//#include "net/uip.h"
|
||||
#include "net/uip_arp.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#include "ip-process.h"
|
||||
|
||||
char * wpcap_start(struct uip_eth_addr *addr, int log);
|
||||
|
||||
|
@ -286,7 +283,8 @@ is_sensible_string(const unsigned char *s, int len)
|
|||
void
|
||||
serial_to_wpcap(FILE *inslip)
|
||||
{
|
||||
unsigned char buf[BUF_SIZE];
|
||||
u16_t buf_aligned[BUF_SIZE/2];
|
||||
u8_t *buf = (u8_t *)buf_aligned;
|
||||
|
||||
static int inbufptr = 0;
|
||||
int ret;
|
||||
|
@ -425,6 +423,12 @@ read_more:
|
|||
|
||||
eth_hdr->type = htons(UIP_ETHTYPE_IPV6);
|
||||
inbufptr += sizeof(struct uip_eth_hdr);
|
||||
|
||||
// Process incoming packets to transform link layer addresses inside ICMP packets.
|
||||
// Try to do processing if we did not succeed to add the neighbor.
|
||||
if(clean_neighb == false){
|
||||
inbufptr = ip_process(buf, inbufptr);
|
||||
}
|
||||
}
|
||||
//print_packet(inpktbuf, inbufptr);
|
||||
|
||||
|
@ -805,9 +809,13 @@ void addAddress(const char * ifname, const char * ipaddr)
|
|||
else{
|
||||
execProcess(&exitCode,"netsh interface ipv6 add address \"%s\" %s",if_name,ipaddr);
|
||||
}
|
||||
if(exitCode==0)
|
||||
if(exitCode==0){
|
||||
clean_addr = true;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "WARNING: subprocess exited with code %ld\n", exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
void delAddress(const char * ifname, const char * ipaddr)
|
||||
{
|
||||
|
@ -843,9 +851,13 @@ void addLoWPANRoute(const char * ifname, const char * net, const char * gw)
|
|||
DWORD exitCode = -1;
|
||||
|
||||
execProcess(&exitCode,"netsh interface ipv6 add route %s/64 \"%s\" %s", net, if_name, gw);
|
||||
if(exitCode==0)
|
||||
if(exitCode==0){
|
||||
clean_route = true;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "WARNING: subprocess exited with code %ld\n", exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
void delLoWPANRoute(const char * ifname, const char * net)
|
||||
{
|
||||
|
@ -856,16 +868,14 @@ void addNeighbor(const char * ifname, const char * neighb, const char * neighb_m
|
|||
{
|
||||
DWORD exitCode = -1;
|
||||
|
||||
if(osVersionInfo.dwMajorVersion < 6){ // < Windows Vista (i.e., Windows XP; check if this command is ok for Windows Server 2003 too).
|
||||
|
||||
fprintf(stderr,"Bridge mode only supported on Windows Vista and later OSs.\r\n");
|
||||
exit(-1);
|
||||
|
||||
if(osVersionInfo.dwMajorVersion >= 6){
|
||||
execProcess(&exitCode,"netsh interface ipv6 add neighbor \"%s\" %s \"%s\"", if_name, neighb, neighb_mac);
|
||||
if(exitCode==0){
|
||||
clean_neighb = true;
|
||||
}
|
||||
else {
|
||||
execProcess(&exitCode,"netsh interface ipv6 add neighbor \"%s\" %s \"%s\"", if_name, neighb, neighb_mac);
|
||||
if(exitCode==0)
|
||||
clean_neighb = true;
|
||||
fprintf(stderr, "WARNING: subprocess exited with code %ld\n", exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -907,7 +917,7 @@ int IPAddrFromPrefix(char * ipaddr, const char * ipprefix, const char * mac)
|
|||
PRINTF("%02X ",dev_addr.addr[i]);
|
||||
PRINTF("\n");*/
|
||||
|
||||
dev_addr.addr[0] |= 0x02;
|
||||
dev_addr.addr[0] ^= 0x02;
|
||||
|
||||
strtok(tmp_ipprefix,"/");
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue