[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/6lowpan IP.h, NONE,
1.1 IP.nc, NONE, 1.1 IPC.nc, NONE, 1.1 IPP.nc, NONE,
1.1 IP_internal.h, NONE, 1.1 README, NONE, 1.1 UDPClient.nc,
NONE, 1.1
Matus Harvan
mharvan at users.sourceforge.net
Wed Dec 5 14:58:44 PST 2007
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/support/sdk/c/6lowpan/serial_tun
6lowpan.h, NONE, 1.1 Makefile, NONE, 1.1 README, NONE,
1.1 serial_tun.c, NONE, 1.1 tun_dev.c, NONE, 1.1 tun_dev.h,
NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/support/sdk/c/6lowpan/serial_tun
Makefile, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/6lowpan
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11742/tos/lib/net/6lowpan
Added Files:
IP.h IP.nc IPC.nc IPP.nc IP_internal.h README UDPClient.nc
Log Message:
6lowpan import
--- NEW FILE: IP.h ---
/*
* Copyright (c) 2007 Matus Harvan
* 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.
* * The name of the author may not 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 __IP_H__
#define __IP_H__
typedef struct {
uint8_t addr[16];
} ip6_addr_t;
#endif // __IP_H__
--- NEW FILE: IP.nc ---
/*
* Copyright (c) 2007 Matus Harvan
* 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.
* * The name of the author may not 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.
*/
/*
* This interface design was inspired Andrew Christian's port
* of Adam Dunkel's uIP to TinyOS 1.x. The original interface file
* is distributed under the following copyrights:
*
* Copyright (c) 2005 Hewlett-Packard Company
* 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 Hewlett-Packard Company 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 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.
*
/*
* IP address interface.
*
*/
#include "IP.h"
interface IP {
command void getAddress(ip6_addr_t *addr);
command void setAddress(const ip6_addr_t *addr);
command void setAddressAutoconf(const ip6_addr_t *addr);
}
--- NEW FILE: IPC.nc ---
/*
* Copyright (c) 2007 Matus Harvan
* 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.
* * The name of the author may not 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.
*/
#include "IP.h"
#include "IP_internal.h"
#include "message.h"
#ifdef ENABLE_PRINTF_DEBUG
#include "printf.h"
#endif /* ENABLE_PRINTF_DEBUG */
configuration IPC {
provides {
interface SplitControl as IPControl;
interface IP;
interface UDPClient[uint8_t i];
}
}
implementation {
components IPP;
components ActiveMessageC as AM;
//TODO: need at least 2 pkts for ND
components new PoolC(lowpan_pkt_t, SEND_PKTS) as SendPktPool;
components new PoolC(app_data_t, FRAG_BUFS) as AppDataPool;
components new PoolC(frag_info_t, FRAG_BUFS*FRAGS_PER_DATAGRAM)
as FragInfoPool;
components new TimerMilliC() as Timer;
components LedsC;
IPControl = IPP;
UDPClient = IPP.UDPClient;
IP = IPP.IP;
IPP.MessageControl -> AM;
IPP.Receive -> AM.Receive[AM_IP_MSG];
IPP.AMSend -> AM.AMSend[AM_IP_MSG];
IPP.Packet -> AM;
IPP.AMPacket -> AM;
IPP.SendPktPool -> SendPktPool;
IPP.AppDataPool -> AppDataPool;
IPP.FragInfoPool -> FragInfoPool;
IPP.Leds -> LedsC;
IPP.Timer -> Timer;
#ifdef ENABLE_PRINTF_DEBUG
components PrintfC;
IPP.PrintfControl -> PrintfC;
IPP.PrintfFlush -> PrintfC;
#endif /* ENABLE_PRINTF_DEBUG */
}
--- NEW FILE: IPP.nc ---
/*
* Copyright (c) 2007 Matus Harvan
* 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.
* * The name of the author may not 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
[...2153 lines suppressed...]
return;
}
else {
//Packet.clear(&test_packet);
uint8_t* data=(uint8_t*) call Packet.getPayload(&test_packet,NULL);
if (call Packet.maxPayloadLength() < 1) {
return;
}
data[0] = counter;
call AMPacket.setSource(&test_packet, 0x14);
if (call AMSend.send(3, &test_packet, 1) == SUCCESS) {
// if (call AMSend.send(AM_BROADCAST_ADDR, &test_packet, sizeof(test_serial_msg_t)) == SUCCESS) {
locked = TRUE;
}
}
*/
}
}
--- NEW FILE: IP_internal.h ---
/*
* Copyright (c) 2007 Matus Harvan
* 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.
* * The name of the author may not 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.
*/
/*
* The structures are based on the ones from FreeBSD header files
* in /usr/include/netinet6/, which are distributed unred the following
* copyright:
*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* 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 project 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 PROJECT 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 PROJECT 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.
*
* Copyright (c) 1982, 1986, 1990, 1993
* The Regents of the University of California. 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.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*/
/*
* Header file for the 6lowpan/IPv6 stack.
*/
#ifndef __IP_INTERNAL_H__
#define __IP_INTERNAL_H__
enum {
HW_ADDR_SHORT,
HW_ADDR_LONG
};
typedef struct hw_addr {
uint8_t type; // HW_ADDR_SHORT | HW_ADDR_LONG
union {
uint8_t addr_short[2];
uint8_t addr_long[8];
};
} hw_addr_t;
/* number of packets in SendPktPool */
#define SEND_PKTS 1
/* number of fragment reassembly buffers */
#define FRAG_BUFS 1
/* timeout for discarding a fragment reassembly buffer
* 60 seconds max in 6lowpan draft */
#define FRAG_TIMEOUT 10
/* number of fragments per reassembled datagram */
#define FRAGS_PER_DATAGRAM 15
/* fragment reassembmly buffer size */
#define FRAG_BUF_SIZE 1280
/* default IPv6 Hop Limit for outgoing packets (except Neighbor Discovery) */
#define IP_HOP_LIMIT 64
#define LOWPAN_MTU 1280
#define LOWPAN_OVERHEAD 17
// 16 bytes opt. headers and 1 byte dispatch
#define LINK_DATA_MTU 100
// 802.15.4 space left after the 802.15.4 header: 128 - xx = 102 bytes max
/* size of app_data buffer */
#define LOWPAN_APP_DATA_LEN FRAG_BUF_SIZE
/* maximum length of 6lowpan headers */
//#define LOWPAN_HEADER_LEN 49
#define LOWPAN_HEADER_LEN 102
/* flag marking an unused fragment reassembly buffer/structure */
#define FRAG_FREE 0xFF
/* 6lowpan dispatch values */
#define DISPATCH_UNCOMPRESSED_IPV6 0x41
#define DISPATCH_COMPRESSED_IPV6 0x42
#define DISPATCH_FIRST_FRAG 0xC0
#define DISPATCH_SUBSEQ_FRAG 0xE0
#define DISPATCH_FRAG_MASK 0xF8
#define DISPATCH_BC0 0x50
#define DISPATCH_MESH 0x80
#define DISPATCH_MESH_MASK 0xC0
#define DISPATCH_MESH_O_FLAG 0x20
#define DISPATCH_MESH_F_FLAG 0x10
#define DISPATCH_MESH_HOPSLEFT_MASK 0x0F
enum {
/* lowpan_pkt_t.app_data_dealloc */
APP_DATA_DEALLOC_FALSE=0,
APP_DATA_DEALLOC_TRUE=1,
/* lowpan_pkt_t.notify_num */
LOWPAN_PKT_NO_NOTIFY = 0,
/* HC1 encoding */
HC1_SRC_PREFIX_MASK = 0x80,
HC1_SRC_PREFIX_LINKLOCAL = 0x80,
HC1_SRC_PREFIX_INLINE = 0,
HC1_SRC_IFACEID_MASK = 0x40,
HC1_SRC_IFACEID_COMRP = 0x40,
HC1_SRC_IFACEID_INLINE = 0,
HC1_DST_PREFIX_MASK = 0x20,
HC1_DST_PREFIX_LINKLOCAL = 0x20,
HC1_DST_PREFIX_INLINE = 0,
HC1_DST_IFACEID_MASK = 0x10,
HC1_DST_IFACEID_COMRP = 0x10,
HC1_DST_IFACEID_INLINE = 0,
HC1_TCFL_MASK = 0x08,
HC1_TCFL_ZERO = 0x08,
HC1_TCFL_INLINE = 0,
HC1_NEXTHDR_MASK = 0x06,
HC1_NEXTHDR_INLINE = 0,
HC1_NEXTHDR_UDP = 0x02,
HC1_NEXTHDR_ICMP = 0x04,
HC1_NEXTHDR_TCP = 0x06,
HC1_HC2_MASK = 0x01,
HC1_HC2_PRESENT = 0x01,
HC1_HC2_NONE = 0,
HC2_UDP_P_VALUE = 0x61616,
HC2_UDP_SRC_PORT_MASK = 0x80,
HC2_UDP_SRC_PORT_COMPR = 0x80,
HC2_UDP_SRC_PORT_INLINE = 0,
HC2_UDP_DST_PORT_MASK = 0x40,
HC2_UDP_DST_PORT_COMPR = 0x40,
HC2_UDP_DST_PORT_INLINE = 0,
HC2_UDP_LEN_MASK = 0x20,
HC2_UDP_LEN_COMPR = 0x20,
HC2_UDP_LEN_INLINE = 0
};
/* used for fragment reassembly */
typedef struct _frag_info_t {
uint8_t offset;
uint8_t len;
struct _frag_info_t *next;
} frag_info_t;
/* used for fragment reassembly */
typedef struct _app_data_t {
uint8_t buf[LOWPAN_MTU];
} app_data_t;
/* used for fragment reassembly */
typedef struct _frag_buf_t {
uint8_t *buf; /* usually a pointer to app_data_t */
hw_addr_t hw_src_addr;
hw_addr_t hw_dst_addr;
uint16_t dgram_tag; /* network byte order */
uint16_t dgram_size; /* host byte order */
uint8_t frag_timeout; /* discarded when zero is reached
* FRAG_FREE means not used at the moment */
frag_info_t *frag_list; /* sorted by offset in decreasing order */
} frag_buf_t;
/*
* sending - application provides app_data and clears app_data_dealloc
* - a pointer to app_data is returned in sendDone to do deallocation
* receiving with fragment reassembly
* - IPP provides app_data and sets app_data_dealloc
* - header_begin is set to point into app_data
* and the received packet is put into app_data
* receiving without fragment reassembly
* - the complete 802.15.4 frame is put into header
* (802.15.4 header is left out) and heade_begin points into header
*/
typedef struct _lowpan_pkt_t {
/* buffers */
uint8_t *app_data; /* buffer for application data */
uint16_t app_data_len; /* how much data is in the buffer */
uint8_t *app_data_begin; /* start of the data in the buffer */
uint8_t app_data_dealloc; /* shall IPC deallocate the app_data buffer?
/* APP_DATA_DEALLOC_FALSE | APP_DATA_DEALLOC_TRUE */
uint8_t header[LINK_DATA_MTU]; /* buffer for the header (tx)
* or unfragmented 802.15.4 frame (rx) */
uint16_t header_len; /* how much data is in the buffer */
uint8_t *header_begin; /* start of the data in the buffer */
/* fragmentation */
uint16_t dgram_tag; /* network byte order */
uint16_t dgram_size; /* host byte order */
uint8_t dgram_offset; /* offset where next fragment starts (tx)
* (in multiples of 8 bytes) */
/* IP addresses */
ip6_addr_t ip_src_addr; /* needed for ND and usefull elsewhere */
ip6_addr_t ip_dst_addr; /* both IP addresses filled in by ipv6*_input */
/* 802.15.4 addresses */
hw_addr_t hw_src_addr;
hw_addr_t hw_dst_addr; /* 802.15.4 MAC addresses
* needed for fragment identification
* needed for 6lowpan IPv6 header decompression
* contains mesh header entries if applicable
*/
/* to notify app with sendDone */
uint8_t notify_num; /* num of UDPClient + 1, 0 means o not notify */
struct _lowpan_pkt_t *next;
} lowpan_pkt_t;
enum {
FRAG_NONE = 0,
FRAG_6LOWPAN = 1,
FRAG_IPV6 = 2,
ND_DONE = 0,
ND_TODO = 1,
ND_SENT = 2,
};
struct lowpan_mesh_hdr {
uint8_t dispatch; // dispatch and flags
// address length depends on flags in dispatch
};
struct lowpan_broadcast_hdr {
uint8_t dispatch;
uint8_t seq_no; // sequence number
};
struct lowpan_frag_hdr {
union {
uint8_t dispatch;
uint16_t dgram_size;
uint8_t dgram_size8[2];
};
uint16_t dgram_tag;
};
/*
* Definition for internet protocol version 6.
* RFC 2460
*/
struct ip6_hdr {
union {
uint8_t vtc; /* 4 bits version, 8 bits class label*/
uint32_t flow; /* 20 bits flow label at the end */
};
uint16_t plen; /* payload length */
uint8_t nxt_hdr; /* next header */
uint8_t hlim; /* hop limit */
ip6_addr_t src_addr; /* source address */
ip6_addr_t dst_addr; /* destination address */
} /* __attribute__((packed))*/;
#define IPV6_VERSION 0x60
#define IPV6_VERSION_MASK 0xf0
/*
* Extension Headers
*/
struct ip6_ext {
uint8_t ip6e_nxt;
uint8_t ip6e_len;
};
struct icmp6_hdr {
uint8_t type; /* type field */
uint8_t code; /* code field */
uint16_t cksum; /* checksum field */
};
enum {
ICMP_TYPE_ECHO_DEST_UNREACH = 1,
ICMP_TYPE_ECHO_PKT_TOO_BIG = 129,
ICMP_TYPE_ECHO_TIME_EXCEEDED = 129,
ICMP_TYPE_ECHO_PARAM_PROBLEM = 129,
ICMP_TYPE_ECHO_REQUEST = 128,
ICMP_TYPE_ECHO_REPLY = 129,
ICMP_TYPE_NEIGHBOR_SOL = 135,
ICMP_TYPE_NEIGHBOR_ADV = 136,
ICMP_NEIGHBOR_HOPLIMIT = 255
};
/*
* Udp protocol header.
* Per RFC 768, September, 1981.
*/
struct udp_hdr {
uint16_t srcport; /* source port */
uint16_t dstport; /* destination port */
uint16_t len; /* udp length */
uint16_t chksum; /* udp checksum */
};
enum {
//NEXT_HEADER_ICMP = 1,
NEXT_HEADER_TCP = 6,
NEXT_HEADER_UDP = 17,
NEXT_HEADER_ICMP6 = 58
};
struct udp_conn {
ip6_addr_t ripaddr; /* IP address of the remote peer. */
uint16_t lport; /* local port number (network byte order) */
uint16_t rport; /* remote port number (network byte order) */
};
/* // from uip-1.0/uip/uip-neighbor.c */
/* #define NEIGHBOR_MAX_TIME 128 */
/* #ifndef NEIGHBOR_ENTRIES */
/* #define NEIGHBOR_ENTRIES 8 */
/* #endif */
/* struct neighbor_entry { */
/* ip6_addr_t ip_addr; */
/* struct hw_addr hw_addr; */
/* uint8_t time; */
/* }; */
/* struct neighbor_entry neighbor_entries[NEIGHBOR_ENTRIES]; */
#endif /* __IP_INTERNAL_H__ */
--- NEW FILE: README ---
A 6lowpan implementation for TinyOS 2.x
This is a 6lowpan implementation for TinyOS 2.x. Mesh Addressing and
Broadcast headers are parsed, but no mesh-networking/multi-hopping is
implemented. 6lowpan fragmentation and fragment reassembly is fully
supported. The 6lowpan-specified HC1 compression of the IPv6 header
and the HC_UDP compression of the UDP header are supported as well as
handling of the uncompressed headers. The implementation can respond
to ICMP echo requests and handles communication over the UDP
protocol. It has been tested on the TelosB and MicaZ hardware
platforms. In addition a 6lowpan-translating daemon has been
implemented to allow a linux PC to use a mote as an 802.15.4
interface.
Shortcomings and missing features:
* 6lowpan payload is sent as Active Message payload. This means that
the 802.15.4 payload is prefixed with the 1-byte AM Type field.
* non-zero Traffic Class and Flow Label are not supported by the
current HC1 implementation
* UDP port numbers compression is not supported and port numbers are
always sent in full by the current HC_UDP compression
* Neighbor Discovery has not been implemented and link local
broadcasts are used instead.
* Not all fragments of a datagram seem to be always received by the
mote. A workaround is to add a usleep(10000) before sending subsequent
fragments in the serial_tun daemon on the PC.
More details can be found in
http://www.inf.ethz.ch/personal/mharvan/docs/msc-thesis.pdf
or by reading the source code.
USAGE - MOTE
The 6lowpan/IPv6 stack is implemented in the IPP module. Applications
should use the IPC component which takes care of wiring the necessary
components. The stack offers the UDPClient interface to application
wishing to exchange UDP datagrams. Replying to ICMP echo requests is
done by the 6lowpan stack.
The stack support two IPv6 addresses:
* a global address
* a link-local address
The link-local address is assigned using an interface identifier
computed from the Active Message address of the mote. This is almost
like the stateless autoconfiguration, but Duplicate Address Detection
or Router Solicitations are not implemented.
The global address can be set manually with
IPC.setAddress(). Alternatively, only the prefix of the global address
can be set with IPC.setAddressAutoconf() and the suffix will be
generated from the Active Message address of the mote.
A sample application using the 6lowpan stack is in apps/6lowpancli.
USAGE - PC
To interact with a 6lowpan mote from a PC, a mote flashed with the
BaseStation application (apps/BaseStation) has to be attached to the
PC. Note that the application has to be built with
CFLAGS += -D'TOSH_DATA_LENGTH=102'.
Furthermore, the serial_tun daemon (support/sdk/c/6lowpan/serial_tun/)
has to run on the PC.
Afterwards, ping6 and nc6 should work for talking to the motes.
Debugging output with printf over USB can be enabled with
CFLAGS="-D'ENABLE_PRINTF_DEBUG=1'
To minimize memory usage, i.e. disable everything (at the moment only
the UDP cli) to determine minimum RAM/ROM requirements, use
CFLAGS="-D'MINIMIZE_MEMORY=1'
--- NEW FILE: UDPClient.nc ---
/*
* Copyright (c) 2007 Matus Harvan
* 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.
* * The name of the author may not 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.
*/
/*
* This file is based on Andrew Christian's UDPClient interface from
* the uIP port to TinyOS 1.x, which is distributed under the
* following licence:
*
* Copyright (c) 2005 Hewlett-Packard Company
* 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 Hewlett-Packard Company 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 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.
*/
/*
* Parameterized interface for creating a UDP client or server
*/
#include "IP.h"
interface UDPClient {
/**
* 'Listening' to a socket binds the local port to a fixed number and allows
* the socket to receive packets. If you call send or sendto on an unbound
* socket, a dynamic local port is assigned. Pass 0 to unbind the port.
*/
command error_t listen( uint16_t port ); // Start listening to a port
/**
* 'Connecting' a UDP socket fixes the remote address and port. Once fixed,
* you can send datagrams with the 'send' command. You can un-fix the socket
* by passing NULL as the argument.
*/
command error_t connect(const ip6_addr_t *addr, const uint16_t port);
/**
* Send a datagram to a remote host. Call 'connect' on a socket before
* calling 'send'. If a local port has not yet been assigned, a dynamic
* one will be assigned by these commands. Both commands are asynchronous
* and will generate the 'sendDone' event once the datagram has been sent.
*/
command error_t sendTo(const ip6_addr_t *addr, uint16_t port,
const uint8_t *buf, uint16_t len );
command error_t send(const uint8_t *buf, uint16_t len );
/**
* The previous send or sendTo command has completed.
*/
event void sendDone(error_t result, void* buf);
/**
* A datagram has been received. Datagrams are only received on sockets
* that have had 'listen' called to assign a local port, or have used
* the 'send' or 'sendTo' command.
*/
event void receive(const ip6_addr_t *addr, uint16_t port,
uint8_t *buf, uint16_t len );
}
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/support/sdk/c/6lowpan/serial_tun
6lowpan.h, NONE, 1.1 Makefile, NONE, 1.1 README, NONE,
1.1 serial_tun.c, NONE, 1.1 tun_dev.c, NONE, 1.1 tun_dev.h,
NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/support/sdk/c/6lowpan/serial_tun
Makefile, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list