commit 3a630dba1d44a9b3c9d9bbf04afd43e59f757b4b Author: jdg <jd@infdj.com> Date: Sun Sep 12 20:55:27 2021 +0200 First commit 07/07/2002 diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..8bd9ee8 --- /dev/null +++ b/Main.cpp @@ -0,0 +1,341 @@ +//--------------------------------------------------------------------------- + +#include <vcl.h> +#include <stdio.h> +#include <time.h> +#pragma hdrstop + +#include "Main.h" +#include "SerieCfg.h" +//--------------------------------------------------------------------------- +#pragma package(smart_init) +#pragma resource "*.dfm" +TSmartCard_Reader *SmartCard_Reader; +//--------------------------------------------------------------------------- +__fastcall TSmartCard_Reader::TSmartCard_Reader(TComponent* Owner) + : TForm(Owner) +{ + TabSheet1->TabVisible=false; + + hCom=INVALID_HANDLE_VALUE; + atr = true; inver = false; + sprintf( serconfig1, "COM2: baud=9600 parity=O data=8 stop=2" ); + sprintf( serconfig2, "COM2: baud=9600 parity=O data=8 stop=2" ); + mlog->Lines->Clear(); + Logger( "Inicializaci�n del programa" ); +} +//--------------------------------------------------------------------------- +void __fastcall TSmartCard_Reader::Logger(AnsiString log) +{ + mlog->Lines->Add( log ); + StatusBar1->SimpleText = AnsiString( TDateTime::CurrentDateTime() ) + " :: " + log; +} +//--------------------------------------------------------------------------- +void __fastcall TSmartCard_Reader::Puertoserie1Click(TObject *Sender) +{ + TSerieConf *conf; + conf = new TSerieConf(this); + conf->ShowModal(); + if ( conf->ModalResult == mrOk ) + { + /* Cambiamos las cadenas de configuracion*/ + try { + sprintf(serconfig1,"%s: baud=%d parity=%c data=%1d stop=%1d", + conf->comPort->Items->Strings[conf->comPort->ItemIndex].c_str(),conf->baudiosA->Text.ToInt(),conf->pariA->Text.c_str()[0],conf->bitsA->Text.ToInt(),conf->stopA->Text.ToInt() ); + sprintf(serconfig2,"%s: baud=%d parity=%c data=%1d stop=%1d", + conf->comPort->Items->Strings[conf->comPort->ItemIndex].c_str(),conf->baudiosD->Text.ToInt(),conf->pariD->Text.c_str()[0],conf->bitsD->Text.ToInt(),conf->stopD->Text.ToInt() ); + atr = conf->ATR->Checked; + inver = conf->ConvenioInverso->Checked; + Logger( "Configuracion del puerto cambiada a: " + AnsiString( serconfig2 ) ); + } catch(...) { + Logger( "Error interpretando nueva configuraci�n" ); + } + /* y desconectamos */ + Desconectar1Click(0); + } + + delete conf; +} +//--------------------------------------------------------------------------- + +void __fastcall TSmartCard_Reader::Conectar1Click(TObject *Sender) +{ + if ( ! Conectar1->Checked ) + { + Desconectar1->Checked = false; + Conectar1->Checked = true; + OpenCOM(); + } +} +//--------------------------------------------------------------------------- +void __fastcall TSmartCard_Reader::Desconectar1Click(TObject *Sender) +{ + if ( ! Desconectar1->Checked ) + { + Desconectar1->Checked = true; + Conectar1->Checked = false; + CloseCOM(); + } +} +//--------------------------------------------------------------------------- +void __fastcall TSmartCard_Reader::OpenCOM(void) +{ + char buf[256]; + bool err = false; + + if ( hCom == INVALID_HANDLE_VALUE ) + { + if ( atr ) + { + Logger( "Inicializando el puerto para LEER ATR: "+AnsiString(serconfig1) ); + if ( Open(serconfig1)<0 ) + { + Logger( "Error en la apertura del puerto para ATR" ); err = true; + } else { + ATR1Click(0); + } + } + if ( !err ) + { + Logger( "Inicializando el puerto: "+AnsiString(serconfig2) ); + if ( SetConfig(serconfig2)<0 ) + { + Logger( "No puedo cambiar la velocidad" ); err = true; + } else { +/* + in[0]=0x21;in[1]=0xC1;in[2]=0x01;in[3]=0x58;in[4]=0xB9; + Send(out,buf,in,5,5); +*/ + } + } + } +} +//--------------------------------------------------------------------------- +void __fastcall TSmartCard_Reader::CloseCOM(void) +{ + if ( hCom != INVALID_HANDLE_VALUE ) + { + CloseHandle(hCom); + hCom=INVALID_HANDLE_VALUE; + } +} +//--------------------------------------------------------------------------- +/* + Funciones extraida integramente de VIAMOSC,(c) No te importa, versi�n 0.1 + Brevementes comentadas por mi (JDsoft para no confundirme) +*/ +int __fastcall TSmartCard_Reader::DoReset(void) +{ + EscapeCommFunction(hCom,SETRTS); + Sleep(50); + EscapeCommFunction(hCom,CLRRTS); + Sleep(250); + return 0; +} + +int __fastcall TSmartCard_Reader::SetConfig(const char *serconfig) +{ + DCB dcb; + BOOL fSuccess; + DWORD dwError; + ComErr[0]=0; + if (hCom==INVALID_HANDLE_VALUE) { strcpy(ComErr,"Port not open");return -1; } + fSuccess = GetCommState(hCom, &dcb); + if (!fSuccess) { strcpy(ComErr,"GetCommState failed");CloseHandle(hCom);return -1; } + fSuccess = BuildCommDCB(serconfig,&dcb); + if (!fSuccess) { strcpy(ComErr,"BuildCommDCB failed");CloseHandle(hCom);return -1; } + dcb.fRtsControl=RTS_CONTROL_DISABLE; + fSuccess = SetCommState(hCom, &dcb); + if (!fSuccess) { dwError=GetLastError();strcpy(ComErr,"SetCommState failed");CloseHandle(hCom);return -1; } + return 0; +} + +DWORD __fastcall TSmartCard_Reader::SRead(BYTE *buf,DWORD bytes_to_read,DWORD wait) +{ + DWORD bytes_read,cnt,t; + BYTE *buf2; + cnt=0; + buf2=buf; + ReadFile(hCom,(void*)buf,bytes_to_read,&bytes_read,NULL); + cnt+=bytes_read; + buf2+=bytes_read; + t=clock(); + while ((clock()<t+wait) && cnt<bytes_to_read) + { + ReadFile(hCom,(void*)buf2,bytes_to_read-cnt,&bytes_read,NULL); + cnt+=bytes_read; + buf2+=bytes_read; + } + if(inver) + for(int i=0;i<cnt;++i) buf[i]=inverso(buf[i]); + return cnt; +} +//--------------------------------------------------------------------------- +DWORD __fastcall TSmartCard_Reader::SWrite(BYTE *buf,DWORD bytes_to_write) +{ + DWORD n,i,j,k,l,tt; + BYTE buf2[256],ch; + for(i=n=l=0;i<bytes_to_write;++i) + { +// tt=rdtsc(); + if(inver) ch=inverso(buf[i]); + else ch=buf[i]; + WriteFile(hCom,(void*)&ch,1,&j,NULL); + n+=j; + ReadFile(hCom,&buf2[l],n-l,&k,NULL); + l+=k; +// while(rdtsc()-tt<delay); + } + if(l<n) SRead(&buf2[l],n-l,20); + return n; +} + +unsigned char __fastcall TSmartCard_Reader::inverso(unsigned char ch) +{ + unsigned char r; + int i; + for(r=i=0;i<8;++i) { r<<=1;r|=(ch&1);ch>>=1; } + return ~r; +} + +int __fastcall TSmartCard_Reader::Send(unsigned char *out,char *buf,unsigned char *in,int m,int RL) +{ + int n,k; + SWrite(in,m); + k=SRead(out,RL,2500); + setarr(buf,out,k); + return k; +} + +#define min(x,y) ((x<y)?(x):(y)) + +// Dado un caracter (con notacion hexadecimal) +// devuelve su valor en decimal +// Ej. '0' == 0 y 'B' == 11 +int __fastcall TSmartCard_Reader::getnyb(char c) +{ + if((c<='9')&&(c>='0')) return c-'0'; + else if((c<='F')&&(c>='A')) return c-'A'+10; + else return -1; +} + +// Dado un puntero a un par de caracteres, (con notacion hex) +// devuelve el n�mero que representa +// Ej. '3B' == 3<<4 + 11 +int __fastcall TSmartCard_Reader::getbyte(char *buf) +{ + int v,w; + v=getnyb(toupper(*buf++)); + w=getnyb(toupper(*buf++)); + if((v<0)||(w<0)) return -1; + return (v<<4)+w; +} + +// Dada una cadena del tipo "AF 32 2D E6" +// devuelve en la cadena a los valores en decimal: +// n == num_elementos a procesar de la cadena buf... +// Ejemplo: para la cadena anterior a[0]=0xAF; a[1]=0x32; a[2]=0x2D; a[3]=0xE6 +int __fastcall TSmartCard_Reader::getarr(unsigned char *a,char *buf,int n) +{ + int i; + for(i=0;i<n;++i,buf+=2) + { + int v; + while(*buf==' ') ++buf; + v=getbyte(buf); + if(v<0) return -1; + a[i]=v; + } + return n; +} + +// Igual que antes, pero para toda la cadena 'buf' +int __fastcall TSmartCard_Reader::getvar(unsigned char *a,char *buf) +{ + int n; + n=0; + while(*buf!=0) + { + int v; + while(*buf==' ') ++buf; + if(*buf==0) return n; + v=getbyte(buf);buf+=2; + if(v<0) return -1; + a[n++]=v; + } + return n; +} + + +// Dado un array de valores, los convierte a hexadecimal +// a[0]=0x1D y a[1]=0x24 ==> buf = "1D 24 "; +int __fastcall TSmartCard_Reader::setarr(char *buf,unsigned char *a,int n) +{ + int i; + for(i=0;i<n;++i) sprintf(&buf[3*i],"%02x ",a[i]); + return n; +} +void __fastcall TSmartCard_Reader::Salir1Click(TObject *Sender) +{ + Close(); +} + +int __fastcall TSmartCard_Reader::Open(const char *serconfig) +{ + COMMTIMEOUTS timeouts; + char string[16]; + BOOL fSuccess; + ComErr[0]=0; + memcpy(string,serconfig,4); + string[4]=0x00; + hCom = CreateFile(string,GENERIC_READ | GENERIC_WRITE,0, NULL,OPEN_EXISTING, 0,NULL); + if (hCom == INVALID_HANDLE_VALUE) { strcpy(ComErr,"Could not create handle");return -1; } + fSuccess = SetupComm(hCom,1024,1024); + if (!fSuccess) { strcpy(ComErr,"SetupComm failed");CloseHandle(hCom);return -1; } + fSuccess = GetCommTimeouts(hCom,&timeouts); + if (!fSuccess) { strcpy(ComErr,"GetCommTimeouts failed");CloseHandle(hCom);return -1; } + timeouts.ReadIntervalTimeout=MAXDWORD; + fSuccess = SetCommTimeouts(hCom,&timeouts); + if (!fSuccess) { strcpy(ComErr,"SetCommTimeouts failed");CloseHandle(hCom);return -1; } + return 0; +} + +/* MIS FUNCIONES AUXILIARES +*/ +//--------------------------------------------------------------------------- +void __fastcall TSmartCard_Reader::ATR1Click(TObject *Sender) +{ + char buf[255]; + DoReset(); + lenATR=SRead(ATR,27,30); + setarr(buf,ATR,lenATR); + Logger( "ATR == " + AnsiString( buf ) ); +} +//--------------------------------------------------------------------------- + + +void __fastcall TSmartCard_Reader::Edit3KeyPress(TObject *Sender, + char &Key) +{ + if ( Key==VK_RETURN ) + SendCommand( Edit3->Text ); +} +//--------------------------------------------------------------------------- + +void __fastcall TSmartCard_Reader::BitBtn1Click(TObject *Sender) +{ + SendCommand( Edit3->Text ); +} +//--------------------------------------------------------------------------- +void __fastcall TSmartCard_Reader::SendCommand( AnsiString cmd ) +{ + char values[255],out[255]; + getvar( values, cmd.c_str() ); + Send( out, values, values, cmd.Length(), 254 ); + Memo1->Lines->Insert(0, "-----------------------------------------" ); + Memo1->Lines->Insert(0, "Respuesta: "+AnsiString(values) ); + Memo1->Lines->Insert(0, "Enviado comando: "+cmd ); + +} +//--------------------------------------------------------------------------- + diff --git a/Main.dfm b/Main.dfm new file mode 100644 index 0000000..ca19af5 --- /dev/null +++ b/Main.dfm @@ -0,0 +1,208 @@ +object SmartCard_Reader: TSmartCard_Reader + Left = 191 + Top = 116 + Width = 572 + Height = 368 + Caption = 'SmartCard_Reader' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'MS Sans Serif' + Font.Style = [] + Menu = MainMenu1 + OldCreateOrder = False + PixelsPerInch = 96 + TextHeight = 13 + object StatusBar1: TStatusBar + Left = 0 + Top = 303 + Width = 564 + Height = 19 + Panels = <> + SimplePanel = False + end + object PageControl1: TPageControl + Left = 0 + Top = 0 + Width = 564 + Height = 303 + ActivePage = cmdManual + Align = alClient + MultiLine = True + TabOrder = 1 + TabPosition = tpBottom + object TabSheet1: TTabSheet + Caption = 'TabSheet1' + object Label1: TLabel + Left = 0 + Top = 16 + Width = 77 + Height = 13 + Caption = 'Direcci�n inicial:' + end + object Label2: TLabel + Left = 104 + Top = 16 + Width = 44 + Height = 13 + Caption = 'Longitud:' + end + object Edit1: TEdit + Left = 0 + Top = 32 + Width = 80 + Height = 21 + TabOrder = 0 + Text = '0' + end + object Edit2: TEdit + Left = 104 + Top = 32 + Width = 80 + Height = 21 + TabOrder = 1 + Text = '0' + end + object UpDown1: TUpDown + Left = 80 + Top = 32 + Width = 12 + Height = 21 + Associate = Edit1 + Min = 0 + Position = 0 + TabOrder = 2 + Wrap = False + end + object UpDown2: TUpDown + Left = 184 + Top = 32 + Width = 12 + Height = 21 + Associate = Edit2 + Min = 0 + Position = 0 + TabOrder = 3 + Wrap = False + end + object Button1: TButton + Left = 208 + Top = 32 + Width = 75 + Height = 21 + Caption = 'Leer &Eeprom' + TabOrder = 4 + end + end + object TabHistorico: TTabSheet + Caption = 'Hist�rico' + ImageIndex = 1 + object mlog: TMemo + Left = 0 + Top = 0 + Width = 556 + Height = 275 + Align = alClient + Lines.Strings = ( + 'mlog') + ScrollBars = ssVertical + TabOrder = 0 + end + end + object cmdManual: TTabSheet + Caption = 'cmdManual' + ImageIndex = 2 + object Label3: TLabel + Left = 8 + Top = 16 + Width = 80 + Height = 13 + Caption = 'Enviar comando:' + end + object Label4: TLabel + Left = 0 + Top = 48 + Width = 142 + Height = 13 + Caption = 'Respuesta al �ltimo comando:' + end + object Memo1: TMemo + Left = 0 + Top = 64 + Width = 556 + Height = 211 + Align = alBottom + Color = clAppWorkSpace + ReadOnly = True + TabOrder = 0 + end + object Edit3: TEdit + Left = 96 + Top = 8 + Width = 433 + Height = 21 + TabOrder = 1 + OnKeyPress = Edit3KeyPress + end + object BitBtn1: TBitBtn + Left = 528 + Top = 5 + Width = 25 + Height = 25 + Caption = '>>' + TabOrder = 2 + OnClick = BitBtn1Click + end + end + end + object MainMenu1: TMainMenu + Left = 168 + Top = 120 + object Archivo1: TMenuItem + Caption = '&Archivo' + object Acercade1: TMenuItem + Caption = 'Acerca &de...' + end + object N1: TMenuItem + Caption = '-' + end + object Salir1: TMenuItem + Caption = '&Salir' + OnClick = Salir1Click + end + end + object Configuracin1: TMenuItem + Caption = '&Configuraci�n' + object Puertoserie1: TMenuItem + Caption = '&Puerto serie' + OnClick = Puertoserie1Click + end + object N2: TMenuItem + Caption = '-' + end + object Conectar1: TMenuItem + Caption = 'Conectado' + GroupIndex = 1 + RadioItem = True + OnClick = Conectar1Click + end + object Desconectar1: TMenuItem + Caption = 'Desconectado' + Checked = True + GroupIndex = 1 + RadioItem = True + OnClick = Desconectar1Click + end + object N4: TMenuItem + Caption = '-' + GroupIndex = 2 + end + object ATR1: TMenuItem + Caption = 'Reset' + GroupIndex = 2 + OnClick = ATR1Click + end + end + end +end diff --git a/Main.h b/Main.h new file mode 100644 index 0000000..b6c58a1 --- /dev/null +++ b/Main.h @@ -0,0 +1,89 @@ +//--------------------------------------------------------------------------- + +#ifndef MainH +#define MainH +//--------------------------------------------------------------------------- +#include <Classes.hpp> +#include <Controls.hpp> +#include <StdCtrls.hpp> +#include <Forms.hpp> +#include <Menus.hpp> +#include <ComCtrls.hpp> +#include <Buttons.hpp> +//--------------------------------------------------------------------------- +class TSmartCard_Reader : public TForm +{ +__published: // IDE-managed Components + TMainMenu *MainMenu1; + TMenuItem *Archivo1; + TMenuItem *Acercade1; + TMenuItem *N1; + TMenuItem *Salir1; + TMenuItem *Configuracin1; + TMenuItem *Puertoserie1; + TMenuItem *N2; + TMenuItem *Conectar1; + TMenuItem *Desconectar1; + TMenuItem *ATR1; + TMenuItem *N4; + TStatusBar *StatusBar1; + TPageControl *PageControl1; + TTabSheet *TabSheet1; + TTabSheet *TabHistorico; + TMemo *mlog; + TEdit *Edit1; + TLabel *Label1; + TEdit *Edit2; + TUpDown *UpDown1; + TUpDown *UpDown2; + TLabel *Label2; + TButton *Button1; + TTabSheet *cmdManual; + TMemo *Memo1; + TLabel *Label3; + TLabel *Label4; + TEdit *Edit3; + TBitBtn *BitBtn1; + void __fastcall Puertoserie1Click(TObject *Sender); + void __fastcall Conectar1Click(TObject *Sender); + void __fastcall Desconectar1Click(TObject *Sender); + void __fastcall Salir1Click(TObject *Sender); + void __fastcall ATR1Click(TObject *Sender); + void __fastcall Edit3KeyPress(TObject *Sender, char &Key); + void __fastcall BitBtn1Click(TObject *Sender); +private: // User declarations + void __fastcall SendCommand( AnsiString cmd ); +public: // User declarations + __fastcall TSmartCard_Reader(TComponent* Owner); + void __fastcall Logger(AnsiString log); + + + /* Funciones para tratar con el puerto serie... */ + HANDLE hCom; + char ComErr[40],serconfig1[40],serconfig2[40]; + unsigned char ATR[40],ATRinv[40],lenATR; + unsigned long delay; + bool inver, atr; + + void __fastcall CloseCOM(void); + void __fastcall OpenCOM(void); + + DWORD __fastcall SRead(BYTE *buf,DWORD bytes_to_read,DWORD wait); + DWORD __fastcall SWrite(BYTE *buf,DWORD bytes_to_write); + int __fastcall Send(unsigned char *out,char *buf,unsigned char *in,int m,int RL); + + int __fastcall DoReset(void); + int __fastcall SetConfig(const char *serconfig); + unsigned char __fastcall inverso(unsigned char ch); + int __fastcall getbyte(char *buf); + int __fastcall getnyb(char c); + int __fastcall getarr(unsigned char *a,char *buf,int n); + int __fastcall getvar(unsigned char *a,char *buf); + int __fastcall setarr(char *buf,unsigned char *a,int n); + int __fastcall Open(const char *serconfig); + +}; +//--------------------------------------------------------------------------- +extern PACKAGE TSmartCard_Reader *SmartCard_Reader; +//--------------------------------------------------------------------------- +#endif diff --git a/README.md b/README.md new file mode 100644 index 0000000..5ac7696 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +#SmartCard + + +*07/07/2002* + +ToDo: wwtcf? + + + diff --git a/SerieCfg.cpp b/SerieCfg.cpp new file mode 100644 index 0000000..daa7db4 --- /dev/null +++ b/SerieCfg.cpp @@ -0,0 +1,26 @@ +//--------------------------------------------------------------------------- + +#include <vcl.h> +#pragma hdrstop + +#include "SerieCfg.h" +//--------------------------------------------------------------------------- +#pragma package(smart_init) +#pragma resource "*.dfm" +TSerieConf *SerieConf; +//--------------------------------------------------------------------------- +__fastcall TSerieConf::TSerieConf(TComponent* Owner) + : TForm(Owner) +{ +} +//--------------------------------------------------------------------------- +void __fastcall TSerieConf::cancelarClick(TObject *Sender) +{ + ModalResult = mrCancel; +} +//--------------------------------------------------------------------------- +void __fastcall TSerieConf::aceptarClick(TObject *Sender) +{ + ModalResult = mrOk; +} +//--------------------------------------------------------------------------- diff --git a/SerieCfg.dfm b/SerieCfg.dfm new file mode 100644 index 0000000..e8b8957 --- /dev/null +++ b/SerieCfg.dfm @@ -0,0 +1,199 @@ +object SerieConf: TSerieConf + Left = 308 + Top = 598 + AutoScroll = False + BorderIcons = [biSystemMenu] + Caption = 'Configuraci�n del Puerto serie' + ClientHeight = 172 + ClientWidth = 285 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'MS Sans Serif' + Font.Style = [] + OldCreateOrder = False + Position = poScreenCenter + PixelsPerInch = 96 + TextHeight = 13 + object Label1: TLabel + Left = 0 + Top = 16 + Width = 34 + Height = 13 + Caption = 'Puerto:' + end + object Label11: TLabel + Left = 192 + Top = 16 + Width = 16 + Height = 13 + Caption = 'bits' + end + object Label4: TLabel + Left = 136 + Top = 16 + Width = 37 + Height = 13 + Caption = 'baudios' + end + object Label12: TLabel + Left = 224 + Top = 16 + Width = 20 + Height = 13 + Caption = 'pari.' + end + object Label13: TLabel + Left = 256 + Top = 16 + Width = 20 + Height = 13 + Caption = 'stop' + end + object Label7: TLabel + Left = 40 + Top = 40 + Width = 70 + Height = 13 + Caption = 'Antes del reset' + end + object Label8: TLabel + Left = 40 + Top = 64 + Width = 85 + Height = 13 + Caption = 'Despu�s del reset' + end + object Label2: TLabel + Left = 40 + Top = 88 + Width = 30 + Height = 13 + Caption = 'Delay:' + end + object aceptar: TBitBtn + Left = 208 + Top = 112 + Width = 75 + Height = 25 + Caption = '&Aceptar' + TabOrder = 0 + OnClick = aceptarClick + end + object cancelar: TBitBtn + Left = 208 + Top = 144 + Width = 75 + Height = 25 + Caption = '&Cancelar' + TabOrder = 1 + OnClick = cancelarClick + end + object comPort: TComboBox + Left = 40 + Top = 8 + Width = 89 + Height = 21 + ItemHeight = 13 + TabOrder = 2 + Text = 'COM1' + Items.Strings = ( + 'COM1' + 'COM2' + 'COM3' + 'COM4') + end + object stopA: TEdit + Left = 256 + Top = 32 + Width = 25 + Height = 21 + TabOrder = 3 + Text = '2' + end + object pariA: TEdit + Left = 224 + Top = 32 + Width = 25 + Height = 21 + TabOrder = 4 + Text = 'O' + end + object bitsA: TEdit + Left = 192 + Top = 32 + Width = 25 + Height = 21 + TabOrder = 5 + Text = '8' + end + object baudiosA: TEdit + Left = 128 + Top = 32 + Width = 57 + Height = 21 + TabOrder = 6 + Text = '4800' + end + object baudiosD: TEdit + Left = 128 + Top = 56 + Width = 57 + Height = 21 + TabOrder = 7 + Text = '57600' + end + object bitsD: TEdit + Left = 192 + Top = 56 + Width = 25 + Height = 21 + TabOrder = 8 + Text = '8' + end + object pariD: TEdit + Left = 224 + Top = 56 + Width = 25 + Height = 21 + TabOrder = 9 + Text = 'O' + end + object stopD: TEdit + Left = 256 + Top = 56 + Width = 25 + Height = 21 + TabOrder = 10 + Text = '2' + end + object delayTime: TEdit + Left = 128 + Top = 80 + Width = 153 + Height = 21 + TabOrder = 11 + Text = '5000' + end + object ConvenioInverso: TCheckBox + Left = 40 + Top = 112 + Width = 161 + Height = 17 + Caption = 'Convenio Inverso' + Checked = True + State = cbChecked + TabOrder = 12 + end + object ATR: TCheckBox + Left = 40 + Top = 128 + Width = 161 + Height = 17 + Caption = 'ATR despues de conectar' + Checked = True + State = cbChecked + TabOrder = 13 + end +end diff --git a/SerieCfg.h b/SerieCfg.h new file mode 100644 index 0000000..f6db066 --- /dev/null +++ b/SerieCfg.h @@ -0,0 +1,46 @@ +//--------------------------------------------------------------------------- + +#ifndef SerieCfgH +#define SerieCfgH +//--------------------------------------------------------------------------- +#include <Classes.hpp> +#include <Controls.hpp> +#include <StdCtrls.hpp> +#include <Forms.hpp> +#include <Buttons.hpp> +//--------------------------------------------------------------------------- +class TSerieConf : public TForm +{ +__published: // IDE-managed Components + TBitBtn *aceptar; + TBitBtn *cancelar; + TComboBox *comPort; + TLabel *Label1; + TLabel *Label11; + TLabel *Label4; + TLabel *Label12; + TLabel *Label13; + TEdit *stopA; + TEdit *pariA; + TEdit *bitsA; + TEdit *baudiosA; + TEdit *baudiosD; + TEdit *bitsD; + TEdit *pariD; + TEdit *stopD; + TLabel *Label7; + TLabel *Label8; + TLabel *Label2; + TEdit *delayTime; + TCheckBox *ConvenioInverso; + TCheckBox *ATR; + void __fastcall cancelarClick(TObject *Sender); + void __fastcall aceptarClick(TObject *Sender); +private: // User declarations +public: // User declarations + __fastcall TSerieConf(TComponent* Owner); +}; +//--------------------------------------------------------------------------- +extern PACKAGE TSerieConf *SerieConf; +//--------------------------------------------------------------------------- +#endif diff --git a/TEMP/emv.exe b/TEMP/emv.exe new file mode 100644 index 0000000..33294cc Binary files /dev/null and b/TEMP/emv.exe differ diff --git a/TEMP/mondex.spt b/TEMP/mondex.spt new file mode 100644 index 0000000..8c188ef --- /dev/null +++ b/TEMP/mondex.spt @@ -0,0 +1,15 @@ +00 a4 08 0c 02 00 +2f 00 +00 b2 01 04 00 02 +00 b2 01 04 00 29 +00 a4 04 0c 08 00 +a0 00 00 00 02 01 99 04 +80 24 00 00 00 03 +80 22 00 00 00 6c +80 54 00 00 00 33 +80 2a 00 00 00 1c +80 38 00 00 03 05 +55 53 44 +end + + diff --git a/TEMP/readme.txt b/TEMP/readme.txt new file mode 100644 index 0000000..bb90f07 --- /dev/null +++ b/TEMP/readme.txt @@ -0,0 +1,42 @@ +PCSC Test Program +v.0.7 (c) Andrew Whitaker + +It can run in either of threemodes. + +Mode 1: +Command line parameter mondex +ie: emv mondex +Automatically does +Application Selection +Purse Register +Register +Payment Register +Read Pocket Record +Currency Enquiry + +Mode 2: +With a command line parameter of the name of a script. I have enclosed a sample script that does the same functions as mode 1 but in a non intelligent way, eg. Register length hard coded not read from purse register. +So: emv mondex.spt is the command line. The file extension can be anything you like. +The structure of the file is as follows: + + +00 a4 08 0c 02 00 +2f 00 +This is CLA INS P1 P2 LC LE +Then data + +00 b2 01 04 00 02 +No LC so no data line + +80 38 00 00 03 05 +55 53 44 +LC and LE so data line + +end +The end just shows the end of the script file. + + +Mode 3: + +emv test +forces the pc/sc resource manager dialog to appear and connects to the reader and then disconnects. diff --git a/leeme.txt b/leeme.txt new file mode 100644 index 0000000..0c7893b --- /dev/null +++ b/leeme.txt @@ -0,0 +1,2 @@ +Inicializando el puerto: COM2: baud=9600 parity=O data=8 stop=2 +ATR == 23 9b ff ff 9b fd ff f6 ff diff --git a/smartcard.bpr b/smartcard.bpr new file mode 100644 index 0000000..996b8e6 --- /dev/null +++ b/smartcard.bpr @@ -0,0 +1,109 @@ +<?xml version='1.0' encoding='utf-8' ?> +<!-- C++Builder XML Project --> +<PROJECT> + <MACROS> + <VERSION value="BCB.05.03"/> + <PROJECT value="smartcard.exe"/> + <OBJFILES value="smartcard.obj Main.obj SerieCfg.obj"/> + <RESFILES value="smartcard.res"/> + <IDLFILES value=""/> + <IDLGENFILES value=""/> + <DEFFILE value=""/> + <RESDEPEN value="$(RESFILES) Main.dfm SerieCfg.dfm"/> + <LIBFILES value=""/> + <LIBRARIES value="VCL50.lib"/> + <SPARELIBS value="VCL50.lib"/> + <PACKAGES value="VCL50.bpi VCLX50.bpi VCLDB50.bpi QRPT50.bpi VCLBDE50.bpi VCLIE50.bpi + INETDB50.bpi INET50.bpi NMFAST50.bpi dclocx50.bpi CabForCB.bpi + CoolPack.bpi JDsoft.bpi PhantomPack.bpi VCLIB50.bpi VCLMID50.bpi + WEBMID50.bpi VCLDBX50.bpi TEEQR50.bpi asgc5.bpi RAS_Tools.bpi + ZCommonCB5.bpi ZDbwareCB5.bpi ZMySqlCB5.bpi ZDb2SqlCB5.bpi ZIbSqlCB5.bpi + ZMsSqlCB5.bpi ZOraSqlCB5.bpi ZPgSqlCB5.bpi TEEUI50.bpi TEEDB50.bpi + TEE50.bpi DSS50.bpi bcbsmp50.bpi VCLADO50.bpi ibsmp50.bpi bcbie50.bpi + bcb2kaxserver50.bpi"/> + <PATHCPP value=".;"/> + <PATHPAS value=".;"/> + <PATHRC value=".;"/> + <PATHASM value=".;"/> + <DEBUGLIBPATH value="$(BCB)\lib\debug"/> + <RELEASELIBPATH value="$(BCB)\lib\release"/> + <LINKER value="tlink32"/> + <USERDEFINES value="_DEBUG"/> + <SYSDEFINES value="NO_STRICT"/> + <MAINSOURCE value="smartcard.cpp"/> + <INCLUDEPATH value="..\ViaMosc;$(BCB)\include;$(BCB)\include\vcl"/> + <LIBPATH value="..\ViaMosc;$(BCB)\Projects\Lib;..\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib"/> + <WARNINGS value="-w-par"/> + </MACROS> + <OPTIONS> + <IDLCFLAGS value="-I..\ViaMosc -I$(BCB)\include -I$(BCB)\include\vcl -src_suffix cpp + -D_DEBUG -boa"/> + <CFLAG1 value="-Od -H=$(BCB)\lib\vcl50.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c + -tW -tWM"/> + <PFLAGS value="-$YD -$W -$O- -v -JPHNE -M"/> + <RFLAGS value=""/> + <AFLAGS value="/mx /w2 /zd"/> + <LFLAGS value="-D"" -aa -Tpe -x -Gn -v"/> + </OPTIONS> + <LINKER> + <ALLOBJ value="c0w32.obj sysinit.obj $(OBJFILES)"/> + <ALLRES value="$(RESFILES)"/> + <ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib"/> + </LINKER> + <IDEOPTIONS> +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=3082 +CodePage=1252 + +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= + +[Excluded Packages] +C:\Mis documentos\Fuentes de Programacion\C++ Builder\CAP\LM2000_vcl\LM2000_vcl.bpl=Funciones para el Manejo del LM2000 + +[Debugging] +DebugSourceDirs=$(BCB)\source\vcl + +[Parameters] +RunParams= +HostApplication= +RemoteHost= +RemotePath= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=0 +LinkCGLIB=0 + +[CORBA] +AddServerUnit=1 +AddClientUnit=1 +PrecompiledHeaders=1 + +[Language] +ActiveLang= +ProjectLang= +RootDir= + </IDEOPTIONS> +</PROJECT> \ No newline at end of file diff --git a/smartcard.cpp b/smartcard.cpp new file mode 100644 index 0000000..c662aa6 --- /dev/null +++ b/smartcard.cpp @@ -0,0 +1,23 @@ +//--------------------------------------------------------------------------- + +#include <vcl.h> +#pragma hdrstop +USERES("smartcard.res"); +USEFORM("Main.cpp", SmartCard_Reader); +USEFORM("SerieCfg.cpp", SerieConf); +//--------------------------------------------------------------------------- +WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) +{ + try + { + Application->Initialize(); + Application->CreateForm(__classid(TSmartCard_Reader), &SmartCard_Reader); + Application->Run(); + } + catch (Exception &exception) + { + Application->ShowException(&exception); + } + return 0; +} +//--------------------------------------------------------------------------- diff --git a/smartcard.exe b/smartcard.exe new file mode 100644 index 0000000..86c9243 Binary files /dev/null and b/smartcard.exe differ diff --git a/smartcard.rar b/smartcard.rar new file mode 100644 index 0000000..6aa7907 Binary files /dev/null and b/smartcard.rar differ diff --git a/smartcard.res b/smartcard.res new file mode 100644 index 0000000..1392cb0 Binary files /dev/null and b/smartcard.res differ