#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "bank/bank8583.h"
ISO8583_FIELD Tbl8583[128] =
{
{0,"BIT MAP,EXTENDED ", 8, 0, 0, 2, NULL,0},
{0,"PRIMARY ACCOUNT NUMBER ", 22, 0, 2, 1, NULL,0},
{0,"PROCESSING CODE ", 6, 0, 0, 1, NULL,0},
{0,"AMOUNT, TRANSACTION ", 12, 0, 0, 1, NULL,0},
{0,"NO USE ", 12, 0, 0, 1, NULL,0},
{0,"NO USE ", 12, 0, 0, 1, NULL,0},
{0,"TRANSACTION DATE AND TIME ", 10, 0, 0, 1, NULL,0},
{0,"NO USE ", 8, 0, 0, 1, NULL,0},
{0,"NO USE ", 8, 0, 0, 1, NULL,0},
{0,"NO USE ", 8, 0, 0, 1, NULL,0},
{0,"SYSTEM TRACE AUDIT NUMBER ", 6, 0, 0, 1, NULL,0},
{0,"TIME, LOCAL TRANSACTION ", 6, 0, 0, 1, NULL,0},
{0,"DATE, LOCAL TRANSACTION ", 4, 0, 0, 1, NULL,0},
{0,"DATE, EXPIRATION ", 4, 0, 0, 1, NULL,0},
{0,"DATE, SETTLEMENT ", 4, 0, 0, 1, NULL,0},
{0,"NO USE ", 4, 0, 0, 1, NULL,0},
{0,"DATE, CAPTURE ", 4, 0, 0, 1, NULL,0},
{0,"MERCHANT'S TYPE ", 4, 0, 0, 1, NULL,0},
{0,"NO USE ", 3, 0, 0, 1, NULL,0},
{0,"NO USE ", 3, 0, 0, 1, NULL,0},
{0,"NO USE ", 3, 0, 0, 1, NULL,0},
{0,"POINT OF SERVICE ENTRY MODE ", 3, 0, 0, 1, NULL,0},
{0,"NO USE ", 3, 0, 0, 1, NULL,0},
{0,"NO USE ", 3, 0, 0, 1, NULL,0},
{0,"POINT OF SERVICE CONDITION CODE ", 2, 0, 0, 1, NULL,0},
{0,"NO USE ", 2, 0, 0, 1, NULL,0},
{0,"NO USE ", 1, 0, 0, 1, NULL,0},
{0,"field27 ", 6, 0, 0, 1, NULL,0},
{0,"NO USE ", 8, 0, 1, 1, NULL,0},
{0,"NO USE ", 8, 0, 1, 1, NULL,0},
{0,"NO USE ", 8, 0, 1, 1, NULL,0},
{0,"ACQUIRER INSTITUTION ID. CODE ", 11, 0, 2, 1, NULL,0},
{0,"FORWARDING INSTITUTION ID. CODE ", 11, 0, 2, 1, NULL,0},
{0,"NO USE ", 28, 0, 2, 0, NULL,0},
{0,"TRACK 2 DATA ", 37, 0, 2, 0, NULL,0},
{0,"TRACK 3 DATA ",104, 0, 3, 0, NULL,0},
{0,"RETRIEVAL REFERENCE NUMBER ", 12, 0, 0, 0, NULL,0},
{0,"AUTH. IDENTIFICATION RESPONSE ", 6, 0, 0, 0, NULL,0},
{0,"RESPONSE CODE ", 2, 0, 0, 0, NULL,0},
{0,"NO USE ", 3, 0, 0, 0, NULL,0},
{0,"CARD ACCEPTOR TERMINAL ID. ", 8, 0, 0, 0, NULL,0},
{0,"CARD ACCEPTOR IDENTIFICATION CODE ", 15, 0, 0, 0, NULL,0},
{0,"CARD ACCEPTOR NAME LOCATION ", 40, 0, 0, 0, NULL,0},
{0,"ADDITIONAL RESPONSE DATA ", 25, 0, 2, 0, NULL,0},
{0,"NO USE ", 76, 0, 2, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"field47 ",999, 0, 3, 0, NULL,0},
{0,"ADDITIONAL DATA --- PRIVATE ",999, 0, 3, 0, NULL,0},
{0,"CURRENCY CODE,TRANSACTION ", 3, 0, 0, 0, NULL,0},
{0,"CURRENCY CODE,SETTLEMENT ", 3, 0, 0, 0, NULL,0},
{0,"NO USE ", 3, 0, 0, 0, NULL,0},
{0,"PERSONAL IDENTIFICATION NUMBER DATA ", 8, 0, 0, 2, NULL,0},
{0,"SECURITY RELATED CONTROL INformATION", 16, 0, 0, 1, NULL,0},
{0,"ADDITIONAL AMOUNTS ",120, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ", 5, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ", 11, 0, 3, 0, NULL,0},
{0,"NO USE ", 11, 0, 3, 0, NULL,0},
{0,"MESSAGE AUTHENTICATION CODE FIELD ", 8, 0, 0, 2, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ", 1, 0, 0, 1, NULL,0},
{0,"NO USE ",999, 0, 3, 1, NULL,0},
{0,"NO USE ",999, 0, 3, 1, NULL,0},
{0,"NO USE ",999, 0, 3, 1, NULL,0},
{0,"SYSTEM MANAGEMENT INformATION CODE ", 3, 0, 0, 1, NULL,0},
{0,"NO USE ",999, 0, 3, 1, NULL,0},
{0,"NO USE ",999, 0, 3, 1, NULL,0},
{0,"NO USE ", 6, 0, 0, 1, NULL,0},
{0,"NUMBER OF CREDITS ", 10, 0, 0, 1, NULL,0},
{0,"REVERSAL NUMBER OF CREDITS ", 10, 0, 0, 1, NULL,0},
{0,"NUMBER OF DEBITS ", 10, 0, 0, 1, NULL,0},
{0,"REVERSAL NUMBER OF DEBITS ", 10, 0, 0, 1, NULL,0},
{0,"NUMBER OF TRANSFER ", 10, 0, 0, 1, NULL,0},
{0,"REVERSAL NUMBER OF TRANSFER ", 10, 0, 0, 1, NULL,0},
{0,"NUMBER OF INQUIRS ", 10, 0, 0, 1, NULL,0},
{0,"AUTHORIZATION NUMBER ", 10, 0, 0, 1, NULL,0},
{0,"NO USE ", 12, 0, 0, 1, NULL,0},
{0,"CREDITS,TRANSCATION FEEAMOUNT ", 12, 0, 0, 1, NULL,0},
{0,"NO USE ", 12, 0, 0, 1, NULL,0},
{0,"DEBITS,TRANSCATION FEEAMOUNT ", 12, 0, 0, 1, NULL,0},
{0,"AMOUNT OF CREDITS ", 16, 0, 0, 1, NULL,0},
{0,"REVERSAL AMOUNT OF CREDITS ", 16, 0, 0, 1, NULL,0},
{0,"AMOUNT OF DEBITS ", 16, 0, 0, 1, NULL,0},
{0,"REVERSAL AMOUNT OF DEBITS ", 16, 0, 0, 1, NULL,0},
{0,"ORIGINAL DATA ELEMENTS ", 42, 0, 0, 1, NULL,0},
{0,"FILE UPDATE CODE ", 1, 0, 0, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"SERVICE INDICATOR ", 7, 0, 0, 0, NULL,0},
{0,"REPLACEMENT AMOUNTS ", 42, 0, 0, 0, NULL,0},
{0,"NO USE ", 8, 0, 0, 0, NULL,0},
{0,"AMOUNT OF NET SETTLEMENT ", 16, 0, 0, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"SETTLEMENT INSTITUTION ID ", 11, 0, 2, 1, NULL,0},
{0,"RECVEING INSTITUTION ID ", 11, 0, 2, 1, NULL,0},
{0,"FILENAME ", 17, 0, 2, 0, NULL,0},
{0,"ACCOUNT IDENTIFICATION1 ", 28, 0, 2, 0, NULL,0},
{0,"ACCOUNT IDENTIFICATION2 ", 28, 0, 2, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NEW PIN DATA ", 8, 0, 3, 2, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"NO USE ",999, 0, 3, 0, NULL,0},
{0,"MESSAGE AUTHENTICATION CODE FIELD ", 8, 0, 0, 2, NULL,0},
};
void Get8583Field( int index, ISO8583_FIELD** ppField )
{
assert( index>=1 && index <= 128 );
*ppField = &Tbl8583[index-1];
}
BYTE g_8583ValidFields[16] = {0};
void Set8583ValidFields( BYTE* pindex )
{
memset( g_8583ValidFields, 0, sizeof(g_8583ValidFields) );
while( *pindex >= 1 && *pindex <= 128 )
{
int num = (*pindex)-1;
int n = num / 8;
BYTE mask = 0x80;
mask >>= num - n * 8;
g_8583ValidFields[n] |= mask;
pindex ++;
}
}
BOOL IsValidField( int index )
{
if( index >= 128 || index <= 1 ) return FALSE;
int num = index-1;
int n = num / 8;
BYTE mask = 0x80;
mask >>= num - n * 8;
return ( g_8583ValidFields[n] & mask );
}
TRADE_8583_DEF* g_8583TradeDef = NULL;
TRADE_8583_DEF* Get8583TradeInfo( DWORD tcode )
{
if( g_8583TradeDef == NULL )
{
printf("Please call [Set8583TradeInfo] function first/r/n");
return NULL;
}
for( int i = 0; g_8583TradeDef[i].req.name != NULL; i ++ )
{
if( g_8583TradeDef[i].tcode & tcode ) return &g_8583TradeDef[i];
}
printf(" trade not find ! /r/n");
return NULL;
}
BOOL Set8583TradeInfo( TRADE_8583_DEF * pDef )
{
g_8583TradeDef = NULL;
for( int i = 0 ; pDef[i].req.name != NULL ; i ++ )
{
int j;
for( j = 0; ; j ++ )
{//保证所有的域都是声明了的
int index = pDef[i].req.bm[j];
if( index >= 128 || index <= 1 ) break;
if( !IsValidField( index ) )
{
printf("field[%d] is not valid!/r/n",index);
return FALSE;
}
if(!( Tbl8583[index-1].variable_flag == 0 ||
Tbl8583[index-1].variable_flag == 1 ||
Tbl8583[index-1].variable_flag == 2 ||
Tbl8583[index-1].variable_flag == 3 ) )
{
printf("field[%d] variable_flag is not a valid number!/r/n",index);
return FALSE;
}
}
}
g_8583TradeDef = pDef;
return TRUE;
}
Pack8583::Pack8583( BOOL bCompressInt )
{
m_pTradeDef = NULL;
m_bCompInt = bCompressInt;
}
Pack8583::~Pack8583()
{
}
BOOL Pack8583::Init(DWORD tcode)
{
m_pTradeDef = Get8583TradeInfo( tcode );
if( m_pTradeDef == NULL ) return FALSE;