2021-07-19 17:59:52 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
|
|
|
|
mod api;
|
2021-07-21 11:47:09 +00:00
|
|
|
use api::*;
|
|
|
|
|
use xous::{CID, msg_scalar_unpack, send_message, Message};
|
2021-07-19 17:59:52 +00:00
|
|
|
|
2021-07-21 11:47:09 +00:00
|
|
|
use num_traits::*;
|
2021-07-19 17:59:52 +00:00
|
|
|
|
|
|
|
|
#[cfg(target_os = "none")]
|
2021-07-21 11:47:09 +00:00
|
|
|
mod implementation;
|
|
|
|
|
#[cfg(target_os = "none")]
|
|
|
|
|
use implementation::*;
|
2021-07-19 17:59:52 +00:00
|
|
|
|
|
|
|
|
// a stub to try to avoid breaking hosted mode for as long as possible.
|
|
|
|
|
#[cfg(not(target_os = "none"))]
|
|
|
|
|
mod implementation {
|
2021-07-21 11:47:09 +00:00
|
|
|
pub struct RootKeys {
|
2021-07-19 17:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-21 11:47:09 +00:00
|
|
|
impl RootKeys {
|
|
|
|
|
pub fn new() -> RootKeys {
|
|
|
|
|
RootKeys {
|
2021-07-19 17:59:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn suspend(&self) {
|
|
|
|
|
}
|
|
|
|
|
pub fn resume(&self) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[xous::xous_main]
|
|
|
|
|
fn xmain() -> ! {
|
2021-07-21 11:47:09 +00:00
|
|
|
use crate::implementation::RootKeys;
|
2021-07-19 17:59:52 +00:00
|
|
|
|
|
|
|
|
log_server::init_wait().unwrap();
|
|
|
|
|
log::set_max_level(log::LevelFilter::Info);
|
2021-07-21 11:47:09 +00:00
|
|
|
log::info!("my PID is {}", xous::process::id());
|
2021-07-19 17:59:52 +00:00
|
|
|
|
|
|
|
|
let xns = xous_names::XousNames::new().unwrap();
|
|
|
|
|
/*
|
|
|
|
|
Connections allowed to the keys server:
|
|
|
|
|
1. Shellchat (to originate update test requests)
|
|
|
|
|
2. (future) PDDB
|
|
|
|
|
*/
|
|
|
|
|
let keys_sid = xns.register_name(api::SERVER_NAME_KEYS, Some(1)).expect("can't register server");
|
|
|
|
|
log::trace!("registered with NS -- {:?}", keys_sid);
|
|
|
|
|
|
2021-07-21 11:47:09 +00:00
|
|
|
let mut keys = RootKeys::new(&xns);
|
2021-07-19 17:59:52 +00:00
|
|
|
|
|
|
|
|
log::trace!("ready to accept requests");
|
|
|
|
|
|
|
|
|
|
// register a suspend/resume listener
|
|
|
|
|
let sr_cid = xous::connect(keys_sid).expect("couldn't create suspend callback connection");
|
|
|
|
|
let mut susres = susres::Susres::new(&xns, api::Opcode::SuspendResume as u32, sr_cid).expect("couldn't create suspend/resume object");
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
let msg = xous::receive_message(keys_sid).unwrap();
|
|
|
|
|
match FromPrimitive::from_usize(msg.body.id()) {
|
2021-07-21 11:47:09 +00:00
|
|
|
Some(Opcode::SuspendResume) => msg_scalar_unpack!(msg, token, _, _, _, {
|
2021-07-19 17:59:52 +00:00
|
|
|
keys.suspend();
|
|
|
|
|
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
|
|
|
|
keys.resume();
|
|
|
|
|
}),
|
2021-07-21 11:47:09 +00:00
|
|
|
Some(Opcode::TryInitKeys) => msg_scalar_unpack!(msg, _, _, _, _, {
|
|
|
|
|
keys.try_init_keys(None);
|
|
|
|
|
}),
|
|
|
|
|
Some(Opcode::TryInitKeysWithProgress) => msg_scalar_unpack!(msg, s0, s1, s2, s3, {
|
|
|
|
|
let sid = xous::SID::from_u32(s0 as u32, s1 as u32, s2 as u32, s3 as u32);
|
|
|
|
|
keys.try_init_keys(Some(sid));
|
|
|
|
|
}),
|
2021-07-21 19:04:16 +00:00
|
|
|
Some(Opcode::TestUx) => {
|
|
|
|
|
keys.test_ux();
|
|
|
|
|
},
|
2021-07-19 17:59:52 +00:00
|
|
|
None => {
|
|
|
|
|
log::error!("couldn't convert opcode");
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// clean up our program
|
|
|
|
|
log::trace!("main loop exit, destroying servers");
|
|
|
|
|
xns.unregister_server(keys_sid).unwrap();
|
|
|
|
|
xous::destroy_server(keys_sid).unwrap();
|
|
|
|
|
log::trace!("quitting");
|
|
|
|
|
xous::terminate_process(0)
|
|
|
|
|
}
|