/*****************************************************************************
 * Copyright (C) Gemalto M2M GmbH
 *****************************************************************************
 * Project: IMC-RIL-Driver
 *****************************************************************************
 * Author : Wireless Modules RD SW A2
 *****************************************************************************
 * $Workfile: Y:/z_ms-d/src/working/Quinn/RilDrv/rilhand.h $
 * $Revision: /main/ms-d/128 $
 *     $Date: 2014-06-19 16:51:00 $
 *   $Author: pmackent $
 *****************************************************************************
 * Target:
 *  Microsoft Windows Mobile 5.0
 *****************************************************************************
 * Description:
 *  Gemalto IMC RIL
 *****************************************************************************
 *
 * $Log: Y:/z_ms-d/src/working/Quinn/RilDrv/rilhand.h$ 
 * 
 * /main/ms-d/128   2014-06-19 16:51:00   pmackent 
 * Fix exception in RIL_GetCurrentSystemType() (IPIS100097887)
 *
 * /main/ms-d/127   2014-05-26 16:30:15   pmackent
 * Correction for incorrectly reported system type while module is in CDMA mode and in no-coverage area (IPIS100097887)
 *
 * /main/ms-d/126   2014-05-08 10:31:53   pmackent
 * Move AT^SAIC to RIL initialization (IPIS100096235)
 *
 * /main/ms-d/125   2014-02-13 11:26:08   pmackent
 * Fix for problems with CE7 2-way-calls
 *
 * /main/ms-d/124   2013-12-02 14:25:57   pmackent
 * Set signal strength thersholds via registry
 *
 * /main/ms-d/123   2013-09-25 15:21:48   pmackent
 * New methods for signal strength display in 3G networks (IPIS100091577)
 *
 * /main/ms-d/122   2013-09-13 09:27:25   pmackent
 * Cell Broadcast for CDMA (IPIS100091379)
 *
 * /main/ms-d/121   2013-08-21 13:18:01   pmackent
 * Sprint: warning for roaming costs (IPIS100090678)
 *
 * /main/ms-d/120   2013-06-27 15:59:58   pmackent
 * Adaptions for EHS5 Rel1->Rel2 update
 *
 * /main/ms-d/119   2013-05-23 11:55:59   pmackent
 * Handle AT^SCFG and AT^SGPSC in one function
 *
 * /main/ms-d/118   2013-05-17 14:59:11   pmackent
 * Make technology switch thread-safe
 *
 * /main/ms-d/117   2013-05-14 14:35:10   pmackent
 * Option to activate OMALOG in Sprint (IPIS100087489)
 *
 * /main/ms-d/116   2013-05-13 15:24:00   pmackent
 * Store NITZ DST settings (IPIS100087449)
 *
 * /main/ms-d/115   2013-05-13 14:12:18   pmackent
 * Optional alternative handling of AT+CDV response (IPIS100087446)
 *
 * /main/ms-d/114   2013-05-07 14:16:52   pmackent
 * New GPIO setting in EHS5
 *
 * /main/ms-d/113   2013-04-05 09:53:48   pmackent
 * Finish EHS5 Java midlet update
 * Add RHA-API for bootloader pin on EHS5
 *
 * /main/ms-d/112   2013-03-21 14:40:56   pmackent
 * Don't store T/P dial modifiers
 *
 * /main/ms-d/111   2013-03-15 14:09:14   pmackent
 * Start introducing Java update for EHS5
 *
 * /main/ms-d/110   2013-03-05 11:33:25   pmackent
 * Handle ^SYSSTART URC for EHS5 Rel2
 *
 * /main/ms-d/109   2013-03-04 13:19:56   pmackent
 * Adaptions for EHS5 1.300
 *
 * /main/ms-d/108   2013-02-27 15:18:05   pmackent
 * Introduce provider spezific PRL update
 *
 * /main/ms-d/107   2013-02-26 15:07:55   pmackent
 * Adaptions for EHS5 1.290
 *
 * /main/ms-d/106   2013-01-16 11:28:49   pmackent
 * Introduce update of module file system
 *
 * /main/ms-d/105   2013-01-14 10:33:35   pmackent
 * Allow update of multiple NV items
 *
 * /main/ms-d/104   2012-12-21 13:09:07   pmackent
 * Introduce NV item update
 *
 * /main/ms-d/103   2012-12-12 15:24:27   pmackent
 * Workarounds for bugs in PXS8 2.821
 *
 * /main/ms-d/102   2012-11-22 10:34:30   pmackent
 * Workaround: no AT+GMM in EHS5, no AT+CGMM in PXS8 (CDMA)
 *
 * /main/ms-d/101   2012-11-19 15:29:09   pmackent
 * No AT+CSQ in D3 is now optional
 *
 * /main/ms-d/100   2012-11-13 13:52:54   pmackent
 * New option: reser of acquisition database (IPIS100083325)
 *
 * /main/ms-d/99   2012-10-17 15:23:02   pmackent
 * Fix for missing NITZ/CCLK in CDMA mode (IPIS100082923)
 *
 * /main/ms-d/98   2012-09-25 10:26:32   pmackent
 * Workaround for double CDMA activation URC
 *
 * /main/ms-d/97   2012-07-11 15:28:40   pmackent
 * Introduce PRI update
 *
 * /main/ms-d/96   2012-07-05 10:12:16   pmackent
 * Introduce loading of network provider list
 *
 * /main/ms-d/95   2012-06-21 13:16:26   pmackent
 * Introduce CDMA PRL list update
 *
 * /main/ms-d/94   2012-06-13 10:44:04   pmackent
 * Added support for CDMA flash
 *
 * /main/ms-d/93   2012-06-08 16:59:30   pmackent
 * Add APIs for CDMA voice privacy
 *
 * /main/ms-d/92   2012-06-07 13:59:03   pmackent
 * Adaptions for multimode
 * Workaround for CREG=0 bug in PXS8
 *
 * /main/ms-d/91   2012-04-26 13:02:29   pmackent
 * Further CDMA specific code
 *
 * /main/ms-d/90   2012-02-22 13:27:12   ctna0256
 * Encapsulate use of Intel AT command set
 *
 * /main/ms-d/89   2012-02-03 15:07:33   ctna0256
 * Move URC parsing functions in separate file
 *
 * /main/ms-d/88   2012-02-03 14:00:59   ctna0256
 * Phonebook and SIM access now in separate files
 *
 * /main/ms-d/87   2012-01-31 16:38:56   ctna0256
 * Added support for EHS5
 *
 * /main/ms-d/86   2012-01-17 10:22:32   ctna0256
 * Workaround for wrong indication of "+CIEV: psinfo,6" (IPIS100076880)
 *
 * /main/ms-d/85   2012-01-12 15:22:51   ctna0256
 * Some basic CDMA adaptions
 *
 * /main/ms-d/84   2012-01-05 14:56:42   ctna0256
 * New RHA-API for CDMA/UMTS technology switch
 *
 * /main/ms-d/83   2012-01-04 15:37:03   ctna0256
 * Outsource XML configuration to external application.
 * Improve CDMA configuration mode.
 *
 * /main/ms-d/82   2012-01-03 15:46:50   ctna0256
 * Introduce PXS8
 *
 * /main/ms-d/81   2011-09-12 14:50:39   ctna0256
 * New GPS test mode for PH8 R2
 *
 * /main/ms-d/80   2011-07-22 11:29:02   ctna0256
 * Filter out "searching" extended notification (IPIS100073242)
 *
 * /main/ms-d/79   2011-07-20 13:01:49   ctna0256
 * Introduce RIL_NOTIFY_DEVSPECIFIC_NETWORK_REJECT_CAUSE and prevent multiple notifications (IPIS100073123)
 *
 * /main/ms-d/78   2011-06-17 10:41:12   ctna0256
 * New API for extended registration status (IPIS100073242)
 *
 * /main/ms-d/77   2011-03-17 10:07:49   ctna0256
 * Abort dial attempt for emergency calls after timeout (IPIS100070746)
 *
 * /main/ms-d/76   2011-02-15 15:17:18   ctna0256
 * Merge SCKS-WA registry key from Psion
 *
 * /main/ms-d/75   2010-12-22 14:31:27   ctna0256
 * No auto-reboot after emergency shutdown
 *
 * /main/ms-d/74   2010-12-15 17:08:25   ctna0256
 * Restart on GPRS-Attach config change
 *
 * /main/ms-d/73   2010-12-14 10:15:11   ctna0256
 * Fix problem with restart on changed settings and resets on SAD
 *
 * /main/ms-d/72   2010-12-13 16:07:03   ctna0256
 * Allow automatic restart on configuration changes
 *
 * /main/ms-d/71   2010-11-26 10:26:26   ctna0256
 * Introducing firmware update for PH8
 *
 * /main/ms-d/70   2010-11-16 13:42:29   ctna0256
 * SCFG setting: write setting only, if changed
 *
 * /main/ms-d/69   2010-11-04 15:47:07   ctna0256
 * New configuration of SDPORT, C-IMEI and SVN
 *
 * /main/ms-d/68   2010-10-26 10:22:29   ctna0256
 * Use SIM path for all CRSM commands
 *
 * /main/ms-d/67   2010-09-21 13:12:51   ctna0256
 * No phonebook access after enabling PIN on PH8 customer sample
 *
 * /main/ms-d/66   2010-08-19 14:30:09   ctna0256
 * Implementation A-GPS for PH8
 *
 * /main/ms-d/65   2010-08-18 10:23:18   ctna0450
 * Added Telstra Home-Net workaround
 *
 * /main/ms-d/64   2010-07-21 09:14:56   ctna0256
 * No audio for CSD dialing option
 *
 * /main/ms-d/63   2010-04-30 15:29:14   ctna0256
 * Automatically switch to 2G for CSD connections (IPIS100064182)
 *
 * /main/ms-d/62   2010-01-26 09:55:41   ctna0256
 * New API: RIL_GetPositionInfo()
 *
 * /main/ms-d/61   2009-10-07 09:22:24   ctna0256
 * Introduce no-operation command queue
 * Support 2nd alpha identifier in SAT setup call (IPIS100055375)
 *
 * /main/ms-d/60   2009-07-28 10:40:53   ctna0256
 * Better handling of the case "suspend during initialization" (IPIS100056850)
 *
 * /main/ms-d/59   2009-07-13 09:24:57   ctna0256
 * Read-IMSI-Workaround only after PIN (IPIS100056758)
 *
 * /main/ms-d/58   2009-07-06 09:56:16   ctna0256
 * Workaround for wrong busy tone (IPIS100056689)
 *
 * /main/ms-d/57   2009-06-18 16:17:28   ctna0256
 * Alllow paket data even while initialization
 *
 * /main/ms-d/56   2009-05-27 10:04:59   ctna0256
 * Deregister module in PUK blocked state caused by wrong PIN change
 *
 * /main/ms-d/55   2009-02-18 09:39:52   ctna0256
 * New WM65 API
 *
 * /main/ms-d/54   2008-10-21 15:05:18   ctna0256
 * Registry key to force use of AT+CSQ
 *
 * /main/ms-d/53   2008-10-06 16:04:18   ctna0256
 * New options: Disable SMS completely; Use SMS reply address
 *
 * /main/ms-d/52   2008-09-23 16:15:03   ctna0256
 * Mute during VTS (optional)
 *
 * /main/ms-d/51   2008-08-27 11:39:03   ctna0256
 * Optional filter of Type 0 SMS
 *
 * /main/ms-d/50   2008-08-26 14:26:53   ctna0256
 * Merged RIL_RADIO_RESILIENCE option from Classic-RIL
 *
 * /main/ms-d/49   2008-08-22 10:27:20   ctna0256
 * Set Cinterion copyright text
 *
 * /main/ms-d/48   2008-08-21 09:35:18   ctna0256
 * Prepared for new disclaimer handling
 *
 * /main/ms-d/47   2008-06-12 15:00:30   mp49210
 * Block writing to phonebook during calls, if there had been an incoming call without number
 *
 * /main/ms-d/46   2008-06-06 15:31:13   mp49210
 * Handling of additional CPOL parameters
 *
 * /main/ms-d/45   2008-05-26 09:00:14   mp49210
 * Synchronize module time with system time
 *
 * /main/ms-d/44   2008-05-15 15:02:11   mp49210
 * Use ECC configuration from radio
 *
 * /main/ms-d/43   2008-05-06 08:21:57   mp49210
 * No inline for RHA_IsRadioPwrOn()
 *
 * /main/ms-d/42   2008-05-05 10:28:09   mp49210
 * Handling of SIM not inserted after SMS retries (Workaround for CCIN pin for SIM card detection)
 *
 * /main/ms-d/41   2008-04-29 13:38:07   mp49210
 * Workaround for missing simstatus URC.
 * New handling of SIM reset.
 *
 * /main/ms-d/40   2008-04-21 08:16:50   mp49210
 * Handling of AT&Ts network selection menue change
 *
 * /main/ms-d/39   2008-04-16 16:24:24   mp49210
 * Debug zones for RHA traces
 *
 * /main/ms-d/38   2008-02-08 13:14:06   mp49210
 * Prevent start of module, if IMEI is missing
 *
 * /main/ms-d/37   2007-12-11 16:22:17   mp49210
 * Read debug options from registry at attach of rilgsm.dll
 *
 * /main/ms-d/36   2007-11-26 17:05:53   kr36712
 * integration of GPS support
 * use of the mux protocol
 *
 * /main/ms-d/35   2007-11-23 15:27:51   mp49210
 * Compatibility SAT Play Tone to Classic RIL
 *
 * /main/ms-d/34   2007-11-21 13:35:09   mp49210
 * Lint compatibility
 *
 * /main/ms-d/33   2007-09-21 10:29:37   mp49210
 * Introduction WM6 specific AcT selection (optional)
 *
 * /main/ms-d/32   2007-09-12 13:34:21   mp49210
 * Configure SIM initialization timeout with registry key
 *
 * /main/ms-d/31   2007-08-10 16:56:09   mp49210
 * IPIS100040302: send AT+CSIM after AT+CPIN?
 *
 * /main/ms-d/30   2007-08-08 11:16:50   mp49210
 * Introduction of audio profile download
 *
 * /main/ms-d/29   2007-07-06 10:13:57   mp49210
 * Lint compatibility
 *
 * /main/ms-d/28   2007-07-04 08:57:22   mp49210
 * Introduction of maximum trace file length
 *
 * /main/ms-d/27   2007-07-04 07:32:03   mp49210
 * Introduction of radio band group search
 *
 * /main/ms-d/26   2007-05-25 11:45:55   mp49210
 * New APPID for AT^SCFG command
 *
 * /main/ms-d/25   2007-05-02 10:26:19   mp49210
 * New registry key "NoRoaming Indicator"
 *
 * /main/ms-d/24   2007-04-27 08:34:00   mp49210
 * Removed Lint warnings
 *
 * /main/ms-d/23   2007-04-24 15:58:23   mp49210
 * IPIS100035501: introduction of list of networks (registry), where the RIL should not send the roaming status
 *
 * /main/ms-d/22   2007-03-28 13:48:10   mp49210
 * Remove 'Classic RIL' specific code and comments
 *
 * /main/ms-d/21   2007-03-28 10:42:06   mp49210
 * Store CLIR value persistent
 *
 * /main/ms-d/20   2007-02-23 10:34:19   mp49210
 * Workaround for AT+CSCA is not needed any more
 *
 * /main/ms-d/19   2007-02-22 16:44:30   mp49210
 * Workaround for unusable AT+CRSM=242 on USIMs
 *
 * /main/ms-d/18   2007-02-21 13:49:59   mp49210
 * HC25 no longer supports AT^SBC
 *
 * /main/ms-d/17   2007-02-16 10:05:32   mp49210
 * Handle error causes for GCF approval
 *
 * /main/ms-d/16   2007-02-09 15:15:23   mp49210
 * Lint compatibility
 *
 * /main/ms-d/15   2007-01-31 17:00:05   mp49210
 * Changed handling of cell broadcast messages to pass Crossbow radiometrics.exe
 *
 * /main/ms-d/14   2007-01-22 16:18:30   wm36264
 * Removed workaround for failing 1st at command after data mode
 *
 * /main/ms-d/13   2007-01-03 17:04:29   mp49210
 * Replace +CIEV: sounder with +CIEV: audio
 *
 * /main/ms-d/12   2006-12-19 18:13:07   mp49210
 * Some changes for commands used during initialization
 *
 * /main/ms-d/11   2006-12-19 11:34:53   mp49210
 * Addotions for AT^SIND=psinfo
 *
 * /main/ms-d/10   2006-12-15 16:40:14   mp49210
 * Workaorund for volatile CSCA setting
 *
 * /main/ms-d/9   2006-11-22 15:43:14   wm36264
 * Avoid obsolete new/delete cycles
 *
 * /main/ms-d/8   2006-11-21 09:02:11   mp49210
 * New GPRS auto attach mechanism
 *
 * /main/ms-d/7   2006-11-14 17:00:01   wm36264
 * Tidy up more unused stuff
 *
 * /main/ms-d/6   2006-11-14 12:49:21   wm36264
 * Updated trace stuff due to global trace handling
 *
 * /main/ms-d/5   2006-11-13 11:53:55   wm36264
 * Added workaround for failing 1st cmd after data mode
 *
 * /main/ms-d/4   2006-11-10 12:50:01   wm36264
 * Simplyfied "Wait for Response" mechanism
 *
 * /main/ms-d/3   2006-11-09 14:24:37   mp49210
 * Quinn specific feature: selction of 2G / 3G network
 *
 * /main/ms-d/2   2006-11-01 10:29:38   mp49210
 * New AT+CFUN handling in Quinn
 *
 * /main/ms-d/1   2006-10-25 16:51:46   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 DEFAULT_COM_MASK (EV_RXCHAR | EV_RLSD | EV_ERR | EV_BREAK)

// Default API timeout (in msec)
#define TIMEOUT_API_DEFAULT         20000
#define TIMEOUT_CMD_INIT            20000

// Timeout (in ms) for SIM initialization
#define SIMINIT_TIMEOUT             150000
#define SIMINIT_TIMEOUT_INTEL       30000

// Timeout for +CIEV: audio URC after SAT Play Tone command
#define SATPLAYTONEAUDIO_TIMEOUT    1500

// Maximum length of cell broadcast message channel list
#define MAX_CBM_STRING              128

// Maximum length of a CDMA provider name
#define MAX_CDMA_PROVIDER_NAME_LEN   64

// Maximum numbers of 'No Roaming' networks
#define MAX_NUMBER_OF_NOROAMINGNETWORKS   10

// Polling interval (in ms) used for checking for SIM initialization.
#define SIM_INIT_POLLING_INTERVAL  3000

// Number of retries for SIM status (SIM PIN / READY / SIM not inserted)
#define MAX_SIM_READY_TRIES_DEFAULT 20
#define SIM_READY_RETRY_INTERVAL  2000

// See WRONG_BUSY_TONE_AFTER_CHLD: timeout after AT+CHLD=0
// after which the next audio tone must be ignored.
#define CHLD0BUSYTONE_TIMEOUT 1500

// Define needed for RIL_NOTIFY_DEVSPECIFIC_REGSTATUS_EX
#define SMONI_STATE_UNKNOWN  0
#define SMONI_STATE_LIMITED_SERVICE  1
#define SMONI_STATE_SEARCHING  2

// Different methods to determine the signal strength in 3G:
// RSSI: RSSI as returned by AT+CSQ
// ECN0: Combination from EC/D0 and RSCP (AT^SMONI)
// RSCP: RSCP only (AT^SMONI)
#define SS_3G_RSSI   0
#define SS_3G_ECN0   1
#define SS_3G_RSCP   2

// Different methods to determine the signal strength in LTE:
// RSSI: RSSI as returned by AT+CSQ
// RSRQ: Combination from RSRQ and RSRP (AT^SMONI)
// RSRP: RSRP only (AT^SMONI)
#define SS_LTE_RSSI   0
#define SS_LTE_RSRQ   1
#define SS_LTE_RSRP   2

//For parsing SWUP configuration file.
#define OPERATION_CMD_INSTALL   "install"
#define OPERATION_CMD_DEPLOY    "deploy"
#define OPERATION_CMD_SAVE      "save"
#define OPERATION_CMD_FCREATE   "fcreate"
#define OPERATION_CMD_FSAVE     "fsave"
#define OPERATION_CMD_FDELETE   "fdel"
#define OPERATION_MIDLET_INSTALL 1
#define OPERATION_MIDLET_DEPLOY 2
#define OPERATION_MIDLET_SAVE 4
#define OPERATION_FILE_CREATE 8
#define OPERATION_FILE_SAVE 16
#define OPERATION_FILE_DELETE 32
#define MAX_VALUE_AMOUNT 10

// Buffer to hold a SCFG setting.
#define MAX_SCFG_SETTING_LEN  32

// Forward declarations
class CRilInstanceHandle;
class CComHandle;
class CMonitor;
class CSimToolkitHandling;
class CEonsHandling;
class CForceHomeNet;

// API IDs
// WARNING: If you add or remove entries from this table,
// you MUST synchronize the change with the table in the registry
// which holds perf/timeout information about each API.
// Held in HKEY_LOCAL_MACHINE\Software\Microsoft\RIL\APIInfo\<ApiEnumId>

enum APIID {
    APIID_NONE                          = -1,
    APIID_GETSUBSCRIBERNUMBERS          = 0,
    APIID_GETOPERATORLIST,              // 1
    APIID_GETPREFERREDOPERATORLIST,     // 2
    APIID_ADDPREFERREDOPERATOR,         // 3
    APIID_REMOVEPREFERREDOPERATOR,      // 4
    APIID_GETCURRENTOPERATOR,           // 5
    APIID_REGISTERONNETWORK,            // 6
    APIID_UNREGISTERFROMNETWORK,        // 7
    APIID_GETREGISTRATIONSTATUS,        // 8
    APIID_GETCALLERIDSETTINGS,          // 9
    APIID_SETCALLERIDSTATUS,            // 10
    APIID_GETHIDEIDSETTINGS,            // 11
    APIID_SETHIDEIDSTATUS,              // 12
    APIID_GETDIALEDIDSETTINGS,          // 13
    APIID_SETDIALEDIDSTATUS,            // 14
    APIID_GETCLOSEDGROUPSETTINGS,       // 15
    APIID_SETCLOSEDGROUPSETTINGS,       // 16
    APIID_GETCALLFORWARDINGSETTINGS,    // 17
    APIID_ADDCALLFORWARDING,            // 18
    APIID_REMOVECALLFORWARDING,         // 19
    APIID_SETCALLFORWARDINGSTATUS,      // 20
    APIID_GETCALLWAITINGSETTINGS,       // 21
    APIID_SETCALLWAITINGSTATUS,         // 22
    APIID_SENDSUPSERVICEDATA,           // 23
    APIID_CANCELSUPSERVICEDATASESSION,  // 24
    APIID_DIAL,                         // 25
    APIID_ANSWER,                       // 26
    APIID_HANGUP,                       // 27
    APIID_SENDDTMF,                     // 28
    APIID_SETDTMFMONITORING,            // 29
    APIID_GETCALLLIST,                  // 30
    APIID_MANAGECALLS,                  // 31
    APIID_TRANSFERCALL,                 // 32
    APIID_GETLINESTATUS,                // 33
    APIID_GETAUDIOGAIN,                 // 34
    APIID_SETAUDIOGAIN,                 // 35
    APIID_GETAUDIODEVICES,              // 36
    APIID_SETAUDIODEVICES,              // 37
    APIID_GETAUDIOMUTING,               // 38
    APIID_SETAUDIOMUTING,               // 39
    APIID_GETHSCSDOPTIONS,              // 40
    APIID_SETHSCSDOPTIONS,              // 41
    APIID_GETHSCSDCALLSETTINGS,         // 42
    APIID_GETDATACOMPRESSION,           // 43
    APIID_SETDATACOMPRESSION,           // 44
    APIID_GETERRORCORRECTION,           // 45
    APIID_SETERRORCORRECTION,           // 46
    APIID_GETBEARERSERVICEOPTIONS,      // 47
    APIID_SETBEARERSERVICEOPTIONS,      // 48
    APIID_GETRLPOPTIONS,                // 49
    APIID_SETRLPOPTIONS,                // 50
    APIID_GETMSGSERVICEOPTIONS,         // 51
    APIID_SETMSGSERVICEOPTIONS,         // 52
    APIID_GETMSGCONFIG,                 // 53
    APIID_SETMSGCONFIG,                 // 54
    APIID_RESTOREMSGCONFIG,             // 55
    APIID_SAVEMSGCONFIG,                // 56
    APIID_READMSG,                      // 57
    APIID_DELETEMSG,                    // 58
    APIID_WRITEMSG,                     // 59
    APIID_SENDMSG,                      // 60
    APIID_SENDSTOREDMSG,                // 61
    APIID_SENDMSGACKNOWLEDGEMENT,       // 62
    APIID_GETUSERIDENTITY,              // 63
    APIID_GETPHONELOCKEDSTATE,          // 64
    APIID_UNLOCKPHONE,                  // 65
    APIID_GETLOCKINGSTATUS,             // 66
    APIID_SETLOCKINGSTATUS,             // 67
    APIID_CHANGELOCKINGPASSWORD,        // 68
    APIID_GETCALLBARRINGSTATUS,         // 69
    APIID_SETCALLBARRINGSTATUS,         // 70
    APIID_CHANGECALLBARRINGPASSWORD,    // 71
    APIID_GETEQUIPMENTINFO,             // 72
    APIID_GETEQUIPMENTSTATE,            // 73
    APIID_SETEQUIPMENTSTATE,            // 74
    APIID_GETPHONEBOOKOPTIONS,          // 75
    APIID_SETPHONEBOOKOPTIONS,          // 76
    APIID_READPHONEBOOKENTRIES,         // 77
    APIID_WRITEPHONEBOOKENTRY,          // 78
    APIID_DELETEPHONEBOOKENTRY,         // 79
    APIID_SENDSIMCMD,                   // 80
    APIID_SENDRESTRICTEDSIMCMD,         // 81
    APIID_GETSIMRECORDSTATUS,           // 82
    APIID_GETSIMTOOLKITPROFILE,         // 83
    APIID_SETSIMTOOLKITPROFILE,         // 84
    APIID_SENDSIMTOOLKITENVELOPECMD,    // 85
    APIID_FETCHSIMTOOLKITCMD,           // 86
    APIID_SENDSIMTOOLKITCMDRESPONSE,    // 87
    APIID_TERMINATESIMTOOLKITSESSION,   // 88
    APIID_GETCOSTINFO,                  // 89
    APIID_SETCOSTINFO,                  // 90
    APIID_GETSIGNALQUALITY,             // 91
    APIID_GETCELLTOWERINFO,             // 92
    APIID_DEVSPECIFIC,                  // 93
    APIID_GETDEVCAPS,                   // 94
    APIID_GETHIDECONNECTEDIDSETTINGS,   // 95
    APIID_SETHIDECONNECTEDIDSTATUS,     // 96
    APIID_GETUUSREQUIREDSTATUS,         // 97
    APIID_CLEARCCBSREGISTRATION,        // 98
    APIID_GETSYSTEMTIME,                    // 99
    APIID_GETGPRSCONTEXTLIST,               // 100
    APIID_SETGPRSCONTEXT,                   // 101
    APIID_DELETEGPRSCONTEXT,                // 102
    APIID_GETREQUESTEDQUALITYOFSERVICELIST, // 103
    APIID_SETREQUESTEDQUALITYOFSERVICE,     // 104
    APIID_DELETEREQUESTEDQUALITYOFSERVICE,  // 105
    APIID_GETMINIMUMQUALITYOFSERVICELIST,   // 106
    APIID_SETMINIMUMQUALITYOFSERVICE,       // 107
    APIID_DELETEMINIMUMQUALITYOFSERVICE,    // 108
    APIID_SETGPRSATTACHED,                  // 109
    APIID_GETGPRSATTACHED,                  // 110
    APIID_SETGPRSCONTEXTACTIVATED,          // 111
    APIID_GETGPRSCONTEXTACTIVATEDLIST,      // 112
    APIID_ENTERGPRSDATAMODE,                // 113
    APIID_GETGPRSADDRESS,                   // 114
    APIID_GPRSANSWER,                       // 115
    APIID_GETGPRSREGISTRATIONSTATUS,        // 116
    APIID_GETGPRSCLASS,                     // 117
    APIID_SETGPRSCLASS,                     // 118
    APIID_GETMOSMSSERVICE,                  // 119
    APIID_SETMOSMSSERVICE,                  // 120
    APIID_GETCBMSGCONFIG,                   // 121
    APIID_SETCBMSGCONFIG,                   // 122
    APIID_GETCURRENTADDRESSID,              // 123
    APIID_SETCURRENTADDRESSID,              // 124
    APIID_GETPACKETBYTECOUNT,               // 125
    APIID_RESETPACKETBYTECOUNT,             // 126
    APIID_GETCURRENTPRIVACYSTATUS,          // 127
    APIID_GETCURRENTSYSTEMTYPE,             // 128
    APIID_GETALLOPERATORSLIST,              // 129
    APIID_SETINITIALGPRSATTACHED,           // 130
    APIID_ENABLEDISABLEURCS,                // 131
    APIID_SAP,                              // 132
    APIID_QUERYUNREADSMS,                   // 133
    APIID_QUERYCEERERROR,                   // 134
    APIID_SCFGRADIOBAND,                    // 135
    APIID_SETRADIOCLOCK,                    // 136
    APIID_GETSMSNLTABLELIST,                // 137
    APIID_GETPOSITIONINFO,                  // 138
    APIID_UPLOAD_AGPS,                      // 139
    APIID_DELETE_AGPS,                      // 140
    APIID_GETROAMINGMODE,                   // 141
    APIID_SETROAMINGMODE,                   // 142
    APIID_GETPREFERREDPRIVACYMODE,          // 143
    APIID_SETPREFERREDPRIVACYMODE,          // 144
    APIID_SENDFLASH,                        // 145
	APIID_GETIMSREGISTRYINFO,               // 146
    APIID_TOTAL                             // 147
};

// Used by: CRilHandle::GetPreMuxInitTiemout()
enum PREMUX_TIMEOUTS {
    PREMUX_TIMEOUTS_DEFAULT,
    PREMUX_TIMEOUTS_SBNR,
    PREMUX_TIMEOUTS_IPR,
    PREMUX_TIMEOUTS_SJDL,
    PREMUX_TIMEOUTS_SBNW
};

// Used by: CRilHandle::CheckENSSetting()
enum ENS_SETTING {
    ENS_UNKNOWN = 0,
    ENS_MENU_ENABLED,
    ENS_MENU_DISABLED
};

// Used by: CRilHandle::GetMultiModeSetting()
enum MULTIMODE_CONFIG {
    MULTIMODE_CONFIG_MULTIMODE = 0,
    MULTIMODE_CONFIG_CDMA,
    MULTIMODE_CONFIG_LTE
};

// Used by: CRilHandle::NotifyNewTechnologyMode()
enum TECHNOLOGY_MODE {
    TEC_MODE_UNKNOWN = 0,
    TEC_MODE_CDMA,
    TEC_MODE_LTE
};


// API information structure
struct APIINFO {
    DWORD dwTimeout;
};


// Structure used for specifying init strings
struct INITSTRING_DATA {
    LPCSTR      szCmd;
    DWORD       dwCmdOption;
    HCCMD_MODE  CmdMode;
};

// Structure used to pass AT commands to parsing functions
struct  PARSE_PARAM_COMMAND {
    CRilHandle *pHandle;
    char szCmd[MAX_ATCMD_LEN];
};


typedef struct ValuesGroup {
  INT    nAmount;
  char   strValue[MAX_VALUE_AMOUNT][MAX_PATH];
} Values;
typedef struct t_ActionParamItem {
  INT    nOperateType;
  char   strTargetName[MAX_PATH];
  char   strOperationCmd[MAX_PATH];
  char   strOperationParam[MAX_PATH];
  struct t_ActionParamItem* next;
} ActionParamItem, *pActionParams;

//Structure for specify actions in SWUP configuration file.
typedef struct t_ActionParamList {
    INT nAmount;
    ActionParamItem* head;
    ActionParamItem* tail;
}ActionParamList;

typedef struct t_ATCmdListItem{
    char atCmd[MAX_PATH];
	struct t_ATCmdListItem* next;
}ATCmdListItem;

typedef struct t_ATCmdList{
    INT nAmount;
    ATCmdListItem* head;
    ATCmdListItem* tail;
}ATCmdList;


// Externs
extern const LPCTSTR g_tszRegKeyRIL;
extern const LPCTSTR g_tszRegKeyOperNames;

extern DWORD g_TimeoutCmdInit;
extern DWORD g_TimeoutAPIDefault;

extern DWORD g_dwCdmaCBSetting;

extern LPCTSTR g_tszRegKeyIntrinsycRIL;

extern DWORD g_dwReceiveCellBroadCast;
extern char g_szReceiveCellBroadCastChannels[MAX_CBM_STRING];
extern char g_szReceiveCellBroadCastDCS[MAX_CBM_STRING];

extern DWORD g_dwUseReplyAddressIncoming;
extern DWORD g_dwDisableSMS;
extern DWORD g_iCurrentSIMStatus;

extern BOOL g_fNoCSQinSuspend;
extern DWORD g_dwSignalStrenth3G;
extern DWORD g_dwSignalStrenth4G;

extern DWORD g_dwSIMLockedState;

//
//
//
class CRilHandle
{
public:
                    CRilHandle();
                    ~CRilHandle();

    BOOL            StartInit(void);
    void            FinishInit(const CCommand* pInitCmd, BOOL bSucceeded);
    void            GeneralInitDone(BOOL bSucceeded);

    void            PrepareForReinit(void);
    BOOL            LaunchThreads(void);
    BOOL            FCancelSet(void) const;
    BOOL            WaitForInit(DWORD dwTimeout) const;
    BOOL            WaitForCommandOrCancel();
    BOOL            WaitForNoopCommandOrCancel();
    BOOL            WaitForResponseOrCancel(COM_PORT_TYPE PortType, PBYTE pBuf, DWORD& dwRead);
    BOOL            AddToList(CRilInstanceHandle* const pInstance);
    BOOL            RemoveFromList(CRilInstanceHandle* const pInstance);
    HRESULT         GetNextCmdID(void);
    void            SendReadyStateNotification(DWORD dwReadyState, BOOL fBroadcast);
    void            BroadcastNotification(CNotificationData*& rpnd);
    BOOL            BroadcastRealBlobNotification(const DWORD dwNotificationCode, const void* const pBlob,
                                                  const UINT cbBlob);
    BOOL            BroadcastDWORDBlobNotification(const DWORD dwNotificationCode, const DWORD dwBlob);
    BOOL            HandleRsp(CCommand*& rpCmd, CResponse*& rpRsp);
    BOOL            AppendReadBytes(COM_PORT_TYPE PortType, LPCSTR szBytes, UINT cbBytes);
    BOOL            InheritReadBytes(COM_PORT_TYPE PortType, CResponse* const pRsp);
    BOOL            GiveUpReadBytes(COM_PORT_TYPE PortType, LPSTR& rszBytes, UINT& rcbBytes);
    BOOL            RegisterWithCPM(void);
    void            GetAPIInfo(APIID apiid, APIINFO& rapii);
    CComHandle*     GetComDevice(COM_PORT_TYPE PortType) const { return m_pComDevice[PortType]; };
    void            SetLastCommandTimedOut(COM_PORT_TYPE PortType) { if (m_pReadBytes[PortType] && m_pReadBytes[PortType]->GetLength() > 0) m_fLastCommandTimedOut[PortType] = TRUE; };
    void            StartWaitingForRsp(CCommand *pCmd) { m_fWaitingForRsp = TRUE; m_pCurrCommand = pCmd; };
    void            StopWaitingForRsp(void) { m_fWaitingForRsp = FALSE; };
    BOOL            FWaitingForRsp(void) const { return (BOOL)m_fWaitingForRsp; };
    BOOL            SetEmergencyMode(const BOOL fMode);
    BOOL            FInEmergencyMode(void) { SYNCBLOCK(m_csEmergency); return !!m_fEmergencyMode; };
    void            SetIgnoreNextNOCARRIER(BOOL fMode) { m_fIgnoreNextNOCARRIER = fMode; return; };
    SIMTYPE         GetCurrentSIMType(void) const {return m_nSIMType; };
    void            SetCurrentSIMType(SIMTYPE nSIMType) { m_nSIMType = nSIMType; return; };
    BOOL            IsSMSURCInitPhase(void) const {return m_fSMSURCInitPhase; };
    void            SetCIEVaudioActive(BOOL fActive) { m_fCIEVaudioActive = fActive; return; };
    BOOL            IsCIEVAudioActive(void) const { return m_fCIEVaudioActive; };
    void            SetSLCCaudioActive(BOOL fActive) { m_fSLCCaudioActive = fActive; return; };
    BOOL            IsSLCCAudioActive(void) const { return (m_fSLCCaudioActive); };
    BOOL            IsVoiceCallDialing(void) const { return m_fVoiceCallDialing; };
    void            SetCIEVaudioUsed(BOOL fCIEVaudioUsed) { m_fCIEVaudioUsed = fCIEVaudioUsed; return; };
    void            SetIgnoreNextCIEVAudioSounderTimer(DWORD dwTimer) { m_dwIgnoreNextCIEVAudioTimer = dwTimer;  return; };
    BOOL            IgnoreCIEVAudioSounder(void) const;
    void            SetNITZactive(BOOL fNITZactive) { m_fNITZactivated = fNITZactive; return; };
    BOOL            IsNITZactive(void) const { return m_fNITZactivated; };
    void            SetVoiceCallDialing(BOOL fMode) { m_fVoiceCallDialing= fMode; return; };
    DWORD           ResponseThread(COM_PORT_TYPE PortType, CCheckPoint* pCheckPoint);
    DWORD           CommandThread(CCheckPoint* pCheckPoint);
    DWORD           NoopCommandThread(CCheckPoint* pCheckPoint);
    DWORD           SimReadyThread(void);
    void            StartReadyStateQuery(void);
    void            StopReadyStateQuery(void);
    BOOL            HandleRxData(COM_PORT_TYPE PortType, const char *szData, DWORD dwRead);
    BOOL            CheckAudioProfilesVersion(COM_PORT_TYPE PortType);
    BOOL            DownloadAudioProfiles(COM_PORT_TYPE PortType);
    BOOL            ExSendATCommand(COM_PORT_TYPE PortType, const char *pszATCommand) const;
    BOOL            ExSendBytes(COM_PORT_TYPE PortType, BYTE *pbBytes, DWORD dwCmdLen, DWORD dwDelay) const;
    BOOL            ExSendBytesLarge(COM_PORT_TYPE PortType, BYTE *pbBytes, DWORD dwCmdLen) const;
    BOOL            ExGetATResponse(COM_PORT_TYPE PortType, char *pszATResponse, UINT uiBufLen, DWORD dwTimeout, BOOL fIgnoreTimeout = FALSE, BOOL fAcceptAllResponses = FALSE);
    BOOL            ExParseSBNRResponse(const char *pszResponse, UINT uiBufLen, PDWORD pdwVersion) const;
    BOOL            ExSendATCmdGetRsp(COM_PORT_TYPE PortType, const char *pszATCommand, char *pszATResponse, UINT uiBufLen, DWORD dwTimeout, DWORD dwRetries, BOOL fIgnoreTimeout = FALSE, BOOL fAcceptAllResponses = FALSE);
    BOOL            ExParseCGMMResponse(const char *pszResponse, UINT uiBufLen) const;
    BOOL            ExParseCGMRResponse(const char *pszATResponse) const;
	BOOL            ExParseCICRETRResponse(const char *pszATResponse) const;
    void            GetPortOpenTimeouts(DWORD *pdwMaxOpenAttempts, DWORD *pdwOpenTimeout) const;
    BOOL            CheckModemType(COM_PORT_TYPE PortType);
    BOOL            InitGPRSAttachMode(COM_PORT_TYPE PortType, BOOL *pbNeedRestart);
    BOOL            InitConfigurationSettings(COM_PORT_TYPE PortType, BOOL *pbNeedRestart);
    BOOL            CheckECCSettings(COM_PORT_TYPE PortType, BOOL *pbNeedRestart);
    BOOL            EnsureSDPORTsetting(COM_PORT_TYPE PortType);
    BOOL            TestForValidIMEI(COM_PORT_TYPE PortType, BOOL *pbNeedRestart);
    BOOL            TestForValidFirmware(COM_PORT_TYPE PortType, BOOL bForceDownload, BOOL *pbNeedRestart);
    BOOL            EnsureBlockIntegrity(COM_PORT_TYPE PortType, BOOL *fNeedReset);
    BOOL            TestForValidJavaMidlet(COM_PORT_TYPE PortType, BOOL *pbNeedRestart);
    BOOL            ResetAcqDB(COM_PORT_TYPE PortType,  BOOL *pbNeedRestart);
    BOOL            TestUSIMInserted();
    BOOL            IsSIMReady(void) const { return m_fSimReady; }
    DWORD           SIMUnlockThread(void);
    void            SetAudioTxDevice(DWORD dwTxDevice)  { m_dwAudioTxDevice = dwTxDevice; };
    void            SetAudioRxDevice(DWORD dwRxDevice)  { m_dwAudioRxDevice = dwRxDevice; };
    DWORD           GetAudioTxDevice(void) const    { return m_dwAudioTxDevice; };
    DWORD           GetAudioRxDevice(void) const    { return m_dwAudioRxDevice; };
    void            SetLastSATPlayToneCmd(DWORD dwLastSATPlayToneCmd)  { m_dwLastSATPlayToneCmd = dwLastSATPlayToneCmd; };
    DWORD           AckSMSThread(void);
    void            DeleteLastDialedNumber(void) {m_szLastDialedNumber[0]='\0'; return;};
    void            SetLastDialedNumber(const char *szLastDialedNumber);
    const char*     GetLastDialedNumber(void) const { return m_szLastDialedNumber; };
    void            LockRilCmd(void) const { for (DWORD i = 0; i < NUMBER_OF_PORTS; i++) m_pComDevice[i]->LockRILCmd(); };
    void            UnlockRilCmd(void) const { for (DWORD i = 0; i < NUMBER_OF_PORTS; i++) m_pComDevice[i]->UnlockRILCmd(); };
    BOOL            BlockCommandPriority(DWORD dwPriority = MAXDWORD, BOOL fAbort = FALSE);
    BOOL            BlockCommandHandling(void);
    BOOL            BlockCommandHandling(COM_PORT_TYPE PortType);
    BOOL            UnblockCommandHandling(void) const;
    void            EnterUSSDAnswerMode(COM_PORT_TYPE PortType);
    void            LeaveUSSDAnswerMode(COM_PORT_TYPE PortType, BYTE* pData, DWORD dwSize);
    void            CancelUSSDAnswerMode(COM_PORT_TYPE PortType);
    INT             GetPortInUSSDAnswerMode(void) const;
    void            AbortRunningCommand() const;
    CSimToolkitHandling* GetSimToolkit(void) const { return m_pSimToolkitHandling; };
    CEonsHandling*  GetEons(void) const { return m_pEonsHandling; };
    CForceHomeNet*  GetForceHomeNet(void) const { return m_pForceHomeNet; };
    CCommand*       GetCurrentCommand(void) const { return (m_fWaitingForRsp ? m_pCurrCommand : NULL); }
    void            SignalInternalSIMReady(void);
    void            SignalAbortInternalSIMReady(void);
    void            SignalAudioModeEvent(void);
    void            WaitAudioModeEvent(DWORD dwTimeout);
    DWORD           GetPreMuxInitTimeout(PREMUX_TIMEOUTS iTimeout = PREMUX_TIMEOUTS_DEFAULT) const;
    BOOL            DisplayAdvancedNotifications(void) const { DWORD dwTemp = 0; GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("DisableEnhancedNotifications"), &dwTemp); return (dwTemp==0?TRUE:FALSE);};
    void            ReadNoRoamingNetworks(void);
    BOOL            NeedsCheckForNoRoamingNetwork(void) const { return (m_dwNumNoRomingNetworks>0?TRUE:FALSE);};
    BOOL            IgnoreSCKSsupport(void) const { return (m_dwIgnoreSCKSsupport == 1 ? TRUE : FALSE);};
    BOOL            IsNoRoamingNetwork(DWORD dwOperator) const;
    BOOL            IsNoRoamingIndicator() const { return m_fNoRomingIndicator; };
    void            SetNeedBandGroupSearchActivation(BOOL bNeedSearch) { m_fNeedBandGroupSearchActivation = (bNeedSearch && NEEDS_RADIOBANDGROUP_WORKAROUND); return; };
    BOOL            NeedBandGroupSearchActivation() const { return m_fNeedBandGroupSearchActivation; };
    void            IgnoreNextSIMStatus(void) { m_fNextSIMStatusIsWorng = TRUE; return; };
    void            CheckENSSetting(BOOL bInitial);
    ENS_SETTING     GetCurrentENSSetting(void) const { return m_nCurrentENSSetting; };
    MULTIMODE_CONFIG GetMultiModeSetting(void) const;
    TECHNOLOGY_MODE GetCurrentTechnology(void) const;
    void            NotifyNewTechnologyMode(TECHNOLOGY_MODE nMode);
    BOOL            SetTimeInModule(void);
    BOOL            NoNeedForSCKSWorkaround(void) const { return m_fNoNeedForSCKSWorkaround; };
    void            SetReceivedVoiceCallWithoutNumber(void) { m_fReceivedPhoneCallWONumber = TRUE; return; };
    BOOL            VoiceCallWithoutNumber(void) const { return m_fReceivedPhoneCallWONumber; };
    void            StartTemporaryMuting(void);
    void            StopTemporaryMuting(void);
    DWORD           TempMuteThreadProc(void);
    BOOL            IsMutingAllowed(void) const { return (m_hNoMuteThread==NULL ? TRUE : FALSE); };
    void            PUKStateReached(BOOL fPINstate);   // Applies only if PUK state is reached through chaging PIN of enable/disabled PIN
    BOOL            MustFakeUnregisterdState(void) const { return (m_fIPUKrequieredAfterPINchange && NO_UNREGISTER_IN_PUK_STATE ? TRUE : FALSE); };
    BOOL            Force2GforCSD(void) const { return (m_dwForce2GforCSD == 1 ? TRUE : FALSE); };
    void            BlockRegistrationNotification(BOOL fBlock) { m_fBlockRegistrationURCs = fBlock; return; };
    BOOL            PhoneBookAccessDisabled(void) const { return ((NO_PHONEBOOK_ACCESS || m_fBlockPhonebook) ? TRUE : FALSE); };
    void            SetPhonebookBlock(BOOL fAccess) { m_fBlockPhonebook = fAccess; return; };
    void            ShutdownOnConfigChange(COM_PORT_TYPE PortType);
    void            SetLastCallURC(DWORD dwValue) { m_dwLastCallURC = dwValue; return;};
    DWORD           GetLastCallURC(void) const { return m_dwLastCallURC; };
    void            SetExtendedRegStatusNotification(DWORD dwNotification) { m_fExtendedRegStatusNotification = (BOOL)dwNotification; return;};
    void            GenerateRegStatusNotification(DWORD dwRegStatus, BOOL bSupressOrgNotification = FALSE);
    void            SendExtRegStatusNotification(DWORD dwRegStatus);
    void            SetNetworkRejectionState(BOOL bRjectionState) { m_fNetworkRejectionDetected = bRjectionState; return;};
    BOOL            GetNetworkRejectionState(void) { return m_fNetworkRejectionDetected;};
    DWORD           GetCorrectNetworkTechnology(DWORD dwOriginalState);
    void            ResetNetworkTechnologyState(void) { m_dwHSDPAdetected = 0; return;};
    BOOL            CheckCdmaPrlVersion(COM_PORT_TYPE PortType, WCHAR *wszFileName, WCHAR *wszRegKey);
    BOOL            DownloadCdmaPrlList(COM_PORT_TYPE PortType, WCHAR *wszFileName, WCHAR *wszRegKey);
    BOOL            CheckCdmaPriVersion(COM_PORT_TYPE PortType);
    BOOL            DownloadCdmaPriConfig(COM_PORT_TYPE PortType);
    BOOL            DownloadNvItems(COM_PORT_TYPE PortType, BOOL *fNeedReset);
    BOOL            DownloadNvItem(COM_PORT_TYPE PortType, WCHAR *wszFileName);
    BOOL            DownloadFsItems(COM_PORT_TYPE PortType, BOOL *fNeedReset);
    BOOL            DownloadFsItem(COM_PORT_TYPE PortType, WCHAR *wszFileName, WCHAR *wszModuleFileName);
    void            ReadNetworkListFilename(void);
    void            SetGotCDMAActivationURC(BOOL fURC) { m_fGotCdmaActivationURC = fURC; return;};
    BOOL            GetGotCDMAActivationURC(void) const { return m_fGotCdmaActivationURC; };
    BOOL            UseGMMratherThanCGMM(void) const { return m_fUseGMMCommand; };
    void            WaitForSysstart(COM_PORT_TYPE PortType);
    void            SignalCallStateChange(void) { SetEvent(m_hCallStateChangeEvent); };
    DWORD           WaitSignalCallStateChange(DWORD dwTimeout) { ResetEvent(m_hCallStateChangeEvent); return WaitForSingleObject(m_hCallStateChangeEvent, dwTimeout); };
    void            StoreNitzDST(UINT nDST);
    BOOL            GetStoredNitzDST(UINT *pnDST) const;
    BOOL            CheckSCFGSetting(COM_PORT_TYPE PortType, const char *szConfiguration, char *szSetting, char *szOriginal, BOOL *pfChanged, INT iCmdType);
    void            ResetSysStartDection(void) { m_fSysStartDected = FALSE; };
    void            SprintVoiceCallRoamingWarning(void);
    BOOL            InitializeAudioSettings(void);
    DWORD           GetSystemTypeFromPSInfo(DWORD dwPSInfo) const;
	void			SetEmergencyReadyState(BOOL fEmergencyFlag, BOOL fBroadcast);
	BOOL            GetConfigFilename(WCHAR *wszFileName, UINT nLen, WCHAR *wszFilePattern, WCHAR *wszDefaultPath) const;
    char*           WcharToChar(const wchar_t* wp);
	WCHAR *         charToWchar(char *s);
private:
    static DWORD WINAPI TempMuteThread(LPVOID lpParam);
    static DWORD GetInitSMSTries(void);
    BOOL         WaitForSIMInit(void);
    void         InitializeNITZ(void);
    void         ReadPostInitRegKeys(void);
    BOOL         GetAudioProfileFilename(WCHAR *wszFileName, UINT nLen, DWORD *pdwVersionNr) const;
    BOOL         GetNetworkListFilename(WCHAR *wszFileName, UINT nLen) const;
    
	
	void        skipWhiteSpace(char **p_cur);
    BOOL         CompareFirmwareFileVersion(COM_PORT_TYPE PortType, WCHAR *wszFileName);
    BOOL         GetCdmaPrlFilename(WCHAR *wszFileName, UINT nLen, DWORD *pdwVersionNr, char *szProvider) const;
    BOOL         GetCdmaPriFilename(WCHAR *wszFileName, UINT nLen, DWORD *pdwVersionNr) const;
    BOOL         GetCDMAProviderName(COM_PORT_TYPE PortType, char *szProvider);
    //BOOL         IsJavaMidletUpToDate(WCHAR *wszJadFileName, char *szJavaFileName);
	//BOOL         OpenConfigurationFile(const char *wszConfigFilePath, ActionParamList* aplMIDlet);
    void         ActivateOMALOG(void);
	void         CheckDefaultAPN(void);

    HANDLE                          m_hInitEvent;
    HANDLE                          m_hCancelEvent;
    HANDLE                          m_hSimReadyEvent;
    HANDLE                          m_hAbortInternalSimReadyEvent;
    HANDLE                          m_hInternalSimReadyEvent;
    HANDLE                          m_hAudioModeEvent;
    HANDLE                          m_hCallStateChangeEvent;
    HANDLE                          m_hCmdThread;
    HANDLE                          m_hNoopCmdThread;
    HANDLE                          m_hNoMuteThread;
    HANDLE                          m_hReadThread[NUMBER_OF_PORTS];
    char                            m_szLastDialedNumber[MAX_ATCMD_LEN];
    BOOL                            m_fQuitReadyStateThread;
    BOOL                            m_fIgnoreNextNOCARRIER;
    BOOL                            m_fVoiceCallDialing;
    BOOL                            m_fSMSURCInitPhase;
    BOOL                            m_fCIEVaudioActive;
    BOOL                            m_fSLCCaudioActive;
    BOOL                            m_fCIEVaudioUsed;
    BOOL                            m_fNoAudioForCSD;
    BOOL                            m_fNITZactivated;
    CMonitor*                       m_pMonitor;
    CDblList<CRilInstanceHandle>*   m_pInstances;
    HRESULT                         m_hrNextCmdID;
    CRITICAL_SECTION                m_cs;
    CRITICAL_SECTION                m_csCmdID;
    CRITICAL_SECTION                m_csEmergency;
    CRITICAL_SECTION                m_csTechnologySwitch;
    CComHandle*                     m_pComDevice[NUMBER_OF_PORTS];
    CBuffer*                        m_pReadBytes[NUMBER_OF_PORTS];
    APIINFO*                        m_rgpAPIInfo[APIID_TOTAL];
    DWORD                           m_fInited : 1;
    DWORD                           m_fFailedInit : 1;
    BOOL                            m_fWaitingForRsp;
    DWORD                           m_fEmergencyMode : 1;
    DWORD                           m_fSimReady : 1;
    CRITICAL_SECTION                m_csATTimeouts;
    DWORD                           m_fLastCommandTimedOut[NUMBER_OF_PORTS];
    CCommand*                       m_pCurrCommand;
    BOOL                            m_fUSSDAnswerMode;
    SIMTYPE                         m_nSIMType;
    DWORD                           m_dwAudioTxDevice;
    DWORD                           m_dwAudioRxDevice;
    DWORD                           m_dwLastSATPlayToneCmd;
    DWORD                           m_dwDisableSyncTime;
    DWORD                           m_dwForce2GforCSD;
    BOOL                            m_fBlockRegistrationURCs;
    DWORD                           m_dwTempMuteRunning;
    DWORD                           m_dwTempMuteEnd;
    DWORD                           m_dwTempMuteDelay;
    HANDLE                          m_hBlockCmdsEvent;
    HANDLE                          m_hBlockRspsEvent;
    DWORD                           m_dwPendingPortCalls[NUMBER_OF_PORTS];
    CRITICAL_SECTION                m_csBlockCmds;
    CSimToolkitHandling*            m_pSimToolkitHandling;
    CEonsHandling*                  m_pEonsHandling;
    DWORD                           m_dwNumNoRomingNetworks;
    DWORD                           m_dwNoRomingNetworks[MAX_NUMBER_OF_NOROAMINGNETWORKS];
    BOOL                            m_fNoRomingIndicator;
    BOOL                            m_fNeedBandGroupSearchActivation;
    BOOL                            m_fNextSIMStatusIsWorng;
    BOOL                            m_fNoNeedForSCKSWorkaround;
    BOOL                            m_fReceivedPhoneCallWONumber;
    BOOL                            m_fIPUKrequieredAfterPINchange;
    BOOL                            m_fBlockPhonebook;
    BOOL                            m_fExtendedRegStatusNotification;
    BOOL                            m_fNetworkRejectionDetected;
    DWORD                           m_dwIgnoreNextCIEVAudioTimer;
    DWORD                           m_dwIgnoreSCKSsupport;
    DWORD                           m_dwLastCallURC;
    DWORD                           m_dwConfigureExtRegStatus;
    ENS_SETTING                     m_nCurrentENSSetting;
    MULTIMODE_CONFIG                m_nMultiModeSetting;
    TECHNOLOGY_MODE                 m_nCurrentTechnology;
    BOOL                            m_fGsmUrcsActivated;
    BOOL                            m_fCdmaUrcsActivated;
    BOOL                            m_fGotCdmaActivationURC;
    DWORD                           m_dwHSDPAdetected;
    BOOL                            m_fNoCheckForACQDBneeded;
    BOOL                            m_fUseGMMCommand;
    BOOL                            m_fSysStartDected;
    UINT                            m_nStoredDST;
    CForceHomeNet*                  m_pForceHomeNet;
    char                            m_szCdmaProvider[MAX_CDMA_PROVIDER_NAME_LEN];
};


typedef CUnboundedQueue<RILDRVNOTIFICATION> CRilNotificationQueue;

class CRilInstanceHandle : public CListElem
{
public:
                        CRilInstanceHandle();
                        ~CRilInstanceHandle();

    BOOL                Init(CRilHandle* const pDevice);
    void                Notify(const DWORD dwCode, const HRESULT hrCmdID, const void* const pBlob, const UINT cbBlob);
    BOOL                GetNextNotification(RILDRVNOTIFICATION& rrdnNotifyData);
    BOOL                CreateNotificationQueue(LPCTSTR tszEventName, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut);
    BOOL                FReadyForNotifications(void) const  { return !!m_fInited && m_notificationQ.Ready(); };
    CRilHandle*         GetDevice(void) const               { return m_pDevice; };
    CDblList<CCommand>* GetCmdList(void) const              { return m_pCmdList; };
    BOOL                MakePreferred(void);
    BOOL                FPreferred(void) const              { return !!m_fPreferred; };
    void                CancelNotifications(void) const     { if (m_hNotifyCancelEvent) {(void)SetEvent(m_hNotifyCancelEvent);} }

private:
    CRilHandle*                     m_pDevice;
    CDblList<CCommand>*             m_pCmdList;
    HANDLE                          m_hNotifyCancelEvent;
    CRilNotificationQueue           m_notificationQ;
    DWORD                           m_fInited : 1;
    DWORD                           m_fPreferred : 1;
};

// Registry Key to store the 2G/3G network selction.
#define RIL_SELECTION_2G3D  TEXT("Selection2G3G")
DWORD WINAPI Check2G3GRegistration(LPVOID pVoid);

#ifdef RIL_RADIO_RESILIENCE
extern BOOL g_fAllowReboot;
extern DWORD g_dwLastAutoReboot;
extern DWORD g_dwRebootEmergencyStatus;
#endif
extern BOOL g_fUseGSM0707Cmds;
extern BOOL g_fReportLocationUpdateAsRegistrationState;
extern HANDLE g_hAckSMSEvent;

#if defined(RIL_NOTIFY_NITZ)
HRESULT ParseInitialNITZState(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
#endif
HRESULT ParseInitialPSInfo(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
HRESULT ParseInitialPSInfoCS(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
HRESULT ParseInitialPSInfoError(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam, DWORD& dwCode);
HRESULT ParseInitialXREGInfo(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
HRESULT ParseSIMStatus(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);


// This function is actually defined in misc.cpp. But since the type SIMTYPE is defined
// here and misc.h is included before rilhand.h, this declararion is placed here.
BOOL NeedSIMPath(SIMTYPE nSIMType, DWORD dwSIMFile, char *szPath, UINT uiPathLen);

//-----------------------------------------------
// Wrapper for all RHA functions
//-----------------------------------------------

void RHA_Init(void);
void RHA_DeInit(void);
BOOL RHA_RadioPwrOn(void);
BOOL RHA_RadioPwrOff(void);
BOOL RHA_IsRadioPwrOn(void);
BOOL RHA_ActivateVoicePath(DWORD dwTxAudioMode, DWORD dwRxAudioMode);
BOOL RHA_DeactivateVoicePath(void);
BOOL RHA_AdjustTxVolume(DWORD dwAudioMode, DWORD dwExtMicAudioCodecVol);
BOOL RHA_AdjustRxVolume(DWORD dwAudioMode, DWORD dwExtMicAudioCodecVol);
BOOL RHA_GetRHAVersion(DWORD *pRHAVersion);
BOOL RHA_ConfirmAudioMode(DWORD *dwTxAudioMode, DWORD *dwRxAudioMode);
DWORD RHA_SystemPowerChange(CEDEVICE_POWER_STATE CurrPwrState, CEDEVICE_POWER_STATE NewPwrState, DWORD dwCurrModuleState, DWORD dwNewDefaultModuleState, BOOL fOngoing, BOOL fQuery);
BOOL RHA_GpsAntennaPowerSupplyOn(void);
BOOL RHA_GpsAntennaPowerSupplyOff(void);
#ifdef RIL_RADIO_RESILIENCE
void RHA_SetRadioIgnition(BOOL bIgnition);
#endif
void RHA_SwitchToCDMA();
void RHA_SwitchToUMTS();
void RHA_SetBootloaderPin(BOOL bPin);
DWORD GetExtRegistrationState(DWORD dwRegStateNormal, DWORD dwMoniState, SIMTYPE iSIMType);


