nl:: Weave:: Platform:: Security
This namespace includes all interfaces within Weave for the Weave Security Monitor memory manager.
Summary
Functions in this namespace are to be implemented by platforms that use Weave, according to the needs/constraints of the particular environment.
Typedefs |
|
---|---|
BlockMark_t
|
typedefuint8_t
The type used to mark which block is currently allocated/unallocated. |
BlockSetParams_t
|
typedefuint8_t
This type is used to encode block set information. |
Variables |
|
---|---|
sBlockSetParams = {
((kBlockSet1Size << kBlockSetSizeShift) & kBlockSetSizeMask) |
((kBlockSet1Count << kBlockSetCountShift) & kBlockSetCountMask) |
((kBlockSet1BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) |
((kBlockSet1isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask),
((kBlockSet2Size << kBlockSetSizeShift) & kBlockSetSizeMask) |
((kBlockSet2Count << kBlockSetCountShift) & kBlockSetCountMask) |
((kBlockSet2BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) |
((kBlockSet2isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask),
((kBlockSet3Size << kBlockSetSizeShift) & kBlockSetSizeMask) |
((kBlockSet3Count << kBlockSetCountShift) & kBlockSetCountMask) |
((kBlockSet3BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) |
((kBlockSet3isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask),
((kBlockSet4Size << kBlockSetSizeShift) & kBlockSetSizeMask) |
((kBlockSet4Count << kBlockSetCountShift) & kBlockSetCountMask) |
((kBlockSet4BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) |
((kBlockSet4isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask),
}[kNumberOfBlockSets]
|
const BlockSetParams_t
Encoded block sets parameters.
|
sBufferAllocationMask = {
kNetworkBuffer0BlockAllocationMask,
kNetworkBuffer1BlockAllocationMask,
}[kNumberOfNetworkBuffers]
|
const BlockMark_t
Set of buffer block masks.
|
sMemBlocksAllocated = 0
|
Indicates which block is allocated/unallocated.
|
sMemBufs = { NULL }[kNumberOfNetworkBuffers]
|
void *
Pointers to memory buffers initialized to NULL.
|
sNetworkBuffersUsed = true
|
bool
A boolean indicating whether (true) or not (false) the network buffers are used by Simple Allocator.
|
Functions |
|
---|---|
DecodeBlockSetParams(BlockSetParams_t blockSetParams, uint16_t & blockSize, uint8_t & blockCount, uint8_t & blockBufferIndex, bool & blockIsLongTerm)
|
void
|
GetSecureRandomData(uint8_t *buf, uint16_t len)
|
This function is called by the Weave layer to generate random data.
|
InitSecureRandomDataSource(nl::Weave::Crypto::EntropyFunct entropyFunct, uint16_t entropyLen, const uint8_t *personalizationData, uint16_t perDataLen)
|
This function is called by the Weave layer to initialize random data source.
|
MemoryAlloc(size_t size)
|
void *
This function is called by the Weave layer to allocate a block of memory of "size" bytes.
|
MemoryAlloc(size_t size, bool isLongTermAlloc)
|
void *
This function is called by the Weave layer to allocate a block of memory of "size" bytes.
|
MemoryFree(void *p)
|
void
This function is called by the Weave layer to release a memory block allocated by the MemeoryAlloc() function.
|
MemoryInit(void *buf, size_t bufSize)
|
This function is called by the Weave layer to initialize memory and resources required for proper functionality of the Weave Security Manager memory allocator.
|
MemoryShutdown(void)
|
void
This function is called by the Weave layer to releases all resources that were allocated by MemoryInit() function.
|
OnTimeConsumingCryptoDone(void)
|
void
This function is called to notify the application when a time-consuming cryptographic operation has just finished.
|
OnTimeConsumingCryptoStart(void)
|
void
This function is called to notify the application when a time-consuming cryptographic operation is about to start.
|
Enumerations
BlockSetParamFields
BlockSetParamFields
Block set parameter fields location in an 8-bit encoded form.
BlockSetParams
BlockSetParams
Defines block set parameters.
Typedefs
BlockMark_t
uint8_t BlockMark_t
The type used to mark which block is currently allocated/unallocated.
uint8_t - supports upto 8 memory blocks total uint16_t - supports upto 16 memory blocks total uint32_t - supports upto 32 memory blocks total
BlockSetParams_t
uint8_t BlockSetParams_t
This type is used to encode block set information.
A block set is a group of memory chunks that have same properties (size, type, and belong to the same buffer). Diagram below presents how block set information encoded in an 8-bit format:
Is Long Term | Block Index | Number of Blocks | Block Size |
[7] | [6:5] | [4:3] | [2:0] |
[2:0] | Decoding |
000 | 0 bytes |
001 | 128 bytes |
010 | 256 bytes |
... | - |
111 | 896 bytes |
[4:3] | Decoding |
00 | 4 blocks |
01 | 1 block |
10 | 2 blocks |
11 | 3 blocks |
[6:5] | Decoding |
00 | Network buffer #0 |
... | - |
11 | Network buffer #3 |
[7] | Decoding |
0 | Short term memory blocks |
1 | Long term memory blocks |
Variables
sBlockSetParams
const BlockSetParams_t sBlockSetParams[kNumberOfBlockSets] = { ((kBlockSet1Size << kBlockSetSizeShift) & kBlockSetSizeMask) | ((kBlockSet1Count << kBlockSetCountShift) & kBlockSetCountMask) | ((kBlockSet1BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) | ((kBlockSet1isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask), ((kBlockSet2Size << kBlockSetSizeShift) & kBlockSetSizeMask) | ((kBlockSet2Count << kBlockSetCountShift) & kBlockSetCountMask) | ((kBlockSet2BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) | ((kBlockSet2isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask), ((kBlockSet3Size << kBlockSetSizeShift) & kBlockSetSizeMask) | ((kBlockSet3Count << kBlockSetCountShift) & kBlockSetCountMask) | ((kBlockSet3BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) | ((kBlockSet3isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask), ((kBlockSet4Size << kBlockSetSizeShift) & kBlockSetSizeMask) | ((kBlockSet4Count << kBlockSetCountShift) & kBlockSetCountMask) | ((kBlockSet4BufferIndex << kBlockSetBufferIndexShift) & kBlockSetBufferIndexMask) | ((kBlockSet4isLongTerm << kBlockSetIsLongTermShift) & kBlockSetIsLongTermMask), }
Encoded block sets parameters.
sBufferAllocationMask
const BlockMark_t sBufferAllocationMask[kNumberOfNetworkBuffers] = { kNetworkBuffer0BlockAllocationMask, kNetworkBuffer1BlockAllocationMask, }
Set of buffer block masks.
Identifies if all blocks in the buffer and unallocated and then the buffer can be relieazed.
sMemBlocksAllocated
BlockMark_t sMemBlocksAllocated = 0
Indicates which block is allocated/unallocated.
Initialized to 0 - means that all memory blocks and unallocated.
sMemBufs
void * sMemBufs[kNumberOfNetworkBuffers] = { NULL }
Pointers to memory buffers initialized to NULL.
When network buffers are used sMemBufs[] point to the PacketBuffer objects. When dedicated buffer is used sMemBufs[0] points to that buffer and other sMemBufs[] pointers are ignored.
sNetworkBuffersUsed
bool sNetworkBuffersUsed = true
A boolean indicating whether (true) or not (false) the network buffers are used by Simple Allocator.
When false - dedicated buffer provided with MemoryInit() function is used.
Functions
DecodeBlockSetParams
void DecodeBlockSetParams( BlockSetParams_t blockSetParams, uint16_t & blockSize, uint8_t & blockCount, uint8_t & blockBufferIndex, bool & blockIsLongTerm )
GetSecureRandomData
WEAVE_ERROR GetSecureRandomData( uint8_t *buf, uint16_t len )
This function is called by the Weave layer to generate random data.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
InitSecureRandomDataSource
WEAVE_ERROR InitSecureRandomDataSource( nl::Weave::Crypto::EntropyFunct entropyFunct, uint16_t entropyLen, const uint8_t *personalizationData, uint16_t perDataLen )
This function is called by the Weave layer to initialize random data source.
This function is platform specific and might be empty when no initialization of random data source is required.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
MemoryAlloc
void * MemoryAlloc( size_t size )
This function is called by the Weave layer to allocate a block of memory of "size" bytes.
This function is equivalent to MemoryAlloc(size, false).
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
MemoryAlloc
void * MemoryAlloc( size_t size, bool isLongTermAlloc )
This function is called by the Weave layer to allocate a block of memory of "size" bytes.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
MemoryFree
void MemoryFree( void *p )
This function is called by the Weave layer to release a memory block allocated by the MemeoryAlloc() function.
Details | |||
---|---|---|---|
Parameters |
|
MemoryInit
WEAVE_ERROR MemoryInit( void *buf, size_t bufSize )
This function is called by the Weave layer to initialize memory and resources required for proper functionality of the Weave Security Manager memory allocator.
This function is platform specific and might be empty in certain cases. For example, this function is doing nothing when the C Standard Library malloc() and free() functions are used for memory allocation.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
MemoryShutdown
void MemoryShutdown( void )
This function is called by the Weave layer to releases all resources that were allocated by MemoryInit() function.
This function can be an empty call if there is no need to release resources. For example, this is the case when the C Standard Library malloc() and free() functions are used for memory allocation.
OnTimeConsumingCryptoDone
void OnTimeConsumingCryptoDone( void )
This function is called to notify the application when a time-consuming cryptographic operation has just finished.
OnTimeConsumingCryptoStart
void OnTimeConsumingCryptoStart( void )
This function is called to notify the application when a time-consuming cryptographic operation is about to start.