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.

130 lines
4.2 KiB

  1. #include <precomp.h>
  2. #include "eapolcfg.h"
  3. #include "wzcdata.h"
  4. ////////////////////////////////////////////////////////////////////////
  5. // CWZCConfig related stuff
  6. //
  7. //+---------------------------------------------------------------------------
  8. // constructor
  9. CWZCConfig::CWZCConfig(DWORD dwFlags, PWZC_WLAN_CONFIG pwzcConfig)
  10. {
  11. m_dwFlags = dwFlags;
  12. CopyMemory(&m_wzcConfig, pwzcConfig, sizeof(WZC_WLAN_CONFIG));
  13. m_pPrev = m_pNext = this;
  14. m_nListIndex = -1;
  15. m_pEapolConfig = NULL;
  16. }
  17. //+---------------------------------------------------------------------------
  18. // destructor
  19. CWZCConfig::~CWZCConfig()
  20. {
  21. // remove the object from the list
  22. m_pPrev->m_pNext = m_pNext;
  23. m_pNext->m_pPrev = m_pPrev;
  24. if (m_pEapolConfig != NULL)
  25. {
  26. delete m_pEapolConfig;
  27. m_pEapolConfig = NULL;
  28. }
  29. }
  30. //+---------------------------------------------------------------------------
  31. // checks whether this configuration matches with the one from pwzcConfig
  32. BOOL
  33. CWZCConfig::Match(PWZC_WLAN_CONFIG pwzcConfig)
  34. {
  35. BOOL bMatch;
  36. // check whether the InfrastructureMode matches
  37. bMatch = (m_wzcConfig.InfrastructureMode == pwzcConfig->InfrastructureMode);
  38. // check whether the SSIDs are of the same length
  39. bMatch = bMatch && (m_wzcConfig.Ssid.SsidLength == pwzcConfig->Ssid.SsidLength);
  40. if (bMatch && m_wzcConfig.Ssid.SsidLength != 0)
  41. {
  42. // in case of Non empty SSIDs, check if they're the same
  43. bMatch = (memcmp(m_wzcConfig.Ssid.Ssid,
  44. pwzcConfig->Ssid.Ssid,
  45. m_wzcConfig.Ssid.SsidLength)) == 0;
  46. }
  47. return bMatch;
  48. }
  49. //+---------------------------------------------------------------------------
  50. // checks whether this configuration is weaker than the one given as parameter
  51. BOOL
  52. CWZCConfig::Weaker(PWZC_WLAN_CONFIG pwzcConfig)
  53. {
  54. BOOL bWeaker = FALSE;
  55. // a configuration is stronger if its privacy bit is set while the matching one is not set
  56. if (m_wzcConfig.Privacy != pwzcConfig->Privacy)
  57. bWeaker = pwzcConfig->Privacy;
  58. // if privacy bits are identical, a configuration is stronger if it has Open Auth mode
  59. else if (m_wzcConfig.AuthenticationMode != pwzcConfig->AuthenticationMode)
  60. bWeaker = (pwzcConfig->AuthenticationMode == Ndis802_11AuthModeOpen);
  61. return bWeaker;
  62. }
  63. DWORD
  64. CWZCConfig::AddConfigToListView(HWND hwndLV, INT nPos)
  65. {
  66. DWORD dwErr = ERROR_SUCCESS;
  67. // ugly but this is life. In order to convert the SSID to LPWSTR we need a buffer.
  68. // We know an SSID can't exceed 32 chars (see NDIS_802_11_SSID from ntddndis.h) so
  69. // make room for the null terminator and that's it. We could do mem alloc but I'm
  70. // not sure it worth the effort (at runtime).
  71. WCHAR wszSSID[33];
  72. UINT nLenSSID = 0;
  73. // convert the LPSTR (original SSID format) to LPWSTR (needed in List Ctrl)
  74. if (m_wzcConfig.Ssid.SsidLength != 0)
  75. {
  76. nLenSSID = MultiByteToWideChar(
  77. CP_ACP,
  78. 0,
  79. (LPCSTR)m_wzcConfig.Ssid.Ssid,
  80. m_wzcConfig.Ssid.SsidLength,
  81. wszSSID,
  82. sizeof(wszSSID)/sizeof(WCHAR));
  83. if (nLenSSID == 0)
  84. dwErr = GetLastError();
  85. }
  86. if (dwErr == ERROR_SUCCESS)
  87. {
  88. LVITEM lvi={0};
  89. UINT nImgIdx;
  90. // put the null terminator
  91. wszSSID[nLenSSID]=L'\0';
  92. // get the item's image index
  93. if (m_wzcConfig.InfrastructureMode == Ndis802_11Infrastructure)
  94. {
  95. nImgIdx = (m_dwFlags & WZC_DESCR_ACTIVE) ? WZCIMG_INFRA_ACTIVE :
  96. ((m_dwFlags & WZC_DESCR_VISIBLE) ? WZCIMG_INFRA_AIRING : WZCIMG_INFRA_SILENT);
  97. }
  98. else
  99. {
  100. nImgIdx = (m_dwFlags & WZC_DESCR_ACTIVE) ? WZCIMG_ADHOC_ACTIVE :
  101. ((m_dwFlags & WZC_DESCR_VISIBLE) ? WZCIMG_ADHOC_AIRING : WZCIMG_ADHOC_SILENT);
  102. }
  103. lvi.iItem = nPos;
  104. lvi.iSubItem = 0;
  105. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  106. lvi.pszText = wszSSID;
  107. lvi.iImage = nImgIdx;
  108. lvi.lParam = (LPARAM)this;
  109. // store the list position in the object
  110. m_nListIndex = ListView_InsertItem(hwndLV, &lvi);
  111. }
  112. return dwErr;
  113. }