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.

1148 lines
26 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. MultiByteToWideChar(
  264. CP_ACP,
  265. 0,
  266. pRasmanPort->P_DeviceName,
  267. -1,
  268. pDeviceObj->wchDeviceName,
  269. MAX_DEVICE_NAME+1 );
  270. MultiByteToWideChar(
  271. CP_ACP,
  272. 0,
  273. pRasmanPort->P_DeviceType,
  274. -1,
  275. pDeviceObj->wchDeviceType,
  276. MAX_DEVICETYPE_NAME+1 );
  277. if ( pRasmanPort->P_ConfiguredUsage & CALL_IN )
  278. {
  279. pDeviceObj->fFlags |= DEV_OBJ_ALLOW_CLIENTS;
  280. }
  281. if ( pRasmanPort->P_ConfiguredUsage &
  282. (CALL_ROUTER | CALL_OUTBOUND_ROUTER) )
  283. {
  284. pDeviceObj->fFlags |= DEV_OBJ_ALLOW_ROUTERS;
  285. }
  286. return( pDeviceObj );
  287. }
  288. //**
  289. //
  290. // Call: DeviceObjStartClosing
  291. //
  292. // Returns: NO_ERROR
  293. //
  294. // Description: Close all active devices; if no devices have been initialized
  295. // and opened then this part is skipped.
  296. //
  297. DWORD
  298. DeviceObjStartClosing(
  299. IN DEVICE_OBJECT * pDeviceObj,
  300. IN PVOID Parameter,
  301. IN DWORD dwBucketIndex,
  302. IN DWORD dwDeviceIndex
  303. )
  304. {
  305. UNREFERENCED_PARAMETER( Parameter );
  306. UNREFERENCED_PARAMETER( dwBucketIndex );
  307. UNREFERENCED_PARAMETER( dwDeviceIndex );
  308. if ( pDeviceObj->fFlags & DEV_OBJ_OPENED_FOR_DIALOUT )
  309. {
  310. RasApiCleanUpPort( pDeviceObj );
  311. }
  312. if ( ( pDeviceObj->DeviceState != DEV_OBJ_CLOSED ) &&
  313. ( pDeviceObj->DeviceState != DEV_OBJ_CLOSING ) )
  314. {
  315. if ( pDeviceObj->fFlags & DEV_OBJ_PPP_IS_ACTIVE )
  316. {
  317. PppDdmStop( (HPORT)pDeviceObj->hPort, NO_ERROR );
  318. }
  319. else
  320. {
  321. DevStartClosing( pDeviceObj );
  322. }
  323. }
  324. return( NO_ERROR );
  325. }
  326. //**
  327. //
  328. // Call: DeviceObjPostListen
  329. //
  330. // Returns:
  331. //
  332. // Description:
  333. //
  334. DWORD
  335. DeviceObjPostListen(
  336. IN DEVICE_OBJECT * pDeviceObj,
  337. IN PVOID Parameter,
  338. IN DWORD dwBucketIndex,
  339. IN DWORD dwDeviceIndex
  340. )
  341. {
  342. DWORD Type;
  343. //UNREFERENCED_PARAMETER( Parameter );
  344. UNREFERENCED_PARAMETER( dwBucketIndex );
  345. UNREFERENCED_PARAMETER( dwDeviceIndex );
  346. if(NULL != Parameter)
  347. {
  348. Type = *((DWORD *) (Parameter));
  349. if(RAS_DEVICE_TYPE(pDeviceObj->dwDeviceType) != Type)
  350. {
  351. return NO_ERROR;
  352. }
  353. }
  354. pDeviceObj->DeviceState = DEV_OBJ_LISTENING;
  355. RmListen( pDeviceObj );
  356. return( NO_ERROR );
  357. }
  358. //**
  359. //
  360. // Call:
  361. //
  362. // Returns:
  363. //
  364. // Description:
  365. //
  366. DWORD
  367. DeviceObjIsClosed(
  368. IN DEVICE_OBJECT * pDeviceObj,
  369. IN PVOID Parameter,
  370. IN DWORD dwBucketIndex,
  371. IN DWORD dwDeviceIndex
  372. )
  373. {
  374. UNREFERENCED_PARAMETER( Parameter );
  375. UNREFERENCED_PARAMETER( dwBucketIndex );
  376. UNREFERENCED_PARAMETER( dwDeviceIndex );
  377. if ( pDeviceObj->DeviceState != DEV_OBJ_CLOSED )
  378. {
  379. return( ERROR_DEVICE_NOT_READY );
  380. }
  381. return( NO_ERROR );
  382. }
  383. //**
  384. //
  385. // Call:
  386. //
  387. // Returns:
  388. //
  389. // Description:
  390. //
  391. DWORD
  392. DeviceObjCopyhPort(
  393. IN DEVICE_OBJECT * pDeviceObj,
  394. IN PVOID Parameter,
  395. IN DWORD dwBucketIndex,
  396. IN DWORD dwDeviceIndex
  397. )
  398. {
  399. HPORT * phPort = (HPORT *)Parameter;
  400. UNREFERENCED_PARAMETER( Parameter );
  401. phPort[dwDeviceIndex] = pDeviceObj->hPort;
  402. return( NO_ERROR );
  403. }
  404. //**
  405. //
  406. // Call:
  407. //
  408. // Returns:
  409. //
  410. // Description:
  411. //
  412. DWORD
  413. DeviceObjCloseListening(
  414. IN DEVICE_OBJECT * pDeviceObj,
  415. IN PVOID Parameter,
  416. IN DWORD dwBucketIndex,
  417. IN DWORD dwDeviceIndex
  418. )
  419. {
  420. UNREFERENCED_PARAMETER( Parameter );
  421. UNREFERENCED_PARAMETER( dwBucketIndex );
  422. UNREFERENCED_PARAMETER( dwDeviceIndex );
  423. if ( pDeviceObj->fFlags & DEV_OBJ_OPENED_FOR_DIALOUT )
  424. {
  425. return( NO_ERROR );
  426. }
  427. switch( pDeviceObj->DeviceState )
  428. {
  429. case DEV_OBJ_HW_FAILURE:
  430. case DEV_OBJ_LISTENING:
  431. DevStartClosing( pDeviceObj );
  432. break;
  433. default:
  434. break;
  435. }
  436. return( NO_ERROR );
  437. }
  438. //**
  439. //
  440. // Call:
  441. //
  442. // Returns:
  443. //
  444. // Description:
  445. //
  446. DWORD
  447. DeviceObjResumeListening(
  448. IN DEVICE_OBJECT * pDeviceObj,
  449. IN PVOID Parameter,
  450. IN DWORD dwBucketIndex,
  451. IN DWORD dwDeviceIndex
  452. )
  453. {
  454. UNREFERENCED_PARAMETER( Parameter );
  455. UNREFERENCED_PARAMETER( dwBucketIndex );
  456. UNREFERENCED_PARAMETER( dwDeviceIndex );
  457. if ( pDeviceObj->DeviceState == DEV_OBJ_CLOSED )
  458. {
  459. DevCloseComplete( pDeviceObj );
  460. }
  461. return( NO_ERROR );
  462. }
  463. //**
  464. //
  465. // Call: DeviceObjRequestNotification
  466. //
  467. // Returns: NO_ERROR - Success
  468. // non-zero return from RasRequestNotification - Failure
  469. //
  470. // Description: Will register each of the bucket events with RasMan for
  471. // RasMan event notification.
  472. //
  473. DWORD
  474. DeviceObjRequestNotification(
  475. IN DEVICE_OBJECT * pDeviceObj,
  476. IN PVOID Parameter,
  477. IN DWORD dwBucketIndex,
  478. IN DWORD dwDeviceIndex
  479. )
  480. {
  481. UNREFERENCED_PARAMETER( Parameter );
  482. UNREFERENCED_PARAMETER( dwDeviceIndex );
  483. return ( RasRequestNotification(
  484. pDeviceObj->hPort,
  485. gblSupervisorEvents[dwBucketIndex+NUM_DDM_EVENTS]));
  486. }
  487. //**
  488. //
  489. // Call: DeviceObjClose
  490. //
  491. // Returns:
  492. //
  493. // Description: Closes opened ports
  494. //
  495. DWORD
  496. DeviceObjClose(
  497. IN DEVICE_OBJECT * pDevObj,
  498. IN PVOID Parameter,
  499. IN DWORD dwBucketIndex,
  500. IN DWORD dwDeviceIndex
  501. )
  502. {
  503. UNREFERENCED_PARAMETER( Parameter );
  504. UNREFERENCED_PARAMETER( dwDeviceIndex );
  505. UNREFERENCED_PARAMETER( dwDeviceIndex );
  506. RasServerPortClose( pDevObj->hPort );
  507. return( NO_ERROR );
  508. }
  509. //**
  510. //
  511. // Call: DeviceObjIsWANDevice
  512. //
  513. // Returns: NO_ERROR - Success
  514. // Non-zero returns - Failure
  515. //
  516. // Description:
  517. //
  518. DWORD
  519. DeviceObjIsWANDevice(
  520. IN DEVICE_OBJECT * pDevObj,
  521. IN PVOID Parameter,
  522. IN DWORD dwBucketIndex,
  523. IN DWORD dwDeviceIndex
  524. )
  525. {
  526. BOOL * pfWANDeviceInstalled = (BOOL *)Parameter;
  527. *pfWANDeviceInstalled = FALSE;
  528. if ( RAS_DEVICE_CLASS( pDevObj->dwDeviceType ) != RDT_Direct )
  529. {
  530. *pfWANDeviceInstalled = TRUE;
  531. }
  532. return( NO_ERROR );
  533. }
  534. //**
  535. //
  536. // Call: DDMServicePostListens
  537. //
  538. // Returns: None
  539. //
  540. // Description: Exported call to DIM to post listens after interfaces have
  541. // been loaded
  542. //
  543. VOID
  544. DDMServicePostListens(
  545. VOID *pVoid
  546. )
  547. {
  548. //
  549. // Post listen for each dcb
  550. //
  551. DeviceObjIterator( DeviceObjPostListen, FALSE, pVoid);
  552. }
  553. //**
  554. //
  555. // Call: DeviceObjGetType
  556. //
  557. // Returns: NO_ERROR - Success
  558. // Non-zero returns - Failure
  559. //
  560. // Description:
  561. //
  562. DWORD
  563. DeviceObjGetType(
  564. IN DEVICE_OBJECT * pDevObj,
  565. IN PVOID Parameter,
  566. IN DWORD dwBucketIndex,
  567. IN DWORD dwDeviceIndex
  568. )
  569. {
  570. DWORD dwVendorId = 311;
  571. DWORD dwType = 6;
  572. DWORD dwValue = (DWORD)-1;
  573. DWORD dwIndex = 0;
  574. ROUTER_IDENTITY_ATTRIBUTE * pRouterIdAttributes =
  575. (ROUTER_IDENTITY_ATTRIBUTE * )Parameter;
  576. switch( RAS_DEVICE_TYPE( pDevObj->dwDeviceType ) )
  577. {
  578. case RDT_Modem:
  579. dwValue = 706;
  580. break;
  581. case RDT_X25:
  582. dwValue = 710;
  583. break;
  584. case RDT_Isdn:
  585. dwValue = 705;
  586. break;
  587. case RDT_Serial:
  588. dwValue = 713;
  589. break;
  590. case RDT_FrameRelay:
  591. dwValue = 703;
  592. break;
  593. case RDT_Atm:
  594. dwValue = 704;
  595. break;
  596. case RDT_Sonet:
  597. dwValue = 707;
  598. break;
  599. case RDT_Sw56:
  600. dwValue = 708;
  601. break;
  602. case RDT_Tunnel_Pptp:
  603. dwValue = 701;
  604. break;
  605. case RDT_Tunnel_L2tp:
  606. dwValue = 702;
  607. break;
  608. case RDT_Irda:
  609. dwValue = 709;
  610. break;
  611. case RDT_Parallel:
  612. dwValue = 714;
  613. break;
  614. case RDT_Other:
  615. default:
  616. //
  617. // unknown so set to generic WAN
  618. //
  619. dwValue = 711;
  620. break;
  621. }
  622. for( dwIndex = 0;
  623. pRouterIdAttributes[dwIndex].dwVendorId != -1;
  624. dwIndex++ )
  625. {
  626. //
  627. // Check if already set
  628. //
  629. if ( ( pRouterIdAttributes[dwIndex].dwVendorId == 311 ) &&
  630. ( pRouterIdAttributes[dwIndex].dwType == 6 ) &&
  631. ( pRouterIdAttributes[dwIndex].dwValue == dwValue ) )
  632. {
  633. return( NO_ERROR );
  634. }
  635. }
  636. //
  637. // Now set so set it here
  638. //
  639. pRouterIdAttributes[dwIndex].dwVendorId = 311;
  640. pRouterIdAttributes[dwIndex].dwType = 6;
  641. pRouterIdAttributes[dwIndex].dwValue = dwValue;
  642. //
  643. // Terminate the array
  644. //
  645. dwIndex++;
  646. pRouterIdAttributes[dwIndex].dwVendorId = (DWORD)-1;
  647. pRouterIdAttributes[dwIndex].dwType = (DWORD)-1;
  648. pRouterIdAttributes[dwIndex].dwValue = (DWORD)-1;
  649. return( NO_ERROR );
  650. }
  651. //**
  652. //
  653. // Call:
  654. //
  655. // Returns:
  656. //
  657. // Description:
  658. //
  659. DWORD
  660. DeviceObjForceIpSec(
  661. IN DEVICE_OBJECT * pDeviceObj,
  662. IN PVOID Parameter,
  663. IN DWORD dwBucketIndex,
  664. IN DWORD dwDeviceIndex
  665. )
  666. {
  667. DWORD dwRetCode;
  668. UNREFERENCED_PARAMETER( Parameter );
  669. UNREFERENCED_PARAMETER( dwBucketIndex );
  670. UNREFERENCED_PARAMETER( dwDeviceIndex );
  671. if ( RAS_DEVICE_TYPE( pDeviceObj->dwDeviceType ) != RDT_Tunnel_L2tp )
  672. {
  673. return( NO_ERROR );
  674. }
  675. if ( pDeviceObj->ConnectionState != LISTENING )
  676. {
  677. return( NO_ERROR );
  678. }
  679. //
  680. // If this is an L2TP tunnel port type and we have to use
  681. // IPSEC, then go ahead and set/unset the filter
  682. //
  683. dwRetCode = RasEnableIpSec(
  684. pDeviceObj->hPort,
  685. //gblDDMConfigInfo.dwServerFlags & PPPCFG_RequireIPSEC,
  686. TRUE,
  687. TRUE,
  688. (gblDDMConfigInfo.dwServerFlags & PPPCFG_RequireIPSEC)
  689. ? RAS_L2TP_REQUIRE_ENCRYPTION
  690. : RAS_L2TP_OPTIONAL_ENCRYPTION);
  691. DDMTRACE2( "Enabled IPSec on port %d, dwRetCode = %d",
  692. pDeviceObj->hPort, dwRetCode );
  693. //
  694. // Log the non certificate errorlog only once
  695. //
  696. if ( dwRetCode == ERROR_NO_CERTIFICATE )
  697. {
  698. if ( !( gblDDMConfigInfo.fFlags & DDM_NO_CERTIFICATE_LOGGED ) )
  699. {
  700. DDMLogWarning( ROUTERLOG_NO_IPSEC_CERT, 0, NULL );
  701. gblDDMConfigInfo.fFlags |= DDM_NO_CERTIFICATE_LOGGED;
  702. }
  703. return( dwRetCode );
  704. }
  705. if( (dwRetCode != NO_ERROR) && !(pDeviceObj->fFlags & DEV_OBJ_IPSEC_ERROR_LOGGED) )
  706. {
  707. WCHAR wchPortName[MAX_PORT_NAME+1];
  708. LPWSTR lpwsAuditStr[1];
  709. RASMAN_INFO rInfo;
  710. DWORD rc;
  711. // DevStartClosing(pDeviceObj);
  712. ZeroMemory(&rInfo, sizeof(RASMAN_INFO));
  713. rc = RasGetInfo(NULL, pDeviceObj->hPort, &rInfo);
  714. if(rc != NO_ERROR)
  715. {
  716. return (NO_ERROR);
  717. }
  718. MultiByteToWideChar( CP_ACP,
  719. 0,
  720. rInfo.RI_szPortName,
  721. -1,
  722. wchPortName,
  723. MAX_PORT_NAME+1 );
  724. lpwsAuditStr[0] = wchPortName;
  725. DDMLogWarningString(ROUTERLOG_IPSEC_FILTER_FAILURE, 1, lpwsAuditStr, dwRetCode,1);
  726. pDeviceObj->fFlags |= DEV_OBJ_IPSEC_ERROR_LOGGED;
  727. }
  728. else
  729. {
  730. //
  731. // Clear the flag so that if we hit this error again
  732. // we do an eventlog
  733. //
  734. pDeviceObj->fFlags &= ~DEV_OBJ_IPSEC_ERROR_LOGGED;
  735. }
  736. return( NO_ERROR );
  737. }
  738. //**
  739. //
  740. // Call: DeviceObjAdd
  741. //
  742. // Returns: NO_ERROR - Success
  743. // Non-zero returns - Failure
  744. //
  745. // Description:
  746. //
  747. VOID
  748. DeviceObjAdd(
  749. IN RASMAN_PORT * pRasmanPort
  750. )
  751. {
  752. DWORD dwRetCode;
  753. HPORT hPort;
  754. DEVICE_OBJECT * pDevObj = DeviceObjGetPointer( pRasmanPort->P_Handle );
  755. //
  756. // Make sure we do not already have this device
  757. //
  758. if ( pDevObj != NULL )
  759. {
  760. DDMTRACE1("Error:Recvd add new port notification for existing port %d",
  761. pRasmanPort->P_Handle );
  762. return;
  763. }
  764. DDMTRACE1( "Adding new port hPort=%d", pRasmanPort->P_Handle );
  765. dwRetCode = RasPortOpen( pRasmanPort->P_PortName, &hPort, NULL );
  766. if ( dwRetCode != NO_ERROR )
  767. {
  768. WCHAR wchPortName[MAX_PORT_NAME+1];
  769. LPWSTR lpwsAuditStr[1];
  770. MultiByteToWideChar(
  771. CP_ACP,
  772. 0,
  773. pRasmanPort->P_PortName,
  774. -1,
  775. wchPortName,
  776. MAX_PORT_NAME+1 );
  777. //
  778. // Log an error
  779. //
  780. lpwsAuditStr[0] = wchPortName;
  781. DDMLogErrorString( ROUTERLOG_UNABLE_TO_OPEN_PORT, 1,
  782. lpwsAuditStr, dwRetCode, 1 );
  783. }
  784. else
  785. {
  786. pDevObj = DeviceObjAllocAndInitialize( hPort, pRasmanPort );
  787. if ( pDevObj == (DEVICE_OBJECT *)NULL )
  788. {
  789. dwRetCode = GetLastError();
  790. DDMLogError(ROUTERLOG_NOT_ENOUGH_MEMORY,0, NULL,dwRetCode);
  791. return;
  792. }
  793. //
  794. // Insert into the device hash table
  795. //
  796. DeviceObjInsertInTable( pDevObj );
  797. //
  798. // Possibly need to notify router managers of reachability
  799. // change
  800. //
  801. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  802. IfObjectNotifyAllOfReachabilityChange( TRUE,
  803. INTERFACE_OUT_OF_RESOURCES );
  804. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  805. //
  806. // Tell DIM to update router identity object
  807. //
  808. ((VOID(*)(VOID))gblDDMConfigInfo.lpfnRouterIdentityObjectUpdate)();
  809. if ( RAS_DEVICE_CLASS( pDevObj->dwDeviceType ) != RDT_Direct )
  810. {
  811. //
  812. // Tell DIM that a WAN device has been installed and that it
  813. // should start advertizing it's presence
  814. //
  815. ((VOID(*)( BOOL ))
  816. gblDDMConfigInfo.lpfnIfObjectWANDeviceInstalled)( TRUE );
  817. }
  818. //
  819. // Post a listen
  820. //
  821. if ( RAS_DEVICE_TYPE( pDevObj->dwDeviceType ) != RDT_PPPoE )
  822. {
  823. DeviceObjPostListen( pDevObj, NULL, 0, 0 );
  824. }
  825. }
  826. }
  827. //**
  828. //
  829. // Call: DeviceObjRemove
  830. //
  831. // Returns: NO_ERROR - Success
  832. // Non-zero returns - Failure
  833. //
  834. // Description:
  835. //
  836. VOID
  837. DeviceObjRemove(
  838. IN RASMAN_PORT * pRasmanPort
  839. )
  840. {
  841. DEVICE_OBJECT * pDevObj = DeviceObjGetPointer( pRasmanPort->P_Handle );
  842. if ( pDevObj == NULL )
  843. {
  844. DDMTRACE1("Error:Recvd remove port notification for existing port %d",
  845. pRasmanPort->P_Handle );
  846. return;
  847. }
  848. DDMTRACE1( "Removing port hPort=%d", pRasmanPort->P_Handle );
  849. if ( pDevObj->fFlags & DEV_OBJ_MARKED_AS_INUSE )
  850. {
  851. //
  852. // If the device is busy, then just set the flag to discard
  853. // the port after disconnection,
  854. //
  855. pDevObj->fFlags |= DEV_OBJ_PNP_DELETE;
  856. }
  857. else
  858. {
  859. //
  860. // Otherwise remove the port
  861. //
  862. DeviceObjRemoveFromTable( pRasmanPort->P_Handle );
  863. }
  864. }
  865. //**
  866. //
  867. // Call: DeviceObjUsageChange
  868. //
  869. // Returns: NO_ERROR - Success
  870. // Non-zero returns - Failure
  871. //
  872. // Description:
  873. //
  874. VOID
  875. DeviceObjUsageChange(
  876. IN RASMAN_PORT * pRasmanPort
  877. )
  878. {
  879. DEVICE_OBJECT * pDevObj = DeviceObjGetPointer( pRasmanPort->P_Handle );
  880. if ( pDevObj == NULL )
  881. {
  882. if ( pRasmanPort->P_ConfiguredUsage &
  883. ( CALL_IN | CALL_ROUTER | CALL_OUTBOUND_ROUTER ) )
  884. {
  885. DeviceObjAdd( pRasmanPort );
  886. }
  887. return;
  888. }
  889. if ( !( pRasmanPort->P_ConfiguredUsage &
  890. ( CALL_IN | CALL_ROUTER | CALL_OUTBOUND_ROUTER ) ) )
  891. {
  892. DeviceObjRemove( pRasmanPort );
  893. return;
  894. }
  895. DDMTRACE1("Changing usage for port %d", pRasmanPort->P_Handle );
  896. //
  897. // Modify the media table and usage accordingly
  898. //
  899. if ( ( pDevObj->fFlags & DEV_OBJ_ALLOW_ROUTERS ) &&
  900. ( !( pRasmanPort->P_ConfiguredUsage &
  901. ( CALL_ROUTER | CALL_OUTBOUND_ROUTER ) ) ) )
  902. {
  903. //
  904. // If it was a router port but is no longer then we
  905. // remove the media from the media table
  906. //
  907. MediaObjRemoveFromTable( pDevObj->wchDeviceType );
  908. //
  909. // Possibly need to notify router managers of reachability
  910. // change
  911. //
  912. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  913. IfObjectNotifyAllOfReachabilityChange( FALSE,
  914. INTERFACE_OUT_OF_RESOURCES );
  915. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  916. }
  917. if ( ( !( pDevObj->fFlags & DEV_OBJ_ALLOW_ROUTERS ) ) &&
  918. ( pRasmanPort->P_ConfiguredUsage &
  919. ( CALL_ROUTER | CALL_OUTBOUND_ROUTER ) ) )
  920. {
  921. //
  922. // If it was not a router port but is now, then we
  923. // add the media to the media table
  924. //
  925. MediaObjAddToTable( pDevObj->wchDeviceType );
  926. //
  927. // Possibly need to notify router managers of reachability
  928. // change
  929. //
  930. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  931. IfObjectNotifyAllOfReachabilityChange( TRUE,
  932. INTERFACE_OUT_OF_RESOURCES );
  933. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  934. }
  935. if ( pRasmanPort->P_ConfiguredUsage & CALL_IN )
  936. {
  937. pDevObj->fFlags |= DEV_OBJ_ALLOW_CLIENTS;
  938. }
  939. else
  940. {
  941. pDevObj->fFlags &= ~DEV_OBJ_ALLOW_CLIENTS;
  942. }
  943. if ( pRasmanPort->P_ConfiguredUsage &
  944. (CALL_ROUTER | CALL_OUTBOUND_ROUTER) )
  945. {
  946. pDevObj->fFlags |= DEV_OBJ_ALLOW_ROUTERS;
  947. }
  948. else
  949. {
  950. pDevObj->fFlags &= ~DEV_OBJ_ALLOW_ROUTERS;
  951. }
  952. }