/*****************************************************************************
 * Copyright (C) Gemalto M2M GmbH
 *****************************************************************************
 * Project: IMC-RIL-Driver
 *****************************************************************************
 * Author : Wireless Modules RD SW A2
 *****************************************************************************
 * $Workfile: Y:/z_ms-d/src/working/Quinn/RilDrv/secur.h $
 * $Revision: /main/ms-d/18 $
 *     $Date: 2012-11-21 13:30:04 $
 *   $Author: pmackent $
 *****************************************************************************
 * Target:
 *  Microsoft Windows Mobile 5.0
 *****************************************************************************
 * Description:
 *  Gemalto IMC RIL
 *****************************************************************************
 *
 * $Log: Y:/z_ms-d/src/working/Quinn/RilDrv/secur.h$ 
 * 
 * /main/ms-d/18   2012-11-21 13:30:04   pmackent 
 * Basic support of EHS5 Rel2
 *
 * /main/ms-d/17   2012-11-05 11:04:55   pmackent
 * Workaround for PIN2-state-query working only once
 *
 * /main/ms-d/16   2012-02-03 15:07:38   ctna0256
 * Move URC parsing functions in separate file
 *
 * /main/ms-d/15   2012-02-02 17:04:06   ctna0256
 * FD phonebook workaround and NITZ URCs for Intel platform
 *
 * /main/ms-d/14   2012-01-05 10:26:54   ctna0256
 * Save PIN2 because of problem with AT+CLCK="FD" in PH8 Rel2 (IPIS100076746)
 *
 * /main/ms-d/13   2010-07-02 11:05:23   ctna0256
 * New handling of Customer SIM lock for HC25 R2 (IPIS100065826)
 *
 * /main/ms-d/12   2010-06-29 10:33:07   ctna0256
 * Swap PH-NET PIN and PUK
 *
 * /main/ms-d/11   2008-08-26 14:27:00   ctna0256
 * Merged RIL_RADIO_RESILIENCE option from Classic-RIL
 *
 * /main/ms-d/10   2008-08-22 10:27:50   ctna0256
 * Set Cinterion copyright text
 *
 * /main/ms-d/9   2008-08-21 09:35:32   ctna0256
 * Prepared for new disclaimer handling
 *
 * /main/ms-d/8   2008-01-17 15:25:54   mp49210
 * Fix for slow UICC SIMs (wrong SIM not inserted error)
 *
 * /main/ms-d/7   2007-11-19 17:43:45   mp49210
 * New WM6 AKU1.0 API
 *
 * /main/ms-d/6   2007-08-10 16:56:13   mp49210
 * IPIS100040302: send AT+CSIM after AT+CPIN?
 *
 * /main/ms-d/5   2007-06-20 13:50:21   mp49210
 * Select FD phonebook as default in case fixed dialing is active
 *
 * /main/ms-d/4   2006-12-11 16:20:38   mp49210
 * Re-Integration of *#-sequences for GCF approval
 *
 * /main/ms-d/3   2006-11-13 10:05:02   mp49210
 * New PIN2 handling in Quinn
 *
 * /main/ms-d/2   2006-11-02 14:59:15   mp49210
 * No *#-sequences in HC25
 *
 * /main/ms-d/1   2006-10-25 16:52:09   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 SECUR_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 SECUR_CMDBUF_LENGTH      (MAX_PATH + 2 * MAXLENGTH_PASSWORD)

// Maximum length of the PIN password.
// Note: it is necessary to have at least 256 bytes to handle PIN encryption
#define MAXLEN_PIN      256
// Maximum length of the PIN2 password.
#define MAXLEN_PIN2     256

// Constant PH_NET PIN on the HC25 Release 2
#define HC25_R2_PHNET_PIN     60351838

// Buffer size to hold IMEI information
#define IMEI_BUFFER_LEN  16
#define EXPECTED_IMEI_LEN  15

//
// Locked states
//
// Remark: the PH-NET PIN dialog requires Windows Mobile 6.5.
//
const LPCSTR g_rgszLockedStates[] =
{
    "",                 // RIL_LOCKEDSTATE_UNKNOWN
    "READY",            // RIL_LOCKEDSTATE_READY
    "SIM PIN",          // RIL_LOCKEDSTATE_SIM_PIN
    "SIM PUK",          // RIL_LOCKEDSTATE_SIM_PUK
    "PH-SIM PIN",       // RIL_LOCKEDSTATE_PH_SIM_PIN
    "PH-FSIM PIN",      // RIL_LOCKEDSTATE_PH_FSIM_PIN
    "PH-FSIM PUK",      // RIL_LOCKEDSTATE_PH_FSIM_PUK
    "SIM PIN2",         // RIL_LOCKEDSTATE_SIM_PIN2
    "SIM PUK2",         // RIL_LOCKEDSTATE_SIM_PUK2
    "PH-NET PIN",       // RIL_LOCKEDSTATE_PH_NET_PIN
    "PH-NET PUK",       // RIL_LOCKEDSTATE_PH_NET_PUK
    "PH-NETSUB PIN",    // RIL_LOCKEDSTATE_PH_NETSUB_PIN
    "PH-NETSUB PUK",    // RIL_LOCKEDSTATE_PH_NETSUB_PUK
    "PH-SP PIN",        // RIL_LOCKEDSTATE_PH_SP_PIN
    "PH-SP PUK",        // RIL_LOCKEDSTATE_PH_SP_PUK
    "PH-CORP PIN",      // RIL_LOCKEDSTATE_PH_CORP_PIN
    "PH-CORP PUK",      // RIL_LOCKEDSTATE_PH_COPR_PUK
};
#define NUM_LOCKEDSTATES     (sizeof(g_rgszLockedStates) / sizeof(LPCSTR) - 1)


//
// Lock facilities
//
static const LPCSTR g_rgszLockFacilities[] =
{
    "",     // 0
    "CS",   // RIL_LOCKFACILITY_CNTRL
    "PS",   // RIL_LOCKFACILITY_PH_SIM
    "PF",   // RIL_LOCKFACILITY_PH_FSIM
    "SC",   // RIL_LOCKFACILITY_SIM
    "P2",   // RIL_LOCKFACILITY_SIM_PIN2
    "FD",   // RIL_LOCKFACILITY_SIM_FIXEDIALING
    "PN",   // RIL_LOCKFACILITY_NETWORKPERS
    "PU",   // RIL_LOCKFACILITY_NETWORKSUBPERS
    "PP",   // RIL_LOCKFACILITY_SERVICEPROVPERS
    "PC",   // RIL_LOCKFACILITY_CORPPERS

};
#define NUM_LOCKFACILITIES    (sizeof(g_rgszLockFacilities) / sizeof(LPCSTR))


//
// Call barring types
//
static const LPCSTR g_rgszBarringTypes[] =
{
    "",     // 0
    "AO",   // RIL_BARRTYPE_ALLOUTGOING
    "OI",   // RIL_BARRTYPE_OUTGOINGINT
    "OX",   // RIL_BARRTYPE_OUTGOINGINTEXTOHOME
    "AI",   // RIL_BARRTYPE_ALLINCOMING
    "IR",   // RIL_BARRTYPE_INCOMINGROAMING
    "NS",   // RIL_BARRTYPE_INCOMINGNOTINSIM
    "AB",   // RIL_BARRTYPE_ALLBARRING
    "AG",   // RIL_BARRTYPE_ALLOUTGOINGBARRING
    "AC",   // RIL_BARRTYPE_ALLINCOMINGBARRING

};
#define NUM_BARRINGTYPES    (sizeof(g_rgszBarringTypes) / sizeof(LPCSTR))

//
// Translation table Barring Type -> *#-Code
//
#define RIL_BARRINGSTATUS_QUERY                   (0x000000FF)

struct BARRING2ATD
{
    DWORD dwBarringType;
    DWORD dwBarringStatus;
    char  szATD[8];
};

static const BARRING2ATD g_rgBarringTypeTable[] =
{
    {RIL_BARRTYPE_ALLOUTGOING, RIL_BARRINGSTATUS_ENABLED,  "*33"},
    {RIL_BARRTYPE_ALLOUTGOING, RIL_BARRINGSTATUS_DISABLED, "#33"},
    {RIL_BARRTYPE_ALLOUTGOING, RIL_BARRINGSTATUS_QUERY,    "*#33"},
    {RIL_BARRTYPE_OUTGOINGINT, RIL_BARRINGSTATUS_ENABLED,  "*331"},
    {RIL_BARRTYPE_OUTGOINGINT, RIL_BARRINGSTATUS_DISABLED, "#331"},
    {RIL_BARRTYPE_OUTGOINGINT, RIL_BARRINGSTATUS_QUERY,     "*#331"},
    {RIL_BARRTYPE_OUTGOINGINTEXTOHOME, RIL_BARRINGSTATUS_ENABLED,  "*332"},
    {RIL_BARRTYPE_OUTGOINGINTEXTOHOME, RIL_BARRINGSTATUS_DISABLED, "#332"},
    {RIL_BARRTYPE_OUTGOINGINTEXTOHOME, RIL_BARRINGSTATUS_QUERY,    "*#332"},
    {RIL_BARRTYPE_ALLINCOMING, RIL_BARRINGSTATUS_ENABLED,  "*35"},
    {RIL_BARRTYPE_ALLINCOMING, RIL_BARRINGSTATUS_DISABLED, "#35"},
    {RIL_BARRTYPE_ALLINCOMING, RIL_BARRINGSTATUS_QUERY,    "*#35"},
    {RIL_BARRTYPE_INCOMINGROAMING, RIL_BARRINGSTATUS_ENABLED,  "*351"},
    {RIL_BARRTYPE_INCOMINGROAMING, RIL_BARRINGSTATUS_DISABLED, "#351"},
    {RIL_BARRTYPE_INCOMINGROAMING, RIL_BARRINGSTATUS_QUERY,    "*#351"},
    {RIL_BARRTYPE_ALLBARRING, RIL_BARRINGSTATUS_DISABLED, "#330"},
    {RIL_BARRTYPE_ALLOUTGOINGBARRING, RIL_BARRINGSTATUS_DISABLED, "#333"},
    {RIL_BARRTYPE_ALLINCOMINGBARRING, RIL_BARRINGSTATUS_DISABLED, "#353"}
};
#define NUM_BARRING_VALUES    (sizeof(g_rgBarringTypeTable) / sizeof(BARRING2ATD))

// Error translation: the HC25 returns 'SIM failure' to AT+CPIN?, when actually 'SIM not inserted' would be correct.
extern const CME_TRANSLATION g_CMET_CPINNoSIM[];
// Error translation: the HC25 returns 'SIM failure' to AT+CPIN?, when actually 'SIM not inserted' would be correct.
extern const CME_TRANSLATION g_CMET_CPINWithSIM[];


HRESULT RILDrv_GetUserIdentity(DWORD dwParam);
HRESULT RILDrv_GetPhoneLockedState(DWORD dwParam);
HRESULT RILDrv_UnlockPhone(DWORD dwParam, LPCSTR lpszPassword, LPCSTR lpszNewPassword);
HRESULT RILDrv_GetLockingStatus(DWORD dwParam, DWORD dwFacility, LPCSTR lpszPassword);
HRESULT RILDrv_SetLockingStatus(DWORD dwParam, DWORD dwFacility, LPCSTR lpszPassword, DWORD dwStatus);
HRESULT RILDrv_ChangeLockingPassword(DWORD dwParam, DWORD dwFacility, DWORD dwOldPasswordType, LPCSTR lpszOldPassword, LPCSTR lpszNewPassword);
HRESULT RILDrv_GetCallBarringStatus(DWORD dwParam, DWORD dwType, DWORD dwInfoClass, LPCSTR lpszPassword);
HRESULT RILDrv_SetCallBarringStatus(DWORD dwParam, DWORD dwType, DWORD dwInfoClass, LPCSTR lpszPassword, DWORD dwStatus);
HRESULT RILDrv_ChangeCallBarringPassword(DWORD dwParam, DWORD dwType, LPCSTR lpszOldPassword, LPCSTR lpszNewPassword);
#if defined (IOCTL_RIL_CHANGECALLBARRINGPASSWORDEX)
HRESULT RILDrv_ChangeCallBarringPasswordEx(DWORD dwParam, DWORD dwType, LPCSTR lpszOldPassword, LPCSTR lpszNewPassword, LPCSTR lpszNewPasswordConfirm);
#endif

HRESULT ParseGetPhoneLockedState(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID /*pParam*/);
HRESULT ParseGetLockingStatus(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
HRESULT ParseSCKSResponse(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
HRESULT ParseGetIMEIInfo(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
HRESULT ParseCPINError(LPCSTR szRsp, void*& /*pBlob*/, UINT& /*cbBlob*/, LPVOID pParam, DWORD& /*dwCode*/);
HRESULT ParseGetUserIdentity(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);


UINT GenerateHC25SIMLockPin(LPCSTR szIMEI);
void ResetSecurityStates(void);

