/*****************************************************************************
 * Copyright (C) Gemalto M2M GmbH
 *****************************************************************************
 * Project: IMC-RIL-Driver
 *****************************************************************************
 * Author : Wireless Modules RD SW A2
 *****************************************************************************
 * $Workfile: Y:/z_ms-d/src/working/Quinn/RilDrv/atcmd.h $
 * $Revision: /main/ms-d/12 $
 *     $Date: 2014-01-31 12:03:42 $
 *   $Author: pmackent $
 *****************************************************************************
 * Target:
 *  Microsoft Windows Mobile 5.0
 *****************************************************************************
 * Description:
 *  Gemalto IMC RIL
 *****************************************************************************
 *
 * $Log: Y:/z_ms-d/src/working/Quinn/RilDrv/atcmd.h$ 
 * 
 * /main/ms-d/12   2014-01-31 12:03:42   pmackent 
 * Handle SIM-PIN error for Wrong-CPWD-WA. Disable this WA for PHS8 Rel3
 *
 * /main/ms-d/11   2011-03-29 11:37:07   ctna0256
 * Don't use noop queue as default to solve timing issues in conference calls
 *
 * /main/ms-d/10   2010-08-19 14:29:52   ctna0256
 * Implementation A-GPS for PH8
 *
 * /main/ms-d/9   2009-10-07 09:22:11   ctna0256
 * Introduce no-operation command queue
 * Support 2nd alpha identifier in SAT setup call (IPIS100055375)
 *
 * /main/ms-d/8   2008-08-22 10:22:30   ctna0256
 * Set Cinterion copyright text
 *
 * /main/ms-d/7   2008-08-21 09:33:50   ctna0256
 * Prepared for new disclaimer handling
 *
 * /main/ms-d/6   2007-11-02 15:16:56   mp49210
 * Check SIM/USIM after successful At+CPIN? command only
 *
 * /main/ms-d/5   2007-07-11 15:11:27   mp49210
 * Optional additional waiting period before sending AT commands
 *
 * /main/ms-d/4   2007-05-29 09:36:59   mp49210
 * Workaoround for wrong error code to AT+CPIN?
 *
 * /main/ms-d/3   2006-11-22 15:43:18   wm36264
 * Avoid obsolete new/delete cycles
 *
 * /main/ms-d/2   2006-11-14 16:59:54   wm36264
 * Tidy up more unused stuff
 *
 * /main/ms-d/1   2006-10-25 16:52:41   wm36264
 * First transformation from classic RIL
 *
*/

//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008 Gemalto M2M GmbH
// Copyright (C) 2006-2008 Siemens AG
// Copyright (C) 2003 Intrinsyc Europe Ltd.
//
// Version: 1.0
// Date:    dummy
//
//////////////////////////////////////////////////////////////////////////////

/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-1999  Microsoft Corporation
--*/

#pragma once

//
// Switches
//

// If USE_NOOP_QUEUE is defined, the RIL handles all no-operation
// commands in an extra queue. This way commands like query of
// signal strength are no longer blocked by long running commands.
// This behaviour is the equivalent to the multiple command queue
// handling of the Classic RIL.
//#define USE_NOOP_QUEUE

//
// Forward declarations
//
class CRilHandle;
enum APIID;


//
// Globals
//

#define COMMAND_QUEUE_SIZE      40
#define RESPONSE_QUEUE_SIZE     10

extern CPriorityQueue<CCommand, COMMAND_QUEUE_SIZE>  g_CmdQ;
extern CQueue<CResponse, RESPONSE_QUEUE_SIZE>        g_RspQ;
extern CPriorityQueue<CCommand, COMMAND_QUEUE_SIZE>  g_NoopCmdQ;

//
// Structures
//
struct REQUEUE_THREAD_DATA {
    CCommand* pCmd;
    DWORD dwDelay;
};

struct QUEUE_THREAD_DATA {
    CRilHandle*    pRilDevice;
    CCheckPoint*   pCheckPoint;
    COM_PORT_TYPE  PortType;
};

struct QUEUE_BLOCKING_DATA {
    PFN_CMD_PARSE     pfnParseOk;
    PFN_CMD_ERROR     pfnParseErr;
    LPVOID            pParam;
    HANDLE            hEvents[2];
    HRESULT           hrError;
};

// Routines
BOOL QueueCmd(HCCMD_MODE CmdMode, CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL);
BOOL QueueCmdWithRetry(HCCMD_MODE CmdMode, CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID, DWORD dwRetries, DWORD dwRetryDelay, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL);
BOOL QueueMultipartCmd(HCCMD_MODE CmdMode, CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const LPCSTR szCmdPart2, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL);
BOOL QueueMultipartCmdWithRetry(HCCMD_MODE CmdMode, CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const LPCSTR szCmdPart2, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID, const PFN_CMD_ERROR pfnError, const LPVOID pParseParam, DWORD dwRetries, DWORD dwRetryDelay);
BOOL QueueCmdWithTimeout(HCCMD_MODE CmdMode, CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const LPCSTR szCmdPart2, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID, DWORD dwTimeout, DWORD dwRetries, DWORD dwRetryDelay,
              const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL, const CME_TRANSLATION *pCMET = NULL, const PFN_PRE_CMD_CHECK pfnPreCheck = NULL);
BOOL RequeueCmdWithDelay(CCommand* pCmd, DWORD dwDelay);
BOOL QueueCmdCMET(HCCMD_MODE CmdMode, CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID, const CME_TRANSLATION *pCMET,  DWORD dwRetries = 0, DWORD dwRetryDelay = 0, const LPVOID pParseParam = NULL);
BOOL QueueInternalCmd(HCCMD_MODE CmdMode, CRilHandle* const pRilDevice, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid, DWORD dwTimeout, DWORD dwRetries, DWORD dwRetryDelay,
              const PFN_CMD_PARSE pfnParse = NULL, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL, CNotificationData* const pnd = NULL, const CME_TRANSLATION *pCMET = NULL);
BOOL QueueInternalMultipartCmd(HCCMD_MODE CmdMode, CRilHandle* const pRilDevice, const LPCSTR szCmd, const LPCSTR szCmd2, const DWORD dwOptions, const APIID apiid, DWORD dwTimeout, DWORD dwRetries, DWORD dwRetryDelay,
              const PFN_CMD_PARSE pfnParse = NULL, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL, CNotificationData* const pnd = NULL, const CME_TRANSLATION *pCMET = NULL);
BOOL QueueInternalCmdBlocking(HCCMD_MODE CmdMode, CRilHandle* const pRilDevice, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid, DWORD dwTimeout, DWORD dwRetries, DWORD dwRetryDelay,
              const PFN_CMD_PARSE pfnParse = NULL, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL, CNotificationData* const pnd = NULL, const CME_TRANSLATION *pCMET = NULL, HRESULT *phr = NULL);
BOOL QueueInternalMultipartCmdBlocking(HCCMD_MODE CmdMode, CRilHandle* const pRilDevice, const LPCSTR szCmd, const LPCSTR szCmd2, const DWORD dwOptions, const APIID apiid, DWORD dwTimeout, DWORD dwRetries, DWORD dwRetryDelay,
              const PFN_CMD_PARSE pfnParse = NULL, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL, CNotificationData* const pnd = NULL, const CME_TRANSLATION *pCMET = NULL, HRESULT *phr = NULL);
BOOL QueueCmdBlocking(HCCMD_MODE CmdMode, CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid, const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd,
              HRESULT& rhrCmdID, DWORD dwTimeout, DWORD dwRetries, DWORD dwRetryDelay, const PFN_CMD_ERROR pfnError = NULL, const LPVOID pParseParam = NULL);


// Thread procedures command COM port
DWORD WINAPI CmdThreadProc(LPVOID lpParameter);
DWORD WINAPI ReadThreadProc(LPVOID lpParameter);
DWORD WINAPI NoopCmdThreadProc(LPVOID lpParameter);

extern DWORD g_dwWaitBeforeATCommand;

