Beispiel #1
0
BOOL OnOKGeneral(HWND hDlg, PWLAN_CFG_PROPS psProp)
{
    HRESULT  hr = S_OK;
    SHWZCNET wzcnet;
    INT      nMeta;
    DWORD    dwMask;

    // Get the UI settings
    memcpy(&wzcnet, &psProp->wzcnet, sizeof(SHWZCNET));
    UpdateDataGeneral(hDlg, &wzcnet, &nMeta, FALSE);

    if (psProp->dwFlags & WZCDLG_PROPS_RWSSID) // SSID is changable
    {
        // Is the SSID empty?
        if (TEXT('\0') == wzcnet.szName[0])
        {
            MessageBoxWithResID(hDlg, IDS_WZC_NULL_SSID, IDS_WZC_MSG_TITLE, MB_ICONSTOP | MB_OK);
            CBR(FALSE);
        }

        // Is the name valid?
        hr = SHWZCValidateNetworkName(wzcnet.szName, NULL, 0);
        if (FAILED(hr))
        {
            MessageBoxWithResID(hDlg, IDS_WZC_INVALID_NAME, IDS_WZC_MSG_TITLE, MB_ICONSTOP | MB_OK);
            CHR(hr);
        }

        // Make sure that we do have a valid handle to shwzc
        // If the handle is null, most likely the parent window received an OnActivateHome.
        // We don't ever destroy the callback because the parent window will destroy it.
        hr = SetCallbackRegistration(TRUE, psProp->psWLanInfo);
        CHR(hr);
        // Is this a duplicate name?
        if (S_FALSE != SHWZCIsDuplicateName(psProp->psWLanInfo->hshwzc,
            wzcnet.szName, BOOLIFY(wzcnet.dwFlags & SHWZCF_NET_ADHOC)))
        {
            MessageBoxWithResID(hDlg, IDS_WZC_DUP_SSID, IDS_WZC_MSG_TITLE, MB_ICONSTOP | MB_OK);
            CBR(FALSE);
        }

        // Copy the name
        CHRA(StringCchCopy(psProp->wzcnet.szName, ARRAYSIZE(psProp->wzcnet.szName), wzcnet.szName));
    }

    // Apply the changes
    dwMask = SHWZCF_SETMASK_ADHOC | SHWZCF_SETMASK_REQUIRE_WZC_PROBE;
    hr = SHWZCCopySettings(&psProp->wzcnet, &wzcnet, dwMask);
    CHR(hr);

    psProp->uMeta = nMeta;
    psProp->dwMask |= dwMask;

Error:
    if (FAILED(hr))
    {
        PostMessage(hDlg, WM_DELAY_SETFOCUS, IDC_WZC_EDIT_SSID, 0L);
    }
    return SUCCEEDED(hr);
}
Beispiel #2
0
HRESULT RefreshWifiAdvanceSettings(HWND hDlg)
{
    HRESULT hr = S_OK;
    HWND    hCombo;
    int     iRet;
    UINT    uiTime;
    BOOL    fNotification;

    hr = SHWZCGetNotificationState(&fNotification);
    CHR(hr);

    SendDlgItemMessage(hDlg, IDC_WZC_CHECK_NOTIFICATION, BM_SETCHECK, fNotification ? BST_CHECKED : BST_UNCHECKED, 0);

    hr = SHWZCGetWifiTimeoutPeriod(&uiTime);
    CHR(hr);

    hCombo = GetDlgItem(hDlg, IDC_WZC_COMBO_AUTO_OFF);
    CWR(hCombo);

    for (int i = 0; i <= (IDS_WZC_AUTO_OFF_LAST-IDS_WZC_AUTO_OFF_FIRST); i++)
    {
        iRet = SendMessage(hCombo, CB_INSERTSTRING, (WPARAM)-1, (LPARAM) LoadStringEtc(HINST_RESDLL, IDS_WZC_AUTO_OFF_FIRST+i, NULL));
        CBR(iRet != CB_ERR);

        if (uiTime == g_uiAutoOffTimer[i])
        {
            SendMessage(hCombo, CB_SETCURSEL, (WPARAM)iRet, (LPARAM)0);
        }

        CBR(CB_ERR != SendMessage(hCombo, CB_SETITEMDATA, (WPARAM)iRet, (LPARAM)g_uiAutoOffTimer[i]));
    }

Error:
    return hr;
}
Beispiel #3
0
static HRESULT GetEAPParams(UINT iIndex, __inout WZC_EAPOL_PARAMS *pwzceap)
{
    HRESULT hr = S_OK;
    HKEY    hkey = NULL;
    DWORD   dwValueType;
    DWORD   cbSize;

    // Open the default type key
    hr = OpenEAPRegistryKey(iIndex, &hkey);
    CHR(hr);

    // Get the type code
    cbSize = sizeof(pwzceap->dwEapType);
    CBR(ERROR_SUCCESS == RegQueryValueEx(hkey, g_szRegValueEAPType, NULL, &dwValueType,
        (BYTE*)&pwzceap->dwEapType, &cbSize) && REG_DWORD == dwValueType);

    // Get the flags
    cbSize = sizeof(pwzceap->dwEapFlags);
    CBR(ERROR_SUCCESS == RegQueryValueEx(hkey, g_szRegValueEAPFlags, NULL, &dwValueType,
        (BYTE*)&pwzceap->dwEapFlags, &cbSize) && REG_DWORD == dwValueType);

Error:
    if (NULL != hkey)
    {
        RegCloseKey(hkey);
    }

    return hr;
}
Beispiel #4
0
static HRESULT OnConnect(PWLAN_INFO psInfo, INT iItem)
{
    HRESULT    hr = S_OK;
    PCSHWZCNET pwzcnet = (PCSHWZCNET)GetListItemLPARAM(psInfo->hwndNetList, iItem);
    SHWZCNET   wzcnet;
    BOOL       fSecure;

    // The first item is "Add net settings...". It cannot be deleted.
    CBR(iItem > 0 && pwzcnet != NULL);
    memcpy(&wzcnet, pwzcnet, sizeof(SHWZCNET));

    // If the item isn't preferred
    if (!(SHWZCF_NET_PREFERRED & wzcnet.dwFlags))
    {
        DWORD dwNoFastConnect = 0;

        fSecure = BOOLIFY(wzcnet.dwFlags & SHWZCF_NET_8021X) ||
                !( ( (Ndis802_11Encryption1Enabled != wzcnet.dwEncryptionType) &&
                (Ndis802_11Encryption2Enabled != wzcnet.dwEncryptionType) &&
                (Ndis802_11Encryption3Enabled != wzcnet.dwEncryptionType) ) &&
                (Ndis802_11AuthModeOpen == wzcnet.dwAuthentication) );

        // If secure or fastconnect is disabled, show the settings wizard, else connect
        RegistryGetDWORD(HKEY_LOCAL_MACHINE, WZC_REGKEY_BASE, WZC_REGKEY_DISABLEFASTCONNECT, &dwNoFastConnect);
        if (fSecure || dwNoFastConnect != 0)
        {
            CBR(OnNetworkProperties(psInfo, iItem));
        }
        else
        {
            SHWZCSetNetwork(psInfo->hshwzc, &wzcnet, NULL, NULL, 0, SHWZCF_SETMASK_ALL);
        }
    }

    // disable SK1 Connect while we're attempting to connect for this network
    SHEnableSoftkey(psInfo->hwndNetListMB, 0, TRUE, FALSE);

    // Ensure that power is on. Ignore errors, this is a "Best-effort" attempt
    SHWZCSetPowerState(TRUE);
        
    // Now connect directly (we'll automatically get a refresh event)
    hr = SHWZCConnectNetwork(psInfo->hshwzc, wzcnet.szName,
        BOOLIFY(SHWZCF_NET_ADHOC & wzcnet.dwFlags));
    CHR(hr);

Error:
    if(FAILED(hr))
    {
        // re-enable SK since something went wrong
        SHEnableSoftkey(psInfo->hwndNetListMB, 0, TRUE, TRUE);
    }
    
    return hr;
}
Beispiel #5
0
static HRESULT GetMetaNetworkNames()
{
    HRESULT hr = S_OK;
    UINT    i;

    if (0 == g_rgmni[0].szName[0])
    {
        // Enumerate the entries
        hr = EnumMetaNetworkNames(EnumMetaNetworkNamesCallback, NULL);
        CHR(hr);

        // Make sure we got them all
        for (i = 0; i != ARRAYSIZE(g_rgmni); ++i)
        {
            CBR(0 != g_rgmni[i].szName[0]);
        }
    }

Error:
    if (FAILED(hr))
    {
        // Make sure we retry later
        g_rgmni[0].szName[0] = TEXT('\0');
    }

    return hr;
}
Beispiel #6
0
HRESULT GetEAPIncremented(PWLC pwlc)
{
    HRESULT hr = S_OK;
    UINT    iIndex;

    // If EAP hasn't been enabled, just start with the initial defaults
    if (!pwlc->EapolParams.bEnable8021x)
    {
        hr = GetEAPDefaults(pwlc);
        CHR(hr);
        goto Exit;
    }

    // WPA[2]-PSK doesn't increment through the EAP types
    CBR(! IsAnyWPAPSK(pwlc->AuthenticationMode));
    
    // Find the index of the current type
    hr = FindEAPRegistryIndex(pwlc->EapolParams.dwEapType, &iIndex, NULL);
    CHR(hr);

    // Set the parameters for the next type
    hr = GetEAPParams(iIndex + 1, &pwlc->EapolParams);
    CHR(hr);

Error:
Exit:
    return hr;
}
Beispiel #7
0
static BOOL CALLBACK EnumAuthentication(DWORD dwType, LPCTSTR pszName, LPVOID pvParam)
{
    HRESULT hr = S_OK;
    HWND    hcbAuth = (HWND)pvParam;
    int     nIndex;

    // Add the item
    nIndex = SendMessage(hcbAuth, CB_ADDSTRING, 0, (LPARAM)pszName);
    CBR(CB_ERR != nIndex);

    // Set the type
    CBR(CB_ERR != SendMessage(hcbAuth, CB_SETITEMDATA, nIndex, dwType));

Error:
    return SUCCEEDED(hr);
}
Beispiel #8
0
inline void
LocalTrrkKernel
( UpperOrLower uplo,
  Orientation orientationOfA,
  Orientation orientationOfB,
  T alpha, const DistMatrix<T,STAR,MC  >& A,
           const DistMatrix<T,MR,  STAR>& B,
  T beta,        DistMatrix<T,MC,  MR  >& C )
{
#ifndef RELEASE
    PushCallStack("LocalTrrkKernel");
    CheckInput( orientationOfA, orientationOfB, A, B, C );
#endif
    const Grid& g = C.Grid();

    DistMatrix<T,STAR,MC> AL(g), AR(g);
    DistMatrix<T,MR,STAR> BT(g), 
                          BB(g);
    DistMatrix<T,MC,MR> CTL(g), CTR(g),
                        CBL(g), CBR(g);
    DistMatrix<T,MC,MR> DTL(g), DBR(g);

    const int half = C.Height()/2;
    ScaleTrapezoid( beta, LEFT, uplo, 0, C );
    LockedPartitionRight( A, AL, AR, half );
    LockedPartitionDown
    ( B, BT, 
         BB, half );
    PartitionDownDiagonal
    ( C, CTL, CTR,
         CBL, CBR, half );

    DTL.AlignWith( CTL );
    DBR.AlignWith( CBR );
    DTL.ResizeTo( CTL.Height(), CTL.Width() );
    DBR.ResizeTo( CBR.Height(), CBR.Width() );
    //------------------------------------------------------------------------//
    if( uplo == LOWER )
        internal::LocalGemm
        ( orientationOfA, orientationOfB, alpha, AR, BT, T(1), CBL );
    else
        internal::LocalGemm
        ( orientationOfA, orientationOfB, alpha, AL, BB, T(1), CTR );

    internal::LocalGemm
    ( orientationOfA, orientationOfB, alpha, AL, BT, T(0), DTL );
    AxpyTriangle( uplo, T(1), DTL, CTL );

    internal::LocalGemm
    ( orientationOfA, orientationOfB, alpha, AR, BB, T(0), DBR );
    AxpyTriangle( uplo, T(1), DBR, CBR );
    //------------------------------------------------------------------------//
#ifndef RELEASE
    PopCallStack();
#endif
}
Beispiel #9
0
HRESULT GetWirelessStateFlags(DWORD *pdwStatus)
{
    HRESULT hr = S_OK;

    CBR(pdwStatus);   
    *pdwStatus = 0;
    
    CHR(RegistryGetDWORD(HKEY_LOCAL_MACHINE, c_szRegKeySSWifi, c_szRegValueSSWifi, pdwStatus));
    
Error:
    return hr;
}
Beispiel #10
0
HRESULT RegValueSZ(HKEY hKey, LPCTSTR szName, LPTSTR* ppszValue, DWORD cbLen)
{
    HRESULT hr = S_OK;
    DWORD   dwRet, cbBufLen;
    BOOL    fDelete = FALSE;
    
    CBR(hKey != NULL && ppszValue != NULL);

    cbBufLen = 0;
    dwRet = RegQueryValueEx(hKey, szName, NULL, NULL, NULL, &cbBufLen);
    CBR(dwRet == ERROR_SUCCESS);

    if (!cbLen)
    {
        *ppszValue = (LPTSTR)LocalAlloc(LPTR, cbBufLen);
        CPR(*ppszValue);
        cbLen = cbBufLen;
        // This flag is to only free space
        // allocated here if RegQuery fails below
        // We should not free space being passed in.
        fDelete = TRUE; 
    }
        
    dwRet = RegQueryValueEx(hKey, szName, NULL, NULL, (LPBYTE)*ppszValue, &cbLen);
    
    if (dwRet != ERROR_SUCCESS && !cbLen)
    {
        if(fDelete) 
        {
            LocalFree(*ppszValue);

            // Avoid a potential double free in the calling function
            *ppszValue = NULL;
        }
    }
    CBR(dwRet == ERROR_SUCCESS);
    
Error:
    return hr;
}
Beispiel #11
0
HRESULT GetMetaNetworkIndex(LPCTSTR pszGUID, UINT *piMetaNetwork)
{
    HRESULT hr = S_OK;
    GUID    guid;
    UINT    i;

    ASSERT(NULL != pszGUID);
    ASSERT(NULL != piMetaNetwork);

    // Convert the string to a GUID
    CBR(SHGUIDFromString(pszGUID, &guid));

    // Get the GUID index
    i = MatchMetaNetworkIndex(guid);
    CBR(i < ARRAYSIZE(g_rgmni));

    // Success
    *piMetaNetwork = i;

Error:
    return hr;
}
Beispiel #12
0
static HRESULT FindEAPRegistryIndex(DWORD dwFindType, __out __opt UINT *piIndex, __out __opt HKEY *phkey)
{
    HRESULT hr = S_OK;
    UINT    iIndex;
    HKEY    hkey = NULL;
    DWORD   dwEAPType;
    DWORD   dwValueType;
    DWORD   cbSize;

    for (iIndex = 0;; ++iIndex)
    {
        // Try to open the registry key at this index
        hr = OpenEAPRegistryKey(iIndex, &hkey);
        CHR(hr);

        // Get the associated type
        cbSize = sizeof(dwEAPType);
        CBR(ERROR_SUCCESS == RegQueryValueEx(hkey, g_szRegValueEAPType, NULL, &dwValueType,
            (BYTE*)&dwEAPType, &cbSize) && REG_DWORD == dwValueType);

        // Do they match?
        if (dwEAPType == dwFindType)
        {
            break;
        }

        // Close the registry key
        RegCloseKey(hkey);
        hkey = NULL;
    }

    // We got a match
    if (NULL != piIndex)
    {
        *piIndex = iIndex;
    }

    if (NULL != phkey)
    {
        *phkey = hkey;
        hkey = NULL;
    }

Error:
    if (NULL != hkey)
    {
        RegCloseKey(hkey);
    }

    return hr;
}
Beispiel #13
0
//==========================================================================*
// Function: OnNetworkProperties
//
// Purpose:  (1) Display the network properties dialog
//           (2) Move(insert) the network to the head of the prefered list
//           
// Arguments: 
//     [IN] psInfo - pointer to the WLAN_INFO structure
//     [IN] item   - item need to show context menu
//
// Return Values:
//     BOOL - TRUE for handle it successfully
//==========================================================================*
static BOOL OnNetworkProperties(PWLAN_INFO psInfo, INT iItem)
{
    HRESULT        hr = S_OK;
    WLAN_CFG_PROPS sProps = {0};
    PCSHWZCNET     pwzcnet = (PCSHWZCNET)GetListItemLPARAM(psInfo->hwndNetList, iItem);
    BOOL           fAdhoc;
    TCHAR          szGUID[MAX_PATH];
    FINDGUID       fg;

    CBR(iItem > 0 && pwzcnet != NULL);

    // If the selected network is a "Permanent" non-editable network, exit without 
    // showing the NetworkProperties pages
    fAdhoc = BOOLIFY(SHWZCF_NET_ADHOC & pwzcnet->dwFlags);
    CBREx (!SHWZCIsPermanentNetwork(pwzcnet->szName, fAdhoc), S_FALSE);

    // Get the current EAP data
    hr = SHWZCGetNetwork(psInfo->hshwzc, pwzcnet->szName, fAdhoc,
        &sProps.wzcnet, &sProps.pvEapData, &sProps.cbEapData);
    CHR(hr);

    // We don't care about the result, since if this fails we just won't match
    // with any networks and we'll use the default
    szGUID[0] = 0;
    SHWZCGetDestinationGUID(psInfo->hshwzc, pwzcnet->szName, fAdhoc,
        szGUID, ARRAYSIZE(szGUID));

    fg.pszGUID = szGUID;
    fg.uIndex = 0;
    if (S_FALSE == SHWZCEnumDestinations(EnumFindGUID, &fg))
    {
        sProps.uMeta = fg.uIndex;
    }

    sProps.psWLanInfo = psInfo;
    
    hr = WZCCreateNetworkWLanPropsDlgs(psInfo->hDlg, &sProps);
    CHR(hr);

    if (IDOK == sProps.nReturn)
    {
        hr = ApplyProperties(psInfo, &sProps);
        CHR(hr); 
    }

Error:
    LocalFree(sProps.pvEapData);
    return SUCCEEDED(hr);
}
Beispiel #14
0
static HRESULT OpenEAPRegistryKey(UINT iIndex, __out HKEY *phkey)
{
    HRESULT hr = S_OK;
    TCHAR   szKey[MAX_PATH];

    // Build the registry path
    hr = StringCchPrintf(szKey, ARRAYSIZE(szKey), TEXT("%s\\%s%u"),
        g_szRegKeyBase, g_szRegKeyEAP, iIndex + 1);
    CHRA(hr);

    // Open the registry key
    CBR(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, szKey, 0, 0, phkey));

Error:
    return hr;
}
Beispiel #15
0
static HRESULT OnChangeNetFilter(PWLAN_INFO psInfo)
{
    HRESULT hr = S_OK;
    INT     nNetFilter;
    
    nNetFilter = SendDlgItemMessage(psInfo->hDlg, IDC_WZC_COMBO_FILTER, CB_GETCURSEL, 0, 0L);
    ASSERT(WZC_FILTER_ALL_AVAILABLE <= nNetFilter && nNetFilter <= WZC_FILTER_ADHOC);

    if (nNetFilter != psInfo->nNetFilter)
    {
        DWORD dwState = 0;

        // Get the current state
        SHWZCGetState(psInfo->hshwzc, &dwState);
        dwState &= ~SHWZCF_ALLOW_MASK;

        // Convert to infrastructure mode
        psInfo->nNetFilter = (WZC_FILTER) nNetFilter;
        switch(nNetFilter)
        {
        case WZC_FILTER_ALL_AVAILABLE:
            dwState |= SHWZCF_ALLOW_ALL;
            break;

        case WZC_FILTER_ACCESS_POINT:
            dwState |= SHWZCF_ALLOW_AP;
            break;

        case WZC_FILTER_ADHOC:
            dwState |= SHWZCF_ALLOW_ADHOC;
            break;

        default:
            // There is no default case, see ASSERT above
            CBR(FALSE);
        }

        // Set the "Network to access" setting to WZC engine
        hr = SHWZCSetState(psInfo->hshwzc, dwState);
        CHR(hr);
        
        hr = RefreshNetListView(psInfo);
    }

Error:
    return hr;
}
Beispiel #16
0
HRESULT SetWirelessStateFlags(UINT uMask, UINT uValue)
{
    HRESULT hr = S_OK;
    DWORD   dwData = 0;
    HKEY    hKey = NULL;

    CBR(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, c_szRegKeySSWifi,
                                        0, NULL, REG_OPTION_VOLATILE, 0, NULL, &hKey, NULL));

    RegistryGetDWORD(hKey, NULL, c_szRegValueSSWifi, &dwData);
    dwData = (dwData & ~uMask) | (uMask & uValue);
    CHR(RegistrySetDWORD(hKey, NULL, c_szRegValueSSWifi, dwData));

Error:
    RegCloseKey(hKey);
    return hr;
}
Beispiel #17
0
HRESULT EnableControlsAuthentication(HWND hDlg, PWLAN_CFG_PROPS psProp)
{
    HRESULT hr = S_OK;
    HWND    hcbAuth = GetDlgItem(hDlg, IDC_WZC_COMBO_AUTHENTICATION);

    // Clear the authentication combo box
    SendMessage(hcbAuth, CB_RESETCONTENT, 0, 0);

    // Populate the authentication combo box
    hr = SHWZCEnumAuthenticationTypes(BOOLIFY(SHWZCF_NET_ADHOC & psProp->wzcnet.dwFlags),
        EnumAuthentication, hcbAuth);
    CHR(hr);
    CBR(S_OK == hr);  // S_FALSE is failure

Error:
    return hr;
}
Beispiel #18
0
static HRESULT OnRemoveSetting(PWLAN_INFO psInfo, INT iItem)
{
    HRESULT    hr = S_OK;
    PCSHWZCNET pwzcnet =(PCSHWZCNET)GetListItemLPARAM(psInfo->hwndNetList, iItem);

    // The first item is "Add net settings...". It cannot be deleted.
    CBR(iItem > 0 && pwzcnet != NULL);

    // Delete the network
    hr = SHWZCDeleteNetwork(psInfo->hshwzc, pwzcnet->szName,
        BOOLIFY(SHWZCF_NET_ADHOC & pwzcnet->dwFlags));
    CHR(hr);

    // Refresh list view
    RefreshNetListView(psInfo);

Error:
    return hr;
}
Beispiel #19
0
//==========================================================================*
// Function: OnNetworkContextMenu
//
// Purpose:  Display wireless network context menu.
//           The menu has two items: connect/disconnect/remove
//           We need to show/hide connect or disconnect items according to
//           the connection state of the network.
//           The first listview item "add new setting..." doesn't have a context menu
//           
// Arguments: 
//     [IN] psInfo - pointer to the WLAN_INFO structure
//     [IN] pt     - position which menu need to locate
//     [IN] item   - item need to show context menu
//
// Return Values:
//     BOOL - TRUE for handle it successfully
//==========================================================================*
static BOOL OnNetworkContextMenu(PWLAN_INFO psInfo, POINT pt, INT iItem)
{
    HRESULT    hr    = S_OK;
    HMENU      hMenu = NULL;
    HMENU      hMenuTrack = NULL;
    IUnknown   *pIUnknown = NULL;
    HANDLE     hCMExtensions = NULL;
        
    // The first item is "Add new network..." item. It doesn't need a context menu.
    CBR(iItem > 0);

    hMenu = LoadMenu(HINST_RESDLL, MAKEINTRESOURCE(IDR_WZC_MENU_NETWORK));
    CWR(hMenu);

    hMenuTrack = GetSubMenu(hMenu, 0);
    CWR(hMenuTrack);

    InsertMenu(hMenuTrack, (UINT)-1, MF_BYPOSITION|MF_STRING, IDM_WZC_WIFI_POWERCMD,
               LoadStringEtc(HINST_RESDLL, IDS_WZC_WIFI_POWERON + ((psInfo->dwHWFlags & SHWZCF_HW_ON) ? 1:0), NULL));

    SHLoadMenuExtensions((IUnknown*)psInfo->pNetworkObject,
                         gc_szMenuNamespace,
                         gc_szContextExtensions,
                         &psInfo->hContextExt);

    TrackPopupMenu(hMenuTrack, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0,
        psInfo->hDlg, NULL);

    SHFreeContextMenuExtensions(psInfo->hContextExt);
    psInfo->hContextExt = NULL;

Error:
    if (hMenuTrack)
    {
        CloseHandle(hMenuTrack);
    }
    if (hMenu)
    {
        DestroyMenu(hMenu);
    }
    return SUCCEEDED(hr);
}
Beispiel #20
0
//==========================================================================*
// Function: InsertFirstSettingsItem
//
// Purpose:  Add the first item of the list view ("Add New" or "Search for Networks")
//           
// Arguments: 
//     [IN] psInfo    - pointer to the WLAN_INFO structure
//
// Return Values:
//     HRESULT - S_OK for succeed
//==========================================================================*
static HRESULT InsertFirstSettingsItem(PWLAN_INFO psInfo)
{
    HRESULT hr = S_OK;
    LV_ITEM lv = { 0 };
    LPCTSTR pszText;

    pszText = (LPCTSTR)LoadString(HINST_RESDLL,
                                  (psInfo->dwHWFlags & SHWZCF_HW_ON) ? IDS_WZC_ADD_NEW_SETTINGS : IDS_WZC_SEARCH_NETWORKS,
                                  NULL,
                                  0);
    CBRA(NULL != pszText);

    // Fill list view structure and insert item
    lv.mask    = LVIF_TEXT | LVIF_IMAGE;
    lv.pszText = (LPTSTR)pszText;
    lv.iImage  = -1;

    CBR(0 <= ListView_InsertItem(psInfo->hwndNetList, &lv));

Error:
    return hr;
}
Beispiel #21
0
HRESULT PopulateEncryptionBox(HWND hDlg, PCSHWZCNET pwzcnet)
{
    HRESULT hr = S_OK;
    HWND    hcbEncryption = GetDlgItem(hDlg, IDC_WZC_COMBO_DATA_ENCRYPTION);
    int     nIndex;

    // Clear the encryption combo box
    SendMessage(hcbEncryption, CB_RESETCONTENT, 0, 0);

    // Enumerate the available encryption types
    hr = SHWZCEnumEncryptionTypes(pwzcnet, EnumEncryption, hcbEncryption);
    CHR(hr);
    CBR(S_OK == hr);  // S_FALSE means failure

    nIndex = FindIndexFromComboData(hcbEncryption, pwzcnet->dwEncryptionType);
    CBRA(0 <= nIndex);  // huh??
    
    SendMessage(hcbEncryption, CB_SETCURSEL, nIndex, 0);
    EnableWepKControls(hDlg, pwzcnet);

Error:
    return hr;
}
Beispiel #22
0
static HRESULT ApplyProperties(PWLAN_INFO psInfo, const WLAN_CFG_PROPS *psProps)
{
    HRESULT  hr = S_OK;
    FINDGUID fg;
    TCHAR    szGUID[MAX_PATH];
    DWORD dwHardwareState;

    fg.pszGUID = szGUID;
    fg.cchGUID = ARRAYSIZE(szGUID);
    fg.uIndex = 0;
    fg.uDesired = psProps->uMeta;

    // Set the network data
    hr = SHWZCSetNetwork(psInfo->hshwzc, &psProps->wzcnet, psProps->pszKey,
        psProps->pvEapData, psProps->cbEapData, psProps->dwMask);
    CHR(hr);

    // Copy the GUID string
    CBR(S_FALSE == SHWZCEnumDestinations(EnumSetGUID, &fg));
    hr = SHWZCSetDestinationGUID(psInfo->hshwzc, psProps->wzcnet.szName,
        BOOLIFY(SHWZCF_NET_ADHOC & psProps->wzcnet.dwFlags), szGUID);
    CHR(hr);

    // Refresh the view
    RefreshNetListView(psInfo);

    dwHardwareState = SHWZCGetHardwareFlags();
    if (!(dwHardwareState & SHWZCF_HW_CONNECTED) && !(dwHardwareState & SHWZCF_HW_CONNECTING))
    {
        hr = SHWZCConnectNetwork(psInfo->hshwzc, psProps->wzcnet.szName,
            BOOLIFY(SHWZCF_NET_ADHOC & psProps->wzcnet.dwFlags));
        CHR(hr);
    }        
Error:
    return hr;
}
Beispiel #23
0
HRESULT GetEAPFlags(DWORD dwType, DWORD *pdwFlags)
{
    HRESULT hr = S_OK;
    HKEY    hkey = NULL;
    DWORD   dwValueType;
    DWORD   cbSize;

    // Find the registry index that matches this type
    hr = FindEAPRegistryIndex(dwType, NULL, &hkey);
    CHR(hr);

    // Get the default flags for this type
    cbSize = sizeof(*pdwFlags);
    CBR(ERROR_SUCCESS == RegQueryValueEx(hkey, g_szRegValueEAPFlags, NULL, &dwValueType,
        (BYTE*)pdwFlags, &cbSize) && REG_DWORD == dwValueType);

Error:
    if (NULL != hkey)
    {
        RegCloseKey(hkey);
    }

    return hr;
}
Beispiel #24
0
HRESULT GetEAPDefaultType(DWORD *pdwType)
{
    HRESULT hr = S_OK;
    HKEY    hkey = NULL;
    DWORD   dwValueType;
    DWORD   cbSize;

    // Open the default type key
    hr = OpenEAPRegistryKey(0, &hkey);
    CHR(hr);

    // Get the type code
    cbSize = sizeof(*pdwType);
    CBR(ERROR_SUCCESS == RegQueryValueEx(hkey, g_szRegValueEAPType, NULL, &dwValueType,
        (BYTE*)pdwType, &cbSize) && REG_DWORD == dwValueType);

Error:
    if (NULL != hkey)
    {
        RegCloseKey(hkey);
    }

    return hr;
}
Beispiel #25
0
void OnEAPProps(HWND hDlg, PWLAN_CFG_PROPS psProp)
{
    HRESULT hr = S_OK;
    HINSTANCE hinstEAPDll = NULL;
    WZC_EAP_CB_ITEMDATA *pEapCbItemData;
    PEAP_EXTENSION_INFO pCurExt=NULL;
    HWND hwndCbEAPType = GetDlgItem(hDlg, IDC_WZC_COMBO_EAP_TYPE);
    int iListIndex = ComboBox_GetCurSel(hwndCbEAPType);
    DWORD dwError = (DWORD)-1;
    UCHAR *pConnectionDataOut=NULL;
    DWORD dwSizeOfConnectionDataOut=0;

    UNREFERENCED_PARAMETER(psProp);

    pEapCbItemData = (WZC_EAP_CB_ITEMDATA *)ComboBox_GetItemData(hwndCbEAPType,iListIndex);
    if (pEapCbItemData)
    {
        pCurExt = pEapCbItemData->pEapExtInfo;
    }

    if (pCurExt && pCurExt->wszConfigUIPath) 
    {
        RASEAPINVOKECONFIGUI pfnEapConfig;
        RASEAPFREE           pfnEapFreeMem;

        hinstEAPDll = LoadLibrary(pCurExt->wszConfigUIPath);
        CBR(hinstEAPDll != NULL);
        
        pfnEapConfig = (RASEAPINVOKECONFIGUI)GetProcAddress(hinstEAPDll,TEXT("RasEapInvokeConfigUI"));
        pfnEapFreeMem= (RASEAPFREE)GetProcAddress(hinstEAPDll,TEXT("RasEapFreeMemory"));
        CBR((pfnEapConfig != NULL) && (pfnEapFreeMem != NULL));
            
        // Call into config UI
        __try {
            dwError = pfnEapConfig(pCurExt->dwExtensionType,
                                   hDlg,
                                   0, // flags TBD
                                   pEapCbItemData->pbAuthData,
                                   pEapCbItemData->dwAuthDataLen,
                                   &pConnectionDataOut,
                                   &dwSizeOfConnectionDataOut);
        } 
        __except(WatsonReportFault(GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)) 
        {
        }

        CBR(dwError == ERROR_SUCCESS);
        
        if (dwSizeOfConnectionDataOut && pConnectionDataOut) 
        {
            
            if (pEapCbItemData->pbAuthData) 
            {
                LocalFree(pEapCbItemData->pbAuthData);
            }

            pEapCbItemData->pbAuthData = LocalAlloc(LPTR, dwSizeOfConnectionDataOut);
            CPR(pEapCbItemData->pbAuthData);

            pEapCbItemData->dwAuthDataLen = dwSizeOfConnectionDataOut;

            __try 
            {
                memcpy(pEapCbItemData->pbAuthData,
                       pConnectionDataOut,dwSizeOfConnectionDataOut);
            } 
            __except(WatsonReportFault(GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)) 
            {
                  LocalFree(pEapCbItemData->pbAuthData);
                  pEapCbItemData->pbAuthData    = NULL;
                  pEapCbItemData->dwAuthDataLen = 0;
            }
            
            __try 
            {
                pfnEapFreeMem(pConnectionDataOut);
            } 
            __except(WatsonReportFault(GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)) 
            {
                  ;
            }
        }
    }
Beispiel #26
0
BOOL OnOKAuthentication(HWND hDlg, PWLAN_CFG_PROPS psProp, BOOL fValidate)
{
    HRESULT  hr = S_OK;
    SHWZCNET wzcnet;
    DWORD    dwDisplayFlags = 0;
    BOOL     fApplyKey;
    BOOL     fVerified = FALSE;
    DWORD    dwMask = SHWZCF_SETMASK_AUTHENTICATION | SHWZCF_SETMASK_ENCRYPTION | SHWZCF_SETMASK_KEYINDEX;

    // Get the UI settings
    memcpy(&wzcnet, &psProp->wzcnet, sizeof(SHWZCNET));
    hr = UpdateDataAuthentication(hDlg, &wzcnet, FALSE);
    CHR(hr);

    // Check for valid authentication and encryption configuration
    if (fValidate && 
        !SHWZCValidateSecurityConfig(wzcnet.dwAuthentication, 
                                     wzcnet.dwEncryptionType,
                                     BOOLIFY(SHWZCF_NET_ADHOC & wzcnet.dwFlags)))
    {
        DisplayError(hDlg, IDS_WZC_INVALID_CONFIG, IDC_WZC_COMBO_AUTHENTICATION);
        CBR(FALSE);
    }

    // Get the display flags
    hr = SHWZCGetDisplayFlags(&wzcnet, &dwDisplayFlags);
    CHR(hr);

    // Only verify the key if the key material is touched
    if (!(SHWZCF_UI_KEYDATA_DISABLED & dwDisplayFlags) &&
        (SHWZCF_NET_KEYDATA & wzcnet.dwFlags) &&
        (WZCDLG_PROPS_KEYTOUCHED & psProp->dwFlags))
    {
        TCHAR szKeyBuf[WZCCTL_MAX_WEPK_MATERIAL * 2 + 1];
        DDX_Text(hDlg, IDC_WZC_EDIT_WEP, szKeyBuf, ARRAYSIZE(szKeyBuf), FALSE);

        if(fValidate)
        {        
            BOOL fDisplayError = FALSE;
            
            if(TEXT('\0') == szKeyBuf[0])
            {
                // only adhoc networks can have an empty string as a key
                if(BOOLIFY(SHWZCF_NET_ADHOC & psProp->wzcnet.dwFlags))
                {
                    // make sure apply key doesn't get set.  This way if the user validates this state, the wifi netkey will not display *'s when 
                    // when editing the network.  
                    wzcnet.dwFlags &= ~SHWZCF_NET_KEYDATA;
                }
                else
                {
                    fDisplayError = TRUE;
                }
            }
            else 
            {
                if (SHWZCValidateKey(szKeyBuf, wzcnet.dwEncryptionType, wzcnet.dwAuthentication))
                {
                    fVerified = TRUE;
                }
                else
                {
                    fDisplayError = TRUE;
                }
            }

            if(fDisplayError)
            {
                DisplayError(hDlg, IDS_WZC_INCORRECT_WEP_KEY, IDC_WZC_EDIT_WEP);
                CBR(FALSE);
            }
        }

        // Copy the key data into the buffer
        hr = StringCchCopy(psProp->pszKey, ARRAYSIZE(psProp->pszKey), szKeyBuf);
        CHRA(hr);  // this should always work
    }

    // Apply the changes to the network
    fApplyKey = (!(SHWZCF_NET_KEYDATA & wzcnet.dwFlags) || (WZCDLG_PROPS_KEYTOUCHED & psProp->dwFlags));
    dwMask |= (fApplyKey ? SHWZCF_SETMASK_KEYDATA : 0);
    hr = SHWZCCopySettings(&psProp->wzcnet, &wzcnet, dwMask);
    CHR(hr);

    // Success
    psProp->dwMask |= dwMask;

    if(fVerified)
    {   
        // at this point we can say the WEP key is untouched since it's been verified
        psProp->dwFlags &= ~WZCDLG_PROPS_KEYTOUCHED;
    }

Error:
    return SUCCEEDED(hr);
}
Beispiel #27
0
DWORD 
EapTlsInvokeConfigUI(
    IN  DWORD       dwEapTypeId,
    IN  HWND        hwndParent,
    IN  DWORD       dwFlags,
    IN  BYTE*       pConnectionDataIn,
    IN  DWORD       dwSizeOfConnectionDataIn,
    OUT BYTE**      ppConnectionDataOut,
    OUT DWORD*      pdwSizeOfConnectionDataOut
)
{
    UNREFERENCED_PARAMETER(dwFlags);
    
    EAPTLS_CONN_PROPERTIES_V1* pConnProp = NULL;
    PCCERT_CONTEXT pCertContext = NULL;
    HCERTSTORE     hMyStore = NULL;
    DWORD          dwErr = NO_ERROR;
    HRESULT        hr = S_OK;
    DWORD          cbHash = 0, dwConnFlags;
    BYTE           bHash[MAX_HASH_SIZE], *pbHashCert = NULL;
    BOOL           bSuccess, fCapi2 = FALSE;
    INT            cnCerts = 0, nSelected = -1;
    DWORD          dwValidServerClert, dwType, cb;

    hr = LoadCAPI2();
    CHR(hr);
    fCapi2 = TRUE;

    dwConnFlags = (dwEapTypeId == PPP_EAP_PEAP) ? EAPTLS_CONN_FLAG_NO_CLIENT_CERT : 0;

    cb = sizeof(dwValidServerClert);
    if (ERROR_SUCCESS == SHRegQueryValueEx(HKEY_CURRENT_USER, c_szValidateServerCert,
            (DWORD *)c_szRegistryKey, &dwType, (BYTE *)&dwValidServerClert, &cb))
    {
        CBR(REG_DWORD == dwType);

        // dwValidServerClert =  0 - don't validate server certification
        if (dwValidServerClert == 0)
        {
            dwConnFlags |= EAPTLS_CONN_FLAG_NO_VALIDATE_CERT;  // we do not validate server cert by default
        }
    }
    else
    {
        // We dvalidates server cert by default
    }

    pConnProp = InitConnectionData(pConnectionDataIn, dwSizeOfConnectionDataIn, dwConnFlags);
    CPR(pConnProp);

    hMyStore = pfnCertOpenStore(CERT_STORE_PROV_SYSTEM_W, CRYPT_ASN_ENCODING, 
                            0, CERT_SYSTEM_STORE_CURRENT_USER, TEXT("MY"));
    CBR(hMyStore);

    // Enum on personal cert store
    while (NULL != (pCertContext = pfnCertEnumCertificatesInStore(hMyStore, pCertContext)))
    {
        BYTE  bHashTemp[MAX_HASH_SIZE];
        DWORD cbHashTemp = ARRAYSIZE(bHashTemp);

        bSuccess = pfnCertGetCertificateContextProperty(pCertContext, CERT_HASH_PROP_ID,
                        bHashTemp, &cbHashTemp);
        if (   nSelected < 0 // There is matched cert
            && cbHashTemp  
            && cbHashTemp == pConnProp->UserHash.cbHash // The size of certs are equal
            && memcmp(bHashTemp, pConnProp->UserHash.pbHash, cbHashTemp) == 0)
        {
            nSelected = cnCerts;
            cbHash    = cbHashTemp;
            memcpy(bHash, bHashTemp, cbHash);
        }
        cnCerts++;
    }

    if (cnCerts == 0)
    {
        // There is no cert on the device, warrning!
        MessageBox(SHGetLastActiveWindow(hwndParent), 
            (PTSTR)LoadString(HINST_RESDLL, IDS_NETUI_EAPTLS_NO_CERT, NULL, 0), 
            (PTSTR)LoadString(HINST_RESDLL, IDS_NETUI_WRN_TITLE_WARNING, NULL, 0),
            MB_OK | MB_SETFOREGROUND);
        dwErr = ERROR_NOT_FOUND;
    }
    else if (cnCerts > 0)
    {
        DWORD cbHashCert = 0;
        
        // Need to let user choice one
        hr = PickCertificateDlg(NULL, TEXT("MY"), c_szPickCertHelpLink,
                (PTSTR)LoadString(HINST_RESDLL, IDS_NETUI_EAPTLS_DESC, NULL, 0),
                bHash, cbHash, 
                &pbHashCert, &cbHashCert);
        CHR(hr);
        CBRA(cbHashCert <= MAX_HASH_SIZE);

        memcpy(pConnProp->UserHash.pbHash, pbHashCert, cbHashCert);
        pConnProp->UserHash.cbHash = cbHashCert;

        *ppConnectionDataOut        = (BYTE*)pConnProp;
        *pdwSizeOfConnectionDataOut = pConnProp->dwSize;
    }

Error:
    pfnCertFreeCertificateContext(pCertContext);
    pfnCertCloseStore(hMyStore, 0);
    LocalFree(pbHashCert);

    if (fCapi2)
    {
        FreeCAPI2();
    }

    return FAILED(hr) ? ERROR_NOT_FOUND : dwErr;
}
Beispiel #28
0
DWORD
RasEapInvokeInteractiveUI(
    IN  DWORD           dwEapTypeId,
    IN  HWND            hwndParent,
    IN  BYTE*           pUIContextData,
    IN  DWORD           dwSizeofUIContextData,
    OUT BYTE**          ppDataFromInteractiveUI,
    OUT DWORD*          pdwSizeOfDataFromInteractiveUI
)
{
    HRESULT hr = E_FAIL;  // assume not supported

    UNREFERENCED_PARAMETER(dwSizeofUIContextData);
    
    if (PPP_EAP_TLS == dwEapTypeId)
    {
        EAPEXTUI_INPUT *pExtUIInput;
        *ppDataFromInteractiveUI = NULL;
        *pdwSizeOfDataFromInteractiveUI = 0;

        pExtUIInput = (EAPEXTUI_INPUT *)pUIContextData;

        if (NULL != pExtUIInput
            && pExtUIInput->dwVersion == 1
            && pExtUIInput->dwSize >= sizeof(EAPEXTUI_INPUT)
            )
        {
            hr = S_OK;  // assume success

            switch(pExtUIInput->dwCode)
            {
            default:
                CBR(FALSE);
            case EAPEXTUI_CODE_CLIENTAUTH_ERROR:                        
                break;
            case EAPEXTUI_CODE_SERVERAUTH_ERROR:
            {
                TCHAR   szMutexName[64];
                LPCTSTR pszErrorTitle;
                LPCTSTR pszErrorString;
                UINT    uStringID;
                UINT    uType = MB_OK;
                HANDLE  hMutex;

                if (pExtUIInput->fFlags & EAPEXTUI_FLAG_RESPONSE)
                {
                    // response expected
                    uType = MB_YESNO;
                }

                switch (pExtUIInput->dwStatus)
                {
                case SEC_E_UNTRUSTED_ROOT:
                    uStringID = IDS_NETUI_UNKNOWN_ROOT_ERROR;
                    break;
                case SEC_E_CERT_UNKNOWN:
                    uStringID = IDS_NETUI_UNKNOWN_CERT_ERROR;                    
                    break;
                case SEC_E_CERT_EXPIRED:
                    uStringID = IDS_NETUI_CERT_EXPIRED_ERROR;
                    break;
                default:
                    uStringID = IDS_NETUI_GENERIC_CERT_ERROR;
                    break;
                }

                pszErrorTitle = (LPCTSTR)LoadString(HINST_RESDLL, IDS_NETUI_SERVER_VALIDATION_ERROR, NULL, 0);
                CBRA(NULL != pszErrorTitle);

                pszErrorString = (LPCTSTR)LoadString(HINST_RESDLL, uStringID, NULL, 0);
                CBRA(NULL != pszErrorString);

                hr = StringCchPrintf(szMutexName, ARRAYSIZE(szMutexName),
                    TEXT("%s%X"), TEXT("IPInteractUI"), uStringID);
                CHR(hr);

                hMutex = CheckPrevInstance(szMutexName);
                if(INVALID_HANDLE_VALUE != hMutex)
                {
                    int nRet = MessageBox(SHGetLastActiveWindow(hwndParent), 
                        pszErrorString, pszErrorTitle,
                        uType | MB_TOPMOST | MB_SETFOREGROUND);

                    CloseHandle(hMutex);

                    if (pExtUIInput->fFlags & EAPEXTUI_FLAG_RESPONSE)
                    {
                        // response expected
                        EAPEXTUI_OUTPUT *pExtUIOutput = (EAPEXTUI_OUTPUT *)LocalAlloc(LPTR, sizeof(EAPEXTUI_OUTPUT));
                        if (pExtUIOutput)
                        {
                            pExtUIOutput->dwVersion =1;
                            pExtUIOutput->dwSize = sizeof(EAPEXTUI_OUTPUT);
                            pExtUIOutput->dwValue = nRet;
                            *ppDataFromInteractiveUI = (PBYTE)pExtUIOutput;
                            *pdwSizeOfDataFromInteractiveUI = pExtUIOutput->dwSize;
                        }
                    }
                }
            } // case  EAPEXTUI_CODE_SERVERAUTH_ERROR  
                break;
            }
        }
    }

Error:
    return SUCCEEDED(hr) ? NO_ERROR : ERROR_NOT_SUPPORTED;
}
Beispiel #29
0
void debayer_ccm_uyvy(unicap_data_buffer_t *destbuf, unicap_data_buffer_t *srcbuf,
                      debayer_data_t *data) {
    int i, j;
    int dest_offset = 0;
    unsigned char *dest = destbuf->data;
    unsigned char *source = srcbuf->data;
    int width = destbuf->format.size.width;
    int height = destbuf->format.size.height;

    for (j = 2; j < height - 2; j += 2) {
        int lineoffset = j * width;
        dest_offset = j * width * 2 + 2;

        for (i = 1; i < width - 2;) {
            int r, g, b;
            int g1 = source[lineoffset + i - 1];
            int g2 = source[lineoffset + i + 1];
            int g3 = source[(lineoffset + i) - width];
            int g4 = source[lineoffset + i + width];

            int d1 = ABS(g1 - g2);
            int d2 = ABS(g3 - g4);

            b = source[lineoffset + i];
            r = (((int)source[((lineoffset + i) - width) + 1] +
                  (int)source[(lineoffset + i + width) + 1] +
                  (int)source[((lineoffset + i) - width) - 1] +
                  (int)source[(lineoffset + i + width) - 1]) /
                 4);

            if (d1 < d2) {
                g = (g1 + g2) / 2;
            } else {
                g = (g3 + g4) / 2;
            }

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_V(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;

            g = g2;
            b = ((int)source[(lineoffset + i) - 1] + (int)source[(lineoffset + i) + 1]) / 2;
            r = ((int)source[(lineoffset + i) - width] + (int)source[lineoffset + i + width]) / 2;

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_U(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;
        }

        lineoffset += width;
        dest_offset = (j + 1) * width * 2 + 4;

        for (i = 2; i < width - 3;) {
            int r, g, b;
            int g1 = source[lineoffset + i - 1];
            int g2 = source[lineoffset + i + 1];
            int g3 = source[(lineoffset + i) - width];
            int g4 = source[lineoffset + i + width];

            int d1 = ABS(g1 - g2);
            int d2 = ABS(g3 - g4);

            r = source[lineoffset + i];

            if (d1 < d2) {
                g = (g1 + g2) / 2;
            }

            else {
                g = (g3 + g4) / 2;
            }

            b = (((int)source[((lineoffset + i) - width) + 1] +
                  (int)source[(lineoffset + i + width) + 1] +
                  (int)source[((lineoffset + i) - width) - 1] +
                  (int)source[(lineoffset + i + width) - 1]) /
                 4);

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_U(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;

            g = g2;
            r = ((int)source[(lineoffset + i) - 1] + (int)source[(lineoffset + i) + 1]) / 2;
            b = ((int)source[(lineoffset + i) - width] + (int)source[lineoffset + i + width]) / 2;

            if (data->use_ccm) {
                r = CLIP((r * CRR(data->ccm) + g * CRG(data->ccm) + b * CRB(data->ccm)) / 1024);
                g = CLIP((r * CGR(data->ccm) + g * CGG(data->ccm) + b * CGB(data->ccm)) / 1024);
                b = CLIP((r * CBR(data->ccm) + g * CBG(data->ccm) + b * CBB(data->ccm)) / 1024);
            } else if (data->use_rbgain) {
                r = CLIP((r * data->rgain) / 1024);
                b = CLIP((b * data->bgain) / 1024);
            }

            dest[dest_offset++] = YUV_V(r, g, b);
            dest[dest_offset++] = YUV_Y(r, g, b);

            i++;
        }
    }
}
Beispiel #30
0
IPSTATE GetIPState(LPCTSTR pszAdapter, LPTSTR pszAddress, UINT cchAddress)
{
    HRESULT              hr = S_OK;
    IPSTATE              state = IPSTATE_DHCP;
    ULONG                ulAdapterIndex;
    PIP_ADAPTER_INFO     paiBuffer = NULL;
    ULONG                cbBuffer = 0;
    DWORD                dwError;
    PIP_ADAPTER_INFO     paiCurrent;
    PIP_PER_ADAPTER_INFO pper = NULL;

    // Check inputs
    CBRAEx(NULL != pszAdapter, E_INVALIDARG);

    // Get the adapter index
    CBR(NO_ERROR == GetAdapterIndex(const_cast<LPWSTR>(pszAdapter), &ulAdapterIndex));

    // Get the status of all connected adapters
    cbBuffer = sizeof(IP_ADAPTER_INFO);
    paiBuffer = (PIP_ADAPTER_INFO)LocalAlloc(LMEM_FIXED, cbBuffer);
    CPR(paiBuffer);

    while (ERROR_BUFFER_OVERFLOW == (dwError = GetAdaptersInfo(paiBuffer, &cbBuffer)))
    {
        PIP_ADAPTER_INFO paiTemp = (PIP_ADAPTER_INFO)LocalReAlloc(paiBuffer, cbBuffer, LMEM_MOVEABLE);
        CPR(paiTemp);
        paiBuffer = paiTemp;
    }

    CBR(NO_ERROR == dwError);

    // Find our adapter index
    for (paiCurrent = paiBuffer; paiCurrent; paiCurrent = paiCurrent->Next)
    {
        if (paiCurrent->Index == ulAdapterIndex)
        {
            break;
        }
    }

    CBR(NULL != paiCurrent);  // did we find it?
    CBR(NULL != paiCurrent->CurrentIpAddress);

    // Is this adapter using DHCP?
    if (!paiCurrent->DhcpEnabled)
    {
        state = IPSTATE_CONNECTED;
    }
    else
    {
        // Get the per-adapter info
        cbBuffer = sizeof(IP_PER_ADAPTER_INFO);
        pper = (PIP_PER_ADAPTER_INFO)LocalAlloc(LMEM_FIXED, cbBuffer);
        CPR(pper);

        while (ERROR_BUFFER_OVERFLOW == (dwError = GetPerAdapterInfo(ulAdapterIndex, pper, &cbBuffer)))
        {
            PIP_PER_ADAPTER_INFO pperTemp = (PIP_PER_ADAPTER_INFO)LocalReAlloc(pper, cbBuffer, LMEM_MOVEABLE);
            CPR(pperTemp);
            pper = pperTemp;
        }

        CBR(NO_ERROR == dwError);

        // Are we using an automatic IP?
        if (pper->AutoconfigActive || IsAutoIPAddr(paiCurrent->CurrentIpAddress->IpAddress.String))
        {
            state = IPSTATE_AUTOIP;
        }
    }

    // Optionally copy the IP address string to the output
    if (NULL != pszAddress && 0 != cchAddress)
    {
        UINT cchInput = strlen(paiCurrent->CurrentIpAddress->IpAddress.String);
        if (cchInput >= cchAddress)
        {
            cchInput = cchAddress - 1;
        }

        MultiByteToWideChar(CP_ACP, 0,
            paiCurrent->CurrentIpAddress->IpAddress.String, cchInput,
            pszAddress, cchAddress);
        pszAddress[cchAddress-1] = TEXT('\0');
    }

Error:
    LocalFree(pper);
    LocalFree(paiBuffer);
    return (SUCCEEDED(hr) ? state : IPSTATE_DISCONNECTED);
}