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.

150 lines
3.3 KiB

  1. #include "lvprot.h"
  2. #include "usbreader.h"// TO REMOVE LATER....
  3. #pragma PAGEDCODE
  4. VOID CLVProtocol::set_WTR_Delay(LONG Delay)
  5. {
  6. if(device) device->set_WTR_Delay(Delay);
  7. }
  8. #pragma PAGEDCODE
  9. ULONG CLVProtocol::get_WTR_Delay()
  10. {
  11. if(device) return device->get_WTR_Delay();
  12. else return 0;
  13. }
  14. #pragma PAGEDCODE
  15. VOID CLVProtocol::set_Default_WTR_Delay()
  16. {
  17. if(device) device->set_Default_WTR_Delay();
  18. }
  19. #pragma PAGEDCODE
  20. LONG CLVProtocol::get_Power_WTR_Delay()
  21. {
  22. if(device) return device->get_Power_WTR_Delay();
  23. else return 0;
  24. }
  25. #pragma PAGEDCODE
  26. ULONG CLVProtocol::getCardState()
  27. {
  28. if(device) return device->getCardState();
  29. else return 0;
  30. }
  31. #pragma PAGEDCODE
  32. NTSTATUS CLVProtocol::writeAndWait(BYTE* pRequest,ULONG RequestLength,BYTE* pReply,ULONG* pReplyLength)
  33. {
  34. ULONG BufferLength;
  35. NTSTATUS status;
  36. if(device)
  37. {
  38. if(!pRequest || !RequestLength || !pReply
  39. || !pReplyLength || !*pReplyLength || RequestLength>=PROTOCOL_OUTPUT_BUFFER_SIZE)
  40. {
  41. TRACE("writeAndWait(): INVALID PARAMETERS PROVIDED FOR PROTOCOL!...\n");
  42. ASSERT(FALSE);
  43. return STATUS_INVALID_PARAMETER;
  44. }
  45. __try
  46. {
  47. pOutputBuffer[0] = (UCHAR)RequestLength;
  48. memory->copy(pOutputBuffer+1,pRequest, RequestLength+1);
  49. TRACE("LV protocol: writeAndWait()");
  50. TRACE_BUFFER(pOutputBuffer,RequestLength+1);
  51. BufferLength = InputBufferLength;
  52. status = device->writeAndWait(pOutputBuffer,RequestLength+1,pInputBuffer,&BufferLength);
  53. if(!NT_SUCCESS(status))
  54. {
  55. *pReplyLength = 0;
  56. __leave;
  57. }
  58. if(BufferLength>*pReplyLength)
  59. {
  60. *pReplyLength = 0;
  61. status = STATUS_INSUFFICIENT_RESOURCES;
  62. __leave;
  63. }
  64. //Skip length byte
  65. if(BufferLength>1) BufferLength--;
  66. *pReplyLength = BufferLength;
  67. if(BufferLength)
  68. {
  69. memory->copy(pReply,pInputBuffer+1,BufferLength);
  70. }
  71. TRACE("LV protocol: writeAndWait() response");
  72. TRACE_BUFFER(pReply,BufferLength);
  73. __leave;
  74. }
  75. __finally
  76. {
  77. }
  78. return status;
  79. }
  80. return STATUS_INVALID_DEVICE_STATE;
  81. };
  82. #pragma PAGEDCODE
  83. NTSTATUS CLVProtocol::readAndWait(BYTE* pRequest,ULONG RequestLength,BYTE* pReply,ULONG* pReplyLength)
  84. {
  85. ULONG BufferLength;
  86. NTSTATUS status;
  87. if(device)
  88. {
  89. if(!pRequest || !RequestLength || !pReply
  90. || !pReplyLength || !*pReplyLength || RequestLength>=PROTOCOL_OUTPUT_BUFFER_SIZE)
  91. {
  92. TRACE("readAndWait(): INVALID PARAMETERS PROVIDED FOR PROTOCOL!...\n");
  93. ASSERT(FALSE);
  94. return STATUS_INVALID_PARAMETER;
  95. }
  96. __try
  97. {
  98. pOutputBuffer[0] = (UCHAR)RequestLength;
  99. memory->copy(pOutputBuffer+1,pRequest, RequestLength+1);
  100. TRACE("LV protocol: readAndWait()");
  101. TRACE_BUFFER(pOutputBuffer,RequestLength+1);
  102. BufferLength = InputBufferLength;
  103. status = device->readAndWait(pOutputBuffer,RequestLength+1,pInputBuffer,&BufferLength);
  104. if(!NT_SUCCESS(status))
  105. {
  106. TRACE("LV protocol: readAndWait() reports error %8.8lX\n",status);
  107. *pReplyLength = 0;
  108. __leave;
  109. }
  110. if(BufferLength>*pReplyLength)
  111. {
  112. *pReplyLength = 0;
  113. status = STATUS_INSUFFICIENT_RESOURCES;
  114. __leave;
  115. }
  116. //Skip length byte
  117. if(BufferLength>1) BufferLength--;
  118. *pReplyLength = BufferLength;
  119. if(BufferLength)
  120. {
  121. memory->copy(pReply,pInputBuffer+1,BufferLength);
  122. }
  123. TRACE("LV protocol: readAndWait() response");
  124. TRACE_BUFFER(pInputBuffer,BufferLength);
  125. __leave;
  126. }
  127. __finally
  128. {
  129. }
  130. return status;
  131. }
  132. return STATUS_INVALID_DEVICE_STATE;
  133. };