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.

302 lines
11 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. rndissim.c
  5. Author:
  6. ervinp
  7. Environment:
  8. Kernel mode
  9. Revision History:
  10. --*/
  11. #include <ndis.h>
  12. #include <ntddndis.h> // defines OID's
  13. #include "..\inc\rndis.h"
  14. #include "..\inc\rndisapi.h"
  15. #include "usb8023.h"
  16. #include "debug.h"
  17. #if DO_FULL_RESET
  18. NTSTATUS SimulateRNDISHalt(ADAPTEREXT *adapter)
  19. {
  20. USBPACKET *packet;
  21. NTSTATUS status;
  22. packet = DequeueFreePacket(adapter);
  23. if (packet){
  24. PRNDIS_MESSAGE haltMsg;
  25. ULONG haltMsgSize;
  26. haltMsgSize = FIELD_OFFSET(RNDIS_MESSAGE, Message) +
  27. sizeof(RNDIS_HALT_REQUEST);
  28. haltMsg = (PRNDIS_MESSAGE)packet->dataBuffer;
  29. haltMsg->NdisMessageType = REMOTE_NDIS_HALT_MSG;
  30. haltMsg->MessageLength = haltMsgSize;
  31. haltMsg->Message.HaltRequest.RequestId = 1;
  32. packet->dataBufferCurrentLength = haltMsgSize;
  33. status = SubmitPacketToControlPipe(packet, TRUE, TRUE);
  34. EnqueueFreePacket(packet);
  35. }
  36. else {
  37. status = STATUS_INSUFFICIENT_RESOURCES;
  38. }
  39. ASSERT(NT_SUCCESS(status));
  40. return status;
  41. }
  42. NTSTATUS SimulateRNDISInit(ADAPTEREXT *adapter)
  43. {
  44. USBPACKET *packet;
  45. NTSTATUS status;
  46. packet = DequeueFreePacket(adapter);
  47. if (packet){
  48. PRNDIS_MESSAGE initMsg;
  49. ULONG initMsgSize;
  50. initMsgSize = FIELD_OFFSET(RNDIS_MESSAGE, Message) +
  51. sizeof(RNDIS_INITIALIZE_REQUEST);
  52. initMsg = (PRNDIS_MESSAGE)packet->dataBuffer;
  53. initMsg->NdisMessageType = REMOTE_NDIS_INITIALIZE_MSG;
  54. initMsg->MessageLength = initMsgSize;
  55. initMsg->Message.InitializeRequest.RequestId = 1;
  56. initMsg->Message.InitializeRequest.MajorVersion = adapter->rndismpMajorVersion;
  57. initMsg->Message.InitializeRequest.MinorVersion = adapter->rndismpMinorVersion;
  58. initMsg->Message.InitializeRequest.MaxTransferSize = adapter->rndismpMaxTransferSize;
  59. packet->dataBufferCurrentLength = initMsgSize;
  60. status = SubmitPacketToControlPipe(packet, TRUE, TRUE);
  61. if (NT_SUCCESS(status)){
  62. /*
  63. * The adapter will now return a notification to indicate
  64. * that it has the init-complete response.
  65. * Read the notify pipe synchronously so as not to
  66. * restart the notify read loop.
  67. */
  68. status = SubmitNotificationRead(adapter, TRUE);
  69. if (NT_SUCCESS(status)){
  70. /*
  71. * Now read the init-complete message
  72. * from the control pipe and throw it away.
  73. * Do a synchronous read so the result doesn't
  74. * propagate up to RNDISMP.
  75. */
  76. status = ReadPacketFromControlPipe(packet, TRUE);
  77. if (NT_SUCCESS(status)){
  78. PRNDIS_MESSAGE initCmpltMessage;
  79. initCmpltMessage = (PRNDIS_MESSAGE)packet->dataBuffer;
  80. status = initCmpltMessage->Message.InitializeComplete.Status;
  81. if (NT_SUCCESS(status)){
  82. }
  83. else {
  84. DBGERR(("SimulateRNDISInit: init-complete failed with %xh.", status));
  85. }
  86. }
  87. else {
  88. DBGERR(("SimulateRNDISInit: read for init-complete failed with %xh.", status));
  89. }
  90. }
  91. else {
  92. DBGERR(("SimulateRNDISInit: notification read failed with %xh.", status));
  93. }
  94. }
  95. else {
  96. DBGWARN(("SimulateRNDISInit: simulated init failed with %xh.", status));
  97. }
  98. EnqueueFreePacket(packet);
  99. }
  100. else {
  101. status = STATUS_INSUFFICIENT_RESOURCES;
  102. }
  103. return status;
  104. }
  105. NTSTATUS SimulateRNDISSetPacketFilter(ADAPTEREXT *adapter)
  106. {
  107. USBPACKET *packet;
  108. NTSTATUS status;
  109. packet = DequeueFreePacket(adapter);
  110. if (packet){
  111. PRNDIS_MESSAGE setMsg;
  112. ULONG setMsgSize;
  113. setMsgSize = FIELD_OFFSET(RNDIS_MESSAGE, Message) +
  114. sizeof(RNDIS_SET_REQUEST) +
  115. sizeof(ULONG);
  116. setMsg = (PRNDIS_MESSAGE)packet->dataBuffer;
  117. setMsg->NdisMessageType = REMOTE_NDIS_SET_MSG;
  118. setMsg->MessageLength = setMsgSize;
  119. setMsg->Message.SetRequest.RequestId = 1;
  120. setMsg->Message.SetRequest.Oid = OID_GEN_CURRENT_PACKET_FILTER;
  121. setMsg->Message.SetRequest.InformationBufferLength = sizeof(ULONG);
  122. setMsg->Message.SetRequest.InformationBufferOffset = sizeof(RNDIS_SET_REQUEST);
  123. *(PULONG)((PUCHAR)&setMsg->Message.SetRequest+sizeof(RNDIS_SET_REQUEST)) = adapter->currentPacketFilter;
  124. packet->dataBufferCurrentLength = setMsgSize;
  125. status = SubmitPacketToControlPipe(packet, TRUE, TRUE);
  126. if (NT_SUCCESS(status)){
  127. /*
  128. * The adapter will now return a notification to indicate
  129. * that it has the init-complete response.
  130. * Read the notify pipe synchronously so as not to
  131. * restart the notify read loop.
  132. */
  133. status = SubmitNotificationRead(adapter, TRUE);
  134. if (NT_SUCCESS(status)){
  135. /*
  136. * Now read the init-complete message
  137. * from the control pipe and throw it away.
  138. * Do a synchronous read so the result doesn't
  139. * propagate up to RNDISMP.
  140. */
  141. status = ReadPacketFromControlPipe(packet, TRUE);
  142. if (NT_SUCCESS(status)){
  143. PRNDIS_MESSAGE setCmpltMessage;
  144. setCmpltMessage = (PRNDIS_MESSAGE)packet->dataBuffer;
  145. status = setCmpltMessage->Message.SetComplete.Status;
  146. if (NT_SUCCESS(status)){
  147. }
  148. else {
  149. DBGERR(("SimulateRNDISSetPacketFilter: init-complete failed with %xh.", status));
  150. }
  151. }
  152. else {
  153. DBGERR(("SimulateRNDISSetPacketFilter: read for init-complete failed with %xh.", status));
  154. }
  155. }
  156. else {
  157. DBGERR(("SimulateRNDISSetPacketFilter: notification read failed with %xh.", status));
  158. }
  159. }
  160. else {
  161. DBGERR(("SimulateRNDISSetPacketFilter: oid returned %xh.", status));
  162. }
  163. EnqueueFreePacket(packet);
  164. }
  165. else {
  166. status = STATUS_INSUFFICIENT_RESOURCES;
  167. }
  168. ASSERT(NT_SUCCESS(status));
  169. return status;
  170. }
  171. NTSTATUS SimulateRNDISSetCurrentAddress(ADAPTEREXT *adapter)
  172. {
  173. NTSTATUS status;
  174. if (RtlEqualMemory(adapter->MAC_Address, "\0\0\0\0\0\0", ETHERNET_ADDRESS_LENGTH)){
  175. /*
  176. * A 'software' MAC address was never assigned.
  177. * So no need to resend it.
  178. */
  179. status = STATUS_SUCCESS;
  180. }
  181. else {
  182. USBPACKET *packet = DequeueFreePacket(adapter);
  183. if (packet){
  184. PRNDIS_MESSAGE setMsg;
  185. ULONG setMsgSize;
  186. setMsgSize = FIELD_OFFSET(RNDIS_MESSAGE, Message) +
  187. sizeof(RNDIS_SET_REQUEST) +
  188. ETHERNET_ADDRESS_LENGTH;
  189. setMsg = (PRNDIS_MESSAGE)packet->dataBuffer;
  190. setMsg->NdisMessageType = REMOTE_NDIS_SET_MSG;
  191. setMsg->MessageLength = setMsgSize;
  192. setMsg->Message.SetRequest.RequestId = 1;
  193. setMsg->Message.SetRequest.Oid = OID_802_3_CURRENT_ADDRESS;
  194. setMsg->Message.SetRequest.InformationBufferLength = ETHERNET_ADDRESS_LENGTH;
  195. setMsg->Message.SetRequest.InformationBufferOffset = sizeof(RNDIS_SET_REQUEST);
  196. RtlMoveMemory( (PUCHAR)&setMsg->Message.SetRequest+sizeof(RNDIS_SET_REQUEST),
  197. adapter->MAC_Address,
  198. ETHERNET_ADDRESS_LENGTH);
  199. packet->dataBufferCurrentLength = setMsgSize;
  200. status = SubmitPacketToControlPipe(packet, TRUE, TRUE);
  201. if (NT_SUCCESS(status)){
  202. /*
  203. * The adapter will now return a notification to indicate
  204. * that it has the init-complete response.
  205. * Read the notify pipe synchronously so as not to
  206. * restart the notify read loop.
  207. */
  208. status = SubmitNotificationRead(adapter, TRUE);
  209. if (NT_SUCCESS(status)){
  210. /*
  211. * Now read the init-complete message
  212. * from the control pipe and throw it away.
  213. * Do a synchronous read so the result doesn't
  214. * propagate up to RNDISMP.
  215. */
  216. status = ReadPacketFromControlPipe(packet, TRUE);
  217. if (NT_SUCCESS(status)){
  218. PRNDIS_MESSAGE setCmpltMessage;
  219. setCmpltMessage = (PRNDIS_MESSAGE)packet->dataBuffer;
  220. status = setCmpltMessage->Message.SetComplete.Status;
  221. if (NT_SUCCESS(status)){
  222. }
  223. else {
  224. DBGERR(("SimulateRNDISSetPacketFilter: init-complete failed with %xh.", status));
  225. }
  226. }
  227. else {
  228. DBGERR(("SimulateRNDISSetCurrentAddress: read for init-complete failed with %xh.", status));
  229. }
  230. }
  231. else {
  232. DBGERR(("SimulateRNDISSetCurrentAddress: notification read failed with %xh.", status));
  233. }
  234. }
  235. else {
  236. DBGERR(("SimulateRNDISSetCurrentAddress: oid returned %xh.", status));
  237. }
  238. EnqueueFreePacket(packet);
  239. }
  240. else {
  241. status = STATUS_INSUFFICIENT_RESOURCES;
  242. }
  243. }
  244. ASSERT(NT_SUCCESS(status));
  245. return status;
  246. }
  247. #endif