Skip to content

Commit c9fea62

Browse files
Przemyslaw Bidarlubos
authored andcommitted
[nrf fromtree] net: openthread: Add modcarrier command to OT diag module.
Commit add `modcarrier` shell command for Openthread diagnostic mode. Command can transmit modulated carrier out of device for test purposes. Signed-off-by: Przemyslaw Bida <[email protected]> (cherry picked from commit 63e1bb4)
1 parent 3ac6a88 commit c9fea62

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

drivers/ieee802154/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ config IEEE802154_SELECTIVE_TXCHANNEL
102102

103103
config IEEE802154_CARRIER_FUNCTIONS
104104
bool "Support for carrier functions"
105+
default y if OPENTHREAD_DIAG
105106
help
106107
Enable support for functions such as modulated carrier and continuous carrier.
107108

modules/openthread/Kconfig.features

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ config OPENTHREAD_DHCP6_SERVER
136136

137137
config OPENTHREAD_DIAG
138138
bool "Diagnostic functions support"
139-
depends on IEEE802154_CARRIER_FUNCTIONS
140139
help
141140
Enable OpenThread CLI diagnostic commands
142141

modules/openthread/platform/diag.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/drivers/gpio.h>
99

10+
#include <openthread/error.h>
1011
#include <openthread/platform/diag.h>
1112

1213
#include "platform-zephyr.h"
14+
#include "zephyr/sys/util.h"
1315

1416
/**
1517
* Diagnostics mode variables.
@@ -19,6 +21,8 @@ static bool sDiagMode;
1921
static void *sDiagCallbackContext;
2022
static otPlatDiagOutputCallback sDiagOutputCallback;
2123

24+
static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]);
25+
2226
static void diag_output(const char *aFormat, ...)
2327
{
2428
va_list args;
@@ -47,6 +51,12 @@ otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArg
4751
ARG_UNUSED(aInstance);
4852
ARG_UNUSED(aArgsLength);
4953

54+
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
55+
if (strcmp(aArgs[0], "modcarrier") == 0) {
56+
return startModCarrier(aInstance, aArgsLength - 1, aArgs + 1);
57+
}
58+
#endif
59+
5060
/* Add more platform specific diagnostics features here. */
5161
diag_output("diag feature '%s' is not supported\r\n", aArgs[0]);
5262

@@ -276,3 +286,30 @@ otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode)
276286
#endif /* DT_HAS_COMPAT_STATUS_OKAY(openthread_config) && \
277287
* DT_NODE_HAS_PROP(DT_COMPAT_GET_ANY_STATUS_OKAY(openthread_config), diag_gpios)
278288
*/
289+
290+
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
291+
292+
static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
293+
{
294+
ARG_UNUSED(aInstance);
295+
ARG_UNUSED(aArgsLength);
296+
297+
bool enable = true;
298+
uint8_t data[OT_RADIO_FRAME_MAX_SIZE + 1];
299+
300+
if (aArgsLength <= 0) {
301+
return OT_ERROR_INVALID_ARGS;
302+
}
303+
304+
if (strcmp(aArgs[0], "stop") == 0) {
305+
enable = false;
306+
} else {
307+
if (hex2bin(aArgs[0], strlen(aArgs[0]), data, ARRAY_SIZE(data)) == 0) {
308+
return OT_ERROR_INVALID_ARGS;
309+
}
310+
}
311+
312+
return platformRadioTransmitModulatedCarrier(aInstance, enable, data);
313+
}
314+
315+
#endif

modules/openthread/platform/platform-zephyr.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,20 @@ uint16_t platformRadioChannelGet(otInstance *aInstance);
7777
otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable);
7878
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */
7979

80+
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
81+
/**
82+
* Start/stop modulated carrier wave transmission.
83+
*/
84+
otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnable,
85+
const uint8_t *aData);
86+
#endif
87+
8088
/**
8189
* This function initializes the random number service used by OpenThread.
8290
*
8391
*/
8492
void platformRandomInit(void);
8593

86-
8794
/**
8895
* Initialize platform Shell driver.
8996
*/

modules/openthread/platform/radio.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
*/
1313

14+
#include <openthread/error.h>
1415
#define LOG_MODULE_NAME net_otPlat_radio
1516

1617
#include <zephyr/logging/log.h>
@@ -832,6 +833,34 @@ otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable)
832833

833834
return OT_ERROR_NONE;
834835
}
836+
837+
otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnable,
838+
const uint8_t *aData)
839+
{
840+
if (radio_api->modulated_carrier == NULL) {
841+
return OT_ERROR_NOT_IMPLEMENTED;
842+
}
843+
844+
if (aEnable && sState == OT_RADIO_STATE_RECEIVE) {
845+
if (aData == NULL) {
846+
return OT_ERROR_INVALID_ARGS;
847+
}
848+
849+
radio_api->set_txpower(radio_dev, get_transmit_power_for_channel(channel));
850+
851+
if (radio_api->modulated_carrier(radio_dev, aData) != 0) {
852+
return OT_ERROR_FAILED;
853+
}
854+
sState = OT_RADIO_STATE_TRANSMIT;
855+
} else if ((!aEnable) && sState == OT_RADIO_STATE_TRANSMIT) {
856+
return otPlatRadioReceive(aInstance, channel);
857+
} else {
858+
return OT_ERROR_INVALID_STATE;
859+
}
860+
861+
return OT_ERROR_NONE;
862+
}
863+
835864
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */
836865

837866
otRadioState otPlatRadioGetState(otInstance *aInstance)

0 commit comments

Comments
 (0)