-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathPCSCConnector.pas
More file actions
699 lines (630 loc) · 21.5 KB
/
PCSCConnector.pas
File metadata and controls
699 lines (630 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
{******************************************************************}
{ }
{ PC/SC Interface component }
{ Helps you access a cardreader through Microsofts SmartCard API }
{ }
{ The Original Code is PCSCConnector.pas }
{ }
{ The Initial Developer of the Original Code is }
{ Norbert Huettisch (nobbi(at)nobbi.com) }
{ }
{ Any suggestions and improvements to the code are appreciated }
{ }
{ This Code uses a modified SCardErr.pas (included) }
{ This Code uses a modified WinSCard.pas (included) }
{ This code uses the original WinSmCrd.pas (included) }
{ }
{ All originally made by Chris Dickerson (chrisd(at)tsc.com), }
{ available as 'Interface units for the Microsoft Smart Card API' }
{ at the Project JEDI Homepage http://www.delphi-jedi.org }
{ }
{ Version info: }
{ 021230 - initial version }
{ 030101 - routed errors from 'init' to the OnError event }
{ }
{ }
{******************************************************************}
{ }
{ The contents of this file are subject to the }
{ }
{ Mozilla Public License Version 1.1 (the "License") }
{ }
{ You may not use this file except in compliance with the License. }
{ You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
{ implied. See the License for the specific language governing }
{ rights and limitations under the License. }
{ }
{******************************************************************}
unit PCSCConnector;
interface
uses
Windows, Messages, Forms, Classes, SysUtils,
SCardErr, WinSCard, WinSmCrd;
type
TErrSource = (esInit, esConnect, esGetStatus, esTransmit);
TNeededPIN = (npPIN1, npPIN2, npPUK1, npPUK2);
TDelimiters = set of Char;
TPCSCErrorEvent = procedure(Sender: TObject; ErrSource: TErrSource; ErrCode: cardinal) of object;
TPCSCPinEvent = procedure(Sender: TObject; NeedPIN: TNeededPIN) of object;
const
MAXAPDULENGTH = 260; // CLA + INS + P1..3 + 255Bytes
NOREADERSELECTED = -1;
SCARD_PCI_T0 : SCARD_IO_REQUEST = (dwProtocol:1; dbPciLength:8);
SCARD_PCI_T1 : SCARD_IO_REQUEST = (dwProtocol:2; dbPciLength:8);
SCARD_PROTOCOL_T0 = $00000001;
SCARD_PROTOCOL_T1 = $00000002;
SCARD_PROTOCOL_RAW = $00010000;
SCARD_PROTOCOL_UNK = $00000000;
WM_CARDSTATE = WM_USER + 42;
GSMStatusOK = $9000;
GSMStatusMemoryError = $9240;
GSMStatusNoEFSelected = $9400;
GSMStatusOutOfRange = $9402;
GSMStatusNotFound = $9404;
GSMStatusFCDoNotMatch = $9408;
GSMStatusCHVNeeded = $9802;
GSMStatusAuthFailed = $9804;
GSMStatusAuthFailedBl = $9840;
GSMStatusTechProblem = $6F00;
GSMStatusResponseData = $9F;
GSMFileTypeRFU = 0;
GSMFileTypeMF = 1;
GSMFileTypeDF = 2;
GSMFileTypeEF = 4;
GSMEfTransp = 0;
GSMEfLinFixed = 1;
GSMEfCyclic = 3;
type
TPCSCConnector = class(TComponent)
protected
FContext : cardinal;
FCardHandle : integer;
FConnected : boolean;
FNumReaders : integer;
FUseReaderNum : integer;
FReaderList : TStringlist;
FAttrProtocol : integer;
FAttrICCType : string;
FAttrCardATR : string;
FAttrVendorName : string;
FAttrVendorSerial : string;
FGSMCurrentFile : string;
FGSMFileInfo : string;
FGSMDirInfo : string;
FGSMVoltage30 : boolean;
FGSMVoltage18 : boolean;
FOnReaderWaiting : TNotifyEvent;
FOnReaderListChange : TNotifyEvent;
FOnCardInserted : TNotifyEvent;
FOnCardActive : TNotifyEvent;
FOnCardRemoved : TNotifyEvent;
FOnCardInvalid : TNotifyEvent;
FOnError : TPCSCErrorEvent;
FOnCHVNeeded : TPCSCPinEvent;
procedure SetReaderNum(Value: integer);
procedure MessageWndProc(var Msg: TMessage);
function ConnectSelectedReader: boolean;
procedure ProcessReaderState(const OldState,NewState: cardinal);
procedure GetReaderAttributes;
procedure GetCardAttributes;
procedure ClearReaderAttributes;
procedure ClearCardAttributes;
function IsReaderOpen: boolean;
function GetReaderState: cardinal;
procedure CloseAndDisconnect;
procedure CardInsertedAction;
procedure CardActiveAction;
procedure CardRemovedAction;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Init: boolean;
function Open: boolean;
procedure Close;
function Connect: boolean;
procedure Disconnect;
function GetResponseFromCard(const apdu: string): string; overload;
function GetResponseFromCard(const command: string; var data: string; var sw1, sw2: byte): boolean; overload;
function GSMStatus: integer;
function GSMSelect(const FileID: string): integer;
function GSMReadBinary(const Offset, Length: integer; var Data: string): integer;
published
property UseReaderNum: integer read FUseReaderNum write SetReaderNum default -1;
property OnCardInserted: TNotifyEvent read FOnCardInserted write FOnCardInserted;
property OnCardActive: TNotifyEvent read FOnCardActive write FOnCardActive;
property OnCardRemoved: TNotifyEvent read FOnCardRemoved write FOnCardRemoved;
property OnCardInvalid: TNotifyEvent read FOnCardInvalid write FOnCardInvalid;
property OnReaderWaiting: TNotifyEvent read FOnReaderWaiting write FOnReaderWaiting;
property OnReaderListChange: TNotifyEvent read FOnReaderListChange write FOnReaderListChange;
property OnError: TPCSCErrorEvent read FOnError write FOnError;
property OnCHVNeeded: TPCSCPinEvent read FOnCHVNeeded write FOnCHVNeeded;
property ReaderList: TStringList read FReaderList;
property NumReaders: integer read FNumReaders;
property Connected: boolean read FConnected;
property Opened: boolean read IsReaderOpen;
property ReaderState: cardinal read GetReaderState;
property AttrProtocol: integer read FAttrProtocol;
property AttrICCType: string read FAttrICCType;
property AttrCardATR: string read FAttrCardATR;
property AttrVendorName: string read FAttrVendorName;
property AttrVendorSerial: string read FAttrVendorSerial;
property GSMCurrentFile: string read FGSMCurrentFile;
property GSMFileInfo: string read FGSMFileInfo;
property GSMDirInfo: string read FGSMDirInfo;
property GSMVoltage30: boolean read FGSMVoltage30;
property GSMVoltage18: boolean read FGSMVoltage18;
end;
procedure Register;
implementation
var
ActReaderState : cardinal;
LastReaderState : cardinal;
SelectedReader : PChar;
ReaderOpen : boolean;
NotifyHandle : HWND;
const
// GSM Commands
GCGetStatus = #$A0#$F2#$00#$00#$16;
GCGetResponse = #$A0#$C0#$00#$00;
GCSelectFile = #$A0#$A4#$00#$00#$02;
GCReadBinary = #$A0#$B0;
GSMMasterFile = #$3f#$00;
DFgsm900 = #$7f#$20;
DFgsm1800 = #$7f#$21;
procedure Register;
begin
RegisterComponents('More...', [TPCSCConnector]);
end;
function SortOutSubstrings(const From:string; var t:array of string; const Delim:TDelimiters = [' ',';']; const ConcatDelim:boolean = true):integer;
var a,b,s,i : integer;
sep : boolean;
begin
a := 1;
b := Low(t);
s := 1;
i := 0;
sep := ConcatDelim;
t[b] := '';
while a <= Length(From) do
begin
if not (From[a] in Delim) then
begin
Inc(i);
sep := false;
end else
begin
if not sep then
begin
t[b] := Copy(From, s, i);
Inc(b);
if b > High(t) then Break;
t[b] := '';
end;
if ConcatDelim then sep := true;
s := a + 1;
i := 0;
end;
Inc(a);
end;
if (b <= High(t)) and (i > 0) then
begin
t[b] := Copy(From, s, i);
Inc(b);
end;
for a := b + 1 to High(t) do t[a] := '';
Result := b;
end;
function OrdD(const From: string; const Index: integer): integer;
begin
if Index <= Length(From) then Result := Ord(From[Index])
else Result := 0;
end;
function CardWatcherThread(PContext: pointer): integer;
var
RetVar : cardinal;
RContext : cardinal;
RStates : array[0..1] of SCARD_READERSTATEA;
begin
try
RContext := cardinal(PContext^);
FillChar(RStates,SizeOf(RStates),#0);
RStates[0].szReader := SelectedReader;
RStates[0].pvUserData := nil;
RStates[0].dwEventState := ActReaderState;
while ReaderOpen do
begin
RStates[0].dwCurrentState := RStates[0].dwEventState;
RetVar := SCardGetStatusChangeA(RContext, -1, RStates, 1);
ActReaderState := RStates[0].dwEventState;
PostMessage(NotifyHandle, WM_CARDSTATE, RetVar, 0);
end;
finally
Result := 0;
end;
end;
procedure TPCSCConnector.MessageWndProc(var Msg: TMessage);
begin
if (Msg.Msg = WM_CARDSTATE) then
begin
if Msg.WParam <> SCARD_S_SUCCESS then
if Assigned(FOnError) then FOnError(Self, esGetStatus, Msg.WParam);
if ActReaderState <> LastReaderState then
begin
ProcessReaderState(LastReaderState, ActReaderState);
end;
end
else Msg.Result := DefWindowProc(NotifyHandle, Msg.Msg, Msg.WParam, Msg.LParam);
end;
constructor TPCSCConnector.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FReaderList := TStringlist.Create;
FContext := 0;
FCardHandle := 0;
FNumReaders := 0;
FUseReaderNum := -1;
FConnected := false;
ActReaderState := SCARD_STATE_UNAWARE;
LastReaderState := SCARD_STATE_UNAWARE;
ReaderOpen := false;
ClearReaderAttributes;
ClearCardAttributes;
if not (csDesigning in ComponentState) then NotifyHandle := AllocateHWnd(MessageWndProc);
end;
destructor TPCSCConnector.Destroy;
begin
CloseAndDisconnect;
SCardReleaseContext(FContext);
FReaderList.Free;
if not (csDesigning in ComponentState) then DeallocateHWnd(NotifyHandle);
inherited Destroy;
end;
function TPCSCConnector.Init: boolean;
var
RetVar : cardinal;
ReaderList : string;
ReaderListSize : integer;
v : array[0..MAXIMUM_SMARTCARD_READERS] of string;
i : integer;
begin
Result := false;
FNumReaders := 0;
CloseAndDisconnect;
if SCardIsValidContext(FContext) = SCARD_S_SUCCESS then SCardReleaseContext(FContext);
RetVar := SCardEstablishContext(SCARD_SCOPE_USER, nil, nil, @FContext);
if RetVar = SCARD_S_SUCCESS then
begin
ReaderListSize := 0;
RetVar := SCardListReadersA(FContext, nil, nil, ReaderListSize);
if RetVar = SCARD_S_SUCCESS then
begin
SetLength(ReaderList, ReaderListSize);
SCardListReadersA(FContext, nil, Pointer(ReaderList), ReaderListSize);
FReaderList.Clear;
SortOutSubstrings(ReaderList,v,[#0]);
for i := 0 to MAXIMUM_SMARTCARD_READERS do
if v[i] <> '' then FReaderList.Add(v[i]);
FNumReaders := FReaderList.Count;
if FNumReaders > 0 then
begin
if Assigned(FOnReaderListChange) then FOnReaderListChange(Self);
Result := true;
end;
end else if Assigned(FOnError) then FOnError(Self, esInit, RetVar);
end else if Assigned(FOnError) then FOnError(Self, esInit, RetVar);
end;
function TPCSCConnector.Open: boolean;
var
ThreadID : LongWord;
begin
CloseAndDisconnect;
if (FUseReaderNum > NOREADERSELECTED) and
(SCardIsValidContext(FContext) = SCARD_S_SUCCESS) then
begin
ReaderOpen := true;
ActReaderState := SCARD_STATE_UNAWARE;
LastReaderState := SCARD_STATE_UNAWARE;
BeginThread(nil, 0, CardWatcherThread, @FContext, 0, ThreadID);
Result := true;
end else Result := false;
end;
procedure TPCSCConnector.Close;
begin
ReaderOpen := false;
SCardCancel(FContext);
if FConnected then Disconnect;
end;
function TPCSCConnector.Connect: boolean;
begin
if FConnected then Disconnect;
if FUseReaderNum > NOREADERSELECTED then
if ConnectSelectedReader then FConnected := true
else FConnected := false;
Result := FConnected;
end;
procedure TPCSCConnector.Disconnect;
begin
if FConnected then
begin
SCardDisconnect(FCardHandle, SCARD_RESET_CARD);
FConnected := false;
FCardHandle := 0;
end;
end;
procedure TPCSCConnector.CloseAndDisconnect;
begin
if FConnected then Disconnect;
if ReaderOpen then Close;
end;
function TPCSCConnector.ConnectSelectedReader: boolean;
var
RetVar : cardinal;
begin
RetVar := SCardConnectA(FContext,
SelectedReader,
SCARD_SHARE_EXCLUSIVE,
SCARD_PROTOCOL_Tx,
FCardHandle,
@FAttrProtocol);
case RetVar of
SCARD_S_SUCCESS : begin
CardActiveAction;
Result := true;
end;
SCARD_W_REMOVED_CARD : begin
Result := true;
end;
else begin
Result := false;
if Assigned(FOnError) then FOnError(Self, esConnect, RetVar);
end;
end;
end;
procedure TPCSCConnector.ProcessReaderState(const OldState,NewState: cardinal);
var
CardInOld, CardInNew : boolean;
ReaderEmOld, ReaderEmNew : boolean;
CardMuteOld, CardMuteNew : boolean;
CardIgnore : boolean;
begin
CardInOld := (OldState and SCARD_STATE_PRESENT) > 0;
CardInNew := (NewState and SCARD_STATE_PRESENT) > 0;
ReaderEmOld := (OldState and SCARD_STATE_EMPTY) > 0;
ReaderEmNew := (NewState and SCARD_STATE_EMPTY) > 0;
CardMuteOld := (OldState and SCARD_STATE_MUTE) > 0;
CardMuteNew := (NewState and SCARD_STATE_MUTE) > 0;
CardIgnore := (NewState and SCARD_STATE_IGNORE) > 0;
if CardMuteNew and
not CardMuteold then if Assigned(FOnCardInvalid) then FOnCardInvalid(Self);
if CardInNew and
not CardInOld and
not CardMuteNew and
not CardIgnore then CardInsertedAction;
if CardInOld and
not CardInNew then CardRemovedAction;
if ReaderEmNew and
not ReaderEmOld then begin
if Assigned(FOnReaderWaiting) then FOnReaderWaiting(Self);
end;
LastReaderState := NewState;
end;
procedure TPCSCConnector.CardInsertedAction;
begin
if Assigned(FOnCardInserted) then FOnCardInserted(Self);
if FConnected then CardActiveAction;
end;
procedure TPCSCConnector.CardActiveAction;
begin
GetReaderAttributes;
if FAttrProtocol <> SCARD_PROTOCOL_UNK then
begin
GetCardAttributes;
if Assigned(FOnCardActive) then FOnCardActive(Self);
end;
end;
procedure TPCSCConnector.CardRemovedAction;
begin
ClearReaderAttributes;
ClearCardAttributes;
if Assigned(FOnCardRemoved) then FOnCardRemoved(Self);
Disconnect;
end;
procedure TPCSCConnector.SetReaderNum(Value: Integer);
begin
if Value <> FUseReaderNum then
begin
CloseAndDisconnect;
if Value < FReaderList.Count then
begin
SelectedReader := PChar(FReaderList[Value]);
FUseReaderNum := Value;
end else
begin
SelectedReader := '';
FUseReaderNum := -1;
end;
end;
end;
function TPCSCConnector.IsReaderOpen: boolean;
begin
Result := ReaderOpen;
end;
function TPCSCConnector.GetReaderState: cardinal;
begin
Result := ActReaderState;
end;
procedure TPCSCConnector.GetReaderAttributes;
var
RetVar : cardinal;
ABuf : string;
AIBuf : integer;
ALen : integer;
begin
ABuf := StringOfChar(#0, 127);
ALen := Length(ABuf);
RetVar := SCardGetAttrib(FCardHandle, SCARD_ATTR_ATR_STRING, Pointer(ABuf), @ALen);
if RetVar = SCARD_S_SUCCESS then FAttrCardATR := Copy(ABuf, 1, ALen)
else FAttrCardATR := '';
ALen := Length(ABuf);
RetVar := SCardGetAttrib(FCardHandle, SCARD_ATTR_VENDOR_NAME, Pointer(ABuf), @ALen);
if RetVar = SCARD_S_SUCCESS then FAttrVendorName := Copy(ABuf, 1, ALen)
else FAttrVendorName := '';
ALen := Length(ABuf);
RetVar := SCardGetAttrib(FCardHandle, SCARD_ATTR_VENDOR_IFD_SERIAL_NO, Pointer(ABuf), @ALen);
if RetVar = SCARD_S_SUCCESS then FAttrVendorSerial := Copy(ABuf, 1, ALen)
else FAttrVendorSerial := '';
ALen := SizeOf(AIBuf);
RetVar := SCardGetAttrib(FCardHandle, SCARD_ATTR_CURRENT_PROTOCOL_TYPE, @AIBuf, @ALen);
if RetVar = SCARD_S_SUCCESS then FAttrProtocol := AIBuf
else FAttrProtocol := 0;
ALen := SizeOf(AIBuf);
AIBuf := 0;
RetVar := SCardGetAttrib(FCardHandle, SCARD_ATTR_ICC_TYPE_PER_ATR, @AIBuf, @ALen);
if RetVar = SCARD_S_SUCCESS then begin
case AIBuf of
1 : FAttrICCType := 'ISO7816A';
2 : FAttrICCType := 'ISO7816S';
else FAttrICCType := 'UNKNOWN';
end;
end
else FAttrICCType := '';
end;
procedure TPCSCConnector.GetCardAttributes;
begin
if GSMSelect(DFgsm900) = GSMStatusOK then
begin
FGSMVoltage30 := (OrdD(FGSMDirInfo, 14) and $10) > 0;
FGSMVoltage18 := (OrdD(FGSMDirInfo, 14) and $20) > 0;
end;
end;
procedure TPCSCConnector.ClearReaderAttributes;
begin
FAttrCardATR := '';
FAttrVendorName := '';
FAttrVendorSerial := '';
FAttrProtocol := 0;
FAttrICCType := '';
end;
procedure TPCSCConnector.ClearCardAttributes;
begin
FGSMCurrentFile := '';
FGSMFileInfo := '';
FGSMDirInfo := '';
FGSMVoltage30 := false;
FGSMVoltage18 := false;
end;
function TPCSCConnector.GetResponseFromCard(const APdu: string): string;
var
RetVar : cardinal;
SBuf : string;
SLen : cardinal;
RBuf : string;
RLen : cardinal;
Ppci : Pointer;
begin
SBuf := APdu;
RBuf := StringOfChar(#0,MAXAPDULENGTH);
if Length(SBuf) <= MAXAPDULENGTH then
begin
case FAttrProtocol of
SCARD_PROTOCOL_T0 : Ppci := @SCARD_PCI_T0;
SCARD_PROTOCOL_T1 : Ppci := @SCARD_PCI_T1;
else Ppci := nil;
end;
SLen := Length(APdu);
RLen := Length(RBuf);
RetVar := SCardTransmit(FCardHandle, Ppci, Pointer(SBuf), SLen, nil, Pointer(RBuf), @RLen);
if RetVar = SCARD_S_SUCCESS then
begin
Result := Copy(RBuf,1,RLen);
end else
begin
Result := '';
if Assigned(FOnError) then FOnError(Self, esTransmit, RetVar);
end;
end;
end;
function TPCSCConnector.GetResponseFromCard(const Command: string; var Data: string; var sw1, sw2: byte): boolean;
var
Answer : string;
AnswerL : integer;
begin
Answer := GetResponseFromCard(Command + Data);
AnswerL := Length(Answer);
if AnswerL >= 2 then
begin
Data := Copy(Answer, 1, AnswerL - 2);
sw1 := Ord(Answer[AnswerL - 1]);
sw2 := Ord(Answer[AnswerL]);
if sw1 = GSMStatusResponseData then
begin
Data := Chr(sw2);
if not GetResponseFromCard(GCGetResponse, Data, sw1, sw2) then
begin
Data := '';
sw1 := 0;
sw2 := 0;
Result := false;
end else Result := true;
end else Result := true;
end else
begin
Data := '';
sw1 := 0;
sw2 := 0;
Result := false;
end;
end;
function TPCSCConnector.GSMStatus: integer;
var
Answer : string;
sw1, sw2 : byte;
begin
GetResponseFromCard(GCGetStatus, Answer, sw1, sw2);
Result := (sw1 shl 8) + sw2;
if Result = GSMStatusOK then
begin
FGSMDirInfo := Answer;
FGSMCurrentFile := Copy(Answer, 5, 2);
end else
begin
FGSMDirInfo := '';
end;
end;
function TPCSCConnector.GSMSelect(const FileID: string): integer;
var
Answer : string;
sw1, sw2 : byte;
begin
Answer := FileID;
GetResponseFromCard(GCSelectFile, Answer, sw1, sw2);
Result := (sw1 shl 8) + sw2;
if Result = GSMStatusOK then
begin
FGSMCurrentFile := Copy(Answer, 5, 2);
if OrdD(Answer, 7) = GSMFileTypeEF then
begin
FGSMFileInfo := Answer;
end else
begin
FGSMDirInfo := Answer;
end;
end;
end;
function TPCSCConnector.GSMReadBinary(const Offset, Length: integer; var Data: string): integer;
var
Command : string;
sw1, sw2 : byte;
begin
Command := GCReadBinary + Chr(Offset div 256) + Chr(Offset mod 256) + Chr(Length mod 256);
GetResponseFromCard(Command, Data, sw1, sw2);
Result := (sw1 shl 8) + sw2;
if Result = GSMStatusOK then
begin
end;
end;
end.