wideband_scanner within a loop - RTL-SDR

146 views
Skip to first unread message

MD TB

unread,
Jun 9, 2022, 3:36:08 AM6/9/22
to gr-gsm
Hi everyone,

I've been working with the gr-gsm code which obtains the Cell-ID using and RTL-SDR. I was trying to understand the source code and I've been planning to make an application which is continuous scanning, based on the wideband-scanner and do-scan functions.
Nevertheless, I was not successful when I tried to execute the do_scan function within a loop, because at the second loop scanning the full band the program stops with this error:

Scanning @  955.8  /  959.0  MHz
gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.8.1.0
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy airspyhf soapy redpitaya freesrp
Using device #0 Realtek RTL2838UHIDIR SN: 00000001
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!
Exact sample rate is: 2000000,052982 Hz
[R82XX] PLL not locked!
gr::vmcircbuf_sysv_shm: shmget (2): No queda espacio en el dispositivo
gr::vmcircbuf_sysv_shm: shmget (2): No queda espacio en el dispositivo
gr::vmcircbuf_sysv_shm: shmget (2): No queda espacio en el dispositivo
gr::buffer::allocate_buffer: failed to allocate buffer of size 64 KB
gr::vmcircbuf_sysv_shm: shmget (2): No queda espacio en el dispositivo
gr::vmcircbuf_sysv_shm: shmget (2): No queda espacio en el dispositivo
gr::vmcircbuf_sysv_shm: shmget (2): No queda espacio en el dispositivo
gr::buffer::allocate_buffer: failed to allocate buffer of size 64 KB
Traceback (most recent call last):
[...]
  File "/usr/lib/python3/dist-packages/gnuradio/gr/top_block.py", line 111, in start
    top_block_start_unlocked(self._impl, max_noutput_items)
  File "/usr/lib/python3/dist-packages/gnuradio/gr/runtime_swig.py", line 4832, in top_block_start_unlocked
    return _runtime_swig.top_block_start_unlocked(r, max_noutput_items)
RuntimeError: std::bad_alloc

The application can do a complete band scan only once and a half before stopping.
I understand that the problem is the memory reservation done by GNURadio, but I don't know how to solve or alleviate it. I'm executing this code in my computer (MSI i7 Ubuntu Focal Fossa) and I prefer to optimize the code before changing hardware parameters, because I plan to repeat the band scanning at least 30 times.

Thank you very much in advance.

Nikos Balkanas

unread,
Jun 9, 2022, 4:28:59 AM6/9/22
to MD TB, gr-gsm
Hi,

"No queda espacio en el dispositivo" = No space left on device. (sysv
shared memory).
I assume that stock grgsm_scanner doesn't have this issue in your PC.
It doesn't have in mine :)
It means that your code is accessing more shared memory than it
should. If you are sure you need that memory,
and is not leaking, you can raise it in /etc/fstab. But you shouldn't
do that without making sure you don't have leaks.
valgrind might help.

HTH
Nikos
> --
> You received this message because you are subscribed to the Google Groups "gr-gsm" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gr-gsm+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/gr-gsm/138673d3-653b-4d95-b152-8da6a08d840dn%40googlegroups.com.

MD TB

unread,
Jun 9, 2022, 6:52:57 AM6/9/22
to gr-gsm
Hi,

thanks for your quick answer.

This error replicates when I simply loop the main() function from the grgsm_scanner script within a for, I was suspecting that it could be my application as you have said, but I tested with the original grgsm_scanner script and it was the same, so I don't know if it's a problem which could be fixed by software :(

Thanks again!

Big Benny

unread,
Jun 9, 2022, 7:28:39 AM6/9/22
to gr-gsm
Do you know how I can capture 2g traffic using gr-gsm livemon from a 4g LTE device do I just have to 
Change my network to 2 G

Nikos Balkanas

unread,
Jun 9, 2022, 7:33:54 AM6/9/22
to MD TB, gr-gsm
Hi MD,

Plz don't loop anything. Just try to run grgsm_scanner on its own
through all the gsm bands.
If you get the same shm error, then you should configure your ubuntu
for more gnuradio shm.
Else your code is doing smt it shoudln't:(
In fact don't try to loop the top_block_start_unlocked. It is meant to
run only once at the start!

BR
Nikos
> To view this discussion on the web visit https://groups.google.com/d/msgid/gr-gsm/46953f19-d399-498f-af6c-2ba752ac173dn%40googlegroups.com.

MD TB

unread,
Jun 9, 2022, 7:49:21 AM6/9/22
to gr-gsm
Hi Nikos,

thank you again. I understand the point about not to loop the top_block (wideband_scanner), but in the other hand, how could I repeat automatically the full band scan if is not looping it?
Also, If I have understood correctly, do_scan function instantiates wideband_scanner block for each frequency:

def do_scan(samp_rate, band, speed, ppm, gain, args, prn = None, debug = False):

signallist = []

channels_num = int(samp_rate / 0.2e6)

for arfcn_range in grgsm.arfcn.get_arfcn_ranges(band):

first_arfcn = arfcn_range[0]

last_arfcn = arfcn_range[1]

last_center_arfcn = last_arfcn - int((channels_num / 2) - 1)


current_freq = grgsm.arfcn.arfcn2downlink(first_arfcn + int(channels_num / 2) - 1)

last_freq = grgsm.arfcn.arfcn2downlink(last_center_arfcn)

stop_freq = last_freq + 0.2e6 * channels_num


while current_freq < stop_freq:

[...]

# instantiate scanner and processor

scanner = wideband_scanner(rec_len=6 - speed,

sample_rate=samp_rate,

carrier_frequency=current_freq,

ppm=ppm, gain=gain, args=args)


# start recording

scanner.start()

scanner.wait()
scanner.stop()

My question is why that could be done but I can't loop the do_scan function to repeat the full scan :( I'm sorry for being stubborn but I wanna know the root cause for this problem.

Thanks again!

Nikos Balkanas

unread,
Jun 9, 2022, 8:13:09 AM6/9/22
to MD TB, gr-gsm
top_block initializes gnuradio_runtime, including shm, each time you call it.
If you want to loop it, you need to stop it (clear it) after each loop.
That's how grgsm_scanner works. Otherwise you will keep allocating shm
to infinity:(
And yes, do_scan specifies the frequencies and wideband_receiver does
all the analysis.

HTH
Nikos
> To view this discussion on the web visit https://groups.google.com/d/msgid/gr-gsm/ce6bf381-5035-4c5d-956c-66c3735150edn%40googlegroups.com.

Nikos Balkanas

unread,
Jun 9, 2022, 8:16:05 AM6/9/22
to Big Benny, gr-gsm
Please start another thread for this unrelated question.
Yes you should connect your 4G phone to a 2G BTS and capture that.

BR
Nikos
> To view this discussion on the web visit https://groups.google.com/d/msgid/gr-gsm/4f307b6b-b149-49ab-834c-502e51bbf0cfn%40googlegroups.com.

MD TB

unread,
Jun 9, 2022, 10:38:45 AM6/9/22
to gr-gsm
Hi Nikos,

so, as you have said,it's possible to loop the do_scan function inside a loop, but I have to ensure the resources clean doing the stop as do_scan does.
There are other explicit method to clean the shm inside a Python application with has the do_scan loop? Only with the .close() from the do_scan function, it seems that it's not actually liberating the shm...

Thanks you for your patience!!

Nikos Balkanas

unread,
Jun 9, 2022, 12:14:11 PM6/9/22
to MD TB, gr-gsm
Hi MD,

I am a C/C++, not a python programmer.
It seems to me cleaner to allocate just 1 top_block, the equivalent of
1 grc chart, and inside do all the loops you need.
I dunno why scanner starts and stops a grc at each frequency. It's all
a matter of implementation.
How you want to implement it it is your decision, it's your code.
Your initial question was why you ran out of shm. I think you know that by now:)

BR
Nikos
> To view this discussion on the web visit https://groups.google.com/d/msgid/gr-gsm/6786b134-6b54-49ba-a2d8-8695cc8f48d8n%40googlegroups.com.

MD TB

unread,
Jun 10, 2022, 2:00:26 AM6/10/22
to gr-gsm
Thank you for your help Nikos, I'll try my best with that information :)
Reply all
Reply to author
Forward
0 new messages