INET Framework for OMNeT++/OMNEST
inet::ieee80211::Ieee80211MgmtAPBase Class Reference

Used in 802.11 infrastructure mode: abstract base class for management frame handling for access points (APs). More...

#include <Ieee80211MgmtAPBase.h>

Inheritance diagram for inet::ieee80211::Ieee80211MgmtAPBase:
inet::ieee80211::Ieee80211MgmtBase inet::ILifecycle inet::ieee80211::Ieee80211MgmtAP inet::ieee80211::Ieee80211MgmtAPSimplified

Public Types

enum  EncapDecap { ENCAP_DECAP_TRUE = 1, ENCAP_DECAP_FALSE, ENCAP_DECAP_ETH }
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int) override
 
virtual void distributeReceivedDataFrame (Ieee80211DataFrame *frame)
 Utility function for APs: sends back a data frame we received from a STA to the wireless LAN, after tweaking fromDS/toDS bits and shuffling addresses as needed. More...
 
virtual Ieee80211DataFrameencapsulate (cPacket *msg)
 Utility function for handleUpperMessage() More...
 
virtual Ieee80211DataFrameconvertFromEtherFrame (EtherFrame *ethframe)
 Utility function: converts EtherFrame to Ieee80211Frame. More...
 
virtual EtherFrameconvertToEtherFrame (Ieee80211DataFrame *frame)
 Utility function: converts Ieee80211Frame to EtherFrame. More...
 
virtual void sendToUpperLayer (Ieee80211DataFrame *frame)
 Utility function: send a frame to upperLayerOut. More...
 
- Protected Member Functions inherited from inet::ieee80211::Ieee80211MgmtBase
virtual void handleMessage (cMessage *msg) override
 Dispatches incoming messages to handleTimer(), handleUpperMessage() or processFrame(). More...
 
virtual void handleTimer (cMessage *frame)=0
 Should be redefined to deal with self-messages. More...
 
virtual void handleUpperMessage (cPacket *msg)=0
 Should be redefined to encapsulate and enqueue msgs from higher layers. More...
 
virtual void handleCommand (int msgkind, cObject *ctrl)=0
 Should be redefined to handle commands from the "agent" (if present) More...
 
virtual void sendDown (cPacket *frame)
 Utility method for implementing handleUpperMessage(): send message to MAC. More...
 
virtual void dropManagementFrame (Ieee80211ManagementFrame *frame)
 Utility method to dispose of an unhandled frame. More...
 
virtual void sendUp (cMessage *msg)
 Utility method: sends the packet to the upper layer. More...
 
virtual void processFrame (Ieee80211DataOrMgmtFrame *frame)
 Dispatch to frame processing methods according to frame type. More...
 
virtual void handleDataFrame (Ieee80211DataFrame *frame)=0
 
virtual void handleAuthenticationFrame (Ieee80211AuthenticationFrame *frame)=0
 
virtual void handleDeauthenticationFrame (Ieee80211DeauthenticationFrame *frame)=0
 
virtual void handleAssociationRequestFrame (Ieee80211AssociationRequestFrame *frame)=0
 
virtual void handleAssociationResponseFrame (Ieee80211AssociationResponseFrame *frame)=0
 
virtual void handleReassociationRequestFrame (Ieee80211ReassociationRequestFrame *frame)=0
 
virtual void handleReassociationResponseFrame (Ieee80211ReassociationResponseFrame *frame)=0
 
virtual void handleDisassociationFrame (Ieee80211DisassociationFrame *frame)=0
 
virtual void handleBeaconFrame (Ieee80211BeaconFrame *frame)=0
 
virtual void handleProbeRequestFrame (Ieee80211ProbeRequestFrame *frame)=0
 
virtual void handleProbeResponseFrame (Ieee80211ProbeResponseFrame *frame)=0
 
virtual void start ()
 lifecycle support More...
 
virtual void stop ()
 

Protected Attributes

bool isConnectedToHL
 
EncapDecap encapDecap
 
- Protected Attributes inherited from inet::ieee80211::Ieee80211MgmtBase
MACAddress myAddress
 
bool isOperational
 
long numDataFramesReceived
 
long numMgmtFramesReceived
 
long numMgmtFramesDropped
 

Additional Inherited Members

- Public Member Functions inherited from inet::ieee80211::Ieee80211MgmtBase
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Detailed Description

Used in 802.11 infrastructure mode: abstract base class for management frame handling for access points (APs).

This class extends Ieee80211MgmtBase with utility functions that are useful for implementing AP functionality.

Author
Andras Varga

Member Enumeration Documentation

Enumerator
ENCAP_DECAP_TRUE 
ENCAP_DECAP_FALSE 
ENCAP_DECAP_ETH 

Member Function Documentation

Ieee80211DataFrame * inet::ieee80211::Ieee80211MgmtAPBase::convertFromEtherFrame ( EtherFrame ethframe)
protectedvirtual

Utility function: converts EtherFrame to Ieee80211Frame.

This is needed because MACRelayUnit which we use for LAN bridging functionality deals with EtherFrames.

Referenced by encapsulate().

138 {
139 #ifdef WITH_ETHERNET
140  // create new frame
141  Ieee80211DataFrameWithSNAP *frame = new Ieee80211DataFrameWithSNAP(ethframe->getName());
142  frame->setFromDS(true);
143 
144  // copy addresses from ethernet frame (transmitter addr will be set to our addr by MAC)
145  frame->setReceiverAddress(ethframe->getDest());
146  frame->setAddress3(ethframe->getSrc());
147 
148  // copy EtherType from original frame
149  if (dynamic_cast<EthernetIIFrame *>(ethframe))
150  frame->setEtherType(((EthernetIIFrame *)ethframe)->getEtherType());
151  else if (dynamic_cast<EtherFrameWithSNAP *>(ethframe))
152  frame->setEtherType(((EtherFrameWithSNAP *)ethframe)->getLocalcode());
153  else
154  throw cRuntimeError("Unaccepted EtherFrame type: %s, contains no EtherType", ethframe->getClassName());
155 
156  // encapsulate payload
157  cPacket *payload = ethframe->decapsulate();
158  if (!payload)
159  throw cRuntimeError("received empty EtherFrame from upper layer");
160  frame->encapsulate(payload);
161  delete ethframe;
162 
163  // done
164  return frame;
165 #else // ifdef WITH_ETHERNET
166  throw cRuntimeError("INET compiled without ETHERNET feature!");
167 #endif // ifdef WITH_ETHERNET
168 }
EtherFrame * inet::ieee80211::Ieee80211MgmtAPBase::convertToEtherFrame ( Ieee80211DataFrame frame)
protectedvirtual

Utility function: converts Ieee80211Frame to EtherFrame.

This is needed because MACRelayUnit which we use for LAN bridging functionality deals with EtherFrames.

Referenced by sendToUpperLayer().

111 {
112 #ifdef WITH_ETHERNET
113  Ieee80211DataFrameWithSNAP *frame = check_and_cast<Ieee80211DataFrameWithSNAP *>(frame_);
114 
115  // create a matching ethernet frame
116  EthernetIIFrame *ethframe = new EthernetIIFrame(frame->getName()); //TODO option to use EtherFrameWithSNAP instead
117  ethframe->setDest(frame->getAddress3());
118  ethframe->setSrc(frame->getTransmitterAddress());
119  ethframe->setEtherType(frame->getEtherType());
120  ethframe->setByteLength(ETHER_MAC_FRAME_BYTES);
121 
122  // encapsulate the payload in there
123  cPacket *payload = frame->decapsulate();
124  delete frame;
125  ASSERT(payload != nullptr);
126  ethframe->encapsulate(payload);
127  if (ethframe->getByteLength() < MIN_ETHERNET_FRAME_BYTES)
128  ethframe->setByteLength(MIN_ETHERNET_FRAME_BYTES);
129 
130  // done
131  return ethframe;
132 #else // ifdef WITH_ETHERNET
133  throw cRuntimeError("INET compiled without ETHERNET feature!");
134 #endif // ifdef WITH_ETHERNET
135 }
#define ETHER_MAC_FRAME_BYTES
Definition: Ethernet.h:49
#define MIN_ETHERNET_FRAME_BYTES
Definition: Ethernet.h:31
void inet::ieee80211::Ieee80211MgmtAPBase::distributeReceivedDataFrame ( Ieee80211DataFrame frame)
protectedvirtual

Utility function for APs: sends back a data frame we received from a STA to the wireless LAN, after tweaking fromDS/toDS bits and shuffling addresses as needed.

Referenced by inet::ieee80211::Ieee80211MgmtAPSimplified::handleDataFrame().

51 {
52  // adjust toDS/fromDS bits, and shuffle addresses
53  frame->setToDS(false);
54  frame->setFromDS(true);
55 
56  // move destination address to address1 (receiver address),
57  // and fill address3 with original source address;
58  // sender address (address2) will be filled in by MAC
59  ASSERT(!frame->getAddress3().isUnspecified());
60  frame->setReceiverAddress(frame->getAddress3());
61  frame->setAddress3(frame->getTransmitterAddress());
62 
63  sendDown(frame);
64 }
virtual void sendDown(cPacket *frame)
Utility method for implementing handleUpperMessage(): send message to MAC.
Definition: Ieee80211MgmtBase.cc:84
Ieee80211DataFrame * inet::ieee80211::Ieee80211MgmtAPBase::encapsulate ( cPacket *  msg)
protectedvirtual

Utility function for handleUpperMessage()

Referenced by inet::ieee80211::Ieee80211MgmtAPSimplified::handleUpperMessage().

171 {
172  switch (encapDecap) {
173  case ENCAP_DECAP_ETH:
174 #ifdef WITH_ETHERNET
175  return convertFromEtherFrame(check_and_cast<EtherFrame *>(msg));
176 #else // ifdef WITH_ETHERNET
177  throw cRuntimeError("INET compiled without ETHERNET feature, but the 'encapDecap' parameter is set to 'eth'!");
178 #endif // ifdef WITH_ETHERNET
179  break;
180 
181  case ENCAP_DECAP_TRUE: {
182  Ieee802Ctrl *ctrl = check_and_cast<Ieee802Ctrl *>(msg->removeControlInfo());
183  Ieee80211DataFrameWithSNAP *frame = new Ieee80211DataFrameWithSNAP(msg->getName());
184  frame->setFromDS(true);
185 
186  // copy addresses from ethernet frame (transmitter addr will be set to our addr by MAC)
187  frame->setAddress3(ctrl->getSrc());
188  frame->setReceiverAddress(ctrl->getDest());
189  frame->setEtherType(ctrl->getEtherType());
190  int up = ctrl->getUserPriority();
191  if (up >= 0) {
192  // make it a QoS frame, and set TID
193  frame->setType(ST_DATA_WITH_QOS);
194  frame->addBitLength(QOSCONTROL_BITS);
195  frame->setTid(up);
196  }
197  delete ctrl;
198 
199  // encapsulate payload
200  frame->encapsulate(msg);
201  return frame;
202  }
203  break;
204 
205  case ENCAP_DECAP_FALSE:
206  return check_and_cast<Ieee80211DataFrame *>(msg);
207  break;
208 
209  default:
210  throw cRuntimeError("Unknown encapDecap value: %d", encapDecap);
211  break;
212  }
213  return nullptr;
214 }
EncapDecap encapDecap
Definition: Ieee80211MgmtAPBase.h:45
Definition: Ieee80211Frame_m.h:117
virtual Ieee80211DataFrame * convertFromEtherFrame(EtherFrame *ethframe)
Utility function: converts EtherFrame to Ieee80211Frame.
Definition: Ieee80211MgmtAPBase.cc:137
Definition: Ieee80211MgmtAPBase.h:41
Definition: Ieee80211MgmtAPBase.h:41
const unsigned int QOSCONTROL_BITS
Definition: Ieee80211Frame_m.h:48
void inet::ieee80211::Ieee80211MgmtAPBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::ieee80211::Ieee80211MgmtBase.

Reimplemented in inet::ieee80211::Ieee80211MgmtAP, and inet::ieee80211::Ieee80211MgmtAPSimplified.

Referenced by inet::ieee80211::Ieee80211MgmtAPSimplified::initialize(), and inet::ieee80211::Ieee80211MgmtAP::initialize().

31 {
33 
34  if (stage == INITSTAGE_LOCAL) {
35  isConnectedToHL = gate("upperLayerOut")->getPathEndGate()->isConnected();
36  const char *encDec = par("encapDecap").stringValue();
37  if (!strcmp(encDec, "true"))
39  else if (!strcmp(encDec, "false"))
41  else if (!strcmp(encDec, "eth"))
43  else
44  throw cRuntimeError("Unknown encapDecap parameter value: '%s'! Must be 'true','false' or 'eth'.", encDec);
45 
46  WATCH(isConnectedToHL);
47  }
48 }
bool isConnectedToHL
Definition: Ieee80211MgmtAPBase.h:44
EncapDecap encapDecap
Definition: Ieee80211MgmtAPBase.h:45
Local initializations.
Definition: InitStages.h:35
Definition: Ieee80211MgmtAPBase.h:41
Definition: Ieee80211MgmtAPBase.h:41
virtual void initialize(int) override
Definition: Ieee80211MgmtBase.cc:30
virtual int inet::ieee80211::Ieee80211MgmtAPBase::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::ieee80211::Ieee80211MgmtBase.

Reimplemented in inet::ieee80211::Ieee80211MgmtAP, and inet::ieee80211::Ieee80211MgmtAPSimplified.

48 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::ieee80211::Ieee80211MgmtAPBase::sendToUpperLayer ( Ieee80211DataFrame frame)
protectedvirtual

Utility function: send a frame to upperLayerOut.

If convertToEtherFrameFlag is true, converts the given frame to EtherFrame, deleting the original frame, and send the converted frame. This function is needed for LAN bridging functionality: MACRelayUnit deals with EtherFrames.

Referenced by inet::ieee80211::Ieee80211MgmtAPSimplified::handleDataFrame().

67 {
68  if (!isConnectedToHL) {
69  delete frame;
70  return;
71  }
72  cPacket *outFrame = nullptr;
73  switch (encapDecap) {
74  case ENCAP_DECAP_ETH:
75 #ifdef WITH_ETHERNET
76  outFrame = convertToEtherFrame(frame);
77 #else // ifdef WITH_ETHERNET
78  throw cRuntimeError("INET compiled without ETHERNET feature, but the 'encapDecap' parameter is set to 'eth'!");
79 #endif // ifdef WITH_ETHERNET
80  break;
81 
82  case ENCAP_DECAP_TRUE: {
83  cPacket *payload = frame->decapsulate();
84  Ieee802Ctrl *ctrl = new Ieee802Ctrl();
85  ctrl->setSrc(frame->getTransmitterAddress());
86  ctrl->setDest(frame->getAddress3());
87  int tid = frame->getTid();
88  if (tid < 8)
89  ctrl->setUserPriority(tid); // TID values 0..7 are UP
90  Ieee80211DataFrameWithSNAP *frameWithSNAP = dynamic_cast<Ieee80211DataFrameWithSNAP *>(frame);
91  if (frameWithSNAP)
92  ctrl->setEtherType(frameWithSNAP->getEtherType());
93  payload->setControlInfo(ctrl);
94  delete frame;
95  outFrame = payload;
96  }
97  break;
98 
99  case ENCAP_DECAP_FALSE:
100  outFrame = frame;
101  break;
102 
103  default:
104  throw cRuntimeError("Unknown encapDecap value: %d", encapDecap);
105  break;
106  }
107  send(outFrame, "upperLayerOut");
108 }
bool isConnectedToHL
Definition: Ieee80211MgmtAPBase.h:44
EncapDecap encapDecap
Definition: Ieee80211MgmtAPBase.h:45
Definition: Ieee80211MgmtAPBase.h:41
Definition: Ieee80211MgmtAPBase.h:41
virtual EtherFrame * convertToEtherFrame(Ieee80211DataFrame *frame)
Utility function: converts Ieee80211Frame to EtherFrame.
Definition: Ieee80211MgmtAPBase.cc:110

Member Data Documentation

EncapDecap inet::ieee80211::Ieee80211MgmtAPBase::encapDecap
protected
bool inet::ieee80211::Ieee80211MgmtAPBase::isConnectedToHL
protected

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