/*****************************************************************************
 * Copyright (C) Gemalto M2M GmbH
 *****************************************************************************
 * Project: IMC-RIL-Driver
 *****************************************************************************
 * Author : Wireless Modules RD SW A2
 *****************************************************************************
 * $Workfile: Y:/z_ms-d/src/working/Quinn/RilDrv/msg.h $
 * $Revision: /main/ms-d/31 $
 *     $Date: 2013-09-13 09:27:12 $
 *   $Author: pmackent $
 *****************************************************************************
 * Target:
 *  Microsoft Windows Mobile 5.0
 *****************************************************************************
 * Description:
 *  Gemalto IMC RIL
 *****************************************************************************
 *
 * $Log: Y:/z_ms-d/src/working/Quinn/RilDrv/msg.h$ 
 * 
 * /main/ms-d/31   2013-09-13 09:27:12   pmackent 
 * Cell Broadcast for CDMA (IPIS100091379)
 *
 * /main/ms-d/30   2013-04-24 11:44:44   pmackent
 * New CDMA/CNMI setting and CDMA/CLCC workaround
 *
 * /main/ms-d/29   2012-11-21 13:30:20   pmackent
 * Basic support of EHS5 Rel2
 *
 * /main/ms-d/28   2012-10-01 09:58:30   pmackent
 * Handle class 2 SMS for PTCRB 8.2.1 (IPIS100082634)
 *
 * /main/ms-d/27   2012-07-10 11:55:49   pmackent
 * Workaround for lost +CMT: URC.
 *
 * /main/ms-d/26   2012-04-18 13:47:05   ctna0256
 * Introducing PVS8
 * Implementing CDMA-SMS
 * Various CDMA enhancements
 *
 * /main/ms-d/25   2012-02-22 13:26:51   ctna0256
 * Encapsulate use of Intel AT command set
 *
 * /main/ms-d/24   2012-02-09 16:44:28   ctna0256
 * Check for missed SMS with AT+CRSM on EHS5, small bug fixes
 *
 * /main/ms-d/23   2012-01-31 16:38:40   ctna0256
 * Added support for EHS5
 *
 * /main/ms-d/22   2010-07-22 14:44:47   ctna0256
 * Allow setting of default behaviour for incoming text messages
 *
 * /main/ms-d/21   2008-09-16 16:20:22   ctna0256
 * New registry keys for retries on multi-part SMS
 *
 * /main/ms-d/20   2008-08-27 11:39:11   ctna0256
 * Optional filter of Type 0 SMS
 *
 * /main/ms-d/19   2008-08-22 10:24:38   ctna0256
 * Set Cinterion copyright text
 *
 * /main/ms-d/18   2008-08-21 09:34:51   ctna0256
 * Prepared for new disclaimer handling
 *
 * /main/ms-d/17   2008-07-07 09:55:04   mp49210
 * Removed typo in #define
 *
 * /main/ms-d/16   2007-12-05 13:54:19   mp49210
 * Introduction of SMS persist link
 *
 * /main/ms-d/15   2007-08-09 09:56:42   mp49210
 * Check ME storage for accidently wrong routed SMS
 *
 * /main/ms-d/14   2007-06-01 16:21:01   mp49210
 * IPIS100036445: workaround for sending and receiving SMS per registry key
 *
 * /main/ms-d/13   2007-04-10 15:26:20   mp49210
 * Change SMS index range
 * Query SMSC before wiriting SMS to SIM
 *
 * /main/ms-d/12   2007-03-28 13:48:02   mp49210
 * Remove 'Classic RIL' specific code and comments
 *
 * /main/ms-d/11   2007-03-24 09:05:06   mp49210
 * Changed CNMI-options
 *
 * /main/ms-d/10   2007-02-26 16:15:30   mp49210
 * New behaviour of CBS, SIM storage and SMS SR
 *
 * /main/ms-d/9   2007-01-19 13:59:22   mp49210
 * Workaround for AT+CNMI problem with Quinn 020
 *
 * /main/ms-d/8   2007-01-19 11:27:57   mp49210
 * New build option RIL_STORE_SMS_ON_SIM_ON_SUSPEND
 *
 * /main/ms-d/7   2007-01-08 10:01:00   mp49210
 * Activation of CBM via AT+CNMI can be used now
 *
 * /main/ms-d/6   2006-12-29 10:20:48   mp49210
 * Set ME storrage to 0 while not in use
 *
 * /main/ms-d/5   2006-12-20 17:01:01   mp49210
 * Changes for AT+CNMI, AT+CAOC.
 * Modified URC configuration commands.
 *
 * /main/ms-d/4   2006-12-14 16:39:23   mp49210
 * Workaround for problem with MT storage
 *
 * /main/ms-d/3   2006-12-06 13:34:49   mp49210
 * Changed behaviour of AT+CSCB command
 *
 * /main/ms-d/2   2006-11-02 09:32:40   mp49210
 * No AT^SSMSS for Quinn
 *
 * /main/ms-d/1   2006-10-25 16:54:03   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 MSG_MSGBUF_LENGTH      (MAXLENGTH_MSG * 2 + 1)
#define MSG_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 MSG_CMDBUF_LENGTH      (MAX_PATH * 2 + MSG_MSGBUF_LENGTH)
#define MSG_ALLOC_NUMBER        16

// The AT+CSCB commands works different in the HC25 than in the other Cinterion modules like the MC75.
// HC25 style: first parameter <operation> adds or removes channels from the list of valid channels.
// MC75 style: first parameter <mode> selects two modes: 0 = only selected channels are accpeted,
//       1 = all channels are accepted expect the selected ones.
// Since the Microsoft RadioMetrics test expects the MC75 type it is reconmended to use this option.
#define CSCB_IN_MC75_STYLE

// The index for the SMS storage for the HC25 has the range 0...<n-1>. The MC75 uses
// the range 1..<n> instead. To simulate the MC75-style-index, use this option.
// If the EHS5 is used, this define has no effect, since the index for this module already
// uses the range 1..<n>.
#define NO_SMS_INDEX0

// Special SMS handling: to have always some reserved space for incomming SMS, we use the MT
// storage. This is a combined store of SIM (SM) and module (ME). The SIM entries are the first
// in the index order. To the OS we do not report the existence of these additional SMS storage
// places to be sure that they are available in case they are needed to receive SMS during
// suspend.
#define SMS_CNMI_STORE_ON_SIM         "+CNMI=2,1,2,9,1"
#define SMS_CNMI_STORE_ON_SIM_3GPP    "+CNMI=2,1,2,0,1"
#define SMS_CNMI_MANUAL_ACK           "+CNMI=2,2,2,1,1"
#define SMS_CNMI_CDMA_BASIC           "+CNMI=1,1"
#define SMS_CNMI_CDMA_FULL            "+CNMI=2,1,2,1"
#define SMS_INIT_PREFERRED_STORE_UMTS "AT+CPMS=\"SM\",\"SM\",\"SM\"\r"
#define SMS_INIT_PREFERRED_STORE_CDMA "AT+CPMS=\"ME\",\"ME\",\"ME\"\r"

// Element types of the SMS user data headers.
#define UDH_ELEMENTTYPE_CONCAT    0x00
#define UDH_ELEMENTTYPE_REPLY     0x22

// SIM file for SMS storage
#define SIM_EF_SMS          0x6F3C

#ifdef CSCB_IN_MC75_STYLE
extern DWORD g_dwReceiveCellBroadCastAccept;
#endif
extern BOOL g_bDefaultCNMIstoreOnSIM;
extern BOOL g_bChangeCNMIwhileSMSsend;

// Options for SMS persist link (AT+CMMS command)
#define SMSPERSISTLINK_NONE       0   // AT+CMMS will not be used.
#define SMSPERSISTLINK_TEMPORARY  1   // AT+CMMS will be set to 1, if RIL_SENDOPT_PERSISTLINK is used.
#define SMSPERSISTLINK_PERMANENT  2   // AT+CMMS will be permanently set to 2.

struct SMS_CLASS2_CHECK_THREAD_DATA {
    CRilHandle* pHandle;
    RILMESSAGE_IN_SIM rmMessageInSim;
};

extern DWORD g_dwSMSPersistLink;

HRESULT RILDrv_GetMsgServiceOptions(DWORD dwParam);
HRESULT RILDrv_SetMsgServiceOptions(DWORD dwParam, const RILMSGSERVICEINFO *lpMsgServiceInfo);
HRESULT RILDrv_GetMsgConfig(DWORD dwParam);
HRESULT RILDrv_SetMsgConfig(DWORD dwParam, const RILMSGCONFIG *lpMsgConfigInfo);
HRESULT RILDrv_GetCellBroadcastMsgConfig(DWORD dwParam);
HRESULT RILDrv_SetCellBroadcastMsgConfig(DWORD dwParam, const RILCBMSGCONFIG *lpMsgConfigInfo);
HRESULT RILDrv_ReadMsg(DWORD dwParam, DWORD dwIndex);
HRESULT RILDrv_DeleteMsg(DWORD dwParam, DWORD dwIndex);
HRESULT RILDrv_WriteMsg(DWORD dwParam, const RILMESSAGE *lpMessage, DWORD dwStatus);
HRESULT RILDrv_SendMsg(DWORD dwParam, const RILMESSAGE *lpMessage, DWORD dwOptions);
HRESULT RILDrv_SendStoredMsg(DWORD dwParam, DWORD dwIndex, DWORD dwOptions);
HRESULT RILDrv_SendMsgAcknowledgement(DWORD dwParam, BOOL fSuccess);

DWORD WINAPI CNMIReactivationThreadProc(LPVOID pVoid);
DWORD WINAPI ReCheckCBStatusThreadProc(LPVOID pVoid);
DWORD WINAPI SMSClass2CheckTreadProc(LPVOID pVoid);
HRESULT ParseSMSListAndSendAck(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
HRESULT ParseSMSListAndSendAckDelete(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);
void StartCNMICheck(CRilHandle* pHandle);
void RejectAllPendingSms(CRilHandle* pHandle);

BOOL MustFilterSMS(RILMESSAGE *pMsg);
BOOL ExtractUDHInformation(const BYTE *pUDH, UINT uiUDHLen, BYTE bUDHElementType, BYTE *bUDHElement, UINT uiUDHElementBufferLen, UINT& uiUDHElementLen);
BOOL CheckForMissedSMS(CRilHandle *pHandle, BOOL bWithDelete);
const char *GetCdmaCnmiSetting(void);
void ConfigureCdmaCellBroadcast(CRilHandle *pHandle);

