您现在的位置是:首页 > 数码 > 

手机访问FC

2025-07-29 15:59:15
手机访问FC 使用设备:MX, 魅蓝note 调用:       Open Mobile API 问题描述: 1.nfc手机使用Open Mobile API访问到的是内置的nfc的SE?如何才能访问sim卡上的SE?      使用MX访问nfc-sim卡时,访问到的是内置的

手机访问FC

使用设备:MX, 魅蓝note

调用:       Open Mobile API


问题描述:
手机使用Open Mobile API访问到的是内置的nfc的SE?如何才能访问sim卡上的SE?

     使用MX访问nfc-sim卡时,访问到的是内置的SE,没有显示可访问sim卡的SE。按照Open Mobile API的使用规范以及在网上的一些资料:,在创建,继承,实现接口之后,访问SE。在调用SEService.getReaders()时,不论手机是否插上了nfc-SIM卡,得到的readers数目始终是1。也就是说,手机只能访问到手机内部的SE,对nfc-sim卡中的SE始终“视而不见”。代码如下:(参考网上资料)

package ;import org.Channel;
import org.Reader;
import org.SEService;
import org.Session;
import fcAdapter;
import Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.TextView;public class MainActivity extends Activity implements SEService.CallBack {final String LOG_TAG = HelloSmartcard;/*** API entry point*/private SEService seService;fcAdapter mfc;TextView mTextView;@Overridepublic void onCreate(Bundle savedInstanceState) {(savedInstanceState);mfc = fcAdapter.getDefaultAdapter(this);// do layout and UI stuffsetContentView(R.layout.activity_main);mTextView = (TextView) this.findViewById(R.);try {// create API entry pointmTextView.setText(creating new SEService\n);seService = new SEService(, this);} catch (SecurityException e) {mTextView.append(Binding not allowed, uses-permission SMARTCARD?);} catch (Exception e) {mTextView.append(Exception:   e.getMessage());}}@Overrideprotected void onDestroy() {if (seService != null && seService.isConnected()) {seService.shutdown();}();}public void serviceConnected(SEService service) {Session session = null;Channel basicChannel = null;mTextView.append(serviceConnected()\n);if(!service.isConnected()){Log.d(LOG_TAG, seService is not Connected);mTextView.append(seService is not Connected);return;}try {mTextView.append(Getting available readers...\n);Reader[] readers = service.getReaders();//mTextView.append(The number of readers:  readers.length  \n);for(Reader reader:readers){                       Log.i(LOG_TAG,  =   reader.getame());mTextView.append( =   reader.getame()\n);}mTextView.append(Getting Session ...\n);session = readers[0].openSession();         //is SE?if(readers[0].isSecureElementPresent()){Log.v(SE, HasSE);mTextView.append(yes\n);}else {Log.v(SE, oSE);mTextView.append(o\n);}mTextView.append(open Session ...\n);//mTextView.append(ATR: ByteArrayToString(session.getATR())\n);byte[] aid = {(byte) 0xA0,0x00,0x00,0x00,0x0,0x00,0x00,0x00};basicChannel = (aid);      mTextView.append(open Channel ...\n);byte[] CPLC = {(byte) 0x80,(byte) 0xca,(byte) 0x9f,0x7f,0x00};byte[] respe1 = (CPLC);                     mTextView.append(CPLC:  () \n);               if(respe1.length>=20){mTextView.append(String.format(SerialID: %02x%02x%02x%02x\n, respe1[15],respe1[16],respe1[17],respe1[18]));    }} catch (Exception e) {mTextView.append(Error occured: e.getMessage()\n);}if(basicChannel!=null)();if(session!=null)();}private String ByteArrayToString(byte[] b) {StringBuffer s = new StringBuffer();for (int i = 0; i < b.length; i) {s.append((0x100  (b[i] & 0xff)).substring(1));}return ();}
}

运行结果如下:


2.非nfc不能使用Open Mobile API访问?
    为了探是否可以成功使用Open Mobile API来访问nfc-sim卡,使用魅蓝note(不具有nfc功能),但是按照上述代码(去掉关于nfc的部分),连基本的SEService都无法连接。(理论上,访问sim卡的SE不需要nfc手机),具体运行结果显示图如下:


.猜想
    a. 是否需要某些操作把手机默认的SE设置到sim卡上,如果是,要怎么做?
    b. 是否只有nfc手机才支持Open Mobile API,非nfc手机系统把这个API精简了?


4.解决

    a. 使用的手机MX没有内置SE,检查属性较慢,拔下卡后可能需要等待一段时间才能更新状态。

    b. 只要是android手机,就可以使用Open Mobile API来访问sim卡(前提是手机支持smartcard service),魅蓝note没有支持smartcard service。

    c. Smartcard service谷歌提供的代码,是通过检查sim卡是否存在,从而判断sim SE是否存在,所以,会存在普通卡也被识别成有SE这种不科学的情况。(据说谷歌这个是通过7816接口访问,不是通过SWP访问的,所以会有这个问题)


5.补充7816和SWP的一些知识

    a. SWP接口

    b. 7816接口

    c. SWP接口和7816在手机上结合


刚刚开始接触这一方面的知识,很多不懂,有错误的地方望指出,共勉~



#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/shuma/856930.html

相关标签:无
上传时间: 2024-02-10 03:29:05
留言与评论(共有 5 条评论)
本站网友 brian
3分钟前 发表
uses-permission SMARTCARD?);} catch (Exception e) {mTextView.append(Exception
本站网友 天章
23分钟前 发表
也就是说,手机只能访问到手机内部的SE,对nfc-sim卡中的SE始终“视而不见”
本站网友 两面针的功效与作用
1分钟前 发表
oSE);mTextView.append(o\n);}mTextView.append(open Session ...\n);//mTextView.append(ATR
本站网友 北城新风
3分钟前 发表
(byte) 0xca