00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
#include "iop.h"
00028
#pragma hdrstop
00029
00030
#if UMODETEST
00031
#undef IsNEC_98
00032
#define IsNEC_98 0
00033
#endif
00034
00035
#ifdef POOL_TAGGING
00036
#undef ExAllocatePool
00037
#define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'rpaM')
00038
#endif
00039
00040
00041
00042
00043
00044
00045
00046 typedef struct _FIRMWARE_CONFIGURATION {
00047 struct _FIRMWARE_CONFIGURATION *
Next;
00048 INTERFACE_TYPE
BusType;
00049 ULONG
BusNumber;
00050 CONFIGURATION_TYPE ControllerType;
00051 ULONG
ControllerNumber;
00052 CONFIGURATION_TYPE PeripheralType;
00053 ULONG
PeripheralNumber;
00054 ULONG
NumberBases;
00055 ULONG
ResourceDescriptorSize;
00056 PVOID
ResourceDescriptor;
00057 ULONG
IdentifierLength;
00058 ULONG
IdentifierType;
00059 PVOID
Identifier;
00060 PWCHAR
PnPId;
00061 BOOLEAN
NewlyCreated;
00062 }
FIRMWARE_CONFIGURATION, *
PFIRMWARE_CONFIGURATION;
00063
00064
00065
00066
00067
00068
typedef struct _DEVICE_EXTENSION {
00069
PDEVICE_OBJECT DeviceObject;
00070 PDRIVER_OBJECT DriverObject;
00071 INTERFACE_TYPE
InterfaceType;
00072 ULONG
BusNumber;
00073 PFIRMWARE_CONFIGURATION FirmwareList;
00074 }
DEVICE_EXTENSION, *
PDEVICE_EXTENSION;
00075
00076
00077
00078
00079 typedef struct _FIRMWARE_IDENT_TO_PNP_ID {
00080 PWCHAR
FirmwareName;
00081 PWCHAR
PnPId;
00082 }
FIRMWARE_IDENT_TO_PNP_ID, *
PFIRMWARE_IDENT_TO_PNP_ID;
00083
00084
00085
00086
00087
00088 #define OPTIONS_NONE 0x00000000
00089 #define OPTIONS_INSERT_PNP_ID 0x00000001
00090 #define OPTIONS_INSERT_DEVICEDESC 0x00000002
00091 #define OPTIONS_INSERT_COMPATIBLE_IDS 0x00000004
00092 #define OPTIONS_INSERT_PHANTOM_MARKER 0x00000008
00093 typedef struct _MAPPER_SEED {
00094 PWCHAR
ValueName;
00095 ULONG
ValueType;
00096 ULONG
DwordValueContent;
00097 ULONG
Options;
00098 }
MAPPER_SEED, *
PMAPPER_SEED;
00099
00100
00101
00102
00103
00104
00105 #define KEY_SEED_REQUIRED 0x00000000
00106 #define KEY_SEED_DEVICE_PARAMETERS 0x00000001
00107 typedef struct _KEY_SEED {
00108 PWCHAR
KeyName;
00109 ULONG
Attribute;
00110 ULONG
Options;
00111 }
KEY_SEED, *
PKEY_SEED;
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 DEVICE_EXTENSION MapperDeviceExtension;
00123
00124
00125
00126
00127
00128
00129 FIRMWARE_IDENT_TO_PNP_ID KeyboardMap[] = {
00130
L"XT_83KEY",
L"*PNP0300",
00131
L"PCAT_86KEY",
L"*PNP0301",
00132
L"PCXT_84KEY",
L"*PNP0302",
00133
L"XT_84KEY",
L"*PNP0302",
00134
L"101-KEY",
L"*PNP0303",
00135
L"OLI_83KEY",
L"*PNP0304",
00136
L"ATT_301",
L"*PNP0304",
00137
L"OLI_102KEY",
L"*PNP0305",
00138
L"OLI_86KEY",
L"*PNP0306",
00139
L"OLI_A101_102KEY",
L"*PNP0309",
00140
L"ATT_302",
L"*PNP030a",
00141
L"PCAT_ENHANCED",
L"*PNP030b",
00142
L"PC98_106KEY",
L"*nEC1300",
00143
L"PC98_LaptopKEY",
L"*nEC1300",
00144
L"PC98_N106KEY",
L"*PNP0303",
00145
NULL,
NULL
00146 };
00147
00148 #define PS2_KEYBOARD_COMPATIBLE_ID L"PS2_KEYBOARD"
00149 #define PS2_MOUSE_COMPATIBLE_ID L"PS2_MOUSE"
00150
00151
00152
00153
00154
00155
00156 FIRMWARE_IDENT_TO_PNP_ID PointerMap[] = {
00157
L"PS2 MOUSE",
L"*PNP0F0E",
00158
L"SERIAL MOUSE",
L"*PNP0F0C",
00159
L"MICROSOFT PS2 MOUSE",
L"*PNP0F03",
00160
L"LOGITECH PS2 MOUSE",
L"*PNP0F12",
00161
L"MICROSOFT INPORT MOUSE",
L"*PNP0F02",
00162
L"MICROSOFT SERIAL MOUSE",
L"*PNP0F01",
00163
L"MICROSOFT BALLPOINT SERIAL MOUSE",
L"*PNP0F09",
00164
L"LOGITECH SERIAL MOUSE",
L"*PNP0F08",
00165
L"MICROSOFT BUS MOUSE",
L"*PNP0F00",
00166
L"NEC PC-9800 BUS MOUSE",
L"*nEC1F00",
00167
NULL,
NULL
00168 };
00169
00170
00171
00172
00173
00174
00175
00176 MAPPER_SEED MapperValueSeed[] = {
00177 REGSTR_VAL_HARDWAREID, REG_MULTI_SZ, 0,
OPTIONS_INSERT_PNP_ID,
00178 REGSTR_VAL_COMPATIBLEIDS, REG_MULTI_SZ, 0,
OPTIONS_INSERT_COMPATIBLE_IDS,
00179 REGSTR_VAL_FIRMWAREIDENTIFIED, REG_DWORD, 1,
OPTIONS_NONE,
00180 REGSTR_VAL_DEVDESC, REG_SZ, 0,
OPTIONS_INSERT_DEVICEDESC,
00181 REGSTR_VAL_PHANTOM, REG_DWORD, 1,
OPTIONS_INSERT_PHANTOM_MARKER,
00182
NULL, 0, 0, 0
00183 };
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 KEY_SEED MapperKeySeed[] = {
00195
L"\\Control", REG_OPTION_VOLATILE,
KEY_SEED_REQUIRED,
00196
L"\\LogConf", REG_OPTION_NON_VOLATILE,
KEY_SEED_REQUIRED,
00197
L"", REG_OPTION_NON_VOLATILE,
KEY_SEED_DEVICE_PARAMETERS,
00198
NULL, 0, 0
00199 };
00200
00201
00202
00203
00204
00205
00206 PWSTR
SerialId =
L"*PNP0501";
00207
00208 PWSTR
SerialIdNEC[] = {
00209
L"*nEC1500",
00210
L"*nEC1501",
00211
L"*nEC1502",
00212
L"*nEC1503",
00213
L"*nEC8071",
00214
L"*nEC0C01",
00215
NULL
00216 };
00217
00218
00219
00220
00221
00222
00223 PWSTR
ParallelId =
L"*PNP0400";
00224
00225 PWSTR
ParallelIdNEC =
L"*nEC1401";
00226
00227
00228
00229
00230
00231 PWSTR
FloppyId =
L"*PNP0700";
00232
00233
00234
00235
00236
00237
00238 PWSTR
ATAId =
L"*PNP0600";
00239
00240
00241
00242
00243
00244
#if DBG
00245
00246
#define MAPPER_ERROR 0x00000001
00247
#define MAPPER_INFORMATION 0x00000002
00248
#define MAPPER_PNP_ID 0x00000004
00249
#define MAPPER_RESOURCES 0x00000008
00250
#define MAPPER_REGISTRY 0x00000010
00251
#define MAPPER_VERBOSE 0x00008000
00252
00253 ULONG MapperDebugMask = MAPPER_ERROR |
00254
00255
00256
00257
00258
00259 0;
00260
00261
#define DebugPrint(X) MapperDebugPrint X
00262
00263
VOID
00264 MapperDebugPrint(
00265 ULONG DebugMask,
00266 PCCHAR DebugMessage,
00267 ...
00268 );
00269
00270
#else
00271
00272 #define DebugPrint(X)
00273
00274
#endif // DBG
00275
00276
00277
00278
00279
00280
PFIRMWARE_IDENT_TO_PNP_ID
00281
MapperFindIdentMatch(
00282 PFIRMWARE_IDENT_TO_PNP_ID IdentTable,
00283 PWCHAR String
00284 );
00285
00286 PWSTR
00287
MapperTranslatePnPId(
00288 CONFIGURATION_TYPE PeripheralType,
00289 PKEY_VALUE_FULL_INFORMATION Identifier
00290 );
00291
00292
NTSTATUS
00293
MapperPeripheralCallback(
00294 IN PVOID Context,
00295 IN PUNICODE_STRING PathName,
00296 IN INTERFACE_TYPE BusType,
00297 IN ULONG BusNumber,
00298 IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
00299 IN CONFIGURATION_TYPE ControllerType,
00300 IN ULONG ControllerNumber,
00301 IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
00302 IN CONFIGURATION_TYPE PeripheralType,
00303 IN ULONG PeripheralNumber,
00304 IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
00305 );
00306
00307
NTSTATUS
00308
MapperCallback(
00309 IN PVOID Context,
00310 IN PUNICODE_STRING PathName,
00311 IN INTERFACE_TYPE BusType,
00312 IN ULONG BusNumber,
00313 IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
00314 IN CONFIGURATION_TYPE ControllerType,
00315 IN ULONG ControllerNumber,
00316 IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
00317 IN CONFIGURATION_TYPE PeripheralType,
00318 IN ULONG PeripheralNumber,
00319 IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
00320 );
00321
00322
VOID
00323
MapperMarkKey(
00324 IN HANDLE Handle,
00325 IN PUNICODE_STRING PathName,
00326 IN PFIRMWARE_CONFIGURATION FirmwareEntry
00327 );
00328
00329
VOID
00330
MapperSeedKey(
00331 IN HANDLE Handle,
00332 IN PUNICODE_STRING PathName,
00333 IN PFIRMWARE_CONFIGURATION FirmwareEntry,
00334 IN BOOLEAN DeviceIsPhantom
00335 );
00336
00337 PCM_RESOURCE_LIST
00338
MapperAdjustResourceList (
00339 IN PCM_RESOURCE_LIST ResourceList,
00340 IN PWCHAR PnPId,
00341 IN OUT PULONG Size
00342 );
00343
00344
NTSTATUS
00345
ComPortDBAdd(
00346 IN HANDLE DeviceParamKey,
00347 IN PWSTR PortName
00348 );
00349
00350
#ifdef ALLOC_PRAGMA
00351
#pragma alloc_text(INIT, MapperFindIdentMatch)
00352
#pragma alloc_text(INIT, MapperTranslatePnPId)
00353
#pragma alloc_text(INIT, MapperPeripheralCallback)
00354
#pragma alloc_text(INIT, MapperCallback)
00355
#pragma alloc_text(INIT, MapperMarkKey)
00356
#pragma alloc_text(INIT, MapperSeedKey)
00357
#pragma alloc_text(INIT, MapperFreeList)
00358
#pragma alloc_text(INIT, MapperAdjustResourceList)
00359
#pragma alloc_text(INIT, ComPortDBAdd)
00360
#pragma alloc_text(INIT, MapperPhantomizeDetectedComPorts)
00361
#if DBG
00362
#pragma alloc_text(INIT, MapperDebugPrint)
00363
#endif
00364
#endif
00365
00366
PFIRMWARE_IDENT_TO_PNP_ID
00367 MapperFindIdentMatch(
00368 PFIRMWARE_IDENT_TO_PNP_ID IdentTable,
00369 PWCHAR String
00370 )
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 {
00389
PFIRMWARE_IDENT_TO_PNP_ID entry;
00390
00391 entry = IdentTable;
00392
while (entry->
FirmwareName) {
00393
if (!wcscmp(
String, entry->
FirmwareName)) {
00394
return entry;
00395 }
00396 entry++;
00397 }
00398
return NULL;
00399 }
00400
00401 PWSTR
00402 MapperTranslatePnPId(
00403 CONFIGURATION_TYPE PeripheralType,
00404 PKEY_VALUE_FULL_INFORMATION Identifier
00405 )
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 {
00428
PFIRMWARE_IDENT_TO_PNP_ID identMap;
00429 PWSTR identifierString;
00430 PWSTR idStr;
00431
00432
if (Identifier) {
00433 identifierString = (PWSTR)((PUCHAR)Identifier + Identifier->DataOffset);
00434
DebugPrint((MAPPER_PNP_ID,
00435
"Mapper: identifier = %ws\n\tType = ",
00436 identifierString));
00437 }
00438
00439 idStr =
NULL;
00440
switch (
PeripheralType) {
00441
case DiskController:
00442
DebugPrint((MAPPER_PNP_ID,
00443
"%s (%d)\n",
00444
"DiskController",
00445
PeripheralType));
00446 idStr =
FloppyId;
00447
break;
00448
00449
case SerialController:
00450
DebugPrint((MAPPER_PNP_ID,
00451
"%s (%d)\n",
00452
"SerialController",
00453
PeripheralType));
00454 idStr =
SerialId;
00455
break;
00456
00457
case ParallelController:
00458
DebugPrint((MAPPER_PNP_ID,
00459
"%s (%d)\n",
00460
"ParallelController",
00461
PeripheralType));
00462 idStr =
ParallelId;
00463
break;
00464
00465
case PointerController:
00466
DebugPrint((MAPPER_PNP_ID,
00467
"%s (%d)\n",
00468
"PointerController",
00469
PeripheralType));
00470 idStr =
PointerMap[0].
PnPId;
00471
break;
00472
00473
case KeyboardController:
00474
DebugPrint((MAPPER_PNP_ID,
00475
"%s (%d)\n",
00476
"KeyboardController",
00477
PeripheralType));
00478 idStr =
KeyboardMap[0].
PnPId;
00479
break;
00480
00481
case DiskPeripheral:
00482
DebugPrint((MAPPER_PNP_ID,
00483
"%s (%d)\n",
00484
"DiskPeripheral",
00485
PeripheralType));
00486
break;
00487
00488
case FloppyDiskPeripheral:
00489
DebugPrint((MAPPER_PNP_ID,
00490
"%s (%d)\n",
00491
"FloppyDiskPeripheral",
00492
PeripheralType));
00493 idStr =
FloppyId;
00494
break;
00495
00496
case PointerPeripheral:
00497 identMap =
MapperFindIdentMatch(
PointerMap, identifierString);
00498
if (identMap) {
00499
DebugPrint((MAPPER_PNP_ID,
00500
"%ws\n",
00501 identMap->
PnPId));
00502 idStr = identMap->
PnPId;
00503 }
else {
00504
DebugPrint((MAPPER_ERROR,
00505
"Mapper: No pointer match found\n"));
00506 }
00507
break;
00508
00509
case KeyboardPeripheral:
00510 identMap =
MapperFindIdentMatch(
KeyboardMap, identifierString);
00511
00512
if (identMap) {
00513
DebugPrint((MAPPER_PNP_ID,
00514
"%ws\n",
00515 identMap->
PnPId));
00516 idStr = identMap->
PnPId;
00517 }
else {
00518
DebugPrint((MAPPER_ERROR,
00519
"Mapper: No keyboard match found\n"));
00520 }
00521
00522
break;
00523
00524
default:
00525
DebugPrint((MAPPER_ERROR,
00526
"Mapper: Unknown device (%d)\n",
00527
PeripheralType));
00528
break;
00529 }
00530
return idStr;
00531 }
00532
00533
00534
NTSTATUS
00535 MapperPeripheralCallback(
00536 IN PVOID Context,
00537 IN PUNICODE_STRING PathName,
00538 IN INTERFACE_TYPE BusType,
00539 IN ULONG BusNumber,
00540 IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
00541 IN CONFIGURATION_TYPE ControllerType,
00542 IN ULONG ControllerNumber,
00543 IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
00544 IN CONFIGURATION_TYPE PeripheralType,
00545 IN ULONG PeripheralNumber,
00546 IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
00547 )
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 {
00581
PFIRMWARE_CONFIGURATION firmwareEntry = Context;
00582 PKEY_VALUE_FULL_INFORMATION information;
00583 ULONG dataLength;
00584 PWCHAR ptr;
00585 PVOID temp;
00586
00587
DebugPrint((MAPPER_REGISTRY,
00588
"Mapper: peripheral registry location is\n %ws\n",
00589 PathName->Buffer));
00590
00591
if (!ControllerInformation) {
00592
DebugPrint((MAPPER_VERBOSE,
00593
"Mapper: No component information\n"));
00594 }
00595
if (!PeripheralInformation) {
00596
DebugPrint((MAPPER_VERBOSE,
00597
"Mapper: No peripheral information\n"));
00598
return STATUS_SUCCESS;
00599 }
00600
00601
00602
00603
00604
00605
if (PeripheralInformation[
IoQueryDeviceIdentifier]) {
00606 information = PeripheralInformation[
IoQueryDeviceIdentifier];
00607 firmwareEntry->
PnPId =
MapperTranslatePnPId(
PeripheralType, information);
00608
00609
if (firmwareEntry->
PnPId) {
00610
00611
00612
00613
00614
00615
if (((dataLength = information->DataLength) >
sizeof(WCHAR)) &&
00616 (information->Type == REG_SZ)) {
00617
00618 ptr = (PWCHAR) ((PUCHAR)information + information->DataOffset);
00619
00620
if (*ptr) {
00621 temp =
ExAllocatePool(
NonPagedPool, dataLength);
00622
if (temp) {
00623
00624
00625
00626
00627
00628
00629
if(firmwareEntry->
Identifier) {
00630
ExFreePool(firmwareEntry->
Identifier);
00631 }
00632
00633
00634
00635
00636
00637 firmwareEntry->
Identifier = temp;
00638 firmwareEntry->
IdentifierType = information->Type;
00639 firmwareEntry->
IdentifierLength = dataLength;
00640 RtlMoveMemory(firmwareEntry->
Identifier, ptr, dataLength);
00641 }
00642 }
00643 }
00644 }
00645 }
00646
00647
00648
00649
00650
00651 firmwareEntry->
PeripheralType =
PeripheralType;
00652 firmwareEntry->
PeripheralNumber = PeripheralNumber;
00653
00654
return STATUS_SUCCESS;
00655 }
00656
00657
NTSTATUS
00658 MapperCallback(
00659 IN PVOID Context,
00660 IN PUNICODE_STRING PathName,
00661 IN INTERFACE_TYPE BusType,
00662 IN ULONG BusNumber,
00663 IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
00664 IN CONFIGURATION_TYPE ControllerType,
00665 IN ULONG ControllerNumber,
00666 IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
00667 IN CONFIGURATION_TYPE PeripheralType,
00668 IN ULONG PeripheralNumber,
00669 IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
00670 )
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703 {
00704
PDEVICE_EXTENSION deviceExtension = Context;
00705 PCM_FULL_RESOURCE_DESCRIPTOR controllerData;
00706 PKEY_VALUE_FULL_INFORMATION information;
00707
PFIRMWARE_CONFIGURATION firmwareEntry;
00708
CONFIGURATION_TYPE peripheralType;
00709 PUCHAR buffer;
00710 PUCHAR identifier;
00711 ULONG dataLength;
00712
00713
00714
00715
00716
00717
if (!(information = ControllerInformation[
IoQueryDeviceConfigurationData])) {
00718
00719
return STATUS_SUCCESS;
00720 }
00721
00722
if (!(dataLength = information->DataLength)) {
00723
00724
return STATUS_SUCCESS;
00725 }
00726
00727
00728
00729
00730
00731 firmwareEntry =
ExAllocatePool(
NonPagedPool,
sizeof(
FIRMWARE_CONFIGURATION));
00732
if (!firmwareEntry) {
00733
00734
return STATUS_INSUFFICIENT_RESOURCES;
00735 }
00736 RtlZeroMemory(firmwareEntry,
sizeof(
FIRMWARE_CONFIGURATION));
00737
00738
00739
00740
00741
00742 firmwareEntry->
ControllerType =
ControllerType;
00743 firmwareEntry->
ControllerNumber = ControllerNumber;
00744 firmwareEntry->
BusNumber =
BusNumber;
00745 firmwareEntry->
BusType = BusType;
00746
00747
00748
00749
00750
00751 buffer = firmwareEntry->
ResourceDescriptor =
ExAllocatePool(
NonPagedPool,
00752 dataLength);
00753
00754
if (!buffer) {
00755
ExFreePool(firmwareEntry);
00756
return STATUS_INSUFFICIENT_RESOURCES;
00757 }
00758
00759
00760
00761
00762
00763 controllerData = (PCM_FULL_RESOURCE_DESCRIPTOR)
00764 ((PUCHAR)information + information->DataOffset);
00765 RtlMoveMemory(buffer, controllerData, dataLength);
00766 firmwareEntry->
ResourceDescriptorSize = dataLength;
00767
00768
00769
00770
00771
00772
if (information = ControllerInformation[
IoQueryDeviceIdentifier]) {
00773 PWCHAR ptr;
00774
00775
if (dataLength = information->DataLength) {
00776
00777 ptr = (PWCHAR) ((PUCHAR)information + information->DataOffset);
00778
if (
ControllerType ==
ParallelController) {
00779 PWCHAR tmpChar;
00780
00781
00782
00783
00784
00785
00786 *ptr++ = (WCHAR)
'L';
00787 *ptr++ = (WCHAR)
'P';
00788 *ptr++ = (WCHAR)
'T';
00789
00790
00791
00792
00793
00794 tmpChar = ptr;
00795
while (*tmpChar) {
00796
if ((*tmpChar >= (WCHAR)
'0') &&
00797 (*tmpChar <= (WCHAR)
'9')) {
00798
break;
00799 }
00800 tmpChar++;
00801 }
00802
00803
if (*tmpChar) {
00804
while (*tmpChar) {
00805 *ptr++ = *tmpChar++;
00806 }
00807 *ptr = (WCHAR) 0;
00808
00809
00810
00811
00812
00813
00814 ptr = (PWCHAR) ((PUCHAR)information + information->DataOffset);
00815 dataLength = 10;
00816 }
else {
00817 dataLength = 0;
00818
DebugPrint((MAPPER_ERROR,
00819
"Mapper: no parallel port number!\n"));
00820 }
00821 }
00822
00823
if (dataLength) {
00824 firmwareEntry->
Identifier =
ExAllocatePool(
NonPagedPool,
00825 dataLength);
00826
if (firmwareEntry->
Identifier) {
00827
00828
00829
00830
00831
00832 firmwareEntry->
IdentifierType = information->Type;
00833 firmwareEntry->
IdentifierLength = dataLength;
00834 RtlMoveMemory(firmwareEntry->
Identifier, ptr, dataLength);
00835 }
00836 }
00837 }
00838 }
00839
00840
00841
00842
00843
00844
switch (
ControllerType) {
00845
case SerialController:
00846
case ParallelController:
00847
00848
00849
00850 peripheralType = (
CONFIGURATION_TYPE) 0;
00851
break;
00852
case DiskController:
00853 peripheralType =
FloppyDiskPeripheral;
00854
break;
00855
case KeyboardController:
00856 peripheralType =
KeyboardPeripheral;
00857
break;
00858
case PointerController:
00859 peripheralType =
PointerPeripheral;
00860
break;
00861
default:
00862 peripheralType = (
CONFIGURATION_TYPE) 0;
00863
break;
00864 }
00865
00866
DebugPrint((MAPPER_REGISTRY,
00867
"Mapper: registry location is\n %ws\n",
00868 PathName->Buffer));
00869
00870
DebugPrint((MAPPER_INFORMATION,
00871
"Mapper: ControllerInformation[] -\n\tIdent: %x -\n\tData: %x -\n\tInformation: %x\n",
00872 ControllerInformation[0],
00873 ControllerInformation[1],
00874 ControllerInformation[2]));
00875
00876
if (peripheralType) {
00877
DebugPrint((MAPPER_PNP_ID,
00878
"Mapper: searching for peripheral type %d\n",
00879 peripheralType));
00880
00881
IoQueryDeviceDescription(&BusType,
00882 &
BusNumber,
00883 &
ControllerType,
00884 &ControllerNumber,
00885 &peripheralType,
00886
NULL,
00887
MapperPeripheralCallback,
00888 firmwareEntry);
00889 }
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
if (!firmwareEntry->
PnPId && firmwareEntry->
PeripheralType == 0) {
00908
00909
00910
00911
00912
00913 firmwareEntry->
PnPId =
MapperTranslatePnPId(
ControllerType,
NULL);
00914
00915
if (!firmwareEntry->
PnPId) {
00916
DebugPrint((MAPPER_PNP_ID,
00917
"Mapper: NO PnP Id for\n ==> %ws\n",
00918 PathName->Buffer));
00919 }
00920 }
00921
00922
00923
if (IsNEC_98){
00924
00925
switch (
ControllerType) {
00926
case SerialController:{
00927 ULONG i,j;
00928 PWSTR serialFirmwareName;
00929 serialFirmwareName =
ExAllocatePool(
NonPagedPool,
sizeof(
USHORT)*10);
00930
if (!serialFirmwareName) {
00931
if (buffer)
00932
ExFreePool(buffer);
00933
if (firmwareEntry) {
00934
if (firmwareEntry->
Identifier)
00935
ExFreePool(firmwareEntry->
Identifier);
00936
ExFreePool(firmwareEntry);
00937 }
00938
return STATUS_INSUFFICIENT_RESOURCES;
00939 }
00940
for (
00941 i = 0;
00942 i < controllerData->PartialResourceList.Count;
00943 i++
00944 ) {
00945 PCM_PARTIAL_RESOURCE_DESCRIPTOR partial =
00946 &controllerData->PartialResourceList.PartialDescriptors[i];
00947
00948
if (partial->Type == CmResourceTypeDeviceSpecific) {
00949 PCM_SERIAL_DEVICE_DATA sDeviceData;
00950
00951 sDeviceData = (PCM_SERIAL_DEVICE_DATA)(partial + 1);
00952
00953 swprintf(serialFirmwareName,
L"*nEC%04X\0", sDeviceData->Revision);
00954 j = 0;
00955
while (
SerialIdNEC[j]) {
00956
if (!wcscmp(serialFirmwareName,
SerialIdNEC[j])) {
00957 firmwareEntry->
PnPId =
SerialIdNEC[j];
00958 }
00959 j++;
00960 }
00961 }
00962
00963 }
00964
ExFreePool(serialFirmwareName);
00965
break;
00966 }
00967
case ParallelController:
00968 firmwareEntry->
PnPId =
ParallelIdNEC;
00969
break;
00970
default:
00971
break;
00972 }
00973 }
00974
00975
DebugPrint((MAPPER_PNP_ID,
00976
"Mapper: constructed name %d_%d_%d_%d_%d_%d\n",
00977 firmwareEntry->
BusType,
00978 firmwareEntry->
BusNumber,
00979 firmwareEntry->
ControllerType,
00980 firmwareEntry->
ControllerNumber,
00981 firmwareEntry->
PeripheralType,
00982 firmwareEntry->
PeripheralNumber));
00983
00984
if (firmwareEntry->
PnPId) {
00985
00986
00987
00988
00989
00990 firmwareEntry->
Next = deviceExtension->
FirmwareList;
00991 deviceExtension->
FirmwareList = firmwareEntry;
00992 }
else {
00993
00994
00995
00996
00997
00998
ExFreePool(buffer);
00999
if(firmwareEntry->
Identifier) {
01000
ExFreePool(firmwareEntry->
Identifier);
01001 }
01002
ExFreePool(firmwareEntry);
01003 }
01004
return STATUS_SUCCESS;
01005 }
01006
01007
01008
VOID
01009 MapperProcessFirmwareTree(
01010 IN BOOLEAN OnlyProcessSerialPorts
01011 )
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035 {
01036 INTERFACE_TYPE interfaceType;
01037 ULONG index;
01038
CONFIGURATION_TYPE sc;
01039
CONFIGURATION_TYPE controllerTypes[] = {
PointerController,
01040
KeyboardController,
01041
ParallelController,
01042
DiskController,
01043
FloppyDiskPeripheral,
01044
SerialController
01045 };
01046
#define CONTROLLER_TYPES_COUNT (sizeof(controllerTypes) / sizeof(controllerTypes[0]))
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
for (interfaceType = 0; interfaceType < MaximumInterfaceType; interfaceType++) {
01057
01058
DebugPrint((MAPPER_VERBOSE,
01059
"Mapper: searching on interface ===> %d\n",
01060 interfaceType));
01061
01062
if(OnlyProcessSerialPorts) {
01063
01064
01065
01066
01067
01068
01069 index =
CONTROLLER_TYPES_COUNT - 1;
01070 }
else {
01071 index = 0;
01072 }
01073
01074
for ( ; index <
CONTROLLER_TYPES_COUNT; index++) {
01075 sc = controllerTypes[index];
01076
01077
IoQueryDeviceDescription(&interfaceType,
01078
NULL,
01079 &sc,
01080
NULL,
01081
NULL,
01082
NULL,
01083
MapperCallback,
01084 &
MapperDeviceExtension);
01085 }
01086 }
01087 }
01088
01089
01090
VOID
01091 MapperMarkKey(
01092 IN HANDLE Handle,
01093 IN PUNICODE_STRING PathName,
01094 IN PFIRMWARE_CONFIGURATION FirmwareEntry
01095 )
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116 {
01117 OBJECT_ATTRIBUTES objectAttributes;
01118 PCM_RESOURCE_LIST resourceList;
01119 UNICODE_STRING unicodeName;
01120
NTSTATUS status;
01121 HANDLE subKeyHandle;
01122 PWCHAR wcptr;
01123 ULONG disposition;
01124 ULONG buffer;
01125
USHORT originalLength;
01126
01127
01128
01129
01130
01131 buffer = 1;
01132
RtlInitUnicodeString(&unicodeName, REGSTR_VAL_FIRMWAREIDENTIFIED);
01133
01134 ZwSetValueKey(
Handle,
01135 &unicodeName,
01136 0,
01137 REG_DWORD,
01138 &buffer,
01139
sizeof(ULONG));
01140
01141
01142
01143
01144
01145
DebugPrint((MAPPER_INFORMATION,
01146
"Mapper: marking existing key\n"));
01147 originalLength = PathName->Length;
01148 wcptr = (PWCHAR) ((PUCHAR)PathName->Buffer + PathName->Length);
01149 wcptr++;
01150
01151
01152
01153
01154
01155 InitializeObjectAttributes(&objectAttributes,
01156 PathName,
01157 OBJ_CASE_INSENSITIVE,
01158
NULL,
01159
NULL);
01160
RtlAppendUnicodeToString(PathName,
L"\\Control");
01161 status = ZwCreateKey(&subKeyHandle,
01162 KEY_READ | KEY_WRITE,
01163 &objectAttributes,
01164 0,
01165
NULL,
01166 REG_OPTION_VOLATILE,
01167 &disposition);
01168
01169
if (
NT_SUCCESS(status)) {
01170
01171
01172
01173
01174
01175 buffer = 1;
01176
RtlInitUnicodeString(&unicodeName, REGSTR_VAL_FIRMWAREMEMBER);
01177
01178 ZwSetValueKey(subKeyHandle,
01179 &unicodeName,
01180 0,
01181 REG_DWORD,
01182 &buffer,
01183
sizeof(ULONG));
01184 ZwClose(subKeyHandle);
01185
01186 }
else {
01187
01188
01189
01190
01191
01192
DebugPrint((MAPPER_ERROR,
01193
"Mapper: failed to mark control key %x\n",
01194 status));
01195 }
01196
01197
01198
01199
01200
01201
if (FirmwareEntry->ResourceDescriptor) {
01202 PathName->Length = originalLength;
01203 *wcptr = (WCHAR) 0;
01204
01205 InitializeObjectAttributes(&objectAttributes,
01206 PathName,
01207 OBJ_CASE_INSENSITIVE,
01208
NULL,
01209
NULL);
01210
RtlAppendUnicodeToString(PathName,
L"\\LogConf");
01211 status = ZwCreateKey(&subKeyHandle,
01212 KEY_READ | KEY_WRITE,
01213 &objectAttributes,
01214 0,
01215
NULL,
01216 REG_OPTION_VOLATILE,
01217 &disposition);
01218
01219
if (
NT_SUCCESS(status)) {
01220 ULONG size;
01221
01222
01223
01224
01225
01226
01227
01228 size =
sizeof(CM_RESOURCE_LIST) -
01229
sizeof(CM_FULL_RESOURCE_DESCRIPTOR) +
01230 FirmwareEntry->ResourceDescriptorSize;
01231
01232 resourceList =
ExAllocatePool(
NonPagedPool, size);
01233
01234
if (resourceList) {
01235 PIO_RESOURCE_REQUIREMENTS_LIST reqList;
01236
01237 resourceList->Count = 1;
01238 RtlMoveMemory(&resourceList->List[0],
01239 FirmwareEntry->ResourceDescriptor,
01240 FirmwareEntry->ResourceDescriptorSize);
01241
01242 resourceList =
MapperAdjustResourceList (
01243 resourceList,
01244 FirmwareEntry->PnPId,
01245 &size
01246 );
01247
01248
RtlInitUnicodeString(&unicodeName,
01249
L"BootConfig");
01250 ZwSetValueKey(subKeyHandle,
01251 &unicodeName,
01252 0,
01253 REG_RESOURCE_LIST,
01254 resourceList,
01255 size);
01256
#if 0
01257
01258
01259
01260
01261 reqList =
IopCmResourcesToIoResources(0, resourceList);
01262
01263
if (reqList) {
01264
RtlInitUnicodeString(&unicodeName,
01265
L"BasicConfigVector");
01266 ZwSetValueKey(subKeyHandle,
01267 &unicodeName,
01268 0,
01269 REG_RESOURCE_REQUIREMENTS_LIST,
01270 reqList,
01271 reqList->ListSize);
01272
ExFreePool(reqList);
01273 }
01274
#endif
01275
ExFreePool(resourceList);
01276 }
01277 }
else {
01278
01279
01280
01281
01282
01283
DebugPrint((MAPPER_ERROR,
01284
"Mapper: failed to update logconf key %x\n",
01285 status));
01286 }
01287 }
01288
01289
01290
01291
01292
01293 PathName->Length = originalLength;
01294 *wcptr = (WCHAR) 0;
01295 }
01296
01297
VOID
01298 MapperSeedKey(
01299 IN HANDLE Handle,
01300 IN PUNICODE_STRING PathName,
01301 IN PFIRMWARE_CONFIGURATION FirmwareEntry,
01302 IN BOOLEAN DeviceIsPhantom
01303 )
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330 {
01331
#define SEED_BUFFER_SIZE (512 * sizeof(WCHAR))
01332
UNICODE_STRING unicodeName;
01333 UNICODE_STRING unicodeValue;
01334 OBJECT_ATTRIBUTES objectAttributes;
01335
PMAPPER_SEED valueSeed;
01336
PKEY_SEED keySeed;
01337
NTSTATUS status;
01338 HANDLE subKeyHandle;
01339 PWCHAR pnpid;
01340 PWCHAR buffer;
01341 PWCHAR wcptr;
01342 ULONG disposition;
01343 ULONG size;
01344
USHORT originalLength;
01345
01346 buffer =
ExAllocatePool(
NonPagedPool,
SEED_BUFFER_SIZE);
01347
if (!buffer) {
01348
return;
01349 }
01350 RtlZeroMemory(buffer,
SEED_BUFFER_SIZE);
01351
01352
01353
01354
01355
01356 originalLength = PathName->Length;
01357 wcptr = (PWCHAR) ((PUCHAR)PathName->Buffer + PathName->Length);
01358
01359
for (keySeed =
MapperKeySeed; keySeed->
KeyName; keySeed++) {
01360
01361
01362
01363
01364
01365 *wcptr = (WCHAR) 0;
01366 PathName->Length = originalLength;
01367
RtlAppendUnicodeToString(PathName, keySeed->
KeyName);
01368
01369
01370
01371
01372
01373
01374
if (keySeed->
Options &
KEY_SEED_DEVICE_PARAMETERS) {
01375
if (((FirmwareEntry->ControllerType !=
SerialController) && (FirmwareEntry->ControllerType !=
ParallelController)) ||
01376 !FirmwareEntry->Identifier) {
01377
continue;
01378 }
01379
01380 status =
IopOpenDeviceParametersSubkey( &subKeyHandle,
01381
NULL,
01382 PathName,
01383 KEY_READ | KEY_WRITE
01384 );
01385
if (
NT_SUCCESS(status)) {
01386 status = STATUS_SUCCESS;
01387 }
else {
01388 status = STATUS_UNSUCCESSFUL;
01389 }
01390 }
else {
01391
01392
01393
01394
01395
01396 InitializeObjectAttributes(&objectAttributes,
01397 PathName,
01398 OBJ_CASE_INSENSITIVE,
01399
NULL,
01400
NULL);
01401 status = ZwCreateKey(&subKeyHandle,
01402 KEY_READ | KEY_WRITE,
01403 &objectAttributes,
01404 0,
01405
NULL,
01406 keySeed->
Attribute,
01407 &disposition);
01408 }
01409
01410
if (
NT_SUCCESS(status)) {
01411
01412
01413
01414
01415
01416
01417
if (keySeed->
Options &
KEY_SEED_DEVICE_PARAMETERS) {
01418
01419
if (FirmwareEntry->ControllerType ==
SerialController) {
01420
01421
ComPortDBAdd(subKeyHandle, (PWSTR)FirmwareEntry->Identifier);
01422 }
else {
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
RtlInitUnicodeString(&unicodeName,
01433
L"PortName");
01434 ZwSetValueKey(subKeyHandle,
01435 &unicodeName,
01436 0,
01437 FirmwareEntry->IdentifierType,
01438 FirmwareEntry->Identifier,
01439 FirmwareEntry->IdentifierLength);
01440 }
01441 }
01442 ZwClose(subKeyHandle);
01443 }
else {
01444
01445
01446
01447
01448
01449
DebugPrint((MAPPER_ERROR,
01450
"Mapper: failed to build control key %x\n",
01451 status));
01452 }
01453 }
01454
01455
01456
01457
01458
01459 *wcptr = (WCHAR) 0;
01460 PathName->Length = originalLength;
01461
01462
01463
01464
01465
01466 pnpid = FirmwareEntry->PnPId;
01467
for (valueSeed =
MapperValueSeed; valueSeed->
ValueName; valueSeed++) {
01468
01469
if (valueSeed->
ValueType == REG_DWORD) {
01470
01471
if ((valueSeed->
Options ==
OPTIONS_INSERT_PHANTOM_MARKER) &&
01472 !DeviceIsPhantom) {
01473
01474
01475
01476
01477
01478
continue;
01479 }
01480
01481 size =
sizeof(ULONG);
01482 RtlMoveMemory(buffer, &valueSeed->
DwordValueContent, size);
01483
01484 }
else if (valueSeed->
Options ==
OPTIONS_INSERT_PNP_ID) {
01485
01486 size = (wcslen(pnpid) + 2) *
sizeof(WCHAR);
01487
if (FirmwareEntry->BusType == Eisa) {
01488
01489
01490
01491
01492
01493 RtlZeroMemory(buffer,
SEED_BUFFER_SIZE);
01494 wcptr = pnpid;
01495 wcptr++;
01496 swprintf(buffer,
L"EISA\\%s", wcptr);
01497
01498 wcptr = buffer;
01499
while (*wcptr) {
01500 wcptr++;
01501 }
01502 wcptr++;
01503
01504 RtlMoveMemory(wcptr, pnpid, size);
01505
01506 size += (ULONG)((PUCHAR)wcptr - (PUCHAR)buffer);
01507 }
else {
01508 RtlMoveMemory(buffer, pnpid, size -
sizeof(WCHAR));
01509 buffer[size /
sizeof(WCHAR) - 1] =
L'\0';
01510 }
01511 }
else if (valueSeed->
Options ==
OPTIONS_INSERT_COMPATIBLE_IDS) {
01512
if (FirmwareEntry->PeripheralType ==
KeyboardPeripheral) {
01513 size =
sizeof(
PS2_KEYBOARD_COMPATIBLE_ID);
01514 RtlMoveMemory(buffer,
PS2_KEYBOARD_COMPATIBLE_ID, size);
01515 }
else if (FirmwareEntry->PeripheralType ==
PointerPeripheral &&
01516 (wcscmp(pnpid,
L"*PNP0F0E") == 0 ||
01517 wcscmp(pnpid,
L"*PNP0F03") == 0 ||
01518 wcscmp(pnpid,
L"*PNP0F12") == 0)) {
01519 size =
sizeof(
PS2_MOUSE_COMPATIBLE_ID);
01520 RtlMoveMemory(buffer,
PS2_MOUSE_COMPATIBLE_ID, size);
01521 }
else {
01522
continue;
01523 }
01524 buffer[size / 2] =
L'\0';
01525 size +=
sizeof(
L'\0');
01526 }
else if (valueSeed->
Options ==
OPTIONS_INSERT_DEVICEDESC) {
01527 size = FirmwareEntry->IdentifierLength;
01528 RtlMoveMemory(buffer, FirmwareEntry->Identifier, size);
01529 }
else {
01530
DebugPrint((MAPPER_ERROR,
"Mapper: NO VALUE TYPE!\n"));
01531
ASSERT(
FALSE);
01532
continue;
01533 }
01534
01535
RtlInitUnicodeString(&unicodeName,
01536 valueSeed->
ValueName);
01537 ZwSetValueKey(
Handle,
01538 &unicodeName,
01539 0,
01540 valueSeed->
ValueType,
01541 buffer,
01542 size);
01543 }
01544
ExFreePool(buffer);
01545 }
01546
01547
01548
VOID
01549 MapperFreeList(
01550 VOID
01551 )
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570 {
01571
PDEVICE_EXTENSION deviceExtension = &
MapperDeviceExtension;
01572
PFIRMWARE_CONFIGURATION tempEntry;
01573
PFIRMWARE_CONFIGURATION firmwareEntry;
01574
01575 firmwareEntry = deviceExtension->
FirmwareList;
01576
while (firmwareEntry) {
01577
01578
01579
01580
01581
01582
if (firmwareEntry->
ResourceDescriptor) {
01583
ExFreePool(firmwareEntry->
ResourceDescriptor);
01584 }
01585
if (firmwareEntry->
Identifier) {
01586
ExFreePool(firmwareEntry->
Identifier);
01587 }
01588
01589
01590
01591
01592
01593 tempEntry = firmwareEntry->
Next;
01594
ExFreePool(firmwareEntry);
01595 firmwareEntry = tempEntry;
01596 }
01597 }
01598
01599
VOID
01600 MapperConstructRootEnumTree(
01601 IN BOOLEAN CreatePhantomDevices
01602 )
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628 {
01629
#define ENUM_KEY_BUFFER_SIZE (1024 * sizeof(WCHAR))
01630
#define INSTANCE_BUFFER_SIZE (256 * sizeof(WCHAR))
01631
UNICODE_STRING enumKey;
01632
PFIRMWARE_CONFIGURATION firmwareEntry;
01633 OBJECT_ATTRIBUTES objectAttributes;
01634
NTSTATUS status;
01635 BOOLEAN keyPresent;
01636 PWCHAR registryBase;
01637 PWCHAR instanceBuffer;
01638 HANDLE handle;
01639 ULONG disposition;
01640 PVOID buffer;
01641
PDEVICE_EXTENSION DeviceExtension = &
MapperDeviceExtension;
01642
01643
01644
01645
01646
01647
01648 buffer =
ExAllocatePool(
NonPagedPool,
ENUM_KEY_BUFFER_SIZE);
01649
01650
if (!buffer) {
01651
MapperFreeList();
01652
DebugPrint((MAPPER_ERROR,
01653
"Mapper: could not allocate memory for registry update\n"));
01654
return;
01655 }
01656
01657 instanceBuffer =
ExAllocatePool(
NonPagedPool,
INSTANCE_BUFFER_SIZE);
01658
if (!instanceBuffer) {
01659
MapperFreeList();
01660
ExFreePool(buffer);
01661
DebugPrint((MAPPER_ERROR,
01662
"Mapper: could not allocate memory for instance buffer\n"));
01663
return;
01664 }
01665
01666 InitializeObjectAttributes(&objectAttributes,
01667 &enumKey,
01668 OBJ_CASE_INSENSITIVE,
01669
NULL,
01670
NULL);
01671
01672
#if UMODETEST
01673
registryBase =
L"\\Registry\\Machine\\System\\TestControlSet\\Enum\\Root\\";
01674
#else
01675
registryBase =
L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\Root\\";
01676
#endif
01677
01678 firmwareEntry = DeviceExtension->
FirmwareList;
01679
while (firmwareEntry) {
01680
01681
01682
01683
01684
01685
01686
RtlInitUnicodeString(&enumKey,
NULL);
01687 enumKey.MaximumLength =
ENUM_KEY_BUFFER_SIZE;
01688 enumKey.Buffer = buffer;
01689 RtlZeroMemory(buffer,
ENUM_KEY_BUFFER_SIZE);
01690
RtlAppendUnicodeToString(&enumKey, registryBase);
01691
RtlAppendUnicodeToString(&enumKey, firmwareEntry->
PnPId);
01692
01693
01694
01695
01696
01697 status = ZwCreateKey(&handle,
01698 KEY_READ | KEY_WRITE,
01699 &objectAttributes,
01700 0,
01701
NULL,
01702 REG_OPTION_NON_VOLATILE,
01703 &disposition);
01704
01705
if (
NT_SUCCESS(status)) {
01706
01707
01708
01709
01710
01711
01712 ZwClose(handle);
01713 keyPresent = (disposition == REG_OPENED_EXISTING_KEY) ?
TRUE :
FALSE;
01714
DebugPrint((MAPPER_INFORMATION,
01715
"Mapper: Key was %s\n",
01716 keyPresent ?
"Present" :
"Created"));
01717
01718
01719
01720
01721
01722 RtlZeroMemory(instanceBuffer,
INSTANCE_BUFFER_SIZE);
01723 swprintf(instanceBuffer,
01724
L"\\%d_%d_%d_%d_%d_%d",
01725 firmwareEntry->
BusType,
01726 firmwareEntry->
BusNumber,
01727 firmwareEntry->
ControllerType,
01728 firmwareEntry->
ControllerNumber,
01729 firmwareEntry->
PeripheralType,
01730 firmwareEntry->
PeripheralNumber);
01731
RtlAppendUnicodeToString(&enumKey, instanceBuffer);
01732
01733 status = ZwCreateKey(&handle,
01734 KEY_READ | KEY_WRITE,
01735 &objectAttributes,
01736 0,
01737
NULL,
01738 REG_OPTION_NON_VOLATILE,
01739 &disposition);
01740
01741
if (
NT_SUCCESS(status)) {
01742
01743
if (firmwareEntry->
ResourceDescriptor) {
01744
DebugPrint((MAPPER_INFORMATION,
01745
"Mapper: firmware entry has resources %x\n",
01746 firmwareEntry->
ResourceDescriptor));
01747 }
01748
01749
if (firmwareEntry->
Identifier) {
01750
DebugPrint((MAPPER_INFORMATION,
01751
"Mapper: firmware entry has identifier %x\n",
01752 firmwareEntry->
Identifier));
01753 }
01754
01755
01756
01757
01758
01759
if (disposition == REG_CREATED_NEW_KEY) {
01760
01761
01762
01763
01764
01765
01766
01767 firmwareEntry->
NewlyCreated =
TRUE;
01768
01769
01770
01771
01772
01773
01774
MapperSeedKey(handle,
01775 &enumKey,
01776 firmwareEntry,
01777 CreatePhantomDevices
01778 );
01779 }
01780
MapperMarkKey(handle,
01781 &enumKey,
01782 firmwareEntry);
01783 ZwClose(handle);
01784
01785 }
else {
01786
DebugPrint((MAPPER_ERROR,
01787
"Mapper: create of instance key failed %x\n",
01788 status));
01789 }
01790
01791 }
else {
01792
DebugPrint((MAPPER_ERROR,
01793
"Mapper: create pnp key failed %x\n",
01794 status));
01795 }
01796
01797 firmwareEntry = firmwareEntry->
Next;
01798 }
01799
ExFreePool(instanceBuffer);
01800 }
01801
01802 PCM_RESOURCE_LIST
01803 MapperAdjustResourceList (
01804 IN PCM_RESOURCE_LIST ResourceList,
01805 IN PWCHAR PnPId,
01806 IN OUT PULONG Size
01807 )
01808 {
01809 PCM_PARTIAL_RESOURCE_LIST partialResourceList;
01810 PCM_PARTIAL_RESOURCE_DESCRIPTOR problemPartialDescriptors;
01811 PCM_PARTIAL_RESOURCE_DESCRIPTOR partialDescriptors;
01812 PCM_RESOURCE_LIST newResourceList;
01813 ULONG i;
01814
01815 newResourceList = ResourceList;
01816
01817
#if _X86_
01818
if (
KeI386MachineType == MACHINE_TYPE_EISA) {
01819
01820 PCM_FULL_RESOURCE_DESCRIPTOR fullDescriptor;
01821 PCM_PARTIAL_RESOURCE_DESCRIPTOR partialDescriptor;
01822 PUCHAR nextDescriptor;
01823 ULONG j;
01824 ULONG lastResourceIndex;
01825
01826 fullDescriptor = &ResourceList->List[0];
01827
01828
for (i = 0; i < ResourceList->Count; i++) {
01829
01830 partialResourceList = &fullDescriptor->PartialResourceList;
01831
01832
for (j = 0; j < partialResourceList->Count; j++) {
01833 partialDescriptor = &partialResourceList->PartialDescriptors[j];
01834
01835
if (partialDescriptor->Type == CmResourceTypePort) {
01836
if (partialDescriptor->u.Port.Start.HighPart == 0 &&
01837 (partialDescriptor->u.Port.Start.LowPart & 0x00000300) == 0) {
01838 partialDescriptor->Flags |= CM_RESOURCE_PORT_16_BIT_DECODE;
01839 }
01840 }
01841 }
01842
01843 nextDescriptor = (PUCHAR)fullDescriptor +
sizeof(CM_FULL_RESOURCE_DESCRIPTOR);
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
if (partialResourceList->Count > 0) {
01856
01857 nextDescriptor += (partialResourceList->Count - 1) *
01858
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
01859
01860 lastResourceIndex = partialResourceList->Count - 1;
01861
01862
if (partialResourceList->PartialDescriptors[lastResourceIndex].Type ==
01863 CmResourceTypeDeviceSpecific) {
01864
01865 nextDescriptor += partialResourceList->PartialDescriptors[lastResourceIndex].
01866 u.DeviceSpecificData.DataSize;
01867 }
01868 }
01869
01870 fullDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR)nextDescriptor;
01871 }
01872 }
01873
#endif
01874
01875
if (wcscmp(PnPId,
FloppyId) == 0) {
01876
01877
if (ResourceList->Count == 1) {
01878
01879 partialResourceList = &ResourceList->List->PartialResourceList;
01880
01881 partialDescriptors = partialResourceList->PartialDescriptors;
01882
01883
01884
01885
01886 problemPartialDescriptors =
NULL;
01887
for (i=0; i<partialResourceList->Count; i++) {
01888
01889
if ((partialDescriptors[i].Type == CmResourceTypePort) &&
01890 (partialDescriptors[i].u.Port.Length == 8)) {
01891
01892
if (problemPartialDescriptors ==
NULL) {
01893
01894 problemPartialDescriptors = partialDescriptors + i;
01895 }
else {
01896
01897 problemPartialDescriptors =
NULL;
01898
break;
01899 }
01900 }
01901 }
01902
01903
if (problemPartialDescriptors) {
01904
01905 problemPartialDescriptors->u.Port.Length = 6;
01906
01907 newResourceList =
ExAllocatePool (
01908
NonPagedPool,
01909 *
Size +
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)
01910 );
01911
if (newResourceList) {
01912
01913 RtlMoveMemory (
01914 newResourceList,
01915 ResourceList,
01916 *
Size
01917 );
01918
01919
01920
01921
01922 partialDescriptors = newResourceList->List->
01923 PartialResourceList.PartialDescriptors;
01924 partialDescriptors += newResourceList->List->PartialResourceList.Count;
01925
01926 RtlMoveMemory (
01927 partialDescriptors,
01928 problemPartialDescriptors,
01929
sizeof(*partialDescriptors)
01930 );
01931
01932 partialDescriptors->u.Port.Start.QuadPart += 7;
01933 partialDescriptors->u.Port.Length = 1;
01934
01935
01936
01937
01938 newResourceList->List->PartialResourceList.Count++;
01939 *
Size +=
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
01940
01941
ExFreePool (ResourceList);
01942
01943 }
else {
01944
01945 newResourceList = ResourceList;
01946 }
01947 }
01948 }
01949 }
01950
01951
return newResourceList;
01952 }
01953
01954
NTSTATUS
01955 ComPortDBAdd(
01956 IN HANDLE DeviceParamKey,
01957 IN PWSTR PortName
01958 )
01959 {
01960 UNICODE_STRING portNameString;
01961 UNICODE_STRING portPrefixString;
01962 UNICODE_STRING comDBName;
01963 UNICODE_STRING valueName;
01964 PKEY_VALUE_PARTIAL_INFORMATION valueInfo;
01965 ULONG valueInfoLength;
01966 ULONG returnedLength;
01967 HANDLE comDBKey;
01968 ULONG portNo;
01969
NTSTATUS status;
01970
01971
RtlInitUnicodeString(&portNameString,
PortName);
01972
01973
if (portNameString.Length > 3 *
sizeof(WCHAR)) {
01974 portNameString.Length = 3 *
sizeof(WCHAR);
01975 }
01976
01977
RtlInitUnicodeString(&portPrefixString,
L"COM");
01978
01979
if (
RtlCompareUnicodeString(&portNameString, &portPrefixString,
TRUE) == 0) {
01980 portNo = _wtol(&
PortName[3]);
01981
01982
if (portNo > 0 && portNo <= 256) {
01983
01984
#if UMODETEST
01985
RtlInitUnicodeString(&comDBName,
L"\\Registry\\Machine\\System\\TestControlSet\\Control\\COM Name Arbiter");
01986
#else
01987
RtlInitUnicodeString(&comDBName,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\COM Name Arbiter");
01988
#endif
01989
01990 status =
IopCreateRegistryKeyEx( &comDBKey,
01991
NULL,
01992 &comDBName,
01993 KEY_ALL_ACCESS,
01994 REG_OPTION_NON_VOLATILE,
01995
NULL
01996 );
01997
01998
if (
NT_SUCCESS(status)) {
01999
02000
RtlInitUnicodeString(&valueName,
L"ComDB Merge");
02001
02002
#define COMPORT_DB_MERGE_SIZE 32 // 256 / 8
02003
02004 valueInfoLength =
sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
COMPORT_DB_MERGE_SIZE;
02005 valueInfo =
ExAllocatePool(
PagedPool, valueInfoLength);
02006
02007
if (valueInfo !=
NULL) {
02008
02009 status = ZwQueryValueKey( comDBKey,
02010 &valueName,
02011 KeyValuePartialInformation,
02012 valueInfo,
02013 valueInfoLength,
02014 &returnedLength);
02015
02016
if (status == STATUS_OBJECT_NAME_NOT_FOUND) {
02017
02018 valueInfo->Type = REG_BINARY;
02019 valueInfo->DataLength =
COMPORT_DB_MERGE_SIZE;
02020 RtlZeroMemory(valueInfo->Data, valueInfo->DataLength);
02021 status = STATUS_SUCCESS;
02022 }
02023
02024
if (
NT_SUCCESS(status)) {
02025 portNo--;
02026 valueInfo->Data[ portNo / 8 ] |= 1 << (portNo % 8);
02027
02028 status = ZwSetValueKey( comDBKey,
02029 &valueName,
02030 0,
02031 valueInfo->Type,
02032 valueInfo->Data,
02033 valueInfo->DataLength );
02034
02035
ASSERT(
NT_SUCCESS(status));
02036 }
02037
02038
ExFreePool(valueInfo);
02039 }
02040
02041 ZwClose(comDBKey);
02042 }
02043 }
02044 }
02045
02046
RtlInitUnicodeString( &valueName,
L"PortName" );
02047
02048 status = ZwSetValueKey( DeviceParamKey,
02049 &valueName,
02050 0,
02051 REG_SZ,
02052
PortName,
02053 (wcslen(
PortName) + 1) *
sizeof(WCHAR) );
02054
02055
return status;
02056 }
02057
02058
02059
VOID
02060 MapperPhantomizeDetectedComPorts (
02061 VOID
02062 )
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079 {
02080
PFIRMWARE_CONFIGURATION firmwareEntry;
02081
NTSTATUS status;
02082 PWCHAR registryBase;
02083 PWCHAR instanceBuffer;
02084 HANDLE handle;
02085 PWCHAR buffer;
02086
PDEVICE_EXTENSION DeviceExtension = &
MapperDeviceExtension;
02087 UNICODE_STRING enumKey;
02088 OBJECT_ATTRIBUTES objectAttributes;
02089 UNICODE_STRING unicodeName;
02090 ULONG
regValue;
02091
02092
02093
02094
02095
02096
02097 buffer =
ExAllocatePool(
NonPagedPool,
ENUM_KEY_BUFFER_SIZE);
02098
02099
if (!buffer) {
02100
DebugPrint((MAPPER_ERROR,
02101
"Mapper: could not allocate memory for registry update\n"));
02102
return;
02103 }
02104
02105 instanceBuffer =
ExAllocatePool(
NonPagedPool,
INSTANCE_BUFFER_SIZE);
02106
if (!instanceBuffer) {
02107
ExFreePool(buffer);
02108
DebugPrint((MAPPER_ERROR,
02109
"Mapper: could not allocate memory for instance buffer\n"));
02110
return;
02111 }
02112
02113 InitializeObjectAttributes(&objectAttributes,
02114 &enumKey,
02115 OBJ_CASE_INSENSITIVE,
02116
NULL,
02117
NULL);
02118
02119
#if UMODETEST
02120
registryBase =
L"\\Registry\\Machine\\System\\TestControlSet\\Enum\\Root\\";
02121
#else
02122
registryBase =
L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\Root\\";
02123
#endif
02124
02125 firmwareEntry = DeviceExtension->
FirmwareList;
02126
while (firmwareEntry) {
02127
02128
02129
02130
02131
02132
02133
if ((firmwareEntry->
ControllerType ==
SerialController) &&
02134 firmwareEntry->
NewlyCreated) {
02135
02136
RtlInitUnicodeString(&enumKey,
NULL);
02137 enumKey.MaximumLength =
ENUM_KEY_BUFFER_SIZE;
02138 enumKey.Buffer = buffer;
02139 RtlZeroMemory(buffer,
ENUM_KEY_BUFFER_SIZE);
02140
RtlAppendUnicodeToString(&enumKey, registryBase);
02141
RtlAppendUnicodeToString(&enumKey, firmwareEntry->
PnPId);
02142
02143
02144
02145
02146
02147 RtlZeroMemory(instanceBuffer,
INSTANCE_BUFFER_SIZE);
02148 swprintf(instanceBuffer,
02149
L"\\%d_%d_%d_%d_%d_%d",
02150 firmwareEntry->
BusType,
02151 firmwareEntry->
BusNumber,
02152 firmwareEntry->
ControllerType,
02153 firmwareEntry->
ControllerNumber,
02154 firmwareEntry->
PeripheralType,
02155 firmwareEntry->
PeripheralNumber);
02156
RtlAppendUnicodeToString(&enumKey, instanceBuffer);
02157
02158 status = ZwOpenKey(&handle,
02159 KEY_READ | KEY_WRITE,
02160 &objectAttributes
02161 );
02162
02163
if (
NT_SUCCESS(status)) {
02164
02165
RtlInitUnicodeString(&unicodeName, REGSTR_VAL_PHANTOM);
02166
regValue = 1;
02167 ZwSetValueKey(handle,
02168 &unicodeName,
02169 0,
02170 REG_DWORD,
02171 &
regValue,
02172
sizeof(
regValue)
02173 );
02174
02175 ZwClose(handle);
02176 }
02177 }
02178
02179 firmwareEntry = firmwareEntry->
Next;
02180 }
02181
02182
ExFreePool (buffer);
02183
ExFreePool (instanceBuffer);
02184 }
02185
02186
02187
#if DBG
02188
VOID
02189 MapperDebugPrint(
02190 ULONG DebugMask,
02191 PCCHAR DebugMessage,
02192 ...
02193 )
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211 {
02212 va_list ap;
02213
CHAR buffer[256];
02214
02215 va_start(ap, DebugMessage);
02216
02217
if (DebugMask & MapperDebugMask) {
02218 vsprintf(buffer, DebugMessage, ap);
02219
DbgPrint(buffer);
02220 }
02221
02222 va_end(ap);
02223
02224 }
02225
#endif
02226
02227