/*****************************************************************************
 * Copyright (C) Gemalto M2M GmbH
 *****************************************************************************
 * Project: IMC-RIL-Driver
 *****************************************************************************
 * Author : Wireless Modules RD SW A2
 *****************************************************************************
 * $Workfile: Y:/z_ms-d/src/working/Quinn/RilDrv/supsvc.h $
 * $Revision: /main/ms-d/12 $
 *     $Date: 2013-03-01 09:10:21 $
 *   $Author: pmackent $
 *****************************************************************************
 * Target:
 *  Microsoft Windows Mobile 5.0
 *****************************************************************************
 * Description:
 *  Gemalto IMC RIL
 *****************************************************************************
 *
 * $Log: Y:/z_ms-d/src/working/Quinn/RilDrv/supsvc.h$ 
 * 
 * /main/ms-d/12   2013-03-01 09:10:21   pmackent 
 * No semicolon for *# on EHS5 (IPIS100085708)
 *
 * /main/ms-d/11   2012-06-07 13:48:45   pmackent
 * Avoid *#-squences in CDMA mode
 *
 * /main/ms-d/10   2010-10-15 11:56:51   ctna0256
 * COLR now supported in PH8
 *
 * /main/ms-d/9   2008-08-22 10:28:15   ctna0256
 * Set Cinterion copyright text
 *
 * /main/ms-d/8   2008-08-21 09:35:42   ctna0256
 * Prepared for new disclaimer handling
 *
 * /main/ms-d/7   2008-01-11 12:17:07   mp49210
 * Remove unnecessary * in *# sequences
 *
 * /main/ms-d/6   2007-03-28 10:42:01   mp49210
 * Store CLIR value persistent
 *
 * /main/ms-d/5   2006-12-28 12:03:55   mp49210
 * No <t> parameter for *#61#
 *
 * /main/ms-d/4   2006-12-11 16:20:42   mp49210
 * Re-Integration of *#-sequences for GCF approval
 *
 * /main/ms-d/3   2006-11-08 09:35:24   mp49210
 * No COLR in Quinn
 *
 * /main/ms-d/2   2006-11-02 14:59:12   mp49210
 * No *#-sequences in HC25
 *
 * /main/ms-d/1   2006-10-25 16:52:25   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

#define SUPSVC_CMDBUF_LENGTH        (MAX_ATCMD_LEN)
// We do not need this calculation: any string from or to the AT interface will not exceed MAX_ATCMD_LEN character
//#define SUPSVC_CMDBUF_LENGTH        (MAX_PATH + MAXLENGTH_ADDRESS)
#define SUPSVC_ALLOC_NUMBER         16         // Max. numbers of digits for call forwaring numbers

#define USSD_TIMEOUT                30000      // Timeout: Response for USSD commands (in ms)
#define USSD_COLP_TIMEOUT           30000      // Time (in ms) to wait after AT+CUSD before AT+COLP? or AT+CLIP? can be used
#define USSD_COLP_TIMEOUT_RETRIES   10         // Number of retries for AT+COLP? and AT+CLIP? after USSD
#define ATD_CCFC_TIMEOUT            3000       // Time (in ms) which must pass between ATD (voice) and AT+CCFC (or *#-sequences), must be larger than ATD_BEFORE_DIALING
#define ATD_CCFC_TIMEOUT_RETRIES    10         // Numbers of retries in case of a ATD (voice) and AT+CCFC (or *#-sequences) conflict
#define ATD_BEFORE_DIALING          2500       // Time (in ms) the module takes to enter dialing state after ATD

//
// Information classes
//
const DWORD g_rgdwInfoClasses[] =
{
    RIL_INFOCLASS_VOICE,            // 1  = 2^0
    RIL_INFOCLASS_DATA,             // 2  = 2^1
    RIL_INFOCLASS_FAX,              // 4  = 2^2
    RIL_INFOCLASS_SMS,              // 8  = 2^3
    RIL_INFOCLASS_DATACIRCUITSYNC,  // 16 = 2^4
    RIL_INFOCLASS_DATACIRCUITASYNC, // 32 = 2^5
    RIL_INFOCLASS_PACKETACCESS,     // 32 = 2^6
    RIL_INFOCLASS_PADACCESS,        // 64 = 2^7
};
#define NUM_INFOCLASSES        (sizeof(g_rgdwInfoClasses) / sizeof(DWORD))

//
// Translation table InfoClass -> BS
//
struct INFOCLASS2BS
{
    DWORD dwInfoClass;
    UINT  uiBS;
};

static const INFOCLASS2BS g_rgInfoClassTable[] =
{
    {RIL_INFOCLASS_VOICE, 11},
    {RIL_INFOCLASS_FAX, 13},
    {RIL_INFOCLASS_SMS, 16},
    {RIL_INFOCLASS_FAX|RIL_INFOCLASS_SMS, 12},
    {RIL_INFOCLASS_DATACIRCUITASYNC, 25},
    {RIL_INFOCLASS_DATACIRCUITSYNC, 24},
    {RIL_INFOCLASS_PADACCESS, 27},
    {RIL_INFOCLASS_PACKETACCESS, 26},
    {RIL_INFOCLASS_DATACIRCUITASYNC|RIL_INFOCLASS_PADACCESS, 21},
    {RIL_INFOCLASS_DATACIRCUITSYNC|RIL_INFOCLASS_PACKETACCESS, 22},
    {RIL_INFOCLASS_DATACIRCUITASYNC|RIL_INFOCLASS_DATACIRCUITSYNC|RIL_INFOCLASS_PACKETACCESS|RIL_INFOCLASS_PADACCESS, 20},
    {RIL_INFOCLASS_DATA, 20},
    {RIL_INFOCLASS_VOICE|RIL_INFOCLASS_DATA|RIL_INFOCLASS_FAX|RIL_INFOCLASS_SMS, 100},     // 100 -> ommit parameter
    {RIL_INFOCLASS_VOICE|RIL_INFOCLASS_DATA|RIL_INFOCLASS_FAX, 100}     // this is not conform to spec but occasional MS uses this combination, when the mean all services.
};
#define NUM_BS_VALUES    (sizeof(g_rgInfoClassTable) / sizeof(INFOCLASS2BS))

//
// Translation table Forwarding Type -> *#-Code
//
#define RIL_FORWARDINGSTATUS_ACTIVATE                (0x00000001)
#define RIL_FORWARDINGSTATUS_DEACTIVATE              (0x00000002)
#define RIL_FORWARDINGSTATUS_QUERY                   (0x00000003)
#define RIL_FORWARDINGSTATUS_REGISTER                (0x00000004)
#define RIL_FORWARDINGSTATUS_REMOVE                  (0x00000005)

struct FORWARDING2ATD
{
    DWORD dwForwardingReason;
    DWORD dwForwardingStatus;
    char  szATD[8];
    BOOL  bNeedsT;
};

static const FORWARDING2ATD g_rgForwardingTypeTable[] =
{
    {RIL_FWDREASON_UNCONDITIONAL, RIL_FORWARDINGSTATUS_ACTIVATE, "*21", FALSE},
    {RIL_FWDREASON_MOBILEBUSY,    RIL_FORWARDINGSTATUS_ACTIVATE, "*67", FALSE},
    {RIL_FWDREASON_NOREPLY,       RIL_FORWARDINGSTATUS_ACTIVATE, "*61", TRUE},
    {RIL_FWDREASON_UNREACHABLE,   RIL_FORWARDINGSTATUS_ACTIVATE, "*62", FALSE},
    {RIL_FWDREASON_ALLFORWARDING, RIL_FORWARDINGSTATUS_ACTIVATE, "*002", TRUE},
    {RIL_FWDREASON_ALLCONDITIONAL,RIL_FORWARDINGSTATUS_ACTIVATE, "*004", TRUE},
    {RIL_FWDREASON_UNCONDITIONAL, RIL_FORWARDINGSTATUS_DEACTIVATE, "#21", FALSE},
    {RIL_FWDREASON_MOBILEBUSY,    RIL_FORWARDINGSTATUS_DEACTIVATE, "#67", FALSE},
    {RIL_FWDREASON_NOREPLY,       RIL_FORWARDINGSTATUS_DEACTIVATE, "#61", TRUE},
    {RIL_FWDREASON_UNREACHABLE,   RIL_FORWARDINGSTATUS_DEACTIVATE, "#62", FALSE},
    {RIL_FWDREASON_ALLFORWARDING, RIL_FORWARDINGSTATUS_DEACTIVATE, "#002", TRUE},
    {RIL_FWDREASON_ALLCONDITIONAL,RIL_FORWARDINGSTATUS_DEACTIVATE, "#004", TRUE},
    {RIL_FWDREASON_UNCONDITIONAL, RIL_FORWARDINGSTATUS_QUERY, "*#21", FALSE},
    {RIL_FWDREASON_MOBILEBUSY,    RIL_FORWARDINGSTATUS_QUERY, "*#67", FALSE},
    {RIL_FWDREASON_NOREPLY,       RIL_FORWARDINGSTATUS_QUERY, "*#61", FALSE},
    {RIL_FWDREASON_UNREACHABLE,   RIL_FORWARDINGSTATUS_QUERY, "*#62", FALSE},
    {RIL_FWDREASON_ALLFORWARDING, RIL_FORWARDINGSTATUS_QUERY, "*#002", TRUE},
    {RIL_FWDREASON_ALLCONDITIONAL,RIL_FORWARDINGSTATUS_QUERY, "*#004", TRUE},
    {RIL_FWDREASON_UNCONDITIONAL, RIL_FORWARDINGSTATUS_REGISTER, "**21", FALSE},
    {RIL_FWDREASON_MOBILEBUSY,    RIL_FORWARDINGSTATUS_REGISTER, "**67", FALSE},
    {RIL_FWDREASON_NOREPLY,       RIL_FORWARDINGSTATUS_REGISTER, "**61", TRUE},
    {RIL_FWDREASON_UNREACHABLE,   RIL_FORWARDINGSTATUS_REGISTER, "**62", FALSE},
    {RIL_FWDREASON_ALLFORWARDING, RIL_FORWARDINGSTATUS_REGISTER, "**002", TRUE},
    {RIL_FWDREASON_ALLCONDITIONAL,RIL_FORWARDINGSTATUS_REGISTER, "**004", TRUE},
    {RIL_FWDREASON_UNCONDITIONAL, RIL_FORWARDINGSTATUS_REMOVE, "##21", FALSE},
    {RIL_FWDREASON_MOBILEBUSY,    RIL_FORWARDINGSTATUS_REMOVE, "##67", FALSE},
    {RIL_FWDREASON_NOREPLY,       RIL_FORWARDINGSTATUS_REMOVE, "##61", TRUE},
    {RIL_FWDREASON_UNREACHABLE,   RIL_FORWARDINGSTATUS_REMOVE, "##62", FALSE},
    {RIL_FWDREASON_ALLFORWARDING, RIL_FORWARDINGSTATUS_REMOVE, "##002", TRUE},
    {RIL_FWDREASON_ALLCONDITIONAL,RIL_FORWARDINGSTATUS_REMOVE, "##004", TRUE}
};
#define NUM_FORWARDING_VALUES    (sizeof(g_rgForwardingTypeTable) / sizeof(FORWARDING2ATD))

//
// Translation table Call Waiting Type -> *#-Code
//
#define RIL_CALLWAITINGSTATUS_ACTIVATE                (0x00000001)
#define RIL_CALLWAITINGSTATUS_DEACTIVATE              (0x00000002)
#define RIL_CALLWAITINGSTATUS_QUERY                   (0x00000003)

struct CALLWAITING2ATD
{
    DWORD dwCallWaitingStatus;
    char  szATD[8];
};

static const CALLWAITING2ATD g_rgCallWaitingTypeTable[] =
{
    {RIL_CALLWAITINGSTATUS_ACTIVATE, "*43" },
    {RIL_CALLWAITINGSTATUS_DEACTIVATE, "#43" },
    {RIL_CALLWAITINGSTATUS_QUERY, "*#43" }
};
#define NUM_CALLWAITING_VALUES    (sizeof(g_rgCallWaitingTypeTable) / sizeof(CALLWAITING2ATD))

//
// HideID status values
//
const DWORD g_rgdwHideIDStats[] =
{
    RIL_SVCSTAT_DEFAULT,            // 0
    RIL_SVCSTAT_ENABLED,            // 1
    RIL_SVCSTAT_DISABLED,           // 2
};
#define NUM_HIDEIDSTATS   (sizeof(g_rgdwHideIDStats) / sizeof(DWORD))


// This #define is missing on some Microsoft builds.
#ifndef RIL_INFOCLASS_NONE
#define RIL_INFOCLASS_NONE    (0x00000000)
#endif
// These default values are used, when RIL_INFOCLASS_NONE is passed by the MMI.
#define RIL_INFOCLASS_DEFAULT_CALLWAITING   (RIL_INFOCLASS_VOICE | RIL_INFOCLASS_DATA | RIL_INFOCLASS_FAX)
#define RIL_INFOCLASS_DEFAULT_CALLFORWARING (RIL_INFOCLASS_VOICE | RIL_INFOCLASS_DATA | RIL_INFOCLASS_FAX)
#define RIL_INFOCLASS_DEFAULT_CALLBARRING   (RIL_INFOCLASS_VOICE | RIL_INFOCLASS_DATA | RIL_INFOCLASS_FAX | RIL_INFOCLASS_SMS)
#define ETSI_SPEC

// Registry Key: last set CLIR value
#define REG_LAST_CLIR   TEXT("LastCLIR")

//
// Translation function InfoClass (Microsoft) -> BS (GSM)
//
UINT RILDrv_FindBS4InfoClass(DWORD dwInfoClass);

HRESULT RILDrv_GetCallerIdSettings(DWORD dwParam);
HRESULT RILDrv_SetCallerIdStatus(DWORD dwParam, DWORD dwStatus);
HRESULT RILDrv_GetHideIdSettings(DWORD dwParam);
HRESULT RILDrv_SetHideIdStatus(DWORD dwParam, DWORD dwStatus);
HRESULT RILDrv_GetDialedIdSettings(DWORD dwParam);
HRESULT RILDrv_SetDialedIdStatus(DWORD dwParam, DWORD dwStatus);
HRESULT RILDrv_GetHideConnectedIdSettings(DWORD dwParam);
HRESULT RILDrv_SetHideConnectedIdStatus(DWORD dwParam, DWORD dwStatus);
HRESULT RILDrv_GetClosedGroupSettings(DWORD dwParam);
HRESULT RILDrv_SetClosedGroupSettings(DWORD dwParam, const RILCLOSEDGROUPSETTINGS* lpSettings);
HRESULT RILDrv_GetCallForwardingSettings(DWORD dwParam, DWORD dwReason, DWORD dwInfoClasses);
HRESULT RILDrv_AddCallForwarding(DWORD dwParam, DWORD dwReason, const RILCALLFORWARDINGSETTINGS* lpSettings);
HRESULT RILDrv_RemoveCallForwarding(DWORD dwParam, DWORD dwReason, DWORD dwInfoClasses);
HRESULT RILDrv_SetCallForwardingStatus(DWORD dwParam, DWORD dwReason, DWORD dwInfoClasses, DWORD dwStatus);
HRESULT RILDrv_GetCallWaitingSettings(DWORD dwParam, DWORD dwInfoClasses);
HRESULT RILDrv_SetCallWaitingStatus(DWORD dwParam, DWORD dwInfoClasses, DWORD dwStatus);
HRESULT RILDrv_SendSupServiceData(DWORD dwParam, const BYTE* lpbData, DWORD dwSize);
HRESULT RILDrv_CancelSupServiceDataSession(DWORD dwParam);

extern DWORD g_dwHideCallerId;

void CleanATDString(LPSTR lpszATDString);
BOOL UseGSM0707Cmd(CRilInstanceHandle *pHandle);
const char *GetATDSemicolon(void);

