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.

927 lines
32 KiB

  1. #ifndef _MINIPORT_H_
  2. #define _MINIPORT_H_
  3. #define MP_NDIS_MajorVersion 4
  4. #define MP_NDIS_MinorVersion 0
  5. typedef struct _LINE* PLINE;
  6. typedef struct _CALL* PCALL;
  7. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8. Functional Description:
  9. These macros will be called by MpWanSend() and PrSendComplete()
  10. functions when a PPPOE_PACKET with references to a packet owned by NDIS is
  11. created and freed, respectively.
  12. ---------------------------------------------------------------------------*/
  13. #define MpPacketOwnedByNdiswanReceived( pM ) \
  14. NdisInterlockedIncrement( &(pM)->NumPacketsOwnedByNdiswan )
  15. #define MpPacketOwnedByNdiswanReturned( pM ) \
  16. NdisInterlockedDecrement( &(pM)->NumPacketsOwnedByNdiswan )
  17. typedef struct
  18. _ADAPTER
  19. {
  20. //
  21. // Tag for the adapter control block (used for debugging).
  22. //
  23. ULONG tagAdapter;
  24. //
  25. // Keeps the number of references on this adapter.
  26. // References are added and deleted for the following operations:
  27. //
  28. // (a) A reference is added when the adapter is initialized and removed when
  29. // it is halted.
  30. //
  31. // (b) A reference is added when tapi provider is open, and removed when it is shutdown.
  32. //
  33. LONG lRef;
  34. //
  35. // Spin lock to synchronize access to shared members.
  36. //
  37. NDIS_SPIN_LOCK lockAdapter;
  38. //
  39. // This event will be triggered if MPBF_MiniportHaltPending is set and ref count drops to 0.
  40. //
  41. NDIS_EVENT eventAdapterHalted;
  42. //
  43. // These are the various bit flags to indicate other state information for the adapter:
  44. //
  45. // (a) MPBF_MiniportIdle: Indicates that the miniport is in idle state.
  46. //
  47. // (b) MPBF_MiniportInitialized: Indicates that the miniport is initialized.
  48. // The following pending flags can be set additionally.
  49. // MPBF_MiniportHaltPending
  50. //
  51. // (c) MPBF_MiniportHaltPending: Indicates that a miniport halt operation is pending
  52. // on the adappter.
  53. //
  54. // (d) MPBF_MiniportHalted: Indicates that miniport has halted completely.
  55. // No other flags can be set at this time.
  56. //
  57. ULONG ulMpFlags;
  58. #define MPBF_MiniportIdle 0x00000000
  59. #define MPBF_MiniportInitialized 0x00000001
  60. #define MPBF_MiniportHaltPending 0x00000002
  61. #define MPBF_MiniportHalted 0x00000004
  62. //
  63. // Handle passed to us in MiniportInitialize().
  64. // We should keep it around and pass it back to NDISWAN
  65. // in some functions.
  66. //
  67. NDIS_HANDLE MiniportAdapterHandle;
  68. //
  69. // Number of packets owned by NDISWAN, passed to us and will be returned
  70. // to Ndiswan
  71. //
  72. LONG NumPacketsOwnedByNdiswan;
  73. //
  74. // This is the built-in Tapi Provider context.
  75. // It keeps the tables for lines and calls.
  76. //
  77. struct
  78. {
  79. //
  80. // Keeps references on the tapi provider
  81. // References are added and deleted for the following operations:
  82. //
  83. // (a) A reference is added when TapiProvider is initialized and removed when
  84. // it is shutdown.
  85. //
  86. // (b) A reference is added when a line open, and removed when line is closed.
  87. //
  88. LONG lRef;
  89. //
  90. // Tapi Provider context flags.
  91. //
  92. // (a) TPBF_TapiProvIdle: Indicates that the line is in idle state.
  93. //
  94. // (b) TPBF_TapiProvInitialized: Indicates that TAPI provider is initialized.
  95. //
  96. // (c) TPBF_TapiProvShutdownPending: Indicates that a TAPI provider shutdown operation
  97. // is pending.
  98. //
  99. // (d) TPBF_TapiProvShutdown: Indicates that TAPI provider is shutdown.
  100. //
  101. // (e) LNBF_NotifyNDIS: This flag indicates that an asynchronous completion of a Tapi Provider
  102. // shutdown request must be communicated to NDIS using NdisMSetInformationComplete().
  103. //
  104. ULONG ulTpFlags;
  105. #define TPBF_TapiProvIdle 0x00000000
  106. #define TPBF_TapiProvInitialized 0x00000001
  107. #define TPBF_TapiProvShutdownPending 0x00000002
  108. #define TPBF_TapiProvShutdown 0x00000004
  109. #define TPBF_NotifyNDIS 0x00000008
  110. //
  111. // This is supplied by Tapi.
  112. // It is the base index for enumeration of line devices on this tapi provider.
  113. //
  114. ULONG ulDeviceIDBase;
  115. //
  116. // This is the table that holds pointers to active line contexts.
  117. // (pLine->hdLine is holds the index to this table)
  118. //
  119. PLINE* LineTable;
  120. //
  121. // Current active number of lines
  122. //
  123. UINT nActiveLines;
  124. //
  125. // This table holds the handles to calls.
  126. // It's size is pAdapter->nMaxLines * pAdapter->nCallsPerLine.
  127. //
  128. HANDLE_TABLE hCallTable;
  129. } TapiProv;
  130. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++
  131. typedef struct _NDIS_WAN_INFO {
  132. ULONG MaxFrameSize;
  133. ULONG MaxTransmit;
  134. ULONG HeaderPadding;
  135. ULONG TailPadding;
  136. ULONG Endpoints;
  137. UINT MemoryFlags;
  138. NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress;
  139. ULONG FramingBits;
  140. ULONG DesiredACCM;
  141. } NDIS_WAN_INFO, *PNDIS_WAN_INFO;
  142. -------------------------------------------------------*/
  143. NDIS_WAN_INFO NdisWanInfo;
  144. /////////////////////////////////////////////////////////
  145. //
  146. // Config values read from registry
  147. //
  148. /////////////////////////////////////////////////////////
  149. //
  150. // Indicates the role of the machine:
  151. // - fClientRole is TRUE: Machine acts as a client.
  152. // Only outgoing calls are connected, and no calls are received.
  153. //
  154. // - fClientRole is FALSE: Machine acts as a server.
  155. // Only incoming calls are accepted, and no outgoing calls are allowed.
  156. //
  157. BOOLEAN fClientRole;
  158. //
  159. // This is the string that holds the Service-name this server offers.
  160. // It must be an UTF-8 string per PPPoE RFC.
  161. //
  162. // It is only used for incoming calls.
  163. //
  164. #define MAX_COMPUTERNAME_LENGTH 200
  165. #define SERVICE_NAME_EXTENSION " PPPoE"
  166. #define MAX_SERVICE_NAME_LENGTH 256
  167. CHAR ServiceName[MAX_SERVICE_NAME_LENGTH];
  168. //
  169. // Indicates the length of the Service name string
  170. //
  171. USHORT nServiceNameLength;
  172. //
  173. // This is the string that holds the AC-name for this server.
  174. // It must be an UTF-8 string per PPPoE RFC.
  175. //
  176. // It is only used for incoming calls.
  177. //
  178. #define MAX_AC_NAME_LENGTH 256
  179. CHAR ACName[MAX_AC_NAME_LENGTH];
  180. //
  181. // Indicates the length of the AC name string
  182. //
  183. USHORT nACNameLength;
  184. //
  185. // Max number of simultaneous calls that can be established between the same
  186. // client and server
  187. //
  188. UINT nClientQuota;
  189. //
  190. // Indicates the number of line contexts that will be created.
  191. //
  192. UINT nMaxLines;
  193. //
  194. // Indicates the number of calls that each individual line will support.
  195. //
  196. UINT nCallsPerLine;
  197. //
  198. // Indicates the maximum number of timeouts for the PPPoE FSM.
  199. // When the current number of timeouts , reach this number call will be dropped.
  200. //
  201. UINT nMaxTimeouts;
  202. //
  203. // This is the timeout period for client side operations (in ms)
  204. //
  205. ULONG ulSendTimeout;
  206. //
  207. // This is the timeout period for server side operations (in ms)
  208. //
  209. ULONG ulRecvTimeout;
  210. //
  211. // This shows the maximum number of packets that NDISWAN can pass to us simultaneously.
  212. // This does not make any sense for us as we do not queue the packets, but send them to
  213. // peer directly when we receive them from NDISWAN.
  214. //
  215. UINT nMaxSendPackets;
  216. //
  217. // This is related to the problem where the server does not support the empty service-name.
  218. // In this case, there is no way for clients to discover the services supported by the server,
  219. // since the server sends back a PADO packet without the empty service-name attribute, and we drop
  220. // it (per RFC). So if this value is TRUE, then we break the RFC and do the following:
  221. // If client asks for the empty service name, then we do not ignore the PADO that does not contain
  222. // the empty service-name. Instead we try to find the empty service-name field, and request it if its
  223. // available. If not, then we request the first service available in the PADO.
  224. //
  225. BOOLEAN fAcceptAnyService;
  226. }
  227. ADAPTER;
  228. //
  229. // This is our call line context.
  230. // All information pertinent to a line is kept in this context.
  231. //
  232. typedef struct
  233. _LINE
  234. {
  235. //
  236. // Tag for the line control block (used for debugging).
  237. //
  238. ULONG tagLine;
  239. //
  240. // Keeps reference count on the line control block.
  241. // References are added and deleted for the following operations:
  242. //
  243. // (a) A reference is added when a line is opened and removed when
  244. // line is closed.
  245. //
  246. // (b) A reference is added when a call context is created on the line,
  247. // and removed when call context is cleaned up.
  248. //
  249. LONG lRef;
  250. //
  251. // Spin lock to synchronize access to shared members
  252. //
  253. NDIS_SPIN_LOCK lockLine;
  254. //
  255. // These are the various bit flags to indicate other state information for the line:
  256. //
  257. // (a) LNBF_LineIdle: Indicates that the line is in idle state.
  258. //
  259. // (b) LNBF_LineOpen: Indicates that the line is in open state. Whan this flag is set,
  260. // only the following pending flags may be set additionally:
  261. // LNBF_LineClosePending
  262. //
  263. // (c) LNBF_LineClosePending: This pending flag can be only set only if LNBF_LineOpen is set,
  264. // and indicates that there is a pending line close operation.
  265. //
  266. // (d) LNBF_LineClosed: Indicates that the line is in closed state. When this flag is set,
  267. // no other pending flags can be set.
  268. //
  269. // (e) LNBF_NotifyNDIS: This flag indicates that an asynchronous completion of a close line request
  270. // must be communicated to NDIS using NdisMSetInformationComplete().
  271. //
  272. // (f) LNBF_MakeOutgoingCalls: This flag is set if line is allowed to make outgoing calls.
  273. // It will be set in TpMakeCall() if machine is acting as a client
  274. // (pAdapter->fClientRole is TRUE).
  275. //
  276. // (g) LNBF_AcceptIncomingCalls: This flag is set if TAPI is able to take calls over this line.
  277. // It will be set in TpSetDefaultMediaDetection() if machine is acting as
  278. // a server (pAdapter->fClientRole is FALSE).
  279. //
  280. ULONG ulLnFlags;
  281. #define LNBF_LineIdle 0x00000000
  282. #define LNBF_LineOpen 0x00000001
  283. #define LNBF_LineClosed 0x00000002
  284. #define LNBF_LineClosePending 0x00000004
  285. #define LNBF_NotifyNDIS 0x00000008
  286. #define LNBF_MakeOutgoingCalls 0x00000010
  287. #define LNBF_AcceptIncomingCalls 0x00000020
  288. //
  289. // Back pointer to owning adapter context
  290. //
  291. ADAPTER* pAdapter;
  292. //
  293. // Indicates the maximum number of calls that is permitted on this line.
  294. // Copy of pAdapter->nCallsPerLine.
  295. //
  296. UINT nMaxCalls;
  297. //
  298. // Indicates the number of current call contexts attached to the line.
  299. //
  300. // It will be incremented when a call context is created and attached to a line,
  301. // and decremented when such a call context is destroyed.
  302. //
  303. UINT nActiveCalls;
  304. //
  305. // Link list of calls
  306. //
  307. LIST_ENTRY linkCalls;
  308. //
  309. // This is the handle assigned by TAPI to the line.
  310. // We obtain it in TpOpenLine() from TAPI.
  311. //
  312. HTAPI_LINE htLine;
  313. //
  314. // This is the handle assigned by us to the line.
  315. // We pass it to TAPI TpOpenLine().
  316. //
  317. // It is basically the index of the entry that points
  318. // to the line context in pAdapter->TapiProv.LineTable
  319. //
  320. HDRV_LINE hdLine;
  321. }
  322. LINE;
  323. typedef enum
  324. _CALLSTATES
  325. {
  326. //
  327. // Initial state
  328. //
  329. CL_stateIdle = 0,
  330. //
  331. // CLIENT states
  332. //
  333. CL_stateSendPadi, // Prepare a PADI packet and broadcast it
  334. CL_stateWaitPado, // Wait for a PADO packet; timeout and broadcast PADI again if necesarry
  335. CL_stateSendPadr, // PADO packet received and processed, prepare a PADR packet and send it to the peer
  336. CL_stateWaitPads, // Wait for a PADS packet; timeout and resend the PADR packet if necesarry
  337. //
  338. // SERVER states
  339. //
  340. CL_stateRecvdPadr, // Received a PADR packet from the peer, and processing it.
  341. // Once it is processed TAPI will be informed about the call.
  342. //
  343. CL_stateOffering, // TAPI is informaed about the call and call is waiting for an OID_TAPI_ANSWER
  344. // from TAPI. If we do not get a an OID_TAPI_ANSWER in a timely manner, we time out
  345. // and drop the call
  346. //
  347. CL_stateSendPads, // Call received a OID_TAPI_ANSWER from TAPI, so prepare a PADS packet and send it to
  348. // the peer.
  349. //
  350. //
  351. // CLIENT or SERVER states
  352. //
  353. CL_stateSessionUp, // Either sent or received a PADS packet and session is established
  354. CL_stateDisconnected // Call is disconnected. Call may proceed to this state from any of the
  355. // above states, it does not need to be connected first.
  356. }
  357. CALLSTATES;
  358. //
  359. // These identify the types of scheduled works:
  360. //
  361. // - CWT_workFsmMakeCall: This item is scheduled from TpMakeCall() to start making a call.
  362. //
  363. typedef enum
  364. _CALL_WORKTYPE
  365. {
  366. CWT_workUnknown = 0,
  367. CWT_workFsmMakeCall
  368. }
  369. CALL_WORKTYPE;
  370. //
  371. // This is our call call context.
  372. // All information pertinent to a call is kept in this context.
  373. //
  374. typedef struct
  375. _CALL
  376. {
  377. //
  378. // Points to the next and previous call contexts in a double linked list
  379. //
  380. LIST_ENTRY linkCalls;
  381. //
  382. // Tag for the call control block (used for debugging).
  383. //
  384. ULONG tagCall;
  385. //
  386. // Keeps reference count on the call control block.
  387. // References are added and deleted for the following operations:
  388. //
  389. // (a) A reference is added for running the initial FSM function for the call.
  390. //
  391. // (b) A reference is added for dropping the call, and removed when drop call
  392. // is called.
  393. //
  394. // (c) A reference is added for closing the call, and removed when close call
  395. // is called.
  396. //
  397. // (d) A reference is added when timers are set, and removed if timer expires,
  398. // is cancelled or terminated.
  399. //
  400. // (e) When a packet is received to be dispatched, adapter context is locked,
  401. // call context is found and referenced, adapter is unlocked and FSM function
  402. // is called.
  403. //
  404. // (f) For any other operation not listed here, programmer should do as in (e).
  405. //
  406. LONG lRef;
  407. //
  408. // Spin lock to synchronize access to shared members
  409. //
  410. NDIS_SPIN_LOCK lockCall;
  411. //
  412. // Indicates the calls PPPoE state
  413. //
  414. CALLSTATES stateCall;
  415. //
  416. // Indicates that the call is initiated from another machine, and this machine is acting as
  417. // a server.
  418. //
  419. BOOLEAN fIncoming;
  420. //
  421. // These are the various bit flags to indicate other state information for the call:
  422. //
  423. // (a) CLBF_CallIdle: This is the initial state of the call.
  424. //
  425. // (b) CLBF_CallOpen: This flag is indicates that the call context is opened.
  426. // When a call context is created it is always created with CLBF_CallOpen
  427. // and CLBF_CallConnectPending flags set, then if call connects succesfully,
  428. // CLBF_CallConnectPending flag is reset, and only CLBF_CallOpen is left.
  429. //
  430. // The following pending flags might be set additionally:
  431. // CLBF_CallConnectPending : If this flag is set the call is still connecting.
  432. // Otherwise it means that the call is connected, and
  433. // can make data over the link.
  434. //
  435. // (c) CLBF_CallConnectPending: This flag may be set only if CLBF_CallOpen is set. It means that
  436. // the call is still in connect pending state. You can look at pCall->stateCall
  437. // variable to retrieve the actual state of the call.
  438. //
  439. // (d) CLBF_CallDropped: This flag is set when call is dropped (disconnected).
  440. // The following pending flags might be set additionally:
  441. // CLBF_CallClosePending
  442. //
  443. // (e) CLBF_CallClosePending: This flag is set after the call is dropped and context is being cleared to
  444. // be freed.
  445. //
  446. // (f) CLBF_CallClosed: This flag is set when call is closed (resources ready to be freed).
  447. // No pending flags might be set when this bit is set.
  448. //
  449. //
  450. //
  451. // (g) CLBF_NotifyNDIS: This flag indicates that an asynchronous completion of a close call request
  452. // must be communicated to NDIS using NdisMSetInformationComplete().
  453. //
  454. // (h) CLBF_CallReceivePacketHandlerScheduled: This flag indicates that the MpIndicateReceivedPackets()
  455. // is scheduled to indicate packets in the receive queue.
  456. //
  457. ULONG ulClFlags;
  458. #define CLBF_CallIdle 0x00000000
  459. #define CLBF_CallOpen 0x00000001
  460. #define CLBF_CallConnectPending 0x00000002
  461. #define CLBF_CallDropped 0x00000004
  462. #define CLBF_CallClosePending 0x00000008
  463. #define CLBF_CallClosed 0x00000010
  464. #define CLBF_NotifyNDIS 0x00000020
  465. #define CLBF_CallReceivePacketHandlerScheduled 0x00000040
  466. //
  467. // Back pointer to the owning line context
  468. //
  469. LINE* pLine;
  470. //
  471. // This is the handle assigned by TAPI to the call.
  472. // We obtain it in TpMakeCall() or TpAnswerCall() from TAPI.
  473. //
  474. HTAPI_CALL htCall;
  475. //
  476. // This is the handle assigned by us to the call.
  477. // We obtain this when we create the call context and pass it back to TAPI
  478. // either in return from TpMakeCall() or TpReceiveCall().
  479. //
  480. // This handle forms of 2 USHORT values appended.
  481. // The higher 16 bits represent the index to the pAdapter->TapiProv.hCallTable, and
  482. // the lower 16 bits is just a unique number generated everytime a call handle is created.
  483. //
  484. // This ensures the uniqueness of handles to avoid pitfalls that could result due to some weird
  485. // timing conditions.
  486. //
  487. HDRV_CALL hdCall;
  488. //
  489. // This gives the link speed. It is obtained from the underlying binding context when
  490. // call is attached to the binding.
  491. //
  492. ULONG ulSpeed;
  493. //
  494. // This is the max frame size for the underlying binding context.
  495. // Passed to the call context in PrAddCallToBinding().
  496. //
  497. ULONG ulMaxFrameSize;
  498. //
  499. // This keeps TAPI's states. Its values are from LINECALLSTATE_ constants in SDK.
  500. //
  501. // States supported by us are:
  502. // - LINECALLSTATE_IDLE
  503. // - LINECALLSTATE_OFFERING
  504. // - LINECALLSTATE_DIALING
  505. // - LINECALLSTATE_PROCEEDING
  506. // - LINECALLSTATE_CONNECTED
  507. // - LINECALLSTATE_DISCONNECTED
  508. //
  509. ULONG ulTapiCallState;
  510. #define TAPI_LINECALLSTATES_SUPPORTED ( LINECALLSTATE_IDLE | \
  511. LINECALLSTATE_OFFERING | \
  512. LINECALLSTATE_DIALING | \
  513. LINECALLSTATE_PROCEEDING | \
  514. LINECALLSTATE_CONNECTED | \
  515. LINECALLSTATE_DISCONNECTED )
  516. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++
  517. Link info needed by NDISWAN
  518. typedef struct _NDIS_WAN_GET_LINK_INFO {
  519. IN NDIS_HANDLE NdisLinkHandle;
  520. OUT ULONG MaxSendFrameSize;
  521. OUT ULONG MaxRecvFrameSize;
  522. OUT ULONG HeaderPadding;
  523. OUT ULONG TailPadding;
  524. OUT ULONG SendFramingBits;
  525. OUT ULONG RecvFramingBits;
  526. OUT ULONG SendCompressionBits;
  527. OUT ULONG RecvCompressionBits;
  528. OUT ULONG SendACCM;
  529. OUT ULONG RecvACCM;
  530. } NDIS_WAN_GET_LINK_INFO, *PNDIS_WAN_GET_LINK_INFO;
  531. typedef struct _NDIS_WAN_SET_LINK_INFO {
  532. IN NDIS_HANDLE NdisLinkHandle;
  533. IN ULONG MaxSendFrameSize;
  534. IN ULONG MaxRecvFrameSize;
  535. ULONG HeaderPadding;
  536. ULONG TailPadding;
  537. IN ULONG SendFramingBits;
  538. IN ULONG RecvFramingBits;
  539. IN ULONG SendCompressionBits;
  540. IN ULONG RecvCompressionBits;
  541. IN ULONG SendACCM;
  542. IN ULONG RecvACCM;
  543. } NDIS_WAN_SET_LINK_INFO, *PNDIS_WAN_SET_LINK_INFO;
  544. -------------------------------------------------------*/
  545. NDIS_WAN_GET_LINK_INFO NdisWanLinkInfo;
  546. //
  547. // This is the string that holds the service-name for the call.
  548. // It must be an UTF-8 string per PPPoE RFC.
  549. //
  550. // We either obtain it in TpMakeCall() as the phone-number to dial, or
  551. // receive it from the peer for an incoming call.
  552. //
  553. CHAR ServiceName[MAX_SERVICE_NAME_LENGTH];
  554. //
  555. // Indicates the length of the service name string
  556. //
  557. USHORT nServiceNameLength;
  558. //
  559. // This is the string that holds the AC-name for this call.
  560. // It must be an UTF-8 string per PPPoE RFC.
  561. //
  562. // For an outgoing call, we obtain it from the adapter's context,
  563. // for an incoming call we get it from PADO packet server sends.
  564. //
  565. CHAR ACName[MAX_AC_NAME_LENGTH];
  566. //
  567. // Indicates the length of the AC name string
  568. //
  569. USHORT nACNameLength;
  570. //
  571. // Indicates if ACName was specified by the caller or not
  572. //
  573. BOOLEAN fACNameSpecified;
  574. //
  575. // Peer's MAC address, obtained either when we receive or send a PADO packet
  576. //
  577. CHAR DestAddr[6];
  578. //
  579. // Our MAC address, obtained from binding in PrAddCallToBinding()
  580. //
  581. CHAR SrcAddr[6];
  582. //
  583. // Indicates the session id for the call.
  584. //
  585. // As per PPPoE RFC, a call is identified uniquely by the peer's MAC addresses plus a session id.
  586. // In this implementation, we do not really care about the peer's MAC addresses, so we always
  587. // make a unique session id. This is partly why we do not support both client and server functionality
  588. // on the same box at the same time.
  589. //
  590. // For an incoming call, session id is selected as the index into pAdapter->TapiProv.hCallTable, and
  591. // for an outgoing call it is assigned by the peer so we just traverse active calls to identify the
  592. // correct call (which is very inefficient by the way, but this was a design decision that was discussed
  593. // and approved by the PMs - the main scenario is that most people will not have many outgoing calls -
  594. // anyway ).
  595. //
  596. USHORT usSessionId;
  597. //
  598. // Pointer to the binding context that the call is running over
  599. //
  600. BINDING* pBinding;
  601. //
  602. // Handle assigned to this peer-to-peer link by NDISWAN.
  603. //
  604. // This value is passed to us in NDIS_MAC_LINE_UP.
  605. // We indicate anything to NDISWAN using this handle.
  606. //
  607. NDIS_HANDLE NdisLinkContext;
  608. //
  609. // This points to the last PPPoE control packet sent to the peer.
  610. //
  611. // This is necesarry for resending the packet on a timeout condition
  612. // when we do not get a reply.
  613. //
  614. PPPOE_PACKET* pSendPacket;
  615. //
  616. // This is a special queue added to fix bug 172298 in Windows Bugs database.
  617. // The problem is that the payload packets received right after a PADS but before contexts are exchanged
  618. // with NDISWAN are dropped, and this causes a disturbing user experience.
  619. //
  620. // So I decided to change the packet receive mechanism. Instead I will queue up the packets and
  621. // use a timer to indicate them to NDISWAN. I prefered timers instead of scheduling a work item because
  622. // timers are more reliable than work items in terms of when to run.
  623. //
  624. LIST_ENTRY linkReceivedPackets;
  625. //
  626. // The maximum length of the queue
  627. //
  628. #define MAX_RECEIVED_PACKETS 100
  629. //
  630. // Number of packets in the received packet queue.
  631. // The value can not exceed MAX_RECEIVED_PACKETS
  632. //
  633. ULONG nReceivedPackets;
  634. //
  635. // This will be used to indicate the packets in the receive queue to NDISWAN
  636. //
  637. TIMERQITEM timerReceivedPackets;
  638. //
  639. // The maximum number of packets to be indicated from the queue in one function call.
  640. // If there are more items in the queue, we should schedule another timer.
  641. //
  642. #define MAX_INDICATE_RECEIVED_PACKETS 100
  643. #define RECEIVED_PACKETS_TIMEOUT 1
  644. //
  645. // This is the timer queue item we use for this call.
  646. //
  647. TIMERQITEM timerTimeout;
  648. //
  649. // Indicates the number of timeouts occured.
  650. // Max number of time outs is kept in pAdapter->nMaxTimeouts and is read from registry.
  651. //
  652. UINT nNumTimeouts;
  653. }
  654. CALL;
  655. ////////////////////////////////////
  656. //
  657. // Local macros
  658. //
  659. ////////////////////////////////////
  660. #define ALLOC_ADAPTER( ppA ) NdisAllocateMemoryWithTag( (PVOID*) ppA, sizeof( ADAPTER ), MTAG_ADAPTER )
  661. #define FREE_ADAPTER( pA ) NdisFreeMemory( (PVOID) pA, sizeof( ADAPTER ), 0 );
  662. #define VALIDATE_ADAPTER( pA ) ( (pA) && (pA->tagAdapter == MTAG_ADAPTER) )
  663. VOID
  664. CreateUniqueValue(
  665. IN HDRV_CALL hdCall,
  666. OUT CHAR* pUniqueValue,
  667. OUT USHORT* pSize
  668. );
  669. VOID
  670. ReferenceAdapter(
  671. IN ADAPTER* pAdapter,
  672. IN BOOLEAN fAcquireLock
  673. );
  674. VOID DereferenceAdapter(
  675. IN ADAPTER* pAdapter
  676. );
  677. VOID
  678. MpNotifyBindingRemoval(
  679. BINDING* pBinding
  680. );
  681. VOID
  682. MpRecvPacket(
  683. IN BINDING* pBinding,
  684. IN PPPOE_PACKET* pPacket
  685. );
  686. VOID
  687. MpIndicateReceivedPackets(
  688. IN TIMERQITEM* pTqi,
  689. IN VOID* pContext,
  690. IN TIMERQEVENT event
  691. );
  692. VOID
  693. MpScheduleIndicateReceivedPacketsHandler(
  694. CALL* pCall
  695. );
  696. NDIS_STATUS
  697. MpWanGetInfo(
  698. IN ADAPTER* pAdapter,
  699. IN PNDIS_WAN_INFO pWanInfo
  700. );
  701. NDIS_STATUS
  702. MpWanGetLinkInfo(
  703. IN ADAPTER* pAdapter,
  704. IN PNDIS_WAN_GET_LINK_INFO pWanLinkInfo
  705. );
  706. NDIS_STATUS
  707. MpWanSetLinkInfo(
  708. IN ADAPTER* pAdapter,
  709. IN PNDIS_WAN_SET_LINK_INFO pWanLinkInfo
  710. );
  711. //////////////////////////////////////////////////////////////
  712. //
  713. // Interface prototypes: Functions exposed from this module
  714. //
  715. //////////////////////////////////////////////////////////////
  716. NDIS_STATUS
  717. MpRegisterMiniport(
  718. IN PDRIVER_OBJECT pDriverObject,
  719. IN PUNICODE_STRING pRegistryPath,
  720. OUT NDIS_HANDLE* pNdisWrapperHandle
  721. );
  722. // These basics are not in the DDK headers for some reason.
  723. //
  724. #define min( a, b ) (((a) < (b)) ? (a) : (b))
  725. #define max( a, b ) (((a) > (b)) ? (a) : (b))
  726. #define InsertBefore( pNewL, pL ) \
  727. { \
  728. (pNewL)->Flink = (pL); \
  729. (pNewL)->Blink = (pL)->Blink; \
  730. (pNewL)->Flink->Blink = (pNewL); \
  731. (pNewL)->Blink->Flink = (pNewL); \
  732. }
  733. #define InsertAfter( pNewL, pL ) \
  734. { \
  735. (pNewL)->Flink = (pL)->Flink; \
  736. (pNewL)->Blink = (pL); \
  737. (pNewL)->Flink->Blink = (pNewL); \
  738. (pNewL)->Blink->Flink = (pNewL); \
  739. }
  740. // Pad to the size of the given datatype. (Borrowed from wdm.h which is not
  741. // otherwise needed)
  742. //
  743. #define ALIGN_DOWN(length, type) \
  744. ((ULONG)(length) & ~(sizeof(type) - 1))
  745. #define ALIGN_UP(length, type) \
  746. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  747. // Place in a TRACE argument list to correspond with a format of "%d" to print
  748. // a percentage of two integers, or an average of two integers, or those
  749. // values rounded.
  750. //
  751. #define PCTTRACE( n, d ) ((d) ? (((n) * 100) / (d)) : 0)
  752. #define AVGTRACE( t, c ) ((c) ? ((t) / (c)) : 0)
  753. #define PCTRNDTRACE( n, d ) ((d) ? (((((n) * 1000) / (d)) + 5) / 10) : 0)
  754. #define AVGRNDTRACE( t, c ) ((c) ? (((((t) * 10) / (c)) + 5) / 10) : 0)
  755. // All memory allocations and frees are done with these ALLOC_*/FREE_*
  756. // macros/inlines to allow memory management scheme changes without global
  757. // editing. For example, might choose to lump several lookaside lists of
  758. // nearly equal sized items into a single list for efficiency.
  759. //
  760. // NdisFreeMemory requires the length of the allocation as an argument. NT
  761. // currently doesn't use this for non-paged memory, but according to JameelH,
  762. // Windows95 does. These inlines stash the length at the beginning of the
  763. // allocation, providing the traditional malloc/free interface. The
  764. // stash-area is a ULONGLONG so that all allocated blocks remain ULONGLONG
  765. // aligned as they would be otherwise, preventing problems on Alphas.
  766. //
  767. __inline
  768. VOID*
  769. ALLOC_NONPAGED(
  770. IN ULONG ulBufLength,
  771. IN ULONG ulTag )
  772. {
  773. CHAR* pBuf;
  774. NdisAllocateMemoryWithTag(
  775. &pBuf, (UINT )(ulBufLength + MEMORY_ALLOCATION_ALIGNMENT), ulTag );
  776. if (!pBuf)
  777. {
  778. return NULL;
  779. }
  780. ((ULONG* )pBuf)[ 0 ] = ulBufLength;
  781. ((ULONG* )pBuf)[ 1 ] = 0xC0BBC0DE;
  782. return pBuf + MEMORY_ALLOCATION_ALIGNMENT;
  783. }
  784. __inline
  785. VOID
  786. FREE_NONPAGED(
  787. IN VOID* pBuf )
  788. {
  789. ULONG ulBufLen;
  790. ulBufLen = *((ULONG* )(((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT));
  791. NdisFreeMemory(
  792. ((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT,
  793. (UINT )(ulBufLen + MEMORY_ALLOCATION_ALIGNMENT),
  794. 0 );
  795. }
  796. #define ALLOC_NDIS_WORK_ITEM( pWorkItemLookasideList ) \
  797. NdisAllocateFromNPagedLookasideList( pWorkItemLookasideList )
  798. #define FREE_NDIS_WORK_ITEM( pA, pNwi ) \
  799. NdisFreeToNPagedLookasideList( pWorkItemLookasideList, (pNwi) )
  800. #endif