Fixing some files...
This commit is contained in:
parent
2238f2e7da
commit
9cc14d43ef
5 changed files with 0 additions and 1038 deletions
|
@ -1,4 +0,0 @@
|
|||
CONTIKI_TARGET_SOURCEFILES += mac.c sicslowmac.c
|
||||
|
||||
APPDIRS += $(CONTIKI)/cpu/avr/radio/mac
|
||||
|
|
@ -1,193 +0,0 @@
|
|||
/* Copyright (c) 2008, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Additional fixes for AVR contributed 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.
|
||||
**/
|
||||
/**
|
||||
* \addtogroup wireless
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* \defgroup rf230mac RF230 MAC
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* \brief The IEEE 802.15.4 (2003/2006) MAC utility functions.
|
||||
*
|
||||
* $Id: mac.c,v 1.1 2008/10/14 09:43:40 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \author
|
||||
* Eric Gnoske <egnoske@gmail.com>
|
||||
* Blake Leverett <bleverett@gmail.com>
|
||||
* Mike Vidales <mavida404@gmail.com>
|
||||
* Colin O'Flynn <coflynn@newae.com>
|
||||
*
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mac.h"
|
||||
#include "radio.h"
|
||||
#include "hal.h"
|
||||
#include "tcpip.h"
|
||||
#include "uip.h"
|
||||
#include "sicslowpan.h"
|
||||
#include "sicslowmac.h"
|
||||
|
||||
/* Globals */
|
||||
/** \brief Interface structure for this module */
|
||||
ieee_15_4_manager_t ieee15_4ManagerAddress;
|
||||
|
||||
//dataRequest_t dataRequestStructAddress;
|
||||
|
||||
/* Macros & Defines */
|
||||
|
||||
uint8_t msduHandle;
|
||||
bool iAmCoord;
|
||||
bool autoModes;
|
||||
|
||||
|
||||
/** \brief The RF channel to use for all following transmissions and
|
||||
* receptions (see 6.1.2). Allowable values are 0-26
|
||||
*/
|
||||
uint8_t phyCurrentChannel;
|
||||
|
||||
/** \brief The 64-bit address of the coordinator/router through which
|
||||
* the network layer wishes to communicate.
|
||||
*/
|
||||
uint64_t macCoordExtendedAddress;
|
||||
|
||||
/** \brief The 16-bit short address assigned to the coordinator
|
||||
* through which the network layer wishes to communicate. A value
|
||||
* of 0xfffe indicates th the coordinator is only using it's 64-bit
|
||||
* extended address. A value of 0xffff indicates that this value is
|
||||
* unknown. The default value is 0xfff.
|
||||
*/
|
||||
uint16_t macCoordShortAddress;
|
||||
|
||||
/** \brief This address is the 64-bit address that will be used as
|
||||
* the mechanism to provide a destination to the upper layers. The
|
||||
* default value is 0xfff.
|
||||
*/
|
||||
uint64_t macDestAddress;
|
||||
|
||||
/** \brief The sequence number (0x00 - 0xff) added to the transmitted
|
||||
* data or MAC command frame. The default is a random value within
|
||||
* the range.
|
||||
*/
|
||||
uint8_t macDSN;
|
||||
|
||||
/** \brief The 16-bit identifier of the PAN on which the device is
|
||||
* sending to. If this value is 0xffff, the device is not
|
||||
* associated. The default value is 0xffff.
|
||||
*/
|
||||
uint16_t macDstPANId;
|
||||
|
||||
/** \brief The 16-bit identifier of the PAN on which the device is
|
||||
* operating. If this value is 0xffff, the device is not
|
||||
* associated. The default value is 0xffff.
|
||||
*/
|
||||
uint16_t macSrcPANId;
|
||||
|
||||
/** \brief The 16-bit address that the device uses to communicate in
|
||||
* the PAN. If the device is the PAN coordinator, this value shall
|
||||
* be chosen before a PAN is started. Otherwise, the address is
|
||||
* allocated by a coordinator during association. A value of 0xfffe
|
||||
* indicates that the device has associated but has not been
|
||||
* allocated an address. A value of 0xffff indicates that the
|
||||
* device does not have a short address. The default value is
|
||||
* 0xffff.
|
||||
*/
|
||||
uint16_t macShortAddress;
|
||||
|
||||
|
||||
/** \brief Our own long address. This needs to be read from EEPROM or
|
||||
* other secure memory storage.
|
||||
*/
|
||||
uint64_t macLongAddr;
|
||||
|
||||
/* Implementation */
|
||||
|
||||
/** \brief Initializes the (quasi) 802.15.4 MAC. This function should
|
||||
* be called only once on startup.
|
||||
*/
|
||||
void
|
||||
mac_init(void)
|
||||
{
|
||||
volatile uint8_t buf[8];
|
||||
|
||||
sicslowmac_resetRequest(true);
|
||||
|
||||
/* Set up the radio for auto mode operation. */
|
||||
hal_subregister_write( SR_MAX_FRAME_RETRIES, 2 );
|
||||
|
||||
/* Need to laod PANID for auto modes */
|
||||
radio_set_pan_id(DEST_PAN_ID);
|
||||
|
||||
/* Buffer the uint64_t address for easy loading and debug. */
|
||||
/** \todo Find a better location to load the IEEE address. */
|
||||
buf[0] = macLongAddr & 0xFF;
|
||||
buf[1] = (macLongAddr >> 8) & 0xFF;
|
||||
buf[2] = (macLongAddr >> 16) & 0xFF;
|
||||
buf[3] = (macLongAddr >> 24) & 0xFF;
|
||||
buf[4] = (macLongAddr >> 32) & 0xFF;
|
||||
buf[5] = (macLongAddr >> 40) & 0xFF;
|
||||
buf[6] = (macLongAddr >> 48) & 0xFF;
|
||||
buf[7] = (macLongAddr >> 56) & 0xFF;
|
||||
/* Load the long address into the radio. This is required for auto mode */
|
||||
/* operation. */
|
||||
radio_set_extended_address((uint8_t *)&macLongAddr);
|
||||
|
||||
srand(1234 );
|
||||
msduHandle = rand();
|
||||
|
||||
/* Ping6 debug */
|
||||
memcpy(uip_lladdr.addr, &macLongAddr, 8);
|
||||
|
||||
/* Convert expected byte order */
|
||||
byte_reverse((uint8_t *)uip_lladdr.addr, 8);
|
||||
}
|
||||
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
|
@ -1,241 +0,0 @@
|
|||
/* Copyright (c) 2008, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Additional fixes for AVR contributed 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.
|
||||
*/
|
||||
/**
|
||||
* \brief The equivalent IEEE 802.15.4 (2003/2006) header file for
|
||||
* the mac primitives.
|
||||
*
|
||||
* $Id: mac.h,v 1.1 2008/10/14 09:43:40 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \addtogroup rf230mac
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* \brief The IEEE 802.15.4 (2003/2006) MAC utility functions.
|
||||
*/
|
||||
|
||||
#ifndef MAC_H
|
||||
#define MAC_H
|
||||
|
||||
/* Includes */
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "frame.h"
|
||||
#include "ieee-15-4-manager.h"
|
||||
|
||||
#define EEPROMMACADDRESS ((void*)0)
|
||||
#define EEPROMDSTADDRESS ((void*)8)
|
||||
#define EEPROMCHANADDRESS ((void*)16)
|
||||
#define EEPROMPANIDADDRESS ((void*)17)
|
||||
#define EEPROMROLEADDRESS ((void*)19)
|
||||
#define SUCCESS (0)
|
||||
#define CHANNEL_PAGE_0 (0)
|
||||
|
||||
|
||||
|
||||
|
||||
/* MAC command frames codes */
|
||||
|
||||
/* MAC enumerations */
|
||||
/** \brief Pre-defined data frame control field (FCF) values.
|
||||
* \name FCF Values
|
||||
* @{
|
||||
*/
|
||||
#define FCF_NO_ACK (0x8841)
|
||||
#define FCF_ACK_REQ (0x8861)
|
||||
/** @} */
|
||||
|
||||
/** \brief Hardcoded various "network" addresses, for use when testing.
|
||||
* \name Pre-defined network addresses
|
||||
* @{
|
||||
*/
|
||||
#define DEST_PAN_ID (0xABCD)
|
||||
#define SOURCE_PAN_ID (0xABCD)
|
||||
#define LONG_ADDR_1 (0xFFEEDDCCBBAA1100LL)
|
||||
#define LONG_ADDR_2 (0x1122334455667788LL)
|
||||
#define LONG_ADDR_3 (0xDDEEAADDBBEEEEFFLL)
|
||||
#define LONG_ADDR_4 (0x0123456789ABCDEFLL)
|
||||
#define SOURCE_ADDR (0x1234)
|
||||
#define FCF_ACK (0x0002)
|
||||
#define TX_OPTION_NOACK (0)
|
||||
#define TX_OPTION_ACK (1)
|
||||
#define LONG_ADDR_LEN (8)
|
||||
/** @} */
|
||||
|
||||
#define MPDU_OVERHEAD (11) /**< This overhead includes FCF, DSN, DEST_PAN_ID, DEST_ADDR, SOURCE_ADDR, & FCS */
|
||||
|
||||
|
||||
/** \brief These are some definitions of values used in the FCF. See the 802.15.4 spec for details.
|
||||
* \name FCF element values definitions
|
||||
* @{
|
||||
*/
|
||||
#define BEACONFRAME (0x00)
|
||||
#define DATAFRAME (0x01)
|
||||
#define ACKFRAME (0x02)
|
||||
#define CMDFRAME (0x03)
|
||||
|
||||
#define BEACONREQ (0x07)
|
||||
|
||||
#define IEEERESERVED (0x00)
|
||||
#define NOADDR (0x00) /**< Only valid for ACK or Beacon frames. */
|
||||
#define SHORTADDRMODE (0x02)
|
||||
#define LONGADDRMODE (0x03)
|
||||
|
||||
#define NOBEACONS (0x0F)
|
||||
|
||||
#define BROADCASTADDR (0xFFFF)
|
||||
#define BROADCASTPANDID (0xFFFF)
|
||||
|
||||
#define IEEE802154_2003 (0x00)
|
||||
#define IEEE802154_2006 (0x01)
|
||||
|
||||
#define SECURITY_LEVEL_NONE (0)
|
||||
#define SECURITY_LEVEL_128 (3)
|
||||
|
||||
#define PSDULEN (127)
|
||||
/** @} */
|
||||
|
||||
|
||||
/* typedef enum {TRUE, FALSE} bool; */
|
||||
|
||||
typedef struct dataRequest {
|
||||
uint8_t srcAddrMode;
|
||||
uint8_t dstAddrMode;
|
||||
uint16_t dstPANId;
|
||||
addr_t dstAddr;
|
||||
uint8_t msduLength;
|
||||
uint8_t *msdu;
|
||||
uint8_t msduHandle;
|
||||
uint8_t txOptions;
|
||||
uint8_t securityLevel;
|
||||
uint8_t keyIdMode;
|
||||
uint8_t *keySource;
|
||||
uint8_t keyIndex;
|
||||
} dataRequest_t;
|
||||
|
||||
|
||||
/* Macros & Defines */
|
||||
extern ieee_15_4_manager_t ieee15_4ManagerAddress;
|
||||
extern dataRequest_t dataRequestStructAddress;
|
||||
#define ieee15_4Struct (&ieee15_4ManagerAddress)
|
||||
#define dataRequestStruct (&dataRequestStructAddress)
|
||||
|
||||
|
||||
/**
|
||||
* \name Scan variables
|
||||
* \brief Global variables and defines for scan.
|
||||
* \{
|
||||
*/
|
||||
extern uint8_t msduHandle;
|
||||
extern bool iAmCoord;
|
||||
extern bool autoModes;
|
||||
extern uint16_t macShortAddr;
|
||||
extern uint64_t macLongAddr;
|
||||
/** @} */
|
||||
|
||||
/* PHY PIB Attributes */
|
||||
|
||||
/* uint8_t phyCurrentChannel Integer 0-26
|
||||
* The RF channel to use for all following transmissions and receptions (see6.1.2).
|
||||
*/
|
||||
extern uint8_t phyCurrentChannel;
|
||||
|
||||
/* uint64_t macCoordExtendedAddress -- no default
|
||||
*
|
||||
* The 64-bit address of the coordinator/router through which the network layer wishes to communicate
|
||||
*/
|
||||
extern uint64_t macCoordExtendedAddress;
|
||||
|
||||
/* uint16_t macCoordShortAddress -- default 0xffff
|
||||
*
|
||||
* The 16-bit short address assigned to the coordinator through which the network layer wishes
|
||||
* to communicate. A value of 0xfffe indicates th the coordinator is only using it's 64-bit
|
||||
* extended address. A value of 0xffff indicates that this value is unknown.
|
||||
*/
|
||||
extern uint16_t macCoordShortAddress;
|
||||
|
||||
/* uint64_t macDestAddress -- default 0xffff
|
||||
*
|
||||
* This address is the 64-bit address that will be used as the mechanism to
|
||||
* provide a destination to the upper layers.
|
||||
*/
|
||||
extern uint64_t macDestAddress;
|
||||
|
||||
/* uint8_t macDSN -- default is random value within the range
|
||||
*
|
||||
* The sequence number (0x00 - 0xff) added to the transmitted data or MAC command frame.
|
||||
*/
|
||||
extern uint8_t macDSN;
|
||||
|
||||
/* uint16_t macDstPANId -- default 0xffff
|
||||
*
|
||||
* The 16-bit identifier of the PAN on which the device is sending to. If this value
|
||||
* is 0xffff, the device is not associated.
|
||||
*/
|
||||
extern uint16_t macDstPANId;
|
||||
|
||||
/* uint16_t macSrcPANId -- default 0xffff
|
||||
*
|
||||
* The 16-bit identifier of the PAN on which the device is operating. If this value
|
||||
* is 0xffff, the device is not associated.
|
||||
*/
|
||||
extern uint16_t macSrcPANId;
|
||||
|
||||
/* uint16_t macShortAddress -- default 0xffff
|
||||
*
|
||||
* The 16-bit address that the device uses to communicate in the PAN. If the device is the
|
||||
* PAN coordinator, this value shall be chosen before a PAN is started. Otherwise, the
|
||||
* address is allocated by a coordinator during association. A value of 0xfffe indicates
|
||||
* that the device has associated but has not been allocated an address. A value of 0xffff
|
||||
* indicates that the device does not have a short address.
|
||||
*/
|
||||
extern uint16_t macShortAddress;
|
||||
|
||||
/* Scan defines */
|
||||
|
||||
|
||||
/* Protoypes */
|
||||
void mac_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
|
@ -1,488 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 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.
|
||||
*
|
||||
* $Id: sicslowmac.c,v 1.1 2008/10/14 09:43:40 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Example glue code between the existing MAC code and the
|
||||
* Contiki mac interface
|
||||
*
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
* Eric Gnoske <egnoske@gmail.com>
|
||||
* Blake Leverett <bleverett@gmail.com>
|
||||
*
|
||||
* \addtogroup rf230mac
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <util/delay.h>
|
||||
#include "net/rime/rimebuf.h"
|
||||
#include "mac.h"
|
||||
#include "frame.h"
|
||||
#include "radio.h"
|
||||
#include "tcpip.h"
|
||||
#include "sicslowmac.h"
|
||||
#include "sicslowpan.h"
|
||||
#include "ieee-15-4-manager.h"
|
||||
|
||||
/* Macros */
|
||||
#define DEBUG 0
|
||||
#define MAX_EVENTS 10
|
||||
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
/* Globals */
|
||||
static mac_driver_t mac_driver;
|
||||
static mac_driver_t *pmac_driver = &mac_driver;
|
||||
extern ieee_15_4_manager_t ieee15_4ManagerAddress;
|
||||
static parsed_frame_t *parsed_frame;
|
||||
|
||||
|
||||
const mac_driver_t sicslowmac_driver = {
|
||||
sicslowmac_dataRequest,
|
||||
/* read_packet, */
|
||||
/* set_receive_function, */
|
||||
/* on, */
|
||||
/* off, */
|
||||
};
|
||||
|
||||
static struct {
|
||||
uint8_t head;
|
||||
uint8_t tail;
|
||||
event_object_t event_object[MAX_EVENTS];
|
||||
} event_queue;
|
||||
|
||||
/* Prototypes */
|
||||
static void setinput(void (*r)(const mac_driver_t *d));
|
||||
static void (*pinput)(const mac_driver_t *r);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Checks for any pending events in the queue.
|
||||
*
|
||||
* \return True if there is a pending event, else false.
|
||||
*/
|
||||
uint8_t
|
||||
mac_event_pending(void)
|
||||
{
|
||||
return (event_queue.head != event_queue.tail);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Puts an event into the queue of events.
|
||||
*
|
||||
* \param object is a pointer to the event to add to queue.
|
||||
*/
|
||||
void
|
||||
mac_put_event(event_object_t *object)
|
||||
{
|
||||
uint8_t newhead;
|
||||
|
||||
if ((event_queue.head + 1) % MAX_EVENTS == event_queue.tail){
|
||||
/* queue full, get outta here */
|
||||
return;
|
||||
}
|
||||
|
||||
newhead = event_queue.head;
|
||||
|
||||
/* store in queue */
|
||||
event_queue.event_object[newhead] = *object;
|
||||
|
||||
/* calculate new head index */
|
||||
newhead++;
|
||||
if (newhead >= MAX_EVENTS){
|
||||
newhead = 0;
|
||||
}
|
||||
event_queue.head = newhead;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Pulls an event from the event queue.
|
||||
* Assumes that there is an event in the queue. See mac_event_pending().
|
||||
*
|
||||
* \return Pointer to the event object, or NULL in the event of empty queue.
|
||||
*/
|
||||
event_object_t
|
||||
*mac_get_event(void)
|
||||
{
|
||||
event_object_t *object = NULL;
|
||||
volatile uint8_t newtail;
|
||||
|
||||
newtail = event_queue.tail;
|
||||
|
||||
object = &(event_queue.event_object[newtail]);
|
||||
|
||||
/* calculate new tail */
|
||||
newtail++;
|
||||
if (newtail >= MAX_EVENTS){
|
||||
newtail = 0;
|
||||
}
|
||||
|
||||
event_queue.tail = newtail;
|
||||
|
||||
return(object);
|
||||
}
|
||||
|
||||
void mac_pollhandler(void)
|
||||
{
|
||||
mac_task(NULL, NULL);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief This is the main loop task for the MAC. Called by the
|
||||
* main application loop.
|
||||
*/
|
||||
void
|
||||
mac_task(process_event_t ev, process_data_t data)
|
||||
{
|
||||
/* check for event in queue */
|
||||
event_object_t *event;
|
||||
|
||||
if(mac_event_pending()){
|
||||
|
||||
event = mac_get_event();
|
||||
|
||||
/* Handle events from radio */
|
||||
if (event){
|
||||
if (event->event == MAC_EVENT_RX){
|
||||
/* got a frame, find out with kind of frame */
|
||||
parsed_frame = (parsed_frame_t *)event->data;
|
||||
if (parsed_frame->fcf->frameType == DATAFRAME){
|
||||
sicslowmac_dataIndication();
|
||||
}
|
||||
|
||||
/* Frame no longer in use */
|
||||
parsed_frame->in_use = false;
|
||||
}
|
||||
|
||||
if (event->event == MAC_EVENT_DROPPED){
|
||||
/* Frame was dropped */
|
||||
printf("sicslowmac: Frame Dropped!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
setinput(void (*r)(const mac_driver_t *d))
|
||||
{
|
||||
pinput = r;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
sicslowmac_dataIndication(void)
|
||||
{
|
||||
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);
|
||||
|
||||
/* Change addresses to expected byte order */
|
||||
byte_reverse((uint8_t *)parsed_frame->dest_addr, 8);
|
||||
byte_reverse((uint8_t *)parsed_frame->src_addr, 8);
|
||||
|
||||
rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, (const rimeaddr_t *)parsed_frame->dest_addr);
|
||||
rimebuf_set_addr(RIMEBUF_ADDR_SENDER, (const rimeaddr_t *)parsed_frame->src_addr);
|
||||
|
||||
PRINTF("sicslowmac: hand off frame to sicslowpan \n");
|
||||
pinput(pmac_driver);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief This is the implementation of the 15.4 MAC Data Request
|
||||
* primitive.
|
||||
*
|
||||
* \return Integer denoting success or failure.
|
||||
* \retval 0 Failure.
|
||||
* \retval 1 Success.
|
||||
*
|
||||
* The data request primitive creates the frame header based
|
||||
* on static and dynamic data. The static data will be refined
|
||||
* in phase II of the project. The frame payload and length are
|
||||
* retrieved from the rime buffer and rime length respectively.
|
||||
*
|
||||
* When the header and payload are assembled into the
|
||||
* frame_create_params structure, the frame is created
|
||||
* by a call to frame_tx_create and then transmited via
|
||||
* radio_send_data.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
sicslowmac_dataRequest(void)
|
||||
{
|
||||
|
||||
/* create structure to store result. */
|
||||
frame_create_params_t params;
|
||||
frame_result_t result;
|
||||
|
||||
/* Save the msduHandle in a global variable. */
|
||||
msduHandle = rimebuf_attr(RIMEBUF_ATTR_PACKET_ID);
|
||||
|
||||
/* Build the FCF. */
|
||||
params.fcf.frameType = DATAFRAME;
|
||||
params.fcf.securityEnabled = false;
|
||||
params.fcf.framePending = false;
|
||||
params.fcf.ackRequired = rimebuf_attr(RIMEBUF_ATTR_RELIABLE);
|
||||
params.fcf.panIdCompression = false;
|
||||
|
||||
/* Insert IEEE 802.15.4 (2003) version bit. */
|
||||
params.fcf.frameVersion = IEEE802154_2003;
|
||||
|
||||
/* Increment and set the data sequence number. */
|
||||
params.seq = macDSN++;
|
||||
|
||||
/* Complete the addressing fields. */
|
||||
/**
|
||||
\todo For phase 1 the addresses are all long. We'll need a mechanism
|
||||
in the rime attributes to tell the mac to use long or short for phase 2.
|
||||
*/
|
||||
params.fcf.srcAddrMode = LONGADDRMODE;
|
||||
params.dest_pid = ieee15_4ManagerAddress.get_dst_panid();
|
||||
|
||||
/*
|
||||
* If the output address is NULL in the Rime buf, then it is broadcast
|
||||
* on the 802.15.4 network.
|
||||
*/
|
||||
if(rimeaddr_cmp(rimebuf_addr(RIMEBUF_ADDR_RECEIVER), &rimeaddr_null) ) {
|
||||
/* Broadcast requires short address mode. */
|
||||
params.fcf.destAddrMode = SHORTADDRMODE;
|
||||
params.dest_pid = BROADCASTPANDID;
|
||||
params.dest_addr.addr16 = BROADCASTADDR;
|
||||
|
||||
} else {
|
||||
|
||||
/* Phase 1.5 - end nodes send to anyone? */
|
||||
memcpy(¶ms.dest_addr, (uint8_t *)rimebuf_addr(RIMEBUF_ADDR_RECEIVER), LONG_ADDR_LEN);
|
||||
|
||||
/* Hack to allow Ethernet to send us data, we have to limit addresses to have zero in upper */
|
||||
/* two bytes */
|
||||
/* params.dest_addr.addr64 &= 0x0000ffffffffffffUL; */
|
||||
|
||||
/* Phase 1 - end nodes only sends to pan coordinator node. */
|
||||
/* params.dest_addr.addr64 = ieee15_4ManagerAddress.get_coord_long_addr(); */
|
||||
params.fcf.destAddrMode = LONGADDRMODE;
|
||||
}
|
||||
|
||||
/* Set the source PAN ID to the global variable. */
|
||||
params.src_pid = ieee15_4ManagerAddress.get_src_panid();
|
||||
|
||||
/*
|
||||
* Set up the source address using only the long address mode for
|
||||
* phase 1.
|
||||
*/
|
||||
params.src_addr.addr64 = ieee15_4ManagerAddress.get_long_addr();
|
||||
|
||||
/* Copy the payload data. */
|
||||
params.payload_len = rimebuf_datalen();
|
||||
params.payload = rimebuf_dataptr();
|
||||
|
||||
/* Create transmission frame. */
|
||||
frame_tx_create(¶ms, &result);
|
||||
|
||||
/* Retry up to this many times to send the packet if radio is busy */
|
||||
uint8_t retry_count = 3;
|
||||
|
||||
while(retry_count) {
|
||||
|
||||
PRINTF("sicslowmac: sending packet of length %d to radio, result:", result.length);
|
||||
|
||||
/* Send data to radio. */
|
||||
radio_status_t rv = radio_send_data(result.length, result.frame);
|
||||
|
||||
if (rv == RADIO_SUCCESS) {
|
||||
PRINTF(" Success\n");
|
||||
|
||||
return 1; /* True says that the packet could be sent */
|
||||
}
|
||||
|
||||
|
||||
if (rv != RADIO_WRONG_STATE) {
|
||||
PRINTF(" Failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRINTF(" Radio busy, retrying\n");
|
||||
|
||||
_delay_ms(10); //We have blocking delay here, it is safest this way
|
||||
|
||||
retry_count--;
|
||||
}
|
||||
|
||||
PRINTF("sicslowmac: Unable to send packet, dropped\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Stub function that will be implemented in phase 2 to cause
|
||||
* end nodes to sleep.
|
||||
*/
|
||||
int
|
||||
mac_wake(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Stub function that will be implemented in phase 2 to cause
|
||||
* end nodes to sleep.
|
||||
*/
|
||||
int
|
||||
mac_sleep(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const mac_driver_t *
|
||||
sicslowmac_init(const struct radio_driver *d)
|
||||
{
|
||||
/* AD: commented out the radio_driver code for now.*/
|
||||
/* radio = d;
|
||||
radio->set_receive_function(input_packet);
|
||||
radio->on();*/
|
||||
|
||||
return &sicslowmac_driver;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief This is the implementation of the 15.4 MAC Reset Request
|
||||
* primitive.
|
||||
* \param setDefaultPIB True if the default PIB values should be set.
|
||||
* \return Integer denoting success or failure.
|
||||
* \retval 0 Failure.
|
||||
* \retval 1 Success.
|
||||
*
|
||||
* Sets all PIB values to default.
|
||||
*/
|
||||
void
|
||||
sicslowmac_resetRequest (bool setDefaultPIB)
|
||||
{
|
||||
if(setDefaultPIB){
|
||||
/* initialize all of the MAC PIB variables to their default values */
|
||||
macCoordShortAddress = 0xffff;
|
||||
macDSN = rand() % 256;
|
||||
macSrcPANId = SOURCE_PAN_ID;
|
||||
macDstPANId = DEST_PAN_ID;
|
||||
macShortAddress = 0xffff;
|
||||
/* Setup the address of this device by reading a stored address from eeprom. */
|
||||
/** \todo This might be read from the serial eeprom onboard Raven. */
|
||||
AVR_ENTER_CRITICAL_REGION();
|
||||
eeprom_read_block ((void *)&macLongAddr, EEPROMMACADDRESS, 8);
|
||||
|
||||
byte_reverse((uint8_t *) &macLongAddr, 8);
|
||||
|
||||
|
||||
AVR_LEAVE_CRITICAL_REGION();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(mac_process, "802.15.4 MAC process");
|
||||
PROCESS_THREAD(mac_process, ev, data)
|
||||
{
|
||||
|
||||
PROCESS_POLLHANDLER(mac_pollhandler());
|
||||
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
radio_status_t return_value;
|
||||
|
||||
/* init radio */
|
||||
/** \todo: this screws up if calosc is set to TRUE, find out why? */
|
||||
return_value = radio_init(false, NULL, NULL, NULL);
|
||||
|
||||
#if DEBUG
|
||||
if (return_value == RADIO_SUCCESS) {
|
||||
printf("Radio init successful.\n");
|
||||
} else {
|
||||
printf("Radio init failed with return: %d\n", return_value);
|
||||
}
|
||||
#endif
|
||||
|
||||
radio_set_operating_channel(24);
|
||||
radio_use_auto_tx_crc(true);
|
||||
radio_set_trx_state(TRX_OFF);
|
||||
|
||||
mac_init();
|
||||
|
||||
/* Set up MAC function pointers and sicslowpan callback. */
|
||||
pmac_driver->set_receive_function = setinput;
|
||||
pmac_driver->send = sicslowmac_dataRequest;
|
||||
pmac_driver->wake = mac_wake;
|
||||
pmac_driver->sleep = mac_sleep;
|
||||
sicslowpan_init(pmac_driver);
|
||||
|
||||
ieee_15_4_init(&ieee15_4ManagerAddress);
|
||||
|
||||
radio_set_trx_state(RX_AACK_ON);
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
mac_task(ev, data);
|
||||
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
||||
void byte_reverse(uint8_t * bytes, uint8_t num)
|
||||
{
|
||||
uint8_t tempbyte;
|
||||
|
||||
uint8_t i, j;
|
||||
|
||||
i = 0;
|
||||
j = num - 1;
|
||||
|
||||
while(i < j) {
|
||||
tempbyte = bytes[i];
|
||||
bytes[i] = bytes[j];
|
||||
bytes[j] = tempbyte;
|
||||
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 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.
|
||||
*
|
||||
* $Id: sicslowmac.h,v 1.1 2008/10/14 09:43:40 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Example glue code between the existing MAC code and the
|
||||
* Contiki mac interface
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
* Eric Gnoske <egnoske@gmail.com>
|
||||
* Blake Leverett <bleverett@gmail.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
\addtogroup rf230mac
|
||||
*/
|
||||
|
||||
#ifndef __SICSLOWMAC_H__
|
||||
#define __SICSLOWMAC_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/radio.h"
|
||||
|
||||
/**
|
||||
* The structure of a device driver for a radio in Contiki.
|
||||
*/
|
||||
typedef struct mac_driver_s{
|
||||
/** Send a packet from the Rime buffer */
|
||||
int (* send)(void);
|
||||
|
||||
/** Read a received packet into the Rime buffer. */
|
||||
/* int (* read)(void); */
|
||||
|
||||
/** Set a function to be called when a packet has been received. */
|
||||
void (* set_receive_function)(void (*f)(const struct mac_driver_s *d));
|
||||
|
||||
/** Wake the radio up. */
|
||||
int (* wake)(void);
|
||||
|
||||
/** Put the radio to sleep. */
|
||||
int (* sleep)(void);
|
||||
}mac_driver_t;
|
||||
|
||||
/* Macros & Defines */
|
||||
|
||||
typedef enum {
|
||||
MAC_EVENT_RX=0x10,
|
||||
MAC_EVENT_ACK,
|
||||
MAC_EVENT_NACK,
|
||||
MAC_EVENT_SCAN,
|
||||
MAC_EVENT_BEACON_REQ,
|
||||
MAC_EVENT_DROPPED,
|
||||
MAC_EVENT_TX
|
||||
/* MAC_EVENT_TIMER */
|
||||
} event_t;
|
||||
|
||||
typedef struct {
|
||||
event_t event; /**< Event type, see event_t for details. */
|
||||
uint8_t *data; /**< Associated data that goes with the event. Depends on event type. */
|
||||
} event_object_t;
|
||||
|
||||
extern const mac_driver_t sicslowmac_driver;
|
||||
|
||||
/* Prototypes */
|
||||
PROCESS_NAME(mac_process);
|
||||
|
||||
uint8_t mac_event_pending(void);
|
||||
void mac_put_event(event_object_t *object);
|
||||
event_object_t *mac_get_event(void);
|
||||
void mac_task(process_event_t ev, process_data_t data);
|
||||
uint8_t nwk_dataIndication(void);
|
||||
const mac_driver_t *sicslowmac_init(const struct radio_driver *r);
|
||||
/* void sicslowmac_input_packet(const struct radio_driver *d); */
|
||||
int sicslowmac_dataRequest(void);
|
||||
void sicslowmac_dataIndication(void);
|
||||
void sicslowmac_resetRequest (bool setDefaultPIB);
|
||||
int sicsloread(void);
|
||||
void byte_reverse(uint8_t * bytes, uint8_t num);
|
||||
|
||||
#endif /* __SICSLOWMAC_H__ */
|
Loading…
Reference in a new issue