Skip to content

Commit 0648c0d

Browse files
Hooleangpotter2
andauthored
Make Dot11EltVendorSpecific packet extensible (#4660)
* Make Dot11EltVendorSpecific packet extensible See #4659 This commit allows the Dot11EltVendorSpecific packet to dispatch to its subclasses based on their OUI, with the same idiom that the parent Dot11Elt uses to select subclasses based on their ID already: https://github.com/secdev/scapy/blob/c15a670926185f6ddb9b3330ed1f947ff6f14b92/scapy/layers/dot11.py#L1057-L1074 This is just a rough sketch, so feedback very welcome to make sure it is heading in the right direction :) * Fix copy-paste typo * Fix child register_variant swallowing call to parent register_variant * Fix 'TODO' * Remove comment --------- Co-authored-by: gpotter2 <[email protected]>
1 parent e44c79e commit 0648c0d

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

scapy/layers/dot11.py

+35-14
Original file line numberDiff line numberDiff line change
@@ -1439,22 +1439,25 @@ class Dot11EltVendorSpecific(Dot11Elt):
14391439
def dispatch_hook(cls, _pkt=None, *args, **kargs):
14401440
if _pkt:
14411441
oui = struct.unpack("!I", b"\x00" + _pkt[2:5])[0]
1442-
if oui == 0x0050f2: # Microsoft
1443-
type_ = orb(_pkt[5])
1444-
if type_ == 0x01:
1445-
# MS WPA IE
1446-
return Dot11EltMicrosoftWPA
1447-
elif type_ == 0x02:
1448-
# MS WME IE TODO
1449-
# return Dot11EltMicrosoftWME
1450-
pass
1451-
elif type_ == 0x04:
1452-
# MS WPS IE TODO
1453-
# return Dot11EltWPS
1454-
pass
1455-
return Dot11EltVendorSpecific
1442+
ouicls = cls.registered_ouis.get(oui, cls)
1443+
if ouicls.dispatch_hook != cls.dispatch_hook:
1444+
# Sub-classes can have their own dispatch_hook
1445+
return ouicls.dispatch_hook(_pkt=_pkt, *args, **kargs)
1446+
cls = ouicls
14561447
return cls
14571448

1449+
registered_ouis = {}
1450+
1451+
@classmethod
1452+
def register_variant(cls):
1453+
oui = cls.oui.default
1454+
if not oui:
1455+
# This is Dot11EltVendorSpecific, register it in the super-class.
1456+
super().register_variant()
1457+
elif oui not in cls.registered_ouis:
1458+
# Sub-Vendor (e.g. Dot11EltMicrosoftWPA)
1459+
cls.registered_ouis[oui] = cls
1460+
14581461

14591462
class Dot11EltMicrosoftWPA(Dot11EltVendorSpecific):
14601463
name = "802.11 Microsoft WPA"
@@ -1467,6 +1470,24 @@ class Dot11EltMicrosoftWPA(Dot11EltVendorSpecific):
14671470
XByteField("type", 0x01)
14681471
] + Dot11EltRSN.fields_desc[2:8]
14691472

1473+
@classmethod
1474+
def dispatch_hook(cls, _pkt=None, *args, **kargs):
1475+
if _pkt:
1476+
type_ = orb(_pkt[5])
1477+
if type_ == 0x01:
1478+
# MS WPA IE
1479+
return Dot11EltMicrosoftWPA
1480+
elif type_ == 0x02:
1481+
# MS WME IE TODO
1482+
# return Dot11EltMicrosoftWME
1483+
pass
1484+
elif type_ == 0x04:
1485+
# MS WPS IE TODO
1486+
# return Dot11EltWPS
1487+
pass
1488+
return Dot11EltVendorSpecific
1489+
return cls
1490+
14701491

14711492
# 802.11-2016 9.4.2.19
14721493

0 commit comments

Comments
 (0)