diff --git a/src/ncp/ncp_base_radio.cpp b/src/ncp/ncp_base_radio.cpp index 6fb67b8d0..9eb87fcb1 100644 --- a/src/ncp/ncp_base_radio.cpp +++ b/src/ncp/ncp_base_radio.cpp @@ -195,10 +195,17 @@ void NcpBase::LinkRawTransmitDone(uint8_t aIid, otRadioFrame *aFrame, otRadioFra uint8_t keyIndex; uint32_t frameCounter; - // Transmit frame auxiliary key index and frame counter - SuccessOrExit(static_cast(aFrame)->GetKeyIndex(keyIndex)); SuccessOrExit(static_cast(aFrame)->GetFrameCounter(frameCounter)); + // If the frame uses Key ID Mode 0, there is no Key Index field in + // the Security Header, so `GetKeyIndex()` may return an error. + // We default `keyIndex` to 0 in this case. + + if (static_cast(aFrame)->GetKeyIndex(keyIndex) != OT_ERROR_NONE) + { + keyIndex = 0; + } + SuccessOrExit(mEncoder.WriteUint8(keyIndex)); SuccessOrExit(mEncoder.WriteUint32(frameCounter)); }