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.

225 lines
5.9 KiB

  1. /*++
  2. Copyright (C) 1999- Microsoft Corporation
  3. Module Name:
  4. camusb.h
  5. Abstract:
  6. Header file that declares CUsbCamera object
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. #ifndef CAMUSB__H_
  12. #define CAMUSB__H_
  13. //
  14. // These are the USB timeout values in seconds
  15. //
  16. const PTP_READ_TIMEOUT = 5;
  17. const PTP_WRITE_TIMEOUT = 5;
  18. const PTP_EVENT_TIMEOUT = 0;
  19. //
  20. // USB Still image device container types
  21. //
  22. const WORD PTPCONTAINER_TYPE_UNDEFINED = 0;
  23. const WORD PTPCONTAINER_TYPE_COMMAND = 1;
  24. const WORD PTPCONTAINER_TYPE_DATA = 2;
  25. const WORD PTPCONTAINER_TYPE_RESPONSE = 3;
  26. const WORD PTPCONTAINER_TYPE_EVENT = 4;
  27. //
  28. // Used to store info about the endpoints
  29. //
  30. typedef struct _USB_PTP_ENDPOINT_INFO
  31. {
  32. USHORT BulkInMaxSize;
  33. UCHAR BulkInAddress;
  34. USHORT BulkOutMaxSize;
  35. UCHAR BulkOutAddress;
  36. USHORT InterruptMaxSize;
  37. UCHAR InterruptAddress;
  38. } USB_PTP_ENDPOINT_INFO, *PUSB_PTP_ENDPOINT_INFO;
  39. #pragma pack(push, Old, 1)
  40. //
  41. // When a USB device stalls, the usb kernel mode stack driver returns
  42. // a NTSTATUS code, STATUS_DEVICE_DATA_ERROR. Translates this NT status
  43. // code to WIN32 error code, we get ERROR_CRC.
  44. //
  45. const DWORD WIN32ERROR_USBSTALL = ERROR_CRC;
  46. //
  47. // Container header
  48. //
  49. typedef struct _USB_PTP_HEADER
  50. {
  51. DWORD Len; // total length of container in bytes including header
  52. WORD Type; // container type, one of CONTAINER_TYPE_COMMAND/RESPONSE/DATA/EVENT
  53. WORD Code; // opcode, response code, or event code
  54. DWORD TransactionId; // transaction id
  55. }USB_PTP_HEADER, *PUSB_PTP_HEADER;
  56. //
  57. // USB PTP command structure
  58. //
  59. typedef struct _USB_PTP_COMMAND
  60. {
  61. USB_PTP_HEADER Header;
  62. DWORD Params[COMMAND_NUMPARAMS_MAX];
  63. }USB_PTP_COMMAND, *PUSB_PTP_COMMAND;
  64. //
  65. // USB PTP response structure
  66. //
  67. typedef struct _USB_PTP_RESPONSE
  68. {
  69. USB_PTP_HEADER Header;
  70. DWORD Params[RESPONSE_NUMPARAMS_MAX];
  71. }USB_PTP_RESPONSE, *PUSB_PTP_RESPONSE;
  72. //
  73. // USB PTP event structure
  74. //
  75. typedef struct _USB_PTP_EVENT
  76. {
  77. USB_PTP_HEADER Header;
  78. DWORD Params[EVENT_NUMPARAMS_MAX];
  79. }USB_PTP_EVENT, *PUSB_PTP_EVENT;
  80. //
  81. // USB PTP data structure
  82. //
  83. typedef struct _USB_PTP_DATA
  84. {
  85. USB_PTP_HEADER Header;
  86. BYTE Data[1];
  87. }USB_PTP_DATA, *PUSB_PTP_DATA;
  88. //
  89. // GetDeviceStatus header
  90. //
  91. typedef struct tagUSBPTPDeviceStatusHeader
  92. {
  93. WORD Len; // status
  94. WORD Code; // ptp response code
  95. }USB_PTPDEVICESTATUS_HEADER, *PUSB_PTPDEVICESTATUS_HEADER;
  96. //
  97. // GetDeviceStatus data
  98. //
  99. typedef struct tagUSBPTPDeviceStatus
  100. {
  101. USB_PTPDEVICESTATUS_HEADER Header; // the header
  102. DWORD Params[MAX_NUM_PIPES];
  103. }USB_PTPDEVICESTATUS, *PUSB_PTPDEVICESTATUS;
  104. const BYTE USB_PTPREQUEST_TYPE_OUT = 0x21;
  105. const BYTE USB_PTPREQUEST_TYPE_IN = 0xA1;
  106. const BYTE USB_PTPREQUEST_CANCELIO = 0x64;
  107. const BYTE USB_PTPREQUEST_GETEVENT = 0x65;
  108. const BYTE USB_PTPREQUEST_RESET = 0x66;
  109. const BYTE USB_PTPREQUEST_GETSTATUS = 0x67;
  110. const WORD USB_PTPCANCELIO_ID = 0x4001;
  111. //
  112. // Other USB Imaging Class-specific commands
  113. //
  114. typedef struct tagUSBPTPCancelIoRequest
  115. {
  116. WORD Id;
  117. DWORD TransactionId;
  118. }USB_PTPCANCELIOREQUEST, *PUSB_PTPCANCELIOREQUEST;
  119. typedef struct tagUSBPTPResetRequest
  120. {
  121. DWORD TransactionId;
  122. }USB_PTPRESETREQUEST, *PUSB_PTPRESETREQUEST;
  123. typedef struct tagUSBPTPGetEventRequest
  124. {
  125. WORD EventCode;
  126. DWORD TransactionId;
  127. DWORD Params;
  128. }USB_PTPGETEVENTREQUEST, *PUSB_PTPGETEVENTREQUEST;
  129. #pragma pack(pop, Old)
  130. //
  131. // A CPTPCamera derived class to support PTP USB devices
  132. //
  133. class CUsbCamera : public CPTPCamera
  134. {
  135. public:
  136. CUsbCamera();
  137. ~CUsbCamera();
  138. private:
  139. HRESULT Open(LPWSTR DevicePortName, PTPEventCallback pPTPEventCB,
  140. PTPDataCallback pPTPDataCB, LPVOID pEventParam, BOOL bEnableEvents = TRUE);
  141. HRESULT Close();
  142. //
  143. // Functions called by the base class
  144. //
  145. HRESULT SendCommand(PTP_COMMAND *pCommand, UINT NumParams);
  146. HRESULT ReadData(BYTE *pData, UINT *pBufferSize);
  147. HRESULT SendData(BYTE *pData, UINT BufferSize);
  148. HRESULT ReadResponse(PTP_RESPONSE *pResponse);
  149. HRESULT ReadEvent(PTP_EVENT *pEvent);
  150. HRESULT AbortTransfer();
  151. HRESULT RecoverFromError();
  152. private:
  153. //
  154. // Private utility functions
  155. //
  156. HRESULT GetDeviceStatus(USB_PTPDEVICESTATUS *pDeviceStatus);
  157. HRESULT ClearStalls(USB_PTPDEVICESTATUS *pDeviceStatus);
  158. HRESULT SendResetDevice();
  159. HRESULT SendCancelRequest(DWORD dwTransactionId);
  160. //
  161. // Member variables
  162. //
  163. HANDLE m_hUSB; // File handle used to communicate with USB device
  164. HANDLE m_hEventUSB; // File handle used to read events
  165. OVERLAPPED m_Overlapped; // Overlapped structure for event reads
  166. HANDLE m_hEventRead; // Event handle used by event read
  167. HANDLE m_hEventCancel; // Event handle used to cancel interrupt read
  168. HANDLE m_EventHandles[2]; // Array used by WaitForMultipleObjects
  169. USB_PTP_ENDPOINT_INFO m_EndpointInfo; // Info about the endpoints
  170. USB_PTP_COMMAND m_UsbCommand; // Re-usable buffer for commands
  171. USB_PTP_RESPONSE m_UsbResponse; // Re-usable buffer for responses
  172. USB_PTP_DATA *m_pUsbData; // Pointer to re-usable buffer for short data transfers
  173. UINT m_UsbDataSize; // Size allocated for the data transfer buffer
  174. WORD m_prevOpCode; // Used to store opcode between command and data phases
  175. DWORD m_prevTranId; // Used to store transaction id between command and data phases
  176. };
  177. #endif // #ifndef CAMUSB__H_