Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 1994 - 1995 Microsoft Corporation
  3. Module Name:
  4. PnpId.c
  5. Abstract:
  6. Generate pnp hardware id from model manufacturer
  7. Author:
  8. Revision History:
  9. --*/
  10. #define NOMINMAX
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. WORD wCRC16a[16]={
  18. 0000000, 0140301, 0140601, 0000500,
  19. 0141401, 0001700, 0001200, 0141101,
  20. 0143001, 0003300, 0003600, 0143501,
  21. 0002400, 0142701, 0142201, 0002100,
  22. };
  23. WORD wCRC16b[16]={
  24. 0000000, 0146001, 0154001, 0012000,
  25. 0170001, 0036000, 0024000, 0162001,
  26. 0120001, 0066000, 0074000, 0132001,
  27. 0050000, 0116001, 0104001, 0043000,
  28. };
  29. //
  30. // From win95
  31. //
  32. #define MAX_DEVNODE_NAME_ROOT 20
  33. USHORT
  34. GetCheckSum(
  35. PBYTE ptr,
  36. ULONG ulSize
  37. )
  38. {
  39. BYTE byte;
  40. USHORT CS=0;
  41. for ( ; ulSize ; --ulSize, ++ptr) {
  42. byte = (BYTE)(((WORD)*ptr)^((WORD)CS)); // Xor CRC with new char
  43. CS = ((CS)>>8) ^ wCRC16a[byte&0x0F] ^ wCRC16b[byte>>4];
  44. }
  45. printf("Check sum: %04X\n", CS);
  46. return CS;
  47. }
  48. int
  49. #if !defined(_MIPS_) && !defined(_ALPHA_) && !defined(_PPC_)
  50. _cdecl
  51. #endif
  52. main (argc, argv)
  53. int argc;
  54. char *argv[];
  55. {
  56. TCHAR szHwId[100], szCheckSum[10],
  57. szDevNodeName[100], *p;
  58. USHORT usCheckSum;
  59. DWORD dwLastError, dwcbHardwareIDSize;
  60. if ( argc != 3 ) {
  61. printf("Usage: %s ""Manufacturer Name"" ""Model Name""\n", argv[0]);
  62. return 0;
  63. }
  64. lstrcpy(szHwId, argv[1]);
  65. lstrcat(szHwId, argv[2]);
  66. usCheckSum = GetCheckSum(szHwId, strlen(szHwId));
  67. sprintf( szCheckSum, "%04X", usCheckSum );
  68. dwcbHardwareIDSize = strlen(argv[1]) + strlen(argv[2]);
  69. if ( dwcbHardwareIDSize > MAX_DEVNODE_NAME_ROOT )
  70. dwcbHardwareIDSize = MAX_DEVNODE_NAME_ROOT;
  71. szHwId[dwcbHardwareIDSize] = TEXT('\0');
  72. for ( p = szHwId ; p = strchr(p, TEXT(' ')) ; )
  73. *p = TEXT('_');
  74. lstrcat(szHwId, szCheckSum);
  75. lstrcpy(szDevNodeName, TEXT("LPTENUM"));
  76. lstrcat(szDevNodeName, TEXT("\\"));
  77. lstrcat(szDevNodeName, szHwId);
  78. printf("Hardware Id : %s\n", szHwId);
  79. printf("Devnode name: %s\n", szDevNodeName);
  80. }