Hi everybody. I'm newbie in smart card world. I've got a gcr-410 reader and 
am experimenting with the basics of sending APDU from and to the smart card.
As the simulator given by Gemplus is quicker,I've developed a program which 
sends my name to the card and the it's stored in an static variable in the 
card using the simulator.
When developing with the simulator, everything works OK (the apdu returned 
has the bytes expected). However when loading and installing it into the 
smart card, when I asked for the name stored in the card the apdu return 
has extra info:
         --> Term : 00 30 00 00 00
         <-- Card : E7 46 65 72 6E 61 6E 64 6F 90 00 6D
                          F e    r    n   a  n   d   o

The E7 and 6D always appears when getting info from the SC.

Any Idea? Any help is welcomed.
Thank in advanced.

P.D.: I attach the files of the example

/**
 * Copyright (c) 2000 GEMPLUS group. All Rights Reserved.
 *------------------------------------------------------------------------------
 *  Project name:  GemXpresso RAD 211 Environment
 *                 - OP/VOP Template: applet part -
 *
 *  Platform    :  Java virtual machine
 *  Language    :  JAVA 1.2
 *  Devl tool   :  Symantec VisualCafe
 *
 *  Original author:
 *------------------------------------------------------------------------------
 */

/*
 * Package name
 */
package es.unican.examples.prueba;

/*
 * Imported packages
 */
// specific import for Javacard API access
import javacard.framework.*;
// specific import for OpenPlatform API access
import visa.openplatform.*;

public class Prueba extends javacard.framework.Applet
{
    // the OP/VOP specific instruction set for mutual authentication if used
    private final static byte CLA_INITIALIZE_UPDATE     = (byte)0x80 ;
    private final static byte INS_INITIALIZE_UPDATE     = (byte)0x50 ;
    private final static byte CLA_EXTERNAL_AUTHENTICATE = (byte)0x84 ;
    private final static byte INS_EXTERNAL_AUTHENTICATE = (byte)0x82 ;

    // the APDU constants for all commands
    private final static byte INS_GET_NAME              = (byte)0x30 ;
    private final static byte INS_GET_NAME_SECURE       = (byte)0x31 ;
    private final static byte INS_SET_NAME              = (byte)0x40 ;
    private final static byte INS_SET_NAME_SECURE       = (byte)0x41 ;
    
    // security domain instance used for secured actions
    private ProviderSecurityDomain securityObject;
    // security channel number. The value is returned by the Security Manager 
"openSecureChannel" method
    private byte secureChannel = (byte)0xFF;
    // the channel status
    private boolean channelOpened = false;
    // the authentication status
    private boolean authenticationDone = false;

    private static byte[] name = {'J','O','R','G','E'};
    
    /**
     * Prueba default constructor
     * Only this class's install method should create the applet object.
     */
    protected Prueba()
    {
        // register this instance as an installed applet
        register();
        securityObject = OPSystem.getSecurityDomain();
    }

    /**
     * Method installing the applet.
     * @param bArray the array containing installation parameters
     * @param bOffset the starting offset in bArray
     * @param bLength the length in bytes of the data parameter in bArray
     */
    public static void install( byte[] bArray, short bOffset, byte bLength ) throws 
ISOException
    {
        // applet  instance creation
        new Prueba();
    }

    /**
     * Select method returns true if applet selection is supported.
     * @return boolean status of selection.
     */
    public boolean select()
    {
        // reset security if used.
        // In case of reset deselect is not called
        reset_security();
        // <PUT YOUR SELECTION ACTION HERE>
        // return status of selection
        return true;
    }

    /**
     * Deselect method called by the system in the deselection process.
     */
    public void deselect()
    {
        // reset security if used.
        reset_security();
        // <PUT YOUR DESELECTION ACTION HERE>
        return;
    }

    /**
     * Method processing an incoming APDU.
     * @see APDU
     * @param apdu the incoming APDU
     * @exception ISOException with the response bytes defined by ISO 7816-4
     */
    public void process(APDU apdu) throws ISOException
    {
        // get the APDU buffer
        byte[] apduBuffer = apdu.getBuffer();

        // ignore the applet select command dispached to the process
        if (selectingApplet())
            return;

        // APDU instruction parser
        switch ( apduBuffer[ISO7816.OFFSET_INS] )
        {
            case INS_INITIALIZE_UPDATE :
            if(apduBuffer[ISO7816.OFFSET_CLA] == CLA_INITIALIZE_UPDATE)
                init_update( apdu ) ;
                else ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            break ;

            case INS_EXTERNAL_AUTHENTICATE :
                if(apduBuffer[ISO7816.OFFSET_CLA] == CLA_EXTERNAL_AUTHENTICATE)
                    external_authenticate( apdu ) ;
                else ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            break ;

            // <PUT YOUR IMPLEMENTATION HERE>
            case ISO7816.INS_SELECT :
            break ;
            
            case INS_GET_NAME :
                getName(apdu);
            break ;
            
            case INS_SET_NAME :
                setName(apdu);
            break ;
                
            default :
                // The INS code is not supported by the dispatcher
                ISOException.throwIt( ISO7816.SW_INS_NOT_SUPPORTED ) ;
            break ;

        }
    }

    /**
     * Performs the "init_update" security operation.
     *
     * @param apdu The APDU to process.
     */
    private void init_update( APDU apdu )
    {
        // receives data
        apdu.setIncomingAndReceive();
        // checks for existing active secure channel
        if(channelOpened)
        {
            // close the openned security channel
            reset_security();
        }
        try
        {
            // open a new security channel
            secureChannel = securityObject.openSecureChannel(apdu);
            // set the channel flag to open
            channelOpened = true;
            // get expected length
            short expected = apdu.setOutgoing();
            // send authentication result
            apdu.setOutgoingLength(expected);
            apdu.sendBytes(ISO7816.OFFSET_CDATA, expected);
        }
        catch(CardRuntimeException cre)
        {
            // no available channel or APDU is invalid
            ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
        }
        // send authentication result
        ISOException.throwIt(ISO7816.SW_NO_ERROR);
    }

    /**
     * Performs the "external_authenticate" security operation.
     *
     * @param apdu The APDU to process.
     */
    private void external_authenticate( APDU apdu )
    {
        // checks for existing active secure channel
        if(channelOpened)
        {
            try
            {
                // try to authenticate the client
                securityObject.verifyExternalAuthenticate(secureChannel, apdu);
                // authentication succeed
                authenticationDone = true;
            }
            catch(CardRuntimeException cre)
            {
                // authentication fails
                // set authentication flag to fails
                authenticationDone = false;
                // close the openned security channel
                reset_security();
                // send authentication result
                ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
            }
            // send authentication result
            ISOException.throwIt(ISO7816.SW_NO_ERROR);
        }
        else
            ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
    }

    /**
     * The "reset_security" method close an opened secure channel if exist.
     * @return void.
     */
    public void reset_security()
    {
        // close the secure channel if openned.
        if(secureChannel != (byte)0xFF)
        {
            try
            {
                // close the openned security channel
                securityObject.closeSecureChannel(secureChannel);
            }
            catch(CardRuntimeException cre2)
            {
                // channel number is invalid. this case is ignored
            }
            secureChannel = (byte)0xFF;
            channelOpened = false;
            authenticationDone = false;
        }
        return;
    }

    private void getName( APDU apdu )
    {
        // get the APDU buffer
        byte[] apduBuffer = apdu.getBuffer();
       
        // Write the out APDU
        for (byte i=0; i<name.length; i++)
        {
            apduBuffer[i+5] = name[i];
        }
       
        // APDU response
        short le = apdu.setOutgoing();
        apdu.setOutgoingLength( (short) name.length);
        apdu.sendBytes((short)5, (short) name.length);
        //apdu.setOutgoingAndSend((short)5, (short) name.length);
    }


    private void setName( APDU apdu )
    {
        // get the APDU buffer
        byte[] apduBuffer = apdu.getBuffer();
        
        // gets the length of bytes to recieved from the terminal and receives them
        // if does not receive 2 bytes throws an ISO.SW_WRONG_LENGTH exception
                short a = apduBuffer[ISO7816.OFFSET_LC];
                apdu.setIncomingAndReceive();
                
        name = new byte[apduBuffer[ISO7816.OFFSET_LC]];
        
        for (byte i=0; i< name.length; i++)
            name[i] = apduBuffer[5 + i];
            
//        apdu.setOutgoingAndSend((short)0, (short)0);
//        return(tmp_name);
    }


}
/**
 * Copyright (c) 2000 GEMPLUS group. All Rights Reserved.
 *------------------------------------------------------------------------------
 *  Project name:  GemXpresso RAD 211 Environment
 *                 - OP/VOP Template client part -
 *
 *  Platform    :  Java virtual machine
 *  Language    :  JAVA 1.2
 *  Devl tool   :  Symantec VisualCafe
 *
 *  Original author:
 *------------------------------------------------------------------------------
 */

/*
 * Package name
 */
package es.unican.examples.prueba.client;

/*
 * Imported packages
 */
import java.io.*;

// standard Java imports
import java.util.Random;

// standard OCF imports
import opencard.core.service.*;
import opencard.core.terminal.*;
import opencard.opt.management.*;


// gemplus OCF imports
import com.gemplus.opencard.service.*;
import com.gemplus.opencard.terminal.*;

// gemplus specific OCF imports for OP/VOP services
import com.gemplus.opencard.service.op.*;
import com.gemplus.opencard.service.op.vop.*;
import com.gemplus.opencard.service.op.vop.vop211.*;
import com.gemplus.tools.gemxpresso.*;

// GSE imports
import com.gemplus.javacard.gse.Simulator;
import com.gemplus.javacard.gse.util.APDUPrinter;

/**
 * The client application that manages and uses the 'Prueba' applet in the Card or GSE.
 * applet in the GSE or in the GemXpresso 211 Card.
 * <p>
 * This implementation uses the OCF 1.1.1 framework and the target specific
 * CardTerminal to communicate with the 'Prueba' applet.
 * <p>
 * This client loads a package, installs an applet, selects it and sends it some
 * APDU commands. It is just a simple example
 */
class PruebaClient
{
    /**
     * global declarations
     */
    // the OCF service used for VOP management
    private CardServiceVOP211 serv;
    // the OCF service library
    private GemXpressoService libService;
    // the OCF terminal used for communication
    private CardTerminal term;
    // the OCF specific object for sending APDUs
    private CommandAPDU cmd;
    // the OCF specific object for receiving APDUs
    private ResponseAPDU resp;
    // the display tool object for trace
    private APDUPrinter printer = new APDUPrinter();
    
    // Directories
    // Home directory
    private String homeDir = "C:" + File.separator + "Mis documentos" +
    File.separator + "Visual Cafe" + File.separator + "Tarjetas Inteligentes";
    // Project directory
    private String projectDir = homeDir + File.separator + "Prueba";
    // Custom directory
    private String customDir = projectDir + File.separator + "custom";
    // the key Files location
    private String keyFileHome = customDir + File.separator + "targets";
    // the system key File for management
    private String keyFile ;

    // GSE target constant values
    // the OCF GSE target name (define in the "opencard.properties" file)
    private String gseTarget = "Simulator";
    // the GSE default key set version (can be set to 0 to get the target file's one)
    private int gseKeyVersion = 13;
    // the GSE key file
    private String gseKeyFile = "gse.properties";

    // Card target constant values
    // the OCF Card target name (define in the "opencard.properties" file)
    private String cardTarget = "gcr410_com1";
    // the full name of the Card JAR file
    private String jarFileName = projectDir + File.separator + 
    "es" + File.separator + "unican" + File.separator + "examples" + File.separator + 
    "prueba" + File.separator + "javacard" + File.separator + "prueba.jar";
    // the Card key file
    private String cardKeyFile = "card.properties";

    // Target flag, if true the simulator target is used, otherwises card
    // <CHANGE THE TARGET HERE>
    private static boolean simulation = true;

    // Load flag, if true package will be loaded
    // <ACTIVATE THE PACKAGE LOAD HERE>
    private boolean loadPackage  = true;

    // authentication informations
    // <PLACE THE SECURITY DOMAIN AID HERE (null = default)>
    private byte[] securityDomainAID = null;
    // the key version used for security
    private int keySetVersion = 13;
    // the key index used for security
    private int keyIndex = 0;
    // <CHANGE THE SECURITY TO THE REQUIRED LEVEL>
    private boolean isEnciphered = false;
    private boolean isMacing = false;

    // client global informations
    // the name of the package to load
    private String packageName;
    // the package AID
    private ApplicationID packaid;
    // the name of the applet
    private String appletName;
    // the applet AID
    private ApplicationID aid;

    /**
     * PruebaClient default constructor
     */
    public PruebaClient()
    {
        // set the current directory to this sample one
        java.util.Properties p = System.getProperties();
        p.put("user.dir", customDir);
        System.setProperties(p);
    }

    /**
     * OCF Layer Initialisation
     */
    public void initOCF()
    {
        // start of initialisation
        try
        {

            System.out.println("----- In initOCF -----");
            
            // start OCF layer with the "opencard.properties" parameters
            SmartCard.start();

            // initialize target
            String target = (simulation) ? gseTarget : cardTarget;

            // Print found terminals
            printAvailableTerminals();
            
            // select the corresponding CardTerminal
            term = CardTerminalRegistry.getRegistry().cardTerminalForName(target);

            // check the terminal validity
            if(term == null) {
                throw new Exception("terminal not found : " + target);
            }
            // get terminal type
            String type = term.getType();
            if((type.compareTo("SOCKETJC21SIMULATOR") == 0) && !simulation) {
                throw new Exception("terminal " + target + " is a simulator instance");
            }
            if(!(type.compareTo("SOCKETJC21SIMULATOR") == 0) && simulation) {
                throw new Exception("terminal " + target + " is not a simulator 
instance");
            }

            // create a new card request
            CardRequest cr = new CardRequest();

            // defines a specific CardTerminal
            cr.setCardTerminal(term);

            if(simulation)
            {
                // GSE creation
                Simulator gse = new Simulator();
                // GSE start
                gse.start(5000,"GXP211_PK");
                // display simulator version at start-up
                gse.printVersion();
                // personalize with the GSE key set version
                keySetVersion = gseKeyVersion;
                // build the complete key file for the gse target
                keyFile = keyFileHome + File.separator + gseKeyFile;
            }
            else
            {
                // build the complete key file for the card target
                keyFile = keyFileHome + File.separator + cardKeyFile;
            }

            // wait for card insertion
            System.out.println("Please insert the card...");
            SmartCard sc = SmartCard.waitForCard(cr);

            // get the OP/VOP specific card service
            serv = (CardServiceVOP211)sc.getCardService(CardServiceVOP211.class, true);

            // create GemXpresso service API library
            libService  = new GemXpressoServiceVOP211();
            // set the VOP service for library use
            libService.setCardService(serv);

            // reset the Card or GSE to look for the default ATR
            System.out.println("ATR returned by the " +
                ((simulation)? "GSE" : "Card") +"...");
            displayAPDUResp(new ResponseAPDU(serv.warmReset()));

            // ask the service for a security session
            OPSecuritySession session = serv.GetSecuritySession();

            // use Security Domain AID if define otherwise default one
            if(securityDomainAID == null)
                session.setSecurityDomainAID(session.getCardManagerAID());
            else
                session.setSecurityDomainAID(securityDomainAID);

            // service specific authentication object
            VOPAuthenticationInput authenticationInput;

            // authentication object creation
            authenticationInput = new VOPAuthenticationInput();
            // look if key set version is defined
            if(keySetVersion > 0)
            {
                // key set version configuration
                authenticationInput.setKeySetVersion(keySetVersion);
                // do not use the key set version defined in the target file
                authenticationInput.setDefaultKeySetVersion(false);
            }
            else
            {
                // no key set version defined
                // use the key set version defined in the target file
                authenticationInput.setDefaultKeySetVersion(true);
            }
            // set key index
            authenticationInput.setKeyIndex(keyIndex);
            // set security level
            authenticationInput.setEnciphered(isEnciphered);
            authenticationInput.setMacing(isMacing);
            // define the target specific key file to use
            authenticationInput.setKeyfile(keyFile);
            // define if the security domain has to be select (yes)
            authenticationInput.setSecurityDomainSelection(true);
            // define the Security Domain AID
            // null force the use of the AID present in the target key file
            authenticationInput.setSecurityDomainAID(null);

            try
            {
                // try authentication for openning a secure channel
                Result result = serv.openSecureChanel(authenticationInput);
                if((result!=null) && !result.isOK())
                {
                    throw new Exception("authentication error : " + 
result.getResultMessage());
                }
            }
            catch(Exception ex)
            {
                throw new Exception("authentication error : " + ex.getMessage() );
            }
            System.out.println("Authentication OK");
        }
        catch(Exception ex)
        {
            System.out.println("Exception caught in initOCF : " + ex.getMessage() );
            // terminate client application
            java.lang.System.exit( -1 );
        }
    }

    /**
     * Method containing administration commands
     */
    public void runAdminCommands()
    {
        try
        {
            /*
             * Administration commands preparating the package.
             * AIDs are created for Package and Applet(s).
             * A loadable Package formatted for the GSE is created,
             * containing applet(s) defined by the client.
             */

            // create a package application ID
            packaid = new ApplicationID(new byte[]
            // <CHANGE YOUR PACKAGE AID HERE>
            // length Min 5, length Max 16
            {
                (byte)0xA0,(byte)0x00,(byte)0x00,(byte)0x00,
                        (byte)0x18,(byte)0xFF,(byte)0x00,(byte)0x00,
                        (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
                        (byte)0x00,(byte)0x00,(byte)0x01,(byte)0x01
            });

            // creates a new loadable package
            packageName = "es.unican.examples.prueba";
            OPLoadFile pack = new OPLoadFile(packageName);
            // set the package AID
            pack.setAID(packaid.getAID());
            // set the Security Domain for package applets's security features
            pack.setSecurityDomainAID(null);
            // set the load parameter value
            pack.setLoadParameters(null);

            // create an applet application ID
            aid = new ApplicationID(new byte[]
            // <CHANGE YOUR APPLET AID HERE>
            // length Min 5, length Max 16
            {
                (byte)0xA0,(byte)0x00,(byte)0x00,(byte)0x00,
                        (byte)0x18,(byte)0xFF,(byte)0x00,(byte)0x00,
                        (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
                        (byte)0x00,(byte)0x00,(byte)0x01,(byte)0x02
            });

            // creates a new application definition object
            OPApplication applet = new OPApplication(pack, "Prueba");
            // set the default applet AID
            applet.setAID(aid.getAID());
            // set the applet instance AID
            applet.setInstanceAID(aid.getAID());
            // defines if the applet will be installed after load
            applet.setIsToInstallFlag(true);
            // defines if the applet is a Security Domain
            applet.setSecurityDomainFlag(false);
            // defines if the applet will be selectable after install
            applet.setSelectableFlag(true);

            // add the applet to the package
            pack.addApplication(applet);

            // ckeck if the card has to be loaded
//            if (!exists(aid))
                if(loadPackage)
                {
                    loadPackage(pack);
                }

            /* select the applet for use
             *   applet 'select' method is called. If selection is successful, 
'Install Applet'
             *   is deselected and commands are sent to the selected applet 'process' 
method.
             *   For new administration commands Install Applet must be selected again.
             *   See Java Card 2.1 specifications for details.
             */
            System.out.println("Select applet... ");
            SelectResult selectResult = serv.select(aid);

            if(!((selectResult != null) && (selectResult.isOK())))
                throw new Exception("Select applet error : " + 
selectResult.getResultMessage());

            System.out.println("Select applet Prueba OK");
        }
        catch(Exception ex)
        {
            System.out.println("Exception caught in runAdminCommands : " + 
ex.getMessage() );
            // terminate client application
            java.lang.System.exit( -1 );
        }
    }

    /**
     * Method loading the package in the target.
     * @param pack the "load file" object to load
     */
    public void loadPackage(OPLoadFile pack)
    throws Exception
    {
        // the result of the load file operation
        LoadFileResult loadFileResult = null;
        // define the maximum length of data in each "load" APDU
        int maxBlockSize = 200;
        // the Security Domain OCF AID object
        ApplicationID securityDomainID = null;
        if(pack.getSecurityDomainAID()!=null)
        {
            // create the Security Domain OCF AID object
            securityDomainID = new ApplicationID(pack.getSecurityDomainAID());
        }
        if(simulation)
        // load in the GSE
        {
            // create an intermediate SAP (GSE specific format) file
            String sapFileName = ".\\" + packageName + ".sap";
            // build the file in the defined path
            GemXpressoService.CreateSapfileFromOPLoadFile(pack,sapFileName);

            // load the "load file" in the GSE
            System.out.println("Load in the GSE...");
            //
            loadFileResult = libService.loadFromSapFile(
                              packaid,
                              securityDomainID,
                              pack.getLoadParameters(),
                              maxBlockSize,
                              sapFileName
                              );
        }
        // end of load in the GSE

        else
        // load in card
        {
            // load the JAR file in the card
            System.out.println("Load in the card...");
            // check valid JAR file
            if(!jarFileName.equals(""))
             {
                loadFileResult = libService.loadFromJarFile(
                              packaid,
                              securityDomainID,
                              pack.getLoadParameters(),
                              maxBlockSize,
                              jarFileName
                              );
            }
        }
        // end of load in the card

        // check the load result state
        // case of null result
        if(loadFileResult == null)
            throw new Exception("Load error : null loadFileResult");

        // case of wrong result
        if(!loadFileResult.isOK())
            throw new Exception("Load error : " + loadFileResult.getResultMessage());

        // loading succeed
        System.out.println("Loading  succeed");

        // install the applet with parameters
        System.out.println("Install applet... ");

        // the result of the load file operation
        InstallApplicationResult installApplicationResult;
        installApplicationResult = serv.installApplication(
                    aid,        // application AID
                    aid,        // application instance AID
                    packaid,    // load File AID
                    null,       // application properties byte array
                    // install parameter (length Min 0, length Max 32)
                    // <CHANGE YOUR INSTALL PARAMETER HERE>
                    new byte[] {(byte) 0x00, (byte) 0x64},
                    null,       // non volatile code space limit parameters
                    null,       // volatile data space limit parameters
                    null,       // non volatile data space limit parameters
                    null,       // others parameters
                    null,       // install token (none)
                    true,       // make selectable flag
                    null        // DAP (not present)
                    );

        // check install result
        if(!((installApplicationResult!=null)&&(installApplicationResult.isOK())))
            throw new Exception("Install error : " + 
installApplicationResult.getResultMessage());

        // install succeed
        System.out.println("Installing application Prueba succeed");
    }

    /**
     * Method containing application commands exchanging APDU with the applet.
     * All APDUs are forwarded by the GSE to the applet 'process' method
     * until a new select command is received.
     */
    public void runAppliCommands()
    {
        try
        {
            // Send commands to the applet 'process' method
            // <PLACE THE APDU COMMANDS HERE>

            // ----- Example implementing APDU exchange -----

            getName();            
           
            setName(new byte[] {'F', 'e', 'r', 'n', 'a', 'n', 'd', 'o'});
            
            getName();
            // ----- End of Example ----- 

        }
        catch(Exception ex)
        {
            System.out.println("Exception caught in runAppliCommands : " + 
ex.getMessage() );
            // terminate client application
            java.lang.System.exit( -1 );
        }
    }


    private void getName() //throws Exception
    {
        try {
            CommandAPDU cmd = new CommandAPDU(new byte[]
            {
                (byte)0x00,     // CLA
                (byte)0x30,     // INS
                (byte)0x00,     // P1
                (byte)0x00,     // P2
                (byte)0x00      // Le
                //(byte)0x09
            });
                
            //ResponseAPDU  resp;
            ResponseAPDU resp = serv.sendAPDU(cmd);

            displayAPDU(cmd, resp);
                
            byte[] name = resp.data();
            for (int i=0; i<name.length; i++)
                System.out.print((char)name[i]);
            System.out.println();
        } catch (Exception a) {}
    }
    
    public void setName(byte[] name) throws Exception
    {
        System.out.println(name.toString());
        final int HEADER_LENGTH = 4;      
/*        CommandAPDU cmd = new CommandAPDU(new byte[]
        {
            (byte)0x00,     // CLA
            (byte)0x40,     // INS
            (byte)0x00,     // P1
            (byte)0x00,     // P2
            //(byte)0x00      // P3
            //(byte)0x09
        }, name.length + 5);
*/
        CommandAPDU cmd = new CommandAPDU(HEADER_LENGTH + 1 + name.length);
        // Fill the LC field
        //cmd.setLength(HEADER_LENGTH);
        cmd.append((byte) 0x00 );
        cmd.append((byte) 0x40 );
        cmd.append((byte) 0x00 );
        cmd.append((byte) 0x00 );
        cmd.append((byte) name.length);
        
        // Fill the data field
        for (int i=0; i<name.length; i++)
            cmd.append((byte) name[i]);

//        byte[] tmp = new byte[4+1+name.length];
        
        
        
        //ResponseAPDU  resp;
        ResponseAPDU resp = serv.sendAPDU(cmd);

        displayAPDU(cmd, resp);
    }
    
        
    
    /**
     * Free OCF layer used by the client
     */
    public void stopOCF()
    {
        try
        {
            // free the OCF layer before terminating
            SmartCard.shutdown();
        }
        catch(Exception ex)
        {
            System.out.println("Exception caught in stopOCF : " + ex.getMessage() );
            // terminate client application
            java.lang.System.exit( -1 );
        }
    }

    /**
     * Display utility for APDU command & response
     * @param termCmd a CommandAPDU type command
     * @param cardResp a ResponseAPDU type response
     */
    private void displayAPDU(CommandAPDU termCmd, ResponseAPDU cardResp)
    {
        printer.printAPDU(termCmd.getBuffer(), cardResp.getBuffer());
    }

    /**
     * Display utility for APDU command
     * @param termCmd a CommandAPDU type command
     * @param cardResp a ResponseAPDU type response
     */
    private void displayAPDUCmd(CommandAPDU termCmd)
    {
        printer.printAPDUCmd(termCmd.getBuffer());
    }

    /**
     * Display utility for APDU response
     * @param termCmd a CommandAPDU type command
     * @param cardResp a ResponseAPDU type response
     */
    private void displayAPDUResp(ResponseAPDU cardResp)
    {
        printer.printAPDUResp(cardResp.getBuffer());
    }

    /**
     * Utility that print the available OCF CardTerminal for the client
     */
    private void printAvailableTerminals()
    {
          // get an enumeration from the registry
          java.util.Enumeration terminals = CardTerminalRegistry.getRegistry().
                                                            getCardTerminals();
          // the CardTerminal we are retreiving information
          CardTerminal inFocusTerminal;

          // analyse loop
          while (terminals.hasMoreElements())
          {
                inFocusTerminal = (CardTerminal)terminals.nextElement();
                System.out.println("Found OCF Card Terminal:");
                // print the user defined name
                System.out.println("\t- Name = " + inFocusTerminal.getName());
                // print the legal type
                System.out.println("\t- Type = " + inFocusTerminal.getType());
                // print the corresponding adress
                System.out.println("\t- Adress = " + inFocusTerminal.getAddress() + 
"\n");
          }
    }

    /**
     * Application main entry point.
     * @param argv not used by default application.
     */
    public static void main(String[] argv)
    {
        // parse arguments
        for(int i=0; i<argv.length; i++)
        {
            // help request
            if(argv[i].toLowerCase().equals("-help"))
            {
                System.out.println("");
                System.out.println("  Select Target");
                System.out.println("    -gse  : for the GSE");
                System.out.println("    -card : for the Card");
                System.out.println("");
                System.exit(0);
            }
            // card request
            if(argv[i].toLowerCase().equals("-card"))
                simulation = false;
            // GSE request
            if(argv[i].toLowerCase().equals("-gse"))
                simulation = true;
        }
        // create client instance
        PruebaClient client = new PruebaClient();

        System.out.println("----- start of PruebaClient client application -----");

        // initialise OCF layer
        client.initOCF();

        // run administration commands
        client.runAdminCommands();

        // run application commands
        client.runAppliCommands();

        // free OCF layer
        client.stopOCF();

        System.out.println("----- end of PruebaClient client application -----");
        // terminate client application normally
        java.lang.System.exit(0) ;
    }

}

Reply via email to