<s> import signal <EOL> from multiprocessing import Lock <EOL> from multiprocessing import Process <EOL> from helpers import interface <EOL> import ethernet <EOL> import frames <EOL> from impacket . ImpactPacket import Ethernet <EOL> import pcapy <EOL> class WiWoDataFrameHandler ( Process ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , manager , iface_name , data_handler ) : <EOL> Process . __init__ ( self ) <EOL> self . data_fragments = dict ( ) <EOL> self . manager = manager <EOL> self . iface_name = iface_name <EOL> self . data_handler = data_handler <EOL> def run ( self ) : <EOL> signal . signal ( signal . SIGINT , signal . SIG_IGN ) <EOL> l = Lock ( ) <EOL> l . acquire ( ) <EOL> pd = pcapy . open_live ( self . iface_name , ethernet . ETHERNET_MTU , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> pcap_filter = "<STR_LIT>" % hex ( frames . WiwoFrame . ethertype ) + "<STR_LIT>" <EOL> pd . setfilter ( pcap_filter ) <EOL> l . release ( ) <EOL> pd . loop ( - <NUM_LIT:1> , self . frame_handler ) <EOL> def frame_handler ( self , hdr , buff ) : <EOL> e = Ethernet ( buff ) <EOL> src = e . get_ether_shost ( ) . tostring ( ) <EOL> ether_type = e . get_ether_type ( ) <EOL> if ether_type != frames . WiwoFrame . ethertype : <EOL> return <EOL> wf = frames . WiwoFrame ( buff [ e . get_header_size ( ) : ] ) <EOL> wiwo_sub_frame = wf . get_packet ( ) [ wf . get_header_size ( ) : ] <EOL> if wf . get_type ( ) == frames . WiwoDataFrame . frametype : <EOL> self . data_handler ( self . manager , src , wiwo_sub_frame ) <EOL> elif wf . get_type ( ) == frames . WiwoDataFragmentFrame . frametype : <EOL> wdf = frames . WiwoDataFragmentFrame ( wf . get_packet ( ) [ wf . get_header_size ( ) : ] ) <EOL> if not ( src in self . data_fragments ) : <EOL> self . data_fragments [ src ] = list ( ) <EOL> self . data_fragments [ src ] . append ( wdf . get_data_as_string ( ) ) <EOL> if wdf . is_last_fragment ( ) : <EOL> frame = str ( ) <EOL> for fragment in self . data_fragments [ src ] : <EOL> frame += fragment <EOL> self . data_handler ( self . manager , src , frame ) <EOL> del ( self . data_fragments [ src ] ) <EOL> class WiWoManagementFrameHandler ( Process ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , iface_name , mgnt_frames_queue ) : <EOL> Process . __init__ ( self ) <EOL> self . iface_name = iface_name <EOL> self . mgnt_frames_queue = mgnt_frames_queue <EOL> def run ( self ) : <EOL> signal . signal ( signal . SIGINT , signal . SIG_IGN ) <EOL> l = Lock ( ) <EOL> l . acquire ( ) <EOL> pd = pcapy . open_live ( self . iface_name , ethernet . ETHERNET_MTU , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> iface_mac_addr = interface . get_string_mac_address ( self . iface_name ) <EOL> pcap_filter = "<STR_LIT>" + iface_mac_addr + "<STR_LIT>" % hex ( frames . WiwoFrame . ethertype ) + "<STR_LIT>" <EOL> pd . setfilter ( pcap_filter ) <EOL> l . release ( ) <EOL> pd . loop ( - <NUM_LIT:1> , self . frame_handler ) <EOL> def frame_handler ( self , hdr , buff ) : <EOL> self . mgnt_frames_queue . put ( buff ) </s>
