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.

459 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. BOOLEAN
  272. PrQueryAdapterForCurrentAddress(
  273. IN BINDING* pBinding
  274. );
  275. BOOLEAN
  276. PrQueryAdapterForLinkSpeed(
  277. IN BINDING* pBinding
  278. );
  279. BOOLEAN
  280. PrQueryAdapterForMaxFrameSize(
  281. IN BINDING* pBinding
  282. );
  283. BOOLEAN
  284. PrSetPacketFilterForAdapter(
  285. IN BINDING* pBinding,
  286. IN BOOLEAN fSet
  287. );
  288. VOID
  289. PrRequestComplete(
  290. IN NDIS_HANDLE ProtocolBindingContext,
  291. IN PNDIS_REQUEST pRequest,
  292. IN NDIS_STATUS status
  293. );
  294. VOID
  295. PrUnbindAdapter(
  296. OUT PNDIS_STATUS Status,
  297. IN NDIS_HANDLE ProtocolBindingContext,
  298. IN NDIS_HANDLE UnbindContext
  299. );
  300. VOID
  301. PrCloseAdapter(
  302. IN BINDING* pBinding
  303. );
  304. VOID
  305. PrCloseAdapterComplete(
  306. IN NDIS_HANDLE ProtocolBindingContext,
  307. IN NDIS_STATUS Status
  308. );
  309. BOOLEAN
  310. PrAddCallToBinding(
  311. IN BINDING* pBinding,
  312. IN PCALL pCall
  313. );
  314. VOID
  315. PrRemoveCallFromBinding(
  316. IN BINDING* pBinding,
  317. IN PCALL pCall
  318. );
  319. VOID
  320. PrSendComplete(
  321. IN NDIS_HANDLE ProtocolBindingContext,
  322. IN PNDIS_PACKET pNdisPacket,
  323. IN NDIS_STATUS Status
  324. );
  325. INT
  326. PrReceivePacket(
  327. IN NDIS_HANDLE ProtocolBindingContext,
  328. IN PNDIS_PACKET Packet
  329. );
  330. NDIS_STATUS
  331. PrBroadcast(
  332. IN PPPOE_PACKET* pPacket
  333. );
  334. VOID
  335. ExecBindingWorkItem(
  336. PVOID Args[4],
  337. UINT workType
  338. );
  339. NDIS_STATUS
  340. PrReceive(
  341. IN NDIS_HANDLE ProtocolBindingContext,
  342. IN NDIS_HANDLE MacReceiveContext,
  343. IN PVOID HeaderBuffer,
  344. IN UINT HeaderBufferSize,
  345. IN PVOID LookAheadBuffer,
  346. IN UINT LookaheadBufferSize,
  347. IN UINT PacketSize
  348. );
  349. VOID
  350. PrTransferDataComplete(
  351. IN NDIS_HANDLE ProtocolBindingContext,
  352. IN PNDIS_PACKET Packet,
  353. IN NDIS_STATUS Status,
  354. IN UINT BytesTransferred
  355. );
  356. VOID
  357. PrReceiveComplete(
  358. IN NDIS_HANDLE ProtocolBindingContext
  359. );
  360. ULONG
  361. PrQueryMaxFrameSize();
  362. NDIS_STATUS
  363. PrSend(
  364. IN BINDING* pBinding,
  365. IN PPPOE_PACKET* pPacket
  366. );
  367. VOID
  368. PrStatus(
  369. IN NDIS_HANDLE ProtocolBindingContext,
  370. IN NDIS_STATUS GeneralStatus,
  371. IN PVOID StatusBuffer,
  372. IN UINT StatusBufferSize
  373. );
  374. NDIS_STATUS
  375. PrPnPEvent(
  376. IN NDIS_HANDLE hProtocolBindingContext,
  377. IN PNET_PNP_EVENT pNetPnPEvent
  378. );
  379. VOID
  380. PrReEnumerateBindings(
  381. VOID
  382. );
  383. #endif