Removed UIP_LLH_LEN
This commit is contained in:
parent
999e7dc3a7
commit
ea32ab0f12
|
@ -263,7 +263,7 @@ output(const linkaddr_t *localdest)
|
|||
{
|
||||
LOG_DBG("SUT: %u\n", uip_len);
|
||||
if(uip_len > 0) {
|
||||
return tun_output(&uip_buf[UIP_LLH_LEN], uip_len);
|
||||
return tun_output(uip_buf, uip_len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ handle_fd(fd_set *rset, fd_set *wset)
|
|||
LOG_INFO("Tun6-handle FD\n");
|
||||
|
||||
if(FD_ISSET(tunfd, rset)) {
|
||||
size = tun_input(&uip_buf[UIP_LLH_LEN], sizeof(uip_buf));
|
||||
size = tun_input(uip_buf, sizeof(uip_buf));
|
||||
LOG_DBG("TUN data incoming read:%d\n", size);
|
||||
uip_len = size;
|
||||
tcpip_input();
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
static uint8_t
|
||||
uip_driver_send(const linkaddr_t *addr)
|
||||
{
|
||||
packetbuf_copyfrom(&uip_buf[UIP_LLH_LEN], uip_len);
|
||||
packetbuf_copyfrom(uip_buf, uip_len);
|
||||
|
||||
/* XXX we should provide a callback function that is called when the
|
||||
packet is sent. For now, we just supply a NULL pointer. */
|
||||
|
@ -64,9 +64,8 @@ init(void)
|
|||
static void
|
||||
input(void)
|
||||
{
|
||||
if(packetbuf_datalen() > 0 &&
|
||||
packetbuf_datalen() <= UIP_BUFSIZE - UIP_LLH_LEN) {
|
||||
memcpy(&uip_buf[UIP_LLH_LEN], packetbuf_dataptr(), packetbuf_datalen());
|
||||
if(packetbuf_datalen() > 0 && packetbuf_datalen() <= UIP_BUFSIZE) {
|
||||
memcpy(uip_buf, packetbuf_dataptr(), packetbuf_datalen());
|
||||
uip_len = packetbuf_datalen();
|
||||
tcpip_input();
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ unsigned long slip_received, slip_frames;
|
|||
#ifdef SLIP_CONF_RX_BUFSIZE
|
||||
#define RX_BUFSIZE SLIP_CONF_RX_BUFSIZE
|
||||
|
||||
#if RX_BUFSIZE < (UIP_BUFSIZE - UIP_LLH_LEN + 16)
|
||||
#if RX_BUFSIZE < (UIP_BUFSIZE + 16)
|
||||
#error "SLIP_CONF_RX_BUFSIZE too small for UIP_BUFSIZE"
|
||||
#endif
|
||||
|
||||
|
@ -194,7 +194,7 @@ slip_send(void)
|
|||
|
||||
slip_arch_writeb(SLIP_END);
|
||||
|
||||
ptr = &uip_buf[UIP_LLH_LEN];
|
||||
ptr = uip_buf;
|
||||
for(i = 0; i < uip_len; ++i) {
|
||||
c = *ptr++;
|
||||
slip_write_char(c);
|
||||
|
@ -316,8 +316,7 @@ PROCESS_THREAD(slip_process, ev, data)
|
|||
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
||||
|
||||
/* Move packet from rxbuf to buffer provided by uIP. */
|
||||
uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN],
|
||||
UIP_BUFSIZE - UIP_LLH_LEN);
|
||||
uip_len = slip_poll_handler(uip_buf, UIP_BUFSIZE);
|
||||
|
||||
PRINTF("SLIP: recv bytes %u frames RECV: %u. is_full %u, is_dropping %u.\n",
|
||||
end_counter, uip_len, is_full, is_dropping);
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
#define REST_MAX_CHUNK_SIZE 256
|
||||
|
||||
/* Network config */
|
||||
//#define UIP_CONF_BUFFER_SIZE (REST_MAX_CHUNK_SIZE + UIP_LLH_LEN + UIP_IPUDPH_LEN + COAP_MAX_HEADER_SIZE)
|
||||
//#define UIP_CONF_BUFFER_SIZE (REST_MAX_CHUNK_SIZE + UIP_IPUDPH_LEN + COAP_MAX_HEADER_SIZE)
|
||||
//#define UIP_CONF_BUFFER_SIZE (REST_MAX_CHUNK_SIZE + 0 + 48 + 70)
|
||||
#define UIP_CONF_BUFFER_SIZE 1280 /* ipv6 required minimum */
|
||||
|
||||
|
|
|
@ -97,7 +97,6 @@ PROCESS_THREAD(er_example_server, ev, data)
|
|||
PRINTF("Starting Erbium Example Server\n");
|
||||
|
||||
PRINTF("uIP buffer: %u\n", UIP_BUFSIZE);
|
||||
PRINTF("LL header: %u\n", UIP_LLH_LEN);
|
||||
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
|
||||
PRINTF("REST max chunk: %u\n", COAP_MAX_CHUNK_SIZE);
|
||||
|
||||
|
|
|
@ -226,9 +226,8 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
|
|||
static void
|
||||
slip_input_callback(void)
|
||||
{
|
||||
LOG_DBG("SR-SIN: %u '%c%c'\n", uip_len,
|
||||
uip_buf[UIP_LLH_LEN], uip_buf[UIP_LLH_LEN + 1]);
|
||||
if(!cmd_input(&uip_buf[UIP_LLH_LEN], uip_len)) {
|
||||
LOG_DBG("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]);
|
||||
if(!cmd_input(uip_buf, uip_len)) {
|
||||
cmd_send((uint8_t *)"EUnknown command", 16);
|
||||
}
|
||||
uipbuf_clear();
|
||||
|
|
|
@ -52,7 +52,7 @@ static uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop;
|
|||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Must be at least one byte larger than UIP_BUFSIZE! */
|
||||
#define RX_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN + 16)
|
||||
#define RX_BUFSIZE (UIP_BUFSIZE + 16)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
enum {
|
||||
STATE_TWOPACKETS = 0, /* We have 2 packets and drop incoming data. */
|
||||
|
@ -87,7 +87,7 @@ slip_set_input_callback(void (*c)(void))
|
|||
void
|
||||
slip_send(void)
|
||||
{
|
||||
slip_write(&uip_buf[UIP_LLH_LEN], uip_len);
|
||||
slip_write(uip_buf, uip_len);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -252,8 +252,7 @@ PROCESS_THREAD(slip_process, ev, data)
|
|||
slip_active = 1;
|
||||
|
||||
/* Move packet from rxbuf to buffer provided by uIP. */
|
||||
uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN],
|
||||
UIP_BUFSIZE - UIP_LLH_LEN);
|
||||
uip_len = slip_poll_handler(uip_buf, UIP_BUFSIZE);
|
||||
|
||||
if(uip_len > 0) {
|
||||
if(input_callback) {
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
#endif /* WITH_DTLS */
|
||||
|
||||
/* sanity check for configured values */
|
||||
#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPH_LEN - UIP_UDPH_LEN)
|
||||
#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_IPH_LEN - UIP_UDPH_LEN)
|
||||
#error "UIP_CONF_BUFFER_SIZE too small for COAP_MAX_CHUNK_SIZE"
|
||||
#endif
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ static void mcast_fwd(void *p);
|
|||
struct multicast_on_behalf{ /* ICMP message of multicast_on_behalf */
|
||||
uint16_t mcast_port;
|
||||
uip_ipaddr_t mcast_ip;
|
||||
uint8_t mcast_payload[UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN];
|
||||
uint8_t mcast_payload[UIP_BUFSIZE - UIP_IPUDPH_LEN];
|
||||
};
|
||||
#define UIP_ICMP_MOB 18 /* Size of multicast_on_behalf ICMP header */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -135,7 +135,7 @@ icmp_output()
|
|||
|
||||
struct multicast_on_behalf *mob;
|
||||
mob = (struct multicast_on_behalf *)UIP_ICMP_PAYLOAD;
|
||||
memcpy(&mob->mcast_payload, &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], uip_slen);
|
||||
memcpy(&mob->mcast_payload, &uip_buf[UIP_IPUDPH_LEN], uip_slen);
|
||||
|
||||
UIP_IP_BUF->vtc = 0x60;
|
||||
UIP_IP_BUF->tcflow = 0;
|
||||
|
@ -215,13 +215,13 @@ icmp_input()
|
|||
c->rport = locmobptr->mcast_port;
|
||||
uip_slen = loclen;
|
||||
uip_udp_conn=c;
|
||||
memcpy(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], locmobptr->mcast_payload,
|
||||
loclen > UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN?
|
||||
UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN: loclen);
|
||||
memcpy(&uip_buf[UIP_IPUDPH_LEN], locmobptr->mcast_payload,
|
||||
loclen > UIP_BUFSIZE - UIP_IPUDPH_LEN?
|
||||
UIP_BUFSIZE - UIP_IPUDPH_LEN: loclen);
|
||||
|
||||
uip_process(UIP_UDP_SEND_CONN);
|
||||
|
||||
memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len);
|
||||
memcpy(&mcast_buf, uip_buf, uip_len);
|
||||
mcast_len = uip_len;
|
||||
/* pass the packet to our uip_process to check if it is allowed to
|
||||
* accept this packet or not */
|
||||
|
@ -231,7 +231,7 @@ icmp_input()
|
|||
|
||||
uip_process(UIP_DATA);
|
||||
|
||||
memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len);
|
||||
memcpy(uip_buf, &mcast_buf, mcast_len);
|
||||
uip_len = mcast_len;
|
||||
/* Return the IP of the original Multicast sender */
|
||||
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &src_ip);
|
||||
|
@ -249,7 +249,7 @@ icmp_input()
|
|||
static void
|
||||
mcast_fwd(void *p)
|
||||
{
|
||||
memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len);
|
||||
memcpy(uip_buf, &mcast_buf, mcast_len);
|
||||
uip_len = mcast_len;
|
||||
UIP_IP_BUF->ttl--;
|
||||
tcpip_output(NULL);
|
||||
|
@ -343,7 +343,7 @@ in()
|
|||
fwd_delay = fwd_delay * (1 + ((random_rand() >> 11) % fwd_spread));
|
||||
}
|
||||
|
||||
memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len);
|
||||
memcpy(&mcast_buf, uip_buf, uip_len);
|
||||
mcast_len = uip_len;
|
||||
ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL);
|
||||
}
|
||||
|
|
|
@ -276,7 +276,7 @@ struct mcast_packet {
|
|||
uint16_t seq_val; /* host-byte order */
|
||||
struct sliding_window *sw; /* Pointer to the SW this packet belongs to */
|
||||
uint8_t flags; /* Is-Used, Must Send, Is Listed */
|
||||
uint8_t buff[UIP_BUFSIZE - UIP_LLH_LEN];
|
||||
uint8_t buff[UIP_BUFSIZE];
|
||||
};
|
||||
|
||||
/* Flag bits */
|
||||
|
@ -289,7 +289,7 @@ struct mcast_packet {
|
|||
#define MCAST_PACKET_GET_SEED(p) ((seed_id_t *)&((p)->seed_id))
|
||||
#else
|
||||
#define MCAST_PACKET_GET_SEED(p) \
|
||||
((seed_id_t *)&((struct uip_ip_hdr *)&(p)->buff[UIP_LLH_LEN])->srcipaddr)
|
||||
((seed_id_t *)&((struct uip_ip_hdr *)&(p)->buff[0])->srcipaddr)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -1314,7 +1314,7 @@ static void
|
|||
out()
|
||||
{
|
||||
|
||||
if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE - UIP_LLH_LEN) {
|
||||
if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE) {
|
||||
PRINTF("ROLL TM: Multicast Out can not add HBHO. Packet too long\n");
|
||||
goto drop;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ static uint8_t fwd_spread;
|
|||
static void
|
||||
mcast_fwd(void *p)
|
||||
{
|
||||
memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len);
|
||||
memcpy(uip_buf, &mcast_buf, mcast_len);
|
||||
uip_len = mcast_len;
|
||||
UIP_IP_BUF->ttl--;
|
||||
tcpip_output(NULL);
|
||||
|
@ -174,7 +174,7 @@ in()
|
|||
fwd_delay = fwd_delay * (1 + ((random_rand() >> 11) % fwd_spread));
|
||||
}
|
||||
|
||||
memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len);
|
||||
memcpy(&mcast_buf, uip_buf, uip_len);
|
||||
mcast_len = uip_len;
|
||||
ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL);
|
||||
}
|
||||
|
|
|
@ -1932,12 +1932,12 @@ input(void)
|
|||
|
||||
/* Sanity-check size of incoming packet to avoid buffer overflow */
|
||||
{
|
||||
int req_size = UIP_LLH_LEN + uncomp_hdr_len + (uint16_t)(frag_offset << 3)
|
||||
int req_size = uncomp_hdr_len + (uint16_t)(frag_offset << 3)
|
||||
+ packetbuf_payload_len;
|
||||
if(req_size > sizeof(uip_buf)) {
|
||||
LOG_ERR(
|
||||
"input: packet dropped, minimum required IP_BUF size: %d+%d+%d+%d=%d (current size: %u)\n",
|
||||
UIP_LLH_LEN, uncomp_hdr_len, (uint16_t)(frag_offset << 3),
|
||||
"input: packet dropped, minimum required IP_BUF size: %d+%d+%d=%d (current size: %u)\n",
|
||||
uncomp_hdr_len, (uint16_t)(frag_offset << 3),
|
||||
packetbuf_payload_len, req_size, (unsigned)sizeof(uip_buf));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ struct uip_packetqueue_handle;
|
|||
|
||||
struct uip_packetqueue_packet {
|
||||
struct uip_ds6_queued_packet *next;
|
||||
uint8_t queue_buf[UIP_BUFSIZE - UIP_LLH_LEN];
|
||||
uint8_t queue_buf[UIP_BUFSIZE];
|
||||
uint16_t queue_buf_len;
|
||||
struct ctimer lifetimer;
|
||||
struct uip_packetqueue_handle *handle;
|
||||
|
|
|
@ -51,10 +51,10 @@ void
|
|||
uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len)
|
||||
{
|
||||
#if UIP_UDP
|
||||
if(data != NULL && len <= (UIP_BUFSIZE - (UIP_LLH_LEN + UIP_IPUDPH_LEN))) {
|
||||
if(data != NULL && len <= (UIP_BUFSIZE - UIP_IPUDPH_LEN)) {
|
||||
uip_udp_conn = c;
|
||||
uip_slen = len;
|
||||
memmove(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], data, len);
|
||||
memmove(&uip_buf[UIP_IPUDPH_LEN], data, len);
|
||||
uip_process(UIP_UDP_SEND_CONN);
|
||||
|
||||
#if UIP_IPV6_MULTICAST
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + TCP header */
|
||||
#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
|
||||
#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* Size of ICMP + IP header */
|
||||
#define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* Size of L2 + IP header */
|
||||
#define UIP_LLIPH_LEN (UIP_IPH_LEN) /* Size of L2 + IP header */
|
||||
|
||||
/**
|
||||
* The sums below are quite used in ND. When used for uip_buf, we
|
||||
|
@ -72,14 +72,14 @@
|
|||
* we need values with and without LLH_LEN we do not use capital
|
||||
* letters as these values are variable
|
||||
*/
|
||||
#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
|
||||
#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
|
||||
#define uip_l2_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
|
||||
#define uip_l2_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
|
||||
#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
|
||||
|
||||
/**
|
||||
* Direct access to IPv6 header
|
||||
*/
|
||||
#define UIP_IP_BUF_CHAR ((unsigned char *)uip_buf + UIP_LLH_LEN)
|
||||
#define UIP_IP_BUF_CHAR ((unsigned char *)uip_buf)
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)UIP_IP_BUF_CHAR)
|
||||
#define UIP_IP_PAYLOAD(ext) ((unsigned char *)UIP_IP_BUF_CHAR + UIP_IPH_LEN + (ext))
|
||||
|
||||
|
@ -1780,7 +1780,7 @@ struct uip_udp_hdr {
|
|||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
|
||||
#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_TCPIP_HLEN)
|
||||
|
||||
#define UIP_PROTO_ICMP 1
|
||||
#define UIP_PROTO_TCP 6
|
||||
|
|
|
@ -321,7 +321,7 @@ uip_ipchksum(void)
|
|||
{
|
||||
uint16_t sum;
|
||||
|
||||
sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
|
||||
sum = chksum(0, uip_buf, UIP_IPH_LEN);
|
||||
LOG_DBG("uip_ipchksum: sum 0x%04x\n", sum);
|
||||
return (sum == 0) ? 0xffff : uip_htons(sum);
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ uip_listen(uint16_t port)
|
|||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#if UIP_CONF_IPV6_REASSEMBLY
|
||||
#define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
|
||||
#define UIP_REASS_BUFSIZE (UIP_BUFSIZE)
|
||||
|
||||
static uint8_t uip_reassbuf[UIP_REASS_BUFSIZE];
|
||||
|
||||
|
@ -935,7 +935,7 @@ uip_process(uint8_t flag)
|
|||
goto udp_send;
|
||||
}
|
||||
#endif /* UIP_UDP */
|
||||
uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
|
||||
uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN];
|
||||
|
||||
/* Check if we were invoked because of a poll request for a
|
||||
particular connection. */
|
||||
|
@ -1072,7 +1072,7 @@ uip_process(uint8_t flag)
|
|||
if(flag == UIP_UDP_TIMER) {
|
||||
if(uip_udp_conn->lport != 0) {
|
||||
uip_conn = NULL;
|
||||
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
|
||||
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN];
|
||||
uip_len = uip_slen = 0;
|
||||
uip_flags = UIP_POLL;
|
||||
UIP_UDP_APPCALL();
|
||||
|
@ -1512,10 +1512,10 @@ uip_process(uint8_t flag)
|
|||
UIP_STAT(++uip_stat.udp.recv);
|
||||
|
||||
uip_len = uip_len - UIP_IPUDPH_LEN;
|
||||
uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
|
||||
uip_appdata = &uip_buf[UIP_IPUDPH_LEN];
|
||||
uip_conn = NULL;
|
||||
uip_flags = UIP_NEWDATA;
|
||||
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
|
||||
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN];
|
||||
uip_slen = 0;
|
||||
UIP_UDP_APPCALL();
|
||||
|
||||
|
@ -1545,7 +1545,7 @@ uip_process(uint8_t flag)
|
|||
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &uip_udp_conn->ripaddr);
|
||||
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
|
||||
|
||||
uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
|
||||
uip_appdata = &uip_buf[UIP_IPTCPH_LEN];
|
||||
|
||||
#if UIP_UDP_CHECKSUMS
|
||||
/* Calculate UDP checksum. */
|
||||
|
@ -1728,7 +1728,7 @@ uip_process(uint8_t flag)
|
|||
/* Parse the TCP MSS option, if present. */
|
||||
if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
|
||||
for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
|
||||
opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
|
||||
opt = uip_buf[UIP_TCPIP_HLEN + c];
|
||||
if(opt == TCP_OPT_END) {
|
||||
/* End of options. */
|
||||
break;
|
||||
|
@ -1736,10 +1736,10 @@ uip_process(uint8_t flag)
|
|||
++c;
|
||||
/* NOP option. */
|
||||
} else if(opt == TCP_OPT_MSS &&
|
||||
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
||||
uip_buf[UIP_TCPIP_HLEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
||||
/* An MSS option with the right option length. */
|
||||
tmp16 = ((uint16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
|
||||
(uint16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
|
||||
tmp16 = ((uint16_t)uip_buf[UIP_TCPIP_HLEN + 2 + c] << 8) |
|
||||
(uint16_t)uip_buf[UIP_IPTCPH_LEN + 3 + c];
|
||||
uip_connr->initialmss = uip_connr->mss =
|
||||
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
|
||||
|
||||
|
@ -1748,12 +1748,12 @@ uip_process(uint8_t flag)
|
|||
} else {
|
||||
/* All other options have a length field, so that we easily
|
||||
can skip past them. */
|
||||
if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
|
||||
if(uip_buf[UIP_TCPIP_HLEN + 1 + c] == 0) {
|
||||
/* If the length field is zero, the options are malformed
|
||||
and we don't process them further. */
|
||||
break;
|
||||
}
|
||||
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
|
||||
c += uip_buf[UIP_TCPIP_HLEN + 1 + c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1915,7 +1915,7 @@ uip_process(uint8_t flag)
|
|||
/* Parse the TCP MSS option, if present. */
|
||||
if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
|
||||
for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
|
||||
opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
|
||||
opt = uip_buf[UIP_IPTCPH_LEN + c];
|
||||
if(opt == TCP_OPT_END) {
|
||||
/* End of options. */
|
||||
break;
|
||||
|
@ -1923,10 +1923,10 @@ uip_process(uint8_t flag)
|
|||
++c;
|
||||
/* NOP option. */
|
||||
} else if(opt == TCP_OPT_MSS &&
|
||||
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
||||
uip_buf[UIP_TCPIP_HLEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
||||
/* An MSS option with the right option length. */
|
||||
tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
|
||||
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
|
||||
tmp16 = (uip_buf[UIP_TCPIP_HLEN + 2 + c] << 8) |
|
||||
uip_buf[UIP_TCPIP_HLEN + 3 + c];
|
||||
uip_connr->initialmss =
|
||||
uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
|
||||
|
||||
|
@ -1935,12 +1935,12 @@ uip_process(uint8_t flag)
|
|||
} else {
|
||||
/* All other options have a length field, so that we easily
|
||||
can skip past them. */
|
||||
if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
|
||||
if(uip_buf[UIP_TCPIP_HLEN + 1 + c] == 0) {
|
||||
/* If the length field is zero, the options are malformed
|
||||
and we don't process them further. */
|
||||
break;
|
||||
}
|
||||
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
|
||||
c += uip_buf[UIP_TCPIP_HLEN + 1 + c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2054,7 +2054,7 @@ uip_process(uint8_t flag)
|
|||
When the application is called, the global variable uip_len
|
||||
contains the length of the incoming data. The application can
|
||||
access the incoming data through the global pointer
|
||||
uip_appdata, which usually points UIP_IPTCPH_LEN + UIP_LLH_LEN
|
||||
uip_appdata, which usually points UIP_IPTCPH_LEN
|
||||
bytes into the uip_buf array.
|
||||
|
||||
If the application wishes to send any data, this data should be
|
||||
|
@ -2307,10 +2307,10 @@ uip_send(const void *data, int len)
|
|||
int copylen;
|
||||
|
||||
if(uip_sappdata != NULL) {
|
||||
copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN -
|
||||
copylen = MIN(len, UIP_BUFSIZE - UIP_TCPIP_HLEN -
|
||||
(int)((char *)uip_sappdata - (char *)UIP_TCP_PAYLOAD));
|
||||
} else {
|
||||
copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN);
|
||||
copylen = MIN(len, UIP_BUFSIZE - UIP_TCPIP_HLEN);
|
||||
}
|
||||
if(copylen > 0) {
|
||||
uip_slen = copylen;
|
||||
|
|
|
@ -121,26 +121,6 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The link level header length.
|
||||
*
|
||||
* This is the offset into the uip_buf where the IP header can be
|
||||
* found. For Ethernet, this should be set to 14. For SLIP, this
|
||||
* should be set to 0.
|
||||
*
|
||||
* \note we probably won't use this constant for other link layers than
|
||||
* ethernet as they have variable header length (this is due to variable
|
||||
* number and type of address fields and to optional security features)
|
||||
* E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14
|
||||
* 802.11 -> 4 + (6*3/4) + 2
|
||||
* \hideinitializer
|
||||
*/
|
||||
#ifdef UIP_CONF_LLH_LEN
|
||||
#define UIP_LLH_LEN (UIP_CONF_LLH_LEN)
|
||||
#else /* UIP_LLH_LEN */
|
||||
#define UIP_LLH_LEN 0
|
||||
#endif /* UIP_CONF_LLH_LEN */
|
||||
|
||||
/**
|
||||
* The size of the uIP packet buffer.
|
||||
*
|
||||
|
@ -151,12 +131,11 @@
|
|||
* \hideinitializer
|
||||
*/
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_BUFSIZE (UIP_LINK_MTU + UIP_LLH_LEN)
|
||||
#define UIP_BUFSIZE (UIP_LINK_MTU)
|
||||
#else /* UIP_CONF_BUFFER_SIZE */
|
||||
#define UIP_BUFSIZE (UIP_CONF_BUFFER_SIZE)
|
||||
#endif /* UIP_CONF_BUFFER_SIZE */
|
||||
|
||||
|
||||
/**
|
||||
* Determines if statistics support should be compiled in.
|
||||
*
|
||||
|
@ -435,15 +414,15 @@ void uip_log(char *msg);
|
|||
* The TCP maximum segment size.
|
||||
*
|
||||
* This is should not be to set to more than
|
||||
* UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
|
||||
* UIP_BUFSIZE - UIP_TCPIP_HLEN.
|
||||
*/
|
||||
#ifdef UIP_CONF_TCP_MSS
|
||||
#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
|
||||
#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_TCPIP_HLEN)
|
||||
#error UIP_CONF_TCP_MSS is too large for the current UIP_BUFSIZE
|
||||
#endif /* UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) */
|
||||
#endif /* UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_TCPIP_HLEN) */
|
||||
#define UIP_TCP_MSS (UIP_CONF_TCP_MSS)
|
||||
#else /* UIP_CONF_TCP_MSS */
|
||||
#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
|
||||
#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_TCPIP_HLEN)
|
||||
#endif /* UIP_CONF_TCP_MSS */
|
||||
|
||||
/**
|
||||
|
|
|
@ -139,7 +139,7 @@ ip64_arp_timer(void)
|
|||
{
|
||||
struct arp_entry *tabptr;
|
||||
int i;
|
||||
|
||||
|
||||
++arptime;
|
||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
||||
tabptr = &arp_table[i];
|
||||
|
@ -157,7 +157,7 @@ arp_update(uip_ip4addr_t *ipaddr, struct uip_eth_addr *ethaddr)
|
|||
{
|
||||
register struct arp_entry *tabptr = arp_table;
|
||||
int i, c;
|
||||
|
||||
|
||||
/* Walk through the ARP mapping table and try to find an entry to
|
||||
update. If none is found, the IP -> MAC address mapping is
|
||||
inserted in the ARP table. */
|
||||
|
@ -170,7 +170,7 @@ arp_update(uip_ip4addr_t *ipaddr, struct uip_eth_addr *ethaddr)
|
|||
/* Check if the source IP address of the incoming packet matches
|
||||
the IP address in this ARP table entry. */
|
||||
if(uip_ip4addr_cmp(ipaddr, &tabptr->ipaddr)) {
|
||||
|
||||
|
||||
/* An old entry found, update this and return. */
|
||||
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
|
||||
tabptr->time = arptime;
|
||||
|
@ -239,7 +239,7 @@ ip64_arp_arp_input(const uint8_t *packet, uint16_t packet_len)
|
|||
table, since it is likely that we will do more communication
|
||||
with this host in the future. */
|
||||
arp_update(&arphdr->sipaddr, &arphdr->shwaddr);
|
||||
|
||||
|
||||
arphdr->opcode = UIP_HTONS(ARP_REPLY);
|
||||
|
||||
memcpy(arphdr->dhwaddr.addr, arphdr->shwaddr.addr, 6);
|
||||
|
@ -275,7 +275,7 @@ ip64_arp_check_cache(const uint8_t *nlhdr)
|
|||
|
||||
printf("check cache %d.%d.%d.%d\n",
|
||||
uip_ipaddr_to_quad(&ipv4_hdr->destipaddr));
|
||||
|
||||
|
||||
/* First check if destination is a local broadcast. */
|
||||
uip_ipaddr(&broadcast_addr, 255,255,255,255);
|
||||
if(uip_ip4addr_cmp(&ipv4_hdr->destipaddr, &broadcast_addr)) {
|
||||
|
@ -321,7 +321,7 @@ ip64_arp_create_ethhdr(uint8_t *llhdr, const uint8_t *nlhdr)
|
|||
struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)nlhdr;
|
||||
struct ip64_eth_hdr *ethhdr = (struct ip64_eth_hdr *)llhdr;
|
||||
uip_ip4addr_t broadcast_addr;
|
||||
|
||||
|
||||
/* Find the destination IP address in the ARP table and construct
|
||||
the Ethernet header. If the destination IP addres isn't on the
|
||||
local network, we use the default router's IP address instead.
|
||||
|
@ -371,7 +371,7 @@ ip64_arp_create_ethhdr(uint8_t *llhdr, const uint8_t *nlhdr)
|
|||
|
||||
}
|
||||
memcpy(ethhdr->src.addr, ip64_eth_addr.addr, 6);
|
||||
|
||||
|
||||
ethhdr->type = UIP_HTONS(IP64_ETH_TYPE_IP);
|
||||
return sizeof(struct ip64_eth_hdr);
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr)
|
|||
struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)nlhdr;
|
||||
struct arp_hdr *arp_hdr = (struct arp_hdr *)llhdr;
|
||||
uip_ip4addr_t ipaddr;
|
||||
|
||||
|
||||
if(!uip_ipaddr_maskcmp(&ipv4_hdr->destipaddr,
|
||||
ip64_get_hostaddr(),
|
||||
ip64_get_netmask())) {
|
||||
|
@ -394,7 +394,7 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr)
|
|||
/* Else, we use the destination IP address. */
|
||||
uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr);
|
||||
}
|
||||
|
||||
|
||||
memset(arp_hdr->ethhdr.dest.addr, 0xff, 6);
|
||||
memset(arp_hdr->dhwaddr.addr, 0x00, 6);
|
||||
memcpy(arp_hdr->ethhdr.src.addr, ip64_eth_addr.addr, 6);
|
||||
|
@ -408,8 +408,8 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr)
|
|||
arp_hdr->hwlen = 6;
|
||||
arp_hdr->protolen = 4;
|
||||
arp_hdr->ethhdr.type = UIP_HTONS(IP64_ETH_TYPE_ARP);
|
||||
|
||||
uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
|
||||
|
||||
uip_appdata = &uip_buf[UIP_TCPIP_HLEN];
|
||||
|
||||
return sizeof(struct arp_hdr);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ struct dhcp_msg {
|
|||
uint8_t options[312];
|
||||
};
|
||||
|
||||
#if (UIP_BUFSIZE - UIP_LLH_LEN - UIP_UDPIP_HLEN) < 548
|
||||
#if (UIP_BUFSIZE - UIP_UDPIP_HLEN) < 548
|
||||
#error UIP_CONF_BUFFER_SIZE may be too small to accomodate DHCPv4 packets
|
||||
#error Increase UIP_CONF_BUFFER_SIZE in your project-conf.h, or contiki-conf.h
|
||||
#error A good size is 600 bytes
|
||||
|
@ -191,12 +191,12 @@ send_request(void)
|
|||
struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;
|
||||
|
||||
create_msg(m);
|
||||
|
||||
|
||||
end = add_msg_type(&m->options[4], DHCPREQUEST);
|
||||
end = add_server_id(end);
|
||||
end = add_req_ipaddr(end);
|
||||
end = add_end(end);
|
||||
|
||||
|
||||
uip_send(uip_appdata, (int)(end - (uint8_t *)uip_appdata));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -239,7 +239,7 @@ static uint8_t
|
|||
parse_msg(void)
|
||||
{
|
||||
struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;
|
||||
|
||||
|
||||
if(m->op == DHCP_REPLY &&
|
||||
memcmp(m->xid, &xid, sizeof(xid)) == 0 &&
|
||||
memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) {
|
||||
|
@ -258,7 +258,7 @@ msg_for_me(void)
|
|||
struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;
|
||||
uint8_t *optptr = &m->options[4];
|
||||
uint8_t *end = (uint8_t*)uip_appdata + uip_datalen();
|
||||
|
||||
|
||||
if(m->op == DHCP_REPLY &&
|
||||
memcmp(m->xid, &xid, sizeof(xid)) == 0 &&
|
||||
memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) {
|
||||
|
@ -280,7 +280,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data))
|
|||
clock_time_t ticks;
|
||||
|
||||
PT_BEGIN(&s.pt);
|
||||
|
||||
|
||||
init:
|
||||
xid++;
|
||||
s.state = STATE_SENDING;
|
||||
|
@ -305,7 +305,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data))
|
|||
s.ticks *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
selecting:
|
||||
s.ticks = CLOCK_SECOND;
|
||||
do {
|
||||
|
@ -330,7 +330,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data))
|
|||
goto init;
|
||||
}
|
||||
} while(s.state != STATE_CONFIG_RECEIVED);
|
||||
|
||||
|
||||
bound:
|
||||
#if 0
|
||||
printf("Got IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&s.ipaddr));
|
||||
|
@ -343,7 +343,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data))
|
|||
#endif
|
||||
|
||||
ip64_dhcpc_configured(&s);
|
||||
|
||||
|
||||
#define MAX_TICKS (~((clock_time_t)0) / 2)
|
||||
#define MAX_TICKS32 (~((uint32_t)0))
|
||||
#define IMIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
@ -407,12 +407,12 @@ ip64_dhcpc_init(const void *mac_addr, int mac_len)
|
|||
uip_ip6addr_t v6addr;
|
||||
uip_ip4addr_t v4addr;
|
||||
struct uip_udp_conn *conn2;
|
||||
|
||||
|
||||
s.mac_addr = mac_addr;
|
||||
s.mac_len = mac_len;
|
||||
|
||||
s.state = STATE_INITIAL;
|
||||
uip_ipaddr(&v4addr, 255,255,255,255);
|
||||
uip_ipaddr(&v4addr, 255,255,255,255);
|
||||
ip64_addr_4to6(&v4addr, &v6addr);
|
||||
s.conn = udp_new(&v6addr, UIP_HTONS(IP64_DHCPC_SERVER_PORT), NULL);
|
||||
conn2 = udp_new(NULL, UIP_HTONS(IP64_DHCPC_SERVER_PORT), NULL);
|
||||
|
@ -437,7 +437,7 @@ void
|
|||
ip64_dhcpc_request(void)
|
||||
{
|
||||
uip_ipaddr_t ipaddr;
|
||||
|
||||
|
||||
if(s.state == STATE_INITIAL) {
|
||||
uip_ipaddr(&ipaddr, 0,0,0,0);
|
||||
uip_sethostaddr(&ipaddr);
|
||||
|
|
|
@ -60,7 +60,7 @@ ip64_eth_interface_input(uint8_t *packet, uint16_t len)
|
|||
printf("-------------->\n");
|
||||
uip_len = ip64_4to6(&packet[sizeof(struct ip64_eth_hdr)],
|
||||
len - sizeof(struct ip64_eth_hdr),
|
||||
&uip_buf[UIP_LLH_LEN]);
|
||||
uip_buf);
|
||||
if(uip_len > 0) {
|
||||
printf("ip64_interface_process: converted %d bytes\n", uip_len);
|
||||
|
||||
|
@ -94,7 +94,7 @@ output(void)
|
|||
PRINTF("\n");
|
||||
|
||||
printf("<--------------\n");
|
||||
len = ip64_6to4(&uip_buf[UIP_LLH_LEN], uip_len,
|
||||
len = ip64_6to4(uip_buf, uip_len,
|
||||
&ip64_packet_buffer[sizeof(struct ip64_eth_hdr)]);
|
||||
|
||||
printf("ip64-interface: output len %d\n", len);
|
||||
|
|
|
@ -55,24 +55,24 @@ static void
|
|||
input_callback(void)
|
||||
{
|
||||
/*PRINTF("SIN: %u\n", uip_len);*/
|
||||
if(uip_buf[UIP_LLH_LEN] == '!') {
|
||||
PRINTF("Got configuration message of type %c\n", uip_buf[UIP_LLH_LEN + 1]);
|
||||
if(uip_buf[0] == '!') {
|
||||
PRINTF("Got configuration message of type %c\n", uip_buf[1]);
|
||||
uipbuf_clear();
|
||||
#if 0
|
||||
if(uip_buf[UIP_LLH_LEN + 1] == 'P') {
|
||||
if(uip_buf[1] == 'P') {
|
||||
uip_ipaddr_t prefix;
|
||||
/* Here we set a prefix !!! */
|
||||
memset(&prefix, 0, 16);
|
||||
memcpy(&prefix, &uip_buf[UIP_LLH_LEN + 2], 8);
|
||||
memcpy(&prefix, &uip_buf[2], 8);
|
||||
PRINTF("Setting prefix ");
|
||||
PRINT6ADDR(&prefix);
|
||||
PRINTF("\n");
|
||||
set_prefix_64(&prefix);
|
||||
}
|
||||
#endif
|
||||
} else if(uip_buf[UIP_LLH_LEN] == '?') {
|
||||
PRINTF("Got request message of type %c\n", uip_buf[UIP_LLH_LEN + 1]);
|
||||
if(uip_buf[UIP_LLH_LEN + 1] == 'M') {
|
||||
} else if(uip_buf[0] == '?') {
|
||||
PRINTF("Got request message of type %c\n", uip_buf[1]);
|
||||
if(uip_buf[1] == 'M') {
|
||||
const char *hexchar = "0123456789abcdef";
|
||||
int j;
|
||||
/* this is just a test so far... just to see if it works */
|
||||
|
@ -91,10 +91,10 @@ input_callback(void)
|
|||
packet back if no route is found */
|
||||
uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr);
|
||||
|
||||
uint16_t len = ip64_4to6(&uip_buf[UIP_LLH_LEN], uip_len,
|
||||
uint16_t len = ip64_4to6(uip_buf, uip_len,
|
||||
ip64_packet_buffer);
|
||||
if(len > 0) {
|
||||
memcpy(&uip_buf[UIP_LLH_LEN], ip64_packet_buffer, len);
|
||||
memcpy(uip_buf, ip64_packet_buffer, len);
|
||||
uip_len = len;
|
||||
/* PRINTF("send len %d\n", len); */
|
||||
} else {
|
||||
|
@ -127,11 +127,11 @@ output(void)
|
|||
if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
|
||||
PRINTF("ip64-interface: output, not sending bounced message\n");
|
||||
} else {
|
||||
len = ip64_6to4(&uip_buf[UIP_LLH_LEN], uip_len,
|
||||
len = ip64_6to4(uip_buf, uip_len,
|
||||
ip64_packet_buffer);
|
||||
PRINTF("ip64-interface: output len %d\n", len);
|
||||
if(len > 0) {
|
||||
memcpy(&uip_buf[UIP_LLH_LEN], ip64_packet_buffer, len);
|
||||
memcpy(uip_buf, ip64_packet_buffer, len);
|
||||
uip_len = len;
|
||||
slip_send();
|
||||
return len;
|
||||
|
|
|
@ -68,14 +68,14 @@ static void
|
|||
slip_input_callback(void)
|
||||
{
|
||||
LOG_DBG("SIN: %u\n", uip_len);
|
||||
if(uip_buf[UIP_LLH_LEN] == '!') {
|
||||
if(uip_buf[0] == '!') {
|
||||
LOG_INFO("Got configuration message of type %c\n",
|
||||
uip_buf[UIP_LLH_LEN + 1]);
|
||||
if(uip_buf[UIP_LLH_LEN + 1] == 'P') {
|
||||
uip_buf[1]);
|
||||
if(uip_buf[1] == 'P') {
|
||||
uip_ipaddr_t prefix;
|
||||
/* Here we set a prefix !!! */
|
||||
memset(&prefix, 0, 16);
|
||||
memcpy(&prefix, &uip_buf[UIP_LLH_LEN + 2], 8);
|
||||
memcpy(&prefix, &uip_buf[2], 8);
|
||||
|
||||
uipbuf_clear();
|
||||
|
||||
|
@ -86,9 +86,9 @@ slip_input_callback(void)
|
|||
}
|
||||
uipbuf_clear();
|
||||
|
||||
} else if(uip_buf[UIP_LLH_LEN] == '?') {
|
||||
LOG_INFO("Got request message of type %c\n", uip_buf[UIP_LLH_LEN + 1]);
|
||||
if(uip_buf[UIP_LLH_LEN + 1] == 'M') {
|
||||
} else if(uip_buf[0] == '?') {
|
||||
LOG_INFO("Got request message of type %c\n", uip_buf[1]);
|
||||
if(uip_buf[1] == 'M') {
|
||||
char *hexchar = "0123456789abcdef";
|
||||
int j;
|
||||
/* this is just a test so far... just to see if it works */
|
||||
|
|
|
@ -256,7 +256,7 @@ output(void)
|
|||
{
|
||||
LOG_DBG("SUT: %u\n", uip_len);
|
||||
if(uip_len > 0) {
|
||||
return tun_output(&uip_buf[UIP_LLH_LEN], uip_len);
|
||||
return tun_output(uip_buf, uip_len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ handle_fd(fd_set *rset, fd_set *wset)
|
|||
int size;
|
||||
|
||||
if(FD_ISSET(tunfd, rset)) {
|
||||
size = tun_input(&uip_buf[UIP_LLH_LEN], sizeof(uip_buf));
|
||||
size = tun_input(uip_buf, sizeof(uip_buf));
|
||||
/* printf("TUN data incoming read:%d\n", size); */
|
||||
uip_len = size;
|
||||
tcpip_input();
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
ifdef CONTIKI_HOME
|
||||
CONTIKI = $(CONTIKI_HOME)
|
||||
else
|
||||
ifndef CONTIKI
|
||||
CONTIKI=../../..
|
||||
endif
|
||||
endif
|
||||
|
||||
DEFINES=WITH_SLIP=1
|
||||
|
||||
ifndef TARGET
|
||||
TARGET=sky
|
||||
endif
|
||||
|
||||
MODULES_REL += dev
|
||||
PROJECT_SOURCEFILES = fakeuip.c sicslow_ethernet.c
|
||||
|
||||
all: uip6-bridge-tap.sky
|
||||
|
||||
upload: uip6-bridge-tap.ihex
|
||||
cp $< $(IHEXFILE)
|
||||
$(MAKE) sky-u.$(subst /,-,$(word $(MOTE), $(MOTES)))
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
||||
../../tapslip6: ../../tapslip6.c
|
||||
(cd ../../; $(MAKE) tapslip6)
|
||||
|
||||
ifndef MOTE
|
||||
MOTE=1
|
||||
endif
|
||||
|
||||
connect: ../../tapslip6
|
||||
sudo ../../tapslip6 -t tap0 -s $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) 127.0.0.1 255.0.0.0
|
||||
|
||||
bridge:
|
||||
@sudo service radvd restart || echo radvd could not be restarted
|
||||
sudo route add -6 fd00::/64 tap0
|
||||
sudo ip -6 address add fd00::1/64 dev tap0
|
|
@ -1,322 +0,0 @@
|
|||
/* -*- C -*- */
|
||||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "dev/ds2411/ds2411.h"
|
||||
#include "contiki.h"
|
||||
|
||||
#include "net/ipv6/uip.h"
|
||||
|
||||
#include "dev/slip.h"
|
||||
|
||||
#define SLIP_END 0300
|
||||
#define SLIP_ESC 0333
|
||||
#define SLIP_ESC_END 0334
|
||||
#define SLIP_ESC_ESC 0335
|
||||
|
||||
PROCESS(slip_process, "SLIP driver");
|
||||
|
||||
uint8_t slip_active;
|
||||
|
||||
#if 1
|
||||
#define SLIP_STATISTICS(statement)
|
||||
#else
|
||||
uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop;
|
||||
#define SLIP_STATISTICS(statement) statement
|
||||
#endif
|
||||
|
||||
/* Must be at least one byte larger than UIP_BUFSIZE! */
|
||||
#define RX_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN + 16)
|
||||
|
||||
enum {
|
||||
STATE_TWOPACKETS = 0, /* We have 2 packets and drop incoming data. */
|
||||
STATE_OK = 1,
|
||||
STATE_ESC = 2,
|
||||
STATE_RUBBISH = 3,
|
||||
};
|
||||
|
||||
/*
|
||||
* Variables begin and end manage the buffer space in a cyclic
|
||||
* fashion. The first used byte is at begin and end is one byte past
|
||||
* the last. I.e. [begin, end) is the actively used space.
|
||||
*
|
||||
* If begin != pkt_end we have a packet at [begin, pkt_end),
|
||||
* furthermore, if state == STATE_TWOPACKETS we have one more packet at
|
||||
* [pkt_end, end). If more bytes arrive in state STATE_TWOPACKETS
|
||||
* they are discarded.
|
||||
*/
|
||||
|
||||
static uint8_t state = STATE_TWOPACKETS;
|
||||
static uint16_t begin, end;
|
||||
static uint8_t rxbuf[RX_BUFSIZE];
|
||||
static uint16_t pkt_end; /* SLIP_END tracker. */
|
||||
|
||||
static void (* input_callback)(void) = NULL;
|
||||
static void (* tcpip_input_callback)(void) = NULL;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_set_input_callback(void (*c)(void))
|
||||
{
|
||||
input_callback = c;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_set_tcpip_input_callback(void (*c)(void))
|
||||
{
|
||||
tcpip_input_callback = c;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint8_t
|
||||
slip_write(const void *_ptr, int len)
|
||||
{
|
||||
const uint8_t *ptr = _ptr;
|
||||
uint16_t i;
|
||||
uint8_t c;
|
||||
|
||||
slip_arch_writeb(SLIP_END);
|
||||
|
||||
for(i = 0; i < len; ++i) {
|
||||
c = *ptr++;
|
||||
if(c == SLIP_END) {
|
||||
slip_arch_writeb(SLIP_ESC);
|
||||
c = SLIP_ESC_END;
|
||||
} else if(c == SLIP_ESC) {
|
||||
slip_arch_writeb(SLIP_ESC);
|
||||
c = SLIP_ESC_ESC;
|
||||
}
|
||||
slip_arch_writeb(c);
|
||||
}
|
||||
slip_arch_writeb(SLIP_END);
|
||||
|
||||
return len;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
rxbuf_init(void)
|
||||
{
|
||||
begin = end = pkt_end = 0;
|
||||
state = STATE_OK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Upper half does the polling. */
|
||||
static uint16_t
|
||||
slip_poll_handler(uint8_t *outbuf, uint16_t blen)
|
||||
{
|
||||
/* This is a hack and won't work across buffer edge! */
|
||||
if(rxbuf[begin] == 'C') {
|
||||
int i;
|
||||
if(begin < end && (end - begin) >= 6
|
||||
&& memcmp(&rxbuf[begin], "CLIENT", 6) == 0) {
|
||||
state = STATE_TWOPACKETS; /* Interrupts do nothing. */
|
||||
memset(&rxbuf[begin], 0x0, 6);
|
||||
|
||||
rxbuf_init();
|
||||
|
||||
for(i = 0; i < 13; i++) {
|
||||
slip_arch_writeb("CLIENTSERVER\300"[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} else if(rxbuf[begin] == '?') {
|
||||
int i, j;
|
||||
char* hexchar = "0123456789abcdef";
|
||||
if(begin < end && (end - begin) >= 2
|
||||
&& rxbuf[begin + 1] == 'M') {
|
||||
state = STATE_TWOPACKETS; /* Interrupts do nothing. */
|
||||
rxbuf[begin] = 0;
|
||||
rxbuf[begin + 1] = 0;
|
||||
|
||||
rxbuf_init();
|
||||
|
||||
/* this is just a test so far... just to see if it works */
|
||||
slip_arch_writeb('!');
|
||||
slip_arch_writeb('M');
|
||||
for(j = 0; j < 8; j++) {
|
||||
slip_arch_writeb(hexchar[ds2411_id[j] >> 4]);
|
||||
slip_arch_writeb(hexchar[ds2411_id[j] & 15]);
|
||||
}
|
||||
slip_arch_writeb(SLIP_END);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Interrupt can not change begin but may change pkt_end.
|
||||
* If pkt_end != begin it will not change again.
|
||||
*/
|
||||
if(begin != pkt_end) {
|
||||
uint16_t len;
|
||||
|
||||
if(begin < pkt_end) {
|
||||
len = pkt_end - begin;
|
||||
if(len > blen) {
|
||||
len = 0;
|
||||
} else {
|
||||
memcpy(outbuf, &rxbuf[begin], len);
|
||||
}
|
||||
} else {
|
||||
len = (RX_BUFSIZE - begin) + (pkt_end - 0);
|
||||
if(len > blen) {
|
||||
len = 0;
|
||||
} else {
|
||||
unsigned i;
|
||||
for(i = begin; i < RX_BUFSIZE; i++) {
|
||||
*outbuf++ = rxbuf[i];
|
||||
}
|
||||
for(i = 0; i < pkt_end; i++) {
|
||||
*outbuf++ = rxbuf[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove data from buffer together with the copied packet. */
|
||||
begin = pkt_end;
|
||||
if(state == STATE_TWOPACKETS) {
|
||||
pkt_end = end;
|
||||
state = STATE_OK; /* Assume no bytes where lost! */
|
||||
|
||||
/* One more packet is buffered, need to be polled again! */
|
||||
process_poll(&slip_process);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(slip_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
rxbuf_init();
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
||||
|
||||
slip_active = 1;
|
||||
|
||||
/* Move packet from rxbuf to buffer provided by uIP. */
|
||||
uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN],
|
||||
UIP_BUFSIZE - UIP_LLH_LEN);
|
||||
if(uip_len > 0) {
|
||||
if(tcpip_input_callback) {
|
||||
tcpip_input_callback();
|
||||
} else {
|
||||
tcpip_input();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
slip_input_byte(unsigned char c)
|
||||
{
|
||||
switch(state) {
|
||||
case STATE_RUBBISH:
|
||||
if(c == SLIP_END) {
|
||||
state = STATE_OK;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case STATE_TWOPACKETS: /* Two packets are already buffered! */
|
||||
return 0;
|
||||
|
||||
case STATE_ESC:
|
||||
if(c == SLIP_ESC_END) {
|
||||
c = SLIP_END;
|
||||
} else if(c == SLIP_ESC_ESC) {
|
||||
c = SLIP_ESC;
|
||||
} else {
|
||||
state = STATE_RUBBISH;
|
||||
SLIP_STATISTICS(slip_rubbish++);
|
||||
end = pkt_end; /* remove rubbish */
|
||||
return 0;
|
||||
}
|
||||
state = STATE_OK;
|
||||
break;
|
||||
|
||||
case STATE_OK:
|
||||
if(c == SLIP_ESC) {
|
||||
state = STATE_ESC;
|
||||
return 0;
|
||||
} else if(c == SLIP_END) {
|
||||
/*
|
||||
* We have a new packet, possibly of zero length.
|
||||
*
|
||||
* There may already be one packet buffered.
|
||||
*/
|
||||
if(end != pkt_end) { /* Non zero length. */
|
||||
if(begin == pkt_end) { /* None buffered. */
|
||||
pkt_end = end;
|
||||
} else {
|
||||
state = STATE_TWOPACKETS;
|
||||
SLIP_STATISTICS(slip_twopackets++);
|
||||
}
|
||||
process_poll(&slip_process);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* add_char: */
|
||||
{
|
||||
unsigned next;
|
||||
next = end + 1;
|
||||
if(next == RX_BUFSIZE) {
|
||||
next = 0;
|
||||
}
|
||||
if(next == begin) { /* rxbuf is full */
|
||||
state = STATE_RUBBISH;
|
||||
SLIP_STATISTICS(slip_overflow++);
|
||||
end = pkt_end; /* remove rubbish */
|
||||
return 0;
|
||||
}
|
||||
rxbuf[end] = c;
|
||||
end = next;
|
||||
}
|
||||
|
||||
/* There could be a separate poll routine for this. */
|
||||
if(c == 'T' && rxbuf[begin] == 'C') {
|
||||
process_poll(&slip_process);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,92 +0,0 @@
|
|||
/* -*- C -*- */
|
||||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SLIP_H_
|
||||
#define SLIP_H_
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
PROCESS_NAME(slip_process);
|
||||
|
||||
/**
|
||||
* Send an IP packet from the uIP buffer with SLIP.
|
||||
*/
|
||||
uint8_t slip_send(void);
|
||||
|
||||
/**
|
||||
* Input a SLIP byte.
|
||||
*
|
||||
* This function is called by the RS232/SIO device driver to pass
|
||||
* incoming bytes to the SLIP driver. The function can be called from
|
||||
* an interrupt context.
|
||||
*
|
||||
* For systems using low-power CPU modes, the return value of the
|
||||
* function can be used to determine if the CPU should be woken up or
|
||||
* not. If the function returns non-zero, the CPU should be powered
|
||||
* up. If the function returns zero, the CPU can continue to be
|
||||
* powered down.
|
||||
*
|
||||
* \param c The data that is to be passed to the SLIP driver
|
||||
*
|
||||
* \return Non-zero if the CPU should be powered up, zero otherwise.
|
||||
*/
|
||||
int slip_input_byte(unsigned char c);
|
||||
|
||||
uint8_t slip_write(const void *ptr, int len);
|
||||
|
||||
/* Did we receive any bytes lately? */
|
||||
extern uint8_t slip_active;
|
||||
|
||||
/* Statistics. */
|
||||
extern uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop;
|
||||
|
||||
/**
|
||||
* Set a function to be called when there is activity on the SLIP
|
||||
* interface; used for detecting if a node is a gateway node.
|
||||
*/
|
||||
void slip_set_input_callback(void (*callback)(void));
|
||||
|
||||
/**
|
||||
* Set a function to be called when a packet has been received.
|
||||
* Default is tcpip_input().
|
||||
*/
|
||||
void slip_set_tcpip_input_callback(void (*callback)(void));
|
||||
|
||||
/*
|
||||
* These machine dependent functions and an interrupt service routine
|
||||
* must be provided externally (slip_arch.c).
|
||||
*/
|
||||
void slip_arch_init(void);
|
||||
void slip_arch_writeb(unsigned char c);
|
||||
|
||||
#endif /* SLIP_H_ */
|
|
@ -1,134 +0,0 @@
|
|||
|
||||
/* 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 */
|
||||
|
||||
|
||||
#include "net/ipv6/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#include <string.h>
|
||||
|
||||
uip_buf_t uip_aligned_buf;
|
||||
|
||||
uint16_t uip_len;
|
||||
|
||||
struct uip_stats uip_stat;
|
||||
|
||||
uip_lladdr_t uip_lladdr;
|
||||
|
||||
uint16_t uip_htons(uint16_t val) { return UIP_HTONS(val);}
|
||||
|
||||
uip_ds6_netif_t uip_ds6_if;
|
||||
|
||||
/********** UIP_DS6.c **********/
|
||||
|
||||
void
|
||||
uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
|
||||
{
|
||||
/* We consider only links with IEEE EUI-64 identifier or
|
||||
IEEE 48-bit MAC addresses */
|
||||
#if (UIP_LLADDR_LEN == 8)
|
||||
memcpy(ipaddr->u8 + 8, lladdr, UIP_LLADDR_LEN);
|
||||
ipaddr->u8[8] ^= 0x02;
|
||||
#elif (UIP_LLADDR_LEN == 6)
|
||||
memcpy(ipaddr->u8 + 8, lladdr, 3);
|
||||
ipaddr->u8[11] = 0xff;
|
||||
ipaddr->u8[12] = 0xfe;
|
||||
memcpy(ipaddr->u8 + 13, lladdr + 3, 3);
|
||||
ipaddr->u8[8] ^= 0x02;
|
||||
#else
|
||||
#error fakeuip.c cannot build interface address when UIP_LLADDR_LEN is not 6 or 8
|
||||
#endif
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* get a link local address -
|
||||
* state = -1 => any address is ok. Otherwise state = desired state of addr.
|
||||
* (TENTATIVE, PREFERRED, DEPRECATED)
|
||||
*/
|
||||
uip_ds6_addr_t *
|
||||
uip_ds6_get_link_local(int8_t state) {
|
||||
uip_ds6_addr_t *locaddr;
|
||||
for(locaddr = uip_ds6_if.addr_list;
|
||||
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
||||
if((locaddr->isused) && (state == - 1 || locaddr->state == state)
|
||||
&& (uip_is_addr_linklocal(&locaddr->ipaddr))) {
|
||||
return locaddr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uip_ds6_addr_t *
|
||||
uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/********** UIP.c ****************/
|
||||
|
||||
static uint16_t
|
||||
chksum(uint16_t sum, const uint8_t *data, uint16_t len)
|
||||
{
|
||||
uint16_t t;
|
||||
const uint8_t *dataptr;
|
||||
const uint8_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 uint16_t
|
||||
upper_layer_chksum(uint8_t proto)
|
||||
{
|
||||
uint16_t upper_layer_len;
|
||||
uint16_t sum;
|
||||
|
||||
upper_layer_len = uipbuf_get_len_field(UIP_IP_BUF);
|
||||
|
||||
/* 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, (uint8_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 : uip_htons(sum);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t
|
||||
uip_icmp6chksum(void)
|
||||
{
|
||||
return upper_layer_chksum(UIP_PROTO_ICMP6);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uip_ds6_link_callback(int status, int numtx)
|
||||
{
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A brief description of what this file is
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef BRIDGE_CONF_H_
|
||||
#define BRIDGE_CONF_H_
|
||||
|
||||
#undef UIP_CONF_ROUTER
|
||||
|
||||
#undef UIP_CONF_LLH_LEN
|
||||
#define UIP_CONF_LLH_LEN 14
|
||||
|
||||
#undef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 256
|
||||
#endif /* BRIDGE_CONF_H_ */
|
|
@ -1,16 +0,0 @@
|
|||
interface tap0 {
|
||||
AdvSendAdvert on;
|
||||
AdvLinkMTU 1280;
|
||||
AdvCurHopLimit 128;
|
||||
AdvReachableTime 360000;
|
||||
MinRtrAdvInterval 100;
|
||||
MaxRtrAdvInterval 150;
|
||||
AdvDefaultLifetime 200;
|
||||
prefix AAAA::/64
|
||||
{
|
||||
AdvOnLink on;
|
||||
AdvAutonomous on;
|
||||
AdvPreferredLifetime 4294967295;
|
||||
AdvValidLifetime 4294967295;
|
||||
};
|
||||
};
|
|
@ -1,879 +0,0 @@
|
|||
/**
|
||||
* \file sicslow_ethernet.c
|
||||
* Routines to interface between Ethernet and 6LowPan
|
||||
*
|
||||
* \author
|
||||
* Colin O'Flynn <coflynn@newae.com>
|
||||
*
|
||||
* \addtogroup usbstick
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2008 by:
|
||||
* Colin O'Flynn coflynn@newae.com
|
||||
* Eric Gnoske egnoske@gmail.com
|
||||
* Blake Leverett bleverett@gmail.com
|
||||
* Mike Vidales mavida404@gmail.com
|
||||
* Kevin Brown kbrown3@uccs.edu
|
||||
* Nate Bohlmann nate@elfwerks.com
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of the copyright holders nor the names of
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
\ingroup usbstick
|
||||
\defgroup sicslowinterop 6LowPan Ethernet Interop
|
||||
@{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
\par Ethernet to 6LowPan Address Translation
|
||||
|
||||
It should be obvious that since 802.15.4 addresses are 8
|
||||
bytes, and 802.3 addresses are 6 bytes, some form of
|
||||
address translation is needed. These routines provide this
|
||||
|
||||
\par 802.3 Address Formats
|
||||
|
||||
802.3 MAC addresses used here have this form:
|
||||
|
||||
\verbatim
|
||||
+----+----+----+----+----+----+----+----+
|
||||
+ + + + + + TR + GL + MU +
|
||||
+----+----+----+----+----+----+----+----+
|
||||
\endverbatim
|
||||
|
||||
|
||||
It can be seen this is like a normal ethernet MAC address,
|
||||
with GL being the Global/Local bit, and MU being the
|
||||
Multicast/Unicast bit.
|
||||
|
||||
The addition is the 'TR' bit, which if set indicates that
|
||||
the address must be translated when going between 802.15.4
|
||||
and 802.3.
|
||||
|
||||
\par Address Translation
|
||||
|
||||
If the TRANSLATE (TR) bit is CLEAR, this means the 5th and
|
||||
4th LSBytes of the 802.15.4 address are fffe, aka the address
|
||||
has the hexidecial form:
|
||||
|
||||
xxxxxxfffexxxxxx
|
||||
|
||||
\note
|
||||
You should always aim to set the 802.15.4 addresses
|
||||
of the devices on your network to ones that will
|
||||
satisfy this requirement. Some examples are:
|
||||
\note
|
||||
0x02 23 42 ff fe 73 92 28
|
||||
\note
|
||||
0x82 00 82 ff fe cd ee 22
|
||||
|
||||
\note
|
||||
So the most significant octets MUST
|
||||
have bit 0 CLEAR, bit 1 SET, and bit 2 CLEAR. The remaining
|
||||
bits in this octet can be anything.
|
||||
|
||||
If the TRANSLATE bit is SET, this means the address on the
|
||||
802.3 side does not directly convert to an 802.15.4 address.
|
||||
To translate it, the remainder of the octet is used as an
|
||||
index in a look-up table. This look-up table simply stores
|
||||
the 4th, 5th, and 8th octet of the 802.15.4 address, and attaches
|
||||
them to the remaining 5 bytes of the 802.3 address.
|
||||
|
||||
In this way there can be 32 different 802.15.4 'prefixes',
|
||||
requiring only 96 bytes of RAM in a storage table on the
|
||||
802.3 to 802.15.4 bridge.
|
||||
|
||||
Mulitcast addresses on 802.3 are mapped to broadcast addresses on
|
||||
802.15.4 and vis-versa. Since IPv6 does not use 802.3 broadcast,
|
||||
this code will drop all 802.3 broadcast packets. They are most
|
||||
likely something unwanted, such as IPv4 packets that snuck in.
|
||||
|
||||
\par Notes on how addresses are stored
|
||||
|
||||
An 802.15.4 address will be reported for example as:
|
||||
|
||||
0x8877665544332211
|
||||
|
||||
Stored in the array as passed to these functions, it will be:
|
||||
\verbatim
|
||||
array[0] = 0x88;
|
||||
array[1] = 0x77;
|
||||
array[2] = 0x66;
|
||||
etc.
|
||||
\endverbatim
|
||||
|
||||
An 802.3 address will be reported for example as:
|
||||
02:43:53:35:45:45
|
||||
|
||||
Stored in the array as passed to these functions, it will be:
|
||||
\verbatim
|
||||
array[0] = 0x02;
|
||||
array[1] = 0x43;
|
||||
array[2] = 0x53;
|
||||
array[3] = 0x35
|
||||
etc.
|
||||
\endverbatim
|
||||
*/
|
||||
|
||||
#include "uip.h"
|
||||
#include "uip_arp.h" /* For ethernet header structure */
|
||||
#include "net/ipv6/sicslowpan.h"
|
||||
#include "sicslow_ethernet.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
//#define PRINTF printf
|
||||
#define PRINTF(...)
|
||||
|
||||
#define ETHBUF(x) ((struct uip_eth_hdr *)x)
|
||||
|
||||
//For little endian, such as our friend mr. AVR
|
||||
#ifndef LSB
|
||||
#define LSB(u16) (((uint8_t *)&(u16))[0]) //!< Least significant byte of \a u16.
|
||||
#define MSB(u16) (((uint8_t *)&(u16))[1]) //!< Most significant byte of \a u16.
|
||||
#endif
|
||||
|
||||
usbstick_mode_t usbstick_mode;
|
||||
|
||||
uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan);
|
||||
uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan);
|
||||
/* uint8_t memcmp_reverse(uint8_t * a, uint8_t * b, uint8_t num); */
|
||||
/* void mac_ethhijack_nondata(const struct mac_driver *r); */
|
||||
/* void mac_ethhijack(const struct mac_driver *r); */
|
||||
|
||||
/* extern void (*sicslowmac_snifferhook)(const struct mac_driver *r); */
|
||||
|
||||
|
||||
//! Location of TRANSLATE (TR) bit in Ethernet address
|
||||
#define TRANSLATE_BIT_MASK (1<<2)
|
||||
//! Location of LOCAL (GL) bit in Ethernet address
|
||||
#define LOCAL_BIT_MASK (1<<1)
|
||||
//! Location of MULTICAST (MU) bit in Ethernet address
|
||||
#define MULTICAST_BIT_MASK (1<<0)
|
||||
|
||||
#define PREFIX_BUFFER_SIZE 32
|
||||
|
||||
uint8_t prefixCounter;
|
||||
uint8_t prefixBuffer[PREFIX_BUFFER_SIZE][3];
|
||||
|
||||
/* 6lowpan max size + ethernet header size + 1 */
|
||||
uint8_t raw_buf[127+ UIP_LLH_LEN +1];
|
||||
|
||||
|
||||
/* void tcpip_input( void ) */
|
||||
/* { */
|
||||
/* mac_LowpanToEthernet(); */
|
||||
/* } */
|
||||
|
||||
/**
|
||||
* \brief Perform any setup needed
|
||||
*/
|
||||
/* struct mac_driver * pmac; */
|
||||
void mac_ethernetSetup(void)
|
||||
{
|
||||
usbstick_mode.sicslowpan = 1;
|
||||
usbstick_mode.sendToRf = 1;
|
||||
usbstick_mode.translate = 1;
|
||||
usbstick_mode.raw = 1;
|
||||
|
||||
/* sicslowinput = pinput; */
|
||||
|
||||
|
||||
/* pmac = sicslowmac_get_driver(); */
|
||||
/* pmac->set_receive_function(mac_ethhijack); */
|
||||
/* sicslowmac_snifferhook = mac_ethhijack_nondata; */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Take a packet received over the ethernet link, and send it
|
||||
* out over 802.15.4
|
||||
*/
|
||||
void mac_ethernetToLowpan(uint8_t * ethHeader)
|
||||
{
|
||||
//Dest address
|
||||
uip_lladdr_t destAddr;
|
||||
uip_lladdr_t *destAddrPtr = NULL;
|
||||
|
||||
PRINTF("Packet type: %x\n", ((struct uip_eth_hdr *) ethHeader)->type);
|
||||
|
||||
//RUM doesn't support sending data
|
||||
#if UIP_CONF_USE_RUM
|
||||
return;
|
||||
#endif
|
||||
|
||||
//If not IPv6 we don't do anything
|
||||
if (((struct uip_eth_hdr *) ethHeader)->type != UIP_HTONS(UIP_ETHTYPE_IPV6)) {
|
||||
PRINTF("eth2low: Packet is not IPv6, dropping\n");
|
||||
/* rndis_stat.txbad++; */
|
||||
uipbuf_clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// In sniffer mode we don't ever send anything
|
||||
if (usbstick_mode.sendToRf == 0) {
|
||||
uipbuf_clear();
|
||||
return;
|
||||
}
|
||||
|
||||
/* IPv6 uses 33-33-xx-xx-xx-xx prefix for multicast ND stuff */
|
||||
if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0x33) &&
|
||||
(((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0x33) )
|
||||
{
|
||||
PRINTF("eth2low: Ethernet multicast packet received\n");
|
||||
;//Do Nothing
|
||||
} else if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0xFF) &&
|
||||
(((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0xFF) &&
|
||||
(((struct uip_eth_hdr *) ethHeader)->dest.addr[2] == 0xFF) &&
|
||||
(((struct uip_eth_hdr *) ethHeader)->dest.addr[3] == 0xFF) &&
|
||||
(((struct uip_eth_hdr *) ethHeader)->dest.addr[4] == 0xFF) &&
|
||||
(((struct uip_eth_hdr *) ethHeader)->dest.addr[5] == 0xFF) ) {
|
||||
/* IPv6 does not use broadcast addresses, hence this should not happen */
|
||||
PRINTF("eth2low: Ethernet broadcast address received, should not happen?\n");
|
||||
/* rndis_stat.txbad++; */
|
||||
uipbuf_clear();
|
||||
return;
|
||||
} else {
|
||||
PRINTF("eth2low: Addressed packet received... ");
|
||||
//Check this returns OK
|
||||
if (mac_createSicslowpanLongAddr( &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), &destAddr) == 0) {
|
||||
PRINTF(" translation failed\n");
|
||||
/* rndis_stat.txbad++; */
|
||||
uipbuf_clear();
|
||||
return;
|
||||
}
|
||||
PRINTF(" translated OK\n");
|
||||
destAddrPtr = &destAddr;
|
||||
}
|
||||
|
||||
//Remove header from length before passing onward
|
||||
if(uip_len > UIP_LLH_LEN) {
|
||||
uip_len -= UIP_LLH_LEN;
|
||||
|
||||
//Some IP packets have link layer in them, need to change them around!
|
||||
if (usbstick_mode.translate) {
|
||||
/* uint8_t transReturn = */
|
||||
mac_translateIPLinkLayer(ll_802154_type);
|
||||
PRINTF("IPTranslation: returns %d\n", transReturn);
|
||||
}
|
||||
|
||||
if (usbstick_mode.sendToRf){
|
||||
tcpip_output(destAddrPtr);
|
||||
/* rndis_stat.txok++; */
|
||||
}
|
||||
}
|
||||
|
||||
uipbuf_clear();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Take a packet received over the 802.15.4 link, and send it
|
||||
* out over ethernet, performing any translations needed.
|
||||
*/
|
||||
void mac_LowpanToEthernet(void)
|
||||
{
|
||||
/* parsed_frame = sicslowmac_get_frame(); */
|
||||
|
||||
//Setup generic ethernet stuff
|
||||
ETHBUF(uip_buf)->type = uip_htons(UIP_ETHTYPE_IPV6);
|
||||
|
||||
//Check for broadcast message
|
||||
if(packetbuf_holds_broadcast()) {
|
||||
/* if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) && */
|
||||
/* ( parsed_frame->dest_addr->addr16 == 0xffff) ) { */
|
||||
ETHBUF(uip_buf)->dest.addr[0] = 0x33;
|
||||
ETHBUF(uip_buf)->dest.addr[1] = 0x33;
|
||||
ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
|
||||
ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
|
||||
ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
|
||||
ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
|
||||
} else {
|
||||
//Otherwise we have a real address
|
||||
mac_createEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->dest.addr[0]),
|
||||
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
|
||||
}
|
||||
|
||||
|
||||
mac_createEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]),
|
||||
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
||||
|
||||
//We only do address translation in network mode!
|
||||
if (usbstick_mode.translate) {
|
||||
//Some IP packets have link layer in them, need to change them around!
|
||||
mac_translateIPLinkLayer(ll_8023_type);
|
||||
}
|
||||
|
||||
PRINTF("Low2Eth: Sending packet to ethernet\n");
|
||||
|
||||
uip_len += UIP_LLH_LEN;
|
||||
|
||||
/* rndis_send(uip_buf, uip_len, 1); */
|
||||
/* rndis_stat.rxok++; */
|
||||
/* uipbuf_clear(); */
|
||||
}
|
||||
|
||||
/**
|
||||
* \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(lltype_t target)
|
||||
{
|
||||
|
||||
#if UIP_LLADDR_LEN == 8
|
||||
if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) {
|
||||
PRINTF("eth2low: ICMP Message detected\n");
|
||||
return mac_translateIcmpLinkLayer(target);
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#include "net/ipv6/uip-icmp6.h"
|
||||
#include "net/ipv6/uip-nd6.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
uint8_t data[16];
|
||||
} icmp_opts_t;
|
||||
|
||||
#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)UIP_IP_PAYLOAD(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(lltype_t target)
|
||||
{
|
||||
uint16_t icmp_opt_offset = 0;
|
||||
int16_t len = uipbuf_get_len_field(UIP_IP_BUF);
|
||||
|
||||
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
|
||||
if (target == ll_802154_type) {
|
||||
//Current is 802.3, Hence current link-layer option is 6 extra bytes
|
||||
sizechange = 8;
|
||||
slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 6, len - 6, sizechange);
|
||||
} else if (target == ll_8023_type) {
|
||||
/* 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);
|
||||
} else {
|
||||
return -3; //Uh-oh!
|
||||
}
|
||||
|
||||
//Translate addresses
|
||||
if (target == ll_802154_type) {
|
||||
mac_createSicslowpanLongAddr(llbuf, (uip_lladdr_t *)UIP_ICMP_OPTS(icmp_opt_offset)->data);
|
||||
} else {
|
||||
mac_createEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data, (uip_lladdr_t *)llbuf);
|
||||
}
|
||||
|
||||
//Adjust the length
|
||||
if (target == ll_802154_type) {
|
||||
UIP_ICMP_OPTS(icmp_opt_offset)->length = 2;
|
||||
} else {
|
||||
UIP_ICMP_OPTS(icmp_opt_offset)->length = 1;
|
||||
}
|
||||
|
||||
//Adjust the IP header length, as well as uIP length
|
||||
iplen = uipbuf_get_len_field(UIP_IP_BUF);
|
||||
iplen += sizechange;
|
||||
len += sizechange;
|
||||
|
||||
uipbuf_set_len_field(UIP_IP_BUF, iplen);
|
||||
|
||||
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.15.4 long address from a 802.3 address
|
||||
* \param ethernet Pointer to ethernet address
|
||||
* \param lowpan Pointer to 802.15.4 address
|
||||
*/
|
||||
uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
|
||||
{
|
||||
uint8_t index;
|
||||
|
||||
#if UIP_LLADDR_LEN == 8
|
||||
//Special case - if the address is our address, we just copy over what we know to be
|
||||
//our 802.15.4 address
|
||||
|
||||
/* if (memcmp_reverse((uint8_t *)&rndis_ethernet_addr, ethernet, 6) == 0) { */
|
||||
if (memcmp((uint8_t *)&uip_lladdr.addr[2], ethernet, 6) == 0) {
|
||||
memcpy((uint8_t *)lowpan, uip_lladdr.addr, 8);
|
||||
/* byte_reverse((uint8_t *)lowpan, 8); */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Check if translate bit is set, hence we have to look up the prefix
|
||||
if (ethernet[0] & TRANSLATE_BIT_MASK) {
|
||||
|
||||
//Get top bits
|
||||
index = ethernet[0] >> 3;
|
||||
|
||||
//Check this is plausible...
|
||||
if (index >= prefixCounter) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Copy over prefix
|
||||
lowpan->addr[0] = prefixBuffer[index][0];
|
||||
lowpan->addr[3] = prefixBuffer[index][1];
|
||||
lowpan->addr[4] = prefixBuffer[index][2];
|
||||
|
||||
//Bit is clear
|
||||
//so we copy all six
|
||||
} else {
|
||||
lowpan->addr[0] = ethernet[0];
|
||||
lowpan->addr[3] = 0xff;
|
||||
lowpan->addr[4] = 0xfe;
|
||||
}
|
||||
|
||||
//Copy over reamining five bytes
|
||||
lowpan->addr[1] = ethernet[1];
|
||||
lowpan->addr[2] = ethernet[2];
|
||||
lowpan->addr[5] = ethernet[3];
|
||||
lowpan->addr[6] = ethernet[4];
|
||||
lowpan->addr[7] = ethernet[5];
|
||||
|
||||
#else
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < UIP_LLADDR_LEN; i++) {
|
||||
lowpan->addr[i] = ethernet[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \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 index = 0;
|
||||
uint8_t i;
|
||||
/* uint8_t j, match; */
|
||||
|
||||
#if UIP_LLADDR_LEN == 8
|
||||
|
||||
//Special case - if the address is our address, we just copy over what we know to be
|
||||
//our 802.3 address
|
||||
/* if (memcmp_reverse(uip_lladdr.addr, (uint8_t *)lowpan, 8) == 0) { */
|
||||
if (memcmp(uip_lladdr.addr, (uint8_t *)lowpan, 8) == 0) {
|
||||
memcpy(ethernet, &uip_lladdr.addr[2], 6);
|
||||
/* byte_reverse(ethernet, 6); */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//Check if we need to do anything:
|
||||
if ((lowpan->addr[3] == 0xff) && (lowpan->addr[4] == 0xfe) &&
|
||||
((lowpan->addr[0] & TRANSLATE_BIT_MASK) == 0) &&
|
||||
((lowpan->addr[0] & MULTICAST_BIT_MASK) == 0) &&
|
||||
(lowpan->addr[0] & LOCAL_BIT_MASK)) {
|
||||
|
||||
/** Nope: just copy over 6 bytes **/
|
||||
ethernet[0] = lowpan->addr[0];
|
||||
ethernet[1] = lowpan->addr[1];
|
||||
ethernet[2] = lowpan->addr[2];
|
||||
ethernet[3] = lowpan->addr[5];
|
||||
ethernet[4] = lowpan->addr[6];
|
||||
ethernet[5] = lowpan->addr[7];
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
/** Yes: need to store prefix **/
|
||||
for (i = 0; i < prefixCounter; i++) {
|
||||
//Check the current prefix - if it fails, check next one
|
||||
|
||||
|
||||
if ((lowpan->addr[0] == prefixBuffer[i][0]) &&
|
||||
(lowpan->addr[3] == prefixBuffer[i][1]) &&
|
||||
(lowpan->addr[4] == prefixBuffer[i][2])) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
index = i;
|
||||
|
||||
//Deal with overflow, iron-fist style
|
||||
if (index >= PREFIX_BUFFER_SIZE) {
|
||||
index = 0;
|
||||
prefixCounter = PREFIX_BUFFER_SIZE;
|
||||
} else {
|
||||
//Are we making a new one?
|
||||
if (index == prefixCounter) {
|
||||
prefixCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
//Copy the prefix over, no matter if we have a new or old one
|
||||
prefixBuffer[index][0] = lowpan->addr[0];
|
||||
prefixBuffer[index][1] = lowpan->addr[3];
|
||||
prefixBuffer[index][2] = lowpan->addr[4];
|
||||
|
||||
//Create ethernet MAC address now
|
||||
ethernet[1] = lowpan->addr[1];
|
||||
ethernet[2] = lowpan->addr[2];
|
||||
ethernet[3] = lowpan->addr[5];
|
||||
ethernet[4] = lowpan->addr[6];
|
||||
ethernet[5] = lowpan->addr[7];
|
||||
|
||||
|
||||
ethernet[0] = TRANSLATE_BIT_MASK | LOCAL_BIT_MASK | (index << 3);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//Create ethernet MAC address now
|
||||
for(i = 0; i < UIP_LLADDR_LEN; i++) {
|
||||
ethernet[i] = lowpan->addr[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/** \brief Process a received 6lowpan packet. Hijack function.
|
||||
* \param r The MAC layer
|
||||
*
|
||||
* The 6lowpan packet is put in packetbuf by the MAC. This routine calls
|
||||
* any other needed layers (either 6lowpan, or just raw ethernet dump)
|
||||
*/
|
||||
#if 0
|
||||
void mac_ethhijack(const struct mac_driver *r)
|
||||
{
|
||||
if (usbstick_mode.raw) {
|
||||
mac_802154raw(r);
|
||||
}
|
||||
|
||||
if (usbstick_mode.sicslowpan) {
|
||||
|
||||
#if UIP_CONF_USE_RUM
|
||||
if (parsed_frame->payload[4]) { /* RUM 6lowpan frame type */
|
||||
#endif
|
||||
sicslowinput(r);
|
||||
#if UIP_CONF_USE_RUM
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void mac_ethhijack_nondata(const struct mac_driver *r)
|
||||
{
|
||||
if (usbstick_mode.raw)
|
||||
mac_802154raw(r);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------------*/
|
||||
/** \brief Logs a sent 6lowpan frame
|
||||
*
|
||||
* This routine passes a frame
|
||||
* directly to the ethernet layer without decompressing.
|
||||
*/
|
||||
#if 0
|
||||
void mac_logTXtoEthernet(frame_create_params_t *p,frame_result_t *frame_result)
|
||||
{
|
||||
uint8_t sendlen;
|
||||
|
||||
/* Make sure we are supposed to do this */
|
||||
if (usbstick_mode.raw == 0) return;
|
||||
|
||||
/* Get the raw frame */
|
||||
memcpy(&raw_buf[UIP_LLH_LEN], frame_result->frame, frame_result->length);
|
||||
sendlen = frame_result->length;
|
||||
|
||||
//Setup generic ethernet stuff
|
||||
ETHBUF(raw_buf)->type = uip_htons(UIP_ETHTYPE_802154);
|
||||
|
||||
uint64_t tempaddr;
|
||||
|
||||
|
||||
//Check for broadcast message
|
||||
//if(linkaddr_cmp((const linkaddr_t *)destAddr, &linkaddr_null)) {
|
||||
if( ( p->fcf.destAddrMode == SHORTADDRMODE) &&
|
||||
( p->dest_addr.addr16 == 0xffff) ) {
|
||||
ETHBUF(raw_buf)->dest.addr[0] = 0x33;
|
||||
ETHBUF(raw_buf)->dest.addr[1] = 0x33;
|
||||
ETHBUF(raw_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
|
||||
ETHBUF(raw_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
|
||||
ETHBUF(raw_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
|
||||
ETHBUF(raw_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
|
||||
} else {
|
||||
|
||||
tempaddr = p->dest_addr.addr64;
|
||||
|
||||
byte_reverse((uint8_t *)&tempaddr, 8);
|
||||
|
||||
//Otherwise we have a real address
|
||||
mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]),
|
||||
(uip_lladdr_t *)&tempaddr);
|
||||
|
||||
}
|
||||
|
||||
tempaddr = p->src_addr.addr64;
|
||||
|
||||
byte_reverse((uint8_t *)&tempaddr, 8);
|
||||
|
||||
mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]),
|
||||
(uip_lladdr_t *)&tempaddr);
|
||||
|
||||
PRINTF("Low2Eth: Sending 802.15.4 packet to ethernet\n");
|
||||
|
||||
sendlen += UIP_LLH_LEN;
|
||||
|
||||
rndis_send(raw_buf, sendlen, 0);
|
||||
rndis_stat.rxok++;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
/** \brief Process a received 6lowpan packet.
|
||||
* \param r The MAC layer
|
||||
*
|
||||
* The 6lowpan packet is put in packetbuf by the MAC. This routine passes
|
||||
* it directly to the ethernet layer without decompressing.
|
||||
*/
|
||||
#if 0
|
||||
void mac_802154raw(const struct mac_driver *r)
|
||||
{
|
||||
uint8_t sendlen;
|
||||
|
||||
parsed_frame = sicslowmac_get_frame();
|
||||
|
||||
/* Get the raw frame */
|
||||
memcpy(&raw_buf[UIP_LLH_LEN], radio_frame_data(), radio_frame_length());
|
||||
sendlen = radio_frame_length();
|
||||
|
||||
//Setup generic ethernet stuff
|
||||
ETHBUF(raw_buf)->type = uip_htons(UIP_ETHTYPE_802154);
|
||||
|
||||
|
||||
//Check for broadcast message
|
||||
//if(linkaddr_cmp((const linkaddr_t *)destAddr, &linkaddr_null)) {
|
||||
if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) &&
|
||||
( parsed_frame->dest_addr->addr16 == 0xffff) ) {
|
||||
ETHBUF(raw_buf)->dest.addr[0] = 0x33;
|
||||
ETHBUF(raw_buf)->dest.addr[1] = 0x33;
|
||||
ETHBUF(raw_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
|
||||
ETHBUF(raw_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
|
||||
ETHBUF(raw_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
|
||||
ETHBUF(raw_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
|
||||
} else {
|
||||
|
||||
//Otherwise we have a real address
|
||||
mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]),
|
||||
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
|
||||
|
||||
}
|
||||
|
||||
mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]),
|
||||
(uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
||||
|
||||
PRINTF("Low2Eth: Sending 802.15.4 packet to ethernet\n");
|
||||
|
||||
sendlen += UIP_LLH_LEN;
|
||||
|
||||
rndis_send(raw_buf, sendlen, 1);
|
||||
rndis_stat.rxok++;
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
/** @} */
|
|
@ -1,78 +0,0 @@
|
|||
/**
|
||||
* \file sicslow_ethernet.c
|
||||
* Routines to interface between Ethernet and 6LowPan
|
||||
*
|
||||
* \author
|
||||
* Colin O'Flynn <coflynn@newae.com>
|
||||
*
|
||||
* \addtogroup usbstick
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2008 by:
|
||||
|
||||
Colin O'Flynn coflynn@newae.com
|
||||
Eric Gnoske egnoske@gmail.com
|
||||
Blake Leverett bleverett@gmail.com
|
||||
Mike Vidales mavida404@gmail.com
|
||||
Kevin Brown kbrown3@uccs.edu
|
||||
Nate Bohlmann nate@elfwerks.com
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of the copyright holders nor the names of
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef SICSLOW_ETHERNET_H
|
||||
#define SICSLOW_ETHERNET_H
|
||||
|
||||
typedef enum {
|
||||
ll_802154_type,
|
||||
ll_8023_type
|
||||
} lltype_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t sicslowpan :1;
|
||||
uint8_t sendToRf :1;
|
||||
uint8_t translate :1;
|
||||
uint8_t raw :1;
|
||||
} usbstick_mode_t;
|
||||
|
||||
|
||||
#define UIP_ETHTYPE_802154 0x809A
|
||||
|
||||
extern usbstick_mode_t usbstick_mode;
|
||||
|
||||
|
||||
int8_t mac_translateIcmpLinkLayer(lltype_t target);
|
||||
int8_t mac_translateIPLinkLayer(lltype_t target);
|
||||
void mac_LowpanToEthernet(void);
|
||||
void mac_ethernetToLowpan(uint8_t * ethHeader);
|
||||
void mac_ethernetSetup(void);
|
||||
/* void mac_802154raw(const struct mac_driver *r); */
|
||||
/* void mac_logTXtoEthernet(frame_create_params_t *p,frame_result_t *frame_result); */
|
||||
|
||||
#endif
|
|
@ -1,150 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A brief description of what this file is
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/ipv6/uip.h"
|
||||
#include "dev/slip.h"
|
||||
#include "dev/leds.h"
|
||||
#include "sicslow_ethernet.h"
|
||||
|
||||
#include "net/packetbuf.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
PROCESS(uip6_bridge, "IPv6/6lowpan TAP bridge");
|
||||
PROCESS(tcpip_process, "tcpip dummy");
|
||||
AUTOSTART_PROCESSES(&uip6_bridge);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t (* outputfunc)(const uip_lladdr_t *a);
|
||||
uint8_t
|
||||
tcpip_output(const uip_lladdr_t *a)
|
||||
{
|
||||
if(outputfunc != NULL) {
|
||||
outputfunc(a);
|
||||
leds_toggle(LEDS_GREEN);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void
|
||||
tcpip_ipv6_output(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *))
|
||||
{
|
||||
outputfunc = f;
|
||||
}
|
||||
PROCESS_THREAD(tcpip_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Packet from SICSLoWPAN */
|
||||
void
|
||||
tcpip_input(void)
|
||||
{
|
||||
if(uip_len > 0) {
|
||||
mac_LowpanToEthernet();
|
||||
if(uip_len > 0) {
|
||||
slip_write(uip_buf, uip_len);
|
||||
leds_toggle(LEDS_RED);
|
||||
uipbuf_clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Packet from SLIP */
|
||||
static void
|
||||
slip_tcpip_input(void)
|
||||
{
|
||||
/* TODO Should fix this in slip configuration */
|
||||
memmove(uip_buf, &uip_buf[UIP_LLH_LEN], uip_len);
|
||||
mac_ethernetToLowpan(uip_buf);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
slip_activity(void)
|
||||
{
|
||||
leds_toggle(LEDS_BLUE);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(uip6_bridge, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
printf("Setting up SLIP\n");
|
||||
|
||||
mac_ethernetSetup();
|
||||
|
||||
slip_arch_init();
|
||||
slip_set_input_callback(slip_activity);
|
||||
slip_set_tcpip_input_callback(slip_tcpip_input);
|
||||
process_start(&slip_process, NULL);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
putchar(int c)
|
||||
{
|
||||
#define SLIP_END 0300
|
||||
static char debug_frame = 0;
|
||||
|
||||
if(!debug_frame) { /* Start of debug output */
|
||||
slip_arch_writeb(SLIP_END);
|
||||
slip_arch_writeb('\r'); /* Type debug line == '\r' */
|
||||
debug_frame = 1;
|
||||
}
|
||||
|
||||
slip_arch_writeb((char)c);
|
||||
|
||||
/*
|
||||
* Line buffered output, a newline marks the end of debug output and
|
||||
* implicitly flushes debug output.
|
||||
*/
|
||||
if(c == '\n') {
|
||||
slip_arch_writeb(SLIP_END);
|
||||
debug_frame = 0;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -451,7 +451,7 @@ arp_out(struct ethip_hdr *iphdr, int len)
|
|||
arphdr->protolen = 4;
|
||||
arphdr->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);
|
||||
|
||||
/* uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];*/
|
||||
/* uip_appdata = &uip_buf[UIP_TCPIP_HLEN];*/
|
||||
|
||||
return sizeof(struct arp_hdr);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue