mirage.libs.common.sdr package

Submodules

mirage.libs.common.sdr.hardware module

class mirage.libs.common.sdr.hardware.HackRFSDR(interface)

Bases: object

This class provides an API allowing to interact with an HackRF one Sofware Defined Radio.

close()

This method closes the current HackRF.

Returns

boolean indicating if the operation was successful

Return type

int

Example
>>> hackrf.close()
True
classmethod closeAPI()

This method closes the HackRF API.

disableAmplifier()

This method disables the HackRF amplifier.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.disableAmplifier()
True
disableAntenna()

This method disables the HackRF antenna.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.disableAntenna()
True
enableAmplifier()

This method enables the HackRF amplifier.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.enableAmplifier()
True
enableAntenna()

This method enables the HackRF antenna.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.enableAntenna()
True
getAPIVersion()

This method returns the HackRF API version.

Returns

tuple of integers indicating the API version

Return type

(int,int)

Example
>>> hackrf.getAPIVersion()
(1, 3)
getBandwidth()

This method returns the Bandwidth used by the HackRF.

Returns

bandwidth in Hertz

Return type

int

Example
>>> hackrf.getBandwidth()
1000000
getBoardID()

This method returns the board identifier of the current HackRF.

Returns

board identifier of the current HackRF

Return type

int

Example
>>> hackrf.getBoardID()
2
getBoardName()

This method returns the board name of the current HackRF.

Returns

board name of the current HackRF

Return type

str

Example
>>> hackrf.getBoardName()
'HackRF One'
getDeviceIndex()

This method returns the device index of the current HackRF.

Returns

device index of the current HackRF

Return type

int

Example
>>> hackrf.getDeviceIndex()
0
getFirmwareVersion()

This method returns the firmware version of the current HackRF.

Returns

string indicating firmware version of the current HackRF

Return type

str

Example
>>> hackrf.getFirmwareVersion()
'git-b9558ba'
getFrequency()

This method returns the frequency used by the HackRF.

Returns

current frequency (in Hertz)

Return type

int

Example
>>> hackrf.getFrequency()
2402000000
getGain()

This method returns the VGA gain used by the HackRF.

Returns

VGA gain in use

Return type

int

Example
>>> hackrf.getGain()
40
getLNAGain()

This method returns the LNA gain used by the HackRF.

Returns

VGA gain in use

Return type

int

Example
>>> hackrf.getLNAGain()
40
getSampleRate()

This method returns the sample rate used by the HackRF.

Returns

sample rate in use(in samples/s)

Return type

int

Example
>>> hackrf.getSampleRate()
2000000
getSerial()

This method returns the serial number of the current HackRF.

Returns

serial number of the current HackRF

Return type

str

Example
>>> hackrf.getSerial()
'0000000000000000a06063c8234e925f'
getTXGain()

This method returns the TX gain used by the HackRF.

Returns

TX gain in use

Return type

int

Example
>>> hackrf.getTXGain()
40
initialized = False
instances = {}
isReady()

This method indicates if the current HackRF is ready to use.

Returns

boolean indicating if the HackRF is ready

Return type

bool

Example
>>> hackrf.isReady()
True
classmethod listHackRFs()

This method returns the HackRF devices found.

Example
>>> HackRFSDR.listHackRFs()
['0000000000000000a06063c8234e925f']
openHackRF()
restart()
setBandwidth(bandwidth)

This method sets the Bandwidth used by the HackRF.

Parameters

bandwidth (int) – bandwidth in Hertz

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.setBandwidth(1 * 1000 * 1000)
True
setFrequency(frequency)

This method sets the frequency used by the HackRF.

Parameters

frequency (int) – frequency (in Hertz)

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.setFrequency(2402000000)
True
setGain(gain)

This method sets the VGA gain used by the HackRF.

Parameters

gain (int) – VGA gain

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.setGain(40)
True
setLNAGain(lnaGain)

This method sets the LNA gain used by the HackRF.

Parameters

gain (int) – LNA gain

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.setLNAGain(40)
True
setSampleRate(sampleRate)

This method sets the sample rate used by the HackRF.

Parameters

sampleRate (int) – sample rate (in samples/s)

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.setSampleRate(2 * 1000 * 1000)
True
setTXGain(txGain)

This method sets the TX gain used by the HackRF.

Parameters

txGain (int) – TX gain

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrf.setTXGain(40)
True
classmethod setupAPI()

This method initializes the HackRF API.

mirage.libs.common.sdr.sinks module

class mirage.libs.common.sdr.sinks.HackRFSink(interface)

Bases: mirage.libs.common.sdr.hardware.HackRFSDR, mirage.libs.common.sdr.sinks.SDRSink

This class defines a Sink for HackRF Software Defined Radio. It inherits from SDRSink.

checkParameters()

This method returns a boolean indicating if a mandatory parameter is missing.

Returns

boolean indicating if the sink is correctly configured

Return type

bool

Example
>>> hackrfSink.checkParameters()
[FAIL] You have to provide a frequency !
False
close()

This method closes the HackRF Sink.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrfSink.close()
getGain()

This method returns the TX gain used by the HackRF sink.

Returns

TX gain in use

Return type

int

Example
>>> hackrfSink.getGain()
40
isStreaming()

This method returns a boolean indicating if the streaming process is enabled.

Returns

boolean indicating if streaming is enabled

Return type

bool

Example
>>> hackrfSink.isStreaming()
False
numberOfSinks = 0
setGain(gain)

This method allows to set the TX gain used by the HackRF sink.

Parameters

gain (int) – TX gain to use

Example
>>> hackrfSink.setGain(40)
startStreaming()

This method starts the streaming process.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrfSink.startStreaming()
True
stopStreaming()

This method stops the streaming process.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrfSink.stopStreaming()
True
class mirage.libs.common.sdr.sinks.SDRSink(interface)

Bases: object

This class defines a standard Software Defined Radio sink. Every Software Defined Radio supporting IQ transmission has to implement a Sink inheriting from this class.

The following methods have to be implemented:

  • setGain(gain) : this method allows to sets the TX gain used by the sink

  • getGain() : this method returns the TX gain in use by the sink

  • startStreaming() : this method allows to start the IQ streaming

  • stopStreaming() : this method allows to stop the IQ streaming

  • isStreaming() : this method returns a boolean indicating if streaming is enabled

  • close() : this method closes the sink

close()
isStreaming()
nextData()
setBandwidth(bandwidth)
setFrequency(frequency)
setSampleRate(sampleRate)
setTXGain(txGain)
startStreaming()
stopStreaming()
transmit(iqSamples)

mirage.libs.common.sdr.sources module

class mirage.libs.common.sdr.sources.HackRFSource(interface)

Bases: mirage.libs.common.sdr.hardware.HackRFSDR, mirage.libs.common.sdr.sources.SDRSource

This class defines a Source for HackRF Software Defined Radio. It inherits from SDRSource.

checkParameters()

This method returns a boolean indicating if a mandatory parameter is missing.

Returns

boolean indicating if the source is correctly configured

Return type

bool

Example
>>> hackrfSource.checkParameters()
[FAIL] You have to provide a frequency !
False
close()

This method closes the HackRF Source.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrfSource.close()
isStreaming()

This method returns a boolean indicating if the streaming process is enabled.

Returns

boolean indicating if streaming is enabled

Return type

bool

Example
>>> hackrfSource.isStreaming()
False
numberOfSources = 0
startStreaming()

This method starts the streaming process.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrfSource.startStreaming()
True
stopStreaming()

This method stops the streaming process.

Returns

boolean indicating if the operation was successful

Return type

bool

Example
>>> hackrfSource.stopStreaming()
True
class mirage.libs.common.sdr.sources.SDRSource(interface)

Bases: object

This class defines a standard Software Defined Radio source. Every Software Defined Radio supporting IQ reception has to implement a Source inheriting from this class.

The following methods have to be implemented:

  • startStreaming() : this method allows to start the IQ streaming

  • stopStreaming() : this method allows to stop the IQ streaming

  • isStreaming() : this method returns a boolean indicating if streaming is enabled

  • close() : this method closes the sink

close()
isStreaming()
setBandwidth(bandwidth)
setFrequency(frequency)
setGain(gain)
setSampleRate(sampleRate)
startStreaming()
stopStreaming()

mirage.libs.common.sdr.demodulators module

class mirage.libs.common.sdr.demodulators.FSK2Demodulator(samplesPerSymbol=1, samplesBefore=60, samplesAfter=60, size=320, preamble='01101011011111011001000101110001')

Bases: mirage.libs.common.sdr.demodulators.SDRDemodulator

This demodulator allows to demodulate a 2-Frequency Shift Keying (2-FSK) stream.

run()
class mirage.libs.common.sdr.demodulators.FasterFSK2Demodulator(samplesPerSymbol=1, samplesBefore=60, samplesAfter=60, size=320, preamble='01101011011111011001000101110001')

Bases: mirage.libs.common.sdr.demodulators.SDRDemodulator

This experimental demodulator allows to demodulate a 2-Frequency Shift Keying stream. It is an experimental demodulator based on a amplitude filter, which tries to estimate the noise level to demodulate the stream only if the amplitude is above the noise thresold. The main objective of this implementation is to increase the demodulator’s speed, however it may miss some packets if the noise thresold is wrong.

run()
stop()

This method stops the demodulator.

Example
>>> demodulator.start()
class mirage.libs.common.sdr.demodulators.SDRDemodulator

Bases: object

This class implements a Sofware Defined Radio demodulator: every specific demodulator has to inherit from this class and implement the run method. When the demodulator is started, it processes the IQ stream received from the SDRSource, performs the operations needed to demodulate the stream and adds the demodulated packets to the output queue using generateOutput method.

addDecoder(decoder)

This method associates a SDRDecoder to the demodulator.

Parameters

decoder (SDRDecoder) – decoder to associate

generateOutput(demodulatedData, iqSamples)

This method allows to generate an output, by providing the demodulated data and the corresponding IQ. The output will be processed sequentially by every associated decoders, then it is added to the output queue.

Parameters
  • demodulatedData (bytes) – demodulated data

  • iqSamples (list of complex) – IQ samples linked to the demodulated data

getDecoders()
getOutput()

This method returns the next demodulated and decoded element from the output queue.

Returns

tuple of demodulated data and the correspond IQ samples

Return type

(bytes, list of complex)

removeDecoders()

This method removes every associated decoders.

run()
setSource(source)

This method associates a SDRSource to the demodulator.

Parameters

source (SDRSource) – source to associate

start()

This method starts the demodulator.

Example
>>> demodulator.start()
stop()

This method stops the demodulator.

Example
>>> demodulator.start()

mirage.libs.common.sdr.modulators module

class mirage.libs.common.sdr.modulators.GFSKModulator(samplesPerSymbol=8, gain=1.0, bt=0.3, modulationIndex=0.5)

Bases: mirage.libs.common.sdr.modulators.SDRModulator

This class implements a Gaussian Frequency Shift Keying modulator.

generateFilter()

This method generates the gaussian filter according to the provided parameters.

getBT()

This method returns the Bandwidth-Time value used by the modulator’s filter.

Returns

Bandwidth-Time value

Return type

float

getModulationIndex()

This method returns the modulation index used by the modulator.

Returns

modulation index

Return type

float

getSamplesPerSymbol()

This method returns the samples per symbol used by the modulator.

Returns

samples per symbol

Return type

int

run()
setBT(bt)

This method sets the Bandwidth-Time value used by the modulator’s filter.

Parameters

bt (float) – Bandwidth-Time value

setModulationIndex(modulationIndex)

This method sets the modulation index used by the modulator.

Parameters

modulationIndex (float) – modulation index

setSamplesPerSymbol(samplesPerSymbol)

This method sets the samples per symbol used by the modulator.

Parameters

samplesPerSymbol (int) – samples per symbol

class mirage.libs.common.sdr.modulators.OQPSKModulator(samplesPerSymbol=8, pulseType='sinus')

Bases: mirage.libs.common.sdr.modulators.SDRModulator

This class implements an Offset-Quadrature Phase Shift Keying modulator.

generatePulse(samplesPerSymbol, pulseType='sinus')

This method generates a pulse according to the provided pulse type and the samples per symbol.

Parameters
  • samplesPerSymbol (int) – samples per symbol

  • pulseType (str) – pulse type (“square” or “sinus”)

Returns

pulse

Return type

list of int

getPulseType()

This method returns the pulse type used to shape the modulator.

Returns

pulse type (“square” or “sinus”)

Return type

str

Example
>>> modulator.getPulseType()
'sinus'
getSamplesPerSymbol()

This method returns the samples per symbol used by the modulator.

Returns

samples per symbol

Return type

int

run()
setPulseType(pulseType)

This method sets the pulse type used to shape the modulator.

Parameters

pulseType (str) – pulse type (“square” or “sinus”)

Example
>>> modulator.setPulseType("square")
setSamplesPerSymbol(samplesPerSymbol)

This method sets the samples per symbol used by the modulator.

Parameters

samplesPerSymbol (int) – samples per symbol

class mirage.libs.common.sdr.modulators.SDRModulator

Bases: object

This class implements a Sofware Defined Radio modulator: every specific modulator has to inherit from this class and implement the run method. When the modulator is started, it processes the packets transmitted using setInput, performs the operations needed to modulate the data and transmits the IQ stream to the associated SDRSink.

addEncoder(encoder)

This method associates a SDREncoder to the modulator.

Parameters

encoder (SDREncoder) – encoder to associate

generateInput(data)

This method allows to generate an input, by providing the data to modulate. The input will be processed sequentially by every associated encoders, and the result is returned by the method.

Parameters

data (bytes) – data to modulate

Returns

data processed by every associated encoders (binary string)

Return type

str

removeEncoders()

This method removes every associated encoders.

run()
setInput(data)

This method allows to provide an input to the modulator, encode it and add it to the input queue. The input will be processed sequentially by every associated encoders, and the result is returned by the method.

Parameters

data (bytes) – data to modulate

setSink(sink)

This method associates a SDRSink to the modulator.

Parameters

sink (SDRSink) – sink to associate

start()

This method starts the modulator.

Example
>>> modulator.start()
stop()

This method stops the modulator.

Example
>>> modulator.stop()

mirage.libs.common.sdr.decoders module

This component implements the Software Defined Radios Decoders.

class mirage.libs.common.sdr.decoders.SDRDecoder

Bases: object

This class implements a simple Sofware Defined Radio decoder. An decoder is used to convert a binary string into a packet or a sequence of bytes. Every decoder must inherit from this class and implement the decode method.

decode(demodulatedData, iqSamples)

This method implements the decoding process and transforms a binary string into a packet or a sequence of bytes.

Parameters
  • demodulatedData (str) – data to decode

  • iqSamples (list of complex) – IQ samples corresponding with the demodulated data

Returns

tuple composed of the decoded data and the correspond IQ samples

Return type

(bytes, list of complex)

mirage.libs.common.sdr.encoders module

This component implements the Software Defined Radios Encoders.

class mirage.libs.common.sdr.encoders.SDREncoder

Bases: object

This class implements a simple Sofware Defined Radio encoder. An encoder is used to convert a packet data or a sequence of bytes into a binary string. Every encoder must inherit from this class and implement the encode method.

encode(data)

This method implements the encoding process and transforms a sequence of bytes into a binary string.

Parameters

data (bytes) – data to encode

Returns

binary string

Return type

str

mirage.libs.common.sdr.pipeline module

class mirage.libs.common.sdr.pipeline.SDRPipeline(source=None, demodulator=None, sink=None, modulator=None)

Bases: object

This class implements a Software Defined Radio pipeline, allowing to connect multiple SDR blocks together to manipulate an IQ stream.

  • A pipeline can be used to demodulate and decode an IQ stream provided by a SDRSource: in this case, the pipeline is composed of a SDRSource, a SDRDemodulator and a SDRDecoder.

  • A pipeline can be used to encode and modulate an IQ stream transmitted to a SDRSink: in this case, the pipeline is composed of a SDREncoder, z SDRModulator and a SDRSink.

The “>>” operator is overloaded to simplify the connection between blocks. As an example, you can build a pipeline automatically using the following syntax:

Example
>>> rxPipeline = source >> demodulator >> decoder
>>> txPipeline = sink << modulator << encoder
getDemodulator()

This method returns the demodulator connected to the pipeline (if any).

Returns

pipeline demodulator

Return type

SDRDemodulator

getModulator()

This method returns the modulator connected to the pipeline (if any).

Returns

pipeline modulator

Return type

SDRModulator

getOutput()

This method returns the demodulator’s output .

Returns

tuple of demodulated data and the corresponding IQ Samples

Return type

(bytes, list of complex)

getSink()

This method returns the sink connected to the pipeline (if any).

Returns

pipeline sink

Return type

SDRSink

getSource()

This method returns the source connected to the pipeline (if any).

Returns

pipeline source

Return type

SDRSource

isStarted()

This method returns a boolean indicating if the pipeline is started.

Returns

boolean indicating if the pipeline is started

Return type

bool

setInput(data)

This method sets the modulator’s input.

Parameters

data (bytes) – bytes to transmit

start()

This method starts the pipeline.

Example
>>> pipeline.start()
stop()

This method stops the pipeline.

Example
>>> pipeline.stop()
updateDemodulator(demodulator)

This method replaces the current demodulator by the provided one.

Parameters

demodulator (SDRDemodulator) – New demodulator to use

mirage.libs.common.sdr.hackrf_definitions

This module contains HackRF definitions needed to interact with an HackRF One