diff options
| author | J M Rossy <[email protected]> | 2015-07-29 15:40:09 -0700 |
|---|---|---|
| committer | J M Rossy <[email protected]> | 2015-07-29 16:34:40 -0700 |
| commit | 5d61a4a79a1e96dc5d9af1e5e712c84507307544 (patch) | |
| tree | 49ed270893578cd18758b74ffcca16dc7ab948d6 /bluetooth | |
| parent | 5d41613e26e147d2300c786bb2b34cb4b4067a25 (diff) | |
Samples update for public Windows 10 release
Fix #2 Enabling WPP Recorder in Sensors Samples causes errors
Fix #4 Add back fixed KMDOD sample
Add new BarcodeScanner sample in pos folder
Add new MagneticStripeReader sample in pos folder
Add new SynpaticsTouch sample in input folder
Add new Power Engine Plugin sample in pofx folder
Add new DeviceMft sample in avstream folder
Add new AvsCamera sample in root
Add new SimBatt sample in root
Add other pre-existing samples not yet released for Win10
Diffstat (limited to 'bluetooth')
21 files changed, 1147 insertions, 1254 deletions
diff --git a/bluetooth/bthecho/ReadMe.md b/bluetooth/bthecho/ReadMe.md index 8bc6e35f..cf19189a 100644 --- a/bluetooth/bthecho/ReadMe.md +++ b/bluetooth/bthecho/ReadMe.md @@ -3,39 +3,14 @@ Bluetooth Echo L2CAP Profile Driver This sample demonstrates developing [Bluetooth L2CAP profile drivers](http://msdn.microsoft.com/en-us/library/windows/hardware/ff536598) using [Bluetooth L2CAP DDIs](http://msdn.microsoft.com/en-us/library/windows/hardware/ff536585).The sample includes two drivers. One for a device that acts as an L2CAP server and another for a device that acts as an L2CAP client. The server simply echoes back any data that it receives from client on the same L2CA channel. These drivers can be used with devices that can be installed with bth.inf. Such devices get installed as ‘Generic Bluetooth Radio’. Examples of such devices are Bluetooth USB dongles such as (but not limited to): -``` {.syntax xml:space="preserve"} -Generic Bluetooth Radio=\ - BthUsb, USB\Vid_0a12&Pid_0001 -CSR Nanosira=\ - BthUsb, USB\Vid_0a12&Pid_0003 -CSR Nanosira WHQL Reference Radio=\ - BthUsb, USB\Vid_0a12&Pid_0004 -CSR Nanosira-Multimedia=\ - BthUsb, USB\Vid_0a12&Pid_0005 -CSR Nanosira-Multimedia WHQL Reference Radio=\ - BthUsb, USB\Vid_0a12&Pid_0006 -``` + Generic Bluetooth Radio = BthUsb, USB\Vid_0a12&Pid_0001 + CSR Nanosira = BthUsb, USB\Vid_0a12&Pid_0003 + CSR Nanosira WHQL Reference Radi o= BthUsb, USB\Vid_0a12&Pid_0004 + CSR Nanosira-Multimedia = BthUsb, USB\Vid_0a12&Pid_0005 + CSR Nanosira-Multimedia WHQL Reference Radio = BthUsb, USB\Vid_0a12&Pid_0006 Please refer to bth.inf for the complete list of devices. The installation steps below describe how to install echo server and client with such a device. Please note that RFCOMM based profiles must be developed and accessed using user-mode socket APIs. This sample is applicable to Windows® Vista, Windows® 7 and Windows® 8 operating systems. -**Note** - -To build this sample, you can use Microsoft Visual Studio 2013 (Express, Professional, or Ultimate) and Windows Driver Kit (WDK) 8.1 Update. You can get Visual Studio 2013 and WDK 8.1 Update [here](http://go.microsoft.com/fwlink/p/?LInkID=239721). - -You can also build this sample with Visual Studio 2013 (Professional or Ultimate) and [Windows Driver Kit (WDK) 8.1](http://go.microsoft.com/fwlink/p/?LInkID=391348). - -For Windows Driver Kit (WDK) 8 samples, download the [WDK 8 samples pack](%20http://go.microsoft.com/fwlink/?LinkId=317090). The samples in the WDK 8 samples pack will build only with Microsoft Visual Studio Professional 2012 (Professional or Ultimate) and WDK 8. - -Operating system requirements ------------------------------ - -Client - -Windows 7 - -Server - -Windows Server 2008 R2 Build the sample ---------------- diff --git a/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj b/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj index f982f9b7..8da1d16a 100644 --- a/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj +++ b/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj @@ -19,11 +19,11 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{B506A244-2ADC-4C65-85B8-8B19764B4849}</ProjectGuid> + <ProjectGuid>{8D6A9C42-F4FA-4D7B-A038-5209844883C3}</ProjectGuid> <RootNamespace>$(MSBuildProjectName)</RootNamespace> <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{ED7BAD90-5755-4501-83C1-30383B8C2D76}</SampleGuid> + <SampleGuid>{A9FD1AC6-CE1D-45EE-9079-FE3C370F871F}</SampleGuid> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -177,7 +177,6 @@ <ItemGroup> <Inf Exclude="@(Inf)" Include="*.inf" /> <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> diff --git a/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj.Filters b/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj.Filters index bb3d32ad..5f00fc7a 100644 --- a/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj.Filters +++ b/bluetooth/bthecho/bthcli/app/BthEcho.vcxproj.Filters @@ -3,15 +3,15 @@ <ItemGroup> <Filter Include="Source Files"> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{0A8DC157-9CD8-47FC-96AB-AB876FCB97C8}</UniqueIdentifier> + <UniqueIdentifier>{D5028DD9-763A-43E5-A26D-8D3BEF9DEB88}</UniqueIdentifier> </Filter> <Filter Include="Header Files"> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{B0233FE1-6785-4466-886B-FC81C40F8257}</UniqueIdentifier> + <UniqueIdentifier>{AD474526-552E-4398-818A-E95F266E7F91}</UniqueIdentifier> </Filter> <Filter Include="Resource Files"> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{6E8F0465-6F65-432E-9958-9869CF84EB6B}</UniqueIdentifier> + <UniqueIdentifier>{6B067815-190E-45D2-B008-7E8562CD0B30}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> diff --git a/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.inx b/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.inx index 9f55cc59..4fe47e28 100644 --- a/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.inx +++ b/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.inx @@ -21,7 +21,7 @@ Signature="$WINDOWS NT$" Class=Sample ClassGuid={e0cbf06c-cd8b-4647-bb8a-263b43f0f974} -Provider=%MSFTSAMPLE% +Provider=%ProviderString% DriverVer=06/21/2006,6.0.5841. CatalogFile=KmdfSamples.cat @@ -39,8 +39,7 @@ BthEchoSampleCli.sys = 1,, ;***************************************** [Manufacturer] -%MSFTSAMPLE%=Microsoft,NTamd64...1 -%MSFTSAMPLE%=Microsoft,NTx86...1 +%ManufacturerString%=Microsoft,NTx86...1,NTamd64...1 [Microsoft.NTamd64...1] %BthEchoSampleCli.DeviceDesc% = BthEchoSampleCli_Inst,BTHENUM\{c07508f2-b970-43ca-b5dd-cc4f2391bef4} @@ -94,8 +93,8 @@ KmdfLibraryVersion = $KMDFVERSION$ [Strings] SPSVCINST_ASSOCSERVICE= 0x00000002 -MSFTSAMPLE = "Microsoft Sample" -StdMfg = "(Standard system devices)" +ProviderString = "TODO-Set-Provider" +ManufacturerString = "TODO-Set-Manufacturer" DiskId1 = "BthEchoSampleCli installation disk" BthEchoSampleCli.DeviceDesc = "Bluetooth Echo Sample Client" BthEchoSampleCli.SVCDESC = "BthEchoSampleCli" diff --git a/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj b/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj index f30cb9f3..2b111734 100644 --- a/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj +++ b/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj @@ -19,12 +19,12 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}</ProjectGuid> + <ProjectGuid>{D0526687-DE4D-409A-9488-F0A874D6EA3E}</ProjectGuid> <RootNamespace>$(MSBuildProjectName)</RootNamespace> <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{FA5BA6C8-691B-4FF7-9AFB-B50CE61C8ED1}</SampleGuid> + <SampleGuid>{67C06B25-EC35-414F-A8A1-03BC3787C159}</SampleGuid> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -187,7 +187,6 @@ <ItemGroup> <Inf Exclude="@(Inf)" Include="*.inf" /> <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> diff --git a/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj.Filters b/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj.Filters index 176a771f..49ad94cf 100644 --- a/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj.Filters +++ b/bluetooth/bthecho/bthcli/sys/BthEchoSampleCli.vcxproj.Filters @@ -3,19 +3,19 @@ <ItemGroup> <Filter Include="Source Files"> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{12E8E936-7BEE-4822-9BB5-A95B2C6C6537}</UniqueIdentifier> + <UniqueIdentifier>{33095013-BA3C-4D73-972A-1BC536F0480F}</UniqueIdentifier> </Filter> <Filter Include="Header Files"> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{379796ED-172B-4B2C-9E23-302F90088C9F}</UniqueIdentifier> + <UniqueIdentifier>{54B5DEBA-240B-44F1-AEA4-DCA8F28C63CB}</UniqueIdentifier> </Filter> <Filter Include="Resource Files"> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{5B69AC41-D941-4D63-82AB-FAED650522CE}</UniqueIdentifier> + <UniqueIdentifier>{04631531-1FEF-42BD-83FA-5382EC0D29A3}</UniqueIdentifier> </Filter> <Filter Include="Driver Files"> <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{1907D7F9-002C-43DE-BB60-1544D4D62A74}</UniqueIdentifier> + <UniqueIdentifier>{32A5AE44-0838-409A-BAB9-2611B33E8829}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> @@ -33,9 +33,6 @@ </ClCompile> </ItemGroup> <ItemGroup> - <FilesToPackage Include=".\Debug\\BthEchoSampleCli.inf"> - <Filter>Driver Files</Filter> - </FilesToPackage> <Inf Include=".\BthEchoSampleCli.inx"> <Filter>Driver Files</Filter> </Inf> diff --git a/bluetooth/bthecho/bthecho.sln b/bluetooth/bthecho/bthecho.sln index 3e94270a..cf33ad90 100644 --- a/bluetooth/bthecho/bthecho.sln +++ b/bluetooth/bthecho/bthecho.sln @@ -3,36 +3,36 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0 MinimumVisualStudioVersion = 12.0 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{83E67B5A-A079-4795-BB30-7DF17133F3F2}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{ABF4399D-D992-42E1-8EBF-68C9CFB7F2C3}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5581D7EE-1489-4811-94EE-AA7717B4367A}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{556D6471-9F94-46BB-BF1D-B4436E8577E1}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "App", "App", "{17CBFF38-C5AD-417C-8CC8-864EE0DDDD4C}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "App", "App", "{CD3B1A5A-0BBE-4F0C-B412-2A5662ED766A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bthcli", "Bthcli", "{8107A759-05EB-4C85-8E43-21D9C34D8437}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bthcli", "Bthcli", "{A10654D9-385E-4D89-B10B-992F8B31D5DC}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sys", "Sys", "{7F96521C-27C0-448F-9408-BE90EAEAC221}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sys", "Sys", "{B1A01E5B-0A99-42AD-A897-8B91E9ADAB2F}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Inst", "Inst", "{2E43D7E2-4E3C-490D-951B-4271FB00B68D}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Inst", "Inst", "{82373034-DC87-4536-9BE6-06818943E8BA}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bthsrv", "Bthsrv", "{2FC6C414-6626-45DC-9519-70E6412A131E}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bthsrv", "Bthsrv", "{23D66828-26DC-48AC-A34B-6503C2345B78}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sys", "Sys", "{2D8F29A9-064E-4557-BBCB-1A09BCC8CC68}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sys", "Sys", "{52BF960B-FC39-4AC7-9486-C3EC71456856}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bthecho", "common\lib\bthecho.vcxproj", "{A2EE1D94-8521-48CE-B925-271ACA5DD459}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bthecho", "common\lib\bthecho.vcxproj", "{279A982A-666D-434D-A53D-3FF3CEBC175D}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BthEcho", "bthcli\app\BthEcho.vcxproj", "{B506A244-2ADC-4C65-85B8-8B19764B4849}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BthEcho", "bthcli\app\BthEcho.vcxproj", "{8D6A9C42-F4FA-4D7B-A038-5209844883C3}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BthEchoSampleCli", "bthcli\sys\BthEchoSampleCli.vcxproj", "{AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BthEchoSampleCli", "bthcli\sys\BthEchoSampleCli.vcxproj", "{5346197B-56DB-4486-BEE2-68D0380B7D5B}" ProjectSection(ProjectDependencies) = postProject - {A2EE1D94-8521-48CE-B925-271ACA5DD459} = {A2EE1D94-8521-48CE-B925-271ACA5DD459} + {279A982A-666D-434D-A53D-3FF3CEBC175D} = {279A982A-666D-434D-A53D-3FF3CEBC175D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bthsrvinst", "bthsrv\inst\bthsrvinst.vcxproj", "{9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bthsrvinst", "bthsrv\inst\bthsrvinst.vcxproj", "{AD63285D-E1DA-41F5-93F8-A076CF4A3B64}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BthEchoSampleSrv", "bthsrv\sys\BthEchoSampleSrv.vcxproj", "{B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BthEchoSampleSrv", "bthsrv\sys\BthEchoSampleSrv.vcxproj", "{2A776B98-0216-4882-A0EA-1AC2251AD597}" ProjectSection(ProjectDependencies) = postProject - {A2EE1D94-8521-48CE-B925-271ACA5DD459} = {A2EE1D94-8521-48CE-B925-271ACA5DD459} + {279A982A-666D-434D-A53D-3FF3CEBC175D} = {279A982A-666D-434D-A53D-3FF3CEBC175D} EndProjectSection EndProject Global @@ -43,60 +43,60 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Debug|Win32.ActiveCfg = Debug|Win32 - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Debug|Win32.Build.0 = Debug|Win32 - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Release|Win32.ActiveCfg = Release|Win32 - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Release|Win32.Build.0 = Release|Win32 - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Debug|x64.ActiveCfg = Debug|x64 - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Debug|x64.Build.0 = Debug|x64 - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Release|x64.ActiveCfg = Release|x64 - {A2EE1D94-8521-48CE-B925-271ACA5DD459}.Release|x64.Build.0 = Release|x64 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Debug|Win32.ActiveCfg = Debug|Win32 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Debug|Win32.Build.0 = Debug|Win32 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Release|Win32.ActiveCfg = Release|Win32 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Release|Win32.Build.0 = Release|Win32 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Debug|x64.ActiveCfg = Debug|x64 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Debug|x64.Build.0 = Debug|x64 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Release|x64.ActiveCfg = Release|x64 - {B506A244-2ADC-4C65-85B8-8B19764B4849}.Release|x64.Build.0 = Release|x64 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Debug|Win32.ActiveCfg = Debug|Win32 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Debug|Win32.Build.0 = Debug|Win32 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Release|Win32.ActiveCfg = Release|Win32 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Release|Win32.Build.0 = Release|Win32 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Debug|x64.ActiveCfg = Debug|x64 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Debug|x64.Build.0 = Debug|x64 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Release|x64.ActiveCfg = Release|x64 - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94}.Release|x64.Build.0 = Release|x64 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Debug|Win32.ActiveCfg = Debug|Win32 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Debug|Win32.Build.0 = Debug|Win32 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Release|Win32.ActiveCfg = Release|Win32 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Release|Win32.Build.0 = Release|Win32 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Debug|x64.ActiveCfg = Debug|x64 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Debug|x64.Build.0 = Debug|x64 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Release|x64.ActiveCfg = Release|x64 - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}.Release|x64.Build.0 = Release|x64 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Debug|Win32.ActiveCfg = Debug|Win32 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Debug|Win32.Build.0 = Debug|Win32 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Release|Win32.ActiveCfg = Release|Win32 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Release|Win32.Build.0 = Release|Win32 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Debug|x64.ActiveCfg = Debug|x64 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Debug|x64.Build.0 = Debug|x64 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Release|x64.ActiveCfg = Release|x64 - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}.Release|x64.Build.0 = Release|x64 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Debug|Win32.ActiveCfg = Debug|Win32 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Debug|Win32.Build.0 = Debug|Win32 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Release|Win32.ActiveCfg = Release|Win32 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Release|Win32.Build.0 = Release|Win32 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Debug|x64.ActiveCfg = Debug|x64 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Debug|x64.Build.0 = Debug|x64 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Release|x64.ActiveCfg = Release|x64 + {279A982A-666D-434D-A53D-3FF3CEBC175D}.Release|x64.Build.0 = Release|x64 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Debug|Win32.ActiveCfg = Debug|Win32 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Debug|Win32.Build.0 = Debug|Win32 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Release|Win32.ActiveCfg = Release|Win32 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Release|Win32.Build.0 = Release|Win32 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Debug|x64.ActiveCfg = Debug|x64 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Debug|x64.Build.0 = Debug|x64 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Release|x64.ActiveCfg = Release|x64 + {8D6A9C42-F4FA-4D7B-A038-5209844883C3}.Release|x64.Build.0 = Release|x64 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Debug|Win32.ActiveCfg = Debug|Win32 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Debug|Win32.Build.0 = Debug|Win32 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Release|Win32.ActiveCfg = Release|Win32 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Release|Win32.Build.0 = Release|Win32 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Debug|x64.ActiveCfg = Debug|x64 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Debug|x64.Build.0 = Debug|x64 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Release|x64.ActiveCfg = Release|x64 + {5346197B-56DB-4486-BEE2-68D0380B7D5B}.Release|x64.Build.0 = Release|x64 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Debug|Win32.ActiveCfg = Debug|Win32 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Debug|Win32.Build.0 = Debug|Win32 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Release|Win32.ActiveCfg = Release|Win32 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Release|Win32.Build.0 = Release|Win32 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Debug|x64.ActiveCfg = Debug|x64 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Debug|x64.Build.0 = Debug|x64 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Release|x64.ActiveCfg = Release|x64 + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64}.Release|x64.Build.0 = Release|x64 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Debug|Win32.ActiveCfg = Debug|Win32 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Debug|Win32.Build.0 = Debug|Win32 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Release|Win32.ActiveCfg = Release|Win32 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Release|Win32.Build.0 = Release|Win32 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Debug|x64.ActiveCfg = Debug|x64 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Debug|x64.Build.0 = Debug|x64 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Release|x64.ActiveCfg = Release|x64 + {2A776B98-0216-4882-A0EA-1AC2251AD597}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {A2EE1D94-8521-48CE-B925-271ACA5DD459} = {83E67B5A-A079-4795-BB30-7DF17133F3F2} - {B506A244-2ADC-4C65-85B8-8B19764B4849} = {17CBFF38-C5AD-417C-8CC8-864EE0DDDD4C} - {AADDAE40-9C46-4C50-AC5F-FF957C3A6E94} = {7F96521C-27C0-448F-9408-BE90EAEAC221} - {9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2} = {2E43D7E2-4E3C-490D-951B-4271FB00B68D} - {B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3} = {2D8F29A9-064E-4557-BBCB-1A09BCC8CC68} - {83E67B5A-A079-4795-BB30-7DF17133F3F2} = {5581D7EE-1489-4811-94EE-AA7717B4367A} - {17CBFF38-C5AD-417C-8CC8-864EE0DDDD4C} = {8107A759-05EB-4C85-8E43-21D9C34D8437} - {7F96521C-27C0-448F-9408-BE90EAEAC221} = {8107A759-05EB-4C85-8E43-21D9C34D8437} - {2E43D7E2-4E3C-490D-951B-4271FB00B68D} = {2FC6C414-6626-45DC-9519-70E6412A131E} - {2D8F29A9-064E-4557-BBCB-1A09BCC8CC68} = {2FC6C414-6626-45DC-9519-70E6412A131E} + {279A982A-666D-434D-A53D-3FF3CEBC175D} = {ABF4399D-D992-42E1-8EBF-68C9CFB7F2C3} + {8D6A9C42-F4FA-4D7B-A038-5209844883C3} = {CD3B1A5A-0BBE-4F0C-B412-2A5662ED766A} + {5346197B-56DB-4486-BEE2-68D0380B7D5B} = {B1A01E5B-0A99-42AD-A897-8B91E9ADAB2F} + {AD63285D-E1DA-41F5-93F8-A076CF4A3B64} = {82373034-DC87-4536-9BE6-06818943E8BA} + {2A776B98-0216-4882-A0EA-1AC2251AD597} = {52BF960B-FC39-4AC7-9486-C3EC71456856} + {ABF4399D-D992-42E1-8EBF-68C9CFB7F2C3} = {556D6471-9F94-46BB-BF1D-B4436E8577E1} + {CD3B1A5A-0BBE-4F0C-B412-2A5662ED766A} = {A10654D9-385E-4D89-B10B-992F8B31D5DC} + {B1A01E5B-0A99-42AD-A897-8B91E9ADAB2F} = {A10654D9-385E-4D89-B10B-992F8B31D5DC} + {82373034-DC87-4536-9BE6-06818943E8BA} = {23D66828-26DC-48AC-A34B-6503C2345B78} + {52BF960B-FC39-4AC7-9486-C3EC71456856} = {23D66828-26DC-48AC-A34B-6503C2345B78} EndGlobalSection EndGlobal diff --git a/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj b/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj index 612205d0..2f38026b 100644 --- a/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj +++ b/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj @@ -19,11 +19,11 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{9DF556F0-A8AB-41C6-A9A4-EEB07CA724A2}</ProjectGuid> + <ProjectGuid>{4BAF5A1E-F44D-4883-8434-758C29841444}</ProjectGuid> <RootNamespace>$(MSBuildProjectName)</RootNamespace> <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{6D053B10-3595-40FE-AB0C-0BFF3690D74B}</SampleGuid> + <SampleGuid>{E2F8D294-B9B1-4F9E-9A7B-F0A49D7C4C8F}</SampleGuid> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -177,7 +177,6 @@ <ItemGroup> <Inf Exclude="@(Inf)" Include="*.inf" /> <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> diff --git a/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj.Filters b/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj.Filters index d6a736d1..a4d8af9a 100644 --- a/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj.Filters +++ b/bluetooth/bthecho/bthsrv/inst/bthsrvinst.vcxproj.Filters @@ -3,15 +3,15 @@ <ItemGroup> <Filter Include="Source Files"> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{269E58B5-F87C-40BF-9AF8-D7A43956F273}</UniqueIdentifier> + <UniqueIdentifier>{54764289-21F6-4CB7-B759-F580ABFAA48F}</UniqueIdentifier> </Filter> <Filter Include="Header Files"> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{C83F223A-D6E4-4CBD-BE8A-F23F9C51CD21}</UniqueIdentifier> + <UniqueIdentifier>{2CA7739A-5BEB-4DBE-B55B-4E42BC89D6BC}</UniqueIdentifier> </Filter> <Filter Include="Resource Files"> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{E0EF99F8-3D01-474D-9924-A4E579A44058}</UniqueIdentifier> + <UniqueIdentifier>{755A8841-90F7-4E7A-92AF-47B1BF16358B}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> diff --git a/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.inx b/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.inx index c414b565..a85479d0 100644 --- a/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.inx +++ b/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.inx @@ -21,7 +21,7 @@ Signature="$WINDOWS NT$" Class=Sample ClassGuid={e0cbf06c-cd8b-4647-bb8a-263b43f0f974} -Provider=%MSFTSAMPLE% +Provider=%ProviderString% DriverVer=06/21/2006,6.0.6001.16625 CatalogFile=KmdfSamples.cat @@ -39,8 +39,7 @@ BthEchoSampleSrv.sys = 1,, ;***************************************** [Manufacturer] -%MSFTSAMPLE%=Microsoft,NTamd64...1 -%MSFTSAMPLE%=Microsoft,NTx86...1 +%ManufacturerString%=Microsoft,NTx86...1,NTamd64...1 [Microsoft.NTamd64...1] %BthEchoSampleSrv.DeviceDesc% = BthEchoSampleSrv_Inst,BTHENUM\{c07508f2-b970-43ca-b5dd-cc4f2391bef4} @@ -95,8 +94,8 @@ KmdfLibraryVersion = $KMDFVERSION$ [Strings] SPSVCINST_ASSOCSERVICE= 0x00000002 -MSFTSAMPLE = "Microsoft Sample" -StdMfg = "(Standard system devices)" +ProviderString = "TODO-Set-Provider" +ManufacturerString = "TODO-Set-Manufacturer" DiskId1 = "BthEchoSampleSrv installation disk" BthEchoSampleSrv.DeviceDesc = "Bluetooth Echo Sample Server" BthEchoSampleSrv.SVCDESC = "BthEchoSampleSrv" diff --git a/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj b/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj index d175beea..c46955f2 100644 --- a/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj +++ b/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj @@ -19,12 +19,12 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{B3D6AD34-E4B4-4C3E-8CD2-583FFE3501E3}</ProjectGuid> + <ProjectGuid>{E76B7342-7D14-4C40-ADA4-40D0269CC2C4}</ProjectGuid> <RootNamespace>$(MSBuildProjectName)</RootNamespace> <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{B2ECC080-547B-4E53-90B4-DD7637A509E1}</SampleGuid> + <SampleGuid>{8092859B-AF55-4BF1-A3F4-945B4198D753}</SampleGuid> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -187,7 +187,6 @@ <ItemGroup> <Inf Exclude="@(Inf)" Include="*.inf" /> <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> diff --git a/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj.Filters b/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj.Filters index bcf30fdb..12d1cfc1 100644 --- a/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj.Filters +++ b/bluetooth/bthecho/bthsrv/sys/BthEchoSampleSrv.vcxproj.Filters @@ -3,19 +3,19 @@ <ItemGroup> <Filter Include="Source Files"> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{AD6BD7F9-8AA3-4C43-80E5-43FAB4855E99}</UniqueIdentifier> + <UniqueIdentifier>{DB9631DF-48DF-461B-AE7F-506167663FDB}</UniqueIdentifier> </Filter> <Filter Include="Header Files"> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{C9966B02-9CF0-4709-81DB-6C07A8C61EA2}</UniqueIdentifier> + <UniqueIdentifier>{80DE4EC6-38A5-4477-89E7-7474A47F2AB9}</UniqueIdentifier> </Filter> <Filter Include="Resource Files"> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{3EB93E42-3C57-45BD-B13C-3BFBBE7327C8}</UniqueIdentifier> + <UniqueIdentifier>{9A504811-A75F-4216-9CF0-308AA242BA42}</UniqueIdentifier> </Filter> <Filter Include="Driver Files"> <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{1AD1BB40-C641-417E-BEEB-6D99F9B5AF3A}</UniqueIdentifier> + <UniqueIdentifier>{D808070A-9612-4A62-842D-141D1C7A3100}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> @@ -36,9 +36,6 @@ </ClCompile> </ItemGroup> <ItemGroup> - <FilesToPackage Include=".\Debug\\BthEchoSampleSrv.inf"> - <Filter>Driver Files</Filter> - </FilesToPackage> <Inf Include=".\BthEchoSampleSrv.inx"> <Filter>Driver Files</Filter> </Inf> diff --git a/bluetooth/bthecho/common/lib/bthecho.vcxproj b/bluetooth/bthecho/common/lib/bthecho.vcxproj index 1ff84251..0966aafa 100644 --- a/bluetooth/bthecho/common/lib/bthecho.vcxproj +++ b/bluetooth/bthecho/common/lib/bthecho.vcxproj @@ -19,12 +19,12 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{A2EE1D94-8521-48CE-B925-271ACA5DD459}</ProjectGuid> + <ProjectGuid>{279A982A-666D-434D-A53D-3FF3CEBC175D}</ProjectGuid> <RootNamespace>$(MSBuildProjectName)</RootNamespace> <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{7D08015D-5262-4372-8E97-C25A002DA190}</SampleGuid> + <SampleGuid>{2887F895-DC60-4F81-9E78-B126FC82D6DE}</SampleGuid> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -188,7 +188,6 @@ <ItemGroup> <Inf Exclude="@(Inf)" Include="*.inf" /> <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> diff --git a/bluetooth/bthecho/common/lib/bthecho.vcxproj.Filters b/bluetooth/bthecho/common/lib/bthecho.vcxproj.Filters index 70735b7e..ec089435 100644 --- a/bluetooth/bthecho/common/lib/bthecho.vcxproj.Filters +++ b/bluetooth/bthecho/common/lib/bthecho.vcxproj.Filters @@ -3,19 +3,19 @@ <ItemGroup> <Filter Include="Source Files"> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{2F1B68C0-756D-4458-87A8-8E75D9D889E3}</UniqueIdentifier> + <UniqueIdentifier>{6217FA2C-0C23-4AB7-A668-E0C7E3CA4CF6}</UniqueIdentifier> </Filter> <Filter Include="Header Files"> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{B9556308-CC93-4C4F-A7E2-55F119DCD6DA}</UniqueIdentifier> + <UniqueIdentifier>{620A4632-EEE2-4CB4-AC1B-3E0BB40B6E8F}</UniqueIdentifier> </Filter> <Filter Include="Resource Files"> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{A3F3F256-9D63-4D56-8493-B44D13A67F0A}</UniqueIdentifier> + <UniqueIdentifier>{0A73451A-D21E-42CE-810D-663390E414AF}</UniqueIdentifier> </Filter> <Filter Include="Driver Files"> <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{11D85DF8-6812-42E3-A08E-798DE942BED5}</UniqueIdentifier> + <UniqueIdentifier>{BD9AA505-1CD0-4D77-AECB-D3D8871886E6}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> diff --git a/bluetooth/serialhcibus/Fdo.c b/bluetooth/serialhcibus/Fdo.c index c7fcc4ff..8082e4e8 100644 --- a/bluetooth/serialhcibus/Fdo.c +++ b/bluetooth/serialhcibus/Fdo.c @@ -9,7 +9,7 @@ Module Name: Abstract: This module contains routines to handle the function driver - aspect of the bus driver. + aspect of the bus driver. Environment: @@ -18,13 +18,12 @@ Environment: --*/ #include "driver.h" -#include <reshub.h> +#include <reshub.h> #include "fdo.tmh" #define BTHX_VALID_WRITE_PACKET_TYPE(type) (type == HciPacketCommand || type == HciPacketAclData) #define BTHX_VALID_READ_PACKET_TYPE(type) (type == HciPacketEvent || type == HciPacketAclData) - #ifdef ALLOC_PRAGMA #pragma alloc_text (PAGE, FdoCreateOneChildDevice) #pragma alloc_text (PAGE, FdoRemoveOneChildDevice) @@ -40,14 +39,14 @@ Environment: #endif // -// Child device node, PDO(s), could be enumerated statically if number of PDOs are known -// at driver start, or dynamic enuermation mechanism is used. Both methods are presented +// Child device node, PDO(s), could be enumerated statically if number of PDOs are known +// at driver start, or dynamic enuermation mechanism is used. Both methods are presented // in this code, but only one can be chosen using the define macro (see sources file). // #ifdef DYNAMIC_ENUM typedef struct _ENABLE_PDO_CONTEXT { - WDFDEVICE Fdo; + WDFDEVICE Fdo; } ENABLE_PDO_CONTEXT, *PENABLE_PDO_CONTEXT; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(ENABLE_PDO_CONTEXT, GetEnablePdoWorkItemContext) @@ -68,31 +67,31 @@ Arguments: _pWorkItem - work item that contains a context to help carrying out its task -Return Value: ---*/ +Return Value: +--*/ { - PENABLE_PDO_CONTEXT Context; + PENABLE_PDO_CONTEXT Context; LARGE_INTEGER RemoteWakeTimeout; - + NTSTATUS Status = STATUS_SUCCESS; PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP, ("+DeviceEnablePDOWorker")); - Context = GetEnablePdoWorkItemContext(_WorkItem); + DoTrace(LEVEL_INFO, TFLAG_PNP, ("+DeviceEnablePDOWorker")); + Context = GetEnablePdoWorkItemContext(_WorkItem); - RemoteWakeTimeout.QuadPart = WDF_REL_TIMEOUT_IN_MS(g_WaitToEnablePDO); - KeDelayExecutionThread(KernelMode, FALSE, &RemoteWakeTimeout); + RemoteWakeTimeout.QuadPart = WDF_REL_TIMEOUT_IN_MS(g_WaitToEnablePDO); + KeDelayExecutionThread(KernelMode, FALSE, &RemoteWakeTimeout); - DoTrace(LEVEL_INFO, TFLAG_PNP, ("+Complete the wait")); + DoTrace(LEVEL_INFO, TFLAG_PNP, ("+Complete the wait")); Status = FdoCreateOneChildDeviceDynamic(Context->Fdo, BT_PDO_HARDWARE_IDS, sizeof(BT_PDO_HARDWARE_IDS)/sizeof(WCHAR), - BLUETOOTH_FUNC_IDS ); + BLUETOOTH_FUNC_IDS ); + + DoTrace(LEVEL_INFO, TFLAG_POWER, ("-DeviceEnablePDOWorker %!STATUS!", Status)); - DoTrace(LEVEL_INFO, TFLAG_POWER, ("-DeviceEnablePDOWorker %!STATUS!", Status)); - } NTSTATUS @@ -138,7 +137,6 @@ Return Value: pDesc->SerialNo); } - NTSTATUS FdoCreateOneChildDeviceDynamic( _In_ WDFDEVICE _Device, @@ -187,7 +185,7 @@ Routine Description: // response to InvalidateDeviceRelations call made as part of adding // a new child. // - Status = WdfChildListAddOrUpdateChildDescriptionAsPresent(WdfFdoGetDefaultChildList(_Device), + Status = WdfChildListAddOrUpdateChildDescriptionAsPresent(WdfFdoGetDefaultChildList(_Device), &Description.Header, NULL); // AddressDescription @@ -204,32 +202,31 @@ Routine Description: #endif // ifdef DYNAMIC_ENUM - NTSTATUS FdoCreateOneChildDevice( _In_ WDFDEVICE _Device, - _In_ PWSTR _HardwareIds, + _In_ PWSTR _HardwareIds, _In_ ULONG _SerialNo ) /*++ Routine Description: - Create a new PDO, initialize it, add it to the list of PDOs for this + Create a new PDO, initialize it, add it to the list of PDOs for this FDO bus. Arguments: _Device - WDF device object - _HardwareIDs - hardware Id for a device + _HardwareIDs - hardware Id for a device _SerialNo - Unique ID for a child DO Returns: Status - + --*/ { NTSTATUS Status = STATUS_SUCCESS; @@ -240,7 +237,7 @@ Returns: PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP, ("+ FdoCreateOneChildDevice() HWID: %S", _HardwareIds)); + DoTrace(LEVEL_INFO, TFLAG_PNP, ("+ FdoCreateOneChildDevice() HWID: %S", _HardwareIds)); // // First make sure that we don't already have another device with the @@ -271,7 +268,7 @@ Returns: WdfFdoLockStaticChildListForIteration(_Device); while ((ChildDevice = WdfFdoRetrieveNextStaticChild(_Device, - ChildDevice, + ChildDevice, WdfRetrieveAddedChildren)) != NULL) { // // WdfFdoRetrieveNextStaticChild returns reported and to be reported @@ -306,7 +303,7 @@ Returns: WdfFdoUnlockStaticChildListFromIteration(_Device); WdfWaitLockRelease(FdoExtension->ChildLock); - DoTrace(LEVEL_INFO, TFLAG_PNP, ("- FdoCreateOneChildDevice() %!STATUS!", Status)); + DoTrace(LEVEL_INFO, TFLAG_PNP, ("- FdoCreateOneChildDevice() %!STATUS!", Status)); return Status; } @@ -334,10 +331,10 @@ Arguments: Returns: Status - + --*/ -{ +{ PPDO_EXTENSION PdoExtension; BOOLEAN Found = FALSE; BOOLEAN PlugOutAll; @@ -353,7 +350,7 @@ Returns: WdfFdoLockStaticChildListForIteration(_Device); while ((ChildDevice = WdfFdoRetrieveNextStaticChild(_Device, - ChildDevice, + ChildDevice, WdfRetrieveAddedChildren)) != NULL) { if (PlugOutAll) { @@ -366,7 +363,7 @@ Returns: Found = TRUE; } else { - PdoExtension = PdoGetExtension(ChildDevice); + PdoExtension = PdoGetExtension(ChildDevice); if (_SerialNo == PdoExtension->SerialNo) { @@ -391,7 +388,6 @@ Returns: return Status; } - NTSTATUS FdoCreateAllChildren( _In_ WDFDEVICE _Device @@ -400,7 +396,7 @@ FdoCreateAllChildren( Routine Description: The routine enables you to statically enumerate child device functions - during start. + during start. Arguments: @@ -408,25 +404,25 @@ Arguments: Returns: - Status + Status --*/ { - NTSTATUS Status; + NTSTATUS Status; PFDO_EXTENSION FdoExtension; PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP, (" + FdoCreateAllChildren")); + DoTrace(LEVEL_INFO, TFLAG_PNP, (" + FdoCreateAllChildren")); - // + // // Bus driver enumerates all child devnode in this function. // Vendor Specific: retrieve all statically saved devnode info // HWID, COMPATID, etc. // - + // - // This sample code only enuemrate the Bluetooth function as the only + // This sample code only enuemrate the Bluetooth function as the only // child device. // Status = FdoCreateOneChildDevice(_Device, @@ -436,16 +432,15 @@ Returns: FdoExtension = FdoGetExtension(_Device); if (NT_SUCCESS(Status)) { FdoExtension->IsRadioEnabled = TRUE; - } - + } + return Status; } - NTSTATUS HlpInitializeFdoExtension( - WDFDEVICE _Device + WDFDEVICE _Device ) /*++ Routine Description: @@ -460,7 +455,7 @@ Return Value: Status ---*/ +--*/ { PFDO_EXTENSION FdoExtension; WDF_OBJECT_ATTRIBUTES Attributes; @@ -468,7 +463,7 @@ Return Value: PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP,("+HlpInitializeFdoExtension")); + DoTrace(LEVEL_INFO, TFLAG_PNP,("+HlpInitializeFdoExtension")); FdoExtension = FdoGetExtension(_Device); FdoExtension->WdfDevice = _Device; @@ -476,58 +471,62 @@ Return Value: // // Set Bluetooth (PDO) capabilities // MaxAclTransferInSize - is used by the host to notify the Bluetooth controller - // in HCI_Host_Buffer_Size command to set the maximum size of the data portion - // of an HCI ACL packet that will be sent from the controller to the host. + // in HCI_Host_Buffer_Size command to set the maximum size of the data portion + // of an HCI ACL packet that will be sent from the controller to the host. // BthMini will only send down an HCI read request with this data buffer size. // - FdoExtension->BthXCaps.MaxAclTransferInSize = MAX_HCI_ACLDATA_SIZE; + FdoExtension->BthXCaps.MaxAclTransferInSize = MAX_HCI_ACLDATA_SIZE; FdoExtension->BthXCaps.ScoSupport = ScoSupportHCIBypass; // Only option FdoExtension->BthXCaps.MaxScoChannels = 1; // Limit to 1 HCIBypass channel FdoExtension->BthXCaps.IsDeviceIdleCapable = TRUE; // Disable Idle to S0 and wake FdoExtension->BthXCaps.IsDeviceWakeCapable = FALSE; // Wake from Sx - + + // + // Preallocate Request // - // Preallocate Request - // WDF_OBJECT_ATTRIBUTES_INIT(&Attributes); - Attributes.ParentObject = _Device; - + Attributes.ParentObject = _Device; + Status = WdfRequestCreate(&Attributes, FdoExtension->IoTargetSerial, &FdoExtension->RequestIoctlSync); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_PNP, (" WdfRequestCreate failed %!STATUS!", Status)); goto Exit; - } + } FdoExtension->HardwareErrorDetected = FALSE; Status = WdfRequestCreate(&Attributes, FdoExtension->IoTargetSerial, &FdoExtension->RequestWaitOnError); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_PNP, (" WdfRequestCreate failed %!STATUS!", Status)); goto Exit; - } - - Status = WdfMemoryCreatePreallocated(&Attributes, + } + + Status = WdfMemoryCreatePreallocated(&Attributes, &FdoExtension->SerErrorMask, sizeof(FdoExtension->SerErrorMask), - &FdoExtension->WaitMaskMemory); + &FdoExtension->WaitMaskMemory); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_PNP, (" WdfMemoryCreatePreallocated failed %!STATUS!", Status)); goto Exit; - } + } - KeInitializeSpinLock(&FdoExtension->QueueAccessLock); + Status = WdfSpinLockCreate(&Attributes, &FdoExtension->QueueAccessLock); + if (!NT_SUCCESS(Status)) + { + DoTrace(LEVEL_ERROR, TFLAG_PNP, (" WdfSpinLockCreate failed %!STATUS!", Status)); + goto Exit; + } Exit: - + return Status; } - VOID FdoEvtDeviceDisarmWake( _In_ WDFDEVICE _Device @@ -535,12 +534,11 @@ FdoEvtDeviceDisarmWake( /*++ Routine Description: - - This function is invoked by the framework after the bus driver determines - that an event has awakened the device, and after the bus driver subsequently + This function is invoked by the framework after the bus driver determines + that an event has awakened the device, and after the bus driver subsequently completes the wait/wake IRP. - This function perform any hardware operations that are needed to disable + This function perform any hardware operations that are needed to disable the device's ability to trigger a wake signal after the power has been lowered. Arguments: @@ -551,13 +549,12 @@ Return Value: VOID ---*/ -{ +--*/ +{ UNREFERENCED_PARAMETER(_Device); DoTrace(LEVEL_INFO, TFLAG_PNP,(" FdoEvtDeviceDisarmWake")); } - NTSTATUS FdoEvtDeviceArmWake( _In_ WDFDEVICE _Device @@ -566,8 +563,8 @@ FdoEvtDeviceArmWake( Routine Description: This function is invoked while the device is still in the D0 device power state, - before the bus driver lowers the device's power state but after the framework - has sent a wait/wake IRP on behalf of the driver. + before the bus driver lowers the device's power state but after the framework + has sent a wait/wake IRP on behalf of the driver. Arguments: @@ -577,14 +574,14 @@ Return Value: NTSTATUS ---*/ +--*/ { NTSTATUS Status = STATUS_SUCCESS; UNREFERENCED_PARAMETER(_Device); - + DoTrace(LEVEL_INFO, TFLAG_PNP,(" FdoEvtDeviceArmWake")); - return Status; + return Status; } NTSTATUS @@ -620,7 +617,7 @@ Return Value: { PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor; - PFDO_EXTENSION FdoExtension; + PFDO_EXTENSION FdoExtension; ULONG Index; ULONG ResourceCount = 0; NTSTATUS Status; @@ -630,96 +627,94 @@ Return Value: PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoFindConnectResources")); + DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoFindConnectResources")); FdoExtension = FdoGetExtension(_Device); Status = STATUS_SUCCESS; // - // Walk through the resource list and find and cache expected resources. + // Walk through the resource list and find and cache expected resources. // ResourceCount = WdfCmResourceListGetCount(_ResourcesTranslated); - - for (Index = 0; Index < ResourceCount; Index++) + + for (Index = 0; Index < ResourceCount; Index++) { Descriptor = WdfCmResourceListGetDescriptor(_ResourcesTranslated, Index); - - switch(Descriptor->Type) - { + + switch(Descriptor->Type) + { case CmResourceTypeConnection: // // Cache connetion ID that this BT Peripheral device is connected to // - UART (must exist) - // - GPIO (optional) + // - GPIO (optional) // - + if ((Descriptor->u.Connection.Class == CM_RESOURCE_CONNECTION_CLASS_SERIAL) && - (Descriptor->u.Connection.Type == CM_RESOURCE_CONNECTION_TYPE_SERIAL_UART)) + (Descriptor->u.Connection.Type == CM_RESOURCE_CONNECTION_TYPE_SERIAL_UART)) { NT_ASSERT(UartConnectionIdIsFound == FALSE && L"More than one set of UART connection"); - + UartConnectionIdIsFound = TRUE; - + FdoExtension->UARTConnectionId.LowPart = Descriptor->u.Connection.IdLowPart; FdoExtension->UARTConnectionId.HighPart = Descriptor->u.Connection.IdHighPart; - DoTrace(LEVEL_INFO, TFLAG_PNP,(" UART ConnectionID (0x%x, 0x%x)", + DoTrace(LEVEL_INFO, TFLAG_PNP,(" UART ConnectionID (0x%x, 0x%x)", FdoExtension->UARTConnectionId.HighPart, FdoExtension->UARTConnectionId.LowPart)); - } + } else if ((Descriptor->u.Connection.Class == CM_RESOURCE_CONNECTION_CLASS_SERIAL) && - (Descriptor->u.Connection.Type == CM_RESOURCE_CONNECTION_TYPE_SERIAL_I2C)) + (Descriptor->u.Connection.Type == CM_RESOURCE_CONNECTION_TYPE_SERIAL_I2C)) { FdoExtension->I2CConnectionId.LowPart = Descriptor->u.Connection.IdLowPart; FdoExtension->I2CConnectionId.HighPart = Descriptor->u.Connection.IdHighPart; - - DoTrace(LEVEL_INFO, TFLAG_PNP,(" I2C ConnectionID (0x%x, 0x%x)", + + DoTrace(LEVEL_INFO, TFLAG_PNP,(" I2C ConnectionID (0x%x, 0x%x)", FdoExtension->I2CConnectionId.HighPart, FdoExtension->I2CConnectionId.LowPart)); - } + } else if ((Descriptor->u.Connection.Class == CM_RESOURCE_CONNECTION_CLASS_GPIO) && - (Descriptor->u.Connection.Type == CM_RESOURCE_CONNECTION_TYPE_GPIO_IO)) + (Descriptor->u.Connection.Type == CM_RESOURCE_CONNECTION_TYPE_GPIO_IO)) { FdoExtension->GPIOConnectionId.LowPart = Descriptor->u.Connection.IdLowPart; FdoExtension->GPIOConnectionId.HighPart = Descriptor->u.Connection.IdHighPart; - - DoTrace(LEVEL_INFO, TFLAG_PNP,(" GPIO ConnectionID (0x%x, 0x%x)", + + DoTrace(LEVEL_INFO, TFLAG_PNP,(" GPIO ConnectionID (0x%x, 0x%x)", FdoExtension->GPIOConnectionId.HighPart, FdoExtension->GPIOConnectionId.LowPart)); - } + } break; - + case CmResourceTypeInterrupt: - + // // NT Interrupt to support HOST_WAKE for remote wake (TBD) - // - + // + default: - DoTrace(LEVEL_INFO, TFLAG_PNP,(" Resource type %d not used.", Descriptor->Type)); + DoTrace(LEVEL_INFO, TFLAG_PNP,(" Resource type %d not used.", Descriptor->Type)); break; } } - - // + // // Expect to find UART controller - // + // if (!UartConnectionIdIsFound) { Status = STATUS_NOT_FOUND; } - DoTrace(LEVEL_INFO, TFLAG_PNP,("-FdoFindConnectResources ResourceCount %d, %!STATUS!", ResourceCount, Status)); - + DoTrace(LEVEL_INFO, TFLAG_PNP,("-FdoFindConnectResources ResourceCount %d, %!STATUS!", ResourceCount, Status)); + return Status; } - NTSTATUS FdoOpenDevice( _In_ WDFDEVICE _Device, @@ -741,34 +736,33 @@ Return Value: NTSTATUS ---*/ -{ - NTSTATUS Status = STATUS_SUCCESS; +--*/ +{ + NTSTATUS Status = STATUS_SUCCESS; WDFIOTARGET IoTargetSerial; PFDO_EXTENSION FdoExtension = NULL; WCHAR TargetDeviceNameBuffer[100]; PWSTR SymbolicLinkList = NULL; UNICODE_STRING TargetDeviceName; - - WDF_IO_TARGET_OPEN_PARAMS OpenParams; - - DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoOpenDevice")); + WDF_IO_TARGET_OPEN_PARAMS OpenParams; + + DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoOpenDevice")); Status = WdfIoTargetCreate(_Device, - WDF_NO_OBJECT_ATTRIBUTES, + WDF_NO_OBJECT_ATTRIBUTES, &IoTargetSerial); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { goto Exit; - } + } FdoExtension = FdoGetExtension(_Device); // - // On SoC platform, a valid connection ID to a UART is set; if not, the legacy way - // of enumerating serial device interface is used. + // On SoC platform, a valid connection ID to a UART is set; if not, the legacy way + // of enumerating serial device interface is used. // if (ValidConnectionID(FdoExtension->UARTConnectionId)) @@ -786,7 +780,7 @@ Return Value: goto Exit; } } - else + else { // Query the system for device with SERIAL interface Status = IoGetDeviceInterfaces(&GUID_DEVINTERFACE_COMPORT, @@ -794,7 +788,7 @@ Return Value: 0, &SymbolicLinkList // List of symbolic names; separate by NULL, EOL with NULL+NULL. ); - + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_INFO, TFLAG_PNP,("IoGetDeviceInterfaces(): %!STATUS!", Status)); @@ -810,13 +804,13 @@ Return Value: // A list of devices is returned, we use only the first one. // ACPI component will enuermate us and this step is not necessary. - RtlInitUnicodeString(&TargetDeviceName, SymbolicLinkList); + RtlInitUnicodeString(&TargetDeviceName, SymbolicLinkList); } - DoTrace(LEVEL_INFO, TFLAG_PNP, (" Symbolic Name '%S'", TargetDeviceName.Buffer)); + DoTrace(LEVEL_INFO, TFLAG_PNP, (" Symbolic Name '%S'", TargetDeviceName.Buffer)); // - // Open the "remote" IO Target (device) using its symbolic link. + // Open the "remote" IO Target (device) using its symbolic link. // WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME(&OpenParams, &TargetDeviceName, @@ -826,48 +820,47 @@ Return Value: // // Open this serial device (Io Target) in order to send IOCTL_SERIAL_* control to it. // - Status = WdfIoTargetOpen(IoTargetSerial, - &OpenParams); - - if (!NT_SUCCESS(Status)) + Status = WdfIoTargetOpen(IoTargetSerial, + &OpenParams); + + if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_INFO, TFLAG_PNP, ( " WdfIoTargetOpen failed %!STATUS!", Status)); + DoTrace(LEVEL_INFO, TFLAG_PNP, ( " WdfIoTargetOpen failed %!STATUS!", Status)); WdfObjectDelete(IoTargetSerial); goto Exit; - } - + } + *_pIoTarget = IoTargetSerial; - + Exit: - + if (SymbolicLinkList) { ExFreePool(SymbolicLinkList); SymbolicLinkList = NULL; - } - + } + return Status; } - NTSTATUS FdoSetIdleSettings( _In_ WDFDEVICE _Device, _In_ IDLE_CAP_STATE _IdleCapState - ) + ) /*++ Routine Description: - This function defines how device idle (Dx) is support while system is in - (S0) for the Serial Hci device (not its child node, which is supported - in the PDO). - + This function defines how device idle (Dx) is support while system is in + (S0) for the Serial Hci device (not its child node, which is supported + in the PDO). + If its Enuemrator is "ROOT" (in the case of using a Bluetooth dev board), its Idle support is IdleCannotWakeFromS0. Its power capabilities are - limited to D0 and D3; it is basically on or off, and there is no Idle + limited to D0 and D3; it is basically on or off, and there is no Idle while in S0. - Vendor: If its Enumerator is ACPI, then it might be possible to support + Vendor: If its Enumerator is ACPI, then it might be possible to support idle while in S0. This is vendor specific. Arguments: @@ -880,15 +873,15 @@ Return Value: NTSTATUS ---*/ +--*/ { WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS IdleSettings; - NTSTATUS Status = STATUS_SUCCESS; + NTSTATUS Status = STATUS_SUCCESS; BOOLEAN AssignS0IdleSettings = TRUE; - DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoSetIdleSettings")); + DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoSetIdleSettings")); - switch (_IdleCapState) + switch (_IdleCapState) { case IdleCapActiveOnly: @@ -896,87 +889,87 @@ Return Value: // By default ACPI supports D0 active, and idle to D3 without remote wake. // While in D3, only host (e.g. IO request) can wake the device to D0. // - WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&IdleSettings, - IdleCannotWakeFromS0); - - // Low Dx state to enter after IdleTimeout has expired and Idle is enabled. - IdleSettings.DxState = PowerDeviceD3; + WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&IdleSettings, + IdleCannotWakeFromS0); + + // Low Dx state to enter after IdleTimeout has expired and Idle is enabled. + IdleSettings.DxState = PowerDeviceD3; IdleSettings.IdleTimeout = IdleTimeoutDefaultValue; // Use default (~5 seconds) - IdleSettings.IdleTimeoutType = DriverManagedIdleTimeout; // Driver is in control (typically for out of SoC). - - // Idle to DxState is not initially disable, and do not allow user control to enable it (as this is active only). - IdleSettings.UserControlOfIdleSettings = IdleDoNotAllowUserControl; - IdleSettings.Enabled = WdfFalse; + IdleSettings.IdleTimeoutType = DriverManagedIdleTimeout; // Driver is in control (typically for out of SoC). + + // Idle to DxState is not initially disable, and do not allow user control to enable it (as this is active only). + IdleSettings.UserControlOfIdleSettings = IdleDoNotAllowUserControl; + IdleSettings.Enabled = WdfFalse; - // Do not wake from D3 to D0 due to system wake (Sx to S0); ie only host app can wake. - IdleSettings.PowerUpIdleDeviceOnSystemWake = WdfFalse; + // Do not wake from D3 to D0 due to system wake (Sx to S0); ie only host app can wake. + IdleSettings.PowerUpIdleDeviceOnSystemWake = WdfFalse; break; - + case IdleCapCanWake: - + // // If it has a child PDO and there is a controller (GPIO) being configured to support wake, // this state can be supported. // - // Vendor: in order to support idle in S0 for this ACPI enumerated device, specify that the device + // Vendor: in order to support idle in S0 for this ACPI enumerated device, specify that the device // can wake in S0. For example, if it can wake from D2 in S0, this should be set in its device section: // // Name(_S0W, 0x2) // - // Additionally, the wake interrupt, e.g. HOST_WAKE, will need to be known by ACPI (instead of exposing - // it directly to this driver as system resource); so that, ACPI will do the arming and wake on this - // driver's behalf with Dx state transition. + // Additionally, the wake interrupt, e.g. HOST_WAKE, will need to be known by ACPI (instead of exposing + // it directly to this driver as system resource); so that, ACPI will do the arming and wake on this + // driver's behalf with Dx state transition. // - - WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&IdleSettings, - IdleCanWakeFromS0); - - // Low Dx state to enter after IdleTimeout has expired and Idle is enabled. - IdleSettings.DxState = PowerDeviceD2; + + WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&IdleSettings, + IdleCanWakeFromS0); + + // Low Dx state to enter after IdleTimeout has expired and Idle is enabled. + IdleSettings.DxState = PowerDeviceD2; IdleSettings.IdleTimeout = 0; // May want to enter D2 immediately and invoke arm wake callback. - IdleSettings.IdleTimeoutType = DriverManagedIdleTimeout; // Driver is in control (typically for out of SoC). - - // Idle to DxState is initially enable, but allow user control as well (e.g to turn off idle support). - IdleSettings.UserControlOfIdleSettings = IdleAllowUserControl; - IdleSettings.Enabled = WdfTrue; + IdleSettings.IdleTimeoutType = DriverManagedIdleTimeout; // Driver is in control (typically for out of SoC). + + // Idle to DxState is initially enable, but allow user control as well (e.g to turn off idle support). + IdleSettings.UserControlOfIdleSettings = IdleAllowUserControl; + IdleSettings.Enabled = WdfTrue; // // Note: wiil invoke EvtDeviceArmWakeFromS0 callback before entering DxState; // Driver can arm for HOST_WAKE interrrupt in the callback. // break; - + case IdleCapCanTurnOff: // // If there is no child PDO (e.g. in Radio off mode), in effect the BT radio can be turned off - // to enter D3 state. All unused controllers (e.g. GPIO) can be turned off, also + // to enter D3 state. All unused controllers (e.g. GPIO) can be turned off, also // the Bluetooth function block. While in D3 state, only host can wake the device. // // Here is one approach to prevent the FDO from entering DxState while its PDO is in Dx and there is no pending IO: // - // The PDO can hold a reference on its parent to prevent the parent from going into DxState. This is done in + // The PDO can hold a reference on its parent to prevent the parent from going into DxState. This is done in // PrepareHardware with WdfDeviceStopIdle() and releasing that reference // in the PDO's ReleaseHardware with WdfDeviceResumeIdle(). This applies to the case when the PDO is disabled. // In the resource rebalancing case, the FDO may enter D3 shortly and then resume to D0. // - - WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&IdleSettings, - IdleCannotWakeFromS0); - - // Low Dx state to enter after IdleTimeout has expired and Idle is enabled. - IdleSettings.DxState = PowerDeviceD3; - IdleSettings.IdleTimeout = IdleTimeoutDefaultValue; - IdleSettings.IdleTimeoutType = DriverManagedIdleTimeout; // Driver is in control (typically for out of SoC). - - // Idle to DxState is initially enabled, but allow user control as well (e.g. do not turn off). - IdleSettings.UserControlOfIdleSettings = IdleAllowUserControl; - IdleSettings.Enabled = WdfTrue; - // Do not wake from D3 to D0 due to system wake (Sx to S0); ie only host app can wake. - IdleSettings.PowerUpIdleDeviceOnSystemWake = WdfFalse; + WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&IdleSettings, + IdleCannotWakeFromS0); + + // Low Dx state to enter after IdleTimeout has expired and Idle is enabled. + IdleSettings.DxState = PowerDeviceD3; + IdleSettings.IdleTimeout = IdleTimeoutDefaultValue; + IdleSettings.IdleTimeoutType = DriverManagedIdleTimeout; // Driver is in control (typically for out of SoC). + + // Idle to DxState is initially enabled, but allow user control as well (e.g. do not turn off). + IdleSettings.UserControlOfIdleSettings = IdleAllowUserControl; + IdleSettings.Enabled = WdfTrue; + + // Do not wake from D3 to D0 due to system wake (Sx to S0); ie only host app can wake. + IdleSettings.PowerUpIdleDeviceOnSystemWake = WdfFalse; break; - + default: AssignS0IdleSettings = FALSE; break; @@ -985,24 +978,23 @@ Return Value: if (AssignS0IdleSettings) { Status = WdfDeviceAssignS0IdleSettings(_Device, - &IdleSettings); + &IdleSettings); } - - DoTrace(LEVEL_INFO, TFLAG_PNP,("-FdoSetIdleSettings %!STATUS!", Status)); - return Status; -} + DoTrace(LEVEL_INFO, TFLAG_PNP,("-FdoSetIdleSettings %!STATUS!", Status)); + return Status; +} NTSTATUS FdoDevPrepareHardware( _In_ WDFDEVICE _Device, _In_ WDFCMRESLIST _ResourcesRaw, - _In_ WDFCMRESLIST _ResourcesTranslated + _In_ WDFCMRESLIST _ResourcesTranslated ) /*++ Routine Description: - This PnP CB function allocate hardware related resource allocation and + This PnP CB function allocate hardware related resource allocation and perform device initialization. Arguments: @@ -1010,22 +1002,21 @@ Arguments: _Device - WDF Device object _ResourcesRaw - (Not referenced) - + _ResourcesTranslated - (Not referenced) Return Value: NTSTATUS ---*/ +--*/ { NTSTATUS Status; - PFDO_EXTENSION FdoExtension; - - + PFDO_EXTENSION FdoExtension; + PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoDevPrepareHardware")); + DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoDevPrepareHardware")); // // Acquire connection ID of connected controllers (UART and GPIO) @@ -1035,13 +1026,12 @@ Return Value: _ResourcesTranslated); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP, (" Failed to find connection ID of target UART controller %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP, (" Failed to find connection ID of target UART controller %!STATUS!", Status)); // Log(Informational): no UART Connection ID resource - + // Can still use the legacy approach to find it based on its serial interface GUID. } - FdoExtension = FdoGetExtension(_Device); @@ -1049,42 +1039,42 @@ Return Value: // Open Bluetooth UART device as a remote IO Target // Status = FdoOpenDevice(_Device, &FdoExtension->IoTargetSerial); - - if (!NT_SUCCESS(Status) || FdoExtension->IoTargetSerial == NULL) - { + + if (!NT_SUCCESS(Status) || FdoExtension->IoTargetSerial == NULL) + { DoTrace(LEVEL_ERROR, TFLAG_PNP, (" FdoOpenDevice failed %!STATUS!", Status)); - // Log(Error): Failed to open UART controller + // Log(Error): Failed to open UART controller goto Exit; } // // Initialize content of this device extension // - Status = HlpInitializeFdoExtension(_Device); - + Status = HlpInitializeFdoExtension(_Device); + if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP, (" HlpInitializeFdoExtension failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP, (" HlpInitializeFdoExtension failed %!STATUS!", Status)); goto Exit; - } + } // // Set device's idle configuration if it is capable - // - Status = FdoSetIdleSettings(_Device, + // + Status = FdoSetIdleSettings(_Device, IdleCapCanTurnOff); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP, (" FdoSetIdleSettings failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP, (" FdoSetIdleSettings failed %!STATUS!", Status)); // goto Exit; - } + } // Enable serial bus device if (ValidConnectionID(FdoExtension->GPIOConnectionId)) { Status = DeviceEnable(_Device, TRUE); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP,("DeviceEnable failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP,("DeviceEnable failed %!STATUS!", Status)); goto Exit; } } @@ -1093,35 +1083,35 @@ Return Value: if (ValidConnectionID(FdoExtension->I2CConnectionId)) { Status = DevicePowerOn(_Device); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP,("DevicePowerOn failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP,("DevicePowerOn failed %!STATUS!", Status)); goto Exit; } } - + // - // Configure local UART controller + // Configure local UART controller // FdoExtension->DeviceInitialized = DeviceInitialize(FdoExtension, - FdoExtension->IoTargetSerial, + FdoExtension->IoTargetSerial, FdoExtension->RequestIoctlSync, - TRUE); + TRUE); if (!IsDeviceInitialized(FdoExtension)) { // Can have issue if this UART device cannot be initalized Status = STATUS_DEVICE_NOT_READY; - DoTrace(LEVEL_ERROR, TFLAG_PNP, (" DeviceInitialize failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP, (" DeviceInitialize failed %!STATUS!", Status)); - // Log(Error): Failed to intialize/configure the device + // Log(Error): Failed to intialize/configure the device goto Exit; } #ifdef DYNAMIC_ENUM // - // This code segment is for testing: spawn a work item to do dynamic enuermation - // of a Bluetooth dev node (PDO); the actual implementation could be to query + // This code segment is for testing: spawn a work item to do dynamic enuermation + // of a Bluetooth dev node (PDO); the actual implementation could be to query // the peripheral device for what function blocks that it can support, or // to listen for a published interface of its dependent controller driver - // to start the enuermation after driver has started. + // to start the enuermation after driver has started. // { WDF_OBJECT_ATTRIBUTES ObjAttributes; @@ -1129,12 +1119,12 @@ Return Value: WDFWORKITEM WorkItem; PENABLE_PDO_CONTEXT Context; - PAGED_CODE(); + PAGED_CODE(); + + DoTrace(LEVEL_INFO, TFLAG_PNP, ("+CreateWorkItem to enable PDO")); - DoTrace(LEVEL_INFO, TFLAG_PNP, ("+CreateWorkItem to enable PDO")); - WDF_OBJECT_ATTRIBUTES_INIT(&ObjAttributes); - + WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&ObjAttributes, ENABLE_PDO_CONTEXT); ObjAttributes.ParentObject = _Device; @@ -1143,32 +1133,31 @@ Return Value: Status = WdfWorkItemCreate(&WorkitemConfig, &ObjAttributes, &WorkItem); if (NT_SUCCESS(Status)) - { + { // Get and initialize the context - Context = GetEnablePdoWorkItemContext(WorkItem); - Context->Fdo = _Device; - - // Initialize work item context - WdfWorkItemEnqueue(WorkItem); - } + Context = GetEnablePdoWorkItemContext(WorkItem); + Context->Fdo = _Device; + + // Initialize work item context + WdfWorkItemEnqueue(WorkItem); + } } #else - // + // // Perform static PDO enumertion by reading child device info saved in the registry. // But the info needs to be populated first by acquired supported device for supported // child devices. - // + // Status = FdoCreateAllChildren(_Device); #endif - + Exit: - DoTrace(LEVEL_INFO, TFLAG_PNP, ("-FdoDevPrepareHardware %!STATUS!", Status)); - + DoTrace(LEVEL_INFO, TFLAG_PNP, ("-FdoDevPrepareHardware %!STATUS!", Status)); + return Status; } - NTSTATUS FdoDevReleaseHardware( _In_ WDFDEVICE _Device, @@ -1182,22 +1171,22 @@ Routine Description: Arguments: _Device - WDF Device object - + _ResourcesTranslated - (Not referenced) Return Value: NTSTATUS ---*/ +--*/ { - PFDO_EXTENSION FdoExtension; - + PFDO_EXTENSION FdoExtension; + PAGED_CODE(); - - UNREFERENCED_PARAMETER(_ResourcesTranslated); - DoTrace(LEVEL_INFO, TFLAG_PNP,("+PnpReleaseHardware")); + UNREFERENCED_PARAMETER(_ResourcesTranslated); + + DoTrace(LEVEL_INFO, TFLAG_PNP,("+PnpReleaseHardware")); FdoExtension = FdoGetExtension(_Device); @@ -1205,14 +1194,13 @@ Return Value: { WdfObjectDelete(FdoExtension->IoTargetSerial); FdoExtension->IoTargetSerial = NULL; - } - + } + return STATUS_SUCCESS; } - -NTSTATUS +NTSTATUS FdoDevSelfManagedIoInit( _In_ WDFDEVICE _Device ) @@ -1220,7 +1208,7 @@ FdoDevSelfManagedIoInit( Routine Description: This PnP CB function is invoked once and will perform IO related resource allocation - and start the read pump. + and start the read pump. Arguments: @@ -1230,56 +1218,55 @@ Return Value: NTSTATUS ---*/ +--*/ { NTSTATUS Status; PFDO_EXTENSION FdoExtension; - + PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoDevSelfManagedIoInit")); + DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoDevSelfManagedIoInit")); // - // Preallocate resources needed to perform read opeations - // + // Preallocate resources needed to perform read opeations + // Status = ReadResourcesAllocate(_Device); - + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" ReadResourcesAllocate failed %!STATUS!", Status)); goto Exit; - } + } // Issue pending IO request to prefetch HCI event and data FdoExtension = FdoGetExtension(_Device); FdoExtension->ReadContext.RequestState = REQUEST_COMPLETE; - // Start the read pump - FdoExtension->ReadPumpRunning = TRUE; + // Start the read pump + FdoExtension->ReadPumpRunning = TRUE; Status = ReadH4Packet(&FdoExtension->ReadContext, FdoExtension->ReadRequest, FdoExtension->ReadMemory, FdoExtension->ReadBuffer, - INITIAL_H4_READ_SIZE); + INITIAL_H4_READ_SIZE); if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" ReadH4Packet failed %!STATUS!", Status)); goto Exit; - } - + } + Exit: - return Status; + return Status; } - -VOID +VOID FdoDevSelfManagedIoCleanup( _In_ WDFDEVICE _Device ) /*++ Routine Description: - This PnP CB function is invoked once and will be used here to free resource + This PnP CB function is invoked once and will be used here to free resource that was alocated in its corresponding SelfMagedInit fucntion. Arguments: @@ -1290,20 +1277,19 @@ Return Value: none ---*/ -{ +--*/ +{ PAGED_CODE(); - DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoDevSelfManagedIoCleanup")); - + DoTrace(LEVEL_INFO, TFLAG_PNP,("+FdoDevSelfManagedIoCleanup")); + // // Cancel and free resources - // - ReadResourcesFree(_Device); - - return; -} + // + ReadResourcesFree(_Device); + return; +} NTSTATUS FdoDevD0Entry( @@ -1320,33 +1306,33 @@ Routine Description: Arguments: _Device - WDF Device object - + PreviousState - Next power state it is entering from D0 Return Value: NTSTATUS ---*/ +--*/ { PFDO_EXTENSION FdoExtension = FdoGetExtension(_Device); - NTSTATUS Status = STATUS_SUCCESS; + NTSTATUS Status = STATUS_SUCCESS; - UNREFERENCED_PARAMETER(_PreviousState); - - DoTrace(LEVEL_INFO, TFLAG_UART, ("+FdoDevD0Entry")); + UNREFERENCED_PARAMETER(_PreviousState); + + DoTrace(LEVEL_INFO, TFLAG_UART, ("+FdoDevD0Entry")); // Reset error count upon resume to D0 FdoExtension->OutOfSyncErrorCount = 0; // Initialize serial port settings if re-enter D0 - if (!IsDeviceInitialized(FdoExtension)) { + if (!IsDeviceInitialized(FdoExtension)) { // Enable serial bus device if (ValidConnectionID(FdoExtension->GPIOConnectionId)) { Status = DeviceEnable(_Device, TRUE); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP,("DeviceEnable failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP,("DeviceEnable failed %!STATUS!", Status)); goto Done; } } @@ -1355,30 +1341,30 @@ Return Value: if (ValidConnectionID(FdoExtension->I2CConnectionId)) { Status = DevicePowerOn(_Device); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP,("DevicePowerOn failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP,("DevicePowerOn failed %!STATUS!", Status)); goto Done; } } // // The local UART may need to be re-initialized to match the remote UART if its context - // was lost, but the assumption here is that the UART controller driver does save and + // was lost, but the assumption here is that the UART controller driver does save and // restore its context. // #ifdef REQUIRE_REINITIALIZE // Reinitialize serial bus device - FdoExtension->DeviceInitialized = DeviceInitialize(FdoExtension, - FdoExtension->IoTargetSerial, + FdoExtension->DeviceInitialized = DeviceInitialize(FdoExtension, + FdoExtension->IoTargetSerial, FdoExtension->RequestIoctlSync, - FALSE); + FALSE); if (!IsDeviceInitialized(FdoExtension)) { Status = STATUS_DEVICE_NOT_READY; - DoTrace(LEVEL_ERROR, TFLAG_PNP, ("DeviceInitialize failed!")); - goto Done; + DoTrace(LEVEL_ERROR, TFLAG_PNP, ("DeviceInitialize failed!")); + goto Done; } -#else +#else // Set to TRUE in order to restart the read pump FdoExtension->DeviceInitialized = TRUE; #endif @@ -1386,31 +1372,30 @@ Return Value: // Restart the IOTarget to receiving request Status = WdfIoTargetStart(FdoExtension->IoTargetSerial); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_PNP, ("WdfIoTargetStart failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_PNP, ("WdfIoTargetStart failed %!STATUS!", Status)); goto Done; - } - + } + // Restart read pump DoTrace(LEVEL_INFO, TFLAG_IO, (" Restarting read pump")); Status = ReadH4Packet(&FdoExtension->ReadContext, FdoExtension->ReadRequest, FdoExtension->ReadMemory, FdoExtension->ReadBuffer, - INITIAL_H4_READ_SIZE); + INITIAL_H4_READ_SIZE); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_IO, ("ReadH4Packet [0] failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_IO, ("ReadH4Packet [0] failed %!STATUS!", Status)); goto Done; - } - } + } + } Done: - + DoTrace(LEVEL_INFO, TFLAG_UART, ("-FdoDevD0Entry %!STATUS!", Status)); return Status; } - NTSTATUS FdoDevD0Exit( _In_ WDFDEVICE _Device, @@ -1421,34 +1406,34 @@ Routine Description: This PnP CB function is invoked when device has exited D0 (working) state. It stops the queue and can be restarted later, and mark the device uninitialize - and will be initialized again when resumes to D0. + and will be initialized again when resumes to D0. Arguments: _Device - WDF Device object - + _TargetState - Next power state it is entering from D0 Return Value: NTSTATUS ---*/ +--*/ { PFDO_EXTENSION FdoExtension = FdoGetExtension(_Device); - PAGED_CODE(); + PAGED_CODE(); UNREFERENCED_PARAMETER(_TargetState); - + DoTrace(LEVEL_INFO, TFLAG_UART, ("+FdoDevD0Exit D0-> D%d", _TargetState-WdfPowerDeviceD0)); - // Cancel IO requests that are already in the IO queue, + // Cancel IO requests that are already in the IO queue, // wait for their completion before this function is returned. // Can restart this queue at later time. WdfIoTargetStop(FdoExtension->IoTargetSerial, WdfIoTargetCancelSentIo); - // Delete GPIO IoTarget to disable the device and this will + // Delete GPIO IoTarget to disable the device and this will // require device to be re-initialized when it re-enters D0. if (FdoExtension->IoTargetGPIO) { @@ -1460,13 +1445,12 @@ Return Value: // // Note: Do not delete the UART's IoTarget. // - + DoTrace(LEVEL_INFO, TFLAG_UART, ("-FdoDevD0Exit")); return STATUS_SUCCESS; } - NTSTATUS HCIContextValidate( ULONG _Index, @@ -1475,12 +1459,12 @@ HCIContextValidate( /*++ Routine Description: - This function validate the incoming data context and print out (WPP) trace. - + This function validate the incoming data context and print out (WPP) trace. + Arguments: _Index - count number of HCI command/event/data that has been completed (0 based). - _HCIContext - Context to be valdiated + _HCIContext - Context to be valdiated Return Value: @@ -1492,44 +1476,44 @@ Return Value: ULONG Index; DoTrace(LEVEL_INFO, TFLAG_HCI,("+HCIContextValidate")); - + switch ((BTHX_HCI_PACKET_TYPE) _HCIContext->Type) { case HciPacketCommand: - { + { PHCI_COMMAND_PACKET HciCommand = (PHCI_COMMAND_PACKET) _HCIContext->Data; DoTrace(LEVEL_INFO, TFLAG_HCI, (" -> HCI Command [%d] OpCode: 0x%x, nParams: %d ---->", _Index, - HciCommand->Opcode, + HciCommand->Opcode, HciCommand->ParamsCount)); - + for (Index = 0; Index < MinToPrint((ULONG) HciCommand->ParamsCount, MAX_COMMAND_PARAMS_TO_DISPLAY); Index++) { DoTrace(LEVEL_INFO, TFLAG_HCI, (" [%d] 0x%.2x", Index, HciCommand->Params[Index])); } - + if (!WithinRange(MIN_HCI_CMD_SIZE, _HCIContext->DataLen, MAX_HCI_CMD_SIZE)) { Status = STATUS_INVALID_PARAMETER; - DoTrace(LEVEL_ERROR, TFLAG_HCI,(" HciPacketCommand %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_HCI,(" HciPacketCommand %!STATUS!", Status)); break; - } + } } break; - + case HciPacketEvent: { PHCI_EVENT_PACKET HciEvent = (PHCI_EVENT_PACKET) _HCIContext->Data; DoTrace(LEVEL_INFO, TFLAG_HCI, (" <- HCI Event [%d] EventCode: 0x%x (%S), nParams: %d", _Index, - HciEvent->EventCode, - HciEvent->EventCode == CommandComplete ? L"Complete" : + HciEvent->EventCode, + HciEvent->EventCode == CommandComplete ? L"Complete" : HciEvent->EventCode == CommandStatus ? L"Status(Async)!!" : L"??", HciEvent->ParamsCount)); // Note if CommandStatus is returned, there will be another event to complete this command. - + for (Index = 0; Index < MinToPrint((ULONG) HciEvent->ParamsCount, MAX_EVENT_PARAMS_TO_DISPLAY); Index++) { DoTrace(LEVEL_VERBOSE, TFLAG_HCI, (" [%d] 0x%.2x", @@ -1539,13 +1523,13 @@ Return Value: if (!WithinRange(MIN_HCI_EVENT_SIZE, _HCIContext->DataLen, MAX_HCI_EVENT_SIZE)) { Status = STATUS_INVALID_PARAMETER; - DoTrace(LEVEL_ERROR, TFLAG_HCI,(" HciPacketEvent %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_HCI,(" HciPacketEvent %!STATUS!", Status)); break; - } - } + } + } break; - - case HciPacketAclData: + + case HciPacketAclData: { PHCI_ACLDATA_PACKET AclData = (PHCI_ACLDATA_PACKET) _HCIContext->Data; DoTrace(LEVEL_INFO, TFLAG_HCI, (" HCI Data [%d] (Handle:0x%x, PB:%x, BC:%x, Length:%d)", @@ -1554,39 +1538,37 @@ Return Value: AclData->PBFlag, AclData->BCFlag, AclData->DataLength)); - + for (Index = 0; Index < (ULONG) (AclData->DataLength > 8 ? 8 : AclData->DataLength); Index++) { DoTrace(LEVEL_VERBOSE, TFLAG_HCI, (" [%d] 0x%.2x", Index, AclData->Data[Index])); } - - if (!WithinRange(1, AclData->DataLength, MAX_HCI_ACLDATA_SIZE)) + + if (!WithinRange(1, AclData->DataLength, MAX_HCI_ACLDATA_SIZE)) { Status = STATUS_INVALID_PARAMETER; - DoTrace(LEVEL_ERROR, TFLAG_HCI,(" HciPacketAclData data (%d) exceeds its max %d, %!STATUS!", - AclData->DataLength, MAX_HCI_ACLDATA_SIZE, Status)); + DoTrace(LEVEL_ERROR, TFLAG_HCI,(" HciPacketAclData data (%d) exceeds its max %d, %!STATUS!", + AclData->DataLength, MAX_HCI_ACLDATA_SIZE, Status)); break; - } - } + } + } break; - + default: DoTrace(LEVEL_ERROR, TFLAG_HCI, (" Packet type %d unexpected!", _HCIContext->Type)); Status = STATUS_INVALID_PARAMETER; break; } - NT_ASSERT(NT_SUCCESS(Status) && L"Invlaid data is detected!"); + NT_ASSERT(NT_SUCCESS(Status) && L"Invlaid data is detected!"); + + DoTrace(LEVEL_INFO, TFLAG_HCI,("-HCIContextValidate %!STATUS!", Status)); - DoTrace(LEVEL_INFO, TFLAG_HCI,("-HCIContextValidate %!STATUS!", Status)); - return Status; } - - NTSTATUS FdoWriteDeviceIO( _In_ WDFREQUEST _RequestFromBthport, @@ -1598,7 +1580,7 @@ FdoWriteDeviceIO( Routine Description: - This function send an HCI packet to target device. + This function send an HCI packet to target device. Arguments: @@ -1610,18 +1592,17 @@ Arguments: Return Value: NTSTATUS - ---*/ -{ - WDF_OBJECT_ATTRIBUTES ObjAttributes; - NTSTATUS Status; + +--*/ +{ + WDF_OBJECT_ATTRIBUTES ObjAttributes; + NTSTATUS Status; WDFREQUEST RequestToUART; PUART_WRITE_CONTEXT TransferContext = NULL; ULONG DataLength; PVOID Data = NULL; - - DoTrace(LEVEL_INFO, TFLAG_DATA,("+FdoWriteDeviceIO")); + DoTrace(LEVEL_INFO, TFLAG_DATA,("+FdoWriteDeviceIO")); if (!IsDeviceInitialized(_FdoExtension)) { @@ -1635,13 +1616,13 @@ Return Value: // WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&ObjAttributes, UART_WRITE_CONTEXT); - + Status = WdfObjectAllocateContext(_RequestFromBthport, &ObjAttributes, - &TransferContext); + &TransferContext); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfObjectAllocateContext failed %!STATUS!", Status)); - goto Done; + DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfObjectAllocateContext failed %!STATUS!", Status)); + goto Done; } Status = HLP_AllocateResourceForWrite( @@ -1650,72 +1631,71 @@ Return Value: &RequestToUART); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_IO,(" HLP_WriteDeviceIO %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_IO,(" HLP_WriteDeviceIO %!STATUS!", Status)); goto Done; } WDF_OBJECT_ATTRIBUTES_INIT(&ObjAttributes); - ObjAttributes.ParentObject = _Device; - - // Reuse the data buffer coming from upper layer; UART's HCI packet starts with + ObjAttributes.ParentObject = _Device; + + // Reuse the data buffer coming from upper layer; UART's HCI packet starts with // packet type, and then follows by the actual HCI packet. Data = (PVOID) &_HCIContext->Type; DataLength = (ULONG) sizeof(_HCIContext->Type) + _HCIContext->DataLen; _Analysis_assume_(DataLength > 0); - Status = WdfMemoryCreatePreallocated(&ObjAttributes, - Data, - DataLength, + Status = WdfMemoryCreatePreallocated(&ObjAttributes, + Data, + DataLength, &TransferContext->Memory); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfMemoryCreatePreallocated failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfMemoryCreatePreallocated failed %!STATUS!", Status)); goto Done; } - + Status = WdfIoTargetFormatRequestForWrite(_FdoExtension->IoTargetSerial, RequestToUART, - TransferContext->Memory, - NULL, - NULL); + TransferContext->Memory, + NULL, + NULL); if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfIoTargetFormatRequestForRead failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfIoTargetFormatRequestForRead failed %!STATUS!", Status)); goto Done; } - + // Setup transfer context - TransferContext->FdoExtension = _FdoExtension; - TransferContext->HCIContext = _HCIContext; + TransferContext->FdoExtension = _FdoExtension; + TransferContext->HCIContext = _HCIContext; TransferContext->RequestFromBthport = _RequestFromBthport; TransferContext->RequestCompletePath = REQUEST_PATH_NONE; TransferContext->RequestToUART = RequestToUART; TransferContext->HCIPacket = Data; - TransferContext->HCIPacketLen = DataLength; + TransferContext->HCIPacketLen = DataLength; // - // Both Requests are typically accessed by the completion routine, and in rare case also - // by the cancellation callback. Take a reference on them to ensure they stays valid in both cases. + // Both Requests are typically accessed by the completion routine, and in rare case also + // by the cancellation callback. Take a reference on them to ensure they stays valid in both cases. // WdfObjectReference(RequestToUART); - WdfObjectReference(_RequestFromBthport); - + WdfObjectReference(_RequestFromBthport); // Mark cancellable of the Request in our possession from upper layer // Cannot mark the request that we will forward to lower driver cancellable. - // Only if the Request from upper layer is cancelled, we will then cancel the - // Request that is sent to lower driver. - WdfRequestMarkCancelable(_RequestFromBthport, CB_RequestFromBthportCancel); - + // Only if the Request from upper layer is cancelled, we will then cancel the + // Request that is sent to lower driver. + WdfRequestMarkCancelable(_RequestFromBthport, CB_RequestFromBthportCancel); + WdfRequestSetCompletionRoutine(RequestToUART, CR_WriteDeviceIO, TransferContext); - // This request will be delivered to its IoTarget asynchronously (the default option). It should return + // This request will be delivered to its IoTarget asynchronously (the default option). It should return // STATUS_PENDING unless there is an error in its delivery to its IoTarget. After it has been delivered // successfully, its completion function will be called for any outcome - success, failure, or cancellation. if (!WdfRequestSend(RequestToUART, _FdoExtension->IoTargetSerial, WDF_NO_SEND_OPTIONS)) { NTSTATUS StatusTemp; - + // Get failure status, and this request will be completed by its caller of this function with this status. Status = WdfRequestGetStatus(RequestToUART); @@ -1723,12 +1703,12 @@ Return Value: StatusTemp = WdfRequestUnmarkCancelable(_RequestFromBthport); // Balance the reference count for both Requests due to failure. - WdfObjectDereference(RequestToUART); - WdfObjectDereference(_RequestFromBthport); - + WdfObjectDereference(RequestToUART); + WdfObjectDereference(_RequestFromBthport); + DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfRequestSend failed %!STATUS! and UnmarkCancelable %!STATUS!", Status, StatusTemp)); goto Done; - } + } else { // Request has been delivered to UART driver asychronously. It will be completed in its completion function @@ -1747,13 +1727,12 @@ Done: return Status; } - NTSTATUS FdoWriteToDeviceSync( _In_ WDFIOTARGET _IoTargetSerial, _In_ WDFREQUEST _RequestWriteSync, _In_ ULONG _IoControlCode, - _In_opt_ ULONG _InBufferSize, + _In_opt_ ULONG _InBufferSize, _In_opt_ PVOID _InBuffer, _Out_ PULONG_PTR _BytesWritten ) @@ -1761,28 +1740,28 @@ FdoWriteToDeviceSync( Routine Description: This helper function send a synchronous write or Ioctl Request to device with - timeout (to prevent hang). - + timeout (to prevent hang). + Arguments: _IoTargetSerial - Serial port IO Target where to issue this request to _RequestWriteSync - caller allocated WDF Request - _IoControlCode - IOCTL control code; if 0, it is a Write request. + _IoControlCode - IOCTL control code; if 0, it is a Write request. _InBufferSize - Input buffer size _InBuffer - (optional) Input buffer - _BytesWritten - Bytes written to device; this is driver dependent; a write + _BytesWritten - Bytes written to device; this is driver dependent; a write could be successfully (and fully) written with 0 BytesWritten. - + Return Value: NTSTATUS - STATUS_SUCCESS or Status from issuing this request --*/ { - NTSTATUS Status = STATUS_SUCCESS; - WDF_REQUEST_REUSE_PARAMS RequestReuseParams; - WDF_REQUEST_SEND_OPTIONS Options; - WDF_MEMORY_DESCRIPTOR MemoryDescriptor; + NTSTATUS Status = STATUS_SUCCESS; + WDF_REQUEST_REUSE_PARAMS RequestReuseParams; + WDF_REQUEST_SEND_OPTIONS Options; + WDF_MEMORY_DESCRIPTOR MemoryDescriptor; ULONG_PTR BytesWritten = 0; BOOLEAN HasInputParam = FALSE; @@ -1790,14 +1769,13 @@ Return Value: DoTrace(LEVEL_INFO, TFLAG_IO,("+FdoWriteToDeviceSync")); - - WDF_REQUEST_REUSE_PARAMS_INIT(&RequestReuseParams, WDF_REQUEST_REUSE_NO_FLAGS, STATUS_SUCCESS); + WDF_REQUEST_REUSE_PARAMS_INIT(&RequestReuseParams, WDF_REQUEST_REUSE_NO_FLAGS, STATUS_SUCCESS); Status = WdfRequestReuse(_RequestWriteSync, &RequestReuseParams); if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfRequestReuse failed %!STATUS!", Status)); goto Done; - } + } if (_InBuffer && _InBufferSize) { HasInputParam = TRUE; @@ -1805,16 +1783,16 @@ Return Value: _InBuffer, _InBufferSize); } - - WDF_REQUEST_SEND_OPTIONS_INIT(&Options, WDF_REQUEST_SEND_OPTION_SYNCHRONOUS); + + WDF_REQUEST_SEND_OPTIONS_INIT(&Options, WDF_REQUEST_SEND_OPTION_SYNCHRONOUS); WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&Options, WDF_REL_TIMEOUT_IN_SEC(MAX_WRITE_TIMEOUT_IN_SEC)); if (_IoControlCode) { Status = WdfIoTargetSendIoctlSynchronously(_IoTargetSerial, - NULL, + NULL, _IoControlCode, - HasInputParam ? &MemoryDescriptor : NULL, // InputBuffer + HasInputParam ? &MemoryDescriptor : NULL, // InputBuffer NULL, // OutputBuffer &Options, // RequestOptions &BytesWritten // BytesReturned @@ -1823,14 +1801,14 @@ Return Value: else { Status = WdfIoTargetSendWriteSynchronously(_IoTargetSerial, - NULL, + NULL, HasInputParam ? &MemoryDescriptor : NULL, // InputBuffer NULL, // DeviceOffset &Options, // RequestOptions &BytesWritten // BytesReturned ); } - + DoTrace(LEVEL_INFO, TFLAG_IO,("-FdoWriteToDeviceSync: %d BytesWritten %!STATUS!", (ULONG) BytesWritten, Status)); if (NT_SUCCESS(Status)) @@ -1839,10 +1817,9 @@ Return Value: } Done: - return Status; + return Status; } - VOID FdoIoQuDeviceControl( _In_ WDFQUEUE _Queue, @@ -1856,7 +1833,7 @@ FdoIoQuDeviceControl( Routine Description: This routine is the dispatch routine for device control requests. - + Arguments: _Queue - Handle to the framework queue object that is associated @@ -1877,21 +1854,19 @@ Return Value: --*/ { - WDFMEMORY ReqInMemory = NULL, ReqOutMemory = NULL; + WDFMEMORY ReqInMemory = NULL, ReqOutMemory = NULL; PVOID InBuffer = NULL, OutBuffer = NULL; - size_t InBufferSize = 0, OutBufferSize = 0; + size_t InBufferSize = 0, OutBufferSize = 0; PFDO_EXTENSION FdoExtension; NTSTATUS Status = STATUS_SUCCESS; WDFDEVICE Device; BOOLEAN CompleteRequest = FALSE; ULONG ControlCode = (_IoControlCode & 0x00003ffc) >> 2; - KIRQL Irql; BTHX_HCI_PACKET_TYPE PacketType; PBTHX_HCI_READ_WRITE_CONTEXT HCIContext; - DoTrace(LEVEL_INFO, TFLAG_IOCTL,("+IoDeviceControl - InBufLen:%d, OutBufLen:%d", - (ULONG) _InputBufferLength, (ULONG) _OutputBufferLength)); + (ULONG) _InputBufferLength, (ULONG) _OutputBufferLength)); Device = WdfIoQueueGetDevice(_Queue); @@ -1899,46 +1874,46 @@ Return Value: if (_InputBufferLength) { - Status = WdfRequestRetrieveInputMemory(_Request, &ReqInMemory); - if (NT_SUCCESS(Status)) - { - InBuffer = WdfMemoryGetBuffer(ReqInMemory, &InBufferSize); + Status = WdfRequestRetrieveInputMemory(_Request, &ReqInMemory); + if (NT_SUCCESS(Status)) + { + InBuffer = WdfMemoryGetBuffer(ReqInMemory, &InBufferSize); } - } + } if (_OutputBufferLength) { - Status = WdfRequestRetrieveOutputMemory(_Request, &ReqOutMemory); - if (NT_SUCCESS(Status)) - { - OutBuffer = WdfMemoryGetBuffer(ReqOutMemory, &OutBufferSize); - } - } + Status = WdfRequestRetrieveOutputMemory(_Request, &ReqOutMemory); + if (NT_SUCCESS(Status)) + { + OutBuffer = WdfMemoryGetBuffer(ReqOutMemory, &OutBufferSize); + } + } - switch (_IoControlCode) - { - case IOCTL_BTHX_WRITE_HCI: + switch (_IoControlCode) + { + case IOCTL_BTHX_WRITE_HCI: DoTrace(LEVEL_INFO, TFLAG_IOCTL,(" IOCTL_BTHX_WRITE_HCI ---------->")); // Validate input and output parameters if (!InBuffer || InBufferSize < sizeof(BTHX_HCI_READ_WRITE_CONTEXT) || - !OutBuffer || OutBufferSize != sizeof(BTHX_HCI_PACKET_TYPE)) + !OutBuffer || OutBufferSize != sizeof(BTHX_HCI_PACKET_TYPE)) { Status = STATUS_INVALID_PARAMETER; DoTrace(LEVEL_ERROR, TFLAG_IOCTL,(" IOCTL_BTHX_WRITE_HCI %!STATUS!", Status)); - break; + break; } - + HCIContext = (PBTHX_HCI_READ_WRITE_CONTEXT) InBuffer; - PacketType = (BTHX_HCI_PACKET_TYPE) HCIContext->Type; - + PacketType = (BTHX_HCI_PACKET_TYPE) HCIContext->Type; + if (!BTHX_VALID_WRITE_PACKET_TYPE(PacketType)) { Status = STATUS_INVALID_PARAMETER; - DoTrace(LEVEL_ERROR, TFLAG_IOCTL,(" Mismach Write HCI packet type and IOCTL %!STATUS!", Status)); - break; - } - + DoTrace(LEVEL_ERROR, TFLAG_IOCTL,(" Mismach Write HCI packet type and IOCTL %!STATUS!", Status)); + break; + } + if (PacketType == HciPacketCommand) { InterlockedIncrement(&FdoExtension->CntCommandReq); @@ -1947,176 +1922,176 @@ Return Value: { InterlockedIncrement(&FdoExtension->CntWriteDataReq); } - + Status = FdoWriteDeviceIO(_Request, Device, FdoExtension, - HCIContext); + HCIContext); break; - + case IOCTL_BTHX_READ_HCI: - DoTrace(LEVEL_INFO, TFLAG_IOCTL,(" IOCTL_BTHX_READ_HCI <----------")); - // Validate input and output parameters + DoTrace(LEVEL_INFO, TFLAG_IOCTL,(" IOCTL_BTHX_READ_HCI <----------")); + // Validate input and output parameters if (!InBuffer || InBufferSize != sizeof(BTHX_HCI_PACKET_TYPE) || !OutBuffer || OutBufferSize < sizeof(BTHX_HCI_READ_WRITE_CONTEXT)) - { + { Status = STATUS_INVALID_PARAMETER; DoTrace(LEVEL_ERROR, TFLAG_IOCTL,(" IOCTL_BTHX_READ_HCI %!STATUS!", Status)); - break; - } + break; + } + + PacketType = *((BTHX_HCI_PACKET_TYPE *) InBuffer); - PacketType = *((BTHX_HCI_PACKET_TYPE *) InBuffer); - if (!BTHX_VALID_READ_PACKET_TYPE(PacketType)) { Status = STATUS_INVALID_PARAMETER; DoTrace(LEVEL_ERROR, TFLAG_IOCTL,(" IOCTL_BTHX_READ_HCI %!STATUS!", Status)); - break; + break; } if (PacketType == HciPacketEvent) { - KeAcquireSpinLock(&FdoExtension->QueueAccessLock, &Irql); + WdfSpinLockAcquire(FdoExtension->QueueAccessLock); // Queue the new request to preserve sequential order - Status = WdfRequestForwardToIoQueue(_Request, FdoExtension->ReadEventQueue); + Status = WdfRequestForwardToIoQueue(_Request, FdoExtension->ReadEventQueue); if (NT_SUCCESS(Status)) { InterlockedIncrement(&FdoExtension->EventQueueCount); - InterlockedIncrement(&FdoExtension->CntEventReq); + InterlockedIncrement(&FdoExtension->CntEventReq); } - KeReleaseSpinLock(&FdoExtension->QueueAccessLock, Irql); + WdfSpinLockRelease(FdoExtension->QueueAccessLock); if (NT_SUCCESS(Status)) { - Status = ReadRequestComplete(FdoExtension, + Status = ReadRequestComplete(FdoExtension, HciPacketEvent, 0, NULL, FdoExtension->ReadEventQueue, &FdoExtension->EventQueueCount, &FdoExtension->ReadEventList, - &FdoExtension->EventListCount); - } + &FdoExtension->EventListCount); + } } else if (PacketType == HciPacketAclData) - { - KeAcquireSpinLock(&FdoExtension->QueueAccessLock, &Irql); + { + WdfSpinLockAcquire(FdoExtension->QueueAccessLock); // Queue the new request to preserve sequential order - Status = WdfRequestForwardToIoQueue(_Request, FdoExtension->ReadDataQueue); + Status = WdfRequestForwardToIoQueue(_Request, FdoExtension->ReadDataQueue); if (NT_SUCCESS(Status)) - { + { InterlockedIncrement(&FdoExtension->DataQueueCount); InterlockedIncrement(&FdoExtension->CntReadDataReq); } - KeReleaseSpinLock(&FdoExtension->QueueAccessLock, Irql); + WdfSpinLockRelease(FdoExtension->QueueAccessLock); if (NT_SUCCESS(Status)) - { - Status = ReadRequestComplete(FdoExtension, + { + Status = ReadRequestComplete(FdoExtension, HciPacketAclData, 0, NULL, FdoExtension->ReadDataQueue, &FdoExtension->DataQueueCount, &FdoExtension->ReadDataList, - &FdoExtension->DataListCount); - } + &FdoExtension->DataListCount); + } } else { Status = STATUS_INVALID_PARAMETER; DoTrace(LEVEL_ERROR, TFLAG_IOCTL,(" IOCTL_BTHX_READ_HCI %!STATUS!", Status)); - break; + break; } - break; + break; - case IOCTL_BTHX_GET_VERSION: - CompleteRequest = TRUE; + case IOCTL_BTHX_GET_VERSION: + CompleteRequest = TRUE; DoTrace(LEVEL_INFO, TFLAG_IOCTL,("IOCTL_BTHX_GET_VERSION")); - + if (OutBuffer && OutBufferSize >= sizeof(BTHX_VERSION)) { RtlCopyMemory(OutBuffer, &Microsoft_BTHX_DDI_Version, sizeof(BTHX_VERSION)); WdfRequestCompleteWithInformation(_Request, Status, sizeof(BTHX_VERSION)); return; - } + } else { Status = STATUS_INVALID_PARAMETER; } - break; + break; + + case IOCTL_BTHX_SET_VERSION: + CompleteRequest = TRUE; + DoTrace(LEVEL_INFO, TFLAG_IOCTL,("IOCTL_BTHX_SET_VERSION")); - case IOCTL_BTHX_SET_VERSION: - CompleteRequest = TRUE; - DoTrace(LEVEL_INFO, TFLAG_IOCTL,("IOCTL_BTHX_SET_VERSION")); - if (InBuffer && InBufferSize >= sizeof(BTHX_VERSION)) { BTHX_VERSION SupportedVersion = *((BTHX_VERSION *)InBuffer); DoTrace(LEVEL_INFO, TFLAG_IOCTL,("IOCTL_BTHX_SET_VERSION 0x%x", SupportedVersion.Version)); - + WdfRequestComplete(_Request, Status); return; - } + } else { Status = STATUS_INVALID_PARAMETER; } - break; + break; case IOCTL_BTHX_QUERY_CAPABILITIES: - CompleteRequest = TRUE; + CompleteRequest = TRUE; DoTrace(LEVEL_INFO, TFLAG_IOCTL,("IOCTL_BTHX_QUERY_CAPABILITIES")); - + if (OutBuffer && OutBufferSize >= sizeof(BTHX_CAPABILITIES)) { BTHX_CAPABILITIES *pCaps = (BTHX_CAPABILITIES *) OutBuffer; - RtlCopyMemory(pCaps, &FdoExtension->BthXCaps, sizeof(BTHX_CAPABILITIES)); + RtlCopyMemory(pCaps, &FdoExtension->BthXCaps, sizeof(BTHX_CAPABILITIES)); WdfRequestCompleteWithInformation(_Request, Status, sizeof(BTHX_CAPABILITIES)); - return; + return; } else { Status = STATUS_INVALID_PARAMETER; - } - break; + } + break; // // This IOCTL is used to support radio on/off feature by doing the following - // 1. Power up/down the Bluetooth radio function, and + // 1. Power up/down the Bluetooth radio function, and // 2. Add/remove a PDO for Bluetooth devnode; // case IOCTL_BUSENUM_SET_RADIO_ONOFF_VENDOR_SPECFIC: - CompleteRequest = TRUE; - DoTrace(LEVEL_INFO, TFLAG_IOCTL,("IOCTL_BUSENUM_SET_RADIO_ONOFF_VENDOR_SPECFIC")); + CompleteRequest = TRUE; + DoTrace(LEVEL_INFO, TFLAG_IOCTL,("IOCTL_BUSENUM_SET_RADIO_ONOFF_VENDOR_SPECFIC")); if (InBuffer && InBufferSize >= sizeof(BOOLEAN)) { BOOLEAN IsRadioEnabled = *((BOOLEAN *) InBuffer); - if (IsRadioEnabled) { + if (IsRadioEnabled) { if (!FdoExtension->IsRadioEnabled) { - + // - // 1. Power up the Bluetooth function of this device; + // 1. Power up the Bluetooth function of this device; // - Status = DevicePowerOn(Device); + Status = DevicePowerOn(Device); if (NT_SUCCESS(Status)) { - + // - // 2. Create a PDO for the Bluetooth devnode; + // 2. Create a PDO for the Bluetooth devnode; // Status = FdoCreateOneChildDevice(Device, BT_PDO_HARDWARE_IDS, - BLUETOOTH_FUNC_IDS); + BLUETOOTH_FUNC_IDS); if (NT_SUCCESS(Status)) { FdoExtension->IsRadioEnabled = TRUE; - } + } } - DoTrace(LEVEL_INFO, TFLAG_IOCTL,(" EnableRadio %!STATUS!", Status)); + DoTrace(LEVEL_INFO, TFLAG_IOCTL,(" EnableRadio %!STATUS!", Status)); } else { - Status = STATUS_SUCCESS; + Status = STATUS_SUCCESS; DoTrace(LEVEL_WARNING, TFLAG_IOCTL,(" Already enabled!")); } } @@ -2125,41 +2100,41 @@ Return Value: // // 1. Remove the PDO for the Bluetooth devnode; - // + // Status = FdoRemoveOneChildDevice(Device, BLUETOOTH_FUNC_IDS); if (NT_SUCCESS(Status)) { - FdoExtension->IsRadioEnabled = FALSE; - + FdoExtension->IsRadioEnabled = FALSE; + // - // 2. Power down the Bluetooth function (at least the antenna) of this device; - // - Status = DevicePowerOff(Device); + // 2. Power down the Bluetooth function (at least the antenna) of this device; + // + Status = DevicePowerOff(Device); } - + DoTrace(LEVEL_INFO, TFLAG_IOCTL,(" DisableRadio %!STATUS!", Status)); } - else { - Status = STATUS_SUCCESS; - DoTrace(LEVEL_WARNING, TFLAG_IOCTL,(" Already disabled!")); + else { + Status = STATUS_SUCCESS; + DoTrace(LEVEL_WARNING, TFLAG_IOCTL,(" Already disabled!")); } - } + } } else { Status = STATUS_INVALID_PARAMETER; - } - break; - + } + break; + default: DoTrace(LEVEL_INFO, TFLAG_IOCTL,(" IOCTL_(0x%x, Func %d)", _IoControlCode, ControlCode)); - Status = STATUS_NOT_SUPPORTED; - break; + Status = STATUS_NOT_SUPPORTED; + break; } - - if (!NT_SUCCESS(Status) || CompleteRequest) + + if (!NT_SUCCESS(Status) || CompleteRequest) { WdfRequestComplete(_Request, Status); - } + } return; } diff --git a/bluetooth/serialhcibus/WDK/SerialBusWdk.inx b/bluetooth/serialhcibus/WDK/SerialBusWdk.inx index b6e81096..5ba76403 100644 --- a/bluetooth/serialhcibus/WDK/SerialBusWdk.inx +++ b/bluetooth/serialhcibus/WDK/SerialBusWdk.inx @@ -20,7 +20,7 @@ Signature="$WINDOWS NT$" Class=System ClassGuid={4D36E97D-E325-11CE-BFC1-08002BE10318} -Provider=%MSFTSAMPLE% +Provider=%ProviderString% DriverVer=06/21/2006,6.2.7923.0 CatalogFile=SerialBusWdk.cat @@ -81,7 +81,7 @@ ServiceBinary = %12%\SerialBusWdk.sys SPSVCINST_ASSOCSERVICE= 0x00000002 ;Localizable -MSFTSAMPLE = "Microsoft Sample" +ProviderString = "TODO-Set-Provider" StdMfg = "(Standard system devices)" DiskId1 = "Serial Bus Driver over UART Installation Disk #1" Bus.DeviceDesc = "Serial Bus Driver over UART Bus Enumerator" diff --git a/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj b/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj index 1b1088b1..79bbcc83 100644 --- a/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj +++ b/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj @@ -19,12 +19,12 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}</ProjectGuid> + <ProjectGuid>{6844B626-ABF4-4F07-BD90-7AA8A8A87E12}</ProjectGuid> <RootNamespace>$(MSBuildProjectName)</RootNamespace> <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{B81CFC73-D7CD-484D-B134-1D6AC0106514}</SampleGuid> + <SampleGuid>{F1C3593E-8279-482B-8D67-8319913E265E}</SampleGuid> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -196,7 +196,6 @@ <ItemGroup> <Inf Exclude="@(Inf)" Include="*.inf" /> <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> diff --git a/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj.Filters b/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj.Filters index 90e9b2a7..7d476dc7 100644 --- a/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj.Filters +++ b/bluetooth/serialhcibus/WDK/SerialBusWdk.vcxproj.Filters @@ -3,19 +3,19 @@ <ItemGroup> <Filter Include="Source Files"> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{201450EB-D675-4E41-BAAC-8BF2E93F8BA4}</UniqueIdentifier> + <UniqueIdentifier>{413E2A31-6D3D-48D5-B3C7-73714F810CAF}</UniqueIdentifier> </Filter> <Filter Include="Header Files"> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{28214B85-07EC-4DAA-9EE8-7ECB4867524B}</UniqueIdentifier> + <UniqueIdentifier>{1494E901-78AF-4262-8B85-C70B93AA8465}</UniqueIdentifier> </Filter> <Filter Include="Resource Files"> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{CCE43425-7067-4FF7-A1FA-B55E892E4CF6}</UniqueIdentifier> + <UniqueIdentifier>{38B6E2D0-6448-48E5-B1F7-BD648B4C0112}</UniqueIdentifier> </Filter> <Filter Include="Driver Files"> <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{678E1E03-C75C-4BFD-A872-84A5F2191188}</UniqueIdentifier> + <UniqueIdentifier>{62F3F5F6-E755-4AFE-9C33-C1E065E5BAF1}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> @@ -36,9 +36,6 @@ </ClCompile> </ItemGroup> <ItemGroup> - <FilesToPackage Include=".\Debug\\SerialBusWdk.inf"> - <Filter>Driver Files</Filter> - </FilesToPackage> <Inf Include=".\SerialBusWdk.inx"> <Filter>Driver Files</Filter> </Inf> diff --git a/bluetooth/serialhcibus/driver.h b/bluetooth/serialhcibus/driver.h index d82f1f55..4d9decca 100644 --- a/bluetooth/serialhcibus/driver.h +++ b/bluetooth/serialhcibus/driver.h @@ -8,7 +8,7 @@ Module Name: Abstract: - This module contains the common private declarations for + This module contains the common private declarations for for the Serial HCI bus driver. Environment: @@ -32,7 +32,7 @@ Environment: #include <BthXDDI.h> // BT Extensible Transport DDI -#include "device.h" // Device specific +#include "device.h" // Device specific #include "io.h" // Read pump #include "debugdef.h" // WPP trace #include "public.h" // Share between driver and application @@ -47,7 +47,7 @@ DEFINE_GUID(GUID_CONTAINERID_INTERNALLY_CONNECTED_DEVICE, //{00000000-0000-0000-ffff-ffffffffffff} -#endif // #ifdef DEFINE_GUID +#endif // #ifdef DEFINE_GUID // // Define HCI event code @@ -71,7 +71,6 @@ DEFINE_GUID(GUID_CONTAINERID_INTERNALLY_CONNECTED_DEVICE, #define BLUETOOTH_FUNC_IDS 0x1001 - // // Device's idle state capability // @@ -81,7 +80,6 @@ typedef enum _IDLE_CAP_STATE { IdleCapCanTurnOff = 3 // Can enter D3 (off) and not remote wake to save max power while device is off. } IDLE_CAP_STATE; - #ifdef DYNAMIC_ENUM // // The goal of the identification and address description abstractions is that enough @@ -123,15 +121,13 @@ typedef struct _PDO_IDENTIFICATION_DESCRIPTION } PDO_IDENTIFICATION_DESCRIPTION, *PPDO_IDENTIFICATION_DESCRIPTION; #endif // #ifdef DYNAMIC_ENUM - typedef struct _UART_READ_CONTEXT *PUART_READ_CONTEXT; // -// Bus driver's FDO (Function Device Object) extension structure used to maintain device +// Bus driver's FDO (Function Device Object) extension structure used to maintain device // properties and state. // - typedef struct _FDO_EXTENSION { WDFWAITLOCK ChildLock; @@ -149,20 +145,20 @@ typedef struct _FDO_EXTENSION // // Serial port IO Target where we send IOCTL/READ/WRITE reuquest to // - WDFIOTARGET IoTargetSerial; + WDFIOTARGET IoTargetSerial; // - // (optional) GPIO IO Target to enable serial bus device + // (optional) GPIO IO Target to enable serial bus device // - WDFIOTARGET IoTargetGPIO; + WDFIOTARGET IoTargetGPIO; // // Bluetooth child dev node (PDO) capabilities // - BTHX_CAPABILITIES BthXCaps; + BTHX_CAPABILITIES BthXCaps; // - // Indicator if UART is properly initialize; may require re-inialization + // Indicator if UART is properly initialize; may require re-inialization // when tranistion from exiting D0 to resume D0. // BOOLEAN DeviceInitialized; @@ -176,10 +172,10 @@ typedef struct _FDO_EXTENSION // Cached I2C controller connection IDs // LARGE_INTEGER I2CConnectionId; - + // // Cached GPIO controller connection IDs - // + // LARGE_INTEGER GPIOConnectionId; // @@ -190,7 +186,7 @@ typedef struct _FDO_EXTENSION // // Preallocate WDF Requests to wait on serial error event // - WDFREQUEST RequestWaitOnError; + WDFREQUEST RequestWaitOnError; // // Data return from serial event wait mask IOCTL @@ -200,42 +196,42 @@ typedef struct _FDO_EXTENSION // // WDM memory use for Wait Mask event // - WDFMEMORY WaitMaskMemory; + WDFMEMORY WaitMaskMemory; // // Set if a hardware error (e.g. data overrun in UART FIFO) is detected // BOOLEAN HardwareErrorDetected; - + // // Indication the state of the read pump (TRUE = active) // - BOOLEAN ReadPumpRunning; + BOOLEAN ReadPumpRunning; // - // Track number of out-of-sync error that has been detected + // Track number of out-of-sync error that has been detected // ULONG OutOfSyncErrorCount; // // Locks for synchronization for list and queue // - KSPIN_LOCK QueueAccessLock; - + WDFSPINLOCK QueueAccessLock; + // // Track next packet read (one and only one) // - UART_READ_CONTEXT ReadContext; + UART_READ_CONTEXT ReadContext; - // - // Preallocated local WDF requested and memory object that is reused to + // + // Preallocated local WDF requested and memory object that is reused to // implement read pump // - WDFREQUEST ReadRequest; - WDFMEMORY ReadMemory; - UCHAR ReadBuffer[MAX_H4_HCI_PACKET_SIZE]; + WDFREQUEST ReadRequest; + WDFMEMORY ReadMemory; + UCHAR ReadBuffer[MAX_H4_HCI_PACKET_SIZE]; -#if DBG +#if DBG // // Track last completed HCI packet // @@ -245,57 +241,52 @@ typedef struct _FDO_EXTENSION // // WDF Queue for HCI event Request and total number of such request recevied // - WDFQUEUE ReadEventQueue; - LONG EventQueueCount; + WDFQUEUE ReadEventQueue; + LONG EventQueueCount; // // List to store (prefetched) incoming HCI events and number of entries // - LIST_ENTRY ReadEventList; - LONG EventListCount; - + LIST_ENTRY ReadEventList; + LONG EventListCount; // // WDF Queue for HCI read data Request and total number of such request recevied // - WDFQUEUE ReadDataQueue; - LONG DataQueueCount; + WDFQUEUE ReadDataQueue; + LONG DataQueueCount; // // List to store (prefetched) incoming HCI data and number of entries - // - LIST_ENTRY ReadDataList; - LONG DataListCount; + // + LIST_ENTRY ReadDataList; + LONG DataListCount; - // - // Counts used to track HCI requests received and completed for various packet types - // - LONG CntCommandReq; // Track total number of HCI command Requests - LONG CntCommandCompleted; // Number of HCI Command completed + // Counts used to track HCI requests received and completed for various packet types + // + LONG CntCommandReq; // Track total number of HCI command Requests + LONG CntCommandCompleted; // Number of HCI Command completed - LONG CntEventReq; // Track total number of HCI Event Requests - LONG CntEventCompleted; // Number of HCI Command completed + LONG CntEventReq; // Track total number of HCI Event Requests + LONG CntEventCompleted; // Number of HCI Command completed - LONG CntWriteDataReq; // Track total number of HCI Write Data requests - LONG CntWriteDataCompleted; // Number of HCI (write) Data completed + LONG CntWriteDataReq; // Track total number of HCI Write Data requests + LONG CntWriteDataCompleted; // Number of HCI (write) Data completed - LONG CntReadDataReq; // Track total number of HCI Read Data Requests - LONG CntReadDataCompleted; // Number of HCI (Read) Data completed + LONG CntReadDataReq; // Track total number of HCI Read Data Requests + LONG CntReadDataCompleted; // Number of HCI (Read) Data completed } FDO_EXTENSION, *PFDO_EXTENSION; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_EXTENSION, FdoGetExtension) - // // Can send IO only if the device (UART) is in the initialized state. // #define IsDeviceInitialized(FdoExtension) (FdoExtension->DeviceInitialized) - #define ValidConnectionID(ConnectionId) (ConnectionId.QuadPart != 0) - // // Bus driver's child PDO (Physical Device Object) extension structure used to maintain this // PDO's device properties and state. @@ -317,12 +308,10 @@ typedef struct _PDO_EXTENSION WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(PDO_EXTENSION, PdoGetExtension) - // // Prototypes of functions // - // // Driver.c // @@ -338,7 +327,6 @@ EVT_WDF_DRIVER_DEVICE_ADD DriverDeviceAdd; DRIVER_INITIALIZE DriverEntry; - // // FDO.c // @@ -357,7 +345,7 @@ FdoWriteToDeviceSync(_In_ WDFIOTARGET _IoTargetSerial, _In_ WDFREQUEST _RequestWriteSync, _In_ ULONG _IoControlCode, _In_opt_ ULONG _InBufferSize, - _In_opt_ PVOID _InBuffer, + _In_opt_ PVOID _InBuffer, _Out_ PULONG_PTR _BytesWritten); NTSTATUS @@ -367,12 +355,10 @@ DeviceConfigWaitOnError(_In_ WDFIOTARGET _IoTargetSerial, _In_ PULONG _ErrorResult, _In_ PFDO_EXTENSION _FdoExtension); - NTSTATUS HCIContextValidate(ULONG Index, PBTHX_HCI_READ_WRITE_CONTEXT _HCIContext); - // Power policy events EVT_WDF_DEVICE_ARM_WAKE_FROM_S0 FdoEvtDeviceArmWake; EVT_WDF_DEVICE_DISARM_WAKE_FROM_S0 FdoEvtDeviceDisarmWake; @@ -432,7 +418,6 @@ FdoFindConnectResources(_In_ WDFDEVICE _Device, _In_ WDFCMRESLIST _ResourcesRaw, _In_ WDFCMRESLIST _ResourcesTranslated); - // // Pdo.c // @@ -468,7 +453,7 @@ HLP_AllocateResourceForWrite(_In_ WDFDEVICE _Device, _In_ WDFIOTARGET _IoTargetSerial, _Out_ WDFREQUEST *_pRequest); -VOID +VOID HLP_FreeResourceForWrite(PUART_WRITE_CONTEXT _TransferContext); EVT_WDF_REQUEST_CANCEL CB_RequestFromBthportCancel; @@ -479,9 +464,9 @@ NTSTATUS ReadRequestComplete(_In_ PFDO_EXTENSION _FdoExtension, _In_ UCHAR _Type, _In_ ULONG _PacketLength, - _In_reads_bytes_opt_(_PacketLength) PUCHAR _Packet, + _In_reads_bytes_opt_(_PacketLength) PUCHAR _Packet, _Inout_ WDFQUEUE _Queue, - _Inout_ PLONG _QueueCount, + _Inout_ PLONG _QueueCount, _Inout_ PLIST_ENTRY _ListHead, _Inout_ PLONG _ListCount); @@ -494,7 +479,6 @@ ReadH4Packet(_In_ PUART_READ_CONTEXT _ReadContext, _Pre_notnull_ _Pre_writable_byte_size_(_BufferLen) PVOID _Buffer, _In_ ULONG _BufferLen); - // // Device.c // @@ -518,13 +502,12 @@ NTSTATUS DeviceEnable(_In_ WDFDEVICE _Device, _In_ BOOLEAN _Enabled); -NTSTATUS +NTSTATUS DevicePowerOn(_In_ WDFDEVICE _Device); -NTSTATUS +NTSTATUS DevicePowerOff(_In_ WDFDEVICE _Device); #endif - diff --git a/bluetooth/serialhcibus/io.c b/bluetooth/serialhcibus/io.c index 0b4d64ac..c0a77142 100644 --- a/bluetooth/serialhcibus/io.c +++ b/bluetooth/serialhcibus/io.c @@ -14,7 +14,7 @@ Environment: Kernel mode only -Revision History: +Revision History: --*/ @@ -34,23 +34,23 @@ CB_RequestFromBthportCancel( Routine Description: - Request from upper layer that driver owns is being canceled. Its associated + Request from upper layer that driver owns is being canceled. Its associated Request to lower (UART) driver will be canceled and then this Request will - be completed with STATUS_CANCELLED. + be completed with STATUS_CANCELLED. There are different paths for the Request from upper layer: - + 1. Completion routine is invoked without cancellation (typical path) - 2. Cancellation routine is invoked while lower Request is pending. The lower + 2. Cancellation routine is invoked while lower Request is pending. The lower request could be completed either - a. Synchronously - completion routine is invoked before + a. Synchronously - completion routine is invoked before WdfRequestCancelSentRequest() is returned in the cancellation routine; or - b. Asynchronously - completion routine is invoked at later time after + b. Asynchronously - completion routine is invoked at later time after WdfRequestCancelSentRequest has returned. 3. Race conditions when both the cancelation and completion routine have independently started a. Cancellation routine is ahead and the request is completed with cancellation status. b. Completion routine is ahead and the request is completed with the status from the lower request. - + Arguments: _RequestFromUpper - WDF Request to be cancelled @@ -59,24 +59,22 @@ Return Value: none ---*/ -{ +--*/ +{ PUART_WRITE_CONTEXT TransferContext; WDFREQUEST RequestToUART; - WDFMEMORY Memory; + WDFMEMORY Memory; BOOLEAN CancelSuccess; LONG CompletePath = REQUEST_PATH_NONE; - DoTrace(LEVEL_WARNING, TFLAG_IO, ("+CB_RequestFromBthportCancel: Request(%p) from upper driver", _RequestFromUpper)); TransferContext = GetWriteRequestContext(_RequestFromUpper); NT_ASSERT(TransferContext && L"TransferContext is not valid!"); - - // Cancel the write Request that was previously submitted to its I/O target - RequestToUART = TransferContext->RequestToUART; - Memory = TransferContext->Memory; + // Cancel the write Request that was previously submitted to its I/O target + RequestToUART = TransferContext->RequestToUART; + Memory = TransferContext->Memory; // // The below operation can return one of the following values. @@ -97,23 +95,22 @@ Return Value: if (REQUEST_PATH_NONE == CompletePath) { - DoTrace(LEVEL_WARNING, TFLAG_IO, (" >CancelSentRequest(%p) to IO Target", RequestToUART)); + DoTrace(LEVEL_WARNING, TFLAG_IO, (" >CancelSentRequest(%p) to IO Target", RequestToUART)); CancelSuccess = WdfRequestCancelSentRequest(RequestToUART); DoTrace(LEVEL_WARNING, TFLAG_IO, (" <CancelSentRequest: %S", CancelSuccess ? L"Cancelled" : L"Failed")); // Done sending the cancel. It can be dereferenced. WdfObjectDereference(RequestToUART); - // No need to access this memory object in the cancellation code path in the completion function. + // No need to access this memory object in the cancellation code path in the completion function. WdfObjectDelete(Memory); // Cannot access this request, including WdfRequestUnmarkCancelable(), after it has been completed. - WdfRequestComplete(_RequestFromUpper, STATUS_CANCELLED); + WdfRequestComplete(_RequestFromUpper, STATUS_CANCELLED); } } - NTSTATUS HLP_AllocateResourceForWrite( _In_ WDFDEVICE _Device, @@ -129,41 +126,40 @@ Routine Description: Arguments: _Device - WDF Device object - - _IoTargetSerial - WDF IO Target - + + _IoTargetSerial - WDF IO Target + _PRequest - WDF Request to allocate in this function Return Value: NTSTATUS - ---*/ + +--*/ { NTSTATUS Status; WDF_OBJECT_ATTRIBUTES ObjAttributes; - DoTrace(LEVEL_INFO, TFLAG_IO,("+HLP_AllocateResourceForWrite")); + DoTrace(LEVEL_INFO, TFLAG_IO,("+HLP_AllocateResourceForWrite")); // Create a WDF Request that will allocate a context(UART_WRITE_CONTEXT) WDF_OBJECT_ATTRIBUTES_INIT(&ObjAttributes); - ObjAttributes.ParentObject = _Device; - - Status = WdfRequestCreate(&ObjAttributes, - _IoTargetSerial, + ObjAttributes.ParentObject = _Device; + + Status = WdfRequestCreate(&ObjAttributes, + _IoTargetSerial, _PRequest); - - if (!NT_SUCCESS(Status)) + + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfRequestCreate() failed %!STATUS!", Status)); goto Done; - } - + } + Done: - - return Status; -} + return Status; +} VOID HLP_FreeResourceForWrite( @@ -182,29 +178,28 @@ Arguments: Return Value: none - ---*/ -{ - DoTrace(LEVEL_INFO, TFLAG_IO,("+HLP_FreeResourceForWrite")); - + +--*/ +{ + DoTrace(LEVEL_INFO, TFLAG_IO,("+HLP_FreeResourceForWrite")); + if (_TransferContext) - { + { if (_TransferContext->Memory) { WdfObjectDelete(_TransferContext->Memory); _TransferContext->Memory = NULL; - } - + } + if (_TransferContext->RequestToUART) { WdfObjectDelete(_TransferContext->RequestToUART); _TransferContext->RequestToUART = NULL; - + } } } - VOID CR_WriteDeviceIO( _In_ WDFREQUEST _Request, @@ -216,53 +211,53 @@ CR_WriteDeviceIO( Routine Description: - This is the completion function for sending HCI packet to the lower layer. - This function can also complete the request from the upper layer; see the + This is the completion function for sending HCI packet to the lower layer. + This function can also complete the request from the upper layer; see the description in the cancellation function for detail on the handling of possible race conditions. - A RequestCompletionPath flag in the write Context is used with atomic Interlocked function + A RequestCompletionPath flag in the write Context is used with atomic Interlocked function to ensure deterministic operation in both the cancellation and this completion functions. - If the cancellation function has been called, the WdfRequestUnmarkCancelable in the completion function will return STATUS_CANCELLED. - This return code is used to determine to handle the processing either as a typical completion, or as a cancellation and be in sync - with the cancellation function. - + If the cancellation function has been called, the WdfRequestUnmarkCancelable in the completion function will return STATUS_CANCELLED. + This return code is used to determine to handle the processing either as a typical completion, or as a cancellation and be in sync + with the cancellation function. + Here are what are performed in either situations: - + 1. Typical completion (completion function only) - WdfRequestUnmarkCancelable() returns not STATUS_CANCELLED Exercise its typical completion code path - Retrieve data transfer information for success case - - Dereference(RequestUART) - will not be accessed by cancellation function + - Dereference(RequestUART) - will not be accessed by cancellation function - Complete(RequestFromUpper) & Delete(its Memory Object) - + - Delete(RequestUART) - - Dereference(RequestFromUpper) - + - Dereference(RequestFromUpper) + 2. Cancellation (both functions) A: Cancellation Function WdfRequestCancelSentRequest(RequestToUART) to cancel RequestToUART - - Dereference(RequestToUART) after cancel is sent - - Complete(RequestFromUpper) & Delete(its Memory Object) - + - Dereference(RequestToUART) after cancel is sent + - Complete(RequestFromUpper) & Delete(its Memory Object) + B: Completion function WdfRequestUnmarkCancelable() returns STATUS_CANCELLED Exercise its cancellation code path - Delete(RequestToUART) - Dereference(RequestFromUpper) - + Note: Code path A & B have no synchronization object to ensure their order of execution, but reference is taken on the Requests to ensure that they stay valid until last access. - + RequestToUART - take a reference to protect against being used by the cancellation function; it is de-referenced by the - completion function - in its typical completion code path, or - cancellation function - after finishing accessing it (to sent cancel) - - RequestFromBthport - take a reference to protect against being completed by the cancellation function and then its context + + RequestFromBthport - take a reference to protect against being completed by the cancellation function and then its context is later accessed by the completion function; this can happen if the completion function is completed asynchronously after WdfRequestCancelSentRequest() is returned; it is de-referenced by the - - completion function - right before it exits. + - completion function - right before it exits. Arguments: @@ -270,30 +265,30 @@ Arguments: _Target - WDF IO Target _Params - Completion parameters _Context - Context used to process this request - + Return Value: none - + --*/ { NTSTATUS Status; - PUART_WRITE_CONTEXT TransferContext; + PUART_WRITE_CONTEXT TransferContext; PFDO_EXTENSION FdoExtension; WDFREQUEST RequestFromBthport; - ULONG BytesDataWritten = 0; - LONG CompletePath = REQUEST_PATH_NONE; + ULONG BytesDataWritten = 0; + LONG CompletePath = REQUEST_PATH_NONE; - UNREFERENCED_PARAMETER(_Target); + UNREFERENCED_PARAMETER(_Target); Status = _Params->IoStatus.Status; - TransferContext = (PUART_WRITE_CONTEXT) _Context; + TransferContext = (PUART_WRITE_CONTEXT) _Context; + + DoTrace(LEVEL_INFO, TFLAG_DATA,("+CR_WriteDeviceIO: %!STATUS!, Request %p, Context %p", + Status, _Request, _Context)); + + NT_ASSERT( (Status == STATUS_SUCCESS || Status == STATUS_CANCELLED) && L"WriteHCI request failed!"); - DoTrace(LEVEL_INFO, TFLAG_DATA,("+CR_WriteDeviceIO: %!STATUS!, Request %p, Context %p", - Status, _Request, _Context)); - - NT_ASSERT( (Status == STATUS_SUCCESS || Status == STATUS_CANCELLED) && L"WriteHCI request failed!"); - // // Request to be completed to upper layer. // @@ -314,12 +309,12 @@ Return Value: // This function does not have the control to complete the request from bthport. // CompletePath = InterlockedOr(&TransferContext->RequestCompletePath, REQUEST_PATH_COMPLETION); - + // Mark RequestFromBthPort not cancellable as it is about to be completed. if (REQUEST_PATH_NONE != CompletePath) { DoTrace(LEVEL_ERROR, TFLAG_IO,(" Request %p is in the process of being cancelled", RequestFromBthport)); - } + } else { // @@ -354,10 +349,10 @@ Return Value: } if (REQUEST_PATH_NONE == CompletePath) { - + // Dereference this request as cancellation function is not invoked to access it. WdfObjectDereference(_Request); - + // // Return data transfer information to caller for success Status // @@ -365,85 +360,84 @@ Return Value: { WDFMEMORY ReqOutMemory = NULL; ULONG BytesWritten; - PULONG OutBuffer = NULL; - size_t OutBufferSize = 0; + PULONG OutBuffer = NULL; + size_t OutBufferSize = 0; - BytesWritten = (ULONG) _Params->Parameters.Write.Length; + BytesWritten = (ULONG) _Params->Parameters.Write.Length; - DoTrace(LEVEL_INFO, TFLAG_DATA,(" Packet: Type %d, DataLen %d, BytesWritten %d", + DoTrace(LEVEL_INFO, TFLAG_DATA,(" Packet: Type %d, DataLen %d, BytesWritten %d", TransferContext->HCIContext->Type, TransferContext->HCIContext->DataLen, - BytesWritten)); + BytesWritten)); NT_ASSERT(BytesWritten == TransferContext->HCIPacketLen && "Unexpected incomplete HCI Write!"); - + if (BytesWritten != TransferContext->HCIPacketLen) { // return a generic failure for an incomplete transfer Status = STATUS_UNSUCCESSFUL; goto Done; } - + // // return data bytes written in the OutputParameter // - Status = WdfRequestRetrieveOutputMemory(RequestFromBthport, &ReqOutMemory); - if (NT_SUCCESS(Status)) - { + Status = WdfRequestRetrieveOutputMemory(RequestFromBthport, &ReqOutMemory); + if (NT_SUCCESS(Status)) + { OutBuffer = (PULONG) WdfMemoryGetBuffer(ReqOutMemory, &OutBufferSize); if (OutBufferSize >= sizeof(ULONG)) - { - // Set OutputParameter value and its size + { + // Set OutputParameter value and its size *OutBuffer = TransferContext->HCIContext->DataLen; - BytesDataWritten = sizeof(ULONG); + BytesDataWritten = sizeof(ULONG); } - } + } } - else + else { // Return the status as is. - } + } } } -Done: +Done: if (REQUEST_PATH_NONE == CompletePath) - { + { // Increment the completion count based on packet type. - FdoExtension = TransferContext->FdoExtension; - + FdoExtension = TransferContext->FdoExtension; + if (TransferContext->HCIContext->Type == (UCHAR) HciPacketCommand) { InterlockedIncrement(&FdoExtension->CntCommandCompleted); } else if (TransferContext->HCIContext->Type == (UCHAR) HciPacketAclData) { - InterlockedIncrement(&FdoExtension->CntWriteDataCompleted); - } + InterlockedIncrement(&FdoExtension->CntWriteDataCompleted); + } DoTrace(LEVEL_INFO, TFLAG_IO,(" WriteDeviceIO: Request %p complete with %!STATUS! and %d BytesDataWritten", - RequestFromBthport, Status, BytesDataWritten)); + RequestFromBthport, Status, BytesDataWritten)); // Delete this memory object that is no longer needed. - WdfObjectDelete(TransferContext->Memory); + WdfObjectDelete(TransferContext->Memory); + + // Cannot access this Request and its context after it is completed. + WdfRequestCompleteWithInformation(RequestFromBthport, Status, BytesDataWritten); - // Cannot access this Request and its context after it is completed. - WdfRequestCompleteWithInformation(RequestFromBthport, Status, BytesDataWritten); - } - - // Delete this request in its completion function. - WdfObjectDelete(_Request); + + // Delete this request in its completion function. + WdfObjectDelete(_Request); // Done accessing it in this function. This request is either completed in this function for the typical completion situation or in the cancellation function. WdfObjectDereference(RequestFromBthport); - DoTrace(LEVEL_INFO, TFLAG_IO,("-CR_WriteDeviceIO")); + DoTrace(LEVEL_INFO, TFLAG_IO,("-CR_WriteDeviceIO")); } - VOID ReadSegmentStateSet( PUART_READ_CONTEXT _ReadContext, @@ -453,52 +447,52 @@ ReadSegmentStateSet( Routine Description: - This helper centralize the setting of read state. It can be used to detect - possible incorrect state transition. + This helper centralize the setting of read state. It can be used to detect + possible incorrect state transition. Arguments: _ReadContext - read context which has existing state _NewState - new read state - + Return Value: none - ---*/ + +--*/ { UART_READ_STATE OldState = _ReadContext->ReadSegmentState; - + DoTrace(LEVEL_INFO, TFLAG_IO, ("+<<<< -- %s to %s state -- >>>>", OldState == GET_PKT_TYPE ? "Type" : - OldState == GET_PKT_HEADER ? "Header" : - OldState == GET_PKT_PAYLOAD ? "Payload" : "Unknown", + OldState == GET_PKT_HEADER ? "Header" : + OldState == GET_PKT_PAYLOAD ? "Payload" : "Unknown", _NewState == GET_PKT_TYPE ? "Type" : - _NewState == GET_PKT_HEADER ? "Header" : + _NewState == GET_PKT_HEADER ? "Header" : _NewState == GET_PKT_PAYLOAD ? "Payload" : "Unknown" )); // Validate the state transition switch (_NewState) { - case GET_PKT_TYPE: + case GET_PKT_TYPE: // Intialize the context for a new packet _ReadContext->BytesReadNextSegment = 0; _ReadContext->H4Packet.Type = 0; _ReadContext->BytesToRead4FullPacket = 0; RtlZeroMemory(_ReadContext->H4Packet.Packet.Raw, HCI_ACLDATA_HEADER_LEN); - break; + break; case GET_PKT_HEADER: case GET_PKT_PAYLOAD: // Reset segment count _ReadContext->BytesReadNextSegment = 0; - break; + break; } - + _ReadContext->ReadSegmentState = _NewState; } // Full packet: match to a Request and complete it. -NTSTATUS +NTSTATUS ReadH4PacketComplete( PFDO_EXTENSION _FdoExtension, UCHAR _Type, @@ -508,44 +502,43 @@ ReadH4PacketComplete( { NTSTATUS Status = STATUS_SUCCESS; - DoTrace(LEVEL_INFO, TFLAG_IO, ("+ReadH4PacketComplete %S Packet Length %d", - _Type == (UCHAR) HciPacketEvent ? L"Event" : L"AclData", _BufferLength )); + DoTrace(LEVEL_INFO, TFLAG_IO, ("+ReadH4PacketComplete %S Packet Length %d", + _Type == (UCHAR) HciPacketEvent ? L"Event" : L"AclData", _BufferLength )); #if DBG - // Tracking last completed packet + // Tracking last completed packet RtlCopyMemory(_FdoExtension->LastPacket, _Buffer, _BufferLength); _FdoExtension->LastPacketLength = _BufferLength; -#endif - +#endif + if (_Type == (UCHAR) HciPacketEvent) { - ReadRequestComplete(_FdoExtension, - HciPacketEvent, + ReadRequestComplete(_FdoExtension, + HciPacketEvent, _BufferLength, _Buffer, _FdoExtension->ReadEventQueue, &_FdoExtension->EventQueueCount, - &_FdoExtension->ReadEventList, - &_FdoExtension->EventListCount); + &_FdoExtension->ReadEventList, + &_FdoExtension->EventListCount); } - else + else { - ReadRequestComplete(_FdoExtension, + ReadRequestComplete(_FdoExtension, HciPacketAclData, _BufferLength, _Buffer, _FdoExtension->ReadDataQueue, &_FdoExtension->DataQueueCount, - &_FdoExtension->ReadDataList, - &_FdoExtension->DataListCount); - } + &_FdoExtension->ReadDataList, + &_FdoExtension->DataListCount); + } DoTrace(LEVEL_INFO, TFLAG_IO, ("-ReadH4PacketComplete %!STATUS!", Status)); - + return Status; } - NTSTATUS ReadH4PacketReassemble( _Inout_ PUART_READ_CONTEXT _ReadContext, @@ -556,45 +549,44 @@ ReadH4PacketReassemble( Routine Description: - A function enforce a state machine to process reading data to form a - complete HCI packet. + A function enforce a state machine to process reading data to form a + complete HCI packet. Arguments: _ReadContext - read context _BytesRead - bytes of data read and is in the output buffer _OutBuffer - Buffer that contain the data - + Return Value: NTSTATUS - ---*/ + +--*/ { - NTSTATUS Status = STATUS_SUCCESS; + NTSTATUS Status = STATUS_SUCCESS; ULONG BytesRemained = _BytesRead; PUCHAR Buffer = _Buffer; - PFDO_EXTENSION FdoExtension = _ReadContext->FdoExtension; + PFDO_EXTENSION FdoExtension = _ReadContext->FdoExtension; PH4_PACKET H4Packet; ULONG PacketLen; ULONG BytesToRead; - - - DoTrace(LEVEL_INFO, TFLAG_IO, ("+ReadH4PacketReassemble: %d _BytesRead, ReadSegmentState %d", - _BytesRead, _ReadContext->ReadSegmentState)); - // + DoTrace(LEVEL_INFO, TFLAG_IO, ("+ReadH4PacketReassemble: %d _BytesRead, ReadSegmentState %d", + _BytesRead, _ReadContext->ReadSegmentState)); + + // // By design, it will take two reads to complete an H4 packets. // // First Read (5 bytes = 1 + 4 = Type + Larger of (ACLDataHeader:4, EvetnHeader:2)) // - // - Event - // Complete (1 + 2 ), this is an Event packet without any param. + // - Event + // Complete (1 + 2 ), this is an Event packet without any param. // Complete (1 + 2 + 1), event with 1 param - // * These two outcome requires interval timeout to complete the read (ask for 5). + // * These two outcome requires interval timeout to complete the read (ask for 5). // Complete (1 + 2 + 2), event with 2 params // * if completed with one read, do the First read again. - // + // // Partial (1 + 2 + 2 + ParamCount-2), this will complete in next read // BytesToRead = ParamCount - 2 // @@ -603,210 +595,210 @@ Return Value: // ByteToRead = DataLength // Second read // - Event/AclData - // Complete (5 + BytesToRead) - // + // Complete (5 + BytesToRead) + // while (NT_SUCCESS(Status) && BytesRemained > 0) { - + // Process read buffer based on its read state switch (_ReadContext->ReadSegmentState) { - case GET_PKT_TYPE: + case GET_PKT_TYPE: H4Packet = (PH4_PACKET) Buffer; BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); - + if (H4Packet->Type == (UCHAR) HciPacketEvent) { - DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] ---------- ")); + DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] ---------- ")); _ReadContext->BytesToRead4FullPacket = HCI_EVENT_HEADER_SIZE; } - else if (H4Packet->Type == (UCHAR) HciPacketAclData) { - DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] ---------- ")); + else if (H4Packet->Type == (UCHAR) HciPacketAclData) { + DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] ---------- ")); _ReadContext->BytesToRead4FullPacket = HCI_ACL_HEADER_SIZE; } else { // - // Abort the read operation here but can consider to traverse the data - // until a valid packet type is found. + // Abort the read operation here but can consider to traverse the data + // until a valid packet type is found. // Status = STATUS_INVALID_PARAMETER; // discard and read again - DoTrace(LEVEL_ERROR, TFLAG_IO, (" Unexpected PacketType %d", H4Packet->Type)); - NT_ASSERT(FALSE && L"Detected unknown packet type"); - goto OutOfSync; + DoTrace(LEVEL_ERROR, TFLAG_IO, (" Unexpected PacketType %d", H4Packet->Type)); + NT_ASSERT(FALSE && L"Detected unknown packet type"); + goto OutOfSync; } // Proceed to read packet header - _ReadContext->H4Packet.Type = H4Packet->Type; // Valid packet type is cached. - ReadSegmentStateSet(_ReadContext, GET_PKT_HEADER); + _ReadContext->H4Packet.Type = H4Packet->Type; // Valid packet type is cached. + ReadSegmentStateSet(_ReadContext, GET_PKT_HEADER); break; - - case GET_PKT_HEADER: + + case GET_PKT_HEADER: if (_ReadContext->H4Packet.Type == (UCHAR) HciPacketEvent) { if (_ReadContext->BytesReadNextSegment == 0 && BytesRemained) { _ReadContext->H4Packet.Packet.Event.EventCode = *Buffer; - DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] Code 0x%x", _ReadContext->H4Packet.Packet.Event.EventCode)); - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); + DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] Code 0x%x", _ReadContext->H4Packet.Packet.Event.EventCode)); + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); _ReadContext->BytesToRead4FullPacket = 1; // Read the ParamsCount if needed } - + if (_ReadContext->BytesReadNextSegment == 1 && BytesRemained) { _ReadContext->H4Packet.Packet.Event.ParamsCount = *Buffer; - DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] ParamsCount 0x%x", _ReadContext->H4Packet.Packet.Event.ParamsCount)); + DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] ParamsCount 0x%x", _ReadContext->H4Packet.Packet.Event.ParamsCount)); BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); if (_ReadContext->H4Packet.Packet.Event.ParamsCount == 0) { // Full packet: match to a Request and complete it. - PacketLen = HCI_EVENT_HEADER_LEN + _ReadContext->H4Packet.Packet.Event.ParamsCount; + PacketLen = HCI_EVENT_HEADER_LEN + _ReadContext->H4Packet.Packet.Event.ParamsCount; DoTrace(LEVEL_INFO, TFLAG_DATA, (" [Event completed] PacketLen %d", PacketLen)); Status = ReadH4PacketComplete(FdoExtension, _ReadContext->H4Packet.Type, - (PUCHAR) &_ReadContext->H4Packet.Packet.Event, - PacketLen); + (PUCHAR) &_ReadContext->H4Packet.Packet.Event, + PacketLen); // Read next packet - ReadSegmentStateSet(_ReadContext, GET_PKT_TYPE); + ReadSegmentStateSet(_ReadContext, GET_PKT_TYPE); } // Read the remainder of a full (Event) packet else { - if (BytesRemained < _ReadContext->H4Packet.Packet.Event.ParamsCount) { - _ReadContext->BytesToRead4FullPacket = + if (BytesRemained < _ReadContext->H4Packet.Packet.Event.ParamsCount) { + _ReadContext->BytesToRead4FullPacket = _ReadContext->H4Packet.Packet.Event.ParamsCount - BytesRemained; } - + // Process to read packet payload ReadSegmentStateSet(_ReadContext, GET_PKT_PAYLOAD); } - } + } } else { - + if (_ReadContext->BytesReadNextSegment == 0 && BytesRemained) { _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment] = *Buffer; - DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[0] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); + DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[0] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); _ReadContext->BytesToRead4FullPacket = 3; // Read the remaining Dta header if needed } if (_ReadContext->BytesReadNextSegment == 1 && BytesRemained) { _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment] = *Buffer; - DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[1] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); - _ReadContext->BytesToRead4FullPacket = 2; // Read the remaining Dta header if needed - } + DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[1] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); + _ReadContext->BytesToRead4FullPacket = 2; // Read the remaining Dta header if needed + } if (_ReadContext->BytesReadNextSegment == 2 && BytesRemained) { _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment] = *Buffer; - DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[2] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); - _ReadContext->BytesToRead4FullPacket = 1; // Read the remaining Dta header if needed + DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[2] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); + _ReadContext->BytesToRead4FullPacket = 1; // Read the remaining Dta header if needed } if (_ReadContext->BytesReadNextSegment == 3 && BytesRemained) { _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment] = *Buffer; - DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[3] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); + DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Header[3] 0x%x", _ReadContext->H4Packet.Packet.Raw[_ReadContext->BytesReadNextSegment])); + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, 1); // Read the reamainder of a full (Data) packet - if (BytesRemained < _ReadContext->H4Packet.Packet.AclData.DataLength) { - _ReadContext->BytesToRead4FullPacket = + if (BytesRemained < _ReadContext->H4Packet.Packet.AclData.DataLength) { + _ReadContext->BytesToRead4FullPacket = _ReadContext->H4Packet.Packet.AclData.DataLength - BytesRemained; } // Process to read packet payload - ReadSegmentStateSet(_ReadContext, GET_PKT_PAYLOAD); - } - } + ReadSegmentStateSet(_ReadContext, GET_PKT_PAYLOAD); + } + } break; - + case GET_PKT_PAYLOAD: - if (_ReadContext->H4Packet.Type == (UCHAR) HciPacketEvent) { - + if (_ReadContext->H4Packet.Type == (UCHAR) HciPacketEvent) { + BytesToRead = _ReadContext->H4Packet.Packet.Event.ParamsCount - _ReadContext->BytesReadNextSegment; - + if (BytesRemained >= BytesToRead) { // Full packet - RtlCopyMemory(&_ReadContext->H4Packet.Packet.Event.Params[_ReadContext->BytesReadNextSegment], - Buffer, + RtlCopyMemory(&_ReadContext->H4Packet.Packet.Event.Params[_ReadContext->BytesReadNextSegment], + Buffer, BytesToRead); - DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] Payload[%d + %d] = FULL", - _ReadContext->BytesReadNextSegment, - BytesToRead)); - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesToRead); - + DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] Payload[%d + %d] = FULL", + _ReadContext->BytesReadNextSegment, + BytesToRead)); + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesToRead); + // Full packet: match to a Request and complete it. - PacketLen = HCI_EVENT_HEADER_LEN + _ReadContext->H4Packet.Packet.Event.ParamsCount; + PacketLen = HCI_EVENT_HEADER_LEN + _ReadContext->H4Packet.Packet.Event.ParamsCount; Status = ReadH4PacketComplete(FdoExtension, _ReadContext->H4Packet.Type, - (PUCHAR) &_ReadContext->H4Packet.Packet.Event, - PacketLen); + (PUCHAR) &_ReadContext->H4Packet.Packet.Event, + PacketLen); // Read next packet - ReadSegmentStateSet(_ReadContext, GET_PKT_TYPE); + ReadSegmentStateSet(_ReadContext, GET_PKT_TYPE); } else { // Partial packet - RtlCopyMemory(&_ReadContext->H4Packet.Packet.Event.Params[_ReadContext->BytesReadNextSegment], - Buffer, + RtlCopyMemory(&_ReadContext->H4Packet.Packet.Event.Params[_ReadContext->BytesReadNextSegment], + Buffer, BytesRemained); - DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] Payload[%d + %d] = Partial; %d to read", + DoTrace(LEVEL_INFO, TFLAG_IO, (" [Event] Payload[%d + %d] = Partial; %d to read", _ReadContext->BytesReadNextSegment, BytesRemained, - BytesToRead - BytesRemained)); - _ReadContext->BytesReadNextSegment += BytesRemained; - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesRemained); - + BytesToRead - BytesRemained)); + _ReadContext->BytesReadNextSegment += BytesRemained; + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesRemained); + // Remaining event params to read - _ReadContext->BytesToRead4FullPacket = + _ReadContext->BytesToRead4FullPacket = _ReadContext->H4Packet.Packet.Event.ParamsCount - _ReadContext->BytesReadNextSegment; - } + } } else { if (_ReadContext->H4Packet.Packet.AclData.DataLength > HCI_MAX_ACL_PAYLOAD_SIZE) { Status = STATUS_INVALID_PARAMETER; // discard and read again - DoTrace(LEVEL_ERROR, TFLAG_IO, (" Unexpected ACL DataLength %d > Presetted maximum size %d", + DoTrace(LEVEL_ERROR, TFLAG_IO, (" Unexpected ACL DataLength %d > Presetted maximum size %d", _ReadContext->H4Packet.Packet.AclData.DataLength, HCI_MAX_ACL_PAYLOAD_SIZE)); - NT_ASSERT(FALSE && L"Max ACL DataLength exceeded the presetted Max"); - goto OutOfSync; + NT_ASSERT(FALSE && L"Max ACL DataLength exceeded the presetted Max"); + goto OutOfSync; } - + BytesToRead = _ReadContext->H4Packet.Packet.AclData.DataLength - _ReadContext->BytesReadNextSegment; - + if (BytesRemained >= BytesToRead) { // Process full packet - RtlCopyMemory(&_ReadContext->H4Packet.Packet.AclData.Data[_ReadContext->BytesReadNextSegment], - Buffer, + RtlCopyMemory(&_ReadContext->H4Packet.Packet.AclData.Data[_ReadContext->BytesReadNextSegment], + Buffer, BytesToRead); - DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Payload[%d + %d] = FULL", + DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Payload[%d + %d] = FULL", _ReadContext->BytesReadNextSegment, - BytesToRead)); - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesToRead); - + BytesToRead)); + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesToRead); + // Full packet: try match to a Request in queue (if any) and complete it. - PacketLen = HCI_ACLDATA_HEADER_LEN + _ReadContext->H4Packet.Packet.AclData.DataLength; + PacketLen = HCI_ACLDATA_HEADER_LEN + _ReadContext->H4Packet.Packet.AclData.DataLength; Status = ReadH4PacketComplete(FdoExtension, _ReadContext->H4Packet.Type, - (PUCHAR) &_ReadContext->H4Packet.Packet.AclData, - PacketLen); + (PUCHAR) &_ReadContext->H4Packet.Packet.AclData, + PacketLen); // Next packet - ReadSegmentStateSet(_ReadContext, GET_PKT_TYPE); + ReadSegmentStateSet(_ReadContext, GET_PKT_TYPE); } else { // Process partial packet - RtlCopyMemory(&_ReadContext->H4Packet.Packet.AclData.Data[_ReadContext->BytesReadNextSegment], - Buffer, + RtlCopyMemory(&_ReadContext->H4Packet.Packet.AclData.Data[_ReadContext->BytesReadNextSegment], + Buffer, BytesRemained); - DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Payload[%d + %d] = Partial; %d to read", + DoTrace(LEVEL_INFO, TFLAG_IO, (" [AclData] Payload[%d + %d] = Partial; %d to read", _ReadContext->BytesReadNextSegment, BytesRemained, - BytesToRead - BytesRemained)); - _ReadContext->BytesReadNextSegment += BytesRemained; - BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesRemained); - + BytesToRead - BytesRemained)); + _ReadContext->BytesReadNextSegment += BytesRemained; + BUFFER_AND_SIZE_ADJUSTED(Buffer, BytesRemained, _ReadContext->BytesReadNextSegment, BytesRemained); + // Remaining data to read - _ReadContext->BytesToRead4FullPacket = - _ReadContext->H4Packet.Packet.AclData.DataLength - _ReadContext->BytesReadNextSegment; - } - } - break; - + _ReadContext->BytesToRead4FullPacket = + _ReadContext->H4Packet.Packet.AclData.DataLength - _ReadContext->BytesReadNextSegment; + } + } + break; + default: DoTrace(LEVEL_ERROR, TFLAG_IO, (" Unknown ReadSegmentState")); break; @@ -814,15 +806,14 @@ Return Value: } return Status; - + OutOfSync: DoTrace(LEVEL_ERROR, TFLAG_IO, (" Out-of-sync error detected in ProcessReadBuffer() %!STATUS!", Status)); - + return Status; } - VOID ReadH4PacketCompletionRoutine( _In_ WDFREQUEST _Request, @@ -834,8 +825,8 @@ ReadH4PacketCompletionRoutine( Routine Description: - This is CR function for reading data from device. It process the data read and - send down another request unless there is an error or the request is being + This is CR function for reading data from device. It process the data read and + send down another request unless there is an error or the request is being canceled. Arguments: @@ -844,14 +835,14 @@ Arguments: _Target - WDF IO Target _Params - Completion parameters _Context - Context of this request - + Return Value: none - ---*/ + +--*/ { - NTSTATUS Status; + NTSTATUS Status; PUART_READ_CONTEXT ReadContext; PFDO_EXTENSION FdoExtension; ULONG BytesRead; @@ -859,143 +850,141 @@ Return Value: PUCHAR OutBuffer; size_t OutBufferSize; READ_REQUEST_STATE PreviousState; - - UNREFERENCED_PARAMETER(_Request); - UNREFERENCED_PARAMETER(_Target); + UNREFERENCED_PARAMETER(_Request); + UNREFERENCED_PARAMETER(_Target); - // Operation result + // Operation result Status = _Params->IoStatus.Status; BytesRead = (ULONG) _Params->Parameters.Read.Length; - + ReadContext = (PUART_READ_CONTEXT) _Context; ReadContext->Status = Status; - - // Set to REQUEST_COMPLETE if skip REQUEST_PENDING state. + + // Set to REQUEST_COMPLETE if skip REQUEST_PENDING state. PreviousState = InterlockedCompareExchange((PLONG)&ReadContext->RequestState, REQUEST_COMPLETE, - REQUEST_SENT); + REQUEST_SENT); + + DoTrace(LEVEL_WARNING, TFLAG_DATA, ("+ReadH4PacketCompletionRoutine %!STATUS! %d BytesRead %S)", + Status, BytesRead, PreviousState == REQUEST_PENDING ? L"Async" : L"*Sync*")); - DoTrace(LEVEL_WARNING, TFLAG_DATA, ("+ReadH4PacketCompletionRoutine %!STATUS! %d BytesRead %S)", - Status, BytesRead, PreviousState == REQUEST_PENDING ? L"Async" : L"*Sync*")); + FdoExtension = (PFDO_EXTENSION) ReadContext->FdoExtension; - FdoExtension = (PFDO_EXTENSION) ReadContext->FdoExtension; - // - // The return status can either be - // - successful (buffer completely filled), + // The return status can either be + // - successful (buffer completely filled), // - timeout (buffer not completed filled prior to interval timeout expired - // - cancellation + // - cancellation // - failure // if (NT_SUCCESS(Status) || Status == STATUS_IO_TIMEOUT || Status == STATUS_TIMEOUT) { - // Continue to process + // Continue to process } else { DoTrace(LEVEL_ERROR, TFLAG_IO, (" ReadH4PacketCompletionRoutine failed %!STATUS!", Status)); if (Status == STATUS_CANCELLED) { // - // Under regualr operational state, IO Target will only cancel a request - // when it is ready to abort (e.g. device removal). - // + // Under regualr operational state, IO Target will only cancel a request + // when it is ready to abort (e.g. device removal). + // } - + goto Exit; } - + ReadMemory = _Params->Parameters.Read.Buffer; - OutBuffer = (PUCHAR) WdfMemoryGetBuffer(ReadMemory, &OutBufferSize); + OutBuffer = (PUCHAR) WdfMemoryGetBuffer(ReadMemory, &OutBufferSize); NT_ASSERT(OutBufferSize >= BytesRead); - DoTrace(LEVEL_INFO, TFLAG_IO, (" ReadH4PacketCompletionRoutine %d BytesRead pBuffer %p", BytesRead, OutBuffer)); - + DoTrace(LEVEL_INFO, TFLAG_IO, (" ReadH4PacketCompletionRoutine %d BytesRead pBuffer %p", BytesRead, OutBuffer)); + // // Process a read buffer if there is data // if (OutBuffer && BytesRead) - { + { // // Process the incoming data to form partial or full H4 packet // - Status = ReadH4PacketReassemble(ReadContext, - BytesRead, - OutBuffer); + Status = ReadH4PacketReassemble(ReadContext, + BytesRead, + OutBuffer); // If data stream error, ignore the packet and start over. if (!NT_SUCCESS(Status)) { - FdoExtension->OutOfSyncErrorCount++; - DoTrace(LEVEL_ERROR, TFLAG_IO, (" ====> [%d] 0x%x <=====", + FdoExtension->OutOfSyncErrorCount++; + DoTrace(LEVEL_ERROR, TFLAG_IO, (" ====> [%d] 0x%x <=====", FdoExtension->OutOfSyncErrorCount, *OutBuffer)); NT_ASSERT(NT_SUCCESS(Status) && L"Encountered an out-of-sync condition!"); - + // Prepare to read next data packet, starting with packet type. ReadSegmentStateSet(ReadContext, GET_PKT_TYPE); // Log(Error): log statistic of the read pump until this error // - // If there is a (knonw) hardware error or if we have exceeded maximun hardware count, + // If there is a (knonw) hardware error or if we have exceeded maximun hardware count, // the link is no longer reliable. Need to report to the upper layer via a read request. // if (FdoExtension->HardwareErrorDetected && FdoExtension->OutOfSyncErrorCount > MAX_HARDWARE_ERROR_COUNT) { // // Complete an event or read data request with STATUS_DEVICE_DATA_ERROR error to trigger - // BthMini/BthPort to handle the situation. IT can perform HCI_RESET to restore the + // BthMini/BthPort to handle the situation. IT can perform HCI_RESET to restore the // data channel. // #ifdef REPORT_HARDWARE_ERROR WDFREQUEST Request; DoTrace(LEVEL_ERROR, TFLAG_IO, (" ++++ Report a hardware error; OutOfSyncCount %d", FdoExtension->OutOfSyncErrorCount)); - - KeAcquireSpinLock(&FdoExtension->QueueAccessLock, &Irql); + + WdfSpinLockAcquire(FdoExtension->QueueAccessLock); // Complete a read (event or data) request with a specific error to indicate hardware error. Status = WdfIoQueueRetrieveNextRequest(FdoExtension->ReadEventQueue, &Request); - + // if there is no event request, find a read data request. if (Status == STATUS_NO_MORE_ENTRIES) { - Status = WdfIoQueueRetrieveNextRequest(FdoExtension->ReadDataQueue, &Request); + Status = WdfIoQueueRetrieveNextRequest(FdoExtension->ReadDataQueue, &Request); } - KeReleaseSpinLock(&FdoExtension->QueueAccessLock, Irql); + WdfSpinLockRelease(FdoExtension->QueueAccessLock); - if (NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_IO, (" Complete a request with STATUS_DEVICE_DATA_ERROR")); - WdfRequestComplete(Request, STATUS_DEVICE_DATA_ERROR); + DoTrace(LEVEL_ERROR, TFLAG_IO, (" Complete a request with STATUS_DEVICE_DATA_ERROR")); + WdfRequestComplete(Request, STATUS_DEVICE_DATA_ERROR); } #endif // REPORT_HARDWARE_ERROR Status = STATUS_DEVICE_DATA_ERROR; // abort and stop read pump - goto Exit; + goto Exit; } else { DoTrace(LEVEL_ERROR, TFLAG_IO, (" Detect out-of-sync error but read ahead...")); - + // Reset hardware error. - FdoExtension->HardwareErrorDetected = FALSE; + FdoExtension->HardwareErrorDetected = FALSE; - // try next - goto ReadNext; - } - } + // try next + goto ReadNext; + } + } } else { NT_ASSERT(Status == STATUS_TIMEOUT); } -ReadNext: +ReadNext: - if (PreviousState == REQUEST_PENDING) - { + if (PreviousState == REQUEST_PENDING) + { ULONG BytesToRead; // @@ -1006,9 +995,9 @@ ReadNext: sizeof(FdoExtension->ReadBuffer)); DoTrace(LEVEL_INFO, TFLAG_IO, (" ReadH4Packet(Read Buffer Size %d bytes)", BytesToRead)); - - // Issue next read here since this request was complete asychronously - // i.e. pending first and then this completion routein is invoked. + + // Issue next read here since this request was complete asychronously + // i.e. pending first and then this completion routein is invoked. ReadH4Packet(ReadContext, FdoExtension->ReadRequest, FdoExtension->ReadMemory, @@ -1017,27 +1006,26 @@ ReadNext: } else { - // Fall through and leave this fucntion if this request was completed synchronously; + // Fall through and leave this fucntion if this request was completed synchronously; // i.e. this function is invoked first and then return to the RequestSent function. - } + } - DoTrace(LEVEL_INFO, TFLAG_IO, ("-CR_ReadReadIO (fall though)")); + DoTrace(LEVEL_INFO, TFLAG_IO, ("-CR_ReadReadIO (fall though)")); return; Exit: - + if (!NT_SUCCESS(Status)) - { - NT_ASSERT(Status == STATUS_CANCELLED); + { + NT_ASSERT(Status == STATUS_CANCELLED); FdoExtension->ReadPumpRunning = FALSE; - DoTrace(LEVEL_WARNING, TFLAG_IO, (" Pump has stopped!")); - } + DoTrace(LEVEL_WARNING, TFLAG_IO, (" Pump has stopped!")); + } - DoTrace(LEVEL_INFO, TFLAG_IO, ("-CR_ReadReadIO (error)")); + DoTrace(LEVEL_INFO, TFLAG_IO, ("-CR_ReadReadIO (error)")); } - NTSTATUS ReadH4Packet( _In_ PUART_READ_CONTEXT _ReadContext, @@ -1059,17 +1047,16 @@ Arguments: Return Value: NTSTATUS - ---*/ -{ - PFDO_EXTENSION FdoExtension; - WDF_REQUEST_REUSE_PARAMS RequestReuseParams; - NTSTATUS Status; +--*/ +{ + PFDO_EXTENSION FdoExtension; + WDF_REQUEST_REUSE_PARAMS RequestReuseParams; + NTSTATUS Status; DoTrace(LEVEL_INFO, TFLAG_IO, ("+ReadH4Packet")); - FdoExtension = _ReadContext->FdoExtension; + FdoExtension = _ReadContext->FdoExtension; if (0 == _BufferLen) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" ReadH4Packet: _BufferLen cannot be 0")); @@ -1078,10 +1065,10 @@ Return Value: } while (TRUE) { - + DoTrace(LEVEL_INFO, TFLAG_IO, (" ReadH4Packet - <start>")); - NT_ASSERT(_ReadContext->RequestState != REQUEST_SENT); - + NT_ASSERT(_ReadContext->RequestState != REQUEST_SENT); + if (!IsDeviceInitialized(FdoExtension)) { Status = STATUS_DEVICE_NOT_READY; DoTrace(LEVEL_ERROR, TFLAG_IO, (" ReadH4Packet: cannot attach IO %!STATUS!", Status)); @@ -1091,50 +1078,50 @@ Return Value: // // Issue a read event request // - WDF_REQUEST_REUSE_PARAMS_INIT(&RequestReuseParams, WDF_REQUEST_REUSE_NO_FLAGS, STATUS_SUCCESS); + WDF_REQUEST_REUSE_PARAMS_INIT(&RequestReuseParams, WDF_REQUEST_REUSE_NO_FLAGS, STATUS_SUCCESS); Status = WdfRequestReuse(_WdfRequest, &RequestReuseParams); if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfRequestReuse failed %!STATUS!", Status)); goto Done; - } - + } + Status = WdfMemoryAssignBuffer(_WdfMemory, _Buffer, _BufferLen); if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfMemoryAssignBuffer failed %!STATUS!", Status)); goto Done; } - + Status = WdfIoTargetFormatRequestForRead(FdoExtension->IoTargetSerial, _WdfRequest, _WdfMemory, NULL, NULL); - + if (!NT_SUCCESS(Status)) { - DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfIoTargetFormatRequestForRead failed %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfIoTargetFormatRequestForRead failed %!STATUS!", Status)); goto Done; } - + // Note: This request is sent to UART driver so it cannot be marked cancellable. // But it can be canceled by issuing WdfRequestCancelSentRequest(). - + WdfRequestSetCompletionRoutine(_WdfRequest, ReadH4PacketCompletionRoutine, - _ReadContext); - + _ReadContext); + InterlockedExchange((PLONG)&_ReadContext->RequestState, REQUEST_SENT); - if (FALSE == WdfRequestSend(_WdfRequest, + if (FALSE == WdfRequestSend(_WdfRequest, FdoExtension->IoTargetSerial, WDF_NO_SEND_OPTIONS)) { Status = WdfRequestGetStatus(_WdfRequest); DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfRequestSend failed %!STATUS!", Status)); - // Not much we can do if cannot send this request; data pump will be stopped! + // Not much we can do if cannot send this request; data pump will be stopped! goto Done; } else - { + { READ_REQUEST_STATE PreviousState; // Set to REQUEST_PENDING if it is in the REQUEST_SENT state. @@ -1143,22 +1130,22 @@ Return Value: REQUEST_SENT); DoTrace(LEVEL_WARNING, TFLAG_IO, (" WdfRequestSend ReqState: %d -> %d", - PreviousState, _ReadContext->RequestState)); + PreviousState, _ReadContext->RequestState)); - if (PreviousState == REQUEST_SENT) + if (PreviousState == REQUEST_SENT) { - // Request is still pending, and will be completed asychronously in the + // Request is still pending, and will be completed asychronously in the // completion routine where it can issue next read. - Status = STATUS_PENDING; + Status = STATUS_PENDING; break; } - else + else { Status = FdoExtension->ReadContext.Status; if (NT_SUCCESS(Status)) { - // Previous request has been complete synchronously in the - // completion routine; do next read in this function. + // Previous request has been complete synchronously in the + // completion routine; do next read in this function. } else { @@ -1173,31 +1160,31 @@ Done: if (!NT_SUCCESS(Status)) { - NT_ASSERT(Status == STATUS_CANCELLED); + NT_ASSERT(Status == STATUS_CANCELLED); FdoExtension->ReadPumpRunning = FALSE; - } - + } + DoTrace(LEVEL_INFO, TFLAG_IO, ("-ReadH4Packet %!STATUS!", Status)); return Status; } -__inline +__inline PHCI_PACKET_ENTRY HLP_CreatePacketEntry( - _In_ ULONG _PacketLength, + _In_ ULONG _PacketLength, _In_reads_bytes_(_PacketLength) PUCHAR _Packet ) { PHCI_PACKET_ENTRY PacketEntry = NULL; - + PacketEntry = (PHCI_PACKET_ENTRY)ExAllocatePool(NonPagedPoolNx, sizeof(HCI_PACKET_ENTRY) + _PacketLength); if (PacketEntry != NULL) { InitializeListHead(&PacketEntry->DataEntry); - RtlCopyMemory(PacketEntry->Packet, _Packet, _PacketLength); + RtlCopyMemory(PacketEntry->Packet, _Packet, _PacketLength); PacketEntry->PacketLen = _PacketLength; } - + return PacketEntry; } @@ -1205,17 +1192,17 @@ NTSTATUS ReadRequestComplete( _In_ PFDO_EXTENSION _FdoExtension, _In_ UCHAR _PacketType, - _In_ ULONG _PacketLength, - _In_reads_bytes_opt_(_PacketLength) PUCHAR _Packet, + _In_ ULONG _PacketLength, + _In_reads_bytes_opt_(_PacketLength) PUCHAR _Packet, _Inout_ WDFQUEUE _Queue, - _Inout_ PLONG _QueueCount, + _Inout_ PLONG _QueueCount, _Inout_ PLIST_ENTRY _ListHead, _Inout_ PLONG _ListCount ) /*++ Routine Description: - This helper function processes both complete HCI Data packet from the device to find + This helper function processes both complete HCI Data packet from the device to find a pending Request, or find a completed HCI packet in a list to complete a Request. Arguments: @@ -1229,9 +1216,8 @@ Return Value: NTSTATUS - STATUS_SUCCESS Or STATUS_INSUFFICIENT_RESOURCE ---*/ +--*/ { - KIRQL Irql; WDFREQUEST Request = NULL; NTSTATUS Status = STATUS_SUCCESS; PHCI_PACKET_ENTRY PacketEntry = NULL; @@ -1240,29 +1226,28 @@ Return Value: PBTHX_HCI_READ_WRITE_CONTEXT HCIContext; BOOLEAN CompleteRequest = FALSE; - DoTrace(LEVEL_INFO, TFLAG_IO, ("+ReadRequestComplete")); + DoTrace(LEVEL_INFO, TFLAG_IO, ("+ReadRequestComplete")); - // + // // (ReqQueue, PktList) // C0. ( empty, empty) -> Add packet to list // C1. ( empty, !empty) -> Add packet to list // C2. (!empty, empty) -> DequeueAndCompletRequest(Packet) // C3. (!empty, !empty) -> Error! Cannot both empty at this function entry. // - - KeAcquireSpinLock(&_FdoExtension->QueueAccessLock, &Irql); + WdfSpinLockAcquire(_FdoExtension->QueueAccessLock); if (_Packet) { - - Status = WdfIoQueueRetrieveNextRequest(_Queue, &Request); + + Status = WdfIoQueueRetrieveNextRequest(_Queue, &Request); if (Status == STATUS_SUCCESS) { // Case 2: Typical code path - InterlockedDecrement(_QueueCount); - DoTrace(LEVEL_INFO, TFLAG_IO, (" (C2) Complete a request %p, _Packet %p, _PacketLength %d", - Request, _Packet, _PacketLength)); + InterlockedDecrement(_QueueCount); + DoTrace(LEVEL_INFO, TFLAG_IO, (" (C2) Complete a request %p, _Packet %p, _PacketLength %d", + Request, _Packet, _PacketLength)); CompleteRequest = TRUE; - + // Case 3: An error condition if List is not empty NT_ASSERT(IsListEmpty(_ListHead)); } @@ -1272,31 +1257,31 @@ Return Value: if (PacketEntry == NULL) { // Error condition Status = STATUS_INSUFFICIENT_RESOURCES; - DoTrace(LEVEL_ERROR, TFLAG_IO, (" (C0/Error) Could not allocate HCI_PACKET_ENTRY %!STATUS!", Status)); + DoTrace(LEVEL_ERROR, TFLAG_IO, (" (C0/Error) Could not allocate HCI_PACKET_ENTRY %!STATUS!", Status)); // This packet will be dropped; but nothing we can do as system resource is depleted! - } + } else { // Cache this packet to Packet List InsertTailList(_ListHead, &PacketEntry->DataEntry); InterlockedIncrement(_ListCount); - DoTrace(LEVEL_INFO, TFLAG_IO, (" (C0) Queuing packet with list count %d", *_ListCount)); + DoTrace(LEVEL_INFO, TFLAG_IO, (" (C0) Queuing packet with list count %d", *_ListCount)); } } - } - else { - if (!IsListEmpty(_ListHead)) { - Status = WdfIoQueueRetrieveNextRequest(_Queue, &Request); + } + else { + if (!IsListEmpty(_ListHead)) { + Status = WdfIoQueueRetrieveNextRequest(_Queue, &Request); if (Status == STATUS_SUCCESS) { // Case 2: Has Packet in the list while a new request arrives - InterlockedDecrement(_QueueCount); - + InterlockedDecrement(_QueueCount); + PacketEntry = (PHCI_PACKET_ENTRY) RemoveHeadList(_ListHead); _Packet = PacketEntry->Packet; - _PacketLength = PacketEntry->PacketLen; - InterlockedDecrement(_ListCount); - - DoTrace(LEVEL_INFO, TFLAG_IO, (" (C2) Complete a request %p, _Packet %p, _PacketLength %d", - Request, _Packet, _PacketLength)); + _PacketLength = PacketEntry->PacketLen; + InterlockedDecrement(_ListCount); + + DoTrace(LEVEL_INFO, TFLAG_IO, (" (C2) Complete a request %p, _Packet %p, _PacketLength %d", + Request, _Packet, _PacketLength)); CompleteRequest = TRUE; } @@ -1308,18 +1293,18 @@ Return Value: // Case 1: Request is pre-pening and queued. Status = STATUS_PENDING; DoTrace(LEVEL_INFO, TFLAG_IO, (" (C1) Read request is queued")); - } + } } - KeReleaseSpinLock(&_FdoExtension->QueueAccessLock, Irql); - + WdfSpinLockRelease(_FdoExtension->QueueAccessLock); + if (!CompleteRequest) { goto Done; - } - - // Complete this request - Status = WdfRequestRetrieveOutputMemory(Request, &ReqOutMemory); - if (Status != STATUS_SUCCESS) { + } + + // Complete this request + Status = WdfRequestRetrieveOutputMemory(Request, &ReqOutMemory); + if (Status != STATUS_SUCCESS) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" Could not retrieve output buffer")); WdfRequestCompleteWithInformation(Request, Status, (ULONG_PTR)0); goto Done; @@ -1328,22 +1313,22 @@ Return Value: HCIContext = WdfMemoryGetBuffer(ReqOutMemory, &BufferSize); BytesToReturn = FIELD_OFFSET(BTHX_HCI_READ_WRITE_CONTEXT, Data) + _PacketLength; - // This should not happen because BthMini should have sent down largest buffer according to device's capability. - NT_ASSERT(BytesToReturn <= BufferSize); - + // This should not happen because BthMini should have sent down largest buffer according to device's capability. + NT_ASSERT(BytesToReturn <= BufferSize); + // Transfer data to Request's output buffer HCIContext->Type = _PacketType; - HCIContext->DataLen = _PacketLength; + HCIContext->DataLen = _PacketLength; if (BytesToReturn <= BufferSize) { - RtlCopyMemory(&HCIContext->Data, _Packet, _PacketLength); + RtlCopyMemory(&HCIContext->Data, _Packet, _PacketLength); } else { - Status = STATUS_BUFFER_TOO_SMALL; + Status = STATUS_BUFFER_TOO_SMALL; BytesToReturn = 0; } - + // Validate and print out (WPP) HCI packet info - HCIContextValidate(HCIContext->Type == (UCHAR) HciPacketEvent ? + HCIContextValidate(HCIContext->Type == (UCHAR) HciPacketEvent ? _FdoExtension->CntEventCompleted : _FdoExtension->CntReadDataCompleted, HCIContext); @@ -1351,36 +1336,35 @@ Return Value: // Release memory allocated for a completed packet entry; it was not removed from the packet list. // if (PacketEntry) { - ExFreePool(PacketEntry); + ExFreePool(PacketEntry); } if (HCIContext->Type == (UCHAR) HciPacketEvent) { InterlockedIncrement(&_FdoExtension->CntEventCompleted); DoTrace(LEVEL_INFO, TFLAG_DATA, (" [%d] HciPacketEvent completing %!STATUS!, %d BytesToReturn", - _FdoExtension->CntEventCompleted, Status, (ULONG) BytesToReturn)); + _FdoExtension->CntEventCompleted, Status, (ULONG) BytesToReturn)); } else if (HCIContext->Type == (UCHAR) HciPacketAclData) { - InterlockedIncrement(&_FdoExtension->CntReadDataCompleted); + InterlockedIncrement(&_FdoExtension->CntReadDataCompleted); DoTrace(LEVEL_INFO, TFLAG_DATA, (" [%d] HciPacketAclData completing %!STATUS!, %d BytesToReturn", - _FdoExtension->CntReadDataCompleted, Status, (ULONG) BytesToReturn)); - } + _FdoExtension->CntReadDataCompleted, Status, (ULONG) BytesToReturn)); + } DoTrace(LEVEL_INFO, TFLAG_IO, (" Completing Request(%p) %!STATUS!, %d BytesToReturn", - Request, Status, (ULONG) BytesToReturn)); + Request, Status, (ULONG) BytesToReturn)); // // return only the actual data read, not including BTHX_HCI_READ_WRITE_CONTEXT // - WdfRequestCompleteWithInformation(Request, Status, BytesToReturn); - -Done: - - DoTrace(LEVEL_INFO, TFLAG_IO, ("-ReadRequestComplete: %!STATUS!", Status)); + WdfRequestCompleteWithInformation(Request, Status, BytesToReturn); + +Done: + + DoTrace(LEVEL_INFO, TFLAG_IO, ("-ReadRequestComplete: %!STATUS!", Status)); return Status; } - VOID ReadResourcesFree( _In_ WDFDEVICE _Device @@ -1399,35 +1383,34 @@ Return VOID ---*/ +--*/ { PFDO_EXTENSION FdoExtension; - KIRQL Irql; DoTrace(LEVEL_INFO, TFLAG_IO,("+ReadResourcesFree")); FdoExtension = FdoGetExtension(_Device); // - // Note: The Request(s) in WDFQUEUE (Event and ReadData) WDFQUEUEs + // Note: The Request(s) in WDFQUEUE (Event and ReadData) WDFQUEUEs // are managed by WDF, which will dequeue and cancel them for us. - // WdfIoQueueRetrieveNextRequest() returns STATUS_WDF_PAUSED since this + // WdfIoQueueRetrieveNextRequest() returns STATUS_WDF_PAUSED since this // function is invoked after entered D0. // // // Free resources allocated earlier // - - while(!IsListEmpty(&FdoExtension->ReadEventList)) + + while(!IsListEmpty(&FdoExtension->ReadEventList)) { - PHCI_PACKET_ENTRY PacketEntry; + PHCI_PACKET_ENTRY PacketEntry; - KeAcquireSpinLock(&FdoExtension->QueueAccessLock, &Irql); + WdfSpinLockAcquire(FdoExtension->QueueAccessLock); PacketEntry = (PHCI_PACKET_ENTRY)RemoveHeadList(&FdoExtension->ReadEventList); - InterlockedDecrement(&FdoExtension->EventListCount); - KeReleaseSpinLock(&FdoExtension->QueueAccessLock, Irql); - + InterlockedDecrement(&FdoExtension->EventListCount); + WdfSpinLockRelease(FdoExtension->QueueAccessLock); + if (PacketEntry) { ExFreePool(PacketEntry); @@ -1436,31 +1419,30 @@ Return } NT_ASSERT(FdoExtension->EventListCount == 0); - while(!IsListEmpty(&FdoExtension->ReadDataList)) + while(!IsListEmpty(&FdoExtension->ReadDataList)) { - PHCI_PACKET_ENTRY PacketEntry; + PHCI_PACKET_ENTRY PacketEntry; - KeAcquireSpinLock(&FdoExtension->QueueAccessLock, &Irql); + WdfSpinLockAcquire(FdoExtension->QueueAccessLock); PacketEntry = (PHCI_PACKET_ENTRY)RemoveHeadList(&FdoExtension->ReadDataList); - InterlockedDecrement(&FdoExtension->DataListCount); - KeReleaseSpinLock(&FdoExtension->QueueAccessLock, Irql); - + InterlockedDecrement(&FdoExtension->DataListCount); + WdfSpinLockRelease(FdoExtension->QueueAccessLock); + if (PacketEntry) { ExFreePool(PacketEntry); PacketEntry = NULL; } - } + } NT_ASSERT(FdoExtension->DataListCount == 0); - + if (FdoExtension->ReadRequest) { WdfObjectDelete(FdoExtension->ReadRequest); FdoExtension->ReadRequest = NULL; - } + } } - NTSTATUS ReadResourcesAllocate( _In_ WDFDEVICE _Device @@ -1479,21 +1461,20 @@ Return Value: NTSTATUS - STATUS_SUCCESS Or STATUS_INSUFFICIENT_RESOURCE ---*/ +--*/ { NTSTATUS Status; PFDO_EXTENSION FdoExtension; WDF_IO_QUEUE_CONFIG QueueConfig; WDF_OBJECT_ATTRIBUTES ObjAttributes; - DoTrace(LEVEL_INFO, TFLAG_IO,("+ReadResourcesAllocate")); + DoTrace(LEVEL_INFO, TFLAG_IO,("+ReadResourcesAllocate")); FdoExtension = FdoGetExtension(_Device); - - // HCI_EVENT - // Create WDF Queue for pending Read Event Request(s), and - // Initialize a List for pre-fetched Event + // HCI_EVENT + // Create WDF Queue for pending Read Event Request(s), and + // Initialize a List for pre-fetched Event WDF_IO_QUEUE_CONFIG_INIT(&QueueConfig, WdfIoQueueDispatchManual); @@ -1502,77 +1483,74 @@ Return Value: WDF_NO_OBJECT_ATTRIBUTES, &FdoExtension->ReadEventQueue); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfIoQueueCreate(Event) %!STATUS!", Status)); goto Done; } - + InitializeListHead(&FdoExtension->ReadEventList); - - FdoExtension->EventListCount = 0; + + FdoExtension->EventListCount = 0; FdoExtension->EventQueueCount = 0; - - // HCI_DATA - // Create WDF Queue for pending Read Data Request(s), and - // Initialize a List for pre-fetched Data + // HCI_DATA + // Create WDF Queue for pending Read Data Request(s), and + // Initialize a List for pre-fetched Data Status = WdfIoQueueCreate(_Device, &QueueConfig, WDF_NO_OBJECT_ATTRIBUTES, &FdoExtension->ReadDataQueue); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfIoQueueCreate(Data) %!STATUS!", Status)); goto Done; } - - InitializeListHead(&FdoExtension->ReadDataList); - - FdoExtension->DataListCount = 0; - FdoExtension->DataQueueCount = 0; + InitializeListHead(&FdoExtension->ReadDataList); + + FdoExtension->DataListCount = 0; + FdoExtension->DataQueueCount = 0; // Track request from top and HCI packets from device FdoExtension->CntCommandReq = 0; FdoExtension->CntCommandCompleted = 0; FdoExtension->CntEventReq = 0; - FdoExtension->CntEventCompleted = 0; - + FdoExtension->CntEventCompleted = 0; + FdoExtension->CntWriteDataReq = 0; - FdoExtension->CntWriteDataCompleted = 0; - + FdoExtension->CntWriteDataCompleted = 0; + FdoExtension->CntReadDataReq = 0; FdoExtension->CntReadDataCompleted = 0; - // Create a WDF Request WDF_OBJECT_ATTRIBUTES_INIT(&ObjAttributes); - ObjAttributes.ParentObject = _Device; - - Status = WdfRequestCreate(&ObjAttributes, - FdoExtension->IoTargetSerial, + ObjAttributes.ParentObject = _Device; + + Status = WdfRequestCreate(&ObjAttributes, + FdoExtension->IoTargetSerial, &FdoExtension->ReadRequest); - - if (!NT_SUCCESS(Status)) + + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfRequestCreate(ReadRequest) failed %!STATUS!", Status)); goto Done; - } + } // Initialize the ReadContext and its initial ReadSegmentState - RtlZeroMemory(&FdoExtension->ReadContext, sizeof(UART_READ_CONTEXT)); + RtlZeroMemory(&FdoExtension->ReadContext, sizeof(UART_READ_CONTEXT)); FdoExtension->ReadContext.FdoExtension = FdoExtension; - ReadSegmentStateSet(&FdoExtension->ReadContext, GET_PKT_TYPE); + ReadSegmentStateSet(&FdoExtension->ReadContext, GET_PKT_TYPE); - Status = WdfMemoryCreatePreallocated(&ObjAttributes, + Status = WdfMemoryCreatePreallocated(&ObjAttributes, &FdoExtension->ReadBuffer, - sizeof(FdoExtension->ReadBuffer), - &FdoExtension->ReadMemory); + sizeof(FdoExtension->ReadBuffer), + &FdoExtension->ReadMemory); - if (!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { DoTrace(LEVEL_ERROR, TFLAG_IO, (" WdfMemoryCreatePreallocated(ReadMemory) failed %!STATUS!", Status)); goto Done; @@ -1580,13 +1558,12 @@ Return Value: Done: - DoTrace(LEVEL_INFO, TFLAG_IO,("-ReadResourcesAllocate %!STATUS!", Status)); + DoTrace(LEVEL_INFO, TFLAG_IO,("-ReadResourcesAllocate %!STATUS!", Status)); if (!NT_SUCCESS(Status)) { - ReadResourcesFree(_Device); + ReadResourcesFree(_Device); } return Status; } - diff --git a/bluetooth/serialhcibus/serialhcibus.sln b/bluetooth/serialhcibus/serialhcibus.sln index f299309d..25bc57e7 100644 --- a/bluetooth/serialhcibus/serialhcibus.sln +++ b/bluetooth/serialhcibus/serialhcibus.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0 MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SerialBusWdk", "WDK\SerialBusWdk.vcxproj", "{186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SerialBusWdk", "WDK\SerialBusWdk.vcxproj", "{6844B626-ABF4-4F07-BD90-7AA8A8A87E12}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,14 +13,14 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Debug|Win32.ActiveCfg = Debug|Win32 - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Debug|Win32.Build.0 = Debug|Win32 - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Release|Win32.ActiveCfg = Release|Win32 - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Release|Win32.Build.0 = Release|Win32 - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Debug|x64.ActiveCfg = Debug|x64 - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Debug|x64.Build.0 = Debug|x64 - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Release|x64.ActiveCfg = Release|x64 - {186E63FF-9F2F-4FF6-82CB-FBAD7BA24089}.Release|x64.Build.0 = Release|x64 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Debug|Win32.ActiveCfg = Debug|Win32 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Debug|Win32.Build.0 = Debug|Win32 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Release|Win32.ActiveCfg = Release|Win32 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Release|Win32.Build.0 = Release|Win32 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Debug|x64.ActiveCfg = Debug|x64 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Debug|x64.Build.0 = Debug|x64 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Release|x64.ActiveCfg = Release|x64 + {6844B626-ABF4-4F07-BD90-7AA8A8A87E12}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE |
