[PATCH] osmocom-bb[fixeria/trx]: fake_trx: Always send control responses to where commands ar...

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Feb 28 22:17:57 UTC 2018


Review at  https://gerrit.osmocom.org/7011

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
---
M src/target/fake_trx/ctrl_if.py
M src/target/fake_trx/fake_trx.py
M src/target/fake_trx/udp_link.py
3 files changed, 13 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/11/7011/1

diff --git a/src/target/fake_trx/ctrl_if.py b/src/target/fake_trx/ctrl_if.py
index e84c1c8..394c959 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 @@
 
 		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 @@
 		# 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 c9e427c..a0534fd 100755
--- a/src/target/fake_trx/fake_trx.py
+++ b/src/target/fake_trx/fake_trx.py
@@ -124,12 +124,12 @@
 			# 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 c464802..c9640b1 100644
--- a/src/target/fake_trx/udp_link.py
+++ b/src/target/fake_trx/udp_link.py
@@ -43,3 +43,9 @@
 			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()
+                print("sending %s to %s" % (data, remote));
+		self.sock.sendto(data, remote)

-- 
To view, visit https://gerrit.osmocom.org/7011
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I24a0bba6eed059b101af95dac7d059f34dd715fc
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: fixeria/trx
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>


More information about the gerrit-log mailing list