rtsctsMac.c File Reference

RTS/CTS MAC. More...

#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include "xparameters.h"
#include "xutil.h"
#include "ofdm_pktdetector_mimo_regMacros.h"
#include "warp_timer_regMacros.h"
#include "ofdm_txrx_mimo_regMacros.h"
#include "warpmac.h"
#include "warpphy.h"
#include "rtsctsMac.h"
#include "rtsctsTest.h"
#include "ascii_characters.h"

Go to the source code of this file.

Enumerations

enum  
 MAC/NAV states.
enum  
 packet types and MAC states
enum  
 packet counter array indices

Functions

void unlockRXantenna ()
 enables antenna selection diversity after setting SISO antenna to A (to ensure that transmissions are initiated from antenna A)
void lockRXantenna ()
 locks onto the last selected antenna disables antenna selection diversity and checks the gains assigned by the AGC to determine which antenna to use
void loadCSI (unsigned char *newCSI)
 test function for loading CSI into CTS packet buffer 3 this will eventually be done by the PHY
void updateTimer (unsigned char type, unsigned int newTime)
 timer management function Handles setting and updating the timers
int rtsmac_timer_callback (unsigned char unused)
 Callback for the expiration of timers.
void dropPacket ()
 Drops the ethernet packet waiting to be sent Reenables ethernet reception.
int rtsmac_emacRx_callback (Xuint32 length, char *payload)
 Callback for the reception of Ethernet packets This function is called by the ethernet MAC drivers when a packet is available to send. If the packet is addressed to a specific IP address, this function translates that IP address into a MAC address using the routeTable, completes the headers of the RTS and data packets, and calls initTX. If the packet is to be broadcast, sendBCD is called.
void initTX ()
 Initiate a packet exchange sequence The sequence begins with an RTS if the data packet length exceeds the RTS/CTS threshold or with the data packet if not. The packet is dropped if the maximum resend count has been reached. If a carrier is sensed, a backoff timer is set. Once the timer ends, the communication will be retried. After sending a packet, this function sets a timeout for receiving the response.
void sendCTS (Macframe *packet)
 Send Clear To Send packet over the PHY checks NAV state to determine whether channel is reserved Channel state information should be in TxBuffer 3.
void sendDAT ()
 Send a data packet over the PHY.
void sendBCD ()
 Broadcast a data packet Verifies that the channel is not reserved or busy before transmitting.
int rtsmac_phyRx_badHeader_callback ()
 Callback for the reception of bad wireless packets.
int rtsmac_phyRx_goodHeader_callback (Macframe *packet)
 Callback for the reception of good wireless packet headers This interrupt service routine is called when a packet header is detected, allowing a reduction in the turn-around time of the response packet. This is accomplished by completing the response packet header and loading it into the PHY before the rest of the incoming packet is received, letting us send the response as soon as possible.
int main ()
 Main function.
void initFeedback ()
 Set up RTS/CTS MAC to send per subcarrier antenna selection feedback. Feedback is sent in the CTS packet payload and is used only in transmitting data packets.
void initDelays ()
 Define transmit, inter-frame, and timeout times.
void initAddresses ()
 Set up addresses and routing table.
void initHeaders ()
 Set up headers for each packet type.
void rtsmac_left ()
 Left push-button handler decrease transmitter gain.
void rtsmac_middle ()
 Middle push-button handler print state variables.
void rtsmac_right ()
 Right push-button handler increase transmitter gain.
void rtsmac_up ()
 Up push-button handler toggle between RTS/CTS and ordinary CSMA/CA by moving the rtsThreshold.
void printState ()
 display status of the node
void clearPktCtr ()
 clear packet counter arrays
void printStatistics ()
 display packet counts TX - transmitted packets RX_good - received good packet RX_unexp - good packet received when a different type of packet was expected RX_bad - received bad packet

Variables

struct {
   Macframe   rx
 received packet
   Macframe   rts
 Request To Send.
   Macframe   cts
 Clear To Send.
   Macframe   dat
 DATa.
   Macframe   ack
 ACKnowledgement.
   Macframe   bcd
 BroadCast Data.
pkt
 packet headers
struct {
   unsigned short   slot
 backoff time increments
   unsigned short   SIFS
 time between adjacent symbols within a packet exchange sequence, used only for timer calculations
   unsigned short   DIFS
 time the channel must be idle to begin a packet exchange
   unsigned short   EIFS
 time the channel must be idle to begin a packet exchange after receiving a bad packet
   unsigned short   header
 header transmission time
   unsigned short   transmit [5]
 transmission times for each of the packet types (not all are used)
   unsigned short   timeout [5]
 timeouts for receiving each of the packet types (not all are used)
delay
 inter-frame delays, packet transmission times, and packet timeouts
unsigned int pktCtr [4][7]
 packet counters
struct {
   unsigned char   antA [8]
 set all subcarriers to antenna A
   unsigned char   antB [8]
 set all subcarriers to antenna B
   unsigned char   half [8]
 enable the first half of subcarriers on A and last half on B
   unsigned char   otherhalf [8]
 enable the first half of subcarriers on B and last half on A
   unsigned char   alternating [8]
 enable odd subcarriers on A, even on B
   unsigned char *   current
 pointer to currently used csi
csi
 channel state information
const unsigned char modMasks [64]
 modulation masks for each subcarrier
const unsigned char modFlags [64]
 flags indicating which subcarriers are used for data
struct {
   unsigned short   rtsThreshold
 packets with payload shorter than rtsThreshold are sent without RTS/CTS handshake
   unsigned char   feedback_en
 enable sending of CSI in the CTS packet
   unsigned char   mac
 MAC state; idle or indicates the type of packet that we expect to receive.
   unsigned char   chan
 wireless channel number (1-14)
   unsigned char   currentAnt
 current antenna; 0 - antenna A, 1 - antenna B
   unsigned char   myID
 index to the routing table that identifies this node
   unsigned char   GPIOval
 state of the general purpose IO pins (for debugging)
   const unsigned char   baseRate
 modulation for base rate symbols
   const unsigned char   fullRate
 modulation for full rate symbols
   const unsigned char   csiLength
 number of bits of CSI
   struct {
      unsigned short   rts
 RTS packet resend limit.
      unsigned short   dat
 data packet resend limit
   }   maxResend
 resend limits
   struct {
      unsigned char   my [6]
 MAC address of this node.
      const unsigned char   bc [6]
 broadcast MAC address
      const unsigned char   net [4]
 network IP address
   }   addr
 addresses
   struct {
      unsigned char   addr [6]
   }   routeTable [16]
 Routing table with agreed-upon mapping between dip-switches and physical addresses.
state
 struct for RTS/CTS MAC state variables


Detailed Description

RTS/CTS MAC.

Author:
Keith Wilhelm
The RTS/CTS MAC is a modified CSMA MAC that implements the RTS/CTS exchange protocol on the WARP platform. When a node receives a packet over its ethernet link addressed to another node in the network, it first sends an RTS (Request to Send) to that node. The node to which this RTS was addressed then replies with a CTS (Clear To Send) if it is ready to receive data. Upon receiving the CTS, the original node begins transmitting its data across the PHY. Once the data packet is received by the other node, it replies with an ACK packet. If there is a failure at any point in the exchange, it must be restarted from the beginning. The rtsThreshold can be used to disable the RTS/CTS exchange for packets shorter than the threshold, sending the data packet directly instead.

The RTS/CTS MAC is able to look at IP addresses in the ethernet packets that it receives and address those packets to a corresponding MAC address. Ethernet packets that are sent to broadcast addresses or that are unrecognized are sent directly over the PHY with no RTS, CTS, or ACK.

The RTS, CTS, and data packets carry information about how long the current exchange will take to finish, so that other nodes hearing any of those packets can defer until the end of the exchange, preventing them from interfering with the exchange. This is accomplished by setting a network allocation vector (NAV) timer.

Setup: The each node must have an IP address whose first three bytes match the net address (state.addr.net) and last byte matches the node ID (setting of the dip switches). (Since the last number of the IP address cannot be 0, the node ID cannot be 0 either). Each node's mac address must also match the routeTable entry corresponding to its node ID (routeTable[myID].addr[]).

Definition in file rtsctsMac.c.


Function Documentation

void loadCSI ( unsigned char *  newCSI  ) 

test function for loading CSI into CTS packet buffer 3 this will eventually be done by the PHY

Parameters:
newCSI Pointer to array of channel state information

Definition at line 311 of file rtsctsMac.c.

References controlStruct, NUM_HEADER_BYTES, state, and warpphy_getBuffAddr.

Referenced by sendCTS().

int main (  ) 

Main function.

This function configures MAC parameters, enables the underlying frameworks, and then loops forever.

Definition at line 703 of file rtsctsMac.c.

References BACKOFF, clearPktCtr(), csi, GHZ_2, initAddresses(), initDelays(), initHeaders(), NAV, pkt, rtsmac_emacRx_callback(), rtsmac_left(), rtsmac_middle(), rtsmac_phyRx_badHeader_callback(), rtsmac_phyRx_goodHeader_callback(), rtsmac_right(), rtsmac_timer_callback(), rtsmac_up(), state, TIMEOUT, warp_timer_setMode(), warpmac_enableCSMA(), warpmac_enableEthernet(), warpmac_init(), warpmac_leftHex(), warpmac_pollEthernet(), warpmac_setBadHeaderCallback(), warpmac_setBaseRate(), warpmac_setEmacCallback(), warpmac_setGoodHeaderCallback(), warpmac_setLeftButtonCallback(), warpmac_setMiddleButtonCallback(), warpmac_setRightButtonCallback(), warpmac_setRxBuffer(), warpmac_setTimerCallback(), warpmac_setTxBuffer(), warpmac_setUpButtonCallback(), and warpphy_setChannel().

int rtsmac_emacRx_callback ( Xuint32  length,
char *  payload 
)

Callback for the reception of Ethernet packets This function is called by the ethernet MAC drivers when a packet is available to send. If the packet is addressed to a specific IP address, this function translates that IP address into a MAC address using the routeTable, completes the headers of the RTS and data packets, and calls initTX. If the packet is to be broadcast, sendBCD is called.

Parameters:
length Length, in bytes, of received Ethernet frame
payload Pointer to Ethernet payload.

Definition at line 423 of file rtsctsMac.c.

References delay, initTX(), pkt, pktCtr, sendBCD(), state, UTime::uint16, UTime::uint8, warpmac_disableEthernet(), and warpmac_prepPhyForXmit().

Referenced by main().

int rtsmac_phyRx_goodHeader_callback ( Macframe packet  ) 

Callback for the reception of good wireless packet headers This interrupt service routine is called when a packet header is detected, allowing a reduction in the turn-around time of the response packet. This is accomplished by completing the response packet header and loading it into the PHY before the rest of the incoming packet is received, letting us send the response as soon as possible.

Parameters:
packet Pointer to received header

Definition at line 600 of file rtsctsMac.c.

References BACKOFF, BADPACKET, controlStruct, Maccontrol::currBackoff, GOODPACKET, Macframe::header, INCOMPLETE, NAV, pkt, pktCtr, phyHeader::pktType, phyHeader::reserved1, phyHeader::reserved2, phyHeader::reserved4, rtsmac_phyRx_badHeader_callback(), sendCTS(), sendDAT(), phyHeader::srcAddr, state, TIMEOUT, UTime::uint16, UTime::uint8, unlockRXantenna(), updateTimer(), warp_timer_isActive(), warp_timer_stop(), warpmac_addressedToMe(), warpmac_enableEthernet(), warpmac_finishPhyXmit(), warpmac_incrementLEDHigh(), warpmac_prepEmacForXmit(), warpmac_prepPhyForXmit(), warpmac_startEmacXmit(), warpmac_startPhyXmit(), and warpphy_pollRxStatus().

Referenced by main().

int rtsmac_timer_callback ( unsigned char  unused  ) 

Callback for the expiration of timers.

Parameters:
unused Not used

Definition at line 386 of file rtsctsMac.c.

References BACKOFF, initTX(), pkt, sendBCD(), timerIntStatus, unlockRXantenna(), and updateTimer().

Referenced by main().

void sendCTS ( Macframe packet  ) 

Send Clear To Send packet over the PHY checks NAV state to determine whether channel is reserved Channel state information should be in TxBuffer 3.

Parameters:
packet Pointer to received RTS packet

Definition at line 512 of file rtsctsMac.c.

References csi, delay, Macframe::header, loadCSI(), lockRXantenna(), NAV, pkt, pktCtr, phyHeader::reserved1, phyHeader::reserved2, phyHeader::srcAddr, state, TIMEOUT, UTime::uint16, UTime::uint8, updateTimer(), warp_timer_isActive(), warpmac_finishPhyXmit(), warpmac_prepPhyForXmit(), and warpmac_startPhyXmit().

Referenced by rtsmac_phyRx_goodHeader_callback().

void updateTimer ( unsigned char  type,
unsigned int  newTime 
)

timer management function Handles setting and updating the timers

Parameters:
type Indicates which timer to set
newTime Length of timer in microseconds (not used for backoff)

Definition at line 325 of file rtsctsMac.c.

References BACKOFF, controlStruct, Maccontrol::currBackoff, delay, Maccontrol::maxBackoff, NAV, randNum(), state, TIMEOUT, warp_timer_isActive(), warp_timer_isPaused(), warp_timer_pause(), warp_timer_resume(), warp_timer_setVal(), warp_timer_start(), warp_timer_stop(), and warp_timer_timeLeft().

Referenced by initTX(), rtsmac_phyRx_badHeader_callback(), rtsmac_phyRx_goodHeader_callback(), rtsmac_timer_callback(), sendBCD(), sendCTS(), and sendDAT().


Updated on Wed Aug 6 13:29:32 2008 WARP