• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2024, 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"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "fake_platform.hpp"
30 
31 #include <assert.h>
32 #include <stdint.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <sys/time.h>
37 
38 #include <openthread/error.h>
39 #include <openthread/instance.h>
40 #include <openthread/tasklet.h>
41 #include <openthread/tcat.h>
42 #include <openthread/platform/ble.h>
43 #include <openthread/platform/diag.h>
44 #include <openthread/platform/dso_transport.h>
45 #include <openthread/platform/entropy.h>
46 #include <openthread/platform/logging.h>
47 #include <openthread/platform/misc.h>
48 #include <openthread/platform/toolchain.h>
49 #include <openthread/platform/trel.h>
50 #include <openthread/platform/udp.h>
51 
52 using namespace ot;
53 
operator <(const otExtAddress & aLeft,const otExtAddress & aRight)54 bool operator<(const otExtAddress &aLeft, const otExtAddress &aRight)
55 {
56     return memcmp(&aLeft, &aRight, sizeof(aLeft)) < 0;
57 }
58 
59 namespace ot {
60 
61 FakePlatform *FakePlatform::sPlatform = nullptr;
62 
FakePlatform()63 FakePlatform::FakePlatform()
64 {
65     assert(sPlatform == nullptr);
66     sPlatform = this;
67 
68     mTransmitFrame.mPsdu = mTransmitBuffer;
69 
70 #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
71 #if OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
72     mInstance = otInstanceInitMultiple(0);
73 #else
74     {
75         size_t instanceBufferLength = 0;
76         void  *instanceBuffer       = nullptr;
77 
78         otInstanceInit(nullptr, &instanceBufferLength);
79 
80         instanceBuffer = malloc(instanceBufferLength);
81         assert(instanceBuffer != nullptr);
82         memset(instanceBuffer, 0, instanceBufferLength);
83 
84         mInstance = otInstanceInit(instanceBuffer, &instanceBufferLength);
85     }
86 #endif
87 #else
88     mInstance = otInstanceInitSingle();
89 #endif
90 }
91 
~FakePlatform()92 FakePlatform::~FakePlatform()
93 {
94     otInstanceFinalize(mInstance);
95     sPlatform = nullptr;
96 }
97 
98 #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
StartMicroAlarm(uint32_t aT0,uint32_t aDt)99 void FakePlatform::StartMicroAlarm(uint32_t aT0, uint32_t aDt)
100 {
101     uint64_t start = mNow;
102     uint32_t now   = mNow;
103 
104     if (static_cast<int32_t>(aT0 - now) > 0 || static_cast<int32_t>(aT0 - now) + static_cast<int64_t>(aDt) > 0)
105     {
106         start += static_cast<uint64_t>(aDt) + static_cast<int32_t>(aT0 - now);
107     }
108 
109     mMicroAlarmStart = start;
110 }
111 
StopMicroAlarm()112 void FakePlatform::StopMicroAlarm() { mMicroAlarmStart = kAlarmStop; }
113 #endif
114 
StartMilliAlarm(uint32_t aT0,uint32_t aDt)115 void FakePlatform::StartMilliAlarm(uint32_t aT0, uint32_t aDt)
116 {
117     uint64_t start = mNow - (mNow % OT_US_PER_MS);
118     uint32_t now   = (mNow / OT_US_PER_MS);
119 
120     if (static_cast<int32_t>(aT0 - now) > 0 || static_cast<int32_t>(aT0 - now) + static_cast<int64_t>(aDt) > 0)
121     {
122         start += (static_cast<uint64_t>(aDt) + static_cast<int32_t>(aT0 - now)) * OT_US_PER_MS;
123     }
124 
125     mMilliAlarmStart = start;
126 }
127 
StopMilliAlarm()128 void FakePlatform::StopMilliAlarm() { mMilliAlarmStart = kAlarmStop; }
129 
HandleSchedule()130 template <> void FakePlatform::HandleSchedule<&FakePlatform::mReceiveAtStart>() { mChannel = mReceiveAtChannel; }
131 
HandleSchedule()132 template <> void FakePlatform::HandleSchedule<&FakePlatform::mReceiveAtEnd>() { mChannel = 0; }
133 
ProcessSchedules(uint64_t & aTimeout)134 void FakePlatform::ProcessSchedules(uint64_t &aTimeout)
135 {
136     uint64_t guard = mNow + aTimeout;
137 
138     uint64_t *alarm = &guard;
139 #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
140     if (mMicroAlarmStart < *alarm)
141     {
142         alarm = &mMicroAlarmStart;
143     }
144 #endif
145     if (mMilliAlarmStart < *alarm)
146     {
147         alarm = &mMilliAlarmStart;
148     }
149     if (mReceiveAtStart < *alarm)
150     {
151         alarm = &mReceiveAtStart;
152     }
153     else if (mReceiveAtEnd < *alarm)
154     {
155         alarm = &mReceiveAtEnd;
156     }
157 
158     if (mNow < *alarm)
159     {
160         aTimeout -= *alarm - mNow;
161         mNow = *alarm;
162     }
163     *alarm = kAlarmStop;
164 
165     if (alarm == &guard)
166     {
167         // nonthing scheduled within this period.
168     }
169     else if (alarm == &mReceiveAtEnd)
170     {
171         FakePlatform::HandleSchedule<&FakePlatform::mReceiveAtEnd>();
172     }
173     else if (alarm == &mReceiveAtStart)
174     {
175         FakePlatform::HandleSchedule<&FakePlatform::mReceiveAtStart>();
176     }
177     else if (alarm == &mMilliAlarmStart)
178     {
179         FakePlatform::HandleSchedule<&FakePlatform::mMilliAlarmStart>();
180     }
181 #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
182     else if (alarm == &mMicroAlarmStart)
183     {
184         FakePlatform::HandleSchedule<&FakePlatform::mMicroAlarmStart>();
185     }
186 #endif
187 }
188 
Run(uint64_t aTimeoutInUs)189 uint64_t FakePlatform::Run(uint64_t aTimeoutInUs)
190 {
191     if (otTaskletsArePending(mInstance))
192     {
193         otTaskletsProcess(mInstance);
194     }
195     else
196     {
197         ProcessSchedules(aTimeoutInUs);
198     }
199 
200     return aTimeoutInUs;
201 }
202 
GoInUs(uint64_t aTimeoutInUs)203 void FakePlatform::GoInUs(uint64_t aTimeoutInUs)
204 {
205     while ((aTimeoutInUs = Run(aTimeoutInUs)) > 0)
206     {
207         // nothing
208     }
209 }
210 
Transmit(otRadioFrame * aFrame)211 otError FakePlatform::Transmit(otRadioFrame *aFrame)
212 {
213     otPlatRadioTxStarted(mInstance, aFrame);
214     return OT_ERROR_NONE;
215 }
216 
SettingsGet(uint16_t aKey,uint16_t aIndex,uint8_t * aValue,uint16_t * aValueLength) const217 otError FakePlatform::SettingsGet(uint16_t aKey, uint16_t aIndex, uint8_t *aValue, uint16_t *aValueLength) const
218 {
219     auto setting = mSettings.find(aKey);
220 
221     if (setting == mSettings.end())
222     {
223         return OT_ERROR_NOT_FOUND;
224     }
225 
226     if (aIndex > setting->second.size())
227     {
228         return OT_ERROR_NOT_FOUND;
229     }
230 
231     if (aValueLength == nullptr)
232     {
233         return OT_ERROR_NONE;
234     }
235 
236     const auto &data = setting->second[aIndex];
237 
238     if (aValue == nullptr)
239     {
240         *aValueLength = data.size();
241         return OT_ERROR_NONE;
242     }
243 
244     if (*aValueLength >= data.size())
245     {
246         *aValueLength = data.size();
247     }
248 
249     memcpy(aValue, &data[0], *aValueLength);
250 
251     return OT_ERROR_NONE;
252 }
253 
SettingsSet(uint16_t aKey,const uint8_t * aValue,uint16_t aValueLength)254 otError FakePlatform::SettingsSet(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
255 {
256     auto setting = std::vector<uint8_t>(aValue, aValue + aValueLength);
257 
258     mSettings[aKey].clear();
259     mSettings[aKey].push_back(setting);
260 
261     return OT_ERROR_NONE;
262 }
263 
SettingsAdd(uint16_t aKey,const uint8_t * aValue,uint16_t aValueLength)264 otError FakePlatform::SettingsAdd(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
265 {
266     auto setting = std::vector<uint8_t>(aValue, aValue + aValueLength);
267 
268     mSettings[aKey].push_back(setting);
269 
270     return OT_ERROR_NONE;
271 }
272 
SettingsDelete(uint16_t aKey,int aIndex)273 otError FakePlatform::SettingsDelete(uint16_t aKey, int aIndex)
274 {
275     auto setting = mSettings.find(aKey);
276     if (setting == mSettings.end())
277     {
278         return OT_ERROR_NOT_FOUND;
279     }
280 
281     if (static_cast<std::size_t>(aIndex) >= setting->second.size())
282     {
283         return OT_ERROR_NOT_FOUND;
284     }
285     setting->second.erase(setting->second.begin() + aIndex);
286     return OT_ERROR_NONE;
287 }
288 
SettingsWipe()289 void FakePlatform::SettingsWipe() { mSettings.clear(); }
290 
FlashInit()291 void FakePlatform::FlashInit() { memset(mFlash, 0xff, sizeof(mFlash)); }
FlashErase(uint8_t aSwapIndex)292 void FakePlatform::FlashErase(uint8_t aSwapIndex)
293 {
294     uint32_t address;
295 
296     assert(aSwapIndex < kFlashSwapNum);
297 
298     address = aSwapIndex ? kFlashSwapSize : 0;
299 
300     memset(mFlash + address, 0xff, kFlashSwapSize);
301 }
302 
FlashRead(uint8_t aSwapIndex,uint32_t aOffset,void * aData,uint32_t aSize) const303 void FakePlatform::FlashRead(uint8_t aSwapIndex, uint32_t aOffset, void *aData, uint32_t aSize) const
304 {
305     uint32_t address;
306 
307     assert(aSwapIndex < kFlashSwapNum);
308     assert(aSize <= kFlashSwapSize);
309     assert(aOffset <= (kFlashSwapSize - aSize));
310 
311     address = aSwapIndex ? kFlashSwapSize : 0;
312 
313     memcpy(aData, mFlash + address + aOffset, aSize);
314 }
315 
FlashWrite(uint8_t aSwapIndex,uint32_t aOffset,const void * aData,uint32_t aSize)316 void FakePlatform::FlashWrite(uint8_t aSwapIndex, uint32_t aOffset, const void *aData, uint32_t aSize)
317 {
318     uint32_t address;
319 
320     assert(aSwapIndex < kFlashSwapNum);
321     assert(aSize <= kFlashSwapSize);
322     assert(aOffset <= (kFlashSwapSize - aSize));
323 
324     address = aSwapIndex ? kFlashSwapSize : 0;
325 
326     for (uint32_t index = 0; index < aSize; index++)
327     {
328         mFlash[address + aOffset + index] &= static_cast<const uint8_t *>(aData)[index];
329     }
330 }
331 
332 } // namespace ot
333 
334 extern "C" {
335 
otTaskletsSignalPending(otInstance *)336 void otTaskletsSignalPending(otInstance *) {}
337 
otPlatAlarmMilliStop(otInstance *)338 void otPlatAlarmMilliStop(otInstance *) { FakePlatform::CurrentPlatform().StopMilliAlarm(); }
339 
otPlatAlarmMilliStartAt(otInstance *,uint32_t aT0,uint32_t aDt)340 void otPlatAlarmMilliStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
341 {
342     FakePlatform::CurrentPlatform().StartMilliAlarm(aT0, aDt);
343 }
344 
otPlatAlarmMilliGetNow(void)345 uint32_t otPlatAlarmMilliGetNow(void) { return FakePlatform::CurrentPlatform().GetNow() / OT_US_PER_MS; }
346 
347 #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
otPlatAlarmMicroStop(otInstance *)348 void otPlatAlarmMicroStop(otInstance *) { FakePlatform::CurrentPlatform().StopMicroAlarm(); }
otPlatAlarmMicroStartAt(otInstance *,uint32_t aT0,uint32_t aDt)349 void otPlatAlarmMicroStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
350 {
351     FakePlatform::CurrentPlatform().StartMicroAlarm(aT0, aDt);
352 }
353 #endif
354 
otPlatTimeGet(void)355 uint64_t otPlatTimeGet(void) { return FakePlatform::CurrentPlatform().GetNow(); }
otPlatTimeGetXtalAccuracy(void)356 uint16_t otPlatTimeGetXtalAccuracy(void) { return 0; }
357 
otPlatAlarmMicroGetNow(void)358 uint32_t otPlatAlarmMicroGetNow(void) { return otPlatTimeGet(); }
359 
otPlatRadioGetIeeeEui64(otInstance *,uint8_t * aIeeeEui64)360 void otPlatRadioGetIeeeEui64(otInstance *, uint8_t *aIeeeEui64)
361 {
362     uint64_t eui64 = FakePlatform::CurrentPlatform().GetEui64();
363     memcpy(aIeeeEui64, &eui64, sizeof(eui64));
364 }
365 
otPlatRadioSetPanId(otInstance *,uint16_t)366 void otPlatRadioSetPanId(otInstance *, uint16_t) {}
367 
otPlatRadioSetExtendedAddress(otInstance *,const otExtAddress *)368 void otPlatRadioSetExtendedAddress(otInstance *, const otExtAddress *) {}
369 
otPlatRadioSetShortAddress(otInstance *,uint16_t)370 void otPlatRadioSetShortAddress(otInstance *, uint16_t) {}
371 
otPlatRadioSetPromiscuous(otInstance *,bool)372 void otPlatRadioSetPromiscuous(otInstance *, bool) {}
373 
otPlatRadioSetRxOnWhenIdle(otInstance *,bool)374 void otPlatRadioSetRxOnWhenIdle(otInstance *, bool) {}
375 
otPlatRadioIsEnabled(otInstance *)376 bool otPlatRadioIsEnabled(otInstance *) { return true; }
377 
otPlatRadioEnable(otInstance *)378 otError otPlatRadioEnable(otInstance *) { return OT_ERROR_NONE; }
379 
otPlatRadioDisable(otInstance *)380 otError otPlatRadioDisable(otInstance *) { return OT_ERROR_NONE; }
381 
otPlatRadioSleep(otInstance *)382 otError otPlatRadioSleep(otInstance *) { return OT_ERROR_NONE; }
383 
otPlatRadioReceive(otInstance *,uint8_t aChannel)384 otError otPlatRadioReceive(otInstance *, uint8_t aChannel) { return FakePlatform::CurrentPlatform().Receive(aChannel); }
385 
otPlatRadioReceiveAt(otInstance *,uint8_t aChannel,uint32_t aStart,uint32_t aDuration)386 otError otPlatRadioReceiveAt(otInstance *, uint8_t aChannel, uint32_t aStart, uint32_t aDuration)
387 {
388     return FakePlatform::CurrentPlatform().ReceiveAt(aChannel, aStart, aDuration);
389 }
390 
otPlatRadioTransmit(otInstance *,otRadioFrame * aFrame)391 otError otPlatRadioTransmit(otInstance *, otRadioFrame *aFrame)
392 {
393     return FakePlatform::CurrentPlatform().Transmit(aFrame);
394 }
395 
otPlatRadioGetTransmitBuffer(otInstance *)396 otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *) { return FakePlatform::CurrentPlatform().GetTransmitBuffer(); }
397 
otPlatRadioGetRssi(otInstance *)398 int8_t otPlatRadioGetRssi(otInstance *) { return 0; }
399 
otPlatRadioGetCaps(otInstance *)400 otRadioCaps otPlatRadioGetCaps(otInstance *) { return OT_RADIO_CAPS_NONE; }
401 
otPlatRadioGetPromiscuous(otInstance *)402 bool otPlatRadioGetPromiscuous(otInstance *) { return false; }
403 
otPlatRadioEnableSrcMatch(otInstance *,bool aEnabled)404 void otPlatRadioEnableSrcMatch(otInstance *, bool aEnabled)
405 {
406     FakePlatform::CurrentPlatform().SrcMatchEnable(aEnabled);
407 }
408 
otPlatRadioAddSrcMatchShortEntry(otInstance *,uint16_t aShortAddr)409 otError otPlatRadioAddSrcMatchShortEntry(otInstance *, uint16_t aShortAddr)
410 {
411     FakePlatform::CurrentPlatform().SrcMatchAddShortEntry(aShortAddr);
412     return OT_ERROR_NONE;
413 }
414 
otPlatRadioAddSrcMatchExtEntry(otInstance *,const otExtAddress * aExtAddr)415 otError otPlatRadioAddSrcMatchExtEntry(otInstance *, const otExtAddress *aExtAddr)
416 {
417     FakePlatform::CurrentPlatform().SrcMatchAddExtEntry(*aExtAddr);
418     return OT_ERROR_NONE;
419 }
420 
otPlatRadioClearSrcMatchShortEntry(otInstance *,uint16_t aShortAddr)421 otError otPlatRadioClearSrcMatchShortEntry(otInstance *, uint16_t aShortAddr)
422 {
423     FakePlatform::CurrentPlatform().SrcMatchClearShortEntry(aShortAddr);
424     return OT_ERROR_NONE;
425 }
426 
otPlatRadioClearSrcMatchExtEntry(otInstance *,const otExtAddress * aExtAddr)427 otError otPlatRadioClearSrcMatchExtEntry(otInstance *, const otExtAddress *aExtAddr)
428 {
429     FakePlatform::CurrentPlatform().SrcMatchClearExtEntry(*aExtAddr);
430     return OT_ERROR_NONE;
431 }
432 
otPlatRadioClearSrcMatchShortEntries(otInstance *)433 void otPlatRadioClearSrcMatchShortEntries(otInstance *) { FakePlatform::CurrentPlatform().SrcMatchClearShortEntries(); }
434 
otPlatRadioClearSrcMatchExtEntries(otInstance *)435 void otPlatRadioClearSrcMatchExtEntries(otInstance *) { FakePlatform::CurrentPlatform().SrcMatchClearExtEntries(); }
436 
otPlatRadioEnergyScan(otInstance *,uint8_t,uint16_t)437 otError otPlatRadioEnergyScan(otInstance *, uint8_t, uint16_t) { return OT_ERROR_NOT_IMPLEMENTED; }
438 
otPlatRadioSetTransmitPower(otInstance *,int8_t)439 otError otPlatRadioSetTransmitPower(otInstance *, int8_t) { return OT_ERROR_NOT_IMPLEMENTED; }
440 
otPlatRadioGetReceiveSensitivity(otInstance *)441 int8_t otPlatRadioGetReceiveSensitivity(otInstance *) { return -100; }
442 
otPlatRadioSetCcaEnergyDetectThreshold(otInstance *,int8_t)443 otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *, int8_t) { return OT_ERROR_NONE; }
444 
otPlatRadioGetCcaEnergyDetectThreshold(otInstance *,int8_t *)445 otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *, int8_t *) { return OT_ERROR_NONE; }
446 
otPlatRadioGetCoexMetrics(otInstance *,otRadioCoexMetrics *)447 otError otPlatRadioGetCoexMetrics(otInstance *, otRadioCoexMetrics *) { return OT_ERROR_NONE; }
448 
otPlatRadioGetTransmitPower(otInstance *,int8_t *)449 otError otPlatRadioGetTransmitPower(otInstance *, int8_t *) { return OT_ERROR_NONE; }
450 
otPlatRadioIsCoexEnabled(otInstance *)451 bool otPlatRadioIsCoexEnabled(otInstance *) { return true; }
452 
otPlatRadioSetCoexEnabled(otInstance *,bool)453 otError otPlatRadioSetCoexEnabled(otInstance *, bool) { return OT_ERROR_NOT_IMPLEMENTED; }
454 
otPlatRadioConfigureEnhAckProbing(otInstance *,otLinkMetrics,otShortAddress,const otExtAddress *)455 otError otPlatRadioConfigureEnhAckProbing(otInstance *, otLinkMetrics, otShortAddress, const otExtAddress *)
456 {
457     return OT_ERROR_NOT_IMPLEMENTED;
458 }
459 
460 // Add WEAK here because in some unit test there is an implementation for `otPlatRadioSetChannelTargetPower`
otPlatRadioSetChannelTargetPower(otInstance *,uint8_t,int16_t)461 OT_TOOL_WEAK otError otPlatRadioSetChannelTargetPower(otInstance *, uint8_t, int16_t) { return OT_ERROR_NONE; }
462 
otPlatReset(otInstance *)463 void otPlatReset(otInstance *) {}
464 
otPlatGetResetReason(otInstance *)465 otPlatResetReason otPlatGetResetReason(otInstance *) { return OT_PLAT_RESET_REASON_POWER_ON; }
466 
otPlatWakeHost(void)467 void otPlatWakeHost(void) {}
468 
otPlatEntropyGet(uint8_t * aOutput,uint16_t aOutputLength)469 otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
470 {
471     otError error = OT_ERROR_NONE;
472 
473     assert(aOutput != nullptr);
474 
475     for (uint16_t length = 0; length < aOutputLength; length++)
476     {
477         aOutput[length] = static_cast<uint8_t>(rand());
478     }
479 
480     return error;
481 }
482 
otPlatDiagSetOutputCallback(otInstance *,otPlatDiagOutputCallback,void *)483 void otPlatDiagSetOutputCallback(otInstance *, otPlatDiagOutputCallback, void *) {}
484 
otPlatDiagModeSet(bool)485 void otPlatDiagModeSet(bool) {}
486 
otPlatDiagModeGet()487 bool otPlatDiagModeGet() { return false; }
488 
otPlatDiagChannelSet(uint8_t)489 void otPlatDiagChannelSet(uint8_t) {}
490 
otPlatDiagTxPowerSet(int8_t)491 void otPlatDiagTxPowerSet(int8_t) {}
492 
otPlatDiagRadioReceived(otInstance *,otRadioFrame *,otError)493 void otPlatDiagRadioReceived(otInstance *, otRadioFrame *, otError) {}
494 
otPlatDiagAlarmCallback(otInstance *)495 void otPlatDiagAlarmCallback(otInstance *) {}
496 
otPlatLog(otLogLevel,otLogRegion,const char *,...)497 OT_TOOL_WEAK void otPlatLog(otLogLevel, otLogRegion, const char *, ...) {}
498 
otPlatCAlloc(size_t aNum,size_t aSize)499 void *otPlatCAlloc(size_t aNum, size_t aSize) { return calloc(aNum, aSize); }
500 
otPlatFree(void * aPtr)501 void otPlatFree(void *aPtr) { free(aPtr); }
502 
otPlatInfraIfHasAddress(uint32_t,const otIp6Address *)503 bool otPlatInfraIfHasAddress(uint32_t, const otIp6Address *) { return false; }
504 
otPlatInfraIfSendIcmp6Nd(uint32_t,const otIp6Address *,const uint8_t *,uint16_t)505 otError otPlatInfraIfSendIcmp6Nd(uint32_t, const otIp6Address *, const uint8_t *, uint16_t) { return OT_ERROR_FAILED; }
506 
otPlatInfraIfDiscoverNat64Prefix(uint32_t)507 otError otPlatInfraIfDiscoverNat64Prefix(uint32_t) { return OT_ERROR_FAILED; }
508 
otPlatDsoEnableListening(otInstance *,bool)509 void otPlatDsoEnableListening(otInstance *, bool) {}
510 
otPlatDsoConnect(otPlatDsoConnection *,const otSockAddr *)511 void otPlatDsoConnect(otPlatDsoConnection *, const otSockAddr *) {}
512 
otPlatDsoSend(otPlatDsoConnection *,otMessage *)513 void otPlatDsoSend(otPlatDsoConnection *, otMessage *) {}
514 
otPlatDsoDisconnect(otPlatDsoConnection *,otPlatDsoDisconnectMode)515 void otPlatDsoDisconnect(otPlatDsoConnection *, otPlatDsoDisconnectMode) {}
516 
otPlatBleEnable(otInstance *)517 otError otPlatBleEnable(otInstance *) { return OT_ERROR_NONE; }
518 
otPlatBleDisable(otInstance *)519 otError otPlatBleDisable(otInstance *) { return OT_ERROR_NONE; }
520 
otPlatBleGetAdvertisementBuffer(otInstance *,uint8_t **)521 otError otPlatBleGetAdvertisementBuffer(otInstance *, uint8_t **) { return OT_ERROR_NO_BUFS; }
522 
otPlatBleGapAdvStart(otInstance *,uint16_t)523 otError otPlatBleGapAdvStart(otInstance *, uint16_t) { return OT_ERROR_NONE; }
524 
otPlatBleGapAdvStop(otInstance *)525 otError otPlatBleGapAdvStop(otInstance *) { return OT_ERROR_NONE; }
526 
otPlatBleGapDisconnect(otInstance *)527 otError otPlatBleGapDisconnect(otInstance *) { return OT_ERROR_NONE; }
528 
otPlatBleGattMtuGet(otInstance *,uint16_t *)529 otError otPlatBleGattMtuGet(otInstance *, uint16_t *) { return OT_ERROR_NONE; }
530 
otPlatBleGattServerIndicate(otInstance *,uint16_t,const otBleRadioPacket *)531 otError otPlatBleGattServerIndicate(otInstance *, uint16_t, const otBleRadioPacket *) { return OT_ERROR_NONE; }
532 
otPlatBleGetLinkCapabilities(otInstance *,otBleLinkCapabilities *)533 void otPlatBleGetLinkCapabilities(otInstance *, otBleLinkCapabilities *) {}
534 
otPlatBleSupportsMultiRadio(otInstance *)535 bool otPlatBleSupportsMultiRadio(otInstance *) { return false; }
536 
otPlatBleGapAdvSetData(otInstance *,uint8_t *,uint16_t)537 otError otPlatBleGapAdvSetData(otInstance *, uint8_t *, uint16_t) { return OT_ERROR_NONE; }
538 
otPlatRadioAddCalibratedPower(otInstance *,uint8_t,int16_t,const uint8_t *,uint16_t)539 OT_TOOL_WEAK otError otPlatRadioAddCalibratedPower(otInstance *, uint8_t, int16_t, const uint8_t *, uint16_t)
540 {
541     return OT_ERROR_NONE;
542 }
543 
otPlatRadioClearCalibratedPowers(otInstance *)544 OT_TOOL_WEAK otError otPlatRadioClearCalibratedPowers(otInstance *) { return OT_ERROR_NONE; }
545 
otPlatSettingsInit(otInstance *,const uint16_t *,uint16_t)546 void otPlatSettingsInit(otInstance *, const uint16_t *, uint16_t) {}
547 
otPlatSettingsDeinit(otInstance *)548 void otPlatSettingsDeinit(otInstance *) {}
549 
otPlatSettingsGet(otInstance *,uint16_t aKey,int aIndex,uint8_t * aValue,uint16_t * aValueLength)550 otError otPlatSettingsGet(otInstance *, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
551 {
552     return FakePlatform::CurrentPlatform().SettingsGet(aKey, aIndex, aValue, aValueLength);
553 }
554 
otPlatSettingsSet(otInstance *,uint16_t aKey,const uint8_t * aValue,uint16_t aValueLength)555 otError otPlatSettingsSet(otInstance *, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
556 {
557     return FakePlatform::CurrentPlatform().SettingsSet(aKey, aValue, aValueLength);
558 }
559 
otPlatSettingsAdd(otInstance *,uint16_t aKey,const uint8_t * aValue,uint16_t aValueLength)560 otError otPlatSettingsAdd(otInstance *, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
561 {
562     return FakePlatform::CurrentPlatform().SettingsAdd(aKey, aValue, aValueLength);
563 }
564 
otPlatSettingsDelete(otInstance *,uint16_t aKey,int aIndex)565 otError otPlatSettingsDelete(otInstance *, uint16_t aKey, int aIndex)
566 {
567     return FakePlatform::CurrentPlatform().SettingsDelete(aKey, aIndex);
568 }
569 
otPlatSettingsWipe(otInstance *)570 void otPlatSettingsWipe(otInstance *) { FakePlatform::CurrentPlatform().SettingsWipe(); }
571 
otPlatFlashInit(otInstance *)572 void otPlatFlashInit(otInstance *) { return FakePlatform::CurrentPlatform().FlashInit(); }
573 
otPlatFlashGetSwapSize(otInstance *)574 uint32_t otPlatFlashGetSwapSize(otInstance *) { return FakePlatform::CurrentPlatform().FlashGetSwapSize(); }
575 
otPlatFlashErase(otInstance *,uint8_t aSwapIndex)576 void otPlatFlashErase(otInstance *, uint8_t aSwapIndex) { FakePlatform::CurrentPlatform().FlashErase(aSwapIndex); }
577 
otPlatFlashRead(otInstance *,uint8_t aSwapIndex,uint32_t aOffset,void * aData,uint32_t aSize)578 void otPlatFlashRead(otInstance *, uint8_t aSwapIndex, uint32_t aOffset, void *aData, uint32_t aSize)
579 {
580     FakePlatform::CurrentPlatform().FlashRead(aSwapIndex, aOffset, aData, aSize);
581 }
582 
otPlatFlashWrite(otInstance *,uint8_t aSwapIndex,uint32_t aOffset,const void * aData,uint32_t aSize)583 void otPlatFlashWrite(otInstance *, uint8_t aSwapIndex, uint32_t aOffset, const void *aData, uint32_t aSize)
584 {
585     FakePlatform::CurrentPlatform().FlashWrite(aSwapIndex, aOffset, aData, aSize);
586 }
587 
otPlatTrelEnable(otInstance *,uint16_t *)588 void otPlatTrelEnable(otInstance *, uint16_t *) {}
otPlatTrelDisable(otInstance *)589 void otPlatTrelDisable(otInstance *) {}
otPlatTrelNotifyPeerSocketAddressDifference(otInstance *,const otSockAddr *,const otSockAddr *)590 void otPlatTrelNotifyPeerSocketAddressDifference(otInstance *, const otSockAddr *, const otSockAddr *) {}
otPlatTrelRegisterService(otInstance *,uint16_t,const uint8_t *,uint8_t)591 void otPlatTrelRegisterService(otInstance *, uint16_t, const uint8_t *, uint8_t) {}
otPlatTrelSend(otInstance *,const uint8_t *,uint16_t,const otSockAddr *)592 void otPlatTrelSend(otInstance *, const uint8_t *, uint16_t, const otSockAddr *) {}
otPlatTrelGetCounters(otInstance *)593 const otPlatTrelCounters *otPlatTrelGetCounters(otInstance *) { return nullptr; }
otPlatTrelResetCounters(otInstance *)594 void                      otPlatTrelResetCounters(otInstance *) {}
595 
otPlatUdpSocket(otUdpSocket *)596 otError otPlatUdpSocket(otUdpSocket *) { return OT_ERROR_NOT_IMPLEMENTED; }
otPlatUdpClose(otUdpSocket *)597 otError otPlatUdpClose(otUdpSocket *) { return OT_ERROR_NOT_IMPLEMENTED; }
otPlatUdpBind(otUdpSocket *)598 otError otPlatUdpBind(otUdpSocket *) { return OT_ERROR_NOT_IMPLEMENTED; }
otPlatUdpBindToNetif(otUdpSocket *,otNetifIdentifier)599 otError otPlatUdpBindToNetif(otUdpSocket *, otNetifIdentifier) { return OT_ERROR_NOT_IMPLEMENTED; }
otPlatUdpConnect(otUdpSocket *)600 otError otPlatUdpConnect(otUdpSocket *) { return OT_ERROR_NOT_IMPLEMENTED; }
otPlatUdpSend(otUdpSocket *,otMessage *,const otMessageInfo *)601 otError otPlatUdpSend(otUdpSocket *, otMessage *, const otMessageInfo *) { return OT_ERROR_NOT_IMPLEMENTED; }
otPlatUdpJoinMulticastGroup(otUdpSocket *,otNetifIdentifier,const otIp6Address *)602 otError otPlatUdpJoinMulticastGroup(otUdpSocket *, otNetifIdentifier, const otIp6Address *)
603 {
604     return OT_ERROR_NOT_IMPLEMENTED;
605 }
otPlatUdpLeaveMulticastGroup(otUdpSocket *,otNetifIdentifier,const otIp6Address *)606 otError otPlatUdpLeaveMulticastGroup(otUdpSocket *, otNetifIdentifier, const otIp6Address *)
607 {
608     return OT_ERROR_NOT_IMPLEMENTED;
609 }
otPlatAssertFail(const char *,int)610 void otPlatAssertFail(const char *, int) {}
611 } // extern "C"
612