コード例 #1
0
ファイル: ctrl_cmd.py プロジェクト: axilirator/osmocom-bb
	def __init__(self):
		self.app_print_copyright(APP_CR_HOLDERS)
		self.argv = self.parse_argv()

		# Set up signal handlers
		signal.signal(signal.SIGINT, self.sig_handler)

		# Configure logging
		self.app_init_logging(self.argv)

		# Init UDP connection
		self.ctrl_link = UDPLink(
			self.argv.remote_addr, self.argv.base_port + 1,
			self.argv.bind_addr, self.argv.bind_port)

		# Debug print
		log.info("Init TRXC interface (%s)" \
			% self.ctrl_link.desc_link())
コード例 #2
0
 def __init__(self, *udp_link_args):
     UDPLink.__init__(self, *udp_link_args)
     log.debug("Init TRXC interface (%s)" % self.desc_link())
コード例 #3
0
ファイル: ctrl_cmd.py プロジェクト: axilirator/osmocom-bb
class Application(ApplicationBase):
	def __init__(self):
		self.app_print_copyright(APP_CR_HOLDERS)
		self.argv = self.parse_argv()

		# Set up signal handlers
		signal.signal(signal.SIGINT, self.sig_handler)

		# Configure logging
		self.app_init_logging(self.argv)

		# Init UDP connection
		self.ctrl_link = UDPLink(
			self.argv.remote_addr, self.argv.base_port + 1,
			self.argv.bind_addr, self.argv.bind_port)

		# Debug print
		log.info("Init TRXC interface (%s)" \
			% self.ctrl_link.desc_link())

	def parse_argv(self):
		parser = argparse.ArgumentParser(prog = "ctrl_cmd",
			description = "Auxiliary tool to send control commands")

		# Register common logging options
		self.app_reg_logging_options(parser)

		trx_group = parser.add_argument_group("TRX interface")
		trx_group.add_argument("-r", "--remote-addr",
			dest = "remote_addr", type = str, default = "127.0.0.1",
			help = "Set remote address (default %(default)s)")
		trx_group.add_argument("-b", "--bind-addr",
			dest = "bind_addr", type = str, default = "0.0.0.0",
			help = "Set bind address (default %(default)s)")
		trx_group.add_argument("-p", "--base-port",
			dest = "base_port", type = int, default = 6700,
			help = "Set base port number (default %(default)s)")
		trx_group.add_argument("-P", "--bind-port",
			dest = "bind_port", type = int, default = 0,
			help = "Set bind port number (default random)")
		trx_group.add_argument("-f", "--fuzzing",
			dest = "fuzzing", action = "store_true",
			help = "Send raw payloads (without CMD)")

		return parser.parse_args()

	def run(self):
		while True:
			self.print_prompt()

			# Wait until we get any data on any socket
			socks = [sys.stdin, self.ctrl_link.sock]
			r_event, w_event, x_event = select.select(socks, [], [])

			# Check for incoming CTRL commands
			if sys.stdin in r_event:
				cmd = sys.stdin.readline()
				self.handle_cmd(cmd)

			if self.ctrl_link.sock in r_event:
				data, addr = self.ctrl_link.sock.recvfrom(128)
				sys.stdout.write("\r%s\n" % data.decode())
				sys.stdout.flush()

	def handle_cmd(self, cmd):
		# Strip spaces, tabs, etc.
		cmd = cmd.strip().strip("\0")

		# Send a command
		if self.argv.fuzzing:
			self.ctrl_link.send("%s" % cmd)
		else:
			self.ctrl_link.send("CMD %s\0" % cmd)

	def print_prompt(self):
		sys.stdout.write("TRXC# ")
		sys.stdout.flush()

	def sig_handler(self, signum, frame):
		log.info("Signal %d received" % signum)
		if signum is signal.SIGINT:
			sys.exit(0)
コード例 #4
0
 def run(self):
     self.link = UDPLink("127.0.0.1", 5800, "0.0.0.0", 5700)
     self.clck = CLCKGen([self.link], ind_period=51)
     self.clck.start()
コード例 #5
0
class Application(ApplicationBase):
    def __init__(self):
        self.app_print_copyright(APP_CR_HOLDERS)
        self.argv = self.parse_argv()

        # Set up signal handlers
        signal.signal(signal.SIGINT, self.sig_handler)

        # Configure logging
        self.app_init_logging(self.argv)

        # Init UDP connection
        self.ctrl_link = UDPLink(self.argv.remote_addr,
                                 self.argv.base_port + 1, self.argv.bind_addr,
                                 self.argv.bind_port)

        # Debug print
        log.info("Init TRXC interface (%s)" \
         % self.ctrl_link.desc_link())

    def parse_argv(self):
        parser = argparse.ArgumentParser(
            prog="ctrl_cmd",
            description="Auxiliary tool to send control commands")

        # Register common logging options
        self.app_reg_logging_options(parser)

        trx_group = parser.add_argument_group("TRX interface")
        trx_group.add_argument("-r",
                               "--remote-addr",
                               dest="remote_addr",
                               type=str,
                               default="127.0.0.1",
                               help="Set remote address (default %(default)s)")
        trx_group.add_argument("-b",
                               "--bind-addr",
                               dest="bind_addr",
                               type=str,
                               default="0.0.0.0",
                               help="Set bind address (default %(default)s)")
        trx_group.add_argument(
            "-p",
            "--base-port",
            dest="base_port",
            type=int,
            default=6700,
            help="Set base port number (default %(default)s)")
        trx_group.add_argument("-P",
                               "--bind-port",
                               dest="bind_port",
                               type=int,
                               default=0,
                               help="Set bind port number (default random)")
        trx_group.add_argument("-f",
                               "--fuzzing",
                               dest="fuzzing",
                               action="store_true",
                               help="Send raw payloads (without CMD)")

        return parser.parse_args()

    def run(self):
        while True:
            self.print_prompt()

            # Wait until we get any data on any socket
            socks = [sys.stdin, self.ctrl_link.sock]
            r_event, w_event, x_event = select.select(socks, [], [])

            # Check for incoming CTRL commands
            if sys.stdin in r_event:
                cmd = sys.stdin.readline()
                self.handle_cmd(cmd)

            if self.ctrl_link.sock in r_event:
                data, addr = self.ctrl_link.sock.recvfrom(128)
                sys.stdout.write("\r%s\n" % data.decode())
                sys.stdout.flush()

    def handle_cmd(self, cmd):
        # Strip spaces, tabs, etc.
        cmd = cmd.strip().strip("\0")

        # Send a command
        if self.argv.fuzzing:
            self.ctrl_link.send("%s" % cmd)
        else:
            self.ctrl_link.send("CMD %s\0" % cmd)

    def print_prompt(self):
        sys.stdout.write("TRXC# ")
        sys.stdout.flush()

    def sig_handler(self, signum, frame):
        log.info("Signal %d received" % signum)
        if signum == signal.SIGINT:
            sys.exit(0)
コード例 #6
0
    def run(self):
        # Init TRX CTRL interface for BTS
        self.bts_ctrl = CTRLInterfaceBTS(self.bts_addr,
                                         self.bts_base_port + 101,
                                         self.trx_bind_addr,
                                         self.bts_base_port + 1)

        # Init TRX CTRL interface for BB
        self.bb_ctrl = CTRLInterfaceBB(self.bb_addr, self.bb_base_port + 101,
                                       self.trx_bind_addr,
                                       self.bb_base_port + 1)

        # Power measurement emulation
        # Noise: -120 .. -105
        # BTS: -75 .. -50
        self.pm = FakePM(-120, -105, -75, -50)

        # Share a FakePM instance between both BTS and BB
        self.bts_ctrl.pm = self.pm
        self.bb_ctrl.pm = self.pm

        # Init DATA links
        self.bts_data = UDPLink(self.bts_addr, self.bts_base_port + 102,
                                self.trx_bind_addr, self.bts_base_port + 2)
        self.bb_data = UDPLink(self.bb_addr, self.bb_base_port + 102,
                               self.trx_bind_addr, self.bb_base_port + 2)

        # BTS <-> BB burst forwarding
        self.burst_fwd = BurstForwarder(self.bts_data, self.bb_data)
        self.burst_fwd.randomize_dl_toa256 = self.randomize_dl_toa256
        self.burst_fwd.randomize_ul_toa256 = self.randomize_ul_toa256
        self.burst_fwd.randomize_dl_rssi = self.randomize_dl_rssi
        self.burst_fwd.randomize_ul_rssi = self.randomize_ul_rssi

        # Share a BurstForwarder instance between BTS and BB
        self.bts_ctrl.burst_fwd = self.burst_fwd
        self.bb_ctrl.burst_fwd = self.burst_fwd

        # Provide clock to BTS
        self.bts_clck = UDPLink(self.bts_addr, self.bts_base_port + 100,
                                self.trx_bind_addr, self.bts_base_port)
        self.clck_gen = CLCKGen([self.bts_clck])
        self.bts_ctrl.clck_gen = self.clck_gen

        print("[i] Init complete")

        # Enter main loop
        while True:
            socks = [
                self.bts_ctrl.sock, self.bb_ctrl.sock, self.bts_data.sock,
                self.bb_data.sock
            ]

            # Wait until we get any data on any socket
            r_event, w_event, x_event = select.select(socks, [], [])

            # Downlink: BTS -> BB
            if self.bts_data.sock in r_event:
                self.burst_fwd.bts2bb()

            # Uplink: BB -> BTS
            if self.bb_data.sock in r_event:
                self.burst_fwd.bb2bts()

            # CTRL commands from BTS
            if self.bts_ctrl.sock in r_event:
                data, addr = self.bts_ctrl.sock.recvfrom(128)
                self.bts_ctrl.handle_rx(data.decode(), addr)

            # CTRL commands from BB
            if self.bb_ctrl.sock in r_event:
                data, addr = self.bb_ctrl.sock.recvfrom(128)
                self.bb_ctrl.handle_rx(data.decode(), addr)
コード例 #7
0
ファイル: data_if.py プロジェクト: osmocom/osmocom-bb
    def __init__(self, *udp_link_args):
        # Default header version (legacy)
        self._hdr_ver = 0x00

        UDPLink.__init__(self, *udp_link_args)
        log.debug("Init TRXD interface (%s)" % self.desc_link())
コード例 #8
0
ファイル: data_if.py プロジェクト: axilirator/osmocom-bb
	def __init__(self, *udp_link_args):
		UDPLink.__init__(self, *udp_link_args)
		log.debug("Init TRXD interface (%s)" % self.desc_link())
コード例 #9
0
ファイル: ctrl_if.py プロジェクト: osmocom/osmocom-bb
    def __init__(self, *udp_link_args):
        UDPLink.__init__(self, *udp_link_args)
        log.debug("Init TRXC interface (%s)" % self.desc_link())

        # Do not delay RSP messages by default
        self.rsp_delay_ms = 0
コード例 #10
0
class Application:
    # Application variables
    remote_addr = "127.0.0.1"
    bind_addr = "0.0.0.0"
    base_port = 5700
    bind_port = 0
    fuzzing = False

    def __init__(self):
        print_copyright(CR_HOLDERS)
        self.parse_argv()

        # Set up signal handlers
        signal.signal(signal.SIGINT, self.sig_handler)

        # Init UDP connection
        self.ctrl_link = UDPLink(self.remote_addr, self.base_port + 1,
                                 self.bind_addr, self.bind_port)

        # Debug print
        print("[i] Init CTRL interface (%s)" \
         % self.ctrl_link.desc_link())

    def print_help(self, msg=None):
        s  = " Usage: " + sys.argv[0] + " [options]\n\n" \
          " Some help...\n" \
          "  -h --help           this text\n\n"

        s += " TRX interface specific\n" \
          "  -r --remote-addr    Set remote address (default %s)\n"   \
          "  -p --base-port      Set base port number (default %d)\n" \
          "  -P --bind-port      Set local port number (default: random)\n" \
          "  -b --bind-addr      Set local address (default %s)\n" \
          "  -f --fuzzing        Send raw payloads (without CMD)\n"   \

        print(s % (self.remote_addr, self.base_port, self.bind_addr))

        if msg is not None:
            print(msg)

    def parse_argv(self):
        try:
            opts, args = getopt.getopt(sys.argv[1:], "r:p:P:b:fh", [
                "help",
                "fuzzing",
                "base-port=",
                "bind-port=",
                "bind-addr=",
                "remote-addr=",
            ])
        except getopt.GetoptError as err:
            self.print_help("[!] " + str(err))
            sys.exit(2)

        for o, v in opts:
            if o in ("-h", "--help"):
                self.print_help()
                sys.exit(2)

            elif o in ("-r", "--remote-addr"):
                self.remote_addr = v
            elif o in ("-b", "--bind-addr"):
                self.bind_addr = v
            elif o in ("-p", "--base-port"):
                self.base_port = int(v)
            elif o in ("-P", "--bind-port"):
                self.bind_port = int(v)
            elif o in ("-f", "--fuzzing"):
                self.fuzzing = True

    def run(self):
        while True:
            self.print_prompt()

            # Wait until we get any data on any socket
            socks = [sys.stdin, self.ctrl_link.sock]
            r_event, w_event, x_event = select.select(socks, [], [])

            # Check for incoming CTRL commands
            if sys.stdin in r_event:
                cmd = sys.stdin.readline()
                self.handle_cmd(cmd)

            if self.ctrl_link.sock in r_event:
                data, addr = self.ctrl_link.sock.recvfrom(128)
                sys.stdout.write("\r%s\n" % data.decode())
                sys.stdout.flush()

    def handle_cmd(self, cmd):
        # Strip spaces, tabs, etc.
        cmd = cmd.strip().strip("\0")

        # Send a command
        if self.fuzzing:
            self.ctrl_link.send("%s" % cmd)
        else:
            self.ctrl_link.send("CMD %s\0" % cmd)

    def print_prompt(self):
        sys.stdout.write("CTRL# ")
        sys.stdout.flush()

    def sig_handler(self, signum, frame):
        print("\n\nSignal %d received" % signum)
        if signum is signal.SIGINT:
            sys.exit(0)