HackRF is a unique device designed for enthusiasts and radio amateurs who are passionate about the study of radio signals and everything connected with it.
The uniqueness of HackRF in its technical parameters - at a price of about $ 300, the device allows not only to receive, but also to transmit radio signals in the 1 MHz to 6 GHz band with a bandwidth of up to 20 MHz. The use of HackRF is practically not covered in Habré and Hiktatimes, it's time to fill this gap.
As for the reception of radio signals, everything is simple, and practically does not differ from the popular 10-dollar RTL-SDR, about which only the laziest did not write. The necessary DLL is put, the program is started, in general, that's all. Those who have not heard of such a “miracle” can read here on the site:
habrahabr.ru/post/149698
habrahabr.ru/post/149702
habrahabr.ru/post/280454
habrahabr.ru/post/200914
With the reception, everything is quite simple and trivial, the technology is cheap and long-established. With the transfer of all a bit more complicated. What we now do.
')
Low level - / ++
The first way is to communicate directly with the device. HackRF has a library with an open API, an example of its use can be found on the author’s website in the hackrf_transfer utility:
github.com/mossmann/hackrf/blob/master/host/hackrf-tools/src/hackrf_transfer.c . For those who have worked with a sound card at least once, the principle will be clear - a callback function is called a certain number of times per second, the buffer for which must be filled with data. It would seem simple, but there is one “but” - HackRF is SDR. Software Defined Radio. This means that simply sending a WAV file to the buffer will not come out, nothing will be transmitted. We must programmatically form an integrated (IQ) signal for the entire required receiver band, so that its DAC, in turn, sends “this” on the air. It is also necessary to set a number of settings (frequency, gain, bandwidth), which can also be viewed in the source.
HackRF supports work with various bandwidths, from 1 to 20 MHz, and this band needs to be formed programmatically. We will not do this. Mathematics is needed rather seriously, so let's go straight to the second method - using the GNU Radio package.
GNU Radio
GNU Radio is an open and free software package designed for digital signal processing for scientific, educational or commercial purposes. The system consists of a large number of ready-made blocks that have an interface in Python, the blocks themselves are written in C ++. GNU Radio also includes the GNURadio Companion visual editor, which allows you to visually connect blocks into a ready-made “device” without using a programming language at all.
So, install drivers for Hack RF, install GNU Radio (it can be installed on Linux or Mac OS, or downloaded as a Linux Live CD), run in the console “gnuradio-companion”. Now everything is ready, you can proceed to the transfer.
Formally, HackRF can transmit anything within its bandwidth, for example, knowing the data transfer protocol, you can drive a radio-controlled machine or control the doorbell. Consider the most trivial examples: amplitude (AM) and frequency (FM) modulation.
Frequency modulation
To transmit in FM mode, run gnuradio-companion and create such a graph in the program.
Its structure is quite simple. The WAV file with a sampling frequency of 44100 was selected as the source, the Multiply Const block multiplies the signal by 2 (the original sound was rather quiet), the next WBFM Transmit block and does all the “magic” - converts our real signal with a frequency of 44100 into a complex signal with a sampling frequency of 88200. The next Resampler block increases the sampling rate to the 2.4 MHz selected for this example. The transmission frequency is set to 87.5 MHz, it was the lowest FM radio frequency supported by my smartphone, and it was free from FM stations.
The result - we launch the graph in GNU Radio, the red TX LED lights up on HackRF, our file is heard in the smartphone.
It is interesting to see how it really works. In the GNU Radio console you can see the following output:
Executing /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u /Users/XXXX/Documents/Projects/Gnuradio/top_block.py
Its content is a finished program on Python that implements our program!
It can be saved in a separate folder and used as you like, modified, etc. This is quite convenient, since allows for example, to add your UI, to make a launch on a schedule, in general, everything is limited only by the imagination of the programmer.
We slightly modify the graph to start the program in the “narrow FM” mode, which is used in radios and baby monitors:
The difference is small - we installed the NBFM block, and the transmission frequency was set to 433.075 MHz - the first channel of the LPD-band. Turn on the radio and hear the sound. By the way, GNU Radio allows you to use as a source not only a WAV file, but also a microphone, so the program is easy to remake to transmit voice messages.
Amplitude modulation
For those who have left the grandmother's HF-range receiver (although at least a Degen 1103 or IC-R9500 is better, of course), it will be interesting to try the AM mode. To do this, create the following graph:
Here we use the Hilbert transform unit to convert data into a complex signal. Otherwise, the essence has not changed, the signal is resampled to the desired sampling rate and sent to HackRF.
More SDR
Finally, we show that HackRF can do much more than just a walkie-talkie from the Svyaznoy with a price of 1000r. This is a full-fledged Software Defined Radio, where you can transmit anything. To show the ease of working with “numbers” in GNU Radio, we add the graph of FM translations so that HackRF broadcasts information simultaneously on 2 frequencies.
Here we add the second file, repeat the same structure. But the data obtained is multiplied by a complex sinusoidal signal with a frequency of 125 kHz, which is equivalent to a frequency shift of these 125 kHz, as a result, the second data stream will be broadcast at a frequency of 433075 + 125 = 433200, which corresponds to the 6th LPD channel. Now HackRF simultaneously transmits 2 audio files at 2 different frequencies. You can add and 3rd, everything is limited only by the bandwidth and power of the computer.
That's all. Those interested in the topic of GNU Radio can find tutorials on the net, there are quite a lot of them.
Finally. HackRF is not a full-fledged radio station, its power is too low and is about 20mW, and the efficiency of a regular antenna is less than 1%. It is rather a device for experimenting with signals in the “near zone”, within the office or apartment. If someone wants to experiment with more powerful signals, you should definitely follow the rules of the distribution of the radio frequency spectrum, so as not to interfere with others.