1 # This file is part of Scapy 2 # Scapy is free software: you can redistribute it and/or modify 3 # it under the terms of the GNU General Public License as published by 4 # the Free Software Foundation, either version 2 of the License, or 5 # any later version. 6 # 7 # Scapy is distributed in the hope that it will be useful, 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License 13 # along with Scapy. If not, see <http://www.gnu.org/licenses/>. 14 15 # author: <jellch (at] harris.com> 16 17 # scapy.contrib.description = PPI CACE 18 # scapy.contrib.status = loads 19 20 """ 21 CACE PPI types 22 """ 23 import logging,struct 24 from scapy.config import conf 25 from scapy.packet import * 26 from scapy.fields import * 27 from scapy.layers.l2 import Ether 28 from scapy.layers.dot11 import Dot11 29 from scapy.contrib.ppi import * 30 31 PPI_DOT11COMMON = 2 32 PPI_DOT11NMAC = 3 33 PPI_DOT11NMACPHY = 4 34 PPI_SPECTRUMMAP = 5 35 PPI_PROCESSINFO = 6 36 PPI_CAPTUREINFO = 7 37 PPI_AGGREGATION = 8 38 PPI_DOT3 = 9 39 40 # PPI 802.11 Common Field Header Fields 41 class dBmByteField(Field): 42 def __init__(self, name, default): 43 Field.__init__(self, name, default, "b") 44 def i2repr(self, pkt, val): 45 if (val != None): 46 val = "%4d dBm" % val 47 return val 48 49 class PPITSFTField(LELongField): 50 def i2h(self, pkt, val): 51 flags = 0 52 if (pkt): 53 flags = pkt.getfieldval("Pkt_Flags") 54 if not flags: 55 flags = 0 56 if (flags & 0x02): 57 scale = 1e-3 58 else: 59 scale = 1e-6 60 tout = scale * float(val) 61 return tout 62 def h2i(self, pkt, val): 63 scale = 1e6 64 if pkt: 65 flags = pkt.getfieldval("Pkt_Flags") 66 if flags: 67 if (flags & 0x02): 68 scale = 1e3 69 tout = int((scale * val) + 0.5) 70 return tout 71 72 _PPIDot11CommonChFlags = ['','','','','Turbo','CCK','OFDM','2GHz','5GHz', 73 'PassiveOnly','Dynamic CCK-OFDM','GSFK'] 74 75 _PPIDot11CommonPktFlags = ['FCS','TSFT_ms','FCS_Invalid','PHY_Error'] 76 77 # PPI 802.11 Common Field Header 78 class Dot11Common(Packet): 79 name = "PPI 802.11-Common" 80 fields_desc = [ LEShortField('pfh_type',PPI_DOT11COMMON), 81 LEShortField('pfh_length', 20), 82 PPITSFTField('TSF_Timer', 0), 83 FlagsField('Pkt_Flags',0, -16, _PPIDot11CommonPktFlags), 84 LEShortField('Rate',0), 85 LEShortField('Ch_Freq',0), 86 FlagsField('Ch_Flags', 0, -16, _PPIDot11CommonChFlags), 87 ByteField('FHSS_Hop',0), 88 ByteField('FHSS_Pat',0), 89 dBmByteField('Antsignal',-128), 90 dBmByteField('Antnoise',-128)] 91 92 def extract_padding(self, p): 93 return b"",p 94 #Hopefully other CACE defined types will be added here. 95 96 #Add the dot11common layer to the PPI array 97 addPPIType(PPI_DOT11COMMON, Dot11Common) 98 99