home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / surpriz / MSRMesh-VirtualWIFI.MSI / adapter.cpp next >
Encoding:
C/C++ Source or Header  |  2005-06-24  |  26.6 KB  |  932 lines

  1. /*
  2.  * Author   : Ranveer Chandra
  3.  * Directory: VirtualWiFi_Root\notifyob
  4.  * File Name: adapter.cpp
  5.  * Purpose  : Physical adapter class definition.
  6.  */
  7.  
  8. #include "adapter.h"
  9. #include "common.h"
  10.  
  11. #ifdef  CUSTOM_EVENTS
  12. #include "public.h"
  13. #endif
  14.  
  15. //+---------------------------------------------------------------------------
  16. //
  17. // Function:  CMuxPhysicalAdapter::CMuxPhysicalAdapter
  18. //
  19. // Purpose:   Constructor for class CMuxPhysicalAdapter
  20. //
  21. // Arguments: None
  22. //
  23. // Returns:
  24. //
  25. // Notes:
  26. //
  27.  
  28. CMuxPhysicalAdapter::CMuxPhysicalAdapter (INetCfg *pnc,
  29.                                           GUID *pguidAdapter)
  30. {
  31.  
  32.     TraceMsg( L"-->CMuxPhysicalAdapter::CMuxPhysicalAdapter(Constructor).\n" );
  33.  
  34.     m_pnc = pnc;
  35.     m_pnc->AddRef();
  36.  
  37.     CopyMemory( &m_guidAdapter,
  38.                 pguidAdapter,
  39.                 sizeof(GUID) );
  40.  
  41.     TraceMsg( L"<--CMuxPhysicalAdapter::CMuxPhysicalAdapter(Constructor).\n" );
  42. }
  43.  
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Function:  CMuxPhysicalAdapter::~CMuxPhysicalAdapter
  47. //
  48. // Purpose:   Destructor for class CMuxPhysicalAdapter
  49. //
  50. // Arguments: None
  51. //
  52. // Returns:
  53. //
  54. // Notes:
  55. //
  56.  
  57. CMuxPhysicalAdapter::~CMuxPhysicalAdapter (VOID)
  58. {
  59.     CMuxVirtualMiniport  *pMiniport;
  60.     DWORD                dwMiniportCount;
  61.     DWORD                i;
  62.  
  63.  
  64.     TraceMsg( L"-->CMuxPhysicalAdapter::~CMuxPhysicalAdapter(Destructor).\n" );
  65.  
  66.     //
  67.     // Delete all the instances representing the virtual miniports.
  68.     // We are only deleting the class instances, not uninstalling the
  69.     // the virtual miniports.
  70.     //
  71.  
  72.     dwMiniportCount = m_MiniportList.ListCount();
  73.  
  74.     for (i=0; i < dwMiniportCount; ++i) {
  75.  
  76.         m_MiniportList.Remove( &pMiniport );
  77.         delete pMiniport;
  78.     }
  79.  
  80.     dwMiniportCount = m_MiniportsToAdd.ListCount();
  81.  
  82.     for (i=0; i < dwMiniportCount; ++i) {
  83.  
  84.         m_MiniportsToAdd.Remove( &pMiniport );
  85.         delete pMiniport;
  86.     }
  87.  
  88.     dwMiniportCount = m_MiniportsToRemove.ListCount();
  89.  
  90.     for (i=0; i < dwMiniportCount; ++i) {
  91.  
  92.         m_MiniportsToRemove.Remove( &pMiniport );
  93.         delete pMiniport;
  94.     }
  95.  
  96.     ReleaseObj( m_pnc );
  97.  
  98.     TraceMsg( L"<--CMuxPhysicalAdapter::~CMuxPhysicalAdapter(Destructor).\n" );
  99.  
  100. }
  101.  
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Function:  CMuxPhysicalAdapter::LoadConfiguration
  105. //
  106. // Purpose:   Read the registry to get the device IDs of the 
  107. //            virtual miniports installed on the adapter and
  108. //            crate an instance to represent each virtual miniport.
  109. //
  110. // Arguments: None
  111. //
  112. // Returns: S_OK on success, otherwise an error code.
  113. //
  114. // Notes:
  115. //
  116.  
  117. HRESULT CMuxPhysicalAdapter::LoadConfiguration (VOID)
  118. {
  119.     HKEY                    hkeyAdapterGuid;
  120.     WCHAR                   szAdapterGuidKey[MAX_PATH+1];
  121.     WCHAR                   szAdapterGuid[MAX_PATH+1];
  122.     LPWSTR                  lpMiniportList;
  123.     LPWSTR                  lpMiniport;
  124.     LPWSTR                  lpMiniportGuid;
  125.     DWORD                   dwDisp;
  126.     CMuxVirtualMiniport     *pMiniport;
  127.     GUID                    guidMiniport;
  128.     DWORD                   dwBytes;
  129.     LONG                    lResult;
  130.  
  131.     TraceMsg( L"-->CMuxPhysicalAdapter::LoadConfiguration.\n" );
  132.  
  133.     //
  134.     // Build the registry key using the adapter guid under which 
  135.     // device IDs of the virtual miniports are stored.
  136.     //
  137.  
  138.     StringFromGUID2( m_guidAdapter,
  139.                     szAdapterGuid,
  140.                     MAX_PATH+1 );
  141.  
  142.     swprintf( szAdapterGuidKey,
  143.               L"%s\\%s",
  144.               c_szAdapterList,
  145.               szAdapterGuid );
  146.  
  147.     lResult = RegCreateKeyExW( HKEY_LOCAL_MACHINE,
  148.                                 szAdapterGuidKey,
  149.                                 0,
  150.                                 NULL,
  151.                                 REG_OPTION_NON_VOLATILE,
  152.                                 KEY_ALL_ACCESS,
  153.                                 NULL,
  154.                                 &hkeyAdapterGuid,
  155.                                 &dwDisp);
  156.  
  157.     if ( lResult == ERROR_SUCCESS ) {
  158.  
  159.         //
  160.         // If dwDisp indicates that a new key is created then, we know there
  161.         // is no virtual miniport currently listed underneath and we simply
  162.         // return.
  163.         //
  164.  
  165.         if ( dwDisp != REG_CREATED_NEW_KEY ) {
  166.  
  167.             dwBytes = 0;
  168.             lResult =  RegQueryValueExW(
  169.                                         hkeyAdapterGuid,
  170.                                         c_szUpperBindings,
  171.                                         NULL,
  172.                                         NULL,
  173.                                         NULL,
  174.                                         &dwBytes );
  175.  
  176.             lpMiniportList = (LPWSTR)calloc( dwBytes, 1 );
  177.  
  178.             if ( lpMiniportList ) {
  179.  
  180.                 lResult =  RegQueryValueExW(
  181.                                     hkeyAdapterGuid,
  182.                                     c_szUpperBindings,
  183.                                     NULL,
  184.                                     NULL,
  185.                                     (LPBYTE)lpMiniportList,
  186.                                     &dwBytes );
  187.  
  188.                 if ( lResult == ERROR_SUCCESS ) {
  189.  
  190.                     lpMiniport = lpMiniportList;
  191.  
  192. #ifndef PASSTHRU_NOTIFY
  193.  
  194.                     //
  195.                     // In case of mux, c_szUpperBindings is a multi_sz string.
  196.                     //
  197.  
  198.                     while ( wcslen(lpMiniport) ) {
  199.  
  200.                         lpMiniportGuid = RemoveDevicePrefix( lpMiniport );
  201.  
  202.                         TraceMsg( L"   Loading configuration for miniport %s...\n",
  203.                         lpMiniportGuid );
  204.  
  205.                         if ( lpMiniportGuid ) {
  206.  
  207.                             CLSIDFromString( lpMiniportGuid,
  208.                                              &guidMiniport );
  209.          
  210.                             //
  211.                             // Create an instance representing the virtual miniport.
  212.                             //
  213.  
  214.                             pMiniport = new CMuxVirtualMiniport( m_pnc,
  215.                                                                  &guidMiniport,
  216.                                                                  &m_guidAdapter );
  217.  
  218.                             if ( pMiniport ) {
  219.  
  220.                                 //
  221.                                 // Load any miniport specific configuration.
  222.                                 //
  223.  
  224.                                 pMiniport->LoadConfiguration();
  225.  
  226.                                 //
  227.                                 // Save the miniport instance in a list.
  228.                                 //
  229.  
  230.                                 m_MiniportList.Insert( pMiniport,
  231.                                                        guidMiniport );
  232.  
  233.                             }
  234.  
  235.                             free( lpMiniportGuid );
  236.                         }
  237.  
  238.                         //
  239.                         // Get next miniport guid.
  240.                         //
  241.  
  242.                         lpMiniport += wcslen(lpMiniport) + 1;
  243.                     }
  244.  
  245. #else
  246.  
  247.                     //
  248.                     // In case of the passthru driver, c_szUpperBindings is
  249.                     // a reg_sz string.
  250.                     //
  251.  
  252.                     lpMiniportGuid = RemoveDevicePrefix( lpMiniport );
  253.  
  254.                     TraceMsg( L"   Loading configuration for miniport %s...\n",
  255.                               lpMiniportGuid );
  256.  
  257.                     if ( lpMiniportGuid ) {
  258.  
  259.                         CLSIDFromString( lpMiniportGuid,
  260.                                          &guidMiniport );
  261.  
  262.                         //
  263.                         // Create an instance representing the virtual miniport.
  264.                         //
  265.  
  266.                         pMiniport = new CMuxVirtualMiniport( m_pnc,
  267.                                                              &guidMiniport,
  268.                                                              &m_guidAdapter );
  269.  
  270.                         if ( pMiniport ) {
  271.  
  272.                             //
  273.                             // Load any miniport specific configuration.
  274.                             //
  275.  
  276.                             pMiniport->LoadConfiguration();
  277.  
  278.                             //
  279.                             // Save the miniport instance in a list.
  280.                             //
  281.  
  282.                             m_MiniportList.Insert( pMiniport,
  283.                                                    guidMiniport );
  284.                         }
  285.  
  286.                         free( lpMiniportGuid );
  287.                     }
  288. #endif
  289.                 }
  290.                 else {
  291.                     TraceMsg( L"   Failed to read the registry value: %s.\n",
  292.                               c_szUpperBindings );
  293.                 }
  294.  
  295.                 free( lpMiniportList );
  296.             }
  297.             else {
  298.                 lResult = ERROR_NOT_ENOUGH_MEMORY;
  299.             }
  300.         }
  301.  
  302.         RegCloseKey( hkeyAdapterGuid );
  303.     }
  304.     else {
  305.  
  306.         TraceMsg( L"   Failed to open the registry key: %s.\n",
  307.                   szAdapterGuidKey );
  308.     }
  309.  
  310.     TraceMsg( L"<--CMuxPhysicalAdapter::LoadConfiguration(HRESULT = %x).\n",
  311.               HRESULT_FROM_WIN32(lResult) );
  312.  
  313.     return HRESULT_FROM_WIN32(lResult);
  314. }
  315.  
  316. //+---------------------------------------------------------------------------
  317. //
  318. // Function:  CMuxPhysicalAdapter::GetAdapterGUID
  319. //
  320. // Purpose:   Returns the adapter GUID.
  321. //
  322. // Arguments:
  323. //          OUT pguidAdapter:  GUID of the adapter returned.
  324. //
  325. // Returns: None.
  326. //
  327. // Notes:
  328. //
  329.  
  330. VOID CMuxPhysicalAdapter::GetAdapterGUID (GUID *pguidAdapter)
  331. {
  332.     TraceMsg( L"-->CMuxPhysicalAdapter::GetAdapterGUID.\n" );
  333.  
  334.     CopyMemory( pguidAdapter,
  335.                 &m_guidAdapter,
  336.                 sizeof(GUID) );
  337.  
  338.     TraceMsg( L"<--CMuxPhysicalAdapter::GetAdapterGUID.\n" );
  339. }
  340.  
  341. //+---------------------------------------------------------------------------
  342. //
  343. // Function:  CMuxPhysicalAdapter::AddMiniport
  344. //
  345. // Purpose:   Puts the miniport instance into the list of newly added miniports.
  346. //
  347. // Arguments:
  348. //          IN pMiniport:  A newly create miniport instance.
  349. //
  350. // Returns: S_OK on success, otherwize and error code.
  351. //
  352. // Notes:
  353. //
  354.  
  355. HRESULT CMuxPhysicalAdapter::AddMiniport (CMuxVirtualMiniport *pMiniport)
  356. {
  357.     GUID    guidMiniport;
  358.     HRESULT hr;
  359.  
  360.     TraceMsg( L"-->CMuxPhysicalAdapter::AddMiniport.\n" );
  361.  
  362.     pMiniport->GetMiniportGUID( &guidMiniport );
  363.  
  364.     hr = m_MiniportsToAdd.Insert( pMiniport,
  365.                                   guidMiniport );
  366.  
  367.     TraceMsg( L"<--CMuxPhysicalAdapter::AddMiniport(HRESULT = %x).\n",
  368.               hr );
  369.  
  370.     return hr;
  371. }
  372.  
  373. //+---------------------------------------------------------------------------
  374. //
  375. // Function:  CMuxPhysicalAdapter::RemoveMiniport
  376. //
  377. // Purpose:   Remove a specified miniport instance from the list and
  378. //            uninstalls the corresponding virtual miniport.
  379. //
  380. // Arguments:
  381. //          IN pguidMiniportToRemove: GUID of the miniport to be removed
  382. //                                    and uninstalled. If it is NULL then,
  383. //                                    the first miniport instance is removed.
  384. //
  385. // Returns: S_OK on success, otherwize and error code.
  386. //
  387. // Notes:
  388. //
  389.  
  390. HRESULT CMuxPhysicalAdapter::RemoveMiniport (GUID *pguidMiniportToRemove)
  391. {
  392.     CMuxVirtualMiniport  *pMiniport;
  393.     GUID                 guidMiniport;
  394.     HRESULT              hr;
  395.  
  396.     TraceMsg( L"-->CMuxPhysicalAdapter::RemoveMiniport.\n" );
  397.  
  398.     //
  399.     // If miniport GUID specified then, delete that one.
  400.     //
  401.  
  402.     if ( pguidMiniportToRemove ) {
  403.  
  404.         hr = m_MiniportList.RemoveByKey( *pguidMiniportToRemove,
  405.                                       &pMiniport );
  406.     }
  407.     else {
  408.  
  409.         //
  410.         // No GUID specified, so we just delete the first one.
  411.         //
  412.  
  413.         hr = m_MiniportList.Remove( &pMiniport );
  414.     }
  415.  
  416.     if ( hr == S_OK ) {
  417.  
  418.         pMiniport->GetMiniportGUID( &guidMiniport );
  419.  
  420.         m_MiniportsToRemove.Insert( pMiniport,
  421.                                     guidMiniport );
  422.         pMiniport->DeInstall();
  423.     }
  424.  
  425.     TraceMsg( L"<--CMuxPhysicalAdapter::RemoveMiniport(HRESULT = %x).\n",
  426.               hr );
  427.  
  428.     return hr;
  429. }
  430.  
  431. //+---------------------------------------------------------------------------
  432. //
  433. // Function:  CMuxPhysicalAdapter::Remove
  434. //
  435. // Purpose:   Uninstall all the instances of virtual miniports.
  436. //
  437. // Arguments: None
  438. //
  439. // Returns: S_OK.
  440. //
  441. // Notes:
  442. //
  443.  
  444. HRESULT CMuxPhysicalAdapter::Remove (VOID)
  445. {
  446.     CMuxVirtualMiniport  *pMiniport;
  447.     GUID                    guidMiniport;
  448.     DWORD                   dwMiniportCount;
  449.     DWORD                   i;
  450.  
  451.     TraceMsg( L"-->CMuxPhysicalAdapter::Remove.\n" );
  452.  
  453.     dwMiniportCount = m_MiniportList.ListCount();
  454.  
  455.     TraceMsg ( L"   Removing %d miniports.\n",
  456.                dwMiniportCount );
  457.  
  458.     for (i=0; i < dwMiniportCount; ++i) {
  459.  
  460.         m_MiniportList.Remove( &pMiniport );
  461.         pMiniport->GetMiniportGUID( &guidMiniport );
  462.         m_MiniportsToRemove.Insert( pMiniport,
  463.                                     guidMiniport );
  464.         pMiniport->DeInstall();
  465.     }
  466.  
  467.     TraceMsg( L"<--CMuxPhysicalAdapter::Remove(HRESULT = %x).\n",
  468.               S_OK );
  469.  
  470.     return S_OK;
  471. }
  472.  
  473. //+---------------------------------------------------------------------------
  474. //
  475. // Function:  CMuxPhysicalAdapter::ApplyRegistryChanges
  476. //
  477. // Purpose:   Update the registry depending on the actions performed.
  478. //
  479. // Arguments:
  480. //          IN eApplyAction:  Action that was last performed.
  481. //                            
  482. //
  483. // Returns: S_OK.
  484. //
  485. // Notes:
  486. //        More than one action could have been performed by the user
  487. //        but this function is called only once at the end. So, the argument
  488. //        only denotes the very last action performed. For example, if the 
  489. //        user deletes one miniport and adds two miniports then, the argument
  490. //        will denote an add action.
  491. //
  492.  
  493. HRESULT CMuxPhysicalAdapter::ApplyRegistryChanges (ConfigAction eApplyAction)
  494. {
  495.     HKEY                    hkeyAdapterList;
  496.     HKEY                    hkeyAdapterGuid;
  497.     WCHAR                   szAdapterGuid[MAX_PATH+1];
  498.     CMuxVirtualMiniport     *pMiniport = NULL;
  499.     DWORD                   dwMiniportCount;
  500.     DWORD                   dwDisp;
  501.     DWORD                   i;
  502.     LONG                    lResult;
  503.     HRESULT                 hr;
  504.  
  505.  
  506.     TraceMsg( L"-->CMuxPhysicalAdapter::ApplyRegistryChanges.\n" );
  507.  
  508.     //
  509.     // Open/create and then close the registry key to ensure that it does exist.
  510.     //
  511.  
  512.     StringFromGUID2( m_guidAdapter,
  513.                      szAdapterGuid,
  514.                      MAX_PATH+1 );
  515.  
  516.     lResult = RegCreateKeyExW( HKEY_LOCAL_MACHINE,
  517.                                c_szAdapterList,
  518.                                0,
  519.                                NULL,
  520.                                REG_OPTION_NON_VOLATILE,
  521.                                KEY_ALL_ACCESS,
  522.                                NULL,
  523.                                &hkeyAdapterList,
  524.                                &dwDisp);
  525.  
  526.  
  527.     if ( lResult == ERROR_SUCCESS ) {
  528.  
  529.         lResult = RegCreateKeyExW( hkeyAdapterList,
  530.                                    szAdapterGuid,
  531.                                    0,
  532.                                    NULL,
  533.                                    REG_OPTION_NON_VOLATILE,
  534.                                    KEY_ALL_ACCESS,
  535.                                    NULL,
  536.                                    &hkeyAdapterGuid,
  537.                                    &dwDisp);
  538.  
  539.         if ( lResult == ERROR_SUCCESS ) {
  540.  
  541.             RegCloseKey( hkeyAdapterGuid );
  542.         }
  543.         else {
  544.             TraceMsg( L"   Failed to create/open the registry key: %s\\%s.\n",
  545.                       c_szAdapterList, szAdapterGuid );
  546.         }
  547.  
  548.         RegCloseKey( hkeyAdapterList );
  549.     }
  550.     else {
  551.  
  552.         TraceMsg( L"   Failed to open the registry key: %s.\n",
  553.                   c_szAdapterList );
  554.     }
  555.  
  556.     //
  557.     // Update the registry in case there were new miniports installed.
  558.     //
  559.  
  560.     hr = HRESULT_FROM_WIN32( lResult );
  561.  
  562.     dwMiniportCount = m_MiniportsToAdd.ListCount();
  563.  
  564.     TraceMsg( L"   Applying registry changes when %d miniports added.\n",
  565.               dwMiniportCount );
  566.  
  567.     for (i=0; i < dwMiniportCount; ++i) {
  568.  
  569.         m_MiniportsToAdd.Find( i,
  570.                                &pMiniport );
  571.  
  572.         //
  573.         // Do virtual miniport specific registry changes.
  574.         //
  575.         // We need to tell the miniport instance explicitly what the action
  576.         // is.
  577.         //
  578.  
  579.         hr = pMiniport->ApplyRegistryChanges( eActAdd );
  580.  
  581.         if ( hr != S_OK ) {
  582.  
  583.             TraceMsg( L"   Failed to apply registry changes to miniport(%d).\n",
  584.                       i );
  585.  
  586.         }
  587.     }
  588.  
  589.  
  590.  
  591.     //
  592.     // Update the registry in case one or more miniports were uninstalled.
  593.     //
  594.  
  595.     dwMiniportCount = m_MiniportsToRemove.ListCount();
  596.  
  597.     TraceMsg( L"   Applying registry changes when %d miniports removed.\n",
  598.               dwMiniportCount );
  599.  
  600.     for (i=0; i < dwMiniportCount; ++i) {
  601.  
  602.         m_MiniportsToRemove.Find( i,
  603.                                   &pMiniport );
  604.  
  605.         //
  606.         // Do virtual miniport specific registry changes.
  607.         //
  608.         // We need to tell the miniport instance explicitly what the action
  609.         // is.
  610.         //
  611.  
  612.         hr = pMiniport->ApplyRegistryChanges( eActRemove );
  613.  
  614.         if ( hr != S_OK ) {
  615.  
  616.             TraceMsg( L"   Failed to apply registry changes to miniport(%d).\n",
  617.                       i );
  618.  
  619.         }
  620.     }
  621.  
  622.     //
  623.     // If the adapter is being removed or the protocol is being uninstalled,
  624.     // delete the adatper registry key.
  625.     //
  626.  
  627.     if ( eApplyAction == eActRemove ) {
  628.  
  629.         //
  630.         // Delete the adapter key.
  631.         //
  632.  
  633.         lResult = RegCreateKeyExW( HKEY_LOCAL_MACHINE,
  634.                                    c_szAdapterList,
  635.                                    0,
  636.                                    NULL,
  637.                                    REG_OPTION_NON_VOLATILE,
  638.                                    KEY_ALL_ACCESS,
  639.                                    NULL,
  640.                                    &hkeyAdapterList,
  641.                                    &dwDisp);
  642.  
  643.         if ( lResult == ERROR_SUCCESS ) {
  644.  
  645.             TraceMsg( L"   Deleting the registry key: %s.\n", szAdapterGuid );
  646.  
  647.             RegDeleteKeyW( hkeyAdapterList,
  648.                            szAdapterGuid );
  649.         }
  650.     }
  651.  
  652.     TraceMsg( L"<--CMuxPhysicalAdapter::ApplyRegistryChanges(HRESULT = %x).\n",
  653.             S_OK );
  654.  
  655.     return S_OK;
  656. }
  657.  
  658. //+---------------------------------------------------------------------------
  659. //
  660. // Function:  CMuxPhysicalAdapter::ApplyPnpChanges
  661. //
  662. // Purpose:   Apply the PnP changes depending on the actions performed.
  663. //
  664. // Arguments:
  665. //          IN pfCallback  :  SendPnpConfig Callback interface.
  666. //          IN eApplyAction:  Action that was last performed.
  667. //                            
  668. //
  669. // Returns: S_OK.
  670. //
  671. // Notes:
  672. //        More than one action could have been performed by the user
  673. //        but this function is called only once at the end. So, the argument
  674. //        only denotes the very last action performed. For example, if the 
  675. //        user deletes one miniport and adds two miniports then, the argument
  676. //        will denote an add action.
  677. //
  678.  
  679. HRESULT CMuxPhysicalAdapter::ApplyPnpChanges(
  680.                     INetCfgPnpReconfigCallback *pfCallback,
  681.                     ConfigAction eApplyAction)
  682. {
  683.     CMuxVirtualMiniport     *pMiniport;
  684.     GUID                    guidMiniport;
  685.     WCHAR                   szMiniportGuid[MAX_PATH+1];
  686.     LPWSTR                  lpDevice;
  687.     DWORD                   dwMiniportCount;
  688.     DWORD                   i;
  689.     DWORD                   dwBytes;
  690.     INetCfgComponent        *pncc;
  691.     HRESULT                 hr;
  692.  
  693. #ifdef CUSTOM_EVENTS    
  694.     LPWSTR                  lpszBindName;
  695.     PNOTIFY_CUSTOM_EVENT       lppnpEvent;
  696. #endif
  697.  
  698.     TraceMsg( L"-->CMuxPhysicalAdapter::ApplyPnpChanges.\n" );
  699.  
  700. #ifdef CUSTOM_EVENTS    
  701.  
  702.     //
  703.     // Find the instance of the adapter to get its bindname.
  704.     //
  705.  
  706.     hr = HrFindInstance( m_pnc,
  707.                          m_guidAdapter,
  708.                          &pncc );
  709.  
  710.     if ( hr == S_OK ) {
  711.  
  712.         hr = pncc->GetBindName( &lpszBindName );
  713.  
  714.         if ( hr != S_OK ) {
  715.             TraceMsg( L"  GetBindName failed.(HRESULT = %x). PnP changes will not "
  716.                       L"be applied and the driver will not be notified.\n",
  717.                       hr );
  718.         }
  719.  
  720.         ReleaseObj( pncc );
  721.     }
  722.     else {
  723.         TraceMsg( L"  PnP changes will not "
  724.                L"be applied and the driver will not be notified.\n",
  725.                hr );
  726.     }
  727.  
  728. #endif    
  729.  
  730.     dwMiniportCount = m_MiniportsToAdd.ListCount();
  731.  
  732.     TraceMsg( L"   Applying PnP changes to %d new miniports.\n",
  733.             dwMiniportCount );
  734.  
  735.     for (i=0; i < dwMiniportCount; ++i) {
  736.  
  737.         m_MiniportsToAdd.Remove( &pMiniport );
  738.  
  739.         pMiniport->GetMiniportGUID( &guidMiniport );
  740.  
  741.         m_MiniportList.Insert( pMiniport,
  742.                                guidMiniport );
  743.  
  744.         //
  745.         // Do miniport specific Pnp Changes when they are added.
  746.         //
  747.  
  748.         hr = pMiniport->ApplyPnpChanges( pfCallback,
  749.                                          eActAdd );
  750.  
  751. #ifdef CUSTOM_EVENTS
  752.  
  753.  
  754.         //
  755.         // Notify the driver that one or more virtual miniports have been added.
  756.         //
  757.  
  758.         StringFromGUID2( guidMiniport,
  759.                          szMiniportGuid,
  760.                          MAX_PATH+1 );
  761.         lpDevice = AddDevicePrefix( szMiniportGuid );
  762.  
  763.         if ( lpDevice ) {
  764.  
  765.             dwBytes = sizeof(NOTIFY_CUSTOM_EVENT) +
  766.                       ((wcslen(lpDevice) + 1) * sizeof(WCHAR));
  767.  
  768.             lppnpEvent = (PNOTIFY_CUSTOM_EVENT)malloc( dwBytes );
  769.  
  770.             if ( lppnpEvent ) {
  771.  
  772.                 lppnpEvent->uSignature = NOTIFY_SIGNATURE;
  773.                 lppnpEvent->uEvent = MUX_CUSTOM_EVENT;
  774.                 wcscpy( lppnpEvent->szMiniport,
  775.                        lpDevice );
  776.  
  777.                 hr = pfCallback->SendPnpReconfig( NCRL_NDIS,
  778.                                                  c_szMuxService,
  779.                                                  lpszBindName,
  780.                                                  (PVOID)lppnpEvent,
  781.                                                  dwBytes );
  782.  
  783.                 TraceMsg( L"   INetCfgPnpReconfigCallback->SendPnpReconfig returned "
  784.                          L"%#x.\n",
  785.                          hr );
  786.  
  787.                 if ( hr != S_OK ) {
  788.  
  789.                   TraceMsg( L"   Failed to apply Pnp changes, miniport(%d).\n",
  790.                             i );
  791.  
  792.                 }
  793.  
  794.                 free( lppnpEvent );
  795.             }
  796.             free( lpDevice );
  797.         }
  798. #endif        
  799.     }
  800.  
  801.     dwMiniportCount = m_MiniportsToRemove.ListCount();
  802.  
  803.     TraceMsg( L"   Applying PnP changes to %d removed miniports.\n",
  804.             dwMiniportCount );
  805.  
  806.     for (i=0; i < dwMiniportCount; ++i) {
  807.  
  808.         m_MiniportsToRemove.Remove( &pMiniport );
  809.  
  810.         pMiniport->GetMiniportGUID( &guidMiniport );
  811.  
  812.         //
  813.         // Do miniport specific Pnp Changes when they are uninstalled.
  814.         //
  815.  
  816.         hr = pMiniport->ApplyPnpChanges( pfCallback,
  817.                                          eActRemove );
  818.  
  819.         delete pMiniport;
  820.  
  821. #ifdef CUSTOM_EVENTS
  822.  
  823.         //
  824.         // Notify the driver that one or more virtual miniports have been
  825.         // uninstalled.
  826.         //
  827.         // We can't notify the driver in case the adapter or the protocol is
  828.         // being uninstalled because the binding handle doesn't exist.
  829.         //
  830.  
  831.         if ( eApplyAction != eActRemove ) {
  832.  
  833.             StringFromGUID2( guidMiniport,
  834.                              szMiniportGuid,
  835.                              MAX_PATH+1 );
  836.             lpDevice = AddDevicePrefix( szMiniportGuid );
  837.  
  838.             if ( lpDevice ) {
  839.  
  840.                 dwBytes = sizeof(NOTIFY_CUSTOM_EVENT) +
  841.                          ((wcslen(lpDevice) + 1) * sizeof(WCHAR));
  842.  
  843.                 lppnpEvent = (PNOTIFY_CUSTOM_EVENT)malloc( dwBytes );
  844.  
  845.                 if ( lppnpEvent ) {
  846.  
  847.                     lppnpEvent->uSignature = NOTIFY_SIGNATURE;
  848.                     lppnpEvent->uEvent = MUX_CUSTOM_EVENT;
  849.                     wcscpy( lppnpEvent->szMiniport,
  850.                           lpDevice );
  851.  
  852.                     hr = pfCallback->SendPnpReconfig( NCRL_NDIS,
  853.                                                     c_szMuxService,
  854.                                                     lpszBindName,
  855.                                                     (PVOID)lppnpEvent,
  856.                                                     dwBytes );
  857.                     TraceMsg( L"   INetCfgPnpReconfigCallback->SendPnpReconfig returned "
  858.                             L"%#x.\n",
  859.                             hr );
  860.  
  861.                     if ( hr != S_OK ) {
  862.  
  863.                         TraceMsg( L"   Failed to apply Pnp changes, miniport(%d).\n",
  864.                                i );
  865.  
  866.                     }
  867.  
  868.                     free( lppnpEvent );
  869.                 }
  870.  
  871.                 free( lpDevice );
  872.             }
  873.         }
  874. #endif         
  875.  
  876.     }
  877.  
  878. #ifdef CUSTOM_EVENTS    
  879.     CoTaskMemFree( lpszBindName );
  880. #endif
  881.  
  882.     TraceMsg( L"<--CMuxPhysicalAdapter::ApplyPnpChanges(HRESULT = %x).\n",
  883.             S_OK );
  884.  
  885.     return S_OK;
  886. }
  887.  
  888. //+---------------------------------------------------------------------------
  889. //
  890. // Function:  CMuxPhysicalAdapter::CancelChanges
  891. //
  892. // Purpose:   Cancel any changes made.
  893. //
  894. // Arguments: None
  895. //                            
  896. //
  897. // Returns: S_OK.
  898. //
  899. // Notes:
  900. //
  901.  
  902. HRESULT CMuxPhysicalAdapter::CancelChanges (VOID)
  903. {
  904.     TraceMsg( L"-->CMuxPhysicalAdapter::CancelChanges.\n" );
  905.  
  906.     TraceMsg( L"<--CMuxPhysicalAdapter::CancelChanges(HRESULT = %x).\n",
  907.             S_OK );
  908.  
  909.     return S_OK;
  910. }
  911.  
  912. //+---------------------------------------------------------------------------
  913. //
  914. // Function:  CMuxPhysicalAdapter::AllMiniportsRemoved
  915. //
  916. // Purpose:   Find out if there is no miniport installed on the adapter.
  917. //
  918. // Arguments: None
  919. //                            
  920. //
  921. // Returns: TRUE if all the miniports associated with this adapter have been
  922. //          uninstalled and there is none pending to be added, otherwise FALSE.
  923. //
  924. // Notes:
  925. //
  926.  
  927. BOOL  CMuxPhysicalAdapter::AllMiniportsRemoved (VOID)
  928. {
  929.   return (m_MiniportList.ListCount() + m_MiniportsToAdd.ListCount()) == 0;
  930. }
  931.  
  932.