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.

464 lines
11 KiB

  1. #ifndef _PROTOCOL_H_
  2. #define _PROTOCOL_H_
  3. #define PR_NDIS_MajorVersion 4
  4. #define PR_NDIS_MinorVersion 0
  5. #define PR_CHARACTERISTIC_NAME "RasPppoe"
  6. typedef struct _CALL* PCALL;
  7. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8. Functional Description:
  9. These macros will be called by PacketCreateForReceived() and DereferencePacket()
  10. functions when a PPPOE_PACKET with references to a packet owned by NDIS is
  11. created and freed, respectively.
  12. ---------------------------------------------------------------------------*/
  13. #define PrPacketOwnedByNdisReceived( pB ) \
  14. NdisInterlockedIncrement( &(pB)->NumPacketsOwnedByNdis )
  15. #define PrPacketOwnedByNdisReturned( pB ) \
  16. NdisInterlockedDecrement( &(pB)->NumPacketsOwnedByNdis )
  17. //
  18. // Constants
  19. //
  20. #define BN_SetFiltersForMediaDetection 0x00000001
  21. #define BN_SetFiltersForMakeCall 0x00000002
  22. #define BN_ResetFiltersForCloseLine 0x00000003
  23. //
  24. // These are the states that a binding can be in.
  25. // They are pretty self explanatory.
  26. //
  27. typedef enum
  28. _BINDING_STATE
  29. {
  30. BN_stateIdle = 0,
  31. BN_stateBindPending,
  32. BN_stateBound,
  33. BN_stateSleepPending,
  34. BN_stateSleeping,
  35. BN_stateUnbindPending,
  36. BN_stateUnbound
  37. }
  38. BINDING_STATE;
  39. //
  40. // These are the schedulable work items for the bindings:
  41. //
  42. // - BWT_workPrSend: This work item is scheduled by PrBroadcast() with a copy of a
  43. // packet given to broadcast. When it runs, it sends the clone packet.
  44. //
  45. // - BWT_PrReceiveComplete: This work item is scheduled by PrReceivePacket() if a packet is received
  46. // and there is no PrReceiveComplete() running to drain the receive queue.
  47. //
  48. typedef enum
  49. _BINDING_WORKTYPE
  50. {
  51. BWT_workUnknown = 0,
  52. BWT_workPrStartBinds,
  53. BWT_workPrSend,
  54. BWT_workPrReceiveComplete
  55. }
  56. BINDING_WORKTYPE;
  57. //
  58. // This is the binding context.
  59. // All information pertinent to our bindings are kept here.
  60. //
  61. typedef struct
  62. _BINDING
  63. {
  64. //
  65. // Link to other bindings in the protocols binding list
  66. //
  67. LIST_ENTRY linkBindings;
  68. //
  69. // Tag that identifies the binding (used for debugging)
  70. //
  71. ULONG tagBinding;
  72. //
  73. // Keeps reference count on the binding.
  74. // References are added and deleted for the following operations:
  75. //
  76. // (a) A reference is added in AddBindingToProtocol and removed in RemoveBindingFromProtocol
  77. //
  78. // (b) A reference is added when a call is added, and removed when call is removed.
  79. //
  80. // (c) A reference is added when a BWT_workPrSend item is scheduled and removed when
  81. // work item is executed.
  82. //
  83. // (d) A reference must be added before sending a packet, and must be removed if NdisSend()
  84. // completes synchronously. Otherwise it will be removed by PrSendComplete() function
  85. // when Ndis calls it to notify the completion of the send.
  86. //
  87. LONG lRef;
  88. //
  89. // (a) BNBF_OpenAdapterCompleted: This flag will be set by PrOpenAdapterComplete().
  90. //
  91. // (b) BNBF_CurrentAddressQueryCompleted: This flag will be set by PrRequestComplete().
  92. //
  93. // (c) BNBF_LinkSpeedQueryCompleted: This flag will be set by PrRequestComplete().
  94. //
  95. // (d) BNBF_MaxFrameSizeQueryCompleted: This flag will be set by PrRequestComplete().
  96. //
  97. // (e) BNBF_BindAdapterCompleted: This flag will be set by PrBindAdapter().
  98. //
  99. // (f) BNBF_CloseAdapterCompleted: This flag will be set by PrCloseAdapterComplete().
  100. //
  101. // (g) BNBF_PacketFilterSet: This flag indicates that the packet filter for the binding is set.
  102. // It will be set and reset in ChangePacketFiltersForBindings().
  103. //
  104. // (h) BNBF_PacketFilterChangeInProgress: This flag indicates that the binding is referenced for
  105. // packet filter change.
  106. //
  107. ULONG ulBindingFlags;
  108. #define BNBF_OpenAdapterCompleted 0x00000001
  109. #define BNBF_CurrentAddressQueryCompleted 0x00000002
  110. #define BNBF_LinkSpeedQueryCompleted 0x00000004
  111. #define BNBF_MaxFrameSizeQueryCompleted 0x00000008
  112. #define BNBF_BindAdapterCompleted 0x00000010
  113. #define BNBF_CloseAdapterCompleted 0x00000020
  114. #define BNBF_PacketFilterSet 0x00000040
  115. #define BNBF_PacketFilterChangeInProgress 0x00000080
  116. //
  117. // Shows the status of the bind adapter operation.
  118. // Valid only if BNBF_BindAdapterCompleted is set.
  119. //
  120. NDIS_STATUS BindAdapterStatus;
  121. //
  122. // Shows the status of the open adapter operation.
  123. // Valid only if BNBF_OpenAdapterCompleted is set.
  124. //
  125. NDIS_STATUS OpenAdapterStatus;
  126. //
  127. // Shows the status of the latest request made to NDIS.
  128. //
  129. NDIS_STATUS RequestStatus;
  130. //
  131. // Ndis Request structure passed to the underlying NIC cards
  132. //
  133. NDIS_REQUEST Request;
  134. //
  135. // Event to be signaled when requests are completed.
  136. //
  137. NDIS_EVENT RequestCompleted;
  138. //
  139. // Keeps the MAC address of the NIC card represented by this binding.
  140. // This information is obtained from the underlying by passing it a set of OID queries
  141. //
  142. CHAR LocalAddress[6];
  143. //
  144. // Keeps the speed of the NIC cards represented by this binding.
  145. // This information is obtained from the underlying by passing it a set of OID queries
  146. //
  147. ULONG ulSpeed;
  148. //
  149. // Max frame size of the underlying NIC
  150. //
  151. ULONG ulMaxFrameSize;
  152. //
  153. // Keeps the filter information for this binding.
  154. //
  155. ULONG ulPacketFilter;
  156. //
  157. // This is the handle returned to us by NdisOpenAdapter().
  158. // It is the handle for accessing the underlying NIC card represented by this binding.
  159. //
  160. NDIS_HANDLE NdisBindingHandle;
  161. //
  162. // This is the index of the supported medium by the underlying NIC card.
  163. //
  164. UINT uintSelectedMediumIndex;
  165. //
  166. // This is the event that we wait on in PrUnbindAdapter().
  167. // It will be signaled from DereferenceBinding() when ref count of the binding reaches 0.
  168. //
  169. NDIS_EVENT eventFreeBinding;
  170. //
  171. // Spin lock to synchronize access to shared members
  172. //
  173. NDIS_SPIN_LOCK lockBinding;
  174. //
  175. // Indicates state information about the binding
  176. //
  177. BINDING_STATE stateBinding;
  178. //
  179. // Flag that indicates that the receive loop is running.
  180. // To make sure the serialization of PPP packets, we can not let more than 1 threads
  181. // making receive indications to NDISWAN
  182. //
  183. BOOLEAN fRecvLoopRunning;
  184. //
  185. // List of received packets waiting to be processed by ProtocolReceiveComplete()
  186. //
  187. LIST_ENTRY linkPackets;
  188. //
  189. // This is the number of packets that are received that are owned by NDIS and must
  190. // be returned back to NDIS.
  191. //
  192. LONG NumPacketsOwnedByNdis;
  193. }
  194. BINDING, *PBINDING;
  195. /////////////////////////////////////////////////////////////////////////////
  196. //
  197. //
  198. // Local macros
  199. //
  200. /////////////////////////////////////////////////////////////////////////////
  201. #define ALLOC_BINDING( ppB ) NdisAllocateMemoryWithTag( ppB, sizeof( BINDING ), MTAG_BINDING )
  202. #define FREE_BINDING( pB ) NdisFreeMemory( pB, sizeof( BINDING ), 0 )
  203. #define VALIDATE_BINDING( pB ) ( ( pB ) && ( pB->tagBinding == MTAG_BINDING ) )
  204. NDIS_STATUS
  205. InitializeProtocol(
  206. IN NDIS_HANDLE NdisProtocolHandle,
  207. IN PUNICODE_STRING RegistryPath
  208. );
  209. VOID
  210. PrLoad(
  211. VOID
  212. );
  213. BINDING*
  214. AllocBinding();
  215. VOID
  216. ReferenceBinding(
  217. IN BINDING* pBinding,
  218. IN BOOLEAN fAcquireLock
  219. );
  220. VOID
  221. DereferenceBinding(
  222. IN BINDING* pBinding
  223. );
  224. VOID
  225. BindingCleanup(
  226. IN BINDING* pBinding
  227. );
  228. VOID
  229. DetermineMaxFrameSize();
  230. VOID
  231. ChangePacketFiltersForAdapters(
  232. BOOLEAN fSet
  233. );
  234. VOID
  235. AddBindingToProtocol(
  236. IN BINDING* pBinding
  237. );
  238. VOID
  239. RemoveBindingFromProtocol(
  240. IN BINDING* pBinding
  241. );
  242. VOID
  243. PrUnload(
  244. VOID
  245. );
  246. NDIS_STATUS
  247. PrRegisterProtocol(
  248. IN PDRIVER_OBJECT DriverObject,
  249. IN PUNICODE_STRING RegistryPath,
  250. OUT NDIS_HANDLE* pNdisProtocolHandle
  251. );
  252. VOID
  253. PrBindAdapter(
  254. OUT PNDIS_STATUS Status,
  255. IN NDIS_HANDLE BindContext,
  256. IN PNDIS_STRING DeviceName,
  257. IN PVOID SystemSpecific1,
  258. IN PVOID SystemSpecific2
  259. );
  260. BOOLEAN
  261. PrOpenAdapter(
  262. IN BINDING* pBinding,
  263. IN PNDIS_STRING DeviceName
  264. );
  265. VOID
  266. PrOpenAdapterComplete(
  267. IN NDIS_HANDLE ProtocolBindingContext,
  268. IN NDIS_STATUS Status,
  269. IN NDIS_STATUS OpenErrorStatus
  270. );
  271. VOID
  272. PrStatusComplete(
  273. IN NDIS_HANDLE ProtocolBindingContext
  274. );
  275. BOOLEAN
  276. PrQueryAdapterForCurrentAddress(
  277. IN BINDING* pBinding
  278. );
  279. BOOLEAN
  280. PrQueryAdapterForLinkSpeed(
  281. IN BINDING* pBinding
  282. );
  283. BOOLEAN
  284. PrQueryAdapterForMaxFrameSize(
  285. IN BINDING* pBinding
  286. );
  287. BOOLEAN
  288. PrSetPacketFilterForAdapter(
  289. IN BINDING* pBinding,
  290. IN BOOLEAN fSet
  291. );
  292. VOID
  293. PrRequestComplete(
  294. IN NDIS_HANDLE ProtocolBindingContext,
  295. IN PNDIS_REQUEST pRequest,
  296. IN NDIS_STATUS status
  297. );
  298. VOID
  299. PrUnbindAdapter(
  300. OUT PNDIS_STATUS Status,
  301. IN NDIS_HANDLE ProtocolBindingContext,
  302. IN NDIS_HANDLE UnbindContext
  303. );
  304. VOID
  305. PrCloseAdapter(
  306. IN BINDING* pBinding
  307. );
  308. VOID
  309. PrCloseAdapterComplete(
  310. IN NDIS_HANDLE ProtocolBindingContext,
  311. IN NDIS_STATUS Status
  312. );
  313. BOOLEAN
  314. PrAddCallToBinding(
  315. IN BINDING* pBinding,
  316. IN PCALL pCall
  317. );
  318. VOID
  319. PrRemoveCallFromBinding(
  320. IN BINDING* pBinding,
  321. IN PCALL pCall
  322. );
  323. VOID
  324. PrSendComplete(
  325. IN NDIS_HANDLE ProtocolBindingContext,
  326. IN PNDIS_PACKET pNdisPacket,
  327. IN NDIS_STATUS Status
  328. );
  329. INT
  330. PrReceivePacket(
  331. IN NDIS_HANDLE ProtocolBindingContext,
  332. IN PNDIS_PACKET Packet
  333. );
  334. NDIS_STATUS
  335. PrBroadcast(
  336. IN PPPOE_PACKET* pPacket
  337. );
  338. VOID
  339. ExecBindingWorkItem(
  340. PVOID Args[4],
  341. UINT workType
  342. );
  343. NDIS_STATUS
  344. PrReceive(
  345. IN NDIS_HANDLE ProtocolBindingContext,
  346. IN NDIS_HANDLE MacReceiveContext,
  347. IN PVOID HeaderBuffer,
  348. IN UINT HeaderBufferSize,
  349. IN PVOID LookAheadBuffer,
  350. IN UINT LookaheadBufferSize,
  351. IN UINT PacketSize
  352. );
  353. VOID
  354. PrTransferDataComplete(
  355. IN NDIS_HANDLE ProtocolBindingContext,
  356. IN PNDIS_PACKET Packet,
  357. IN NDIS_STATUS Status,
  358. IN UINT BytesTransferred
  359. );
  360. VOID
  361. PrReceiveComplete(
  362. IN NDIS_HANDLE ProtocolBindingContext
  363. );
  364. ULONG
  365. PrQueryMaxFrameSize();
  366. NDIS_STATUS
  367. PrSend(
  368. IN BINDING* pBinding,
  369. IN PPPOE_PACKET* pPacket
  370. );
  371. VOID
  372. PrStatus(
  373. IN NDIS_HANDLE ProtocolBindingContext,
  374. IN NDIS_STATUS GeneralStatus,
  375. IN PVOID StatusBuffer,
  376. IN UINT StatusBufferSize
  377. );
  378. NDIS_STATUS
  379. PrPnPEvent(
  380. IN NDIS_HANDLE hProtocolBindingContext,
  381. IN PNET_PNP_EVENT pNetPnPEvent
  382. );
  383. VOID
  384. PrReEnumerateBindings(
  385. VOID
  386. );
  387. #endif