Contiki-Inga 3.x
ieee-15-4-manager.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  *
35  * \addtogroup rf230mac
36  * \{
37  */
38 
39 /**
40  * \file
41  * \brief Interfaces the 802.15.4 MAC to upper network layers.
42  *
43  * \author
44  * Mike Vidales <mavida404@gmail.com>
45  */
46 
47 #include "zmac.h"
48 #include "radio.h"
49 #include "ieee-15-4-manager.h"
50 
51 /*---------------------------------------------------------------------------*/
52 static int
53 wake(void)
54 {
55  /* Wake the radio. */
56  return radio_leave_sleep_mode();
57 }
58 /*---------------------------------------------------------------------------*/
59 static int
60 sleep(void)
61 {
62  /* Sleep the radio. */
63  return radio_enter_sleep_mode();
64 }
65 /*---------------------------------------------------------------------------*/
66 static void
67 set_channel(int channel)
68 {
69  /* Set the channel. */
70  phyCurrentChannel = channel;
72 }
73 /*---------------------------------------------------------------------------*/
74 static int
75 get_channel(void)
76 {
77  /* Reads the current channel. */
79  return phyCurrentChannel;
80 }
81 /*---------------------------------------------------------------------------*/
82 static void
83 set_dst_panid(int panid)
84 {
85  macDstPANId = panid;
86 }
87 /*---------------------------------------------------------------------------*/
88 static int
89 get_dst_panid(void)
90 {
91  return macDstPANId;
92 }
93 /*---------------------------------------------------------------------------*/
94 static void
95 set_src_panid(int panid)
96 {
97  /* Writes the PAN_ID to the radio. */
98  macSrcPANId = panid;
100 }
101 /*---------------------------------------------------------------------------*/
102 static int
103 get_src_panid(void)
104 {
105  /* Gets the PAN_ID from the radio. */
107  return macSrcPANId;
108 }
109 /*---------------------------------------------------------------------------*/
110 static void
111 set_auto_mode(bool mode)
112 {
113  autoModes = mode;
114 }
115 /*---------------------------------------------------------------------------*/
116 static bool
117 get_auto_mode(void)
118 {
119  return autoModes;
120 }
121 /*---------------------------------------------------------------------------*/
122 static void
123 set_long_addr(uint64_t address)
124 {
125  /* Set the Long address in the radio. */
126  macLongAddr = address;
128 }
129 /*---------------------------------------------------------------------------*/
130 static uint64_t
131 get_long_addr(void)
132 {
133  /* Get the Long address from the radio. */
135  return macLongAddr;
136 }
137 /*---------------------------------------------------------------------------*/
138 static void
139 set_short_addr(int address)
140 {
141  /* Set the Short address in the radio. */
142  macShortAddress = address;
144 }
145 /*---------------------------------------------------------------------------*/
146 static int
147 get_short_addr(void)
148 {
149  /* Get the Short address from the radio. */
151  return macShortAddress;
152 }
153 /*---------------------------------------------------------------------------*/
154 static void
155 set_iamcoord_bit(bool iamcoord)
156 {
157  /** Set the iAmCoord bit. */
158  iAmCoord = iamcoord;
159  radio_set_device_role(iAmCoord);
160 }
161 /*---------------------------------------------------------------------------*/
162 static bool
163 get_iamcoord_bit(void)
164 {
165  /** Get the iAmCoord bit. */
166  iAmCoord = radio_get_device_role();
167  return iAmCoord;
168 }
169 /*---------------------------------------------------------------------------*/
170 static void
171 set_coord_long_addr(uint64_t address)
172 {
173  macCoordExtendedAddress = address;
174 }
175 /*---------------------------------------------------------------------------*/
176 static uint64_t
177 get_coord_long_addr(void)
178 {
180 }
181 /*---------------------------------------------------------------------------*/
182 static void
183 set_coord_short_addr(int address)
184 {
185  macCoordShortAddress = address;
186 }
187 /*---------------------------------------------------------------------------*/
188 static int
189 get_coord_short_addr(void)
190 {
191  return macCoordShortAddress;
192 }
193 /*---------------------------------------------------------------------------*/
194 static void
195 set_dest_long_addr(uint64_t address)
196 {
197  macDestAddress = address;
198 }
199 /*---------------------------------------------------------------------------*/
200 static uint64_t
201 get_dest_long_addr(void)
202 {
203  return macDestAddress;
204 }
205 /*---------------------------------------------------------------------------*/
206 /** \brief initializes the 802.15.4 manager layer.
207  * \param pieee_15_4_manager Pointer to \ref ieee_15_4_manager
208  */
209 void ieee_15_4_init(ieee_15_4_manager_t *pieee_15_4_manager)
210 {
211 /* Initialize the IEEE 15.4 manager. */
212  pieee_15_4_manager->wake = wake;
213  pieee_15_4_manager->sleep = sleep;
214  pieee_15_4_manager->set_channel = set_channel;
215  pieee_15_4_manager->get_channel = get_channel;
216  pieee_15_4_manager->set_dst_panid = set_dst_panid;
217  pieee_15_4_manager->get_dst_panid = get_dst_panid;
218  pieee_15_4_manager->set_src_panid = set_src_panid;
219  pieee_15_4_manager->get_src_panid = get_src_panid;
220  pieee_15_4_manager->set_auto_mode = set_auto_mode;
221  pieee_15_4_manager->get_auto_mode = get_auto_mode;
222  pieee_15_4_manager->set_long_addr = set_long_addr;
223  pieee_15_4_manager->get_long_addr = get_long_addr;
224  pieee_15_4_manager->set_short_addr = set_short_addr;
225  pieee_15_4_manager->get_short_addr = get_short_addr;
226  pieee_15_4_manager->set_iamcoord_bit = set_iamcoord_bit;
227  pieee_15_4_manager->get_iamcoord_bit = get_iamcoord_bit;
228  pieee_15_4_manager->set_coord_long_addr = set_coord_long_addr;
229  pieee_15_4_manager->get_coord_long_addr = get_coord_long_addr;
230  pieee_15_4_manager->set_coord_short_addr = set_coord_short_addr;
231  pieee_15_4_manager->get_coord_short_addr = get_coord_short_addr;
232  pieee_15_4_manager->set_dest_long_addr = set_dest_long_addr;
233  pieee_15_4_manager->get_dest_long_addr = get_dest_long_addr;
234 }
235 
236 /** \} */