Java卡的應用開發其實並不難(6)-toolkit app demo
import sim.toolkit.*;
import sim.access.*;
import javacard.framework.*;
public class MyToolkitApplet extends javacard.framework.Applet implements ToolkitInterface, ToolkitConstants
{
// BIP Constants
private static final byte TAG_DATA_DESTINATION_ADDRESS = (byte) 0x3E;
private static byte[] myAPN = {(byte)0x0A,(byte)'m',(byte)'y',(byte)'o',(byte)'p',(byte)'e',(byte)'r',(byte)'a',(byte)'t',(byte)'o',
(byte)'r',(byte)0x09,(byte)'m',(byte)'y',(byte)'c',(byte)'o',(byte)'u',(byte)'n',(byte)'t',
(byte)'r',(byte)'y'};
//GPRS = 0x02
private static final byte BEARER_TYPE_GPRS = (byte) 0x02;
// The service precedence class indicates the relative priority of maintaining the service
//Precedence Class n? => High priority.
private static final byte BEARER_PARAMETER_PRECEDENCE_CLASS1 = (byte) 0x01;
private static final byte BEARER_PARAMETER_DELAY_CLASS1 = (byte) 0x01;
private static final byte BEARER_PARAMETER_RELIABILITY_CLASS1 = (byte) 0x01;
private static final byte BEARER_PARAMETER_PEAK_THROUGHPUT_CLASS1= (byte) 0x01;
private static final byte BEARER_PARAMETER_MEAN_THROUGHPUT_CLASS1 = (byte) 0x01;
// PDP Type --> IP
private static final byte BEARER_PARAMETER_PDP_IP = (byte) 0x02;
// Define parameters necessary to launch a PDP context
private static byte[] BearerParameters= {(byte) BEARER_TYPE_GPRS, (byte) BEARER_PARAMETER_PRECEDENCE_CLASS1,
(byte) BEARER_PARAMETER_DELAY_CLASS1, (byte) BEARER_PARAMETER_RELIABILITY_CLASS1,
(byte) BEARER_PARAMETER_PEAK_THROUGHPUT_CLASS1, (byte) BEARER_PARAMETER_MEAN_THROUGHPUT_CLASS1,
(byte) BEARER_PARAMETER_PDP_IP };
// Type of Address IPV4=21,
private static final byte TYPE_OF_ADDRESS_IPV4 = (byte) 0x21;
// SIM/ME interface transport level UDP=01
private static final byte TRANSPORT_PROTOCOL_TYPE = (byte) 0x01;
// --> ... end GPRS case
public static final byte MY_INSTRUCTION = (byte)0x46;
public static final byte SERVER_OPERATION = (byte)0x0F;
public static final byte CMD_QUALIFIER = (byte)0x80;
public static final byte EXIT_REQUESTED_BY_USER = (byte)0x10;
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'};
private byte[] menuTitle= {(byte)'M',(byte)'y',(byte)'M',(byte)'e',(byte)'n' ,(byte)'u'};
private byte[] item1 = {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'1' };
private byte[] item2 = {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'2' };
private byte[] item3 = {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'3' };
private byte[] item4 = {(byte)'I',(byte)'T',(byte)'E',(byte)'M',(byte)'4' };
private Object[] ItemList = { item1, item2, item3, item4 };
private byte[] textDText = {(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o',(byte)' ',
(byte)'w',(byte)'o',(byte)'r',(byte)'l',(byte)'d',(byte)'2'};
private byte[] textGInput = {(byte)'Y',(byte)'o',(byte)'u',(byte)'r',(byte)' ',(byte)'n',
(byte)'a',(byte)'m',(byte)'e',(byte)'?'};
private byte[] baGSMAID = {(byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x09, (byte)0x00, (byte)0x01};
private ToolkitRegistry reg;
private SIMView gsmFile;
private byte buffer[] = new byte[10];
private byte itemId;
private byte result;
private static final short BUFFER_SIZE = (short)0x01F4;
private static final short MAX_TLV_OVERHEAD = (short)0x0012;
private static short myRspHdlrCapacity;
private static byte[] portNumber = {(byte)0x00,(byte)0x23};
private static byte channelID = 0x00;
private static byte[] channelData = new byte [BUFFER_SIZE];
private static byte[] IPAddress = {(byte)163,(byte)187,(byte)203,(byte)1};
public MyToolkitApplet() {
gsmFile = SIMSystem.getTheSIMView();
reg = ToolkitRegistry.getEntry();
itemId = reg.initMenuEntry(menuEntry, (short)0x0000, (short)menuEntry.length,
PRO_CMD_DISPLAY_TEXT, false, (byte) 0x00, (short) 0x0000);
reg.setEvent(EVENT_UNFORMATTED_SMS_PP_ENV);
reg.setEvent(EVENT_EVENT_DOWNLOAD_DATA_AVAILABLE);
}
public static void install(byte bArray[], short bOffset, byte bLength) {
MyToolkitApplet MyApplet = new MyToolkitApplet();
MyApplet.register();
}
public Shareable getShareableInterfaceObject(AID clientAID, byte parameter){
if (parameter == (byte) 0x00){
if ( clientAID.partialEquals(baGSMAID, (byte) 0x00, (byte) baGSMAID.length) == true )
return((Shareable) this);
}
return(null);
}
public void processToolkit(byte event) {
EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
ProactiveResponseHandler rspHdlr ;
boolean repeat;
switch(event) {
case EVENT_MENU_SELECTION:
proHdlr.init(PRO_CMD_SELECT_ITEM,(byte)0x00,DEV_ID_ME);
proHdlr.appendTLV((byte) (TAG_ALPHA_IDENTIFIER | TAG_SET_CR),
menuTitle,(short)0x0000,(short)menuTitle.length);
for (short i=(short) 0x0000; i<(short) 0x0004; i++) {
proHdlr.appendTLV((byte) (TAG_ITEM | TAG_SET_CR),(byte) (i+1),
(byte[])ItemList[i],(short) 0x0000,
(short)((byte[])ItemList[i]).length);
}
if((result = proHdlr.send()) == RES_CMD_PERF){
rspHdlr = ProactiveResponseHandler.getTheHandler();
switch (rspHdlr.getItemIdentifier()) {
case 1:
case 2:
proHdlr.init(PRO_CMD_OPEN_CHANNEL,(byte)0x00, DEV_ID_ME);
proHdlr.appendTLV((byte)(TAG_BEARER_DESCRIPTION | TAG_SET_CR),(byte)BEARER_TYPE_GPRS,
BearerParameters,
(short)0x0000, (short)BearerParameters.length);
proHdlr.appendTLV((byte)(TAG_BUFFER_SIZE | TAG_SET_CR),(byte)(BUFFER_SIZE>>(byte)8),(byte)BUFFER_SIZE);
proHdlr.appendTLV((byte)(TAG_NETWORK_ACCESS_NAME | TAG_SET_CR),myAPN,(short)0,(short)myAPN.length);
相關文章
- Java卡應用開發其實並不難(3)Java
- Java卡應用開發其實並不難(5)-SIM卡的Applet開發JavaAPP
- Java卡應用開發其實並不難(1)-開發環境Java開發環境
- Java卡應用開發其實並不難(2)-第一個Applet的建立JavaAPP
- webpack-dev-server 其實並不難WebdevServer
- Java開發難不難?Java
- Java從程式設計師到架構師其實並不難Java程式設計師架構
- 成為一名PHP專家其實並不難PHP
- WEB開發的需求溝通並不難Web
- 學習Java開發難不難?好學嗎?Java
- Java EE 6之企業應用開發Java
- 當女生成為軟體測試員,我才發現年薪30W+其實並不難…
- 手摸手教你使用WebSocket[其實WebSocket也不難]Web
- API 與 Webhook,其實並沒有那麼難懂APIWebHook
- Kafka並不難學Kafka
- 用uni-app開發app應用登陸APP
- Windows App 應用開發教程WindowsAPP
- Empatika:研究發現70%左右App Store評價內容與其相應的星級評價結果並不匹配APP
- 開發Linux系統裝置驅動程式並不難(轉)Linux
- MySQL的Double Write並不難理解MySql
- 用java實現日曆demo。Java
- 介面卡模式:我真的不難模式
- 雲端計算、大資料和人工智慧有什麼區別?理清楚其實並不難大資料人工智慧
- 應用程式APP原生開發的好處APP
- ES6 實用開發技巧
- 第一個Java卡應用的除錯Java除錯
- 手機APP應用軟體開發APP
- 【轉載】App Inventor 開發BLE應用APP
- java開發一個應用的總結Java
- Java的企業應用開發死期已到Java
- 急聘JAVA Web應用開發高手JavaWeb
- 應用開發:Java依然強勢Java
- 使用JAVA開發CORBA應用 (轉)JavaORB
- 使用Eclipse開發Java應用並部署到SAP雲平臺SCP上去EclipseJava
- 【T04】開發並使用應用程式框架框架
- 應用卡的原因
- 6個開源專案+Node.js中文教程讓Mixin Messenger 應用開發無難度Node.jsMessenger
- 用WindowsAppSDK(WASDK)優雅的開發上位機應用WindowsAPP