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

Used in 802.11 infrastructure mode: handles management frames for a station (STA). More...

#include <Ieee80211MgmtSTA.h>

Inheritance diagram for inet::ieee80211::Ieee80211MgmtSTA:
inet::ieee80211::Ieee80211MgmtBase inet::ILifecycle

Classes

struct  APInfo
 
struct  AssociatedAPInfo
 
struct  ScanningInfo
 

Public Member Functions

 Ieee80211MgmtSTA ()
 
- 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 ()
 

Protected Types

typedef std::list< APInfoAccessPointList
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleTimer (cMessage *msg) override
 Implements abstract Ieee80211MgmtBase method. More...
 
virtual void handleUpperMessage (cPacket *msg) override
 Implements abstract Ieee80211MgmtBase method. More...
 
virtual void handleCommand (int msgkind, cObject *ctrl) override
 Implements abstract Ieee80211MgmtBase method. More...
 
virtual Ieee80211DataFrameencapsulate (cPacket *msg)
 Utility function for handleUpperMessage() More...
 
virtual cPacket * decapsulate (Ieee80211DataFrame *frame)
 Utility method to decapsulate a data frame. More...
 
virtual void startAuthentication (APInfo *ap, simtime_t timeout)
 Utility function: sends authentication request. More...
 
virtual void startAssociation (APInfo *ap, simtime_t timeout)
 Utility function: sends association request. More...
 
virtual APInfolookupAP (const MACAddress &address)
 Utility function: looks up AP in our AP list. More...
 
virtual void clearAPList ()
 Utility function: clear the AP list, and cancel any pending authentications. More...
 
virtual void changeChannel (int channelNum)
 Utility function: switches to the given radio channel. More...
 
virtual void storeAPInfo (const MACAddress &address, const Ieee80211BeaconFrameBody &body)
 Stores AP info received in a beacon or probe response. More...
 
virtual bool scanNextChannel ()
 Switches to the next channel to scan; returns true if done (there wasn't any more channel to scan). More...
 
virtual void sendProbeRequest ()
 Broadcasts a Probe Request. More...
 
virtual void beaconLost ()
 Missed a few consecutive beacons. More...
 
virtual void sendScanConfirm ()
 Sends back result of scanning to the agent. More...
 
virtual void sendAuthenticationConfirm (APInfo *ap, int resultCode)
 Sends back result of authentication to the agent. More...
 
virtual void sendAssociationConfirm (APInfo *ap, int resultCode)
 Sends back result of association to the agent. More...
 
virtual void disassociate ()
 Utility function: Cancel the existing association. More...
 
virtual void sendConfirm (Ieee80211PrimConfirm *confirm, int resultCode)
 Utility function: sends a confirmation to the agent. More...
 
virtual void sendManagementFrame (Ieee80211ManagementFrame *frame, const MACAddress &address)
 Utility function: sends a management frame. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, long value, cObject *details) override
 Called by the signal handler whenever a change occurs we're interested in. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
virtual int statusCodeToPrimResultCode (int statusCode)
 Utility function: converts Ieee80211StatusCode (->frame) to Ieee80211PrimResultCode (->primitive) More...
 
Processing of different frame types
virtual void handleDataFrame (Ieee80211DataFrame *frame) override
 
virtual void handleAuthenticationFrame (Ieee80211AuthenticationFrame *frame) override
 
virtual void handleDeauthenticationFrame (Ieee80211DeauthenticationFrame *frame) override
 
virtual void handleAssociationRequestFrame (Ieee80211AssociationRequestFrame *frame) override
 
virtual void handleAssociationResponseFrame (Ieee80211AssociationResponseFrame *frame) override
 
virtual void handleReassociationRequestFrame (Ieee80211ReassociationRequestFrame *frame) override
 
virtual void handleReassociationResponseFrame (Ieee80211ReassociationResponseFrame *frame) override
 
virtual void handleDisassociationFrame (Ieee80211DisassociationFrame *frame) override
 
virtual void handleBeaconFrame (Ieee80211BeaconFrame *frame) override
 
virtual void handleProbeRequestFrame (Ieee80211ProbeRequestFrame *frame) override
 
virtual void handleProbeResponseFrame (Ieee80211ProbeResponseFrame *frame) override
 
Processing of different agent commands
virtual void processScanCommand (Ieee80211Prim_ScanRequest *ctrl)
 
virtual void processAuthenticateCommand (Ieee80211Prim_AuthenticateRequest *ctrl)
 
virtual void processDeauthenticateCommand (Ieee80211Prim_DeauthenticateRequest *ctrl)
 
virtual void processAssociateCommand (Ieee80211Prim_AssociateRequest *ctrl)
 
virtual void processReassociateCommand (Ieee80211Prim_ReassociateRequest *ctrl)
 
virtual void processDisassociateCommand (Ieee80211Prim_DisassociateRequest *ctrl)
 
- 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 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 start ()
 lifecycle support More...
 
virtual void stop ()
 

Protected Attributes

cModule * host
 
IInterfaceTableinterfaceTable
 
InterfaceEntrymyIface
 
int numChannels
 
bool isScanning
 
ScanningInfo scanning
 
AccessPointList apList
 
bool isAssociated
 
cMessage * assocTimeoutMsg
 
AssociatedAPInfo assocAP
 
- Protected Attributes inherited from inet::ieee80211::Ieee80211MgmtBase
MACAddress myAddress
 
bool isOperational
 
long numDataFramesReceived
 
long numMgmtFramesReceived
 
long numMgmtFramesDropped
 

Detailed Description

Used in 802.11 infrastructure mode: handles management frames for a station (STA).

See corresponding NED file for a detailed description.

Author
Andras Varga

Member Typedef Documentation

Constructor & Destructor Documentation

inet::ieee80211::Ieee80211MgmtSTA::Ieee80211MgmtSTA ( )
inline
118 : host(nullptr), interfaceTable(nullptr), myIface(nullptr), numChannels(-1), isScanning(false), isAssociated(false), assocTimeoutMsg(nullptr) {}
cMessage * assocTimeoutMsg
Definition: Ieee80211MgmtSTA.h:114
int numChannels
Definition: Ieee80211MgmtSTA.h:101
IInterfaceTable * interfaceTable
Definition: Ieee80211MgmtSTA.h:97
bool isScanning
Definition: Ieee80211MgmtSTA.h:104
InterfaceEntry * myIface
Definition: Ieee80211MgmtSTA.h:98
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
cModule * host
Definition: Ieee80211MgmtSTA.h:96

Member Function Documentation

void inet::ieee80211::Ieee80211MgmtSTA::beaconLost ( )
protectedvirtual

Missed a few consecutive beacons.

292 {
293  EV << "Missed a few consecutive beacons -- AP is considered lost\n";
294  emit(NF_L2_BEACON_LOST, myIface);
295 }
simsignal_t NF_L2_BEACON_LOST
Definition: NotifierConsts.cc:35
InterfaceEntry * myIface
Definition: Ieee80211MgmtSTA.h:98
void inet::ieee80211::Ieee80211MgmtSTA::changeChannel ( int  channelNum)
protectedvirtual

Utility function: switches to the given radio channel.

281 {
282  EV << "Tuning to channel #" << channelNum << "\n";
283 
284  Ieee80211ConfigureRadioCommand *configureCommand = new Ieee80211ConfigureRadioCommand();
285  configureCommand->setChannelNumber(channelNum);
286  cMessage *msg = new cMessage("changeChannel", RADIO_C_CONFIGURE);
287  msg->setControlInfo(configureCommand);
288  send(msg, "macOut");
289 }
Definition: RadioControlInfo_m.h:56
void inet::ieee80211::Ieee80211MgmtSTA::clearAPList ( )
protectedvirtual

Utility function: clear the AP list, and cancel any pending authentications.

272 {
273  for (auto & elem : apList)
274  if (elem.authTimeoutMsg)
275  delete cancelEvent(elem.authTimeoutMsg);
276 
277  apList.clear();
278 }
AccessPointList apList
Definition: Ieee80211MgmtSTA.h:110
cPacket * inet::ieee80211::Ieee80211MgmtSTA::decapsulate ( Ieee80211DataFrame frame)
protectedvirtual

Utility method to decapsulate a data frame.

242 {
243  cPacket *payload = frame->decapsulate();
244 
245  Ieee802Ctrl *ctrl = new Ieee802Ctrl();
246  ctrl->setSrc(frame->getAddress3());
247  ctrl->setDest(frame->getReceiverAddress());
248  if (frame->getType() == ST_DATA_WITH_QOS) {
249  int tid = frame->getTid();
250  if (tid < 8)
251  ctrl->setUserPriority(tid); // TID values 0..7 are UP
252  }
253  Ieee80211DataFrameWithSNAP *frameWithSNAP = dynamic_cast<Ieee80211DataFrameWithSNAP *>(frame);
254  if (frameWithSNAP)
255  ctrl->setEtherType(frameWithSNAP->getEtherType());
256  payload->setControlInfo(ctrl);
257 
258  delete frame;
259  return payload;
260 }
Definition: Ieee80211Frame_m.h:117
void inet::ieee80211::Ieee80211MgmtSTA::disassociate ( )
protectedvirtual

Utility function: Cancel the existing association.

570 {
571  EV << "Disassociating from AP address=" << assocAP.address << "\n";
572  ASSERT(isAssociated);
573  isAssociated = false;
574  delete cancelEvent(assocAP.beaconTimeoutMsg);
575  assocAP.beaconTimeoutMsg = nullptr;
576  assocAP = AssociatedAPInfo(); // clear it
577 }
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
cMessage * beaconTimeoutMsg
Definition: Ieee80211MgmtSTA.h:90
Ieee80211DataFrame * inet::ieee80211::Ieee80211MgmtSTA::encapsulate ( cPacket *  msg)
protectedvirtual

Utility function for handleUpperMessage()

215 {
216  Ieee80211DataFrameWithSNAP *frame = new Ieee80211DataFrameWithSNAP(msg->getName());
217 
218  // frame goes to the AP
219  frame->setToDS(true);
220 
221  // receiver is the AP
222  frame->setReceiverAddress(assocAP.address);
223 
224  // destination address is in address3
225  Ieee802Ctrl *ctrl = check_and_cast<Ieee802Ctrl *>(msg->removeControlInfo());
226  frame->setAddress3(ctrl->getDest());
227  frame->setEtherType(ctrl->getEtherType());
228  int up = ctrl->getUserPriority();
229  if (up >= 0) {
230  // make it a QoS frame, and set TID
231  frame->setType(ST_DATA_WITH_QOS);
232  frame->addBitLength(QOSCONTROL_BITS);
233  frame->setTid(up);
234  }
235  delete ctrl;
236 
237  frame->encapsulate(msg);
238  return frame;
239 }
Definition: Ieee80211Frame_m.h:117
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
const unsigned int QOSCONTROL_BITS
Definition: Ieee80211Frame_m.h:48
void inet::ieee80211::Ieee80211MgmtSTA::handleAssociationRequestFrame ( Ieee80211AssociationRequestFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

713 {
714  dropManagementFrame(frame);
715 }
virtual void dropManagementFrame(Ieee80211ManagementFrame *frame)
Utility method to dispose of an unhandled frame.
Definition: Ieee80211MgmtBase.cc:90
void inet::ieee80211::Ieee80211MgmtSTA::handleAssociationResponseFrame ( Ieee80211AssociationResponseFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

718 {
719  EV << "Received Association Response frame\n";
720 
721  if (!assocTimeoutMsg) {
722  EV << "No association in progress, ignoring frame\n";
723  delete frame;
724  return;
725  }
726 
727  // extract frame contents
728  MACAddress address = frame->getTransmitterAddress();
729  int statusCode = frame->getBody().getStatusCode();
730  //XXX short aid;
731  //XXX Ieee80211SupportedRatesElement supportedRates;
732  delete frame;
733 
734  // look up AP data structure
735  APInfo *ap = lookupAP(address);
736  if (!ap)
737  throw cRuntimeError("handleAssociationResponseFrame: AP not known: address=%s", address.str().c_str());
738 
739  if (isAssociated) {
740  EV << "Breaking existing association with AP address=" << assocAP.address << "\n";
741  isAssociated = false;
742  delete cancelEvent(assocAP.beaconTimeoutMsg);
743  assocAP.beaconTimeoutMsg = nullptr;
744  assocAP = AssociatedAPInfo();
745  }
746 
747  delete cancelEvent(assocTimeoutMsg);
748  assocTimeoutMsg = nullptr;
749 
750  if (statusCode != SC_SUCCESSFUL) {
751  EV << "Association failed with AP address=" << ap->address << "\n";
752  }
753  else {
754  EV << "Association successful, AP address=" << ap->address << "\n";
755 
756  // change our state to "associated"
757  isAssociated = true;
758  (APInfo&)assocAP = (*ap);
759 
760  emit(NF_L2_ASSOCIATED, myIface, ap);
761 
762  assocAP.beaconTimeoutMsg = new cMessage("beaconTimeout", MK_BEACON_TIMEOUT);
764  }
765 
766  // report back to agent
768 }
cMessage * assocTimeoutMsg
Definition: Ieee80211MgmtSTA.h:114
simtime_t beaconInterval
Definition: Ieee80211MgmtSTA.h:67
virtual void sendAssociationConfirm(APInfo *ap, int resultCode)
Sends back result of association to the agent.
Definition: Ieee80211MgmtSTA.cc:586
virtual int statusCodeToPrimResultCode(int statusCode)
Utility function: converts Ieee80211StatusCode (->frame) to Ieee80211PrimResultCode (->primitive) ...
Definition: Ieee80211MgmtSTA.cc:599
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
Definition: Ieee80211MgmtFrames_m.h:175
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
#define MAX_BEACONS_MISSED
Definition: Ieee80211MgmtSTA.cc:51
InterfaceEntry * myIface
Definition: Ieee80211MgmtSTA.h:98
#define MK_BEACON_TIMEOUT
Definition: Ieee80211MgmtSTA.cc:49
simsignal_t NF_L2_ASSOCIATED
Definition: NotifierConsts.cc:36
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
cMessage * beaconTimeoutMsg
Definition: Ieee80211MgmtSTA.h:90
void inet::ieee80211::Ieee80211MgmtSTA::handleAuthenticationFrame ( Ieee80211AuthenticationFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

617 {
618  MACAddress address = frame->getTransmitterAddress();
619  int frameAuthSeq = frame->getBody().getSequenceNumber();
620  EV << "Received Authentication frame from address=" << address << ", seqNum=" << frameAuthSeq << "\n";
621 
622  APInfo *ap = lookupAP(address);
623  if (!ap) {
624  EV << "AP not known, discarding authentication frame\n";
625  delete frame;
626  return;
627  }
628 
629  // what if already authenticated with AP
630  if (ap->isAuthenticated) {
631  EV << "AP already authenticated, ignoring frame\n";
632  delete frame;
633  return;
634  }
635 
636  // is authentication is in progress with this AP?
637  if (!ap->authTimeoutMsg) {
638  EV << "No authentication in progress with AP, ignoring frame\n";
639  delete frame;
640  return;
641  }
642 
643  // check authentication sequence number is OK
644  if (frameAuthSeq != ap->authSeqExpected) {
645  // wrong sequence number: send error and return
646  EV << "Wrong sequence number, " << ap->authSeqExpected << " expected\n";
647  Ieee80211AuthenticationFrame *resp = new Ieee80211AuthenticationFrame("Auth-ERROR");
648  resp->getBody().setStatusCode(SC_AUTH_OUT_OF_SEQ);
649  sendManagementFrame(resp, frame->getTransmitterAddress());
650  delete frame;
651 
652  // cancel timeout, send error to agent
653  delete cancelEvent(ap->authTimeoutMsg);
654  ap->authTimeoutMsg = nullptr;
655  sendAuthenticationConfirm(ap, PRC_REFUSED); //XXX or what resultCode?
656  return;
657  }
658 
659  // check if more exchanges are needed for auth to be complete
660  int statusCode = frame->getBody().getStatusCode();
661 
662  if (statusCode == SC_SUCCESSFUL && !frame->getBody().getIsLast()) {
663  EV << "More steps required, sending another Authentication frame\n";
664 
665  // more steps required, send another Authentication frame
666  Ieee80211AuthenticationFrame *resp = new Ieee80211AuthenticationFrame("Auth");
667  resp->getBody().setSequenceNumber(frameAuthSeq + 1);
668  resp->getBody().setStatusCode(SC_SUCCESSFUL);
669  // XXX frame length could be increased to account for challenge text length etc.
670  sendManagementFrame(resp, address);
671  ap->authSeqExpected += 2;
672  }
673  else {
674  if (statusCode == SC_SUCCESSFUL)
675  EV << "Authentication successful\n";
676  else
677  EV << "Authentication failed\n";
678 
679  // authentication completed
680  ap->isAuthenticated = (statusCode == SC_SUCCESSFUL);
681  delete cancelEvent(ap->authTimeoutMsg);
682  ap->authTimeoutMsg = nullptr;
684  }
685 
686  delete frame;
687 }
virtual int statusCodeToPrimResultCode(int statusCode)
Utility function: converts Ieee80211StatusCode (->frame) to Ieee80211PrimResultCode (->primitive) ...
Definition: Ieee80211MgmtSTA.cc:599
Definition: Ieee80211Primitives_m.h:142
Definition: Ieee80211MgmtFrames_m.h:175
virtual void sendManagementFrame(Ieee80211ManagementFrame *frame, const MACAddress &address)
Utility function: sends a management frame.
Definition: Ieee80211MgmtSTA.cc:297
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
Definition: Ieee80211MgmtFrames_m.h:181
virtual void sendAuthenticationConfirm(APInfo *ap, int resultCode)
Sends back result of authentication to the agent.
Definition: Ieee80211MgmtSTA.cc:579
void inet::ieee80211::Ieee80211MgmtSTA::handleBeaconFrame ( Ieee80211BeaconFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

804 {
805  EV << "Received Beacon frame\n";
806  storeAPInfo(frame->getTransmitterAddress(), frame->getBody());
807 
808  // if it is out associate AP, restart beacon timeout
809  if (isAssociated && frame->getTransmitterAddress() == assocAP.address) {
810  EV << "Beacon is from associated AP, restarting beacon timeout timer\n";
811  ASSERT(assocAP.beaconTimeoutMsg != nullptr);
812  cancelEvent(assocAP.beaconTimeoutMsg);
814 
815  //APInfo *ap = lookupAP(frame->getTransmitterAddress());
816  //ASSERT(ap!=nullptr);
817  }
818 
819  delete frame;
820 }
simtime_t beaconInterval
Definition: Ieee80211MgmtSTA.h:67
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
virtual void storeAPInfo(const MACAddress &address, const Ieee80211BeaconFrameBody &body)
Stores AP info received in a beacon or probe response.
Definition: Ieee80211MgmtSTA.cc:834
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
#define MAX_BEACONS_MISSED
Definition: Ieee80211MgmtSTA.cc:51
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
cMessage * beaconTimeoutMsg
Definition: Ieee80211MgmtSTA.h:90
void inet::ieee80211::Ieee80211MgmtSTA::handleCommand ( int  msgkind,
cObject *  ctrl 
)
overrideprotectedvirtual

Implements abstract Ieee80211MgmtBase method.

Implements inet::ieee80211::Ieee80211MgmtBase.

194 {
195  if (dynamic_cast<Ieee80211Prim_ScanRequest *>(ctrl))
196  processScanCommand((Ieee80211Prim_ScanRequest *)ctrl);
197  else if (dynamic_cast<Ieee80211Prim_AuthenticateRequest *>(ctrl))
198  processAuthenticateCommand((Ieee80211Prim_AuthenticateRequest *)ctrl);
199  else if (dynamic_cast<Ieee80211Prim_DeauthenticateRequest *>(ctrl))
200  processDeauthenticateCommand((Ieee80211Prim_DeauthenticateRequest *)ctrl);
201  else if (dynamic_cast<Ieee80211Prim_AssociateRequest *>(ctrl))
202  processAssociateCommand((Ieee80211Prim_AssociateRequest *)ctrl);
203  else if (dynamic_cast<Ieee80211Prim_ReassociateRequest *>(ctrl))
204  processReassociateCommand((Ieee80211Prim_ReassociateRequest *)ctrl);
205  else if (dynamic_cast<Ieee80211Prim_DisassociateRequest *>(ctrl))
206  processDisassociateCommand((Ieee80211Prim_DisassociateRequest *)ctrl);
207  else if (ctrl)
208  throw cRuntimeError("handleCommand(): unrecognized control info class `%s'", ctrl->getClassName());
209  else
210  throw cRuntimeError("handleCommand(): control info is nullptr");
211  delete ctrl;
212 }
virtual void processDeauthenticateCommand(Ieee80211Prim_DeauthenticateRequest *ctrl)
Definition: Ieee80211MgmtSTA.cc:509
virtual void processDisassociateCommand(Ieee80211Prim_DisassociateRequest *ctrl)
Definition: Ieee80211MgmtSTA.cc:550
virtual void processAssociateCommand(Ieee80211Prim_AssociateRequest *ctrl)
Definition: Ieee80211MgmtSTA.cc:534
virtual void processScanCommand(Ieee80211Prim_ScanRequest *ctrl)
Definition: Ieee80211MgmtSTA.cc:394
virtual void processAuthenticateCommand(Ieee80211Prim_AuthenticateRequest *ctrl)
Definition: Ieee80211MgmtSTA.cc:500
virtual void processReassociateCommand(Ieee80211Prim_ReassociateRequest *ctrl)
Definition: Ieee80211MgmtSTA.cc:543
void inet::ieee80211::Ieee80211MgmtSTA::handleDataFrame ( Ieee80211DataFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

605 {
606  // Only send the Data frame up to the higher layer if the STA is associated with an AP,
607  // else delete the frame
608  if (isAssociated)
609  sendUp(decapsulate(frame));
610  else {
611  EV << "Rejecting data frame as STA is not associated with an AP" << endl;
612  delete frame;
613  }
614 }
virtual void sendUp(cMessage *msg)
Utility method: sends the packet to the upper layer.
Definition: Ieee80211MgmtBase.cc:97
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
virtual cPacket * decapsulate(Ieee80211DataFrame *frame)
Utility method to decapsulate a data frame.
Definition: Ieee80211MgmtSTA.cc:241
void inet::ieee80211::Ieee80211MgmtSTA::handleDeauthenticationFrame ( Ieee80211DeauthenticationFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

690 {
691  EV << "Received Deauthentication frame\n";
692  const MACAddress& address = frame->getAddress3(); // source address
693  APInfo *ap = lookupAP(address);
694  if (!ap || !ap->isAuthenticated) {
695  EV << "Unknown AP, or not authenticated with that AP -- ignoring frame\n";
696  delete frame;
697  return;
698  }
699  if (ap->authTimeoutMsg) {
700  delete cancelEvent(ap->authTimeoutMsg);
701  ap->authTimeoutMsg = nullptr;
702  EV << "Cancelling pending authentication\n";
703  delete frame;
704  return;
705  }
706 
707  EV << "Setting isAuthenticated flag for that AP to false\n";
708  ap->isAuthenticated = false;
709  delete frame;
710 }
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
void inet::ieee80211::Ieee80211MgmtSTA::handleDisassociationFrame ( Ieee80211DisassociationFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

782 {
783  EV << "Received Disassociation frame\n";
784  const MACAddress& address = frame->getAddress3(); // source address
785 
786  if (assocTimeoutMsg) {
787  // pending association
788  delete cancelEvent(assocTimeoutMsg);
789  assocTimeoutMsg = nullptr;
790  }
791  if (!isAssociated || address != assocAP.address) {
792  EV << "Not associated with that AP -- ignoring frame\n";
793  delete frame;
794  return;
795  }
796 
797  EV << "Setting isAssociated flag to false\n";
798  isAssociated = false;
799  delete cancelEvent(assocAP.beaconTimeoutMsg);
800  assocAP.beaconTimeoutMsg = nullptr;
801 }
cMessage * assocTimeoutMsg
Definition: Ieee80211MgmtSTA.h:114
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
cMessage * beaconTimeoutMsg
Definition: Ieee80211MgmtSTA.h:90
void inet::ieee80211::Ieee80211MgmtSTA::handleProbeRequestFrame ( Ieee80211ProbeRequestFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

823 {
824  dropManagementFrame(frame);
825 }
virtual void dropManagementFrame(Ieee80211ManagementFrame *frame)
Utility method to dispose of an unhandled frame.
Definition: Ieee80211MgmtBase.cc:90
void inet::ieee80211::Ieee80211MgmtSTA::handleProbeResponseFrame ( Ieee80211ProbeResponseFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

828 {
829  EV << "Received Probe Response frame\n";
830  storeAPInfo(frame->getTransmitterAddress(), frame->getBody());
831  delete frame;
832 }
virtual void storeAPInfo(const MACAddress &address, const Ieee80211BeaconFrameBody &body)
Stores AP info received in a beacon or probe response.
Definition: Ieee80211MgmtSTA.cc:834
void inet::ieee80211::Ieee80211MgmtSTA::handleReassociationRequestFrame ( Ieee80211ReassociationRequestFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

771 {
772  dropManagementFrame(frame);
773 }
virtual void dropManagementFrame(Ieee80211ManagementFrame *frame)
Utility method to dispose of an unhandled frame.
Definition: Ieee80211MgmtBase.cc:90
void inet::ieee80211::Ieee80211MgmtSTA::handleReassociationResponseFrame ( Ieee80211ReassociationResponseFrame frame)
overrideprotectedvirtual

Implements inet::ieee80211::Ieee80211MgmtBase.

776 {
777  EV << "Received Reassociation Response frame\n";
778  //TBD handle with the same code as Association Response?
779 }
void inet::ieee80211::Ieee80211MgmtSTA::handleTimer ( cMessage *  msg)
overrideprotectedvirtual

Implements abstract Ieee80211MgmtBase method.

Implements inet::ieee80211::Ieee80211MgmtBase.

126 {
127  if (msg->getKind() == MK_AUTH_TIMEOUT) {
128  // authentication timed out
129  APInfo *ap = (APInfo *)msg->getContextPointer();
130  EV << "Authentication timed out, AP address = " << ap->address << "\n";
131 
132  // send back failure report to agent
134  }
135  else if (msg->getKind() == MK_ASSOC_TIMEOUT) {
136  // association timed out
137  APInfo *ap = (APInfo *)msg->getContextPointer();
138  EV << "Association timed out, AP address = " << ap->address << "\n";
139 
140  // send back failure report to agent
142  }
143  else if (msg->getKind() == MK_SCAN_MAXCHANNELTIME) {
144  // go to next channel during scanning
145  bool done = scanNextChannel();
146  if (done)
147  sendScanConfirm(); // send back response to agents' "scan" command
148  delete msg;
149  }
150  else if (msg->getKind() == MK_SCAN_SENDPROBE) {
151  // Active Scan: send a probe request, then wait for minChannelTime (11.1.3.2.2)
152  delete msg;
154  cMessage *timerMsg = new cMessage("minChannelTime", MK_SCAN_MINCHANNELTIME);
155  scheduleAt(simTime() + scanning.minChannelTime, timerMsg); //XXX actually, we should start waiting after ProbeReq actually got transmitted
156  }
157  else if (msg->getKind() == MK_SCAN_MINCHANNELTIME) {
158  // Active Scan: after minChannelTime, possibly listen for the remaining time until maxChannelTime
159  delete msg;
161  EV << "Busy channel detected during minChannelTime, continuing listening until maxChannelTime elapses\n";
162  cMessage *timerMsg = new cMessage("maxChannelTime", MK_SCAN_MAXCHANNELTIME);
163  scheduleAt(simTime() + scanning.maxChannelTime - scanning.minChannelTime, timerMsg);
164  }
165  else {
166  EV << "Channel was empty during minChannelTime, going to next channel\n";
167  bool done = scanNextChannel();
168  if (done)
169  sendScanConfirm(); // send back response to agents' "scan" command
170  }
171  }
172  else if (msg->getKind() == MK_BEACON_TIMEOUT) {
173  // missed a few consecutive beacons
174  beaconLost();
175  }
176  else {
177  throw cRuntimeError("internal error: unrecognized timer '%s'", msg->getName());
178  }
179 }
virtual void beaconLost()
Missed a few consecutive beacons.
Definition: Ieee80211MgmtSTA.cc:291
virtual void sendAssociationConfirm(APInfo *ap, int resultCode)
Sends back result of association to the agent.
Definition: Ieee80211MgmtSTA.cc:586
#define MK_SCAN_SENDPROBE
Definition: Ieee80211MgmtSTA.cc:46
virtual bool scanNextChannel()
Switches to the next channel to scan; returns true if done (there wasn&#39;t any more channel to scan)...
Definition: Ieee80211MgmtSTA.cc:439
virtual void sendScanConfirm()
Sends back result of scanning to the agent.
Definition: Ieee80211MgmtSTA.cc:477
ScanningInfo scanning
Definition: Ieee80211MgmtSTA.h:105
simtime_t maxChannelTime
Definition: Ieee80211MgmtSTA.h:55
#define MK_SCAN_MINCHANNELTIME
Definition: Ieee80211MgmtSTA.cc:47
#define MK_SCAN_MAXCHANNELTIME
Definition: Ieee80211MgmtSTA.cc:48
simtime_t minChannelTime
Definition: Ieee80211MgmtSTA.h:54
bool busyChannelDetected
Definition: Ieee80211MgmtSTA.h:53
#define MK_ASSOC_TIMEOUT
Definition: Ieee80211MgmtSTA.cc:45
Definition: Ieee80211Primitives_m.h:140
#define MK_AUTH_TIMEOUT
Definition: Ieee80211MgmtSTA.cc:44
#define MK_BEACON_TIMEOUT
Definition: Ieee80211MgmtSTA.cc:49
virtual void sendAuthenticationConfirm(APInfo *ap, int resultCode)
Sends back result of authentication to the agent.
Definition: Ieee80211MgmtSTA.cc:579
virtual void sendProbeRequest()
Broadcasts a Probe Request.
Definition: Ieee80211MgmtSTA.cc:469
void inet::ieee80211::Ieee80211MgmtSTA::handleUpperMessage ( cPacket *  msg)
overrideprotectedvirtual

Implements abstract Ieee80211MgmtBase method.

Implements inet::ieee80211::Ieee80211MgmtBase.

182 {
184  EV << "STA is not associated with an access point, discarding packet" << msg << "\n";
185  delete msg;
186  return;
187  }
188 
189  Ieee80211DataFrame *frame = encapsulate(msg);
190  sendDown(frame);
191 }
virtual void sendDown(cPacket *frame)
Utility method for implementing handleUpperMessage(): send message to MAC.
Definition: Ieee80211MgmtBase.cc:84
bool isUnspecified() const
Returns true if all address bytes are zero.
Definition: MACAddress.h:151
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
virtual Ieee80211DataFrame * encapsulate(cPacket *msg)
Utility function for handleUpperMessage()
Definition: Ieee80211MgmtSTA.cc:214
void inet::ieee80211::Ieee80211MgmtSTA::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::ieee80211::Ieee80211MgmtBase.

97 {
99 
100  if (stage == INITSTAGE_LOCAL) {
101  isScanning = false;
102  isAssociated = false;
103  assocTimeoutMsg = nullptr;
104  myIface = nullptr;
105  numChannels = par("numChannels");
106 
107  host = getContainingNode(this);
108  host->subscribe(NF_LINK_FULL_PROMISCUOUS, this);
109 
110  WATCH(isScanning);
111  WATCH(isAssociated);
112 
113  WATCH(scanning);
114  WATCH(assocAP);
115  WATCH_LIST(apList);
116  }
117  else if (stage == INITSTAGE_LINK_LAYER_2) {
118  IInterfaceTable *ift = findModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
119  if (ift) {
120  myIface = ift->getInterfaceByName(utils::stripnonalnum(findModuleUnderContainingNode(this)->getFullName()).c_str());
121  }
122  }
123 }
cMessage * assocTimeoutMsg
Definition: Ieee80211MgmtSTA.h:114
simsignal_t NF_LINK_FULL_PROMISCUOUS
Definition: NotifierConsts.cc:45
cModule * findModuleUnderContainingNode(const cModule *from)
Find the ancestor module under the node containing the given module.
Definition: ModuleAccess.cc:73
std::string stripnonalnum(const char *s)
Removes non-alphanumeric characters from the given string.
Definition: INETUtils.cc:56
ScanningInfo scanning
Definition: Ieee80211MgmtSTA.h:105
int numChannels
Definition: Ieee80211MgmtSTA.h:101
Local initializations.
Definition: InitStages.h:35
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
bool isScanning
Definition: Ieee80211MgmtSTA.h:104
InterfaceEntry * myIface
Definition: Ieee80211MgmtSTA.h:98
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
Additional link-layer initializations that depend on the previous stage.
Definition: InitStages.h:64
cModule * host
Definition: Ieee80211MgmtSTA.h:96
virtual void initialize(int) override
Definition: Ieee80211MgmtBase.cc:30
AccessPointList apList
Definition: Ieee80211MgmtSTA.h:110
Ieee80211MgmtSTA::APInfo * inet::ieee80211::Ieee80211MgmtSTA::lookupAP ( const MACAddress address)
protectedvirtual

Utility function: looks up AP in our AP list.

Returns nullptr if not found.

263 {
264  for (auto & elem : apList)
265  if (elem.address == address)
266  return &(elem);
267 
268  return nullptr;
269 }
AccessPointList apList
Definition: Ieee80211MgmtSTA.h:110
virtual int inet::ieee80211::Ieee80211MgmtSTA::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::ieee80211::Ieee80211MgmtBase.

121 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::ieee80211::Ieee80211MgmtSTA::processAssociateCommand ( Ieee80211Prim_AssociateRequest ctrl)
protectedvirtual
535 {
536  const MACAddress& address = ctrl->getAddress();
537  APInfo *ap = lookupAP(address);
538  if (!ap)
539  throw cRuntimeError("processAssociateCommand: AP not known: address = %s", address.str().c_str());
540  startAssociation(ap, ctrl->getTimeout());
541 }
virtual void startAssociation(APInfo *ap, simtime_t timeout)
Utility function: sends association request.
Definition: Ieee80211MgmtSTA.cc:333
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
void inet::ieee80211::Ieee80211MgmtSTA::processAuthenticateCommand ( Ieee80211Prim_AuthenticateRequest ctrl)
protectedvirtual
501 {
502  const MACAddress& address = ctrl->getAddress();
503  APInfo *ap = lookupAP(address);
504  if (!ap)
505  throw cRuntimeError("processAuthenticateCommand: AP not known: address = %s", address.str().c_str());
506  startAuthentication(ap, ctrl->getTimeout());
507 }
virtual void startAuthentication(APInfo *ap, simtime_t timeout)
Utility function: sends authentication request.
Definition: Ieee80211MgmtSTA.cc:307
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
void inet::ieee80211::Ieee80211MgmtSTA::processDeauthenticateCommand ( Ieee80211Prim_DeauthenticateRequest ctrl)
protectedvirtual
510 {
511  const MACAddress& address = ctrl->getAddress();
512  APInfo *ap = lookupAP(address);
513  if (!ap)
514  throw cRuntimeError("processDeauthenticateCommand: AP not known: address = %s", address.str().c_str());
515 
516  if (isAssociated && assocAP.address == address)
517  disassociate();
518 
519  if (ap->isAuthenticated)
520  ap->isAuthenticated = false;
521 
522  // cancel possible pending authentication timer
523  if (ap->authTimeoutMsg) {
524  delete cancelEvent(ap->authTimeoutMsg);
525  ap->authTimeoutMsg = nullptr;
526  }
527 
528  // create and send deauthentication request
529  Ieee80211DeauthenticationFrame *frame = new Ieee80211DeauthenticationFrame("Deauth");
530  frame->getBody().setReasonCode(ctrl->getReasonCode());
531  sendManagementFrame(frame, address);
532 }
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
virtual void disassociate()
Utility function: Cancel the existing association.
Definition: Ieee80211MgmtSTA.cc:569
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
virtual void sendManagementFrame(Ieee80211ManagementFrame *frame, const MACAddress &address)
Utility function: sends a management frame.
Definition: Ieee80211MgmtSTA.cc:297
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
void inet::ieee80211::Ieee80211MgmtSTA::processDisassociateCommand ( Ieee80211Prim_DisassociateRequest ctrl)
protectedvirtual
551 {
552  const MACAddress& address = ctrl->getAddress();
553 
554  if (isAssociated && address == assocAP.address) {
555  disassociate();
556  }
557  else if (assocTimeoutMsg) {
558  // pending association
559  delete cancelEvent(assocTimeoutMsg);
560  assocTimeoutMsg = nullptr;
561  }
562 
563  // create and send disassociation request
564  Ieee80211DisassociationFrame *frame = new Ieee80211DisassociationFrame("Disass");
565  frame->getBody().setReasonCode(ctrl->getReasonCode());
566  sendManagementFrame(frame, address);
567 }
cMessage * assocTimeoutMsg
Definition: Ieee80211MgmtSTA.h:114
MACAddress address
Definition: Ieee80211MgmtSTA.h:64
virtual void disassociate()
Utility function: Cancel the existing association.
Definition: Ieee80211MgmtSTA.cc:569
AssociatedAPInfo assocAP
Definition: Ieee80211MgmtSTA.h:115
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
virtual void sendManagementFrame(Ieee80211ManagementFrame *frame, const MACAddress &address)
Utility function: sends a management frame.
Definition: Ieee80211MgmtSTA.cc:297
void inet::ieee80211::Ieee80211MgmtSTA::processReassociateCommand ( Ieee80211Prim_ReassociateRequest ctrl)
protectedvirtual
544 {
545  // treat the same way as association
546  //XXX refine
548 }
virtual void processAssociateCommand(Ieee80211Prim_AssociateRequest *ctrl)
Definition: Ieee80211MgmtSTA.cc:534
void inet::ieee80211::Ieee80211MgmtSTA::processScanCommand ( Ieee80211Prim_ScanRequest ctrl)
protectedvirtual
395 {
396  EV << "Received Scan Request from agent, clearing AP list and starting scanning...\n";
397 
398  if (isScanning)
399  throw cRuntimeError("processScanCommand: scanning already in progress");
400  if (isAssociated) {
401  disassociate();
402  }
403  else if (assocTimeoutMsg) {
404  EV << "Cancelling ongoing association process\n";
405  delete cancelEvent(assocTimeoutMsg);
406  assocTimeoutMsg = nullptr;
407  }
408 
409  // clear existing AP list (and cancel any pending authentications) -- we want to start with a clean page
410  clearAPList();
411 
412  // fill in scanning state
413  ASSERT(ctrl->getBSSType() == BSSTYPE_INFRASTRUCTURE);
414  scanning.bssid = ctrl->getBSSID().isUnspecified() ? MACAddress::BROADCAST_ADDRESS : ctrl->getBSSID();
415  scanning.ssid = ctrl->getSSID();
416  scanning.activeScan = ctrl->getActiveScan();
417  scanning.probeDelay = ctrl->getProbeDelay();
418  scanning.channelList.clear();
419  scanning.minChannelTime = ctrl->getMinChannelTime();
420  scanning.maxChannelTime = ctrl->getMaxChannelTime();
422 
423  // channel list to scan (default: all channels)
424  for (int i = 0; i < (int)ctrl->getChannelListArraySize(); i++)
425  scanning.channelList.push_back(ctrl->getChannelList(i));
426  if (scanning.channelList.empty())
427  for (int i = 0; i < numChannels; i++)
428  scanning.channelList.push_back(i);
429 
430 
431  // start scanning
432  if (scanning.activeScan)
433  host->subscribe(IRadio::receptionStateChangedSignal, this);
434  scanning.currentChannelIndex = -1; // so we'll start with index==0
435  isScanning = true;
436  scanNextChannel();
437 }
std::string ssid
Definition: Ieee80211MgmtSTA.h:48
cMessage * assocTimeoutMsg
Definition: Ieee80211MgmtSTA.h:114
bool isUnspecified() const
Returns true if all address bytes are zero.
Definition: MACAddress.h:151
bool activeScan
Definition: Ieee80211MgmtSTA.h:49
virtual bool scanNextChannel()
Switches to the next channel to scan; returns true if done (there wasn&#39;t any more channel to scan)...
Definition: Ieee80211MgmtSTA.cc:439
Definition: Ieee80211Primitives_m.h:113
std::vector< int > channelList
Definition: Ieee80211MgmtSTA.h:51
ScanningInfo scanning
Definition: Ieee80211MgmtSTA.h:105
simtime_t maxChannelTime
Definition: Ieee80211MgmtSTA.h:55
int numChannels
Definition: Ieee80211MgmtSTA.h:101
int currentChannelIndex
Definition: Ieee80211MgmtSTA.h:52
virtual void disassociate()
Utility function: Cancel the existing association.
Definition: Ieee80211MgmtSTA.cc:569
simtime_t minChannelTime
Definition: Ieee80211MgmtSTA.h:54
simtime_t probeDelay
Definition: Ieee80211MgmtSTA.h:50
static simsignal_t receptionStateChangedSignal
This signal is emitted every time the radio reception state changes.
Definition: IRadio.h:66
bool isScanning
Definition: Ieee80211MgmtSTA.h:104
MACAddress bssid
Definition: Ieee80211MgmtSTA.h:47
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
virtual void clearAPList()
Utility function: clear the AP list, and cancel any pending authentications.
Definition: Ieee80211MgmtSTA.cc:271
cModule * host
Definition: Ieee80211MgmtSTA.h:96
static const MACAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MACAddress.h:60
void inet::ieee80211::Ieee80211MgmtSTA::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
long  value,
cObject *  details 
)
overrideprotectedvirtual

Called by the signal handler whenever a change occurs we're interested in.

360 {
361  Enter_Method_Silent();
362  // Note that we are only subscribed during scanning!
363  if (signalID == IRadio::receptionStateChangedSignal) {
364  IRadio::ReceptionState newReceptionState = (IRadio::ReceptionState)value;
365  if (newReceptionState != IRadio::RECEPTION_STATE_UNDEFINED && newReceptionState != IRadio::RECEPTION_STATE_IDLE) {
366  EV << "busy radio channel detected during scanning\n";
368  }
369  }
370 }
The radio medium state is unknown, reception state is meaningless, signal detection is not possible...
Definition: IRadio.h:142
ReceptionState
This enumeration specifies the reception state of the radio.
Definition: IRadio.h:136
ScanningInfo scanning
Definition: Ieee80211MgmtSTA.h:105
The radio medium is free, no signal is detected.
Definition: IRadio.h:148
bool busyChannelDetected
Definition: Ieee80211MgmtSTA.h:53
static simsignal_t receptionStateChangedSignal
This signal is emitted every time the radio reception state changes.
Definition: IRadio.h:66
void inet::ieee80211::Ieee80211MgmtSTA::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual
373 {
374  Enter_Method_Silent();
375  printNotificationBanner(signalID, obj);
376 
377  // Note that we are only subscribed during scanning!
378  if (signalID == NF_LINK_FULL_PROMISCUOUS) {
379  Ieee80211DataOrMgmtFrame *frame = dynamic_cast<Ieee80211DataOrMgmtFrame *>(obj);
380  if (!frame || frame->getControlInfo() == nullptr)
381  return;
382  if (frame->getType() != ST_BEACON)
383  return;
384  Ieee80211ReceptionIndication *ctl = dynamic_cast<Ieee80211ReceptionIndication *>(frame->getControlInfo());
385  if (ctl == nullptr)
386  return;
387  Ieee80211BeaconFrame *beacon = (check_and_cast<Ieee80211BeaconFrame *>(frame));
388  APInfo *ap = lookupAP(beacon->getTransmitterAddress());
389  if (ap)
390  ap->rxPower = ctl->getRecPow();
391  }
392 }
simsignal_t NF_LINK_FULL_PROMISCUOUS
Definition: NotifierConsts.cc:45
Definition: Ieee80211Frame_m.h:103
void printNotificationBanner(simsignal_t signalID, const cObject *obj)
Utility function.
Definition: NotifierConsts.cc:109
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
double rxPower
Definition: Ieee80211MgmtSTA.h:68
bool inet::ieee80211::Ieee80211MgmtSTA::scanNextChannel ( )
protectedvirtual

Switches to the next channel to scan; returns true if done (there wasn't any more channel to scan).

440 {
441  // if we're already at the last channel, we're through
442  if (scanning.currentChannelIndex == (int)scanning.channelList.size() - 1) {
443  EV << "Finished scanning last channel\n";
444  if (scanning.activeScan)
445  host->unsubscribe(IRadio::receptionStateChangedSignal, this);
446  isScanning = false;
447  return true; // we're done
448  }
449 
450  // tune to next channel
451  int newChannel = scanning.channelList[++scanning.currentChannelIndex];
452  changeChannel(newChannel);
454 
455  if (scanning.activeScan) {
456  // Active Scan: first wait probeDelay, then send a probe. Listening
457  // for minChannelTime or maxChannelTime takes place after that. (11.1.3.2)
458  scheduleAt(simTime() + scanning.probeDelay, new cMessage("sendProbe", MK_SCAN_SENDPROBE));
459  }
460  else {
461  // Passive Scan: spend maxChannelTime on the channel (11.1.3.1)
462  cMessage *timerMsg = new cMessage("maxChannelTime", MK_SCAN_MAXCHANNELTIME);
463  scheduleAt(simTime() + scanning.maxChannelTime, timerMsg);
464  }
465 
466  return false;
467 }
bool activeScan
Definition: Ieee80211MgmtSTA.h:49
#define MK_SCAN_SENDPROBE
Definition: Ieee80211MgmtSTA.cc:46
std::vector< int > channelList
Definition: Ieee80211MgmtSTA.h:51
ScanningInfo scanning
Definition: Ieee80211MgmtSTA.h:105
simtime_t maxChannelTime
Definition: Ieee80211MgmtSTA.h:55
int currentChannelIndex
Definition: Ieee80211MgmtSTA.h:52
#define MK_SCAN_MAXCHANNELTIME
Definition: Ieee80211MgmtSTA.cc:48
simtime_t probeDelay
Definition: Ieee80211MgmtSTA.h:50
bool busyChannelDetected
Definition: Ieee80211MgmtSTA.h:53
static simsignal_t receptionStateChangedSignal
This signal is emitted every time the radio reception state changes.
Definition: IRadio.h:66
bool isScanning
Definition: Ieee80211MgmtSTA.h:104
virtual void changeChannel(int channelNum)
Utility function: switches to the given radio channel.
Definition: Ieee80211MgmtSTA.cc:280
cModule * host
Definition: Ieee80211MgmtSTA.h:96
void inet::ieee80211::Ieee80211MgmtSTA::sendAssociationConfirm ( APInfo ap,
int  resultCode 
)
protectedvirtual

Sends back result of association to the agent.

587 {
588  sendConfirm(new Ieee80211Prim_AssociateConfirm(), resultCode);
589 }
virtual void sendConfirm(Ieee80211PrimConfirm *confirm, int resultCode)
Utility function: sends a confirmation to the agent.
Definition: Ieee80211MgmtSTA.cc:591
void inet::ieee80211::Ieee80211MgmtSTA::sendAuthenticationConfirm ( APInfo ap,
int  resultCode 
)
protectedvirtual

Sends back result of authentication to the agent.

580 {
581  Ieee80211Prim_AuthenticateConfirm *confirm = new Ieee80211Prim_AuthenticateConfirm();
582  confirm->setAddress(ap->address);
583  sendConfirm(confirm, resultCode);
584 }
virtual void sendConfirm(Ieee80211PrimConfirm *confirm, int resultCode)
Utility function: sends a confirmation to the agent.
Definition: Ieee80211MgmtSTA.cc:591
void inet::ieee80211::Ieee80211MgmtSTA::sendConfirm ( Ieee80211PrimConfirm confirm,
int  resultCode 
)
protectedvirtual

Utility function: sends a confirmation to the agent.

592 {
593  confirm->setResultCode(resultCode);
594  cMessage *msg = new cMessage(confirm->getClassName());
595  msg->setControlInfo(confirm);
596  send(msg, "agentOut");
597 }
void inet::ieee80211::Ieee80211MgmtSTA::sendManagementFrame ( Ieee80211ManagementFrame frame,
const MACAddress address 
)
protectedvirtual

Utility function: sends a management frame.

298 {
299  // frame goes to the specified AP
300  frame->setToDS(true);
301  frame->setReceiverAddress(address);
302  //XXX set sequenceNumber?
303 
304  sendDown(frame);
305 }
virtual void sendDown(cPacket *frame)
Utility method for implementing handleUpperMessage(): send message to MAC.
Definition: Ieee80211MgmtBase.cc:84
void inet::ieee80211::Ieee80211MgmtSTA::sendProbeRequest ( )
protectedvirtual

Broadcasts a Probe Request.

470 {
471  EV << "Sending Probe Request, BSSID=" << scanning.bssid << ", SSID=\"" << scanning.ssid << "\"\n";
472  Ieee80211ProbeRequestFrame *frame = new Ieee80211ProbeRequestFrame("ProbeReq");
473  frame->getBody().setSSID(scanning.ssid.c_str());
475 }
std::string ssid
Definition: Ieee80211MgmtSTA.h:48
ScanningInfo scanning
Definition: Ieee80211MgmtSTA.h:105
MACAddress bssid
Definition: Ieee80211MgmtSTA.h:47
virtual void sendManagementFrame(Ieee80211ManagementFrame *frame, const MACAddress &address)
Utility function: sends a management frame.
Definition: Ieee80211MgmtSTA.cc:297
void inet::ieee80211::Ieee80211MgmtSTA::sendScanConfirm ( )
protectedvirtual

Sends back result of scanning to the agent.

478 {
479  EV << "Scanning complete, found " << apList.size() << " APs, sending confirmation to agent\n";
480 
481  // copy apList contents into a ScanConfirm primitive and send it back
482  int n = apList.size();
483  Ieee80211Prim_ScanConfirm *confirm = new Ieee80211Prim_ScanConfirm();
484  confirm->setBssListArraySize(n);
485  auto it = apList.begin();
486  //XXX filter for req'd bssid and ssid
487  for (int i = 0; i < n; i++, it++) {
488  APInfo *ap = &(*it);
489  Ieee80211Prim_BSSDescription& bss = confirm->getBssList(i);
490  bss.setChannelNumber(ap->channel);
491  bss.setBSSID(ap->address);
492  bss.setSSID(ap->ssid.c_str());
493  bss.setSupportedRates(ap->supportedRates);
494  bss.setBeaconInterval(ap->beaconInterval);
495  bss.setRxPower(ap->rxPower);
496  }
497  sendConfirm(confirm, PRC_SUCCESS);
498 }
Definition: Ieee80211Primitives_m.h:138
virtual void sendConfirm(Ieee80211PrimConfirm *confirm, int resultCode)
Utility function: sends a confirmation to the agent.
Definition: Ieee80211MgmtSTA.cc:591
AccessPointList apList
Definition: Ieee80211MgmtSTA.h:110
void inet::ieee80211::Ieee80211MgmtSTA::startAssociation ( APInfo ap,
simtime_t  timeout 
)
protectedvirtual

Utility function: sends association request.

334 {
336  throw cRuntimeError("startAssociation: already associated or association currently in progress");
337  if (!ap->isAuthenticated)
338  throw cRuntimeError("startAssociation: not yet authenticated with AP address=", ap->address.str().c_str());
339 
340  // switch to that channel
341  changeChannel(ap->channel);
342 
343  // create and send association request
344  Ieee80211AssociationRequestFrame *frame = new Ieee80211AssociationRequestFrame("Assoc");
345 
346  //XXX set the following too?
347  // string SSID
348  // Ieee80211SupportedRatesElement supportedRates;
349 
350  sendManagementFrame(frame, ap->address);
351 
352  // schedule timeout
353  ASSERT(assocTimeoutMsg == nullptr);
354  assocTimeoutMsg = new cMessage("assocTimeout", MK_ASSOC_TIMEOUT);
355  assocTimeoutMsg->setContextPointer(ap);
356  scheduleAt(simTime() + timeout, assocTimeoutMsg);
357 }
cMessage * assocTimeoutMsg
Definition: Ieee80211MgmtSTA.h:114
#define MK_ASSOC_TIMEOUT
Definition: Ieee80211MgmtSTA.cc:45
virtual void changeChannel(int channelNum)
Utility function: switches to the given radio channel.
Definition: Ieee80211MgmtSTA.cc:280
bool isAssociated
Definition: Ieee80211MgmtSTA.h:113
virtual void sendManagementFrame(Ieee80211ManagementFrame *frame, const MACAddress &address)
Utility function: sends a management frame.
Definition: Ieee80211MgmtSTA.cc:297
void inet::ieee80211::Ieee80211MgmtSTA::startAuthentication ( APInfo ap,
simtime_t  timeout 
)
protectedvirtual

Utility function: sends authentication request.

308 {
309  if (ap->authTimeoutMsg)
310  throw cRuntimeError("startAuthentication: authentication currently in progress with AP address=", ap->address.str().c_str());
311  if (ap->isAuthenticated)
312  throw cRuntimeError("startAuthentication: already authenticated with AP address=", ap->address.str().c_str());
313 
314  changeChannel(ap->channel);
315 
316  EV << "Sending initial Authentication frame with seqNum=1\n";
317 
318  // create and send first authentication frame
319  Ieee80211AuthenticationFrame *frame = new Ieee80211AuthenticationFrame("Auth");
320  frame->getBody().setSequenceNumber(1);
321  //XXX frame length could be increased to account for challenge text length etc.
322  sendManagementFrame(frame, ap->address);
323 
324  ap->authSeqExpected = 2;
325 
326  // schedule timeout
327  ASSERT(ap->authTimeoutMsg == nullptr);
328  ap->authTimeoutMsg = new cMessage("authTimeout", MK_AUTH_TIMEOUT);
329  ap->authTimeoutMsg->setContextPointer(ap);
330  scheduleAt(simTime() + timeout, ap->authTimeoutMsg);
331 }
#define MK_AUTH_TIMEOUT
Definition: Ieee80211MgmtSTA.cc:44
virtual void changeChannel(int channelNum)
Utility function: switches to the given radio channel.
Definition: Ieee80211MgmtSTA.cc:280
virtual void sendManagementFrame(Ieee80211ManagementFrame *frame, const MACAddress &address)
Utility function: sends a management frame.
Definition: Ieee80211MgmtSTA.cc:297
int inet::ieee80211::Ieee80211MgmtSTA::statusCodeToPrimResultCode ( int  statusCode)
protectedvirtual

Utility function: converts Ieee80211StatusCode (->frame) to Ieee80211PrimResultCode (->primitive)

600 {
601  return statusCode == SC_SUCCESSFUL ? PRC_SUCCESS : PRC_REFUSED;
602 }
Definition: Ieee80211Primitives_m.h:138
Definition: Ieee80211Primitives_m.h:142
Definition: Ieee80211MgmtFrames_m.h:175
void inet::ieee80211::Ieee80211MgmtSTA::storeAPInfo ( const MACAddress address,
const Ieee80211BeaconFrameBody body 
)
protectedvirtual

Stores AP info received in a beacon or probe response.

835 {
836  APInfo *ap = lookupAP(address);
837  if (ap) {
838  EV << "AP address=" << address << ", SSID=" << body.getSSID() << " already in our AP list, refreshing the info\n";
839  }
840  else {
841  EV << "Inserting AP address=" << address << ", SSID=" << body.getSSID() << " into our AP list\n";
842  apList.push_back(APInfo());
843  ap = &apList.back();
844  }
845 
846  ap->channel = body.getChannelNumber();
847  ap->address = address;
848  ap->ssid = body.getSSID();
849  ap->supportedRates = body.getSupportedRates();
850  ap->beaconInterval = body.getBeaconInterval();
851 
852  //XXX where to get this from?
853  //ap->rxPower = ...
854 }
virtual APInfo * lookupAP(const MACAddress &address)
Utility function: looks up AP in our AP list.
Definition: Ieee80211MgmtSTA.cc:262
AccessPointList apList
Definition: Ieee80211MgmtSTA.h:110

Member Data Documentation

AccessPointList inet::ieee80211::Ieee80211MgmtSTA::apList
protected
AssociatedAPInfo inet::ieee80211::Ieee80211MgmtSTA::assocAP
protected
cMessage* inet::ieee80211::Ieee80211MgmtSTA::assocTimeoutMsg
protected
cModule* inet::ieee80211::Ieee80211MgmtSTA::host
protected
IInterfaceTable* inet::ieee80211::Ieee80211MgmtSTA::interfaceTable
protected
bool inet::ieee80211::Ieee80211MgmtSTA::isAssociated
protected
bool inet::ieee80211::Ieee80211MgmtSTA::isScanning
protected
InterfaceEntry* inet::ieee80211::Ieee80211MgmtSTA::myIface
protected
int inet::ieee80211::Ieee80211MgmtSTA::numChannels
protected
ScanningInfo inet::ieee80211::Ieee80211MgmtSTA::scanning
protected

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