Contiki 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 /** \} */
uint16_t macCoordShortAddress
The 16-bit short address assigned to the coordinator through which the network layer wishes to commun...
Definition: mac.c:104
int(* get_src_panid)(void)
Get the Source PAN_ID.
int(* get_coord_short_addr)(void)
Get the Coordinator Long address.
uint8_t radio_get_device_role(void)
This function will read the I_AM_COORD sub register.
Definition: radio.c:1056
void(* set_long_addr)(uint64_t address)
Set the Long Address.
Example glue code between the existing MAC code and the Contiki mac interface.
uint16_t macSrcPANId
The 16-bit identifier of the PAN on which the device is operating.
Definition: mac.c:128
int(* get_dst_panid)(void)
Get the Destination PAN_ID.
uint64_t(* get_long_addr)(void)
Get the Long Address.
int(* sleep)(void)
Turn the MAC layer off.
void(* set_dest_long_addr)(uint64_t address)
Set the Destination address.
void(* set_src_panid)(int panid)
Set the Source PAN_ID.
The interface structure for the 802.15.4 quasi-MAC.
void ieee_15_4_init(ieee_15_4_manager_t *pieee_15_4_manager)
initializes the 802.15.4 manager layer.
uint8_t radio_get_operating_channel(void)
This function will return the channel used by the radio transceiver.
Definition: radio.c:313
uint64_t(* get_dest_long_addr)(void)
Get the Destination address.
radio_status_t radio_leave_sleep_mode(void)
This function will take the radio transceiver from sleep mode and put it into the TRX_OFF state...
Definition: radio.c:932
void radio_get_extended_address(uint8_t *extended_address)
This function will read the extended address used by the address filter.
Definition: radio.c:1152
uint64_t macLongAddr
Our own long address.
Definition: mac.c:145
uint16_t radio_get_pan_id(void)
This function will return the PANID used by the address filter.
Definition: radio.c:1081
uint64_t macCoordExtendedAddress
The 64-bit address of the coordinator/router through which the network layer wishes to communicate...
Definition: mac.c:96
uint16_t radio_get_short_address(void)
This function will return the current short address used by the address filter.
Definition: radio.c:1115
void(* set_short_addr)(int address)
Set the Short Address.
void(* set_auto_mode)(bool mode)
Set the Automatic TRX modes.
uint64_t(* get_coord_long_addr)(void)
Get the Coordinator Long address.
void(* set_iamcoord_bit)(bool iamcoord)
Set the iAmCoord bit.
void(* set_dst_panid)(int panid)
Set the Destination PAN_ID.
radio_status_t radio_set_operating_channel(uint8_t channel)
This function will change the operating channel.
Definition: radio.c:329
void(* set_coord_short_addr)(int address)
Set the Coordinator Long address.
void radio_set_pan_id(uint16_t new_pan_id)
This function will set the PANID used by the address filter.
Definition: radio.c:1098
void radio_set_device_role(bool i_am_coordinator)
This function will set the I_AM_COORD sub register.
Definition: radio.c:1070
uint8_t phyCurrentChannel
The RF channel to use for all following transmissions and receptions (see 6.1.2). ...
Definition: mac.c:91
bool(* get_iamcoord_bit)(void)
Get the iAmCoord bit.
void radio_set_extended_address(uint8_t *extended_address)
This function will set a new extended address to be used by the address filter.
Definition: radio.c:1171
bool(* get_auto_mode)(void)
Get the current state of Automatic TRX modes.
int(* get_channel)(void)
Get the operating channel.
radio_status_t radio_enter_sleep_mode(void)
This function will put the radio transceiver to sleep.
Definition: radio.c:902
void(* set_channel)(int channel)
Set the operating channel.
uint64_t macDestAddress
This address is the 64-bit address that will be used as the mechanism to provide a destination to the...
Definition: mac.c:110
void radio_set_short_address(uint16_t new_short_address)
This function will set the short address used by the address filter.
Definition: radio.c:1132
The IEEE 802.15.4 (2003/2006) MAC utility functions.
int(* get_short_addr)(void)
Get the short Address.
void(* set_coord_long_addr)(uint64_t address)
Set the Coordinator Long address.
uint16_t macShortAddress
The 16-bit address that the device uses to communicate in the PAN.
Definition: mac.c:139
uint16_t macDstPANId
The 16-bit identifier of the PAN on which the device is sending to.
Definition: mac.c:122
int(* wake)(void)
Turn the MAC layer on.