Exemple #1
0
class OpenVizslaBackend(ViewSBBackend):
    """ Capture backend that captures packets from OpenVizsla. """
    def __init__(self, capture_speed, suppress_packet_callback=None):
        """ Creates a new OpenVizsla capture backend.

        Args:
            capture_speed -- The speed at which to capture.
        """

        # TODO: validate
        self.capture_speed = capture_speed

        # Create a new OpenVizsla device; but don't yet try to connect to it.
        self.ov_device = OVDevice()

        # And create the packet sink we'll use to get data from the OV device.
        self.packet_sink = ViewSBEventSink(self, suppress_packet_callback)
        self.ov_device.register_sink(self.packet_sink)

    def run(self):
        """ Run an OpenVizsla capture. """

        self.ov_device.open(reconfigure_fpga=True)

        try:
            halt_callback = lambda _: self.termination_event.is_set()
            self.ov_device.run_capture(self.capture_speed,
                                       halt_callback=halt_callback)

        finally:
            self.ov_device.ensure_capture_stopped()
            self.ov_device.close()
Exemple #2
0
class OpenVizslaBackend(ViewSBBackend):
    """ Capture backend that captures packets from OpenVizsla. """

    UI_NAME = "openvizsla"
    UI_DESCRIPTION = "OpenVizsla hardware analyzers"

    @staticmethod
    def reason_to_be_disabled():
        # The main reason we'd not be available would be that pyopenvizsla
        # isn't importable (and thus likely not installed).
        if not 'ViewSBEventSink' in globals():
            return "pyopenvizsla (openvizsla driver) not available"

        return None

    @staticmethod
    def speed_from_string(string):
        speeds = {
            'high': OVCaptureUSBSpeed.HIGH,
            'full': OVCaptureUSBSpeed.FULL,
            'low': OVCaptureUSBSpeed.LOW
        }

        try:
            return speeds[string]
        except KeyError:
            return None

    @classmethod
    def parse_arguments(cls, args, parent_parser=[]):

        # Parse user input and try to extract our class options.
        parser = argparse.ArgumentParser(parents=parent_parser, add_help=False)
        parser.add_argument(
            '--speed',
            type=cls.speed_from_string,
            default='high',
            help=
            "the speed of the USB data to capture [valid: {high, full, low}]")
        args, leftover_args = parser.parse_known_args()

        if args.speed is None:
            sys.stderr.write("speed must be 'high', 'full', or 'low'\n")
            sys.exit(errno.EINVAL)

        #  Return the class and leftover arguments.
        return (args.speed, ), leftover_args

    def __init__(self, capture_speed, suppress_packet_callback=None):
        """ Creates a new OpenVizsla capture backend.

        Args:
            capture_speed -- The speed at which to capture.
            suppress_packet_callback -- A callback function that determines
                which packets should be dropped before being submitted to the
                analysis queue.
        """

        # TODO: validate
        self.capture_speed = capture_speed

        # Create a new OpenVizsla device; but don't yet try to connect to it.
        self.ov_device = OVDevice()

        # And create the packet sink we'll use to get data from the OV device.
        self.packet_sink = ViewSBEventSink(self, suppress_packet_callback)
        self.ov_device.register_sink(self.packet_sink)

    def run(self):
        """ Run an OpenVizsla capture. """

        self.ov_device.open(reconfigure_fpga=True)

        try:
            halt_callback = lambda _: self.termination_event.is_set()
            self.ov_device.run_capture(self.capture_speed,
                                       halt_callback=halt_callback)

        finally:
            self.ov_device.ensure_capture_stopped()
            self.ov_device.close()
Exemple #3
0
class OpenVizslaBackend(ViewSBBackend):
    """ Capture backend that captures packets from OpenVizsla. """

    UI_NAME = "openvizsla"
    UI_DESCRIPTION = "OpenVizsla hardware analyzers"


    @staticmethod
    def reason_to_be_disabled():
        # The main reason we'd not be available would be that pyopenvizsla
        # isn't importable (and thus likely not installed).
        if not 'ViewSBEventSink' in globals():
            return "pyopenvizsla (openvizsla driver) not available"

        return None


    @staticmethod
    def speed_from_string(string):

        try:
            return SPEEDS[string]
        except KeyError:
            return string


    @classmethod
    def add_options(cls, parser):

        parser.add_argument('--speed', default='high', choices=SPEEDS.keys(),
            help="The speed of the USB data to capture.")


    def __init__(self, speed, suppress_packet_callback=None):
        """ Creates a new OpenVizsla capture backend.

        Args:
            capture_speed -- The speed at which to capture.
            suppress_packet_callback -- A callback function that determines
                which packets should be dropped before being submitted to the
                analysis queue.
        """

        super().__init__()

        # TODO: validate
        self.capture_speed = self.speed_from_string(speed)

        # Create a new OpenVizsla device; but don't yet try to connect to it.
        self.ov_device = OVDevice()

        # And create the packet sink we'll use to get data from the OV device.
        self.packet_sink = ViewSBEventSink(self, suppress_packet_callback)
        self.ov_device.register_sink(self.packet_sink)


    def run(self):
        """ Run an OpenVizsla capture. """

        self.ov_device.open(reconfigure_fpga=True)

        try:
            halt_callback = lambda _ : self.termination_event.is_set()
            self.ov_device.run_capture(self.capture_speed, halt_callback=halt_callback)

        finally:
            self.ov_device.ensure_capture_stopped()
            self.ov_device.close()