hwstub: allow minor version mismatch in net layer

Change-Id: I81a75bd7b9f3fd1a56e5bea521966c1847adfec7
This commit is contained in:
Amaury Pouly 2018-02-23 22:13:19 +11:00
parent 966c1d7650
commit eb39277d4a
2 changed files with 27 additions and 8 deletions

View file

@ -112,6 +112,7 @@ protected:
virtual void destroy_device_list(void *ptr); virtual void destroy_device_list(void *ptr);
virtual error create_device(ctx_dev_t dev, std::shared_ptr<hwstub::device>& hwdev); virtual error create_device(ctx_dev_t dev, std::shared_ptr<hwstub::device>& hwdev);
virtual bool match_device(ctx_dev_t dev, std::shared_ptr<hwstub::device> hwdev); virtual bool match_device(ctx_dev_t dev, std::shared_ptr<hwstub::device> hwdev);
static inline int hwstub_ver(int major, int minor) { return major * 100 + minor; }
enum class state enum class state
{ {
@ -122,6 +123,7 @@ protected:
state m_state; /* client state */ state m_state; /* client state */
error m_error; /* error state for DEAD */ error m_error; /* error state for DEAD */
int m_ver; /* Server revision (uses hwstub_ver()) */
}; };
/** Socket based net context /** Socket based net context

View file

@ -437,14 +437,25 @@ void context::delayed_init()
return; return;
} }
/* check the server is running the same version */ /* check the server is running the same version */
debug() << "[net::ctx] <-- HELLO " << ((args[0] & 0xff00) >> 8) << "." << (args[0] & 0xff) << ""; int serv_maj = (args[0] >> 8) & 0xff;
if(args[0] != (HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR)) 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_state = state::DEAD;
m_error = error::SERVER_MISMATCH; 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 */ /* good, we can now send commands */
m_state = state::IDLE; m_state = state::IDLE;
} }
@ -994,16 +1005,22 @@ error server::handle_cmd(client_state *state, uint32_t cmd, uint32_t args[HWSTUB
/* HELLO */ /* HELLO */
if(cmd == HWSERVER_HELLO) if(cmd == HWSERVER_HELLO)
{ {
debug() << "[net::srv::cmd] --> HELLO " << ((args[0] & 0xff00) >> 8) int cli_maj = (args[0] >> 8) & 0xff;
<< "." << (args[0] & 0xff); int cli_min = args[0] & 0xff;
if(args[0] != (HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR)) 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; return error::ERROR;
} }
debug() << " (good)\n"; debug() << " (good)\n";
debug() << "[net::srv::cmd] <-- HELLO " << HWSTUB_VERSION_MAJOR << "." debug() << "[net::srv::cmd] <-- HELLO " << HWSTUB_VERSION_MAJOR << "."
<< HWSTUB_VERSION_MINOR << "\n"; << 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 */ /* send HELLO with our version */
args[0] = HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR; args[0] = HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR;
return error::SUCCESS; return error::SUCCESS;