예제 #1
0
    def frame_handler(self, hdr, buff):
        e = Ethernet(buff)
        src = e.get_ether_shost().tostring()
        ether_type = e.get_ether_type()

        if ether_type != frames.WiwoFrame.ethertype:
            return

        wf = frames.WiwoFrame(buff[e.get_header_size():])

        wiwo_sub_frame = wf.get_packet()[wf.get_header_size():]

        if wf.get_type() == frames.WiwoDataFrame.frametype:
            self.data_handler(self.manager, src, wiwo_sub_frame)
        elif wf.get_type() == frames.WiwoDataFragmentFrame.frametype:
            wdf = frames.WiwoDataFragmentFrame(
                wf.get_packet()[wf.get_header_size():])

            if not (src in self.data_fragments):
                self.data_fragments[src] = list()

            self.data_fragments[src].append(wdf.get_data_as_string())

            if wdf.is_last_fragment():
                frame = str()
                for fragment in self.data_fragments[src]:
                    frame += fragment
                self.data_handler(self.manager, src, frame)
                del (self.data_fragments[src])
예제 #2
0
 def stop_worker_interfaces(self, dst):
     """
     Sends a WiWo Stop frame to a worker in order to stop capturing data.
     """
     wiwo_frame = frames.WiwoFrame()
     wiwo_frame.set_type(frames.WiwoStopFrame.frametype)
     wiwo_stop_frame = frames.WiwoStopFrame()
     wiwo_frame.contains(wiwo_stop_frame)
     ethernet_frame = self.__create_wiwo_ethernet_frame(dst, self.__mac)
     ethernet_frame.contains(wiwo_frame)
     return self.__send_frame(dst, ethernet_frame)
예제 #3
0
 def announce_to_worker(self, dst):
     """
     Sends a WiWo Announce frame to find Workers.
     """
     wiwo_frame = frames.WiwoFrame()
     wiwo_frame.set_type(frames.WiwoAnnounceFrame.frametype)
     wiwo_announce_frame = frames.WiwoAnnounceFrame()
     wiwo_frame.contains(wiwo_announce_frame)
     ethernet_frame = self.__create_wiwo_ethernet_frame(dst, self.__mac)
     ethernet_frame.contains(wiwo_frame)
     self.__send_frame(dst, ethernet_frame)
예제 #4
0
 def __create_wiwo_request_info_frame(self, dst, src):
     """
     Returns a WiWo Info Request frame.
     """
     wiwo_frame = frames.WiwoFrame()
     wiwo_frame.set_type(frames.WiwoInfoRequestFrame.frametype)
     wiwo_info_request_frame = frames.WiwoInfoRequestFrame()
     wiwo_frame.contains(wiwo_info_request_frame)
     ethernet_frame = self.__create_wiwo_ethernet_frame(dst, src)
     ethernet_frame.contains(wiwo_frame)
     return ethernet_frame
예제 #5
0
 def inject_data_from_worker_interface(self, dst, iface_name, data):
     """
     Sends WiWo Data Inject frame to injected data from a Worker.
     """
     wiwo_frame = frames.WiwoFrame()
     wiwo_frame.set_type(frames.WiwoDataInjectFrame.frametype)
     wiwo_data_inject_frame = frames.WiwoDataInjectFrame()
     wiwo_data_inject_frame.set_iface_len(len(iface_name))
     wiwo_data_inject_frame.set_iface_from_string(iface_name)
     wiwo_data_inject_frame.set_data_from_string(data)
     wiwo_frame.contains(wiwo_data_inject_frame)
     ethernet_frame = self.__create_wiwo_ethernet_frame(dst, self.__mac)
     ethernet_frame.contains(wiwo_frame)
     self.__send_frame(dst, ethernet_frame)
예제 #6
0
 def set_channel_to_worker_interface(self, dst, iface_name, channel):
     """
     Sends a WiWo Set Channel frame to a Worker.
     """
     wiwo_frame = frames.WiwoFrame()
     wiwo_frame.set_type(frames.WiwoSetChannelFrame.frametype)
     wiwo_set_channel_frame = frames.WiwoSetChannelFrame()
     wiwo_set_channel_frame.set_iface_len(len(iface_name))
     wiwo_set_channel_frame.set_iface_from_string(iface_name)
     wiwo_set_channel_frame.set_channel(channel)
     wiwo_frame.contains(wiwo_set_channel_frame)
     ethernet_frame = self.__create_wiwo_ethernet_frame(dst, self.__mac)
     ethernet_frame.contains(wiwo_frame)
     self.__send_frame(dst, ethernet_frame)
예제 #7
0
 def start_worker_interface(self, dst, iface_name, bpf_filter):
     """
     Sends a WiWo Start frame to a worker in order to start capturing data.
     """
     wiwo_frame = frames.WiwoFrame()
     wiwo_frame.set_type(frames.WiwoStartFrame.frametype)
     wiwo_start_frame = frames.WiwoStartFrame()
     wiwo_start_frame.set_iface_len(len(iface_name))
     wiwo_start_frame.set_iface_from_string(iface_name)
     wiwo_start_frame.set_filter_len(len(bpf_filter))
     wiwo_start_frame.set_filter_from_string(bpf_filter)
     wiwo_frame.contains(wiwo_start_frame)
     ethernet_frame = self.__create_wiwo_ethernet_frame(dst, self.__mac)
     ethernet_frame.contains(wiwo_frame)
     self.__send_frame(dst, ethernet_frame)
예제 #8
0
    def __management_frame_handler(self, wiwo_frame_buffer):
        """
        Method that process management frame from a WiWo Worker.
        """
        ethernet_frame = Ethernet(wiwo_frame_buffer)
        ether_dst_addr = ethernet_frame.get_ether_dhost().tostring()
        ether_src_addr = ethernet_frame.get_ether_shost().tostring()

        ether_type = ethernet_frame.get_ether_type()

        if ether_type != frames.WiwoFrame.ethertype:
            return

        wiwo_frame_buffer = wiwo_frame_buffer[ethernet_frame.get_header_size():]
        wiwo_frame = frames.WiwoFrame(wiwo_frame_buffer)
        ethernet_frame.contains(wiwo_frame)

        if not (ether_src_addr in self.__worker_dict.keys()):
            if wiwo_frame.get_type() == frames.WiwoAckFrame.frametype:  # We assume it's a ACK from an Announce
                worker = Worker(ether_src_addr)
                self.__worker_dict[ether_src_addr] = worker
                wiwo_req_info_frame_buffer = self.__create_wiwo_request_info_frame(ether_src_addr, ether_dst_addr)
                worker.send(wiwo_req_info_frame_buffer, self.__iface_name)
                self.__event_handler(WiwoEvent(ether_src_addr, WiwoEvent.WorkerAdded))
        else:
            if wiwo_frame.get_type() == frames.WiwoErrorFrame.frametype:
                worker = self.__worker_dict[ether_src_addr]
                worker.update_after_error()
                wiwo_error_frame_buffer = wiwo_frame_buffer[wiwo_frame.get_header_size():]
                we = frames.WiwoErrorFrame(wiwo_error_frame_buffer)
                self.__event_handler(WiwoEvent(ether_src_addr, WiwoEvent.Error, we.get_msg_as_string()))
            else:
                worker = self.__worker_dict[ether_src_addr]
                type_from_last_frame_sent = worker.get_type_from_last_frame_sent()
                worker.process_ctrl_and_mgnt_frame_received(ethernet_frame, self.__iface_name)

                if type_from_last_frame_sent == -1:
                    return
                elif type_from_last_frame_sent == frames.WiwoDataInjectFrame.frametype:
                    self.__event_handler(WiwoEvent(ether_src_addr, WiwoEvent.DataInjected))
                else:
                    self.__event_handler(WiwoEvent(ether_src_addr, WiwoEvent.WorkerUpdated))