diff --git a/client/wivrn_client.cpp b/client/wivrn_client.cpp index 376d7cb1..547561e0 100644 --- a/client/wivrn_client.cpp +++ b/client/wivrn_client.cpp @@ -19,6 +19,7 @@ #include "wivrn_client.h" #include "hardware.h" +#include "protocol_version.h" #include "secrets.h" #include "smp.h" #include "spdlog/common.h" @@ -99,6 +100,7 @@ void wivrn_session::handshake(T address, bool tcp_only, crypto::key & headset_ke }; send_control(from_headset::crypto_handshake{ + .protocol_version = wivrn::protocol_version, .public_key = headset_keypair.public_key(), .name = model_name(), }); @@ -178,6 +180,10 @@ void wivrn_session::handshake(T address, bool tcp_only, crypto::key & headset_ke case to_headset::crypto_handshake::crypto_state::pairing_disabled: spdlog::info("Pairing is disabled on server"); throw std::runtime_error(_("Pairing is disabled on server")); + + case to_headset::crypto_handshake::crypto_state::incompatible_version: + spdlog::error("Incompatible protocol versions"); + throw std::runtime_error(_("Incompatible server version")); } // may be on control socket if forced TCP diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 1d4cbcab..90dbb0fb 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -34,7 +34,6 @@ #include "smp.h" #include "wivrn_serialization_types.h" -#include "xr/pico_eye_types.h" namespace wivrn { @@ -42,7 +41,7 @@ namespace wivrn // Default port for server to listen, both TCP and UDP static const int default_port = 9757; -static constexpr int protocol_revision = 2; +static constexpr int protocol_revision = 0; enum class device_id : uint8_t { @@ -165,6 +164,7 @@ namespace from_headset { struct crypto_handshake { + uint64_t protocol_version; std::string public_key; // In PEM format std::string name; }; @@ -441,6 +441,7 @@ struct crypto_handshake pin_needed, client_already_paired, pairing_disabled, + incompatible_version, }; std::string public_key; // In PEM format diff --git a/server/driver/wivrn_connection.cpp b/server/driver/wivrn_connection.cpp index 1c09c6f1..76c4756a 100644 --- a/server/driver/wivrn_connection.cpp +++ b/server/driver/wivrn_connection.cpp @@ -19,6 +19,7 @@ #include "wivrn_connection.h" #include "configuration.h" +#include "protocol_version.h" #include "secrets.h" #include "smp.h" #include "wivrn_ipc.h" @@ -169,6 +170,14 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function(receive(10s).first); + if (crypto_handshake.protocol_version != wivrn::protocol_version) + { + control.send(to_headset::crypto_handshake{ + .state = to_headset::crypto_handshake::crypto_state::incompatible_version, + }); + throw std::runtime_error("Incompatible protocol version"); + } + crypto::key headset_key = crypto::key::from_public_key(crypto_handshake.public_key); bool is_public_key_known = std::ranges::any_of( wivrn::known_keys(),