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_clusterId = clusterId;
109}
110
111uint16_t
113{
114 return m_clusterId;
115}
116
117void
119{
120 m_profileId = profileId;
121}
122
123uint16_t
125{
126 return m_profileId;
127}
128
129void
131{
132 m_srcEndpoint = src;
133}
134
135uint8_t
137{
138 return m_srcEndpoint;
139}
140
141void
143{
144 m_apsCounter = counter;
145}
146
147uint8_t
149{
150 return m_apsCounter;
151}
152
153void
155{
156 Buffer::Iterator i = start;
157
158 // Frame control field
159 uint8_t frameControl = (m_frameType & 0x03) | ((m_deliveryMode & 0x03) << 2) |
160 ((m_ackFormat ? 1 : 0) << 4) | ((m_security ? 1 : 0) << 5) |
161 ((m_ackRequest ? 1 : 0) << 6) | ((m_extHeaderPresent ? 1 : 0) << 7);
162
163 i.WriteU8(frameControl);
164
165 // Addressing fields
166
168 {
170 }
171
173 {
175 }
176
178 {
181 }
182
184 {
186 }
187
189
190 // Extended Header
191
193 {
194 // Extended Frame control field
195 uint8_t extFrameControl = (m_fragmentation & 0x03);
196 i.WriteU8(extFrameControl);
197
198 // Block control
200 {
202 }
203 // ACK Bitfield
205 {
207 }
208 }
209}
210
213{
214 Buffer::Iterator i = start;
215
216 uint8_t frameControl = i.ReadU8();
217 m_frameType = static_cast<ApsFrameType>(frameControl & 0x03);
218 m_deliveryMode = static_cast<ApsDeliveryMode>((frameControl >> 2) & 0x03);
219 m_ackFormat = (frameControl >> 4) & 0x01;
220 m_security = (frameControl >> 5) & 0x01;
221 m_ackRequest = (frameControl >> 6) & 0x01;
222 m_extHeaderPresent = (frameControl >> 7) & 0x01;
223
224 // Addressing fields
225
227 {
228 m_dstEndpoint = i.ReadU8();
229 }
230
232 {
234 }
235
237 {
240 }
241
243 {
244 m_srcEndpoint = i.ReadU8();
245 }
246
247 m_apsCounter = i.ReadU8();
248
249 // Extended Header
250
252 {
253 // Extended Frame control field
254 uint8_t extFrameControl = i.ReadU8();
255 m_fragmentation = static_cast<ApsFragmentation>(extFrameControl & 0x03);
256
257 // Block control
259 {
260 m_blockNumber = i.ReadU8();
261 }
262 // ACK Bitfield
264 {
265 m_ackBitfield = i.ReadU8();
266 }
267 }
268
269 return i.GetDistanceFrom(start);
270}
271
274{
275 uint8_t totalSize;
276 // See Zigbee Specification r22.1.0
277
278 // Fixed field:
279 // Frame Control (1) + APS Counter (1)
280 totalSize = 2;
281
282 // Variable Fields:
283 // Destination EndPoint field (1) (Section 2.2.5.1.2)
285 {
286 totalSize += 1;
287 }
288
289 // Group Address field (2) (Section 2.2.5.1.3)
291 {
292 totalSize += 2;
293 }
294
295 // Cluster identifier field and Profile identifier field (4)
296 // (Sections 2.2.5.1.4 and 2.2.5.15)
298 {
299 totalSize += 4;
300 }
301
302 // Source Endpoint field (1) (Section 2.2.5.1.6)
304 {
305 totalSize += 1;
306 }
307
308 // Extended header sub-frame (variable)
310 {
311 // Extended Frame control field (1)
312 totalSize += 1;
313
314 // Block control (1)
316 {
317 totalSize += 1;
318 }
319 // ACK Bitfield
321 {
322 totalSize += 1;
323 }
324 }
325
326 return totalSize;
327}
328
329TypeId
331{
332 static TypeId tid = TypeId("ns3::zigbee::ZigbeeApsHeader")
333 .SetParent<Header>()
334 .SetGroupName("Zigbee")
335 .AddConstructor<ZigbeeApsHeader>();
336 return tid;
337}
338
339TypeId
341{
342 return GetTypeId();
343}
344
345void
346ZigbeeApsHeader::Print(std::ostream& os) const
347{
348 // TODO:
349 /* os << "\nAPS Frame Control = " << std::hex << std::showbase << static_cast<uint32_t>(
350 (m_frameType & 0x03) |
351 ((m_deliveryMode & 0x03) << 2) |
352 ((m_ackFormat ? 1 : 0) << 4) |
353 ((m_security ? 1 : 0) << 5) |
354 ((m_ackRequest ? 1 : 0) << 6) |
355 ((m_extHeader ? 1 : 0) << 7));
356
357 os << " | Dst EP = " << static_cast<uint32_t>(m_dstEndpoint)
358 << " | Src EP = " << static_cast<uint32_t>(m_srcEndpoint)
359 << " | Cluster ID = " << m_clusterId
360 << " | Profile ID = " << m_profileId
361 << " | Counter = " << static_cast<uint32_t>(m_counter);
362 os << "\n";*/
363}
364
365} // namespace zigbee
366} // 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 SetFrameType(enum ApsFrameType frameType)
Set the Frame type defined in the APS layer.
uint8_t m_blockNumber
Extended header field: Block number.
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.