Example #1
0
    def __init__(self, interface):
        HackRFSDR.setupAPI()
        self.lock = threading.Lock()
        self.ready = False
        self.device = POINTER(hackrf_device)()
        devicesList = HackRFSDR.listHackRFs()
        self.antenna = True
        self.amplifier = False

        if "hackrf" == interface[:6] and (interface[6:].isdigit()
                                          or interface[6:] == ""):
            self.index = 0 if interface[6:] == "" else int(interface[6:])
            self.serial = devicesList[
                self.index] if self.index < len(devicesList) else None
        elif "hackrf:" in interface and len(interface.split(":")[1]) == 32:
            self.serial = interface.split(":")[1] if interface.split(
                ":")[1] in devicesList else None
            self.index = devicesList.index(
                self.serial) if self.serial is not None else None
        if self.serial is not None:
            if self.serial not in HackRFSDR.instances:
                self.openHackRF()
            else:
                self.device = HackRFSDR.instances[self.serial]
                self.ready = True

        else:
            io.fail("HackRF not found !")
            utils.exitMirage()
            self.device = None
Example #2
0
    def setupAPI(cls):
        '''
		This method initializes the HackRF API.
		'''
        if not HACKRFLIB_AVAILABLE:
            io.fail("Fatal error: libhackrf has not been found. Exiting ...")
            utils.exitMirage()

        if not cls.initialized:
            libhackrf.hackrf_init()
            cls.initialized = True
            io.success("HackRF API initialized !")
Example #3
0
	def get(cls, interface):
		'''
		This class method implements the Register device pattern.
		According to the interface parameter, only one instance of a given specific device will be instanciated if multiple Emitters and/or Receivers tries to access it.
		'''
		if interface not in cls.instances:
			cls.instances[interface] = cls(interface)
			cls.instances[interface].init()
		if not cls.instances[interface].isUp():
			io.fail("An error occured during device initialization (interface : "+str(interface)+")")
			exitMirage()
			return None
		return cls.instances[interface]
Example #4
0
    def getReceiver(self, interface=""):
        '''
		Helper allowing to easily get a specific Receiver instance according to the ``technology`` attribute.

		:param interface: string indicating the interface to use
		:type interface: str
		:return: Receiver instance
		:rtype: core.wireless.Receiver
		'''
        interface = interface if interface != "" else self.args['INTERFACE']
        if interface not in self.__class__.Receivers:
            try:
                self.__class__.Receivers[
                    interface] = self.__class__.ReceiversClass[
                        self.technology](interface=interface)
            except AttributeError:
                io.fail("Device not found !")
                utils.exitMirage()
        self.__class__.Receivers[interface].updateSDRConfig(self.sdrConfig)
        return self.__class__.Receivers[interface]