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.

191 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. usb.c
  5. Abstract: ESC/POS (serial) interface for USB Point-of-Sale devices
  6. Author:
  7. ervinp
  8. Environment:
  9. Kernel mode
  10. Revision History:
  11. --*/
  12. #include <WDM.H>
  13. #include <usbdi.h>
  14. #include <usbdlib.h>
  15. #include <usbioctl.h>
  16. #include "escpos.h"
  17. #include "debug.h"
  18. #if DBG
  19. BOOLEAN dbgTrapOnWarn = FALSE;
  20. BOOLEAN dbgVerbose = FALSE;
  21. VOID DbgLogIrpMajor(ULONG irpPtr, ULONG majorFunc, ULONG isPdo, ULONG isComplete, ULONG status)
  22. {
  23. if (dbgVerbose){
  24. char *funcName;
  25. switch (majorFunc){
  26. #undef MAKE_CASE
  27. #define MAKE_CASE(fnc) case fnc: funcName = #fnc; break;
  28. MAKE_CASE(IRP_MJ_CREATE)
  29. MAKE_CASE(IRP_MJ_CREATE_NAMED_PIPE)
  30. MAKE_CASE(IRP_MJ_CLOSE)
  31. MAKE_CASE(IRP_MJ_READ)
  32. MAKE_CASE(IRP_MJ_WRITE)
  33. MAKE_CASE(IRP_MJ_QUERY_INFORMATION)
  34. MAKE_CASE(IRP_MJ_SET_INFORMATION)
  35. MAKE_CASE(IRP_MJ_QUERY_EA)
  36. MAKE_CASE(IRP_MJ_SET_EA)
  37. MAKE_CASE(IRP_MJ_FLUSH_BUFFERS)
  38. MAKE_CASE(IRP_MJ_QUERY_VOLUME_INFORMATION)
  39. MAKE_CASE(IRP_MJ_SET_VOLUME_INFORMATION)
  40. MAKE_CASE(IRP_MJ_DIRECTORY_CONTROL)
  41. MAKE_CASE(IRP_MJ_FILE_SYSTEM_CONTROL)
  42. MAKE_CASE(IRP_MJ_DEVICE_CONTROL)
  43. MAKE_CASE(IRP_MJ_INTERNAL_DEVICE_CONTROL)
  44. MAKE_CASE(IRP_MJ_SHUTDOWN)
  45. MAKE_CASE(IRP_MJ_LOCK_CONTROL)
  46. MAKE_CASE(IRP_MJ_CLEANUP)
  47. MAKE_CASE(IRP_MJ_CREATE_MAILSLOT)
  48. MAKE_CASE(IRP_MJ_QUERY_SECURITY)
  49. MAKE_CASE(IRP_MJ_SET_SECURITY)
  50. MAKE_CASE(IRP_MJ_POWER)
  51. MAKE_CASE(IRP_MJ_SYSTEM_CONTROL)
  52. MAKE_CASE(IRP_MJ_DEVICE_CHANGE)
  53. MAKE_CASE(IRP_MJ_QUERY_QUOTA)
  54. MAKE_CASE(IRP_MJ_SET_QUOTA)
  55. MAKE_CASE(IRP_MJ_PNP)
  56. default: funcName = "????"; break;
  57. }
  58. if (isComplete){
  59. DBGOUT(("< %s for %s status=%xh %s (irp=%xh)",
  60. funcName,
  61. (PUCHAR)(isPdo ? "pdo" : "fdo"),
  62. status,
  63. NT_SUCCESS(status) ? "" : "<** ERROR **>",
  64. irpPtr));
  65. }
  66. else {
  67. DBGOUT(("> %s for %s (irp=%xh)",
  68. funcName,
  69. (PUCHAR)(isPdo ? "pdo" : "fdo"),
  70. irpPtr));
  71. }
  72. }
  73. }
  74. VOID DbgLogPnpIrp(ULONG irpPtr, ULONG minorFunc, ULONG isPdo, ULONG isComplete, ULONG status)
  75. {
  76. if (dbgVerbose){
  77. char *funcName;
  78. ULONG funcShortName;
  79. switch (minorFunc){
  80. #undef MAKE_CASE
  81. #define MAKE_CASE(fnc) case fnc: funcName = #fnc; funcShortName = *(ULONG *)(funcName+7); break;
  82. MAKE_CASE(IRP_MN_START_DEVICE)
  83. MAKE_CASE(IRP_MN_QUERY_REMOVE_DEVICE)
  84. MAKE_CASE(IRP_MN_REMOVE_DEVICE)
  85. MAKE_CASE(IRP_MN_CANCEL_REMOVE_DEVICE)
  86. MAKE_CASE(IRP_MN_STOP_DEVICE)
  87. MAKE_CASE(IRP_MN_QUERY_STOP_DEVICE)
  88. MAKE_CASE(IRP_MN_CANCEL_STOP_DEVICE)
  89. MAKE_CASE(IRP_MN_QUERY_DEVICE_RELATIONS)
  90. MAKE_CASE(IRP_MN_QUERY_INTERFACE)
  91. MAKE_CASE(IRP_MN_QUERY_CAPABILITIES)
  92. MAKE_CASE(IRP_MN_QUERY_RESOURCES)
  93. MAKE_CASE(IRP_MN_QUERY_RESOURCE_REQUIREMENTS)
  94. MAKE_CASE(IRP_MN_QUERY_DEVICE_TEXT)
  95. MAKE_CASE(IRP_MN_READ_CONFIG)
  96. MAKE_CASE(IRP_MN_WRITE_CONFIG)
  97. MAKE_CASE(IRP_MN_EJECT)
  98. MAKE_CASE(IRP_MN_SET_LOCK)
  99. MAKE_CASE(IRP_MN_QUERY_ID)
  100. MAKE_CASE(IRP_MN_QUERY_PNP_DEVICE_STATE)
  101. MAKE_CASE(IRP_MN_QUERY_BUS_INFORMATION)
  102. MAKE_CASE(IRP_MN_DEVICE_USAGE_NOTIFICATION)
  103. MAKE_CASE(IRP_MN_SURPRISE_REMOVAL)
  104. default: funcName = "????"; funcShortName = (ULONG)'\?\?\?\?'; break;
  105. }
  106. if (isComplete){
  107. DBGOUT((" < %s for %s status=%xh (irp=%xh)",
  108. funcName,
  109. (PUCHAR)(isPdo ? "pdo" : "fdo"),
  110. status,
  111. irpPtr));
  112. }
  113. else {
  114. DBGOUT((" > %s for %s (irp=%xh)",
  115. funcName,
  116. (PUCHAR)(isPdo ? "pdo" : "fdo"),
  117. irpPtr));
  118. }
  119. }
  120. }
  121. VOID DbgShowBytes(PUCHAR msg, PUCHAR buf, ULONG len)
  122. {
  123. if (dbgVerbose){
  124. ULONG i, j;
  125. DbgPrint("%c%s (len %xh @ %p): \r\n", DBG_LEADCHAR, msg, len, buf);
  126. for (i = 0; i < len; i += 16){
  127. DbgPrint("%c ", DBG_LEADCHAR);
  128. for (j = 0; j < 16; j++){
  129. if (i+j < len){
  130. DbgPrint("%02x ", (ULONG)buf[i+j]);
  131. }
  132. else {
  133. DbgPrint(" ");
  134. }
  135. }
  136. DbgPrint(" ");
  137. for (j = 0; j < 16; j++){
  138. if (i+j < len){
  139. UCHAR ch = buf[i+j];
  140. if ((ch < ' ') || (ch > '~')){
  141. ch = '.';
  142. }
  143. DbgPrint("%c", ch);
  144. }
  145. else {
  146. DbgPrint(" ");
  147. }
  148. }
  149. DbgPrint("\r\n");
  150. }
  151. }
  152. }
  153. #endif