|
14 | 14 | # along with Scapy. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
|
16 | 16 | # Copyright (C) Philippe Biondi <[email protected]> |
17 | | -# Original PPI author: <[email protected]> |
18 | 17 |
|
19 | 18 | """ |
20 | 19 | Wireless LAN according to IEEE 802.11. |
@@ -218,74 +217,6 @@ def post_build(self, p, pay): |
218 | 217 | return p + pay |
219 | 218 |
|
220 | 219 |
|
221 | | -# Dictionary to map the TLV type to the class name of a sub-packet |
222 | | -_ppi_types = {} |
223 | | - |
224 | | - |
225 | | -def addPPIType(id, value): |
226 | | - _ppi_types[id] = value |
227 | | - |
228 | | - |
229 | | -def getPPIType(id, default="default"): |
230 | | - return _ppi_types.get(id, _ppi_types.get(default, None)) |
231 | | - |
232 | | - |
233 | | -# Default PPI Field Header |
234 | | -class PPIGenericFldHdr(Packet): |
235 | | - name = "PPI Field Header" |
236 | | - fields_desc = [LEShortField('pfh_type', 0), |
237 | | - FieldLenField('pfh_length', None, length_of="value", fmt='<H', adjust=lambda p, x:x + 4), |
238 | | - StrLenField("value", "", length_from=lambda p:p.pfh_length)] |
239 | | - |
240 | | - def extract_padding(self, p): |
241 | | - return b"", p |
242 | | - |
243 | | - |
244 | | -def _PPIGuessPayloadClass(p, **kargs): |
245 | | - """ This function tells the PacketListField how it should extract the |
246 | | - TLVs from the payload. We pass cls only the length string |
247 | | - pfh_len says it needs. If a payload is returned, that means |
248 | | - part of the sting was unused. This converts to a Raw layer, and |
249 | | - the remainder of p is added as Raw's payload. If there is no |
250 | | - payload, the remainder of p is added as out's payload. |
251 | | - """ |
252 | | - if len(p) >= 4: |
253 | | - t, pfh_len = struct.unpack("<HH", p[:4]) |
254 | | - # Find out if the value t is in the dict _ppi_types. |
255 | | - # If not, return the default TLV class |
256 | | - cls = getPPIType(t, "default") |
257 | | - pfh_len += 4 |
258 | | - out = cls(p[:pfh_len], **kargs) |
259 | | - if (out.payload): |
260 | | - out.payload = conf.raw_layer(out.payload.load) |
261 | | - out.payload.underlayer = out |
262 | | - if (len(p) > pfh_len): |
263 | | - out.payload.payload = conf.padding_layer(p[pfh_len:]) |
264 | | - out.payload.payload.underlayer = out.payload |
265 | | - elif (len(p) > pfh_len): |
266 | | - out.payload = conf.padding_layer(p[pfh_len:]) |
267 | | - out.payload.underlayer = out |
268 | | - else: |
269 | | - out = conf.raw_layer(p, **kargs) |
270 | | - return out |
271 | | - |
272 | | - |
273 | | -class PPI(Packet): |
274 | | - name = "Per-Packet Information header (PPI)" |
275 | | - fields_desc = [ByteField('version', 0), |
276 | | - ByteField('flags', 0), |
277 | | - FieldLenField('len', None, length_of="PPIFieldHeaders", fmt="<H", adjust=lambda p, x: x + 8), |
278 | | - LEIntField('dlt', 1), |
279 | | - PacketListField("PPIFieldHeaders", [], _PPIGuessPayloadClass, length_from=lambda p: p.len - 8,)] |
280 | | - |
281 | | - def guess_payload_class(self, payload): |
282 | | - return conf.l2types.get(self.dlt, Packet.guess_payload_class(self, payload)) |
283 | | - |
284 | | - |
285 | | -# Register PPI |
286 | | -addPPIType("default", PPIGenericFldHdr) |
287 | | - |
288 | | - |
289 | 220 | class Dot11(Packet): |
290 | 221 | name = "802.11" |
291 | 222 | fields_desc = [ |
@@ -764,8 +695,6 @@ class Dot11Ack(Packet): |
764 | 695 |
|
765 | 696 |
|
766 | 697 | bind_layers(PrismHeader, Dot11,) |
767 | | -bind_layers(PPI, Dot11, dlt=DLT_IEEE802_11) |
768 | | -bind_layers(PPI, Ether, dlt=DLT_EN10MB) |
769 | 698 | bind_layers(Dot11, LLC, type=2) |
770 | 699 | bind_layers(Dot11QoS, LLC,) |
771 | 700 | bind_layers(Dot11, Dot11AssoReq, subtype=0, type=0) |
@@ -797,7 +726,6 @@ class Dot11Ack(Packet): |
797 | 726 | conf.l2types.register_num2layer(802, PrismHeader) |
798 | 727 | conf.l2types.register(DLT_IEEE802_11_RADIO, RadioTap) |
799 | 728 | conf.l2types.register_num2layer(803, RadioTap) |
800 | | -conf.l2types.register(DLT_PPI, PPI) |
801 | 729 |
|
802 | 730 |
|
803 | 731 | class WiFi_am(AnsweringMachine): |
|
0 commit comments