*Support for Atmel 'Router Under Mac' (RUM) in Jackdaw

This commit is contained in:
c_oflynn 2008-12-10 21:26:05 +00:00
parent c2ef633c87
commit 5ec6412fbc
5 changed files with 190 additions and 37 deletions

View File

@ -47,7 +47,7 @@
* *
* This file is part of the uIP TCP/IP stack. * This file is part of the uIP TCP/IP stack.
* *
* $Id: uip.h,v 1.20 2008/10/15 08:56:44 adamdunkels Exp $ * $Id: uip.h,v 1.21 2008/12/10 21:26:05 c_oflynn Exp $
* *
*/ */
@ -80,7 +80,7 @@ typedef uip_ip4addr_t uip_ipaddr_t;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** \brief 64 bit 802.15.4 address */ /** \brief 64 bit 802.15.4 address */
struct uip_802154_shortaddr { struct uip_802154_shortaddr {
u8_t addr[2]; u8_t addr[2];
@ -88,18 +88,18 @@ struct uip_802154_shortaddr {
/** \brief 16 bit 802.15.4 address */ /** \brief 16 bit 802.15.4 address */
struct uip_802154_longaddr { struct uip_802154_longaddr {
u8_t addr[8]; u8_t addr[8];
}; };
/** \brief 802.11 address */ /** \brief 802.11 address */
struct uip_80211_addr { struct uip_80211_addr {
u8_t addr[6]; u8_t addr[6];
}; };
/** \brief 802.3 address */ /** \brief 802.3 address */
struct uip_eth_addr { struct uip_eth_addr {
u8_t addr[6]; u8_t addr[6];
}; };
#if UIP_CONF_LL_802154 #if UIP_CONF_LL_802154
/** \brief 802.15.4 address */ /** \brief 802.15.4 address */
typedef struct uip_802154_longaddr uip_lladdr_t; typedef struct uip_802154_longaddr uip_lladdr_t;
@ -1405,7 +1405,7 @@ struct uip_stats {
uip_stats_t sent; /**< Number of sent ICMP packets. */ uip_stats_t sent; /**< Number of sent ICMP packets. */
uip_stats_t drop; /**< Number of dropped ICMP packets. */ uip_stats_t drop; /**< Number of dropped ICMP packets. */
uip_stats_t typeerr; /**< Number of ICMP packets with a wrong uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
type. */ type. */
uip_stats_t chkerr; /**< Number of ICMP packets with a bad uip_stats_t chkerr; /**< Number of ICMP packets with a bad
checksum. */ checksum. */
} icmp; /**< ICMP statistics. */ } icmp; /**< ICMP statistics. */
@ -1997,6 +1997,18 @@ CCIF extern uip_lladdr_t uip_lladdr;
(((a)->u8[13]) == (m)->addr[5]) && \ (((a)->u8[13]) == (m)->addr[5]) && \
(((a)->u8[14]) == (m)->addr[6]) && \ (((a)->u8[14]) == (m)->addr[6]) && \
(((a)->u8[15]) == (m)->addr[7])) (((a)->u8[15]) == (m)->addr[7]))
#else
#define uip_is_addr_mac_addr_based(a, m) \
((((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \
(((a)->u8[9]) == (m)->addr[1]) && \
(((a)->u8[10]) == (m)->addr[2]) && \
(((a)->u8[11]) == 0xff) && \
(((a)->u8[12]) == 0xfe) && \
(((a)->u8[13]) == (m)->addr[3]) && \
(((a)->u8[14]) == (m)->addr[4]) && \
(((a)->u8[15]) == (m)->addr[5]))
#endif /*UIP_CONF_LL_802154*/ #endif /*UIP_CONF_LL_802154*/
/** /**

View File

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: sicslowmac.c,v 1.5 2008/11/08 03:29:15 c_oflynn Exp $ * $Id: sicslowmac.c,v 1.6 2008/12/10 21:26:05 c_oflynn Exp $
*/ */
@ -230,27 +230,75 @@ setinput(void (*r)(const struct mac_driver *d))
pinput = r; pinput = r;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static uint8_t dest_reversed[8]; static uint8_t dest_reversed[UIP_LLADDR_LEN];
static uint8_t src_reversed[8]; static uint8_t src_reversed[UIP_LLADDR_LEN];
# define MSB(u16) (((uint8_t* )&u16)[1])
# define LSB(u16) (((uint8_t* )&u16)[0])
void void
sicslowmac_dataIndication(void) sicslowmac_dataIndication(void)
{ {
rimebuf_clear(); rimebuf_clear();
/* Finally, get the stuff into the rime buffer.... */
rimebuf_copyfrom(parsed_frame->payload, parsed_frame->payload_length);
rimebuf_set_datalen(parsed_frame->payload_length);
memcpy(dest_reversed, (uint8_t *)parsed_frame->dest_addr, 8); #if UIP_LLADDR_LEN == 8
memcpy(src_reversed, (uint8_t *)parsed_frame->src_addr, 8); /* Finally, get the stuff into the rime buffer.... */
rimebuf_copyfrom(parsed_frame->payload, parsed_frame->payload_length);
rimebuf_set_datalen(parsed_frame->payload_length);
/* Change addresses to expected byte order */ memcpy(dest_reversed, (uint8_t *)parsed_frame->dest_addr, UIP_LLADDR_LEN);
byte_reverse((uint8_t *)dest_reversed, 8); memcpy(src_reversed, (uint8_t *)parsed_frame->src_addr, UIP_LLADDR_LEN);
byte_reverse((uint8_t *)src_reversed, 8);
rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed); /* Change addresses to expected byte order */
rimebuf_set_addr(RIMEBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed); byte_reverse((uint8_t *)dest_reversed, UIP_LLADDR_LEN);
byte_reverse((uint8_t *)src_reversed, UIP_LLADDR_LEN);
rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed);
rimebuf_set_addr(RIMEBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed);
#elif UIP_CONF_USE_RUM
/* Finally, get the stuff into the rime buffer.... */
rimebuf_copyfrom(parsed_frame->payload + UIP_DATA_RUM_OFFSET, parsed_frame->payload_length - UIP_DATA_RUM_OFFSET);
rimebuf_set_datalen(parsed_frame->payload_length + UIP_DATA_RUM_OFFSET);
dest_reversed[0] = MSB(parsed_frame->dest_pid);
dest_reversed[1] = LSB(parsed_frame->dest_pid);
dest_reversed[2] = 0;
dest_reversed[3] = 0;
dest_reversed[4] = MSB(parsed_frame->payload[0]); //FinalDestAddr
dest_reversed[5] = LSB(parsed_frame->payload[1]);
src_reversed[0] = MSB(parsed_frame->src_pid);
src_reversed[1] = LSB(parsed_frame->src_pid);
src_reversed[2] = 0;
src_reversed[3] = 0;
src_reversed[4] = MSB(parsed_frame->payload[2]); //originAddr
src_reversed[5] = LSB(parsed_frame->payload[3]);
#else
/* Finally, get the stuff into the rime buffer.... */
rimebuf_copyfrom(parsed_frame->payload, parsed_frame->payload_length);
rimebuf_set_datalen(parsed_frame->payload_length);
dest_reversed[0] = MSB(parsed_frame->dest_pid);
dest_reversed[1] = LSB(parsed_frame->dest_pid);
dest_reversed[2] = 0;
dest_reversed[3] = 0;
dest_reversed[4] = MSB(parsed_frame->dest_addr->addr16);
dest_reversed[5] = LSB(parsed_frame->dest_addr->addr16);
src_reversed[0] = MSB(parsed_frame->src_pid);
src_reversed[1] = LSB(parsed_frame->src_pid);
src_reversed[2] = 0;
src_reversed[3] = 0;
src_reversed[4] = MSB(parsed_frame->src_addr->addr16);
src_reversed[5] = LSB(parsed_frame->src_addr->addr16);
rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed);
rimebuf_set_addr(RIMEBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed);
#endif
PRINTF("sicslowmac: hand off frame to sicslowpan \n"); PRINTF("sicslowmac: hand off frame to sicslowpan \n");
pinput(pmac_driver); pinput(pmac_driver);
@ -267,15 +315,53 @@ sicslowmac_unknownIndication(void)
rimebuf_copyfrom(parsed_frame->payload, parsed_frame->payload_length); rimebuf_copyfrom(parsed_frame->payload, parsed_frame->payload_length);
rimebuf_set_datalen(parsed_frame->payload_length); rimebuf_set_datalen(parsed_frame->payload_length);
memcpy(dest_reversed, (uint8_t *)parsed_frame->dest_addr, 8); #if UIP_LLADDR_LEN == 8
memcpy(src_reversed, (uint8_t *)parsed_frame->src_addr, 8); memcpy(dest_reversed, (uint8_t *)parsed_frame->dest_addr, UIP_LLADDR_LEN);
memcpy(src_reversed, (uint8_t *)parsed_frame->src_addr, UIP_LLADDR_LEN);
/* Change addresses to expected byte order */
byte_reverse((uint8_t *)dest_reversed, 8); /* Change addresses to expected byte order */
byte_reverse((uint8_t *)src_reversed, 8); byte_reverse((uint8_t *)dest_reversed, UIP_LLADDR_LEN);
byte_reverse((uint8_t *)src_reversed, UIP_LLADDR_LEN);
rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed);
rimebuf_set_addr(RIMEBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed); rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed);
rimebuf_set_addr(RIMEBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed);
#elif UIP_CONF_USE_RUM
dest_reversed[0] = MSB(parsed_frame->dest_pid);
dest_reversed[1] = LSB(parsed_frame->dest_pid);
dest_reversed[2] = 0;
dest_reversed[3] = 0;
dest_reversed[4] = MSB(parsed_frame->payload[0]); //FinalDestAddr
dest_reversed[5] = LSB(parsed_frame->payload[1]);
src_reversed[0] = MSB(parsed_frame->src_pid);
src_reversed[1] = LSB(parsed_frame->src_pid);
src_reversed[2] = 0;
src_reversed[3] = 0;
src_reversed[4] = MSB(parsed_frame->payload[2]); //originAddr
src_reversed[5] = LSB(parsed_frame->payload[3]);
#else
dest_reversed[0] = MSB(parsed_frame->dest_pid);
dest_reversed[1] = LSB(parsed_frame->dest_pid);
dest_reversed[2] = 0;
dest_reversed[3] = 0;
dest_reversed[4] = MSB(parsed_frame->dest_addr->addr16);
dest_reversed[5] = LSB(parsed_frame->dest_addr->addr16);
src_reversed[0] = MSB(parsed_frame->src_pid);
src_reversed[1] = LSB(parsed_frame->src_pid);
src_reversed[2] = 0;
src_reversed[3] = 0;
src_reversed[4] = MSB(parsed_frame->src_addr->addr16);
src_reversed[5] = LSB(parsed_frame->src_addr->addr16);
rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed);
rimebuf_set_addr(RIMEBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed);
#endif
PRINTF("sicslowmac: hand off frame to sniffer \n"); PRINTF("sicslowmac: hand off frame to sniffer \n");
@ -530,7 +616,11 @@ PROCESS_THREAD(mac_process, ev, data)
eeprom_check = eeprom_read_byte(10); eeprom_check = eeprom_read_byte(10);
if ((eeprom_channel < 11) || (eeprom_channel > 26) || ((uint8_t)eeprom_channel != (uint8_t)~eeprom_check)) { if ((eeprom_channel < 11) || (eeprom_channel > 26) || ((uint8_t)eeprom_channel != (uint8_t)~eeprom_check)) {
#if UIP_CONF_USE_RUM
eeprom_channel = 19; //Default
#else
eeprom_channel = 24; //Default eeprom_channel = 24; //Default
#endif
} }
radio_set_operating_channel(eeprom_channel); radio_set_operating_channel(eeprom_channel);

View File

@ -39,7 +39,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: frame.c,v 1.3 2008/11/08 03:29:15 c_oflynn Exp $ * $Id: frame.c,v 1.4 2008/12/10 21:26:05 c_oflynn Exp $
*/ */
/* /*
* \brief This file is where the main functions that relate to frame * \brief This file is where the main functions that relate to frame
@ -309,6 +309,8 @@ void rx_frame_parse(hal_rx_frame_t *rx_frame, parsed_frame_t *pf)
if (!fcf->panIdCompression){ if (!fcf->panIdCompression){
pf->src_pid = (uint16_t *)p; pf->src_pid = (uint16_t *)p;
p += 2; p += 2;
} else {
pf->src_pid = pf->dest_pid;
} }
/* Source address */ /* Source address */
pf->src_addr = (addr_t *)p; pf->src_addr = (addr_t *)p;

View File

@ -70,6 +70,9 @@ typedef int32_t s32_t;
*/ */
#define EEPROMFS_ADDR_CODEPROP 0x8000 #define EEPROMFS_ADDR_CODEPROP 0x8000
/* Use Atmel 'Route Under MAC', currently just in sniffer mode! */
//#define UIP_CONF_USE_RUM 1
#define CCIF #define CCIF
#define CLIF #define CLIF
@ -112,6 +115,12 @@ typedef int32_t s32_t;
#define UIP_CONF_STATISTICS 1 #define UIP_CONF_STATISTICS 1
/* Route-Under-MAC uses 16-bit short addresses */
#if UIP_CONF_USE_RUM
#undef UIP_CONF_LL_802154
#define UIP_DATA_RUM_OFFSET 5
#endif
typedef unsigned short clock_time_t; typedef unsigned short clock_time_t;
typedef unsigned char u8_t; typedef unsigned char u8_t;
typedef unsigned short u16_t; typedef unsigned short u16_t;

View File

@ -238,6 +238,11 @@ void mac_ethernetToLowpan(uint8_t * ethHeader)
PRINTF("Packet type: %x\n", ((struct uip_eth_hdr *) ethHeader)->type); 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 not IPv6 we don't do anything
if (((struct uip_eth_hdr *) ethHeader)->type != HTONS(UIP_ETHTYPE_IPV6)) { if (((struct uip_eth_hdr *) ethHeader)->type != HTONS(UIP_ETHTYPE_IPV6)) {
printf("eth2low: Packet is not IPv6, dropping\n"); printf("eth2low: Packet is not IPv6, dropping\n");
@ -360,11 +365,17 @@ void mac_LowpanToEthernet(void)
*/ */
int8_t mac_translateIPLinkLayer(lltype_t target) int8_t mac_translateIPLinkLayer(lltype_t target)
{ {
#if UIP_LLADDR_LEN == 8
if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) { if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) {
PRINTF("eth2low: ICMP Message detected\n"); PRINTF("eth2low: ICMP Message detected\n");
return mac_translateIcmpLinkLayer(target); return mac_translateIcmpLinkLayer(target);
} }
return 0; return 0;
#else
return 1;
#endif
} }
#include "net/uip-icmp6.h" #include "net/uip-icmp6.h"
@ -538,7 +549,7 @@ uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
uint8_t index; uint8_t index;
uint8_t i; uint8_t i;
#if UIP_LLADDR_LEN == 8
//Special case - if the address is our address, we just copy over what we know to be //Special case - if the address is our address, we just copy over what we know to be
//our 802.15.4 address //our 802.15.4 address
@ -579,6 +590,13 @@ uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
lowpan->addr[5] = ethernet[3]; lowpan->addr[5] = ethernet[3];
lowpan->addr[6] = ethernet[4]; lowpan->addr[6] = ethernet[4];
lowpan->addr[7] = ethernet[5]; lowpan->addr[7] = ethernet[5];
#else
for(i = 0; i < UIP_LLADDR_LEN; i++) {
lowpan->addr[i] = ethernet[i];
}
#endif
return 1; return 1;
} }
@ -594,6 +612,8 @@ uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
uint8_t index = 0; uint8_t index = 0;
uint8_t i,j, match; uint8_t i,j, match;
#if UIP_LLADDR_LEN == 8
//Special case - if the address is our address, we just copy over what we know to be //Special case - if the address is our address, we just copy over what we know to be
//our 802.3 address //our 802.3 address
if (memcmp_reverse((uint8_t *)&macLongAddr, (uint8_t *)lowpan, 8) == 0) { if (memcmp_reverse((uint8_t *)&macLongAddr, (uint8_t *)lowpan, 8) == 0) {
@ -662,6 +682,15 @@ uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
ethernet[0] = TRANSLATE_BIT_MASK | LOCAL_BIT_MASK | (index << 3); 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; return 1;
} }
@ -707,11 +736,22 @@ void slide(uint8_t * data, uint8_t length, int16_t slide)
*/ */
void mac_ethhijack(const struct mac_driver *r) void mac_ethhijack(const struct mac_driver *r)
{ {
if (usbstick_mode.raw) if (usbstick_mode.raw) {
mac_802154raw(r); mac_802154raw(r);
}
if (usbstick_mode.sicslowpan) if (usbstick_mode.sicslowpan) {
#if UIP_CONF_USE_RUM
if (parsed_frame->payload[4]) { /* RUM 6lowpan frame type */
#endif
sicslowinput(r); sicslowinput(r);
#if UIP_CONF_USE_RUM
}
#endif
}
} }