Serializes a cPacket for transmission on the wire.
Returns the length of data written into buffer.
49 if (dynamic_cast<const Ieee80211ACKFrame *>(pkt))
51 const Ieee80211ACKFrame *ackFrame =
static_cast<const Ieee80211ACKFrame *
>(pkt);
54 b.writeUint16(ackFrame->getDuration().inUnit(SIMTIME_MS));
55 b.writeMACAddress(ackFrame->getReceiverAddress());
57 else if (dynamic_cast<const Ieee80211RTSFrame *>(pkt))
59 const Ieee80211RTSFrame *rtsFrame =
static_cast<const Ieee80211RTSFrame *
>(pkt);
62 b.writeUint16(rtsFrame->getDuration().inUnit(SIMTIME_MS));
63 b.writeMACAddress(rtsFrame->getReceiverAddress());
64 b.writeMACAddress(rtsFrame->getTransmitterAddress());
66 else if (dynamic_cast<const Ieee80211CTSFrame *>(pkt))
68 const Ieee80211CTSFrame *ctsFrame =
static_cast<const Ieee80211CTSFrame *
>(pkt);
71 b.writeUint16(ctsFrame->getDuration().inUnit(SIMTIME_MS));
72 b.writeMACAddress(ctsFrame->getReceiverAddress());
74 else if (dynamic_cast<const Ieee80211DataOrMgmtFrame *>(pkt))
76 const Ieee80211DataOrMgmtFrame *dataOrMgmtFrame =
static_cast<const Ieee80211DataOrMgmtFrame *
>(pkt);
81 fc1 = (dataOrMgmtFrame->getRetry() ? 8 : 0)
82 | (dataOrMgmtFrame->getMoreFragments() ? 4 : 0)
83 | (dataOrMgmtFrame->getFromDS() ? 2 : 0)
84 | (dataOrMgmtFrame->getToDS() ? 1 : 0);
86 b.writeUint16(dataOrMgmtFrame->getDuration().inUnit(SIMTIME_MS));
87 b.writeMACAddress(dataOrMgmtFrame->getReceiverAddress());
88 b.writeMACAddress(dataOrMgmtFrame->getTransmitterAddress());
89 b.writeMACAddress(dataOrMgmtFrame->getAddress3());
90 b.writeUint16(dataOrMgmtFrame->getSequenceNumber() << 4
91 | dataOrMgmtFrame->getFragmentNumber());
94 if (dynamic_cast<const Ieee80211DataFrameWithSNAP *>(pkt))
96 const Ieee80211DataFrameWithSNAP *dataFrame =
static_cast<const Ieee80211DataFrameWithSNAP *
>(pkt);
97 if (dataFrame->getFromDS() && dataFrame->getToDS())
99 b.writeMACAddress(dataFrame->getAddress4());
102 b.writeUint16(dataFrame->getQos());
109 b.writeNBytes(3,
"\0\0\0");
110 b.writeUint16(dataFrame->getEtherType());
112 const cPacket *encapPacket = dataFrame->getEncapsulatedPacket();
115 else if (dynamic_cast<const Ieee80211AuthenticationFrame *>(pkt))
118 const Ieee80211AuthenticationFrame *Frame =
static_cast<const Ieee80211AuthenticationFrame *
>(pkt);
122 b.writeUint16(Frame->getBody().getSequenceNumber());
124 b.writeUint16(Frame->getBody().getStatusCode());
128 else if (dynamic_cast<const Ieee80211DeauthenticationFrame *>(pkt))
131 const Ieee80211DeauthenticationFrame *Frame =
static_cast<const Ieee80211DeauthenticationFrame *
>(pkt);
132 b.writeUint16(Frame->getBody().getReasonCode());
134 else if (dynamic_cast<const Ieee80211DisassociationFrame *>(pkt))
137 const Ieee80211DisassociationFrame *Frame =
static_cast<const Ieee80211DisassociationFrame *
>(pkt);
138 b.writeUint16(Frame->getBody().getReasonCode());
140 else if (dynamic_cast<const Ieee80211ProbeRequestFrame *>(pkt))
143 const Ieee80211ProbeRequestFrame *Frame =
static_cast<const Ieee80211ProbeRequestFrame *
>(pkt);
145 const char *SSID = Frame->getBody().getSSID();
146 unsigned int length = strlen(SSID);
149 b.writeNBytes(length, SSID);
151 const Ieee80211SupportedRatesElement& supportedRates = Frame->getBody().getSupportedRates();
153 b.writeByte(supportedRates.numRates);
154 for (
int i = 0; i < supportedRates.numRates; i++)
156 uint8_t rate = ceil(supportedRates.rate[i]/0.5);
164 else if (dynamic_cast<const Ieee80211AssociationRequestFrame *>(pkt))
167 const Ieee80211AssociationRequestFrame *Frame =
static_cast<const Ieee80211AssociationRequestFrame *
>(pkt);
173 const char *SSID = Frame->getBody().getSSID();
174 unsigned int length = strlen(SSID);
177 b.writeNBytes(length, SSID);
179 const Ieee80211SupportedRatesElement& supportedRates = Frame->getBody().getSupportedRates();
181 b.writeByte(supportedRates.numRates);
182 for (
int i = 0; i < supportedRates.numRates; i++) {
183 uint8_t rate = ceil(supportedRates.rate[i]/0.5);
194 else if (dynamic_cast<const Ieee80211ReassociationRequestFrame *>(pkt))
197 const Ieee80211ReassociationRequestFrame *Frame =
dynamic_cast<const Ieee80211ReassociationRequestFrame *
>(pkt);
203 b.writeMACAddress(Frame->getBody().getCurrentAP());
205 const char *SSID = Frame->getBody().getSSID();
206 unsigned int length = strlen(SSID);
210 b.writeNBytes(length, SSID);
212 const Ieee80211SupportedRatesElement& supportedRates = Frame->getBody().getSupportedRates();
214 b.writeByte(supportedRates.numRates);
215 for (
int i = 0; i < supportedRates.numRates; i++)
217 uint8_t rate = ceil(supportedRates.rate[i]/0.5);
228 else if (dynamic_cast<const Ieee80211AssociationResponseFrame *>(pkt))
231 const Ieee80211AssociationResponseFrame *Frame =
static_cast<const Ieee80211AssociationResponseFrame *
>(pkt);
235 b.writeUint16(Frame->getBody().getStatusCode());
237 b.writeUint16(Frame->getBody().getAid());
240 b.writeByte(Frame->getBody().getSupportedRates().numRates);
241 for (
int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
243 uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
251 else if (dynamic_cast<const Ieee80211ReassociationResponseFrame *>(pkt))
254 const Ieee80211ReassociationResponseFrame *Frame =
dynamic_cast<const Ieee80211ReassociationResponseFrame *
>(pkt);
258 b.writeUint16(Frame->getBody().getStatusCode());
260 b.writeUint16(Frame->getBody().getAid());
263 b.writeByte(Frame->getBody().getSupportedRates().numRates);
264 for (
int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
266 uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
274 else if (dynamic_cast<const Ieee80211BeaconFrame *>(pkt))
277 const Ieee80211BeaconFrame *Frame =
static_cast<const Ieee80211BeaconFrame *
>(pkt);
279 b.writeUint64(Frame->getTimestamp().raw());
281 b.writeUint16((uint16_t)(Frame->getBody().getBeaconInterval().inUnit(SIMTIME_US)/1024));
285 const char *SSID = Frame->getBody().getSSID();
286 unsigned int length = strlen(SSID);
289 b.writeNBytes(length, SSID);
292 b.writeByte(Frame->getBody().getSupportedRates().numRates);
293 for (
int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
295 uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
320 else if (dynamic_cast<const Ieee80211ProbeResponseFrame *>(pkt))
323 const Ieee80211ProbeResponseFrame *Frame =
static_cast<const Ieee80211ProbeResponseFrame *
>(pkt);
325 b.writeUint64(Frame->getTimestamp().raw());
327 b.writeUint16((uint16_t)(Frame->getBody().getBeaconInterval().inUnit(SIMTIME_US)/1024));
331 const char *SSID = Frame->getBody().getSSID();
332 unsigned int length = strlen(SSID);
335 b.writeNBytes(length, SSID);
338 b.writeByte(Frame->getBody().getSupportedRates().numRates);
339 for (
int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
341 uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
366 else if (dynamic_cast<const Ieee80211ActionFrame *>(pkt))
374 throw cRuntimeError(
"Ieee80211Serializer: cannot serialize the frame");
Definition: SerializerBase.h:39
uint32_t ethernetCRC(const unsigned char *buf, unsigned int bufsize)
Definition: EthernetCRC.cc:67
Definition: Ieee80211Frame_m.h:117
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
static void lookupAndSerialize(const cPacket *pkt, Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
Definition: SerializerBase.cc:88
value< double, units::m > b
Definition: Units.h:1054