Android使用NFC模拟M卡实现 (一)

本文档详细介绍了Android如何使用Host-based Card Emulation (HCE)模拟M卡,包括HCE服务的概念、AID组的选择、服务实现、安全性和协议参数等。HCE使得Android应用能够直接与NFC阅读器通信,而无需安全元件。开发者可以通过注册AID并创建HCE服务来实现NFC卡功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Android使用NFC模拟M卡实现 (一)

Android使用NFC模拟M卡实现 (二)

Android使用NFC模拟M卡实现 (三)

 

在百度找一遍,没有一篇,讲的比较通俗易懂的文件。讲解Android 的NFC 功能 card emulation。

略有点用的附在下面。

参考:
安卓 NFC 主机卡模拟
来自 <https://blog.csdn.net/chenyuebo11/article/details/54894296> 

修改配置文件方式
Android使用NFC模拟IC卡
来自 <https://blog.csdn.net/qq_21051503/article/details/73064910>
Android使用NFC模拟IC卡
来自 <https://blog.csdn.net/chenhao0428/article/details/51917634>

自己动手,丰衣足食。那首先就得看官方的文档。

https://developer.android.google.cn/guide/topics/connectivity/nfc/hce

那就的细看,都翻译下。我的半桶水英语水平,向谷歌翻译借力。

如果想了解具体的,必须细看本文,只想结果,只想撸,那就看我的另篇:Android使用NFC模拟M卡实现 (二)

原文全拷过来,进行翻译备注,此次文档是API 28,勉强作下面官方翻译。

Host-based card emulation overview

基于主机的卡仿真概述

Many Android-powered devices that offer NFC functionality already support NFC card emulation. In most cases, the card is emulated by a separate chip in the device, called a secure element. Many SIM cards provided by wireless carriers also contain a secure element.

许多的Android设备提供NFC功能已经支持NFC卡仿真。在大多数情况下,卡的模拟在设备中有单独芯片,称为安全元件。无线运营商提供的许多SIM卡也包含安全元件。

Android 4.4 introduces an additional method of card emulation that does not involve a secure element, called host-based card emulation. This allows any Android application to emulate a card and talk directly to the NFC reader. This document describes how host-based card emulation (HCE) works on Android and how you can develop an app that emulates an NFC card using this technique.

Android4.4引入了另一种卡仿真方法,该方法不涉及称为基于主机的卡仿真的安全元素。这允许任何Android应用程序模拟卡并直接与NFC阅读器对话。本文档介绍了基于主机的卡仿真(HCE)如何在Android上运行,以及如何使用此技术开发模拟NFC卡的应用程序。

Card Emulation with a secure element

具有安全元素的卡仿真

When NFC card emulation is provided using a secure element, the card to be emulated is provisioned into the secure element on the device through an Android application. Then, when the user holds the device over an NFC terminal, the NFC controller in the device routes all data from the reader directly to the secure element. Figure 1 illustrates this concept.

当使用安全元件提供NFC卡仿真时,要仿真的卡通过Android应用程序提供到设备上的安全元件中。然后,当用户将设备保持在NFC终端上时,设备中的NFC控制器将来自读取器的所有数据直接路由到安全元件。

Figure 1. NFC card emulation with a secure element.

图1说明了这个概念。

The secure element itself performs the communication with the NFC terminal, and no Android application is involved in the transaction at all. After the transaction is complete, an Android application can query the secure element directly for the transaction status and notify the user.

安全元件本身执行与NFC终端的通信,并且交易中根本不涉及Android应用程序。事务完成后,Android应用程序可以直接查询安全元素以获取事务状态并通知用户。

Host-based card emulation

基于主机的卡仿真

When an NFC card is emulated using host-based card emulation, the data is routed to the host CPU on which Android applications are running directly, instead of routing the NFC protocol frames to a secure element. Figure 2 illustrates how host-based card emulation works.

使用基于主机的卡仿真模拟NFC卡时,数据将路由到直接运行Android应用程序的主机CPU,而不是将NFC协议帧路由到安全元件。图2说明了基于主机的卡仿真的工作原理。

Figure 2. NFC card emulation without a secure element.

图2.没有安全元件的NFC卡仿真。

 

Supported NFC cards and protocols

支持的NFC卡和协议

The NFC standards offer support for many different protocols, and there are different types of cards that can be emulated.

NFC标准提供对许多不同协议的支持,并且可以模拟不同类型的卡。

Android 4.4 supports several protocols that are common in the market today. Many existing contactless cards are already based on these protocols, such as contactless payment cards. These protocols are also supported by many NFC readers in the market today, including Android NFC devices functioning as readers themselves (see the IsoDep class). This allows you to build and deploy an end-to-end NFC solution around HCE using only Android-powered devices.

Android 4.4支持当今市场上常见的几种协议。许多现有的非接触式卡已经基于这些协议,例如非接触式支付卡。当今市场上的许多NFC阅读器也支持这些协议,包括作为阅读器本身的Android NFC设备(参见IsoDep课程)。这使您可以仅使用Android驱动的设备围绕HCE构建和部署端到端NFC解决方案。

Specifically, Android 4.4 supports emulating cards that are based on the NFC-Forum ISO-DEP specification (based on ISO/IEC 14443-4) and process Application Protocol Data Units (APDUs) as defined in the ISO/IEC 7816-4 specification. Android mandates emulating ISO-DEP only on top of the Nfc-A (ISO/IEC 14443-3 Type A) technology. Support for Nfc-B (ISO/IEC 14443-4 Type B) technology is optional. The layering of all these specifications is shown in the figure 3.

具体而言,Android 4.4支持仿真基于NFC论坛ISO-DEP规范(基于ISO / IEC 14443-4)和ISO / IEC 7816-4规范中定义的处理应用协议数据单元(APDU)的卡。Android要求仅在Nfc-A(ISO / IEC 14443-3 A类)技术之上模拟ISO-DEP。支持Nfc-B(ISO / IEC 14443-4 B类)技术是可选的。所有这些规范的分层如图3所示。

 

Figure 3. Android's HCE protocol stack.

图3. Android的HCE协议栈。

HCE services

HCE服务 【即Host-based card emulation services

The HCE architecture in Android is based around Android Service components (known as "HCE services"). One of the key advantages of a service is that it can run in the background without any user interface. This is a natural fit for many HCE applications like loyalty or transit cards, with which the user shouldn't need to launch the app to use it. Instead, tapping the device against the NFC reader starts the correct service (if not already running) and executes the transaction in the background. Of course, you are free to launch additional UI (such as user notifications) from your service if that makes sense.

Android中的HCE架构基于Android Service组件(称为“HCE服务”)。服务的一个主要优点是它可以在后台运行而无需任何用户界面。这很适合许多HCE应用程序,如忠诚度[优惠]卡或转接[交通]卡,用户无需启动应用程序即可使用它。相反,在NFC阅读器上点击设备会启动正确的服务(如果尚未运行)并在后台执行事务。当然,如果有意义,您可以自由地从服务中启动其他UI(例如用户通知)。

Service selection

服务选择

When the user taps a device to an NFC reader, the Android system needs to know which HCE service the NFC reader actually wants to talk to. This is where the ISO/IEC 7816-4 specification comes in: it defines a way to select applications, centered around an Application ID (AID). An AID consists of up to 16 bytes. If you are emulating cards for an existing NFC reader infrastructure, the AIDs that those readers are looking for are typically well-known and publicly registered (for example, the AIDs of payment networks such as Visa and MasterCard).

当用户将设备轻敲到NFC读取器时,Android系统需要知道NFC读取器实际想要与哪个HCE服务通信。这就是ISO / IEC 7816-4规范的用武之地:它定义了一种以应用程序ID(AID)为中心选择应用程序的方法。AID最多包含16个字节。如果您要模拟现有NFC读卡器基础设施的卡,那些读者正在寻找的AID通常是众所周知的并且是公开注册的(例如,支付网络的AID,例如Visa和MasterCard)。

If you want to deploy new reader infrastructure for your own application, you will need to register your own AID(s). The registration procedure for AIDs is defined in the ISO/IEC 7816-5 specification. Google recommends registering an AID as per 7816-5 if you are deploying a HCE application for Android, as it will avoid collisions with other applications.

如果要为自己的应用程序部署新的阅读器基础结构,则需要注册自己的AID。AID的注册程序在ISO / IEC 7816-5规范中定义。如果您要为Android部署HCE应用程序,Google建议按照7816-5注册AID,因为这样可以避免与其他应用程序发生冲突。

AID groups

AID组

In some cases, an HCE service may need to register multiple AIDs to implement a certain application, and it needs to be sure that it is the default handler for all of these AIDs (as opposed to some AIDs in the group going to another service).

在某些情况下,HCE服务可能需要注册多个AID来实现某个应用程序,并且需要确保它是所有这些AID的默认处理程序(而不是该组中的某些AID转到另一个服务) 。

An AID group is a list of AIDs that should be considered as belonging together by the OS. For all AIDs in an AID group, Android guarantees one of the following:

AID组是应被视为OS所属的AID列表。对于AID组中的所有AID,Android保证以下其中一项:

  • All AIDs in the group are routed to this HCE service
  • 组中的所有AID都路由到[对应]HCE服务
  • No AIDs in the group are routed to this HCE service (for example, because the user preferred another service which requested one or more AIDs in your group as well)
  • 组中没有AID被路由到此HCE服务(例如,因为用户更喜欢在您的组中请求一个或多个AID的另一个服务)

In other words, there is no in-between state, where some AIDs in the group can be routed to one HCE service, and some to another.

换句话说,没有中间状态,其中组中的一些AID可以路由到一个HCE服务,一些到另一个。

AID groups and categories

AID组和类别

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值