[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/mac/tkn154/interfaces/public IEEE154BeaconFrame.nc, NONE, 1.1 IEEE154Frame.nc, NONE, 1.1 IEEE154TxBeaconPayload.nc, NONE, 1.1

Jan-Hinrich Hauer janhauer at users.sourceforge.net
Mon Jun 16 11:00:36 PDT 2008


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/interfaces/public
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30549/tos/lib/mac/tkn154/interfaces/public

Added Files:
	IEEE154BeaconFrame.nc IEEE154Frame.nc 
	IEEE154TxBeaconPayload.nc 
Log Message:
Initial version of TKN15.4, a platform-independent IEEE 802.15.4-2006 MAC implementation (see tinyos-2.x/tos/lib/mac/tkn154/README.txt)

--- NEW FILE: IEEE154BeaconFrame.nc ---
/* 
 * Copyright (c) 2008, Technische Universitaet Berlin
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * - Neither the name of the Technische Universitaet Berlin nor the names
 *   of its contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * - Revision -------------------------------------------------------------
 * $Revision: 1.1 $
 * $Date: 2008/06/16 18:00:34 $
 * @author Jan Hauer <hauer at tkn.tu-berlin.de>
 * ========================================================================
 */


#include <TKN154.h>

interface IEEE154BeaconFrame 
{
 
 /**
   * Reads the Pending Address Specification of a beacon frame.
   *
   * @param frame         the beacon frame
   * @param pendAddrSpec  a pointer to where the Pending Address 
   *                      Specification should be written
   * @return              FAIL if the frame is not a beacon frame,
   *                      SUCCESS otherwise
   */
  command error_t getPendAddrSpec(message_t* frame, uint8_t* pendAddrSpec);

 /**
   * Reads the Pending Addresses of a given type (short or extended) from a 
   * beacon frame.
   *
   * @param frame         the beacon frame
   * @param addrMode      the address mode of the sought addresses, either 
   *                      ADDR_MODE_SHORT_ADDRESS or ADDR_MODE_EXTENDED_ADDRESS
   * @param buffer        a pointer to an array of "bufferSize" addresses
   * @param bufferSize    number of address entries in the buffer
   *
   * @return              FAIL if the frame is not a beacon frame,
   *                      SUCCESS otherwise
   */
  command error_t getPendAddr(message_t* frame, uint8_t addrMode, 
      ieee154_address_t buffer[], uint8_t bufferSize);

 /**
   * Determines whether the local macShortAddress or aExtendedAddress
   * (as currently registered in the PIB) is part of the pending 
   * address list of a beacon.
   *
   * @param frame the beacon frame
   * 
   * @return      ADDR_MODE_NOT_PRESENT if the frame is not a beacon
   *              beacon frame, or the local address is not part of
   *              the pending address list,
   *              ADDR_MODE_SHORT_ADDRESS if the local macShortAddress 
   *              is part of the pending address list,
   *              ADDR_MODE_EXTENDED_ADDRESS if the local aExtendedAddress
   *              is part of the pending address list
   */
  command uint8_t isLocalAddrPending(message_t* frame);

 /**
   * Parses the PAN Descriptor of a beacon frame. Since a frame
   * does not include information about the channel that it was 
   * received on this information must be provided by the caller. 
   *
   * @param frame          the beacon frame
   * @param LogicalChannel will be written to PANDescriptor->LogicalChannel
   * @param ChannelPage    will be written to PANDescriptor->ChannelPage
   * @param PANDescriptor  a pointer to a PAN Descriptor, that will hold 
   *                       the PAN Descriptor as parsed of the beacon frame 
   * @param bufferSize     number of address entries in the buffer
   *
   * @return               SUCCESS if the frame is a valid beacon frame and the 
   *                       PANDescriptor was successfully parsed, FAIL
   *                       otherwise
   */
  command error_t parsePANDescriptor(message_t *frame, uint8_t LogicalChannel,
      uint8_t ChannelPage, ieee154_PANDescriptor_t *PANDescriptor);  

 /**
   * Returns a pointer to the beacon payload.
   *
   * @param frame         the beacon frame
   * @return              a pointer to the beacon payload, or, if the
   *                      frame is not a beacon frame, a pointer to
   *                      the MAC payload. If the frame was received
   *                      while in promiscuous mode, then this command
   *                      returns a pointer to the first byte of the MHR.
   */
  command void* getBeaconPayload(message_t* frame);

  /**
    * Returns the length of the beacon payload portion of the frame
    * (in byte).
    *
    * @param  frame   the frame 
    * @return         the length (in byte) of the frame's beacon payload
    *                 portion, or, if the frame is not a beacon frame 
    *                 the length of the MAC payload. If the frame 
    *                 was received while in promiscuous mode, then 
    *                 this command returns the length of MHR + MAC Payload.
    */
  command uint8_t getBeaconPayloadLength(message_t* frame);

 /**
   * Returns the (beacon) sequence number of the frame.
   *
   * @param frame     the frame
   * @return          sequence number of the frame
   */
  command uint8_t getBSN(message_t* frame);  
}

--- NEW FILE: IEEE154Frame.nc ---
/* 
 * Copyright (c) 2008, Technische Universitaet Berlin
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * - Neither the name of the Technische Universitaet Berlin nor the names
 *   of its contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * - Revision -------------------------------------------------------------
 * $Revision: 1.1 $
 * $Date: 2008/06/16 18:00:34 $
 * @author Jan Hauer <hauer at tkn.tu-berlin.de>
 * ========================================================================
 */


#include <TKN154.h>
#include <message.h>

interface IEEE154Frame 
{

 /**
   * Returns the source addressing mode of the frame.
   *
   * @param frame     the frame
   * @return          source addressing mode of the frame; either
   *                  ADDR_MODE_NOT_PRESENT, ADDR_MODE_RESERVED,
   *                  ADDR_MODE_SHORT_ADDRESS or ADDR_MODE_EXTENDED_ADDRESS
   */
  command uint8_t getSrcAddrMode(message_t* frame);    

 /**
   * Reads the source address (to be interpreted
   * as specified by the source addressing mode) of the frame.
   *
   * @param frame     the frame
   * @param address   a pointer to where the source address 
   *                  will be written
   * @return          SUCCESS, if the source address is present 
   *                  and was written to "address",
   *                  FAIL otherwise (source address remains
   *                  unmodified)
   */
  command error_t getSrcAddr(message_t* frame, ieee154_address_t *address);   

 /**
   * Reads the source PAN identifier of the frame.
   *
   * @param frame     the frame
   * @param PANID     a pointer to where the source PAN identifier 
   *                  will be written
   * @return          SUCCESS, if the source PAN identifier is present 
   *                  and was written to "PANID", 
   *                  FAIL otherwise (PANID remains unmodified)
   */
  command error_t getSrcPANId(message_t* frame, uint16_t* PANID);  

 /**
   * Returns the destination addressing mode of the frame.
   *
   * @param frame     the frame
   * @return          destination addressing mode of the frame; either
   *                  ADDR_MODE_NOT_PRESENT, ADDR_MODE_RESERVED,
   *                  ADDR_MODE_SHORT_ADDRESS or ADDR_MODE_EXTENDED_ADDRESS
   */
  command uint8_t getDstAddrMode(message_t* frame);    

 /**
   * Reads the destination address (to be interpreted
   * as specified by the destination addressing mode) of the frame.
   *
   * @param frame     the frame
   * @param address   a pointer to where the destination address 
   *                  will be written
   * @return          SUCCESS, if the destination address is present 
   *                  and was written to "address",
   *                  FAIL otherwise (destination address 
   *                  remains unmodified)
   */
  command error_t getDstAddr(message_t* frame, ieee154_address_t *address);   

 /**
   * Reads the destination PAN identifier of the frame.
   *
   * @param PANID     a pointer to where the destination 
   *                  PAN identifier should be written
   * @param frame     the frame
   * @return          SUCCESS, if the destination PAN identifier 
   *                  is present and was copied to "PANID", 
   *                  FAIL otherwise (PANID remains unmodified)
   */
  command error_t getDstPANId(message_t* frame, uint16_t* PANID);  

 /**
   * Sets the addressing fields in the MAC header of a frame. The source 
   * PAN identifier and the source address will be set automatically, their
   * values depend on the <code>SrcAddrMode</code> parameter: if 
   * <code>SrcAddrMode</code> is a short or extended address, then
   * the current PIB attributes <code>macShortAddress</code> or 
   * <code>aExtendedAddress</code> and <code>macPANId</code> are used.
   *
   * @param frame         the frame
   * @param srcAddrMode   the source addressing mode
   * @param dstAddrMode   the destination addressing mode
   * @param dstPANID      the 16 bit PAN identifier of the destination
   * @param dstAddr       individual device address of the destination as per
   *                      the dstAddrMode
   * @param security      the security options (NULL means security is
   *                      disabled)
   *                      
   * @return          SUCCESS if the addressing fields where written,
   *                  FAIL if a wrong addressing mode was specified
   */
  command error_t setAddressingFields(message_t* frame,
                          uint8_t SrcAddrMode,
                          uint8_t DstAddrMode,
                          uint16_t DstPANID,
                          ieee154_address_t *DstAddr,
                          ieee154_security_t *security);

 /**
   * Returns a pointer to the MAC payload portion of a frame.
   *
   * @param frame     the frame
   * @return          a pointer to the frame's payload 
   */
  command void* getPayload(message_t* frame);

  /**
    * Returns the length of the MAC payload portion of the frame (in byte). 
    *
    * @param  frame   the frame 
    * @return         the length of the frame's payload (in byte)
    */
  command uint8_t getPayloadLength(message_t* frame);

 /**
   * Returns the point in time when the frame was received. If 
   * <code>isTimestampValid()<\code> returns FALSE then the 
   * timestamp is not valid and must be ignored.
   *
   * @param frame     the frame
   * @return          timestamp of the frame
   */
  command uint32_t getTimestamp(message_t* frame);  

 /**
   * Tells whether the timestamp is valid.
   *
   * @return          TRUE if timestamp is valid, FALSE otherwise.
   */
  command bool isTimestampValid(message_t* frame);  

 /**
   * Returns the sequence number of the frame.
   *
   * @param frame     the frame
   * @return          sequence number of the frame
   */
  command uint8_t getDSN(message_t* frame);  

 /**
   * Returns the link quality level at which the frame was received.
   *
   * @param frame     the frame
   * @return          link quality level 
   */
  command uint8_t getLinkQuality(message_t* frame);  

  /**
    * Returns the type of the frame
    * BEACON=0, DATA=1, ACK=2, COMMAND=3.
    *
    * Note: For beacon frames one can use the <code>IEEE154BeaconFrame<\code>
    * interface to inspect additional fields of the frame.
    *
    * @param  frame   the frame
    * @return         the type of the frame
    */
  command uint8_t getFrameType(message_t* frame);

 /**
   * Returns a pointer to the MAC header (i.e. to the first byte of 
   * the Frame Control field).
   *
   * @param frame     the frame
   * @return          a pointer to the frame's header
   */
  command void* getHeader(message_t* frame);

  /**
    * Returns the length of the MAC header.
    *
    * @param  frame   the frame 
    * @return         the length of the MAC header (in byte)
    */
  command uint8_t getHeaderLength(message_t* frame);

  /**
    * Tells whether or not the frame was received while 
    * promiscuous mode was enabled.
    *
    * @param  frame   the frame
    * @return         TRUE if frame was received while in promiscuous
    *                 mode, FALSE otherwise
    */
  command bool wasPromiscuousModeEnabled(message_t* frame);

  /**
    * Tells whether or not the frame has a standard compliant
    * IEEE 802.15.4 header - this will only be relevant for frames 
    * received while in promiscuous mode, because then no filtering
    * (except CRC check) was applied. Note: if this command returns
    * FALSE, then all other commands in this interface (except
    * <code>wasPromiscuousModeEnabled()</code>) and the 
    * <code>IEEE154BeaconFrame</code> interface return undefined values!
    *
    * @param  frame   the frame
    * @return         TRUE if frame has a standard compliant header,
    *                 FALSE otherwise
    */
  command bool hasStandardCompliantHeader(message_t* frame);

}

--- NEW FILE: IEEE154TxBeaconPayload.nc ---
/* 
 * Copyright (c) 2008, Technische Universitaet Berlin
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * - Neither the name of the Technische Universitaet Berlin nor the names
 *   of its contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * - Revision -------------------------------------------------------------
 * $Revision: 1.1 $
 * $Date: 2008/06/16 18:00:34 $
 * @author Jan Hauer <hauer at tkn.tu-berlin.de>
 * ========================================================================
 */


#include <TKN154.h>

interface IEEE154TxBeaconPayload 
{
  /** 
   * Sets the beacon payload portion for all subsequently transmitted beacons.
   * This command replaces the MLME-SET command for the PIB attribute values
   * 0x45 (macBeaconPayload) and 0x46 (macBeaconPayloadLength). The
   * <code>setBeaconPayloadDone()<\code> event will be signalled when the 
   * beacon payload has been set -- until then <code>beaconPayload<\code> must 
   * not be modified.
   *
   * @param beaconPayload   the new beacon payload
   * @param length          the length of the new beacon payload (in byte)
   *
   * @return EBUSY if another transaction is pending, ESIZE if length is too big, 
   * SUCCESS otherwise (and only then the <code>setBeaconPayloadDone<\code> event 
   * will be signalled)
   */
 command error_t setBeaconPayload(void *beaconPayload, uint8_t length);

  /**
   * Signalled in response to a <code>setBeaconPayload()<\code> request.
   * Indicates that the beacon payload has been copied and returns the
   * ownership of the buffer to the next higher layer. 
   * 
   * @param beaconPayload   the <code>beaconPayload<\code> passed in the 
   *                        <code>setBeaconPayload()<\code> command
   * @param length          the <code>length<\code> passed in the 
   *                        <code>setBeaconPayload()<\code> command
   */
 event void setBeaconPayloadDone(void *beaconPayload, uint8_t length);

  /**
   * Returns a pointer to the current beacon payload. 
   * 
   * @return the current beacon payload
   */
 command const void* getBeaconPayload();

  /**
   * Returns the length of the current beacon payload (in byte). 
   * 
   * @return length of the current beacon payload
   */
 command uint8_t getBeaconPayloadLength();

  /**
   * Replaces (overwrites) a portion of the current beacon payload. Whenever
   * possible, to minimize overhead, the next higher layer should prefer this
   * command over the <code>setBeaconPayload()<\code> command.  The
   * <code>modifyBeaconPayloadDone()<\code> event will be signalled when the 
   * beacon payload has been updated -- until then <code>buffer<\code> must 
   * not be modified.
   *
   * @param offset      offset into the current beacon payload
   * @param buffer      the buffer to be written 
   * @param length      the length of the buffer
   *
   * @return EBUSY if another transaction is pending, ESIZE if offset+length is too big, 
   * SUCCESS otherwise (and only then the <code>modifyBeaconPayloadDone<\code> event 
   * will be signalled)
   */
 command error_t modifyBeaconPayload(uint8_t offset, void *buffer, uint8_t bufferLength);

  /**
   * Signalled in response to a <code>modifyBeaconPayload()<\code> request.
   * Indicates that the beacon payload has been updated. 
   * 
   * @param offset        the <code>offset<\code> passed in the 
   *                      <code>modifyBeaconPayload()<\code> command
   * @param buffer        the <code>buffer<\code> passed in the 
   *                      <code>modifyBeaconPayload()<\code> command
   * @param bufferLength  the <code>bufferLength<\code> passed in the 
   *                      <code>modifyBeaconPayload()<\code> command
   */
 event void modifyBeaconPayloadDone(uint8_t offset, void *buffer, uint8_t bufferLength);

  /** 
   * Indicates that a beacon frame will be transmitted "soon" and now is a good
   * time to update the beacon payload (if desired).
   *
   * The usual policy is that (1) this event is signalled before every beacon
   * transmission, and (2) that a subsequent call to <code>setPayload<\code>
   * will update the beacon payload portion of this beacon.  However, 
   * because of tight timing constraints in beacon-enabled mode neither can be
   * guaranteed!
   */
 event void aboutToTransmit();  

  /** 
   * Indicates that a beacon frame has been transmitted (the 
   * <code>getBeaconPayload<\code> command can be used to inspect the
   * beacon payload).
   */
 event void beaconTransmitted();  
}



More information about the Tinyos-2-commits mailing list