Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016-2017, The OpenThread Authors. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * 3. Neither the name of the copyright holder nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * @file |
| 30 | * This file implements minimal thread device required Spinel interface to the OpenThread stack. |
| 31 | */ |
| 32 | |
Jonathan Hui | 512d233 | 2019-07-12 14:57:15 -0700 | [diff] [blame] | 33 | #include "openthread-core-config.h" |
Yakun Xu | 96ed7cc | 2018-04-17 00:28:00 +0800 | [diff] [blame] | 34 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 35 | #include "ncp_base.hpp" |
| 36 | |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 37 | #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 38 | #include <openthread/border_router.h> |
| 39 | #endif |
Jonathan Hui | 01ebc18 | 2019-07-12 15:21:49 -0700 | [diff] [blame] | 40 | #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 41 | #include <openthread/channel_monitor.h> |
| 42 | #endif |
Jonathan Hui | aa82391 | 2019-07-15 12:03:36 -0700 | [diff] [blame] | 43 | #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE |
Abtin Keshavarzian | 1ca81fb | 2018-08-02 15:21:11 -0700 | [diff] [blame] | 44 | #include <openthread/child_supervision.h> |
| 45 | #endif |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 46 | #include <openthread/diag.h> |
| 47 | #include <openthread/icmp6.h> |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 48 | #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 49 | #include <openthread/jam_detection.h> |
| 50 | #endif |
| 51 | #include <openthread/ncp.h> |
Jonathan Hui | 926b9e8 | 2019-07-15 21:16:37 -0700 | [diff] [blame] | 52 | #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE |
Shu Chen | e69019f | 2018-06-27 02:46:32 +0800 | [diff] [blame] | 53 | #include <openthread/network_time.h> |
| 54 | #endif |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 55 | #include <openthread/platform/misc.h> |
| 56 | #include <openthread/platform/radio.h> |
| 57 | #if OPENTHREAD_FTD |
| 58 | #include <openthread/thread_ftd.h> |
| 59 | #endif |
Jonathan Hui | 149640d | 2019-07-16 11:06:03 -0700 | [diff] [blame] | 60 | #if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 61 | #include <openthread/server.h> |
| 62 | #endif |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 63 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 64 | #include "common/code_utils.hpp" |
| 65 | #include "common/debug.hpp" |
Abtin Keshavarzian | 02c876e | 2017-11-13 08:27:57 -0800 | [diff] [blame] | 66 | #include "common/instance.hpp" |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 67 | #include "net/ip6.hpp" |
| 68 | |
| 69 | #if OPENTHREAD_MTD || OPENTHREAD_FTD |
| 70 | |
| 71 | namespace ot { |
| 72 | namespace Ncp { |
| 73 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 74 | static uint8_t BorderRouterConfigToFlagByte(const otBorderRouterConfig &aConfig) |
| 75 | { |
| 76 | uint8_t flags(0); |
| 77 | |
| 78 | if (aConfig.mPreferred) |
| 79 | { |
| 80 | flags |= SPINEL_NET_FLAG_PREFERRED; |
| 81 | } |
| 82 | |
| 83 | if (aConfig.mSlaac) |
| 84 | { |
| 85 | flags |= SPINEL_NET_FLAG_SLAAC; |
| 86 | } |
| 87 | |
| 88 | if (aConfig.mDhcp) |
| 89 | { |
| 90 | flags |= SPINEL_NET_FLAG_DHCP; |
| 91 | } |
| 92 | |
| 93 | if (aConfig.mDefaultRoute) |
| 94 | { |
| 95 | flags |= SPINEL_NET_FLAG_DEFAULT_ROUTE; |
| 96 | } |
| 97 | |
| 98 | if (aConfig.mConfigure) |
| 99 | { |
| 100 | flags |= SPINEL_NET_FLAG_CONFIGURE; |
| 101 | } |
| 102 | |
| 103 | if (aConfig.mOnMesh) |
| 104 | { |
| 105 | flags |= SPINEL_NET_FLAG_ON_MESH; |
| 106 | } |
| 107 | |
Jonathan Hui | 70cb48f | 2019-01-28 08:39:02 -0800 | [diff] [blame] | 108 | flags |= (static_cast<uint8_t>(aConfig.mPreference) << SPINEL_NET_FLAG_PREFERENCE_OFFSET); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 109 | |
| 110 | return flags; |
| 111 | } |
| 112 | |
| 113 | static uint8_t ExternalRoutePreferenceToFlagByte(int aPreference) |
| 114 | { |
| 115 | uint8_t flags; |
| 116 | |
| 117 | switch (aPreference) |
| 118 | { |
| 119 | case OT_ROUTE_PREFERENCE_LOW: |
| 120 | flags = SPINEL_ROUTE_PREFERENCE_LOW; |
| 121 | break; |
| 122 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 123 | case OT_ROUTE_PREFERENCE_HIGH: |
| 124 | flags = SPINEL_ROUTE_PREFERENCE_HIGH; |
| 125 | break; |
| 126 | |
Yakun Xu | 26694be | 2020-01-23 02:18:54 +0800 | [diff] [blame] | 127 | case OT_ROUTE_PREFERENCE_MED: |
| 128 | // fall through |
| 129 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 130 | default: |
| 131 | flags = SPINEL_ROUTE_PREFERENCE_MEDIUM; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | return flags; |
| 136 | } |
| 137 | |
| 138 | uint8_t NcpBase::LinkFlagsToFlagByte(bool aRxOnWhenIdle, bool aSecureDataRequests, bool aDeviceType, bool aNetworkData) |
| 139 | { |
| 140 | uint8_t flags(0); |
| 141 | |
| 142 | if (aRxOnWhenIdle) |
| 143 | { |
| 144 | flags |= SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE; |
| 145 | } |
| 146 | |
| 147 | if (aSecureDataRequests) |
| 148 | { |
| 149 | flags |= SPINEL_THREAD_MODE_SECURE_DATA_REQUEST; |
| 150 | } |
| 151 | |
| 152 | if (aDeviceType) |
| 153 | { |
Jonathan Hui | 5a48983 | 2018-09-27 09:33:03 -0700 | [diff] [blame] | 154 | flags |= SPINEL_THREAD_MODE_FULL_THREAD_DEV; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | if (aNetworkData) |
| 158 | { |
| 159 | flags |= SPINEL_THREAD_MODE_FULL_NETWORK_DATA; |
| 160 | } |
| 161 | |
| 162 | return flags; |
| 163 | } |
| 164 | |
Abtin Keshavarzian | a1b2d35 | 2019-05-19 00:05:21 -0700 | [diff] [blame] | 165 | otError NcpBase::EncodeNeighborInfo(const otNeighborInfo &aNeighborInfo) |
| 166 | { |
| 167 | otError error; |
| 168 | uint8_t modeFlags; |
| 169 | |
| 170 | modeFlags = LinkFlagsToFlagByte(aNeighborInfo.mRxOnWhenIdle, aNeighborInfo.mSecureDataRequest, |
| 171 | aNeighborInfo.mFullThreadDevice, aNeighborInfo.mFullNetworkData); |
| 172 | |
| 173 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 174 | |
| 175 | SuccessOrExit(error = mEncoder.WriteEui64(aNeighborInfo.mExtAddress)); |
| 176 | SuccessOrExit(error = mEncoder.WriteUint16(aNeighborInfo.mRloc16)); |
| 177 | SuccessOrExit(error = mEncoder.WriteUint32(aNeighborInfo.mAge)); |
| 178 | SuccessOrExit(error = mEncoder.WriteUint8(aNeighborInfo.mLinkQualityIn)); |
| 179 | SuccessOrExit(error = mEncoder.WriteInt8(aNeighborInfo.mAverageRssi)); |
| 180 | SuccessOrExit(error = mEncoder.WriteUint8(modeFlags)); |
| 181 | SuccessOrExit(error = mEncoder.WriteBool(aNeighborInfo.mIsChild)); |
| 182 | SuccessOrExit(error = mEncoder.WriteUint32(aNeighborInfo.mLinkFrameCounter)); |
| 183 | SuccessOrExit(error = mEncoder.WriteUint32(aNeighborInfo.mMleFrameCounter)); |
| 184 | SuccessOrExit(error = mEncoder.WriteInt8(aNeighborInfo.mLastRssi)); |
| 185 | |
| 186 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 187 | |
| 188 | exit: |
| 189 | return error; |
| 190 | } |
| 191 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 192 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_DATA_POLL_PERIOD>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 193 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 194 | return mEncoder.WriteUint32(otLinkGetPollPeriod(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 195 | } |
| 196 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 197 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MAC_DATA_POLL_PERIOD>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 198 | { |
| 199 | uint32_t pollPeriod; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 200 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 201 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 202 | SuccessOrExit(error = mDecoder.ReadUint32(pollPeriod)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 203 | |
rongli | 3282398 | 2018-12-28 14:35:57 +0800 | [diff] [blame] | 204 | error = otLinkSetPollPeriod(mInstance, pollPeriod); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 205 | |
| 206 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 207 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 208 | } |
| 209 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 210 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_EXTENDED_ADDR>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 211 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 212 | return mEncoder.WriteEui64(*otLinkGetExtendedAddress(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 213 | } |
| 214 | |
Rafał Kuźnia | 5a7e190 | 2019-10-29 17:04:26 +0100 | [diff] [blame] | 215 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_MAX_RETRY_NUMBER_DIRECT>(void) |
| 216 | { |
| 217 | return mEncoder.WriteUint8(otLinkGetMaxFrameRetriesDirect(mInstance)); |
| 218 | } |
| 219 | |
| 220 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MAC_MAX_RETRY_NUMBER_DIRECT>(void) |
| 221 | { |
| 222 | uint8_t maxFrameRetriesDirect; |
| 223 | otError error = OT_ERROR_NONE; |
| 224 | |
| 225 | SuccessOrExit(error = mDecoder.ReadUint8(maxFrameRetriesDirect)); |
| 226 | otLinkSetMaxFrameRetriesDirect(mInstance, maxFrameRetriesDirect); |
| 227 | |
| 228 | exit: |
| 229 | return error; |
| 230 | } |
| 231 | |
Abtin Keshavarzian | 31698ec | 2018-07-02 08:43:45 -0700 | [diff] [blame] | 232 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_PHY_CHAN_SUPPORTED>(void) |
| 233 | { |
| 234 | uint32_t newMask = 0; |
| 235 | otError error = OT_ERROR_NONE; |
| 236 | |
| 237 | SuccessOrExit(error = DecodeChannelMask(newMask)); |
| 238 | error = otLinkSetSupportedChannelMask(mInstance, newMask); |
| 239 | |
| 240 | exit: |
| 241 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 242 | } |
| 243 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 244 | otError NcpBase::CommandHandler_NET_CLEAR(uint8_t aHeader) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 245 | { |
Abtin Keshavarzian | 9ce57b2 | 2017-12-05 18:33:53 -0800 | [diff] [blame] | 246 | return PrepareLastStatusResponse(aHeader, ThreadErrorToSpinelStatus(otInstanceErasePersistentInfo(mInstance))); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 249 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_SAVED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 250 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 251 | return mEncoder.WriteBool(otDatasetIsCommissioned(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 252 | } |
| 253 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 254 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_IF_UP>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 255 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 256 | return mEncoder.WriteBool(otIp6IsEnabled(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 257 | } |
| 258 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 259 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_IF_UP>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 260 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 261 | bool enabled = false; |
| 262 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 263 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 264 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 265 | |
| 266 | error = otIp6SetEnabled(mInstance, enabled); |
| 267 | |
| 268 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 269 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 270 | } |
| 271 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 272 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_STACK_UP>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 273 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 274 | return mEncoder.WriteBool(otThreadGetDeviceRole(mInstance) != OT_DEVICE_ROLE_DISABLED); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 275 | } |
| 276 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 277 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_STACK_UP>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 278 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 279 | bool enabled = false; |
| 280 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 281 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 282 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 283 | |
| 284 | // If the value has changed... |
| 285 | if ((enabled != false) != (otThreadGetDeviceRole(mInstance) != OT_DEVICE_ROLE_DISABLED)) |
| 286 | { |
| 287 | if (enabled != false) |
| 288 | { |
| 289 | error = otThreadSetEnabled(mInstance, true); |
Abtin Keshavarzian | ecd2845 | 2018-04-05 10:20:47 -0700 | [diff] [blame] | 290 | StartLegacy(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 291 | } |
| 292 | else |
| 293 | { |
| 294 | error = otThreadSetEnabled(mInstance, false); |
Abtin Keshavarzian | ecd2845 | 2018-04-05 10:20:47 -0700 | [diff] [blame] | 295 | StopLegacy(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 300 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 301 | } |
| 302 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 303 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_ROLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 304 | { |
| 305 | spinel_net_role_t role(SPINEL_NET_ROLE_DETACHED); |
| 306 | |
| 307 | switch (otThreadGetDeviceRole(mInstance)) |
| 308 | { |
| 309 | case OT_DEVICE_ROLE_DISABLED: |
| 310 | case OT_DEVICE_ROLE_DETACHED: |
| 311 | role = SPINEL_NET_ROLE_DETACHED; |
| 312 | break; |
| 313 | |
| 314 | case OT_DEVICE_ROLE_CHILD: |
| 315 | role = SPINEL_NET_ROLE_CHILD; |
| 316 | break; |
| 317 | |
| 318 | case OT_DEVICE_ROLE_ROUTER: |
| 319 | role = SPINEL_NET_ROLE_ROUTER; |
| 320 | break; |
| 321 | |
| 322 | case OT_DEVICE_ROLE_LEADER: |
| 323 | role = SPINEL_NET_ROLE_LEADER; |
| 324 | break; |
| 325 | } |
| 326 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 327 | return mEncoder.WriteUint8(role); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 328 | } |
| 329 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 330 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_ROLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 331 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 332 | unsigned int role = 0; |
| 333 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 334 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 335 | SuccessOrExit(error = mDecoder.ReadUintPacked(role)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 336 | |
| 337 | switch (role) |
| 338 | { |
| 339 | case SPINEL_NET_ROLE_DETACHED: |
| 340 | error = otThreadBecomeDetached(mInstance); |
| 341 | break; |
| 342 | |
| 343 | #if OPENTHREAD_FTD |
| 344 | case SPINEL_NET_ROLE_ROUTER: |
| 345 | error = otThreadBecomeRouter(mInstance); |
| 346 | break; |
| 347 | |
| 348 | case SPINEL_NET_ROLE_LEADER: |
| 349 | error = otThreadBecomeLeader(mInstance); |
| 350 | break; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 351 | #endif // OPENTHREAD_FTD |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 352 | |
| 353 | case SPINEL_NET_ROLE_CHILD: |
| 354 | error = otThreadBecomeChild(mInstance); |
| 355 | break; |
| 356 | } |
| 357 | |
| 358 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 359 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 360 | } |
| 361 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 362 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_NETWORK_NAME>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 363 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 364 | return mEncoder.WriteUtf8(otThreadGetNetworkName(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 365 | } |
| 366 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 367 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_NETWORK_NAME>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 368 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 369 | const char *string = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 370 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 371 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 372 | SuccessOrExit(mDecoder.ReadUtf8(string)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 373 | |
| 374 | error = otThreadSetNetworkName(mInstance, string); |
| 375 | |
| 376 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 377 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 378 | } |
| 379 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 380 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_XPANID>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 381 | { |
Jonathan Hui | 9201973 | 2018-08-15 10:12:49 -0700 | [diff] [blame] | 382 | return mEncoder.WriteData(otThreadGetExtendedPanId(mInstance)->m8, sizeof(spinel_net_xpanid_t)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 383 | } |
| 384 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 385 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_XPANID>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 386 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 387 | const uint8_t *ptr = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 388 | uint16_t len; |
| 389 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 390 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 391 | SuccessOrExit(error = mDecoder.ReadData(ptr, len)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 392 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 393 | VerifyOrExit(len == sizeof(spinel_net_xpanid_t), error = OT_ERROR_PARSE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 394 | |
Jonathan Hui | 9201973 | 2018-08-15 10:12:49 -0700 | [diff] [blame] | 395 | error = otThreadSetExtendedPanId(mInstance, reinterpret_cast<const otExtendedPanId *>(ptr)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 396 | |
| 397 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 398 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 399 | } |
| 400 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 401 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_MASTER_KEY>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 402 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 403 | return mEncoder.WriteData(otThreadGetMasterKey(mInstance)->m8, OT_MASTER_KEY_SIZE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 404 | } |
| 405 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 406 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_MASTER_KEY>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 407 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 408 | const uint8_t *ptr = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 409 | uint16_t len; |
| 410 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 411 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 412 | SuccessOrExit(error = mDecoder.ReadData(ptr, len)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 413 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 414 | VerifyOrExit(len == OT_MASTER_KEY_SIZE, error = OT_ERROR_PARSE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 415 | |
| 416 | error = otThreadSetMasterKey(mInstance, reinterpret_cast<const otMasterKey *>(ptr)); |
| 417 | |
| 418 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 419 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 420 | } |
| 421 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 422 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 423 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 424 | return mEncoder.WriteUint32(otThreadGetKeySequenceCounter(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 425 | } |
| 426 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 427 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 428 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 429 | uint32_t keySeqCounter; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 430 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 431 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 432 | SuccessOrExit(error = mDecoder.ReadUint32(keySeqCounter)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 433 | |
| 434 | otThreadSetKeySequenceCounter(mInstance, keySeqCounter); |
| 435 | |
| 436 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 437 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 438 | } |
| 439 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 440 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_PARTITION_ID>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 441 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 442 | return mEncoder.WriteUint32(otThreadGetPartitionId(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 443 | } |
| 444 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 445 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_KEY_SWITCH_GUARDTIME>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 446 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 447 | return mEncoder.WriteUint32(otThreadGetKeySwitchGuardTime(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 448 | } |
| 449 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 450 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_KEY_SWITCH_GUARDTIME>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 451 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 452 | uint32_t keyGuardTime; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 453 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 454 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 455 | SuccessOrExit(error = mDecoder.ReadUint32(keyGuardTime)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 456 | |
| 457 | otThreadSetKeySwitchGuardTime(mInstance, keyGuardTime); |
| 458 | |
| 459 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 460 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 461 | } |
| 462 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 463 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_NETWORK_DATA_VERSION>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 464 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 465 | return mEncoder.WriteUint8(otNetDataGetVersion(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 466 | } |
| 467 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 468 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_STABLE_NETWORK_DATA_VERSION>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 469 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 470 | return mEncoder.WriteUint8(otNetDataGetStableVersion(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 471 | } |
| 472 | |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 473 | #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 474 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_NETWORK_DATA>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 475 | { |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 476 | uint8_t networkData[255]; |
| 477 | uint8_t networkDataLen = 255; |
| 478 | |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 479 | IgnoreError(otBorderRouterGetNetData(mInstance, |
| 480 | false, // Stable? |
| 481 | networkData, &networkDataLen)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 482 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 483 | return mEncoder.WriteData(networkData, networkDataLen); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 484 | } |
| 485 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 486 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_STABLE_NETWORK_DATA>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 487 | { |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 488 | uint8_t networkData[255]; |
| 489 | uint8_t networkDataLen = 255; |
| 490 | |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 491 | IgnoreError(otBorderRouterGetNetData(mInstance, |
| 492 | true, // Stable? |
| 493 | networkData, &networkDataLen)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 494 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 495 | return mEncoder.WriteData(networkData, networkDataLen); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 496 | } |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 497 | #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 498 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 499 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_LEADER_NETWORK_DATA>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 500 | { |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 501 | uint8_t networkData[255]; |
| 502 | uint8_t networkDataLen = 255; |
| 503 | |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 504 | IgnoreError(otNetDataGet(mInstance, |
| 505 | false, // Stable? |
| 506 | networkData, &networkDataLen)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 507 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 508 | return mEncoder.WriteData(networkData, networkDataLen); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 509 | } |
| 510 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 511 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_STABLE_LEADER_NETWORK_DATA>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 512 | { |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 513 | uint8_t networkData[255]; |
| 514 | uint8_t networkDataLen = 255; |
| 515 | |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 516 | IgnoreError(otNetDataGet(mInstance, |
| 517 | true, // Stable? |
| 518 | networkData, &networkDataLen)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 519 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 520 | return mEncoder.WriteData(networkData, networkDataLen); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 521 | } |
| 522 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 523 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_LEADER_RID>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 524 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 525 | return mEncoder.WriteUint8(otThreadGetLeaderRouterId(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 526 | } |
| 527 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 528 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_LEADER_ADDR>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 529 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 530 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 531 | otIp6Address address; |
| 532 | |
| 533 | error = otThreadGetLeaderRloc(mInstance, &address); |
| 534 | |
| 535 | if (error == OT_ERROR_NONE) |
| 536 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 537 | error = mEncoder.WriteIp6Address(address); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 538 | } |
| 539 | else |
| 540 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 541 | error = mEncoder.OverwriteWithLastStatusError(ThreadErrorToSpinelStatus(error)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | return error; |
| 545 | } |
| 546 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 547 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_PARENT>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 548 | { |
| 549 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 550 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 551 | otRouterInfo parentInfo; |
| 552 | |
| 553 | error = otThreadGetParentInfo(mInstance, &parentInfo); |
| 554 | |
| 555 | if (error == OT_ERROR_NONE) |
| 556 | { |
Abtin Keshavarzian | 52354e7 | 2018-07-04 13:40:40 -0700 | [diff] [blame] | 557 | if (parentInfo.mLinkEstablished) |
| 558 | { |
| 559 | int8_t averageRssi; |
| 560 | int8_t lastRssi; |
| 561 | |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 562 | IgnoreError(otThreadGetParentAverageRssi(mInstance, &averageRssi)); |
| 563 | IgnoreError(otThreadGetParentLastRssi(mInstance, &lastRssi)); |
Abtin Keshavarzian | 52354e7 | 2018-07-04 13:40:40 -0700 | [diff] [blame] | 564 | |
| 565 | SuccessOrExit(error = mEncoder.WriteEui64(parentInfo.mExtAddress)); |
| 566 | SuccessOrExit(error = mEncoder.WriteUint16(parentInfo.mRloc16)); |
| 567 | SuccessOrExit(error = mEncoder.WriteUint32(parentInfo.mAge)); |
| 568 | SuccessOrExit(error = mEncoder.WriteInt8(averageRssi)); |
| 569 | SuccessOrExit(error = mEncoder.WriteInt8(lastRssi)); |
| 570 | SuccessOrExit(error = mEncoder.WriteUint8(parentInfo.mLinkQualityIn)); |
| 571 | SuccessOrExit(error = mEncoder.WriteUint8(parentInfo.mLinkQualityOut)); |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | SuccessOrExit(error = mEncoder.OverwriteWithLastStatusError(SPINEL_STATUS_ITEM_NOT_FOUND)); |
| 576 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 577 | } |
| 578 | else |
| 579 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 580 | error = mEncoder.OverwriteWithLastStatusError(ThreadErrorToSpinelStatus(error)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 581 | } |
| 582 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 583 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 584 | return error; |
| 585 | } |
| 586 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 587 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_NEIGHBOR_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 588 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 589 | otError error = OT_ERROR_NONE; |
| 590 | otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT; |
| 591 | otNeighborInfo neighInfo; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 592 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 593 | while (otThreadGetNextNeighborInfo(mInstance, &iter, &neighInfo) == OT_ERROR_NONE) |
| 594 | { |
Abtin Keshavarzian | a1b2d35 | 2019-05-19 00:05:21 -0700 | [diff] [blame] | 595 | SuccessOrExit(error = EncodeNeighborInfo(neighInfo)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 596 | } |
| 597 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 598 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 599 | return error; |
| 600 | } |
| 601 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 602 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_NEIGHBOR_TABLE_ERROR_RATES>(void) |
Abtin Keshavarzian | 10f6c4f | 2018-02-02 10:29:52 -0800 | [diff] [blame] | 603 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 604 | otError error = OT_ERROR_NONE; |
| 605 | otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT; |
| 606 | otNeighborInfo neighInfo; |
Abtin Keshavarzian | 10f6c4f | 2018-02-02 10:29:52 -0800 | [diff] [blame] | 607 | |
| 608 | while (otThreadGetNextNeighborInfo(mInstance, &iter, &neighInfo) == OT_ERROR_NONE) |
| 609 | { |
| 610 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 611 | |
| 612 | SuccessOrExit(error = mEncoder.WriteEui64(neighInfo.mExtAddress)); |
| 613 | SuccessOrExit(error = mEncoder.WriteUint16(neighInfo.mRloc16)); |
| 614 | SuccessOrExit(error = mEncoder.WriteUint16(neighInfo.mFrameErrorRate)); |
| 615 | SuccessOrExit(error = mEncoder.WriteUint16(neighInfo.mMessageErrorRate)); |
| 616 | SuccessOrExit(error = mEncoder.WriteInt8(neighInfo.mAverageRssi)); |
| 617 | SuccessOrExit(error = mEncoder.WriteInt8(neighInfo.mLastRssi)); |
| 618 | |
| 619 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 620 | } |
| 621 | |
| 622 | exit: |
| 623 | return error; |
| 624 | } |
| 625 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 626 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_ASSISTING_PORTS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 627 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 628 | otError error = OT_ERROR_NONE; |
| 629 | uint8_t numEntries = 0; |
| 630 | const uint16_t *ports = otIp6GetUnsecurePorts(mInstance, &numEntries); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 631 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 632 | for (; numEntries != 0; ports++, numEntries--) |
| 633 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 634 | SuccessOrExit(error = mEncoder.WriteUint16(*ports)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 635 | } |
| 636 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 637 | exit: |
| 638 | return error; |
| 639 | } |
| 640 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 641 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_ASSISTING_PORTS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 642 | { |
Zhanglong Xia | c573daf | 2018-09-11 08:39:06 +0800 | [diff] [blame] | 643 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 644 | |
| 645 | // First, we need to remove all of the current assisting ports. |
Zhanglong Xia | c573daf | 2018-09-11 08:39:06 +0800 | [diff] [blame] | 646 | otIp6RemoveAllUnsecurePorts(mInstance); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 647 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 648 | while (mDecoder.GetRemainingLengthInStruct() >= sizeof(uint16_t)) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 649 | { |
| 650 | uint16_t port; |
| 651 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 652 | SuccessOrExit(mDecoder.ReadUint16(port)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 653 | |
| 654 | SuccessOrExit(error = otIp6AddUnsecurePort(mInstance, port)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 655 | } |
| 656 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 657 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 658 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 659 | if (error != OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 660 | { |
| 661 | // We had an error, but we've actually changed |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 662 | // the state of these ports, so we need to report |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 663 | // those incomplete changes via an asynchronous |
| 664 | // change event. |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 665 | IgnoreError( |
| 666 | WritePropertyValueIsFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_PROP_THREAD_ASSISTING_PORTS)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | return error; |
| 670 | } |
| 671 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 672 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 673 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 674 | return mEncoder.WriteBool(mAllowLocalNetworkDataChange); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 675 | } |
| 676 | |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 677 | #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 678 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 679 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 680 | bool value = false; |
| 681 | otError error = OT_ERROR_NONE; |
| 682 | bool shouldRegisterWithLeader = false; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 683 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 684 | SuccessOrExit(error = mDecoder.ReadBool(value)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 685 | |
| 686 | // Register any net data changes on transition from `true` to `false`. |
| 687 | shouldRegisterWithLeader = (mAllowLocalNetworkDataChange == true) && (value == false); |
| 688 | |
| 689 | mAllowLocalNetworkDataChange = value; |
| 690 | |
| 691 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 692 | |
| 693 | if (shouldRegisterWithLeader) |
| 694 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 695 | IgnoreError(otBorderRouterRegister(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | return error; |
| 699 | } |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 700 | #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 701 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 702 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_ON_MESH_NETS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 703 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 704 | otError error = OT_ERROR_NONE; |
| 705 | otBorderRouterConfig borderRouterConfig; |
Abtin Keshavarzian | 2c8f50b | 2017-09-01 21:27:58 -0700 | [diff] [blame] | 706 | otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 707 | |
| 708 | // Fill from non-local network data first |
Abtin Keshavarzian | 2c8f50b | 2017-09-01 21:27:58 -0700 | [diff] [blame] | 709 | while (otNetDataGetNextOnMeshPrefix(mInstance, &iter, &borderRouterConfig) == OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 710 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 711 | SuccessOrExit(error = mEncoder.OpenStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 712 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 713 | SuccessOrExit(error = mEncoder.WriteIp6Address(borderRouterConfig.mPrefix.mPrefix)); |
| 714 | SuccessOrExit(error = mEncoder.WriteUint8(borderRouterConfig.mPrefix.mLength)); |
| 715 | SuccessOrExit(error = mEncoder.WriteBool(borderRouterConfig.mStable)); |
| 716 | SuccessOrExit(error = mEncoder.WriteUint8(BorderRouterConfigToFlagByte(borderRouterConfig))); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 717 | SuccessOrExit(error = mEncoder.WriteBool(false)); // isLocal |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 718 | SuccessOrExit(error = mEncoder.WriteUint16(borderRouterConfig.mRloc16)); |
| 719 | |
| 720 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 721 | } |
| 722 | |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 723 | #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Abtin Keshavarzian | 2c8f50b | 2017-09-01 21:27:58 -0700 | [diff] [blame] | 724 | |
| 725 | iter = OT_NETWORK_DATA_ITERATOR_INIT; |
| 726 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 727 | // Fill from local network data last |
Abtin Keshavarzian | 2c8f50b | 2017-09-01 21:27:58 -0700 | [diff] [blame] | 728 | while (otBorderRouterGetNextOnMeshPrefix(mInstance, &iter, &borderRouterConfig) == OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 729 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 730 | SuccessOrExit(error = mEncoder.OpenStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 731 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 732 | SuccessOrExit(error = mEncoder.WriteIp6Address(borderRouterConfig.mPrefix.mPrefix)); |
| 733 | SuccessOrExit(error = mEncoder.WriteUint8(borderRouterConfig.mPrefix.mLength)); |
| 734 | SuccessOrExit(error = mEncoder.WriteBool(borderRouterConfig.mStable)); |
| 735 | SuccessOrExit(error = mEncoder.WriteUint8(BorderRouterConfigToFlagByte(borderRouterConfig))); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 736 | SuccessOrExit(error = mEncoder.WriteBool(true)); // isLocal |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 737 | SuccessOrExit(error = mEncoder.WriteUint16(borderRouterConfig.mRloc16)); |
| 738 | |
| 739 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 740 | } |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 741 | #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 742 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 743 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 744 | return error; |
| 745 | } |
| 746 | |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 747 | #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 748 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_THREAD_ON_MESH_NETS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 749 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 750 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 751 | otBorderRouterConfig borderRouterConfig; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 752 | bool stable = false; |
| 753 | uint8_t flags = 0; |
| 754 | uint8_t prefixLength; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 755 | |
| 756 | memset(&borderRouterConfig, 0, sizeof(otBorderRouterConfig)); |
| 757 | |
Abtin Keshavarzian | 31ce3d4 | 2019-08-01 10:30:08 -0700 | [diff] [blame] | 758 | VerifyOrExit(mAllowLocalNetworkDataChange, error = OT_ERROR_INVALID_STATE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 759 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 760 | SuccessOrExit(error = mDecoder.ReadIp6Address(borderRouterConfig.mPrefix.mPrefix)); |
Łukasz Duda | 7b084ec | 2017-10-25 17:54:17 +0200 | [diff] [blame] | 761 | SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 762 | SuccessOrExit(error = mDecoder.ReadBool(stable)); |
| 763 | SuccessOrExit(error = mDecoder.ReadUint8(flags)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 764 | |
Łukasz Duda | 7b084ec | 2017-10-25 17:54:17 +0200 | [diff] [blame] | 765 | borderRouterConfig.mPrefix.mLength = prefixLength; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 766 | borderRouterConfig.mStable = stable; |
| 767 | borderRouterConfig.mPreference = ((flags & SPINEL_NET_FLAG_PREFERENCE_MASK) >> SPINEL_NET_FLAG_PREFERENCE_OFFSET); |
| 768 | borderRouterConfig.mPreferred = ((flags & SPINEL_NET_FLAG_PREFERRED) != 0); |
| 769 | borderRouterConfig.mSlaac = ((flags & SPINEL_NET_FLAG_SLAAC) != 0); |
| 770 | borderRouterConfig.mDhcp = ((flags & SPINEL_NET_FLAG_DHCP) != 0); |
| 771 | borderRouterConfig.mConfigure = ((flags & SPINEL_NET_FLAG_CONFIGURE) != 0); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 772 | borderRouterConfig.mDefaultRoute = ((flags & SPINEL_NET_FLAG_DEFAULT_ROUTE) != 0); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 773 | borderRouterConfig.mOnMesh = ((flags & SPINEL_NET_FLAG_ON_MESH) != 0); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 774 | |
| 775 | error = otBorderRouterAddOnMeshPrefix(mInstance, &borderRouterConfig); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 776 | |
| 777 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 778 | return error; |
| 779 | } |
| 780 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 781 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_THREAD_ON_MESH_NETS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 782 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 783 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 784 | otIp6Prefix ip6Prefix; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 785 | uint8_t prefixLength; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 786 | |
| 787 | memset(&ip6Prefix, 0, sizeof(otIp6Prefix)); |
| 788 | |
Abtin Keshavarzian | 31ce3d4 | 2019-08-01 10:30:08 -0700 | [diff] [blame] | 789 | VerifyOrExit(mAllowLocalNetworkDataChange, error = OT_ERROR_INVALID_STATE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 790 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 791 | SuccessOrExit(error = mDecoder.ReadIp6Address(ip6Prefix.mPrefix)); |
Łukasz Duda | 7b084ec | 2017-10-25 17:54:17 +0200 | [diff] [blame] | 792 | SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); |
| 793 | |
| 794 | ip6Prefix.mLength = prefixLength; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 795 | |
| 796 | error = otBorderRouterRemoveOnMeshPrefix(mInstance, &ip6Prefix); |
| 797 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 798 | // If prefix was not on the list, "remove" command can be considred |
| 799 | // successful. |
Abtin Keshavarzian | 02bdc69 | 2017-08-15 09:11:19 -0700 | [diff] [blame] | 800 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 801 | if (error == OT_ERROR_NOT_FOUND) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 802 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 803 | error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 804 | } |
| 805 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 806 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 807 | return error; |
| 808 | } |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 809 | #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 810 | |
Jonathan Hui | 149640d | 2019-07-16 11:06:03 -0700 | [diff] [blame] | 811 | #if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 812 | |
| 813 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_SERVER_ALLOW_LOCAL_DATA_CHANGE>(void) |
| 814 | { |
| 815 | return mEncoder.WriteBool(mAllowLocalServerDataChange); |
| 816 | } |
| 817 | |
| 818 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_SERVER_ALLOW_LOCAL_DATA_CHANGE>(void) |
| 819 | { |
| 820 | bool value = false; |
| 821 | otError error = OT_ERROR_NONE; |
| 822 | bool shouldRegisterWithLeader = false; |
| 823 | |
| 824 | SuccessOrExit(error = mDecoder.ReadBool(value)); |
| 825 | |
| 826 | // Register any server data changes on transition from `true` to `false`. |
| 827 | shouldRegisterWithLeader = (mAllowLocalServerDataChange == true) && (value == false); |
| 828 | |
| 829 | mAllowLocalServerDataChange = value; |
| 830 | |
| 831 | exit: |
| 832 | |
| 833 | if (shouldRegisterWithLeader) |
| 834 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 835 | IgnoreError(otServerRegister(mInstance)); |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | return error; |
| 839 | } |
| 840 | |
| 841 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_SERVER_SERVICES>(void) |
| 842 | { |
| 843 | otError error = OT_ERROR_NONE; |
| 844 | otServiceConfig cfg; |
| 845 | bool stable; |
| 846 | const uint8_t * data; |
| 847 | uint16_t dataLen; |
| 848 | |
Abtin Keshavarzian | 31ce3d4 | 2019-08-01 10:30:08 -0700 | [diff] [blame] | 849 | VerifyOrExit(mAllowLocalServerDataChange, error = OT_ERROR_INVALID_STATE); |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 850 | |
| 851 | SuccessOrExit(error = mDecoder.ReadUint32(cfg.mEnterpriseNumber)); |
| 852 | SuccessOrExit(error = mDecoder.ReadDataWithLen(data, dataLen)); |
| 853 | |
| 854 | VerifyOrExit((dataLen <= sizeof(cfg.mServiceData)), error = OT_ERROR_INVALID_ARGS); |
| 855 | memcpy(cfg.mServiceData, data, dataLen); |
| 856 | |
Abtin Keshavarzian | 53d23b5 | 2020-06-20 18:09:14 -0700 | [diff] [blame] | 857 | static_assert((sizeof(cfg.mServiceData) <= UINT8_MAX), "Cannot handle full range of buffer length"); |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 858 | cfg.mServiceDataLength = static_cast<uint8_t>(dataLen); |
| 859 | |
| 860 | SuccessOrExit(error = mDecoder.ReadBool(stable)); |
| 861 | cfg.mServerConfig.mStable = stable; |
| 862 | SuccessOrExit(error = mDecoder.ReadDataWithLen(data, dataLen)); |
| 863 | |
| 864 | VerifyOrExit((dataLen <= sizeof(cfg.mServerConfig.mServerData)), error = OT_ERROR_INVALID_ARGS); |
| 865 | memcpy(cfg.mServerConfig.mServerData, data, dataLen); |
| 866 | |
Abtin Keshavarzian | 53d23b5 | 2020-06-20 18:09:14 -0700 | [diff] [blame] | 867 | static_assert((sizeof(cfg.mServerConfig.mServerData) <= UINT8_MAX), "Cannot handle full range of buffer length"); |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 868 | cfg.mServerConfig.mServerDataLength = static_cast<uint8_t>(dataLen); |
| 869 | |
| 870 | SuccessOrExit(error = otServerAddService(mInstance, &cfg)); |
| 871 | exit: |
| 872 | return error; |
| 873 | } |
| 874 | |
| 875 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_SERVER_SERVICES>(void) |
| 876 | { |
| 877 | otError error = OT_ERROR_NONE; |
| 878 | |
| 879 | uint32_t enterpriseNumber; |
| 880 | const uint8_t *serviceData; |
| 881 | uint16_t serviceDataLength; |
| 882 | |
Abtin Keshavarzian | 31ce3d4 | 2019-08-01 10:30:08 -0700 | [diff] [blame] | 883 | VerifyOrExit(mAllowLocalServerDataChange, error = OT_ERROR_INVALID_STATE); |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 884 | |
| 885 | SuccessOrExit(error = mDecoder.ReadUint32(enterpriseNumber)); |
| 886 | SuccessOrExit(error = mDecoder.ReadDataWithLen(serviceData, serviceDataLength)); |
| 887 | |
| 888 | VerifyOrExit(serviceDataLength <= UINT8_MAX, error = OT_ERROR_INVALID_ARGS); |
| 889 | |
| 890 | SuccessOrExit(error = otServerRemoveService(mInstance, enterpriseNumber, serviceData, |
| 891 | static_cast<uint8_t>(serviceDataLength))); |
| 892 | exit: |
| 893 | return error; |
| 894 | } |
| 895 | |
| 896 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_SERVER_SERVICES>(void) |
| 897 | { |
| 898 | otError error = OT_ERROR_NONE; |
| 899 | otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT; |
| 900 | otServiceConfig cfg; |
| 901 | |
| 902 | while (otServerGetNextService(mInstance, &iterator, &cfg) == OT_ERROR_NONE) |
| 903 | { |
| 904 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 905 | |
| 906 | SuccessOrExit(error = mEncoder.WriteUint32(cfg.mEnterpriseNumber)); |
| 907 | SuccessOrExit(error = mEncoder.WriteDataWithLen(cfg.mServiceData, cfg.mServiceDataLength)); |
| 908 | SuccessOrExit(error = mEncoder.WriteBool(cfg.mServerConfig.mStable)); |
| 909 | SuccessOrExit( |
| 910 | error = mEncoder.WriteDataWithLen(cfg.mServerConfig.mServerData, cfg.mServerConfig.mServerDataLength)); |
| 911 | SuccessOrExit(error = mEncoder.WriteUint16(cfg.mServerConfig.mRloc16)); |
| 912 | |
| 913 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 914 | } |
| 915 | exit: |
| 916 | return error; |
| 917 | } |
Rongli Sun | e860009 | 2019-12-03 00:42:46 +0800 | [diff] [blame] | 918 | #endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 919 | |
| 920 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_SERVER_LEADER_SERVICES>(void) |
| 921 | { |
| 922 | otError error = OT_ERROR_NONE; |
| 923 | otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT; |
| 924 | otServiceConfig cfg; |
| 925 | |
Rongli Sun | e860009 | 2019-12-03 00:42:46 +0800 | [diff] [blame] | 926 | while (otNetDataGetNextService(mInstance, &iterator, &cfg) == OT_ERROR_NONE) |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 927 | { |
| 928 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 929 | |
Rongli Sun | 315a27b | 2020-03-26 23:54:23 +0800 | [diff] [blame] | 930 | SuccessOrExit(error = mEncoder.WriteUint8(cfg.mServiceId)); |
Joseph Newman | ecad717 | 2019-03-29 05:29:25 +0000 | [diff] [blame] | 931 | SuccessOrExit(error = mEncoder.WriteUint32(cfg.mEnterpriseNumber)); |
| 932 | SuccessOrExit(error = mEncoder.WriteDataWithLen(cfg.mServiceData, cfg.mServiceDataLength)); |
| 933 | SuccessOrExit(error = mEncoder.WriteBool(cfg.mServerConfig.mStable)); |
| 934 | SuccessOrExit( |
| 935 | error = mEncoder.WriteDataWithLen(cfg.mServerConfig.mServerData, cfg.mServerConfig.mServerDataLength)); |
| 936 | SuccessOrExit(error = mEncoder.WriteUint16(cfg.mServerConfig.mRloc16)); |
| 937 | |
| 938 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 939 | } |
| 940 | exit: |
| 941 | return error; |
| 942 | } |
| 943 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 944 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_DISCOVERY_SCAN_JOINER_FLAG>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 945 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 946 | return mEncoder.WriteBool(mDiscoveryScanJoinerFlag); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 947 | } |
| 948 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 949 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_DISCOVERY_SCAN_JOINER_FLAG>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 950 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 951 | return mDecoder.ReadBool(mDiscoveryScanJoinerFlag); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 952 | } |
| 953 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 954 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_DISCOVERY_SCAN_ENABLE_FILTERING>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 955 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 956 | return mEncoder.WriteBool(mDiscoveryScanEnableFiltering); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 957 | } |
| 958 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 959 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_DISCOVERY_SCAN_ENABLE_FILTERING>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 960 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 961 | return mDecoder.ReadBool(mDiscoveryScanEnableFiltering); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 962 | } |
| 963 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 964 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_DISCOVERY_SCAN_PANID>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 965 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 966 | return mEncoder.WriteUint16(mDiscoveryScanPanId); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 967 | } |
| 968 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 969 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_DISCOVERY_SCAN_PANID>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 970 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 971 | return mDecoder.ReadUint16(mDiscoveryScanPanId); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 972 | } |
| 973 | |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 974 | otError NcpBase::EncodeOperationalDataset(const otOperationalDataset &aDataset) |
| 975 | { |
| 976 | otError error = OT_ERROR_NONE; |
| 977 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 978 | if (aDataset.mComponents.mIsActiveTimestampPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 979 | { |
| 980 | SuccessOrExit(mEncoder.OpenStruct()); |
| 981 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_DATASET_ACTIVE_TIMESTAMP)); |
| 982 | SuccessOrExit(mEncoder.WriteUint64(aDataset.mActiveTimestamp)); |
| 983 | SuccessOrExit(mEncoder.CloseStruct()); |
| 984 | } |
| 985 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 986 | if (aDataset.mComponents.mIsPendingTimestampPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 987 | { |
| 988 | SuccessOrExit(mEncoder.OpenStruct()); |
| 989 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_DATASET_PENDING_TIMESTAMP)); |
| 990 | SuccessOrExit(mEncoder.WriteUint64(aDataset.mPendingTimestamp)); |
| 991 | SuccessOrExit(mEncoder.CloseStruct()); |
| 992 | } |
| 993 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 994 | if (aDataset.mComponents.mIsMasterKeyPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 995 | { |
| 996 | SuccessOrExit(mEncoder.OpenStruct()); |
| 997 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_NET_MASTER_KEY)); |
| 998 | SuccessOrExit(mEncoder.WriteData(aDataset.mMasterKey.m8, OT_MASTER_KEY_SIZE)); |
| 999 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1000 | } |
| 1001 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 1002 | if (aDataset.mComponents.mIsNetworkNamePresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1003 | { |
| 1004 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1005 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_NET_NETWORK_NAME)); |
| 1006 | SuccessOrExit(mEncoder.WriteUtf8(aDataset.mNetworkName.m8)); |
| 1007 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1008 | } |
| 1009 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 1010 | if (aDataset.mComponents.mIsExtendedPanIdPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1011 | { |
| 1012 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1013 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_NET_XPANID)); |
| 1014 | SuccessOrExit(mEncoder.WriteData(aDataset.mExtendedPanId.m8, OT_EXT_PAN_ID_SIZE)); |
| 1015 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1016 | } |
| 1017 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 1018 | if (aDataset.mComponents.mIsMeshLocalPrefixPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1019 | { |
| 1020 | otIp6Address addr; |
| 1021 | |
| 1022 | memcpy(addr.mFields.m8, aDataset.mMeshLocalPrefix.m8, 8); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1023 | memset(addr.mFields.m8 + 8, 0, 8); // Zero out the last 8 bytes. |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1024 | |
| 1025 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1026 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_IPV6_ML_PREFIX)); |
Jintao Lin | 8788cf5 | 2020-01-10 10:15:23 +0800 | [diff] [blame] | 1027 | SuccessOrExit(error = mEncoder.WriteIp6Address(addr)); // Mesh local prefix |
| 1028 | SuccessOrExit(error = mEncoder.WriteUint8(OT_IP6_PREFIX_BITSIZE)); // Prefix length (in bits) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1029 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1030 | } |
| 1031 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 1032 | if (aDataset.mComponents.mIsDelayPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1033 | { |
| 1034 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1035 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_DATASET_DELAY_TIMER)); |
| 1036 | SuccessOrExit(mEncoder.WriteUint32(aDataset.mDelay)); |
| 1037 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1038 | } |
| 1039 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 1040 | if (aDataset.mComponents.mIsPanIdPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1041 | { |
| 1042 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1043 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_MAC_15_4_PANID)); |
| 1044 | SuccessOrExit(mEncoder.WriteUint16(aDataset.mPanId)); |
| 1045 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1046 | } |
| 1047 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 1048 | if (aDataset.mComponents.mIsChannelPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1049 | { |
| 1050 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1051 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_PHY_CHAN)); |
| 1052 | |
| 1053 | // The channel is stored in Dataset as `uint16_t` (to accommodate |
| 1054 | // larger number of channels in sub-GHz band), however the current |
| 1055 | // definition of `SPINEL_PROP_PHY_CHAN` property limits the channel |
| 1056 | // to a `uint8_t`. |
| 1057 | |
| 1058 | SuccessOrExit(mEncoder.WriteUint8(static_cast<uint8_t>(aDataset.mChannel))); |
| 1059 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1060 | } |
| 1061 | |
Abtin Keshavarzian | 1555b21 | 2019-09-18 19:11:07 -0700 | [diff] [blame] | 1062 | if (aDataset.mComponents.mIsPskcPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1063 | { |
| 1064 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1065 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_NET_PSKC)); |
Abtin Keshavarzian | 1555b21 | 2019-09-18 19:11:07 -0700 | [diff] [blame] | 1066 | SuccessOrExit(mEncoder.WriteData(aDataset.mPskc.m8, sizeof(spinel_net_pskc_t))); |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1067 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1068 | } |
| 1069 | |
Abtin Keshavarzian | 758e647 | 2018-07-19 14:33:49 -0700 | [diff] [blame] | 1070 | if (aDataset.mComponents.mIsSecurityPolicyPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1071 | { |
| 1072 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1073 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_DATASET_SECURITY_POLICY)); |
| 1074 | SuccessOrExit(mEncoder.WriteUint16(aDataset.mSecurityPolicy.mRotationTime)); |
| 1075 | SuccessOrExit(mEncoder.WriteUint8(aDataset.mSecurityPolicy.mFlags)); |
| 1076 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1077 | } |
| 1078 | |
Zhanglong Xia | ce24abb | 2019-03-13 22:49:25 +0800 | [diff] [blame] | 1079 | if (aDataset.mComponents.mIsChannelMaskPresent) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1080 | { |
| 1081 | SuccessOrExit(mEncoder.OpenStruct()); |
| 1082 | SuccessOrExit(mEncoder.WriteUintPacked(SPINEL_PROP_PHY_CHAN_SUPPORTED)); |
Zhanglong Xia | ce24abb | 2019-03-13 22:49:25 +0800 | [diff] [blame] | 1083 | SuccessOrExit(EncodeChannelMask(aDataset.mChannelMask)); |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1084 | SuccessOrExit(mEncoder.CloseStruct()); |
| 1085 | } |
| 1086 | |
| 1087 | exit: |
| 1088 | return error; |
| 1089 | } |
| 1090 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1091 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_ACTIVE_DATASET>(void) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1092 | { |
| 1093 | otOperationalDataset dataset; |
| 1094 | |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 1095 | IgnoreError(otDatasetGetActive(mInstance, &dataset)); |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1096 | return EncodeOperationalDataset(dataset); |
| 1097 | } |
| 1098 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1099 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_PENDING_DATASET>(void) |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1100 | { |
| 1101 | otOperationalDataset dataset; |
| 1102 | |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 1103 | IgnoreError(otDatasetGetPending(mInstance, &dataset)); |
Abtin Keshavarzian | 4e060e4 | 2017-11-16 05:43:13 -0800 | [diff] [blame] | 1104 | return EncodeOperationalDataset(dataset); |
| 1105 | } |
| 1106 | |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1107 | otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, |
| 1108 | const uint8_t ** aTlvs, |
| 1109 | uint8_t * aTlvsLength, |
| 1110 | const otIp6Address ** aDestIpAddress, |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1111 | bool aAllowEmptyValues) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1112 | { |
| 1113 | otError error = OT_ERROR_NONE; |
| 1114 | |
| 1115 | memset(&aDataset, 0, sizeof(otOperationalDataset)); |
| 1116 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1117 | if (aTlvs != nullptr) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1118 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1119 | *aTlvs = nullptr; |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1120 | } |
| 1121 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1122 | if (aTlvsLength != nullptr) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1123 | { |
| 1124 | *aTlvsLength = 0; |
| 1125 | } |
| 1126 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1127 | if (aDestIpAddress != nullptr) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1128 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1129 | *aDestIpAddress = nullptr; |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | while (!mDecoder.IsAllReadInStruct()) |
| 1133 | { |
| 1134 | unsigned int propKey; |
| 1135 | |
| 1136 | SuccessOrExit(error = mDecoder.OpenStruct()); |
| 1137 | SuccessOrExit(error = mDecoder.ReadUintPacked(propKey)); |
| 1138 | |
| 1139 | switch (static_cast<spinel_prop_key_t>(propKey)) |
| 1140 | { |
| 1141 | case SPINEL_PROP_DATASET_ACTIVE_TIMESTAMP: |
| 1142 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1143 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1144 | { |
| 1145 | SuccessOrExit(error = mDecoder.ReadUint64(aDataset.mActiveTimestamp)); |
| 1146 | } |
| 1147 | |
| 1148 | aDataset.mComponents.mIsActiveTimestampPresent = true; |
| 1149 | break; |
| 1150 | |
| 1151 | case SPINEL_PROP_DATASET_PENDING_TIMESTAMP: |
| 1152 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1153 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1154 | { |
| 1155 | SuccessOrExit(error = mDecoder.ReadUint64(aDataset.mPendingTimestamp)); |
| 1156 | } |
| 1157 | |
| 1158 | aDataset.mComponents.mIsPendingTimestampPresent = true; |
| 1159 | break; |
| 1160 | |
| 1161 | case SPINEL_PROP_NET_MASTER_KEY: |
| 1162 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1163 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1164 | { |
| 1165 | const uint8_t *key; |
| 1166 | uint16_t len; |
| 1167 | |
| 1168 | SuccessOrExit(error = mDecoder.ReadData(key, len)); |
| 1169 | VerifyOrExit(len == OT_MASTER_KEY_SIZE, error = OT_ERROR_INVALID_ARGS); |
| 1170 | memcpy(aDataset.mMasterKey.m8, key, len); |
| 1171 | } |
| 1172 | |
| 1173 | aDataset.mComponents.mIsMasterKeyPresent = true; |
| 1174 | break; |
| 1175 | |
| 1176 | case SPINEL_PROP_NET_NETWORK_NAME: |
| 1177 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1178 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1179 | { |
| 1180 | const char *name; |
| 1181 | size_t len; |
| 1182 | |
| 1183 | SuccessOrExit(error = mDecoder.ReadUtf8(name)); |
| 1184 | len = strlen(name); |
| 1185 | VerifyOrExit(len <= OT_NETWORK_NAME_MAX_SIZE, error = OT_ERROR_INVALID_ARGS); |
| 1186 | memcpy(aDataset.mNetworkName.m8, name, len + 1); |
| 1187 | } |
| 1188 | |
| 1189 | aDataset.mComponents.mIsNetworkNamePresent = true; |
| 1190 | break; |
| 1191 | |
| 1192 | case SPINEL_PROP_NET_XPANID: |
| 1193 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1194 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1195 | { |
| 1196 | const uint8_t *xpanid; |
| 1197 | uint16_t len; |
| 1198 | |
| 1199 | SuccessOrExit(error = mDecoder.ReadData(xpanid, len)); |
| 1200 | VerifyOrExit(len == OT_EXT_PAN_ID_SIZE, error = OT_ERROR_INVALID_ARGS); |
| 1201 | memcpy(aDataset.mExtendedPanId.m8, xpanid, len); |
| 1202 | } |
| 1203 | |
| 1204 | aDataset.mComponents.mIsExtendedPanIdPresent = true; |
| 1205 | break; |
| 1206 | |
| 1207 | case SPINEL_PROP_IPV6_ML_PREFIX: |
| 1208 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1209 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1210 | { |
| 1211 | const otIp6Address *addr; |
| 1212 | uint8_t prefixLen; |
| 1213 | |
| 1214 | SuccessOrExit(error = mDecoder.ReadIp6Address(addr)); |
| 1215 | SuccessOrExit(error = mDecoder.ReadUint8(prefixLen)); |
Jintao Lin | 8788cf5 | 2020-01-10 10:15:23 +0800 | [diff] [blame] | 1216 | VerifyOrExit(prefixLen == OT_IP6_PREFIX_BITSIZE, error = OT_ERROR_INVALID_ARGS); |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1217 | memcpy(aDataset.mMeshLocalPrefix.m8, addr, OT_MESH_LOCAL_PREFIX_SIZE); |
| 1218 | } |
| 1219 | |
| 1220 | aDataset.mComponents.mIsMeshLocalPrefixPresent = true; |
| 1221 | break; |
| 1222 | |
| 1223 | case SPINEL_PROP_DATASET_DELAY_TIMER: |
| 1224 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1225 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1226 | { |
| 1227 | SuccessOrExit(error = mDecoder.ReadUint32(aDataset.mDelay)); |
| 1228 | } |
| 1229 | |
| 1230 | aDataset.mComponents.mIsDelayPresent = true; |
| 1231 | break; |
| 1232 | |
| 1233 | case SPINEL_PROP_MAC_15_4_PANID: |
| 1234 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1235 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1236 | { |
| 1237 | SuccessOrExit(error = mDecoder.ReadUint16(aDataset.mPanId)); |
| 1238 | } |
| 1239 | |
| 1240 | aDataset.mComponents.mIsPanIdPresent = true; |
| 1241 | break; |
| 1242 | |
| 1243 | case SPINEL_PROP_PHY_CHAN: |
| 1244 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1245 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1246 | { |
| 1247 | uint8_t channel; |
| 1248 | |
| 1249 | SuccessOrExit(error = mDecoder.ReadUint8(channel)); |
| 1250 | aDataset.mChannel = channel; |
| 1251 | } |
| 1252 | |
| 1253 | aDataset.mComponents.mIsChannelPresent = true; |
| 1254 | break; |
| 1255 | |
| 1256 | case SPINEL_PROP_NET_PSKC: |
| 1257 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1258 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1259 | { |
| 1260 | const uint8_t *psk; |
| 1261 | uint16_t len; |
| 1262 | |
| 1263 | SuccessOrExit(error = mDecoder.ReadData(psk, len)); |
| 1264 | VerifyOrExit(len == OT_PSKC_MAX_SIZE, error = OT_ERROR_INVALID_ARGS); |
Abtin Keshavarzian | 1555b21 | 2019-09-18 19:11:07 -0700 | [diff] [blame] | 1265 | memcpy(aDataset.mPskc.m8, psk, OT_PSKC_MAX_SIZE); |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1266 | } |
| 1267 | |
Abtin Keshavarzian | 1555b21 | 2019-09-18 19:11:07 -0700 | [diff] [blame] | 1268 | aDataset.mComponents.mIsPskcPresent = true; |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1269 | break; |
| 1270 | |
| 1271 | case SPINEL_PROP_DATASET_SECURITY_POLICY: |
| 1272 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1273 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1274 | { |
| 1275 | SuccessOrExit(error = mDecoder.ReadUint16(aDataset.mSecurityPolicy.mRotationTime)); |
| 1276 | SuccessOrExit(error = mDecoder.ReadUint8(aDataset.mSecurityPolicy.mFlags)); |
| 1277 | } |
| 1278 | |
| 1279 | aDataset.mComponents.mIsSecurityPolicyPresent = true; |
| 1280 | break; |
| 1281 | |
| 1282 | case SPINEL_PROP_PHY_CHAN_SUPPORTED: |
| 1283 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1284 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1285 | { |
| 1286 | uint8_t channel; |
| 1287 | |
Zhanglong Xia | ce24abb | 2019-03-13 22:49:25 +0800 | [diff] [blame] | 1288 | aDataset.mChannelMask = 0; |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1289 | |
| 1290 | while (!mDecoder.IsAllReadInStruct()) |
| 1291 | { |
| 1292 | SuccessOrExit(error = mDecoder.ReadUint8(channel)); |
| 1293 | VerifyOrExit(channel <= 31, error = OT_ERROR_INVALID_ARGS); |
Zhanglong Xia | ce24abb | 2019-03-13 22:49:25 +0800 | [diff] [blame] | 1294 | aDataset.mChannelMask |= (1UL << channel); |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | |
Zhanglong Xia | ce24abb | 2019-03-13 22:49:25 +0800 | [diff] [blame] | 1298 | aDataset.mComponents.mIsChannelMaskPresent = true; |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1299 | break; |
| 1300 | |
| 1301 | case SPINEL_PROP_DATASET_RAW_TLVS: |
| 1302 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1303 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1304 | { |
| 1305 | const uint8_t *tlvs; |
| 1306 | uint16_t len; |
| 1307 | |
| 1308 | SuccessOrExit(error = mDecoder.ReadData(tlvs, len)); |
| 1309 | VerifyOrExit(len <= 255, error = OT_ERROR_INVALID_ARGS); |
| 1310 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1311 | if (aTlvs != nullptr) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1312 | { |
| 1313 | *aTlvs = tlvs; |
| 1314 | } |
| 1315 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1316 | if (aTlvsLength != nullptr) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1317 | { |
| 1318 | *aTlvsLength = static_cast<uint8_t>(len); |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | break; |
| 1323 | |
| 1324 | case SPINEL_PROP_DATASET_DEST_ADDRESS: |
| 1325 | |
Jonathan Hui | 49c4b63 | 2019-03-21 09:52:32 -0700 | [diff] [blame] | 1326 | if (!aAllowEmptyValues || !mDecoder.IsAllReadInStruct()) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1327 | { |
| 1328 | const otIp6Address *addr; |
| 1329 | |
| 1330 | SuccessOrExit(error = mDecoder.ReadIp6Address(addr)); |
| 1331 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1332 | if (aDestIpAddress != nullptr) |
rongli | 1253bec | 2018-12-04 13:28:09 +0800 | [diff] [blame] | 1333 | { |
| 1334 | *aDestIpAddress = addr; |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | break; |
| 1339 | |
| 1340 | default: |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | SuccessOrExit(error = mDecoder.CloseStruct()); |
| 1345 | } |
| 1346 | |
| 1347 | exit: |
| 1348 | return error; |
| 1349 | } |
| 1350 | |
| 1351 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_ACTIVE_DATASET>(void) |
| 1352 | { |
| 1353 | otError error = OT_ERROR_NONE; |
| 1354 | otOperationalDataset dataset; |
| 1355 | |
| 1356 | SuccessOrExit(error = DecodeOperationalDataset(dataset)); |
| 1357 | error = otDatasetSetActive(mInstance, &dataset); |
| 1358 | |
| 1359 | exit: |
| 1360 | return error; |
| 1361 | } |
| 1362 | |
| 1363 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_PENDING_DATASET>(void) |
| 1364 | { |
| 1365 | otError error = OT_ERROR_NONE; |
| 1366 | otOperationalDataset dataset; |
| 1367 | |
| 1368 | SuccessOrExit(error = DecodeOperationalDataset(dataset)); |
| 1369 | error = otDatasetSetPending(mInstance, &dataset); |
| 1370 | |
| 1371 | exit: |
| 1372 | return error; |
| 1373 | } |
| 1374 | |
| 1375 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_MGMT_SET_ACTIVE_DATASET>(void) |
| 1376 | { |
| 1377 | otError error = OT_ERROR_NONE; |
| 1378 | otOperationalDataset dataset; |
| 1379 | const uint8_t * extraTlvs; |
| 1380 | uint8_t extraTlvsLength; |
| 1381 | |
| 1382 | SuccessOrExit(error = DecodeOperationalDataset(dataset, &extraTlvs, &extraTlvsLength)); |
| 1383 | error = otDatasetSendMgmtActiveSet(mInstance, &dataset, extraTlvs, extraTlvsLength); |
| 1384 | |
| 1385 | exit: |
| 1386 | return error; |
| 1387 | } |
| 1388 | |
| 1389 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_MGMT_SET_PENDING_DATASET>(void) |
| 1390 | { |
| 1391 | otError error = OT_ERROR_NONE; |
| 1392 | otOperationalDataset dataset; |
| 1393 | const uint8_t * extraTlvs; |
| 1394 | uint8_t extraTlvsLength; |
| 1395 | |
| 1396 | SuccessOrExit(error = DecodeOperationalDataset(dataset, &extraTlvs, &extraTlvsLength)); |
| 1397 | error = otDatasetSendMgmtPendingSet(mInstance, &dataset, extraTlvs, extraTlvsLength); |
| 1398 | |
| 1399 | exit: |
| 1400 | return error; |
| 1401 | } |
| 1402 | |
| 1403 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_MGMT_GET_ACTIVE_DATASET>(void) |
| 1404 | { |
| 1405 | otError error = OT_ERROR_NONE; |
| 1406 | otOperationalDataset dataset; |
| 1407 | const uint8_t * extraTlvs; |
| 1408 | uint8_t extraTlvsLength; |
| 1409 | const otIp6Address * destIpAddress; |
| 1410 | |
| 1411 | SuccessOrExit(error = DecodeOperationalDataset(dataset, &extraTlvs, &extraTlvsLength, &destIpAddress, true)); |
| 1412 | error = otDatasetSendMgmtActiveGet(mInstance, &dataset.mComponents, extraTlvs, extraTlvsLength, destIpAddress); |
| 1413 | |
| 1414 | exit: |
| 1415 | return error; |
| 1416 | } |
| 1417 | |
| 1418 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_MGMT_GET_PENDING_DATASET>(void) |
| 1419 | { |
| 1420 | otError error = OT_ERROR_NONE; |
| 1421 | otOperationalDataset dataset; |
| 1422 | const uint8_t * extraTlvs; |
| 1423 | uint8_t extraTlvsLength; |
| 1424 | const otIp6Address * destIpAddress; |
| 1425 | |
| 1426 | SuccessOrExit(error = DecodeOperationalDataset(dataset, &extraTlvs, &extraTlvsLength, &destIpAddress, true)); |
| 1427 | error = otDatasetSendMgmtPendingGet(mInstance, &dataset.mComponents, extraTlvs, extraTlvsLength, destIpAddress); |
| 1428 | |
| 1429 | exit: |
| 1430 | return error; |
| 1431 | } |
Jonathan Hui | 31ffd16 | 2019-07-16 12:01:36 -0700 | [diff] [blame] | 1432 | #if OPENTHREAD_CONFIG_JOINER_ENABLE |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1433 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MESHCOP_JOINER_STATE>(void) |
| 1434 | { |
Abtin Keshavarzian | 99f5790 | 2019-04-22 10:04:54 -0700 | [diff] [blame] | 1435 | spinel_meshcop_joiner_state_t state = SPINEL_MESHCOP_JOINER_STATE_IDLE; |
| 1436 | |
| 1437 | switch (otJoinerGetState(mInstance)) |
| 1438 | { |
| 1439 | case OT_JOINER_STATE_IDLE: |
| 1440 | state = SPINEL_MESHCOP_JOINER_STATE_IDLE; |
| 1441 | break; |
| 1442 | case OT_JOINER_STATE_DISCOVER: |
| 1443 | state = SPINEL_MESHCOP_JOINER_STATE_DISCOVER; |
| 1444 | break; |
| 1445 | case OT_JOINER_STATE_CONNECT: |
| 1446 | state = SPINEL_MESHCOP_JOINER_STATE_CONNECTING; |
| 1447 | break; |
| 1448 | case OT_JOINER_STATE_CONNECTED: |
| 1449 | state = SPINEL_MESHCOP_JOINER_STATE_CONNECTED; |
| 1450 | break; |
| 1451 | case OT_JOINER_STATE_ENTRUST: |
| 1452 | state = SPINEL_MESHCOP_JOINER_STATE_ENTRUST; |
| 1453 | break; |
| 1454 | case OT_JOINER_STATE_JOINED: |
| 1455 | state = SPINEL_MESHCOP_JOINER_STATE_JOINED; |
| 1456 | break; |
| 1457 | } |
| 1458 | |
| 1459 | return mEncoder.WriteUint8(state); |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING>(void) |
| 1463 | { |
Abtin Keshavarzian | 987e96b | 2019-04-17 19:08:11 -0700 | [diff] [blame] | 1464 | otError error = OT_ERROR_NONE; |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1465 | bool action = false; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1466 | const char *psk = nullptr; |
| 1467 | const char *provisioningUrl = nullptr; |
| 1468 | const char *vendorName = nullptr; |
| 1469 | const char *vendorModel = nullptr; |
| 1470 | const char *vendorSwVersion = nullptr; |
| 1471 | const char *vendorData = nullptr; |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1472 | |
| 1473 | SuccessOrExit(error = mDecoder.ReadBool(action)); |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1474 | |
Abtin Keshavarzian | 987e96b | 2019-04-17 19:08:11 -0700 | [diff] [blame] | 1475 | if (action == false) |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1476 | { |
Yakun Xu | 957d79d | 2019-09-10 23:42:02 +0800 | [diff] [blame] | 1477 | otJoinerStop(mInstance); |
Abtin Keshavarzian | 987e96b | 2019-04-17 19:08:11 -0700 | [diff] [blame] | 1478 | ExitNow(); |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1479 | } |
Abtin Keshavarzian | 987e96b | 2019-04-17 19:08:11 -0700 | [diff] [blame] | 1480 | |
| 1481 | SuccessOrExit(error = mDecoder.ReadUtf8(psk)); |
| 1482 | |
| 1483 | // Parse optional fields |
| 1484 | |
| 1485 | if (!mDecoder.IsAllReadInStruct()) |
| 1486 | { |
| 1487 | SuccessOrExit(error = mDecoder.ReadUtf8(provisioningUrl)); |
| 1488 | } |
| 1489 | |
| 1490 | if (!mDecoder.IsAllReadInStruct()) |
| 1491 | { |
| 1492 | SuccessOrExit(error = mDecoder.ReadUtf8(vendorName)); |
| 1493 | } |
| 1494 | |
| 1495 | if (!mDecoder.IsAllReadInStruct()) |
| 1496 | { |
| 1497 | SuccessOrExit(error = mDecoder.ReadUtf8(vendorModel)); |
| 1498 | } |
| 1499 | |
| 1500 | if (!mDecoder.IsAllReadInStruct()) |
| 1501 | { |
| 1502 | SuccessOrExit(error = mDecoder.ReadUtf8(vendorSwVersion)); |
| 1503 | } |
| 1504 | |
| 1505 | if (!mDecoder.IsAllReadInStruct()) |
| 1506 | { |
| 1507 | SuccessOrExit(error = mDecoder.ReadUtf8(vendorData)); |
| 1508 | } |
| 1509 | |
| 1510 | // Use OpenThread default values for vendor name, mode, sw version if |
| 1511 | // not specified or an empty string is given. |
| 1512 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1513 | if ((vendorName == nullptr) || (vendorName[0] == 0)) |
Abtin Keshavarzian | 987e96b | 2019-04-17 19:08:11 -0700 | [diff] [blame] | 1514 | { |
| 1515 | vendorName = PACKAGE_NAME; |
| 1516 | } |
| 1517 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1518 | if ((vendorModel == nullptr) || (vendorModel[0] == 0)) |
Abtin Keshavarzian | 987e96b | 2019-04-17 19:08:11 -0700 | [diff] [blame] | 1519 | { |
| 1520 | vendorModel = OPENTHREAD_CONFIG_PLATFORM_INFO; |
| 1521 | } |
| 1522 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1523 | if ((vendorSwVersion == nullptr) || (vendorSwVersion[0] == 0)) |
Abtin Keshavarzian | 987e96b | 2019-04-17 19:08:11 -0700 | [diff] [blame] | 1524 | { |
| 1525 | vendorSwVersion = PACKAGE_VERSION; |
| 1526 | } |
| 1527 | |
| 1528 | error = otJoinerStart(mInstance, psk, provisioningUrl, vendorName, vendorModel, vendorSwVersion, vendorData, |
| 1529 | &NcpBase::HandleJoinerCallback_Jump, this); |
| 1530 | |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1531 | exit: |
| 1532 | return error; |
| 1533 | } |
| 1534 | |
Abtin Keshavarzian | a7415b5 | 2020-06-20 00:35:57 -0700 | [diff] [blame] | 1535 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MESHCOP_JOINER_DISCERNER>(void) |
| 1536 | { |
| 1537 | otError error; |
| 1538 | const otJoinerDiscerner *discerner = otJoinerGetDiscerner(mInstance); |
| 1539 | |
| 1540 | if (discerner == nullptr) |
| 1541 | { |
| 1542 | SuccessOrExit(error = mEncoder.WriteUint8(0)); |
| 1543 | } |
| 1544 | else |
| 1545 | { |
| 1546 | SuccessOrExit(error = mEncoder.WriteUint8(discerner->mLength)); |
| 1547 | SuccessOrExit(error = mEncoder.WriteUint64(discerner->mValue)); |
| 1548 | } |
| 1549 | |
| 1550 | exit: |
| 1551 | return error; |
| 1552 | } |
| 1553 | |
| 1554 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MESHCOP_JOINER_DISCERNER>(void) |
| 1555 | { |
| 1556 | otError error = OT_ERROR_NONE; |
| 1557 | otJoinerDiscerner discerner; |
| 1558 | |
| 1559 | SuccessOrExit(error = mDecoder.ReadUint8(discerner.mLength)); |
| 1560 | |
| 1561 | if (discerner.mLength == 0) |
| 1562 | { |
| 1563 | // Clearing any previously set Joiner Discerner |
| 1564 | error = otJoinerSetDiscerner(mInstance, nullptr); |
| 1565 | ExitNow(); |
| 1566 | } |
| 1567 | |
| 1568 | SuccessOrExit(error = mDecoder.ReadUint64(discerner.mValue)); |
| 1569 | error = otJoinerSetDiscerner(mInstance, &discerner); |
| 1570 | |
| 1571 | exit: |
| 1572 | return error; |
| 1573 | } |
| 1574 | |
| 1575 | #endif // OPENTHREAD_CONFIG_JOINER_ENABLE |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 1576 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1577 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_ML_PREFIX>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1578 | { |
Jonathan Hui | c116441 | 2018-08-17 08:59:37 -0700 | [diff] [blame] | 1579 | otError error = OT_ERROR_NONE; |
| 1580 | const otMeshLocalPrefix *mlPrefix = otThreadGetMeshLocalPrefix(mInstance); |
| 1581 | otIp6Address addr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1582 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1583 | VerifyOrExit(mlPrefix != nullptr, OT_NOOP); // If `mlPrefix` is nullptr send empty response. |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1584 | |
Jonathan Hui | c116441 | 2018-08-17 08:59:37 -0700 | [diff] [blame] | 1585 | memcpy(addr.mFields.m8, mlPrefix->m8, 8); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1586 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1587 | // Zero out the last 8 bytes. |
| 1588 | memset(addr.mFields.m8 + 8, 0, 8); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1589 | |
Jintao Lin | 8788cf5 | 2020-01-10 10:15:23 +0800 | [diff] [blame] | 1590 | SuccessOrExit(error = mEncoder.WriteIp6Address(addr)); // Mesh local prefix |
| 1591 | SuccessOrExit(error = mEncoder.WriteUint8(OT_IP6_PREFIX_BITSIZE)); // Prefix length (in bits) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1592 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1593 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1594 | return error; |
| 1595 | } |
| 1596 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1597 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_IPV6_ML_PREFIX>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1598 | { |
Jonathan Hui | c116441 | 2018-08-17 08:59:37 -0700 | [diff] [blame] | 1599 | otError error = OT_ERROR_NONE; |
| 1600 | const otIp6Address *meshLocalPrefix; |
| 1601 | uint8_t prefixLength; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1602 | |
rongli | 11f3260 | 2018-03-20 23:55:41 +0800 | [diff] [blame] | 1603 | SuccessOrExit(error = mDecoder.ReadIp6Address(meshLocalPrefix)); |
| 1604 | SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); |
Jintao Lin | 8788cf5 | 2020-01-10 10:15:23 +0800 | [diff] [blame] | 1605 | VerifyOrExit(prefixLength == OT_IP6_PREFIX_BITSIZE, error = OT_ERROR_INVALID_ARGS); |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1606 | |
Jonathan Hui | c116441 | 2018-08-17 08:59:37 -0700 | [diff] [blame] | 1607 | error = otThreadSetMeshLocalPrefix(mInstance, reinterpret_cast<const otMeshLocalPrefix *>(meshLocalPrefix)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1608 | |
| 1609 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1610 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1611 | } |
| 1612 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1613 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_ML_ADDR>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1614 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1615 | otError error = OT_ERROR_NONE; |
| 1616 | const otIp6Address *ml64 = otThreadGetMeshLocalEid(mInstance); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1617 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1618 | VerifyOrExit(ml64 != nullptr, OT_NOOP); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1619 | SuccessOrExit(error = mEncoder.WriteIp6Address(*ml64)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1620 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1621 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1622 | return error; |
| 1623 | } |
| 1624 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1625 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_LL_ADDR>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1626 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1627 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1628 | const otIp6Address *address = otThreadGetLinkLocalIp6Address(mInstance); |
| 1629 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1630 | VerifyOrExit(address != nullptr, OT_NOOP); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1631 | SuccessOrExit(error = mEncoder.WriteIp6Address(*address)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1632 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1633 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1634 | return error; |
| 1635 | } |
| 1636 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1637 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_ADDRESS_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1638 | { |
| 1639 | otError error = OT_ERROR_NONE; |
| 1640 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1641 | for (const otNetifAddress *address = otIp6GetUnicastAddresses(mInstance); address; address = address->mNext) |
| 1642 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1643 | SuccessOrExit(error = mEncoder.OpenStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1644 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1645 | SuccessOrExit(error = mEncoder.WriteIp6Address(address->mAddress)); |
| 1646 | SuccessOrExit(error = mEncoder.WriteUint8(address->mPrefixLength)); |
| 1647 | SuccessOrExit(error = mEncoder.WriteUint32(address->mPreferred ? 0xffffffff : 0)); |
| 1648 | SuccessOrExit(error = mEncoder.WriteUint32(address->mValid ? 0xffffffff : 0)); |
| 1649 | |
| 1650 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1651 | } |
| 1652 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1653 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1654 | return error; |
| 1655 | } |
| 1656 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1657 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_IPV6_ADDRESS_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1658 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1659 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1660 | otNetifAddress netifAddr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1661 | uint32_t preferredLifetime; |
| 1662 | uint32_t validLifetime; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1663 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1664 | SuccessOrExit(error = mDecoder.ReadIp6Address(netifAddr.mAddress)); |
| 1665 | SuccessOrExit(error = mDecoder.ReadUint8(netifAddr.mPrefixLength)); |
| 1666 | SuccessOrExit(error = mDecoder.ReadUint32(preferredLifetime)); |
| 1667 | SuccessOrExit(error = mDecoder.ReadUint32(validLifetime)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1668 | |
Markus Becker | bad53a2 | 2020-06-16 03:24:14 +0200 | [diff] [blame] | 1669 | netifAddr.mAddressOrigin = OT_ADDRESS_ORIGIN_MANUAL; |
| 1670 | netifAddr.mPreferred = (preferredLifetime != 0); |
| 1671 | netifAddr.mValid = (validLifetime != 0); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1672 | |
| 1673 | error = otIp6AddUnicastAddress(mInstance, &netifAddr); |
| 1674 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1675 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1676 | return error; |
| 1677 | } |
| 1678 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1679 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_IPV6_ADDRESS_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1680 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1681 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1682 | const otIp6Address *addrPtr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1683 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1684 | SuccessOrExit(error = mDecoder.ReadIp6Address(addrPtr)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1685 | |
| 1686 | error = otIp6RemoveUnicastAddress(mInstance, addrPtr); |
Abtin Keshavarzian | 02bdc69 | 2017-08-15 09:11:19 -0700 | [diff] [blame] | 1687 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1688 | // If address was not on the list, "remove" command is successful. |
| 1689 | if (error == OT_ERROR_NOT_FOUND) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1690 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1691 | error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1692 | } |
| 1693 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1694 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1695 | return error; |
| 1696 | } |
| 1697 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1698 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_ROUTE_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1699 | { |
| 1700 | // TODO: Implement get route table |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1701 | return mEncoder.OverwriteWithLastStatusError(SPINEL_STATUS_UNIMPLEMENTED); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1702 | } |
| 1703 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1704 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1705 | { |
Jonathan Hui | f602dcd | 2018-03-13 18:10:28 +0000 | [diff] [blame] | 1706 | return mEncoder.WriteBool(otIcmp6GetEchoMode(mInstance) != OT_ICMP6_ECHO_HANDLER_DISABLED); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1707 | } |
| 1708 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1709 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1710 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1711 | bool enabled = false; |
| 1712 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1713 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1714 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1715 | |
Jonathan Hui | f602dcd | 2018-03-13 18:10:28 +0000 | [diff] [blame] | 1716 | otIcmp6SetEchoMode(mInstance, enabled ? OT_ICMP6_ECHO_HANDLER_ALL : OT_ICMP6_ECHO_HANDLER_DISABLED); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1717 | |
| 1718 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1719 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1720 | } |
| 1721 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1722 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1723 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1724 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1725 | const otNetifMulticastAddress *address; |
| 1726 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1727 | for (address = otIp6GetMulticastAddresses(mInstance); address; address = address->mNext) |
| 1728 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1729 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 1730 | SuccessOrExit(error = mEncoder.WriteIp6Address(address->mAddress)); |
| 1731 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1732 | } |
| 1733 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1734 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1735 | return error; |
| 1736 | } |
| 1737 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1738 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1739 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1740 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1741 | const otIp6Address *addrPtr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1742 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1743 | SuccessOrExit(error = mDecoder.ReadIp6Address(addrPtr)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1744 | |
| 1745 | error = otIp6SubscribeMulticastAddress(mInstance, addrPtr); |
Abtin Keshavarzian | 02bdc69 | 2017-08-15 09:11:19 -0700 | [diff] [blame] | 1746 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1747 | if (error == OT_ERROR_ALREADY) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1748 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1749 | error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1750 | } |
| 1751 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1752 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1753 | return error; |
| 1754 | } |
| 1755 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1756 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1757 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1758 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1759 | const otIp6Address *addrPtr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1760 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1761 | SuccessOrExit(error = mDecoder.ReadIp6Address(addrPtr)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1762 | |
| 1763 | error = otIp6UnsubscribeMulticastAddress(mInstance, addrPtr); |
Abtin Keshavarzian | 02bdc69 | 2017-08-15 09:11:19 -0700 | [diff] [blame] | 1764 | |
| 1765 | // If the address was not on the list, "remove" command is successful, |
| 1766 | // and we respond with a `SPINEL_STATUS_OK` status. |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1767 | if (error == OT_ERROR_NOT_FOUND) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1768 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1769 | error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1770 | } |
| 1771 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1772 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1773 | return error; |
| 1774 | } |
| 1775 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1776 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD_MODE>(void) |
Jonathan Hui | f602dcd | 2018-03-13 18:10:28 +0000 | [diff] [blame] | 1777 | { |
| 1778 | spinel_ipv6_icmp_ping_offload_mode_t mode = SPINEL_IPV6_ICMP_PING_OFFLOAD_DISABLED; |
| 1779 | |
| 1780 | switch (otIcmp6GetEchoMode(mInstance)) |
| 1781 | { |
| 1782 | case OT_ICMP6_ECHO_HANDLER_DISABLED: |
| 1783 | mode = SPINEL_IPV6_ICMP_PING_OFFLOAD_DISABLED; |
| 1784 | break; |
| 1785 | case OT_ICMP6_ECHO_HANDLER_UNICAST_ONLY: |
| 1786 | mode = SPINEL_IPV6_ICMP_PING_OFFLOAD_UNICAST_ONLY; |
| 1787 | break; |
| 1788 | case OT_ICMP6_ECHO_HANDLER_MULTICAST_ONLY: |
| 1789 | mode = SPINEL_IPV6_ICMP_PING_OFFLOAD_MULTICAST_ONLY; |
| 1790 | break; |
| 1791 | case OT_ICMP6_ECHO_HANDLER_ALL: |
| 1792 | mode = SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL; |
| 1793 | break; |
| 1794 | }; |
| 1795 | |
| 1796 | return mEncoder.WriteUint8(mode); |
| 1797 | } |
| 1798 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1799 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_IPV6_ICMP_PING_OFFLOAD_MODE>(void) |
Jonathan Hui | f602dcd | 2018-03-13 18:10:28 +0000 | [diff] [blame] | 1800 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1801 | otError error = OT_ERROR_NONE; |
| 1802 | otIcmp6EchoMode mode = OT_ICMP6_ECHO_HANDLER_DISABLED; |
| 1803 | uint8_t spinelMode; |
Jonathan Hui | f602dcd | 2018-03-13 18:10:28 +0000 | [diff] [blame] | 1804 | |
| 1805 | SuccessOrExit(error = mDecoder.ReadUint8(spinelMode)); |
| 1806 | |
| 1807 | switch (spinelMode) |
| 1808 | { |
| 1809 | case SPINEL_IPV6_ICMP_PING_OFFLOAD_DISABLED: |
| 1810 | mode = OT_ICMP6_ECHO_HANDLER_DISABLED; |
| 1811 | break; |
| 1812 | case SPINEL_IPV6_ICMP_PING_OFFLOAD_UNICAST_ONLY: |
| 1813 | mode = OT_ICMP6_ECHO_HANDLER_UNICAST_ONLY; |
| 1814 | break; |
| 1815 | case SPINEL_IPV6_ICMP_PING_OFFLOAD_MULTICAST_ONLY: |
| 1816 | mode = OT_ICMP6_ECHO_HANDLER_MULTICAST_ONLY; |
| 1817 | break; |
| 1818 | case SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL: |
| 1819 | mode = OT_ICMP6_ECHO_HANDLER_ALL; |
| 1820 | break; |
| 1821 | }; |
| 1822 | |
| 1823 | otIcmp6SetEchoMode(mInstance, mode); |
| 1824 | |
| 1825 | exit: |
| 1826 | return error; |
| 1827 | } |
| 1828 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1829 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_RLOC16_DEBUG_PASSTHRU>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1830 | { |
| 1831 | // Note reverse logic: passthru enabled = filter disabled |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1832 | return mEncoder.WriteBool(!otIp6IsReceiveFilterEnabled(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1833 | } |
| 1834 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1835 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_RLOC16_DEBUG_PASSTHRU>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1836 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1837 | bool enabled = false; |
| 1838 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1839 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1840 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1841 | |
| 1842 | // Note reverse logic: passthru enabled = filter disabled |
| 1843 | otIp6SetReceiveFilterEnabled(mInstance, !enabled); |
| 1844 | |
| 1845 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1846 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1847 | } |
| 1848 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1849 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_OFF_MESH_ROUTES>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1850 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1851 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1852 | otExternalRouteConfig routeConfig; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1853 | otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT; |
| 1854 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1855 | while (otNetDataGetNextRoute(mInstance, &iter, &routeConfig) == OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1856 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1857 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 1858 | |
| 1859 | SuccessOrExit(error = mEncoder.WriteIp6Address(routeConfig.mPrefix.mPrefix)); |
| 1860 | SuccessOrExit(error = mEncoder.WriteUint8(routeConfig.mPrefix.mLength)); |
| 1861 | SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mStable)); |
| 1862 | SuccessOrExit(error = mEncoder.WriteUint8(ExternalRoutePreferenceToFlagByte(routeConfig.mPreference))); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1863 | SuccessOrExit(error = mEncoder.WriteBool(false)); // IsLocal |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1864 | SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mNextHopIsThisDevice)); |
| 1865 | SuccessOrExit(error = mEncoder.WriteUint16(routeConfig.mRloc16)); |
| 1866 | |
| 1867 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1868 | } |
| 1869 | |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 1870 | #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Abtin Keshavarzian | 2c8f50b | 2017-09-01 21:27:58 -0700 | [diff] [blame] | 1871 | |
| 1872 | iter = OT_NETWORK_DATA_ITERATOR_INIT; |
| 1873 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1874 | while (otBorderRouterGetNextRoute(mInstance, &iter, &routeConfig) == OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1875 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1876 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 1877 | |
| 1878 | SuccessOrExit(error = mEncoder.WriteIp6Address(routeConfig.mPrefix.mPrefix)); |
| 1879 | SuccessOrExit(error = mEncoder.WriteUint8(routeConfig.mPrefix.mLength)); |
| 1880 | SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mStable)); |
| 1881 | SuccessOrExit(error = mEncoder.WriteUint8(ExternalRoutePreferenceToFlagByte(routeConfig.mPreference))); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1882 | SuccessOrExit(error = mEncoder.WriteBool(true)); // IsLocal |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1883 | SuccessOrExit(error = mEncoder.WriteBool(routeConfig.mNextHopIsThisDevice)); |
| 1884 | SuccessOrExit(error = mEncoder.WriteUint16(routeConfig.mRloc16)); |
| 1885 | |
| 1886 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1887 | } |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 1888 | #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1889 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1890 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1891 | return error; |
| 1892 | } |
| 1893 | |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 1894 | #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1895 | static int FlagByteToExternalRoutePreference(uint8_t aFlags) |
| 1896 | { |
| 1897 | int route_preference = 0; |
| 1898 | |
| 1899 | switch (aFlags & SPINEL_NET_FLAG_PREFERENCE_MASK) |
| 1900 | { |
| 1901 | case SPINEL_ROUTE_PREFERENCE_HIGH: |
| 1902 | route_preference = OT_ROUTE_PREFERENCE_HIGH; |
| 1903 | break; |
| 1904 | |
| 1905 | case SPINEL_ROUTE_PREFERENCE_MEDIUM: |
| 1906 | route_preference = OT_ROUTE_PREFERENCE_MED; |
| 1907 | break; |
| 1908 | |
| 1909 | case SPINEL_ROUTE_PREFERENCE_LOW: |
| 1910 | route_preference = OT_ROUTE_PREFERENCE_LOW; |
| 1911 | break; |
| 1912 | } |
| 1913 | |
| 1914 | return route_preference; |
| 1915 | } |
| 1916 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1917 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_THREAD_OFF_MESH_ROUTES>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1918 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1919 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1920 | otExternalRouteConfig routeConfig; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1921 | bool stable = false; |
| 1922 | uint8_t flags = 0; |
| 1923 | uint8_t prefixLength; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1924 | |
| 1925 | memset(&routeConfig, 0, sizeof(otExternalRouteConfig)); |
| 1926 | |
Abtin Keshavarzian | 31ce3d4 | 2019-08-01 10:30:08 -0700 | [diff] [blame] | 1927 | VerifyOrExit(mAllowLocalNetworkDataChange, error = OT_ERROR_INVALID_STATE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1928 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1929 | SuccessOrExit(error = mDecoder.ReadIp6Address(routeConfig.mPrefix.mPrefix)); |
Łukasz Duda | 7b084ec | 2017-10-25 17:54:17 +0200 | [diff] [blame] | 1930 | SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1931 | SuccessOrExit(error = mDecoder.ReadBool(stable)); |
| 1932 | SuccessOrExit(error = mDecoder.ReadUint8(flags)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1933 | |
Łukasz Duda | 7b084ec | 2017-10-25 17:54:17 +0200 | [diff] [blame] | 1934 | routeConfig.mPrefix.mLength = prefixLength; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1935 | routeConfig.mStable = stable; |
| 1936 | routeConfig.mPreference = FlagByteToExternalRoutePreference(flags); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1937 | |
| 1938 | error = otBorderRouterAddRoute(mInstance, &routeConfig); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1939 | |
| 1940 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1941 | return error; |
| 1942 | } |
| 1943 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1944 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_THREAD_OFF_MESH_ROUTES>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1945 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1946 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1947 | otIp6Prefix ip6Prefix; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1948 | uint8_t prefixLength; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1949 | |
| 1950 | memset(&ip6Prefix, 0, sizeof(otIp6Prefix)); |
| 1951 | |
Abtin Keshavarzian | 31ce3d4 | 2019-08-01 10:30:08 -0700 | [diff] [blame] | 1952 | VerifyOrExit(mAllowLocalNetworkDataChange, error = OT_ERROR_INVALID_STATE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1953 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1954 | SuccessOrExit(error = mDecoder.ReadIp6Address(ip6Prefix.mPrefix)); |
Łukasz Duda | 7b084ec | 2017-10-25 17:54:17 +0200 | [diff] [blame] | 1955 | SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); |
| 1956 | |
| 1957 | ip6Prefix.mLength = prefixLength; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1958 | |
| 1959 | error = otBorderRouterRemoveRoute(mInstance, &ip6Prefix); |
Abtin Keshavarzian | 02bdc69 | 2017-08-15 09:11:19 -0700 | [diff] [blame] | 1960 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1961 | // If the route prefix was not on the list, "remove" command is successful. |
| 1962 | if (error == OT_ERROR_NOT_FOUND) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1963 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1964 | error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1965 | } |
| 1966 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 1967 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1968 | return error; |
| 1969 | } |
Jonathan Hui | f184973 | 2019-07-16 12:31:11 -0700 | [diff] [blame] | 1970 | #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1971 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 1972 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_STREAM_NET>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1973 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1974 | const uint8_t *framePtr = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1975 | uint16_t frameLen = 0; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1976 | const uint8_t *metaPtr = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1977 | uint16_t metaLen = 0; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1978 | otMessage * message = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 1979 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1980 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 1981 | SuccessOrExit(error = mDecoder.ReadDataWithLen(framePtr, frameLen)); |
| 1982 | SuccessOrExit(error = mDecoder.ReadData(metaPtr, metaLen)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1983 | |
| 1984 | // We ignore metadata for now. |
| 1985 | // May later include TX power, allow retransmits, etc... |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1986 | |
Zhanglong Xia | 19f2533 | 2018-12-20 05:55:26 +0800 | [diff] [blame] | 1987 | // STREAM_NET requires layer 2 security. |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 1988 | message = otIp6NewMessageFromBuffer(mInstance, framePtr, frameLen, nullptr); |
| 1989 | VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1990 | |
| 1991 | error = otIp6Send(mInstance, message); |
| 1992 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1993 | exit: |
| 1994 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1995 | if (error == OT_ERROR_NONE) |
| 1996 | { |
| 1997 | mInboundSecureIpFrameCounter++; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 1998 | } |
| 1999 | else |
| 2000 | { |
| 2001 | mDroppedInboundIpFrameCounter++; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2002 | } |
| 2003 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2004 | return error; |
| 2005 | } |
| 2006 | |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 2007 | #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2008 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2009 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_JAM_DETECT_ENABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2010 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2011 | return mEncoder.WriteBool(otJamDetectionIsEnabled(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2012 | } |
| 2013 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2014 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_JAM_DETECTED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2015 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2016 | return mEncoder.WriteBool(otJamDetectionGetState(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2017 | } |
| 2018 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2019 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_JAM_DETECT_RSSI_THRESHOLD>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2020 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2021 | return mEncoder.WriteInt8(otJamDetectionGetRssiThreshold(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2022 | } |
| 2023 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2024 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_JAM_DETECT_WINDOW>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2025 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2026 | return mEncoder.WriteUint8(otJamDetectionGetWindow(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2027 | } |
| 2028 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2029 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_JAM_DETECT_BUSY>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2030 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2031 | return mEncoder.WriteUint8(otJamDetectionGetBusyPeriod(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2032 | } |
| 2033 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2034 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_JAM_DETECT_HISTORY_BITMAP>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2035 | { |
Abtin Keshavarzian | 07f4ae1 | 2017-12-07 10:22:24 -0800 | [diff] [blame] | 2036 | return mEncoder.WriteUint64(otJamDetectionGetHistoryBitmap(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2037 | } |
| 2038 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2039 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_JAM_DETECT_ENABLE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2040 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2041 | bool enabled; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2042 | otError error = OT_ERROR_NONE; |
| 2043 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2044 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2045 | |
| 2046 | if (enabled) |
| 2047 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 2048 | IgnoreError(otJamDetectionStart(mInstance, &NcpBase::HandleJamStateChange_Jump, this)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2049 | } |
| 2050 | else |
| 2051 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 2052 | IgnoreError(otJamDetectionStop(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2056 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2059 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_JAM_DETECT_RSSI_THRESHOLD>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2060 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2061 | int8_t threshold = 0; |
| 2062 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2063 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2064 | SuccessOrExit(error = mDecoder.ReadInt8(threshold)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2065 | |
| 2066 | error = otJamDetectionSetRssiThreshold(mInstance, threshold); |
| 2067 | |
| 2068 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2069 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2070 | } |
| 2071 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2072 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_JAM_DETECT_WINDOW>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2073 | { |
| 2074 | uint8_t window = 0; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2075 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2076 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2077 | SuccessOrExit(error = mDecoder.ReadUint8(window)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2078 | |
| 2079 | error = otJamDetectionSetWindow(mInstance, window); |
| 2080 | |
| 2081 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2082 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2083 | } |
| 2084 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2085 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_JAM_DETECT_BUSY>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2086 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2087 | uint8_t busy = 0; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2088 | otError error = OT_ERROR_NONE; |
| 2089 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2090 | SuccessOrExit(error = mDecoder.ReadUint8(busy)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2091 | |
| 2092 | error = otJamDetectionSetBusyPeriod(mInstance, busy); |
| 2093 | |
| 2094 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2095 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | void NcpBase::HandleJamStateChange_Jump(bool aJamState, void *aContext) |
| 2099 | { |
| 2100 | static_cast<NcpBase *>(aContext)->HandleJamStateChange(aJamState); |
| 2101 | } |
| 2102 | |
| 2103 | void NcpBase::HandleJamStateChange(bool aJamState) |
| 2104 | { |
| 2105 | OT_UNUSED_VARIABLE(aJamState); |
| 2106 | |
| 2107 | mChangedPropsSet.AddProperty(SPINEL_PROP_JAM_DETECTED); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 2108 | mUpdateChangedPropsTask.Post(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2109 | } |
| 2110 | |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 2111 | #endif // OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2112 | |
Jonathan Hui | aa82391 | 2019-07-15 12:03:36 -0700 | [diff] [blame] | 2113 | #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE |
Abtin Keshavarzian | 1ca81fb | 2018-08-02 15:21:11 -0700 | [diff] [blame] | 2114 | |
| 2115 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CHILD_SUPERVISION_CHECK_TIMEOUT>(void) |
| 2116 | { |
| 2117 | return mEncoder.WriteUint16(otChildSupervisionGetCheckTimeout(mInstance)); |
| 2118 | } |
| 2119 | |
| 2120 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_CHILD_SUPERVISION_CHECK_TIMEOUT>(void) |
| 2121 | { |
| 2122 | otError error = OT_ERROR_NONE; |
| 2123 | uint16_t timeout; |
| 2124 | |
| 2125 | SuccessOrExit(error = mDecoder.ReadUint16(timeout)); |
| 2126 | otChildSupervisionSetCheckTimeout(mInstance, timeout); |
| 2127 | |
| 2128 | exit: |
| 2129 | return error; |
| 2130 | } |
| 2131 | |
Jonathan Hui | aa82391 | 2019-07-15 12:03:36 -0700 | [diff] [blame] | 2132 | #endif // OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE |
Abtin Keshavarzian | 1ca81fb | 2018-08-02 15:21:11 -0700 | [diff] [blame] | 2133 | |
Jonathan Hui | 01ebc18 | 2019-07-12 15:21:49 -0700 | [diff] [blame] | 2134 | #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2135 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2136 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_INTERVAL>(void) |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2137 | { |
| 2138 | return mEncoder.WriteUint32(otChannelMonitorGetSampleInterval(mInstance)); |
| 2139 | } |
| 2140 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2141 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CHANNEL_MONITOR_RSSI_THRESHOLD>(void) |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2142 | { |
| 2143 | return mEncoder.WriteInt8(otChannelMonitorGetRssiThreshold(mInstance)); |
| 2144 | } |
| 2145 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2146 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_WINDOW>(void) |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2147 | { |
| 2148 | return mEncoder.WriteUint32(otChannelMonitorGetSampleWindow(mInstance)); |
| 2149 | } |
| 2150 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2151 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CHANNEL_MONITOR_SAMPLE_COUNT>(void) |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2152 | { |
| 2153 | return mEncoder.WriteUint32(otChannelMonitorGetSampleCount(mInstance)); |
| 2154 | } |
| 2155 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2156 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CHANNEL_MONITOR_CHANNEL_OCCUPANCY>(void) |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2157 | { |
Shu Chen | a43a263 | 2019-04-09 12:25:16 +0800 | [diff] [blame] | 2158 | otError error = OT_ERROR_NONE; |
| 2159 | uint32_t channelMask = otLinkGetSupportedChannelMask(mInstance); |
| 2160 | uint8_t channelNum = sizeof(channelMask) * CHAR_BIT; |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2161 | |
Shu Chen | a43a263 | 2019-04-09 12:25:16 +0800 | [diff] [blame] | 2162 | for (uint8_t channel = 0; channel < channelNum; channel++) |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2163 | { |
Shu Chen | a43a263 | 2019-04-09 12:25:16 +0800 | [diff] [blame] | 2164 | if (!((1UL << channel) & channelMask)) |
| 2165 | { |
| 2166 | continue; |
| 2167 | } |
| 2168 | |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2169 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2170 | |
| 2171 | SuccessOrExit(error = mEncoder.WriteUint8(channel)); |
Abtin Keshavarzian | df45240 | 2018-04-16 11:17:09 -0700 | [diff] [blame] | 2172 | SuccessOrExit(error = mEncoder.WriteUint16(otChannelMonitorGetChannelOccupancy(mInstance, channel))); |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2173 | |
| 2174 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 2175 | } |
| 2176 | |
| 2177 | exit: |
| 2178 | return error; |
| 2179 | } |
| 2180 | |
Jonathan Hui | 01ebc18 | 2019-07-12 15:21:49 -0700 | [diff] [blame] | 2181 | #endif // OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE |
Abtin Keshavarzian | ba5317a | 2018-01-13 13:37:04 -0800 | [diff] [blame] | 2182 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2183 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_CCA_FAILURE_RATE>(void) |
Abtin Keshavarzian | 171c951 | 2018-01-23 09:10:13 -0800 | [diff] [blame] | 2184 | { |
| 2185 | return mEncoder.WriteUint16(otLinkGetCcaFailureRate(mInstance)); |
| 2186 | } |
| 2187 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2188 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_TOTAL>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2189 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2190 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxTotal); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2191 | } |
| 2192 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2193 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_ACK_REQ>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2194 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2195 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxAckRequested); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2196 | } |
| 2197 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2198 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_ACKED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2199 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2200 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxAcked); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2201 | } |
| 2202 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2203 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_NO_ACK_REQ>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2204 | { |
| 2205 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxNoAckRequested); |
| 2206 | } |
| 2207 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2208 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_DATA>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2209 | { |
| 2210 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxData); |
| 2211 | } |
| 2212 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2213 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_DATA_POLL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2214 | { |
| 2215 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxDataPoll); |
| 2216 | } |
| 2217 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2218 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_BEACON>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2219 | { |
| 2220 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxBeacon); |
| 2221 | } |
| 2222 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2223 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_BEACON_REQ>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2224 | { |
| 2225 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxBeaconRequest); |
| 2226 | } |
| 2227 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2228 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_OTHER>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2229 | { |
| 2230 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxOther); |
| 2231 | } |
| 2232 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2233 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_RETRY>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2234 | { |
| 2235 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxRetry); |
| 2236 | } |
| 2237 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2238 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_ERR_CCA>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2239 | { |
| 2240 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxErrCca); |
| 2241 | } |
| 2242 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2243 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_UNICAST>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2244 | { |
| 2245 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxUnicast); |
| 2246 | } |
| 2247 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2248 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_PKT_BROADCAST>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2249 | { |
| 2250 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxBroadcast); |
| 2251 | } |
| 2252 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2253 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_ERR_ABORT>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2254 | { |
| 2255 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mTxErrAbort); |
| 2256 | } |
| 2257 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2258 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_TOTAL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2259 | { |
| 2260 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxTotal); |
| 2261 | } |
| 2262 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2263 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_DATA>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2264 | { |
| 2265 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxData); |
| 2266 | } |
| 2267 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2268 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_DATA_POLL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2269 | { |
| 2270 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxDataPoll); |
| 2271 | } |
| 2272 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2273 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_BEACON>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2274 | { |
| 2275 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxBeacon); |
| 2276 | } |
| 2277 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2278 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_BEACON_REQ>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2279 | { |
| 2280 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxBeaconRequest); |
| 2281 | } |
| 2282 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2283 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_OTHER>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2284 | { |
| 2285 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxOther); |
| 2286 | } |
| 2287 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2288 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_FILT_WL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2289 | { |
rongli | b1baa7d | 2017-10-14 00:33:23 +0800 | [diff] [blame] | 2290 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxAddressFiltered); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2293 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_FILT_DA>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2294 | { |
| 2295 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxDestAddrFiltered); |
| 2296 | } |
| 2297 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2298 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_DUP>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2299 | { |
| 2300 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxDuplicated); |
| 2301 | } |
| 2302 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2303 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_UNICAST>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2304 | { |
| 2305 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxUnicast); |
| 2306 | } |
| 2307 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2308 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_PKT_BROADCAST>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2309 | { |
| 2310 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxBroadcast); |
| 2311 | } |
| 2312 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2313 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_ERR_EMPTY>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2314 | { |
| 2315 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxErrNoFrame); |
| 2316 | } |
| 2317 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2318 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_ERR_UKWN_NBR>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2319 | { |
| 2320 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxErrUnknownNeighbor); |
| 2321 | } |
| 2322 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2323 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_ERR_NVLD_SADDR>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2324 | { |
| 2325 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxErrInvalidSrcAddr); |
| 2326 | } |
| 2327 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2328 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_ERR_SECURITY>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2329 | { |
| 2330 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxErrSec); |
| 2331 | } |
| 2332 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2333 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_ERR_BAD_FCS>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2334 | { |
| 2335 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxErrFcs); |
| 2336 | } |
| 2337 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2338 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_ERR_OTHER>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2339 | { |
| 2340 | return mEncoder.WriteUint32(otLinkGetCounters(mInstance)->mRxErrOther); |
| 2341 | } |
| 2342 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2343 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_IP_SEC_TOTAL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2344 | { |
| 2345 | return mEncoder.WriteUint32(mInboundSecureIpFrameCounter); |
| 2346 | } |
| 2347 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2348 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_IP_INSEC_TOTAL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2349 | { |
| 2350 | return mEncoder.WriteUint32(mInboundInsecureIpFrameCounter); |
| 2351 | } |
| 2352 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2353 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_IP_DROPPED>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2354 | { |
| 2355 | return mEncoder.WriteUint32(mDroppedInboundIpFrameCounter); |
| 2356 | } |
| 2357 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2358 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_IP_SEC_TOTAL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2359 | { |
| 2360 | return mEncoder.WriteUint32(mOutboundSecureIpFrameCounter); |
| 2361 | } |
| 2362 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2363 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_IP_INSEC_TOTAL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2364 | { |
| 2365 | return mEncoder.WriteUint32(mOutboundInsecureIpFrameCounter); |
| 2366 | } |
| 2367 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2368 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_IP_DROPPED>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2369 | { |
| 2370 | return mEncoder.WriteUint32(mDroppedOutboundIpFrameCounter); |
| 2371 | } |
| 2372 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2373 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_TX_SPINEL_TOTAL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2374 | { |
| 2375 | return mEncoder.WriteUint32(mTxSpinelFrameCounter); |
| 2376 | } |
| 2377 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2378 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_SPINEL_TOTAL>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2379 | { |
| 2380 | return mEncoder.WriteUint32(mRxSpinelFrameCounter); |
| 2381 | } |
| 2382 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2383 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_SPINEL_OUT_OF_ORDER_TID>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2384 | { |
| 2385 | return mEncoder.WriteUint32(mRxSpinelOutOfOrderTidCounter); |
| 2386 | } |
| 2387 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2388 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_RX_SPINEL_ERR>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2389 | { |
| 2390 | return mEncoder.WriteUint32(mFramingErrorCounter); |
| 2391 | } |
| 2392 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2393 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_IP_TX_SUCCESS>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2394 | { |
| 2395 | return mEncoder.WriteUint32(otThreadGetIp6Counters(mInstance)->mTxSuccess); |
| 2396 | } |
| 2397 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2398 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_IP_RX_SUCCESS>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2399 | { |
| 2400 | return mEncoder.WriteUint32(otThreadGetIp6Counters(mInstance)->mRxSuccess); |
| 2401 | } |
| 2402 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2403 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_IP_TX_FAILURE>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2404 | { |
| 2405 | return mEncoder.WriteUint32(otThreadGetIp6Counters(mInstance)->mTxFailure); |
| 2406 | } |
| 2407 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2408 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_IP_RX_FAILURE>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2409 | { |
| 2410 | return mEncoder.WriteUint32(otThreadGetIp6Counters(mInstance)->mRxFailure); |
| 2411 | } |
| 2412 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2413 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MSG_BUFFER_COUNTERS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2414 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2415 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2416 | otBufferInfo bufferInfo; |
| 2417 | |
| 2418 | otMessageGetBufferInfo(mInstance, &bufferInfo); |
| 2419 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2420 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mTotalBuffers)); |
| 2421 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mFreeBuffers)); |
| 2422 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.m6loSendMessages)); |
| 2423 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.m6loSendBuffers)); |
| 2424 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.m6loReassemblyMessages)); |
| 2425 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.m6loReassemblyBuffers)); |
| 2426 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mIp6Messages)); |
| 2427 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mIp6Buffers)); |
| 2428 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mMplMessages)); |
| 2429 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mMplBuffers)); |
| 2430 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mMleMessages)); |
| 2431 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mMleBuffers)); |
| 2432 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mArpMessages)); |
| 2433 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mArpBuffers)); |
| 2434 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mCoapMessages)); |
| 2435 | SuccessOrExit(mEncoder.WriteUint16(bufferInfo.mCoapBuffers)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2436 | |
| 2437 | exit: |
| 2438 | return error; |
| 2439 | } |
| 2440 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2441 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_ALL_MAC_COUNTERS>(void) |
Abtin Keshavarzian | 23069bb | 2018-01-23 09:00:27 -0800 | [diff] [blame] | 2442 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2443 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 23069bb | 2018-01-23 09:00:27 -0800 | [diff] [blame] | 2444 | const otMacCounters *counters = otLinkGetCounters(mInstance); |
| 2445 | |
Abtin Keshavarzian | 23069bb | 2018-01-23 09:00:27 -0800 | [diff] [blame] | 2446 | // Encode Tx related counters |
| 2447 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2448 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxTotal)); |
| 2449 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxUnicast)); |
| 2450 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxBroadcast)); |
| 2451 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxAckRequested)); |
| 2452 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxAcked)); |
| 2453 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxNoAckRequested)); |
| 2454 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxData)); |
| 2455 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxDataPoll)); |
| 2456 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxBeacon)); |
| 2457 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxBeaconRequest)); |
| 2458 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxOther)); |
| 2459 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxRetry)); |
| 2460 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxErrCca)); |
| 2461 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxErrAbort)); |
| 2462 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxErrBusyChannel)); |
Paweł Wańczyk | c646e6f | 2019-12-18 19:23:43 +0100 | [diff] [blame] | 2463 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxDirectMaxRetryExpiry)); |
| 2464 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxIndirectMaxRetryExpiry)); |
Abtin Keshavarzian | 23069bb | 2018-01-23 09:00:27 -0800 | [diff] [blame] | 2465 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 2466 | |
| 2467 | // Encode Rx related counters |
| 2468 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2469 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxTotal)); |
| 2470 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxUnicast)); |
| 2471 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxBroadcast)); |
| 2472 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxData)); |
| 2473 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxDataPoll)); |
| 2474 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxBeacon)); |
| 2475 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxBeaconRequest)); |
| 2476 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxOther)); |
| 2477 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxAddressFiltered)); |
| 2478 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxDestAddrFiltered)); |
| 2479 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxDuplicated)); |
| 2480 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrNoFrame)); |
| 2481 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrUnknownNeighbor)); |
| 2482 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrInvalidSrcAddr)); |
| 2483 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrSec)); |
| 2484 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrFcs)); |
| 2485 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxErrOther)); |
| 2486 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 2487 | |
| 2488 | exit: |
| 2489 | return error; |
| 2490 | } |
| 2491 | |
Abtin Keshavarzian | 112d1bb | 2019-10-29 15:34:03 -0700 | [diff] [blame] | 2492 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_CNTR_ALL_MAC_COUNTERS>(void) |
| 2493 | { |
| 2494 | otLinkResetCounters(mInstance); |
| 2495 | |
| 2496 | return OT_ERROR_NONE; |
| 2497 | } |
| 2498 | |
Abtin Keshavarzian | bd4ca81 | 2019-02-06 08:41:50 -0800 | [diff] [blame] | 2499 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_MLE_COUNTERS>(void) |
| 2500 | { |
| 2501 | otError error = OT_ERROR_NONE; |
| 2502 | const otMleCounters *counters = otThreadGetMleCounters(mInstance); |
| 2503 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2504 | OT_ASSERT(counters != nullptr); |
Abtin Keshavarzian | bd4ca81 | 2019-02-06 08:41:50 -0800 | [diff] [blame] | 2505 | |
| 2506 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mDisabledRole)); |
| 2507 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mDetachedRole)); |
| 2508 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mChildRole)); |
| 2509 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mRouterRole)); |
| 2510 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mLeaderRole)); |
| 2511 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mAttachAttempts)); |
| 2512 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mPartitionIdChanges)); |
| 2513 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mBetterPartitionAttachAttempts)); |
| 2514 | SuccessOrExit(error = mEncoder.WriteUint16(counters->mParentChanges)); |
| 2515 | |
| 2516 | exit: |
| 2517 | return error; |
| 2518 | } |
| 2519 | |
Abtin Keshavarzian | 112d1bb | 2019-10-29 15:34:03 -0700 | [diff] [blame] | 2520 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_CNTR_MLE_COUNTERS>(void) |
| 2521 | { |
| 2522 | otThreadResetMleCounters(mInstance); |
| 2523 | |
| 2524 | return OT_ERROR_NONE; |
| 2525 | } |
| 2526 | |
| 2527 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_ALL_IP_COUNTERS>(void) |
| 2528 | { |
| 2529 | otError error = OT_ERROR_NONE; |
| 2530 | const otIpCounters *counters = otThreadGetIp6Counters(mInstance); |
| 2531 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2532 | OT_ASSERT(counters != nullptr); |
Abtin Keshavarzian | 112d1bb | 2019-10-29 15:34:03 -0700 | [diff] [blame] | 2533 | |
| 2534 | // Encode Tx related counters |
| 2535 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2536 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxSuccess)); |
| 2537 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mTxFailure)); |
| 2538 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 2539 | |
| 2540 | // Encode Rx related counters |
| 2541 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2542 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxSuccess)); |
| 2543 | SuccessOrExit(error = mEncoder.WriteUint32(counters->mRxFailure)); |
| 2544 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 2545 | |
| 2546 | exit: |
| 2547 | return error; |
| 2548 | } |
| 2549 | |
Paweł Wańczyk | c646e6f | 2019-12-18 19:23:43 +0100 | [diff] [blame] | 2550 | #if OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE |
| 2551 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CNTR_MAC_RETRY_HISTOGRAM>(void) |
| 2552 | { |
| 2553 | otError error = OT_ERROR_NONE; |
| 2554 | const uint32_t *histogramDirect; |
| 2555 | const uint32_t *histogramIndirect; |
| 2556 | uint8_t histogramDirectEntries; |
| 2557 | uint8_t histogramIndirectEntries; |
| 2558 | |
| 2559 | histogramDirect = otLinkGetTxDirectRetrySuccessHistogram(mInstance, &histogramDirectEntries); |
| 2560 | histogramIndirect = otLinkGetTxIndirectRetrySuccessHistogram(mInstance, &histogramIndirectEntries); |
| 2561 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2562 | OT_ASSERT((histogramDirectEntries == 0) || (histogramDirect != nullptr)); |
| 2563 | OT_ASSERT((histogramIndirectEntries == 0) || (histogramIndirect != nullptr)); |
Paweł Wańczyk | c646e6f | 2019-12-18 19:23:43 +0100 | [diff] [blame] | 2564 | |
| 2565 | // Encode direct message retries histogram |
| 2566 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2567 | for (uint8_t i = 0; i < histogramDirectEntries; i++) |
| 2568 | { |
| 2569 | SuccessOrExit(error = mEncoder.WriteUint32(histogramDirect[i])); |
| 2570 | } |
| 2571 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 2572 | |
| 2573 | // Encode indirect message retries histogram |
| 2574 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2575 | for (uint8_t i = 0; i < histogramIndirectEntries; i++) |
| 2576 | { |
| 2577 | SuccessOrExit(error = mEncoder.WriteUint32(histogramIndirect[i])); |
| 2578 | } |
| 2579 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 2580 | |
| 2581 | exit: |
| 2582 | return error; |
| 2583 | } |
| 2584 | |
| 2585 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_CNTR_MAC_RETRY_HISTOGRAM>(void) |
| 2586 | { |
| 2587 | otLinkResetTxRetrySuccessHistogram(mInstance); |
| 2588 | |
| 2589 | return OT_ERROR_NONE; |
| 2590 | } |
| 2591 | #endif // OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE |
| 2592 | |
Abtin Keshavarzian | 112d1bb | 2019-10-29 15:34:03 -0700 | [diff] [blame] | 2593 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_CNTR_ALL_IP_COUNTERS>(void) |
| 2594 | { |
| 2595 | otThreadResetIp6Counters(mInstance); |
| 2596 | |
| 2597 | return OT_ERROR_NONE; |
| 2598 | } |
| 2599 | |
Jonathan Hui | 0baaf1a | 2019-07-15 12:57:32 -0700 | [diff] [blame] | 2600 | #if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2601 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2602 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_WHITELIST>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2603 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2604 | otMacFilterEntry entry; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2605 | otMacFilterIterator iterator = OT_MAC_FILTER_ITERATOR_INIT; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2606 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2607 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2608 | while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) |
| 2609 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2610 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2611 | |
| 2612 | SuccessOrExit(error = mEncoder.WriteEui64(entry.mExtAddress)); |
| 2613 | SuccessOrExit(error = mEncoder.WriteInt8(entry.mRssIn)); |
| 2614 | |
| 2615 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2616 | } |
| 2617 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2618 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2619 | return error; |
| 2620 | } |
| 2621 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2622 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_WHITELIST_ENABLED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2623 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2624 | return mEncoder.WriteBool(otLinkFilterGetAddressMode(mInstance) == OT_MAC_FILTER_ADDRESS_MODE_WHITELIST); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2625 | } |
| 2626 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2627 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_BLACKLIST>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2628 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2629 | otMacFilterEntry entry; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2630 | otMacFilterIterator iterator = OT_MAC_FILTER_ITERATOR_INIT; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2631 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2632 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2633 | while (otLinkFilterGetNextAddress(mInstance, &iterator, &entry) == OT_ERROR_NONE) |
| 2634 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2635 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2636 | SuccessOrExit(error = mEncoder.WriteEui64(entry.mExtAddress)); |
| 2637 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2638 | } |
| 2639 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2640 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2641 | return error; |
| 2642 | } |
| 2643 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2644 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_BLACKLIST_ENABLED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2645 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2646 | return mEncoder.WriteBool(otLinkFilterGetAddressMode(mInstance) == OT_MAC_FILTER_ADDRESS_MODE_BLACKLIST); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2647 | } |
| 2648 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2649 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MAC_FIXED_RSS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2650 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2651 | otMacFilterEntry entry; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2652 | otMacFilterIterator iterator = OT_MAC_FILTER_ITERATOR_INIT; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2653 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2654 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2655 | while (otLinkFilterGetNextRssIn(mInstance, &iterator, &entry) == OT_ERROR_NONE) |
| 2656 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2657 | SuccessOrExit(error = mEncoder.OpenStruct()); |
| 2658 | |
| 2659 | SuccessOrExit(error = mEncoder.WriteEui64(entry.mExtAddress)); |
| 2660 | SuccessOrExit(error = mEncoder.WriteInt8(entry.mRssIn)); |
| 2661 | |
| 2662 | SuccessOrExit(error = mEncoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2663 | } |
| 2664 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2665 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2666 | return error; |
| 2667 | } |
| 2668 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2669 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MAC_WHITELIST>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2670 | { |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2671 | otError error = OT_ERROR_NONE; |
| 2672 | |
| 2673 | // First, clear the address filter entries. |
| 2674 | otLinkFilterClearAddresses(mInstance); |
| 2675 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2676 | while (mDecoder.GetRemainingLengthInStruct() > 0) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2677 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2678 | const otExtAddress *extAddress = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2679 | int8_t rss; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2680 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2681 | SuccessOrExit(error = mDecoder.OpenStruct()); |
| 2682 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2683 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2684 | if (!mDecoder.IsAllReadInStruct()) |
| 2685 | { |
| 2686 | SuccessOrExit(error = mDecoder.ReadInt8(rss)); |
| 2687 | } |
| 2688 | else |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2689 | { |
| 2690 | rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2691 | } |
| 2692 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2693 | SuccessOrExit(error = mDecoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2694 | |
| 2695 | error = otLinkFilterAddAddress(mInstance, extAddress); |
| 2696 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2697 | if (error == OT_ERROR_ALREADY) |
| 2698 | { |
| 2699 | error = OT_ERROR_NONE; |
| 2700 | } |
| 2701 | |
| 2702 | SuccessOrExit(error); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2703 | |
| 2704 | if (rss != OT_MAC_FILTER_FIXED_RSS_DISABLED) |
| 2705 | { |
| 2706 | SuccessOrExit(error = otLinkFilterAddRssIn(mInstance, extAddress, rss)); |
| 2707 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | exit: |
| 2711 | // If we had an error, we may have actually changed |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2712 | // the state of the whitelist, so we need to report |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2713 | // those incomplete changes via an asynchronous |
| 2714 | // change event. |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2715 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2716 | if (error != OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2717 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 2718 | IgnoreError(WritePropertyValueIsFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_PROP_MAC_WHITELIST)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | return error; |
| 2722 | } |
| 2723 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2724 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MAC_WHITELIST_ENABLED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2725 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2726 | bool enabled; |
| 2727 | otError error = OT_ERROR_NONE; |
| 2728 | otMacFilterAddressMode mode = OT_MAC_FILTER_ADDRESS_MODE_DISABLED; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2729 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2730 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2731 | |
| 2732 | if (enabled) |
| 2733 | { |
| 2734 | mode = OT_MAC_FILTER_ADDRESS_MODE_WHITELIST; |
| 2735 | } |
| 2736 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 2737 | otLinkFilterSetAddressMode(mInstance, mode); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2738 | |
| 2739 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2740 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2741 | } |
| 2742 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2743 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MAC_BLACKLIST>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2744 | { |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2745 | otError error = OT_ERROR_NONE; |
| 2746 | |
| 2747 | // First, clear the address filter entries. |
| 2748 | otLinkFilterClearAddresses(mInstance); |
| 2749 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2750 | while (mDecoder.GetRemainingLengthInStruct() > 0) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2751 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2752 | const otExtAddress *extAddress = nullptr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2753 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2754 | SuccessOrExit(error = mDecoder.OpenStruct()); |
| 2755 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
| 2756 | SuccessOrExit(error = mDecoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2757 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 2758 | otLinkFilterRemoveAddress(mInstance, extAddress); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | exit: |
| 2762 | // If we had an error, we may have actually changed |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2763 | // the state of the blacklist, so we need to report |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2764 | // those incomplete changes via an asynchronous |
| 2765 | // change event. |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2766 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2767 | if (error != OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2768 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 2769 | IgnoreError(WritePropertyValueIsFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_PROP_MAC_BLACKLIST)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | return error; |
| 2773 | } |
| 2774 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2775 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MAC_BLACKLIST_ENABLED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2776 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2777 | bool enabled; |
| 2778 | otError error = OT_ERROR_NONE; |
| 2779 | otMacFilterAddressMode mode = OT_MAC_FILTER_ADDRESS_MODE_DISABLED; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2780 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2781 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2782 | |
| 2783 | if (enabled) |
| 2784 | { |
| 2785 | mode = OT_MAC_FILTER_ADDRESS_MODE_BLACKLIST; |
| 2786 | } |
| 2787 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 2788 | otLinkFilterSetAddressMode(mInstance, mode); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2789 | |
| 2790 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2791 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2792 | } |
| 2793 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2794 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MAC_FIXED_RSS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2795 | { |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2796 | otError error = OT_ERROR_NONE; |
| 2797 | |
| 2798 | // First, clear the address filter entries. |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 2799 | otLinkFilterClearAllRssIn(mInstance); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2800 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2801 | while (mDecoder.GetRemainingLengthInStruct() > 0) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2802 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2803 | const otExtAddress *extAddress; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2804 | int8_t rss; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2805 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2806 | SuccessOrExit(error = mDecoder.OpenStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2807 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2808 | if (mDecoder.GetRemainingLengthInStruct() > sizeof(otExtAddress)) |
| 2809 | { |
| 2810 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
| 2811 | } |
| 2812 | else |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2813 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2814 | extAddress = nullptr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2815 | } |
| 2816 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2817 | SuccessOrExit(error = mDecoder.ReadInt8(rss)); |
| 2818 | |
| 2819 | SuccessOrExit(error = mDecoder.CloseStruct()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2820 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 2821 | if (extAddress != nullptr) |
| 2822 | { |
| 2823 | SuccessOrExit(error = otLinkFilterAddRssIn(mInstance, extAddress, rss)); |
| 2824 | } |
| 2825 | else |
| 2826 | { |
| 2827 | otLinkFilterSetDefaultRssIn(mInstance, rss); |
| 2828 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | exit: |
| 2832 | // If we had an error, we may have actually changed |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2833 | // the state of the RssIn filter, so we need to report |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2834 | // those incomplete changes via an asynchronous |
| 2835 | // change event. |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2836 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2837 | if (error != OT_ERROR_NONE) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2838 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 2839 | IgnoreError(WritePropertyValueIsFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_PROP_MAC_FIXED_RSS)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | return error; |
| 2843 | } |
Jonathan Hui | 0baaf1a | 2019-07-15 12:57:32 -0700 | [diff] [blame] | 2844 | #endif // OPENTHREAD_CONFIG_MAC_FILTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2845 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2846 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_MODE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2847 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2848 | uint8_t numericMode; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2849 | otLinkModeConfig modeConfig = otThreadGetLinkMode(mInstance); |
| 2850 | |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2851 | numericMode = LinkFlagsToFlagByte(modeConfig.mRxOnWhenIdle, modeConfig.mSecureDataRequests, modeConfig.mDeviceType, |
| 2852 | modeConfig.mNetworkData); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2853 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2854 | return mEncoder.WriteUint8(numericMode); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2855 | } |
| 2856 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2857 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_MODE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2858 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2859 | uint8_t numericMode = 0; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2860 | otLinkModeConfig modeConfig; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2861 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2862 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2863 | SuccessOrExit(mDecoder.ReadUint8(numericMode)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2864 | |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2865 | modeConfig.mRxOnWhenIdle = |
| 2866 | ((numericMode & SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE) == SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2867 | modeConfig.mSecureDataRequests = |
| 2868 | ((numericMode & SPINEL_THREAD_MODE_SECURE_DATA_REQUEST) == SPINEL_THREAD_MODE_SECURE_DATA_REQUEST); |
Jonathan Hui | 5a48983 | 2018-09-27 09:33:03 -0700 | [diff] [blame] | 2869 | modeConfig.mDeviceType = ((numericMode & SPINEL_THREAD_MODE_FULL_THREAD_DEV) == SPINEL_THREAD_MODE_FULL_THREAD_DEV); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2870 | modeConfig.mNetworkData = |
| 2871 | ((numericMode & SPINEL_THREAD_MODE_FULL_NETWORK_DATA) == SPINEL_THREAD_MODE_FULL_NETWORK_DATA); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2872 | |
| 2873 | error = otThreadSetLinkMode(mInstance, modeConfig); |
| 2874 | |
| 2875 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2876 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2877 | } |
| 2878 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2879 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_CHILD_TIMEOUT>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2880 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2881 | return mEncoder.WriteUint32(otThreadGetChildTimeout(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2882 | } |
| 2883 | |
Abtin Keshavarzian | d67c4e2 | 2018-08-01 22:55:35 -0700 | [diff] [blame] | 2884 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_CHILD_TIMEOUT>(void) |
| 2885 | { |
| 2886 | uint32_t timeout = 0; |
| 2887 | otError error = OT_ERROR_NONE; |
| 2888 | |
| 2889 | SuccessOrExit(error = mDecoder.ReadUint32(timeout)); |
| 2890 | |
| 2891 | otThreadSetChildTimeout(mInstance, timeout); |
| 2892 | |
| 2893 | exit: |
| 2894 | return error; |
| 2895 | } |
| 2896 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2897 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_RLOC16>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2898 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2899 | return mEncoder.WriteUint16(otThreadGetRloc16(mInstance)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2900 | } |
| 2901 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2902 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2903 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2904 | return mEncoder.WriteBool(mRequireJoinExistingNetwork); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2905 | } |
| 2906 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2907 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2908 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2909 | return mDecoder.ReadBool(mRequireJoinExistingNetwork); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2910 | } |
| 2911 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2912 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_STREAM_NET_INSECURE>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2913 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2914 | const uint8_t * framePtr = nullptr; |
Zhanglong Xia | f890959 | 2018-11-06 04:48:39 +0800 | [diff] [blame] | 2915 | uint16_t frameLen = 0; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2916 | const uint8_t * metaPtr = nullptr; |
Zhanglong Xia | f890959 | 2018-11-06 04:48:39 +0800 | [diff] [blame] | 2917 | uint16_t metaLen = 0; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2918 | otMessage * message = nullptr; |
Zhanglong Xia | f890959 | 2018-11-06 04:48:39 +0800 | [diff] [blame] | 2919 | otError error = OT_ERROR_NONE; |
| 2920 | otMessageSettings msgSettings = {false, OT_MESSAGE_PRIORITY_NORMAL}; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2921 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2922 | SuccessOrExit(mDecoder.ReadDataWithLen(framePtr, frameLen)); |
| 2923 | SuccessOrExit(mDecoder.ReadData(metaPtr, metaLen)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2924 | |
| 2925 | // We ignore metadata for now. |
| 2926 | // May later include TX power, allow retransmits, etc... |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2927 | |
Zhanglong Xia | 19f2533 | 2018-12-20 05:55:26 +0800 | [diff] [blame] | 2928 | // STREAM_NET_INSECURE packets are not secured at layer 2. |
| 2929 | message = otIp6NewMessageFromBuffer(mInstance, framePtr, frameLen, &msgSettings); |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 2930 | VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2931 | |
| 2932 | // Ensure the insecure message is forwarded using direct transmission. |
| 2933 | otMessageSetDirectTransmission(message, true); |
| 2934 | |
| 2935 | error = otIp6Send(mInstance, message); |
| 2936 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2937 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2938 | if (error == OT_ERROR_NONE) |
| 2939 | { |
| 2940 | mInboundInsecureIpFrameCounter++; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2941 | } |
| 2942 | else |
| 2943 | { |
| 2944 | mDroppedInboundIpFrameCounter++; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2945 | } |
| 2946 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2947 | return error; |
| 2948 | } |
| 2949 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2950 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_CNTR_RESET>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2951 | { |
Abtin Keshavarzian | 112d1bb | 2019-10-29 15:34:03 -0700 | [diff] [blame] | 2952 | otLinkResetCounters(mInstance); |
Paweł Wańczyk | c646e6f | 2019-12-18 19:23:43 +0100 | [diff] [blame] | 2953 | #if OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE |
| 2954 | otLinkResetTxRetrySuccessHistogram(mInstance); |
| 2955 | #endif |
Abtin Keshavarzian | 112d1bb | 2019-10-29 15:34:03 -0700 | [diff] [blame] | 2956 | otThreadResetIp6Counters(mInstance); |
| 2957 | otThreadResetMleCounters(mInstance); |
| 2958 | ResetCounters(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2959 | |
Abtin Keshavarzian | 112d1bb | 2019-10-29 15:34:03 -0700 | [diff] [blame] | 2960 | return OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2961 | } |
| 2962 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2963 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_THREAD_ASSISTING_PORTS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2964 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 2965 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2966 | uint16_t port; |
| 2967 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2968 | SuccessOrExit(error = mDecoder.ReadUint16(port)); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2969 | |
| 2970 | error = otIp6AddUnsecurePort(mInstance, port); |
| 2971 | exit: |
| 2972 | return error; |
| 2973 | } |
| 2974 | |
Jonathan Hui | 0baaf1a | 2019-07-15 12:57:32 -0700 | [diff] [blame] | 2975 | #if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2976 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 2977 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_MAC_WHITELIST>(void) |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2978 | { |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 2979 | otError error = OT_ERROR_NONE; |
| 2980 | const otExtAddress *extAddress; |
| 2981 | int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2982 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2983 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2984 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 2985 | if (!mDecoder.IsAllRead()) |
| 2986 | { |
| 2987 | SuccessOrExit(error = mDecoder.ReadInt8(rss)); |
| 2988 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2989 | |
| 2990 | error = otLinkFilterAddAddress(mInstance, extAddress); |
| 2991 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 2992 | if (error == OT_ERROR_ALREADY) |
| 2993 | { |
| 2994 | error = OT_ERROR_NONE; |
| 2995 | } |
| 2996 | |
| 2997 | SuccessOrExit(error); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 2998 | |
| 2999 | if (rss != OT_MAC_FILTER_FIXED_RSS_DISABLED) |
| 3000 | { |
| 3001 | error = otLinkFilterAddRssIn(mInstance, extAddress, rss); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3002 | } |
| 3003 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3004 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3005 | return error; |
| 3006 | } |
| 3007 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3008 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_MAC_BLACKLIST>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3009 | { |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 3010 | otError error = OT_ERROR_NONE; |
| 3011 | const otExtAddress *extAddress; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3012 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3013 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3014 | |
| 3015 | error = otLinkFilterAddAddress(mInstance, extAddress); |
| 3016 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3017 | if (error == OT_ERROR_ALREADY) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3018 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3019 | error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3020 | } |
| 3021 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3022 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3023 | return error; |
| 3024 | } |
| 3025 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3026 | template <> otError NcpBase::HandlePropertyInsert<SPINEL_PROP_MAC_FIXED_RSS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3027 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3028 | otError error = OT_ERROR_NONE; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3029 | const otExtAddress *extAddress = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3030 | int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3031 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3032 | if (mDecoder.GetRemainingLength() > sizeof(int8_t)) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3033 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3034 | SuccessOrExit(mDecoder.ReadEui64(extAddress)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3035 | } |
| 3036 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3037 | SuccessOrExit(mDecoder.ReadInt8(rss)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3038 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 3039 | if (extAddress != nullptr) |
| 3040 | { |
| 3041 | error = otLinkFilterAddRssIn(mInstance, extAddress, rss); |
| 3042 | } |
| 3043 | else |
| 3044 | { |
| 3045 | otLinkFilterSetDefaultRssIn(mInstance, rss); |
| 3046 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3047 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3048 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3049 | return error; |
| 3050 | } |
| 3051 | |
Jonathan Hui | 0baaf1a | 2019-07-15 12:57:32 -0700 | [diff] [blame] | 3052 | #endif // OPENTHREAD_CONFIG_MAC_FILTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3053 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3054 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_THREAD_ASSISTING_PORTS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3055 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3056 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3057 | uint16_t port; |
| 3058 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3059 | SuccessOrExit(error = mDecoder.ReadUint16(port)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3060 | |
| 3061 | error = otIp6RemoveUnsecurePort(mInstance, port); |
Abtin Keshavarzian | 02bdc69 | 2017-08-15 09:11:19 -0700 | [diff] [blame] | 3062 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3063 | // If unsecure port was not on the list, "remove" command is successful. |
| 3064 | if (error == OT_ERROR_NOT_FOUND) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3065 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3066 | error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3067 | } |
| 3068 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3069 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3070 | return error; |
| 3071 | } |
| 3072 | |
Jonathan Hui | 0baaf1a | 2019-07-15 12:57:32 -0700 | [diff] [blame] | 3073 | #if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3074 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3075 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_MAC_WHITELIST>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3076 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3077 | otError error = OT_ERROR_NONE; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3078 | const otExtAddress *extAddress = nullptr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3079 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3080 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3081 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 3082 | otLinkFilterRemoveAddress(mInstance, extAddress); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3083 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3084 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3085 | return error; |
| 3086 | } |
| 3087 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3088 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_MAC_BLACKLIST>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3089 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3090 | otError error = OT_ERROR_NONE; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3091 | const otExtAddress *extAddress = nullptr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3092 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3093 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3094 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 3095 | otLinkFilterRemoveAddress(mInstance, extAddress); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3096 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3097 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3098 | return error; |
| 3099 | } |
| 3100 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3101 | template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_MAC_FIXED_RSS>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3102 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3103 | otError error = OT_ERROR_NONE; |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3104 | const otExtAddress *extAddress = nullptr; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3105 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3106 | if (mDecoder.GetRemainingLength() > 0) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3107 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3108 | SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3109 | } |
| 3110 | |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 3111 | if (extAddress != nullptr) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3112 | { |
Abtin Keshavarzian | 6f1fc2e | 2020-06-29 08:59:34 -0700 | [diff] [blame] | 3113 | otLinkFilterRemoveRssIn(mInstance, extAddress); |
| 3114 | } |
| 3115 | else |
| 3116 | { |
| 3117 | otLinkFilterClearDefaultRssIn(mInstance); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3118 | } |
| 3119 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3120 | exit: |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3121 | return error; |
| 3122 | } |
| 3123 | |
Jonathan Hui | 0baaf1a | 2019-07-15 12:57:32 -0700 | [diff] [blame] | 3124 | #endif // OPENTHREAD_CONFIG_MAC_FILTER_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3125 | |
Yakun Xu | 6537459 | 2020-03-12 02:42:30 +0800 | [diff] [blame] | 3126 | #if OPENTHREAD_PLATFORM_POSIX |
Abtin Keshavarzian | 7c8a372 | 2018-10-12 10:40:57 -0700 | [diff] [blame] | 3127 | |
| 3128 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_RCP_VERSION>(void) |
| 3129 | { |
| 3130 | return mEncoder.WriteUtf8(otGetRadioVersionString(mInstance)); |
| 3131 | } |
| 3132 | |
Abtin Keshavarzian | 6e718a1 | 2019-04-04 17:39:22 -0700 | [diff] [blame] | 3133 | #endif |
Abtin Keshavarzian | 7c8a372 | 2018-10-12 10:40:57 -0700 | [diff] [blame] | 3134 | |
Jonathan Hui | 4a475d5 | 2019-07-15 22:13:11 -0700 | [diff] [blame] | 3135 | #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE |
Abtin Keshavarzian | 89396ab | 2019-03-11 14:59:43 -0700 | [diff] [blame] | 3136 | |
| 3137 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_SLAAC_ENABLED>(void) |
| 3138 | { |
| 3139 | return mEncoder.WriteBool(otIp6IsSlaacEnabled(mInstance)); |
| 3140 | } |
| 3141 | |
| 3142 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_SLAAC_ENABLED>(void) |
| 3143 | { |
| 3144 | otError error = OT_ERROR_NONE; |
| 3145 | bool enabled; |
| 3146 | |
| 3147 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
| 3148 | otIp6SetSlaacEnabled(mInstance, enabled); |
| 3149 | |
| 3150 | exit: |
| 3151 | return error; |
| 3152 | } |
| 3153 | |
Jonathan Hui | 4a475d5 | 2019-07-15 22:13:11 -0700 | [diff] [blame] | 3154 | #endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE |
Abtin Keshavarzian | 89396ab | 2019-03-11 14:59:43 -0700 | [diff] [blame] | 3155 | |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3156 | #if OPENTHREAD_CONFIG_LEGACY_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3157 | |
| 3158 | void NcpBase::RegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers) |
| 3159 | { |
| 3160 | mLegacyHandlers = aHandlers; |
| 3161 | bool isEnabled; |
| 3162 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3163 | VerifyOrExit(mLegacyHandlers != nullptr, OT_NOOP); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3164 | |
| 3165 | isEnabled = (otThreadGetDeviceRole(mInstance) != OT_DEVICE_ROLE_DISABLED); |
| 3166 | |
| 3167 | if (isEnabled) |
| 3168 | { |
| 3169 | if (mLegacyHandlers->mStartLegacy) |
| 3170 | { |
| 3171 | mLegacyHandlers->mStartLegacy(); |
| 3172 | } |
| 3173 | } |
| 3174 | else |
| 3175 | { |
| 3176 | if (mLegacyHandlers->mStopLegacy) |
| 3177 | { |
| 3178 | mLegacyHandlers->mStopLegacy(); |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | if (mLegacyHandlers->mSetLegacyUlaPrefix) |
| 3183 | { |
| 3184 | mLegacyHandlers->mSetLegacyUlaPrefix(mLegacyUlaPrefix); |
| 3185 | } |
| 3186 | |
| 3187 | exit: |
| 3188 | return; |
| 3189 | } |
| 3190 | |
| 3191 | void NcpBase::HandleDidReceiveNewLegacyUlaPrefix(const uint8_t *aUlaPrefix) |
| 3192 | { |
| 3193 | memcpy(mLegacyUlaPrefix, aUlaPrefix, OT_NCP_LEGACY_ULA_PREFIX_LENGTH); |
| 3194 | mChangedPropsSet.AddProperty(SPINEL_PROP_NEST_LEGACY_ULA_PREFIX); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3195 | mUpdateChangedPropsTask.Post(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | void NcpBase::HandleLegacyNodeDidJoin(const otExtAddress *aExtAddr) |
| 3199 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3200 | mLegacyNodeDidJoin = true; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3201 | mLegacyLastJoinedNode = *aExtAddr; |
| 3202 | mChangedPropsSet.AddProperty(SPINEL_PROP_NEST_LEGACY_LAST_NODE_JOINED); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3203 | mUpdateChangedPropsTask.Post(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3204 | } |
| 3205 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3206 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NEST_LEGACY_ULA_PREFIX>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3207 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3208 | return mEncoder.WriteData(mLegacyUlaPrefix, sizeof(mLegacyUlaPrefix)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3209 | } |
| 3210 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3211 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NEST_LEGACY_ULA_PREFIX>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3212 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3213 | const uint8_t *ptr = nullptr; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3214 | uint16_t len; |
| 3215 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3216 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3217 | SuccessOrExit(error = mDecoder.ReadData(ptr, len)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3218 | |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3219 | VerifyOrExit(len <= sizeof(mLegacyUlaPrefix), error = OT_ERROR_PARSE); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3220 | |
| 3221 | memset(mLegacyUlaPrefix, 0, sizeof(mLegacyUlaPrefix)); |
| 3222 | memcpy(mLegacyUlaPrefix, ptr, len); |
| 3223 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3224 | if ((mLegacyHandlers != nullptr) && (mLegacyHandlers->mSetLegacyUlaPrefix != nullptr)) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3225 | { |
| 3226 | mLegacyHandlers->mSetLegacyUlaPrefix(mLegacyUlaPrefix); |
| 3227 | } |
| 3228 | |
| 3229 | exit: |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3230 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3231 | } |
| 3232 | |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3233 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NEST_LEGACY_LAST_NODE_JOINED>(void) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3234 | { |
| 3235 | if (!mLegacyNodeDidJoin) |
| 3236 | { |
| 3237 | memset(&mLegacyLastJoinedNode, 0, sizeof(mLegacyLastJoinedNode)); |
| 3238 | } |
| 3239 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3240 | return mEncoder.WriteEui64(mLegacyLastJoinedNode); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3241 | } |
Abtin Keshavarzian | ecd2845 | 2018-04-05 10:20:47 -0700 | [diff] [blame] | 3242 | |
| 3243 | void NcpBase::StartLegacy(void) |
| 3244 | { |
| 3245 | mLegacyNodeDidJoin = false; |
| 3246 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3247 | if ((mLegacyHandlers != nullptr) && (mLegacyHandlers->mStartLegacy != nullptr)) |
Abtin Keshavarzian | ecd2845 | 2018-04-05 10:20:47 -0700 | [diff] [blame] | 3248 | { |
| 3249 | mLegacyHandlers->mStartLegacy(); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | void NcpBase::StopLegacy(void) |
| 3254 | { |
| 3255 | mLegacyNodeDidJoin = false; |
| 3256 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3257 | if ((mLegacyHandlers != nullptr) && (mLegacyHandlers->mStopLegacy != nullptr)) |
Abtin Keshavarzian | ecd2845 | 2018-04-05 10:20:47 -0700 | [diff] [blame] | 3258 | { |
| 3259 | mLegacyHandlers->mStopLegacy(); |
| 3260 | } |
| 3261 | } |
| 3262 | |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3263 | #endif // OPENTHREAD_CONFIG_LEGACY_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3264 | |
Jonathan Hui | 926b9e8 | 2019-07-15 21:16:37 -0700 | [diff] [blame] | 3265 | #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE |
Yakun Xu | 8ccf138 | 2018-06-29 00:26:31 +0800 | [diff] [blame] | 3266 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_NETWORK_TIME>(void) |
Shu Chen | e69019f | 2018-06-27 02:46:32 +0800 | [diff] [blame] | 3267 | { |
| 3268 | otError error = OT_ERROR_NONE; |
| 3269 | otNetworkTimeStatus networkTimeStatus; |
| 3270 | uint64_t time; |
| 3271 | |
Jonathan Hui | fa395d7 | 2019-05-20 08:50:43 -0700 | [diff] [blame] | 3272 | networkTimeStatus = otNetworkTimeGet(mInstance, &time); |
Shu Chen | e69019f | 2018-06-27 02:46:32 +0800 | [diff] [blame] | 3273 | |
| 3274 | SuccessOrExit(error = mEncoder.WriteUint64(time)); |
| 3275 | SuccessOrExit(error = mEncoder.WriteInt8((int8_t)networkTimeStatus)); |
| 3276 | |
| 3277 | exit: |
| 3278 | return error; |
| 3279 | } |
Joseph Newman | 4f99bcf | 2018-11-08 06:32:31 +0000 | [diff] [blame] | 3280 | |
| 3281 | void NcpBase::HandleTimeSyncUpdate(void *aContext) |
| 3282 | { |
| 3283 | static_cast<NcpBase *>(aContext)->HandleTimeSyncUpdate(); |
| 3284 | } |
| 3285 | |
| 3286 | void NcpBase::HandleTimeSyncUpdate(void) |
| 3287 | { |
| 3288 | mChangedPropsSet.AddProperty(SPINEL_PROP_THREAD_NETWORK_TIME); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3289 | mUpdateChangedPropsTask.Post(); |
Joseph Newman | 4f99bcf | 2018-11-08 06:32:31 +0000 | [diff] [blame] | 3290 | } |
Jonathan Hui | 926b9e8 | 2019-07-15 21:16:37 -0700 | [diff] [blame] | 3291 | #endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE |
Shu Chen | e69019f | 2018-06-27 02:46:32 +0800 | [diff] [blame] | 3292 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3293 | void NcpBase::HandleActiveScanResult_Jump(otActiveScanResult *aResult, void *aContext) |
| 3294 | { |
| 3295 | static_cast<NcpBase *>(aContext)->HandleActiveScanResult(aResult); |
| 3296 | } |
| 3297 | |
| 3298 | // ---------------------------------------------------------------------------- |
| 3299 | // MARK: Scan Results Glue |
| 3300 | // ---------------------------------------------------------------------------- |
| 3301 | |
| 3302 | void NcpBase::HandleActiveScanResult(otActiveScanResult *aResult) |
| 3303 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3304 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3305 | |
| 3306 | if (aResult) |
| 3307 | { |
| 3308 | uint8_t flags = static_cast<uint8_t>(aResult->mVersion << SPINEL_BEACON_THREAD_FLAG_VERSION_SHIFT); |
| 3309 | |
| 3310 | if (aResult->mIsJoinable) |
| 3311 | { |
| 3312 | flags |= SPINEL_BEACON_THREAD_FLAG_JOINABLE; |
| 3313 | } |
| 3314 | |
| 3315 | if (aResult->mIsNative) |
| 3316 | { |
| 3317 | flags |= SPINEL_BEACON_THREAD_FLAG_NATIVE; |
| 3318 | } |
| 3319 | |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3320 | SuccessOrExit(error = mEncoder.BeginFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, |
| 3321 | SPINEL_CMD_PROP_VALUE_INSERTED, SPINEL_PROP_MAC_SCAN_BEACON)); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3322 | SuccessOrExit(error = mEncoder.WriteUint8(aResult->mChannel)); |
| 3323 | SuccessOrExit(error = mEncoder.WriteInt8(aResult->mRssi)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3324 | |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3325 | SuccessOrExit(error = mEncoder.OpenStruct()); // "mac-layer data" |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3326 | SuccessOrExit(error = mEncoder.WriteEui64(aResult->mExtAddress)); |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3327 | SuccessOrExit(error = mEncoder.WriteUint16(0xffff)); // short address, not given |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3328 | SuccessOrExit(error = mEncoder.WriteUint16(aResult->mPanId)); |
| 3329 | SuccessOrExit(error = mEncoder.WriteUint8(aResult->mLqi)); |
| 3330 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 3331 | |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3332 | SuccessOrExit(error = mEncoder.OpenStruct()); // "net-layer data" |
| 3333 | SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_PROTOCOL_TYPE_THREAD)); // type |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3334 | SuccessOrExit(error = mEncoder.WriteUint8(flags)); |
| 3335 | SuccessOrExit(error = mEncoder.WriteUtf8(aResult->mNetworkName.m8)); |
| 3336 | SuccessOrExit(error = mEncoder.WriteDataWithLen(aResult->mExtendedPanId.m8, OT_EXT_PAN_ID_SIZE)); |
| 3337 | SuccessOrExit(error = mEncoder.WriteDataWithLen(aResult->mSteeringData.m8, aResult->mSteeringData.mLength)); |
| 3338 | SuccessOrExit(error = mEncoder.CloseStruct()); |
| 3339 | |
| 3340 | SuccessOrExit(error = mEncoder.EndFrame()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3341 | } |
| 3342 | else |
| 3343 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3344 | // We are finished with the scan, send an unsolicited |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3345 | // scan state update. |
| 3346 | mChangedPropsSet.AddProperty(SPINEL_PROP_MAC_SCAN_STATE); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3347 | mUpdateChangedPropsTask.Post(); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3348 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3349 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3350 | exit: |
| 3351 | |
| 3352 | if (error != OT_ERROR_NONE) |
| 3353 | { |
| 3354 | // We ran out of buffer adding a scan result so remember to send |
| 3355 | // an async `LAST_STATUS(NOMEM)` when buffer space becomes |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3356 | // available. |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3357 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_NOMEM); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3358 | mUpdateChangedPropsTask.Post(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | void NcpBase::HandleEnergyScanResult_Jump(otEnergyScanResult *aResult, void *aContext) |
| 3363 | { |
| 3364 | static_cast<NcpBase *>(aContext)->HandleEnergyScanResult(aResult); |
| 3365 | } |
| 3366 | |
| 3367 | void NcpBase::HandleEnergyScanResult(otEnergyScanResult *aResult) |
| 3368 | { |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3369 | otError error = OT_ERROR_NONE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3370 | |
| 3371 | if (aResult) |
| 3372 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3373 | SuccessOrExit(error = mEncoder.BeginFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, |
| 3374 | SPINEL_CMD_PROP_VALUE_INSERTED, SPINEL_PROP_MAC_ENERGY_SCAN_RESULT)); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3375 | SuccessOrExit(error = mEncoder.WriteUint8(aResult->mChannel)); |
| 3376 | SuccessOrExit(error = mEncoder.WriteInt8(aResult->mMaxRssi)); |
| 3377 | SuccessOrExit(error = mEncoder.EndFrame()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3378 | } |
| 3379 | else |
| 3380 | { |
Abtin Keshavarzian | 92ba27a | 2017-10-13 09:18:37 -0700 | [diff] [blame] | 3381 | // We are finished with the scan, send an unsolicited |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3382 | // scan state update. |
| 3383 | mChangedPropsSet.AddProperty(SPINEL_PROP_MAC_SCAN_STATE); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3384 | mUpdateChangedPropsTask.Post(); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3385 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3386 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3387 | exit: |
| 3388 | |
| 3389 | if (error != OT_ERROR_NONE) |
| 3390 | { |
| 3391 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_NOMEM); |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3392 | mUpdateChangedPropsTask.Post(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3393 | } |
| 3394 | } |
| 3395 | |
Jonathan Hui | 31ffd16 | 2019-07-16 12:01:36 -0700 | [diff] [blame] | 3396 | #if OPENTHREAD_CONFIG_JOINER_ENABLE |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 3397 | void NcpBase::HandleJoinerCallback_Jump(otError aError, void *aContext) |
| 3398 | { |
| 3399 | static_cast<NcpBase *>(aContext)->HandleJoinerCallback(aError); |
| 3400 | } |
| 3401 | |
| 3402 | void NcpBase::HandleJoinerCallback(otError aError) |
| 3403 | { |
| 3404 | switch (aError) |
| 3405 | { |
| 3406 | case OT_ERROR_NONE: |
| 3407 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_JOIN_SUCCESS); |
| 3408 | break; |
| 3409 | case OT_ERROR_SECURITY: |
| 3410 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_JOIN_SECURITY); |
| 3411 | break; |
| 3412 | case OT_ERROR_NOT_FOUND: |
| 3413 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_JOIN_NO_PEERS); |
| 3414 | break; |
| 3415 | case OT_ERROR_RESPONSE_TIMEOUT: |
| 3416 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_JOIN_RSP_TIMEOUT); |
| 3417 | break; |
| 3418 | default: |
| 3419 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_JOIN_FAILURE); |
| 3420 | break; |
| 3421 | } |
| 3422 | |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3423 | mUpdateChangedPropsTask.Post(); |
rongli | 90ee0a4 | 2018-08-09 02:18:53 +0800 | [diff] [blame] | 3424 | } |
| 3425 | #endif |
| 3426 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3427 | // ---------------------------------------------------------------------------- |
| 3428 | // MARK: Outbound Datagram Handling |
| 3429 | // ---------------------------------------------------------------------------- |
| 3430 | |
| 3431 | void NcpBase::HandleDatagramFromStack(otMessage *aMessage, void *aContext) |
| 3432 | { |
| 3433 | static_cast<NcpBase *>(aContext)->HandleDatagramFromStack(aMessage); |
| 3434 | } |
| 3435 | |
| 3436 | void NcpBase::HandleDatagramFromStack(otMessage *aMessage) |
| 3437 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3438 | VerifyOrExit(aMessage != nullptr, OT_NOOP); |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3439 | |
Duda, Lukasz | 9aa7340 | 2020-05-08 22:46:00 +0200 | [diff] [blame] | 3440 | // Do not forward frames larger than SPINEL payload size. |
| 3441 | VerifyOrExit(otMessageGetLength(aMessage) <= SPINEL_FRAME_MAX_COMMAND_PAYLOAD_SIZE, otMessageFree(aMessage)); |
| 3442 | |
Jonathan Hui | 7540758 | 2020-05-08 20:43:40 -0700 | [diff] [blame] | 3443 | otMessageQueueEnqueue(&mMessageQueue, aMessage); |
Abtin Keshavarzian | 9ce57b2 | 2017-12-05 18:33:53 -0800 | [diff] [blame] | 3444 | |
| 3445 | // If there is no queued spinel command response, try to write/send |
| 3446 | // the datagram message immediately. If there is a queued response |
| 3447 | // or if currently out of buffer space, the IPv6 datagram message |
| 3448 | // will be sent from `HandleFrameRemovedFromNcpBuffer()` when buffer |
| 3449 | // space becomes available and after any pending spinel command |
| 3450 | // response. |
| 3451 | |
| 3452 | if (IsResponseQueueEmpty()) |
| 3453 | { |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 3454 | IgnoreError(SendQueuedDatagramMessages()); |
Abtin Keshavarzian | 9ce57b2 | 2017-12-05 18:33:53 -0800 | [diff] [blame] | 3455 | } |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3456 | |
| 3457 | exit: |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3458 | return; |
| 3459 | } |
| 3460 | |
| 3461 | otError NcpBase::SendDatagramMessage(otMessage *aMessage) |
| 3462 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3463 | otError error = OT_ERROR_NONE; |
| 3464 | uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; |
| 3465 | bool isSecure = otMessageIsLinkSecurityEnabled(aMessage); |
| 3466 | spinel_prop_key_t propKey = isSecure ? SPINEL_PROP_STREAM_NET : SPINEL_PROP_STREAM_NET_INSECURE; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3467 | |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3468 | SuccessOrExit(error = mEncoder.BeginFrame(header, SPINEL_CMD_PROP_VALUE_IS, propKey)); |
| 3469 | SuccessOrExit(error = mEncoder.WriteUint16(otMessageGetLength(aMessage))); |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3470 | SuccessOrExit(error = mEncoder.WriteMessage(aMessage)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3471 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3472 | // Append any metadata (rssi, lqi, channel, etc) here! |
| 3473 | |
Abtin Keshavarzian | 192df6c | 2017-09-27 23:04:53 -0700 | [diff] [blame] | 3474 | SuccessOrExit(error = mEncoder.EndFrame()); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3475 | |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3476 | if (isSecure) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3477 | { |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3478 | mOutboundSecureIpFrameCounter++; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3479 | } |
| 3480 | else |
| 3481 | { |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3482 | mOutboundInsecureIpFrameCounter++; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3483 | } |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3484 | |
| 3485 | exit: |
| 3486 | return error; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3487 | } |
| 3488 | |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3489 | otError NcpBase::SendQueuedDatagramMessages(void) |
| 3490 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3491 | otError error = OT_ERROR_NONE; |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3492 | otMessage *message; |
| 3493 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3494 | while ((message = otMessageQueueGetHead(&mMessageQueue)) != nullptr) |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3495 | { |
| 3496 | // Since an `otMessage` instance can be in one queue at a time, |
| 3497 | // it is first dequeued from `mMessageQueue` before attempting |
| 3498 | // to include it in a spinel frame by calling `SendDatagramMessage()` |
| 3499 | // If forming of the spinel frame fails, the message is enqueued |
| 3500 | // back at the front of `mMessageQueue`. |
| 3501 | |
Jonathan Hui | cf57110 | 2020-05-08 21:42:11 -0700 | [diff] [blame] | 3502 | otMessageQueueDequeue(&mMessageQueue, message); |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3503 | |
| 3504 | error = SendDatagramMessage(message); |
| 3505 | |
| 3506 | if (error != OT_ERROR_NONE) |
| 3507 | { |
Jonathan Hui | 7540758 | 2020-05-08 20:43:40 -0700 | [diff] [blame] | 3508 | otMessageQueueEnqueueAtHead(&mMessageQueue, message); |
Abtin Keshavarzian | 54fa0f1 | 2017-10-13 09:29:18 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | SuccessOrExit(error); |
| 3512 | } |
| 3513 | |
| 3514 | exit: |
| 3515 | return error; |
| 3516 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3517 | |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3518 | #if OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE |
Yakun Xu | b9b57cc | 2018-11-06 12:48:08 +0800 | [diff] [blame] | 3519 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_UDP_FORWARD_STREAM>(void) |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3520 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3521 | const uint8_t * framePtr = nullptr; |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3522 | uint16_t frameLen = 0; |
| 3523 | const otIp6Address *peerAddr; |
| 3524 | uint16_t peerPort; |
| 3525 | uint16_t sockPort; |
| 3526 | otMessage * message; |
Zhanglong Xia | f890959 | 2018-11-06 04:48:39 +0800 | [diff] [blame] | 3527 | otError error = OT_ERROR_NONE; |
| 3528 | otMessageSettings msgSettings = {false, OT_MESSAGE_PRIORITY_NORMAL}; |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3529 | |
Zhanglong Xia | f890959 | 2018-11-06 04:48:39 +0800 | [diff] [blame] | 3530 | message = otIp6NewMessage(mInstance, &msgSettings); |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3531 | VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3532 | |
| 3533 | SuccessOrExit(error = mDecoder.ReadDataWithLen(framePtr, frameLen)); |
| 3534 | SuccessOrExit(error = mDecoder.ReadUint16(peerPort)); |
| 3535 | SuccessOrExit(error = mDecoder.ReadIp6Address(peerAddr)); |
| 3536 | SuccessOrExit(error = mDecoder.ReadUint16(sockPort)); |
| 3537 | |
| 3538 | SuccessOrExit(error = otMessageAppend(message, framePtr, static_cast<uint16_t>(frameLen))); |
| 3539 | |
Yakun Xu | b9b57cc | 2018-11-06 12:48:08 +0800 | [diff] [blame] | 3540 | otUdpForwardReceive(mInstance, message, peerPort, peerAddr, sockPort); |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3541 | |
Yakun Xu | b9b57cc | 2018-11-06 12:48:08 +0800 | [diff] [blame] | 3542 | // `otUdpForwardReceive()` takes ownership of `message` (in both success |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3543 | // or failure cases). `message` is set to nullptr so it is not freed at |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3544 | // exit. |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3545 | message = nullptr; |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3546 | |
| 3547 | exit: |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3548 | if (message != nullptr) |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3549 | { |
| 3550 | otMessageFree(message); |
| 3551 | } |
| 3552 | |
| 3553 | return error; |
| 3554 | } |
| 3555 | |
Yakun Xu | b9b57cc | 2018-11-06 12:48:08 +0800 | [diff] [blame] | 3556 | void NcpBase::HandleUdpForwardStream(otMessage * aMessage, |
| 3557 | uint16_t aPeerPort, |
| 3558 | otIp6Address *aPeerAddr, |
| 3559 | uint16_t aSockPort, |
| 3560 | void * aContext) |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3561 | { |
Yakun Xu | b9b57cc | 2018-11-06 12:48:08 +0800 | [diff] [blame] | 3562 | static_cast<NcpBase *>(aContext)->HandleUdpForwardStream(aMessage, aPeerPort, *aPeerAddr, aSockPort); |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3563 | } |
| 3564 | |
Yakun Xu | b9b57cc | 2018-11-06 12:48:08 +0800 | [diff] [blame] | 3565 | void NcpBase::HandleUdpForwardStream(otMessage *aMessage, uint16_t aPeerPort, otIp6Address &aPeerAddr, uint16_t aPort) |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3566 | { |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3567 | uint16_t length = otMessageGetLength(aMessage); |
| 3568 | uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; |
| 3569 | |
Yakun Xu | b9b57cc | 2018-11-06 12:48:08 +0800 | [diff] [blame] | 3570 | SuccessOrExit(mEncoder.BeginFrame(header, SPINEL_CMD_PROP_VALUE_IS, SPINEL_PROP_THREAD_UDP_FORWARD_STREAM)); |
Kamil Sroka | d7f8a5b | 2018-07-13 18:35:47 +0200 | [diff] [blame] | 3571 | SuccessOrExit(mEncoder.WriteUint16(length)); |
| 3572 | SuccessOrExit(mEncoder.WriteMessage(aMessage)); |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3573 | |
Kamil Sroka | d7f8a5b | 2018-07-13 18:35:47 +0200 | [diff] [blame] | 3574 | SuccessOrExit(mEncoder.WriteUint16(aPeerPort)); |
| 3575 | SuccessOrExit(mEncoder.WriteIp6Address(aPeerAddr)); |
| 3576 | SuccessOrExit(mEncoder.WriteUint16(aPort)); |
| 3577 | SuccessOrExit(mEncoder.EndFrame()); |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3578 | |
| 3579 | // The `aMessage` is owned by the outbound frame and NCP buffer |
| 3580 | // after frame was finished/ended successfully. It will be freed |
| 3581 | // when the frame is successfully sent and removed. |
| 3582 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3583 | aMessage = nullptr; |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3584 | |
| 3585 | exit: |
| 3586 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3587 | if (aMessage != nullptr) |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3588 | { |
| 3589 | otMessageFree(aMessage); |
| 3590 | } |
| 3591 | } |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3592 | #endif // OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE |
Yakun Xu | 96a7e2d | 2018-07-10 04:25:23 +0800 | [diff] [blame] | 3593 | |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3594 | // ---------------------------------------------------------------------------- |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3595 | // MARK: Pcap frame handling |
| 3596 | // ---------------------------------------------------------------------------- |
| 3597 | |
Yakun Xu | 504331e | 2019-01-29 04:31:15 +0800 | [diff] [blame] | 3598 | void NcpBase::HandlePcapFrame(const otRadioFrame *aFrame, bool aIsTx, void *aContext) |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3599 | { |
Yakun Xu | 504331e | 2019-01-29 04:31:15 +0800 | [diff] [blame] | 3600 | static_cast<NcpBase *>(aContext)->HandlePcapFrame(aFrame, aIsTx); |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3601 | } |
| 3602 | |
Yakun Xu | 504331e | 2019-01-29 04:31:15 +0800 | [diff] [blame] | 3603 | void NcpBase::HandlePcapFrame(const otRadioFrame *aFrame, bool aIsTx) |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3604 | { |
| 3605 | uint16_t flags = 0; |
| 3606 | uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; |
| 3607 | |
Jonathan Hui | a459223 | 2020-04-08 15:22:25 -0700 | [diff] [blame] | 3608 | VerifyOrExit(mPcapEnabled, OT_NOOP); |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3609 | |
Yakun Xu | 504331e | 2019-01-29 04:31:15 +0800 | [diff] [blame] | 3610 | if (aIsTx) |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3611 | { |
| 3612 | flags |= SPINEL_MD_FLAG_TX; |
| 3613 | } |
| 3614 | |
| 3615 | SuccessOrExit(mEncoder.BeginFrame(header, SPINEL_CMD_PROP_VALUE_IS, SPINEL_PROP_STREAM_RAW)); |
| 3616 | SuccessOrExit(mEncoder.WriteUint16(aFrame->mLength)); |
| 3617 | |
| 3618 | SuccessOrExit(mEncoder.WriteData(aFrame->mPsdu, aFrame->mLength)); |
| 3619 | |
| 3620 | // Append metadata (rssi, etc) |
| 3621 | SuccessOrExit(mEncoder.WriteInt8(aFrame->mInfo.mRxInfo.mRssi)); // RSSI |
| 3622 | SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise floor (Currently unused) |
| 3623 | SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags |
| 3624 | |
| 3625 | SuccessOrExit(mEncoder.OpenStruct()); // PHY-data |
| 3626 | // Empty for now |
| 3627 | SuccessOrExit(mEncoder.CloseStruct()); |
| 3628 | |
| 3629 | SuccessOrExit(mEncoder.OpenStruct()); // Vendor-data |
| 3630 | // Empty for now |
| 3631 | SuccessOrExit(mEncoder.CloseStruct()); |
| 3632 | |
| 3633 | SuccessOrExit(mEncoder.EndFrame()); |
| 3634 | |
| 3635 | exit: |
| 3636 | return; |
| 3637 | } |
| 3638 | |
| 3639 | template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_PHY_PCAP_ENABLED>(void) |
| 3640 | { |
| 3641 | return mEncoder.WriteBool(mPcapEnabled); |
| 3642 | } |
| 3643 | |
| 3644 | template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_PHY_PCAP_ENABLED>(void) |
| 3645 | { |
| 3646 | otError error = OT_ERROR_NONE; |
| 3647 | bool enabled; |
| 3648 | |
| 3649 | SuccessOrExit(error = mDecoder.ReadBool(enabled)); |
Jonathan Hui | a459223 | 2020-04-08 15:22:25 -0700 | [diff] [blame] | 3650 | VerifyOrExit(enabled != mPcapEnabled, OT_NOOP); |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3651 | |
| 3652 | mPcapEnabled = enabled; |
| 3653 | |
| 3654 | if (mPcapEnabled) |
| 3655 | { |
| 3656 | otLinkSetPcapCallback(mInstance, &NcpBase::HandlePcapFrame, static_cast<void *>(this)); |
| 3657 | } |
| 3658 | else |
| 3659 | { |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3660 | otLinkSetPcapCallback(mInstance, nullptr, nullptr); |
Abtin Keshavarzian | 765c45c | 2018-11-09 08:59:20 -0800 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | exit: |
| 3664 | return error; |
| 3665 | } |
| 3666 | |
| 3667 | // ---------------------------------------------------------------------------- |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3668 | // MARK: Property/Status Changed |
| 3669 | // ---------------------------------------------------------------------------- |
| 3670 | |
Abtin Keshavarzian | 9ce38e0 | 2018-06-22 15:09:18 -0700 | [diff] [blame] | 3671 | void NcpBase::HandleStateChanged(otChangedFlags aFlags, void *aContext) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3672 | { |
| 3673 | NcpBase *ncp = static_cast<NcpBase *>(aContext); |
| 3674 | |
| 3675 | ncp->mThreadChangedFlags |= aFlags; |
Abtin Keshavarzian | a1adaac | 2020-05-11 10:24:58 -0700 | [diff] [blame] | 3676 | ncp->mUpdateChangedPropsTask.Post(); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | void NcpBase::ProcessThreadChangedFlags(void) |
| 3680 | { |
| 3681 | static const struct |
| 3682 | { |
Abtin Keshavarzian | 9ce38e0 | 2018-06-22 15:09:18 -0700 | [diff] [blame] | 3683 | otChangedFlags mThreadFlag; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3684 | spinel_prop_key_t mPropKey; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3685 | } kFlags[] = { |
| 3686 | {OT_CHANGED_IP6_ADDRESS_ADDED, SPINEL_PROP_IPV6_ADDRESS_TABLE}, |
| 3687 | {OT_CHANGED_IP6_ADDRESS_REMOVED, SPINEL_PROP_IPV6_ADDRESS_TABLE}, |
| 3688 | {OT_CHANGED_THREAD_ROLE, SPINEL_PROP_NET_ROLE}, |
| 3689 | {OT_CHANGED_THREAD_LL_ADDR, SPINEL_PROP_IPV6_LL_ADDR}, |
| 3690 | {OT_CHANGED_THREAD_ML_ADDR, SPINEL_PROP_IPV6_ML_ADDR}, |
| 3691 | {OT_CHANGED_THREAD_PARTITION_ID, SPINEL_PROP_NET_PARTITION_ID}, |
| 3692 | {OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER, SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER}, |
| 3693 | {OT_CHANGED_THREAD_NETDATA, SPINEL_PROP_THREAD_LEADER_NETWORK_DATA}, |
| 3694 | {OT_CHANGED_THREAD_CHILD_ADDED, SPINEL_PROP_THREAD_CHILD_TABLE}, |
| 3695 | {OT_CHANGED_THREAD_CHILD_REMOVED, SPINEL_PROP_THREAD_CHILD_TABLE}, |
Jonathan Hui | 98fb9df | 2019-10-09 15:01:32 -0700 | [diff] [blame] | 3696 | {OT_CHANGED_IP6_MULTICAST_SUBSCRIBED, SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE}, |
| 3697 | {OT_CHANGED_IP6_MULTICAST_UNSUBSCRIBED, SPINEL_PROP_IPV6_MULTICAST_ADDRESS_TABLE}, |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3698 | {OT_CHANGED_THREAD_CHANNEL, SPINEL_PROP_PHY_CHAN}, |
| 3699 | {OT_CHANGED_THREAD_PANID, SPINEL_PROP_MAC_15_4_PANID}, |
| 3700 | {OT_CHANGED_THREAD_NETWORK_NAME, SPINEL_PROP_NET_NETWORK_NAME}, |
| 3701 | {OT_CHANGED_THREAD_EXT_PANID, SPINEL_PROP_NET_XPANID}, |
Simon Lin | b5b97ae | 2020-03-10 23:55:25 +0800 | [diff] [blame] | 3702 | {OT_CHANGED_THREAD_RLOC_ADDED, SPINEL_PROP_IPV6_ADDRESS_TABLE}, |
| 3703 | {OT_CHANGED_THREAD_RLOC_REMOVED, SPINEL_PROP_IPV6_ADDRESS_TABLE}, |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3704 | {OT_CHANGED_MASTER_KEY, SPINEL_PROP_NET_MASTER_KEY}, |
| 3705 | {OT_CHANGED_PSKC, SPINEL_PROP_NET_PSKC}, |
| 3706 | {OT_CHANGED_CHANNEL_MANAGER_NEW_CHANNEL, SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL}, |
Abtin Keshavarzian | 31698ec | 2018-07-02 08:43:45 -0700 | [diff] [blame] | 3707 | {OT_CHANGED_SUPPORTED_CHANNEL_MASK, SPINEL_PROP_PHY_CHAN_SUPPORTED}, |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3708 | }; |
| 3709 | |
Jonathan Hui | a459223 | 2020-04-08 15:22:25 -0700 | [diff] [blame] | 3710 | VerifyOrExit(mThreadChangedFlags != 0, OT_NOOP); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3711 | |
| 3712 | // If thread role has changed, check for possible "join" error. |
| 3713 | |
| 3714 | if ((mThreadChangedFlags & OT_CHANGED_THREAD_ROLE) != 0) |
| 3715 | { |
| 3716 | if (mRequireJoinExistingNetwork) |
| 3717 | { |
| 3718 | switch (otThreadGetDeviceRole(mInstance)) |
| 3719 | { |
| 3720 | case OT_DEVICE_ROLE_DETACHED: |
| 3721 | case OT_DEVICE_ROLE_DISABLED: |
| 3722 | break; |
| 3723 | |
| 3724 | default: |
| 3725 | mRequireJoinExistingNetwork = false; |
| 3726 | mChangedPropsSet.AddProperty(SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING); |
| 3727 | break; |
| 3728 | } |
| 3729 | |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3730 | if ((otThreadGetDeviceRole(mInstance) == OT_DEVICE_ROLE_LEADER) && otThreadIsSingleton(mInstance) |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3731 | #if OPENTHREAD_CONFIG_LEGACY_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3732 | && !mLegacyNodeDidJoin |
| 3733 | #endif |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3734 | ) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3735 | { |
| 3736 | mThreadChangedFlags &= ~static_cast<uint32_t>(OT_CHANGED_THREAD_PARTITION_ID); |
kangping | 49f36f8 | 2020-05-07 02:17:58 +0800 | [diff] [blame] | 3737 | IgnoreError(otThreadSetEnabled(mInstance, false)); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3738 | |
| 3739 | mChangedPropsSet.AddProperty(SPINEL_PROP_NET_STACK_UP); |
| 3740 | mChangedPropsSet.AddLastStatus(SPINEL_STATUS_JOIN_FAILURE); |
| 3741 | } |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | // Convert OT_CHANGED flags to corresponding NCP property update. |
| 3746 | |
Simon Lin | 5e9b281 | 2020-07-22 00:41:40 +0800 | [diff] [blame^] | 3747 | for (auto flag : kFlags) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3748 | { |
Simon Lin | 5e9b281 | 2020-07-22 00:41:40 +0800 | [diff] [blame^] | 3749 | uint32_t threadFlag = flag.mThreadFlag; |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3750 | |
| 3751 | if (mThreadChangedFlags & threadFlag) |
| 3752 | { |
Simon Lin | 5e9b281 | 2020-07-22 00:41:40 +0800 | [diff] [blame^] | 3753 | spinel_prop_key_t propKey = flag.mPropKey; |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3754 | bool shouldAddProperty = true; |
Abtin Keshavarzian | 7392200 | 2017-10-31 14:15:04 -0700 | [diff] [blame] | 3755 | |
| 3756 | // Child table changes are reported using the `HandleChildAdded()` and |
| 3757 | // `HandleChildRemoved()` callbacks emitting spinel `VALUE_INSERTED` and |
| 3758 | // `VALUE_REMOVED` async spinel frames. If the spinel frames could not be |
| 3759 | // added (e.g., out of NCP buffer) from the above callbacks, the flag |
| 3760 | // `mShouldEmitChildTableUpdate` is set to `true` so that the entire |
| 3761 | // child table is emitted as an unsolicited `VALUE_IS` update. |
| 3762 | |
| 3763 | if (propKey == SPINEL_PROP_THREAD_CHILD_TABLE) |
| 3764 | { |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3765 | shouldAddProperty = mShouldEmitChildTableUpdate; |
Abtin Keshavarzian | 7392200 | 2017-10-31 14:15:04 -0700 | [diff] [blame] | 3766 | mShouldEmitChildTableUpdate = false; |
| 3767 | } |
| 3768 | |
| 3769 | if (shouldAddProperty) |
| 3770 | { |
| 3771 | mChangedPropsSet.AddProperty(propKey); |
| 3772 | } |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3773 | |
| 3774 | if (threadFlag == OT_CHANGED_THREAD_NETDATA) |
| 3775 | { |
| 3776 | mChangedPropsSet.AddProperty(SPINEL_PROP_THREAD_ON_MESH_NETS); |
| 3777 | mChangedPropsSet.AddProperty(SPINEL_PROP_THREAD_OFF_MESH_ROUTES); |
| 3778 | } |
| 3779 | |
| 3780 | mThreadChangedFlags &= ~threadFlag; |
Jonathan Hui | a459223 | 2020-04-08 15:22:25 -0700 | [diff] [blame] | 3781 | VerifyOrExit(mThreadChangedFlags != 0, OT_NOOP); |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | // Clear any remaining ThreadFlag that has no matching |
Simon Lin | b5b97ae | 2020-03-10 23:55:25 +0800 | [diff] [blame] | 3786 | // NCP property update (e.g., OT_CHANGED_SECURITY_POLICY) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3787 | |
| 3788 | mThreadChangedFlags = 0; |
| 3789 | |
| 3790 | exit: |
| 3791 | return; |
| 3792 | } |
| 3793 | |
Yakun Xu | b833373 | 2018-06-21 04:15:13 +0800 | [diff] [blame] | 3794 | } // namespace Ncp |
| 3795 | } // namespace ot |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3796 | |
| 3797 | // ---------------------------------------------------------------------------- |
| 3798 | // MARK: Legacy network APIs |
| 3799 | // ---------------------------------------------------------------------------- |
| 3800 | |
| 3801 | void otNcpRegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers) |
| 3802 | { |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3803 | #if OPENTHREAD_CONFIG_LEGACY_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3804 | ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); |
| 3805 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3806 | if (ncp != nullptr) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3807 | { |
| 3808 | ncp->RegisterLegacyHandlers(aHandlers); |
| 3809 | } |
| 3810 | |
| 3811 | #else |
| 3812 | OT_UNUSED_VARIABLE(aHandlers); |
| 3813 | #endif |
| 3814 | } |
| 3815 | |
| 3816 | void otNcpHandleDidReceiveNewLegacyUlaPrefix(const uint8_t *aUlaPrefix) |
| 3817 | { |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3818 | #if OPENTHREAD_CONFIG_LEGACY_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3819 | ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); |
| 3820 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3821 | if (ncp != nullptr) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3822 | { |
| 3823 | ncp->HandleDidReceiveNewLegacyUlaPrefix(aUlaPrefix); |
| 3824 | } |
| 3825 | |
| 3826 | #else |
| 3827 | OT_UNUSED_VARIABLE(aUlaPrefix); |
| 3828 | #endif |
| 3829 | } |
| 3830 | |
| 3831 | void otNcpHandleLegacyNodeDidJoin(const otExtAddress *aExtAddr) |
| 3832 | { |
Jonathan Hui | 02da206 | 2019-07-16 12:18:34 -0700 | [diff] [blame] | 3833 | #if OPENTHREAD_CONFIG_LEGACY_ENABLE |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3834 | ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); |
| 3835 | |
Jonathan Hui | 1326d64 | 2020-06-17 22:44:54 -0700 | [diff] [blame] | 3836 | if (ncp != nullptr) |
Buke Po | 818998e | 2017-08-04 01:19:07 +0800 | [diff] [blame] | 3837 | { |
| 3838 | ncp->HandleLegacyNodeDidJoin(aExtAddr); |
| 3839 | } |
| 3840 | |
| 3841 | #else |
| 3842 | OT_UNUSED_VARIABLE(aExtAddr); |
| 3843 | #endif |
| 3844 | } |
| 3845 | |
| 3846 | #endif // OPENTHREAD_MTD || OPENTHREAD_FTD |