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.

104 lines
2.9 KiB

  1. //
  2. // Broadbnd.cpp
  3. //
  4. // Code for keeping track of which NIC is the user's broadband NIC.
  5. // NOTE: this may be replaced by standard ICS APIs.
  6. //
  7. // History:
  8. //
  9. // 9/29/1999 KenSh Created from JetNet sources
  10. // 11/03/1999 KenSh Fixed so it uses proper registry keys
  11. //
  12. #include "stdafx.h"
  13. #include "NetConn.h"
  14. #include "nconnwrap.h"
  15. static const TCHAR c_szAppRegKey[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\HomeNetWizard");
  16. static const TCHAR c_szRegVal_Broadband[] = _T("BroadbandAdapter");
  17. // Did the user pick this adapter as their broadband connection either in Setup
  18. // or in the diagnostic app?
  19. BOOL WINAPI IsAdapterBroadband(const NETADAPTER* pAdapter)
  20. {
  21. CRegistry reg;
  22. if (!reg.OpenKey(HKEY_LOCAL_MACHINE, c_szAppRegKey, KEY_READ))
  23. {
  24. return (pAdapter->bIcsStatus == ICS_EXTERNAL);
  25. }
  26. if (pAdapter->bNicType == NIC_VIRTUAL || pAdapter->bNetType != NETTYPE_LAN)
  27. return FALSE; // not an ethernet NIC, therefore not broadband
  28. TCHAR szAdapterNumber[20];
  29. if (reg.QueryStringValue(c_szRegVal_Broadband, szAdapterNumber, _countof(szAdapterNumber)))
  30. {
  31. return (0 == lstrcmpi(FindFileTitle(pAdapter->szClassKey), szAdapterNumber));
  32. }
  33. else
  34. {
  35. return FALSE;
  36. }
  37. }
  38. // Saves info about the user's broadband selection into the registry
  39. // Adapter number is FindFileTitle(pAdapter->szClassKey)
  40. void WINAPI SaveBroadbandSettings(LPCSTR pszBroadbandAdapterNumber)
  41. {
  42. CRegistry reg;
  43. if (reg.CreateKey(HKEY_LOCAL_MACHINE, c_szAppRegKey))
  44. {
  45. // No high speed connection? then don't save one.
  46. if (pszBroadbandAdapterNumber == NULL || *pszBroadbandAdapterNumber == _T('\0'))
  47. {
  48. reg.DeleteValue(c_szRegVal_Broadband);
  49. }
  50. else
  51. {
  52. // Save the enum key of the NIC we want to use
  53. reg.SetStringValue(c_szRegVal_Broadband, pszBroadbandAdapterNumber);
  54. }
  55. }
  56. }
  57. #if 0 // old JetNet function not used by Home Networking Wizard
  58. // Loads current broadband settings from the registry, and updates the registry
  59. // if we now have more information about a recently installed broadband NIC
  60. BOOL WINAPI UpdateBroadbandSettings(LPTSTR pszEnumKeyBuf, int cchEnumKeyBuf)
  61. {
  62. ASSERT(pszEnumKeyBuf != NULL);
  63. *pszEnumKeyBuf = '\0';
  64. CRegistry reg;
  65. if (reg.OpenKey(HKEY_LOCAL_MACHINE, c_szBroadbandRegKey))
  66. {
  67. if (reg.QueryStringValue("BroadbandYes", pszEnumKeyBuf, cchEnumKeyBuf))
  68. goto done; // we already have a particular broadband NIC selected
  69. NETADAPTER* prgAdapters;
  70. int cAdapters = EnumNetAdapters(&prgAdapters);
  71. NETADAPTER* pBroadbandAdapter = NULL;
  72. for (int iAdapter = 0; iAdapter < cAdapters; iAdapter++)
  73. {
  74. NETADAPTER* pAdapter = &prgAdapters[iAdapter];
  75. if (IsAdapterBroadband(pAdapter))
  76. {
  77. pBroadbandAdapter = pAdapter;
  78. break;
  79. }
  80. }
  81. if (pBroadbandAdapter != NULL)
  82. {
  83. SaveBroadbandSettings(pBroadbandAdapter->szEnumKey);
  84. lstrcpyn(pszEnumKeyBuf, pBroadbandAdapter->szEnumKey, cchEnumKeyBuf);
  85. }
  86. NetConnFree(prgAdapters);
  87. }
  88. done:
  89. return (*pszEnumKeyBuf != '\0');
  90. }
  91. #endif // 0