mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Merge branch 'libstd-fs'
This commit is contained in:
commit
13b6669445
6 changed files with 201 additions and 190 deletions
|
|
@ -431,7 +431,7 @@ impl SystemServices {
|
|||
entry.state = ProcessState::Ready(1 << INITIAL_TID);
|
||||
}
|
||||
// entry.ppid = _ppid;
|
||||
klog!("created new process for PID {} with PPID {}", new_pid, ppid);
|
||||
klog!("created new process for PID {} with PPID {}", new_pid, _ppid);
|
||||
return Ok(startup);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,93 +113,93 @@ pub struct UxRegistration {
|
|||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum Opcode {
|
||||
// clears a canvas with a given GID
|
||||
ClearCanvas, //(Gid),
|
||||
ClearCanvas = 0, //(Gid),
|
||||
|
||||
// return the dimensions of a canvas as a Point (the top left is always (0,0))
|
||||
GetCanvasBounds, //(Gid),
|
||||
GetCanvasBounds = 1, //(Gid),
|
||||
|
||||
// request a new size for my canvas.
|
||||
// This normally will be denied, unless the requested Gid corresponds to a special canvas that allows resizing.
|
||||
SetCanvasBounds, //(SetCanvasBoundsRequest),
|
||||
SetCanvasBounds = 2, //(SetCanvasBoundsRequest),
|
||||
|
||||
// draws an object
|
||||
RenderObject, //(GamObject),
|
||||
RenderObjectList,
|
||||
RenderObject = 3, //(GamObject),
|
||||
RenderObjectList = 4,
|
||||
// draws a tile. this is *not* part of the ObjectList because then every vector object suddenly also carries
|
||||
// the allocation burden of a bitmap tile.
|
||||
#[cfg(feature="ditherpunk")]
|
||||
RenderTile,
|
||||
RenderTile = 5,
|
||||
|
||||
// renders a TextView
|
||||
RenderTextView, //(TextView),
|
||||
RenderTextView = 6, //(TextView),
|
||||
|
||||
// forces a redraw (which also does defacement, etc.)
|
||||
Redraw,
|
||||
Redraw = 7,
|
||||
|
||||
// returns a GID to the "content" Canvas of the token holder
|
||||
RequestContentCanvas,
|
||||
RequestContentCanvas = 8,
|
||||
|
||||
// registers a Ux of a requested type
|
||||
// takes in the LayoutType, default PredictorType, a SID for UxEvents, a human-readable identifier token; returns a content canvas GID
|
||||
// also takes a bunch of optional ID codes for the various callbacks
|
||||
// internally assigns a trust level, based on a first-come first-serve basis for known services, and then a much lower trust for rando ones
|
||||
RegisterUx,
|
||||
RegisterUx = 9,
|
||||
|
||||
// updates the audio connection ID post-registration
|
||||
SetAudioOpcode,
|
||||
SetAudioOpcode = 10,
|
||||
|
||||
// Requests setting the UI to the power down screen
|
||||
PowerDownRequest,
|
||||
PowerDownRequest = 11,
|
||||
|
||||
// Request blank screen for ship mode
|
||||
ShipModeBlankRequest,
|
||||
ShipModeBlankRequest = 12,
|
||||
|
||||
// used to claim a GAM registration token (should be used only by status.rs)
|
||||
ClaimToken,
|
||||
ClaimToken = 13,
|
||||
// used to set a predictor API token (should be used only by ime-frontend)
|
||||
PredictorApiToken,
|
||||
PredictorApiToken = 14,
|
||||
|
||||
/// system-level API that can be called by the Xous process launcher to check if we're at a state where less trusted code could be run
|
||||
/// it basically checks that all tokens have been claimed by trusted OS procesess, thus blocking any further token creation
|
||||
TrustedInitDone,
|
||||
TrustedInitDone = 15,
|
||||
|
||||
/// this is used internally to route input lines from the IMEF
|
||||
InputLine,
|
||||
InputLine = 16,
|
||||
|
||||
/// passed to the keyboard server to notify me of a keyboard event
|
||||
KeyboardEvent,
|
||||
KeyboardEvent = 17,
|
||||
|
||||
/// used to turn keyboard vibrate on and off
|
||||
Vibe,
|
||||
Vibe = 18,
|
||||
/// used to toggle menu mode behavior for the prediction area (default: false)
|
||||
ToggleMenuMode,
|
||||
ToggleMenuMode = 19,
|
||||
|
||||
/// called by a context when it's done with taking the screen; requests the GAM to revert focus to the last-focused app
|
||||
RevertFocus,
|
||||
RevertFocusNb, // non-blocking version
|
||||
RevertFocus = 20,
|
||||
RevertFocusNb = 21, // non-blocking version
|
||||
|
||||
/// pass-through to get glyph heights to assist with layout planning, without having to create a gfx connection
|
||||
QueryGlyphProps,
|
||||
QueryGlyphProps = 22,
|
||||
|
||||
/// request redraw of IME area
|
||||
RedrawIme,
|
||||
RedrawIme = 23,
|
||||
|
||||
/// switch focus to an app
|
||||
SwitchToApp,
|
||||
SwitchToApp = 24,
|
||||
|
||||
/// raise a context menu
|
||||
RaiseMenu,
|
||||
RaiseMenu = 25,
|
||||
|
||||
/// Turn on Devboot Flag
|
||||
Devboot,
|
||||
Devboot = 26,
|
||||
|
||||
/// Show a test pattern. Can only call this once (to prevent abuse)
|
||||
TestPattern,
|
||||
TestPattern = 27,
|
||||
|
||||
/// Toggle debug on serial console
|
||||
SetDebugLevel,
|
||||
SetDebugLevel = 28,
|
||||
|
||||
Quit,
|
||||
Quit = 29,
|
||||
}
|
||||
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
|
|
|
|||
|
|
@ -77,43 +77,43 @@ pub struct DynamicNotification {
|
|||
pub(crate) enum Opcode {
|
||||
// these are blocking calls
|
||||
/// ask a question, get a single response from a list of defined items (radio box)
|
||||
PromptWithFixedResponse,
|
||||
PromptWithFixedResponse = 0,
|
||||
/// ask a question, get multiple responses from a list of defined items (check box)
|
||||
PromptWithMultiResponse,
|
||||
PromptWithMultiResponse = 1,
|
||||
/// simple notification
|
||||
Notification,
|
||||
Notification = 2,
|
||||
/// display an image
|
||||
#[cfg(feature = "ditherpunk")]
|
||||
Image,
|
||||
Image = 3,
|
||||
/// dynamic notification - a simple non-interactive notification that allows its text to be dynamically updated
|
||||
DynamicNotification,
|
||||
DynamicNotification = 4,
|
||||
/// listen to dynamic notification - a blocking call, meant to be called from a separate thread from the control loop
|
||||
ListenToDynamicNotification,
|
||||
ListenToDynamicNotification = 5,
|
||||
|
||||
/// ask a question, get a free-form answer back
|
||||
PromptWithTextResponse,
|
||||
PromptWithTextResponse = 6,
|
||||
/// must be used by the PromptWithTextResponse caller to acknowledge correct input
|
||||
TextResponseValid,
|
||||
TextResponseValid = 7,
|
||||
|
||||
// these are non-blocking calls
|
||||
/// add an item to the radio box or check box. Note that all added items
|
||||
/// are cleared after the relevant "action" call happens (PromptWith[Fixed,Multi]Response)
|
||||
AddModalItem,
|
||||
AddModalItem = 8,
|
||||
/// get the index of the selected radio button / checkboxes
|
||||
GetModalIndex,
|
||||
GetModalIndex = 9,
|
||||
/// raise a progress bar
|
||||
StartProgress,
|
||||
StartProgress = 10,
|
||||
/// update the progress bar
|
||||
DoUpdateProgress,
|
||||
DoUpdateProgress = 11,
|
||||
/// lower a progress bar
|
||||
StopProgress,
|
||||
StopProgress = 12,
|
||||
/// update a dynamic notification's text
|
||||
UpdateDynamicNotification,
|
||||
UpdateDynamicNotification = 13,
|
||||
/// close dynamic notification
|
||||
CloseDynamicNotification,
|
||||
CloseDynamicNotification = 14,
|
||||
|
||||
/// used by libraries to get the mutex on the server
|
||||
GetMutex,
|
||||
GetMutex = 15,
|
||||
|
||||
// these are used internally by the modals to handle intermediate state. Do not call from the outside.
|
||||
// these were originally handled in a separate thread for deferred responses using busy-waits. They are
|
||||
|
|
@ -121,24 +121,24 @@ pub(crate) enum Opcode {
|
|||
// it does expose some of the internal API mechanics to outside processes. This is fine for the modals
|
||||
// box because it's a convenience routine used by "everyone"; password boxes are always handled within
|
||||
// a given secured server so that the attack surface for these do not extend into the modals boundary.
|
||||
InitiateOp,
|
||||
FinishProgress,
|
||||
InitiateOp = 16,
|
||||
FinishProgress = 17,
|
||||
|
||||
TextEntryReturn,
|
||||
RadioReturn,
|
||||
CheckBoxReturn,
|
||||
NotificationReturn,
|
||||
TextEntryReturn = 18,
|
||||
RadioReturn = 19,
|
||||
CheckBoxReturn = 20,
|
||||
NotificationReturn = 21,
|
||||
#[cfg(feature = "ditherpunk")]
|
||||
ImageReturn,
|
||||
ImageReturn = 22,
|
||||
|
||||
DoUpdateDynamicNotification,
|
||||
DoCloseDynamicNotification,
|
||||
HandleDynamicNotificationKeyhit,
|
||||
DoUpdateDynamicNotification = 23,
|
||||
DoCloseDynamicNotification = 24,
|
||||
HandleDynamicNotificationKeyhit = 25,
|
||||
|
||||
ModalRedraw,
|
||||
ModalKeypress,
|
||||
ModalDrop,
|
||||
Gutter,
|
||||
ModalRedraw = 26,
|
||||
ModalKeypress = 27,
|
||||
ModalDrop = 28,
|
||||
Gutter = 29,
|
||||
|
||||
Quit,
|
||||
Quit = 30,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,82 +85,88 @@ pub(crate) const BCRYPT_COST: u32 = 7; // 10 is the minimum recommended by OWA
|
|||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Opcode {
|
||||
IsMounted,
|
||||
TryMount,
|
||||
IsMounted = 0,
|
||||
TryMount = 1,
|
||||
|
||||
ListBasis,
|
||||
LatestBasis,
|
||||
ListBasis = 2,
|
||||
LatestBasis = 3,
|
||||
/// Note that creating a basis does not automatically open it!
|
||||
CreateBasis,
|
||||
OpenBasis,
|
||||
CloseBasis,
|
||||
CreateBasis = 4,
|
||||
OpenBasis = 5,
|
||||
CloseBasis = 6,
|
||||
/// warning, the Delete routines have not been well tested
|
||||
DeleteBasis,
|
||||
DeleteKey,
|
||||
DeleteDict,
|
||||
KeyAttributes,
|
||||
DeleteBasis = 7,
|
||||
DeleteKey = 8,
|
||||
DeleteDict = 9,
|
||||
KeyAttributes = 10,
|
||||
|
||||
// routines to list available resources
|
||||
KeyCountInDict,
|
||||
GetKeyNameAtIndex,
|
||||
DictCountInBasis,
|
||||
GetDictNameAtIndex,
|
||||
KeyCountInDict = 11,
|
||||
GetKeyNameAtIndex = 12,
|
||||
DictCountInBasis = 13,
|
||||
GetDictNameAtIndex = 14,
|
||||
|
||||
/// primary method for accessing the database
|
||||
KeyRequest,
|
||||
KeyRequest = 15,
|
||||
|
||||
// pddbkey methods
|
||||
ReadKey,
|
||||
WriteKey,
|
||||
WriteKeyFlush,
|
||||
ReadKey = 16,
|
||||
WriteKey = 17,
|
||||
WriteKeyFlush = 18,
|
||||
|
||||
// GC methods
|
||||
PeriodicScrub,
|
||||
PeriodicScrub = 19,
|
||||
|
||||
/// drops any connection state associated with a given key
|
||||
KeyDrop,
|
||||
KeyDrop = 20,
|
||||
|
||||
/// Menu opcodes
|
||||
MenuListBasis,
|
||||
MenuListBasis = 21,
|
||||
|
||||
/// Security state checks
|
||||
IsEfuseSecured,
|
||||
IsEfuseSecured = 22,
|
||||
|
||||
/// Suspend/resume callback
|
||||
SuspendResume,
|
||||
SuspendResume = 23,
|
||||
/// quit the server
|
||||
Quit,
|
||||
Quit = 24,
|
||||
/// Write debug dump (only available in hosted mode)
|
||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
DangerousDebug,
|
||||
DangerousDebug = 25,
|
||||
|
||||
/// This key type could not be decoded
|
||||
InvalidOpcode = u32::MAX as _,
|
||||
}
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum PollOp {
|
||||
Poll,
|
||||
Quit,
|
||||
Poll = 0,
|
||||
Quit = 1,
|
||||
}
|
||||
|
||||
pub type ApiToken = [u32; 3];
|
||||
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
#[repr(C)]
|
||||
pub struct PddbBasisList {
|
||||
/// the first 63 that fit in the list -- generally we anticipate not more than a few being open at a time, so this should be enough.
|
||||
pub list: [xous_ipc::String::<BASIS_NAME_LEN>; 63],
|
||||
/// total number of basis open. Should be <= 63, but we allow it to be larger to indicate cases where this structure wasn't big enough.
|
||||
pub num: u32,
|
||||
}
|
||||
|
||||
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub enum PddbRequestCode {
|
||||
Create,
|
||||
Open,
|
||||
Close,
|
||||
Delete,
|
||||
NoErr,
|
||||
NotMounted,
|
||||
NoFreeSpace,
|
||||
NotFound,
|
||||
InternalError,
|
||||
AccessDenied,
|
||||
Uninit,
|
||||
Create = 0,
|
||||
Open = 1,
|
||||
Close = 2,
|
||||
Delete = 3,
|
||||
NoErr = 4,
|
||||
NotMounted = 5,
|
||||
NoFreeSpace = 6,
|
||||
NotFound = 7,
|
||||
InternalError = 8,
|
||||
AccessDenied = 9,
|
||||
Uninit = 10,
|
||||
}
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
|
|
@ -222,26 +228,31 @@ pub(crate) enum PddbRetcode {
|
|||
InternalError = 5,
|
||||
DiskFull = 6,
|
||||
}
|
||||
|
||||
/// PddbBuf is a C-representation of a page of memory that's used
|
||||
/// to shuttle data for streaming channels. It must be exactly one
|
||||
/// page in size, with some overhead specific to the PDDB book-keeping
|
||||
/// at the top, and the remainder available for shuttling data.
|
||||
///
|
||||
/// It does not use rkyv, as the blanket implementation of that tends to
|
||||
/// incur too many extra copies an/or zeroing operations.
|
||||
#[repr(C, packed)]
|
||||
#[repr(C, align(4096))]
|
||||
pub(crate) struct PddbBuf {
|
||||
/// api token for the given buffer
|
||||
pub(crate) token: ApiToken,
|
||||
/// point in the key stream. 64-bit for future-compatibility; but, can't be larger than 32 bits on a 32-bit target.
|
||||
pub(crate) position: u64,
|
||||
/// length of the data field
|
||||
pub(crate) len: u16,
|
||||
/// a field reserved for the return code
|
||||
pub(crate) retcode: PddbRetcode,
|
||||
pub(crate) reserved: u8,
|
||||
reserved: u8,
|
||||
/// length of the data field
|
||||
pub(crate) len: u16,
|
||||
/// point in the key stream. 64-bit for future-compatibility; but, can't be larger than 32 bits on a 32-bit target.
|
||||
pub(crate) position: u64,
|
||||
pub(crate) data: [u8; 4072],
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Ensure that the `PddbBuf` struct is exactly one page big
|
||||
const fn _assert_pddbbuf_is_4096_bytes() {
|
||||
unsafe { core::mem::transmute::<_, PddbBuf>([0u8; 4096]); }
|
||||
}
|
||||
|
||||
impl PddbBuf {
|
||||
pub(crate) fn from_slice_mut(slice: &mut [u8]) -> &mut PddbBuf {
|
||||
// this transforms the slice [u8] into a PddbBuf ref.
|
||||
|
|
@ -342,8 +353,8 @@ pub struct PddbDangerousDebug {
|
|||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub enum DebugRequest {
|
||||
Dump,
|
||||
Remount,
|
||||
Dump = 0,
|
||||
Remount = 1,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -551,26 +551,26 @@ fn main() -> ! {
|
|||
Opcode::SuspendResume as u32, my_cid).expect("couldn't create suspend/resume object");
|
||||
loop {
|
||||
let mut msg = xous::receive_message(pddb_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
|
||||
match FromPrimitive::from_usize(msg.body.id()).unwrap_or(Opcode::InvalidOpcode) {
|
||||
Opcode::SuspendResume => xous::msg_scalar_unpack!(msg, token, _, _, _, {
|
||||
basis_cache.suspend(&mut pddb_os);
|
||||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
||||
}),
|
||||
Some(Opcode::IsEfuseSecured) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
Opcode::IsEfuseSecured => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
if pddb_os.is_efuse_secured() {
|
||||
xous::return_scalar(msg.sender, 1).unwrap();
|
||||
} else {
|
||||
xous::return_scalar(msg.sender, 0).unwrap();
|
||||
}
|
||||
}),
|
||||
Some(Opcode::IsMounted) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
Opcode::IsMounted => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
if basis_cache.basis_count() > 0 { // if there's anything in the cache, we're mounted.
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||
} else {
|
||||
mount_notifications.push(msg.sender); // defer response until later
|
||||
}
|
||||
}),
|
||||
Some(Opcode::TryMount) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
Opcode::TryMount => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
if basis_cache.basis_count() > 0 {
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||
} else {
|
||||
|
|
@ -617,7 +617,7 @@ fn main() -> ! {
|
|||
}
|
||||
}
|
||||
}),
|
||||
Some(Opcode::PeriodicScrub) => {
|
||||
Opcode::PeriodicScrub => {
|
||||
let current_heap = heap_usage();
|
||||
let current_cache = basis_cache.cache_size();
|
||||
if current_heap != latest_heap || current_cache != latest_cache {
|
||||
|
|
@ -661,7 +661,7 @@ fn main() -> ! {
|
|||
heap_increased = true;
|
||||
}
|
||||
}
|
||||
Some(Opcode::ListBasis) => {
|
||||
Opcode::ListBasis => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut list_ipc = buffer.to_original::<PddbBasisList, _>().unwrap();
|
||||
let basis_list = basis_cache.basis_list();
|
||||
|
|
@ -672,7 +672,7 @@ fn main() -> ! {
|
|||
list_ipc.num = basis_list.len() as u32;
|
||||
buffer.replace(list_ipc).unwrap();
|
||||
}
|
||||
Some(Opcode::LatestBasis) => {
|
||||
Opcode::LatestBasis => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut mgmt = buffer.to_original::<PddbBasisRequest, _>().unwrap();
|
||||
if let Some(name) = basis_cache.basis_latest() {
|
||||
|
|
@ -684,7 +684,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(mgmt).unwrap();
|
||||
}
|
||||
Some(Opcode::CreateBasis) => {
|
||||
Opcode::CreateBasis => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut mgmt = buffer.to_original::<PddbBasisRequest, _>().unwrap();
|
||||
match mgmt.code {
|
||||
|
|
@ -711,7 +711,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(mgmt).unwrap();
|
||||
}
|
||||
Some(Opcode::OpenBasis) => {
|
||||
Opcode::OpenBasis => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut mgmt = buffer.to_original::<PddbBasisRequest, _>().unwrap();
|
||||
match mgmt.code {
|
||||
|
|
@ -764,7 +764,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(mgmt).unwrap();
|
||||
}
|
||||
Some(Opcode::CloseBasis) => {
|
||||
Opcode::CloseBasis => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut mgmt = buffer.to_original::<PddbBasisRequest, _>().unwrap();
|
||||
notify_of_disconnect(&mut pddb_os, &token_dict, &mut basis_cache);
|
||||
|
|
@ -784,7 +784,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(mgmt).unwrap();
|
||||
}
|
||||
Some(Opcode::DeleteBasis) => {
|
||||
Opcode::DeleteBasis => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut mgmt = buffer.to_original::<PddbBasisRequest, _>().unwrap();
|
||||
notify_of_disconnect(&mut pddb_os, &token_dict, &mut basis_cache);
|
||||
|
|
@ -804,7 +804,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(mgmt).unwrap();
|
||||
}
|
||||
Some(Opcode::KeyRequest) => {
|
||||
Opcode::KeyRequest => {
|
||||
for basis in basis_cache.access_list().iter() {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req: PddbKeyRequest = buffer.to_original::<PddbKeyRequest, _>().unwrap();
|
||||
|
|
@ -878,7 +878,7 @@ fn main() -> ! {
|
|||
break; // if we got here, entry was found, stop searching
|
||||
}
|
||||
}
|
||||
Some(Opcode::KeyDrop) => msg_blocking_scalar_unpack!(msg, t0, t1, t2, _, {
|
||||
Opcode::KeyDrop => msg_blocking_scalar_unpack!(msg, t0, t1, t2, _, {
|
||||
let token: ApiToken = [t0 as u32, t1 as u32, t2 as u32];
|
||||
if let Some(rec) = token_dict.remove(&token) {
|
||||
// now check if we can safely disconnect and recycle our connection number.
|
||||
|
|
@ -904,7 +904,7 @@ fn main() -> ! {
|
|||
}
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't ack KeyDrop");
|
||||
}),
|
||||
Some(Opcode::DeleteKey) => {
|
||||
Opcode::DeleteKey => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req: PddbKeyRequest = buffer.to_original::<PddbKeyRequest, _>().unwrap();
|
||||
let bname = if req.basis_specified {
|
||||
|
|
@ -954,7 +954,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(req).unwrap();
|
||||
}
|
||||
Some(Opcode::DeleteDict) => {
|
||||
Opcode::DeleteDict => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req: PddbKeyRequest = buffer.to_original::<PddbKeyRequest, _>().unwrap();
|
||||
let bname = if req.basis_specified {
|
||||
|
|
@ -1004,7 +1004,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(req).unwrap();
|
||||
}
|
||||
Some(Opcode::KeyAttributes) => {
|
||||
Opcode::KeyAttributes => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req = buffer.to_original::<PddbKeyAttrIpc, _>().unwrap();
|
||||
if let Some(token_record) = token_dict.get(&req.token) {
|
||||
|
|
@ -1024,7 +1024,7 @@ fn main() -> ! {
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(Opcode::KeyCountInDict) => {
|
||||
Opcode::KeyCountInDict => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req = buffer.to_original::<PddbDictRequest, _>().unwrap();
|
||||
if key_token.is_some() {
|
||||
|
|
@ -1070,7 +1070,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(req).unwrap();
|
||||
}
|
||||
Some(Opcode::GetKeyNameAtIndex) => {
|
||||
Opcode::GetKeyNameAtIndex => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req = buffer.to_original::<PddbDictRequest, _>().unwrap();
|
||||
if let Some(token) = key_token {
|
||||
|
|
@ -1097,7 +1097,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(req).unwrap();
|
||||
}
|
||||
Some(Opcode::DictCountInBasis) => {
|
||||
Opcode::DictCountInBasis => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req = buffer.to_original::<PddbDictRequest, _>().unwrap();
|
||||
if key_token.is_some() {
|
||||
|
|
@ -1125,7 +1125,7 @@ fn main() -> ! {
|
|||
req.code = PddbRequestCode::NoErr;
|
||||
buffer.replace(req).unwrap();
|
||||
}
|
||||
Some(Opcode::GetDictNameAtIndex) => {
|
||||
Opcode::GetDictNameAtIndex => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req = buffer.to_original::<PddbDictRequest, _>().unwrap();
|
||||
if let Some(token) = dict_token {
|
||||
|
|
@ -1149,7 +1149,7 @@ fn main() -> ! {
|
|||
}
|
||||
buffer.replace(req).unwrap();
|
||||
}
|
||||
Some(Opcode::ReadKey) => {
|
||||
Opcode::ReadKey => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let pbuf = PddbBuf::from_slice_mut(buffer.as_mut()); // direct translation, no serialization necessary for performance
|
||||
let token = pbuf.token;
|
||||
|
|
@ -1183,7 +1183,7 @@ fn main() -> ! {
|
|||
}
|
||||
// we don't nede a "replace" operation because all ops happen in-place
|
||||
}
|
||||
Some(Opcode::WriteKey) => {
|
||||
Opcode::WriteKey => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let pbuf = PddbBuf::from_slice_mut(buffer.as_mut()); // direct translation, no serialization necessary for performance
|
||||
let token = pbuf.token;
|
||||
|
|
@ -1217,7 +1217,7 @@ fn main() -> ! {
|
|||
// for now, do an expensive sync operation after every write to ensure data integrity
|
||||
basis_cache.sync(&mut pddb_os, None).expect("couldn't sync basis");
|
||||
}
|
||||
Some(Opcode::WriteKeyFlush) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
Opcode::WriteKeyFlush => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
match basis_cache.sync(&mut pddb_os, None) {
|
||||
Ok(_) => xous::return_scalar(msg.sender, PddbRetcode::Ok.to_usize().unwrap()).unwrap(),
|
||||
Err(e) => match e.kind() {
|
||||
|
|
@ -1227,7 +1227,7 @@ fn main() -> ! {
|
|||
}
|
||||
};
|
||||
}),
|
||||
Some(Opcode::MenuListBasis) => {
|
||||
Opcode::MenuListBasis => {
|
||||
let bases = basis_cache.basis_list();
|
||||
let mut note = String::from(t!("pddb.menu.listbasis_response", xous::LANG));
|
||||
for basis in bases.iter() {
|
||||
|
|
@ -1237,7 +1237,7 @@ fn main() -> ! {
|
|||
modals.show_notification(¬e, None).expect("couldn't show basis list");
|
||||
},
|
||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
Some(Opcode::DangerousDebug) => {
|
||||
Opcode::DangerousDebug => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let dbg = buffer.to_original::<PddbDangerousDebug, _>().unwrap();
|
||||
match dbg.request {
|
||||
|
|
@ -1257,7 +1257,7 @@ fn main() -> ! {
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(Opcode::Quit) => {
|
||||
Opcode::Quit => {
|
||||
log::warn!("quitting the PDDB server");
|
||||
send_message(
|
||||
pw_cid,
|
||||
|
|
@ -1266,7 +1266,7 @@ fn main() -> ! {
|
|||
xous::return_scalar(msg.sender, 0).unwrap();
|
||||
break
|
||||
}
|
||||
None => {
|
||||
Opcode::InvalidOpcode => {
|
||||
log::error!("couldn't convert opcode: {:?}", msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,74 +6,74 @@ pub(crate) const SIG_VERSION: u32 = 1;
|
|||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Opcode {
|
||||
/// use to check if we've been initialized
|
||||
KeysInitialized,
|
||||
KeysInitialized = 0,
|
||||
/// check that the digital signature on the gateware
|
||||
CheckGatewareSignature,
|
||||
CheckGatewareSignature = 1,
|
||||
/// check if the efuse has been locked down
|
||||
IsEfuseSecured,
|
||||
IsEfuseSecured = 2,
|
||||
/// quick check to see if the JTAG can read its IDCODE
|
||||
IsJtagWorking,
|
||||
IsJtagWorking = 3,
|
||||
/// initiate an AES oracle operation
|
||||
AesOracle,
|
||||
AesOracle = 4,
|
||||
/// initiate key wrapper operation
|
||||
AesKwp,
|
||||
AesKwp = 5,
|
||||
/// create new FPGA keys; provisioning requires a slave device to be connected that can run the JTAG sequence
|
||||
BbramProvision,
|
||||
BbramProvision = 6,
|
||||
/// clear a cached password
|
||||
ClearPasswordCacheEntry,
|
||||
ClearPasswordCacheEntry = 7,
|
||||
|
||||
TestUx,
|
||||
TestUx = 8,
|
||||
|
||||
/// attempt to initialize keys on a brand new system. Does nothing if the keys are already provisioned.
|
||||
UxTryInitKeys,
|
||||
UxInitBootPasswordReturn,
|
||||
UxInitUpdatePasswordReturn,
|
||||
UxTryInitKeys = 9,
|
||||
UxInitBootPasswordReturn = 10,
|
||||
UxInitUpdatePasswordReturn = 11,
|
||||
|
||||
/// provision a gateware update with our secret data
|
||||
UxUpdateGateware,
|
||||
UxUpdateGwPasswordReturn,
|
||||
UxUpdateGwRun,
|
||||
UxUpdateGateware = 12,
|
||||
UxUpdateGwPasswordReturn = 13,
|
||||
UxUpdateGwRun = 14,
|
||||
|
||||
/// self-sign kernel/loader
|
||||
UxSelfSignXous,
|
||||
UxSignXousPasswordReturn,
|
||||
UxSignXousRun,
|
||||
UxSelfSignXous = 15,
|
||||
UxSignXousPasswordReturn = 16,
|
||||
UxSignXousRun = 17,
|
||||
|
||||
/// Ux AES calls
|
||||
UxAesEnsurePassword,
|
||||
UxAesPasswordPolicy,
|
||||
UxAesEnsureReturn,
|
||||
UxAesEnsurePassword = 18,
|
||||
UxAesPasswordPolicy = 19,
|
||||
UxAesEnsureReturn = 20,
|
||||
|
||||
/// Ux BBRAM flow
|
||||
UxBbramCheckReturn,
|
||||
UxBbramPasswordReturn,
|
||||
UxBbramRun,
|
||||
UxBbramCheckReturn = 21,
|
||||
UxBbramPasswordReturn = 22,
|
||||
UxBbramRun = 23,
|
||||
|
||||
// General Ux calls
|
||||
UxGutter, // NOP for UX calls that require a destination
|
||||
UxGutter = 24, // NOP for UX calls that require a destination
|
||||
#[cfg(feature = "policy-menu")]
|
||||
UxGetPolicy,
|
||||
UxGetPolicy = 25,
|
||||
#[cfg(feature = "policy-menu")]
|
||||
UxPolicyReturn,
|
||||
UxTryReboot,
|
||||
UxDoReboot,
|
||||
UxPolicyReturn = 26,
|
||||
UxTryReboot = 27,
|
||||
UxDoReboot = 28,
|
||||
|
||||
/// UX opcodes
|
||||
ModalRedraw,
|
||||
ModalKeys,
|
||||
ModalDrop,
|
||||
ModalRedraw = 29,
|
||||
ModalKeys = 30,
|
||||
ModalDrop = 31,
|
||||
|
||||
/// Suspend/resume callback
|
||||
SuspendResume,
|
||||
SuspendResume = 32,
|
||||
|
||||
Quit
|
||||
Quit = 33,
|
||||
}
|
||||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive, PartialEq, Eq)]
|
||||
pub enum PasswordRetentionPolicy {
|
||||
AlwaysKeep,
|
||||
EraseOnSuspend,
|
||||
AlwaysPurge,
|
||||
AlwaysKeep = 0,
|
||||
EraseOnSuspend = 1,
|
||||
AlwaysPurge = 2,
|
||||
}
|
||||
|
||||
/// Enumerate the possible password types dealt with by this manager.
|
||||
|
|
@ -89,10 +89,10 @@ pub enum PasswordType {
|
|||
#[cfg_attr(not(any(target_os = "none", target_os = "xous")), allow(dead_code))]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum RootkeyResult {
|
||||
AlignmentError,
|
||||
KeyError,
|
||||
IntegrityError,
|
||||
FlashError,
|
||||
AlignmentError = 0,
|
||||
KeyError = 1,
|
||||
IntegrityError = 2,
|
||||
FlashError = 3,
|
||||
}
|
||||
|
||||
/// AES operation definitions
|
||||
|
|
@ -125,8 +125,8 @@ pub enum AesBlockType {
|
|||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Zeroize)]
|
||||
#[zeroize(drop)]
|
||||
pub enum AesOpType {
|
||||
Encrypt,
|
||||
Decrypt,
|
||||
Encrypt = 0,
|
||||
Decrypt = 1,
|
||||
}
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Zeroize)]
|
||||
#[zeroize(drop)]
|
||||
|
|
@ -158,20 +158,20 @@ impl AesOp {
|
|||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Zeroize, Eq, PartialEq, Copy, Clone)]
|
||||
pub enum KeywrapError {
|
||||
/// Input is too big.
|
||||
TooBig,
|
||||
TooBig = 0,
|
||||
/// Input is too small.
|
||||
TooSmall,
|
||||
TooSmall = 1,
|
||||
/// Ciphertext has invalid padding.
|
||||
Unpadded,
|
||||
Unpadded = 2,
|
||||
/// The ciphertext is not valid for the expected length.
|
||||
InvalidExpectedLen,
|
||||
InvalidExpectedLen = 3,
|
||||
/// The ciphertext couldn't be authenticated.
|
||||
AuthenticationFailed,
|
||||
AuthenticationFailed = 4,
|
||||
}
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Zeroize, Eq, PartialEq)]
|
||||
pub enum KeyWrapOp {
|
||||
Wrap,
|
||||
Unwrap,
|
||||
Wrap = 0,
|
||||
Unwrap = 1,
|
||||
}
|
||||
|
||||
use std::error::Error;
|
||||
|
|
|
|||
Loading…
Reference in a new issue