Skip to content

Commit

Permalink
added wireless struct and constants to Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brijeshkrishna committed Jan 22, 2024
1 parent 40741ba commit 0196b92
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4369,7 +4369,11 @@ fn test_linux(target: &str) {
// the `ifc_ifcu` field is an anonymous union
(struct_ == "ifconf" && field == "ifc_ifcu") ||
// glibc uses a single array `uregs` instead of individual fields.
(struct_ == "user_regs" && arm)
(struct_ == "user_regs" && arm) ||
// the `ifr_ifrn` field is an anonymous union
(struct_ == "iwreq" && field == "ifr_ifrn") ||
// the `key` field is a zero-sized array
(struct_ == "iw_encode_ext" && field == "key")
});

cfg.skip_roundtrip(move |s| match s {
Expand Down
23 changes: 23 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,8 @@ IW_ENC_CAPA_WPA2
IW_ENC_CAPA_CIPHER_TKIP
IW_ENC_CAPA_CIPHER_CCMP
IW_ENC_CAPA_4WAY_HANDSHAKE
IW_EVENT_CAPA_K_0
IW_EVENT_CAPA_K_1
IW_PMKSA_ADD
IW_PMKSA_REMOVE
IW_PMKSA_FLUSH
Expand All @@ -2752,6 +2754,11 @@ IW_PMKID_CAND_PREAUTH
IW_EV_CHAR_PK_LEN
IW_EV_LCP_PK_LEN
IW_EV_POINT_PK_LEN
IW_EV_UINT_PK_LEN
IW_EV_FREQ_PK_LEN
IW_EV_PARAM_PK_LEN
IW_EV_ADDR_PK_LEN
IW_EV_QUAL_PK_LEN
SI_LOAD_SHIFT
SND_CNT
SND_MAX
Expand Down Expand Up @@ -3595,6 +3602,22 @@ ip_mreqn
ip_mreq_source
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
iwreq
iwreq_data
iw_scan_req
iw_statistics
j1939_filter
jrand48
key_t
Expand Down
247 changes: 245 additions & 2 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,153 @@ s! {
pub salt: [::c_uchar; TLS_CIPHER_CHACHA20_POLY1305_SALT_SIZE],
pub rec_seq: [::c_uchar; TLS_CIPHER_CHACHA20_POLY1305_REC_SEQ_SIZE],
}

// 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! {
if #[cfg(not(target_arch = "sparc64"))] {
s!{
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 @@ -1048,6 +1193,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 @@ -1546,6 +1730,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 @@ -3457,6 +3692,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 @@ -3467,8 +3705,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 0196b92

Please sign in to comment.