Leaked source code of windows server 2003
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.

1155 lines
27 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: devobj.c
  7. //
  8. // Description: All procedures in devices.
  9. //
  10. // History: May 11,1995 NarenG Created original version.
  11. //
  12. #include "ddm.h"
  13. #include <winsvc.h>
  14. #include "objects.h"
  15. #include "handlers.h"
  16. #include <raserror.h>
  17. #include <dimif.h>
  18. #include "rasmanif.h"
  19. #include <stdlib.h>
  20. //**
  21. //
  22. // Call: DeviceObjIterator
  23. //
  24. // Returns:
  25. //
  26. // Description: Will iterate through all the devices and will call the
  27. // ProcessFunction for each one
  28. //
  29. DWORD
  30. DeviceObjIterator(
  31. IN DWORD (*pProcessFunction)( IN DEVICE_OBJECT *,
  32. IN LPVOID,
  33. IN DWORD,
  34. IN DWORD ),
  35. IN BOOL fReturnOnError,
  36. IN PVOID Parameter
  37. )
  38. {
  39. DEVICE_OBJECT * pDeviceObj;
  40. DWORD dwRetCode;
  41. DWORD dwDeviceIndex = 0;
  42. DWORD dwBucketIndex = 0;
  43. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  44. //
  45. // Iterate through the device table
  46. //
  47. for ( dwBucketIndex = 0;
  48. dwBucketIndex < gblDeviceTable.NumDeviceBuckets;
  49. dwBucketIndex++ )
  50. {
  51. for ( pDeviceObj = gblDeviceTable.DeviceBucket[dwBucketIndex];
  52. pDeviceObj != NULL;
  53. pDeviceObj = pDeviceObj->pNext )
  54. {
  55. dwRetCode = (*pProcessFunction)( pDeviceObj,
  56. Parameter,
  57. dwBucketIndex,
  58. dwDeviceIndex++ );
  59. if ( fReturnOnError && ( dwRetCode != NO_ERROR ) )
  60. {
  61. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  62. return( dwRetCode );
  63. }
  64. }
  65. }
  66. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  67. return( NO_ERROR );
  68. }
  69. //**
  70. //
  71. // Call: DeviceObjInsertInTable
  72. //
  73. // Returns: None
  74. //
  75. // Description Will insert a given device into the device table
  76. //
  77. VOID
  78. DeviceObjInsertInTable(
  79. IN DEVICE_OBJECT * pDeviceObj
  80. )
  81. {
  82. DWORD dwBucketIndex = DeviceObjHashPortToBucket( pDeviceObj->hPort );
  83. pDeviceObj->pNext = gblDeviceTable.DeviceBucket[dwBucketIndex];
  84. gblDeviceTable.DeviceBucket[dwBucketIndex] = pDeviceObj;
  85. gblDeviceTable.NumDeviceNodes++;
  86. //
  87. // Increase the count for this media type for routers only
  88. //
  89. if ( pDeviceObj->fFlags & DEV_OBJ_ALLOW_ROUTERS )
  90. {
  91. MediaObjAddToTable( pDeviceObj->wchDeviceType );
  92. }
  93. }
  94. //**
  95. //
  96. // Call: DeviceObjRemoveFromTable
  97. //
  98. // Returns: None
  99. //
  100. // Description Will remove a given device from the device table
  101. //
  102. VOID
  103. DeviceObjRemoveFromTable(
  104. IN HPORT hPort
  105. )
  106. {
  107. DWORD dwBucketIndex;
  108. DEVICE_OBJECT * pDeviceObj ;
  109. DEVICE_OBJECT * pDeviceObjPrev;
  110. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  111. dwBucketIndex = DeviceObjHashPortToBucket( hPort );
  112. pDeviceObj = gblDeviceTable.DeviceBucket[dwBucketIndex];
  113. pDeviceObjPrev = pDeviceObj;
  114. while( pDeviceObj != (DEVICE_OBJECT *)NULL )
  115. {
  116. if ( pDeviceObj->hPort == hPort )
  117. {
  118. BOOL fWANDeviceInstalled = FALSE;
  119. if ( gblDeviceTable.DeviceBucket[dwBucketIndex] == pDeviceObj )
  120. {
  121. gblDeviceTable.DeviceBucket[dwBucketIndex] = pDeviceObj->pNext;
  122. }
  123. else
  124. {
  125. pDeviceObjPrev->pNext = pDeviceObj->pNext;
  126. }
  127. gblDeviceTable.NumDeviceNodes--;
  128. RasServerPortClose ( hPort );
  129. if ( pDeviceObj->fFlags & DEV_OBJ_ALLOW_ROUTERS )
  130. {
  131. MediaObjRemoveFromTable( pDeviceObj->wchDeviceType );
  132. }
  133. LOCAL_FREE( pDeviceObj );
  134. //
  135. // Possibly need to notify router managers of reachability
  136. // change
  137. //
  138. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  139. IfObjectNotifyAllOfReachabilityChange( FALSE,
  140. INTERFACE_OUT_OF_RESOURCES );
  141. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  142. //
  143. // Tell DIM to update router identity object
  144. //
  145. ((VOID(*)(VOID))gblDDMConfigInfo.lpfnRouterIdentityObjectUpdate)();
  146. DeviceObjIterator(DeviceObjIsWANDevice,FALSE,&fWANDeviceInstalled);
  147. //
  148. // Tell DIM that a WAN device has been deinstalled and that it
  149. // should stop advertizing it's presence
  150. //
  151. ((VOID(*)( BOOL ))
  152. gblDDMConfigInfo.lpfnIfObjectWANDeviceInstalled)(
  153. fWANDeviceInstalled );
  154. break;
  155. }
  156. pDeviceObjPrev = pDeviceObj;
  157. pDeviceObj = pDeviceObj->pNext;
  158. }
  159. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  160. return;
  161. }
  162. //**
  163. //
  164. // Call:
  165. //
  166. // Returns:
  167. //
  168. // Description:
  169. //
  170. DWORD
  171. DeviceObjHashPortToBucket(
  172. IN HPORT hPort
  173. )
  174. {
  175. return( ((DWORD)HandleToUlong(hPort)) % gblDeviceTable.NumDeviceBuckets );
  176. }
  177. //**
  178. //
  179. // Call:
  180. //
  181. // Returns:
  182. //
  183. // Description:
  184. //
  185. DEVICE_OBJECT *
  186. DeviceObjGetPointer(
  187. IN HPORT hPort
  188. )
  189. {
  190. DEVICE_OBJECT * pDeviceObj;
  191. DWORD dwBucketIndex = DeviceObjHashPortToBucket( hPort );
  192. for ( pDeviceObj = gblDeviceTable.DeviceBucket[dwBucketIndex];
  193. pDeviceObj != NULL;
  194. pDeviceObj = pDeviceObj->pNext )
  195. {
  196. if ( pDeviceObj->hPort == hPort )
  197. {
  198. return( pDeviceObj );
  199. }
  200. }
  201. return( (DEVICE_OBJECT *)NULL );
  202. }
  203. //**
  204. //
  205. // Call: DeviceObjAllocAndInitialize
  206. //
  207. // Returns: DEVICE_OBJECT * - Success
  208. // NULL - Failure
  209. //
  210. // Description: Will allocate and initialize a device object
  211. //
  212. DEVICE_OBJECT *
  213. DeviceObjAllocAndInitialize(
  214. IN HPORT hPort,
  215. IN RASMAN_PORT* pRasmanPort
  216. )
  217. {
  218. DEVICE_OBJECT * pDeviceObj = NULL;
  219. RASMAN_INFO RasmanInfo;
  220. DWORD dwRetCode = RasGetInfo( NULL, hPort, &RasmanInfo );
  221. if( dwRetCode != NO_ERROR )
  222. {
  223. SetLastError( dwRetCode );
  224. return( NULL );
  225. }
  226. //
  227. // Allocate and initialize a Device CB
  228. //
  229. pDeviceObj = (DEVICE_OBJECT *)LOCAL_ALLOC( LPTR, sizeof(DEVICE_OBJECT) );
  230. if ( pDeviceObj == (DEVICE_OBJECT *)NULL )
  231. {
  232. return( NULL );
  233. }
  234. pDeviceObj->hPort = hPort;
  235. pDeviceObj->pNext = (DEVICE_OBJECT *)NULL;
  236. pDeviceObj->hConnection = (HCONN)INVALID_HANDLE_VALUE;
  237. pDeviceObj->DeviceState = DEV_OBJ_CLOSED;
  238. pDeviceObj->ConnectionState = DISCONNECTED;
  239. pDeviceObj->SecurityState = DEV_OBJ_SECURITY_DIALOG_INACTIVE;
  240. pDeviceObj->dwCallbackDelay = gblDDMConfigInfo.dwCallbackTime;
  241. pDeviceObj->fFlags = 0;
  242. pDeviceObj->dwHwErrorSignalCount = HW_FAILURE_CNT;
  243. pDeviceObj->wchCallbackNumber[0] = TEXT('\0');
  244. pDeviceObj->hRasConn = NULL;
  245. pDeviceObj->dwDeviceType = RasmanInfo.RI_rdtDeviceType;
  246. //
  247. // copy the port name,device type and device name in the dcb
  248. //
  249. MultiByteToWideChar(
  250. CP_ACP,
  251. 0,
  252. pRasmanPort->P_PortName,
  253. -1,
  254. pDeviceObj->wchPortName,
  255. MAX_PORT_NAME+1 );
  256. MultiByteToWideChar(
  257. CP_ACP,
  258. 0,
  259. pRasmanPort->P_MediaName,
  260. -1,
  261. pDeviceObj->wchMediaName,
  262. MAX_MEDIA_NAME+1 );
  263. if(ERROR_SUCCESS != RasGetUnicodeDeviceName(
  264. pRasmanPort->P_Handle,
  265. pDeviceObj->wchDeviceName))
  266. {
  267. DDMTRACE( "DeviceObjAllocAndInitialize GetUnicodeDviceName failed ******");
  268. MultiByteToWideChar(
  269. CP_ACP,
  270. 0,
  271. pRasmanPort->P_DeviceName,
  272. -1,
  273. pDeviceObj->wchDeviceName,
  274. MAX_DEVICE_NAME+1 );
  275. }
  276. MultiByteToWideChar(
  277. CP_ACP,
  278. 0,
  279. pRasmanPort->P_DeviceType,
  280. -1,
  281. pDeviceObj->wchDeviceType,
  282. MAX_DEVICETYPE_NAME+1 );
  283. if ( pRasmanPort->P_ConfiguredUsage & (CALL_IN | CALL_IN_ONLY))
  284. {
  285. pDeviceObj->fFlags |= DEV_OBJ_ALLOW_CLIENTS;
  286. }
  287. if ( pRasmanPort->P_ConfiguredUsage &
  288. (CALL_ROUTER | CALL_OUTBOUND_ROUTER) )
  289. {
  290. pDeviceObj->fFlags |= DEV_OBJ_ALLOW_ROUTERS;
  291. }
  292. return( pDeviceObj );
  293. }
  294. //**
  295. //
  296. // Call: DeviceObjStartClosing
  297. //
  298. // Returns: NO_ERROR
  299. //
  300. // Description: Close all active devices; if no devices have been initialized
  301. // and opened then this part is skipped.
  302. //
  303. DWORD
  304. DeviceObjStartClosing(
  305. IN DEVICE_OBJECT * pDeviceObj,
  306. IN PVOID Parameter,
  307. IN DWORD dwBucketIndex,
  308. IN DWORD dwDeviceIndex
  309. )
  310. {
  311. UNREFERENCED_PARAMETER( Parameter );
  312. UNREFERENCED_PARAMETER( dwBucketIndex );
  313. UNREFERENCED_PARAMETER( dwDeviceIndex );
  314. if ( pDeviceObj->fFlags & DEV_OBJ_OPENED_FOR_DIALOUT )
  315. {
  316. RasApiCleanUpPort( pDeviceObj );
  317. }
  318. if ( ( pDeviceObj->DeviceState != DEV_OBJ_CLOSED ) &&
  319. ( pDeviceObj->DeviceState != DEV_OBJ_CLOSING ) )
  320. {
  321. if ( pDeviceObj->fFlags & DEV_OBJ_PPP_IS_ACTIVE )
  322. {
  323. PppDdmStop( (HPORT)pDeviceObj->hPort, NO_ERROR );
  324. }
  325. else
  326. {
  327. DevStartClosing( pDeviceObj );
  328. }
  329. }
  330. return( NO_ERROR );
  331. }
  332. //**
  333. //
  334. // Call: DeviceObjPostListen
  335. //
  336. // Returns:
  337. //
  338. // Description:
  339. //
  340. DWORD
  341. DeviceObjPostListen(
  342. IN DEVICE_OBJECT * pDeviceObj,
  343. IN PVOID Parameter,
  344. IN DWORD dwBucketIndex,
  345. IN DWORD dwDeviceIndex
  346. )
  347. {
  348. DWORD Type;
  349. //UNREFERENCED_PARAMETER( Parameter );
  350. UNREFERENCED_PARAMETER( dwBucketIndex );
  351. UNREFERENCED_PARAMETER( dwDeviceIndex );
  352. if(NULL != Parameter)
  353. {
  354. Type = *((DWORD *) (Parameter));
  355. if(RAS_DEVICE_TYPE(pDeviceObj->dwDeviceType) != Type)
  356. {
  357. return NO_ERROR;
  358. }
  359. }
  360. pDeviceObj->DeviceState = DEV_OBJ_LISTENING;
  361. RmListen( pDeviceObj );
  362. return( NO_ERROR );
  363. }
  364. //**
  365. //
  366. // Call:
  367. //
  368. // Returns:
  369. //
  370. // Description:
  371. //
  372. DWORD
  373. DeviceObjIsClosed(
  374. IN DEVICE_OBJECT * pDeviceObj,
  375. IN PVOID Parameter,
  376. IN DWORD dwBucketIndex,
  377. IN DWORD dwDeviceIndex
  378. )
  379. {
  380. UNREFERENCED_PARAMETER( Parameter );
  381. UNREFERENCED_PARAMETER( dwBucketIndex );
  382. UNREFERENCED_PARAMETER( dwDeviceIndex );
  383. if ( pDeviceObj->DeviceState != DEV_OBJ_CLOSED )
  384. {
  385. return( ERROR_DEVICE_NOT_READY );
  386. }
  387. return( NO_ERROR );
  388. }
  389. //**
  390. //
  391. // Call:
  392. //
  393. // Returns:
  394. //
  395. // Description:
  396. //
  397. DWORD
  398. DeviceObjCopyhPort(
  399. IN DEVICE_OBJECT * pDeviceObj,
  400. IN PVOID Parameter,
  401. IN DWORD dwBucketIndex,
  402. IN DWORD dwDeviceIndex
  403. )
  404. {
  405. HPORT * phPort = (HPORT *)Parameter;
  406. UNREFERENCED_PARAMETER( Parameter );
  407. phPort[dwDeviceIndex] = pDeviceObj->hPort;
  408. return( NO_ERROR );
  409. }
  410. //**
  411. //
  412. // Call:
  413. //
  414. // Returns:
  415. //
  416. // Description:
  417. //
  418. DWORD
  419. DeviceObjCloseListening(
  420. IN DEVICE_OBJECT * pDeviceObj,
  421. IN PVOID Parameter,
  422. IN DWORD dwBucketIndex,
  423. IN DWORD dwDeviceIndex
  424. )
  425. {
  426. UNREFERENCED_PARAMETER( Parameter );
  427. UNREFERENCED_PARAMETER( dwBucketIndex );
  428. UNREFERENCED_PARAMETER( dwDeviceIndex );
  429. if ( pDeviceObj->fFlags & DEV_OBJ_OPENED_FOR_DIALOUT )
  430. {
  431. return( NO_ERROR );
  432. }
  433. switch( pDeviceObj->DeviceState )
  434. {
  435. case DEV_OBJ_HW_FAILURE:
  436. case DEV_OBJ_LISTENING:
  437. DevStartClosing( pDeviceObj );
  438. break;
  439. default:
  440. break;
  441. }
  442. return( NO_ERROR );
  443. }
  444. //**
  445. //
  446. // Call:
  447. //
  448. // Returns:
  449. //
  450. // Description:
  451. //
  452. DWORD
  453. DeviceObjResumeListening(
  454. IN DEVICE_OBJECT * pDeviceObj,
  455. IN PVOID Parameter,
  456. IN DWORD dwBucketIndex,
  457. IN DWORD dwDeviceIndex
  458. )
  459. {
  460. UNREFERENCED_PARAMETER( Parameter );
  461. UNREFERENCED_PARAMETER( dwBucketIndex );
  462. UNREFERENCED_PARAMETER( dwDeviceIndex );
  463. if ( pDeviceObj->DeviceState == DEV_OBJ_CLOSED )
  464. {
  465. DevCloseComplete( pDeviceObj );
  466. }
  467. return( NO_ERROR );
  468. }
  469. //**
  470. //
  471. // Call: DeviceObjRequestNotification
  472. //
  473. // Returns: NO_ERROR - Success
  474. // non-zero return from RasRequestNotification - Failure
  475. //
  476. // Description: Will register each of the bucket events with RasMan for
  477. // RasMan event notification.
  478. //
  479. DWORD
  480. DeviceObjRequestNotification(
  481. IN DEVICE_OBJECT * pDeviceObj,
  482. IN PVOID Parameter,
  483. IN DWORD dwBucketIndex,
  484. IN DWORD dwDeviceIndex
  485. )
  486. {
  487. UNREFERENCED_PARAMETER( Parameter );
  488. UNREFERENCED_PARAMETER( dwDeviceIndex );
  489. return ( RasRequestNotification(
  490. pDeviceObj->hPort,
  491. gblSupervisorEvents[dwBucketIndex+NUM_DDM_EVENTS]));
  492. }
  493. //**
  494. //
  495. // Call: DeviceObjClose
  496. //
  497. // Returns:
  498. //
  499. // Description: Closes opened ports
  500. //
  501. DWORD
  502. DeviceObjClose(
  503. IN DEVICE_OBJECT * pDevObj,
  504. IN PVOID Parameter,
  505. IN DWORD dwBucketIndex,
  506. IN DWORD dwDeviceIndex
  507. )
  508. {
  509. UNREFERENCED_PARAMETER( Parameter );
  510. UNREFERENCED_PARAMETER( dwDeviceIndex );
  511. UNREFERENCED_PARAMETER( dwDeviceIndex );
  512. RasServerPortClose( pDevObj->hPort );
  513. return( NO_ERROR );
  514. }
  515. //**
  516. //
  517. // Call: DeviceObjIsWANDevice
  518. //
  519. // Returns: NO_ERROR - Success
  520. // Non-zero returns - Failure
  521. //
  522. // Description:
  523. //
  524. DWORD
  525. DeviceObjIsWANDevice(
  526. IN DEVICE_OBJECT * pDevObj,
  527. IN PVOID Parameter,
  528. IN DWORD dwBucketIndex,
  529. IN DWORD dwDeviceIndex
  530. )
  531. {
  532. BOOL * pfWANDeviceInstalled = (BOOL *)Parameter;
  533. *pfWANDeviceInstalled = FALSE;
  534. if ( RAS_DEVICE_CLASS( pDevObj->dwDeviceType ) != RDT_Direct )
  535. {
  536. *pfWANDeviceInstalled = TRUE;
  537. }
  538. return( NO_ERROR );
  539. }
  540. //**
  541. //
  542. // Call: DDMServicePostListens
  543. //
  544. // Returns: None
  545. //
  546. // Description: Exported call to DIM to post listens after interfaces have
  547. // been loaded
  548. //
  549. VOID
  550. DDMServicePostListens(
  551. VOID *pVoid
  552. )
  553. {
  554. //
  555. // Post listen for each dcb
  556. //
  557. DeviceObjIterator( DeviceObjPostListen, FALSE, pVoid);
  558. }
  559. //**
  560. //
  561. // Call: DeviceObjGetType
  562. //
  563. // Returns: NO_ERROR - Success
  564. // Non-zero returns - Failure
  565. //
  566. // Description:
  567. //
  568. DWORD
  569. DeviceObjGetType(
  570. IN DEVICE_OBJECT * pDevObj,
  571. IN PVOID Parameter,
  572. IN DWORD dwBucketIndex,
  573. IN DWORD dwDeviceIndex
  574. )
  575. {
  576. DWORD dwVendorId = 311;
  577. DWORD dwType = 6;
  578. DWORD dwValue = (DWORD)-1;
  579. DWORD dwIndex = 0;
  580. ROUTER_IDENTITY_ATTRIBUTE * pRouterIdAttributes =
  581. (ROUTER_IDENTITY_ATTRIBUTE * )Parameter;
  582. switch( RAS_DEVICE_TYPE( pDevObj->dwDeviceType ) )
  583. {
  584. case RDT_Modem:
  585. dwValue = 706;
  586. break;
  587. case RDT_X25:
  588. dwValue = 710;
  589. break;
  590. case RDT_Isdn:
  591. dwValue = 705;
  592. break;
  593. case RDT_Serial:
  594. dwValue = 713;
  595. break;
  596. case RDT_FrameRelay:
  597. dwValue = 703;
  598. break;
  599. case RDT_Atm:
  600. dwValue = 704;
  601. break;
  602. case RDT_Sonet:
  603. dwValue = 707;
  604. break;
  605. case RDT_Sw56:
  606. dwValue = 708;
  607. break;
  608. case RDT_Tunnel_Pptp:
  609. dwValue = 701;
  610. break;
  611. case RDT_Tunnel_L2tp:
  612. dwValue = 702;
  613. break;
  614. case RDT_Irda:
  615. dwValue = 709;
  616. break;
  617. case RDT_Parallel:
  618. dwValue = 714;
  619. break;
  620. case RDT_Other:
  621. default:
  622. //
  623. // unknown so set to generic WAN
  624. //
  625. dwValue = 711;
  626. break;
  627. }
  628. for( dwIndex = 0;
  629. pRouterIdAttributes[dwIndex].dwVendorId != -1;
  630. dwIndex++ )
  631. {
  632. //
  633. // Check if already set
  634. //
  635. if ( ( pRouterIdAttributes[dwIndex].dwVendorId == 311 ) &&
  636. ( pRouterIdAttributes[dwIndex].dwType == 6 ) &&
  637. ( pRouterIdAttributes[dwIndex].dwValue == dwValue ) )
  638. {
  639. return( NO_ERROR );
  640. }
  641. }
  642. //
  643. // Now set so set it here
  644. //
  645. pRouterIdAttributes[dwIndex].dwVendorId = 311;
  646. pRouterIdAttributes[dwIndex].dwType = 6;
  647. pRouterIdAttributes[dwIndex].dwValue = dwValue;
  648. //
  649. // Terminate the array
  650. //
  651. dwIndex++;
  652. pRouterIdAttributes[dwIndex].dwVendorId = (DWORD)-1;
  653. pRouterIdAttributes[dwIndex].dwType = (DWORD)-1;
  654. pRouterIdAttributes[dwIndex].dwValue = (DWORD)-1;
  655. return( NO_ERROR );
  656. }
  657. //**
  658. //
  659. // Call:
  660. //
  661. // Returns:
  662. //
  663. // Description:
  664. //
  665. DWORD
  666. DeviceObjForceIpSec(
  667. IN DEVICE_OBJECT * pDeviceObj,
  668. IN PVOID Parameter,
  669. IN DWORD dwBucketIndex,
  670. IN DWORD dwDeviceIndex
  671. )
  672. {
  673. DWORD dwRetCode;
  674. UNREFERENCED_PARAMETER( Parameter );
  675. UNREFERENCED_PARAMETER( dwBucketIndex );
  676. UNREFERENCED_PARAMETER( dwDeviceIndex );
  677. if ( RAS_DEVICE_TYPE( pDeviceObj->dwDeviceType ) != RDT_Tunnel_L2tp )
  678. {
  679. return( NO_ERROR );
  680. }
  681. if ( pDeviceObj->ConnectionState != LISTENING )
  682. {
  683. return( NO_ERROR );
  684. }
  685. //
  686. // If this is an L2TP tunnel port type and we have to use
  687. // IPSEC, then go ahead and set/unset the filter
  688. //
  689. dwRetCode = RasEnableIpSec(
  690. pDeviceObj->hPort,
  691. //gblDDMConfigInfo.dwServerFlags & PPPCFG_RequireIPSEC,
  692. TRUE,
  693. TRUE,
  694. (gblDDMConfigInfo.dwServerFlags & PPPCFG_RequireIPSEC)
  695. ? RAS_L2TP_REQUIRE_ENCRYPTION
  696. : RAS_L2TP_OPTIONAL_ENCRYPTION);
  697. DDMTRACE2( "Enabled IPSec on port %d, dwRetCode = %d",
  698. pDeviceObj->hPort, dwRetCode );
  699. //
  700. // Log the non certificate errorlog only once
  701. //
  702. if ( dwRetCode == ERROR_NO_CERTIFICATE )
  703. {
  704. if ( !( gblDDMConfigInfo.fFlags & DDM_NO_CERTIFICATE_LOGGED ) )
  705. {
  706. DDMLogWarning( ROUTERLOG_NO_IPSEC_CERT, 0, NULL );
  707. gblDDMConfigInfo.fFlags |= DDM_NO_CERTIFICATE_LOGGED;
  708. }
  709. return( dwRetCode );
  710. }
  711. if( (dwRetCode != NO_ERROR) && !(pDeviceObj->fFlags & DEV_OBJ_IPSEC_ERROR_LOGGED) )
  712. {
  713. WCHAR wchPortName[MAX_PORT_NAME+1];
  714. LPWSTR lpwsAuditStr[1];
  715. RASMAN_INFO rInfo;
  716. DWORD rc;
  717. // DevStartClosing(pDeviceObj);
  718. ZeroMemory(&rInfo, sizeof(RASMAN_INFO));
  719. rc = RasGetInfo(NULL, pDeviceObj->hPort, &rInfo);
  720. if(rc != NO_ERROR)
  721. {
  722. return (NO_ERROR);
  723. }
  724. MultiByteToWideChar( CP_ACP,
  725. 0,
  726. rInfo.RI_szPortName,
  727. -1,
  728. wchPortName,
  729. MAX_PORT_NAME+1 );
  730. lpwsAuditStr[0] = wchPortName;
  731. DDMLogWarningString(ROUTERLOG_IPSEC_FILTER_FAILURE, 1, lpwsAuditStr, dwRetCode,1);
  732. pDeviceObj->fFlags |= DEV_OBJ_IPSEC_ERROR_LOGGED;
  733. }
  734. else
  735. {
  736. //
  737. // Clear the flag so that if we hit this error again
  738. // we do an eventlog
  739. //
  740. pDeviceObj->fFlags &= ~DEV_OBJ_IPSEC_ERROR_LOGGED;
  741. }
  742. return( NO_ERROR );
  743. }
  744. //**
  745. //
  746. // Call: DeviceObjAdd
  747. //
  748. // Returns: NO_ERROR - Success
  749. // Non-zero returns - Failure
  750. //
  751. // Description:
  752. //
  753. VOID
  754. DeviceObjAdd(
  755. IN RASMAN_PORT * pRasmanPort
  756. )
  757. {
  758. DWORD dwRetCode;
  759. HPORT hPort;
  760. DEVICE_OBJECT * pDevObj = DeviceObjGetPointer( pRasmanPort->P_Handle );
  761. //
  762. // Make sure we do not already have this device
  763. //
  764. if ( pDevObj != NULL )
  765. {
  766. DDMTRACE1("Error:Recvd add new port notification for existing port %d",
  767. pRasmanPort->P_Handle );
  768. return;
  769. }
  770. DDMTRACE1( "Adding new port hPort=%d", pRasmanPort->P_Handle );
  771. dwRetCode = RasPortOpen( pRasmanPort->P_PortName, &hPort, NULL );
  772. if ( dwRetCode != NO_ERROR )
  773. {
  774. WCHAR wchPortName[MAX_PORT_NAME+1];
  775. LPWSTR lpwsAuditStr[1];
  776. MultiByteToWideChar(
  777. CP_ACP,
  778. 0,
  779. pRasmanPort->P_PortName,
  780. -1,
  781. wchPortName,
  782. MAX_PORT_NAME+1 );
  783. //
  784. // Log an error
  785. //
  786. lpwsAuditStr[0] = wchPortName;
  787. DDMLogErrorString( ROUTERLOG_UNABLE_TO_OPEN_PORT, 1,
  788. lpwsAuditStr, dwRetCode, 1 );
  789. }
  790. else
  791. {
  792. pDevObj = DeviceObjAllocAndInitialize( hPort, pRasmanPort );
  793. if ( pDevObj == (DEVICE_OBJECT *)NULL )
  794. {
  795. dwRetCode = GetLastError();
  796. DDMLogError(ROUTERLOG_NOT_ENOUGH_MEMORY,0, NULL,dwRetCode);
  797. return;
  798. }
  799. //
  800. // Insert into the device hash table
  801. //
  802. DeviceObjInsertInTable( pDevObj );
  803. //
  804. // Possibly need to notify router managers of reachability
  805. // change
  806. //
  807. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  808. IfObjectNotifyAllOfReachabilityChange( TRUE,
  809. INTERFACE_OUT_OF_RESOURCES );
  810. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  811. //
  812. // Tell DIM to update router identity object
  813. //
  814. ((VOID(*)(VOID))gblDDMConfigInfo.lpfnRouterIdentityObjectUpdate)();
  815. if ( RAS_DEVICE_CLASS( pDevObj->dwDeviceType ) != RDT_Direct )
  816. {
  817. //
  818. // Tell DIM that a WAN device has been installed and that it
  819. // should start advertizing it's presence
  820. //
  821. ((VOID(*)( BOOL ))
  822. gblDDMConfigInfo.lpfnIfObjectWANDeviceInstalled)( TRUE );
  823. }
  824. //
  825. // Post a listen
  826. //
  827. if ( RAS_DEVICE_TYPE( pDevObj->dwDeviceType ) != RDT_PPPoE )
  828. {
  829. DeviceObjPostListen( pDevObj, NULL, 0, 0 );
  830. }
  831. }
  832. }
  833. //**
  834. //
  835. // Call: DeviceObjRemove
  836. //
  837. // Returns: NO_ERROR - Success
  838. // Non-zero returns - Failure
  839. //
  840. // Description:
  841. //
  842. VOID
  843. DeviceObjRemove(
  844. IN RASMAN_PORT * pRasmanPort
  845. )
  846. {
  847. DEVICE_OBJECT * pDevObj = DeviceObjGetPointer( pRasmanPort->P_Handle );
  848. if ( pDevObj == NULL )
  849. {
  850. DDMTRACE1("Error:Recvd remove port notification for existing port %d",
  851. pRasmanPort->P_Handle );
  852. return;
  853. }
  854. DDMTRACE1( "Removing port hPort=%d", pRasmanPort->P_Handle );
  855. if ( pDevObj->fFlags & DEV_OBJ_MARKED_AS_INUSE )
  856. {
  857. //
  858. // If the device is busy, then just set the flag to discard
  859. // the port after disconnection,
  860. //
  861. pDevObj->fFlags |= DEV_OBJ_PNP_DELETE;
  862. }
  863. else
  864. {
  865. //
  866. // Otherwise remove the port
  867. //
  868. DeviceObjRemoveFromTable( pRasmanPort->P_Handle );
  869. }
  870. }
  871. //**
  872. //
  873. // Call: DeviceObjUsageChange
  874. //
  875. // Returns: NO_ERROR - Success
  876. // Non-zero returns - Failure
  877. //
  878. // Description:
  879. //
  880. VOID
  881. DeviceObjUsageChange(
  882. IN RASMAN_PORT * pRasmanPort
  883. )
  884. {
  885. DEVICE_OBJECT * pDevObj = DeviceObjGetPointer( pRasmanPort->P_Handle );
  886. if ( pDevObj == NULL )
  887. {
  888. if ( pRasmanPort->P_ConfiguredUsage &
  889. ( CALL_IN | CALL_ROUTER | CALL_OUTBOUND_ROUTER ) )
  890. {
  891. DeviceObjAdd( pRasmanPort );
  892. }
  893. return;
  894. }
  895. if ( !( pRasmanPort->P_ConfiguredUsage &
  896. ( CALL_IN | CALL_ROUTER | CALL_OUTBOUND_ROUTER ) ) )
  897. {
  898. DeviceObjRemove( pRasmanPort );
  899. return;
  900. }
  901. DDMTRACE1("Changing usage for port %d", pRasmanPort->P_Handle );
  902. //
  903. // Modify the media table and usage accordingly
  904. //
  905. if ( ( pDevObj->fFlags & DEV_OBJ_ALLOW_ROUTERS ) &&
  906. ( !( pRasmanPort->P_ConfiguredUsage &
  907. ( CALL_ROUTER | CALL_OUTBOUND_ROUTER ) ) ) )
  908. {
  909. //
  910. // If it was a router port but is no longer then we
  911. // remove the media from the media table
  912. //
  913. MediaObjRemoveFromTable( pDevObj->wchDeviceType );
  914. //
  915. // Possibly need to notify router managers of reachability
  916. // change
  917. //
  918. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  919. IfObjectNotifyAllOfReachabilityChange( FALSE,
  920. INTERFACE_OUT_OF_RESOURCES );
  921. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  922. }
  923. if ( ( !( pDevObj->fFlags & DEV_OBJ_ALLOW_ROUTERS ) ) &&
  924. ( pRasmanPort->P_ConfiguredUsage &
  925. ( CALL_ROUTER | CALL_OUTBOUND_ROUTER ) ) )
  926. {
  927. //
  928. // If it was not a router port but is now, then we
  929. // add the media to the media table
  930. //
  931. MediaObjAddToTable( pDevObj->wchDeviceType );
  932. //
  933. // Possibly need to notify router managers of reachability
  934. // change
  935. //
  936. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  937. IfObjectNotifyAllOfReachabilityChange( TRUE,
  938. INTERFACE_OUT_OF_RESOURCES );
  939. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  940. }
  941. if ( pRasmanPort->P_ConfiguredUsage & CALL_IN )
  942. {
  943. pDevObj->fFlags |= DEV_OBJ_ALLOW_CLIENTS;
  944. }
  945. else
  946. {
  947. pDevObj->fFlags &= ~DEV_OBJ_ALLOW_CLIENTS;
  948. }
  949. if ( pRasmanPort->P_ConfiguredUsage &
  950. (CALL_ROUTER | CALL_OUTBOUND_ROUTER) )
  951. {
  952. pDevObj->fFlags |= DEV_OBJ_ALLOW_ROUTERS;
  953. }
  954. else
  955. {
  956. pDevObj->fFlags &= ~DEV_OBJ_ALLOW_ROUTERS;
  957. }
  958. }