/*****************************************************************************
 * Copyright (C) Cinterion Wireless Modules GmbH
 *****************************************************************************
 * Project: Quinn-CE-USB-Driver
 *****************************************************************************
 * Author : Siemens AG Berlin COM WM RD SW
 *****************************************************************************
 * $Workfile: O:/ctna0450_RIL/z_ms-d/src/working/Classic/HcUsbDrv/UsbPipe.h $
 * $Revision: /main/ms-d/19 $
 * $Date: 2011-03-02 10:50:44 $
 * $Author: ctna0450 $
 *****************************************************************************
 * Target:
 *  Microsoft Windows CE 5.0
 *****************************************************************************
 * Description:
 *  Quinn-USB-Driver: Virtual COM port port class CUsbPipe
 *  definition
 *****************************************************************************
 *
 * $Log: O:/ctna0450_RIL/z_ms-d/src/working/Classic/HcUsbDrv/UsbPipe.h$ 
 * 
 * /main/ms-d/19   2011-03-02 10:50:44   ctna0450 
 * Avoid sending of unnecessary zero length packages
 *
 * /main/ms-d/18   2011-02-02 10:27:57   ctna0450
 * Removed unused USB-Reset workaround for Uranus USB problems
 *
 * /main/ms-d/17   2011-01-13 15:26:27   ctna0152
 * added support for zero length packets
 *
 * /main/ms-d/16   2010-12-13 14:22:55   ctna0152
 * added USB reset handling
 *
 * /main/ms-d/15   2009-02-18 11:49:43   ctna0256
 * Set copyright text
 *
 * /main/ms-d/14   2008-08-20 11:39:19   ctna0450
 * Prepared for new disclaimer handling
 *
 * /main/ms-d/13   2008-06-19 14:24:33   ht37010
 * added workaround for USB host function failure
 *
 * /main/ms-d/12   2008-04-10 15:14:04   ht37010
 * bugfix: deadlock in UsbPipe.WaitForResume() vs. VPort.Close()
 *
 * /main/ms-d/11   2008-03-03 12:38:35   ht37010
 * added force flag to AbortTransfer() to abort waiting-for-resume on VPort.Close()
 *
 * /main/ms-d/10   2008-02-18 15:12:00   ht37010
 * added new event as bugfix for possible deadlock on closing a virtual port (may happen if pipe is waiting for device resume and the port is closed)
 *
 * /main/ms-d/9   2007-12-18 11:45:22   ht37010
 * added USB Watchdog for lpResetPipe
 *
 * /main/ms-d/8   2006-11-03 17:07:02   wm36264
 * Continued to prepare selective suspend handling
 *
 * /main/ms-d/7   2006-10-20 12:16:24   wm36264
 * The ndis irq pipe notifies us when there is qmi data available on the default pipe
 *
 * /main/ms-d/6   2006-10-18 12:33:52   wm36264
 * Several modifications regarding default pipe handling for qmi
 *
 * /main/ms-d/5   2006-10-12 16:52:34   wm36264
 * For a possible future selective suspend implementation it is much easier when there is only one pipe class
 *
 * /main/ms-d/4   2006-09-29 15:33:34   wm36264
 * Consider latest findings about QMI and NDIS handling
 *
 * /main/ms-d/3   2006-09-22 14:33:38   wm36264
 * Cosmetics mostly
 *
 * /main/ms-d/2   2006-09-21 17:05:30   wm36264
 * Prepared access to QMI interface
 *
 * /main/ms-d/1   2006-09-18 15:31:36   wm36264
 * Initial Quinn Windows CE USB Driver based on UsbSer
 *
*/

//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008 Cinterion Wireless Modules GmbH
// Copyright (C) 2006-2008 Siemens AG
//
// Version: 1.0
// Date:    dummy
//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
//
// UsbPipe.h
//
// This file contains the definition of the class "CUsbPipe" which implements
// the handling of an USB pipe.
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

//////////////////////////////////////////////////////////////////////////////

class CUsbWatchDog;

class CUsbPipe {
public:
  CUsbPipe();
  ~CUsbPipe();
  BOOL                 Initialize(USB_HANDLE Device, LPCUSB_FUNCS Funcs, LPCUSB_ENDPOINT Endpoint, CSelectiveSuspend* pSelectiveSuspend);
  BOOL                 Deinitialize(void);
  BOOL                 IsValid(void) { SYNCBLOCK(m_csLock); return((m_hPipe != NULL) || m_fIsDefaultPipe); };
  DWORD                TransferData(PBYTE pData, DWORD dwLen, DWORD dwTimeout, BOOL fUseZLP = FALSE);
  DWORD                TransferVendorData(BOOL fOut, USHORT wIndex, UCHAR bRequest, USHORT wValue, PBYTE pData, USHORT wLen, DWORD dwTimeout);
  BOOL                 AbortTransfer(void);
  BOOL                 Reset(BOOL fClrStall = FALSE);
  BOOL                 Open(void);
  BOOL                 Close(void);

private:
  static DWORD         TransferComplete(PVOID pvNotifyParameter);

  CRITICAL_SECTION     m_csLock;
  USB_HANDLE           m_hDevice;
  LPCUSB_FUNCS         m_pFuncs;
  USB_PIPE             m_hPipe;
  USB_TRANSFER         m_hTransfer;
  HANDLE               m_hCompletionEvent;
  HANDLE               m_hDefaultCompletionEvent;
  HANDLE               m_hAbortTransferEvent;
  BYTE                 m_bType;
  BYTE                 m_bIndex;
  BOOL                 m_fIsDefaultPipe;
  CSelectiveSuspend*   m_pSelectiveSuspend;

  USHORT               m_wMaxPacketSize;

  BOOL                 TransferZeroLengthPacket(void);

#ifdef USE_WA_RETRY_ON_HOSTFN_FAIL
  DWORD                m_dwHostFnRetryDelay;
  DWORD                m_dwHostFnRetryCount;
#endif

#ifdef USE_WATCHDOG_RESET_PIPE
  CUsbWatchDog *m_pWDResetPipe;
public:
  CUsbWatchDog * getWDResetPipe( void ) { return m_pWDResetPipe; };
#endif
};
