From eb39277d4a5bababbd7169af2106b396125f1c65 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Fri, 23 Feb 2018 22:13:19 +1100 Subject: [PATCH] hwstub: allow minor version mismatch in net layer Change-Id: I81a75bd7b9f3fd1a56e5bea521966c1847adfec7 --- utils/hwstub/include/hwstub_net.hpp | 2 ++ utils/hwstub/lib/hwstub_net.cpp | 33 ++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/utils/hwstub/include/hwstub_net.hpp b/utils/hwstub/include/hwstub_net.hpp index 72d73e83e5..f6992b5348 100644 --- a/utils/hwstub/include/hwstub_net.hpp +++ b/utils/hwstub/include/hwstub_net.hpp @@ -112,6 +112,7 @@ protected: virtual void destroy_device_list(void *ptr); virtual error create_device(ctx_dev_t dev, std::shared_ptr& hwdev); virtual bool match_device(ctx_dev_t dev, std::shared_ptr hwdev); + static inline int hwstub_ver(int major, int minor) { return major * 100 + minor; } enum class state { @@ -122,6 +123,7 @@ protected: state m_state; /* client state */ error m_error; /* error state for DEAD */ + int m_ver; /* Server revision (uses hwstub_ver()) */ }; /** Socket based net context diff --git a/utils/hwstub/lib/hwstub_net.cpp b/utils/hwstub/lib/hwstub_net.cpp index 6f828f81ec..851723f37d 100644 --- a/utils/hwstub/lib/hwstub_net.cpp +++ b/utils/hwstub/lib/hwstub_net.cpp @@ -437,14 +437,25 @@ void context::delayed_init() return; } /* check the server is running the same version */ - debug() << "[net::ctx] <-- HELLO " << ((args[0] & 0xff00) >> 8) << "." << (args[0] & 0xff) << ""; - if(args[0] != (HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR)) + int serv_maj = (args[0] >> 8) & 0xff; + int serv_min = args[0] & 0xff; + debug() << "[net::ctx] <-- HELLO " << serv_maj << "." << serv_min << ""; + + m_ver = hwstub_ver(serv_maj, serv_min); + /* Major mismatch -> error */ + if(serv_maj != HWSTUB_VERSION_MAJOR) { - debug() << " (mismatch)\n"; + debug() << " (major version mismatch)\n"; m_state = state::DEAD; m_error = error::SERVER_MISMATCH; } - debug() << " (good)\n"; + else + debug() << " (good)\n"; + /* Minor mismatch -> warning */ + if(serv_min < HWSTUB_VERSION_MINOR) + debug() << "[net::ctx] Some operations might not be supported by the server.\n"; + else if(serv_min > HWSTUB_VERSION_MINOR) + debug() << "[net::ctx] Some operations might not be supported by this client.\n"; /* good, we can now send commands */ m_state = state::IDLE; } @@ -994,16 +1005,22 @@ error server::handle_cmd(client_state *state, uint32_t cmd, uint32_t args[HWSTUB /* HELLO */ if(cmd == HWSERVER_HELLO) { - debug() << "[net::srv::cmd] --> HELLO " << ((args[0] & 0xff00) >> 8) - << "." << (args[0] & 0xff); - if(args[0] != (HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR)) + int cli_maj = (args[0] >> 8) & 0xff; + int cli_min = args[0] & 0xff; + debug() << "[net::srv::cmd] --> HELLO " << cli_maj << "." << cli_min; + if(cli_maj != HWSTUB_VERSION_MAJOR) { - debug() << " (mismatch)\n"; + debug() << " (major version mismatch)\n"; return error::ERROR; } debug() << " (good)\n"; debug() << "[net::srv::cmd] <-- HELLO " << HWSTUB_VERSION_MAJOR << "." << HWSTUB_VERSION_MINOR << "\n"; + /* Minor mismatch -> warning */ + if(cli_min < HWSTUB_VERSION_MINOR) + debug() << "[net::ctx] Some operations might not be supported by the client.\n"; + else if(cli_min > HWSTUB_VERSION_MINOR) + debug() << "[net::ctx] Some operations might not be supported by this server.\n"; /* send HELLO with our version */ args[0] = HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR; return error::SUCCESS;