From 1a3e88d788fb533d8cbea006e6fb46ff3b16dcec Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 21 Nov 2017 17:50:07 -0800 Subject: Adding WinHEC Lab Content --- general/WinHEC 2017 Lab/PlugInToaster/devcon.exe | Bin 0 -> 81920 bytes general/WinHEC 2017 Lab/PlugInToaster/plug.exe | Bin 0 -> 12848 bytes general/WinHEC 2017 Lab/PlugInToaster/unplug.bat | 2 + .../Toaster Driver/Service/HsaService.cpp | 116 +++++ .../Toaster Driver/Service/Metering.cpp | 148 ++++++ .../Toaster Driver/Service/Metering.h | 29 ++ .../Toaster Driver/Service/RpcInterface.Idl | 51 ++ .../Toaster Driver/Service/RpcInterface.acf | 17 + .../Toaster Driver/Service/RpcInterface_c.c | 476 +++++++++++++++++ .../Toaster Driver/Service/RpcInterface_h.h | 103 ++++ .../Toaster Driver/Service/RpcInterface_s.c | 430 ++++++++++++++++ .../Toaster Driver/Service/RpcServer.cpp | 320 ++++++++++++ .../Toaster Driver/Service/RpcServer.h | 16 + .../Toaster Driver/Service/RpcServer.vcxproj | 284 +++++++++++ .../Service/RpcServer.vcxproj.filters | 76 +++ .../Toaster Driver/Service/SampleService.cpp | 155 ++++++ .../Toaster Driver/Service/SampleService.h | 46 ++ .../Toaster Driver/Service/ServiceBase.cpp | 566 +++++++++++++++++++++ .../Toaster Driver/Service/ServiceBase.h | 121 +++++ .../Toaster Driver/Service/ServiceInstaller.cpp | 191 +++++++ .../Toaster Driver/Service/ServiceInstaller.h | 57 +++ .../Toaster Driver/Service/stdafx.cpp | 8 + .../Toaster Driver/Service/stdafx.h | 15 + .../Toaster Driver/Service/targetver.h | 8 + general/WinHEC 2017 Lab/Toaster Driver/toaster.sln | 40 ++ .../Toaster Driver/toaster/driver.h | 80 +++ .../Toaster Driver/toaster/public.h | 167 ++++++ .../Toaster Driver/toaster/toaster.c | 418 +++++++++++++++ .../Toaster Driver/toaster/toaster.h | 134 +++++ .../Toaster Driver/toaster/toaster.inx | 25 + .../Toaster Driver/toaster/toaster.vcxproj | 229 +++++++++ .../Toaster Driver/toaster/toaster.vcxproj.filters | 45 ++ .../WinHEC 2017 Lab/Toaster Driver/toaster/trace.h | 62 +++ .../WinHEC 2017 Lab/Toaster Support App/App.sln | 40 ++ .../App/CustomCapability/cpp/CustomCapability.SCCD | 11 + .../CustomCapability/cpp/CustomCapability.vcxproj | 287 +++++++++++ .../cpp/CustomCapability.vcxproj.filters | 89 ++++ .../App/CustomCapability/cpp/DeviceList.cpp | 244 +++++++++ .../App/CustomCapability/cpp/Package.appxmanifest | 41 ++ .../App/CustomCapability/cpp/RpcClient.cpp | 177 +++++++ .../App/CustomCapability/cpp/RpcClient.h | 30 ++ .../App/CustomCapability/cpp/RpcInterface.c | 6 + .../App/CustomCapability/cpp/RpcInterface_c.c | 476 +++++++++++++++++ .../App/CustomCapability/cpp/RpcInterface_h.h | 112 ++++ .../App/CustomCapability/cpp/RpcInterface_s.c | 430 ++++++++++++++++ .../CustomCapability/cpp/SampleConfiguration.cpp | 21 + .../App/CustomCapability/cpp/SampleConfiguration.h | 47 ++ .../cpp/Scenario1_MeteringData.xaml | 68 +++ .../cpp/Scenario1_MeteringData.xaml.cpp | 47 ++ .../cpp/Scenario1_MeteringData.xaml.h | 31 ++ .../App/CustomCapability/cpp/ServiceViewModel.cpp | 282 ++++++++++ .../App/CustomCapability/cpp/ServiceViewModel.h | 77 +++ .../App/CustomCapability/cpp/pch.cpp | 60 +++ .../App/CustomCapability/cpp/pch.h | 27 + .../SharedContent/cpp/App.xaml.cpp | 134 +++++ .../SharedContent/cpp/App.xaml.h | 33 ++ .../SharedContent/cpp/DeviceHelpers.h | 67 +++ .../SharedContent/cpp/MainPage.xaml | 80 +++ .../SharedContent/cpp/MainPage.xaml.cpp | 154 ++++++ .../SharedContent/cpp/MainPage.xaml.h | 46 ++ .../SharedContent/media/Square310x310Logo.png | Bin 0 -> 6124 bytes .../SharedContent/media/microsoft-sdk.png | Bin 0 -> 3405 bytes .../SharedContent/media/placeholder-sdk.png | Bin 0 -> 8991 bytes .../SharedContent/media/placeholder.png | Bin 0 -> 4568 bytes .../SharedContent/media/smalltile-sdk.png | Bin 0 -> 670 bytes .../SharedContent/media/splash-sdk.png | Bin 0 -> 9274 bytes .../SharedContent/media/squaretile-sdk.png | Bin 0 -> 1137 bytes .../SharedContent/media/storelogo-sdk.png | Bin 0 -> 442 bytes .../SharedContent/media/tile-sdk.png | Bin 0 -> 4852 bytes .../SharedContent/media/windows-sdk.png | Bin 0 -> 2997 bytes .../SharedContent/xaml/App.xaml | 34 ++ .../SharedContent/xaml/Styles.xaml | 536 +++++++++++++++++++ general/WinHEC 2017 Lab/WinHEC 2017 Lab.docx | Bin 0 -> 1118785 bytes general/WinHEC 2017 Lab/WinHEC 2017 Lab.zip | Bin 0 -> 1125330 bytes 74 files changed, 8122 insertions(+) create mode 100644 general/WinHEC 2017 Lab/PlugInToaster/devcon.exe create mode 100644 general/WinHEC 2017 Lab/PlugInToaster/plug.exe create mode 100644 general/WinHEC 2017 Lab/PlugInToaster/unplug.bat create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.Idl create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.acf create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_c.c create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_h.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_s.c create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj.filters create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/Service/targetver.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster.sln create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/driver.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/public.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.c create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.h create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.inx create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj.filters create mode 100644 general/WinHEC 2017 Lab/Toaster Driver/toaster/trace.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App.sln create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.SCCD create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj.filters create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/DeviceList.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Package.appxmanifest create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface.c create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_c.c create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_h.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_s.c create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Scenario1_MeteringData.xaml create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Scenario1_MeteringData.xaml.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Scenario1_MeteringData.xaml.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/ServiceViewModel.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/ServiceViewModel.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/pch.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/pch.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/DeviceHelpers.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.cpp create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.h create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/Square310x310Logo.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/microsoft-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/placeholder-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/placeholder.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/smalltile-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/splash-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/squaretile-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/storelogo-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/tile-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/media/windows-sdk.png create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/xaml/App.xaml create mode 100644 general/WinHEC 2017 Lab/Toaster Support App/SharedContent/xaml/Styles.xaml create mode 100644 general/WinHEC 2017 Lab/WinHEC 2017 Lab.docx create mode 100644 general/WinHEC 2017 Lab/WinHEC 2017 Lab.zip diff --git a/general/WinHEC 2017 Lab/PlugInToaster/devcon.exe b/general/WinHEC 2017 Lab/PlugInToaster/devcon.exe new file mode 100644 index 00000000..92f91505 Binary files /dev/null and b/general/WinHEC 2017 Lab/PlugInToaster/devcon.exe differ diff --git a/general/WinHEC 2017 Lab/PlugInToaster/plug.exe b/general/WinHEC 2017 Lab/PlugInToaster/plug.exe new file mode 100644 index 00000000..d84aa38b Binary files /dev/null and b/general/WinHEC 2017 Lab/PlugInToaster/plug.exe differ diff --git a/general/WinHEC 2017 Lab/PlugInToaster/unplug.bat b/general/WinHEC 2017 Lab/PlugInToaster/unplug.bat new file mode 100644 index 00000000..324ae1cf --- /dev/null +++ b/general/WinHEC 2017 Lab/PlugInToaster/unplug.bat @@ -0,0 +1,2 @@ +@sc delete hsa_usersrv +@devcon remove TOASTER\BASIC_TOASTER \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp new file mode 100644 index 00000000..d3f70fdf --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp @@ -0,0 +1,116 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "stdafx.h" + +#pragma region Includes +#include +#include +#include "ServiceInstaller.h" +#include "ServiceBase.h" +#include "SampleService.h" +#pragma endregion + +// +// Settings of the service +// + +// Internal name of the service +#define SERVICE_NAME L"HsaService" + +// Displayed name of the service +#define SERVICE_DISPLAY_NAME L"Hsa Sample Service" + +// Service start options. +#define SERVICE_START_TYPE SERVICE_DEMAND_START + +// List of service dependencies - "dep1\0dep2\0\0" +#define SERVICE_DEPENDENCIES L"" + +// The name of the account under which the service should run - NULL uses LocalSystem account. +#define SERVICE_ACCOUNT NULL + +// The password to the service account name +#define SERVICE_PASSWORD NULL + + +// +// FUNCTION: wmain(int, wchar_t *[]) +// +// PURPOSE: entrypoint for the application. +// +// PARAMETERS: +// argc - number of command line arguments +// argv - array of command line arguments +// +// RETURN VALUE: +// none +// +// COMMENTS: +// wmain() either performs the command line task, or run the service. +// +int wmain(_In_ int argc, _In_ wchar_t *argv[]) +{ + bool invalidArgs = false; + + if ((argc > 1) && ((*argv[1] == L'-' || (*argv[1] == L'/')))) + { + if (_wcsicmp(L"install", argv[1] + 1) == 0) + { + // Install the service when the command is + // "-install" or "/install". + InstallService( + SERVICE_NAME, // Name of service + SERVICE_DISPLAY_NAME, // Name to display + SERVICE_START_TYPE, // Service start type + SERVICE_DEPENDENCIES, // Dependencies + SERVICE_ACCOUNT, // Service running account + SERVICE_PASSWORD // Password of the account + ); + } + else if (_wcsicmp(L"remove", argv[1] + 1) == 0) + { + // Uninstall the service when the command is + // "-remove" or "/remove". + UninstallService(SERVICE_NAME); + } + else if (_wcsicmp(L"console", argv[1] + 1) == 0) + { + // Uninstall the service when the command is + // "-remove" or "/remove". + CSampleService service(SERVICE_NAME); + service.ConsoleRun(); + } + else + { + invalidArgs = true; + } + } + else + { + invalidArgs = true; + CSampleService service(SERVICE_NAME); + if (!CServiceBase::Run(service)) + { + wprintf(L"Service failed to run w/err 0x%08lx\n", GetLastError()); + } + } + + if (invalidArgs) + { + wprintf(L"Parameters:\n"); + wprintf(L" -install to install the service.\n"); + wprintf(L" -remove to remove the service.\n"); + wprintf(L" -console to run in console mode.\n"); + } + + return 0; +} \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.cpp new file mode 100644 index 00000000..1766b37c --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.cpp @@ -0,0 +1,148 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "stdafx.h" +#include "Metering.h" +#include +#include "RpcInterface_h.h" + +using namespace RpcServer; + +// +// Thread pool callback method for metering worker +// +void CALLBACK MeteringWorkerTpCallback( + _In_ PTP_CALLBACK_INSTANCE /*iTimerInstance*/, + _In_ PVOID pContext, + _In_ PTP_TIMER /*pTimer*/) +{ + Metering *metering = static_cast(pContext); + + if (metering != nullptr) + { + // Run the metering worker for this instance of metering + metering->MeteringWorker(); + } +} + +// +// ctor for Metering +// +Metering::Metering( + _In_ __int64 period) +{ + tpTimer = CreateThreadpoolTimer(::MeteringWorkerTpCallback, this, nullptr); + // TODO: Handle if CreateThreadpoolTimer fails i.e tpTimer == nullptr + + samplePeriod = period; + event = CreateEvent( + nullptr, // default security attributes + FALSE, // auto-reset event object + FALSE, // initial state is nonsignaled + nullptr); // unnamed object +} + +// +// dtor for Metering +// +Metering::~Metering() +{ + if (tpTimer != nullptr) + { + // How to close threadpool timer when there are outstanding callbacks: + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682040(v=vs.85).aspx + SetThreadpoolTimer(tpTimer, nullptr, 0, 0); + WaitForThreadpoolTimerCallbacks(tpTimer, true); + CloseThreadpoolTimer(tpTimer); + tpTimer = nullptr; + } + CloseHandle(event); +} + +// +// Set the lowest sample period +// +void Metering::SetSamplePeriod(_In_ __int64 period) +{ + if (period < 1) + { + // Don't allow 0 (too fast) or negative numbers. + period = 1; + } + if (period > 1000) + { + // Don't let the period be too long, or we will be + // slow to shut down. + period = 1000; + } + samplePeriod = period; +} + +// +// Get last known metering data +// +__int64 Metering::GetMeteringData() const +{ + return _data; +} + +// +// Metering worker that updates metering data +// +void Metering::MeteringWorker() +{ + // Get the value from the imaginary driver and update the data + _data = GetTickCount(); + SetEvent(event); +} + +// +// Set the thread poot timer and wait for metering data. +// +void Metering::WaitForMeteringData() const +{ + ULARGE_INTEGER ulDueTime; + FILETIME FileDueTime; + ulDueTime.QuadPart = static_cast(-(1 * 10 * 1000 * samplePeriod)); + FileDueTime.dwHighDateTime = ulDueTime.HighPart; + FileDueTime.dwLowDateTime = ulDueTime.LowPart; + + SetThreadpoolTimer(tpTimer, + &FileDueTime, + 0, + 0); + + WaitForSingleObject(event, INFINITE); +} + +void Metering::StartMetering( + _In_ __int64 samplePeriod, + _In_ __int64 context) +{ + stopMeteringRequested = false; + SetSamplePeriod(samplePeriod); + + while (true) + { + WaitForMeteringData(); + if (stopMeteringRequested || ShutdownRequested) + { + break; + } + MeteringDataEvent(GetMeteringData(), context); + } +} + +void Metering::StopMetering() +{ + stopMeteringRequested = true; +} + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.h new file mode 100644 index 00000000..bfb48216 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/Metering.h @@ -0,0 +1,29 @@ +#include "stdafx.h" +#include + +#include // std::cout +#include // std::thread +#include + +namespace RpcServer +{ + class Metering + { + public: + Metering(__int64 period); + void SetSamplePeriod(__int64 period); + __int64 GetMeteringData() const; + void MeteringWorker(); + void WaitForMeteringData() const; + void StartMetering(__int64 samplePeriod, __int64 context); + void StopMetering(); + ~Metering(); + + private: + volatile __int64 _data; + volatile __int64 samplePeriod; + PTP_TIMER tpTimer = nullptr; + HANDLE event; + volatile bool stopMeteringRequested = false; + }; +} diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.Idl b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.Idl new file mode 100644 index 00000000..1b4b74cc --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.Idl @@ -0,0 +1,51 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +import "oaidl.idl"; +import "unknwn.idl"; + +[uuid (906B0CE0-C70B-1067-B317-00DD010662DA), +version(1.0), +pointer_default(unique), +] +interface RpcInterface +{ + + // context_handle_noserialize in acf for RPC to call rundown when the client goes away + typedef [context_handle] void* PCONTEXT_HANDLE_TYPE; + typedef [ref] PCONTEXT_HANDLE_TYPE * PPCONTEXT_HANDLE_TYPE; + + // + // RPC methods to retrieve/clean client context + // + void RemoteOpen([in] handle_t hBinding, + [out] PPCONTEXT_HANDLE_TYPE pphContext); + + void RemoteClose([in, out] PPCONTEXT_HANDLE_TYPE pphContext); + + // + // Metering Interface + // + void StartMetering( + [in] PCONTEXT_HANDLE_TYPE phContext, + [in] __int64 samplePeriod, + [in, optional] __int64 context); + + void SetSamplePeriod( + [in] PCONTEXT_HANDLE_TYPE phContext, + [in] __int64 samplePeriod); + + void StopMetering([in] PCONTEXT_HANDLE_TYPE phContext); + + [callback] void MeteringDataEvent( + [in] __int64 data, + [in, optional] __int64 context); +} diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.acf b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.acf new file mode 100644 index 00000000..d00ed5af --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface.acf @@ -0,0 +1,17 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the Microsoft Public License. +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + + +interface RpcInterface +{ + // We need the RPC to call rundown when the client goes away + typedef [context_handle_noserialize] PCONTEXT_HANDLE_TYPE; +} diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_c.c b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_c.c new file mode 100644 index 00000000..fbe0a799 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_c.c @@ -0,0 +1,476 @@ + + +/* this ALWAYS GENERATED file contains the RPC client stubs */ + + + /* File created by MIDL compiler version 8.01.0622 */ +/* at Mon Jan 18 19:14:07 2038 + */ +/* Compiler settings for RpcInterface.Idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#if defined(_M_AMD64) + + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ +#if _MSC_VER >= 1200 +#pragma warning(push) +#endif + +#pragma warning( disable: 4211 ) /* redefine extern to static */ +#pragma warning( disable: 4232 ) /* dllimport identity*/ +#pragma warning( disable: 4024 ) /* array to pointer mapping*/ + +#include + +#include "RpcInterface_h.h" + +#define TYPE_FORMAT_STRING_SIZE 23 +#define PROC_FORMAT_STRING_SIZE 245 +#define EXPR_FORMAT_STRING_SIZE 1 +#define TRANSMIT_AS_TABLE_SIZE 0 +#define WIRE_MARSHAL_TABLE_SIZE 0 + +typedef struct _RpcInterface_MIDL_TYPE_FORMAT_STRING + { + short Pad; + unsigned char Format[ TYPE_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_TYPE_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_PROC_FORMAT_STRING + { + short Pad; + unsigned char Format[ PROC_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_PROC_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_EXPR_FORMAT_STRING + { + long Pad; + unsigned char Format[ EXPR_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_EXPR_FORMAT_STRING; + + +static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax = +{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}; + + +extern const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString; +extern const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString; +extern const RpcInterface_MIDL_EXPR_FORMAT_STRING RpcInterface__MIDL_ExprFormatString; + +#define GENERIC_BINDING_TABLE_SIZE 0 + + +/* Standard interface: RpcInterface, ver. 1.0, + GUID={0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}} */ + + +extern const MIDL_SERVER_INFO RpcInterface_ServerInfo; + + +extern const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable; + +static const RPC_CLIENT_INTERFACE RpcInterface___RpcClientInterface = + { + sizeof(RPC_CLIENT_INTERFACE), + {{0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}},{1,0}}, + {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, + (RPC_DISPATCH_TABLE*)&RpcInterface_v1_0_DispatchTable, + 0, + 0, + 0, + &RpcInterface_ServerInfo, + 0x04000000 + }; +RPC_IF_HANDLE RpcInterface_v1_0_c_ifspec = (RPC_IF_HANDLE)& RpcInterface___RpcClientInterface; + +extern const MIDL_STUB_DESC RpcInterface_StubDesc; + +static RPC_BINDING_HANDLE RpcInterface__MIDL_AutoBindHandle; + + +void RemoteOpen( + /* [in] */ handle_t hBinding, + /* [out] */ PPCONTEXT_HANDLE_TYPE pphContext) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[0], + hBinding, + pphContext); + +} + + +void RemoteClose( + /* [out][in] */ PPCONTEXT_HANDLE_TYPE pphContext) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[36], + pphContext); + +} + + +void StartMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod, + /* [optional][in] */ __int64 context) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[74], + phContext, + samplePeriod, + context); + +} + + +void SetSamplePeriod( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[124], + phContext, + samplePeriod); + +} + + +void StopMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[168], + phContext); + +} + + +#if !defined(__RPC_WIN64__) +#error Invalid build platform for this stub. +#endif + +static const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString = + { + 0, + { + + /* Procedure RemoteOpen */ + + 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 2 */ NdrFcLong( 0x0 ), /* 0 */ +/* 6 */ NdrFcShort( 0x0 ), /* 0 */ +/* 8 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 10 */ 0x32, /* FC_BIND_PRIMITIVE */ + 0x0, /* 0 */ +/* 12 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 14 */ NdrFcShort( 0x0 ), /* 0 */ +/* 16 */ NdrFcShort( 0x38 ), /* 56 */ +/* 18 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 20 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 22 */ NdrFcShort( 0x0 ), /* 0 */ +/* 24 */ NdrFcShort( 0x0 ), /* 0 */ +/* 26 */ NdrFcShort( 0x0 ), /* 0 */ +/* 28 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 30 */ NdrFcShort( 0x110 ), /* Flags: out, simple ref, */ +/* 32 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 34 */ NdrFcShort( 0x6 ), /* Type Offset=6 */ + + /* Procedure RemoteClose */ + +/* 36 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 38 */ NdrFcLong( 0x0 ), /* 0 */ +/* 42 */ NdrFcShort( 0x1 ), /* 1 */ +/* 44 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 46 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe4, /* Ctxt flags: via ptr, in, out, no serialize, */ +/* 48 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 50 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 52 */ NdrFcShort( 0x38 ), /* 56 */ +/* 54 */ NdrFcShort( 0x38 ), /* 56 */ +/* 56 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 58 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 60 */ NdrFcShort( 0x0 ), /* 0 */ +/* 62 */ NdrFcShort( 0x0 ), /* 0 */ +/* 64 */ NdrFcShort( 0x0 ), /* 0 */ +/* 66 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 68 */ NdrFcShort( 0x118 ), /* Flags: in, out, simple ref, */ +/* 70 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 72 */ NdrFcShort( 0xe ), /* Type Offset=14 */ + + /* Procedure StartMetering */ + +/* 74 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 76 */ NdrFcLong( 0x0 ), /* 0 */ +/* 80 */ NdrFcShort( 0x2 ), /* 2 */ +/* 82 */ NdrFcShort( 0x18 ), /* X64 Stack size/offset = 24 */ +/* 84 */ 0x30, /* FC_BIND_CONTEXT */ + 0x44, /* Ctxt flags: in, no serialize, */ +/* 86 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 88 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 90 */ NdrFcShort( 0x44 ), /* 68 */ +/* 92 */ NdrFcShort( 0x0 ), /* 0 */ +/* 94 */ 0x40, /* Oi2 Flags: has ext, */ + 0x3, /* 3 */ +/* 96 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 98 */ NdrFcShort( 0x0 ), /* 0 */ +/* 100 */ NdrFcShort( 0x0 ), /* 0 */ +/* 102 */ NdrFcShort( 0x0 ), /* 0 */ +/* 104 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 106 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 108 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 110 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 112 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 114 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 116 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 118 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 120 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 122 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure SetSamplePeriod */ + +/* 124 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 126 */ NdrFcLong( 0x0 ), /* 0 */ +/* 130 */ NdrFcShort( 0x3 ), /* 3 */ +/* 132 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 134 */ 0x30, /* FC_BIND_CONTEXT */ + 0x44, /* Ctxt flags: in, no serialize, */ +/* 136 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 138 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 140 */ NdrFcShort( 0x34 ), /* 52 */ +/* 142 */ NdrFcShort( 0x0 ), /* 0 */ +/* 144 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 146 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 148 */ NdrFcShort( 0x0 ), /* 0 */ +/* 150 */ NdrFcShort( 0x0 ), /* 0 */ +/* 152 */ NdrFcShort( 0x0 ), /* 0 */ +/* 154 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 156 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 158 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 160 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 162 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 164 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 166 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure StopMetering */ + +/* 168 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 170 */ NdrFcLong( 0x0 ), /* 0 */ +/* 174 */ NdrFcShort( 0x4 ), /* 4 */ +/* 176 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 178 */ 0x30, /* FC_BIND_CONTEXT */ + 0x44, /* Ctxt flags: in, no serialize, */ +/* 180 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 182 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 184 */ NdrFcShort( 0x24 ), /* 36 */ +/* 186 */ NdrFcShort( 0x0 ), /* 0 */ +/* 188 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 190 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 192 */ NdrFcShort( 0x0 ), /* 0 */ +/* 194 */ NdrFcShort( 0x0 ), /* 0 */ +/* 196 */ NdrFcShort( 0x0 ), /* 0 */ +/* 198 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 200 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 202 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 204 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Procedure MeteringDataEvent */ + +/* 206 */ 0x34, /* FC_CALLBACK_HANDLE */ + 0x48, /* Old Flags: */ +/* 208 */ NdrFcLong( 0x0 ), /* 0 */ +/* 212 */ NdrFcShort( 0x0 ), /* 0 */ +/* 214 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 216 */ NdrFcShort( 0x20 ), /* 32 */ +/* 218 */ NdrFcShort( 0x0 ), /* 0 */ +/* 220 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 222 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 224 */ NdrFcShort( 0x0 ), /* 0 */ +/* 226 */ NdrFcShort( 0x0 ), /* 0 */ +/* 228 */ NdrFcShort( 0x0 ), /* 0 */ +/* 230 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter data */ + +/* 232 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 234 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 236 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 238 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 240 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 242 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString = + { + 0, + { + NdrFcShort( 0x0 ), /* 0 */ +/* 2 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 4 */ NdrFcShort( 0x2 ), /* Offset= 2 (6) */ +/* 6 */ 0x30, /* FC_BIND_CONTEXT */ + 0xa4, /* Ctxt flags: via ptr, out, no serialize, */ +/* 8 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 10 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 12 */ NdrFcShort( 0x2 ), /* Offset= 2 (14) */ +/* 14 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe5, /* Ctxt flags: via ptr, in, out, no serialize, can't be null */ +/* 16 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 18 */ 0x30, /* FC_BIND_CONTEXT */ + 0x45, /* Ctxt flags: in, no serialize, can't be null */ +/* 20 */ 0x0, /* 0 */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const unsigned short RpcInterface_FormatStringOffsetTable[] = + { + 0, + 36, + 74, + 124, + 168, + }; + + +static const unsigned short _callbackRpcInterface_FormatStringOffsetTable[] = + { + 206 + }; + + +static const MIDL_STUB_DESC RpcInterface_StubDesc = + { + (void *)& RpcInterface___RpcClientInterface, + MIDL_user_allocate, + MIDL_user_free, + &RpcInterface__MIDL_AutoBindHandle, + 0, + 0, + 0, + 0, + RpcInterface__MIDL_TypeFormatString.Format, + 1, /* -error bounds_check flag */ + 0x50002, /* Ndr library version */ + 0, + 0x801026e, /* MIDL Version 8.1.622 */ + 0, + 0, + 0, /* notify & notify_flag routine table */ + 0x1, /* MIDL flag */ + 0, /* cs routines */ + 0, /* proxy/server info */ + 0 + }; + +static const RPC_DISPATCH_FUNCTION RpcInterface_table[] = + { + NdrServerCall2, + 0 + }; +static const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable = + { + 1, + (RPC_DISPATCH_FUNCTION*)RpcInterface_table + }; + +static const SERVER_ROUTINE RpcInterface_ServerRoutineTable[] = + { + (SERVER_ROUTINE)MeteringDataEvent + }; + +static const MIDL_SERVER_INFO RpcInterface_ServerInfo = + { + &RpcInterface_StubDesc, + RpcInterface_ServerRoutineTable, + RpcInterface__MIDL_ProcFormatString.Format, + _callbackRpcInterface_FormatStringOffsetTable, + 0, + 0, + 0, + 0}; +#if _MSC_VER >= 1200 +#pragma warning(pop) +#endif + + +#endif /* defined(_M_AMD64)*/ + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_h.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_h.h new file mode 100644 index 00000000..98544da7 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_h.h @@ -0,0 +1,103 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 8.01.0622 */ +/* at Mon Jan 18 19:14:07 2038 + */ +/* Compiler settings for RpcInterface.Idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 475 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif /* __RPCNDR_H_VERSION__ */ + + +#ifndef __RpcInterface_h_h__ +#define __RpcInterface_h_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +/* Forward Declarations */ + +/* header files for imported files */ +#include "oaidl.h" + +#ifdef __cplusplus +extern "C"{ +#endif + + +#ifndef __RpcInterface_INTERFACE_DEFINED__ +#define __RpcInterface_INTERFACE_DEFINED__ + +/* interface RpcInterface */ +/* [unique][version][uuid] */ + +typedef /* [context_handle_noserialize][context_handle] */ void *PCONTEXT_HANDLE_TYPE; + +typedef /* [ref] */ PCONTEXT_HANDLE_TYPE *PPCONTEXT_HANDLE_TYPE; + +void RemoteOpen( + /* [in] */ handle_t hBinding, + /* [out] */ PPCONTEXT_HANDLE_TYPE pphContext); + +void RemoteClose( + /* [out][in] */ PPCONTEXT_HANDLE_TYPE pphContext); + +void StartMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod, + /* [optional][in] */ __int64 context); + +void SetSamplePeriod( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod); + +void StopMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext); + +/* [callback] */ void MeteringDataEvent( + /* [in] */ __int64 data, + /* [optional][in] */ __int64 context); + + + +extern RPC_IF_HANDLE RpcInterface_v1_0_c_ifspec; +extern RPC_IF_HANDLE RpcInterface_v1_0_s_ifspec; +#endif /* __RpcInterface_INTERFACE_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +void __RPC_USER PCONTEXT_HANDLE_TYPE_rundown( PCONTEXT_HANDLE_TYPE ); + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_s.c b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_s.c new file mode 100644 index 00000000..89aa59bf --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcInterface_s.c @@ -0,0 +1,430 @@ + + +/* this ALWAYS GENERATED file contains the RPC server stubs */ + + + /* File created by MIDL compiler version 8.01.0622 */ +/* at Mon Jan 18 19:14:07 2038 + */ +/* Compiler settings for RpcInterface.Idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#if defined(_M_AMD64) + + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ +#if _MSC_VER >= 1200 +#pragma warning(push) +#endif + +#pragma warning( disable: 4211 ) /* redefine extern to static */ +#pragma warning( disable: 4232 ) /* dllimport identity*/ +#pragma warning( disable: 4024 ) /* array to pointer mapping*/ + +#include +#include "RpcInterface_h.h" + +#define TYPE_FORMAT_STRING_SIZE 23 +#define PROC_FORMAT_STRING_SIZE 245 +#define EXPR_FORMAT_STRING_SIZE 1 +#define TRANSMIT_AS_TABLE_SIZE 0 +#define WIRE_MARSHAL_TABLE_SIZE 0 + +typedef struct _RpcInterface_MIDL_TYPE_FORMAT_STRING + { + short Pad; + unsigned char Format[ TYPE_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_TYPE_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_PROC_FORMAT_STRING + { + short Pad; + unsigned char Format[ PROC_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_PROC_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_EXPR_FORMAT_STRING + { + long Pad; + unsigned char Format[ EXPR_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_EXPR_FORMAT_STRING; + + +static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax = +{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}; + +extern const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString; +extern const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString; +extern const RpcInterface_MIDL_EXPR_FORMAT_STRING RpcInterface__MIDL_ExprFormatString; + +/* Standard interface: RpcInterface, ver. 1.0, + GUID={0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}} */ + + +extern const MIDL_SERVER_INFO RpcInterface_ServerInfo; + +extern const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable; + +static const RPC_SERVER_INTERFACE RpcInterface___RpcServerInterface = + { + sizeof(RPC_SERVER_INTERFACE), + {{0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}},{1,0}}, + {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, + (RPC_DISPATCH_TABLE*)&RpcInterface_v1_0_DispatchTable, + 0, + 0, + 0, + &RpcInterface_ServerInfo, + 0x04000000 + }; +RPC_IF_HANDLE RpcInterface_v1_0_s_ifspec = (RPC_IF_HANDLE)& RpcInterface___RpcServerInterface; + +extern const MIDL_STUB_DESC RpcInterface_StubDesc; + + extern const MIDL_STUBLESS_PROXY_INFO RpcInterface_ProxyInfo; + +/* [callback] */ void MeteringDataEvent( + /* [in] */ __int64 data, + /* [optional][in] */ __int64 context) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[206], + data, + context); + +} + +extern const NDR_RUNDOWN RundownRoutines[]; + +#if !defined(__RPC_WIN64__) +#error Invalid build platform for this stub. +#endif + +static const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString = + { + 0, + { + + /* Procedure RemoteOpen */ + + 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 2 */ NdrFcLong( 0x0 ), /* 0 */ +/* 6 */ NdrFcShort( 0x0 ), /* 0 */ +/* 8 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 10 */ 0x32, /* FC_BIND_PRIMITIVE */ + 0x0, /* 0 */ +/* 12 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 14 */ NdrFcShort( 0x0 ), /* 0 */ +/* 16 */ NdrFcShort( 0x38 ), /* 56 */ +/* 18 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 20 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 22 */ NdrFcShort( 0x0 ), /* 0 */ +/* 24 */ NdrFcShort( 0x0 ), /* 0 */ +/* 26 */ NdrFcShort( 0x0 ), /* 0 */ +/* 28 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 30 */ NdrFcShort( 0x110 ), /* Flags: out, simple ref, */ +/* 32 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 34 */ NdrFcShort( 0x6 ), /* Type Offset=6 */ + + /* Procedure RemoteClose */ + +/* 36 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 38 */ NdrFcLong( 0x0 ), /* 0 */ +/* 42 */ NdrFcShort( 0x1 ), /* 1 */ +/* 44 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 46 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe4, /* Ctxt flags: via ptr, in, out, no serialize, */ +/* 48 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 50 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 52 */ NdrFcShort( 0x38 ), /* 56 */ +/* 54 */ NdrFcShort( 0x38 ), /* 56 */ +/* 56 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 58 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 60 */ NdrFcShort( 0x0 ), /* 0 */ +/* 62 */ NdrFcShort( 0x0 ), /* 0 */ +/* 64 */ NdrFcShort( 0x0 ), /* 0 */ +/* 66 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 68 */ NdrFcShort( 0x118 ), /* Flags: in, out, simple ref, */ +/* 70 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 72 */ NdrFcShort( 0xe ), /* Type Offset=14 */ + + /* Procedure StartMetering */ + +/* 74 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 76 */ NdrFcLong( 0x0 ), /* 0 */ +/* 80 */ NdrFcShort( 0x2 ), /* 2 */ +/* 82 */ NdrFcShort( 0x18 ), /* X64 Stack size/offset = 24 */ +/* 84 */ 0x30, /* FC_BIND_CONTEXT */ + 0x44, /* Ctxt flags: in, no serialize, */ +/* 86 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 88 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 90 */ NdrFcShort( 0x44 ), /* 68 */ +/* 92 */ NdrFcShort( 0x0 ), /* 0 */ +/* 94 */ 0x40, /* Oi2 Flags: has ext, */ + 0x3, /* 3 */ +/* 96 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 98 */ NdrFcShort( 0x0 ), /* 0 */ +/* 100 */ NdrFcShort( 0x0 ), /* 0 */ +/* 102 */ NdrFcShort( 0x0 ), /* 0 */ +/* 104 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 106 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 108 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 110 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 112 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 114 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 116 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 118 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 120 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 122 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure SetSamplePeriod */ + +/* 124 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 126 */ NdrFcLong( 0x0 ), /* 0 */ +/* 130 */ NdrFcShort( 0x3 ), /* 3 */ +/* 132 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 134 */ 0x30, /* FC_BIND_CONTEXT */ + 0x44, /* Ctxt flags: in, no serialize, */ +/* 136 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 138 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 140 */ NdrFcShort( 0x34 ), /* 52 */ +/* 142 */ NdrFcShort( 0x0 ), /* 0 */ +/* 144 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 146 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 148 */ NdrFcShort( 0x0 ), /* 0 */ +/* 150 */ NdrFcShort( 0x0 ), /* 0 */ +/* 152 */ NdrFcShort( 0x0 ), /* 0 */ +/* 154 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 156 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 158 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 160 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 162 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 164 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 166 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure StopMetering */ + +/* 168 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 170 */ NdrFcLong( 0x0 ), /* 0 */ +/* 174 */ NdrFcShort( 0x4 ), /* 4 */ +/* 176 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 178 */ 0x30, /* FC_BIND_CONTEXT */ + 0x44, /* Ctxt flags: in, no serialize, */ +/* 180 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 182 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 184 */ NdrFcShort( 0x24 ), /* 36 */ +/* 186 */ NdrFcShort( 0x0 ), /* 0 */ +/* 188 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 190 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 192 */ NdrFcShort( 0x0 ), /* 0 */ +/* 194 */ NdrFcShort( 0x0 ), /* 0 */ +/* 196 */ NdrFcShort( 0x0 ), /* 0 */ +/* 198 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 200 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 202 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 204 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Procedure MeteringDataEvent */ + +/* 206 */ 0x34, /* FC_CALLBACK_HANDLE */ + 0x48, /* Old Flags: */ +/* 208 */ NdrFcLong( 0x0 ), /* 0 */ +/* 212 */ NdrFcShort( 0x0 ), /* 0 */ +/* 214 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 216 */ NdrFcShort( 0x20 ), /* 32 */ +/* 218 */ NdrFcShort( 0x0 ), /* 0 */ +/* 220 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 222 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 224 */ NdrFcShort( 0x0 ), /* 0 */ +/* 226 */ NdrFcShort( 0x0 ), /* 0 */ +/* 228 */ NdrFcShort( 0x0 ), /* 0 */ +/* 230 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter data */ + +/* 232 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 234 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 236 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 238 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 240 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 242 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString = + { + 0, + { + NdrFcShort( 0x0 ), /* 0 */ +/* 2 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 4 */ NdrFcShort( 0x2 ), /* Offset= 2 (6) */ +/* 6 */ 0x30, /* FC_BIND_CONTEXT */ + 0xa4, /* Ctxt flags: via ptr, out, no serialize, */ +/* 8 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 10 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 12 */ NdrFcShort( 0x2 ), /* Offset= 2 (14) */ +/* 14 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe5, /* Ctxt flags: via ptr, in, out, no serialize, can't be null */ +/* 16 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 18 */ 0x30, /* FC_BIND_CONTEXT */ + 0x45, /* Ctxt flags: in, no serialize, can't be null */ +/* 20 */ 0x0, /* 0 */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const NDR_RUNDOWN RundownRoutines[] = + { + PCONTEXT_HANDLE_TYPE_rundown + }; + + +static const unsigned short RpcInterface_FormatStringOffsetTable[] = + { + 0, + 36, + 74, + 124, + 168, + }; + + +static const unsigned short _callbackRpcInterface_FormatStringOffsetTable[] = + { + 206 + }; + + +static const MIDL_STUB_DESC RpcInterface_StubDesc = + { + (void *)& RpcInterface___RpcServerInterface, + MIDL_user_allocate, + MIDL_user_free, + 0, + RundownRoutines, + 0, + 0, + 0, + RpcInterface__MIDL_TypeFormatString.Format, + 1, /* -error bounds_check flag */ + 0x50002, /* Ndr library version */ + 0, + 0x801026e, /* MIDL Version 8.1.622 */ + 0, + 0, + 0, /* notify & notify_flag routine table */ + 0x1, /* MIDL flag */ + 0, /* cs routines */ + 0, /* proxy/server info */ + 0 + }; + +static const RPC_DISPATCH_FUNCTION RpcInterface_table[] = + { + NdrServerCall2, + NdrServerCall2, + NdrServerCall2, + NdrServerCall2, + NdrServerCall2, + 0 + }; +static const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable = + { + 5, + (RPC_DISPATCH_FUNCTION*)RpcInterface_table + }; + +static const SERVER_ROUTINE RpcInterface_ServerRoutineTable[] = + { + (SERVER_ROUTINE)RemoteOpen, + (SERVER_ROUTINE)RemoteClose, + (SERVER_ROUTINE)StartMetering, + (SERVER_ROUTINE)SetSamplePeriod, + (SERVER_ROUTINE)StopMetering, + }; + +static const MIDL_SERVER_INFO RpcInterface_ServerInfo = + { + &RpcInterface_StubDesc, + RpcInterface_ServerRoutineTable, + RpcInterface__MIDL_ProcFormatString.Format, + RpcInterface_FormatStringOffsetTable, + 0, + 0, + 0, + 0}; +#if _MSC_VER >= 1200 +#pragma warning(pop) +#endif + + +#endif /* defined(_M_AMD64)*/ + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.cpp new file mode 100644 index 00000000..0cad3578 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.cpp @@ -0,0 +1,320 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "stdafx.h" +#include +#include +#include +#include "RpcInterface_h.h" +#include + +#include +#include +#include +#include "RpcServer.h" + +using namespace RpcServer; + +#define DEFAULT_METERING_PERIOD 100 + +bool ShutdownRequested; +static RPC_BINDING_VECTOR* BindingVector = nullptr; + +void FreeSidArray(__inout_ecount(cSIDs) PSID* pSIDs, ULONG cSIDs) +{ + if (pSIDs != nullptr) + { + for (ULONG i = 0; i < cSIDs; i++) + { + LocalFree(pSIDs[i]); + + pSIDs[i] = nullptr; + } + + LocalFree(pSIDs); + + pSIDs = nullptr; + cSIDs = 0; + } +} + +// +// Routine to create RPC server and listen to incoming RPC calls +// +DWORD RpcServerStart() +{ + DWORD hResult = S_OK; + WCHAR* protocolSequence = L"ncalrpc"; + unsigned int minCalls = 1; + unsigned int dontWait = false; + ShutdownRequested = false; + + SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY; + PSID everyoneSid = nullptr; + PSID* capabilitySids = nullptr; + DWORD capabilitySidCount = 0; + PSID* capabilityGroupSids = nullptr; + DWORD capabilityGroupSidCount = 0; + EXPLICIT_ACCESS ea[2] = {}; + PACL acl = nullptr; + SECURITY_DESCRIPTOR rpcSecurityDescriptor = {}; + + // When creating the RPC endpoint we want it to allow connections from any UWA that contains + // the custom capability SID in its process token. When a UWA declares the custom capability + // in its app manifest, it will later contain the SID form of that custom capability in its + // process token at runtime. By default, RPC endpoints don't allow UWAs (AppContainer processes) + // to connect to them, so we need to set the security on the endpoint to allow access to UWAs with the + // custom capability. + // + // To do this we'll perform the following steps: + // 1) Convert the custom capability name to a SID + // 2) Create a security descriptor using that SID, as well as other needed SIDs. This sample shows how to allow + // all 'non UWAs' access as well as UWAs containing the custom capability SID. + // 3) Create the RPC endpoint using that security descriptor + // + // To create the security descriptor we're roughly following this MSDN sample: + // https://msdn.microsoft.com/en-us/library/windows/desktop/aa446595(v=vs.85).aspx + + // Get the SID form of the custom capability. In this case we only expect one SID and + // we don't care about the capability group. + //INSERT DERIVE CAPABILTY SIDS FROM NAME HERE + + // Get the SID that represents 'everyone' (this doesn't include AppContainers) + if (!AllocateAndInitializeSid( + &SIDAuthWorld, 1, + SECURITY_WORLD_RID, + 0, 0, 0, 0, 0, 0, 0, + &everyoneSid)) + { + hResult = GetLastError(); + goto end; + } + + // Now create the Access Control List (ACL) for the Security descriptor + + // Everyone GENERIC_ALL access + ea[0].grfAccessMode = SET_ACCESS; + ea[0].grfAccessPermissions = GENERIC_ALL; + ea[0].grfInheritance = NO_INHERITANCE; + ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID; + ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP; + ea[0].Trustee.ptstrName = static_cast(everyoneSid); + + // Custom capability GENERIC_ALL access + ea[1].grfAccessMode = SET_ACCESS; + ea[1].grfAccessPermissions = GENERIC_ALL; + ea[1].grfInheritance = NO_INHERITANCE; + ea[1].Trustee.TrusteeForm = TRUSTEE_IS_SID; + ea[1].Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN; + ea[1].Trustee.ptstrName = static_cast(everyoneSid); + + hResult = SetEntriesInAcl(ARRAYSIZE(ea), ea, nullptr, &acl); + + if (hResult != ERROR_SUCCESS) + { + goto end; + } + + // Initialize an empty security descriptor + if (!InitializeSecurityDescriptor(&rpcSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION)) + { + hResult = GetLastError(); + goto end; + } + + // Assign the ACL to the security descriptor + if (!SetSecurityDescriptorDacl(&rpcSecurityDescriptor, TRUE, acl, FALSE)) + { + hResult = GetLastError(); + goto end; + } + + // + // Bind to LRPC using dynamic endpoints + // + hResult = RpcServerUseProtseqEp( + reinterpret_cast(protocolSequence), + RPC_C_PROTSEQ_MAX_REQS_DEFAULT, + reinterpret_cast(RPC_STATIC_ENDPOINT), + &rpcSecurityDescriptor); + + if (hResult != S_OK) + { + goto end; + } + + hResult = RpcServerRegisterIf3( + RpcInterface_v1_0_s_ifspec, + nullptr, + nullptr, + RPC_IF_AUTOLISTEN | RPC_IF_ALLOW_LOCAL_ONLY, + RPC_C_LISTEN_MAX_CALLS_DEFAULT, + 0, + nullptr, + &rpcSecurityDescriptor); + + if (hResult != S_OK) + { + goto end; + } + + hResult = RpcServerInqBindings(&BindingVector); + + if (hResult != S_OK) + { + goto end; + } + + hResult = RpcEpRegister( + RpcInterface_v1_0_s_ifspec, + BindingVector, + nullptr, + nullptr); + + if (hResult != S_OK) + { + goto end; + } + + hResult = RpcServerListen( + minCalls, + RPC_C_LISTEN_MAX_CALLS_DEFAULT, + dontWait); + + if (hResult == RPC_S_ALREADY_LISTENING) + { + hResult = RPC_S_OK; + } + +end: + + // Cleanup sids + FreeSidArray(capabilityGroupSids, capabilityGroupSidCount); + FreeSidArray(capabilitySids, capabilitySidCount); + + if (everyoneSid != nullptr) + { + FreeSid(everyoneSid); + } + + // cleanup acl + if (acl != nullptr) + { + LocalFree(acl); + } + + return hResult; +} + +// +// Notify rpc server to stop listening to incoming rpc calls +// +void RpcServerDisconnect() +{ + DWORD hResult = S_OK; + ShutdownRequested = true; + hResult = RpcServerUnregisterIf(RpcInterface_v1_0_s_ifspec, nullptr, 0); + + RpcEpUnregister(RpcInterface_v1_0_s_ifspec, BindingVector, nullptr); + + if (BindingVector != nullptr) + { + RpcBindingVectorFree(&BindingVector); + BindingVector = nullptr; + } +} + +// +// Rpc method to retrieve client context handle +// +void RemoteOpen( + _In_ handle_t hBinding, + _Out_ PPCONTEXT_HANDLE_TYPE pphContext) +{ + *pphContext = static_cast(midl_user_allocate(sizeof(METERING_CONTEXT))); + METERING_CONTEXT* meteringContext = static_cast(*pphContext); + meteringContext->metering = new Metering(DEFAULT_METERING_PERIOD); +} + +// +// Rpc method to close the client context handle +// +void RemoteClose(_Inout_ PPCONTEXT_HANDLE_TYPE pphContext) +{ + if (*pphContext == nullptr) + { + //Log error, client tried to close a NULL handle. + return; + } + + METERING_CONTEXT* meteringContext = static_cast(*pphContext); + delete meteringContext->metering; + MIDL_user_free(meteringContext); + + // This tells the run-time, when it is marshalling the out + // parameters, that the context handle has been closed normally. + *pphContext = nullptr; +} + +// +// Routine to cleanup client context when client has died with active +// connection with server +// +void __RPC_USER PCONTEXT_HANDLE_TYPE_rundown( + _In_ PCONTEXT_HANDLE_TYPE phContext) +{ + StopMetering(phContext); + RemoteClose(&phContext); +} + +#pragma region METERING_RPCROUTINES + +void StartMetering( + _In_ PCONTEXT_HANDLE_TYPE phContext, + _In_ __int64 period, + _In_ __int64 context) +{ + std::cout << "start metering" << std::endl; + METERING_CONTEXT* meteringContext = static_cast(phContext); + meteringContext->metering->StartMetering(period, context); + std::cout << "done metering" << std::endl; +} + +void SetSamplePeriod( + _In_ PCONTEXT_HANDLE_TYPE phContext, + _In_ __int64 period) +{ + METERING_CONTEXT* meteringContext = static_cast(phContext); + meteringContext->metering->SetSamplePeriod(period); +} + + +void StopMetering(_In_ PCONTEXT_HANDLE_TYPE phContext) +{ + METERING_CONTEXT* meteringContext = static_cast(phContext); + meteringContext->metering->StopMetering(); +} + +#pragma endregion METERING_RPCROUTINES + +/******************************************************/ +/* MIDL allocate and free */ +/******************************************************/ + +void __RPC_FAR * __RPC_USER midl_user_allocate(_In_ size_t len) +{ + return(malloc(len)); +} + +void __RPC_USER midl_user_free(_In_ void __RPC_FAR* ptr) +{ + free(ptr); +} diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.h new file mode 100644 index 00000000..bc7294db --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.h @@ -0,0 +1,16 @@ +#include "metering.h" + +#define RPC_STATIC_ENDPOINT L"HsaSampleRpcEndpoint" + +// Client context used for making rpc calls using context handle +// https://msdn.microsoft.com/en-us/library/windows/desktop/aa378674(v=vs.85).aspx +typedef struct +{ + RpcServer::Metering* metering; +} METERING_CONTEXT; + +// Create a rpc server endpoint and listen to incoming rpc calls +DWORD RpcServerStart(); + +// Signal the rpc server to stop listening to incoming rpc calls +void RpcServerDisconnect(); diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj new file mode 100644 index 00000000..b5c043dc --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj @@ -0,0 +1,284 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Release + ARM + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {ADFC4322-5F0E-5BFD-83DA-19B35EFD513B} + Win32Proj + RpcServer + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + true + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + false + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + %(AdditionalIncludeDirectories);$(OutDir) + + + Console + true + onecoreuap.lib;%(AdditionalDependencies);rpcrt4.lib + false + %(IgnoreSpecificDefaultLibraries);kernel32.lib;user32.lib;shell32.lib;gdi32.lib + + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + %(AdditionalIncludeDirectories);$(OutDir) + + + Console + true + onecoreuap.lib;%(AdditionalDependencies);rpcrt4.lib + false + %(IgnoreSpecificDefaultLibraries);kernel32.lib;user32.lib;shell32.lib;gdi32.lib + + + + + Use + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + %(AdditionalIncludeDirectories);$(OutDir) + + + Console + true + onecoreuap.lib;%(AdditionalDependencies);rpcrt4.lib + false + %(IgnoreSpecificDefaultLibraries);kernel32.lib;user32.lib;shell32.lib;gdi32.lib + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + %(AdditionalIncludeDirectories);$(OutDir) + MultiThreaded + + + Console + true + true + true + onecoreuap.lib;%(AdditionalDependencies);ucrt.lib;rpcrt4.lib;libcmt.lib;libvcruntime.lib + true + %(IgnoreSpecificDefaultLibraries);kernel32.lib;user32.lib;shell32.lib;gdi32.lib + /VERBOSE %(AdditionalOptions) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions); + true + %(AdditionalIncludeDirectories);$(OutDir) + MultiThreaded + + + Console + true + true + true + onecoreuap.lib;%(AdditionalDependencies);ucrt.lib;rpcrt4.lib;libcmt.lib;libvcruntime.lib + true + %(IgnoreSpecificDefaultLibraries);kernel32.lib;user32.lib;shell32.lib;gdi32.lib + /VERBOSE %(AdditionalOptions) + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + %(AdditionalIncludeDirectories);$(OutDir) + MultiThreaded + + + Console + true + true + true + onecoreuap.lib;%(AdditionalDependencies);ucrt.lib;rpcrt4.lib;libcmt.lib;libvcruntime.lib + true + %(IgnoreSpecificDefaultLibraries);kernel32.lib;user32.lib;shell32.lib;gdi32.lib + /VERBOSE %(AdditionalOptions) + + + + + + + + + + + + + + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + + + + Create + Create + Create + Create + Create + Create + + + + + + + + + + + + \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj.filters b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj.filters new file mode 100644 index 00000000..9644ad4e --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/RpcServer.vcxproj.filters @@ -0,0 +1,76 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + + + Source Files + + + \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.cpp new file mode 100644 index 00000000..793a7009 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.cpp @@ -0,0 +1,155 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "stdafx.h" + +#pragma region Includes +#include "SampleService.h" +#include "RpcServer.h" +#include +#pragma endregion + +CSampleService::CSampleService( + PWSTR pszServiceName, + BOOL fCanStop, + BOOL fCanShutdown, + BOOL fCanPauseContinue) + : CServiceBase(pszServiceName, fCanStop, fCanShutdown, fCanPauseContinue) +{ +} + +void CSampleService::WriteEventLogEntry(PWSTR pszMessage, BYTE bLevel) +{ + if (IsConsoleRun()) + { + wprintf(L"%d: %ls\n", bLevel, pszMessage); + } + __super::WriteEventLogEntry(pszMessage, bLevel); +} + +CSampleService::~CSampleService(void) +{ +} + +// +// This is the thread pool work callback function. +// +VOID CALLBACK ServiceWorkerThread( + _In_ PTP_CALLBACK_INSTANCE /*Instance*/, + _In_ PVOID Parameter, + _In_ PTP_WORK /*Work*/) +{ + // + // Do something when the work callback is invoked. + // + { + _int64 status = RpcServerStart(); + if (status) + { + CSampleService* sampleService = static_cast(Parameter); + sampleService->Stop(); + } + } + + return; +} + +// +// FUNCTION: CSampleService::OnStart(DWORD, LPWSTR *) +// +// PURPOSE: The function is executed when a Start command is sent to the +// service by the SCM or when the operating system starts (for a service +// that starts automatically). It specifies actions to take when the +// service starts. In this code sample, OnStart logs a service-start +// message to the Application log, and queues the main service function for +// execution in a thread pool worker thread. +// +// PARAMETERS: +// * dwArgc - number of command line arguments +// * lpszArgv - array of command line arguments +// +// NOTE: A service application is designed to be long running. Therefore, +// it usually polls or monitors something in the system. The monitoring is +// set up in the OnStart method. However, OnStart does not actually do the +// monitoring. The OnStart method must return to the operating system after +// the service's operation has begun. It must not loop forever or block. To +// set up a simple monitoring mechanism, one general solution is to create +// a timer in OnStart. The timer would then raise events in your code +// periodically, at which time your service could do its monitoring. The +// other solution is to spawn a new thread to perform the main service +// functions, which is demonstrated in this code sample. +// +void CSampleService::OnStart( + _In_ DWORD dwArgc, + _In_ LPWSTR *lpszArgv) +{ + // Log a service start message to the Application log. + WriteEventLogEntry(L"CppWindowsService in OnStart", TRACE_LEVEL_INFORMATION); + + // Queue the main service function for execution in a worker thread. + PTP_WORK_CALLBACK workcallback = ServiceWorkerThread; + m_work = CreateThreadpoolWork(workcallback, this, nullptr); + + if (NULL == m_work) + { + // TODO: Capture get last error + WriteEventLogEntry(L"CreateThreadpoolWork failed", TRACE_LEVEL_ERROR); + } + + // + // Submit the work to the pool. Because this was a pre-allocated + // work item (using CreateThreadpoolWork), it is guaranteed to execute. + // + SubmitThreadpoolWork(m_work); +} + +// +// FUNCTION: CSampleService::ConsoleRun() +// +// PURPOSE: The function is executed to simulate OnStart in +// console mode. +// +void CSampleService::ConsoleRun() +{ + m_runningInConsole = true; + + WriteEventLogEntry(L"Starting Rpc Server..", TRACE_LEVEL_INFORMATION); + long status = RpcServerStart(); + + if (status) + { + printf_s("RpcServerConnect returned: 0x%x\n", status); + WriteEventLogEntry(L"Starting Rpc Server..", TRACE_LEVEL_INFORMATION); + exit(static_cast(status)); + } +} + +// +// FUNCTION: CSampleService::OnStop() +// +// PURPOSE: The function is executed when a Stop command is sent to the +// service by SCM. It specifies actions to take when a service stops +// running. In this code sample, OnStop logs a service-stop message to the +// Application log, and waits for the finish of the main service function. +// +// COMMENTS: +// Be sure to periodically call ReportServiceStatus() with +// SERVICE_STOP_PENDING if the procedure is going to take long time. +// +void CSampleService::OnStop() +{ + // Log a service stop message to the Application log. + WriteEventLogEntry(L"CppWindowsService in OnStop", TRACE_LEVEL_INFORMATION); + + // Instruct server to stop listening to remote procedure calls and + // unregister rpc interface + RpcServerDisconnect(); +} \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.h new file mode 100644 index 00000000..04621b3e --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/SampleService.h @@ -0,0 +1,46 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +// Provides a sample service class that derives from the service base class - +// CServiceBase. The sample service logs the service start and stop +// information to the Application event log, and shows how to run the main +// function of the service in a thread pool worker thread. + +#pragma once + +#include "ServiceBase.h" + +class CSampleService : public CServiceBase +{ +public: + + CSampleService(PWSTR pszServiceName, + BOOL fCanStop = TRUE, + BOOL fCanShutdown = TRUE, + BOOL fCanPauseContinue = FALSE); + void ConsoleRun(); + bool IsConsoleRun() + { + return m_runningInConsole; + } + void WriteEventLogEntry(PWSTR pszMessage, BYTE bLevel) override; + virtual ~CSampleService(void); + +protected: + + virtual void OnStart(DWORD dwArgc, PWSTR *pszArgv) override; + virtual void OnStop() override; + + +private: + PTP_WORK m_work = nullptr; + bool m_runningInConsole = false; +}; \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.cpp new file mode 100644 index 00000000..117d740c --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.cpp @@ -0,0 +1,566 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "stdafx.h" +#pragma region Includes + +#include "ServiceBase.h" +#include +#include +#include +#include +#pragma endregion + +// +// HSA Service trace event provider +// {BE2E880E-F79F-4C30-9C95-09F003A0A7EA} +// +EXTERN_C __declspec(selectany) const GUID HSA_SERVICE_PROVIDER_GUID = { 0xbe2e880e, 0xf79f, 0x4c30,{ 0x9c, 0x95, 0x9, 0xf0, 0x3, 0xa0, 0xa7, 0xea } }; + +#pragma region Static Members + +// Initialize the singleton service instance. +CServiceBase *CServiceBase::s_service = nullptr; + + +// +// FUNCTION: CServiceBase::Run(CServiceBase &) +// +// PURPOSE: Register the executable for a service with the Service Control +// Manager (SCM). After you call Run(ServiceBase), the SCM issues a Start +// command, which results in a call to the OnStart method in the service. +// This method blocks until the service has stopped. +// +// PARAMETERS: +// * service - the reference to a CServiceBase object. It will become the +// singleton service instance of this service application. +// +// RETURN VALUE: If the function succeeds, the return value is TRUE. If the +// function fails, the return value is FALSE. To get extended error +// information, call GetLastError. +// +BOOL CServiceBase::Run(CServiceBase &service) +{ + s_service = &service; + + SERVICE_TABLE_ENTRY serviceTable[] = + { + { service.m_name, ServiceMain }, + { nullptr, nullptr } + }; + + // Connects the main thread of a service process to the service control + // manager, which causes the thread to be the service control dispatcher + // thread for the calling process. This call returns when the service has + // stopped. The process should simply terminate when the call returns. + return StartServiceCtrlDispatcher(serviceTable); +} + + +// +// FUNCTION: CServiceBase::ServiceMain(DWORD, PWSTR *) +// +// PURPOSE: Entry point for the service. It registers the handler function +// for the service and starts the service. +// +// PARAMETERS: +// * dwArgc - number of command line arguments +// * lpszArgv - array of command line arguments +// +void WINAPI CServiceBase::ServiceMain(DWORD dwArgc, PWSTR *pszArgv) +{ + assert(s_service != NULL); + + // Register the handler function for the service + s_service->m_statusHandle = RegisterServiceCtrlHandler( + s_service->m_name, ServiceCtrlHandler); + + if (s_service->m_statusHandle == NULL) + { + throw GetLastError(); + } + + // Start the service. + s_service->Start(dwArgc, pszArgv); +} + + +// +// FUNCTION: CServiceBase::ServiceCtrlHandler(DWORD) +// +// PURPOSE: The function is called by the SCM whenever a control code is +// sent to the service. +// +// PARAMETERS: +// * dwCtrlCode - the control code. This parameter can be one of the +// following values: +// +// SERVICE_CONTROL_CONTINUE +// SERVICE_CONTROL_INTERROGATE +// SERVICE_CONTROL_NETBINDADD +// SERVICE_CONTROL_NETBINDDISABLE +// SERVICE_CONTROL_NETBINDREMOVE +// SERVICE_CONTROL_PARAMCHANGE +// SERVICE_CONTROL_PAUSE +// SERVICE_CONTROL_SHUTDOWN +// SERVICE_CONTROL_STOP +// +// This parameter can also be a user-defined control code ranges from 128 +// to 255. +// +void WINAPI CServiceBase::ServiceCtrlHandler(DWORD dwCtrl) +{ + switch (dwCtrl) + { + case SERVICE_CONTROL_STOP: s_service->Stop(); break; + case SERVICE_CONTROL_PAUSE: s_service->Pause(); break; + case SERVICE_CONTROL_CONTINUE: s_service->Continue(); break; + case SERVICE_CONTROL_SHUTDOWN: s_service->Shutdown(); break; + case SERVICE_CONTROL_INTERROGATE: break; + default: break; + } +} + +#pragma endregion + + +#pragma region Service Constructor and Destructor + +// +// FUNCTION: CServiceBase::CServiceBase(PWSTR, BOOL, BOOL, BOOL) +// +// PURPOSE: The constructor of CServiceBase. It initializes a new instance +// of the CServiceBase class. The optional parameters (fCanStop, +/// fCanShutdown and fCanPauseContinue) allow you to specify whether the +// service can be stopped, paused and continued, or be notified when system +// shutdown occurs. +// +// PARAMETERS: +// * pszServiceName - the name of the service +// * fCanStop - the service can be stopped +// * fCanShutdown - the service is notified when system shutdown occurs +// * fCanPauseContinue - the service can be paused and continued +// +CServiceBase::CServiceBase( + PWSTR pszServiceName, + BOOL fCanStop, + BOOL fCanShutdown, + BOOL fCanPauseContinue) +{ + // Service name must be a valid string and cannot be NULL. + m_name = (pszServiceName == nullptr) ? L"" : pszServiceName; + + m_statusHandle = nullptr; + + // The service runs in its own process. + m_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; + + // The service is starting. + m_status.dwCurrentState = SERVICE_START_PENDING; + + // The accepted commands of the service. + DWORD dwControlsAccepted = 0; + if (fCanStop) + dwControlsAccepted |= SERVICE_ACCEPT_STOP; + if (fCanShutdown) + dwControlsAccepted |= SERVICE_ACCEPT_SHUTDOWN; + if (fCanPauseContinue) + dwControlsAccepted |= SERVICE_ACCEPT_PAUSE_CONTINUE; + m_status.dwControlsAccepted = dwControlsAccepted; + + m_status.dwWin32ExitCode = NO_ERROR; + m_status.dwServiceSpecificExitCode = 0; + m_status.dwCheckPoint = 0; + m_status.dwWaitHint = 0; + + NTSTATUS status = EventRegister(&HSA_SERVICE_PROVIDER_GUID, + nullptr, + nullptr, + &m_etwRegHandle); + if (ERROR_SUCCESS != status) + { + wprintf(L"Provider not registered. EventRegister failed with %d\n", status); + } +} + + +// +// FUNCTION: CServiceBase::~CServiceBase() +// +// PURPOSE: The virtual destructor of CServiceBase. +// +CServiceBase::~CServiceBase(void) +{ + if (m_etwRegHandle != NULL) + { + EventUnregister(m_etwRegHandle); + } +} + +#pragma endregion + + +#pragma region Service Start, Stop, Pause, Continue, and Shutdown + +// +// FUNCTION: CServiceBase::Start(DWORD, PWSTR *) +// +// PURPOSE: The function starts the service. It calls the OnStart virtual +// function in which you can specify the actions to take when the service +// starts. If an error occurs during the startup, the error will be logged +// in the Application event log, and the service will be stopped. +// +// PARAMETERS: +// * dwArgc - number of command line arguments +// * lpszArgv - array of command line arguments +// +void CServiceBase::Start(DWORD dwArgc, PWSTR *pszArgv) +{ + WriteEventLogEntry(L"Service trying to start.", TRACE_LEVEL_ERROR); + try + { + // Tell SCM that the service is starting. + SetServiceStatus(SERVICE_START_PENDING); + + // Perform service-specific initialization. + OnStart(dwArgc, pszArgv); + + // Tell SCM that the service is started. + SetServiceStatus(SERVICE_RUNNING); + } + catch (DWORD dwError) + { + // Log the error. + WriteErrorLogEntry(L"Service Start", dwError); + + // Set the service status to be stopped. + SetServiceStatus(SERVICE_STOPPED, dwError); + } + catch (...) + { + // Log the error. + WriteEventLogEntry(L"Service failed to start.", TRACE_LEVEL_ERROR); + + // Set the service status to be stopped. + SetServiceStatus(SERVICE_STOPPED); + } +} + + +// +// FUNCTION: CServiceBase::OnStart(DWORD, PWSTR *) +// +// PURPOSE: When implemented in a derived class, executes when a Start +// command is sent to the service by the SCM or when the operating system +// starts (for a service that starts automatically). Specifies actions to +// take when the service starts. Be sure to periodically call +// CServiceBase::SetServiceStatus() with SERVICE_START_PENDING if the +// procedure is going to take long time. You may also consider spawning a +// new thread in OnStart to perform time-consuming initialization tasks. +// +// PARAMETERS: +// * dwArgc - number of command line arguments +// * lpszArgv - array of command line arguments +// +void CServiceBase::OnStart(DWORD dwArgc, PWSTR *pszArgv) +{ +} + + +// +// FUNCTION: CServiceBase::Stop() +// +// PURPOSE: The function stops the service. It calls the OnStop virtual +// function in which you can specify the actions to take when the service +// stops. If an error occurs, the error will be logged in the Application +// event log, and the service will be restored to the original state. +// +void CServiceBase::Stop() +{ + DWORD dwOriginalState = m_status.dwCurrentState; + try + { + // Tell SCM that the service is stopping. + SetServiceStatus(SERVICE_STOP_PENDING); + + // Perform service-specific stop operations. + OnStop(); + + // Tell SCM that the service is stopped. + SetServiceStatus(SERVICE_STOPPED); + } + catch (DWORD dwError) + { + // Log the error. + WriteErrorLogEntry(L"Service Stop", dwError); + + // Set the orginal service status. + SetServiceStatus(dwOriginalState); + } + catch (...) + { + // Log the error. + WriteEventLogEntry(L"Service failed to stop.", TRACE_LEVEL_ERROR); + + // Set the orginal service status. + SetServiceStatus(dwOriginalState); + } +} + + +// +// FUNCTION: CServiceBase::OnStop() +// +// PURPOSE: When implemented in a derived class, executes when a Stop +// command is sent to the service by the SCM. Specifies actions to take +// when a service stops running. Be sure to periodically call +// CServiceBase::SetServiceStatus() with SERVICE_STOP_PENDING if the +// procedure is going to take long time. +// +void CServiceBase::OnStop() +{ +} + + +// +// FUNCTION: CServiceBase::Pause() +// +// PURPOSE: The function pauses the service if the service supports pause +// and continue. It calls the OnPause virtual function in which you can +// specify the actions to take when the service pauses. If an error occurs, +// the error will be logged in the Application event log, and the service +// will become running. +// +void CServiceBase::Pause() +{ + try + { + // Tell SCM that the service is pausing. + SetServiceStatus(SERVICE_PAUSE_PENDING); + + // Perform service-specific pause operations. + OnPause(); + + // Tell SCM that the service is paused. + SetServiceStatus(SERVICE_PAUSED); + } + catch (DWORD dwError) + { + // Log the error. + WriteErrorLogEntry(L"Service Pause", dwError); + + // Tell SCM that the service is still running. + SetServiceStatus(SERVICE_RUNNING); + } + catch (...) + { + // Log the error. + WriteEventLogEntry(L"Service failed to pause.", TRACE_LEVEL_ERROR); + + // Tell SCM that the service is still running. + SetServiceStatus(SERVICE_RUNNING); + } +} + + +// +// FUNCTION: CServiceBase::OnPause() +// +// PURPOSE: When implemented in a derived class, executes when a Pause +// command is sent to the service by the SCM. Specifies actions to take +// when a service pauses. +// +void CServiceBase::OnPause() +{ +} + + +// +// FUNCTION: CServiceBase::Continue() +// +// PURPOSE: The function resumes normal functioning after being paused if +// the service supports pause and continue. It calls the OnContinue virtual +// function in which you can specify the actions to take when the service +// continues. If an error occurs, the error will be logged in the +// Application event log, and the service will still be paused. +// +void CServiceBase::Continue() +{ + try + { + // Tell SCM that the service is resuming. + SetServiceStatus(SERVICE_CONTINUE_PENDING); + + // Perform service-specific continue operations. + OnContinue(); + + // Tell SCM that the service is running. + SetServiceStatus(SERVICE_RUNNING); + } + catch (DWORD dwError) + { + // Log the error. + WriteErrorLogEntry(L"Service Continue", dwError); + + // Tell SCM that the service is still paused. + SetServiceStatus(SERVICE_PAUSED); + } + catch (...) + { + // Log the error. + WriteEventLogEntry(L"Service failed to resume.", TRACE_LEVEL_ERROR); + + // Tell SCM that the service is still paused. + SetServiceStatus(SERVICE_PAUSED); + } +} + + +// +// FUNCTION: CServiceBase::OnContinue() +// +// PURPOSE: When implemented in a derived class, OnContinue runs when a +// Continue command is sent to the service by the SCM. Specifies actions to +// take when a service resumes normal functioning after being paused. +// +void CServiceBase::OnContinue() +{ +} + + +// +// FUNCTION: CServiceBase::Shutdown() +// +// PURPOSE: The function executes when the system is shutting down. It +// calls the OnShutdown virtual function in which you can specify what +// should occur immediately prior to the system shutting down. If an error +// occurs, the error will be logged in the Application event log. +// +void CServiceBase::Shutdown() +{ + try + { + // Perform service-specific shutdown operations. + OnShutdown(); + + // Tell SCM that the service is stopped. + SetServiceStatus(SERVICE_STOPPED); + } + catch (DWORD dwError) + { + // Log the error. + WriteErrorLogEntry(L"Service Shutdown", dwError); + } + catch (...) + { + // Log the error. + WriteEventLogEntry(L"Service failed to shut down.", TRACE_LEVEL_ERROR); + } +} + + +// +// FUNCTION: CServiceBase::OnShutdown() +// +// PURPOSE: When implemented in a derived class, executes when the system +// is shutting down. Specifies what should occur immediately prior to the +// system shutting down. +// +void CServiceBase::OnShutdown() +{ +} + +#pragma endregion + + +#pragma region Helper Functions + +// +// FUNCTION: CServiceBase::SetServiceStatus(DWORD, DWORD, DWORD) +// +// PURPOSE: The function sets the service status and reports the status to +// the SCM. +// +// PARAMETERS: +// * dwCurrentState - the state of the service +// * dwWin32ExitCode - error code to report +// * dwWaitHint - estimated time for pending operation, in milliseconds +// +void CServiceBase::SetServiceStatus( + _In_ DWORD dwCurrentState, + _In_ DWORD dwWin32ExitCode, + _In_ DWORD dwWaitHint) +{ + static DWORD dwCheckPoint = 1; + + // Fill in the SERVICE_STATUS structure of the service. + + m_status.dwCurrentState = dwCurrentState; + m_status.dwWin32ExitCode = dwWin32ExitCode; + m_status.dwWaitHint = dwWaitHint; + + m_status.dwCheckPoint = + ((dwCurrentState == SERVICE_RUNNING) || + (dwCurrentState == SERVICE_STOPPED)) ? + 0 : dwCheckPoint++; + + // Report the status of the service to the SCM. + ::SetServiceStatus(m_statusHandle, &m_status); +} + + +// +// FUNCTION: CServiceBase::WriteEventLogEntry(PWSTR, WORD) +// +// PURPOSE: Log an event. +// +// PARAMETERS: +// * pszMessage - string message to be logged. +// * wType - the type of event to be logged. The parameter can be one of +// the following values. +// +// EVENTLOG_SUCCESS +// EVENTLOG_AUDIT_FAILURE +// EVENTLOG_AUDIT_SUCCESS +// EVENTLOG_ERROR_TYPE +// EVENTLOG_INFORMATION_TYPE +// EVENTLOG_WARNING_TYPE +// +void CServiceBase::WriteEventLogEntry( + _In_ PWSTR pszMessage, + _In_ BYTE bLevel) +{ + if (m_etwRegHandle != NULL) + { + EventWriteString(m_etwRegHandle, bLevel, 0, pszMessage); + } +} + +// +// FUNCTION: CServiceBase::WriteErrorLogEntry(PWSTR, DWORD) +// +// PURPOSE: Log an event. +// +// PARAMETERS: +// * pszFunction - the function that gives the error +// * dwError - the error code +// +void CServiceBase::WriteErrorLogEntry( + _In_ PWSTR pszFunction, + _In_ DWORD dwError) +{ + wchar_t szMessage[260]; + StringCchPrintf(szMessage, ARRAYSIZE(szMessage), + L"%s failed w/err 0x%08lx", pszFunction, dwError); + WriteEventLogEntry(szMessage, TRACE_LEVEL_ERROR); +} + +#pragma endregion \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.h new file mode 100644 index 00000000..ebae808e --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceBase.h @@ -0,0 +1,121 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +// Provides a base class for a service that will exist as part of a service +// application. CServiceBase must be derived from when creating a new service +// class. + +#pragma once + +#include +#include + +class CServiceBase +{ +public: + + // Register the executable for a service with the Service Control Manager + // (SCM). After you call Run(ServiceBase), the SCM issues a Start command, + // which results in a call to the OnStart method in the service. This + // method blocks until the service has stopped. + static BOOL Run(CServiceBase& service); + + // Service object constructor. The optional parameters (fCanStop, + // fCanShutdown and fCanPauseContinue) allow you to specify whether the + // service can be stopped, paused and continued, or be notified when + // system shutdown occurs. + CServiceBase(PWSTR pszServiceName, + BOOL fCanStop = TRUE, + BOOL fCanShutdown = TRUE, + BOOL fCanPauseContinue = FALSE); + + // Service object destructor. + virtual ~CServiceBase(void); + + // Stop the service. + void Stop(); + +protected: + + // When implemented in a derived class, executes when a Start command is + // sent to the service by the SCM or when the operating system starts + // (for a service that starts automatically). Specifies actions to take + // when the service starts. + virtual void OnStart(DWORD dwArgc, PWSTR *pszArgv); + + // When implemented in a derived class, executes when a Stop command is + // sent to the service by the SCM. Specifies actions to take when a + // service stops running. + virtual void OnStop(); + + // When implemented in a derived class, executes when a Pause command is + // sent to the service by the SCM. Specifies actions to take when a + // service pauses. + virtual void OnPause(); + + // When implemented in a derived class, OnContinue runs when a Continue + // command is sent to the service by the SCM. Specifies actions to take + // when a service resumes normal functioning after being paused. + virtual void OnContinue(); + + // When implemented in a derived class, executes when the system is + // shutting down. Specifies what should occur immediately prior to the + // system shutting down. + virtual void OnShutdown(); + + // Set the service status and report the status to the SCM. + void SetServiceStatus(DWORD dwCurrentState, + DWORD dwWin32ExitCode = NO_ERROR, + DWORD dwWaitHint = 0); + + // Log an event. + virtual void WriteEventLogEntry(PWSTR pszMessage, BYTE bLevel); + + // Log an event. + void WriteErrorLogEntry(PWSTR pszFunction, + DWORD dwError = GetLastError()); + +private: + + // Entry point for the service. It registers the handler function for the + // service and starts the service. + static void WINAPI ServiceMain(DWORD dwArgc, LPWSTR *lpszArgv); + + // The function is called by the SCM whenever a control code is sent to + // the service. + static void WINAPI ServiceCtrlHandler(DWORD dwCtrl); + + // Start the service. + void Start(DWORD dwArgc, PWSTR *pszArgv); + + // Pause the service. + void Pause(); + + // Resume the service after being paused. + void Continue(); + + // Execute when the system is shutting down. + void Shutdown(); + + // The singleton service instance. + static CServiceBase *s_service; + + // The name of the service + PWSTR m_name; + + // The status of the service + SERVICE_STATUS m_status; + + // The service status handle + SERVICE_STATUS_HANDLE m_statusHandle; + + REGHANDLE m_etwRegHandle; +}; \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.cpp new file mode 100644 index 00000000..27b107a9 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.cpp @@ -0,0 +1,191 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "stdafx.h" +#pragma region "Includes" + +#include +#include +#include "ServiceInstaller.h" +#pragma endregion + + +// +// FUNCTION: InstallService +// +// PURPOSE: Install the current application as a service to the local +// service control manager database. +// +// PARAMETERS: +// * pszServiceName - the name of the service to be installed +// * pszDisplayName - the display name of the service +// * dwStartType - the service start option. This parameter can be one of +// the following values: SERVICE_AUTO_START, SERVICE_BOOT_START, +// SERVICE_DEMAND_START, SERVICE_DISABLED, SERVICE_SYSTEM_START. +// * pszDependencies - a pointer to a double null-terminated array of null- +// separated names of services or load ordering groups that the system +// must start before this service. +// * pszAccount - the name of the account under which the service runs. +// * pszPassword - the password to the account name. +// +// NOTE: If the function fails to install the service, it prints the error +// in the standard output stream for users to diagnose the problem. +// +void InstallService( + _In_ PWSTR pszServiceName, + _In_ PWSTR pszDisplayName, + _In_ DWORD dwStartType, + _In_ PWSTR pszDependencies, + _In_ PWSTR pszAccount, + _In_ PWSTR pszPassword) +{ + wchar_t szPath[MAX_PATH]; + SC_HANDLE schSCManager = nullptr; + SC_HANDLE schService = nullptr; + + if (GetModuleFileName(nullptr, szPath, ARRAYSIZE(szPath)) == 0) + { + wprintf(L"GetModuleFileName failed w/err 0x%08lx\n", GetLastError()); + goto Cleanup; + } + + // Open the local default service control manager database + schSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT | + SC_MANAGER_CREATE_SERVICE); + if (schSCManager == nullptr) + { + wprintf(L"OpenSCManager failed w/err 0x%08lx\n", GetLastError()); + goto Cleanup; + } + + // Install the service into SCM by calling CreateService + schService = CreateService( + schSCManager, // SCManager database + pszServiceName, // Name of service + pszDisplayName, // Name to display + SERVICE_QUERY_STATUS, // Desired access + SERVICE_WIN32_OWN_PROCESS, // Service type + dwStartType, // Service start type + SERVICE_ERROR_NORMAL, // Error control type + szPath, // Service's binary + nullptr, // No load ordering group + nullptr, // No tag identifier + pszDependencies, // Dependencies + pszAccount, // Service running account + pszPassword // Password of the account + ); + + if (schService == nullptr) + { + wprintf(L"CreateService failed w/err 0x%08lx\n", GetLastError()); + goto Cleanup; + } + + wprintf(L"%s is installed.\n", pszServiceName); + +Cleanup: + // Centralized cleanup for all allocated resources. + if (schSCManager) + { + CloseServiceHandle(schSCManager); + schSCManager = nullptr; + } + if (schService) + { + CloseServiceHandle(schService); + schService = nullptr; + } +} + + +// +// FUNCTION: UninstallService +// +// PURPOSE: Stop and remove the service from the local service control +// manager database. +// +// PARAMETERS: +// * pszServiceName - the name of the service to be removed. +// +// NOTE: If the function fails to uninstall the service, it prints the +// error in the standard output stream for users to diagnose the problem. +// +void UninstallService(_In_ PWSTR pszServiceName) +{ + SC_HANDLE schSCManager = nullptr; + SC_HANDLE schService = nullptr; + SERVICE_STATUS ssSvcStatus = {}; + + // Open the local default service control manager database + schSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT); + if (schSCManager == nullptr) + { + wprintf(L"OpenSCManager failed w/err 0x%08lx\n", GetLastError()); + goto Cleanup; + } + + // Open the service with delete, stop, and query status permissions + schService = OpenService(schSCManager, pszServiceName, SERVICE_STOP | + SERVICE_QUERY_STATUS | DELETE); + if (schService == nullptr) + { + wprintf(L"OpenService failed w/err 0x%08lx\n", GetLastError()); + goto Cleanup; + } + + // Try to stop the service + if (ControlService(schService, SERVICE_CONTROL_STOP, &ssSvcStatus)) + { + wprintf(L"Stopping %s.", pszServiceName); + Sleep(1000); + + while (QueryServiceStatus(schService, &ssSvcStatus)) + { + if (ssSvcStatus.dwCurrentState == SERVICE_STOP_PENDING) + { + wprintf(L"."); + Sleep(1000); + } + else break; + } + + if (ssSvcStatus.dwCurrentState == SERVICE_STOPPED) + { + wprintf(L"\n%s is stopped.\n", pszServiceName); + } + else + { + wprintf(L"\n%s failed to stop.\n", pszServiceName); + } + } + + // Now remove the service by calling DeleteService. + if (!DeleteService(schService)) + { + wprintf(L"DeleteService failed w/err 0x%08lx\n", GetLastError()); + goto Cleanup; + } + + wprintf(L"%s is removed.\n", pszServiceName); + +Cleanup: + // Centralized cleanup for all allocated resources. + if (schSCManager) + { + CloseServiceHandle(schSCManager); + schSCManager = nullptr; + } + if (schService) + { + CloseServiceHandle(schService); + schService = nullptr; + } +} \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.h new file mode 100644 index 00000000..af6507e6 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/ServiceInstaller.h @@ -0,0 +1,57 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +// The file declares functions that install and uninstall the service. + +#pragma once + +// +// FUNCTION: InstallService +// +// PURPOSE: Install the current application as a service to the local +// service control manager database. +// +// PARAMETERS: +// * pszServiceName - the name of the service to be installed +// * pszDisplayName - the display name of the service +// * dwStartType - the service start option. This parameter can be one of +// the following values: SERVICE_AUTO_START, SERVICE_BOOT_START, +// SERVICE_DEMAND_START, SERVICE_DISABLED, SERVICE_SYSTEM_START. +// * pszDependencies - a pointer to a double null-terminated array of null- +// separated names of services or load ordering groups that the system +// must start before this service. +// * pszAccount - the name of the account under which the service runs. +// * pszPassword - the password to the account name. +// +// NOTE: If the function fails to install the service, it prints the error +// in the standard output stream for users to diagnose the problem. +// +void InstallService(PWSTR pszServiceName, + PWSTR pszDisplayName, + DWORD dwStartType, + PWSTR pszDependencies, + PWSTR pszAccount, + PWSTR pszPassword); + + +// +// FUNCTION: UninstallService +// +// PURPOSE: Stop and remove the service from the local service control +// manager database. +// +// PARAMETERS: +// * pszServiceName - the name of the service to be removed. +// +// NOTE: If the function fails to uninstall the service, it prints the +// error in the standard output stream for users to diagnose the problem. +// +void UninstallService(PWSTR pszServiceName); diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.cpp new file mode 100644 index 00000000..ce19a949 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// RpcServer.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.h new file mode 100644 index 00000000..306c4330 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include + +#define NOMINMAX // disable min and max macros in windows.h + +extern bool ShutdownRequested; diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/targetver.h b/general/WinHEC 2017 Lab/Toaster Driver/Service/targetver.h new file mode 100644 index 00000000..87c0086d --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster.sln b/general/WinHEC 2017 Lab/Toaster Driver/toaster.sln new file mode 100644 index 00000000..35e5dcbc --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "toaster", "toaster\toaster.vcxproj", "{2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM = Release|ARM + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|ARM.ActiveCfg = Debug|ARM + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|ARM.Build.0 = Debug|ARM + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|ARM64.Build.0 = Debug|ARM64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|x64.ActiveCfg = Debug|x64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|x64.Build.0 = Debug|x64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|x86.ActiveCfg = Debug|Win32 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Debug|x86.Build.0 = Debug|Win32 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|ARM.ActiveCfg = Release|ARM + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|ARM.Build.0 = Release|ARM + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|ARM64.ActiveCfg = Release|ARM64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|ARM64.Build.0 = Release|ARM64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|x64.ActiveCfg = Release|x64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|x64.Build.0 = Release|x64 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|x86.ActiveCfg = Release|Win32 + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/driver.h b/general/WinHEC 2017 Lab/Toaster Driver/toaster/driver.h new file mode 100644 index 00000000..8e7ade01 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/driver.h @@ -0,0 +1,80 @@ +/*++ +Copyright (c) 1990-2000 Microsoft Corporation All Rights Reserved + +Module Name: + + driver.h + +Abstract: + + This module contains the common declarations for the + bus, function and filter drivers. + +Environment: + + kernel mode only + +--*/ + +//#include "public.h" + +// +// Define an Interface Guid to access the proprietary toaster interface. +// This guid is used to identify a specific interface in IRP_MN_QUERY_INTERFACE +// handler. +// + +DEFINE_GUID(GUID_TOASTER_INTERFACE_STANDARD, + 0xe0b27630, 0x5434, 0x11d3, 0xb8, 0x90, 0x0, 0xc0, 0x4f, 0xad, 0x51, 0x71); +// {E0B27630-5434-11d3-B890-00C04FAD5171} + + +// +// GUID definition are required to be outside of header inclusion pragma to avoid +// error during precompiled headers. +// + +#ifndef __DRIVER_H +#define __DRIVER_H + +// +// Define Interface reference/dereference routines for +// Interfaces exported by IRP_MN_QUERY_INTERFACE +// + +typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context); +typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context); + +typedef +BOOLEAN +(*PTOASTER_GET_CRISPINESS_LEVEL)( + IN PVOID Context, + OUT PUCHAR Level + ); + +typedef +BOOLEAN +(*PTOASTER_SET_CRISPINESS_LEVEL)( + IN PVOID Context, + OUT UCHAR Level + ); + +typedef +BOOLEAN +(*PTOASTER_IS_CHILD_PROTECTED)( + IN PVOID Context + ); + +// +// Interface for getting and setting power level etc., +// +typedef struct _TOASTER_INTERFACE_STANDARD { + INTERFACE InterfaceHeader; + PTOASTER_GET_CRISPINESS_LEVEL GetCrispinessLevel; + PTOASTER_SET_CRISPINESS_LEVEL SetCrispinessLevel; + PTOASTER_IS_CHILD_PROTECTED IsSafetyLockEnabled; //): +} TOASTER_INTERFACE_STANDARD, *PTOASTER_INTERFACE_STANDARD; + + +#endif + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/public.h b/general/WinHEC 2017 Lab/Toaster Driver/toaster/public.h new file mode 100644 index 00000000..0628f95f --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/public.h @@ -0,0 +1,167 @@ +/*++ +Copyright (c) 1990-2000 Microsoft Corporation All Rights Reserved + +Module Name: + + public.h + +Abstract: + + This module contains the common declarations shared by driver + and user applications. + +Environment: + + user and kernel + +--*/ + +// +// Define an Interface Guid for bus enumerator class. +// This GUID is used to register (IoRegisterDeviceInterface) +// an instance of an interface so that enumerator application +// can send an ioctl to the bus driver. +// + +DEFINE_GUID (GUID_DEVINTERFACE_BUSENUM_TOASTER, + 0xD35F7840, 0x6A0C, 0x11d2, 0xB8, 0x41, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71); +// {D35F7840-6A0C-11d2-B841-00C04FAD5171} + +// +// Define an Interface Guid for toaster device class. +// This GUID is used to register (IoRegisterDeviceInterface) +// an instance of an interface so that user application +// can control the toaster device. +// + +DEFINE_GUID (GUID_DEVINTERFACE_TOASTER, + 0x781EF630, 0x72B2, 0x11d2, 0xB8, 0x52, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71); +//{781EF630-72B2-11d2-B852-00C04FAD5171} + +// +// Define a Setup Class GUID for Toaster Class. This is same +// as the TOASTSER CLASS guid in the INF files. +// + +DEFINE_GUID (GUID_DEVCLASS_TOASTER, + 0xB85B7C50, 0x6A01, 0x11d2, 0xB8, 0x41, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71); +//{B85B7C50-6A01-11d2-B841-00C04FAD5171} + +// +// Define a WMI GUID to get busenum info. +// + +DEFINE_GUID (TOASTER_BUS_WMI_STD_DATA_GUID, + 0x0006A660, 0x8F12, 0x11d2, 0xB8, 0x54, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71); +//{0006A660-8F12-11d2-B854-00C04FAD5171} + +// +// Define a WMI GUID to get toaster device info. +// + +DEFINE_GUID (TOASTER_WMI_STD_DATA_GUID, + 0xBBA21300L, 0x6DD3, 0x11d2, 0xB8, 0x44, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71); + +// +// Define a WMI GUID to represent device arrival notification WMIEvent class. +// + +DEFINE_GUID (TOASTER_NOTIFY_DEVICE_ARRIVAL_EVENT, + 0x1cdaff1, 0xc901, 0x45b4, 0xb3, 0x59, 0xb5, 0x54, 0x27, 0x25, 0xe2, 0x9c); +// {01CDAFF1-C901-45b4-B359-B5542725E29C} + + +// +// GUID definition are required to be outside of header inclusion pragma to avoid +// error during precompiled headers. +// + +#ifndef __PUBLIC_H +#define __PUBLIC_H + +#define BUS_HARDWARE_IDS L"{B85B7C50-6A01-11d2-B841-00C04FAD5171}\\MsToaster\0" +#define BUS_HARDWARE_IDS_LENGTH sizeof (BUS_HARDWARE_IDS) + +#define BUSENUM_COMPATIBLE_IDS L"{B85B7C50-6A01-11d2-B841-00C04FAD5171}\\MsCompatibleToaster\0" +#define BUSENUM_COMPATIBLE_IDS_LENGTH sizeof(BUSENUM_COMPATIBLE_IDS) + + +#define FILE_DEVICE_BUSENUM FILE_DEVICE_BUS_EXTENDER + +#define BUSENUM_IOCTL(_index_) \ + CTL_CODE (FILE_DEVICE_BUSENUM, _index_, METHOD_BUFFERED, FILE_READ_DATA) + +#define IOCTL_BUSENUM_PLUGIN_HARDWARE BUSENUM_IOCTL (0x0) +#define IOCTL_BUSENUM_UNPLUG_HARDWARE BUSENUM_IOCTL (0x1) +#define IOCTL_BUSENUM_EJECT_HARDWARE BUSENUM_IOCTL (0x2) +#define IOCTL_TOASTER_DONT_DISPLAY_IN_UI_DEVICE BUSENUM_IOCTL (0x3) + +// +// Data structure used in PlugIn and UnPlug ioctls +// + +typedef struct _BUSENUM_PLUGIN_HARDWARE +{ + // + // sizeof (struct _BUSENUM_HARDWARE) + // + IN ULONG Size; + + // + // Unique serial number of the device to be enumerated. + // Enumeration will be failed if another device on the + // bus has the same serail number. + // + + IN ULONG SerialNo; + + // + // An array of (zero terminated wide character strings). The array itself + // also null terminated (ie, MULTI_SZ) + // + #pragma warning(disable:4200) // nonstandard extension used + + IN WCHAR HardwareIDs[]; + + #pragma warning(default:4200) + +} BUSENUM_PLUGIN_HARDWARE, *PBUSENUM_PLUGIN_HARDWARE; + +typedef struct _BUSENUM_UNPLUG_HARDWARE +{ + // + // sizeof (struct _REMOVE_HARDWARE) + // + + IN ULONG Size; + + // + // Serial number of the device to be plugged out + // + + ULONG SerialNo; + + ULONG Reserved[2]; + +} BUSENUM_UNPLUG_HARDWARE, *PBUSENUM_UNPLUG_HARDWARE; + +typedef struct _BUSENUM_EJECT_HARDWARE +{ + // + // sizeof (struct _EJECT_HARDWARE) + // + + IN ULONG Size; + + // + // Serial number of the device to be ejected + // + + ULONG SerialNo; + + ULONG Reserved[2]; + +} BUSENUM_EJECT_HARDWARE, *PBUSENUM_EJECT_HARDWARE; + +#endif + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.c b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.c new file mode 100644 index 00000000..6ed215db --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.c @@ -0,0 +1,418 @@ +/*++ + +Copyright (c) Microsoft Corporation. All rights reserved. + + THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY + KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR + PURPOSE. + +Module Name: + + Toaster.c + +Abstract: + + This is a simple form of function driver for toaster device. The driver + doesn't handle any PnP and Power events because the framework provides + default behavior for those events. This driver has enough support to + allow an user application (toast/notify.exe) to open the device + interface registered by the driver and send read, write or ioctl requests. + +Environment: + + Kernel mode + +--*/ + +#include "toaster.h" + +#ifdef ALLOC_PRAGMA +#pragma alloc_text (INIT, DriverEntry) +#pragma alloc_text (PAGE, ToasterEvtDeviceAdd) +#pragma alloc_text (PAGE, ToasterEvtIoRead) +#pragma alloc_text (PAGE, ToasterEvtIoWrite) +#pragma alloc_text (PAGE, ToasterEvtIoDeviceControl) +#endif + + +NTSTATUS +DriverEntry( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath + ) +/*++ + +Routine Description: + DriverEntry initializes the driver and is the first routine called by the + system after the driver is loaded. DriverEntry configures and creates a WDF driver + object. + . +Parameters Description: + + DriverObject - represents the instance of the function driver that is loaded + into memory. DriverObject is allocated by the system before the + driver is loaded, and it is released by the system after the system unloads + the function driver from memory. + + RegistryPath - represents the driver specific path in the Registry. + The function driver can use the path to store driver related data between + reboots. The path does not store hardware instance specific data. + +Return Value: + + STATUS_SUCCESS if successful, + STATUS_UNSUCCESSFUL otherwise. + +--*/ +{ + NTSTATUS status = STATUS_SUCCESS; + WDF_DRIVER_CONFIG config; + + KdPrint(("Toaster Function Driver Sample - Driver Framework Edition.\n")); + + // + // Initiialize driver config to control the attributes that + // are global to the driver. Note that framework by default + // provides a driver unload routine. If DriverEntry creates any resources + // that require clean-up in driver unload, + // you can manually override the default by supplying a pointer to the EvtDriverUnload + // callback in the config structure. In general xxx_CONFIG_INIT macros are provided to + // initialize most commonly used members. + // + + WDF_DRIVER_CONFIG_INIT( + &config, + ToasterEvtDeviceAdd + ); + + + // + // Create a framework driver object to represent our driver. + // + status = WdfDriverCreate( + DriverObject, + RegistryPath, + WDF_NO_OBJECT_ATTRIBUTES, // Driver Attributes + &config, // Driver Config Info + WDF_NO_HANDLE + ); + + if (!NT_SUCCESS(status)) { + KdPrint( ("WdfDriverCreate failed with status 0x%x\n", status)); + } + + return status; +} + + +NTSTATUS +ToasterEvtDeviceAdd( + IN WDFDRIVER Driver, + IN PWDFDEVICE_INIT DeviceInit + ) +/*++ +Routine Description: + + ToasterEvtDeviceAdd is called by the framework in response to AddDevice + call from the PnP manager. We create and initialize a WDF device object to + represent a new instance of toaster device. + +Arguments: + + Driver - Handle to a framework driver object created in DriverEntry + + DeviceInit - Pointer to a framework-allocated WDFDEVICE_INIT structure. + +Return Value: + + NTSTATUS + +--*/ +{ + NTSTATUS status = STATUS_SUCCESS; + PFDO_DATA fdoData; + WDF_IO_QUEUE_CONFIG queueConfig; + WDF_OBJECT_ATTRIBUTES fdoAttributes; + WDFDEVICE hDevice; + WDFQUEUE queue; + + UNREFERENCED_PARAMETER(Driver); + + PAGED_CODE(); + + KdPrint(("ToasterEvtDeviceAdd called\n")); + + // + // Initialize attributes and a context area for the device object. + // + // + WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&fdoAttributes, FDO_DATA); + + // + // Create a framework device object.This call will in turn create + // a WDM device object, attach to the lower stack, and set the + // appropriate flags and attributes. + // + status = WdfDeviceCreate(&DeviceInit, &fdoAttributes, &hDevice); + if (!NT_SUCCESS(status)) { + KdPrint( ("WdfDeviceCreate failed with status code 0x%x\n", status)); + return status; + } + + // + // Get the device context by using the accessor function specified in + // the WDF_DECLARE_CONTEXT_TYPE_WITH_NAME macro for FDO_DATA. + // + fdoData = ToasterFdoGetData(hDevice); + + // + // Tell the Framework that this device will need an interface + // + status = WdfDeviceCreateDeviceInterface( + hDevice, + (LPGUID) &GUID_DEVINTERFACE_TOASTER, + NULL // ReferenceString + ); + + if (!NT_SUCCESS (status)) { + KdPrint( ("WdfDeviceCreateDeviceInterface failed 0x%x\n", status)); + return status; + } + + // + // Register I/O callbacks to tell the framework that you are interested + // in handling IRP_MJ_READ, IRP_MJ_WRITE, and IRP_MJ_DEVICE_CONTROL requests. + // If a specific callback function is not specified for one ofthese, + // the request will be dispatched to the EvtIoDefault handler, if any. + // If there is no EvtIoDefault handler, the request will be failed with + // STATUS_INVALID_DEVICE_REQUEST. + // WdfIoQueueDispatchParallel means that we are capable of handling + // all the I/O requests simultaneously and we are responsible for protecting + // data that could be accessed by these callbacks simultaneously. + // A default queue gets all the requests that are not + // configured for forwarding using WdfDeviceConfigureRequestDispatching. + // + WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchParallel); + + queueConfig.EvtIoRead = ToasterEvtIoRead; + queueConfig.EvtIoWrite = ToasterEvtIoWrite; + queueConfig.EvtIoDeviceControl = ToasterEvtIoDeviceControl; + + // + // By default, Static Driver Verifier (SDV) displays a warning if it + // doesn't find the EvtIoStop callback on a power-managed queue. + // The 'assume' below causes SDV to suppress this warning. If the driver + // has not explicitly set PowerManaged to WdfFalse, the framework creates + // power-managed queues when the device is not a filter driver. Normally + // the EvtIoStop is required for power-managed queues, but for this driver + // it is not needed b/c the driver doesn't hold on to the requests or + // forward them to other drivers. This driver completes the requests + // directly in the queue's handlers. If the EvtIoStop callback is not + // implemented, the framework waits for all driver-owned requests to be + // done before moving in the Dx/sleep states or before removing the + // device, which is the correct behavior for this type of driver. + // If the requests were taking an indeterminate amount of time to complete, + // or if the driver forwarded the requests to a lower driver/another stack, + // the queue should have an EvtIoStop/EvtIoResume. + // + __analysis_assume(queueConfig.EvtIoStop != 0); + status = WdfIoQueueCreate( + hDevice, + &queueConfig, + WDF_NO_OBJECT_ATTRIBUTES, + &queue + ); + __analysis_assume(queueConfig.EvtIoStop == 0); + + if (!NT_SUCCESS (status)) { + + KdPrint( ("WdfIoQueueCreate failed 0x%x\n", status)); + return status; + } + + return status; +} + +VOID +ToasterEvtIoRead ( + WDFQUEUE Queue, + WDFREQUEST Request, + size_t Length + ) +/*++ + +Routine Description: + + Performs read from the toaster device. This event is called when the + framework receives IRP_MJ_READ requests. + +Arguments: + + Queue - Handle to the framework queue object that is associated with the + I/O request. + Request - Handle to a framework request object. + + Lenght - Length of the data buffer associated with the request. + By default, the queue does not dispatch + zero length read & write requests to the driver and instead to + complete such requests with status success. So we will never get + a zero length request. + +Return Value: + + None. + +--*/ +{ + NTSTATUS status; + ULONG_PTR bytesCopied =0; + WDFMEMORY memory; + + UNREFERENCED_PARAMETER(Queue); + UNREFERENCED_PARAMETER(Length); + + PAGED_CODE(); + + KdPrint(( "ToasterEvtIoRead: Request: 0x%p, Queue: 0x%p\n", + Request, Queue)); + + // + // Get the request memory and perform read operation here + // + status = WdfRequestRetrieveOutputMemory(Request, &memory); + if(NT_SUCCESS(status) ) { + // + // Copy data into the memory buffer using WdfMemoryCopyFromBuffer + // + } + + WdfRequestCompleteWithInformation(Request, status, bytesCopied); +} + +VOID +ToasterEvtIoWrite ( + WDFQUEUE Queue, + WDFREQUEST Request, + size_t Length + ) +/*++ + +Routine Description: + + Performs write to the toaster device. This event is called when the + framework receives IRP_MJ_WRITE requests. + +Arguments: + + Queue - Handle to the framework queue object that is associated with the + I/O request. + Request - Handle to a framework request object. + + Lenght - Length of the data buffer associated with the request. + The default property of the queue is to not dispatch + zero lenght read & write requests to the driver and + complete is with status success. So we will never get + a zero length request. + +Return Value: + + None +--*/ + +{ + NTSTATUS status; + ULONG_PTR bytesWritten =0; + WDFMEMORY memory; + + UNREFERENCED_PARAMETER(Queue); + UNREFERENCED_PARAMETER(Length); + + KdPrint(("ToasterEvtIoWrite. Request: 0x%p, Queue: 0x%p\n", + Request, Queue)); + + PAGED_CODE(); + + // + // Get the request buffer and perform write operation here + // + status = WdfRequestRetrieveInputMemory(Request, &memory); + if(NT_SUCCESS(status) ) { + // + // 1) Use WdfMemoryCopyToBuffer to copy data from the request + // to driver buffer. + // 2) Or get the buffer pointer from the request by calling + // WdfRequestRetrieveInputBuffer + // 3) Or you can get the buffer pointer from the memory handle + // by calling WdfMemoryGetBuffer. + // + bytesWritten = Length; + } + + WdfRequestCompleteWithInformation(Request, status, bytesWritten); + +} + + +VOID +ToasterEvtIoDeviceControl( + IN WDFQUEUE Queue, + IN WDFREQUEST Request, + IN size_t OutputBufferLength, + IN size_t InputBufferLength, + IN ULONG IoControlCode + ) +/*++ +Routine Description: + + This event is called when the framework receives IRP_MJ_DEVICE_CONTROL + requests from the system. + +Arguments: + + Queue - Handle to the framework queue object that is associated + with the I/O request. + Request - Handle to a framework request object. + + OutputBufferLength - length of the request's output buffer, + if an output buffer is available. + InputBufferLength - length of the request's input buffer, + if an input buffer is available. + + IoControlCode - the driver-defined or system-defined I/O control code + (IOCTL) that is associated with the request. + +Return Value: + + VOID + +--*/ +{ + NTSTATUS status= STATUS_SUCCESS; + + UNREFERENCED_PARAMETER(Queue); + UNREFERENCED_PARAMETER(OutputBufferLength); + UNREFERENCED_PARAMETER(InputBufferLength); + + KdPrint(("ToasterEvtIoDeviceControl called\n")); + + PAGED_CODE(); + + // + // Use WdfRequestRetrieveInputBuffer and WdfRequestRetrieveOutputBuffer + // to get the request buffers. + // + + switch (IoControlCode) { + + default: + status = STATUS_INVALID_DEVICE_REQUEST; + } + + // + // Complete the Request. + // + WdfRequestCompleteWithInformation(Request, status, (ULONG_PTR) 0); +} + + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.h b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.h new file mode 100644 index 00000000..fc847d2d --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.h @@ -0,0 +1,134 @@ +/*++ + +Copyright (c) 1990-2000 Microsoft Corporation All Rights Reserved + +Module Name: + + Toaster.h + +Abstract: + + Header file for the toaster driver modules. + +Environment: + + Kernel mode + +--*/ + + +#if !defined(_TOASTER_H_) +#define _TOASTER_H_ + +#include +#include + +#define NTSTRSAFE_LIB +#include + +#include "wmilib.h" +#include +#include "driver.h" +#include "public.h" + +// For Featured driver only +#ifdef TOASTER_FUNC_FEATURED +#include +#endif // TOASTER_FUNC_FEATURED + +#define TOASTER_POOL_TAG (ULONG) 'saoT' + +#define MOFRESOURCENAME L"ToasterWMI" + +#define TOASTER_FUNC_DEVICE_LOG_ID "ToasterDevice" +// +// The device extension for the device object +// +typedef struct _FDO_DATA +{ + + WDFWMIINSTANCE WmiDeviceArrivalEvent; + + BOOLEAN WmiPowerDeviceEnableRegistered; + + TOASTER_INTERFACE_STANDARD BusInterface; + +// For Featured driver only +#ifdef TOASTER_FUNC_FEATURED + RECORDER_LOG WppRecorderLog; +#endif // TOASTER_FUNC_FEATURED + +} FDO_DATA, *PFDO_DATA; + +WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_DATA, ToasterFdoGetData) + + +// +// Connector Types +// + +#define TOASTER_WMI_STD_I8042 0 +#define TOASTER_WMI_STD_SERIAL 1 +#define TOASTER_WMI_STD_PARALEL 2 +#define TOASTER_WMI_STD_USB 3 + +DRIVER_INITIALIZE DriverEntry; +EVT_WDF_DRIVER_UNLOAD ToasterEvtDriverUnload; + +EVT_WDF_DRIVER_DEVICE_ADD ToasterEvtDeviceAdd; + +EVT_WDF_DEVICE_CONTEXT_CLEANUP ToasterEvtDeviceContextCleanup; +EVT_WDF_DEVICE_D0_ENTRY ToasterEvtDeviceD0Entry; +EVT_WDF_DEVICE_D0_EXIT ToasterEvtDeviceD0Exit; +EVT_WDF_DEVICE_PREPARE_HARDWARE ToasterEvtDevicePrepareHardware; +EVT_WDF_DEVICE_RELEASE_HARDWARE ToasterEvtDeviceReleaseHardware; + +EVT_WDF_DEVICE_SELF_MANAGED_IO_INIT ToasterEvtDeviceSelfManagedIoInit; + +// +// Io events callbacks. +// +EVT_WDF_IO_QUEUE_IO_READ ToasterEvtIoRead; +EVT_WDF_IO_QUEUE_IO_WRITE ToasterEvtIoWrite; +EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL ToasterEvtIoDeviceControl; +EVT_WDF_DEVICE_FILE_CREATE ToasterEvtDeviceFileCreate; +EVT_WDF_FILE_CLOSE ToasterEvtFileClose; + +NTSTATUS +ToasterWmiRegistration( + _In_ WDFDEVICE Device + ); + +// +// Power events callbacks +// +EVT_WDF_DEVICE_ARM_WAKE_FROM_S0 ToasterEvtDeviceArmWakeFromS0; +EVT_WDF_DEVICE_ARM_WAKE_FROM_SX ToasterEvtDeviceArmWakeFromSx; +EVT_WDF_DEVICE_DISARM_WAKE_FROM_S0 ToasterEvtDeviceDisarmWakeFromS0; +EVT_WDF_DEVICE_DISARM_WAKE_FROM_SX ToasterEvtDeviceDisarmWakeFromSx; +EVT_WDF_DEVICE_WAKE_FROM_S0_TRIGGERED ToasterEvtDeviceWakeFromS0Triggered; +EVT_WDF_DEVICE_WAKE_FROM_SX_TRIGGERED ToasterEvtDeviceWakeFromSxTriggered; + +PCHAR +DbgDevicePowerString( + IN WDF_POWER_DEVICE_STATE Type + ); + +// +// WMI event callbacks +// +EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiInstanceStdDeviceDataQueryInstance; +EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiInstanceToasterControlQueryInstance; +EVT_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiInstanceStdDeviceDataSetInstance; +EVT_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiInstanceToasterControlSetInstance; +EVT_WDF_WMI_INSTANCE_SET_ITEM EvtWmiInstanceToasterControlSetItem; +EVT_WDF_WMI_INSTANCE_SET_ITEM EvtWmiInstanceStdDeviceDataSetItem; +EVT_WDF_WMI_INSTANCE_EXECUTE_METHOD EvtWmiInstanceToasterControlExecuteMethod; + +NTSTATUS +ToasterFireArrivalEvent( + _In_ WDFDEVICE Device + ); + +#endif // _TOASTER_H_ + diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.inx b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.inx new file mode 100644 index 00000000..2217039d --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.inx @@ -0,0 +1,25 @@ +;Copyright (c) Microsoft Corporation. All rights reserved. + +[Version] +Signature = "$WINDOWS NT$" +Class = System +ClassGuid = {4D36E97D-E325-11CE-BFC1-08002BE10318} +Provider = Contoso +DriverVer = 06/16/1999, 5.00.2064 +CatalogFile = toaster.cat + +[Manufacturer] +Contoso = Contoso, NT$ARCH$ + +[Contoso.NT$ARCH$] +"Basic Toaster" = Toaster_Device, TOASTER\BASIC_TOASTER + +[Toaster_Device.NT] +CopyFiles = Toaster_Device.NT.Copy + +[Toaster_Device.NT.Copy] + +[SourceDisksNames] +1 = "Toaster Device Installation Disk #1",,,"" + +[SourceDisksFiles] \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj new file mode 100644 index 00000000..cfdfd574 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj @@ -0,0 +1,229 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM + + + Release + ARM + + + Debug + ARM64 + + + Release + ARM64 + + + + {2D4FC000-01E2-4FDD-B01A-4FD3C59D245D} + {497e31cb-056b-4f31-abb8-447fd55ee5a5} + v4.5 + 12.0 + Debug + Win32 + toaster + $(LatestTargetPlatformVersion) + + + + Windows10 + true + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + + + Windows10 + false + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + + + Windows10 + true + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + true + + + Windows10 + false + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + + + Windows10 + true + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + + + Windows10 + false + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + + + Windows10 + true + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + + + Windows10 + false + WindowsKernelModeDriver10.0 + Driver + KMDF + Universal + + + + + + + + + + + DbgengKernelDebugger + + + DbgengKernelDebugger + + + DbgengKernelDebugger + true + $(SolutionDir)$(Platform)\$(ConfigurationName)\ + + + DbgengKernelDebugger + + + DbgengKernelDebugger + + + DbgengKernelDebugger + + + DbgengKernelDebugger + + + DbgengKernelDebugger + + + + true + true + trace.h + true + + + + + true + true + trace.h + true + + + + + true + true + trace.h + true + + + + + true + true + trace.h + true + + + + + true + true + trace.h + true + + + + + true + true + trace.h + true + + + + + true + true + trace.h + true + + + + + true + true + trace.h + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj.filters b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj.filters new file mode 100644 index 00000000..2edeb4fc --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/toaster.vcxproj.filters @@ -0,0 +1,45 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {8E41214B-6785-4CFE-B992-037D68949A14} + inf;inv;inx;mof;mc; + + + + + Driver Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Driver/toaster/trace.h b/general/WinHEC 2017 Lab/Toaster Driver/toaster/trace.h new file mode 100644 index 00000000..820df2ea --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Driver/toaster/trace.h @@ -0,0 +1,62 @@ +/*++ + +Module Name: + + Trace.h + +Abstract: + + Header file for the debug tracing related function defintions and macros. + +Environment: + + Kernel mode + +--*/ + +// +// Define the tracing flags. +// +// Tracing GUID - f1f5e659-1217-48bd-9c69-6d9cb3a147d5 +// + +#define WPP_CONTROL_GUIDS \ + WPP_DEFINE_CONTROL_GUID( \ + KMDFDriver1TraceGuid, (f1f5e659,1217,48bd,9c69,6d9cb3a147d5), \ + \ + WPP_DEFINE_BIT(MYDRIVER_ALL_INFO) \ + WPP_DEFINE_BIT(TRACE_DRIVER) \ + WPP_DEFINE_BIT(TRACE_DEVICE) \ + WPP_DEFINE_BIT(TRACE_QUEUE) \ + ) + +#define WPP_FLAG_LEVEL_LOGGER(flag, level) \ + WPP_LEVEL_LOGGER(flag) + +#define WPP_FLAG_LEVEL_ENABLED(flag, level) \ + (WPP_LEVEL_ENABLED(flag) && \ + WPP_CONTROL(WPP_BIT_ ## flag).Level >= level) + +#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ + WPP_LEVEL_LOGGER(flags) + +#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ + (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) + +// +// WPP orders static parameters before dynamic parameters. To support the Trace function +// defined below which sets FLAGS=MYDRIVER_ALL_INFO, a custom macro must be defined to +// reorder the arguments to what the .tpl configuration file expects. +// +#define WPP_RECORDER_FLAGS_LEVEL_ARGS(flags, lvl) WPP_RECORDER_LEVEL_FLAGS_ARGS(lvl, flags) +#define WPP_RECORDER_FLAGS_LEVEL_FILTER(flags, lvl) WPP_RECORDER_LEVEL_FLAGS_FILTER(lvl, flags) + +// +// This comment block is scanned by the trace preprocessor to define our +// Trace function. +// +// begin_wpp config +// FUNC Trace{FLAGS=MYDRIVER_ALL_INFO}(LEVEL, MSG, ...); +// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); +// end_wpp +// diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App.sln b/general/WinHEC 2017 Lab/Toaster Support App/App.sln new file mode 100644 index 00000000..8d28827e --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CustomCapability", "App\CustomCapability\cpp\CustomCapability.vcxproj", "{0213712B-62E6-5546-8D25-79B90244FFA9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|ARM.ActiveCfg = Debug|ARM + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|ARM.Build.0 = Debug|ARM + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|ARM.Deploy.0 = Debug|ARM + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|x64.ActiveCfg = Debug|x64 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|x64.Build.0 = Debug|x64 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|x64.Deploy.0 = Debug|x64 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|x86.ActiveCfg = Debug|Win32 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|x86.Build.0 = Debug|Win32 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Debug|x86.Deploy.0 = Debug|Win32 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|ARM.ActiveCfg = Release|ARM + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|ARM.Build.0 = Release|ARM + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|ARM.Deploy.0 = Release|ARM + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|x64.ActiveCfg = Release|x64 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|x64.Build.0 = Release|x64 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|x64.Deploy.0 = Release|x64 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|x86.ActiveCfg = Release|Win32 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|x86.Build.0 = Release|Win32 + {0213712B-62E6-5546-8D25-79B90244FFA9}.Release|x86.Deploy.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.SCCD b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.SCCD new file mode 100644 index 00000000..cad58db2 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.SCCD @@ -0,0 +1,11 @@ + + + + + + + + + + xxxx + diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj new file mode 100644 index 00000000..8efaa78d --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj @@ -0,0 +1,287 @@ + + + + {0213712b-62e6-5546-8d25-79b90244ffa9} + SDKTemplate + en-US + 14.0 + true + Windows Store + 10.0.15063.0 + 10.0.15063.0 + 10.0 + CustomCapability + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + Application + true + v141 + + + Application + true + v141 + + + Application + true + v141 + + + Application + false + true + v141 + true + + + Application + false + true + v141 + true + + + Application + false + true + v141 + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(IncludePath);..\..\..\SharedContent\cpp + + + $(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\ + $(Platform)\$(Configuration)\ + + + + /bigobj %(AdditionalOptions) + 4453;28204 + $(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(OutDir).. + false + + + vccorlib.lib;WindowsApp.lib;%(AdditionalDependencies);rpcrt4.lib + false + + + + + /bigobj %(AdditionalOptions) + 4453;28204 + $(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(OutDir).. + false + + + vccorlib.lib;WindowsApp.lib;%(AdditionalDependencies);rpcrt4.lib + false + + + + + /bigobj %(AdditionalOptions) + 4453;28204 + $(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(OutDir).. + false + + + vccorlib.lib;WindowsApp.lib;%(AdditionalDependencies);rpcrt4.lib + true + + + + + /bigobj %(AdditionalOptions) + 4453;28204 + $(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(OutDir).. + false + + + vccorlib.lib;WindowsApp.lib;%(AdditionalDependencies);rpcrt4.lib + true + + + + + /bigobj %(AdditionalOptions) + 4453;28204 + $(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(OutDir).. + false + + + vccorlib.lib;WindowsApp.lib;%(AdditionalDependencies);rpcrt4.lib + false + + + + + /bigobj %(AdditionalOptions) + 4453;28204 + $(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(OutDir).. + false + + + vccorlib.lib;WindowsApp.lib;%(AdditionalDependencies);rpcrt4.lib + true + + + + + + + ..\..\..\SharedContent\xaml\App.xaml + + + ..\..\..\SharedContent\cpp\MainPage.xaml + + + Scenario1_MeteringData.xaml + + + + + + + Designer + + + Styles\Styles.xaml + + + Designer + + + Designer + + + + + Designer + + + + + Assets\microsoft-sdk.png + + + Assets\smalltile-sdk.png + + + Assets\splash-sdk.png + + + Assets\squaretile-sdk.png + + + Assets\storelogo-sdk.png + + + Assets\tile-sdk.png + + + Assets\windows-sdk.png + + + + + false + NotUsing + + + ..\..\..\SharedContent\xaml\App.xaml + + + ..\..\..\SharedContent\cpp\MainPage.xaml + + + + Scenario1_MeteringData.xaml + + + + Create + Create + Create + Create + Create + Create + + + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj.filters b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj.filters new file mode 100644 index 00000000..af84bc38 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/CustomCapability.vcxproj.filters @@ -0,0 +1,89 @@ + + + + + 81d95eea-286c-4a5e-98f1-eef612020bf0 + + + 85b464d3-9e56-4242-b58b-1f226dd034b4 + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + {1c0f2943-52c2-4a54-93a2-971c14e7c8ec} + + + {33085be2-4c37-4eab-8f6e-6add0cffe2d4} + + + + + + + + + Model + + + Common + + + + + + ViewModel + + + + + + + Model + + + Common + + + + + + ViewModel + + + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/DeviceList.cpp b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/DeviceList.cpp new file mode 100644 index 00000000..cb3a7a8e --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/DeviceList.cpp @@ -0,0 +1,244 @@ +#include "pch.h" +#include "DeviceList.h" +#include "MainPage.xaml.h" +#include "App.xaml.h" + +using namespace SDKTemplate; + +using namespace Platform; +using namespace Platform::Collections; +using namespace Windows::ApplicationModel; +using namespace Windows::Devices::Enumeration; +using namespace Windows::Devices::Custom; +using namespace Windows::Foundation; +using namespace Windows::UI::Core; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Documents; + +DeviceList^ DeviceList::_Current = nullptr; + +DeviceList^ DeviceList::Current::get() +{ + if (DeviceList::_Current == nullptr) + { + DeviceList::_Current = ref new DeviceList(); + } + return DeviceList::_Current; +} + +DeviceList::DeviceList() : m_WatcherStarted(false), m_WatcherSuspended(false) +{ + m_Fx2Watcher = nullptr; + m_List = ref new Vector(); + InitDeviceWatcher(); + + // Register for app suspend/resume handlers + App::Current->Suspending += ref new SuspendingEventHandler(this, &DeviceList::SuspendDeviceWatcher); + App::Current->Resuming += ref new EventHandler(this, &DeviceList::ResumeDeviceWatcher); +} + +void DeviceList::InitDeviceWatcher() +{ + // Define the selector to enumerate all of the fx2 device interface class instances. + // Use the DeviceInterfaceGuid provided by the driver (Fx2Driver, in this case). + auto selector = CustomDevice::GetDeviceSelector(Fx2Driver::DeviceInterfaceGuid); + + // Set of properties to retrieve + auto properties = ref new Vector({ "System.Devices.DeviceInstanceId" }); + + // Create a device watcher to look for instances of the fx2 device interface. + m_Fx2Watcher = DeviceInformation::CreateWatcher(selector, properties); + + m_Fx2Watcher->Added += ref new TypedEventHandler(this, &DeviceList::OnFx2Added); + m_Fx2Watcher->Removed += ref new TypedEventHandler(this, &DeviceList::OnFx2Removed); + m_Fx2Watcher->EnumerationCompleted += ref new TypedEventHandler(this, &DeviceList::OnFx2EnumerationComplete); +} + +void DeviceList::StartFx2Watcher() +{ + MainPage::Current->NotifyUser("starting device watcher", NotifyType::StatusMessage); + + std::for_each( + begin(m_List), + end(m_List), + [](DeviceListEntry^ Entry) { + Entry->Matched = false; + }); + + WatcherStarted = true; + m_Fx2Watcher->Start(); +} + +void DeviceList::StopFx2Watcher() +{ + MainPage::Current->NotifyUser("stopping fx2 watcher", NotifyType::StatusMessage); + m_Fx2Watcher->Stop(); + WatcherStarted = false; +} + +void DeviceList::CreateBooleanTable( + InlineCollection^ Table, + const Platform::Array^ NewValues, + const Platform::Array^ OldValues, + String^ /* IndexTitle */, + String^ /* ValueTitle */, + String^ TrueValue, + String^ FalseValue) +{ + Table->Clear(); + + for (int i = 0; i < (int)NewValues->Length; i += 1) + { + auto line = ref new Span(); + auto block = ref new Run(); + block->Text = (i + 1).ToString(); + line->Inlines->Append(block); + + block = ref new Run(); + block->Text = " "; + line->Inlines->Append(block); + + block = ref new Run(); + block->Text = NewValues[i] ? TrueValue : FalseValue; + + if ((OldValues != nullptr) && (OldValues[i] != NewValues[i])) + { + auto bold = ref new Bold(); + bold->Inlines->Append(block); + line->Inlines->Append(bold); + } + else + { + line->Inlines->Append(block); + } + + line->Inlines->Append(ref new LineBreak()); + + Table->Append(line); + } +} + +DeviceListEntry^ DeviceList::FindDevice(String^ Id) +{ + auto i = std::find_if( + begin(m_List), + end(m_List), + [Id](DeviceListEntry^ e) {return e->Id == Id; }); + + if (i == end(m_List)) + { + return nullptr; + } + else + { + return *i; + } +} + +void DeviceList::OnFx2Added(DeviceWatcher ^ /* Sender */, DeviceInformation^ DevInterface) +{ + MainPage::Current->Dispatcher->RunAsync( + CoreDispatcherPriority::Normal, + ref new DispatchedHandler( + [this, DevInterface]()->void + { + MainPage::Current->NotifyUser("OnFx2Added: " + DevInterface->Id, NotifyType::StatusMessage); + + // search the device list for a device with a matching interface ID + auto match = FindDevice(DevInterface->Id); + + // If we found a match then mark it as verified and return + if (match != nullptr) + { + match->Matched = true; + return; + } + + // Create a new elemetn for this device interface, and queue up the query of its + // device information + match = ref new DeviceListEntry(DevInterface); + + // Add the new element to the end of the list of devices + m_List->Append(match); + })); +} + +void DeviceList::OnFx2Removed(DeviceWatcher ^ /* Sender */, DeviceInformationUpdate^ DevInterface) +{ + auto deviceId = DevInterface->Id; + + MainPage::Current->Dispatcher->RunAsync( + CoreDispatcherPriority::Normal, + ref new DispatchedHandler( + [this, deviceId]() + { + MainPage::Current->NotifyUser("OnFx2Removed: " + deviceId, NotifyType::StatusMessage); + + // Search the list of devices for one with a matching ID. Move the matched + // item to the end of the list. + auto i = std::remove_if( + begin(m_List), + end(m_List), + [deviceId](DeviceListEntry^ e) {return e->Id == deviceId; }); + + // if there's no match return. + if (i == end(m_List)) + { + return; + } + + // Remove the last item from the list. + MainPage::Current->NotifyUser("OnFx2Removed: " + deviceId + " removed", NotifyType::StatusMessage); + m_List->RemoveAtEnd(); + })); +} + +void DeviceList::OnFx2EnumerationComplete(DeviceWatcher ^ /* Sender */, Object ^ /* o */) +{ + MainPage::Current->Dispatcher->RunAsync( + CoreDispatcherPriority::Normal, + ref new DispatchedHandler( + [this]() + { + MainPage::Current->NotifyUser("OnFx2EnumerationComplete", NotifyType::StatusMessage); + + DeviceList^ me = this; + + // Move all the unmatched elements to the end of the list + auto i = std::remove_if( + begin(m_List), + end(m_List), + [](DeviceListEntry^ e) { return e->Matched == false; }); + + // Determine the number of unmatched entries + auto unmatchedCount = end(m_List) - i; + + while (unmatchedCount > 0) + { + m_List->RemoveAtEnd(); + unmatchedCount -= 1; + } + })); +} + +void DeviceList::SuspendDeviceWatcher(Object^, SuspendingEventArgs^) +{ + if (WatcherStarted) + { + m_WatcherSuspended = true; + StopFx2Watcher(); + } + else + { + m_WatcherSuspended = false; + } +} + +void DeviceList::ResumeDeviceWatcher(Object^, Object^) +{ + if (m_WatcherSuspended) + { + m_WatcherSuspended = false; + StartFx2Watcher(); + } +} diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Package.appxmanifest b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Package.appxmanifest new file mode 100644 index 00000000..0ec45a07 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Package.appxmanifest @@ -0,0 +1,41 @@ + + + + + + Custom Capability C++ Sample + Microsoft Corporation + Assets\StoreLogo-sdk.png + + + + + + + + + + + + + + + + + + + + + diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.cpp b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.cpp new file mode 100644 index 00000000..870d6306 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.cpp @@ -0,0 +1,177 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +// There is an error in the system header files that incorrectly +// places RpcStringBindingCompose in the app partition. +// Work around it by changing the WINAPI_FAMILY to desktop temporarily. +#pragma push_macro("WINAPI_FAMILY") +#undef WINAPI_FAMILY +#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP +#include "RpcClient.h" +#pragma pop_macro("WINAPI_FAMILY") + +using namespace SDKTemplate; + +__int64 RpcClient::Initialize() +{ + RPC_STATUS status; + RPC_WSTR pszStringBinding = nullptr; + + status = RpcStringBindingCompose( + NULL, + reinterpret_cast(L"ncalrpc"), + NULL, + reinterpret_cast(RPC_STATIC_ENDPOINT), + NULL, + &pszStringBinding); + + if (status) + { + goto error_status; + } + + status = RpcBindingFromStringBinding( + pszStringBinding, + &hRpcBinding); + + if (status) + { + goto error_status; + } + + status = RpcStringFree(&pszStringBinding); + + if (status) + { + goto error_status; + } + + RpcTryExcept + { + ::RemoteOpen(hRpcBinding, &phContext); + } + RpcExcept(1) + { + status = RpcExceptionCode(); + } + RpcEndExcept + +error_status: + + return status; +} + +// +// Make RPC call to start metering. This is a blocking call and +// will return only after StopMetering is called. +// +__int64 RpcClient::StartMeteringAndWaitForStop(__int64 samplePeriod) +{ + __int64 ulCode = 0; + CallbackCount = 0; + MeteringData = 0; + + RpcTryExcept + { + ::StartMetering(phContext, samplePeriod, (__int64)this); + } + RpcExcept(1) + { + ulCode = RpcExceptionCode(); + } + RpcEndExcept + + return ulCode; +} + + +// +// Make rpc call SetSampleRate +// +__int64 RpcClient::SetSampleRate(int rate) +{ + __int64 ulCode = 0; + RpcTryExcept + { + ::SetSamplePeriod(phContext, rate); + } + RpcExcept(1) + { + ulCode = RpcExceptionCode(); + } + RpcEndExcept + return ulCode; +} + +// +// Make rpc call StopMetering +// +__int64 RpcClient::StopMetering() +{ + __int64 ulCode = 0; + RpcTryExcept + { + ::StopMetering(phContext); + } + RpcExcept(1) + { + ulCode = RpcExceptionCode(); + } + RpcEndExcept + return ulCode; +} + +RpcClient::~RpcClient() +{ + RPC_STATUS status; + + if (hRpcBinding != NULL) + { + RpcTryExcept + { + ::RemoteClose(&phContext); + } + RpcExcept(1) + { + // Ignoring the result of RemoteClose as nothing can be + // done on the client side with this return code + status = RpcExceptionCode(); + } + RpcEndExcept + + status = RpcBindingFree(&hRpcBinding); + hRpcBinding = NULL; + } +} + +// +// Metering rpc callback +// +void MeteringDataEvent(__int64 data, __int64 context) +{ + RpcClient* client = static_cast((PVOID)context); + client->MeteringData = data; + ++client->CallbackCount; +} + +///******************************************************/ +///* MIDL allocate and free */ +///******************************************************/ + +void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) +{ + return(malloc(len)); +} + +void __RPC_USER midl_user_free(void __RPC_FAR * ptr) +{ + free(ptr); +} \ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.h b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.h new file mode 100644 index 00000000..0ee5ff78 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcClient.h @@ -0,0 +1,30 @@ +// +// RpcClient.h +// + +#pragma once + +#define RPC_STATIC_ENDPOINT L"HsaSampleRpcEndpoint" + +#include "RpcInterface_h.h" + +namespace SDKTemplate +{ + /// + /// Client side RPC implementation + /// + private class RpcClient sealed + { + public: + ~RpcClient(); + __int64 Initialize(); + __int64 StartMeteringAndWaitForStop(__int64 samplePeriod); + __int64 StopMetering(); + __int64 SetSampleRate(int rate); + int CallbackCount; + __int64 MeteringData; + private: + handle_t hRpcBinding; + PCONTEXT_HANDLE_TYPE phContext; + }; +} diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface.c b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface.c new file mode 100644 index 00000000..0f988533 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface.c @@ -0,0 +1,6 @@ +// RpcInterface_c.c expects _ARM_ to be set when building for ARM. +#ifdef _M_ARM +#define _ARM_ 1 +#endif + +#include "RpcInterface_c.c" diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_c.c b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_c.c new file mode 100644 index 00000000..8b05c1ea --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_c.c @@ -0,0 +1,476 @@ + + +/* this ALWAYS GENERATED file contains the RPC client stubs */ + + + /* File created by MIDL compiler version 8.01.0622 */ +/* at Mon Jan 18 19:14:07 2038 + */ +/* Compiler settings for C:\WinHEC 2017 Lab\Toaster Driver\Service\RpcInterface.Idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#if defined(_M_AMD64) + + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ +#if _MSC_VER >= 1200 +#pragma warning(push) +#endif + +#pragma warning( disable: 4211 ) /* redefine extern to static */ +#pragma warning( disable: 4232 ) /* dllimport identity*/ +#pragma warning( disable: 4024 ) /* array to pointer mapping*/ + +#include + +#include "RpcInterface_h.h" + +#define TYPE_FORMAT_STRING_SIZE 23 +#define PROC_FORMAT_STRING_SIZE 245 +#define EXPR_FORMAT_STRING_SIZE 1 +#define TRANSMIT_AS_TABLE_SIZE 0 +#define WIRE_MARSHAL_TABLE_SIZE 0 + +typedef struct _RpcInterface_MIDL_TYPE_FORMAT_STRING + { + short Pad; + unsigned char Format[ TYPE_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_TYPE_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_PROC_FORMAT_STRING + { + short Pad; + unsigned char Format[ PROC_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_PROC_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_EXPR_FORMAT_STRING + { + long Pad; + unsigned char Format[ EXPR_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_EXPR_FORMAT_STRING; + + +static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax = +{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}; + + +extern const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString; +extern const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString; +extern const RpcInterface_MIDL_EXPR_FORMAT_STRING RpcInterface__MIDL_ExprFormatString; + +#define GENERIC_BINDING_TABLE_SIZE 0 + + +/* Standard interface: RpcInterface, ver. 1.0, + GUID={0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}} */ + + +extern const MIDL_SERVER_INFO RpcInterface_ServerInfo; + + +extern const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable; + +static const RPC_CLIENT_INTERFACE RpcInterface___RpcClientInterface = + { + sizeof(RPC_CLIENT_INTERFACE), + {{0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}},{1,0}}, + {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, + (RPC_DISPATCH_TABLE*)&RpcInterface_v1_0_DispatchTable, + 0, + 0, + 0, + &RpcInterface_ServerInfo, + 0x04000000 + }; +RPC_IF_HANDLE RpcInterface_v1_0_c_ifspec = (RPC_IF_HANDLE)& RpcInterface___RpcClientInterface; + +extern const MIDL_STUB_DESC RpcInterface_StubDesc; + +static RPC_BINDING_HANDLE RpcInterface__MIDL_AutoBindHandle; + + +void RemoteOpen( + /* [in] */ handle_t hBinding, + /* [out] */ PPCONTEXT_HANDLE_TYPE pphContext) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[0], + hBinding, + pphContext); + +} + + +void RemoteClose( + /* [out][in] */ PPCONTEXT_HANDLE_TYPE pphContext) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[36], + pphContext); + +} + + +void StartMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod, + /* [optional][in] */ __int64 context) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[74], + phContext, + samplePeriod, + context); + +} + + +void SetSamplePeriod( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[124], + phContext, + samplePeriod); + +} + + +void StopMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[168], + phContext); + +} + + +#if !defined(__RPC_WIN64__) +#error Invalid build platform for this stub. +#endif + +static const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString = + { + 0, + { + + /* Procedure RemoteOpen */ + + 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 2 */ NdrFcLong( 0x0 ), /* 0 */ +/* 6 */ NdrFcShort( 0x0 ), /* 0 */ +/* 8 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 10 */ 0x32, /* FC_BIND_PRIMITIVE */ + 0x0, /* 0 */ +/* 12 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 14 */ NdrFcShort( 0x0 ), /* 0 */ +/* 16 */ NdrFcShort( 0x38 ), /* 56 */ +/* 18 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 20 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 22 */ NdrFcShort( 0x0 ), /* 0 */ +/* 24 */ NdrFcShort( 0x0 ), /* 0 */ +/* 26 */ NdrFcShort( 0x0 ), /* 0 */ +/* 28 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 30 */ NdrFcShort( 0x110 ), /* Flags: out, simple ref, */ +/* 32 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 34 */ NdrFcShort( 0x6 ), /* Type Offset=6 */ + + /* Procedure RemoteClose */ + +/* 36 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 38 */ NdrFcLong( 0x0 ), /* 0 */ +/* 42 */ NdrFcShort( 0x1 ), /* 1 */ +/* 44 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 46 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe0, /* Ctxt flags: via ptr, in, out, */ +/* 48 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 50 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 52 */ NdrFcShort( 0x38 ), /* 56 */ +/* 54 */ NdrFcShort( 0x38 ), /* 56 */ +/* 56 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 58 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 60 */ NdrFcShort( 0x0 ), /* 0 */ +/* 62 */ NdrFcShort( 0x0 ), /* 0 */ +/* 64 */ NdrFcShort( 0x0 ), /* 0 */ +/* 66 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 68 */ NdrFcShort( 0x118 ), /* Flags: in, out, simple ref, */ +/* 70 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 72 */ NdrFcShort( 0xe ), /* Type Offset=14 */ + + /* Procedure StartMetering */ + +/* 74 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 76 */ NdrFcLong( 0x0 ), /* 0 */ +/* 80 */ NdrFcShort( 0x2 ), /* 2 */ +/* 82 */ NdrFcShort( 0x18 ), /* X64 Stack size/offset = 24 */ +/* 84 */ 0x30, /* FC_BIND_CONTEXT */ + 0x40, /* Ctxt flags: in, */ +/* 86 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 88 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 90 */ NdrFcShort( 0x44 ), /* 68 */ +/* 92 */ NdrFcShort( 0x0 ), /* 0 */ +/* 94 */ 0x40, /* Oi2 Flags: has ext, */ + 0x3, /* 3 */ +/* 96 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 98 */ NdrFcShort( 0x0 ), /* 0 */ +/* 100 */ NdrFcShort( 0x0 ), /* 0 */ +/* 102 */ NdrFcShort( 0x0 ), /* 0 */ +/* 104 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 106 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 108 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 110 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 112 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 114 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 116 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 118 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 120 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 122 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure SetSamplePeriod */ + +/* 124 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 126 */ NdrFcLong( 0x0 ), /* 0 */ +/* 130 */ NdrFcShort( 0x3 ), /* 3 */ +/* 132 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 134 */ 0x30, /* FC_BIND_CONTEXT */ + 0x40, /* Ctxt flags: in, */ +/* 136 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 138 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 140 */ NdrFcShort( 0x34 ), /* 52 */ +/* 142 */ NdrFcShort( 0x0 ), /* 0 */ +/* 144 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 146 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 148 */ NdrFcShort( 0x0 ), /* 0 */ +/* 150 */ NdrFcShort( 0x0 ), /* 0 */ +/* 152 */ NdrFcShort( 0x0 ), /* 0 */ +/* 154 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 156 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 158 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 160 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 162 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 164 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 166 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure StopMetering */ + +/* 168 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 170 */ NdrFcLong( 0x0 ), /* 0 */ +/* 174 */ NdrFcShort( 0x4 ), /* 4 */ +/* 176 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 178 */ 0x30, /* FC_BIND_CONTEXT */ + 0x40, /* Ctxt flags: in, */ +/* 180 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 182 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 184 */ NdrFcShort( 0x24 ), /* 36 */ +/* 186 */ NdrFcShort( 0x0 ), /* 0 */ +/* 188 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 190 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 192 */ NdrFcShort( 0x0 ), /* 0 */ +/* 194 */ NdrFcShort( 0x0 ), /* 0 */ +/* 196 */ NdrFcShort( 0x0 ), /* 0 */ +/* 198 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 200 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 202 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 204 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Procedure MeteringDataEvent */ + +/* 206 */ 0x34, /* FC_CALLBACK_HANDLE */ + 0x48, /* Old Flags: */ +/* 208 */ NdrFcLong( 0x0 ), /* 0 */ +/* 212 */ NdrFcShort( 0x0 ), /* 0 */ +/* 214 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 216 */ NdrFcShort( 0x20 ), /* 32 */ +/* 218 */ NdrFcShort( 0x0 ), /* 0 */ +/* 220 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 222 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 224 */ NdrFcShort( 0x0 ), /* 0 */ +/* 226 */ NdrFcShort( 0x0 ), /* 0 */ +/* 228 */ NdrFcShort( 0x0 ), /* 0 */ +/* 230 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter data */ + +/* 232 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 234 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 236 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 238 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 240 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 242 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString = + { + 0, + { + NdrFcShort( 0x0 ), /* 0 */ +/* 2 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 4 */ NdrFcShort( 0x2 ), /* Offset= 2 (6) */ +/* 6 */ 0x30, /* FC_BIND_CONTEXT */ + 0xa0, /* Ctxt flags: via ptr, out, */ +/* 8 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 10 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 12 */ NdrFcShort( 0x2 ), /* Offset= 2 (14) */ +/* 14 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe1, /* Ctxt flags: via ptr, in, out, can't be null */ +/* 16 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 18 */ 0x30, /* FC_BIND_CONTEXT */ + 0x41, /* Ctxt flags: in, can't be null */ +/* 20 */ 0x0, /* 0 */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const unsigned short RpcInterface_FormatStringOffsetTable[] = + { + 0, + 36, + 74, + 124, + 168, + }; + + +static const unsigned short _callbackRpcInterface_FormatStringOffsetTable[] = + { + 206 + }; + + +static const MIDL_STUB_DESC RpcInterface_StubDesc = + { + (void *)& RpcInterface___RpcClientInterface, + MIDL_user_allocate, + MIDL_user_free, + &RpcInterface__MIDL_AutoBindHandle, + 0, + 0, + 0, + 0, + RpcInterface__MIDL_TypeFormatString.Format, + 1, /* -error bounds_check flag */ + 0x50002, /* Ndr library version */ + 0, + 0x801026e, /* MIDL Version 8.1.622 */ + 0, + 0, + 0, /* notify & notify_flag routine table */ + 0x1, /* MIDL flag */ + 0, /* cs routines */ + 0, /* proxy/server info */ + 0 + }; + +static const RPC_DISPATCH_FUNCTION RpcInterface_table[] = + { + NdrServerCall2, + 0 + }; +static const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable = + { + 1, + (RPC_DISPATCH_FUNCTION*)RpcInterface_table + }; + +static const SERVER_ROUTINE RpcInterface_ServerRoutineTable[] = + { + (SERVER_ROUTINE)MeteringDataEvent + }; + +static const MIDL_SERVER_INFO RpcInterface_ServerInfo = + { + &RpcInterface_StubDesc, + RpcInterface_ServerRoutineTable, + RpcInterface__MIDL_ProcFormatString.Format, + _callbackRpcInterface_FormatStringOffsetTable, + 0, + 0, + 0, + 0}; +#if _MSC_VER >= 1200 +#pragma warning(pop) +#endif + + +#endif /* defined(_M_AMD64)*/ + diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_h.h b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_h.h new file mode 100644 index 00000000..a0e2dcac --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_h.h @@ -0,0 +1,112 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 8.01.0622 */ +/* at Mon Jan 18 19:14:07 2038 + */ +/* Compiler settings for C:\WinHEC 2017 Lab\Toaster Driver\Service\RpcInterface.Idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 475 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif /* __RPCNDR_H_VERSION__ */ + + +#ifndef __RpcInterface_h_h__ +#define __RpcInterface_h_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +#if defined(__cplusplus) +#if defined(__MIDL_USE_C_ENUM) +#define MIDL_ENUM enum +#else +#define MIDL_ENUM enum class +#endif +#endif + + +/* Forward Declarations */ + +/* header files for imported files */ +#include "oaidl.h" + +#ifdef __cplusplus +extern "C"{ +#endif + + +#ifndef __RpcInterface_INTERFACE_DEFINED__ +#define __RpcInterface_INTERFACE_DEFINED__ + +/* interface RpcInterface */ +/* [unique][version][uuid] */ + +typedef /* [context_handle] */ void *PCONTEXT_HANDLE_TYPE; + +typedef /* [ref] */ PCONTEXT_HANDLE_TYPE *PPCONTEXT_HANDLE_TYPE; + +void RemoteOpen( + /* [in] */ handle_t hBinding, + /* [out] */ PPCONTEXT_HANDLE_TYPE pphContext); + +void RemoteClose( + /* [out][in] */ PPCONTEXT_HANDLE_TYPE pphContext); + +void StartMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod, + /* [optional][in] */ __int64 context); + +void SetSamplePeriod( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext, + /* [in] */ __int64 samplePeriod); + +void StopMetering( + /* [in] */ PCONTEXT_HANDLE_TYPE phContext); + +/* [callback] */ void MeteringDataEvent( + /* [in] */ __int64 data, + /* [optional][in] */ __int64 context); + + + +extern RPC_IF_HANDLE RpcInterface_v1_0_c_ifspec; +extern RPC_IF_HANDLE RpcInterface_v1_0_s_ifspec; +#endif /* __RpcInterface_INTERFACE_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +void __RPC_USER PCONTEXT_HANDLE_TYPE_rundown( PCONTEXT_HANDLE_TYPE ); + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_s.c b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_s.c new file mode 100644 index 00000000..ec58170d --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/RpcInterface_s.c @@ -0,0 +1,430 @@ + + +/* this ALWAYS GENERATED file contains the RPC server stubs */ + + + /* File created by MIDL compiler version 8.01.0622 */ +/* at Mon Jan 18 19:14:07 2038 + */ +/* Compiler settings for C:\WinHEC 2017 Lab\Toaster Driver\Service\RpcInterface.Idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#if defined(_M_AMD64) + + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ +#if _MSC_VER >= 1200 +#pragma warning(push) +#endif + +#pragma warning( disable: 4211 ) /* redefine extern to static */ +#pragma warning( disable: 4232 ) /* dllimport identity*/ +#pragma warning( disable: 4024 ) /* array to pointer mapping*/ + +#include +#include "RpcInterface_h.h" + +#define TYPE_FORMAT_STRING_SIZE 23 +#define PROC_FORMAT_STRING_SIZE 245 +#define EXPR_FORMAT_STRING_SIZE 1 +#define TRANSMIT_AS_TABLE_SIZE 0 +#define WIRE_MARSHAL_TABLE_SIZE 0 + +typedef struct _RpcInterface_MIDL_TYPE_FORMAT_STRING + { + short Pad; + unsigned char Format[ TYPE_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_TYPE_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_PROC_FORMAT_STRING + { + short Pad; + unsigned char Format[ PROC_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_PROC_FORMAT_STRING; + +typedef struct _RpcInterface_MIDL_EXPR_FORMAT_STRING + { + long Pad; + unsigned char Format[ EXPR_FORMAT_STRING_SIZE ]; + } RpcInterface_MIDL_EXPR_FORMAT_STRING; + + +static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax = +{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}; + +extern const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString; +extern const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString; +extern const RpcInterface_MIDL_EXPR_FORMAT_STRING RpcInterface__MIDL_ExprFormatString; + +/* Standard interface: RpcInterface, ver. 1.0, + GUID={0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}} */ + + +extern const MIDL_SERVER_INFO RpcInterface_ServerInfo; + +extern const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable; + +static const RPC_SERVER_INTERFACE RpcInterface___RpcServerInterface = + { + sizeof(RPC_SERVER_INTERFACE), + {{0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}},{1,0}}, + {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, + (RPC_DISPATCH_TABLE*)&RpcInterface_v1_0_DispatchTable, + 0, + 0, + 0, + &RpcInterface_ServerInfo, + 0x04000000 + }; +RPC_IF_HANDLE RpcInterface_v1_0_s_ifspec = (RPC_IF_HANDLE)& RpcInterface___RpcServerInterface; + +extern const MIDL_STUB_DESC RpcInterface_StubDesc; + + extern const MIDL_STUBLESS_PROXY_INFO RpcInterface_ProxyInfo; + +/* [callback] */ void MeteringDataEvent( + /* [in] */ __int64 data, + /* [optional][in] */ __int64 context) +{ + + NdrClientCall2( + ( PMIDL_STUB_DESC )&RpcInterface_StubDesc, + (PFORMAT_STRING) &RpcInterface__MIDL_ProcFormatString.Format[206], + data, + context); + +} + +extern const NDR_RUNDOWN RundownRoutines[]; + +#if !defined(__RPC_WIN64__) +#error Invalid build platform for this stub. +#endif + +static const RpcInterface_MIDL_PROC_FORMAT_STRING RpcInterface__MIDL_ProcFormatString = + { + 0, + { + + /* Procedure RemoteOpen */ + + 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 2 */ NdrFcLong( 0x0 ), /* 0 */ +/* 6 */ NdrFcShort( 0x0 ), /* 0 */ +/* 8 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 10 */ 0x32, /* FC_BIND_PRIMITIVE */ + 0x0, /* 0 */ +/* 12 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 14 */ NdrFcShort( 0x0 ), /* 0 */ +/* 16 */ NdrFcShort( 0x38 ), /* 56 */ +/* 18 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 20 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 22 */ NdrFcShort( 0x0 ), /* 0 */ +/* 24 */ NdrFcShort( 0x0 ), /* 0 */ +/* 26 */ NdrFcShort( 0x0 ), /* 0 */ +/* 28 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 30 */ NdrFcShort( 0x110 ), /* Flags: out, simple ref, */ +/* 32 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 34 */ NdrFcShort( 0x6 ), /* Type Offset=6 */ + + /* Procedure RemoteClose */ + +/* 36 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 38 */ NdrFcLong( 0x0 ), /* 0 */ +/* 42 */ NdrFcShort( 0x1 ), /* 1 */ +/* 44 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 46 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe0, /* Ctxt flags: via ptr, in, out, */ +/* 48 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 50 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 52 */ NdrFcShort( 0x38 ), /* 56 */ +/* 54 */ NdrFcShort( 0x38 ), /* 56 */ +/* 56 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 58 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 60 */ NdrFcShort( 0x0 ), /* 0 */ +/* 62 */ NdrFcShort( 0x0 ), /* 0 */ +/* 64 */ NdrFcShort( 0x0 ), /* 0 */ +/* 66 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter pphContext */ + +/* 68 */ NdrFcShort( 0x118 ), /* Flags: in, out, simple ref, */ +/* 70 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 72 */ NdrFcShort( 0xe ), /* Type Offset=14 */ + + /* Procedure StartMetering */ + +/* 74 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 76 */ NdrFcLong( 0x0 ), /* 0 */ +/* 80 */ NdrFcShort( 0x2 ), /* 2 */ +/* 82 */ NdrFcShort( 0x18 ), /* X64 Stack size/offset = 24 */ +/* 84 */ 0x30, /* FC_BIND_CONTEXT */ + 0x40, /* Ctxt flags: in, */ +/* 86 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 88 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 90 */ NdrFcShort( 0x44 ), /* 68 */ +/* 92 */ NdrFcShort( 0x0 ), /* 0 */ +/* 94 */ 0x40, /* Oi2 Flags: has ext, */ + 0x3, /* 3 */ +/* 96 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 98 */ NdrFcShort( 0x0 ), /* 0 */ +/* 100 */ NdrFcShort( 0x0 ), /* 0 */ +/* 102 */ NdrFcShort( 0x0 ), /* 0 */ +/* 104 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 106 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 108 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 110 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 112 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 114 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 116 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 118 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 120 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 122 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure SetSamplePeriod */ + +/* 124 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 126 */ NdrFcLong( 0x0 ), /* 0 */ +/* 130 */ NdrFcShort( 0x3 ), /* 3 */ +/* 132 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 134 */ 0x30, /* FC_BIND_CONTEXT */ + 0x40, /* Ctxt flags: in, */ +/* 136 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 138 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 140 */ NdrFcShort( 0x34 ), /* 52 */ +/* 142 */ NdrFcShort( 0x0 ), /* 0 */ +/* 144 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 146 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 148 */ NdrFcShort( 0x0 ), /* 0 */ +/* 150 */ NdrFcShort( 0x0 ), /* 0 */ +/* 152 */ NdrFcShort( 0x0 ), /* 0 */ +/* 154 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 156 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 158 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 160 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Parameter samplePeriod */ + +/* 162 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 164 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 166 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Procedure StopMetering */ + +/* 168 */ 0x0, /* 0 */ + 0x48, /* Old Flags: */ +/* 170 */ NdrFcLong( 0x0 ), /* 0 */ +/* 174 */ NdrFcShort( 0x4 ), /* 4 */ +/* 176 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 178 */ 0x30, /* FC_BIND_CONTEXT */ + 0x40, /* Ctxt flags: in, */ +/* 180 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 182 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 184 */ NdrFcShort( 0x24 ), /* 36 */ +/* 186 */ NdrFcShort( 0x0 ), /* 0 */ +/* 188 */ 0x40, /* Oi2 Flags: has ext, */ + 0x1, /* 1 */ +/* 190 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 192 */ NdrFcShort( 0x0 ), /* 0 */ +/* 194 */ NdrFcShort( 0x0 ), /* 0 */ +/* 196 */ NdrFcShort( 0x0 ), /* 0 */ +/* 198 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter phContext */ + +/* 200 */ NdrFcShort( 0x8 ), /* Flags: in, */ +/* 202 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 204 */ NdrFcShort( 0x12 ), /* Type Offset=18 */ + + /* Procedure MeteringDataEvent */ + +/* 206 */ 0x34, /* FC_CALLBACK_HANDLE */ + 0x48, /* Old Flags: */ +/* 208 */ NdrFcLong( 0x0 ), /* 0 */ +/* 212 */ NdrFcShort( 0x0 ), /* 0 */ +/* 214 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ +/* 216 */ NdrFcShort( 0x20 ), /* 32 */ +/* 218 */ NdrFcShort( 0x0 ), /* 0 */ +/* 220 */ 0x40, /* Oi2 Flags: has ext, */ + 0x2, /* 2 */ +/* 222 */ 0xa, /* 10 */ + 0x1, /* Ext Flags: new corr desc, */ +/* 224 */ NdrFcShort( 0x0 ), /* 0 */ +/* 226 */ NdrFcShort( 0x0 ), /* 0 */ +/* 228 */ NdrFcShort( 0x0 ), /* 0 */ +/* 230 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter data */ + +/* 232 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 234 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ +/* 236 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + /* Parameter context */ + +/* 238 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */ +/* 240 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ +/* 242 */ 0xb, /* FC_HYPER */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const RpcInterface_MIDL_TYPE_FORMAT_STRING RpcInterface__MIDL_TypeFormatString = + { + 0, + { + NdrFcShort( 0x0 ), /* 0 */ +/* 2 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 4 */ NdrFcShort( 0x2 ), /* Offset= 2 (6) */ +/* 6 */ 0x30, /* FC_BIND_CONTEXT */ + 0xa0, /* Ctxt flags: via ptr, out, */ +/* 8 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 10 */ + 0x11, 0x4, /* FC_RP [alloced_on_stack] */ +/* 12 */ NdrFcShort( 0x2 ), /* Offset= 2 (14) */ +/* 14 */ 0x30, /* FC_BIND_CONTEXT */ + 0xe1, /* Ctxt flags: via ptr, in, out, can't be null */ +/* 16 */ 0x0, /* 0 */ + 0x0, /* 0 */ +/* 18 */ 0x30, /* FC_BIND_CONTEXT */ + 0x41, /* Ctxt flags: in, can't be null */ +/* 20 */ 0x0, /* 0 */ + 0x0, /* 0 */ + + 0x0 + } + }; + +static const NDR_RUNDOWN RundownRoutines[] = + { + PCONTEXT_HANDLE_TYPE_rundown + }; + + +static const unsigned short RpcInterface_FormatStringOffsetTable[] = + { + 0, + 36, + 74, + 124, + 168, + }; + + +static const unsigned short _callbackRpcInterface_FormatStringOffsetTable[] = + { + 206 + }; + + +static const MIDL_STUB_DESC RpcInterface_StubDesc = + { + (void *)& RpcInterface___RpcServerInterface, + MIDL_user_allocate, + MIDL_user_free, + 0, + RundownRoutines, + 0, + 0, + 0, + RpcInterface__MIDL_TypeFormatString.Format, + 1, /* -error bounds_check flag */ + 0x50002, /* Ndr library version */ + 0, + 0x801026e, /* MIDL Version 8.1.622 */ + 0, + 0, + 0, /* notify & notify_flag routine table */ + 0x1, /* MIDL flag */ + 0, /* cs routines */ + 0, /* proxy/server info */ + 0 + }; + +static const RPC_DISPATCH_FUNCTION RpcInterface_table[] = + { + NdrServerCall2, + NdrServerCall2, + NdrServerCall2, + NdrServerCall2, + NdrServerCall2, + 0 + }; +static const RPC_DISPATCH_TABLE RpcInterface_v1_0_DispatchTable = + { + 5, + (RPC_DISPATCH_FUNCTION*)RpcInterface_table + }; + +static const SERVER_ROUTINE RpcInterface_ServerRoutineTable[] = + { + (SERVER_ROUTINE)RemoteOpen, + (SERVER_ROUTINE)RemoteClose, + (SERVER_ROUTINE)StartMetering, + (SERVER_ROUTINE)SetSamplePeriod, + (SERVER_ROUTINE)StopMetering, + }; + +static const MIDL_SERVER_INFO RpcInterface_ServerInfo = + { + &RpcInterface_StubDesc, + RpcInterface_ServerRoutineTable, + RpcInterface__MIDL_ProcFormatString.Format, + RpcInterface_FormatStringOffsetTable, + 0, + 0, + 0, + 0}; +#if _MSC_VER >= 1200 +#pragma warning(pop) +#endif + + +#endif /* defined(_M_AMD64)*/ + diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.cpp b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.cpp new file mode 100644 index 00000000..a808cf83 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.cpp @@ -0,0 +1,21 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "pch.h" +#include "MainPage.xaml.h" +#include "SampleConfiguration.h" + +using namespace SDKTemplate; + +Platform::Array^ MainPage::scenariosInner = ref new Platform::Array +{ + { "Connect to an NT Service", "SDKTemplate.MeteringData" }, +}; diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.h b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.h new file mode 100644 index 00000000..22581275 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/SampleConfiguration.h @@ -0,0 +1,47 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#pragma once +#include "pch.h" + +namespace SDKTemplate +{ + value struct Scenario; + + partial ref class MainPage + { + internal: + static property Platform::String^ FEATURE_NAME + { + Platform::String^ get() + { + return "Custom Capability C++ sample"; + } + } + + static property Platform::Array^ scenarios + { + Platform::Array^ get() + { + return scenariosInner; + } + } + + private: + static Platform::Array^ scenariosInner; + }; + + public value struct Scenario + { + Platform::String^ Title; + Platform::String^ ClassName; + }; +} diff --git a/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Scenario1_MeteringData.xaml b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Scenario1_MeteringData.xaml new file mode 100644 index 00000000..0636f74d --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/Scenario1_MeteringData.xaml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + This scenario demonstrates RPC communication between an app and an NT service. For demonstration purposes, the service reads data from an imaginary device. + + + + + + + Sample Period (ms): + + + + + + + + +