diff --git a/openthread/src/lib.rs b/openthread/src/lib.rs index c556cb9..0e7e33d 100644 --- a/openthread/src/lib.rs +++ b/openthread/src/lib.rs @@ -77,7 +77,7 @@ use sys::{ otOperationalDataset, otOperationalDatasetTlvs, otPlatAlarmMilliFired, otPlatRadioReceiveDone, otPlatRadioTxDone, otPlatRadioTxStarted, otRadioCaps, otRadioFrame, otSetStateChangedCallback, otTaskletsArePending, otTaskletsProcess, otThreadGetDeviceRole, otThreadGetExtendedPanId, - otThreadSetEnabled, OT_RADIO_CAPS_ACK_TIMEOUT, OT_RADIO_FRAME_MAX_SIZE, + otThreadGetLinkMode, otThreadSetEnabled, OT_RADIO_CAPS_ACK_TIMEOUT, OT_RADIO_FRAME_MAX_SIZE, }; /// A newtype wrapper over the native OpenThread error type (`otError`). @@ -1394,7 +1394,13 @@ impl<'a> OtContext<'a> { fn plat_changed(&mut self, _flags: u32) { trace!("Plat changed callback"); - self.state().ot.changes.signal(()); + + let state = self.state(); + + let rx_on_when_idle = unsafe { otThreadGetLinkMode(state.ot.instance) }.mRxOnWhenIdle(); + Self::update_rx_when_idle(state, rx_on_when_idle); + + state.ot.changes.signal(()); } fn plat_now(&mut self) -> u32 { @@ -1506,6 +1512,25 @@ impl<'a> OtContext<'a> { } } + fn plat_radio_set_rx_on_when_idle(&mut self, rx_on_when_idle: bool) { + info!( + "Plat radio set rx_on_when_idle callback, rx_on_when_idle: {}", + rx_on_when_idle + ); + + Self::update_rx_when_idle(self.state(), rx_on_when_idle); + } + + fn update_rx_when_idle(state: &mut OtActiveState<'_>, rx_on_when_idle: bool) { + if state.ot.radio_conf.rx_when_idle != rx_on_when_idle { + info!( + "Updating rx_when_idle: {} -> {}", + state.ot.radio_conf.rx_when_idle, rx_on_when_idle + ); + state.ot.radio_conf.rx_when_idle = rx_on_when_idle; + } + } + fn plat_radio_set_extended_address(&mut self, address: u64) { info!( "Plat radio set extended address callback, addr: 0x{:08x}", diff --git a/openthread/src/platform.rs b/openthread/src/platform.rs index 7a38fb8..be10344 100644 --- a/openthread/src/platform.rs +++ b/openthread/src/platform.rs @@ -105,6 +105,11 @@ extern "C" fn otPlatRadioSetPromiscuous(instance: *const otInstance, enable: boo OtContext::callback(instance).plat_radio_set_promiscuous(enable) } +#[no_mangle] +extern "C" fn otPlatRadioSetRxOnWhenIdle(instance: *mut otInstance, enable: bool) { + OtContext::callback(instance).plat_radio_set_rx_on_when_idle(enable) +} + #[no_mangle] extern "C" fn otPlatRadioGetRssi(instance: *const otInstance) -> i8 { OtContext::callback(instance).plat_radio_get_rssi()