From: Aleksander Morgado <aleksander@aleksander.es>
To: barebox@lists.infradead.org
Cc: Aleksander Morgado <aleksander@aleksander.es>
Subject: [PATCH 03/10] ratp: port ping operation to req/rsp format
Date: Fri, 2 Feb 2018 12:14:35 +0100 [thread overview]
Message-ID: <20180202111442.12444-4-aleksander@aleksander.es> (raw)
In-Reply-To: <20180202111442.12444-1-aleksander@aleksander.es>
The ping operation executed via RATP is processed in the following way:
* The client sends a 'ping' packet to barebox.
* Barebox replies with a 'pong' packet.
We now consolidate this process using the request and response
packet flags, and making them part of the same 'ping' packet type.
Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---
common/ratp.c | 12 ++++++------
scripts/remote/controller.py | 14 +++++++-------
scripts/remote/messages.py | 18 ++++++++++--------
3 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/common/ratp.c b/common/ratp.c
index 7d7fb5fcd..222bf624a 100644
--- a/common/ratp.c
+++ b/common/ratp.c
@@ -32,8 +32,7 @@
#include <fs.h>
#define BB_RATP_TYPE_CONSOLE 1
-#define BB_RATP_TYPE_PING 4
-#define BB_RATP_TYPE_PONG 5
+#define BB_RATP_TYPE_PING 2
#define BB_RATP_TYPE_GETENV 6
#define BB_RATP_TYPE_GETENV_RETURN 7
#define BB_RATP_TYPE_FS 8
@@ -169,7 +168,8 @@ static int ratp_bb_send_pong(struct ratp_ctx *ctx)
buf = xzalloc(len);
rbb = buf;
- rbb->type = cpu_to_be16(BB_RATP_TYPE_PONG);
+ rbb->type = cpu_to_be16(BB_RATP_TYPE_PING);
+ rbb->flags = cpu_to_be16(BB_RATP_FLAG_RESPONSE);
ret = ratp_send(&ctx->ratp, buf, len);
@@ -231,10 +231,10 @@ static int ratp_bb_dispatch(struct ratp_ctx *ctx, const void *buf, int len)
pr_debug("got command: %s\n", ratp_command);
break;
- case BB_RATP_TYPE_PONG:
- break;
-
case BB_RATP_TYPE_PING:
+ if (flags & BB_RATP_FLAG_RESPONSE)
+ break;
+
ret = ratp_bb_send_pong(ctx);
break;
diff --git a/scripts/remote/controller.py b/scripts/remote/controller.py
index c3f29334a..518973038 100644
--- a/scripts/remote/controller.py
+++ b/scripts/remote/controller.py
@@ -32,11 +32,11 @@ def unpack(data):
logging.debug("received: console request")
return BBPacketConsoleRequest(raw=data)
elif p_type == BBType.ping:
+ if p_flag & BBFlag.response:
+ logging.debug("received: pong")
+ return BBPacketPingResponse(raw=data)
logging.debug("received: ping")
- return BBPacketPing(raw=data)
- elif p_type == BBType.pong:
- logging.debug("received: pong")
- return BBPacketPong(raw=data)
+ return BBPacketPingRequest(raw=data)
elif p_type == BBType.getenv_return:
logging.debug("received: getenv_return")
return BBPacketGetenvReturn(raw=data)
@@ -92,8 +92,8 @@ class Controller(Thread):
self.fsserver = RatpFSServer(path)
def ping(self):
- self._send(BBPacketPing())
- r = self._expect(BBPacketPong)
+ self._send(BBPacketPingRequest())
+ r = self._expect(BBPacketPingResponse)
logging.info("Ping: %r", r)
if not r:
return 1
@@ -157,7 +157,7 @@ class Controller(Thread):
self._txq.put(BBPacketConsoleIndication(text=text))
def send_async_ping(self):
- self._txq.put(BBPacketPing())
+ self._txq.put(BBPacketPingRequest())
def main():
diff --git a/scripts/remote/messages.py b/scripts/remote/messages.py
index 2f63f1831..6c5601d78 100644
--- a/scripts/remote/messages.py
+++ b/scripts/remote/messages.py
@@ -13,8 +13,7 @@ class BBFlag(object):
class BBType(object):
console = 1
- ping = 4
- pong = 5
+ ping = 2
getenv = 6
getenv_return = 7
fs = 8
@@ -98,20 +97,23 @@ class BBPacketConsoleIndication(BBPacket):
return self.text
-class BBPacketPing(BBPacket):
+class BBPacketPingRequest(BBPacket):
def __init__(self, raw=None):
- super(BBPacketPing, self).__init__(BBType.ping, raw=raw)
+ super(BBPacketPingRequest, self).__init__(BBType.ping,
+ raw=raw)
def __repr__(self):
- return "BBPacketPing()"
+ return "BBPacketPingRequest()"
-class BBPacketPong(BBPacket):
+class BBPacketPingResponse(BBPacket):
def __init__(self, raw=None):
- super(BBPacketPong, self).__init__(BBType.pong, raw=raw)
+ super(BBPacketPingResponse, self).__init__(BBType.ping,
+ BBFlag.response,
+ raw=raw)
def __repr__(self):
- return "BBPacketPong()"
+ return "BBPacketPingResponse()"
class BBPacketGetenv(BBPacket):
--
2.15.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-02-02 11:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-02 11:14 [RFC PATCH 00/10] ratp: new generic RATP command support Aleksander Morgado
2018-02-02 11:14 ` [PATCH 01/10] ratp: define message type flags Aleksander Morgado
2018-02-02 11:14 ` [PATCH 02/10] ratp: port command operation to req/rsp/ind format Aleksander Morgado
2018-02-02 11:14 ` Aleksander Morgado [this message]
2018-02-02 11:14 ` [PATCH 04/10] ratp: port getenv operation to req/rsp format Aleksander Morgado
2018-02-02 11:14 ` [PATCH 05/10] ratp: port filesystem " Aleksander Morgado
2018-02-02 11:14 ` [PATCH 06/10] ratp: implement generic command support Aleksander Morgado
2018-02-06 9:30 ` Sascha Hauer
2018-02-06 16:49 ` Aleksander Morgado
2018-02-07 8:34 ` Sascha Hauer
2018-02-02 11:14 ` [PATCH 07/10] ratp: implement ping as a standard ratp command Aleksander Morgado
2018-02-06 9:33 ` Sascha Hauer
2018-02-06 16:51 ` Aleksander Morgado
2018-02-07 8:26 ` Sascha Hauer
2018-02-02 11:14 ` [PATCH 08/10] ratp: implement getenv " Aleksander Morgado
2018-02-02 11:14 ` [PATCH 09/10] ratp: new reset command Aleksander Morgado
2018-02-02 11:14 ` [PATCH 10/10] ratp: new md and mw commands Aleksander Morgado
2018-02-06 9:24 ` [RFC PATCH 00/10] ratp: new generic RATP command support Sascha Hauer
2018-02-06 16:43 ` Aleksander Morgado
2018-02-07 8:33 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180202111442.12444-4-aleksander@aleksander.es \
--to=aleksander@aleksander.es \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox