⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tstril.cpp

📁 wince ril程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// tstril.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "tstril.h"
#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>

#include "ril.h"

typedef struct simtkitrspitem_tag {
    DWORD cbSize;                       // @field Structure size in bytes
    DWORD dwParams;                     // @field Indicates valid parameters
    DWORD dwId;                         // @field Selected Item Identifier
} SIMTKITRSPITEM, *LPSIMTKITRSPITEM;

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE			g_hInst;				// The current instance
HWND				g_hwndCB;					// The command bar handle

HWND				g_hwndEdit;
HRIL				g_hRil = 0;
DWORD				g_dwParam = 0x0;


static SHACTIVATEINFO s_sai;

// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass	(HINSTANCE, LPTSTR);
BOOL				InitInstance	(HINSTANCE, int);
LRESULT CALLBACK	WndProc			(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About			(HWND, UINT, WPARAM, LPARAM);
HWND				CreateRpCommandBar(HWND);

TCHAR *hexdump(unsigned char *data, int n)
{
    static TCHAR buf[1000];
    TCHAR *p;
    p=buf;
    while (n--)
    {
        p += _sntprintf(p, 4, TEXT(" %02x"), *data++);
    }
    return buf;
}

void DoError(LPTSTR where)
{
    TCHAR *msgbuf;

    int msglen= FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL, GetLastError(), 0, (LPTSTR) &msgbuf, 0, NULL);

	MessageBox(NULL, msgbuf, where, MB_OK);
    LocalFree(msgbuf);
}

BOOL GetDateAndTime(SYSTEMTIME *st, LPTSTR szDate, LPTSTR szTime, DWORD dwSize)
{

	if (!GetDateFormat(LOCALE_NEUTRAL, DATE_SHORTDATE, st, NULL, szDate, dwSize)) {
		DoError(L"GetDateFormat");
		return FALSE;
	}

	if (!GetTimeFormat(LOCALE_NEUTRAL, TIME_NOSECONDS, st, NULL, szTime, dwSize)) {
		DoError(L"GetTimeFormat");
		return FALSE;
	}


	return TRUE;
}

void 
DisplayDCS(RILMSGDCS * prmDCS)
{
	TCHAR szString[256];

	wsprintf(szString, L"    DCS cbSize: 0x%0x, %d", prmDCS->cbSize, prmDCS->cbSize);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"    DCS dwParams: 0x%0x, %d", prmDCS->dwParams, prmDCS->dwParams);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"    DCS dwType: 0x%0x, %d", prmDCS->dwType, prmDCS->dwType);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"    DCS dwFlags: 0x%0x, %d", prmDCS->dwFlags, prmDCS->dwFlags);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"    DCS dwMsgClass: 0x%0x, %d", prmDCS->dwMsgClass, prmDCS->dwMsgClass);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"    DCS dwAlphabet: 0x%0x, %d", prmDCS->dwAlphabet, prmDCS->dwAlphabet);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"    DCS dwIndication: 0x%0x, %d", prmDCS->dwIndication, prmDCS->dwIndication);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"    DCS dwLanguage: 0x%0x, %d", prmDCS->dwLanguage, prmDCS->dwLanguage);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
}

void
DisplayMessage(RILMESSAGE *prmMsg)
{
	TCHAR szDate[256], szTime[256];
	TCHAR szString[1024];

	wsprintf(szString, L"  cbSize: 0x%0x, %d", prmMsg->cbSize, prmMsg->cbSize);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"  dwParams: 0x%0x, %d", prmMsg->dwParams, prmMsg->dwParams);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"  Service Centre: %s", prmMsg->raSvcCtrAddress.wszAddress);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"  dwType: 0x%0x, %d", prmMsg->dwType, prmMsg->dwType);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
	wsprintf(szString, L"  dwFlags: 0x%0x, %d", prmMsg->dwFlags, prmMsg->dwFlags);
	SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);

	switch(prmMsg->dwType) {
		case RIL_MSG_IN_DELIVER:
			{
				wsprintf(szString, L"  From: %s", prmMsg->msgInDeliver.raOrigAddress.wszAddress);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				wsprintf(szString, L"  dwProtocolID: 0x%0x, %d", prmMsg->msgInDeliver.dwProtocolID, prmMsg->msgInDeliver.dwProtocolID);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				DisplayDCS(&prmMsg->msgInDeliver.rmdDataCoding);

				if (!GetDateAndTime(&prmMsg->msgInDeliver.stSCReceiveTime, szDate, szTime, 256))
				{
					return;
				}
				wsprintf(szString, L"  Received: %s on %s", szTime, szDate);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);

				wsprintf(szString, L"  Header Length: %d", prmMsg->msgInDeliver.cbHdrLength);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				wsprintf(szString, L"  Body Length: %d", prmMsg->msgInDeliver.cchMsgLength);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				if (prmMsg->msgInDeliver.cchMsgLength) {
					wsprintf(szString, L"  Message: %s", hexdump(prmMsg->msgInDeliver.rgbMsg, prmMsg->msgInDeliver.cchMsgLength));
					SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				}
				break;
			}
		case RIL_MSG_IN_STATUS:
			{
				wsprintf(szString, L"  Target address: %s", prmMsg->msgInStatus.raTgtRecipAddress.wszAddress);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);

				if (!GetDateAndTime(&prmMsg->msgInStatus.stTgtSCReceiveTime, szDate, szTime, 256))
				{
					return;
				}

				wsprintf(szString, L"  Receive Time: %s on %s", szTime, szDate);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);

				if (!GetDateAndTime(&prmMsg->msgInStatus.stTgtDischargeTime, szDate, szTime, 256))
				{
					return;
				}

				wsprintf(szString, L"  Discharge Time: %s on %s", szTime, szDate);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);

				wsprintf(szString, L"  dwTgtDlvStatus: 0x%0x, %d", prmMsg->msgInStatus.dwTgtDlvStatus, prmMsg->msgInStatus.dwTgtDlvStatus);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				wsprintf(szString, L"  dwProtocolID: 0x%0x, %d", prmMsg->msgInStatus.dwProtocolID, prmMsg->msgInStatus.dwProtocolID);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				DisplayDCS(&prmMsg->msgInStatus.rmdDataCoding);
				wsprintf(szString, L"  Header Length: %d", prmMsg->msgInStatus.cbHdrLength);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				wsprintf(szString, L"  Body Length: %d", prmMsg->msgInStatus.cchMsgLength);
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				if (prmMsg->msgInStatus.cchMsgLength) {
					wsprintf(szString, L"  Message: %s", hexdump(prmMsg->msgInStatus.rgbMsg, prmMsg->msgInStatus.cchMsgLength));
					SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				}
				break;
			}
		default:
				wsprintf(szString, L"Message type not covered yet!");
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				break;
	}

}

void CALLBACK NotifyCallback(DWORD dwCode, const void *lpData, 
										   DWORD cbData, DWORD dwParam)
{
	TCHAR szString[512];
    static BOOL   hashandle = FALSE;


    if(dwCode & RIL_NCLASS_SIMTOOLKIT)	
    {
        wsprintf(szString, L"notify: dwCode=0x%0X lpData=%p, cbData=%d, dwParam =%p",dwCode, lpData, cbData, dwParam);
	    SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
    	switch (dwCode) {
		case RIL_NOTIFY_SIMTOOLKITCMD:
			{
                RILSIMTOOLKITCMD *cmddata = (RILSIMTOOLKITCMD *)lpData;
				unsigned char *prm = (unsigned char *)lpData;
                wsprintf(szString, L"  A SIM Toolkit command:");
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
                memset(szString, 0, 256 * sizeof(TCHAR));
                if(cbData > 256)
                {
                    break;
                }

                for(int i = 0; i < cbData; i++)
                {
                    TCHAR text[2] ;
                    wsprintf(text, L"0x%2x", prm[i]);
                    wcscat(szString, text);
                    wcscat(szString, L" ");                    
                }
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);

                HRESULT result; 
                if( hashandle == FALSE)
                {
                RILSIMTOOLKITRSP response = {0};
                response.cbSize = sizeof(RILSIMTOOLKITRSP);// Structure and text size in bytes
                response.dwParams = 0x1f; // Indicates valid parameters
                response.dwId = 0x01;// ID number of command
                response.dwTag = *((unsigned char *)lpData + 2);// Command tag (with comprehension bit)
                response.dwType = 0x24; // Type of command (DISPLAY TEXT, etc.)
                response.dwQualifier = 0x0; // Command details qualifier
                response.dwResponse = 0; // Command result from SIM toolkit layer
                response.dwAdditionalInfo = 0;// Additional command result information.
                
                SIMTKITRSPITEM Detail;
                Detail.cbSize = sizeof(SIMTKITRSPITEM);
                Detail.dwParams = 1;
                Detail.dwId = 1;

                result = RIL_SendSimToolkitCmdResponse(g_hRil, &response, (LPBYTE)&Detail,  Detail.cbSize); 

                BYTE envcmd[9];  
                envcmd[0] = 0xd3; // Menu selection tag
                envcmd[1] = 0x07; // Length
                envcmd[2] = 0x02; // Device Identity Tag
                envcmd[3] = 0x02; // Device Identity length
                envcmd[4] = 0x82; // Source: ME
                envcmd[5] = 0x81; // Destination: SIM
                envcmd[6] = *((unsigned char *)lpData + 11); // Item Identifier tag
                envcmd[7] = 0x01; // Item Identifier length
                envcmd[8] = 0x01; // Item chose               
                //result = RIL_FetchSimToolkitCmd(g_hRil);
                result = RIL_SendSimToolkitEnvelopeCmd(g_hRil, envcmd, 9);       
                hashandle = TRUE;    
                }
                else
                {
                    RILSIMTOOLKITRSP response = {0};
                    response.cbSize = sizeof(RILSIMTOOLKITRSP);// Structure and text size in bytes
                    response.dwParams = 0x1f; // Indicates valid parameters
                    response.dwId = 0x01;// ID number of command
                    response.dwTag = 0x81;//*((unsigned char *)lpData + 2);// Command tag (with comprehension bit)
                    response.dwType = 0x24; // Type of command (DISPLAY TEXT, etc.)
                    response.dwQualifier = 0x0; // Command details qualifier
                    response.dwResponse = 0; // Command result from SIM toolkit layer
                    response.dwAdditionalInfo = 0;// Additional command result information.

                    SIMTKITRSPITEM Detail;
                    Detail.cbSize = sizeof(SIMTKITRSPITEM);
                    Detail.dwParams = 1;
                    Detail.dwId = 1;
                    result = RIL_SendSimToolkitCmdResponse(g_hRil, &response, (LPBYTE)&Detail,  Detail.cbSize); 
			        }
                }
				break;
		case RIL_NOTIFY_SIMTOOLKITCALLSETUP:
			{
				RILMESSAGE *prm = (RILMESSAGE *)lpData;

				wsprintf(szString, L" SIM Toolkit is trying to set up a call ");
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				break;
			}
     case RIL_NOTIFY_SIMTOOLKITEVENT:
            {
				RILMESSAGE *prm = (RILMESSAGE *)lpData;
				wsprintf(szString, L" A SIM Toolkit command was handled by the radio or the radio sent a SIM Toolkit command response to the SIM ");
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				break;
			}
     case RIL_NOTIFY_SIMTOOLKITSESSIONEND:
            {
				RILMESSAGE *prm = (RILMESSAGE *)lpData;
				wsprintf(szString, L"A SIM Toolkit command session is ending ");
				SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
				break;
			}
      }
    }
}

void CALLBACK ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void *lpData, 
										   DWORD cbData, DWORD dwParam)
{
    TCHAR szString[256];
    BYTE *prm = (BYTE *)lpData;
    wsprintf(szString, L"ResultCallback result: dwCode=%d, hrCmdID=%d lpData=%p, cbData=%d",
    dwCode, hrCmdID, lpData, cbData);    
    SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);

   /*szString[0] = 0;
    for(int i = 0; i < cbData; i++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -