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.

936 lines
29 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1998-1999 Microsoft Corporation
  4. *
  5. * MINIPORT.C - NDIS support for PPTP
  6. *
  7. * Author: Stan Adermann (stana)
  8. *
  9. * Created: 7/28/1998
  10. *
  11. *****************************************************************************/
  12. #include "raspptp.h"
  13. PPPTP_ADAPTER pgAdapter = NULL;
  14. NDIS_OID SupportedOids[] = {
  15. OID_GEN_CURRENT_LOOKAHEAD,
  16. OID_GEN_DRIVER_VERSION,
  17. OID_GEN_HARDWARE_STATUS,
  18. OID_GEN_LINK_SPEED,
  19. OID_GEN_MAC_OPTIONS,
  20. OID_GEN_MAXIMUM_LOOKAHEAD,
  21. OID_GEN_MAXIMUM_FRAME_SIZE,
  22. OID_GEN_MAXIMUM_TOTAL_SIZE,
  23. OID_GEN_MEDIA_SUPPORTED,
  24. OID_GEN_MEDIA_IN_USE,
  25. OID_GEN_RCV_ERROR,
  26. OID_GEN_RCV_OK,
  27. OID_GEN_RECEIVE_BLOCK_SIZE,
  28. OID_GEN_RECEIVE_BUFFER_SPACE,
  29. OID_GEN_SUPPORTED_LIST,
  30. OID_GEN_TRANSMIT_BLOCK_SIZE,
  31. OID_GEN_TRANSMIT_BUFFER_SPACE,
  32. OID_GEN_VENDOR_DESCRIPTION,
  33. OID_GEN_VENDOR_ID,
  34. OID_GEN_XMIT_ERROR,
  35. OID_GEN_XMIT_OK,
  36. OID_PNP_CAPABILITIES,
  37. OID_PNP_SET_POWER,
  38. OID_PNP_QUERY_POWER,
  39. OID_PNP_ENABLE_WAKE_UP,
  40. OID_TAPI_CLOSE,
  41. OID_TAPI_DROP,
  42. OID_TAPI_GET_ADDRESS_CAPS,
  43. OID_TAPI_GET_CALL_INFO,
  44. OID_TAPI_GET_CALL_STATUS,
  45. OID_TAPI_GET_DEV_CAPS,
  46. OID_TAPI_GET_EXTENSION_ID,
  47. OID_TAPI_MAKE_CALL,
  48. OID_TAPI_NEGOTIATE_EXT_VERSION,
  49. OID_TAPI_OPEN,
  50. OID_TAPI_PROVIDER_INITIALIZE,
  51. OID_WAN_CURRENT_ADDRESS,
  52. OID_WAN_GET_BRIDGE_INFO,
  53. OID_WAN_GET_COMP_INFO,
  54. OID_WAN_GET_INFO,
  55. OID_WAN_GET_LINK_INFO,
  56. OID_WAN_GET_STATS_INFO,
  57. OID_WAN_HEADER_FORMAT,
  58. OID_WAN_LINE_COUNT,
  59. OID_WAN_MEDIUM_SUBTYPE,
  60. OID_WAN_PERMANENT_ADDRESS,
  61. OID_WAN_PROTOCOL_TYPE,
  62. OID_WAN_QUALITY_OF_SERVICE,
  63. OID_WAN_SET_BRIDGE_INFO,
  64. OID_WAN_SET_COMP_INFO,
  65. OID_WAN_SET_LINK_INFO
  66. };
  67. #if DBG
  68. PUCHAR
  69. GetOidString(
  70. NDIS_OID Oid
  71. )
  72. {
  73. PUCHAR OidName = NULL;
  74. #define OID_CASE(oid) case (oid): OidName = #oid; break
  75. switch (Oid)
  76. {
  77. OID_CASE(OID_GEN_CURRENT_LOOKAHEAD);
  78. OID_CASE(OID_GEN_DRIVER_VERSION);
  79. OID_CASE(OID_GEN_HARDWARE_STATUS);
  80. OID_CASE(OID_GEN_LINK_SPEED);
  81. OID_CASE(OID_GEN_MAC_OPTIONS);
  82. OID_CASE(OID_GEN_MAXIMUM_LOOKAHEAD);
  83. OID_CASE(OID_GEN_MAXIMUM_FRAME_SIZE);
  84. OID_CASE(OID_GEN_MAXIMUM_TOTAL_SIZE);
  85. OID_CASE(OID_GEN_MEDIA_CONNECT_STATUS);
  86. OID_CASE(OID_GEN_MEDIA_SUPPORTED);
  87. OID_CASE(OID_GEN_MEDIA_IN_USE);
  88. OID_CASE(OID_GEN_RECEIVE_BLOCK_SIZE);
  89. OID_CASE(OID_GEN_RECEIVE_BUFFER_SPACE);
  90. OID_CASE(OID_GEN_SUPPORTED_GUIDS);
  91. OID_CASE(OID_GEN_SUPPORTED_LIST);
  92. OID_CASE(OID_GEN_TRANSMIT_BLOCK_SIZE);
  93. OID_CASE(OID_GEN_TRANSMIT_BUFFER_SPACE);
  94. OID_CASE(OID_GEN_VENDOR_DESCRIPTION);
  95. OID_CASE(OID_GEN_VENDOR_ID);
  96. OID_CASE(OID_PNP_CAPABILITIES);
  97. OID_CASE(OID_PNP_SET_POWER);
  98. OID_CASE(OID_PNP_QUERY_POWER);
  99. OID_CASE(OID_PNP_ENABLE_WAKE_UP);
  100. OID_CASE(OID_TAPI_ACCEPT);
  101. OID_CASE(OID_TAPI_ANSWER);
  102. OID_CASE(OID_TAPI_CLOSE);
  103. OID_CASE(OID_TAPI_CLOSE_CALL);
  104. OID_CASE(OID_TAPI_CONDITIONAL_MEDIA_DETECTION);
  105. OID_CASE(OID_TAPI_CONFIG_DIALOG);
  106. OID_CASE(OID_TAPI_DEV_SPECIFIC);
  107. OID_CASE(OID_TAPI_DIAL);
  108. OID_CASE(OID_TAPI_DROP);
  109. OID_CASE(OID_TAPI_GET_ADDRESS_CAPS);
  110. OID_CASE(OID_TAPI_GET_ADDRESS_ID);
  111. OID_CASE(OID_TAPI_GET_ADDRESS_STATUS);
  112. OID_CASE(OID_TAPI_GET_CALL_ADDRESS_ID);
  113. OID_CASE(OID_TAPI_GET_CALL_INFO);
  114. OID_CASE(OID_TAPI_GET_CALL_STATUS);
  115. OID_CASE(OID_TAPI_GET_DEV_CAPS);
  116. OID_CASE(OID_TAPI_GET_DEV_CONFIG);
  117. OID_CASE(OID_TAPI_GET_EXTENSION_ID);
  118. OID_CASE(OID_TAPI_GET_ID);
  119. OID_CASE(OID_TAPI_GET_LINE_DEV_STATUS);
  120. OID_CASE(OID_TAPI_MAKE_CALL);
  121. OID_CASE(OID_TAPI_NEGOTIATE_EXT_VERSION);
  122. OID_CASE(OID_TAPI_OPEN);
  123. OID_CASE(OID_TAPI_PROVIDER_INITIALIZE);
  124. OID_CASE(OID_TAPI_PROVIDER_SHUTDOWN);
  125. OID_CASE(OID_TAPI_SECURE_CALL);
  126. OID_CASE(OID_TAPI_SELECT_EXT_VERSION);
  127. OID_CASE(OID_TAPI_SEND_USER_USER_INFO);
  128. OID_CASE(OID_TAPI_SET_APP_SPECIFIC);
  129. OID_CASE(OID_TAPI_SET_CALL_PARAMS);
  130. OID_CASE(OID_TAPI_SET_DEFAULT_MEDIA_DETECTION);
  131. OID_CASE(OID_TAPI_SET_DEV_CONFIG);
  132. OID_CASE(OID_TAPI_SET_MEDIA_MODE);
  133. OID_CASE(OID_TAPI_SET_STATUS_MESSAGES);
  134. OID_CASE(OID_WAN_CURRENT_ADDRESS);
  135. OID_CASE(OID_WAN_GET_BRIDGE_INFO);
  136. OID_CASE(OID_WAN_GET_COMP_INFO);
  137. OID_CASE(OID_WAN_GET_INFO);
  138. OID_CASE(OID_WAN_GET_LINK_INFO);
  139. OID_CASE(OID_WAN_GET_STATS_INFO);
  140. OID_CASE(OID_WAN_HEADER_FORMAT);
  141. OID_CASE(OID_WAN_LINE_COUNT);
  142. OID_CASE(OID_WAN_MEDIUM_SUBTYPE);
  143. OID_CASE(OID_WAN_PERMANENT_ADDRESS);
  144. OID_CASE(OID_WAN_PROTOCOL_TYPE);
  145. OID_CASE(OID_WAN_QUALITY_OF_SERVICE);
  146. OID_CASE(OID_WAN_SET_BRIDGE_INFO);
  147. OID_CASE(OID_WAN_SET_COMP_INFO);
  148. OID_CASE(OID_WAN_SET_LINK_INFO);
  149. default:
  150. OidName = "Unknown OID";
  151. break;
  152. }
  153. return OidName;
  154. }
  155. #endif
  156. STATIC NDIS_STATUS
  157. MpReadConfig(
  158. NDIS_HANDLE WrapperConfigurationContext
  159. )
  160. {
  161. NDIS_STATUS Status, ReturnStatus = NDIS_STATUS_SUCCESS;
  162. PNDIS_CONFIGURATION_PARAMETER Value;
  163. NDIS_HANDLE hConfig;
  164. NdisOpenConfiguration(&ReturnStatus, &hConfig, WrapperConfigurationContext);
  165. if (ReturnStatus==NDIS_STATUS_SUCCESS)
  166. {
  167. OsReadConfig(hConfig);
  168. NdisCloseConfiguration(hConfig);
  169. }
  170. #if 0
  171. OsGetFullHostName();
  172. #endif
  173. return ReturnStatus;
  174. }
  175. NDIS_STATUS
  176. MiniportInitialize(
  177. OUT PNDIS_STATUS OpenErrorStatus,
  178. OUT PUINT SelectedMediumIndex,
  179. IN PNDIS_MEDIUM MediumArray,
  180. IN UINT MediumArraySize,
  181. IN NDIS_HANDLE NdisAdapterHandle,
  182. IN NDIS_HANDLE WrapperConfigurationContext
  183. )
  184. {
  185. ULONG i;
  186. NDIS_STATUS Status;
  187. PPPTP_ADAPTER pAdapter = NULL;
  188. DbgMsgInit();
  189. InitMemory();
  190. Status = MpReadConfig(WrapperConfigurationContext);
  191. if(Status != NDIS_STATUS_SUCCESS)
  192. {
  193. goto miDone;
  194. }
  195. Status = InitThreading( NdisAdapterHandle );
  196. if(Status != NDIS_STATUS_SUCCESS)
  197. {
  198. goto miDone;
  199. }
  200. InitCallLayer();
  201. DEBUGMSG(DBG_FUNC, (DTEXT("+MiniportInitialize\n")));
  202. // Find our medium
  203. for (i=0; i<MediumArraySize; i++)
  204. {
  205. if (MediumArray[i]==NdisMediumWan)
  206. {
  207. break;
  208. }
  209. }
  210. // Did we find a medium?
  211. if (i<MediumArraySize)
  212. {
  213. *SelectedMediumIndex = i;
  214. }
  215. else
  216. {
  217. DEBUGMSG(DBG_ERROR, (DTEXT("PPTP-ERROR: Medium not found\n")));
  218. Status = NDIS_STATUS_UNSUPPORTED_MEDIA;
  219. goto miDone;
  220. }
  221. ASSERT(!pgAdapter);
  222. pgAdapter = pAdapter = AdapterAlloc(NdisAdapterHandle);
  223. if (pAdapter==NULL)
  224. {
  225. Status = NDIS_STATUS_RESOURCES;
  226. goto miDone;
  227. }
  228. NdisMSetAttributesEx(NdisAdapterHandle,
  229. (NDIS_HANDLE)pAdapter,
  230. 0,
  231. NDIS_ATTRIBUTE_IGNORE_PACKET_TIMEOUT |
  232. NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT |
  233. NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND |
  234. NDIS_ATTRIBUTE_DESERIALIZE,
  235. NdisInterfaceInternal
  236. );
  237. NdisZeroMemory(&gCounters, sizeof(gCounters));
  238. miDone:
  239. if (Status!=NDIS_STATUS_SUCCESS)
  240. {
  241. DEBUGMSG(DBG_ERROR, (DTEXT("-MiniportInitialize returning failure %x\n"), Status));
  242. if (pAdapter)
  243. {
  244. AdapterFree(pAdapter);
  245. pgAdapter = NULL;
  246. }
  247. DeinitThreading();
  248. DeinitMemory();
  249. DbgMsgUninit();
  250. }
  251. DEBUGMSG(DBG_FUNC, (DTEXT("-MiniportInitialize\n")));
  252. return Status;
  253. }
  254. VOID
  255. MiniportHalt(
  256. IN NDIS_HANDLE MiniportAdapterContext
  257. )
  258. {
  259. PPPTP_ADAPTER pAdapter = (PPPTP_ADAPTER)MiniportAdapterContext;
  260. ULONG i;
  261. DEBUGMSG(DBG_FUNC, (DTEXT("+MiniportHalt\n")));
  262. // There are several ways the driver can be brought down. Check for
  263. // lingering calls.
  264. for (i=0; i<pAdapter->Info.Endpoints; i++)
  265. {
  266. PCALL_SESSION pCall = pAdapter->pCallArray[i];
  267. if (IS_CALL(pCall))
  268. {
  269. NdisAcquireSpinLock(&pCall->Lock);
  270. if (pCall->State>STATE_CALL_IDLE && pCall->State<STATE_CALL_CLEANUP)
  271. {
  272. CallSetState(pCall, STATE_CALL_CLEANUP, LINEDISCONNECTMODE_NORMAL, LOCKED);
  273. CallDetachFromAdapter(pCall);
  274. CallCleanup(pCall, LOCKED);
  275. }
  276. NdisReleaseSpinLock(&pCall->Lock);
  277. }
  278. }
  279. PptpAuthenticateIncomingCalls = FALSE;
  280. if (g_AcceptClientList)
  281. {
  282. MyMemFree(g_AcceptClientList, sizeof(CLIENT_ADDRESS)*g_ulAcceptClientAddresses);
  283. g_AcceptClientList = NULL;
  284. }
  285. g_ulAcceptClientAddresses = 0;
  286. if (g_TrustedClientList)
  287. {
  288. MyMemFree(g_TrustedClientList, sizeof(CLIENT_ADDRESS)*g_ulTrustedClientAddresses);
  289. g_TrustedClientList = NULL;
  290. }
  291. g_ulTrustedClientAddresses = 0;
  292. if (pAdapter->hCtdiDg)
  293. {
  294. CtdiClose(pAdapter->hCtdiDg);
  295. pAdapter->hCtdiDg = NULL;
  296. }
  297. if (pAdapter->hCtdiListen)
  298. {
  299. CtdiClose(pAdapter->hCtdiListen);
  300. pAdapter->hCtdiListen = NULL;
  301. }
  302. for (i=0; i<10; i++)
  303. {
  304. if (IsListEmpty(&pAdapter->ControlTunnelList))
  305. {
  306. break;
  307. }
  308. // Give the Ctl and Tdi layers a chance to clean up.
  309. NdisMSleep(50*1000);
  310. }
  311. CtdiShutdown();
  312. // Deinit FIPS
  313. if (pAdapter->pFipsFileObject)
  314. {
  315. ObDereferenceObject(pAdapter->pFipsFileObject);
  316. pAdapter->pFipsFileObject = NULL;
  317. }
  318. AdapterFree(pAdapter);
  319. pgAdapter = NULL;
  320. DeinitThreading();
  321. DeinitMemory();
  322. DbgMsgUninit();
  323. DEBUGMSG(DBG_FUNC, (DTEXT("-MiniportHalt\n")));
  324. }
  325. NDIS_STATUS
  326. MiniportReset(
  327. OUT PBOOLEAN AddressingReset,
  328. IN NDIS_HANDLE MiniportAdapterContext
  329. )
  330. {
  331. ASSERTMSG(0,(DTEXT("MiniportReset not implemented")));
  332. return (NDIS_STATUS_FAILURE);
  333. }
  334. #ifndef WIN95_BUILD // ToDo: Win98PNP
  335. NDIS_PNP_CAPABILITIES PnpCaps =
  336. {
  337. 0, // Flags
  338. {
  339. NdisDeviceStateUnspecified,
  340. NdisDeviceStateUnspecified,
  341. NdisDeviceStateUnspecified
  342. }
  343. };
  344. #endif
  345. // CHECK_TAPI_SIZE forces the internal tapi size values to conform to the size
  346. // passed in the MiniportQueryInformation call
  347. #define CHECK_TAPI_SIZE(ptr, size, type1, struct2) \
  348. (((size)>=sizeof(type1)) && \
  349. ((((type1 *)(ptr))->struct2.ulTotalSize)=(size)-FIELD_OFFSET(type1, struct2)))
  350. #define TAPI_USED_SIZE(ptr, type1, struct2) \
  351. (((type1 *)(ptr))->struct2.ulUsedSize+FIELD_OFFSET(type1, struct2))
  352. #define TAPI_NEEDED_SIZE(ptr, type1, struct2) \
  353. (((type1 *)(ptr))->struct2.ulNeededSize+FIELD_OFFSET(type1, struct2))
  354. // Repeated code, make a macro
  355. #define HANDLE_TAPI_OID(type1, struct2, TapiFunc) \
  356. { \
  357. DoCopy = FALSE; \
  358. if (CHECK_TAPI_SIZE(InformationBuffer, \
  359. InformationBufferLength, \
  360. type1, \
  361. struct2)) \
  362. { \
  363. Status = TapiFunc(pAdapter, InformationBuffer); \
  364. UsedLength = TAPI_USED_SIZE(InformationBuffer, \
  365. type1, \
  366. struct2); \
  367. NeededLength = TAPI_NEEDED_SIZE(InformationBuffer, \
  368. type1, \
  369. struct2); \
  370. if (NeededLength>UsedLength) \
  371. { \
  372. PartialReturn = TRUE; \
  373. } \
  374. } \
  375. else \
  376. { \
  377. UsedLength = sizeof(type1); \
  378. } \
  379. }
  380. NDIS_STATUS
  381. MiniportQueryInformation(
  382. IN NDIS_HANDLE MiniportAdapterContext,
  383. IN NDIS_OID Oid,
  384. IN PVOID InformationBuffer,
  385. IN ULONG InformationBufferLength,
  386. OUT PULONG BytesWritten,
  387. OUT PULONG BytesNeeded
  388. )
  389. {
  390. PPPTP_ADAPTER pAdapter = (PPPTP_ADAPTER)MiniportAdapterContext;
  391. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  392. ULONG_PTR GenericUlong = 0;
  393. PVOID SourceBuffer = (PVOID) &GenericUlong;
  394. ULONG UsedLength = sizeof(ULONG);
  395. ULONG NeededLength = 0; // Used when returning part of all required info
  396. BOOLEAN DoCopy = TRUE;
  397. BOOLEAN PartialReturn = FALSE;
  398. UCHAR PptpWanAddress[6] = {'P','P','T','P','0','0'}; // This is the address returned by OID_WAN_*_ADDRESS.
  399. DEBUGMSG(DBG_FUNC|DBG_NDIS, (DTEXT("+MiniportQueryInformation Oid==0x%08X %hs\n"),
  400. Oid, GetOidString(Oid)));
  401. switch (Oid)
  402. {
  403. case OID_GEN_MAC_OPTIONS:
  404. {
  405. // Believe these to be pretty much ignored.
  406. GenericUlong = NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
  407. NDIS_MAC_OPTION_TRANSFERS_NOT_PEND;
  408. break;
  409. }
  410. case OID_GEN_MAXIMUM_LOOKAHEAD:
  411. {
  412. GenericUlong = PPTP_MAX_LOOKAHEAD;
  413. break;
  414. }
  415. case OID_GEN_SUPPORTED_LIST:
  416. {
  417. SourceBuffer = (PVOID) SupportedOids;
  418. UsedLength = sizeof(SupportedOids);
  419. break;
  420. }
  421. case OID_GEN_RCV_ERROR:
  422. {
  423. GenericUlong = gCounters.PacketsRejected + gCounters.PacketsMissed;
  424. break;
  425. }
  426. case OID_GEN_RCV_OK:
  427. {
  428. GenericUlong = gCounters.PacketsReceived;
  429. break;
  430. }
  431. case OID_GEN_XMIT_ERROR:
  432. {
  433. GenericUlong = gCounters.PacketsSentError;
  434. break;
  435. }
  436. case OID_GEN_XMIT_OK:
  437. {
  438. GenericUlong = gCounters.PacketsSent - gCounters.PacketsSentError;
  439. break;
  440. }
  441. case OID_TAPI_GET_ADDRESS_CAPS:
  442. {
  443. HANDLE_TAPI_OID(NDIS_TAPI_GET_ADDRESS_CAPS,
  444. LineAddressCaps,
  445. TapiGetAddressCaps);
  446. break;
  447. }
  448. case OID_TAPI_GET_CALL_INFO:
  449. {
  450. // If the buffer isn't large enough at all, the size of all the
  451. // data including strings is returned. If the buffer is big enough
  452. // for the data structure but not the strings, then only the data
  453. // structure is returned.
  454. // Get the length needed, including strings
  455. NeededLength = 0;
  456. Status = TapiGetCallInfo(pAdapter, InformationBuffer, &NeededLength);
  457. UsedLength = NeededLength;
  458. if( Status == NDIS_STATUS_SUCCESS )
  459. {
  460. if (sizeof(NDIS_TAPI_GET_CALL_INFO)<=InformationBufferLength)
  461. {
  462. if( NeededLength > InformationBufferLength )
  463. {
  464. UsedLength = sizeof(NDIS_TAPI_GET_CALL_INFO);
  465. PartialReturn = TRUE;
  466. }else{
  467. // Used=Needed = the entire thing inluding strings
  468. }
  469. Status = TapiGetCallInfo(pAdapter,
  470. InformationBuffer,
  471. NULL);
  472. // NULL in the second call makes it fill in the structure,
  473. // which it doesn't do on the first call.
  474. }
  475. }
  476. DoCopy = FALSE;
  477. break;
  478. }
  479. case OID_TAPI_GET_CALL_STATUS:
  480. {
  481. HANDLE_TAPI_OID(NDIS_TAPI_GET_CALL_STATUS,
  482. LineCallStatus,
  483. TapiGetCallStatus);
  484. break;
  485. }
  486. case OID_TAPI_GET_DEV_CAPS:
  487. {
  488. HANDLE_TAPI_OID(NDIS_TAPI_GET_DEV_CAPS,
  489. LineDevCaps,
  490. TapiGetDevCaps);
  491. if (NeededLength < TAPI_DEV_CAPS_SIZE)
  492. {
  493. NeededLength = TAPI_DEV_CAPS_SIZE;
  494. }
  495. break;
  496. }
  497. case OID_TAPI_GET_ID:
  498. {
  499. PNDIS_TAPI_GET_ID pRequest = (PNDIS_TAPI_GET_ID)InformationBuffer;
  500. UsedLength = sizeof(NDIS_TAPI_GET_ID);
  501. if (UsedLength<=InformationBufferLength)
  502. {
  503. if(pRequest->ulDeviceClassOffset < sizeof(NDIS_TAPI_GET_ID) ||
  504. pRequest->ulDeviceClassOffset >= InformationBufferLength ||
  505. pRequest->ulDeviceClassSize > InformationBufferLength - pRequest->ulDeviceClassOffset)
  506. {
  507. Status = NDIS_STATUS_FAILURE;
  508. break;
  509. }
  510. HANDLE_TAPI_OID(NDIS_TAPI_GET_ID,
  511. DeviceID,
  512. TapiGetId);
  513. }
  514. break;
  515. }
  516. case OID_TAPI_GET_ADDRESS_STATUS:
  517. {
  518. HANDLE_TAPI_OID(NDIS_TAPI_GET_ADDRESS_STATUS,
  519. LineAddressStatus,
  520. TapiGetAddressStatus);
  521. break;
  522. }
  523. case OID_TAPI_GET_EXTENSION_ID:
  524. {
  525. UsedLength = sizeof(NDIS_TAPI_GET_EXTENSION_ID);
  526. if (UsedLength<=InformationBufferLength)
  527. {
  528. DoCopy = FALSE;
  529. Status = TapiGetExtensionId(pAdapter, InformationBuffer);
  530. }
  531. break;
  532. }
  533. case OID_TAPI_MAKE_CALL:
  534. {
  535. PNDIS_TAPI_MAKE_CALL pRequest = (PNDIS_TAPI_MAKE_CALL)InformationBuffer;
  536. UsedLength = sizeof(NDIS_TAPI_MAKE_CALL);
  537. if (UsedLength<=InformationBufferLength)
  538. {
  539. if (pRequest->ulDestAddressSize < 2 ||
  540. pRequest->ulDestAddressOffset < sizeof(NDIS_TAPI_MAKE_CALL) ||
  541. pRequest->ulDestAddressOffset >= InformationBufferLength ||
  542. pRequest->ulDestAddressSize > InformationBufferLength - pRequest->ulDestAddressOffset)
  543. {
  544. // Bogus input data
  545. DBG_D(DBG_ERROR, pRequest->ulDestAddressOffset);
  546. Status = NDIS_STATUS_FAILURE;
  547. }
  548. else
  549. {
  550. UsedLength = pRequest->ulDestAddressSize + pRequest->ulDestAddressOffset;
  551. }
  552. if (Status == NDIS_STATUS_SUCCESS)
  553. {
  554. DoCopy = FALSE;
  555. Status = TapiMakeCall(pAdapter, InformationBuffer);
  556. }
  557. }
  558. break;
  559. }
  560. case OID_TAPI_NEGOTIATE_EXT_VERSION:
  561. {
  562. UsedLength = sizeof(NDIS_TAPI_NEGOTIATE_EXT_VERSION);
  563. if (UsedLength<=InformationBufferLength)
  564. {
  565. DoCopy = FALSE;
  566. Status = TapiNegotiateExtVersion(pAdapter, InformationBuffer);
  567. }
  568. break;
  569. }
  570. case OID_TAPI_OPEN:
  571. {
  572. UsedLength = sizeof(NDIS_TAPI_OPEN);
  573. if (UsedLength<=InformationBufferLength)
  574. {
  575. DoCopy = FALSE;
  576. Status = TapiOpen(pAdapter, InformationBuffer);
  577. }
  578. break;
  579. }
  580. case OID_TAPI_PROVIDER_INITIALIZE:
  581. {
  582. UsedLength = sizeof(NDIS_TAPI_PROVIDER_INITIALIZE);
  583. if (UsedLength<=InformationBufferLength)
  584. {
  585. DoCopy = FALSE;
  586. Status = TapiProviderInitialize(pAdapter, InformationBuffer);
  587. }
  588. break;
  589. }
  590. case OID_WAN_GET_INFO:
  591. {
  592. SourceBuffer = &pAdapter->Info;
  593. UsedLength = sizeof(pAdapter->Info);
  594. break;
  595. }
  596. case OID_WAN_MEDIUM_SUBTYPE:
  597. {
  598. GenericUlong = OS_SPECIFIC_NDIS_WAN_MEDIUM_TYPE;
  599. break;
  600. }
  601. case OID_WAN_CURRENT_ADDRESS:
  602. case OID_WAN_PERMANENT_ADDRESS:
  603. {
  604. SourceBuffer = PptpWanAddress;
  605. UsedLength = sizeof(PptpWanAddress);
  606. break;
  607. }
  608. #ifndef WIN95_BUILD // ToDo: Win98PNP
  609. case OID_PNP_CAPABILITIES:
  610. {
  611. SourceBuffer = &PnpCaps;
  612. UsedLength = sizeof(PnpCaps);
  613. break;
  614. }
  615. #endif
  616. case OID_PNP_SET_POWER:
  617. // Just success
  618. break;
  619. case OID_PNP_QUERY_POWER:
  620. // Just success
  621. break;
  622. case OID_PNP_ENABLE_WAKE_UP:
  623. // Just success
  624. break;
  625. case OID_GEN_CURRENT_LOOKAHEAD:
  626. case OID_GEN_DRIVER_VERSION:
  627. case OID_GEN_HARDWARE_STATUS:
  628. case OID_GEN_LINK_SPEED:
  629. case OID_GEN_MAXIMUM_FRAME_SIZE:
  630. case OID_GEN_MAXIMUM_TOTAL_SIZE:
  631. case OID_GEN_MEDIA_SUPPORTED:
  632. case OID_GEN_MEDIA_IN_USE:
  633. case OID_GEN_RECEIVE_BLOCK_SIZE:
  634. case OID_GEN_RECEIVE_BUFFER_SPACE:
  635. case OID_GEN_TRANSMIT_BLOCK_SIZE:
  636. case OID_GEN_TRANSMIT_BUFFER_SPACE:
  637. case OID_GEN_VENDOR_DESCRIPTION:
  638. case OID_GEN_VENDOR_ID:
  639. case OID_WAN_GET_BRIDGE_INFO:
  640. case OID_WAN_GET_LINK_INFO:
  641. case OID_WAN_GET_STATS_INFO:
  642. case OID_WAN_HEADER_FORMAT:
  643. case OID_WAN_LINE_COUNT:
  644. case OID_WAN_PROTOCOL_TYPE:
  645. case OID_WAN_QUALITY_OF_SERVICE:
  646. case OID_WAN_SET_BRIDGE_INFO:
  647. case OID_WAN_SET_COMP_INFO:
  648. case OID_WAN_SET_LINK_INFO:
  649. DEBUGMSG(DBG_ERROR, (DTEXT("OID Not Implemented %hs\n"), GetOidString(Oid)));
  650. case OID_WAN_GET_COMP_INFO: // never supported
  651. default:
  652. {
  653. UsedLength = NeededLength = 0;
  654. Status = NDIS_STATUS_NOT_SUPPORTED;
  655. break;
  656. }
  657. }
  658. if (!PartialReturn)
  659. {
  660. NeededLength = UsedLength;
  661. }
  662. if (Status == NDIS_STATUS_SUCCESS || Status == NDIS_STATUS_PENDING)
  663. {
  664. if (InformationBufferLength < UsedLength)
  665. {
  666. Status = NDIS_STATUS_INVALID_LENGTH;
  667. *BytesNeeded = UsedLength;
  668. }
  669. else
  670. {
  671. *BytesNeeded = NeededLength;
  672. *BytesWritten = UsedLength;
  673. if (DoCopy)
  674. {
  675. NdisMoveMemory(InformationBuffer, SourceBuffer, UsedLength);
  676. }
  677. }
  678. }
  679. DEBUGMSG(DBG_FUNC|DBG_ERR(Status), (DTEXT("-MiniportQueryInformation %08X\n"), Status));
  680. return Status;
  681. }
  682. NDIS_STATUS
  683. MiniportSetInformation(
  684. IN NDIS_HANDLE MiniportAdapterContext,
  685. IN NDIS_OID Oid,
  686. IN PVOID InformationBuffer,
  687. IN ULONG InformationBufferLength,
  688. OUT PULONG BytesRead,
  689. OUT PULONG BytesNeeded
  690. )
  691. {
  692. PPPTP_ADAPTER pAdapter = (PPPTP_ADAPTER)MiniportAdapterContext;
  693. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  694. ULONG_PTR GenericUlong = 0;
  695. ULONG UsedLength = sizeof(ULONG);
  696. DEBUGMSG(DBG_FUNC|DBG_NDIS, (DTEXT("+MiniportSetInformation Oid==0x%08X %hs\n"),
  697. Oid, GetOidString(Oid)));
  698. switch (Oid)
  699. {
  700. case OID_TAPI_ANSWER:
  701. {
  702. UsedLength = sizeof(NDIS_TAPI_ANSWER);
  703. if (UsedLength<=InformationBufferLength)
  704. {
  705. Status = TapiAnswer(pAdapter, InformationBuffer);
  706. }
  707. break;
  708. }
  709. case OID_TAPI_CLOSE:
  710. {
  711. UsedLength = sizeof(NDIS_TAPI_CLOSE);
  712. if (UsedLength<=InformationBufferLength)
  713. {
  714. Status = TapiClose(pAdapter, InformationBuffer);
  715. }
  716. break;
  717. }
  718. case OID_TAPI_CLOSE_CALL:
  719. {
  720. UsedLength = sizeof(NDIS_TAPI_CLOSE_CALL);
  721. if (UsedLength<=InformationBufferLength)
  722. {
  723. Status = TapiCloseCall(pAdapter, InformationBuffer);
  724. }
  725. break;
  726. }
  727. case OID_TAPI_DROP:
  728. {
  729. UsedLength = sizeof(NDIS_TAPI_DROP);
  730. if (UsedLength<=InformationBufferLength)
  731. {
  732. // We don't use the UserUserInfo
  733. Status = TapiDrop(pAdapter, InformationBuffer);
  734. }
  735. break;
  736. }
  737. case OID_TAPI_PROVIDER_SHUTDOWN:
  738. {
  739. UsedLength = sizeof(NDIS_TAPI_PROVIDER_SHUTDOWN);
  740. if (UsedLength<=InformationBufferLength)
  741. {
  742. // We don't use the UserUserInfo
  743. Status = TapiProviderShutdown(pAdapter, InformationBuffer);
  744. }
  745. break;
  746. }
  747. case OID_TAPI_SET_DEFAULT_MEDIA_DETECTION:
  748. {
  749. UsedLength = sizeof(NDIS_TAPI_SET_DEFAULT_MEDIA_DETECTION);
  750. if (UsedLength<=InformationBufferLength)
  751. {
  752. Status = TapiSetDefaultMediaDetection(pAdapter, InformationBuffer);
  753. }
  754. break;
  755. }
  756. case OID_TAPI_SET_STATUS_MESSAGES:
  757. {
  758. UsedLength = sizeof(NDIS_TAPI_SET_STATUS_MESSAGES);
  759. if (UsedLength<=InformationBufferLength)
  760. {
  761. Status = TapiSetStatusMessages(pAdapter, InformationBuffer);
  762. }
  763. break;
  764. }
  765. case OID_WAN_SET_LINK_INFO:
  766. {
  767. UsedLength = sizeof(NDIS_WAN_SET_LINK_INFO);
  768. if (UsedLength<=InformationBufferLength)
  769. {
  770. Status = CallSetLinkInfo(pAdapter, InformationBuffer);
  771. }
  772. break;
  773. }
  774. case OID_PNP_SET_POWER:
  775. case OID_PNP_ENABLE_WAKE_UP:
  776. UsedLength = 0;
  777. // Success
  778. break;
  779. default:
  780. DEBUGMSG(DBG_ERROR, (DTEXT("SetInformation OID Not Implemented %hs\n"), GetOidString(Oid)));
  781. // No break
  782. case OID_TAPI_ACCEPT:
  783. Status = NDIS_STATUS_INVALID_OID;
  784. break;
  785. }
  786. *BytesNeeded = UsedLength;
  787. if (Status==NDIS_STATUS_SUCCESS || Status == NDIS_STATUS_PENDING)
  788. {
  789. if (UsedLength>InformationBufferLength)
  790. {
  791. *BytesRead = 0;
  792. Status = NDIS_STATUS_INVALID_LENGTH;
  793. }
  794. else
  795. {
  796. *BytesRead = UsedLength;
  797. }
  798. }
  799. DEBUGMSG(DBG_FUNC|DBG_ERR(Status), (DTEXT("-MiniportSetInformation %08X\n"), Status));
  800. return Status;
  801. }
  802. NDIS_STATUS
  803. MiniportWanSend(
  804. IN NDIS_HANDLE MiniportAdapterContext,
  805. IN NDIS_HANDLE NdisLinkHandle,
  806. IN PNDIS_WAN_PACKET WanPacket
  807. )
  808. {
  809. PPPTP_ADAPTER pAdapter = (PPPTP_ADAPTER)MiniportAdapterContext;
  810. PCALL_SESSION pCall;
  811. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  812. DEBUGMSG(DBG_FUNC, (DTEXT("+MiniportWanSend NdisLinkHandle=%x, WanPacket=%x\n"),
  813. NdisLinkHandle, WanPacket));
  814. pCall = CallGetCall(pAdapter, LinkHandleToId(NdisLinkHandle));
  815. if (!IS_CALL(pCall) || pCall->State!=STATE_CALL_ESTABLISHED)
  816. {
  817. // Just say success, don't send.
  818. goto mwsDone;
  819. }
  820. DEBUGMSG(DBG_TX, (DTEXT("TxPacket: %08x Call: %08x\n"), WanPacket, pCall));
  821. REFERENCE_OBJECT(pCall);
  822. Status = CallQueueTransmitPacket(pCall, WanPacket);
  823. if (Status!=NDIS_STATUS_PENDING)
  824. {
  825. DEREFERENCE_OBJECT(pCall);
  826. }
  827. mwsDone:
  828. DEBUGMSG(DBG_FUNC|DBG_ERR(Status), (DTEXT("-MiniportWanSend %08x\n"), Status));
  829. return Status;
  830. }