Skip to content

Commit

Permalink
WPA2 ENTERPRISE
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ committed Aug 30, 2024
1 parent 533288d commit 935c11c
Show file tree
Hide file tree
Showing 22 changed files with 966 additions and 897 deletions.
2 changes: 1 addition & 1 deletion esp-ieee802154/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ byte = "0.2.7"
critical-section = "1.1.3"
document-features = "0.2.10"
esp-hal = { version = "0.20.0", path = "../esp-hal" }
esp-wifi-sys = "0.4.0"
esp-wifi-sys = "0.5.0"
heapless = "0.8.0"
ieee802154 = "0.6.1"
log = "0.4.22"
Expand Down
116 changes: 7 additions & 109 deletions esp-ieee802154/src/compat/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#[cfg(feature = "binary-logs")]
mod str_buf;

#[cfg(feature = "binary-logs")]
mod binary_logs {
use core::{ffi::VaListImpl, fmt::Write};

use log::info;

use super::str_buf::StrBuf;
extern "C" {
fn vsnprintf(dst: *mut u8, _n: u32, format: *const u8, ...) -> i32;
}

#[no_mangle]
pub unsafe extern "C" fn phy_printf(_format: *const u8, _args: ...) {
Expand All @@ -29,109 +26,10 @@ mod binary_logs {
pub unsafe extern "C" fn syslog(format: *const u8, args: VaListImpl) {
let mut buf = [0u8; 512];
vsnprintf(&mut buf as *mut u8, 511, format, args);
let res_str = StrBuf::from(&buf as *const u8);
info!("{}", res_str.as_str_ref());
}

pub(crate) unsafe fn vsnprintf(
dst: *mut u8,
_n: u32,
format: *const u8,
mut args: VaListImpl,
) -> i32 {
let fmt_str_ptr = format;

let mut res_str = StrBuf::new();

let strbuf = StrBuf::from(fmt_str_ptr);
let s = strbuf.as_str_ref();

let mut format_char = ' ';
let mut is_long = false;
let mut found = false;
for c in s.chars() {
if !found {
if c == '%' {
found = true;
}

if !found {
res_str.append_char(c);
}
} else if c.is_numeric() || c == '-' || c == 'l' {
if c == 'l' {
is_long = true;
}
// ignore
} else {
// a format char
format_char = c;
}

if found && format_char != ' ' {
// have to format an arg
match format_char {
'd' => {
if is_long {
let v = args.arg::<i64>();
write!(res_str, "{}", v).ok();
} else {
let v = args.arg::<i32>();
write!(res_str, "{}", v).ok();
}
}

'u' => {
let v = args.arg::<u32>();
write!(res_str, "{}", v).ok();
}

'p' => {
let v = args.arg::<u32>();
write!(res_str, "0x{:x}", v).ok();
}

'X' => {
let v = args.arg::<u32>();
write!(res_str, "{:02x}", (v & 0xff000000) >> 24).ok();
}

'x' => {
let v = args.arg::<u32>();
write!(res_str, "{:02x}", v).ok();
}

's' => {
let v = args.arg::<u32>() as *const u8;
let vbuf = StrBuf::from(v);
write!(res_str, "{}", vbuf.as_str_ref()).ok();
}

'c' => {
let v = args.arg::<u8>();
if v != 0 {
write!(res_str, "{}", v as char).ok();
}
}

_ => {
write!(res_str, "<UNKNOWN{}>", format_char).ok();
}
}

format_char = ' ';
found = false;
is_long = false;
}
}
let mut idx = 0;
res_str.as_str_ref().chars().for_each(|c| {
*(dst.offset(idx)) = c as u8;
idx += 1;
});
*(dst.offset(idx)) = 0;

idx as i32
let res_str = core::ffi::CStr::from_ptr(core::ptr::addr_of!(buf).cast())
.to_str()
.unwrap();
info!("{}", res_str);
}
}

Expand Down
58 changes: 0 additions & 58 deletions esp-ieee802154/src/compat/str_buf.rs

This file was deleted.

2 changes: 1 addition & 1 deletion esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ heapless = { version = "0.8.0", default-features = false, features = [
num-derive = { version = "0.4.2" }
num-traits = { version = "0.2.19", default-features = false }
no-std-net = { version = "0.6.0", optional = true }
esp-wifi-sys = { version = "0.4.0" }
esp-wifi-sys = { version = "0.5.0" }
embassy-sync = { version = "0.6.0", optional = true }
embassy-futures = { version = "0.1.1", optional = true }
embassy-net-driver = { version = "0.2.0", optional = true }
Expand Down
24 changes: 9 additions & 15 deletions esp-wifi/src/ble/btdm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
HciOutCollector,
HCI_OUT_COLLECTOR,
},
compat::{common::str_from_c, queue::SimpleQueue, task_runner::spawn_task},
compat::{common::str_from_c, queue::SimpleQueue},
hal::macros::ram,
memory_fence::memory_fence,
timer::yield_task,
Expand Down Expand Up @@ -305,21 +305,15 @@ unsafe extern "C" fn task_create(
core_id
);

*(handle as *mut usize) = 0; // we will run it in task 0
let task_func = core::mem::transmute::<
*mut crate::binary::c_types::c_void,
extern "C" fn(*mut esp_wifi_sys::c_types::c_void),
>(func);

if spawn_task(
func,
name as *const i8,
stack_depth,
param,
prio,
handle,
core_id,
) {
1
} else {
0
}
let task = crate::preempt::arch_specific::task_create(task_func, param, stack_depth as usize);
*(handle as *mut usize) = task as usize;

1
}

unsafe extern "C" fn task_delete(_task: *const ()) {
Expand Down
32 changes: 14 additions & 18 deletions esp-wifi/src/ble/npl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
include::*,
},
compat,
compat::{common::str_from_c, queue::SimpleQueue, task_runner::spawn_task},
compat::{common::str_from_c, queue::SimpleQueue},
timer::yield_task,
};

Expand Down Expand Up @@ -294,10 +294,10 @@ pub struct ext_funcs_t {
hal_uart_init: Option<unsafe extern "C" fn(i32, *const c_void) -> i32>,
task_create: Option<
unsafe extern "C" fn(
*const c_void,
*mut c_void,
*const c_char,
u32,
*const c_void,
*mut c_void,
u32,
*const c_void,
u32,
Expand Down Expand Up @@ -352,10 +352,10 @@ unsafe extern "C" fn os_random() -> u32 {
}

unsafe extern "C" fn task_create(
task_func: *const c_void,
task_func: *mut c_void,
name: *const c_char,
stack_depth: u32,
param: *const c_void,
param: *mut c_void,
prio: u32,
task_handle: *const c_void,
core_id: u32,
Expand All @@ -374,19 +374,15 @@ unsafe extern "C" fn task_create(

*(task_handle as *mut usize) = 0; // we will run it in task 0

if spawn_task(
task_func as *mut c_void,
name as *const c_char,
stack_depth,
param as *mut c_void,
prio,
task_handle as *mut c_void,
core_id,
) {
1
} else {
0
}
let task_func = core::mem::transmute::<
*mut crate::binary::c_types::c_void,
extern "C" fn(*mut esp_wifi_sys::c_types::c_void),
>(task_func);

let task = crate::preempt::arch_specific::task_create(task_func, param, stack_depth as usize);
*(task_handle as *mut usize) = task as usize;

1
}

unsafe extern "C" fn task_delete(_: *const c_void) {
Expand Down
51 changes: 4 additions & 47 deletions esp-wifi/src/common_adapter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ptr::addr_of;

use esp_wifi_sys::include::timespec;
use esp_wifi_sys::include::timeval;
use hal::{macros::ram, rng::Rng};

use crate::{
Expand Down Expand Up @@ -219,48 +219,8 @@ pub unsafe extern "C" fn puts(s: *const u8) {
info!("{}", cstr);
}

#[cfg(any(feature = "wifi-logs", nightly))]
#[no_mangle]
pub unsafe extern "C" fn sprintf(dst: *mut u8, format: *const u8, args: ...) -> i32 {
let str = str_from_c(format);
trace!("sprintf format: {}", str);

let len = crate::compat::syslog::vsnprintf(dst, 512, format, args);

let s = str_from_c(dst);
trace!("sprintf result: {}", s);

len
}

#[cfg(all(not(feature = "wifi-logs"), not(nightly)))]
#[no_mangle]
pub unsafe extern "C" fn sprintf(dst: *mut u8, format: *const u8, _args: *const ()) -> i32 {
let str = str_from_c(format);

let res = match str {
"ESP_%02X%02X%02X" => "ESP_0000",
"%d,%s,%s,%s" => "????",
"unknown id:%d" => "unknown id:??",
_ => {
warn!("Unexpected call to `sprintf`: {}", str);
"???"
}
};

dst.copy_from_nonoverlapping(res.as_ptr(), res.len());
dst.add(res.len()).write_volatile(0);

res.len() as i32
}

#[cfg(feature = "wifi-logs")]
mod log {
#[no_mangle]
pub unsafe extern "C" fn printf(s: *const u8, args: ...) {
crate::compat::syslog::syslog(0, s, args);
}

#[no_mangle]
pub unsafe extern "C" fn rtc_printf(s: *const u8, args: ...) {
crate::compat::syslog::syslog(0, s, args);
Expand Down Expand Up @@ -289,9 +249,6 @@ mod log {

#[cfg(not(feature = "wifi-logs"))]
mod log {
#[no_mangle]
pub unsafe extern "C" fn printf(_s: *const u8, _args: *const ()) {}

#[no_mangle]
pub unsafe extern "C" fn rtc_printf(_s: *const u8, _args: *const ()) {}

Expand Down Expand Up @@ -380,12 +337,12 @@ pub unsafe extern "C" fn ets_timer_arm_us(
}

#[no_mangle]
pub unsafe extern "C" fn gettimeofday(tv: *mut timespec, _tz: *mut ()) -> i32 {
pub unsafe extern "C" fn gettimeofday(tv: *mut timeval, _tz: *mut ()) -> i32 {
if !tv.is_null() {
unsafe {
let microseconds = esp_timer_get_time();
(*tv).tv_sec = (microseconds / 1_000_000) as i32;
(*tv).tv_nsec = (microseconds % 1_000_000) as i32 * 1000;
(*tv).tv_sec = (microseconds / 1_000_000) as u64;
(*tv).tv_usec = (microseconds % 1_000_000) as u32;
}
}

Expand Down
Loading

0 comments on commit 935c11c

Please sign in to comment.