Commit c8469395 authored by Marek Porwisz's avatar Marek Porwisz Committed by Benjamin Cabé
Browse files

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: default avatarMarek Porwisz <marek.porwisz@nordicsemi.no>
parent f7f84f0a
Loading
Loading
Loading
Loading
+16 −16
Changes for modules/openthread/platform/diag.c: 16 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -92,18 +92,25 @@ otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArg
	return OT_ERROR_NOT_IMPLEMENTED;
}

void otPlatDiagModeSet(bool aMode)
static void log_error_returned(otError error, const char *name)
{
	otError error;
	if (error != OT_ERROR_NONE) {
		otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
			  "%s failed (%d)", name, error);
	}
}

void otPlatDiagModeSet(bool aMode)
{
	sDiagMode = aMode;

	if (!sDiagMode) {
		error = otPlatRadioSleep(NULL);
		if (error != OT_ERROR_NONE) {
			otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
				  "%s failed (%d)", "otPlatRadioSleep", error);
		if (OT_RADIO_STATE_TRANSMIT == otPlatRadioGetState(NULL)) {
			log_error_returned(otPlatRadioReceive(NULL, sChannel),
					   "otPlatRadioReceive");
		}

		log_error_returned(otPlatRadioSleep(NULL), "otPlatRadioSleep");
	}
}

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

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

			error = otPlatRadioTransmit(aInstance, txPacket);
			if (error != OT_ERROR_NONE) {
				otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
					  "%s failed (%d)", "otPlatRadioTransmit", error);
			}
			log_error_returned(otPlatRadioTransmit(aInstance, txPacket),
					"otPlatRadioTransmit");

			if (sTxCount != -1) {
				sTxCount--;
@@ -421,10 +424,7 @@ static otError processTransmit(otInstance *aInstance, uint8_t aArgsLength, char
		diag_output("diagnostic message transmission is stopped\r\n");
		sTransmitMode = DIAG_TRANSMIT_MODE_IDLE;
		error = otPlatRadioReceive(aInstance, sChannel);
		if (error != OT_ERROR_NONE) {
			otPlatLog(OT_LOG_LEVEL_WARN, OT_LOG_REGION_PLATFORM,
				  "%s failed (%d)", "otPlatRadioReceive", error);
		}
		log_error_returned(error, "otPlatRadioReceive");
	} else if (strcmp(aArgs[0], "start") == 0) {
		if (sTransmitMode != DIAG_TRANSMIT_MODE_IDLE) {
			return OT_ERROR_INVALID_STATE;
+4 −0
Changes for modules/openthread/platform/radio.c: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -811,6 +811,10 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
	radio_api->start(radio_dev);
	sState = OT_RADIO_STATE_RECEIVE;

	if (is_pending_event_set(PENDING_EVENT_TX_DONE)) {
		reset_pending_event(PENDING_EVENT_TX_DONE);
	}

	return OT_ERROR_NONE;
}