forked from nikmes/iso8583lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso8583.cs
1387 lines (1093 loc) · 51 KB
/
iso8583.cs
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using LibTLV;
using ConvertionsHelper;
using LogingUtils;
namespace iso8583
{
// Enum types used by iso8583 module
public enum rType
{
INCOMMING,
OUTGOING
}
public enum FieldType
{
A, // Alpha, including blanks
N, // Numeric values only
S, // Special characters only
AN, // Alphanumeric
AS, // Alpha & Special Characters only
NS, // Numeric & Special Characters only
ANS, // Alphabetic, numberic and special characters
B, // Binary data
Z, // Track 2 and 3 code set as defined in ISO/IEC 7813 and ISO/IEC 4909 respectively
NULL, // No data type
BITMAP // BITMAP
}
public enum LengthType
{
FIXED, // Fixed Length field, no length indicator
LLVAR, // variable length field, 1 bytes used for length indicator
LLLVAR // variable length field, 2 bytes used for length indicator
}
public enum EncodingType
{
ASCII, // Value: 0800 30 38 30 30 [4 bytes to represent]
BCD, // Value: 0800 - 08 00 [2 bytes to represent]
EBCDIC, // Value:
HEX, //
NULL, // No encoding type
}
public enum Particiation
{
MANDATORY, // Field is mandatory in a message
OPTIONAL, // Field is optional in a message
DONTEXIST // Field dose not exists at all in a message
}
public class isoHeader
{
byte[] m_headerData; // holds the raw data of the header
public isoHeader()
{
m_headerData = new byte[5];
}
public isoHeader(byte[] header)
{
// initialize header data with incomming byte array
m_headerData = header;
}
public isoHeader(String header)
{
// sets the header data from HEX string
m_headerData = ConvHelper.hex2bytes(header);
}
public void setHeader(String header)
{
// sets the header data from HEX string
m_headerData = ConvHelper.hex2bytes(header);
}
public void setHeader(byte[] header)
{
// sets the header data from byte array
m_headerData = header;
}
public byte[] getHeaderBYTE()
{
// returns the byte array with header data
return m_headerData;
}
public String getHeaderHEX()
{
// returns the hexadecimal representation of the header
return ConvHelper.bytes2hex(m_headerData, m_headerData.Length, 0);
}
public String getHeaderBINARY()
{
// returns the binary bitmap representation of the header
return ConvHelper.hex2bin(ConvHelper.bytes2hex(m_headerData, m_headerData.Length, 0));
}
public int getHeaderLength()
{
// returns the binary bitmap representation of the header
return m_headerData.Length;
}
}
public class isoBitmap
{
byte[] m_bitmapData; // holds the raw bytes of bitmap
public isoBitmap()
{
// Initialize Bitmap Properties
m_bitmapData = new byte[24];
}
public isoBitmap(byte[] bitmap)
{
// Initialize bitmap with incomming raw data
m_bitmapData = bitmap;
}
public isoBitmap(String bitmap)
{
// Initialize bitmap with incomming HEXADECIMAL representation of data
m_bitmapData = ConvHelper.hex2bytes(bitmap);
}
public bool bitIsSet(int field)
{
// Checks if a bit in the bitmap is set
if (field < 2)
{
// nothing to set. Field 000 Message type and 001 Bitmap are always present
return true;
}
String bitmapBin = ConvHelper.hex2bin(ConvHelper.bytes2hex(m_bitmapData, m_bitmapData.Length, 0));
if (bitmapBin[field - 1] == '1')
{
return true;
}
else
{
return false;
}
}
public void setBit(int fieldNumber)
{
// Sets field participation indicator in bitmap. Even if field in message has data it wont be send
if (fieldNumber < 2)
{
// nothing to set. Field 000 Message type and 001 Bitmap are always present
return;
}
String bitmapBin = ConvHelper.hex2bin(ConvHelper.bytes2hex(m_bitmapData, m_bitmapData.Length, 0));
StringBuilder sb = new StringBuilder(bitmapBin);
sb[fieldNumber - 1] = '1';
bitmapBin = sb.ToString();
String BitmapHex = ConvHelper.bin2hex(bitmapBin);
m_bitmapData = ConvHelper.hex2bytes(BitmapHex);
}
public void clearBit(int fieldNumber)
{
// Clears field participation indicator in bitmap. Even if field in message has data it wont be send
if (fieldNumber < 3)
{
return;
}
String bitmapBin = ConvHelper.hex2bin(ConvHelper.bytes2hex(m_bitmapData, m_bitmapData.Length, 0));
StringBuilder sb = new StringBuilder(bitmapBin);
sb[fieldNumber - 1] = '0';
bitmapBin = sb.ToString();
String BitmapHex = ConvHelper.bin2hex(bitmapBin);
m_bitmapData = ConvHelper.hex2bytes(BitmapHex);
}
public byte[] getBitmapBYTE()
{
// Returns the raw data of bitmap to be included in outgoing buffer
// should detect if first,second,third bitmap is used and return appropriate part of byte sequence
return (m_bitmapData);
}
public string getBitmapHEX()
{
// Returns the hexadecimal representation of raw data of bitmap
return ConvHelper.bytes2hex(m_bitmapData, m_bitmapData.Length, 0);
}
public string getBitmapBINARY()
{
// Returns the binary sequence representation of the bitmap
return ConvHelper.hex2bin(ConvHelper.bytes2hex(m_bitmapData, m_bitmapData.Length, 0));
}
}
public class isoFieldDefinition
{
public FieldType fieldType;
public EncodingType fieldEncoding;
public LengthType lengthType;
public EncodingType lengthEncoding;
public String name;
public String description;
public int number;
public int lenLength;
public int fixedLength;
public isoFieldDefinition(int fn, FieldType ft, EncodingType fe, LengthType lt, EncodingType le, int fl)
{
fieldType = ft; // the data type of the field data
lengthType = lt; // the length type FIXED,LVAR, LLVAR or LLLVAR
if (lengthType == LengthType.LLVAR)
{
lenLength = 1; // check the encoding to decide how many bytes needed. if BCD then 1 byte is enough
lengthEncoding = le; // the length indicator encoding type
fixedLength = 0;
}
else if (lengthType == LengthType.LLLVAR)
{
lenLength = 2; // check the encoding to decide how many bytes needed. if BCD then 2 bytes are enough
lengthEncoding = le; // the length indicator encoding type
fixedLength = 0;
}
else if (lengthType == LengthType.FIXED)
{
lenLength = 0; // length indicator is 0 since is FIXED length field
lengthEncoding = EncodingType.NULL; // encoding method is NULL since we have no length indicator to encode
fixedLength = fl;
}
fieldEncoding = fe; // the field data encoding type
number = fn; // field number
}
public void setDescription(String desc)
{
description = desc;
}
public string getDescription()
{
if (this.description != null)
{
return this.description;
}
else
{
return String.Empty;
}
}
public void setName(String n)
{
name = n;
}
public string getName()
{
return name;
}
public LengthType getLengthType()
{
// returns the field legnthtype
return lengthType;
}
public EncodingType getLengthEncoding()
{
// returns the field legnthtype
return lengthEncoding;
}
public FieldType getType()
{
return fieldType;
}
public EncodingType getEncoding()
{
return fieldEncoding;
}
public int getLengthIndicatorLen()
{
// returns the size in bytes that length indicator holds
return lenLength;
}
public int getLength()
{
return fixedLength;
}
}
public class isoField
{
public int length;
public int number;
private byte[] m_rawValue;
public FieldType fieldType;
public EncodingType fieldEncoding;
public LengthType lengthType;
public EncodingType lengthEncoding;
public String name;
public String description;
public int lenLength;
public isoField()
{
}
public void setValueBYTE(byte[] myVal)
{
m_rawValue = myVal;
if (lengthType == LengthType.LLLVAR || lengthType == LengthType.LLVAR)
{
if (fieldType == FieldType.N || fieldType == FieldType.B)
{
length = myVal.Length * 2;
}
else
{
length = myVal.Length;
}
}
}
public void setValue(String myVal)
{
//based on field type set the field val
if (fieldType == FieldType.AN || fieldType == FieldType.ANS)
{
m_rawValue = ConvHelper.hex2bytes(ConvHelper.ascii2hex(myVal));
}
else if (fieldType == FieldType.N || fieldType == FieldType.B)
{
m_rawValue = ConvHelper.hex2bytes(myVal);
}
if (lengthType != LengthType.FIXED)
{
// dont overide dialect definition FIXED length casuse builder will copy bytes based on that so is risky
if (fieldType == FieldType.N || fieldType == FieldType.B)
{
length = myVal.Length * 2;
}
else
{
length = myVal.Length;
}
}
}
public string getValueASCII()
{
if (m_rawValue != null)
return ConvHelper.hex2ascii(ConvHelper.bytes2hex(m_rawValue, m_rawValue.Length, 0));
else
return String.Empty;
}
public byte[] getValueBYTE()
{
return m_rawValue;
}
public string getValueHEX()
{
return ConvHelper.bytes2hex(m_rawValue, m_rawValue.Length, 0);
}
public string getValue()
{
if (this.number == 63)
{
return ConvHelper.bytes2hex(m_rawValue, m_rawValue.Length, 0);
}
else if (this.fieldType == FieldType.ANS || this.fieldType == FieldType.A || this.fieldType == FieldType.AN)
{
return ConvHelper.hex2ascii(ConvHelper.bytes2hex(m_rawValue, m_rawValue.Length, 0));
}
else
{
return ConvHelper.bytes2hex(m_rawValue, m_rawValue.Length, 0);
}
}
public int getLengthIndicatorLen()
{
// returns the size in bytes that length indicator holds
return lenLength;
}
public void setLength(int len)
{
length = len;
}
public int getLength()
{
// returns the length of the field
if (fieldType == FieldType.N || fieldType == FieldType.B)
{
return (length / 2);
}
else
{
return length;
}
}
public int getFieldLength()
{
/*
* returns the length of data in the field data buffer
* (no length indicators calculated if field is LLVAR or LLLVAR)
*/
return m_rawValue.Length;
}
public int getFieldLengthInclusive()
{
/*
* returns the length of field if is FIXED or the length of field
* (assuming field value is set) + the LengthIndicator bytes
*/
if (this.lengthType == LengthType.LLVAR)
{
if (fieldType == FieldType.N || fieldType == FieldType.B)
{
return (length / 2) + 1;
}
else
{
return (length) + 1;
}
}
else if (this.lengthType == LengthType.LLLVAR)
{
if (fieldType == FieldType.N || fieldType == FieldType.B)
{
return (length / 2) + 2;
}
else
{
return (length) + 2;
}
}
else
{
if (fieldType == FieldType.N || fieldType == FieldType.B)
{
return (length / 2);
}
else
{
return length;
}
}
}
}
public class isoDialect
{
private int numberOfFields;
private string m_name;
public List<isoFieldDefinition> fieldList;
public void initVISABaseIDialect()
{
Logger.Instance.Log("Initialize VISA Base I ISO8583 Dialect");
setName("visa");
}
public void initMASTBankNetDialect()
{
Logger.Instance.Log("Initialize MASTERCARD BankNet ISO8583 Dialect");
setName("mastercard");
}
public void initCUPDialect()
{
Logger.Instance.Log("Initialize CHINA UNION PAY ISO8583 Dialect");
setName("cup");
}
public void initAMEXDialect()
{
Logger.Instance.Log("Initialize AMEX ISO8583 Dialect");
setName("amex");
}
public void initJCBDialect()
{
Logger.Instance.Log("Initialize JCB ISO8583 Dialect");
setName("jcb");
}
public void initHYPERCOMDialect()
{
Logger.Instance.Log("Initialize HYPERCOM ISO8583 Dialect");
setName("hypercom");
}
public isoDialect (int totalFields)
{
Logger.Instance.Log("Initializing ISO Dialect hardcoded...");
fieldList = new List<isoFieldDefinition>();
numberOfFields = totalFields;
Logger.Instance.Log("Number of fields = " + totalFields.ToString());
// Field[000][MTI]
isoFieldDefinition f000 = new isoFieldDefinition(0, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 4);
f000.setDescription("Message Type Identifier");
fieldList.Add(f000);
// Field[001][BITMAP]
isoFieldDefinition f001 = new isoFieldDefinition(1, FieldType.B, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 48);
f001.setDescription("Bitmap Indicator");
fieldList.Add(f001);
// Field[002][ACOUNT NUMBER] ISO NUMBERIC - LLVAR - LENGTHBYTES BINARY
isoFieldDefinition f002 = new isoFieldDefinition(2, FieldType.N, EncodingType.NULL, LengthType.LLVAR, EncodingType.BCD, 0);
f002.setDescription("Account Number");
fieldList.Add(f002);
// Field[003][PROCESSING CODE] ISO NUMBERIC - FIXED
isoFieldDefinition f003 = new isoFieldDefinition(3, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 6);
f003.setDescription("Processing Code");
fieldList.Add(f003);
// Field[004][TRASACTION AMOUNT] ISO NUMBERIC - FIXED
isoFieldDefinition f004 = new isoFieldDefinition(4, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 12);
f004.setDescription("Transaction Amount");
fieldList.Add(f004);
// Field[005][NOT USED]
isoFieldDefinition f005 = new isoFieldDefinition(5, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f005);
// Field[006][NOT USED]
isoFieldDefinition f006 = new isoFieldDefinition(6, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f006);
// Field[007][NOT USED]
isoFieldDefinition f007 = new isoFieldDefinition(7, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f007);
// Field[008][NOT USED]
isoFieldDefinition f008 = new isoFieldDefinition(8, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f008);
// Field[009][NOT USED]
isoFieldDefinition f009 = new isoFieldDefinition(9, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f009);
// Field[010][NOT USED]
isoFieldDefinition f010 = new isoFieldDefinition(10, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f010);
// Field[011][SYSTEM TRACE AUDIT NUMBER] ISO NUMBERIC - FIXED
isoFieldDefinition f011 = new isoFieldDefinition(11, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 6);
f011.setDescription("System Trace Audit Number");
fieldList.Add(f011);
// Field[011][TIME LOCAL TRANSACTION] ISO NUMBERIC - FIXED
isoFieldDefinition f012 = new isoFieldDefinition(12, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 6);
f012.setDescription("Local Transaction Time");
fieldList.Add(f012);
// Field[013][DATE LOCAL TRANSACTION] ISO NUMBERIC - FIXED
isoFieldDefinition f013 = new isoFieldDefinition(13, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 4);
f013.setDescription("Local Transaction Date");
fieldList.Add(f013);
// Field[014][EXPIRATION DATE] ISO NUMBERIC - FIXED
isoFieldDefinition f014 = new isoFieldDefinition(14, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 4);
f014.setDescription("Account Expiration Date");
fieldList.Add(f014);
// Field[015][NOT USED]
isoFieldDefinition f015 = new isoFieldDefinition(15, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f015);
// Field[015][NOT USED]
isoFieldDefinition f016 = new isoFieldDefinition(16, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f016);
// Field[017][NOT USED]
isoFieldDefinition f017 = new isoFieldDefinition(17, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f017);
// Field[018][NOT USED]
isoFieldDefinition f018 = new isoFieldDefinition(18, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f018);
// Field[019][NOT USED]
isoFieldDefinition f019 = new isoFieldDefinition(19, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f015);
// Field[020][NOT USED]
isoFieldDefinition f020 = new isoFieldDefinition(20, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f020);
// Field[021][NOT USED]
isoFieldDefinition f021 = new isoFieldDefinition(21, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f021);
// Field[022][POINT OF SERVICE ENTRY MODE]
isoFieldDefinition f022 = new isoFieldDefinition(22, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 4);
f022.setDescription("Point of Service Entry Mode");
fieldList.Add(f022);
// Field[023][NOT USED]
isoFieldDefinition f023 = new isoFieldDefinition(23, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 4);
fieldList.Add(f023);
// Field[024][Network International Identifier]
isoFieldDefinition f024 = new isoFieldDefinition(24, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 4);
f024.setDescription("Network International Identifier");
fieldList.Add(f024);
// Field[025][Network International Identifier]
isoFieldDefinition f025 = new isoFieldDefinition(25, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 2);
f025.setDescription("POS Condition Code");
fieldList.Add(f025);
// Field[026][NOT USED]
isoFieldDefinition f026 = new isoFieldDefinition(26, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f026);
// Field[027][NOT USED]
isoFieldDefinition f027 = new isoFieldDefinition(27, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f027);
// Field[028][NOT USED]
isoFieldDefinition f028 = new isoFieldDefinition(28, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f028);
// Field[029][NOT USED]
isoFieldDefinition f029 = new isoFieldDefinition(29, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f029);
// Field[030][NOT USED]
isoFieldDefinition f030 = new isoFieldDefinition(30, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f030);
// Field[031][NOT USED]
isoFieldDefinition f031 = new isoFieldDefinition(31, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f031);
// Field[032][NOT USED]
isoFieldDefinition f032 = new isoFieldDefinition(32, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f032);
// Field[033][NOT USED]
isoFieldDefinition f033 = new isoFieldDefinition(33, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f033);
// Field[034][NOT USED]
isoFieldDefinition f034 = new isoFieldDefinition(34, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f034);
// Field[035][TRACK 2 DATA] ISO NUMBERIC - LLVAR - LENGTHBYTES BINARY
isoFieldDefinition f035 = new isoFieldDefinition(35, FieldType.Z, EncodingType.NULL, LengthType.LLVAR, EncodingType.BCD, 0);
f035.setDescription("Track2 Data");
fieldList.Add(f035);
// Field[036][NOT USED]
isoFieldDefinition f036 = new isoFieldDefinition(36, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f036);
// Field[037][RETRIEVAL REFERENCE NUMBER]
isoFieldDefinition f037 = new isoFieldDefinition(37, FieldType.AN, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 12);
f037.setDescription("Retrieval Reference Number");
fieldList.Add(f037);
// Field[038][AUTHORIZATION CODE]
isoFieldDefinition f038 = new isoFieldDefinition(38, FieldType.AN, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 6);
f038.setDescription("Authorization Code");
fieldList.Add(f038);
// Field[039][RESPONSE CODE]
isoFieldDefinition f039 = new isoFieldDefinition(39, FieldType.AN, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 2);
f039.setDescription("Response Code");
fieldList.Add(f039);
// Field[040][NOT USED]
isoFieldDefinition f040 = new isoFieldDefinition(40, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f040);
// Field[41][CARD ACCEPTOR TERMINAL IDENTIFICATION]
isoFieldDefinition f041 = new isoFieldDefinition(41, FieldType.ANS, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 8);
f041.setDescription("Card Acceptor Terminal Identification");
fieldList.Add(f041);
// Field[042][CARD ACCEPTOR IDENTIFICATION CODE]
isoFieldDefinition f042 = new isoFieldDefinition(42, FieldType.ANS, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 15);
f042.setDescription("Card Acceptor Identification Code");
fieldList.Add(f042);
// Field[040][NOT USED]
isoFieldDefinition f043 = new isoFieldDefinition(43, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f043);
// Field[044][NOT USED]
isoFieldDefinition f044 = new isoFieldDefinition(44, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f044);
// Field[045][NOT USED]
isoFieldDefinition f045 = new isoFieldDefinition(45, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f045);
// Field[046][NOT USED]
isoFieldDefinition f046 = new isoFieldDefinition(46, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f046);
// Field[047][NOT USED]
isoFieldDefinition f047 = new isoFieldDefinition(47, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f047);
// Field[048][NOT USED]
isoFieldDefinition f048 = new isoFieldDefinition(48, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f048);
// Field[049][TRANSACTION CURRENCY CODE]
isoFieldDefinition f049 = new isoFieldDefinition(49, FieldType.N, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 4);
f049.setDescription("Transaction Currency Code");
fieldList.Add(f049);
// Field[050][NOT USED]
isoFieldDefinition f050 = new isoFieldDefinition(50, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f050);
// Field[051][NOT USED]
isoFieldDefinition f051 = new isoFieldDefinition(51, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f051);
// Field[52][PERSONAL IDENTIFICATION CODE]
isoFieldDefinition f052 = new isoFieldDefinition(52, FieldType.B, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 16);
f052.setDescription("Personal Identification Code");
fieldList.Add(f052);
// Field[053][NOT USED]
isoFieldDefinition f053 = new isoFieldDefinition(53, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f053);
// Field[054][NOT USED]
isoFieldDefinition f054 = new isoFieldDefinition(54, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f054);
// Field[55][ICC SYSTEM RELATED DATA]
isoFieldDefinition f055 = new isoFieldDefinition(55, FieldType.B, EncodingType.NULL, LengthType.LLLVAR, EncodingType.BCD, 0);
f055.setDescription("ICC System Related Data");
fieldList.Add(f055);
// Field[056][NOT USED]
isoFieldDefinition f056 = new isoFieldDefinition(56, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f056);
// Field[057][NOT USED]
isoFieldDefinition f057 = new isoFieldDefinition(57, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f057);
// Field[058][NOT USED]
isoFieldDefinition f058 = new isoFieldDefinition(58, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f058);
// Field[059][NOT USED]
isoFieldDefinition f059 = new isoFieldDefinition(59, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f059);
// Field[060][Private Use - Batch Number + SoftID + OrigData(stan/mti) + origAmt + EncKey(110/210) ]
isoFieldDefinition f060 = new isoFieldDefinition(60, FieldType.ANS, EncodingType.NULL, LengthType.LLLVAR, EncodingType.BCD, 0);
f060.setDescription("Private Use - Batch Number + SoftID + OrigData(stan/mti) + origAmt + EncKey(110/210)");
fieldList.Add(f060);
// Field[061][NOT USED]
isoFieldDefinition f061 = new isoFieldDefinition(61, FieldType.NULL, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 0);
fieldList.Add(f061);
// Field[062][RECONCILIATION TOTALS]
isoFieldDefinition f062 = new isoFieldDefinition(62, FieldType.ANS, EncodingType.NULL, LengthType.LLLVAR, EncodingType.BCD, 0);
f062.setDescription("Reconciliation totals");
fieldList.Add(f062);
// Field[063][ADDITIONAL DATA]
isoFieldDefinition f063 = new isoFieldDefinition(63, FieldType.ANS, EncodingType.NULL, LengthType.LLLVAR, EncodingType.BCD, 0);
f063.setDescription("Additional Data");
fieldList.Add(f063);
// Field[064][MAC - MESSAGE AUTHENTICATION CODE]
isoFieldDefinition f064 = new isoFieldDefinition(64, FieldType.B, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 8);
f064.setDescription("MAC - Message Authentication Code");
fieldList.Add(f064);
// Field[065][BITMAP]
isoFieldDefinition f065 = new isoFieldDefinition(65, FieldType.B, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 1);
f065.setDescription("Bitmap Extender");
fieldList.Add(f065);
// Field[066][MAC - MESSAGE AUTHENTICATION CODE]
isoFieldDefinition f066 = new isoFieldDefinition(66, FieldType.B, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 8);
f066.setDescription("MAC - Message Authentication Code");
fieldList.Add(f066);
// Field[067][MAC - MESSAGE AUTHENTICATION CODE]
isoFieldDefinition f067 = new isoFieldDefinition(67, FieldType.B, EncodingType.NULL, LengthType.FIXED, EncodingType.NULL, 8);
f067.setDescription("MAC - Message Authentication Code");
fieldList.Add(f067);
}
public isoDialect (String defFileName)
{
// initialize iso dialect form xml defintion file
}
public void setName(String name)
{
m_name=name;
}
public isoFieldDefinition getFieldDefinition(int fieldNum)
{
// return the field definition of field fieldNum
return fieldList.ElementAt(fieldNum);
}
public int getTotalFields()
{
return numberOfFields;
}
public void saveToFile(string fileName)
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode rootNode = xmlDoc.CreateElement("isodialect");
xmlDoc.AppendChild(rootNode);
foreach (isoFieldDefinition f in fieldList)
{
XmlNode fieldNode = xmlDoc.CreateElement("field");
//field number
XmlAttribute attribute = xmlDoc.CreateAttribute("num");
attribute.Value = f.number.ToString("D3");
fieldNode.Attributes.Append(attribute);
//legnth type
attribute = xmlDoc.CreateAttribute("lenType");
attribute.Value = f.lengthType.ToString().PadRight(6,' ');
fieldNode.Attributes.Append(attribute);
// length encoding
attribute = xmlDoc.CreateAttribute("lenEnc");
attribute.Value = f.lengthEncoding.ToString().PadRight(4,' ');
fieldNode.Attributes.Append(attribute);
// length encoding
attribute = xmlDoc.CreateAttribute("len");
attribute.Value = f.getLength().ToString("D3");
fieldNode.Attributes.Append(attribute);
// field name
attribute = xmlDoc.CreateAttribute("name");
attribute.Value = f.name;
fieldNode.Attributes.Append(attribute);
// field description
attribute = xmlDoc.CreateAttribute("desc");
attribute.Value = f.description;
fieldNode.Attributes.Append(attribute);
//fieldNode.InnerText = "John Doe";
rootNode.AppendChild(fieldNode);
}
xmlDoc.Save(fileName);
}
public void traceToConsole()
{
Logger.Instance.Log("Tracing dialect definition:");
Logger.Instance.Log("Dialect name: " + m_name);
Logger.Instance.Log("Number of fields: " + numberOfFields.ToString());
foreach (isoFieldDefinition f in fieldList)
{
Logger.Instance.Log(String.Format("Field Number : [{0}] ", f.number.ToString("D3")));
if (f.lengthType == LengthType.FIXED)
Logger.Instance.Log(String.Format("Field Length Type : [FIXED] "));
else if (f.lengthType == LengthType.LLVAR)
Logger.Instance.Log(String.Format("Field Length Type : [LLVAR] "));
else if (f.lengthType == LengthType.LLLVAR)
Logger.Instance.Log(String.Format("Field Length Type : [LLLVAR] "));
Logger.Instance.Log("");
}
}
public void traceToFile()
{
Logger.Instance.Log("Tracing dialect definition:");
Logger.Instance.Log("Dialect name: " + m_name);
Logger.Instance.Log("Number of fields: " + numberOfFields.ToString());
foreach (isoFieldDefinition f in fieldList)
{
Logger.Instance.Log(String.Format("Field Number : [{0}] ", f.number.ToString("D3")));
if (f.lengthType==LengthType.FIXED)
Logger.Instance.Log(String.Format("Field Length Type : [FIXED] "));
else if (f.lengthType==LengthType.LLVAR)
Logger.Instance.Log(String.Format("Field Length Type : [LLVAR] "));
else if (f.lengthType==LengthType.LLLVAR)
Logger.Instance.Log(String.Format("Field Length Type : [LLLVAR] "));
Logger.Instance.Log("");
}
}
}
public class isoMessage
{
private List<isoField> fieldList; // iso fields with their values
public isoDialect msgDialect; // iso message dialect definition
public isoBitmap msgBitmap; // iso message bitmap handler
public isoHeader msgHeader; // iso message header handler
public byte[] requestBuffer; // the raw data buffer that contains the request message
public byte[] responseBuffer; // the raw data buffer that contains the response message
public String f63v; // Final value of field 63