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.

303 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. status.c
  5. Abstract:
  6. Status Code mapping functions
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. Revision History:
  11. 6-20-99 : created
  12. --*/
  13. #include "common.h"
  14. // paged functions
  15. #ifdef ALLOC_PRAGMA
  16. #endif
  17. // non paged functions
  18. // USBPORT_SetUSBDError
  19. // USBPORT_MiniportStatus_TO_USBDStatus
  20. // USBPORT_MiniportStatus_TO_NtStatus
  21. NTSTATUS
  22. USBPORT_SetUSBDError(
  23. PURB Urb,
  24. USBD_STATUS UsbdStatus
  25. )
  26. /*++
  27. Routine Description:
  28. Set the USBD error code in the urb and return an NTSTATUS
  29. equivalent
  30. Arguments:
  31. URB urb to set error in (optional)
  32. Return Value:
  33. --*/
  34. {
  35. if (Urb) {
  36. Urb->UrbHeader.Status = UsbdStatus;
  37. }
  38. switch (UsbdStatus) {
  39. case USBD_STATUS_SUCCESS:
  40. return STATUS_SUCCESS;
  41. case USBD_STATUS_INSUFFICIENT_RESOURCES:
  42. return STATUS_INSUFFICIENT_RESOURCES;
  43. case USBD_STATUS_INVALID_URB_FUNCTION:
  44. case USBD_STATUS_INVALID_PARAMETER:
  45. case USBD_STATUS_INVALID_PIPE_HANDLE:
  46. case USBD_STATUS_BAD_START_FRAME:
  47. return STATUS_INVALID_PARAMETER;
  48. case USBD_STATUS_NOT_SUPPORTED:
  49. return STATUS_NOT_SUPPORTED;
  50. case USBD_STATUS_DEVICE_GONE:
  51. return STATUS_DEVICE_NOT_CONNECTED;
  52. case USBD_STATUS_CANCELED:
  53. return STATUS_CANCELLED;
  54. }
  55. return STATUS_UNSUCCESSFUL;
  56. }
  57. USBD_STATUS
  58. USBPORT_MiniportStatus_TO_USBDStatus(
  59. USB_MINIPORT_STATUS mpStatus
  60. )
  61. /*++
  62. Routine Description:
  63. return the USBD status code equivalent for a
  64. miniport status code
  65. Arguments:
  66. Return Value:
  67. --*/
  68. {
  69. USBD_STATUS usbdStatus = USBD_STATUS_STATUS_NOT_MAPPED;
  70. switch (mpStatus) {
  71. case USBMP_STATUS_SUCCESS:
  72. usbdStatus = USBD_STATUS_SUCCESS;
  73. break;
  74. case USBMP_STATUS_BUSY:
  75. //usbdStatus =
  76. //should not be mapping this one
  77. USBPORT_ASSERT(FALSE);
  78. break;
  79. case USBMP_STATUS_NO_RESOURCES:
  80. usbdStatus = USBD_STATUS_INSUFFICIENT_RESOURCES;
  81. break;
  82. case USBMP_STATUS_NO_BANDWIDTH:
  83. usbdStatus = USBD_STATUS_NO_BANDWIDTH;
  84. break;
  85. case USBMP_STATUS_NOT_SUPPORTED:
  86. usbdStatus = USBD_STATUS_NOT_SUPPORTED;
  87. break;
  88. default:
  89. usbdStatus = USBD_STATUS_INTERNAL_HC_ERROR;
  90. DEBUG_BREAK();
  91. break;
  92. }
  93. return usbdStatus;
  94. }
  95. NTSTATUS
  96. USBPORT_MiniportStatus_TO_NtStatus(
  97. USB_MINIPORT_STATUS mpStatus
  98. )
  99. /*++
  100. Routine Description:
  101. return the NT status code equivalent for a
  102. miniport status code
  103. Arguments:
  104. Return Value:
  105. --*/
  106. {
  107. USBD_STATUS usbdStatus;
  108. NTSTATUS ntStatus;
  109. usbdStatus =
  110. USBPORT_MiniportStatus_TO_USBDStatus(mpStatus);
  111. ntStatus = USBPORT_SetUSBDError(NULL, usbdStatus);
  112. return ntStatus;
  113. }
  114. USB_MINIPORT_STATUS
  115. USBPORT_NtStatus_TO_MiniportStatus(
  116. NTSTATUS NtStatus
  117. )
  118. /*++
  119. Routine Description:
  120. return the miniport status code equivalent for a
  121. NTSTATUS status code
  122. Arguments:
  123. Return Value:
  124. --*/
  125. {
  126. USB_MINIPORT_STATUS mpStatus;
  127. switch (NtStatus) {
  128. case STATUS_SUCCESS:
  129. mpStatus = USBMP_STATUS_SUCCESS;
  130. break;
  131. default:
  132. mpStatus = USBMP_STATUS_NTERRCODE_NOT_MAPPFED;
  133. }
  134. return mpStatus;
  135. }
  136. RHSTATUS
  137. USBPORT_MiniportStatus_TO_RHStatus(
  138. USB_MINIPORT_STATUS mpStatus
  139. )
  140. /*++
  141. Routine Description:
  142. return the RH status code equivalent for a
  143. miniport status code
  144. Arguments:
  145. Return Value:
  146. --*/
  147. {
  148. RHSTATUS rhStatus;
  149. if (mpStatus == USBMP_STATUS_SUCCESS) {
  150. rhStatus = RH_SUCCESS;
  151. } else if (mpStatus == USBMP_STATUS_BUSY) {
  152. rhStatus = RH_NAK;
  153. } else {
  154. rhStatus = RH_STALL;
  155. }
  156. return rhStatus;
  157. }
  158. USBD_STATUS
  159. USBPORT_RHStatus_TO_USBDStatus(
  160. USB_MINIPORT_STATUS rhStatus
  161. )
  162. /*++
  163. Routine Description:
  164. return the RH status code equivalent for a
  165. miniport status code
  166. Arguments:
  167. Return Value:
  168. --*/
  169. {
  170. USBD_STATUS usbdStatus;
  171. switch (rhStatus) {
  172. case RH_STALL:
  173. usbdStatus = USBD_STATUS_STALL_PID;
  174. break;
  175. case RH_SUCCESS:
  176. usbdStatus = USBD_STATUS_SUCCESS;
  177. break;
  178. case RH_NAK:
  179. default:
  180. // why are we mapping a NAK -- this is a bug.
  181. usbdStatus = USBD_STATUS_STALL_PID;
  182. DEBUG_BREAK();
  183. }
  184. return usbdStatus;
  185. }
  186. USB_USER_ERROR_CODE
  187. USBPORT_NtStatus_TO_UsbUserStatus(
  188. NTSTATUS NtStatus
  189. )
  190. /*++
  191. Routine Description:
  192. map NT status codes to our UI error codes
  193. Arguments:
  194. Return Value:
  195. --*/
  196. {
  197. USB_USER_ERROR_CODE usbUserStatus;
  198. switch (NtStatus) {
  199. case STATUS_SUCCESS:
  200. usbUserStatus = UsbUserSuccess;
  201. break;
  202. case STATUS_INVALID_PARAMETER:
  203. usbUserStatus = UsbUserInvalidParameter;
  204. break;
  205. default:
  206. usbUserStatus = UsbUserErrorNotMapped;
  207. }
  208. return usbUserStatus;
  209. }