Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ieee802154.h Source File

ieee802154.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Definitions for IEEE 802.15.4 MAC frames
00004  */
00005 
00006 /*
00007  * Copyright (c) 2018 Simon Goldschmidt.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Simon Goldschmidt <goldsimon@gmx.de>
00035  *
00036  */
00037 #ifndef LWIP_HDR_NETIF_IEEE802154_H
00038 #define LWIP_HDR_NETIF_IEEE802154_H
00039 
00040 #include "lwip/opt.h"
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 #ifdef PACK_STRUCT_USE_INCLUDES
00047 #  include "arch/bpstruct.h"
00048 #endif
00049 PACK_STRUCT_BEGIN
00050 /** General MAC frame format
00051  * This shows the full featured header, mainly for documentation.
00052  * Some fields are omitted or shortened to achieve frame compression.
00053  */
00054 struct ieee_802154_hdr {
00055   /** See IEEE_802154_FC_* defines */
00056   PACK_STRUCT_FIELD(u16_t frame_control);
00057   /** Sequence number is omitted if IEEE_802154_FC_SEQNO_SUPPR is set in frame_control */
00058   PACK_STRUCT_FLD_8(u8_t  sequence_number);
00059   /** Destination PAN ID is omitted if Destination Addressing Mode is 0 */
00060   PACK_STRUCT_FIELD(u16_t destination_pan_id);
00061   /** Destination Address is omitted if Destination Addressing Mode is 0 */
00062   PACK_STRUCT_FLD_8(u8_t destination_address[8]);
00063   /** Source PAN ID is omitted if Source Addressing Mode is 0
00064       or if IEEE_802154_FC_PANID_COMPR is set in frame control*/
00065   PACK_STRUCT_FIELD(u16_t source_pan_id);
00066   /** Source Address is omitted if Source Addressing Mode is 0 */
00067   PACK_STRUCT_FLD_8(u8_t source_address[8]);
00068   /* The rest is variable */
00069 } PACK_STRUCT_STRUCT;
00070 PACK_STRUCT_END
00071 #ifdef PACK_STRUCT_USE_INCLUDES
00072 #  include "arch/epstruct.h"
00073 #endif
00074 
00075 /* Addressing modes (2 bits) */
00076 #define IEEE_802154_ADDR_MODE_NO_ADDR   0x00 /* PAN ID and address fields are not present */
00077 #define IEEE_802154_ADDR_MODE_RESERVED  0x01 /* Reserved */
00078 #define IEEE_802154_ADDR_MODE_SHORT     0x02 /* Address field contains a short address (16 bit) */
00079 #define IEEE_802154_ADDR_MODE_EXT       0x03 /* Address field contains an extended address (64 bit) */
00080 
00081 /* IEEE 802.15.4 Frame Control definitions (2 bytes; see IEEE 802.15.4-2015 ch. 7.2.1) */
00082 #define IEEE_802154_FC_FT_MASK             0x0007 /* bits 0..2: Frame Type */
00083 #define IEEE_802154_FC_FT_BEACON               0x00
00084 #define IEEE_802154_FC_FT_DATA                 0x01
00085 #define IEEE_802154_FC_FT_ACK                  0x02
00086 #define IEEE_802154_FC_FT_MAC_CMD              0x03
00087 #define IEEE_802154_FC_FT_RESERVED             0x04
00088 #define IEEE_802154_FC_FT_MULTIPURPOSE         0x05
00089 #define IEEE_802154_FC_FT_FRAG                 0x06
00090 #define IEEE_802154_FC_FT_EXT                  0x07
00091 #define IEEE_802154_FC_SEC_EN              0x0008 /* bit 3: Security Enabled */
00092 #define IEEE_802154_FC_FRAME_PEND          0x0010 /* bit 4: Frame Pending */
00093 #define IEEE_802154_FC_ACK_REQ             0x0020 /* bit 5: AR (ACK required) */
00094 #define IEEE_802154_FC_PANID_COMPR         0x0040 /* bit 6: PAN ID Compression (src and dst are equal, src PAN ID omitted) */
00095 #define IEEE_802154_FC_RESERVED            0x0080
00096 #define IEEE_802154_FC_SEQNO_SUPPR         0x0100 /* bit 8: Sequence Number Suppression */
00097 #define IEEE_802154_FC_IE_PRESENT          0x0200 /* bit 9: IE Present */
00098 #define IEEE_802154_FC_DST_ADDR_MODE_MASK  0x0c00 /* bits 10..11: Destination Addressing Mode */
00099 #define IEEE_802154_FC_DST_ADDR_MODE_NO_ADDR   (IEEE_802154_ADDR_MODE_NO_ADDR << 10)
00100 #define IEEE_802154_FC_DST_ADDR_MODE_SHORT     (IEEE_802154_ADDR_MODE_SHORT << 10)
00101 #define IEEE_802154_FC_DST_ADDR_MODE_EXT       (IEEE_802154_ADDR_MODE_EXT << 10)
00102 #define IEEE_802154_FC_FRAME_VERSION_MASK  0x3000 /* bits 12..13: Frame Version */
00103 #define IEEE_802154_FC_FRAME_VERSION_GET(x)    (((x) & IEEE_802154_FC_FRAME_VERSION_MASK) >> 12)
00104 #define IEEE_802154_FC_SRC_ADDR_MODE_MASK  0xc000 /* bits 14..15: Source Addressing Mode */
00105 #define IEEE_802154_FC_SRC_ADDR_MODE_SHORT     (IEEE_802154_ADDR_MODE_SHORT << 14)
00106 #define IEEE_802154_FC_SRC_ADDR_MODE_EXT       (IEEE_802154_ADDR_MODE_EXT << 14)
00107 
00108 #ifdef __cplusplus
00109 }
00110 #endif
00111 
00112 #endif /* LWIP_HDR_NETIF_IEEE802154_H */