From 54dd82ffcf08d93d8df403e07ebb3a6f49f5a23c Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 23 Aug 2011 17:00:23 +0200 Subject: Firmware can now be loaded from GUI, threading problem fixed --- Src/CatcherGUI/.project | 17 -- Src/CatcherGUI/.pydevproject | 10 -- Src/PyCatcher/GUI/mainWindow.glade | 176 +++++++++++++++++++-- Src/PyCatcher/src/driverConnector.py | 78 +++++++-- Src/PyCatcher/src/main.py | 3 - Src/PyCatcher/src/pyCatcherController.py | 44 +++++- Src/PyCatcher/src/pyCatcherModel.py | 12 +- Src/PyCatcher/src/pyCatcherView.py | 130 ++++++++++++--- .../src/host/layer23/src/misc/Makefile.am | 5 +- 9 files changed, 380 insertions(+), 95 deletions(-) delete mode 100644 Src/CatcherGUI/.project delete mode 100644 Src/CatcherGUI/.pydevproject (limited to 'Src') diff --git a/Src/CatcherGUI/.project b/Src/CatcherGUI/.project deleted file mode 100644 index b2e8d0b..0000000 --- a/Src/CatcherGUI/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - CatcherGUI - - - - - - org.python.pydev.PyDevBuilder - - - - - - org.python.pydev.pythonNature - - diff --git a/Src/CatcherGUI/.pydevproject b/Src/CatcherGUI/.pydevproject deleted file mode 100644 index 509e5b5..0000000 --- a/Src/CatcherGUI/.pydevproject +++ /dev/null @@ -1,10 +0,0 @@ - - - - -Default -python 2.6 - -/CatcherGUI/src - - diff --git a/Src/PyCatcher/GUI/mainWindow.glade b/Src/PyCatcher/GUI/mainWindow.glade index 4ccaf4d..1b7da70 100644 --- a/Src/PyCatcher/GUI/mainWindow.glade +++ b/Src/PyCatcher/GUI/mainWindow.glade @@ -3,11 +3,10 @@ - True False - PyCatcher Prototype - 800 - 600 + IMSI Catcher Detector + 1024 + 700 @@ -17,12 +16,28 @@ True False + both + + + True + False + False + Toggle Firmware + True + modem + + + + False + True + + True False False - toggle scanning + Toggle Scanning True network-wireless @@ -32,6 +47,36 @@ True + + + True + False + False + Open File + True + document-open + + + + False + True + + + + + True + False + False + Save Project + True + document-save + + + + False + True + + False @@ -44,23 +89,82 @@ True False - + True - True - automatic - automatic + False + + + - + True False - + + True + False + False + Zoom In + True + zoom-in + + + + False + True + + + + + True + False + False + Zoom Out + True + zoom-out + + + + False + True + + + + True False - gtk-missing-image + False + Fit To Screen + True + zoom-best-fit + + + False + True + + + + + True + False + False + 100% + True + zoom-original + + + + False + True + + + False + True + 1 + @@ -85,9 +189,17 @@ True False - + True True + never + automatic + + + True + True + + True @@ -107,9 +219,17 @@ - + True True + automatic + + + True + True + False + + True @@ -119,7 +239,7 @@ - True + False True 2 @@ -132,10 +252,34 @@ - + True False 2 + + + True + False + Firmware: Not Loaded + + + True + True + 0 + + + + + True + False + Scanner: Not scanning + + + True + True + 1 + + False diff --git a/Src/PyCatcher/src/driverConnector.py b/Src/PyCatcher/src/driverConnector.py index d7509e6..6ae998b 100644 --- a/Src/PyCatcher/src/driverConnector.py +++ b/Src/PyCatcher/src/driverConnector.py @@ -1,26 +1,70 @@ from pyCatcherModel import BaseStationInformation import subprocess import threading +import re +from pyCatcherSettings import Commands +import sys +import time +import gtk #@UnresolvedImport -class DriverConnector: - def __init__ (self, bs_found_callback): - self._thread_break = False - self._bs_found_callback = bs_found_callback - pass +class DriverConnector: + def __init__ (self): + self._scan_thread_break = False + self._firmware_thread_break = False + self._firmware_waiting_callback = None + self._firmware_loaded_callback = None + self._test_thread = None def start_scanning (self): - self._thread_break = False + self._scan_thread_break = False threading.Thread(target= self._do_scan).start() - def _do_scan(self): - #TODO: insert right command here - ps_object = subprocess.Popen('ps', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - while not self._thread_break: - base_station_info = BaseStationInformation() - base_station_info.parse_file(ps_object.stdout) - self._bs_found_callback(base_station_info) - ps_object.kill() - + def start_firmware(self, firmware_waiting_callback, firmware_loaded_callback): + self._firmware_thread_break = False + self._firmware_waiting_callback = firmware_waiting_callback + self._firmware_loaded_callback = firmware_loaded_callback + testThread = FirmwareThread(self._firmware_waiting_callback, self._firmware_loaded_callback, self._firmware_thread_break) + testThread.start() + def stop_scanning (self): - self._thread_break = True - \ No newline at end of file + self._scan_thread_break = True + + def stop_firmware(self): + self._firmware_thread_break = True + +class FirmwareThread(threading.Thread): + def __init__(self, firmware_waiting_callback, firmware_loaded_callback, thread_break): + gtk.gdk.threads_init() + threading.Thread.__init__(self) + self._firmware_waiting_callback = firmware_waiting_callback + self._firmware_loaded_callback = firmware_loaded_callback + self._thread_break = thread_break + + def run(self): + loader_process_object = subprocess.Popen(Commands['osmocon_command'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + time.sleep(3) + self._firmware_waiting_callback() + while not self._thread_break: + line = loader_process_object.stdout.readline() + #if line: + # print line + if (line.strip() == 'Finishing download phase'): + self._firmware_loaded_callback() + #time.sleep(0.5) + loader_process_object.kill() + +class ScanThread(threading.Thread): + def __init__(self, thread_break): + gtk.gdk.threads_init() + threading.Thread.__init__(self) + self._thread_break = thread_break + + def run(self): + scan_command = Commands['scan_command'] + scan_process = subprocess.Popen(scan_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + while not self._scan_thread_break: + base_station_info = BaseStationInformation() + base_station_info.parse_file(scan_process.stdout) + self._bs_found_callback(base_station_info) + scan_process.kill() + \ No newline at end of file diff --git a/Src/PyCatcher/src/main.py b/Src/PyCatcher/src/main.py index 50f3d86..0bbda10 100644 --- a/Src/PyCatcher/src/main.py +++ b/Src/PyCatcher/src/main.py @@ -1,7 +1,4 @@ from pyCatcherController import PyCatcherController -import time -from pyCatcherView import PyCatcherGUI -import gtk #@UnresolvedImport def main (): controller = PyCatcherController() diff --git a/Src/PyCatcher/src/pyCatcherController.py b/Src/PyCatcher/src/pyCatcherController.py index 06d8c8e..a55bd5e 100644 --- a/Src/PyCatcher/src/pyCatcherController.py +++ b/Src/PyCatcher/src/pyCatcherController.py @@ -3,21 +3,49 @@ import pygtk import gtk #@UnresolvedImport import gtk.glade #@UnresolvedImport from driverConnector import DriverConnector -from pyCatcherModel import BaseStationInformation +from pyCatcherModel import BaseStationInformation, BaseStationInformationList from pyCatcherView import PyCatcherGUI +from pyCatcherController import DriverConnector class PyCatcherController: def __init__(self): - self.gui = PyCatcherGUI(self) - gtk.main() - self.driver_connector = DriverConnector(self._foundBaseStationCallback) + self.bs_tree_list_data = gtk.ListStore(str,str,str,str) + + self._gui = PyCatcherGUI(self) + self._driver_connector = DriverConnector() + + self._gui.log_line("GUI initialized") + + gtk.main() + + def log_message(self, message): + self._gui.log_line(message) + def start_scan(self): - self.driver_connector.start_scanning() + self._gui.log_line("start scan") def stop_scan(self): - self.driver_connector.stop_scanning() + self._gui.log_line("stop scan") + + def start_firmware(self): + self._gui.log_line("start firmware") + self._driver_connector.start_firmware(self._firmware_waiting_callback, self._firmware_done_callback) + + def stop_firmware(self): + self._gui.log_line("stop firmware") + print 'stop firmwares' + self._driver_connector.stop_firmware() + + def _found_base_station_callback(self): + self._gui.log_line("found base station") + + def _firmware_waiting_callback(self): + self._gui.log_line("firmware waiting for device") + self._gui.show_info('Switch on the phone now.', 'Firmware') - def _foundBaseStationCallback(self): - print "found a station" + + def _firmware_done_callback(self): + self._gui.log_line("firmware loaded, ready for scanning") + self._gui.show_info('Firmware load completed', 'Firmware') \ No newline at end of file diff --git a/Src/PyCatcher/src/pyCatcherModel.py b/Src/PyCatcher/src/pyCatcherModel.py index 7ece9b6..6473dc7 100644 --- a/Src/PyCatcher/src/pyCatcherModel.py +++ b/Src/PyCatcher/src/pyCatcherModel.py @@ -1,3 +1,5 @@ +import datetime + class BaseStationInformation: def __init__ (self): self.arcfn = 0 @@ -23,13 +25,15 @@ class BaseStationInformation: self.s4 = fileobject.readline().split(' ') return self - def __str__ (self): - return 'foo' + self.arcfn + def get_tree_data(self): + return [self.bsic, self.arcfn, self.rxlev, datetime.datetime.now().strftime("%H:%M:%S")] class BaseStationInformationList: def __init__(self): - self.base_station_list + self.base_station_list = [] def add_station(self): pass - \ No newline at end of file + + def get_dot_code(self): + pass \ No newline at end of file diff --git a/Src/PyCatcher/src/pyCatcherView.py b/Src/PyCatcher/src/pyCatcherView.py index de71727..8f0ee6b 100644 --- a/Src/PyCatcher/src/pyCatcherView.py +++ b/Src/PyCatcher/src/pyCatcherView.py @@ -1,39 +1,131 @@ import sys +import locale import pygtk import gtk #@UnresolvedImport import gtk.glade #@UnresolvedImport +from pyCatcherModel import BaseStationInformation +from xdot import DotWidget +import datetime +import time class PyCatcherGUI: def __init__(self, catcher_controller): - self.scan_toggled_on = False - self.catcher_controller = catcher_controller + encoding = locale.getlocale()[1] + self._utf8conv = lambda x : unicode(x, encoding).encode('utf8') - self.w_tree = gtk.glade.XML("../GUI/mainWindow.glade") - self.main_window = self.w_tree.get_widget("main_window") + self._scan_toggled_on = False + self._firmware_toggled_on = False + + self._catcher_controller = catcher_controller + + self._w_tree = gtk.glade.XML("../GUI/mainWindow.glade") + + self._bs_tree_view = self._w_tree.get_widget("bs_table") + self._add_column("Provider", 0) + self._add_column("Frequency", 1) + self._add_column("Strength",2) + self._add_column("Last seen", 3) + self._bs_tree_view.set_model(self._catcher_controller.bs_tree_list_data) + + self._horizontal_container = self._w_tree.get_widget("vbox4") + self._dot_widget = DotWidget() + self._horizontal_container.pack_start_defaults(self._dot_widget) + self._dot_widget.show() + + self._main_window = self._w_tree.get_widget("main_window") signals = {"on_main_window_destroy": gtk.main_quit, - "on_scan_toggle_toggled": self._toggle_scan + "on_scan_toggle_toggled": self._on_toggle_scan, + "on_firmware_toggle_toggled": self._on_toggle_firmware, + "on_graph_zoom_in_clicked": self._dot_widget.on_zoom_in, + "on_graph_zoom_out_clicked": self._dot_widget.on_zoom_out, + "on_graph_fit_clicked": self._dot_widget.on_zoom_fit, + "on_graph_zoom_default_clicked": self._dot_widget.on_zoom_100, + "on_save_project_clicked": self._on_save_project, + "on_open_file_clicked": self._on_open_file } - self.w_tree.signal_autoconnect(signals) + self._w_tree.signal_autoconnect(signals) + + log_view = self._w_tree.get_widget("log_output") + self._log_buffer = log_view.get_buffer() + self._log_buffer.insert(self._log_buffer.get_end_iter(),self._utf8conv("-- Log execution on " + datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M %p") + " --\n\n")) - self.bs_view = self.w_tree.get_widget("bs_table") - self._add_column("foo", 0) - self._add_column("bar", 1) + self._main_window.show() def _add_column(self, name, index): column = gtk.TreeViewColumn(name, gtk.CellRendererText(), text=index) column.set_resizable(True) column.set_sort_column_id(index) - self.bs_view.append_column(column) + self._bs_tree_view.append_column(column) - def _toggle_scan (self, widget): - if(not self.scan_toggled_on): - print "toggle on" - self.catcher_controller.start_scan() - self.scan_toggled_on = True + def _on_toggle_scan(self, widget): + if(not self._scan_toggled_on): + self._catcher_controller.start_scan() + self._scan_toggled_on = True + else: + self._catcher_controller.stop_scan() + self._scan_toggled_on = False + + def _on_toggle_firmware(self, widget): + if(not self._firmware_toggled_on): + self._catcher_controller.start_firmware() + self._firmware_toggled_on = True + else: + self._catcher_controller.stop_firmware() + self._firmware_toggled_on = False + + def _on_open_file(self, widget): + chooser = gtk.FileChooserDialog(title="Open dot File", + action=gtk.FILE_CHOOSER_ACTION_OPEN, + buttons=(gtk.STOCK_CANCEL, + gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, + gtk.RESPONSE_OK)) + chooser.set_default_response(gtk.RESPONSE_OK) + filter = gtk.FileFilter() + filter.set_name("Graphviz dot files") + filter.add_pattern("*.dot") + chooser.add_filter(filter) + filter = gtk.FileFilter() + filter.set_name("All files") + filter.add_pattern("*") + chooser.add_filter(filter) + if chooser.run() == gtk.RESPONSE_OK: + filename = chooser.get_filename() + chooser.destroy() + self.load_dot_from_file(filename) else: - print "toggle off" - self.catcher_controller.stop_scan() - self.scan_toggled_on = False - \ No newline at end of file + chooser.destroy() + + def load_dot_from_file(self, filename): + try: + fp = file(filename, 'rt') + self.load_dot(fp.read(), filename) + fp.close() + except IOError, ex: + self.show_info(ex) + + def load_dot(self, dotcode, filename=""): + if self._dot_widget.set_dotcode(dotcode, filename): + self._dot_widget.zoom_to_fit() + + def _on_save_project(self, widget): + pass + + def show_info(self, message, title='PyCatcher', time_to_sleep=3, type='INFO'): + gtk_type = {'INFO' : gtk.MESSAGE_INFO, + 'ERROR': gtk.MESSAGE_ERROR} + + dlg = gtk.MessageDialog(type=gtk.MESSAGE_INFO, + message_format=str(message) + ) + + dlg.set_title(title) + #dlg.run() + dlg.show() + time.sleep(time_to_sleep) + dlg.destroy() + + def log_line(self, line): + self._log_buffer.insert(self._log_buffer.get_end_iter(),self._utf8conv(datetime.datetime.now().strftime("%I:%M:%S %p")+ ": " + line + "\n")) \ No newline at end of file diff --git a/Src/osmoconbb/src/host/layer23/src/misc/Makefile.am b/Src/osmoconbb/src/host/layer23/src/misc/Makefile.am index 0b59f38..a4cabac 100644 --- a/Src/osmoconbb/src/host/layer23/src/misc/Makefile.am +++ b/Src/osmoconbb/src/host/layer23/src/misc/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) LDADD = ../common/liblayer23.a $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) -bin_PROGRAMS = bcch_scan ccch_scan echo_test cell_log cbch_sniff +bin_PROGRAMS = bcch_scan ccch_scan echo_test cell_log cbch_sniff catcher bcch_scan_SOURCES = ../common/main.c app_bcch_scan.c bcch_scan.c ccch_scan_SOURCES = ../common/main.c app_ccch_scan.c rslms.c @@ -11,3 +11,6 @@ cell_log_LDADD = $(LDADD) -lm cell_log_SOURCES = ../common/main.c app_cell_log.c cell_log.c \ ../../../gsmmap/geo.c cbch_sniff_SOURCES = ../common/main.c app_cbch_sniff.c +catcher_LDADD = $(LDADD) -lm +catcher_SOURCES = ../common/main.c app_catcher.c catcher.c \ + ../../../gsmmap/geo.c -- cgit v1.2.3-55-g7522