Leaked source code of windows server 2003
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.

176 lines
5.7 KiB

  1. /** FILE: cyfriend.c ********** Module Header ********************************
  2. *
  3. *
  4. *
  5. * Copyright (C) 2000 Cyclades Corporation
  6. *
  7. *************************************************************************/
  8. #include "cyyports.h"
  9. //
  10. // For Cyyport
  11. //
  12. TCHAR y_szCyyPort[] = TEXT("Cyclom-Y Port ");
  13. TCHAR y_szPortIndex[] = TEXT("PortIndex");
  14. BOOL
  15. ReplaceFriendlyName(
  16. IN HDEVINFO DeviceInfoSet,
  17. IN PSP_DEVINFO_DATA DeviceInfoData,
  18. IN PTCHAR NewComName
  19. )
  20. {
  21. DEVINST parentInst;
  22. HDEVINFO parentInfo;
  23. SP_DEVINFO_DATA parentData;
  24. TCHAR parentId[MAX_DEVICE_ID_LEN];
  25. TCHAR charBuffer[MAX_PATH],
  26. deviceDesc[LINE_LEN];
  27. HKEY hDeviceKey;
  28. TCHAR PortName[20];
  29. DWORD PortNameSize,PortIndexSize,PortIndex;
  30. DWORD dwErr;
  31. PTCHAR comName = NULL;
  32. DWORD portNumber = 0;
  33. //DbgOut(TEXT("ReplaceFriendlyName\n"));
  34. if((hDeviceKey = SetupDiOpenDevRegKey(DeviceInfoSet,
  35. DeviceInfoData,
  36. DICS_FLAG_GLOBAL,
  37. 0,
  38. DIREG_DEV,
  39. KEY_READ)) == INVALID_HANDLE_VALUE) {
  40. DbgOut(TEXT("SetupDiOpenDevRegKey failed\n"));
  41. return FALSE;
  42. }
  43. PortNameSize = sizeof(PortName);
  44. dwErr = RegQueryValueEx(hDeviceKey,
  45. m_szPortName,
  46. NULL,
  47. NULL,
  48. (PBYTE)PortName,
  49. &PortNameSize
  50. );
  51. if (dwErr == ERROR_SUCCESS) {
  52. PortIndexSize = sizeof(PortIndex);
  53. dwErr = RegQueryValueEx(hDeviceKey,
  54. y_szPortIndex,
  55. NULL,
  56. NULL,
  57. (PBYTE)&PortIndex,
  58. &PortIndexSize
  59. );
  60. }
  61. RegCloseKey(hDeviceKey);
  62. if(dwErr != ERROR_SUCCESS) {
  63. DbgOut(TEXT("RegQueryValueEx failed\n"));
  64. return FALSE;
  65. }
  66. if (NewComName == NULL) {
  67. comName = PortName;
  68. } else {
  69. comName = NewComName;
  70. }
  71. if (comName == NULL) {
  72. DbgOut(TEXT("comName NULL\n"));
  73. return FALSE;
  74. }
  75. portNumber = PortIndex+1;
  76. if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
  77. DeviceInfoData,
  78. SPDRP_DEVICEDESC,
  79. NULL,
  80. (PBYTE)deviceDesc,
  81. sizeof(deviceDesc),
  82. NULL)) {
  83. DbgOut(TEXT("Couldn't get Device Description\n"));
  84. return FALSE;
  85. }
  86. if (_tcsnicmp (deviceDesc,y_szCyyPort,_tcslen(y_szCyyPort)) != 0){
  87. DbgOut(TEXT("Device Description is different of Cyclom-Y Port \n"));
  88. return FALSE;
  89. }
  90. if (portNumber == 0) {
  91. DbgOut(TEXT("Invalid portNumber\n"));
  92. return FALSE;
  93. }
  94. if (CM_Get_Parent(&parentInst,DeviceInfoData->DevInst,0) != CR_SUCCESS) {
  95. DbgOut(TEXT("CM_Get_Parent failed.\n"));
  96. return FALSE;
  97. }
  98. if (CM_Get_Device_ID(parentInst,parentId,CharSizeOf(parentId),0) != CR_SUCCESS) {
  99. DbgOut(TEXT("CM_Get_Device_ID failed.\n"));
  100. return FALSE;
  101. }
  102. parentInfo = SetupDiCreateDeviceInfoList(NULL,NULL);
  103. if (parentInfo == INVALID_HANDLE_VALUE) {
  104. DbgOut(TEXT("SetupDiCreateDeviceInfoList failed\n"));
  105. return FALSE;
  106. }
  107. parentData.cbSize = sizeof(SP_DEVINFO_DATA);
  108. if (SetupDiOpenDeviceInfo(parentInfo,parentId,NULL,0,&parentData)) {
  109. if (SetupDiGetDeviceRegistryProperty(parentInfo,
  110. &parentData,
  111. SPDRP_FRIENDLYNAME,
  112. NULL,
  113. (PBYTE)deviceDesc,
  114. sizeof(deviceDesc),
  115. NULL) ||
  116. SetupDiGetDeviceRegistryProperty(parentInfo,
  117. &parentData,
  118. SPDRP_DEVICEDESC,
  119. NULL,
  120. (PBYTE)deviceDesc,
  121. sizeof(deviceDesc),
  122. NULL)) {
  123. wsprintf(charBuffer,TEXT("%s Port %2u (%s)"),deviceDesc,portNumber,comName);
  124. // #if DBG
  125. // {
  126. // TCHAR buf[500];
  127. // wsprintf(buf, TEXT("%s\n"), charBuffer);
  128. // DbgOut(buf);
  129. // }
  130. // #endif
  131. SetupDiSetDeviceRegistryProperty(DeviceInfoSet,
  132. DeviceInfoData,
  133. SPDRP_FRIENDLYNAME,
  134. (PBYTE)charBuffer,
  135. ByteCountOf(_tcslen(charBuffer) + 1)
  136. );
  137. }
  138. } else {
  139. #if DBG
  140. {
  141. TCHAR buf[500];
  142. wsprintf(buf, TEXT("SetupDiOpenDeviceInfo failed with error %x\n"), GetLastError());
  143. DbgOut(buf);
  144. }
  145. #endif
  146. }
  147. SetupDiDestroyDeviceInfoList(parentInfo);
  148. return TRUE;
  149. }