Contiki 2.5
zmac.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, Swedish Institute of Computer Science
2  * All rights reserved.
3  *
4  * Additional fixes for AVR contributed by:
5  *
6  * Colin O'Flynn coflynn@newae.com
7  * Eric Gnoske egnoske@gmail.com
8  * Blake Leverett bleverett@gmail.com
9  * Mike Vidales mavida404@gmail.com
10  * Kevin Brown kbrown3@uccs.edu
11  * Nate Bohlmann nate@elfwerks.com
12  *
13  * All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are met:
17  *
18  * * Redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer.
20  * * Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in
22  * the documentation and/or other materials provided with the
23  * distribution.
24  * * Neither the name of the copyright holders nor the names of
25  * contributors may be used to endorse or promote products derived
26  * from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 /**
41  * \brief The equivalent IEEE 802.15.4 (2003/2006) header file for
42  * the mac primitives.
43  *
44  */
45 /**
46  * \addtogroup rf230mac
47  * @{
48 */
49 /**
50  * \file
51  * \brief The IEEE 802.15.4 (2003/2006) MAC utility functions.
52  */
53 
54 #ifndef MAC_H
55 #define MAC_H
56 
57 /* Includes */
58 #include <stdint.h>
59 #include <stdbool.h>
60 #include "frame.h"
61 #include "ieee-15-4-manager.h"
62 
63 #define EEPROMMACADDRESS ((void*)0)
64 #define EEPROMDSTADDRESS ((void*)8)
65 #define EEPROMCHANADDRESS ((void*)16)
66 #define EEPROMPANIDADDRESS ((void*)17)
67 #define EEPROMROLEADDRESS ((void*)19)
68 #define SUCCESS (0)
69 #define CHANNEL_PAGE_0 (0)
70 
71 
72 
73 
74 /* MAC command frames codes */
75 
76 /* MAC enumerations */
77 /** \brief Pre-defined data frame control field (FCF) values.
78  * \name FCF Values
79  * @{
80 */
81 #define FCF_NO_ACK (0x8841)
82 #define FCF_ACK_REQ (0x8861)
83 /** @} */
84 
85 /** \brief Hardcoded various "network" addresses, for use when testing.
86  * \name Pre-defined network addresses
87  * @{
88  */
89 #define DEST_PAN_ID (0xABCD)
90 #define SOURCE_PAN_ID (0xABCD)
91 #define LONG_ADDR_1 (0xFFEEDDCCBBAA1100LL)
92 #define LONG_ADDR_2 (0x1122334455667788LL)
93 #define LONG_ADDR_3 (0xDDEEAADDBBEEEEFFLL)
94 #define LONG_ADDR_4 (0x0123456789ABCDEFLL)
95 #define SOURCE_ADDR (0x1234)
96 #define FCF_ACK (0x0002)
97 #define TX_OPTION_NOACK (0)
98 #define TX_OPTION_ACK (1)
99 #define LONG_ADDR_LEN (8)
100 /** @} */
101 
102 #define MPDU_OVERHEAD (11) /**< This overhead includes FCF, DSN, DEST_PAN_ID, DEST_ADDR, SOURCE_ADDR, & FCS */
103 
104 
105 /** \brief These are some definitions of values used in the FCF. See the 802.15.4 spec for details.
106  * \name FCF element values definitions
107  * @{
108  */
109 #define BEACONFRAME (0x00)
110 #define DATAFRAME (0x01)
111 #define ACKFRAME (0x02)
112 #define CMDFRAME (0x03)
113 
114 #define BEACONREQ (0x07)
115 
116 #define IEEERESERVED (0x00)
117 #define NOADDR (0x00) /**< Only valid for ACK or Beacon frames. */
118 #define SHORTADDRMODE (0x02)
119 #define LONGADDRMODE (0x03)
120 
121 #define NOBEACONS (0x0F)
122 
123 #define BROADCASTADDR (0xFFFF)
124 #define BROADCASTPANDID (0xFFFF)
125 
126 #define IEEE802154_2003 (0x00)
127 #define IEEE802154_2006 (0x01)
128 
129 #define SECURITY_LEVEL_NONE (0)
130 #define SECURITY_LEVEL_128 (3)
131 
132 #define PSDULEN (127)
133 /** @} */
134 
135 
136 /* typedef enum {TRUE, FALSE} bool; */
137 
138 typedef struct dataRequest {
139  uint8_t srcAddrMode;
140  uint8_t dstAddrMode;
141  uint16_t dstPANId;
142  addr_t dstAddr;
143  uint8_t msduLength;
144  uint8_t *msdu;
145  uint8_t msduHandle;
146  uint8_t txOptions;
147  uint8_t securityLevel;
148  uint8_t keyIdMode;
149  uint8_t *keySource;
150  uint8_t keyIndex;
151 } dataRequest_t;
152 
153 
154 /* Macros & Defines */
156 extern dataRequest_t dataRequestStructAddress;
157 #define ieee15_4Struct (&ieee15_4ManagerAddress)
158 #define dataRequestStruct (&dataRequestStructAddress)
159 
160 
161 /**
162  * \name Scan variables
163  * \brief Global variables and defines for scan.
164  * \{
165 */
166 extern uint8_t msduHandle;
167 extern bool iAmCoord;
168 extern bool autoModes;
169 extern uint16_t macShortAddr;
170 extern uint64_t macLongAddr;
171 /** @} */
172 
173 /* PHY PIB Attributes */
174 
175 /* uint8_t phyCurrentChannel Integer 0-26
176  * The RF channel to use for all following transmissions and receptions (see6.1.2).
177  */
178 extern uint8_t phyCurrentChannel;
179 
180 /* uint64_t macCoordExtendedAddress -- no default
181  *
182  * The 64-bit address of the coordinator/router through which the network layer wishes to communicate
183  */
184 extern uint64_t macCoordExtendedAddress;
185 
186 /* uint16_t macCoordShortAddress -- default 0xffff
187  *
188  * The 16-bit short address assigned to the coordinator through which the network layer wishes
189  * to communicate. A value of 0xfffe indicates th the coordinator is only using it's 64-bit
190  * extended address. A value of 0xffff indicates that this value is unknown.
191  */
192 extern uint16_t macCoordShortAddress;
193 
194 /* uint64_t macDestAddress -- default 0xffff
195  *
196  * This address is the 64-bit address that will be used as the mechanism to
197  * provide a destination to the upper layers.
198  */
199 extern uint64_t macDestAddress;
200 
201 /* uint8_t macDSN -- default is random value within the range
202  *
203  * The sequence number (0x00 - 0xff) added to the transmitted data or MAC command frame.
204  */
205 extern uint8_t macDSN;
206 
207 /* uint16_t macDstPANId -- default 0xffff
208  *
209  * The 16-bit identifier of the PAN on which the device is sending to. If this value
210  * is 0xffff, the device is not associated.
211  */
212 extern uint16_t macDstPANId;
213 
214 /* uint16_t macSrcPANId -- default 0xffff
215  *
216  * The 16-bit identifier of the PAN on which the device is operating. If this value
217  * is 0xffff, the device is not associated.
218  */
219 extern uint16_t macSrcPANId;
220 
221 /* uint16_t macShortAddress -- default 0xffff
222  *
223  * The 16-bit address that the device uses to communicate in the PAN. If the device is the
224  * PAN coordinator, this value shall be chosen before a PAN is started. Otherwise, the
225  * address is allocated by a coordinator during association. A value of 0xfffe indicates
226  * that the device has associated but has not been allocated an address. A value of 0xffff
227  * indicates that the device does not have a short address.
228  */
229 extern uint16_t macShortAddress;
230 
231 /* Scan defines */
232 
233 
234 /* Protoypes */
235 void mac_init(void);
236 
237 #endif
238 
239 /** @} */