A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
zigbee-aps-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Tokushima University, Japan
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors:
7 * Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
8 */
9
10#include "zigbee-aps-header.h"
11
12#include "ns3/address-utils.h"
13
14namespace ns3
15{
16namespace zigbee
17{
18
28
32
33void
38
41{
42 return m_frameType;
43}
44
45void
50
56
57void
59{
60 m_security = enabled;
61}
62
63bool
68
69void
71{
72 m_ackRequest = ack;
73}
74
75bool
80
81void
83{
84 m_extHeaderPresent = present;
85}
86
87bool
92
93void
95{
96 m_dstEndpoint = dst;
97}
98
99uint8_t
101{
102 return m_dstEndpoint;
103}
104
105void
107{
108 m_groupAddress = groupAddress;
109}
110
111uint16_t
116
117void
119{
120 m_clusterId = clusterId;
121}
122
123uint16_t
125{
126 return m_clusterId;
127}
128
129void
131{
132 m_profileId = profileId;
133}
134
135uint16_t
137{
138 return m_profileId;
139}
140
141void
143{
144 m_srcEndpoint = src;
145}
146
147uint8_t
149{
150 return m_srcEndpoint;
151}
152
153void
155{
156 m_apsCounter = counter;
157}
158
159uint8_t
161{
162 return m_apsCounter;
163}
164
165void
167{
168 Buffer::Iterator i = start;
169
170 // Frame control field
171 uint8_t frameControl = (m_frameType & 0x03) | ((m_deliveryMode & 0x03) << 2) |
172 ((m_ackFormat ? 1 : 0) << 4) | ((m_security ? 1 : 0) << 5) |
173 ((m_ackRequest ? 1 : 0) << 6) | ((m_extHeaderPresent ? 1 : 0) << 7);
174
175 i.WriteU8(frameControl);
176
177 // Addressing fields
178
180 {
182 }
183
185 {
187 }
188
190 {
193 }
194
196 {
198 }
199
201
202 // Extended Header
203
205 {
206 // Extended Frame control field
207 uint8_t extFrameControl = (m_fragmentation & 0x03);
208 i.WriteU8(extFrameControl);
209
210 // Block control
212 {
214 }
215 // ACK Bitfield
217 {
219 }
220 }
221}
222
225{
226 Buffer::Iterator i = start;
227
228 uint8_t frameControl = i.ReadU8();
229 m_frameType = static_cast<ApsFrameType>(frameControl & 0x03);
230 m_deliveryMode = static_cast<ApsDeliveryMode>((frameControl >> 2) & 0x03);
231 m_ackFormat = (frameControl >> 4) & 0x01;
232 m_security = (frameControl >> 5) & 0x01;
233 m_ackRequest = (frameControl >> 6) & 0x01;
234 m_extHeaderPresent = (frameControl >> 7) & 0x01;
235
236 // Addressing fields
237
239 {
240 m_dstEndpoint = i.ReadU8();
241 }
242
244 {
246 }
247
249 {
252 }
253
255 {
256 m_srcEndpoint = i.ReadU8();
257 }
258
259 m_apsCounter = i.ReadU8();
260
261 // Extended Header
262
264 {
265 // Extended Frame control field
266 uint8_t extFrameControl = i.ReadU8();
267 m_fragmentation = static_cast<ApsFragmentation>(extFrameControl & 0x03);
268
269 // Block control
271 {
272 m_blockNumber = i.ReadU8();
273 }
274 // ACK Bitfield
276 {
277 m_ackBitfield = i.ReadU8();
278 }
279 }
280
281 return i.GetDistanceFrom(start);
282}
283
286{
287 uint8_t totalSize;
288 // See Zigbee Specification r22.1.0
289
290 // Fixed field:
291 // Frame Control (1) + APS Counter (1)
292 totalSize = 2;
293
294 // Variable Fields:
295 // Destination EndPoint field (1) (Section 2.2.5.1.2)
297 {
298 totalSize += 1;
299 }
300
301 // Group Address field (2) (Section 2.2.5.1.3)
303 {
304 totalSize += 2;
305 }
306
307 // Cluster identifier field and Profile identifier field (4)
308 // (Sections 2.2.5.1.4 and 2.2.5.15)
310 {
311 totalSize += 4;
312 }
313
314 // Source Endpoint field (1) (Section 2.2.5.1.6)
316 {
317 totalSize += 1;
318 }
319
320 // Extended header sub-frame (variable)
322 {
323 // Extended Frame control field (1)
324 totalSize += 1;
325
326 // Block control (1)
328 {
329 totalSize += 1;
330 }
331 // ACK Bitfield
333 {
334 totalSize += 1;
335 }
336 }
337
338 return totalSize;
339}
340
341TypeId
343{
344 static TypeId tid = TypeId("ns3::zigbee::ZigbeeApsHeader")
345 .SetParent<Header>()
346 .SetGroupName("Zigbee")
347 .AddConstructor<ZigbeeApsHeader>();
348 return tid;
349}
350
351TypeId
353{
354 return GetTypeId();
355}
356
357void
358ZigbeeApsHeader::Print(std::ostream& os) const
359{
360 // TODO:
361 /* os << "\nAPS Frame Control = " << std::hex << std::showbase << static_cast<uint32_t>(
362 (m_frameType & 0x03) |
363 ((m_deliveryMode & 0x03) << 2) |
364 ((m_ackFormat ? 1 : 0) << 4) |
365 ((m_security ? 1 : 0) << 5) |
366 ((m_ackRequest ? 1 : 0) << 6) |
367 ((m_extHeader ? 1 : 0) << 7));
368
369 os << " | Dst EP = " << static_cast<uint32_t>(m_dstEndpoint)
370 << " | Src EP = " << static_cast<uint32_t>(m_srcEndpoint)
371 << " | Cluster ID = " << m_clusterId
372 << " | Profile ID = " << m_profileId
373 << " | Counter = " << static_cast<uint32_t>(m_counter);
374 os << "\n";*/
375}
376
377} // namespace zigbee
378} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteHtolsbU16(uint16_t data)
Definition buffer.cc:891
void WriteU8(uint8_t data)
Definition buffer.h:870
uint16_t ReadLsbtohU16()
Definition buffer.cc:1053
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
Protocol header serialization and deserialization.
Definition header.h:33
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Defines the APS header use by data transfer and commands issued from the APS layer.
void SetSecurity(bool enabled)
Set whether or not security should be used to transmit the frame.
void SetDstEndpoint(uint8_t endpoint)
Set the destination endpoint in the APS header.
uint16_t GetClusterId() const
Get the cluster id in the APS header.
void SetDeliveryMode(enum ApsDeliveryMode mode)
Defines the mode in which this frame should be transmitted.
bool IsExtHeaderPresent() const
Indicates whether or not the extended header is present in the frame.
void SetGroupAddress(uint16_t groupAddress)
Set the group address in the APS header.
void SetFrameType(enum ApsFrameType frameType)
Set the Frame type defined in the APS layer.
uint8_t m_blockNumber
Extended header field: Block number.
uint16_t GetGroupAddress() const
Get the group address in the APS header.
bool IsSecurityEnabled() const
Returns whether or not security is enabled for the present frame.alignas.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint16_t m_groupAddress
Addressing field: Group or 16-bit address.
ApsFragmentation m_fragmentation
Extended header field: Fragmentation block type.
void SetSrcEndpoint(uint8_t endpoint)
Set the source endpoint in the APS header.
void SetExtHeaderPresent(bool present)
Enables or disables the usage of the extended header.
uint8_t m_srcEndpoint
Addressing field: Source endpoint.
uint16_t m_clusterId
Addressing field: Cluster ID.
ApsDeliveryMode m_deliveryMode
Frame control field: Delivery mode.
uint16_t m_profileId
Addressing field: Profile ID.
ApsDeliveryMode GetDeliveryMode() const
Get the transmission mode set on the header.
bool m_extHeaderPresent
Frame control field: Extended header present.
uint8_t GetApsCounter() const
Get the APS counter value present in the APS header.
void SetApsCounter(uint8_t counter)
Set the value of the APS counter in the APS header.
void SetAckRequest(bool request)
Set the acknowledment flag in the APS header.
void SetClusterId(uint16_t clusterId)
Set the cluster id in the APS header.
bool m_ackFormat
Frame control field: Acknowledgment format.
uint32_t GetSerializedSize() const override
uint8_t GetSrcEndpoint() const
Get the source endpoint in the APS header.
uint8_t m_dstEndpoint
Addressing field: Destination endpoint.
uint32_t Deserialize(Buffer::Iterator start) override
uint8_t GetDstEndpoint() const
Get the destination endpoint in the APS header.
ApsFrameType GetFrameType() const
Get the frame time present in the header.
bool m_ackRequest
Frame control field: Acknowledge requested.
uint8_t m_apsCounter
APS counter field.
void Print(std::ostream &os) const override
bool m_security
Frame control field: Security.
uint8_t m_ackBitfield
Extended header field: Acknowledgement bit field.
bool IsAckRequested() const
Indicates if the present frame requires acknowledgment.
void SetProfileId(uint16_t profileId)
Set the profile ID in the APS header.
ApsFrameType m_frameType
Frame control field: Frame type.
void Serialize(Buffer::Iterator start) const override
static TypeId GetTypeId()
Get the type ID.
uint16_t GetProfileId() const
Get the profile ID in the APS header.
ApsFrameType
Values of the Frame Type Sub-Field.
ApsDeliveryMode
Values of the Delivery Mode Sub-Field.
ApsFragmentation
Table 2-22 Values of the Fragmentation Sub-Field Zigbee Specification r22.1.0, Table 2-22.
Every class exported by the ns3 library is enclosed in the ns3 namespace.