diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-01 04:21:06 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-01 04:21:06 +0000 |
commit | 3bc98df66715fee142a67dda43f7186574b24550 (patch) | |
tree | 823188d70d1a0ddb965f2adcef56166e83b69232 | |
parent | 9a851d086738c05456c689c26901f0daba171174 (diff) | |
parent | e52af41550862775dfc3372daacf12873ce5eb8b (diff) | |
download | openthread-android14-mainline-wifi-release.tar.gz |
Snap for 11164065 from e52af41550862775dfc3372daacf12873ce5eb8b to mainline-wifi-releaseaml_wif_341410080android14-mainline-wifi-release
Change-Id: Ibb1ab52c432d301a169e15500d3c757197f46e85
-rw-r--r-- | Android.bp | 6 | ||||
-rw-r--r-- | TEST_MAPPING | 7 | ||||
-rw-r--r-- | include/openthread/link.h | 33 | ||||
-rw-r--r-- | include/openthread/platform/radio.h | 3 | ||||
-rw-r--r-- | src/android/openthread-android-config.h | 5 | ||||
-rw-r--r-- | src/android/ot-cli-ftd.rc | 4 | ||||
-rw-r--r-- | src/cli/cli.cpp | 8 | ||||
-rw-r--r-- | src/core/api/link_api.cpp | 21 | ||||
-rw-r--r-- | src/core/mac/mac.cpp | 19 | ||||
-rw-r--r-- | src/core/mac/mac.hpp | 30 | ||||
-rw-r--r-- | src/core/meshcop/dataset_manager.cpp | 9 | ||||
-rw-r--r-- | src/core/radio/radio.hpp | 30 | ||||
-rw-r--r-- | src/core/thread/mle.cpp | 12 | ||||
-rw-r--r-- | tests/scripts/expect/posix-channel-mask.exp | 34 |
14 files changed, 201 insertions, 20 deletions
diff --git a/Android.bp b/Android.bp index c5d672f92..47695073f 100644 --- a/Android.bp +++ b/Android.bp @@ -397,6 +397,7 @@ filegroup { "examples/platforms/simulation/uart.c", "examples/platforms/utils/link_metrics.cpp", "examples/platforms/utils/mac_frame.cpp", + "examples/platforms/utils/settings_ram.c", "examples/platforms/utils/soft_source_match_table.c", ], } @@ -660,9 +661,11 @@ cc_defaults { "-DOPENTHREAD_CONFIG_MLR_ENABLE=1", "-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1", "-DOPENTHREAD_CONFIG_PING_SENDER_ENABLE=1", + "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=0", "-DOPENTHREAD_EXAMPLES_SIMULATION=1", "-DOPENTHREAD_CONFIG_TCP_ENABLE=0", "-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"examples/platforms/simulation/openthread-core-simulation-config.h\"", + "-DOPENTHREAD_SETTINGS_RAM=1", "-DPACKAGE=\"openthread\"", "-DPACKAGE_BUGREPORT=\"openthread-devel@googlegroups.com\"", "-DPACKAGE_NAME=\"OPENTHREAD\"", @@ -994,7 +997,4 @@ cc_binary { shared_libs: [ "libcutils", // Required by src/core/instance_api.cpp ], - - init_rc: ["src/android/ot-cli-ftd.rc"], - vendor: true, } diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 000000000..9bafe2943 --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "imports": [ + { + "path": "external/ot-br-posix" + } + ] +} diff --git a/include/openthread/link.h b/include/openthread/link.h index d48d5d498..f4d203e72 100644 --- a/include/openthread/link.h +++ b/include/openthread/link.h @@ -1183,6 +1183,39 @@ bool otLinkIsCslSupported(otInstance *aInstance); otError otLinkSendEmptyData(otInstance *aInstance); /** + * Sets the region code. + * + * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code. + * + * @param[in] aInstance The OpenThread instance structure. + * @param[in] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char + * and the `aRegionCode & 0xff` is the second ascii char. + * + * @retval OT_ERROR_FAILED Other platform specific errors. + * @retval OT_ERROR_NONE Successfully set region code. + * @retval OT_ERROR_NOT_IMPLEMENTED The feature is not implemented. + * + */ +otError otLinkSetRegion(otInstance *aInstance, uint16_t aRegionCode); + +/** + * Get the region code. + * + * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code. + + * @param[in] aInstance The OpenThread instance structure. + * @param[out] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char + * and the `aRegionCode & 0xff` is the second ascii char. + * + * @retval OT_ERROR_INVALID_ARGS @p aRegionCode is nullptr. + * @retval OT_ERROR_FAILED Other platform specific errors. + * @retval OT_ERROR_NONE Successfully got region code. + * @retval OT_ERROR_NOT_IMPLEMENTED The feature is not implemented. + * + */ +otError otLinkGetRegion(otInstance *aInstance, uint16_t *aRegionCode); + +/** * @} * */ diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index d11549e07..7f39d9832 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -1186,7 +1186,8 @@ otError otPlatRadioSetChannelMaxTransmitPower(otInstance *aInstance, uint8_t aCh * ISO 3166 alpha-2 code. * * @param[in] aInstance The OpenThread instance structure. - * @param[in] aRegionCode The radio region. + * @param[in] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char + * and the `aRegionCode & 0xff` is the second ascii char. * * @retval OT_ERROR_FAILED Other platform specific errors. * @retval OT_ERROR_NONE Successfully set region code. diff --git a/src/android/openthread-android-config.h b/src/android/openthread-android-config.h index 2aa291565..e61482d3a 100644 --- a/src/android/openthread-android-config.h +++ b/src/android/openthread-android-config.h @@ -45,10 +45,9 @@ #define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 3500 /** - * Disables the default posix infrastructure interface implementation - * so that we can can use the Android specific implementation. + * Enables the default posix infrastructure interface implementation. */ -#define OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE 0 +#define OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE 1 /** * Disables the default posix TUN interface implementation diff --git a/src/android/ot-cli-ftd.rc b/src/android/ot-cli-ftd.rc deleted file mode 100644 index 57d2d299d..000000000 --- a/src/android/ot-cli-ftd.rc +++ /dev/null @@ -1,4 +0,0 @@ -# The settings data directory for simulation `ot-cli-ftd` program -on post-fs-data - mkdir /data/vendor/threadnetwork 0770 root root - mkdir /data/vendor/threadnetwork/simulation 0770 root root diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index e2c66ae77..9c329178e 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -6658,7 +6658,7 @@ exit: * Done * @endcode * @par api_copy - * #otPlatRadioGetRegion + * #otLinkGetRegion */ template <> otError Interpreter::Process<Cmd("region")>(Arg aArgs[]) { @@ -6667,7 +6667,7 @@ template <> otError Interpreter::Process<Cmd("region")>(Arg aArgs[]) if (aArgs[0].IsEmpty()) { - SuccessOrExit(error = otPlatRadioGetRegion(GetInstancePtr(), ®ionCode)); + SuccessOrExit(error = otLinkGetRegion(GetInstancePtr(), ®ionCode)); OutputLine("%c%c", regionCode >> 8, regionCode & 0xff); } /** @@ -6677,7 +6677,7 @@ template <> otError Interpreter::Process<Cmd("region")>(Arg aArgs[]) * Done * @endcode * @par api_copy - * #otPlatRadioSetRegion + * #otLinkSetRegion * @par * Changing this can affect the transmit power limit. */ @@ -6688,7 +6688,7 @@ template <> otError Interpreter::Process<Cmd("region")>(Arg aArgs[]) regionCode = static_cast<uint16_t>(static_cast<uint16_t>(aArgs[0].GetCString()[0]) << 8) + static_cast<uint16_t>(aArgs[0].GetCString()[1]); - error = otPlatRadioSetRegion(GetInstancePtr(), regionCode); + error = otLinkSetRegion(GetInstancePtr(), regionCode); } exit: diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index f342627a9..95ec35c42 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -460,3 +460,24 @@ otError otLinkSendEmptyData(otInstance *aInstance) return AsCoreType(aInstance).Get<MeshForwarder>().SendEmptyMessage(); } #endif + +otError otLinkSetRegion(otInstance *aInstance, uint16_t aRegionCode) +{ + return AsCoreType(aInstance).Get<Mac::Mac>().SetRegion(aRegionCode); +} + +otError otLinkGetRegion(otInstance *aInstance, uint16_t *aRegionCode) +{ + Error error; + + if (aRegionCode == nullptr) + { + error = kErrorInvalidArgs; + } + else + { + error = AsCoreType(aInstance).Get<Mac::Mac>().GetRegion(*aRegionCode); + } + + return error; +} diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index aa13d3a96..314085147 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -187,7 +187,7 @@ void Mac::Scan(Operation aScanOperation, uint32_t aScanChannels, uint16_t aScanD if (aScanChannels == 0) { - aScanChannels = GetSupportedChannelMask().GetMask(); + aScanChannels = mSupportedChannelMask.GetMask(); } mScanChannelMask.SetMask(aScanChannels); @@ -474,7 +474,7 @@ void Mac::SetSupportedChannelMask(const ChannelMask &aMask) { ChannelMask newMask = aMask; - newMask.Intersect(ChannelMask(Get<Radio>().GetSupportedChannelMask())); + newMask.Intersect(mSupportedChannelMask); IgnoreError(Get<Notifier>().Update(mSupportedChannelMask, newMask, kEventSupportedChannelMaskChanged)); } @@ -2105,6 +2105,21 @@ void Mac::SetPromiscuous(bool aPromiscuous) UpdateIdleMode(); } +Error Mac::SetRegion(uint16_t aRegionCode) +{ + Error error; + ChannelMask oldMask = mSupportedChannelMask; + + SuccessOrExit(error = Get<Radio>().SetRegion(aRegionCode)); + mSupportedChannelMask.SetMask(Get<Radio>().GetSupportedChannelMask()); + IgnoreError(Get<Notifier>().Update(oldMask, mSupportedChannelMask, kEventSupportedChannelMaskChanged)); + +exit: + return error; +} + +Error Mac::GetRegion(uint16_t &aRegionCode) const { return Get<Radio>().GetRegion(aRegionCode); } + #if OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE const uint32_t *Mac::GetDirectRetrySuccessHistogram(uint8_t &aNumberOfEntries) { diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index e14d436c8..1b2ae6c67 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -720,6 +720,36 @@ public: bool IsRadioFilterEnabled(void) const { return mLinks.GetSubMac().IsRadioFilterEnabled(); } #endif + /** + * Sets the region code. + * + * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code. + * + * @param[in] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char + * and the `aRegionCode & 0xff` is the second ascii char. + * + * @retval kErrorFailed Other platform specific errors. + * @retval kErrorNone Successfully set region code. + * @retval kErrorNotImplemented The feature is not implemented. + * + */ + Error SetRegion(uint16_t aRegionCode); + + /** + * Get the region code. + * + * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code. + * + * @param[out] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char + * and the `aRegionCode & 0xff` is the second ascii char. + * + * @retval kErrorFailed Other platform specific errors. + * @retval kErrorNone Successfully set region code. + * @retval kErrorNotImplemented The feature is not implemented. + * + */ + Error GetRegion(uint16_t &aRegionCode) const; + private: static constexpr uint16_t kMaxCcaSampleCount = OPENTHREAD_CONFIG_CCA_FAILURE_RATE_AVERAGING_WINDOW; diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 043f88c2a..e236fcc57 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -312,15 +312,18 @@ void DatasetManager::HandleMgmtSetResponse(Coap::Message *aMessage, const Ip6::M OT_UNUSED_VARIABLE(aMessageInfo); Error error; - uint8_t state; + uint8_t state = StateTlv::kPending; SuccessOrExit(error = aError); VerifyOrExit(Tlv::Find<StateTlv>(*aMessage, state) == kErrorNone && state != StateTlv::kPending, error = kErrorParse); + if (state == StateTlv::kReject) + { + error = kErrorRejected; + } exit: - LogInfo("MGMT_SET finished: %s", - error == kErrorNone ? StateTlv::StateToString(static_cast<StateTlv::State>(state)) : ErrorToString(error)); + LogInfo("MGMT_SET finished: %s", error == kErrorNone ? "Accepted" : ErrorToString(error)); mMgmtPending = false; diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index a8d36a1a5..892e57919 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -733,6 +733,36 @@ public: ((kChannelMin == aCslChannel) || ((kChannelMin < aCslChannel) && (aCslChannel <= kChannelMax)))); } + /** + * Sets the region code. + * + * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code. + * + * @param[in] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char + * and the `aRegionCode & 0xff` is the second ascii char. + * + * @retval kErrorFailed Other platform specific errors. + * @retval kErrorNone Successfully set region code. + * @retval kErrorNotImplemented The feature is not implemented. + * + */ + Error SetRegion(uint16_t aRegionCode) { return otPlatRadioSetRegion(GetInstancePtr(), aRegionCode); } + + /** + * Get the region code. + * + * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code. + * + * @param[out] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char + * and the `aRegionCode & 0xff` is the second ascii char. + * + * @retval kErrorFailed Other platform specific errors. + * @retval kErrorNone Successfully set region code. + * @retval kErrorNotImplemented The feature is not implemented. + * + */ + Error GetRegion(uint16_t &aRegionCode) const { return otPlatRadioGetRegion(GetInstancePtr(), &aRegionCode); } + private: otInstance *GetInstancePtr(void) const { return reinterpret_cast<otInstance *>(&InstanceLocator::GetInstance()); } diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index fa67446df..fb5bcda08 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1251,6 +1251,18 @@ void Mle::HandleNotifierEvents(Events aEvents) } #endif + if (aEvents.Contains(kEventSupportedChannelMaskChanged)) + { + Mac::ChannelMask channelMask = Get<Mac::Mac>().GetSupportedChannelMask(); + + if (!channelMask.ContainsChannel(Get<Mac::Mac>().GetPanChannel()) && (mRole != kRoleDisabled)) + { + LogWarn("Channel %u is not in the supported channel mask %s, detach the network gracefully!", + Get<Mac::Mac>().GetPanChannel(), channelMask.ToString().AsCString()); + IgnoreError(DetachGracefully(nullptr, nullptr)); + } + } + exit: return; } diff --git a/tests/scripts/expect/posix-channel-mask.exp b/tests/scripts/expect/posix-channel-mask.exp index 6e387d802..d754feaa4 100644 --- a/tests/scripts/expect/posix-channel-mask.exp +++ b/tests/scripts/expect/posix-channel-mask.exp @@ -61,4 +61,38 @@ send "channel preferred\n" expect "0x1fff800" expect_line "Done" +send "region US\n" +expect_line "Done" + +send "channel supported\n" +expect "0x7fff800" +expect_line "Done" + +send "dataset init new\n" +expect_line "Done" +send "dataset channel 26\n" +expect_line "Done" +send "dataset commit active\n" +expect_line "Done" + +attach "leader" + +send "channel\n" +expect "26" +expect_line "Done" + +send "region WW\n" +expect_line "Done" + +wait_for "state" "disabled" +expect_line "Done" + +send "channel supported\n" +expect "0x3fff800" +expect_line "Done" + +send "channel\n" +expect "26" +expect_line "Done" + dispose_node 1 |