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::*;
|
2021-07-25 16:51:22 +00:00
|
|
|
use xous::{CID, msg_scalar_unpack, send_message, Message, msg_blocking_scalar_unpack};
|
|
|
|
|
use xous_ipc::{String, Buffer};
|
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
|
|
|
|
2021-07-25 16:51:22 +00:00
|
|
|
use gam::modal::*;
|
|
|
|
|
|
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-25 16:51:22 +00:00
|
|
|
use crate::ROOTKEY_MODAL_NAME;
|
|
|
|
|
use gam::modal::*;
|
|
|
|
|
use xous_ipc::String;
|
|
|
|
|
|
2021-07-21 11:47:09 +00:00
|
|
|
pub struct RootKeys {
|
2021-07-25 16:51:22 +00:00
|
|
|
gam: gam::Gam,
|
|
|
|
|
ticktimer: ticktimer_server::Ticktimer,
|
2021-07-19 17:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-21 11:47:09 +00:00
|
|
|
impl RootKeys {
|
2021-07-25 16:51:22 +00:00
|
|
|
pub fn new(xns: &xous_names::XousNames) -> RootKeys {
|
2021-07-21 11:47:09 +00:00
|
|
|
RootKeys {
|
2021-07-25 16:51:22 +00:00
|
|
|
gam: gam::Gam::new(&xns).expect("couldn't allocate GAM for testing"),
|
|
|
|
|
ticktimer: ticktimer_server::Ticktimer::new().expect("couldn't get ticktimer"),
|
2021-07-19 17:59:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn suspend(&self) {
|
|
|
|
|
}
|
|
|
|
|
pub fn resume(&self) {
|
|
|
|
|
}
|
2021-07-25 16:51:22 +00:00
|
|
|
|
|
|
|
|
pub fn try_init_keys(&mut self, _maybe_progress: Option<xous::SID>) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn test_ux(&mut self, arg: usize) {
|
|
|
|
|
match arg {
|
|
|
|
|
0 => self.gam.raise_modal(ROOTKEY_MODAL_NAME).expect("couldn't raise modal"),
|
|
|
|
|
1 => self.gam.relinquish_focus().expect("couldn't hide modal"),
|
|
|
|
|
_ => log::info!("test_ux got unrecognized arg: {}", arg),
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-07-19 17:59:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 16:51:22 +00:00
|
|
|
pub(crate) fn rootkeys_ux_thread() {
|
|
|
|
|
let password_action = gam::modal::TextEntry {
|
|
|
|
|
is_password: true,
|
|
|
|
|
visibility: gam::modal::TextEntryVisibility::LastChars,
|
|
|
|
|
action_conn: 0, //place holder
|
|
|
|
|
action_opcode: 0, // placeholder
|
|
|
|
|
action_payload: None, //placeholder
|
|
|
|
|
};
|
|
|
|
|
let mut modal = gam::Modal::new(crate::ROOTKEY_MODAL_NAME, gam::ActionType::TextEntry(password_action), None, None);
|
|
|
|
|
log::trace!("ux thread modal: {:?}", modal);
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
let msg = xous::receive_message(modal.sid).unwrap();
|
|
|
|
|
log::trace!("ux message: {:?}", msg);
|
|
|
|
|
match FromPrimitive::from_usize(msg.body.id()) {
|
|
|
|
|
Some(ModalOpcode::Redraw) => {
|
|
|
|
|
modal.redraw();
|
|
|
|
|
},
|
|
|
|
|
Some(ModalOpcode::Rawkeys) => msg_scalar_unpack!(msg, k1, k2, k3, k4, {
|
|
|
|
|
let keys = [
|
|
|
|
|
if let Some(a) = core::char::from_u32(k1 as u32) {
|
|
|
|
|
a
|
|
|
|
|
} else {
|
|
|
|
|
'\u{0000}'
|
|
|
|
|
},
|
|
|
|
|
if let Some(a) = core::char::from_u32(k2 as u32) {
|
|
|
|
|
a
|
|
|
|
|
} else {
|
|
|
|
|
'\u{0000}'
|
|
|
|
|
},
|
|
|
|
|
if let Some(a) = core::char::from_u32(k3 as u32) {
|
|
|
|
|
a
|
|
|
|
|
} else {
|
|
|
|
|
'\u{0000}'
|
|
|
|
|
},
|
|
|
|
|
if let Some(a) = core::char::from_u32(k4 as u32) {
|
|
|
|
|
a
|
|
|
|
|
} else {
|
|
|
|
|
'\u{0000}'
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
modal.key_event(keys);
|
|
|
|
|
}),
|
|
|
|
|
Some(ModalOpcode::Quit) => {
|
|
|
|
|
break;
|
|
|
|
|
},
|
|
|
|
|
None => {
|
|
|
|
|
log::error!("unknown opcode {:?}", msg.body.id());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log::trace!("password modal thread exit, destroying servers");
|
|
|
|
|
// do we want to add a deregister_ux call to the system?
|
|
|
|
|
xous::destroy_server(modal.sid).unwrap();
|
|
|
|
|
}
|
2021-07-19 17:59:52 +00:00
|
|
|
|
|
|
|
|
#[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();
|
2021-07-25 16:51:22 +00:00
|
|
|
log::set_max_level(log::LevelFilter::Trace);
|
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");
|
|
|
|
|
|
2021-07-25 16:51:22 +00:00
|
|
|
xous::create_thread_0(rootkeys_ux_thread).expect("couldn't start rootkeys UX thread");
|
|
|
|
|
|
2021-07-19 17:59:52 +00:00
|
|
|
loop {
|
|
|
|
|
let msg = xous::receive_message(keys_sid).unwrap();
|
2021-07-25 16:51:22 +00:00
|
|
|
log::trace!("message: {:?}", msg);
|
2021-07-19 17:59:52 +00:00
|
|
|
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-25 16:51:22 +00:00
|
|
|
Some(Opcode::TestUx) => msg_blocking_scalar_unpack!(msg, arg, _, _, _, {
|
|
|
|
|
keys.test_ux(arg);
|
|
|
|
|
xous::return_scalar(msg.sender, 0).expect("couldn't unblock sender");
|
|
|
|
|
}),
|
|
|
|
|
Some(Opcode::Quit) => {
|
|
|
|
|
log::warn!("password thread received quit, exiting.");
|
|
|
|
|
break
|
|
|
|
|
}
|
2021-07-19 17:59:52 +00:00
|
|
|
None => {
|
|
|
|
|
log::error!("couldn't convert opcode");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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)
|
|
|
|
|
}
|