INET Framework for OMNeT++/OMNEST
inet::serializer::Ieee80211Serializer Class Reference

Converts between Ieee802.11Frame and binary (network byte order) Ieee802.11 header. More...

#include <Ieee80211Serializer.h>

Inheritance diagram for inet::serializer::Ieee80211Serializer:
inet::serializer::SerializerBase

Public Member Functions

 Ieee80211Serializer (const char *name=nullptr)
 
- Public Member Functions inherited from inet::serializer::SerializerBase
 SerializerBase (const char *name=nullptr)
 
void serializePacket (const cPacket *pkt, Buffer &b, Context &context)
 
cPacket * deserializePacket (const Buffer &b, Context &context)
 

Protected Member Functions

void parseDataOrMgmtFrame (const Buffer &b, inet::ieee80211::Ieee80211DataOrMgmtFrame *Frame, short type)
 
virtual void serialize (const cPacket *pkt, Buffer &b, Context &context) override
 Serializes a cPacket for transmission on the wire. More...
 
virtual cPacket * deserialize (const Buffer &b, Context &context) override
 Puts a packet sniffed from the wire into an EtherFrame. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from inet::serializer::SerializerBase
static SerializerBaselookupSerializer (const cPacket *pkt, Context &context, ProtocolGroup group, int id)
 
static void lookupAndSerialize (const cPacket *pkt, Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 
static SerializerBaselookupDeserializer (Context &context, ProtocolGroup group, int id)
 
static cPacket * lookupAndDeserialize (const Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 

Detailed Description

Converts between Ieee802.11Frame and binary (network byte order) Ieee802.11 header.

Constructor & Destructor Documentation

inet::serializer::Ieee80211Serializer::Ieee80211Serializer ( const char *  name = nullptr)
inline
42 : SerializerBase(name) {}
SerializerBase(const char *name=nullptr)
Definition: SerializerBase.h:84

Member Function Documentation

cPacket * inet::serializer::Ieee80211Serializer::deserialize ( const Buffer b,
Context context 
)
overrideprotectedvirtual

Puts a packet sniffed from the wire into an EtherFrame.

Implements inet::serializer::SerializerBase.

408 {
409  ASSERT(b.getPos() == 0);
410  cPacket *frame = nullptr;
411 
412  uint8_t type = b.readByte();
413  uint8_t fc_1 = b.readByte(); (void)fc_1; // fc_1
414  switch(type)
415  {
416  case 0xD4: // ST_ACK //TODO ((ST_ACK & 0x0F) << 4) | ((ST_ACK & 0x30) >> 2)
417  {
418  Ieee80211ACKFrame *ackFrame = new Ieee80211ACKFrame();
419  ackFrame->setType(ST_ACK);
420  ackFrame->setToDS(false);
421  ackFrame->setFromDS(false);
422  ackFrame->setRetry(false);
423  ackFrame->setMoreFragments(false);
424  ackFrame->setDuration(SimTime((double)b.readUint16()/1000.0)); //i_dur
425  ackFrame->setReceiverAddress(b.readMACAddress());
426  frame = ackFrame;
427  break;
428  }
429  case 0xB4: // ST_RTS
430  {
431  Ieee80211RTSFrame *rtsFrame = new Ieee80211RTSFrame();
432  rtsFrame->setType(ST_RTS);
433  rtsFrame->setToDS(false);
434  rtsFrame->setFromDS(false);
435  rtsFrame->setRetry(false);
436  rtsFrame->setMoreFragments(false);
437  rtsFrame->setDuration(SimTime(b.readUint16(), SIMTIME_MS)); //i_dur
438  rtsFrame->setReceiverAddress(b.readMACAddress());
439  rtsFrame->setTransmitterAddress(b.readMACAddress());
440  frame = rtsFrame;
441  break;
442  }
443  case 0xC4: // ST_CTS
444  {
445  Ieee80211CTSFrame *ctsFrame = new Ieee80211CTSFrame();
446  ctsFrame->setType(ST_CTS);
447  ctsFrame->setToDS(false);
448  ctsFrame->setFromDS(false);
449  ctsFrame->setRetry(false);
450  ctsFrame->setMoreFragments(false);
451  ctsFrame->setDuration(SimTime(b.readUint16(),SIMTIME_MS)); //i_dur
452  ctsFrame->setReceiverAddress(b.readMACAddress());
453  frame = ctsFrame;
454  break;
455  }
456  case 0x08: // ST_DATA
457  case 0x88: // ST_DATA_WITH_QOS
458  {
459  Ieee80211DataFrameWithSNAP *dataFrame = new Ieee80211DataFrameWithSNAP();
460  parseDataOrMgmtFrame(b, dataFrame, type == 0x08 ? ST_DATA : ST_DATA_WITH_QOS);
461 
462  // snap_header:
463  b.accessNBytes(6);
464  dataFrame->setEtherType(b.readUint16()); // ethertype
465 
466  cPacket *encapPacket = SerializerBase::lookupAndDeserialize(b, c, ETHERTYPE, dataFrame->getEtherType(), b.getRemainingSize(4));
467  if (encapPacket) {
468  dataFrame->encapsulate(encapPacket);
469  dataFrame->setName(encapPacket->getName());
470  }
471  frame = dataFrame;
472  break;
473  }
474 
475  case 0xB0: // ST_AUTHENTICATION
476  {
477  Ieee80211AuthenticationFrame *pkt = new Ieee80211AuthenticationFrame();
479  Ieee80211AuthenticationFrameBody body;
480  b.readUint16();
481  body.setSequenceNumber(b.readUint16());
482  body.setStatusCode(b.readUint16());
483 
484  pkt->setBody(body);
485  frame = pkt;
486  break;
487  }
488 
489  case 0xC0: //ST_ST_DEAUTHENTICATION
490  {
491  Ieee80211DeauthenticationFrame *pkt = new Ieee80211DeauthenticationFrame();
493  Ieee80211DeauthenticationFrameBody body;
494 
495  body.setReasonCode(b.readUint16());
496 
497  pkt->setBody(body);
498  frame = pkt;
499  break;
500  }
501 
502  case 0xA0: // ST_DISASSOCIATION
503  {
504  Ieee80211DisassociationFrame *pkt = new Ieee80211DisassociationFrame();
506  Ieee80211DisassociationFrameBody body;
507 
508  body.setReasonCode(b.readUint16());
509 
510  pkt->setBody(body);
511  frame = pkt;
512  break;
513  }
514 
515  case 0x40: // ST_PROBEREQUEST
516  {
517  Ieee80211ProbeRequestFrame *pkt = new Ieee80211ProbeRequestFrame();
519  Ieee80211ProbeRequestFrameBody body;
520 
521  char SSID[256];
522  b.readByte();
523  unsigned int length = b.readByte();
524  b.readNBytes(length, SSID);
525  SSID[length] = '\0';
526  body.setSSID(SSID);
527 
528  Ieee80211SupportedRatesElement supRat;
529  b.readByte();
530  supRat.numRates = b.readByte();
531  for (int i = 0; i < supRat.numRates; i++)
532  supRat.rate[i] = (double)(b.readByte() & 0x7F) * 0.5;
533  body.setSupportedRates(supRat);
534 
535  pkt->setBody(body);
536  frame = pkt;
537  break;
538  }
539 
540  case 0x00: // ST_ASSOCIATIONREQUEST
541  {
542  Ieee80211AssociationRequestFrame *pkt = new Ieee80211AssociationRequestFrame;
544  Ieee80211AssociationRequestFrameBody body;
545 
546  char SSID[256];
547  b.readByte();
548  unsigned int length = b.readByte();
549  b.readNBytes(length, SSID);
550  SSID[length] = '\0';
551  body.setSSID(SSID);
552 
553  Ieee80211SupportedRatesElement supRat;
554  b.readByte();
555  supRat.numRates = b.readByte();
556  for (int i = 0; i < supRat.numRates; i++)
557  supRat.rate[i] = (double)(b.readByte() & 0x7F) * 0.5;
558  body.setSupportedRates(supRat);
559 
560  pkt->setBody(body);
561  frame = pkt;
562  break;
563  }
564 
565  case 0x02: // ST_REASSOCIATIONREQUEST
566  {
567  Ieee80211ReassociationRequestFrame *pkt = new Ieee80211ReassociationRequestFrame;
569  Ieee80211ReassociationRequestFrameBody body;
570  b.readUint16();
571  b.readUint16();
572 
573  body.setCurrentAP(b.readMACAddress());
574 
575  char SSID[256];
576  b.readByte();
577  unsigned int length = b.readByte();
578  b.readNBytes(length, SSID);
579  SSID[length] = '\0';
580  body.setSSID(SSID);
581 
582  Ieee80211SupportedRatesElement supRat;
583  b.readByte();
584  supRat.numRates = b.readByte();
585  for (int i = 0; i < supRat.numRates; i++)
586  supRat.rate[i] = (double)(b.readByte() & 0x7F) * 0.5;
587  body.setSupportedRates(supRat);
588 
589  pkt->setBody(body);
590  frame = pkt;
591  break;
592  }
593 
594  case 0x01: // ST_ASSOCIATIONRESPONSE
595  {
596  Ieee80211AssociationResponseFrame *pkt = new Ieee80211AssociationResponseFrame;
598  Ieee80211AssociationResponseFrameBody body;
599  b.readUint16();
600  body.setStatusCode(b.readUint16());
601  body.setAid(b.readUint16());
602 
603  Ieee80211SupportedRatesElement supRat;
604  b.readByte();
605  supRat.numRates = b.readByte();
606  for (int i = 0; i < supRat.numRates; i++)
607  supRat.rate[i] = (double)(b.readByte() & 0x7F) * 0.5;
608  body.setSupportedRates(supRat);
609 
610  pkt->setBody(body);
611  frame = pkt;
612  break;
613  }
614 
615  case 0x03: // ST_REASSOCIATIONRESPONSE
616  {
617  Ieee80211ReassociationResponseFrame *pkt = new Ieee80211ReassociationResponseFrame;
619  Ieee80211ReassociationResponseFrameBody body;
620  b.readUint16();
621  body.setStatusCode(b.readUint16());
622  body.setAid(b.readUint16());
623 
624  Ieee80211SupportedRatesElement supRat;
625  b.readByte();
626  supRat.numRates = b.readByte();
627  for (int i = 0; i < supRat.numRates; i++)
628  supRat.rate[i] = (double)(b.readByte() & 0x7F) * 0.5;
629  body.setSupportedRates(supRat);
630 
631  pkt->setBody(body);
632  frame = pkt;
633  break;
634  }
635 
636  case 0x80: // ST_BEACON
637  {
638  Ieee80211BeaconFrame *pkt = new Ieee80211BeaconFrame();
640  Ieee80211BeaconFrameBody body;
641 
642  simtime_t t; t.setRaw(b.readUint64()); pkt->setTimestamp(t); //timestamp //FIXME
643 
644  body.setBeaconInterval(SimTime((int64_t)b.readUint16()*1024, SIMTIME_US));
645  b.readUint16(); // Capability
646 
647  char SSID[256];
648  b.readByte();
649  unsigned int length = b.readByte();
650  b.readNBytes(length, SSID);
651  SSID[length] = '\0';
652  body.setSSID(SSID);
653 
654  Ieee80211SupportedRatesElement supRat;
655  b.readByte();
656  supRat.numRates = b.readByte();
657  for (int i = 0; i < supRat.numRates; i++)
658  supRat.rate[i] = (double)(b.readByte() & 0x7F) * 0.5;
659  body.setSupportedRates(supRat);
660 
661  pkt->setBody(body);
662  frame = pkt;
663  break;
664  }
665 
666  case 0x50: // ST_PROBERESPONSE
667  {
668  Ieee80211ProbeResponseFrame *pkt = new Ieee80211ProbeResponseFrame();
670  Ieee80211ProbeResponseFrameBody body;
671 
672  simtime_t t; t.setRaw(b.readUint64()); pkt->setTimestamp(t); //timestamp //FIXME
673 
674  body.setBeaconInterval(SimTime((int64_t)b.readUint16() * 1024, SIMTIME_US));
675  b.readUint16();
676 
677  char SSID[256];
678  b.readByte();
679  unsigned int length = b.readByte();
680  b.readNBytes(length, SSID);
681  SSID[length] = '\0';
682  body.setSSID(SSID);
683 
684  Ieee80211SupportedRatesElement supRat;
685  b.readByte();
686  supRat.numRates = b.readByte();
687  for (int i = 0; i < supRat.numRates; i++)
688  supRat.rate[i] = (double)(b.readByte() & 0x7F) * 0.5;
689  body.setSupportedRates(supRat);
690 
691  pkt->setBody(body);
692  frame = pkt;
693  break;
694  }
695 
696  case 0xD0: // type = ST_ACTION
697  {
698  // Ieee80211ActionFrame
699  return nullptr;
700  }
701 
702  default:
703  {
704  EV_ERROR << "Cannot deserialize Ieee80211 packet: type " << type << " not supported.";
705  b.setError();
706  return nullptr;
707  }
708  }
709  uint32_t calculatedCrc = ethernetCRC(b._getBuf(), b.getPos());
710  uint32_t receivedCrc = b.readUint32();
711  EV_DEBUG << "Calculated CRC: " << calculatedCrc << ", received CRC: " << receivedCrc << endl;
712  if (receivedCrc != calculatedCrc)
713  frame->setBitError(true);
714 
715  // TODO: don't set this directly, it should be computed above separately in each case
716  if (frame->getByteLength() != b.getPos()) {
717  throw cRuntimeError("ieee802.11 deserializer: packet length error: generated=%i v.s. read=%i", (int)frame->getByteLength(), b.getPos());
718  }
719  //frame->setByteLength(b.getPos());
720  return frame;
721 }
Definition: Ieee80211Frame_m.h:99
Definition: Ieee80211Frame_m.h:100
Definition: SerializerBase.h:39
Definition: Ieee80211Frame_m.h:106
uint32_t ethernetCRC(const unsigned char *buf, unsigned int bufsize)
Definition: EthernetCRC.cc:67
void parseDataOrMgmtFrame(const Buffer &b, inet::ieee80211::Ieee80211DataOrMgmtFrame *Frame, short type)
Definition: Ieee80211Serializer.cc:380
Definition: Ieee80211Frame_m.h:117
Definition: Ieee80211Frame_m.h:98
Definition: Ieee80211Frame_m.h:113
Definition: Ieee80211Frame_m.h:101
Definition: Ieee80211Frame_m.h:103
Definition: Ieee80211Frame_m.h:112
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
Definition: Ieee80211Frame_m.h:102
Definition: Ieee80211Frame_m.h:111
Definition: Ieee80211Frame_m.h:116
static cPacket * lookupAndDeserialize(const Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
Definition: SerializerBase.cc:99
Definition: Ieee80211Frame_m.h:97
value< double, units::m > b
Definition: Units.h:1054
Definition: Ieee80211Frame_m.h:107
Definition: Ieee80211Frame_m.h:105
void inet::serializer::Ieee80211Serializer::parseDataOrMgmtFrame ( const Buffer b,
inet::ieee80211::Ieee80211DataOrMgmtFrame Frame,
short  type 
)
protected
381 {
382  Frame->setType(type);
383  b.seek(0);
384  b.readByte(); // i_fc[0]
385  uint8_t fc1 = b.readByte(); // i_fc[1]
386  Frame->setToDS(fc1 & 0x1);
387  Frame->setFromDS(fc1 & 0x2);
388  Frame->setMoreFragments(fc1 & 0x4);
389  Frame->setRetry(fc1 & 0x8);
390  Frame->setDuration(SimTime(b.readUint16() / 1000.0)); // i_dur
391  Frame->setReceiverAddress(b.readMACAddress());
392  Frame->setTransmitterAddress(b.readMACAddress());
393  Frame->setAddress3(b.readMACAddress());
394  uint16_t seq = b.readUint16(); // i_seq
395  Frame->setSequenceNumber(seq >> 4);
396  Frame->setFragmentNumber(seq & 0x0F);
397 
398  if ((type == ST_DATA || type == ST_DATA_WITH_QOS) && Frame->getFromDS() && Frame->getToDS())
399  {
400  check_and_cast<Ieee80211DataFrame*>(Frame)->setAddress4(b.readMACAddress());
401  }
402  if (type == ST_DATA_WITH_QOS) {
403  check_and_cast<Ieee80211DataFrame*>(Frame)->setQos(b.readUint16());
404  }
405 }
virtual bool getToDS() const
virtual void setFromDS(bool fromDS)
virtual void setType(short type)
virtual void setSequenceNumber(uint16_t sequenceNumber)
Definition: Ieee80211Frame_m.h:117
virtual void setReceiverAddress(const MACAddress &receiverAddress)
virtual void setAddress3(const MACAddress &address3)
virtual void setMoreFragments(bool moreFragments)
virtual void setToDS(bool toDS)
Definition: Ieee80211Frame_m.h:116
virtual bool getFromDS() const
virtual void setFragmentNumber(short fragmentNumber)
virtual void setDuration(::omnetpp::simtime_t duration)
value< double, units::m > b
Definition: Units.h:1054
virtual void setTransmitterAddress(const MACAddress &transmitterAddress)
virtual void setRetry(bool retry)
void inet::serializer::Ieee80211Serializer::serialize ( const cPacket *  pkt,
Buffer b,
Context context 
)
overrideprotectedvirtual

Serializes a cPacket for transmission on the wire.

Returns the length of data written into buffer.

Implements inet::serializer::SerializerBase.

48 {
49  if (dynamic_cast<const Ieee80211ACKFrame *>(pkt))
50  {
51  const Ieee80211ACKFrame *ackFrame = static_cast<const Ieee80211ACKFrame *>(pkt);
52  b.writeByte(0xD4);
53  b.writeByte(0);
54  b.writeUint16(ackFrame->getDuration().inUnit(SIMTIME_MS));
55  b.writeMACAddress(ackFrame->getReceiverAddress());
56  }
57  else if (dynamic_cast<const Ieee80211RTSFrame *>(pkt))
58  {
59  const Ieee80211RTSFrame *rtsFrame = static_cast<const Ieee80211RTSFrame *>(pkt);
60  b.writeByte(0xB4);
61  b.writeByte(0);
62  b.writeUint16(rtsFrame->getDuration().inUnit(SIMTIME_MS));
63  b.writeMACAddress(rtsFrame->getReceiverAddress());
64  b.writeMACAddress(rtsFrame->getTransmitterAddress());
65  }
66  else if (dynamic_cast<const Ieee80211CTSFrame *>(pkt))
67  {
68  const Ieee80211CTSFrame *ctsFrame = static_cast<const Ieee80211CTSFrame *>(pkt);
69  b.writeByte(0xC4);
70  b.writeByte(0);
71  b.writeUint16(ctsFrame->getDuration().inUnit(SIMTIME_MS));
72  b.writeMACAddress(ctsFrame->getReceiverAddress());
73  }
74  else if (dynamic_cast<const Ieee80211DataOrMgmtFrame *>(pkt))
75  {
76  const Ieee80211DataOrMgmtFrame *dataOrMgmtFrame = static_cast<const Ieee80211DataOrMgmtFrame *>(pkt);
77 
78  b.writeByte(0x08); //without Qos=0x08, with Qos=0x88
79  uint8_t fc1;
80  // TODO: Order, Protected Frame, MoreData, Power Mgt
81  fc1 = (dataOrMgmtFrame->getRetry() ? 8 : 0)
82  | (dataOrMgmtFrame->getMoreFragments() ? 4 : 0)
83  | (dataOrMgmtFrame->getFromDS() ? 2 : 0)
84  | (dataOrMgmtFrame->getToDS() ? 1 : 0);
85  b.writeByte(fc1);
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());
92 
93 
94  if (dynamic_cast<const Ieee80211DataFrameWithSNAP *>(pkt))
95  {
96  const Ieee80211DataFrameWithSNAP *dataFrame = static_cast<const Ieee80211DataFrameWithSNAP *>(pkt);
97  if (dataFrame->getFromDS() && dataFrame->getToDS())
98  {
99  b.writeMACAddress(dataFrame->getAddress4());
100  }
101  if (dataFrame->getType() == ST_DATA_WITH_QOS) {
102  b.writeUint16(dataFrame->getQos());
103  }
104 
105  // snap header:
106  b.writeByte(0xAA); // snap_hdr.dsap
107  b.writeByte(0xAA); // snap_hdr.ssap
108  b.writeByte(0x03); // snap_hdr.ctrl
109  b.writeNBytes(3, "\0\0\0"); // snap_hdr.oui
110  b.writeUint16(dataFrame->getEtherType()); // snap_hdr.ethertype
111 
112  const cPacket *encapPacket = dataFrame->getEncapsulatedPacket();
113  SerializerBase::lookupAndSerialize(encapPacket, b, c, ETHERTYPE, dataFrame->getEtherType(), b.getRemainingSize(4)); // 4 byte for store crc at end of packet
114  }
115  else if (dynamic_cast<const Ieee80211AuthenticationFrame *>(pkt))
116  {
117  //type = ST_AUTHENTICATION;
118  const Ieee80211AuthenticationFrame *Frame = static_cast<const Ieee80211AuthenticationFrame *>(pkt);
119  // 1 Authentication algorithm number
120  b.writeUint16(0);
121  // 2 Authentication transaction sequence number
122  b.writeUint16(Frame->getBody().getSequenceNumber());
123  // 3 Status code The status code information is reserved in certain Authentication frames as defined in Table 7-17.
124  b.writeUint16(Frame->getBody().getStatusCode());
125  // 4 Challenge text The challenge text information is present only in certain Authentication frames as defined in Table 7-17.
126  // Last Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
127  }
128  else if (dynamic_cast<const Ieee80211DeauthenticationFrame *>(pkt))
129  {
130  //type = ST_DEAUTHENTICATION;
131  const Ieee80211DeauthenticationFrame *Frame = static_cast<const Ieee80211DeauthenticationFrame *>(pkt);
132  b.writeUint16(Frame->getBody().getReasonCode());
133  }
134  else if (dynamic_cast<const Ieee80211DisassociationFrame *>(pkt))
135  {
136  //type = ST_DISASSOCIATION;
137  const Ieee80211DisassociationFrame *Frame = static_cast<const Ieee80211DisassociationFrame *>(pkt);
138  b.writeUint16(Frame->getBody().getReasonCode());
139  }
140  else if (dynamic_cast<const Ieee80211ProbeRequestFrame *>(pkt))
141  {
142  //type = ST_PROBEREQUEST;
143  const Ieee80211ProbeRequestFrame *Frame = static_cast<const Ieee80211ProbeRequestFrame *>(pkt);
144  // 1 SSID
145  const char *SSID = Frame->getBody().getSSID();
146  unsigned int length = strlen(SSID);
147  b.writeByte(0); //FIXME dummy, what is it?
148  b.writeByte(length);
149  b.writeNBytes(length, SSID);
150  // 2 Supported rates
151  const Ieee80211SupportedRatesElement& supportedRates = Frame->getBody().getSupportedRates();
152  b.writeByte(1);
153  b.writeByte(supportedRates.numRates);
154  for (int i = 0; i < supportedRates.numRates; i++)
155  {
156  uint8_t rate = ceil(supportedRates.rate[i]/0.5);
157  // rate |= 0x80 if rate contained in the BSSBasicRateSet parameter
158  b.writeByte(rate);
159  }
160  // 3 Request information May be included if dot11MultiDomainCapabilityEnabled is true.
161  // 4 Extended Supported Rates The Extended Supported Rates element is present whenever there are more than eight supported rates, and it is optional otherwise.
162  // Last Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
163  }
164  else if (dynamic_cast<const Ieee80211AssociationRequestFrame *>(pkt))
165  {
166  //type = ST_ASSOCIATIONREQUEST;
167  const Ieee80211AssociationRequestFrame *Frame = static_cast<const Ieee80211AssociationRequestFrame *>(pkt);
168  // 1 Capability
169  b.writeUint16(0); //FIXME
170  // 2 Listen interval
171  b.writeUint16(0); //FIXME
172  // 3 SSID
173  const char *SSID = Frame->getBody().getSSID();
174  unsigned int length = strlen(SSID);
175  b.writeByte(0); //FIXME dummy, what is it?
176  b.writeByte(length);
177  b.writeNBytes(length, SSID);
178  // 4 Supported rates
179  const Ieee80211SupportedRatesElement& supportedRates = Frame->getBody().getSupportedRates();
180  b.writeByte(1);
181  b.writeByte(supportedRates.numRates);
182  for (int i = 0; i < supportedRates.numRates; i++) {
183  uint8_t rate = ceil(supportedRates.rate[i]/0.5);
184  // rate |= 0x80 if rate contained in the BSSBasicRateSet parameter
185  b.writeByte(rate);
186  }
187  // 5 Extended Supported Rates The Extended Supported Rates element is present whenever there are more than eight supported rates, and it is optional otherwise.
188  // 6 Power Capability The Power Capability element shall be present if dot11SpectrumManagementRequired is true.
189  // 7 Supported Channel The Supported Channels element shall be present if dot11SpectrumManagementRequired is true.
190  // 8 RSN The RSN information element is only present within Association Request frames generated by STAs that have dot11RSNAEnabled set to TRUE.
191  // 9 QoS Capability The QoS Capability element is present when dot11QosOption- Implemented is true.
192  // Last Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
193  }
194  else if (dynamic_cast<const Ieee80211ReassociationRequestFrame *>(pkt))
195  {
196  //type = ST_REASSOCIATIONREQUEST;
197  const Ieee80211ReassociationRequestFrame *Frame = dynamic_cast<const Ieee80211ReassociationRequestFrame *>(pkt);
198  // 1 Capability
199  b.writeUint16(0); //FIXME
200  // 2 Listen interval
201  b.writeUint16(0); //FIXME
202  // 3 Current AP address
203  b.writeMACAddress(Frame->getBody().getCurrentAP());
204  // 4 SSID
205  const char *SSID = Frame->getBody().getSSID();
206  unsigned int length = strlen(SSID);
207  //FIXME buffer.writeByte(buf + packetLength, ???);
208  b.writeByte(0); //FIXME
209  b.writeByte(length);
210  b.writeNBytes(length, SSID);
211  // 5 Supported rates
212  const Ieee80211SupportedRatesElement& supportedRates = Frame->getBody().getSupportedRates();
213  b.writeByte(1);
214  b.writeByte(supportedRates.numRates);
215  for (int i = 0; i < supportedRates.numRates; i++)
216  {
217  uint8_t rate = ceil(supportedRates.rate[i]/0.5);
218  // rate |= 0x80 if rate contained in the BSSBasicRateSet parameter
219  b.writeByte(rate);
220  }
221  // 6 Extended Supported Rates The Extended Supported Rates element is present whenever there are more than eight supported rates, and it is optional otherwise.
222  // 7 Power Capability The Power Capability element shall be present if dot11SpectrumManagementRequired is true.
223  // 8 Supported Channels The Supported Channels element shall be present if dot11SpectrumManagementRequired is true.
224  // 9 RSN The RSN information element is only present within Reassociation Request frames generated by STAs that have dot11RSNAEnabled set to TRUE.
225  // 10 QoS Capability The QoS Capability element is present when dot11QosOption- Implemented is true.
226  // Last Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
227  }
228  else if (dynamic_cast<const Ieee80211AssociationResponseFrame *>(pkt))
229  {
230  //type = ST_ASSOCIATIONRESPONSE;
231  const Ieee80211AssociationResponseFrame *Frame = static_cast<const Ieee80211AssociationResponseFrame *>(pkt);
232  // 1 Capability
233  b.writeUint16(0); //FIXME
234  // 2 Status code
235  b.writeUint16(Frame->getBody().getStatusCode());
236  // 3 AID
237  b.writeUint16(Frame->getBody().getAid());
238  // 4 Supported rates
239  b.writeByte(1);
240  b.writeByte(Frame->getBody().getSupportedRates().numRates);
241  for (int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
242  {
243  uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
244  // rate |= 0x80 if rate contained in the BSSBasicRateSet parameter
245  b.writeByte(rate);
246  }
247  // 5 Extended Supported Rates The Extended Supported Rates element is present whenever there are more than eight supported rates, and it is optional otherwise.
248  // 6 EDCA Parameter Set
249  // Last Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
250  }
251  else if (dynamic_cast<const Ieee80211ReassociationResponseFrame *>(pkt))
252  {
253  //type = ST_REASSOCIATIONRESPONSE;
254  const Ieee80211ReassociationResponseFrame *Frame = dynamic_cast<const Ieee80211ReassociationResponseFrame *>(pkt);
255  // 1 Capability
256  b.writeUint16(0); //FIXME
257  // 2 Status code
258  b.writeUint16(Frame->getBody().getStatusCode());
259  // 3 AID
260  b.writeUint16(Frame->getBody().getAid());
261  // 4 Supported rates
262  b.writeByte(1);
263  b.writeByte(Frame->getBody().getSupportedRates().numRates);
264  for (int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
265  {
266  uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
267  // rate |= 0x80 if rate contained in the BSSBasicRateSet parameter
268  b.writeByte(rate);
269  }
270  // 5 Extended Supported Rates The Extended Supported Rates element is present whenever there are more than eight supported rates, and it is optional otherwise.
271  // 6 EDCA Parameter Set
272  // Last Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
273  }
274  else if (dynamic_cast<const Ieee80211BeaconFrame *>(pkt))
275  {
276  //type = ST_BEACON;
277  const Ieee80211BeaconFrame *Frame = static_cast<const Ieee80211BeaconFrame *>(pkt);
278  // 1 Timestamp
279  b.writeUint64(Frame->getTimestamp().raw()); //FIXME
280  // 2 Beacon interval
281  b.writeUint16((uint16_t)(Frame->getBody().getBeaconInterval().inUnit(SIMTIME_US)/1024));
282  // 3 Capability
283  b.writeUint16(0); //FIXME set capability
284  // 4 Service Set Identifier (SSID)
285  const char *SSID = Frame->getBody().getSSID();
286  unsigned int length = strlen(SSID);
287  b.writeByte(0); //FIXME
288  b.writeByte(length);
289  b.writeNBytes(length, SSID);
290  // 5 Supported rates
291  b.writeByte(1);
292  b.writeByte(Frame->getBody().getSupportedRates().numRates);
293  for (int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
294  {
295  uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
296  // rate |= 0x80 if rate contained in the BSSBasicRateSet parameter
297  b.writeByte(rate);
298  }
299  // 6 Frequency-Hopping (FH) Parameter Set The FH Parameter Set information element is present within Beacon frames generated by STAs using FH PHYs.
300  // 7 DS Parameter Set The DS Parameter Set information element is present within Beacon frames generated by STAs using Clause 15, Clause 18, and Clause 19 PHYs.
301  // 8 CF Parameter Set The CF Parameter Set information element is present only within Beacon frames generated by APs supporting a PCF.
302  // 9 IBSS Parameter Set The IBSS Parameter Set information element is present only within Beacon frames generated by STAs in an IBSS.
303  // 10 Traffic indication map (TIM) The TIM information element is present only within Beacon frames generated by APs.
304  // 11 Country The Country information element shall be present when dot11MultiDomainCapabilityEnabled is true or dot11SpectrumManagementRequired is true.
305  // 12 FH Parameters FH Parameters as specified in 7.3.2.10 may be included if dot11MultiDomainCapabilityEnabled is true.
306  // 13 FH Pattern Table FH Pattern Table information as specified in 7.3.2.11 may be included if dot11MultiDomainCapabilityEnabled is true.
307  // 14 Power Constraint Power Constraint element shall be present if dot11SpectrumManagementRequired is true.
308  // 15 Channel Switch Announcement Channel Switch Announcement element may be present if dot11SpectrumManagementRequired is true.
309  // 16 Quiet Quiet element may be present if dot11SpectrumManagementRequired is true.
310  // 17 IBSS DFS IBSS DFS element shall be present if dot11SpectrumManagementRequired is true in an IBSS.
311  // 18 TPC Report TPC Report element shall be present if dot11SpectrumManagementRequired is true.
312  // 19 ERP Information The ERP Information element is present within Beacon frames generated by STAs using extended rate PHYs (ERPs) defined in Clause 19 and is optionally present in other cases.
313  // 20 Extended Supported Rates The Extended Supported Rates element is present whenever there are more than eight supported rates, and it is optional otherwise.
314  // 21 RSN The RSN information element shall be present within Beacon frames generated by STAs that have dot11RSNAEnabled set to TRUE.
315  // 22 BSS Load The BSS Load element is present when dot11QosOption- Implemented and dot11QBSSLoadImplemented are both true.
316  // 23 EDCA Parameter Set The EDCA Parameter Set element is present when dot11QosOptionImplemented is true and the QoS Capability element is not present.
317  // 24 QoS Capability The QoS Capability element is present when dot11QosOption- Implemented is true and EDCA Parameter Set element is not present.
318  // Last Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
319  }
320  else if (dynamic_cast<const Ieee80211ProbeResponseFrame *>(pkt))
321  {
322  //type = ST_PROBERESPONSE;
323  const Ieee80211ProbeResponseFrame *Frame = static_cast<const Ieee80211ProbeResponseFrame *>(pkt);
324  // 1 Timestamp
325  b.writeUint64(Frame->getTimestamp().raw()); //FIXME
326  // 2 Beacon interval
327  b.writeUint16((uint16_t)(Frame->getBody().getBeaconInterval().inUnit(SIMTIME_US)/1024));
328  // 3 Capability
329  b.writeUint16(0); //FIXME
330  // 4 SSID
331  const char *SSID = Frame->getBody().getSSID();
332  unsigned int length = strlen(SSID);
333  b.writeByte(0); //FIXME
334  b.writeByte(length);
335  b.writeNBytes(length, SSID);
336  // 5 Supported rates
337  b.writeByte(1);
338  b.writeByte(Frame->getBody().getSupportedRates().numRates);
339  for (int i = 0; i < Frame->getBody().getSupportedRates().numRates; i++)
340  {
341  uint8_t rate = ceil(Frame->getBody().getSupportedRates().rate[i]/0.5);
342  // rate |= 0x80 if rate contained in the BSSBasicRateSet parameter
343  b.writeByte(rate);
344  }
345  // 6 FH Parameter Set The FH Parameter Set information element is present within Probe Response frames generated by STAs using FH PHYs.
346  // 7 DS Parameter Set The DS Parameter Set information element is present within Probe Response frames generated by STAs using Clause 15, Clause 18, and Clause 19 PHYs.
347  // 8 CF Parameter Set The CF Parameter Set information element is present only within Probe Response frames generated by APs supporting a PCF.
348  // 9 IBSS Parameter Set The IBSS Parameter Set information element is present only within Probe Response frames generated by STAs in an IBSS.
349  // 10 Country Included if dot11MultiDomainCapabilityEnabled or dot11SpectrumManagementRequired is true.
350  // 11 FH Parameters FH Parameters, as specified in 7.3.2.10, may be included if dot11MultiDomainCapabilityEnabled is true.
351  // 12 FH Pattern Table FH Pattern Table information, as specified in 7.3.2.11, may be included if dot11MultiDomainCapabilityEnabled is true.
352  // 13 Power Constraint Shall be included if dot11SpectrumManagementRequired is true.
353  // 14 Channel Switch Announcement May be included if dot11SpectrumManagementRequired is true.
354  // 15 Quiet May be included if dot11SpectrumManagementRequired is true.
355  // 16 IBSS DFS Shall be included if dot11SpectrumManagementRequired is true in an IBSS.
356  // 17 TPC Report Shall be included if dot11SpectrumManagementRequired is true.
357  // 18 ERP Information The ERP Information element is present within Probe Response frames generated by STAs using ERPs and is optionally present in other cases.
358  // 19 Extended Supported Rates The Extended Supported Rates element is present whenever there are more than eight supported rates, and it is optional otherwise.
359  // 20 RSN The RSN information element is only present within Probe Response frames generated by STAs that have dot11RSNA- Enabled set to TRUE.
360  // 21 BSS Load The BSS Load element is present when dot11QosOption- Implemented and dot11QBSSLoadImplemented are both true.
361  // 22 EDCA Parameter Set The EDCA Parameter Set element is present when dot11QosOptionImplemented is true.
362  // Last�1 Vendor Specific One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements, except the Requested Information elements.
363  // Last�n Requested information elements Elements requested by the Request information element of the Probe Request frame.
364  }
365 
366  else if (dynamic_cast<const Ieee80211ActionFrame *>(pkt))
367  {
368  //type = ST_ACTION;
369  // 1 Action
370  // Last One or more vendor-specific information elements may appear in this frame. This information element follows all other information elements.
371  }
372  }
373  else
374  throw cRuntimeError("Ieee80211Serializer: cannot serialize the frame");
375 
376  // CRC
377  b.writeUint32(ethernetCRC(b._getBuf(), b.getPos()));
378 }
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

The documentation for this class was generated from the following files: