From 7f680552ebc199d37f78549d5fd55391c3cc68aa Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 18 Jan 2017 12:03:23 -0800 Subject: [PATCH] Thread API cleanup. --- etc/visual-studio/libopenthread.vcxproj | 1 + .../libopenthread.vcxproj.filters | 3 + etc/visual-studio/libopenthread_k.vcxproj | 1 + .../libopenthread_k.vcxproj.filters | 3 + examples/apps/windows/MainPage.xaml.cpp | 20 +- examples/drivers/windows/otApi/otApi.cpp | 142 ++- examples/drivers/windows/otLwf/iocontrol.c | 132 ++- examples/drivers/windows/otLwf/thread.c | 2 +- .../drivers/windows/otNodeApi/otNodeApi.cpp | 68 +- examples/platforms/da15000/platform.c | 2 +- include/openthread-types.h | 12 - include/openthread.h | 847 +--------------- include/openthread/Makefile.am | 1 + include/openthread/thread.h | 901 ++++++++++++++++++ src/cli/cli.cpp | 116 +-- src/core/Makefile.am | 1 + src/core/api/instance_api.cpp | 6 +- src/core/api/thread_api.cpp | 658 +++++++++++++ src/core/openthread.cpp | 612 ------------ src/ncp/ncp_base.cpp | 118 +-- tests/unit/test_fuzz.cpp | 2 +- 21 files changed, 1865 insertions(+), 1783 deletions(-) create mode 100644 include/openthread/thread.h create mode 100644 src/core/api/thread_api.cpp diff --git a/etc/visual-studio/libopenthread.vcxproj b/etc/visual-studio/libopenthread.vcxproj index 003dbd4f3..f63d45be7 100644 --- a/etc/visual-studio/libopenthread.vcxproj +++ b/etc/visual-studio/libopenthread.vcxproj @@ -66,6 +66,7 @@ + diff --git a/etc/visual-studio/libopenthread.vcxproj.filters b/etc/visual-studio/libopenthread.vcxproj.filters index 27f01fbf5..277b82efe 100644 --- a/etc/visual-studio/libopenthread.vcxproj.filters +++ b/etc/visual-studio/libopenthread.vcxproj.filters @@ -93,6 +93,9 @@ Source Files\api + + Source Files\api + Source Files\coap diff --git a/etc/visual-studio/libopenthread_k.vcxproj b/etc/visual-studio/libopenthread_k.vcxproj index ad6f8bb73..9528623cc 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj +++ b/etc/visual-studio/libopenthread_k.vcxproj @@ -74,6 +74,7 @@ + diff --git a/etc/visual-studio/libopenthread_k.vcxproj.filters b/etc/visual-studio/libopenthread_k.vcxproj.filters index 7fbbc86af..3004870f5 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj.filters +++ b/etc/visual-studio/libopenthread_k.vcxproj.filters @@ -93,6 +93,9 @@ Source Files\api + + Source Files\api + Source Files\coap diff --git a/examples/apps/windows/MainPage.xaml.cpp b/examples/apps/windows/MainPage.xaml.cpp index ed34fd654..8abe3b4ad 100644 --- a/examples/apps/windows/MainPage.xaml.cpp +++ b/examples/apps/windows/MainPage.xaml.cpp @@ -204,7 +204,7 @@ void MainPage::ShowInterfaceDetails(Platform::Guid InterfaceGuid) InterfaceMacAddress->Text = L"ERROR"; } - auto ml_eid = otGetMeshLocalEid(device); + auto ml_eid = otThreadGetMeshLocalEid(device); if (ml_eid) { WCHAR szAddress[46] = { 0 }; @@ -218,16 +218,16 @@ void MainPage::ShowInterfaceDetails(Platform::Guid InterfaceGuid) InterfaceML_EID->Text = L"ERROR"; } - auto rloc16 = otGetRloc16(device); + auto rloc16 = otThreadGetRloc16(device); WCHAR szRloc[16] = { 0 }; swprintf_s(szRloc, 16, L"%4x", rloc16); InterfaceRLOC->Text = ref new String(szRloc); - if (otGetDeviceRole(device) > kDeviceRoleChild) + if (otThreadGetDeviceRole(device) > kDeviceRoleChild) { uint8_t index = 0; otChildInfo childInfo; - while (kThreadError_None == otGetChildInfoByIndex(device, index, &childInfo)) + while (kThreadError_None == otThreadGetChildInfoByIndex(device, index, &childInfo)) { index++; } @@ -255,7 +255,7 @@ UIElement^ MainPage::CreateNewInterface(Platform::Guid InterfaceGuid) GUID deviceGuid = InterfaceGuid; auto device = otInstanceInit(ApiInstance, &deviceGuid); - auto deviceRole = otGetDeviceRole(device); + auto deviceRole = otThreadGetDeviceRole(device); WCHAR szText[256] = { 0 }; swprintf_s(szText, 256, L"%s\r\n\t" GUID_FORMAT L"\r\n\t%s", @@ -364,14 +364,14 @@ void MainPage::ConnectNetwork(Platform::Guid InterfaceGuid) otNetworkName networkName = {}; wcstombs(networkName.m8, InterfaceConfigName->Text->Data(), sizeof(networkName.m8)); - otSetNetworkName(device, networkName.m8); + otThreadSetNetworkName(device, networkName.m8); otMasterKey masterKey = {}; wcstombs((char*)masterKey.m8, InterfaceConfigKey->Text->Data(), sizeof(masterKey.m8)); - otSetMasterKey(device, masterKey.m8, sizeof(masterKey.m8)); + otThreadSetMasterKey(device, masterKey.m8, sizeof(masterKey.m8)); otLinkSetChannel(device, (uint8_t)InterfaceConfigChannel->Value); - otSetMaxAllowedChildren(device, (uint8_t)InterfaceConfigMaxChildren->Value); + otThreadSetMaxAllowedChildren(device, (uint8_t)InterfaceConfigMaxChildren->Value); otLinkSetPanId(device, 0x4567); @@ -381,7 +381,7 @@ void MainPage::ConnectNetwork(Platform::Guid InterfaceGuid) otIp6SetEnabled(device, true); - otThreadStart(device); + otThreadSetEnabled(device, true); // Cleanup otFreeMemory(device); @@ -398,7 +398,7 @@ void MainPage::DisconnectNetwork(Platform::Guid InterfaceGuid) // Start the Thread logic and the interface // - otThreadStop(device); + otThreadSetEnabled(device, false); otIp6SetEnabled(device, false); diff --git a/examples/drivers/windows/otApi/otApi.cpp b/examples/drivers/windows/otApi/otApi.cpp index 241189445..877dade34 100644 --- a/examples/drivers/windows/otApi/otApi.cpp +++ b/examples/drivers/windows/otApi/otApi.cpp @@ -1215,23 +1215,13 @@ otIp6IsEnabled( OTAPI ThreadError OTCALL -otThreadStart( - _In_ otInstance *aInstance +otThreadSetEnabled( + _In_ otInstance *aInstance, + bool aEnabled ) { if (aInstance == nullptr) return kThreadError_InvalidArgs; - return DwordToThreadError(SetIOCTL(aInstance, IOCTL_OTLWF_OT_THREAD, (BOOLEAN)TRUE)); -} - -OTAPI -ThreadError -OTCALL -otThreadStop( - _In_ otInstance *aInstance - ) -{ - if (aInstance == nullptr) return kThreadError_InvalidArgs; - return DwordToThreadError(SetIOCTL(aInstance, IOCTL_OTLWF_OT_THREAD, (BOOLEAN)FALSE)); + return DwordToThreadError(SetIOCTL(aInstance, IOCTL_OTLWF_OT_THREAD, (BOOLEAN)aEnabled)); } OTAPI @@ -1261,7 +1251,7 @@ otThreadGetAutoStart( OTAPI bool OTCALL -otIsSingleton( +otThreadIsSingleton( _In_ otInstance *aInstance ) { @@ -1341,7 +1331,7 @@ otLinkIsEnergyScanInProgress( OTAPI ThreadError OTCALL -otDiscover( +otThreadDiscover( _In_ otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration, @@ -1438,7 +1428,7 @@ otDatasetGetDelayTimerMinimal( OTAPI uint8_t OTCALL -otGetMaxAllowedChildren( +otThreadGetMaxAllowedChildren( _In_ otInstance *aInstance ) { @@ -1450,7 +1440,7 @@ otGetMaxAllowedChildren( OTAPI ThreadError OTCALL -otSetMaxAllowedChildren( +otThreadSetMaxAllowedChildren( _In_ otInstance *aInstance, uint8_t aMaxChildren ) @@ -1462,7 +1452,7 @@ otSetMaxAllowedChildren( OTAPI uint32_t OTCALL -otGetChildTimeout( +otThreadGetChildTimeout( _In_ otInstance *aInstance ) { @@ -1474,7 +1464,7 @@ otGetChildTimeout( OTAPI void OTCALL -otSetChildTimeout( +otThreadSetChildTimeout( _In_ otInstance *aInstance, uint32_t aTimeout ) @@ -1517,7 +1507,7 @@ otLinkSetExtendedAddress( OTAPI const uint8_t * OTCALL -otGetExtendedPanId( +otThreadGetExtendedPanId( _In_ otInstance *aInstance ) { @@ -1535,7 +1525,7 @@ otGetExtendedPanId( OTAPI void OTCALL -otSetExtendedPanId( +otThreadSetExtendedPanId( _In_ otInstance *aInstance, const uint8_t *aExtendedPanId ) @@ -1570,7 +1560,7 @@ otLinkGetJoinerId( OTAPI ThreadError OTCALL -otGetLeaderRloc( +otThreadGetLeaderRloc( _In_ otInstance *aInstance, _Out_ otIp6Address *aLeaderRloc ) @@ -1582,7 +1572,7 @@ otGetLeaderRloc( OTAPI otLinkModeConfig OTCALL -otGetLinkMode( +otThreadGetLinkMode( _In_ otInstance *aInstance ) { @@ -1595,7 +1585,7 @@ otGetLinkMode( OTAPI ThreadError OTCALL -otSetLinkMode( +otThreadSetLinkMode( _In_ otInstance *aInstance, otLinkModeConfig aConfig ) @@ -1608,7 +1598,7 @@ otSetLinkMode( OTAPI const uint8_t * OTCALL -otGetMasterKey( +otThreadGetMasterKey( _In_ otInstance *aInstance, _Out_ uint8_t *aKeyLength ) @@ -1639,7 +1629,7 @@ otGetMasterKey( OTAPI ThreadError OTCALL -otSetMasterKey( +otThreadSetMasterKey( _In_ otInstance *aInstance, const uint8_t *aKey, uint8_t aKeyLength @@ -1681,7 +1671,7 @@ otLinkSetMaxTransmitPower( OTAPI const otIp6Address * OTCALL -otGetMeshLocalEid( +otThreadGetMeshLocalEid( _In_ otInstance *aInstance ) { @@ -1697,7 +1687,7 @@ otGetMeshLocalEid( OTAPI const uint8_t * OTCALL -otGetMeshLocalPrefix( +otThreadGetMeshLocalPrefix( _In_ otInstance *aInstance ) { @@ -1715,7 +1705,7 @@ otGetMeshLocalPrefix( OTAPI ThreadError OTCALL -otSetMeshLocalPrefix( +otThreadSetMeshLocalPrefix( _In_ otInstance *aInstance, const uint8_t *aMeshLocalPrefix ) @@ -1727,7 +1717,7 @@ otSetMeshLocalPrefix( OTAPI ThreadError OTCALL -otGetNetworkDataLeader( +otThreadGetNetworkDataLeader( _In_ otInstance *aInstance, bool aStable, _Out_ uint8_t *aData, @@ -1745,7 +1735,7 @@ otGetNetworkDataLeader( OTAPI ThreadError OTCALL -otGetNetworkDataLocal( +otThreadGetNetworkDataLocal( _In_ otInstance *aInstance, bool aStable, _Out_ uint8_t *aData, @@ -1763,7 +1753,7 @@ otGetNetworkDataLocal( OTAPI const char * OTCALL -otGetNetworkName( +otThreadGetNetworkName( _In_ otInstance *aInstance ) { @@ -1781,7 +1771,7 @@ otGetNetworkName( OTAPI ThreadError OTCALL -otSetNetworkName( +otThreadSetNetworkName( _In_ otInstance *aInstance, _In_ const char *aNetworkName ) @@ -1857,7 +1847,7 @@ otLinkSetPanId( OTAPI bool OTCALL -otIsRouterRoleEnabled( +otThreadIsRouterRoleEnabled( _In_ otInstance *aInstance ) { @@ -1869,7 +1859,7 @@ otIsRouterRoleEnabled( OTAPI void OTCALL -otSetRouterRoleEnabled( +otThreadSetRouterRoleEnabled( _In_ otInstance *aInstance, bool aEnabled ) @@ -2375,7 +2365,7 @@ otLinkSetPollPeriod( OTAPI uint8_t OTCALL -otGetLocalLeaderWeight( +otThreadGetLocalLeaderWeight( _In_ otInstance *aInstance ) { @@ -2387,7 +2377,7 @@ otGetLocalLeaderWeight( OTAPI void OTCALL -otSetLocalLeaderWeight( +otThreadSetLocalLeaderWeight( _In_ otInstance *aInstance, uint8_t aWeight ) @@ -2398,7 +2388,7 @@ otSetLocalLeaderWeight( OTAPI uint32_t OTCALL -otGetLocalLeaderPartitionId( +otThreadGetLocalLeaderPartitionId( _In_ otInstance *aInstance ) { @@ -2410,7 +2400,7 @@ otGetLocalLeaderPartitionId( OTAPI void OTCALL -otSetLocalLeaderPartitionId( +otThreadSetLocalLeaderPartitionId( _In_ otInstance *aInstance, uint32_t aPartitionId ) @@ -2421,7 +2411,7 @@ otSetLocalLeaderPartitionId( OTAPI uint16_t OTCALL -otGetJoinerUdpPort( +otThreadGetJoinerUdpPort( _In_ otInstance *aInstance ) { @@ -2433,7 +2423,7 @@ otGetJoinerUdpPort( OTAPI ThreadError OTCALL -otSetJoinerUdpPort( +otThreadSetJoinerUdpPort( _In_ otInstance *aInstance, uint16_t aJoinerUdpPort ) @@ -2504,7 +2494,7 @@ otNetDataRegister( OTAPI uint32_t OTCALL -otGetContextIdReuseDelay( +otThreadGetContextIdReuseDelay( _In_ otInstance *aInstance ) { @@ -2516,7 +2506,7 @@ otGetContextIdReuseDelay( OTAPI void OTCALL -otSetContextIdReuseDelay( +otThreadSetContextIdReuseDelay( _In_ otInstance *aInstance, uint32_t aDelay ) @@ -2527,7 +2517,7 @@ otSetContextIdReuseDelay( OTAPI uint32_t OTCALL -otGetKeySequenceCounter( +otThreadGetKeySequenceCounter( _In_ otInstance *aInstance ) { @@ -2539,7 +2529,7 @@ otGetKeySequenceCounter( OTAPI void OTCALL -otSetKeySequenceCounter( +otThreadSetKeySequenceCounter( _In_ otInstance *aInstance, uint32_t aKeySequenceCounter ) @@ -2550,7 +2540,7 @@ otSetKeySequenceCounter( OTAPI uint32_t OTCALL -otGetKeySwitchGuardTime( +otThreadGetKeySwitchGuardTime( _In_ otInstance *aInstance ) { @@ -2562,7 +2552,7 @@ otGetKeySwitchGuardTime( OTAPI void OTCALL -otSetKeySwitchGuardTime( +otThreadSetKeySwitchGuardTime( _In_ otInstance *aInstance, uint32_t aKeySwitchGuardTime ) @@ -2573,7 +2563,7 @@ otSetKeySwitchGuardTime( OTAPI uint8_t OTCALL -otGetNetworkIdTimeout( +otThreadGetNetworkIdTimeout( _In_ otInstance *aInstance ) { @@ -2585,7 +2575,7 @@ otGetNetworkIdTimeout( OTAPI void OTCALL -otSetNetworkIdTimeout( +otThreadSetNetworkIdTimeout( _In_ otInstance *aInstance, uint8_t aTimeout ) @@ -2596,7 +2586,7 @@ otSetNetworkIdTimeout( OTAPI uint8_t OTCALL -otGetRouterUpgradeThreshold( +otThreadGetRouterUpgradeThreshold( _In_ otInstance *aInstance ) { @@ -2608,7 +2598,7 @@ otGetRouterUpgradeThreshold( OTAPI void OTCALL -otSetRouterUpgradeThreshold( +otThreadSetRouterUpgradeThreshold( _In_ otInstance *aInstance, uint8_t aThreshold ) @@ -2619,7 +2609,7 @@ otSetRouterUpgradeThreshold( OTAPI uint8_t OTCALL -otGetRouterDowngradeThreshold( +otThreadGetRouterDowngradeThreshold( _In_ otInstance *aInstance ) { @@ -2631,7 +2621,7 @@ otGetRouterDowngradeThreshold( OTAPI void OTCALL -otSetRouterDowngradeThreshold( +otThreadSetRouterDowngradeThreshold( _In_ otInstance *aInstance, uint8_t aThreshold ) @@ -2642,7 +2632,7 @@ otSetRouterDowngradeThreshold( OTAPI uint8_t OTCALL -otGetRouterSelectionJitter( +otThreadGetRouterSelectionJitter( _In_ otInstance *aInstance ) { @@ -2654,7 +2644,7 @@ otGetRouterSelectionJitter( OTAPI void OTCALL -otSetRouterSelectionJitter( +otThreadSetRouterSelectionJitter( _In_ otInstance *aInstance, uint8_t aRouterJitter ) @@ -2665,7 +2655,7 @@ otSetRouterSelectionJitter( OTAPI ThreadError OTCALL -otReleaseRouterId( +otThreadReleaseRouterId( _In_ otInstance *aInstance, uint8_t aRouterId ) @@ -2761,7 +2751,7 @@ otLinkIsWhitelistEnabled( OTAPI ThreadError OTCALL -otBecomeDetached( +otThreadBecomeDetached( _In_ otInstance *aInstance ) { @@ -2772,7 +2762,7 @@ otBecomeDetached( OTAPI ThreadError OTCALL -otBecomeChild( +otThreadBecomeChild( _In_ otInstance *aInstance, otMleAttachFilter aFilter ) @@ -2789,7 +2779,7 @@ otBecomeChild( OTAPI ThreadError OTCALL -otBecomeRouter( +otThreadBecomeRouter( _In_ otInstance *aInstance ) { @@ -2800,7 +2790,7 @@ otBecomeRouter( OTAPI ThreadError OTCALL -otBecomeLeader( +otThreadBecomeLeader( _In_ otInstance *aInstance ) { @@ -2927,7 +2917,7 @@ otInstanceFactoryReset( OTAPI ThreadError OTCALL -otGetChildInfoById( +otThreadGetChildInfoById( _In_ otInstance *aInstance, uint16_t aChildId, _Out_ otChildInfo *aChildInfo @@ -2940,7 +2930,7 @@ otGetChildInfoById( OTAPI ThreadError OTCALL -otGetChildInfoByIndex( +otThreadGetChildInfoByIndex( _In_ otInstance *aInstance, uint8_t aChildIndex, _Out_ otChildInfo *aChildInfo @@ -2953,7 +2943,7 @@ otGetChildInfoByIndex( OTAPI ThreadError OTCALL -otGetNextNeighborInfo( +otThreadGetNextNeighborInfo( _In_ otInstance *aInstance, _Inout_ otNeighborInfoIterator *aIterator, _Out_ otNeighborInfo *aInfo @@ -2968,7 +2958,7 @@ otGetNextNeighborInfo( OTAPI otDeviceRole OTCALL -otGetDeviceRole( +otThreadGetDeviceRole( _In_ otInstance *aInstance ) { @@ -2980,7 +2970,7 @@ otGetDeviceRole( OTAPI ThreadError OTCALL -otGetEidCacheEntry( +otThreadGetEidCacheEntry( _In_ otInstance *aInstance, uint8_t aIndex, _Out_ otEidCacheEntry *aEntry @@ -2993,7 +2983,7 @@ otGetEidCacheEntry( OTAPI ThreadError OTCALL -otGetLeaderData( +otThreadGetLeaderData( _In_ otInstance *aInstance, _Out_ otLeaderData *aLeaderData ) @@ -3005,7 +2995,7 @@ otGetLeaderData( OTAPI uint8_t OTCALL -otGetLeaderRouterId( +otThreadGetLeaderRouterId( _In_ otInstance *aInstance ) { @@ -3017,7 +3007,7 @@ otGetLeaderRouterId( OTAPI uint8_t OTCALL -otGetLeaderWeight( +otThreadGetLeaderWeight( _In_ otInstance *aInstance ) { @@ -3041,7 +3031,7 @@ otNetDataGetVersion( OTAPI uint32_t OTCALL -otGetPartitionId( +otThreadGetPartitionId( _In_ otInstance *aInstance ) { @@ -3053,7 +3043,7 @@ otGetPartitionId( OTAPI uint16_t OTCALL -otGetRloc16( +otThreadGetRloc16( _In_ otInstance *aInstance ) { @@ -3065,7 +3055,7 @@ otGetRloc16( OTAPI uint8_t OTCALL -otGetRouterIdSequence( +otThreadGetRouterIdSequence( _In_ otInstance *aInstance ) { @@ -3077,7 +3067,7 @@ otGetRouterIdSequence( OTAPI ThreadError OTCALL -otGetRouterInfo( +otThreadGetRouterInfo( _In_ otInstance *aInstance, uint16_t aRouterId, _Out_ otRouterInfo *aRouterInfo @@ -3090,7 +3080,7 @@ otGetRouterInfo( OTAPI ThreadError OTCALL -otGetParentInfo( +otThreadGetParentInfo( _In_ otInstance *aInstance, _Out_ otRouterInfo *aParentInfo ) @@ -3439,7 +3429,7 @@ otThreadErrorToString( OTAPI ThreadError OTCALL -otSendDiagnosticGet( +otThreadSendDiagnosticGet( _In_ otInstance *aInstance, const otIp6Address *aDestination, const uint8_t aTlvTypes[], @@ -3468,7 +3458,7 @@ otSendDiagnosticGet( OTAPI ThreadError OTCALL -otSendDiagnosticReset( +otThreadSendDiagnosticReset( _In_ otInstance *aInstance, const otIp6Address *aDestination, const uint8_t aTlvTypes[], diff --git a/examples/drivers/windows/otLwf/iocontrol.c b/examples/drivers/windows/otLwf/iocontrol.c index 93bc2894b..c84a277ef 100644 --- a/examples/drivers/windows/otLwf/iocontrol.c +++ b/examples/drivers/windows/otLwf/iocontrol.c @@ -567,20 +567,12 @@ otLwfIoCtl_otThread( if (InBufferLength >= sizeof(BOOLEAN)) { BOOLEAN IsEnabled = *(BOOLEAN*)InBuffer; - if (IsEnabled) - { - status = ThreadErrorToNtstatus(otThreadStart(pFilter->otCtx)); - } - else - { - status = ThreadErrorToNtstatus(otThreadStop(pFilter->otCtx)); - } - + status = ThreadErrorToNtstatus(otThreadSetEnabled(pFilter->otCtx, IsEnabled)); *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(BOOLEAN)) { - *(BOOLEAN*)OutBuffer = (otGetDeviceRole(pFilter->otCtx) > kDeviceRoleDisabled) ? TRUE : FALSE; + *(BOOLEAN*)OutBuffer = (otThreadGetDeviceRole(pFilter->otCtx) > kDeviceRoleDisabled) ? TRUE : FALSE; *OutBufferLength = sizeof(BOOLEAN); status = STATUS_SUCCESS; } @@ -917,7 +909,7 @@ otLwfIoCtl_otDiscover( uint16_t aScanDuration = *(uint16_t*)(InBuffer + sizeof(uint32_t)); uint16_t aPanid = *(uint16_t*)(InBuffer + sizeof(uint32_t) + sizeof(uint16_t)); status = ThreadErrorToNtstatus( - otDiscover( + otThreadDiscover( pFilter->otCtx, aScanChannels, aScanDuration, @@ -928,7 +920,7 @@ otLwfIoCtl_otDiscover( } else if (*OutBufferLength >= sizeof(BOOLEAN)) { - *(BOOLEAN*)OutBuffer = otIsDiscoverInProgress(pFilter->otCtx) ? TRUE : FALSE; + *(BOOLEAN*)OutBuffer = otThreadIsDiscoverInProgress(pFilter->otCtx) ? TRUE : FALSE; *OutBufferLength = sizeof(BOOLEAN); status = STATUS_SUCCESS; } @@ -1054,13 +1046,13 @@ otLwfIoCtl_otChildTimeout( if (InBufferLength >= sizeof(uint32_t)) { - otSetChildTimeout(pFilter->otCtx, *(uint32_t*)InBuffer); + otThreadSetChildTimeout(pFilter->otCtx, *(uint32_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint32_t)) { - *(uint32_t*)OutBuffer = otGetChildTimeout(pFilter->otCtx); + *(uint32_t*)OutBuffer = otThreadGetChildTimeout(pFilter->otCtx); *OutBufferLength = sizeof(uint32_t); status = STATUS_SUCCESS; } @@ -1253,13 +1245,13 @@ otLwfIoCtl_otExtendedPanId( if (InBufferLength >= sizeof(otExtendedPanId)) { - otSetExtendedPanId(pFilter->otCtx, (uint8_t*)InBuffer); + otThreadSetExtendedPanId(pFilter->otCtx, (uint8_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(otExtendedPanId)) { - memcpy(OutBuffer, otGetExtendedPanId(pFilter->otCtx), sizeof(otExtendedPanId)); + memcpy(OutBuffer, otThreadGetExtendedPanId(pFilter->otCtx), sizeof(otExtendedPanId)); *OutBufferLength = sizeof(otExtendedPanId); status = STATUS_SUCCESS; } @@ -1422,7 +1414,7 @@ otLwfIoCtl_otLeaderRloc( if (*OutBufferLength >= sizeof(otIp6Address)) { - status = ThreadErrorToNtstatus(otGetLeaderRloc(pFilter->otCtx, (otIp6Address*)OutBuffer)); + status = ThreadErrorToNtstatus(otThreadGetLeaderRloc(pFilter->otCtx, (otIp6Address*)OutBuffer)); *OutBufferLength = sizeof(otIp6Address); } else @@ -1517,12 +1509,12 @@ otLwfIoCtl_otLinkMode( static_assert(sizeof(otLinkModeConfig) == 4, "The size of otLinkModeConfig should be 4 bytes"); if (InBufferLength >= sizeof(otLinkModeConfig)) { - status = ThreadErrorToNtstatus(otSetLinkMode(pFilter->otCtx, *(otLinkModeConfig*)InBuffer)); + status = ThreadErrorToNtstatus(otThreadSetLinkMode(pFilter->otCtx, *(otLinkModeConfig*)InBuffer)); *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(otLinkModeConfig)) { - *(otLinkModeConfig*)OutBuffer = otGetLinkMode(pFilter->otCtx); + *(otLinkModeConfig*)OutBuffer = otThreadGetLinkMode(pFilter->otCtx); *OutBufferLength = sizeof(otLinkModeConfig); status = STATUS_SUCCESS; } @@ -1640,13 +1632,13 @@ otLwfIoCtl_otMasterKey( if (InBufferLength >= sizeof(otMasterKey) + sizeof(uint8_t)) { uint8_t aKeyLength = *(uint8_t*)(InBuffer + sizeof(otMasterKey)); - status = ThreadErrorToNtstatus(otSetMasterKey(pFilter->otCtx, InBuffer, aKeyLength)); + status = ThreadErrorToNtstatus(otThreadSetMasterKey(pFilter->otCtx, InBuffer, aKeyLength)); *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(otMasterKey) + sizeof(uint8_t)) { uint8_t aKeyLength = 0; - const uint8_t* aMasterKey = otGetMasterKey(pFilter->otCtx, &aKeyLength); + const uint8_t* aMasterKey = otThreadGetMasterKey(pFilter->otCtx, &aKeyLength); memcpy(OutBuffer, aMasterKey, aKeyLength); memcpy((PUCHAR)OutBuffer + sizeof(otMasterKey), &aKeyLength, sizeof(uint8_t)); *OutBufferLength = sizeof(otMasterKey) + sizeof(uint8_t); @@ -1752,7 +1744,7 @@ otLwfIoCtl_otMeshLocalEid( if (*OutBufferLength >= sizeof(otIp6Address)) { - memcpy(OutBuffer, otGetMeshLocalEid(pFilter->otCtx), sizeof(otIp6Address)); + memcpy(OutBuffer, otThreadGetMeshLocalEid(pFilter->otCtx), sizeof(otIp6Address)); status = STATUS_SUCCESS; } else @@ -1836,12 +1828,12 @@ otLwfIoCtl_otMeshLocalPrefix( if (InBufferLength >= sizeof(otMeshLocalPrefix)) { - status = ThreadErrorToNtstatus(otSetMeshLocalPrefix(pFilter->otCtx, InBuffer)); + status = ThreadErrorToNtstatus(otThreadSetMeshLocalPrefix(pFilter->otCtx, InBuffer)); *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(otMeshLocalPrefix)) { - memcpy(OutBuffer, otGetMeshLocalPrefix(pFilter->otCtx), sizeof(otMeshLocalPrefix)); + memcpy(OutBuffer, otThreadGetMeshLocalPrefix(pFilter->otCtx), sizeof(otMeshLocalPrefix)); *OutBufferLength = sizeof(otMeshLocalPrefix); status = STATUS_SUCCESS; } @@ -1942,12 +1934,12 @@ otLwfIoCtl_otNetworkName( if (InBufferLength >= sizeof(otNetworkName)) { - status = ThreadErrorToNtstatus(otSetNetworkName(pFilter->otCtx, (char*)InBuffer)); + status = ThreadErrorToNtstatus(otThreadSetNetworkName(pFilter->otCtx, (char*)InBuffer)); *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(otNetworkName)) { - strcpy_s((char*)OutBuffer, sizeof(otNetworkName), otGetNetworkName(pFilter->otCtx)); + strcpy_s((char*)OutBuffer, sizeof(otNetworkName), otThreadGetNetworkName(pFilter->otCtx)); *OutBufferLength = sizeof(otNetworkName); status = STATUS_SUCCESS; } @@ -2140,13 +2132,13 @@ otLwfIoCtl_otRouterRollEnabled( if (InBufferLength >= sizeof(BOOLEAN)) { - otSetRouterRoleEnabled(pFilter->otCtx, *(BOOLEAN*)InBuffer); + otThreadSetRouterRoleEnabled(pFilter->otCtx, *(BOOLEAN*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(BOOLEAN)) { - *(BOOLEAN*)OutBuffer = otIsRouterRoleEnabled(pFilter->otCtx) ? TRUE : FALSE; + *(BOOLEAN*)OutBuffer = otThreadIsRouterRoleEnabled(pFilter->otCtx) ? TRUE : FALSE; *OutBufferLength = sizeof(BOOLEAN); status = STATUS_SUCCESS; } @@ -2391,13 +2383,13 @@ otLwfIoCtl_otLocalLeaderWeight( if (InBufferLength >= sizeof(uint8_t)) { - otSetLocalLeaderWeight(pFilter->otCtx, *(uint8_t*)InBuffer); + otThreadSetLocalLeaderWeight(pFilter->otCtx, *(uint8_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetLeaderWeight(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetLeaderWeight(pFilter->otCtx); *OutBufferLength = sizeof(uint8_t); status = STATUS_SUCCESS; } @@ -2793,13 +2785,13 @@ otLwfIoCtl_otContextIdReuseDelay( if (InBufferLength >= sizeof(uint32_t)) { - otSetContextIdReuseDelay(pFilter->otCtx, *(uint32_t*)InBuffer); + otThreadSetContextIdReuseDelay(pFilter->otCtx, *(uint32_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint32_t)) { - *(uint32_t*)OutBuffer = otGetContextIdReuseDelay(pFilter->otCtx); + *(uint32_t*)OutBuffer = otThreadGetContextIdReuseDelay(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint32_t); } @@ -2892,13 +2884,13 @@ otLwfIoCtl_otKeySequenceCounter( if (InBufferLength >= sizeof(uint32_t)) { - otSetKeySequenceCounter(pFilter->otCtx, *(uint32_t*)InBuffer); + otThreadSetKeySequenceCounter(pFilter->otCtx, *(uint32_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint32_t)) { - *(uint32_t*)OutBuffer = otGetKeySequenceCounter(pFilter->otCtx); + *(uint32_t*)OutBuffer = otThreadGetKeySequenceCounter(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint32_t); } @@ -2991,13 +2983,13 @@ otLwfIoCtl_otNetworkIdTimeout( if (InBufferLength >= sizeof(uint8_t)) { - otSetNetworkIdTimeout(pFilter->otCtx, *(uint8_t*)InBuffer); + otThreadSetNetworkIdTimeout(pFilter->otCtx, *(uint8_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetNetworkIdTimeout(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetNetworkIdTimeout(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint8_t); } @@ -3090,13 +3082,13 @@ otLwfIoCtl_otRouterUpgradeThreshold( if (InBufferLength >= sizeof(uint8_t)) { - otSetRouterUpgradeThreshold(pFilter->otCtx, *(uint8_t*)InBuffer); + otThreadSetRouterUpgradeThreshold(pFilter->otCtx, *(uint8_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetRouterUpgradeThreshold(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetRouterUpgradeThreshold(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint8_t); } @@ -3189,13 +3181,13 @@ otLwfIoCtl_otRouterDowngradeThreshold( if (InBufferLength >= sizeof(uint8_t)) { - otSetRouterDowngradeThreshold(pFilter->otCtx, *(uint8_t*)InBuffer); + otThreadSetRouterDowngradeThreshold(pFilter->otCtx, *(uint8_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetRouterDowngradeThreshold(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetRouterDowngradeThreshold(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint8_t); } @@ -3291,7 +3283,7 @@ otLwfIoCtl_otReleaseRouterId( if (InBufferLength >= sizeof(uint8_t)) { - status = ThreadErrorToNtstatus(otReleaseRouterId(pFilter->otCtx, *(uint8_t*)InBuffer)); + status = ThreadErrorToNtstatus(otThreadReleaseRouterId(pFilter->otCtx, *(uint8_t*)InBuffer)); } return status; @@ -3669,13 +3661,13 @@ otLwfIoCtl_otDeviceRole( if (role == kDeviceRoleLeader) { status = ThreadErrorToNtstatus( - otBecomeLeader(pFilter->otCtx) + otThreadBecomeLeader(pFilter->otCtx) ); } else if (role == kDeviceRoleRouter) { status = ThreadErrorToNtstatus( - otBecomeRouter(pFilter->otCtx) + otThreadBecomeRouter(pFilter->otCtx) ); } else if (role == kDeviceRoleChild) @@ -3683,21 +3675,21 @@ otLwfIoCtl_otDeviceRole( if (InBufferLength >= sizeof(uint8_t)) { status = ThreadErrorToNtstatus( - otBecomeChild(pFilter->otCtx, *(uint8_t*)InBuffer) + otThreadBecomeChild(pFilter->otCtx, *(uint8_t*)InBuffer) ); } } else if (role == kDeviceRoleDetached) { status = ThreadErrorToNtstatus( - otBecomeDetached(pFilter->otCtx) + otThreadBecomeDetached(pFilter->otCtx) ); } *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = (uint8_t)otGetDeviceRole(pFilter->otCtx); + *(uint8_t*)OutBuffer = (uint8_t)otThreadGetDeviceRole(pFilter->otCtx); *OutBufferLength = sizeof(uint8_t); status = STATUS_SUCCESS; } @@ -3826,7 +3818,7 @@ otLwfIoCtl_otChildInfoById( *OutBufferLength >= sizeof(otChildInfo)) { status = ThreadErrorToNtstatus( - otGetChildInfoById( + otThreadGetChildInfoById( pFilter->otCtx, *(uint16_t*)InBuffer, (otChildInfo*)OutBuffer) @@ -3859,7 +3851,7 @@ otLwfIoCtl_otChildInfoByIndex( *OutBufferLength >= sizeof(otChildInfo)) { status = ThreadErrorToNtstatus( - otGetChildInfoByIndex( + otThreadGetChildInfoByIndex( pFilter->otCtx, *(uint8_t*)InBuffer, (otChildInfo*)OutBuffer) @@ -3892,7 +3884,7 @@ otLwfIoCtl_otEidCacheEntry( *OutBufferLength >= sizeof(otEidCacheEntry)) { status = ThreadErrorToNtstatus( - otGetEidCacheEntry( + otThreadGetEidCacheEntry( pFilter->otCtx, *(uint8_t*)InBuffer, (otEidCacheEntry*)OutBuffer) @@ -3926,7 +3918,7 @@ otLwfIoCtl_otLeaderData( if (*OutBufferLength >= sizeof(otLeaderData)) { - status = ThreadErrorToNtstatus(otGetLeaderData(pFilter->otCtx, (otLeaderData*)OutBuffer)); + status = ThreadErrorToNtstatus(otThreadGetLeaderData(pFilter->otCtx, (otLeaderData*)OutBuffer)); *OutBufferLength = sizeof(otLeaderData); } else @@ -3956,7 +3948,7 @@ otLwfIoCtl_otLeaderRouterId( if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetLeaderRouterId(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetLeaderRouterId(pFilter->otCtx); *OutBufferLength = sizeof(uint8_t); status = STATUS_SUCCESS; } @@ -4042,7 +4034,7 @@ otLwfIoCtl_otLeaderWeight( if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetLeaderWeight(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetLeaderWeight(pFilter->otCtx); *OutBufferLength = sizeof(uint8_t); status = STATUS_SUCCESS; } @@ -4214,7 +4206,7 @@ otLwfIoCtl_otPartitionId( if (*OutBufferLength >= sizeof(uint32_t)) { - *(uint32_t*)OutBuffer = otGetPartitionId(pFilter->otCtx); + *(uint32_t*)OutBuffer = otThreadGetPartitionId(pFilter->otCtx); *OutBufferLength = sizeof(uint32_t); status = STATUS_SUCCESS; } @@ -4300,7 +4292,7 @@ otLwfIoCtl_otRloc16( if (*OutBufferLength >= sizeof(uint16_t)) { - *(uint16_t*)OutBuffer = otGetRloc16(pFilter->otCtx); + *(uint16_t*)OutBuffer = otThreadGetRloc16(pFilter->otCtx); *OutBufferLength = sizeof(uint16_t); status = STATUS_SUCCESS; } @@ -4386,7 +4378,7 @@ otLwfIoCtl_otRouterIdSequence( if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetRouterIdSequence(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetRouterIdSequence(pFilter->otCtx); *OutBufferLength = sizeof(uint8_t); status = STATUS_SUCCESS; } @@ -4416,7 +4408,7 @@ otLwfIoCtl_otRouterInfo( *OutBufferLength >= sizeof(otRouterInfo)) { status = ThreadErrorToNtstatus( - otGetRouterInfo( + otThreadGetRouterInfo( pFilter->otCtx, *(uint16_t*)InBuffer, (otRouterInfo*)OutBuffer) @@ -4785,13 +4777,13 @@ otLwfIoCtl_otLocalLeaderPartitionId( if (InBufferLength >= sizeof(uint32_t)) { - otSetLocalLeaderPartitionId(pFilter->otCtx, *(uint32_t*)InBuffer); + otThreadSetLocalLeaderPartitionId(pFilter->otCtx, *(uint32_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint32_t)) { - *(uint32_t*)OutBuffer = otGetLocalLeaderPartitionId(pFilter->otCtx); + *(uint32_t*)OutBuffer = otThreadGetLocalLeaderPartitionId(pFilter->otCtx); *OutBufferLength = sizeof(uint32_t); status = STATUS_SUCCESS; } @@ -4943,7 +4935,7 @@ otLwfIoCtl_otParentInfo( static_assert(sizeof(otRouterInfo) == 20, "The size of otRouterInfo should be 20 bytes"); if (*OutBufferLength >= sizeof(otRouterInfo)) { - status = ThreadErrorToNtstatus(otGetParentInfo(pFilter->otCtx, (otRouterInfo*)OutBuffer)); + status = ThreadErrorToNtstatus(otThreadGetParentInfo(pFilter->otCtx, (otRouterInfo*)OutBuffer)); *OutBufferLength = sizeof(otRouterInfo); } else @@ -5030,7 +5022,7 @@ otLwfIoCtl_otSingleton( if (*OutBufferLength >= sizeof(BOOLEAN)) { - *(BOOLEAN*)OutBuffer = otIsSingleton(pFilter->otCtx) ? TRUE : FALSE; + *(BOOLEAN*)OutBuffer = otThreadIsSingleton(pFilter->otCtx) ? TRUE : FALSE; *OutBufferLength = sizeof(BOOLEAN); status = STATUS_SUCCESS; } @@ -5089,13 +5081,13 @@ otLwfIoCtl_otMaxChildren( if (InBufferLength >= sizeof(uint8_t)) { - otSetMaxAllowedChildren(pFilter->otCtx, *(uint8_t*)InBuffer); + otThreadSetMaxAllowedChildren(pFilter->otCtx, *(uint8_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetMaxAllowedChildren(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetMaxAllowedChildren(pFilter->otCtx); *OutBufferLength = sizeof(uint8_t); status = STATUS_SUCCESS; } @@ -5391,13 +5383,13 @@ otLwfIoCtl_otRouterSelectionJitter( if (InBufferLength >= sizeof(uint8_t)) { - otSetRouterSelectionJitter(pFilter->otCtx, *(uint8_t*)InBuffer); + otThreadSetRouterSelectionJitter(pFilter->otCtx, *(uint8_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint8_t)) { - *(uint8_t*)OutBuffer = otGetRouterSelectionJitter(pFilter->otCtx); + *(uint8_t*)OutBuffer = otThreadGetRouterSelectionJitter(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint8_t); } @@ -5490,13 +5482,13 @@ otLwfIoCtl_otJoinerUdpPort( if (InBufferLength >= sizeof(uint16_t)) { - otSetJoinerUdpPort(pFilter->otCtx, *(uint16_t*)InBuffer); + otThreadSetJoinerUdpPort(pFilter->otCtx, *(uint16_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint16_t)) { - *(uint16_t*)OutBuffer = otGetJoinerUdpPort(pFilter->otCtx); + *(uint16_t*)OutBuffer = otThreadGetJoinerUdpPort(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint16_t); } @@ -5534,7 +5526,7 @@ otLwfIoCtl_otSendDiagnosticGet( if (InBufferLength >= sizeof(otIp6Address) + sizeof(uint8_t) + aCount) { status = ThreadErrorToNtstatus( - otSendDiagnosticGet( + otThreadSendDiagnosticGet( pFilter->otCtx, aAddress, aTlvTypes, @@ -5572,7 +5564,7 @@ otLwfIoCtl_otSendDiagnosticReset( if (InBufferLength >= sizeof(otIp6Address) + sizeof(uint8_t) + aCount) { status = ThreadErrorToNtstatus( - otSendDiagnosticReset( + otThreadSendDiagnosticReset( pFilter->otCtx, aAddress, aTlvTypes, @@ -5972,13 +5964,13 @@ otLwfIoCtl_otKeySwitchGuardtime( if (InBufferLength >= sizeof(uint32_t)) { - otSetKeySwitchGuardTime(pFilter->otCtx, *(uint32_t*)InBuffer); + otThreadSetKeySwitchGuardTime(pFilter->otCtx, *(uint32_t*)InBuffer); status = STATUS_SUCCESS; *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(uint32_t)) { - *(uint32_t*)OutBuffer = otGetKeySwitchGuardTime(pFilter->otCtx); + *(uint32_t*)OutBuffer = otThreadGetKeySwitchGuardTime(pFilter->otCtx); status = STATUS_SUCCESS; *OutBufferLength = sizeof(uint32_t); } diff --git a/examples/drivers/windows/otLwf/thread.c b/examples/drivers/windows/otLwf/thread.c index 03e3dc5bf..d96f3466f 100644 --- a/examples/drivers/windows/otLwf/thread.c +++ b/examples/drivers/windows/otLwf/thread.c @@ -299,7 +299,7 @@ otLwfProcessRoleStateChange( ) { otDeviceRole prevRole = pFilter->otCachedRole; - pFilter->otCachedRole = otGetDeviceRole(pFilter->otCtx); + pFilter->otCachedRole = otThreadGetDeviceRole(pFilter->otCtx); if (prevRole == pFilter->otCachedRole) return; LogInfo(DRIVER_DEFAULT, "Interface %!GUID! new role: %!otDeviceRole!", &pFilter->InterfaceGuid, pFilter->otCachedRole); diff --git a/examples/drivers/windows/otNodeApi/otNodeApi.cpp b/examples/drivers/windows/otNodeApi/otNodeApi.cpp index 25287448c..86cb96fe8 100644 --- a/examples/drivers/windows/otNodeApi/otNodeApi.cpp +++ b/examples/drivers/windows/otNodeApi/otNodeApi.cpp @@ -391,7 +391,7 @@ PingHandlerRecvCallback( if (memcmp(RecvDest, &LinkLocalAllRoutersAddress, sizeof(IN6_ADDR)) == 0 || memcmp(RecvDest, &RealmLocalAllRoutersAddress, sizeof(IN6_ADDR)) == 0) { - auto Role = otGetDeviceRole(aPingHandler->mParentNode->mInstance); + auto Role = otThreadGetDeviceRole(aPingHandler->mParentNode->mInstance); if (Role != kDeviceRoleLeader && Role != kDeviceRoleRouter) shouldReply = false; } @@ -448,7 +448,7 @@ PingHandlerRecvCallback( bool IsMeshLocalEID(otNode *aNode, const otIp6Address *aAddress) { - auto ML_EID = otGetMeshLocalEid(aNode->mInstance); + auto ML_EID = otThreadGetMeshLocalEid(aNode->mInstance); if (ML_EID == nullptr) return false; bool result = memcmp(ML_EID->mFields.m8, aAddress->mFields.m8, sizeof(otIp6Address)) == 0; otFreeMemory(ML_EID); @@ -710,7 +710,7 @@ void OTCALL otNodeStateChangedCallback(uint32_t aFlags, void *aContext) if ((aFlags & OT_NET_ROLE) != 0) { - auto Role = otGetDeviceRole(aNode->mInstance); + auto Role = otThreadGetDeviceRole(aNode->mInstance); printf("%d: new role: %s\r\n", aNode->mId, otDeviceRoleToString(Role)); } @@ -944,7 +944,7 @@ OTNODEAPI int32_t OTCALL otNodeSetMode(otNode* aNode, const char *aMode) index++; } - auto result = otSetLinkMode(aNode->mInstance, linkMode); + auto result = otThreadSetLinkMode(aNode->mInstance, linkMode); otLogFuncExit(); return result; @@ -977,7 +977,7 @@ OTNODEAPI int32_t OTCALL otNodeThreadStart(otNode* aNode) otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: thread start\r\n", aNode->mId); - auto error = otThreadStart(aNode->mInstance); + auto error = otThreadSetEnabled(aNode->mInstance, true); otLogFuncExit(); return error; @@ -988,7 +988,7 @@ OTNODEAPI int32_t OTCALL otNodeThreadStop(otNode* aNode) otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: thread stop\r\n", aNode->mId); - (void)otThreadStop(aNode->mInstance); + (void)otThreadSetEnabled(aNode->mInstance, false); otLogFuncExit(); return 0; @@ -1134,7 +1134,7 @@ OTNODEAPI int32_t OTCALL otNodeRemoveWhitelist(otNode* aNode, const char *aExtAd OTNODEAPI uint16_t OTCALL otNodeGetAddr16(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto result = otGetRloc16(aNode->mInstance); + auto result = otThreadGetRloc16(aNode->mInstance); printf("%d: rloc16\r\n%04x\r\n", aNode->mId, result); otLogFuncExit(); return result; @@ -1205,7 +1205,7 @@ OTNODEAPI int32_t OTCALL otNodeSetMasterkey(otNode* aNode, const char *aMasterke return kThreadError_Parse; } - auto error = otSetMasterKey(aNode->mInstance, key, (uint8_t)keyLength); + auto error = otThreadSetMasterKey(aNode->mInstance, key, (uint8_t)keyLength); otLogFuncExit(); return error; } @@ -1214,7 +1214,7 @@ OTNODEAPI const char* OTCALL otNodeGetMasterkey(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); uint8_t aKeyLength = 0; - auto aMasterKey = otGetMasterKey(aNode->mInstance, &aKeyLength); + auto aMasterKey = otThreadGetMasterKey(aNode->mInstance, &aKeyLength); uint8_t strLength = 2*aKeyLength + 1; char* str = (char*)malloc(strLength); if (str != nullptr) @@ -1232,7 +1232,7 @@ OTNODEAPI const char* OTCALL otNodeGetMasterkey(otNode* aNode) OTNODEAPI uint32_t OTCALL otNodeGetKeySequenceCounter(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto result = otGetKeySequenceCounter(aNode->mInstance); + auto result = otThreadGetKeySequenceCounter(aNode->mInstance); printf("%d: keysequence\r\n%d\r\n", aNode->mId, result); otLogFuncExit(); return result; @@ -1242,7 +1242,7 @@ OTNODEAPI int32_t OTCALL otNodeSetKeySequenceCounter(otNode* aNode, uint32_t aSe { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: keysequence counter %d\r\n", aNode->mId, aSequence); - otSetKeySequenceCounter(aNode->mInstance, aSequence); + otThreadSetKeySequenceCounter(aNode->mInstance, aSequence); otLogFuncExit(); return 0; } @@ -1251,7 +1251,7 @@ OTNODEAPI int32_t OTCALL otNodeSetKeySwitchGuardTime(otNode* aNode, uint32_t aKe { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: keysequence guardtime %d\r\n", aNode->mId, aKeySwitchGuardTime); - otSetKeySwitchGuardTime(aNode->mInstance, aKeySwitchGuardTime); + otThreadSetKeySwitchGuardTime(aNode->mInstance, aKeySwitchGuardTime); otLogFuncExit(); return 0; } @@ -1260,7 +1260,7 @@ OTNODEAPI int32_t OTCALL otNodeSetNetworkIdTimeout(otNode* aNode, uint8_t aTimeo { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: networkidtimeout %d\r\n", aNode->mId, aTimeout); - otSetNetworkIdTimeout(aNode->mInstance, aTimeout); + otThreadSetNetworkIdTimeout(aNode->mInstance, aTimeout); otLogFuncExit(); return 0; } @@ -1269,7 +1269,7 @@ OTNODEAPI int32_t OTCALL otNodeSetNetworkName(otNode* aNode, const char *aName) { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: networkname %s\r\n", aNode->mId, aName); - auto result = otSetNetworkName(aNode->mInstance, aName); + auto result = otThreadSetNetworkName(aNode->mInstance, aName); otLogFuncExit(); return result; } @@ -1277,7 +1277,7 @@ OTNODEAPI int32_t OTCALL otNodeSetNetworkName(otNode* aNode, const char *aName) OTNODEAPI const char* OTCALL otNodeGetNetworkName(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto result = otGetNetworkName(aNode->mInstance); + auto result = otThreadGetNetworkName(aNode->mInstance); aNode->mMemoryToFree.push_back((char*)result); printf("%d: networkname\r\n%s\r\n", aNode->mId, result); otLogFuncExit(); @@ -1305,7 +1305,7 @@ OTNODEAPI int32_t OTCALL otNodeSetPanId(otNode* aNode, uint16_t aPanId) OTNODEAPI uint32_t OTCALL otNodeGetPartitionId(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto result = otGetLocalLeaderPartitionId(aNode->mInstance); + auto result = otThreadGetLocalLeaderPartitionId(aNode->mInstance); printf("%d: leaderpartitionid\r\n0x%04x\r\n", aNode->mId, result); otLogFuncExit(); return result; @@ -1315,7 +1315,7 @@ OTNODEAPI int32_t OTCALL otNodeSetPartitionId(otNode* aNode, uint32_t aPartition { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: leaderpartitionid 0x%04x\r\n", aNode->mId, aPartitionId); - otSetLocalLeaderPartitionId(aNode->mInstance, aPartitionId); + otThreadSetLocalLeaderPartitionId(aNode->mInstance, aPartitionId); otLogFuncExit(); return 0; } @@ -1324,7 +1324,7 @@ OTNODEAPI int32_t OTCALL otNodeSetRouterUpgradeThreshold(otNode* aNode, uint8_t { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: routerupgradethreshold %d\r\n", aNode->mId, aThreshold); - otSetRouterUpgradeThreshold(aNode->mInstance, aThreshold); + otThreadSetRouterUpgradeThreshold(aNode->mInstance, aThreshold); otLogFuncExit(); return 0; } @@ -1333,7 +1333,7 @@ OTNODEAPI int32_t OTCALL otNodeSetRouterDowngradeThreshold(otNode* aNode, uint8_ { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: routerdowngradethreshold %d\r\n", aNode->mId, aThreshold); - otSetRouterDowngradeThreshold(aNode->mInstance, aThreshold); + otThreadSetRouterDowngradeThreshold(aNode->mInstance, aThreshold); otLogFuncExit(); return 0; } @@ -1342,7 +1342,7 @@ OTNODEAPI int32_t OTCALL otNodeReleaseRouterId(otNode* aNode, uint8_t aRouterId) { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: releaserouterid %d\r\n", aNode->mId, aRouterId); - auto result = otReleaseRouterId(aNode->mInstance, aRouterId); + auto result = otThreadReleaseRouterId(aNode->mInstance, aRouterId); otLogFuncExit(); return result; } @@ -1350,7 +1350,7 @@ OTNODEAPI int32_t OTCALL otNodeReleaseRouterId(otNode* aNode, uint8_t aRouterId) OTNODEAPI const char* OTCALL otNodeGetState(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto role = otGetDeviceRole(aNode->mInstance); + auto role = otThreadGetDeviceRole(aNode->mInstance); auto result = _strdup(otDeviceRoleToString(role)); aNode->mMemoryToFree.push_back(result); printf("%d: state\r\n%s\r\n", aNode->mId, result); @@ -1366,19 +1366,19 @@ OTNODEAPI int32_t OTCALL otNodeSetState(otNode* aNode, const char *aState) ThreadError error; if (strcmp(aState, "detached") == 0) { - error = otBecomeDetached(aNode->mInstance); + error = otThreadBecomeDetached(aNode->mInstance); } else if (strcmp(aState, "child") == 0) { - error = otBecomeChild(aNode->mInstance, kMleAttachAnyPartition); + error = otThreadBecomeChild(aNode->mInstance, kMleAttachAnyPartition); } else if (strcmp(aState, "router") == 0) { - error = otBecomeRouter(aNode->mInstance); + error = otThreadBecomeRouter(aNode->mInstance); } else if (strcmp(aState, "leader") == 0) { - error = otBecomeLeader(aNode->mInstance); + error = otThreadBecomeLeader(aNode->mInstance); } else { @@ -1391,7 +1391,7 @@ OTNODEAPI int32_t OTCALL otNodeSetState(otNode* aNode, const char *aState) OTNODEAPI uint32_t OTCALL otNodeGetTimeout(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto result = otGetChildTimeout(aNode->mInstance); + auto result = otThreadGetChildTimeout(aNode->mInstance); printf("%d: childtimeout\r\n%d\r\n", aNode->mId, result); otLogFuncExit(); return result; @@ -1401,7 +1401,7 @@ OTNODEAPI int32_t OTCALL otNodeSetTimeout(otNode* aNode, uint32_t aTimeout) { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: childtimeout %d\r\n", aNode->mId, aTimeout); - otSetChildTimeout(aNode->mInstance, aTimeout); + otThreadSetChildTimeout(aNode->mInstance, aTimeout); otLogFuncExit(); return 0; } @@ -1409,7 +1409,7 @@ OTNODEAPI int32_t OTCALL otNodeSetTimeout(otNode* aNode, uint32_t aTimeout) OTNODEAPI uint8_t OTCALL otNodeGetWeight(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto result = otGetLeaderWeight(aNode->mInstance); + auto result = otThreadGetLeaderWeight(aNode->mInstance); printf("%d: leaderweight\r\n%d\r\n", aNode->mId, result); otLogFuncExit(); return result; @@ -1419,7 +1419,7 @@ OTNODEAPI int32_t OTCALL otNodeSetWeight(otNode* aNode, uint8_t aWeight) { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: leaderweight %d\r\n", aNode->mId, aWeight); - otSetLocalLeaderWeight(aNode->mInstance, aWeight); + otThreadSetLocalLeaderWeight(aNode->mInstance, aWeight); otLogFuncExit(); return 0; } @@ -1500,7 +1500,7 @@ OTNODEAPI const char* OTCALL otNodeGetAddrs(otNode* aNode) OTNODEAPI uint32_t OTCALL otNodeGetContextReuseDelay(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); - auto result = otGetContextIdReuseDelay(aNode->mInstance); + auto result = otThreadGetContextIdReuseDelay(aNode->mInstance); printf("%d: contextreusedelay\r\n%d\r\n", aNode->mId, result); otLogFuncExit(); return result; @@ -1510,7 +1510,7 @@ OTNODEAPI int32_t OTCALL otNodeSetContextReuseDelay(otNode* aNode, uint32_t aDel { otLogFuncEntryMsg("[%d] %d", aNode->mId, aDelay); printf("%d: contextreusedelay %d\r\n", aNode->mId, aDelay); - otSetContextIdReuseDelay(aNode->mInstance, aDelay); + otThreadSetContextIdReuseDelay(aNode->mInstance, aDelay); otLogFuncExit(); return 0; } @@ -1741,7 +1741,7 @@ OTNODEAPI uint32_t OTCALL otNodePing(otNode* aNode, const char *aAddr, uint16_t } // Get ML-EID as source address for ping - auto otSourceAddress = otGetMeshLocalEid(aNode->mInstance); + auto otSourceAddress = otThreadGetMeshLocalEid(aNode->mInstance); sockaddr_in6 SourceAddress = { AF_INET6, (USHORT)(CertificationPingPort + 1) }; sockaddr_in6 DestinationAddress = { AF_INET6, CertificationPingPort }; @@ -1891,7 +1891,7 @@ OTNODEAPI int32_t OTCALL otNodeSetRouterSelectionJitter(otNode* aNode, uint8_t a { otLogFuncEntryMsg("[%d] %d", aNode->mId, aRouterJitter); printf("%d: routerselectionjitter %d\r\n", aNode->mId, aRouterJitter); - otSetRouterSelectionJitter(aNode->mInstance, aRouterJitter); + otThreadSetRouterSelectionJitter(aNode->mInstance, aRouterJitter); otLogFuncExit(); return 0; } @@ -2147,7 +2147,7 @@ OTNODEAPI int32_t OTCALL otNodeSetMaxChildren(otNode* aNode, uint8_t aMaxChildre { otLogFuncEntryMsg("[%d] %d", aNode->mId, aMaxChildren); printf("%d: childmax %d\r\n", aNode->mId, aMaxChildren); - auto result = otSetMaxAllowedChildren(aNode->mInstance, aMaxChildren); + auto result = otThreadSetMaxAllowedChildren(aNode->mInstance, aMaxChildren); otLogFuncExit(); return result; } diff --git a/examples/platforms/da15000/platform.c b/examples/platforms/da15000/platform.c index 99273cbdd..404db27e7 100644 --- a/examples/platforms/da15000/platform.c +++ b/examples/platforms/da15000/platform.c @@ -92,7 +92,7 @@ void ExampleProcess(otInstance *aInstance) otDeviceRole devRole; static int thrValue; - devRole = otGetDeviceRole(aInstance); + devRole = otThreadGetDeviceRole(aInstance); if (sBlink == false && otPlatAlarmGetNow() != 0) { diff --git a/include/openthread-types.h b/include/openthread-types.h index c389a4e7c..182d2a4c2 100644 --- a/include/openthread-types.h +++ b/include/openthread-types.h @@ -1093,18 +1093,6 @@ typedef void (OTCALL *otDeviceAvailabilityChangedCallback)(bool aAdded, const GU #endif // OTDLL -/** - * This function pointer is called when Network Diagnostic Get response is received. - * - * @param[in] aMessage A pointer to the message buffer containing the received Network Diagnostic - * Get response payload. - * @param[in] aMessageInfo A pointer to the message info for @p aMessage. - * @param[in] aContext A pointer to application-specific context. - * - */ -typedef void (*otReceiveDiagnosticGetCallback)(otMessage aMessage, const otMessageInfo *aMessageInfo, - void *aContext); - /** * @} * diff --git a/include/openthread.h b/include/openthread.h index 366f6c29e..9d54a3e44 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -45,6 +45,7 @@ #include "openthread/message.h" #include "openthread/netdata.h" #include "openthread/tasklet.h" +#include "openthread/thread.h" #ifdef __cplusplus extern "C" { @@ -109,15 +110,6 @@ extern "C" { * */ -/** - * @addtogroup commands Commands - * - * @brief - * This module includes functions for OpenThread commands. - * - * @{ - * - */ /** * Get the OpenThread version string. @@ -127,843 +119,6 @@ extern "C" { */ OTAPI const char *OTCALL otGetVersionString(void); -/** - * This function starts Thread protocol operation. - * - * The interface must be up when calling this function. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval kThreadError_None Successfully started Thread protocol operation. - * @retval kThreadError_InvalidState The network interface was not not up. - * - */ -OTAPI ThreadError OTCALL otThreadStart(otInstance *aInstance); - -/** - * This function stops Thread protocol operation. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval kThreadError_None Successfully stopped Thread protocol operation. - * - */ -OTAPI ThreadError OTCALL otThreadStop(otInstance *aInstance); - -/** - * This function configures the Thread stack to automatically start on reinitialization. - * It has no effect on the current Thread state. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aStartAutomatically TRUE to automatically start; FALSE to not automatically start. - * - */ -OTAPI ThreadError OTCALL otThreadSetAutoStart(otInstance *aInstance, bool aStartAutomatically); - -/** - * This function queries if the Thread stack is configured to automatically start on reinitialization. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval TRUE It is configured to automatically start. - * @retval FALSE It is not configured to automatically start. - * - */ -OTAPI bool OTCALL otThreadGetAutoStart(otInstance *aInstance); - -/** - * This function indicates whether a node is the only router on the network. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval TRUE It is the only router in the network. - * @retval FALSE It is a child or is not a single router in the network. - * - */ -OTAPI bool OTCALL otIsSingleton(otInstance *aInstance); - -/** - * This function starts a Thread Discovery scan. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aScanChannels A bit vector indicating which channels to scan (e.g. OT_CHANNEL_11_MASK). - * @param[in] aScanDuration The time in milliseconds to spend scanning each channel. - * @param[in] aPanId The PAN ID filter (set to Broadcast PAN to disable filter). - * @param[in] aCallback A pointer to a function called on receiving an MLE Discovery Response or scan completes. - * @param[in] aCallbackContext A pointer to application-specific context. - * - * @retval kThreadError_None Accepted the Thread Discovery request. - * @retval kThreadError_Busy Already performing an Thread Discovery. - * - */ -OTAPI ThreadError OTCALL otDiscover(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration, - uint16_t aPanid, - otHandleActiveScanResult aCallback, void *aCallbackContext); - -/** - * This function determines if an MLE Thread Discovery is currently in progress. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - */ -OTAPI bool OTCALL otIsDiscoverInProgress(otInstance *aInstance); - -/** - * @} - * - */ - -/** - * @addtogroup config Configuration - * - * @brief - * This module includes functions for configuration. - * - * @{ - * - */ - -/** - * @defgroup config-general General - * - * @brief - * This module includes functions that manage configuration parameters for the Thread Child, Router, and Leader roles. - * - * @{ - * - */ - -/** - * Get the maximum number of children currently allowed. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The maximum number of children currently allowed. - * - * @sa otSetMaxAllowedChildren - */ -OTAPI uint8_t OTCALL otGetMaxAllowedChildren(otInstance *aInstance); - -/** - * Set the maximum number of children currently allowed. - * - * This parameter can only be set when Thread protocol operation - * has been stopped. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aMaxChildren The maximum allowed children. - * - * @retval kThreadErrorNone Successfully set the max. - * @retval kThreadError_InvalidArgs If @p aMaxChildren is not in the range [1, OPENTHREAD_CONFIG_MAX_CHILDREN]. - * @retval kThreadError_InvalidState If Thread isn't stopped. - * - * @sa otGetMaxAllowedChildren, otThreadStop - */ -OTAPI ThreadError OTCALL otSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren); - -/** - * Get the Thread Child Timeout used when operating in the Child role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Thread Child Timeout value. - * - * @sa otSetChildTimeout - */ -OTAPI uint32_t OTCALL otGetChildTimeout(otInstance *aInstance); - -/** - * Set the Thread Child Timeout used when operating in the Child role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @sa otSetChildTimeout - */ -OTAPI void OTCALL otSetChildTimeout(otInstance *aInstance, uint32_t aTimeout); - -/** - * Get the IEEE 802.15.4 Extended PAN ID. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns A pointer to the IEEE 802.15.4 Extended PAN ID. - * - * @sa otSetExtendedPanId - */ -OTAPI const uint8_t *OTCALL otGetExtendedPanId(otInstance *aInstance); - -/** - * Set the IEEE 802.15.4 Extended PAN ID. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aExtendedPanId A pointer to the IEEE 802.15.4 Extended PAN ID. - * - * @sa otGetExtendedPanId - */ -OTAPI void OTCALL otSetExtendedPanId(otInstance *aInstance, const uint8_t *aExtendedPanId); - -/** - * This function returns a pointer to the Leader's RLOC. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[out] aLeaderRloc A pointer to where the Leader's RLOC will be written. - * - * @retval kThreadError_None The Leader's RLOC was successfully written to @p aLeaderRloc. - * @retval kThreadError_InvalidArgs @p aLeaderRloc was NULL. - * @retval kThreadError_Detached Not currently attached to a Thread Partition. - * - */ -OTAPI ThreadError OTCALL otGetLeaderRloc(otInstance *aInstance, otIp6Address *aLeaderRloc); - -/** - * Get the MLE Link Mode configuration. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The MLE Link Mode configuration. - * - * @sa otSetLinkMode - */ -OTAPI otLinkModeConfig OTCALL otGetLinkMode(otInstance *aInstance); - -/** - * Set the MLE Link Mode configuration. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aConfig A pointer to the Link Mode configuration. - * - * @retval kThreadErrorNone Successfully set the MLE Link Mode configuration. - * - * @sa otGetLinkMode - */ -OTAPI ThreadError OTCALL otSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig); - -/** - * Get the thrMasterKey. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[out] aKeyLength A pointer to an unsigned 8-bit value that the function will set to the number of bytes that - * represent the thrMasterKey. Caller may set to NULL. - * - * @returns A pointer to a buffer containing the thrMasterKey. - * - * @sa otSetMasterKey - */ -OTAPI const uint8_t *OTCALL otGetMasterKey(otInstance *aInstance, uint8_t *aKeyLength); - -/** - * Set the thrMasterKey. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aKey A pointer to a buffer containing the thrMasterKey. - * @param[in] aKeyLength Number of bytes representing the thrMasterKey stored at aKey. Valid range is [0, 16]. - * - * @retval kThreadErrorNone Successfully set the thrMasterKey. - * @retval kThreadErrorInvalidArgs If aKeyLength is larger than 16. - * - * @sa otGetMasterKey - */ -OTAPI ThreadError OTCALL otSetMasterKey(otInstance *aInstance, const uint8_t *aKey, uint8_t aKeyLength); - -/** - * This function returns a pointer to the Mesh Local EID. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns A pointer to the Mesh Local EID. - * - */ -OTAPI const otIp6Address *OTCALL otGetMeshLocalEid(otInstance *aInstance); - -/** - * This function returns a pointer to the Mesh Local Prefix. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns A pointer to the Mesh Local Prefix. - * - */ -OTAPI const uint8_t *OTCALL otGetMeshLocalPrefix(otInstance *aInstance); - -/** - * This function sets the Mesh Local Prefix. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aMeshLocalPrefix A pointer to the Mesh Local Prefix. - * - * @retval kThreadError_None Successfully set the Mesh Local Prefix. - * - */ -OTAPI ThreadError OTCALL otSetMeshLocalPrefix(otInstance *aInstance, const uint8_t *aMeshLocalPrefix); - -/** - * Get the Thread Network Name. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns A pointer to the Thread Network Name. - * - * @sa otSetNetworkName - */ -OTAPI const char *OTCALL otGetNetworkName(otInstance *aInstance); - -/** - * Set the Thread Network Name. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aNetworkName A pointer to the Thread Network Name. - * - * @retval kThreadErrorNone Successfully set the Thread Network Name. - * - * @sa otGetNetworkName - */ -OTAPI ThreadError OTCALL otSetNetworkName(otInstance *aInstance, const char *aNetworkName); - -/** - * This function indicates whether or not the Router Role is enabled. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval TRUE If the Router Role is enabled. - * @retval FALSE If the Router Role is not enabled. - * - */ -OTAPI bool OTCALL otIsRouterRoleEnabled(otInstance *aInstance); - -/** - * This function sets whether or not the Router Role is enabled. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aEnabled TRUE if the Router Role is enabled, FALSE otherwise. - * - */ -OTAPI void OTCALL otSetRouterRoleEnabled(otInstance *aInstance, bool aEnabled); - -/** - * Set the preferred Router Id. - * - * Upon becoming a router/leader the node attempts to use this Router Id. If the - * preferred Router Id is not set or if it can not be used, a randomly generated - * router id is picked. This property can be set only when the device role is - * either detached or disabled. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aRouterId The preferred Router Id. - * - * @retval kThreadError_None Successfully set the preferred Router Id. - * @retval kThreadError_InvalidState Could not set (role is not detached or disabled) - * - */ -ThreadError otSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId); - -/** - * @} - */ - -/** - * @defgroup config-router Router/Leader - * - * @brief - * This module includes functions that manage configuration parameters for the Thread Router and Leader roles. - * - * @{ - * - */ - -/** - * Get the Thread Leader Weight used when operating in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Thread Leader Weight value. - * - * @sa otSetLeaderWeight - */ -OTAPI uint8_t OTCALL otGetLocalLeaderWeight(otInstance *aInstance); - -/** - * Set the Thread Leader Weight used when operating in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aWeight The Thread Leader Weight value.. - * - * @sa otGetLeaderWeight - */ -OTAPI void OTCALL otSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight); - -/** - * Get the Thread Leader Partition Id used when operating in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Thread Leader Partition Id value. - * - */ -OTAPI uint32_t OTCALL otGetLocalLeaderPartitionId(otInstance *aInstance); - -/** - * Set the Thread Leader Partition Id used when operating in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aPartitionId The Thread Leader Partition Id value. - * - */ -OTAPI void OTCALL otSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId); - -/** - * Get the Joiner UDP Port. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Joiner UDP Port number. - * - * @sa otSetJoinerUdpPort - */ -OTAPI uint16_t OTCALL otGetJoinerUdpPort(otInstance *aInstance); - -/** - * Set the Joiner UDP Port - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aJoinerUdpPort The Joiner UDP Port number. - * - * @retval kThreadErrorNone Successfully set the Joiner UDP Port. - * - * @sa otGetJoinerUdpPort - */ -OTAPI ThreadError OTCALL otSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort); - -/** - * @} - */ - -/** - * @defgroup config-test Test - * - * @brief - * This module includes functions that manage configuration parameters required for Thread Certification testing. - * - * @{ - * - */ - -/** - * Get the CONTEXT_ID_REUSE_DELAY parameter used in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The CONTEXT_ID_REUSE_DELAY value. - * - * @sa otSetContextIdReuseDelay - */ -OTAPI uint32_t OTCALL otGetContextIdReuseDelay(otInstance *aInstance); - -/** - * Set the CONTEXT_ID_REUSE_DELAY parameter used in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aDelay The CONTEXT_ID_REUSE_DELAY value. - * - * @sa otGetContextIdReuseDelay - */ -OTAPI void OTCALL otSetContextIdReuseDelay(otInstance *aInstance, uint32_t aDelay); - -/** - * Get the thrKeySequenceCounter. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The thrKeySequenceCounter value. - * - * @sa otSetKeySequenceCounter - */ -OTAPI uint32_t OTCALL otGetKeySequenceCounter(otInstance *aInstance); - -/** - * Set the thrKeySequenceCounter. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aKeySequenceCounter The thrKeySequenceCounter value. - * - * @sa otGetKeySequenceCounter - */ -OTAPI void OTCALL otSetKeySequenceCounter(otInstance *aInstance, uint32_t aKeySequenceCounter); - -/** - * Get the thrKeySwitchGuardTime - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The thrKeySwitchGuardTime value (in hours). - * - * @sa otSetKeySwitchGuardTime - */ -OTAPI uint32_t OTCALL otGetKeySwitchGuardTime(otInstance *aInstance); - -/** - * Set the thrKeySwitchGuardTime - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aKeySwitchGuardTime The thrKeySwitchGuardTime value (in hours). - * - * @sa otGetKeySwitchGuardTime - */ -OTAPI void OTCALL otSetKeySwitchGuardTime(otInstance *aInstance, uint32_t aKeySwitchGuardTime); - - -/** - * Get the NETWORK_ID_TIMEOUT parameter used in the Router role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The NETWORK_ID_TIMEOUT value. - * - * @sa otSetNetworkIdTimeout - */ -OTAPI uint8_t OTCALL otGetNetworkIdTimeout(otInstance *aInstance); - -/** - * Set the NETWORK_ID_TIMEOUT parameter used in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aTimeout The NETWORK_ID_TIMEOUT value. - * - * @sa otGetNetworkIdTimeout - */ -OTAPI void OTCALL otSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout); - -/** - * Get the ROUTER_UPGRADE_THRESHOLD parameter used in the REED role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The ROUTER_UPGRADE_THRESHOLD value. - * - * @sa otSetRouterUpgradeThreshold - */ -OTAPI uint8_t OTCALL otGetRouterUpgradeThreshold(otInstance *aInstance); - -/** - * Set the ROUTER_UPGRADE_THRESHOLD parameter used in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aThreshold The ROUTER_UPGRADE_THRESHOLD value. - * - * @sa otGetRouterUpgradeThreshold - */ -OTAPI void OTCALL otSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold); - -/** - * Release a Router ID that has been allocated by the device in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aRouterId The Router ID to release. Valid range is [0, 62]. - * - * @retval kThreadErrorNone Successfully released the Router ID specified by aRouterId. - */ -OTAPI ThreadError OTCALL otReleaseRouterId(otInstance *aInstance, uint8_t aRouterId); - -/** - * Detach from the Thread network. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval kThreadErrorNone Successfully detached from the Thread network. - * @retval kThreadErrorInvalidState Thread is disabled. - */ -OTAPI ThreadError OTCALL otBecomeDetached(otInstance *aInstance); - -/** - * Attempt to reattach as a child. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aFilter Identifies whether to join any, same, or better partition. - * - * @retval kThreadErrorNone Successfully begin attempt to become a child. - * @retval kThreadErrorInvalidState Thread is disabled. - */ -OTAPI ThreadError OTCALL otBecomeChild(otInstance *aInstance, otMleAttachFilter aFilter); - -/** - * Attempt to become a router. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval kThreadErrorNone Successfully begin attempt to become a router. - * @retval kThreadErrorInvalidState Thread is disabled. - */ -OTAPI ThreadError OTCALL otBecomeRouter(otInstance *aInstance); - -/** - * Become a leader and start a new partition. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval kThreadErrorNone Successfully became a leader and started a new partition. - * @retval kThreadErrorInvalidState Thread is disabled. - */ -OTAPI ThreadError OTCALL otBecomeLeader(otInstance *aInstance); - -/** - * Get the ROUTER_DOWNGRADE_THRESHOLD parameter used in the Router role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The ROUTER_DOWNGRADE_THRESHOLD value. - * - * @sa otSetRouterDowngradeThreshold - */ -OTAPI uint8_t OTCALL otGetRouterDowngradeThreshold(otInstance *aInstance); - -/** - * Set the ROUTER_DOWNGRADE_THRESHOLD parameter used in the Leader role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aThreshold The ROUTER_DOWNGRADE_THRESHOLD value. - * - * @sa otGetRouterDowngradeThreshold - */ -OTAPI void OTCALL otSetRouterDowngradeThreshold(otInstance *aInstance, uint8_t aThreshold); - -/** - * Get the ROUTER_SELECTION_JITTER parameter used in the REED/Router role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The ROUTER_SELECTION_JITTER value. - * - * @sa otSetRouterSelectionJitter - */ -OTAPI uint8_t OTCALL otGetRouterSelectionJitter(otInstance *aInstance); - -/** - * Set the ROUTER_SELECTION_JITTER parameter used in the REED/Router role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aRouterJitter The ROUTER_SELECTION_JITTER value. - * - * @sa otGetRouterSelectionJitter - */ -OTAPI void OTCALL otSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitter); - -/** - * @} - * - */ - -/** - * @} - * - */ - -/** - * @addtogroup diags Diagnostics - * - * @brief - * This module includes functions that expose internal state. - * - * @{ - * - */ - -/** - * The function retains diagnostic information for an attached Child by its Child ID or RLOC16. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aChildId The Child ID or RLOC16 for the attached child. - * @param[out] aChildInfo A pointer to where the child information is placed. - * - * @retavl kThreadError_None @p aChildInfo was successfully updated with the info for the given ID. - * @retval kThreadError_NotFound No valid child with this Child ID. - * @retavl kThreadError_InvalidArgs If @p aChildInfo is NULL. - * - */ -OTAPI ThreadError OTCALL otGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo); - -/** - * The function retains diagnostic information for an attached Child by the internal table index. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aChildIndex The table index. - * @param[out] aChildInfo A pointer to where the child information is placed. - * - * @retavl kThreadError_None @p aChildInfo was successfully updated with the info for the given index. - * @retval kThreadError_NotFound No valid child at this index. - * @retavl kThreadError_InvalidArgs Either @p aChildInfo is NULL, or @p aChildIndex is out of range (higher - * than max table index). - * - * @sa otGetMaxAllowedChildren - * - */ -OTAPI ThreadError OTCALL otGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, otChildInfo *aChildInfo); - -/** - * This function gets the next neighbor information. It is used to go through the entries of - * the neighbor table. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[inout] aIterator A pointer to the iterator context. To get the first neighbor entry - it should be set to OT_NEIGHBOR_INFO_ITERATOR_INIT. - * @param[out] aInfo A pointer to where the neighbor information will be placed. - * - * @retval kThreadError_None Successfully found the next neighbor entry in table. - * @retval kThreadError_NotFound No subsequent neighbor entry exists in the table. - * @retval kThreadError_InvalidArgs @p aIterator or @p aInfo was NULL. - * - */ -OTAPI ThreadError OTCALL otGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, - otNeighborInfo *aInfo); - -/** - * Get the device role. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval ::kDeviceRoleDisabled The Thread stack is disabled. - * @retval ::kDeviceRoleDetached The device is not currently participating in a Thread network/partition. - * @retval ::kDeviceRoleChild The device is currently operating as a Thread Child. - * @retval ::kDeviceRoleRouter The device is currently operating as a Thread Router. - * @retval ::kDeviceRoleLeader The device is currently operating as a Thread Leader. - */ -OTAPI otDeviceRole OTCALL otGetDeviceRole(otInstance *aInstance); - -/** - * This function gets an EID cache entry. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aIndex An index into the EID cache table. - * @param[out] aEntry A pointer to where the EID information is placed. - * - * @retval kThreadError_None Successfully retrieved the EID cache entry. - * @retval kThreadError_InvalidArgs @p aIndex was out of bounds or @p aEntry was NULL. - * - */ -OTAPI ThreadError OTCALL otGetEidCacheEntry(otInstance *aInstance, uint8_t aIndex, otEidCacheEntry *aEntry); - -/** - * This function get the Thread Leader Data. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[out] aLeaderData A pointer to where the leader data is placed. - * - * @retval kThreadError_None Successfully retrieved the leader data. - * @retval kThreadError_Detached Not currently attached. - * @retval kThreadError_InvalidArgs @p aLeaderData is NULL. - * - */ -OTAPI ThreadError OTCALL otGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData); - -/** - * Get the Leader's Router ID. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Leader's Router ID. - */ -OTAPI uint8_t OTCALL otGetLeaderRouterId(otInstance *aInstance); - -/** - * Get the Leader's Weight. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Leader's Weight. - */ -OTAPI uint8_t OTCALL otGetLeaderWeight(otInstance *aInstance); - -/** - * Get the Partition ID. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Partition ID. - */ -OTAPI uint32_t OTCALL otGetPartitionId(otInstance *aInstance); - -/** - * Get the RLOC16. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The RLOC16. - */ -OTAPI uint16_t OTCALL otGetRloc16(otInstance *aInstance); - -/** - * Get the current Router ID Sequence. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The Router ID Sequence. - */ -OTAPI uint8_t OTCALL otGetRouterIdSequence(otInstance *aInstance); - -/** - * The function retains diagnostic information for a given Thread Router. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aRouterId The router ID or RLOC16 for a given router. - * @param[out] aRouterInfo A pointer to where the router information is placed. - * - */ -OTAPI ThreadError OTCALL otGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo); - -/** - * The function retrieves diagnostic information for a Thread Router as parent. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[out] aParentInfo A pointer to where the parent router information is placed. - * - */ -OTAPI ThreadError OTCALL otGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo); - -/** - * The function retrieves the average RSSI for the Thread Parent. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[out] aParentInfo A pointer to where the parent rssi should be placed. - * - */ -OTAPI ThreadError OTCALL otGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi); - -/** - * This function registers a callback to provide received raw Network Diagnostic Get response payload. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aCallback A pointer to a function that is called when Network Diagnostic Get response - * is received or NULL to disable the callback. - * @param[in] aCallbackContext A pointer to application-specific context. - * - */ -void otSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback, - void *aCallbackContext); - -/** - * Send a Network Diagnostic Get request. - * - * @param[in] aDestination A pointer to destination address. - * @param[in] aTlvTypes An array of Network Diagnostic TLV types. - * @param[in] aCount Number of types in aTlvTypes - */ -OTAPI ThreadError OTCALL otSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination, - const uint8_t aTlvTypes[], uint8_t aCount); - -/** - * Send a Network Diagnostic Reset request. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aDestination A pointer to destination address. - * @param[in] aTlvTypes An array of Network Diagnostic TLV types. Currently only Type 9 is allowed. - * @param[in] aCount Number of types in aTlvTypes - */ -OTAPI ThreadError OTCALL otSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination, - const uint8_t aTlvTypes[], uint8_t aCount); - -/** - * @} - * - */ - /** * This function converts a ThreadError enum into a string. * diff --git a/include/openthread/Makefile.am b/include/openthread/Makefile.am index cabe9c088..80583fdd3 100644 --- a/include/openthread/Makefile.am +++ b/include/openthread/Makefile.am @@ -43,6 +43,7 @@ openthread_headers = \ message.h \ netdata.h \ tasklet.h \ + thread.h \ udp.h \ $(NULL) diff --git a/include/openthread/thread.h b/include/openthread/thread.h new file mode 100644 index 000000000..aadb7070a --- /dev/null +++ b/include/openthread/thread.h @@ -0,0 +1,901 @@ +/* + * Copyright (c) 2016, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * @brief + * This file defines the OpenThread Thread API. + */ + +#ifndef OPENTHREAD_THREAD_H_ +#define OPENTHREAD_THREAD_H_ + +#include "openthread-types.h" +#include "openthread/link.h" +#include "openthread/message.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup thread Thread + * + * @brief + * This module includes functions that control Thread-specific functions. + * + * @{ + * + */ + +/** + * @addtogroup config Configuration + * + * @brief + * This module includes functions for configuration. + * + * @{ + * + */ + +/** + * This function starts Thread protocol operation. + * + * The interface must be up when calling this function. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aEnabled TRUE if Thread is enabled, FALSE otherwise. + * + * @retval kThreadError_None Successfully started Thread protocol operation. + * @retval kThreadError_InvalidState The network interface was not not up. + * + */ +OTAPI ThreadError OTCALL otThreadSetEnabled(otInstance *aInstance, bool aEnabled); + +/** + * This function queries if the Thread stack is configured to automatically start on reinitialization. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval TRUE It is configured to automatically start. + * @retval FALSE It is not configured to automatically start. + * + */ +OTAPI bool OTCALL otThreadGetAutoStart(otInstance *aInstance); + +/** + * This function configures the Thread stack to automatically start on reinitialization. + * It has no effect on the current Thread state. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aStartAutomatically TRUE to automatically start; FALSE to not automatically start. + * + */ +OTAPI ThreadError OTCALL otThreadSetAutoStart(otInstance *aInstance, bool aStartAutomatically); + +/** + * This function indicates whether a node is the only router on the network. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval TRUE It is the only router in the network. + * @retval FALSE It is a child or is not a single router in the network. + * + */ +OTAPI bool OTCALL otThreadIsSingleton(otInstance *aInstance); + +/** + * This function starts a Thread Discovery scan. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aScanChannels A bit vector indicating which channels to scan (e.g. OT_CHANNEL_11_MASK). + * @param[in] aScanDuration The time in milliseconds to spend scanning each channel. + * @param[in] aPanId The PAN ID filter (set to Broadcast PAN to disable filter). + * @param[in] aCallback A pointer to a function called on receiving an MLE Discovery Response or scan completes. + * @param[in] aCallbackContext A pointer to application-specific context. + * + * @retval kThreadError_None Accepted the Thread Discovery request. + * @retval kThreadError_Busy Already performing an Thread Discovery. + * + */ +OTAPI ThreadError OTCALL otThreadDiscover(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration, + uint16_t aPanid, + otHandleActiveScanResult aCallback, void *aCallbackContext); + +/** + * This function determines if an MLE Thread Discovery is currently in progress. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + */ +OTAPI bool OTCALL otThreadIsDiscoverInProgress(otInstance *aInstance); + +/** + * @defgroup config-general General + * + * @brief + * This module includes functions that manage configuration parameters for the Thread Child, Router, and Leader roles. + * + * @{ + * + */ + +/** + * Get the maximum number of children currently allowed. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The maximum number of children currently allowed. + * + * @sa otThreadSetMaxAllowedChildren + */ +OTAPI uint8_t OTCALL otThreadGetMaxAllowedChildren(otInstance *aInstance); + +/** + * Set the maximum number of children currently allowed. + * + * This parameter can only be set when Thread protocol operation + * has been stopped. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aMaxChildren The maximum allowed children. + * + * @retval kThreadErrorNone Successfully set the max. + * @retval kThreadError_InvalidArgs If @p aMaxChildren is not in the range [1, OPENTHREAD_CONFIG_MAX_CHILDREN]. + * @retval kThreadError_InvalidState If Thread isn't stopped. + * + * @sa otThreadGetMaxAllowedChildren, otThreadStop + */ +OTAPI ThreadError OTCALL otThreadSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren); + +/** + * Get the Thread Child Timeout used when operating in the Child role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Thread Child Timeout value. + * + * @sa otThreadSetChildTimeout + */ +OTAPI uint32_t OTCALL otThreadGetChildTimeout(otInstance *aInstance); + +/** + * Set the Thread Child Timeout used when operating in the Child role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @sa otThreadSetChildTimeout + */ +OTAPI void OTCALL otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout); + +/** + * Get the IEEE 802.15.4 Extended PAN ID. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns A pointer to the IEEE 802.15.4 Extended PAN ID. + * + * @sa otThreadSetExtendedPanId + */ +OTAPI const uint8_t *OTCALL otThreadGetExtendedPanId(otInstance *aInstance); + +/** + * Set the IEEE 802.15.4 Extended PAN ID. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aExtendedPanId A pointer to the IEEE 802.15.4 Extended PAN ID. + * + * @sa otThreadGetExtendedPanId + */ +OTAPI void OTCALL otThreadSetExtendedPanId(otInstance *aInstance, const uint8_t *aExtendedPanId); + +/** + * This function returns a pointer to the Leader's RLOC. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aLeaderRloc A pointer to where the Leader's RLOC will be written. + * + * @retval kThreadError_None The Leader's RLOC was successfully written to @p aLeaderRloc. + * @retval kThreadError_InvalidArgs @p aLeaderRloc was NULL. + * @retval kThreadError_Detached Not currently attached to a Thread Partition. + * + */ +OTAPI ThreadError OTCALL otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aLeaderRloc); + +/** + * Get the MLE Link Mode configuration. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The MLE Link Mode configuration. + * + * @sa otThreadSetLinkMode + */ +OTAPI otLinkModeConfig OTCALL otThreadGetLinkMode(otInstance *aInstance); + +/** + * Set the MLE Link Mode configuration. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aConfig A pointer to the Link Mode configuration. + * + * @retval kThreadErrorNone Successfully set the MLE Link Mode configuration. + * + * @sa otThreadGetLinkMode + */ +OTAPI ThreadError OTCALL otThreadSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig); + +/** + * Get the thrMasterKey. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aKeyLength A pointer to an unsigned 8-bit value that the function will set to the number of bytes that + * represent the thrMasterKey. Caller may set to NULL. + * + * @returns A pointer to a buffer containing the thrMasterKey. + * + * @sa otThreadSetMasterKey + */ +OTAPI const uint8_t *OTCALL otThreadGetMasterKey(otInstance *aInstance, uint8_t *aKeyLength); + +/** + * Set the thrMasterKey. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aKey A pointer to a buffer containing the thrMasterKey. + * @param[in] aKeyLength Number of bytes representing the thrMasterKey stored at aKey. Valid range is [0, 16]. + * + * @retval kThreadErrorNone Successfully set the thrMasterKey. + * @retval kThreadErrorInvalidArgs If aKeyLength is larger than 16. + * + * @sa otThreadGetMasterKey + */ +OTAPI ThreadError OTCALL otThreadSetMasterKey(otInstance *aInstance, const uint8_t *aKey, uint8_t aKeyLength); + +/** + * This function returns a pointer to the Mesh Local EID. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns A pointer to the Mesh Local EID. + * + */ +OTAPI const otIp6Address *OTCALL otThreadGetMeshLocalEid(otInstance *aInstance); + +/** + * This function returns a pointer to the Mesh Local Prefix. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns A pointer to the Mesh Local Prefix. + * + */ +OTAPI const uint8_t *OTCALL otThreadGetMeshLocalPrefix(otInstance *aInstance); + +/** + * This function sets the Mesh Local Prefix. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aMeshLocalPrefix A pointer to the Mesh Local Prefix. + * + * @retval kThreadError_None Successfully set the Mesh Local Prefix. + * + */ +OTAPI ThreadError OTCALL otThreadSetMeshLocalPrefix(otInstance *aInstance, const uint8_t *aMeshLocalPrefix); + +/** + * Get the Thread Network Name. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns A pointer to the Thread Network Name. + * + * @sa otThreadSetNetworkName + */ +OTAPI const char *OTCALL otThreadGetNetworkName(otInstance *aInstance); + +/** + * Set the Thread Network Name. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aNetworkName A pointer to the Thread Network Name. + * + * @retval kThreadErrorNone Successfully set the Thread Network Name. + * + * @sa otThreadGetNetworkName + */ +OTAPI ThreadError OTCALL otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName); + +/** + * This function indicates whether or not the Router Role is enabled. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval TRUE If the Router Role is enabled. + * @retval FALSE If the Router Role is not enabled. + * + */ +OTAPI bool OTCALL otThreadIsRouterRoleEnabled(otInstance *aInstance); + +/** + * This function sets whether or not the Router Role is enabled. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aEnabled TRUE if the Router Role is enabled, FALSE otherwise. + * + */ +OTAPI void OTCALL otThreadSetRouterRoleEnabled(otInstance *aInstance, bool aEnabled); + +/** + * Set the preferred Router Id. + * + * Upon becoming a router/leader the node attempts to use this Router Id. If the + * preferred Router Id is not set or if it can not be used, a randomly generated + * router id is picked. This property can be set only when the device role is + * either detached or disabled. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aRouterId The preferred Router Id. + * + * @retval kThreadError_None Successfully set the preferred Router Id. + * @retval kThreadError_InvalidState Could not set (role is not detached or disabled) + * + */ +ThreadError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId); + +/** + * @} + */ + +/** + * @defgroup config-router Router/Leader + * + * @brief + * This module includes functions that manage configuration parameters for the Thread Router and Leader roles. + * + * @{ + * + */ + +/** + * Get the Thread Leader Weight used when operating in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Thread Leader Weight value. + * + * @sa otThreadSetLeaderWeight + */ +OTAPI uint8_t OTCALL otThreadGetLocalLeaderWeight(otInstance *aInstance); + +/** + * Set the Thread Leader Weight used when operating in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aWeight The Thread Leader Weight value.. + * + * @sa otThreadGetLeaderWeight + */ +OTAPI void OTCALL otThreadSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight); + +/** + * Get the Thread Leader Partition Id used when operating in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Thread Leader Partition Id value. + * + */ +OTAPI uint32_t OTCALL otThreadGetLocalLeaderPartitionId(otInstance *aInstance); + +/** + * Set the Thread Leader Partition Id used when operating in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aPartitionId The Thread Leader Partition Id value. + * + */ +OTAPI void OTCALL otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId); + +/** + * Get the Joiner UDP Port. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Joiner UDP Port number. + * + * @sa otThreadSetJoinerUdpPort + */ +OTAPI uint16_t OTCALL otThreadGetJoinerUdpPort(otInstance *aInstance); + +/** + * Set the Joiner UDP Port + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aJoinerUdpPort The Joiner UDP Port number. + * + * @retval kThreadErrorNone Successfully set the Joiner UDP Port. + * + * @sa otThreadGetJoinerUdpPort + */ +OTAPI ThreadError OTCALL otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort); + +/** + * @} + */ + +/** + * @defgroup config-test Test + * + * @brief + * This module includes functions that manage configuration parameters required for Thread Certification testing. + * + * @{ + * + */ + +/** + * Get the CONTEXT_ID_REUSE_DELAY parameter used in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The CONTEXT_ID_REUSE_DELAY value. + * + * @sa otThreadSetContextIdReuseDelay + */ +OTAPI uint32_t OTCALL otThreadGetContextIdReuseDelay(otInstance *aInstance); + +/** + * Set the CONTEXT_ID_REUSE_DELAY parameter used in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDelay The CONTEXT_ID_REUSE_DELAY value. + * + * @sa otThreadGetContextIdReuseDelay + */ +OTAPI void OTCALL otThreadSetContextIdReuseDelay(otInstance *aInstance, uint32_t aDelay); + +/** + * Get the thrKeySequenceCounter. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The thrKeySequenceCounter value. + * + * @sa otThreadSetKeySequenceCounter + */ +OTAPI uint32_t OTCALL otThreadGetKeySequenceCounter(otInstance *aInstance); + +/** + * Set the thrKeySequenceCounter. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aKeySequenceCounter The thrKeySequenceCounter value. + * + * @sa otThreadGetKeySequenceCounter + */ +OTAPI void OTCALL otThreadSetKeySequenceCounter(otInstance *aInstance, uint32_t aKeySequenceCounter); + +/** + * Get the thrKeySwitchGuardTime + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The thrKeySwitchGuardTime value (in hours). + * + * @sa otThreadSetKeySwitchGuardTime + */ +OTAPI uint32_t OTCALL otThreadGetKeySwitchGuardTime(otInstance *aInstance); + +/** + * Set the thrKeySwitchGuardTime + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aKeySwitchGuardTime The thrKeySwitchGuardTime value (in hours). + * + * @sa otThreadGetKeySwitchGuardTime + */ +OTAPI void OTCALL otThreadSetKeySwitchGuardTime(otInstance *aInstance, uint32_t aKeySwitchGuardTime); + + +/** + * Get the NETWORK_ID_TIMEOUT parameter used in the Router role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The NETWORK_ID_TIMEOUT value. + * + * @sa otThreadSetNetworkIdTimeout + */ +OTAPI uint8_t OTCALL otThreadGetNetworkIdTimeout(otInstance *aInstance); + +/** + * Set the NETWORK_ID_TIMEOUT parameter used in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aTimeout The NETWORK_ID_TIMEOUT value. + * + * @sa otThreadGetNetworkIdTimeout + */ +OTAPI void OTCALL otThreadSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout); + +/** + * Get the ROUTER_UPGRADE_THRESHOLD parameter used in the REED role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The ROUTER_UPGRADE_THRESHOLD value. + * + * @sa otThreadSetRouterUpgradeThreshold + */ +OTAPI uint8_t OTCALL otThreadGetRouterUpgradeThreshold(otInstance *aInstance); + +/** + * Set the ROUTER_UPGRADE_THRESHOLD parameter used in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aThreshold The ROUTER_UPGRADE_THRESHOLD value. + * + * @sa otThreadGetRouterUpgradeThreshold + */ +OTAPI void OTCALL otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold); + +/** + * Release a Router ID that has been allocated by the device in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aRouterId The Router ID to release. Valid range is [0, 62]. + * + * @retval kThreadErrorNone Successfully released the Router ID specified by aRouterId. + */ +OTAPI ThreadError OTCALL otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId); + +/** + * Detach from the Thread network. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval kThreadErrorNone Successfully detached from the Thread network. + * @retval kThreadErrorInvalidState Thread is disabled. + */ +OTAPI ThreadError OTCALL otThreadBecomeDetached(otInstance *aInstance); + +/** + * Attempt to reattach as a child. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aFilter Identifies whether to join any, same, or better partition. + * + * @retval kThreadErrorNone Successfully begin attempt to become a child. + * @retval kThreadErrorInvalidState Thread is disabled. + */ +OTAPI ThreadError OTCALL otThreadBecomeChild(otInstance *aInstance, otMleAttachFilter aFilter); + +/** + * Attempt to become a router. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval kThreadErrorNone Successfully begin attempt to become a router. + * @retval kThreadErrorInvalidState Thread is disabled. + */ +OTAPI ThreadError OTCALL otThreadBecomeRouter(otInstance *aInstance); + +/** + * Become a leader and start a new partition. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval kThreadErrorNone Successfully became a leader and started a new partition. + * @retval kThreadErrorInvalidState Thread is disabled. + */ +OTAPI ThreadError OTCALL otThreadBecomeLeader(otInstance *aInstance); + +/** + * Get the ROUTER_DOWNGRADE_THRESHOLD parameter used in the Router role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The ROUTER_DOWNGRADE_THRESHOLD value. + * + * @sa otThreadSetRouterDowngradeThreshold + */ +OTAPI uint8_t OTCALL otThreadGetRouterDowngradeThreshold(otInstance *aInstance); + +/** + * Set the ROUTER_DOWNGRADE_THRESHOLD parameter used in the Leader role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aThreshold The ROUTER_DOWNGRADE_THRESHOLD value. + * + * @sa otThreadGetRouterDowngradeThreshold + */ +OTAPI void OTCALL otThreadSetRouterDowngradeThreshold(otInstance *aInstance, uint8_t aThreshold); + +/** + * Get the ROUTER_SELECTION_JITTER parameter used in the REED/Router role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The ROUTER_SELECTION_JITTER value. + * + * @sa otThreadSetRouterSelectionJitter + */ +OTAPI uint8_t OTCALL otThreadGetRouterSelectionJitter(otInstance *aInstance); + +/** + * Set the ROUTER_SELECTION_JITTER parameter used in the REED/Router role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aRouterJitter The ROUTER_SELECTION_JITTER value. + * + * @sa otThreadGetRouterSelectionJitter + */ +OTAPI void OTCALL otThreadSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitter); + +/** + * @} + * + */ + +/** + * @} + * + */ + +/** + * @addtogroup diags Diagnostics + * + * @brief + * This module includes functions that expose internal state. + * + * @{ + * + */ + +/** + * The function retains diagnostic information for an attached Child by its Child ID or RLOC16. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aChildId The Child ID or RLOC16 for the attached child. + * @param[out] aChildInfo A pointer to where the child information is placed. + * + * @retavl kThreadError_None @p aChildInfo was successfully updated with the info for the given ID. + * @retval kThreadError_NotFound No valid child with this Child ID. + * @retavl kThreadError_InvalidArgs If @p aChildInfo is NULL. + * + */ +OTAPI ThreadError OTCALL otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo); + +/** + * The function retains diagnostic information for an attached Child by the internal table index. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aChildIndex The table index. + * @param[out] aChildInfo A pointer to where the child information is placed. + * + * @retavl kThreadError_None @p aChildInfo was successfully updated with the info for the given index. + * @retval kThreadError_NotFound No valid child at this index. + * @retavl kThreadError_InvalidArgs Either @p aChildInfo is NULL, or @p aChildIndex is out of range (higher + * than max table index). + * + * @sa otGetMaxAllowedChildren + * + */ +OTAPI ThreadError OTCALL otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, + otChildInfo *aChildInfo); + +/** + * This function gets the next neighbor information. It is used to go through the entries of + * the neighbor table. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[inout] aIterator A pointer to the iterator context. To get the first neighbor entry + it should be set to OT_NEIGHBOR_INFO_ITERATOR_INIT. + * @param[out] aInfo A pointer to where the neighbor information will be placed. + * + * @retval kThreadError_None Successfully found the next neighbor entry in table. + * @retval kThreadError_NotFound No subsequent neighbor entry exists in the table. + * @retval kThreadError_InvalidArgs @p aIterator or @p aInfo was NULL. + * + */ +OTAPI ThreadError OTCALL otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, + otNeighborInfo *aInfo); + +/** + * Get the device role. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval ::kDeviceRoleDisabled The Thread stack is disabled. + * @retval ::kDeviceRoleDetached The device is not currently participating in a Thread network/partition. + * @retval ::kDeviceRoleChild The device is currently operating as a Thread Child. + * @retval ::kDeviceRoleRouter The device is currently operating as a Thread Router. + * @retval ::kDeviceRoleLeader The device is currently operating as a Thread Leader. + */ +OTAPI otDeviceRole OTCALL otThreadGetDeviceRole(otInstance *aInstance); + +/** + * This function gets an EID cache entry. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aIndex An index into the EID cache table. + * @param[out] aEntry A pointer to where the EID information is placed. + * + * @retval kThreadError_None Successfully retrieved the EID cache entry. + * @retval kThreadError_InvalidArgs @p aIndex was out of bounds or @p aEntry was NULL. + * + */ +OTAPI ThreadError OTCALL otThreadGetEidCacheEntry(otInstance *aInstance, uint8_t aIndex, otEidCacheEntry *aEntry); + +/** + * This function get the Thread Leader Data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aLeaderData A pointer to where the leader data is placed. + * + * @retval kThreadError_None Successfully retrieved the leader data. + * @retval kThreadError_Detached Not currently attached. + * @retval kThreadError_InvalidArgs @p aLeaderData is NULL. + * + */ +OTAPI ThreadError OTCALL otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData); + +/** + * Get the Leader's Router ID. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Leader's Router ID. + */ +OTAPI uint8_t OTCALL otThreadGetLeaderRouterId(otInstance *aInstance); + +/** + * Get the Leader's Weight. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Leader's Weight. + */ +OTAPI uint8_t OTCALL otThreadGetLeaderWeight(otInstance *aInstance); + +/** + * Get the Partition ID. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Partition ID. + */ +OTAPI uint32_t OTCALL otThreadGetPartitionId(otInstance *aInstance); + +/** + * Get the RLOC16. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The RLOC16. + */ +OTAPI uint16_t OTCALL otThreadGetRloc16(otInstance *aInstance); + +/** + * Get the current Router ID Sequence. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns The Router ID Sequence. + */ +OTAPI uint8_t OTCALL otThreadGetRouterIdSequence(otInstance *aInstance); + +/** + * The function retains diagnostic information for a given Thread Router. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aRouterId The router ID or RLOC16 for a given router. + * @param[out] aRouterInfo A pointer to where the router information is placed. + * + */ +OTAPI ThreadError OTCALL otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo); + +/** + * The function retrieves diagnostic information for a Thread Router as parent. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aParentInfo A pointer to where the parent router information is placed. + * + */ +OTAPI ThreadError OTCALL otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo); + +/** + * The function retrieves the average RSSI for the Thread Parent. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aParentInfo A pointer to where the parent rssi should be placed. + * + */ +OTAPI ThreadError OTCALL otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi); + +/** + * This function pointer is called when Network Diagnostic Get response is received. + * + * @param[in] aMessage A pointer to the message buffer containing the received Network Diagnostic + * Get response payload. + * @param[in] aMessageInfo A pointer to the message info for @p aMessage. + * @param[in] aContext A pointer to application-specific context. + * + */ +typedef void (*otReceiveDiagnosticGetCallback)(otMessage aMessage, const otMessageInfo *aMessageInfo, + void *aContext); + +/** + * This function registers a callback to provide received raw Network Diagnostic Get response payload. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aCallback A pointer to a function that is called when Network Diagnostic Get response + * is received or NULL to disable the callback. + * @param[in] aCallbackContext A pointer to application-specific context. + * + */ +void otThreadSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback, + void *aCallbackContext); + +/** + * Send a Network Diagnostic Get request. + * + * @param[in] aDestination A pointer to destination address. + * @param[in] aTlvTypes An array of Network Diagnostic TLV types. + * @param[in] aCount Number of types in aTlvTypes + */ +OTAPI ThreadError OTCALL otThreadSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination, + const uint8_t aTlvTypes[], uint8_t aCount); + +/** + * Send a Network Diagnostic Reset request. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDestination A pointer to destination address. + * @param[in] aTlvTypes An array of Network Diagnostic TLV types. Currently only Type 9 is allowed. + * @param[in] aCount Number of types in aTlvTypes + */ +OTAPI ThreadError OTCALL otThreadSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination, + const uint8_t aTlvTypes[], uint8_t aCount); + +/** + * @} + * + */ + +/** + * @} + * + */ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OPENTHREAD_THREAD_H_ diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index a070290a8..32ad55474 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -202,7 +202,7 @@ Interpreter::Interpreter(otInstance *aInstance): #else memset(mSlaacAddresses, 0, sizeof(mSlaacAddresses)); otSetStateChangedCallback(mInstance, &Interpreter::s_HandleNetifStateChanged, this); - otSetReceiveDiagnosticGetCallback(mInstance, &Interpreter::s_HandleDiagnosticGetResponse, this); + otThreadSetReceiveDiagnosticGetCallback(mInstance, &Interpreter::s_HandleDiagnosticGetResponse, this); mIcmpHandler.mReceiveCallback = Interpreter::s_HandleIcmpReceive; mIcmpHandler.mContext = this; @@ -464,11 +464,11 @@ void Interpreter::ProcessChild(int argc, char *argv[]) sServer->OutputFormat("+-----+--------+------------+------------+--------+------+-+-+-+-+------------------+\r\n"); } - maxChildren = otGetMaxAllowedChildren(mInstance); + maxChildren = otThreadGetMaxAllowedChildren(mInstance); for (uint8_t i = 0; i < maxChildren ; i++) { - if (otGetChildInfoByIndex(mInstance, i, &childInfo) != kThreadError_None) + if (otThreadGetChildInfoByIndex(mInstance, i, &childInfo) != kThreadError_None) { sServer->OutputFormat("\r\n"); ExitNow(); @@ -506,7 +506,7 @@ void Interpreter::ProcessChild(int argc, char *argv[]) } SuccessOrExit(error = ParseLong(argv[0], value)); - SuccessOrExit(error = otGetChildInfoById(mInstance, static_cast(value), &childInfo)); + SuccessOrExit(error = otThreadGetChildInfoById(mInstance, static_cast(value), &childInfo)); sServer->OutputFormat("Child ID: %d\r\n", childInfo.mChildId); sServer->OutputFormat("Rloc: %04x\r\n", childInfo.mRloc16); @@ -559,12 +559,12 @@ void Interpreter::ProcessChildMax(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetMaxAllowedChildren(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetMaxAllowedChildren(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); - SuccessOrExit(error = otSetMaxAllowedChildren(mInstance, static_cast(value))); + SuccessOrExit(error = otThreadSetMaxAllowedChildren(mInstance, static_cast(value))); } exit: @@ -578,12 +578,12 @@ void Interpreter::ProcessChildTimeout(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetChildTimeout(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetChildTimeout(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); - otSetChildTimeout(mInstance, static_cast(value)); + otThreadSetChildTimeout(mInstance, static_cast(value)); } exit: @@ -597,12 +597,12 @@ void Interpreter::ProcessContextIdReuseDelay(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetContextIdReuseDelay(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetContextIdReuseDelay(mInstance)); } else { SuccessOrExit(ParseLong(argv[0], value)); - otSetContextIdReuseDelay(mInstance, static_cast(value)); + otThreadSetContextIdReuseDelay(mInstance, static_cast(value)); } exit: @@ -697,8 +697,8 @@ void Interpreter::ProcessDiscover(int argc, char *argv[]) scanChannels = 1 << value; } - SuccessOrExit(error = otDiscover(mInstance, scanChannels, 0, OT_PANID_BROADCAST, - &Interpreter::s_HandleActiveScanResult, this)); + SuccessOrExit(error = otThreadDiscover(mInstance, scanChannels, 0, OT_PANID_BROADCAST, + &Interpreter::s_HandleActiveScanResult, this)); sServer->OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n"); sServer->OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n"); @@ -714,7 +714,7 @@ void Interpreter::ProcessEidCache(int argc, char *argv[]) for (uint8_t i = 0; ; i++) { - SuccessOrExit(otGetEidCacheEntry(mInstance, i, &entry)); + SuccessOrExit(otThreadGetEidCacheEntry(mInstance, i, &entry)); if (entry.mValid == false) { @@ -793,7 +793,7 @@ void Interpreter::ProcessExtPanId(int argc, char *argv[]) if (argc == 0) { - otBufferPtr extPanId(otGetExtendedPanId(mInstance)); + otBufferPtr extPanId(otThreadGetExtendedPanId(mInstance)); OutputBytes(extPanId, OT_EXT_PAN_ID_SIZE); sServer->OutputFormat("\r\n"); } @@ -803,7 +803,7 @@ void Interpreter::ProcessExtPanId(int argc, char *argv[]) VerifyOrExit(Hex2Bin(argv[0], extPanId, sizeof(extPanId)) >= 0, error = kThreadError_Parse); - otSetExtendedPanId(mInstance, extPanId); + otThreadSetExtendedPanId(mInstance, extPanId); } exit: @@ -1044,24 +1044,24 @@ void Interpreter::ProcessKeySequence(int argc, char *argv[]) { if (argc == 1) { - sServer->OutputFormat("%d\r\n", otGetKeySequenceCounter(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetKeySequenceCounter(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[1], value)); - otSetKeySequenceCounter(mInstance, static_cast(value)); + otThreadSetKeySequenceCounter(mInstance, static_cast(value)); } } else if (strcmp(argv[0], "guardtime") == 0) { if (argc == 1) { - sServer->OutputFormat("%d\r\n", otGetKeySwitchGuardTime(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetKeySwitchGuardTime(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[1], value)); - otSetKeySwitchGuardTime(mInstance, static_cast(value)); + otThreadSetKeySwitchGuardTime(mInstance, static_cast(value)); } } @@ -1074,7 +1074,7 @@ void Interpreter::ProcessLeaderData(int argc, char *argv[]) ThreadError error; otLeaderData leaderData; - SuccessOrExit(error = otGetLeaderData(mInstance, &leaderData)); + SuccessOrExit(error = otThreadGetLeaderData(mInstance, &leaderData)); sServer->OutputFormat("Partition ID: %u\r\n", leaderData.mPartitionId); sServer->OutputFormat("Weighting: %d\r\n", leaderData.mWeighting); @@ -1095,12 +1095,12 @@ void Interpreter::ProcessLeaderPartitionId(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%u\r\n", otGetLocalLeaderPartitionId(mInstance)); + sServer->OutputFormat("%u\r\n", otThreadGetLocalLeaderPartitionId(mInstance)); } else { SuccessOrExit(error = ParseUnsignedLong(argv[0], value)); - otSetLocalLeaderPartitionId(mInstance, static_cast(value)); + otThreadSetLocalLeaderPartitionId(mInstance, static_cast(value)); } exit: @@ -1114,12 +1114,12 @@ void Interpreter::ProcessLeaderWeight(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetLocalLeaderWeight(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetLocalLeaderWeight(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); - otSetLocalLeaderWeight(mInstance, static_cast(value)); + otThreadSetLocalLeaderWeight(mInstance, static_cast(value)); } exit: @@ -1159,7 +1159,7 @@ void Interpreter::ProcessMasterKey(int argc, char *argv[]) if (argc == 0) { uint8_t keyLength; - otBufferPtr key(otGetMasterKey(mInstance, &keyLength)); + otBufferPtr key(otThreadGetMasterKey(mInstance, &keyLength)); for (int i = 0; i < keyLength; i++) { @@ -1174,7 +1174,7 @@ void Interpreter::ProcessMasterKey(int argc, char *argv[]) uint8_t key[OT_MASTER_KEY_SIZE]; VerifyOrExit((keyLength = Hex2Bin(argv[0], key, sizeof(key))) == OT_MASTER_KEY_SIZE, error = kThreadError_Parse); - SuccessOrExit(error = otSetMasterKey(mInstance, key, static_cast(keyLength))); + SuccessOrExit(error = otThreadSetMasterKey(mInstance, key, static_cast(keyLength))); } exit: @@ -1190,7 +1190,7 @@ void Interpreter::ProcessMode(int argc, char *argv[]) if (argc == 0) { - linkMode = otGetLinkMode(mInstance); + linkMode = otThreadGetLinkMode(mInstance); if (linkMode.mRxOnWhenIdle) { @@ -1241,7 +1241,7 @@ void Interpreter::ProcessMode(int argc, char *argv[]) } } - SuccessOrExit(error = otSetLinkMode(mInstance, linkMode)); + SuccessOrExit(error = otThreadSetLinkMode(mInstance, linkMode)); } exit: @@ -1266,12 +1266,12 @@ void Interpreter::ProcessNetworkIdTimeout(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetNetworkIdTimeout(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetNetworkIdTimeout(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); - otSetNetworkIdTimeout(mInstance, static_cast(value)); + otThreadSetNetworkIdTimeout(mInstance, static_cast(value)); } exit: @@ -1284,12 +1284,12 @@ void Interpreter::ProcessNetworkName(int argc, char *argv[]) if (argc == 0) { - otStringPtr networkName(otGetNetworkName(mInstance)); + otStringPtr networkName(otThreadGetNetworkName(mInstance)); sServer->OutputFormat("%.*s\r\n", OT_NETWORK_NAME_MAX_SIZE, (const char *)networkName); } else { - SuccessOrExit(error = otSetNetworkName(mInstance, argv[0])); + SuccessOrExit(error = otThreadSetNetworkName(mInstance, argv[0])); } exit: @@ -1320,7 +1320,7 @@ void Interpreter::ProcessParent(int argc, char *argv[]) ThreadError error = kThreadError_None; otRouterInfo parentInfo; - SuccessOrExit(error = otGetParentInfo(mInstance, &parentInfo)); + SuccessOrExit(error = otThreadGetParentInfo(mInstance, &parentInfo)); sServer->OutputFormat("Ext Addr: "); for (size_t i = 0; i < sizeof(parentInfo.mExtAddress); i++) @@ -1813,7 +1813,7 @@ void Interpreter::ProcessReleaseRouterId(int argc, char *argv[]) VerifyOrExit(argc > 0, error = kThreadError_Parse); SuccessOrExit(error = ParseLong(argv[0], value)); - SuccessOrExit(error = otReleaseRouterId(mInstance, static_cast(value))); + SuccessOrExit(error = otThreadReleaseRouterId(mInstance, static_cast(value))); exit: AppendResult(error); @@ -1828,7 +1828,7 @@ void Interpreter::ProcessReset(int argc, char *argv[]) void Interpreter::ProcessRloc16(int argc, char *argv[]) { - sServer->OutputFormat("%04x\r\n", otGetRloc16(mInstance)); + sServer->OutputFormat("%04x\r\n", otThreadGetRloc16(mInstance)); sServer->OutputFormat("Done\r\n"); (void)argc; (void)argv; @@ -1971,7 +1971,7 @@ void Interpreter::ProcessRouter(int argc, char *argv[]) for (uint8_t i = 0; ; i++) { - if (otGetRouterInfo(mInstance, i, &routerInfo) != kThreadError_None) + if (otThreadGetRouterInfo(mInstance, i, &routerInfo) != kThreadError_None) { sServer->OutputFormat("\r\n"); ExitNow(); @@ -2006,7 +2006,7 @@ void Interpreter::ProcessRouter(int argc, char *argv[]) } SuccessOrExit(error = ParseLong(argv[0], value)); - SuccessOrExit(error = otGetRouterInfo(mInstance, static_cast(value), &routerInfo)); + SuccessOrExit(error = otThreadGetRouterInfo(mInstance, static_cast(value), &routerInfo)); sServer->OutputFormat("Alloc: %d\r\n", routerInfo.mAllocated); @@ -2045,12 +2045,12 @@ void Interpreter::ProcessRouterDowngradeThreshold(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetRouterDowngradeThreshold(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetRouterDowngradeThreshold(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); - otSetRouterDowngradeThreshold(mInstance, static_cast(value)); + otThreadSetRouterDowngradeThreshold(mInstance, static_cast(value)); } exit: @@ -2063,7 +2063,7 @@ void Interpreter::ProcessRouterRole(int argc, char *argv[]) if (argc == 0) { - if (otIsRouterRoleEnabled(mInstance)) + if (otThreadIsRouterRoleEnabled(mInstance)) { sServer->OutputFormat("Enabled\r\n"); } @@ -2074,11 +2074,11 @@ void Interpreter::ProcessRouterRole(int argc, char *argv[]) } else if (strcmp(argv[0], "enable") == 0) { - otSetRouterRoleEnabled(mInstance, true); + otThreadSetRouterRoleEnabled(mInstance, true); } else if (strcmp(argv[0], "disable") == 0) { - otSetRouterRoleEnabled(mInstance, false); + otThreadSetRouterRoleEnabled(mInstance, false); } else { @@ -2096,13 +2096,13 @@ void Interpreter::ProcessRouterSelectionJitter(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetRouterSelectionJitter(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetRouterSelectionJitter(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); VerifyOrExit(0 < value && value < 256, error = kThreadError_InvalidArgs); - otSetRouterSelectionJitter(mInstance, static_cast(value)); + otThreadSetRouterSelectionJitter(mInstance, static_cast(value)); } exit: @@ -2116,12 +2116,12 @@ void Interpreter::ProcessRouterUpgradeThreshold(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetRouterUpgradeThreshold(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetRouterUpgradeThreshold(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); - otSetRouterUpgradeThreshold(mInstance, static_cast(value)); + otThreadSetRouterUpgradeThreshold(mInstance, static_cast(value)); } exit: @@ -2185,7 +2185,7 @@ void Interpreter::ProcessSingleton(int argc, char *argv[]) { ThreadError error = kThreadError_None; - if (otIsSingleton(mInstance)) + if (otThreadIsSingleton(mInstance)) { sServer->OutputFormat("true\r\n"); } @@ -2206,7 +2206,7 @@ void Interpreter::ProcessState(int argc, char *argv[]) if (argc == 0) { - switch (otGetDeviceRole(mInstance)) + switch (otThreadGetDeviceRole(mInstance)) { case kDeviceRoleOffline: sServer->OutputFormat("offline\r\n"); @@ -2237,19 +2237,19 @@ void Interpreter::ProcessState(int argc, char *argv[]) { if (strcmp(argv[0], "detached") == 0) { - SuccessOrExit(error = otBecomeDetached(mInstance)); + SuccessOrExit(error = otThreadBecomeDetached(mInstance)); } else if (strcmp(argv[0], "child") == 0) { - SuccessOrExit(error = otBecomeChild(mInstance, kMleAttachSamePartition1)); + SuccessOrExit(error = otThreadBecomeChild(mInstance, kMleAttachSamePartition1)); } else if (strcmp(argv[0], "router") == 0) { - SuccessOrExit(error = otBecomeRouter(mInstance)); + SuccessOrExit(error = otThreadBecomeRouter(mInstance)); } else if (strcmp(argv[0], "leader") == 0) { - SuccessOrExit(error = otBecomeLeader(mInstance)); + SuccessOrExit(error = otThreadBecomeLeader(mInstance)); } else { @@ -2269,11 +2269,11 @@ void Interpreter::ProcessThread(int argc, char *argv[]) if (strcmp(argv[0], "start") == 0) { - SuccessOrExit(error = otThreadStart(mInstance)); + SuccessOrExit(error = otThreadSetEnabled(mInstance, true)); } else if (strcmp(argv[0], "stop") == 0) { - SuccessOrExit(error = otThreadStop(mInstance)); + SuccessOrExit(error = otThreadSetEnabled(mInstance, false)); } exit: @@ -2623,12 +2623,12 @@ void Interpreter::ProcessJoinerPort(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", otGetJoinerUdpPort(mInstance)); + sServer->OutputFormat("%d\r\n", otThreadGetJoinerUdpPort(mInstance)); } else { SuccessOrExit(error = ParseLong(argv[0], value)); - error = otSetJoinerUdpPort(mInstance, static_cast(value)); + error = otThreadSetJoinerUdpPort(mInstance, static_cast(value)); } exit: @@ -2838,12 +2838,12 @@ void Interpreter::ProcessNetworkDiagnostic(int argc, char *argv[]) if (strcmp(argv[0], "get") == 0) { - otSendDiagnosticGet(mInstance, &address, payload, payloadIndex); + otThreadSendDiagnosticGet(mInstance, &address, payload, payloadIndex); return; } else if (strcmp(argv[0], "reset") == 0) { - otSendDiagnosticReset(mInstance, &address, payload, payloadIndex); + otThreadSendDiagnosticReset(mInstance, &address, payload, payloadIndex); } exit: diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 0648b6154..1b1f1b881 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -48,6 +48,7 @@ SOURCES_COMMON = \ api/message_api.cpp \ api/netdata_api.cpp \ api/tasklet_api.cpp \ + api/thread_api.cpp \ api/udp_api.cpp \ coap/coap_base.cpp \ coap/coap_client.cpp \ diff --git a/src/core/api/instance_api.cpp b/src/core/api/instance_api.cpp index 7e446ba68..16b38bb05 100644 --- a/src/core/api/instance_api.cpp +++ b/src/core/api/instance_api.cpp @@ -84,7 +84,7 @@ void otInstancePostConstructor(otInstance *aInstance) if (otIp6SetEnabled(aInstance, true) == kThreadError_None) { // Only try to start Thread if we could bring up the interface - if (otThreadStart(aInstance) != kThreadError_None) + if (otThreadSetEnabled(aInstance, true) != kThreadError_None) { // Bring the interface down if Thread failed to start otIp6SetEnabled(aInstance, false); @@ -152,7 +152,7 @@ void otInstanceFinalize(otInstance *aInstance) otLogFuncEntry(); // Ensure we are disabled - (void)otThreadStop(aInstance); + (void)otThreadSetEnabled(aInstance, false); (void)otIp6SetEnabled(aInstance, false); #ifndef OPENTHREAD_MULTIPLE_INSTANCE @@ -206,7 +206,7 @@ ThreadError otInstanceErasePersistentInfo(otInstance *aInstance) { ThreadError error = kThreadError_None; - VerifyOrExit(otGetDeviceRole(aInstance) == kDeviceRoleDisabled, error = kThreadError_InvalidState); + VerifyOrExit(otThreadGetDeviceRole(aInstance) == kDeviceRoleDisabled, error = kThreadError_InvalidState); otPlatSettingsWipe(aInstance); exit: diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp new file mode 100644 index 000000000..04c694f93 --- /dev/null +++ b/src/core/api/thread_api.cpp @@ -0,0 +1,658 @@ +/* + * Copyright (c) 2016, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements the OpenThread Thread API. + */ + +#define WPP_NAME "thread_api.tmh" + +#include "openthread/thread.h" + +#include "openthread-instance.h" +#include "common/logging.hpp" +#include "common/settings.hpp" +#include "platform/settings.h" + +using namespace Thread; + +#ifdef __cplusplus +extern "C" { +#endif + +uint8_t otThreadGetMaxAllowedChildren(otInstance *aInstance) +{ + uint8_t aNumChildren; + + (void)aInstance->mThreadNetif.GetMle().GetChildren(&aNumChildren); + + return aNumChildren; +} + +ThreadError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren) +{ + return aInstance->mThreadNetif.GetMle().SetMaxAllowedChildren(aMaxChildren); +} + +uint32_t otThreadGetChildTimeout(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetTimeout(); +} + +void otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout) +{ + aInstance->mThreadNetif.GetMle().SetTimeout(aTimeout); +} + +const uint8_t *otThreadGetExtendedPanId(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMac().GetExtendedPanId(); +} + +void otThreadSetExtendedPanId(otInstance *aInstance, const uint8_t *aExtendedPanId) +{ + uint8_t mlPrefix[8]; + + aInstance->mThreadNetif.GetMac().SetExtendedPanId(aExtendedPanId); + + mlPrefix[0] = 0xfd; + memcpy(mlPrefix + 1, aExtendedPanId, 5); + mlPrefix[6] = 0x00; + mlPrefix[7] = 0x00; + aInstance->mThreadNetif.GetMle().SetMeshLocalPrefix(mlPrefix); +} + +ThreadError otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aAddress) +{ + ThreadError error; + + VerifyOrExit(aAddress != NULL, error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetMle().GetLeaderAddress(*static_cast(aAddress)); + +exit: + return error; +} + +otLinkModeConfig otThreadGetLinkMode(otInstance *aInstance) +{ + otLinkModeConfig config; + uint8_t mode = aInstance->mThreadNetif.GetMle().GetDeviceMode(); + + memset(&config, 0, sizeof(otLinkModeConfig)); + + if (mode & Mle::ModeTlv::kModeRxOnWhenIdle) + { + config.mRxOnWhenIdle = 1; + } + + if (mode & Mle::ModeTlv::kModeSecureDataRequest) + { + config.mSecureDataRequests = 1; + } + + if (mode & Mle::ModeTlv::kModeFFD) + { + config.mDeviceType = 1; + } + + if (mode & Mle::ModeTlv::kModeFullNetworkData) + { + config.mNetworkData = 1; + } + + return config; +} + +ThreadError otThreadSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig) +{ + uint8_t mode = 0; + + if (aConfig.mRxOnWhenIdle) + { + mode |= Mle::ModeTlv::kModeRxOnWhenIdle; + } + + if (aConfig.mSecureDataRequests) + { + mode |= Mle::ModeTlv::kModeSecureDataRequest; + } + + if (aConfig.mDeviceType) + { + mode |= Mle::ModeTlv::kModeFFD; + } + + if (aConfig.mNetworkData) + { + mode |= Mle::ModeTlv::kModeFullNetworkData; + } + + return aInstance->mThreadNetif.GetMle().SetDeviceMode(mode); +} + +const uint8_t *otThreadGetMasterKey(otInstance *aInstance, uint8_t *aKeyLength) +{ + return aInstance->mThreadNetif.GetKeyManager().GetMasterKey(aKeyLength); +} + +ThreadError otThreadSetMasterKey(otInstance *aInstance, const uint8_t *aKey, uint8_t aKeyLength) +{ + return aInstance->mThreadNetif.GetKeyManager().SetMasterKey(aKey, aKeyLength); +} + +const otIp6Address *otThreadGetMeshLocalEid(otInstance *aInstance) +{ + return &aInstance->mThreadNetif.GetMle().GetMeshLocal64(); +} + +const uint8_t *otThreadGetMeshLocalPrefix(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetMeshLocalPrefix(); +} + +ThreadError otThreadSetMeshLocalPrefix(otInstance *aInstance, const uint8_t *aMeshLocalPrefix) +{ + return aInstance->mThreadNetif.GetMle().SetMeshLocalPrefix(aMeshLocalPrefix); +} + +const char *otThreadGetNetworkName(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMac().GetNetworkName(); +} + +ThreadError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName) +{ + return aInstance->mThreadNetif.GetMac().SetNetworkName(aNetworkName); +} + +bool otThreadIsRouterRoleEnabled(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().IsRouterRoleEnabled(); +} + +void otThreadSetRouterRoleEnabled(otInstance *aInstance, bool aEnabled) +{ + aInstance->mThreadNetif.GetMle().SetRouterRoleEnabled(aEnabled); +} + +uint8_t otThreadGetLocalLeaderWeight(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetLeaderWeight(); +} + +void otThreadSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight) +{ + aInstance->mThreadNetif.GetMle().SetLeaderWeight(aWeight); +} + +uint32_t otThreadGetLocalLeaderPartitionId(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetLeaderPartitionId(); +} + +void otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId) +{ + return aInstance->mThreadNetif.GetMle().SetLeaderPartitionId(aPartitionId); +} + +uint16_t otThreadGetJoinerUdpPort(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetJoinerRouter().GetJoinerUdpPort(); +} + +ThreadError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort) +{ + return aInstance->mThreadNetif.GetJoinerRouter().SetJoinerUdpPort(aJoinerUdpPort); +} + +uint32_t otThreadGetContextIdReuseDelay(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetNetworkDataLeader().GetContextIdReuseDelay(); +} + +void otThreadSetContextIdReuseDelay(otInstance *aInstance, uint32_t aDelay) +{ + aInstance->mThreadNetif.GetNetworkDataLeader().SetContextIdReuseDelay(aDelay); +} + +uint32_t otThreadGetKeySequenceCounter(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetKeyManager().GetCurrentKeySequence(); +} + +void otThreadSetKeySequenceCounter(otInstance *aInstance, uint32_t aKeySequenceCounter) +{ + aInstance->mThreadNetif.GetKeyManager().SetCurrentKeySequence(aKeySequenceCounter); +} + +uint32_t otThreadGetKeySwitchGuardTime(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetKeyManager().GetKeySwitchGuardTime(); +} + +void otThreadSetKeySwitchGuardTime(otInstance *aInstance, uint32_t aKeySwitchGuardTime) +{ + aInstance->mThreadNetif.GetKeyManager().SetKeySwitchGuardTime(aKeySwitchGuardTime); +} + +uint8_t otThreadGetNetworkIdTimeout(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetNetworkIdTimeout(); +} + +void otThreadSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout) +{ + aInstance->mThreadNetif.GetMle().SetNetworkIdTimeout((uint8_t)aTimeout); +} + +uint8_t otThreadGetRouterUpgradeThreshold(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetRouterUpgradeThreshold(); +} + +void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold) +{ + aInstance->mThreadNetif.GetMle().SetRouterUpgradeThreshold(aThreshold); +} + +ThreadError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId) +{ + return aInstance->mThreadNetif.GetMle().ReleaseRouterId(aRouterId); +} + +ThreadError otThreadBecomeDetached(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().BecomeDetached(); +} + +ThreadError otThreadBecomeChild(otInstance *aInstance, otMleAttachFilter aFilter) +{ + return aInstance->mThreadNetif.GetMle().BecomeChild(aFilter); +} + +ThreadError otThreadBecomeRouter(otInstance *aInstance) +{ + ThreadError error = kThreadError_InvalidState; + + switch (aInstance->mThreadNetif.GetMle().GetDeviceState()) + { + case Mle::kDeviceStateDisabled: + case Mle::kDeviceStateDetached: + break; + + case Mle::kDeviceStateChild: + error = aInstance->mThreadNetif.GetMle().BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest); + break; + + case Mle::kDeviceStateRouter: + case Mle::kDeviceStateLeader: + error = kThreadError_None; + break; + } + + return error; +} + +ThreadError otThreadBecomeLeader(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().BecomeLeader(); +} + +uint8_t otThreadGetRouterDowngradeThreshold(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetRouterDowngradeThreshold(); +} + +void otThreadSetRouterDowngradeThreshold(otInstance *aInstance, uint8_t aThreshold) +{ + aInstance->mThreadNetif.GetMle().SetRouterDowngradeThreshold(aThreshold); +} + +uint8_t otThreadGetRouterSelectionJitter(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetRouterSelectionJitter(); +} + +void otThreadSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitter) +{ + aInstance->mThreadNetif.GetMle().SetRouterSelectionJitter(aRouterJitter); +} + +ThreadError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo) +{ + ThreadError error = kThreadError_None; + + VerifyOrExit(aChildInfo != NULL, error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetMle().GetChildInfoById(aChildId, *aChildInfo); + +exit: + return error; +} + +ThreadError otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, otChildInfo *aChildInfo) +{ + ThreadError error = kThreadError_None; + + VerifyOrExit(aChildInfo != NULL, error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetMle().GetChildInfoByIndex(aChildIndex, *aChildInfo); + +exit: + return error; +} + +ThreadError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo) +{ + ThreadError error = kThreadError_None; + + VerifyOrExit((aInfo != NULL) && (aIterator != NULL), error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetMle().GetNextNeighborInfo(*aIterator, *aInfo); + +exit: + return error; +} + +otDeviceRole otThreadGetDeviceRole(otInstance *aInstance) +{ + otDeviceRole rval = kDeviceRoleDisabled; + + switch (aInstance->mThreadNetif.GetMle().GetDeviceState()) + { + case Mle::kDeviceStateDisabled: + rval = kDeviceRoleDisabled; + break; + + case Mle::kDeviceStateDetached: + rval = kDeviceRoleDetached; + break; + + case Mle::kDeviceStateChild: + rval = kDeviceRoleChild; + break; + + case Mle::kDeviceStateRouter: + rval = kDeviceRoleRouter; + break; + + case Mle::kDeviceStateLeader: + rval = kDeviceRoleLeader; + break; + } + + return rval; +} + +ThreadError otThreadGetEidCacheEntry(otInstance *aInstance, uint8_t aIndex, otEidCacheEntry *aEntry) +{ + ThreadError error; + + VerifyOrExit(aEntry != NULL, error = kThreadError_InvalidArgs); + error = aInstance->mThreadNetif.GetAddressResolver().GetEntry(aIndex, *aEntry); + +exit: + return error; +} + +ThreadError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData) +{ + ThreadError error; + + VerifyOrExit(aLeaderData != NULL, error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetMle().GetLeaderData(*aLeaderData); + +exit: + return error; +} + +uint8_t otThreadGetLeaderRouterId(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetLeaderRouterId(); +} + +uint8_t otThreadGetLeaderWeight(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetWeighting(); +} + +uint32_t otThreadGetPartitionId(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetPartitionId(); +} + +uint16_t otThreadGetRloc16(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetRloc16(); +} + +uint8_t otThreadGetRouterIdSequence(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().GetRouterIdSequence(); +} + +ThreadError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo) +{ + ThreadError error = kThreadError_None; + + VerifyOrExit(aRouterInfo != NULL, error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetMle().GetRouterInfo(aRouterId, *aRouterInfo); + +exit: + return error; +} + +ThreadError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) +{ + ThreadError error = kThreadError_None; + Router *parent; + + VerifyOrExit(aParentInfo != NULL, error = kThreadError_InvalidArgs); + + parent = aInstance->mThreadNetif.GetMle().GetParent(); + memcpy(aParentInfo->mExtAddress.m8, parent->mMacAddr.m8, OT_EXT_ADDRESS_SIZE); + + aParentInfo->mRloc16 = parent->mValid.mRloc16; + aParentInfo->mRouterId = Mle::Mle::GetRouterId(parent->mValid.mRloc16); + aParentInfo->mNextHop = parent->mNextHop; + aParentInfo->mPathCost = parent->mCost; + aParentInfo->mLinkQualityIn = parent->mLinkInfo.GetLinkQuality(aInstance->mThreadNetif.GetMac().GetNoiseFloor()); + aParentInfo->mLinkQualityOut = parent->mLinkQualityOut; + aParentInfo->mAge = static_cast(Timer::MsecToSec(Timer::GetNow() - parent->mLastHeard)); + aParentInfo->mAllocated = parent->mAllocated; + aParentInfo->mLinkEstablished = parent->mState == Neighbor::kStateValid; + +exit: + return error; +} + +ThreadError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) +{ + ThreadError error = kThreadError_None; + Router *parent; + + VerifyOrExit(aParentRssi != NULL, error = kThreadError_InvalidArgs); + + parent = aInstance->mThreadNetif.GetMle().GetParent(); + *aParentRssi = parent->mLinkInfo.GetAverageRss(); + + VerifyOrExit(*aParentRssi != LinkQualityInfo::kUnknownRss, error = kThreadError_Failed); + +exit: + return error; +} + +const char *otGetVersionString(void) +{ + /** + * PLATFORM_VERSION_ATTR_PREFIX and PLATFORM_VERSION_ATTR_SUFFIX are + * intended to be used to specify compiler directives to indicate + * what linker section the platform version string should be stored. + * + * This is useful for specifying an exact locaiton of where the version + * string will be located so that it can be easily retrieved from the + * raw firmware image. + * + * If PLATFORM_VERSION_ATTR_PREFIX is unspecified, the keyword `static` + * is used instead. + * + * If both are unspecified, the location of the string in the firmware + * image will be undefined and may change. + */ + +#ifdef PLATFORM_VERSION_ATTR_PREFIX + PLATFORM_VERSION_ATTR_PREFIX +#else + static +#endif + const char sVersion[] = + PACKAGE_NAME "/" PACKAGE_VERSION +#ifdef PLATFORM_INFO + "; " PLATFORM_INFO +#endif +#if defined(__DATE__) + "; " __DATE__ " " __TIME__ +#endif +#ifdef PLATFORM_VERSION_ATTR_SUFFIX + PLATFORM_VERSION_ATTR_SUFFIX +#endif + ; // Trailing semicolon to end statement. + + return sVersion; +} + +ThreadError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId) +{ + return aInstance->mThreadNetif.GetMle().SetPreferredRouterId(aRouterId); +} + +void otThreadSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback, + void *aCallbackContext) +{ + aInstance->mThreadNetif.GetNetworkDiagnostic().SetReceiveDiagnosticGetCallback(aCallback, aCallbackContext); +} + +ThreadError otThreadSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination, + const uint8_t aTlvTypes[], uint8_t aCount) +{ + return aInstance->mThreadNetif.GetNetworkDiagnostic().SendDiagnosticGet(*static_cast + (aDestination), + aTlvTypes, + aCount); +} + +ThreadError otThreadSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination, + const uint8_t aTlvTypes[], uint8_t aCount) +{ + return aInstance->mThreadNetif.GetNetworkDiagnostic().SendDiagnosticReset(*static_cast + (aDestination), + aTlvTypes, + aCount); +} + +ThreadError otThreadSetEnabled(otInstance *aInstance, bool aEnabled) +{ + ThreadError error = kThreadError_None; + + otLogFuncEntry(); + + if (aEnabled) + { + VerifyOrExit(aInstance->mThreadNetif.GetMac().GetPanId() != Mac::kPanIdBroadcast, + error = kThreadError_InvalidState); + error = aInstance->mThreadNetif.GetMle().Start(true); + } + else + { + error = aInstance->mThreadNetif.GetMle().Stop(true); + } + +exit: + otLogFuncExitErr(error); + return error; +} + +bool otThreadGetAutoStart(otInstance *aInstance) +{ +#if OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT + uint8_t autoStart = 0; + uint16_t autoStartLength = sizeof(autoStart); + + if (otPlatSettingsGet(aInstance, kKeyThreadAutoStart, 0, &autoStart, &autoStartLength) != kThreadError_None) + { + autoStart = 0; + } + + return autoStart != 0; +#else + (void)aInstance; + return false; +#endif +} + +ThreadError otThreadSetAutoStart(otInstance *aInstance, bool aStartAutomatically) +{ +#if OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT + uint8_t autoStart = aStartAutomatically ? 1 : 0; + return otPlatSettingsSet(aInstance, kKeyThreadAutoStart, &autoStart, sizeof(autoStart)); +#else + (void)aInstance; + (void)aStartAutomatically; + return kThreadError_NotImplemented; +#endif +} + +bool otThreadIsSingleton(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().IsSingleton(); +} + +ThreadError otThreadDiscover(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration, uint16_t aPanId, + otHandleActiveScanResult aCallback, void *aCallbackContext) +{ + return aInstance->mThreadNetif.GetMle().Discover(aScanChannels, aScanDuration, aPanId, false, + aCallback, aCallbackContext); +} + +bool otThreadIsDiscoverInProgress(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMle().IsDiscoverInProgress(); +} + +ThreadError otSendMacDataRequest(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetMeshForwarder().SendMacDataRequest(); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 171bf0fcf..a9d780997 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -66,618 +66,6 @@ using namespace Thread; extern "C" { #endif -uint8_t otGetMaxAllowedChildren(otInstance *aInstance) -{ - uint8_t aNumChildren; - - (void)aInstance->mThreadNetif.GetMle().GetChildren(&aNumChildren); - - return aNumChildren; -} - -ThreadError otSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren) -{ - return aInstance->mThreadNetif.GetMle().SetMaxAllowedChildren(aMaxChildren); -} - -uint32_t otGetChildTimeout(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetTimeout(); -} - -void otSetChildTimeout(otInstance *aInstance, uint32_t aTimeout) -{ - aInstance->mThreadNetif.GetMle().SetTimeout(aTimeout); -} - -const uint8_t *otGetExtendedPanId(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMac().GetExtendedPanId(); -} - -void otSetExtendedPanId(otInstance *aInstance, const uint8_t *aExtendedPanId) -{ - uint8_t mlPrefix[8]; - - aInstance->mThreadNetif.GetMac().SetExtendedPanId(aExtendedPanId); - - mlPrefix[0] = 0xfd; - memcpy(mlPrefix + 1, aExtendedPanId, 5); - mlPrefix[6] = 0x00; - mlPrefix[7] = 0x00; - aInstance->mThreadNetif.GetMle().SetMeshLocalPrefix(mlPrefix); -} - -ThreadError otGetLeaderRloc(otInstance *aInstance, otIp6Address *aAddress) -{ - ThreadError error; - - VerifyOrExit(aAddress != NULL, error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetMle().GetLeaderAddress(*static_cast(aAddress)); - -exit: - return error; -} - -otLinkModeConfig otGetLinkMode(otInstance *aInstance) -{ - otLinkModeConfig config; - uint8_t mode = aInstance->mThreadNetif.GetMle().GetDeviceMode(); - - memset(&config, 0, sizeof(otLinkModeConfig)); - - if (mode & Mle::ModeTlv::kModeRxOnWhenIdle) - { - config.mRxOnWhenIdle = 1; - } - - if (mode & Mle::ModeTlv::kModeSecureDataRequest) - { - config.mSecureDataRequests = 1; - } - - if (mode & Mle::ModeTlv::kModeFFD) - { - config.mDeviceType = 1; - } - - if (mode & Mle::ModeTlv::kModeFullNetworkData) - { - config.mNetworkData = 1; - } - - return config; -} - -ThreadError otSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig) -{ - uint8_t mode = 0; - - if (aConfig.mRxOnWhenIdle) - { - mode |= Mle::ModeTlv::kModeRxOnWhenIdle; - } - - if (aConfig.mSecureDataRequests) - { - mode |= Mle::ModeTlv::kModeSecureDataRequest; - } - - if (aConfig.mDeviceType) - { - mode |= Mle::ModeTlv::kModeFFD; - } - - if (aConfig.mNetworkData) - { - mode |= Mle::ModeTlv::kModeFullNetworkData; - } - - return aInstance->mThreadNetif.GetMle().SetDeviceMode(mode); -} - -const uint8_t *otGetMasterKey(otInstance *aInstance, uint8_t *aKeyLength) -{ - return aInstance->mThreadNetif.GetKeyManager().GetMasterKey(aKeyLength); -} - -ThreadError otSetMasterKey(otInstance *aInstance, const uint8_t *aKey, uint8_t aKeyLength) -{ - return aInstance->mThreadNetif.GetKeyManager().SetMasterKey(aKey, aKeyLength); -} - -const otIp6Address *otGetMeshLocalEid(otInstance *aInstance) -{ - return &aInstance->mThreadNetif.GetMle().GetMeshLocal64(); -} - -const uint8_t *otGetMeshLocalPrefix(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetMeshLocalPrefix(); -} - -ThreadError otSetMeshLocalPrefix(otInstance *aInstance, const uint8_t *aMeshLocalPrefix) -{ - return aInstance->mThreadNetif.GetMle().SetMeshLocalPrefix(aMeshLocalPrefix); -} - -const char *otGetNetworkName(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMac().GetNetworkName(); -} - -ThreadError otSetNetworkName(otInstance *aInstance, const char *aNetworkName) -{ - return aInstance->mThreadNetif.GetMac().SetNetworkName(aNetworkName); -} - -bool otIsRouterRoleEnabled(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().IsRouterRoleEnabled(); -} - -void otSetRouterRoleEnabled(otInstance *aInstance, bool aEnabled) -{ - aInstance->mThreadNetif.GetMle().SetRouterRoleEnabled(aEnabled); -} - -uint8_t otGetLocalLeaderWeight(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetLeaderWeight(); -} - -void otSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight) -{ - aInstance->mThreadNetif.GetMle().SetLeaderWeight(aWeight); -} - -uint32_t otGetLocalLeaderPartitionId(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetLeaderPartitionId(); -} - -void otSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId) -{ - return aInstance->mThreadNetif.GetMle().SetLeaderPartitionId(aPartitionId); -} - -uint16_t otGetJoinerUdpPort(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetJoinerRouter().GetJoinerUdpPort(); -} - -ThreadError otSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort) -{ - return aInstance->mThreadNetif.GetJoinerRouter().SetJoinerUdpPort(aJoinerUdpPort); -} - -uint32_t otGetContextIdReuseDelay(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetNetworkDataLeader().GetContextIdReuseDelay(); -} - -void otSetContextIdReuseDelay(otInstance *aInstance, uint32_t aDelay) -{ - aInstance->mThreadNetif.GetNetworkDataLeader().SetContextIdReuseDelay(aDelay); -} - -uint32_t otGetKeySequenceCounter(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetKeyManager().GetCurrentKeySequence(); -} - -void otSetKeySequenceCounter(otInstance *aInstance, uint32_t aKeySequenceCounter) -{ - aInstance->mThreadNetif.GetKeyManager().SetCurrentKeySequence(aKeySequenceCounter); -} - -uint32_t otGetKeySwitchGuardTime(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetKeyManager().GetKeySwitchGuardTime(); -} - -void otSetKeySwitchGuardTime(otInstance *aInstance, uint32_t aKeySwitchGuardTime) -{ - aInstance->mThreadNetif.GetKeyManager().SetKeySwitchGuardTime(aKeySwitchGuardTime); -} - -uint8_t otGetNetworkIdTimeout(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetNetworkIdTimeout(); -} - -void otSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout) -{ - aInstance->mThreadNetif.GetMle().SetNetworkIdTimeout((uint8_t)aTimeout); -} - -uint8_t otGetRouterUpgradeThreshold(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetRouterUpgradeThreshold(); -} - -void otSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold) -{ - aInstance->mThreadNetif.GetMle().SetRouterUpgradeThreshold(aThreshold); -} - -ThreadError otReleaseRouterId(otInstance *aInstance, uint8_t aRouterId) -{ - return aInstance->mThreadNetif.GetMle().ReleaseRouterId(aRouterId); -} - -ThreadError otBecomeDetached(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().BecomeDetached(); -} - -ThreadError otBecomeChild(otInstance *aInstance, otMleAttachFilter aFilter) -{ - return aInstance->mThreadNetif.GetMle().BecomeChild(aFilter); -} - -ThreadError otBecomeRouter(otInstance *aInstance) -{ - ThreadError error = kThreadError_InvalidState; - - switch (aInstance->mThreadNetif.GetMle().GetDeviceState()) - { - case Mle::kDeviceStateDisabled: - case Mle::kDeviceStateDetached: - break; - - case Mle::kDeviceStateChild: - error = aInstance->mThreadNetif.GetMle().BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest); - break; - - case Mle::kDeviceStateRouter: - case Mle::kDeviceStateLeader: - error = kThreadError_None; - break; - } - - return error; -} - -ThreadError otBecomeLeader(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().BecomeLeader(); -} - -uint8_t otGetRouterDowngradeThreshold(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetRouterDowngradeThreshold(); -} - -void otSetRouterDowngradeThreshold(otInstance *aInstance, uint8_t aThreshold) -{ - aInstance->mThreadNetif.GetMle().SetRouterDowngradeThreshold(aThreshold); -} - -uint8_t otGetRouterSelectionJitter(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetRouterSelectionJitter(); -} - -void otSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitter) -{ - aInstance->mThreadNetif.GetMle().SetRouterSelectionJitter(aRouterJitter); -} - -ThreadError otGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit(aChildInfo != NULL, error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetMle().GetChildInfoById(aChildId, *aChildInfo); - -exit: - return error; -} - -ThreadError otGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, otChildInfo *aChildInfo) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit(aChildInfo != NULL, error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetMle().GetChildInfoByIndex(aChildIndex, *aChildInfo); - -exit: - return error; -} - -ThreadError otGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit((aInfo != NULL) && (aIterator != NULL), error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetMle().GetNextNeighborInfo(*aIterator, *aInfo); - -exit: - return error; -} - -otDeviceRole otGetDeviceRole(otInstance *aInstance) -{ - otDeviceRole rval = kDeviceRoleDisabled; - - switch (aInstance->mThreadNetif.GetMle().GetDeviceState()) - { - case Mle::kDeviceStateDisabled: - rval = kDeviceRoleDisabled; - break; - - case Mle::kDeviceStateDetached: - rval = kDeviceRoleDetached; - break; - - case Mle::kDeviceStateChild: - rval = kDeviceRoleChild; - break; - - case Mle::kDeviceStateRouter: - rval = kDeviceRoleRouter; - break; - - case Mle::kDeviceStateLeader: - rval = kDeviceRoleLeader; - break; - } - - return rval; -} - -ThreadError otGetEidCacheEntry(otInstance *aInstance, uint8_t aIndex, otEidCacheEntry *aEntry) -{ - ThreadError error; - - VerifyOrExit(aEntry != NULL, error = kThreadError_InvalidArgs); - error = aInstance->mThreadNetif.GetAddressResolver().GetEntry(aIndex, *aEntry); - -exit: - return error; -} - -ThreadError otGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData) -{ - ThreadError error; - - VerifyOrExit(aLeaderData != NULL, error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetMle().GetLeaderData(*aLeaderData); - -exit: - return error; -} - -uint8_t otGetLeaderRouterId(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetLeaderRouterId(); -} - -uint8_t otGetLeaderWeight(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetWeighting(); -} - -uint32_t otGetPartitionId(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetPartitionId(); -} - -uint16_t otGetRloc16(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetRloc16(); -} - -uint8_t otGetRouterIdSequence(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().GetRouterIdSequence(); -} - -ThreadError otGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit(aRouterInfo != NULL, error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetMle().GetRouterInfo(aRouterId, *aRouterInfo); - -exit: - return error; -} - -ThreadError otGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) -{ - ThreadError error = kThreadError_None; - Router *parent; - - VerifyOrExit(aParentInfo != NULL, error = kThreadError_InvalidArgs); - - parent = aInstance->mThreadNetif.GetMle().GetParent(); - memcpy(aParentInfo->mExtAddress.m8, parent->mMacAddr.m8, OT_EXT_ADDRESS_SIZE); - - aParentInfo->mRloc16 = parent->mValid.mRloc16; - aParentInfo->mRouterId = Mle::Mle::GetRouterId(parent->mValid.mRloc16); - aParentInfo->mNextHop = parent->mNextHop; - aParentInfo->mPathCost = parent->mCost; - aParentInfo->mLinkQualityIn = parent->mLinkInfo.GetLinkQuality(aInstance->mThreadNetif.GetMac().GetNoiseFloor()); - aParentInfo->mLinkQualityOut = parent->mLinkQualityOut; - aParentInfo->mAge = static_cast(Timer::MsecToSec(Timer::GetNow() - parent->mLastHeard)); - aParentInfo->mAllocated = parent->mAllocated; - aParentInfo->mLinkEstablished = parent->mState == Neighbor::kStateValid; - -exit: - return error; -} - -ThreadError otGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) -{ - ThreadError error = kThreadError_None; - Router *parent; - - VerifyOrExit(aParentRssi != NULL, error = kThreadError_InvalidArgs); - - parent = aInstance->mThreadNetif.GetMle().GetParent(); - *aParentRssi = parent->mLinkInfo.GetAverageRss(); - - VerifyOrExit(*aParentRssi != LinkQualityInfo::kUnknownRss, error = kThreadError_Failed); - -exit: - return error; -} - -const char *otGetVersionString(void) -{ - /** - * PLATFORM_VERSION_ATTR_PREFIX and PLATFORM_VERSION_ATTR_SUFFIX are - * intended to be used to specify compiler directives to indicate - * what linker section the platform version string should be stored. - * - * This is useful for specifying an exact locaiton of where the version - * string will be located so that it can be easily retrieved from the - * raw firmware image. - * - * If PLATFORM_VERSION_ATTR_PREFIX is unspecified, the keyword `static` - * is used instead. - * - * If both are unspecified, the location of the string in the firmware - * image will be undefined and may change. - */ - -#ifdef PLATFORM_VERSION_ATTR_PREFIX - PLATFORM_VERSION_ATTR_PREFIX -#else - static -#endif - const char sVersion[] = - PACKAGE_NAME "/" PACKAGE_VERSION -#ifdef PLATFORM_INFO - "; " PLATFORM_INFO -#endif -#if defined(__DATE__) - "; " __DATE__ " " __TIME__ -#endif -#ifdef PLATFORM_VERSION_ATTR_SUFFIX - PLATFORM_VERSION_ATTR_SUFFIX -#endif - ; // Trailing semicolon to end statement. - - return sVersion; -} - -ThreadError otSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId) -{ - return aInstance->mThreadNetif.GetMle().SetPreferredRouterId(aRouterId); -} - -void otSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback, - void *aCallbackContext) -{ - aInstance->mThreadNetif.GetNetworkDiagnostic().SetReceiveDiagnosticGetCallback(aCallback, aCallbackContext); -} - -ThreadError otSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination, const uint8_t aTlvTypes[], - uint8_t aCount) -{ - return aInstance->mThreadNetif.GetNetworkDiagnostic().SendDiagnosticGet(*static_cast - (aDestination), - aTlvTypes, - aCount); -} - -ThreadError otSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination, const uint8_t aTlvTypes[], - uint8_t aCount) -{ - return aInstance->mThreadNetif.GetNetworkDiagnostic().SendDiagnosticReset(*static_cast - (aDestination), - aTlvTypes, - aCount); -} - -ThreadError otThreadStart(otInstance *aInstance) -{ - ThreadError error = kThreadError_None; - - otLogFuncEntry(); - - VerifyOrExit(aInstance->mThreadNetif.GetMac().GetPanId() != Mac::kPanIdBroadcast, error = kThreadError_InvalidState); - - error = aInstance->mThreadNetif.GetMle().Start(true); - -exit: - otLogFuncExitErr(error); - return error; -} - -ThreadError otThreadStop(otInstance *aInstance) -{ - ThreadError error = kThreadError_None; - - otLogFuncEntry(); - - error = aInstance->mThreadNetif.GetMle().Stop(true); - - otLogFuncExitErr(error); - return error; -} - -ThreadError otThreadSetAutoStart(otInstance *aInstance, bool aStartAutomatically) -{ -#if OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT - uint8_t autoStart = aStartAutomatically ? 1 : 0; - return otPlatSettingsSet(aInstance, kKeyThreadAutoStart, &autoStart, sizeof(autoStart)); -#else - (void)aInstance; - (void)aStartAutomatically; - return kThreadError_NotImplemented; -#endif -} - -bool otThreadGetAutoStart(otInstance *aInstance) -{ -#if OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT - uint8_t autoStart = 0; - uint16_t autoStartLength = sizeof(autoStart); - - if (otPlatSettingsGet(aInstance, kKeyThreadAutoStart, 0, &autoStart, &autoStartLength) != kThreadError_None) - { - autoStart = 0; - } - - return autoStart != 0; -#else - (void)aInstance; - return false; -#endif -} - -bool otIsSingleton(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().IsSingleton(); -} - -ThreadError otDiscover(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration, uint16_t aPanId, - otHandleActiveScanResult aCallback, void *aCallbackContext) -{ - return aInstance->mThreadNetif.GetMle().Discover(aScanChannels, aScanDuration, aPanId, false, aCallback, - aCallbackContext); -} - -bool otIsDiscoverInProgress(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMle().IsDiscoverInProgress(); -} - -ThreadError otSendMacDataRequest(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetMeshForwarder().SendMacDataRequest(); -} - bool otIcmp6IsEchoEnabled(otInstance *aInstance) { return aInstance->mIp6.mIcmp.IsEchoEnabled(); diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 95b809270..53a48d2ce 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -988,7 +988,7 @@ void NcpBase::UpdateChangedProps(void) { if (mRequireJoinExistingNetwork) { - switch (otGetDeviceRole(mInstance)) + switch (otThreadGetDeviceRole(mInstance)) { case kDeviceRoleDetached: case kDeviceRoleDisabled: @@ -999,14 +999,14 @@ void NcpBase::UpdateChangedProps(void) break; } - if ( (otGetDeviceRole(mInstance) == kDeviceRoleLeader) - && otIsSingleton(mInstance) + if ( (otThreadGetDeviceRole(mInstance) == kDeviceRoleLeader) + && otThreadIsSingleton(mInstance) #if OPENTHREAD_ENABLE_LEGACY && !mLegacyNodeDidJoin #endif ) { mChangedFlags &= ~static_cast(OT_NET_PARTITION_ID); - otThreadStop(mInstance); + otThreadSetEnabled(mInstance, false); // TODO: It would be nice to be able to indicate // something more specific than SPINEL_STATUS_JOIN_FAILURE @@ -1524,7 +1524,7 @@ ThreadError NcpBase::CommandHandler_RESET(uint8_t header, unsigned int command, // platform doesn't support resetting. // In such a case we fake it. - otThreadStop(mInstance); + otThreadSetEnabled(mInstance, false); otIp6SetEnabled(mInstance, false); errorCode = SendLastStatus(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_STATUS_RESET_SOFTWARE); @@ -2077,7 +2077,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_STACK_UP(uint8_t header, spinel_prop SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_BOOL_S, - otGetDeviceRole(mInstance) != kDeviceRoleDisabled + otThreadGetDeviceRole(mInstance) != kDeviceRoleDisabled ); } @@ -2085,7 +2085,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_ROLE(uint8_t header, spinel_prop_key { spinel_net_role_t role(SPINEL_NET_ROLE_DETACHED); - switch (otGetDeviceRole(mInstance)) + switch (otThreadGetDeviceRole(mInstance)) { case kDeviceRoleOffline: case kDeviceRoleDisabled: @@ -2122,7 +2122,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_NETWORK_NAME(uint8_t header, spinel_ SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UTF8_S, - otGetNetworkName(mInstance) + otThreadGetNetworkName(mInstance) ); } @@ -2133,7 +2133,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_XPANID(uint8_t header, spinel_prop_k SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_DATA_S, - otGetExtendedPanId(mInstance), + otThreadGetExtendedPanId(mInstance), sizeof(spinel_net_xpanid_t) ); } @@ -2143,7 +2143,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_MASTER_KEY(uint8_t header, spinel_pr const uint8_t *ptr(NULL); uint8_t len(0); - ptr = otGetMasterKey(mInstance, &len); + ptr = otThreadGetMasterKey(mInstance, &len); return SendPropertyUpdate( header, @@ -2162,7 +2162,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_KEY_SEQUENCE_COUNTER(uint8_t header, SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT32_S, - otGetKeySequenceCounter(mInstance) + otThreadGetKeySequenceCounter(mInstance) ); } @@ -2173,7 +2173,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_PARTITION_ID(uint8_t header, spinel_ SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT32_S, - otGetPartitionId(mInstance) + otThreadGetPartitionId(mInstance) ); } @@ -2184,7 +2184,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_KEY_SWITCH_GUARDTIME(uint8_t header, SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT32_S, - otGetKeySwitchGuardTime(mInstance) + otThreadGetKeySwitchGuardTime(mInstance) ); } @@ -2305,7 +2305,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LEADER_RID(uint8_t header, spinel SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetLeaderRouterId(mInstance) + otThreadGetLeaderRouterId(mInstance) ); } @@ -2316,7 +2316,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT(uint8_t heade SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetLocalLeaderWeight(mInstance) + otThreadGetLocalLeaderWeight(mInstance) ); } @@ -2327,7 +2327,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LEADER_WEIGHT(uint8_t header, spi SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetLeaderWeight(mInstance) + otThreadGetLeaderWeight(mInstance) ); } @@ -2336,7 +2336,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LEADER_ADDR(uint8_t header, spine ThreadError errorCode = kThreadError_None; otIp6Address address; - errorCode = otGetLeaderRloc(mInstance, &address); + errorCode = otThreadGetLeaderRloc(mInstance, &address); if (errorCode == kThreadError_None) { @@ -2361,7 +2361,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_PARENT(uint8_t header, spinel_pro ThreadError errorCode = kThreadError_None; otRouterInfo parentInfo; - errorCode = otGetParentInfo(mInstance, &parentInfo); + errorCode = otThreadGetParentInfo(mInstance, &parentInfo); if (errorCode == kThreadError_None) { @@ -2394,11 +2394,11 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_CHILD_TABLE(uint8_t header, spine SuccessOrExit(errorCode = OutboundFrameBegin()); SuccessOrExit(errorCode = OutboundFrameFeedPacked("Cii", header, SPINEL_CMD_PROP_VALUE_IS, key)); - maxChildren = otGetMaxAllowedChildren(mInstance); + maxChildren = otThreadGetMaxAllowedChildren(mInstance); for (uint8_t index = 0; index < maxChildren; index++) { - errorCode = otGetChildInfoByIndex(mInstance, index, &childInfo); + errorCode = otThreadGetChildInfoByIndex(mInstance, index, &childInfo); if (errorCode != kThreadError_None) { @@ -2469,7 +2469,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_NEIGHBOR_TABLE(uint8_t header, sp SuccessOrExit(errorCode = OutboundFrameBegin()); SuccessOrExit(errorCode = OutboundFrameFeedPacked("Cii", header, SPINEL_CMD_PROP_VALUE_IS, key)); - while (otGetNextNeighborInfo(mInstance, &iter, &neighInfo) == kThreadError_None) + while (otThreadGetNextNeighborInfo(mInstance, &iter, &neighInfo) == kThreadError_None) { modeFlags = 0; @@ -2563,7 +2563,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(uint8_t heade SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_BOOL_S, - otIsRouterRoleEnabled(mInstance) + otThreadIsRouterRoleEnabled(mInstance) ); } @@ -2645,7 +2645,7 @@ exit: ThreadError NcpBase::GetPropertyHandler_IPV6_ML_PREFIX(uint8_t header, spinel_prop_key_t key) { ThreadError errorCode = kThreadError_None; - const uint8_t *ml_prefix = otGetMeshLocalPrefix(mInstance); + const uint8_t *ml_prefix = otThreadGetMeshLocalPrefix(mInstance); if (ml_prefix) { @@ -2681,7 +2681,7 @@ ThreadError NcpBase::GetPropertyHandler_IPV6_ML_PREFIX(uint8_t header, spinel_pr ThreadError NcpBase::GetPropertyHandler_IPV6_ML_ADDR(uint8_t header, spinel_prop_key_t key) { ThreadError errorCode = kThreadError_None; - const otIp6Address *ml64 = otGetMeshLocalEid(mInstance); + const otIp6Address *ml64 = otThreadGetMeshLocalEid(mInstance); if (ml64) { @@ -3183,7 +3183,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_WHITELIST_ENABLED(uint8_t header, sp ThreadError NcpBase::GetPropertyHandler_THREAD_MODE(uint8_t header, spinel_prop_key_t key) { uint8_t numeric_mode(0); - otLinkModeConfig mode_config(otGetLinkMode(mInstance)); + otLinkModeConfig mode_config(otThreadGetLinkMode(mInstance)); if (mode_config.mRxOnWhenIdle) { @@ -3221,7 +3221,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_CHILD_COUNT_MAX(uint8_t header, s SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetMaxAllowedChildren(mInstance) + otThreadGetMaxAllowedChildren(mInstance) ); } @@ -3232,7 +3232,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_CHILD_TIMEOUT(uint8_t header, spi SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT32_S, - otGetChildTimeout(mInstance) + otThreadGetChildTimeout(mInstance) ); } @@ -3243,7 +3243,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_RLOC16(uint8_t header, spinel_pro SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT16_S, - otGetRloc16(mInstance) + otThreadGetRloc16(mInstance) ); } @@ -3254,7 +3254,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD(uint8_t SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetRouterUpgradeThreshold(mInstance) + otThreadGetRouterUpgradeThreshold(mInstance) ); } @@ -3265,7 +3265,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ROUTER_DOWNGRADE_THRESHOLD(uint8_ SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetRouterDowngradeThreshold(mInstance) + otThreadGetRouterDowngradeThreshold(mInstance) ); } @@ -3276,7 +3276,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ROUTER_SELECTION_JITTER(uint8_t h SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetRouterSelectionJitter(mInstance) + otThreadGetRouterSelectionJitter(mInstance) ); } @@ -3287,7 +3287,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(uint8_t heade SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT32_S, - otGetContextIdReuseDelay(mInstance) + otThreadGetContextIdReuseDelay(mInstance) ); } @@ -3298,7 +3298,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(uint8_t header SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_UINT8_S, - otGetNetworkIdTimeout(mInstance) + otThreadGetNetworkIdTimeout(mInstance) ); } @@ -4021,11 +4021,11 @@ ThreadError NcpBase::SetPropertyHandler_NET_STACK_UP(uint8_t header, spinel_prop if (parsedLength > 0) { // If the value has changed... - if ((value != false) != (otGetDeviceRole(mInstance) != kDeviceRoleDisabled)) + if ((value != false) != (otThreadGetDeviceRole(mInstance) != kDeviceRoleDisabled)) { if (value != false) { - errorCode = otThreadStart(mInstance); + errorCode = otThreadSetEnabled(mInstance, true); #if OPENTHREAD_ENABLE_LEGACY mLegacyNodeDidJoin = false; @@ -4040,7 +4040,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_STACK_UP(uint8_t header, spinel_prop } else { - errorCode = otThreadStop(mInstance); + errorCode = otThreadSetEnabled(mInstance, false); #if OPENTHREAD_ENABLE_LEGACY mLegacyNodeDidJoin = false; @@ -4091,19 +4091,19 @@ ThreadError NcpBase::SetPropertyHandler_NET_ROLE(uint8_t header, spinel_prop_key switch (i) { case SPINEL_NET_ROLE_DETACHED: - errorCode = otBecomeDetached(mInstance); + errorCode = otThreadBecomeDetached(mInstance); break; case SPINEL_NET_ROLE_ROUTER: - errorCode = otBecomeRouter(mInstance); + errorCode = otThreadBecomeRouter(mInstance); break; case SPINEL_NET_ROLE_LEADER: - errorCode = otBecomeLeader(mInstance); + errorCode = otThreadBecomeLeader(mInstance); break; case SPINEL_NET_ROLE_CHILD: - errorCode = otBecomeChild(mInstance, kMleAttachAnyPartition); + errorCode = otThreadBecomeChild(mInstance, kMleAttachAnyPartition); break; } @@ -4141,7 +4141,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_NETWORK_NAME(uint8_t header, spinel_ if ((parsedLength > 0) && (string != NULL)) { - errorCode = otSetNetworkName(mInstance, string); + errorCode = otThreadSetNetworkName(mInstance, string); if (errorCode == kThreadError_None) { @@ -4178,7 +4178,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_XPANID(uint8_t header, spinel_prop_k if ((parsedLength > 0) && (len == sizeof(spinel_net_xpanid_t))) { - otSetExtendedPanId(mInstance, ptr); + otThreadSetExtendedPanId(mInstance, ptr); errorCode = HandleCommandPropertyGet(header, key); } else @@ -4207,7 +4207,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_MASTER_KEY(uint8_t header, spinel_pr if ((parsedLength > 0) && (len < 100)) { - errorCode = otSetMasterKey(mInstance, ptr, static_cast(len)); + errorCode = otThreadSetMasterKey(mInstance, ptr, static_cast(len)); if (errorCode == kThreadError_None) { @@ -4243,7 +4243,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_KEY_SEQUENCE_COUNTER(uint8_t header, if (parsedLength > 0) { - otSetKeySequenceCounter(mInstance, i); + otThreadSetKeySequenceCounter(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } else @@ -4271,7 +4271,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_KEY_SWITCH_GUARDTIME(uint8_t header, if (parsedLength > 0) { - otSetKeySwitchGuardTime(mInstance, i); + otThreadSetKeySwitchGuardTime(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } else @@ -4298,7 +4298,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT(uint8_t heade if (parsedLength > 0) { - otSetLocalLeaderWeight(mInstance, value); + otThreadSetLocalLeaderWeight(mInstance, value); } else { @@ -4470,7 +4470,7 @@ ThreadError NcpBase::SetPropertyHandler_IPV6_ML_PREFIX(uint8_t header, spinel_pr if (value_len >= 8) { - errorCode = otSetMeshLocalPrefix(mInstance, value_ptr); + errorCode = otThreadSetMeshLocalPrefix(mInstance, value_ptr); HandleCommandPropertyGet(header, key); } else @@ -4684,7 +4684,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(uint8_t heade if (parsedLength > 0) { - otSetRouterRoleEnabled(mInstance, isEnabled); + otThreadSetRouterRoleEnabled(mInstance, isEnabled); errorCode = HandleCommandPropertyGet(header, key); } @@ -5010,7 +5010,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_MODE(uint8_t header, spinel_prop_ mode_config.mDeviceType = ((numeric_mode & kThreadMode_FullFunctionDevice) == kThreadMode_FullFunctionDevice); mode_config.mNetworkData = ((numeric_mode & kThreadMode_FullNetworkData) == kThreadMode_FullNetworkData); - errorCode = otSetLinkMode(mInstance, mode_config); + errorCode = otThreadSetLinkMode(mInstance, mode_config); if (errorCode == kThreadError_None) { @@ -5045,7 +5045,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_CHILD_COUNT_MAX(uint8_t header, s if (parsedLength > 0) { - otSetMaxAllowedChildren(mInstance, n); + otThreadSetMaxAllowedChildren(mInstance, n); errorCode = HandleCommandPropertyGet(header, key); } @@ -5073,7 +5073,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_CHILD_TIMEOUT(uint8_t header, spi if (parsedLength > 0) { - otSetChildTimeout(mInstance, i); + otThreadSetChildTimeout(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } @@ -5101,7 +5101,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD(uint8_t if (parsedLength > 0) { - otSetRouterUpgradeThreshold(mInstance, i); + otThreadSetRouterUpgradeThreshold(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } @@ -5129,7 +5129,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ROUTER_DOWNGRADE_THRESHOLD(uint8_ if (parsedLength > 0) { - otSetRouterDowngradeThreshold(mInstance, i); + otThreadSetRouterDowngradeThreshold(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } @@ -5157,7 +5157,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ROUTER_SELECTION_JITTER(uint8_t h if (parsedLength > 0) { - otSetRouterSelectionJitter(mInstance, i); + otThreadSetRouterSelectionJitter(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } @@ -5185,7 +5185,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_PREFERRED_ROUTER_ID(uint8_t heade if (parsedLength > 0) { - errorCode = otSetPreferredRouterId(mInstance, router_id); + errorCode = otThreadSetPreferredRouterId(mInstance, router_id); if (errorCode == kThreadError_None) { @@ -5226,7 +5226,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(uint8_t heade if (parsedLength > 0) { - otSetContextIdReuseDelay(mInstance, i); + otThreadSetContextIdReuseDelay(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } @@ -5254,7 +5254,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(uint8_t header if (parsedLength > 0) { - otSetNetworkIdTimeout(mInstance, i); + otThreadSetNetworkIdTimeout(mInstance, i); errorCode = HandleCommandPropertyGet(header, key); } @@ -6192,7 +6192,7 @@ ThreadError NcpBase::RemovePropertyHandler_THREAD_ACTIVE_ROUTER_IDS(uint8_t head if (parsedLength > 0) { - errorCode = otReleaseRouterId(mInstance, router_id); + errorCode = otThreadReleaseRouterId(mInstance, router_id); if (errorCode == kThreadError_None) { @@ -6260,7 +6260,7 @@ void NcpBase::RegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers) VerifyOrExit(mLegacyHandlers != NULL, ;); - isEnabled = (otGetDeviceRole(mInstance) != kDeviceRoleDisabled); + isEnabled = (otThreadGetDeviceRole(mInstance) != kDeviceRoleDisabled); if (isEnabled) { diff --git a/tests/unit/test_fuzz.cpp b/tests/unit/test_fuzz.cpp index 520299030..7a3070cae 100644 --- a/tests/unit/test_fuzz.cpp +++ b/tests/unit/test_fuzz.cpp @@ -132,7 +132,7 @@ void TestFuzz(uint32_t aSeconds) // Start the Thread network otLinkSetPanId(aInstance, (otPanId)0xFACE); otIp6SetEnabled(aInstance, true); - otThreadStart(aInstance); + otThreadSetEnabled(aInstance, true); uint32_t countRecv = 0;