2013-06-18 17:21:38 +02:00
/**
2013-06-22 05:11:53 +02:00
* Generic transceiver module as an interface to NIC driver .
2013-06-18 17:21:38 +02:00
*
* Copyright ( C ) 2013 INRIA .
*
2013-11-22 20:47:05 +01:00
* This file is subject to the terms and conditions of the GNU Lesser General
2013-06-18 17:21:38 +02:00
* Public License . See the file LICENSE in the top level directory for more
* details .
*
* @ ingroup transceiver
* @ {
* @ file transceiver . c
* @ brief Providing a generic interface to the driver implementation for any supported network device .
* @ author Oliver Hahm < oliver . hahm @ inria . fr >
* @ }
*/
# include <stdint.h>
2010-11-19 20:10:09 +01:00
# include <stdio.h>
# include <errno.h>
2010-11-23 11:37:13 +01:00
# include <string.h>
2013-08-08 22:56:17 +02:00
# include <inttypes.h>
2010-11-23 11:37:13 +01:00
2013-08-10 12:15:51 +02:00
# include "thread.h"
# include "msg.h"
2013-08-08 11:08:33 +02:00
# include "irq.h"
2010-11-19 20:10:09 +01:00
2013-08-10 12:15:51 +02:00
# include "radio/types.h"
2010-11-19 20:10:09 +01:00
2013-08-08 23:43:15 +02:00
# include "transceiver.h"
2010-11-19 20:10:09 +01:00
/* supported transceivers */
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X
2014-02-07 18:26:21 +01:00
# include "cc110x.h"
2012-03-01 22:12:25 +01:00
# endif
2010-11-23 11:37:13 +01:00
# ifdef MODULE_CC110X_NG
2013-08-10 12:15:51 +02:00
# include "cc110x_ng.h"
2010-11-23 11:37:13 +01:00
# endif
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2013-08-10 12:15:51 +02:00
# include "cc2420.h"
2014-01-24 16:59:06 +01:00
# include "ieee802154_frame.h"
2013-05-02 08:45:47 +02:00
# endif
2013-07-24 23:22:11 +02:00
# ifdef MODULE_MC1322X
2013-08-10 12:15:51 +02:00
# include "mc1322x.h"
# include "maca.h"
# include "maca_packet.h"
2014-01-24 16:59:06 +01:00
# include "ieee802154_frame.h"
2013-07-24 23:22:11 +02:00
# endif
2013-07-23 15:27:12 +02:00
2013-08-08 11:08:33 +02:00
# ifdef MODULE_NATIVENET
# include "nativenet.h"
# include "nativenet_internal.h"
# endif
2013-08-15 19:07:14 +02:00
# ifdef MODULE_AT86RF231
2013-12-16 17:54:58 +01:00
# include "at86rf231.h"
2014-01-24 16:59:06 +01:00
# include "ieee802154_frame.h"
2013-07-24 23:22:11 +02:00
# endif
2013-07-23 15:27:12 +02:00
2013-07-24 00:36:06 +02:00
# define ENABLE_DEBUG (0)
2013-08-08 23:43:15 +02:00
# if ENABLE_DEBUG
2014-01-24 16:59:06 +01:00
# define DEBUG_ENABLED
2013-08-11 14:12:32 +02:00
# undef TRANSCEIVER_STACK_SIZE
2014-03-09 10:30:22 +01:00
# define TRANSCEIVER_STACK_SIZE (KERNEL_CONF_STACKSIZE_MAIN)
2013-08-08 23:43:15 +02:00
# endif
2013-08-10 12:15:51 +02:00
# include "debug.h"
2010-11-19 20:10:09 +01:00
2010-11-26 10:23:46 +01:00
/*------------------------------------------------------------------------------------*/
2010-11-21 14:00:24 +01:00
/* used transceiver types */
2010-11-23 11:37:13 +01:00
transceiver_type_t transceivers = TRANSCEIVER_NONE ;
2010-11-21 14:00:24 +01:00
2010-11-26 10:23:46 +01:00
/* registered upper layer threads */
2010-11-21 14:00:24 +01:00
registered_t reg [ TRANSCEIVER_MAX_REGISTERED ] ;
/* packet buffers */
2014-01-24 16:59:06 +01:00
# if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
ieee802154_packet_t transceiver_buffer [ TRANSCEIVER_BUFFER_SIZE ] ;
# else
2010-11-19 20:10:09 +01:00
radio_packet_t transceiver_buffer [ TRANSCEIVER_BUFFER_SIZE ] ;
2014-01-24 16:59:06 +01:00
# endif
2013-08-11 14:12:32 +02:00
uint8_t data_buffer [ TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE ] ;
2010-11-19 20:10:09 +01:00
2010-11-27 19:27:05 +01:00
/* message buffer */
2011-07-10 22:49:41 +02:00
msg_t msg_buffer [ TRANSCEIVER_MSG_BUFFER_SIZE ] ;
2010-11-27 19:27:05 +01:00
2010-11-26 10:23:46 +01:00
uint32_t response ; ///< response bytes for messages to upper layer threads
2013-06-24 22:12:57 +02:00
int transceiver_pid = - 1 ; ///< the transceiver thread's pid
2010-11-27 11:09:42 +01:00
2010-11-19 20:10:09 +01:00
static volatile uint8_t rx_buffer_pos = 0 ;
static volatile uint8_t transceiver_buffer_pos = 0 ;
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X
2014-01-31 14:36:09 +01:00
void * cc1100_payload ;
int cc1100_payload_size ;
packet_info_t * cc1100_packet_info ;
uint8_t cc1100_pkt [ CC1100_MAX_DATA_LENGTH ] ;
2012-03-01 22:12:25 +01:00
# endif
2010-11-21 14:00:24 +01:00
/* transceiver stack */
2010-11-24 11:20:27 +01:00
char transceiver_stack [ TRANSCEIVER_STACK_SIZE ] ;
2010-11-19 20:10:09 +01:00
2010-11-26 10:23:46 +01:00
/*------------------------------------------------------------------------------------*/
2010-11-21 14:00:24 +01:00
/* function prototypes */
2010-11-23 11:37:13 +01:00
static void run ( void ) ;
2010-11-24 11:20:27 +01:00
static void receive_packet ( uint16_t type , uint8_t pos ) ;
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2010-12-11 12:09:20 +01:00
static void receive_cc110x_packet ( radio_packet_t * trans_p ) ;
2013-08-15 20:08:18 +02:00
# endif
# ifdef MODULE_CC110X
2013-06-22 05:11:53 +02:00
void cc1100_packet_monitor ( void * payload , int payload_size , protocol_t protocol , packet_info_t * packet_info ) ;
2012-03-01 22:12:25 +01:00
void receive_cc1100_packet ( radio_packet_t * trans_p ) ;
2013-08-15 20:08:18 +02:00
# endif
# ifdef MODULE_CC2420
2014-01-24 16:59:06 +01:00
static void receive_cc2420_packet ( ieee802154_packet_t * trans_p ) ;
2013-08-15 20:08:18 +02:00
# endif
# ifdef MODULE_NATIVENET
2013-08-08 11:08:33 +02:00
static void receive_nativenet_packet ( radio_packet_t * trans_p ) ;
2013-08-15 20:08:18 +02:00
# endif
# ifdef MODULE_AT86RF231
2014-01-24 16:59:06 +01:00
void receive_at86rf231_packet ( ieee802154_packet_t * trans_p ) ;
2012-03-01 22:12:25 +01:00
# endif
2013-11-23 14:03:26 +01:00
static int8_t send_packet ( transceiver_type_t t , void * pkt ) ;
2014-02-06 02:32:38 +01:00
static int32_t get_channel ( transceiver_type_t t ) ;
static int32_t set_channel ( transceiver_type_t t , void * channel ) ;
2014-01-31 09:55:24 +01:00
static radio_address_t get_address ( transceiver_type_t t ) ;
static radio_address_t set_address ( transceiver_type_t t , void * address ) ;
2014-01-21 17:08:27 +01:00
static transceiver_eui64_t get_long_addr ( transceiver_type_t t ) ;
static transceiver_eui64_t set_long_addr ( transceiver_type_t t ,
void * address ) ;
2014-02-06 02:32:38 +01:00
static int32_t get_pan ( transceiver_type_t t ) ;
static int32_t set_pan ( transceiver_type_t t , void * pan ) ;
2013-05-02 08:45:47 +02:00
2010-11-27 10:50:18 +01:00
static void set_monitor ( transceiver_type_t t , void * mode ) ;
2010-12-02 15:38:28 +01:00
static void powerdown ( transceiver_type_t t ) ;
static void switch_to_rx ( transceiver_type_t t ) ;
2010-11-19 20:10:09 +01:00
2012-02-08 17:14:50 +01:00
# ifdef DBG_IGNORE
2014-02-15 12:58:55 +01:00
static int16_t ignore_add ( transceiver_type_t transceiver , void * address ) ;
2013-11-19 23:45:03 +01:00
# define MAX_IGNORED_ADDR (10)
radio_address_t ignored_addr [ MAX_IGNORED_ADDR ] ;
2012-02-08 17:14:50 +01:00
# endif
2010-11-26 10:23:46 +01:00
/*------------------------------------------------------------------------------------*/
/* Transceiver init */
2013-06-22 05:11:53 +02:00
void transceiver_init ( transceiver_type_t t )
{
2010-11-21 14:00:24 +01:00
uint8_t i ;
2011-12-26 02:59:58 +01:00
2013-06-24 22:12:57 +02:00
if ( transceiver_pid > = 0 ) {
/* do not re-initialize an already running transceiver */
return ;
}
2011-12-26 02:59:58 +01:00
/* Initializing transceiver buffer and data buffer */
2014-01-24 16:59:06 +01:00
memset ( transceiver_buffer , 0 , sizeof ( transceiver_buffer ) ) ;
2011-12-26 02:59:58 +01:00
memset ( data_buffer , 0 , TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE ) ;
2013-11-19 23:45:03 +01:00
# ifdef DBG_IGNORE
memset ( ignored_addr , 0 , MAX_IGNORED_ADDR * sizeof ( radio_address_t ) ) ;
# endif
2011-12-26 02:59:58 +01:00
2013-06-24 22:37:35 +02:00
for ( i = 0 ; i < TRANSCEIVER_MAX_REGISTERED ; i + + ) {
2010-11-23 11:37:13 +01:00
reg [ i ] . transceivers = TRANSCEIVER_NONE ;
reg [ i ] . pid = 0 ;
2010-11-21 14:00:24 +01:00
}
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
/* check if a non defined bit is set */
2013-08-15 19:07:14 +02:00
if ( t & ~ ( TRANSCEIVER_CC1100 | TRANSCEIVER_CC2420 | TRANSCEIVER_MC1322X | TRANSCEIVER_NATIVE | TRANSCEIVER_AT86RF231 ) ) {
2013-08-10 12:15:51 +02:00
puts ( " Invalid transceiver type " ) ;
2013-07-23 15:27:12 +02:00
}
2010-11-21 14:00:24 +01:00
else {
2013-08-10 12:15:51 +02:00
transceivers | = t ;
2010-11-19 20:10:09 +01:00
}
}
2010-11-26 10:23:46 +01:00
/* Start the transceiver thread */
2013-06-22 05:11:53 +02:00
int transceiver_start ( void )
{
transceiver_pid = thread_create ( transceiver_stack , TRANSCEIVER_STACK_SIZE , PRIORITY_MAIN - 3 , CREATE_STACKTEST , run , " Transceiver " ) ;
2013-06-24 22:37:35 +02:00
if ( transceiver_pid < 0 ) {
2010-11-19 20:10:09 +01:00
puts ( " Error creating transceiver thread " ) ;
}
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC110X_NG
2013-06-24 22:37:35 +02:00
else if ( transceivers & TRANSCEIVER_CC1100 ) {
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Transceiver started for CC1100 \n " ) ;
2010-12-11 12:09:20 +01:00
cc110x_init ( transceiver_pid ) ;
2013-05-02 08:45:47 +02:00
}
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
# endif
# ifdef MODULE_CC110X
2013-05-02 08:45:47 +02:00
else if ( transceivers & TRANSCEIVER_CC1100 ) {
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Transceiver started for CC1100 \n " ) ;
2012-03-01 22:12:25 +01:00
cc1100_init ( ) ;
cc1100_set_packet_monitor ( cc1100_packet_monitor ) ;
2010-11-23 11:37:13 +01:00
}
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
# endif
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
else if ( transceivers & TRANSCEIVER_CC2420 ) {
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Transceiver started for CC2420 \n " ) ;
2013-05-02 08:45:47 +02:00
cc2420_init ( transceiver_pid ) ;
}
2014-01-31 14:36:09 +01:00
2013-07-24 23:22:11 +02:00
# endif
2013-08-15 19:07:14 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
else if ( transceivers & TRANSCEIVER_AT86RF231 ) {
2013-08-15 19:07:14 +02:00
DEBUG ( " transceiver: Transceiver started for AT86RF231 \n " ) ;
2013-07-12 12:31:16 +02:00
at86rf231_init ( transceiver_pid ) ;
}
2014-01-31 14:36:09 +01:00
2013-07-24 23:22:11 +02:00
# endif
# ifdef MODULE_MC1322X
2013-07-23 15:27:12 +02:00
else if ( transceivers & TRANSCEIVER_MC1322X ) {
maca_init ( ) ;
}
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
else if ( transceivers & TRANSCEIVER_NATIVE ) {
nativenet_init ( transceiver_pid ) ;
}
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
# endif
2010-11-27 11:09:42 +01:00
return transceiver_pid ;
2010-11-19 20:10:09 +01:00
}
2010-11-26 10:23:46 +01:00
/* Register an upper layer thread */
2013-06-22 05:11:53 +02:00
uint8_t transceiver_register ( transceiver_type_t t , int pid )
{
uint8_t i ;
2013-11-22 12:31:37 +01:00
/* find pid in registered threads or first unused space */
2014-02-07 09:06:34 +01:00
for ( i = 0 ; ( ( i < TRANSCEIVER_MAX_REGISTERED ) & &
2014-01-31 14:36:09 +01:00
( reg [ i ] . pid ! = pid ) & &
( reg [ i ] . transceivers ! = TRANSCEIVER_NONE ) ) ; i + + ) ;
2013-06-22 05:11:53 +02:00
2013-06-24 22:37:35 +02:00
if ( i > = TRANSCEIVER_MAX_REGISTERED ) {
2013-06-22 05:11:53 +02:00
return ENOMEM ;
}
else {
reg [ i ] . transceivers | = t ;
reg [ i ] . pid = pid ;
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Thread %i registered for %i \n " , reg [ i ] . pid , reg [ i ] . transceivers ) ;
2013-06-22 05:11:53 +02:00
return 1 ;
}
2010-11-21 14:00:24 +01:00
}
/*------------------------------------------------------------------------------------*/
/* Internal functions */
/*------------------------------------------------------------------------------------*/
2010-11-26 10:23:46 +01:00
/*
* @ brief The main thread run , receiving and processing messages in an infinite
* loop
*/
2013-06-22 05:11:53 +02:00
void run ( void )
{
2011-07-10 22:49:41 +02:00
msg_t m ;
2010-11-24 21:45:38 +01:00
transceiver_command_t * cmd ;
2010-11-24 11:20:27 +01:00
2010-11-27 19:27:05 +01:00
msg_init_queue ( msg_buffer , TRANSCEIVER_MSG_BUFFER_SIZE ) ;
2013-06-22 05:11:53 +02:00
2013-06-24 22:37:35 +02:00
while ( 1 ) {
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Waiting for next message \n " ) ;
2010-11-19 20:10:09 +01:00
msg_receive ( & m ) ;
2010-11-26 10:23:46 +01:00
/* only makes sense for messages for upper layers */
2013-06-22 05:11:53 +02:00
cmd = ( transceiver_command_t * ) m . content . ptr ;
2013-10-23 18:49:36 +02:00
DEBUG ( " transceiver: Transceiver: Message received, type: %02X \n " , m . type ) ;
2013-06-22 05:11:53 +02:00
2014-01-31 14:36:09 +01:00
switch ( m . type ) {
2010-11-24 11:20:27 +01:00
case RCV_PKT_CC1020 :
case RCV_PKT_CC1100 :
2013-05-02 08:45:47 +02:00
case RCV_PKT_CC2420 :
2013-08-10 12:15:51 +02:00
case RCV_PKT_MC1322X :
2013-08-08 11:08:33 +02:00
case RCV_PKT_NATIVE :
2013-07-12 12:31:16 +02:00
case RCV_PKT_AT86RF231 :
2013-05-02 08:45:47 +02:00
receive_packet ( m . type , m . content . value ) ;
break ;
2014-01-31 14:36:09 +01:00
2010-11-21 14:00:24 +01:00
case SND_PKT :
2010-11-26 10:23:46 +01:00
response = send_packet ( cmd - > transceivers , cmd - > data ) ;
m . content . value = response ;
msg_reply ( & m , & m ) ;
2010-11-24 21:45:38 +01:00
break ;
2013-06-22 05:11:53 +02:00
2010-11-24 21:45:38 +01:00
case GET_CHANNEL :
2014-02-06 02:32:38 +01:00
* ( ( int32_t * ) cmd - > data ) = get_channel ( cmd - > transceivers ) ;
2010-11-24 21:45:38 +01:00
msg_reply ( & m , & m ) ;
break ;
2013-06-22 05:11:53 +02:00
2010-11-24 21:45:38 +01:00
case SET_CHANNEL :
2014-02-06 02:32:38 +01:00
* ( ( int32_t * ) cmd - > data ) = set_channel ( cmd - > transceivers , cmd - > data ) ;
2010-11-26 10:23:46 +01:00
msg_reply ( & m , & m ) ;
break ;
2013-06-22 05:11:53 +02:00
2010-11-26 10:23:46 +01:00
case GET_ADDRESS :
2014-01-31 09:55:24 +01:00
* ( ( radio_address_t * ) cmd - > data ) = get_address ( cmd - > transceivers ) ;
2010-11-26 10:23:46 +01:00
msg_reply ( & m , & m ) ;
break ;
2013-06-22 05:11:53 +02:00
2010-11-26 10:23:46 +01:00
case SET_ADDRESS :
2014-01-31 09:55:24 +01:00
* ( ( radio_address_t * ) cmd - > data ) = set_address ( cmd - > transceivers , cmd - > data ) ;
2010-11-24 21:45:38 +01:00
msg_reply ( & m , & m ) ;
2010-11-21 14:00:24 +01:00
break ;
2013-06-22 05:11:53 +02:00
2014-01-21 17:08:27 +01:00
case GET_LONG_ADDR :
* ( ( transceiver_eui64_t * ) cmd - > data ) = get_long_addr ( cmd - > transceivers ) ;
msg_reply ( & m , & m ) ;
break ;
case SET_LONG_ADDR :
* ( ( transceiver_eui64_t * ) cmd - > data ) = set_long_addr ( cmd - > transceivers , cmd - > data ) ;
msg_reply ( & m , & m ) ;
break ;
2010-11-27 10:50:18 +01:00
case SET_MONITOR :
set_monitor ( cmd - > transceivers , cmd - > data ) ;
break ;
2013-06-22 05:11:53 +02:00
2010-12-02 15:38:28 +01:00
case POWERDOWN :
powerdown ( cmd - > transceivers ) ;
break ;
2013-06-22 05:11:53 +02:00
2010-12-02 15:38:28 +01:00
case SWITCH_RX :
switch_to_rx ( cmd - > transceivers ) ;
break ;
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
case GET_PAN :
2014-02-06 02:32:38 +01:00
* ( ( int32_t * ) cmd - > data ) = get_pan ( cmd - > transceivers ) ;
2013-05-02 08:45:47 +02:00
msg_reply ( & m , & m ) ;
break ;
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
case SET_PAN :
2014-02-06 02:32:38 +01:00
* ( ( int32_t * ) cmd - > data ) = set_pan ( cmd - > transceivers , cmd - > data ) ;
2013-05-02 08:45:47 +02:00
msg_reply ( & m , & m ) ;
break ;
2012-02-08 17:14:50 +01:00
# ifdef DBG_IGNORE
2014-01-31 14:36:09 +01:00
2012-02-08 17:14:50 +01:00
case DBG_IGN :
2014-01-31 14:36:09 +01:00
* ( ( int16_t * ) cmd - > data ) = ignore_add ( cmd - > transceivers , cmd - > data ) ;
2013-11-19 23:45:03 +01:00
msg_reply ( & m , & m ) ;
2012-02-08 17:14:50 +01:00
break ;
# endif
2013-06-22 05:11:53 +02:00
2010-11-19 20:10:09 +01:00
default :
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Unknown message received \n " ) ;
2010-11-19 20:10:09 +01:00
break ;
}
}
}
2010-11-26 10:23:46 +01:00
/*------------------------------------------------------------------------------------*/
/*
* @ brief Processes a packet received by any transceiver device
*
* @ param type The message type to determine which device has received the
* packet
* @ param pos The current device driver ' s buffer position
*/
2013-06-22 05:11:53 +02:00
static void receive_packet ( uint16_t type , uint8_t pos )
{
2010-11-21 14:00:24 +01:00
uint8_t i = 0 ;
2010-11-24 11:20:27 +01:00
transceiver_type_t t ;
rx_buffer_pos = pos ;
2011-07-10 22:49:41 +02:00
msg_t m ;
2013-06-22 05:11:53 +02:00
2010-11-24 13:47:31 +01:00
DEBUG ( " Packet received \n " ) ;
2013-06-22 05:11:53 +02:00
2014-01-31 14:36:09 +01:00
switch ( type ) {
2010-11-24 11:20:27 +01:00
case RCV_PKT_CC1020 :
t = TRANSCEIVER_CC1020 ;
break ;
2013-06-22 05:11:53 +02:00
2010-11-24 11:20:27 +01:00
case RCV_PKT_CC1100 :
t = TRANSCEIVER_CC1100 ;
break ;
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
case RCV_PKT_CC2420 :
t = TRANSCEIVER_CC2420 ;
break ;
2014-01-31 14:36:09 +01:00
2013-07-23 15:27:12 +02:00
case RCV_PKT_MC1322X :
t = TRANSCEIVER_MC1322X ;
break ;
2014-01-31 14:36:09 +01:00
case RCV_PKT_NATIVE :
t = TRANSCEIVER_NATIVE ;
break ;
2013-07-12 12:31:16 +02:00
case RCV_PKT_AT86RF231 :
t = TRANSCEIVER_AT86RF231 ;
break ;
2014-01-31 14:36:09 +01:00
2010-11-24 11:20:27 +01:00
default :
t = TRANSCEIVER_NONE ;
break ;
}
2013-06-22 05:11:53 +02:00
2010-11-24 11:20:27 +01:00
/* search first free position in transceiver buffer */
2013-06-24 22:37:35 +02:00
for ( i = 0 ; ( i < TRANSCEIVER_BUFFER_SIZE ) & & ( transceiver_buffer [ transceiver_buffer_pos ] . processing ) ; i + + ) {
if ( + + transceiver_buffer_pos = = TRANSCEIVER_BUFFER_SIZE ) {
2010-11-27 19:27:05 +01:00
transceiver_buffer_pos = 0 ;
}
2010-11-23 11:37:13 +01:00
}
2013-06-22 05:11:53 +02:00
2010-11-24 11:20:27 +01:00
/* no buffer left */
2013-06-24 22:37:35 +02:00
if ( i > = TRANSCEIVER_BUFFER_SIZE ) {
2010-11-24 11:20:27 +01:00
/* inform upper layers of lost packet */
2010-11-23 11:37:13 +01:00
m . type = ENOBUFFER ;
m . content . value = t ;
}
2010-11-24 11:20:27 +01:00
/* copy packet and handle it */
2010-11-23 11:37:13 +01:00
else {
m . type = PKT_PENDING ;
2013-08-10 12:15:51 +02:00
/* pass a null pointer if a packet from a undefined transceiver is
* received */
2013-06-24 22:37:35 +02:00
if ( type = = RCV_PKT_CC1100 ) {
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2014-01-24 16:59:06 +01:00
radio_packet_t * trans_p = & ( transceiver_buffer [ transceiver_buffer_pos ] ) ;
2014-02-11 18:15:43 +01:00
receive_cc110x_packet ( trans_p ) ;
2013-05-02 08:45:47 +02:00
# elif MODULE_CC110X
2014-01-24 16:59:06 +01:00
radio_packet_t * trans_p = & ( transceiver_buffer [ transceiver_buffer_pos ] ) ;
2012-03-01 22:12:25 +01:00
receive_cc1100_packet ( trans_p ) ;
2013-05-02 08:45:47 +02:00
# endif
2014-02-11 18:15:43 +01:00
}
2013-07-24 23:53:23 +02:00
else if ( type = = RCV_PKT_MC1322X ) {
# ifdef MODULE_MC1322X
2014-01-24 16:59:06 +01:00
ieee802154_packet_t * trans_p = & ( transceiver_buffer [ transceiver_buffer_pos ] ) ;
2013-07-23 15:27:12 +02:00
receive_mc1322x_packet ( trans_p ) ;
2013-07-24 23:53:23 +02:00
# endif
2013-05-02 08:45:47 +02:00
}
else if ( type = = RCV_PKT_CC2420 ) {
# ifdef MODULE_CC2420
2014-01-24 16:59:06 +01:00
ieee802154_packet_t * trans_p = & ( transceiver_buffer [ transceiver_buffer_pos ] ) ;
2013-05-02 08:45:47 +02:00
receive_cc2420_packet ( trans_p ) ;
2013-08-08 11:08:33 +02:00
# endif
}
2013-07-12 12:31:16 +02:00
else if ( type = = RCV_PKT_AT86RF231 ) {
# ifdef MODULE_AT86RF231
2014-01-24 16:59:06 +01:00
ieee802154_packet_t * trans_p = & ( transceiver_buffer [ transceiver_buffer_pos ] ) ;
2013-07-12 12:31:16 +02:00
receive_at86rf231_packet ( trans_p ) ;
2012-03-01 22:12:25 +01:00
# endif
2014-01-08 17:01:22 +01:00
}
2013-08-08 11:08:33 +02:00
else if ( type = = RCV_PKT_NATIVE ) {
# ifdef MODULE_NATIVENET
2014-01-24 16:59:06 +01:00
radio_packet_t * trans_p = & ( transceiver_buffer [ transceiver_buffer_pos ] ) ;
2013-08-08 11:08:33 +02:00
receive_nativenet_packet ( trans_p ) ;
2012-03-01 22:12:25 +01:00
# endif
2010-11-23 11:37:13 +01:00
}
else {
puts ( " Invalid transceiver type " ) ;
return ;
2010-11-21 14:00:24 +01:00
}
2014-01-31 14:36:09 +01:00
2013-11-19 23:45:03 +01:00
# ifdef DBG_IGNORE
2014-01-31 14:36:09 +01:00
2013-11-19 23:45:03 +01:00
for ( uint8_t i = 0 ; ( i < MAX_IGNORED_ADDR ) & & ( ignored_addr [ i ] ) ; i + + ) {
2014-03-07 06:21:01 +01:00
DEBUG ( " check if source (%u) is ignored -> %u \n " , transceiver_buffer [ transceiver_buffer_pos ] . src , ignored_addr [ i ] ) ;
2014-01-31 14:36:09 +01:00
2014-03-07 06:21:01 +01:00
if ( transceiver_buffer [ transceiver_buffer_pos ] . src = = ignored_addr [ i ] ) {
DEBUG ( " ignored packet from % " PRIu16 " \n " , transceiver_buffer [ transceiver_buffer_pos ] . src ) ;
2013-11-19 23:45:03 +01:00
return ;
}
}
2014-01-31 14:36:09 +01:00
2013-11-19 23:45:03 +01:00
# endif
2010-11-19 20:10:09 +01:00
}
2010-11-23 11:37:13 +01:00
2010-11-24 11:20:27 +01:00
/* finally notify waiting upper layers
* this is done non - blocking , so packets can get lost */
2010-11-27 19:27:05 +01:00
i = 0 ;
2013-06-22 05:11:53 +02:00
2013-06-24 22:37:35 +02:00
while ( reg [ i ] . transceivers ! = TRANSCEIVER_NONE ) {
if ( reg [ i ] . transceivers & t ) {
2014-01-31 14:36:09 +01:00
m . content . ptr = ( char * ) & ( transceiver_buffer [ transceiver_buffer_pos ] ) ;
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Notify thread %i \n " , reg [ i ] . pid ) ;
2013-06-22 05:11:53 +02:00
2013-06-24 22:37:35 +02:00
if ( msg_send ( & m , reg [ i ] . pid , false ) & & ( m . type ! = ENOBUFFER ) ) {
2010-11-27 19:27:05 +01:00
transceiver_buffer [ transceiver_buffer_pos ] . processing + + ;
}
2010-11-23 11:37:13 +01:00
}
2013-06-22 05:11:53 +02:00
2010-11-23 11:37:13 +01:00
i + + ;
2010-11-21 14:00:24 +01:00
}
}
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2010-11-26 10:23:46 +01:00
/*
* @ brief process packets from CC1100
*
* @ param trans_p The current entry in the transceiver buffer
*/
2013-06-22 05:11:53 +02:00
static void receive_cc110x_packet ( radio_packet_t * trans_p )
{
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Handling CC1100 packet \n " ) ;
2010-11-23 11:37:13 +01:00
/* disable interrupts while copying packet */
dINT ( ) ;
2010-12-11 12:09:20 +01:00
cc110x_packet_t p = cc110x_rx_buffer [ rx_buffer_pos ] . packet ;
2013-06-22 05:11:53 +02:00
2010-11-23 11:37:13 +01:00
trans_p - > src = p . phy_src ;
trans_p - > dst = p . address ;
2010-12-11 12:09:20 +01:00
trans_p - > rssi = cc110x_rx_buffer [ rx_buffer_pos ] . rssi ;
trans_p - > lqi = cc110x_rx_buffer [ rx_buffer_pos ] . lqi ;
2010-11-26 17:06:54 +01:00
trans_p - > length = p . length - CC1100_HEADER_LENGTH ;
2014-01-31 14:36:09 +01:00
memcpy ( ( void * ) & ( data_buffer [ transceiver_buffer_pos * PAYLOAD_SIZE ] ) , p . data , CC1100_MAX_DATA_LENGTH ) ;
2010-11-23 11:37:13 +01:00
eINT ( ) ;
2014-01-31 14:36:09 +01:00
trans_p - > data = ( uint8_t * ) & ( data_buffer [ transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH ] ) ;
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Packet %p (%p) was from %hu to %hu, size: %u \n " , trans_p , trans_p - > data , trans_p - > src , trans_p - > dst , trans_p - > length ) ;
2010-11-23 11:37:13 +01:00
}
2012-03-01 22:12:25 +01:00
# endif
# ifdef MODULE_CC110X
2013-06-22 05:11:53 +02:00
void receive_cc1100_packet ( radio_packet_t * trans_p )
{
2012-03-01 22:12:25 +01:00
dINT ( ) ;
trans_p - > src = cc1100_packet_info - > source ;
trans_p - > dst = cc1100_packet_info - > destination ;
trans_p - > rssi = cc1100_packet_info - > rssi ;
trans_p - > lqi = cc1100_packet_info - > lqi ;
trans_p - > length = cc1100_payload_size ;
2014-01-31 14:36:09 +01:00
memcpy ( ( void * ) & ( data_buffer [ transceiver_buffer_pos * PAYLOAD_SIZE ] ) , cc1100_payload , CC1100_MAX_DATA_LENGTH ) ;
2012-03-01 22:12:25 +01:00
eINT ( ) ;
2014-01-31 14:36:09 +01:00
trans_p - > data = ( uint8_t * ) & ( data_buffer [ transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH ] ) ;
2012-03-01 22:12:25 +01:00
}
# endif
2013-06-22 05:11:53 +02:00
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-24 16:59:06 +01:00
void receive_cc2420_packet ( ieee802154_packet_t * trans_p )
2014-01-31 14:36:09 +01:00
{
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Handling CC2420 packet \n " ) ;
2013-05-02 08:45:47 +02:00
dINT ( ) ;
2014-01-24 16:59:06 +01:00
cc2420_packet_t * p = & cc2420_rx_buffer [ rx_buffer_pos ] ;
trans_p - > length = p - > length ;
memcpy ( & trans_p - > frame , & p - > frame , p - > length ) ;
trans_p - > rssi = p - > rssi ;
trans_p - > crc = p - > crc ;
trans_p - > lqi = p - > lqi ;
memcpy ( & data_buffer [ transceiver_buffer_pos * CC2420_MAX_DATA_LENGTH ] ,
p - > frame . payload , p - > frame . payload_len ) ;
trans_p - > frame . payload = ( uint8_t * ) & ( data_buffer [ transceiver_buffer_pos * CC2420_MAX_DATA_LENGTH ] ) ;
2013-05-02 08:45:47 +02:00
eINT ( ) ;
2014-01-24 16:59:06 +01:00
# ifdef DEBUG_ENABLED
if ( trans_p - > frame . fcf . dest_addr_m = = IEEE_802154_SHORT_ADDR_M ) {
if ( trans_p - > frame . fcf . src_addr_m = = IEEE_802154_SHORT_ADDR_M ) {
DEBUG ( " Packet %p was from % " PRIu16 " to % " PRIu16 " , size: %u \n " , trans_p , * ( ( uint16_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint16_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
else if ( trans_p - > frame . fcf . src_addr_m = = IEEE_802154_LONG_ADDR_M ) {
DEBUG ( " Packet %p was from %016 " PRIx64 " to % " PRIu16 " , size: %u \n " , trans_p , * ( ( uint64_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint16_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
else {
DEBUG ( " Illegal source address mode: %d \n " , trans_p - > frame . fcf . src_addr_m ) ;
return ;
}
}
else if ( trans_p - > frame . fcf . dest_addr_m = = IEEE_802154_LONG_ADDR_M ) {
if ( trans_p - > frame . fcf . src_addr_m = = IEEE_802154_SHORT_ADDR_M ) {
DEBUG ( " Packet %p was from % " PRIu16 " to %016 " PRIx64 " , size: %u \n " , trans_p , * ( ( uint16_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint64_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
else if ( trans_p - > frame . fcf . src_addr_m = = IEEE_802154_LONG_ADDR_M ) {
DEBUG ( " Packet %p was from %016 " PRIx64 " to %016 " PRIx64 " , size: %u \n " , trans_p , * ( ( uint64_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint16_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
else {
DEBUG ( " Illegal source address mode: %d \n " , trans_p - > frame . fcf . src_addr_m ) ;
return ;
}
}
else {
DEBUG ( " Illegal destination address mode: %d \n " , trans_p - > frame . fcf . src_addr_m ) ;
return ;
}
# endif
trans_p - > frame . payload = ( uint8_t * ) & ( data_buffer [ transceiver_buffer_pos * CC2420_MAX_DATA_LENGTH ] ) ;
trans_p - > frame . payload_len = p - > frame . payload_len ;
2013-08-11 14:12:32 +02:00
DEBUG ( " transceiver: Content: %s \n " , trans_p - > data ) ;
2013-05-02 08:45:47 +02:00
}
# endif
2013-07-24 23:22:11 +02:00
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
void receive_mc1322x_packet ( radio_packet_t * trans_p )
{
maca_packet_t * maca_pkt ;
2013-07-23 15:27:12 +02:00
dINT ( ) ;
2014-01-31 14:36:09 +01:00
maca_pkt = maca_get_rx_packet ( ) ;
2013-07-23 15:27:12 +02:00
trans_p - > lqi = maca_pkt - > lqi ;
trans_p - > length = maca_pkt - > length ;
2014-01-31 14:36:09 +01:00
memcpy ( ( void * ) & ( data_buffer [ transceiver_buffer_pos * PAYLOAD_SIZE ] ) , maca_pkt - > data , MACA_MAX_PAYLOAD_SIZE ) ;
maca_free_packet ( maca_pkt ) ;
2013-07-23 15:27:12 +02:00
eINT ( ) ;
2014-02-11 18:15:43 +01:00
2014-01-31 14:36:09 +01:00
trans_p - > data = ( uint8_t * ) & ( data_buffer [ transceiver_buffer_pos * MACA_MAX_PAYLOAD_SIZE ] ) ;
2013-07-23 15:27:12 +02:00
}
2013-07-24 23:22:11 +02:00
# endif
2013-07-23 15:27:12 +02:00
2014-02-11 18:15:43 +01:00
2013-08-08 11:08:33 +02:00
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
void receive_nativenet_packet ( radio_packet_t * trans_p )
{
2013-08-08 11:08:33 +02:00
unsigned state ;
radio_packet_t * p = & _nativenet_rx_buffer [ rx_buffer_pos ] . packet ;
/* disable interrupts while copying packet */
state = disableIRQ ( ) ;
DEBUG ( " Handling nativenet packet \n " ) ;
memcpy ( trans_p , p , sizeof ( radio_packet_t ) ) ;
2013-09-04 20:40:58 +02:00
memcpy ( & ( data_buffer [ transceiver_buffer_pos * PAYLOAD_SIZE ] ) , p - > data , p - > length ) ;
2014-01-31 14:36:09 +01:00
trans_p - > data = ( uint8_t * ) & ( data_buffer [ transceiver_buffer_pos * PAYLOAD_SIZE ] ) ;
2013-08-08 11:08:33 +02:00
2014-02-18 16:54:42 +01:00
DEBUG ( " Packet %p was from % " PRIu16 " to % " PRIu16 " , size: % " PRIu8 " \n " , trans_p , trans_p - > src , trans_p - > dst , trans_p - > length ) ;
2013-08-08 11:08:33 +02:00
/* reset interrupts */
restoreIRQ ( state ) ;
}
# endif
2013-08-15 19:07:14 +02:00
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-24 16:59:06 +01:00
void receive_at86rf231_packet ( ieee802154_packet_t * trans_p )
2014-01-31 14:36:09 +01:00
{
2013-07-12 12:31:16 +02:00
DEBUG ( " Handling AT86RF231 packet \n " ) ;
dINT ( ) ;
2014-01-24 16:59:06 +01:00
at86rf231_packet_t * p = & at86rf231_rx_buffer [ rx_buffer_pos ] ;
trans_p - > length = p - > length ;
trans_p - > rssi = p - > rssi ;
trans_p - > crc = p - > crc ;
trans_p - > lqi = p - > lqi ;
memcpy ( & trans_p - > frame , & p - > frame , p - > length ) ;
memcpy ( & data_buffer [ transceiver_buffer_pos * AT86RF231_MAX_DATA_LENGTH ] , p - > frame . payload ,
p - > frame . payload_len ) ;
trans_p - > frame . payload = ( uint8_t * ) & ( data_buffer [ transceiver_buffer_pos * AT86RF231_MAX_DATA_LENGTH ] ) ;
2013-07-12 12:31:16 +02:00
eINT ( ) ;
2014-01-24 16:59:06 +01:00
# ifdef DEBUG_ENABLED
if ( trans_p - > frame . fcf . dest_addr_m = = IEEE_802154_SHORT_ADDR_M ) {
if ( trans_p - > frame . fcf . src_addr_m = = IEEE_802154_SHORT_ADDR_M ) {
DEBUG ( " Packet %p was from % " PRIu16 " to % " PRIu16 " , size: %u \n " , trans_p , * ( ( uint16_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint16_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
else {
DEBUG ( " Packet %p was from %016 " PRIx64 " to % " PRIu16 " , size: %u \n " , trans_p , * ( ( uint64_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint16_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
}
else {
if ( trans_p - > frame . fcf . src_addr_m = = IEEE_802154_SHORT_ADDR_M ) {
DEBUG ( " Packet %p was from % " PRIu16 " to %016 " PRIx64 " , size: %u \n " , trans_p , * ( ( uint16_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint64_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
else {
DEBUG ( " Packet %p was from %016 " PRIx64 " to %016 " PRIx64 " , size: %u \n " , trans_p , * ( ( uint64_t * ) & trans_p - > frame . src_addr [ 0 ] ) , * ( ( uint16_t * ) & trans_p - > frame . dest_addr ) , trans_p - > frame . payload_len ) ;
}
}
# endif
DEBUG ( " Content: %s \n " , trans_p - > frame . payload ) ;
2013-07-12 12:31:16 +02:00
}
# endif
2010-11-26 10:23:46 +01:00
/*------------------------------------------------------------------------------------*/
/*
* @ brief Sends a radio packet to the receiver
*
* @ param t The transceiver device
2014-01-24 16:59:06 +01:00
* @ param pkt Generic pointer to the packet ( use ieee802154_packet_t for
* AT86RF231 , CC2420 , and MC1322X )
2010-11-26 10:23:46 +01:00
*
2013-11-23 14:03:26 +01:00
* @ return A negative value if operation failed , 0 or the number of bytes sent otherwise .
2010-11-26 10:23:46 +01:00
*/
2013-11-23 14:03:26 +01:00
static int8_t send_packet ( transceiver_type_t t , void * pkt )
2013-06-22 05:11:53 +02:00
{
2013-11-23 14:03:26 +01:00
int8_t res = - 1 ;
2014-01-24 16:59:06 +01:00
# if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
ieee802154_packet_t * p = ( ieee802154_packet_t * ) pkt ;
DEBUG ( " transceiver: Send packet to " ) ;
# ifdef DEBUG_ENABLED
for ( size_t i = 0 ; i < 8 ; i + + ) {
printf ( " %02x " , p - > frame . dest_addr [ i ] ) ;
}
printf ( " \n " ) ;
# endif
# else
radio_packet_t * p = ( radio_packet_t * ) pkt ;
DEBUG ( " transceiver: Send packet to % " PRIu16 " \n " , p - > dst ) ;
2014-03-07 15:34:09 +01:00
for ( size_t i = 0 ; i < p - > length ; i + + ) {
DEBUG ( " %02x " , p - > data [ i ] ) ;
}
DEBUG ( " \n " ) ;
2014-01-24 16:59:06 +01:00
# endif
2013-06-22 05:11:53 +02:00
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2010-12-11 12:09:20 +01:00
cc110x_packet_t cc110x_pkt ;
2012-03-01 22:12:25 +01:00
# endif
2013-07-24 23:53:23 +02:00
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
maca_packet_t * maca_pkt = maca_get_free_packet ( ) ;
2013-07-24 23:53:23 +02:00
# endif
2010-11-26 10:23:46 +01:00
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
cc2420_packet_t cc2420_pkt ;
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
at86rf231_packet_t at86rf231_pkt ;
# endif
2010-11-26 10:23:46 +01:00
switch ( t ) {
case TRANSCEIVER_CC1100 :
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2014-01-24 16:59:06 +01:00
cc110x_pkt . length = p - > length + CC1100_HEADER_LENGTH ;
cc110x_pkt . address = p - > dst ;
2010-12-11 12:09:20 +01:00
cc110x_pkt . flags = 0 ;
2014-01-24 16:59:06 +01:00
memcpy ( cc110x_pkt . data , p - > data , p - > length ) ;
2010-12-11 12:09:20 +01:00
res = cc110x_send ( & cc110x_pkt ) ;
2013-05-02 08:45:47 +02:00
# elif MODULE_CC110X
2014-01-24 16:59:06 +01:00
memcpy ( cc1100_pkt , p - > data , p - > length ) ;
2013-06-22 05:11:53 +02:00
2014-01-24 16:59:06 +01:00
res = cc1100_send_csmaca ( p - > dst , 4 , 0 , ( char * ) cc1100_pkt , p - > length ) ;
DEBUG ( " transceiver: snd_ret (%u) = %i \n " , p - > length , snd_ret ) ;
2013-08-10 12:15:51 +02:00
# else
puts ( " Unknown transceiver " ) ;
2012-03-01 22:12:25 +01:00
# endif
2010-11-26 10:23:46 +01:00
break ;
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
case TRANSCEIVER_CC2420 :
2014-01-24 16:59:06 +01:00
memcpy ( & cc2420_pkt . frame , & p - > frame , sizeof ( ieee802154_frame_t ) ) ;
cc2420_pkt . length = p - > frame . payload_len + IEEE_802154_FCS_LEN ;
2013-05-02 08:45:47 +02:00
res = cc2420_send ( & cc2420_pkt ) ;
break ;
2013-07-24 23:22:11 +02:00
# endif
# ifdef MODULE_MC1322X
2014-01-24 16:59:06 +01:00
2013-07-23 15:27:12 +02:00
case TRANSCEIVER_MC1322X :
2014-01-24 16:59:06 +01:00
maca_pkt - > length = p - > length ;
2014-04-18 16:05:23 +02:00
memcpy ( maca_pkt - > data , & p - > frame , p - > length ) ;
2014-01-31 14:36:09 +01:00
maca_set_tx_packet ( maca_pkt ) ;
2013-07-23 15:27:12 +02:00
res = 1 ;
2013-08-10 12:15:51 +02:00
break ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-24 16:59:06 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
2014-01-24 16:59:06 +01:00
res = nativenet_send ( p ) ;
2013-08-08 11:08:33 +02:00
break ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-24 16:59:06 +01:00
2013-07-12 12:31:16 +02:00
case TRANSCEIVER_AT86RF231 :
2014-01-24 16:59:06 +01:00
memcpy ( & at86rf231_pkt . frame , & p - > frame , sizeof ( ieee802154_frame_t ) ) ;
at86rf231_pkt . length = p - > frame . payload_len + IEEE_802154_FCS_LEN ;
2013-07-12 12:31:16 +02:00
res = at86rf231_send ( & at86rf231_pkt ) ;
break ;
2013-05-02 08:45:47 +02:00
# endif
2014-01-31 14:36:09 +01:00
2010-11-26 10:23:46 +01:00
default :
puts ( " Unknown transceiver " ) ;
break ;
}
2013-06-22 05:11:53 +02:00
2010-11-23 11:37:13 +01:00
return res ;
2010-11-19 20:10:09 +01:00
}
2010-11-24 21:45:38 +01:00
2010-11-26 10:23:46 +01:00
/*------------------------------------------------------------------------------------*/
/*
* @ brief Sets the radio channel for any transceiver device
*
* @ param t The transceiver device
* @ param channel The channel to be set
*
* @ return The radio channel AFTER calling the set command , - 1 on error
*/
2014-02-06 02:32:38 +01:00
static int32_t set_channel ( transceiver_type_t t , void * channel )
2013-06-22 05:11:53 +02:00
{
uint8_t c = * ( ( uint8_t * ) channel ) ;
2014-01-31 14:36:09 +01:00
switch ( t ) {
2010-11-24 21:45:38 +01:00
case TRANSCEIVER_CC1100 :
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2010-12-11 12:09:20 +01:00
return cc110x_set_channel ( c ) ;
2013-05-02 08:45:47 +02:00
# elif MODULE_CC110X
2012-03-01 22:12:25 +01:00
return cc1100_set_channel ( c ) ;
2013-08-10 12:15:51 +02:00
# else
return - 1 ;
2012-03-01 22:12:25 +01:00
# endif
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2013-05-02 08:45:47 +02:00
return cc2420_set_channel ( c ) ;
2012-03-01 22:12:25 +01:00
# endif
2013-07-24 23:22:11 +02:00
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_MC1322X :
2013-07-23 15:27:12 +02:00
maca_set_channel ( c ) ;
2014-01-31 14:36:09 +01:00
return c ; ///< TODO: should be changed!implement get channel
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
return nativenet_set_channel ( c ) ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2013-07-12 12:31:16 +02:00
return at86rf231_set_channel ( c ) ;
2012-03-01 22:12:25 +01:00
# endif
2014-01-31 14:36:09 +01:00
2010-11-24 21:45:38 +01:00
default :
return - 1 ;
}
}
2010-11-26 10:23:46 +01:00
/*
* @ brief Get the radio channel of any transceiver device
*
* @ param t The transceiver device
*
* @ return The current radio channel of the transceiver , - 1 on error
*/
2014-02-06 02:32:38 +01:00
static int32_t get_channel ( transceiver_type_t t )
2013-06-22 05:11:53 +02:00
{
2014-01-31 14:36:09 +01:00
switch ( t ) {
2010-11-24 21:45:38 +01:00
case TRANSCEIVER_CC1100 :
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2010-12-11 12:09:20 +01:00
return cc110x_get_channel ( ) ;
2013-05-02 08:45:47 +02:00
# elif MODULE_CC110X
2012-03-01 22:12:25 +01:00
return cc1100_get_channel ( ) ;
2013-08-10 12:15:51 +02:00
# else
return - 1 ;
2012-03-01 22:12:25 +01:00
# endif
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2013-05-02 08:45:47 +02:00
return cc2420_get_channel ( ) ;
# endif
2013-08-08 11:08:33 +02:00
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
2013-07-23 15:27:12 +02:00
case TRANSCEIVER_MC1322X :
2014-02-11 18:15:43 +01:00
///< TODO:implement return maca_get_channel();
2014-02-07 18:23:02 +01:00
return - 1 ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
return nativenet_get_channel ( ) ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2013-07-12 12:31:16 +02:00
return at86rf231_get_channel ( ) ;
2013-08-08 11:08:33 +02:00
# endif
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
default :
return - 1 ;
}
}
/*------------------------------------------------------------------------------------*/
/*
2014-05-27 15:57:28 +02:00
* @ brief Sets the PAN for any transceiver device
2013-05-02 08:45:47 +02:00
*
* @ param t The transceiver device
2014-05-27 15:57:28 +02:00
* @ param pan The PAN to be set
2013-05-02 08:45:47 +02:00
*
2014-05-27 15:57:28 +02:00
* @ return The PAN AFTER calling the set command , - 1 on error
2013-05-02 08:45:47 +02:00
*/
2014-01-31 14:36:09 +01:00
static int32_t set_pan ( transceiver_type_t t , void * pan )
{
uint16_t c = * ( ( uint16_t * ) pan ) ;
2013-05-02 08:45:47 +02:00
switch ( t ) {
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2013-05-02 08:45:47 +02:00
return cc2420_set_pan ( c ) ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
return nativenet_set_pan ( c ) ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2013-07-12 12:31:16 +02:00
return at86rf231_set_pan ( c ) ;
2013-10-04 13:11:31 +02:00
# endif
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
2013-10-04 13:11:31 +02:00
case TRANSCEIVER_MC1322X :
return maca_set_pan ( c ) ;
2013-05-02 08:45:47 +02:00
# endif
2014-01-31 14:36:09 +01:00
2013-05-02 08:45:47 +02:00
default :
2013-06-25 15:33:40 +02:00
/* get rid of compiler warning about unused variable */
( void ) c ;
2013-05-02 08:45:47 +02:00
return - 1 ;
}
}
2013-06-22 05:11:53 +02:00
2013-05-02 08:45:47 +02:00
/*
2014-05-27 15:57:28 +02:00
* @ brief Get the pan of any transceiver device
2013-05-02 08:45:47 +02:00
*
* @ param t The transceiver device
*
* @ return The current pan of the transceiver , - 1 on error
*/
2014-01-31 14:36:09 +01:00
static int32_t get_pan ( transceiver_type_t t )
{
2013-05-02 08:45:47 +02:00
switch ( t ) {
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2013-05-02 08:45:47 +02:00
return cc2420_get_pan ( ) ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
return nativenet_get_pan ( ) ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2013-07-12 12:31:16 +02:00
return at86rf231_get_pan ( ) ;
2013-10-04 13:11:31 +02:00
# endif
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
2013-10-04 13:11:31 +02:00
case TRANSCEIVER_MC1322X :
return maca_get_pan ( ) ;
2012-03-01 22:12:25 +01:00
# endif
2014-01-31 14:36:09 +01:00
2010-11-24 21:45:38 +01:00
default :
return - 1 ;
}
}
2010-11-26 10:23:46 +01:00
/*------------------------------------------------------------------------------------*/
/*
* @ brief Get the current address of transceiver device
*
2013-08-10 12:15:51 +02:00
* @ param t The transceiver device
2010-11-26 10:23:46 +01:00
*
2014-01-31 09:55:24 +01:00
* @ return The configured address of the device
*
* TODO : define error behavior
2010-11-26 10:23:46 +01:00
*/
2014-01-31 09:55:24 +01:00
static radio_address_t get_address ( transceiver_type_t t )
2013-06-22 05:11:53 +02:00
{
2014-01-31 14:36:09 +01:00
switch ( t ) {
2010-11-26 10:23:46 +01:00
case TRANSCEIVER_CC1100 :
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2010-12-11 12:09:20 +01:00
return cc110x_get_address ( ) ;
2013-05-02 08:45:47 +02:00
# elif MODULE_CC110X
2012-03-01 22:12:25 +01:00
return cc1100_get_address ( ) ;
2013-08-10 12:15:51 +02:00
# else
2014-01-31 09:55:24 +01:00
return 0 ; /* XXX see TODO above */
2012-03-01 22:12:25 +01:00
# endif
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2013-05-02 08:45:47 +02:00
return cc2420_get_address ( ) ;
2013-07-24 23:22:11 +02:00
# endif
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
2013-07-23 15:27:12 +02:00
case TRANSCEIVER_MC1322X :
return maca_get_address ( ) ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
return nativenet_get_address ( ) ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2013-07-12 12:31:16 +02:00
return at86rf231_get_address ( ) ;
2012-03-01 22:12:25 +01:00
# endif
2014-01-31 14:36:09 +01:00
2010-11-26 10:23:46 +01:00
default :
2014-01-31 09:55:24 +01:00
return 0 ; /* XXX see TODO above */
2010-11-26 10:23:46 +01:00
}
}
/*
* @ brief Set the address of the transceiver device
*
* @ param t The transceiver device
* @ param address Generic pointer to the address to set
*
* @ return The new radio address of the device
2014-01-31 09:55:24 +01:00
*
* TODO : define error behavior
2010-11-26 10:23:46 +01:00
*/
2014-01-31 09:55:24 +01:00
static radio_address_t set_address ( transceiver_type_t t , void * address )
2013-06-22 05:11:53 +02:00
{
radio_address_t addr = * ( ( radio_address_t * ) address ) ;
2014-01-31 14:36:09 +01:00
switch ( t ) {
2010-11-26 10:23:46 +01:00
case TRANSCEIVER_CC1100 :
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2010-12-11 12:09:20 +01:00
return cc110x_set_address ( addr ) ;
2013-05-02 08:45:47 +02:00
# elif MODULE_CC110X
2012-03-01 22:12:25 +01:00
return cc1100_set_address ( addr ) ;
2013-08-10 12:15:51 +02:00
# else
2014-01-31 09:55:24 +01:00
return 0 ; /* XXX see TODO above */
2012-03-01 22:12:25 +01:00
# endif
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2013-05-02 08:45:47 +02:00
return cc2420_set_address ( addr ) ;
2013-07-24 23:22:11 +02:00
# endif
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
2013-07-23 15:27:12 +02:00
case TRANSCEIVER_MC1322X :
return maca_set_address ( addr ) ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
return nativenet_set_address ( addr ) ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2013-07-12 12:31:16 +02:00
return at86rf231_set_address ( addr ) ;
2012-03-01 22:12:25 +01:00
# endif
2014-01-31 14:36:09 +01:00
2010-11-26 10:23:46 +01:00
default :
2014-01-31 09:55:24 +01:00
return 0 ; /* XXX see TODO above */
2010-11-26 10:23:46 +01:00
}
}
2010-11-27 10:50:18 +01:00
2014-01-21 17:08:27 +01:00
/*
* @ brief Get the current long address of transceiver device
*
* @ param t The transceiver device
*
* @ return The configured long address of the device , 0 on error
*/
static transceiver_eui64_t get_long_addr ( transceiver_type_t t )
{
switch ( t ) {
# ifdef MODULE_CC2420
case TRANSCEIVER_CC2420 :
return cc2420_get_address_long ( ) ;
# endif
# ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231 :
return at86rf231_get_address_long ( ) ;
# endif
default :
return 0 ;
}
}
/*
* @ brief Set the long address of the transceiver device
*
* @ param t The transceiver device
* @ param address Generic pointer to the long address to set
*
* @ return The new long radio address of the device , 0 on error
*/
static transceiver_eui64_t set_long_addr ( transceiver_type_t t , void * address )
{
uint64_t addr = * ( ( uint64_t * ) address ) ;
switch ( t ) {
# ifdef MODULE_CC2420
case TRANSCEIVER_CC2420 :
return cc2420_set_address_long ( addr ) ;
# endif
# ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231 :
return at86rf231_set_address_long ( addr ) ;
# endif
default :
( void ) addr ;
return 0 ;
}
}
2010-11-27 10:50:18 +01:00
/*
* @ brief Set the transceiver device into monitor mode ( disabling address check )
*
* @ param t The transceiver device
* @ param mode 1 for enabling monitor mode , 0 for enabling address check
*/
2013-06-22 05:11:53 +02:00
static void set_monitor ( transceiver_type_t t , void * mode )
{
2013-11-21 14:18:54 +01:00
( void ) mode ;
2014-01-31 14:36:09 +01:00
switch ( t ) {
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC1100 :
2013-06-22 05:11:53 +02:00
cc110x_set_monitor ( * ( ( uint8_t * ) mode ) ) ;
2010-11-27 10:50:18 +01:00
break ;
2013-08-13 18:12:04 +02:00
# endif
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2014-01-31 14:36:09 +01:00
cc2420_set_monitor ( * ( ( uint8_t * ) mode ) ) ;
2010-11-27 10:50:18 +01:00
break ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
2014-01-31 14:36:09 +01:00
nativenet_set_monitor ( * ( ( uint8_t * ) mode ) ) ;
2013-08-08 11:08:33 +02:00
break ;
2013-07-12 12:31:16 +02:00
# endif
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2014-01-31 14:36:09 +01:00
at86rf231_set_monitor ( * ( ( uint8_t * ) mode ) ) ;
2013-08-13 18:12:04 +02:00
# endif
2014-01-31 14:36:09 +01:00
2010-11-27 10:50:18 +01:00
default :
break ;
}
}
2013-08-10 12:15:51 +02:00
# ifdef MODULE_CC110X
void cc1100_packet_monitor ( void * payload , int payload_size , protocol_t protocol , packet_info_t * packet_info )
{
2013-11-21 14:18:54 +01:00
( void ) protocol ;
2013-08-10 12:15:51 +02:00
cc1100_payload = payload ;
cc1100_payload_size = payload_size - 3 ;
cc1100_packet_info = packet_info ;
receive_packet ( TRANSCEIVER_CC1100 , 0 ) ;
}
# endif
2010-12-02 15:38:28 +01:00
/*------------------------------------------------------------------------------------*/
2013-06-22 05:11:53 +02:00
static void powerdown ( transceiver_type_t t )
{
2014-01-31 14:36:09 +01:00
switch ( t ) {
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC1100 :
2010-12-11 12:09:20 +01:00
cc110x_switch_to_pwd ( ) ;
2010-12-02 15:38:28 +01:00
break ;
2013-08-13 18:12:04 +02:00
# endif
2013-07-24 23:22:11 +02:00
# ifdef MODULE_MC1322X
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_MC1322X :
2013-07-23 15:27:12 +02:00
maca_off ( ) ;
break ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
nativenet_powerdown ( ) ;
break ;
2013-08-13 18:12:04 +02:00
# endif
2014-01-31 14:36:09 +01:00
2010-12-02 15:38:28 +01:00
default :
break ;
}
}
/*------------------------------------------------------------------------------------*/
2013-06-22 05:11:53 +02:00
static void switch_to_rx ( transceiver_type_t t )
{
2014-01-31 14:36:09 +01:00
switch ( t ) {
2012-03-01 22:12:25 +01:00
# ifdef MODULE_CC110X_NG
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC1100 :
2010-12-11 12:09:20 +01:00
cc110x_switch_to_rx ( ) ;
2010-12-02 15:38:28 +01:00
break ;
2013-08-13 18:12:04 +02:00
# endif
2013-05-02 08:45:47 +02:00
# ifdef MODULE_CC2420
2014-01-31 14:36:09 +01:00
2013-08-10 12:15:51 +02:00
case TRANSCEIVER_CC2420 :
2013-08-15 19:07:14 +02:00
2013-05-02 08:45:47 +02:00
cc2420_switch_to_rx ( ) ;
2010-12-02 15:38:28 +01:00
break ;
2013-08-08 11:08:33 +02:00
# endif
# ifdef MODULE_NATIVENET
2014-01-31 14:36:09 +01:00
2013-08-08 11:08:33 +02:00
case TRANSCEIVER_NATIVE :
nativenet_switch_to_rx ( ) ;
break ;
2013-08-15 19:07:14 +02:00
# endif
2013-07-12 12:31:16 +02:00
# ifdef MODULE_AT86RF231
2014-01-31 14:36:09 +01:00
2013-08-15 19:07:14 +02:00
case TRANSCEIVER_AT86RF231 :
2013-07-12 12:31:16 +02:00
at86rf231_switch_to_rx ( ) ;
2013-08-13 18:12:04 +02:00
# endif
2014-01-31 14:36:09 +01:00
2010-12-02 15:38:28 +01:00
default :
break ;
}
}
2012-02-08 17:14:50 +01:00
# ifdef DBG_IGNORE
2014-02-15 12:58:55 +01:00
static int16_t ignore_add ( transceiver_type_t transceiver , void * address )
2013-06-22 05:11:53 +02:00
{
2014-02-15 12:58:55 +01:00
( void ) transceiver ;
2013-06-22 05:11:53 +02:00
radio_address_t addr = * ( ( radio_address_t * ) address ) ;
2013-11-19 23:45:03 +01:00
for ( uint8_t i = 0 ; i < MAX_IGNORED_ADDR ; i + + ) {
if ( ignored_addr [ i ] = = 0 ) {
ignored_addr [ i ] = addr ;
DEBUG ( " addr %u will be ignored (%u) \n " , addr , i ) ;
return i ;
}
2012-02-08 17:14:50 +01:00
}
2014-01-31 14:36:09 +01:00
2013-11-19 23:45:03 +01:00
return - 1 ;
2012-02-08 17:14:50 +01:00
}
# endif