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
This commit is contained in:
parent
b1b1162019
commit
4e74311b00
|
@ -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
|
||||
|
|
|
@ -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...")
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue