Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

How to send SET_UP_MENU command

JavaCard Applet Development Related Questions and Answers.
qjal001
Posts: 4
Joined: Fri Jun 12, 2020 10:26 pm
Points :60
Contact:

How to send SET_UP_MENU command

Post by qjal001 » Fri Aug 28, 2020 8:43 am

I developed my own STK applet and install in SIM card.
But, as I insert SIM card in smartphone, SET_UP_MENU proactive command is not sent to terminal.
My applet's codes are below.
  1. package com.example.ToolkitAppletExample;
  2.  
  3.  
  4.  
  5. import uicc.toolkit.*;
  6.  
  7. import uicc.access.*;
  8.  
  9. import javacard.framework.*;
  10.  
  11.  
  12.  
  13. public class MyToolkitApplet extends javacard.framework.Applet implements ToolkitInterface, uicc.toolkit.ToolkitConstants
  14.  
  15. {
  16.  
  17.     public static final byte MY_INSTRUCTION         = (byte)0x46;
  18.  
  19.     public static final byte SERVER_OPERATION       = (byte)0x0F;
  20.  
  21.     public static final byte CMD_QUALIFIER          = (byte)0x80;
  22.  
  23.     public static final byte EXIT_REQUESTED_BY_USER = (byte)0x10;
  24.  
  25.  
  26.  
  27.     private byte[] menuEntry =    {(byte)'0',(byte)'3',(byte)'.',(byte)'1',(byte)'9',(byte)' ',(byte)'A',(byte)'p',(byte)'p',(byte)'l',(byte)'e',(byte)'t'};
  28.  
  29.    
  30.  
  31.     private byte[] menuTitle=     {(byte)'M',(byte)'y',(byte)'M',(byte)'e',(byte)'n' ,(byte)'u'};
  32.  
  33.     private byte[] item1 =        {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'1' };
  34.  
  35.     private byte[] item2 =        {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'2' };
  36.  
  37.     private byte[] item3 =        {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'3' };
  38.  
  39.     private byte[] item4 =        {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'4' };
  40.  
  41.     private Object[] ItemList =   { item1, item2, item3, item4 };
  42.  
  43.     private byte[] textDText =    {(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o',(byte)' ',
  44.  
  45.       (byte)'w',(byte)'o',(byte)'r',(byte)'l',(byte)'d',(byte)'2'};
  46.  
  47.     private byte[] textGInput =    {(byte)'Y',(byte)'o',(byte)'u',(byte)'r',(byte)' ',(byte)'n',
  48.  
  49.       (byte)'a',(byte)'m',(byte)'e',(byte)'?'};
  50.  
  51.  
  52.  
  53.     private byte[]  baGSMAID =    {(byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x09, (byte)0x00, (byte)0x01};
  54.  
  55.     private ToolkitRegistry reg;
  56.  
  57.     private byte buffer[] = new byte[10];
  58.  
  59.     private byte itemId;
  60.  
  61.     private byte result;
  62.  
  63.  
  64.  
  65.  
  66.  
  67.     // Allocate 500 bytes for the reception buffer
  68.  
  69.     private static final short BUFFER_SIZE = (short)0x01F4;    
  70.  
  71.     // TLVs overhead in the Terminal Response in case of Receice Data:
  72.  
  73.     //      Command details size: 5 bytes
  74.  
  75.     //      Device identities size : 4 bytes
  76.  
  77.     //      Result size : 3 bytes (in success case)
  78.  
  79.     //      Channel data length size : 3 bytes
  80.  
  81.     //      Channel data TL size : 3 bytes
  82.  
  83.     private static final short MAX_TLV_OVERHEAD = (short)0x0012;
  84.  
  85.     // Maximum response handler capacity to be used for the receive data
  86.  
  87.     private static short myRspHdlrCapacity;
  88.  
  89.    
  90.  
  91.     // Port number : integer
  92.  
  93.     private static byte[] portNumber = {(byte)0x00,(byte)0x23};
  94.  
  95.     // Channel Identifier given by the ME after the OPEN CHANNEL proactive command
  96.  
  97.     private static byte channelID = 0x00;
  98.  
  99.     // Byte array where data from the ME buffer is stored
  100.  
  101.     private static byte[] channelData = new byte [BUFFER_SIZE];
  102.  
  103.     // IP Address of the Server
  104.  
  105.     private static byte[] IPAddress = {(byte)163,(byte)187,(byte)203,(byte)1};
  106.  
  107.  
  108.  
  109.     /**
  110.  
  111.     * Constructor of the applet
  112.  
  113.     */
  114.  
  115.     public MyToolkitApplet(byte bArray[], short bOffset, byte bLength) {
  116.  
  117.        
  118.  
  119.         register();
  120.  
  121.        
  122.  
  123.         // register to the SIM Toolkit Framework
  124.  
  125.         reg = ToolkitRegistrySystem.getEntry();
  126.  
  127.  
  128.  
  129.         // Define the applet Menu Entry and register to the EVENT_MENU_SELECTION
  130.  
  131.         itemId = reg.initMenuEntry(menuEntry, (short)0x0000, (short)menuEntry.length,
  132.  
  133.                                    PRO_CMD_DISPLAY_TEXT, false, (byte) 0x00, (short) 0x0000);
  134.  
  135.        
  136.  
  137.         reg.enableMenuEntry((byte)itemId);
  138.  
  139.     }
  140.  
  141.  
  142.  
  143.     /**
  144.  
  145.     * Method called by the JCRE at the installation of the applet
  146.  
  147.     */
  148.  
  149.     public static void install(byte bArray[], short bOffset, byte bLength) {
  150.  
  151.         MyToolkitApplet MyApplet = new MyToolkitApplet(bArray, bOffset, bLength);      
  152.  
  153.     }
  154.  
  155.  
  156.  
  157.     /**
  158.  
  159.     * Method called by the GSM Framework
  160.  
  161.     */
  162.  
  163.     public Shareable getShareableInterfaceObject(AID aid, byte p) {
  164.  
  165.          if (aid == null && p == (byte)1) {
  166.  
  167.             return this ;
  168.  
  169.          }
  170.  
  171.          return null;
  172.  
  173.     }
  174.  
  175.  
  176.  
  177.     /**
  178.  
  179.     * Method called by the SIM Toolkit Framework
  180.  
  181.     */
  182.  
  183.     public void processToolkit(short event) {
  184.  
  185.  
  186.  
  187.         // get the handler references
  188.  
  189.         EnvelopeHandler          envHdlr = EnvelopeHandlerSystem.getTheHandler();
  190.  
  191.         ProactiveHandler         proHdlr = ProactiveHandlerSystem.getTheHandler();
  192.  
  193.         ProactiveResponseHandler rspHdlr = ProactiveResponseHandlerSystem.getTheHandler();;
  194.  
  195.         boolean repeat;
  196.  
  197.  
  198.  
  199.         switch(event) {
  200.  
  201.             case EVENT_STATUS_COMMAND:
  202.  
  203.                 reg.enableMenuEntry((byte)itemId);  
  204.  
  205.  
  206.  
  207.            
  208.  
  209.             case EVENT_PROFILE_DOWNLOAD:
  210.  
  211.                 reg.enableMenuEntry((byte)itemId);              
  212.  
  213.             break;
  214.  
  215.             case EVENT_MENU_SELECTION:
  216.  
  217.                 // Prepare the Select Item proactive command
  218.  
  219.                 proHdlr.init(PRO_CMD_SELECT_ITEM,(byte)0x00,DEV_ID_TERMINAL);
  220.  
  221.                 // Append the Menu Title
  222.  
  223.                 proHdlr.appendTLV((byte) (TAG_ALPHA_IDENTIFIER | TAG_SET_CR),
  224.  
  225.                                  menuTitle,(short)0x0000,(short)menuTitle.length);
  226.  
  227.                 // add all the Item
  228.  
  229.                 for (short i=(short) 0x0000; i<(short) 0x0004; i++) {
  230.  
  231.                     proHdlr.appendTLV((byte) (TAG_ITEM | TAG_SET_CR),(byte) (i+1),
  232.  
  233.                                       (byte[])ItemList[i],(short) 0x0000,
  234.  
  235.                                       (short)((byte[])ItemList[i]).length);
  236.  
  237.                 }
  238.  
  239.                 // ask the SIM Toolkit Framework to send the proactive command and check the result
  240.  
  241.                 if((result = proHdlr.send()) == RES_CMD_PERF){
  242.  
  243.  
  244.  
  245.                     // SelectItem response handling
  246.  
  247.                     switch (rspHdlr.getItemIdentifier()) {
  248.  
  249.                         case 1:
  250.  
  251.                             // DisplayText High Priority
  252.  
  253.                             proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  254.  
  255.                             proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), (byte)0x04,
  256.  
  257.                                                 textDText,(short)0x0000, (short)textDText.length);
  258.  
  259.                             proHdlr.send();
  260.  
  261.                         break;
  262.  
  263.  
  264.  
  265.                         case 2: // Ask the user to enter data and display it
  266.  
  267.                             do {
  268.  
  269.                                 repeat = false;
  270.  
  271.                                 try {
  272.  
  273.                                     // GetInput asking the users name
  274.  
  275.                                     proHdlr.initGetInput((byte)0x01, (byte)0x04, textGInput,(byte)0x00,
  276.  
  277.                                                 (short)textGInput.length,(short)0x0001,(short)0x0002);
  278.  
  279.                                     proHdlr.send();
  280.  
  281.                                     // Display the entered text
  282.  
  283.                                     rspHdlr.copyTextString(textDText,(short)0x0000);
  284.  
  285.                                     proHdlr.initDisplayText((byte)0x00, (byte)0x04, textDText,
  286.  
  287.                                                             (short)0x0000,(short) textDText.length);
  288.  
  289.                                     proHdlr.send();
  290.  
  291.                                 }
  292.  
  293.                                 catch (ToolkitException MyException) {
  294.  
  295.                                     if (MyException.getReason() == ToolkitException.UNAVAILABLE_ELEMENT ){
  296.  
  297.                                         if (rspHdlr.getGeneralResult() != EXIT_REQUESTED_BY_USER)
  298.  
  299.                                             repeat = true;
  300.  
  301.                                         break;
  302.  
  303.                                     }
  304.  
  305.                                 }
  306.  
  307.                             }
  308.  
  309.                             while(repeat);
  310.  
  311.                         break;
  312.  
  313.                     }
  314.  
  315.                 }
  316.  
  317.             break;
  318.  
  319.            
  320.  
  321.         }
  322.  
  323.     }
  324.  
  325.  
  326.  
  327.     /**
  328.  
  329.     * Method called by the JCRE, once selected
  330.  
  331.     */
  332.  
  333.     public void process(APDU apdu) {
  334.  
  335.         // Handle the Select AID apdu
  336.  
  337.         if(selectingApplet())
  338.  
  339.             return;
  340.  
  341.  
  342.  
  343.         switch(apdu.getBuffer()[1]) {
  344.  
  345.             // specific APDU for this applet to configure the MenuTitle from SelectItem
  346.  
  347.             case (byte)MY_INSTRUCTION:
  348.  
  349.                 if(apdu.setIncomingAndReceive() > (short)0) {
  350.  
  351.                     Util.arrayCopy(apdu.getBuffer(),(short)0x0005,menuTitle,(short)0x0000,(short)0x0006);
  352.  
  353.                 }
  354.  
  355.             break;
  356.  
  357.  
  358.  
  359.             default:
  360.  
  361.                 ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
  362.  
  363.         }
  364.  
  365.     }
  366.  
  367. }
As I know, methods initMenuEntry and enableMenuEntry trigger to send SET_UP_MENU proactive command.
But when I insert SIM, there are no SET_UP_MENU command.
Is there anyone else how to send SET_UP_MENU proactive command when SIM card is inserted in phone ?
Please help me...

Who is online

Users browsing this forum: No registered users and 51 guests

JavaCard OS : Disclaimer