Skip to content

Commit 14a71f5

Browse files
mgonzalezlopezudclevy
authored andcommitted
fix(ieee80211): track association IDs in MIB
1 parent 8c5c849 commit 14a71f5

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

src/inet/linklayer/ieee80211/mgmt/Ieee80211MgmtAp.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ void Ieee80211MgmtAp::handleAuthenticationFrame(Packet *packet, const Ptr<const
144144
// receives authentication frame number 1 from STA, which will cause the AP to return an Auth-Error
145145
// making the MN STA to start the handover process all over again.
146146
if (frameAuthSeq == 1) {
147-
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED)
147+
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED) {
148148
sendDisAssocNotification(sta->address);
149+
mib->releaseAssociationId(sta->address);
150+
}
149151
mib->bssAccessPointData.stations[sta->address] = Ieee80211Mib::NOT_AUTHENTICATED;
150152
sta->authSeqExpected = 1;
151153
}
@@ -179,8 +181,10 @@ void Ieee80211MgmtAp::handleAuthenticationFrame(Packet *packet, const Ptr<const
179181

180182
// update status
181183
if (isLast) {
182-
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED)
184+
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED) {
183185
sendDisAssocNotification(sta->address);
186+
mib->releaseAssociationId(sta->address);
187+
}
184188
mib->bssAccessPointData.stations[sta->address] = Ieee80211Mib::AUTHENTICATED; // TODO only when ACK of this frame arrives
185189
EV << "STA authenticated\n";
186190
}
@@ -199,8 +203,10 @@ void Ieee80211MgmtAp::handleDeauthenticationFrame(Packet *packet, const Ptr<cons
199203

200204
if (sta) {
201205
// mark STA as not authenticated; alternatively, it could also be removed from staList
202-
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED)
206+
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED) {
203207
sendDisAssocNotification(sta->address);
208+
mib->releaseAssociationId(sta->address);
209+
}
204210
mib->bssAccessPointData.stations[sta->address] = Ieee80211Mib::NOT_AUTHENTICATED;
205211
sta->authSeqExpected = 1;
206212
}
@@ -282,8 +288,10 @@ void Ieee80211MgmtAp::handleDisassociationFrame(Packet *packet, const Ptr<const
282288
delete packet;
283289

284290
if (sta) {
285-
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED)
291+
if (mib->bssAccessPointData.stations[sta->address] == Ieee80211Mib::ASSOCIATED) {
286292
sendDisAssocNotification(sta->address);
293+
mib->releaseAssociationId(sta->address);
294+
}
287295
mib->bssAccessPointData.stations[sta->address] = Ieee80211Mib::AUTHENTICATED;
288296
}
289297
}
@@ -348,6 +356,7 @@ void Ieee80211MgmtAp::stop()
348356
{
349357
cancelEvent(beaconTimer);
350358
staList.clear();
359+
mib->bssAccessPointData.associationIds.clear();
351360
Ieee80211MgmtApBase::stop();
352361
}
353362

src/inet/linklayer/ieee80211/mib/Ieee80211Mib.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void Ieee80211Mib::initialize(int stage)
2323
WATCH(bssStationData.stationType);
2424
WATCH(bssStationData.isAssociated);
2525
WATCH(bssAccessPointData.stations);
26+
WATCH(bssAccessPointData.associationIds);
2627
WATCH_EXPR("modeStr", getModeStr(mode));
2728
WATCH_EXPR("stationTypeStr", getStationTypeStr(bssStationData.stationType));
2829
WATCH_EXPR("qosStr", qos ? ", QoS" : ", Non-QoS");
@@ -58,7 +59,31 @@ const char *Ieee80211Mib::getStationTypeStr(Ieee80211Mib::BssStationType station
5859
}
5960
}
6061

62+
short Ieee80211Mib::allocateAssociationId(const MacAddress& address)
63+
{
64+
auto existing = bssAccessPointData.associationIds.find(address);
65+
if (existing != bssAccessPointData.associationIds.end())
66+
return existing->second;
67+
for (short aid = 1; aid <= 2007; aid++) {
68+
bool used = false;
69+
for (const auto& entry : bssAccessPointData.associationIds)
70+
if (entry.second == aid) {
71+
used = true;
72+
break;
73+
}
74+
if (!used) {
75+
bssAccessPointData.associationIds[address] = aid;
76+
return aid;
77+
}
78+
}
79+
throw cRuntimeError("No IEEE 802.11 association ID is available");
80+
}
81+
82+
void Ieee80211Mib::releaseAssociationId(const MacAddress& address)
83+
{
84+
bssAccessPointData.associationIds.erase(address);
85+
}
86+
6187
} // namespace ieee80211
6288

6389
} // namespace inet
64-

src/inet/linklayer/ieee80211/mib/Ieee80211Mib.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class INET_API Ieee80211Mib : public SimpleModule
5050
class INET_API BssAccessPointData {
5151
public:
5252
std::map<MacAddress, BssMemberStatus> stations;
53+
std::map<MacAddress, short> associationIds;
5354
};
5455

5556
public:
@@ -68,11 +69,12 @@ class INET_API Ieee80211Mib : public SimpleModule
6869
static const char *getModeStr(Ieee80211Mib::Mode mode);
6970
static const char *getStationTypeStr(Ieee80211Mib::BssStationType stationType);
7071
std::string getSsidStr() const;
72+
short allocateAssociationId(const MacAddress& address);
73+
void releaseAssociationId(const MacAddress& address);
7174
};
7275

7376
} // namespace ieee80211
7477

7578
} // namespace inet
7679

7780
#endif
78-

0 commit comments

Comments
 (0)