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.

479 lines
16 KiB

  1. /*
  2. (C) Copyright 1998
  3. All rights reserved.
  4. Portions of this software are:
  5. (C) Copyright 1995, 1999 TriplePoint, Inc. -- http://www.TriplePoint.com
  6. License to use this software is granted under the terms outlined in
  7. the TriplePoint Software Services Agreement.
  8. (C) Copyright 1992 Microsoft Corp. -- http://www.Microsoft.com
  9. License to use this software is granted under the terms outlined in
  10. the Microsoft Windows Device Driver Development Kit.
  11. @doc INTERNAL Card Card_h
  12. @module Card.h |
  13. This module defines the hardware specific structures and values used to
  14. control the network interface card.
  15. @head3 Contents |
  16. @index class,mfunc,func,msg,mdata,struct,enum | Card_h
  17. @end
  18. */
  19. #ifndef _CARD_H
  20. #define _CARD_H
  21. #define CARD_OBJECT_TYPE ((ULONG)'C')+\
  22. ((ULONG)'A'<<8)+\
  23. ((ULONG)'R'<<16)+\
  24. ((ULONG)'D'<<24)
  25. /*
  26. // TODO - These values will normally come from the NIC or the installer.
  27. */
  28. #define MAX_ADAPTERS 4
  29. #define CARD_NUM_PORTS 1
  30. //#define CARD_MIN_IOPORT_SIZE 256
  31. // TODO - How many I/O ports does the card have? (undefined if none)
  32. //#define CARD_MIN_MEMORY_SIZE 256
  33. // TODO - How much memory does the card have? (undefined if none)
  34. #define CARD_IS_BUS_MASTER FALSE
  35. // TODO - Is the card a bus master device? (TRUE or FALSE)
  36. #if (CARD_IS_BUS_MASTER)
  37. # define CARD_MAP_REGISTERS_NEEDED NUM_DEV_PER_ADAP
  38. // TODO - How many map registers needed to transmit data to card.
  39. #endif
  40. //#define CARD_REQUEST_ISR TRUE
  41. // TODO - How do you want to handle interrupts from the card?
  42. // TRUE if you want to always use MiniportISR().
  43. // FALSE if you want to use MiniportDisable() and MiniportEnable().
  44. // Undefined if your card does not generate interrupts.
  45. #if defined(CARD_REQUEST_ISR)
  46. #define CARD_INTERRUPT_SHARED TRUE
  47. // TODO - Is your interrupt shared? (TRUE or FALSE).
  48. #define CARD_INTERRUPT_MODE NdisInterruptLevelSensitive
  49. // TODO - Is your interrupt latched or level sensitve?
  50. #endif // defined(CARD_REQUEST_ISR)
  51. /*
  52. // Maximum packet size allowed by the adapter -- must be restricted to
  53. // 1500 bytes at this point, and must also allow for frames at least 32
  54. // bytes longer.
  55. */
  56. #define NDISWAN_EXTRA_SIZE 32
  57. #define CARD_MIN_PACKET_SIZE ( 480 + NDISWAN_EXTRA_SIZE)
  58. #define CARD_MAX_PACKET_SIZE (2016 + NDISWAN_EXTRA_SIZE)
  59. #define CARD_DEFAULT_PACKET_SIZE (1504 + NDISWAN_EXTRA_SIZE)
  60. /*
  61. // The WAN miniport must indicate the entire packet when it is received.
  62. */
  63. #define CARD_MAX_LOOKAHEAD (pAdapter->pCard->BufferSize)
  64. /*
  65. // Number of digits allowed in a phone number (not including spaces).
  66. */
  67. #define CARD_MAX_DIAL_DIGITS 32
  68. /*
  69. // These time out values depend on the card firmware and media contraints.
  70. // We should then see an answer within at most 30 seconds.
  71. // When a call arrives, it should be accepted within 10 seconds.
  72. */
  73. #define CARD_NO_ANSWER_TIMEOUT (30*1000) // 30 seconds
  74. #define CARD_NO_ACCEPT_TIMEOUT (10*1000) // 10 seconds
  75. #define CARD_NO_CLOSECALL_TIMEOUT (5*1000) // 5 seconds - NDISWAN_BUG
  76. #define NULL_BUFFER_POOL ((NDIS_HANDLE) 0xFFFFFFFF)
  77. /* @doc INTERNAL Card Card_h CARD_RESOURCES
  78. @struct CARD_RESOURCES |
  79. This structure contains the data associated with the hardware resources
  80. required to configure the NIC. These values are isolated from the rest
  81. of the <t CARD_OBJECT> because they depend on the underlying hardware.
  82. @comm
  83. The contents of this structure depends on compile time flags and should
  84. only include information about the resource actually used by the NIC.
  85. This structure is filled in by <f CardFindNIC> and is used to configure
  86. and allocate resources from NDIS when <f CardInitialize> is called.
  87. */
  88. typedef struct CARD_RESOURCES
  89. {
  90. NDIS_INTERFACE_TYPE BusInterfaceType; // @field
  91. // This value is used to tell NDIS what type of adapter this is.
  92. // This is usually the same as the registry parameter BusType, but
  93. // may be different in the case of a bridged adapter.
  94. BOOLEAN Master; // @field
  95. // This is TRUE if the adapter is capable of bus master transfers.
  96. // Use the <t CARD_IS_BUS_MASTER> defininition to set this value
  97. // so the other bus master values will be included if needed.
  98. // See <f NdisMAllocateMapRegisters> for more details on the bus
  99. // master parameters.
  100. #if (CARD_IS_BUS_MASTER)
  101. BOOLEAN Dma32BitAddresses; // @field
  102. // This is TRUE if the bus master device uses 32-bit addresses.
  103. // Almost always TRUE for today's devices.
  104. ULONG PhysicalMapRegistersNeeded; // @field
  105. // This should be set to the maximum number of outstanding DMA
  106. // transfers that can be active at one time. One for each physical
  107. // buffer segment.
  108. ULONG MaximumPhysicalMapping; // @field
  109. // This should be set to the maximum number of contigous bytes that
  110. // can make up a single DMA transfer.
  111. ULONG DmaChannel; // @field
  112. // This should only be set if your adapter is an ISA bus master and
  113. // requires the use of one of the host DMA channels.
  114. #endif // (CARD_IS_BUS_MASTER)
  115. #if defined(CARD_MIN_MEMORY_SIZE)
  116. ULONG MemoryLength; // @field
  117. // The number of bytes of memory the NIC has on board.
  118. // Use the <t CARD_MIN_MEMORY_SIZE> defininition to set the minimum value
  119. // so the other NIC based memory values will be included if needed.
  120. NDIS_PHYSICAL_ADDRESS MemoryPhysicalAddress; // @field
  121. // System physical address assigned to the NIC's on board memory.
  122. #endif // CARD_MIN_MEMORY_SIZE
  123. #if defined(CARD_MIN_IOPORT_SIZE)
  124. ULONG IoPortLength; // @field
  125. // The number of bytes of I/O ports the NIC has on board.
  126. // Use the <t CARD_MIN_IOPORT_SIZE> defininition to set the minimum value
  127. // so the other NIC based memory values will be included if needed.
  128. NDIS_PHYSICAL_ADDRESS IoPortPhysicalAddress; // @field
  129. // System physical address assigned to the NIC's on board I/O ports.
  130. #endif // CARD_MIN_IOPORT_SIZE
  131. #if defined(CARD_REQUEST_ISR)
  132. ULONG InterruptVector; // @field
  133. // System interrupt vector assigned to the NIC's interrupt request line.
  134. ULONG InterruptLevel; // @field
  135. // System interrupt level assigned to the NIC's interrupt request line.
  136. ULONG InterruptMode; // @field
  137. // Set this value to NdisInterruptLevelSensitive or NdisInterruptLatched.
  138. // Use the <t CARD_INTERRUPT_MODE> defininition to set this value.
  139. BOOLEAN InterruptShared; // @field
  140. // Set TRUE if you want to allow the NIC's <f InterruptVector> to be
  141. // shared with other drivers in the system.
  142. // Use the <t CARD_INTERRUPT_SHARED> defininition to set this value.
  143. #endif // defined(CARD_REQUEST_ISR)
  144. } CARD_RESOURCES;
  145. #if !defined(CARD_REQUEST_ISR)
  146. /* @doc INTERNAL Card Card_h CARD_EVENT_CODE
  147. @enum CARD_EVENT_CODE |
  148. This enumeration defines the events generated by the card.
  149. */
  150. typedef enum CARD_EVENT_CODE
  151. {
  152. CARD_EVENT_NULL, // @emem
  153. // Not used for anything.
  154. CARD_EVENT_RING, // @emem
  155. // Indicates that a call is incoming on the given BChannel.
  156. CARD_EVENT_CONNECT, // @emem
  157. // Indicates that a call is connected on the given BChannel.
  158. CARD_EVENT_DISCONNECT, // @emem
  159. // Indicates that a call is disconnected on the given BChannel.
  160. CARD_EVENT_RECEIVE, // @emem
  161. // Indicates that a packet is incoming on the given BChannel.
  162. CARD_EVENT_TRANSMIT_COMPLETE // @emem
  163. // Indicates that the transmit is complete on the given BChannel.
  164. } CARD_EVENT_CODE;
  165. /* @doc INTERNAL Card Card_h CARD_EVENT_OBJECT
  166. @struct CARD_EVENT_OBJECT |
  167. This structure is used to keep track of events passed between the
  168. callee and caller. Each <t CARD_OBJECT> keeps a list of these events.
  169. */
  170. typedef struct CARD_EVENT_OBJECT
  171. {
  172. LIST_ENTRY Queue; // @field
  173. // Used to place the buffer on one of the receive lists.
  174. CARD_EVENT_CODE ulEventCode; // @field
  175. // Reason for event notification.
  176. PVOID pSendingObject; // @field
  177. // Interface object that is notifying. See <t BCHANNEL_OBJECT> or
  178. // <t DCHANNEL_OBJECT>,
  179. PVOID pReceivingObject; // @field
  180. // Interface object that is notifying. See <t BCHANNEL_OBJECT> or
  181. // <t DCHANNEL_OBJECT>,
  182. PNDIS_WAN_PACKET pWanPacket; // @field
  183. // A pointer to the associated NDIS packet structure <t NDIS_WAN_PACKET>.
  184. } CARD_EVENT_OBJECT, *PCARD_EVENT_OBJECT;
  185. #endif // !defined(CARD_REQUEST_ISR)
  186. /* @doc INTERNAL Card Card_h CARD_OBJECT
  187. @struct CARD_OBJECT |
  188. This structure contains the data associated with the Network Interface
  189. Card (NIC). This object is responsible for managing all the hardware
  190. specific components of the NIC.
  191. @comm
  192. The <t MINIPORT_ADAPTER_OBJECT> manages the interface between NDIS and
  193. the driver, and then passes off the hardware specific interface to this
  194. object. There is one <t CARD_OBJECT> for each <t MINIPORT_ADAPTER_OBJECT>.
  195. One of these objects is created each time that our <f MiniportInitialize>
  196. routine is called. The NDIS wrapper calls this routine once for each of
  197. NIC installed and enabled in the system. In the case of a hot swappable
  198. NIC (e.g. PCMCIA) the adapter might come and go several times during a
  199. single Windows session.
  200. */
  201. typedef struct CARD_OBJECT
  202. {
  203. ULONG ObjectType; // @field
  204. // Four characters used to identify this type of object 'CARD'.
  205. ULONG ObjectID; // @field
  206. // Instance number used to identify a specific object instance.
  207. PMINIPORT_ADAPTER_OBJECT pAdapter; // @field
  208. // A pointer to the <t MINIPORT_ADAPTER_OBJECT> instance.
  209. CARD_RESOURCES ResourceInformation; // @field
  210. // Contains adapter specific resource requirements and settings.
  211. // See <t CARD_RESOURCES>.
  212. ULONG InterruptStatus; // @field
  213. // Bits indicating which interrupts need to be processed.
  214. NDIS_MINIPORT_INTERRUPT Interrupt; // @field
  215. // Miniport interrupt object used by NDIS.
  216. USHORT ReceiveBuffersPerLink; // @field
  217. // Maximum number of receive buffers per channel, registry parameter.
  218. USHORT TransmitBuffersPerLink; // @field
  219. // Maximum number of transmit buffers per channel, registry parameter.
  220. USHORT BufferSize; // @field
  221. // The maxmimum packet size. The NDISWAN spec says this must be 1500+32,
  222. // but everything seems to work okay if it is set smaller.
  223. ULONG NumChannels; // @field
  224. // Number of communication channels configured on the NIC.
  225. ULONG NumPorts; // @field
  226. // Number of <t PORT_OBJECT>'s allocated in <p pPortArray>.
  227. PPORT_OBJECT * pPortArray; // @field
  228. // An array of <t PORT_OBJECT>'s created by <f PortCreate>.
  229. // One entry for each port on NIC.
  230. #if defined(PCI_BUS)
  231. ULONG PciSlotNumber; // @field
  232. // PCI slot number for this adapter (FunctionNumber * 32) + DeviceNumber.
  233. #endif // PCI_BUS
  234. #if defined(CARD_MIN_MEMORY_SIZE)
  235. PCHAR pMemoryVirtualAddress; // @field
  236. // Virtual adress of NIC memory area.
  237. #endif // CARD_MIN_MEMORY_SIZE
  238. #if defined(CARD_MIN_IOPORT_SIZE)
  239. PCHAR pIoPortVirtualAddress; // @field
  240. // Virtual adress of NIC I/O port area.
  241. #endif // CARD_MIN_IOPORT_SIZE
  242. #if (CARD_IS_BUS_MASTER)
  243. ULONG MapRegisterIndex; // @field
  244. // Next map register index to be used for DMA transfer.
  245. long MapRegistersInUse; // @field
  246. // Number of map registers currently in use.
  247. #endif // (CARD_IS_BUS_MASTER)
  248. ULONG TODO; // @field
  249. // Add your data members here.
  250. ULONG NumDChannels; // @field
  251. // The sample driver uses this registry value to determine the number
  252. // of ports to simulate.
  253. #if defined(SAMPLE_DRIVER)
  254. LIST_ENTRY EventList; // @field
  255. // Events waiting to be processed. See <t CARD_EVENT_OBJECT>.
  256. # define MAX_EVENTS 32
  257. CARD_EVENT_OBJECT EventArray[MAX_EVENTS]; // @field
  258. // Card event allocation array.
  259. ULONG NextEvent; // @field
  260. // Index into EventArray.
  261. #endif // SAMPLE_DRIVER
  262. } CARD_OBJECT;
  263. #define GET_ADAPTER_FROM_CARD(pCard) (pCard->pAdapter)
  264. /*
  265. Object Interface Prototypes
  266. */
  267. NDIS_STATUS CardCreate(
  268. OUT PCARD_OBJECT * ppCard,
  269. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  270. );
  271. void CardDestroy(
  272. IN PCARD_OBJECT pCard
  273. );
  274. NDIS_STATUS CardInitialize(
  275. IN PCARD_OBJECT pCard
  276. );
  277. ULONG CardNumChannels(
  278. IN PCARD_OBJECT pCard
  279. );
  280. ULONG CardNumPorts(
  281. IN PCARD_OBJECT pCard
  282. );
  283. void CardInterruptHandler(
  284. IN PCARD_OBJECT pCard
  285. );
  286. NDIS_STATUS CardLineConnect(
  287. IN PCARD_OBJECT pCard,
  288. IN PBCHANNEL_OBJECT pBChannel
  289. );
  290. void CardLineDisconnect(
  291. IN PCARD_OBJECT pCard,
  292. IN PBCHANNEL_OBJECT pBChannel
  293. );
  294. BOOLEAN CardTransmitPacket(
  295. IN PCARD_OBJECT pCard,
  296. IN PBCHANNEL_OBJECT pBChannel,
  297. IN PNDIS_WAN_PACKET pWanPacket
  298. );
  299. PUCHAR CardGetReceiveInfo(
  300. IN PCARD_OBJECT pCard,
  301. OUT PBCHANNEL_OBJECT * ppBChannel,
  302. OUT PULONG pBytesReceived
  303. );
  304. void CardReceiveComplete(
  305. IN PCARD_OBJECT pCard,
  306. IN PBCHANNEL_OBJECT pBChannel
  307. );
  308. USHORT CardCleanPhoneNumber(
  309. OUT PUCHAR Dst,
  310. IN PUCHAR Src,
  311. IN USHORT Length
  312. );
  313. NDIS_STATUS CardReset(
  314. IN PCARD_OBJECT pCard
  315. );
  316. #if defined(SAMPLE_DRIVER)
  317. PBCHANNEL_OBJECT GET_BCHANNEL_FROM_PHONE_NUMBER(
  318. IN PUCHAR pDialString
  319. );
  320. VOID CardNotifyEvent(
  321. IN PCARD_OBJECT pCard,
  322. IN PCARD_EVENT_OBJECT pEvent
  323. );
  324. PCARD_EVENT_OBJECT CardEventAllocate(
  325. IN PCARD_OBJECT pCard
  326. );
  327. VOID CardEventRelease(
  328. IN PCARD_OBJECT pCard,
  329. IN PCARD_EVENT_OBJECT pEvent
  330. );
  331. #endif // SAMPLE_DRIVER
  332. #endif // _CARD_H