wpan.h File Reference

Wireless Personal Area Network routines. More...

Include dependency graph for wpan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  wpan_address

Defines

#define FRAME_TYPE_ACK   0b010
#define FRAME_TYPE_BEACON   0b000
#define FRAME_TYPE_DATA   0b001
#define FRAME_TYPE_MAC_COMMAND   0b011
#define MAC_CMD_ASSOC_REQ   0x01
#define MAC_CMD_ASSOC_RES   0x02
#define MAC_CMD_BEACON_REQ   0x07
#define MAC_CMD_COORD_REALIGN   0x08
#define MAC_CMD_DATA_REQ   0x04
#define MAC_CMD_DISASSOC   0x03
#define MAC_CMD_GTS_REQ   0x09
#define MAC_CMD_ORPHAN   0x06
#define MAC_CMD_PAN_ID_CONFLICT   0x05
#define WPAN_ADDR_TYPE_EXTENDED   0b00000011
#define WPAN_ADDR_TYPE_NONE   0b00000000
#define WPAN_ADDR_TYPE_SHORT   0b00000010

Functions

void wpan_data_received_callback (wpan_address *addr, uns8 *data, uns8 data_size, uns8 lqi, uns8 rssi)
 Callback for data received.
void wpan_data_transmitted_callback (uns8 status, uns8 retries, uns8 channel_busy)
 Callback for data transmitted.
void wpan_handle_receive ()
 Handle reception of packet.
void wpan_init ()
 Initialise this and lower layers ready for use.
void wpan_print_address (wpan_address *addr)
 Print the address of the packet.
void wpan_print_frame_type (uns8 frame_type)
 Print information about the WPAN frame type.
void wpan_print_mac_command (uns8 *data)
 Debug routine that prints out the mac command type.
void wpan_process ()
 Process WPAN layer.
void wpan_setup_io ()
 Setup IO as requred.

Variables

uns8 pkt_received

Detailed Description

Put this in your config.h

// ------------------------
// WPAN (802.15.4) wireless
// ------------------------

#define WPAN_USE_MRF24J50
// ------------------------

Define Documentation

#define FRAME_TYPE_ACK   0b010
#define FRAME_TYPE_BEACON   0b000
#define FRAME_TYPE_DATA   0b001
#define FRAME_TYPE_MAC_COMMAND   0b011
#define MAC_CMD_ASSOC_REQ   0x01
#define MAC_CMD_ASSOC_RES   0x02
#define MAC_CMD_BEACON_REQ   0x07
#define MAC_CMD_COORD_REALIGN   0x08
#define MAC_CMD_DATA_REQ   0x04
#define MAC_CMD_DISASSOC   0x03
#define MAC_CMD_GTS_REQ   0x09
#define MAC_CMD_ORPHAN   0x06
#define MAC_CMD_PAN_ID_CONFLICT   0x05
#define WPAN_ADDR_TYPE_EXTENDED   0b00000011
#define WPAN_ADDR_TYPE_NONE   0b00000000
#define WPAN_ADDR_TYPE_SHORT   0b00000010

Function Documentation

void wpan_data_received_callback ( wpan_address addr,
uns8 *  data,
uns8  data_size,
uns8  lqi,
uns8  rssi 
)

After the packet has been processed and the address extracted, it is delivered to the callback function.

void wpan_data_transmitted_callback ( uns8  status,
uns8  retries,
uns8  channel_busy 
)

Once the lower layers have attempted to transmit the packet, the results will be presented to the callback.

Parameters:
status Set to 0 for success or 1 for failure
retries Set to the number of retries
channel_busy Set to 1 if failure was due to the channel being busy.

00804                                                                                   {
00805     its2_transmitting = 0;
00806 }

Here is the caller graph for this function:

void wpan_handle_receive (  ) 

Internal routine for WPAN layer to handle the reception of a packet.

00225                            {
00226 
00227 wpan_address addr;
00228 
00229 uns8 temp;
00230 uns8 count;
00231 uns8 frame_type;
00232 uns8 buffer_pos;
00233 
00234 
00235     // destination address
00236     addr.dest_address_type = wpan_rx_buffer[1] >> 6;    // fc lsb dest address type
00237     
00238     buffer_pos = 0;
00239     
00240     switch (addr.dest_address_type) {
00241         case WPAN_ADDR_TYPE_EXTENDED: // extended address
00242     
00243             // get dest pan
00244             addr.dest_pan_id = wpan_rx_buffer[4];   // msb
00245             addr.dest_pan_id <<= 8;
00246             addr.dest_pan_id += wpan_rx_buffer[3];  // lsb
00247             // get extended address
00248             for (count = 0; count < 8; count++) {
00249                 addr.dest_ea[count] = wpan_rx_buffer[5+count];
00250             }
00251             // might be faster to unwind this loop...
00252             buffer_pos = 13;
00253             break;
00254         case WPAN_ADDR_TYPE_SHORT: // short address
00255             // get dest pan
00256             addr.dest_pan_id = wpan_rx_buffer[4];   // msb
00257             addr.dest_pan_id <<= 8;
00258             addr.dest_pan_id += wpan_rx_buffer[3];  // lsb
00259             // get short address
00260             addr.dest_sa = wpan_rx_buffer[6];   // msb
00261             addr.dest_sa <<= 8;
00262             addr.dest_sa += wpan_rx_buffer[5];  // lsb
00263             buffer_pos = 7;
00264             break;
00265         case WPAN_ADDR_TYPE_NONE: // no address
00266             buffer_pos = 3;
00267             break;
00268     }
00269     
00270     // source address
00271     
00272     addr.source_address_type = (wpan_rx_buffer[1] >> 2) & 0b00000011;   // fc lsb src address type
00273     
00274     switch (addr.source_address_type) {
00275         case WPAN_ADDR_TYPE_EXTENDED: // extended address
00276             // get source pan
00277             if (test_bit(wpan_rx_buffer[0], 6)) {   // pan id compression
00278                 addr.source_pan_id = addr.dest_pan_id;
00279             } else {    
00280                 addr.source_pan_id = wpan_rx_buffer[buffer_pos+1];  // msb
00281                 addr.source_pan_id <<= 8;
00282                 addr.source_pan_id += wpan_rx_buffer[buffer_pos];   // lsb
00283                 buffer_pos += 2;
00284             }   
00285             // get extended address
00286             for (count = 0; count < 8; count++) {
00287                 addr.source_ea[count] = wpan_rx_buffer[buffer_pos++];
00288             }
00289 
00290             break;
00291         case WPAN_ADDR_TYPE_SHORT: // short address
00292             if (test_bit(wpan_rx_buffer[0], 6)) {   // pan id compression
00293                 addr.source_pan_id = addr.dest_pan_id;
00294             } else {    
00295                 // get pan
00296                 addr.source_pan_id = wpan_rx_buffer[buffer_pos+1];  // msb
00297                 addr.source_pan_id <<= 8;
00298                 addr.source_pan_id += wpan_rx_buffer[buffer_pos];   // lsb
00299                 buffer_pos += 2;
00300             }   
00301             // get short address
00302             addr.source_sa = wpan_rx_buffer[buffer_pos+1];  // msb
00303             addr.source_sa <<= 8;
00304             addr.source_sa += wpan_rx_buffer[buffer_pos];   // lsb
00305             buffer_pos += 2;
00306             break;
00307         case WPAN_ADDR_TYPE_NONE: // no address
00308             break;
00309     }
00310     //debug_var(" buffer pos = ", buffer_pos);
00311     //debug_var(" wpan_rx_count = ", wpan_rx_count);
00312     // data should be at buffer_pos
00313     frame_type = wpan_rx_buffer[0] & 0b00000111;    // frame type
00314     switch(frame_type) {
00315         case FRAME_TYPE_MAC_COMMAND:
00316             //wpan_handle_mac_command(&addr, &wpan_rx_buffer[buffer_pos], wpan_rx_count - buffer_pos);
00317             break;
00318         case FRAME_TYPE_BEACON:
00319             //wpan_handle_beacon(&addr, &wpan_rx_buffer[buffer_pos], wpan_rx_count - buffer_pos);
00320             break;
00321         case FRAME_TYPE_DATA:
00322             wpan_data_received_callback(&addr, &wpan_rx_buffer[buffer_pos], wpan_rx_count - buffer_pos - 4, 
00323                                         /* lqi */ wpan_rx_buffer[wpan_rx_count-2], /* rssi */ wpan_rx_buffer[wpan_rx_count-1]);
00324             break;
00325         // We'll never see an ACK frame, that should be handled by the MRF
00326     }                          
00327                                
00328     pkt_received = 0;
00329 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wpan_init (  ) 

Initialise underlying hardware (typically mrf24j40)

00336                  {
00337     
00338     mrf24j40_init();
00339     
00340 }       

Here is the call graph for this function:

Here is the caller graph for this function:

void wpan_print_address ( wpan_address addr  ) 

Print out the source and destination address

00096                                             {
00097     
00098 uns8 count;
00099 
00100     debug_str("\nPKT:\nSrc ");
00101     if (addr->source_address_type) { // ie, not 0
00102         serial_print_str(" PAN: ");
00103         serial_print_int_hex_16bit(addr->source_pan_id);
00104         
00105         switch (addr->source_address_type) {
00106             case WPAN_ADDR_TYPE_EXTENDED:
00107                 serial_print_str(" EA: ");
00108                 for (count = 7; count != 255; count--) {
00109                     serial_print_int_hex(addr->source_ea[count]);
00110                     serial_putc(' ');
00111                 }
00112                 break;
00113             case WPAN_ADDR_TYPE_SHORT:
00114                 serial_print_str(" SA: ");
00115                 serial_print_int_hex_16bit(addr->source_sa);
00116                 serial_putc(' ');
00117                 break;
00118         }           
00119     } else {
00120         serial_print_str(" (blank) ");
00121     }
00122     
00123     serial_print_str(" Dest ");
00124     
00125     if (addr->dest_address_type) { // ie, not 0
00126         serial_print_str(" PAN: ");
00127         serial_print_int_hex_16bit(addr->dest_pan_id);
00128         
00129         switch (addr->dest_address_type) {
00130             case WPAN_ADDR_TYPE_EXTENDED:
00131                 serial_print_str(" EA: ");
00132                 for (count = 7; count != 255; count--) {
00133                     serial_print_int_hex(addr->dest_ea[count]);
00134                     serial_putc(' ');
00135                 }
00136                 break;
00137             case WPAN_ADDR_TYPE_SHORT:
00138                 serial_print_str(" SA: ");
00139                 serial_print_int_hex_16bit(addr->dest_sa);
00140                 serial_putc(' ');
00141                 break;
00142         }       
00143     } else {
00144         serial_print_str(" (blank) ");
00145     }
00146 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wpan_print_frame_type ( uns8  frame_type  ) 

00148                                             {
00149 
00150     switch(frame_type) {
00151         case FRAME_TYPE_BEACON:
00152             serial_print_str(" Beacon ");
00153             break;
00154         case FRAME_TYPE_DATA:
00155             serial_print_str(" Data ");
00156             break;
00157         case FRAME_TYPE_ACK:
00158             serial_print_str(" Ack ");
00159             break;
00160         case FRAME_TYPE_MAC_COMMAND:
00161             serial_print_str(" Mac ");
00162             break;
00163     }
00164 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wpan_print_mac_command ( uns8 *  data  ) 

Print the MAC layer command details

00166                                         {
00167 
00168 uns8 mac_command = data[0]; // Uses less flash this way
00169 
00170     switch (data[0]) {
00171         
00172         case MAC_CMD_ASSOC_REQ:
00173             serial_print_str("ASSOC REQ (Capability: ");
00174             serial_print_int_hex(data[1]);
00175             serial_putc(')');
00176             break;
00177         case MAC_CMD_ASSOC_RES:
00178             serial_print_str("ASSOC RES (Short addr: ");
00179             serial_print_int_hex(data[2]);  // msb
00180             serial_print_int_hex(data[1]);  // lsb
00181             serial_print_str(" Status: ");
00182             serial_print_int_hex(data[3]);
00183             serial_putc(')');
00184             break;
00185         case MAC_CMD_DISASSOC:
00186             serial_print_str("DISASSOC (Reason: ");
00187             serial_print_int_hex(data[1]);
00188             serial_putc(')');
00189             break;
00190         case MAC_CMD_DATA_REQ:
00191             serial_print_str("DATA REQ");
00192             break;
00193         case MAC_CMD_PAN_ID_CONFLICT:
00194             serial_print_str("PAN ID CONFLICT");
00195             break;
00196         case MAC_CMD_ORPHAN:
00197             serial_print_str("ORPHAN");
00198             break;
00199         case MAC_CMD_BEACON_REQ:
00200             serial_print_str("BEACON REQ");
00201             break;
00202         case MAC_CMD_COORD_REALIGN:
00203             serial_print_str("COORD REALIGN (data TBD)");
00204             break;
00205         case MAC_CMD_GTS_REQ:
00206             serial_print_str("GTS REQ (Char: ");
00207             serial_print_int_hex(data[1]);
00208             serial_putc(')');
00209             break;
00210     }       
00211 }   

Here is the call graph for this function:

void wpan_process (  ) 

Call wpan_process() regularly to handle events at the WPAN layer. Typically this includes handling any received packets, processing them, and handing up to a higher layer.

00214                     {
00215     
00216     if (pkt_received) {
00217         wpan_handle_receive();
00218     }
00219 }

Here is the call graph for this function:

void wpan_setup_io (  ) 

Set up ports and pins for WPAN use

00332                      {
00333     mrf24j40_setup_io();
00334 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation


Generated on Fri Aug 19 09:09:54 2011 for Pic Pack Library by  doxygen 1.6.1