FileDocCategorySizeDatePackage
GSMApplet.javaAPI DocphoneME MR2 API (J2ME)5272Wed May 02 18:00:40 BST 2007com.sun.satsa.gsmapplet

GSMApplet

public class GSMApplet extends Applet implements ToolkitConstants
This applets is suppose to simulate the working of the main GSM applet in (U)SIM that controls access to all other applets. No other applet is selected directly but is invoked by this applet on basis of events.

Fields Summary
private static final byte
ENVELOPE_INS
Instruction byte for an Envelope. Only Envelopes are supported at this time
private static final byte
GET_RESPONSE_INS
Instruction byte value for GET RESPONSE APDU.
AccessSATImpl
SATAccessor
A field to hold the instance of SATAccessor which is used by the toolkit classes to set and get the APDU buffer.
Constructors Summary
private GSMApplet()
Constructor.

    
           
      
        register();
        SATAccessor = new AccessSATImpl();
        AID aid = JCSystem.getAID();
        ViewHandler.SATAccessor = (AccessSAT)
                    JCSystem.getAppletShareableInterfaceObject(aid, (byte)0);
    
Methods Summary
public ShareablegetShareableInterfaceObject(AID clientAID, byte parameter)
Returns shareable interface object to SIM Framework.

param
clientAID - aid of SIM Framework
param
parameter
return
The current applet instance

        return (Shareable)SATAccessor;
    
public static voidinstall(byte[] bArray, short bOffset, byte bLength)
Applet's install method. Creates an instance of GSMApplet

param
bArray parameters array
param
bOffset offset in the parameters array
param
bLength length of parameters

        new GSMApplet();
    
public voidprocess(APDU apdu)
Process method that processes all the APDUs received from the terminal.

param
apdu APDU that has been received from the terminal

        byte[] buffer = apdu.getBuffer();

        // clear the channel information 
        buffer[ISO7816.OFFSET_CLA] = (byte)(buffer[ISO7816.OFFSET_CLA] 
                                            & (byte)0xFC);

        // check SELECT APDU command
        if ((buffer[ISO7816.OFFSET_CLA] == 0) &&
            (buffer[ISO7816.OFFSET_INS] == (byte)(0xA4)))
            return;

        switch (buffer[ISO7816.OFFSET_INS]) {
            case ENVELOPE_INS:
                short incomingData = apdu.setIncomingAndReceive();
                SATAccessor.resetBuffers();
                SATAccessor.setAPDUBuffer(buffer, (short)(incomingData + 5));
                
                for (byte i = 0; i < AccessSATImpl.MAX_LISTENERS; i++) {
                    ToolkitInterface ti = SATAccessor.tiList[i];
                    if (ti == null) {
                        continue;
                    }
                    ViewHandler.currentTI = ti;
                    ti.processToolkit(EVENT_UNFORMATTED_SMS_PP_ENV);
                    if (EnvelopeResponseHandler.status != 0) {
                        short dataLength = SATAccessor.getOutDataLength();
                        short st = (short)
                        ((EnvelopeResponseHandler.status << 8) | dataLength);
                        ISOException.throwIt(st);
                    } 
                }
                break;
            case GET_RESPONSE_INS:
                SATAccessor.setAPDUBuffer(buffer, (short)5);
                short dataLength = SATAccessor.getOutDataLength();
                apdu.setOutgoing();
                apdu.setOutgoingLength(dataLength);
                SATAccessor.setOutgoingAPDU();
                Util.arrayCopy(SATAccessor.getAPDUBuffer(), (short)0, 
                        buffer, (short)0, dataLength);
                apdu.sendBytes((short)0, dataLength);
                break;
            default:        
        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    
public voiduninstall()
This method is called by JCRE before it tries to uninstall this applet.

        ViewHandler.SATAccessor = null;