1 /*
2 * Copyright (c) 2016, 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 // Disable OpenThread's own new implementation to avoid duplicate definition
30 #define OT_CORE_COMMON_NEW_HPP_
31 #include "test_platform.h"
32
33 #include <map>
34 #include <vector>
35
36 #include <stdio.h>
37 #include <sys/time.h>
38 #ifdef OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
39 #include <openthread/platform/ble.h>
40 #endif
41
42 enum
43 {
44 FLASH_SWAP_SIZE = 2048,
45 FLASH_SWAP_NUM = 2,
46 };
47
48 std::map<uint32_t, std::vector<std::vector<uint8_t>>> settings;
49
testInitInstance(void)50 ot::Instance *testInitInstance(void)
51 {
52 otInstance *instance = nullptr;
53
54 #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
55 #if OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
56 instance = otInstanceInitMultiple(0);
57 #else
58 size_t instanceBufferLength = 0;
59 uint8_t *instanceBuffer = nullptr;
60
61 // Call to query the buffer size
62 (void)otInstanceInit(nullptr, &instanceBufferLength);
63
64 // Call to allocate the buffer
65 instanceBuffer = (uint8_t *)malloc(instanceBufferLength);
66 VerifyOrQuit(instanceBuffer != nullptr, "Failed to allocate otInstance");
67 memset(instanceBuffer, 0, instanceBufferLength);
68
69 // Initialize OpenThread with the buffer
70 instance = otInstanceInit(instanceBuffer, &instanceBufferLength);
71 #endif
72 #else
73 instance = otInstanceInitSingle();
74 #endif
75
76 return static_cast<ot::Instance *>(instance);
77 }
78
79 #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
testInitAdditionalInstance(uint8_t id)80 ot::Instance *testInitAdditionalInstance(uint8_t id)
81 {
82 otInstance *instance = nullptr;
83
84 instance = otInstanceInitMultiple(id);
85
86 return static_cast<ot::Instance *>(instance);
87 }
88 #endif
89
testFreeInstance(otInstance * aInstance)90 void testFreeInstance(otInstance *aInstance)
91 {
92 otInstanceFinalize(aInstance);
93
94 #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && !OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
95 free(aInstance);
96 #endif
97 }
98
99 bool sDiagMode = false;
100
101 extern "C" {
102
103 #if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
otPlatCAlloc(size_t aNum,size_t aSize)104 OT_TOOL_WEAK void *otPlatCAlloc(size_t aNum, size_t aSize) { return calloc(aNum, aSize); }
105
otPlatFree(void * aPtr)106 OT_TOOL_WEAK void otPlatFree(void *aPtr) { free(aPtr); }
107 #endif
108
otTaskletsSignalPending(otInstance *)109 OT_TOOL_WEAK void otTaskletsSignalPending(otInstance *) {}
110
otPlatAlarmMilliStop(otInstance *)111 OT_TOOL_WEAK void otPlatAlarmMilliStop(otInstance *) {}
112
otPlatAlarmMilliStartAt(otInstance *,uint32_t,uint32_t)113 OT_TOOL_WEAK void otPlatAlarmMilliStartAt(otInstance *, uint32_t, uint32_t) {}
114
otPlatAlarmMilliGetNow(void)115 OT_TOOL_WEAK uint32_t otPlatAlarmMilliGetNow(void)
116 {
117 struct timeval tv;
118
119 gettimeofday(&tv, nullptr);
120
121 return (uint32_t)((tv.tv_sec * 1000) + (tv.tv_usec / 1000) + 123456);
122 }
123
otPlatAlarmMicroStop(otInstance *)124 OT_TOOL_WEAK void otPlatAlarmMicroStop(otInstance *) {}
125
otPlatAlarmMicroStartAt(otInstance *,uint32_t,uint32_t)126 OT_TOOL_WEAK void otPlatAlarmMicroStartAt(otInstance *, uint32_t, uint32_t) {}
127
otPlatAlarmMicroGetNow(void)128 OT_TOOL_WEAK uint32_t otPlatAlarmMicroGetNow(void)
129 {
130 struct timeval tv;
131
132 gettimeofday(&tv, nullptr);
133
134 return (uint32_t)((tv.tv_sec * 1000000) + tv.tv_usec + 123456);
135 }
136
otPlatMultipanGetActiveInstance(otInstance **)137 OT_TOOL_WEAK otError otPlatMultipanGetActiveInstance(otInstance **) { return OT_ERROR_NOT_IMPLEMENTED; }
138
otPlatMultipanSetActiveInstance(otInstance *,bool)139 OT_TOOL_WEAK otError otPlatMultipanSetActiveInstance(otInstance *, bool) { return OT_ERROR_NOT_IMPLEMENTED; }
140
otPlatRadioGetIeeeEui64(otInstance *,uint8_t *)141 OT_TOOL_WEAK void otPlatRadioGetIeeeEui64(otInstance *, uint8_t *) {}
142
otPlatRadioSetPanId(otInstance *,uint16_t)143 OT_TOOL_WEAK void otPlatRadioSetPanId(otInstance *, uint16_t) {}
144
otPlatRadioSetExtendedAddress(otInstance *,const otExtAddress *)145 OT_TOOL_WEAK void otPlatRadioSetExtendedAddress(otInstance *, const otExtAddress *) {}
146
otPlatRadioSetShortAddress(otInstance *,uint16_t)147 OT_TOOL_WEAK void otPlatRadioSetShortAddress(otInstance *, uint16_t) {}
148
otPlatRadioSetPromiscuous(otInstance *,bool)149 OT_TOOL_WEAK void otPlatRadioSetPromiscuous(otInstance *, bool) {}
150
otPlatRadioSetRxOnWhenIdle(otInstance *,bool)151 OT_TOOL_WEAK void otPlatRadioSetRxOnWhenIdle(otInstance *, bool) {}
152
otPlatRadioIsEnabled(otInstance *)153 OT_TOOL_WEAK bool otPlatRadioIsEnabled(otInstance *) { return true; }
154
otPlatRadioEnable(otInstance *)155 OT_TOOL_WEAK otError otPlatRadioEnable(otInstance *) { return OT_ERROR_NONE; }
156
otPlatRadioDisable(otInstance *)157 OT_TOOL_WEAK otError otPlatRadioDisable(otInstance *) { return OT_ERROR_NONE; }
158
otPlatRadioSleep(otInstance *)159 OT_TOOL_WEAK otError otPlatRadioSleep(otInstance *) { return OT_ERROR_NONE; }
160
otPlatRadioReceive(otInstance *,uint8_t)161 OT_TOOL_WEAK otError otPlatRadioReceive(otInstance *, uint8_t) { return OT_ERROR_NONE; }
162
otPlatRadioTransmit(otInstance *,otRadioFrame *)163 OT_TOOL_WEAK otError otPlatRadioTransmit(otInstance *, otRadioFrame *) { return OT_ERROR_NONE; }
164
otPlatRadioGetTransmitBuffer(otInstance *)165 OT_TOOL_WEAK otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *) { return nullptr; }
166
otPlatRadioGetRssi(otInstance *)167 OT_TOOL_WEAK int8_t otPlatRadioGetRssi(otInstance *) { return 0; }
168
otPlatRadioGetCaps(otInstance *)169 OT_TOOL_WEAK otRadioCaps otPlatRadioGetCaps(otInstance *) { return OT_RADIO_CAPS_NONE; }
170
otPlatRadioGetPromiscuous(otInstance *)171 OT_TOOL_WEAK bool otPlatRadioGetPromiscuous(otInstance *) { return false; }
172
otPlatRadioEnableSrcMatch(otInstance *,bool)173 OT_TOOL_WEAK void otPlatRadioEnableSrcMatch(otInstance *, bool) {}
174
otPlatRadioAddSrcMatchShortEntry(otInstance *,uint16_t)175 OT_TOOL_WEAK otError otPlatRadioAddSrcMatchShortEntry(otInstance *, uint16_t) { return OT_ERROR_NONE; }
176
otPlatRadioAddSrcMatchExtEntry(otInstance *,const otExtAddress *)177 OT_TOOL_WEAK otError otPlatRadioAddSrcMatchExtEntry(otInstance *, const otExtAddress *) { return OT_ERROR_NONE; }
178
otPlatRadioClearSrcMatchShortEntry(otInstance *,uint16_t)179 OT_TOOL_WEAK otError otPlatRadioClearSrcMatchShortEntry(otInstance *, uint16_t) { return OT_ERROR_NONE; }
180
otPlatRadioClearSrcMatchExtEntry(otInstance *,const otExtAddress *)181 OT_TOOL_WEAK otError otPlatRadioClearSrcMatchExtEntry(otInstance *, const otExtAddress *) { return OT_ERROR_NONE; }
182
otPlatRadioClearSrcMatchShortEntries(otInstance *)183 OT_TOOL_WEAK void otPlatRadioClearSrcMatchShortEntries(otInstance *) {}
184
otPlatRadioClearSrcMatchExtEntries(otInstance *)185 OT_TOOL_WEAK void otPlatRadioClearSrcMatchExtEntries(otInstance *) {}
186
otPlatRadioEnergyScan(otInstance *,uint8_t,uint16_t)187 OT_TOOL_WEAK otError otPlatRadioEnergyScan(otInstance *, uint8_t, uint16_t) { return OT_ERROR_NOT_IMPLEMENTED; }
188
otPlatRadioSetTransmitPower(otInstance *,int8_t)189 OT_TOOL_WEAK otError otPlatRadioSetTransmitPower(otInstance *, int8_t) { return OT_ERROR_NOT_IMPLEMENTED; }
190
otPlatRadioGetReceiveSensitivity(otInstance *)191 OT_TOOL_WEAK int8_t otPlatRadioGetReceiveSensitivity(otInstance *) { return -100; }
192
otPlatEntropyGet(uint8_t * aOutput,uint16_t aOutputLength)193 OT_TOOL_WEAK otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
194 {
195 otError error = OT_ERROR_NONE;
196
197 VerifyOrExit(aOutput, error = OT_ERROR_INVALID_ARGS);
198
199 #if __SANITIZE_ADDRESS__ == 0
200 {
201 FILE *file = nullptr;
202 size_t readLength;
203
204 file = fopen("/dev/urandom", "rb");
205 VerifyOrExit(file != nullptr, error = OT_ERROR_FAILED);
206
207 readLength = fread(aOutput, 1, aOutputLength, file);
208
209 if (readLength != aOutputLength)
210 {
211 error = OT_ERROR_FAILED;
212 }
213
214 fclose(file);
215 }
216 #else
217 for (uint16_t length = 0; length < aOutputLength; length++)
218 {
219 aOutput[length] = (uint8_t)rand();
220 }
221 #endif
222
223 exit:
224 return error;
225 }
226
otPlatDiagProcess(otInstance *,uint8_t,char * aArgs[],char * aOutput,size_t aOutputMaxLen)227 OT_TOOL_WEAK void otPlatDiagProcess(otInstance *, uint8_t, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
228 {
229 snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", aArgs[0]);
230 }
231
otPlatDiagModeSet(bool aMode)232 OT_TOOL_WEAK void otPlatDiagModeSet(bool aMode) { sDiagMode = aMode; }
233
otPlatDiagModeGet()234 OT_TOOL_WEAK bool otPlatDiagModeGet() { return sDiagMode; }
235
otPlatDiagChannelSet(uint8_t)236 OT_TOOL_WEAK void otPlatDiagChannelSet(uint8_t) {}
237
otPlatDiagTxPowerSet(int8_t)238 OT_TOOL_WEAK void otPlatDiagTxPowerSet(int8_t) {}
239
otPlatDiagRadioReceived(otInstance *,otRadioFrame *,otError)240 OT_TOOL_WEAK void otPlatDiagRadioReceived(otInstance *, otRadioFrame *, otError) {}
241
otPlatDiagAlarmCallback(otInstance *)242 OT_TOOL_WEAK void otPlatDiagAlarmCallback(otInstance *) {}
243
otPlatUartSendDone(void)244 OT_TOOL_WEAK void otPlatUartSendDone(void) {}
245
otPlatUartReceived(const uint8_t *,uint16_t)246 OT_TOOL_WEAK void otPlatUartReceived(const uint8_t *, uint16_t) {}
247
otPlatReset(otInstance *)248 OT_TOOL_WEAK void otPlatReset(otInstance *) {}
249
otPlatResetToBootloader(otInstance *)250 OT_TOOL_WEAK otError otPlatResetToBootloader(otInstance *) { return OT_ERROR_NOT_CAPABLE; }
251
otPlatGetResetReason(otInstance *)252 OT_TOOL_WEAK otPlatResetReason otPlatGetResetReason(otInstance *) { return OT_PLAT_RESET_REASON_POWER_ON; }
253
otPlatWakeHost(void)254 OT_TOOL_WEAK void otPlatWakeHost(void) {}
255
otPlatLog(otLogLevel,otLogRegion,const char *,...)256 OT_TOOL_WEAK void otPlatLog(otLogLevel, otLogRegion, const char *, ...) {}
257
otPlatSettingsInit(otInstance *,const uint16_t *,uint16_t)258 OT_TOOL_WEAK void otPlatSettingsInit(otInstance *, const uint16_t *, uint16_t) {}
259
otPlatSettingsDeinit(otInstance *)260 OT_TOOL_WEAK void otPlatSettingsDeinit(otInstance *) {}
261
otPlatSettingsGet(otInstance *,uint16_t aKey,int aIndex,uint8_t * aValue,uint16_t * aValueLength)262 OT_TOOL_WEAK otError otPlatSettingsGet(otInstance *, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
263 {
264 auto setting = settings.find(aKey);
265
266 if (setting == settings.end())
267 {
268 return OT_ERROR_NOT_FOUND;
269 }
270
271 if (aIndex > setting->second.size())
272 {
273 return OT_ERROR_NOT_FOUND;
274 }
275
276 if (aValueLength == nullptr)
277 {
278 return OT_ERROR_NONE;
279 }
280
281 const auto &data = setting->second[aIndex];
282
283 if (aValue == nullptr)
284 {
285 *aValueLength = data.size();
286 return OT_ERROR_NONE;
287 }
288
289 if (*aValueLength >= data.size())
290 {
291 *aValueLength = data.size();
292 }
293
294 memcpy(aValue, &data[0], *aValueLength);
295
296 return OT_ERROR_NONE;
297 }
298
otPlatSettingsSet(otInstance *,uint16_t aKey,const uint8_t * aValue,uint16_t aValueLength)299 OT_TOOL_WEAK otError otPlatSettingsSet(otInstance *, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
300 {
301 auto setting = std::vector<uint8_t>(aValue, aValue + aValueLength);
302
303 settings[aKey].clear();
304 settings[aKey].push_back(setting);
305
306 return OT_ERROR_NONE;
307 }
308
otPlatSettingsAdd(otInstance *,uint16_t aKey,const uint8_t * aValue,uint16_t aValueLength)309 OT_TOOL_WEAK otError otPlatSettingsAdd(otInstance *, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
310 {
311 auto setting = std::vector<uint8_t>(aValue, aValue + aValueLength);
312 settings[aKey].push_back(setting);
313
314 return OT_ERROR_NONE;
315 }
316
otPlatSettingsDelete(otInstance *,uint16_t aKey,int aIndex)317 OT_TOOL_WEAK otError otPlatSettingsDelete(otInstance *, uint16_t aKey, int aIndex)
318 {
319 auto setting = settings.find(aKey);
320 if (setting == settings.end())
321 {
322 return OT_ERROR_NOT_FOUND;
323 }
324
325 if (aIndex >= setting->second.size())
326 {
327 return OT_ERROR_NOT_FOUND;
328 }
329 setting->second.erase(setting->second.begin() + aIndex);
330 return OT_ERROR_NONE;
331 }
332
otPlatSettingsWipe(otInstance *)333 OT_TOOL_WEAK void otPlatSettingsWipe(otInstance *) { settings.clear(); }
334
GetFlash(void)335 uint8_t *GetFlash(void)
336 {
337 static uint8_t sFlash[FLASH_SWAP_SIZE * FLASH_SWAP_NUM];
338 static bool sInitialized;
339
340 if (!sInitialized)
341 {
342 memset(sFlash, 0xff, sizeof(sFlash));
343 sInitialized = true;
344 }
345
346 return sFlash;
347 }
348
otPlatFlashInit(otInstance *)349 OT_TOOL_WEAK void otPlatFlashInit(otInstance *) {}
350
otPlatFlashGetSwapSize(otInstance *)351 OT_TOOL_WEAK uint32_t otPlatFlashGetSwapSize(otInstance *) { return FLASH_SWAP_SIZE; }
352
otPlatFlashErase(otInstance *,uint8_t aSwapIndex)353 OT_TOOL_WEAK void otPlatFlashErase(otInstance *, uint8_t aSwapIndex)
354 {
355 uint32_t address;
356
357 VerifyOrQuit(aSwapIndex < FLASH_SWAP_NUM, "aSwapIndex invalid");
358
359 address = aSwapIndex ? FLASH_SWAP_SIZE : 0;
360
361 memset(GetFlash() + address, 0xff, FLASH_SWAP_SIZE);
362 }
363
otPlatFlashRead(otInstance *,uint8_t aSwapIndex,uint32_t aOffset,void * aData,uint32_t aSize)364 OT_TOOL_WEAK void otPlatFlashRead(otInstance *, uint8_t aSwapIndex, uint32_t aOffset, void *aData, uint32_t aSize)
365 {
366 uint32_t address;
367
368 VerifyOrQuit(aSwapIndex < FLASH_SWAP_NUM, "aSwapIndex invalid");
369 VerifyOrQuit(aSize <= FLASH_SWAP_SIZE, "aSize invalid");
370 VerifyOrQuit(aOffset <= (FLASH_SWAP_SIZE - aSize), "aOffset + aSize invalid");
371
372 address = aSwapIndex ? FLASH_SWAP_SIZE : 0;
373
374 memcpy(aData, GetFlash() + address + aOffset, aSize);
375 }
376
otPlatFlashWrite(otInstance *,uint8_t aSwapIndex,uint32_t aOffset,const void * aData,uint32_t aSize)377 OT_TOOL_WEAK void otPlatFlashWrite(otInstance *,
378 uint8_t aSwapIndex,
379 uint32_t aOffset,
380 const void *aData,
381 uint32_t aSize)
382 {
383 uint32_t address;
384
385 VerifyOrQuit(aSwapIndex < FLASH_SWAP_NUM, "aSwapIndex invalid");
386 VerifyOrQuit(aSize <= FLASH_SWAP_SIZE, "aSize invalid");
387 VerifyOrQuit(aOffset <= (FLASH_SWAP_SIZE - aSize), "aOffset + aSize invalid");
388
389 address = aSwapIndex ? FLASH_SWAP_SIZE : 0;
390
391 for (uint32_t index = 0; index < aSize; index++)
392 {
393 GetFlash()[address + aOffset + index] &= ((uint8_t *)aData)[index];
394 }
395 }
396
397 #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
otPlatTimeGetXtalAccuracy(void)398 OT_TOOL_WEAK uint16_t otPlatTimeGetXtalAccuracy(void) { return 0; }
399 #endif
400
401 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
otPlatRadioEnableCsl(otInstance *,uint32_t,otShortAddress,const otExtAddress *)402 OT_TOOL_WEAK otError otPlatRadioEnableCsl(otInstance *, uint32_t, otShortAddress, const otExtAddress *)
403 {
404 return OT_ERROR_NONE;
405 }
406
otPlatRadioResetCsl(otInstance *)407 OT_TOOL_WEAK otError otPlatRadioResetCsl(otInstance *) { return OT_ERROR_NONE; }
408
otPlatRadioUpdateCslSampleTime(otInstance *,uint32_t)409 OT_TOOL_WEAK void otPlatRadioUpdateCslSampleTime(otInstance *, uint32_t) {}
410
otPlatRadioGetCslAccuracy(otInstance *)411 OT_TOOL_WEAK uint8_t otPlatRadioGetCslAccuracy(otInstance *)
412 {
413 return static_cast<uint8_t>(otPlatTimeGetXtalAccuracy() / 2);
414 }
415 #endif
416
417 #if OPENTHREAD_CONFIG_OTNS_ENABLE
otPlatOtnsStatus(const char *)418 OT_TOOL_WEAK void otPlatOtnsStatus(const char *) {}
419 #endif
420
421 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
otPlatTrelEnable(otInstance *,uint16_t *)422 OT_TOOL_WEAK void otPlatTrelEnable(otInstance *, uint16_t *) {}
423
otPlatTrelDisable(otInstance *)424 OT_TOOL_WEAK void otPlatTrelDisable(otInstance *) {}
425
otPlatTrelSend(otInstance *,const uint8_t *,uint16_t,const otSockAddr *)426 OT_TOOL_WEAK void otPlatTrelSend(otInstance *, const uint8_t *, uint16_t, const otSockAddr *) {}
427
otPlatTrelRegisterService(otInstance *,uint16_t,const uint8_t *,uint8_t)428 OT_TOOL_WEAK void otPlatTrelRegisterService(otInstance *, uint16_t, const uint8_t *, uint8_t) {}
429
otPlatTrelGetCounters(otInstance *)430 OT_TOOL_WEAK const otPlatTrelCounters *otPlatTrelGetCounters(otInstance *) { return nullptr; }
431
otPlatTrelResetCounters(otInstance *)432 OT_TOOL_WEAK void otPlatTrelResetCounters(otInstance *) {}
433 #endif
434
435 #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
otPlatRadioConfigureEnhAckProbing(otInstance *,otLinkMetrics,const otShortAddress,const otExtAddress *)436 OT_TOOL_WEAK otError otPlatRadioConfigureEnhAckProbing(otInstance *,
437 otLinkMetrics,
438 const otShortAddress,
439 const otExtAddress *)
440 {
441 return OT_ERROR_NONE;
442 }
443
otPlatRadioGetEnhAckProbingMetrics(otInstance *,const otShortAddress)444 OT_TOOL_WEAK otLinkMetrics otPlatRadioGetEnhAckProbingMetrics(otInstance *, const otShortAddress)
445 {
446 otLinkMetrics metrics;
447
448 memset(&metrics, 0, sizeof(metrics));
449
450 return metrics;
451 }
452 #endif
453
454 #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
otPlatInfraIfHasAddress(uint32_t,const otIp6Address *)455 OT_TOOL_WEAK bool otPlatInfraIfHasAddress(uint32_t, const otIp6Address *) { return false; }
456
otPlatInfraIfSendIcmp6Nd(uint32_t,const otIp6Address *,const uint8_t *,uint16_t)457 OT_TOOL_WEAK otError otPlatInfraIfSendIcmp6Nd(uint32_t, const otIp6Address *, const uint8_t *, uint16_t)
458 {
459 return OT_ERROR_FAILED;
460 }
461
otPlatInfraIfDiscoverNat64Prefix(uint32_t)462 OT_TOOL_WEAK otError otPlatInfraIfDiscoverNat64Prefix(uint32_t) { return OT_ERROR_FAILED; }
463 #endif
464
465 #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
466
otPlatCryptoImportKey(otCryptoKeyRef * aKeyRef,otCryptoKeyType aKeyType,otCryptoKeyAlgorithm aKeyAlgorithm,int aKeyUsage,otCryptoKeyStorage aKeyPersistence,const uint8_t * aKey,size_t aKeyLen)467 otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef,
468 otCryptoKeyType aKeyType,
469 otCryptoKeyAlgorithm aKeyAlgorithm,
470 int aKeyUsage,
471 otCryptoKeyStorage aKeyPersistence,
472 const uint8_t *aKey,
473 size_t aKeyLen)
474 {
475 OT_UNUSED_VARIABLE(aKeyRef);
476 OT_UNUSED_VARIABLE(aKeyType);
477 OT_UNUSED_VARIABLE(aKeyAlgorithm);
478 OT_UNUSED_VARIABLE(aKeyUsage);
479 OT_UNUSED_VARIABLE(aKeyPersistence);
480 OT_UNUSED_VARIABLE(aKey);
481 OT_UNUSED_VARIABLE(aKeyLen);
482
483 return OT_ERROR_NONE;
484 }
485
otPlatCryptoExportKey(otCryptoKeyRef aKeyRef,uint8_t * aBuffer,size_t aBufferLen,size_t * aKeyLen)486 otError otPlatCryptoExportKey(otCryptoKeyRef aKeyRef, uint8_t *aBuffer, size_t aBufferLen, size_t *aKeyLen)
487 {
488 OT_UNUSED_VARIABLE(aKeyRef);
489 OT_UNUSED_VARIABLE(aBuffer);
490 OT_UNUSED_VARIABLE(aBufferLen);
491
492 *aKeyLen = 0;
493
494 return OT_ERROR_NONE;
495 }
496
otPlatCryptoDestroyKey(otCryptoKeyRef aKeyRef)497 otError otPlatCryptoDestroyKey(otCryptoKeyRef aKeyRef)
498 {
499 OT_UNUSED_VARIABLE(aKeyRef);
500
501 return OT_ERROR_NONE;
502 }
503
otPlatCryptoHasKey(otCryptoKeyRef aKeyRef)504 bool otPlatCryptoHasKey(otCryptoKeyRef aKeyRef)
505 {
506 OT_UNUSED_VARIABLE(aKeyRef);
507
508 return false;
509 }
510
otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef)511 otError otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef)
512 {
513 OT_UNUSED_VARIABLE(aKeyRef);
514
515 return OT_ERROR_NONE;
516 }
517
otPlatCryptoEcdsaExportPublicKey(otCryptoKeyRef aKeyRef,otPlatCryptoEcdsaPublicKey * aPublicKey)518 otError otPlatCryptoEcdsaExportPublicKey(otCryptoKeyRef aKeyRef, otPlatCryptoEcdsaPublicKey *aPublicKey)
519 {
520 OT_UNUSED_VARIABLE(aKeyRef);
521 OT_UNUSED_VARIABLE(aPublicKey);
522
523 return OT_ERROR_NONE;
524 }
525
otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef,const otPlatCryptoSha256Hash * aHash,otPlatCryptoEcdsaSignature * aSignature)526 otError otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef,
527 const otPlatCryptoSha256Hash *aHash,
528 otPlatCryptoEcdsaSignature *aSignature)
529 {
530 OT_UNUSED_VARIABLE(aKeyRef);
531 OT_UNUSED_VARIABLE(aHash);
532 OT_UNUSED_VARIABLE(aSignature);
533
534 return OT_ERROR_NONE;
535 }
536
otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKeyRef,const otPlatCryptoSha256Hash * aHash,const otPlatCryptoEcdsaSignature * aSignature)537 otError otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKeyRef,
538 const otPlatCryptoSha256Hash *aHash,
539 const otPlatCryptoEcdsaSignature *aSignature)
540 {
541 OT_UNUSED_VARIABLE(aKeyRef);
542 OT_UNUSED_VARIABLE(aHash);
543 OT_UNUSED_VARIABLE(aSignature);
544
545 return OT_ERROR_NONE;
546 }
547
548 #endif // OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
549
otPlatRadioSetCcaEnergyDetectThreshold(otInstance * aInstance,int8_t aThreshold)550 otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aThreshold)
551 {
552 OT_UNUSED_VARIABLE(aInstance);
553 OT_UNUSED_VARIABLE(aThreshold);
554
555 return OT_ERROR_NONE;
556 }
557
558 #if OPENTHREAD_CONFIG_DNS_DSO_ENABLE
559
otPlatDsoEnableListening(otInstance * aInstance,bool aEnable)560 OT_TOOL_WEAK void otPlatDsoEnableListening(otInstance *aInstance, bool aEnable)
561 {
562 OT_UNUSED_VARIABLE(aInstance);
563 OT_UNUSED_VARIABLE(aEnable);
564 }
565
otPlatDsoConnect(otPlatDsoConnection * aConnection,const otSockAddr * aPeerSockAddr)566 OT_TOOL_WEAK void otPlatDsoConnect(otPlatDsoConnection *aConnection, const otSockAddr *aPeerSockAddr)
567 {
568 OT_UNUSED_VARIABLE(aConnection);
569 OT_UNUSED_VARIABLE(aPeerSockAddr);
570 }
571
otPlatDsoSend(otPlatDsoConnection * aConnection,otMessage * aMessage)572 OT_TOOL_WEAK void otPlatDsoSend(otPlatDsoConnection *aConnection, otMessage *aMessage)
573 {
574 OT_UNUSED_VARIABLE(aConnection);
575 OT_UNUSED_VARIABLE(aMessage);
576 }
577
otPlatDsoDisconnect(otPlatDsoConnection * aConnection,otPlatDsoDisconnectMode aMode)578 OT_TOOL_WEAK void otPlatDsoDisconnect(otPlatDsoConnection *aConnection, otPlatDsoDisconnectMode aMode)
579 {
580 OT_UNUSED_VARIABLE(aConnection);
581 OT_UNUSED_VARIABLE(aMode);
582 }
583
584 #endif // #if OPENTHREAD_CONFIG_DNS_DSO_ENABLE
585
586 #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
otPlatUdpSocket(otUdpSocket * aUdpSocket)587 otError otPlatUdpSocket(otUdpSocket *aUdpSocket)
588 {
589 OT_UNUSED_VARIABLE(aUdpSocket);
590 return OT_ERROR_NONE;
591 }
592
otPlatUdpClose(otUdpSocket * aUdpSocket)593 otError otPlatUdpClose(otUdpSocket *aUdpSocket)
594 {
595 OT_UNUSED_VARIABLE(aUdpSocket);
596 return OT_ERROR_NONE;
597 }
598
otPlatUdpBind(otUdpSocket * aUdpSocket)599 otError otPlatUdpBind(otUdpSocket *aUdpSocket)
600 {
601 OT_UNUSED_VARIABLE(aUdpSocket);
602 return OT_ERROR_NONE;
603 }
604
otPlatUdpBindToNetif(otUdpSocket * aUdpSocket,otNetifIdentifier aNetifIdentifier)605 otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifIdentifier)
606 {
607 OT_UNUSED_VARIABLE(aUdpSocket);
608 OT_UNUSED_VARIABLE(aNetifIdentifier);
609 return OT_ERROR_NONE;
610 }
611
otPlatUdpConnect(otUdpSocket * aUdpSocket)612 otError otPlatUdpConnect(otUdpSocket *aUdpSocket)
613 {
614 OT_UNUSED_VARIABLE(aUdpSocket);
615 return OT_ERROR_NONE;
616 }
617
otPlatUdpSend(otUdpSocket * aUdpSocket,otMessage * aMessage,const otMessageInfo * aMessageInfo)618 otError otPlatUdpSend(otUdpSocket *aUdpSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo)
619 {
620 OT_UNUSED_VARIABLE(aUdpSocket);
621 OT_UNUSED_VARIABLE(aMessageInfo);
622 return OT_ERROR_NONE;
623 }
624
otPlatUdpJoinMulticastGroup(otUdpSocket * aUdpSocket,otNetifIdentifier aNetifIdentifier,const otIp6Address * aAddress)625 otError otPlatUdpJoinMulticastGroup(otUdpSocket *aUdpSocket,
626 otNetifIdentifier aNetifIdentifier,
627 const otIp6Address *aAddress)
628 {
629 OT_UNUSED_VARIABLE(aUdpSocket);
630 OT_UNUSED_VARIABLE(aNetifIdentifier);
631 OT_UNUSED_VARIABLE(aAddress);
632 return OT_ERROR_NONE;
633 }
634
otPlatUdpLeaveMulticastGroup(otUdpSocket * aUdpSocket,otNetifIdentifier aNetifIdentifier,const otIp6Address * aAddress)635 otError otPlatUdpLeaveMulticastGroup(otUdpSocket *aUdpSocket,
636 otNetifIdentifier aNetifIdentifier,
637 const otIp6Address *aAddress)
638 {
639 OT_UNUSED_VARIABLE(aUdpSocket);
640 OT_UNUSED_VARIABLE(aNetifIdentifier);
641 OT_UNUSED_VARIABLE(aAddress);
642 return OT_ERROR_NONE;
643 }
644 #endif // OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
645
646 #if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
otPlatDnsStartUpstreamQuery(otInstance * aInstance,otPlatDnsUpstreamQuery * aTxn,const otMessage * aQuery)647 void otPlatDnsStartUpstreamQuery(otInstance *aInstance, otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
648 {
649 OT_UNUSED_VARIABLE(aInstance);
650 OT_UNUSED_VARIABLE(aTxn);
651 OT_UNUSED_VARIABLE(aQuery);
652 }
653
otPlatDnsCancelUpstreamQuery(otInstance * aInstance,otPlatDnsUpstreamQuery * aTxn)654 void otPlatDnsCancelUpstreamQuery(otInstance *aInstance, otPlatDnsUpstreamQuery *aTxn)
655 {
656 otPlatDnsUpstreamQueryDone(aInstance, aTxn, nullptr);
657 }
658 #endif
659
otPlatRadioGetCcaEnergyDetectThreshold(otInstance *,int8_t *)660 OT_TOOL_WEAK otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *, int8_t *) { return OT_ERROR_NONE; }
661
otPlatRadioGetCoexMetrics(otInstance *,otRadioCoexMetrics *)662 OT_TOOL_WEAK otError otPlatRadioGetCoexMetrics(otInstance *, otRadioCoexMetrics *) { return OT_ERROR_NONE; }
663
otPlatRadioGetTransmitPower(otInstance *,int8_t *)664 OT_TOOL_WEAK otError otPlatRadioGetTransmitPower(otInstance *, int8_t *) { return OT_ERROR_NONE; }
665
otPlatRadioIsCoexEnabled(otInstance *)666 OT_TOOL_WEAK bool otPlatRadioIsCoexEnabled(otInstance *) { return true; }
667
otPlatRadioSetCoexEnabled(otInstance *,bool)668 OT_TOOL_WEAK otError otPlatRadioSetCoexEnabled(otInstance *, bool) { return OT_ERROR_NOT_IMPLEMENTED; }
669
670 #if OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
otPlatRadioSetChannelTargetPower(otInstance * aInstance,uint8_t aChannel,int16_t aTargetPower)671 OT_TOOL_WEAK otError otPlatRadioSetChannelTargetPower(otInstance *aInstance, uint8_t aChannel, int16_t aTargetPower)
672 {
673 return OT_ERROR_NONE;
674 }
675
otPlatRadioAddCalibratedPower(otInstance * aInstance,uint8_t aChannel,int16_t aActualPower,const uint8_t * aRawPowerSetting,uint16_t aRawPowerSettingLength)676 OT_TOOL_WEAK otError otPlatRadioAddCalibratedPower(otInstance *aInstance,
677 uint8_t aChannel,
678 int16_t aActualPower,
679 const uint8_t *aRawPowerSetting,
680 uint16_t aRawPowerSettingLength)
681 {
682 return OT_ERROR_NONE;
683 }
684
otPlatRadioClearCalibratedPowers(otInstance * aInstance)685 OT_TOOL_WEAK otError otPlatRadioClearCalibratedPowers(otInstance *aInstance) { return OT_ERROR_NONE; }
686 #endif // OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
687
688 #if OPENTHREAD_CONFIG_NCP_ENABLE_MCU_POWER_STATE_CONTROL
otPlatGetMcuPowerState(otInstance * aInstance)689 OT_TOOL_WEAK otPlatMcuPowerState otPlatGetMcuPowerState(otInstance *aInstance) { return OT_PLAT_MCU_POWER_STATE_ON; }
690
otPlatSetMcuPowerState(otInstance * aInstance,otPlatMcuPowerState aState)691 OT_TOOL_WEAK otError otPlatSetMcuPowerState(otInstance *aInstance, otPlatMcuPowerState aState) { return OT_ERROR_NONE; }
692 #endif // OPENTHREAD_CONFIG_NCP_ENABLE_MCU_POWER_STATE_CONTROL
693 #ifdef OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
otPlatBleEnable(otInstance * aInstance)694 otError otPlatBleEnable(otInstance *aInstance)
695 {
696 OT_UNUSED_VARIABLE(aInstance);
697 return OT_ERROR_NOT_IMPLEMENTED;
698 }
699
otPlatBleDisable(otInstance * aInstance)700 otError otPlatBleDisable(otInstance *aInstance)
701 {
702 OT_UNUSED_VARIABLE(aInstance);
703 return OT_ERROR_NOT_IMPLEMENTED;
704 }
705
otPlatBleGapAdvStart(otInstance * aInstance,uint16_t aInterval)706 otError otPlatBleGapAdvStart(otInstance *aInstance, uint16_t aInterval)
707 {
708 OT_UNUSED_VARIABLE(aInstance);
709 OT_UNUSED_VARIABLE(aInterval);
710 return OT_ERROR_NOT_IMPLEMENTED;
711 }
712
otPlatBleGapAdvStop(otInstance * aInstance)713 otError otPlatBleGapAdvStop(otInstance *aInstance)
714 {
715 OT_UNUSED_VARIABLE(aInstance);
716 return OT_ERROR_NOT_IMPLEMENTED;
717 }
718
otPlatBleGapDisconnect(otInstance * aInstance)719 otError otPlatBleGapDisconnect(otInstance *aInstance)
720 {
721 OT_UNUSED_VARIABLE(aInstance);
722 return OT_ERROR_NOT_IMPLEMENTED;
723 }
724
otPlatBleGattMtuGet(otInstance * aInstance,uint16_t * aMtu)725 otError otPlatBleGattMtuGet(otInstance *aInstance, uint16_t *aMtu)
726 {
727 OT_UNUSED_VARIABLE(aInstance);
728 OT_UNUSED_VARIABLE(aMtu);
729 return OT_ERROR_NOT_IMPLEMENTED;
730 }
731
otPlatBleGattServerIndicate(otInstance * aInstance,uint16_t aHandle,const otBleRadioPacket * aPacket)732 otError otPlatBleGattServerIndicate(otInstance *aInstance, uint16_t aHandle, const otBleRadioPacket *aPacket)
733 {
734 OT_UNUSED_VARIABLE(aInstance);
735 OT_UNUSED_VARIABLE(aHandle);
736 OT_UNUSED_VARIABLE(aPacket);
737 return OT_ERROR_NOT_IMPLEMENTED;
738 }
739 #endif // OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
740
741 } // extern "C"
742