Skip to content

Commit

Permalink
Cleanup logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ committed Feb 27, 2024
1 parent be90de7 commit 9371d7d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bleps/src/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl AclPacket {
);

let len = u16::from_le_bytes([connector.read().unwrap(), connector.read().unwrap()]);
log::info!("read len {}", len);
log::debug!("read len {}", len);
let data = Data::read(connector, len as usize);

Self {
Expand Down
2 changes: 0 additions & 2 deletions bleps/src/att.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::convert::TryInto;

use crate::{l2cap::L2capPacket, Data};

pub const ATT_READ_BY_GROUP_TYPE_REQUEST_OPCODE: u8 = 0x10;
Expand Down
6 changes: 3 additions & 3 deletions bleps/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a> Command<'a> {
pub fn encode(self) -> Data {
match self {
Command::Reset => {
log::info!("encode reset command");
log::debug!("encode reset command");
let mut data = [0u8; 4];
data[0] = 0x01;
CommandHeader::from_ogf_ocf(CONTROLLER_OGF, RESET_OCF, 0x00)
Expand Down Expand Up @@ -155,15 +155,15 @@ impl<'a> Command<'a> {
Data::new(&data)
}
Command::ReadBrAddr => {
log::info!("command read br addr");
log::debug!("command read br addr");
let mut data = [0u8; 4];
data[0] = 0x01;
CommandHeader::from_ogf_ocf(INFORMATIONAL_OGF, READ_BD_ADDR_OCF, 0x00)
.write_into(&mut data[1..]);
Data::new(&data)
}
Command::SetEventMask { events } => {
log::info!("command set event mask");
log::debug!("command set event mask");
let mut data = [0u8; 12];
data[0] = 0x01;
CommandHeader::from_ogf_ocf(CONTROLLER_OGF, SET_EVENT_MASK_OCF, 0x08)
Expand Down
2 changes: 1 addition & 1 deletion bleps/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::Addr;

use cmac::digest;
use p256::{ecdh, elliptic_curve::rand_core};
use p256::ecdh;
use rand_core::CryptoRng;
use rand_core::RngCore;

Expand Down
14 changes: 7 additions & 7 deletions bleps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,17 @@ impl<'a> Ble<'a> {
where
Self: Sized,
{
log::info!("before, key = {:x}, hanlde = {:x}", ltk, handle);
log::trace!("before, key = {:x}, hanlde = {:x}", ltk, handle);
self.write_bytes(
Command::LeLongTermKeyRequestReply { handle, ltk }
.encode()
.as_slice(),
);
log::info!("done writing command");
log::trace!("done writing command");
let res = self
.wait_for_command_complete(LE_OGF, LONG_TERM_KEY_REQUEST_REPLY_OCF)?
.check_command_completed();
log::info!("got completion event");
log::trace!("got completion event");

res
}
Expand Down Expand Up @@ -374,7 +374,7 @@ impl<'a> Ble<'a> {
loop {
let res = self.poll();
if res.is_some() {
log::info!("polled while waiting {:?}", res);
log::debug!("polled while waiting {:?}", res);
}

match res {
Expand Down Expand Up @@ -642,19 +642,19 @@ pub mod asynch {
where
Self: Sized,
{
log::info!("before, key = {:x}, hanlde = {:x}", ltk, handle);
log::trace!("before, key = {:x}, handle = {:x}", ltk, handle);
self.write_bytes(
Command::LeLongTermKeyRequestReply { handle, ltk }
.encode()
.as_slice(),
)
.await;
log::info!("done writing command");
log::trace!("done writing command");
let res = self
.wait_for_command_complete(LE_OGF, LONG_TERM_KEY_REQUEST_REPLY_OCF)
.await?
.check_command_completed();
log::info!("got completion event");
log::trace!("got completion event");

res
}
Expand Down
29 changes: 10 additions & 19 deletions bleps/src/sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a, B, R> SYNC SecurityManager<'a, B, R> where B: BleWriter, R: CryptoRng +
impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R: CryptoRng + RngCore
{
pub(crate) async fn handle(&mut self, ble: &mut B, src_handle: u16, payload: crate::Data, pin_callback: &mut Option<&mut dyn FnMut(u32)>) -> Result<(), AttributeServerError> {
log::info!("SM packet {:02x?}", payload.as_slice());
log::debug!("SM packet {:02x?}", payload.as_slice());

let data = &payload.as_slice()[1..];
let command = payload.as_slice()[0];
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R:

async fn handle_pairing_request(&mut self, ble: &mut B, src_handle: u16, data: &[u8]) {
self.ioa = Some(IoCap::new(data[2], data[1] != 0, data[0]));
log::info!("got pairing request");
log::debug!("got pairing request");

let mut data = Data::new(&[SM_PAIRING_RESPONSE]);
data.append_value(IoCapability::DisplayYesNo as u8);
Expand All @@ -252,9 +252,9 @@ impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R:
}

async fn handle_pairing_public_key(&mut self, ble: &mut B, src_handle: u16, pka: &[u8]) -> Result<(), AttributeServerError> {
log::info!("got public key");
log::debug!("got public key");

log::info!("key len = {} {:02x?}", pka.len(), pka);
log::debug!("key len = {} {:02x?}", pka.len(), pka);
let pka = PublicKey::from_bytes(pka);

// Send the local public key before validating the remote key to allow
Expand Down Expand Up @@ -302,7 +302,7 @@ impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R:
}

async fn handle_pairing_random(&mut self, ble: &mut B, src_handle: u16, random: &[u8], pin_callback: &mut Option<&mut dyn FnMut(u32)>) -> Result<(), AttributeServerError> {
log::info!("got pairing random {:02x?}", random);
log::debug!("got pairing random {:02x?}", random);

if *&(self.nb).is_none() {
self.report_error(ble, src_handle, SecurityManagerError::UnspecifiedReason).await;
Expand Down Expand Up @@ -355,8 +355,8 @@ impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R:
let a = self.peer_address.unwrap();
let b = self.local_address.unwrap();
let ra = 0;
log::info!("a = {:02x?}", a.0);
log::info!("b = {:02x?}", b.0);
log::trace!("a = {:02x?}", a.0);
log::trace!("b = {:02x?}", b.0);

let io_cap = IoCapability::DisplayYesNo as u8;
let iob = IoCap::new(make_auth_req().0, false, io_cap);
Expand All @@ -373,7 +373,7 @@ impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R:
}

async fn handle_pairing_dhkey_check(&mut self, ble: &mut B, src_handle: u16, ea: &[u8]) -> Result<(), AttributeServerError> {
log::info!("got dhkey_check {:02x?}", ea);
log::debug!("got dhkey_check {:02x?}", ea);

if *&(self.na).is_none() {
self.report_error(ble, src_handle, SecurityManagerError::UnspecifiedReason).await;
Expand Down Expand Up @@ -426,19 +426,10 @@ impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R:
}

async fn write_sm(&self, ble: &mut B, handle: u16, data: Data) {
// Workaround! For unknown reasons this is currently necessary
// Needs to get solved in the underlying esp-wifi implementation
static mut DUMMY: u32 = 0;
unsafe {
for _ in 0..1_000_000 {
(&mut DUMMY as *mut u32).write_volatile(0);
}
}

log::debug!("data {:x?}", data.as_slice());

let res = L2capPacket::encode_sm(data);
log::info!("encoded_l2cap {:x?}", res.as_slice());
log::trace!("encoded_l2cap {:x?}", res.as_slice());

let res = AclPacket::encode(
handle,
Expand All @@ -447,7 +438,7 @@ impl<'a, B, R> ASYNC AsyncSecurityManager<'a, B, R> where B: AsyncBleWriter, R:
res,
);

log::info!("writing {:02x?}", res.as_slice());
log::debug!("writing {:02x?}", res.as_slice());
ble.write_bytes(res.as_slice()).await;
}

Expand Down

0 comments on commit 9371d7d

Please sign in to comment.