Monday, March 26, 2012

Certain Simple C Concepts

C Preprocessor Directives


    C Preprocessor is a separate program invoked by the compiler as first part of the compilation. It includes the directives for source file inclusion (ie #include), macro definition (#define) and conditional inclusion (ie #if).

    Preprocessor directives starts with a "#" sign, and that statement will be executed prior to the actual compilation of the code.

  (1) Source code inclusion

    #include Directive
      Preprocessor will replace the #include directive by entire content of the specified file.
     If the file name is enclosed in angle brackets, compiler will search the file in standard directories where it is configured to search.
 #include < stdio.h> 
     If the file name is enclosed in single quotes, compiler will search the file first in current directory and then if not found search in standard directories.
 #include "Timer.h" 
     Inorder to search in directories other than standard directories, use -I flag in the Makefile.
 CFLAGS += -I$(TOSDIR)/lib/printf

  (2) Macro definition 


    "#define" Directive

       #define Directive Defines the processor to replace all subsequent occurrence of a macro with a specific token.
 #define ADXL345_DEVID 0x00 
     The above example causes the preprocessor to replace the subsequent occurrence of the identifier "ADXL345_DEVID" with constant hex value 0x00.

     "#undef"Directive
        Defines macros are not affected by the block structure of C. A macro once defined will last until a "#undef" directive for that particular token. After undefining you can again redefine that token.
 #define ADXL345_DEVID 0x00 
 #undef ADXL345_DEVID 
 #define ADXL345_DEVID 0x01 

  (3) Conditional Inclusions

         Allows to include or discard certain code based on some conditions.

       #ifdef
 #ifdef NUM
 int amount [NUM];
 #endif
        Here the middle line will be compiled only if the NUM variable is already defined with #define.

        #ifndef
 #ifndef NUM
 #define NUM 46
 int amount [NUM];
 #endif
        Here the NUM variable will be defined only if it is not previously defined.

       #if, #else, #elif
 #if NUM>100
 #undef NUM
 #define NUM 100
 
 #elif NUM<50
 #undef NUM
 #define NUM 50

 #else
 #undef NUM
 #define NUM 200
 #endif 
       Here depending on certain condition the code is compiled.

Race condition

   Usually occurs in threaded programs. When two or more threads try to access same resource and change its value at same time, race condition occurs. Inorder to avoid this condition put a lock around the variable before using.

Printing in C


     To print the remainder

Use % for printing remainder of a division operation.
printf("%d",564%10);

rvalue Vs lvalue


   rvalue: rvalue of a variable is the value stored in that variable.
   lvalue: lvalue of a variable is the value of its address (where it is stored).
j=6;
k=j;

   Here in first line 'j' is at the left side of the equation and it denotes the address to which value 6 is to be copied. In the second line 'j' is at the right side of the equation and it denotes the value stored in 'j' to be copied to the address denoted by 'k'.

Function Pointer

   Declaring function pointer


      "ptFunction" is the function pointer declared and initialized to Null value.
int (*pt2Function)(float, char, char) = NULL; 

   Defining function pointer


      "ptFunction" is initialized to "DoIt" function whose definition is given below
ptFunction = DoIt;        // short form
ptFunction = &DoIt;   // correct assignment using address operator

void DoIt(float a, char b, char c) { }

   Comparing function pointer 


      This checks whether the  "ptFunction" is defined or not.
if(ptFunction >0) { }

   Calling function using function pointer 


       Both the methods will work.
int result1 = ptFunction(12, 'a', 'b'); 
int result2 = (*ptFunction) (12, 'a', 'b');

   Pass function pointer as argument 


       Both the function call and the function definition are given below.
PassPtr(&DoIt);  //Call the function

void PassPtr(int (*pt2Func)(float, char, char)) { } // Definition for the called function

Enumerations (enum)


   It is a set of named integer constants. Is defined like structures.

   Enum definition


enum coin {penny, dollar, paisa=15, dime, quater}

   Each of the enum symbol stands for an integer value starting from 0.

   Printing the values

printf("%d %d %d %d %d\n",penny,dollar,paisa,dime,quater);
   Here penny=0, dollar=1, paisa=15, dime=16 and quater=17.

   Declare variable


enum coin money;
   "money" is an object of type coin. 

   Initialize the variable

money = paisa;
   "money" is initialized to value "paisa". Printing money will print value 15.

Tuesday, March 20, 2012

NesC programming concepts.

Components


   Two kinds of components.

1. Singletons components

    Only one instant can exist. Renaming not possible.
configuration MainC {
}//  Singletons components module
components MainC; //Instantiating a Singletons component.

2. Generic components

    Can have multiple instants.
generic configuration TimerMilliC() {

 }   //  Generic components module

 //Instantiating a Generic component and renaming it.
 components new TimerMilliC() as TimerAccel;

 //Instantiating a Generic component without renaming.
 components new TimerMilliC(); 

Data types


uint8_t  :   Unsigned 8 bit integer.
uint16_t  :   Unsigned 16 bit integer.
uint32_t  :   Unsigned 32 bit integer.
uint8_t var1 =250;
printf("Value1 = %u", var1);
 
uint16_t var2 =65000;
printf("Value2 = %u", var2);

uint32_t var3 =4294960000;
printf("Value3 = %lu", var3);
 

Printf


   In NesC "printf" library will provides the terminal printing functionality for motes connected to PC through serial interface.

For using printf() in your NesC program:
  1. Include "printf.h" header in the component where it is being used.
#include "printf.h"

  2. Give path for the printf library in Makefile.
        CFLAGS += -I$(TOSDIR)/lib/printf   where $TOSDIR=/opt/tinyos-2.x/tos
COMPONENT=PrintfAppC
CFLAGS += -I$(TOSDIR)/lib/printf
include $(MAKERULES) 

 3. For explicit flushing of the printf output use the function printfflush().
printfflush(); 

  4. Default buffer size for the printf is 250 bytes as defined in the printf.h library in /opt/tinyos-2.x/tos/lib/printf/2_0_2/. For changing the buffer size edit the Makefile.
CFLAGS += -DPRINTF_BUFFER_SIZE={NEW_SIZE} 

Adding libraries or drivers in "Makefile" 


1. For adding libraries or drivers into your NesC program, add this line in your Makefile.
 CFLAGS += -I${PATH_OF_LIBRARY} 

2. If you want to add more than one library files, this line can be used repeatedly.
COMPONENT=PrintfAppC
CFLAGS += -I$(TOSDIR)/lib/printf
CFLAGS += -I$(TOSDIR)/chips/adxl345
include $(MAKERULES)

Commands and Events


   In NesC communication between two components are possible by using the interfaces. An interface will be provided by the provider component and used by the used component.
The user component make use of an interface provided by provider component, by making request (calls commands) to provider component. The provider component will make callbacks (signals events) as response to the user component.

  Commands
    Set of functions to be defined and implemented by interface's provider.
 return call Timer.startPeriodic(1000); //Call for the function Timer to start.
  Events
    Set of functions to be defined by interface's provider and implemented by interface's user.
 event result_t Timer.fired() {
} // Event is signaled once the Timer is fired 

"SplitControl" Interface


   This interface is used for switching between ON and OFF power states of the component providing it. If the command returns SUCCESS then corresponding startDone() or stopDone() event must be signalled.

SplitControl is similar to StdControl. StdControl is single-phase with only commands, while SplitControl is split-phase with commands and command completion events.

    Commands
 command error_t start()  // Start this component and all its subcomponents.
 command error_t stop()  //  Start this component and all its subcomponents. 
    Events
 event void startDone(error_t error) // Notify caller that component is 
  started and ready to receive other commands.
 event void stopDone(error_t error) // Notify caller that component has
  been stopped.

Task


   Task is a light weight procedure call. It can be posted at any time and posted task are executed later, one at a time by the TinyOS scheduler. A Task has following features.
    Has return value of void
    Takes no parameters
    Declared with task keyword.
    Task can be called by post operator.
    Posting task will always return success unless the task is pending.

Task declaration
 task void sendEvent1(); 
Task definition
 task void sendEvent1() {
 } 
Post a task
post sendEvent1();

Platform independent Data types


   Tinyos introduces platform independent data format that can be easily accessed and used. Usage of nx_ prefix or nxle_prefix on keywords such as struct and uint16_t or unint32_t means that they are external types, which have same representation on all hardware platforms.
typedef nx_struct BlinkToRadio{
   nx_uint16_t nodeid;            // Big endian 16 bit value
   nxle_uint8_t length;            // Little endian 8 bit value
}

Thursday, March 15, 2012

Manual Installation of Tiny OS in Ubuntu 11.10 from RPM


 The procedure given is for setting up Tiny OS 2.x in Ubuntu 11.10.

  I had followed the TinyOS wiki page and these are the exact steps i followed for Tiny OS installation for my TelosB mote which is using TIMSP430 processor.

After the installation, i dealt  with an error while compiling the TestSerial application for serial communication. It seems the issue is due to the Ubuntu 11.10 version OS.

1. Install Java

    (1) Install "python-software-properties" package.
apt-get install python-software-properties 
    (2) Add proper Repo for Java package.
           Log out from the current terminal and open a new one.
add-apt-repository ppa:ferramroberto/java 
    (3) Update your local package index.
 apt-get update 
    (4) Now install java packages.
 apt-get install sun-java6-jdk sun-java6-plugin 

2. Install  "rpm" package for installing RPM packages in Ubuntu.
 apt-get install rpm 

3. Install compilers for TIMSP430

      (1) Download msp430tools-base from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-base-0.1-20050607.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-base-0.1-20050607.i386.rpm 
      (2) Download msp430tools-python-tools from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-python-tools-1.0-1.noarch.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-python-tools-1.0-1.noarch.rpm 
      (3) Download msp430tools-binutils from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-binutils-2.16-20050607.i386.rpm
      Install it using this command.
rpm -Uvh --force --nodeps msp430tools-binutils-2.16-20050607.i386.rpm 
      (4) Download msp430tools-gcc from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-gcc-3.2.3-20050607.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-gcc-3.2.3-20050607.i386.rpm 
      (5) Download msp430tools-libc from here.
        http://www.tinyos.net/dist-2.1.0/tools/linux/msp430tools-libc-20080808-1.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-libc-20080808-1.i386.rpm 
      (6) Downloadmsp430tools-jtag-lib from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-jtag-lib-20031101cvs-20050610.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-jtag-lib-20031101cvs-20050610.i386.rpm 
      (7) Download msp430tools-gdb from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-gdb-6.0-20050609.i386.rpm   
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-gdb-6.0-20050609.i386.rpm 

4. Install TinyOS toolchain.

      (1) Download nesc from here.
        http://tinyos.stanford.edu/tinyos-rpms/nesc-1.3.1-1.fc9.i386.rpm
      Install it using this command.
 rpm -Uvh --ignoreos --nodeps nesc-1.3.1-1.fc9.i386.rpm 
      (2) Download tinyos-deputy from here.
        http://www.tinyos.net/dist-2.1.0/tinyos/linux/tinyos-deputy-1.1-1.fc9.i386.rpm
      Install it using this command.
 rpm -Uvh --ignoreos --nodeps tinyos-deputy-1.1-1.fc9.i386.rpm 
      (3) Download tinyos-tools from here.
        http://tinyos.stanford.edu/tinyos-rpms/tinyos-tools-1.4.0-3.ubuntu.i386.rpm          Install it using this command.
rpm -Uvh --ignoreos --nodeps tinyos-tools-1.4.0-3.ubuntu.i386.rpm 

5. Install TinyOS 2.x source tree.

      (1) Download tinyos source from here.
        http://tinyos.stanford.edu/tinyos-rpms/tinyos-2.1.1-3.ubuntu.noarch.rpm
      Install it using this command.
 rpm -Uvh --ignoreos --nodeps tinyos-2.1.1-3.ubuntu.noarch.rpm 

6. Add path.

      (1) Open bashrc file.
 vim ~/.bashrc 
      (2) Add the following lines to end of the bashrc file.
export TOSROOT=/opt/tinyos-2.x
export TOSDIR=$TOSROOT/tos
export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.
export MAKERULES=$TOSROOT/support/make/Makerules
export PATH=/opt/msp430/bin:/opt/jflashmm:$PATH 

7. Graphviz installation.

       (1) You can download graphviz and its dependency libgraphviz from this location.
         http://www.graphviz.org/Download_linux_ubuntu.php
       (3) liblasi0 is a dependency which i installed from ubuntu repo for graphviz.
 apt-get install liblasi0 
       (2) Install graphviz and its dependency.
 dpkg -i libgraphviz4_2.28.0-1_i386.deb

dpkg -i graphviz_2.28.0-1_i386.deb 
      

Errors

(1) Error while compiling the TestSerial application for serial communication.
/apps/tests/TestSerial# make telosb

mkdir -p build/telosb
mig java -target=null -I/opt/tinyos-2.x/tos/lib/T2Hack
-DIDENT_APPNAME=\"TestSerialAppC\" -DIDENT_USERNAME=\"root\"
-DIDENT_HOSTNAME=\"ubuntu\" -DIDENT_USERHASH=0xa3473ba6L
-DIDENT_TIMESTAMP=0x4f634feeL -DIDENT_UIDHASH=0x185584f2L -java-
classname=TestSerialMsg TestSerial.h test_serial_msg -o TestSerialMsg.java
two source files specified (PLATFORM_NULL and IDENT_APPNAME="TestSerialAppC")
failed to parse message file TestSerial.h

make: *** [TestSerialMsg.java] Error 1 

Solution:

  Couldn't solve the issue. It seems  the issue is with the ubuntu version 11.10. I solved the issue by switching back to Ubuntu 10.04 LTS version.

(2) Error with the java files.
        java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb

Exception in thread "main" java.lang.NoClassDefFoundError: net/tinyos/tools/Listen

Caused by: java.lang.ClassNotFoundException: net.tinyos.tools.Listen
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: net.tinyos.tools.Listen.  Program will exit.

Solution:

  1. Download of whole "java" as tarball from Tiny OS CVS repository.
      http://tinyos.cvs.sourceforge.net/viewvc/tinyos/tinyos-2.x/support/sdk/java/
  2. Replace the "java" file from /opt/tinyos-2.x/support/sdk/ with the extracted java file, from the downloaded tarball file.
  3. Go inside the java folder in terminal and give "make" command.
  4. Enjoy.

(3) Error in installing rpm packages.
rpm -Uvh --force --nodeps msp430tools-base-0.1-20050607.i386.rpm

rpm: please use alien to install rpm packages on Debian, if you are really sure use --force-debian switch. See README.Debian for more details.

Solution:
  Use this command instead.
rpm -Uvh --force-debian --nodeps msp430tools-base-0.1-20050607.i386.rpm


(3) Error in "make "
make telosb
make: *** No rule to make target `telosb'.  Stop.

Solution:

This is because you have done the installation as root user and trying to "make" as a different user.
Solve this by doing "make" as root user or give proper permission for that particular user.
sudo chown prasanth:prasanth -R /opt/tinyos-2.x/

Monday, March 12, 2012

Data Transmission message sequence Chart – Recipient


  1. MLME-RX-ENABLE.request (TRUE or FALSE (Receiver enable for this superfra or until next), 0 x 000000–0 x ffffff (RxOnTime ), 0 x 000000–0 x ffffff (RxOnDuration ) )
        → Higher to MAC
  1.  PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY
  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

Note: Receives data.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )  
        PHY to MAC
  1. MCPS-DATA.indication (0 x 00–0 x 03(SrcAddrMode ), 0 x 000–0 x ffff (SrcPANId ) SrcAddr (As specified by the SrcAddrMode ) 0 x 00–0 x 03 (DstAddrMode ) 0 x 0000–0 x ffff (DstPANId ) DstAddr(As specified by the DstAddrMode )msduLength, msdu, 0 x 00–0 x ff (mpduLinkQuality), TRUE or FALSE (Security), 0 x 00–0 x 08 (ACL entry) )
          → MAC to Higher level.

  1. PLME-SET-TRX-STATE.request (TX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) )
        → MAC to PHY

Note: Sent Acknowledgment.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (TRX_OFF)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

Data Transmission message sequence Chart – Orginator


  1. MCPS-DATA.request ( 0 x 00–0 x 03(SrcAddrMode ), 0 x 000–0 x ffff (SrcPANId ) SrcAddr (As specified by the SrcAddrMode ) 0 x 00–0 x 03 (DstAddrMode )  x 0000–0 x ffff (DstPANId ) DstAddr(As specified by the DstAddrMode ) msduLength, msdu, 0 x 00–0 x ff(msduHandle) 0000 xxxx(TxOptions ) )

        Higher layer to MAC

  1. PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-CCA.request ()
        → MAC to PHY
        → No parameter.

Note: Do this upto channel is idle.

  1. PLME-CCA.confirm (IDLE(status ))
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (TX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) )
        → MAC to PHY

Note: Sent Data.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

Note: Wait for macAckWaitDuration, and receive the Acknowledgment.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (TRx_off)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. MCPS-DATA.confirm ( 0 x 000 x ff (MSDU handle), SUCCESS(Status) )
        → MAC to Higher layer.

Zigbee standard message sequence while Orphan Channel Scan



Orphan Channel Scan

  1. MLME-SCAN.request( 0 x 03(ScanType, Orphan), 32-bit field(ScanChannels), 0 to 14(ScanDuration) )
        Higher layer to MAC.
  1. PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET.request ( 0 x 00(PIBAttribute Identifier-phyCurrentChannel), firstchannel(0 to 26) )
        → MAC to PHY

  1. PLME-SET.confirm ( SUCCESS,0 x 00(PIBAttribute Identifier-phyCurrentChannel) )
       → PHY to MAC

Note: Sent orphan notification.

  1. PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

Note: Wait for aResponseWaitTime.

Note: Repeat for all the channels until it receives coordinator realignment command .

  1. MLME-ORPHAN.indication ( 64-bit address of the orphaned device, TRUE or FALSE (Security use), 0 x 00–0 x 08(ACL entry) )
        MAC to Higher level of Coordinator.

  1. MLME-ORPHAN.response ( 64 bit address of orphaned device, 0 x 0000–0 x ffff(Short address of orphaned device ), TRUE or FALSE(Associated member ), TRUE or FALSE(Security enable))
        → Higher layer to MAC on coordinatorr.
Note: Sent coordinator realignment command to device.
  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )
        PHY to MAC on device.

Note: Device assigned to its previous values.

Zigbee standard message sequence while Disassosiation

Disassociation

  1. MLME-DISASSOCIATE.request (64-bit address, 0 x 00–0 x ff (disassociation reason), True/False(Security enable))
        → Higher layer to MAC of device.

  1. PLME-SET-TRX-STATE.request (TX_ON)
        → MAC to PHY of device.

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC of device.

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) )
        → MAC to PHY of device.

Note: Sent Disassociation notification.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC of device.

  1. PLME-SET-TRX-STATE.request (RX_ON)
        MAC to PHY of device.

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC of device.

Note: Wait for macAckWaitDuration & get it.

  1. PLME_SET-TRX-STATE.request (RX_ON)
        → PHY to MAC on coordinator side.

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC on coordinator side.

Note: Receives disassociation request.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )

        → PHY to MAC on coordinator side.

  1. PLME-SET-TRX-STATE.request (TX_ON)
        → MAC to PHY on coordinator side.

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC on coordinator side.

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) )
        → MAC to PHY on coordinator side.

Note: Sent Acknowledgment request.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC on coordinator side.

  1. MLME-DISASSOCIATE.indication ( DeviceAddress(64 bit address), 0 x 000 x ff (DisassociateReason ), True/False(Security use), 0 x 000 x 08 (ACLEntry ) )
        → MAC to Higher layer on coordinator side.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )
       PHY to MAC on device.

Note: Received acknowledgment.

  1. MLME-DISASSOCIATE.confirm ( SUCCESS )
        → MAC to Higher layer on device.

Zigbee standard message sequence while a Device associate with a Co-ordinator (In Device side)



Device Association with Coordinator (Device side)


  1. MLME-RESET.request ( true/false (SetDefaultPIB) )
        → Upper layer to MAC

  1. PLME-SET-TRX-STATE.request (TRX_OFF)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. MLME-RESET.confirm (SUCCESS)
        → MAC to Higher layer

  1. MLME-SCAN.request( 0 x 02(ScanType, Passive), 32-bit field(ScanChannels), 0 to 14(ScanDuration) )
        Higher layer to MAC.

  1. PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET.request ( 0 x 00(PIBAttribute Identifier-phyCurrentChannel), firstchannel(0 to 26) )
        → MAC to PHY

  1. PLME-SET.confirm ( SUCCESS, 0 x 00(PIBAttribute Identifier- phyCurrentChannel) )
        PHY to MAC

Note: Beacons will arrive

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )

        PHY to MAC

 Note: Receives the beacon from one channel for aBaseSuperframeDuration x (2n +1), where n is ScanDuration whose value < 14.

Note: Steps 8 to 10 done repeatedly to finish scanning of all channels specified in ScanChannels parameter of MLME-SCAN.request.


  1. PLME-SET-TRX-STATE.request (TRx_off)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. MLME-SCAN.confirm( SUCCESS, 0 x 02(ScanType-Passive scan), 32-bit field(unscanned channels), ResultListSize(No. Of elements returned, 0 for orphan), 0 x 00 to 0x ff(List of energy measured, one for each channel), PANDescriptorList(Null for ED & Orphan) )

        MAC to Higher level

Note: Selection of PAN based on list of PAN descriptors.

  1. MLME-ASSOCIATE.request ( LogicalChannel(Integer), 0 x 02–0 x 03 (CoordAddrMode), 0 x 0000–0 x ffff(CoordPANId), CoordAddress(As specified inCoordAddrMode ), CapabilityInformation, True/False(Security enable) )

        Higher layer to MAC

  1. PLME-SET-TRX-STATE.request (TX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) ) 

    → MAC to PHY

Note: Sent Association request.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

Note: Wait for macAckWaitDuration, and receive the Acknowledgment.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )

        PHY to MAC

Note: Wait for aResponseWaitTime.

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) )
        → MAC to PHY

Note: Sent Data request.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

Note: Wait for macAckWaitDuration, and receive the Acknowledgment.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )

        PHY to MAC

Note: Receive Association response.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )

        PHY to MAC

  1. PLME-SET-TRX-STATE.request (TX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) )
        → MAC to PHY

Note: Sent Acknowledgment.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (TRX_OFF)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. MLME-ASSOCIATE.confirm ( 0 x 00000 x ffff(Short address for device), SUCCESS(Status if association))

       → MAC to Higher layer.