Skip to content

Commit c846939

Browse files
MarekPorwiszkartben
authored andcommitted
net: openthread: Fix exiting diag when transmission is ongoing
Crash was observed if "diag stop" was invoked during the transmission. The issue was caused by an update to otPlatRadioSleep that made it compilant with the documentation and not allowing direct Transmit 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 f7f84f0 commit c846939

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-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 error, const char *name)
9696
{
97-
otError error;
97+
if (error != OT_ERROR_NONE) {
98+
otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
99+
"%s failed (%d)", name, error);
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,10 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
811811
radio_api->start(radio_dev);
812812
sState = OT_RADIO_STATE_RECEIVE;
813813

814+
if (is_pending_event_set(PENDING_EVENT_TX_DONE)) {
815+
reset_pending_event(PENDING_EVENT_TX_DONE);
816+
}
817+
814818
return OT_ERROR_NONE;
815819
}
816820

0 commit comments

Comments
 (0)