capsules_extra/
eui64.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2024.
4
5//! Provides an EUI-64 (Extended Unique Identifier) interface for userspace.
6
7use capsules_core::driver;
8pub const DRIVER_NUM: usize = driver::NUM::Eui64 as usize;
9
10use kernel::syscall::{CommandReturn, SyscallDriver};
11use kernel::{ErrorCode, ProcessId};
12
13pub struct Eui64 {
14    eui64: u64,
15}
16
17impl Eui64 {
18    pub fn new(eui64: u64) -> Eui64 {
19        Eui64 { eui64 }
20    }
21}
22
23impl SyscallDriver for Eui64 {
24    /// Control the Eui64.
25    ///
26    /// ### `command_num`
27    ///
28    /// - `0`: Driver existence check.
29    /// - `1`: Obtain EUI64 - providing the value within a u64 returncode.
30    fn command(&self, command_num: usize, _: usize, _: usize, _: ProcessId) -> CommandReturn {
31        match command_num {
32            0 => CommandReturn::success(),
33            1 => CommandReturn::success_u64(self.eui64),
34            _ => CommandReturn::failure(ErrorCode::NOSUPPORT),
35        }
36    }
37
38    fn allocate_grant(&self, _: ProcessId) -> Result<(), kernel::process::Error> {
39        Ok(())
40    }
41}