• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/wpan/p802_15_4phy.h

00001 /********************************************/
00002 /*     NS2 Simulator for IEEE 802.15.4      */
00003 /*           (per P802.15.4/D18)            */
00004 /*------------------------------------------*/
00005 /* by:        Jianliang Zheng               */
00006 /*        (zheng@ee.ccny.cuny.edu)          */
00007 /*              Myung J. Lee                */
00008 /*          (lee@ccny.cuny.edu)             */
00009 /*        ~~~~~~~~~~~~~~~~~~~~~~~~~         */
00010 /*           SAIT-CUNY Joint Lab            */
00011 /********************************************/
00012 
00013 // File:  p802_15_4phy.h
00014 // Mode:  C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t
00015 
00016 // $Header: /cvsroot/nsnam/ns-2/wpan/p802_15_4phy.h,v 1.2 2007/01/30 05:00:52 tom_henderson Exp $
00017 
00018 /*
00019  * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and
00020  * The City University of New York. All rights reserved.
00021  *
00022  * Redistribution and use in source and binary forms, with or without
00023  * modification, are permitted provided that the following conditions
00024  * are met:
00025  * 1. Redistributions of source code must retain the above copyright
00026  *    notice, this list of conditions and the following disclaimer.
00027  * 2. Redistributions in binary form must reproduce the above copyright
00028  *    notice, this list of conditions and the following disclaimer in the
00029  *    documentation and/or other materials provided with the distribution.
00030  * 3. All advertising materials mentioning features or use of this software
00031  *    must display the following acknowledgement:
00032  *      This product includes software developed by the Joint Lab of Samsung 
00033  *      Advanced Institute of Technology and The City University of New York.
00034  * 4. Neither the name of Samsung Advanced Institute of Technology nor of 
00035  *    The City University of New York may be used to endorse or promote 
00036  *    products derived from this software without specific prior written 
00037  *    permission.
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE
00040  * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS 
00041  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00042  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 
00043  * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK 
00044  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00045  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00046  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00047  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00048  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00049  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00050  */
00051 
00052 
00053 #ifndef p802_15_4phy_h
00054 #define p802_15_4phy_h
00055 
00056 //#include <scheduler.h>
00057 #include <packet.h>
00058 #include <wireless-phy.h>
00059 #include "p802_15_4def.h"
00060 
00061 //PHY enumerations description (Table 16)
00062 typedef enum
00063 {
00064         p_BUSY = 0,
00065         p_BUSY_RX,
00066         p_BUSY_TX,
00067         p_FORCE_TRX_OFF,
00068         p_IDLE,
00069         p_INVALID_PARAMETER,
00070         p_RX_ON,
00071         p_SUCCESS,
00072         p_TRX_OFF,
00073         p_TX_ON,
00074         p_UNSUPPORT_ATTRIBUTE,
00075         p_UNDEFINED                     //we added this for handling any case not specified in the draft
00076 }PHYenum;
00077 
00078 //PHY PIB attributes (Table 19)
00079 typedef enum
00080 {
00081         phyCurrentChannel = 0x00,
00082         phyChannelsSupported,
00083         phyTransmitPower,
00084         phyCCAMode
00085 }PPIBAenum;
00086 
00087 struct PHY_PIB
00088 {
00089         UINT_8  phyCurrentChannel;
00090         UINT_32 phyChannelsSupported;
00091         UINT_8  phyTransmitPower;
00092         UINT_8  phyCCAMode;
00093 };
00094 
00095 //---handlers---
00096 #define phyCCAHType             1
00097 #define phyEDHType              2
00098 #define phyTRXHType             3
00099 #define phyRecvOverHType        4
00100 #define phySendOverHType        5
00101 #define phyCCAReportHType       6  // 2.31 change: new timer added for CCA reporting
00102 class Phy802_15_4;
00103 class Phy802_15_4Timer : public Handler
00104 {
00105         friend class Phy802_15_4;
00106 public:
00107         Phy802_15_4Timer(Phy802_15_4 *p, int tp) : Handler()
00108         {
00109                 phy = p;
00110                 type = tp;
00111                 active = false;
00112         }
00113         virtual void start(double wtime);
00114         virtual void cancel(void);
00115         virtual void handle(Event* e);
00116 
00117 protected:
00118         Phy802_15_4 *phy;
00119         int type;
00120         bool active;
00121         Event nullEvent;
00122 };
00123 
00124 class Mac802_15_4;
00125 class Phy802_15_4 : public WirelessPhy
00126 {
00127         friend class Phy802_15_4Timer;
00128 public:
00129         Phy802_15_4(PHY_PIB *pp);
00130         void macObj(Mac802_15_4 *m);
00131         bool channelSupported(UINT_8 channel);
00132         double getRate(char dataOrSymbol);
00133         double trxTime(Packet *p,bool phyPkt = false);
00134         void construct_PPDU(UINT_8 psduLength,Packet *psdu);
00135         void PD_DATA_request(UINT_8 psduLength,Packet *psdu);
00136         void PD_DATA_indication(UINT_8 psduLength,Packet *psdu,UINT_8 ppduLinkQuality);
00137         void PLME_CCA_request();
00138         void PLME_ED_request();
00139         void PLME_GET_request(PPIBAenum PIBAttribute);
00140         void PLME_SET_TRX_STATE_request(PHYenum state);
00141         void PLME_SET_request(PPIBAenum PIBAttribute,PHY_PIB *PIBAttributeValue);
00142         UINT_8 measureLinkQ(Packet *p);
00143         void recv(Packet *p, Handler *h);
00144         Packet* rxPacket(void) {return rxPkt;}
00145         void wakeupNode(int cause); // 2.31 change: for MAC to wake up the node
00146         void putNodeToSleep(); // 2.31 change: for MAC to put the node to sleep
00147         double channel_sleep_time_;     // 2.31 change: time when node was put to sleep 
00148         double T_transition_local_;     // 2.31 change: created a local variable since WirelessPhy::T_transition_ is not visible to CsmaCA802_15_4
00149 
00150         
00151 public:
00152         static PHY_PIB PPIB;
00153         double last_tx_time;    // 2.31 change: 
00154 
00155 protected:
00156         void    CCAHandler(void);
00157         void    EDHandler(void);
00158         void    TRXHandler(void);
00159         void    recvOverHandler(Packet *p);
00160         void    sendOverHandler(void);
00161         void    CCAReportHandler(void); // 2.31 change: new timer added to report CCA
00162 
00163 private:
00164         PHY_PIB ppib;
00165         PHYenum trx_state;              //tranceiver state: TRX_OFF/TX_ON/RX_ON
00166         PHYenum trx_state_defer_set;    //defer setting tranceiver state: TX_ON/RX_ON/TRX_OFF/IDLE (IDLE = no defer pending)
00167         PHYenum trx_state_turnaround;   //defer setting tranceiver state in case Tx2Rx or Rx2Tx
00168         PHYenum tx_state;               //transmitting state: IDLE/BUSY
00169         PHYenum sensed_ch_state;        //Stored value of ch state done at beginning of                                         //backoffSlot for forwarding to MAC after ccaDetectTime
00170         Packet *rxPkt;                  //the packet meets the following conditions:
00171                                         // -- on the current channel
00172                                         // -- for this node (not interference)
00173                                         // -- with the strongest receiving power among all packets that are for this node and on the current channel
00174         Packet *txPkt;                  //the packet being transmitted
00175         Packet *txPktCopy;              //the copy of the packet being transmitted
00176         double rxTotPower[27];          
00177         double rxEDPeakPower;           
00178         UINT_32 rxTotNum[27];           
00179         UINT_32 rxThisTotNum[27];       
00180         Mac802_15_4 *mac;
00181         Phy802_15_4Timer CCAH;
00182         Phy802_15_4Timer EDH;
00183         Phy802_15_4Timer TRXH;
00184         Phy802_15_4Timer recvOverH;
00185         Phy802_15_4Timer sendOverH;
00186         Phy802_15_4Timer CCAReportH; // 2.31 change: new timer to report CCA
00187 };
00188 
00189 #endif
00190 
00191 // End of file: p802_15_4phy.h

Generated on Tue Aug 10 2010 16:16:09 for ns-2.33 by  doxygen 1.7.1