跳转到内容

std.os.uefi.protocol.simple_network

标准库Zig 0.17.0官方原文
源码std/os/uefi/protocol/simple_network.zig

第 1 行

std.os.uefi.protocol.simple_network.cc

别名

第 6 行

别名目标 std.os.uefi.cc

std.os.uefi.protocol.simple_network.Event

别名

第 3 行

别名目标 std.os.uefi.Event

std.os.uefi.protocol.simple_network.Guid

别名

第 4 行

别名目标 std.os.uefi.Guid

std.os.uefi.protocol.simple_network.SimpleNetwork

容器

第 8 行

字段

revision: u64
_start: *const fn (*SimpleNetwork) callconv(cc) Status
_stop: *const fn (*SimpleNetwork) callconv(cc) Status
_initialize: *const fn (*SimpleNetwork, usize, usize) callconv(cc) Status
_reset: *const fn (*SimpleNetwork, bool) callconv(cc) Status
_shutdown: *const fn (*SimpleNetwork) callconv(cc) Status
_receive_filters: *const fn (*SimpleNetwork, ReceiveFilter, ReceiveFilter, bool, usize, ?[*]const MacAddress) callconv(cc) Status
_station_address: *const fn (*SimpleNetwork, bool, ?*const MacAddress) callconv(cc) Status
_statistics: *const fn (*const SimpleNetwork, bool, ?*usize, ?*Statistics) callconv(cc) Status
_mcast_ip_to_mac: *const fn (*SimpleNetwork, bool, *const anyopaque, *MacAddress) callconv(cc) Status
_nvdata: *const fn (*SimpleNetwork, bool, usize, usize, [*]u8) callconv(cc) Status
_get_status: *const fn (*SimpleNetwork, ?*InterruptStatus, ?*?[*]u8) callconv(cc) Status
_transmit: *const fn (*SimpleNetwork, usize, usize, [*]const u8, ?*const MacAddress, ?*const MacAddress, ?*const u16) callconv(cc) Status
_receive: *const fn (*SimpleNetwork, ?*usize, *usize, [*]u8, ?*MacAddress, ?*MacAddress, ?*u16) callconv(cc) Status
wait_for_packet: Event
mode: *Mode

std.os.uefi.protocol.simple_network.SimpleNetwork.getStatus

函数

第 284 行

从网络接口读取当前中断状态及已回收发送缓冲区的状态。

pub fn getStatus( self: *SimpleNetwork, interrupt_status: ?*InterruptStatus, recycled_tx_buf: ?*?[*]u8, ) GetStatusError!void

参数

self: *SimpleNetwork
interrupt_status: ?*InterruptStatus
recycled_tx_buf: ?*?[*]u8

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError

std.os.uefi.protocol.simple_network.SimpleNetwork.GetStatusError

错误集合

第 87 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError

std.os.uefi.protocol.simple_network.SimpleNetwork.guid

常量

第 351 行

std.os.uefi.protocol.simple_network.SimpleNetwork.initialize

函数

第 133 行

重置网络适配器,并分配网络接口所需的发送和接收缓冲区。

pub fn initialize( self: *SimpleNetwork, extra_rx_buffer_size: usize, extra_tx_buffer_size: usize, ) InitializeError!void

参数

self: *SimpleNetwork
extra_rx_buffer_size: usize
extra_tx_buffer_size: usize

错误

DeviceError
InvalidParameter
NotStarted
OutOfResources
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.InitializeError

错误集合

第 38 行

错误

DeviceError
InvalidParameter
NotStarted
OutOfResources
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.InterruptStatus

容器

第 433 行

字段

receive_interrupt: bool
transmit_interrupt: bool
command_interrupt: bool
software_interrupt: bool
_pad: u28 = 0

std.os.uefi.protocol.simple_network.SimpleNetwork.MacAddress

类型

第 365 行

std.os.uefi.protocol.simple_network.SimpleNetwork.mcastIpToMac

函数

第 243 行

将多播 IP 地址转换为多播硬件 MAC 地址。

pub fn mcastIpToMac( self: *SimpleNetwork, ipv6: bool, ip: *const anyopaque, ) McastIpToMacError!MacAddress

参数

self: *SimpleNetwork
ipv6: bool
ip: *const anyopaque

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.McastIpToMacError

错误集合

第 75 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.Mode

容器

第 367 行

字段

state: State
hw_address_size: u32
media_header_size: u32
max_packet_size: u32
nvram_size: u32
nvram_access_size: u32
receive_filter_mask: ReceiveFilter
receive_filter_setting: ReceiveFilter
max_mcast_filter_count: u32
mcast_filter_count: u32
mcast_filter: [16]MacAddress
current_address: MacAddress
broadcast_address: MacAddress
permanent_address: MacAddress
if_type: u8
mac_address_changeable: bool
multiple_tx_supported: bool
media_present_supported: bool
media_present: bool

std.os.uefi.protocol.simple_network.SimpleNetwork.nvData

函数

第 260 行

对连接到网络接口的 NVRAM 设备执行读写操作。

pub fn nvData( self: *SimpleNetwork, read_write: NvDataOperation, offset: usize, buffer: []u8, ) NvDataError!void

参数

self: *SimpleNetwork
read_write: NvDataOperation
offset: usize
buffer: []u8

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.NvDataError

错误集合

第 81 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.NvDataOperation

容器

第 360 行

字段

read
write

std.os.uefi.protocol.simple_network.SimpleNetwork.Packet

容器

第 441 行

字段

header_size: usize
buffer: []u8
src_addr: MacAddress
dst_addr: MacAddress
protocol: u16

std.os.uefi.protocol.simple_network.SimpleNetwork.receive

函数

第 328 行

从网络接口接收数据包。

pub fn receive(self: *SimpleNetwork, buffer: []u8) ReceiveError!Packet

参数

self: *SimpleNetwork
buffer: []u8

错误

BufferTooSmall
DeviceError
InvalidParameter
NotReady
NotStarted
Unexpected UnexpectedError

std.os.uefi.protocol.simple_network.SimpleNetwork.ReceiveError

错误集合

第 100 行

错误

BufferTooSmall
DeviceError
InvalidParameter
NotReady
NotStarted
Unexpected UnexpectedError

std.os.uefi.protocol.simple_network.SimpleNetwork.ReceiveFilter

容器

第 389 行

字段

receive_unicast: bool
receive_multicast: bool
receive_broadcast: bool
receive_promiscuous: bool
receive_promiscuous_multicast: bool
_pad: u27 = 0

std.os.uefi.protocol.simple_network.SimpleNetwork.receiveFilters

函数

第 173 行

管理网络接口的多播接收过滤器。

pub fn receiveFilters( self: *SimpleNetwork, enable: ReceiveFilter, disable: ReceiveFilter, reset_mcast_filter: bool, mcast_filter: ?[]const MacAddress, ) ReceiveFiltersError!void

参数

self: *SimpleNetwork
enable: ReceiveFilter
disable: ReceiveFilter
reset_mcast_filter: bool
mcast_filter: ?[]const MacAddress

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.ReceiveFiltersError

错误集合

第 56 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.reset

函数

第 150 行

重置网络适配器,并使用上一次调用 initialize() 时提供的参数重新初始化。

pub fn reset(self: *SimpleNetwork, extended_verification: bool) ResetError!void

参数

self: *SimpleNetwork
extended_verification: bool

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.ResetError

错误集合

第 45 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.resetStatistics

函数

第 212 行

pub fn resetStatistics(self: *SimpleNetwork) StatisticsError!void

参数

self: *SimpleNetwork

错误

BufferTooSmall
DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.shutdown

函数

第 162 行

重置网络适配器,并使其处于可供其他驱动程序安全初始化的状态。

pub fn shutdown(self: *SimpleNetwork) ShutdownError!void

参数

self: *SimpleNetwork

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError

std.os.uefi.protocol.simple_network.SimpleNetwork.ShutdownError

错误集合

第 51 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError

std.os.uefi.protocol.simple_network.SimpleNetwork.start

函数

第 109 行

将网络接口从“已停止”状态改为“已启动”状态。

pub fn start(self: *SimpleNetwork) StartError!void

参数

self: *SimpleNetwork

错误

AlreadyStarted
DeviceError
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.StartError

错误集合

第 26 行

错误

AlreadyStarted
DeviceError
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.State

容器

第 398 行

字段

stopped
started
initialized

std.os.uefi.protocol.simple_network.SimpleNetwork.stationAddress

函数

第 197 行

若支持,则修改或重置当前站点地址。

pub fn stationAddress( self: *SimpleNetwork, reset_flag: bool, new: ?*const MacAddress, ) StationAddressError!void

参数

self: *SimpleNetwork
reset_flag: bool
new: ?*const MacAddress

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.StationAddressError

错误集合

第 62 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.statistics

函数

第 224 行

重置或收集网络接口的统计信息。

pub fn statistics(self: *SimpleNetwork, reset_flag: bool) StatisticsError!Statistics

参数

self: *SimpleNetwork
reset_flag: bool

错误

BufferTooSmall
DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.Statistics

容器

第 404 行

字段

rx_total_frames: u64
rx_good_frames: u64
rx_undersize_frames: u64
rx_oversize_frames: u64
rx_dropped_frames: u64
rx_unicast_frames: u64
rx_broadcast_frames: u64
rx_multicast_frames: u64
rx_crc_error_frames: u64
rx_total_bytes: u64
tx_total_frames: u64
tx_good_frames: u64
tx_undersize_frames: u64
tx_oversize_frames: u64
tx_dropped_frames: u64
tx_unicast_frames: u64
tx_broadcast_frames: u64
tx_multicast_frames: u64
tx_crc_error_frames: u64
tx_total_bytes: u64
collisions: u64
unsupported_protocol: u64
rx_duplicated_frames: u64
rx_decryptError_frames: u64
tx_error_frames: u64
tx_retry_frames: u64

std.os.uefi.protocol.simple_network.SimpleNetwork.StatisticsError

错误集合

第 68 行

错误

BufferTooSmall
DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.stop

函数

第 121 行

将网络接口状态从 "started" 改为 "stopped"。

pub fn stop(self: *SimpleNetwork) StopError!void

参数

self: *SimpleNetwork

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.StopError

错误集合

第 32 行

错误

DeviceError
InvalidParameter
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.transmit

函数

第 299 行

将数据包放入网络接口的发送队列。

pub fn transmit( self: *SimpleNetwork, header_size: usize, buffer: []const u8, src_addr: ?*const MacAddress, dest_addr: ?*const MacAddress, protocol: ?*const u16, ) TransmitError!void

参数

self: *SimpleNetwork
header_size: usize
buffer: []const u8
src_addr: ?*const MacAddress
dest_addr: ?*const MacAddress
protocol: ?*const u16

错误

BufferTooSmall
DeviceError
InvalidParameter
NotReady
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.SimpleNetwork.TransmitError

错误集合

第 92 行

错误

BufferTooSmall
DeviceError
InvalidParameter
NotReady
NotStarted
Unexpected UnexpectedError
Unsupported

std.os.uefi.protocol.simple_network.Status

别名

第 5 行

别名目标 std.os.uefi.Status

std.os.uefi.protocol.simple_network.std

别名

第 1 行

别名目标 std

std.os.uefi.protocol.simple_network.uefi

别名

第 2 行

别名目标 std.os.uefi

源码

std/os/uefi/protocol/simple_network.zig

const std = @import("std");
const uefi = std.os.uefi;
const Event = uefi.Event;
const Guid = uefi.Guid;
const Status = uefi.Status;
const cc = uefi.cc;

pub const SimpleNetwork = extern struct {
    revision: u64,
    _start: *const fn (*SimpleNetwork) callconv(cc) Status,
    _stop: *const fn (*SimpleNetwork) callconv(cc) Status,
    _initialize: *const fn (*SimpleNetwork, usize, usize) callconv(cc) Status,
    _reset: *const fn (*SimpleNetwork, bool) callconv(cc) Status,
    _shutdown: *const fn (*SimpleNetwork) callconv(cc) Status,
    _receive_filters: *const fn (*SimpleNetwork, ReceiveFilter, ReceiveFilter, bool, usize, ?[*]const MacAddress) callconv(cc) Status,
    _station_address: *const fn (*SimpleNetwork, bool, ?*const MacAddress) callconv(cc) Status,
    _statistics: *const fn (*const SimpleNetwork, bool, ?*usize, ?*Statistics) callconv(cc) Status,
    _mcast_ip_to_mac: *const fn (*SimpleNetwork, bool, *const anyopaque, *MacAddress) callconv(cc) Status,
    _nvdata: *const fn (*SimpleNetwork, bool, usize, usize, [*]u8) callconv(cc) Status,
    _get_status: *const fn (*SimpleNetwork, ?*InterruptStatus, ?*?[*]u8) callconv(cc) Status,
    _transmit: *const fn (*SimpleNetwork, usize, usize, [*]const u8, ?*const MacAddress, ?*const MacAddress, ?*const u16) callconv(cc) Status,
    _receive: *const fn (*SimpleNetwork, ?*usize, *usize, [*]u8, ?*MacAddress, ?*MacAddress, ?*u16) callconv(cc) Status,
    wait_for_packet: Event,
    mode: *Mode,

    pub const StartError = uefi.UnexpectedError || error{
        AlreadyStarted,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const StopError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const InitializeError = uefi.UnexpectedError || error{
        NotStarted,
        OutOfResources,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const ResetError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const ShutdownError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
    };
    pub const ReceiveFiltersError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const StationAddressError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const StatisticsError = uefi.UnexpectedError || error{
        NotStarted,
        BufferTooSmall,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const McastIpToMacError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const NvDataError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const GetStatusError = uefi.UnexpectedError || error{
        NotStarted,
        InvalidParameter,
        DeviceError,
    };
    pub const TransmitError = uefi.UnexpectedError || error{
        NotStarted,
        NotReady,
        BufferTooSmall,
        InvalidParameter,
        DeviceError,
        Unsupported,
    };
    pub const ReceiveError = uefi.UnexpectedError || error{
        NotStarted,
        NotReady,
        BufferTooSmall,
        InvalidParameter,
        DeviceError,
    };

    /// 将网络接口从“已停止”状态改为“已启动”状态。
    pub fn start(self: *SimpleNetwork) StartError!void {
        switch (self._start(self)) {
            .success => {},
            .already_started => return error.AlreadyStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 将网络接口状态从 "started" 改为 "stopped"。
    pub fn stop(self: *SimpleNetwork) StopError!void {
        switch (self._stop(self)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 重置网络适配器,并分配网络接口所需的发送和接收缓冲区。
    pub fn initialize(
        self: *SimpleNetwork,
        extra_rx_buffer_size: usize,
        extra_tx_buffer_size: usize,
    ) InitializeError!void {
        switch (self._initialize(self, extra_rx_buffer_size, extra_tx_buffer_size)) {
            .success => {},
            .not_started => return error.NotStarted,
            .out_of_resources => return error.OutOfResources,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 重置网络适配器,并使用上一次调用 initialize() 时提供的参数重新初始化。
    pub fn reset(self: *SimpleNetwork, extended_verification: bool) ResetError!void {
        switch (self._reset(self, extended_verification)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 重置网络适配器,并使其处于可供其他驱动程序安全初始化的状态。
    pub fn shutdown(self: *SimpleNetwork) ShutdownError!void {
        switch (self._shutdown(self)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 管理网络接口的多播接收过滤器。
    pub fn receiveFilters(
        self: *SimpleNetwork,
        enable: ReceiveFilter,
        disable: ReceiveFilter,
        reset_mcast_filter: bool,
        mcast_filter: ?[]const MacAddress,
    ) ReceiveFiltersError!void {
        const count: usize, const ptr: ?[*]const MacAddress =
            if (mcast_filter) |f|
                .{ f.len, f.ptr }
            else
                .{ 0, null };

        switch (self._receive_filters(self, enable, disable, reset_mcast_filter, count, ptr)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 若支持,则修改或重置当前站点地址。
    pub fn stationAddress(
        self: *SimpleNetwork,
        reset_flag: bool,
        new: ?*const MacAddress,
    ) StationAddressError!void {
        switch (self._station_address(self, reset_flag, new)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn resetStatistics(self: *SimpleNetwork) StatisticsError!void {
        switch (self._statistics(self, true, null, null)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 重置或收集网络接口的统计信息。
    pub fn statistics(self: *SimpleNetwork, reset_flag: bool) StatisticsError!Statistics {
        var stats: Statistics = undefined;
        var stats_size: usize = @sizeOf(Statistics);
        switch (self._statistics(self, reset_flag, &stats_size, &stats)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }

        if (stats_size != @sizeOf(Statistics))
            return error.Unexpected
        else
            return stats;
    }

    /// 将多播 IP 地址转换为多播硬件 MAC 地址。
    pub fn mcastIpToMac(
        self: *SimpleNetwork,
        ipv6: bool,
        ip: *const anyopaque,
    ) McastIpToMacError!MacAddress {
        var mac: MacAddress = undefined;
        switch (self._mcast_ip_to_mac(self, ipv6, ip, &mac)) {
            .success => return mac,
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 对连接到网络接口的 NVRAM 设备执行读写操作。
    pub fn nvData(
        self: *SimpleNetwork,
        read_write: NvDataOperation,
        offset: usize,
        buffer: []u8,
    ) NvDataError!void {
        switch (self._nvdata(
            self,
            // 如果 ReadWrite 为 TRUE,则执行读取操作。
            read_write == .read,
            offset,
            buffer.len,
            buffer.ptr,
        )) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 从网络接口读取当前中断状态及已回收发送缓冲区的状态。
    pub fn getStatus(
        self: *SimpleNetwork,
        interrupt_status: ?*InterruptStatus,
        recycled_tx_buf: ?*?[*]u8,
    ) GetStatusError!void {
        switch (self._get_status(self, interrupt_status, recycled_tx_buf)) {
            .success => {},
            .not_started => return error.NotStarted,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 将数据包放入网络接口的发送队列。
    pub fn transmit(
        self: *SimpleNetwork,
        header_size: usize,
        buffer: []const u8,
        src_addr: ?*const MacAddress,
        dest_addr: ?*const MacAddress,
        protocol: ?*const u16,
    ) TransmitError!void {
        switch (self._transmit(
            self,
            header_size,
            buffer.len,
            buffer.ptr,
            src_addr,
            dest_addr,
            protocol,
        )) {
            .success => {},
            .not_started => return error.NotStarted,
            .not_ready => return error.NotReady,
            .buffer_too_small => return error.BufferTooSmall,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 从网络接口接收数据包。
    pub fn receive(self: *SimpleNetwork, buffer: []u8) ReceiveError!Packet {
        var packet: Packet = undefined;
        packet.buffer = buffer;

        switch (self._receive(
            self,
            &packet.header_size,
            &packet.buffer.len,
            packet.buffer.ptr,
            &packet.src_addr,
            &packet.dst_addr,
            &packet.protocol,
        )) {
            .success => return packet,
            .not_started => return error.NotStarted,
            .not_ready => return error.NotReady,
            .buffer_too_small => return error.BufferTooSmall,
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub const guid align(8) = Guid{
        .time_low = 0xa19832b9,
        .time_mid = 0xac25,
        .time_high_and_version = 0x11d3,
        .clock_seq_high_and_reserved = 0x9a,
        .clock_seq_low = 0x2d,
        .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d },
    };

    pub const NvDataOperation = enum {
        read,
        write,
    };

    pub const MacAddress = [32]u8;

    pub const Mode = extern struct {
        state: State,
        hw_address_size: u32,
        media_header_size: u32,
        max_packet_size: u32,
        nvram_size: u32,
        nvram_access_size: u32,
        receive_filter_mask: ReceiveFilter,
        receive_filter_setting: ReceiveFilter,
        max_mcast_filter_count: u32,
        mcast_filter_count: u32,
        mcast_filter: [16]MacAddress,
        current_address: MacAddress,
        broadcast_address: MacAddress,
        permanent_address: MacAddress,
        if_type: u8,
        mac_address_changeable: bool,
        multiple_tx_supported: bool,
        media_present_supported: bool,
        media_present: bool,
    };

    pub const ReceiveFilter = packed struct(u32) {
        receive_unicast: bool,
        receive_multicast: bool,
        receive_broadcast: bool,
        receive_promiscuous: bool,
        receive_promiscuous_multicast: bool,
        _pad: u27 = 0,
    };

    pub const State = enum(u32) {
        stopped,
        started,
        initialized,
    };

    pub const Statistics = extern struct {
        rx_total_frames: u64,
        rx_good_frames: u64,
        rx_undersize_frames: u64,
        rx_oversize_frames: u64,
        rx_dropped_frames: u64,
        rx_unicast_frames: u64,
        rx_broadcast_frames: u64,
        rx_multicast_frames: u64,
        rx_crc_error_frames: u64,
        rx_total_bytes: u64,
        tx_total_frames: u64,
        tx_good_frames: u64,
        tx_undersize_frames: u64,
        tx_oversize_frames: u64,
        tx_dropped_frames: u64,
        tx_unicast_frames: u64,
        tx_broadcast_frames: u64,
        tx_multicast_frames: u64,
        tx_crc_error_frames: u64,
        tx_total_bytes: u64,
        collisions: u64,
        unsupported_protocol: u64,
        rx_duplicated_frames: u64,
        rx_decryptError_frames: u64,
        tx_error_frames: u64,
        tx_retry_frames: u64,
    };

    pub const InterruptStatus = packed struct(u32) {
        receive_interrupt: bool,
        transmit_interrupt: bool,
        command_interrupt: bool,
        software_interrupt: bool,
        _pad: u28 = 0,
    };

    pub const Packet = struct {
        header_size: usize,
        buffer: []u8,
        src_addr: MacAddress,
        dst_addr: MacAddress,
        protocol: u16,
    };
};