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.

801 lines
21 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: ifobject.c
  7. //
  8. // Description: Routines to manipulate ROUTER_INTERFACE_OBJECTs
  9. //
  10. // History: May 11,1995 NarenG Created original version.
  11. //
  12. #include "dimsvcp.h"
  13. #include <netconp.h>
  14. //**
  15. //
  16. // Call: GetNewIfHandle
  17. //
  18. // Returns: Handle for new interface
  19. //
  20. // Description: Will generate an id that will be used for an handle to the new
  21. // interface.
  22. //
  23. HANDLE
  24. GetNewIfHandle(
  25. VOID
  26. )
  27. {
  28. static DWORD Id = 2;
  29. return( (HANDLE)UlongToPtr(Id++) );
  30. }
  31. //**
  32. //
  33. // Call: IfObjectAllocateAndInit
  34. //
  35. // Returns: ROUTER_INTERFACE_OBJECT * - Success
  36. // NULL - Failure
  37. //
  38. // Description: Allocates and initializes a ROUTER_INTERFACE_OBJECT structure
  39. //
  40. ROUTER_INTERFACE_OBJECT *
  41. IfObjectAllocateAndInit(
  42. IN LPWSTR lpwstrName,
  43. IN ROUTER_INTERFACE_STATE State,
  44. IN ROUTER_INTERFACE_TYPE IfType,
  45. IN HCONN hConnection,
  46. IN BOOL fEnabled,
  47. IN DWORD dwInterfaceReachableAfterSecondsMin,
  48. IN DWORD dwInterfaceReachableAfterSecondsMax,
  49. IN LPWSTR lpwsDialoutHoursRestriction
  50. )
  51. {
  52. DWORD dwRetCode;
  53. ROUTER_INTERFACE_OBJECT * pIfObject;
  54. DWORD dwIfObjectSize;
  55. DWORD dwTransportIndex;
  56. //
  57. // On a workstation we do not allow creation of demand-dial interfaces
  58. //
  59. if ( gblDIMConfigInfo.NtProductType == NtProductWinNt )
  60. {
  61. if ( ( IfType == ROUTER_IF_TYPE_FULL_ROUTER ) )
  62. {
  63. WCHAR * pChar = lpwstrName;
  64. DIMLogWarning( ROUTERLOG_LIMITED_WKSTA_SUPPORT,1, &pChar );
  65. SetLastError( ERROR_NOT_SUPPORTED );
  66. return( (ROUTER_INTERFACE_OBJECT *)NULL );
  67. }
  68. }
  69. //
  70. // Hardcode to 2 routermanagers, one for IP, one for IPX. We need to do this
  71. // because then we do not need to reallocate the size to accomodate a new protocol
  72. // when it is added dynamically to the router
  73. //
  74. dwIfObjectSize = sizeof( ROUTER_INTERFACE_OBJECT )
  75. + ( sizeof( ROUTER_INTERFACE_TRANSPORT ) * 2 );
  76. pIfObject = (ROUTER_INTERFACE_OBJECT *)LOCAL_ALLOC( LPTR, dwIfObjectSize );
  77. if ( pIfObject == (ROUTER_INTERFACE_OBJECT *)NULL )
  78. {
  79. return( (ROUTER_INTERFACE_OBJECT *)NULL );
  80. }
  81. pIfObject->lpwsInterfaceName = (LPWSTR)LOCAL_ALLOC( LPTR,
  82. (wcslen(lpwstrName)+1)
  83. * sizeof(WCHAR) );
  84. if ( pIfObject->lpwsInterfaceName == (LPWSTR)NULL )
  85. {
  86. IfObjectFree( pIfObject );
  87. return( (ROUTER_INTERFACE_OBJECT *)NULL );
  88. }
  89. if ( ( IfType == ROUTER_IF_TYPE_DEDICATED ) ||
  90. ( IfType == ROUTER_IF_TYPE_TUNNEL1 ) ||
  91. ( IfType == ROUTER_IF_TYPE_INTERNAL ) )
  92. {
  93. if ( !fEnabled )
  94. {
  95. WCHAR * pChar = lpwstrName;
  96. SetLastError( ERROR_INVALID_PARAMETER );
  97. DIMLogErrorString( ROUTERLOG_COULDNT_LOAD_IF, 1, &pChar,
  98. ERROR_INVALID_PARAMETER, 1 );
  99. IfObjectFree( pIfObject );
  100. return( (ROUTER_INTERFACE_OBJECT *)NULL );
  101. }
  102. }
  103. pIfObject->dwReachableAfterSecondsMin=dwInterfaceReachableAfterSecondsMin;
  104. pIfObject->dwReachableAfterSecondsMax=dwInterfaceReachableAfterSecondsMax;
  105. pIfObject->dwReachableAfterSeconds =dwInterfaceReachableAfterSecondsMin;
  106. wcscpy( pIfObject->lpwsInterfaceName, lpwstrName );
  107. pIfObject->State = State;
  108. pIfObject->IfType = IfType;
  109. pIfObject->hConnection = hConnection;
  110. pIfObject->hDIMInterface = ( IfType == ROUTER_IF_TYPE_LOOPBACK )
  111. ? (HANDLE)1
  112. : GetNewIfHandle();
  113. pIfObject->fFlags = ( fEnabled ) ? IFFLAG_ENABLED : 0;
  114. pIfObject->hEventNotifyCaller = INVALID_HANDLE_VALUE;
  115. //
  116. // Initialize the router manager handles
  117. //
  118. for ( dwTransportIndex = 0;
  119. dwTransportIndex < gblDIMConfigInfo.dwNumRouterManagers;
  120. dwTransportIndex++ )
  121. {
  122. pIfObject->Transport[dwTransportIndex].hInterface=INVALID_HANDLE_VALUE;
  123. }
  124. //
  125. // If we are running in LANONLYMode then we do not care about media bits
  126. //
  127. if ( gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN )
  128. {
  129. return( pIfObject );
  130. }
  131. if ( ( IfType == ROUTER_IF_TYPE_FULL_ROUTER ) )
  132. {
  133. DWORD (*IfObjectLoadPhonebookInfo)( ROUTER_INTERFACE_OBJECT * ) =
  134. (DWORD(*)( ROUTER_INTERFACE_OBJECT * ))
  135. GetDDMEntryPoint("IfObjectLoadPhonebookInfo");
  136. //
  137. // Load phonebook information for this interface
  138. //
  139. dwRetCode = IfObjectLoadPhonebookInfo( pIfObject );
  140. if ( dwRetCode != NO_ERROR )
  141. {
  142. if ( dwRetCode == ERROR_INTERFACE_HAS_NO_DEVICES )
  143. {
  144. pIfObject->fFlags |= IFFLAG_OUT_OF_RESOURCES;
  145. }
  146. else
  147. {
  148. WCHAR * pChar = lpwstrName;
  149. DIMLogErrorString( ROUTERLOG_COULDNT_LOAD_IF, 1, &pChar,
  150. dwRetCode, 1 );
  151. SetLastError( dwRetCode );
  152. IfObjectFree( pIfObject );
  153. return( NULL );
  154. }
  155. }
  156. pIfObject->lpwsDialoutHoursRestriction = lpwsDialoutHoursRestriction;
  157. }
  158. return( pIfObject );
  159. }
  160. //**
  161. //
  162. // Call: IfObjectInsertInTable
  163. //
  164. // Returns: NO_ERROR - Success
  165. // ERROR_MAX_WAN_INTERFACE_LIMIT - Failure
  166. // ERROR_MAX_LAN_INTERFACE_LIMIT - Failure
  167. // ERROR_MAX_CLIENT_INTERFACE_LIMIT - Failure
  168. //
  169. // Description: Will insert this interface object into the interface object
  170. // table
  171. //
  172. DWORD
  173. IfObjectInsertInTable(
  174. IN ROUTER_INTERFACE_OBJECT * pIfObject
  175. )
  176. {
  177. DWORD dwBucketIndex=IfObjectHashIfHandleToBucket(pIfObject->hDIMInterface);
  178. if ( pIfObject->IfType == ROUTER_IF_TYPE_FULL_ROUTER )
  179. {
  180. if ( gblInterfaceTable.dwNumWanInterfaces == DIM_MAX_WAN_INTERFACES )
  181. {
  182. return( ERROR_MAX_WAN_INTERFACE_LIMIT );
  183. }
  184. else
  185. {
  186. gblInterfaceTable.dwNumWanInterfaces++;
  187. }
  188. }
  189. else if ( pIfObject->IfType == ROUTER_IF_TYPE_DEDICATED )
  190. {
  191. if ( gblInterfaceTable.dwNumLanInterfaces == DIM_MAX_LAN_INTERFACES )
  192. {
  193. return( ERROR_MAX_LAN_INTERFACE_LIMIT );
  194. }
  195. else
  196. {
  197. gblInterfaceTable.dwNumLanInterfaces++;
  198. }
  199. }
  200. else if ( pIfObject->IfType == ROUTER_IF_TYPE_CLIENT )
  201. {
  202. if (gblInterfaceTable.dwNumClientInterfaces==DIM_MAX_CLIENT_INTERFACES)
  203. {
  204. return( ERROR_MAX_CLIENT_INTERFACE_LIMIT );
  205. }
  206. else
  207. {
  208. gblInterfaceTable.dwNumClientInterfaces++;
  209. }
  210. }
  211. pIfObject->pNext = gblInterfaceTable.IfBucket[dwBucketIndex];
  212. gblInterfaceTable.IfBucket[dwBucketIndex] = pIfObject;
  213. gblInterfaceTable.dwNumTotalInterfaces++;
  214. return( NO_ERROR );
  215. }
  216. //**
  217. //
  218. // Call:
  219. //
  220. // Returns:
  221. //
  222. // Description:
  223. //
  224. ROUTER_INTERFACE_OBJECT *
  225. IfObjectGetPointer(
  226. IN HANDLE hDIMInterface
  227. )
  228. {
  229. DWORD dwBucketIndex;
  230. ROUTER_INTERFACE_OBJECT * pIfObject;
  231. dwBucketIndex = IfObjectHashIfHandleToBucket(hDIMInterface);
  232. for( pIfObject = gblInterfaceTable.IfBucket[dwBucketIndex];
  233. pIfObject != (ROUTER_INTERFACE_OBJECT *)NULL;
  234. pIfObject = pIfObject->pNext )
  235. {
  236. if ( pIfObject->hDIMInterface == hDIMInterface )
  237. {
  238. return( pIfObject );
  239. }
  240. }
  241. return( (ROUTER_INTERFACE_OBJECT *)NULL );
  242. }
  243. //**
  244. //
  245. // Call: IfObjectHashIfHandleToBucket
  246. //
  247. // Returns:
  248. //
  249. // Description:
  250. //
  251. DWORD
  252. IfObjectHashIfHandleToBucket(
  253. IN HANDLE hDIMInterface
  254. )
  255. {
  256. return( (DWORD)((ULONG_PTR)hDIMInterface) % NUM_IF_BUCKETS );
  257. }
  258. //**
  259. //
  260. // Call: IfObjectRemove
  261. //
  262. // Returns:
  263. //
  264. // Description:
  265. //
  266. VOID
  267. IfObjectRemove(
  268. IN HANDLE hDIMInterface
  269. )
  270. {
  271. DWORD dwBucketIndex;
  272. ROUTER_INTERFACE_OBJECT * pIfObject;
  273. ROUTER_INTERFACE_OBJECT * pIfObjectPrev;
  274. dwBucketIndex = IfObjectHashIfHandleToBucket(hDIMInterface);
  275. pIfObject = gblInterfaceTable.IfBucket[dwBucketIndex];
  276. pIfObjectPrev = pIfObject;
  277. while( pIfObject != (ROUTER_INTERFACE_OBJECT *)NULL )
  278. {
  279. if ( pIfObject->hDIMInterface == hDIMInterface )
  280. {
  281. if ( gblInterfaceTable.IfBucket[dwBucketIndex] == pIfObject )
  282. {
  283. gblInterfaceTable.IfBucket[dwBucketIndex] = pIfObject->pNext;
  284. }
  285. else
  286. {
  287. pIfObjectPrev->pNext = pIfObject->pNext;
  288. }
  289. gblInterfaceTable.dwNumTotalInterfaces--;
  290. if ( pIfObject->IfType == ROUTER_IF_TYPE_FULL_ROUTER )
  291. {
  292. gblInterfaceTable.dwNumWanInterfaces--;
  293. }
  294. else if ( pIfObject->IfType == ROUTER_IF_TYPE_DEDICATED )
  295. {
  296. gblInterfaceTable.dwNumLanInterfaces--;
  297. }
  298. else if ( pIfObject->IfType == ROUTER_IF_TYPE_CLIENT )
  299. {
  300. gblInterfaceTable.dwNumClientInterfaces--;
  301. }
  302. IfObjectFree( pIfObject );
  303. return;
  304. }
  305. pIfObjectPrev = pIfObject;
  306. pIfObject = pIfObject->pNext;
  307. }
  308. }
  309. //**
  310. //
  311. // Call: IfObjectFree
  312. //
  313. // Returns: NO_ERROR - Success
  314. // Non-zero returns - Failure
  315. //
  316. // Description: Will release all memory allocated for the interfae object.
  317. //
  318. VOID
  319. IfObjectFree(
  320. IN ROUTER_INTERFACE_OBJECT * pIfObject
  321. )
  322. {
  323. if ( pIfObject->lpwsInterfaceName != NULL )
  324. {
  325. LOCAL_FREE( pIfObject->lpwsInterfaceName );
  326. }
  327. if ( pIfObject->lpwsDialoutHoursRestriction != NULL )
  328. {
  329. LOCAL_FREE( pIfObject->lpwsDialoutHoursRestriction );
  330. }
  331. LOCAL_FREE( pIfObject );
  332. }
  333. //**
  334. //
  335. // Call: IfObjectGetPointerByName
  336. //
  337. // Returns:
  338. //
  339. // Description:
  340. //
  341. ROUTER_INTERFACE_OBJECT *
  342. IfObjectGetPointerByName(
  343. IN LPWSTR lpwstrName,
  344. IN BOOL fIncludeClientInterfaces
  345. )
  346. {
  347. DWORD dwBucketIndex;
  348. ROUTER_INTERFACE_OBJECT * pIfObject;
  349. for ( dwBucketIndex = 0; dwBucketIndex < NUM_IF_BUCKETS; dwBucketIndex++ )
  350. {
  351. for( pIfObject = gblInterfaceTable.IfBucket[dwBucketIndex];
  352. pIfObject != (ROUTER_INTERFACE_OBJECT *)NULL;
  353. pIfObject = pIfObject->pNext )
  354. {
  355. if ( _wcsicmp( pIfObject->lpwsInterfaceName, lpwstrName ) == 0 )
  356. {
  357. if ( pIfObject->IfType == ROUTER_IF_TYPE_CLIENT )
  358. {
  359. if ( fIncludeClientInterfaces )
  360. {
  361. return( pIfObject );
  362. }
  363. else
  364. {
  365. continue;
  366. }
  367. }
  368. return( pIfObject );
  369. }
  370. }
  371. }
  372. return( (ROUTER_INTERFACE_OBJECT *)NULL );
  373. }
  374. //**
  375. //
  376. // Call: IfObjectDoesLanInterfaceExist
  377. //
  378. // Returns: NO_ERROR - Success
  379. // Non-zero returns - Failure
  380. //
  381. // Description:
  382. //
  383. BOOL
  384. IfObjectDoesLanInterfaceExist(
  385. VOID
  386. )
  387. {
  388. DWORD dwBucketIndex;
  389. ROUTER_INTERFACE_OBJECT * pIfObject;
  390. for ( dwBucketIndex = 0; dwBucketIndex < NUM_IF_BUCKETS; dwBucketIndex++ )
  391. {
  392. for( pIfObject = gblInterfaceTable.IfBucket[dwBucketIndex];
  393. pIfObject != (ROUTER_INTERFACE_OBJECT *)NULL;
  394. pIfObject = pIfObject->pNext )
  395. {
  396. if ( pIfObject->IfType == ROUTER_IF_TYPE_DEDICATED )
  397. {
  398. return( TRUE );
  399. }
  400. }
  401. }
  402. return( FALSE );
  403. }
  404. //**
  405. //
  406. // Call: IfObjectWANDeviceInstalled
  407. //
  408. // Returns: None
  409. //
  410. // Description: Called by DDM whenever a WAN device is installed or removed
  411. //
  412. VOID
  413. IfObjectWANDeviceInstalled(
  414. IN BOOL fWANDeviceInstalled
  415. )
  416. {
  417. DWORD dwXportIndex = GetTransportIndex( PID_IP );
  418. //
  419. // If a WAN device is installed and IP is installed then we
  420. // start advertizing on specific multicast address so as to make this
  421. // router discoverable
  422. //
  423. if ( ( fWANDeviceInstalled ) && ( dwXportIndex != (DWORD)-1 ) )
  424. {
  425. DWORD dwRetCode =
  426. gblRouterManagers[dwXportIndex].DdmRouterIf.SetRasAdvEnable(
  427. fWANDeviceInstalled );
  428. DIMTRACE2( "Calling SetRasAdvEnable( %d ) = %d",
  429. fWANDeviceInstalled, dwRetCode );
  430. }
  431. }
  432. //**
  433. //
  434. // Call: IfObjectNotifyOfMediaSenseChange
  435. //
  436. // Returns: None
  437. //
  438. // Description: Notifies the object of change in reachablity status due to
  439. // media sense.
  440. //
  441. //
  442. VOID
  443. IfObjectNotifyOfMediaSenseChange(
  444. VOID
  445. )
  446. {
  447. DWORD dwBucketIndex;
  448. ROUTER_INTERFACE_OBJECT * pIfObject;
  449. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  450. for ( dwBucketIndex = 0; dwBucketIndex < NUM_IF_BUCKETS; dwBucketIndex++ )
  451. {
  452. for( pIfObject = gblInterfaceTable.IfBucket[dwBucketIndex];
  453. pIfObject != (ROUTER_INTERFACE_OBJECT *)NULL;
  454. pIfObject = pIfObject->pNext )
  455. {
  456. if ( pIfObject->IfType == ROUTER_IF_TYPE_DEDICATED )
  457. {
  458. DWORD dwInactiveReason;
  459. if ( IfObjectIsLANDeviceActive( pIfObject->lpwsInterfaceName,
  460. &dwInactiveReason ) )
  461. {
  462. if ( pIfObject->State != RISTATE_CONNECTED )
  463. {
  464. pIfObject->State = RISTATE_CONNECTED;
  465. pIfObject->fFlags &= ~IFFLAG_NO_MEDIA_SENSE;
  466. IfObjectNotifyOfReachabilityChange(
  467. pIfObject,
  468. TRUE,
  469. INTERFACE_NO_MEDIA_SENSE );
  470. }
  471. }
  472. else if ( dwInactiveReason == INTERFACE_NO_MEDIA_SENSE )
  473. {
  474. if ( pIfObject->State != RISTATE_DISCONNECTED )
  475. {
  476. pIfObject->State = RISTATE_DISCONNECTED;
  477. pIfObject->fFlags |= IFFLAG_NO_MEDIA_SENSE;
  478. IfObjectNotifyOfReachabilityChange(
  479. pIfObject,
  480. FALSE,
  481. INTERFACE_NO_MEDIA_SENSE );
  482. }
  483. }
  484. }
  485. }
  486. }
  487. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  488. }
  489. //**
  490. //
  491. // Call: IfObjectNotifyOfReachabilityChange
  492. //
  493. // Returns: None
  494. //
  495. // Description: Notifies the object of change in reachablity status due to
  496. // media sense.
  497. //
  498. //
  499. VOID
  500. IfObjectNotifyOfReachabilityChange(
  501. IN ROUTER_INTERFACE_OBJECT * pIfObject,
  502. IN BOOL fReachable,
  503. IN UNREACHABILITY_REASON dwReason
  504. )
  505. {
  506. DWORD dwIndex;
  507. WCHAR wchFriendlyName[MAX_INTERFACE_NAME_LEN+1];
  508. LPWSTR lpszFriendlyName = wchFriendlyName;
  509. for ( dwIndex = 0;
  510. dwIndex < gblDIMConfigInfo.dwNumRouterManagers;
  511. dwIndex++ )
  512. {
  513. if ( pIfObject->Transport[dwIndex].hInterface == INVALID_HANDLE_VALUE )
  514. {
  515. continue;
  516. }
  517. if ( fReachable )
  518. {
  519. DIMTRACE2( "Notifying Protocol = 0x%x, Interface=%ws is Reachable",
  520. gblRouterManagers[dwIndex].DdmRouterIf.dwProtocolId,
  521. pIfObject->lpwsInterfaceName );
  522. gblRouterManagers[dwIndex].DdmRouterIf.InterfaceReachable(
  523. pIfObject->Transport[dwIndex].hInterface );
  524. }
  525. else
  526. {
  527. DIMTRACE3(
  528. "Notifying Protocol = 0x%x,Interface=%ws is UnReachable=%d",
  529. gblRouterManagers[dwIndex].DdmRouterIf.dwProtocolId,
  530. pIfObject->lpwsInterfaceName,
  531. dwReason );
  532. gblRouterManagers[dwIndex].DdmRouterIf.InterfaceNotReachable(
  533. pIfObject->Transport[dwIndex].hInterface,
  534. dwReason );
  535. }
  536. }
  537. if ( MprConfigGetFriendlyName( gblDIMConfigInfo.hMprConfig,
  538. pIfObject->lpwsInterfaceName,
  539. wchFriendlyName,
  540. sizeof( wchFriendlyName ) ) != NO_ERROR )
  541. {
  542. wcscpy( wchFriendlyName, pIfObject->lpwsInterfaceName );
  543. }
  544. if ( fReachable )
  545. {
  546. DIMLogInformation(ROUTERLOG_IF_REACHABLE,1, &lpszFriendlyName );
  547. }
  548. else
  549. {
  550. DWORD dwEventLogId = 0;
  551. switch( dwReason )
  552. {
  553. case INTERFACE_OUT_OF_RESOURCES:
  554. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON1;
  555. break;
  556. case INTERFACE_CONNECTION_FAILURE:
  557. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON2;
  558. break;
  559. case INTERFACE_DISABLED:
  560. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON3;
  561. break;
  562. case INTERFACE_SERVICE_IS_PAUSED:
  563. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON4;
  564. break;
  565. case INTERFACE_DIALOUT_HOURS_RESTRICTION:
  566. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON5;
  567. break;
  568. case INTERFACE_NO_MEDIA_SENSE:
  569. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON6;
  570. break;
  571. case INTERFACE_NO_DEVICE:
  572. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON7;
  573. break;
  574. default:
  575. dwEventLogId = 0;
  576. break;
  577. }
  578. if ( dwEventLogId != 0 )
  579. {
  580. DIMLogInformation( dwEventLogId, 1, &lpszFriendlyName );
  581. }
  582. }
  583. }
  584. //**
  585. //
  586. // Call: IfObjectIsLANDeviceActive
  587. //
  588. // Returns: NO_ERROR - Success
  589. // Non-zero returns - Failure
  590. //
  591. // Description:
  592. //
  593. BOOL
  594. IfObjectIsLANDeviceActive(
  595. IN LPWSTR lpwsInterfaceName,
  596. OUT LPDWORD lpdwInactiveReason
  597. )
  598. {
  599. NETCON_STATUS NetConStatus;
  600. HRESULT hResult;
  601. BOOL fEnabled;
  602. GUID Guid;
  603. NTSTATUS NtStatus;
  604. UNICODE_STRING usTemp;
  605. //
  606. // First check media state
  607. //
  608. usTemp.Length = wcslen(lpwsInterfaceName) * sizeof(WCHAR);
  609. usTemp.MaximumLength = usTemp.Length + sizeof(WCHAR);
  610. usTemp.Buffer = lpwsInterfaceName;
  611. NtStatus = RtlGUIDFromString( &usTemp, &Guid );
  612. if ( NtStatus != STATUS_SUCCESS )
  613. {
  614. *lpdwInactiveReason = INTERFACE_NO_DEVICE;
  615. return( FALSE );
  616. }
  617. hResult = HrGetPnpDeviceStatus( &Guid, &NetConStatus );
  618. if ( HRESULT_CODE( hResult ) == NO_ERROR )
  619. {
  620. switch ( NetConStatus )
  621. {
  622. case NCS_MEDIA_DISCONNECTED:
  623. *lpdwInactiveReason = INTERFACE_NO_MEDIA_SENSE;
  624. return( FALSE );
  625. case NCS_CONNECTED:
  626. case NCS_INVALID_ADDRESS:
  627. case NCS_AUTHENTICATING:
  628. case NCS_CREDENTIALS_REQUIRED:
  629. case NCS_AUTHENTICATION_FAILED:
  630. case NCS_AUTHENTICATION_SUCCEEDED:
  631. {
  632. return( TRUE );
  633. }
  634. default:
  635. *lpdwInactiveReason = INTERFACE_NO_DEVICE;
  636. return( FALSE );
  637. }
  638. }
  639. else
  640. {
  641. *lpdwInactiveReason = INTERFACE_NO_DEVICE;
  642. return( FALSE );
  643. }
  644. return( TRUE );
  645. }
  646. //**
  647. //
  648. // Call: IfObjectDeleteInterface
  649. //
  650. // Returns: None
  651. //
  652. // Description: Delete this interface with all the router managers.
  653. //
  654. //
  655. VOID
  656. IfObjectDeleteInterfaceFromTransport(
  657. IN ROUTER_INTERFACE_OBJECT * pIfObject,
  658. IN DWORD dwPid
  659. )
  660. {
  661. DWORD dwIndex;
  662. DIM_ROUTER_INTERFACE * pDdmRouterIf;
  663. DWORD dwRetCode;
  664. for ( dwIndex = 0;
  665. dwIndex < gblDIMConfigInfo.dwNumRouterManagers;
  666. dwIndex++ )
  667. {
  668. if ( pIfObject->Transport[dwIndex].hInterface == INVALID_HANDLE_VALUE )
  669. {
  670. continue;
  671. }
  672. pDdmRouterIf=&(gblRouterManagers[dwIndex].DdmRouterIf);
  673. if ( pDdmRouterIf->dwProtocolId == dwPid )
  674. {
  675. dwRetCode = pDdmRouterIf->DeleteInterface(
  676. pIfObject->Transport[dwIndex].hInterface );
  677. if ( dwRetCode != NO_ERROR )
  678. {
  679. LPWSTR lpwsInsertStrings[2];
  680. lpwsInsertStrings[0] = pIfObject->lpwsInterfaceName;
  681. lpwsInsertStrings[1] = ( pDdmRouterIf->dwProtocolId == PID_IP )
  682. ? L"IP" : L"IPX";
  683. DIMLogErrorString( ROUTERLOG_COULDNT_REMOVE_INTERFACE, 2,
  684. lpwsInsertStrings, dwRetCode, 2 );
  685. }
  686. pIfObject->Transport[dwIndex].hInterface = INVALID_HANDLE_VALUE;
  687. }
  688. }
  689. }