Beispiel #1
0
HRESULT
CIcsManager::EnableIcs
(
    GUID&   PublicGuid,
    GUID&   PrivateGuid
)
{
    HRESULT     hr              =   S_OK;
    long        lPublicIndex    =   0;
    long        lPrivateIndex   =   0;

    hr = GetIndexByGuid( PublicGuid, &lPublicIndex );
    BAIL_ON_HRESULT_ERROR(hr);

    hr = GetIndexByGuid( PrivateGuid, &lPrivateIndex );
    BAIL_ON_HRESULT_ERROR(hr);

    // Check if the ICS on public/private interfaces are already enabled.
    // if so, no need to start ICS again.
    m_pList[lPublicIndex].RefreshSharingEnabled();
    m_pList[lPrivateIndex].RefreshSharingEnabled();

    if (m_pList[lPublicIndex].IsSharingEnabled() &&
        m_pList[lPublicIndex].IsPublic() &&
        m_pList[lPrivateIndex].IsSharingEnabled() &&
        m_pList[lPrivateIndex].IsPrivate())
    {
        BAIL();
    }

    //
    // Disable existing ICS first
    //
    DisableIcsOnAll();

    //
    // Enable new ICS
    //
    hr = m_pList[lPublicIndex].EnableAsPublic( );
    BAIL_ON_HRESULT_ERROR(hr);

    hr = m_pList[lPrivateIndex].EnableAsPrivate( );
    BAIL_ON_HRESULT_ERROR(hr);

error:
    return hr;
}
Beispiel #2
0
// Enable ICS on private interface
HRESULT
CIcsConnection::EnableAsPrivate
(
)
{
    HRESULT     hr  =   S_OK;

    hr = DisableSharing( );
    BAIL_ON_HRESULT_ERROR(hr);

    hr = m_pNSConfig->EnableSharing( ICSSHARINGTYPE_PRIVATE );
    BAIL_ON_HRESULT_ERROR(hr);

    (VOID) RefreshSharingEnabled( );

error:
    return hr;
}
Beispiel #3
0
//
// Retrieve the current ICS setting for an interface
//
HRESULT
CIcsConnection::RefreshSharingEnabled
(
)
{
    HRESULT                 hr          =   S_OK;
    VARIANT_BOOL            bEnabled    =   VARIANT_FALSE;
    SHARINGCONNECTIONTYPE   Type        =   ICSSHARINGTYPE_PUBLIC;

    hr =
    m_pNSConfig->get_SharingEnabled
    (
        &bEnabled
    );
    BAIL_ON_HRESULT_ERROR(hr);

    m_bSharingEnabled   =   (bEnabled == VARIANT_TRUE);
    m_bPublic           =   false;
    m_bPrivate          =   false;

    if (m_bSharingEnabled)
    {
        hr =
        m_pNSConfig->get_SharingConnectionType
        (
            &Type
        );
        BAIL_ON_HRESULT_ERROR(hr);

        m_bPublic   = (Type == ICSSHARINGTYPE_PUBLIC);
        m_bPrivate  = (Type == ICSSHARINGTYPE_PRIVATE);

        ASSERT( m_bPublic || m_bPrivate );
    }

error:
    return hr;
}
Beispiel #4
0
// disable ICS only when ICS is enabled
HRESULT
CIcsConnection::DisableSharing
(
)
{
    HRESULT     hr  =   S_OK;

    hr = RefreshSharingEnabled( );
    BAIL_ON_HRESULT_ERROR(hr);

    if (!m_bSharingEnabled)
    {
        hr = S_FALSE;
        BAIL( );
    }

    hr = m_pNSConfig->DisableSharing();
    BAIL_ON_HRESULT_ERROR(hr);

    (VOID) RefreshSharingEnabled( );

error:
    return hr;
}
Beispiel #5
0
//
// Find out if ICS is supported
//
HRESULT
CIcsManager::RefreshInstalled
(
)
{
    HRESULT         hr          =   S_OK;
    VARIANT_BOOL    bInstalled  =   VARIANT_FALSE;

    hr =
    m_pNSMgr->get_SharingInstalled
    (
        &bInstalled
    );
    BAIL_ON_HRESULT_ERROR(hr);

    m_bInstalled = (bInstalled == VARIANT_TRUE);

error:
    return hr;
}
Beispiel #6
0
HRESULT
CIcsManager::GetIndexByGuid
(
    GUID&       Guid,
    long*       plIndex
)
{
    HRESULT     hr      =   S_OK;
    long        lIndex  =   0;
    bool        bMatch  =   false;

    ASSERT(plIndex);

    ASSERT(m_pList);

    for ( lIndex = 0; lIndex < m_lNumConns; lIndex++ )
    {
        if (!(m_pList[lIndex].IsSupported( )))
        {
            continue;
        }

        bMatch = m_pList[lIndex].IsMatch( &Guid );
        if (bMatch)
        {
            (*plIndex) = lIndex;
            BAIL( );
        }
    }

    ASSERT(!bMatch);

    hr = E_INVALIDARG;
    BAIL_ON_HRESULT_ERROR(hr);


error:
    return hr;
}
Beispiel #7
0
// 
// The ICS manager initialization takes 3 steps --
// 1. Make sure that ICS is supported in the current version of Windows
// 2. Retrieve all the ICS connections
// 3. Initialize each connection
//
HRESULT
CIcsManager::InitIcsManager
(
)
{
    HRESULT                                 hr                  =   S_OK;
    IUnknown*                               pUnkEnum            =   nullptr;
    IEnumNetSharingEveryConnection*         pNSEConn            =   nullptr;
    INetSharingEveryConnectionCollection*   pConnectionsList    =   nullptr;
    INetConnection*                         pNetConnection      =   nullptr;
    LONG                                    lIndex              =   0;
    VARIANT_BOOL                            bSharingEnabled     =   VARIANT_FALSE;
    VARIANT                                 varItem;
    ULONG                                   pceltFetched;

    VariantInit(&varItem);

    if (m_pNSMgr)
    {
        hr = E_UNEXPECTED;
        BAIL_ON_HRESULT_ERROR(hr);
    }

    hr =
    CoCreateInstance
    (
        __uuidof(NetSharingManager),
        nullptr,
        CLSCTX_ALL,
        __uuidof(INetSharingManager),
        reinterpret_cast<void**>(&m_pNSMgr)
    );
    BAIL_ON_HRESULT_ERROR(hr);
    ASSERT(m_pNSMgr);


    hr =
    RefreshInstalled
    (
    );
    BAIL_ON_HRESULT_ERROR(hr);

    if (!m_bInstalled)
    {
        hr = E_UNEXPECTED;
        BAIL_ON_HRESULT_ERROR(hr);
    }

    hr =
    m_pNSMgr->get_EnumEveryConnection
    (
        &pConnectionsList
    );
    BAIL_ON_HRESULT_ERROR(hr);
    ASSERT(pConnectionsList);

    hr =
    pConnectionsList->get__NewEnum
    (
        &pUnkEnum
    );
    BAIL_ON_HRESULT_ERROR(hr);
    ASSERT(pUnkEnum);

    hr =
    pUnkEnum->QueryInterface
    (
        __uuidof(IEnumNetSharingEveryConnection),
        reinterpret_cast<void**>(&pNSEConn)
    );
    BAIL_ON_HRESULT_ERROR(hr);
    ASSERT(pNSEConn);

    m_lNumConns = 0;

    while (1)
    {
        VariantClear(&varItem);

        hr =
        pNSEConn->Next
        (
            1,
            &varItem,
            &pceltFetched    
        );
        BAIL_ON_HRESULT_ERROR(hr);

        if (S_FALSE == hr)
        {
            hr = S_OK;
            break;
        }

        m_lNumConns++;

        ASSERT( (V_VT(&varItem) == VT_UNKNOWN) && V_UNKNOWN(&varItem) );
    }

    hr = pNSEConn->Reset( );
    BAIL_ON_HRESULT_ERROR(hr);


    if (0 == m_lNumConns)
    {
        BAIL( );
    }

    m_pList = new(std::nothrow) CIcsConnection [m_lNumConns];
    if (!m_pList)
    {
        hr = E_OUTOFMEMORY;
        BAIL_ON_HRESULT_ERROR(hr);
    }


    lIndex = 0;
    while ( 1 )
    {
        SAFE_RELEASE(pNetConnection);
        VariantClear(&varItem);

        hr =
        pNSEConn->Next
        (
            1,
            &varItem,
            &pceltFetched
        );
        BAIL_ON_HRESULT_ERROR(hr);

        if (S_FALSE == hr)
        {
            hr = S_OK;
            break;
        }

        lIndex++;
        if (lIndex > m_lNumConns)
        {
            hr = E_UNEXPECTED;
            BAIL_ON_HRESULT_ERROR(hr);
        }


        ASSERT( (V_VT(&varItem) == VT_UNKNOWN) && V_UNKNOWN(&varItem) );

        hr =
        V_UNKNOWN(&varItem)->QueryInterface
        (
            __uuidof(INetConnection),
            reinterpret_cast<void**>(&pNetConnection)
        );
        BAIL_ON_HRESULT_ERROR(hr);
        ASSERT(pNetConnection);

        hr =
        m_pList[lIndex-1].InitIcsConnection
        (
            this,
            pNetConnection,
            lIndex-1
        );
        BAIL_ON_HRESULT_ERROR(hr);

    }

    ASSERT(lIndex == m_lNumConns);

error:

    SAFE_RELEASE(pNetConnection);
    VariantClear(&varItem);
    SAFE_RELEASE(pNSEConn);
    SAFE_RELEASE(pUnkEnum);
    SAFE_RELEASE(pConnectionsList);

    return hr;
}
Beispiel #8
0
//
// Initialize an ICS connection object
// 1. Make sure that ICS is supported and hardware is available
// 2. Retrieve the ICS configuration from the connection
//
HRESULT
CIcsConnection::InitIcsConnection
(
    CIcsManager*        pIcsMgr,
    INetConnection*     pNetConnection,
    LONG                lIndex
)
{
    HRESULT             hr          =   S_OK;
    NETCON_PROPERTIES*  pNCProps    =   nullptr;

    if (m_pIcsMgr)
    {
        hr = E_UNEXPECTED;
        BAIL_ON_HRESULT_ERROR(hr);
    }

    if (!(pIcsMgr && pNetConnection))
    {
        hr = E_INVALIDARG;
        BAIL_ON_HRESULT_ERROR(hr);
    }

    // No need to AddRef
    m_pIcsMgr   =   pIcsMgr;
    m_lIndex    =   lIndex;

    m_pNetConnection = pNetConnection;
    pNetConnection->AddRef( );

    hr =
    m_pNetConnection->GetProperties
    (
        &pNCProps
    );
    BAIL_ON_HRESULT_ERROR(hr);
    ASSERT(pNCProps);

    hr = NSModDuplicateNetconProperties(pNCProps, &m_NetConnProps);
    BAIL_ON_HRESULT_ERROR(hr);

    if ( NCM_LAN != m_NetConnProps.MediaType )
    {
        // Unsupported connection.
        hr = S_FALSE;
        BAIL( );
    }

    if (NCS_DISCONNECTED == m_NetConnProps.Status)
    {
        // Hardware is disabled
        hr = S_FALSE;
        BAIL();
    }

    hr =
    m_pIcsMgr->m_pNSMgr->get_INetSharingConfigurationForINetConnection
    (
        pNetConnection,
        &m_pNSConfig
    );
    BAIL_ON_HRESULT_ERROR(hr);
    ASSERT(m_pNSConfig);

    hr = RefreshSharingEnabled( );
    BAIL_ON_HRESULT_ERROR(hr);

    m_bSupported = true;

error:
    SAFE_FREE_NCP(pNCProps);
    return hr;
}
HRESULT 
CWlanManager::AdviseHostedNetworkNotification(
    CHostedNetworkNotificationSink * pSink
    )
{
    HRESULT hr = S_OK;

    Lock();

    if (NULL == pSink)
    {
        BAIL_ON_HRESULT_ERROR(hr, E_INVALIDARG);
    }

    if (!m_Initialized)
    {
        BAIL_ON_WIN32_ERROR(ERROR_INVALID_STATE, hr);
    }

    if (m_NotificationSink != NULL)
    {
        BAIL_ON_HRESULT_ERROR(hr, E_FAIL);
    }

    //
    // Create callback complete event if needed
    //
    if (NULL == m_CallbackComplete)
    {
        m_CallbackComplete = CreateEvent(
                                    NULL,
                                    FALSE,        // manual reset
                                    TRUE,        // initial state
                                    NULL
                                    );

        if (NULL == m_CallbackComplete)
        {
            BAIL_ON_LAST_ERROR(hr);
        }
    }
    
    //
    // Set notification sink
    //
    m_NotificationSink = pSink;
    
    //
    // check if hosted network is supported
    //
    if (wlan_hosted_network_unavailable == m_HostedNetworkState)
    {
        pSink->OnHostedNetworkNotAvailable();
    }

    //
    // Check if hosted network is enabled
    //
    if (wlan_hosted_network_active == m_HostedNetworkState)
    {
        for (unsigned int i = 0; i < m_StationList.GetCount(); i++)
        {
            CWlanStation * pStation = m_StationList.GetAt(m_StationList.FindIndex(i));

            _ASSERT(pStation != NULL);

            pSink->OnStationJoin(pStation);
        }
    }

error:
    Unlock();

    return hr;
}