Skip to content

Commit a64ed1e

Browse files
author
Marek Porwisz
committed
diag: Fix exiting diag when transmission is ongoing
Crash was observed if "diag stop" was invoked during the transmission. The issue was sacused by an update to otPlatRadioSleep that made it compilant with the documentation and not allowing direct Transmeet to sleep transition. The transmission result was forwarded to OpenThread making it crash due to an invalid state. Signed-off-by: Marek Porwisz <[email protected]>
1 parent 7d913ca commit a64ed1e

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

modules/openthread/platform/diag.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,25 @@ otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArg
9292
return OT_ERROR_NOT_IMPLEMENTED;
9393
}
9494

95-
void otPlatDiagModeSet(bool aMode)
95+
static void log_error_returned(otError aError, const char * aName)
9696
{
97-
otError error;
97+
if (aError != OT_ERROR_NONE) {
98+
otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
99+
"%s failed (%d)", aName, aError);
100+
}
101+
}
98102

103+
void otPlatDiagModeSet(bool aMode)
104+
{
99105
sDiagMode = aMode;
100106

101107
if (!sDiagMode) {
102-
error = otPlatRadioSleep(NULL);
103-
if (error != OT_ERROR_NONE) {
104-
otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
105-
"%s failed (%d)", "otPlatRadioSleep", error);
108+
if(OT_RADIO_STATE_TRANSMIT == otPlatRadioGetState(NULL)) {
109+
log_error_returned(otPlatRadioReceive(NULL, sChannel),
110+
"otPlatRadioReceive");
106111
}
112+
113+
log_error_returned(otPlatRadioSleep(NULL), "otPlatRadioSleep");
107114
}
108115
}
109116

@@ -355,7 +362,6 @@ static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char
355362
void otPlatDiagAlarmCallback(otInstance *aInstance)
356363
{
357364
uint32_t now;
358-
otError error;
359365
otRadioFrame *txPacket;
360366
const uint16_t diag_packet_len = 30;
361367

@@ -381,11 +387,8 @@ void otPlatDiagAlarmCallback(otInstance *aInstance)
381387
txPacket->mPsdu[i] = i;
382388
}
383389

384-
error = otPlatRadioTransmit(aInstance, txPacket);
385-
if (error != OT_ERROR_NONE) {
386-
otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
387-
"%s failed (%d)", "otPlatRadioTransmit", error);
388-
}
390+
log_error_returned(otPlatRadioTransmit(aInstance, txPacket),
391+
"otPlatRadioTransmit");
389392

390393
if (sTxCount != -1) {
391394
sTxCount--;
@@ -421,10 +424,7 @@ static otError processTransmit(otInstance *aInstance, uint8_t aArgsLength, char
421424
diag_output("diagnostic message transmission is stopped\r\n");
422425
sTransmitMode = DIAG_TRANSMIT_MODE_IDLE;
423426
error = otPlatRadioReceive(aInstance, sChannel);
424-
if (error != OT_ERROR_NONE) {
425-
otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
426-
"%s failed (%d)", "otPlatRadioReceive", error);
427-
}
427+
log_error_returned(error, "otPlatRadioReceive");
428428
} else if (strcmp(aArgs[0], "start") == 0) {
429429
if (sTransmitMode != DIAG_TRANSMIT_MODE_IDLE) {
430430
return OT_ERROR_INVALID_STATE;

modules/openthread/platform/radio.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
809809
radio_api->start(radio_dev);
810810
sState = OT_RADIO_STATE_RECEIVE;
811811

812+
if(is_pending_event_set(PENDING_EVENT_TX_DONE))
813+
{
814+
reset_pending_event(PENDING_EVENT_TX_DONE);
815+
}
816+
812817
return OT_ERROR_NONE;
813818
}
814819

0 commit comments

Comments
 (0)