def channelinfo(self, args): """ Print channel info for an ARFCN. """ if args.arfcn is not None: if args.band is not None: self.__print_arfcn_info(args.arfcn, args.band) else: for b in arfcn_converter.get_bands(): self.__print_arfcn_info(args.arfcn, b) else: if args.band is not None: # print the starting channels and end channels of the band arfcn_range = arfcn_converter.get_arfcn_ranges(args.band)[0] arfcn_start = arfcn_range[0] f_down_start = arfcn_converter.arfcn2downlink( arfcn_start, args.band) / 1e6 f_up_start = arfcn_converter.arfcn2uplink( arfcn_start, args.band) / 1e6 arfcn_end = arfcn_range[1] f_down_end = arfcn_converter.arfcn2downlink( arfcn_end, args.band) / 1e6 f_up_end = arfcn_converter.arfcn2uplink(arfcn_end, args.band) / 1e6 self.printmsg( "ARFCN %i-%i (%s): Downlink: %4.1f-%4.1f MHz, Uplink: %4.1f-%4.1f MHz" % (arfcn_start, arfcn_end, args.band, f_down_start, f_down_end, f_up_start, f_up_end)) else: for band in arfcn_converter.get_bands(): arfcn_range = arfcn_converter.get_arfcn_ranges(band)[0] # print the starting channels and end channels of the band arfcn_start = arfcn_range[0] f_down_start = arfcn_converter.arfcn2downlink( arfcn_start, band) / 1e6 f_up_start = arfcn_converter.arfcn2uplink( arfcn_start, band) / 1e6 arfcn_end = arfcn_range[1] f_down_end = arfcn_converter.arfcn2downlink( arfcn_end, band) / 1e6 f_up_end = arfcn_converter.arfcn2uplink(arfcn_end, band) / 1e6 self.printmsg( "ARFCN %i-%i (%s): Downlink: %4.1f-%4.1f MHz, Uplink: %4.1f-%4.1f MHz" % (arfcn_start, arfcn_end, band, f_down_start, f_down_end, f_up_start, f_up_end))
def __print_arfcn_info(self, arfcn, band): if arfcn_converter.is_valid_arfcn(arfcn, band): f_down = arfcn_converter.arfcn2downlink(arfcn, band) / 1e6 f_up = arfcn_converter.arfcn2uplink(arfcn, band) / 1e6 self.printmsg("ARFCN %i (%s): Downlink: %4.1f MHz, Uplink: %4.1f MHz" % (arfcn, band, f_down, f_up)) else: self.printmsg("ARFCN %i is NOT valid in %s" % (arfcn, band))
def scan_rtlsdr(self, args): if args.speed < 0 or args.speed > 5: raise PluginError("Invalid speed") path = self._config_provider.get("gr-gsm", "apps_path") grgsm_scanner = imp.load_source("", os.path.join(path, "grgsm_scanner")) band = args.band sample_rate = args.samp_rate ppm = args.ppm gain = args.gain speed = args.speed if ppm is None: ppm = self._config_provider.getint("rtl_sdr", "ppm") if sample_rate is None: sample_rate = self._config_provider.getint("rtl_sdr", "sample_rate") if gain is None: gain = self._config_provider.getint("rtl_sdr", "gain") if band == 'DCS1800' or band == 'PCS1900': shmmni = self.get_shmmni() if shmmni < 32000: msg = "Unsufficient shared memory segments.\n" msg += "For scanning DCS1800 or PCS1900 you need to increase the value, i.e. using the following command:\n\n" msg += "sudo sysctl kernel.shmmni=32000" self.printmsg(msg) return channels_num = int(sample_rate / 0.2e6) for arfcn_range in arfcn_converter.get_arfcn_ranges(args.band): try: first_arfcn = arfcn_range[0] last_arfcn = arfcn_range[1] last_center_arfcn = last_arfcn - int((channels_num / 2) - 1) current_freq = arfcn_converter.arfcn2downlink( first_arfcn + int(channels_num / 2) - 1, band) last_freq = arfcn_converter.arfcn2downlink( last_center_arfcn, band) stop_freq = last_freq + 0.2e6 * channels_num while current_freq < stop_freq: # silence rtl_sdr output: with Silencer(): # instantiate scanner and processor scanner = grgsm_scanner.wideband_scanner( rec_len=6 - speed, sample_rate=sample_rate, carrier_frequency=current_freq, ppm=ppm, args="") # start recording scanner.start() scanner.wait() scanner.stop() freq_offsets = numpy.fft.ifftshift( numpy.array( range(int(-numpy.floor(channels_num / 2)), int(numpy.floor( (channels_num + 1) / 2)))) * 2e5) detected_c0_channels = scanner.gsm_extract_system_info.get_chans( ) found_list = [] if detected_c0_channels: chans = numpy.array( scanner.gsm_extract_system_info.get_chans()) found_freqs = current_freq + freq_offsets[(chans)] cell_ids = numpy.array( scanner.gsm_extract_system_info.get_cell_id()) lacs = numpy.array( scanner.gsm_extract_system_info.get_lac()) mccs = numpy.array( scanner.gsm_extract_system_info.get_mcc()) mncs = numpy.array( scanner.gsm_extract_system_info.get_mnc()) ccch_confs = numpy.array( scanner.gsm_extract_system_info.get_ccch_conf( )) powers = numpy.array( scanner.gsm_extract_system_info.get_pwrs()) for i in range(0, len(chans)): cell_arfcn_list = scanner.gsm_extract_system_info.get_cell_arfcns( chans[i]) neighbour_list = scanner.gsm_extract_system_info.get_neighbours( chans[i]) info = grgsm_scanner.channel_info( arfcn_converter.downlink2arfcn( found_freqs[i], band), found_freqs[i], cell_ids[i], lacs[i], mccs[i], mncs[i], ccch_confs[i], powers[i], neighbour_list, cell_arfcn_list) found_list.append(info) scanner = None for info in sorted(found_list): self.printmsg(info.__str__()) if args.verbose: self.printmsg(info.get_verbose_info()) current_freq += channels_num * 0.2e6 except KeyboardInterrupt: self.printmsg("Stopping.")
def capture_rtlsdr(self, args): path = self._config_provider.get("gr-gsm", "apps_path") freq = args.freq arfcn = args.arfcn band = args.band ppm = args.ppm sample_rate = args.samp_rate gain = args.gain cfile = None burstfile = None verbose = args.print_bursts gsmtap = args.gsmtap length = args.length if freq is not None: if band: if not arfcn_converter.is_valid_downlink(freq, band): self.printmsg( "Frequency is not valid in the specified band") return else: arfcn = arfcn_converter.downlink2arfcn(freq, band) else: for band in arfcn_converter.get_bands(): if arfcn_converter.is_valid_downlink(freq, band): arfcn = arfcn.downlink2arfcn(freq, band) break elif arfcn is not None: if band: if not arfcn_converter.is_valid_arfcn(arfcn, band): self.printmsg("ARFCN is not valid in the specified band") return else: freq = arfcn_converter.arfcn2downlink(arfcn, band) else: for band in arfcn_converter.get_bands(): if arfcn_converter.is_valid_arfcn(arfcn, band): freq = arfcn_converter.arfcn2downlink(arfcn, band) break if ppm is None: ppm = self._config_provider.getint("rtl_sdr", "ppm") if sample_rate is None: sample_rate = self._config_provider.getint("rtl_sdr", "sample_rate") if gain is None: gain = self._config_provider.getint("rtl_sdr", "gain") if args.cfile is not None: cfile = self._data_access_provider.getfilepath(args.cfile) if args.bursts is not None: burstfile = self._data_access_provider.getfilepath(args.bursts) if cfile is None and burstfile is None: self.printmsg( "You must provide either a cfile or a burst file as destination." ) return tb = grgsm_capture(fc=freq, gain=gain, samp_rate=sample_rate, ppm=ppm, arfcn=arfcn, cfile=cfile, burst_file=burstfile, band=band, verbose=verbose, gsmtap=gsmtap, rec_length=length) def signal_handler(signal, frame): tb.stop() tb.wait() signal.signal(signal.SIGINT, signal_handler) tb.start() tb.wait()
def tmsi_correlation(self, args): mode = args.mode freq = args.freq arfcn = args.arfcn band = args.band ppm = args.ppm sample_rate = args.samp_rate gain = args.gain timeslot = args.timeslot max_iterations = args.max_sms msisdn = args.msisdn wait = args.wait if ppm is None: ppm = self._config_provider.getint("rtl_sdr", "ppm") if sample_rate is None: sample_rate = self._config_provider.getint("rtl_sdr", "sample_rate") if gain is None: gain = self._config_provider.getint("rtl_sdr", "gain") if freq is not None: if band: if not arfcn_converter.is_valid_downlink(freq, band): self.printmsg( "Frequency is not valid in the specified band") return else: arfcn = arfcn_converter.downlink2arfcn(freq, band) else: for band in arfcn_converter.get_bands(): if arfcn_converter.is_valid_downlink(freq, band): arfcn = arfcn_converter.downlink2arfcn(freq, band) break elif arfcn is not None: if band: if not arfcn_converter.is_valid_arfcn(arfcn, band): self.printmsg("ARFCN is not valid in the specified band") return else: freq = arfcn_converter.arfcn2downlink(arfcn, band) else: for band in arfcn_converter.get_bands(): if arfcn_converter.is_valid_arfcn(arfcn, band): freq = arfcn_converter.arfcn2downlink(arfcn, band) break # todo: stop if max_iterations < 6 response_queue = Queue.Queue() def callback(msg): response_queue.put(msg) adapter = GatAppSmsAdapter(self._config_provider, wait) adapter.register_read_callback(callback) candidates = set() i = 0 try: print "---------------------------------------------------------------start-----------------------------------------------" while i < max_iterations: print timeslot, mode, freq, arfcn, sample_rate, ppm, gain flowgraph = TmsiLiveCapture(timeslot=timeslot, chan_mode=mode, fc=freq, arfcn=arfcn, samp_rate=sample_rate, ppm=ppm, gain=gain) print "###################################################" with Silencer(): flowgraph.start() response_received = False adapter.send(sms_type=SmsType.MWID_Report, msisdn=msisdn, text=None) start = time.time() print start now = start while (now - start) < 15: if not response_queue.empty(): response = response_queue.get() # self.printmsg("response: " + response) if "Connection refused" in response.strip('\n'): self.printmsg("Failed to connect to GAT app") break response_msg = self.parse_response(response) response_type = response_msg[0] response_msisdn = response_msg[1] response_status = response_msg[2] if response_type == "sms-status": if response_status != "OK": self.printmsg("Sending to %s failed" % response_msisdn) else: pass # self.printmsg("SMS message to %s was sent." % response_msisdn) elif response_type == "sms-rcv": # recipient got our message response_received = True break if response_type == "sms-send" and response_status != "OK": self.printmsg("Sending to %s failed" % response_msisdn) elif response_type == "sms-delivery": if response_status != "OK": self.printmsg("Delivery to %s failed." % response_msisdn) else: self.printmsg( "Response from %s received." % response_msisdn) time.sleep(0.2) # ToDo: No busy waiting ! now = time.time() if not response_received: self.printmsg("Timeout: no response to the ping") # return flowgraph.wait() flowgraph.stop() flowgraph = None iteration_candidates = self.read_tmsi_file() if i == 0: candidates = candidates.union(iteration_candidates) else: candidates = candidates.intersection(iteration_candidates) print "candidates: " + str(len(candidates)) if len(candidates) == 0: if i > 0: self.printmsg("No intersection found.") break else: self.printmsg("No TMSIs captured.") break elif len(candidates) == 1: result = candidates.pop() self.printmsg("Found TMSI: {}".format(result)) break i += 1 except Exception, e: print e