📄 emmgdlg_cpp.txt
字号:
// Catb.cpp : implementation file
//
#include "stdafx.h"
#include "tdcas.h"
#include "emmgdlg.h"
#include "cas.h"
#include "des.h"
#include "winsock.h"
#include "io.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEMMGDlg dialog
int number;
//int m_number;
char EmmData[66]={
0x02,0x02,0x11,0x00,0x3D,0x00,0x01,0x00,0x04,0x4A,0x02,
0x00,0x01,0x00,0x03,0x00,0x02,0x00,0x01,0x00,0x04,0x00,
0x02,0x00,0x01,0x00,0x08,0x00,0x02,0x00,0x00,0x00,0x05,
0x00,0x1F,0x82,0x70,0x1C,0x55,0x22,0x12,0x34,0x56,0x78,
0x90,0x24,0x00,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,
0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x80,0x00,0x00,0x64 };
unsigned char szDBData[70*100000];
int EmmDataLen;
/////////////////////////////////////////////////////////////////////////////
#define MAX_MESSAGE_LENGTH 2048
#define FILENAMELENGTH 60
#define MAXCONN 1000
#define UM_EMM_SOCK WM_USER+0x200
extern char LOGFILEPATH[FILENAMELENGTH];
SOCKET sock1scs,sock1id[MAXCONN];
CString temp;
extern unsigned int Super_CAS_ID;
extern char protocol_version;
extern char access_criteria[100];
extern char section_TSpkt_flag;
char flag=0;//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
extern void stoi(char *inbuf,unsigned int & hex,int len);
extern void WriteToLogfile(CString str,int LogFile);
extern void WriteToLogfile(char* buf,int len,int LogFile);
HANDLE hEvent=NULL;
//void SendEMMData(void);
//short EMM_WriteTo(SOCKET s, char *sendbuf, int buflen);
// CEMMGDlg dialog
short gEMM_WriteTo(SOCKET s, char *sendbuf, int buflen,CEdit * m_info)
{
CString temp;
m_info->ReplaceSel("b\r\n");
int sendlen=send(s,sendbuf,buflen,0);
m_info->ReplaceSel("a\r\n");
if (sendlen==SOCKET_ERROR)
{
int iWinsockErr=WSAGetLastError();
temp.Format("%d Error %d come from the send()!!\r\n ",s,iWinsockErr);
m_info->ReplaceSel(temp);
WriteToLogfile(temp,EMM_LOG);
return -1;
}
else
{
temp.Format("%d Send():return SUCCESS,packet length = %d\r\n",s,sendlen);
m_info->ReplaceSel(temp);
WriteToLogfile(temp,EMM_LOG);
WriteToLogfile(sendbuf,buflen,EMM_LOG);
WriteToLogfile("\r\n",EMM_LOG);
return(sendlen);
}
}
DWORD WINAPI tSendEmmData(PVOID pvParam)
{
int buflen,i;
char buf[2048];
CString temp;
int a=0;
// AfxMessageBox("start new thread!");
do{
gEMM_WriteTo(sock1scs,buf,buflen,(CEdit*)pvParam);
buflen=66;
for(i=0;i<66;i++)
buf[i]=EmmData[i];
temp.Format("%d\r\n",a++);
((CEdit*)pvParam)->ReplaceSel(temp);
//
// AfxMessageBox("before");
//WaitForSingleObject(hEvent,5000);
// Sleep(1000);
// AfxMessageBox("after");
}
while(1);
AfxMessageBox("Exit from tSendEmmData ");
}
void CEMMGDlg::Make_EMM_Provision(char *buf,int &buflen)
{
buf[0]=0x02;//protocol_version
buf[1]=0x02; buf[2]=0x11;//data_provision
buf[3]=0x00; buf[4]=0x3D;//下面有61个字节
buf[5]=0x00; buf[6]=0x01;//client_id
buf[7]=0x00; buf[8]=0x04;
buf[9]=0x4A; buf[10]=0x02;
buf[11]=0x00; buf[12]=0x01;
buf[13]=0x00; buf[14]=0x03;//EMM_channel_id
buf[15]=0x00; buf[16]=0x02;
buf[17]=0x00; buf[18]=0x01;
buf[19]=0x00; buf[20]=0x04;//EMM_stream_id
buf[21]=0x00; buf[22]=0x02;
buf[23]=0x00; buf[24]=0x01;
buf[25]=0x00; buf[26]=0x08;//data_id
buf[27]=0x00; buf[28]=0x02;
buf[29]=0x00; buf[30]=0x00;
buf[31]=0x00; buf[32]=0x05;//datagram
buf[33]=0x00; buf[34]=0x1F;//EMM_message_section_length
buf[35]=0x82;//table_id Unique方式
buf[36]=0x70; buf[37]=0x1C;//28字节
buf[38]=0x55;//SC_id start
buf[39]=0x22;
buf[40]=0x00;
buf[41]=0x11;
buf[42]=0x33;
buf[43]=0x11;
buf[44]=0x44;//SC_id end
buf[45]=0x24;//3-DES, Version 1.0
buf[46]=0xA1;//SK start
buf[47]=0x22;
buf[48]=0x33;
buf[49]=0x44;
buf[50]=0x55;
buf[51]=0x66;
buf[52]=0x77;
buf[53]=0x88;
buf[54]=0x99;
buf[55]=0x00;
buf[56]=0x11;
buf[57]=0x22;
buf[58]=0x33;
buf[59]=0x44;
buf[60]=0x55;
buf[61]=0x66;//SK end
buf[62]=0x80;//充值100元
buf[63]=0x00;
buf[64]=0x00;
buf[65]=0x64;
buflen=66;
}
int CEMMGDlg::m_number=0;
int CEMMGDlg::GetNo()
{
m_number++;
number++;
return (m_number);
}
CEMMGDlg::CEMMGDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEMMGDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEMMGDlg)
m_icid = _T("");
m_sk = _T("");
m_esk = _T("");
m_pky= _T("");
m_muxip = _T("");
m_period = _T("");
m_EMMPort = 20000;
//}}AFX_DATA_INIT
m_bCreated=false;
}
void CEMMGDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEMMGDlg)
DDX_Control(pDX, IDC_EDIT_EMM_LOG, m_info);
DDX_Control(pDX, IDC_LIST_userright, m_userright);
DDX_Text(pDX, IDC_EDIT_icid, m_icid);
DDX_CBString(pDX, IDC_COMBO_SK, m_sk);
DDX_Text(pDX, IDC_EDIT_esk, m_esk);
DDX_Text(pDX, IDC_EDIT_pky, m_pky);
DDX_Text(pDX, IDC_EDIT_MUX_IP, m_muxip);
// DDX_Text(pDX, IDC_EDIT_Period, m_period);
DDX_Text(pDX, IDC_EDIT_EMMG_PROT, m_EMMPort);
DDV_MinMaxInt(pDX, m_EMMPort, 10000, 30000);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEMMGDlg, CDialog)
//{{AFX_MSG_MAP(CEMMGDlg)
ON_BN_CLICKED(IDC_BUTTON_INSERT, OnButtonInsert)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
ON_BN_CLICKED(IDC_BUTTON_UPATE, OnButtonUpate)
ON_NOTIFY(NM_CLICK, IDC_LIST_userright, OnClickLISTuserright)
ON_BN_CLICKED(IDC_BUTTON_Start, OnBUTTONStart)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_CBN_SELCHANGE(IDC_COMBO_SK, OnSelchangeComboSk)
ON_MESSAGE(UM_EMM_SOCK,OnRecv)
ON_WM_CLOSE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEMMGDlg message handlers
void CEMMGDlg::OnButtonInsert()
{
UpdateData();
CString strTmp;
CString strSQL;
int nSQL=0;
int nTmp=0;
int i=0;
_variant_t RecordsAffected;
_RecordsetPtr m_pRecordset;
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
m_pConnection->ConnectionTimeout = 8;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_userright.DeleteAllItems();
try
{
CString str ;
// str="dsn=catv;uid=catv;pwd=123456";
str="provider=microsoft.jet.oledb.4.0;data source=catv.mdb";
m_pConnection->Open((_bstr_t)str,"","",adModeUnknown);
}
catch(_com_error e)
{
dump_com_error(e);
return ;
}
if(m_icid.IsEmpty())
{
AfxMessageBox("请重新输入icid");
return ;
}
strSQL.Format("select * from catv where icid='%s'",m_icid);
// strSQL+="'%"+m_icid+"%'";
try
{
m_pRecordset->Open(_variant_t(strSQL),_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error &e)
{
dump_com_error(e);
return ;
}
try
{
if(!m_pRecordset->adoEOF)
{
AfxMessageBox("该用户或者该ic已经存在了,请重新输入");
return ;
}
else
{
_variant_t RecordsAffected;
strSQL.Format("insert into catv(icid,pky,sk,esk)values('%s','%s','%s','%s')",
m_icid,m_pky,m_sk,m_esk);
m_pConnection->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
}
//
m_pRecordset->Close();
m_pConnection->Close();
}
catch(_com_error e)
{
dump_com_error(e);
return ;
}
}
void CEMMGDlg::OnButtonQuery()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strTmp;
CString strSQL;
int nSQL=0;
int nTmp=0;
_variant_t RecordsAffected;
_RecordsetPtr m_pRecordset;
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
m_pConnection->ConnectionTimeout = 8;
m_pRecordset.CreateInstance("ADODB.Recordset");
strSQL="select * from catv ";
GetDlgItemText(IDC_EDIT_icid,m_icid);
if(!m_icid.IsEmpty())
{
if(nSQL)
strSQL=strSQL+"and ";
else
strSQL=strSQL+"where ";
strSQL=strSQL+" icid=";
strSQL=strSQL+"'"+m_icid+"'";
nSQL++;
}
m_userright.DeleteAllItems();
try
{
CString str ;
// str="dsn=catv;uid=catv;pwd=123456";
str="provider=microsoft.jet.oledb.4.0;data source=catv.mdb";
m_pConnection->Open((_bstr_t)str,"","",adModeUnknown);
}
catch(_com_error e)
{
dump_com_error(e);
return ;
}
try
{
m_pRecordset->Open(_variant_t(strSQL),_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error &e)
{
dump_com_error(e);
return ;
}
int i=0;
try
{
while (!m_pRecordset->adoEOF)
{
char str[255];
int k=1;
//icid
strcpy(str,(LPSTR)(LPCSTR)(_bstr_t)m_pRecordset->GetCollect("icid"));
TrimEmpt(str);
m_userright.InsertItem(i,str);
//pky
strcpy(str,(LPSTR)(LPCSTR)(_bstr_t)m_pRecordset->GetCollect("pky"));
TrimEmpt(str);
m_userright.SetItemText(i,k++,str);
//sk
strcpy(str,(LPSTR)(LPCSTR)(_bstr_t)m_pRecordset->GetCollect("sk"));
TrimEmpt(str);
m_userright.SetItemText(i,k++,str);
//esk
strcpy(str,(LPSTR)(LPCSTR)(_bstr_t)m_pRecordset->GetCollect("esk"));
TrimEmpt(str);
m_userright.SetItemText(i,k++,str);
//
memcpy(szDBData+i*32,(LPSTR)(LPCSTR)str,32);
m_pRecordset->MoveNext();
i++;
}
}
catch(_com_error &e)
{
dump_com_error(e);//return ;
}
if (i==0)
{
AfxMessageBox("没有相应的记录,请返回重新输入查找条件!");
}
try
{
m_pRecordset->Close();
m_pConnection->Close();
}
catch(_com_error &e)
{
dump_com_error(e);
}
}
void CEMMGDlg::OnButtonReset()
{
// TODO: Add your control notification handler code here
m_esk = _T("");
m_icid = _T("");
m_pky= _T("");
m_sk = _T("");
UpdateData(FALSE);
}
BOOL CEMMGDlg::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD dwStyle=m_userright.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_TWOCLICKACTIVATE|LVS_EX_UNDERLINEHOT ;
m_userright.SetExtendedStyle(dwStyle);
LV_COLUMN Column;
Column.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
Column.fmt=LVCFMT_LEFT;
int isubitem=0; //
Column.cx=150; Column.pszText="icid"; Column.iSubItem=isubitem;m_userright.InsertColumn(isubitem,&Column); isubitem++;
Column.cx=150; Column.pszText="pky"; Column.iSubItem=isubitem;m_userright.InsertColumn(isubitem,&Column); isubitem++;
Column.cx=150; Column.pszText="sk"; Column.iSubItem=isubitem;m_userright.InsertColumn(isubitem,&Column); isubitem++;
//
Column.cx=150; Column.pszText="esk"; Column.iSubItem=isubitem;m_userright.InsertColumn(isubitem,&Column); isubitem++;
//SetTimer(1,1000,NULL);
hEvent=CreateEvent(NULL,TRUE,FALSE,"EMMEVENT");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CEMMGDlg::OnButtonUpate()
{
UpdateData();
CString strTmp;
CString strSQL;
int nSQL=0;
int nTmp=0;
int i=0;
_variant_t RecordsAffected;
_RecordsetPtr m_pRecordset;
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
m_pConnection->ConnectionTimeout = 8;
m_pRecordset.CreateInstance("ADODB.Recordset");
try
{
CString str ;
// str="dsn=catv;uid=catv;pwd=123456";
str="provider=microsoft.jet.oledb.4.0;data source=catv.mdb";
m_pConnection->Open((_bstr_t)str,"","",adModeUnknown);
}
catch(_com_error e)
{
dump_com_error(e);
return ;
}
if(m_icid.IsEmpty())
{
AfxMessageBox("请重新输入icid");
return ;
}
strSQL.Format("update catv set esk='%s' where icid='%s'",m_esk, m_icid);
try
{
m_pRecordset->Open(_variant_t(strSQL),_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error &e)
{
dump_com_error(e);
return ;
}
try
{
m_pConnection->Close();
}
catch(_com_error e)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -