summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-02-28 23:02:46 +0100
committerHarald Welte <laforge@gnumonks.org>2018-03-01 11:49:15 +0100
commit4e74311b00363b2ba417d7ca3ed67abfab1eaec8 (patch)
tree741ecdcad629b86300720f05700aff57da67b988
parentb1b11620191d14943303a5104d845295f74750e8 (diff)
fake_trx: Always send control responses to where commands are from
fake_trx is using locally bound and not connected UDP sockets for control commands. When we receive a control command, we should not simply send the response to the default destination, but send it back to the exact ip+prt from which the command originated. This ensures correct routing of responses even in case multiple programs are interfacing concurrently with a control socket. Change-Id: I24a0bba6eed059b101af95dac7d059f34dd715fc
-rw-r--r--src/target/fake_trx/ctrl_if.py10
-rwxr-xr-xsrc/target/fake_trx/fake_trx.py4
-rw-r--r--src/target/fake_trx/udp_link.py6
3 files changed, 13 insertions, 7 deletions
diff --git a/src/target/fake_trx/ctrl_if.py b/src/target/fake_trx/ctrl_if.py
index e84c1c87..394c959f 100644
--- a/src/target/fake_trx/ctrl_if.py
+++ b/src/target/fake_trx/ctrl_if.py
@@ -25,16 +25,16 @@
from udp_link import UDPLink
class CTRLInterface(UDPLink):
- def handle_rx(self, data):
+ def handle_rx(self, data, remote):
# print(data)
if self.verify_req(data):
request = self.prepare_req(data)
rc = self.parse_cmd(request)
if type(rc) is tuple:
- self.send_response(request, rc[0], rc[1])
+ self.send_response(request, remote, rc[0], rc[1])
else:
- self.send_response(request, rc)
+ self.send_response(request, remote, rc)
else:
print("[!] Wrong data on CTRL interface")
@@ -66,7 +66,7 @@ class CTRLInterface(UDPLink):
return True
- def send_response(self, request, response_code, params = None):
+ def send_response(self, request, remote, response_code, params = None):
# Include status code, for example ["TXTUNE", "0", "941600"]
request.insert(1, str(response_code))
@@ -77,7 +77,7 @@ class CTRLInterface(UDPLink):
# Add the response signature, and join back to string
response = "RSP " + " ".join(request) + "\0"
# Now we have something like "RSP TXTUNE 0 941600"
- self.send(response)
+ self.sendto(response, remote)
def parse_cmd(self, request):
raise NotImplementedError
diff --git a/src/target/fake_trx/fake_trx.py b/src/target/fake_trx/fake_trx.py
index c9e427ca..a0534fd2 100755
--- a/src/target/fake_trx/fake_trx.py
+++ b/src/target/fake_trx/fake_trx.py
@@ -124,12 +124,12 @@ class Application:
# 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())
+ 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())
+ self.bb_ctrl.handle_rx(data.decode(), addr)
def shutdown(self):
print("[i] Shutting down...")
diff --git a/src/target/fake_trx/udp_link.py b/src/target/fake_trx/udp_link.py
index c464802b..dda901cb 100644
--- a/src/target/fake_trx/udp_link.py
+++ b/src/target/fake_trx/udp_link.py
@@ -43,3 +43,9 @@ class UDPLink:
data = data.encode()
self.sock.sendto(data, (self.remote_addr, self.remote_port))
+
+ def sendto(self, data, remote):
+ if type(data) not in [bytearray, bytes]:
+ data = data.encode()
+
+ self.sock.sendto(data, remote)