mirror of
https://github.com/espressif/openthread.git
synced 2026-08-07 19:27:46 +00:00
Merge Windows Driver Code (#817)
This is the first of the Windows implementation code that will be merged. This is only the driver code. Also note the updates to the appveyor configuration. It now builds, installs and queries the status of driver directly on the build machine. Then it builds an 'artifact' which is essentially the binaries packaged up.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 includes Windows compile-time configuration constants
|
||||
* for OpenThread.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_CORE_WINDOWS_CONFIG_H_
|
||||
#define OPENTHREAD_CORE_WINDOWS_CONFIG_H_
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS
|
||||
*
|
||||
* The number of message buffers in the buffer pool.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 2048
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAX_CHILDREN
|
||||
*
|
||||
* The maximum number of children.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_MAX_CHILDREN 32
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_IP_ADDRS_PER_CHILD
|
||||
*
|
||||
* The minimum number of supported IPv6 address registrations per child.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_IP_ADDRS_PER_CHILD 6
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAX_JOINER_ENTRIES
|
||||
*
|
||||
* The maximum number of Joiner entries maintained by the Commissioner.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_MAX_JOINER_ENTRIES 16
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_LOG_LEVEL
|
||||
*
|
||||
* The log level.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_LOG_LEVEL OPENTHREAD_LOG_LEVEL_DEBG
|
||||
|
||||
#endif // OPENTHREAD_CORE_WINDOWS_CONFIG_H_
|
||||
|
||||
@@ -0,0 +1,662 @@
|
||||
/*
|
||||
* 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 IOCTL interface for otLwf.sys.
|
||||
*/
|
||||
|
||||
#ifndef __OTLWFIOCTL_H__
|
||||
#define __OTLWFIOCTL_H__
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
__inline LONG ThreadErrorToNtstatus(ThreadError error) { return (LONG)-((int)error); }
|
||||
|
||||
// User-mode IOCTL path for CreateFile
|
||||
#define OTLWF_IOCLT_PATH TEXT("\\\\.\\\\otlwf")
|
||||
|
||||
//
|
||||
// IOCLTs and Data Types
|
||||
//
|
||||
|
||||
#define OTLWF_CTL_CODE(request, method, access) \
|
||||
CTL_CODE(FILE_DEVICE_NETWORK, request, method, access)
|
||||
|
||||
// Different possible notification types
|
||||
typedef enum _OTLWF_NOTIF_TYPE
|
||||
{
|
||||
OTLWF_NOTIF_UNSPECIFIED,
|
||||
OTLWF_NOTIF_DEVICE_AVAILABILITY,
|
||||
OTLWF_NOTIF_STATE_CHANGE,
|
||||
OTLWF_NOTIF_DISCOVER,
|
||||
OTLWF_NOTIF_ACTIVE_SCAN,
|
||||
OTLWF_NOTIF_ENERGY_SCAN,
|
||||
OTLWF_NOTIF_COMMISSIONER_ENERGY_REPORT,
|
||||
OTLWF_NOTIF_COMMISSIONER_PANID_QUERY
|
||||
|
||||
} OTLWF_NOTIF_TYPE;
|
||||
|
||||
#define MAX_ENERGY_REPORT_LENGTH 64
|
||||
|
||||
//
|
||||
// Queries (async) the next notification in the queue
|
||||
//
|
||||
#define IOCTL_OTLWF_QUERY_NOTIFICATION \
|
||||
OTLWF_CTL_CODE(0, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
typedef struct _OTLWF_NOTIFICATION {
|
||||
GUID InterfaceGuid;
|
||||
OTLWF_NOTIF_TYPE NotifType;
|
||||
union
|
||||
{
|
||||
// Payload for OTLWF_NOTIF_DEVICE_AVAILABILITY
|
||||
struct
|
||||
{
|
||||
BOOLEAN Available;
|
||||
} DeviceAvailabilityPayload;
|
||||
|
||||
// Payload for OTLWF_NOTIF_STATE_CHANGE
|
||||
struct
|
||||
{
|
||||
uint32_t Flags;
|
||||
} StateChangePayload;
|
||||
|
||||
// Payload for OTLWF_NOTIF_DISCOVER
|
||||
struct
|
||||
{
|
||||
BOOLEAN Valid;
|
||||
otActiveScanResult Results;
|
||||
} DiscoverPayload;
|
||||
|
||||
// Payload for OTLWF_NOTIF_ACTIVE_SCAN
|
||||
struct
|
||||
{
|
||||
BOOLEAN Valid;
|
||||
otActiveScanResult Results;
|
||||
} ActiveScanPayload;
|
||||
|
||||
// Payload for OTLWF_NOTIF_ENERGY_SCAN
|
||||
struct
|
||||
{
|
||||
BOOLEAN Valid;
|
||||
otEnergyScanResult Results;
|
||||
} EnergyScanPayload;
|
||||
|
||||
// Payload for OTLWF_NOTIF_COMMISSIONER_ENERGY_REPORT
|
||||
struct
|
||||
{
|
||||
uint32_t ChannelMask;
|
||||
uint8_t EnergyListLength;
|
||||
uint8_t EnergyList[MAX_ENERGY_REPORT_LENGTH];
|
||||
|
||||
} CommissionerEnergyReportPayload;
|
||||
|
||||
// Payload for OTLWF_NOTIF_COMMISSIONER_PANID_QUERY
|
||||
struct
|
||||
{
|
||||
uint16_t PanId;
|
||||
uint32_t ChannelMask;
|
||||
} CommissionerPanIdQueryPayload;
|
||||
};
|
||||
} OTLWF_NOTIFICATION, *POTLWF_NOTIFICATION;
|
||||
|
||||
//
|
||||
// Enumerates all the Thread interfaces guids
|
||||
//
|
||||
#define IOCTL_OTLWF_ENUMERATE_DEVICES \
|
||||
OTLWF_CTL_CODE(1, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
typedef struct _OTLWF_INTERFACE_LIST
|
||||
{
|
||||
uint16_t cInterfaceGuids;
|
||||
GUID InterfaceGuids[1];
|
||||
} OTLWF_INTERFACE_LIST, *POTLWF_INTERFACE_LIST;
|
||||
|
||||
//
|
||||
// Queries the detials of a given device Thread interfaces
|
||||
//
|
||||
#define IOCTL_OTLWF_QUERY_DEVICE \
|
||||
OTLWF_CTL_CODE(2, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid (in)
|
||||
typedef struct _OTLWF_DEVICE {
|
||||
ULONG CompartmentID;
|
||||
} OTLWF_DEVICE, *POTLWF_DEVICE;
|
||||
|
||||
//
|
||||
// Proxies to ot* APIs in otLwf.sys
|
||||
//
|
||||
|
||||
/* REMOVED
|
||||
#define IOCTL_OTLWF_OT_ENABLED \
|
||||
OTLWF_CTL_CODE(100, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aEnabled
|
||||
*/
|
||||
#define IOCTL_OTLWF_OT_INTERFACE \
|
||||
OTLWF_CTL_CODE(101, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aUp
|
||||
|
||||
#define IOCTL_OTLWF_OT_THREAD \
|
||||
OTLWF_CTL_CODE(102, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aStarted
|
||||
|
||||
#define IOCTL_OTLWF_OT_ACTIVE_SCAN \
|
||||
OTLWF_CTL_CODE(103, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aScanChannels
|
||||
// uint16_t - aScanDuration
|
||||
|
||||
#define IOCTL_OTLWF_OT_DISCOVER \
|
||||
OTLWF_CTL_CODE(104, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aScanChannels
|
||||
// uint16_t - aScanDuration
|
||||
// uint16_t - aPanid
|
||||
|
||||
#define IOCTL_OTLWF_OT_CHANNEL \
|
||||
OTLWF_CTL_CODE(105, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aChannel
|
||||
|
||||
#define IOCTL_OTLWF_OT_CHILD_TIMEOUT \
|
||||
OTLWF_CTL_CODE(106, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aTimeout
|
||||
|
||||
#define IOCTL_OTLWF_OT_EXTENDED_ADDRESS \
|
||||
OTLWF_CTL_CODE(107, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aExtendedAddress
|
||||
|
||||
#define IOCTL_OTLWF_OT_EXTENDED_PANID \
|
||||
OTLWF_CTL_CODE(108, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtendedPanId - aExtendedPanId
|
||||
|
||||
#define IOCTL_OTLWF_OT_LEADER_RLOC \
|
||||
OTLWF_CTL_CODE(109, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otIp6Address - aLeaderRloc
|
||||
|
||||
#define IOCTL_OTLWF_OT_LINK_MODE \
|
||||
OTLWF_CTL_CODE(110, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otLinkModeConfig - aConfig
|
||||
|
||||
#define IOCTL_OTLWF_OT_MASTER_KEY \
|
||||
OTLWF_CTL_CODE(111, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otMasterKey - aKey
|
||||
// uint8_t - aKeyLength
|
||||
|
||||
#define IOCTL_OTLWF_OT_MESH_LOCAL_EID \
|
||||
OTLWF_CTL_CODE(112, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otIp6Address - aMeshLocalEid
|
||||
|
||||
#define IOCTL_OTLWF_OT_MESH_LOCAL_PREFIX \
|
||||
OTLWF_CTL_CODE(113, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otMeshLocalPrefix - aPrefix
|
||||
|
||||
#define IOCTL_OTLWF_OT_NETWORK_DATA_LEADER \
|
||||
OTLWF_CTL_CODE(114, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t[] - aData
|
||||
|
||||
#define IOCTL_OTLWF_OT_NETWORK_DATA_LOCAL \
|
||||
OTLWF_CTL_CODE(115, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t[] - aData
|
||||
|
||||
#define IOCTL_OTLWF_OT_NETWORK_NAME \
|
||||
OTLWF_CTL_CODE(116, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otNetworkName - aNetworkName
|
||||
|
||||
#define IOCTL_OTLWF_OT_PAN_ID \
|
||||
OTLWF_CTL_CODE(117, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otPanId - aPanId
|
||||
|
||||
#define IOCTL_OTLWF_OT_ROUTER_ROLL_ENABLED \
|
||||
OTLWF_CTL_CODE(118, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aEnabled
|
||||
|
||||
#define IOCTL_OTLWF_OT_SHORT_ADDRESS \
|
||||
OTLWF_CTL_CODE(119, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otShortAddress - aShortAddress
|
||||
|
||||
#define IOCTL_OTLWF_OT_UNICAST_ADDRESSES \
|
||||
OTLWF_CTL_CODE(120, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otNetifAddress[] - aAddresses
|
||||
|
||||
#define IOCTL_OTLWF_OT_ACTIVE_DATASET \
|
||||
OTLWF_CTL_CODE(121, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otOperationalDataset - aDataset
|
||||
|
||||
#define IOCTL_OTLWF_OT_PENDING_DATASET \
|
||||
OTLWF_CTL_CODE(122, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otOperationalDataset - aDataset
|
||||
|
||||
#define IOCTL_OTLWF_OT_LOCAL_LEADER_WEIGHT \
|
||||
OTLWF_CTL_CODE(123, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aWeight
|
||||
|
||||
#define IOCTL_OTLWF_OT_ADD_BORDER_ROUTER \
|
||||
OTLWF_CTL_CODE(124, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otBorderRouterConfig - aConfig
|
||||
|
||||
#define IOCTL_OTLWF_OT_REMOVE_BORDER_ROUTER \
|
||||
OTLWF_CTL_CODE(125, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otIp6Prefix - aPrefix
|
||||
|
||||
#define IOCTL_OTLWF_OT_ADD_EXTERNAL_ROUTE \
|
||||
OTLWF_CTL_CODE(126, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExternalRouteConfig - aConfig
|
||||
|
||||
#define IOCTL_OTLWF_OT_REMOVE_EXTERNAL_ROUTE \
|
||||
OTLWF_CTL_CODE(127, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otIp6Prefix - aPrefix
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_SERVER_DATA \
|
||||
OTLWF_CTL_CODE(128, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
|
||||
#define IOCTL_OTLWF_OT_CONTEXT_ID_REUSE_DELAY \
|
||||
OTLWF_CTL_CODE(129, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aDelay
|
||||
|
||||
#define IOCTL_OTLWF_OT_KEY_SEQUENCE_COUNTER \
|
||||
OTLWF_CTL_CODE(130, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aKeySequenceCounter
|
||||
|
||||
#define IOCTL_OTLWF_OT_NETWORK_ID_TIMEOUT \
|
||||
OTLWF_CTL_CODE(131, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aTimeout
|
||||
|
||||
#define IOCTL_OTLWF_OT_ROUTER_UPGRADE_THRESHOLD \
|
||||
OTLWF_CTL_CODE(132, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aThreshold
|
||||
|
||||
#define IOCTL_OTLWF_OT_RELEASE_ROUTER_ID \
|
||||
OTLWF_CTL_CODE(133, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aRouterId
|
||||
|
||||
#define IOCTL_OTLWF_OT_MAC_WHITELIST_ENABLED \
|
||||
OTLWF_CTL_CODE(134, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aEnabled
|
||||
|
||||
#define IOCTL_OTLWF_OT_ADD_MAC_WHITELIST \
|
||||
OTLWF_CTL_CODE(135, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aExtAddr
|
||||
// int8_t - aRssi (optional)
|
||||
|
||||
#define IOCTL_OTLWF_OT_REMOVE_MAC_WHITELIST \
|
||||
OTLWF_CTL_CODE(136, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aExtAddr
|
||||
|
||||
#define IOCTL_OTLWF_OT_MAC_WHITELIST_ENTRY \
|
||||
OTLWF_CTL_CODE(137, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aIndex (input)
|
||||
// otMacWhitelistEntry - aEntry (output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_CLEAR_MAC_WHITELIST \
|
||||
OTLWF_CTL_CODE(138, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
|
||||
#define IOCTL_OTLWF_OT_DEVICE_ROLE \
|
||||
OTLWF_CTL_CODE(139, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otDeviceRole - aRole
|
||||
// otMleAttachFilter - aFilter (only for kDeviceRoleChild)
|
||||
|
||||
#define IOCTL_OTLWF_OT_CHILD_INFO_BY_ID \
|
||||
OTLWF_CTL_CODE(140, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint16_t - aChildId (input)
|
||||
// otChildInfo - aChildInfo (output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_CHILD_INFO_BY_INDEX \
|
||||
OTLWF_CTL_CODE(141, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aChildIndex (input)
|
||||
// otChildInfo - aChildInfo (output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_EID_CACHE_ENTRY \
|
||||
OTLWF_CTL_CODE(142, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aIndex (input)
|
||||
// otEidCacheEntry - aEntry (output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_LEADER_DATA \
|
||||
OTLWF_CTL_CODE(143, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otLeaderData - aLeaderData
|
||||
|
||||
#define IOCTL_OTLWF_OT_LEADER_ROUTER_ID \
|
||||
OTLWF_CTL_CODE(144, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aRouterID
|
||||
|
||||
#define IOCTL_OTLWF_OT_LEADER_WEIGHT \
|
||||
OTLWF_CTL_CODE(145, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aWeight
|
||||
|
||||
#define IOCTL_OTLWF_OT_NETWORK_DATA_VERSION \
|
||||
OTLWF_CTL_CODE(146, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aVersion
|
||||
|
||||
#define IOCTL_OTLWF_OT_PARTITION_ID \
|
||||
OTLWF_CTL_CODE(147, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aPartition
|
||||
|
||||
#define IOCTL_OTLWF_OT_RLOC16 \
|
||||
OTLWF_CTL_CODE(148, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint16_t - aRloc16
|
||||
|
||||
#define IOCTL_OTLWF_OT_ROUTER_ID_SEQUENCE \
|
||||
OTLWF_CTL_CODE(149, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aIdSequence
|
||||
|
||||
#define IOCTL_OTLWF_OT_ROUTER_INFO \
|
||||
OTLWF_CTL_CODE(150, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint16_t - aRouterId (input)
|
||||
// otRouterInfo - aRouterInfo (output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_STABLE_NETWORK_DATA_VERSION \
|
||||
OTLWF_CTL_CODE(151, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aVersion
|
||||
|
||||
#define IOCTL_OTLWF_OT_MAC_BLACKLIST_ENABLED \
|
||||
OTLWF_CTL_CODE(152, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aEnabled
|
||||
|
||||
#define IOCTL_OTLWF_OT_ADD_MAC_BLACKLIST \
|
||||
OTLWF_CTL_CODE(153, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aExtAddr
|
||||
|
||||
#define IOCTL_OTLWF_OT_REMOVE_MAC_BLACKLIST \
|
||||
OTLWF_CTL_CODE(154, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aExtAddr
|
||||
|
||||
#define IOCTL_OTLWF_OT_MAC_BLACKLIST_ENTRY \
|
||||
OTLWF_CTL_CODE(155, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aIndex (input)
|
||||
// otMacBlacklistEntry - aEntry (output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_CLEAR_MAC_BLACKLIST \
|
||||
OTLWF_CTL_CODE(156, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
|
||||
#define IOCTL_OTLWF_OT_MAX_TRANSMIT_POWER \
|
||||
OTLWF_CTL_CODE(157, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// int8_t - aPower
|
||||
|
||||
#define IOCTL_OTLWF_OT_NEXT_ON_MESH_PREFIX \
|
||||
OTLWF_CTL_CODE(158, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aLocal (input)
|
||||
// uint8_t - aIterator (input)
|
||||
// uint8_t - aNewIterator (output)
|
||||
// otBorderRouterConfig - aConfig (output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_POLL_PERIOD \
|
||||
OTLWF_CTL_CODE(159, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aPollPeriod
|
||||
|
||||
#define IOCTL_OTLWF_OT_LOCAL_LEADER_PARTITION_ID \
|
||||
OTLWF_CTL_CODE(160, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aPartitionId
|
||||
|
||||
#define IOCTL_OTLWF_OT_ASSIGN_LINK_QUALITY \
|
||||
OTLWF_CTL_CODE(161, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aExtAddr (input)
|
||||
// uint8_t - aLinkQuality (input or output)
|
||||
|
||||
#define IOCTL_OTLWF_OT_PLATFORM_RESET \
|
||||
OTLWF_CTL_CODE(162, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
|
||||
#define IOCTL_OTLWF_OT_PARENT_INFO \
|
||||
OTLWF_CTL_CODE(163, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otRouterInfo - aParentInfo
|
||||
|
||||
#define IOCTL_OTLWF_OT_SINGLETON \
|
||||
OTLWF_CTL_CODE(164, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// BOOLEAN - aSingleton
|
||||
|
||||
#define IOCTL_OTLWF_OT_MAC_COUNTERS \
|
||||
OTLWF_CTL_CODE(165, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otMacCounters - aCounters
|
||||
|
||||
#define IOCTL_OTLWF_OT_MAX_CHILDREN \
|
||||
OTLWF_CTL_CODE(166, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aMaxChildren
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISIONER_START \
|
||||
OTLWF_CTL_CODE(167, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISIONER_STOP \
|
||||
OTLWF_CTL_CODE(168, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
|
||||
#define OPENTHREAD_PSK_MAX_LENGTH 32
|
||||
#define OPENTHREAD_PROV_URL_MAX_LENGTH 64
|
||||
typedef struct otCommissionConfig
|
||||
{
|
||||
uint8_t PSKd[OPENTHREAD_PSK_MAX_LENGTH + 1];
|
||||
uint8_t ProvisioningUrl[OPENTHREAD_PROV_URL_MAX_LENGTH + 1];
|
||||
} otCommissionConfig;
|
||||
|
||||
#define IOCTL_OTLWF_OT_JOINER_START \
|
||||
OTLWF_CTL_CODE(169, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otCommissionConfig - aConfig
|
||||
|
||||
#define IOCTL_OTLWF_OT_JOINER_STOP \
|
||||
OTLWF_CTL_CODE(170, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
|
||||
#define IOCTL_OTLWF_OT_FACTORY_EUI64 \
|
||||
OTLWF_CTL_CODE(171, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aEui64
|
||||
|
||||
#define IOCTL_OTLWF_OT_HASH_MAC_ADDRESS \
|
||||
OTLWF_CTL_CODE(172, METHOD_BUFFERED, FILE_READ_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otExtAddress - aEui64
|
||||
|
||||
#define IOCTL_OTLWF_OT_ROUTER_DOWNGRADE_THRESHOLD \
|
||||
OTLWF_CTL_CODE(173, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aThreshold
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISSIONER_PANID_QUERY \
|
||||
OTLWF_CTL_CODE(174, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint16_t - aPanId
|
||||
// uint32_t - aChannekMask
|
||||
// otIp6Address - aAddress
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISSIONER_ENERGY_SCAN \
|
||||
OTLWF_CTL_CODE(175, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aChannekMask
|
||||
// uint8_t - aCount
|
||||
// uint16_t - aPeriod
|
||||
// uint16_t - aScanDuration
|
||||
// otIp6Address - aAddress
|
||||
|
||||
#define IOCTL_OTLWF_OT_ROUTER_SELECTION_JITTER \
|
||||
OTLWF_CTL_CODE(176, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aRouterJitter
|
||||
|
||||
#define IOCTL_OTLWF_OT_JOINER_UDP_PORT \
|
||||
OTLWF_CTL_CODE(177, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint16_t - aJoinerUdpPort
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_DIAGNOSTIC_GET \
|
||||
OTLWF_CTL_CODE(178, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otIp6Address - aDestination
|
||||
// uint8_t - aCount
|
||||
// uint8_t[aCount] - aTlvTypes
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_DIAGNOSTIC_RESET \
|
||||
OTLWF_CTL_CODE(179, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otIp6Address - aDestination
|
||||
// uint8_t - aCount
|
||||
// uint8_t[aCount] - aTlvTypes
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISIONER_ADD_JOINER \
|
||||
OTLWF_CTL_CODE(180, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aExtAddressValid
|
||||
// otExtAddress - aExtAddress (optional)
|
||||
// char[OPENTHREAD_PSK_MAX_LENGTH + 1] - aPSKd
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISIONER_REMOVE_JOINER \
|
||||
OTLWF_CTL_CODE(181, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aExtAddressValid
|
||||
// otExtAddress - aExtAddress (optional)
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISIONER_PROVISIONING_URL \
|
||||
OTLWF_CTL_CODE(182, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// char[OPENTHREAD_PROV_URL_MAX_LENGTH + 1] - aProvisioningUrl (optional)
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISIONER_ANNOUNCE_BEGIN \
|
||||
OTLWF_CTL_CODE(183, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aChannelMask
|
||||
// uint8_t - aCount
|
||||
// uint16_t - aPeriod
|
||||
// otIp6Address - aAddress
|
||||
|
||||
#define IOCTL_OTLWF_OT_ENERGY_SCAN \
|
||||
OTLWF_CTL_CODE(184, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aScanChannels
|
||||
// uint16_t - aScanDuration
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_ACTIVE_GET \
|
||||
OTLWF_CTL_CODE(185, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aLength
|
||||
// uint8_t[aLength] - aTlvTypes
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_ACTIVE_SET \
|
||||
OTLWF_CTL_CODE(186, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otOperationalDataset - aDataset
|
||||
// uint8_t - aLength
|
||||
// uint8_t[aLength] - aTlvTypes
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_PENDING_GET \
|
||||
OTLWF_CTL_CODE(187, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aLength
|
||||
// uint8_t[aLength] - aTlvTypes
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_PENDING_SET \
|
||||
OTLWF_CTL_CODE(188, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otOperationalDataset - aDataset
|
||||
// uint8_t - aLength
|
||||
// uint8_t[aLength] - aTlvTypes
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_MGMT_COMMISSIONER_GET \
|
||||
OTLWF_CTL_CODE(189, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint8_t - aLength
|
||||
// uint8_t[aLength] - aTlvs
|
||||
|
||||
#define IOCTL_OTLWF_OT_SEND_MGMT_COMMISSIONER_SET \
|
||||
OTLWF_CTL_CODE(190, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// otOperationalDataset - aDataset
|
||||
// uint8_t - aLength
|
||||
// uint8_t[aLength] - aTlvs
|
||||
|
||||
#define IOCTL_OTLWF_OT_KEY_SWITCH_GUARDTIME \
|
||||
OTLWF_CTL_CODE(191, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
// GUID - InterfaceGuid
|
||||
// uint32_t - aKeySwitchGuardTime
|
||||
|
||||
// OpenThread function IOCTL codes
|
||||
#define MIN_OTLWF_IOCTL_FUNC_CODE 100
|
||||
#define MAX_OTLWF_IOCTL_FUNC_CODE 191
|
||||
|
||||
#endif //__OTLWFIOCTL_H__
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 context structure for NBLs send between otLwf and it's miniport.
|
||||
*/
|
||||
|
||||
#ifndef __OT_NBL_CONTEXT_H__
|
||||
#define __OT_NBL_CONTEXT_H__
|
||||
|
||||
#ifndef _NDIS_
|
||||
#define NET_BUFFER_LIST_INFO(_NBL, _Id) ((_NBL)->NetBufferListInfo[(_Id)])
|
||||
#endif
|
||||
|
||||
// Flag that indicates the ACK received had the Frame pending flag
|
||||
#define OT_NBL_FLAG_ACK_FRAME_PENDING 0x01
|
||||
|
||||
// Represents the data necessary for the MAC layer to send out the NetBufferList
|
||||
// Must be saved in: NET_BUFFER_LIST_INFO(NetBufferList, MediaSpecificInformationEx)
|
||||
typedef struct _OT_NBL_CONTEXT
|
||||
{
|
||||
// Flags
|
||||
UCHAR Flags;
|
||||
|
||||
// Channel used to transmit/receive the frame.
|
||||
UCHAR Channel;
|
||||
|
||||
// Transmit/receive power in dBm.
|
||||
CHAR Power;
|
||||
|
||||
// Link Quality Indicator for received frames.
|
||||
UCHAR Lqi;
|
||||
|
||||
} OT_NBL_CONTEXT, *POT_NBL_CONTEXT;
|
||||
|
||||
// OT_NBL_CONTEXT must fit in the pointer used for MediaSpecificInformationEx in the NBL
|
||||
C_ASSERT(sizeof(OT_NBL_CONTEXT) <= sizeof(PVOID));
|
||||
|
||||
// Helper to set the OT_NBL_CONTEXT attached to the NetBufferList
|
||||
__forceinline VOID SetNBLContext(_In_ PNET_BUFFER_LIST NetBufferList, _In_ POT_NBL_CONTEXT Context)
|
||||
{
|
||||
*(POT_NBL_CONTEXT)(&NET_BUFFER_LIST_INFO(NetBufferList, MediaSpecificInformationEx)) = *Context;
|
||||
}
|
||||
|
||||
// Helper to return the OT_NBL_CONTEXT attached to the NetBufferList
|
||||
__forceinline POT_NBL_CONTEXT GetNBLContext(_In_ PNET_BUFFER_LIST NetBufferList)
|
||||
{
|
||||
return (POT_NBL_CONTEXT)(&NET_BUFFER_LIST_INFO(NetBufferList, MediaSpecificInformationEx));
|
||||
}
|
||||
|
||||
#endif //__OT_NBL_CONTEXT_H__
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* 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 OID interface between otLwf and it's miniport.
|
||||
*/
|
||||
|
||||
#ifndef __OTOID_H__
|
||||
#define __OTOID_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Macros for defining native OpenThread OIDs
|
||||
//
|
||||
|
||||
#define OT_OPERATIONAL_OID (0x01U)
|
||||
#define OT_STATISTICS_OID (0x02U)
|
||||
|
||||
#define OT_MANDATORY_OID (0x01U)
|
||||
#define OT_OPTIONAL_OID (0x02U)
|
||||
|
||||
#define OT_DEFINE_OID(Seq,o,m) ((0xD0000000U) | ((o) << 16) | ((m) << 8) | (Seq))
|
||||
|
||||
//
|
||||
// OpenThread Status Indication codes (and associated payload types)
|
||||
//
|
||||
|
||||
#define NDIS_STATUS_OT_ENERGY_SCAN_RESULT ((NDIS_STATUS)0x40050000L)
|
||||
typedef struct _OT_ENERGY_SCAN_RESULT
|
||||
{
|
||||
NDIS_STATUS Status;
|
||||
CHAR MaxRssi;
|
||||
} OT_ENERGY_SCAN_RESULT, * POT_ENERGY_SCAN_RESULT;
|
||||
|
||||
//
|
||||
// General OID Definitions
|
||||
//
|
||||
|
||||
// Used to query initial constants of the miniport
|
||||
#define OID_OT_CAPABILITIES OT_DEFINE_OID(0, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef enum OT_MP_MODE
|
||||
{
|
||||
OT_MP_MODE_RADIO, // Supports the physical radio layer
|
||||
OT_MP_MODE_THREAD // Supports the full Thread stack
|
||||
} OT_MP_MODE;
|
||||
typedef enum OT_RADIO_CAPABILITY
|
||||
{
|
||||
// Radio supports Ack timeouts internally
|
||||
OT_RADIO_CAP_ACK_TIMEOUT = 1 << 0,
|
||||
// Radio supports MAC retry logic and timers; as well as collision avoidance.
|
||||
OT_RADIO_CAP_MAC_RETRY_AND_COLLISION_AVOIDANCE = 1 << 1,
|
||||
// Radio supports sleeping. If the device supports sleeping, it is assumed to
|
||||
// default to the sleep state on bring up.
|
||||
OT_RADIO_CAP_SLEEP = 1 << 2,
|
||||
} OT_RADIO_CAPABILITY;
|
||||
typedef struct _OT_CAPABILITIES
|
||||
{
|
||||
#define OT_CAPABILITIES_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
OT_MP_MODE MiniportMode;
|
||||
USHORT RadioCapabilities; // OT_RADIO_CAPABILITY flags
|
||||
} OT_CAPABILITIES, * POT_CAPABILITIES;
|
||||
|
||||
#define SIZEOF_OT_CAPABILITIES_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_CAPABILITIES, RadioCapabilities)
|
||||
|
||||
//
|
||||
// Radio Mode OIDs
|
||||
//
|
||||
|
||||
// Used to query/set sleep mode; only used if RadioCapabilities
|
||||
// indicates support for OT_RADIO_CAP_SLEEP.
|
||||
#define OID_OT_SLEEP_MODE OT_DEFINE_OID(100, OT_OPERATIONAL_OID, OT_OPTIONAL_OID)
|
||||
typedef struct _OT_SLEEP_MODE
|
||||
{
|
||||
#define OT_SLEEP_MODE_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
BOOLEAN InSleepMode;
|
||||
} OT_SLEEP_MODE, * POT_SLEEP_MODE;
|
||||
|
||||
#define SIZEOF_OT_SLEEP_MODE_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_SLEEP_MODE, InSleepMode)
|
||||
|
||||
// Used to query/set promiscuous mode
|
||||
#define OID_OT_PROMISCUOUS_MODE OT_DEFINE_OID(101, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_PROMISCUOUS_MODE
|
||||
{
|
||||
#define OT_PROMISCUOUS_MODE_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
BOOLEAN InPromiscuousMode;
|
||||
} OT_PROMISCUOUS_MODE, * POT_PROMISCUOUS_MODE;
|
||||
|
||||
#define SIZEOF_OT_PROMISCUOUS_MODE_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_PROMISCUOUS_MODE, InPromiscuousMode)
|
||||
|
||||
// Used to query the factory Extended Address
|
||||
#define OID_OT_FACTORY_EXTENDED_ADDRESS OT_DEFINE_OID(102, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_FACTORY_EXTENDED_ADDRESS
|
||||
{
|
||||
#define OT_FACTORY_EXTENDED_ADDRESS_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
ULONGLONG ExtendedAddress;
|
||||
} OT_FACTORY_EXTENDED_ADDRESS, * POT_FACTORY_EXTENDED_ADDRESS;
|
||||
|
||||
#define SIZEOF_OT_FACTORY_EXTENDED_ADDRESS_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_FACTORY_EXTENDED_ADDRESS, ExtendedAddress)
|
||||
|
||||
// Used to query/set the Pan ID
|
||||
#define OID_OT_PAND_ID OT_DEFINE_OID(103, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_PAND_ID
|
||||
{
|
||||
#define OT_PAND_ID_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
USHORT PanID;
|
||||
} OT_PAND_ID, * POT_PAND_ID;
|
||||
|
||||
#define SIZEOF_OT_PAND_ID_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_PAND_ID, PanID)
|
||||
|
||||
// Used to query/set the Short Address
|
||||
#define OID_OT_SHORT_ADDRESS OT_DEFINE_OID(104, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_SHORT_ADDRESS
|
||||
{
|
||||
#define OT_SHORT_ADDRESS_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
USHORT ShortAddress;
|
||||
} OT_SHORT_ADDRESS, * POT_SHORT_ADDRESS;
|
||||
|
||||
#define SIZEOF_OT_SHORT_ADDRESS_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_SHORT_ADDRESS, ShortAddress)
|
||||
|
||||
// Used to query/set the Extended Address
|
||||
#define OID_OT_EXTENDED_ADDRESS OT_DEFINE_OID(105, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_EXTENDED_ADDRESS
|
||||
{
|
||||
#define OT_EXTENDED_ADDRESS_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
ULONGLONG ExtendedAddress;
|
||||
} OT_EXTENDED_ADDRESS, * POT_EXTENDED_ADDRESS;
|
||||
|
||||
#define SIZEOF_OT_EXTENDED_ADDRESS_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_EXTENDED_ADDRESS, ExtendedAddress)
|
||||
|
||||
// Used to query/set the current listening channel
|
||||
#define OID_OT_CURRENT_CHANNEL OT_DEFINE_OID(106, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_CURRENT_CHANNEL
|
||||
{
|
||||
#define OT_CURRENT_CHANNEL_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
UCHAR Channel;
|
||||
} OT_CURRENT_CHANNEL, * POT_CURRENT_CHANNEL;
|
||||
|
||||
#define SIZEOF_OT_CURRENT_CHANNEL_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_CURRENT_CHANNEL, Channel)
|
||||
|
||||
// Used to query the current RSSI for the current channel
|
||||
#define OID_OT_RSSI OT_DEFINE_OID(107, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_RSSI
|
||||
{
|
||||
#define OT_RSSI_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
CHAR Rssi;
|
||||
} OT_RSSI, * POT_RSSI;
|
||||
|
||||
#define SIZEOF_OT_RSSI_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_RSSI, Rssi)
|
||||
|
||||
// The maximum of each type (short or extended) of MAC address to pend
|
||||
#define MAX_PENDING_MAC_SIZE 32
|
||||
|
||||
// Used to set the list of MAC addresses for SEDs we currently have packets pending
|
||||
#define OID_OT_PENDING_MAC_OFFLOAD OT_DEFINE_OID(108, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_PENDING_MAC_OFFLOAD
|
||||
{
|
||||
#define OT_PENDING_MAC_OFFLOAD_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
UCHAR ShortAddressCount;
|
||||
UCHAR ExtendedAddressCount;
|
||||
// Dynamic array of USHORT ShortAddresses of count ShortAddressCount
|
||||
// Dynamic array of ULONGLONG ExtendedAddresses of count ExtendedAddressCount
|
||||
} OT_PENDING_MAC_OFFLOAD, * POT_PENDING_MAC_OFFLOAD;
|
||||
|
||||
#define SIZEOF_OT_PENDING_MAC_OFFLOAD_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_PENDING_MAC_OFFLOAD, ExtendedAddressCount)
|
||||
|
||||
#define COMPLETE_SIZEOF_OT_PENDING_MAC_OFFLOAD_REVISION_1(ShortAddressCount, ExtendedAddressCount) \
|
||||
(SIZEOF_OT_PENDING_MAC_OFFLOAD_REVISION_1 + sizeof(USHORT) * ShortAddressCount + sizeof(ULONGLONG) * ExtendedAddressCount)
|
||||
|
||||
// Used to issue an energy scan request for the given channel
|
||||
#define OID_OT_ENERGY_SCAN OT_DEFINE_OID(109, OT_OPERATIONAL_OID, OT_MANDATORY_OID)
|
||||
typedef struct _OT_ENERGY_SCAN
|
||||
{
|
||||
#define OT_ENERGY_SCAN_REVISION_1 1
|
||||
NDIS_OBJECT_HEADER Header;
|
||||
UCHAR Channel;
|
||||
USHORT DurationMs;
|
||||
} OT_ENERGY_SCAN, * POT_ENERGY_SCAN;
|
||||
|
||||
#define SIZEOF_OT_ENERGY_SCAN_REVISION_1 \
|
||||
RTL_SIZEOF_THROUGH_FIELD(OT_ENERGY_SCAN, DurationMs)
|
||||
|
||||
//
|
||||
// Thread Mode OIDs
|
||||
//
|
||||
|
||||
// TODO ...
|
||||
|
||||
#endif //__OTOID_H__
|
||||
@@ -0,0 +1,441 @@
|
||||
/*
|
||||
* 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 module contains routines and type definitions for managing reference
|
||||
* counts.
|
||||
*
|
||||
* N.B. The functions defined here use the minimum fencing required for correct
|
||||
* management of the reference count contract. No additional memory
|
||||
* ordering should be assumed.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Architecture support macros.
|
||||
// (Undefined at the bottom to avoid global namespace pollution)
|
||||
//
|
||||
|
||||
#if defined(_WIN64)
|
||||
|
||||
#define RtlIncrementLongPtrNoFence InterlockedIncrementNoFence64
|
||||
#define RtlDecrementLongPtrRelease InterlockedDecrementRelease64
|
||||
#define RtlExchangeAddLongPtrNoFence InterlockedExchangeAddNoFence64
|
||||
#define RtlExchangeAddLongPtrRelease InterlockedExchangeAddRelease64
|
||||
#define RtlCompareExchangeLongPtrNoFence InterlockedCompareExchangeNoFence64
|
||||
#define RtlCompareExchangeLongPtrRelease InterlockedCompareExchangeRelease64
|
||||
|
||||
#else
|
||||
|
||||
#define RtlIncrementLongPtrNoFence InterlockedIncrementNoFence
|
||||
#define RtlDecrementLongPtrRelease InterlockedDecrementRelease
|
||||
#define RtlExchangeAddLongPtrNoFence InterlockedExchangeAddNoFence
|
||||
#define RtlExchangeAddLongPtrRelease InterlockedExchangeAddRelease
|
||||
#define RtlCompareExchangeLongPtrNoFence InterlockedCompareExchangeNoFence
|
||||
#define RtlCompareExchangeLongPtrRelease InterlockedCompareExchangeRelease
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_X86_) || defined(_AMD64_)
|
||||
|
||||
#define RtlBarrierAfterInterlock()
|
||||
|
||||
#elif defined(_ARM64_)
|
||||
|
||||
#define RtlBarrierAfterInterlock() __dmb(_ARM64_BARRIER_ISH)
|
||||
|
||||
#elif defined(_ARM_)
|
||||
|
||||
#define RtlBarrierAfterInterlock() __dmb(_ARM_BARRIER_ISH)
|
||||
|
||||
#else
|
||||
|
||||
#define Unsupported architecture.
|
||||
|
||||
#endif
|
||||
|
||||
#define RTL_REF_COUNT_INIT 1
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
RtlInitializeReferenceCount (
|
||||
_Out_ PRTL_REFERENCE_COUNT RefCount
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function initializes a reference count to 1.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count to initialize.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
*RefCount = RTL_REF_COUNT_INIT;
|
||||
return;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
RtlInitializeReferenceCountEx (
|
||||
_Out_ PRTL_REFERENCE_COUNT RefCount,
|
||||
_In_ ULONG Bias
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function initializes a reference count to a positive value.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count to initialize.
|
||||
|
||||
Bias - Supplies an initial reference count (must be positive).
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
*RefCount = Bias;
|
||||
return;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
RtlIncrementReferenceCount (
|
||||
_Inout_ PRTL_REFERENCE_COUNT RefCount
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function increments the specified reference count, preventing object
|
||||
deletion.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
if (RtlIncrementLongPtrNoFence(RefCount) > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
__fastfail(FAST_FAIL_INVALID_REFERENCE_COUNT);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
RtlIncrementReferenceCountEx (
|
||||
_Inout_ PRTL_REFERENCE_COUNT RefCount,
|
||||
_In_ ULONG Bias
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function increases the specified reference count by the specified bias,
|
||||
preventing object deletion.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count.
|
||||
|
||||
Bias - Supplies a reference bias amount.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
if (RtlExchangeAddLongPtrNoFence(RefCount, Bias) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
__fastfail(FAST_FAIL_INVALID_REFERENCE_COUNT);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
RtlIncrementReferenceCountNonZero (
|
||||
_Inout_ volatile RTL_REFERENCE_COUNT *RefCount,
|
||||
_In_ ULONG Bias
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function increases the specified reference count by the specified bias,
|
||||
unless the reference count was previously zero.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count.
|
||||
|
||||
Bias - Supplies a reference bias amount.
|
||||
|
||||
Return Value:
|
||||
|
||||
TRUE if the reference count was incremented, FALSE otherwise.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
RTL_REFERENCE_COUNT NewValue;
|
||||
RTL_REFERENCE_COUNT OldValue;
|
||||
|
||||
PrefetchForWrite(RefCount);
|
||||
OldValue = ReadLongPtrNoFence(RefCount);
|
||||
for (;;) {
|
||||
NewValue = OldValue + Bias;
|
||||
if ((ULONG_PTR)NewValue > Bias) {
|
||||
NewValue = RtlCompareExchangeLongPtrNoFence(RefCount,
|
||||
NewValue,
|
||||
OldValue);
|
||||
|
||||
if (NewValue == OldValue) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
OldValue = NewValue;
|
||||
|
||||
} else if ((ULONG_PTR)NewValue == Bias) {
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
__fastfail(FAST_FAIL_INVALID_REFERENCE_COUNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
RtlDecrementReferenceCount (
|
||||
_Inout_ PRTL_REFERENCE_COUNT RefCount
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function reduces the specified reference count, potentially triggering
|
||||
the destruction of the guarded object.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count.
|
||||
|
||||
Return Value:
|
||||
|
||||
TRUE if the object should be destroyed, FALSE otherwise.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
RTL_REFERENCE_COUNT NewValue;
|
||||
|
||||
//
|
||||
// A release fence is required to ensure all guarded memory accesses are
|
||||
// complete before any thread can begin destroying the object.
|
||||
//
|
||||
|
||||
NewValue = RtlDecrementLongPtrRelease(RefCount);
|
||||
if (NewValue > 0) {
|
||||
return FALSE;
|
||||
|
||||
} else if (NewValue == 0) {
|
||||
|
||||
//
|
||||
// An acquire fence is required before object destruction to ensure
|
||||
// that the destructor cannot observe values changing on other threads.
|
||||
//
|
||||
|
||||
RtlBarrierAfterInterlock();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
__fastfail(FAST_FAIL_INVALID_REFERENCE_COUNT);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
RtlDecrementReferenceCountEx (
|
||||
_Inout_ PRTL_REFERENCE_COUNT RefCount,
|
||||
_In_ ULONG Bias
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function reduces the specified reference count by the specified amount,
|
||||
potentially triggering the destruction of the guarded object.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count.
|
||||
|
||||
Bias - Supplies a reference bias amount.
|
||||
|
||||
Return Value:
|
||||
|
||||
TRUE if the object should be destroyed, FALSE otherwise.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
RTL_REFERENCE_COUNT NewValue;
|
||||
|
||||
//
|
||||
// A release fence is required to ensure all guarded memory accesses are
|
||||
// complete before any thread can begin destroying the object.
|
||||
//
|
||||
|
||||
NewValue = RtlExchangeAddLongPtrRelease(RefCount, -(LONG)Bias) - Bias;
|
||||
if (NewValue > 0) {
|
||||
return FALSE;
|
||||
|
||||
} else if (NewValue == 0) {
|
||||
|
||||
//
|
||||
// An acquire fence is required before object destruction to ensure
|
||||
// that the destructor cannot observe values changing on other threads.
|
||||
//
|
||||
|
||||
RtlBarrierAfterInterlock();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
__fastfail(FAST_FAIL_INVALID_REFERENCE_COUNT);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
RtlDecrementReferenceCountNonZero (
|
||||
_Inout_ volatile RTL_REFERENCE_COUNT *RefCount,
|
||||
_In_ ULONG Bias
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function reduces the specified reference count by the specified amount,
|
||||
unless doing so would result in a zero value.
|
||||
|
||||
Arguments:
|
||||
|
||||
RefCount - Supplies a pointer to a reference count.
|
||||
|
||||
Bias - Supplies a reference bias amount.
|
||||
|
||||
Return Value:
|
||||
|
||||
TRUE if the reference count would be zero, FALSE otherwise.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
|
||||
RTL_REFERENCE_COUNT NewValue;
|
||||
RTL_REFERENCE_COUNT OldValue;
|
||||
|
||||
PrefetchForWrite(RefCount);
|
||||
OldValue = ReadLongPtrNoFence(RefCount);
|
||||
for (;;) {
|
||||
NewValue = OldValue - Bias;
|
||||
if (NewValue > 0) {
|
||||
|
||||
//
|
||||
// A release fence is required to ensure all guarded memory
|
||||
// accesses are complete before any thread can begin destroying
|
||||
// the object.
|
||||
//
|
||||
|
||||
NewValue = RtlCompareExchangeLongPtrRelease(RefCount,
|
||||
NewValue,
|
||||
OldValue);
|
||||
|
||||
if (NewValue == OldValue) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
OldValue = NewValue;
|
||||
|
||||
} else if (NewValue == 0) {
|
||||
return TRUE;
|
||||
|
||||
} else {
|
||||
__fastfail(FAST_FAIL_INVALID_REFERENCE_COUNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef RtlIncrementLongPtrNoFence
|
||||
#undef RtlDecrementLongPtrRelease
|
||||
#undef RtlExchangeAddLongPtrNoFence
|
||||
#undef RtlExchangeAddLongPtrRelease
|
||||
#undef RtlCompareExchangeLongPtrNoFence
|
||||
#undef RtlCompareExchangeLongPtrRelease
|
||||
#undef RtlBarrierAfterInterlock
|
||||
Reference in New Issue
Block a user