nf 0.1.0

A port of the netfilter framework written entirely in rust.
Documentation
#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types)]

/// Loopback mode - device receives its own transmitted frames
pub const CAN_CTRLMODE_LOOPBACK: u32 = 0x01; /* Loopback mode */
/// Listen-only mode - no transmission, reception only
pub const CAN_CTRLMODE_LISTENONLY: u32 = 0x02; /* Listen-only mode */
/// Triple sampling mode - take 3 samples of each bit instead of 1
pub const CAN_CTRLMODE_3_SAMPLES: u32 = 0x04; /* Triple sampling mode */
/// One-Shot mode - no retransmission attempts
pub const CAN_CTRLMODE_ONE_SHOT: u32 = 0x08; /* One-Shot mode */
/// Bus-error reporting - report errors when they occur
pub const CAN_CTRLMODE_BERR_REPORTING: u32 = 0x10; /* Bus-error reporting */
/// CAN FD mode - controller supports CAN FD protocol
pub const CAN_CTRLMODE_FD: u32 = 0x20; /* CAN FD mode */
/// Presume ACK - ignore missing CAN ACKs
pub const CAN_CTRLMODE_PRESUME_ACK: u32 = 0x40; /* Ignore missing CAN ACKs */
/// CAN FD in non-ISO mode - use non-ISO CAN FD frame format
pub const CAN_CTRLMODE_FD_NON_ISO: u32 = 0x80; /* CAN FD in non-ISO mode */
/// Classic CAN DLC option - use 8 byte payload with DLC > 8
pub const CAN_CTRLMODE_CC_LEN8_DLC: u32 = 0x100; /* Classic CAN DLC option */
/// Automatic TDC - transceiver automatically calculates TDCV
pub const CAN_CTRLMODE_TDC_AUTO: u32 = 0x200; /* CAN transiver automatically calculates TDCV */
/// Manual TDC - TDCV is manually set up by user
pub const CAN_CTRLMODE_TDC_MANUAL: u32 = 0x400; /* TDCV is manually set up by user */
/// Termination disabled - no line termination
pub const CAN_TERMINATION_DISABLED: u32 = 0;

/*
 * CAN netlink interface
 */
/// CAN interface netlink attribute types
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u32)]
pub enum ifla_can {
    /// Unspecified attribute
    IFLA_CAN_UNSPEC,
    /// Bit timing parameters
    IFLA_CAN_BITTIMING,
    /// Bit timing constants
    IFLA_CAN_BITTIMING_CONST,
    /// Clock parameters
    IFLA_CAN_CLOCK,
    /// CAN controller state
    IFLA_CAN_STATE,
    /// Controller mode
    IFLA_CAN_CTRLMODE,
    /// Restart delay (ms)
    IFLA_CAN_RESTART_MS,
    /// Restart flag
    IFLA_CAN_RESTART,
    /// Bus error counters
    IFLA_CAN_BERR_COUNTER,
    /// Data phase bit timing parameters
    IFLA_CAN_DATA_BITTIMING,
    /// Data phase bit timing constants
    IFLA_CAN_DATA_BITTIMING_CONST,
    /// Termination setting
    IFLA_CAN_TERMINATION,
    /// Termination constants
    IFLA_CAN_TERMINATION_CONST,
    /// Bit rate constants
    IFLA_CAN_BITRATE_CONST,
    /// Data bit rate constants
    IFLA_CAN_DATA_BITRATE_CONST,
    /// Maximum bit rate
    IFLA_CAN_BITRATE_MAX,
    /// Transmitter delay compensation parameters
    IFLA_CAN_TDC,
    /// Extended controller mode
    IFLA_CAN_CTRLMODE_EXT,

    /* add new constants above here */
    /// Upper bound of CAN interface attributes
    __IFLA_CAN_MAX,
}

/// Maximum CAN interface attribute value
pub const IFLA_CAN_MAX: u32 = ifla_can::__IFLA_CAN_MAX as u32 - 1;

/*
 * CAN FD Transmitter Delay Compensation (TDC)
 *
 * Please refer to struct can_tdc_const and can_tdc in
 * include/linux/can/bittiming.h for further details.
 */
/// CAN Transmitter Delay Compensation netlink attribute types
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u32)]
pub enum ifla_can_tdc {
    /// Unspecified attribute
    IFLA_CAN_TDC_UNSPEC,
    /// Minimum TDCV value
    IFLA_CAN_TDC_TDCV_MIN, /* u32 */
    /// Maximum TDCV value
    IFLA_CAN_TDC_TDCV_MAX, /* u32 */
    /// Minimum TDCO value
    IFLA_CAN_TDC_TDCO_MIN, /* u32 */
    /// Maximum TDCO value
    IFLA_CAN_TDC_TDCO_MAX, /* u32 */
    /// Minimum TDCF value
    IFLA_CAN_TDC_TDCF_MIN, /* u32 */
    /// Maximum TDCF value
    IFLA_CAN_TDC_TDCF_MAX, /* u32 */
    /// TDCV (transmitter delay compensation value)
    IFLA_CAN_TDC_TDCV,     /* u32 */
    /// TDCO (transmitter delay compensation offset)
    IFLA_CAN_TDC_TDCO,     /* u32 */
    /// TDCF (transmitter delay compensation filter window length)
    IFLA_CAN_TDC_TDCF,     /* u32 */

    /* add new constants above here */
    /// Upper bound of CAN TDC attributes
    __IFLA_CAN_TDC,
}

/// Maximum CAN TDC attribute value
pub const IFLA_CAN_TDC_MAX: u32 = ifla_can_tdc::__IFLA_CAN_TDC as u32 - 1;

/*
 * IFLA_CAN_CTRLMODE_EXT nest: controller mode extended parameters
 */
/// CAN controller mode extended netlink attribute types
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u32)]
pub enum ifla_can_ctrlmode {
    /// Unspecified attribute
    IFLA_CAN_CTRLMODE_UNSPEC,
    /// Supported controller modes (u32 bitmask)
    IFLA_CAN_CTRLMODE_SUPPORTED, /* u32 */
    /* add new constants above here */
    /// Upper bound of CAN controller mode attributes
    __IFLA_CAN_CTRLMODE,
}

/// Maximum CAN controller mode attribute value
pub const IFLA_CAN_CTRLMODE_MAX: u32 = ifla_can_ctrlmode::__IFLA_CAN_CTRLMODE as u32 - 1;

/*
 * CAN operational and error states
 */
/// CAN controller state enumeration
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u32)]
pub enum can_state {
    /// Error active: RX/TX error count < 96
    CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */
    /// Error warning: RX/TX error count < 128 
    CAN_STATE_ERROR_WARNING,    /* RX/TX error count < 128 */
    /// Error passive: RX/TX error count < 256
    CAN_STATE_ERROR_PASSIVE,    /* RX/TX error count < 256 */
    /// Bus off: RX/TX error count >= 256
    CAN_STATE_BUS_OFF,          /* RX/TX error count >= 256 */
    /// Device stopped
    CAN_STATE_STOPPED,          /* Device is stopped */
    /// Device in sleep mode
    CAN_STATE_SLEEPING,         /* Device is sleeping */
    /// Maximum state value
    CAN_STATE_MAX,
}

/**
 * CAN bit-timing parameters
 *
 * For further information, please read chapter "8 BIT TIMING
 * REQUIREMENTS" of the "Bosch CAN Specification version 2.0"
 * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf.
 */
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct can_bittiming {
    /// Bit-rate in bits/second
    pub bitrate: u32,
    /// Sample point in one-tenth of a percent
    pub sample_point: u32,
    /// Time quanta in nanoseconds
    pub tq: u32,
    /// Propagation segment in time quanta
    pub prop_seg: u32,
    /// Phase buffer segment 1 in time quanta
    pub phase_seg1: u32,
    /// Phase buffer segment 2 in time quanta
    pub phase_seg2: u32,
    /// Synchronisation jump width in time quanta
    pub sjw: u32,
    /// Bit-rate prescaler
    pub brp: u32,
}

/**
 * CAN hardware-dependent bit-timing constant
 *
 * Used for calculating and checking bit-timing parameters
 */
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct can_bittiming_const {
    /// Name of the CAN controller hardware
    pub name: [u8; 16],
    /// Time segment 1 = prop_seg + phase_seg1
    pub tseg1_min: u32,
    /// Time segment 1 = prop_seg + phase_seg1
    pub tseg1_max: u32,
    /// Time segment 2
    pub tseg2_min: u32,
    /// Time segment 2
    pub tseg2_max: u32,
    /// Synchronisation jump width
    pub sjw_max: u32,
    /// Bit-rate prescaler
    pub brp_min: u32,
    /// Bit-rate prescaler
    pub brp_max: u32,
    /// Bit-rate prescaler increment
    pub brp_inc: u32,
}

/*
 * CAN clock parameters
 */
/// CAN controller clock parameters
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct can_clock {
    /// CAN system clock frequency in Hz
    pub freq: u32,
}

/*
 * CAN bus error counters
 */
/// CAN controller bus error counters
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct can_berr_counter {
    /// TX error counter
    pub txerr: u16,
    /// RX error counter
    pub rxerr: u16,
}

/*
 * CAN controller mode
 */
/// CAN controller mode settings
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct can_ctrlmode {
    /// Mode bitmask
    pub flags: u32,
    /// Mode bitmask mask
    pub mask: u32,
}

/*
 * CAN device statistics
 */
/// CAN device statistics
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct can_device_stats {
    /// Bus error counter
    pub bus_error: u32,
    /// Error warning counter
    pub error_warning: u32,
    /// Error passive counter
    pub error_passive: u32,
    /// Bus off counter
    pub bus_off: u32,
    /// Arbitration lost counter
    pub arbitration_lost: u32,
    /// Restarts counter
    pub restarts: u32,
}