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.

374 lines
10 KiB

  1. /*****************************************************************************
  2. ** **
  3. ** COPYRIGHT (C) 2000, 2001 MKNET CORPORATION **
  4. ** DEVELOPED FOR THE MK7100-BASED VFIR PCI CONTROLLER. **
  5. ** **
  6. *****************************************************************************/
  7. /**********************************************************************
  8. Module Name:
  9. WINOIDS.C
  10. Routines:
  11. MKMiniportQueryInformation
  12. MKMiniportSetInformation
  13. Comments:
  14. Windows-NDIS Sets & Gets of OIDs.
  15. **********************************************************************/
  16. #include "precomp.h"
  17. #include "protot.h"
  18. #pragma hdrstop
  19. //----------------------------------------------------------------------
  20. // Function: MKMiniportQueryInformation
  21. //
  22. // Description:
  23. // Query the capabilities and status of the miniport driver.
  24. //
  25. //----------------------------------------------------------------------
  26. NDIS_STATUS MKMiniportQueryInformation (
  27. IN NDIS_HANDLE MiniportAdapterContext,
  28. IN NDIS_OID Oid,
  29. IN PVOID InformationBuffer,
  30. IN ULONG InformationBufferLength,
  31. OUT PULONG BytesWritten,
  32. OUT PULONG BytesNeeded)
  33. {
  34. NDIS_STATUS result = NDIS_STATUS_SUCCESS;
  35. PMK7_ADAPTER Adapter = PMK7_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
  36. INT i, speeds, speedSupported;
  37. UINT *infoPtr;
  38. CHAR *pnpid;
  39. MK7REG mk7reg;
  40. // CMCONFIG_A *hwInfo = (CMCONFIG_A *)InformationBuffer;
  41. static NDIS_OID MK7GlobalSupportedOids[] = {
  42. OID_GEN_SUPPORTED_LIST,
  43. OID_GEN_HARDWARE_STATUS,
  44. OID_GEN_MEDIA_SUPPORTED,
  45. OID_GEN_MEDIA_IN_USE,
  46. OID_GEN_MEDIA_CONNECT_STATUS, // 1.0.0
  47. OID_GEN_MAXIMUM_LOOKAHEAD,
  48. OID_GEN_MAXIMUM_FRAME_SIZE,
  49. OID_GEN_MAXIMUM_SEND_PACKETS,
  50. OID_GEN_MAXIMUM_TOTAL_SIZE,
  51. OID_GEN_MAC_OPTIONS,
  52. OID_GEN_PROTOCOL_OPTIONS,
  53. OID_GEN_LINK_SPEED,
  54. OID_GEN_TRANSMIT_BUFFER_SPACE,
  55. OID_GEN_RECEIVE_BUFFER_SPACE,
  56. OID_GEN_TRANSMIT_BLOCK_SIZE,
  57. OID_GEN_RECEIVE_BLOCK_SIZE,
  58. OID_GEN_VENDOR_DESCRIPTION,
  59. OID_GEN_VENDOR_DRIVER_VERSION,
  60. OID_GEN_DRIVER_VERSION,
  61. OID_GEN_CURRENT_PACKET_FILTER,
  62. OID_GEN_CURRENT_LOOKAHEAD,
  63. OID_IRDA_RECEIVING,
  64. OID_IRDA_SUPPORTED_SPEEDS,
  65. OID_IRDA_LINK_SPEED,
  66. OID_IRDA_MEDIA_BUSY,
  67. OID_IRDA_TURNAROUND_TIME,
  68. OID_IRDA_MAX_RECEIVE_WINDOW_SIZE,
  69. OID_IRDA_EXTRA_RCV_BOFS };
  70. static ULONG BaudRateTable[NUM_BAUDRATES] = {
  71. // Add 16Mbps support; 2400 not supported
  72. 0, 9600, 19200,38400, 57600, 115200, 576000, 1152000, 4000000, 16000000};
  73. NDIS_MEDIUM Medium = NdisMediumIrda;
  74. ULONG GenericUlong;
  75. PVOID SourceBuffer = (PVOID) (&GenericUlong);
  76. ULONG SourceLength = sizeof(ULONG);
  77. switch (Oid){
  78. case OID_GEN_SUPPORTED_LIST:
  79. SourceBuffer = (PVOID) (MK7GlobalSupportedOids);
  80. SourceLength = sizeof(MK7GlobalSupportedOids);
  81. break;
  82. case OID_GEN_HARDWARE_STATUS:
  83. GenericUlong = Adapter->hardwareStatus;
  84. break;
  85. case OID_GEN_MEDIA_SUPPORTED:
  86. case OID_GEN_MEDIA_IN_USE:
  87. SourceBuffer = (PVOID) (&Medium);
  88. SourceLength = sizeof(NDIS_MEDIUM);
  89. break;
  90. case OID_GEN_MEDIA_CONNECT_STATUS:
  91. GenericUlong = (ULONG) NdisMediaStateConnected;
  92. break;
  93. case OID_IRDA_RECEIVING:
  94. GenericUlong = (ULONG)Adapter->nowReceiving;
  95. break;
  96. case OID_IRDA_SUPPORTED_SPEEDS:
  97. speeds = Adapter->supportedSpeedsMask &
  98. Adapter->AllowedSpeedMask &
  99. ALL_IRDA_SPEEDS;
  100. for (i = 0, infoPtr = (PUINT)BaudRateTable, SourceLength=0;
  101. (i < NUM_BAUDRATES) && speeds;
  102. i++){
  103. if (supportedBaudRateTable[i].ndisCode & speeds){
  104. *infoPtr++ = supportedBaudRateTable[i].bitsPerSec;
  105. SourceLength += sizeof(UINT);
  106. speeds &= ~supportedBaudRateTable[i].ndisCode;
  107. }
  108. }
  109. SourceBuffer = (PVOID) BaudRateTable;
  110. break;
  111. case OID_GEN_LINK_SPEED:
  112. GenericUlong = Adapter->MaxConnSpeed; // 100bps increments
  113. break;
  114. case OID_IRDA_LINK_SPEED:
  115. if (Adapter->linkSpeedInfo){
  116. GenericUlong = (ULONG)Adapter->linkSpeedInfo->bitsPerSec;
  117. }
  118. else {
  119. GenericUlong = DEFAULT_BAUD_RATE;
  120. }
  121. break;
  122. case OID_IRDA_MEDIA_BUSY: // 4.1.0
  123. if (Adapter->HwVersion == HW_VER_1){
  124. if (Adapter->nowReceiving==TRUE){
  125. NdisAcquireSpinLock(&Adapter->Lock);
  126. Adapter->mediaBusy=TRUE;
  127. NdisReleaseSpinLock(&Adapter->Lock);
  128. }
  129. else {
  130. NdisAcquireSpinLock(&Adapter->Lock);
  131. Adapter->mediaBusy=FALSE;
  132. NdisReleaseSpinLock(&Adapter->Lock);
  133. }
  134. }
  135. else{
  136. MK7Reg_Read(Adapter, R_CFG3, &mk7reg);
  137. if(((mk7reg & 0x1000) != 0)|| (Adapter->nowReceiving==TRUE)) {
  138. NdisAcquireSpinLock(&Adapter->Lock);
  139. Adapter->mediaBusy = TRUE;
  140. NdisReleaseSpinLock(&Adapter->Lock);
  141. }
  142. else {
  143. NdisAcquireSpinLock(&Adapter->Lock);
  144. Adapter->mediaBusy=FALSE;
  145. NdisReleaseSpinLock(&Adapter->Lock);
  146. }
  147. }
  148. GenericUlong = (UINT)Adapter->mediaBusy;
  149. break;
  150. case OID_GEN_CURRENT_LOOKAHEAD:
  151. case OID_GEN_MAXIMUM_LOOKAHEAD:
  152. GenericUlong = MAX_I_DATA_SIZE;
  153. break;
  154. case OID_GEN_MAXIMUM_TOTAL_SIZE: // Largest pkt protocol sends to miniport
  155. case OID_GEN_TRANSMIT_BLOCK_SIZE:
  156. case OID_GEN_RECEIVE_BLOCK_SIZE:
  157. case OID_GEN_MAXIMUM_FRAME_SIZE:
  158. // Normally there's some difference in these values, based on the
  159. // MAC header, but IrDA doesn't have one.
  160. GenericUlong = MAX_I_DATA_SIZE;
  161. break;
  162. case OID_GEN_RECEIVE_BUFFER_SPACE:
  163. case OID_GEN_TRANSMIT_BUFFER_SPACE:
  164. GenericUlong = (ULONG) (MK7_MAXIMUM_PACKET_SIZE * MAX_TX_PACKETS);
  165. break;
  166. case OID_GEN_MAC_OPTIONS:
  167. GenericUlong = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |
  168. NDIS_MAC_OPTION_TRANSFERS_NOT_PEND;
  169. break;
  170. case OID_GEN_MAXIMUM_SEND_PACKETS:
  171. GenericUlong = MAX_ARRAY_SEND_PACKETS;
  172. break;
  173. case OID_IRDA_TURNAROUND_TIME:
  174. // Indicate the amount of time that the transceiver needs
  175. // to recuperate after a send.
  176. GenericUlong =
  177. (ULONG)Adapter->turnAroundTime_usec;
  178. break;
  179. case OID_IRDA_EXTRA_RCV_BOFS:
  180. // Pass back the number of _extra_ BOFs to be prepended
  181. // to packets sent to this unit at 115.2 baud, the
  182. // maximum Slow IR speed. This will be scaled for other
  183. // speed according to the table in the
  184. // Infrared Extensions to NDIS' spec.
  185. GenericUlong = (ULONG)Adapter->extraBOFsRequired;
  186. break;
  187. case OID_GEN_CURRENT_PACKET_FILTER:
  188. GenericUlong = NDIS_PACKET_TYPE_PROMISCUOUS;
  189. break;
  190. case OID_IRDA_MAX_RECEIVE_WINDOW_SIZE:
  191. GenericUlong = MAX_RX_PACKETS;
  192. //GenericUlong = 1;
  193. break;
  194. case OID_GEN_VENDOR_DESCRIPTION:
  195. SourceBuffer = (PVOID)"MKNet Very Highspeed IR";
  196. SourceLength = 24;
  197. break;
  198. case OID_GEN_VENDOR_DRIVER_VERSION:
  199. // This value is used to know whether to update driver.
  200. GenericUlong = (MK7_MAJOR_VERSION << 16) +
  201. (MK7_MINOR_VERSION << 8) +
  202. MK7_LETTER_VERSION;
  203. break;
  204. case OID_GEN_DRIVER_VERSION:
  205. GenericUlong = (MK7_NDIS_MAJOR_VERSION << 8) + MK7_NDIS_MINOR_VERSION;
  206. SourceLength = 2;
  207. break;
  208. case OID_IRDA_MAX_SEND_WINDOW_SIZE: // 4.0.1
  209. GenericUlong = MAX_ARRAY_SEND_PACKETS;
  210. break;
  211. default:
  212. result = NDIS_STATUS_NOT_SUPPORTED;
  213. break;
  214. }
  215. if (result == NDIS_STATUS_SUCCESS) {
  216. if (SourceLength > InformationBufferLength) {
  217. *BytesNeeded = SourceLength;
  218. result = NDIS_STATUS_INVALID_LENGTH;
  219. }
  220. else {
  221. *BytesNeeded = 0;
  222. *BytesWritten = SourceLength;
  223. NdisMoveMemory(InformationBuffer, SourceBuffer, SourceLength);
  224. }
  225. }
  226. return result;
  227. }
  228. //----------------------------------------------------------------------
  229. // Function: MKMiniportSetInformation
  230. //
  231. // Description:
  232. // Allow other layers of the network software (e.g., a transport
  233. // driver) to control the miniport driver by changing information that
  234. // the miniport driver maintains in its OIDs, such as the packet
  235. // or multicast addresses.
  236. //----------------------------------------------------------------------
  237. NDIS_STATUS MKMiniportSetInformation (
  238. IN NDIS_HANDLE MiniportAdapterContext,
  239. IN NDIS_OID Oid,
  240. IN PVOID InformationBuffer,
  241. IN ULONG InformationBufferLength,
  242. OUT PULONG BytesRead,
  243. OUT PULONG BytesNeeded)
  244. {
  245. NDIS_STATUS result = NDIS_STATUS_SUCCESS;
  246. PMK7_ADAPTER Adapter = PMK7_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
  247. UINT i,speedSupported;
  248. NDIS_DMA_DESCRIPTION DMAChannelDcr;
  249. CHAR *pnpid;
  250. UCHAR IOResult;
  251. // CMCONFIG_A *hwInfo = (CMCONFIG_A *)InformationBuffer;
  252. if (InformationBufferLength >= sizeof(UINT)){
  253. UINT info = *(UINT *)InformationBuffer;
  254. *BytesRead = sizeof(UINT);
  255. *BytesNeeded = 0;
  256. switch (Oid) {
  257. case OID_IRDA_LINK_SPEED:
  258. result = NDIS_STATUS_INVALID_DATA;
  259. // Find the appropriate speed and set it
  260. speedSupported = NUM_BAUDRATES;
  261. for (i = 0; i < speedSupported; i++) {
  262. if (supportedBaudRateTable[i].bitsPerSec == info) {
  263. Adapter->linkSpeedInfo = &supportedBaudRateTable[i];
  264. result = NDIS_STATUS_SUCCESS;
  265. break;
  266. }
  267. }
  268. if (result == NDIS_STATUS_SUCCESS) {
  269. if (!SetSpeed(Adapter)){
  270. result = NDIS_STATUS_FAILURE;
  271. }
  272. }
  273. else {
  274. *BytesRead = 0;
  275. *BytesNeeded = 0;
  276. }
  277. break;
  278. case OID_IRDA_MEDIA_BUSY:
  279. // The protocol can use this OID to reset the busy field
  280. // in order to check it later for intervening activity.
  281. //
  282. Adapter->mediaBusy = (BOOLEAN)info;
  283. result = NDIS_STATUS_SUCCESS;
  284. break;
  285. case OID_GEN_CURRENT_PACKET_FILTER:
  286. result = NDIS_STATUS_SUCCESS;
  287. break;
  288. case OID_GEN_CURRENT_LOOKAHEAD:
  289. result = (info<=MAX_I_DATA_SIZE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_INVALID_LENGTH;
  290. break;
  291. // We don't support these
  292. //
  293. case OID_IRDA_RATE_SNIFF:
  294. case OID_IRDA_UNICAST_LIST:
  295. // These are query-only parameters.
  296. //
  297. case OID_IRDA_SUPPORTED_SPEEDS:
  298. case OID_IRDA_MAX_UNICAST_LIST_SIZE:
  299. case OID_IRDA_TURNAROUND_TIME:
  300. default:
  301. *BytesRead = 0;
  302. *BytesNeeded = 0;
  303. result = NDIS_STATUS_NOT_SUPPORTED;
  304. break;
  305. }
  306. }
  307. else {
  308. *BytesRead = 0;
  309. *BytesNeeded = sizeof(UINT);
  310. result = NDIS_STATUS_INVALID_LENGTH;
  311. }
  312. return result;
  313. }