net: openthread: Update OpenThread version

Use the newest version of the OpenThread project, as updated in
https://github.com/zephyrproject-rtos/openthread/pull/2.

Introduce the following fixes along with the update (they're squashed to
retain bisectability of OT samples):

* Update configs and flags used
	Some OT configs were renamed, some new were introduced that Zephyr port
	needs to set.

* Add entropy platform driver
	OpenThreads `random` platform subsystem was replaced with `entropy`
	subsystem which is supposed to serve as an entropy source for the
	generic OpenThread's random generator.

* Halt OT thread when OT command is processed
	OpenThread can currently be processed from two threads - a
	genuine OpenThread thread and shell thread, which processes CLI
	commands. This could cause trouble, when context was switched
	during OT command processing (i.e. switched to process an incomming OT
	message, while still in unfinished command handler).

	In result, it was not possible to turn the commissioner role on via
	CLI, as the commissioner petition response was handled before the
	Commissioner::Start function finished its execution (if the
	petitioner is also the network leader, all messages are passed
	internally within the stack).

	Fix this by suspending the OT thread for the time of an OT command
	processing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2019-10-24 13:15:30 +02:00 committed by Jukka Rissanen
commit 83bb911a21
9 changed files with 107 additions and 59 deletions

View file

@ -30,6 +30,8 @@ struct openthread_context {
struct pkt_list_elem pkt_list[CONFIG_OPENTHREAD_PKT_LIST_SIZE]; struct pkt_list_elem pkt_list[CONFIG_OPENTHREAD_PKT_LIST_SIZE];
}; };
k_tid_t openthread_thread_id_get(void);
#define OPENTHREAD_L2_CTX_TYPE struct openthread_context #define OPENTHREAD_L2_CTX_TYPE struct openthread_context
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -21,6 +21,7 @@ menuconfig NET_L2_OPENTHREAD
select MBEDTLS_CIPHER_AES_ENABLED select MBEDTLS_CIPHER_AES_ENABLED
select MBEDTLS_CIPHER_CCM_ENABLED select MBEDTLS_CIPHER_CCM_ENABLED
select MBEDTLS_MAC_SHA256_ENABLED select MBEDTLS_MAC_SHA256_ENABLED
select MBEDTLS_ENTROPY_ENABLED
if NET_L2_OPENTHREAD if NET_L2_OPENTHREAD
@ -36,7 +37,6 @@ config OPENTHREAD_DTLS
select MBEDTLS_SSL_EXPORT_KEYS select MBEDTLS_SSL_EXPORT_KEYS
select MBEDTLS_CTR_DRBG_ENABLED select MBEDTLS_CTR_DRBG_ENABLED
select MBEDTLS_HMAC_DRBG_ENABLED select MBEDTLS_HMAC_DRBG_ENABLED
select MBEDTLS_ENTROPY_ENABLED
config OPENTHREAD_PLAT config OPENTHREAD_PLAT
bool bool

View file

@ -64,6 +64,11 @@ static struct net_linkaddr *ll_addr;
static struct net_mgmt_event_callback ip6_addr_cb; static struct net_mgmt_event_callback ip6_addr_cb;
k_tid_t openthread_thread_id_get(void)
{
return ot_tid;
}
static void ipv6_addr_event_handler(struct net_mgmt_event_callback *cb, static void ipv6_addr_event_handler(struct net_mgmt_event_callback *cb,
u32_t mgmt_event, struct net_if *iface) u32_t mgmt_event, struct net_if *iface)
{ {
@ -114,12 +119,12 @@ void ot_state_changed_handler(uint32_t flags, void *context)
add_ipv6_addr_to_zephyr(ot_context); add_ipv6_addr_to_zephyr(ot_context);
} }
if (flags & OT_CHANGED_IP6_MULTICAST_UNSUBSRCRIBED) { if (flags & OT_CHANGED_IP6_MULTICAST_UNSUBSCRIBED) {
NET_DBG("Ipv6 multicast address removed"); NET_DBG("Ipv6 multicast address removed");
rm_ipv6_maddr_from_zephyr(ot_context); rm_ipv6_maddr_from_zephyr(ot_context);
} }
if (flags & OT_CHANGED_IP6_MULTICAST_SUBSRCRIBED) { if (flags & OT_CHANGED_IP6_MULTICAST_SUBSCRIBED) {
NET_DBG("Ipv6 multicast address added"); NET_DBG("Ipv6 multicast address added");
add_ipv6_maddr_to_zephyr(ot_context); add_ipv6_maddr_to_zephyr(ot_context);
} }

View file

@ -3,12 +3,12 @@
zephyr_library_named(openthread_platform) zephyr_library_named(openthread_platform)
zephyr_library_sources( zephyr_library_sources(
alarm.c alarm.c
entropy.c
flash.c flash.c
logging.c logging.c
misc.c misc.c
platform.c platform.c
radio.c radio.c
random.c
spi.c spi.c
) )

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <string.h>
#include <drivers/entropy.h>
#include <logging/log.h>
#include <openthread/platform/entropy.h>
#include "platform-zephyr.h"
LOG_MODULE_REGISTER(net_otPlat_entropy, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
#if !defined(CONFIG_ENTROPY_HAS_DRIVER)
#error OpenThread requires an entropy source for a TRNG
#endif
otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
{
/* static to obtain it once in a first call */
static struct device *dev;
int err;
if ((aOutput == NULL) || (aOutputLength == 0)) {
return OT_ERROR_INVALID_ARGS;
}
if (dev == NULL) {
dev = device_get_binding(CONFIG_ENTROPY_NAME);
if (dev == NULL) {
LOG_ERR("Failed to obtain entropy device");
return OT_ERROR_FAILED;
}
}
err = entropy_get_entropy(dev, aOutput, aOutputLength);
if (err != 0) {
LOG_ERR("Failed to obtain entropy, err %d", err);
return OT_ERROR_FAILED;
}
return OT_ERROR_NONE;
}

View file

@ -33,36 +33,42 @@
#define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 2 #define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 2
/** /**
* @def OPENTHREAD_CONFIG_ADDRESS_CACHE_ENTRIES * @def OPENTHREAD_CONFIG_TMF_ADDRESS_CACHE_ENTRIES
* *
* The number of EID-to-RLOC cache entries. * The number of EID-to-RLOC cache entries.
* *
*/ */
#define OPENTHREAD_CONFIG_ADDRESS_CACHE_ENTRIES 20 #define OPENTHREAD_CONFIG_TMF_ADDRESS_CACHE_ENTRIES 20
/** /**
* @def OPENTHREAD_CONFIG_LOG_PREPREND_LEVEL * @def OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL
* *
* Define to prepend the log level to all log messages * Define to prepend the log level to all log messages.
* *
*/ */
#define OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL 0 #define OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL 0
/** /**
* @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT * @def OPENTHREAD_CONFIG_SOFTWARE_ACK_TIMEOUT_ENABLE
* *
* Define to 1 if you want to enable software ACK timeout logic. * Define to 1 to enable software ACK timeout logic.
*
* Applicable only if raw link layer API is enabled
* (i.e., `OPENTHREAD_CONFIG_LINK_RAW_ENABLE` is set).
* *
*/ */
#define OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT 1 #define OPENTHREAD_CONFIG_SOFTWARE_ACK_TIMEOUT_ENABLE 1
/** /**
* @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT * @def OPENTHREAD_CONFIG_SOFTWARE_RETRANSMIT_ENABLE
* *
* Define to 1 if you want to enable software retransmission logic. * Define to 1 to enable software retransmission logic.
*
* Applicable only if raw link layer API is enabled
* (i.e., `OPENTHREAD_CONFIG_LINK_RAW_ENABLE` is set).
* *
*/ */
#define OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT 1 #define OPENTHREAD_CONFIG_SOFTWARE_RETRANSMIT_ENABLE 1
/** /**
* @def SETTINGS_CONFIG_BASE_ADDRESS * @def SETTINGS_CONFIG_BASE_ADDRESS
@ -90,13 +96,13 @@
#define SETTINGS_CONFIG_PAGE_NUM 4 #define SETTINGS_CONFIG_PAGE_NUM 4
/** /**
* @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
* *
* Define to 1 if you want to enable microsecond backoff timer * Define to 1 if you want to enable microsecond backoff timer implemented
* implemented in platform. * in platform.
* *
*/ */
#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER 0 #define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 0
/* Zephyr does not use OpenThreads heap. mbedTLS will use heap memory allocated /* Zephyr does not use OpenThreads heap. mbedTLS will use heap memory allocated
* by Zephyr. Here, we use some dummy values to prevent OpenThread warnings. * by Zephyr. Here, we use some dummy values to prevent OpenThread warnings.
@ -108,7 +114,7 @@
* The size of heap buffer when DTLS is enabled. * The size of heap buffer when DTLS is enabled.
* *
*/ */
#define OPENTHREAD_CONFIG_HEAP_SIZE (4 * sizeof(void *)) #define OPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE (4 * sizeof(void *))
/** /**
* @def OPENTHREAD_CONFIG_HEAP_SIZE_NO_DTLS * @def OPENTHREAD_CONFIG_HEAP_SIZE_NO_DTLS
@ -116,6 +122,24 @@
* The size of heap buffer when DTLS is disabled. * The size of heap buffer when DTLS is disabled.
* *
*/ */
#define OPENTHREAD_CONFIG_HEAP_SIZE_NO_DTLS (4 * sizeof(void *)) #define OPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE_NO_DTLS (4 * sizeof(void *))
/* Disable software srouce address matching. */
/**
* @def RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM
*
* The number of short source address table entries.
*
*/
#define RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM 0
/**
* @def RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
*
* The number of extended source address table entries.
*
*/
#define RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM 0
#endif /* OPENTHREAD_CORE_NRF52840_CONFIG_H_ */ #endif /* OPENTHREAD_CORE_NRF52840_CONFIG_H_ */

View file

@ -1,37 +0,0 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <string.h>
#include <openthread/platform/random.h>
#include "platform-zephyr.h"
uint32_t otPlatRandomGet(void)
{
return sys_rand32_get();
}
otError otPlatRandomGetTrue(u8_t *aOutput, u16_t aOutputLength)
{
int i;
u32_t random;
if (!aOutput) {
return OT_ERROR_INVALID_ARGS;
}
for (i = 0; i < (aOutputLength & 0xFFFC); i += 4) {
random = sys_rand32_get();
memcpy(&aOutput[i], &random, sizeof(random));
}
random = sys_rand32_get();
memcpy(&aOutput[i], &random, aOutputLength & 0x0003);
return OT_ERROR_NONE;
}

View file

@ -6,6 +6,7 @@
#include <kernel.h> #include <kernel.h>
#include <stdio.h> #include <stdio.h>
#include <net/openthread.h>
#include <sys/printk.h> #include <sys/printk.h>
#include <shell/shell.h> #include <shell/shell.h>
#include <shell/shell_uart.h> #include <shell/shell_uart.h>
@ -39,6 +40,7 @@ static int ot_cmd(const struct shell *shell, size_t argc, char *argv[])
char *buf_ptr = rx_buffer; char *buf_ptr = rx_buffer;
size_t buf_len = OT_SHELL_BUFFER_SIZE; size_t buf_len = OT_SHELL_BUFFER_SIZE;
size_t arg_len = 0; size_t arg_len = 0;
k_tid_t ot_tid = openthread_thread_id_get();
int i; int i;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
@ -64,7 +66,13 @@ static int ot_cmd(const struct shell *shell, size_t argc, char *argv[])
} }
shell_p = shell; shell_p = shell;
/* Halt the OpenThread thread execution. This will prevent from being
* rescheduled into the OT thread in the middle of command processing.
*/
k_thread_suspend(ot_tid);
otCliConsoleInputLine(rx_buffer, OT_SHELL_BUFFER_SIZE - buf_len); otCliConsoleInputLine(rx_buffer, OT_SHELL_BUFFER_SIZE - buf_len);
k_thread_resume(ot_tid);
return 0; return 0;
} }
@ -75,4 +83,3 @@ void platformShellInit(otInstance *aInstance)
{ {
otCliConsoleInit(aInstance, otConsoleOutputCallback, NULL); otCliConsoleInit(aInstance, otConsoleOutputCallback, NULL);
} }

View file

@ -89,7 +89,7 @@ manifest:
revision: 9b591b289e1f37339bd038b5a1f0e6c8ad39c63a revision: 9b591b289e1f37339bd038b5a1f0e6c8ad39c63a
path: modules/lib/open-amp path: modules/lib/open-amp
- name: openthread - name: openthread
revision: 3c32244f098f8daf8741efe0a2ad839b67f8567f revision: 882e7074b5986027b85cb4f3ba1dc563a11ca013
path: modules/lib/openthread path: modules/lib/openthread
- name: segger - name: segger
revision: 6fcf61606d6012d2c44129edc033f59331e268bc revision: 6fcf61606d6012d2c44129edc033f59331e268bc