fork(19) download
  1.  
  2. // Applet Display Text de prueba, TELEM
  3.  
  4. package bip1;
  5.  
  6. import javacard.framework.*;
  7. import sim.toolkit.*;
  8. import sim.access.*;
  9.  
  10. /*
  11. import javacard.framework.*;
  12. import sim.access.*;
  13. //import sim.toolkit.EnvelopeResponseHandler;
  14. import uicc.access.*;
  15. import uicc.toolkit.*;
  16. import sim.toolkit.EnvelopeResponseHandler;
  17.  */
  18.  
  19. public class bip1 extends Applet implements ToolkitInterface, ToolkitConstants // SIM
  20. //public class bip1 extends javacard.framework.Applet implements ToolkitInterface, uicc.toolkit.ToolkitConstants // USIM
  21.  
  22. {
  23. private ToolkitRegistry reg;
  24.  
  25. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  26. // BIP DATA CONSTANTS
  27.  
  28. // BIP Constants
  29. private static final byte TAG_DATA_DESTINATION_ADDRESS = (byte) 0x3E;
  30.  
  31. private static byte[] myAPN = {(byte)0x0A,(byte)'m',(byte)'y',(byte)'o',(byte)'p',(byte)'e',(byte)'r',(byte)'a',(byte)'t',(byte)'o',
  32. (byte)'r',(byte)0x09,(byte)'m',(byte)'y',(byte)'c',(byte)'o',(byte)'u',(byte)'n',(byte)'t',
  33. (byte)'r',(byte)'y'};
  34. //GPRS = 0x02
  35. private static final byte BEARER_TYPE_GPRS = (byte) 0x02;
  36. private static final byte BEARER_PARAMETER_PRECEDENCE_CLASS1 = (byte) 0x01;
  37. private static final byte BEARER_PARAMETER_DELAY_CLASS1 = (byte) 0x01;
  38. private static final byte BEARER_PARAMETER_RELIABILITY_CLASS1 = (byte) 0x01;
  39. private static final byte BEARER_PARAMETER_PEAK_THROUGHPUT_CLASS1= (byte) 0x01;
  40. private static final byte BEARER_PARAMETER_MEAN_THROUGHPUT_CLASS1 = (byte) 0x01;
  41.  
  42. // PDP Type = IP
  43. private static final byte BEARER_PARAMETER_PDP_IP = (byte) 0x02;
  44.  
  45. // Bearer parameters array
  46. private static byte[] BearerParameters= {(byte) BEARER_TYPE_GPRS, (byte) BEARER_PARAMETER_PRECEDENCE_CLASS1,
  47. (byte) BEARER_PARAMETER_DELAY_CLASS1, (byte) BEARER_PARAMETER_RELIABILITY_CLASS1,
  48. (byte) BEARER_PARAMETER_PEAK_THROUGHPUT_CLASS1, (byte) BEARER_PARAMETER_MEAN_THROUGHPUT_CLASS1,
  49. (byte) BEARER_PARAMETER_PDP_IP };
  50.  
  51. // Type of Address IPV4=21,
  52. private static final byte TYPE_OF_ADDRESS_IPV4 = (byte) 0x21;
  53.  
  54. // SIM/ME interface transport level UDP=01
  55. private static final byte TRANSPORT_PROTOCOL_TYPE = (byte) 0x01;
  56.  
  57. // BUFFER FOR HEXTOASCII CONVERTIONS
  58. private static byte m_BufferInternal[];
  59.  
  60. ///// PERSISTENT BUFFER/////
  61. private static byte[] m_buffer = {(byte)0x31,(byte)0x32,(byte)0x33,(byte)0x34 ,(byte)0x35 };
  62.  
  63. private static byte[] hexStrBuffer; // [COMMENT FOR RELEASE]
  64.  
  65. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  66.  
  67.  
  68. private static final byte[] MENU_ENTRY = {(byte)'D', (byte)'e', (byte)'m', (byte)'o',(byte)' ', (byte)'B', (byte)'I', (byte)'P'};
  69. private static final byte[] HELLO = {(byte)'H', (byte)'e', (byte)'l',(byte)'l', (byte)'o'};
  70. private static final byte[] HELLO1 = {(byte)'H', (byte)'e', (byte)'l',(byte)'l', (byte)'o', (byte)'1'};
  71. private static final byte[] HELLO2 = {(byte)'H', (byte)'e', (byte)'l',(byte)'l', (byte)'o', (byte)'2'};
  72.  
  73.  
  74. private byte[] menuTitle= {(byte)'M',(byte)'e',(byte)'n' ,(byte)'u'};
  75. private byte[] item1 = {(byte)'D',(byte)'i',(byte)'s',(byte)'p',(byte)'T',(byte)'e',(byte)'x',(byte)'t' };
  76. private byte[] item2 = {(byte)'O',(byte)'p',(byte)'e',(byte)'n',(byte)' ',(byte)'C',(byte)'h' };
  77. private byte[] item3 = {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'3' };
  78. private byte[] item4 = {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'4' };
  79. private Object[] ItemList = { item1, item2, item3, item4 };
  80.  
  81. private static final byte PROFILE_DISPLAY_TEXT = (byte)16;
  82. private byte result;
  83. public static final byte CMD_QUALIFIER = (byte)0x80;
  84. private static final short BUFFER_SIZE = (short)0x01F4;
  85. private static byte[] portNumber = {(byte)0x00,(byte)0x23}; // Port 13020
  86. private static byte channelID = 0x00;
  87. private static byte[] channelData = new byte [BUFFER_SIZE];
  88. private static short myRspHdlrCapacity;
  89. private static byte[] IPAddress = {(byte)96,(byte)80,(byte)99,(byte)17}; // 96.80.99.17 Blade1
  90.  
  91.  
  92. // Constants
  93. public static final byte DEV_ID_ME = (byte)0x82;
  94. public static final byte DCS_8_BIT_DATA = (byte)0x04;
  95. public static final byte TAG_SIM_ME_INTERFACE_TRANSPORT_LEVEL = (byte)0x3C;
  96.  
  97. // Display text qualifiers
  98. public final static byte DTQ_HIGH_PRIORITY = (byte)0x01;
  99. public final static byte DTQ_NORMAL_PRIORITY = (byte)0x00;
  100. public final static byte DTQ_WAIT_FOR_USER_TO_CLEAR_MESSAGE = (byte)0x80;
  101. public final static byte TAG_LOCATION_INFORMATION_93 = (byte)0x93;
  102. public static final byte DEV_ID_NETWORK = (byte)0x83;
  103. public static final byte PRO_CMD_SEND_SHORT_MESSAGE = (byte)0x13;
  104. public static final byte TAG_SMS_TPDU = (byte)0x0B;
  105. public final static byte DTQ_CRITICAL = (byte)(DTQ_HIGH_PRIORITY|DTQ_WAIT_FOR_USER_TO_CLEAR_MESSAGE);
  106. public static final byte TAG_TEXT_STRING_CR = (byte)(TAG_TEXT_STRING|TAG_SET_CR);
  107.  
  108. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  109.  
  110.  
  111.  
  112. // Constructor of the applet
  113. public bip1()
  114. {
  115. // Register to the SIM Toolkit Framework
  116. //reg = ToolkitRegistry.getEntry();
  117.  
  118. //reg = ToolkitRegistrySystem.getEntry(); // USIM
  119. reg = ToolkitRegistry.getEntry(); // SIM
  120.  
  121.  
  122. // Define the menu entry
  123. reg.initMenuEntry(MENU_ENTRY, (short)0, (short)MENU_ENTRY.length, PRO_CMD_DISPLAY_TEXT, false, (byte)0, (short)0);
  124. }
  125.  
  126. // install method
  127. public static void install(byte[] buffer,short offset, byte length) throws ISOException
  128. {
  129. bip1 bip1 = new bip1();
  130. bip1.register();
  131. }
  132.  
  133. // process method
  134. public void process(APDU apdu) throws ISOException
  135. {
  136. }
  137.  
  138. // process toolkit method
  139. //public void processToolkit(byte event) throws ToolkitException
  140. //public void processToolkit(short event) throws ToolkitException // USIM
  141. public void processToolkit(byte event) throws ToolkitException // SIM
  142. {
  143. //ProactiveHandler ph = ProactiveHandler.getTheHandler();
  144. //EnvelopeHandler envHdlr = EnvelopeHandlerSystem.getTheHandler(); // USIM
  145. //ProactiveHandler proHdlr = ProactiveHandlerSystem.getTheHandler(); // USIM
  146.  
  147. EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler(); // SIM
  148. ProactiveHandler proHdlr = ProactiveHandler.getTheHandler(); // SIM
  149.  
  150.  
  151. //ProactiveResponseHandler rspHdlr = ProactiveResponseHandlerSystem.getTheHandler(); // USIM
  152. ProactiveResponseHandler rspHdlr = ProactiveResponseHandler.getTheHandler(); // SIM
  153.  
  154.  
  155. // Setup Menu
  156. proHdlr.init(PRO_CMD_SELECT_ITEM,(byte)0x00,DEV_ID_ME);
  157. proHdlr.appendTLV((byte) (TAG_ALPHA_IDENTIFIER | TAG_SET_CR), menuTitle,(short)0x0000,(short)menuTitle.length);
  158. for (short i=(short) 0x0000; i<(short) 0x0004; i++)
  159. {
  160. proHdlr.appendTLV((byte) (TAG_ITEM | TAG_SET_CR),(byte) (i+1),(byte[])ItemList[i],(short) 0x0000,(short)((byte[])ItemList[i]).length);
  161. }
  162.  
  163.  
  164. if((result = proHdlr.send()) == RES_CMD_PERF)
  165. {
  166. //rspHdlr = ProactiveResponseHandlerSystem.getTheHandler();
  167. switch (rspHdlr.getItemIdentifier())
  168. {
  169. // DISPLAY TEXT MENU
  170. case 1:
  171. proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  172. proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), DCS_8_BIT_DATA,HELLO,(short)0x0000, (short)HELLO.length);
  173. proHdlr.send();
  174. //DisplayText ( proHdlr, HELLO);
  175. break;
  176.  
  177. // OPEN CHANNEL MENU
  178. case 2:
  179.  
  180. DisplayText ( proHdlr, HELLO);
  181. DisplayText ( proHdlr, HELLO1);
  182.  
  183. proHdlr.init(PRO_CMD_OPEN_CHANNEL,(byte)0x00, DEV_ID_ME);
  184. proHdlr.appendTLV((byte)(TAG_BEARER_DESCRIPTION | TAG_SET_CR),(byte)BEARER_TYPE_GPRS,BearerParameters, (short)0x0000, (short)BearerParameters.length);
  185. proHdlr.appendTLV((byte)(TAG_BUFFER_SIZE | TAG_SET_CR),(byte)(BUFFER_SIZE>>(byte)8),(byte)BUFFER_SIZE);
  186. proHdlr.appendTLV((byte)(TAG_NETWORK_ACCESS_NAME | TAG_SET_CR),myAPN,(short)0,(short)myAPN.length);
  187. proHdlr.appendTLV((byte) (TAG_SIM_ME_INTERFACE_TRANSPORT_LEVEL | TAG_SET_CR),TRANSPORT_PROTOCOL_TYPE,portNumber, (short)0, (short)portNumber.length);
  188. proHdlr.appendTLV((byte) (TAG_DATA_DESTINATION_ADDRESS | TAG_SET_CR),TYPE_OF_ADDRESS_IPV4,IPAddress,(short)0, (short) IPAddress.length);
  189.  
  190. result = proHdlr.send();
  191.  
  192. DisplayText ( proHdlr, HELLO2);
  193.  
  194. if (result == RES_CMD_PERF)
  195. {
  196. //rspHdlr = ProactiveResponseHandlerSystem.getTheHandler();
  197. channelID = rspHdlr.getChannelIdentifier();
  198. myRspHdlrCapacity = rspHdlr.getCapacity();
  199.  
  200. proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  201. proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), DCS_8_BIT_DATA,HELLO,(short)0x0000, (short)HELLO.length);
  202. proHdlr.send();
  203. DisplayText ( proHdlr, HELLO1);
  204.  
  205. }
  206. else
  207. {
  208. channelID = 0x00;
  209. DisplayText ( proHdlr, HELLO2);
  210. }
  211.  
  212. break;
  213.  
  214.  
  215. case 3:
  216.  
  217. proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  218. proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), DCS_8_BIT_DATA,HELLO,(short)0x0000, (short)HELLO.length);
  219. proHdlr.send();
  220.  
  221.  
  222. //m_buffer[0]=(byte)0x30;
  223. //m_buffer[1]=(byte)0x31;
  224.  
  225. proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  226. proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), DCS_8_BIT_DATA,HELLO2,(short)0x0000, (short)HELLO2.length);
  227. proHdlr.send();
  228.  
  229. proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  230. proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), DCS_8_BIT_DATA,m_buffer,(short)0x0000, (short)m_buffer.length);
  231. proHdlr.send();
  232.  
  233.  
  234.  
  235. byteToHexString(m_buffer, (short)0, hexStrBuffer, (short)0, (short)5);
  236.  
  237. proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  238. proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), DCS_8_BIT_DATA,hexStrBuffer,(short)0x0000, (short)hexStrBuffer.length);
  239. proHdlr.send();
  240.  
  241.  
  242. //Hex2Acii( m_buffer, (short)5);
  243. //proHdlr.initDisplayText((byte)0x81, (byte)0x04, m_BufferInternal, (short)0, (short)(5*2));
  244. //proHdlr.send();
  245.  
  246.  
  247.  
  248. //proHdlr.initDisplayText((byte)0x81, (byte)0x04, hexStrBuffer, (short)0, (short)hexStrBuffer.length);
  249. // proHdlr.send();
  250.  
  251.  
  252. break;
  253.  
  254.  
  255. case 4:
  256. proHdlr.init(PRO_CMD_DISPLAY_TEXT, CMD_QUALIFIER,DEV_ID_DISPLAY);
  257. proHdlr.appendTLV((byte)(TAG_TEXT_STRING| TAG_SET_CR), DCS_8_BIT_DATA,HELLO2,(short)0x0000, (short)HELLO2.length);
  258. proHdlr.send();
  259. break;
  260.  
  261.  
  262.  
  263.  
  264.  
  265. } // Close switch
  266. } // close if
  267. }
  268.  
  269. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  270. public final static void DisplayText ( ProactiveHandler PH, byte[] m_DatatoDisplay)
  271. {
  272.  
  273. PH.init( PRO_CMD_DISPLAY_TEXT, DTQ_CRITICAL, DEV_ID_DISPLAY );
  274. PH.appendTLV( TAG_TEXT_STRING_CR, DCS_8_BIT_DATA, m_DatatoDisplay, (short)0, (short)m_DatatoDisplay.length );
  275. PH.send( );
  276. }
  277. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  278.  
  279. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  280. //*** For Testing, comment for Release
  281. //*******************************************************************************
  282. // Method : byteToHexString
  283. // Author : Sao Paulo Boco
  284. // Created : June 24, 2004
  285. // Description :
  286. /**
  287.   * This function accepts a string of bytes and formats it into a HEX string
  288.   * @param buff_A buffer to translate to hex string
  289.   * @param index offset of buff_A where to start converting
  290.   * @param buff_B buffer to write hex string
  291.   * @param pos offset of buff_B where to start writing
  292.   * @param lenBuff_A length of buff_A
  293.   */
  294. //*******************************************************************************
  295. public static void byteToHexString(byte[] buff_A, short index, byte[] buff_B, short pos, short lenBuff_A)
  296. {
  297. byte hi;
  298. byte lo;
  299. byte temp;
  300. short length = (short)(lenBuff_A + index);
  301.  
  302. for (; index < length; index++)
  303. {
  304. hi = (byte) ((byte) (buff_A[index] >> 4) & 0x0F); //high nibble
  305. lo = (byte) ((byte) buff_A[index] & 0x0F); //low nibble
  306.  
  307. temp = (byte)0;
  308. while (temp < (byte)2)
  309. {
  310. if ((hi >= 0) && (hi <= (byte)0x09))
  311. {
  312. buff_B[pos++] = (byte)((byte)'0' + hi);
  313. } else if ((hi >= (byte)0x0A) && (hi <= (byte)0x0F))
  314. {
  315. buff_B[pos++] = (byte)((byte)0x37 + hi);
  316. }
  317. hi = lo;
  318. temp++;
  319. }
  320. }
  321. }
  322. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  323.  
  324.  
  325.  
  326. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  327. private final static void Hex2Acii( byte[] m_Hex, short length2)
  328. {
  329. byte nibL= (byte)0;
  330. byte nibL2= (byte)0;
  331. byte nibR= (byte)0;
  332. Util.arrayFillNonAtomic( m_BufferInternal, (byte)0, length2, (byte)0 );
  333. for(byte i=0; i<(byte)(length2); i++)
  334. {
  335. nibR = ( byte )( ( byte )m_Hex[ i ] & ( byte )0x0F );
  336. nibL2 = ( byte )(( byte )m_Hex[ i ] & ( byte )0xF0 );
  337. nibL = ( byte )(( byte )nibL2>>>( byte )4);
  338. nibL = ( byte )(( byte )nibL & ( byte )0x0F);
  339. if ( nibR < (byte)10)
  340. {
  341. nibR=( byte )(nibR+( byte )0x30);
  342. }
  343. else
  344. {
  345. nibR=( byte )(nibR+( byte )0x37);
  346. }
  347. if ( nibL < (byte)10)
  348. {
  349. nibL=( byte )(nibL+( byte )0x30);
  350. }
  351. else
  352. {
  353. nibL=( byte )(nibL+( byte )0x37);
  354. }
  355. m_BufferInternal[( byte )(i*2)]=( byte )nibL;
  356. m_BufferInternal[( byte )((i*2)+1)]=( byte )nibR;
  357. }
  358. //return m_BufferInternal;
  359. }
  360.  
  361.  
  362.  
  363. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  364.  
  365.  
  366.  
  367.  
  368.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:359: error: reached end of file while parsing
     }
      ^
1 error
stdout
Standard output is empty