Skip to content

Avoid overwriting HCI buffer until sent #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions esp-wifi/src/ble/btdm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::{cell::RefCell, ptr::addr_of};

use critical_section::Mutex;
use portable_atomic::{AtomicBool, Ordering};

use crate::ble::btdm::ble_os_adapter_chip_specific::{osi_funcs_s, G_OSI_FUNCS};
use crate::ble::HciOutCollector;
Expand Down Expand Up @@ -31,6 +32,8 @@ pub struct ReceivedPacket {
static BT_INTERNAL_QUEUE: Mutex<RefCell<SimpleQueue<[u8; 8], 10>>> =
Mutex::new(RefCell::new(SimpleQueue::new()));

static PACKET_SENT: AtomicBool = AtomicBool::new(true);

#[repr(C)]
struct vhci_host_callback_s {
notify_host_send_available: extern "C" fn(), /* callback used to notify that the host can send packet to controller */
Expand Down Expand Up @@ -64,6 +67,8 @@ static VHCI_HOST_CALLBACK: vhci_host_callback_s = vhci_host_callback_s {

extern "C" fn notify_host_send_available() {
trace!("notify_host_send_available");

PACKET_SENT.store(true, Ordering::Relaxed);
}

extern "C" fn notify_host_recv(data: *mut u8, len: u16) -> i32 {
Expand Down Expand Up @@ -581,13 +586,17 @@ pub fn send_hci(data: &[u8]) {
continue;
}

PACKET_SENT.store(false, Ordering::Relaxed);
API_vhci_host_send_packet(packet.as_ptr() as *const u8, packet.len() as u16);
trace!("sent vhci host packet");

dump_packet_info(packet);

break;
}

// make sure the packet buffer doesn't get touched until sent
while !PACKET_SENT.load(Ordering::Relaxed) {}
}

hci_out.reset();
Expand Down