Initial commit

This commit is contained in:
Jonathan Hui
2016-05-10 22:49:53 -07:00
commit 4f9945c533
1335 changed files with 616850 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 includes the platform abstraction for AES ECB computations.
*/
#ifndef AES_ECB_H_
#define AES_ECB_H_
#include <stdint.h>
#include <openthread-types.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup core-security
*
* @{
*
*/
enum
{
otAesBlockSize = 16, ///< AES-128 block size.
};
/**
* This method sets the key.
*
* @param[in] aKey A pointer to the key.
* @param[in] aKeyLength Length of the key in bytes.
*
*/
void otCryptoAesEcbSetKey(const void *aKey, uint16_t aKeyLength);
/**
* This method encrypts data.
*
* @param[in] aInput A pointer to the input.
* @param[out] aOutput A pointer to the output.
*
*/
void otCryptoAesEcbEncrypt(const uint8_t aInput[otAesBlockSize], uint8_t aOutput[otAesBlockSize]);
/**
* @}
*
*/
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // AES_ECB_H_
+90
View File
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 includes the platform abstraction for HMAC SHA-256 computations.
*/
#ifndef HMAC_SHA256_H_
#define HMAC_SHA256_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup core-security
*
* @{
*
*/
enum
{
otCryptoSha256Size = 32, ///< SHA-256 hash size (bytes)
};
/**
* This method sets the key.
*
* @param[in] aKey A pointer to the key.
* @param[in] aKeyLength The key length in bytes.
*
*/
void otCryptoHmacSha256Start(const void *aKey, uint16_t aKeyLength);
/**
* This method inputs bytes into the HMAC computation.
*
* @param[in] aBuf A pointer to the input buffer.
* @param[in] aBufLength The length of @p aBuf in bytes.
*
*/
void otCryptoHmacSha256Update(const void *aBuf, uint16_t aBufLength);
/**
* This method finalizes the hash computation.
*
* @param[out] aHash A pointer to the output buffer.
*
*/
void otCryptoHmacSha256Finish(uint8_t aHash[otCryptoSha256Size]);
/**
* @}
*
*/
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // HMAC_SHA256_H_
+378
View File
@@ -0,0 +1,378 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 types and structures used in the OpenThread library API.
*/
#ifndef OPENTHREAD_TYPES_H_
#define OPENTHREAD_TYPES_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* This enumeration represents error codes used throughout OpenThread.
*/
typedef enum ThreadError
{
kThreadError_None = 0,
kThreadError_Failed = 1,
kThreadError_Drop = 2,
kThreadError_NoBufs = 3,
kThreadError_NoRoute = 4,
kThreadError_Busy = 5,
kThreadError_Parse = 6,
kThreadError_InvalidArgs = 7,
kThreadError_Security = 8,
kThreadError_AddressQuery = 9,
kThreadError_NoAddress = 10,
kThreadError_NotReceiving = 11,
kThreadError_Abort = 12,
kThreadError_NotImplemented = 13,
kThreadError_InvalidState = 14,
kThreadError_NoTasklets = 15,
kThreadError_Error = 255,
} ThreadError;
/**
* @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 rols.
*
* @{
*
*/
#define OT_NETWORK_NAME_SIZE 16 ///< Network name size (bytes).
/**
* This structure represents an MLE Link Mode configuration.
*/
typedef struct otLinkModeConfig
{
/**
* 1, if the sender has its receiver on when not transmitting. 0, otherwise.
*/
uint8_t mRxOnWhenIdle : 1;
/**
* 1, if the sender will use IEEE 802.15.4 to secure all data requests. 0, otherwise.
*/
uint8_t mSecureDataRequests : 1;
/**
* 1, if the sender is an FFD. 0, otherwise.
*/
uint8_t mDeviceType : 1;
/**
* 1, if the sender requires the full Network Data. 0, otherwise.
*/
uint8_t mNetworkData : 1;
} otLinkModeConfig;
/**
* @}
*/
/**
* @defgroup config-br Border Router
*
* @brief
* This module includes functions that manage configuration parameters that apply to the Thread Border Router role.
*
* @{
*
*/
enum
{
kIp6AddressSize = 16,
};
/**
* This structure represents an IPv6 address.
*/
typedef struct otIp6Address
{
union
{
uint8_t m8[kIp6AddressSize];
uint16_t m16[kIp6AddressSize / sizeof(uint16_t)];
uint32_t m32[kIp6AddressSize / sizeof(uint32_t)];
};
} __attribute__((packed)) otIp6Address;
/**
* This structure represents an IPv6 prefix.
*/
typedef struct otIp6Prefix
{
otIp6Address mPrefix; ///< The IPv6 prefix.
uint8_t mLength; ///< The IPv6 prefix length.
} otIp6Prefix;
/**
* This structure represents a Border Router configuration.
*/
typedef struct otBorderRouterConfig
{
/**
* TRUE, if this border router is a DHCPv6 Agent that supplies other configuration data. FALSE, otherwise.
*/
otIp6Prefix mPrefix;
/**
* A 2-bit signed integer indicating router preference as defined in RFC 4291.
*/
int8_t mPreference : 2;
/**
* TRUE, if @p mPrefix is preferred and should e used for address autoconfiguration. FALSE, otherwise.
*/
uint8_t mSlaacPreferred : 1;
/**
* TRUE, if @p mPrefix is valid and should be used for address autoconfiguration. FALSE, otherwise.
*/
uint8_t mSlaacValid : 1;
/**
* TRUE, if this border router is a DHCPv6 Agent that supplies IPv6 address configuration. FALSE, otherwise.
*/
uint8_t mDhcp : 1;
/**
* TRUE, if this border router is a DHCPv6 Agent that supplies other configuration data. FALSE, otherwise.
*/
uint8_t mConfigure : 1;
/**
* TRUE, if this border router is a default route for @p mPrefix. FALSE, otherwise.
*/
uint8_t mDefaultRoute : 1;
/**
* TRUE, if this configuration is considered Stable Network Data. FALSE, otherwise.
*/
uint8_t mStable : 1;
} otBorderRouterConfig;
/**
* This structure represents an External Route configuration.
*/
typedef struct otExternalRouteConfig
{
/**
* The prefix for the off-mesh route.
*/
otIp6Prefix mPrefix;
/**
* A 2-bit signed integer indicating router preference as defined in RFC 4291.
*/
int8_t mPreference : 2;
/**
* TRUE, if this configuration is considered Stable Network Data. FALSE, otherwise.
*/
uint8_t mStable : 1;
} otExternalRouteConfig;
/**
* @}
*
*/
/**
* @defgroup config-test Test
*
* @brief
* This module includes functions that manage configuration parameters required for Thread Certification testing.
*
* @{
*
*/
/**
* Represents any restrictions on the attach process.
*/
typedef enum otMleAttachFilter
{
kMleAttachAnyPartition = 0, ///< Attach to any Thread partition.
kMleAttachSamePartition = 1, ///< Attach to the same Thread partition.
kMleAttachBetterPartition = 2, ///< Attach to a better (i.e. higher weight/partition id) Thread partition.
} otMleAttachFilter;
/**
* @}
*
*/
/**
* @}
*
*/
/**
* @addtogroup diags Diagnostics
*
* @brief
* This module includes functions that expose internal state.
*
* @{
*
*/
/**
* Represents a Thread device role.
*/
enum otDeviceRole
{
kDeviceRoleDisabled, ///< The Thread stack is disabled.
kDeviceRoleDetached, ///< Not currently participating in a Thread network/partition.
kDeviceRoleChild, ///< The Thread Child role.
kDeviceRoleRouter, ///< The Thread Router role.
kDeviceRoleLeader, ///< The Thread Leader role.
};
/**
* @}
*
*/
/**
* This structure represents an IPv6 network interface address.
*
*/
typedef struct otNetifAddress
{
otIp6Address mAddress; ///< The IPv6 address.
uint32_t mPreferredLifetime; ///< The Preferred Lifetime.
uint32_t mValidLifetime; ///< The Valid lifetime.
uint8_t mPrefixLength; ///< The Prefix length.
struct otNetifAddress *mNext; ///< A pointer to the next network interface address.
} otNetifAddress;
/**
* @addtogroup messages Message Buffers
*
* @brief
* This module includes functions that manipulate OpenThread message buffers
*
* @{
*
*/
/**
* This type points to an OpenThread message buffer.
*/
typedef void *otMessage;
/**
* @}
*
*/
/**
* @addtogroup udp UDP
*
* @brief
* This module includes functions that control UDP communication.
*
* @{
*
*/
/**
* This structure represents an IPv6 socket address.
*/
typedef struct otSockAddr
{
otIp6Address mAddress; ///< An IPv6 address.
uint16_t mPort; ///< A transport-layer port.
uint8_t mScopeId; ///< An IPv6 scope identifier.
} otSockAddr;
/**
* This structure represents the local and peer IPv6 socket addresses.
*/
typedef struct otMessageInfo
{
otIp6Address mSockAddr; ///< The local IPv6 address.
otIp6Address mPeerAddr; ///< The peer IPv6 address.
uint16_t mSockPort; ///< The local transport-layer port.
uint16_t mPeerPort; ///< The peer transport-layer port.
uint8_t mInterfaceId; ///< An IPv6 interface identifier.
uint8_t mHopLimit; ///< The IPv6 Hop Limit.
const void *mLinkInfo; ///< A pointer to link-specific information.
} otMessageInfo;
/**
* This callback allows OpenThread to inform the application of a received UDP message.
*/
typedef void (*otUdpReceive)(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
/**
* This structure represents a UDP socket.
*/
typedef struct otUdpSocket
{
otSockAddr mSockName; ///< The local IPv6 socket address.
otSockAddr mPeerName; ///< The peer IPv6 socket address.
otUdpReceive mHandler; ///< A function pointer to the application callback.
void *mContext; ///< A pointer to application-specific context.
struct otUdpSocket *mNext; ///< A pointer to the next UDP socket.
} otUdpSocket;
/**
* @}
*
*/
#ifdef __cplusplus
} // extern "C"
#endif
#endif // OPENTHREAD_TYPES_H_
+1039
View File
File diff suppressed because it is too large Load Diff
+93
View File
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 includes the platform abstraction for the alarm service.
*/
#ifndef ALARM_H_
#define ALARM_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup alarm Alarm
* @ingroup platform
*
* @brief
* This module includes the platform abstraction for the alarm service.
*
* @{
*
*/
/**
* Initialize the Alarm.
*/
void otPlatAlarmInit(void);
/**
* Set the alarm to fire at @p aDt milliseconds after @p aT0.
*
* @param[in] aT0 The reference time.
* @param[in] aDt The time delay in milliseconds from @p aT0.
*/
void otPlatAlarmStartAt(uint32_t aT0, uint32_t aDt);
/**
* Stop the alarm.
*/
void otPlatAlarmStop(void);
/**
* Get the current current time.
*
* @returns The current time in milliseconds.
*/
uint32_t otPlatAlarmGetNow(void);
/**
* Signal that the alarm has fired.
*/
extern void otPlatAlarmSignalFired(void);
/**
* @}
*
*/
#ifdef __cplusplus
} // extern "C"
#endif
#endif // ALARM_H_
+73
View File
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 includes the platform abstraction to support critical sections.
*/
#ifndef ATOMIC_H_
#define ATOMIC_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup atomic Atomic
* @ingroup platform
*
* @brief
* This module includes the platform abstraction to support critical sections.
*
* @{
*
*/
/**
* Begin critical section.
*/
uint32_t otPlatAtomicBegin();
/**
* End critical section.
*/
void otPlatAtomicEnd(uint32_t state);
/**
* @}
*
*/
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // ATOMIC_H_
+583
View File
@@ -0,0 +1,583 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 includes the platform abstraction for the debug log service.
*/
#ifndef LOGGING_H_
#define LOGGING_H_
#include <stdint.h>
#include <openthread-core-config.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup logging Logging
* @ingroup platform
*
* @brief
* This module includes the platform abstraction for the debug log service.
*
* @{
*
*/
#define OPENTHREAD_LOG_LEVEL_NONE 0
#define OPENTHREAD_LOG_LEVEL_CRIT 1
#define OPENTHREAD_LOG_LEVEL_WARN 2
#define OPENTHREAD_LOG_LEVEL_INFO 3
#define OPENTHREAD_LOG_LEVEL_DEBG 4
/**
* This enum represents different log levels.
*
*/
typedef enum otLogLevel
{
kLogLevelNone = OPENTHREAD_LOG_LEVEL_NONE, ///< None
kLogLevelCrit = OPENTHREAD_LOG_LEVEL_CRIT, ///< Critical
kLogLevelWarn = OPENTHREAD_LOG_LEVEL_WARN, ///< Warning
kLogLevelInfo = OPENTHREAD_LOG_LEVEL_INFO, ///< Info
kLogLevelDebg = OPENTHREAD_LOG_LEVEL_DEBG, ///< Debug
} otLogLevel;
/**
* This enum represents log regions.
*
*/
typedef enum otLogRegion
{
kLogRegionApi = 1, ///< OpenThread API
kLogRegionMle = 2, ///< MLE
kLogRegionArp = 3, ///< EID-to-RLOC mapping.
kLogRegionNetData = 4, ///< Network Data
kLogRegionIcmp = 5, ///< ICMPv6
kLogRegionIp6 = 6, ///< IPv6
kLogRegionMac = 7, ///< IEEE 802.15.4 MAC
kLogRegionMem = 8, ///< Memory
} otLogRegion;
/**
* This function outputs logs.
*
* @param[in] aLogLevel The log level.
* @param[in] aLogRegion The log region.
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...);
/**
* @def otLogCrit
*
* Logging at log level critical.
*
* @param[in] aRegion The log region.
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#if OPENTHREAD_CONFIG_LOG_LEVEL >= OPENTHREAD_LOG_LEVEL_CRIT
#define otLogCrit(aRegion, aFormat, ...) otPlatLog(kLogLevelCrit, aRegion, aFormat, ## __VA_ARGS__)
#else
#define otLogCrit(aRegion, aFormat, ...)
#endif
/**
* @def otLogWarn
*
* Logging at log level warning.
*
* @param[in] aRegion The log region.
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#if OPENTHREAD_CONFIG_LOG_LEVEL >= OPENTHREAD_LOG_LEVEL_WARN
#define otLogWarn(aRegion, aFormat, ...) otPlatLog(kLogLevelWarn, aRegion, aFormat, ## __VA_ARGS__)
#else
#define otLogWarn(aRegion, aFormat, ...)
#endif
/**
* @def otLogInfo
*
* Logging at log level info.
*
* @param[in] aRegion The log region.
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#if OPENTHREAD_CONFIG_LOG_LEVEL >= OPENTHREAD_LOG_LEVEL_INFO
#define otLogInfo(aRegion, aFormat, ...) otPlatLog(kLogLevelInfo, aRegion, aFormat, ## __VA_ARGS__)
#else
#define otLogInfo(aRegion, aFormat, ...)
#endif
/**
* @def otLogDebg
*
* Logging at log level debug.
*
* @param[in] aRegion The log region.
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#if OPENTHREAD_CONFIG_LOG_LEVEL >= OPENTHREAD_LOG_LEVEL_DEBG
#define otLogDebg(aRegion, aFormat, ...) otPlatLog(kLogLevelDebg, aRegion, aFormat, ## __VA_ARGS__)
#else
#define otLogDebg(aRegion, aFormat, ...)
#endif
/**
* @def otLogCritApi
*
* This method generates a log with level critical for the API region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnApi
*
* This method generates a log with level warning for the API region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoApi
*
* This method generates a log with level info for the API region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgApi
*
* This method generates a log with level debug for the API region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_API
#define otLogCritApi(aFormat, ...) otLogCrit(kLogRegionApi, aFormat, ## __VA_ARGS__)
#define otLogWarnApi(aFormat, ...) otLogWarn(kLogRegionApi, aFormat, ## __VA_ARGS__)
#define otLogInfoApi(aFormat, ...) otLogInfo(kLogRegionApi, aFormat, ## __VA_ARGS__)
#define otLogDebgApi(aFormat, ...) otLogDebg(kLogRegionApi, aFormat, ## __VA_ARGS__)
#else
#define otLogCritApi(aFormat, ...)
#define otLogWarnApi(aFormat, ...)
#define otLogInfoApi(aFormat, ...)
#define otLogDebgApi(aFormat, ...)
#endif
/**
* @def otLogCritMle
*
* This method generates a log with level critical for the MLE region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnMle
*
* This method generates a log with level warning for the MLE region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoMle
*
* This method generates a log with level info for the MLE region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgMle
*
* This method generates a log with level debug for the MLE region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_MLE
#define otLogCritMle(aFormat, ...) otLogCrit(kLogRegionMle, aFormat, ## __VA_ARGS__)
#define otLogWarnMle(aFormat, ...) otLogWarn(kLogRegionMle, aFormat, ## __VA_ARGS__)
#define otLogInfoMle(aFormat, ...) otLogInfo(kLogRegionMle, aFormat, ## __VA_ARGS__)
#define otLogDebgMle(aFormat, ...) otLogDebg(kLogRegionMle, aFormat, ## __VA_ARGS__)
#else
#define otLogCritMle(aFormat, ...)
#define otLogWarnMle(aFormat, ...)
#define otLogInfoMle(aFormat, ...)
#define otLogDebgMle(aFormat, ...)
#endif
/**
* @def otLogCritArp
*
* This method generates a log with level critical for the EID-to-RLOC mapping region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnArp
*
* This method generates a log with level warning for the EID-to-RLOC mapping region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoArp
*
* This method generates a log with level info for the EID-to-RLOC mapping region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgArp
*
* This method generates a log with level debug for the EID-to-RLOC mapping region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_ARP
#define otLogCritArp(aFormat, ...) otLogCrit(kLogRegionArp, aFormat, ## __VA_ARGS__)
#define otLogWarnArp(aFormat, ...) otLogWarn(kLogRegionArp, aFormat, ## __VA_ARGS__)
#define otLogInfoArp(aFormat, ...) otLogInfo(kLogRegionArp, aFormat, ## __VA_ARGS__)
#define otLogDebgArp(aFormat, ...) otLogDebg(kLogRegionArp, aFormat, ## __VA_ARGS__)
#else
#define otLogCritArp(aFormat, ...)
#define otLogWarnArp(aFormat, ...)
#define otLogInfoArp(aFormat, ...)
#define otLogDebgArp(aFormat, ...)
#endif
/**
* @def otLogCritNetData
*
* This method generates a log with level critical for the Network Data region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnNetData
*
* This method generates a log with level warning for the Network Data region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoNetData
*
* This method generates a log with level info for the Network Data region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgNetData
*
* This method generates a log with level debug for the Network Data region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_NETDATA
#define otLogCritNetData(aFormat, ...) otLogCrit(kLogRegionNetData, aFormat, ## __VA_ARGS__)
#define otLogWarnNetData(aFormat, ...) otLogWarn(kLogRegionNetData, aFormat, ## __VA_ARGS__)
#define otLogInfoNetData(aFormat, ...) otLogInfo(kLogRegionNetData, aFormat, ## __VA_ARGS__)
#define otLogDebgNetData(aFormat, ...) otLogDebg(kLogRegionNetData, aFormat, ## __VA_ARGS__)
#else
#define otLogCritNetData(aFormat, ...)
#define otLogWarnNetData(aFormat, ...)
#define otLogInfoNetData(aFormat, ...)
#define otLogDebgNetData(aFormat, ...)
#endif
/**
* @def otLogCritIcmp
*
* This method generates a log with level critical for the ICMPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnIcmp
*
* This method generates a log with level warning for the ICMPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoIcmp
*
* This method generates a log with level info for the ICMPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgIcmp
*
* This method generates a log with level debug for the ICMPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_ICMP
#define otLogCritIcmp(aFormat, ...) otLogCrit(kLogRegionIcmp, aFormat, ## __VA_ARGS__)
#define otLogWarnIcmp(aFormat, ...) otLogWarn(kLogRegionIcmp, aFormat, ## __VA_ARGS__)
#define otLogInfoIcmp(aFormat, ...) otLogInfo(kLogRegionIcmp, aFormat, ## __VA_ARGS__)
#define otLogDebgIcmp(aFormat, ...) otLogDebg(kLogRegionIcmp, aFormat, ## __VA_ARGS__)
#else
#define otLogCritIcmp(aFormat, ...)
#define otLogWarnIcmp(aFormat, ...)
#define otLogInfoIcmp(aFormat, ...)
#define otLogDebgIcmp(aFormat, ...)
#endif
/**
* @def otLogCritIp6
*
* This method generates a log with level critical for the IPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnIp6
*
* This method generates a log with level warning for the IPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoIp6
*
* This method generates a log with level info for the IPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgIp6
*
* This method generates a log with level debug for the IPv6 region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_IP6
#define otLogCritIp6(aFormat, ...) otLogCrit(kLogRegionIp6, aFormat, ## __VA_ARGS__)
#define otLogWarnIp6(aFormat, ...) otLogWarn(kLogRegionIp6, aFormat, ## __VA_ARGS__)
#define otLogInfoIp6(aFormat, ...) otLogInfo(kLogRegionIp6, aFormat, ## __VA_ARGS__)
#define otLogDebgIp6(aFormat, ...) otLogDebg(kLogRegionIp6, aFormat, ## __VA_ARGS__)
#else
#define otLogCritIp6(aFormat, ...)
#define otLogWarnIp6(aFormat, ...)
#define otLogInfoIp6(aFormat, ...)
#define otLogDebgIp6(aFormat, ...)
#endif
/**
* @def otLogCritMac
*
* This method generates a log with level critical for the MAC region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnMac
*
* This method generates a log with level warning for the MAC region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoMac
*
* This method generates a log with level info for the MAC region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgMac
*
* This method generates a log with level debug for the MAC region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_MAC
#define otLogCritMac(aFormat, ...) otLogCrit(kLogRegionMac, aFormat, ## __VA_ARGS__)
#define otLogWarnMac(aFormat, ...) otLogWarn(kLogRegionMac, aFormat, ## __VA_ARGS__)
#define otLogInfoMac(aFormat, ...) otLogInfo(kLogRegionMac, aFormat, ## __VA_ARGS__)
#define otLogDebgMac(aFormat, ...) otLogDebg(kLogRegionMac, aFormat, ## __VA_ARGS__)
#else
#define otLogCritMac(aFormat, ...)
#define otLogWarnMac(aFormat, ...)
#define otLogInfoMac(aFormat, ...)
#define otLogDebgMac(aFormat, ...)
#endif
/**
* @def otLogCritMem
*
* This method generates a log with level critical for the memory region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogWarnMem
*
* This method generates a log with level warning for the memory region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogInfoMem
*
* This method generates a log with level info for the memory region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
/**
* @def otLogDebgMem
*
* This method generates a log with level debug for the memory region.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] ... Arguments for the format specification.
*
*/
#ifdef OPENTHREAD_CONFIG_LOG_MEM
#define otLogCritMem(aFormat, ...) otLogCrit(kLogRegionMem, aFormat, ## __VA_ARGS__)
#define otLogWarnMem(aFormat, ...) otLogWarn(kLogRegionMem, aFormat, ## __VA_ARGS__)
#define otLogInfoMem(aFormat, ...) otLogInfo(kLogRegionMem, aFormat, ## __VA_ARGS__)
#define otLogDebgMem(aFormat, ...) otLogDebg(kLogRegionMem, aFormat, ## __VA_ARGS__)
#else
#define otLogCritMem(aFormat, ...)
#define otLogWarnMem(aFormat, ...)
#define otLogInfoMem(aFormat, ...)
#define otLogDebgMem(aFormat, ...)
#endif
/**
* @}
*
*/
#ifdef __cplusplus
} // extern "C"
#endif
#endif // DEBUG_H_
+288
View File
@@ -0,0 +1,288 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 radio interface for OpenThread.
*
*/
#ifndef RADIO_H_
#define RADIO_H_
#include <stdint.h>
#include <openthread-types.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup radio Radio
* @ingroup platform
*
* @brief
* This module includes the platform abstraction for radio communication.
*
* @{
*
*/
/**
* @defgroup radio-types Types
*
* @brief
* This module includes the platform abstraction for a radio packet.
*
* @{
*
*/
enum
{
kMaxPHYPacketSize = 127, ///< aMaxPHYPacketSize (IEEE 802.15.4-2006)
kPhyMinChannel = 11, ///< 2.4 GHz IEEE 802.15.4-2006
kPhyMaxChannel = 26, ///< 2.4 GHz IEEE 802.15.4-2006
kPhySymbolsPerOctet = 2, ///< 2.4 GHz IEEE 802.15.4-2006
kPhyBitRate = 250000, ///< 2.4 GHz IEEE 802.15.4 (kilbits per second)
kPhyBitsPerOctet = 8,
kPhyUsPerSymbol = ((kPhyBitsPerOctet / kPhySymbolsPerOctet) * 1000000) / kPhyBitRate,
};
/**
* This structure represents an IEEE 802.15.4 radio frame.
*/
typedef struct RadioPacket
{
uint8_t mLength; ///< Length of the PSDU.
uint8_t mPsdu[kMaxPHYPacketSize]; ///< The PSDU.
uint8_t mChannel; ///< Channel used to transmit/receive the frame.
int8_t mPower; ///< Transmit/receive power in dBm.
} RadioPacket;
/**
* @}
*
*/
/**
* @defgroup radio-config Configuration
*
* @brief
* This module includes the platform abstraction for radio configuration.
*
* @{
*
*/
/**
* Set the PAN ID for address filtering.
*
* @param[in] aPanId The IEEE 802.15.4 PAN ID.
*
* @retval ::kThreadError_None If the PAN ID was set properly.
* @retval ::kThreadError_Fail If the PAN ID was not set properly.
*/
ThreadError otPlatRadioSetPanId(uint16_t aPanId);
/**
* Set the Extended Address for address filtering.
*
* @param[in] aExtendedAddress A pointer to the IEEE 802.15.4 Extended Address.
*
* @retval ::kThreadError_None If the Extended Address was set properly.
* @retval ::kThreadError_Fail If the Extended Address was not set properly.
*/
ThreadError otPlatRadioSetExtendedAddress(uint8_t *aExtendedAddress);
/**
* Set the Short Address for address filtering.
*
* @param[in] aShortAddress The IEEE 802.15.4 Short Address.
*
* @retval ::kThreadError_None If the Short Address was set properly.
* @retval ::kThreadError_Fail If the Short Address was not set properly.
*/
ThreadError otPlatRadioSetShortAddress(uint16_t aShortAddress);
/**
* @}
*
*/
/**
* @defgroup radio-operation Operation
*
* @brief
* This module includes the platform abstraction for radio operations.
*
* @{
*
*/
/**
* Intialize the radio.
*/
void otPlatRadioInit();
/**
* Enable the radio.
*
* @retval ::kThreadError_None Successfully transitioned to Idle.
* @retval ::kThreadError_Fail Failed to transition to Idle.
*/
ThreadError otPlatRadioEnable();
/**
* Disable the radio.
*
* @retval ::kThreadError_None Successfully transitioned to Disabled.
* @retval ::kThreadError_Fail Failed to transition to Disabled.
*/
ThreadError otPlatRadioDisable();
/**
* Transition the radio to Sleep.
*
* @retval ::kThreadError_None Successfully transitioned to Sleep.
* @retval ::kThreadError_Fail Failed to transition to Sleep.
*/
ThreadError otPlatRadioSleep();
/**
* Transition the radio to Idle.
*
* @retval ::kThreadError_None Successfully transitioned to Idle.
* @retval ::kThreadError_Fail Failed to transition to Idle.
*/
ThreadError otPlatRadioIdle();
/**
* Begins the receive sequence on the radio.
*
* The receive sequence consists of:
* 1. Transitioning the radio to Receive from Idle.
* 2. Remain in Receive until a packet is received or reception is aborted.
* 3. Return to Idle.
*
* Upon completion of the receive sequence, otPlatRadioSignalReceiveDone() is called to signal completion to the MAC
* layer.
*
* @param[in] aPacket A pointer to a packet buffer.
*
* @note The channel is specified in @p aPacket.
*
* @retval ::kThreadError_None Successfully transitioned to Receive.
* @retval ::kThreadError_Fail Failed to transition to Receive.
*/
ThreadError otPlatRadioReceive(RadioPacket *aPacket);
/**
* Signal that a packet has been received.
*
* This may be called from interrupt context. The MAC layer will then schedule a call to otPlatRadioHandleReceive().
*/
extern void otPlatRadioSignalReceiveDone();
/**
* Complete the receive sequence.
*
* @retval ::kThreadError_None Successfully received a frame.
* @retval ::kThreadError_Abort Reception was aborted and a frame was not received.
* @retval ::kThreadError_InvalidState The radio was not in Receive.
*/
ThreadError otPlatRadioHandleReceiveDone();
/**
* Begins the transmit sequence on the radio.
*
* The transmit sequence consists of:
* 1. Transitioning the radio to Transmit from Idle.
* 2. Transmits the psdu on the given channel and at the given transmit power.
* 3. Return to Idle.
*
* Upon completion of the transmit sequence, otPlatRadioSignalTransmitDone() is called to signal completion to the MAC
* layer.
*
* @param[in] aPacket A pointer to a packet buffer.
*
* @note The channel is specified in @p aPacket.
* @note The transmit power is specified in @p aPacket.
*
* @retval ::kThreadError_None Successfully transitioned to Transmit.
* @retval ::kThreadError_InvalidArgs One or more parameters in @p aPacket are invalid.
* @retval ::kThreadError_Fail Failed to transition to Transmit.
*/
ThreadError otPlatRadioTransmit(RadioPacket *aPacket);
/**
* Signal that the requested transmission is complete.
*
* This may be called from interrupt context. OpenThread will then schedule a call to
* otPlatRadio_handle_transmit_done().
*/
extern void otPlatRadioSignalTransmitDone();
/**
* Complete the transmit sequence on the radio.
*
* @param[out] aFramePending TRUE if an ACK frame was received and the Frame Pending bit was set.
*
* @retval ::kThreadError_None The frame was transmitted.
* @retval ::kThreadError_NoAck The frame was transmitted, but no ACK was received.
* @retval ::kThreadError_CcaFailed The transmission was aborted due to CCA failure.
* @retval ::kThreadError_Abort The transmission was aborted for other reasons.
* @retval ::kThreadError_InvalidState The radio did not transmit a packet.
*/
ThreadError otPlatRadioHandleTransmitDone(bool *aFramePending);
/**
* Get the most recent RSSI measurement.
*
* @returns The noise floor value in dBm when the noise floor value is valid. 127 when noise floor value is invalid.
*/
int8_t otPlatRadioGetNoiseFloor();
/**
* @}
*
*/
/**
* @}
*
*/
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // RADIO_H_
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 includes the platform abstraction for true random number generation.
*/
#ifndef RANDOM_H_
#define RANDOM_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup random Random
* @ingroup platform
*
* @brief
* This module includes the platform abstraction to support critical sections.
*
* @{
*
*/
/**
* Initialize the true random number generator.
*
*/
void otPlatRandomInit(void);
/**
* Get a 32-bit true random value.
*
* @returns A 32-bit true random value.
*
*/
uint32_t otPlatRandomGet(void);
/**
* @}
*
*/
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // RANDOM_H_
+126
View File
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* 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 includes the platform abstraction for serial communication.
*/
#ifndef SERIAL_H_
#define SERIAL_H_
#include <stdint.h>
#include <openthread-types.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup serial Serial
* @ingroup platform
*
* @brief
* This module includes the platform abstraction for serial communication.
*
* @{
*
*/
/**
* Enable the serial.
*
* @retval ::kThreadError_None Successfully enabled the serial.
* @retval ::kThreadError_Fail Failed to enabled the serial.
*/
ThreadError otPlatSerialEnable(void);
/**
* Disable the serial.
*
* @retval ::kThreadError_None Successfully disabled the serial.
* @retval ::kThreadError_Fail Failed to disable the serial.
*/
ThreadError otPlatSerialDisable(void);
/**
* Send bytes over the serial.
*
* @param[in] aBuf A pointer to the data buffer.
* @param[in] aBufLength Number of bytes to transmit.
*
* @retval ::kThreadError_None Successfully started transmission.
* @retval ::kThreadError_Fail Failed to start the transmission.
*/
ThreadError otPlatSerialSend(const uint8_t *aBuf, uint16_t aBufLength);
/**
* Signal that the bytes send operation has completed.
*
* This may be called from interrupt context. This will schedule calls to otPlatSerialHandleSendDone().
*/
extern void otPlatSerialSignalSendDone(void);
/**
* Complete the send sequence.
*/
void otPlatSerialHandleSendDone(void);
/**
* Signal that bytes have been received.
*
* This may be called from interrupt context. This will schedule calls to otPlatSerialGetReceivedBytes() and
* otPlatSerialHandleReceiveDone().
*/
extern void otPlatSerialSignalReceive(void);
/**
* Get a pointer to the received bytes.
*
* @param[out] aBufLength A pointer to a variable that this function will put the number of bytes received.
*
* @returns A pointer to the received bytes. NULL, if there are no received bytes to process.
*/
const uint8_t *otPlatSerialGetReceivedBytes(uint16_t *aBufLength);
/**
* Release received bytes.
*/
void otPlatSerialHandleReceiveDone();
/**
* @}
*
*/
#ifdef __cplusplus
} // extern "C"
#endif
#endif // SERIAL_H_