*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.
*
* $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 $
*
*/
@ -1997,6 +1997,18 @@ CCIF extern uip_lladdr_t uip_lladdr;
(((a)->u8[13]) == (m)->addr[5]) && \
(((a)->u8[14]) == (m)->addr[6]) && \
(((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*/
/**

View file

@ -28,7 +28,7 @@
*
* 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,28 +230,76 @@ setinput(void (*r)(const struct mac_driver *d))
pinput = r;
}
/*---------------------------------------------------------------------------*/
static uint8_t dest_reversed[8];
static uint8_t src_reversed[8];
static uint8_t dest_reversed[UIP_LLADDR_LEN];
static uint8_t src_reversed[UIP_LLADDR_LEN];
# define MSB(u16) (((uint8_t* )&u16)[1])
# define LSB(u16) (((uint8_t* )&u16)[0])
void
sicslowmac_dataIndication(void)
{
rimebuf_clear();
#if UIP_LLADDR_LEN == 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);
memcpy(dest_reversed, (uint8_t *)parsed_frame->dest_addr, 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);
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);
#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");
pinput(pmac_driver);
}
@ -267,16 +315,54 @@ sicslowmac_unknownIndication(void)
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);
memcpy(src_reversed, (uint8_t *)parsed_frame->src_addr, 8);
#if UIP_LLADDR_LEN == 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);
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);
#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");
sicslowmac_snifferhook(pmac_driver);
@ -530,7 +616,11 @@ PROCESS_THREAD(mac_process, ev, data)
eeprom_check = eeprom_read_byte(10);
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
#endif
}
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
* 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
@ -309,6 +309,8 @@ void rx_frame_parse(hal_rx_frame_t *rx_frame, parsed_frame_t *pf)
if (!fcf->panIdCompression){
pf->src_pid = (uint16_t *)p;
p += 2;
} else {
pf->src_pid = pf->dest_pid;
}
/* Source address */
pf->src_addr = (addr_t *)p;

View file

@ -70,6 +70,9 @@ typedef int32_t s32_t;
*/
#define EEPROMFS_ADDR_CODEPROP 0x8000
/* Use Atmel 'Route Under MAC', currently just in sniffer mode! */
//#define UIP_CONF_USE_RUM 1
#define CCIF
#define CLIF
@ -112,6 +115,12 @@ typedef int32_t s32_t;
#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 char u8_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);
//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 != HTONS(UIP_ETHTYPE_IPV6)) {
printf("eth2low: Packet is not IPv6, dropping\n");
@ -360,11 +365,17 @@ void mac_LowpanToEthernet(void)
*/
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/uip-icmp6.h"
@ -538,7 +549,7 @@ uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
uint8_t index;
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
//our 802.15.4 address
@ -580,6 +591,13 @@ uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
lowpan->addr[6] = ethernet[4];
lowpan->addr[7] = ethernet[5];
#else
for(i = 0; i < UIP_LLADDR_LEN; i++) {
lowpan->addr[i] = ethernet[i];
}
#endif
return 1;
}
@ -594,6 +612,8 @@ uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
uint8_t index = 0;
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
//our 802.3 address
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);
}
#else
//Create ethernet MAC address now
for(i = 0; i < UIP_LLADDR_LEN; i++) {
ethernet[i] = lowpan->addr[i];
}
#endif
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)
{
if (usbstick_mode.raw)
if (usbstick_mode.raw) {
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);
#if UIP_CONF_USE_RUM
}
#endif
}
}