diff --git a/Cargo.lock b/Cargo.lock index 826c376f1..34e9ef1a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1691,6 +1691,8 @@ dependencies = [ "heapless", "log", "log-server", + "num-derive", + "num-traits", "rkyv 0.4.3", "ticktimer-server", "utralib", diff --git a/services/xous-names/Cargo.toml b/services/xous-names/Cargo.toml index 8eec3e31d..9956de31b 100644 --- a/services/xous-names/Cargo.toml +++ b/services/xous-names/Cargo.toml @@ -9,6 +9,8 @@ version = "0.1.0" hash32 = "0.1.0" hash32-derive = "0.1.0" heapless = "0.5" +num-derive = {version = "0.3", default-features = false} +num-traits = {version = "0.2", default-features = false} log = "0.4" log-server = {path = "../log-server"} ticktimer-server = {path = "../ticktimer-server"} diff --git a/services/xous-names/src/api.rs b/services/xous-names/src/api.rs index 909c8be09..884bbe2d2 100644 --- a/services/xous-names/src/api.rs +++ b/services/xous-names/src/api.rs @@ -1,16 +1,33 @@ -#![allow(dead_code)] - -use xous::CID; use hash32::{Hash, Hasher}; -// bottom 16 bits are reserved for structure re-use by other servers -pub const ID_REGISTER_NAME: u32 = 0x1_0000; -pub const ID_LOOKUP_NAME: u32 = 0x2_0000; -pub const ID_AUTHENTICATE: u32 = 0x3_0000; - pub const AUTHENTICATE_TIMEOUT: u32 = 10_000; // time in ms that a process has to respond to an authentication request -#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Debug)] +#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)] +pub(crate) enum Request { + /// Create a new server with the given name and return its SID. + Register, + + /// Create a connection to the target server. + Lookup, + + /// Create an authenticated connection to the target server. + AuthenticatedLookup, + + // Return values + + /// The caller must perform an AuthenticatedLookup using this challenge + AuthenticateRequest, + + /// The connection failed for some reason + Failure, + + /// A server was successfully created with the given SID + SID, + + /// A connection was successfully made with the given CID + CID, +} +/* pub(crate) enum Request { /// Create a new server with the given name and return its SID. Register(xous_ipc::String::<64>), @@ -24,7 +41,7 @@ pub(crate) enum Request { // Return values /// The caller must perform an AuthenticatedLookup using this challenge - AuthenticateRequest([u32; 8]), + AuthenticateRequest(AuthenticatedRequest), /// The connection failed for some reason Failure, @@ -34,12 +51,7 @@ pub(crate) enum Request { /// A connection was successfully made with the given CID CID(CID), -} - -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] -pub(crate) struct Lookup { - pub name: xous_ipc::String::<64>, -} +}*/ #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub(crate) struct AuthenticatedLookup { @@ -48,21 +60,18 @@ pub(crate) struct AuthenticatedLookup { pub challenge: [u32; 8], } -#[derive(Debug)] -pub struct Authenticate { - pub name: xous_ipc::String::<64>, - pub success: bool, - pub response_to_challenge: [u32; 8], +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub(crate) struct AuthenticatedRequest { + pub request: AuthenicatedLookup, // a copy of the original request. We don't trust it, but it's helpful to have for reference + pub nonce: [u32; 4], + pub response: [u32; 8], } -impl Authenticate { - pub fn mid(&self) -> u32 { - ID_AUTHENTICATE as u32 - } -} +////////////////////////////////////////////////////////////////////////////////////////////// // We keep XousServerName around because want to be able to index off the server name, without // burdening the Kernel String type with the Hash32 methods +////////////////////////////////////////////////////////////////////////////////////////////// // --------------------- Taken from rkyv docs https://docs.rs/rkyv/0.3.0/rkyv/trait.Archive.html // #[derive(Debug, Copy, Clone)] diff --git a/services/xous-names/src/lib.rs b/services/xous-names/src/lib.rs index af5a602b5..a7c4a8f1e 100644 --- a/services/xous-names/src/lib.rs +++ b/services/xous-names/src/lib.rs @@ -4,6 +4,21 @@ pub mod api; use core::fmt::Write; +pub struct XousNames { + conn: xous::CID, +} +impl XousNames { + pub fn new() -> Result { + let conn = xous::connect(xous::SID::from_bytes(b"xous-name-server").unwrap()).expect("Couldn't connect to XousNames"); + Ok(XousNames { + conn, + }) + } + pub fn register_name(&self, name: &str) -> Result { + + } +} + pub fn register_name(name: &str) -> Result { // Ensure we have a connection to the nameserver. If one exists, this is a no-op. let ns_id = xous::SID::from_bytes(b"xous-name-server").unwrap();