-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements sockets, initializes rng, gc and camera devices
- Loading branch information
1 parent
30c3e25
commit ecc4933
Showing
13 changed files
with
380 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use crate::{ | ||
errno::Errno, | ||
fs::{ | ||
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoCmd, MakeDevError, MakeDevFlags, | ||
Mode, OpenFlags, Uio, UioMut, | ||
}, | ||
process::VThread, | ||
ucred::{Gid, Uid}, | ||
}; | ||
use std::sync::Arc; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug)] | ||
struct Camera {} | ||
|
||
impl Camera { | ||
fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl DeviceDriver for Camera { | ||
#[allow(unused_variables)] // TODO: remove when implementing | ||
fn open( | ||
&self, | ||
dev: &Arc<CharacterDevice>, | ||
mode: OpenFlags, | ||
devtype: i32, | ||
td: Option<&VThread>, | ||
) -> Result<(), Box<dyn Errno>> { | ||
todo!() | ||
} | ||
|
||
#[allow(unused_variables)] // TODO: remove when implementing | ||
fn read( | ||
&self, | ||
dev: &Arc<CharacterDevice>, | ||
data: &mut UioMut, | ||
td: Option<&VThread>, | ||
) -> Result<(), Box<dyn Errno>> { | ||
todo!() | ||
} | ||
|
||
#[allow(unused_variables)] // TODO: remove when implementing | ||
fn write( | ||
&self, | ||
dev: &Arc<CharacterDevice>, | ||
data: &mut Uio, | ||
td: Option<&VThread>, | ||
) -> Result<(), Box<dyn Errno>> { | ||
todo!() | ||
} | ||
|
||
#[allow(unused_variables)] // TODO: remove when implementing | ||
fn ioctl( | ||
&self, | ||
dev: &Arc<CharacterDevice>, | ||
cmd: IoCmd, | ||
td: Option<&VThread>, | ||
) -> Result<(), Box<dyn Errno>> { | ||
todo!() | ||
} | ||
} | ||
|
||
pub struct CameraManager { | ||
dipsw: Arc<CharacterDevice>, | ||
} | ||
|
||
impl CameraManager { | ||
pub fn new() -> Result<Arc<Self>, CameraInitError> { | ||
let dipsw = make_dev( | ||
Camera::new(), | ||
DriverFlags::from_bits_retain(0x80000004), | ||
0, | ||
"camera", | ||
Uid::ROOT, | ||
Gid::ROOT, | ||
Mode::new(0o666).unwrap(), | ||
None, | ||
MakeDevFlags::MAKEDEV_ETERNAL, | ||
)?; | ||
|
||
Ok(Arc::new(Self { dipsw })) | ||
} | ||
} | ||
|
||
/// Represents an error when [`CameraManager`] fails to initialize. | ||
#[derive(Debug, Error)] | ||
pub enum CameraInitError { | ||
#[error("cannot create camera device")] | ||
CreateGcFailed(#[from] MakeDevError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,79 @@ | ||
use crate::{ | ||
arnd, | ||
errno::Errno, | ||
fs::{CharacterDevice, DeviceDriver, IoCmd}, | ||
fs::{ | ||
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoCmd, MakeDevError, MakeDevFlags, | ||
Mode, | ||
}, | ||
process::VThread, | ||
ucred::{Gid, Uid}, | ||
}; | ||
use std::sync::Arc; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug)] | ||
struct Rng {} | ||
|
||
impl Rng { | ||
fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl DeviceDriver for Rng { | ||
fn ioctl( | ||
&self, | ||
dev: &Arc<CharacterDevice>, | ||
_: &Arc<CharacterDevice>, | ||
cmd: IoCmd, | ||
_: Option<&VThread>, | ||
) -> Result<(), Box<dyn Errno>> { | ||
match cmd { | ||
IoCmd::RNGGETGENUINE(_) => todo!(), | ||
IoCmd::RNGFIPS(_) => todo!(), | ||
// TODO: these are separate algorithms, and should be implemented as such, | ||
// however arc4rand seems sufficient for now | ||
IoCmd::RNGGETGENUINE(input) | IoCmd::RNGFIPS(input) => { | ||
input.error = 0; | ||
|
||
arnd::rand_bytes(&mut input.data); | ||
|
||
Ok(()) | ||
} | ||
_ => todo!(), // ENOIOCTL, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct RngInput { | ||
/// This field seems to be treated as an error | ||
error: i32, | ||
data: [u8; 64], | ||
} | ||
|
||
pub struct RngManager { | ||
dipsw: Arc<CharacterDevice>, | ||
} | ||
|
||
impl RngManager { | ||
pub fn new() -> Result<Arc<Self>, RngInitError> { | ||
let rng = make_dev( | ||
Rng::new(), | ||
DriverFlags::from_bits_retain(0x80000004), | ||
0, | ||
"rng", | ||
Uid::ROOT, | ||
Gid::ROOT, | ||
Mode::new(0o444).unwrap(), | ||
None, | ||
MakeDevFlags::MAKEDEV_ETERNAL, | ||
)?; | ||
|
||
Ok(Arc::new(Self { dipsw: rng })) | ||
} | ||
} | ||
|
||
/// Represents an error when [`RngManager`] fails to initialize. | ||
#[derive(Debug, Error)] | ||
pub enum RngInitError { | ||
#[error("cannot create rng device")] | ||
CreateRngFailed(#[from] MakeDevError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.