1 /**
  2  *  ---------
  3  * |.##> <##.|  Open Smart Card Development Platform (www.openscdp.org)
  4  * |#       #|  
  5  * |#       #|  Copyright (c) 1999-2009 CardContact Software & System Consulting
  6  * |'##> <##'|  Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de)
  7  *  --------- 
  8  *
  9  *  This file is part of OpenSCDP.
 10  *
 11  *  OpenSCDP is free software; you can redistribute it and/or modify
 12  *  it under the terms of the GNU General Public License version 2 as
 13  *  published by the Free Software Foundation.
 14  *
 15  *  OpenSCDP is distributed in the hope that it will be useful,
 16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18  *  GNU General Public License for more details.
 19  *
 20  *  You should have received a copy of the GNU General Public License
 21  *  along with OpenSCDP; if not, write to the Free Software
 22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 23  *
 24  * @fileoverview Implementation of an EMV command interpreter
 25  */
 26 
 27 load("../../cardsim/commandinterpreter.js");
 28 
 29 
 30 
 31 /**
 32  * Create a command interpreter
 33  *
 34  * @class Class implementing a command interpreter that handles EMV command APDUs
 35  * @constructor
 36  * @param {FileSelector} fileSelector the file selector object
 37  */
 38 function EMVCommandInterpreter(fileSelector) {
 39 	CommandInterpreter.call(this, fileSelector);
 40 }
 41 
 42 // Inherit from CommandInterpreter
 43 EMVCommandInterpreter.prototype = new CommandInterpreter();
 44 EMVCommandInterpreter.constructor = EMVCommandInterpreter;
 45 
 46 
 47 
 48 /**
 49  * Implements GET PROCESSING OPTIONS
 50  *
 51  * @param {APDU} apdu the command APDU
 52  */
 53 EMVCommandInterpreter.prototype.getProcessingOptions = function(apdu) {
 54 	if ((apdu.getP1() != 0x00) || (apdu.getP2() != 0x00)) {
 55 		throw new GPError("EMVCommandInterpreter", GPError.INVALID_DATA, APDU.SW_INCP1P2, "P1 and P2 must be 00 in GET PROCESSING OPTIONS");
 56 	}
 57 	var aip = this.fileSelector.getMeta("ApplicationInterchangeProfile");
 58 	var afl = this.fileSelector.getMeta("ApplicationFileLocator");
 59 
 60 	var resp = new ASN1(0x77,
 61 						new ASN1(EMV.AIP, aip),
 62 						new ASN1(EMV.AFL, afl)
 63 					);
 64 	apdu.setRData(resp.getBytes());
 65 	apdu.setSW(APDU.SW_OK);
 66 }
 67 
 68 
 69 
 70 /**
 71  * Dispatch to command handler based in INS byte in APDU
 72  *
 73  * @param {APDU} apdu the apdu
 74  * @param {Number} ins the normalized instruction code
 75  */
 76 EMVCommandInterpreter.prototype.dispatch = function(apdu, ins) {
 77 	switch(ins) {
 78 	case EMV.INS_GET_PROCESSING_OPTIONS:
 79 		this.getProcessingOptions(apdu);
 80 		break;
 81 	default:
 82 		CommandInterpreter.prototype.dispatch.call(this, apdu, ins);
 83 	}
 84 }
 85