Skip to content

Commit

Permalink
added wireless struct and constants to Linux.
Browse files Browse the repository at this point in the history
(backport <rust-lang#3441>)
(cherry picked from commit 1ee94df)
  • Loading branch information
Brijeshkrishna authored and tgross35 committed Nov 18, 2024
1 parent 69ce895 commit 758a436
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 8 deletions.
5 changes: 0 additions & 5 deletions libc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,3 @@ harness = true
name = "semver"
path = "test/semver.rs"
harness = false

[[test]]
name = "primitive_types"
path = "test/primitive_types.rs"
harness = true
23 changes: 23 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1353,9 +1353,16 @@ IW_ENC_CAPA_CIPHER_TKIP
IW_ENC_CAPA_WPA
IW_ENC_CAPA_WPA2
IW_ESSID_MAX_SIZE
IW_EVENT_CAPA_K_0
IW_EVENT_CAPA_K_1
IW_EV_ADDR_PK_LEN
IW_EV_CHAR_PK_LEN
IW_EV_FREQ_PK_LEN
IW_EV_LCP_PK_LEN
IW_EV_PARAM_PK_LEN
IW_EV_POINT_PK_LEN
IW_EV_QUAL_PK_LEN
IW_EV_UINT_PK_LEN
IW_FREQ_AUTO
IW_FREQ_FIXED
IW_GENERIC_IE_MAX
Expand Down Expand Up @@ -3728,6 +3735,22 @@ ip_mreq_source
ip_mreqn
ipc_perm
itimerspec
iw_discarded
iw_encode_ext
iw_event
iw_freq
iw_missed
iw_param
iw_pmkid_cand
iw_pmksa
iw_point
iw_priv_args
iw_quality
iw_range
iw_scan_req
iw_statistics
iwreq
iwreq_data
j1939_filter
jrand48
key_t
Expand Down
255 changes: 252 additions & 3 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,141 @@ s! {
pub ts_first_pkt: ::tpacket_bd_ts,
pub ts_last_pkt: ::tpacket_bd_ts,
}

// linux/wireless.h

pub struct iw_param {
pub value: __s32,
pub fixed: __u8,
pub disabled: __u8,
pub flags: __u16,
}

pub struct iw_point {
pub pointer: *mut ::c_void,
pub length: __u16,
pub flags: __u16,
}

pub struct iw_freq {
pub m: __s32,
pub e: __s16,
pub i: __u8,
pub flags: __u8,
}

pub struct iw_quality {
pub qual: __u8,
pub level: __u8,
pub noise: __u8,
pub updated: __u8,
}

pub struct iw_discarded {
pub nwid: __u32,
pub code: __u32,
pub fragment: __u32,
pub retries: __u32,
pubmisc: __u32,
}

pub struct iw_missed {
pub beacon: __u32,
}

pub struct iw_scan_req {
pub scan_type: __u8,
pub essid_len: __u8,
pub num_channels: __u8,
pub flags: __u8,
pub bssid: ::sockaddr,
pub essid: [__u8; IW_ESSID_MAX_SIZE],
pub min_channel_time: __u32,
pub max_channel_time: __u32,
pub channel_list: [iw_freq; IW_MAX_FREQUENCIES],
}

pub struct iw_encode_ext {
pub ext_flags: __u32,
pub tx_seq: [__u8; IW_ENCODE_SEQ_MAX_SIZE],
pub rx_seq: [__u8; IW_ENCODE_SEQ_MAX_SIZE],
pub addr: ::sockaddr,
pub alg: __u16,
pub key_len: __u16,
pub key: [__u8;0],
}

pub struct iw_pmksa {
pub cmd: __u32,
pub bssid: ::sockaddr,
pub pmkid: [__u8; IW_PMKID_LEN],
}

pub struct iw_pmkid_cand {
pub flags: __u32,
pub index: __u32,
pub bssid: ::sockaddr,
}

pub struct iw_statistics {
pub status: __u16,
pub qual: iw_quality,
pub discard: iw_discarded,
pub miss: iw_missed,
}

pub struct iw_range {
pub throughput: __u32,
pub min_nwid: __u32,
pub max_nwid: __u32,
pub old_num_channels: __u16,
pub old_num_frequency: __u8,
pub scan_capa: __u8,
pub event_capa: [__u32; 6],
pub sensitivity: __s32,
pub max_qual: iw_quality,
pub avg_qual: iw_quality,
pub num_bitrates: __u8,
pub bitrate: [__s32; IW_MAX_BITRATES],
pub min_rts: __s32,
pub max_rts: __s32,
pub min_frag: __s32,
pub max_frag: __s32,
pub min_pmp: __s32,
pub max_pmp: __s32,
pub min_pmt: __s32,
pub max_pmt: __s32,
pub pmp_flags: __u16,
pub pmt_flags: __u16,
pub pm_capa: __u16,
pub encoding_size: [__u16; IW_MAX_ENCODING_SIZES],
pub num_encoding_sizes: __u8,
pub max_encoding_tokens: __u8,
pub encoding_login_index: __u8,
pub txpower_capa: __u16,
pub num_txpower: __u8,
pub txpower: [__s32;IW_MAX_TXPOWER],
pub we_version_compiled: __u8,
pub we_version_source: __u8,
pub retry_capa: __u16,
pub retry_flags: __u16,
pub r_time_flags: __u16,
pub min_retry: __s32,
pub max_retry: __s32,
pub min_r_time: __s32,
pub max_r_time: __s32,
pub num_channels: __u16,
pub num_frequency: __u8,
pub freq: [iw_freq; IW_MAX_FREQUENCIES],
pub enc_capa: __u32,
}

pub struct iw_priv_args {
pub cmd: __u32,
pub set_args: __u16,
pub get_args: __u16,
pub name: [c_char; ::IFNAMSIZ],
}
}

cfg_if! {
Expand All @@ -1009,10 +1144,26 @@ cfg_if! {
pub r_info: Elf64_Xword,
pub r_addend: Elf64_Sxword,
}

pub struct iw_thrspy {
pub addr: ::sockaddr,
pub qual: iw_quality,
pub low: iw_quality,
pub high: iw_quality,
}
pub struct iw_mlme {
pub cmd: __u16,
pub reason_code: __u16,
pub addr: ::sockaddr,
}
pub struct iw_michaelmicfailure {
pub flags: __u32,
pub src_addr: ::sockaddr,
pub tsc: [__u8; IW_ENCODE_SEQ_MAX_SIZE],
}
}
}
}

s_no_extra_traits! {
pub struct sockaddr_nl {
pub nl_family: ::sa_family_t,
Expand Down Expand Up @@ -1325,6 +1476,45 @@ s_no_extra_traits! {
}
}

s_no_extra_traits! {
// linux/wireless.h
pub union iwreq_data {
pub name: [c_char; ::IFNAMSIZ],
pub essid: iw_point,
pub nwid: iw_param,
pub freq: iw_freq,
pub sens: iw_param,
pub bitrate: iw_param,
pub txpower: iw_param,
pub rts: iw_param,
pub frag: iw_param,
pub mode: __u32,
pub retry: iw_param,
pub encoding: iw_point,
pub power: iw_param,
pub qual: iw_quality,
pub ap_addr: ::sockaddr,
pub addr: ::sockaddr,
pub param: iw_param,
pub data: iw_point,
}

pub struct iw_event {
pub len: __u16,
pub cmd: __u16,
pub u: iwreq_data,
}

pub union __c_anonymous_iwreq {
pub ifrn_name: [c_char; ::IFNAMSIZ],
}

pub struct iwreq {
pub ifr_ifrn: __c_anonymous_iwreq,
pub u: iwreq_data,
}
}

cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for sockaddr_nl {
Expand Down Expand Up @@ -1797,6 +1987,57 @@ cfg_if! {
self.sched_period.hash(state);
}
}
impl ::fmt::Debug for iwreq_data {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("iwreq_data")
.field("name", unsafe { &self.name })
.field("essid", unsafe { &self.essid })
.field("nwid", unsafe { &self.nwid })
.field("freq", unsafe { &self.freq })
.field("sens", unsafe { &self.sens })
.field("bitrate", unsafe { &self.bitrate })
.field("txpower", unsafe { &self.txpower })
.field("rts", unsafe { &self.rts })
.field("frag", unsafe { &self.frag })
.field("mode", unsafe { &self.mode })
.field("retry", unsafe { &self.retry })
.field("encoding", unsafe { &self.encoding })
.field("power", unsafe { &self.power })
.field("qual", unsafe { &self.qual })
.field("ap_addr", unsafe { &self.ap_addr })
.field("addr", unsafe { &self.addr })
.field("param", unsafe { &self.param })
.field("data", unsafe { &self.data })
.finish()
}
}

impl ::fmt::Debug for iw_event {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("iw_event")
.field("len", &self.len )
.field("cmd", &self.cmd )
.field("u", &self.u )
.finish()
}
}

impl ::fmt::Debug for __c_anonymous_iwreq {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("__c_anonymous_iwreq")
.field("ifrn_name", unsafe { &self.ifrn_name })
.finish()
}
}

impl ::fmt::Debug for iwreq {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("iwreq")
.field("ifr_ifrn", &self.ifr_ifrn )
.field("u", &self.u )
.finish()
}
}
}
}

Expand Down Expand Up @@ -3794,6 +4035,9 @@ pub const IW_ENC_CAPA_CIPHER_TKIP: ::c_ulong = 0x00000004;
pub const IW_ENC_CAPA_CIPHER_CCMP: ::c_ulong = 0x00000008;
pub const IW_ENC_CAPA_4WAY_HANDSHAKE: ::c_ulong = 0x00000010;

pub const IW_EVENT_CAPA_K_0: c_ulong = 0x4000050; // IW_EVENT_CAPA_MASK(0x8B04) | IW_EVENT_CAPA_MASK(0x8B06) | IW_EVENT_CAPA_MASK(0x8B1A);
pub const IW_EVENT_CAPA_K_1: c_ulong = 0x400; // W_EVENT_CAPA_MASK(0x8B2A);

pub const IW_PMKSA_ADD: usize = 1;
pub const IW_PMKSA_REMOVE: usize = 2;
pub const IW_PMKSA_FLUSH: usize = 3;
Expand All @@ -3804,8 +4048,13 @@ pub const IW_PMKID_CAND_PREAUTH: ::c_ulong = 0x00000001;

pub const IW_EV_LCP_PK_LEN: usize = 4;

pub const IW_EV_CHAR_PK_LEN: usize = IW_EV_LCP_PK_LEN + ::IFNAMSIZ;
pub const IW_EV_POINT_PK_LEN: usize = IW_EV_LCP_PK_LEN + 4;
pub const IW_EV_CHAR_PK_LEN: usize = 20; // IW_EV_LCP_PK_LEN + ::IFNAMSIZ;
pub const IW_EV_UINT_PK_LEN: usize = 8; // IW_EV_LCP_PK_LEN + ::mem::size_of::<u32>();
pub const IW_EV_FREQ_PK_LEN: usize = 12; // IW_EV_LCP_PK_LEN + ::mem::size_of::<iw_freq>();
pub const IW_EV_PARAM_PK_LEN: usize = 12; // IW_EV_LCP_PK_LEN + ::mem::size_of::<iw_param>();
pub const IW_EV_ADDR_PK_LEN: usize = 20; // IW_EV_LCP_PK_LEN + ::mem::size_of::<::sockaddr>();
pub const IW_EV_QUAL_PK_LEN: usize = 8; // IW_EV_LCP_PK_LEN + ::mem::size_of::<iw_quality>();
pub const IW_EV_POINT_PK_LEN: usize = 8; // IW_EV_LCP_PK_LEN + 4;

pub const IPTOS_TOS_MASK: u8 = 0x1E;
pub const IPTOS_PREC_MASK: u8 = 0xE0;
Expand Down

0 comments on commit 758a436

Please sign in to comment.